Home | History | Annotate | Download | only in ssl

Lines Matching defs:aead

20 #include <openssl/aead.h>
36 const EVP_AEAD *aead;
38 if (!ssl_cipher_get_evp_aead(&aead, &discard, &discard, cipher, version)) {
45 /* This is a "stateful" AEAD (for compatibility with pre-AEAD cipher
68 &aead_ctx->ctx, aead, enc_key, enc_key_len,
74 assert(EVP_AEAD_nonce_length(aead) <= EVP_AEAD_MAX_NONCE_LENGTH);
75 aead_ctx->variable_nonce_len = (uint8_t)EVP_AEAD_nonce_length(aead);
105 void SSL_AEAD_CTX_free(SSL_AEAD_CTX *aead) {
106 if (aead == NULL) {
109 EVP_AEAD_CTX_cleanup(&aead->ctx);
110 OPENSSL_free(aead);
113 size_t SSL_AEAD_CTX_explicit_nonce_len(SSL_AEAD_CTX *aead) {
114 if (aead != NULL && aead->variable_nonce_included_in_record) {
115 return aead->variable_nonce_len;
120 size_t SSL_AEAD_CTX_max_overhead(SSL_AEAD_CTX *aead) {
121 if (aead == NULL) {
124 return EVP_AEAD_max_overhead(aead->ctx.aead) +
125 SSL_AEAD_CTX_explicit_nonce_len(aead);
128 /* ssl_aead_ctx_get_ad writes the additional data for |aead| into |out| and
130 static size_t ssl_aead_ctx_get_ad(SSL_AEAD_CTX *aead, uint8_t out[13],
137 if (!aead->omit_version_in_ad) {
141 if (!aead->omit_length_in_ad) {
148 int SSL_AEAD_CTX_open(SSL_AEAD_CTX *aead, uint8_t *out, size_t *out_len,
152 if (aead == NULL) {
166 if (!aead->omit_length_in_ad) {
167 size_t overhead = SSL_AEAD_CTX_max_overhead(aead);
176 size_t ad_len = ssl_aead_ctx_get_ad(aead, ad, type, wire_version, seqnum,
184 if (aead->xor_fixed_nonce) {
185 nonce_len = aead->fixed_nonce_len - aead->variable_nonce_len;
188 memcpy(nonce, aead->fixed_nonce, aead->fixed_nonce_len);
189 nonce_len += aead->fixed_nonce_len;
193 if (aead->variable_nonce_included_in_record) {
194 if (in_len < aead->variable_nonce_len) {
199 memcpy(nonce + nonce_len, in, aead->variable_nonce_len);
200 in += aead->variable_nonce_len;
201 in_len -= aead->variable_nonce_len;
203 assert(aead->variable_nonce_len == 8);
204 memcpy(nonce + nonce_len, seqnum, aead->variable_nonce_len);
206 nonce_len += aead->variable_nonce_len;
209 if (aead->xor_fixed_nonce) {
210 assert(nonce_len == aead->fixed_nonce_len);
212 for (i = 0; i < aead->fixed_nonce_len; i++) {
213 nonce[i] ^= aead->fixed_nonce[i];
217 return EVP_AEAD_CTX_open(&aead->ctx, out, out_len, max_out, nonce, nonce_len,
221 int SSL_AEAD_CTX_seal(SSL_AEAD_CTX *aead, uint8_t *out, size_t *out_len,
225 if (aead == NULL) {
237 size_t ad_len = ssl_aead_ctx_get_ad(aead, ad, type, wire_version, seqnum,
245 if (aead->xor_fixed_nonce) {
246 nonce_len = aead->fixed_nonce_len - aead->variable_nonce_len;
249 memcpy(nonce, aead->fixed_nonce, aead->fixed_nonce_len);
250 nonce_len += aead->fixed_nonce_len;
254 if (aead->random_variable_nonce) {
255 assert(aead->variable_nonce_included_in_record);
256 if (!RAND_bytes(nonce + nonce_len, aead->variable_nonce_len)) {
262 assert(aead->variable_nonce_len == 8);
263 memcpy(nonce + nonce_len, seqnum, aead->variable_nonce_len);
265 nonce_len += aead->variable_nonce_len;
269 if (aead->variable_nonce_included_in_record) {
270 assert(!aead->xor_fixed_nonce);
271 if (max_out < aead->variable_nonce_len) {
275 if (out < in + in_len && in < out + aead->variable_nonce_len) {
279 memcpy(out, nonce + aead->fixed_nonce_len, aead->variable_nonce_len);
280 extra_len = aead->variable_nonce_len;
281 out += aead->variable_nonce_len;
282 max_out -= aead->variable_nonce_len;
286 if (aead->xor_fixed_nonce) {
287 assert(nonce_len == aead->fixed_nonce_len);
289 for (i = 0; i < aead->fixed_nonce_len; i++) {
290 nonce[i] ^= aead->fixed_nonce[i];
294 if (!EVP_AEAD_CTX_seal(&aead->ctx, out, out_len, max_out, nonce, nonce_len,