diff options
Diffstat (limited to 'src/lib/libcrypto/bn/bn_gf2m.c')
-rw-r--r-- | src/lib/libcrypto/bn/bn_gf2m.c | 55 |
1 files changed, 1 insertions, 54 deletions
diff --git a/src/lib/libcrypto/bn/bn_gf2m.c b/src/lib/libcrypto/bn/bn_gf2m.c index eceaba47c3..8adbbeb040 100644 --- a/src/lib/libcrypto/bn/bn_gf2m.c +++ b/src/lib/libcrypto/bn/bn_gf2m.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_gf2m.c,v 1.26 2022/11/24 01:30:01 jsing Exp $ */ | 1 | /* $OpenBSD: bn_gf2m.c,v 1.27 2022/11/26 13:56:33 jsing Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | 3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
4 | * | 4 | * |
@@ -325,8 +325,6 @@ BN_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) | |||
325 | int i; | 325 | int i; |
326 | const BIGNUM *at, *bt; | 326 | const BIGNUM *at, *bt; |
327 | 327 | ||
328 | bn_check_top(a); | ||
329 | bn_check_top(b); | ||
330 | 328 | ||
331 | if (a->top < b->top) { | 329 | if (a->top < b->top) { |
332 | at = b; | 330 | at = b; |
@@ -368,7 +366,6 @@ BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const int p[]) | |||
368 | int n, dN, d0, d1; | 366 | int n, dN, d0, d1; |
369 | BN_ULONG zz, *z; | 367 | BN_ULONG zz, *z; |
370 | 368 | ||
371 | bn_check_top(a); | ||
372 | 369 | ||
373 | if (!p[0]) { | 370 | if (!p[0]) { |
374 | /* reduction mod 1 => return 0 */ | 371 | /* reduction mod 1 => return 0 */ |
@@ -467,8 +464,6 @@ BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p) | |||
467 | const int max = BN_num_bits(p) + 1; | 464 | const int max = BN_num_bits(p) + 1; |
468 | int *arr = NULL; | 465 | int *arr = NULL; |
469 | 466 | ||
470 | bn_check_top(a); | ||
471 | bn_check_top(p); | ||
472 | if ((arr = reallocarray(NULL, max, sizeof(int))) == NULL) | 467 | if ((arr = reallocarray(NULL, max, sizeof(int))) == NULL) |
473 | goto err; | 468 | goto err; |
474 | ret = BN_GF2m_poly2arr(p, arr, max); | 469 | ret = BN_GF2m_poly2arr(p, arr, max); |
@@ -477,7 +472,6 @@ BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p) | |||
477 | goto err; | 472 | goto err; |
478 | } | 473 | } |
479 | ret = BN_GF2m_mod_arr(r, a, arr); | 474 | ret = BN_GF2m_mod_arr(r, a, arr); |
480 | bn_check_top(r); | ||
481 | 475 | ||
482 | err: | 476 | err: |
483 | free(arr); | 477 | free(arr); |
@@ -496,8 +490,6 @@ BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const int p[], | |||
496 | BIGNUM *s; | 490 | BIGNUM *s; |
497 | BN_ULONG x1, x0, y1, y0, zz[4]; | 491 | BN_ULONG x1, x0, y1, y0, zz[4]; |
498 | 492 | ||
499 | bn_check_top(a); | ||
500 | bn_check_top(b); | ||
501 | 493 | ||
502 | if (a == b) { | 494 | if (a == b) { |
503 | return BN_GF2m_mod_sqr_arr(r, a, p, ctx); | 495 | return BN_GF2m_mod_sqr_arr(r, a, p, ctx); |
@@ -530,7 +522,6 @@ BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const int p[], | |||
530 | bn_correct_top(s); | 522 | bn_correct_top(s); |
531 | if (BN_GF2m_mod_arr(r, s, p)) | 523 | if (BN_GF2m_mod_arr(r, s, p)) |
532 | ret = 1; | 524 | ret = 1; |
533 | bn_check_top(r); | ||
534 | 525 | ||
535 | err: | 526 | err: |
536 | BN_CTX_end(ctx); | 527 | BN_CTX_end(ctx); |
@@ -552,9 +543,6 @@ BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *p, | |||
552 | const int max = BN_num_bits(p) + 1; | 543 | const int max = BN_num_bits(p) + 1; |
553 | int *arr = NULL; | 544 | int *arr = NULL; |
554 | 545 | ||
555 | bn_check_top(a); | ||
556 | bn_check_top(b); | ||
557 | bn_check_top(p); | ||
558 | if ((arr = reallocarray(NULL, max, sizeof(int))) == NULL) | 546 | if ((arr = reallocarray(NULL, max, sizeof(int))) == NULL) |
559 | goto err; | 547 | goto err; |
560 | ret = BN_GF2m_poly2arr(p, arr, max); | 548 | ret = BN_GF2m_poly2arr(p, arr, max); |
@@ -563,7 +551,6 @@ BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *p, | |||
563 | goto err; | 551 | goto err; |
564 | } | 552 | } |
565 | ret = BN_GF2m_mod_mul_arr(r, a, b, arr, ctx); | 553 | ret = BN_GF2m_mod_mul_arr(r, a, b, arr, ctx); |
566 | bn_check_top(r); | ||
567 | 554 | ||
568 | err: | 555 | err: |
569 | free(arr); | 556 | free(arr); |
@@ -578,7 +565,6 @@ BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[], BN_CTX *ctx) | |||
578 | int i, ret = 0; | 565 | int i, ret = 0; |
579 | BIGNUM *s; | 566 | BIGNUM *s; |
580 | 567 | ||
581 | bn_check_top(a); | ||
582 | BN_CTX_start(ctx); | 568 | BN_CTX_start(ctx); |
583 | if ((s = BN_CTX_get(ctx)) == NULL) | 569 | if ((s = BN_CTX_get(ctx)) == NULL) |
584 | goto err; | 570 | goto err; |
@@ -594,7 +580,6 @@ BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[], BN_CTX *ctx) | |||
594 | bn_correct_top(s); | 580 | bn_correct_top(s); |
595 | if (!BN_GF2m_mod_arr(r, s, p)) | 581 | if (!BN_GF2m_mod_arr(r, s, p)) |
596 | goto err; | 582 | goto err; |
597 | bn_check_top(r); | ||
598 | ret = 1; | 583 | ret = 1; |
599 | 584 | ||
600 | err: | 585 | err: |
@@ -615,8 +600,6 @@ BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) | |||
615 | const int max = BN_num_bits(p) + 1; | 600 | const int max = BN_num_bits(p) + 1; |
616 | int *arr = NULL; | 601 | int *arr = NULL; |
617 | 602 | ||
618 | bn_check_top(a); | ||
619 | bn_check_top(p); | ||
620 | if ((arr = reallocarray(NULL, max, sizeof(int))) == NULL) | 603 | if ((arr = reallocarray(NULL, max, sizeof(int))) == NULL) |
621 | goto err; | 604 | goto err; |
622 | ret = BN_GF2m_poly2arr(p, arr, max); | 605 | ret = BN_GF2m_poly2arr(p, arr, max); |
@@ -625,7 +608,6 @@ BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) | |||
625 | goto err; | 608 | goto err; |
626 | } | 609 | } |
627 | ret = BN_GF2m_mod_sqr_arr(r, a, arr, ctx); | 610 | ret = BN_GF2m_mod_sqr_arr(r, a, arr, ctx); |
628 | bn_check_top(r); | ||
629 | 611 | ||
630 | err: | 612 | err: |
631 | free(arr); | 613 | free(arr); |
@@ -644,8 +626,6 @@ BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) | |||
644 | BIGNUM *b, *c = NULL, *u = NULL, *v = NULL, *tmp; | 626 | BIGNUM *b, *c = NULL, *u = NULL, *v = NULL, *tmp; |
645 | int ret = 0; | 627 | int ret = 0; |
646 | 628 | ||
647 | bn_check_top(a); | ||
648 | bn_check_top(p); | ||
649 | 629 | ||
650 | BN_CTX_start(ctx); | 630 | BN_CTX_start(ctx); |
651 | 631 | ||
@@ -795,7 +775,6 @@ BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) | |||
795 | 775 | ||
796 | if (!BN_copy(r, b)) | 776 | if (!BN_copy(r, b)) |
797 | goto err; | 777 | goto err; |
798 | bn_check_top(r); | ||
799 | ret = 1; | 778 | ret = 1; |
800 | 779 | ||
801 | err: | 780 | err: |
@@ -820,7 +799,6 @@ BN_GF2m_mod_inv_arr(BIGNUM *r, const BIGNUM *xx, const int p[], BN_CTX *ctx) | |||
820 | BIGNUM *field; | 799 | BIGNUM *field; |
821 | int ret = 0; | 800 | int ret = 0; |
822 | 801 | ||
823 | bn_check_top(xx); | ||
824 | BN_CTX_start(ctx); | 802 | BN_CTX_start(ctx); |
825 | if ((field = BN_CTX_get(ctx)) == NULL) | 803 | if ((field = BN_CTX_get(ctx)) == NULL) |
826 | goto err; | 804 | goto err; |
@@ -828,7 +806,6 @@ BN_GF2m_mod_inv_arr(BIGNUM *r, const BIGNUM *xx, const int p[], BN_CTX *ctx) | |||
828 | goto err; | 806 | goto err; |
829 | 807 | ||
830 | ret = BN_GF2m_mod_inv(r, xx, field, ctx); | 808 | ret = BN_GF2m_mod_inv(r, xx, field, ctx); |
831 | bn_check_top(r); | ||
832 | 809 | ||
833 | err: | 810 | err: |
834 | BN_CTX_end(ctx); | 811 | BN_CTX_end(ctx); |
@@ -847,9 +824,6 @@ BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *y, const BIGNUM *x, const BIGNUM *p, | |||
847 | BIGNUM *xinv = NULL; | 824 | BIGNUM *xinv = NULL; |
848 | int ret = 0; | 825 | int ret = 0; |
849 | 826 | ||
850 | bn_check_top(y); | ||
851 | bn_check_top(x); | ||
852 | bn_check_top(p); | ||
853 | 827 | ||
854 | BN_CTX_start(ctx); | 828 | BN_CTX_start(ctx); |
855 | if ((xinv = BN_CTX_get(ctx)) == NULL) | 829 | if ((xinv = BN_CTX_get(ctx)) == NULL) |
@@ -859,7 +833,6 @@ BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *y, const BIGNUM *x, const BIGNUM *p, | |||
859 | goto err; | 833 | goto err; |
860 | if (!BN_GF2m_mod_mul(r, y, xinv, p, ctx)) | 834 | if (!BN_GF2m_mod_mul(r, y, xinv, p, ctx)) |
861 | goto err; | 835 | goto err; |
862 | bn_check_top(r); | ||
863 | ret = 1; | 836 | ret = 1; |
864 | 837 | ||
865 | err: | 838 | err: |
@@ -880,9 +853,6 @@ BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *y, const BIGNUM *x, const BIGNUM *p, | |||
880 | BIGNUM *a, *b, *u, *v; | 853 | BIGNUM *a, *b, *u, *v; |
881 | int ret = 0; | 854 | int ret = 0; |
882 | 855 | ||
883 | bn_check_top(y); | ||
884 | bn_check_top(x); | ||
885 | bn_check_top(p); | ||
886 | 856 | ||
887 | BN_CTX_start(ctx); | 857 | BN_CTX_start(ctx); |
888 | 858 | ||
@@ -949,7 +919,6 @@ BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *y, const BIGNUM *x, const BIGNUM *p, | |||
949 | 919 | ||
950 | if (!BN_copy(r, u)) | 920 | if (!BN_copy(r, u)) |
951 | goto err; | 921 | goto err; |
952 | bn_check_top(r); | ||
953 | ret = 1; | 922 | ret = 1; |
954 | 923 | ||
955 | err: | 924 | err: |
@@ -972,8 +941,6 @@ BN_GF2m_mod_div_arr(BIGNUM *r, const BIGNUM *yy, const BIGNUM *xx, | |||
972 | BIGNUM *field; | 941 | BIGNUM *field; |
973 | int ret = 0; | 942 | int ret = 0; |
974 | 943 | ||
975 | bn_check_top(yy); | ||
976 | bn_check_top(xx); | ||
977 | 944 | ||
978 | BN_CTX_start(ctx); | 945 | BN_CTX_start(ctx); |
979 | if ((field = BN_CTX_get(ctx)) == NULL) | 946 | if ((field = BN_CTX_get(ctx)) == NULL) |
@@ -982,7 +949,6 @@ BN_GF2m_mod_div_arr(BIGNUM *r, const BIGNUM *yy, const BIGNUM *xx, | |||
982 | goto err; | 949 | goto err; |
983 | 950 | ||
984 | ret = BN_GF2m_mod_div(r, yy, xx, field, ctx); | 951 | ret = BN_GF2m_mod_div(r, yy, xx, field, ctx); |
985 | bn_check_top(r); | ||
986 | 952 | ||
987 | err: | 953 | err: |
988 | BN_CTX_end(ctx); | 954 | BN_CTX_end(ctx); |
@@ -1001,8 +967,6 @@ BN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const int p[], | |||
1001 | int ret = 0, i, n; | 967 | int ret = 0, i, n; |
1002 | BIGNUM *u; | 968 | BIGNUM *u; |
1003 | 969 | ||
1004 | bn_check_top(a); | ||
1005 | bn_check_top(b); | ||
1006 | 970 | ||
1007 | if (BN_is_zero(b)) | 971 | if (BN_is_zero(b)) |
1008 | return (BN_one(r)); | 972 | return (BN_one(r)); |
@@ -1028,7 +992,6 @@ BN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const int p[], | |||
1028 | } | 992 | } |
1029 | if (!BN_copy(r, u)) | 993 | if (!BN_copy(r, u)) |
1030 | goto err; | 994 | goto err; |
1031 | bn_check_top(r); | ||
1032 | ret = 1; | 995 | ret = 1; |
1033 | 996 | ||
1034 | err: | 997 | err: |
@@ -1051,9 +1014,6 @@ BN_GF2m_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *p, | |||
1051 | const int max = BN_num_bits(p) + 1; | 1014 | const int max = BN_num_bits(p) + 1; |
1052 | int *arr = NULL; | 1015 | int *arr = NULL; |
1053 | 1016 | ||
1054 | bn_check_top(a); | ||
1055 | bn_check_top(b); | ||
1056 | bn_check_top(p); | ||
1057 | if ((arr = reallocarray(NULL, max, sizeof(int))) == NULL) | 1017 | if ((arr = reallocarray(NULL, max, sizeof(int))) == NULL) |
1058 | goto err; | 1018 | goto err; |
1059 | ret = BN_GF2m_poly2arr(p, arr, max); | 1019 | ret = BN_GF2m_poly2arr(p, arr, max); |
@@ -1062,7 +1022,6 @@ BN_GF2m_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *p, | |||
1062 | goto err; | 1022 | goto err; |
1063 | } | 1023 | } |
1064 | ret = BN_GF2m_mod_exp_arr(r, a, b, arr, ctx); | 1024 | ret = BN_GF2m_mod_exp_arr(r, a, b, arr, ctx); |
1065 | bn_check_top(r); | ||
1066 | 1025 | ||
1067 | err: | 1026 | err: |
1068 | free(arr); | 1027 | free(arr); |
@@ -1079,7 +1038,6 @@ BN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a, const int p[], BN_CTX *ctx) | |||
1079 | int ret = 0; | 1038 | int ret = 0; |
1080 | BIGNUM *u; | 1039 | BIGNUM *u; |
1081 | 1040 | ||
1082 | bn_check_top(a); | ||
1083 | 1041 | ||
1084 | if (!p[0]) { | 1042 | if (!p[0]) { |
1085 | /* reduction mod 1 => return 0 */ | 1043 | /* reduction mod 1 => return 0 */ |
@@ -1094,7 +1052,6 @@ BN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a, const int p[], BN_CTX *ctx) | |||
1094 | if (!BN_set_bit(u, p[0] - 1)) | 1052 | if (!BN_set_bit(u, p[0] - 1)) |
1095 | goto err; | 1053 | goto err; |
1096 | ret = BN_GF2m_mod_exp_arr(r, a, u, p, ctx); | 1054 | ret = BN_GF2m_mod_exp_arr(r, a, u, p, ctx); |
1097 | bn_check_top(r); | ||
1098 | 1055 | ||
1099 | err: | 1056 | err: |
1100 | BN_CTX_end(ctx); | 1057 | BN_CTX_end(ctx); |
@@ -1114,8 +1071,6 @@ BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) | |||
1114 | int ret = 0; | 1071 | int ret = 0; |
1115 | const int max = BN_num_bits(p) + 1; | 1072 | const int max = BN_num_bits(p) + 1; |
1116 | int *arr = NULL; | 1073 | int *arr = NULL; |
1117 | bn_check_top(a); | ||
1118 | bn_check_top(p); | ||
1119 | if ((arr = reallocarray(NULL, max, sizeof(int))) == NULL) | 1074 | if ((arr = reallocarray(NULL, max, sizeof(int))) == NULL) |
1120 | goto err; | 1075 | goto err; |
1121 | ret = BN_GF2m_poly2arr(p, arr, max); | 1076 | ret = BN_GF2m_poly2arr(p, arr, max); |
@@ -1124,7 +1079,6 @@ BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) | |||
1124 | goto err; | 1079 | goto err; |
1125 | } | 1080 | } |
1126 | ret = BN_GF2m_mod_sqrt_arr(r, a, arr, ctx); | 1081 | ret = BN_GF2m_mod_sqrt_arr(r, a, arr, ctx); |
1127 | bn_check_top(r); | ||
1128 | 1082 | ||
1129 | err: | 1083 | err: |
1130 | free(arr); | 1084 | free(arr); |
@@ -1141,7 +1095,6 @@ BN_GF2m_mod_solve_quad_arr(BIGNUM *r, const BIGNUM *a_, const int p[], | |||
1141 | int ret = 0, count = 0, j; | 1095 | int ret = 0, count = 0, j; |
1142 | BIGNUM *a, *z, *rho, *w, *w2, *tmp; | 1096 | BIGNUM *a, *z, *rho, *w, *w2, *tmp; |
1143 | 1097 | ||
1144 | bn_check_top(a_); | ||
1145 | 1098 | ||
1146 | if (!p[0]) { | 1099 | if (!p[0]) { |
1147 | /* reduction mod 1 => return 0 */ | 1100 | /* reduction mod 1 => return 0 */ |
@@ -1228,7 +1181,6 @@ BN_GF2m_mod_solve_quad_arr(BIGNUM *r, const BIGNUM *a_, const int p[], | |||
1228 | 1181 | ||
1229 | if (!BN_copy(r, z)) | 1182 | if (!BN_copy(r, z)) |
1230 | goto err; | 1183 | goto err; |
1231 | bn_check_top(r); | ||
1232 | 1184 | ||
1233 | ret = 1; | 1185 | ret = 1; |
1234 | 1186 | ||
@@ -1250,8 +1202,6 @@ BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) | |||
1250 | const int max = BN_num_bits(p) + 1; | 1202 | const int max = BN_num_bits(p) + 1; |
1251 | int *arr = NULL; | 1203 | int *arr = NULL; |
1252 | 1204 | ||
1253 | bn_check_top(a); | ||
1254 | bn_check_top(p); | ||
1255 | if ((arr = reallocarray(NULL, max, sizeof(int))) == NULL) | 1205 | if ((arr = reallocarray(NULL, max, sizeof(int))) == NULL) |
1256 | goto err; | 1206 | goto err; |
1257 | ret = BN_GF2m_poly2arr(p, arr, max); | 1207 | ret = BN_GF2m_poly2arr(p, arr, max); |
@@ -1260,7 +1210,6 @@ BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) | |||
1260 | goto err; | 1210 | goto err; |
1261 | } | 1211 | } |
1262 | ret = BN_GF2m_mod_solve_quad_arr(r, a, arr, ctx); | 1212 | ret = BN_GF2m_mod_solve_quad_arr(r, a, arr, ctx); |
1263 | bn_check_top(r); | ||
1264 | 1213 | ||
1265 | err: | 1214 | err: |
1266 | free(arr); | 1215 | free(arr); |
@@ -1312,13 +1261,11 @@ BN_GF2m_arr2poly(const int p[], BIGNUM *a) | |||
1312 | { | 1261 | { |
1313 | int i; | 1262 | int i; |
1314 | 1263 | ||
1315 | bn_check_top(a); | ||
1316 | BN_zero(a); | 1264 | BN_zero(a); |
1317 | for (i = 0; p[i] != -1; i++) { | 1265 | for (i = 0; p[i] != -1; i++) { |
1318 | if (BN_set_bit(a, p[i]) == 0) | 1266 | if (BN_set_bit(a, p[i]) == 0) |
1319 | return 0; | 1267 | return 0; |
1320 | } | 1268 | } |
1321 | bn_check_top(a); | ||
1322 | 1269 | ||
1323 | return 1; | 1270 | return 1; |
1324 | } | 1271 | } |