+ return ret;
+}
+
+static int test_contexts_digest(const char *name)
+{
+ EVP_MD *type;
+ ERR_set_mark();
+ T((type = (EVP_MD *)EVP_get_digestbyname(name))
+ || (type = EVP_MD_fetch(NULL, name, NULL)));
+ ERR_pop_to_mark();
+
+ printf(cBLUE "Digest test for %s" cNORM "\n", name);
+ int ret = test_contexts_digest_or_legacy_mac(type, 0);
+ EVP_MD_free(type);
+ return ret;
+}
+
+static int test_contexts_mac(const char *name)
+{
+ int ret = 0, test = 0;
+ unsigned char K[32] = {1};
+ const EVP_MD *type = EVP_get_digestbyname(name);
+ EVP_MAC *mac;
+
+ if (type) {
+ printf(cBLUE "Mac via EVP_MD test for %s" cNORM "\n", name);
+ return test_contexts_digest_or_legacy_mac(type, 1);
+ }
+
+ T(mac = EVP_MAC_fetch(NULL, name, NULL));
+ printf(cBLUE "Mac test for %s" cNORM "\n", name);
+
+ /* produce base mac */
+ EVP_MAC_CTX *ctx;
+ unsigned char pt[TEST_SIZE] = {1};
+ unsigned char b[EVP_MAX_MD_SIZE] = {0};
+ unsigned char c[EVP_MAX_MD_SIZE] = {0};
+ size_t outlen, tmplen;
+
+ /* Simply mac whole input. */
+ T(ctx = EVP_MAC_CTX_new(mac));
+ T(EVP_MAC_init(ctx, K, sizeof(K), NULL));
+ T(EVP_MAC_update(ctx, pt, sizeof(pt)));
+ T(EVP_MAC_final(ctx, b, &tmplen, sizeof(b)));
+ EVP_MAC_CTX_free(ctx);
+
+ /* Mac with rolling input. */
+ printf(" cloned contexts: ");
+ T(ctx = EVP_MAC_CTX_new(mac));
+ T(EVP_MAC_init(ctx, K, sizeof(K), NULL));
+ int i;
+ for (i = 0; i < TEST_SIZE / STEP_SIZE; i++) {
+ T(EVP_MAC_update(ctx, pt + STEP_SIZE * i, STEP_SIZE));
+ }
+ outlen = i * STEP_SIZE;
+ T(EVP_MAC_final(ctx, c, &tmplen, sizeof(c)));
+ EVP_MAC_CTX_free(ctx);
+ EVP_MAC_free(mac);
+
+ /* Rolling mac should give the same result as the simple mac. */
+ TEST_ASSERT(outlen != TEST_SIZE || memcmp(c, b, EVP_MAX_MD_SIZE));
+
+ if (test) {
+ printf(" b[%d] = ", (int)outlen);
+ hexdump(b, outlen);
+ printf(" c[%d] = ", (int)outlen);
+ hexdump(c, outlen);
+ }
+ ret |= test;
+
+ return ret;
+}
+
+static struct testcase_cipher {
+ const char *name;
+ int acpkm;
+} testcases_ciphers[] = {
+ { SN_id_Gost28147_89, },
+ { SN_gost89_cnt, },
+ { SN_gost89_cnt_12, },
+ { SN_gost89_cbc, },
+ { SN_grasshopper_ecb, },
+ { SN_grasshopper_cbc, },
+ { SN_grasshopper_cfb, },
+ { SN_grasshopper_ofb, },
+ { SN_grasshopper_ctr, },
+ { SN_magma_cbc, },
+ { SN_magma_ctr, },
+ { SN_id_tc26_cipher_gostr3412_2015_kuznyechik_ctracpkm, 256 / 8 },
+ { 0 },
+};
+
+static struct testcase_digest {
+ const char *name;
+ int mac;
+} testcases_digests[] = {
+ { SN_id_GostR3411_94, },
+ { SN_id_Gost28147_89_MAC, 1 },
+ { SN_id_GostR3411_2012_256, },
+ { SN_id_GostR3411_2012_512, },
+ { SN_gost_mac_12, 1 },
+ { SN_magma_mac, 1 },
+ { SN_grasshopper_mac, 1 },
+ { SN_id_tc26_cipher_gostr3412_2015_kuznyechik_ctracpkm_omac, 1 },
+ { 0 },
+};