commit
824c7bf16a
@ -100,6 +100,13 @@ int rsa_exptmod(const unsigned char *in, unsigned long inlen,
|
|||||||
}
|
}
|
||||||
#endif /* LTC_RSA_BLINDING */
|
#endif /* LTC_RSA_BLINDING */
|
||||||
|
|
||||||
|
if ((key->dP == NULL) || (mp_get_digit_count(key->dP) == 0)) {
|
||||||
|
/*
|
||||||
|
* In case CRT optimization parameters are not provided,
|
||||||
|
* the private key is directly used to exptmod it
|
||||||
|
*/
|
||||||
|
if ((err = mp_exptmod(tmp, key->d, key->N, tmp)) != CRYPT_OK) { goto error; }
|
||||||
|
} else {
|
||||||
/* tmpa = tmp^dP mod p */
|
/* tmpa = tmp^dP mod p */
|
||||||
if ((err = mp_exptmod(tmp, key->dP, key->p, tmpa)) != CRYPT_OK) { goto error; }
|
if ((err = mp_exptmod(tmp, key->dP, key->p, tmpa)) != CRYPT_OK) { goto error; }
|
||||||
|
|
||||||
@ -113,6 +120,7 @@ int rsa_exptmod(const unsigned char *in, unsigned long inlen,
|
|||||||
/* tmp = tmpb + q * tmp */
|
/* tmp = tmpb + q * tmp */
|
||||||
if ((err = mp_mul(tmp, key->q, tmp)) != CRYPT_OK) { goto error; }
|
if ((err = mp_mul(tmp, key->q, tmp)) != CRYPT_OK) { goto error; }
|
||||||
if ((err = mp_add(tmp, tmpb, tmp)) != CRYPT_OK) { goto error; }
|
if ((err = mp_add(tmp, tmpb, tmp)) != CRYPT_OK) { goto error; }
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef LTC_RSA_BLINDING
|
#ifdef LTC_RSA_BLINDING
|
||||||
/* unblind */
|
/* unblind */
|
||||||
|
@ -291,6 +291,26 @@ for (cnt = 0; cnt < len; ) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* verify with privKey but remove pointer to dP to test without CRT */
|
||||||
|
|
||||||
|
void* dP = privKey.dP;
|
||||||
|
privKey.dP = NULL;
|
||||||
|
/* change byte back to original */
|
||||||
|
in[0] ^= 1;
|
||||||
|
DO(rsa_verify_hash(out, len, in, 20, hash_idx, 0, &stat, &privKey));
|
||||||
|
/* change a byte */
|
||||||
|
in[0] ^= 1;
|
||||||
|
DO(rsa_verify_hash(out, len, in, 20, hash_idx, 0, &stat2, &privKey));
|
||||||
|
|
||||||
|
if (!(stat == 1 && stat2 == 0)) {
|
||||||
|
fprintf(stderr, "rsa_verify_hash (unsalted, privKey) failed, %d, %d", stat, stat2);
|
||||||
|
rsa_free(&key);
|
||||||
|
rsa_free(&pubKey);
|
||||||
|
rsa_free(&privKey);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
privKey.dP = dP;
|
||||||
|
|
||||||
/* verify with pubKey */
|
/* verify with pubKey */
|
||||||
/* change byte back to original */
|
/* change byte back to original */
|
||||||
in[0] ^= 1;
|
in[0] ^= 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user