michael@0: /* michael@0: * aes_cbc.c michael@0: * michael@0: * AES Cipher Block Chaining Mode michael@0: * michael@0: * David A. McGrew michael@0: * Cisco Systems, Inc. michael@0: */ michael@0: michael@0: /* michael@0: * michael@0: * Copyright (c) 2001-2006, Cisco Systems, Inc. michael@0: * All rights reserved. michael@0: * michael@0: * Redistribution and use in source and binary forms, with or without michael@0: * modification, are permitted provided that the following conditions michael@0: * are met: michael@0: * michael@0: * Redistributions of source code must retain the above copyright michael@0: * notice, this list of conditions and the following disclaimer. michael@0: * michael@0: * Redistributions in binary form must reproduce the above michael@0: * copyright notice, this list of conditions and the following michael@0: * disclaimer in the documentation and/or other materials provided michael@0: * with the distribution. michael@0: * michael@0: * Neither the name of the Cisco Systems, Inc. nor the names of its michael@0: * contributors may be used to endorse or promote products derived michael@0: * from this software without specific prior written permission. michael@0: * michael@0: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT michael@0: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS michael@0: * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE michael@0: * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, michael@0: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES michael@0: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR michael@0: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) michael@0: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, michael@0: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) michael@0: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED michael@0: * OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: * michael@0: */ michael@0: michael@0: michael@0: #include "aes_cbc.h" michael@0: #include "alloc.h" michael@0: michael@0: debug_module_t mod_aes_cbc = { michael@0: 0, /* debugging is off by default */ michael@0: "aes cbc" /* printable module name */ michael@0: }; michael@0: michael@0: michael@0: michael@0: err_status_t michael@0: aes_cbc_alloc(cipher_t **c, int key_len) { michael@0: extern cipher_type_t aes_cbc; michael@0: uint8_t *pointer; michael@0: int tmp; michael@0: michael@0: debug_print(mod_aes_cbc, michael@0: "allocating cipher with key length %d", key_len); michael@0: michael@0: if (key_len != 16 && key_len != 24 && key_len != 32) michael@0: return err_status_bad_param; michael@0: michael@0: /* allocate memory a cipher of type aes_cbc */ michael@0: tmp = (sizeof(aes_cbc_ctx_t) + sizeof(cipher_t)); michael@0: pointer = (uint8_t*)crypto_alloc(tmp); michael@0: if (pointer == NULL) michael@0: return err_status_alloc_fail; michael@0: michael@0: /* set pointers */ michael@0: *c = (cipher_t *)pointer; michael@0: (*c)->type = &aes_cbc; michael@0: (*c)->state = pointer + sizeof(cipher_t); michael@0: michael@0: /* increment ref_count */ michael@0: aes_cbc.ref_count++; michael@0: michael@0: /* set key size */ michael@0: (*c)->key_len = key_len; michael@0: michael@0: return err_status_ok; michael@0: } michael@0: michael@0: err_status_t michael@0: aes_cbc_dealloc(cipher_t *c) { michael@0: extern cipher_type_t aes_cbc; michael@0: michael@0: /* zeroize entire state*/ michael@0: octet_string_set_to_zero((uint8_t *)c, michael@0: sizeof(aes_cbc_ctx_t) + sizeof(cipher_t)); michael@0: michael@0: /* free memory */ michael@0: crypto_free(c); michael@0: michael@0: /* decrement ref_count */ michael@0: aes_cbc.ref_count--; michael@0: michael@0: return err_status_ok; michael@0: } michael@0: michael@0: err_status_t michael@0: aes_cbc_context_init(aes_cbc_ctx_t *c, const uint8_t *key, int key_len, michael@0: cipher_direction_t dir) { michael@0: err_status_t status; michael@0: michael@0: debug_print(mod_aes_cbc, michael@0: "key: %s", octet_string_hex_string(key, key_len)); michael@0: michael@0: /* expand key for the appropriate direction */ michael@0: switch (dir) { michael@0: case (direction_encrypt): michael@0: status = aes_expand_encryption_key(key, key_len, &c->expanded_key); michael@0: if (status) michael@0: return status; michael@0: break; michael@0: case (direction_decrypt): michael@0: status = aes_expand_decryption_key(key, key_len, &c->expanded_key); michael@0: if (status) michael@0: return status; michael@0: break; michael@0: default: michael@0: return err_status_bad_param; michael@0: } michael@0: michael@0: michael@0: return err_status_ok; michael@0: } michael@0: michael@0: michael@0: err_status_t michael@0: aes_cbc_set_iv(aes_cbc_ctx_t *c, void *iv) { michael@0: int i; michael@0: /* v128_t *input = iv; */ michael@0: uint8_t *input = (uint8_t*) iv; michael@0: michael@0: /* set state and 'previous' block to iv */ michael@0: for (i=0; i < 16; i++) michael@0: c->previous.v8[i] = c->state.v8[i] = input[i]; michael@0: michael@0: debug_print(mod_aes_cbc, "setting iv: %s", v128_hex_string(&c->state)); michael@0: michael@0: return err_status_ok; michael@0: } michael@0: michael@0: err_status_t michael@0: aes_cbc_encrypt(aes_cbc_ctx_t *c, michael@0: unsigned char *data, michael@0: unsigned int *bytes_in_data) { michael@0: int i; michael@0: unsigned char *input = data; /* pointer to data being read */ michael@0: unsigned char *output = data; /* pointer to data being written */ michael@0: int bytes_to_encr = *bytes_in_data; michael@0: michael@0: /* michael@0: * verify that we're 16-octet aligned michael@0: */ michael@0: if (*bytes_in_data & 0xf) michael@0: return err_status_bad_param; michael@0: michael@0: /* michael@0: * note that we assume that the initialization vector has already michael@0: * been set, e.g. by calling aes_cbc_set_iv() michael@0: */ michael@0: debug_print(mod_aes_cbc, "iv: %s", michael@0: v128_hex_string(&c->state)); michael@0: michael@0: /* michael@0: * loop over plaintext blocks, exoring state into plaintext then michael@0: * encrypting and writing to output michael@0: */ michael@0: while (bytes_to_encr > 0) { michael@0: michael@0: /* exor plaintext into state */ michael@0: for (i=0; i < 16; i++) michael@0: c->state.v8[i] ^= *input++; michael@0: michael@0: debug_print(mod_aes_cbc, "inblock: %s", michael@0: v128_hex_string(&c->state)); michael@0: michael@0: aes_encrypt(&c->state, &c->expanded_key); michael@0: michael@0: debug_print(mod_aes_cbc, "outblock: %s", michael@0: v128_hex_string(&c->state)); michael@0: michael@0: /* copy ciphertext to output */ michael@0: for (i=0; i < 16; i++) michael@0: *output++ = c->state.v8[i]; michael@0: michael@0: bytes_to_encr -= 16; michael@0: } michael@0: michael@0: return err_status_ok; michael@0: } michael@0: michael@0: err_status_t michael@0: aes_cbc_decrypt(aes_cbc_ctx_t *c, michael@0: unsigned char *data, michael@0: unsigned int *bytes_in_data) { michael@0: int i; michael@0: v128_t state, previous; michael@0: unsigned char *input = data; /* pointer to data being read */ michael@0: unsigned char *output = data; /* pointer to data being written */ michael@0: int bytes_to_encr = *bytes_in_data; michael@0: uint8_t tmp; michael@0: michael@0: /* michael@0: * verify that we're 16-octet aligned michael@0: */ michael@0: if (*bytes_in_data & 0x0f) michael@0: return err_status_bad_param; michael@0: michael@0: /* set 'previous' block to iv*/ michael@0: for (i=0; i < 16; i++) { michael@0: previous.v8[i] = c->previous.v8[i]; michael@0: } michael@0: michael@0: debug_print(mod_aes_cbc, "iv: %s", michael@0: v128_hex_string(&previous)); michael@0: michael@0: /* michael@0: * loop over ciphertext blocks, decrypting then exoring with state michael@0: * then writing plaintext to output michael@0: */ michael@0: while (bytes_to_encr > 0) { michael@0: michael@0: /* set state to ciphertext input block */ michael@0: for (i=0; i < 16; i++) { michael@0: state.v8[i] = *input++; michael@0: } michael@0: michael@0: debug_print(mod_aes_cbc, "inblock: %s", michael@0: v128_hex_string(&state)); michael@0: michael@0: /* decrypt state */ michael@0: aes_decrypt(&state, &c->expanded_key); michael@0: michael@0: debug_print(mod_aes_cbc, "outblock: %s", michael@0: v128_hex_string(&state)); michael@0: michael@0: /* michael@0: * exor previous ciphertext block out of plaintext, and write new michael@0: * plaintext block to output, while copying old ciphertext block michael@0: * to the 'previous' block michael@0: */ michael@0: for (i=0; i < 16; i++) { michael@0: tmp = *output; michael@0: *output++ = state.v8[i] ^ previous.v8[i]; michael@0: previous.v8[i] = tmp; michael@0: } michael@0: michael@0: bytes_to_encr -= 16; michael@0: } michael@0: michael@0: return err_status_ok; michael@0: } michael@0: michael@0: michael@0: err_status_t michael@0: aes_cbc_nist_encrypt(aes_cbc_ctx_t *c, michael@0: unsigned char *data, michael@0: unsigned int *bytes_in_data) { michael@0: int i; michael@0: unsigned char *pad_start; michael@0: int num_pad_bytes; michael@0: err_status_t status; michael@0: michael@0: /* michael@0: * determine the number of padding bytes that we need to add - michael@0: * this value is always between 1 and 16, inclusive. michael@0: */ michael@0: num_pad_bytes = 16 - (*bytes_in_data & 0xf); michael@0: pad_start = data; michael@0: pad_start += *bytes_in_data; michael@0: *pad_start++ = 0xa0; michael@0: for (i=0; i < num_pad_bytes; i++) michael@0: *pad_start++ = 0x00; michael@0: michael@0: /* michael@0: * increment the data size michael@0: */ michael@0: *bytes_in_data += num_pad_bytes; michael@0: michael@0: /* michael@0: * now cbc encrypt the padded data michael@0: */ michael@0: status = aes_cbc_encrypt(c, data, bytes_in_data); michael@0: if (status) michael@0: return status; michael@0: michael@0: return err_status_ok; michael@0: } michael@0: michael@0: michael@0: err_status_t michael@0: aes_cbc_nist_decrypt(aes_cbc_ctx_t *c, michael@0: unsigned char *data, michael@0: unsigned int *bytes_in_data) { michael@0: unsigned char *pad_end; michael@0: int num_pad_bytes; michael@0: err_status_t status; michael@0: michael@0: /* michael@0: * cbc decrypt the padded data michael@0: */ michael@0: status = aes_cbc_decrypt(c, data, bytes_in_data); michael@0: if (status) michael@0: return status; michael@0: michael@0: /* michael@0: * determine the number of padding bytes in the decrypted plaintext michael@0: * - this value is always between 1 and 16, inclusive. michael@0: */ michael@0: num_pad_bytes = 1; michael@0: pad_end = data + (*bytes_in_data - 1); michael@0: while (*pad_end != 0xa0) { /* note: should check padding correctness */ michael@0: pad_end--; michael@0: num_pad_bytes++; michael@0: } michael@0: michael@0: /* decrement data size */ michael@0: *bytes_in_data -= num_pad_bytes; michael@0: michael@0: return err_status_ok; michael@0: } michael@0: michael@0: michael@0: char michael@0: aes_cbc_description[] = "aes cipher block chaining (cbc) mode"; michael@0: michael@0: /* michael@0: * Test case 0 is derived from FIPS 197 Appendix C; it uses an michael@0: * all-zero IV, so that the first block encryption matches the test michael@0: * case in that appendix. This property provides a check of the base michael@0: * AES encryption and decryption algorithms; if CBC fails on some michael@0: * particular platform, then you should print out AES intermediate michael@0: * data and compare with the detailed info provided in that appendix. michael@0: * michael@0: */ michael@0: michael@0: michael@0: uint8_t aes_cbc_test_case_0_key[16] = { michael@0: 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, michael@0: 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f michael@0: }; michael@0: michael@0: uint8_t aes_cbc_test_case_0_plaintext[64] = { michael@0: 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, michael@0: 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff michael@0: }; michael@0: michael@0: uint8_t aes_cbc_test_case_0_ciphertext[80] = { michael@0: 0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x04, 0x30, michael@0: 0xd8, 0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a, michael@0: 0x03, 0x35, 0xed, 0x27, 0x67, 0xf2, 0x6d, 0xf1, michael@0: 0x64, 0x83, 0x2e, 0x23, 0x44, 0x38, 0x70, 0x8b michael@0: michael@0: }; michael@0: michael@0: uint8_t aes_cbc_test_case_0_iv[16] = { michael@0: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, michael@0: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 michael@0: }; michael@0: michael@0: michael@0: cipher_test_case_t aes_cbc_test_case_0 = { michael@0: 16, /* octets in key */ michael@0: aes_cbc_test_case_0_key, /* key */ michael@0: aes_cbc_test_case_0_iv, /* initialization vector */ michael@0: 16, /* octets in plaintext */ michael@0: aes_cbc_test_case_0_plaintext, /* plaintext */ michael@0: 32, /* octets in ciphertext */ michael@0: aes_cbc_test_case_0_ciphertext, /* ciphertext */ michael@0: NULL /* pointer to next testcase */ michael@0: }; michael@0: michael@0: michael@0: /* michael@0: * this test case is taken directly from Appendix F.2 of NIST Special michael@0: * Publication SP 800-38A michael@0: */ michael@0: michael@0: uint8_t aes_cbc_test_case_1_key[16] = { michael@0: 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, michael@0: 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c, michael@0: }; michael@0: michael@0: uint8_t aes_cbc_test_case_1_plaintext[64] = { michael@0: 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, michael@0: 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, michael@0: 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, michael@0: 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51, michael@0: 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, michael@0: 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef, michael@0: 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, michael@0: 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 michael@0: }; michael@0: michael@0: uint8_t aes_cbc_test_case_1_ciphertext[80] = { michael@0: 0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46, michael@0: 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d, michael@0: 0x50, 0x86, 0xcb, 0x9b, 0x50, 0x72, 0x19, 0xee, michael@0: 0x95, 0xdb, 0x11, 0x3a, 0x91, 0x76, 0x78, 0xb2, michael@0: 0x73, 0xbe, 0xd6, 0xb8, 0xe3, 0xc1, 0x74, 0x3b, michael@0: 0x71, 0x16, 0xe6, 0x9e, 0x22, 0x22, 0x95, 0x16, michael@0: 0x3f, 0xf1, 0xca, 0xa1, 0x68, 0x1f, 0xac, 0x09, michael@0: 0x12, 0x0e, 0xca, 0x30, 0x75, 0x86, 0xe1, 0xa7, michael@0: 0x39, 0x34, 0x07, 0x03, 0x36, 0xd0, 0x77, 0x99, michael@0: 0xe0, 0xc4, 0x2f, 0xdd, 0xa8, 0xdf, 0x4c, 0xa3 michael@0: }; michael@0: michael@0: uint8_t aes_cbc_test_case_1_iv[16] = { michael@0: 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, michael@0: 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f michael@0: }; michael@0: michael@0: cipher_test_case_t aes_cbc_test_case_1 = { michael@0: 16, /* octets in key */ michael@0: aes_cbc_test_case_1_key, /* key */ michael@0: aes_cbc_test_case_1_iv, /* initialization vector */ michael@0: 64, /* octets in plaintext */ michael@0: aes_cbc_test_case_1_plaintext, /* plaintext */ michael@0: 80, /* octets in ciphertext */ michael@0: aes_cbc_test_case_1_ciphertext, /* ciphertext */ michael@0: &aes_cbc_test_case_0 /* pointer to next testcase */ michael@0: }; michael@0: michael@0: /* michael@0: * Test case 2 is like test case 0, but for 256-bit keys. (FIPS 197 michael@0: * appendix C.3). michael@0: */ michael@0: michael@0: michael@0: uint8_t aes_cbc_test_case_2_key[32] = { michael@0: 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, michael@0: 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, michael@0: 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, michael@0: 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f michael@0: }; michael@0: michael@0: uint8_t aes_cbc_test_case_2_plaintext[64] = { michael@0: 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, michael@0: 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff michael@0: }; michael@0: michael@0: uint8_t aes_cbc_test_case_2_ciphertext[80] = { michael@0: 0x8e, 0xa2, 0xb7, 0xca, 0x51, 0x67, 0x45, 0xbf, michael@0: 0xea, 0xfc, 0x49, 0x90, 0x4b, 0x49, 0x60, 0x89, michael@0: 0x72, 0x72, 0x6e, 0xe7, 0x71, 0x39, 0xbf, 0x11, michael@0: 0xe5, 0x40, 0xe2, 0x7c, 0x54, 0x65, 0x1d, 0xee michael@0: }; michael@0: michael@0: uint8_t aes_cbc_test_case_2_iv[16] = { michael@0: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, michael@0: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 michael@0: }; michael@0: michael@0: cipher_test_case_t aes_cbc_test_case_2 = { michael@0: 32, /* octets in key */ michael@0: aes_cbc_test_case_2_key, /* key */ michael@0: aes_cbc_test_case_2_iv, /* initialization vector */ michael@0: 16, /* octets in plaintext */ michael@0: aes_cbc_test_case_2_plaintext, /* plaintext */ michael@0: 32, /* octets in ciphertext */ michael@0: aes_cbc_test_case_2_ciphertext, /* ciphertext */ michael@0: &aes_cbc_test_case_1 /* pointer to next testcase */ michael@0: }; michael@0: michael@0: michael@0: /* michael@0: * this test case is taken directly from Appendix F.2 of NIST Special michael@0: * Publication SP 800-38A michael@0: */ michael@0: michael@0: uint8_t aes_cbc_test_case_3_key[32] = { michael@0: 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, michael@0: 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81, michael@0: 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7, michael@0: 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4 michael@0: }; michael@0: michael@0: uint8_t aes_cbc_test_case_3_plaintext[64] = { michael@0: 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, michael@0: 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, michael@0: 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, michael@0: 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51, michael@0: 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, michael@0: 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef, michael@0: 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, michael@0: 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 michael@0: }; michael@0: michael@0: uint8_t aes_cbc_test_case_3_ciphertext[80] = { michael@0: 0xf5, 0x8c, 0x4c, 0x04, 0xd6, 0xe5, 0xf1, 0xba, michael@0: 0x77, 0x9e, 0xab, 0xfb, 0x5f, 0x7b, 0xfb, 0xd6, michael@0: 0x9c, 0xfc, 0x4e, 0x96, 0x7e, 0xdb, 0x80, 0x8d, michael@0: 0x67, 0x9f, 0x77, 0x7b, 0xc6, 0x70, 0x2c, 0x7d, michael@0: 0x39, 0xf2, 0x33, 0x69, 0xa9, 0xd9, 0xba, 0xcf, michael@0: 0xa5, 0x30, 0xe2, 0x63, 0x04, 0x23, 0x14, 0x61, michael@0: 0xb2, 0xeb, 0x05, 0xe2, 0xc3, 0x9b, 0xe9, 0xfc, michael@0: 0xda, 0x6c, 0x19, 0x07, 0x8c, 0x6a, 0x9d, 0x1b, michael@0: 0xfb, 0x98, 0x20, 0x2c, 0x45, 0xb2, 0xe4, 0xa0, michael@0: 0x63, 0xc4, 0x68, 0xba, 0x84, 0x39, 0x16, 0x5a michael@0: }; michael@0: michael@0: uint8_t aes_cbc_test_case_3_iv[16] = { michael@0: 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, michael@0: 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f michael@0: }; michael@0: michael@0: cipher_test_case_t aes_cbc_test_case_3 = { michael@0: 32, /* octets in key */ michael@0: aes_cbc_test_case_3_key, /* key */ michael@0: aes_cbc_test_case_3_iv, /* initialization vector */ michael@0: 64, /* octets in plaintext */ michael@0: aes_cbc_test_case_3_plaintext, /* plaintext */ michael@0: 80, /* octets in ciphertext */ michael@0: aes_cbc_test_case_3_ciphertext, /* ciphertext */ michael@0: &aes_cbc_test_case_2 /* pointer to next testcase */ michael@0: }; michael@0: michael@0: cipher_type_t aes_cbc = { michael@0: (cipher_alloc_func_t) aes_cbc_alloc, michael@0: (cipher_dealloc_func_t) aes_cbc_dealloc, michael@0: (cipher_init_func_t) aes_cbc_context_init, michael@0: (cipher_encrypt_func_t) aes_cbc_nist_encrypt, michael@0: (cipher_decrypt_func_t) aes_cbc_nist_decrypt, michael@0: (cipher_set_iv_func_t) aes_cbc_set_iv, michael@0: (char *) aes_cbc_description, michael@0: (int) 0, /* instance count */ michael@0: (cipher_test_case_t *) &aes_cbc_test_case_3, michael@0: (debug_module_t *) &mod_aes_cbc, michael@0: (cipher_type_id_t) AES_CBC michael@0: }; michael@0: michael@0: