@@ -2629,7 +2629,7 @@ void CipherBase::New(const FunctionCallbackInfo<Value>& args) {
2629
2629
void CipherBase::Init (const char * cipher_type,
2630
2630
const char * key_buf,
2631
2631
int key_buf_len,
2632
- int auth_tag_len) {
2632
+ unsigned int auth_tag_len) {
2633
2633
HandleScope scope (env ()->isolate ());
2634
2634
2635
2635
#ifdef NODE_FIPS_MODE
@@ -2700,10 +2700,16 @@ void CipherBase::Init(const FunctionCallbackInfo<Value>& args) {
2700
2700
const node::Utf8Value cipher_type (args.GetIsolate (), args[0 ]);
2701
2701
const char * key_buf = Buffer::Data (args[1 ]);
2702
2702
ssize_t key_buf_len = Buffer::Length (args[1 ]);
2703
- CHECK (args[ 2 ]-> IsInt32 ());
2703
+
2704
2704
// Don't assign to cipher->auth_tag_len_ directly; the value might not
2705
2705
// represent a valid length at this point.
2706
- int auth_tag_len = args[2 ].As <v8::Int32>()->Value ();
2706
+ unsigned int auth_tag_len;
2707
+ if (args[2 ]->IsUint32 ()) {
2708
+ auth_tag_len = args[2 ].As <v8::Uint32>()->Value ();
2709
+ } else {
2710
+ CHECK (args[2 ]->IsInt32 () && args[2 ].As <v8::Int32>()->Value () == -1 );
2711
+ auth_tag_len = kNoAuthTagLength ;
2712
+ }
2707
2713
2708
2714
cipher->Init (*cipher_type, key_buf, key_buf_len, auth_tag_len);
2709
2715
}
@@ -2714,7 +2720,7 @@ void CipherBase::InitIv(const char* cipher_type,
2714
2720
int key_len,
2715
2721
const char * iv,
2716
2722
int iv_len,
2717
- int auth_tag_len) {
2723
+ unsigned int auth_tag_len) {
2718
2724
HandleScope scope (env ()->isolate ());
2719
2725
2720
2726
const EVP_CIPHER* const cipher = EVP_get_cipherbyname (cipher_type);
@@ -2788,10 +2794,16 @@ void CipherBase::InitIv(const FunctionCallbackInfo<Value>& args) {
2788
2794
iv_buf = Buffer::Data (args[2 ]);
2789
2795
iv_len = Buffer::Length (args[2 ]);
2790
2796
}
2791
- CHECK (args[ 3 ]-> IsInt32 ());
2797
+
2792
2798
// Don't assign to cipher->auth_tag_len_ directly; the value might not
2793
2799
// represent a valid length at this point.
2794
- int auth_tag_len = args[3 ].As <v8::Int32>()->Value ();
2800
+ unsigned int auth_tag_len;
2801
+ if (args[3 ]->IsUint32 ()) {
2802
+ auth_tag_len = args[3 ].As <v8::Uint32>()->Value ();
2803
+ } else {
2804
+ CHECK (args[3 ]->IsInt32 () && args[3 ].As <v8::Int32>()->Value () == -1 );
2805
+ auth_tag_len = kNoAuthTagLength ;
2806
+ }
2795
2807
2796
2808
cipher->InitIv (*cipher_type, key_buf, key_len, iv_buf, iv_len, auth_tag_len);
2797
2809
}
@@ -2802,7 +2814,7 @@ static bool IsValidGCMTagLength(unsigned int tag_len) {
2802
2814
}
2803
2815
2804
2816
bool CipherBase::InitAuthenticated (const char *cipher_type, int iv_len,
2805
- int auth_tag_len) {
2817
+ unsigned int auth_tag_len) {
2806
2818
CHECK (IsAuthenticatedMode ());
2807
2819
2808
2820
// TODO(tniessen) Use EVP_CTRL_AEAD_SET_IVLEN when migrating to OpenSSL 1.1.0
@@ -2815,7 +2827,7 @@ bool CipherBase::InitAuthenticated(const char *cipher_type, int iv_len,
2815
2827
2816
2828
const int mode = EVP_CIPHER_CTX_mode (ctx_);
2817
2829
if (mode == EVP_CIPH_CCM_MODE) {
2818
- if (auth_tag_len < 0 ) {
2830
+ if (auth_tag_len == kNoAuthTagLength ) {
2819
2831
char msg[128 ];
2820
2832
snprintf (msg, sizeof (msg), " authTagLength required for %s" , cipher_type);
2821
2833
env ()->ThrowError (msg);
@@ -2850,7 +2862,7 @@ bool CipherBase::InitAuthenticated(const char *cipher_type, int iv_len,
2850
2862
} else {
2851
2863
CHECK_EQ (mode, EVP_CIPH_GCM_MODE);
2852
2864
2853
- if (auth_tag_len >= 0 ) {
2865
+ if (auth_tag_len != kNoAuthTagLength ) {
2854
2866
if (!IsValidGCMTagLength (auth_tag_len)) {
2855
2867
char msg[50 ];
2856
2868
snprintf (msg, sizeof (msg),
0 commit comments