Updated wolfSSL_EVP_Cipher() for AES GCM

This commit is contained in:
Tesfa Mael
2019-08-27 11:36:39 -07:00
parent 208e9f3fcf
commit f9e364f893

View File

@ -14405,12 +14405,41 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
case AES_192_GCM_TYPE :
case AES_256_GCM_TYPE :
WOLFSSL_MSG("AES GCM");
if (ctx->enc)
ret = 1;
// ret = wc_AesGcmEncrypt(&ctx->cipher.aes, dst, src, len);
else
// ret = wc_AesGcmDecrypt(&ctx->cipher.aes, dst, src, len);
if (ctx->enc) {
if (dst){
/* encrypt confidential data*/
ret = wc_AesGcmEncrypt(&ctx->cipher.aes, dst, src, len,
ctx->iv, ctx->ivSz, ctx->authTag, ctx->authTagSz,
NULL, 0);
}
else {
/* authenticated, non-confidential data */
ret = wc_AesGcmEncrypt(&ctx->cipher.aes, NULL, NULL, 0,
ctx->iv, ctx->ivSz, ctx->authTag, ctx->authTagSz,
src, len);
/* Reset partial authTag error for AAD*/
if (ret == AES_GCM_AUTH_E)
ret = 0;
}
}
else {
if (dst){
/* decrypt confidential data*/
ret = wc_AesGcmDecrypt(&ctx->cipher.aes, dst, src, len,
ctx->iv, ctx->ivSz, ctx->authTag, ctx->authTagSz,
NULL, 0);
}
else {
/* authenticated, non-confidential data*/
ret = wc_AesGcmDecrypt(&ctx->cipher.aes, NULL, NULL, 0,
ctx->iv, ctx->ivSz,
ctx->authTag, ctx->authTagSz,
src, len);
/* Reset partial authTag error for AAD*/
if (ret == AES_GCM_AUTH_E)
ret = 0;
}
}
break;
#endif /* HAVE_AESGCM */
#ifdef HAVE_AES_ECB