]> git.cryptolib.org Git - arm-crypto-lib.git/commitdiff
modified testing tools
authorbg <daniel.otte@rub.de>
Sat, 8 Oct 2011 10:35:42 +0000 (12:35 +0200)
committerbg <daniel.otte@rub.de>
Sat, 8 Oct 2011 10:35:42 +0000 (12:35 +0200)
bcal/keysize_descriptor.c [new file with mode: 0644]
bcal/keysize_descriptor.h [new file with mode: 0644]
host/shavs_test2.rb
test_src/shavs.c

diff --git a/bcal/keysize_descriptor.c b/bcal/keysize_descriptor.c
new file mode 100644 (file)
index 0000000..579ef56
--- /dev/null
@@ -0,0 +1,161 @@
+/* keysize_descriptor.c */
+/*
+    This file is part of the ARM-Crypto-Lib.
+    Copyright (C) 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 <http://www.gnu.org/licenses/>.
+*/
+/**
+ * \file    keysize_descriptor.c 
+ * \author  Daniel Otte
+ * \email   daniel.otte@rub.de
+ * \date    2009-01-07
+ * \license GPLv3 or later
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include "keysize_descriptor.h"
+
+uint8_t is_valid_keysize_P(const void* ks_desc, uint16_t keysize){
+       uint8_t type;
+       type = *((uint8_t*)ks_desc);
+       ks_desc = (uint8_t*)ks_desc + 1;
+       if(type==KS_TYPE_TERMINATOR)
+               return 0;
+       if(type==KS_TYPE_LIST){
+               uint8_t items;
+               uint16_t item;
+               items = *((uint8_t*)ks_desc);
+               ks_desc = (uint8_t*)ks_desc + 1;
+               while(items--){
+                       item = *((uint16_t*)ks_desc);
+                       ks_desc = (uint8_t*)ks_desc + 2;
+                       if(item==keysize)
+                               return 1;
+               }
+               ks_desc = (uint8_t*)ks_desc - 2;
+       }
+       if(type==KS_TYPE_RANGE){
+               uint16_t max, min;
+               min = *((uint16_t*)ks_desc);
+               ks_desc = (uint8_t*)ks_desc + 2;
+               max = *((uint16_t*)ks_desc);
+               if(min<=keysize && keysize<=max)
+                       return 1;
+       }
+       if(type==KS_TYPE_ARG_RANGE){
+               uint16_t max, min, dist, offset;
+               min = *((uint16_t*)ks_desc);
+               ks_desc = (uint8_t*)ks_desc + 2;
+               max = *((uint16_t*)ks_desc);
+               ks_desc = (uint8_t*)ks_desc + 2;
+               dist = *((uint16_t*)ks_desc);
+               ks_desc = (uint8_t*)ks_desc + 2;
+               offset = *((uint16_t*)ks_desc);
+               if(min<=keysize && keysize<=max && (keysize%dist==offset))
+                       return 1;
+       }
+       if(type>KS_TYPE_ARG_RANGE){
+               /* bad error, you may insert a big warning message here */
+               return 0;
+       }
+       return is_valid_keysize_P((uint8_t*)ks_desc+1, keysize); /* search the next record */
+}
+
+uint16_t get_keysize(const void* ks_desc){
+       uint8_t type;
+       uint16_t keysize;
+       type = *((uint8_t*)ks_desc);
+       if(type==KS_TYPE_LIST){
+               ks_desc = (uint8_t*)ks_desc + 1;
+       }
+       ks_desc = (uint8_t*)ks_desc + 1;
+       keysize = *((uint8_t*)ks_desc);
+       return keysize;
+}
+
+uint16_t get_keysizes(const void* ks_desc, uint16_t** list){
+       uint8_t type;
+       uint16_t items;
+       uint8_t i;
+       type = *((uint8_t*)ks_desc);
+       ks_desc = (uint8_t*)ks_desc + 1;
+       if(type==KS_TYPE_LIST){
+               items = *((uint8_t*)ks_desc);
+               ks_desc = (uint8_t*)ks_desc + 1;
+               if(!*list){
+                       *list = malloc(items*2);
+                       if(!*list){
+                               return 0;
+                       }
+               }
+               for(i=0; i<items; ++i){
+                       ((uint16_t*)(*list))[i] = *((uint16_t*)ks_desc);
+                       ks_desc = (uint8_t*)ks_desc + 2;
+               }
+               return items;
+       }
+       if(type==KS_TYPE_ARG_RANGE){
+               uint16_t min, max, distance, offset;
+               min = *((uint16_t*)ks_desc);
+               ks_desc = (uint8_t*)ks_desc + 2;
+               max = *((uint16_t*)ks_desc);
+               ks_desc = (uint8_t*)ks_desc + 2;
+               distance = *((uint16_t*)ks_desc);
+               ks_desc = (uint8_t*)ks_desc + 2;
+               offset = *((uint16_t*)ks_desc);
+               items = (max-min)/distance+1;
+               if(min%distance!=offset){
+                       --items;
+                       min += (distance-(min%distance-offset))%distance;
+               }
+               if(!*list){
+                       *list = malloc(items*2);
+                       if(!*list){
+                               return 0;
+                       }
+               }
+               i=0;
+               while(min<max){
+                       ((uint16_t*)*list)[i++] = min;
+                       min += distance;
+               }
+               return i;
+       }
+       if(type==KS_TYPE_RANGE){
+               uint16_t min, max, distance=8, offset=0;
+               min = *((uint16_t*)ks_desc);
+               ks_desc = (uint8_t*)ks_desc + 2;
+               max = *((uint16_t*)ks_desc);
+               items = (max-min)/distance+1;
+               if(min%distance!=offset){
+                       --items;
+                       min += (distance-(min%distance-offset))%distance;
+               }
+               if(!*list){
+                       *list = malloc(items*2);
+                       if(!*list){
+                               return 0;
+                       }
+               }
+               i=0;
+               while(min<max){
+                       ((uint16_t*)*list)[i++] = min;
+                       min += distance;
+               }
+               return i;
+       }
+       return 0;
+}
diff --git a/bcal/keysize_descriptor.h b/bcal/keysize_descriptor.h
new file mode 100644 (file)
index 0000000..2858e90
--- /dev/null
@@ -0,0 +1,61 @@
+/* keysize_descriptor.h */
+/*
+    This file is part of the ARM-Crypto-Lib.
+    Copyright (C) 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 <http://www.gnu.org/licenses/>.
+*/
+/**
+ * \file    keysize_descriptor.h 
+ * \author  Daniel Otte
+ * \email   daniel.otte@rub.de
+ * \date    2009-01-07
+ * \license GPLv3 or later
+ */
+
+#ifndef KEYSIZE_DESCRIPTOR_H_
+#define KEYSIZE_DESCRIPTOR_H_
+
+#include <stdint.h>
+
+#define KS_TYPE_TERMINATOR 0x00
+#define KS_TYPE_LIST       0x01
+#define KS_TYPE_RANGE      0x02
+#define KS_TYPE_ARG_RANGE  0x03
+
+#define KS_INT(a) ((a)&0xFF), ((a)>>8)
+
+typedef struct{ /* keysize is valid if listed in items */
+       uint8_t  n_items;  /* number of items (value 0 is reserved) */
+       uint16_t items[]; /* list of valid lengths */
+}keysize_desc_list_t;
+
+typedef struct{ /* keysize is valid if min<=keysize<=max */
+       uint16_t min;
+       uint16_t max;
+}keysize_desc_range_t;
+
+typedef struct{ /* keysize is valid if min<=keysize<=max and if keysize mod distance == offset */
+       uint16_t min;
+       uint16_t max;
+       uint16_t distance;
+       uint16_t offset;
+}keysize_desc_arg_range_t;
+
+uint8_t is_valid_keysize_P(const void* ks_desc, uint16_t keysize);
+uint16_t get_keysize(const void* ks_desc);
+uint16_t get_keysizes(const void* ks_desc, uint16_t** list);
+
+
+#endif /* KEYSIZE_DESCRIPTOR_H_ */
index fadbcb5904572bd1363899ebbf2051d7721aaf53..36c3e8cdeb00d1218f98573fa10c29f9daf9d6e1 100644 (file)
@@ -24,7 +24,7 @@ require 'rubygems'
 require 'serialport'
 require 'getopt/std'
 
