1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/tests/sys_crypto/tests-crypto-modes-ccm.c
2020-10-05 12:32:51 +02:00

1345 lines
52 KiB
C

/*
* Copyright (C) 2015 Nico von Geyso
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "embUnit.h"
#include "crypto/ciphers.h"
#include "crypto/modes/ccm.h"
#include "tests-crypto.h"
static const size_t nonce_and_len_encoding_size = 15;
/* RFC3610 Packet Vector #1 */
static const uint8_t TEST_RFC_1_KEY[] = {
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
};
static const size_t TEST_RFC_1_KEY_LEN = 16;
static const uint8_t TEST_RFC_1_NONCE[] = {
0x00, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00, 0xA0,
0xA1, 0xA2, 0xA3, 0xA4, 0xA5,
};
static const size_t TEST_RFC_1_NONCE_LEN = 13;
static const size_t TEST_RFC_1_MAC_LEN = 8;
static const uint8_t TEST_RFC_1_INPUT[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E,
};
static const size_t TEST_RFC_1_INPUT_LEN = 23;
static const size_t TEST_RFC_1_ADATA_LEN = 8;
static const uint8_t TEST_RFC_1_EXPECTED[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x58, 0x8C, 0x97, 0x9A, 0x61, 0xC6, 0x63, 0xD2,
0xF0, 0x66, 0xD0, 0xC2, 0xC0, 0xF9, 0x89, 0x80,
0x6D, 0x5F, 0x6B, 0x61, 0xDA, 0xC3, 0x84, 0x17,
0xE8, 0xD1, 0x2C, 0xFD, 0xF9, 0x26, 0xE0,
};
static const size_t TEST_RFC_1_EXPECTED_LEN = 39;
/* RFC3610 Packet Vector #2 */
static const uint8_t TEST_RFC_2_KEY[] = {
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
};
static const size_t TEST_RFC_2_KEY_LEN = 16;
static const uint8_t TEST_RFC_2_NONCE[] = {
0x00, 0x00, 0x00, 0x04, 0x03, 0x02, 0x01, 0xA0,
0xA1, 0xA2, 0xA3, 0xA4, 0xA5,
};
static const size_t TEST_RFC_2_NONCE_LEN = 13;
static const size_t TEST_RFC_2_MAC_LEN = 8;
static const uint8_t TEST_RFC_2_INPUT[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
};
static const size_t TEST_RFC_2_INPUT_LEN = 24;
static const size_t TEST_RFC_2_ADATA_LEN = 8;
static const uint8_t TEST_RFC_2_EXPECTED[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x72, 0xC9, 0x1A, 0x36, 0xE1, 0x35, 0xF8, 0xCF,
0x29, 0x1C, 0xA8, 0x94, 0x08, 0x5C, 0x87, 0xE3,
0xCC, 0x15, 0xC4, 0x39, 0xC9, 0xE4, 0x3A, 0x3B,
0xA0, 0x91, 0xD5, 0x6E, 0x10, 0x40, 0x09, 0x16,
};
static const size_t TEST_RFC_2_EXPECTED_LEN = 40;
/* RFC3610 Packet Vector #3 */
static const uint8_t TEST_RFC_3_KEY[] = {
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
};
static const size_t TEST_RFC_3_KEY_LEN = 16;
static const uint8_t TEST_RFC_3_NONCE[] = {
0x00, 0x00, 0x00, 0x05, 0x04, 0x03, 0x02, 0xA0,
0xA1, 0xA2, 0xA3, 0xA4, 0xA5,
};
static const size_t TEST_RFC_3_NONCE_LEN = 13;
static const size_t TEST_RFC_3_MAC_LEN = 8;
static const uint8_t TEST_RFC_3_INPUT[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0x20,
};
static const size_t TEST_RFC_3_INPUT_LEN = 25;
static const size_t TEST_RFC_3_ADATA_LEN = 8;
static const uint8_t TEST_RFC_3_EXPECTED[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x51, 0xB1, 0xE5, 0xF4, 0x4A, 0x19, 0x7D, 0x1D,
0xA4, 0x6B, 0x0F, 0x8E, 0x2D, 0x28, 0x2A, 0xE8,
0x71, 0xE8, 0x38, 0xBB, 0x64, 0xDA, 0x85, 0x96,
0x57, 0x4A, 0xDA, 0xA7, 0x6F, 0xBD, 0x9F, 0xB0,
0xC5,
};
static const size_t TEST_RFC_3_EXPECTED_LEN = 41;
/* RFC3610 Packet Vector #4 */
static const uint8_t TEST_RFC_4_KEY[] = {
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
};
static const uint8_t TEST_RFC_4_KEY_LEN = 16;
static const uint8_t TEST_RFC_4_NONCE[] = {
0x00, 0x00, 0x00, 0x06, 0x05, 0x04, 0x03, 0xA0,
0xA1, 0xA2, 0xA3, 0xA4, 0xA5,
};
static const uint8_t TEST_RFC_4_NONCE_LEN = 13;
static const uint8_t TEST_RFC_4_MAC_LEN = 8;
static const uint8_t TEST_RFC_4_INPUT[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E,
};
static const size_t TEST_RFC_4_INPUT_LEN = 19;
static const size_t TEST_RFC_4_ADATA_LEN = 12;
static const uint8_t TEST_RFC_4_EXPECTED[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0xA2, 0x8C, 0x68, 0x65,
0x93, 0x9A, 0x9A, 0x79, 0xFA, 0xAA, 0x5C, 0x4C,
0x2A, 0x9D, 0x4A, 0x91, 0xCD, 0xAC, 0x8C, 0x96,
0xC8, 0x61, 0xB9, 0xC9, 0xE6, 0x1E, 0xF1,
};
static const size_t TEST_RFC_4_EXPECTED_LEN = 39;
/* RFC3610 Packet Vector #5 */
static const uint8_t TEST_RFC_5_KEY[] = {
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
};
static const uint8_t TEST_RFC_5_KEY_LEN = 16;
static const uint8_t TEST_RFC_5_NONCE[] = {
0x00, 0x00, 0x00, 0x07, 0x06, 0x05, 0x04, 0xA0,
0xA1, 0xA2, 0xA3, 0xA4, 0xA5,
};
static const uint8_t TEST_RFC_5_NONCE_LEN = 13;
static const uint8_t TEST_RFC_5_MAC_LEN = 8;
static const uint8_t TEST_RFC_5_INPUT[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
};
static const size_t TEST_RFC_5_INPUT_LEN = 20;
static const size_t TEST_RFC_5_ADATA_LEN = 12;
static const uint8_t TEST_RFC_5_EXPECTED[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0xDC, 0xF1, 0xFB, 0x7B,
0x5D, 0x9E, 0x23, 0xFB, 0x9D, 0x4E, 0x13, 0x12,
0x53, 0x65, 0x8A, 0xD8, 0x6E, 0xBD, 0xCA, 0x3E,
0x51, 0xE8, 0x3F, 0x07, 0x7D, 0x9C, 0x2D, 0x93,
};
static const size_t TEST_RFC_5_EXPECTED_LEN = 40;
/* RFC3610 Packet Vector #6 */
static const uint8_t TEST_RFC_6_KEY[] = {
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
};
static const uint8_t TEST_RFC_6_KEY_LEN = 16;
static const uint8_t TEST_RFC_6_NONCE[] = {
0x00, 0x00, 0x00, 0x08, 0x07, 0x06, 0x05, 0xA0,
0xA1, 0xA2, 0xA3, 0xA4, 0xA5,
};
static const uint8_t TEST_RFC_6_NONCE_LEN = 13;
static const uint8_t TEST_RFC_6_MAC_LEN = 8;
static const uint8_t TEST_RFC_6_INPUT[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0x20,
};
static const size_t TEST_RFC_6_INPUT_LEN = 21;
static const size_t TEST_RFC_6_ADATA_LEN = 12;
static const uint8_t TEST_RFC_6_EXPECTED[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x6F, 0xC1, 0xB0, 0x11,
0xF0, 0x06, 0x56, 0x8B, 0x51, 0x71, 0xA4, 0x2D,
0x95, 0x3D, 0x46, 0x9B, 0x25, 0x70, 0xA4, 0xBD,
0x87, 0x40, 0x5A, 0x04, 0x43, 0xAC, 0x91, 0xCB,
0x94,
};
static const size_t TEST_RFC_6_EXPECTED_LEN = 41;
/* RFC3610 Packet Vector #7 */
static const uint8_t TEST_RFC_7_KEY[] = {
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
};
static const uint8_t TEST_RFC_7_KEY_LEN = 16;
static const uint8_t TEST_RFC_7_NONCE[] = {
0x00, 0x00, 0x00, 0x09, 0x08, 0x07, 0x06, 0xA0,
0xA1, 0xA2, 0xA3, 0xA4, 0xA5,
};
static const uint8_t TEST_RFC_7_NONCE_LEN = 13;
static const uint8_t TEST_RFC_7_MAC_LEN = 10;
static const uint8_t TEST_RFC_7_INPUT[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E,
};
static const size_t TEST_RFC_7_INPUT_LEN = 23;
static const size_t TEST_RFC_7_ADATA_LEN = 8;
static const uint8_t TEST_RFC_7_EXPECTED[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x01, 0x35, 0xD1, 0xB2, 0xC9, 0x5F, 0x41, 0xD5,
0xD1, 0xD4, 0xFE, 0xC1, 0x85, 0xD1, 0x66, 0xB8,
0x09, 0x4E, 0x99, 0x9D, 0xFE, 0xD9, 0x6C, 0x04,
0x8C, 0x56, 0x60, 0x2C, 0x97, 0xAC, 0xBB, 0x74,
0x90,
};
static const size_t TEST_RFC_7_EXPECTED_LEN = 41;
/* RFC3610 Packet Vector #8 */
static const uint8_t TEST_RFC_8_KEY[] = {
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
};
static const uint8_t TEST_RFC_8_KEY_LEN = 16;
static const uint8_t TEST_RFC_8_NONCE[] = {
0x00, 0x00, 0x00, 0x0A, 0x09, 0x08, 0x07, 0xA0,
0xA1, 0xA2, 0xA3, 0xA4, 0xA5,
};
static const uint8_t TEST_RFC_8_NONCE_LEN = 13;
static const uint8_t TEST_RFC_8_MAC_LEN = 10;
static const uint8_t TEST_RFC_8_INPUT[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
};
static const size_t TEST_RFC_8_INPUT_LEN = 24;
static const size_t TEST_RFC_8_ADATA_LEN = 8;
static const uint8_t TEST_RFC_8_EXPECTED[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x7B, 0x75, 0x39, 0x9A, 0xC0, 0x83, 0x1D, 0xD2,
0xF0, 0xBB, 0xD7, 0x58, 0x79, 0xA2, 0xFD, 0x8F,
0x6C, 0xAE, 0x6B, 0x6C, 0xD9, 0xB7, 0xDB, 0x24,
0xC1, 0x7B, 0x44, 0x33, 0xF4, 0x34, 0x96, 0x3F,
0x34, 0xB4,
};
static const size_t TEST_RFC_8_EXPECTED_LEN = 42;
/* RFC3610 Packet Vector #9 */
static const uint8_t TEST_RFC_9_KEY[] = {
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
};
static const uint8_t TEST_RFC_9_KEY_LEN = 16;
static const uint8_t TEST_RFC_9_NONCE[] = {
0x00, 0x00, 0x00, 0x0B, 0x0A, 0x09, 0x08, 0xA0,
0xA1, 0xA2, 0xA3, 0xA4, 0xA5,
};
static const uint8_t TEST_RFC_9_NONCE_LEN = 13;
static const uint8_t TEST_RFC_9_MAC_LEN = 10;
static const uint8_t TEST_RFC_9_INPUT[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0x20,
};
static const size_t TEST_RFC_9_INPUT_LEN = 25;
static const size_t TEST_RFC_9_ADATA_LEN = 8;
static const uint8_t TEST_RFC_9_EXPECTED[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x82, 0x53, 0x1A, 0x60, 0xCC, 0x24, 0x94, 0x5A,
0x4B, 0x82, 0x79, 0x18, 0x1A, 0xB5, 0xC8, 0x4D,
0xF2, 0x1C, 0xE7, 0xF9, 0xB7, 0x3F, 0x42, 0xE1,
0x97, 0xEA, 0x9C, 0x07, 0xE5, 0x6B, 0x5E, 0xB1,
0x7E, 0x5F, 0x4E,
};
static const size_t TEST_RFC_9_EXPECTED_LEN = 43;
/* RFC3610 Packet Vector #10 */
static const uint8_t TEST_RFC_10_KEY[] = {
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
};
static const uint8_t TEST_RFC_10_KEY_LEN = 16;
static const uint8_t TEST_RFC_10_NONCE[] = {
0x00, 0x00, 0x00, 0x0C, 0x0B, 0x0A, 0x09, 0xA0,
0xA1, 0xA2, 0xA3, 0xA4, 0xA5,
};
static const uint8_t TEST_RFC_10_NONCE_LEN = 13;
static const uint8_t TEST_RFC_10_MAC_LEN = 10;
static const uint8_t TEST_RFC_10_INPUT[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E,
};
static const size_t TEST_RFC_10_INPUT_LEN = 19;
static const size_t TEST_RFC_10_ADATA_LEN = 12;
static const uint8_t TEST_RFC_10_EXPECTED[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x07, 0x34, 0x25, 0x94,
0x15, 0x77, 0x85, 0x15, 0x2B, 0x07, 0x40, 0x98,
0x33, 0x0A, 0xBB, 0x14, 0x1B, 0x94, 0x7B, 0x56,
0x6A, 0xA9, 0x40, 0x6B, 0x4D, 0x99, 0x99, 0x88,
0xDD,
};
static const size_t TEST_RFC_10_EXPECTED_LEN = 41;
/* RFC3610 Packet Vector #11 */
static const uint8_t TEST_RFC_11_KEY[] = {
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
};
static const uint8_t TEST_RFC_11_KEY_LEN = 16;
static const uint8_t TEST_RFC_11_NONCE[] = {
0x00, 0x00, 0x00, 0x0D, 0x0C, 0x0B, 0x0A, 0xA0,
0xA1, 0xA2, 0xA3, 0xA4, 0xA5,
};
static const uint8_t TEST_RFC_11_NONCE_LEN = 13;
static const uint8_t TEST_RFC_11_MAC_LEN = 10;
static const uint8_t TEST_RFC_11_INPUT[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
};
static const size_t TEST_RFC_11_INPUT_LEN = 20;
static const size_t TEST_RFC_11_ADATA_LEN = 12;
static const uint8_t TEST_RFC_11_EXPECTED[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x67, 0x6B, 0xB2, 0x03,
0x80, 0xB0, 0xE3, 0x01, 0xE8, 0xAB, 0x79, 0x59,
0x0A, 0x39, 0x6D, 0xA7, 0x8B, 0x83, 0x49, 0x34,
0xF5, 0x3A, 0xA2, 0xE9, 0x10, 0x7A, 0x8B, 0x6C,
0x02, 0x2C,
};
static const size_t TEST_RFC_11_EXPECTED_LEN = 42;
/* RFC3610 Packet Vector #12 */
static const uint8_t TEST_RFC_12_KEY[] = {
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
};
static const uint8_t TEST_RFC_12_KEY_LEN = 16;
static const uint8_t TEST_RFC_12_NONCE[] = {
0x00, 0x00, 0x00, 0x0E, 0x0D, 0x0C, 0x0B, 0xA0,
0xA1, 0xA2, 0xA3, 0xA4, 0xA5,
};
static const uint8_t TEST_RFC_12_NONCE_LEN = 13;
static const uint8_t TEST_RFC_12_MAC_LEN = 10;
static const uint8_t TEST_RFC_12_INPUT[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0x20,
};
static const size_t TEST_RFC_12_INPUT_LEN = 21;
static const size_t TEST_RFC_12_ADATA_LEN = 12;
static const uint8_t TEST_RFC_12_EXPECTED[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0xC0, 0xFF, 0xA0, 0xD6,
0xF0, 0x5B, 0xDB, 0x67, 0xF2, 0x4D, 0x43, 0xA4,
0x33, 0x8D, 0x2A, 0xA4, 0xBE, 0xD7, 0xB2, 0x0E,
0x43, 0xCD, 0x1A, 0xA3, 0x16, 0x62, 0xE7, 0xAD,
0x65, 0xD6, 0xDB,
};
static const size_t TEST_RFC_12_EXPECTED_LEN = 43;
/* RFC3610 Packet Vector #13 */
static const uint8_t TEST_RFC_13_KEY[] = {
0xD7, 0x82, 0x8D, 0x13, 0xB2, 0xB0, 0xBD, 0xC3,
0x25, 0xA7, 0x62, 0x36, 0xDF, 0x93, 0xCC, 0x6B,
};
static const uint8_t TEST_RFC_13_KEY_LEN = 16;
static const uint8_t TEST_RFC_13_NONCE[] = {
0x00, 0x41, 0x2B, 0x4E, 0xA9, 0xCD, 0xBE, 0x3C,
0x96, 0x96, 0x76, 0x6C, 0xFA,
};
static const uint8_t TEST_RFC_13_NONCE_LEN = 13;
static const uint8_t TEST_RFC_13_MAC_LEN = 8;
static const uint8_t TEST_RFC_13_INPUT[] = {
0x0B, 0xE1, 0xA8, 0x8B, 0xAC, 0xE0, 0x18, 0xB1,
0x08, 0xE8, 0xCF, 0x97, 0xD8, 0x20, 0xEA, 0x25,
0x84, 0x60, 0xE9, 0x6A, 0xD9, 0xCF, 0x52, 0x89,
0x05, 0x4D, 0x89, 0x5C, 0xEA, 0xC4, 0x7C,
};
static const size_t TEST_RFC_13_INPUT_LEN = 23;
static const size_t TEST_RFC_13_ADATA_LEN = 8;
static const uint8_t TEST_RFC_13_EXPECTED[] = {
0x0B, 0xE1, 0xA8, 0x8B, 0xAC, 0xE0, 0x18, 0xB1,
0x4C, 0xB9, 0x7F, 0x86, 0xA2, 0xA4, 0x68, 0x9A,
0x87, 0x79, 0x47, 0xAB, 0x80, 0x91, 0xEF, 0x53,
0x86, 0xA6, 0xFF, 0xBD, 0xD0, 0x80, 0xF8, 0xE7,
0x8C, 0xF7, 0xCB, 0x0C, 0xDD, 0xD7, 0xB3,
};
static const size_t TEST_RFC_13_EXPECTED_LEN = 39;
/* RFC3610 Packet Vector #14 */
static const uint8_t TEST_RFC_14_KEY[] = {
0xD7, 0x82, 0x8D, 0x13, 0xB2, 0xB0, 0xBD, 0xC3,
0x25, 0xA7, 0x62, 0x36, 0xDF, 0x93, 0xCC, 0x6B,
};
static const uint8_t TEST_RFC_14_KEY_LEN = 16;
static const uint8_t TEST_RFC_14_NONCE[] = {
0x00, 0x33, 0x56, 0x8E, 0xF7, 0xB2, 0x63, 0x3C,
0x96, 0x96, 0x76, 0x6C, 0xFA,
};
static const uint8_t TEST_RFC_14_NONCE_LEN = 13;
static const uint8_t TEST_RFC_14_MAC_LEN = 8;
static const uint8_t TEST_RFC_14_INPUT[] = {
0x63, 0x01, 0x8F, 0x76, 0xDC, 0x8A, 0x1B, 0xCB,
0x90, 0x20, 0xEA, 0x6F, 0x91, 0xBD, 0xD8, 0x5A,
0xFA, 0x00, 0x39, 0xBA, 0x4B, 0xAF, 0xF9, 0xBF,
0xB7, 0x9C, 0x70, 0x28, 0x94, 0x9C, 0xD0, 0xEC,
};
static const size_t TEST_RFC_14_INPUT_LEN = 24;
static const size_t TEST_RFC_14_ADATA_LEN = 8;
static const uint8_t TEST_RFC_14_EXPECTED[] = {
0x63, 0x01, 0x8F, 0x76, 0xDC, 0x8A, 0x1B, 0xCB,
0x4C, 0xCB, 0x1E, 0x7C, 0xA9, 0x81, 0xBE, 0xFA,
0xA0, 0x72, 0x6C, 0x55, 0xD3, 0x78, 0x06, 0x12,
0x98, 0xC8, 0x5C, 0x92, 0x81, 0x4A, 0xBC, 0x33,
0xC5, 0x2E, 0xE8, 0x1D, 0x7D, 0x77, 0xC0, 0x8A,
};
static const size_t TEST_RFC_14_EXPECTED_LEN = 40;
/* RFC3610 Packet Vector #15 */
static const uint8_t TEST_RFC_15_KEY[] = {
0xD7, 0x82, 0x8D, 0x13, 0xB2, 0xB0, 0xBD, 0xC3,
0x25, 0xA7, 0x62, 0x36, 0xDF, 0x93, 0xCC, 0x6B,
};
static const uint8_t TEST_RFC_15_KEY_LEN = 16;
static const uint8_t TEST_RFC_15_NONCE[] = {
0x00, 0x10, 0x3F, 0xE4, 0x13, 0x36, 0x71, 0x3C,
0x96, 0x96, 0x76, 0x6C, 0xFA,
};
static const uint8_t TEST_RFC_15_NONCE_LEN = 13;
static const uint8_t TEST_RFC_15_MAC_LEN = 8;
static const uint8_t TEST_RFC_15_INPUT[] = {
0xAA, 0x6C, 0xFA, 0x36, 0xCA, 0xE8, 0x6B, 0x40,
0xB9, 0x16, 0xE0, 0xEA, 0xCC, 0x1C, 0x00, 0xD7,
0xDC, 0xEC, 0x68, 0xEC, 0x0B, 0x3B, 0xBB, 0x1A,
0x02, 0xDE, 0x8A, 0x2D, 0x1A, 0xA3, 0x46, 0x13,
0x2E,
};
static const size_t TEST_RFC_15_INPUT_LEN = 25;
static const size_t TEST_RFC_15_ADATA_LEN = 8;
static const uint8_t TEST_RFC_15_EXPECTED[] = {
0xAA, 0x6C, 0xFA, 0x36, 0xCA, 0xE8, 0x6B, 0x40,
0xB1, 0xD2, 0x3A, 0x22, 0x20, 0xDD, 0xC0, 0xAC,
0x90, 0x0D, 0x9A, 0xA0, 0x3C, 0x61, 0xFC, 0xF4,
0xA5, 0x59, 0xA4, 0x41, 0x77, 0x67, 0x08, 0x97,
0x08, 0xA7, 0x76, 0x79, 0x6E, 0xDB, 0x72, 0x35,
0x06,
};
static const size_t TEST_RFC_15_EXPECTED_LEN = 41;
/* RFC3610 Packet Vector #16 */
static const uint8_t TEST_RFC_16_KEY[] = {
0xD7, 0x82, 0x8D, 0x13, 0xB2, 0xB0, 0xBD, 0xC3,
0x25, 0xA7, 0x62, 0x36, 0xDF, 0x93, 0xCC, 0x6B,
};
static const uint8_t TEST_RFC_16_KEY_LEN = 16;
static const uint8_t TEST_RFC_16_NONCE[] = {
0x00, 0x76, 0x4C, 0x63, 0xB8, 0x05, 0x8E, 0x3C,
0x96, 0x96, 0x76, 0x6C, 0xFA,
};
static const uint8_t TEST_RFC_16_NONCE_LEN = 13;
static const uint8_t TEST_RFC_16_MAC_LEN = 8;
static const uint8_t TEST_RFC_16_INPUT[] = {
0xD0, 0xD0, 0x73, 0x5C, 0x53, 0x1E, 0x1B, 0xEC,
0xF0, 0x49, 0xC2, 0x44, 0x12, 0xDA, 0xAC, 0x56,
0x30, 0xEF, 0xA5, 0x39, 0x6F, 0x77, 0x0C, 0xE1,
0xA6, 0x6B, 0x21, 0xF7, 0xB2, 0x10, 0x1C,
};
static const size_t TEST_RFC_16_INPUT_LEN = 19;
static const size_t TEST_RFC_16_ADATA_LEN = 12;
static const uint8_t TEST_RFC_16_EXPECTED[] = {
0xD0, 0xD0, 0x73, 0x5C, 0x53, 0x1E, 0x1B, 0xEC,
0xF0, 0x49, 0xC2, 0x44, 0x14, 0xD2, 0x53, 0xC3,
0x96, 0x7B, 0x70, 0x60, 0x9B, 0x7C, 0xBB, 0x7C,
0x49, 0x91, 0x60, 0x28, 0x32, 0x45, 0x26, 0x9A,
0x6F, 0x49, 0x97, 0x5B, 0xCA, 0xDE, 0xAF,
};
static const size_t TEST_RFC_16_EXPECTED_LEN = 39;
/* RFC3610 Packet Vector #17 */
static const uint8_t TEST_RFC_17_KEY[] = {
0xD7, 0x82, 0x8D, 0x13, 0xB2, 0xB0, 0xBD, 0xC3,
0x25, 0xA7, 0x62, 0x36, 0xDF, 0x93, 0xCC, 0x6B,
};
static const uint8_t TEST_RFC_17_KEY_LEN = 16;
static const uint8_t TEST_RFC_17_NONCE[] = {
0x00, 0xF8, 0xB6, 0x78, 0x09, 0x4E, 0x3B, 0x3C,
0x96, 0x96, 0x76, 0x6C, 0xFA,
};
static const uint8_t TEST_RFC_17_NONCE_LEN = 13;
static const uint8_t TEST_RFC_17_MAC_LEN = 8;
static const uint8_t TEST_RFC_17_INPUT[] = {
0x77, 0xB6, 0x0F, 0x01, 0x1C, 0x03, 0xE1, 0x52,
0x58, 0x99, 0xBC, 0xAE, 0xE8, 0x8B, 0x6A, 0x46,
0xC7, 0x8D, 0x63, 0xE5, 0x2E, 0xB8, 0xC5, 0x46,
0xEF, 0xB5, 0xDE, 0x6F, 0x75, 0xE9, 0xCC, 0x0D,
};
static const size_t TEST_RFC_17_INPUT_LEN = 20;
static const size_t TEST_RFC_17_ADATA_LEN = 12;
static const uint8_t TEST_RFC_17_EXPECTED[] = {
0x77, 0xB6, 0x0F, 0x01, 0x1C, 0x03, 0xE1, 0x52,
0x58, 0x99, 0xBC, 0xAE, 0x55, 0x45, 0xFF, 0x1A,
0x08, 0x5E, 0xE2, 0xEF, 0xBF, 0x52, 0xB2, 0xE0,
0x4B, 0xEE, 0x1E, 0x23, 0x36, 0xC7, 0x3E, 0x3F,
0x76, 0x2C, 0x0C, 0x77, 0x44, 0xFE, 0x7E, 0x3C,
};
static const size_t TEST_RFC_17_EXPECTED_LEN = 40;
/* RFC3610 Packet Vector #18 */
static const uint8_t TEST_RFC_18_KEY[] = {
0xD7, 0x82, 0x8D, 0x13, 0xB2, 0xB0, 0xBD, 0xC3,
0x25, 0xA7, 0x62, 0x36, 0xDF, 0x93, 0xCC, 0x6B,
};
static const uint8_t TEST_RFC_18_KEY_LEN = 16;
static const uint8_t TEST_RFC_18_NONCE[] = {
0x00, 0xD5, 0x60, 0x91, 0x2D, 0x3F, 0x70, 0x3C,
0x96, 0x96, 0x76, 0x6C, 0xFA,
};
static const uint8_t TEST_RFC_18_NONCE_LEN = 13;
static const uint8_t TEST_RFC_18_MAC_LEN = 8;
static const uint8_t TEST_RFC_18_INPUT[] = {
0xCD, 0x90, 0x44, 0xD2, 0xB7, 0x1F, 0xDB, 0x81,
0x20, 0xEA, 0x60, 0xC0, 0x64, 0x35, 0xAC, 0xBA,
0xFB, 0x11, 0xA8, 0x2E, 0x2F, 0x07, 0x1D, 0x7C,
0xA4, 0xA5, 0xEB, 0xD9, 0x3A, 0x80, 0x3B, 0xA8,
0x7F,
};
static const size_t TEST_RFC_18_INPUT_LEN = 21;
static const size_t TEST_RFC_18_ADATA_LEN = 12;
static const uint8_t TEST_RFC_18_EXPECTED[] = {
0xCD, 0x90, 0x44, 0xD2, 0xB7, 0x1F, 0xDB, 0x81,
0x20, 0xEA, 0x60, 0xC0, 0x00, 0x97, 0x69, 0xEC,
0xAB, 0xDF, 0x48, 0x62, 0x55, 0x94, 0xC5, 0x92,
0x51, 0xE6, 0x03, 0x57, 0x22, 0x67, 0x5E, 0x04,
0xC8, 0x47, 0x09, 0x9E, 0x5A, 0xE0, 0x70, 0x45,
0x51,
};
static const size_t TEST_RFC_18_EXPECTED_LEN = 41;
/* RFC3610 Packet Vector #19 */
static const uint8_t TEST_RFC_19_KEY[] = {
0xD7, 0x82, 0x8D, 0x13, 0xB2, 0xB0, 0xBD, 0xC3,
0x25, 0xA7, 0x62, 0x36, 0xDF, 0x93, 0xCC, 0x6B,
};
static const uint8_t TEST_RFC_19_KEY_LEN = 16;
static const uint8_t TEST_RFC_19_NONCE[] = {
0x00, 0x42, 0xFF, 0xF8, 0xF1, 0x95, 0x1C, 0x3C,
0x96, 0x96, 0x76, 0x6C, 0xFA,
};
static const uint8_t TEST_RFC_19_NONCE_LEN = 13;
static const uint8_t TEST_RFC_19_MAC_LEN = 10;
static const uint8_t TEST_RFC_19_INPUT[] = {
0xD8, 0x5B, 0xC7, 0xE6, 0x9F, 0x94, 0x4F, 0xB8,
0x8A, 0x19, 0xB9, 0x50, 0xBC, 0xF7, 0x1A, 0x01,
0x8E, 0x5E, 0x67, 0x01, 0xC9, 0x17, 0x87, 0x65,
0x98, 0x09, 0xD6, 0x7D, 0xBE, 0xDD, 0x18,
};
static const size_t TEST_RFC_19_INPUT_LEN = 23;
static const size_t TEST_RFC_19_ADATA_LEN = 8;
static const uint8_t TEST_RFC_19_EXPECTED[] = {
0xD8, 0x5B, 0xC7, 0xE6, 0x9F, 0x94, 0x4F, 0xB8,
0xBC, 0x21, 0x8D, 0xAA, 0x94, 0x74, 0x27, 0xB6,
0xDB, 0x38, 0x6A, 0x99, 0xAC, 0x1A, 0xEF, 0x23,
0xAD, 0xE0, 0xB5, 0x29, 0x39, 0xCB, 0x6A, 0x63,
0x7C, 0xF9, 0xBE, 0xC2, 0x40, 0x88, 0x97, 0xC6,
0xBA,
};
static const size_t TEST_RFC_19_EXPECTED_LEN = 41;
/* RFC3610 Packet Vector #20 */
static const uint8_t TEST_RFC_20_KEY[] = {
0xD7, 0x82, 0x8D, 0x13, 0xB2, 0xB0, 0xBD, 0xC3,
0x25, 0xA7, 0x62, 0x36, 0xDF, 0x93, 0xCC, 0x6B,
};
static const uint8_t TEST_RFC_20_KEY_LEN = 16;
static const uint8_t TEST_RFC_20_NONCE[] = {
0x00, 0x92, 0x0F, 0x40, 0xE5, 0x6C, 0xDC, 0x3C,
0x96, 0x96, 0x76, 0x6C, 0xFA,
};
static const uint8_t TEST_RFC_20_NONCE_LEN = 13;
static const uint8_t TEST_RFC_20_MAC_LEN = 10;
static const uint8_t TEST_RFC_20_INPUT[] = {
0x74, 0xA0, 0xEB, 0xC9, 0x06, 0x9F, 0x5B, 0x37,
0x17, 0x61, 0x43, 0x3C, 0x37, 0xC5, 0xA3, 0x5F,
0xC1, 0xF3, 0x9F, 0x40, 0x63, 0x02, 0xEB, 0x90,
0x7C, 0x61, 0x63, 0xBE, 0x38, 0xC9, 0x84, 0x37,
};
static const size_t TEST_RFC_20_INPUT_LEN = 24;
static const size_t TEST_RFC_20_ADATA_LEN = 8;
static const uint8_t TEST_RFC_20_EXPECTED[] = {
0x74, 0xA0, 0xEB, 0xC9, 0x06, 0x9F, 0x5B, 0x37,
0x58, 0x10, 0xE6, 0xFD, 0x25, 0x87, 0x40, 0x22,
0xE8, 0x03, 0x61, 0xA4, 0x78, 0xE3, 0xE9, 0xCF,
0x48, 0x4A, 0xB0, 0x4F, 0x44, 0x7E, 0xFF, 0xF6,
0xF0, 0xA4, 0x77, 0xCC, 0x2F, 0xC9, 0xBF, 0x54,
0x89, 0x44,
};
static const size_t TEST_RFC_20_EXPECTED_LEN = 42;
/* RFC3610 Packet Vector #21 */
static const uint8_t TEST_RFC_21_KEY[] = {
0xD7, 0x82, 0x8D, 0x13, 0xB2, 0xB0, 0xBD, 0xC3,
0x25, 0xA7, 0x62, 0x36, 0xDF, 0x93, 0xCC, 0x6B,
};
static const uint8_t TEST_RFC_21_KEY_LEN = 16;
static const uint8_t TEST_RFC_21_NONCE[] = {
0x00, 0x27, 0xCA, 0x0C, 0x71, 0x20, 0xBC, 0x3C,
0x96, 0x96, 0x76, 0x6C, 0xFA,
};
static const uint8_t TEST_RFC_21_NONCE_LEN = 13;
static const uint8_t TEST_RFC_21_MAC_LEN = 10;
static const uint8_t TEST_RFC_21_INPUT[] = {
0x44, 0xA3, 0xAA, 0x3A, 0xAE, 0x64, 0x75, 0xCA,
0xA4, 0x34, 0xA8, 0xE5, 0x85, 0x00, 0xC6, 0xE4,
0x15, 0x30, 0x53, 0x88, 0x62, 0xD6, 0x86, 0xEA,
0x9E, 0x81, 0x30, 0x1B, 0x5A, 0xE4, 0x22, 0x6B,
0xFA,
};
static const size_t TEST_RFC_21_INPUT_LEN = 25;
static const size_t TEST_RFC_21_ADATA_LEN = 8;
static const uint8_t TEST_RFC_21_EXPECTED[] = {
0x44, 0xA3, 0xAA, 0x3A, 0xAE, 0x64, 0x75, 0xCA,
0xF2, 0xBE, 0xED, 0x7B, 0xC5, 0x09, 0x8E, 0x83,
0xFE, 0xB5, 0xB3, 0x16, 0x08, 0xF8, 0xE2, 0x9C,
0x38, 0x81, 0x9A, 0x89, 0xC8, 0xE7, 0x76, 0xF1,
0x54, 0x4D, 0x41, 0x51, 0xA4, 0xED, 0x3A, 0x8B,
0x87, 0xB9, 0xCE,
};
static const size_t TEST_RFC_21_EXPECTED_LEN = 43;
/* RFC3610 Packet Vector #22 */
static const uint8_t TEST_RFC_22_KEY[] = {
0xD7, 0x82, 0x8D, 0x13, 0xB2, 0xB0, 0xBD, 0xC3,
0x25, 0xA7, 0x62, 0x36, 0xDF, 0x93, 0xCC, 0x6B,
};
static const uint8_t TEST_RFC_22_KEY_LEN = 16;
static const uint8_t TEST_RFC_22_NONCE[] = {
0x00, 0x5B, 0x8C, 0xCB, 0xCD, 0x9A, 0xF8, 0x3C,
0x96, 0x96, 0x76, 0x6C, 0xFA,
};
static const uint8_t TEST_RFC_22_NONCE_LEN = 13;
static const uint8_t TEST_RFC_22_MAC_LEN = 10;
static const uint8_t TEST_RFC_22_INPUT[] = {
0xEC, 0x46, 0xBB, 0x63, 0xB0, 0x25, 0x20, 0xC3,
0x3C, 0x49, 0xFD, 0x70, 0xB9, 0x6B, 0x49, 0xE2,
0x1D, 0x62, 0x17, 0x41, 0x63, 0x28, 0x75, 0xDB,
0x7F, 0x6C, 0x92, 0x43, 0xD2, 0xD7, 0xC2,
};
static const size_t TEST_RFC_22_INPUT_LEN = 19;
static const size_t TEST_RFC_22_ADATA_LEN = 12;
static const uint8_t TEST_RFC_22_EXPECTED[] = {
0xEC, 0x46, 0xBB, 0x63, 0xB0, 0x25, 0x20, 0xC3,
0x3C, 0x49, 0xFD, 0x70, 0x31, 0xD7, 0x50, 0xA0,
0x9D, 0xA3, 0xED, 0x7F, 0xDD, 0xD4, 0x9A, 0x20,
0x32, 0xAA, 0xBF, 0x17, 0xEC, 0x8E, 0xBF, 0x7D,
0x22, 0xC8, 0x08, 0x8C, 0x66, 0x6B, 0xE5, 0xC1,
0x97,
};
static const size_t TEST_RFC_22_EXPECTED_LEN = 41;
/* RFC3610 Packet Vector #23 */
static const uint8_t TEST_RFC_23_KEY[] = {
0xD7, 0x82, 0x8D, 0x13, 0xB2, 0xB0, 0xBD, 0xC3,
0x25, 0xA7, 0x62, 0x36, 0xDF, 0x93, 0xCC, 0x6B,
};
static const uint8_t TEST_RFC_23_KEY_LEN = 16;
static const uint8_t TEST_RFC_23_NONCE[] = {
0x00, 0x3E, 0xBE, 0x94, 0x04, 0x4B, 0x9A, 0x3C,
0x96, 0x96, 0x76, 0x6C, 0xFA,
};
static const uint8_t TEST_RFC_23_NONCE_LEN = 13;
static const uint8_t TEST_RFC_23_MAC_LEN = 10;
static const uint8_t TEST_RFC_23_INPUT[] = {
0x47, 0xA6, 0x5A, 0xC7, 0x8B, 0x3D, 0x59, 0x42,
0x27, 0xE8, 0x5E, 0x71, 0xE2, 0xFC, 0xFB, 0xB8,
0x80, 0x44, 0x2C, 0x73, 0x1B, 0xF9, 0x51, 0x67,
0xC8, 0xFF, 0xD7, 0x89, 0x5E, 0x33, 0x70, 0x76,
};
static const size_t TEST_RFC_23_INPUT_LEN = 20;
static const size_t TEST_RFC_23_ADATA_LEN = 12;
static const uint8_t TEST_RFC_23_EXPECTED[] = {
0x47, 0xA6, 0x5A, 0xC7, 0x8B, 0x3D, 0x59, 0x42,
0x27, 0xE8, 0x5E, 0x71, 0xE8, 0x82, 0xF1, 0xDB,
0xD3, 0x8C, 0xE3, 0xED, 0xA7, 0xC2, 0x3F, 0x04,
0xDD, 0x65, 0x07, 0x1E, 0xB4, 0x13, 0x42, 0xAC,
0xDF, 0x7E, 0x00, 0xDC, 0xCE, 0xC7, 0xAE, 0x52,
0x98, 0x7D,
};
static const size_t TEST_RFC_23_EXPECTED_LEN = 42;
/* RFC3610 Packet Vector #24 */
static const uint8_t TEST_RFC_24_KEY[] = {
0xD7, 0x82, 0x8D, 0x13, 0xB2, 0xB0, 0xBD, 0xC3,
0x25, 0xA7, 0x62, 0x36, 0xDF, 0x93, 0xCC, 0x6B,
};
static const uint8_t TEST_RFC_24_KEY_LEN = 16;
static const uint8_t TEST_RFC_24_NONCE[] = {
0x00, 0x8D, 0x49, 0x3B, 0x30, 0xAE, 0x8B, 0x3C,
0x96, 0x96, 0x76, 0x6C, 0xFA,
};
static const uint8_t TEST_RFC_24_NONCE_LEN = 13;
static const uint8_t TEST_RFC_24_MAC_LEN = 10;
static const uint8_t TEST_RFC_24_INPUT[] = {
0x6E, 0x37, 0xA6, 0xEF, 0x54, 0x6D, 0x95, 0x5D,
0x34, 0xAB, 0x60, 0x59, 0xAB, 0xF2, 0x1C, 0x0B,
0x02, 0xFE, 0xB8, 0x8F, 0x85, 0x6D, 0xF4, 0xA3,
0x73, 0x81, 0xBC, 0xE3, 0xCC, 0x12, 0x85, 0x17,
0xD4,
};
static const size_t TEST_RFC_24_INPUT_LEN = 21;
static const size_t TEST_RFC_24_ADATA_LEN = 12;
static const uint8_t TEST_RFC_24_EXPECTED[] = {
0x6E, 0x37, 0xA6, 0xEF, 0x54, 0x6D, 0x95, 0x5D,
0x34, 0xAB, 0x60, 0x59, 0xF3, 0x29, 0x05, 0xB8,
0x8A, 0x64, 0x1B, 0x04, 0xB9, 0xC9, 0xFF, 0xB5,
0x8C, 0xC3, 0x90, 0x90, 0x0F, 0x3D, 0xA1, 0x2A,
0xB1, 0x6D, 0xCE, 0x9E, 0x82, 0xEF, 0xA1, 0x6D,
0xA6, 0x20, 0x59,
};
static const size_t TEST_RFC_24_EXPECTED_LEN = 43;
/* NIST SP 800-38C Appex C.1 */
static const uint8_t TEST_NIST_1_KEY[] = {
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
};
static const size_t TEST_NIST_1_KEY_LEN = 16;
static const uint8_t TEST_NIST_1_NONCE[] = {
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
};
static const size_t TEST_NIST_1_NONCE_LEN = 7;
static const size_t TEST_NIST_1_MAC_LEN = 4;
static const uint8_t TEST_NIST_1_INPUT[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x20, 0x21, 0x22, 0x23,
};
static const size_t TEST_NIST_1_INPUT_LEN = 4;
static const size_t TEST_NIST_1_ADATA_LEN = 8;
static const uint8_t TEST_NIST_1_EXPECTED[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x71, 0x62, 0x01, 0x5B, 0x4D, 0xAC, 0x25, 0x5D,
};
static const size_t TEST_NIST_1_EXPECTED_LEN = 16;
/* NIST SP 800-38C Appex C.2 */
static const uint8_t TEST_NIST_2_KEY[] = {
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
};
static const size_t TEST_NIST_2_KEY_LEN = 16;
static const uint8_t TEST_NIST_2_NONCE[] = {
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
};
static const size_t TEST_NIST_2_NONCE_LEN = 8;
static const size_t TEST_NIST_2_MAC_LEN = 6;
static const uint8_t TEST_NIST_2_INPUT[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
};
static const size_t TEST_NIST_2_INPUT_LEN = 16;
static const size_t TEST_NIST_2_ADATA_LEN = 16;
static const uint8_t TEST_NIST_2_EXPECTED[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0xD2, 0xA1, 0xF0, 0xE0, 0x51, 0xEA, 0x5F, 0x62,
0x08, 0x1A, 0x77, 0x92, 0x07, 0x3D, 0x59, 0x3D,
0x1F, 0xC6, 0x4F, 0xBF, 0xAC, 0xCD,
};
static const size_t TEST_NIST_2_EXPECTED_LEN = 38;
/* NIST SP 800-38C Appex C.3 */
static const uint8_t TEST_NIST_3_KEY[] = {
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
};
static const size_t TEST_NIST_3_KEY_LEN = 16;
static const uint8_t TEST_NIST_3_NONCE[] = {
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B,
};
static const size_t TEST_NIST_3_NONCE_LEN = 12;
static const size_t TEST_NIST_3_MAC_LEN = 8;
static const uint8_t TEST_NIST_3_INPUT[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x20, 0x21, 0x22, 0x23,
0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B,
0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33,
0x34, 0x35, 0x36, 0x37,
};
static const size_t TEST_NIST_3_INPUT_LEN = 24;
static const size_t TEST_NIST_3_ADATA_LEN = 20;
static const uint8_t TEST_NIST_3_EXPECTED[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0xE3, 0xB2, 0x01, 0xA9,
0xF5, 0xB7, 0x1A, 0x7A, 0x9B, 0x1C, 0xEA, 0xEC,
0xCD, 0x97, 0xE7, 0x0B, 0x61, 0x76, 0xAA, 0xD9,
0xA4, 0x42, 0x8A, 0xA5, 0x48, 0x43, 0x92, 0xFB,
0xC1, 0xB0, 0x99, 0x51,
};
static const size_t TEST_NIST_3_EXPECTED_LEN = 52;
/* Tests from Project Wycheproof */
/* See https://github.com/google/wycheproof/blob/master/testvectors/aes_ccm_test.json */
/* tcId" : 1 */
static const uint8_t TEST_WYCHEPROOF_1_KEY[] = {
0xbe, 0xdc, 0xfb, 0x5a, 0x01, 0x1e, 0xbc, 0x84,
0x60, 0x0f, 0xcb, 0x29, 0x6c, 0x15, 0xaf, 0x0d
};
static const size_t TEST_WYCHEPROOF_1_KEY_LEN = 16;
static const uint8_t TEST_WYCHEPROOF_1_NONCE[] = {
0x43, 0x8a, 0x54, 0x7a, 0x94, 0xea, 0x88, 0xdc,
0xe4, 0x6c, 0x6c, 0x85
};
static const size_t TEST_WYCHEPROOF_1_NONCE_LEN = 12;
static const size_t TEST_WYCHEPROOF_1_MAC_LEN = 16;
static const uint8_t TEST_WYCHEPROOF_1_INPUT[] = {
/* PLAINTEXT */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static const size_t TEST_WYCHEPROOF_1_INPUT_LEN = 0;
static const size_t TEST_WYCHEPROOF_1_ADATA_LEN = 0;
static const uint8_t TEST_WYCHEPROOF_1_EXPECTED[] = {
/* MAC */
0x25, 0xd1, 0xa3, 0x84, 0x95, 0xa7, 0xde, 0xa4,
0x5b, 0xda, 0x04, 0x97, 0x05, 0x62, 0x7d, 0x10
};
static const size_t TEST_WYCHEPROOF_1_EXPECTED_LEN = 16;
/* tcId" : 28 */
static const uint8_t TEST_WYCHEPROOF_28_KEY[] = {
0x20, 0xbb, 0xf7, 0x4c, 0x1e, 0x63, 0x98, 0x2c,
0x47, 0x2c, 0x47, 0x43, 0x56, 0x9e, 0x4c, 0x84,
};
static const size_t TEST_WYCHEPROOF_28_KEY_LEN = 16;
static const uint8_t TEST_WYCHEPROOF_28_NONCE[] = {
0x45, 0x9f, 0xc7, 0xc0, 0x04, 0xbf, 0x46, 0x32,
0x3a, 0x02, 0xd8, 0x46,
};
static const size_t TEST_WYCHEPROOF_28_NONCE_LEN = 12;
static const size_t TEST_WYCHEPROOF_28_MAC_LEN = 16;
static const uint8_t TEST_WYCHEPROOF_28_INPUT[] = {
/* AAD */
0x4f, 0x22, 0x85, 0xce, 0x3d, 0xaf, 0xa5, 0x28,
0xc6, 0x94, 0xa5, 0x27, 0x2d, 0x3b, 0x7b, 0x92,
0x90, 0x97, 0xdb, 0x39, 0x87, 0x72, 0x65, 0x3b,
0xd9, 0xbb, 0xbd, 0xb3, 0xb2, 0xc8, 0xe1,
/* PLAINTEXT */
0x6d, 0xb5, 0x09, 0x92, 0xe8, 0xfb, 0xbe, 0xe1,
0x5d, 0x49, 0x79, 0xd3, 0xe3, 0x22, 0xda, 0xcd,
};
static const size_t TEST_WYCHEPROOF_28_INPUT_LEN = 16;
static const size_t TEST_WYCHEPROOF_28_ADATA_LEN = 31;
static const uint8_t TEST_WYCHEPROOF_28_EXPECTED[] = {
/* AAD */
0x4f, 0x22, 0x85, 0xce, 0x3d, 0xaf, 0xa5, 0x28,
0xc6, 0x94, 0xa5, 0x27, 0x2d, 0x3b, 0x7b, 0x92,
0x90, 0x97, 0xdb, 0x39, 0x87, 0x72, 0x65, 0x3b,
0xd9, 0xbb, 0xbd, 0xb3, 0xb2, 0xc8, 0xe1,
/* CIPHERTEXT */
0x87, 0x03, 0xe4, 0x46, 0x97, 0x13, 0x8c, 0x58,
0x53, 0x2d, 0x97, 0xee, 0x99, 0x23, 0x1d, 0x94,
/* MAC */
0xf1, 0x4c, 0x2f, 0x39, 0xa4, 0x87, 0x1a, 0x4a,
0x16, 0xc4, 0x2f, 0x6f, 0xe8, 0x78, 0xde, 0xef,
};
static const size_t TEST_WYCHEPROOF_28_EXPECTED_LEN = 63;
/* Manually created test vectors */
/* This is necessary, because no test vectors are published with input length > 256 */
/* Data has been verified against BouncyCastle (.NET Core) and pycryptodome */
static const uint8_t TEST_MANUAL_01_KEY[] = {
0x6D, 0x64, 0x80, 0x02, 0x92, 0xE5, 0x60, 0xB5,
0xA4, 0x93, 0x1A, 0x80, 0xC4, 0x8F, 0x43, 0x41
};
static const size_t TEST_MANUAL_01_KEY_LEN = 16;
static const uint8_t TEST_MANUAL_01_NONCE[] = {
0xA0, 0x66, 0xFC, 0xC0, 0x9D, 0xD0, 0x1E, 0x6E,
0x2D, 0xF3, 0x26, 0x1A,
};
static const size_t TEST_MANUAL_01_NONCE_LEN = 12;
static const size_t TEST_MANUAL_01_MAC_LEN = 8;
static const uint8_t TEST_MANUAL_01_INPUT[] = {
/* AAD */
0x10, 0x25, 0x5F, 0xD5, 0xCE, 0x9C, 0xC6, 0xCD,
0x3B, 0x31, 0x21, 0xF5, 0x10, 0x26, 0x20, 0xFA,
0xE9, 0x7A, 0x52, 0x2D, 0x67, 0x4D, 0x8E, 0xD8,
0x4D, 0x0D, 0x85, 0x7C, 0xA3, 0xAD, 0x97, 0x28,
0xF9, 0x60, 0x8A, 0x8A, 0x67, 0x6D, 0xBC, 0x79,
/* PLAINTEXT */
0x6E, 0xA0, 0xA3, 0x0B, 0x80, 0x9A, 0x4A, 0x4E,
0xC1, 0x7F, 0xAB, 0x7E, 0x49, 0x64, 0x49, 0x7F,
0xA0, 0xE6, 0x70, 0x41, 0xDA, 0x16, 0x3D, 0x08,
0x70, 0x8E, 0xC4, 0x1B, 0xF1, 0x0E, 0xDA, 0xC8,
0xED, 0xA2, 0x35, 0xA2, 0xEE, 0x51, 0x62, 0x00,
0xEF, 0x8D, 0x5C, 0x5D, 0x83, 0xFA, 0xB6, 0xC8,
0xBC, 0xE4, 0x08, 0x78, 0xB6, 0x70, 0x0F, 0xE4,
0xC1, 0x70, 0x57, 0x31, 0x8D, 0x77, 0x43, 0x01,
0x55, 0x9E, 0x41, 0xAB, 0xE2, 0x6D, 0x37, 0x9A,
0x5B, 0x30, 0x25, 0xCC, 0xC4, 0x62, 0xCF, 0x91,
0x6B, 0xD2, 0x01, 0x7C, 0x05, 0xD7, 0x84, 0xAB,
0x0F, 0xB1, 0x2C, 0x73, 0x7B, 0xB0, 0x30, 0x44,
0xF5, 0x5E, 0x5D, 0x84, 0xF3, 0xB3, 0xBC, 0xFF,
0xCC, 0x44, 0x23, 0x29, 0xC0, 0xFA, 0x3C, 0xE3,
0x44, 0x64, 0x1E, 0x01, 0x8B, 0xD5, 0xBC, 0x8B,
0xCE, 0x6D, 0xB7, 0xC1, 0x5E, 0xDC, 0x99, 0x0F,
0x75, 0x01, 0xFE, 0xA4, 0x74, 0x0B, 0xE6, 0x37,
0xD5, 0x93, 0x58, 0x7B, 0x66, 0x53, 0x9F, 0x78,
0x89, 0xB9, 0x59, 0x9E, 0xB4, 0x55, 0xA5, 0x86,
0x03, 0x02, 0xDF, 0x8B, 0xB7, 0x8A, 0x02, 0xB7,
0x6E, 0x1D, 0xD2, 0xB0, 0x84, 0xB0, 0x02, 0xF8,
0x1C, 0xEA, 0x17, 0x4F, 0xF4, 0x22, 0x0C, 0xF4,
0x28, 0xFA, 0x8F, 0xA3, 0xE3, 0xDC, 0xB3, 0x9D,
0x53, 0xB9, 0x89, 0x59, 0x2D, 0x3A, 0xC7, 0xC7,
0x6D, 0xC9, 0x5E, 0x82, 0x3B, 0xFD, 0x90, 0x05,
0x5B, 0xFB, 0x51, 0xC1, 0x10, 0xE7, 0xF8, 0x82,
0x59, 0x23, 0x64, 0x96, 0x01, 0x6C, 0xD9, 0x64,
0xF9, 0xB9, 0xF2, 0x12, 0xBE, 0x30, 0x6C, 0x14,
0x76, 0x5A, 0x3C, 0xF1, 0x63, 0x71, 0x86, 0x8F,
0x29, 0x47, 0x8B, 0xB8, 0x6D, 0xA2, 0xE4, 0xF9,
0x29, 0x4E, 0x78, 0xD3, 0x66, 0xDC, 0xBA, 0xAD,
0x2B, 0xE0, 0xF7, 0x76, 0x08, 0xCF, 0x79, 0x2C,
0x5E, 0xC1, 0x9F, 0x67, 0x50, 0x2E, 0x96, 0x78,
0xBA, 0xD8, 0xC3, 0xD3, 0xEE, 0xEA,
};
static const size_t TEST_MANUAL_01_INPUT_LEN = 270;
static const size_t TEST_MANUAL_01_ADATA_LEN = 40;
static const uint8_t TEST_MANUAL_01_EXPECTED[] = {
/* AAD */
0x10, 0x25, 0x5F, 0xD5, 0xCE, 0x9C, 0xC6, 0xCD,
0x3B, 0x31, 0x21, 0xF5, 0x10, 0x26, 0x20, 0xFA,
0xE9, 0x7A, 0x52, 0x2D, 0x67, 0x4D, 0x8E, 0xD8,
0x4D, 0x0D, 0x85, 0x7C, 0xA3, 0xAD, 0x97, 0x28,
0xF9, 0x60, 0x8A, 0x8A, 0x67, 0x6D, 0xBC, 0x79,
/* CIPHERTEXT */
0x3B, 0x39, 0x41, 0x8A, 0xD8, 0xCF, 0x8D, 0xDD,
0xCD, 0x68, 0xE4, 0x61, 0xC5, 0x01, 0x1E, 0xD9,
0x16, 0x8A, 0xCC, 0x9C, 0xE8, 0x28, 0xBF, 0xC3,
0xBD, 0xF4, 0xFE, 0xFD, 0x4B, 0xDC, 0xC0, 0xAD,
0x56, 0xB5, 0x02, 0x65, 0x7D, 0x93, 0xA4, 0x00,
0x2A, 0x48, 0xD9, 0x4E, 0xC9, 0x2E, 0xF6, 0x30,
0x62, 0xBE, 0x50, 0x27, 0x81, 0x24, 0x5D, 0x04,
0xF5, 0x9B, 0x3C, 0x3C, 0xFB, 0xD1, 0x32, 0x67,
0x86, 0x5F, 0xDF, 0xD3, 0x1C, 0x53, 0xC8, 0x58,
0x86, 0xEA, 0xF5, 0x6A, 0x75, 0x43, 0x74, 0x3D,
0x15, 0x96, 0xB2, 0x54, 0x53, 0x28, 0xBC, 0xA2,
0x61, 0x9E, 0x5F, 0x68, 0xE4, 0xCD, 0x9E, 0x46,
0x6D, 0xDD, 0xA4, 0x82, 0x86, 0xFD, 0xD2, 0x67,
0x39, 0x2A, 0x71, 0x65, 0x7E, 0x5E, 0x0C, 0x8A,
0x64, 0xA2, 0xCD, 0x4A, 0x1F, 0x19, 0x49, 0xF4,
0xA7, 0xC5, 0x2B, 0x5D, 0xCC, 0xFD, 0x2F, 0xF4,
0xB5, 0x62, 0x20, 0xA4, 0xE4, 0x55, 0x03, 0xDE,
0x44, 0x7B, 0xD7, 0x2B, 0xD9, 0xAE, 0xED, 0x21,
0x3A, 0x16, 0xF4, 0x7E, 0xB3, 0xE1, 0xD1, 0x87,
0xD6, 0x89, 0xAA, 0x0C, 0x93, 0xCE, 0xEA, 0x0D,
0x9F, 0x24, 0xE2, 0xFD, 0x1D, 0x12, 0xF3, 0x5D,
0x7C, 0x95, 0xF4, 0x7A, 0xC5, 0x50, 0xD2, 0x04,
0xA4, 0x6F, 0xD0, 0xE8, 0xF0, 0x48, 0x01, 0xBC,
0xE1, 0x9E, 0x7A, 0xFB, 0xE2, 0xD8, 0xAB, 0xD8,
0xCD, 0x44, 0x7F, 0x3B, 0x16, 0xAE, 0xA5, 0xDF,
0xC4, 0x9A, 0xDF, 0xD5, 0xFF, 0xD2, 0x1F, 0xDA,
0x59, 0xEA, 0x71, 0x64, 0xCF, 0x55, 0x84, 0x90,
0xC2, 0x7E, 0xBD, 0x2C, 0x3A, 0xD2, 0x9F, 0x56,
0xC2, 0xE1, 0x25, 0x47, 0x31, 0x07, 0x8F, 0x53,
0xB7, 0x9A, 0xB7, 0x14, 0xA3, 0x81, 0x10, 0x97,
0xAB, 0x9B, 0x13, 0x7A, 0xAC, 0xED, 0xA9, 0x73,
0x10, 0x8F, 0xB3, 0xA3, 0x77, 0xBF, 0x3F, 0x9B,
0xB6, 0xB1, 0xAF, 0x07, 0xE5, 0xD1, 0x6E, 0x70,
0x66, 0x30, 0xAE, 0x4E, 0xFB, 0x56,
/* MAC */
0x2E, 0xB4, 0x86, 0xF7, 0x01, 0x6C, 0xD0, 0x6F
};
static const size_t TEST_MANUAL_01_EXPECTED_LEN = 318;
/* Test to check that the whole plaintext_len is written */
static const uint8_t TEST_CUSTOM_1_KEY[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static const uint8_t TEST_CUSTOM_1_KEY_LEN = 16;
static const uint8_t TEST_CUSTOM_1_NONCE[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00,
};
static const uint8_t TEST_CUSTOM_1_NONCE_LEN = 13;
static const uint8_t TEST_CUSTOM_1_MAC_LEN = 8;
static const uint8_t TEST_CUSTOM_1_INPUT[] = {
/* PLAINTEXT */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static const size_t TEST_CUSTOM_1_INPUT_LEN = 256;
static const size_t TEST_CUSTOM_1_ADATA_LEN = 0;
static const uint8_t TEST_CUSTOM_1_EXPECTED[] = {
/* CIPHERTEXT */
0xd5, 0x78, 0xf2, 0x0d, 0x00, 0x95, 0x8c, 0x6c,
0x50, 0x6e, 0x36, 0x76, 0x9e, 0xad, 0xce, 0x6e,
0x0a, 0x2d, 0xdc, 0xe6, 0x4b, 0x3d, 0x6c, 0x0d,
0xfa, 0x35, 0x3e, 0x43, 0x26, 0x37, 0x61, 0x58,
0x36, 0x2a, 0x23, 0xb1, 0x37, 0xe0, 0x3e, 0x6a,
0xa8, 0xcb, 0x51, 0x24, 0x6a, 0x2e, 0x8d, 0x2b,
0xcc, 0x9e, 0x8e, 0x75, 0xae, 0xfb, 0xc8, 0x4a,
0x59, 0xb9, 0x66, 0x06, 0xa0, 0xe4, 0xb7, 0xa7,
0x73, 0xa4, 0xa6, 0x9a, 0x90, 0x22, 0x15, 0x98,
0xb8, 0xe0, 0x94, 0x45, 0xa4, 0x5f, 0xd7, 0xae,
0x72, 0xc5, 0xe5, 0x51, 0x96, 0x6c, 0xd4, 0x0b,
0xed, 0x7e, 0x9a, 0x10, 0x7e, 0x78, 0x89, 0xf9,
0xea, 0xfe, 0x3a, 0xc6, 0x56, 0x8b, 0xdb, 0x45,
0x0f, 0x24, 0x4a, 0xa4, 0x7b, 0x48, 0x6b, 0x68,
0x67, 0x43, 0x7d, 0x2c, 0x06, 0x65, 0xe0, 0xb5,
0xd5, 0x65, 0x3f, 0xaf, 0xc7, 0x16, 0xfe, 0xb1,
0xc7, 0x0a, 0x57, 0x0d, 0xb9, 0xe7, 0xb8, 0xf6,
0x36, 0x72, 0xee, 0x15, 0x08, 0xd3, 0xa4, 0x81,
0x5c, 0xb4, 0x64, 0x8e, 0xee, 0xca, 0xdc, 0x4a,
0x9b, 0x01, 0x35, 0xbc, 0x33, 0xd2, 0x33, 0xee,
0x6d, 0x4a, 0x34, 0x82, 0x83, 0xe4, 0xbe, 0x55,
0x56, 0x69, 0x02, 0x76, 0x9f, 0xbf, 0x33, 0x9b,
0xfa, 0x52, 0xdb, 0x10, 0x1f, 0x49, 0xcd, 0x5d,
0xd6, 0xba, 0x4c, 0x7f, 0x33, 0x02, 0x23, 0x84,
0x5e, 0x4e, 0xd5, 0x58, 0xc4, 0xcc, 0x18, 0xf0,
0x3b, 0x36, 0xf8, 0x2f, 0xfa, 0x76, 0x4e, 0x39,
0x82, 0x5d, 0x4e, 0xbf, 0xbf, 0xda, 0x60, 0x8c,
0x88, 0x78, 0x34, 0xa3, 0x31, 0xb4, 0x97, 0xea,
0xf5, 0x4d, 0xeb, 0xb2, 0x40, 0x10, 0x85, 0x90,
0x6b, 0x7a, 0xc8, 0xad, 0x97, 0x7c, 0x02, 0xe6,
0x46, 0xfe, 0xd3, 0x16, 0x87, 0x87, 0xaf, 0x8e,
0x75, 0x26, 0xe7, 0x00, 0xe8, 0xcc, 0xcc, 0xaa,
/* MAC */
0xff, 0xc7, 0xef, 0x75, 0xa1, 0x4b, 0xa2, 0x25,
};
static const size_t TEST_CUSTOM_1_EXPECTED_LEN = 264;
/* Share test buffer output */
static uint8_t data[512];
static void test_encrypt_op(const uint8_t *key, uint8_t key_len,
const uint8_t *adata, size_t adata_len,
const uint8_t *nonce, uint8_t nonce_len,
const uint8_t *plain, size_t plain_len,
const uint8_t *output_expected,
size_t output_expected_len,
uint8_t mac_length)
{
cipher_t cipher;
int len, err, cmp;
size_t len_encoding = nonce_and_len_encoding_size - nonce_len;
TEST_ASSERT_MESSAGE(sizeof(data) >= output_expected_len,
"Output buffer too small");
err = cipher_init(&cipher, CIPHER_AES_128, key, key_len);
TEST_ASSERT_EQUAL_INT(1, err);
len = cipher_encrypt_ccm(&cipher, adata, adata_len,
mac_length, len_encoding,
nonce, nonce_len, plain, plain_len, data);
TEST_ASSERT_MESSAGE(len > 0, "Encryption failed");
TEST_ASSERT_EQUAL_INT(output_expected_len, len);
cmp = compare(output_expected, data, len);
TEST_ASSERT_MESSAGE(1 == cmp, "wrong ciphertext");
}
static void test_decrypt_op(const uint8_t *key, uint8_t key_len,
const uint8_t *adata, size_t adata_len,
const uint8_t *nonce, uint8_t nonce_len,
const uint8_t *encrypted, size_t encrypted_len,
const uint8_t *output_expected,
size_t output_expected_len,
uint8_t mac_length)
{
cipher_t cipher;
int len, err, cmp;
size_t len_encoding = nonce_and_len_encoding_size - nonce_len;
TEST_ASSERT_MESSAGE(sizeof(data) >= output_expected_len,
"Output buffer too small");
err = cipher_init(&cipher, CIPHER_AES_128, key, key_len);
TEST_ASSERT_EQUAL_INT(1, err);
len = cipher_decrypt_ccm(&cipher, adata, adata_len,
mac_length, len_encoding,
nonce, nonce_len, encrypted, encrypted_len, data);
TEST_ASSERT_MESSAGE(len >= 0, "Decryption failed");
TEST_ASSERT_EQUAL_INT(output_expected_len, len);
cmp = compare(output_expected, data, len);
TEST_ASSERT_MESSAGE(1 == cmp, "wrong ciphertext");
}
#define do_test_encrypt_op(name) do { \
test_encrypt_op(TEST_ ## name ## _KEY, TEST_ ## name ## _KEY_LEN, \
TEST_ ## name ## _INPUT, TEST_ ## name ## _ADATA_LEN, \
TEST_ ## name ## _NONCE, TEST_ ## name ## _NONCE_LEN, \
\
TEST_ ## name ## _INPUT + TEST_ ## name ## _ADATA_LEN, \
TEST_ ## name ## _INPUT_LEN, \
\
TEST_ ## name ## _EXPECTED + TEST_ ## name ## _ADATA_LEN, \
TEST_ ## name ## _EXPECTED_LEN - TEST_ ## name ## _ADATA_LEN, \
\
TEST_ ## name ## _MAC_LEN \
); \
} while (0)
static void test_crypto_modes_ccm_encrypt(void)
{
do_test_encrypt_op(RFC_1);
do_test_encrypt_op(RFC_2);
do_test_encrypt_op(RFC_3);
do_test_encrypt_op(RFC_4);
do_test_encrypt_op(RFC_5);
do_test_encrypt_op(RFC_6);
do_test_encrypt_op(RFC_7);
do_test_encrypt_op(RFC_8);
do_test_encrypt_op(RFC_9);
do_test_encrypt_op(RFC_10);
do_test_encrypt_op(RFC_11);
do_test_encrypt_op(RFC_12);
do_test_encrypt_op(RFC_13);
do_test_encrypt_op(RFC_14);
do_test_encrypt_op(RFC_15);
do_test_encrypt_op(RFC_16);
do_test_encrypt_op(RFC_17);
do_test_encrypt_op(RFC_18);
do_test_encrypt_op(RFC_19);
do_test_encrypt_op(RFC_20);
do_test_encrypt_op(RFC_21);
do_test_encrypt_op(RFC_22);
do_test_encrypt_op(RFC_23);
do_test_encrypt_op(RFC_24);
do_test_encrypt_op(NIST_1);
do_test_encrypt_op(NIST_2);
do_test_encrypt_op(NIST_3);
do_test_encrypt_op(WYCHEPROOF_1);
do_test_encrypt_op(WYCHEPROOF_28);
do_test_encrypt_op(MANUAL_01);
do_test_encrypt_op(CUSTOM_1);
}
#define do_test_decrypt_op(name) do { \
test_decrypt_op(TEST_ ## name ## _KEY, TEST_ ## name ## _KEY_LEN, \
TEST_ ## name ## _INPUT, TEST_ ## name ## _ADATA_LEN, \
TEST_ ## name ## _NONCE, TEST_ ## name ## _NONCE_LEN, \
\
TEST_ ## name ## _EXPECTED + TEST_ ## name ## _ADATA_LEN, \
TEST_ ## name ## _EXPECTED_LEN - TEST_ ## name ## _ADATA_LEN, \
\
TEST_ ## name ## _INPUT + TEST_ ## name ## _ADATA_LEN, \
TEST_ ## name ## _INPUT_LEN, \
\
TEST_ ## name ## _MAC_LEN \
); \
} while (0)
static void test_crypto_modes_ccm_decrypt(void)
{
do_test_decrypt_op(RFC_1);
do_test_decrypt_op(RFC_2);
do_test_decrypt_op(RFC_3);
do_test_decrypt_op(RFC_4);
do_test_decrypt_op(RFC_5);
do_test_decrypt_op(RFC_6);
do_test_decrypt_op(RFC_7);
do_test_decrypt_op(RFC_8);
do_test_decrypt_op(RFC_9);
do_test_decrypt_op(RFC_10);
do_test_decrypt_op(RFC_11);
do_test_decrypt_op(RFC_12);
do_test_decrypt_op(RFC_13);
do_test_decrypt_op(RFC_14);
do_test_decrypt_op(RFC_15);
do_test_decrypt_op(RFC_16);
do_test_decrypt_op(RFC_17);
do_test_decrypt_op(RFC_18);
do_test_decrypt_op(RFC_19);
do_test_decrypt_op(RFC_20);
do_test_decrypt_op(RFC_21);
do_test_decrypt_op(RFC_22);
do_test_decrypt_op(RFC_23);
do_test_decrypt_op(RFC_24);
do_test_decrypt_op(NIST_1);
do_test_decrypt_op(NIST_2);
do_test_decrypt_op(NIST_3);
do_test_decrypt_op(WYCHEPROOF_1);
do_test_decrypt_op(WYCHEPROOF_28);
do_test_decrypt_op(MANUAL_01);
do_test_decrypt_op(CUSTOM_1);
}
typedef int (*func_ccm_t)(const cipher_t *, const uint8_t *, uint32_t,
uint8_t, uint8_t, const uint8_t *, size_t,
const uint8_t *, size_t, uint8_t *);
static int _test_ccm_len(func_ccm_t func, uint8_t len_encoding,
const uint8_t *input, size_t input_len,
size_t adata_len)
{
int ret;
cipher_t cipher;
uint8_t mac_length = 8;
uint8_t nonce[15] = { 0 };
uint8_t key[16] = { 0 };
uint8_t nonce_len = nonce_and_len_encoding_size - len_encoding;
cipher_init(&cipher, CIPHER_AES_128, key, 16);
ret = func(&cipher, NULL, adata_len, mac_length, len_encoding,
nonce, nonce_len, input, input_len, data);
return ret;
}
/* Test length checking in ccm functions. */
static void test_crypto_modes_ccm_check_len(void)
{
int ret;
/* Using length_encoding above UINT16_MAX doesn't work on 8/16 bit
architectures, SIZE_MAX is equal to UINT16_MAX there */
#if SIZE_MAX > UINT16_MAX
/* Just 1 to big to fit */
ret = _test_ccm_len(cipher_encrypt_ccm, 2, NULL, 1 << 16, 0);
TEST_ASSERT_EQUAL_INT(CCM_ERR_INVALID_LENGTH_ENCODING, ret);
ret = _test_ccm_len(cipher_decrypt_ccm, 2, NULL, 1 << 16, 0);
TEST_ASSERT_EQUAL_INT(CCM_ERR_INVALID_LENGTH_ENCODING, ret);
/* adata_len should not change the result (was wrong in previous implem) */
ret = _test_ccm_len(cipher_encrypt_ccm, 2, NULL, 1 << 16, 65535);
TEST_ASSERT_EQUAL_INT(CCM_ERR_INVALID_LENGTH_ENCODING, ret);
ret = _test_ccm_len(cipher_decrypt_ccm, 2, NULL, 1 << 16, 65535);
TEST_ASSERT_EQUAL_INT(CCM_ERR_INVALID_LENGTH_ENCODING, ret);
#endif
/* Invalid length when length_encoding < 2 */
ret = _test_ccm_len(cipher_encrypt_ccm, 1, NULL, 8, 0);
TEST_ASSERT_EQUAL_INT(CCM_ERR_INVALID_LENGTH_ENCODING, ret);
/* Valid length that were wrongly checked */
/* Check should work with len_encoding >= 4, test with 8 */
uint8_t input[8];
ret = _test_ccm_len(cipher_encrypt_ccm, 8, input, 8, 0);
TEST_ASSERT_MESSAGE(ret > 0, "Encryption : failed with valid input_len");
/* einput is encrypted value for
* - 8 * 0 input
* - All 0 nonce and key
* - adata_len == 0
* - mac_len == 8 and len_encoding = 8
*/
uint8_t einput[16] = {
0xa2, 0x46, 0x75, 0xfc, 0x5f, 0x1b, 0x01, 0x37,
0x8a, 0x85, 0xd7, 0xf8, 0x42, 0x82, 0x6a, 0x63,
};
ret = _test_ccm_len(cipher_decrypt_ccm, 8, einput, 16, 0);
TEST_ASSERT_MESSAGE(ret > 0, "Decryption : failed with valid input_len");
/* ccm library does not support auth_data_len > 0xFEFF */
ret = _test_ccm_len(cipher_encrypt_ccm, 2, NULL, 0, 0xFEFF + 1);
TEST_ASSERT_EQUAL_INT(-1, ret);
}
Test *tests_crypto_modes_ccm_tests(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
new_TestFixture(test_crypto_modes_ccm_encrypt),
new_TestFixture(test_crypto_modes_ccm_decrypt),
new_TestFixture(test_crypto_modes_ccm_check_len),
};
EMB_UNIT_TESTCALLER(crypto_modes_ccm_tests, NULL, NULL, fixtures);
return (Test *)&crypto_modes_ccm_tests;
}