diff options
Diffstat (limited to 'src/lib/libcrypto/ec/ec2_mult.c')
| -rw-r--r-- | src/lib/libcrypto/ec/ec2_mult.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/lib/libcrypto/ec/ec2_mult.c b/src/lib/libcrypto/ec/ec2_mult.c index ab631a50a2..e12b9b284a 100644 --- a/src/lib/libcrypto/ec/ec2_mult.c +++ b/src/lib/libcrypto/ec/ec2_mult.c | |||
| @@ -319,6 +319,7 @@ int ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, | |||
| 319 | int ret = 0; | 319 | int ret = 0; |
| 320 | size_t i; | 320 | size_t i; |
| 321 | EC_POINT *p=NULL; | 321 | EC_POINT *p=NULL; |
| 322 | EC_POINT *acc = NULL; | ||
| 322 | 323 | ||
| 323 | if (ctx == NULL) | 324 | if (ctx == NULL) |
| 324 | { | 325 | { |
| @@ -338,15 +339,16 @@ int ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, | |||
| 338 | } | 339 | } |
| 339 | 340 | ||
| 340 | if ((p = EC_POINT_new(group)) == NULL) goto err; | 341 | if ((p = EC_POINT_new(group)) == NULL) goto err; |
| 342 | if ((acc = EC_POINT_new(group)) == NULL) goto err; | ||
| 341 | 343 | ||
| 342 | if (!EC_POINT_set_to_infinity(group, r)) goto err; | 344 | if (!EC_POINT_set_to_infinity(group, acc)) goto err; |
| 343 | 345 | ||
| 344 | if (scalar) | 346 | if (scalar) |
| 345 | { | 347 | { |
| 346 | if (!ec_GF2m_montgomery_point_multiply(group, p, scalar, group->generator, ctx)) goto err; | 348 | if (!ec_GF2m_montgomery_point_multiply(group, p, scalar, group->generator, ctx)) goto err; |
| 347 | if (BN_is_negative(scalar)) | 349 | if (BN_is_negative(scalar)) |
| 348 | if (!group->meth->invert(group, p, ctx)) goto err; | 350 | if (!group->meth->invert(group, p, ctx)) goto err; |
| 349 | if (!group->meth->add(group, r, r, p, ctx)) goto err; | 351 | if (!group->meth->add(group, acc, acc, p, ctx)) goto err; |
| 350 | } | 352 | } |
| 351 | 353 | ||
| 352 | for (i = 0; i < num; i++) | 354 | for (i = 0; i < num; i++) |
| @@ -354,13 +356,16 @@ int ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, | |||
| 354 | if (!ec_GF2m_montgomery_point_multiply(group, p, scalars[i], points[i], ctx)) goto err; | 356 | if (!ec_GF2m_montgomery_point_multiply(group, p, scalars[i], points[i], ctx)) goto err; |
| 355 | if (BN_is_negative(scalars[i])) | 357 | if (BN_is_negative(scalars[i])) |
| 356 | if (!group->meth->invert(group, p, ctx)) goto err; | 358 | if (!group->meth->invert(group, p, ctx)) goto err; |
| 357 | if (!group->meth->add(group, r, r, p, ctx)) goto err; | 359 | if (!group->meth->add(group, acc, acc, p, ctx)) goto err; |
| 358 | } | 360 | } |
| 359 | 361 | ||
| 362 | if (!EC_POINT_copy(r, acc)) goto err; | ||
| 363 | |||
| 360 | ret = 1; | 364 | ret = 1; |
| 361 | 365 | ||
| 362 | err: | 366 | err: |
| 363 | if (p) EC_POINT_free(p); | 367 | if (p) EC_POINT_free(p); |
| 368 | if (acc) EC_POINT_free(acc); | ||
| 364 | if (new_ctx != NULL) | 369 | if (new_ctx != NULL) |
| 365 | BN_CTX_free(new_ctx); | 370 | BN_CTX_free(new_ctx); |
| 366 | return ret; | 371 | return ret; |
