removed all hash function code from pluto

This commit is contained in:
Andreas Steffen
2009-05-06 22:46:51 +02:00
parent ab87051f23
commit 38a7792d8a
19 changed files with 42 additions and 1562 deletions
+25 -26
View File
@@ -148,22 +148,6 @@ ike_alg_register_hash(struct hash_desc *hash_desc)
return_on(ret,-EINVAL);
}
if (hash_desc->hash_ctx_size > sizeof (union hash_ctx))
{
plog ("ike_alg: hash alg=%d has ctx_size=%d > hash_ctx=%d"
, hash_desc->algo_id
, (int)hash_desc->hash_ctx_size
, (int)sizeof (union hash_ctx));
return_on(ret,-EOVERFLOW);
}
if (!(hash_desc->hash_init && hash_desc->hash_update && hash_desc->hash_final))
{
plog ("ike_alg: hash alg=%d needs hash_init(), hash_update() and hash_final()"
, hash_desc->algo_id);
return_on(ret,-EINVAL);
}
alg_name = enum_name(&oakley_hash_names, hash_desc->algo_id);
if (!alg_name)
{
@@ -447,25 +431,32 @@ ike_hash_test(const struct hash_desc *desc)
if (desc->hash_testvectors == NULL)
{
plog(" %s hash self-test not available", enum_name(&oakley_hash_names, desc->algo_id));
plog(" %s hash self-test not available",
enum_name(&oakley_hash_names, desc->algo_id));
}
else
{
int i;
hash_algorithm_t hash_alg;
hasher_t *hasher;
hash_alg = oakley_to_hash_algorithm(desc->algo_id);
hasher = lib->crypto->create_hasher(lib->crypto, hash_alg);
if (hasher == NULL)
{
plog(" %s hash function not available",
enum_name(&oakley_hash_names, desc->algo_id));
return FALSE;
}
for (i = 0; desc->hash_testvectors[i].msg_digest != NULL; i++)
{
u_char digest[MAX_DIGEST_LEN];
chunk_t msg = { desc->hash_testvectors[i].msg,
desc->hash_testvectors[i].msg_size };
hash_algorithm_t hash_alg;
hasher_t *hasher;
bool result;
hash_alg = oakley_to_hash_algorithm(desc->algo_id);
hasher = lib->crypto->create_hasher(lib->crypto, hash_alg);
hasher->get_hash(hasher, msg, digest);
hasher->destroy(hasher);
result = memeq(digest, desc->hash_testvectors[i].msg_digest
, desc->hash_digest_size);
DBG(DBG_CRYPT,
@@ -473,8 +464,9 @@ ike_hash_test(const struct hash_desc *desc)
)
hash_results &= result;
}
plog(" %s hash self-test %s", enum_name(&oakley_hash_names, desc->algo_id)
, hash_results ? "passed":"failed");
hasher->destroy(hasher);
plog(" %s hash self-test %s", enum_name(&oakley_hash_names, desc->algo_id),
hash_results ? "passed":"failed");
}
if (desc->hmac_testvectors == NULL)
@@ -484,6 +476,9 @@ ike_hash_test(const struct hash_desc *desc)
else
{
int i;
pseudo_random_function_t prf_alg;
prf_alg = oakley_to_prf(desc->algo_id);
for (i = 0; desc->hmac_testvectors[i].hmac != NULL; i++)
{
@@ -492,12 +487,16 @@ ike_hash_test(const struct hash_desc *desc)
desc->hmac_testvectors[i].key_size };
chunk_t msg = { desc->hmac_testvectors[i].msg,
desc->hmac_testvectors[i].msg_size };
pseudo_random_function_t prf_alg;
prf_t *prf;
bool result;
prf_alg = oakley_to_prf(desc->algo_id);
prf = lib->crypto->create_prf(lib->crypto, prf_alg);
if (prf == NULL)
{
plog(" %s hmac function not available",
enum_name(&oakley_hash_names, desc->algo_id));
return FALSE;
}
prf->set_key(prf, key);
prf->get_bytes(prf, msg, digest);
prf->destroy(prf);