-static int run_test_vectors(void)
- {
- unsigned int n;
- int errs = 0;
-
- for(n=0 ; n < sizeof(ige_test_vectors)/sizeof(ige_test_vectors[0]) ; ++n)
- {
- const struct ige_test * const v = &ige_test_vectors[n];
- AES_KEY key;
- unsigned char buf[MAX_VECTOR_SIZE];
- unsigned char iv[AES_BLOCK_SIZE*2];
-
- assert(v->length <= MAX_VECTOR_SIZE);
-
- if(v->encrypt == AES_ENCRYPT)
- AES_set_encrypt_key(v->key, 8*sizeof v->key, &key);
- else
- AES_set_decrypt_key(v->key, 8*sizeof v->key, &key);
- memcpy(iv, v->iv, sizeof iv);
- AES_ige_encrypt(v->in, buf, v->length, &key, iv, v->encrypt);
-
- if(memcmp(v->out, buf, v->length))
- {
- printf("IGE test vector %d failed\n", n);
- hexdump(stdout, "key", v->key, sizeof v->key);
- hexdump(stdout, "iv", v->iv, sizeof v->iv);
- hexdump(stdout, "in", v->in, v->length);
- hexdump(stdout, "expected", v->out, v->length);
- hexdump(stdout, "got", buf, v->length);
-
- ++errs;
- }
-
- /* try with in == out */
- memcpy(iv, v->iv, sizeof iv);
- memcpy(buf, v->in, v->length);
- AES_ige_encrypt(buf, buf, v->length, &key, iv, v->encrypt);
-
- if(memcmp(v->out, buf, v->length))
- {
- printf("IGE test vector %d failed (with in == out)\n", n);
- hexdump(stdout, "key", v->key, sizeof v->key);
- hexdump(stdout, "iv", v->iv, sizeof v->iv);
- hexdump(stdout, "in", v->in, v->length);
- hexdump(stdout, "expected", v->out, v->length);
- hexdump(stdout, "got", buf, v->length);
-
- ++errs;
- }
- }
-
- for(n=0 ; n < sizeof(bi_ige_test_vectors)/sizeof(bi_ige_test_vectors[0])
- ; ++n)
- {
- const struct bi_ige_test * const v = &bi_ige_test_vectors[n];
- AES_KEY key1;
- AES_KEY key2;
- unsigned char buf[MAX_VECTOR_SIZE];
-
- assert(v->length <= MAX_VECTOR_SIZE);
-
- if(v->encrypt == AES_ENCRYPT)
- {
- AES_set_encrypt_key(v->key1, 8*v->keysize, &key1);
- AES_set_encrypt_key(v->key2, 8*v->keysize, &key2);
- }
- else
- {
- AES_set_decrypt_key(v->key1, 8*v->keysize, &key1);
- AES_set_decrypt_key(v->key2, 8*v->keysize, &key2);
- }
-
- AES_bi_ige_encrypt(v->in, buf, v->length, &key1, &key2, v->iv,
- v->encrypt);
-
- if(memcmp(v->out, buf, v->length))
- {
- printf("Bidirectional IGE test vector %d failed\n", n);
- hexdump(stdout, "key 1", v->key1, sizeof v->key1);
- hexdump(stdout, "key 2", v->key2, sizeof v->key2);
- hexdump(stdout, "iv", v->iv, sizeof v->iv);
- hexdump(stdout, "in", v->in, v->length);
- hexdump(stdout, "expected", v->out, v->length);
- hexdump(stdout, "got", buf, v->length);
-
- ++errs;
- }
- }
-
- return errs;
- }
-
-int main(int argc, char **argv)
- {
- unsigned char rkey[16];
- unsigned char rkey2[16];
- AES_KEY key;
- AES_KEY key2;
- unsigned char plaintext[BIG_TEST_SIZE];
- unsigned char ciphertext[BIG_TEST_SIZE];
- unsigned char checktext[BIG_TEST_SIZE];
- unsigned char iv[AES_BLOCK_SIZE*4];
- unsigned char saved_iv[AES_BLOCK_SIZE*4];
- int err = 0;
- unsigned int n;
- unsigned matches;
-
- assert(BIG_TEST_SIZE >= TEST_SIZE);
-
- RAND_pseudo_bytes(rkey, sizeof rkey);
- RAND_pseudo_bytes(plaintext, sizeof plaintext);
- RAND_pseudo_bytes(iv, sizeof iv);
- memcpy(saved_iv, iv, sizeof saved_iv);
-
- /* Forward IGE only... */
-
- /* Straight encrypt/decrypt */
- AES_set_encrypt_key(rkey, 8*sizeof rkey, &key);
- AES_ige_encrypt(plaintext, ciphertext, TEST_SIZE, &key, iv,
- AES_ENCRYPT);
-
- AES_set_decrypt_key(rkey, 8*sizeof rkey, &key);
- memcpy(iv, saved_iv, sizeof iv);
- AES_ige_encrypt(ciphertext, checktext, TEST_SIZE, &key, iv,
- AES_DECRYPT);
-
- if(memcmp(checktext, plaintext, TEST_SIZE))
- {
- printf("Encrypt+decrypt doesn't match\n");
- hexdump(stdout, "Plaintext", plaintext, TEST_SIZE);
- hexdump(stdout, "Checktext", checktext, TEST_SIZE);
- ++err;
- }
-
- /* Now check encrypt chaining works */
- AES_set_encrypt_key(rkey, 8*sizeof rkey, &key);
- memcpy(iv, saved_iv, sizeof iv);
- AES_ige_encrypt(plaintext, ciphertext, TEST_SIZE/2, &key, iv,
- AES_ENCRYPT);
- AES_ige_encrypt(plaintext+TEST_SIZE/2,
- ciphertext+TEST_SIZE/2, TEST_SIZE/2,
- &key, iv, AES_ENCRYPT);
-
- AES_set_decrypt_key(rkey, 8*sizeof rkey, &key);
- memcpy(iv, saved_iv, sizeof iv);
- AES_ige_encrypt(ciphertext, checktext, TEST_SIZE, &key, iv,
- AES_DECRYPT);
-
- if(memcmp(checktext, plaintext, TEST_SIZE))
- {
- printf("Chained encrypt+decrypt doesn't match\n");
- hexdump(stdout, "Plaintext", plaintext, TEST_SIZE);
- hexdump(stdout, "Checktext", checktext, TEST_SIZE);
- ++err;
- }
-
- /* And check decrypt chaining */
- AES_set_encrypt_key(rkey, 8*sizeof rkey, &key);
- memcpy(iv, saved_iv, sizeof iv);
- AES_ige_encrypt(plaintext, ciphertext, TEST_SIZE/2, &key, iv,
- AES_ENCRYPT);
- AES_ige_encrypt(plaintext+TEST_SIZE/2,
- ciphertext+TEST_SIZE/2, TEST_SIZE/2,
- &key, iv, AES_ENCRYPT);
-
- AES_set_decrypt_key(rkey, 8*sizeof rkey, &key);
- memcpy(iv, saved_iv, sizeof iv);
- AES_ige_encrypt(ciphertext, checktext, TEST_SIZE/2, &key, iv,
- AES_DECRYPT);
- AES_ige_encrypt(ciphertext+TEST_SIZE/2,
- checktext+TEST_SIZE/2, TEST_SIZE/2, &key, iv,
- AES_DECRYPT);
-
- if(memcmp(checktext, plaintext, TEST_SIZE))
- {
- printf("Chained encrypt+chained decrypt doesn't match\n");
- hexdump(stdout, "Plaintext", plaintext, TEST_SIZE);
- hexdump(stdout, "Checktext", checktext, TEST_SIZE);
- ++err;
- }
-
- /* make sure garble extends forwards only */
- AES_set_encrypt_key(rkey, 8*sizeof rkey, &key);
- memcpy(iv, saved_iv, sizeof iv);
- AES_ige_encrypt(plaintext, ciphertext, sizeof plaintext, &key, iv,
- AES_ENCRYPT);
-
- /* corrupt halfway through */
- ++ciphertext[sizeof ciphertext/2];
- AES_set_decrypt_key(rkey, 8*sizeof rkey, &key);
- memcpy(iv, saved_iv, sizeof iv);
- AES_ige_encrypt(ciphertext, checktext, sizeof checktext, &key, iv,
- AES_DECRYPT);
-
- matches=0;
- for(n=0 ; n < sizeof checktext ; ++n)
- if(checktext[n] == plaintext[n])
- ++matches;
-
- if(matches > sizeof checktext/2+sizeof checktext/100)
- {
- printf("More than 51%% matches after garbling\n");
- ++err;
- }
-
- if(matches < sizeof checktext/2)
- {
- printf("Garble extends backwards!\n");
- ++err;
- }
-
- /* Bi-directional IGE */
-
- /* Note that we don't have to recover the IV, because chaining isn't */
- /* possible with biIGE, so the IV is not updated. */
-
- RAND_pseudo_bytes(rkey2, sizeof rkey2);
-
- /* Straight encrypt/decrypt */
- AES_set_encrypt_key(rkey, 8*sizeof rkey, &key);
- AES_set_encrypt_key(rkey2, 8*sizeof rkey2, &key2);
- AES_bi_ige_encrypt(plaintext, ciphertext, TEST_SIZE, &key, &key2, iv,
- AES_ENCRYPT);
-
- AES_set_decrypt_key(rkey, 8*sizeof rkey, &key);
- AES_set_decrypt_key(rkey2, 8*sizeof rkey2, &key2);
- AES_bi_ige_encrypt(ciphertext, checktext, TEST_SIZE, &key, &key2, iv,
- AES_DECRYPT);
-
- if(memcmp(checktext, plaintext, TEST_SIZE))
- {
- printf("Encrypt+decrypt doesn't match\n");
- hexdump(stdout, "Plaintext", plaintext, TEST_SIZE);
- hexdump(stdout, "Checktext", checktext, TEST_SIZE);
- ++err;
- }
-
- /* make sure garble extends both ways */
- AES_set_encrypt_key(rkey, 8*sizeof rkey, &key);
- AES_set_encrypt_key(rkey2, 8*sizeof rkey2, &key2);
- AES_ige_encrypt(plaintext, ciphertext, sizeof plaintext, &key, iv,
- AES_ENCRYPT);
-
- /* corrupt halfway through */
- ++ciphertext[sizeof ciphertext/2];
- AES_set_decrypt_key(rkey, 8*sizeof rkey, &key);
- AES_set_decrypt_key(rkey2, 8*sizeof rkey2, &key2);
- AES_ige_encrypt(ciphertext, checktext, sizeof checktext, &key, iv,
- AES_DECRYPT);
-
- matches=0;
- for(n=0 ; n < sizeof checktext ; ++n)
- if(checktext[n] == plaintext[n])
- ++matches;
-
- if(matches > sizeof checktext/100)
- {
- printf("More than 1%% matches after bidirectional garbling\n");
- ++err;
- }
-
- /* make sure garble extends both ways (2) */
- AES_set_encrypt_key(rkey, 8*sizeof rkey, &key);
- AES_set_encrypt_key(rkey2, 8*sizeof rkey2, &key2);
- AES_ige_encrypt(plaintext, ciphertext, sizeof plaintext, &key, iv,
- AES_ENCRYPT);
-
- /* corrupt right at the end */
- ++ciphertext[sizeof ciphertext-1];
- AES_set_decrypt_key(rkey, 8*sizeof rkey, &key);
- AES_set_decrypt_key(rkey2, 8*sizeof rkey2, &key2);
- AES_ige_encrypt(ciphertext, checktext, sizeof checktext, &key, iv,
- AES_DECRYPT);
-
- matches=0;
- for(n=0 ; n < sizeof checktext ; ++n)
- if(checktext[n] == plaintext[n])
- ++matches;
-
- if(matches > sizeof checktext/100)
- {
- printf("More than 1%% matches after bidirectional garbling (2)\n");
- ++err;
- }
-
- /* make sure garble extends both ways (3) */
- AES_set_encrypt_key(rkey, 8*sizeof rkey, &key);
- AES_set_encrypt_key(rkey2, 8*sizeof rkey2, &key2);
- AES_ige_encrypt(plaintext, ciphertext, sizeof plaintext, &key, iv,
- AES_ENCRYPT);
-
- /* corrupt right at the start */
- ++ciphertext[0];
- AES_set_decrypt_key(rkey, 8*sizeof rkey, &key);
- AES_set_decrypt_key(rkey2, 8*sizeof rkey2, &key2);
- AES_ige_encrypt(ciphertext, checktext, sizeof checktext, &key, iv,
- AES_DECRYPT);
-
- matches=0;
- for(n=0 ; n < sizeof checktext ; ++n)
- if(checktext[n] == plaintext[n])
- ++matches;
-
- if(matches > sizeof checktext/100)
- {
- printf("More than 1%% matches after bidirectional garbling (3)\n");
- ++err;
- }
-
- err += run_test_vectors();
-
- return err;
- }
+static int test_ige_vectors(int n)
+{
+ const struct ige_test *const v = &ige_test_vectors[n];
+ AES_KEY key;
+ unsigned char buf[MAX_VECTOR_SIZE];
+ unsigned char iv[AES_BLOCK_SIZE * 2];
+ int testresult = 1;
+
+ if (!TEST_int_le(v->length, MAX_VECTOR_SIZE))
+ return 0;
+
+ if (v->encrypt == AES_ENCRYPT)
+ AES_set_encrypt_key(v->key, 8 * sizeof(v->key), &key);
+ else
+ AES_set_decrypt_key(v->key, 8 * sizeof(v->key), &key);
+ memcpy(iv, v->iv, sizeof(iv));
+ AES_ige_encrypt(v->in, buf, v->length, &key, iv, v->encrypt);
+
+ if (!TEST_mem_eq(v->out, v->length, buf, v->length)) {
+ TEST_info("IGE test vector %d failed", n);
+ test_output_memory("key", v->key, sizeof(v->key));
+ test_output_memory("iv", v->iv, sizeof(v->iv));
+ test_output_memory("in", v->in, v->length);
+ testresult = 0;
+ }
+
+ /* try with in == out */
+ memcpy(iv, v->iv, sizeof(iv));
+ memcpy(buf, v->in, v->length);
+ AES_ige_encrypt(buf, buf, v->length, &key, iv, v->encrypt);
+
+ if (!TEST_mem_eq(v->out, v->length, buf, v->length)) {
+ TEST_info("IGE test vector %d failed (with in == out)", n);
+ test_output_memory("key", v->key, sizeof(v->key));
+ test_output_memory("iv", v->iv, sizeof(v->iv));
+ test_output_memory("in", v->in, v->length);
+ testresult = 0;
+ }
+
+ return testresult;
+}
+
+static int test_bi_ige_vectors(int n)
+{
+ const struct bi_ige_test *const v = &bi_ige_test_vectors[n];
+ AES_KEY key1;
+ AES_KEY key2;
+ unsigned char buf[MAX_VECTOR_SIZE];
+
+ if (!TEST_int_le(v->length, MAX_VECTOR_SIZE))
+ return 0;
+
+ if (v->encrypt == AES_ENCRYPT) {
+ AES_set_encrypt_key(v->key1, 8 * v->keysize, &key1);
+ AES_set_encrypt_key(v->key2, 8 * v->keysize, &key2);
+ } else {
+ AES_set_decrypt_key(v->key1, 8 * v->keysize, &key1);
+ AES_set_decrypt_key(v->key2, 8 * v->keysize, &key2);
+ }
+
+ AES_bi_ige_encrypt(v->in, buf, v->length, &key1, &key2, v->iv,
+ v->encrypt);
+
+ if (!TEST_mem_eq(v->out, v->length, buf, v->length)) {
+ test_output_memory("key 1", v->key1, sizeof(v->key1));
+ test_output_memory("key 2", v->key2, sizeof(v->key2));
+ test_output_memory("iv", v->iv, sizeof(v->iv));
+ test_output_memory("in", v->in, v->length);
+ return 0;
+ }
+
+ return 1;
+}
+
+static int test_ige_enc_dec(void)
+{
+ AES_KEY key;
+ unsigned char iv[AES_BLOCK_SIZE * 4];
+ unsigned char ciphertext[BIG_TEST_SIZE];
+ unsigned char checktext[BIG_TEST_SIZE];
+
+ memcpy(iv, saved_iv, sizeof(iv));
+ AES_set_encrypt_key(rkey, 8 * sizeof(rkey), &key);
+ AES_ige_encrypt(plaintext, ciphertext, TEST_SIZE, &key, iv, AES_ENCRYPT);
+
+ AES_set_decrypt_key(rkey, 8 * sizeof(rkey), &key);
+ memcpy(iv, saved_iv, sizeof(iv));
+ AES_ige_encrypt(ciphertext, checktext, TEST_SIZE, &key, iv, AES_DECRYPT);
+
+ return TEST_mem_eq(checktext, TEST_SIZE, plaintext, TEST_SIZE);
+}
+
+static int test_ige_enc_chaining(void)
+{
+ AES_KEY key;
+ unsigned char iv[AES_BLOCK_SIZE * 4];
+ unsigned char ciphertext[BIG_TEST_SIZE];
+ unsigned char checktext[BIG_TEST_SIZE];
+
+ AES_set_encrypt_key(rkey, 8 * sizeof(rkey), &key);
+ memcpy(iv, saved_iv, sizeof(iv));
+ AES_ige_encrypt(plaintext, ciphertext, TEST_SIZE / 2, &key, iv,
+ AES_ENCRYPT);
+ AES_ige_encrypt(plaintext + TEST_SIZE / 2,
+ ciphertext + TEST_SIZE / 2, TEST_SIZE / 2,
+ &key, iv, AES_ENCRYPT);
+
+ AES_set_decrypt_key(rkey, 8 * sizeof(rkey), &key);
+ memcpy(iv, saved_iv, sizeof(iv));
+ AES_ige_encrypt(ciphertext, checktext, TEST_SIZE, &key, iv, AES_DECRYPT);
+
+ return TEST_mem_eq(checktext, TEST_SIZE, plaintext, TEST_SIZE);
+}
+
+static int test_ige_dec_chaining(void)
+{
+ AES_KEY key;
+ unsigned char iv[AES_BLOCK_SIZE * 4];
+ unsigned char ciphertext[BIG_TEST_SIZE];
+ unsigned char checktext[BIG_TEST_SIZE];
+
+ AES_set_encrypt_key(rkey, 8 * sizeof(rkey), &key);
+ memcpy(iv, saved_iv, sizeof(iv));
+ AES_ige_encrypt(plaintext, ciphertext, TEST_SIZE / 2, &key, iv,
+ AES_ENCRYPT);
+ AES_ige_encrypt(plaintext + TEST_SIZE / 2,
+ ciphertext + TEST_SIZE / 2, TEST_SIZE / 2,
+ &key, iv, AES_ENCRYPT);
+
+ AES_set_decrypt_key(rkey, 8 * sizeof(rkey), &key);
+ memcpy(iv, saved_iv, sizeof(iv));
+ AES_ige_encrypt(ciphertext, checktext, TEST_SIZE / 2, &key, iv,
+ AES_DECRYPT);
+ AES_ige_encrypt(ciphertext + TEST_SIZE / 2,
+ checktext + TEST_SIZE / 2, TEST_SIZE / 2, &key, iv,
+ AES_DECRYPT);
+
+ return TEST_mem_eq(checktext, TEST_SIZE, plaintext, TEST_SIZE);
+}
+
+static int test_ige_garble_forwards(void)
+{
+ AES_KEY key;
+ unsigned char iv[AES_BLOCK_SIZE * 4];
+ unsigned char ciphertext[BIG_TEST_SIZE];
+ unsigned char checktext[BIG_TEST_SIZE];
+ unsigned int n;
+ int testresult = 1;
+ const size_t ctsize = sizeof(checktext);
+ size_t matches;
+
+ AES_set_encrypt_key(rkey, 8 * sizeof(rkey), &key);
+ memcpy(iv, saved_iv, sizeof(iv));
+ AES_ige_encrypt(plaintext, ciphertext, sizeof(plaintext), &key, iv,
+ AES_ENCRYPT);
+
+ /* corrupt halfway through */
+ ++ciphertext[sizeof(ciphertext) / 2];
+ AES_set_decrypt_key(rkey, 8 * sizeof(rkey), &key);
+ memcpy(iv, saved_iv, sizeof(iv));
+ AES_ige_encrypt(ciphertext, checktext, sizeof(checktext), &key, iv,
+ AES_DECRYPT);
+
+ matches = 0;
+ for (n = 0; n < sizeof(checktext); ++n)
+ if (checktext[n] == plaintext[n])
+ ++matches;
+
+ /* Fail if there is more than 51% matching bytes */
+ if (!TEST_size_t_le(matches, ctsize / 2 + ctsize / 100))
+ testresult = 0;
+
+ /* Fail if the garble goes backwards */
+ if (!TEST_size_t_gt(matches, ctsize / 2))
+ testresult = 0;
+ return testresult;
+}
+
+static int test_bi_ige_enc_dec(void)
+{
+ AES_KEY key, key2;
+ unsigned char iv[AES_BLOCK_SIZE * 4];
+ unsigned char ciphertext[BIG_TEST_SIZE];
+ unsigned char checktext[BIG_TEST_SIZE];
+
+ memcpy(iv, saved_iv, sizeof(iv));
+ AES_set_encrypt_key(rkey, 8 * sizeof(rkey), &key);
+ AES_set_encrypt_key(rkey2, 8 * sizeof(rkey2), &key2);
+ AES_bi_ige_encrypt(plaintext, ciphertext, TEST_SIZE, &key, &key2, iv,
+ AES_ENCRYPT);
+
+ AES_set_decrypt_key(rkey, 8 * sizeof(rkey), &key);
+ AES_set_decrypt_key(rkey2, 8 * sizeof(rkey2), &key2);
+ AES_bi_ige_encrypt(ciphertext, checktext, TEST_SIZE, &key, &key2, iv,
+ AES_DECRYPT);
+
+ return TEST_mem_eq(checktext, TEST_SIZE, plaintext, TEST_SIZE);
+}
+
+static int test_bi_ige_garble1(void)
+{
+ AES_KEY key, key2;
+ unsigned char iv[AES_BLOCK_SIZE * 4];
+ unsigned char ciphertext[BIG_TEST_SIZE];
+ unsigned char checktext[BIG_TEST_SIZE];
+ unsigned int n;
+ size_t matches;
+
+ memcpy(iv, saved_iv, sizeof(iv));
+ AES_set_encrypt_key(rkey, 8 * sizeof(rkey), &key);
+ AES_set_encrypt_key(rkey2, 8 * sizeof(rkey2), &key2);
+ AES_ige_encrypt(plaintext, ciphertext, sizeof(plaintext), &key, iv,
+ AES_ENCRYPT);
+
+ /* corrupt halfway through */
+ ++ciphertext[sizeof(ciphertext) / 2];
+ AES_set_decrypt_key(rkey, 8 * sizeof(rkey), &key);
+ AES_set_decrypt_key(rkey2, 8 * sizeof(rkey2), &key2);
+ AES_ige_encrypt(ciphertext, checktext, sizeof(checktext), &key, iv,
+ AES_DECRYPT);
+
+ matches = 0;
+ for (n = 0; n < sizeof(checktext); ++n)
+ if (checktext[n] == plaintext[n])
+ ++matches;
+
+ /* Fail if there is more than 1% matching bytes */
+ return TEST_size_t_le(matches, sizeof(checktext) / 100);
+}
+
+static int test_bi_ige_garble2(void)
+{
+ AES_KEY key, key2;
+ unsigned char iv[AES_BLOCK_SIZE * 4];
+ unsigned char ciphertext[BIG_TEST_SIZE];
+ unsigned char checktext[BIG_TEST_SIZE];
+ unsigned int n;
+ size_t matches;
+
+ memcpy(iv, saved_iv, sizeof(iv));
+ AES_set_encrypt_key(rkey, 8 * sizeof(rkey), &key);
+ AES_set_encrypt_key(rkey2, 8 * sizeof(rkey2), &key2);
+ AES_ige_encrypt(plaintext, ciphertext, sizeof(plaintext), &key, iv,
+ AES_ENCRYPT);
+
+ /* corrupt right at the end */
+ ++ciphertext[sizeof(ciphertext) - 1];
+ AES_set_decrypt_key(rkey, 8 * sizeof(rkey), &key);
+ AES_set_decrypt_key(rkey2, 8 * sizeof(rkey2), &key2);
+ AES_ige_encrypt(ciphertext, checktext, sizeof(checktext), &key, iv,
+ AES_DECRYPT);
+
+ matches = 0;
+ for (n = 0; n < sizeof(checktext); ++n)
+ if (checktext[n] == plaintext[n])
+ ++matches;
+
+ /* Fail if there is more than 1% matching bytes */
+ return TEST_size_t_le(matches, sizeof(checktext) / 100);
+}
+
+static int test_bi_ige_garble3(void)
+{
+ AES_KEY key, key2;
+ unsigned char iv[AES_BLOCK_SIZE * 4];
+ unsigned char ciphertext[BIG_TEST_SIZE];
+ unsigned char checktext[BIG_TEST_SIZE];
+ unsigned int n;
+ size_t matches;
+
+ memcpy(iv, saved_iv, sizeof(iv));
+ AES_set_encrypt_key(rkey, 8 * sizeof(rkey), &key);
+ AES_set_encrypt_key(rkey2, 8 * sizeof(rkey2), &key2);
+ AES_ige_encrypt(plaintext, ciphertext, sizeof(plaintext), &key, iv,
+ AES_ENCRYPT);
+
+ /* corrupt right at the start */
+ ++ciphertext[0];
+ AES_set_decrypt_key(rkey, 8 * sizeof(rkey), &key);
+ AES_set_decrypt_key(rkey2, 8 * sizeof(rkey2), &key2);
+ AES_ige_encrypt(ciphertext, checktext, sizeof(checktext), &key, iv,
+ AES_DECRYPT);
+
+ matches = 0;
+ for (n = 0; n < sizeof(checktext); ++n)
+ if (checktext[n] == plaintext[n])
+ ++matches;
+
+ /* Fail if there is more than 1% matching bytes */
+ return TEST_size_t_le(matches, sizeof(checktext) / 100);
+}
+#endif
+
+int setup_tests(void)
+{
+#ifndef OPENSSL_NO_DEPRECATED_3_0
+ RAND_bytes(rkey, sizeof(rkey));
+ RAND_bytes(rkey2, sizeof(rkey2));
+ RAND_bytes(plaintext, sizeof(plaintext));
+ RAND_bytes(saved_iv, sizeof(saved_iv));
+
+ ADD_TEST(test_ige_enc_dec);
+ ADD_TEST(test_ige_enc_chaining);
+ ADD_TEST(test_ige_dec_chaining);
+ ADD_TEST(test_ige_garble_forwards);
+ ADD_TEST(test_bi_ige_enc_dec);
+ ADD_TEST(test_bi_ige_garble1);
+ ADD_TEST(test_bi_ige_garble2);
+ ADD_TEST(test_bi_ige_garble3);
+ ADD_ALL_TESTS(test_ige_vectors, OSSL_NELEM(ige_test_vectors));
+ ADD_ALL_TESTS(test_bi_ige_vectors, OSSL_NELEM(bi_ige_test_vectors));
+#endif
+ return 1;
+}