SKEYID derivation based on libstrongswan

This commit is contained in:
Andreas Steffen
2009-05-05 14:28:31 +02:00
parent e868a564d9
commit 6eb9bc9bb8
22 changed files with 365 additions and 362 deletions
+15 -14
View File
@@ -26,7 +26,6 @@
#include "constants.h"
#include "defs.h"
#include "sha1.h"
#include "cookie.h"
const u_char zero_cookie[COOKIE_SIZE]; /* guaranteed 0 */
@@ -35,11 +34,10 @@ const u_char zero_cookie[COOKIE_SIZE]; /* guaranteed 0 */
* First argument is true if we're to create an Initiator cookie.
* Length SHOULD be a multiple of sizeof(u_int32_t).
*/
void get_cookie(bool initiator, u_int8_t *cookie, int length,
const ip_address *addr)
void get_cookie(bool initiator, u_int8_t *cookie, int length, ip_address *addr)
{
u_char buffer[SHA1_DIGEST_SIZE];
SHA1_CTX ctx;
hasher_t *hasher = lib->crypto->create_hasher(lib->crypto, HASH_SHA1);
u_char buffer[HASH_SIZE_SHA1];
do {
if (initiator)
@@ -52,20 +50,23 @@ void get_cookie(bool initiator, u_int8_t *cookie, int length,
}
else /* Responder cookie */
{
/* This looks as good as any way */
size_t addr_length;
chunk_t addr_chunk, secret_chunk, counter_chunk;
size_t addr_len;
static u_int32_t counter = 0;
unsigned char addr_buff[
unsigned char addr_buf[
sizeof(union {struct in_addr A; struct in6_addr B;})];
addr_length = addrbytesof(addr, addr_buff, sizeof(addr_buff));
SHA1Init(&ctx);
SHA1Update(&ctx, addr_buff, addr_length);
SHA1Update(&ctx, secret_of_the_day, sizeof(secret_of_the_day));
addr_len = addrbytesof(addr, addr_buf, sizeof(addr_buf));
addr_chunk = chunk_create(addr_buf, addr_len);
secret_chunk = chunk_create(secret_of_the_day, HASH_SIZE_SHA1);
counter++;
SHA1Update(&ctx, (const void *) &counter, sizeof(counter));
SHA1Final(buffer, &ctx);
counter_chunk = chunk_create((void *) &counter, sizeof(counter));
hasher->get_hash(hasher, addr_chunk, NULL);
hasher->get_hash(hasher, secret_chunk, NULL);
hasher->get_hash(hasher, counter_chunk, buffer);
memcpy(cookie, buffer, length);
}
} while (is_zero_cookie(cookie)); /* probably never loops */
hasher->destroy(hasher);
}