X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=rsa%2Frsa_pkcs15.c;h=1db7d3ff29e991fc485f79d4393192630c6ee56a;hb=e5296441c98c35140f909ca1dbdb8d6852f996d3;hp=781c9badee0844baa14230d31b7cdba0786a0112;hpb=3edc70ba3f2306ec503fb5e99858d28659dcac65;p=arm-crypto-lib.git diff --git a/rsa/rsa_pkcs15.c b/rsa/rsa_pkcs15.c index 781c9ba..1db7d3f 100644 --- a/rsa/rsa_pkcs15.c +++ b/rsa/rsa_pkcs15.c @@ -23,22 +23,35 @@ #include "bigint.h" #include "rsa_basic.h" +#define DEBUG 0 + +#if DEBUG #include "bigint_io.h" #include "cli.h" +#endif #include "random_dummy.h" +uint16_t rsa_pkcs15_compute_padlength_B(bigint_t* modulus, uint16_t msg_length_B){ + return bigint_get_first_set_bit(modulus) / 8 + 1 - msg_length_B - 3; +} + uint8_t rsa_encrypt_pkcs15(void* dest, uint16_t* out_length, const void* src, uint16_t length_B, rsa_publickey_t* key, const void* pad){ int16_t pad_length; bigint_t x; - pad_length = (bigint_get_first_set_bit(key->modulus) + 7) / 8 - length_B - 3; + pad_length = rsa_pkcs15_compute_padlength_B(key->modulus, length_B); if(pad_length<8){ +#if DEBUG cli_putstr("\r\nERROR: pad_length<8; pad_length: "); cli_hexdump_rev(&pad_length, 2); +#endif return 2; /* message to long */ } if(!pad){ +#if DEBUG + cli_putstr("\r\nauto-generating pad ..."); +#endif uint16_t i; uint8_t c; for(i=0; i=m_length){ + if(idx>=m_length){ return 1; } + if(((uint8_t*)x.wordv)[idx]!=2){ + return 3; + } + ++idx; while(((uint8_t*)x.wordv)[idx+pad_length]!=0 && (idx+pad_length)