| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | #include <stdlib.h> | - |
| 12 | | - |
| 13 | #include <openssl/obj_mac.h> | - |
| 14 | #include <openssl/ec.h> | - |
| 15 | #include <openssl/bn.h> | - |
| 16 | #include "internal/refcount.h" | - |
| 17 | #include "internal/ec_int.h" | - |
| 18 | #include "curve448/curve448_lcl.h" | - |
| 19 | | - |
| 20 | #if defined(__SUNPRO_C) | - |
| 21 | # if __SUNPRO_C >= 0x520 | - |
| 22 | # pragma error_messages (off,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE) | - |
| 23 | # endif | - |
| 24 | #endif | - |
| 25 | | - |
| 26 | | - |
| 27 | #define EC_FLAGS_DEFAULT_OCT 0x1 | - |
| 28 | | - |
| 29 | | - |
| 30 | #define EC_FLAGS_CUSTOM_CURVE 0x2 | - |
| 31 | | - |
| 32 | | - |
| 33 | #define EC_FLAGS_NO_SIGN 0x4 | - |
| 34 | | - |
| 35 | | - |
| 36 | | - |
| 37 | | - |
| 38 | | - |
| 39 | | - |
| 40 | struct ec_method_st { | - |
| 41 | | - |
| 42 | int flags; | - |
| 43 | | - |
| 44 | int field_type; | - |
| 45 | | - |
| 46 | | - |
| 47 | | - |
| 48 | | - |
| 49 | int (*group_init) (EC_GROUP *); | - |
| 50 | void (*group_finish) (EC_GROUP *); | - |
| 51 | void (*group_clear_finish) (EC_GROUP *); | - |
| 52 | int (*group_copy) (EC_GROUP *, const EC_GROUP *); | - |
| 53 | | - |
| 54 | int (*group_set_curve) (EC_GROUP *, const BIGNUM *p, const BIGNUM *a, | - |
| 55 | const BIGNUM *b, BN_CTX *); | - |
| 56 | int (*group_get_curve) (const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, | - |
| 57 | BN_CTX *); | - |
| 58 | | - |
| 59 | int (*group_get_degree) (const EC_GROUP *); | - |
| 60 | int (*group_order_bits) (const EC_GROUP *); | - |
| 61 | | - |
| 62 | int (*group_check_discriminant) (const EC_GROUP *, BN_CTX *); | - |
| 63 | | - |
| 64 | | - |
| 65 | | - |
| 66 | | - |
| 67 | int (*point_init) (EC_POINT *); | - |
| 68 | void (*point_finish) (EC_POINT *); | - |
| 69 | void (*point_clear_finish) (EC_POINT *); | - |
| 70 | int (*point_copy) (EC_POINT *, const EC_POINT *); | - |
| 71 | | - |
| 72 | | - |
| 73 | | - |
| 74 | | - |
| 75 | | - |
| 76 | | - |
| 77 | | - |
| 78 | | - |
| 79 | int (*point_set_to_infinity) (const EC_GROUP *, EC_POINT *); | - |
| 80 | int (*point_set_Jprojective_coordinates_GFp) (const EC_GROUP *, | - |
| 81 | EC_POINT *, const BIGNUM *x, | - |
| 82 | const BIGNUM *y, | - |
| 83 | const BIGNUM *z, BN_CTX *); | - |
| 84 | int (*point_get_Jprojective_coordinates_GFp) (const EC_GROUP *, | - |
| 85 | const EC_POINT *, BIGNUM *x, | - |
| 86 | BIGNUM *y, BIGNUM *z, | - |
| 87 | BN_CTX *); | - |
| 88 | int (*point_set_affine_coordinates) (const EC_GROUP *, EC_POINT *, | - |
| 89 | const BIGNUM *x, const BIGNUM *y, | - |
| 90 | BN_CTX *); | - |
| 91 | int (*point_get_affine_coordinates) (const EC_GROUP *, const EC_POINT *, | - |
| 92 | BIGNUM *x, BIGNUM *y, BN_CTX *); | - |
| 93 | int (*point_set_compressed_coordinates) (const EC_GROUP *, EC_POINT *, | - |
| 94 | const BIGNUM *x, int y_bit, | - |
| 95 | BN_CTX *); | - |
| 96 | | - |
| 97 | size_t (*point2oct) (const EC_GROUP *, const EC_POINT *, | - |
| 98 | point_conversion_form_t form, unsigned char *buf, | - |
| 99 | size_t len, BN_CTX *); | - |
| 100 | int (*oct2point) (const EC_GROUP *, EC_POINT *, const unsigned char *buf, | - |
| 101 | size_t len, BN_CTX *); | - |
| 102 | | - |
| 103 | int (*add) (const EC_GROUP *, EC_POINT *r, const EC_POINT *a, | - |
| 104 | const EC_POINT *b, BN_CTX *); | - |
| 105 | int (*dbl) (const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *); | - |
| 106 | int (*invert) (const EC_GROUP *, EC_POINT *, BN_CTX *); | - |
| 107 | | - |
| 108 | | - |
| 109 | | - |
| 110 | int (*is_at_infinity) (const EC_GROUP *, const EC_POINT *); | - |
| 111 | int (*is_on_curve) (const EC_GROUP *, const EC_POINT *, BN_CTX *); | - |
| 112 | int (*point_cmp) (const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, | - |
| 113 | BN_CTX *); | - |
| 114 | | - |
| 115 | int (*make_affine) (const EC_GROUP *, EC_POINT *, BN_CTX *); | - |
| 116 | int (*points_make_affine) (const EC_GROUP *, size_t num, EC_POINT *[], | - |
| 117 | BN_CTX *); | - |
| 118 | | - |
| 119 | | - |
| 120 | | - |
| 121 | | - |
| 122 | | - |
| 123 | | - |
| 124 | | - |
| 125 | | - |
| 126 | | - |
| 127 | | - |
| 128 | | - |
| 129 | | - |
| 130 | | - |
| 131 | | - |
| 132 | | - |
| 133 | | - |
| 134 | | - |
| 135 | | - |
| 136 | | - |
| 137 | | - |
| 138 | | - |
| 139 | | - |
| 140 | int (*mul) (const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, | - |
| 141 | size_t num, const EC_POINT *points[], const BIGNUM *scalars[], | - |
| 142 | BN_CTX *); | - |
| 143 | int (*precompute_mult) (EC_GROUP *group, BN_CTX *); | - |
| 144 | int (*have_precompute_mult) (const EC_GROUP *group); | - |
| 145 | | - |
| 146 | | - |
| 147 | | - |
| 148 | | - |
| 149 | | - |
| 150 | | - |
| 151 | | - |
| 152 | int (*field_mul) (const EC_GROUP *, BIGNUM *r, const BIGNUM *a, | - |
| 153 | const BIGNUM *b, BN_CTX *); | - |
| 154 | int (*field_sqr) (const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); | - |
| 155 | int (*field_div) (const EC_GROUP *, BIGNUM *r, const BIGNUM *a, | - |
| 156 | const BIGNUM *b, BN_CTX *); | - |
| 157 | | - |
| 158 | int (*field_encode) (const EC_GROUP *, BIGNUM *r, const BIGNUM *a, | - |
| 159 | BN_CTX *); | - |
| 160 | | - |
| 161 | int (*field_decode) (const EC_GROUP *, BIGNUM *r, const BIGNUM *a, | - |
| 162 | BN_CTX *); | - |
| 163 | int (*field_set_to_one) (const EC_GROUP *, BIGNUM *r, BN_CTX *); | - |
| 164 | | - |
| 165 | size_t (*priv2oct)(const EC_KEY *eckey, unsigned char *buf, size_t len); | - |
| 166 | int (*oct2priv)(EC_KEY *eckey, const unsigned char *buf, size_t len); | - |
| 167 | int (*set_private)(EC_KEY *eckey, const BIGNUM *priv_key); | - |
| 168 | int (*keygen)(EC_KEY *eckey); | - |
| 169 | int (*keycheck)(const EC_KEY *eckey); | - |
| 170 | int (*keygenpub)(EC_KEY *eckey); | - |
| 171 | int (*keycopy)(EC_KEY *dst, const EC_KEY *src); | - |
| 172 | void (*keyfinish)(EC_KEY *eckey); | - |
| 173 | | - |
| 174 | int (*ecdh_compute_key)(unsigned char **pout, size_t *poutlen, | - |
| 175 | const EC_POINT *pub_key, const EC_KEY *ecdh); | - |
| 176 | | - |
| 177 | int (*field_inverse_mod_ord)(const EC_GROUP *, BIGNUM *r, | - |
| 178 | const BIGNUM *x, BN_CTX *); | - |
| 179 | int (*blind_coordinates)(const EC_GROUP *group, EC_POINT *p, BN_CTX *ctx); | - |
| 180 | int (*ladder_pre)(const EC_GROUP *group, | - |
| 181 | EC_POINT *r, EC_POINT *s, | - |
| 182 | EC_POINT *p, BN_CTX *ctx); | - |
| 183 | int (*ladder_step)(const EC_GROUP *group, | - |
| 184 | EC_POINT *r, EC_POINT *s, | - |
| 185 | EC_POINT *p, BN_CTX *ctx); | - |
| 186 | int (*ladder_post)(const EC_GROUP *group, | - |
| 187 | EC_POINT *r, EC_POINT *s, | - |
| 188 | EC_POINT *p, BN_CTX *ctx); | - |
| 189 | }; | - |
| 190 | | - |
| 191 | | - |
| 192 | | - |
| 193 | | - |
| 194 | typedef struct nistp224_pre_comp_st NISTP224_PRE_COMP; | - |
| 195 | typedef struct nistp256_pre_comp_st NISTP256_PRE_COMP; | - |
| 196 | typedef struct nistp521_pre_comp_st NISTP521_PRE_COMP; | - |
| 197 | typedef struct nistz256_pre_comp_st NISTZ256_PRE_COMP; | - |
| 198 | typedef struct ec_pre_comp_st EC_PRE_COMP; | - |
| 199 | | - |
| 200 | struct ec_group_st { | - |
| 201 | const EC_METHOD *meth; | - |
| 202 | EC_POINT *generator; | - |
| 203 | BIGNUM *order, *cofactor; | - |
| 204 | int curve_name; | - |
| 205 | int asn1_flag; | - |
| 206 | point_conversion_form_t asn1_form; | - |
| 207 | unsigned char *seed; | - |
| 208 | | - |
| 209 | size_t seed_len; | - |
| 210 | | - |
| 211 | | - |
| 212 | | - |
| 213 | | - |
| 214 | | - |
| 215 | | - |
| 216 | | - |
| 217 | | - |
| 218 | | - |
| 219 | BIGNUM *field; | - |
| 220 | | - |
| 221 | | - |
| 222 | | - |
| 223 | | - |
| 224 | | - |
| 225 | | - |
| 226 | | - |
| 227 | int poly[6]; | - |
| 228 | | - |
| 229 | | - |
| 230 | | - |
| 231 | | - |
| 232 | | - |
| 233 | | - |
| 234 | | - |
| 235 | BIGNUM *a, *b; | - |
| 236 | | - |
| 237 | int a_is_minus3; | - |
| 238 | | - |
| 239 | void *field_data1; | - |
| 240 | | - |
| 241 | void *field_data2; | - |
| 242 | | - |
| 243 | int (*field_mod_func) (BIGNUM *, const BIGNUM *, const BIGNUM *, | - |
| 244 | BN_CTX *); | - |
| 245 | | - |
| 246 | BN_MONT_CTX *mont_data; | - |
| 247 | | - |
| 248 | | - |
| 249 | | - |
| 250 | | - |
| 251 | | - |
| 252 | | - |
| 253 | enum { | - |
| 254 | PCT_none, | - |
| 255 | PCT_nistp224, PCT_nistp256, PCT_nistp521, PCT_nistz256, | - |
| 256 | PCT_ec | - |
| 257 | } pre_comp_type; | - |
| 258 | union { | - |
| 259 | NISTP224_PRE_COMP *nistp224; | - |
| 260 | NISTP256_PRE_COMP *nistp256; | - |
| 261 | NISTP521_PRE_COMP *nistp521; | - |
| 262 | NISTZ256_PRE_COMP *nistz256; | - |
| 263 | EC_PRE_COMP *ec; | - |
| 264 | } pre_comp; | - |
| 265 | }; | - |
| 266 | | - |
| 267 | #define SETPRECOMP(g, type, pre) \ | - |
| 268 | g->pre_comp_type = PCT_##type, g->pre_comp.type = pre | - |
| 269 | #define HAVEPRECOMP(g, type) \ | - |
| 270 | g->pre_comp_type == PCT_##type && g->pre_comp.type != NULL | - |
| 271 | | - |
| 272 | struct ec_key_st { | - |
| 273 | const EC_KEY_METHOD *meth; | - |
| 274 | ENGINE *engine; | - |
| 275 | int version; | - |
| 276 | EC_GROUP *group; | - |
| 277 | EC_POINT *pub_key; | - |
| 278 | BIGNUM *priv_key; | - |
| 279 | unsigned int enc_flag; | - |
| 280 | point_conversion_form_t conv_form; | - |
| 281 | CRYPTO_REF_COUNT references; | - |
| 282 | int flags; | - |
| 283 | CRYPTO_EX_DATA ex_data; | - |
| 284 | CRYPTO_RWLOCK *lock; | - |
| 285 | }; | - |
| 286 | | - |
| 287 | struct ec_point_st { | - |
| 288 | const EC_METHOD *meth; | - |
| 289 | | - |
| 290 | int curve_name; | - |
| 291 | | - |
| 292 | | - |
| 293 | | - |
| 294 | | - |
| 295 | BIGNUM *X; | - |
| 296 | BIGNUM *Y; | - |
| 297 | BIGNUM *Z; | - |
| 298 | | - |
| 299 | int Z_is_one; | - |
| 300 | | - |
| 301 | }; | - |
| 302 | | - |
| 303 | static ossl_inline int ec_point_is_compat(const EC_POINT *point, | - |
| 304 | const EC_GROUP *group) | - |
| 305 | { | - |
| 306 | if (group->meth != point->meth| TRUE | never evaluated | | FALSE | evaluated 1949088 times by 2 testsEvaluated by:- libcrypto.so.1.1
- sm2_internal_test
|
| 0-1949088 |
| 307 | || (group->curve_name != 0| TRUE | evaluated 1702404 times by 1 test | | FALSE | evaluated 246684 times by 2 testsEvaluated by:- libcrypto.so.1.1
- sm2_internal_test
|
| 246684-1702404 |
| 308 | && point->curve_name != 0| TRUE | evaluated 1702402 times by 1 test | | FALSE | evaluated 2 times by 1 test |
| 2-1702402 |
| 309 | && group->curve_name != point->curve_name))| TRUE | never evaluated | | FALSE | evaluated 1702402 times by 1 test |
| 0-1702402 |
| 310 | return 0; never executed: return 0; | 0 |
| 311 | | - |
| 312 | return 1;executed 1949088 times by 2 tests: return 1;Executed by:- libcrypto.so.1.1
- sm2_internal_test
| 1949088 |
| 313 | } | - |
| 314 | | - |
| 315 | NISTP224_PRE_COMP *EC_nistp224_pre_comp_dup(NISTP224_PRE_COMP *); | - |
| 316 | NISTP256_PRE_COMP *EC_nistp256_pre_comp_dup(NISTP256_PRE_COMP *); | - |
| 317 | NISTP521_PRE_COMP *EC_nistp521_pre_comp_dup(NISTP521_PRE_COMP *); | - |
| 318 | NISTZ256_PRE_COMP *EC_nistz256_pre_comp_dup(NISTZ256_PRE_COMP *); | - |
| 319 | NISTP256_PRE_COMP *EC_nistp256_pre_comp_dup(NISTP256_PRE_COMP *); | - |
| 320 | EC_PRE_COMP *EC_ec_pre_comp_dup(EC_PRE_COMP *); | - |
| 321 | | - |
| 322 | void EC_pre_comp_free(EC_GROUP *group); | - |
| 323 | void EC_nistp224_pre_comp_free(NISTP224_PRE_COMP *); | - |
| 324 | void EC_nistp256_pre_comp_free(NISTP256_PRE_COMP *); | - |
| 325 | void EC_nistp521_pre_comp_free(NISTP521_PRE_COMP *); | - |
| 326 | void EC_nistz256_pre_comp_free(NISTZ256_PRE_COMP *); | - |
| 327 | void EC_ec_pre_comp_free(EC_PRE_COMP *); | - |
| 328 | | - |
| 329 | | - |
| 330 | | - |
| 331 | | - |
| 332 | | - |
| 333 | int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, | - |
| 334 | size_t num, const EC_POINT *points[], const BIGNUM *scalars[], | - |
| 335 | BN_CTX *); | - |
| 336 | int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *); | - |
| 337 | int ec_wNAF_have_precompute_mult(const EC_GROUP *group); | - |
| 338 | | - |
| 339 | | - |
| 340 | int ec_GFp_simple_group_init(EC_GROUP *); | - |
| 341 | void ec_GFp_simple_group_finish(EC_GROUP *); | - |
| 342 | void ec_GFp_simple_group_clear_finish(EC_GROUP *); | - |
| 343 | int ec_GFp_simple_group_copy(EC_GROUP *, const EC_GROUP *); | - |
| 344 | int ec_GFp_simple_group_set_curve(EC_GROUP *, const BIGNUM *p, | - |
| 345 | const BIGNUM *a, const BIGNUM *b, BN_CTX *); | - |
| 346 | int ec_GFp_simple_group_get_curve(const EC_GROUP *, BIGNUM *p, BIGNUM *a, | - |
| 347 | BIGNUM *b, BN_CTX *); | - |
| 348 | int ec_GFp_simple_group_get_degree(const EC_GROUP *); | - |
| 349 | int ec_GFp_simple_group_check_discriminant(const EC_GROUP *, BN_CTX *); | - |
| 350 | int ec_GFp_simple_point_init(EC_POINT *); | - |
| 351 | void ec_GFp_simple_point_finish(EC_POINT *); | - |
| 352 | void ec_GFp_simple_point_clear_finish(EC_POINT *); | - |
| 353 | int ec_GFp_simple_point_copy(EC_POINT *, const EC_POINT *); | - |
| 354 | int ec_GFp_simple_point_set_to_infinity(const EC_GROUP *, EC_POINT *); | - |
| 355 | int ec_GFp_simple_set_Jprojective_coordinates_GFp(const EC_GROUP *, | - |
| 356 | EC_POINT *, const BIGNUM *x, | - |
| 357 | const BIGNUM *y, | - |
| 358 | const BIGNUM *z, BN_CTX *); | - |
| 359 | int ec_GFp_simple_get_Jprojective_coordinates_GFp(const EC_GROUP *, | - |
| 360 | const EC_POINT *, BIGNUM *x, | - |
| 361 | BIGNUM *y, BIGNUM *z, | - |
| 362 | BN_CTX *); | - |
| 363 | int ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP *, EC_POINT *, | - |
| 364 | const BIGNUM *x, | - |
| 365 | const BIGNUM *y, BN_CTX *); | - |
| 366 | int ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *, | - |
| 367 | const EC_POINT *, BIGNUM *x, | - |
| 368 | BIGNUM *y, BN_CTX *); | - |
| 369 | int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *, EC_POINT *, | - |
| 370 | const BIGNUM *x, int y_bit, | - |
| 371 | BN_CTX *); | - |
| 372 | size_t ec_GFp_simple_point2oct(const EC_GROUP *, const EC_POINT *, | - |
| 373 | point_conversion_form_t form, | - |
| 374 | unsigned char *buf, size_t len, BN_CTX *); | - |
| 375 | int ec_GFp_simple_oct2point(const EC_GROUP *, EC_POINT *, | - |
| 376 | const unsigned char *buf, size_t len, BN_CTX *); | - |
| 377 | int ec_GFp_simple_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, | - |
| 378 | const EC_POINT *b, BN_CTX *); | - |
| 379 | int ec_GFp_simple_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, | - |
| 380 | BN_CTX *); | - |
| 381 | int ec_GFp_simple_invert(const EC_GROUP *, EC_POINT *, BN_CTX *); | - |
| 382 | int ec_GFp_simple_is_at_infinity(const EC_GROUP *, const EC_POINT *); | - |
| 383 | int ec_GFp_simple_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *); | - |
| 384 | int ec_GFp_simple_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, | - |
| 385 | BN_CTX *); | - |
| 386 | int ec_GFp_simple_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *); | - |
| 387 | int ec_GFp_simple_points_make_affine(const EC_GROUP *, size_t num, | - |
| 388 | EC_POINT *[], BN_CTX *); | - |
| 389 | int ec_GFp_simple_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, | - |
| 390 | const BIGNUM *b, BN_CTX *); | - |
| 391 | int ec_GFp_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, | - |
| 392 | BN_CTX *); | - |
| 393 | int ec_GFp_simple_blind_coordinates(const EC_GROUP *group, EC_POINT *p, | - |
| 394 | BN_CTX *ctx); | - |
| 395 | int ec_GFp_simple_ladder_pre(const EC_GROUP *group, | - |
| 396 | EC_POINT *r, EC_POINT *s, | - |
| 397 | EC_POINT *p, BN_CTX *ctx); | - |
| 398 | int ec_GFp_simple_ladder_step(const EC_GROUP *group, | - |
| 399 | EC_POINT *r, EC_POINT *s, | - |
| 400 | EC_POINT *p, BN_CTX *ctx); | - |
| 401 | int ec_GFp_simple_ladder_post(const EC_GROUP *group, | - |
| 402 | EC_POINT *r, EC_POINT *s, | - |
| 403 | EC_POINT *p, BN_CTX *ctx); | - |
| 404 | | - |
| 405 | | - |
| 406 | int ec_GFp_mont_group_init(EC_GROUP *); | - |
| 407 | int ec_GFp_mont_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, | - |
| 408 | const BIGNUM *b, BN_CTX *); | - |
| 409 | void ec_GFp_mont_group_finish(EC_GROUP *); | - |
| 410 | void ec_GFp_mont_group_clear_finish(EC_GROUP *); | - |
| 411 | int ec_GFp_mont_group_copy(EC_GROUP *, const EC_GROUP *); | - |
| 412 | int ec_GFp_mont_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, | - |
| 413 | const BIGNUM *b, BN_CTX *); | - |
| 414 | int ec_GFp_mont_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, | - |
| 415 | BN_CTX *); | - |
| 416 | int ec_GFp_mont_field_encode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, | - |
| 417 | BN_CTX *); | - |
| 418 | int ec_GFp_mont_field_decode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, | - |
| 419 | BN_CTX *); | - |
| 420 | int ec_GFp_mont_field_set_to_one(const EC_GROUP *, BIGNUM *r, BN_CTX *); | - |
| 421 | | - |
| 422 | | - |
| 423 | int ec_GFp_nist_group_copy(EC_GROUP *dest, const EC_GROUP *src); | - |
| 424 | int ec_GFp_nist_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, | - |
| 425 | const BIGNUM *b, BN_CTX *); | - |
| 426 | int ec_GFp_nist_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, | - |
| 427 | const BIGNUM *b, BN_CTX *); | - |
| 428 | int ec_GFp_nist_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, | - |
| 429 | BN_CTX *); | - |
| 430 | | - |
| 431 | | - |
| 432 | int ec_GF2m_simple_group_init(EC_GROUP *); | - |
| 433 | void ec_GF2m_simple_group_finish(EC_GROUP *); | - |
| 434 | void ec_GF2m_simple_group_clear_finish(EC_GROUP *); | - |
| 435 | int ec_GF2m_simple_group_copy(EC_GROUP *, const EC_GROUP *); | - |
| 436 | int ec_GF2m_simple_group_set_curve(EC_GROUP *, const BIGNUM *p, | - |
| 437 | const BIGNUM *a, const BIGNUM *b, | - |
| 438 | BN_CTX *); | - |
| 439 | int ec_GF2m_simple_group_get_curve(const EC_GROUP *, BIGNUM *p, BIGNUM *a, | - |
| 440 | BIGNUM *b, BN_CTX *); | - |
| 441 | int ec_GF2m_simple_group_get_degree(const EC_GROUP *); | - |
| 442 | int ec_GF2m_simple_group_check_discriminant(const EC_GROUP *, BN_CTX *); | - |
| 443 | int ec_GF2m_simple_point_init(EC_POINT *); | - |
| 444 | void ec_GF2m_simple_point_finish(EC_POINT *); | - |
| 445 | void ec_GF2m_simple_point_clear_finish(EC_POINT *); | - |
| 446 | int ec_GF2m_simple_point_copy(EC_POINT *, const EC_POINT *); | - |
| 447 | int ec_GF2m_simple_point_set_to_infinity(const EC_GROUP *, EC_POINT *); | - |
| 448 | int ec_GF2m_simple_point_set_affine_coordinates(const EC_GROUP *, EC_POINT *, | - |
| 449 | const BIGNUM *x, | - |
| 450 | const BIGNUM *y, BN_CTX *); | - |
| 451 | int ec_GF2m_simple_point_get_affine_coordinates(const EC_GROUP *, | - |
| 452 | const EC_POINT *, BIGNUM *x, | - |
| 453 | BIGNUM *y, BN_CTX *); | - |
| 454 | int ec_GF2m_simple_set_compressed_coordinates(const EC_GROUP *, EC_POINT *, | - |
| 455 | const BIGNUM *x, int y_bit, | - |
| 456 | BN_CTX *); | - |
| 457 | size_t ec_GF2m_simple_point2oct(const EC_GROUP *, const EC_POINT *, | - |
| 458 | point_conversion_form_t form, | - |
| 459 | unsigned char *buf, size_t len, BN_CTX *); | - |
| 460 | int ec_GF2m_simple_oct2point(const EC_GROUP *, EC_POINT *, | - |
| 461 | const unsigned char *buf, size_t len, BN_CTX *); | - |
| 462 | int ec_GF2m_simple_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, | - |
| 463 | const EC_POINT *b, BN_CTX *); | - |
| 464 | int ec_GF2m_simple_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, | - |
| 465 | BN_CTX *); | - |
| 466 | int ec_GF2m_simple_invert(const EC_GROUP *, EC_POINT *, BN_CTX *); | - |
| 467 | int ec_GF2m_simple_is_at_infinity(const EC_GROUP *, const EC_POINT *); | - |
| 468 | int ec_GF2m_simple_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *); | - |
| 469 | int ec_GF2m_simple_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, | - |
| 470 | BN_CTX *); | - |
| 471 | int ec_GF2m_simple_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *); | - |
| 472 | int ec_GF2m_simple_points_make_affine(const EC_GROUP *, size_t num, | - |
| 473 | EC_POINT *[], BN_CTX *); | - |
| 474 | int ec_GF2m_simple_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, | - |
| 475 | const BIGNUM *b, BN_CTX *); | - |
| 476 | int ec_GF2m_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, | - |
| 477 | BN_CTX *); | - |
| 478 | int ec_GF2m_simple_field_div(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, | - |
| 479 | const BIGNUM *b, BN_CTX *); | - |
| 480 | | - |
| 481 | #ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 | - |
| 482 | | - |
| 483 | int ec_GFp_nistp224_group_init(EC_GROUP *group); | - |
| 484 | int ec_GFp_nistp224_group_set_curve(EC_GROUP *group, const BIGNUM *p, | - |
| 485 | const BIGNUM *a, const BIGNUM *n, | - |
| 486 | BN_CTX *); | - |
| 487 | int ec_GFp_nistp224_point_get_affine_coordinates(const EC_GROUP *group, | - |
| 488 | const EC_POINT *point, | - |
| 489 | BIGNUM *x, BIGNUM *y, | - |
| 490 | BN_CTX *ctx); | - |
| 491 | int ec_GFp_nistp224_mul(const EC_GROUP *group, EC_POINT *r, | - |
| 492 | const BIGNUM *scalar, size_t num, | - |
| 493 | const EC_POINT *points[], const BIGNUM *scalars[], | - |
| 494 | BN_CTX *); | - |
| 495 | int ec_GFp_nistp224_points_mul(const EC_GROUP *group, EC_POINT *r, | - |
| 496 | const BIGNUM *scalar, size_t num, | - |
| 497 | const EC_POINT *points[], | - |
| 498 | const BIGNUM *scalars[], BN_CTX *ctx); | - |
| 499 | int ec_GFp_nistp224_precompute_mult(EC_GROUP *group, BN_CTX *ctx); | - |
| 500 | int ec_GFp_nistp224_have_precompute_mult(const EC_GROUP *group); | - |
| 501 | | - |
| 502 | | - |
| 503 | int ec_GFp_nistp256_group_init(EC_GROUP *group); | - |
| 504 | int ec_GFp_nistp256_group_set_curve(EC_GROUP *group, const BIGNUM *p, | - |
| 505 | const BIGNUM *a, const BIGNUM *n, | - |
| 506 | BN_CTX *); | - |
| 507 | int ec_GFp_nistp256_point_get_affine_coordinates(const EC_GROUP *group, | - |
| 508 | const EC_POINT *point, | - |
| 509 | BIGNUM *x, BIGNUM *y, | - |
| 510 | BN_CTX *ctx); | - |
| 511 | int ec_GFp_nistp256_mul(const EC_GROUP *group, EC_POINT *r, | - |
| 512 | const BIGNUM *scalar, size_t num, | - |
| 513 | const EC_POINT *points[], const BIGNUM *scalars[], | - |
| 514 | BN_CTX *); | - |
| 515 | int ec_GFp_nistp256_points_mul(const EC_GROUP *group, EC_POINT *r, | - |
| 516 | const BIGNUM *scalar, size_t num, | - |
| 517 | const EC_POINT *points[], | - |
| 518 | const BIGNUM *scalars[], BN_CTX *ctx); | - |
| 519 | int ec_GFp_nistp256_precompute_mult(EC_GROUP *group, BN_CTX *ctx); | - |
| 520 | int ec_GFp_nistp256_have_precompute_mult(const EC_GROUP *group); | - |
| 521 | | - |
| 522 | | - |
| 523 | int ec_GFp_nistp521_group_init(EC_GROUP *group); | - |
| 524 | int ec_GFp_nistp521_group_set_curve(EC_GROUP *group, const BIGNUM *p, | - |
| 525 | const BIGNUM *a, const BIGNUM *n, | - |
| 526 | BN_CTX *); | - |
| 527 | int ec_GFp_nistp521_point_get_affine_coordinates(const EC_GROUP *group, | - |
| 528 | const EC_POINT *point, | - |
| 529 | BIGNUM *x, BIGNUM *y, | - |
| 530 | BN_CTX *ctx); | - |
| 531 | int ec_GFp_nistp521_mul(const EC_GROUP *group, EC_POINT *r, | - |
| 532 | const BIGNUM *scalar, size_t num, | - |
| 533 | const EC_POINT *points[], const BIGNUM *scalars[], | - |
| 534 | BN_CTX *); | - |
| 535 | int ec_GFp_nistp521_points_mul(const EC_GROUP *group, EC_POINT *r, | - |
| 536 | const BIGNUM *scalar, size_t num, | - |
| 537 | const EC_POINT *points[], | - |
| 538 | const BIGNUM *scalars[], BN_CTX *ctx); | - |
| 539 | int ec_GFp_nistp521_precompute_mult(EC_GROUP *group, BN_CTX *ctx); | - |
| 540 | int ec_GFp_nistp521_have_precompute_mult(const EC_GROUP *group); | - |
| 541 | | - |
| 542 | | - |
| 543 | void ec_GFp_nistp_points_make_affine_internal(size_t num, void *point_array, | - |
| 544 | size_t felem_size, | - |
| 545 | void *tmp_felems, | - |
| 546 | void (*felem_one) (void *out), | - |
| 547 | int (*felem_is_zero) (const void | - |
| 548 | *in), | - |
| 549 | void (*felem_assign) (void *out, | - |
| 550 | const void | - |
| 551 | *in), | - |
| 552 | void (*felem_square) (void *out, | - |
| 553 | const void | - |
| 554 | *in), | - |
| 555 | void (*felem_mul) (void *out, | - |
| 556 | const void | - |
| 557 | *in1, | - |
| 558 | const void | - |
| 559 | *in2), | - |
| 560 | void (*felem_inv) (void *out, | - |
| 561 | const void | - |
| 562 | *in), | - |
| 563 | void (*felem_contract) (void | - |
| 564 | *out, | - |
| 565 | const | - |
| 566 | void | - |
| 567 | *in)); | - |
| 568 | void ec_GFp_nistp_recode_scalar_bits(unsigned char *sign, | - |
| 569 | unsigned char *digit, unsigned char in); | - |
| 570 | #endif | - |
| 571 | int ec_group_simple_order_bits(const EC_GROUP *group); | - |
| 572 | | - |
| 573 | #ifdef ECP_NISTZ256_ASM | - |
| 574 | | - |
| 575 | | - |
| 576 | | - |
| 577 | | - |
| 578 | const EC_METHOD *EC_GFp_nistz256_method(void); | - |
| 579 | #endif | - |
| 580 | | - |
| 581 | size_t ec_key_simple_priv2oct(const EC_KEY *eckey, | - |
| 582 | unsigned char *buf, size_t len); | - |
| 583 | int ec_key_simple_oct2priv(EC_KEY *eckey, const unsigned char *buf, size_t len); | - |
| 584 | int ec_key_simple_generate_key(EC_KEY *eckey); | - |
| 585 | int ec_key_simple_generate_public_key(EC_KEY *eckey); | - |
| 586 | int ec_key_simple_check_key(const EC_KEY *eckey); | - |
| 587 | | - |
| 588 | | - |
| 589 | | - |
| 590 | struct ec_key_method_st { | - |
| 591 | const char *name; | - |
| 592 | int32_t flags; | - |
| 593 | int (*init)(EC_KEY *key); | - |
| 594 | void (*finish)(EC_KEY *key); | - |
| 595 | int (*copy)(EC_KEY *dest, const EC_KEY *src); | - |
| 596 | int (*set_group)(EC_KEY *key, const EC_GROUP *grp); | - |
| 597 | int (*set_private)(EC_KEY *key, const BIGNUM *priv_key); | - |
| 598 | int (*set_public)(EC_KEY *key, const EC_POINT *pub_key); | - |
| 599 | int (*keygen)(EC_KEY *key); | - |
| 600 | int (*compute_key)(unsigned char **pout, size_t *poutlen, | - |
| 601 | const EC_POINT *pub_key, const EC_KEY *ecdh); | - |
| 602 | int (*sign)(int type, const unsigned char *dgst, int dlen, unsigned char | - |
| 603 | *sig, unsigned int *siglen, const BIGNUM *kinv, | - |
| 604 | const BIGNUM *r, EC_KEY *eckey); | - |
| 605 | int (*sign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, | - |
| 606 | BIGNUM **rp); | - |
| 607 | ECDSA_SIG *(*sign_sig)(const unsigned char *dgst, int dgst_len, | - |
| 608 | const BIGNUM *in_kinv, const BIGNUM *in_r, | - |
| 609 | EC_KEY *eckey); | - |
| 610 | | - |
| 611 | int (*verify)(int type, const unsigned char *dgst, int dgst_len, | - |
| 612 | const unsigned char *sigbuf, int sig_len, EC_KEY *eckey); | - |
| 613 | int (*verify_sig)(const unsigned char *dgst, int dgst_len, | - |
| 614 | const ECDSA_SIG *sig, EC_KEY *eckey); | - |
| 615 | }; | - |
| 616 | | - |
| 617 | #define EC_KEY_METHOD_DYNAMIC 1 | - |
| 618 | | - |
| 619 | int ossl_ec_key_gen(EC_KEY *eckey); | - |
| 620 | int ossl_ecdh_compute_key(unsigned char **pout, size_t *poutlen, | - |
| 621 | const EC_POINT *pub_key, const EC_KEY *ecdh); | - |
| 622 | int ecdh_simple_compute_key(unsigned char **pout, size_t *poutlen, | - |
| 623 | const EC_POINT *pub_key, const EC_KEY *ecdh); | - |
| 624 | | - |
| 625 | struct ECDSA_SIG_st { | - |
| 626 | BIGNUM *r; | - |
| 627 | BIGNUM *s; | - |
| 628 | }; | - |
| 629 | | - |
| 630 | int ossl_ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, | - |
| 631 | BIGNUM **rp); | - |
| 632 | int ossl_ecdsa_sign(int type, const unsigned char *dgst, int dlen, | - |
| 633 | unsigned char *sig, unsigned int *siglen, | - |
| 634 | const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey); | - |
| 635 | ECDSA_SIG *ossl_ecdsa_sign_sig(const unsigned char *dgst, int dgst_len, | - |
| 636 | const BIGNUM *in_kinv, const BIGNUM *in_r, | - |
| 637 | EC_KEY *eckey); | - |
| 638 | int ossl_ecdsa_verify(int type, const unsigned char *dgst, int dgst_len, | - |
| 639 | const unsigned char *sigbuf, int sig_len, EC_KEY *eckey); | - |
| 640 | int ossl_ecdsa_verify_sig(const unsigned char *dgst, int dgst_len, | - |
| 641 | const ECDSA_SIG *sig, EC_KEY *eckey); | - |
| 642 | | - |
| 643 | int ED25519_sign(uint8_t *out_sig, const uint8_t *message, size_t message_len, | - |
| 644 | const uint8_t public_key[32], const uint8_t private_key[32]); | - |
| 645 | int ED25519_verify(const uint8_t *message, size_t message_len, | - |
| 646 | const uint8_t signature[64], const uint8_t public_key[32]); | - |
| 647 | void ED25519_public_from_private(uint8_t out_public_key[32], | - |
| 648 | const uint8_t private_key[32]); | - |
| 649 | | - |
| 650 | int X25519(uint8_t out_shared_key[32], const uint8_t private_key[32], | - |
| 651 | const uint8_t peer_public_value[32]); | - |
| 652 | void X25519_public_from_private(uint8_t out_public_value[32], | - |
| 653 | const uint8_t private_key[32]); | - |
| 654 | | - |
| 655 | | - |
| 656 | | - |
| 657 | | - |
| 658 | | - |
| 659 | | - |
| 660 | | - |
| 661 | | - |
| 662 | | - |
| 663 | | - |
| 664 | | - |
| 665 | | - |
| 666 | | - |
| 667 | | - |
| 668 | | - |
| 669 | | - |
| 670 | | - |
| 671 | | - |
| 672 | | - |
| 673 | | - |
| 674 | | - |
| 675 | | - |
| 676 | | - |
| 677 | | - |
| 678 | | - |
| 679 | | - |
| 680 | | - |
| 681 | | - |
| 682 | | - |
| 683 | | - |
| 684 | int ec_scalar_mul_ladder(const EC_GROUP *group, EC_POINT *r, | - |
| 685 | const BIGNUM *scalar, const EC_POINT *point, | - |
| 686 | BN_CTX *ctx); | - |
| 687 | | - |
| 688 | int ec_point_blind_coordinates(const EC_GROUP *group, EC_POINT *p, BN_CTX *ctx); | - |
| 689 | | - |
| 690 | static ossl_inline int ec_point_ladder_pre(const EC_GROUP *group, | - |
| 691 | EC_POINT *r, EC_POINT *s, | - |
| 692 | EC_POINT *p, BN_CTX *ctx) | - |
| 693 | { | - |
| 694 | if (group->meth->ladder_pre != NULL)| TRUE | evaluated 4130 times by 2 testsEvaluated by:- libcrypto.so.1.1
- sm2_internal_test
| | FALSE | never evaluated |
| 0-4130 |
| 695 | return group->meth->ladder_pre(group, r, s, p, ctx);executed 4130 times by 2 tests: return group->meth->ladder_pre(group, r, s, p, ctx);Executed by:- libcrypto.so.1.1
- sm2_internal_test
| 4130 |
| 696 | | - |
| 697 | if (!EC_POINT_copy(s, p)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 698 | || !EC_POINT_dbl(group, r, s, ctx))| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 699 | return 0; never executed: return 0; | 0 |
| 700 | | - |
| 701 | return 1; never executed: return 1; | 0 |
| 702 | } | - |
| 703 | | - |
| 704 | static ossl_inline int ec_point_ladder_step(const EC_GROUP *group, | - |
| 705 | EC_POINT *r, EC_POINT *s, | - |
| 706 | EC_POINT *p, BN_CTX *ctx) | - |
| 707 | { | - |
| 708 | if (group->meth->ladder_step != NULL)| TRUE | evaluated 1193659 times by 2 testsEvaluated by:- libcrypto.so.1.1
- sm2_internal_test
| | FALSE | never evaluated |
| 0-1193659 |
| 709 | return group->meth->ladder_step(group, r, s, p, ctx);executed 1193659 times by 2 tests: return group->meth->ladder_step(group, r, s, p, ctx);Executed by:- libcrypto.so.1.1
- sm2_internal_test
| 1193659 |
| 710 | | - |
| 711 | if (!EC_POINT_add(group, s, r, s, ctx)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 712 | || !EC_POINT_dbl(group, r, r, ctx))| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 713 | return 0; never executed: return 0; | 0 |
| 714 | | - |
| 715 | return 1; never executed: return 1; | 0 |
| 716 | | - |
| 717 | } | - |
| 718 | | - |
| 719 | static ossl_inline int ec_point_ladder_post(const EC_GROUP *group, | - |
| 720 | EC_POINT *r, EC_POINT *s, | - |
| 721 | EC_POINT *p, BN_CTX *ctx) | - |
| 722 | { | - |
| 723 | if (group->meth->ladder_post != NULL)| TRUE | evaluated 4130 times by 2 testsEvaluated by:- libcrypto.so.1.1
- sm2_internal_test
| | FALSE | never evaluated |
| 0-4130 |
| 724 | return group->meth->ladder_post(group, r, s, p, ctx);executed 4130 times by 2 tests: return group->meth->ladder_post(group, r, s, p, ctx);Executed by:- libcrypto.so.1.1
- sm2_internal_test
| 4130 |
| 725 | | - |
| 726 | return 1; never executed: return 1; | 0 |
| 727 | } | - |
| | |