]> git.ipfire.org Git - people/ms/strongswan.git/blob - src/libcharon/sa/keymat.c
Properly handle retransmitted initial IKE messages.
[people/ms/strongswan.git] / src / libcharon / sa / keymat.c
1 /*
2 * Copyright (C) 2011 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include "keymat.h"
17
18 #include <sa/ikev1/keymat_v1.h>
19 #include <sa/ikev2/keymat_v2.h>
20
21 /**
22 * See header
23 */
24 keymat_t *keymat_create(ike_version_t version, bool initiator)
25 {
26 switch (version)
27 {
28 case IKEV1:
29 #ifdef USE_IKEV1
30 return &keymat_v1_create(initiator)->keymat;
31 #endif
32 break;
33 case IKEV2:
34 #ifdef USE_IKEV2
35 return &keymat_v2_create(initiator)->keymat;
36 #endif
37 break;
38 default:
39 break;
40 }
41 return NULL;
42 }
43
44 /**
45 * Implicit key length for an algorithm
46 */
47 typedef struct {
48 /** IKEv2 algorithm identifier */
49 int alg;
50 /** key length in bits */
51 int len;
52 } keylen_entry_t;
53
54 /**
55 * See header.
56 */
57 int keymat_get_keylen_encr(encryption_algorithm_t alg)
58 {
59 keylen_entry_t map[] = {
60 {ENCR_DES, 64},
61 {ENCR_3DES, 192},
62 };
63 int i;
64
65 for (i = 0; i < countof(map); i++)
66 {
67 if (map[i].alg == alg)
68 {
69 return map[i].len;
70 }
71 }
72 return 0;
73 }
74
75 /**
76 * See header.
77 */
78 int keymat_get_keylen_integ(integrity_algorithm_t alg)
79 {
80 keylen_entry_t map[] = {
81 {AUTH_HMAC_MD5_96, 128},
82 {AUTH_HMAC_SHA1_96, 160},
83 {AUTH_HMAC_SHA2_256_96, 256},
84 {AUTH_HMAC_SHA2_256_128, 256},
85 {AUTH_HMAC_SHA2_384_192, 384},
86 {AUTH_HMAC_SHA2_512_256, 512},
87 {AUTH_AES_XCBC_96, 128},
88 };
89 int i;
90
91 for (i = 0; i < countof(map); i++)
92 {
93 if (map[i].alg == alg)
94 {
95 return map[i].len;
96 }
97 }
98 return 0;
99 }