#include "performance_test.h"
-#define DEBUG 0
+#define DEBUG 1
-const char* algo_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))
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;
return counter;
}
-uint16_t own_atou(const char* str){
+uint16_t own_atou(const char *str){
uint16_t r=0;
while(*str && *str >= '0' && *str <= '9'){
r *= 10;
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;
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);
return r;
}
-uint8_t load_bigint_from_os(bigint_t* a, 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"));
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;
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;
}
}
-uint8_t load_bigint_from_os(bigint_t* a, 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"));
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<<"));
}
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);