aead.h (22675B)
1 // Copyright 2014 The BoringSSL Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef OPENSSL_HEADER_AEAD_H 16 #define OPENSSL_HEADER_AEAD_H 17 18 #include <openssl/base.h> // IWYU pragma: export 19 20 #if defined(__cplusplus) 21 extern "C" { 22 #endif 23 24 25 // 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. 89 90 91 // AEAD algorithms. 92 93 // EVP_aead_aes_128_gcm is AES-128 in Galois Counter Mode. 94 // 95 // Note: AES-GCM should only be used with 12-byte (96-bit) nonces. Although it 96 // is specified to take a variable-length nonce, nonces with other lengths are 97 // effectively randomized, which means one must consider collisions. Unless 98 // implementing an existing protocol which has already specified incorrect 99 // parameters, only use 12-byte nonces. 100 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_gcm(void); 101 102 // EVP_aead_aes_192_gcm is AES-192 in Galois Counter Mode. 103 // 104 // WARNING: AES-192 is superfluous and shouldn't exist. NIST should never have 105 // defined it. Use only when interop with another system requires it, never 106 // de novo. 107 // 108 // Note: AES-GCM should only be used with 12-byte (96-bit) nonces. Although it 109 // is specified to take a variable-length nonce, nonces with other lengths are 110 // effectively randomized, which means one must consider collisions. Unless 111 // implementing an existing protocol which has already specified incorrect 112 // parameters, only use 12-byte nonces. 113 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_192_gcm(void); 114 115 // EVP_aead_aes_256_gcm is AES-256 in Galois Counter Mode. 116 // 117 // Note: AES-GCM should only be used with 12-byte (96-bit) nonces. Although it 118 // is specified to take a variable-length nonce, nonces with other lengths are 119 // effectively randomized, which means one must consider collisions. Unless 120 // implementing an existing protocol which has already specified incorrect 121 // parameters, only use 12-byte nonces. 122 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_gcm(void); 123 124 // EVP_aead_chacha20_poly1305 is the AEAD built from ChaCha20 and 125 // Poly1305 as described in RFC 8439. 126 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_chacha20_poly1305(void); 127 128 // EVP_aead_xchacha20_poly1305 is ChaCha20-Poly1305 with an extended nonce that 129 // makes random generation of nonces safe. 130 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_xchacha20_poly1305(void); 131 132 // EVP_aead_aes_128_ctr_hmac_sha256 is AES-128 in CTR mode with HMAC-SHA256 for 133 // authentication. The nonce is 12 bytes; the bottom 32-bits are used as the 134 // block counter, thus the maximum plaintext size is 64GB. 135 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_ctr_hmac_sha256(void); 136 137 // EVP_aead_aes_256_ctr_hmac_sha256 is AES-256 in CTR mode with HMAC-SHA256 for 138 // authentication. See |EVP_aead_aes_128_ctr_hmac_sha256| for details. 139 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_ctr_hmac_sha256(void); 140 141 // EVP_aead_aes_128_gcm_siv is AES-128 in GCM-SIV mode. See RFC 8452. 142 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_gcm_siv(void); 143 144 // EVP_aead_aes_256_gcm_siv is AES-256 in GCM-SIV mode. See RFC 8452. 145 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_gcm_siv(void); 146 147 // EVP_aead_aes_128_gcm_randnonce is AES-128 in Galois Counter Mode with 148 // internal nonce generation. The 12-byte nonce is appended to the tag 149 // and is generated internally. The "tag", for the purpurses of the API, is thus 150 // 12 bytes larger. The nonce parameter when using this AEAD must be 151 // zero-length. Since the nonce is random, a single key should not be used for 152 // more than 2^32 seal operations. 153 // 154 // Warning: this is for use for FIPS compliance only. It is probably not 155 // suitable for other uses. Using standard AES-GCM AEADs allows one to achieve 156 // the same effect, but gives more control over nonce storage. 157 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_gcm_randnonce(void); 158 159 // EVP_aead_aes_256_gcm_randnonce is AES-256 in Galois Counter Mode with 160 // internal nonce generation. The 12-byte nonce is appended to the tag 161 // and is generated internally. The "tag", for the purpurses of the API, is thus 162 // 12 bytes larger. The nonce parameter when using this AEAD must be 163 // zero-length. Since the nonce is random, a single key should not be used for 164 // more than 2^32 seal operations. 165 // 166 // Warning: this is for use for FIPS compliance only. It is probably not 167 // suitable for other uses. Using standard AES-GCM AEADs allows one to achieve 168 // the same effect, but gives more control over nonce storage. 169 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_gcm_randnonce(void); 170 171 // EVP_aead_aes_128_ccm_bluetooth is AES-128-CCM with M=4 and L=2 (4-byte tags 172 // and 13-byte nonces), as decribed in the Bluetooth Core Specification v5.0, 173 // Volume 6, Part E, Section 1. 174 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_ccm_bluetooth(void); 175 176 // EVP_aead_aes_128_ccm_bluetooth_8 is AES-128-CCM with M=8 and L=2 (8-byte tags 177 // and 13-byte nonces), as used in the Bluetooth Mesh Networking Specification 178 // v1.0. 179 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_ccm_bluetooth_8(void); 180 181 // EVP_aead_aes_128_ccm_matter is AES-128-CCM with M=16 and L=2 (16-byte tags 182 // and 13-byte nonces), as used in the Matter specification. 183 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_ccm_matter(void); 184 185 // EVP_has_aes_hardware returns one if we enable hardware support for fast and 186 // constant-time AES-GCM. 187 OPENSSL_EXPORT int EVP_has_aes_hardware(void); 188 189 // EVP_aead_aes_128_eax is AES-128 in EAX mode. Nonce size is either 12 or 16 190 // bytes, tag length is 16 bytes. 191 // See https://doi.org/10.1007/978-3-540-25937-4_25. 192 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_eax(void); 193 194 // EVP_aead_aes_256_eax is AES-256 in EAX mode. Nonce size is either 12 or 16 195 // bytes, tag length is 16 bytes. 196 // See https://doi.org/10.1007/978-3-540-25937-4_25. 197 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_eax(void); 198 199 200 // Utility functions. 201 202 // EVP_AEAD_key_length returns the length, in bytes, of the keys used by 203 // |aead|. 204 OPENSSL_EXPORT size_t EVP_AEAD_key_length(const EVP_AEAD *aead); 205 206 // EVP_AEAD_nonce_length returns the length, in bytes, of the per-message nonce 207 // for |aead|. 208 OPENSSL_EXPORT size_t EVP_AEAD_nonce_length(const EVP_AEAD *aead); 209 210 // EVP_AEAD_max_overhead returns the maximum number of additional bytes added 211 // by the act of sealing data with |aead|. 212 OPENSSL_EXPORT size_t EVP_AEAD_max_overhead(const EVP_AEAD *aead); 213 214 // EVP_AEAD_max_tag_len returns the maximum tag length when using |aead|. This 215 // is the largest value that can be passed as |tag_len| to 216 // |EVP_AEAD_CTX_init|. 217 OPENSSL_EXPORT size_t EVP_AEAD_max_tag_len(const EVP_AEAD *aead); 218 219 220 // AEAD operations. 221 222 union evp_aead_ctx_st_state { 223 uint8_t opaque[560]; 224 uint64_t alignment; 225 }; 226 227 // An evp_aead_ctx_st (typedefed as |EVP_AEAD_CTX| in base.h) represents an AEAD 228 // algorithm configured with a specific key and message-independent IV. 229 struct evp_aead_ctx_st { 230 const EVP_AEAD *aead; 231 union evp_aead_ctx_st_state state; 232 // tag_len may contain the actual length of the authentication tag if it is 233 // known at initialization time. 234 uint8_t tag_len; 235 }; 236 237 // EVP_AEAD_MAX_KEY_LENGTH contains the maximum key length used by 238 // any AEAD defined in this header. 239 #define EVP_AEAD_MAX_KEY_LENGTH 80 240 241 // EVP_AEAD_MAX_NONCE_LENGTH contains the maximum nonce length used by 242 // any AEAD defined in this header. 243 #define EVP_AEAD_MAX_NONCE_LENGTH 24 244 245 // EVP_AEAD_MAX_OVERHEAD contains the maximum overhead used by any AEAD 246 // defined in this header. 247 #define EVP_AEAD_MAX_OVERHEAD 64 248 249 // EVP_AEAD_DEFAULT_TAG_LENGTH is a magic value that can be passed to 250 // EVP_AEAD_CTX_init to indicate that the default tag length for an AEAD should 251 // be used. 252 #define EVP_AEAD_DEFAULT_TAG_LENGTH 0 253 254 // EVP_AEAD_CTX_zero sets an uninitialized |ctx| to the zero state. It must be 255 // initialized with |EVP_AEAD_CTX_init| before use. It is safe, but not 256 // necessary, to call |EVP_AEAD_CTX_cleanup| in this state. This may be used for 257 // more uniform cleanup of |EVP_AEAD_CTX|. 258 OPENSSL_EXPORT void EVP_AEAD_CTX_zero(EVP_AEAD_CTX *ctx); 259 260 // EVP_AEAD_CTX_new allocates an |EVP_AEAD_CTX|, calls |EVP_AEAD_CTX_init| and 261 // returns the |EVP_AEAD_CTX|, or NULL on error. 262 OPENSSL_EXPORT EVP_AEAD_CTX *EVP_AEAD_CTX_new(const EVP_AEAD *aead, 263 const uint8_t *key, 264 size_t key_len, size_t tag_len); 265 266 // EVP_AEAD_CTX_free calls |EVP_AEAD_CTX_cleanup| and |OPENSSL_free| on 267 // |ctx|. 268 OPENSSL_EXPORT void EVP_AEAD_CTX_free(EVP_AEAD_CTX *ctx); 269 270 // EVP_AEAD_CTX_init initializes |ctx| for the given AEAD algorithm. The |impl| 271 // argument is ignored and should be NULL. Authentication tags may be truncated 272 // by passing a size as |tag_len|. A |tag_len| of zero indicates the default 273 // tag length and this is defined as EVP_AEAD_DEFAULT_TAG_LENGTH for 274 // readability. 275 // 276 // Returns 1 on success. Otherwise returns 0 and pushes to the error stack. In 277 // the error case, you do not need to call |EVP_AEAD_CTX_cleanup|, but it's 278 // harmless to do so. 279 OPENSSL_EXPORT int EVP_AEAD_CTX_init(EVP_AEAD_CTX *ctx, const EVP_AEAD *aead, 280 const uint8_t *key, size_t key_len, 281 size_t tag_len, ENGINE *impl); 282 283 // EVP_AEAD_CTX_cleanup frees any data allocated by |ctx|. It is a no-op to 284 // call |EVP_AEAD_CTX_cleanup| on a |EVP_AEAD_CTX| that has been |memset| to 285 // all zeros. 286 OPENSSL_EXPORT void EVP_AEAD_CTX_cleanup(EVP_AEAD_CTX *ctx); 287 288 // EVP_AEAD_CTX_seal encrypts and authenticates |in_len| bytes from |in| and 289 // authenticates |ad_len| bytes from |ad| and writes the result to |out|. It 290 // returns one on success and zero otherwise. 291 // 292 // This function may be called concurrently with itself or any other seal/open 293 // function on the same |EVP_AEAD_CTX|. 294 // 295 // At most |max_out_len| bytes are written to |out| and, in order to ensure 296 // success, |max_out_len| should be |in_len| plus the result of 297 // |EVP_AEAD_max_overhead|. On successful return, |*out_len| is set to the 298 // actual number of bytes written. 299 // 300 // The length of |nonce|, |nonce_len|, must be equal to the result of 301 // |EVP_AEAD_nonce_length| for this AEAD. 302 // 303 // |EVP_AEAD_CTX_seal| never results in a partial output. If |max_out_len| is 304 // insufficient, zero will be returned. If any error occurs, |out| will be 305 // filled with zero bytes and |*out_len| set to zero. 306 // 307 // If |in| and |out| alias then |out| must be == |in|. 308 OPENSSL_EXPORT int EVP_AEAD_CTX_seal(const EVP_AEAD_CTX *ctx, uint8_t *out, 309 size_t *out_len, size_t max_out_len, 310 const uint8_t *nonce, size_t nonce_len, 311 const uint8_t *in, size_t in_len, 312 const uint8_t *ad, size_t ad_len); 313 314 // EVP_AEAD_CTX_open authenticates |in_len| bytes from |in| and |ad_len| bytes 315 // from |ad| and decrypts at most |in_len| bytes into |out|. It returns one on 316 // success and zero otherwise. 317 // 318 // This function may be called concurrently with itself or any other seal/open 319 // function on the same |EVP_AEAD_CTX|. 320 // 321 // At most |in_len| bytes are written to |out|. In order to ensure success, 322 // |max_out_len| should be at least |in_len|. On successful return, |*out_len| 323 // is set to the the actual number of bytes written. 324 // 325 // The length of |nonce|, |nonce_len|, must be equal to the result of 326 // |EVP_AEAD_nonce_length| for this AEAD. 327 // 328 // |EVP_AEAD_CTX_open| never results in a partial output. If |max_out_len| is 329 // insufficient, zero will be returned. If any error occurs, |out| will be 330 // filled with zero bytes and |*out_len| set to zero. 331 // 332 // If |in| and |out| alias then |out| must be == |in|. 333 OPENSSL_EXPORT int EVP_AEAD_CTX_open(const EVP_AEAD_CTX *ctx, uint8_t *out, 334 size_t *out_len, size_t max_out_len, 335 const uint8_t *nonce, size_t nonce_len, 336 const uint8_t *in, size_t in_len, 337 const uint8_t *ad, size_t ad_len); 338 339 // EVP_AEAD_CTX_seal_scatter encrypts and authenticates |in_len| bytes from |in| 340 // and authenticates |ad_len| bytes from |ad|. It writes |in_len| bytes of 341 // ciphertext to |out| and the authentication tag to |out_tag|. It returns one 342 // on success and zero otherwise. 343 // 344 // This function may be called concurrently with itself or any other seal/open 345 // function on the same |EVP_AEAD_CTX|. 346 // 347 // Exactly |in_len| bytes are written to |out|, and up to 348 // |EVP_AEAD_max_overhead+extra_in_len| bytes to |out_tag|. On successful 349 // return, |*out_tag_len| is set to the actual number of bytes written to 350 // |out_tag|. 351 // 352 // |extra_in| may point to an additional plaintext input buffer if the cipher 353 // supports it. If present, |extra_in_len| additional bytes of plaintext are 354 // encrypted and authenticated, and the ciphertext is written (before the tag) 355 // to |out_tag|. |max_out_tag_len| must be sized to allow for the additional 356 // |extra_in_len| bytes. 357 // 358 // The length of |nonce|, |nonce_len|, must be equal to the result of 359 // |EVP_AEAD_nonce_length| for this AEAD. 360 // 361 // |EVP_AEAD_CTX_seal_scatter| never results in a partial output. If 362 // |max_out_tag_len| is insufficient, zero will be returned. If any error 363 // occurs, |out| and |out_tag| will be filled with zero bytes and |*out_tag_len| 364 // set to zero. 365 // 366 // If |in| and |out| alias then |out| must be == |in|. |out_tag| may not alias 367 // any other argument. 368 OPENSSL_EXPORT int EVP_AEAD_CTX_seal_scatter( 369 const EVP_AEAD_CTX *ctx, uint8_t *out, uint8_t *out_tag, 370 size_t *out_tag_len, size_t max_out_tag_len, const uint8_t *nonce, 371 size_t nonce_len, const uint8_t *in, size_t in_len, const uint8_t *extra_in, 372 size_t extra_in_len, const uint8_t *ad, size_t ad_len); 373 374 // EVP_AEAD_CTX_open_gather decrypts and authenticates |in_len| bytes from |in| 375 // and authenticates |ad_len| bytes from |ad| using |in_tag_len| bytes of 376 // authentication tag from |in_tag|. If successful, it writes |in_len| bytes of 377 // plaintext to |out|. It returns one on success and zero otherwise. 378 // 379 // This function may be called concurrently with itself or any other seal/open 380 // function on the same |EVP_AEAD_CTX|. 381 // 382 // The length of |nonce|, |nonce_len|, must be equal to the result of 383 // |EVP_AEAD_nonce_length| for this AEAD. 384 // 385 // |EVP_AEAD_CTX_open_gather| never results in a partial output. If any error 386 // occurs, |out| will be filled with zero bytes. 387 // 388 // If |in| and |out| alias then |out| must be == |in|. 389 OPENSSL_EXPORT int EVP_AEAD_CTX_open_gather( 390 const EVP_AEAD_CTX *ctx, uint8_t *out, const uint8_t *nonce, 391 size_t nonce_len, const uint8_t *in, size_t in_len, const uint8_t *in_tag, 392 size_t in_tag_len, const uint8_t *ad, size_t ad_len); 393 394 // EVP_AEAD_CTX_aead returns the underlying AEAD for |ctx|, or NULL if one has 395 // not been set. 396 OPENSSL_EXPORT const EVP_AEAD *EVP_AEAD_CTX_aead(const EVP_AEAD_CTX *ctx); 397 398 399 // TLS-specific AEAD algorithms. 400 // 401 // These AEAD primitives do not meet the definition of generic AEADs. They are 402 // all specific to TLS and should not be used outside of that context. They must 403 // be initialized with |EVP_AEAD_CTX_init_with_direction|, are stateful, and may 404 // not be used concurrently. Any nonces are used as IVs, so they must be 405 // unpredictable. They only accept an |ad| parameter of length 11 (the standard 406 // TLS one with length omitted). 407 408 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_cbc_sha1_tls(void); 409 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_cbc_sha1_tls_implicit_iv(void); 410 411 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_cbc_sha256_tls(void); 412 413 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_cbc_sha1_tls(void); 414 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_cbc_sha1_tls_implicit_iv(void); 415 416 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_des_ede3_cbc_sha1_tls(void); 417 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_des_ede3_cbc_sha1_tls_implicit_iv(void); 418 419 // EVP_aead_aes_128_gcm_tls12 is AES-128 in Galois Counter Mode using the TLS 420 // 1.2 nonce construction. 421 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_gcm_tls12(void); 422 423 // EVP_aead_aes_256_gcm_tls12 is AES-256 in Galois Counter Mode using the TLS 424 // 1.2 nonce construction. 425 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_gcm_tls12(void); 426 427 // EVP_aead_aes_128_gcm_tls13 is AES-128 in Galois Counter Mode using the TLS 428 // 1.3 nonce construction. 429 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_gcm_tls13(void); 430 431 // EVP_aead_aes_256_gcm_tls13 is AES-256 in Galois Counter Mode using the TLS 432 // 1.3 nonce construction. 433 OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_256_gcm_tls13(void); 434 435 436 // Obscure functions. 437 438 // evp_aead_direction_t denotes the direction of an AEAD operation. 439 enum evp_aead_direction_t { 440 evp_aead_open, 441 evp_aead_seal, 442 }; 443 444 // EVP_AEAD_CTX_init_with_direction calls |EVP_AEAD_CTX_init| for normal 445 // AEADs. For TLS-specific and SSL3-specific AEADs, it initializes |ctx| for a 446 // given direction. 447 OPENSSL_EXPORT int EVP_AEAD_CTX_init_with_direction( 448 EVP_AEAD_CTX *ctx, const EVP_AEAD *aead, const uint8_t *key, size_t key_len, 449 size_t tag_len, enum evp_aead_direction_t dir); 450 451 // EVP_AEAD_CTX_get_iv sets |*out_len| to the length of the IV for |ctx| and 452 // sets |*out_iv| to point to that many bytes of the current IV. This is only 453 // meaningful for AEADs with implicit IVs (i.e. CBC mode in TLS 1.0). 454 // 455 // It returns one on success or zero on error. 456 OPENSSL_EXPORT int EVP_AEAD_CTX_get_iv(const EVP_AEAD_CTX *ctx, 457 const uint8_t **out_iv, size_t *out_len); 458 459 // EVP_AEAD_CTX_tag_len computes the exact byte length of the tag written by 460 // |EVP_AEAD_CTX_seal_scatter| and writes it to |*out_tag_len|. It returns one 461 // on success or zero on error. |in_len| and |extra_in_len| must equal the 462 // arguments of the same names passed to |EVP_AEAD_CTX_seal_scatter|. 463 OPENSSL_EXPORT int EVP_AEAD_CTX_tag_len(const EVP_AEAD_CTX *ctx, 464 size_t *out_tag_len, 465 const size_t in_len, 466 const size_t extra_in_len); 467 468 469 #if defined(__cplusplus) 470 } // extern C 471 472 #if !defined(BORINGSSL_NO_CXX) 473 extern "C++" { 474 475 BSSL_NAMESPACE_BEGIN 476 477 using ScopedEVP_AEAD_CTX = 478 internal::StackAllocated<EVP_AEAD_CTX, void, EVP_AEAD_CTX_zero, 479 EVP_AEAD_CTX_cleanup>; 480 481 BORINGSSL_MAKE_DELETER(EVP_AEAD_CTX, EVP_AEAD_CTX_free) 482 483 BSSL_NAMESPACE_END 484 485 } // extern C++ 486 #endif 487 488 #endif 489 490 #endif // OPENSSL_HEADER_AEAD_H