blob: 1d5019710308c57110ef9d3df3592671826b9724 [file] [log] [blame]
Adam Langleyd9e397b2015-01-22 14:27:53 -08001/* Copyright (c) 2014, Google Inc.
2 *
3 * Permission to use, copy, modify, and/or distribute this software for any
4 * purpose with or without fee is hereby granted, provided that the above
5 * copyright notice and this permission notice appear in all copies.
6 *
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
15#ifndef OPENSSL_HEADER_AEAD_H
16#define OPENSSL_HEADER_AEAD_H
17
18#include <openssl/base.h>
19
20#if defined(__cplusplus)
21extern "C" {
22#endif
23
24
Robert Sloan8f860b12017-08-28 07:37:06 -070025// Authenticated Encryption with Additional Data.
26//
27// AEAD couples confidentiality and integrity in a single primitive. AEAD
28// algorithms take a key and then can seal and open individual messages. Each
29// message has a unique, per-message nonce and, optionally, additional data
30// which is authenticated but not included in the ciphertext.
31//
32// The |EVP_AEAD_CTX_init| function initialises an |EVP_AEAD_CTX| structure and
33// performs any precomputation needed to use |aead| with |key|. The length of
34// the key, |key_len|, is given in bytes.
35//
36// The |tag_len| argument contains the length of the tags, in bytes, and allows
37// for the processing of truncated authenticators. A zero value indicates that
38// the default tag length should be used and this is defined as
39// |EVP_AEAD_DEFAULT_TAG_LENGTH| in order to make the code clear. Using
40// truncated tags increases an attacker's chance of creating a valid forgery.
41// Be aware that the attacker's chance may increase more than exponentially as
42// would naively be expected.
43//
44// When no longer needed, the initialised |EVP_AEAD_CTX| structure must be
45// passed to |EVP_AEAD_CTX_cleanup|, which will deallocate any memory used.
46//
47// With an |EVP_AEAD_CTX| in hand, one can seal and open messages. These
48// operations are intended to meet the standard notions of privacy and
49// authenticity for authenticated encryption. For formal definitions see
50// Bellare and Namprempre, "Authenticated encryption: relations among notions
51// and analysis of the generic composition paradigm," Lecture Notes in Computer
52// Science B<1976> (2000), 531–545,
53// http://www-cse.ucsd.edu/~mihir/papers/oem.html.
54//
55// When sealing messages, a nonce must be given. The length of the nonce is
56// fixed by the AEAD in use and is returned by |EVP_AEAD_nonce_length|. *The
57// nonce must be unique for all messages with the same key*. This is critically
58// important - nonce reuse may completely undermine the security of the AEAD.
59// Nonces may be predictable and public, so long as they are unique. Uniqueness
60// may be achieved with a simple counter or, if large enough, may be generated
61// randomly. The nonce must be passed into the "open" operation by the receiver
62// so must either be implicit (e.g. a counter), or must be transmitted along
63// with the sealed message.
64//
65// The "seal" and "open" operations are atomic - an entire message must be
66// encrypted or decrypted in a single call. Large messages may have to be split
67// up in order to accommodate this. When doing so, be mindful of the need not to
68// repeat nonces and the possibility that an attacker could duplicate, reorder
69// or drop message chunks. For example, using a single key for a given (large)
70// message and sealing chunks with nonces counting from zero would be secure as
71// long as the number of chunks was securely transmitted. (Otherwise an
72// attacker could truncate the message by dropping chunks from the end.)
73//
74// The number of chunks could be transmitted by prefixing it to the plaintext,
75// for example. This also assumes that no other message would ever use the same
76// key otherwise the rule that nonces must be unique for a given key would be
77// violated.
78//
79// The "seal" and "open" operations also permit additional data to be
80// authenticated via the |ad| parameter. This data is not included in the
81// ciphertext and must be identical for both the "seal" and "open" call. This
82// permits implicit context to be authenticated but may be empty if not needed.
83//
84// The "seal" and "open" operations may work in-place if the |out| and |in|
85// arguments are equal. Otherwise, if |out| and |in| alias, input data may be
86// overwritten before it is read. This situation will cause an error.
87//
88// The "seal" and "open" operations return one on success and zero on error.
Adam Langleyd9e397b2015-01-22 14:27:53 -080089
90
Robert Sloan8f860b12017-08-28 07:37:06 -070091// AEAD algorithms.
Adam Langleyd9e397b2015-01-22 14:27:53 -080092
Robert Sloan8f860b12017-08-28 07:37:06 -070093// EVP_aead_aes_128_gcm is AES-128 in Galois Counter Mode.
Adam Langleyd9e397b2015-01-22 14:27:53 -080094OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_gcm(void);
95
Robert Sloan8f860b12017-08-28 07:37:06 -070096// EVP_aead_aes_256_gcm is AES-256 in Galois Counter Mode.
Adam Langleyd9e397b2015-01-22 14:27:53 -080097OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_gcm(void);
98
Robert Sloan8f860b12017-08-28 07:37:06 -070099// EVP_aead_chacha20_poly1305 is the AEAD built from ChaCha20 and
100// Poly1305 as described in RFC 7539.
Adam Langley4139edb2016-01-13 15:00:54 -0800101OPENSSL_EXPORT const EVP_AEAD *EVP_aead_chacha20_poly1305(void);
102
Robert Sloan8f860b12017-08-28 07:37:06 -0700103// EVP_aead_aes_128_ctr_hmac_sha256 is AES-128 in CTR mode with HMAC-SHA256 for
104// authentication. The nonce is 12 bytes; the bottom 32-bits are used as the
105// block counter, thus the maximum plaintext size is 64GB.
Adam Langleye9ada862015-05-11 17:20:37 -0700106OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_ctr_hmac_sha256(void);
107
Robert Sloan8f860b12017-08-28 07:37:06 -0700108// EVP_aead_aes_256_ctr_hmac_sha256 is AES-256 in CTR mode with HMAC-SHA256 for
109// authentication. See |EVP_aead_aes_128_ctr_hmac_sha256| for details.
Adam Langleye9ada862015-05-11 17:20:37 -0700110OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_ctr_hmac_sha256(void);
111
Robert Sloan8f860b12017-08-28 07:37:06 -0700112// EVP_aead_aes_128_gcm_siv is AES-128 in GCM-SIV mode. See
113// https://tools.ietf.org/html/draft-irtf-cfrg-gcmsiv-02
David Benjamin1b249672016-12-06 18:25:50 -0500114OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_gcm_siv(void);
115
Robert Sloan8f860b12017-08-28 07:37:06 -0700116// EVP_aead_aes_256_gcm_siv is AES-256 in GCM-SIV mode. See
117// https://tools.ietf.org/html/draft-irtf-cfrg-gcmsiv-02
David Benjamin1b249672016-12-06 18:25:50 -0500118OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_gcm_siv(void);
119
Robert Sloanab8b8882018-03-26 11:39:51 -0700120// EVP_aead_aes_128_ccm_bluetooth is AES-128-CCM with M=4 and L=2 (4-byte tags
121// and 13-byte nonces), as decribed in the Bluetooth Core Specification v5.0,
122// Volume 6, Part E, Section 1.
123OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_ccm_bluetooth(void);
124
125// EVP_aead_aes_128_ccm_bluetooth_8 is AES-128-CCM with M=8 and L=2 (8-byte tags
126// and 13-byte nonces), as used in the Bluetooth Mesh Networking Specification
127// v1.0.
128OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_ccm_bluetooth_8(void);
129
Robert Sloan8f860b12017-08-28 07:37:06 -0700130// EVP_has_aes_hardware returns one if we enable hardware support for fast and
131// constant-time AES-GCM.
Adam Langleyd9e397b2015-01-22 14:27:53 -0800132OPENSSL_EXPORT int EVP_has_aes_hardware(void);
133
134
Robert Sloan8f860b12017-08-28 07:37:06 -0700135// Utility functions.
Adam Langleyd9e397b2015-01-22 14:27:53 -0800136
Robert Sloan8f860b12017-08-28 07:37:06 -0700137// EVP_AEAD_key_length returns the length, in bytes, of the keys used by
138// |aead|.
Adam Langleyd9e397b2015-01-22 14:27:53 -0800139OPENSSL_EXPORT size_t EVP_AEAD_key_length(const EVP_AEAD *aead);
140
Robert Sloan8f860b12017-08-28 07:37:06 -0700141// EVP_AEAD_nonce_length returns the length, in bytes, of the per-message nonce
142// for |aead|.
Adam Langleyd9e397b2015-01-22 14:27:53 -0800143OPENSSL_EXPORT size_t EVP_AEAD_nonce_length(const EVP_AEAD *aead);
144
Robert Sloan8f860b12017-08-28 07:37:06 -0700145// EVP_AEAD_max_overhead returns the maximum number of additional bytes added
146// by the act of sealing data with |aead|.
Adam Langleyd9e397b2015-01-22 14:27:53 -0800147OPENSSL_EXPORT size_t EVP_AEAD_max_overhead(const EVP_AEAD *aead);
148
Robert Sloan8f860b12017-08-28 07:37:06 -0700149// EVP_AEAD_max_tag_len returns the maximum tag length when using |aead|. This
150// is the largest value that can be passed as |tag_len| to
151// |EVP_AEAD_CTX_init|.
Adam Langleyd9e397b2015-01-22 14:27:53 -0800152OPENSSL_EXPORT size_t EVP_AEAD_max_tag_len(const EVP_AEAD *aead);
153
154
Robert Sloan8f860b12017-08-28 07:37:06 -0700155// AEAD operations.
Adam Langleyd9e397b2015-01-22 14:27:53 -0800156
Robert Sloan8f860b12017-08-28 07:37:06 -0700157// An EVP_AEAD_CTX represents an AEAD algorithm configured with a specific key
158// and message-independent IV.
Adam Langleyd9e397b2015-01-22 14:27:53 -0800159typedef struct evp_aead_ctx_st {
160 const EVP_AEAD *aead;
Robert Sloan8f860b12017-08-28 07:37:06 -0700161 // aead_state is an opaque pointer to whatever state the AEAD needs to
162 // maintain.
Adam Langleyd9e397b2015-01-22 14:27:53 -0800163 void *aead_state;
Robert Sloan8f860b12017-08-28 07:37:06 -0700164 // tag_len may contain the actual length of the authentication tag if it is
165 // known at initialization time.
Robert Sloan8ff03552017-06-14 12:40:58 -0700166 uint8_t tag_len;
Adam Langleyd9e397b2015-01-22 14:27:53 -0800167} EVP_AEAD_CTX;
168
Robert Sloan8f860b12017-08-28 07:37:06 -0700169// EVP_AEAD_MAX_KEY_LENGTH contains the maximum key length used by
170// any AEAD defined in this header.
Adam Langleyd9e397b2015-01-22 14:27:53 -0800171#define EVP_AEAD_MAX_KEY_LENGTH 80
172
Robert Sloan8f860b12017-08-28 07:37:06 -0700173// EVP_AEAD_MAX_NONCE_LENGTH contains the maximum nonce length used by
174// any AEAD defined in this header.
Adam Langleyd9e397b2015-01-22 14:27:53 -0800175#define EVP_AEAD_MAX_NONCE_LENGTH 16
176
Robert Sloan8f860b12017-08-28 07:37:06 -0700177// EVP_AEAD_MAX_OVERHEAD contains the maximum overhead used by any AEAD
178// defined in this header.
Adam Langleyd9e397b2015-01-22 14:27:53 -0800179#define EVP_AEAD_MAX_OVERHEAD 64
180
Robert Sloan8f860b12017-08-28 07:37:06 -0700181// EVP_AEAD_DEFAULT_TAG_LENGTH is a magic value that can be passed to
182// EVP_AEAD_CTX_init to indicate that the default tag length for an AEAD should
183// be used.
Adam Langleyd9e397b2015-01-22 14:27:53 -0800184#define EVP_AEAD_DEFAULT_TAG_LENGTH 0
185
Robert Sloan8f860b12017-08-28 07:37:06 -0700186// EVP_AEAD_CTX_zero sets an uninitialized |ctx| to the zero state. It must be
187// initialized with |EVP_AEAD_CTX_init| before use. It is safe, but not
188// necessary, to call |EVP_AEAD_CTX_cleanup| in this state. This may be used for
189// more uniform cleanup of |EVP_AEAD_CTX|.
Kenny Rootb8494592015-09-25 02:29:14 +0000190OPENSSL_EXPORT void EVP_AEAD_CTX_zero(EVP_AEAD_CTX *ctx);
191
Robert Sloan8f860b12017-08-28 07:37:06 -0700192// EVP_AEAD_CTX_new allocates an |EVP_AEAD_CTX|, calls |EVP_AEAD_CTX_init| and
193// returns the |EVP_AEAD_CTX|, or NULL on error.
Robert Sloan8ff03552017-06-14 12:40:58 -0700194OPENSSL_EXPORT EVP_AEAD_CTX *EVP_AEAD_CTX_new(const EVP_AEAD *aead,
195 const uint8_t *key,
196 size_t key_len, size_t tag_len);
197
Robert Sloan8f860b12017-08-28 07:37:06 -0700198// EVP_AEAD_CTX_free calls |EVP_AEAD_CTX_cleanup| and |OPENSSL_free| on
199// |ctx|.
Robert Sloan8ff03552017-06-14 12:40:58 -0700200OPENSSL_EXPORT void EVP_AEAD_CTX_free(EVP_AEAD_CTX *ctx);
201
Robert Sloan8f860b12017-08-28 07:37:06 -0700202// EVP_AEAD_CTX_init initializes |ctx| for the given AEAD algorithm. The |impl|
203// argument is ignored and should be NULL. Authentication tags may be truncated
204// by passing a size as |tag_len|. A |tag_len| of zero indicates the default
205// tag length and this is defined as EVP_AEAD_DEFAULT_TAG_LENGTH for
206// readability.
207//
208// Returns 1 on success. Otherwise returns 0 and pushes to the error stack. In
209// the error case, you do not need to call |EVP_AEAD_CTX_cleanup|, but it's
210// harmless to do so.
Adam Langleyd9e397b2015-01-22 14:27:53 -0800211OPENSSL_EXPORT int EVP_AEAD_CTX_init(EVP_AEAD_CTX *ctx, const EVP_AEAD *aead,
212 const uint8_t *key, size_t key_len,
213 size_t tag_len, ENGINE *impl);
214
Robert Sloan8f860b12017-08-28 07:37:06 -0700215// EVP_AEAD_CTX_cleanup frees any data allocated by |ctx|. It is a no-op to
216// call |EVP_AEAD_CTX_cleanup| on a |EVP_AEAD_CTX| that has been |memset| to
217// all zeros.
Adam Langleyd9e397b2015-01-22 14:27:53 -0800218OPENSSL_EXPORT void EVP_AEAD_CTX_cleanup(EVP_AEAD_CTX *ctx);
219
Robert Sloan8f860b12017-08-28 07:37:06 -0700220// EVP_AEAD_CTX_seal encrypts and authenticates |in_len| bytes from |in| and
221// authenticates |ad_len| bytes from |ad| and writes the result to |out|. It
222// returns one on success and zero otherwise.
223//
224// This function may be called concurrently with itself or any other seal/open
225// function on the same |EVP_AEAD_CTX|.
226//
227// At most |max_out_len| bytes are written to |out| and, in order to ensure
228// success, |max_out_len| should be |in_len| plus the result of
229// |EVP_AEAD_max_overhead|. On successful return, |*out_len| is set to the
230// actual number of bytes written.
231//
232// The length of |nonce|, |nonce_len|, must be equal to the result of
233// |EVP_AEAD_nonce_length| for this AEAD.
234//
235// |EVP_AEAD_CTX_seal| never results in a partial output. If |max_out_len| is
236// insufficient, zero will be returned. If any error occurs, |out| will be
237// filled with zero bytes and |*out_len| set to zero.
238//
239// If |in| and |out| alias then |out| must be == |in|.
Adam Langleyd9e397b2015-01-22 14:27:53 -0800240OPENSSL_EXPORT int EVP_AEAD_CTX_seal(const EVP_AEAD_CTX *ctx, uint8_t *out,
241 size_t *out_len, size_t max_out_len,
242 const uint8_t *nonce, size_t nonce_len,
243 const uint8_t *in, size_t in_len,
244 const uint8_t *ad, size_t ad_len);
Robert Sloane56da3e2017-06-26 08:26:42 -0700245
Robert Sloan8f860b12017-08-28 07:37:06 -0700246// EVP_AEAD_CTX_open authenticates |in_len| bytes from |in| and |ad_len| bytes
247// from |ad| and decrypts at most |in_len| bytes into |out|. It returns one on
248// success and zero otherwise.
249//
250// This function may be called concurrently with itself or any other seal/open
251// function on the same |EVP_AEAD_CTX|.
252//
253// At most |in_len| bytes are written to |out|. In order to ensure success,
254// |max_out_len| should be at least |in_len|. On successful return, |*out_len|
255// is set to the the actual number of bytes written.
256//
257// The length of |nonce|, |nonce_len|, must be equal to the result of
258// |EVP_AEAD_nonce_length| for this AEAD.
259//
260// |EVP_AEAD_CTX_open| never results in a partial output. If |max_out_len| is
261// insufficient, zero will be returned. If any error occurs, |out| will be
262// filled with zero bytes and |*out_len| set to zero.
263//
264// If |in| and |out| alias then |out| must be == |in|.
Adam Langleyd9e397b2015-01-22 14:27:53 -0800265OPENSSL_EXPORT int EVP_AEAD_CTX_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
266 size_t *out_len, size_t max_out_len,
267 const uint8_t *nonce, size_t nonce_len,
268 const uint8_t *in, size_t in_len,
269 const uint8_t *ad, size_t ad_len);
270
Robert Sloan8f860b12017-08-28 07:37:06 -0700271// EVP_AEAD_CTX_seal_scatter encrypts and authenticates |in_len| bytes from |in|
272// and authenticates |ad_len| bytes from |ad|. It writes |in_len| bytes of
273// ciphertext to |out| and the authentication tag to |out_tag|. It returns one
274// on success and zero otherwise.
275//
276// This function may be called concurrently with itself or any other seal/open
277// function on the same |EVP_AEAD_CTX|.
278//
279// Exactly |in_len| bytes are written to |out|, and up to
280// |EVP_AEAD_max_overhead+extra_in_len| bytes to |out_tag|. On successful
281// return, |*out_tag_len| is set to the actual number of bytes written to
282// |out_tag|.
283//
284// |extra_in| may point to an additional plaintext input buffer if the cipher
285// supports it. If present, |extra_in_len| additional bytes of plaintext are
286// encrypted and authenticated, and the ciphertext is written (before the tag)
287// to |out_tag|. |max_out_tag_len| must be sized to allow for the additional
288// |extra_in_len| bytes.
289//
290// The length of |nonce|, |nonce_len|, must be equal to the result of
291// |EVP_AEAD_nonce_length| for this AEAD.
292//
293// |EVP_AEAD_CTX_seal_scatter| never results in a partial output. If
294// |max_out_tag_len| is insufficient, zero will be returned. If any error
295// occurs, |out| and |out_tag| will be filled with zero bytes and |*out_tag_len|
296// set to zero.
297//
298// If |in| and |out| alias then |out| must be == |in|. |out_tag| may not alias
299// any other argument.
Robert Sloan8ff03552017-06-14 12:40:58 -0700300OPENSSL_EXPORT int EVP_AEAD_CTX_seal_scatter(
Robert Sloan927a4952017-07-03 11:25:09 -0700301 const EVP_AEAD_CTX *ctx, uint8_t *out,
302 uint8_t *out_tag, size_t *out_tag_len, size_t max_out_tag_len,
303 const uint8_t *nonce, size_t nonce_len,
304 const uint8_t *in, size_t in_len,
305 const uint8_t *extra_in, size_t extra_in_len,
306 const uint8_t *ad, size_t ad_len);
Robert Sloan8ff03552017-06-14 12:40:58 -0700307
Robert Sloan8f860b12017-08-28 07:37:06 -0700308// EVP_AEAD_CTX_open_gather decrypts and authenticates |in_len| bytes from |in|
309// and authenticates |ad_len| bytes from |ad| using |in_tag_len| bytes of
310// authentication tag from |in_tag|. If successful, it writes |in_len| bytes of
311// plaintext to |out|. It returns one on success and zero otherwise.
312//
313// This function may be called concurrently with itself or any other seal/open
314// function on the same |EVP_AEAD_CTX|.
315//
316// The length of |nonce|, |nonce_len|, must be equal to the result of
317// |EVP_AEAD_nonce_length| for this AEAD.
318//
319// |EVP_AEAD_CTX_open_gather| never results in a partial output. If any error
320// occurs, |out| will be filled with zero bytes.
321//
322// If |in| and |out| alias then |out| must be == |in|.
Robert Sloan8ff03552017-06-14 12:40:58 -0700323OPENSSL_EXPORT int EVP_AEAD_CTX_open_gather(
324 const EVP_AEAD_CTX *ctx, uint8_t *out, const uint8_t *nonce,
325 size_t nonce_len, const uint8_t *in, size_t in_len, const uint8_t *in_tag,
326 size_t in_tag_len, const uint8_t *ad, size_t ad_len);
327
Robert Sloan8f860b12017-08-28 07:37:06 -0700328// EVP_AEAD_CTX_aead returns the underlying AEAD for |ctx|, or NULL if one has
329// not been set.
David Benjamin7c0d06c2016-08-11 13:26:41 -0400330OPENSSL_EXPORT const EVP_AEAD *EVP_AEAD_CTX_aead(const EVP_AEAD_CTX *ctx);
331
Adam Langleyd9e397b2015-01-22 14:27:53 -0800332
Robert Sloan8f860b12017-08-28 07:37:06 -0700333// TLS-specific AEAD algorithms.
334//
335// These AEAD primitives do not meet the definition of generic AEADs. They are
336// all specific to TLS and should not be used outside of that context. They must
337// be initialized with |EVP_AEAD_CTX_init_with_direction|, are stateful, and may
338// not be used concurrently. Any nonces are used as IVs, so they must be
339// unpredictable. They only accept an |ad| parameter of length 11 (the standard
340// TLS one with length omitted).
David Benjamin4969cc92016-04-22 15:02:23 -0400341
David Benjamin4969cc92016-04-22 15:02:23 -0400342OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_cbc_sha1_tls(void);
343OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_cbc_sha1_tls_implicit_iv(void);
344OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_cbc_sha256_tls(void);
345
346OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_cbc_sha1_tls(void);
347OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_cbc_sha1_tls_implicit_iv(void);
348OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_cbc_sha256_tls(void);
349OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_cbc_sha384_tls(void);
350
351OPENSSL_EXPORT const EVP_AEAD *EVP_aead_des_ede3_cbc_sha1_tls(void);
352OPENSSL_EXPORT const EVP_AEAD *EVP_aead_des_ede3_cbc_sha1_tls_implicit_iv(void);
353
354OPENSSL_EXPORT const EVP_AEAD *EVP_aead_null_sha1_tls(void);
355
Robert Sloan8f860b12017-08-28 07:37:06 -0700356// EVP_aead_aes_128_gcm_tls12 is AES-128 in Galois Counter Mode using the TLS
357// 1.2 nonce construction.
Robert Sloan8ff03552017-06-14 12:40:58 -0700358OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_gcm_tls12(void);
359
Robert Sloan8f860b12017-08-28 07:37:06 -0700360// EVP_aead_aes_256_gcm_tls12 is AES-256 in Galois Counter Mode using the TLS
361// 1.2 nonce construction.
Robert Sloan8ff03552017-06-14 12:40:58 -0700362OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_gcm_tls12(void);
363
David Benjamin4969cc92016-04-22 15:02:23 -0400364
Robert Sloan8f860b12017-08-28 07:37:06 -0700365// SSLv3-specific AEAD algorithms.
366//
367// These AEAD primitives do not meet the definition of generic AEADs. They are
368// all specific to SSLv3 and should not be used outside of that context. They
369// must be initialized with |EVP_AEAD_CTX_init_with_direction|, are stateful,
370// and may not be used concurrently. They only accept an |ad| parameter of
371// length 9 (the standard TLS one with length and version omitted).
David Benjamin4969cc92016-04-22 15:02:23 -0400372
David Benjamin4969cc92016-04-22 15:02:23 -0400373OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_cbc_sha1_ssl3(void);
374OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_cbc_sha1_ssl3(void);
375OPENSSL_EXPORT const EVP_AEAD *EVP_aead_des_ede3_cbc_sha1_ssl3(void);
376OPENSSL_EXPORT const EVP_AEAD *EVP_aead_null_sha1_ssl3(void);
377
378
Robert Sloan8f860b12017-08-28 07:37:06 -0700379// Obscure functions.
Adam Langleye9ada862015-05-11 17:20:37 -0700380
Robert Sloan8f860b12017-08-28 07:37:06 -0700381// evp_aead_direction_t denotes the direction of an AEAD operation.
David Benjamin4969cc92016-04-22 15:02:23 -0400382enum evp_aead_direction_t {
383 evp_aead_open,
384 evp_aead_seal,
385};
386
Robert Sloan8f860b12017-08-28 07:37:06 -0700387// EVP_AEAD_CTX_init_with_direction calls |EVP_AEAD_CTX_init| for normal
388// AEADs. For TLS-specific and SSL3-specific AEADs, it initializes |ctx| for a
389// given direction.
David Benjamin4969cc92016-04-22 15:02:23 -0400390OPENSSL_EXPORT int EVP_AEAD_CTX_init_with_direction(
391 EVP_AEAD_CTX *ctx, const EVP_AEAD *aead, const uint8_t *key, size_t key_len,
392 size_t tag_len, enum evp_aead_direction_t dir);
393
Robert Sloan8f860b12017-08-28 07:37:06 -0700394// EVP_AEAD_CTX_get_iv sets |*out_len| to the length of the IV for |ctx| and
395// sets |*out_iv| to point to that many bytes of the current IV. This is only
396// meaningful for AEADs with implicit IVs (i.e. CBC mode in SSLv3 and TLS 1.0).
397//
398// It returns one on success or zero on error.
Adam Langleyfad63272015-11-12 12:15:39 -0800399OPENSSL_EXPORT int EVP_AEAD_CTX_get_iv(const EVP_AEAD_CTX *ctx,
400 const uint8_t **out_iv, size_t *out_len);
401
Robert Sloan8f860b12017-08-28 07:37:06 -0700402// EVP_AEAD_CTX_tag_len computes the exact byte length of the tag written by
403// |EVP_AEAD_CTX_seal_scatter| and writes it to |*out_tag_len|. It returns one
404// on success or zero on error. |in_len| and |extra_in_len| must equal the
405// arguments of the same names passed to |EVP_AEAD_CTX_seal_scatter|.
Robert Sloanfe7cd212017-08-07 09:03:39 -0700406OPENSSL_EXPORT int EVP_AEAD_CTX_tag_len(const EVP_AEAD_CTX *ctx,
407 size_t *out_tag_len,
408 const size_t in_len,
409 const size_t extra_in_len);
410
Adam Langleye9ada862015-05-11 17:20:37 -0700411
Adam Langleyd9e397b2015-01-22 14:27:53 -0800412#if defined(__cplusplus)
Robert Sloan8f860b12017-08-28 07:37:06 -0700413} // extern C
David Benjaminf0c4a6c2016-08-11 13:26:41 -0400414
415#if !defined(BORINGSSL_NO_CXX)
416extern "C++" {
417
418namespace bssl {
419
420using ScopedEVP_AEAD_CTX =
421 internal::StackAllocated<EVP_AEAD_CTX, void, EVP_AEAD_CTX_zero,
422 EVP_AEAD_CTX_cleanup>;
423
Robert Sloan8ff03552017-06-14 12:40:58 -0700424BORINGSSL_MAKE_DELETER(EVP_AEAD_CTX, EVP_AEAD_CTX_free)
425
David Benjaminf0c4a6c2016-08-11 13:26:41 -0400426} // namespace bssl
427
428} // extern C++
429#endif
430
Adam Langleyd9e397b2015-01-22 14:27:53 -0800431#endif
432
Robert Sloan8f860b12017-08-28 07:37:06 -0700433#endif // OPENSSL_HEADER_AEAD_H