Skip to content

Conversation

maxsharabayko
Copy link
Collaborator

@maxsharabayko maxsharabayko commented Oct 4, 2022

Add AES GCM crypto mode support into the CRYSPR library if built with OpenSSL EVP (-DUSE_ENCLIB=openssl-evp).

List of Changes

  • HCRYPT_CTX_MODE_AESGCM to the hcrypt_Ctx.
  • aes_gcm_cipher function pointer is added to the CRYSPR_methods.
    • crysprOpenSSL_EVP_AES_GCMCipher function added in cryspr-openssl-evp.c; it uses EVP_aes_<128/192/256>_gcm functions in case EVP API is enabled.
    • crysprStub_AES_GCMCipher function (noop) is used otherwise.
  • Added the int HaiCryptCryspr_Is_AES_GCM_Supported(void) function to find out if GCM is supported. It will be useful for the handshaking procedure in follow-up PRs.
  • Added the HCRYPT_CIPHER_AES_GCM definition.

Related FR #2336.

@maxsharabayko maxsharabayko added Type: Enhancement Indicates new feature requests [core] Area: Changes in SRT library core labels Oct 4, 2022
@maxsharabayko maxsharabayko added this to the v1.6.0 milestone Oct 4, 2022
@maxsharabayko maxsharabayko requested a review from jeandube October 4, 2022 10:40
@maxsharabayko maxsharabayko marked this pull request as ready for review October 4, 2022 14:58
}

static int crysprFallback_MsSetKey(CRYSPR_cb *cryspr_cb, hcrypt_Ctx *ctx, const unsigned char *key, size_t key_len)
{
CRYSPR_AESCTX *aes_sek = CRYSPR_GETSEK(cryspr_cb, hcryptCtx_GetKeyIndex(ctx)); /* Ctx tells if it's for odd or even key */

if ((ctx->flags & HCRYPT_CTX_F_ENCRYPT) /* Encrypt key */
if (ctx->mode == HCRYPT_CTX_MODE_AESGCM) { /* AES GCM mode */
if (cryspr_cb->cryspr->aes_set_key(HCRYPT_CTX_MODE_AESGCM, (ctx->flags & HCRYPT_CTX_F_ENCRYPT) != 0, key, key_len, aes_sek)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AES-CTR always set an Encrypt Key even for Decrypt, Isn't it the same for AES-GCM?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly no. If e.g. I pass true in bEncrypt of the aes_set_key, then decryption fails on assigning the AUTH tag buffer to the context.

int crysprOpenSSL_EVP_AES_GCMCipher(bool bEncrypt, ...
{
    // ...
    if (!bEncrypt && !EVP_CIPHER_CTX_ctrl(aes_key, EVP_CTRL_GCM_SET_TAG, 16, out_tag)) {
        ERR_print_errors_fp(stderr);
        HCRYPT_LOG(LOG_ERR, "%s\n", "EVP_EncryptUpdate failed");
        return -1;
    }

@maxsharabayko maxsharabayko merged commit 66179ab into Haivision:master Oct 6, 2022
@maxsharabayko maxsharabayko deleted the develop/crypto-gcm branch October 6, 2022 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[core] Area: Changes in SRT library core Type: Enhancement Indicates new feature requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants