diff options
| author | jsing <> | 2018-11-08 22:20:25 +0000 |
|---|---|---|
| committer | jsing <> | 2018-11-08 22:20:25 +0000 |
| commit | 80dc683994dcdda2b01fd893a5c06c06409e703a (patch) | |
| tree | 6a0b94b4321fa9506ce02074bdbb52724a52f86a | |
| parent | 4994554f5989409aa9e5c0c3bb20dbe99b0a377d (diff) | |
| download | openbsd-80dc683994dcdda2b01fd893a5c06c06409e703a.tar.gz openbsd-80dc683994dcdda2b01fd893a5c06c06409e703a.tar.bz2 openbsd-80dc683994dcdda2b01fd893a5c06c06409e703a.zip | |
Add missing NULL checks on allocation, style(9) and consistently use
goto err instead of handrolling.
Diffstat (limited to '')
| -rw-r--r-- | src/regress/lib/libcrypto/exp/exptest.c | 69 |
1 files changed, 34 insertions, 35 deletions
diff --git a/src/regress/lib/libcrypto/exp/exptest.c b/src/regress/lib/libcrypto/exp/exptest.c index abed6adb70..e7f5848528 100644 --- a/src/regress/lib/libcrypto/exp/exptest.c +++ b/src/regress/lib/libcrypto/exp/exptest.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: exptest.c,v 1.6 2018/11/08 21:40:52 jsing Exp $ */ | 1 | /* $OpenBSD: exptest.c,v 1.7 2018/11/08 22:20:25 jsing Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -204,33 +204,37 @@ static int test_exp_mod_zero(void) | |||
| 204 | 204 | ||
| 205 | int main(int argc, char *argv[]) | 205 | int main(int argc, char *argv[]) |
| 206 | { | 206 | { |
| 207 | BIGNUM *r_mont, *r_mont_const, *r_recp, *r_simple; | ||
| 208 | BIGNUM *r_mont_ct, *r_mont_nonct, *a, *b, *m; | ||
| 207 | BN_CTX *ctx; | 209 | BN_CTX *ctx; |
| 208 | BIO *out = NULL; | 210 | BIO *out = NULL; |
| 209 | int i, ret; | ||
| 210 | unsigned char c; | 211 | unsigned char c; |
| 211 | BIGNUM *r_mont, *r_mont_const, *r_recp, *r_simple, | 212 | int i, ret; |
| 212 | *r_mont_ct, *r_mont_nonct, *a, *b, *m; | ||
| 213 | 213 | ||
| 214 | ERR_load_BN_strings(); | 214 | ERR_load_BN_strings(); |
| 215 | 215 | ||
| 216 | ctx = BN_CTX_new(); | 216 | if ((ctx = BN_CTX_new()) == NULL) |
| 217 | if (ctx == NULL) | 217 | goto err; |
| 218 | exit(1); | 218 | if ((r_mont = BN_new()) == NULL) |
| 219 | r_mont = BN_new(); | 219 | goto err; |
| 220 | r_mont_const = BN_new(); | 220 | if ((r_mont_const = BN_new()) == NULL) |
| 221 | r_mont_ct = BN_new(); | 221 | goto err; |
| 222 | r_mont_nonct = BN_new(); | 222 | if ((r_mont_ct = BN_new()) == NULL) |
| 223 | r_recp = BN_new(); | 223 | goto err; |
| 224 | r_simple = BN_new(); | 224 | if ((r_mont_nonct = BN_new()) == NULL) |
| 225 | a = BN_new(); | 225 | goto err; |
| 226 | b = BN_new(); | 226 | if ((r_recp = BN_new()) == NULL) |
| 227 | m = BN_new(); | 227 | goto err; |
| 228 | if ((r_mont == NULL) || (r_recp == NULL) || (a == NULL) || (b == NULL)) | 228 | if ((r_simple = BN_new()) == NULL) |
| 229 | goto err; | ||
| 230 | if ((a = BN_new()) == NULL) | ||
| 231 | goto err; | ||
| 232 | if ((b = BN_new()) == NULL) | ||
| 233 | goto err; | ||
| 234 | if ((m = BN_new()) == NULL) | ||
| 229 | goto err; | 235 | goto err; |
| 230 | 236 | ||
| 231 | out = BIO_new(BIO_s_file()); | 237 | if ((out = BIO_new(BIO_s_file())) == NULL) |
| 232 | |||
| 233 | if (out == NULL) | ||
| 234 | exit(1); | 238 | exit(1); |
| 235 | BIO_set_fp(out, stdout, BIO_NOCLOSE); | 239 | BIO_set_fp(out, stdout, BIO_NOCLOSE); |
| 236 | 240 | ||
| @@ -253,48 +257,42 @@ int main(int argc, char *argv[]) | |||
| 253 | ret = BN_mod_exp_mont(r_mont, a, b, m, ctx, NULL); | 257 | ret = BN_mod_exp_mont(r_mont, a, b, m, ctx, NULL); |
| 254 | if (ret <= 0) { | 258 | if (ret <= 0) { |
| 255 | printf("BN_mod_exp_mont() problems\n"); | 259 | printf("BN_mod_exp_mont() problems\n"); |
| 256 | ERR_print_errors(out); | 260 | goto err; |
| 257 | exit(1); | ||
| 258 | } | 261 | } |
| 259 | 262 | ||
| 260 | ret = BN_mod_exp_mont_ct(r_mont_ct, a, b, m, ctx, NULL); | 263 | ret = BN_mod_exp_mont_ct(r_mont_ct, a, b, m, ctx, NULL); |
| 261 | if (ret <= 0) { | 264 | if (ret <= 0) { |
| 262 | printf("BN_mod_exp_mont_ct() problems\n"); | 265 | printf("BN_mod_exp_mont_ct() problems\n"); |
| 263 | ERR_print_errors(out); | 266 | goto err; |
| 264 | exit(1); | ||
| 265 | } | 267 | } |
| 266 | 268 | ||
| 267 | ret = BN_mod_exp_mont_nonct(r_mont_nonct, a, b, m, ctx, NULL); | 269 | ret = BN_mod_exp_mont_nonct(r_mont_nonct, a, b, m, ctx, NULL); |
| 268 | if (ret <= 0) { | 270 | if (ret <= 0) { |
| 269 | printf("BN_mod_exp_mont_nonct() problems\n"); | 271 | printf("BN_mod_exp_mont_nonct() problems\n"); |
| 270 | ERR_print_errors(out); | 272 | goto err; |
| 271 | exit(1); | ||
| 272 | } | 273 | } |
| 273 | 274 | ||
| 274 | ret = BN_mod_exp_recp(r_recp, a, b, m, ctx); | 275 | ret = BN_mod_exp_recp(r_recp, a, b, m, ctx); |
| 275 | if (ret <= 0) { | 276 | if (ret <= 0) { |
| 276 | printf("BN_mod_exp_recp() problems\n"); | 277 | printf("BN_mod_exp_recp() problems\n"); |
| 277 | ERR_print_errors(out); | 278 | goto err; |
| 278 | exit(1); | ||
| 279 | } | 279 | } |
| 280 | 280 | ||
| 281 | ret = BN_mod_exp_simple(r_simple, a, b, m, ctx); | 281 | ret = BN_mod_exp_simple(r_simple, a, b, m, ctx); |
| 282 | if (ret <= 0) { | 282 | if (ret <= 0) { |
| 283 | printf("BN_mod_exp_simple() problems\n"); | 283 | printf("BN_mod_exp_simple() problems\n"); |
| 284 | ERR_print_errors(out); | 284 | goto err; |
| 285 | exit(1); | ||
| 286 | } | 285 | } |
| 287 | 286 | ||
| 288 | ret = BN_mod_exp_mont_consttime(r_mont_const, a, b, m, ctx, NULL); | 287 | ret = BN_mod_exp_mont_consttime(r_mont_const, a, b, m, ctx, NULL); |
| 289 | if (ret <= 0) { | 288 | if (ret <= 0) { |
| 290 | printf("BN_mod_exp_mont_consttime() problems\n"); | 289 | printf("BN_mod_exp_mont_consttime() problems\n"); |
| 291 | ERR_print_errors(out); | 290 | goto err; |
| 292 | exit(1); | ||
| 293 | } | 291 | } |
| 294 | 292 | ||
| 295 | if (BN_cmp(r_simple, r_mont) == 0 | 293 | if (BN_cmp(r_simple, r_mont) == 0 && |
| 296 | && BN_cmp(r_simple, r_recp) == 0 | 294 | BN_cmp(r_simple, r_recp) == 0 && |
| 297 | && BN_cmp(r_simple, r_mont_const) == 0) { | 295 | BN_cmp(r_simple, r_mont_const) == 0) { |
| 298 | printf("."); | 296 | printf("."); |
| 299 | fflush(stdout); | 297 | fflush(stdout); |
| 300 | } else { | 298 | } else { |
| @@ -348,6 +346,7 @@ int main(int argc, char *argv[]) | |||
| 348 | printf("done\n"); | 346 | printf("done\n"); |
| 349 | 347 | ||
| 350 | return (0); | 348 | return (0); |
| 349 | |||
| 351 | err: | 350 | err: |
| 352 | ERR_load_crypto_strings(); | 351 | ERR_load_crypto_strings(); |
| 353 | ERR_print_errors(out); | 352 | ERR_print_errors(out); |
