Moved keymat key length lookup functions to keymat.c

This commit is contained in:
Martin Willi
2012-03-20 17:30:48 +01:00
parent d4f6686c69
commit 6cd72730bf
3 changed files with 75 additions and 55 deletions
+57
View File
@@ -31,3 +31,60 @@ keymat_t *keymat_create(ike_version_t version, bool initiator)
}
return NULL;
}
/**
* Implicit key length for an algorithm
*/
typedef struct {
/** IKEv2 algorithm identifier */
int alg;
/** key length in bits */
int len;
} keylen_entry_t;
/**
* See header.
*/
int keymat_get_keylen_encr(encryption_algorithm_t alg)
{
keylen_entry_t map[] = {
{ENCR_DES, 64},
{ENCR_3DES, 192},
};
int i;
for (i = 0; i < countof(map); i++)
{
if (map[i].alg == alg)
{
return map[i].len;
}
}
return 0;
}
/**
* See header.
*/
int keymat_get_keylen_integ(integrity_algorithm_t alg)
{
keylen_entry_t map[] = {
{AUTH_HMAC_MD5_96, 128},
{AUTH_HMAC_SHA1_96, 160},
{AUTH_HMAC_SHA2_256_96, 256},
{AUTH_HMAC_SHA2_256_128, 256},
{AUTH_HMAC_SHA2_384_192, 384},
{AUTH_HMAC_SHA2_512_256, 512},
{AUTH_AES_XCBC_96, 128},
};
int i;
for (i = 0; i < countof(map); i++)
{
if (map[i].alg == alg)
{
return map[i].len;
}
}
return 0;
}