ECDSA with OpenSSL
[strongswan.git] / src / charon / sa / authenticators / authenticator.c
1 /*
2 * Copyright (C) 2008 Tobias Brunner
3 * Copyright (C) 2006 Martin Willi
4 * Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 *
16 * $Id$
17 */
18
19 #include <string.h>
20
21 #include "authenticator.h"
22
23 #include <sa/authenticators/pubkey_authenticator.h>
24 #include <sa/authenticators/psk_authenticator.h>
25 #include <sa/authenticators/eap_authenticator.h>
26
27
28 ENUM_BEGIN(auth_method_names, AUTH_RSA, AUTH_DSS,
29 "RSA signature",
30 "pre-shared key",
31 "DSS signature");
32 ENUM_NEXT(auth_method_names, AUTH_ECDSA_256, AUTH_ECDSA_521, AUTH_DSS,
33 "ECDSA-256 signature",
34 "ECDSA-384 signature",
35 "ECDSA-521 signature");
36 ENUM_NEXT(auth_method_names, AUTH_EAP, AUTH_EAP, AUTH_ECDSA_521,
37 "EAP");
38 ENUM_END(auth_method_names, AUTH_EAP);
39
40 /**
41 * Described in header.
42 */
43 authenticator_t *authenticator_create(ike_sa_t *ike_sa, config_auth_method_t auth_method)
44 {
45 switch (auth_method)
46 {
47 case CONF_AUTH_PUBKEY:
48 return (authenticator_t*)pubkey_authenticator_create(ike_sa);
49 case CONF_AUTH_PSK:
50 return (authenticator_t*)psk_authenticator_create(ike_sa);
51 case CONF_AUTH_EAP:
52 return (authenticator_t*)eap_authenticator_create(ike_sa);
53 default:
54 return NULL;
55 }
56 }
57
58 /**
59 * Described in header.
60 */
61 authenticator_t *authenticator_create_from_auth_payload(ike_sa_t *ike_sa, auth_payload_t *auth_payload)
62 {
63 switch (auth_payload->get_auth_method(auth_payload))
64 {
65 case AUTH_RSA:
66 case AUTH_ECDSA_256:
67 case AUTH_ECDSA_384:
68 case AUTH_ECDSA_521:
69 return (authenticator_t*)pubkey_authenticator_create(ike_sa);
70 case AUTH_PSK:
71 return (authenticator_t*)psk_authenticator_create(ike_sa);
72 default:
73 return NULL;
74 }
75 }