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