1*657b055cStb /* $OpenBSD: igetest.c,v 1.4 2018/07/17 17:06:49 tb Exp $ */
23c6bd008Smiod /* ====================================================================
33c6bd008Smiod * Copyright (c) 2006 The OpenSSL Project. All rights reserved.
43c6bd008Smiod *
53c6bd008Smiod * Redistribution and use in source and binary forms, with or without
63c6bd008Smiod * modification, are permitted provided that the following conditions
73c6bd008Smiod * are met:
83c6bd008Smiod *
93c6bd008Smiod * 1. Redistributions of source code must retain the above copyright
103c6bd008Smiod * notice, this list of conditions and the following disclaimer.
113c6bd008Smiod *
123c6bd008Smiod * 2. Redistributions in binary form must reproduce the above copyright
133c6bd008Smiod * notice, this list of conditions and the following disclaimer in
143c6bd008Smiod * the documentation and/or other materials provided with the
153c6bd008Smiod * distribution.
163c6bd008Smiod *
173c6bd008Smiod * 3. All advertising materials mentioning features or use of this
183c6bd008Smiod * software must display the following acknowledgment:
193c6bd008Smiod * "This product includes software developed by the OpenSSL Project
203c6bd008Smiod * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
213c6bd008Smiod *
223c6bd008Smiod * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
233c6bd008Smiod * endorse or promote products derived from this software without
243c6bd008Smiod * prior written permission. For written permission, please contact
253c6bd008Smiod * openssl-core@openssl.org.
263c6bd008Smiod *
273c6bd008Smiod * 5. Products derived from this software may not be called "OpenSSL"
283c6bd008Smiod * nor may "OpenSSL" appear in their names without prior written
293c6bd008Smiod * permission of the OpenSSL Project.
303c6bd008Smiod *
313c6bd008Smiod * 6. Redistributions of any form whatsoever must retain the following
323c6bd008Smiod * acknowledgment:
333c6bd008Smiod * "This product includes software developed by the OpenSSL Project
343c6bd008Smiod * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
353c6bd008Smiod *
363c6bd008Smiod * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
373c6bd008Smiod * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
383c6bd008Smiod * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
393c6bd008Smiod * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
403c6bd008Smiod * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
413c6bd008Smiod * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
423c6bd008Smiod * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
433c6bd008Smiod * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
443c6bd008Smiod * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
453c6bd008Smiod * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
463c6bd008Smiod * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
473c6bd008Smiod * OF THE POSSIBILITY OF SUCH DAMAGE.
483c6bd008Smiod * ====================================================================
493c6bd008Smiod *
503c6bd008Smiod */
513c6bd008Smiod
523c6bd008Smiod #include <assert.h>
537603f286Sjsing #include <stdio.h>
547603f286Sjsing #include <stdlib.h>
557603f286Sjsing #include <string.h>
567603f286Sjsing
577603f286Sjsing #include <openssl/aes.h>
583c6bd008Smiod
593c6bd008Smiod #define TEST_SIZE 128
603c6bd008Smiod #define BIG_TEST_SIZE 10240
613c6bd008Smiod
hexdump(FILE * f,const char * title,const unsigned char * s,int l)623c6bd008Smiod static void hexdump(FILE *f,const char *title,const unsigned char *s,int l)
633c6bd008Smiod {
643c6bd008Smiod int n=0;
653c6bd008Smiod
663c6bd008Smiod fprintf(f,"%s",title);
673c6bd008Smiod for( ; n < l ; ++n)
683c6bd008Smiod {
693c6bd008Smiod if((n%16) == 0)
703c6bd008Smiod fprintf(f,"\n%04x",n);
713c6bd008Smiod fprintf(f," %02x",s[n]);
723c6bd008Smiod }
733c6bd008Smiod fprintf(f,"\n");
743c6bd008Smiod }
753c6bd008Smiod
763c6bd008Smiod #define MAX_VECTOR_SIZE 64
773c6bd008Smiod
783c6bd008Smiod struct ige_test
793c6bd008Smiod {
803c6bd008Smiod const unsigned char key[16];
813c6bd008Smiod const unsigned char iv[32];
823c6bd008Smiod const unsigned char in[MAX_VECTOR_SIZE];
833c6bd008Smiod const unsigned char out[MAX_VECTOR_SIZE];
843c6bd008Smiod const size_t length;
853c6bd008Smiod const int encrypt;
863c6bd008Smiod };
873c6bd008Smiod
883c6bd008Smiod static struct ige_test const ige_test_vectors[] = {
893c6bd008Smiod { { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
903c6bd008Smiod 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, /* key */
913c6bd008Smiod { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
923c6bd008Smiod 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
933c6bd008Smiod 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
943c6bd008Smiod 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }, /* iv */
953c6bd008Smiod { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
963c6bd008Smiod 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
973c6bd008Smiod 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
983c6bd008Smiod 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* in */
993c6bd008Smiod { 0x1a, 0x85, 0x19, 0xa6, 0x55, 0x7b, 0xe6, 0x52,
1003c6bd008Smiod 0xe9, 0xda, 0x8e, 0x43, 0xda, 0x4e, 0xf4, 0x45,
1013c6bd008Smiod 0x3c, 0xf4, 0x56, 0xb4, 0xca, 0x48, 0x8a, 0xa3,
1023c6bd008Smiod 0x83, 0xc7, 0x9c, 0x98, 0xb3, 0x47, 0x97, 0xcb }, /* out */
1033c6bd008Smiod 32, AES_ENCRYPT }, /* test vector 0 */
1043c6bd008Smiod
1053c6bd008Smiod { { 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
1063c6bd008Smiod 0x61, 0x6e, 0x20, 0x69, 0x6d, 0x70, 0x6c, 0x65 }, /* key */
1073c6bd008Smiod { 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f,
1083c6bd008Smiod 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x49, 0x47, 0x45,
1093c6bd008Smiod 0x20, 0x6d, 0x6f, 0x64, 0x65, 0x20, 0x66, 0x6f,
1103c6bd008Smiod 0x72, 0x20, 0x4f, 0x70, 0x65, 0x6e, 0x53, 0x53 }, /* iv */
1113c6bd008Smiod { 0x4c, 0x2e, 0x20, 0x4c, 0x65, 0x74, 0x27, 0x73,
1123c6bd008Smiod 0x20, 0x68, 0x6f, 0x70, 0x65, 0x20, 0x42, 0x65,
1133c6bd008Smiod 0x6e, 0x20, 0x67, 0x6f, 0x74, 0x20, 0x69, 0x74,
1143c6bd008Smiod 0x20, 0x72, 0x69, 0x67, 0x68, 0x74, 0x21, 0x0a }, /* in */
1153c6bd008Smiod { 0x99, 0x70, 0x64, 0x87, 0xa1, 0xcd, 0xe6, 0x13,
1163c6bd008Smiod 0xbc, 0x6d, 0xe0, 0xb6, 0xf2, 0x4b, 0x1c, 0x7a,
1173c6bd008Smiod 0xa4, 0x48, 0xc8, 0xb9, 0xc3, 0x40, 0x3e, 0x34,
1183c6bd008Smiod 0x67, 0xa8, 0xca, 0xd8, 0x93, 0x40, 0xf5, 0x3b }, /* out */
1193c6bd008Smiod 32, AES_DECRYPT }, /* test vector 1 */
1203c6bd008Smiod };
1213c6bd008Smiod
run_test_vectors(void)1223c6bd008Smiod static int run_test_vectors(void)
1233c6bd008Smiod {
1243c6bd008Smiod unsigned int n;
1253c6bd008Smiod int errs = 0;
1263c6bd008Smiod
1273c6bd008Smiod for(n=0 ; n < sizeof(ige_test_vectors)/sizeof(ige_test_vectors[0]) ; ++n)
1283c6bd008Smiod {
1293c6bd008Smiod const struct ige_test * const v = &ige_test_vectors[n];
1303c6bd008Smiod AES_KEY key;
1313c6bd008Smiod unsigned char buf[MAX_VECTOR_SIZE];
1323c6bd008Smiod unsigned char iv[AES_BLOCK_SIZE*2];
1333c6bd008Smiod
1343c6bd008Smiod assert(v->length <= MAX_VECTOR_SIZE);
1353c6bd008Smiod
1363c6bd008Smiod if(v->encrypt == AES_ENCRYPT)
1373c6bd008Smiod AES_set_encrypt_key(v->key, 8*sizeof v->key, &key);
1383c6bd008Smiod else
1393c6bd008Smiod AES_set_decrypt_key(v->key, 8*sizeof v->key, &key);
1403c6bd008Smiod memcpy(iv, v->iv, sizeof iv);
1413c6bd008Smiod AES_ige_encrypt(v->in, buf, v->length, &key, iv, v->encrypt);
1423c6bd008Smiod
1433c6bd008Smiod if(memcmp(v->out, buf, v->length))
1443c6bd008Smiod {
1453c6bd008Smiod printf("IGE test vector %d failed\n", n);
1463c6bd008Smiod hexdump(stdout, "key", v->key, sizeof v->key);
1473c6bd008Smiod hexdump(stdout, "iv", v->iv, sizeof v->iv);
1483c6bd008Smiod hexdump(stdout, "in", v->in, v->length);
1493c6bd008Smiod hexdump(stdout, "expected", v->out, v->length);
1503c6bd008Smiod hexdump(stdout, "got", buf, v->length);
1513c6bd008Smiod
1523c6bd008Smiod ++errs;
1533c6bd008Smiod }
1543c6bd008Smiod
1553c6bd008Smiod /* try with in == out */
1563c6bd008Smiod memcpy(iv, v->iv, sizeof iv);
1573c6bd008Smiod memcpy(buf, v->in, v->length);
1583c6bd008Smiod AES_ige_encrypt(buf, buf, v->length, &key, iv, v->encrypt);
1593c6bd008Smiod
1603c6bd008Smiod if(memcmp(v->out, buf, v->length))
1613c6bd008Smiod {
1623c6bd008Smiod printf("IGE test vector %d failed (with in == out)\n", n);
1633c6bd008Smiod hexdump(stdout, "key", v->key, sizeof v->key);
1643c6bd008Smiod hexdump(stdout, "iv", v->iv, sizeof v->iv);
1653c6bd008Smiod hexdump(stdout, "in", v->in, v->length);
1663c6bd008Smiod hexdump(stdout, "expected", v->out, v->length);
1673c6bd008Smiod hexdump(stdout, "got", buf, v->length);
1683c6bd008Smiod
1693c6bd008Smiod ++errs;
1703c6bd008Smiod }
1713c6bd008Smiod }
1723c6bd008Smiod
1733c6bd008Smiod return errs;
1743c6bd008Smiod }
1753c6bd008Smiod
main(int argc,char ** argv)1763c6bd008Smiod int main(int argc, char **argv)
1773c6bd008Smiod {
1783c6bd008Smiod unsigned char rkey[16];
1793c6bd008Smiod unsigned char rkey2[16];
1803c6bd008Smiod AES_KEY key;
1813c6bd008Smiod AES_KEY key2;
1823c6bd008Smiod unsigned char plaintext[BIG_TEST_SIZE];
1833c6bd008Smiod unsigned char ciphertext[BIG_TEST_SIZE];
1843c6bd008Smiod unsigned char checktext[BIG_TEST_SIZE];
1853c6bd008Smiod unsigned char iv[AES_BLOCK_SIZE*4];
1863c6bd008Smiod unsigned char saved_iv[AES_BLOCK_SIZE*4];
1873c6bd008Smiod int err = 0;
1883c6bd008Smiod unsigned int n;
1893c6bd008Smiod unsigned matches;
1903c6bd008Smiod
1913c6bd008Smiod assert(BIG_TEST_SIZE >= TEST_SIZE);
1923c6bd008Smiod
1937603f286Sjsing arc4random_buf(rkey, sizeof(rkey));
1947603f286Sjsing arc4random_buf(plaintext, sizeof(plaintext));
1957603f286Sjsing arc4random_buf(iv, sizeof(iv));
1967603f286Sjsing memcpy(saved_iv, iv, sizeof(saved_iv));
1973c6bd008Smiod
1983c6bd008Smiod /* Forward IGE only... */
1993c6bd008Smiod
2003c6bd008Smiod /* Straight encrypt/decrypt */
2013c6bd008Smiod AES_set_encrypt_key(rkey, 8*sizeof rkey, &key);
2023c6bd008Smiod AES_ige_encrypt(plaintext, ciphertext, TEST_SIZE, &key, iv,
2033c6bd008Smiod AES_ENCRYPT);
2043c6bd008Smiod
2053c6bd008Smiod AES_set_decrypt_key(rkey, 8*sizeof rkey, &key);
2063c6bd008Smiod memcpy(iv, saved_iv, sizeof iv);
2073c6bd008Smiod AES_ige_encrypt(ciphertext, checktext, TEST_SIZE, &key, iv,
2083c6bd008Smiod AES_DECRYPT);
2093c6bd008Smiod
2103c6bd008Smiod if(memcmp(checktext, plaintext, TEST_SIZE))
2113c6bd008Smiod {
2123c6bd008Smiod printf("Encrypt+decrypt doesn't match\n");
2133c6bd008Smiod hexdump(stdout, "Plaintext", plaintext, TEST_SIZE);
2143c6bd008Smiod hexdump(stdout, "Checktext", checktext, TEST_SIZE);
2153c6bd008Smiod ++err;
2163c6bd008Smiod }
2173c6bd008Smiod
2183c6bd008Smiod /* Now check encrypt chaining works */
2193c6bd008Smiod AES_set_encrypt_key(rkey, 8*sizeof rkey, &key);
2203c6bd008Smiod memcpy(iv, saved_iv, sizeof iv);
2213c6bd008Smiod AES_ige_encrypt(plaintext, ciphertext, TEST_SIZE/2, &key, iv,
2223c6bd008Smiod AES_ENCRYPT);
2233c6bd008Smiod AES_ige_encrypt(plaintext+TEST_SIZE/2,
2243c6bd008Smiod ciphertext+TEST_SIZE/2, TEST_SIZE/2,
2253c6bd008Smiod &key, iv, AES_ENCRYPT);
2263c6bd008Smiod
2273c6bd008Smiod AES_set_decrypt_key(rkey, 8*sizeof rkey, &key);
2283c6bd008Smiod memcpy(iv, saved_iv, sizeof iv);
2293c6bd008Smiod AES_ige_encrypt(ciphertext, checktext, TEST_SIZE, &key, iv,
2303c6bd008Smiod AES_DECRYPT);
2313c6bd008Smiod
2323c6bd008Smiod if(memcmp(checktext, plaintext, TEST_SIZE))
2333c6bd008Smiod {
2343c6bd008Smiod printf("Chained encrypt+decrypt doesn't match\n");
2353c6bd008Smiod hexdump(stdout, "Plaintext", plaintext, TEST_SIZE);
2363c6bd008Smiod hexdump(stdout, "Checktext", checktext, TEST_SIZE);
2373c6bd008Smiod ++err;
2383c6bd008Smiod }
2393c6bd008Smiod
2403c6bd008Smiod /* And check decrypt chaining */
2413c6bd008Smiod AES_set_encrypt_key(rkey, 8*sizeof rkey, &key);
2423c6bd008Smiod memcpy(iv, saved_iv, sizeof iv);
2433c6bd008Smiod AES_ige_encrypt(plaintext, ciphertext, TEST_SIZE/2, &key, iv,
2443c6bd008Smiod AES_ENCRYPT);
2453c6bd008Smiod AES_ige_encrypt(plaintext+TEST_SIZE/2,
2463c6bd008Smiod ciphertext+TEST_SIZE/2, TEST_SIZE/2,
2473c6bd008Smiod &key, iv, AES_ENCRYPT);
2483c6bd008Smiod
2493c6bd008Smiod AES_set_decrypt_key(rkey, 8*sizeof rkey, &key);
2503c6bd008Smiod memcpy(iv, saved_iv, sizeof iv);
2513c6bd008Smiod AES_ige_encrypt(ciphertext, checktext, TEST_SIZE/2, &key, iv,
2523c6bd008Smiod AES_DECRYPT);
2533c6bd008Smiod AES_ige_encrypt(ciphertext+TEST_SIZE/2,
2543c6bd008Smiod checktext+TEST_SIZE/2, TEST_SIZE/2, &key, iv,
2553c6bd008Smiod AES_DECRYPT);
2563c6bd008Smiod
2573c6bd008Smiod if(memcmp(checktext, plaintext, TEST_SIZE))
2583c6bd008Smiod {
2593c6bd008Smiod printf("Chained encrypt+chained decrypt doesn't match\n");
2603c6bd008Smiod hexdump(stdout, "Plaintext", plaintext, TEST_SIZE);
2613c6bd008Smiod hexdump(stdout, "Checktext", checktext, TEST_SIZE);
2623c6bd008Smiod ++err;
2633c6bd008Smiod }
2643c6bd008Smiod
2653c6bd008Smiod /* make sure garble extends forwards only */
2663c6bd008Smiod AES_set_encrypt_key(rkey, 8*sizeof rkey, &key);
2673c6bd008Smiod memcpy(iv, saved_iv, sizeof iv);
2683c6bd008Smiod AES_ige_encrypt(plaintext, ciphertext, sizeof plaintext, &key, iv,
2693c6bd008Smiod AES_ENCRYPT);
2703c6bd008Smiod
2713c6bd008Smiod /* corrupt halfway through */
2723c6bd008Smiod ++ciphertext[sizeof ciphertext/2];
2733c6bd008Smiod AES_set_decrypt_key(rkey, 8*sizeof rkey, &key);
2743c6bd008Smiod memcpy(iv, saved_iv, sizeof iv);
2753c6bd008Smiod AES_ige_encrypt(ciphertext, checktext, sizeof checktext, &key, iv,
2763c6bd008Smiod AES_DECRYPT);
2773c6bd008Smiod
2783c6bd008Smiod matches=0;
2793c6bd008Smiod for(n=0 ; n < sizeof checktext ; ++n)
2803c6bd008Smiod if(checktext[n] == plaintext[n])
2813c6bd008Smiod ++matches;
2823c6bd008Smiod
2833c6bd008Smiod if(matches > sizeof checktext/2+sizeof checktext/100)
2843c6bd008Smiod {
2853c6bd008Smiod printf("More than 51%% matches after garbling\n");
2863c6bd008Smiod ++err;
2873c6bd008Smiod }
2883c6bd008Smiod
2893c6bd008Smiod if(matches < sizeof checktext/2)
2903c6bd008Smiod {
2913c6bd008Smiod printf("Garble extends backwards!\n");
2923c6bd008Smiod ++err;
2933c6bd008Smiod }
2943c6bd008Smiod
2953c6bd008Smiod /* make sure garble extends both ways */
2963c6bd008Smiod AES_set_encrypt_key(rkey, 8*sizeof rkey, &key);
2973c6bd008Smiod AES_set_encrypt_key(rkey2, 8*sizeof rkey2, &key2);
2983c6bd008Smiod AES_ige_encrypt(plaintext, ciphertext, sizeof plaintext, &key, iv,
2993c6bd008Smiod AES_ENCRYPT);
3003c6bd008Smiod
3013c6bd008Smiod /* corrupt halfway through */
3023c6bd008Smiod ++ciphertext[sizeof ciphertext/2];
3033c6bd008Smiod AES_set_decrypt_key(rkey, 8*sizeof rkey, &key);
3043c6bd008Smiod AES_set_decrypt_key(rkey2, 8*sizeof rkey2, &key2);
3053c6bd008Smiod AES_ige_encrypt(ciphertext, checktext, sizeof checktext, &key, iv,
3063c6bd008Smiod AES_DECRYPT);
3073c6bd008Smiod
3083c6bd008Smiod matches=0;
3093c6bd008Smiod for(n=0 ; n < sizeof checktext ; ++n)
3103c6bd008Smiod if(checktext[n] == plaintext[n])
3113c6bd008Smiod ++matches;
3123c6bd008Smiod
3133c6bd008Smiod if(matches > sizeof checktext/100)
3143c6bd008Smiod {
3153c6bd008Smiod printf("More than 1%% matches after bidirectional garbling\n");
3163c6bd008Smiod ++err;
3173c6bd008Smiod }
3183c6bd008Smiod
3193c6bd008Smiod /* make sure garble extends both ways (2) */
3203c6bd008Smiod AES_set_encrypt_key(rkey, 8*sizeof rkey, &key);
3213c6bd008Smiod AES_set_encrypt_key(rkey2, 8*sizeof rkey2, &key2);
3223c6bd008Smiod AES_ige_encrypt(plaintext, ciphertext, sizeof plaintext, &key, iv,
3233c6bd008Smiod AES_ENCRYPT);
3243c6bd008Smiod
3253c6bd008Smiod /* corrupt right at the end */
3263c6bd008Smiod ++ciphertext[sizeof ciphertext-1];
3273c6bd008Smiod AES_set_decrypt_key(rkey, 8*sizeof rkey, &key);
3283c6bd008Smiod AES_set_decrypt_key(rkey2, 8*sizeof rkey2, &key2);
3293c6bd008Smiod AES_ige_encrypt(ciphertext, checktext, sizeof checktext, &key, iv,
3303c6bd008Smiod AES_DECRYPT);
3313c6bd008Smiod
3323c6bd008Smiod matches=0;
3333c6bd008Smiod for(n=0 ; n < sizeof checktext ; ++n)
3343c6bd008Smiod if(checktext[n] == plaintext[n])
3353c6bd008Smiod ++matches;
3363c6bd008Smiod
3373c6bd008Smiod if(matches > sizeof checktext/100)
3383c6bd008Smiod {
3393c6bd008Smiod printf("More than 1%% matches after bidirectional garbling (2)\n");
3403c6bd008Smiod ++err;
3413c6bd008Smiod }
3423c6bd008Smiod
3433c6bd008Smiod /* make sure garble extends both ways (3) */
3443c6bd008Smiod AES_set_encrypt_key(rkey, 8*sizeof rkey, &key);
3453c6bd008Smiod AES_set_encrypt_key(rkey2, 8*sizeof rkey2, &key2);
3463c6bd008Smiod AES_ige_encrypt(plaintext, ciphertext, sizeof plaintext, &key, iv,
3473c6bd008Smiod AES_ENCRYPT);
3483c6bd008Smiod
3493c6bd008Smiod /* corrupt right at the start */
3503c6bd008Smiod ++ciphertext[0];
3513c6bd008Smiod AES_set_decrypt_key(rkey, 8*sizeof rkey, &key);
3523c6bd008Smiod AES_set_decrypt_key(rkey2, 8*sizeof rkey2, &key2);
3533c6bd008Smiod AES_ige_encrypt(ciphertext, checktext, sizeof checktext, &key, iv,
3543c6bd008Smiod AES_DECRYPT);
3553c6bd008Smiod
3563c6bd008Smiod matches=0;
3573c6bd008Smiod for(n=0 ; n < sizeof checktext ; ++n)
3583c6bd008Smiod if(checktext[n] == plaintext[n])
3593c6bd008Smiod ++matches;
3603c6bd008Smiod
3613c6bd008Smiod if(matches > sizeof checktext/100)
3623c6bd008Smiod {
3633c6bd008Smiod printf("More than 1%% matches after bidirectional garbling (3)\n");
3643c6bd008Smiod ++err;
3653c6bd008Smiod }
3663c6bd008Smiod
3673c6bd008Smiod err += run_test_vectors();
3683c6bd008Smiod
3693c6bd008Smiod return err;
3703c6bd008Smiod }
371