- moved algorithm definitions from payloads to corresponding transforms
[strongswan.git] / Source / charon / transforms / crypters / crypter.h
1 /**
2 * @file crypter.h
3 *
4 * @brief Interface of 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 enum encryption_algorithm_t {
34 ENCR_UNDEFINED = 1024,
35 ENCR_DES_IV64 = 1,
36 ENCR_DES = 2,
37 ENCR_3DES = 3,
38 ENCR_RC5 = 4,
39 ENCR_IDEA = 5,
40 ENCR_CAST = 6,
41 ENCR_BLOWFISH = 7,
42 ENCR_3IDEA = 8,
43 ENCR_DES_IV32 = 9,
44 RESERVED = 10,
45 ENCR_NULL = 11,
46 ENCR_AES_CBC = 12,
47 ENCR_AES_CTR = 13
48 };
49
50 /**
51 * string mappings for encryption_algorithm_t
52 */
53 extern mapping_t encryption_algorithm_m[];
54
55 typedef struct crypter_t crypter_t;
56
57 /**
58 * @brief Generic interface for symmetric encryption algorithms.
59 *
60 * @ingroup crypters
61 */
62 struct crypter_t {
63 /**
64 * @brief Encrypt a chunk of data and allocate space for
65 * the encrypted value.
66 *
67 * @param this calling crypter
68 * @param data data to encrypt
69 * @param [out]encrypted pointer where the encrypted bytes will be written
70 * @return
71 * - SUCCESS in any case
72 */
73 status_t (*encrypt) (crypter_t *this, chunk_t data, chunk_t *encrypted);
74
75 /**
76 * @brief Decrypt a chunk of data and allocate space for
77 * the decrypted value.
78 *
79 * @param this calling crypter
80 * @param data data to decrypt
81 * @param [out]encrypted pointer where the decrypted bytes will be written
82 * @return
83 * - SUCCESS in any case
84 */
85 status_t (*decrypt) (crypter_t *this, chunk_t data, chunk_t *decrypted);
86
87 /**
88 * @brief get the block size of this crypter
89 *
90 * @param this calling crypter
91 * @return block size in bytes
92 */
93 size_t (*get_block_size) (crypter_t *this);
94
95 /**
96 * @brief Set the key for this crypter
97 *
98 * @param this calling crypter
99 * @param key key to set
100 * @return
101 * - SUCCESS in any case
102 */
103 status_t (*set_key) (crypter_t *this, chunk_t key);
104
105 /**
106 * @brief Destroys a crypter_t object.
107 *
108 * @param this crypter_t object to destroy
109 * @return
110 * - SUCCESS in any case
111 */
112 status_t (*destroy) (crypter_t *this);
113 };
114
115 /**
116 * @brief Generic constructor for crypter_t objects.
117 *
118 * @param encryption_algorithm Algorithm to use for crypter
119 * @return
120 * - crypter_t if successfully
121 * - NULL if out of ressources or crypter not supported
122 */
123 crypter_t *crypter_create(encryption_algorithm_t encryption_algorithm);
124
125 #endif /*CRYPTER_H_*/