X-Git-Url: https://git.cryptolib.org/?p=arm-crypto-lib.git;a=blobdiff_plain;f=rsa%2Frsa_basic.c;h=e71bc8cede1c23c3ff40aa3c2b8981d39fb84fdc;hp=38c46a1f630fb68dd0fc78dc429fc12ea61198c1;hb=73f474e8fea34667e788ff4ec24de552e9d1d9e8;hpb=6095187b080b960d111a54f18a3b2da788d2d59d diff --git a/rsa/rsa_basic.c b/rsa/rsa_basic.c index 38c46a1..e71bc8c 100644 --- a/rsa/rsa_basic.c +++ b/rsa/rsa_basic.c @@ -24,8 +24,12 @@ #include "bigint_io.h" #include "rsa_basic.h" +#define DEBUG 0 + +#if DEBUG #include "cli.h" #include "uart_lowlevel.h" +#endif void rsa_enc(bigint_t* data, rsa_publickey_t* key){ /* @@ -52,18 +56,29 @@ uint8_t rsa_dec_crt_mono(bigint_t* data, rsa_privatekey_t* key){ m1.wordv = malloc(key->components[0]->length_B * sizeof(bigint_word_t)); m2.wordv = malloc(key->components[1]->length_B * sizeof(bigint_word_t)); if(!m1.wordv || !m2.wordv){ +#if DEBUG cli_putstr("\r\nERROR: OOM!"); +#endif free(m1.wordv); free(m2.wordv); return 1; } +#if DEBUG + cli_putstr("\r\nDBG: expmod m1 ..."); +#endif bigint_expmod_u(&m1, data, key->components[2], key->components[0]); +#if DEBUG + cli_putstr("expmod m2 ..."); +#endif bigint_expmod_u(&m2, data, key->components[3], key->components[1]); bigint_sub_s(&m1, &m1, &m2); while(BIGINT_NEG_MASK & m1.info){ bigint_add_s(&m1, &m1, key->components[0]); } +#if DEBUG + cli_putstr("\r\nDBG: reduce-mul ..."); +#endif bigint_reduce(&m1, key->components[0]); bigint_mul_u(data, &m1, key->components[4]); bigint_reduce(data, key->components[0]);