summaryrefslogtreecommitdiff
path: root/src/regress/lib
diff options
context:
space:
mode:
authortb <>2021-11-18 15:18:25 +0000
committertb <>2021-11-18 15:18:25 +0000
commit03991a14f44f129f6f8514cada1cb470a5d0f78c (patch)
tree2ee996b82a9a3f011c11ddab7b12125a8930d1f7 /src/regress/lib
parent43d3b29a023a9e5b470aa52a909fe05031ec3646 (diff)
downloadopenbsd-03991a14f44f129f6f8514cada1cb470a5d0f78c.tar.gz
openbsd-03991a14f44f129f6f8514cada1cb470a5d0f78c.tar.bz2
openbsd-03991a14f44f129f6f8514cada1cb470a5d0f78c.zip
gost2814789t: convert to opaque EVP_{MD,CIPHER}_CTX.
Diffstat (limited to 'src/regress/lib')
-rw-r--r--src/regress/lib/libcrypto/gost/gost2814789t.c42
1 files changed, 23 insertions, 19 deletions
diff --git a/src/regress/lib/libcrypto/gost/gost2814789t.c b/src/regress/lib/libcrypto/gost/gost2814789t.c
index 30aaead34e..637e63eb88 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.2 2014/12/15 06:03:15 miod Exp $ */ 1/* $OpenBSD: gost2814789t.c,v 1.3 2021/11/18 15:18:25 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/* ====================================================================
@@ -1251,8 +1251,8 @@ int main(int argc, char *argv[])
1251 unsigned int t; 1251 unsigned int t;
1252 uint64_t ullMaxLen = 6*1000*1000; 1252 uint64_t ullMaxLen = 6*1000*1000;
1253 int ignore = 0; 1253 int ignore = 0;
1254 EVP_MD_CTX mctx; 1254 EVP_MD_CTX *mctx = NULL;
1255 EVP_CIPHER_CTX ectx; 1255 EVP_CIPHER_CTX *ectx = NULL;
1256 EVP_PKEY *mac_key; 1256 EVP_PKEY *mac_key;
1257 unsigned char bDerive[EVP_MAX_KEY_LENGTH]; 1257 unsigned char bDerive[EVP_MAX_KEY_LENGTH];
1258 unsigned char bTest[G89_MAX_TC_LEN]; 1258 unsigned char bTest[G89_MAX_TC_LEN];
@@ -1363,13 +1363,14 @@ int main(int argc, char *argv[])
1363 case G89_CNT: 1363 case G89_CNT:
1364 ctype = cp_g89cnt; 1364 ctype = cp_g89cnt;
1365engine_cipher_check: 1365engine_cipher_check:
1366 EVP_CIPHER_CTX_init(&ectx); 1366 if ((ectx = EVP_CIPHER_CTX_new()) == NULL)
1367 EVP_EncryptInit_ex(&ectx, ctype, NULL, 1367 goto imit_fail;
1368 EVP_EncryptInit_ex(ectx, ctype, NULL,
1368 tcs[t].bRawKey, tcs[t].bIV); 1369 tcs[t].bRawKey, tcs[t].bIV);
1369 EVP_CIPHER_CTX_ctrl(&ectx, EVP_CTRL_GOST_SET_SBOX, OBJ_txt2nid(tcs[t].szParamSet), 0); 1370 EVP_CIPHER_CTX_ctrl(ectx, EVP_CTRL_GOST_SET_SBOX, OBJ_txt2nid(tcs[t].szParamSet), 0);
1370 if(G89_MAX_TC_LEN >= tcs[t].ullLen) { 1371 if(G89_MAX_TC_LEN >= tcs[t].ullLen) {
1371 enlu = sizeof(bTest); 1372 enlu = sizeof(bTest);
1372 EVP_EncryptUpdate(&ectx, bTest, &enlu, 1373 EVP_EncryptUpdate(ectx, bTest, &enlu,
1373 tcs[t].bIn, (int)tcs[t].ullLen); 1374 tcs[t].bIn, (int)tcs[t].ullLen);
1374 l = (size_t)tcs[t].ullLen; 1375 l = (size_t)tcs[t].ullLen;
1375 } else { 1376 } else {
@@ -1379,12 +1380,12 @@ engine_cipher_check:
1379 printf("B"); 1380 printf("B");
1380 fflush(NULL); 1381 fflush(NULL);
1381 enlu = sizeof(bTS); 1382 enlu = sizeof(bTS);
1382 EVP_EncryptUpdate(&ectx, bTS, &enlu, 1383 EVP_EncryptUpdate(ectx, bTS, &enlu,
1383 bZB, sizeof(bZB)); 1384 bZB, sizeof(bZB));
1384 } 1385 }
1385 printf("b%" PRIu64 "/%" PRIu64, ullLeft, tcs[t].ullLen); 1386 printf("b%" PRIu64 "/%" PRIu64, ullLeft, tcs[t].ullLen);
1386 fflush(NULL); 1387 fflush(NULL);
1387 EVP_EncryptUpdate(&ectx, bTS, &enlu, 1388 EVP_EncryptUpdate(ectx, bTS, &enlu,
1388 bZB, (int)ullLeft); 1389 bZB, (int)ullLeft);
1389 memcpy(bTest, &bTS[enlu-16], 16); 1390 memcpy(bTest, &bTS[enlu-16], 16);
1390 enlu = (int)tcs[t].ullLen; 1391 enlu = (int)tcs[t].ullLen;
@@ -1394,21 +1395,22 @@ engine_cipher_check:
1394 if (tcs[t].gMode == G89_ECB) 1395 if (tcs[t].gMode == G89_ECB)
1395 enlf = 0; 1396 enlf = 0;
1396 else 1397 else
1397 EVP_EncryptFinal_ex(&ectx, bTest1, &enlf); 1398 EVP_EncryptFinal_ex(ectx, bTest1, &enlf);
1398 EVP_CIPHER_CTX_cleanup(&ectx); 1399 EVP_CIPHER_CTX_cleanup(ectx);
1399 break; 1400 break;
1400 case G89_IMIT: 1401 case G89_IMIT:
1401 EVP_MD_CTX_init(&mctx); 1402 if ((mctx = EVP_MD_CTX_new()) == NULL)
1403 goto imit_fail;
1402 mac_key = EVP_PKEY_new_mac_key( 1404 mac_key = EVP_PKEY_new_mac_key(
1403 NID_id_Gost28147_89_MAC, NULL, 1405 NID_id_Gost28147_89_MAC, NULL,
1404 bDerive, mdl); 1406 bDerive, mdl);
1405 if (!mac_key) 1407 if (!mac_key)
1406 goto imit_fail; 1408 goto imit_fail;
1407 EVP_DigestSignInit(&mctx, NULL, 1409 EVP_DigestSignInit(mctx, NULL,
1408 md_g89imit, NULL, mac_key); 1410 md_g89imit, NULL, mac_key);
1409 EVP_MD_CTX_ctrl(&mctx, EVP_MD_CTRL_GOST_SET_SBOX, OBJ_txt2nid(tcs[t].szParamSet), 0); 1411 EVP_MD_CTX_ctrl(mctx, EVP_MD_CTRL_GOST_SET_SBOX, OBJ_txt2nid(tcs[t].szParamSet), 0);
1410 if(G89_MAX_TC_LEN >= tcs[t].ullLen) { 1412 if(G89_MAX_TC_LEN >= tcs[t].ullLen) {
1411 EVP_DigestSignUpdate(&mctx, tcs[t].bIn, 1413 EVP_DigestSignUpdate(mctx, tcs[t].bIn,
1412 (unsigned int)tcs[t].ullLen); 1414 (unsigned int)tcs[t].ullLen);
1413 } else { 1415 } else {
1414 for(ullLeft = tcs[t].ullLen; 1416 for(ullLeft = tcs[t].ullLen;
@@ -1416,16 +1418,16 @@ engine_cipher_check:
1416 ullLeft -= sizeof(bZB)) { 1418 ullLeft -= sizeof(bZB)) {
1417 printf("B"); 1419 printf("B");
1418 fflush(NULL); 1420 fflush(NULL);
1419 EVP_DigestSignUpdate(&mctx, bZB, sizeof(bZB)); 1421 EVP_DigestSignUpdate(mctx, bZB, sizeof(bZB));
1420 } 1422 }
1421 printf("b%" PRIu64 "/%" PRIu64, ullLeft, tcs[t].ullLen); 1423 printf("b%" PRIu64 "/%" PRIu64, ullLeft, tcs[t].ullLen);
1422 fflush(NULL); 1424 fflush(NULL);
1423 EVP_DigestSignUpdate(&mctx, bZB, 1425 EVP_DigestSignUpdate(mctx, bZB,
1424 (unsigned int)ullLeft); 1426 (unsigned int)ullLeft);
1425 } 1427 }
1426 siglen = 4; 1428 siglen = 4;
1427 OPENSSL_assert(EVP_DigestSignFinal(&mctx, bTest, &siglen)); 1429 OPENSSL_assert(EVP_DigestSignFinal(mctx, bTest, &siglen));
1428 EVP_MD_CTX_cleanup(&mctx); 1430 EVP_MD_CTX_cleanup(mctx);
1429 EVP_PKEY_free(mac_key); 1431 EVP_PKEY_free(mac_key);
1430 enlu = (int)tcs[t].ullLen; 1432 enlu = (int)tcs[t].ullLen;
1431 enlf = 0; 1433 enlf = 0;
@@ -1454,6 +1456,8 @@ imit_fail:
1454 ERR_print_errors(bio_err); 1456 ERR_print_errors(bio_err);
1455 (void)BIO_flush(bio_err); 1457 (void)BIO_flush(bio_err);
1456 BIO_free(bio_err); 1458 BIO_free(bio_err);
1459 EVP_CIPHER_CTX_free(ectx);
1460 EVP_MD_CTX_free(mctx);
1457 return 0; 1461 return 0;
1458} 1462}
1459#endif 1463#endif