8 #include <openssl/crypto.h> 9 #include <openssl/evp.h> 31 : AesGcmDecryptorComponentBase(compName),
37 this->m_cipher = EVP_CIPHER_fetch(
nullptr,
"AES-256-GCM",
nullptr);
39 this->m_ctx = EVP_CIPHER_CTX_new();
41 int status = EVP_DecryptInit_ex(this->m_ctx, this->m_cipher,
nullptr,
nullptr,
nullptr);
42 FW_ASSERT(status == 1, static_cast<FwAssertArgType>(status));
43 status = EVP_CIPHER_CTX_ctrl(this->m_ctx, EVP_CTRL_GCM_SET_IVLEN, static_cast<int>(
GCM_IV_LEN),
nullptr);
44 FW_ASSERT(status == 1, static_cast<FwAssertArgType>(status));
48 EVP_CIPHER_CTX_free(this->m_ctx);
49 EVP_CIPHER_free(this->m_cipher);
56 void AesGcmDecryptor ::decryptIn_handler(
FwIndexType portNum,
57 U16 securityAssociationIndex,
81 U8*
const tag = ciphertext + cipherLen;
87 if ((vcId != this->m_aadVcId) || (securityAssociationIndex != this->m_aadSaIndex)) {
89 this->m_aadVcId = vcId;
90 this->m_aadSaIndex = securityAssociationIndex;
96 const bool rekeyed = EVP_DecryptInit_ex(this->m_ctx,
nullptr,
nullptr, key.
getBuffAddr(), iv) == 1;
100 const bool aadAbsorbed = rekeyed && (EVP_DecryptUpdate(this->m_ctx,
nullptr, &len, this->m_aad.
bytes,
101 static_cast<int>(
sizeof(this->m_aad.bytes))) == 1);
102 const bool decrypted =
103 aadAbsorbed && (EVP_DecryptUpdate(this->m_ctx, ciphertext, &len, ciphertext, static_cast<int>(cipherLen)) == 1);
105 decrypted && (EVP_CIPHER_CTX_ctrl(this->m_ctx, EVP_CTRL_GCM_SET_TAG, static_cast<int>(
GCM_TAG_LEN), tag) == 1);
113 if (EVP_DecryptFinal_ex(this->m_ctx, ciphertext + plainLen, &len) != 1) {
117 FW_ASSERT(len == 0, static_cast<FwAssertArgType>(len));
121 data.
setSize(static_cast<Fw::Buffer::SizeType>(plainLen));
125 void AesGcmDecryptor ::decryptReturnIn_handler(
FwIndexType portNum,
128 this->bufferReturnOut_out(0, data, context);
PlatformSizeType FwSizeType
void setSize(FwSizeType size)
Decryption operation failed.
Serializable::SizeType getSize() const override
Get current buffer size.
void advance(FwSignedSizeType amount)
static constexpr U32 GCM_IV_LEN
Length of the AES-GCM initialization vector, in bytes.
Serializable::SizeType getCapacity() const override
Get buffer capacity.
Status of an SDLS (Space Data Link Security) encryption/decryption request.
static constexpr FwSizeType AES_256_KEY_LEN
Length of an AES-256 key, in bytes.
U8 * getBuffAddr()
Get buffer address for data filling (non-const version)
U8 get_vcId() const
Get member vcId.
AesGcmDecryptor(const char *const compName)
Construct AesGcmDecryptor object.
~AesGcmDecryptor()
Destroy AesGcmDecryptor object.
Frame failed its authentication check.
static constexpr U32 GCM_TAG_LEN
Length of the AES-GCM authentication tag (the SDLS MAC), in bytes.
uint8_t U8
8-bit unsigned integer
FwSizeType getSize() const
PlatformIndexType FwIndexType
Type used to pass context info between components during framing/deframing.
RateGroupDivider component implementation.
Request completed successfully.