test_clear_aead.c revision 9a690580
1/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc. See LICENSE. */ 2/* 3 * See 4 * https://github.com/quicwg/base-drafts/wiki/Test-Vector-for-the-Clear-Text-AEAD-key-derivation 5 */ 6 7#include <assert.h> 8#include <string.h> 9 10#include <openssl/ssl.h> 11#include <openssl/hkdf.h> 12 13#include "lsquic_types.h" 14#include "lsquic_hkdf.h" 15 16int 17main (void) 18{ 19 const EVP_MD *const md = EVP_sha256(); 20 21 const lsquic_cid_t dcid = { 22 .idbuf = "\xc6\x54\xef\xd8\xa3\x1b\x47\x92", 23 .len = 8, 24 }; 25 unsigned char secret[100]; 26 size_t secret_len; 27 28 const unsigned char expected_secret[] = { 29 0x5f, 0x8d, 0xa5, 0x94, 0xfe, 0xca, 0x72, 0xc1, 30 0x0f, 0x9e, 0xc8, 0x78, 0x81, 0x11, 0x05, 0x57, 31 0x81, 0xa9, 0x6f, 0x6a, 0x06, 0x53, 0x58, 0xbf, 32 0xb4, 0x5a, 0xba, 0x4b, 0xc0, 0x37, 0xf3, 0xb2, 33 }; 34 35 HKDF_extract(secret, &secret_len, md, dcid.idbuf, dcid.len, 36 HSK_SALT, HSK_SALT_SZ); 37 38 assert(sizeof(expected_secret) == secret_len); 39 assert(0 == memcmp(secret, expected_secret, sizeof(expected_secret))); 40 41 unsigned char client_secret[32]; 42 const unsigned char expected_client_secret[] = { 43 0x0c, 0x74, 0xbb, 0x95, 0xa1, 0x04, 0x8e, 0x52, 44 0xef, 0x3b, 0x72, 0xe1, 0x28, 0x89, 0x35, 0x1c, 45 0xd7, 0x3a, 0x55, 0x0f, 0xb6, 0x2c, 0x4b, 0xb0, 46 0x87, 0xe9, 0x15, 0xcc, 0xe9, 0x6c, 0xe3, 0xa0, 47 }; 48 lsquic_qhkdf_expand(md, secret, secret_len, CLIENT_LABEL, CLIENT_LABEL_SZ, 49 client_secret, sizeof(client_secret)); 50 assert(0 == memcmp(client_secret, expected_client_secret, 51 sizeof(client_secret))); 52 const unsigned char expected_client_key[] = { 53 0x86, 0xd1, 0x83, 0x04, 0x80, 0xb4, 0x0f, 0x86, 54 0xcf, 0x9d, 0x68, 0xdc, 0xad, 0xf3, 0x5d, 0xfe, 55 }; 56 const unsigned char expected_client_iv[] = { 57 0x12, 0xf3, 0x93, 0x8a, 0xca, 0x34, 0xaa, 0x02, 58 0x54, 0x31, 0x63, 0xd4, 59 }; 60 const unsigned char expected_client_hp[] = { 61 0xcd, 0x25, 0x3a, 0x36, 0xff, 0x93, 0x93, 0x7c, 62 0x46, 0x93, 0x84, 0xa8, 0x23, 0xaf, 0x6c, 0x56, 63 }; 64 unsigned char client_key[sizeof(expected_client_key)], 65 client_iv[sizeof(expected_client_iv)], 66 client_hp[sizeof(expected_client_hp)]; 67 lsquic_qhkdf_expand(md, client_secret, sizeof(client_secret), "quic key", 8, 68 client_key, sizeof(client_key)); 69 assert(0 == memcmp(client_key, expected_client_key, 70 sizeof(expected_client_key))); 71 lsquic_qhkdf_expand(md, client_secret, sizeof(client_secret), "quic iv", 7, 72 client_iv, sizeof(client_iv)); 73 assert(0 == memcmp(client_iv, expected_client_iv, 74 sizeof(expected_client_iv))); 75 lsquic_qhkdf_expand(md, client_secret, sizeof(client_secret), "quic hp", 7, 76 client_hp, sizeof(client_hp)); 77 assert(0 == memcmp(client_hp, expected_client_hp, 78 sizeof(expected_client_hp))); 79 80 unsigned char server_secret[32]; 81 const unsigned char expected_server_secret[] = { 82 0x4c, 0x9e, 0xdf, 0x24, 0xb0, 0xe5, 0xe5, 0x06, 83 0xdd, 0x3b, 0xfa, 0x4e, 0x0a, 0x03, 0x11, 0xe8, 84 0xc4, 0x1f, 0x35, 0x42, 0x73, 0xd8, 0xcb, 0x49, 85 0xdd, 0xd8, 0x46, 0x41, 0x38, 0xd4, 0x7e, 0xc6, 86 }; 87 lsquic_qhkdf_expand(md, secret, secret_len, SERVER_LABEL, SERVER_LABEL_SZ, 88 server_secret, sizeof(server_secret)); 89 assert(0 == memcmp(server_secret, expected_server_secret, 90 sizeof(server_secret))); 91 const unsigned char expected_server_key[] = { 92 0x2c, 0x78, 0x63, 0x3e, 0x20, 0x6e, 0x99, 0xad, 93 0x25, 0x19, 0x64, 0xf1, 0x9f, 0x6d, 0xcd, 0x6d, 94 }; 95 const unsigned char expected_server_iv[] = { 96 0x7b, 0x50, 0xbf, 0x36, 0x98, 0xa0, 0x6d, 0xfa, 97 0xbf, 0x75, 0xf2, 0x87, 98 }; 99 const unsigned char expected_server_hp[] = { 100 0x25, 0x79, 0xd8, 0x69, 0x6f, 0x85, 0xed, 0xa6, 101 0x8d, 0x35, 0x02, 0xb6, 0x55, 0x96, 0x58, 0x6b, 102 }; 103 unsigned char server_key[sizeof(expected_server_key)], 104 server_iv[sizeof(expected_server_iv)], 105 server_hp[sizeof(expected_server_hp)]; 106 lsquic_qhkdf_expand(md, server_secret, sizeof(server_secret), "quic key", 8, 107 server_key, sizeof(server_key)); 108 assert(0 == memcmp(server_key, expected_server_key, 109 sizeof(expected_server_key))); 110 lsquic_qhkdf_expand(md, server_secret, sizeof(server_secret), "quic iv", 7, 111 server_iv, sizeof(server_iv)); 112 assert(0 == memcmp(server_iv, expected_server_iv, 113 sizeof(expected_server_iv))); 114 lsquic_qhkdf_expand(md, server_secret, sizeof(server_secret), "quic hp", 7, 115 server_hp, sizeof(server_hp)); 116 assert(0 == memcmp(server_hp, expected_server_hp, 117 sizeof(expected_server_hp))); 118 119 return 0; 120} 121