-$buffer_size = 0
+$buffer_size = 0 # set automatically in init_system
 $conffile_check = Hash.new
 $conffile_check.default = 0
 
@@ -137,19 +137,19 @@ end
 =end
 def send_md(md_string)
 #  puts 'DBG: send_md; md_string.length = '+md_string.length.to_s+'; buffer_size = '+$buffer_size.to_s
-  bs = $buffer_size*2
+  bs = $buffer_size
   $sp.print("Msg = ")
   for i in 0..((md_string.length-1)/bs)
 #    puts 'DBG bulk send'
-    if(md_string.length-i*bs<bs)
+    if(md_string.length-i*bs<=bs)
  #     puts "DBG: i="+i.to_s()
       $sp.print(md_string[(i*bs)..-1]) 
       return
     end
     $sp.print(md_string[(i*bs)..((i+1)*bs-1)])
-    begin
-      line=$sp.gets()
-    end while not /\./.match(line) 
+  #  begin
+  #    line=$sp.gets()
+  #  end while not /\./.match(line) 
   end
 end
 
@@ -186,14 +186,16 @@ def run_test(filename, skip=0)
        $sp.print(lb.strip)
        $sp.print("\r")
     begin
-         lb=file.gets()
+           lb=file.gets()
     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(m[1])
