iv-gen: Add a generic constructor to create an IV gen from an algorithm
[strongswan.git] / src / libstrongswan / crypto / iv / iv_gen.c
1 /*
2 * Copyright (C) 2015 Martin Willi
3 * Copyright (C) 2015 revosec AG
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 "iv_gen.h"
17 #include "iv_gen_rand.h"
18 #include "iv_gen_seq.h"
19
20 /**
21 * See header.
22 */
23 iv_gen_t* iv_gen_create_for_alg(encryption_algorithm_t alg)
24 {
25 switch (alg)
26 {
27 case ENCR_DES:
28 case ENCR_3DES:
29 case ENCR_RC5:
30 case ENCR_IDEA:
31 case ENCR_CAST:
32 case ENCR_BLOWFISH:
33 case ENCR_3IDEA:
34 case ENCR_AES_CBC:
35 case ENCR_CAMELLIA_CBC:
36 case ENCR_SERPENT_CBC:
37 case ENCR_TWOFISH_CBC:
38 case ENCR_RC2_CBC:
39 return iv_gen_rand_create();
40 case ENCR_AES_CTR:
41 case ENCR_AES_CCM_ICV8:
42 case ENCR_AES_CCM_ICV12:
43 case ENCR_AES_CCM_ICV16:
44 case ENCR_AES_GCM_ICV8:
45 case ENCR_AES_GCM_ICV12:
46 case ENCR_AES_GCM_ICV16:
47 case ENCR_CAMELLIA_CTR:
48 case ENCR_CAMELLIA_CCM_ICV8:
49 case ENCR_CAMELLIA_CCM_ICV12:
50 case ENCR_CAMELLIA_CCM_ICV16:
51 case ENCR_NULL_AUTH_AES_GMAC:
52 return iv_gen_seq_create();
53 case ENCR_NULL:
54 case ENCR_UNDEFINED:
55 case ENCR_DES_ECB:
56 case ENCR_DES_IV32:
57 case ENCR_DES_IV64:
58 break;
59 }
60 return NULL;
61 }