crypter_t api supports in-place encryption using NULL as output parameter
[strongswan.git] / src / libstrongswan / crypto / crypters / crypter.h
1 /*
2 * Copyright (C) 2005-2006 Martin Willi
3 * Copyright (C) 2005 Jan Hutter
4 * Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 *
16 * $Id$
17 */
18
19 /**
20 * @defgroup crypter crypter
21 * @{ @ingroup crypto
22 */
23
24 #ifndef CRYPTER_H_
25 #define CRYPTER_H_
26
27 typedef enum encryption_algorithm_t encryption_algorithm_t;
28 typedef struct crypter_t crypter_t;
29
30 #include <library.h>
31
32 /**
33 * Encryption algorithm, as in IKEv2 RFC 3.3.2.
34 */
35 enum encryption_algorithm_t {
36 ENCR_UNDEFINED = 1024,
37 ENCR_DES_IV64 = 1,
38 ENCR_DES = 2,
39 ENCR_3DES = 3,
40 ENCR_RC5 = 4,
41 ENCR_IDEA = 5,
42 ENCR_CAST = 6,
43 ENCR_BLOWFISH = 7,
44 ENCR_3IDEA = 8,
45 ENCR_DES_IV32 = 9,
46 ENCR_NULL = 11,
47 ENCR_AES_CBC = 12,
48 ENCR_AES_CTR = 13
49 };
50
51 /**
52 * enum name for encryption_algorithm_t.
53 */
54 extern enum_name_t *encryption_algorithm_names;
55
56 /**
57 * Generic interface for symmetric encryption algorithms.
58 */
59 struct crypter_t {
60
61 /**
62 * Encrypt a chunk of data and allocate space for the encrypted value.
63 *
64 * The length of the iv must equal to get_block_size(), while the length
65 * of data must be a multiple it.
66 * If encrypted is NULL, the encryption is done in-place (overwriting data).
67 *
68 * @param data data to encrypt
69 * @param iv initializing vector
70 * @param encrypted chunk to allocate encrypted data, or NULL
71 */
72 void (*encrypt) (crypter_t *this, chunk_t data, chunk_t iv,
73 chunk_t *encrypted);
74
75 /**
76 * Decrypt a chunk of data and allocate space for the decrypted value.
77 *
78 * The length of the iv must equal to get_block_size(), while the length
79 * of data must be a multiple it.
80 * If decrpyted is NULL, the encryption is done in-place (overwriting data).
81 *
82 * @param data data to decrypt
83 * @param iv initializing vector
84 * @param encrypted chunk to allocate decrypted data, or NULL
85 */
86 void (*decrypt) (crypter_t *this, chunk_t data, chunk_t iv,
87 chunk_t *decrypted);
88
89 /**
90 * Get the block size of the crypto algorithm.
91 *
92 * @return block size in bytes
93 */
94 size_t (*get_block_size) (crypter_t *this);
95
96 /**
97 * Get the key size of the crypto algorithm.
98 *
99 * @return key size in bytes
100 */
101 size_t (*get_key_size) (crypter_t *this);
102
103 /**
104 * Set the key.
105 *
106 * The length of the key must match get_key_size().
107 *
108 * @param key key to set
109 */
110 void (*set_key) (crypter_t *this, chunk_t key);
111
112 /**
113 * Destroys a crypter_t object.
114 */
115 void (*destroy) (crypter_t *this);
116 };
117
118 #endif /*CRYPTER_H_ @} */