#! /usr/sepp/bin/perl -w ############################################################ ## Copyright: 2011 Integrated Sytems Laboratory, ETH Zurich ## http://www.iis.ee.ethz.ch/~sha3 ############################################################ use strict; # v0.3 - kgf@ee.ethz.ch - Thu Aug 11 08:12:28 CEST 2011 # - added a version that will generate arbitrary length messages. # The only restriction is that the message has to be multiple of # 16 bits.. # v0.2 - kgf@ee.ethz.ch - Tue Aug 9 20:10:31 CEST 2011 # - correct padding for upto 1080.. multi block messages to come # v0.1 - kgf@ee.ethz.ch - Sun Aug 7 14:44:16 CEST 2011 # - silly script to generate the vectors from the gen_sha3_stimuli # merge to the cript later on # make sure the lengths are ok later on ## CONSTANTS my $HASH_BLOCK_SIZE=1088; # Keccak SHA-256 version my $MIN_PADDING_SIZE= 16; # this is not completely correct. Min size is # 2 but it is so much easier to generate 16 ## let us extract the information first my @L; # length array my @M; # message array my @D; # digest array # steal all the information # Note: if one of the entries MD, Len, Msg is missing trouble will arise open (S, "< expresp.txt"); while (S){ push (@L,$1) if (/^\s*Len\s*=\s*([0-9]+)/i); push (@M,$1) if (/^\s*Msg\s*=\s*([0-9A-F]+)/i); push (@D,$1) if (/^\s*MD\s*=\s*([0-9A-F]+)/i); } close(S); my $date= `date`; chomp ($date); print <<"BUGU"; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Test vectors for ETHZ KECCAK %% generated by ethz_keccak_stimuli.pl %% on $date %% BUGU ## loop over all read messages for my $i (0..$#L){ ## how many blocks will we need my $num_blocks=int (($L[$i] + $MIN_PADDING_SIZE - 1) / $HASH_BLOCK_SIZE) +1; ## now let us determine the padding ## Because of the brain dead scheme that these guys interpret ## MSBs 100..0001 actually becomes 01 00 00 80 ## It is very easy to calculate this provided the pad size is at least 16 ## it is a restriction at the moment but it works easily.. ## for other lengths we need a more elaborate code.. my $zero_cnt = (($HASH_BLOCK_SIZE * $num_blocks) - $L[$i] -16) / 8; my $pad = "01"."00" x $zero_cnt."80"; ## these two are so that the reports look cute my $pretty_i = $i + 1; my $pretty_len = $#L + 1; # comment character is '%' n the testbench print <<"BUGU"; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% vector $pretty_i of $pretty_len %% Length = $L[$i], Number of $HASH_BLOCK_SIZE bit blocks = $num_blocks, Padding = $pad %% Message = $M[$i] %% Digest = $D[$i] BUGU ## add the pad to the message $M[$i]=$M[$i].$pad; ## now loop over number of blocks for my $j (1..$num_blocks){ ## this is the part of the message that goes out my $sub=substr($M[$i],($j-1)*($HASH_BLOCK_SIZE/4),($HASH_BLOCK_SIZE/4)); ## generate the output print unpack("B*",pack("H*",$sub))." "; # this is the block input ## are we in the last block if ($j eq $num_blocks){ print "1 ".unpack("B*",pack("H*",$D[$i]))."\n"; # set last and compare } else{ print "0 ". '-' x 256 . "\n"; # don't set last and don't care } } }