+    puts("DBG sending [done] getting...") if $debug
        avr_md = get_md()
+    puts("DBG getting [done]") if $debug
     begin
-         lb=file.gets()
+           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];
@@ -221,6 +223,16 @@ end
 ################################################################################
 # MAIN                                                                         #
 ################################################################################
+#
+# Options:
+#  -s {algo_letter} run only specified algos
+#  -f <file>        also read config from <file>
+#  -i <n>           skip until test nr. <n>
+#  -j <n>           start with testfile <n>
+#  -h ???
+#  -d               enable debug mode
+#  -c ???
+#  -a ???
 
 opts = Getopt::Std.getopts("s:f:i:j:hdca")
 
@@ -299,7 +311,7 @@ algo_tasks.each do |algoa|
         puts("\n[errors: "+ nerrors.to_s() +"]")
         logfile.puts("[error] "+nerrors.to_s+" "+conf[algo]["file_#{i}"]+ " ("+Time.now.to_s()+")")
       end
-      i += 1
+      i = i+1
     end
     logfile.close()
   end
index 8ef96191def19a2151f0d02468de5b29e943a85f..41a15514d0920c43c18023982c80cdf1b7916612 100644 (file)
@@ -110,6 +110,7 @@ typedef struct {
 
 static shavs_ctx_t shavs_ctx;
 
+static
 uint8_t buffer_add(char c){
        uint8_t v,t;
        if(shavs_ctx.buffer_idx==shavs_ctx.buffersize_B){
@@ -368,11 +369,11 @@ void shavs_test2(void){ /* Monte Carlo tests for SHA-1 & SHA-2 */
                                return;
                        }
                }
-               if((c=cli_getc_cecho())!='e' && c!='e'){
+               if((c=cli_getc_cecho())!='e' && c!='E'){
                                cli_putstr("\r\nERROR: wrong input (2)!\r\n");
                                return;
                }
-               if((c=cli_getc_cecho())!='e' && c!='e'){
+               if((c=cli_getc_cecho())!='e' && c!='E'){
                                cli_putstr("\r\nERROR: wrong input (3)!\r\n");
                                return;
                }
@@ -453,11 +454,11 @@ void shavs_test3(void){ /* Monte Carlo tests for SHA-3 */
                                return;
                        }
                }
-               if((c=cli_getc_cecho())!='e' && c!='e'){
+               if((c=cli_getc_cecho())!='e' && c!='E'){
                                cli_putstr("\r\nERROR: wrong input (2)!\r\n");
                                return;
                }
-               if((c=cli_getc_cecho())!='e' && c!='e'){
+               if((c=cli_getc_cecho())!='e' && c!='E'){
                                cli_putstr("\r\nERROR: wrong input (3)!\r\n");
                                return;
                }