diff options
Diffstat (limited to 'src/lib/libcrypto/rsa/rsa_chk.c')
| -rw-r--r-- | src/lib/libcrypto/rsa/rsa_chk.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_chk.c b/src/lib/libcrypto/rsa/rsa_chk.c index 54113f89f6..0f9e0944db 100644 --- a/src/lib/libcrypto/rsa/rsa_chk.c +++ b/src/lib/libcrypto/rsa/rsa_chk.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: rsa_chk.c,v 1.7 2014/07/09 08:20:08 miod Exp $ */ | 1 | /* $OpenBSD: rsa_chk.c,v 1.8 2014/07/09 19:51:38 jsing Exp $ */ |
| 2 | /* ==================================================================== | 2 | /* ==================================================================== |
| 3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. |
| 4 | * | 4 | * |
| @@ -7,7 +7,7 @@ | |||
| 7 | * are met: | 7 | * are met: |
| 8 | * | 8 | * |
| 9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * | 11 | * |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in | 13 | * notice, this list of conditions and the following disclaimer in |
| @@ -65,7 +65,7 @@ RSA_check_key(const RSA *key) | |||
| 65 | RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_VALUE_MISSING); | 65 | RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_VALUE_MISSING); |
| 66 | return 0; | 66 | return 0; |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | i = BN_new(); | 69 | i = BN_new(); |
| 70 | j = BN_new(); | 70 | j = BN_new(); |
| 71 | k = BN_new(); | 71 | k = BN_new(); |
| @@ -78,7 +78,7 @@ RSA_check_key(const RSA *key) | |||
| 78 | RSAerr(RSA_F_RSA_CHECK_KEY, ERR_R_MALLOC_FAILURE); | 78 | RSAerr(RSA_F_RSA_CHECK_KEY, ERR_R_MALLOC_FAILURE); |
| 79 | goto err; | 79 | goto err; |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | /* p prime? */ | 82 | /* p prime? */ |
| 83 | r = BN_is_prime_ex(key->p, BN_prime_checks, NULL, NULL); | 83 | r = BN_is_prime_ex(key->p, BN_prime_checks, NULL, NULL); |
| 84 | if (r != 1) { | 84 | if (r != 1) { |
| @@ -87,7 +87,7 @@ RSA_check_key(const RSA *key) | |||
| 87 | goto err; | 87 | goto err; |
| 88 | RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_P_NOT_PRIME); | 88 | RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_P_NOT_PRIME); |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | /* q prime? */ | 91 | /* q prime? */ |
| 92 | r = BN_is_prime_ex(key->q, BN_prime_checks, NULL, NULL); | 92 | r = BN_is_prime_ex(key->q, BN_prime_checks, NULL, NULL); |
| 93 | if (r != 1) { | 93 | if (r != 1) { |
| @@ -96,19 +96,19 @@ RSA_check_key(const RSA *key) | |||
| 96 | goto err; | 96 | goto err; |
| 97 | RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_Q_NOT_PRIME); | 97 | RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_Q_NOT_PRIME); |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | /* n = p*q? */ | 100 | /* n = p*q? */ |
| 101 | r = BN_mul(i, key->p, key->q, ctx); | 101 | r = BN_mul(i, key->p, key->q, ctx); |
| 102 | if (!r) { | 102 | if (!r) { |
| 103 | ret = -1; | 103 | ret = -1; |
| 104 | goto err; | 104 | goto err; |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | if (BN_cmp(i, key->n) != 0) { | 107 | if (BN_cmp(i, key->n) != 0) { |
| 108 | ret = 0; | 108 | ret = 0; |
| 109 | RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_N_DOES_NOT_EQUAL_P_Q); | 109 | RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_N_DOES_NOT_EQUAL_P_Q); |
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | /* d*e = 1 mod lcm(p-1,q-1)? */ | 112 | /* d*e = 1 mod lcm(p-1,q-1)? */ |
| 113 | 113 | ||
| 114 | r = BN_sub(i, key->p, BN_value_one()); | 114 | r = BN_sub(i, key->p, BN_value_one()); |
| @@ -149,7 +149,7 @@ RSA_check_key(const RSA *key) | |||
| 149 | ret = 0; | 149 | ret = 0; |
| 150 | RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_D_E_NOT_CONGRUENT_TO_1); | 150 | RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_D_E_NOT_CONGRUENT_TO_1); |
| 151 | } | 151 | } |
| 152 | 152 | ||
| 153 | if (key->dmp1 != NULL && key->dmq1 != NULL && key->iqmp != NULL) { | 153 | if (key->dmp1 != NULL && key->dmq1 != NULL && key->iqmp != NULL) { |
| 154 | /* dmp1 = d mod (p-1)? */ | 154 | /* dmp1 = d mod (p-1)? */ |
| 155 | r = BN_sub(i, key->p, BN_value_one()); | 155 | r = BN_sub(i, key->p, BN_value_one()); |
| @@ -169,14 +169,14 @@ RSA_check_key(const RSA *key) | |||
| 169 | RSAerr(RSA_F_RSA_CHECK_KEY, | 169 | RSAerr(RSA_F_RSA_CHECK_KEY, |
| 170 | RSA_R_DMP1_NOT_CONGRUENT_TO_D); | 170 | RSA_R_DMP1_NOT_CONGRUENT_TO_D); |
| 171 | } | 171 | } |
| 172 | 172 | ||
| 173 | /* dmq1 = d mod (q-1)? */ | 173 | /* dmq1 = d mod (q-1)? */ |
| 174 | r = BN_sub(i, key->q, BN_value_one()); | 174 | r = BN_sub(i, key->q, BN_value_one()); |
| 175 | if (!r) { | 175 | if (!r) { |
| 176 | ret = -1; | 176 | ret = -1; |
| 177 | goto err; | 177 | goto err; |
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | r = BN_mod(j, key->d, i, ctx); | 180 | r = BN_mod(j, key->d, i, ctx); |
| 181 | if (!r) { | 181 | if (!r) { |
| 182 | ret = -1; | 182 | ret = -1; |
| @@ -188,7 +188,7 @@ RSA_check_key(const RSA *key) | |||
| 188 | RSAerr(RSA_F_RSA_CHECK_KEY, | 188 | RSAerr(RSA_F_RSA_CHECK_KEY, |
| 189 | RSA_R_DMQ1_NOT_CONGRUENT_TO_D); | 189 | RSA_R_DMQ1_NOT_CONGRUENT_TO_D); |
| 190 | } | 190 | } |
| 191 | 191 | ||
| 192 | /* iqmp = q^-1 mod p? */ | 192 | /* iqmp = q^-1 mod p? */ |
| 193 | if (!BN_mod_inverse(i, key->q, key->p, ctx)) { | 193 | if (!BN_mod_inverse(i, key->q, key->p, ctx)) { |
| 194 | ret = -1; | 194 | ret = -1; |
| @@ -202,7 +202,7 @@ RSA_check_key(const RSA *key) | |||
| 202 | } | 202 | } |
| 203 | } | 203 | } |
| 204 | 204 | ||
| 205 | err: | 205 | err: |
| 206 | if (i != NULL) | 206 | if (i != NULL) |
| 207 | BN_free(i); | 207 | BN_free(i); |
| 208 | if (j != NULL) | 208 | if (j != NULL) |
