From 42251bae9cc25d0cce904fb46dd40bb051878da4 Mon Sep 17 00:00:00 2001 From: bg Date: Tue, 10 Nov 2009 03:18:29 +0000 Subject: [PATCH] release of new testing tool (still unfinished) --- blake/blake_common.c | 9 +- host/shavs_test2.rb | 239 +++++++++++++++++++++++++++++++++++++++++++ testport.conf | 65 ++++++++++++ 3 files changed, 307 insertions(+), 6 deletions(-) create mode 100644 host/shavs_test2.rb create mode 100644 testport.conf diff --git a/blake/blake_common.c b/blake/blake_common.c index e0e40f6..4baf372 100644 --- a/blake/blake_common.c +++ b/blake/blake_common.c @@ -45,12 +45,7 @@ uint8_t blake_sigma[] PROGMEM = { 0xB, 0x8, 0xC, 0x0, 0x5, 0x2, 0xF, 0xD, 0xA, 0xE, 0x3, 0x6, 0x7, 0x1, 0x9, 0x4, 0x7, 0x9, 0x3, 0x1, 0xD, 0xC, 0xB, 0xE, 0x2, 0x6, 0x5, 0xA, 0x4, 0x0, 0xF, 0x8 }; -/* - { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15 }, - {14,10, 4, 8, 9,15,13, 6, 1,12, 0, 2,11, 7, 5, 3 }, - {11, 8,12, 0, 5, 2,15,13,10,14, 3, 6, 7, 1, 9, 4 }, - { 7, 9, 3, 1,13,12,11,14, 2, 6, 5,10, 4, 0,15, 8 }}; -*/ + uint8_t blake_index_lut[] PROGMEM = { 0x0, 0x4, 0x8, 0xC, 0x1, 0x5, 0x9, 0xD, @@ -61,3 +56,5 @@ uint8_t blake_index_lut[] PROGMEM = { 0x2, 0x7, 0x8, 0xD, 0x3, 0x4, 0x9, 0xE }; + + diff --git a/host/shavs_test2.rb b/host/shavs_test2.rb new file mode 100644 index 0000000..f6e4af1 --- /dev/null +++ b/host/shavs_test2.rb @@ -0,0 +1,239 @@ +#!/usr/bin/ruby +# shavs_test.rb +=begin + This file is part of the AVR-Crypto-Lib. + Copyright (C) 2008, 2009 Daniel Otte (daniel.otte@rub.de) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +=end + +$debug = true +$debug = false +require 'rubygems' +require 'serialport' +require 'getopt/std' + +$buffer_size = 0 + +def readconfigfile(fname, conf) + section = "default" + if not File.exists?(fname) + return conf + end + file = File.open(fname, "r") + until file.eof + line = file.gets() + next if /[\s]*#/.match(line) + if m=/\[[\s]*([^\s]*)[\s]*\]/.match(line) + section=m[1] + conf[m[1]] = Hash.new + next + end + next if not /=/.match(line) + m=/[\s]*([^\s]*)[\s]*=[\s]*([^\s]*)/.match(line) + conf[section][m[1]] = m[2] + end + file.close() + return conf +end + +def reset_system + $sp.print("exit\r") + sleep 0.1 + $sp.print("exit\r") + sleep 0.1 +end + +def scan_system + algos = Hash.new + $sp.print("shavs_list\r") + while true + line=$sp.gets() + return algos if /^>$/.match(line) + if m = /[\*\ ]([a-z]):[\s]*([a-zA-Z0-9+_-]+)/.match(line) + algos[m[2]]=m[1] + end + end +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 + $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 + begin + 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 + begin + line = $sp.gets() + line = "" if line==nil + puts("DBG got: "+line) if $debug + end while not /[\s]*MD[\s]*=.*/.match(line) + return line +end + +def send_md(md_string) + 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) + end + end +end + +def run_test(filename) + nerrors = 0 + line=1 + if not File.exist?(filename) + puts("ERROR file "+filename+" does not exist!") + return nerrors + end + 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))) + puts("DBG sending: "+lb) if $debug + return if file.eof + $sp.print(lb.strip) + $sp.print("\r") + begin + lb=file.gets() + end while not (file.eof or (/[\s]*Msg[\s]*=.*/.match(lb))) + return if file.eof + puts("DBG sending: "+lb) if $debug + send_md(lb.strip) + avr_md = get_md() + begin + lb=file.gets() + end while not /[\s]*MD[\s]*=.*/.match(lb) + a = (/[\s]*MD[\s]*=[\s]*([0-9a-fA-F]*).*/.match(lb))[1]; + 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) + line += 1 if (pos%$linewidth==0 and $linewidth!=0) + sleep(1) + #putc((a==b)?'*':'!') + if(a==b) + putc('*') + else + putc('!') + printf("\nshould: %s\ngot: %s\n",lb,avr_md) + nerrors += 1 + end + pos += 1 + end + return nerrors.to_i +end + +conf = Hash.new +conf = readconfigfile("/etc/testport.conf", conf) +conf = readconfigfile("~/.testport.conf", conf) +conf = readconfigfile("testport.conf", conf) +puts conf.inspect + +puts("serial port interface version: " + SerialPort::VERSION); +$linewidth = 64 +params = { "baud" => conf["PORT"]["baud"].to_i, + "data_bits" => conf["PORT"]["databits"].to_i, + "stop_bits" => conf["PORT"]["stopbits"].to_i, + "parity" => SerialPort::NONE } +params["paraty"] = SerialPort::ODD if conf["PORT"]["paraty"].downcase == "odd" +params["paraty"] = SerialPort::EVEN if conf["PORT"]["paraty"].downcase == "even" +params["paraty"] = SerialPort::MARK if conf["PORT"]["paraty"].downcase == "mark" +params["paraty"] = SerialPort::SPACE if conf["PORT"]["paraty"].downcase == "space" + +puts("\nPort: "+conf["PORT"]["port"]+"@" + + params["baud"].to_s + + " " + + params["data_bits"].to_s + + conf["PORT"]["paraty"][0,1].upcase + + params["stop_bits"].to_s + + "\n") + +$sp = SerialPort.new(conf["PORT"]["port"], params) + +$sp.read_timeout=1000; # 5 minutes +$sp.flow_control = SerialPort::SOFT +#$algo_select = ARGV[4] +#irb + +reset_system() +algos=scan_system() +puts algos.inspect + +algos.each_key do |algo| + if conf[algo]==nil + puts("No test-set defined for #{algo} \r\n") + next + else + i=0 + logfile=File.open(conf["PORT"]["testlogbase"]+algo+".txt", "a") + 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}"]) + if nerrors == 0 + puts("\n[ok]") + logfile.puts("[ok] "+conf[algo]["file_#{i}"]+ " ("+Time.now.to_s()+")") + else + puts("\n[errors: "+ nerrors.to_s() +"]") + logfile.puts("[error] "+nerrors.to_s+" "+conf[algo]["file_#{i}"]+ " ("+Time.now.to_s()+")") + end + i += 1 + end + logfile.close() + end +end + +=begin +nerrors = 0 +for i in (5..(ARGV.size-1)) + nerrors = run_test(ARGV[i]) + if nerrors == 0 + puts("\n[ok]") + else + puts("\n[errors: "+ nerrors.to_s() +"]") + end +end + $sp.print("EXIT\r"); + +#exit(0); +=end + diff --git a/testport.conf b/testport.conf new file mode 100644 index 0000000..213533d --- /dev/null +++ b/testport.conf @@ -0,0 +1,65 @@ +# configfile for shavs tests + +[PORT] +port = /dev/ttyUSB1 +baud = 38400 +databits = 8 +stopbits = 1 +paraty = none +testlogbase = testlog_ + +############################################################################### + +[BlueMidnightWish-224] +algo=a +file_0=testvectors/shavs/BlueMidnightWish/ShortMsgKAT_224.txt +file_1=testvectors/shavs/BlueMidnightWish/LongMsgKAT_224.txt + +[BlueMidnightWish-256] +algo=b +file_0=testvectors/shavs/BlueMidnightWish/ShortMsgKAT_256.txt +file_1=testvectors/shavs/BlueMidnightWish/LongMsgKAT_256.txt + +[BlueMidnightWish-384] +algo=c +file_0=testvectors/shavs/BlueMidnightWish/ShortMsgKAT_384.txt +file_1=testvectors/shavs/BlueMidnightWish/LongMsgKAT_384.txt + +[BlueMidnightWish-512] +algo=d +file_0=testvectors/shavs/BlueMidnightWish/ShortMsgKAT_512.txt +file_1=testvectors/shavs/BlueMidnightWish/LongMsgKAT_512.txt + +[BlueMidnightWish] +meta=1 +test_0=BlueMidnightWish-256 +test_1=BlueMidnightWish-512 +test_2=BlueMidnightWish-224 +test_3=BlueMidnightWish-384 + +############################################################################### + +[Blake-28] +algo=a +file_0=testvectors/shavs/Blake/ShortMsgKAT_224.txt +file_1=testvectors/shavs/Blake/LongMsgKAT_224.txt + +[Blake-32] +algo=b +file_0=testvectors/shavs/Blake/ShortMsgKAT_256.txt +file_1=testvectors/shavs/Blake/LongMsgKAT_256.txt + +[Blake-48] +algo=c +file_0=testvectors/shavs/Blake/ShortMsgKAT_384.txt +file_1=testvectors/shavs/Blake/LongMsgKAT_384.txt + +[Blake-64] +algo=d +file_0=testvectors/shavs/Blake/ShortMsgKAT_512.txt +file_1=testvectors/shavs/Blake/LongMsgKAT_512.txt + +############################################################################### + + +# END OF CONFIGFILE -- 2.39.5