diff options
author | tb <> | 2021-12-04 08:15:16 +0000 |
---|---|---|
committer | tb <> | 2021-12-04 08:15:16 +0000 |
commit | 210ec512cac8ada8e3b0f62cdf161dd6ea1a1b96 (patch) | |
tree | b9db94e9dd27988bf0e71083b52e361ff59418ec /src/regress/lib | |
parent | d6397c6136efeac1c7ed9a52d7492a73595da922 (diff) | |
download | openbsd-210ec512cac8ada8e3b0f62cdf161dd6ea1a1b96.tar.gz openbsd-210ec512cac8ada8e3b0f62cdf161dd6ea1a1b96.tar.bz2 openbsd-210ec512cac8ada8e3b0f62cdf161dd6ea1a1b96.zip |
Convert main into single exit to appease asan.
Diffstat (limited to 'src/regress/lib')
-rw-r--r-- | src/regress/lib/libcrypto/gost/gost2814789t.c | 55 |
1 files changed, 33 insertions, 22 deletions
diff --git a/src/regress/lib/libcrypto/gost/gost2814789t.c b/src/regress/lib/libcrypto/gost/gost2814789t.c index 6ba5561984..eb60517f49 100644 --- a/src/regress/lib/libcrypto/gost/gost2814789t.c +++ b/src/regress/lib/libcrypto/gost/gost2814789t.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: gost2814789t.c,v 1.5 2021/11/18 21:26:54 tb Exp $ */ | 1 | /* $OpenBSD: gost2814789t.c,v 1.6 2021/12/04 08:15:16 tb Exp $ */ |
2 | /* vim: set fileencoding=ascii : Charset: ASCII */ | 2 | /* vim: set fileencoding=ascii : Charset: ASCII */ |
3 | /* test/gostr2814789t.c */ | 3 | /* test/gostr2814789t.c */ |
4 | /* ==================================================================== | 4 | /* ==================================================================== |
@@ -1270,17 +1270,19 @@ int main(int argc, char *argv[]) | |||
1270 | const EVP_CIPHER *cp_g89cnt = NULL; | 1270 | const EVP_CIPHER *cp_g89cnt = NULL; |
1271 | const EVP_CIPHER *ctype = NULL; | 1271 | const EVP_CIPHER *ctype = NULL; |
1272 | const EVP_MD *md_g89imit = NULL; | 1272 | const EVP_MD *md_g89imit = NULL; |
1273 | int ret = 0; | ||
1273 | 1274 | ||
1274 | printf("Testing GOST 28147-89 "); | 1275 | printf("Testing GOST 28147-89 "); |
1275 | 1276 | ||
1276 | if(1 < argc) { | 1277 | if(1 < argc) { |
1277 | if(1 != sscanf(argv[1], "%" SCNu64, &ullMaxLen) || | 1278 | if(1 != sscanf(argv[1], "%" SCNu64, &ullMaxLen) || |
1278 | ( 2 < argc ? | 1279 | ( 2 < argc ? |
1279 | 1 != sscanf(argv[2], "%d", &ignore) : 0)) { | 1280 | 1 != sscanf(argv[2], "%d", &ignore) : 0)) { |
1280 | fflush(NULL); | 1281 | fflush(NULL); |
1281 | fprintf(stderr, "Usage: %s [maxlen [ignore-error]]\n", | 1282 | fprintf(stderr, "Usage: %s [maxlen [ignore-error]]\n", |
1282 | argv[0]); | 1283 | argv[0]); |
1283 | return 1; | 1284 | ret = 1; |
1285 | goto out; | ||
1284 | } | 1286 | } |
1285 | } | 1287 | } |
1286 | 1288 | ||
@@ -1297,35 +1299,40 @@ int main(int argc, char *argv[]) | |||
1297 | fflush(NULL); | 1299 | fflush(NULL); |
1298 | fprintf(stderr, "\"" SN_id_GostR3411_94 "\" - not found\n"); | 1300 | fprintf(stderr, "\"" SN_id_GostR3411_94 "\" - not found\n"); |
1299 | if(!ignore) { | 1301 | if(!ignore) { |
1300 | return 7; | 1302 | ret = 7; |
1303 | goto out; | ||
1301 | } | 1304 | } |
1302 | } | 1305 | } |
1303 | if(NULL == (cp_g89cfb = EVP_get_cipherbyname(SN_id_Gost28147_89))) { | 1306 | if(NULL == (cp_g89cfb = EVP_get_cipherbyname(SN_id_Gost28147_89))) { |
1304 | fflush(NULL); | 1307 | fflush(NULL); |
1305 | fprintf(stderr, "\"" SN_id_Gost28147_89 "\" - not found\n"); | 1308 | fprintf(stderr, "\"" SN_id_Gost28147_89 "\" - not found\n"); |
1306 | if(!ignore) { | 1309 | if(!ignore) { |
1307 | return 8; | 1310 | ret = 8; |
1311 | goto out; | ||
1308 | } | 1312 | } |
1309 | } | 1313 | } |
1310 | if(NULL == (cp_g89cnt = EVP_get_cipherbyname(SN_gost89_cnt))) { | 1314 | if(NULL == (cp_g89cnt = EVP_get_cipherbyname(SN_gost89_cnt))) { |
1311 | fflush(NULL); | 1315 | fflush(NULL); |
1312 | fprintf(stderr, "\"" SN_gost89_cnt "\" - not found\n"); | 1316 | fprintf(stderr, "\"" SN_gost89_cnt "\" - not found\n"); |
1313 | if(!ignore) { | 1317 | if(!ignore) { |
1314 | return 9; | 1318 | ret = 9; |
1319 | goto out; | ||
1315 | } | 1320 | } |
1316 | } | 1321 | } |
1317 | if(NULL == (cp_g89ecb = EVP_get_cipherbyname(SN_gost89_ecb))) { | 1322 | if(NULL == (cp_g89ecb = EVP_get_cipherbyname(SN_gost89_ecb))) { |
1318 | fflush(NULL); | 1323 | fflush(NULL); |
1319 | fprintf(stderr, "\"" SN_gost89_ecb "\" - not found\n"); | 1324 | fprintf(stderr, "\"" SN_gost89_ecb "\" - not found\n"); |
1320 | if(!ignore) { | 1325 | if(!ignore) { |
1321 | return 8; | 1326 | ret = 8; |
1327 | goto out; | ||
1322 | } | 1328 | } |
1323 | } | 1329 | } |
1324 | if(NULL == (md_g89imit = EVP_get_digestbyname(SN_id_Gost28147_89_MAC))) { | 1330 | if(NULL == (md_g89imit = EVP_get_digestbyname(SN_id_Gost28147_89_MAC))) { |
1325 | fflush(NULL); | 1331 | fflush(NULL); |
1326 | fprintf(stderr, "\"" SN_id_Gost28147_89_MAC "\" - not found\n"); | 1332 | fprintf(stderr, "\"" SN_id_Gost28147_89_MAC "\" - not found\n"); |
1327 | if(!ignore) { | 1333 | if(!ignore) { |
1328 | return 10; | 1334 | ret = 10; |
1335 | goto out; | ||
1329 | } | 1336 | } |
1330 | } | 1337 | } |
1331 | 1338 | ||
@@ -1334,15 +1341,16 @@ int main(int argc, char *argv[]) | |||
1334 | if(NULL != tcs[t].szDerive) { | 1341 | if(NULL != tcs[t].szDerive) { |
1335 | memset(bDerive, 0x3c, sizeof(bDerive)); | 1342 | memset(bDerive, 0x3c, sizeof(bDerive)); |
1336 | mdl = sizeof(bDerive); | 1343 | mdl = sizeof(bDerive); |
1337 | EVP_Digest(tcs[t].szDerive, strlen(tcs[t].szDerive), | 1344 | EVP_Digest(tcs[t].szDerive, strlen(tcs[t].szDerive), |
1338 | bDerive, &mdl, | 1345 | bDerive, &mdl, |
1339 | md_gost94, NULL); | 1346 | md_gost94, NULL); |
1340 | if(0 != memcmp(tcs[t].bRawKey, bDerive, mdl)) { | 1347 | if(0 != memcmp(tcs[t].bRawKey, bDerive, mdl)) { |
1341 | fflush(NULL); | 1348 | fflush(NULL); |
1342 | fprintf(stderr, "Engine test t=%d " | 1349 | fprintf(stderr, "Engine test t=%d " |
1343 | "derive key error.\n", t); | 1350 | "derive key error.\n", t); |
1344 | if(!ignore) { | 1351 | if(!ignore) { |
1345 | return 12; | 1352 | ret = 12; |
1353 | goto out; | ||
1346 | } | 1354 | } |
1347 | } | 1355 | } |
1348 | } | 1356 | } |
@@ -1374,16 +1382,16 @@ engine_cipher_check: | |||
1374 | tcs[t].bIn, (int)tcs[t].ullLen); | 1382 | tcs[t].bIn, (int)tcs[t].ullLen); |
1375 | l = (size_t)tcs[t].ullLen; | 1383 | l = (size_t)tcs[t].ullLen; |
1376 | } else { | 1384 | } else { |
1377 | for(ullLeft = tcs[t].ullLen; | 1385 | for(ullLeft = tcs[t].ullLen; |
1378 | ullLeft >= sizeof(bZB); | 1386 | ullLeft >= sizeof(bZB); |
1379 | ullLeft -= sizeof(bZB)) { | 1387 | ullLeft -= sizeof(bZB)) { |
1380 | printf("B"); | 1388 | printf("B"); |
1381 | fflush(NULL); | 1389 | fflush(NULL); |
1382 | enlu = sizeof(bTS); | 1390 | enlu = sizeof(bTS); |
1383 | EVP_EncryptUpdate(ectx, bTS, &enlu, | 1391 | EVP_EncryptUpdate(ectx, bTS, &enlu, |
1384 | bZB, sizeof(bZB)); | 1392 | bZB, sizeof(bZB)); |
1385 | } | 1393 | } |
1386 | printf("b%" PRIu64 "/%" PRIu64, ullLeft, tcs[t].ullLen); | 1394 | printf("b%" PRIu64 "/%" PRIu64, ullLeft, tcs[t].ullLen); |
1387 | fflush(NULL); | 1395 | fflush(NULL); |
1388 | EVP_EncryptUpdate(ectx, bTS, &enlu, | 1396 | EVP_EncryptUpdate(ectx, bTS, &enlu, |
1389 | bZB, (int)ullLeft); | 1397 | bZB, (int)ullLeft); |
@@ -1413,14 +1421,14 @@ engine_cipher_check: | |||
1413 | EVP_DigestSignUpdate(mctx, tcs[t].bIn, | 1421 | EVP_DigestSignUpdate(mctx, tcs[t].bIn, |
1414 | (unsigned int)tcs[t].ullLen); | 1422 | (unsigned int)tcs[t].ullLen); |
1415 | } else { | 1423 | } else { |
1416 | for(ullLeft = tcs[t].ullLen; | 1424 | for(ullLeft = tcs[t].ullLen; |
1417 | ullLeft >= sizeof(bZB); | 1425 | ullLeft >= sizeof(bZB); |
1418 | ullLeft -= sizeof(bZB)) { | 1426 | ullLeft -= sizeof(bZB)) { |
1419 | printf("B"); | 1427 | printf("B"); |
1420 | fflush(NULL); | 1428 | fflush(NULL); |
1421 | EVP_DigestSignUpdate(mctx, bZB, sizeof(bZB)); | 1429 | EVP_DigestSignUpdate(mctx, bZB, sizeof(bZB)); |
1422 | } | 1430 | } |
1423 | printf("b%" PRIu64 "/%" PRIu64, ullLeft, tcs[t].ullLen); | 1431 | printf("b%" PRIu64 "/%" PRIu64, ullLeft, tcs[t].ullLen); |
1424 | fflush(NULL); | 1432 | fflush(NULL); |
1425 | EVP_DigestSignUpdate(mctx, bZB, | 1433 | EVP_DigestSignUpdate(mctx, bZB, |
1426 | (unsigned int)ullLeft); | 1434 | (unsigned int)ullLeft); |
@@ -1441,7 +1449,8 @@ imit_fail: | |||
1441 | fprintf(stderr, "\nEngine test t=%d len=%" PRIu64 | 1449 | fprintf(stderr, "\nEngine test t=%d len=%" PRIu64 |
1442 | " mode=%d failed.\n", t, tcs[t].ullLen, tcs[t].gMode); | 1450 | " mode=%d failed.\n", t, tcs[t].ullLen, tcs[t].gMode); |
1443 | if(!ignore) { | 1451 | if(!ignore) { |
1444 | return 13; | 1452 | ret = 13; |
1453 | goto out; | ||
1445 | } | 1454 | } |
1446 | } else { | 1455 | } else { |
1447 | printf("."); | 1456 | printf("."); |
@@ -1452,12 +1461,14 @@ imit_fail: | |||
1452 | printf(" passed\n"); | 1461 | printf(" passed\n"); |
1453 | fflush(NULL); | 1462 | fflush(NULL); |
1454 | 1463 | ||
1464 | out: | ||
1465 | |||
1455 | bio_err = BIO_new_fp(stderr, BIO_NOCLOSE); | 1466 | bio_err = BIO_new_fp(stderr, BIO_NOCLOSE); |
1456 | ERR_print_errors(bio_err); | 1467 | ERR_print_errors(bio_err); |
1457 | (void)BIO_flush(bio_err); | 1468 | (void)BIO_flush(bio_err); |
1458 | BIO_free(bio_err); | 1469 | BIO_free(bio_err); |
1459 | EVP_CIPHER_CTX_free(ectx); | 1470 | EVP_CIPHER_CTX_free(ectx); |
1460 | EVP_MD_CTX_free(mctx); | 1471 | EVP_MD_CTX_free(mctx); |
1461 | return 0; | 1472 | return ret; |
1462 | } | 1473 | } |
1463 | #endif | 1474 | #endif |