Skip to content

Commit 88555cc

Browse files
authored
fix: use proper return value check for EVP_CIPHER_CTX_ctrl() (#36)
1 parent 944c570 commit 88555cc

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/ncrypto.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3412,19 +3412,21 @@ bool CipherCtxPointer::setKeyLength(size_t length) {
34123412
bool CipherCtxPointer::setIvLength(size_t length) {
34133413
if (!ctx_) return false;
34143414
return EVP_CIPHER_CTX_ctrl(
3415-
ctx_.get(), EVP_CTRL_AEAD_SET_IVLEN, length, nullptr);
3415+
ctx_.get(), EVP_CTRL_AEAD_SET_IVLEN, length, nullptr) > 0;
34163416
}
34173417

34183418
bool CipherCtxPointer::setAeadTag(const Buffer<const char>& tag) {
34193419
if (!ctx_) return false;
3420-
return EVP_CIPHER_CTX_ctrl(
3421-
ctx_.get(), EVP_CTRL_AEAD_SET_TAG, tag.len, const_cast<char*>(tag.data));
3420+
return EVP_CIPHER_CTX_ctrl(ctx_.get(),
3421+
EVP_CTRL_AEAD_SET_TAG,
3422+
tag.len,
3423+
const_cast<char*>(tag.data)) > 0;
34223424
}
34233425

34243426
bool CipherCtxPointer::setAeadTagLength(size_t length) {
34253427
if (!ctx_) return false;
34263428
return EVP_CIPHER_CTX_ctrl(
3427-
ctx_.get(), EVP_CTRL_AEAD_SET_TAG, length, nullptr);
3429+
ctx_.get(), EVP_CTRL_AEAD_SET_TAG, length, nullptr) > 0;
34283430
}
34293431

34303432
bool CipherCtxPointer::setPadding(bool padding) {
@@ -3494,7 +3496,7 @@ bool CipherCtxPointer::update(const Buffer<const unsigned char>& in,
34943496

34953497
bool CipherCtxPointer::getAeadTag(size_t len, unsigned char* out) {
34963498
if (!ctx_) return false;
3497-
return EVP_CIPHER_CTX_ctrl(ctx_.get(), EVP_CTRL_AEAD_GET_TAG, len, out);
3499+
return EVP_CIPHER_CTX_ctrl(ctx_.get(), EVP_CTRL_AEAD_GET_TAG, len, out) > 0;
34983500
}
34993501

35003502
// ============================================================================

0 commit comments

Comments
 (0)