1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

openssl: gencrypto: aes gcm AAD: use EncryptUpdate or DecryptUpdate to set AAD

Until 1.1.1b OpenSSL didn't mind we were setting AAD for AES GCM
using EVP_EncryptUpdate() for both encrypt and decrypt... but now
it noticed and the bug is fixed.
This commit is contained in:
Andy Green 2019-03-21 06:16:16 +08:00
parent 45f2c9f9f8
commit 30eb3e94ab

View file

@ -277,8 +277,12 @@ lws_genaes_crypt(struct lws_genaes_ctx *ctx,
EVP_CIPHER_CTX_set_key_length(ctx->ctx, ctx->k->len);
if (ctx->mode == LWS_GAESM_GCM) {
EVP_CIPHER_CTX_ctrl(ctx->ctx, EVP_CTRL_GCM_SET_IVLEN,
n = EVP_CIPHER_CTX_ctrl(ctx->ctx, EVP_CTRL_GCM_SET_IVLEN,
*nc_or_iv_off, NULL);
if (n != 1) {
lwsl_err("%s: SET_IVLEN failed\n", __func__);
return -1;
}
memcpy(ctx->tag, stream_block_16, taglen);
ctx->taglen = taglen;
}
@ -311,14 +315,26 @@ lws_genaes_crypt(struct lws_genaes_ctx *ctx,
if (ctx->mode == LWS_GAESM_GCM && !out) {
/* AAD */
if (len)
if (EVP_EncryptUpdate(ctx->ctx, NULL, &olen,
in, len) != 1) {
lwsl_err("%s: set aad failed\n",
__func__);
return -1;
}
if (!len)
return 0;
switch (ctx->op) {
case LWS_GAESO_ENC:
n = EVP_EncryptUpdate(ctx->ctx, NULL, &olen, in, len);
break;
case LWS_GAESO_DEC:
n = EVP_DecryptUpdate(ctx->ctx, NULL, &olen, in, len);
break;
default:
return -1;
}
if (n != 1) {
lwsl_err("%s: set AAD failed\n", __func__);
lws_tls_err_describe();
lwsl_hexdump_err(in, len);
return -1;
}
return 0;
}