added support for 3DES encryption algorithm in IKE
[strongswan.git] / src / libstrongswan / crypto / crypters / crypter.h
1 /**
2 * @file crypter.h
3 *
4 * @brief Interface crypter_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 #ifndef CRYPTER_H_
25 #define CRYPTER_H_
26
27 #include <types.h>
28
29 typedef enum encryption_algorithm_t encryption_algorithm_t;
30
31 /**
32 * @brief Encryption algorithm, as in IKEv2 RFC 3.3.2.
33 *
34 * Currently only the following algorithms are implemented:
35 * - ENCR_AES_CBC
36 * - ENCR_DES
37 * - ENCR_3DES
38 *
39 * @ingroup crypters
40 */
41 enum encryption_algorithm_t {
42 ENCR_UNDEFINED = 1024,
43 ENCR_DES_IV64 = 1,
44 /** Implemented in class des_crypter_t */
45 ENCR_DES = 2,
46 /** Implemented in class des_crypter_t */
47 ENCR_3DES = 3,
48 ENCR_RC5 = 4,
49 ENCR_IDEA = 5,
50 ENCR_CAST = 6,
51 ENCR_BLOWFISH = 7,
52 ENCR_3IDEA = 8,
53 ENCR_DES_IV32 = 9,
54 ENCR_NULL = 11,
55 /** Implemented in class aes_cbc_crypter_t */
56 ENCR_AES_CBC = 12,
57 ENCR_AES_CTR = 13
58 };
59
60 /**
61 * String mappings for encryption_algorithm_t.
62 */
63 extern mapping_t encryption_algorithm_m[];
64
65
66 typedef struct crypter_t crypter_t;
67
68 /**
69 * @brief Generic interface for symmetric encryption algorithms.
70 *
71 * @b Constructors:
72 * - crypter_create()
73 *
74 * @ingroup crypters
75 */
76 struct crypter_t {
77
78 /**
79 * @brief Encrypt a chunk of data and allocate space for the encrypted value.
80 *
81 * @param this calling object
82 * @param data data to encrypt
83 * @param iv initializing vector
84 * @param[out] encrypted pointer where the encrypted bytes will be written
85 * @return
86 * - SUCCESS
87 * - INVALID_ARG if data size not a multiple of block size
88 */
89 status_t (*encrypt) (crypter_t *this, chunk_t data, chunk_t iv, chunk_t *encrypted);
90
91 /**
92 * @brief Decrypt a chunk of data and allocate space for the decrypted value.
93 *
94 * @param this calling object
95 * @param data data to decrypt
96 * @param iv initializing vector
97 * @param[out] encrypted pointer where the decrypted bytes will be written
98 * @return
99 * - SUCCESS
100 * - INVALID_ARG if data size not a multiple of block size
101 */
102 status_t (*decrypt) (crypter_t *this, chunk_t data, chunk_t iv, chunk_t *decrypted);
103
104 /**
105 * @brief Get the block size of this crypter_t object.
106 *
107 * @param this calling object
108 * @return block size in bytes
109 */
110 size_t (*get_block_size) (crypter_t *this);
111
112 /**
113 * @brief Get the key size of this crypter_t object.
114 *
115 * @param this calling object
116 * @return key size in bytes
117 */
118 size_t (*get_key_size) (crypter_t *this);
119
120 /**
121 * @brief Set the key for this crypter_t object.
122 *
123 * @param this calling object
124 * @param key key to set
125 * @return
126 * - SUCCESS
127 * - INVALID_ARG if key length invalid
128 */
129 status_t (*set_key) (crypter_t *this, chunk_t key);
130
131 /**
132 * @brief Destroys a crypter_t object.
133 *
134 * @param this calling object
135 */
136 void (*destroy) (crypter_t *this);
137 };
138
139 /**
140 * @brief Generic constructor for crypter_t objects.
141 *
142 * Currently only the following algorithms are implemented:
143 * - ENCR_AES_CBC
144 * - ENCR_DES
145 * - ENCR_3DES
146 *
147 * The key_size is ignored for algorithms with fixed key size.
148 *
149 * @param encryption_algorithm Algorithm to use for crypter
150 * @param key_size size of the key in bytes
151 * @return
152 * - crypter_t object
153 * - NULL if encryption algorithm/key_size is not supported
154 */
155 crypter_t *crypter_create(encryption_algorithm_t encryption_algorithm, size_t key_size);
156
157 #endif /*CRYPTER_H_*/