<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://www.verific.com/faq/index.php?action=history&amp;feed=atom&amp;title=Write_out_an_encrypted_netlist</id>
		<title>Write out an encrypted netlist - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://www.verific.com/faq/index.php?action=history&amp;feed=atom&amp;title=Write_out_an_encrypted_netlist"/>
		<link rel="alternate" type="text/html" href="https://www.verific.com/faq/index.php?title=Write_out_an_encrypted_netlist&amp;action=history"/>
		<updated>2026-05-02T12:43:00Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.26.3</generator>

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

	</feed>