| OLD | NEW |
| 1 /* crypto/ec/ecp_nist.c */ | 1 /* crypto/ec/ecp_nist.c */ |
| 2 /* | 2 /* |
| 3 * Written by Nils Larsch for the OpenSSL project. | 3 * Written by Nils Larsch for the OpenSSL project. |
| 4 */ | 4 */ |
| 5 /* ==================================================================== | 5 /* ==================================================================== |
| 6 * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved. | 6 * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved. |
| 7 * | 7 * |
| 8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
| 9 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
| 10 * are met: | 10 * are met: |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 ec_GFp_nist_field_mul, | 105 ec_GFp_nist_field_mul, |
| 106 ec_GFp_nist_field_sqr, | 106 ec_GFp_nist_field_sqr, |
| 107 0 /* field_div */, | 107 0 /* field_div */, |
| 108 0 /* field_encode */, | 108 0 /* field_encode */, |
| 109 0 /* field_decode */, | 109 0 /* field_decode */, |
| 110 0 /* field_set_to_one */ }; | 110 0 /* field_set_to_one */ }; |
| 111 | 111 |
| 112 return &ret; | 112 return &ret; |
| 113 } | 113 } |
| 114 | 114 |
| 115 #if BN_BITS2 == 64 | |
| 116 #define NO_32_BIT_TYPE | |
| 117 #endif | |
| 118 | |
| 119 int ec_GFp_nist_group_copy(EC_GROUP *dest, const EC_GROUP *src) | 115 int ec_GFp_nist_group_copy(EC_GROUP *dest, const EC_GROUP *src) |
| 120 { | 116 { |
| 121 dest->field_mod_func = src->field_mod_func; | 117 dest->field_mod_func = src->field_mod_func; |
| 122 | 118 |
| 123 return ec_GFp_simple_group_copy(dest, src); | 119 return ec_GFp_simple_group_copy(dest, src); |
| 124 } | 120 } |
| 125 | 121 |
| 126 int ec_GFp_nist_group_set_curve(EC_GROUP *group, const BIGNUM *p, | 122 int ec_GFp_nist_group_set_curve(EC_GROUP *group, const BIGNUM *p, |
| 127 const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) | 123 const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) |
| 128 { | 124 { |
| 129 int ret = 0; | 125 int ret = 0; |
| 130 BN_CTX *new_ctx = NULL; | 126 BN_CTX *new_ctx = NULL; |
| 131 BIGNUM *tmp_bn; | 127 BIGNUM *tmp_bn; |
| 132 | 128 |
| 133 if (ctx == NULL) | 129 if (ctx == NULL) |
| 134 if ((ctx = new_ctx = BN_CTX_new()) == NULL) return 0; | 130 if ((ctx = new_ctx = BN_CTX_new()) == NULL) return 0; |
| 135 | 131 |
| 136 BN_CTX_start(ctx); | 132 BN_CTX_start(ctx); |
| 137 if ((tmp_bn = BN_CTX_get(ctx)) == NULL) goto err; | 133 if ((tmp_bn = BN_CTX_get(ctx)) == NULL) goto err; |
| 138 | 134 |
| 139 if (BN_ucmp(BN_get0_nist_prime_192(), p) == 0) | 135 if (BN_ucmp(BN_get0_nist_prime_192(), p) == 0) |
| 140 group->field_mod_func = BN_nist_mod_192; | 136 group->field_mod_func = BN_nist_mod_192; |
| 141 else if (BN_ucmp(BN_get0_nist_prime_224(), p) == 0) | 137 else if (BN_ucmp(BN_get0_nist_prime_224(), p) == 0) |
| 142 { | |
| 143 #ifndef NO_32_BIT_TYPE | |
| 144 group->field_mod_func = BN_nist_mod_224; | 138 group->field_mod_func = BN_nist_mod_224; |
| 145 #else | |
| 146 ECerr(EC_F_EC_GFP_NIST_GROUP_SET_CURVE, EC_R_NOT_A_SUPPORTED_NIS
T_PRIME); | |
| 147 goto err; | |
| 148 #endif | |
| 149 } | |
| 150 else if (BN_ucmp(BN_get0_nist_prime_256(), p) == 0) | 139 else if (BN_ucmp(BN_get0_nist_prime_256(), p) == 0) |
| 151 { | |
| 152 #ifndef NO_32_BIT_TYPE | |
| 153 group->field_mod_func = BN_nist_mod_256; | 140 group->field_mod_func = BN_nist_mod_256; |
| 154 #else | |
| 155 ECerr(EC_F_EC_GFP_NIST_GROUP_SET_CURVE, EC_R_NOT_A_SUPPORTED_NIS
T_PRIME); | |
| 156 goto err; | |
| 157 #endif | |
| 158 } | |
| 159 else if (BN_ucmp(BN_get0_nist_prime_384(), p) == 0) | 141 else if (BN_ucmp(BN_get0_nist_prime_384(), p) == 0) |
| 160 { | |
| 161 #ifndef NO_32_BIT_TYPE | |
| 162 group->field_mod_func = BN_nist_mod_384; | 142 group->field_mod_func = BN_nist_mod_384; |
| 163 #else | |
| 164 ECerr(EC_F_EC_GFP_NIST_GROUP_SET_CURVE, EC_R_NOT_A_SUPPORTED_NIS
T_PRIME); | |
| 165 goto err; | |
| 166 #endif | |
| 167 } | |
| 168 else if (BN_ucmp(BN_get0_nist_prime_521(), p) == 0) | 143 else if (BN_ucmp(BN_get0_nist_prime_521(), p) == 0) |
| 169 /* this one works in the NO_32_BIT_TYPE case */ | |
| 170 group->field_mod_func = BN_nist_mod_521; | 144 group->field_mod_func = BN_nist_mod_521; |
| 171 else | 145 else |
| 172 { | 146 { |
| 173 ECerr(EC_F_EC_GFP_NIST_GROUP_SET_CURVE, EC_R_NOT_A_NIST_PRIME); | 147 ECerr(EC_F_EC_GFP_NIST_GROUP_SET_CURVE, EC_R_NOT_A_NIST_PRIME); |
| 174 goto err; | 148 goto err; |
| 175 } | 149 } |
| 176 | 150 |
| 177 ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx); | 151 ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx); |
| 178 | 152 |
| 179 err: | 153 err: |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 if (!BN_sqr(r, a, ctx)) goto err; | 201 if (!BN_sqr(r, a, ctx)) goto err; |
| 228 if (!group->field_mod_func(r, r, &group->field, ctx)) | 202 if (!group->field_mod_func(r, r, &group->field, ctx)) |
| 229 goto err; | 203 goto err; |
| 230 | 204 |
| 231 ret=1; | 205 ret=1; |
| 232 err: | 206 err: |
| 233 if (ctx_new) | 207 if (ctx_new) |
| 234 BN_CTX_free(ctx_new); | 208 BN_CTX_free(ctx_new); |
| 235 return ret; | 209 return ret; |
| 236 } | 210 } |
| OLD | NEW |