8000 crypto, feat: support sha3. · fibjs/fibjs@9ae4816 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 9ae4816

Browse files
committed
crypto, feat: support sha3.
1 parent 8ea81c9 commit 9ae4816

File tree

13 files changed

+1699
-483
lines changed

13 files changed

+1699
-483
lines changed

fibjs/include/ifs/hash.h

Lines changed: 124 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,16 @@ class hash_base : public object_base {
3232
C_SHA512 = 6,
3333
C_RIPEMD160 = 7,
3434
C_SM3 = 8,
35-
C_KECCAK256 = 9,
36-
C_KECCAK384 = 10,
37-
C_KECCAK512 = 11,
38-
C_BLAKE2S = 12,
39-
C_BLAKE2B = 13,
40-
C_BLAKE2SP = 14,
41-
C_BLAKE2BP = 15
35+
C_SHA3_256 = 9,
36+
C_SHA3_384 = 10,
37+
C_SHA3_512 = 11,
38+
C_KECCAK256 = 12,
39+
C_KECCAK384 = 13,
40+
C_KECCAK512 = 14,
41+
C_BLAKE2S = 15,
42+
C_BLAKE2B = 16,
43+
C_BLAKE2SP = 17,
44+
C_BLAKE2BP = 18
4245
};
4346

