Add a return value to hasher_t.get_hash()
[strongswan.git] / src / libstrongswan / crypto / aead.h
1 /*
2 * Copyright (C) 2010 Martin Willi
3 * Copyright (C) 2010 revosec AG
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup aead aead
18 * @{ @ingroup crypto
19 */
20
21 #ifndef AEAD_H_
22 #define AEAD_H_
23
24 typedef struct aead_t aead_t;
25
26 #include <library.h>
27 #include <crypto/crypters/crypter.h>
28 #include <crypto/signers/signer.h>
29
30 /**
31 * Authenticated encryption / authentication decryption interface.
32 */
33 struct aead_t {
34
35 /**
36 * Encrypt and sign data, sign associated data.
37 *
38 * The plain data must be a multiple of get_block_size(), the IV must
39 * have a length of get_iv_size().
40 * If encrypted is NULL, the encryption is done inline. The buffer must
41 * have space for additional get_icv_size() data, the ICV value is
42 * appended silently to the plain chunk.
43 *
44 * @param plain data to encrypt and sign
45 * @param assoc associated data to sign
46 * @param iv initialization vector
47 * @param encrypted allocated encryption result
48 * @return TRUE if successfully encrypted
49 */
50 __attribute__((warn_unused_result))
51 bool (*encrypt)(aead_t *this, chunk_t plain, chunk_t assoc, chunk_t iv,
52 chunk_t *encrypted);
53
54 /**
55 * Decrypt and verify data, verify associated data.
56 *
57 * The IV must have a length of get_iv_size().
58 * If plain is NULL, the decryption is done inline. The decrypted data
59 * is returned in the encrypted chunk, the last get_icv_size() bytes
60 * contain the verified ICV.
61 *
62 * @param encrypted data to encrypt and verify
63 * @param assoc associated data to verify
64 * @param iv initialization vector
65 * @param plain allocated result, if successful
66 * @return TRUE if MAC verification successful
67 */
68 bool (*decrypt)(aead_t *this, chunk_t encrypted, chunk_t assoc, chunk_t iv,
69 chunk_t *plain);
70
71 /**
72 * Get the block size for encryption.
73 *
74 * @return block size in bytes
75 */
76 size_t (*get_block_size)(aead_t *this);
77
78 /**
79 * Get the integrity check value size of the algorithm.
80 *
81 * @return ICV size in bytes
82 */
83 size_t (*get_icv_size)(aead_t *this);
84
85 /**
86 * Get the size of the initialization vector.
87 *
88 * @return IV size in bytes
89 */
90 size_t (*get_iv_size)(aead_t *this);
91
92 /**
93 * Get the size of the key material (for encryption and authentication).
94 *
95 * @return key size in bytes
96 */
97 size_t (*get_key_size)(aead_t *this);
98
99 /**
100 * Set the key for encryption and authentication.
101 *
102 * @param key encryption and authentication key
103 * @return TRUE if key set successfully
104 */
105 __attribute__((warn_unused_result))
106 bool (*set_key)(aead_t *this, chunk_t key);
107
108 /**
109 * Destroy a aead_t.
110 */
111 void (*destroy)(aead_t *this);
112 };
113
114 /**
115 * Create a aead instance using traditional transforms.
116 *
117 * @param crypter encryption transform for this aead
118 * @param signer integrity transform for this aead
119 * @return aead transform
120 */
121 aead_t *aead_create(crypter_t *crypter, signer_t *signer);
122
123 #endif /** AEAD_H_ @}*/