]> git.cryptolib.org Git - avr-crypto-lib.git/blobdiff - test_src/main-rsaes_pkcs1v15-test.c
fixing E-Mail-Address & Copyright
[avr-crypto-lib.git] / test_src / main-rsaes_pkcs1v15-test.c
index a5a3a88e93863cd2af028d3efad44f697286c937..ad2ecae206a472e48335ba78f6a4343107980506 100644 (file)
@@ -1,7 +1,7 @@
 /* main-dsa-test.c */
 /*
     This file is part of the ARM-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
@@ -32,9 +32,9 @@
 
 #include "performance_test.h"
 
-#define DEBUG 0
+#define DEBUG 1
 
-const charalgo_name = "RSAES-PKCS1V15";
+const char *algo_name = "RSAES-PKCS1V15";
 
 #define BIGINT_CEIL(x) ((((x) + sizeof(bigint_word_t) - 1) / sizeof(bigint_word_t)) *  sizeof(bigint_word_t))
 #define BIGINT_OFF(x) ((sizeof(bigint_word_t) - (x) % sizeof(bigint_word_t)) % sizeof(bigint_word_t))
@@ -174,7 +174,7 @@ uint8_t convert_nibble(uint8_t c){
 
 const char *block_ignore_string=" \t\r\n,;";
 #define BUFFER_LIMIT 120
-uint16_t read_os(void* dst, uint16_t length, const char* ignore_string){
+uint16_t read_os(void *dst, uint16_t length, const char *ignore_string){
        uint16_t counter = 0;
        uint16_t c;
        uint8_t v, tmp = 0, idx = 0;
@@ -207,7 +207,7 @@ uint16_t read_os(void* dst, uint16_t length, const char* ignore_string){
        return counter;
 }
 
-uint16_t own_atou(const charstr){
+uint16_t own_atou(const char *str){
        uint16_t r=0;
        while(*str && *str >= '0' && *str <= '9'){
                r *= 10;
@@ -216,7 +216,7 @@ uint16_t own_atou(const char* str){
        return r;
 }
 
-uint8_t read_bigint(bigint_t* a, char* prompt){
+uint8_t read_bigint(bigint_t *a, char *prompt){
        uint16_t read_length, actual_length;
        uint8_t off;
        uint8_t *buffer;
@@ -240,7 +240,7 @@ uint8_t read_bigint(bigint_t* a, char* prompt){
                return 1;
        }
        a->wordv = (bigint_word_t*)buffer;
-       a->length_B = (read_length + sizeof(bigint_word_t) - 1) / sizeof(bigint_word_t);
+       a->length_W = (read_length + sizeof(bigint_word_t) - 1) / sizeof(bigint_word_t);
        a->info = 0;
        bigint_changeendianess(a);
        bigint_adjust(a);
@@ -308,8 +308,8 @@ uint8_t read_key_conv(void){
        return r;
 }
 
-uint8_t load_bigint_from_os(bigint_ta, PGM_VOID_P os, uint16_t length_B){
-       a->length_B = BIGINT_CEIL(length_B) / sizeof(bigint_word_t);
+uint8_t load_bigint_from_os(bigint_t *a, PGM_VOID_P os, uint16_t length_B){
+       a->length_W = BIGINT_CEIL(length_B) / sizeof(bigint_word_t);
        a->wordv = malloc(BIGINT_CEIL(length_B));
        if(!a->wordv){
                cli_putstr_P(PSTR("\r\nOOM!\r\n"));
@@ -474,8 +474,8 @@ void load_priv_conventional(void){
                cli_putstr_P(PSTR("\r\nERROR: OOM!"));
                return;
        }
-       epriv->length_B = (sizeof(PRIV_EXPONENT) + sizeof(bigint_word_t) - 1) / sizeof(bigint_word_t);
-       epriv->wordv =  malloc(epriv->length_B * sizeof(bigint_word_t));
+       epriv->length_W = (sizeof(PRIV_EXPONENT) + sizeof(bigint_word_t) - 1) / sizeof(bigint_word_t);
+       epriv->wordv =  malloc(epriv->length_W * sizeof(bigint_word_t));
        if(!epriv->wordv){
                cli_putstr_P(PSTR("\r\nERROR: OOM!"));
                return;
@@ -508,8 +508,8 @@ void load_priv_crt_mono(void){
        for(i=0; i<5; ++i){
                v[i] = malloc(sizeof(bigint_t));
                v[i]->info = 0;
-               v[i]->length_B = (sv[i] + sizeof(bigint_word_t) - 1) / sizeof(bigint_word_t);
-               v[i]->wordv = calloc(v[i]->length_B , sizeof(bigint_word_t));
+               v[i]->length_W = (sv[i] + sizeof(bigint_word_t) - 1) / sizeof(bigint_word_t);
+               v[i]->wordv = calloc(v[i]->length_W , sizeof(bigint_word_t));
                if(!v[i]->wordv){
                        cli_putstr_P(PSTR("\r\nERROR: OOM!"));
                        return;
@@ -521,8 +521,8 @@ void load_priv_crt_mono(void){
        }
 }
 
-uint8_t load_bigint_from_os(bigint_ta, PGM_VOID_P os, uint16_t length_B){
-       a->length_B = BIGINT_CEIL(length_B) / sizeof(bigint_word_t);
+uint8_t load_bigint_from_os(bigint_t *a, PGM_VOID_P os, uint16_t length_B){
+       a->length_W = BIGINT_CEIL(length_B) / sizeof(bigint_word_t);
        a->wordv = malloc(BIGINT_CEIL(length_B));
        if(!a->wordv){
                cli_putstr_P(PSTR("\r\nOOM!\r\n"));
@@ -588,11 +588,13 @@ void quick_test(void){
 
        cli_putstr_P(PSTR("\r\n\r\nciphertext:"));
        cli_hexdump_block(ciphertext, clen, 4, 16);
-       if(clen!=sizeof(ENCRYPTED)){
+       if(clen != sizeof(ENCRYPTED)){
                        cli_putstr_P(PSTR("\r\n>>FAIL (no size match)<<"));
+                       return;
        }else{
                if(memcmp_P(ciphertext, ENCRYPTED, clen)){
                        cli_putstr_P(PSTR("\r\n>>FAIL (no content match)<<"));
+                       return;
                }else{
                        cli_putstr_P(PSTR("\r\n>>OK<<"));
                }
@@ -663,7 +665,7 @@ void run_seed_test(void){
                cli_putstr_P(PSTR("\r\nERROR: OOM!"));
                return;
        }
-       msg_ = malloc(bigint_length_B(&pub_key.modulus) + sizeof(bigint_word_t));
+       msg_ = malloc(bigint_length_B(&pub_key.modulus) /* + sizeof(bigint_word_t) */ );
 #if DEBUG
        cli_putstr_P(PSTR("\r\nDBG: @msg_: 0x"));
        cli_hexdump_rev(&msg_, 2);