implemented sha2_hasher which supports SHA-256, SHA-384 and SHA-512
[strongswan.git] / src / libstrongswan / crypto / prfs / prf.c
1 /**
2 * @file prf.c
3 *
4 * @brief Generic constructor for all prf_t
5 *
6 */
7
8 /*
9 * Copyright (C) 2005-2006 Martin Willi
10 * Copyright (C) 2005 Jan Hutter
11 * Hochschule fuer Technik Rapperswil
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
22 */
23
24
25 #include "prf.h"
26
27 #include <crypto/hashers/hasher.h>
28 #include <crypto/prfs/hmac_prf.h>
29
30
31 /**
32 * String mappings for encryption_algorithm_t.
33 */
34 mapping_t pseudo_random_function_m[] = {
35 {PRF_UNDEFINED, "PRF_UNDEFINED"},
36 {PRF_HMAC_MD5, "PRF_HMAC_MD5"},
37 {PRF_HMAC_SHA1, "PRF_HMAC_SHA1"},
38 {PRF_HMAC_TIGER, "PRF_HMAC_TIGER"},
39 {PRF_AES128_CBC, "PRF_AES128_CBC"},
40 {MAPPING_END, NULL}
41 };
42
43 /*
44 * Described in header.
45 */
46 prf_t *prf_create(pseudo_random_function_t pseudo_random_function)
47 {
48 switch (pseudo_random_function)
49 {
50 case PRF_HMAC_SHA1:
51 {
52 return (prf_t*)hmac_prf_create(HASH_SHA1);
53 }
54 case PRF_HMAC_MD5:
55 {
56 return (prf_t*)hmac_prf_create(HASH_MD5);
57 }
58 case PRF_HMAC_TIGER:
59 case PRF_AES128_CBC:
60 default:
61 return NULL;
62 }
63 }