4 * @brief Interface crypter_t
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
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>.
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
28 typedef enum encryption_algorithm_t encryption_algorithm_t
;
31 * @brief Encryption algorithm, as in IKEv2 RFC 3.3.2.
33 * Currently only the following algorithms are implemented and therefore supported:
36 * @todo Implement more enryption algorithms, such as 3DES
40 enum encryption_algorithm_t
{
41 ENCR_UNDEFINED
= 1024,
53 * Implemented in class aes_cbc_crypter_t.
60 * String mappings for encryption_algorithm_t.
62 extern mapping_t encryption_algorithm_m
[];
65 typedef struct crypter_t crypter_t
;
68 * @brief Generic interface for symmetric encryption algorithms.
77 * @brief Encrypt a chunk of data and allocate space for the encrypted value.
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
85 * - INVALID_ARG if data size not a multiple of block size
87 status_t (*encrypt
) (crypter_t
*this, chunk_t data
, chunk_t iv
, chunk_t
*encrypted
);
90 * @brief Decrypt a chunk of data and allocate space for the decrypted value.
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
98 * - INVALID_ARG if data size not a multiple of block size
100 status_t (*decrypt
) (crypter_t
*this, chunk_t data
, chunk_t iv
, chunk_t
*decrypted
);
103 * @brief Get the block size of this crypter_t object.
105 * @param this calling object
106 * @return block size in bytes
108 size_t (*get_block_size
) (crypter_t
*this);
111 * @brief Get the key size of this crypter_t object.
113 * @param this calling object
114 * @return key size in bytes
116 size_t (*get_key_size
) (crypter_t
*this);
119 * @brief Set the key for this crypter_t object.
121 * @param this calling object
122 * @param key key to set
125 * - INVALID_ARG if key length invalid
127 status_t (*set_key
) (crypter_t
*this, chunk_t key
);
130 * @brief Destroys a crypter_t object.
132 * @param this calling object
134 void (*destroy
) (crypter_t
*this);
138 * @brief Generic constructor for crypter_t objects.
140 * Currently only the following algorithms are implemented and therefore supported:
143 * The key_size is ignored for algorithms with fixed key size.
145 * @param encryption_algorithm Algorithm to use for crypter
146 * @param key_size size of the key in bytes
149 * - NULL if encryption algorithm/key_size is not supported
151 crypter_t
*crypter_create(encryption_algorithm_t encryption_algorithm
, size_t key_size
);
153 #endif /*CRYPTER_H_*/