Skip to content

🐛 Incorrect tag length in GCM mode #707

Open
@elan

Description

@elan

What's happening?

The tag returned is always length 1. Here is a fix, the issue is that the return value of EVP_CIPHER_CTX_ctrl is 1 for success, not the length of the tag.

diff --git a/node_modules/react-native-quick-crypto/cpp/cipher/HybridCipher.cpp b/node_modules/react-native-quick-crypto/cpp/cipher/HybridCipher.cpp
index d684fe6..965d3f7 100644
--- a/node_modules/react-native-quick-crypto/cpp/cipher/HybridCipher.cpp
+++ b/node_modules/react-native-quick-crypto/cpp/cipher/HybridCipher.cpp
@@ -230,7 +230,7 @@ std::shared_ptr<ArrayBuffer> HybridCipher::getAuthTag() {
       throw std::runtime_error("Failed to get GCM/OCB auth tag: " + std::string(err_buf));
     }

-    size_t actual_tag_len = static_cast<size_t>(ret);
+    size_t actual_tag_len = auth_tag_len;
     uint8_t* raw_ptr = tag_buf.get();
     auto final_tag_buffer =
         std::make_shared<margelo::nitro::NativeArrayBuffer>(tag_buf.release(), actual_tag_len, [raw_ptr]() { delete[] raw_ptr; });

Reproducible Code

const cipher = crypto.createCipheriv('aes-256-gcm', key, nonce);
  cipher.setAAD(...);
  cipher.update(...);
  cipher.final();
  const tag = cipher.getAuthTag();

Relevant log output

There is no relevant log.

Device

iPhone 16 Pro

QuickCrypto Version

1.0.0 beta 15

Can you reproduce this issue in the QuickCrypto Example app?

I didn't try (⚠️ your issue might get ignored & closed if you don't try this)

Additional information

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions