]> git.cryptolib.org Git - avr-crypto-lib.git/blobdiff - host/gf256_table_gen.c
fixing E-Mail-Address & Copyright
[avr-crypto-lib.git] / host / gf256_table_gen.c
index 87887d64cd2bb7b80bfe73faf5ab2492458588a3..d9217c896f7a7e41fa980a8632a94d323942cc47 100644 (file)
@@ -1,7 +1,7 @@
 /* gf256_table_gen.c */
 /*
-    This file is part of the Crypto-avr-lib/microcrypt-lib.
-    Copyright (C) 2008  Daniel Otte (daniel.otte@rub.de)
+    This file is part of the AVR-Crypto-Lib.
+    Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org)
 
     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
@@ -18,7 +18,7 @@
 */
 /**
  * \file     gf256_table_gen.c
- * \email    daniel.otte@rub.de
+ * \email    bg@nerilex.org
  * \author   Daniel Otte 
  * \date     2009-01-13
  * \license  GPLv3 or later
@@ -36,18 +36,36 @@ int print_header =  1,
     print_align  =  1,
     print_prefix =  1;
 
-charfmt_strings[]={"%d", "%3d",
+char *fmt_strings[]={"%d", "%3d",
                      "%X", "%2.2X",
                      "%o", "%3o",
                      "%d", "%3d",
                      "0x%X", "0x%2.2X",
                      "0%o", "0%3o"};
                      
+void print_help(void){
+       puts(
+"gf256_table_gen [-cCbBdhoaApP] [-l min] [-u max]\n"
+"                [-f formatstring] [-o file] -r reducer value {values} \n"
+"\n"
+" -c/-C turn C-header on/off (default: on)\n"
+" -b/-B turn braces on/off (defaul: on)\n"
+" -d/-h/-8 print values in decimal/hexadecimal/octal (default: hexadecimal)\n"
+" -a/-a  turn alignment on/off (default: on)\n"
+" -p/-P  turn base prefix on/off (default: on)\n"
+" -r reducer reducer is the reduction polynomial represented as numeric value\n"
+" -l min starting value for multiplication table (default: 0)\n"
+" -u max upper limit value for multiplication table (default: 255)\n"          
+" -f formatstring string for formating the output of a singel multiplicxation\n"
+" -o file outputfile\n"
+);
+}
+                     
 int main(int argc, char** argv){
        int i,j;
        int c;
        int option_index=0;
-       charfmt=NULL;
+       char *fmt=NULL;
        static struct option long_options[] =
              {
                /* These options set a flag. */
@@ -65,6 +83,7 @@ int main(int argc, char** argv){
                
                /* These options don't set a flag.
                   We distinguish them by their indices. */
+               {"help",    no_argument      , 0, '?'},     
                {"reducer", required_argument, 0, 'r'},
                {"min",     required_argument, 0, 'l'},
                {"max",     required_argument, 0, 'u'},
@@ -76,12 +95,12 @@ int main(int argc, char** argv){
        
        unsigned long ul_a;
        int columns=8;
-       unsigned long ul_reducer=0x1b, max=0xff, min=0x00;
+       unsigned long ul_reducer=0x00, max=0xff, min=0x00;
        uint8_t reducer, a;
        char** eptr;
-       FILEof = stdout;
+       FILE *of = stdout;
        while(c!=-1){
-               c = getopt_long(argc, argv,"cCbBdhoaApPr:l:u:f:", 
+               c = getopt_long(argc, argv,"cCbBdh8aApPr:l:u:f:", 
                                long_options, &option_index);
                switch(c){
                        case 'c': print_header=1; break;
@@ -90,7 +109,7 @@ int main(int argc, char** argv){
                        case 'B': print_braces=0; break;
                        case 'h': print_base = 1; break;
                        case 'd': print_base = 0; break;
-                       case 'o': print_base = 2; break;
+                       case '8': print_base = 2; break;
                        case 'a': print_align =1; break;
                        case 'A': print_align =0; break;
                        case 'p': print_prefix=1; break;
@@ -117,10 +136,19 @@ int main(int argc, char** argv){
                                          }
                                          break;
                        case 'f': fmt = optarg; break;
-                       default: break;
+                       case  -1: break;
+                       case '?': 
+                       default: 
+                               printf ("unknown option '%c' (%2.2X) !\n\t", c, c);
+                               print_help();
+                               return 0;
+                               break;
                }
        }
-       reducer = ul_reducer&0xff;
+       if(!(reducer = ul_reducer&0xff)){
+                       fprintf(stderr, "You must specify a reductionpolynomial!\n", argv[i]);
+                       return -1;
+       }
        if(!fmt)
                fmt = fmt_strings[print_prefix*6+print_base*2+print_align];