keys: provide key type and length

Save the type and length of each key and add a function to get this
information.
This commit is contained in:
Miroslav Lichvar
2020-05-13 13:45:03 +02:00
parent 11a5c7337a
commit f4ed2abdca
3 changed files with 32 additions and 10 deletions

View File

@@ -99,7 +99,7 @@ generate_key_file(const char *name, uint32_t *keys)
void
test_unit(void)
{
int i, j, data_len, auth_len;
int i, j, data_len, auth_len, type, bits;
uint32_t keys[KEYS], key;
unsigned char data[100], auth[MAX_HASH_LENGTH];
char conf[][100] = {
@@ -144,12 +144,16 @@ test_unit(void)
auth[auth_len - 1]++;
TEST_CHECK(!KEY_CheckAuth(keys[j], data, data_len, auth, auth_len, auth_len));
TEST_CHECK(KEY_GetKeyInfo(keys[j], &type, &bits));
TEST_CHECK(type > 0 && bits > 0);
}
for (j = 0; j < 1000; j++) {
UTI_GetRandomBytes(&key, sizeof (key));
if (KEY_KeyKnown(key))
continue;
TEST_CHECK(!KEY_GetKeyInfo(key, &type, &bits));
TEST_CHECK(!KEY_GenerateAuth(key, data, data_len, auth, sizeof (auth)));
TEST_CHECK(!KEY_CheckAuth(key, data, data_len, auth, auth_len, auth_len));
}