@@ -2622,7 +2622,7 @@ void CipherBase::New(const FunctionCallbackInfo<Value>& args) {
2622
2622
void CipherBase::Init (const char * cipher_type,
2623
2623
const char * key_buf,
2624
2624
int key_buf_len,
2625
- int auth_tag_len) {
2625
+ unsigned int auth_tag_len) {
2626
2626
HandleScope scope (env ()->isolate ());
2627
2627
2628
2628
#ifdef NODE_FIPS_MODE
@@ -2693,10 +2693,16 @@ void CipherBase::Init(const FunctionCallbackInfo<Value>& args) {
2693
2693
const node::Utf8Value cipher_type (args.GetIsolate (), args[0 ]);
2694
2694
const char * key_buf = Buffer::Data (args[1 ]);
2695
2695
ssize_t key_buf_len = Buffer::Length (args[1 ]);
2696
- CHECK (args[ 2 ]-> IsInt32 ());
2696
+
2697
2697
// Don't assign to cipher->auth_tag_len_ directly; the value might not
2698
2698
// represent a valid length at this point.
2699
- int auth_tag_len = args[2 ].As <v8::Int32>()->Value ();
2699
+ unsigned int auth_tag_len;
2700
+ if (args[2 ]->IsUint32 ()) {
2701
+ auth_tag_len = args[2 ].As <v8::Uint32>()->Value ();
2702
+ } else {
2703
+ CHECK (args[2 ]->IsInt32 () && args[2 ].As <v8::Int32>()->Value () == -1 );
2704
+ auth_tag_len = kNoAuthTagLength ;
2705
+ }
2700
2706
2701
2707
cipher->Init (*cipher_type, key_buf, key_buf_len, auth_tag_len);
2702
2708
}
@@ -2707,7 +2713,7 @@ void CipherBase::InitIv(const char* cipher_type,
2707
2713
int key_len,
2708
2714
const char * iv,
2709
2715
int iv_len,
2710
- int auth_tag_len) {
2716
+ unsigned int auth_tag_len) {
2711
2717
HandleScope scope (env ()->isolate ());
2712
2718
2713
2719
const EVP_CIPHER* const cipher = EVP_get_cipherbyname (cipher_type);
@@ -2781,10 +2787,16 @@ void CipherBase::InitIv(const FunctionCallbackInfo<Value>& args) {
2781
2787
iv_buf = Buffer::Data (args[2 ]);
2782
2788
iv_len = Buffer::Length (args[2 ]);
2783
2789
}
2784
- CHECK (args[ 3 ]-> IsInt32 ());
2790
+
2785
2791
// Don't assign to cipher->auth_tag_len_ directly; the value might not
2786
2792
// represent a valid length at this point.
2787
- int auth_tag_len = args[3 ].As <v8::Int32>()->Value ();
2793
+ unsigned int auth_tag_len;
2794
+ if (args[3 ]->IsUint32 ()) {
2795
+ auth_tag_len = args[3 ].As <v8::Uint32>()->Value ();
2796
+ } else {
2797
+ CHECK (args[3 ]->IsInt32 () && args[3 ].As <v8::Int32>()->Value () == -1 );
2798
+ auth_tag_len = kNoAuthTagLength ;
2799
+ }
2788
2800
2789
2801
cipher->InitIv (*cipher_type, key_buf, key_len, iv_buf, iv_len, auth_tag_len);
2790
2802
}
@@ -2795,7 +2807,7 @@ static bool IsValidGCMTagLength(unsigned int tag_len) {
2795
2807
}
2796
2808
2797
2809
bool CipherBase::InitAuthenticated (const char *cipher_type, int iv_len,
2798
- int auth_tag_len) {
2810
+ unsigned int auth_tag_len) {
2799
2811
CHECK (IsAuthenticatedMode ());
2800
2812
2801
2813
if (!EVP_CIPHER_CTX_ctrl (ctx_, EVP_CTRL_AEAD_SET_IVLEN, iv_len, nullptr )) {
@@ -2805,7 +2817,7 @@ bool CipherBase::InitAuthenticated(const char *cipher_type, int iv_len,
2805
2817
2806
2818
const int mode = EVP_CIPHER_CTX_mode (ctx_);
2807
2819
if (mode == EVP_CIPH_CCM_MODE) {
2808
- if (auth_tag_len < 0 ) {
2820
+ if (auth_tag_len == kNoAuthTagLength ) {
2809
2821
char msg[128 ];
2810
2822
snprintf (msg, sizeof (msg), " authTagLength required for %s" , cipher_type);
2811
2823
env ()->ThrowError (msg);
@@ -2840,7 +2852,7 @@ bool CipherBase::InitAuthenticated(const char *cipher_type, int iv_len,
2840
2852
} else {
2841
2853
CHECK_EQ (mode, EVP_CIPH_GCM_MODE);
2842
2854
2843
- if (auth_tag_len >= 0 ) {
2855
+ if (auth_tag_len != kNoAuthTagLength ) {
2844
2856
if (!IsValidGCMTagLength (auth_tag_len)) {
2845
2857
char msg[50 ];
2846
2858
snprintf (msg, sizeof (msg),
0 commit comments