]>
Commit | Line | Data |
---|---|---|
36fc5fc6 SL |
1 | /* |
2 | * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. | |
3 | * | |
4 | * Licensed under the OpenSSL license (the "License"). You may not use | |
5 | * this file except in compliance with the License. You can obtain a copy | |
6 | * in the file LICENSE in the source distribution or at | |
7 | * https://www.openssl.org/source/license.html | |
8 | */ | |
9 | ||
10 | typedef struct st_kat_st { | |
11 | const char *desc; | |
12 | const char *algorithm; | |
13 | const unsigned char *pt; | |
14 | size_t pt_len; | |
15 | const unsigned char *expected; | |
16 | size_t expected_len; | |
17 | } ST_KAT; | |
18 | ||
19 | typedef ST_KAT ST_KAT_DIGEST; | |
20 | typedef struct st_kat_cipher_st { | |
21 | ST_KAT base; | |
22 | const unsigned char *key; | |
23 | size_t key_len; | |
24 | const unsigned char *iv; | |
25 | size_t iv_len; | |
26 | const unsigned char *aad; | |
27 | size_t aad_len; | |
28 | const unsigned char *tag; | |
29 | size_t tag_len; | |
30 | } ST_KAT_CIPHER; | |
31 | ||
32 | typedef struct st_kat_nvp_st { | |
33 | const char *name; | |
34 | const char *value; | |
35 | } ST_KAT_NVP; | |
36 | ||
37 | typedef struct st_kat_kdf_st { | |
38 | const char *desc; | |
39 | const char *algorithm; | |
40 | const ST_KAT_NVP *ctrls; | |
41 | const unsigned char *expected; | |
42 | size_t expected_len; | |
43 | } ST_KAT_KDF; | |
44 | ||
45 | /* Macros to build Self test data */ | |
46 | #define ITM(x) x, sizeof(x) | |
47 | #define ITM_STR(x) x, sizeof(x) - 1 | |
48 | ||
49 | /*- DIGEST TEST DATA */ | |
50 | static const unsigned char sha1_pt[] = "abc"; | |
51 | static const unsigned char sha1_digest[] = { | |
52 | 0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A, 0xBA, 0x3E, 0x25, 0x71, | |
53 | 0x78, 0x50, 0xC2, 0x6C, 0x9C, 0xD0, 0xD8, 0x9D | |
54 | }; | |
55 | ||
56 | static const unsigned char sha512_pt[] = "abc"; | |
57 | static const unsigned char sha512_digest[] = { | |
58 | 0xDD, 0xAF, 0x35, 0xA1, 0x93, 0x61, 0x7A, 0xBA, 0xCC, 0x41, 0x73, 0x49, | |
59 | 0xAE, 0x20, 0x41, 0x31, 0x12, 0xE6, 0xFA, 0x4E, 0x89, 0xA9, 0x7E, 0xA2, | |
60 | 0x0A, 0x9E, 0xEE, 0xE6, 0x4B, 0x55, 0xD3, 0x9A, 0x21, 0x92, 0x99, 0x2A, | |
61 | 0x27, 0x4F, 0xC1, 0xA8, 0x36, 0xBA, 0x3C, 0x23, 0xA3, 0xFE, 0xEB, 0xBD, | |
62 | 0x45, 0x4D, 0x44, 0x23, 0x64, 0x3C, 0xE8, 0x0E, 0x2A, 0x9A, 0xC9, 0x4F, | |
63 | 0xA5, 0x4C, 0xA4, 0x9F | |
64 | }; | |
65 | static const unsigned char sha3_256_pt[] = { 0xe7, 0x37, 0x21, 0x05 }; | |
66 | static const unsigned char sha3_256_digest[] = { | |
67 | 0x3a, 0x42, 0xb6, 0x8a, 0xb0, 0x79, 0xf2, 0x8c, 0x4c, 0xa3, 0xc7, 0x52, | |
68 | 0x29, 0x6f, 0x27, 0x90, 0x06, 0xc4, 0xfe, 0x78, 0xb1, 0xeb, 0x79, 0xd9, | |
69 | 0x89, 0x77, 0x7f, 0x05, 0x1e, 0x40, 0x46, 0xae | |
70 | }; | |
71 | ||
72 | static const ST_KAT_DIGEST st_kat_digest_tests[] = | |
73 | { | |
74 | { | |
75 | OSSL_SELF_TEST_DESC_MD_SHA1, | |
76 | "SHA1", | |
77 | ITM_STR(sha1_pt), | |
78 | ITM(sha1_digest), | |
79 | }, | |
80 | { | |
81 | OSSL_SELF_TEST_DESC_MD_SHA2, | |
82 | "SHA512", | |
83 | ITM_STR(sha512_pt), | |
84 | ITM(sha512_digest), | |
85 | }, | |
86 | { | |
87 | OSSL_SELF_TEST_DESC_MD_SHA3, | |
88 | "SHA3-256", | |
89 | ITM(sha3_256_pt), | |
90 | ITM(sha3_256_digest), | |
91 | }, | |
92 | }; | |
93 | ||
94 | ||
95 | /*- CIPHER TEST DATA */ | |
96 | ||
97 | /* DES3 test data */ | |
98 | static const unsigned char des_ede3_cbc_pt[] = { | |
99 | 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96, 0xE9, 0x3D, 0x7E, 0x11, | |
100 | 0x73, 0x93, 0x17, 0x2A, 0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C, | |
101 | 0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51 | |
102 | }; | |
103 | ||
104 | static const unsigned char des_ede3_cbc_key[] = { | |
105 | 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, | |
106 | 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, | |
107 | 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23 | |
108 | }; | |
109 | static const unsigned char des_ede3_cbc_iv[] = { | |
110 | 0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17 | |
111 | }; | |
112 | static const unsigned char des_ede3_cbc_ct[] = { | |
113 | 0x20, 0x79, 0xC3, 0xD5, 0x3A, 0xA7, 0x63, 0xE1, 0x93, 0xB7, 0x9E, 0x25, | |
114 | 0x69, 0xAB, 0x52, 0x62, 0x51, 0x65, 0x70, 0x48, 0x1F, 0x25, 0xB5, 0x0F, | |
115 | 0x73, 0xC0, 0xBD, 0xA8, 0x5C, 0x8E, 0x0D, 0xA7 | |
116 | }; | |
117 | ||
118 | static const unsigned char aes_256_gcm_key[] = { | |
119 | 0x92,0xe1,0x1d,0xcd,0xaa,0x86,0x6f,0x5c,0xe7,0x90,0xfd,0x24, | |
120 | 0x50,0x1f,0x92,0x50,0x9a,0xac,0xf4,0xcb,0x8b,0x13,0x39,0xd5, | |
121 | 0x0c,0x9c,0x12,0x40,0x93,0x5d,0xd0,0x8b | |
122 | }; | |
123 | static const unsigned char aes_256_gcm_iv[] = { | |
124 | 0xac,0x93,0xa1,0xa6,0x14,0x52,0x99,0xbd,0xe9,0x02,0xf2,0x1a | |
125 | }; | |
126 | static const unsigned char aes_256_gcm_pt[] = { | |
127 | 0x2d,0x71,0xbc,0xfa,0x91,0x4e,0x4a,0xc0,0x45,0xb2,0xaa,0x60, | |
128 | 0x95,0x5f,0xad,0x24 | |
129 | }; | |
130 | static const unsigned char aes_256_gcm_aad[] = { | |
131 | 0x1e,0x08,0x89,0x01,0x6f,0x67,0x60,0x1c,0x8e,0xbe,0xa4,0x94, | |
132 | 0x3b,0xc2,0x3a,0xd6 | |
133 | }; | |
134 | static const unsigned char aes_256_gcm_ct[] = { | |
135 | 0x89,0x95,0xae,0x2e,0x6d,0xf3,0xdb,0xf9,0x6f,0xac,0x7b,0x71, | |
136 | 0x37,0xba,0xe6,0x7f | |
137 | }; | |
138 | static const unsigned char aes_256_gcm_tag[] = { | |
139 | 0xec,0xa5,0xaa,0x77,0xd5,0x1d,0x4a,0x0a,0x14,0xd9,0xc5,0x1e, | |
140 | 0x1d,0xa4,0x74,0xab | |
141 | }; | |
142 | ||
143 | static const ST_KAT_CIPHER st_kat_cipher_tests[] = { | |
e89ffd23 | 144 | #ifndef OPENSSL_NO_DES |
36fc5fc6 SL |
145 | { |
146 | { | |
147 | OSSL_SELF_TEST_DESC_CIPHER_TDES, | |
148 | "DES-EDE3-CBC", | |
149 | ITM(des_ede3_cbc_pt), | |
150 | ITM(des_ede3_cbc_ct) | |
151 | }, | |
152 | ITM(des_ede3_cbc_key), | |
153 | ITM(des_ede3_cbc_iv), | |
154 | }, | |
e89ffd23 | 155 | #endif |
36fc5fc6 SL |
156 | { |
157 | { | |
158 | OSSL_SELF_TEST_DESC_CIPHER_AES_GCM, | |
159 | "AES-256-GCM", | |
160 | ITM(aes_256_gcm_pt), | |
161 | ITM(aes_256_gcm_ct), | |
162 | }, | |
163 | ITM(aes_256_gcm_key), | |
164 | ITM(aes_256_gcm_iv), | |
165 | ITM(aes_256_gcm_aad), | |
166 | ITM(aes_256_gcm_tag) | |
167 | } | |
168 | }; | |
169 | ||
170 | /*- KDF TEST DATA */ | |
171 | ||
172 | static const ST_KAT_NVP hkdf_ctrl[] = | |
173 | { | |
174 | { "digest", "SHA256" }, | |
175 | { "key", "secret" }, | |
176 | { "salt", "salt" }, | |
177 | { "info", "label" }, | |
178 | { NULL, NULL } | |
179 | }; | |
180 | static const unsigned char hkdf_expected[] = { | |
181 | 0x2a, 0xc4, 0x36, 0x9f, 0x52, 0x59, 0x96, 0xf8, 0xde, 0x13 | |
182 | }; | |
183 | ||
184 | static const ST_KAT_KDF st_kat_kdf_tests[] = | |
185 | { | |
186 | { | |
187 | OSSL_SELF_TEST_DESC_KDF_HKDF, | |
188 | "HKDF", | |
189 | hkdf_ctrl, | |
190 | ITM(hkdf_expected) | |
191 | } | |
192 | }; | |
193 |