summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ec/ecp_nistz256.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/ec/ecp_nistz256.c')
-rw-r--r--src/lib/libcrypto/ec/ecp_nistz256.c43
1 files changed, 17 insertions, 26 deletions
diff --git a/src/lib/libcrypto/ec/ecp_nistz256.c b/src/lib/libcrypto/ec/ecp_nistz256.c
index b9ad89c1d3..848f15cb17 100644
--- a/src/lib/libcrypto/ec/ecp_nistz256.c
+++ b/src/lib/libcrypto/ec/ecp_nistz256.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_nistz256.c,v 1.1 2016/11/04 17:33:19 miod Exp $ */ 1/* $OpenBSD: ecp_nistz256.c,v 1.2 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (c) 2014, Intel Corporation. 2/* Copyright (c) 2014, Intel Corporation.
3 * 3 *
4 * Permission to use, copy, modify, and/or distribute this software for any 4 * Permission to use, copy, modify, and/or distribute this software for any
@@ -311,7 +311,7 @@ static int
311ecp_nistz256_set_words(BIGNUM *a, BN_ULONG words[P256_LIMBS]) 311ecp_nistz256_set_words(BIGNUM *a, BN_ULONG words[P256_LIMBS])
312{ 312{
313 if (bn_wexpand(a, P256_LIMBS) == NULL) { 313 if (bn_wexpand(a, P256_LIMBS) == NULL) {
314 ECerr(EC_F_ECP_NISTZ256_SET_WORDS, ERR_R_MALLOC_FAILURE); 314 ECerror(ERR_R_MALLOC_FAILURE);
315 return 0; 315 return 0;
316 } 316 }
317 memcpy(a->d, words, sizeof(BN_ULONG) * P256_LIMBS); 317 memcpy(a->d, words, sizeof(BN_ULONG) * P256_LIMBS);
@@ -441,7 +441,7 @@ ecp_nistz256_windowed_mul(const EC_GROUP *group, P256_POINT *r,
441 if (posix_memalign((void **)&table, 64, num * sizeof(*table)) != 0 || 441 if (posix_memalign((void **)&table, 64, num * sizeof(*table)) != 0 ||
442 (p_str = reallocarray(NULL, num, sizeof(*p_str))) == NULL || 442 (p_str = reallocarray(NULL, num, sizeof(*p_str))) == NULL ||
443 (scalars = reallocarray(NULL, num, sizeof(*scalars))) == NULL) { 443 (scalars = reallocarray(NULL, num, sizeof(*scalars))) == NULL) {
444 ECerr(EC_F_ECP_NISTZ256_WINDOWED_MUL, ERR_R_MALLOC_FAILURE); 444 ECerror(ERR_R_MALLOC_FAILURE);
445 goto err; 445 goto err;
446 } 446 }
447 447
@@ -458,8 +458,7 @@ ecp_nistz256_windowed_mul(const EC_GROUP *group, P256_POINT *r,
458 if ((mod = BN_CTX_get(ctx)) == NULL) 458 if ((mod = BN_CTX_get(ctx)) == NULL)
459 goto err; 459 goto err;
460 if (!BN_nnmod(mod, scalar[i], &group->order, ctx)) { 460 if (!BN_nnmod(mod, scalar[i], &group->order, ctx)) {
461 ECerr(EC_F_ECP_NISTZ256_WINDOWED_MUL, 461 ECerror(ERR_R_BN_LIB);
462 ERR_R_BN_LIB);
463 goto err; 462 goto err;
464 } 463 }
465 scalars[i] = mod; 464 scalars[i] = mod;
@@ -496,8 +495,7 @@ ecp_nistz256_windowed_mul(const EC_GROUP *group, P256_POINT *r,
496 &point[i]->Y) || 495 &point[i]->Y) ||
497 !ecp_nistz256_bignum_to_field_elem(row[1 - 1].Z, 496 !ecp_nistz256_bignum_to_field_elem(row[1 - 1].Z,
498 &point[i]->Z)) { 497 &point[i]->Z)) {
499 ECerr(EC_F_ECP_NISTZ256_WINDOWED_MUL, 498 ECerror(EC_R_COORDINATES_OUT_OF_RANGE);
500 EC_R_COORDINATES_OUT_OF_RANGE);
501 goto err; 499 goto err;
502 } 500 }
503 501
@@ -623,8 +621,7 @@ ecp_nistz256_mult_precompute(EC_GROUP *group, BN_CTX *ctx)
623 621
624 generator = EC_GROUP_get0_generator(group); 622 generator = EC_GROUP_get0_generator(group);
625 if (generator == NULL) { 623 if (generator == NULL) {
626 ECerr(EC_F_ECP_NISTZ256_MULT_PRECOMPUTE, 624 ECerror(EC_R_UNDEFINED_GENERATOR);
627 EC_R_UNDEFINED_GENERATOR);
628 return 0; 625 return 0;
629 } 626 }
630 627
@@ -655,12 +652,12 @@ ecp_nistz256_mult_precompute(EC_GROUP *group, BN_CTX *ctx)
655 goto err; 652 goto err;
656 653
657 if (BN_is_zero(order)) { 654 if (BN_is_zero(order)) {
658 ECerr(EC_F_ECP_NISTZ256_MULT_PRECOMPUTE, EC_R_UNKNOWN_ORDER); 655 ECerror(EC_R_UNKNOWN_ORDER);
659 goto err; 656 goto err;
660 } 657 }
661 658
662 if (posix_memalign((void **)&precomp, 64, 37 * sizeof(*precomp)) != 0) { 659 if (posix_memalign((void **)&precomp, 64, 37 * sizeof(*precomp)) != 0) {
663 ECerr(EC_F_ECP_NISTZ256_MULT_PRECOMPUTE, ERR_R_MALLOC_FAILURE); 660 ECerror(ERR_R_MALLOC_FAILURE);
664 goto err; 661 goto err;
665 } 662 }
666 663
@@ -690,8 +687,7 @@ ecp_nistz256_mult_precompute(EC_GROUP *group, BN_CTX *ctx)
690 precomp[j][k].X, &P->X) || 687 precomp[j][k].X, &P->X) ||
691 !ecp_nistz256_bignum_to_field_elem( 688 !ecp_nistz256_bignum_to_field_elem(
692 precomp[j][k].Y, &P->Y)) { 689 precomp[j][k].Y, &P->Y)) {
693 ECerr(EC_F_ECP_NISTZ256_MULT_PRECOMPUTE, 690 ECerror(EC_R_COORDINATES_OUT_OF_RANGE);
694 EC_R_COORDINATES_OUT_OF_RANGE);
695 goto err; 691 goto err;
696 } 692 }
697 for (i = 0; i < 7; i++) { 693 for (i = 0; i < 7; i++) {
@@ -783,7 +779,7 @@ ecp_nistz256_points_mul(const EC_GROUP *group, EC_POINT *r,
783 BIGNUM *tmp_scalar; 779 BIGNUM *tmp_scalar;
784 780
785 if (group->meth != r->meth) { 781 if (group->meth != r->meth) {
786 ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, EC_R_INCOMPATIBLE_OBJECTS); 782 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
787 return 0; 783 return 0;
788 } 784 }
789 785
@@ -792,8 +788,7 @@ ecp_nistz256_points_mul(const EC_GROUP *group, EC_POINT *r,
792 788
793 for (j = 0; j < num; j++) { 789 for (j = 0; j < num; j++) {
794 if (group->meth != points[j]->meth) { 790 if (group->meth != points[j]->meth) {
795 ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, 791 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
796 EC_R_INCOMPATIBLE_OBJECTS);
797 return 0; 792 return 0;
798 } 793 }
799 } 794 }
@@ -809,8 +804,7 @@ ecp_nistz256_points_mul(const EC_GROUP *group, EC_POINT *r,
809 if (scalar) { 804 if (scalar) {
810 generator = EC_GROUP_get0_generator(group); 805 generator = EC_GROUP_get0_generator(group);
811 if (generator == NULL) { 806 if (generator == NULL) {
812 ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, 807 ECerror(EC_R_UNDEFINED_GENERATOR);
813 EC_R_UNDEFINED_GENERATOR);
814 goto err; 808 goto err;
815 } 809 }
816 810
@@ -860,8 +854,7 @@ ecp_nistz256_points_mul(const EC_GROUP *group, EC_POINT *r,
860 854
861 if (!BN_nnmod(tmp_scalar, scalar, &group->order, 855 if (!BN_nnmod(tmp_scalar, scalar, &group->order,
862 ctx)) { 856 ctx)) {
863 ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, 857 ECerror(ERR_R_BN_LIB);
864 ERR_R_BN_LIB);
865 goto err; 858 goto err;
866 } 859 }
867 scalar = tmp_scalar; 860 scalar = tmp_scalar;
@@ -955,8 +948,7 @@ ecp_nistz256_points_mul(const EC_GROUP *group, EC_POINT *r,
955 new_scalars = reallocarray(NULL, num + 1, sizeof(BIGNUM *)); 948 new_scalars = reallocarray(NULL, num + 1, sizeof(BIGNUM *));
956 new_points = reallocarray(NULL, num + 1, sizeof(EC_POINT *)); 949 new_points = reallocarray(NULL, num + 1, sizeof(EC_POINT *));
957 if (new_scalars == NULL || new_points == NULL) { 950 if (new_scalars == NULL || new_points == NULL) {
958 ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, 951 ECerror(ERR_R_MALLOC_FAILURE);
959 ERR_R_MALLOC_FAILURE);
960 goto err; 952 goto err;
961 } 953 }
962 954
@@ -1011,15 +1003,14 @@ ecp_nistz256_get_affine(const EC_GROUP *group, const EC_POINT *point,
1011 BN_ULONG point_x[P256_LIMBS], point_y[P256_LIMBS], point_z[P256_LIMBS]; 1003 BN_ULONG point_x[P256_LIMBS], point_y[P256_LIMBS], point_z[P256_LIMBS];
1012 1004
1013 if (EC_POINT_is_at_infinity(group, point)) { 1005 if (EC_POINT_is_at_infinity(group, point)) {
1014 ECerr(EC_F_ECP_NISTZ256_GET_AFFINE, EC_R_POINT_AT_INFINITY); 1006 ECerror(EC_R_POINT_AT_INFINITY);
1015 return 0; 1007 return 0;
1016 } 1008 }
1017 1009
1018 if (!ecp_nistz256_bignum_to_field_elem(point_x, &point->X) || 1010 if (!ecp_nistz256_bignum_to_field_elem(point_x, &point->X) ||
1019 !ecp_nistz256_bignum_to_field_elem(point_y, &point->Y) || 1011 !ecp_nistz256_bignum_to_field_elem(point_y, &point->Y) ||
1020 !ecp_nistz256_bignum_to_field_elem(point_z, &point->Z)) { 1012 !ecp_nistz256_bignum_to_field_elem(point_z, &point->Z)) {
1021 ECerr(EC_F_ECP_NISTZ256_GET_AFFINE, 1013 ECerror(EC_R_COORDINATES_OUT_OF_RANGE);
1022 EC_R_COORDINATES_OUT_OF_RANGE);
1023 return 0; 1014 return 0;
1024 } 1015 }
1025 1016
@@ -1066,7 +1057,7 @@ ecp_nistz256_pre_comp_new(const EC_GROUP *group)
1066 1057
1067 ret = (EC_PRE_COMP *)malloc(sizeof(EC_PRE_COMP)); 1058 ret = (EC_PRE_COMP *)malloc(sizeof(EC_PRE_COMP));
1068 if (ret == NULL) { 1059 if (ret == NULL) {
1069 ECerr(EC_F_ECP_NISTZ256_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE); 1060 ECerror(ERR_R_MALLOC_FAILURE);
1070 return ret; 1061 return ret;
1071 } 1062 }
1072 1063