]> git.cryptolib.org Git - avr-crypto-lib.git/blobdiff - test_src/main-dsa-test.c
fixing E-Mail-Address & Copyright
[avr-crypto-lib.git] / test_src / main-dsa-test.c
index acbffa9e4ac0572e385da33dd43d293a81672467..78784719c4d27c10178fb244c3ed58d3eb9009ca 100644 (file)
@@ -1,7 +1,7 @@
 /* main-dsa-test.c */
 /*
     This file is part of the AVR-Crypto-Lib.
-    Copyright (C) 2010 Daniel Otte (daniel.otte@rub.de)
+    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
  *
 */
 
-#include "config.h"
-
-#include "uart_i.h"
-#include "debug.h"
+#include "main-test-common.h"
 
 #include "noekeon.h"
 #include "noekeon_prng.h"
 #include "dsa.h"
 #include "dsa_key_blob.h"
 
-#include "cli.h"
 #include "performance_test.h"
 #include "hfal_sha1.h"
 #include "base64_enc.h"
 #include "base64_dec.h"
-#include <stdint.h>
-#include <string.h>
-#include <stdlib.h>
 
-charalgo_name = "DSA";
+char *algo_name = "DSA";
 
 /*****************************************************************************
  *  additional validation-functions                                                                                     *
@@ -54,14 +47,14 @@ void load_fix_dsa(void){
        load_dsa_key_blob(&dsa_ctx);
 }
 
-void dsa_print_item(bigint_ta, PGM_P pstr){
+void dsa_print_item(bigint_t *a, PGM_P pstr){
        uint8_t *p;
        cli_putstr_P(PSTR("\r\n"));
        cli_putstr_P(pstr);
        cli_putstr_P(PSTR(": "));
        uint16_t i;
-       p = a->wordv + a->length_B -1;
-       for(i=0; i<a->length_B-1; ++i){
+       p = a->wordv + a->length_W -1;
+       for(i=0; i<a->length_W-1; ++i){
                if(i%16==0){
                        cli_putstr_P(PSTR("\r\n    "));
                }
@@ -75,10 +68,10 @@ void dsa_print_item(bigint_t* a, PGM_P pstr){
        cli_hexdump(p, 1);
 }
 
-void dsa_print_signature_b64(dsa_signature_ts){
+void dsa_print_signature_b64(dsa_signature_t *s){
        uint16_t size_r, size_s, size_o, i,j;
-       size_r = s->r.length_B +2;
-       size_s = s->s.length_B +2;
+       size_r = s->r.length_W +2;
+       size_s = s->s.length_W +2;
        size_o = size_r + size_s +2;
        uint8_t bin_b[size_o];
        bin_b[0] = 0x30;
@@ -86,12 +79,12 @@ void dsa_print_signature_b64(dsa_signature_t* s){
        bin_b[2] = 0x02;
        bin_b[3] = size_r-2;
        j=4;
-       for(i=s->r.length_B; i>0;  --i){
+       for(i=s->r.length_W; i>0;  --i){
                bin_b[j++] = s->r.wordv[i-1];
        }
        bin_b[j++] = 0x02;
        bin_b[j++] = size_s -2;
-       for(i=s->s.length_B; i>0;  --i){
+       for(i=s->s.length_W; i>0;  --i){
                bin_b[j++] = s->s.wordv[i-1];
        }
        char b64_b[size_o*4/3+5];
@@ -99,7 +92,7 @@ void dsa_print_signature_b64(dsa_signature_t* s){
        cli_putstr(b64_b);
 }
 
-void dsa_print_ctx(dsa_ctx_tctx){
+void dsa_print_ctx(dsa_ctx_t *ctx){
        dsa_print_item(&(ctx->priv), PSTR("private"));
        dsa_print_item(&(ctx->pub), PSTR("public"));
        dsa_print_item(&(ctx->domain.p), PSTR("P"));
@@ -107,7 +100,7 @@ void dsa_print_ctx(dsa_ctx_t* ctx){
        dsa_print_item(&(ctx->domain.g), PSTR("G"));
 }
 
-void dsa_print_signature(const dsa_signature_tsig){
+void dsa_print_signature(const dsa_signature_t *sig){
        cli_putstr_P(PSTR("\r\nDSA-Signature:\r\n r:"));
        bigint_print_hex(&(sig->r));
        cli_putstr_P(PSTR("\r\n s:"));
@@ -118,8 +111,8 @@ void quick_test(void){
        dsa_signature_t dsa_sig;
        uint8_t i, t=0, message[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
        load_fix_dsa();
-       uint8_t dsa_sig_s_b[dsa_ctx.domain.q.length_B],
-               dsa_sig_r_b[dsa_ctx.domain.q.length_B];
+       uint8_t dsa_sig_s_b[dsa_ctx.domain.q.length_W],
+               dsa_sig_r_b[dsa_ctx.domain.q.length_W];
        dsa_print_ctx(&dsa_ctx);
        dsa_sig.r.wordv = dsa_sig_r_b;
        dsa_sig.s.wordv = dsa_sig_s_b;
@@ -169,7 +162,7 @@ const char quick_test_str[]       PROGMEM = "quick-test";
 const char performance_str[]      PROGMEM = "performance";
 const char echo_str[]             PROGMEM = "echo";
 
-cmdlist_entry_t cmdlist[] PROGMEM = {
+const const cmdlist_entry_t cmdlist[] PROGMEM = {
        { reset_prng_str,       NULL, reset_prng                    },
        { quick_test_str,       NULL, quick_test                    },
        { performance_str,      NULL, testrun_performance_bigint    },
@@ -178,14 +171,10 @@ cmdlist_entry_t cmdlist[] PROGMEM = {
 };
 
 int main (void){
-       DEBUG_INIT();
-
-       cli_rx = (cli_rx_fpt)uart0_getc;
-       cli_tx = (cli_tx_fpt)uart0_putc;
-       for(;;){
-               cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
-               cli_putstr(algo_name);
-               cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
-               cmd_interface(cmdlist);
+    main_setup();
+
+    for(;;){
+        welcome_msg(algo_name);
+        cmd_interface(cmdlist);
        }
 }