Debian Codegraph @

debian/rust-vendor/aws-lc-sys/aws-lc/include/openssl/aead.h

raw
1 // Copyright (c) 2014, Google Inc.
2 // SPDX-License-Identifier: ISC
3
4 #ifndef OPENSSL_HEADER_AEAD_H
5 #define OPENSSL_HEADER_AEAD_H
6
7 #include <openssl/base.h>
8
9 #if defined(__cplusplus)
10 extern "C" {
11 #endif
12
13
14 // Authenticated Encryption with Additional Data.
15 //
16 // AEAD couples confidentiality and integrity in a single primitive. AEAD
17 // algorithms take a key and then can seal and open individual messages. Each
18 // message has a unique, per-message nonce and, optionally, additional data
19 // which is authenticated but not included in the ciphertext.
20 //
21 // The |EVP_AEAD_CTX_init| function initialises an |EVP_AEAD_CTX| structure and
22 // performs any precomputation needed to use |aead| with |key|. The length of
23 // the key, |key_len|, is given in bytes.
24 //
25 // The |tag_len| argument contains the length of the tags, in bytes, and allows
26 // for the processing of truncated authenticators. A zero value indicates that
27 // the default tag length should be used and this is defined as
28 // |EVP_AEAD_DEFAULT_TAG_LENGTH| in order to make the code clear. Using
29 // truncated tags increases an attacker's chance of creating a valid forgery.
30 // Be aware that the attacker's chance may increase more than exponentially as
31 // would naively be expected.
32 //
33 // When no longer needed, the initialised |EVP_AEAD_CTX| structure must be
34 // passed to |EVP_AEAD_CTX_cleanup|, which will deallocate any memory used.
35 //
36 // With an |EVP_AEAD_CTX| in hand, one can seal and open messages. These
37 // operations are intended to meet the standard notions of privacy and
38 // authenticity for authenticated encryption. For formal definitions see
39 // Bellare and Namprempre, "Authenticated encryption: relations among notions
40 // and analysis of the generic composition paradigm," Lecture Notes in Computer
41 // Science B<1976> (2000), 531–545,
42 // http://www-cse.ucsd.edu/~mihir/papers/oem.html.
43 //
44 // When sealing messages, a nonce must be given. The length of the nonce is
45 // fixed by the AEAD in use and is returned by |EVP_AEAD_nonce_length|. *The
46 // nonce must be unique for all messages with the same key*. This is critically
47 // important - nonce reuse may completely undermine the security of the AEAD.
48 // Nonces may be predictable and public, so long as they are unique. Uniqueness
49 // may be achieved with a simple counter or, if large enough, may be generated
50 // randomly. The nonce must be passed into the "open" operation by the receiver
51 // so must either be implicit (e.g. a counter), or must be transmitted along
52 // with the sealed message.
53 //
54 // The "seal" and "open" operations are atomic - an entire message must be
55 // encrypted or decrypted in a single call. Large messages may have to be split
56 // up in order to accommodate this. When doing so, be mindful of the need not to
57 // repeat nonces and the possibility that an attacker could duplicate, reorder
58 // or drop message chunks. For example, using a single key for a given (large)
59 // message and sealing chunks with nonces counting from zero would be secure as
60 // long as the number of chunks was securely transmitted. (Otherwise an
61 // attacker could truncate the message by dropping chunks from the end.)
62 //
63 // The number of chunks could be transmitted by prefixing it to the plaintext,
64 // for example. This also assumes that no other message would ever use the same
65 // key otherwise the rule that nonces must be unique for a given key would be
66 // violated.
67 //
68 // The "seal" and "open" operations also permit additional data to be
69 // authenticated via the |ad| parameter. This data is not included in the
70 // ciphertext and must be identical for both the "seal" and "open" call. This
71 // permits implicit context to be authenticated but may be empty if not needed.
72 //
73 // The "seal" and "open" operations may work in-place if the |out| and |in|
74 // arguments are equal. Otherwise, if |out| and |in| alias, input data may be
75 // overwritten before it is read. This situation will cause an error.
76 //
77 // The "seal" and "open" operations return one on success and zero on error.
78
79
80 // AEAD algorithms.
81
82 // EVP_aead_aes_128_gcm is AES-128 in Galois Counter Mode.
83 //
84 // Note: AES-GCM should only be used with 12-byte (96-bit) nonces. Although it
85 // is specified to take a variable-length nonce, nonces with other lengths are
86 // effectively randomized, which means one must consider collisions. Unless
87 // implementing an existing protocol which has already specified incorrect
88 // parameters, only use 12-byte nonces.
89 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_gcm(void);
90
91 // EVP_aead_aes_192_gcm is AES-192 in Galois Counter Mode.
92 //
93 // WARNING: AES-192 is superfluous and shouldn't exist. NIST should never have
94 // defined it. Use only when interop with another system requires it, never
95 // de novo.
96 //
97 // Note: AES-GCM should only be used with 12-byte (96-bit) nonces. Although it
98 // is specified to take a variable-length nonce, nonces with other lengths are
99 // effectively randomized, which means one must consider collisions. Unless
100 // implementing an existing protocol which has already specified incorrect
101 // parameters, only use 12-byte nonces.
102 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_192_gcm(void);
103
104 // EVP_aead_aes_256_gcm is AES-256 in Galois Counter Mode.
105 //
106 // Note: AES-GCM should only be used with 12-byte (96-bit) nonces. Although it
107 // is specified to take a variable-length nonce, nonces with other lengths are
108 // effectively randomized, which means one must consider collisions. Unless
109 // implementing an existing protocol which has already specified incorrect
110 // parameters, only use 12-byte nonces.
111 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_gcm(void);
112
113 // EVP_aead_chacha20_poly1305 is the AEAD built from ChaCha20 and
114 // Poly1305 as described in RFC 8439.
115 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_chacha20_poly1305(void);
116
117 // EVP_aead_xchacha20_poly1305 is ChaCha20-Poly1305 with an extended nonce that
118 // makes random generation of nonces safe.
119 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_xchacha20_poly1305(void);
120
121 // EVP_aead_aes_128_ctr_hmac_sha256 is AES-128 in CTR mode with HMAC-SHA256 for
122 // authentication. The nonce is 12 bytes; the bottom 32-bits are used as the
123 // block counter, thus the maximum plaintext size is 64GB.
124 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_ctr_hmac_sha256(void);
125
126 // EVP_aead_aes_256_ctr_hmac_sha256 is AES-256 in CTR mode with HMAC-SHA256 for
127 // authentication. See |EVP_aead_aes_128_ctr_hmac_sha256| for details.
128 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_ctr_hmac_sha256(void);
129
130 // EVP_aead_aes_128_gcm_siv is AES-128 in GCM-SIV mode. See RFC 8452.
131 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_gcm_siv(void);
132
133 // EVP_aead_aes_256_gcm_siv is AES-256 in GCM-SIV mode. See RFC 8452.
134 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_gcm_siv(void);
135
136 // EVP_aead_aes_128_gcm_randnonce is AES-128 in Galois Counter Mode with
137 // internal nonce generation. The 12-byte nonce is appended to the tag
138 // and is generated internally. The "tag", for the purposes of the API, is thus
139 // 12 bytes larger. The nonce parameter when using this AEAD must be
140 // zero-length. Since the nonce is random, a single key should not be used for
141 // more than 2^32 seal operations.
142 //
143 // Warning: this is for use for FIPS compliance only. It is probably not
144 // suitable for other uses. Using standard AES-GCM AEADs allows one to achieve
145 // the same effect, but gives more control over nonce storage.
146 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_gcm_randnonce(void);
147
148 // EVP_aead_aes_256_gcm_randnonce is AES-256 in Galois Counter Mode with
149 // internal nonce generation. The 12-byte nonce is appended to the tag
150 // and is generated internally. The "tag", for the purposes of the API, is thus
151 // 12 bytes larger. The nonce parameter when using this AEAD must be
152 // zero-length. Since the nonce is random, a single key should not be used for
153 // more than 2^32 seal operations.
154 //
155 // Warning: this is for use for FIPS compliance only. It is probably not
156 // suitable for other uses. Using standard AES-GCM AEADs allows one to achieve
157 // the same effect, but gives more control over nonce storage.
158 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_gcm_randnonce(void);
159
160 // EVP_aead_aes_128_ccm_bluetooth is AES-128-CCM with M=4 and L=2 (4-byte tags
161 // and 13-byte nonces), as described in the Bluetooth Core Specification v5.0,
162 // Volume 6, Part E, Section 1.
163 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_ccm_bluetooth(void);
164
165 // EVP_aead_aes_128_ccm_bluetooth_8 is AES-128-CCM with M=8 and L=2 (8-byte tags
166 // and 13-byte nonces), as used in the Bluetooth Mesh Networking Specification
167 // v1.0.
168 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_ccm_bluetooth_8(void);
169
170 // EVP_aead_aes_128_ccm_matter is AES-128-CCM with M=16 and L=2 (16-byte tags
171 // and 13-byte nonces), as used in the Matter specification.
172 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_ccm_matter(void);
173
174 // EVP_has_aes_hardware returns one if we enable hardware support for fast and
175 // constant-time AES-GCM.
176 OPENSSL_EXPORT int EVP_has_aes_hardware(void);
177
178
179 // Utility functions.
180
181 // EVP_AEAD_key_length returns the length, in bytes, of the keys used by
182 // |aead|.
183 OPENSSL_EXPORT size_t EVP_AEAD_key_length(const EVP_AEAD *aead);
184
185 // EVP_AEAD_nonce_length returns the length, in bytes, of the per-message nonce
186 // for |aead|. Some |aead|s might support a larger set of nonce-lengths (e.g.
187 // aes-gcm).
188 OPENSSL_EXPORT size_t EVP_AEAD_nonce_length(const EVP_AEAD *aead);
189
190 // EVP_AEAD_max_overhead returns the maximum number of additional bytes added
191 // by the act of sealing data with |aead|.
192 OPENSSL_EXPORT size_t EVP_AEAD_max_overhead(const EVP_AEAD *aead);
193
194 // EVP_AEAD_max_tag_len returns the maximum tag length when using |aead|. This
195 // is the largest value that can be passed as |tag_len| to
196 // |EVP_AEAD_CTX_init|.
197 OPENSSL_EXPORT size_t EVP_AEAD_max_tag_len(const EVP_AEAD *aead);
198
199
200 // AEAD operations.
201
202 union evp_aead_ctx_st_state {
203 uint8_t opaque[564];
204 uint64_t alignment;
205 void *ptr;
206 };
207
208 // An evp_aead_ctx_st (typedefed as |EVP_AEAD_CTX| in base.h) represents an AEAD
209 // algorithm configured with a specific key and message-independent IV.
210 struct evp_aead_ctx_st {
211 const EVP_AEAD *aead;
212 union evp_aead_ctx_st_state state;
213 uint8_t state_offset;
214 // tag_len may contain the actual length of the authentication tag if it is
215 // known at initialization time.
216 uint8_t tag_len;
217 };
218
219 // EVP_AEAD_MAX_KEY_LENGTH contains the maximum key length used by
220 // any AEAD defined in this header.
221 #define EVP_AEAD_MAX_KEY_LENGTH 80
222
223 // EVP_AEAD_MAX_NONCE_LENGTH contains the maximum nonce length used by
224 // any AEAD defined in this header.
225 #define EVP_AEAD_MAX_NONCE_LENGTH 24
226
227 // EVP_AEAD_MAX_OVERHEAD contains the maximum overhead used by any AEAD
228 // defined in this header.
229 #define EVP_AEAD_MAX_OVERHEAD 64
230
231 // EVP_AEAD_DEFAULT_TAG_LENGTH is a magic value that can be passed to
232 // EVP_AEAD_CTX_init to indicate that the default tag length for an AEAD should
233 // be used.
234 #define EVP_AEAD_DEFAULT_TAG_LENGTH 0
235
236 // EVP_AEAD_CTX_zero sets an uninitialized |ctx| to the zero state. It must be
237 // initialized with |EVP_AEAD_CTX_init| before use. It is safe, but not
238 // necessary, to call |EVP_AEAD_CTX_cleanup| in this state. This may be used for
239 // more uniform cleanup of |EVP_AEAD_CTX|.
240 OPENSSL_EXPORT void EVP_AEAD_CTX_zero(EVP_AEAD_CTX *ctx);
241
242 // EVP_AEAD_CTX_new allocates an |EVP_AEAD_CTX|, calls |EVP_AEAD_CTX_init| and
243 // returns the |EVP_AEAD_CTX|, or NULL on error.
244 OPENSSL_EXPORT EVP_AEAD_CTX *EVP_AEAD_CTX_new(const EVP_AEAD *aead,
245 const uint8_t *key,
246 size_t key_len, size_t tag_len);
247
248 // EVP_AEAD_CTX_free calls |EVP_AEAD_CTX_cleanup| and |OPENSSL_free| on
249 // |ctx|.
250 OPENSSL_EXPORT void EVP_AEAD_CTX_free(EVP_AEAD_CTX *ctx);
251
252 // EVP_AEAD_CTX_init initializes |ctx| for the given AEAD algorithm. The |impl|
253 // argument is ignored and should be NULL. Authentication tags may be truncated
254 // by passing a size as |tag_len|. A |tag_len| of zero indicates the default
255 // tag length and this is defined as EVP_AEAD_DEFAULT_TAG_LENGTH for
256 // readability.
257 //
258 // Returns 1 on success. Otherwise returns 0 and pushes to the error stack. In
259 // the error case, you do not need to call |EVP_AEAD_CTX_cleanup|, but it's
260 // harmless to do so.
261 OPENSSL_EXPORT int EVP_AEAD_CTX_init(EVP_AEAD_CTX *ctx, const EVP_AEAD *aead,
262 const uint8_t *key, size_t key_len,
263 size_t tag_len, ENGINE *impl);
264
265 // EVP_AEAD_CTX_cleanup frees any data allocated by |ctx|. It is a no-op to
266 // call |EVP_AEAD_CTX_cleanup| on a |EVP_AEAD_CTX| that has been |memset| to
267 // all zeros.
268 OPENSSL_EXPORT void EVP_AEAD_CTX_cleanup(EVP_AEAD_CTX *ctx);
269
270 // EVP_AEAD_CTX_seal encrypts and authenticates |in_len| bytes from |in| and
271 // authenticates |ad_len| bytes from |ad| and writes the result to |out|. It
272 // returns one on success and zero otherwise.
273 //
274 // This function may be called concurrently with itself or any other seal/open
275 // function on the same |EVP_AEAD_CTX|.
276 //
277 // At most |max_out_len| bytes are written to |out| and, in order to ensure
278 // success, |max_out_len| should be |in_len| plus the result of
279 // |EVP_AEAD_max_overhead|. On successful return, |*out_len| is set to the
280 // actual number of bytes written.
281 //
282 // The length of |nonce|, |nonce_len|, must be equal to the result of
283 // |EVP_AEAD_nonce_length| for this AEAD.
284 //
285 // |EVP_AEAD_CTX_seal| never results in a partial output. If |max_out_len| is
286 // insufficient, zero will be returned. If any error occurs, |out| will be
287 // filled with zero bytes and |*out_len| set to zero.
288 //
289 // If |in| and |out| alias then |out| must be == |in|.
290 OPENSSL_EXPORT int EVP_AEAD_CTX_seal(const EVP_AEAD_CTX *ctx, uint8_t *out,
291 size_t *out_len, size_t max_out_len,
292 const uint8_t *nonce, size_t nonce_len,
293 const uint8_t *in, size_t in_len,
294 const uint8_t *ad, size_t ad_len);
295
296 // EVP_AEAD_CTX_open authenticates |in_len| bytes from |in| and |ad_len| bytes
297 // from |ad| and decrypts at most |in_len| bytes into |out|. It returns one on
298 // success and zero otherwise.
299 //
300 // This function may be called concurrently with itself or any other seal/open
301 // function on the same |EVP_AEAD_CTX|.
302 //
303 // At most |in_len| bytes are written to |out|. In order to ensure success,
304 // |max_out_len| should be at least |in_len|. On successful return, |*out_len|
305 // is set to the the actual number of bytes written.
306 //
307 // The length of |nonce|, |nonce_len|, must be equal to the result of
308 // |EVP_AEAD_nonce_length| for this AEAD.
309 //
310 // |EVP_AEAD_CTX_open| never results in a partial output. If |max_out_len| is
311 // insufficient, zero will be returned. If any error occurs, |out| will be
312 // filled with zero bytes and |*out_len| set to zero.
313 //
314 // If |in| and |out| alias then |out| must be == |in|.
315 OPENSSL_EXPORT int EVP_AEAD_CTX_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
316 size_t *out_len, size_t max_out_len,
317 const uint8_t *nonce, size_t nonce_len,
318 const uint8_t *in, size_t in_len,
319 const uint8_t *ad, size_t ad_len);
320
321 // EVP_AEAD_CTX_seal_scatter encrypts and authenticates |in_len| bytes from |in|
322 // and authenticates |ad_len| bytes from |ad|. It writes |in_len| bytes of
323 // ciphertext to |out| and the authentication tag to |out_tag|. It returns one
324 // on success and zero otherwise.
325 //
326 // This function may be called concurrently with itself or any other seal/open
327 // function on the same |EVP_AEAD_CTX|.
328 //
329 // Exactly |in_len| bytes are written to |out|, and up to
330 // |EVP_AEAD_max_overhead+extra_in_len| bytes to |out_tag|. On successful
331 // return, |*out_tag_len| is set to the actual number of bytes written to
332 // |out_tag|.
333 //
334 // |extra_in| may point to an additional plaintext input buffer if the cipher
335 // supports it. If present, |extra_in_len| additional bytes of plaintext are
336 // encrypted and authenticated, and the ciphertext is written (before the tag)
337 // to |out_tag|. |max_out_tag_len| must be sized to allow for the additional
338 // |extra_in_len| bytes.
339 //
340 // The length of |nonce|, |nonce_len|, must be equal to the result of
341 // |EVP_AEAD_nonce_length| for this AEAD.
342 //
343 // |EVP_AEAD_CTX_seal_scatter| never results in a partial output. If
344 // |max_out_tag_len| is insufficient, zero will be returned. If any error
345 // occurs, |out| and |out_tag| will be filled with zero bytes and |*out_tag_len|
346 // set to zero.
347 //
348 // If |in| and |out| alias then |out| must be == |in|. |out_tag| may not alias
349 // any other argument.
350 OPENSSL_EXPORT int EVP_AEAD_CTX_seal_scatter(
351 const EVP_AEAD_CTX *ctx, uint8_t *out, uint8_t *out_tag,
352 size_t *out_tag_len, size_t max_out_tag_len, const uint8_t *nonce,
353 size_t nonce_len, const uint8_t *in, size_t in_len, const uint8_t *extra_in,
354 size_t extra_in_len, const uint8_t *ad, size_t ad_len);
355
356 // EVP_AEAD_CTX_open_gather decrypts and authenticates |in_len| bytes from |in|
357 // and authenticates |ad_len| bytes from |ad| using |in_tag_len| bytes of
358 // authentication tag from |in_tag|. If successful, it writes |in_len| bytes of
359 // plaintext to |out|. It returns one on success and zero otherwise.
360 //
361 // This function may be called concurrently with itself or any other seal/open
362 // function on the same |EVP_AEAD_CTX|.
363 //
364 // The length of |nonce|, |nonce_len|, must be equal to the result of
365 // |EVP_AEAD_nonce_length| for this AEAD.
366 //
367 // |EVP_AEAD_CTX_open_gather| never results in a partial output. If any error
368 // occurs, |out| will be filled with zero bytes.
369 //
370 // If |in| and |out| alias then |out| must be == |in|.
371 OPENSSL_EXPORT int EVP_AEAD_CTX_open_gather(
372 const EVP_AEAD_CTX *ctx, uint8_t *out, const uint8_t *nonce,
373 size_t nonce_len, const uint8_t *in, size_t in_len, const uint8_t *in_tag,
374 size_t in_tag_len, const uint8_t *ad, size_t ad_len);
375
376 // EVP_AEAD_CTX_aead returns the underlying AEAD for |ctx|, or NULL if one has
377 // not been set.
378 OPENSSL_EXPORT const EVP_AEAD *EVP_AEAD_CTX_aead(const EVP_AEAD_CTX *ctx);
379
380
381 // TLS-specific AEAD algorithms.
382 //
383 // These AEAD primitives do not meet the definition of generic AEADs. They are
384 // all specific to TLS and should not be used outside of that context. They must
385 // be initialized with |EVP_AEAD_CTX_init_with_direction|, are stateful, and may
386 // not be used concurrently. Any nonces are used as IVs, so they must be
387 // unpredictable. They only accept an |ad| parameter of length 11 (the standard
388 // TLS one with length omitted).
389
390 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_cbc_sha1_tls(void);
391 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_cbc_sha1_tls_implicit_iv(void);
392
393 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_cbc_sha1_tls(void);
394 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_cbc_sha1_tls_implicit_iv(void);
395
396 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_cbc_sha256_tls(void);
397 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_cbc_sha256_tls_implicit_iv(
398 void);
399
400 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_cbc_sha384_tls(void);
401
402 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_des_ede3_cbc_sha1_tls(void);
403 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_des_ede3_cbc_sha1_tls_implicit_iv(void);
404
405 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_null_sha1_tls(void);
406
407 // EVP_aead_aes_128_gcm_tls12 is AES-128 in Galois Counter Mode using the TLS
408 // 1.2 nonce construction.
409 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_gcm_tls12(void);
410
411 // EVP_aead_aes_256_gcm_tls12 is AES-256 in Galois Counter Mode using the TLS
412 // 1.2 nonce construction.
413 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_gcm_tls12(void);
414
415 // EVP_aead_aes_128_gcm_tls13 is AES-128 in Galois Counter Mode using the TLS
416 // 1.3 nonce construction.
417 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_gcm_tls13(void);
418
419 // EVP_aead_aes_256_gcm_tls13 is AES-256 in Galois Counter Mode using the TLS
420 // 1.3 nonce construction.
421 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_gcm_tls13(void);
422
423
424 // Obscure functions.
425
426 // evp_aead_direction_t denotes the direction of an AEAD operation.
427 enum evp_aead_direction_t {
428 evp_aead_open,
429 evp_aead_seal
430 };
431
432 // EVP_AEAD_CTX_init_with_direction calls |EVP_AEAD_CTX_init| for normal
433 // AEADs. For TLS-specific and SSL3-specific AEADs, it initializes |ctx| for a
434 // given direction.
435 OPENSSL_EXPORT int EVP_AEAD_CTX_init_with_direction(
436 EVP_AEAD_CTX *ctx, const EVP_AEAD *aead, const uint8_t *key, size_t key_len,
437 size_t tag_len, enum evp_aead_direction_t dir);
438
439 // EVP_AEAD_CTX_get_iv sets |*out_len| to the length of the IV for |ctx| and
440 // sets |*out_iv| to point to that many bytes of the current IV. This is only
441 // meaningful for AEADs with implicit IVs (i.e. CBC mode in TLS 1.0).
442 //
443 // It returns one on success or zero on error.
444 OPENSSL_EXPORT int EVP_AEAD_CTX_get_iv(const EVP_AEAD_CTX *ctx,
445 const uint8_t **out_iv, size_t *out_len);
446
447 // EVP_AEAD_CTX_tag_len computes the exact byte length of the tag written by
448 // |EVP_AEAD_CTX_seal_scatter| and writes it to |*out_tag_len|. It returns one
449 // on success or zero on error. |in_len| and |extra_in_len| must equal the
450 // arguments of the same names passed to |EVP_AEAD_CTX_seal_scatter|.
451 OPENSSL_EXPORT int EVP_AEAD_CTX_tag_len(const EVP_AEAD_CTX *ctx,
452 size_t *out_tag_len,
453 const size_t in_len,
454 const size_t extra_in_len);
455
456 #define FIPS_AES_GCM_NONCE_LENGTH 12
457
458 // EVP_AEAD_get_iv_from_ipv4_nanosecs computes a deterministic IV compliant with
459 // NIST SP 800-38D, built from an IPv4 address and the number of nanoseconds
460 // since boot, writing it to |out_iv| (in little endian).
461 // It returns one on success or zero for error.
462 //
463 // This is not a general-purpose API, you should not be using it unless you
464 // specifically know you need to use this.
465 OPENSSL_EXPORT int EVP_AEAD_get_iv_from_ipv4_nanosecs(
466 const uint32_t ipv4_address, const uint64_t nanosecs,
467 uint8_t out_iv[FIPS_AES_GCM_NONCE_LENGTH]);
468
469
470 #if defined(__cplusplus)
471 } // extern C
472
473 #if !defined(BORINGSSL_NO_CXX)
474 extern "C++" {
475
476 BSSL_NAMESPACE_BEGIN
477
478 using ScopedEVP_AEAD_CTX =
479 internal::StackAllocated<EVP_AEAD_CTX, void, EVP_AEAD_CTX_zero,
480 EVP_AEAD_CTX_cleanup>;
481
482 BORINGSSL_MAKE_DELETER(EVP_AEAD_CTX, EVP_AEAD_CTX_free)
483
484 BSSL_NAMESPACE_END
485
486 } // extern C++
487 #endif
488
489 #endif
490
491 #endif // OPENSSL_HEADER_AEAD_H