- added compution of all needed keys and also creation of needed
[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 iv iv
70 * @param [out]encrypted pointer where the encrypted bytes will be written
71 * @return
72 * - SUCCESS in any case
73 */
74 status_t (*encrypt) (crypter_t *this, chunk_t data, chunk_t iv, chunk_t *encrypted);
75
76 /**
77 * @brief Decrypt a chunk of data and allocate space for
78 * the decrypted value.
79 *
80 * @param this calling crypter
81 * @param data data to decrypt
82 * @param iv iv
83 * @param [out]encrypted pointer where the decrypted bytes will be written
84 * @return
85 * - SUCCESS in any case
86 */
87 status_t (*decrypt) (crypter_t *this, chunk_t data, chunk_t iv, chunk_t *decrypted);
88
89 /**
90 * @brief get the block size of this crypter
91 *
92 * @param this calling crypter
93 * @return block size in bytes
94 */
95 size_t (*get_block_size) (crypter_t *this);
96
97 /**
98 * @brief Set the key for this crypter
99 *
100 * @param this calling crypter
101 * @param key key to set
102 * @return
103 * - SUCCESS in any case
104 */
105 status_t (*set_key) (crypter_t *this, chunk_t key);
106
107 /**
108 * @brief Destroys a crypter_t object.
109 *
110 * @param this crypter_t object to destroy
111 * @return
112 * - SUCCESS in any case
113 */
114 status_t (*destroy) (crypter_t *this);
115 };
116
117 /**
118 * @brief Generic constructor for crypter_t objects.
119 *
120 * @param encryption_algorithm Algorithm to use for crypter
121 * @param blocksize block size in bytes
122 * @return
123 * - crypter_t if successfully
124 * - NULL if out of ressources or crypter not supported
125 */
126 crypter_t *crypter_create(encryption_algorithm_t encryption_algorithm, size_t blocksize);
127
128 #endif /*CRYPTER_H_*/