diff options
author | jsing <> | 2015-02-09 15:49:22 +0000 |
---|---|---|
committer | jsing <> | 2015-02-09 15:49:22 +0000 |
commit | 16f790d01f7a6fc6c94e2a033a67b80c8ec5291c (patch) | |
tree | d924c624d5eb949a9e7e395dc99d92616e911ce9 /src/lib/libcrypto/ec/ecp_smpl.c | |
parent | 42f7780549de5b7b5e3e7943cfef87e0e41970fc (diff) | |
download | openbsd-16f790d01f7a6fc6c94e2a033a67b80c8ec5291c.tar.gz openbsd-16f790d01f7a6fc6c94e2a033a67b80c8ec5291c.tar.bz2 openbsd-16f790d01f7a6fc6c94e2a033a67b80c8ec5291c.zip |
BN_CTX_get() can fail - consistently check its return value.
There are currently cases where the return from each call is checked,
the return from only the last call is checked and cases where it is not
checked at all (including code in bn, ec and engine).
Checking the last return value is valid as once the function fails it will
continue to return NULL. However, in order to be consistent check each
call with the same idiom. This makes it easy to verify.
Note there are still a handful of cases that do not follow the idiom -
these will be handled separately.
ok beck@ doug@
Diffstat (limited to 'src/lib/libcrypto/ec/ecp_smpl.c')
-rw-r--r-- | src/lib/libcrypto/ec/ecp_smpl.c | 101 |
1 files changed, 58 insertions, 43 deletions
diff --git a/src/lib/libcrypto/ec/ecp_smpl.c b/src/lib/libcrypto/ec/ecp_smpl.c index 7b3bb2364d..f6db4dc9b1 100644 --- a/src/lib/libcrypto/ec/ecp_smpl.c +++ b/src/lib/libcrypto/ec/ecp_smpl.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ecp_smpl.c,v 1.14 2015/02/08 22:25:03 miod Exp $ */ | 1 | /* $OpenBSD: ecp_smpl.c,v 1.15 2015/02/09 15:49:22 jsing Exp $ */ |
2 | /* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de> | 2 | /* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de> |
3 | * for the OpenSSL project. | 3 | * for the OpenSSL project. |
4 | * Includes code written by Bodo Moeller for the OpenSSL project. | 4 | * Includes code written by Bodo Moeller for the OpenSSL project. |
@@ -188,8 +188,7 @@ ec_GFp_simple_group_set_curve(EC_GROUP * group, | |||
188 | return 0; | 188 | return 0; |
189 | } | 189 | } |
190 | BN_CTX_start(ctx); | 190 | BN_CTX_start(ctx); |
191 | tmp_a = BN_CTX_get(ctx); | 191 | if ((tmp_a = BN_CTX_get(ctx)) == NULL) |
192 | if (tmp_a == NULL) | ||
193 | goto err; | 192 | goto err; |
194 | 193 | ||
195 | /* group->field */ | 194 | /* group->field */ |
@@ -294,12 +293,15 @@ ec_GFp_simple_group_check_discriminant(const EC_GROUP * group, BN_CTX * ctx) | |||
294 | } | 293 | } |
295 | } | 294 | } |
296 | BN_CTX_start(ctx); | 295 | BN_CTX_start(ctx); |
297 | a = BN_CTX_get(ctx); | 296 | if ((a = BN_CTX_get(ctx)) == NULL) |
298 | b = BN_CTX_get(ctx); | 297 | goto err; |
299 | tmp_1 = BN_CTX_get(ctx); | 298 | if ((b = BN_CTX_get(ctx)) == NULL) |
300 | tmp_2 = BN_CTX_get(ctx); | 299 | goto err; |
301 | order = BN_CTX_get(ctx); | 300 | if ((tmp_1 = BN_CTX_get(ctx)) == NULL) |
302 | if (order == NULL) | 301 | goto err; |
302 | if ((tmp_2 = BN_CTX_get(ctx)) == NULL) | ||
303 | goto err; | ||
304 | if ((order = BN_CTX_get(ctx)) == NULL) | ||
303 | goto err; | 305 | goto err; |
304 | 306 | ||
305 | if (group->meth->field_decode) { | 307 | if (group->meth->field_decode) { |
@@ -539,11 +541,13 @@ ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP * group, const EC_POIN | |||
539 | return 0; | 541 | return 0; |
540 | } | 542 | } |
541 | BN_CTX_start(ctx); | 543 | BN_CTX_start(ctx); |
542 | Z = BN_CTX_get(ctx); | 544 | if ((Z = BN_CTX_get(ctx)) == NULL) |
543 | Z_1 = BN_CTX_get(ctx); | 545 | goto err; |
544 | Z_2 = BN_CTX_get(ctx); | 546 | if ((Z_1 = BN_CTX_get(ctx)) == NULL) |
545 | Z_3 = BN_CTX_get(ctx); | 547 | goto err; |
546 | if (Z_3 == NULL) | 548 | if ((Z_2 = BN_CTX_get(ctx)) == NULL) |
549 | goto err; | ||
550 | if ((Z_3 = BN_CTX_get(ctx)) == NULL) | ||
547 | goto err; | 551 | goto err; |
548 | 552 | ||
549 | /* transform (X, Y, Z) into (x, y) := (X/Z^2, Y/Z^3) */ | 553 | /* transform (X, Y, Z) into (x, y) := (X/Z^2, Y/Z^3) */ |
@@ -652,14 +656,19 @@ ec_GFp_simple_add(const EC_GROUP * group, EC_POINT * r, const EC_POINT * a, cons | |||
652 | return 0; | 656 | return 0; |
653 | } | 657 | } |
654 | BN_CTX_start(ctx); | 658 | BN_CTX_start(ctx); |
655 | n0 = BN_CTX_get(ctx); | 659 | if ((n0 = BN_CTX_get(ctx)) == NULL) |
656 | n1 = BN_CTX_get(ctx); | 660 | goto end; |
657 | n2 = BN_CTX_get(ctx); | 661 | if ((n1 = BN_CTX_get(ctx)) == NULL) |
658 | n3 = BN_CTX_get(ctx); | 662 | goto end; |
659 | n4 = BN_CTX_get(ctx); | 663 | if ((n2 = BN_CTX_get(ctx)) == NULL) |
660 | n5 = BN_CTX_get(ctx); | 664 | goto end; |
661 | n6 = BN_CTX_get(ctx); | 665 | if ((n3 = BN_CTX_get(ctx)) == NULL) |
662 | if (n6 == NULL) | 666 | goto end; |
667 | if ((n4 = BN_CTX_get(ctx)) == NULL) | ||
668 | goto end; | ||
669 | if ((n5 = BN_CTX_get(ctx)) == NULL) | ||
670 | goto end; | ||
671 | if ((n6 = BN_CTX_get(ctx)) == NULL) | ||
663 | goto end; | 672 | goto end; |
664 | 673 | ||
665 | /* | 674 | /* |
@@ -834,11 +843,13 @@ ec_GFp_simple_dbl(const EC_GROUP * group, EC_POINT * r, const EC_POINT * a, BN_C | |||
834 | return 0; | 843 | return 0; |
835 | } | 844 | } |
836 | BN_CTX_start(ctx); | 845 | BN_CTX_start(ctx); |
837 | n0 = BN_CTX_get(ctx); | 846 | if ((n0 = BN_CTX_get(ctx)) == NULL) |
838 | n1 = BN_CTX_get(ctx); | 847 | goto err; |
839 | n2 = BN_CTX_get(ctx); | 848 | if ((n1 = BN_CTX_get(ctx)) == NULL) |
840 | n3 = BN_CTX_get(ctx); | 849 | goto err; |
841 | if (n3 == NULL) | 850 | if ((n2 = BN_CTX_get(ctx)) == NULL) |
851 | goto err; | ||
852 | if ((n3 = BN_CTX_get(ctx)) == NULL) | ||
842 | goto err; | 853 | goto err; |
843 | 854 | ||
844 | /* | 855 | /* |
@@ -990,11 +1001,13 @@ ec_GFp_simple_is_on_curve(const EC_GROUP * group, const EC_POINT * point, BN_CTX | |||
990 | return -1; | 1001 | return -1; |
991 | } | 1002 | } |
992 | BN_CTX_start(ctx); | 1003 | BN_CTX_start(ctx); |
993 | rh = BN_CTX_get(ctx); | 1004 | if ((rh = BN_CTX_get(ctx)) == NULL) |
994 | tmp = BN_CTX_get(ctx); | 1005 | goto err; |
995 | Z4 = BN_CTX_get(ctx); | 1006 | if ((tmp = BN_CTX_get(ctx)) == NULL) |
996 | Z6 = BN_CTX_get(ctx); | 1007 | goto err; |
997 | if (Z6 == NULL) | 1008 | if ((Z4 = BN_CTX_get(ctx)) == NULL) |
1009 | goto err; | ||
1010 | if ((Z6 = BN_CTX_get(ctx)) == NULL) | ||
998 | goto err; | 1011 | goto err; |
999 | 1012 | ||
1000 | /* | 1013 | /* |
@@ -1101,11 +1114,13 @@ ec_GFp_simple_cmp(const EC_GROUP * group, const EC_POINT * a, const EC_POINT * b | |||
1101 | return -1; | 1114 | return -1; |
1102 | } | 1115 | } |
1103 | BN_CTX_start(ctx); | 1116 | BN_CTX_start(ctx); |
1104 | tmp1 = BN_CTX_get(ctx); | 1117 | if ((tmp1 = BN_CTX_get(ctx)) == NULL) |
1105 | tmp2 = BN_CTX_get(ctx); | 1118 | goto end; |
1106 | Za23 = BN_CTX_get(ctx); | 1119 | if ((tmp2 = BN_CTX_get(ctx)) == NULL) |
1107 | Zb23 = BN_CTX_get(ctx); | 1120 | goto end; |
1108 | if (Zb23 == NULL) | 1121 | if ((Za23 = BN_CTX_get(ctx)) == NULL) |
1122 | goto end; | ||
1123 | if ((Zb23 = BN_CTX_get(ctx)) == NULL) | ||
1109 | goto end; | 1124 | goto end; |
1110 | 1125 | ||
1111 | /* | 1126 | /* |
@@ -1184,9 +1199,9 @@ ec_GFp_simple_make_affine(const EC_GROUP * group, EC_POINT * point, BN_CTX * ctx | |||
1184 | return 0; | 1199 | return 0; |
1185 | } | 1200 | } |
1186 | BN_CTX_start(ctx); | 1201 | BN_CTX_start(ctx); |
1187 | x = BN_CTX_get(ctx); | 1202 | if ((x = BN_CTX_get(ctx)) == NULL) |
1188 | y = BN_CTX_get(ctx); | 1203 | goto err; |
1189 | if (y == NULL) | 1204 | if ((y = BN_CTX_get(ctx)) == NULL) |
1190 | goto err; | 1205 | goto err; |
1191 | 1206 | ||
1192 | if (!EC_POINT_get_affine_coordinates_GFp(group, point, x, y, ctx)) | 1207 | if (!EC_POINT_get_affine_coordinates_GFp(group, point, x, y, ctx)) |
@@ -1225,9 +1240,9 @@ ec_GFp_simple_points_make_affine(const EC_GROUP * group, size_t num, EC_POINT * | |||
1225 | return 0; | 1240 | return 0; |
1226 | } | 1241 | } |
1227 | BN_CTX_start(ctx); | 1242 | BN_CTX_start(ctx); |
1228 | tmp0 = BN_CTX_get(ctx); | 1243 | if ((tmp0 = BN_CTX_get(ctx)) == NULL) |
1229 | tmp1 = BN_CTX_get(ctx); | 1244 | goto err; |
1230 | if (tmp0 == NULL || tmp1 == NULL) | 1245 | if ((tmp1 = BN_CTX_get(ctx)) == NULL) |
1231 | goto err; | 1246 | goto err; |
1232 | 1247 | ||
1233 | /* | 1248 | /* |