File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change 6
6
#include " node.h"
7
7
8
8
#include < openssl/crypto.h>
9
+ #include < openssl/hmac.h>
10
+ #include < openssl/sha.h>
9
11
10
12
namespace node {
11
13
@@ -42,8 +44,47 @@ void TimingSafeEqual(const FunctionCallbackInfo<Value>& args) {
42
44
return ;
43
45
}
44
46
47
+ uint16_t bufKey[8 ];
48
+ CHECK (crypto::EntropySource (reinterpret_cast <unsigned char *>(bufKey),
49
+ sizeof (bufKey)));
50
+ char key[kKeySize ];
51
+ snprintf (key,
52
+ sizeof (key),
53
+ " %04x%04x%04x%04x%04x%04x%04x%04x" ,
54
+ bufKey[0 ],
55
+ bufKey[1 ],
56
+ bufKey[2 ],
57
+ bufKey[3 ],
58
+ bufKey[4 ],
59
+ bufKey[5 ],
60
+ bufKey[6 ],
61
+ bufKey[7 ]);
62
+
63
+ std::array<unsigned char , EVP_MAX_MD_SIZE> hash1;
64
+ std::array<unsigned char , EVP_MAX_MD_SIZE> hash2;
65
+ unsigned int hash1Len;
66
+ unsigned int hash2Len;
67
+
68
+ HMAC (EVP_sha256 (),
69
+ key,
70
+ kKeySize ,
71
+ reinterpret_cast <unsigned char const *>(buf1.data ()),
72
+ static_cast <int >(buf1.size ()),
73
+ hash1.data (),
74
+ &hash1Len);
75
+
76
+ HMAC (EVP_sha256 (),
77
+ key,
78
+ kKeySize ,
79
+ reinterpret_cast <unsigned char const *>(buf2.data ()),
80
+ static_cast <int >(buf2.size ()),
81
+ hash2.data (),
82
+ &hash2Len);
83
+
84
+ assert (hash1Len == hash2Len);
85
+
45
86
return args.GetReturnValue ().Set (
46
- CRYPTO_memcmp (buf1 .data (), buf2 .data (), buf1. size () ) == 0 );
87
+ CRYPTO_memcmp (hash1 .data (), hash2 .data (), hash1Len ) == 0 );
47
88
}
48
89
49
90
void Initialize (Environment* env, Local<Object> target) {
Original file line number Diff line number Diff line change @@ -11,6 +11,9 @@ namespace crypto {
11
11
namespace Timing {
12
12
void Initialize (Environment* env, v8::Local<v8::Object> target);
13
13
void RegisterExternalReferences (ExternalReferenceRegistry* registry);
14
+
15
+ static const int kKeySize = 256 ;
16
+
14
17
} // namespace Timing
15
18
} // namespace crypto
16
19
} // namespace node
You can’t perform that action at this time.
0 commit comments