Removed len argument from proposal_get_token()
[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 bool (*encrypt)(aead_t *this, chunk_t plain, chunk_t assoc, chunk_t iv,
51 chunk_t *encrypted) __attribute__((warn_unused_result));
52
53 /**
54 * Decrypt and verify data, verify associated data.
55 *
56 * The IV must have a length of get_iv_size().
57 * If plain is NULL, the decryption is done inline. The decrypted data
58 * is returned in the encrypted chunk, the last get_icv_size() bytes
59 * contain the verified ICV.
60 *
61 * @param encrypted data to encrypt and verify
62 * @param assoc associated data to verify
63 * @param iv initialization vector
64 * @param plain allocated result, if successful
65 * @return TRUE if MAC verification successful
66 */
67 bool (*decrypt)(aead_t *this, chunk_t encrypted, chunk_t assoc, chunk_t iv,
68 chunk_t *plain);
69
70 /**
71 * Get the block size for encryption.
72 *
73 * @return block size in bytes
74 */
75 size_t (*get_block_size)(aead_t *this);
76
77 /**
78 * Get the integrity check value size of the algorithm.
79 *
80 * @return ICV size in bytes
81 */
82 size_t (*get_icv_size)(aead_t *this);
83
84 /**
85 * Get the size of the initialization vector.
86 *
87 * @return IV size in bytes
88 */
89 size_t (*get_iv_size)(aead_t *this);
90
91 /**
92 * Get the size of the key material (for encryption and authentication).
93 *
94 * @return key size in bytes
95 */
96 size_t (*get_key_size)(aead_t *this);
97
98 /**
99 * Set the key for encryption and authentication.
100 *
101 * @param key encryption and authentication key
102 * @return TRUE if key set successfully
103 */
104 bool (*set_key)(aead_t *this,
105 chunk_t key) __attribute__((warn_unused_result));
106
107 /**
108 * Destroy a aead_t.
109 */
110 void (*destroy)(aead_t *this);
111 };
112
113 /**
114 * Create a aead instance using traditional transforms.
115 *
116 * @param crypter encryption transform for this aead
117 * @param signer integrity transform for this aead
118 * @return aead transform
119 */
120 aead_t *aead_create(crypter_t *crypter, signer_t *signer);
121
122 #endif /** AEAD_H_ @}*/