diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP index 84829ce43..ecbf12e2c 100644 --- a/MANIFEST.SKIP +++ b/MANIFEST.SKIP @@ -50,6 +50,6 @@ nodist/ /simv.daidir/ /vc_hdrs.h$ /csrc/ -obj_dir/.* +obj_dir.* TAGS .*~ diff --git a/bin/verilator b/bin/verilator index 58a5bd21f..fa3ecda1f 100755 --- a/bin/verilator +++ b/bin/verilator @@ -312,6 +312,7 @@ detailed descriptions in L for more information. -G= Overwrite toplevel parameter --gdb Run Verilator under GDB interactively --gdbbt Run Verilator under GDB for backtrace + --generate-key Create random key for --protect-key --getenv Get environment variable with defaults --help Display this help -I Directory to search for includes @@ -864,6 +865,11 @@ backtrace on exit, then exit GDB immediately. Without --debug or if GDB doesn't seem to work, this flag is ignored. Intended for easy creation of backtraces by users; otherwise see the --gdb flag. +=item --generate-key + +Generate a true-random key suitable for use with --protect-key, print it, +and exit immediately. + =item --getenv I If the variable is declared in the environment, print it and exit @@ -1159,10 +1165,10 @@ this into a nicer visual format and produce some related statistics. =item --protect-key I Specifies the private key for --protect-ids. For best security this key -should be 16 or more random bytes, a reasonable medium-security choice is -the output of uuidgen. Typically, a key would be created by the user once -for a given protected design library, then every Verilator run for -subsequent versions of that library would be passed the same +should be 16 or more random bytes, a reasonable secure choice is the output +of C. Typically, a key would be created by the +user once for a given protected design library, then every Verilator run +for subsequent versions of that library would be passed the same --protect-key. Thus, if the input Verilog is similar between library versions (Verilator runs), the Verilated code will likewise be mostly similar. diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 735b710af..1b8431cc4 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -569,7 +569,7 @@ string V3Options::protectKeyDefaulted() { // Create a key with a human-readable symbol-like name. // This conversion drops ~2 bits of entropy out of 256, shouldn't matter. VHashSha256 digest (V3Os::trueRandom(32)); - m_protectKey = digest.digestSymbol(); + m_protectKey = "VL-KEY-"+digest.digestSymbol(); } return m_protectKey; } @@ -858,6 +858,10 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char shift; m_gateStmts = atoi(argv[i]); } + else if (!strcmp(sw, "-generate-key")) { + cout< 1); + +compile( + v_flags2 => ["--generate-key"], + expect => qr/VL-KEY/, + verilator_make_gmake => 0, + make_top_shell => 0, + make_main => 0, + ); + +ok(1); +1; diff --git a/test_regress/t/t_protect_ids.pl b/test_regress/t/t_protect_ids.pl index cff3e8341..b107ea36c 100755 --- a/test_regress/t/t_protect_ids.pl +++ b/test_regress/t/t_protect_ids.pl @@ -21,6 +21,7 @@ foreach my $filename (glob ("$Self->{obj_dir}/*_PS*.cpp" compile( verilator_flags2 => ["--protect-ids", + "--protect-key SECRET_KEY", "--trace", "--coverage", "-Wno-INSECURE", @@ -39,10 +40,10 @@ if ($Self->{vlt_all}) { # Check for secret in any outputs my $any; foreach my $filename (glob $Self->{obj_dir}."/*.[ch]*") { - if ($filename =~ /secret/) { + if ($filename =~ /secret/i) { $Self->error("Secret found in a filename: ".$filename); } - file_grep_not($filename, qr/secret/); + file_grep_not($filename, qr/secret/i); $any = 1; } $any or $Self->error("No outputs found"); diff --git a/test_regress/t/t_protect_ids_key.out b/test_regress/t/t_protect_ids_key.out index 173c1b1e0..036238fb8 100644 --- a/test_regress/t/t_protect_ids_key.out +++ b/test_regress/t/t_protect_ids_key.out @@ -1,41 +1,41 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test_regress/t/t_protect_ids_key.pl b/test_regress/t/t_protect_ids_key.pl index b51e8cd7b..503b3d5bd 100755 --- a/test_regress/t/t_protect_ids_key.pl +++ b/test_regress/t/t_protect_ids_key.pl @@ -12,7 +12,7 @@ scenarios(vlt => 1); top_filename("t/t_protect_ids.v"); compile( - verilator_flags2 => ["--protect-ids --protect-key MY_KEY", + verilator_flags2 => ["--protect-ids --protect-key SECRET_KEY", "t/t_protect_ids_c.cpp"], );