Files
strongswan-ext/src/libcharon/sa/keymat.c
T

91 lines
1.8 KiB
C

/*
* Copyright (C) 2011 Tobias Brunner
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "keymat.h"
#include "keymat_v1.h"
#include "keymat_v2.h"
/**
* See header
*/
keymat_t *keymat_create(ike_version_t version, bool initiator)
{
switch (version)
{
case IKEV1:
return &keymat_v1_create(initiator)->keymat;
case IKEV2:
return &keymat_v2_create(initiator)->keymat;
}
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;
}