|
53 | 53 | #endif |
54 | 54 | #endif |
55 | 55 |
|
| 56 | +#if defined(WC_RSA_BLINDING) && (!defined(HAVE_FIPS) || \ |
| 57 | + (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) |
| 58 | +#define WOLFPKCS11_NEED_RSA_RNG |
| 59 | +#endif |
| 60 | + |
56 | 61 | /* Size of hash calculated from PIN. */ |
57 | 62 | #define PIN_HASH_SZ 32 |
58 | 63 | /* Size of seed used when calculating hash from PIN. */ |
@@ -6503,26 +6508,23 @@ int WP11_RsaPkcs15_PrivateDecrypt(unsigned char* in, word32 inLen, |
6503 | 6508 | WP11_Object* priv, WP11_Slot* slot) |
6504 | 6509 | { |
6505 | 6510 | int ret = 0; |
6506 | | -#if defined(WC_RSA_BLINDING) && (!defined(HAVE_FIPS) || \ |
6507 | | - (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) |
| 6511 | +#ifdef WOLFPKCS11_NEED_RSA_RNG |
6508 | 6512 | WC_RNG rng; |
6509 | 6513 | #endif |
6510 | 6514 | /* A random number generator is needed for blinding. */ |
6511 | 6515 | if (priv->onToken) |
6512 | 6516 | WP11_Lock_LockRW(priv->lock); |
6513 | | -#if defined(WC_RSA_BLINDING) && (!defined(HAVE_FIPS) || \ |
6514 | | - (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) |
| 6517 | +#ifdef WOLFPKCS11_NEED_RSA_RNG |
6515 | 6518 | ret = Rng_New(&slot->token.rng, &slot->token.rngLock, &rng); |
6516 | | - if (ret == 0) { |
6517 | | - priv->data.rsaKey.rng = &rng; |
6518 | | - } |
6519 | 6519 | #endif |
6520 | 6520 | if (ret == 0) { |
| 6521 | + #ifdef WOLFPKCS11_NEED_RSA_RNG |
| 6522 | + priv->data.rsaKey.rng = &rng; |
| 6523 | + #endif |
6521 | 6524 | ret = wc_RsaPrivateDecrypt_ex(in, inLen, out, *outLen, |
6522 | 6525 | &priv->data.rsaKey, WC_RSA_PKCSV15_PAD, |
6523 | 6526 | WC_HASH_TYPE_NONE, WC_MGF1NONE, NULL, 0); |
6524 | | - #if defined(WC_RSA_BLINDING) && (!defined(HAVE_FIPS) || \ |
6525 | | - (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) |
| 6527 | + #ifdef WOLFPKCS11_NEED_RSA_RNG |
6526 | 6528 | priv->data.rsaKey.rng = NULL; |
6527 | 6529 | Rng_Free(&rng); |
6528 | 6530 | #endif |
@@ -6607,28 +6609,25 @@ int WP11_RsaOaep_PrivateDecrypt(unsigned char* in, word32 inLen, |
6607 | 6609 | int ret = 0; |
6608 | 6610 | WP11_OaepParams* oaep = &session->params.oaep; |
6609 | 6611 | WP11_Slot* slot = WP11_Session_GetSlot(session); |
6610 | | -#if defined(WC_RSA_BLINDING) && (!defined(HAVE_FIPS) || \ |
6611 | | - (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) |
| 6612 | +#ifdef WOLFPKCS11_NEED_RSA_RNG |
6612 | 6613 | WC_RNG rng; |
6613 | 6614 | #endif |
6614 | 6615 |
|
6615 | 6616 | /* A random number generator is needed for blinding. */ |
6616 | 6617 | if (priv->onToken) |
6617 | 6618 | WP11_Lock_LockRW(priv->lock); |
6618 | | -#if defined(WC_RSA_BLINDING) && (!defined(HAVE_FIPS) || \ |
6619 | | - (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) |
| 6619 | +#ifdef WOLFPKCS11_NEED_RSA_RNG |
6620 | 6620 | ret = Rng_New(&slot->token.rng, &slot->token.rngLock, &rng); |
6621 | | - if (ret == 0) { |
6622 | | - priv->data.rsaKey.rng = &rng; |
6623 | | - } |
6624 | 6621 | #endif |
6625 | 6622 | if (ret == 0) { |
| 6623 | + #ifdef WOLFPKCS11_NEED_RSA_RNG |
| 6624 | + priv->data.rsaKey.rng = &rng; |
| 6625 | + #endif |
6626 | 6626 | ret = wc_RsaPrivateDecrypt_ex(in, inLen, out, *outLen, |
6627 | 6627 | &priv->data.rsaKey, WC_RSA_OAEP_PAD, |
6628 | 6628 | oaep->hashType, oaep->mgf, |
6629 | 6629 | oaep->label, oaep->labelSz); |
6630 | | - #if defined(WC_RSA_BLINDING) && (!defined(HAVE_FIPS) || \ |
6631 | | - (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) |
| 6630 | + #ifdef WOLFPKCS11_NEED_RSA_RNG |
6632 | 6631 | priv->data.rsaKey.rng = NULL; |
6633 | 6632 | Rng_Free(&rng); |
6634 | 6633 | #endif |
|
0 commit comments