- added todo
[strongswan.git] / Source / charon / transforms / crypters / crypter.h
1 /**
2 * @file crypter.h
3 *
4 * @brief Interface crypter_t
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #ifndef CRYPTER_H_
24 #define CRYPTER_H_
25
26 #include <types.h>
27
28 typedef enum encryption_algorithm_t encryption_algorithm_t;
29
30 /**
31 * @brief Encryption algorithm, as in IKEv2 draft 3.3.2.
32 *
33 * Currently only the following algorithms are implemented and therefore supported:
34 * - ENCR_AES_CBC
35 *
36 * @b Constructors:
37 * - crypter_create()
38 * - aes_cbc_crypter_create()
39 *
40 * @todo Implement more enryption algorithm, especially 3DES
41 *
42 * @ingroup crypters
43 */
44 enum encryption_algorithm_t {
45 ENCR_UNDEFINED = 1024,
46 ENCR_DES_IV64 = 1,
47 ENCR_DES = 2,
48 ENCR_3DES = 3,
49 ENCR_RC5 = 4,
50 ENCR_IDEA = 5,
51 ENCR_CAST = 6,
52 ENCR_BLOWFISH = 7,
53 ENCR_3IDEA = 8,
54 ENCR_DES_IV32 = 9,
55 ENCR_NULL = 11,
56 /**
57 * Implemented in class aes_cbc_crypter_t.
58 */
59 ENCR_AES_CBC = 12,
60 ENCR_AES_CTR = 13
61 };
62
63 /**
64 * String mappings for encryption_algorithm_t.
65 */
66 extern mapping_t encryption_algorithm_m[];
67
68
69 typedef struct crypter_t crypter_t;
70
71 /**
72 * @brief Generic interface for symmetric encryption algorithms.
73 *
74 * @todo Distinguish between block_size and key_size, since not all
75 * algorithms use key_size == block_size (e.g. 3DES).
76 *
77 * @todo Add a getter which says if an algorithm uses fixed key size, needed for
78 * tranform_attribute encoding.
79 *
80 * @ingroup crypters
81 */
82 struct crypter_t {
83 /**
84 * @brief Encrypt a chunk of data and allocate space for
85 * the encrypted value.
86 *
87 * @param this calling object
88 * @param data data to encrypt
89 * @param iv initializing vector
90 * @param [out]encrypted pointer where the encrypted bytes will be written
91 * @return
92 * - SUCCESS
93 * - INVALID_ARG if data size not a multiple of block size
94 */
95 status_t (*encrypt) (crypter_t *this, chunk_t data, chunk_t iv, chunk_t *encrypted);
96
97 /**
98 * @brief Decrypt a chunk of data and allocate space for
99 * the decrypted value.
100 *
101 * @param this calling object
102 * @param data data to decrypt
103 * @param iv initializing vector
104 * @param [out]encrypted pointer where the decrypted bytes will be written
105 * @return
106 * - SUCCESS
107 * - INVALID_ARG if data size not a multiple of block size
108 */
109 status_t (*decrypt) (crypter_t *this, chunk_t data, chunk_t iv, chunk_t *decrypted);
110
111 /**
112 * @brief Get the block size of this crypter_t object.
113 *
114 * @param this calling object
115 * @return block size in bytes
116 */
117 size_t (*get_block_size) (crypter_t *this);
118
119 /**
120 * @brief Set the key for this crypter_t object.
121 *
122 * @param this calling object
123 * @param key key to set
124 * @return
125 * - SUCCESS
126 * - INVALID_ARG if key size != block size
127 */
128 status_t (*set_key) (crypter_t *this, chunk_t key);
129
130 /**
131 * @brief Destroys a crypter_t object.
132 *
133 * @param this calling object
134 */
135 void (*destroy) (crypter_t *this);
136 };
137
138 /**
139 * @brief Generic constructor for crypter_t objects.
140 *
141 * Currently only the following algorithms are implemented and therefore supported:
142 * - ENCR_AES_CBC
143 *
144 * @param encryption_algorithm Algorithm to use for crypter
145 * @param blocksize block size in bytes
146 * @return
147 * - crypter_t object
148 * - NULL if encryption algorithm or blocksize is not supported
149 */
150 crypter_t *crypter_create(encryption_algorithm_t encryption_algorithm, size_t blocksize);
151
152 #endif /*CRYPTER_H_*/