diff options
-rw-r--r-- | src/regress/lib/libcrypto/gost/gost2814789t.c | 61 |
1 files changed, 36 insertions, 25 deletions
diff --git a/src/regress/lib/libcrypto/gost/gost2814789t.c b/src/regress/lib/libcrypto/gost/gost2814789t.c index 3e33f1e59b..e531229f63 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.7 2022/02/08 17:59:39 tb Exp $ */ | 1 | /* $OpenBSD: gost2814789t.c,v 1.8 2022/09/12 04:20:59 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 | /* ==================================================================== |
@@ -1341,9 +1341,9 @@ int main(int argc, char *argv[]) | |||
1341 | if(NULL != tcs[t].szDerive) { | 1341 | if(NULL != tcs[t].szDerive) { |
1342 | memset(bDerive, 0x3c, sizeof(bDerive)); | 1342 | memset(bDerive, 0x3c, sizeof(bDerive)); |
1343 | mdl = sizeof(bDerive); | 1343 | mdl = sizeof(bDerive); |
1344 | EVP_Digest(tcs[t].szDerive, strlen(tcs[t].szDerive), | 1344 | if (!EVP_Digest(tcs[t].szDerive, strlen(tcs[t].szDerive), bDerive, |
1345 | bDerive, &mdl, | 1345 | &mdl, md_gost94, NULL)) |
1346 | md_gost94, NULL); | 1346 | goto out; |
1347 | if(0 != memcmp(tcs[t].bRawKey, bDerive, mdl)) { | 1347 | if(0 != memcmp(tcs[t].bRawKey, bDerive, mdl)) { |
1348 | fflush(NULL); | 1348 | fflush(NULL); |
1349 | fprintf(stderr, "Engine test t=%d " | 1349 | fprintf(stderr, "Engine test t=%d " |
@@ -1373,13 +1373,17 @@ int main(int argc, char *argv[]) | |||
1373 | engine_cipher_check: | 1373 | engine_cipher_check: |
1374 | if ((ectx = EVP_CIPHER_CTX_new()) == NULL) | 1374 | if ((ectx = EVP_CIPHER_CTX_new()) == NULL) |
1375 | goto imit_fail; | 1375 | goto imit_fail; |
1376 | EVP_EncryptInit_ex(ectx, ctype, NULL, | 1376 | if (!EVP_EncryptInit_ex(ectx, ctype, NULL, tcs[t].bRawKey, |
1377 | tcs[t].bRawKey, tcs[t].bIV); | 1377 | tcs[t].bIV)) |
1378 | EVP_CIPHER_CTX_ctrl(ectx, EVP_CTRL_GOST_SET_SBOX, OBJ_txt2nid(tcs[t].szParamSet), 0); | 1378 | goto imit_fail; |
1379 | if (!EVP_CIPHER_CTX_ctrl(ectx, EVP_CTRL_GOST_SET_SBOX, | ||
1380 | OBJ_txt2nid(tcs[t].szParamSet), 0)) | ||
1381 | goto imit_fail; | ||
1379 | if(G89_MAX_TC_LEN >= tcs[t].ullLen) { | 1382 | if(G89_MAX_TC_LEN >= tcs[t].ullLen) { |
1380 | enlu = sizeof(bTest); | 1383 | enlu = sizeof(bTest); |
1381 | EVP_EncryptUpdate(ectx, bTest, &enlu, | 1384 | if (!EVP_EncryptUpdate(ectx, bTest, &enlu, tcs[t].bIn, |
1382 | tcs[t].bIn, (int)tcs[t].ullLen); | 1385 | (int)tcs[t].ullLen)) |
1386 | goto imit_fail; | ||
1383 | l = (size_t)tcs[t].ullLen; | 1387 | l = (size_t)tcs[t].ullLen; |
1384 | } else { | 1388 | } else { |
1385 | for(ullLeft = tcs[t].ullLen; | 1389 | for(ullLeft = tcs[t].ullLen; |
@@ -1388,13 +1392,14 @@ engine_cipher_check: | |||
1388 | printf("B"); | 1392 | printf("B"); |
1389 | fflush(NULL); | 1393 | fflush(NULL); |
1390 | enlu = sizeof(bTS); | 1394 | enlu = sizeof(bTS); |
1391 | EVP_EncryptUpdate(ectx, bTS, &enlu, | 1395 | if (!EVP_EncryptUpdate(ectx, bTS, &enlu, bZB, |
1392 | bZB, sizeof(bZB)); | 1396 | sizeof(bZB))) |
1397 | goto imit_fail; | ||
1393 | } | 1398 | } |
1394 | printf("b%" PRIu64 "/%" PRIu64, ullLeft, tcs[t].ullLen); | 1399 | printf("b%" PRIu64 "/%" PRIu64, ullLeft, tcs[t].ullLen); |
1395 | fflush(NULL); | 1400 | fflush(NULL); |
1396 | EVP_EncryptUpdate(ectx, bTS, &enlu, | 1401 | if (!EVP_EncryptUpdate(ectx, bTS, &enlu, bZB, (int)ullLeft)) |
1397 | bZB, (int)ullLeft); | 1402 | goto imit_fail; |
1398 | memcpy(bTest, &bTS[enlu-16], 16); | 1403 | memcpy(bTest, &bTS[enlu-16], 16); |
1399 | enlu = (int)tcs[t].ullLen; | 1404 | enlu = (int)tcs[t].ullLen; |
1400 | l = 16; | 1405 | l = 16; |
@@ -1402,8 +1407,10 @@ engine_cipher_check: | |||
1402 | enlf = sizeof(bTest1); | 1407 | enlf = sizeof(bTest1); |
1403 | if (tcs[t].gMode == G89_ECB) | 1408 | if (tcs[t].gMode == G89_ECB) |
1404 | enlf = 0; | 1409 | enlf = 0; |
1405 | else | 1410 | else { |
1406 | EVP_EncryptFinal_ex(ectx, bTest1, &enlf); | 1411 | if (!EVP_EncryptFinal_ex(ectx, bTest1, &enlf)) |
1412 | goto imit_fail; | ||
1413 | } | ||
1407 | EVP_CIPHER_CTX_free(ectx); | 1414 | EVP_CIPHER_CTX_free(ectx); |
1408 | ectx = NULL; | 1415 | ectx = NULL; |
1409 | break; | 1416 | break; |
@@ -1413,26 +1420,30 @@ engine_cipher_check: | |||
1413 | mac_key = EVP_PKEY_new_mac_key( | 1420 | mac_key = EVP_PKEY_new_mac_key( |
1414 | NID_id_Gost28147_89_MAC, NULL, | 1421 | NID_id_Gost28147_89_MAC, NULL, |
1415 | bDerive, mdl); | 1422 | bDerive, mdl); |
1416 | if (!mac_key) | 1423 | if (mac_key == NULL) |
1417 | goto imit_fail; | 1424 | goto imit_fail; |
1418 | EVP_DigestSignInit(mctx, NULL, | 1425 | if (!EVP_DigestSignInit(mctx, NULL, md_g89imit, NULL, mac_key)) |
1419 | md_g89imit, NULL, mac_key); | 1426 | goto imit_fail; |
1420 | EVP_MD_CTX_ctrl(mctx, EVP_MD_CTRL_GOST_SET_SBOX, OBJ_txt2nid(tcs[t].szParamSet), 0); | 1427 | if (!EVP_MD_CTX_ctrl(mctx, EVP_MD_CTRL_GOST_SET_SBOX, |
1428 | OBJ_txt2nid(tcs[t].szParamSet), 0)) | ||
1429 | goto imit_fail; | ||
1421 | if(G89_MAX_TC_LEN >= tcs[t].ullLen) { | 1430 | if(G89_MAX_TC_LEN >= tcs[t].ullLen) { |
1422 | EVP_DigestSignUpdate(mctx, tcs[t].bIn, | 1431 | if (!EVP_DigestSignUpdate(mctx, tcs[t].bIn, |
1423 | (unsigned int)tcs[t].ullLen); | 1432 | (unsigned int)tcs[t].ullLen)) |
1433 | goto imit_fail; | ||
1424 | } else { | 1434 | } else { |
1425 | for(ullLeft = tcs[t].ullLen; | 1435 | for(ullLeft = tcs[t].ullLen; |
1426 | ullLeft >= sizeof(bZB); | 1436 | ullLeft >= sizeof(bZB); |
1427 | ullLeft -= sizeof(bZB)) { | 1437 | ullLeft -= sizeof(bZB)) { |
1428 | printf("B"); | 1438 | printf("B"); |
1429 | fflush(NULL); | 1439 | fflush(NULL); |
1430 | EVP_DigestSignUpdate(mctx, bZB, sizeof(bZB)); | 1440 | if (!EVP_DigestSignUpdate(mctx, bZB, sizeof(bZB))) |
1441 | goto imit_fail; | ||
1431 | } | 1442 | } |
1432 | printf("b%" PRIu64 "/%" PRIu64, ullLeft, tcs[t].ullLen); | 1443 | printf("b%" PRIu64 "/%" PRIu64, ullLeft, tcs[t].ullLen); |
1433 | fflush(NULL); | 1444 | fflush(NULL); |
1434 | EVP_DigestSignUpdate(mctx, bZB, | 1445 | if (!EVP_DigestSignUpdate(mctx, bZB, (unsigned int)ullLeft)) |
1435 | (unsigned int)ullLeft); | 1446 | goto imit_fail; |
1436 | } | 1447 | } |
1437 | siglen = 4; | 1448 | siglen = 4; |
1438 | OPENSSL_assert(EVP_DigestSignFinal(mctx, bTest, &siglen)); | 1449 | OPENSSL_assert(EVP_DigestSignFinal(mctx, bTest, &siglen)); |