X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=test_digest.c;h=68c0e3253f7366cea9d8525dd7199821d92d7093;hb=HEAD;hp=a931a3509d577dacb0917d06185ac25c4230b5bc;hpb=55f0eb1b77c1c1bfc387927bad06210257f50f21;p=openssl-gost%2Fengine.git diff --git a/test_digest.c b/test_digest.c index a931a35..38cc2eb 100644 --- a/test_digest.c +++ b/test_digest.c @@ -7,6 +7,11 @@ * See https://www.openssl.org/source/license.html for details */ +#ifdef _MSC_VER +# pragma warning(push, 3) +# include +# pragma warning(pop) +#endif #include #include #include @@ -29,17 +34,17 @@ #endif /* Helpers to test OpenSSL API calls. */ -#define T(e) ({ if (!(e)) { \ - ERR_print_errors_fp(stderr); \ - OpenSSLDie(__FILE__, __LINE__, #e); \ - } \ - }) -#define TE(e) ({ if (!(e)) { \ - ERR_print_errors_fp(stderr); \ - fprintf(stderr, "Error at %s:%d %s\n", __FILE__, __LINE__, #e); \ - return -1; \ - } \ - }) +#define T(e) \ + if (!(e)) { \ + ERR_print_errors_fp(stderr); \ + OpenSSLDie(__FILE__, __LINE__, #e); \ + } +#define TE(e) \ + if (!(e)) { \ + ERR_print_errors_fp(stderr); \ + fprintf(stderr, "Error at %s:%d %s\n", __FILE__, __LINE__, #e); \ + return -1; \ + } #define cRED "\033[1;31m" #define cDRED "\033[0;31m" @@ -103,6 +108,30 @@ static const char MAC_omac[] = { 0x33,0x6f,0x4d,0x29,0x60,0x59,0xfb,0xe3 }; */ static const char MAC_magma_omac[] = { 0x15,0x4e,0x72,0x10 }; +/* + * OMAC-ACPKM test vector from R 1323565.1.017-2018 A.3.1 + */ +static const char P_omac_acpkm01[] = { + 0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x00,0xFF,0xEE,0xDD,0xCC, +}; + +static const char MAC_omac_acpkm01[] = { + 0xA0,0x54,0x0E,0x37,0x30,0xAC,0xBC,0xF3, +}; + +/* + * OMAC-ACPKM test vector from R 1323565.1.017-2018 A.3.2 + */ +static const char P_omac_acpkm02[] = { + 0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x00,0xFF,0xEE,0xDD,0xCC,0xBB,0xAA,0x99,0x88, + 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA,0xBB,0xCC,0xEE,0xFF,0x0A, + 0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88, +}; + +static const char MAC_omac_acpkm02[] = { + 0x34,0x00,0x8D,0xAD,0x54,0x96,0xBB,0x8E, +}; + /* * OMAC-ACPKM test vector from R 1323565.1.017-2018 A.4.1 */ @@ -182,7 +211,7 @@ struct hash_testvec { const char *hmac; /* Expected output for HMAC tests. */ const char *key; /* MAC key.*/ int psize; /* Input (plaintext) size. */ - int outsize; /* Compare to EVP_MD_size() / EVP_MAC_size() if non-zero. */ + size_t outsize; /* Compare to EVP_MD_size() / EVP_MAC_size() if non-zero. */ int truncate; /* Truncated output (digest) size. */ int key_size; /* MAC key size. */ int block_size; /* Internal block size. */ @@ -272,6 +301,30 @@ static const struct hash_testvec testvecs[] = { .outsize = 64 / 8, .truncate = sizeof(MAC_magma_omac), }, + { + .algname = SN_id_tc26_cipher_gostr3412_2015_magma_ctracpkm_omac, + .name = "M from R 1323565.1.017-2018 (A.3.1)", + .plaintext = P_omac_acpkm01, + .psize = sizeof(P_omac_acpkm01), + .key = K, + .key_size = sizeof(K), + .acpkm = 128 / 8, + .acpkm_t = 640 / 8, + .digest = MAC_omac_acpkm01, + .outsize = sizeof(MAC_omac_acpkm01), + }, + { + .algname = SN_id_tc26_cipher_gostr3412_2015_magma_ctracpkm_omac, + .name = "M from R 1323565.1.017-2018 (A.3.2)", + .plaintext = P_omac_acpkm02, + .psize = sizeof(P_omac_acpkm02), + .key = K, + .key_size = sizeof(K), + .acpkm = 128 / 8, + .acpkm_t = 640 / 8, + .digest = MAC_omac_acpkm02, + .outsize = sizeof(MAC_omac_acpkm02), + }, { .algname = SN_id_tc26_cipher_gostr3412_2015_kuznyechik_ctracpkm_omac, .name = "M from R 1323565.1.017-2018 (A.4.1)", @@ -635,7 +688,7 @@ static int do_mac(int iter, EVP_MAC *mac, const char *plaintext, const struct hash_testvec *t) { if (!iter) - printf("[MAC %d] ", t->outsize); + printf("[MAC %zu] ", t->outsize); size_t acpkm = (size_t)t->acpkm; size_t acpkm_t = (size_t)t->acpkm_t; @@ -658,6 +711,7 @@ static int do_mac(int iter, EVP_MAC *mac, const char *plaintext, } else outsize = EVP_MAC_CTX_get_mac_size(ctx); + T(p - params < 4); T(EVP_MAC_init(ctx, (const unsigned char *)t->key, t->key_size, NULL)); T(EVP_MAC_CTX_set_params(ctx, params)); @@ -691,7 +745,7 @@ static int do_digest(int iter, const EVP_MD *type, const char *plaintext, const struct hash_testvec *t) { if (!iter) - printf("[MD %d] ", t->outsize); + printf("[MD %zu] ", t->outsize); if (t->outsize) T(EVP_MD_size(type) == t->outsize); size_t outsize;