updated copyright information
[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 and therefore supported:
35 * - ENCR_AES_CBC
36 *
37 * @todo Implement more enryption algorithms, such as 3DES
38 *
39 * @ingroup crypters
40 */
41 enum encryption_algorithm_t {
42 ENCR_UNDEFINED = 1024,
43 ENCR_DES_IV64 = 1,
44 ENCR_DES = 2,
45 ENCR_3DES = 3,
46 ENCR_RC5 = 4,
47 ENCR_IDEA = 5,
48 ENCR_CAST = 6,
49 ENCR_BLOWFISH = 7,
50 ENCR_3IDEA = 8,
51 ENCR_DES_IV32 = 9,
52 ENCR_NULL = 11,
53 /**
54 * Implemented in class aes_cbc_crypter_t.
55 */
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 * @brief Encrypt a chunk of data and allocate space for the encrypted value.
79 *
80 * @param this calling object
81 * @param data data to encrypt
82 * @param iv initializing vector
83 * @param[out] encrypted pointer where the encrypted bytes will be written
84 * @return
85 * - SUCCESS
86 * - INVALID_ARG if data size not a multiple of block size
87 */
88 status_t (*encrypt) (crypter_t *this, chunk_t data, chunk_t iv, chunk_t *encrypted);
89
90 /**
91 * @brief Decrypt a chunk of data and allocate space for the decrypted value.
92 *
93 * @param this calling object
94 * @param data data to decrypt
95 * @param iv initializing vector
96 * @param[out] encrypted pointer where the decrypted bytes will be written
97 * @return
98 * - SUCCESS
99 * - INVALID_ARG if data size not a multiple of block size
100 */
101 status_t (*decrypt) (crypter_t *this, chunk_t data, chunk_t iv, chunk_t *decrypted);
102
103 /**
104 * @brief Get the block size of this crypter_t object.
105 *
106 * @param this calling object
107 * @return block size in bytes
108 */
109 size_t (*get_block_size) (crypter_t *this);
110
111 /**
112 * @brief Get the key size of this crypter_t object.
113 *
114 * @param this calling object
115 * @return key size in bytes
116 */
117 size_t (*get_key_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 length invalid
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 * The key_size is ignored for algorithms with fixed key size.
145 *
146 * @param encryption_algorithm Algorithm to use for crypter
147 * @param key_size size of the key in bytes
148 * @return
149 * - crypter_t object
150 * - NULL if encryption algorithm/key_size is not supported
151 */
152 crypter_t *crypter_create(encryption_algorithm_t encryption_algorithm, size_t key_size);
153
154 #endif /*CRYPTER_H_*/