https://www.verific.com/faq/index.php?title=Write_out_an_encrypted_netlist&feed=atom&action=history
Write out an encrypted netlist - Revision history
2024-03-29T15:37:25Z
Revision history for this page on the wiki
MediaWiki 1.26.3
https://www.verific.com/faq/index.php?title=Write_out_an_encrypted_netlist&diff=342&oldid=prev
Hoa: Created page with " <nowiki> #include <iostream> #include <cstring> #include "veri_file.h" #include "DataBase.h" #include "VeriWrite.h" #include "Strings.h" #include "Message.h" #include "Pro..."
2019-03-01T20:54:24Z
<p>Created page with " <nowiki> #include <iostream> #include <cstring> #include "veri_file.h" #include "DataBase.h" #include "VeriWrite.h" #include "Strings.h" #include "Message.h" #include "Pro..."</p>
<p><b>New page</b></p><div> <nowiki><br />
#include <iostream><br />
#include <cstring><br />
<br />
#include "veri_file.h"<br />
<br />
#include "DataBase.h"<br />
#include "VeriWrite.h"<br />
<br />
#include "Strings.h"<br />
#include "Message.h"<br />
#include "Protect.h"<br />
<br />
#ifdef VERIFIC_NAMESPACE<br />
using namespace Verific ;<br />
#endif<br />
<br />
// Derive a class from Protect<br />
class VFC_DLL_PORT Cipher : public Protect<br />
{<br />
public:<br />
Cipher() : Protect(64) {}<br />
virtual ~Cipher() {}<br />
<br />
virtual unsigned encrypt(const char *in_buf, char *out_buf, unsigned size) ;<br />
virtual unsigned decrypt(const char *in_buf, char *out_buf, unsigned size) ;<br />
virtual char *decrypt() ;<br />
virtual char * GetEncryptionHeader() ;<br />
virtual char * GetEncryptionFooter() ;<br />
} ;<br />
<br />
unsigned<br />
Cipher::encrypt(const char *in_buf, char *out_buf, unsigned size)<br />
{<br />
std::memset(out_buf, 0, size) ; // set all bytes to '\0'<br />
unsigned in_len = Strings::len(in_buf) ;<br />
<br />
unsigned i ;<br />
for (i = 0 ; i < in_len ; ++i) {<br />
out_buf[i] = in_buf[i] + 1 ; // increment the ASCII value<br />
}<br />
return size ;<br />
} ;<br />
<br />
unsigned<br />
Cipher::decrypt(const char *in_buf, char *out_buf, unsigned size)<br />
{<br />
std::memset(out_buf, 0, size) ; // set all bytes to '\0'<br />
unsigned in_len = Strings::len(in_buf) ;<br />
<br />
unsigned i ;<br />
for (i = 0 ; i < in_len ; ++i) {<br />
out_buf[i] = in_buf[i] - 1 ; // decrement the ASCII value<br />
}<br />
return size ;<br />
} ;<br />
<br />
char *<br />
Cipher::decrypt()<br />
{<br />
const Directive *directive = GetValue("data_block") ;<br />
char *out_buf = Strings::save(directive->GetStringValue()) ;<br />
decrypt(directive->GetStringValue(), out_buf, Strings::len(out_buf)) ;<br />
return out_buf ;<br />
}<br />
<br />
char *<br />
Cipher::GetEncryptionHeader()<br />
{<br />
// Return the encryption header<br />
return Strings::save("`pragma protect begin_protected\n`pragma protect data_block") ;<br />
}<br />
<br />
<br />
char *<br />
Cipher::GetEncryptionFooter()<br />
{<br />
// Return the encryption the footer<br />
return Strings::save("`pragma protect end_protected") ;<br />
}<br />
<br />
// Call back function to specify if this module is to be encrypted or not<br />
unsigned<br />
encrypt_module_func(const char *mod_name)<br />
{<br />
if (!mod_name) return 0 ;<br />
<br />
//return 1 ; // Enable this line to protect all the modules<br />
<br />
if (Strings::compare(mod_name, "bot1") || Strings::compare(mod_name, "bot2")) {<br />
Message::Info(0, "Encrypting module ", mod_name) ;<br />
return 1 ; // return 1 to encrypt this module<br />
}<br />
<br />
return 0 ;<br />
}<br />
<br />
int main()<br />
{<br />
<br />
// Now read in top-level design. In case of failure return.<br />
if (!veri_file::Read("test.v", "work", veri_file::VERILOG_2K)) {<br />
// Here, design analysis and elaboration failed<br />
return 1 ;<br />
}<br />
<br />
// Get a handle to the top-level netlist<br />
Netlist *top = Netlist::PresentDesign() ;<br />
<br />
Cipher cipher ;<br />
VeriWrite writter ;<br />
<br />
// Set the protection object<br />
writter.SetProtectionObject(&cipher) ;<br />
writter.RegisterEncryptModule(encrypt_module_func) ;<br />
<br />
// Write the netlist<br />
if (!writter.WriteFile("test.v.golden.new", top)) return 1 ;<br />
<br />
Libset::Reset() ;<br />
veri_file::Reset() ;<br />
<br />
// Analyze the encrypted file<br />
veri_file::SetPragmaProtectObject(&cipher) ;<br />
if (!veri_file::Analyze("test.v.golden.new", veri_file::VERILOG_2K, "work")) return 1 ;<br />
<br />
// PrettyPrint the analyzed file<br />
if (!veri_file::PrettyPrint("pp_test.v.golden.new", 0, "work")) return 1 ;<br />
<br />
return 0 ;<br />
}<br />
</nowiki></div>
Hoa