Add test program.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2022-06-17 20:28:25 +09:00
parent 52193bff0b
commit c2fc45bf58

971
misc/t-gcm-siv.c Normal file
View File

@ -0,0 +1,971 @@
/* test vectors from RFC8452 */
#include <stdint.h>
#include <string.h>
void
gcm_siv_encrypt (const uint8_t *key, const uint8_t *nonce,
const uint8_t *ad, int ad_len,
uint8_t *data, int data_len, uint8_t *tag);
int
gcm_siv_decrypt (const uint8_t *key, const uint8_t *nonce,
const uint8_t *ad, int ad_len,
uint8_t *data, int data_len, const uint8_t *tag);
#include <stdlib.h>
const uint8_t key0[] = {
0x01, 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
};
const uint8_t nonce0[] = {
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
const uint8_t tag_expected0[] = {
0x07, 0xf5, 0xf4, 0x16, 0x9b, 0xbf, 0x55, 0xa8,
0x40, 0x0c, 0xd4, 0x7e, 0xa6, 0xfd, 0x40, 0x0f
};
const uint8_t plaintext1[] = {
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const uint8_t ciphertext1[] = {
0xc2, 0xef, 0x32, 0x8e, 0x5c, 0x71, 0xc8, 0x3b
};
const uint8_t tag_expected1[] = {
0x84, 0x31, 0x22, 0x13, 0x0f, 0x73, 0x64, 0xb7,
0x61, 0xe0, 0xb9, 0x74, 0x27, 0xe3, 0xdf, 0x28
};
const uint8_t plaintext2[] = {
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
const uint8_t ciphertext2[] = {
0x9a, 0xab, 0x2a, 0xeb, 0x3f, 0xaa, 0x0a, 0x34,
0xae, 0xa8, 0xe2, 0xb1
};
const uint8_t tag_expected2[] = {
0x8c, 0xa5, 0x0d, 0xa9, 0xae, 0x65, 0x59, 0xe4,
0x8f, 0xd1, 0x0f, 0x6e, 0x5c, 0x9c, 0xa1, 0x7e
};
const uint8_t plaintext3[] = {
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const uint8_t ciphertext3[] = {
0x85, 0xa0, 0x1b, 0x63, 0x02, 0x5b, 0xa1, 0x9b,
0x7f, 0xd3, 0xdd, 0xfc, 0x03, 0x3b, 0x3e, 0x76
};
const uint8_t tag_expected3[] = {
0xc9, 0xea, 0xc6, 0xfa, 0x70, 0x09, 0x42, 0x70,
0x2e, 0x90, 0x86, 0x23, 0x83, 0xc6, 0xc3, 0x66
};
const uint8_t plaintext4[] = {
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const uint8_t ciphertext4[] = {
0x4a, 0x6a, 0x9d, 0xb4, 0xc8, 0xc6, 0x54, 0x92,
0x01, 0xb9, 0xed, 0xb5, 0x30, 0x06, 0xcb, 0xa8,
0x21, 0xec, 0x9c, 0xf8, 0x50, 0x94, 0x8a, 0x7c,
0x86, 0xc6, 0x8a, 0xc7, 0x53, 0x9d, 0x02, 0x7f
};
const uint8_t tag_expected4[] = {
0xe8, 0x19, 0xe6, 0x3a, 0xbc, 0xd0, 0x20, 0xb0,
0x06, 0xa9, 0x76, 0x39, 0x76, 0x32, 0xeb, 0x5d
};
const uint8_t plaintext5[] = {
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const uint8_t ciphertext5[] = {
0xc2, 0xd5, 0x16, 0x0a, 0x1f, 0x86, 0x83, 0x83,
0x49, 0x10, 0xac, 0xda, 0xfc, 0x41, 0xfb, 0xb1,
0x63, 0x2d, 0x4a, 0x35, 0x3e, 0x8b, 0x90, 0x5e,
0xc9, 0xa5, 0x49, 0x9a, 0xc3, 0x4f, 0x96, 0xc7,
0xe1, 0x04, 0x9e, 0xb0, 0x80, 0x88, 0x38, 0x91,
0xa4, 0xdb, 0x8c, 0xaa, 0xa1, 0xf9, 0x9d, 0xd0,
0x04, 0xd8, 0x04, 0x87, 0x54, 0x07, 0x35, 0x23,
0x4e, 0x37, 0x44, 0x51, 0x2c, 0x6f, 0x90, 0xce
};
const uint8_t tag_expected5[] = {
0x11, 0x28, 0x64, 0xc2, 0x69, 0xfc, 0x0d, 0x9d,
0x88, 0xc6, 0x1f, 0xa4, 0x7e, 0x39, 0xaa, 0x08
};
const uint8_t aad6[] = {
0x01
};
const uint8_t plaintext6[] = {
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const uint8_t ciphertext6[] = {
0x1d, 0xe2, 0x29, 0x67, 0x23, 0x7a, 0x81, 0x32
};
const uint8_t tag_expected6[] = {
0x91, 0x21, 0x3f, 0x26, 0x7e, 0x3b, 0x45, 0x2f,
0x02, 0xd0, 0x1a, 0xe3, 0x3e, 0x4e, 0xc8, 0x54
};
const uint8_t plaintext7[] = {
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
const uint8_t ciphertext7[] = {
0x16, 0x3d, 0x6f, 0x9c, 0xc1, 0xb3, 0x46, 0xcd,
0x45, 0x3a, 0x2e, 0x4c
};
const uint8_t tag_expected7[] = {
0xc1, 0xa4, 0xa1, 0x9a, 0xe8, 0x00, 0x94, 0x1c,
0xcd, 0xc5, 0x7c, 0xc8, 0x41, 0x3c, 0x27, 0x7f
};
const uint8_t plaintext8[] = {
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const uint8_t ciphertext8[] = {
0xc9, 0x15, 0x45, 0x82, 0x3c, 0xc2, 0x4f, 0x17,
0xdb, 0xb0, 0xe9, 0xe8, 0x07, 0xd5, 0xec, 0x17
};
const uint8_t tag_expected8[] = {
0xb2, 0x92, 0xd2, 0x8f, 0xf6, 0x11, 0x89, 0xe8,
0xe4, 0x9f, 0x38, 0x75, 0xef, 0x91, 0xaf, 0xf7
};
const uint8_t plaintext9[] = {
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const uint8_t ciphertext9[] = {
0x07, 0xda, 0xd3, 0x64, 0xbf, 0xc2, 0xb9, 0xda,
0x89, 0x11, 0x6d, 0x7b, 0xef, 0x6d, 0xaa, 0xaf,
0x6f, 0x25, 0x55, 0x10, 0xaa, 0x65, 0x4f, 0x92,
0x0a, 0xc8, 0x1b, 0x94, 0xe8, 0xba, 0xd3, 0x65
};
const uint8_t tag_expected9[] = {
0xae, 0xa1, 0xba, 0xd1, 0x27, 0x02, 0xe1, 0x96,
0x56, 0x04, 0x37, 0x4a, 0xab, 0x96, 0xdb, 0xbc
};
const uint8_t plaintextA[] = {
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const uint8_t ciphertextA[] = {
0xc6, 0x7a, 0x1f, 0x0f, 0x56, 0x7a, 0x51, 0x98,
0xaa, 0x1f, 0xcc, 0x8e, 0x3f, 0x21, 0x31, 0x43,
0x36, 0xf7, 0xf5, 0x1c, 0xa8, 0xb1, 0xaf, 0x61,
0xfe, 0xac, 0x35, 0xa8, 0x64, 0x16, 0xfa, 0x47,
0xfb, 0xca, 0x3b, 0x5f, 0x74, 0x9c, 0xdf, 0x56,
0x45, 0x27, 0xf2, 0x31, 0x4f, 0x42, 0xfe, 0x25
};
const uint8_t tag_expectedA[] = {
0x03, 0x33, 0x27, 0x42, 0xb2, 0x28, 0xc6, 0x47,
0x17, 0x36, 0x16, 0xcf, 0xd4, 0x4c, 0x54, 0xeb
};
const uint8_t plaintextB[] = {
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const uint8_t ciphertextB[] = {
0x67, 0xfd, 0x45, 0xe1, 0x26, 0xbf, 0xb9, 0xa7,
0x99, 0x30, 0xc4, 0x3a, 0xad, 0x2d, 0x36, 0x96,
0x7d, 0x3f, 0x0e, 0x4d, 0x21, 0x7c, 0x1e, 0x55,
0x1f, 0x59, 0x72, 0x78, 0x70, 0xbe, 0xef, 0xc9,
0x8c, 0xb9, 0x33, 0xa8, 0xfc, 0xe9, 0xde, 0x88,
0x7b, 0x1e, 0x40, 0x79, 0x99, 0x88, 0xdb, 0x1f,
0xc3, 0xf9, 0x18, 0x80, 0xed, 0x40, 0x5b, 0x2d,
0xd2, 0x98, 0x31, 0x88, 0x58, 0x46, 0x7c, 0x89
};
const uint8_t tag_expectedB[] = {
0x5b, 0xde, 0x02, 0x85, 0x03, 0x7c, 0x5d, 0xe8,
0x1e, 0x5b, 0x57, 0x0a, 0x04, 0x9b, 0x62, 0xa0
};
const uint8_t plaintextC[] = {
0x02, 0x00, 0x00, 0x00
};
const uint8_t aadC[] = {
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
const uint8_t ciphertextC[] = {
0x22, 0xb3, 0xf4, 0xcd
};
const uint8_t tag_expectedC[] = {
0x18, 0x35, 0xe5, 0x17, 0x74, 0x1d, 0xfd, 0xdc,
0xcf, 0xa0, 0x7f, 0xa4, 0x66, 0x1b, 0x74, 0xcf
};
const uint8_t plaintextD[] = {
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00
};
const uint8_t aadD[] = {
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02, 0x00
};
const uint8_t ciphertextD[] = {
0x43, 0xdd, 0x01, 0x63, 0xcd, 0xb4, 0x8f, 0x9f,
0xe3, 0x21, 0x2b, 0xf6, 0x1b, 0x20, 0x19, 0x76,
0x06, 0x7f, 0x34, 0x2b
};
const uint8_t tag_expectedD[] = {
0xb8, 0x79, 0xad, 0x97, 0x6d, 0x82, 0x42, 0xac,
0xc1, 0x88, 0xab, 0x59, 0xca, 0xbf, 0xe3, 0x07
};
const uint8_t plaintextE[] = {
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x04, 0x00
};
const uint8_t aadE[] = {
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00
};
const uint8_t ciphertextE[] = {
0x46, 0x24, 0x01, 0x72, 0x4b, 0x5c, 0xe6, 0x58,
0x8d, 0x5a, 0x54, 0xaa, 0xe5, 0x37, 0x55, 0x13,
0xa0, 0x75
};
const uint8_t tag_expectedE[] = {
0xcf, 0xcd, 0xf5, 0x04, 0x21, 0x12, 0xaa, 0x29,
0x68, 0x5c, 0x91, 0x2f, 0xc2, 0x05, 0x65, 0x43
};
const uint8_t key_0[] = {
0xe6, 0x60, 0x21, 0xd5, 0xeb, 0x8e, 0x4f, 0x40,
0x66, 0xd4, 0xad, 0xb9, 0xc3, 0x35, 0x60, 0xe4,
0xf4, 0x6e, 0x44, 0xbb, 0x3d, 0xa0, 0x01, 0x5c,
0x94, 0xf7, 0x08, 0x87, 0x36, 0x86, 0x42, 0x00
};
const uint8_t nonce_0[] = {
0xe0, 0xea, 0xf5, 0x28, 0x4d, 0x88, 0x4a, 0x0e,
0x77, 0xd3, 0x16, 0x46
};
const uint8_t tag_expected_0[] = {
0x16, 0x9f, 0xbb, 0x2f, 0xbf, 0x38, 0x9a, 0x99,
0x5f, 0x63, 0x90, 0xaf, 0x22, 0x22, 0x8a, 0x62
};
const uint8_t key_1[] = {
0xba, 0xe8, 0xe3, 0x7f, 0xc8, 0x34, 0x41, 0xb1,
0x60, 0x34, 0x56, 0x6b, 0x7a, 0x80, 0x6c, 0x46,
0xbb, 0x91, 0xc3, 0xc5, 0xae, 0xdb, 0x64, 0xa6,
0xc5, 0x90, 0xbc, 0x84, 0xd1, 0xa5, 0xe2, 0x69
};
const uint8_t nonce_1[] = {
0xe4, 0xb4, 0x78, 0x01, 0xaf, 0xc0, 0x57, 0x7e,
0x34, 0x69, 0x9b, 0x9e
};
const uint8_t plaintext_1[] = {
0x67, 0x1f, 0xdd
};
const uint8_t aad_1[] = {
0x4f, 0xbd, 0xc6, 0x6f, 0x14
};
const uint8_t ciphertext_1[] = {
0x0e, 0xac, 0xcb
};
const uint8_t tag_expected_1[] = {
0x93, 0xda, 0x9b, 0xb8, 0x13, 0x33, 0xae, 0xe0,
0xc7, 0x85, 0xb2, 0x40, 0xd3, 0x19, 0x71, 0x9d
};
const uint8_t key_2[] = {
0x65, 0x45, 0xfc, 0x88, 0x0c, 0x94, 0xa9, 0x51,
0x98, 0x87, 0x42, 0x96, 0xd5, 0xcc, 0x1f, 0xd1,
0x61, 0x32, 0x0b, 0x69, 0x20, 0xce, 0x07, 0x78,
0x7f, 0x86, 0x74, 0x3b, 0x27, 0x5d, 0x1a, 0xb3
};
const uint8_t nonce_2[] = {
0x2f, 0x6d, 0x1f, 0x04, 0x34, 0xd8, 0x84, 0x8c,
0x11, 0x77, 0x44, 0x1f
};
const uint8_t plaintext_2[] = {
0x19, 0x54, 0x95, 0x86, 0x0f, 0x04
};
const uint8_t aad_2[] = {
0x67, 0x87, 0xf3, 0xea, 0x22, 0xc1, 0x27, 0xaa,
0xf1, 0x95
};
const uint8_t ciphertext_2[] = {
0xa2, 0x54, 0xda, 0xd4, 0xf3, 0xf9
};
const uint8_t tag_expected_2[] = {
0x6b, 0x62, 0xb8, 0x4d, 0xc4, 0x0c, 0x84, 0x63,
0x6a, 0x5e, 0xc1, 0x20, 0x20, 0xec, 0x8c, 0x2c
};
const uint8_t key_3[] = {
0xd1, 0x89, 0x47, 0x28, 0xb3, 0xfe, 0xd1, 0x47,
0x3c, 0x52, 0x8b, 0x84, 0x26, 0xa5, 0x82, 0x99,
0x59, 0x29, 0xa1, 0x49, 0x9e, 0x9a, 0xd8, 0x78,
0x0c, 0x8d, 0x63, 0xd0, 0xab, 0x41, 0x49, 0xc0
};
const uint8_t nonce_3[] = {
0x9f, 0x57, 0x2c, 0x61, 0x4b, 0x47, 0x45, 0x91,
0x44, 0x74, 0xe7, 0xc7
};
const uint8_t plaintext_3[] = {
0xc9, 0x88, 0x2e, 0x53, 0x86, 0xfd, 0x9f, 0x92,
0xec
};
const uint8_t aad_3[] = {
0x48, 0x9c, 0x8f, 0xde, 0x2b, 0xe2, 0xcf, 0x97,
0xe7, 0x4e, 0x93, 0x2d, 0x4e, 0xd8, 0x7d
};
const uint8_t ciphertext_3[] = {
0x0d, 0xf9, 0xe3, 0x08, 0x67, 0x82, 0x44, 0xc4,
0x4b
};
const uint8_t tag_expected_3[] = {
0xc0, 0xfd, 0x3d, 0xc6, 0x62, 0x8d, 0xfe, 0x55,
0xeb, 0xb0, 0xb9, 0xfb, 0x22, 0x95, 0xc8, 0xc2
};
const uint8_t key_4[] = {
0xa4, 0x41, 0x02, 0x95, 0x2e, 0xf9, 0x4b, 0x02,
0xb8, 0x05, 0x24, 0x9b, 0xac, 0x80, 0xe6, 0xf6,
0x14, 0x55, 0xbf, 0xac, 0x83, 0x08, 0xa2, 0xd4,
0x0d, 0x8c, 0x84, 0x51, 0x17, 0x80, 0x82, 0x35
};
const uint8_t nonce_4[] = {
0x5c, 0x9e, 0x94, 0x0f, 0xea, 0x2f, 0x58, 0x29,
0x50, 0xa7, 0x0d, 0x5a
};
const uint8_t plaintext_4[] = {
0x1d, 0xb2, 0x31, 0x6f, 0xd5, 0x68, 0x37, 0x8d,
0xa1, 0x07, 0xb5, 0x2b
};
const uint8_t aad_4[] = {
0x0d, 0xa5, 0x52, 0x10, 0xcc, 0x1c, 0x1b, 0x0a,
0xbd, 0xe3, 0xb2, 0xf2, 0x04, 0xd1, 0xe9, 0xf8,
0xb0, 0x6b, 0xc4, 0x7f
};
const uint8_t ciphertext_4[] = {
0x8d, 0xbe, 0xb9, 0xf7, 0x25, 0x5b, 0xf5, 0x76,
0x9d, 0xd5, 0x66, 0x92,
};
const uint8_t tag_expected_4[] = {
0x40, 0x40, 0x99, 0xc2, 0x58, 0x7f, 0x64, 0x97,
0x9f, 0x21, 0x82, 0x67, 0x06, 0xd4, 0x97, 0xd5
};
const uint8_t key_5[] = {
0x97, 0x45, 0xb3, 0xd1, 0xae, 0x06, 0x55, 0x6f,
0xb6, 0xaa, 0x78, 0x90, 0xbe, 0xbc, 0x18, 0xfe,
0x6b, 0x3d, 0xb4, 0xda, 0x3d, 0x57, 0xaa, 0x94,
0x84, 0x2b, 0x98, 0x03, 0xa9, 0x6e, 0x07, 0xfb
};
const uint8_t nonce_5[] = {
0x6d, 0xe7, 0x18, 0x60, 0xf7, 0x62, 0xeb, 0xfb,
0xd0, 0x82, 0x84, 0xe4
};
const uint8_t plaintext_5[] = {
0x21, 0x70, 0x2d, 0xe0, 0xde, 0x18, 0xba, 0xa9,
0xc9, 0x59, 0x62, 0x91, 0xb0, 0x84, 0x66
};
const uint8_t aad_5[] = {
0xf3, 0x7d, 0xe2, 0x1c, 0x7f, 0xf9, 0x01, 0xcf,
0xe8, 0xa6, 0x96, 0x15, 0xa9, 0x3f, 0xdf, 0x7a,
0x98, 0xca, 0xd4, 0x81, 0x79, 0x62, 0x45, 0x70,
0x9f
};
const uint8_t ciphertext_5[] = {
0x79, 0x35, 0x76, 0xdf, 0xa5, 0xc0, 0xf8, 0x87,
0x29, 0xa7, 0xed, 0x3c, 0x2f, 0x1b, 0xff
};
const uint8_t tag_expected_5[] = {
0xb3, 0x08, 0x0d, 0x28, 0xf6, 0xeb, 0xb5, 0xd3,
0x64, 0x8c, 0xe9, 0x7b, 0xd5, 0xba, 0x67, 0xfd
};
const uint8_t key_6[] = {
0xb1, 0x88, 0x53, 0xf6, 0x8d, 0x83, 0x36, 0x40,
0xe4, 0x2a, 0x3c, 0x02, 0xc2, 0x5b, 0x64, 0x86,
0x9e, 0x14, 0x6d, 0x7b, 0x23, 0x39, 0x87, 0xbd,
0xdf, 0xc2, 0x40, 0x87, 0x1d, 0x75, 0x76, 0xf7
};
const uint8_t nonce_6[] = {
0x02, 0x8e, 0xc6, 0xeb, 0x5e, 0xa7, 0xe2, 0x98,
0x34, 0x2a, 0x94, 0xd4
};
const uint8_t plaintext_6[] = {
0xb2, 0x02, 0xb3, 0x70, 0xef, 0x97, 0x68, 0xec,
0x65, 0x61, 0xc4, 0xfe, 0x6b, 0x7e, 0x72, 0x96,
0xfa, 0x85
};
const uint8_t aad_6[] = {
0x9c, 0x21, 0x59, 0x05, 0x8b, 0x1f, 0x0f, 0xe9,
0x14, 0x33, 0xa5, 0xbd, 0xc2, 0x0e, 0x21, 0x4e,
0xab, 0x7f, 0xec, 0xef, 0x44, 0x54, 0xa1, 0x0e,
0xf0, 0x65, 0x7d, 0xf2, 0x1a, 0xc7
};
const uint8_t ciphertext_6[] = {
0x85, 0x7e, 0x16, 0xa6, 0x49, 0x15, 0xa7, 0x87,
0x63, 0x76, 0x87, 0xdb, 0x4a, 0x95, 0x19, 0x63,
0x5c, 0xdd
};
const uint8_t tag_expected_6[] = {
0x45, 0x4f, 0xc2, 0xa1, 0x54, 0xfe, 0xa9, 0x1f,
0x83, 0x63, 0xa3, 0x9f, 0xec, 0x7d, 0x0a, 0x49
};
const uint8_t key_7[] = {
0x3c, 0x53, 0x5d, 0xe1, 0x92, 0xea, 0xed, 0x38,
0x22, 0xa2, 0xfb, 0xbe, 0x2c, 0xa9, 0xdf, 0xc8,
0x82, 0x55, 0xe1, 0x4a, 0x66, 0x1b, 0x8a, 0xa8,
0x2c, 0xc5, 0x42, 0x36, 0x09, 0x3b, 0xbc, 0x23
};
const uint8_t nonce_7[] = {
0x68, 0x80, 0x89, 0xe5, 0x55, 0x40, 0xdb, 0x18,
0x72, 0x50, 0x4e, 0x1c
};
const uint8_t plaintext_7[] = {
0xce, 0xd5, 0x32, 0xce, 0x41, 0x59, 0xb0, 0x35,
0x27, 0x7d, 0x4d, 0xfb, 0xb7, 0xdb, 0x62, 0x96,
0x8b, 0x13, 0xcd, 0x4e, 0xec
};
const uint8_t aad_7[] = {
0x73, 0x43, 0x20, 0xcc, 0xc9, 0xd9, 0xbb, 0xbb,
0x19, 0xcb, 0x81, 0xb2, 0xaf, 0x4e, 0xcb, 0xc3,
0xe7, 0x28, 0x34, 0x32, 0x1f, 0x7a, 0xa0, 0xf7,
0x0b, 0x72, 0x82, 0xb4, 0xf3, 0x3d, 0xf2, 0x3f,
0x16, 0x75, 0x41
};
const uint8_t ciphertext_7[] = {
0x62, 0x66, 0x60, 0xc2, 0x6e, 0xa6, 0x61, 0x2f,
0xb1, 0x7a, 0xd9, 0x1e, 0x8e, 0x76, 0x76, 0x39,
0xed, 0xd6, 0xc9, 0xfa, 0xee
};
const uint8_t tag_expected_7[] = {
0x9d, 0x6c, 0x70, 0x29, 0x67, 0x5b, 0x89, 0xea,
0xf4, 0xba, 0x1d, 0xed, 0x1a, 0x28, 0x65, 0x94
};
const uint8_t key_cwt[] = {
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
};
const uint8_t nonce_cwt[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
const uint8_t plaintext_cwt0[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x4d, 0xb9, 0x23, 0xdc, 0x79, 0x3e, 0xe6, 0x49,
0x7c, 0x76, 0xdc, 0xc0, 0x3a, 0x98, 0xe1, 0x08
};
const uint8_t ciphertext_cwt0[] = {
0xf3, 0xf8, 0x0f, 0x2c, 0xf0, 0xcb, 0x2d, 0xd9,
0xc5, 0x98, 0x4f, 0xcd, 0xa9, 0x08, 0x45, 0x6c,
0xc5, 0x37, 0x70, 0x3b, 0x5b, 0xa7, 0x03, 0x24,
0xa6, 0x79, 0x3a, 0x7b, 0xf2, 0x18, 0xd3, 0xea
};
const uint8_t tag_expected_cwt0[] = {
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const uint8_t plaintext_cwt1[] = {
0xeb, 0x36, 0x40, 0x27, 0x7c, 0x7f, 0xfd, 0x13,
0x03, 0xc7, 0xa5, 0x42, 0xd0, 0x2d, 0x3e, 0x4c,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const uint8_t ciphertext_cwt1[] = {
0x18, 0xce, 0x4f, 0x0b, 0x8c, 0xb4, 0xd0, 0xca,
0xc6, 0x5f, 0xea, 0x8f, 0x79, 0x25, 0x7b, 0x20,
0x88, 0x8e, 0x53, 0xe7, 0x22, 0x99, 0xe5, 0x6d
};
const uint8_t tag_expected_cwt1[] = {
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
int
main (int argc, const char *argv[])
{
uint8_t data[64];
uint8_t ad[64];
uint8_t tag[16];
int data_len;
int ad_len;
int r;
memset (data, 0, sizeof data);
data_len = 0;
gcm_siv_encrypt (key0, nonce0,
NULL, 0,
data, data_len, tag);
if (memcmp (tag, tag_expected0, 16))
exit (1);
r = gcm_siv_decrypt (key0, nonce0,
NULL, 0,
data, data_len, tag);
if (!r)
exit (1);
memset (data, 0, sizeof data);
data_len = sizeof (plaintext1);
memcpy (data, plaintext1, data_len);
gcm_siv_encrypt (key0, nonce0,
NULL, 0,
data, data_len, tag);
if (memcmp (ciphertext1, data, data_len))
exit (1);
if (memcmp (tag, tag_expected1, 16))
exit (1);
r = gcm_siv_decrypt (key0, nonce0,
NULL, 0,
data, data_len, tag);
if (!r)
exit (1);
memset (data, 0, sizeof data);
data_len = sizeof (plaintext2);
memcpy (data, plaintext2, data_len);
gcm_siv_encrypt (key0, nonce0,
NULL, 0,
data, data_len, tag);
if (memcmp (ciphertext2, data, data_len))
exit (1);
if (memcmp (tag, tag_expected2, 16))
exit (1);
r = gcm_siv_decrypt (key0, nonce0,
NULL, 0,
data, data_len, tag);
if (!r)
exit (1);
memset (data, 0, sizeof data);
data_len = sizeof (plaintext3);
memcpy (data, plaintext3, data_len);
gcm_siv_encrypt (key0, nonce0,
NULL, 0,
data, data_len, tag);
if (memcmp (ciphertext3, data, data_len))
exit (1);
if (memcmp (tag, tag_expected3, 16))
exit (1);
r = gcm_siv_decrypt (key0, nonce0,
NULL, 0,
data, data_len, tag);
if (!r)
exit (1);
memset (data, 0, sizeof data);
data_len = sizeof (plaintext4);
memcpy (data, plaintext4, data_len);
gcm_siv_encrypt (key0, nonce0,
NULL, 0,
data, data_len, tag);
if (memcmp (ciphertext4, data, data_len))
exit (1);
if (memcmp (tag, tag_expected4, 16))
exit (1);
r = gcm_siv_decrypt (key0, nonce0,
NULL, 0,
data, data_len, tag);
if (!r)
exit (1);
memset (data, 0, sizeof data);
data_len = sizeof (plaintext5);
memcpy (data, plaintext5, data_len);
gcm_siv_encrypt (key0, nonce0,
NULL, 0,
data, data_len, tag);
if (memcmp (ciphertext5, data, data_len))
exit (1);
if (memcmp (tag, tag_expected5, 16))
exit (1);
r = gcm_siv_decrypt (key0, nonce0,
NULL, 0,
data, data_len, tag);
if (!r)
exit (1);
memset (data, 0, sizeof data);
data_len = sizeof (plaintext6);
memcpy (data, plaintext6, data_len);
memset (ad, 0, sizeof ad);
ad_len = sizeof (aad6);
memcpy (ad, aad6, ad_len);
gcm_siv_encrypt (key0, nonce0,
ad, ad_len,
data, data_len, tag);
if (memcmp (ciphertext6, data, data_len))
exit (1);
if (memcmp (tag, tag_expected6, 16))
exit (1);
r = gcm_siv_decrypt (key0, nonce0,
ad, ad_len,
data, data_len, tag);
if (!r)
exit (1);
memset (data, 0, sizeof data);
data_len = sizeof (plaintext7);
memcpy (data, plaintext7, data_len);
gcm_siv_encrypt (key0, nonce0,
ad, ad_len,
data, data_len, tag);
if (memcmp (ciphertext7, data, data_len))
exit (1);
if (memcmp (tag, tag_expected7, 16))
exit (1);
r = gcm_siv_decrypt (key0, nonce0,
ad, ad_len,
data, data_len, tag);
if (!r)
exit (1);
memset (data, 0, sizeof data);
data_len = sizeof (plaintext8);
memcpy (data, plaintext8, data_len);
gcm_siv_encrypt (key0, nonce0,
ad, ad_len,
data, data_len, tag);
if (memcmp (ciphertext8, data, data_len))
exit (1);
if (memcmp (tag, tag_expected8, 16))
exit (1);
r = gcm_siv_decrypt (key0, nonce0,
ad, ad_len,
data, data_len, tag);
if (!r)
exit (1);
memset (data, 0, sizeof data);
data_len = sizeof (plaintext9);
memcpy (data, plaintext9, data_len);
gcm_siv_encrypt (key0, nonce0,
ad, ad_len,
data, data_len, tag);
if (memcmp (ciphertext9, data, data_len))
exit (1);
if (memcmp (tag, tag_expected9, 16))
exit (1);
r = gcm_siv_decrypt (key0, nonce0,
ad, ad_len,
data, data_len, tag);
if (!r)
exit (1);
memset (data, 0, sizeof data);
data_len = sizeof (plaintextA);
memcpy (data, plaintextA, data_len);
gcm_siv_encrypt (key0, nonce0,
ad, ad_len,
data, data_len, tag);
if (memcmp (ciphertextA, data, data_len))
exit (1);
if (memcmp (tag, tag_expectedA, 16))
exit (1);
r = gcm_siv_decrypt (key0, nonce0,
ad, ad_len,
data, data_len, tag);
if (!r)
exit (1);
memset (data, 0, sizeof data);
data_len = sizeof (plaintextB);
memcpy (data, plaintextB, data_len);
gcm_siv_encrypt (key0, nonce0,
ad, ad_len,
data, data_len, tag);
if (memcmp (ciphertextB, data, data_len))
exit (1);
if (memcmp (tag, tag_expectedB, 16))
exit (1);
r = gcm_siv_decrypt (key0, nonce0,
ad, ad_len,
data, data_len, tag);
if (!r)
exit (1);
memset (data, 0, sizeof data);
data_len = sizeof (plaintextC);
memcpy (data, plaintextC, data_len);
memset (ad, 0, sizeof ad);
ad_len = sizeof (aadC);
memcpy (ad, aadC, ad_len);
gcm_siv_encrypt (key0, nonce0,
ad, ad_len,
data, data_len, tag);
if (memcmp (ciphertextC, data, data_len))
exit (1);
if (memcmp (tag, tag_expectedC, 16))
exit (1);
r = gcm_siv_decrypt (key0, nonce0,
ad, ad_len,
data, data_len, tag);
if (!r)
exit (1);
memset (data, 0, sizeof data);
data_len = sizeof (plaintextD);
memcpy (data, plaintextD, data_len);
memset (ad, 0, sizeof ad);
ad_len = sizeof (aadD);
memcpy (ad, aadD, ad_len);
gcm_siv_encrypt (key0, nonce0,
ad, ad_len,
data, data_len, tag);
if (memcmp (ciphertextD, data, data_len))
exit (1);
if (memcmp (tag, tag_expectedD, 16))
exit (1);
r = gcm_siv_decrypt (key0, nonce0,
ad, ad_len,
data, data_len, tag);
if (!r)
exit (1);
memset (data, 0, sizeof data);
data_len = sizeof (plaintextE);
memcpy (data, plaintextE, data_len);
memset (ad, 0, sizeof ad);
ad_len = sizeof (aadE);
memcpy (ad, aadE, ad_len);
gcm_siv_encrypt (key0, nonce0,
ad, ad_len,
data, data_len, tag);
if (memcmp (ciphertextE, data, data_len))
exit (1);
if (memcmp (tag, tag_expectedE, 16))
exit (1);
r = gcm_siv_decrypt (key0, nonce0,
ad, ad_len,
data, data_len, tag);
if (!r)
exit (1);
gcm_siv_encrypt (key_0, nonce_0,
NULL, 0,
NULL, 0, tag);
if (memcmp (tag, tag_expected_0, 16))
exit (1);
r = gcm_siv_decrypt (key_0, nonce_0,
NULL, 0,
NULL, 0, tag);
if (!r)
exit (1);
memset (data, 0, sizeof data);
data_len = sizeof (plaintext_1);
memcpy (data, plaintext_1, data_len);
memset (ad, 0, sizeof ad);
ad_len = sizeof (aad_1);
memcpy (ad, aad_1, ad_len);
gcm_siv_encrypt (key_1, nonce_1,
ad, ad_len,
data, data_len, tag);
if (memcmp (ciphertext_1, data, data_len))
exit (1);
if (memcmp (tag, tag_expected_1, 16))
exit (1);
r = gcm_siv_decrypt (key_1, nonce_1,
ad, ad_len,
data, data_len, tag);
if (!r)
exit (1);
memset (data, 0, sizeof data);
data_len = sizeof (plaintext_2);
memcpy (data, plaintext_2, data_len);
memset (ad, 0, sizeof ad);
ad_len = sizeof (aad_2);
memcpy (ad, aad_2, ad_len);
gcm_siv_encrypt (key_2, nonce_2,
ad, ad_len,
data, data_len, tag);
if (memcmp (ciphertext_2, data, data_len))
exit (1);
if (memcmp (tag, tag_expected_2, 16))
exit (1);
r = gcm_siv_decrypt (key_2, nonce_2,
ad, ad_len,
data, data_len, tag);
if (!r)
exit (1);
memset (data, 0, sizeof data);
data_len = sizeof (plaintext_3);
memcpy (data, plaintext_3, data_len);
memset (ad, 0, sizeof ad);
ad_len = sizeof (aad_3);
memcpy (ad, aad_3, ad_len);
gcm_siv_encrypt (key_3, nonce_3,
ad, ad_len,
data, data_len, tag);
if (memcmp (ciphertext_3, data, data_len))
exit (1);
if (memcmp (tag, tag_expected_3, 16))
exit (1);
r = gcm_siv_decrypt (key_3, nonce_3,
ad, ad_len,
data, data_len, tag);
if (!r)
exit (1);
memset (data, 0, sizeof data);
data_len = sizeof (plaintext_4);
memcpy (data, plaintext_4, data_len);
memset (ad, 0, sizeof ad);
ad_len = sizeof (aad_4);
memcpy (ad, aad_4, ad_len);
gcm_siv_encrypt (key_4, nonce_4,
ad, ad_len,
data, data_len, tag);
if (memcmp (ciphertext_4, data, data_len))
exit (1);
if (memcmp (tag, tag_expected_4, 16))
exit (1);
r = gcm_siv_decrypt (key_4, nonce_4,
ad, ad_len,
data, data_len, tag);
if (!r)
exit (1);
memset (data, 0, sizeof data);
data_len = sizeof (plaintext_5);
memcpy (data, plaintext_5, data_len);
memset (ad, 0, sizeof ad);
ad_len = sizeof (aad_5);
memcpy (ad, aad_5, ad_len);
gcm_siv_encrypt (key_5, nonce_5,
ad, ad_len,
data, data_len, tag);
if (memcmp (ciphertext_5, data, data_len))
exit (1);
if (memcmp (tag, tag_expected_5, 16))
exit (1);
r = gcm_siv_decrypt (key_5, nonce_5,
ad, ad_len,
data, data_len, tag);
if (!r)
exit (1);
memset (data, 0, sizeof data);
data_len = sizeof (plaintext_6);
memcpy (data, plaintext_6, data_len);
memset (ad, 0, sizeof ad);
ad_len = sizeof (aad_6);
memcpy (ad, aad_6, ad_len);
gcm_siv_encrypt (key_6, nonce_6,
ad, ad_len,
data, data_len, tag);
if (memcmp (ciphertext_6, data, data_len))
exit (1);
if (memcmp (tag, tag_expected_6, 16))
exit (1);
r = gcm_siv_decrypt (key_6, nonce_6,
ad, ad_len,
data, data_len, tag);
if (!r)
exit (1);
memset (data, 0, sizeof data);
data_len = sizeof (plaintext_7);
memcpy (data, plaintext_7, data_len);
memset (ad, 0, sizeof ad);
ad_len = sizeof (aad_7);
memcpy (ad, aad_7, ad_len);
gcm_siv_encrypt (key_7, nonce_7,
ad, ad_len,
data, data_len, tag);
if (memcmp (ciphertext_7, data, data_len))
exit (1);
if (memcmp (tag, tag_expected_7, 16))
exit (1);
r = gcm_siv_decrypt (key_7, nonce_7,
ad, ad_len,
data, data_len, tag);
if (!r)
exit (1);
memset (data, 0, sizeof data);
data_len = sizeof (plaintext_cwt0);
memcpy (data, plaintext_cwt0, data_len);
gcm_siv_encrypt (key_cwt, nonce_cwt,
NULL, 0,
data, data_len, tag);
if (memcmp (ciphertext_cwt0, data, data_len))
exit (1);
if (memcmp (tag, tag_expected_cwt0, 16))
exit (1);
r = gcm_siv_decrypt (key_cwt, nonce_cwt,
NULL, 0,
data, data_len, tag);
if (!r)
exit (1);
memset (data, 0, sizeof data);
data_len = sizeof (plaintext_cwt1);
memcpy (data, plaintext_cwt1, data_len);
gcm_siv_encrypt (key_cwt, nonce_cwt,
NULL, 0,
data, data_len, tag);
if (memcmp (ciphertext_cwt1, data, data_len))
exit (1);
if (memcmp (tag, tag_expected_cwt1, 16))
exit (1);
r = gcm_siv_decrypt (key_cwt, nonce_cwt,
NULL, 0,
data, data_len, tag);
if (!r)
exit (1);
exit (0);
}
/*
cc -Wall -g -c -I ../src t-gcm-siv.c \
&& cc -g -o t-gcm-siv t-gcm-siv.o ../src/build/aes.o ../src/build/gcm-siv.o
./t-gcm-siv && echo "OK"
*/