Skip to content

Commit 42e00d8

Browse files
dwsuseigaw
authored andcommitted
test: extend psk to test new 'versioned' API
Also test for nvme_{import|export}_tls_key_versioned API. Signed-off-by: Daniel Wagner <[email protected]>
1 parent 454373a commit 42e00d8

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

test/psk.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,80 @@ static void import_test(struct test_data *test)
133133
free(psk);
134134
}
135135

136+
static void export_versioned_test(struct test_data *test)
137+
{
138+
char *psk;
139+
140+
if (test->version != 1)
141+
return;
142+
143+
printf("test nvme_export_tls_key_versioned hmac %d %s\n",
144+
test->hmac, test->exported_psk);
145+
146+
psk = nvme_export_tls_key_versioned(test->version, test->hmac,
147+
test->configured_psk,
148+
test->psk_length);
149+
if (!psk) {
150+
test_rc = 1;
151+
printf("ERROR: nvme_export_tls_key_versioned() failed with %d\n",
152+
errno);
153+
return;
154+
}
155+
156+
check_str(test->exported_psk, psk);
157+
158+
free(psk);
159+
}
160+
161+
static void import_versioned_test(struct test_data *test)
162+
{
163+
unsigned char *psk;
164+
unsigned char version;
165+
unsigned char hmac;
166+
size_t psk_length;
167+
168+
if (test->version != 1)
169+
return;
170+
171+
printf("test nvme_import_tls_key_versioned hmac %d %s\n",
172+
test->hmac, test->exported_psk);
173+
174+
psk = nvme_import_tls_key_versioned(test->exported_psk, &version,
175+
&hmac, &psk_length);
176+
if (!psk) {
177+
test_rc = 1;
178+
printf("ERROR: nvme_import_tls_key_versioned() failed with %d\n",
179+
errno);
180+
return;
181+
}
182+
183+
if (test->version != version) {
184+
test_rc = 1;
185+
printf("ERROR: version parsing failed\n");
186+
goto out;
187+
}
188+
189+
if (test->hmac != hmac) {
190+
test_rc = 1;
191+
printf("ERROR: hmac parsing failed\n");
192+
goto out;
193+
}
194+
195+
if (test->psk_length != psk_length) {
196+
test_rc = 1;
197+
printf("ERROR: length parsing failed\n");
198+
goto out;
199+
}
200+
201+
if (memcmp(test->configured_psk, psk, psk_length)) {
202+
test_rc = 1;
203+
printf("ERROR: parsing psk failed\n");
204+
}
205+
206+
out:
207+
free(psk);
208+
}
209+
136210
int main(void)
137211
{
138212
for (int i = 0; i < ARRAY_SIZE(test_data); i++)
@@ -141,5 +215,11 @@ int main(void)
141215
for (int i = 0; i < ARRAY_SIZE(test_data); i++)
142216
import_test(&test_data[i]);
143217

218+
for (int i = 0; i < ARRAY_SIZE(test_data); i++)
219+
export_versioned_test(&test_data[i]);
220+
221+
for (int i = 0; i < ARRAY_SIZE(test_data); i++)
222+
import_versioned_test(&test_data[i]);
223+
144224
return test_rc ? EXIT_FAILURE : EXIT_SUCCESS;
145225
}

0 commit comments

Comments
 (0)