1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
/*
* 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;
default:
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;
}
|