#include "blake_large.h"
#include "blake_common.h"
-#include "cli.h"
-
-#define BUG_3 0 /* bug compatibility with reference code */
-#define BUG_4 0 /* bug compatibility with reference code */
-
uint64_t pgm_read_qword(void* p){
union{
uint64_t v64;
void blake_large_compress(uint64_t* v,const void* m){
uint8_t r,i;
uint8_t a,b,c,d, s0, s1;
-// cli_putstr_P(PSTR("\r\nblock:"));
-// cli_hexdump_block(m, 128, 5, 8);
for(r=0; r<14; ++r){
for(i=0; i<8; ++i){
- // blake_large_g(r%10, i, v, (uint64_t*)m);
a = pgm_read_byte(blake_index_lut+4*i+0);
b = pgm_read_byte(blake_index_lut+4*i+1);
c = pgm_read_byte(blake_index_lut+4*i+2);
v[c] += v[d];
v[b] = ROTR64(v[b]^v[c], 11);
}
-/*
- cli_putstr_P(PSTR("\r\nv:"));
- for(i=0; i<16; ++i){
- if(i%4==0)
- cli_putstr_P(PSTR("\r\n "));
- cli_hexdump_rev(&(v[i]), 8);
- cli_putc(' ');
- }
-*/
}
}
buffer[length_b/8] |= 0x80 >> (length_b&0x7);
blake_large_changeendian(buffer, buffer);
blake_large_expand(v, ctx);
-#if BUG_3
- uint8_t x=0;
- if(length_b%1024<895 && length_b%8)
- x=0x40;
- v[12] ^= ctr + x;
- v[13] ^= ctr + x;
-
-#else
- if(length_b){
+ if(length_b>1024-128-2){
v[12] ^= ctr;
v[13] ^= ctr;
- }
-#endif
- if(length_b>1024-128-2){
-#if BUG_4
- if(length_b<1017){
- blake_large_compress(v, buffer);
- blake_large_collapse(ctx, v);
- }
-#else
blake_large_compress(v, buffer);
blake_large_collapse(ctx, v);
-#endif
memset(buffer, 0, 128-8);
blake_large_expand(v, ctx);
+ } else {
+ if(length_b){
+ v[12] ^= ctr;
+ v[13] ^= ctr;
+ }
}
if(ctx->appendone)
buffer[128-16-8] |= 0x01;
end
def init_system(algo_select)
-# sleep 1
$sp.print("echo off \r")
print("DBG i: " + "echo off \r"+"\n") if $debug
-# line = $sp.readlines()
-# print("DBG 0.0: ")
-# print(line)
- sleep 1
+ sleep 1
$sp.print("shavs_set #{algo_select}\r")
print("DBG i: " + "shavs_set #{$algo_select} \r"+"\n") # if $debug
-# line = $sp.readlines()
-# print("DBG 0.1: ")
-# print(line)
sleep 1
$sp.print("shavs_test1 \r")
print("DBG i: " + "shavs_test1 \r"+"\n") if $debug
line=$sp.gets()
end while not m=/buffer_size[\s]*=[\s]*0x([0-9A-Fa-f]*)/.match(line)
$buffer_size = m[1].to_i(16)
-# line = $sp.readlines()
-# print("DBG 0.2: ")
-# print(line)
end
def get_md
end
def send_md(md_string)
+ $sp.print("Msg = ")
for i in 0..md_string.length-1
$sp.print(md_string[i].chr)
# print("DBG s: "+ md_string[i].chr) if $debug
- if(i%$buffer_size==$buffer_size-1)
- begin
- line=$sp.gets()
- end while not /\./.match(line)
+ if((i%($buffer_size*2)==0)&&(i!=0))
+ begin
+ line=$sp.gets()
+ end while not /\./.match(line)
end
end
end
-def run_test(filename)
+def run_test(filename, skip=0)
nerrors = 0
line=1
if not File.exist?(filename)
pos = 0
file = File.new(filename, "r");
until file.eof
- sleep(0.5)
begin
lb=file.gets()
end while not (file.eof or (/[\s]*Len[\s]*=.*/.match(lb)))
+ len = /[\s]*Len[\s]*=[\s]*([0-9]*)/.match(lb)[1].to_i
puts("DBG sending: "+lb) if $debug
return if file.eof
+ if(skip>0)
+ skip -= 1
+ redo
+ end
$sp.print(lb.strip)
$sp.print("\r")
begin
lb=file.gets()
- end while not (file.eof or (/[\s]*Msg[\s]*=.*/.match(lb)))
+ end while not (file.eof or (m=/[\s]*Msg[\s]*=[\s]*([0-9a-fA-F]*)/.match(lb)))
return if file.eof
puts("DBG sending: "+lb) if $debug
- send_md(lb.strip)
+ send_md(m[1])
avr_md = get_md()
begin
lb=file.gets()
b = (/[\s]*MD[\s]*=[\s]*([0-9a-fA-F]*).*/.match(avr_md))[1];
a.upcase!
b.upcase!
- printf("\n%4d (%4d): ", line, (line-1)*$linewidth) if (pos%$linewidth==0 and $linewidth!=0)
+ printf("\n%4d (%4d) [%5d]: ", line, (line-1)*$linewidth, len) if (pos%$linewidth==0 and $linewidth!=0)
line += 1 if (pos%$linewidth==0 and $linewidth!=0)
- sleep(1)
+ #sleep(1)
#putc((a==b)?'*':'!')
if(a==b)
putc('*')
else
putc('!')
- printf("\nshould: %s\ngot: %s\n",lb,avr_md)
+ printf("<%d>",len)
nerrors += 1
end
pos += 1
conf = readconfigfile("/etc/testport.conf", conf)
conf = readconfigfile("~/.testport.conf", conf)
conf = readconfigfile("testport.conf", conf)
-puts conf.inspect
+#puts conf.inspect
puts("serial port interface version: " + SerialPort::VERSION);
$linewidth = 64
$sp.read_timeout=1000; # 5 minutes
$sp.flow_control = SerialPort::SOFT
-#$algo_select = ARGV[4]
-#irb
reset_system()
algos=scan_system()
-puts algos.inspect
+#puts algos.inspect
-algos.each_key do |algo|
+algos.sort.each do |algoa|
+ algo = algoa[0]
if conf[algo]==nil
puts("No test-set defined for #{algo} \r\n")
next
while conf[algo]["file_#{i}"] != nil
puts("Testing #{algo} with #{conf[algo]["file_#{i}"]}")
reset_system()
- init_system(algos[algo])
- nerrors=run_test(conf[algo]["file_#{i}"])
+ init_system(algoa[1])
+ nerrors=run_test(conf[algo]["file_#{i}"], 0)
if nerrors == 0
puts("\n[ok]")
logfile.puts("[ok] "+conf[algo]["file_#{i}"]+ " ("+Time.now.to_s()+")")