Blame SOURCES/openssl-1.1.1-s390x-aes-tests.patch

0c50f5
diff -up openssl-1.1.1k/test/evp_extra_test.c.s390x-test-aes openssl-1.1.1k/test/evp_extra_test.c
0c50f5
--- openssl-1.1.1k/test/evp_extra_test.c.s390x-test-aes	2021-07-16 17:33:04.663181698 +0200
0c50f5
+++ openssl-1.1.1k/test/evp_extra_test.c	2021-07-16 17:49:27.780439742 +0200
0c50f5
@@ -320,6 +320,97 @@ static const unsigned char pExampleECPar
0c50f5
 };
0c50f5
 #endif
0c50f5
 
0c50f5
+static const unsigned char kCFBDefaultKey[] = {
0c50f5
+	0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88,
0c50f5
+    0x09, 0xCF, 0x4F, 0x3C
0c50f5
+};
0c50f5
+
0c50f5
+static const unsigned char kGCMDefaultKey[32] = { 0 };
0c50f5
+
0c50f5
+static const unsigned char kGCMResetKey[] = {
0c50f5
+	0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, 0x6d, 0x6a, 0x8f, 0x94,
0c50f5
+    0x67, 0x30, 0x83, 0x08, 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
0c50f5
+	0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08
0c50f5
+};
0c50f5
+
0c50f5
+static const unsigned char iCFBIV[] = {
0c50f5
+	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
0c50f5
+    0x0C, 0x0D, 0x0E, 0x0F
0c50f5
+};
0c50f5
+
0c50f5
+static const unsigned char iGCMDefaultIV[12] = { 0 };
0c50f5
+
0c50f5
+static const unsigned char iGCMResetIV1[] = {
0c50f5
+	0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad
0c50f5
+};
0c50f5
+
0c50f5
+static const unsigned char iGCMResetIV2[] = {
0c50f5
+	0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad, 0xde, 0xca, 0xf8, 0x88
0c50f5
+};
0c50f5
+
0c50f5
+static const unsigned char cfbPlaintext[] = {
0c50f5
+	0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96, 0xE9, 0x3D, 0x7E, 0x11,
0c50f5
+    0x73, 0x93, 0x17, 0x2A
0c50f5
+};
0c50f5
+
0c50f5
+static const unsigned char gcmDefaultPlaintext[16] = { 0 };
0c50f5
+
0c50f5
+static const unsigned char gcmResetPlaintext[] = {
0c50f5
+	0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, 0xa5, 0x59, 0x09, 0xc5,
0c50f5
+	0xaf, 0xf5, 0x26, 0x9a, 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
0c50f5
+	0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, 0x1c, 0x3c, 0x0c, 0x95,
0c50f5
+	0x95, 0x68, 0x09, 0x53, 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
0c50f5
+    0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, 0xba, 0x63, 0x7b, 0x39
0c50f5
+};
0c50f5
+
0c50f5
+static const unsigned char cfbCiphertext[] = {
0c50f5
+	0x3B, 0x3F, 0xD9, 0x2E, 0xB7, 0x2D, 0xAD, 0x20, 0x33, 0x34, 0x49, 0xF8,
0c50f5
+    0xE8, 0x3C, 0xFB, 0x4A
0c50f5
+};
0c50f5
+
0c50f5
+static const unsigned char gcmDefaultCiphertext[] = {
0c50f5
+	0xce, 0xa7, 0x40, 0x3d, 0x4d, 0x60, 0x6b, 0x6e, 0x07, 0x4e, 0xc5, 0xd3,
0c50f5
+    0xba, 0xf3, 0x9d, 0x18
0c50f5
+};
0c50f5
+
0c50f5
+static const unsigned char gcmResetCiphertext1[] = {
0c50f5
+	0xc3, 0x76, 0x2d, 0xf1, 0xca, 0x78, 0x7d, 0x32, 0xae, 0x47, 0xc1, 0x3b,
0c50f5
+    0xf1, 0x98, 0x44, 0xcb, 0xaf, 0x1a, 0xe1, 0x4d, 0x0b, 0x97, 0x6a, 0xfa,
0c50f5
+    0xc5, 0x2f, 0xf7, 0xd7, 0x9b, 0xba, 0x9d, 0xe0, 0xfe, 0xb5, 0x82, 0xd3,
0c50f5
+	0x39, 0x34, 0xa4, 0xf0, 0x95, 0x4c, 0xc2, 0x36, 0x3b, 0xc7, 0x3f, 0x78,
0c50f5
+	0x62, 0xac, 0x43, 0x0e, 0x64, 0xab, 0xe4, 0x99, 0xf4, 0x7c, 0x9b, 0x1f
0c50f5
+};
0c50f5
+
0c50f5
+static const unsigned char gcmResetCiphertext2[] = {
0c50f5
+	0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07, 0xf4, 0x7f, 0x37, 0xa3,
0c50f5
+    0x2a, 0x84, 0x42, 0x7d, 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9,
0c50f5
+	0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa, 0x8c, 0xb0, 0x8e, 0x48,
0c50f5
+	0x59, 0x0d, 0xbb, 0x3d, 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38,
0c50f5
+	0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a, 0xbc, 0xc9, 0xf6, 0x62
0c50f5
+};
0c50f5
+
0c50f5
+static const unsigned char gcmAAD[] = {
0c50f5
+	0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfe, 0xed, 0xfa, 0xce,
0c50f5
+    0xde, 0xad, 0xbe, 0xef, 0xab, 0xad, 0xda, 0xd2
0c50f5
+};
0c50f5
+
0c50f5
+static const unsigned char gcmDefaultTag[] = {
0c50f5
+	0xd0, 0xd1, 0xc8, 0xa7, 0x99, 0x99, 0x6b, 0xf0, 0x26, 0x5b, 0x98, 0xb5,
0c50f5
+    0xd4, 0x8a, 0xb9, 0x19
0c50f5
+};
0c50f5
+
0c50f5
+static const unsigned char gcmResetTag1[] = {
0c50f5
+	0x3a, 0x33, 0x7d, 0xbf, 0x46, 0xa7, 0x92, 0xc4, 0x5e, 0x45, 0x49, 0x13,
0c50f5
+	0xfe, 0x2e, 0xa8, 0xf2
0c50f5
+};
0c50f5
+
0c50f5
+static const unsigned char gcmResetTag2[] = {
0c50f5
+	0x76, 0xfc, 0x6e, 0xce, 0x0f, 0x4e, 0x17, 0x68, 0xcd, 0xdf, 0x88, 0x53,
0c50f5
+    0xbb, 0x2d, 0x55, 0x1b
0c50f5
+};
0c50f5
+
0c50f5
+
0c50f5
+
0c50f5
 typedef struct APK_DATA_st {
0c50f5
     const unsigned char *kder;
0c50f5
     size_t size;
0c50f5
@@ -330,6 +421,385 @@ typedef struct APK_DATA_st {
0c50f5
     int type; /* 0 for private, 1 for public, 2 for params */
0c50f5
 } APK_DATA;
0c50f5
 
0c50f5
+typedef struct {
0c50f5
+    const char *cipher;
0c50f5
+    const unsigned char *key;
0c50f5
+    const unsigned char *iv;
0c50f5
+    const unsigned char *input;
0c50f5
+    const unsigned char *expected;
0c50f5
+    const unsigned char *tag;
0c50f5
+    size_t ivlen; /* 0 if we do not need to set a specific IV len */
0c50f5
+    size_t inlen;
0c50f5
+    size_t expectedlen;
0c50f5
+    size_t taglen;
0c50f5
+    int keyfirst;
0c50f5
+    int initenc;
0c50f5
+    int finalenc;
0c50f5
+} EVP_INIT_TEST_st;
0c50f5
+
0c50f5
+static const EVP_INIT_TEST_st evp_init_tests[] = {
0c50f5
+    {
0c50f5
+        "aes-128-cfb", kCFBDefaultKey, iCFBIV, cfbPlaintext,
0c50f5
+        cfbCiphertext, NULL, 0, sizeof(cfbPlaintext), sizeof(cfbCiphertext),
0c50f5
+        0, 1, 0, 1
0c50f5
+    },
0c50f5
+    {
0c50f5
+        "aes-256-gcm", kGCMDefaultKey, iGCMDefaultIV, gcmDefaultPlaintext,
0c50f5
+        gcmDefaultCiphertext, gcmDefaultTag, sizeof(iGCMDefaultIV),
0c50f5
+        sizeof(gcmDefaultPlaintext), sizeof(gcmDefaultCiphertext),
0c50f5
+        sizeof(gcmDefaultTag), 1, 0, 1
0c50f5
+    },
0c50f5
+    {
0c50f5
+        "aes-128-cfb", kCFBDefaultKey, iCFBIV, cfbPlaintext,
0c50f5
+        cfbCiphertext, NULL, 0, sizeof(cfbPlaintext), sizeof(cfbCiphertext),
0c50f5
+        0, 0, 0, 1
0c50f5
+    },
0c50f5
+    {
0c50f5
+        "aes-256-gcm", kGCMDefaultKey, iGCMDefaultIV, gcmDefaultPlaintext,
0c50f5
+        gcmDefaultCiphertext, gcmDefaultTag, sizeof(iGCMDefaultIV),
0c50f5
+        sizeof(gcmDefaultPlaintext), sizeof(gcmDefaultCiphertext),
0c50f5
+        sizeof(gcmDefaultTag), 0, 0, 1
0c50f5
+    },
0c50f5
+    {
0c50f5
+        "aes-128-cfb", kCFBDefaultKey, iCFBIV, cfbCiphertext,
0c50f5
+        cfbPlaintext, NULL, 0, sizeof(cfbCiphertext), sizeof(cfbPlaintext),
0c50f5
+        0, 1, 1, 0
0c50f5
+    },
0c50f5
+    {
0c50f5
+        "aes-256-gcm", kGCMDefaultKey, iGCMDefaultIV, gcmDefaultCiphertext,
0c50f5
+        gcmDefaultPlaintext, gcmDefaultTag, sizeof(iGCMDefaultIV),
0c50f5
+        sizeof(gcmDefaultCiphertext), sizeof(gcmDefaultPlaintext),
0c50f5
+        sizeof(gcmDefaultTag), 1, 1, 0
0c50f5
+    },
0c50f5
+    {
0c50f5
+        "aes-128-cfb", kCFBDefaultKey, iCFBIV, cfbCiphertext,
0c50f5
+        cfbPlaintext, NULL, 0, sizeof(cfbCiphertext), sizeof(cfbPlaintext),
0c50f5
+        0, 0, 1, 0
0c50f5
+    },
0c50f5
+    {
0c50f5
+        "aes-256-gcm", kGCMDefaultKey, iGCMDefaultIV, gcmDefaultCiphertext,
0c50f5
+        gcmDefaultPlaintext, gcmDefaultTag, sizeof(iGCMDefaultIV),
0c50f5
+        sizeof(gcmDefaultCiphertext), sizeof(gcmDefaultPlaintext),
0c50f5
+        sizeof(gcmDefaultTag), 0, 1, 0
0c50f5
+    }
0c50f5
+};
0c50f5
+
0c50f5
+static int evp_init_seq_set_iv(EVP_CIPHER_CTX *ctx, const EVP_INIT_TEST_st *t)
0c50f5
+{
0c50f5
+    int res = 0;
0c50f5
+
0c50f5
+    if (t->ivlen != 0) {
0c50f5
+        if (!TEST_true(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, t->ivlen, NULL)))
0c50f5
+            goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_true(EVP_CipherInit_ex(ctx, NULL, NULL, NULL, t->iv, -1)))
0c50f5
+        goto err;
0c50f5
+    res = 1;
0c50f5
+ err:
0c50f5
+    return res;
0c50f5
+}
0c50f5
+
0c50f5
+/*
0c50f5
+ * Test step-wise cipher initialization via EVP_CipherInit_ex where the
0c50f5
+ * arguments are given one at a time and a final adjustment to the enc
0c50f5
+ * parameter sets the correct operation.
0c50f5
+ */
0c50f5
+static int test_evp_init_seq(int idx)
0c50f5
+{
0c50f5
+    int outlen1, outlen2;
0c50f5
+    int testresult = 0;
0c50f5
+    unsigned char outbuf[1024];
0c50f5
+    unsigned char tag[16];
0c50f5
+    const EVP_INIT_TEST_st *t = &evp_init_tests[idx];
0c50f5
+    EVP_CIPHER_CTX *ctx = NULL;
0c50f5
+    const EVP_CIPHER *type = NULL;
0c50f5
+    size_t taglen = sizeof(tag);
0c50f5
+    char *errmsg = NULL;
0c50f5
+
0c50f5
+    ctx = EVP_CIPHER_CTX_new();
0c50f5
+    if (ctx == NULL) {
0c50f5
+        errmsg = "CTX_ALLOC";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_ptr(type = EVP_get_cipherbyname(t->cipher))) {
0c50f5
+        errmsg = "GET_CIPHERBYNAME";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_true(EVP_CipherInit_ex(ctx, type, NULL, NULL, NULL, t->initenc))) {
0c50f5
+        errmsg = "EMPTY_ENC_INIT";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_true(EVP_CIPHER_CTX_set_padding(ctx, 0))) {
0c50f5
+        errmsg = "PADDING";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (t->keyfirst && !TEST_true(EVP_CipherInit_ex(ctx, NULL, NULL, t->key, NULL, -1))) {
0c50f5
+        errmsg = "KEY_INIT (before iv)";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!evp_init_seq_set_iv(ctx, t)) {
0c50f5
+        errmsg = "IV_INIT";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (t->keyfirst == 0 &&  !TEST_true(EVP_CipherInit_ex(ctx, NULL, NULL, t->key, NULL, -1))) {
0c50f5
+        errmsg = "KEY_INIT (after iv)";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_true(EVP_CipherInit_ex(ctx, NULL, NULL, NULL, NULL, t->finalenc))) {
0c50f5
+        errmsg = "FINAL_ENC_INIT";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_true(EVP_CipherUpdate(ctx, outbuf, &outlen1, t->input, t->inlen))) {
0c50f5
+        errmsg = "CIPHER_UPDATE";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (t->finalenc == 0 && t->tag != NULL) {
0c50f5
+        /* Set expected tag */
0c50f5
+        if (!TEST_true(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
0c50f5
+                                           t->taglen, (void *)t->tag))) {
0c50f5
+            errmsg = "SET_TAG";
0c50f5
+            goto err;
0c50f5
+        }
0c50f5
+    }
0c50f5
+    if (!TEST_true(EVP_CipherFinal_ex(ctx, outbuf + outlen1, &outlen2))) {
0c50f5
+        errmsg = "CIPHER_FINAL";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_mem_eq(t->expected, t->expectedlen, outbuf, outlen1 + outlen2)) {
0c50f5
+        errmsg = "WRONG_RESULT";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (t->finalenc != 0 && t->tag != NULL) {
0c50f5
+        if (!TEST_true(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, taglen, tag))) {
0c50f5
+            errmsg = "GET_TAG";
0c50f5
+            goto err;
0c50f5
+        }
0c50f5
+        if (!TEST_mem_eq(t->tag, t->taglen, tag, taglen)) {
0c50f5
+            errmsg = "TAG_ERROR";
0c50f5
+            goto err;
0c50f5
+        }
0c50f5
+    }
0c50f5
+    testresult = 1;
0c50f5
+ err:
0c50f5
+    if (errmsg != NULL)
0c50f5
+        TEST_info("evp_init_test %d: %s", idx, errmsg);
0c50f5
+    EVP_CIPHER_CTX_free(ctx);
0c50f5
+    return testresult;
0c50f5
+}
0c50f5
+
0c50f5
+typedef struct {
0c50f5
+    const unsigned char *input;
0c50f5
+    const unsigned char *expected;
0c50f5
+    size_t inlen;
0c50f5
+    size_t expectedlen;
0c50f5
+    int enc;
0c50f5
+} EVP_RESET_TEST_st;
0c50f5
+
0c50f5
+static const EVP_RESET_TEST_st evp_reset_tests[] = {
0c50f5
+    {
0c50f5
+        cfbPlaintext, cfbCiphertext,
0c50f5
+        sizeof(cfbPlaintext), sizeof(cfbCiphertext), 1
0c50f5
+    },
0c50f5
+    {
0c50f5
+        cfbCiphertext, cfbPlaintext,
0c50f5
+        sizeof(cfbCiphertext), sizeof(cfbPlaintext), 0
0c50f5
+    }
0c50f5
+};
0c50f5
+
0c50f5
+/*
0c50f5
+ * Test a reset of a cipher via EVP_CipherInit_ex after the cipher has already
0c50f5
+ * been used.
0c50f5
+ */
0c50f5
+static int test_evp_reset(int idx)
0c50f5
+{
0c50f5
+    const EVP_RESET_TEST_st *t = &evp_reset_tests[idx];
0c50f5
+    int outlen1, outlen2;
0c50f5
+    int testresult = 0;
0c50f5
+    unsigned char outbuf[1024];
0c50f5
+    EVP_CIPHER_CTX *ctx = NULL;
0c50f5
+    const EVP_CIPHER *type = NULL;
0c50f5
+    char *errmsg = NULL;
0c50f5
+
0c50f5
+    if (!TEST_ptr(ctx = EVP_CIPHER_CTX_new())) {
0c50f5
+        errmsg = "CTX_ALLOC";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_ptr(type = EVP_get_cipherbyname("aes-128-cfb"))) {
0c50f5
+        errmsg = "GET_CIPHERBYNAME";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_true(EVP_CipherInit_ex(ctx, type, NULL, kCFBDefaultKey, iCFBIV, t->enc))) {
0c50f5
+        errmsg = "CIPHER_INIT";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_true(EVP_CIPHER_CTX_set_padding(ctx, 0))) {
0c50f5
+        errmsg = "PADDING";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_true(EVP_CipherUpdate(ctx, outbuf, &outlen1, t->input, t->inlen))) {
0c50f5
+        errmsg = "CIPHER_UPDATE";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_true(EVP_CipherFinal_ex(ctx, outbuf + outlen1, &outlen2))) {
0c50f5
+        errmsg = "CIPHER_FINAL";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_mem_eq(t->expected, t->expectedlen, outbuf, outlen1 + outlen2)) {
0c50f5
+        errmsg = "WRONG_RESULT";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_true(EVP_CipherInit_ex(ctx, NULL, NULL, NULL, NULL, -1))) {
0c50f5
+        errmsg = "CIPHER_REINIT";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_true(EVP_CipherUpdate(ctx, outbuf, &outlen1, t->input, t->inlen))) {
0c50f5
+        errmsg = "CIPHER_UPDATE (reinit)";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_true(EVP_CipherFinal_ex(ctx, outbuf + outlen1, &outlen2))) {
0c50f5
+        errmsg = "CIPHER_FINAL (reinit)";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_mem_eq(t->expected, t->expectedlen, outbuf, outlen1 + outlen2)) {
0c50f5
+        errmsg = "WRONG_RESULT (reinit)";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    testresult = 1;
0c50f5
+ err:
0c50f5
+    if (errmsg != NULL)
0c50f5
+        TEST_info("test_evp_reset %d: %s", idx, errmsg);
0c50f5
+    EVP_CIPHER_CTX_free(ctx);
0c50f5
+    return testresult;
0c50f5
+}
0c50f5
+
0c50f5
+typedef struct {
0c50f5
+    const unsigned char *iv1;
0c50f5
+    const unsigned char *iv2;
0c50f5
+    const unsigned char *expected1;
0c50f5
+    const unsigned char *expected2;
0c50f5
+    const unsigned char *tag1;
0c50f5
+    const unsigned char *tag2;
0c50f5
+    size_t ivlen1;
0c50f5
+    size_t ivlen2;
0c50f5
+    size_t expectedlen1;
0c50f5
+    size_t expectedlen2;
0c50f5
+} TEST_GCM_IV_REINIT_st;
0c50f5
+
0c50f5
+static const TEST_GCM_IV_REINIT_st gcm_reinit_tests[] = {
0c50f5
+    {
0c50f5
+        iGCMResetIV1, iGCMResetIV2, gcmResetCiphertext1, gcmResetCiphertext2,
0c50f5
+        gcmResetTag1, gcmResetTag2, sizeof(iGCMResetIV1), sizeof(iGCMResetIV2),
0c50f5
+        sizeof(gcmResetCiphertext1), sizeof(gcmResetCiphertext2)
0c50f5
+    },
0c50f5
+    {
0c50f5
+        iGCMResetIV2, iGCMResetIV1, gcmResetCiphertext2, gcmResetCiphertext1,
0c50f5
+        gcmResetTag2, gcmResetTag1, sizeof(iGCMResetIV2), sizeof(iGCMResetIV1),
0c50f5
+        sizeof(gcmResetCiphertext2), sizeof(gcmResetCiphertext1)
0c50f5
+    }
0c50f5
+};
0c50f5
+
0c50f5
+static int test_gcm_reinit(int idx)
0c50f5
+{
0c50f5
+    int outlen1, outlen2, outlen3;
0c50f5
+    int testresult = 0;
0c50f5
+    unsigned char outbuf[1024];
0c50f5
+    unsigned char tag[16];
0c50f5
+    const TEST_GCM_IV_REINIT_st *t = &gcm_reinit_tests[idx];
0c50f5
+    EVP_CIPHER_CTX *ctx = NULL;
0c50f5
+    const EVP_CIPHER *type = NULL;
0c50f5
+    size_t taglen = sizeof(tag);
0c50f5
+    char *errmsg = NULL;
0c50f5
+
0c50f5
+    if (!TEST_ptr(ctx = EVP_CIPHER_CTX_new())) {
0c50f5
+        errmsg = "CTX_ALLOC";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_ptr(type = EVP_get_cipherbyname("aes-256-gcm"))) {
0c50f5
+        errmsg = "GET_CIPHERBYNAME";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_true(EVP_CipherInit_ex(ctx, type, NULL, NULL, NULL, 1))) {
0c50f5
+        errmsg = "ENC_INIT";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_true(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, t->ivlen1, NULL))) {
0c50f5
+        errmsg = "SET_IVLEN1";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_true(EVP_CipherInit_ex(ctx, NULL, NULL, kGCMResetKey, t->iv1, 1))) {
0c50f5
+        errmsg = "SET_IV1";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_true(EVP_CipherUpdate(ctx, NULL, &outlen3, gcmAAD, sizeof(gcmAAD)))) {
0c50f5
+        errmsg = "AAD1";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    EVP_CIPHER_CTX_set_padding(ctx, 0);
0c50f5
+    if (!TEST_true(EVP_CipherUpdate(ctx, outbuf, &outlen1, gcmResetPlaintext,
0c50f5
+                                    sizeof(gcmResetPlaintext)))) {
0c50f5
+        errmsg = "CIPHER_UPDATE1";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_true(EVP_CipherFinal_ex(ctx, outbuf + outlen1, &outlen2))) {
0c50f5
+        errmsg = "CIPHER_FINAL1";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_mem_eq(t->expected1, t->expectedlen1, outbuf, outlen1 + outlen2)) {
0c50f5
+        errmsg = "WRONG_RESULT1";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_true(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, taglen, tag))) {
0c50f5
+        errmsg = "GET_TAG1";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_mem_eq(t->tag1, taglen, tag, taglen)) {
0c50f5
+        errmsg = "TAG_ERROR1";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    /* Now reinit */
0c50f5
+    if (!TEST_true(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, t->ivlen2, NULL))) {
0c50f5
+        errmsg = "SET_IVLEN2";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_true(EVP_CipherInit_ex(ctx, NULL, NULL, NULL, t->iv2, -1))) {
0c50f5
+        errmsg = "SET_IV2";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_true(EVP_CipherUpdate(ctx, NULL, &outlen3, gcmAAD, sizeof(gcmAAD)))) {
0c50f5
+        errmsg = "AAD2";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_true(EVP_CipherUpdate(ctx, outbuf, &outlen1, gcmResetPlaintext,
0c50f5
+                                    sizeof(gcmResetPlaintext)))) {
0c50f5
+        errmsg = "CIPHER_UPDATE2";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_true(EVP_CipherFinal_ex(ctx, outbuf + outlen1, &outlen2))) {
0c50f5
+        errmsg = "CIPHER_FINAL2";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_mem_eq(t->expected2, t->expectedlen2, outbuf, outlen1 + outlen2)) {
0c50f5
+        errmsg = "WRONG_RESULT2";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_true(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, taglen, tag))) {
0c50f5
+        errmsg = "GET_TAG2";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    if (!TEST_mem_eq(t->tag2, taglen, tag, taglen)) {
0c50f5
+        errmsg = "TAG_ERROR2";
0c50f5
+        goto err;
0c50f5
+    }
0c50f5
+    testresult = 1;
0c50f5
+ err:
0c50f5
+    if (errmsg != NULL)
0c50f5
+        TEST_info("evp_init_test %d: %s", idx, errmsg);
0c50f5
+    EVP_CIPHER_CTX_free(ctx);
0c50f5
+    return testresult;
0c50f5
+}
0c50f5
+
0c50f5
+
0c50f5
+
0c50f5
 static APK_DATA keydata[] = {
0c50f5
     {kExampleRSAKeyDER, sizeof(kExampleRSAKeyDER), EVP_PKEY_RSA},
0c50f5
     {kExampleRSAKeyPKCS8, sizeof(kExampleRSAKeyPKCS8), EVP_PKEY_RSA},
0c50f5
@@ -1208,6 +1678,8 @@ int setup_tests(void)
0c50f5
 #ifndef OPENSSL_NO_DH
0c50f5
     ADD_TEST(test_EVP_PKEY_set1_DH);
0c50f5
 #endif
0c50f5
-
0c50f5
+    ADD_ALL_TESTS(test_evp_init_seq, OSSL_NELEM(evp_init_tests));
0c50f5
+    ADD_ALL_TESTS(test_evp_reset, OSSL_NELEM(evp_reset_tests));
0c50f5
+    ADD_ALL_TESTS(test_gcm_reinit, OSSL_NELEM(gcm_reinit_tests));
0c50f5
     return 1;
0c50f5
 }