4447
public:
@@ -53,6 +56,9 @@ class hash_base : public object_base {
5356
static result_t ripemd160(Buffer_base* data, obj_ptr<Digest_base>& retVal);
5457
static result_t sm3(Buffer_base* data, obj_ptr<Digest_base>& retVal);
5558
static result_t sm3(PKey_base* pubKey, exlib::string id, Buffer_base* data, obj_ptr<Digest_base>& retVal);
59+
static result_t sha3_256(Buffer_base* data, obj_ptr<Digest_base>& retVal);
60+
static result_t sha3_384(Buffer_base* data, obj_ptr<Digest_base>& retVal);
61+
static result_t sha3_512(Buffer_base* data, obj_ptr<Digest_base>& retVal);
5662
static result_t keccak256(Buffer_base* data, obj_ptr<Digest_base>& retVal);
5763
static result_t keccak384(Buffer_base* data, obj_ptr<Digest_base>& retVal);
5864
static result_t keccak512(Buffer_base* data, obj_ptr<Digest_base>& retVal);
@@ -70,6 +76,9 @@ class hash_base : public object_base {
7076
static result_t hmac_ripemd160(Buffer_base* key, Buffer_base* data, obj_ptr<Digest_base>& retVal);
7177
static result_t hmac_sm3(Buffer_base* key, Buffer_base* data, obj_ptr<Digest_base>& retVal);
7278
static result_t hmac_sm3(PKey_base* pubKey, exlib::string id, Buffer_base* key, Buffer_base* data, obj_ptr<Digest_base>& retVal);
79+
static result_t hmac_sha3_256(Buffer_base* key, Buffer_base* data, obj_ptr<Digest_base>& retVal);
80+
static result_t hmac_sha3_384(Buffer_base* key, Buffer_base* data, obj_ptr<Digest_base>& retVal);
81+
static result_t hmac_sha3_512(Buffer_base* key, Buffer_base* data, obj_ptr<Digest_base>& retVal);
7382
static result_t hmac_keccak256(Buffer_base* key, Buffer_base* data, obj_ptr<Digest_base>& retVal);
7483
static result_t hmac_keccak384(Buffer_base* key, Buffer_base* data, obj_ptr<Digest_base>& retVal);
7584
static result_t hmac_keccak512(Buffer_base* key, Buffer_base* data, obj_ptr<Digest_base>& retVal);
@@ -97,6 +106,9 @@ class hash_base : public object_base {
97106
static void s_static_sha512(const v8::FunctionCallbackInfo<v8::Value>& args);
98107
static void s_static_ripemd160(const v8::FunctionCallbackInfo<v8::Value>& args);
99108
static void s_static_sm3(const v8::FunctionCallbackInfo<v8::Value>& args);
109+
static void s_static_sha3_256(const v8::FunctionCallbackInfo<v8::Value>& args);
110+
static void s_static_sha3_384(const v8::FunctionCallbackInfo<v8::Value>& args);
111+
static void s_static_sha3_512(const v8::FunctionCallbackInfo<v8::Value>& args);
100112
static void s_static_keccak256(const v8::FunctionCallbackInfo<v8::Value>& args);
101113
static void s_static_keccak384(const v8::FunctionCallbackInfo<v8::Value>& args);
102114
static void s_static_keccak512(const v8::FunctionCallbackInfo<v8::Value>& args);
@@ -113,6 +125,9 @@ class hash_base : public object_base {
113125
static void s_static_hmac_sha512(const v8::FunctionCallbackInfo<v8::Value>& args);
114126
static void s_static_hmac_ripemd160(const v8::FunctionCallbackInfo<v8::Value>& args);
115127
static void s_static_hmac_sm3(const v8::FunctionCallbackInfo<v8::Value>& args);
128+
static void s_static_hmac_sha3_256(const v8::FunctionCallbackInfo<v8::Value>& args);
129+
static void s_static_hmac_sha3_384(const v8::FunctionCallbackInfo<v8::Value>& args);
130+
static void s_static_hmac_sha3_512(const v8::FunctionCallbackInfo<v8::Value>& args);
116131
static void s_static_hmac_keccak256(const v8::FunctionCallbackInfo<v8::Value>& args);
117132
static void s_static_hmac_keccak384(const v8::FunctionCallbackInfo<v8::Value>& args);
118133
static void s_static_hmac_keccak512(const v8::FunctionCallbackInfo<v8::Value>& args);
@@ -140,6 +155,9 @@ inline ClassInfo& hash_base::class_info()
140155
{ "sha512", s_static_sha512, true, false },
141156
{ "ripemd160", s_static_ripemd160, true, false },
142157
{ "sm3", s_static_sm3, true, false },
158+
{ "sha3_256", s_static_sha3_256, true, false },
159+
{ "sha3_384", s_static_sha3_384, true, false },
160+
{ "sha3_512", s_static_sha3_512, true, false },
143161
{ "keccak256", s_static_keccak256, true, false },
144162
{ "keccak384", s_static_keccak384, true, false },
145163
{ "keccak512", s_static_keccak512, true, false },
@@ -156,6 +174,9 @@ inline ClassInfo& hash_base::class_info()
156174
{ "hmac_sha512", s_static_hmac_sha512, true, false },
157175
{ "hmac_ripemd160", s_static_hmac_ripemd160, true, false },
158176
{ "hmac_sm3", s_static_hmac_sm3, true, false },
177+
{ "hmac_sha3_256", s_static_hmac_sha3_256, true, false },
178+
{ "hmac_sha3_384", s_static_hmac_sha3_384, true, false },
179+
{ "hmac_sha3_512", s_static_hmac_sha3_512, true, false },
159180
{ "hmac_keccak256", s_static_hmac_keccak256, true, false },
160181
{ "hmac_keccak384", s_static_hmac_keccak384, true, false },
161182
{ "hmac_keccak512", s_static_hmac_keccak512, true, false },
@@ -174,6 +195,9 @@ inline ClassInfo& hash_base::class_info()
174195
{ "SHA512", C_SHA512 },
175196
{ "RIPEMD160", C_RIPEMD160 },
176197
{ "SM3", C_SM3 },
198+
{ "SHA3_256&qu 1E0A ot;, C_SHA3_256 },
199+
{ "SHA3_384", C_SHA3_384 },
200+
{ "SHA3_512", C_SHA3_512 },
177201
{ "KECCAK256", C_KECCAK256 },
178202
{ "KECCAK384", C_KECCAK384 },
179203
{ "KECCAK512", C_KECCAK512 },
@@ -337,6 +361,51 @@ inline void hash_base::s_static_sm3(const v8::FunctionCallbackInfo<v8::Value>& a
337361
METHOD_RETURN();
338362
}
339363

364+
inline void hash_base::s_static_sha3_256(const v8::FunctionCallbackInfo<v8::Value>& args)
365+
{
366+
obj_ptr<Digest_base> vr;
367+
368+
METHOD_ENTER();
369+
370+
METHOD_OVER(1, 0);
371+
372+
OPT_ARG(obj_ptr<Buffer_base>, 0, NULL);
373+
374+
hr = sha3_256(v0, vr);
375+
376+
METHOD_RETURN();
377+
}
378+
379+
inline void hash_base::s_static_sha3_384(const v8::FunctionCallbackInfo<v8::Value>& args)
380+
{
381+
obj_ptr<Digest_base> vr;
382+
383+
METHOD_ENTER();
384+
385+
METHOD_OVER(1, 0);
386+
387+
OPT_ARG(obj_ptr<Buffer_base>, 0, NULL);
388+
389+
hr = sha3_384(v0, vr);
390+
391+
METHOD_RETURN();
392+
}
393+
394+
inline void hash_base::s_static_sha3_512(const v8::FunctionCallbackInfo<v8::Value>& args)
395+
{
396+
obj_ptr<Digest_base> vr;
397+
398+
METHOD_ENTER();
399+
400+
METHOD_OVER(1, 0);
401+
402+
OPT_ARG(obj_ptr<Buffer_base>, 0, NULL);
403+
404+
hr = sha3_512(v0, vr);
405+
406+
METHOD_RETURN();
407+
}
408+
340409
inline void hash_base::s_static_keccak256(const v8::FunctionCallbackInfo<v8::Value>& args)
341410
{
342411
obj_ptr<Digest_base> vr;
@@ -596,6 +665,54 @@ inline void hash_base::s_static_hmac_sm3(const v8::FunctionCallbackInfo<v8::Valu
596665
METHOD_RETURN();
597666
}
598667

668+
inline void hash_base::s_static_hmac_sha3_256(const v8::FunctionCallbackInfo<v8::Value>& args)
669+
{
670+
obj_ptr<Digest_base> vr;
671+
672+
METHOD_ENTER();
673+
674+
METHOD_OVER(2, 1);
675+
676+
ARG(obj_ptr<Buffer_base>, 0);
677+
OPT_ARG(obj_ptr<Buffer_base>, 1, NULL);
678+
679+
hr = hmac_sha3_256(v0, v1, vr);
680+
681+
METHOD_RETURN();
682+
}
683+
684+
inline void hash_base::s_static_hmac_sha3_384(const v8::FunctionCallbackInfo<v8::Value>& args)
685+
{
686+
obj_ptr<Digest_base> vr;
687+
688+
METHOD_ENTER();
689+
690+
METHOD_OVER(2, 1);
691+
692+
ARG(obj_ptr<Buffer_base>, 0);
693+
OPT_ARG(obj_ptr<Buffer_base>, 1, NULL);
694+
695+
hr = hmac_sha3_384(v0, v1, vr);
696+
697+
METHOD_RETURN();
698+
}
699+
700+
inline void hash_base::s_static_hmac_sha3_512(const v8::FunctionCallbackInfo<v8::Value>& args)
701+
{
702+
obj_ptr<Digest_base> vr;
703+
704+
METHOD_ENTER();
705+
706+
METHOD_OVER(2, 1);
707+
708+
ARG(obj_ptr<Buffer_base>, 0);
709+
OPT_ARG(obj_ptr<Buffer_base>, 1, NULL);
710+
711+
hr = hmac_sha3_512(v0, v1, vr);
712+
713+
METHOD_RETURN();
714+
}
715+
599716
inline void hash_base::s_static_hmac_keccak256(const v8::FunctionCallbackInfo<v8::Value>& args)
600717
{
601718
obj_ptr<Digest_base> vr;

0 commit comments

Comments
 (0)
0