├── .gitignore ├── LICENSE ├── Makefile ├── PoW.c ├── PoW.h ├── README.md ├── aes128.c ├── aes128.h ├── binding.gyp ├── blake2_impl.h ├── blake2s.c ├── blake2s.h ├── blake2s256.c ├── blake2s256.h ├── camellia128.c ├── camellia128.h ├── common.c ├── common.h ├── crc32.c ├── crc32.h ├── des.c ├── des.h ├── gost.c ├── gost.h ├── haval5_256.c ├── haval5_256.h ├── hmac_md5.c ├── hmac_md5.h ├── index.js ├── jtr_crc32.c ├── jtr_crc32.h ├── jtr_gost.c ├── jtr_gost.h ├── jtr_haval.c ├── jtr_haval_helper.c ├── jtr_skein.c ├── jtr_sph_haval.h ├── jtr_sph_skein.h ├── jtr_sph_types.h ├── keccak1600.c ├── keccak1600.h ├── main.cpp ├── multihashing.cc ├── my_rand48_r.h ├── my_time.c ├── my_time.h ├── node_modules ├── bindings │ ├── README.md │ ├── bindings.js │ └── package.json └── nan │ ├── CHANGELOG.md │ ├── LICENSE.md │ ├── README.md │ ├── doc │ ├── asyncworker.md │ ├── buffers.md │ ├── callback.md │ ├── converters.md │ ├── errors.md │ ├── json.md │ ├── maybe_types.md │ ├── methods.md │ ├── new.md │ ├── node_misc.md │ ├── object_wrappers.md │ ├── persistent.md │ ├── scopes.md │ ├── script.md │ ├── string_bytes.md │ ├── v8_internals.md │ └── v8_misc.md │ ├── include_dirs.js │ ├── nan.h │ ├── nan_callbacks.h │ ├── nan_callbacks_12_inl.h │ ├── nan_callbacks_pre_12_inl.h │ ├── nan_converters.h │ ├── nan_converters_43_inl.h │ ├── nan_converters_pre_43_inl.h │ ├── nan_define_own_property_helper.h │ ├── nan_implementation_12_inl.h │ ├── nan_implementation_pre_12_inl.h │ ├── nan_json.h │ ├── nan_maybe_43_inl.h │ ├── nan_maybe_pre_43_inl.h │ ├── nan_new.h │ ├── nan_object_wrap.h │ ├── nan_persistent_12_inl.h │ ├── nan_persistent_pre_12_inl.h │ ├── nan_private.h │ ├── nan_string_bytes.h │ ├── nan_typedarray_contents.h │ ├── nan_weak.h │ ├── package.json │ └── tools │ ├── 1to2.js │ ├── README.md │ └── package.json ├── oneWayFunction.c ├── oneWayFunction.h ├── package.json ├── rc4.c ├── rc4.h ├── ripemd160.c ├── ripemd160.h ├── sha1.c ├── sha1.h ├── sha256.c ├── sha256.h ├── sha3_256.c ├── sha3_256.h ├── sha512.c ├── sha512.h ├── skein512_256.c ├── skein512_256.h ├── whirlpool.c └── whirlpool.h /.gitignore: -------------------------------------------------------------------------------- 1 | .vs/ 2 | .vscode/ 3 | .idea/ 4 | build/* 5 | /Release 6 | /Release*/ 7 | build/Release 8 | .deps 9 | .dirstamp 10 | .libs 11 | .*.swp 12 | *.bak 13 | *.rej 14 | *.orig 15 | *.pyc 16 | *.o 17 | *.o-* 18 | *.patch 19 | *.a 20 | 21 | *.lo 22 | *.la 23 | 24 | *.log 25 | *.trs 26 | *.dmg 27 | *.d 28 | *.d.* 29 | PoW 30 | 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Ulord 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | CXX = g++ 3 | CFLAGS = -std=c99 -O3 -g 4 | CXXFLAGS= -O3 -g 5 | INCLUDEFLAGS = 6 | LDFLAGS = -fopenmp -lssl -lcrypto 7 | OBJS = PoW.o hmac_md5.o aes128.o camellia128.o crc32.o gost.o ripemd160.o sha1.o sha3_256.o skein512_256.o blake2s256.o des.o haval5_256.o rc4.o sha256.o sha512.o whirlpool.o jtr_gost.o jtr_skein.o jtr_crc32.o jtr_haval.o blake2s.o keccak1600.o my_time.o common.o PoW.o oneWayFunction.o 8 | TARGETS = PoW libbitcoin_hello.a 9 | 10 | .PHONY:all 11 | all : $(TARGETS) 12 | 13 | PoW:main.o $(OBJS) 14 | $(CXX) -o $@ $^ $(LDFLAGS) 15 | # rm *.d *.o 16 | 17 | libbitcoin_hello.a: $(OBJS) 18 | ar crv $@ $^ 19 | 20 | %.o:%.c 21 | $(CC) $(CFLAGS) -o $@ -c $< $(INCLUDEFLAGS) 22 | 23 | %.d:%.c 24 | @set -e; rm -f $@; $(CC) -MM $< $(INCLUDEFLAGS) > $@.$$$$; \ 25 | sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ 26 | rm -f $@.$$$$ 27 | 28 | -include $(OBJS:.o=.d) 29 | 30 | .PHONY:clean 31 | clean: 32 | rm -f $(TARGETS) *.o *.d *.d.* 33 | -------------------------------------------------------------------------------- /PoW.h: -------------------------------------------------------------------------------- 1 | #ifndef POW_H 2 | #define POW_H 3 | 4 | #include 5 | #include 6 | 7 | #include "common.h" 8 | 9 | #define WORK_MEMORY_SIZE (1024*1024) 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | /* 16 | * Step 1: Initialize working memory. 17 | */ 18 | void initWorkMemory(uint8_t *input, uint32_t inputLen, uint8_t *Maddr, const uint32_t K); 19 | 20 | /* 21 | * Step 2: Modify the working memory contents. 22 | */ 23 | void modifyWorkMemory(uint8_t *Maddr, const uint32_t L, const uint32_t C, uint8_t *result); 24 | 25 | /* 26 | * Step 3: Calculate the final result. 27 | */ 28 | void calculateFinalResult(uint8_t *Maddr, uint8_t *c, const uint32_t D, uint8_t *result); 29 | 30 | /* 31 | * Correctness & Performance test for Proof of work 32 | */ 33 | void testPowFunction(uint8_t *mess, uint32_t messLen, const int64_t iterNum); 34 | void powNistTest(const char *outFileName); 35 | 36 | /* 37 | * smr 38 | */ 39 | void helloHash(uint8_t *mess, uint32_t messLen, uint8_t output[OUTPUT_LEN]); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | /* 46 | * Proof of work. 47 | */ 48 | void powFunction(uint8_t *input, uint32_t inputLen, uint8_t *Maddr, uint8_t *output); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [sunl@localhost PoW]$ ./PoW hashcat 2 | **************************** Correctness test (One way function) **************************** 3 | Test message: hashcat 4 | 00 SHA3-256 d60fcf6585da4e17224f58858970f0ed5ab042c3916b76b0b828e62eaf636cbd 5 | 01 SHA1 125d38130752be6f1b710b727768294d0e6a277b79cde0eea011a8458fde3cbe 6 | 02 SHA256 127e6fbfe24a750e72930c220a8e138275656b8e5d8f48a98c3c92df2caba935 7 | 03 SHA512 b67061ba08c087b396df4f47661bfe098e7de3d4c7b7de51914064f32a36eabe 8 | 04 Whirlpool aefc3088ab874844b539c32c008f0f4fac8d63ddb21f441787f82abba85739d7 9 | 05 RIPEMD-160 6fc8a2f9a021da2b71a9c8ce85586082467f7eb600d9c268807e206d92006a6b 10 | 06 BLAKE2s(256bits) 2c719b484789ad5f6fc1739012182169b25484af156adc91d4f64f72400e574a 11 | 07 AES(128bits) 0d1630bf9b56c515587d12015e1215daa5e50b19e46e4bff3cff2c90a1b1b586 12 | 08 DES b1f4734a9c6f4e275212914931d4d37e104479d43b0f784846e5983cff26b355 13 | 09 RC4 4e37223ef35eb9a548e18daf69fb4ab62eccdd9d12d5456e4e2de42421017e07 14 | 10 Camellia(128bits) b9ac51b5b658cc157b968a30ea5195d24df7490853de5fb6de1bd8d95bd5ddf4 15 | 11 CRC32 27dc803c0dfecf954abff2666caa0bc7329ab0bf9f8ae065b6eda1fe98befb37 16 | 12 HMAC(MD5) 3bd73ff59cd127e7ace5db20f6fbaf5d27c2ef5510bcc2faa2b00f5a5741c7b6 17 | 13 GOST R 34.11-94 df226c2c6dcb1d995c0299a33a084b201544293c31fc3d279530121d36bbcea9 18 | 14 HAVAL-256/5 72f72ddb75c084e6bfe4b939299c55f3d1c1d79f5ec5a9cc3470e0fa56914e9a 19 | 15 Skein-512(256bits) 45e91567c3263a5fb2bcb4a4e403c3b776c087be7176335b2b4d97d3ef47614c 20 | ********************************************************************************************* 21 | ************************************************* Performance test (One way function) ************************************************* 22 | Algorithm 1 4 8 12 16 20 24 32 48 64 23 | 00 SHA3-256 1010 Kps 4041 Kps 8046 Kps 11692 Kps 10545 Kps 10355 Kps 11052 Kps 11581 Kps 11463 Kps 11808 Kps 24 | 01 SHA1 2379 Kps 9252 Kps 18560 Kps 24549 Kps 22240 Kps 25991 Kps 25987 Kps 25409 Kps 25145 Kps 25985 Kps 25 | 02 SHA256 2810 Kps 11132 Kps 19997 Kps 26516 Kps 27441 Kps 31146 Kps 29642 Kps 30162 Kps 30436 Kps 30521 Kps 26 | 03 SHA512 1796 Kps 7134 Kps 14262 Kps 13542 Kps 17585 Kps 20353 Kps 20074 Kps 19056 Kps 20440 Kps 20568 Kps 27 | 04 Whirlpool 1121 Kps 4468 Kps 8909 Kps 12669 Kps 11428 Kps 11432 Kps 12172 Kps 13057 Kps 13018 Kps 12556 Kps 28 | 05 RIPEMD-160 1002 Kps 3993 Kps 7968 Kps 11842 Kps 9302 Kps 11164 Kps 11462 Kps 10852 Kps 11609 Kps 11784 Kps 29 | 06 BLAKE2s(256bits) 3361 Kps 13382 Kps 26705 Kps 35174 Kps 30524 Kps 33288 Kps 35013 Kps 38655 Kps 38455 Kps 37948 Kps 30 | 07 AES(128bits) 921 Kps 3674 Kps 7320 Kps 9397 Kps 9777 Kps 9868 Kps 10219 Kps 10292 Kps 10666 Kps 10767 Kps 31 | 08 DES 657 Kps 2618 Kps 5228 Kps 7751 Kps 6795 Kps 7389 Kps 7085 Kps 7432 Kps 7604 Kps 7723 Kps 32 | 09 RC4 754 Kps 3012 Kps 6013 Kps 8974 Kps 7760 Kps 8058 Kps 8592 Kps 8429 Kps 8801 Kps 8870 Kps 33 | 10 Camellia(128bits) 1075 Kps 4282 Kps 8544 Kps 12605 Kps 10972 Kps 12147 Kps 11262 Kps 12375 Kps 12316 Kps 12300 Kps 34 | 11 CRC32 2185 Kps 8701 Kps 17445 Kps 24501 Kps 19951 Kps 20649 Kps 25113 Kps 24152 Kps 25284 Kps 24897 Kps 35 | 12 HMAC(MD5) 481 Kps 1042 Kps 1916 Kps 2782 Kps 2960 Kps 3315 Kps 3604 Kps 3972 Kps 4243 Kps 4656 Kps 36 | 13 GOST R 34.11-94 372 Kps 1485 Kps 2974 Kps 4430 Kps 3965 Kps 4130 Kps 4162 Kps 4362 Kps 4359 Kps 4383 Kps 37 | 14 HAVAL-256/5 1617 Kps 6464 Kps 12858 Kps 18313 Kps 16855 Kps 17738 Kps 17991 Kps 17358 Kps 17705 Kps 18522 Kps 38 | 15 Skein-512(256bits) 2319 Kps 9237 Kps 18491 Kps 19833 Kps 24235 Kps 22065 Kps 26723 Kps 25705 Kps 25774 Kps 25915 Kps 39 | *************************************************************************************************************************************** 40 | ****************************** Correctness test (PoW function) ****************************** 41 | Test message: hashcat 42 | PoW 224afc7c2525c33eb428167c1fa1b2fa7cf90576ad875064d9948276218a3a75 43 | ********************************************************************************************* 44 | *************************************************** Performance test (PoW function) *************************************************** 45 | Algorithm 1 4 8 12 16 20 24 32 48 64 46 | 00 PoW 80 bps 318 bps 635 bps 951 bps 911 bps 947 bps 920 bps 900 bps 807 bps 788 bps 47 | *************************************************************************************************************************************** 48 | 49 | node-gyp configure --nodedir ~/.node-gyp/node-v8.11.1/ 50 | -------------------------------------------------------------------------------- /aes128.c: -------------------------------------------------------------------------------- 1 | #include "aes128.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "common.h" 12 | 13 | /* 14 | * 功能:单向函数 AES128 15 | * 输入:1. input :输入消息 16 | * 2. output:输出结果 17 | */ 18 | void aes128(uint8_t *input, uint32_t inputLen, uint8_t *output) { 19 | /** 20 | * $hash[0:31] = sha256($input) 21 | * $hash2[0:15] = md5($hash[0:31]) 22 | * $key = aes128_set_key($hash2[0:15]) 23 | * $output[ 0:15] = aes128_encrypt($key, $hash[ 0:15]) 24 | * $output[16:31] = aes128_encrypt($key, $hash[16:31]) 25 | **/ 26 | uint8_t sha256Digest[SHA256_DIGEST_LENGTH]; 27 | 28 | SHA256_CTX sha256_ctx; 29 | SHA256_Init(&sha256_ctx); 30 | SHA256_Update(&sha256_ctx, input, inputLen); 31 | SHA256_Final(sha256Digest, &sha256_ctx); 32 | 33 | uint8_t md5Digest[MD5_DIGEST_LENGTH]; 34 | 35 | MD5_CTX md5_ctx; 36 | MD5_Init(&md5_ctx); 37 | MD5_Update(&md5_ctx, sha256Digest, SHA256_DIGEST_LENGTH); 38 | MD5_Final(md5Digest, &md5_ctx); 39 | 40 | AES_KEY akey; 41 | if(AES_set_encrypt_key(md5Digest, 128, &akey) < 0) { 42 | fprintf(stderr, "AES_set_encrypt_key failed in crypt!\n"); 43 | abort(); 44 | } 45 | uint8_t result[SHA256_DIGEST_LENGTH]; 46 | AES_encrypt(sha256Digest, result, &akey); 47 | AES_encrypt(sha256Digest + AES_BLOCK_SIZE, result + AES_BLOCK_SIZE, &akey); 48 | 49 | memcpy(output, result, OUTPUT_LEN*sizeof(uint8_t)); 50 | } 51 | -------------------------------------------------------------------------------- /aes128.h: -------------------------------------------------------------------------------- 1 | #ifndef AES128_H 2 | #define AES128_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /* 11 | * 功能:单向函数 AES128 12 | * 输入:1. input :输入消息 13 | * 2. output:输出结果 14 | */ 15 | void aes128(uint8_t *input, uint32_t inputLen, uint8_t *output); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | "targets": [ 3 | { 4 | "target_name": "multihashing", 5 | "sources": [ 6 | "multihashing.cc", 7 | "aes128.c", 8 | "blake2s.c", 9 | "blake2s256.c", 10 | "camellia128.c", 11 | "common.c", 12 | "crc32.c", 13 | "des.c", 14 | "gost.c", 15 | "haval5_256.c", 16 | "hmac_md5.c", 17 | "jtr_crc32.c", 18 | "jtr_gost.c", 19 | "jtr_haval.c", 20 | "jtr_skein.c", 21 | "keccak1600.c", 22 | "my_time.c", 23 | "oneWayFunction.c", 24 | "rc4.c", 25 | "ripemd160.c", 26 | "sha1.c", 27 | "sha3_256.c", 28 | "sha256.c", 29 | "sha512.c", 30 | "skein512_256.c", 31 | "whirlpool.c", 32 | "PoW.c" 33 | ], 34 | "include_dirs": [ 35 | "crypto", 36 | " 13 | * More information about the BLAKE2 hash function and its implementations 14 | * can be found at https://blake2.net. 15 | */ 16 | 17 | #ifndef BLAKE2_IMPL_H 18 | #define BLAKE2_IMPL_H 19 | 20 | #include 21 | #include 22 | 23 | static inline uint32_t load32(const uint8_t *src) 24 | { 25 | const union { 26 | long one; 27 | char little; 28 | } is_endian = { 1 }; 29 | 30 | if (is_endian.little) { 31 | uint32_t w; 32 | memcpy(&w, src, sizeof(w)); 33 | return w; 34 | } else { 35 | uint32_t w = ((uint32_t)src[0]) 36 | | ((uint32_t)src[1] << 8) 37 | | ((uint32_t)src[2] << 16) 38 | | ((uint32_t)src[3] << 24); 39 | return w; 40 | } 41 | } 42 | 43 | static inline uint64_t load64(const uint8_t *src) 44 | { 45 | const union { 46 | long one; 47 | char little; 48 | } is_endian = { 1 }; 49 | 50 | if (is_endian.little) { 51 | uint64_t w; 52 | memcpy(&w, src, sizeof(w)); 53 | return w; 54 | } else { 55 | uint64_t w = ((uint64_t)src[0]) 56 | | ((uint64_t)src[1] << 8) 57 | | ((uint64_t)src[2] << 16) 58 | | ((uint64_t)src[3] << 24) 59 | | ((uint64_t)src[4] << 32) 60 | | ((uint64_t)src[5] << 40) 61 | | ((uint64_t)src[6] << 48) 62 | | ((uint64_t)src[7] << 56); 63 | return w; 64 | } 65 | } 66 | 67 | static inline void store32(uint8_t *dst, uint32_t w) 68 | { 69 | const union { 70 | long one; 71 | char little; 72 | } is_endian = { 1 }; 73 | 74 | if (is_endian.little) { 75 | memcpy(dst, &w, sizeof(w)); 76 | } else { 77 | uint8_t *p = (uint8_t *)dst; 78 | int i; 79 | 80 | for (i = 0; i < 4; i++) 81 | p[i] = (uint8_t)(w >> (8 * i)); 82 | } 83 | } 84 | 85 | static inline void store64(uint8_t *dst, uint64_t w) 86 | { 87 | const union { 88 | long one; 89 | char little; 90 | } is_endian = { 1 }; 91 | 92 | if (is_endian.little) { 93 | memcpy(dst, &w, sizeof(w)); 94 | } else { 95 | uint8_t *p = (uint8_t *)dst; 96 | int i; 97 | 98 | for (i = 0; i < 8; i++) 99 | p[i] = (uint8_t)(w >> (8 * i)); 100 | } 101 | } 102 | 103 | static inline uint64_t load48(const uint8_t *src) 104 | { 105 | uint64_t w = ((uint64_t)src[0]) 106 | | ((uint64_t)src[1] << 8) 107 | | ((uint64_t)src[2] << 16) 108 | | ((uint64_t)src[3] << 24) 109 | | ((uint64_t)src[4] << 32) 110 | | ((uint64_t)src[5] << 40); 111 | return w; 112 | } 113 | 114 | static inline void store48(uint8_t *dst, uint64_t w) 115 | { 116 | uint8_t *p = (uint8_t *)dst; 117 | p[0] = (uint8_t)w; 118 | p[1] = (uint8_t)(w>>8); 119 | p[2] = (uint8_t)(w>>16); 120 | p[3] = (uint8_t)(w>>24); 121 | p[4] = (uint8_t)(w>>32); 122 | p[5] = (uint8_t)(w>>40); 123 | } 124 | 125 | static inline uint32_t rotr32(const uint32_t w, const unsigned int c) 126 | { 127 | return (w >> c) | (w << (32 - c)); 128 | } 129 | 130 | static inline uint64_t rotr64(const uint64_t w, const unsigned int c) 131 | { 132 | return (w >> c) | (w << (64 - c)); 133 | } 134 | 135 | #endif 136 | -------------------------------------------------------------------------------- /blake2s.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved. 3 | * 4 | * Licensed under the OpenSSL license (the "License"). You may not use 5 | * this file except in compliance with the License. You can obtain a copy 6 | * in the file LICENSE in the source distribution or at 7 | * https://www.openssl.org/source/license.html 8 | */ 9 | 10 | /* 11 | * Derived from the BLAKE2 reference implementation written by Samuel Neves. 12 | * Copyright 2012, Samuel Neves 13 | * More information about the BLAKE2 hash function and its implementations 14 | * can be found at https://blake2.net. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | #include "blake2s.h" 22 | #include "blake2_impl.h" 23 | 24 | static const uint32_t blake2s_IV[8] = 25 | { 26 | 0x6A09E667U, 0xBB67AE85U, 0x3C6EF372U, 0xA54FF53AU, 27 | 0x510E527FU, 0x9B05688CU, 0x1F83D9ABU, 0x5BE0CD19U 28 | }; 29 | 30 | static const uint8_t blake2s_sigma[10][16] = 31 | { 32 | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } , 33 | { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } , 34 | { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 } , 35 | { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 } , 36 | { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 } , 37 | { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 } , 38 | { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 } , 39 | { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 } , 40 | { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 } , 41 | { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 } , 42 | }; 43 | 44 | /* Set that it's the last block we'll compress */ 45 | static inline void blake2s_set_lastblock(BLAKE2S_CTX *S) 46 | { 47 | S->f[0] = -1; 48 | } 49 | 50 | /* Initialize the hashing state. */ 51 | static inline void blake2s_init0(BLAKE2S_CTX *S) 52 | { 53 | int i; 54 | 55 | memset(S, 0, sizeof(BLAKE2S_CTX)); 56 | for (i = 0; i < 8; ++i) { 57 | S->h[i] = blake2s_IV[i]; 58 | } 59 | } 60 | 61 | /* init2 xors IV with input parameter block */ 62 | static void blake2s_init_param(BLAKE2S_CTX *S, const BLAKE2S_PARAM *P) 63 | { 64 | const uint8_t *p = (const uint8_t *)(P); 65 | size_t i; 66 | 67 | /* The param struct is carefully hand packed, and should be 32 bytes on 68 | * every platform. */ 69 | assert(sizeof(BLAKE2S_PARAM) == 32); 70 | blake2s_init0(S); 71 | /* IV XOR ParamBlock */ 72 | for (i = 0; i < 8; ++i) { 73 | S->h[i] ^= load32(&p[i*4]); 74 | } 75 | } 76 | 77 | /* Initialize the hashing context. Always returns 1. */ 78 | int BLAKE2s_Init(BLAKE2S_CTX *c) 79 | { 80 | BLAKE2S_PARAM P[1]; 81 | 82 | P->digest_length = BLAKE2S_DIGEST_LENGTH; 83 | P->key_length = 0; 84 | P->fanout = 1; 85 | P->depth = 1; 86 | store32(P->leaf_length, 0); 87 | store48(P->node_offset, 0); 88 | P->node_depth = 0; 89 | P->inner_length = 0; 90 | memset(P->salt, 0, sizeof(P->salt)); 91 | memset(P->personal, 0, sizeof(P->personal)); 92 | blake2s_init_param(c, P); 93 | return 1; 94 | } 95 | 96 | /* Permute the state while xoring in the block of data. */ 97 | static void blake2s_compress(BLAKE2S_CTX *S, 98 | const uint8_t *blocks, 99 | size_t len) 100 | { 101 | uint32_t m[16]; 102 | uint32_t v[16]; 103 | size_t i; 104 | size_t increment; 105 | 106 | /* 107 | * There are two distinct usage vectors for this function: 108 | * 109 | * a) BLAKE2s_Update uses it to process complete blocks, 110 | * possibly more than one at a time; 111 | * 112 | * b) BLAK2s_Final uses it to process last block, always 113 | * single but possibly incomplete, in which case caller 114 | * pads input with zeros. 115 | */ 116 | assert(len < BLAKE2S_BLOCKBYTES || len % BLAKE2S_BLOCKBYTES == 0); 117 | 118 | /* 119 | * Since last block is always processed with separate call, 120 | * |len| not being multiple of complete blocks can be observed 121 | * only with |len| being less than BLAKE2S_BLOCKBYTES ("less" 122 | * including even zero), which is why following assignment doesn't 123 | * have to reside inside the main loop below. 124 | */ 125 | increment = len < BLAKE2S_BLOCKBYTES ? len : BLAKE2S_BLOCKBYTES; 126 | 127 | for (i = 0; i < 8; ++i) { 128 | v[i] = S->h[i]; 129 | } 130 | 131 | do { 132 | for (i = 0; i < 16; ++i) { 133 | m[i] = load32(blocks + i * sizeof(m[i])); 134 | } 135 | 136 | /* blake2s_increment_counter */ 137 | S->t[0] += increment; 138 | S->t[1] += (S->t[0] < increment); 139 | 140 | v[ 8] = blake2s_IV[0]; 141 | v[ 9] = blake2s_IV[1]; 142 | v[10] = blake2s_IV[2]; 143 | v[11] = blake2s_IV[3]; 144 | v[12] = S->t[0] ^ blake2s_IV[4]; 145 | v[13] = S->t[1] ^ blake2s_IV[5]; 146 | v[14] = S->f[0] ^ blake2s_IV[6]; 147 | v[15] = S->f[1] ^ blake2s_IV[7]; 148 | #define G(r,i,a,b,c,d) \ 149 | do { \ 150 | a = a + b + m[blake2s_sigma[r][2*i+0]]; \ 151 | d = rotr32(d ^ a, 16); \ 152 | c = c + d; \ 153 | b = rotr32(b ^ c, 12); \ 154 | a = a + b + m[blake2s_sigma[r][2*i+1]]; \ 155 | d = rotr32(d ^ a, 8); \ 156 | c = c + d; \ 157 | b = rotr32(b ^ c, 7); \ 158 | } while (0) 159 | #define ROUND(r) \ 160 | do { \ 161 | G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \ 162 | G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \ 163 | G(r,2,v[ 2],v[ 6],v[10],v[14]); \ 164 | G(r,3,v[ 3],v[ 7],v[11],v[15]); \ 165 | G(r,4,v[ 0],v[ 5],v[10],v[15]); \ 166 | G(r,5,v[ 1],v[ 6],v[11],v[12]); \ 167 | G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \ 168 | G(r,7,v[ 3],v[ 4],v[ 9],v[14]); \ 169 | } while (0) 170 | #if defined(OPENSSL_SMALL_FOOTPRINT) 171 | /* almost 3x reduction on x86_64, 4.5x on ARMv8, 4x on ARMv4 */ 172 | for (i = 0; i < 10; i++) { 173 | ROUND(i); 174 | } 175 | #else 176 | ROUND(0); 177 | ROUND(1); 178 | ROUND(2); 179 | ROUND(3); 180 | ROUND(4); 181 | ROUND(5); 182 | ROUND(6); 183 | ROUND(7); 184 | ROUND(8); 185 | ROUND(9); 186 | #endif 187 | 188 | for (i = 0; i < 8; ++i) { 189 | S->h[i] = v[i] ^= v[i + 8] ^ S->h[i]; 190 | } 191 | #undef G 192 | #undef ROUND 193 | blocks += increment; 194 | len -= increment; 195 | } while (len); 196 | } 197 | 198 | /* Absorb the input data into the hash state. Always returns 1. */ 199 | int BLAKE2s_Update(BLAKE2S_CTX *c, const void *data, size_t datalen) 200 | { 201 | const uint8_t *in = data; 202 | size_t fill; 203 | 204 | /* 205 | * Intuitively one would expect intermediate buffer, c->buf, to 206 | * store incomplete blocks. But in this case we are interested to 207 | * temporarily stash even complete blocks, because last one in the 208 | * stream has to be treated in special way, and at this point we 209 | * don't know if last block in *this* call is last one "ever". This 210 | * is the reason for why |datalen| is compared as >, and not >=. 211 | */ 212 | fill = sizeof(c->buf) - c->buflen; 213 | if (datalen > fill) { 214 | if (c->buflen) { 215 | memcpy(c->buf + c->buflen, in, fill); /* Fill buffer */ 216 | blake2s_compress(c, c->buf, BLAKE2S_BLOCKBYTES); 217 | c->buflen = 0; 218 | in += fill; 219 | datalen -= fill; 220 | } 221 | if (datalen > BLAKE2S_BLOCKBYTES) { 222 | size_t stashlen = datalen % BLAKE2S_BLOCKBYTES; 223 | /* 224 | * If |datalen| is a multiple of the blocksize, stash 225 | * last complete block, it can be final one... 226 | */ 227 | stashlen = stashlen ? stashlen : BLAKE2S_BLOCKBYTES; 228 | datalen -= stashlen; 229 | blake2s_compress(c, in, datalen); 230 | in += datalen; 231 | datalen = stashlen; 232 | } 233 | } 234 | 235 | assert(datalen <= BLAKE2S_BLOCKBYTES); 236 | 237 | memcpy(c->buf + c->buflen, in, datalen); 238 | c->buflen += datalen; /* Be lazy, do not compress */ 239 | 240 | return 1; 241 | } 242 | 243 | /* 244 | * Calculate the final hash and save it in md. 245 | * Always returns 1. 246 | */ 247 | int BLAKE2s_Final(unsigned char *md, BLAKE2S_CTX *c) 248 | { 249 | int i; 250 | 251 | blake2s_set_lastblock(c); 252 | /* Padding */ 253 | memset(c->buf + c->buflen, 0, sizeof(c->buf) - c->buflen); 254 | blake2s_compress(c, c->buf, c->buflen); 255 | 256 | /* Output full hash to temp buffer */ 257 | for (i = 0; i < 8; ++i) { 258 | store32(md + sizeof(c->h[i]) * i, c->h[i]); 259 | } 260 | 261 | OPENSSL_cleanse(c, sizeof(BLAKE2S_CTX)); 262 | return 1; 263 | } 264 | -------------------------------------------------------------------------------- /blake2s.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved. 3 | * 4 | * Licensed under the OpenSSL license (the "License"). You may not use 5 | * this file except in compliance with the License. You can obtain a copy 6 | * in the file LICENSE in the source distribution or at 7 | * https://www.openssl.org/source/license.html 8 | */ 9 | 10 | /* 11 | * Derived from the BLAKE2 reference implementation written by Samuel Neves. 12 | * Copyright 2012, Samuel Neves 13 | * More information about the BLAKE2 hash function and its implementations 14 | * can be found at https://blake2.net. 15 | */ 16 | 17 | #ifndef BLAKE2S_H 18 | #define BLAKE2S_H 19 | 20 | #include 21 | #include 22 | 23 | #define BLAKE2S_BLOCKBYTES 64 24 | #define BLAKE2S_OUTBYTES 32 25 | #define BLAKE2S_KEYBYTES 32 26 | #define BLAKE2S_SALTBYTES 8 27 | #define BLAKE2S_PERSONALBYTES 8 28 | 29 | struct blake2s_param_st { 30 | uint8_t digest_length; /* 1 */ 31 | uint8_t key_length; /* 2 */ 32 | uint8_t fanout; /* 3 */ 33 | uint8_t depth; /* 4 */ 34 | uint8_t leaf_length[4];/* 8 */ 35 | uint8_t node_offset[6];/* 14 */ 36 | uint8_t node_depth; /* 15 */ 37 | uint8_t inner_length; /* 16 */ 38 | uint8_t salt[BLAKE2S_SALTBYTES]; /* 24 */ 39 | uint8_t personal[BLAKE2S_PERSONALBYTES]; /* 32 */ 40 | }; 41 | 42 | typedef struct blake2s_param_st BLAKE2S_PARAM; 43 | 44 | struct blake2s_ctx_st { 45 | uint32_t h[8]; 46 | uint32_t t[2]; 47 | uint32_t f[2]; 48 | uint8_t buf[BLAKE2S_BLOCKBYTES]; 49 | size_t buflen; 50 | }; 51 | 52 | #define BLAKE2S_DIGEST_LENGTH 32 53 | 54 | typedef struct blake2s_ctx_st BLAKE2S_CTX; 55 | 56 | int BLAKE2s_Init(BLAKE2S_CTX *c); 57 | int BLAKE2s_Update(BLAKE2S_CTX *c, const void *data, size_t datalen); 58 | int BLAKE2s_Final(unsigned char *md, BLAKE2S_CTX *c); 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /blake2s256.c: -------------------------------------------------------------------------------- 1 | #include "blake2s256.h" 2 | 3 | #include 4 | #include 5 | #include "blake2s.h" 6 | 7 | #include "common.h" 8 | 9 | void blake2s256(uint8_t *input, uint32_t inputLen, uint8_t *output) { 10 | uint8_t result[BLAKE2S_OUTBYTES]; 11 | 12 | BLAKE2S_CTX ctx; 13 | BLAKE2s_Init(&ctx); 14 | BLAKE2s_Update(&ctx, input, inputLen); 15 | BLAKE2s_Final(result, &ctx); 16 | 17 | memcpy(output, result, OUTPUT_LEN*sizeof(uint8_t)); 18 | } 19 | -------------------------------------------------------------------------------- /blake2s256.h: -------------------------------------------------------------------------------- 1 | #ifndef BLAKE2S256_H 2 | #define BLAKE2S256_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /* 11 | * 功能:单向函数 SHA3-256 12 | * 输入:1. input :输入消息 13 | * 2. output:输出结果 14 | */ 15 | void blake2s256(uint8_t *input, uint32_t inputLen, uint8_t *output); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | 22 | #endif -------------------------------------------------------------------------------- /camellia128.c: -------------------------------------------------------------------------------- 1 | #include "camellia128.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "common.h" 12 | 13 | /* 14 | * 功能:单向函数 Camellia(128bits) 15 | * 输入:1. input :输入消息 16 | * 2. output:输出结果 17 | */ 18 | void camellia128(uint8_t *input, uint32_t inputLen, uint8_t *output) { 19 | /** 20 | * $hash[0:31] = sha256($input) 21 | * $hash2[0:15] = md5($hash[0:31]) 22 | * $key = aes256_set_key($hash2[0:15]) 23 | * $output[ 0:15] = aes256_encrypt($key, $hash[ 0:15]) 24 | * $output[16:31] = aes256_encrypt($key, $hash[16:31]) 25 | **/ 26 | uint8_t sha256Digest[SHA256_DIGEST_LENGTH]; 27 | 28 | SHA256_CTX sha256_ctx; 29 | SHA256_Init(&sha256_ctx); 30 | SHA256_Update(&sha256_ctx, input, inputLen); 31 | SHA256_Final(sha256Digest, &sha256_ctx); 32 | 33 | uint8_t md5Digest[MD5_DIGEST_LENGTH]; 34 | 35 | MD5_CTX md5_ctx; 36 | MD5_Init(&md5_ctx); 37 | MD5_Update(&md5_ctx, sha256Digest, SHA256_DIGEST_LENGTH); 38 | MD5_Final(md5Digest, &md5_ctx); 39 | 40 | CAMELLIA_KEY akey; 41 | if(Camellia_set_key(md5Digest, 128, &akey) < 0) { 42 | fprintf(stderr, "Camellia_set_key failed in crypt!\n"); 43 | abort(); 44 | } 45 | uint8_t result[SHA256_DIGEST_LENGTH]; 46 | Camellia_encrypt(sha256Digest, result, &akey); 47 | Camellia_encrypt(sha256Digest + CAMELLIA_BLOCK_SIZE, result + CAMELLIA_BLOCK_SIZE, &akey); 48 | 49 | memcpy(output, result, OUTPUT_LEN*sizeof(uint8_t)); 50 | } 51 | -------------------------------------------------------------------------------- /camellia128.h: -------------------------------------------------------------------------------- 1 | #ifndef CAMELLIA128_H 2 | #define CAMELLIA128_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | void camellia128(uint8_t *input, uint32_t inputLen, uint8_t *output); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /common.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #ifdef SYS_OS_MAC 8 | #include 9 | #else 10 | #include 11 | #endif 12 | 13 | /* 14 | * 功能:字节数组打印方法 15 | * 输入:1. mess:字节数组名称 16 | * 2. data:字节数组地址 17 | * 3. len :字数组长度 18 | */ 19 | void view_data_u8(const char *mess, 20 | uint8_t *data, uint32_t len) { 21 | printf("%-18s\t", mess); 22 | for (uint32_t i = 0; i < len; ++i) 23 | printf("%.2x", data[i]); 24 | printf("\n"); 25 | } 26 | 27 | /* 28 | * 功能:字数组打印方法 29 | * 输入:1. mess:字数组名称 30 | * 2. data:字数组地址 31 | * 3. len :字数组长度 32 | */ 33 | void view_data_u32(const char *mess, 34 | uint32_t *data, uint32_t len) { 35 | printf("%s: ", mess); 36 | for (uint32_t i = 0; i < len; ++i) 37 | printf("%.8x ", data[i]); 38 | printf("\n"); 39 | } 40 | -------------------------------------------------------------------------------- /common.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_H 2 | #define COMMON_H 3 | 4 | #include 5 | #include 6 | #include 7 | #ifdef SYS_OS_MAC 8 | #include 9 | #else 10 | #include 11 | #endif 12 | 13 | #define INPUT_LEN 140 14 | #define OUTPUT_LEN 32 15 | 16 | // Least common multiple 17 | inline uint32_t lcm(uint32_t num1, uint32_t num2) { 18 | uint32_t m = num1, n = num2; 19 | while(num2) { 20 | uint32_t r = num1 % num2; 21 | num1 = num2; 22 | num2 = r; 23 | } 24 | uint32_t lcm = m * n / num1; 25 | return lcm; 26 | } 27 | 28 | inline void reduce_bit_2(uint8_t *input, uint32_t inputLen, 29 | uint8_t *output, uint32_t bits) { 30 | uint32_t i, outputLen = (bits) >> 3; 31 | uint32_t lcmBytes = lcm(inputLen, outputLen); 32 | memcpy(output, input, outputLen * sizeof(uint8_t)); 33 | for (i = outputLen; i < lcmBytes; ++i) { 34 | output[i % outputLen] ^= input[i % inputLen]; 35 | } 36 | } 37 | 38 | inline void reduce_bit(uint8_t *input, uint32_t inputLen, 39 | uint8_t *output, uint32_t bits) { 40 | uint32_t i, outputLen = (bits) >> 3; 41 | memcpy(output, input, outputLen * sizeof(uint8_t)); 42 | for (i = outputLen; i < inputLen; ++i) { 43 | output[i % outputLen] ^= input[i % inputLen]; 44 | } 45 | } 46 | 47 | inline void rrs(uint8_t *input, uint32_t inputLen, 48 | uint8_t *output, uint32_t bits) { 49 | uint32_t shiftBytes = (bits) >> 3, shiftBits = (bits) & 0x7; 50 | uint32_t rIndex = (inputLen) - shiftBytes; 51 | uint32_t lIndex = (rIndex + (inputLen) - 1) % (inputLen); 52 | for (uint32_t i = 0; i < inputLen; ++i) { 53 | output[i] = (input[(rIndex++) % (inputLen)] >> shiftBits) | 54 | (input[(lIndex++) % (inputLen)] << (8 - shiftBits)); 55 | } 56 | } 57 | 58 | #ifdef __cplusplus 59 | extern "C" { 60 | #endif 61 | 62 | void view_data_u8(const char *mess, uint8_t *data, uint32_t len); 63 | void view_data_u32(const char *mess, uint32_t *data, uint32_t len); 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /crc32.c: -------------------------------------------------------------------------------- 1 | #include "crc32.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "common.h" 10 | #include "jtr_crc32.h" 11 | 12 | /* 13 | * 功能:单向函数 hello_crc32 14 | * 输入:1. input :输入消息 15 | * 2. output:输出结果 16 | */ 17 | void hello_crc32(uint8_t *input, uint32_t inputLen, uint8_t *output) { 18 | /** 19 | * $hash[0:31] = sha256($input) 20 | * $output[0:31] = crc32($hash[0:31]), crc by word 21 | **/ 22 | uint8_t sha256Digest[SHA256_DIGEST_LENGTH]; 23 | 24 | SHA256_CTX ctx; 25 | SHA256_Init(&ctx); 26 | SHA256_Update(&ctx, input, inputLen); 27 | SHA256_Final(sha256Digest, &ctx); 28 | 29 | CRC32_t crc; 30 | for (uint32_t i = 0; i < SHA256_DIGEST_LENGTH; i += 4) { 31 | CRC32_Init(&crc); 32 | CRC32_Update(&crc, &sha256Digest[i], 4); 33 | CRC32_Final(&output[i], crc); 34 | } 35 | } -------------------------------------------------------------------------------- /crc32.h: -------------------------------------------------------------------------------- 1 | #ifndef CRC32_H 2 | #define CRC32_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /* 11 | * 功能:单向函数 CRC32 12 | * 输入:1. input :输入消息 13 | * 2. output:输出结果 14 | */ 15 | void CRC32_Table_Init(); 16 | void hello_crc32(uint8_t *input, uint32_t inputLen, uint8_t *output); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /des.c: -------------------------------------------------------------------------------- 1 | #include "des.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "common.h" 12 | 13 | #define DES_BLOCK_SIZE 8 14 | 15 | /* 16 | * 功能:单向函数 des 17 | * 输入:1. input :输入消息 18 | * 2. output:输出结果 19 | */ 20 | void des(uint8_t *input, uint32_t inputLen, uint8_t *output) { 21 | /** 22 | * $hash[0:31] = sha256($input) 23 | * $hash2[0:15] = md5($hash[0:31]) 24 | * $key = DES_set_key_unchecked($hash2[0:15]) 25 | * $output[ 0: 7] = DES_encrypt($key, $hash[ 0: 7]) 26 | * $output[ 8:15] = DES_encrypt($key, $hash[ 8:15]) 27 | * $output[16:23] = DES_encrypt($key, $hash[16:23]) 28 | * $output[24:31] = DES_encrypt($key, $hash[24:31]) 29 | **/ 30 | uint8_t sha256Digest[SHA256_DIGEST_LENGTH]; 31 | 32 | SHA256_CTX ctx; 33 | SHA256_Init(&ctx); 34 | SHA256_Update(&ctx, input, inputLen); 35 | SHA256_Final(sha256Digest, &ctx); 36 | 37 | uint8_t md5Digest[MD5_DIGEST_LENGTH]; 38 | 39 | MD5_CTX md5_ctx; 40 | MD5_Init(&md5_ctx); 41 | MD5_Update(&md5_ctx, sha256Digest, SHA256_DIGEST_LENGTH); 42 | MD5_Final(md5Digest, &md5_ctx); 43 | 44 | uint8_t result[OUTPUT_LEN]; 45 | 46 | DES_key_schedule akey; 47 | DES_set_key_unchecked((const_DES_cblock *)md5Digest, &akey); 48 | DES_ecb_encrypt((const_DES_cblock *)sha256Digest, (const_DES_cblock *)result, &akey, DES_ENCRYPT); 49 | DES_ecb_encrypt((const_DES_cblock *)(sha256Digest+DES_BLOCK_SIZE), (const_DES_cblock *)(result+DES_BLOCK_SIZE), &akey, DES_ENCRYPT); 50 | DES_ecb_encrypt((const_DES_cblock *)(sha256Digest+2*DES_BLOCK_SIZE), (const_DES_cblock *)(result+2*DES_BLOCK_SIZE), &akey, DES_ENCRYPT); 51 | DES_ecb_encrypt((const_DES_cblock *)(sha256Digest+3*DES_BLOCK_SIZE), (const_DES_cblock *)(result+3*DES_BLOCK_SIZE), &akey, DES_ENCRYPT); 52 | 53 | memcpy(output, result, OUTPUT_LEN*sizeof(uint8_t)); 54 | } 55 | -------------------------------------------------------------------------------- /des.h: -------------------------------------------------------------------------------- 1 | #ifndef DES_H 2 | #define DES_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /* 11 | * 功能:单向函数 DES 12 | * 输入:1. input :输入消息 13 | * 2. output:输出结果 14 | */ 15 | void des(uint8_t *input, uint32_t inputLen, uint8_t *output); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /gost.c: -------------------------------------------------------------------------------- 1 | #include "gost.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "common.h" 8 | #include "jtr_gost.h" 9 | 10 | #define GOST_BINARY_SIZE 32 11 | 12 | /* 13 | * 功能:单向函数 GOST R 34.11-94 14 | * 输入:1. input :输入消息 15 | * 2. output:输出结果 16 | */ 17 | void gost(uint8_t *input, uint32_t inputLen, uint8_t *output) { 18 | uint8_t result[GOST_BINARY_SIZE]; 19 | 20 | gost_ctx ctx; 21 | john_gost_init(&ctx); 22 | john_gost_update(&ctx, input, inputLen); 23 | john_gost_final(&ctx, result); 24 | 25 | memcpy(output, result, OUTPUT_LEN*sizeof(uint8_t)); 26 | } -------------------------------------------------------------------------------- /gost.h: -------------------------------------------------------------------------------- 1 | #ifndef GOST_H 2 | #define GOST_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /* 11 | * 功能:单向函数 GOST R 34.11-94 12 | * 输入:1. input :输入消息 13 | * 2. output:输出结果 14 | */ 15 | void gost_init_table(void); 16 | void gost(uint8_t *input, uint32_t inputLen, uint8_t *output); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /haval5_256.c: -------------------------------------------------------------------------------- 1 | #include "haval5_256.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "common.h" 8 | #include "jtr_sph_haval.h" 9 | 10 | #define HAVAL5_256_BINARY_SIZE 32 11 | 12 | void haval5_256(uint8_t *input, uint32_t inputLen, uint8_t *output) { 13 | uint8_t result[HAVAL5_256_BINARY_SIZE]; 14 | 15 | sph_haval256_5_context ctx; 16 | sph_haval256_5_init(&ctx); 17 | sph_haval256_5(&ctx, input, inputLen); 18 | sph_haval256_5_close(&ctx, result); 19 | 20 | memcpy(output, result, OUTPUT_LEN*sizeof(uint8_t)); 21 | } 22 | -------------------------------------------------------------------------------- /haval5_256.h: -------------------------------------------------------------------------------- 1 | #ifndef HAVAL5_256_H 2 | #define HAVAL5_256_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /* 11 | * 功能:单向函数 HAVAL-256/5 12 | * 输入:1. input :输入消息 13 | * 2. output:输出结果 14 | */ 15 | void haval5_256(uint8_t *input, uint32_t inputLen, uint8_t *output); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /hmac_md5.c: -------------------------------------------------------------------------------- 1 | #include "hmac_md5.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "common.h" 13 | 14 | /* 15 | * 功能:单向函数 HMAC MD5 16 | * 输入:1. input :输入消息 17 | * 2. output:输出结果 18 | */ 19 | void hmac_md5(uint8_t *input, uint32_t inputLen, uint8_t *output) { 20 | uint8_t hmacMd5Digest[MD5_DIGEST_LENGTH]; 21 | unsigned int mdLen; 22 | 23 | // "OpenSSL 1.1.0h-fips 27 Mar 2018" 24 | #if (OPENSSL_VERSION_NUMBER >= 0x1010008fL) 25 | HMAC_CTX *ctx; 26 | 27 | ctx = HMAC_CTX_new(); 28 | HMAC_Init_ex(ctx, input, inputLen, EVP_md5(), NULL); 29 | HMAC_Update(ctx, input, inputLen); 30 | HMAC_Final(ctx, hmacMd5Digest, &mdLen); 31 | HMAC_CTX_free(ctx); 32 | #else 33 | HMAC_CTX ctx; 34 | 35 | HMAC_CTX_init(&ctx); 36 | HMAC_Init_ex(&ctx, input, inputLen, EVP_md5(), NULL); 37 | HMAC_Update(&ctx, input, inputLen); 38 | HMAC_Final(&ctx, hmacMd5Digest, &mdLen); 39 | HMAC_CTX_cleanup(&ctx); 40 | #endif 41 | 42 | uint8_t sha256Digest[SHA256_DIGEST_LENGTH]; 43 | 44 | SHA256_CTX sha256_ctx; 45 | SHA256_Init(&sha256_ctx); 46 | SHA256_Update(&sha256_ctx, hmacMd5Digest, MD5_DIGEST_LENGTH); 47 | SHA256_Final(sha256Digest, &sha256_ctx); 48 | 49 | memcpy(output, sha256Digest, OUTPUT_LEN*sizeof(uint8_t)); 50 | } 51 | -------------------------------------------------------------------------------- /hmac_md5.h: -------------------------------------------------------------------------------- 1 | #ifndef HMAC_MD5_H 2 | #define HMAC_MD5_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /* 11 | * 功能:单向函数 HMAC MD5 12 | * 输入:1. input :输入消息 13 | * 2. output:输出结果 14 | */ 15 | void hmac_md5(uint8_t *input, uint32_t inputLen, uint8_t *output); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('bindings')('multihashing.node') -------------------------------------------------------------------------------- /jtr_crc32.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a tiny implementation of CRC-32. 3 | * 4 | * This software was written by Solar Designer in 1998 and revised in 2005. 5 | * No copyright is claimed, and the software is hereby placed in the public 6 | * domain. 7 | * In case this attempt to disclaim copyright and place the software in the 8 | * public domain is deemed null and void, then the software is 9 | * Copyright (c) 1998,2005 by Solar Designer and it is hereby released to the 10 | * general public under the following terms: 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted. 14 | * 15 | * There's ABSOLUTELY NO WARRANTY, express or implied. 16 | * 17 | * (This is a heavily cut-down "BSD license".) 18 | */ 19 | 20 | #include 21 | 22 | #include "jtr_crc32.h" 23 | 24 | #define POLY 0xEDB88320 25 | #define ALL1 0xFFFFFFFF 26 | 27 | static CRC32_t table[256]; 28 | 29 | void CRC32_Init(CRC32_t *value) 30 | { 31 | *value = ALL1; 32 | } 33 | 34 | static int bInit = 0; 35 | 36 | void CRC32_Table_Init() 37 | { 38 | unsigned int index, bit; 39 | CRC32_t entry; 40 | 41 | if (bInit) return; 42 | bInit = 1; 43 | for (index = 0; index < 0x100; index++) { 44 | entry = index; 45 | 46 | for (bit = 0; bit < 8; bit++) 47 | if (entry & 1) { 48 | entry >>= 1; 49 | entry ^= POLY; 50 | } else 51 | entry >>= 1; 52 | 53 | table[index] = entry; 54 | } 55 | } 56 | 57 | 58 | void CRC32_Update(CRC32_t *value, void *data, unsigned int size) 59 | { 60 | unsigned char *ptr; 61 | unsigned int count; 62 | CRC32_t result; 63 | 64 | result = *value; 65 | ptr = data; 66 | count = size; 67 | 68 | if (count) 69 | do { 70 | result = (result >> 8) ^ table[(result ^ *ptr++) & 0xFF]; 71 | } while (--count); 72 | 73 | *value = result; 74 | } 75 | 76 | void CRC32_Final(unsigned char *out, CRC32_t value) 77 | { 78 | value = ~value; 79 | out[0] = value; 80 | out[1] = value >> 8; 81 | out[2] = value >> 16; 82 | out[3] = value >> 24; 83 | } 84 | -------------------------------------------------------------------------------- /jtr_crc32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a tiny implementation of CRC-32. 3 | * 4 | * This software was written by Solar Designer in 1998 and revised in 2005. 5 | * No copyright is claimed, and the software is hereby placed in the public 6 | * domain. 7 | * In case this attempt to disclaim copyright and place the software in the 8 | * public domain is deemed null and void, then the software is 9 | * Copyright (c) 1998,2005 by Solar Designer and it is hereby released to the 10 | * general public under the following terms: 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted. 14 | * 15 | * There's ABSOLUTELY NO WARRANTY, express or implied. 16 | * 17 | * (This is a heavily cut-down "BSD license".) 18 | */ 19 | 20 | #ifndef _JOHN_CRC32_H 21 | #define _JOHN_CRC32_H 22 | 23 | typedef unsigned int CRC32_t; 24 | 25 | /* 26 | * When called for the first time, allocates memory for and initializes 27 | * the internal table. Always initializes the CRC-32 value to all 1's. 28 | */ 29 | extern void CRC32_Init(CRC32_t *value); 30 | extern void CRC32_Table_Init(); 31 | 32 | /* 33 | * Updates the current CRC-32 value with the supplied data block. 34 | */ 35 | extern void CRC32_Update(CRC32_t *value, void *data, unsigned int size); 36 | 37 | /* 38 | * Finalizes the CRC-32 value by inverting all bits and saving it as 39 | * little-endian. 40 | */ 41 | extern void CRC32_Final(unsigned char *out, CRC32_t value); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /jtr_gost.h: -------------------------------------------------------------------------------- 1 | /* jtr_gost.h */ 2 | #ifndef JTR_GOST_H 3 | #define JTR_GOST_H 4 | 5 | #include 6 | #include 7 | 8 | #define ARCH_LITTLE_ENDIAN 1 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | /* if x86 compatible cpu */ 15 | // NOTE, we should get this from johnswap.h, but I have not done so 'yet' 16 | // A lot (all??) of the swapping code should also come from johnswap.h 17 | #if !defined (CPU_X64) && !defined (CPU_IA32) 18 | #if defined(i386) || defined(__i386__) || defined(__i486__) || \ 19 | defined(__i586__) || defined(__i686__) || defined(__pentium__) || \ 20 | defined(__pentiumpro__) || defined(__pentium4__) || \ 21 | defined(__nocona__) || defined(prescott) || defined(__core2__) || \ 22 | defined(__k6__) || defined(__k8__) || defined(__athlon__) || \ 23 | defined(__amd64) || defined(__amd64__) || \ 24 | defined(__x86_64) || defined(__x86_64__) || defined(_M_IX86) || \ 25 | defined(_M_AMD64) || defined(_M_IA64) || defined(_M_X64) 26 | /* detect if x86-64 instruction set is supported */ 27 | # if defined(_LP64) || defined(__LP64__) || defined(__x86_64) || \ 28 | defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64) 29 | # define CPU_X64 30 | # else 31 | # define CPU_IA32 32 | # endif 33 | #endif 34 | #endif 35 | 36 | #if defined(__GNUC__) && defined(CPU_IA32) && !defined(RHASH_NO_ASM) 37 | # define USE_GCC_ASM_IA32 38 | #elif defined(__GNUC__) && defined(CPU_X64) && !defined(RHASH_NO_ASM) 39 | # define USE_GCC_ASM_X64 40 | #endif 41 | 42 | #define IS_ALIGNED_32(p) (0 == (3 & ((const char*)(p) - (const char*)0))) 43 | #define IS_ALIGNED_64(p) (0 == (7 & ((const char*)(p) - (const char*)0))) 44 | 45 | #if defined(_MSC_VER) || defined(__BORLANDC__) 46 | #define I64(x) x##ui64 47 | #else 48 | #define I64(x) x##LL 49 | #endif 50 | 51 | /* convert a hash flag to index */ 52 | #if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) /* GCC < 3.4 */ 53 | # define rhash_ctz(x) __builtin_ctz(x) 54 | #else 55 | unsigned rhash_ctz(unsigned); /* define as function */ 56 | #endif 57 | 58 | void rhash_u32_swap_copy(void* to, int index, const void* from, size_t length); 59 | void rhash_u64_swap_copy(void* to, int index, const void* from, size_t length); 60 | void rhash_u32_memswap(unsigned *p, int length_in_u32); 61 | 62 | /* define bswap_32 */ 63 | #if defined(__GNUC__) && defined(CPU_IA32) && !defined(__i386__) 64 | /* for intel x86 CPU */ 65 | static inline uint32_t bswap_32(uint32_t x) { 66 | __asm("bswap\t%0" : "=r" (x) : "0" (x)); 67 | return x; 68 | } 69 | #elif defined(__GNUC__) && (__GNUC__ >= 4) && (__GNUC__ > 4 || __GNUC_MINOR__ >= 3) 70 | /* for GCC >= 4.3 */ 71 | # define bswap_32(x) __builtin_bswap32(x) 72 | #elif (_MSC_VER > 1300) && (defined(CPU_IA32) || defined(CPU_X64)) /* MS VC */ 73 | # define bswap_32(x) _byteswap_ulong((unsigned long)x) 74 | #elif !defined(__STRICT_ANSI__) 75 | /* general bswap_32 definition. Note, bswap_32 already defined as inline in GCC 3.4.4, but it sux. */ 76 | static inline uint32_t _JtR_Swap_32(uint32_t x) { 77 | x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0x00FF00FF); 78 | return (x >> 16) | (x << 16); 79 | } 80 | # define bswap_32(x) _JtR_Swap_32(x) 81 | #else 82 | #define bswap_32(x) ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \ 83 | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) 84 | #endif /* bswap_32 */ 85 | 86 | #if defined(__GNUC__) && (__GNUC__ >= 4) && (__GNUC__ > 4 || __GNUC_MINOR__ >= 3) 87 | # define bswap_64(x) __builtin_bswap64(x) 88 | #elif (_MSC_VER > 1300) && (defined(CPU_IA32) || defined(CPU_X64)) /* MS VC */ 89 | # define bswap_64(x) _byteswap_uint64((__int64)x) 90 | #elif !defined(__STRICT_ANSI__) 91 | /* general bswap_64 definition. Note, bswap_64 already defined as inline in GCC 3.4.4, but it sux. */ 92 | static inline uint64_t _JtR_Swap_64(uint64_t x) { 93 | union { 94 | uint64_t ll; 95 | uint32_t l[2]; 96 | } w, r; 97 | w.ll = x; 98 | r.l[0] = bswap_32(w.l[1]); 99 | r.l[1] = bswap_32(w.l[0]); 100 | return r.ll; 101 | } 102 | # define bswap_64(x) _JtR_Swap_64(x) 103 | #else 104 | #error "bswap_64 unsupported" 105 | #endif 106 | 107 | #if !ARCH_LITTLE_ENDIAN 108 | # define be2me_32(x) (x) 109 | # define be2me_64(x) (x) 110 | # define le2me_32(x) bswap_32(x) 111 | # define le2me_64(x) bswap_64(x) 112 | 113 | # define be32_copy(to, index, from, length) memcpy((to) + (index), (from), (length)) 114 | # define le32_copy(to, index, from, length) rhash_u32_swap_copy((to), (index), (from), (length)) 115 | # define be64_copy(to, index, from, length) memcpy((to) + (index), (from), (length)) 116 | # define le64_copy(to, index, from, length) rhash_u64_swap_copy((to), (index), (from), (length)) 117 | #else /* !ARCH_LITTLE_ENDIAN */ 118 | # define be2me_32(x) bswap_32(x) 119 | # define be2me_64(x) bswap_64(x) 120 | # define le2me_32(x) (x) 121 | # define le2me_64(x) (x) 122 | 123 | # define be32_copy(to, index, from, length) rhash_u32_swap_copy((to), (index), (from), (length)) 124 | # define le32_copy(to, index, from, length) memcpy((to) + (index), (from), (length)) 125 | # define be64_copy(to, index, from, length) rhash_u64_swap_copy((to), (index), (from), (length)) 126 | # define le64_copy(to, index, from, length) memcpy((to) + (index), (from), (length)) 127 | #endif /* !ARCH_LITTLE_ENDIAN */ 128 | 129 | /* ROTL/ROTR macros rotate a 32/64-bit word left/right by n bits */ 130 | #define ROTL32(dword, n) ((dword) << (n) ^ ((dword) >> (32 - (n)))) 131 | #define ROTR32(dword, n) ((dword) >> (n) ^ ((dword) << (32 - (n)))) 132 | #define ROTL64(qword, n) ((qword) << (n) ^ ((qword) >> (64 - (n)))) 133 | #define ROTR64(qword, n) ((qword) >> (n) ^ ((qword) << (64 - (n)))) 134 | 135 | #define gost_block_size 32 136 | #define gost_hash_length 32 137 | 138 | /* algorithm context */ 139 | typedef struct gost_ctx 140 | { 141 | unsigned hash[8]; /* algorithm 256-bit state */ 142 | unsigned sum[8]; /* sum of processed message blocks */ 143 | unsigned char message[gost_block_size]; /* 256-bit buffer for leftovers */ 144 | uint64_t length; /* number of processed bytes */ 145 | unsigned cryptpro; /* boolean flag, the type of sbox to use */ 146 | } gost_ctx; 147 | 148 | /* hash functions */ 149 | 150 | void john_gost_init(gost_ctx *ctx); 151 | void john_gost_cryptopro_init(gost_ctx *ctx); 152 | void john_gost_update(gost_ctx *ctx, const unsigned char* msg, size_t size); 153 | void john_gost_final(gost_ctx *ctx, unsigned char result[32]); 154 | 155 | void gost_init_table(void); /* initialize algorithm static data */ 156 | 157 | #ifdef __cplusplus 158 | } /* extern "C" */ 159 | #endif /* __cplusplus */ 160 | 161 | #endif /* JTR_GOST_H */ 162 | -------------------------------------------------------------------------------- /jtr_haval_helper.c: -------------------------------------------------------------------------------- 1 | /* $Id: haval_helper.c 218 2010-06-08 17:06:34Z tp $ */ 2 | /* 3 | * Helper code, included (three times !) by HAVAL implementation. 4 | * 5 | * TODO: try to merge this with md_helper.c. 6 | * 7 | * ==========================(LICENSE BEGIN)============================ 8 | * 9 | * Copyright (c) 2007-2010 Projet RNRT SAPHIR 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining 12 | * a copy of this software and associated documentation files (the 13 | * "Software"), to deal in the Software without restriction, including 14 | * without limitation the rights to use, copy, modify, merge, publish, 15 | * distribute, sublicense, and/or sell copies of the Software, and to 16 | * permit persons to whom the Software is furnished to do so, subject to 17 | * the following conditions: 18 | * 19 | * The above copyright notice and this permission notice shall be 20 | * included in all copies or substantial portions of the Software. 21 | * 22 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 25 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 26 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 27 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 28 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | * 30 | * ===========================(LICENSE END)============================= 31 | * 32 | * @author Thomas Pornin 33 | */ 34 | 35 | #undef SPH_XCAT 36 | #define SPH_XCAT(a, b) SPH_XCAT_(a, b) 37 | #undef SPH_XCAT_ 38 | #define SPH_XCAT_(a, b) a ## b 39 | 40 | static void 41 | #ifdef SPH_UPTR 42 | SPH_XCAT(SPH_XCAT(haval, PASSES), _short) 43 | #else 44 | SPH_XCAT(haval, PASSES) 45 | #endif 46 | (sph_haval_context *sc, const void *data, size_t len) 47 | { 48 | unsigned current; 49 | 50 | #if SPH_64 51 | current = (unsigned)sc->count & 127U; 52 | #else 53 | current = (unsigned)sc->count_low & 127U; 54 | #endif 55 | while (len > 0) { 56 | unsigned clen; 57 | #if !SPH_64 58 | sph_u32 clow, clow2; 59 | #endif 60 | 61 | clen = 128U - current; 62 | if (clen > len) 63 | clen = (unsigned int)len; 64 | memcpy(sc->buf + current, data, clen); 65 | data = (const unsigned char *)data + clen; 66 | current += clen; 67 | len -= clen; 68 | if (current == 128U) { 69 | DSTATE; 70 | IN_PREPARE(sc->buf); 71 | 72 | RSTATE; 73 | SPH_XCAT(CORE, PASSES)(INW); 74 | WSTATE; 75 | current = 0; 76 | } 77 | #if SPH_64 78 | sc->count += clen; 79 | #else 80 | clow = sc->count_low; 81 | clow2 = SPH_T32(clow + clen); 82 | sc->count_low = clow2; 83 | if (clow2 < clow) 84 | sc->count_high ++; 85 | #endif 86 | } 87 | } 88 | 89 | #ifdef SPH_UPTR 90 | static void 91 | SPH_XCAT(haval, PASSES)(sph_haval_context *sc, const void *data, size_t len) 92 | { 93 | unsigned current; 94 | size_t orig_len; 95 | #if !SPH_64 96 | sph_u32 clow, clow2; 97 | #endif 98 | DSTATE; 99 | 100 | if (len < 256U) { 101 | SPH_XCAT(SPH_XCAT(haval, PASSES), _short)(sc, data, len); 102 | return; 103 | } 104 | #if SPH_64 105 | current = (unsigned)sc->count & 127U; 106 | #else 107 | current = (unsigned)sc->count_low & 127U; 108 | #endif 109 | if (current > 0) { 110 | unsigned clen; 111 | 112 | clen = 128U - current; 113 | SPH_XCAT(SPH_XCAT(haval, PASSES), _short)(sc, data, clen); 114 | data = (const unsigned char *)data + clen; 115 | len -= clen; 116 | } 117 | #if !SPH_UNALIGNED 118 | if (((SPH_UPTR)data & 3U) != 0) { 119 | SPH_XCAT(SPH_XCAT(haval, PASSES), _short)(sc, data, len); 120 | return; 121 | } 122 | #endif 123 | orig_len = len; 124 | RSTATE; 125 | while (len >= 128U) { 126 | IN_PREPARE(data); 127 | 128 | SPH_XCAT(CORE, PASSES)(INW); 129 | data = (const unsigned char *)data + 128U; 130 | len -= 128U; 131 | } 132 | WSTATE; 133 | if (len > 0) 134 | memcpy(sc->buf, data, len); 135 | #if SPH_64 136 | sc->count += (sph_u64)orig_len; 137 | #else 138 | clow = sc->count_low; 139 | clow2 = SPH_T32(clow + orig_len); 140 | sc->count_low = clow2; 141 | if (clow2 < clow) 142 | sc->count_high ++; 143 | orig_len >>= 12; 144 | orig_len >>= 10; 145 | orig_len >>= 10; 146 | sc->count_high += orig_len; 147 | #endif 148 | } 149 | #endif 150 | 151 | static void 152 | SPH_XCAT(SPH_XCAT(haval, PASSES), _close)(sph_haval_context *sc, 153 | unsigned ub, unsigned n, void *dst) 154 | { 155 | unsigned current; 156 | DSTATE; 157 | 158 | #if SPH_64 159 | current = (unsigned)sc->count & 127U; 160 | #else 161 | current = (unsigned)sc->count_low & 127U; 162 | #endif 163 | sc->buf[current ++] = (0x01 << n) | ((ub & 0xFF) >> (8 - n)); 164 | RSTATE; 165 | if (current > 118U) { 166 | memset(sc->buf + current, 0, 128U - current); 167 | 168 | do { 169 | IN_PREPARE(sc->buf); 170 | 171 | SPH_XCAT(CORE, PASSES)(INW); 172 | } while (0); 173 | current = 0; 174 | } 175 | memset(sc->buf + current, 0, 118U - current); 176 | sc->buf[118] = 0x01 | (PASSES << 3); 177 | sc->buf[119] = sc->olen << 3; 178 | #if SPH_64 179 | sph_enc64le_aligned(sc->buf + 120, SPH_T64(sc->count << 3)); 180 | #else 181 | sph_enc32le_aligned(sc->buf + 120, SPH_T32(sc->count_low << 3)); 182 | sph_enc32le_aligned(sc->buf + 124, 183 | SPH_T32((sc->count_high << 3) | (sc->count_low >> 29))); 184 | #endif 185 | do { 186 | IN_PREPARE(sc->buf); 187 | 188 | SPH_XCAT(CORE, PASSES)(INW); 189 | } while (0); 190 | 191 | WSTATE; 192 | haval_out(sc, dst); 193 | haval_init(sc, sc->olen, sc->passes); 194 | } 195 | -------------------------------------------------------------------------------- /keccak1600.h: -------------------------------------------------------------------------------- 1 | #ifndef KECCAK1600_H 2 | #define KECCAK1600_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | extern size_t SHA3_absorb(uint64_t A[5][5], const unsigned char *inp, size_t len, size_t r); 11 | extern void SHA3_squeeze(uint64_t A[5][5], unsigned char *out, size_t len, size_t r); 12 | 13 | #ifdef __cplusplus 14 | } 15 | #endif 16 | 17 | #define KECCAK1600_WIDTH 1600 18 | 19 | typedef struct { 20 | uint64_t A[5][5]; 21 | size_t block_size; /* cached ctx->digest->block_size */ 22 | size_t md_size; /* output length, variable in XOF */ 23 | size_t num; /* used bytes in below buffer */ 24 | unsigned char buf[KECCAK1600_WIDTH / 8 - 32]; 25 | unsigned char pad; 26 | } KECCAK1600_CTX; 27 | 28 | inline int sha3_init(KECCAK1600_CTX *ctx, size_t block_size, size_t md_size) 29 | { 30 | size_t bsz = block_size; 31 | 32 | if (bsz <= sizeof(ctx->buf)) { 33 | memset(ctx->A, 0, sizeof(ctx->A)); 34 | 35 | ctx->num = 0; 36 | ctx->block_size = bsz; 37 | ctx->md_size = md_size; 38 | ctx->pad = '\x06'; 39 | 40 | return 1; 41 | } 42 | 43 | return 0; 44 | } 45 | 46 | inline int sha3_update(KECCAK1600_CTX *ctx, const void *_inp, size_t len) 47 | { 48 | const unsigned char *inp = _inp; 49 | size_t bsz = ctx->block_size; 50 | size_t num, rem; 51 | 52 | if ((num = ctx->num) != 0) { /* process intermediate buffer? */ 53 | rem = bsz - num; 54 | 55 | if (len < rem) { 56 | memcpy(ctx->buf + num, inp, len); 57 | ctx->num += len; 58 | return 1; 59 | } 60 | /* 61 | * We have enough data to fill or overflow the intermediate 62 | * buffer. So we append |rem| bytes and process the block, 63 | * leaving the rest for later processing... 64 | */ 65 | memcpy(ctx->buf + num, inp, rem); 66 | inp += rem, len -= rem; 67 | (void)SHA3_absorb(ctx->A, ctx->buf, bsz, bsz); 68 | ctx->num = 0; 69 | /* ctx->buf is processed, ctx->num is guaranteed to be zero */ 70 | } 71 | 72 | if (len >= bsz) 73 | rem = SHA3_absorb(ctx->A, inp, len, bsz); 74 | else 75 | rem = len; 76 | 77 | if (rem) { 78 | memcpy(ctx->buf, inp + len - rem, rem); 79 | ctx->num = rem; 80 | } 81 | 82 | return 1; 83 | } 84 | 85 | inline int sha3_final(KECCAK1600_CTX *ctx, unsigned char *md) 86 | { 87 | size_t bsz = ctx->block_size; 88 | size_t num = ctx->num; 89 | 90 | /* 91 | * Pad the data with 10*1. Note that |num| can be |bsz - 1| 92 | * in which case both byte operations below are performed on 93 | * same byte... 94 | */ 95 | memset(ctx->buf + num, 0, bsz - num); 96 | ctx->buf[num] = ctx->pad; 97 | ctx->buf[bsz - 1] |= 0x80; 98 | 99 | (void)SHA3_absorb(ctx->A, ctx->buf, bsz, bsz); 100 | 101 | SHA3_squeeze(ctx->A, md, ctx->md_size, bsz); 102 | 103 | return 1; 104 | } 105 | 106 | #endif -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "PoW.h" 8 | #include "common.h" 9 | #include "my_rand48_r.h" 10 | #include "oneWayFunction.h" 11 | 12 | int main(int argc, const char *argv[]) { 13 | if (argc != 2) { 14 | printf("Usage: %s message\n", argv[0]); 15 | exit(-1); 16 | } 17 | 18 | const char *mess = argv[1]; 19 | uint32_t messLen = (uint32_t)strlen(mess); 20 | 21 | uint8_t input[messLen]; 22 | memset(input, 0, messLen*sizeof(uint8_t)); 23 | memcpy(input, mess, messLen*sizeof(char)); 24 | 25 | // Test for oneWayFunction 26 | initOneWayFunction(); 27 | //testOneWayFunction(mess, 5000000); 28 | 29 | testPowFunction(input, messLen, 1); 30 | 31 | // powNistTest("./powNistTest"); 32 | 33 | uint8_t Maddr[WORK_MEMORY_SIZE], output[OUTPUT_LEN]; 34 | memset(Maddr, 0, WORK_MEMORY_SIZE*sizeof(uint8_t)); 35 | 36 | helloHash(input, messLen, output); 37 | view_data_u8("PoW_char", output, OUTPUT_LEN); 38 | 39 | /*for (int i = 0; i < 100; ++i) 40 | powFunction(input, messLen, Maddr, output); 41 | view_data_u8("PoW", output, OUTPUT_LEN); */ 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /multihashing.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | extern "C" { 8 | #include "PoW.h" 9 | } 10 | 11 | 12 | #define THROW_ERROR_EXCEPTION(x) Nan::ThrowError(x) 13 | 14 | using namespace node; 15 | using namespace v8; 16 | 17 | 18 | NAN_METHOD(cryptohello) { 19 | if (info.Length() < 1) 20 | return THROW_ERROR_EXCEPTION("You must provide one argument."); 21 | 22 | if (info.Length() >= 2) { 23 | if(!info[1]->IsBoolean()) 24 | return THROW_ERROR_EXCEPTION("Argument 2 should be a boolean"); 25 | } 26 | 27 | Local target = info[0]->ToObject(); 28 | 29 | if(!Buffer::HasInstance(target)) 30 | return THROW_ERROR_EXCEPTION("Argument should be a buffer object."); 31 | 32 | uint8_t * input = (uint8_t *)Buffer::Data(target); 33 | uint8_t output[OUTPUT_LEN]; 34 | 35 | uint32_t input_len = Buffer::Length(target); 36 | //input_len=input_len; 37 | 38 | helloHash(input, input_len, output); 39 | 40 | v8::Local returnValue = Nan::CopyBuffer((char *)output, OUTPUT_LEN).ToLocalChecked(); 41 | 42 | info.GetReturnValue().Set(returnValue); 43 | } 44 | 45 | 46 | NAN_MODULE_INIT(init) { 47 | Nan::Set(target, Nan::New("cryptohello").ToLocalChecked(), Nan::GetFunction(Nan::New(cryptohello)).ToLocalChecked()); 48 | } 49 | 50 | NODE_MODULE(multihashing, init) 51 | -------------------------------------------------------------------------------- /my_rand48_r.h: -------------------------------------------------------------------------------- 1 | #ifndef MY_RAND48_R_H 2 | #define MY_RAND48_R_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | struct vrand48_data { 11 | __m128i vxl, vxh; 12 | __m128i val, vah; 13 | __m128i vc; 14 | }; 15 | 16 | inline void vseed48(uint64_t *s, struct vrand48_data *buffer) { 17 | buffer->vc = _mm_set_epi32(0, 0xb, 0, 0xb); 18 | 19 | buffer->vah = _mm_set_epi32(0, 0x5, 0, 0x5); 20 | buffer->val = _mm_set_epi32(0, 0xdeece66d, 0, 0xdeece66d); 21 | 22 | buffer->vxl = _mm_set_epi32(0, (uint32_t)s[1], 0, (uint32_t)s[0]); 23 | buffer->vxh = _mm_set_epi32(0, (uint32_t)(s[1] >> 32), 0, (uint32_t)(s[0] >> 32)); 24 | } 25 | 26 | inline __m128i vrand48(struct vrand48_data *buffer) { 27 | __m128i vmask = _mm_set_epi32(0x0000FFFF, 0xFFFFFFFF, 0x0000FFFF, 0xFFFFFFFF); 28 | __m128i vmask2 = _mm_set_epi32(0, 0xFFFFFFFF, 0, 0xFFFFFFFF); 29 | 30 | __m128i vrl, vrh, vresult; 31 | vrl = _mm_mul_epu32(buffer->val, buffer->vxl); 32 | vrh = _mm_add_epi64(_mm_mul_epu32(buffer->val, buffer->vxh), _mm_mul_epu32(buffer->vah, buffer->vxl)); 33 | vresult = _mm_and_si128(_mm_add_epi64(_mm_add_epi64(vrl, _mm_slli_epi64(vrh, 32)), buffer->vc), vmask); 34 | 35 | buffer->vxl = _mm_and_si128(vresult, vmask2); buffer->vxh = _mm_and_si128(_mm_srli_epi64 (vresult, 32), vmask2); 36 | 37 | return vresult; 38 | } 39 | 40 | inline void vrand64(uint8_t *b, struct vrand48_data *buffer) { 41 | __m128i vresult0, vresult1; 42 | vresult0 = vrand48(&buffer[0]); 43 | vresult1 = vrand48(&buffer[1]); 44 | 45 | __m128i vresult2, vresult3; 46 | vresult2 = vrand48(&buffer[0]); 47 | vresult3 = vrand48(&buffer[1]); 48 | 49 | vresult0 = _mm_xor_si128(vresult0, _mm_slli_epi64(vresult2, 16)); 50 | vresult1 = _mm_xor_si128(vresult1, _mm_slli_epi64(vresult3, 16)); 51 | 52 | _mm_store_si128((__m128i *)b, vresult0); 53 | _mm_store_si128((__m128i *)(b + 16), vresult1); 54 | } 55 | 56 | struct my_rand48_data { 57 | uint64_t __x; /* Current state. */ 58 | uint16_t __c; /* Additive const. in congruential formula. */ 59 | uint64_t __a; /* Factor in congruential formula. */ 60 | }; 61 | 62 | #define MY_SEED48_R(seedVal, bufferPtr) \ 63 | do { \ 64 | uint64_t seedval = seedVal; \ 65 | struct my_rand48_data *buffer = bufferPtr; \ 66 | \ 67 | buffer->__x = seedval & 0xffffffffffffULL; \ 68 | \ 69 | buffer->__a = 0x5deece66dULL; \ 70 | buffer->__c = 0xb; \ 71 | } while(0) 72 | 73 | #define MY_RAND48_R(bufferPtr, resultPtr) \ 74 | do { \ 75 | uint64_t *result = resultPtr; \ 76 | struct my_rand48_data *buffer = bufferPtr; \ 77 | \ 78 | *result = (buffer->__x * buffer->__a + buffer->__c) & 0xffffffffffffULL; \ 79 | buffer->__x = *result; \ 80 | } while(0) 81 | 82 | #define MY_RAND64_R(bufferPtr, resultPtr) \ 83 | do { \ 84 | uint64_t *result = resultPtr; \ 85 | struct my_rand48_data *buffer = bufferPtr; \ 86 | uint64_t X = buffer->__x; \ 87 | \ 88 | X = (X * buffer->__a + buffer->__c) & 0xffffffffffffULL; \ 89 | buffer->__x = X; \ 90 | \ 91 | buffer->__x = (X * buffer->__a + buffer->__c) & 0xffffffffffffULL; \ 92 | X ^= buffer->__x << 16; \ 93 | \ 94 | *result = X; \ 95 | } while(0) 96 | 97 | int my_seed48_r (uint64_t seedval, struct my_rand48_data *buffer); 98 | 99 | int my_rand48_r (struct my_rand48_data *buffer, uint64_t *result); 100 | 101 | int my_rand64_r (struct my_rand48_data *buffer, uint64_t *result); 102 | 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /my_time.c: -------------------------------------------------------------------------------- 1 | // Windows 2 | #ifdef _WIN32 3 | 4 | #include 5 | 6 | double get_wall_time() { 7 | LARGE_INTEGER time, freq; 8 | if (!QueryPerformanceFrequency(&freq)) { 9 | // Handle error 10 | return 0; 11 | } 12 | if (!QueryPerformanceCounter(&time)) { 13 | // Handle error 14 | return 0; 15 | } 16 | return (double)time.QuadPart / freq.QuadPart; 17 | } 18 | 19 | double get_cpu_time() { 20 | FILETIME a, b, c, d; 21 | if (GetProcessTimes(GetCurrentProcess(),&a,&b,&c,&d) != 0) { 22 | // Returns total user time. 23 | // Can be tweaked to include kernel times as well. 24 | return 25 | (double)(d.dwLowDateTime | 26 | ((unsigned long long)d.dwHighDateTime << 32)) * 0.000001; 27 | } else { 28 | // Handle error 29 | return 0; 30 | } 31 | } 32 | 33 | // Posix/Linux 34 | #else 35 | 36 | #include 37 | #include 38 | 39 | double get_wall_time() { 40 | struct timeval time; 41 | if (gettimeofday(&time,NULL)) { 42 | // Handle error 43 | return 0; 44 | } 45 | return (double)time.tv_sec + (double)time.tv_usec * 0.000001; 46 | } 47 | 48 | double get_cpu_time() { 49 | return (double)clock() / CLOCKS_PER_SEC; 50 | } 51 | 52 | #endif -------------------------------------------------------------------------------- /my_time.h: -------------------------------------------------------------------------------- 1 | #ifndef MY_TIME_H 2 | #define MY_TIME_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | double get_wall_time(); 9 | double get_cpu_time(); 10 | 11 | #ifdef __cplusplus 12 | } 13 | #endif 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /node_modules/bindings/README.md: -------------------------------------------------------------------------------- 1 | node-bindings 2 | ============= 3 | ### Helper module for loading your native module's .node file 4 | 5 | This is a helper module for authors of Node.js native addon modules. 6 | It is basically the "swiss army knife" of `require()`ing your native module's 7 | `.node` file. 8 | 9 | Throughout the course of Node's native addon history, addons have ended up being 10 | compiled in a variety of different places, depending on which build tool and which 11 | version of node was used. To make matters worse, now the _gyp_ build tool can 12 | produce either a _Release_ or _Debug_ build, each being built into different 13 | locations. 14 | 15 | This module checks _all_ the possible locations that a native addon would be built 16 | at, and returns the first one that loads successfully. 17 | 18 | 19 | Installation 20 | ------------ 21 | 22 | Install with `npm`: 23 | 24 | ``` bash 25 | $ npm install bindings 26 | ``` 27 | 28 | Or add it to the `"dependencies"` section of your _package.json_ file. 29 | 30 | 31 | Example 32 | ------- 33 | 34 | `require()`ing the proper bindings file for the current node version, platform 35 | and architecture is as simple as: 36 | 37 | ``` js 38 | var bindings = require('bindings')('binding.node') 39 | 40 | // Use your bindings defined in your C files 41 | bindings.your_c_function() 42 | ``` 43 | 44 | 45 | Nice Error Output 46 | ----------------- 47 | 48 | When the `.node` file could not be loaded, `node-bindings` throws an Error with 49 | a nice error message telling you exactly what was tried. You can also check the 50 | `err.tries` Array property. 51 | 52 | ``` 53 | Error: Could not load the bindings file. Tried: 54 | → /Users/nrajlich/ref/build/binding.node 55 | → /Users/nrajlich/ref/build/Debug/binding.node 56 | → /Users/nrajlich/ref/build/Release/binding.node 57 | → /Users/nrajlich/ref/out/Debug/binding.node 58 | → /Users/nrajlich/ref/Debug/binding.node 59 | → /Users/nrajlich/ref/out/Release/binding.node 60 | → /Users/nrajlich/ref/Release/binding.node 61 | → /Users/nrajlich/ref/build/default/binding.node 62 | → /Users/nrajlich/ref/compiled/0.8.2/darwin/x64/binding.node 63 | at bindings (/Users/nrajlich/ref/node_modules/bindings/bindings.js:84:13) 64 | at Object. (/Users/nrajlich/ref/lib/ref.js:5:47) 65 | at Module._compile (module.js:449:26) 66 | at Object.Module._extensions..js (module.js:467:10) 67 | at Module.load (module.js:356:32) 68 | at Function.Module._load (module.js:312:12) 69 | ... 70 | ``` 71 | 72 | The searching for the `.node` file will originate from the first directory in which has a `package.json` file is found. 73 | 74 | License 75 | ------- 76 | 77 | (The MIT License) 78 | 79 | Copyright (c) 2012 Nathan Rajlich <nathan@tootallnate.net> 80 | 81 | Permission is hereby granted, free of charge, to any person obtaining 82 | a copy of this software and associated documentation files (the 83 | 'Software'), to deal in the Software without restriction, including 84 | without limitation the rights to use, copy, modify, merge, publish, 85 | distribute, sublicense, and/or sell copies of the Software, and to 86 | permit persons to whom the Software is furnished to do so, subject to 87 | the following conditions: 88 | 89 | The above copyright notice and this permission notice shall be 90 | included in all copies or substantial portions of the Software. 91 | 92 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 93 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 94 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 95 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 96 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 97 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 98 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 99 | -------------------------------------------------------------------------------- /node_modules/bindings/bindings.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Module dependencies. 4 | */ 5 | 6 | var fs = require('fs') 7 | , path = require('path') 8 | , join = path.join 9 | , dirname = path.dirname 10 | , exists = ((fs.accessSync && function (path) { try { fs.accessSync(path); } catch (e) { return false; } return true; }) 11 | || fs.existsSync || path.existsSync) 12 | , defaults = { 13 | arrow: process.env.NODE_BINDINGS_ARROW || ' → ' 14 | , compiled: process.env.NODE_BINDINGS_COMPILED_DIR || 'compiled' 15 | , platform: process.platform 16 | , arch: process.arch 17 | , version: process.versions.node 18 | , bindings: 'bindings.node' 19 | , try: [ 20 | // node-gyp's linked version in the "build" dir 21 | [ 'module_root', 'build', 'bindings' ] 22 | // node-waf and gyp_addon (a.k.a node-gyp) 23 | , [ 'module_root', 'build', 'Debug', 'bindings' ] 24 | , [ 'module_root', 'build', 'Release', 'bindings' ] 25 | // Debug files, for development (legacy behavior, remove for node v0.9) 26 | , [ 'module_root', 'out', 'Debug', 'bindings' ] 27 | , [ 'module_root', 'Debug', 'bindings' ] 28 | // Release files, but manually compiled (legacy behavior, remove for node v0.9) 29 | , [ 'module_root', 'out', 'Release', 'bindings' ] 30 | , [ 'module_root', 'Release', 'bindings' ] 31 | // Legacy from node-waf, node <= 0.4.x 32 | , [ 'module_root', 'build', 'default', 'bindings' ] 33 | // Production "Release" buildtype binary (meh...) 34 | , [ 'module_root', 'compiled', 'version', 'platform', 'arch', 'bindings' ] 35 | ] 36 | } 37 | 38 | /** 39 | * The main `bindings()` function loads the compiled bindings for a given module. 40 | * It uses V8's Error API to determine the parent filename that this function is 41 | * being invoked from, which is then used to find the root directory. 42 | */ 43 | 44 | function bindings (opts) { 45 | 46 | // Argument surgery 47 | if (typeof opts == 'string') { 48 | opts = { bindings: opts } 49 | } else if (!opts) { 50 | opts = {} 51 | } 52 | 53 | // maps `defaults` onto `opts` object 54 | Object.keys(defaults).map(function(i) { 55 | if (!(i in opts)) opts[i] = defaults[i]; 56 | }); 57 | 58 | // Get the module root 59 | if (!opts.module_root) { 60 | opts.module_root = exports.getRoot(exports.getFileName()) 61 | } 62 | 63 | // Ensure the given bindings name ends with .node 64 | if (path.extname(opts.bindings) != '.node') { 65 | opts.bindings += '.node' 66 | } 67 | 68 | var tries = [] 69 | , i = 0 70 | , l = opts.try.length 71 | , n 72 | , b 73 | , err 74 | 75 | for (; i* 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 14 | -------------------------------------------------------------------------------- /node_modules/nan/doc/asyncworker.md: -------------------------------------------------------------------------------- 1 | ## Asynchronous work helpers 2 | 3 | `Nan::AsyncWorker`, `Nan::AsyncProgressWorker` and `Nan::AsyncProgressQueueWorker` are helper classes that make working with asynchronous code easier. 4 | 5 | - Nan::AsyncWorker 6 | - Nan::AsyncProgressWorkerBase & Nan::AsyncProgressWorker 7 | - Nan::AsyncProgressQueueWorker 8 | - Nan::AsyncQueueWorker 9 | 10 | 11 | ### Nan::AsyncWorker 12 | 13 | `Nan::AsyncWorker` is an _abstract_ class that you can subclass to have much of the annoying asynchronous queuing and handling taken care of for you. It can even store arbitrary V8 objects for you and have them persist while the asynchronous work is in progress. 14 | 15 | This class internally handles the details of creating an [`AsyncResource`][AsyncResource], and running the callback in the 16 | correct async context. To be able to identify the async resources created by this class in async-hooks, provide a 17 | `resource_name` to the constructor. It is recommended that the module name be used as a prefix to the `resource_name` to avoid 18 | collisions in the names. For more details see [`AsyncResource`][AsyncResource] documentation. The `resource_name` needs to stay valid for the lifetime of the worker instance. 19 | 20 | Definition: 21 | 22 | ```c++ 23 | class AsyncWorker { 24 | public: 25 | explicit AsyncWorker(Callback *callback_, const char* resource_name = "nan:AsyncWorker"); 26 | 27 | virtual ~AsyncWorker(); 28 | 29 | virtual void WorkComplete(); 30 | 31 | void SaveToPersistent(const char *key, const v8::Local &value); 32 | 33 | void SaveToPersistent(const v8::Local &key, 34 | const v8::Local &value); 35 | 36 | void SaveToPersistent(uint32_t index, 37 | const v8::Local &value); 38 | 39 | v8::Local GetFromPersistent(const char *key) const; 40 | 41 | v8::Local GetFromPersistent(const v8::Local &key) const; 42 | 43 | v8::Local GetFromPersistent(uint32_t index) const; 44 | 45 | virtual void Execute() = 0; 46 | 47 | uv_work_t request; 48 | 49 | virtual void Destroy(); 50 | 51 | protected: 52 | Persistent persistentHandle; 53 | 54 | Callback *callback; 55 | 56 | virtual void HandleOKCallback(); 57 | 58 | virtual void HandleErrorCallback(); 59 | 60 | void SetErrorMessage(const char *msg); 61 | 62 | const char* ErrorMessage(); 63 | }; 64 | ``` 65 | 66 | 67 | ### Nan::AsyncProgressWorkerBase & Nan::AsyncProgressWorker 68 | 69 | `Nan::AsyncProgressWorkerBase` is an _abstract_ class template that extends `Nan::AsyncWorker` and adds additional progress reporting callbacks that can be used during the asynchronous work execution to provide progress data back to JavaScript. 70 | 71 | Previously the definiton of `Nan::AsyncProgressWorker` only allowed sending `const char` data. Now extending `Nan::AsyncProgressWorker` will yield an instance of the implicit `Nan::AsyncProgressWorkerBase` template with type `` for compatibility. 72 | 73 | `Nan::AsyncProgressWorkerBase` & `Nan::AsyncProgressWorker` is intended for best-effort delivery of nonessential progress messages, e.g. a progress bar. The last event sent before the main thread is woken will be delivered. 74 | 75 | Definition: 76 | 77 | ```c++ 78 | template 79 | class AsyncProgressWorkerBase : public AsyncWorker { 80 | public: 81 | explicit AsyncProgressWorkerBase(Callback *callback_, const char* resource_name = ...); 82 | 83 | virtual ~AsyncProgressWorkerBase(); 84 | 85 | void WorkProgress(); 86 | 87 | class ExecutionProgress { 88 | public: 89 | void Signal() const; 90 | void Send(const T* data, size_t count) const; 91 | }; 92 | 93 | virtual void Execute(const ExecutionProgress& progress) = 0; 94 | 95 | virtual void HandleProgressCallback(const T *data, size_t count) = 0; 96 | 97 | virtual void Destroy(); 98 | }; 99 | 100 | typedef AsyncProgressWorkerBase AsyncProgressWorker; 101 | ``` 102 | 103 | 104 | ### Nan::AsyncProgressQueueWorker 105 | 106 | `Nan::AsyncProgressQueueWorker` is an _abstract_ class template that extends `Nan::AsyncWorker` and adds additional progress reporting callbacks that can be used during the asynchronous work execution to provide progress data back to JavaScript. 107 | 108 | `Nan::AsyncProgressQueueWorker` behaves exactly the same as `Nan::AsyncProgressWorker`, except all events are queued and delivered to the main thread. 109 | 110 | Definition: 111 | 112 | ```c++ 113 | template 114 | class AsyncProgressQueueWorker : public AsyncWorker { 115 | public: 116 | explicit AsyncProgressQueueWorker(Callback *callback_, const char* resource_name = "nan:AsyncProgressQueueWorker"); 117 | 118 | virtual ~AsyncProgressQueueWorker(); 119 | 120 | void WorkProgress(); 121 | 122 | class ExecutionProgress { 123 | public: 124 | void Send(const T* data, size_t count) const; 125 | }; 126 | 127 | virtual void Execute(const ExecutionProgress& progress) = 0; 128 | 129 | virtual void HandleProgressCallback(const T *data, size_t count) = 0; 130 | 131 | virtual void Destroy(); 132 | }; 133 | ``` 134 | 135 | 136 | ### Nan::AsyncQueueWorker 137 | 138 | `Nan::AsyncQueueWorker` will run a `Nan::AsyncWorker` asynchronously via libuv. Both the `execute` and `after_work` steps are taken care of for you. Most of the logic for this is embedded in `Nan::AsyncWorker`. 139 | 140 | Definition: 141 | 142 | ```c++ 143 | void AsyncQueueWorker(AsyncWorker *); 144 | ``` 145 | 146 | [AsyncResource]: "node_misc.html#api_nan_asyncresource" 147 | -------------------------------------------------------------------------------- /node_modules/nan/doc/buffers.md: -------------------------------------------------------------------------------- 1 | ## Buffers 2 | 3 | NAN's `node::Buffer` helpers exist as the API has changed across supported Node versions. Use these methods to ensure compatibility. 4 | 5 | - Nan::NewBuffer() 6 | - Nan::CopyBuffer() 7 | - Nan::FreeCallback() 8 | 9 | 10 | ### Nan::NewBuffer() 11 | 12 | Allocate a new `node::Buffer` object with the specified size and optional data. Calls `node::Buffer::New()`. 13 | 14 | Note that when creating a `Buffer` using `Nan::NewBuffer()` and an existing `char*`, it is assumed that the ownership of the pointer is being transferred to the new `Buffer` for management. 15 | When a `node::Buffer` instance is garbage collected and a `FreeCallback` has not been specified, `data` will be disposed of via a call to `free()`. 16 | You _must not_ free the memory space manually once you have created a `Buffer` in this way. 17 | 18 | Signature: 19 | 20 | ```c++ 21 | Nan::MaybeLocal Nan::NewBuffer(uint32_t size) 22 | Nan::MaybeLocal Nan::NewBuffer(char* data, uint32_t size) 23 | Nan::MaybeLocal Nan::NewBuffer(char *data, 24 | size_t length, 25 | Nan::FreeCallback callback, 26 | void *hint) 27 | ``` 28 | 29 | 30 | 31 | ### Nan::CopyBuffer() 32 | 33 | Similar to [`Nan::NewBuffer()`](#api_nan_new_buffer) except that an implicit memcpy will occur within Node. Calls `node::Buffer::Copy()`. 34 | 35 | Management of the `char*` is left to the user, you should manually free the memory space if necessary as the new `Buffer` will have its own copy. 36 | 37 | Signature: 38 | 39 | ```c++ 40 | Nan::MaybeLocal Nan::CopyBuffer(const char *data, uint32_t size) 41 | ``` 42 | 43 | 44 | 45 | ### Nan::FreeCallback() 46 | 47 | A free callback that can be provided to [`Nan::NewBuffer()`](#api_nan_new_buffer). 48 | The supplied callback will be invoked when the `Buffer` undergoes garbage collection. 49 | 50 | Signature: 51 | 52 | ```c++ 53 | typedef void (*FreeCallback)(char *data, void *hint); 54 | ``` 55 | -------------------------------------------------------------------------------- /node_modules/nan/doc/callback.md: -------------------------------------------------------------------------------- 1 | ## Nan::Callback 2 | 3 | `Nan::Callback` makes it easier to use `v8::Function` handles as callbacks. A class that wraps a `v8::Function` handle, protecting it from garbage collection and making it particularly useful for storage and use across asynchronous execution. 4 | 5 | - Nan::Callback 6 | 7 | 8 | ### Nan::Callback 9 | 10 | ```c++ 11 | class Callback { 12 | public: 13 | Callback(); 14 | 15 | explicit Callback(const v8::Local &fn); 16 | 17 | ~Callback(); 18 | 19 | bool operator==(const Callback &other) const; 20 | 21 | bool operator!=(const Callback &other) const; 22 | 23 | v8::Local operator*() const; 24 | 25 | MaybeLocal operator()(AsyncResource* async_resource, 26 | v8::Local target, 27 | int argc = 0, 28 | v8::Local argv[] = 0) const; 29 | 30 | MaybeLocal operator()(AsyncResource* async_resource, 31 | int argc = 0, 32 | v8::Local argv[] = 0) const; 33 | 34 | void SetFunction(const v8::Local &fn); 35 | 36 | v8::Local GetFunction() const; 37 | 38 | bool IsEmpty() const; 39 | 40 | void Reset(const v8::Local &fn); 41 | 42 | void Reset(); 43 | 44 | MaybeLocal Call(v8::Local target, 45 | int argc, 46 | v8::Local argv[], 47 | AsyncResource* async_resource) const; 48 | MaybeLocal Call(int argc, 49 | v8::Local argv[], 50 | AsyncResource* async_resource) const; 51 | 52 | // Deprecated versions. Use the versions that accept an async_resource instead 53 | // as they run the callback in the correct async context as specified by the 54 | // resource. If you want to call a synchronous JS function (i.e. on a 55 | // non-empty JS stack), you can use Nan::Call instead. 56 | v8::Local operator()(v8::Local target, 57 | int argc = 0, 58 | v8::Local argv[] = 0) const; 59 | 60 | v8::Local operator()(int argc = 0, 61 | v8::Local argv[] = 0) const; 62 | v8::Local Call(v8::Local target, 63 | int argc, 64 | v8::Local argv[]) const; 65 | 66 | v8::Local Call(int argc, v8::Local argv[]) const; 67 | }; 68 | ``` 69 | 70 | Example usage: 71 | 72 | ```c++ 73 | v8::Local function; 74 | Nan::Callback callback(function); 75 | callback.Call(0, 0); 76 | ``` 77 | -------------------------------------------------------------------------------- /node_modules/nan/doc/converters.md: -------------------------------------------------------------------------------- 1 | ## Converters 2 | 3 | NAN contains functions that convert `v8::Value`s to other `v8::Value` types and native types. Since type conversion is not guaranteed to succeed, they return `Nan::Maybe` types. These converters can be used in place of `value->ToX()` and `value->XValue()` (where `X` is one of the types, e.g. `Boolean`) in a way that provides a consistent interface across V8 versions. Newer versions of V8 use the new `v8::Maybe` and `v8::MaybeLocal` types for these conversions, older versions don't have this functionality so it is provided by NAN. 4 | 5 | - Nan::To() 6 | 7 | 8 | ### Nan::To() 9 | 10 | Converts a `v8::Local` to a different subtype of `v8::Value` or to a native data type. Returns a `Nan::MaybeLocal<>` or a `Nan::Maybe<>` accordingly. 11 | 12 | See [maybe_types.md](./maybe_types.md) for more information on `Nan::Maybe` types. 13 | 14 | Signatures: 15 | 16 | ```c++ 17 | // V8 types 18 | Nan::MaybeLocal Nan::To(v8::Local val); 19 | Nan::MaybeLocal Nan::To(v8::Local val); 20 | Nan::MaybeLocal Nan::To(v8::Local val); 21 | Nan::MaybeLocal Nan::To(v8::Local val); 22 | Nan::MaybeLocal Nan::To(v8::Local val); 23 | Nan::MaybeLocal Nan::To(v8::Local val); 24 | Nan::MaybeLocal Nan::To(v8::Local val); 25 | 26 | // Native types 27 | Nan::Maybe Nan::To(v8::Local val); 28 | Nan::Maybe Nan::To(v8::Local val); 29 | Nan::Maybe Nan::To(v8::Local val); 30 | Nan::Maybe Nan::To(v8::Local val); 31 | Nan::Maybe Nan::To(v8::Local val); 32 | ``` 33 | 34 | ### Example 35 | 36 | ```c++ 37 | v8::Local val; 38 | Nan::MaybeLocal str = Nan::To(val); 39 | Nan::Maybe d = Nan::To(val); 40 | ``` 41 | 42 | -------------------------------------------------------------------------------- /node_modules/nan/doc/errors.md: -------------------------------------------------------------------------------- 1 | ## Errors 2 | 3 | NAN includes helpers for creating, throwing and catching Errors as much of this functionality varies across the supported versions of V8 and must be abstracted. 4 | 5 | Note that an Error object is simply a specialized form of `v8::Value`. 6 | 7 | Also consult the V8 Embedders Guide section on [Exceptions](https://developers.google.com/v8/embed#exceptions) for more information. 8 | 9 | - Nan::Error() 10 | - Nan::RangeError() 11 | - Nan::ReferenceError() 12 | - Nan::SyntaxError() 13 | - Nan::TypeError() 14 | - Nan::ThrowError() 15 | - Nan::ThrowRangeError() 16 | - Nan::ThrowReferenceError() 17 | - Nan::ThrowSyntaxError() 18 | - Nan::ThrowTypeError() 19 | - Nan::FatalException() 20 | - Nan::ErrnoException() 21 | - Nan::TryCatch 22 | 23 | 24 | 25 | ### Nan::Error() 26 | 27 | Create a new Error object using the [v8::Exception](https://v8docs.nodesource.com/io.js-3.3/da/d6a/classv8_1_1_exception.html) class in a way that is compatible across the supported versions of V8. 28 | 29 | Note that an Error object is simply a specialized form of `v8::Value`. 30 | 31 | Signature: 32 | 33 | ```c++ 34 | v8::Local Nan::Error(const char *msg); 35 | v8::Local Nan::Error(v8::Local msg); 36 | ``` 37 | 38 | 39 | 40 | ### Nan::RangeError() 41 | 42 | Create a new RangeError object using the [v8::Exception](https://v8docs.nodesource.com/io.js-3.3/da/d6a/classv8_1_1_exception.html) class in a way that is compatible across the supported versions of V8. 43 | 44 | Note that an RangeError object is simply a specialized form of `v8::Value`. 45 | 46 | Signature: 47 | 48 | ```c++ 49 | v8::Local Nan::RangeError(const char *msg); 50 | v8::Local Nan::RangeError(v8::Local msg); 51 | ``` 52 | 53 | 54 | 55 | ### Nan::ReferenceError() 56 | 57 | Create a new ReferenceError object using the [v8::Exception](https://v8docs.nodesource.com/io.js-3.3/da/d6a/classv8_1_1_exception.html) class in a way that is compatible across the supported versions of V8. 58 | 59 | Note that an ReferenceError object is simply a specialized form of `v8::Value`. 60 | 61 | Signature: 62 | 63 | ```c++ 64 | v8::Local Nan::ReferenceError(const char *msg); 65 | v8::Local Nan::ReferenceError(v8::Local msg); 66 | ``` 67 | 68 | 69 | 70 | ### Nan::SyntaxError() 71 | 72 | Create a new SyntaxError object using the [v8::Exception](https://v8docs.nodesource.com/io.js-3.3/da/d6a/classv8_1_1_exception.html) class in a way that is compatible across the supported versions of V8. 73 | 74 | Note that an SyntaxError object is simply a specialized form of `v8::Value`. 75 | 76 | Signature: 77 | 78 | ```c++ 79 | v8::Local Nan::SyntaxError(const char *msg); 80 | v8::Local Nan::SyntaxError(v8::Local msg); 81 | ``` 82 | 83 | 84 | 85 | ### Nan::TypeError() 86 | 87 | Create a new TypeError object using the [v8::Exception](https://v8docs.nodesource.com/io.js-3.3/da/d6a/classv8_1_1_exception.html) class in a way that is compatible across the supported versions of V8. 88 | 89 | Note that an TypeError object is simply a specialized form of `v8::Value`. 90 | 91 | Signature: 92 | 93 | ```c++ 94 | v8::Local Nan::TypeError(const char *msg); 95 | v8::Local Nan::TypeError(v8::Local msg); 96 | ``` 97 | 98 | 99 | 100 | ### Nan::ThrowError() 101 | 102 | Throw an Error object (a specialized `v8::Value` as above) in the current context. If a `msg` is provided, a new Error object will be created. 103 | 104 | Signature: 105 | 106 | ```c++ 107 | void Nan::ThrowError(const char *msg); 108 | void Nan::ThrowError(v8::Local msg); 109 | void Nan::ThrowError(v8::Local error); 110 | ``` 111 | 112 | 113 | 114 | ### Nan::ThrowRangeError() 115 | 116 | Throw an RangeError object (a specialized `v8::Value` as above) in the current context. If a `msg` is provided, a new RangeError object will be created. 117 | 118 | Signature: 119 | 120 | ```c++ 121 | void Nan::ThrowRangeError(const char *msg); 122 | void Nan::ThrowRangeError(v8::Local msg); 123 | void Nan::ThrowRangeError(v8::Local error); 124 | ``` 125 | 126 | 127 | 128 | ### Nan::ThrowReferenceError() 129 | 130 | Throw an ReferenceError object (a specialized `v8::Value` as above) in the current context. If a `msg` is provided, a new ReferenceError object will be created. 131 | 132 | Signature: 133 | 134 | ```c++ 135 | void Nan::ThrowReferenceError(const char *msg); 136 | void Nan::ThrowReferenceError(v8::Local msg); 137 | void Nan::ThrowReferenceError(v8::Local error); 138 | ``` 139 | 140 | 141 | 142 | ### Nan::ThrowSyntaxError() 143 | 144 | Throw an SyntaxError object (a specialized `v8::Value` as above) in the current context. If a `msg` is provided, a new SyntaxError object will be created. 145 | 146 | Signature: 147 | 148 | ```c++ 149 | void Nan::ThrowSyntaxError(const char *msg); 150 | void Nan::ThrowSyntaxError(v8::Local msg); 151 | void Nan::ThrowSyntaxError(v8::Local error); 152 | ``` 153 | 154 | 155 | 156 | ### Nan::ThrowTypeError() 157 | 158 | Throw an TypeError object (a specialized `v8::Value` as above) in the current context. If a `msg` is provided, a new TypeError object will be created. 159 | 160 | Signature: 161 | 162 | ```c++ 163 | void Nan::ThrowTypeError(const char *msg); 164 | void Nan::ThrowTypeError(v8::Local msg); 165 | void Nan::ThrowTypeError(v8::Local error); 166 | ``` 167 | 168 | 169 | ### Nan::FatalException() 170 | 171 | Replaces `node::FatalException()` which has a different API across supported versions of Node. For use with [`Nan::TryCatch`](#api_nan_try_catch). 172 | 173 | Signature: 174 | 175 | ```c++ 176 | void Nan::FatalException(const Nan::TryCatch& try_catch); 177 | ``` 178 | 179 | 180 | ### Nan::ErrnoException() 181 | 182 | Replaces `node::ErrnoException()` which has a different API across supported versions of Node. 183 | 184 | Signature: 185 | 186 | ```c++ 187 | v8::Local Nan::ErrnoException(int errorno, 188 | const char* syscall = NULL, 189 | const char* message = NULL, 190 | const char* path = NULL); 191 | ``` 192 | 193 | 194 | 195 | ### Nan::TryCatch 196 | 197 | A simple wrapper around [`v8::TryCatch`](https://v8docs.nodesource.com/io.js-3.3/d4/dc6/classv8_1_1_try_catch.html) compatible with all supported versions of V8. Can be used as a direct replacement in most cases. See also [`Nan::FatalException()`](#api_nan_fatal_exception) for an internal use compatible with `node::FatalException`. 198 | 199 | Signature: 200 | 201 | ```c++ 202 | class Nan::TryCatch { 203 | public: 204 | Nan::TryCatch(); 205 | 206 | bool HasCaught() const; 207 | 208 | bool CanContinue() const; 209 | 210 | v8::Local ReThrow(); 211 | 212 | v8::Local Exception() const; 213 | 214 | // Nan::MaybeLocal for older versions of V8 215 | v8::MaybeLocal StackTrace() const; 216 | 217 | v8::Local Message() const; 218 | 219 | void Reset(); 220 | 221 | void SetVerbose(bool value); 222 | 223 | void SetCaptureMessage(bool value); 224 | }; 225 | ``` 226 | 227 | -------------------------------------------------------------------------------- /node_modules/nan/doc/json.md: -------------------------------------------------------------------------------- 1 | ## JSON 2 | 3 | The _JSON_ object provides the c++ versions of the methods offered by the `JSON` object in javascript. V8 exposes these methods via the `v8::JSON` object. 4 | 5 | - Nan::JSON.Parse 6 | - Nan::JSON.Stringify 7 | 8 | Refer to the V8 JSON object in the [V8 documentation](https://v8docs.nodesource.com/node-7.4/da/d6f/classv8_1_1_j_s_o_n.html) for more information about these methods and their arguments. 9 | 10 | 11 | 12 | ### Nan::JSON.Parse 13 | 14 | A simple wrapper around [`v8::JSON::Parse`](https://v8docs.nodesource.com/node-7.4/da/d6f/classv8_1_1_j_s_o_n.html#a936310d2540fb630ed37d3ee3ffe4504). 15 | 16 | Definition: 17 | 18 | ```c++ 19 | Nan::MaybeLocal Nan::JSON::Parse(v8::Local json_string); 20 | ``` 21 | 22 | Use `JSON.Parse(json_string)` to parse a string into a `v8::Value`. 23 | 24 | Example: 25 | 26 | ```c++ 27 | v8::Local json_string = Nan::New("{ \"JSON\": \"object\" }").ToLocalChecked(); 28 | 29 | Nan::JSON NanJSON; 30 | Nan::MaybeLocal result = NanJSON.Parse(json_string); 31 | if (!result.IsEmpty()) { 32 | v8::Local val = result.ToLocalChecked(); 33 | } 34 | ``` 35 | 36 | 37 | 38 | ### Nan::JSON.Stringify 39 | 40 | A simple wrapper around [`v8::JSON::Stringify`](https://v8docs.nodesource.com/node-7.4/da/d6f/classv8_1_1_j_s_o_n.html#a44b255c3531489ce43f6110209138860). 41 | 42 | Definition: 43 | 44 | ```c++ 45 | Nan::MaybeLocal Nan::JSON::Stringify(v8::Local json_object, v8::Local gap = v8::Local()); 46 | ``` 47 | 48 | Use `JSON.Stringify(value)` to stringify a `v8::Object`. 49 | 50 | Example: 51 | 52 | ```c++ 53 | // using `v8::Local val` from the `JSON::Parse` example 54 | v8::Local obj = Nan::To(val).ToLocalChecked(); 55 | 56 | Nan::JSON NanJSON; 57 | Nan::MaybeLocal result = NanJSON.Stringify(obj); 58 | if (!result.IsEmpty()) { 59 | v8::Local stringified = result.ToLocalChecked(); 60 | } 61 | ``` 62 | 63 | -------------------------------------------------------------------------------- /node_modules/nan/doc/new.md: -------------------------------------------------------------------------------- 1 | ## New 2 | 3 | NAN provides a `Nan::New()` helper for the creation of new JavaScript objects in a way that's compatible across the supported versions of V8. 4 | 5 | - Nan::New() 6 | - Nan::Undefined() 7 | - Nan::Null() 8 | - Nan::True() 9 | - Nan::False() 10 | - Nan::EmptyString() 11 | 12 | 13 | 14 | ### Nan::New() 15 | 16 | `Nan::New()` should be used to instantiate new JavaScript objects. 17 | 18 | Refer to the specific V8 type in the [V8 documentation](https://v8docs.nodesource.com/io.js-3.3/d1/d83/classv8_1_1_data.html) for information on the types of arguments required for instantiation. 19 | 20 | Signatures: 21 | 22 | Return types are mostly omitted from the signatures for simplicity. In most cases the type will be contained within a `v8::Local`. The following types will be contained within a `Nan::MaybeLocal`: `v8::String`, `v8::Date`, `v8::RegExp`, `v8::Script`, `v8::UnboundScript`. 23 | 24 | Empty objects: 25 | 26 | ```c++ 27 | Nan::New(); 28 | ``` 29 | 30 | Generic single and multiple-argument: 31 | 32 | ```c++ 33 | Nan::New(A0 arg0); 34 | Nan::New(A0 arg0, A1 arg1); 35 | Nan::New(A0 arg0, A1 arg1, A2 arg2); 36 | Nan::New(A0 arg0, A1 arg1, A2 arg2, A3 arg3); 37 | ``` 38 | 39 | For creating `v8::FunctionTemplate` and `v8::Function` objects: 40 | 41 | _The definition of `Nan::FunctionCallback` can be found in the [Method declaration](./methods.md#api_nan_method) documentation._ 42 | 43 | ```c++ 44 | Nan::New(Nan::FunctionCallback callback, 45 | v8::Local data = v8::Local()); 46 | Nan::New(Nan::FunctionCallback callback, 47 | v8::Local data = v8::Local(), 48 | A2 a2 = A2()); 49 | ``` 50 | 51 | Native number types: 52 | 53 | ```c++ 54 | v8::Local Nan::New(bool value); 55 | v8::Local Nan::New(int32_t value); 56 | v8::Local Nan::New(uint32_t value); 57 | v8::Local Nan::New(double value); 58 | ``` 59 | 60 | String types: 61 | 62 | ```c++ 63 | Nan::MaybeLocal Nan::New(std::string const& value); 64 | Nan::MaybeLocal Nan::New(const char * value, int length); 65 | Nan::MaybeLocal Nan::New(const char * value); 66 | Nan::MaybeLocal Nan::New(const uint16_t * value); 67 | Nan::MaybeLocal Nan::New(const uint16_t * value, int length); 68 | ``` 69 | 70 | Specialized types: 71 | 72 | ```c++ 73 | v8::Local Nan::New(v8::String::ExternalStringResource * value); 74 | v8::Local Nan::New(Nan::ExternalOneByteStringResource * value); 75 | v8::Local Nan::New(v8::Local pattern, v8::RegExp::Flags flags); 76 | ``` 77 | 78 | Note that `Nan::ExternalOneByteStringResource` maps to [`v8::String::ExternalOneByteStringResource`](https://v8docs.nodesource.com/io.js-3.3/d9/db3/classv8_1_1_string_1_1_external_one_byte_string_resource.html), and `v8::String::ExternalAsciiStringResource` in older versions of V8. 79 | 80 | 81 | 82 | ### Nan::Undefined() 83 | 84 | A helper method to reference the `v8::Undefined` object in a way that is compatible across all supported versions of V8. 85 | 86 | Signature: 87 | 88 | ```c++ 89 | v8::Local Nan::Undefined() 90 | ``` 91 | 92 | 93 | ### Nan::Null() 94 | 95 | A helper method to reference the `v8::Null` object in a way that is compatible across all supported versions of V8. 96 | 97 | Signature: 98 | 99 | ```c++ 100 | v8::Local Nan::Null() 101 | ``` 102 | 103 | 104 | ### Nan::True() 105 | 106 | A helper method to reference the `v8::Boolean` object representing the `true` value in a way that is compatible across all supported versions of V8. 107 | 108 | Signature: 109 | 110 | ```c++ 111 | v8::Local Nan::True() 112 | ``` 113 | 114 | 115 | ### Nan::False() 116 | 117 | A helper method to reference the `v8::Boolean` object representing the `false` value in a way that is compatible across all supported versions of V8. 118 | 119 | Signature: 120 | 121 | ```c++ 122 | v8::Local Nan::False() 123 | ``` 124 | 125 | 126 | ### Nan::EmptyString() 127 | 128 | Call [`v8::String::Empty`](https://v8docs.nodesource.com/io.js-3.3/d2/db3/classv8_1_1_string.html#a7c1bc8886115d7ee46f1d571dd6ebc6d) to reference the empty string in a way that is compatible across all supported versions of V8. 129 | 130 | Signature: 131 | 132 | ```c++ 133 | v8::Local Nan::EmptyString() 134 | ``` 135 | 136 | 137 | 138 | ### Nan::NewOneByteString() 139 | 140 | An implementation of [`v8::String::NewFromOneByte()`](https://v8docs.nodesource.com/io.js-3.3/d2/db3/classv8_1_1_string.html#a5264d50b96d2c896ce525a734dc10f09) provided for consistent availability and API across supported versions of V8. Allocates a new string from Latin-1 data. 141 | 142 | Signature: 143 | 144 | ```c++ 145 | Nan::MaybeLocal Nan::NewOneByteString(const uint8_t * value, 146 | int length = -1) 147 | ``` 148 | -------------------------------------------------------------------------------- /node_modules/nan/doc/node_misc.md: -------------------------------------------------------------------------------- 1 | ## Miscellaneous Node Helpers 2 | 3 | - Nan::AsyncResource 4 | - Nan::MakeCallback() 5 | - NAN_MODULE_INIT() 6 | - Nan::Export() 7 | 8 | 9 | ### Nan::AsyncResource 10 | 11 | This class is analogous to the `AsyncResource` JavaScript class exposed by Node's [async_hooks][] API. 12 | 13 | When calling back into JavaScript asynchornously, special care must be taken to ensure that the runtime can properly track 14 | async hops. `Nan::AsyncResource` is a class that provides an RAII wrapper around `node::EmitAsyncInit`, `node::EmitAsyncDestroy`, 15 | and `node::MakeCallback`. Using this mechanism to call back into JavaScript, as opposed to `Nan::MakeCallback` or 16 | `v8::Function::Call` ensures that the callback is executed in the correct async context. This ensures that async mechanisms 17 | such as domains and [async_hooks][] function correctly. 18 | 19 | Definition: 20 | 21 | ```c++ 22 | class AsyncResource { 23 | public: 24 | AsyncResource(v8::Local name, 25 | v8::Local resource = New()); 26 | AsyncResource(const char* name, 27 | v8::Local resource = New()); 28 | ~AsyncResource(); 29 | 30 | v8::MaybeLocal runInAsyncScope(v8::Local target, 31 | v8::Local func, 32 | int argc, 33 | v8::Local* argv); 34 | v8::MaybeLocal runInAsyncScope(v8::Local target, 35 | v8::Local symbol, 36 | int argc, 37 | v8::Local* argv); 38 | v8::MaybeLocal runInAsyncScope(v8::Local target, 39 | const char* method, 40 | int argc, 41 | v8::Local* argv); 42 | }; 43 | ``` 44 | 45 | * `name`: Identifier for the kind of resource that is being provided for diagnostics information exposed by the [async_hooks][] 46 | API. This will be passed to the possible `init` hook as the `type`. To avoid name collisions with other modules we recommend 47 | that the name include the name of the owning module as a prefix. For example `mysql` module could use something like 48 | `mysql:batch-db-query-resource`. 49 | * `resource`: An optional object associated with the async work that will be passed to the possible [async_hooks][] 50 | `init` hook. If this parameter is omitted, or an empty handle is provided, this object will be created automatically. 51 | * When calling JS on behalf of this resource, one can use `runInAsyncScope`. This will ensure that the callback runs in the 52 | correct async execution context. 53 | * `AsyncDestroy` is automatically called when an AsyncResource object is destroyed. 54 | 55 | For more details, see the Node [async_hooks][] documentation. You might also want to take a look at the documentation for the 56 | [N-API counterpart][napi]. For example usage, see the `asyncresource.cpp` example in the `test/cpp` directory. 57 | 58 | 59 | ### Nan::MakeCallback() 60 | 61 | Deprecated wrappers around the legacy `node::MakeCallback()` APIs. Node.js 10+ 62 | has deprecated these legacy APIs as they do not provide a mechanism to preserve 63 | async context. 64 | 65 | We recommend that you use the `AsyncResource` class and `AsyncResource::runInAsyncScope` instead of using `Nan::MakeCallback` or 66 | `v8::Function#Call()` directly. `AsyncResource` properly takes care of running the callback in the correct async execution 67 | context – something that is essential for functionality like domains, async_hooks and async debugging. 68 | 69 | Signatures: 70 | 71 | ```c++ 72 | NAN_DEPRECATED 73 | v8::Local Nan::MakeCallback(v8::Local target, 74 | v8::Local func, 75 | int argc, 76 | v8::Local* argv); 77 | NAN_DEPRECATED 78 | v8::Local Nan::MakeCallback(v8::Local target, 79 | v8::Local symbol, 80 | int argc, 81 | v8::Local* argv); 82 | NAN_DEPRECATED 83 | v8::Local Nan::MakeCallback(v8::Local target, 84 | const char* method, 85 | int argc, 86 | v8::Local* argv); 87 | ``` 88 | 89 | 90 | 91 | ### NAN_MODULE_INIT() 92 | 93 | Used to define the entry point function to a Node add-on. Creates a function with a given `name` that receives a `target` object representing the equivalent of the JavaScript `exports` object. 94 | 95 | See example below. 96 | 97 | 98 | ### Nan::Export() 99 | 100 | A simple helper to register a `v8::FunctionTemplate` from a JavaScript-accessible method (see [Methods](./methods.md)) as a property on an object. Can be used in a way similar to assigning properties to `module.exports` in JavaScript. 101 | 102 | Signature: 103 | 104 | ```c++ 105 | void Export(v8::Local target, const char *name, Nan::FunctionCallback f) 106 | ``` 107 | 108 | Also available as the shortcut `NAN_EXPORT` macro. 109 | 110 | Example: 111 | 112 | ```c++ 113 | NAN_METHOD(Foo) { 114 | ... 115 | } 116 | 117 | NAN_MODULE_INIT(Init) { 118 | NAN_EXPORT(target, Foo); 119 | } 120 | ``` 121 | 122 | [async_hooks]: https://nodejs.org/dist/latest-v9.x/docs/api/async_hooks.html 123 | [napi]: https://nodejs.org/dist/latest-v9.x/docs/api/n-api.html#n_api_custom_asynchronous_operations 124 | -------------------------------------------------------------------------------- /node_modules/nan/doc/object_wrappers.md: -------------------------------------------------------------------------------- 1 | ## Object Wrappers 2 | 3 | The `ObjectWrap` class can be used to make wrapped C++ objects and a factory of wrapped objects. 4 | 5 | - Nan::ObjectWrap 6 | 7 | 8 | 9 | ### Nan::ObjectWrap() 10 | 11 | A reimplementation of `node::ObjectWrap` that adds some API not present in older versions of Node. Should be preferred over `node::ObjectWrap` in all cases for consistency. 12 | 13 | Definition: 14 | 15 | ```c++ 16 | class ObjectWrap { 17 | public: 18 | ObjectWrap(); 19 | 20 | virtual ~ObjectWrap(); 21 | 22 | template 23 | static inline T* Unwrap(v8::Local handle); 24 | 25 | inline v8::Local handle(); 26 | 27 | inline Nan::Persistent& persistent(); 28 | 29 | protected: 30 | inline void Wrap(v8::Local handle); 31 | 32 | inline void MakeWeak(); 33 | 34 | /* Ref() marks the object as being attached to an event loop. 35 | * Refed objects will not be garbage collected, even if 36 | * all references are lost. 37 | */ 38 | virtual void Ref(); 39 | 40 | /* Unref() marks an object as detached from the event loop. This is its 41 | * default state. When an object with a "weak" reference changes from 42 | * attached to detached state it will be freed. Be careful not to access 43 | * the object after making this call as it might be gone! 44 | * (A "weak reference" means an object that only has a 45 | * persistant handle.) 46 | * 47 | * DO NOT CALL THIS FROM DESTRUCTOR 48 | */ 49 | virtual void Unref(); 50 | 51 | int refs_; // ro 52 | }; 53 | ``` 54 | 55 | See the Node documentation on [Wrapping C++ Objects](https://nodejs.org/api/addons.html#addons_wrapping_c_objects) for more details. 56 | 57 | ### This vs. Holder 58 | 59 | When calling `Unwrap`, it is important that the argument is indeed some JavaScript object which got wrapped by a `Wrap` call for this class or any derived class. 60 | The `Signature` installed by [`Nan::SetPrototypeMethod()`](methods.md#api_nan_set_prototype_method) does ensure that `info.Holder()` is just such an instance. 61 | In Node 0.12 and later, `info.This()` will also be of such a type, since otherwise the invocation will get rejected. 62 | However, in Node 0.10 and before it was possible to invoke a method on a JavaScript object which just had the extension type in its prototype chain. 63 | In such a situation, calling `Unwrap` on `info.This()` will likely lead to a failed assertion causing a crash, but could lead to even more serious corruption. 64 | 65 | On the other hand, calling `Unwrap` in an [accessor](methods.md#api_nan_set_accessor) should not use `Holder()` if the accessor is defined on the prototype. 66 | So either define your accessors on the instance template, 67 | or use `This()` after verifying that it is indeed a valid object. 68 | 69 | ### Examples 70 | 71 | #### Basic 72 | 73 | ```c++ 74 | class MyObject : public Nan::ObjectWrap { 75 | public: 76 | static NAN_MODULE_INIT(Init) { 77 | v8::Local tpl = Nan::New(New); 78 | tpl->SetClassName(Nan::New("MyObject").ToLocalChecked()); 79 | tpl->InstanceTemplate()->SetInternalFieldCount(1); 80 | 81 | Nan::SetPrototypeMethod(tpl, "getHandle", GetHandle); 82 | Nan::SetPrototypeMethod(tpl, "getValue", GetValue); 83 | 84 | constructor().Reset(Nan::GetFunction(tpl).ToLocalChecked()); 85 | Nan::Set(target, Nan::New("MyObject").ToLocalChecked(), 86 | Nan::GetFunction(tpl).ToLocalChecked()); 87 | } 88 | 89 | private: 90 | explicit MyObject(double value = 0) : value_(value) {} 91 | ~MyObject() {} 92 | 93 | static NAN_METHOD(New) { 94 | if (info.IsConstructCall()) { 95 | double value = info[0]->IsUndefined() ? 0 : Nan::To(info[0]).FromJust(); 96 | MyObject *obj = new MyObject(value); 97 | obj->Wrap(info.This()); 98 | info.GetReturnValue().Set(info.This()); 99 | } else { 100 | const int argc = 1; 101 | v8::Local argv[argc] = {info[0]}; 102 | v8::Local cons = Nan::New(constructor()); 103 | info.GetReturnValue().Set(cons->NewInstance(argc, argv)); 104 | } 105 | } 106 | 107 | static NAN_METHOD(GetHandle) { 108 | MyObject* obj = Nan::ObjectWrap::Unwrap(info.Holder()); 109 | info.GetReturnValue().Set(obj->handle()); 110 | } 111 | 112 | static NAN_METHOD(GetValue) { 113 | MyObject* obj = Nan::ObjectWrap::Unwrap(info.Holder()); 114 | info.GetReturnValue().Set(obj->value_); 115 | } 116 | 117 | static inline Nan::Persistent & constructor() { 118 | static Nan::Persistent my_constructor; 119 | return my_constructor; 120 | } 121 | 122 | double value_; 123 | }; 124 | 125 | NODE_MODULE(objectwrapper, MyObject::Init) 126 | ``` 127 | 128 | To use in Javascript: 129 | 130 | ```Javascript 131 | var objectwrapper = require('bindings')('objectwrapper'); 132 | 133 | var obj = new objectwrapper.MyObject(5); 134 | console.log('Should be 5: ' + obj.getValue()); 135 | ``` 136 | 137 | #### Factory of wrapped objects 138 | 139 | ```c++ 140 | class MyFactoryObject : public Nan::ObjectWrap { 141 | public: 142 | static NAN_MODULE_INIT(Init) { 143 | v8::Local tpl = Nan::New(New); 144 | tpl->InstanceTemplate()->SetInternalFieldCount(1); 145 | 146 | Nan::SetPrototypeMethod(tpl, "getValue", GetValue); 147 | 148 | constructor().Reset(Nan::GetFunction(tpl).ToLocalChecked()); 149 | } 150 | 151 | static NAN_METHOD(NewInstance) { 152 | v8::Local cons = Nan::New(constructor()); 153 | double value = info[0]->IsNumber() ? Nan::To(info[0]).FromJust() : 0; 154 | const int argc = 1; 155 | v8::Local argv[1] = {Nan::New(value)}; 156 | info.GetReturnValue().Set(Nan::NewInstance(cons, argc, argv).ToLocalChecked()); 157 | } 158 | 159 | // Needed for the next example: 160 | inline double value() const { 161 | return value_; 162 | } 163 | 164 | private: 165 | explicit MyFactoryObject(double value = 0) : value_(value) {} 166 | ~MyFactoryObject() {} 167 | 168 | static NAN_METHOD(New) { 169 | if (info.IsConstructCall()) { 170 | double value = info[0]->IsNumber() ? Nan::To(info[0]).FromJust() : 0; 171 | MyFactoryObject * obj = new MyFactoryObject(value); 172 | obj->Wrap(info.This()); 173 | info.GetReturnValue().Set(info.This()); 174 | } else { 175 | const int argc = 1; 176 | v8::Local argv[argc] = {info[0]}; 177 | v8::Local cons = Nan::New(constructor()); 178 | info.GetReturnValue().Set(Nan::NewInstance(cons, argc, argv).ToLocalChecked()); 179 | } 180 | } 181 | 182 | static NAN_METHOD(GetValue) { 183 | MyFactoryObject* obj = ObjectWrap::Unwrap(info.Holder()); 184 | info.GetReturnValue().Set(obj->value_); 185 | } 186 | 187 | static inline Nan::Persistent & constructor() { 188 | static Nan::Persistent my_constructor; 189 | return my_constructor; 190 | } 191 | 192 | double value_; 193 | }; 194 | 195 | NAN_MODULE_INIT(Init) { 196 | MyFactoryObject::Init(target); 197 | Nan::Set(target, 198 | Nan::New("newFactoryObjectInstance").ToLocalChecked(), 199 | Nan::GetFunction( 200 | Nan::New(MyFactoryObject::NewInstance)).ToLocalChecked() 201 | ); 202 | } 203 | 204 | NODE_MODULE(wrappedobjectfactory, Init) 205 | ``` 206 | 207 | To use in Javascript: 208 | 209 | ```Javascript 210 | var wrappedobjectfactory = require('bindings')('wrappedobjectfactory'); 211 | 212 | var obj = wrappedobjectfactory.newFactoryObjectInstance(10); 213 | console.log('Should be 10: ' + obj.getValue()); 214 | ``` 215 | 216 | #### Passing wrapped objects around 217 | 218 | Use the `MyFactoryObject` class above along with the following: 219 | 220 | ```c++ 221 | static NAN_METHOD(Sum) { 222 | Nan::MaybeLocal maybe1 = Nan::To(info[0]); 223 | Nan::MaybeLocal maybe2 = Nan::To(info[1]); 224 | 225 | // Quick check: 226 | if (maybe1.IsEmpty() || maybe2.IsEmpty()) { 227 | // return value is undefined by default 228 | return; 229 | } 230 | 231 | MyFactoryObject* obj1 = 232 | Nan::ObjectWrap::Unwrap(maybe1.ToLocalChecked()); 233 | MyFactoryObject* obj2 = 234 | Nan::ObjectWrap::Unwrap(maybe2.ToLocalChecked()); 235 | 236 | info.GetReturnValue().Set(Nan::New(obj1->value() + obj2->value())); 237 | } 238 | 239 | NAN_MODULE_INIT(Init) { 240 | MyFactoryObject::Init(target); 241 | Nan::Set(target, 242 | Nan::New("newFactoryObjectInstance").ToLocalChecked(), 243 | Nan::GetFunction( 244 | Nan::New(MyFactoryObject::NewInstance)).ToLocalChecked() 245 | ); 246 | Nan::Set(target, 247 | Nan::New("sum").ToLocalChecked(), 248 | Nan::GetFunction(Nan::New(Sum)).ToLocalChecked() 249 | ); 250 | } 251 | 252 | NODE_MODULE(myaddon, Init) 253 | ``` 254 | 255 | To use in Javascript: 256 | 257 | ```Javascript 258 | var myaddon = require('bindings')('myaddon'); 259 | 260 | var obj1 = myaddon.newFactoryObjectInstance(5); 261 | var obj2 = myaddon.newFactoryObjectInstance(10); 262 | console.log('sum of object values: ' + myaddon.sum(obj1, obj2)); 263 | ``` 264 | -------------------------------------------------------------------------------- /node_modules/nan/doc/scopes.md: -------------------------------------------------------------------------------- 1 | ## Scopes 2 | 3 | A _local handle_ is a pointer to an object. All V8 objects are accessed using handles, they are necessary because of the way the V8 garbage collector works. 4 | 5 | A handle scope can be thought of as a container for any number of handles. When you've finished with your handles, instead of deleting each one individually you can simply delete their scope. 6 | 7 | The creation of `HandleScope` objects is different across the supported versions of V8. Therefore, NAN provides its own implementations that can be used safely across these. 8 | 9 | - Nan::HandleScope 10 | - Nan::EscapableHandleScope 11 | 12 | Also see the V8 Embedders Guide section on [Handles and Garbage Collection](https://github.com/v8/v8/wiki/Embedder%27s%20Guide#handles-and-garbage-collection). 13 | 14 | 15 | ### Nan::HandleScope 16 | 17 | A simple wrapper around [`v8::HandleScope`](https://v8docs.nodesource.com/io.js-3.3/d3/d95/classv8_1_1_handle_scope.html). 18 | 19 | Definition: 20 | 21 | ```c++ 22 | class Nan::HandleScope { 23 | public: 24 | Nan::HandleScope(); 25 | static int NumberOfHandles(); 26 | }; 27 | ``` 28 | 29 | Allocate a new `Nan::HandleScope` whenever you are creating new V8 JavaScript objects. Note that an implicit `HandleScope` is created for you on JavaScript-accessible methods so you do not need to insert one yourself. 30 | 31 | Example: 32 | 33 | ```c++ 34 | // new object is created, it needs a new scope: 35 | void Pointless() { 36 | Nan::HandleScope scope; 37 | v8::Local obj = Nan::New(); 38 | } 39 | 40 | // JavaScript-accessible method already has a HandleScope 41 | NAN_METHOD(Pointless2) { 42 | v8::Local obj = Nan::New(); 43 | } 44 | ``` 45 | 46 | 47 | ### Nan::EscapableHandleScope 48 | 49 | Similar to [`Nan::HandleScope`](#api_nan_handle_scope) but should be used in cases where a function needs to return a V8 JavaScript type that has been created within it. 50 | 51 | Definition: 52 | 53 | ```c++ 54 | class Nan::EscapableHandleScope { 55 | public: 56 | Nan::EscapableHandleScope(); 57 | static int NumberOfHandles(); 58 | template v8::Local Escape(v8::Local value); 59 | } 60 | ``` 61 | 62 | Use `Escape(value)` to return the object. 63 | 64 | Example: 65 | 66 | ```c++ 67 | v8::Local EmptyObj() { 68 | Nan::EscapableHandleScope scope; 69 | v8::Local obj = Nan::New(); 70 | return scope.Escape(obj); 71 | } 72 | ``` 73 | 74 | -------------------------------------------------------------------------------- /node_modules/nan/doc/script.md: -------------------------------------------------------------------------------- 1 | ## Script 2 | 3 | NAN provides a `v8::Script` helpers as the API has changed over the supported versions of V8. 4 | 5 | - Nan::CompileScript() 6 | - Nan::RunScript() 7 | 8 | 9 | 10 | ### Nan::CompileScript() 11 | 12 | A wrapper around [`v8::Script::Compile()`](https://v8docs.nodesource.com/io.js-3.3/da/da5/classv8_1_1_script_compiler.html#a93f5072a0db55d881b969e9fc98e564b). 13 | 14 | Note that `Nan::BoundScript` is an alias for `v8::Script`. 15 | 16 | Signature: 17 | 18 | ```c++ 19 | Nan::MaybeLocal Nan::CompileScript( 20 | v8::Local s, 21 | const v8::ScriptOrigin& origin); 22 | Nan::MaybeLocal Nan::CompileScript(v8::Local s); 23 | ``` 24 | 25 | 26 | 27 | ### Nan::RunScript() 28 | 29 | Calls `script->Run()` or `script->BindToCurrentContext()->Run(Nan::GetCurrentContext())`. 30 | 31 | Note that `Nan::BoundScript` is an alias for `v8::Script` and `Nan::UnboundScript` is an alias for `v8::UnboundScript` where available and `v8::Script` on older versions of V8. 32 | 33 | Signature: 34 | 35 | ```c++ 36 | Nan::MaybeLocal Nan::RunScript(v8::Local script) 37 | Nan::MaybeLocal Nan::RunScript(v8::Local script) 38 | ``` 39 | -------------------------------------------------------------------------------- /node_modules/nan/doc/string_bytes.md: -------------------------------------------------------------------------------- 1 | ## Strings & Bytes 2 | 3 | Miscellaneous string & byte encoding and decoding functionality provided for compatibility across supported versions of V8 and Node. Implemented by NAN to ensure that all encoding types are supported, even for older versions of Node where they are missing. 4 | 5 | - Nan::Encoding 6 | - Nan::Encode() 7 | - Nan::DecodeBytes() 8 | - Nan::DecodeWrite() 9 | 10 | 11 | 12 | ### Nan::Encoding 13 | 14 | An enum representing the supported encoding types. A copy of `node::encoding` that is consistent across versions of Node. 15 | 16 | Definition: 17 | 18 | ```c++ 19 | enum Nan::Encoding { ASCII, UTF8, BASE64, UCS2, BINARY, HEX, BUFFER } 20 | ``` 21 | 22 | 23 | 24 | ### Nan::Encode() 25 | 26 | A wrapper around `node::Encode()` that provides a consistent implementation across supported versions of Node. 27 | 28 | Signature: 29 | 30 | ```c++ 31 | v8::Local Nan::Encode(const void *buf, 32 | size_t len, 33 | enum Nan::Encoding encoding = BINARY); 34 | ``` 35 | 36 | 37 | 38 | ### Nan::DecodeBytes() 39 | 40 | A wrapper around `node::DecodeBytes()` that provides a consistent implementation across supported versions of Node. 41 | 42 | Signature: 43 | 44 | ```c++ 45 | ssize_t Nan::DecodeBytes(v8::Local val, 46 | enum Nan::Encoding encoding = BINARY); 47 | ``` 48 | 49 | 50 | 51 | ### Nan::DecodeWrite() 52 | 53 | A wrapper around `node::DecodeWrite()` that provides a consistent implementation across supported versions of Node. 54 | 55 | Signature: 56 | 57 | ```c++ 58 | ssize_t Nan::DecodeWrite(char *buf, 59 | size_t len, 60 | v8::Local val, 61 | enum Nan::Encoding encoding = BINARY); 62 | ``` 63 | -------------------------------------------------------------------------------- /node_modules/nan/doc/v8_internals.md: -------------------------------------------------------------------------------- 1 | ## V8 internals 2 | 3 | The hooks to access V8 internals—including GC and statistics—are different across the supported versions of V8, therefore NAN provides its own hooks that call the appropriate V8 methods. 4 | 5 | - NAN_GC_CALLBACK() 6 | - Nan::AddGCEpilogueCallback() 7 | - Nan::RemoveGCEpilogueCallback() 8 | - Nan::AddGCPrologueCallback() 9 | - Nan::RemoveGCPrologueCallback() 10 | - Nan::GetHeapStatistics() 11 | - Nan::SetCounterFunction() 12 | - Nan::SetCreateHistogramFunction() 13 | - Nan::SetAddHistogramSampleFunction() 14 | - Nan::IdleNotification() 15 | - Nan::LowMemoryNotification() 16 | - Nan::ContextDisposedNotification() 17 | - Nan::GetInternalFieldPointer() 18 | - Nan::SetInternalFieldPointer() 19 | - Nan::AdjustExternalMemory() 20 | 21 | 22 | 23 | ### NAN_GC_CALLBACK(callbackname) 24 | 25 | Use `NAN_GC_CALLBACK` to declare your callbacks for `Nan::AddGCPrologueCallback()` and `Nan::AddGCEpilogueCallback()`. Your new method receives the arguments `v8::GCType type` and `v8::GCCallbackFlags flags`. 26 | 27 | ```c++ 28 | static Nan::Persistent callback; 29 | 30 | NAN_GC_CALLBACK(gcPrologueCallback) { 31 | v8::Local argv[] = { Nan::New("prologue").ToLocalChecked() }; 32 | Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(callback), 1, argv); 33 | } 34 | 35 | NAN_METHOD(Hook) { 36 | callback.Reset(To(args[0]).ToLocalChecked()); 37 | Nan::AddGCPrologueCallback(gcPrologueCallback); 38 | info.GetReturnValue().Set(info.Holder()); 39 | } 40 | ``` 41 | 42 | 43 | ### Nan::AddGCEpilogueCallback() 44 | 45 | Signature: 46 | 47 | ```c++ 48 | void Nan::AddGCEpilogueCallback(v8::Isolate::GCEpilogueCallback callback, v8::GCType gc_type_filter = v8::kGCTypeAll) 49 | ``` 50 | 51 | Calls V8's [`AddGCEpilogueCallback()`](https://v8docs.nodesource.com/io.js-3.3/d5/dda/classv8_1_1_isolate.html#a90d1860babc76059c62514b422f56960). 52 | 53 | 54 | ### Nan::RemoveGCEpilogueCallback() 55 | 56 | Signature: 57 | 58 | ```c++ 59 | void Nan::RemoveGCEpilogueCallback(v8::Isolate::GCEpilogueCallback callback) 60 | ``` 61 | 62 | Calls V8's [`RemoveGCEpilogueCallback()`](https://v8docs.nodesource.com/io.js-3.3/d5/dda/classv8_1_1_isolate.html#a05c60859fd4b8e96bfcd451281ed6c7c). 63 | 64 | 65 | ### Nan::AddGCPrologueCallback() 66 | 67 | Signature: 68 | 69 | ```c++ 70 | void Nan::AddGCPrologueCallback(v8::Isolate::GCPrologueCallback, v8::GCType gc_type_filter callback) 71 | ``` 72 | 73 | Calls V8's [`AddGCPrologueCallback()`](https://v8docs.nodesource.com/io.js-3.3/d5/dda/classv8_1_1_isolate.html#ab4b87b8f9f8e5bf95eba4009357e001f). 74 | 75 | 76 | ### Nan::RemoveGCPrologueCallback() 77 | 78 | Signature: 79 | 80 | ```c++ 81 | void Nan::RemoveGCPrologueCallback(v8::Isolate::GCPrologueCallback callback) 82 | ``` 83 | 84 | Calls V8's [`RemoveGCEpilogueCallback()`](https://v8docs.nodesource.com/io.js-3.3/d5/dda/classv8_1_1_isolate.html#a9f6c51932811593f81ff30b949124186). 85 | 86 | 87 | ### Nan::GetHeapStatistics() 88 | 89 | Signature: 90 | 91 | ```c++ 92 | void Nan::GetHeapStatistics(v8::HeapStatistics *heap_statistics) 93 | ``` 94 | 95 | Calls V8's [`GetHeapStatistics()`](https://v8docs.nodesource.com/io.js-3.3/d5/dda/classv8_1_1_isolate.html#a5593ac74687b713095c38987e5950b34). 96 | 97 | 98 | ### Nan::SetCounterFunction() 99 | 100 | Signature: 101 | 102 | ```c++ 103 | void Nan::SetCounterFunction(v8::CounterLookupCallback cb) 104 | ``` 105 | 106 | Calls V8's [`SetCounterFunction()`](https://v8docs.nodesource.com/io.js-3.3/d5/dda/classv8_1_1_isolate.html#a045d7754e62fa0ec72ae6c259b29af94). 107 | 108 | 109 | ### Nan::SetCreateHistogramFunction() 110 | 111 | Signature: 112 | 113 | ```c++ 114 | void Nan::SetCreateHistogramFunction(v8::CreateHistogramCallback cb) 115 | ``` 116 | 117 | Calls V8's [`SetCreateHistogramFunction()`](https://v8docs.nodesource.com/io.js-3.3/d5/dda/classv8_1_1_isolate.html#a542d67e85089cb3f92aadf032f99e732). 118 | 119 | 120 | ### Nan::SetAddHistogramSampleFunction() 121 | 122 | Signature: 123 | 124 | ```c++ 125 | void Nan::SetAddHistogramSampleFunction(v8::AddHistogramSampleCallback cb) 126 | ``` 127 | 128 | Calls V8's [`SetAddHistogramSampleFunction()`](https://v8docs.nodesource.com/io.js-3.3/d5/dda/classv8_1_1_isolate.html#aeb420b690bc2c216882d6fdd00ddd3ea). 129 | 130 | 131 | ### Nan::IdleNotification() 132 | 133 | Signature: 134 | 135 | ```c++ 136 | void Nan::IdleNotification(v8::HeapStatistics *heap_statistics) 137 | ``` 138 | 139 | Calls V8's [`IdleNotification()` or `IdleNotificationDeadline()`](https://v8docs.nodesource.com/io.js-3.3/d5/dda/classv8_1_1_isolate.html#ad6a2a02657f5425ad460060652a5a118) depending on V8 version. 140 | 141 | 142 | ### Nan::LowMemoryNotification() 143 | 144 | Signature: 145 | 146 | ```c++ 147 | void Nan::LowMemoryNotification() 148 | ``` 149 | 150 | Calls V8's [`LowMemoryNotification()`](https://v8docs.nodesource.com/io.js-3.3/d5/dda/classv8_1_1_isolate.html#a24647f61d6b41f69668094bdcd6ea91f). 151 | 152 | 153 | ### Nan::ContextDisposedNotification() 154 | 155 | Signature: 156 | 157 | ```c++ 158 | void Nan::ContextDisposedNotification() 159 | ``` 160 | 161 | Calls V8's [`ContextDisposedNotification()`](https://v8docs.nodesource.com/io.js-3.3/d5/dda/classv8_1_1_isolate.html#ad7f5dc559866343fe6cd8db1f134d48b). 162 | 163 | 164 | ### Nan::GetInternalFieldPointer() 165 | 166 | Gets a pointer to the internal field with at `index` from a V8 `Object` handle. 167 | 168 | Signature: 169 | 170 | ```c++ 171 | void* Nan::GetInternalFieldPointer(v8::Local object, int index) 172 | ``` 173 | 174 | Calls the Object's [`GetAlignedPointerFromInternalField()` or `GetPointerFromInternalField()`](https://v8docs.nodesource.com/io.js-3.3/db/d85/classv8_1_1_object.html#ab3c57184263cf29963ef0017bec82281) depending on the version of V8. 175 | 176 | 177 | ### Nan::SetInternalFieldPointer() 178 | 179 | Sets the value of the internal field at `index` on a V8 `Object` handle. 180 | 181 | Signature: 182 | 183 | ```c++ 184 | void Nan::SetInternalFieldPointer(v8::Local object, int index, void* value) 185 | ``` 186 | 187 | Calls the Object's [`SetAlignedPointerInInternalField()` or `SetPointerInInternalField()`](https://v8docs.nodesource.com/io.js-3.3/d5/dda/classv8_1_1_isolate.html#ad7f5dc559866343fe6cd8db1f134d48b) depending on the version of V8. 188 | 189 | 190 | ### Nan::AdjustExternalMemory() 191 | 192 | Signature: 193 | 194 | ```c++ 195 | int Nan::AdjustExternalMemory(int bytesChange) 196 | ``` 197 | 198 | Calls V8's [`AdjustAmountOfExternalAllocatedMemory()`](https://v8docs.nodesource.com/io.js-3.3/d5/dda/classv8_1_1_isolate.html#ae1a59cac60409d3922582c4af675473e). 199 | 200 | -------------------------------------------------------------------------------- /node_modules/nan/doc/v8_misc.md: -------------------------------------------------------------------------------- 1 | ## Miscellaneous V8 Helpers 2 | 3 | - Nan::Utf8String 4 | - Nan::GetCurrentContext() 5 | - Nan::SetIsolateData() 6 | - Nan::GetIsolateData() 7 | - Nan::TypedArrayContents 8 | 9 | 10 | 11 | ### Nan::Utf8String 12 | 13 | Converts an object to a UTF-8-encoded character array. If conversion to a string fails (e.g. due to an exception in the toString() method of the object) then the length() method returns 0 and the * operator returns NULL. The underlying memory used for this object is managed by the object. 14 | 15 | An implementation of [`v8::String::Utf8Value`](https://v8docs.nodesource.com/io.js-3.3/d4/d1b/classv8_1_1_string_1_1_utf8_value.html) that is consistent across all supported versions of V8. 16 | 17 | Definition: 18 | 19 | ```c++ 20 | class Nan::Utf8String { 21 | public: 22 | Nan::Utf8String(v8::Local from); 23 | 24 | int length() const; 25 | 26 | char* operator*(); 27 | const char* operator*() const; 28 | }; 29 | ``` 30 | 31 | 32 | ### Nan::GetCurrentContext() 33 | 34 | A call to [`v8::Isolate::GetCurrent()->GetCurrentContext()`](https://v8docs.nodesource.com/io.js-3.3/d5/dda/classv8_1_1_isolate.html#a81c7a1ed7001ae2a65e89107f75fd053) that works across all supported versions of V8. 35 | 36 | Signature: 37 | 38 | ```c++ 39 | v8::Local Nan::GetCurrentContext() 40 | ``` 41 | 42 | 43 | ### Nan::SetIsolateData() 44 | 45 | A helper to provide a consistent API to [`v8::Isolate#SetData()`](https://v8docs.nodesource.com/io.js-3.3/d5/dda/classv8_1_1_isolate.html#a7acadfe7965997e9c386a05f098fbe36). 46 | 47 | Signature: 48 | 49 | ```c++ 50 | void Nan::SetIsolateData(v8::Isolate *isolate, T *data) 51 | ``` 52 | 53 | 54 | 55 | ### Nan::GetIsolateData() 56 | 57 | A helper to provide a consistent API to [`v8::Isolate#GetData()`](https://v8docs.nodesource.com/io.js-3.3/d5/dda/classv8_1_1_isolate.html#aabd223436bc1100a787dadaa024c6257). 58 | 59 | Signature: 60 | 61 | ```c++ 62 | T *Nan::GetIsolateData(v8::Isolate *isolate) 63 | ``` 64 | 65 | 66 | ### Nan::TypedArrayContents 67 | 68 | A helper class for accessing the contents of an ArrayBufferView (aka a typedarray) from C++. If the input array is not a valid typedarray, then the data pointer of TypedArrayContents will default to `NULL` and the length will be 0. If the data pointer is not compatible with the alignment requirements of type, an assertion error will fail. 69 | 70 | Note that you must store a reference to the `array` object while you are accessing its contents. 71 | 72 | Definition: 73 | 74 | ```c++ 75 | template 76 | class Nan::TypedArrayContents { 77 | public: 78 | TypedArrayContents(v8::Local array); 79 | 80 | size_t length() const; 81 | 82 | T* const operator*(); 83 | const T* const operator*() const; 84 | }; 85 | ``` 86 | -------------------------------------------------------------------------------- /node_modules/nan/include_dirs.js: -------------------------------------------------------------------------------- 1 | console.log(require('path').relative('.', __dirname)); 2 | -------------------------------------------------------------------------------- /node_modules/nan/nan_callbacks.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * NAN - Native Abstractions for Node.js 3 | * 4 | * Copyright (c) 2018 NAN contributors 5 | * 6 | * MIT License 7 | ********************************************************************/ 8 | 9 | #ifndef NAN_CALLBACKS_H_ 10 | #define NAN_CALLBACKS_H_ 11 | 12 | template class FunctionCallbackInfo; 13 | template class PropertyCallbackInfo; 14 | template class Global; 15 | 16 | typedef void(*FunctionCallback)(const FunctionCallbackInfo&); 17 | typedef void(*GetterCallback) 18 | (v8::Local, const PropertyCallbackInfo&); 19 | typedef void(*SetterCallback)( 20 | v8::Local, 21 | v8::Local, 22 | const PropertyCallbackInfo&); 23 | typedef void(*PropertyGetterCallback)( 24 | v8::Local, 25 | const PropertyCallbackInfo&); 26 | typedef void(*PropertySetterCallback)( 27 | v8::Local, 28 | v8::Local, 29 | const PropertyCallbackInfo&); 30 | typedef void(*PropertyEnumeratorCallback) 31 | (const PropertyCallbackInfo&); 32 | typedef void(*PropertyDeleterCallback)( 33 | v8::Local, 34 | const PropertyCallbackInfo&); 35 | typedef void(*PropertyQueryCallback)( 36 | v8::Local, 37 | const PropertyCallbackInfo&); 38 | typedef void(*IndexGetterCallback)( 39 | uint32_t, 40 | const PropertyCallbackInfo&); 41 | typedef void(*IndexSetterCallback)( 42 | uint32_t, 43 | v8::Local, 44 | const PropertyCallbackInfo&); 45 | typedef void(*IndexEnumeratorCallback) 46 | (const PropertyCallbackInfo&); 47 | typedef void(*IndexDeleterCallback)( 48 | uint32_t, 49 | const PropertyCallbackInfo&); 50 | typedef void(*IndexQueryCallback)( 51 | uint32_t, 52 | const PropertyCallbackInfo&); 53 | 54 | namespace imp { 55 | typedef v8::Local Sig; 56 | 57 | static const int kDataIndex = 0; 58 | 59 | static const int kFunctionIndex = 1; 60 | static const int kFunctionFieldCount = 2; 61 | 62 | static const int kGetterIndex = 1; 63 | static const int kSetterIndex = 2; 64 | static const int kAccessorFieldCount = 3; 65 | 66 | static const int kPropertyGetterIndex = 1; 67 | static const int kPropertySetterIndex = 2; 68 | static const int kPropertyEnumeratorIndex = 3; 69 | static const int kPropertyDeleterIndex = 4; 70 | static const int kPropertyQueryIndex = 5; 71 | static const int kPropertyFieldCount = 6; 72 | 73 | static const int kIndexPropertyGetterIndex = 1; 74 | static const int kIndexPropertySetterIndex = 2; 75 | static const int kIndexPropertyEnumeratorIndex = 3; 76 | static const int kIndexPropertyDeleterIndex = 4; 77 | static const int kIndexPropertyQueryIndex = 5; 78 | static const int kIndexPropertyFieldCount = 6; 79 | 80 | } // end of namespace imp 81 | 82 | #if NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION 83 | # include "nan_callbacks_12_inl.h" // NOLINT(build/include) 84 | #else 85 | # include "nan_callbacks_pre_12_inl.h" // NOLINT(build/include) 86 | #endif 87 | 88 | #endif // NAN_CALLBACKS_H_ 89 | -------------------------------------------------------------------------------- /node_modules/nan/nan_converters.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * NAN - Native Abstractions for Node.js 3 | * 4 | * Copyright (c) 2018 NAN contributors 5 | * 6 | * MIT License 7 | ********************************************************************/ 8 | 9 | #ifndef NAN_CONVERTERS_H_ 10 | #define NAN_CONVERTERS_H_ 11 | 12 | namespace imp { 13 | template struct ToFactoryBase { 14 | typedef MaybeLocal return_t; 15 | }; 16 | template struct ValueFactoryBase { typedef Maybe return_t; }; 17 | 18 | template struct ToFactory; 19 | 20 | template<> 21 | struct ToFactory : ToFactoryBase { 22 | static inline return_t convert(v8::Local val) { 23 | if (val.IsEmpty() || !val->IsFunction()) return MaybeLocal(); 24 | return MaybeLocal(val.As()); 25 | } 26 | }; 27 | 28 | #define X(TYPE) \ 29 | template<> \ 30 | struct ToFactory : ToFactoryBase { \ 31 | static inline return_t convert(v8::Local val); \ 32 | }; 33 | 34 | X(Boolean) 35 | X(Number) 36 | X(String) 37 | X(Object) 38 | X(Integer) 39 | X(Uint32) 40 | X(Int32) 41 | 42 | #undef X 43 | 44 | #define X(TYPE) \ 45 | template<> \ 46 | struct ToFactory : ValueFactoryBase { \ 47 | static inline return_t convert(v8::Local val); \ 48 | }; 49 | 50 | X(bool) 51 | X(double) 52 | X(int64_t) 53 | X(uint32_t) 54 | X(int32_t) 55 | 56 | #undef X 57 | } // end of namespace imp 58 | 59 | template 60 | inline 61 | typename imp::ToFactory::return_t To(v8::Local val) { 62 | return imp::ToFactory::convert(val); 63 | } 64 | 65 | #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ 66 | (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) 67 | # include "nan_converters_43_inl.h" 68 | #else 69 | # include "nan_converters_pre_43_inl.h" 70 | #endif 71 | 72 | #endif // NAN_CONVERTERS_H_ 73 | -------------------------------------------------------------------------------- /node_modules/nan/nan_converters_43_inl.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * NAN - Native Abstractions for Node.js 3 | * 4 | * Copyright (c) 2018 NAN contributors 5 | * 6 | * MIT License 7 | ********************************************************************/ 8 | 9 | #ifndef NAN_CONVERTERS_43_INL_H_ 10 | #define NAN_CONVERTERS_43_INL_H_ 11 | 12 | #define X(TYPE) \ 13 | imp::ToFactory::return_t \ 14 | imp::ToFactory::convert(v8::Local val) { \ 15 | v8::Isolate *isolate = v8::Isolate::GetCurrent(); \ 16 | v8::EscapableHandleScope scope(isolate); \ 17 | return scope.Escape( \ 18 | val->To ## TYPE(isolate->GetCurrentContext()) \ 19 | .FromMaybe(v8::Local())); \ 20 | } 21 | 22 | X(Boolean) 23 | X(Number) 24 | X(String) 25 | X(Object) 26 | X(Integer) 27 | X(Uint32) 28 | X(Int32) 29 | 30 | #undef X 31 | 32 | #define X(TYPE, NAME) \ 33 | imp::ToFactory::return_t \ 34 | imp::ToFactory::convert(v8::Local val) { \ 35 | v8::Isolate *isolate = v8::Isolate::GetCurrent(); \ 36 | v8::HandleScope scope(isolate); \ 37 | return val->NAME ## Value(isolate->GetCurrentContext()); \ 38 | } 39 | 40 | X(bool, Boolean) 41 | X(double, Number) 42 | X(int64_t, Integer) 43 | X(uint32_t, Uint32) 44 | X(int32_t, Int32) 45 | 46 | #undef X 47 | 48 | #endif // NAN_CONVERTERS_43_INL_H_ 49 | -------------------------------------------------------------------------------- /node_modules/nan/nan_converters_pre_43_inl.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * NAN - Native Abstractions for Node.js 3 | * 4 | * Copyright (c) 2018 NAN contributors 5 | * 6 | * MIT License 7 | ********************************************************************/ 8 | 9 | #ifndef NAN_CONVERTERS_PRE_43_INL_H_ 10 | #define NAN_CONVERTERS_PRE_43_INL_H_ 11 | 12 | #define X(TYPE) \ 13 | imp::ToFactory::return_t \ 14 | imp::ToFactory::convert(v8::Local val) { \ 15 | return val->To ## TYPE(); \ 16 | } 17 | 18 | X(Boolean) 19 | X(Number) 20 | X(String) 21 | X(Object) 22 | X(Integer) 23 | X(Uint32) 24 | X(Int32) 25 | 26 | #undef X 27 | 28 | #define X(TYPE, NAME) \ 29 | imp::ToFactory::return_t \ 30 | imp::ToFactory::convert(v8::Local val) { \ 31 | return Just(val->NAME ## Value()); \ 32 | } 33 | 34 | X(bool, Boolean) 35 | X(double, Number) 36 | X(int64_t, Integer) 37 | X(uint32_t, Uint32) 38 | X(int32_t, Int32) 39 | 40 | #undef X 41 | 42 | #endif // NAN_CONVERTERS_PRE_43_INL_H_ 43 | -------------------------------------------------------------------------------- /node_modules/nan/nan_define_own_property_helper.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * NAN - Native Abstractions for Node.js 3 | * 4 | * Copyright (c) 2018 NAN contributors 5 | * 6 | * MIT License 7 | ********************************************************************/ 8 | 9 | #ifndef NAN_DEFINE_OWN_PROPERTY_HELPER_H_ 10 | #define NAN_DEFINE_OWN_PROPERTY_HELPER_H_ 11 | 12 | namespace imp { 13 | 14 | inline Maybe DefineOwnPropertyHelper( 15 | v8::PropertyAttribute current 16 | , v8::Handle obj 17 | , v8::Handle key 18 | , v8::Handle value 19 | , v8::PropertyAttribute attribs = v8::None) { 20 | return !(current & v8::DontDelete) || // configurable OR 21 | (!(current & v8::ReadOnly) && // writable AND 22 | !((attribs ^ current) & ~v8::ReadOnly)) // same excluding RO 23 | ? Just(obj->ForceSet(key, value, attribs)) 24 | : Nothing(); 25 | } 26 | 27 | } // end of namespace imp 28 | 29 | #endif // NAN_DEFINE_OWN_PROPERTY_HELPER_H_ 30 | -------------------------------------------------------------------------------- /node_modules/nan/nan_implementation_pre_12_inl.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * NAN - Native Abstractions for Node.js 3 | * 4 | * Copyright (c) 2018 NAN contributors 5 | * 6 | * MIT License 7 | ********************************************************************/ 8 | 9 | #ifndef NAN_IMPLEMENTATION_PRE_12_INL_H_ 10 | #define NAN_IMPLEMENTATION_PRE_12_INL_H_ 11 | 12 | //============================================================================== 13 | // node v0.10 implementation 14 | //============================================================================== 15 | 16 | namespace imp { 17 | 18 | //=== Array ==================================================================== 19 | 20 | Factory::return_t 21 | Factory::New() { 22 | return v8::Array::New(); 23 | } 24 | 25 | Factory::return_t 26 | Factory::New(int length) { 27 | return v8::Array::New(length); 28 | } 29 | 30 | //=== Boolean ================================================================== 31 | 32 | Factory::return_t 33 | Factory::New(bool value) { 34 | return v8::Boolean::New(value)->ToBoolean(); 35 | } 36 | 37 | //=== Boolean Object =========================================================== 38 | 39 | Factory::return_t 40 | Factory::New(bool value) { 41 | return v8::BooleanObject::New(value).As(); 42 | } 43 | 44 | //=== Context ================================================================== 45 | 46 | Factory::return_t 47 | Factory::New( v8::ExtensionConfiguration* extensions 48 | , v8::Local tmpl 49 | , v8::Local obj) { 50 | v8::Persistent ctx = v8::Context::New(extensions, tmpl, obj); 51 | v8::Local lctx = v8::Local::New(ctx); 52 | ctx.Dispose(); 53 | return lctx; 54 | } 55 | 56 | //=== Date ===================================================================== 57 | 58 | Factory::return_t 59 | Factory::New(double value) { 60 | return v8::Date::New(value).As(); 61 | } 62 | 63 | //=== External ================================================================= 64 | 65 | Factory::return_t 66 | Factory::New(void * value) { 67 | return v8::External::New(value); 68 | } 69 | 70 | //=== Function ================================================================= 71 | 72 | Factory::return_t 73 | Factory::New( FunctionCallback callback 74 | , v8::Local data) { 75 | v8::HandleScope scope; 76 | 77 | return scope.Close(Factory::New( 78 | callback, data, v8::Local()) 79 | ->GetFunction()); 80 | } 81 | 82 | 83 | //=== FunctionTemplate ========================================================= 84 | 85 | Factory::return_t 86 | Factory::New( FunctionCallback callback 87 | , v8::Local data 88 | , v8::Local signature) { 89 | if (callback) { 90 | v8::HandleScope scope; 91 | 92 | v8::Local tpl = v8::ObjectTemplate::New(); 93 | tpl->SetInternalFieldCount(imp::kFunctionFieldCount); 94 | v8::Local obj = tpl->NewInstance(); 95 | 96 | obj->SetInternalField( 97 | imp::kFunctionIndex 98 | , v8::External::New(reinterpret_cast(callback))); 99 | 100 | v8::Local val = v8::Local::New(data); 101 | 102 | if (!val.IsEmpty()) { 103 | obj->SetInternalField(imp::kDataIndex, val); 104 | } 105 | 106 | // Note(agnat): Emulate length argument here. Unfortunately, I couldn't find 107 | // a way. Have at it though... 108 | return scope.Close( 109 | v8::FunctionTemplate::New(imp::FunctionCallbackWrapper 110 | , obj 111 | , signature)); 112 | } else { 113 | return v8::FunctionTemplate::New(0, data, signature); 114 | } 115 | } 116 | 117 | //=== Number =================================================================== 118 | 119 | Factory::return_t 120 | Factory::New(double value) { 121 | return v8::Number::New(value); 122 | } 123 | 124 | //=== Number Object ============================================================ 125 | 126 | Factory::return_t 127 | Factory::New(double value) { 128 | return v8::NumberObject::New(value).As(); 129 | } 130 | 131 | //=== Integer, Int32 and Uint32 ================================================ 132 | 133 | template 134 | typename IntegerFactory::return_t 135 | IntegerFactory::New(int32_t value) { 136 | return To(T::New(value)); 137 | } 138 | 139 | template 140 | typename IntegerFactory::return_t 141 | IntegerFactory::New(uint32_t value) { 142 | return To(T::NewFromUnsigned(value)); 143 | } 144 | 145 | Factory::return_t 146 | Factory::New(int32_t value) { 147 | return To(v8::Uint32::NewFromUnsigned(value)); 148 | } 149 | 150 | Factory::return_t 151 | Factory::New(uint32_t value) { 152 | return To(v8::Uint32::NewFromUnsigned(value)); 153 | } 154 | 155 | 156 | //=== Object =================================================================== 157 | 158 | Factory::return_t 159 | Factory::New() { 160 | return v8::Object::New(); 161 | } 162 | 163 | //=== Object Template ========================================================== 164 | 165 | Factory::return_t 166 | Factory::New() { 167 | return v8::ObjectTemplate::New(); 168 | } 169 | 170 | //=== RegExp =================================================================== 171 | 172 | Factory::return_t 173 | Factory::New( 174 | v8::Local pattern 175 | , v8::RegExp::Flags flags) { 176 | return v8::RegExp::New(pattern, flags); 177 | } 178 | 179 | //=== Script =================================================================== 180 | 181 | Factory::return_t 182 | Factory::New( v8::Local source) { 183 | return v8::Script::New(source); 184 | } 185 | Factory::return_t 186 | Factory::New( v8::Local source 187 | , v8::ScriptOrigin const& origin) { 188 | return v8::Script::New(source, const_cast(&origin)); 189 | } 190 | 191 | //=== Signature ================================================================ 192 | 193 | Factory::return_t 194 | Factory::New(Factory::FTH receiver) { 195 | return v8::Signature::New(receiver); 196 | } 197 | 198 | //=== String =================================================================== 199 | 200 | Factory::return_t 201 | Factory::New() { 202 | return v8::String::Empty(); 203 | } 204 | 205 | Factory::return_t 206 | Factory::New(const char * value, int length) { 207 | return v8::String::New(value, length); 208 | } 209 | 210 | Factory::return_t 211 | Factory::New( 212 | std::string const& value) /* NOLINT(build/include_what_you_use) */ { 213 | assert(value.size() <= INT_MAX && "string too long"); 214 | return v8::String::New(value.data(), static_cast(value.size())); 215 | } 216 | 217 | Factory::return_t 218 | Factory::New(const uint16_t * value, int length) { 219 | return v8::String::New(value, length); 220 | } 221 | 222 | Factory::return_t 223 | Factory::New(v8::String::ExternalStringResource * value) { 224 | return v8::String::NewExternal(value); 225 | } 226 | 227 | Factory::return_t 228 | Factory::New(v8::String::ExternalAsciiStringResource * value) { 229 | return v8::String::NewExternal(value); 230 | } 231 | 232 | //=== String Object ============================================================ 233 | 234 | Factory::return_t 235 | Factory::New(v8::Local value) { 236 | return v8::StringObject::New(value).As(); 237 | } 238 | 239 | } // end of namespace imp 240 | 241 | //=== Presistents and Handles ================================================== 242 | 243 | template 244 | inline v8::Local New(v8::Handle h) { 245 | return v8::Local::New(h); 246 | } 247 | 248 | template 249 | inline v8::Local New(v8::Persistent const& p) { 250 | return v8::Local::New(p); 251 | } 252 | 253 | template 254 | inline v8::Local New(Persistent const& p) { 255 | return v8::Local::New(p.persistent); 256 | } 257 | 258 | template 259 | inline v8::Local New(Global const& p) { 260 | return v8::Local::New(p.persistent); 261 | } 262 | 263 | #endif // NAN_IMPLEMENTATION_PRE_12_INL_H_ 264 | -------------------------------------------------------------------------------- /node_modules/nan/nan_json.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * NAN - Native Abstractions for Node.js 3 | * 4 | * Copyright (c) 2018 NAN contributors 5 | * 6 | * MIT License 7 | ********************************************************************/ 8 | 9 | #ifndef NAN_JSON_H_ 10 | #define NAN_JSON_H_ 11 | 12 | #if NODE_MODULE_VERSION < NODE_0_12_MODULE_VERSION 13 | #define NAN_JSON_H_NEED_PARSE 1 14 | #else 15 | #define NAN_JSON_H_NEED_PARSE 0 16 | #endif // NODE_MODULE_VERSION < NODE_0_12_MODULE_VERSION 17 | 18 | #if NODE_MODULE_VERSION >= NODE_7_0_MODULE_VERSION 19 | #define NAN_JSON_H_NEED_STRINGIFY 0 20 | #else 21 | #define NAN_JSON_H_NEED_STRINGIFY 1 22 | #endif // NODE_MODULE_VERSION >= NODE_7_0_MODULE_VERSION 23 | 24 | class JSON { 25 | public: 26 | JSON() { 27 | #if NAN_JSON_H_NEED_PARSE + NAN_JSON_H_NEED_STRINGIFY 28 | Nan::HandleScope scope; 29 | 30 | Nan::MaybeLocal maybe_global_json = Nan::Get( 31 | Nan::GetCurrentContext()->Global(), 32 | Nan::New("JSON").ToLocalChecked() 33 | ); 34 | 35 | assert(!maybe_global_json.IsEmpty() && "global JSON is empty"); 36 | v8::Local val_global_json = maybe_global_json.ToLocalChecked(); 37 | 38 | assert(val_global_json->IsObject() && "global JSON is not an object"); 39 | Nan::MaybeLocal maybe_obj_global_json = 40 | Nan::To(val_global_json); 41 | 42 | assert(!maybe_obj_global_json.IsEmpty() && "global JSON object is empty"); 43 | v8::Local global_json = maybe_obj_global_json.ToLocalChecked(); 44 | 45 | #if NAN_JSON_H_NEED_PARSE 46 | Nan::MaybeLocal maybe_parse_method = Nan::Get( 47 | global_json, Nan::New("parse").ToLocalChecked() 48 | ); 49 | 50 | assert(!maybe_parse_method.IsEmpty() && "JSON.parse is empty"); 51 | v8::Local parse_method = maybe_parse_method.ToLocalChecked(); 52 | 53 | assert(parse_method->IsFunction() && "JSON.parse is not a function"); 54 | parse_cb_.Reset(parse_method.As()); 55 | #endif // NAN_JSON_H_NEED_PARSE 56 | 57 | #if NAN_JSON_H_NEED_STRINGIFY 58 | Nan::MaybeLocal maybe_stringify_method = Nan::Get( 59 | global_json, Nan::New("stringify").ToLocalChecked() 60 | ); 61 | 62 | assert(!maybe_stringify_method.IsEmpty() && "JSON.stringify is empty"); 63 | v8::Local stringify_method = 64 | maybe_stringify_method.ToLocalChecked(); 65 | 66 | assert( 67 | stringify_method->IsFunction() && "JSON.stringify is not a function" 68 | ); 69 | stringify_cb_.Reset(stringify_method.As()); 70 | #endif // NAN_JSON_H_NEED_STRINGIFY 71 | #endif // NAN_JSON_H_NEED_PARSE + NAN_JSON_H_NEED_STRINGIFY 72 | } 73 | 74 | inline 75 | Nan::MaybeLocal Parse(v8::Local json_string) { 76 | Nan::EscapableHandleScope scope; 77 | #if NAN_JSON_H_NEED_PARSE 78 | return scope.Escape(parse(json_string)); 79 | #else 80 | Nan::MaybeLocal result; 81 | #if NODE_MODULE_VERSION >= NODE_0_12_MODULE_VERSION && \ 82 | NODE_MODULE_VERSION <= IOJS_2_0_MODULE_VERSION 83 | result = v8::JSON::Parse(json_string); 84 | #else 85 | #if NODE_MODULE_VERSION > NODE_6_0_MODULE_VERSION 86 | v8::Local context_or_isolate = Nan::GetCurrentContext(); 87 | #else 88 | v8::Isolate* context_or_isolate = v8::Isolate::GetCurrent(); 89 | #endif // NODE_MODULE_VERSION > NODE_6_0_MODULE_VERSION 90 | result = v8::JSON::Parse(context_or_isolate, json_string); 91 | #endif // NODE_MODULE_VERSION >= NODE_0_12_MODULE_VERSION && 92 | // NODE_MODULE_VERSION <= IOJS_2_0_MODULE_VERSION 93 | if (result.IsEmpty()) return v8::Local(); 94 | return scope.Escape(result.ToLocalChecked()); 95 | #endif // NAN_JSON_H_NEED_PARSE 96 | } 97 | 98 | inline 99 | Nan::MaybeLocal Stringify(v8::Local json_object) { 100 | Nan::EscapableHandleScope scope; 101 | Nan::MaybeLocal result = 102 | #if NAN_JSON_H_NEED_STRINGIFY 103 | Nan::To(stringify(json_object)); 104 | #else 105 | v8::JSON::Stringify(Nan::GetCurrentContext(), json_object); 106 | #endif // NAN_JSON_H_NEED_STRINGIFY 107 | if (result.IsEmpty()) return v8::Local(); 108 | return scope.Escape(result.ToLocalChecked()); 109 | } 110 | 111 | inline 112 | Nan::MaybeLocal Stringify(v8::Local json_object, 113 | v8::Local gap) { 114 | Nan::EscapableHandleScope scope; 115 | Nan::MaybeLocal result = 116 | #if NAN_JSON_H_NEED_STRINGIFY 117 | Nan::To(stringify(json_object, gap)); 118 | #else 119 | v8::JSON::Stringify(Nan::GetCurrentContext(), json_object, gap); 120 | #endif // NAN_JSON_H_NEED_STRINGIFY 121 | if (result.IsEmpty()) return v8::Local(); 122 | return scope.Escape(result.ToLocalChecked()); 123 | } 124 | 125 | private: 126 | NAN_DISALLOW_ASSIGN_COPY_MOVE(JSON) 127 | #if NAN_JSON_H_NEED_PARSE 128 | Nan::Callback parse_cb_; 129 | #endif // NAN_JSON_H_NEED_PARSE 130 | #if NAN_JSON_H_NEED_STRINGIFY 131 | Nan::Callback stringify_cb_; 132 | #endif // NAN_JSON_H_NEED_STRINGIFY 133 | 134 | #if NAN_JSON_H_NEED_PARSE 135 | inline v8::Local parse(v8::Local arg) { 136 | assert(!parse_cb_.IsEmpty() && "parse_cb_ is empty"); 137 | AsyncResource resource("nan:JSON.parse"); 138 | return parse_cb_.Call(1, &arg, &resource).FromMaybe(v8::Local()); 139 | } 140 | #endif // NAN_JSON_H_NEED_PARSE 141 | 142 | #if NAN_JSON_H_NEED_STRINGIFY 143 | inline v8::Local stringify(v8::Local arg) { 144 | assert(!stringify_cb_.IsEmpty() && "stringify_cb_ is empty"); 145 | AsyncResource resource("nan:JSON.stringify"); 146 | return stringify_cb_.Call(1, &arg, &resource) 147 | .FromMaybe(v8::Local()); 148 | } 149 | 150 | inline v8::Local stringify(v8::Local arg, 151 | v8::Local gap) { 152 | assert(!stringify_cb_.IsEmpty() && "stringify_cb_ is empty"); 153 | 154 | v8::Local argv[] = { 155 | arg, 156 | Nan::Null(), 157 | gap 158 | }; 159 | AsyncResource resource("nan:JSON.stringify"); 160 | return stringify_cb_.Call(3, argv, &resource) 161 | .FromMaybe(v8::Local()); 162 | } 163 | #endif // NAN_JSON_H_NEED_STRINGIFY 164 | }; 165 | 166 | #endif // NAN_JSON_H_ 167 | -------------------------------------------------------------------------------- /node_modules/nan/nan_object_wrap.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * NAN - Native Abstractions for Node.js 3 | * 4 | * Copyright (c) 2018 NAN contributors 5 | * 6 | * MIT License 7 | ********************************************************************/ 8 | 9 | #ifndef NAN_OBJECT_WRAP_H_ 10 | #define NAN_OBJECT_WRAP_H_ 11 | 12 | class ObjectWrap { 13 | public: 14 | ObjectWrap() { 15 | refs_ = 0; 16 | } 17 | 18 | 19 | virtual ~ObjectWrap() { 20 | if (persistent().IsEmpty()) { 21 | return; 22 | } 23 | 24 | assert(persistent().IsNearDeath()); 25 | persistent().ClearWeak(); 26 | persistent().Reset(); 27 | } 28 | 29 | 30 | template 31 | static inline T* Unwrap(v8::Local object) { 32 | assert(!object.IsEmpty()); 33 | assert(object->InternalFieldCount() > 0); 34 | // Cast to ObjectWrap before casting to T. A direct cast from void 35 | // to T won't work right when T has more than one base class. 36 | void* ptr = GetInternalFieldPointer(object, 0); 37 | ObjectWrap* wrap = static_cast(ptr); 38 | return static_cast(wrap); 39 | } 40 | 41 | 42 | inline v8::Local handle() const { 43 | return New(handle_); 44 | } 45 | 46 | 47 | inline Persistent& persistent() { 48 | return handle_; 49 | } 50 | 51 | 52 | protected: 53 | inline void Wrap(v8::Local object) { 54 | assert(persistent().IsEmpty()); 55 | assert(object->InternalFieldCount() > 0); 56 | SetInternalFieldPointer(object, 0, this); 57 | persistent().Reset(object); 58 | MakeWeak(); 59 | } 60 | 61 | #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ 62 | (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) 63 | 64 | inline void MakeWeak() { 65 | persistent().v8::PersistentBase::SetWeak( 66 | this, WeakCallback, v8::WeakCallbackType::kParameter); 67 | persistent().MarkIndependent(); 68 | } 69 | 70 | #elif NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION 71 | 72 | inline void MakeWeak() { 73 | persistent().v8::PersistentBase::SetWeak(this, WeakCallback); 74 | persistent().MarkIndependent(); 75 | } 76 | 77 | #else 78 | 79 | inline void MakeWeak() { 80 | persistent().persistent.MakeWeak(this, WeakCallback); 81 | persistent().MarkIndependent(); 82 | } 83 | 84 | #endif 85 | 86 | /* Ref() marks the object as being attached to an event loop. 87 | * Refed objects will not be garbage collected, even if 88 | * all references are lost. 89 | */ 90 | virtual void Ref() { 91 | assert(!persistent().IsEmpty()); 92 | persistent().ClearWeak(); 93 | refs_++; 94 | } 95 | 96 | /* Unref() marks an object as detached from the event loop. This is its 97 | * default state. When an object with a "weak" reference changes from 98 | * attached to detached state it will be freed. Be careful not to access 99 | * the object after making this call as it might be gone! 100 | * (A "weak reference" means an object that only has a 101 | * persistant handle.) 102 | * 103 | * DO NOT CALL THIS FROM DESTRUCTOR 104 | */ 105 | virtual void Unref() { 106 | assert(!persistent().IsEmpty()); 107 | assert(!persistent().IsWeak()); 108 | assert(refs_ > 0); 109 | if (--refs_ == 0) 110 | MakeWeak(); 111 | } 112 | 113 | int refs_; // ro 114 | 115 | private: 116 | NAN_DISALLOW_ASSIGN_COPY_MOVE(ObjectWrap) 117 | #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ 118 | (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) 119 | 120 | static void 121 | WeakCallback(v8::WeakCallbackInfo const& info) { 122 | ObjectWrap* wrap = info.GetParameter(); 123 | assert(wrap->refs_ == 0); 124 | assert(wrap->handle_.IsNearDeath()); 125 | wrap->handle_.Reset(); 126 | delete wrap; 127 | } 128 | 129 | #elif NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION 130 | 131 | static void 132 | WeakCallback(v8::WeakCallbackData const& data) { 133 | ObjectWrap* wrap = data.GetParameter(); 134 | assert(wrap->refs_ == 0); 135 | assert(wrap->handle_.IsNearDeath()); 136 | wrap->handle_.Reset(); 137 | delete wrap; 138 | } 139 | 140 | #else 141 | 142 | static void WeakCallback(v8::Persistent value, void *data) { 143 | ObjectWrap *wrap = static_cast(data); 144 | assert(wrap->refs_ == 0); 145 | assert(wrap->handle_.IsNearDeath()); 146 | wrap->handle_.Reset(); 147 | delete wrap; 148 | } 149 | 150 | #endif 151 | Persistent handle_; 152 | }; 153 | 154 | 155 | #endif // NAN_OBJECT_WRAP_H_ 156 | -------------------------------------------------------------------------------- /node_modules/nan/nan_persistent_12_inl.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * NAN - Native Abstractions for Node.js 3 | * 4 | * Copyright (c) 2018 NAN contributors 5 | * 6 | * MIT License 7 | ********************************************************************/ 8 | 9 | #ifndef NAN_PERSISTENT_12_INL_H_ 10 | #define NAN_PERSISTENT_12_INL_H_ 11 | 12 | template class Persistent : 13 | public v8::Persistent { 14 | public: 15 | inline Persistent() : v8::Persistent() {} 16 | 17 | template inline Persistent(v8::Local that) : 18 | v8::Persistent(v8::Isolate::GetCurrent(), that) {} 19 | 20 | template 21 | inline 22 | Persistent(const v8::Persistent &that) : // NOLINT(runtime/explicit) 23 | v8::Persistent(v8::Isolate::GetCurrent(), that) {} 24 | 25 | inline void Reset() { v8::PersistentBase::Reset(); } 26 | 27 | template 28 | inline void Reset(const v8::Local &other) { 29 | v8::PersistentBase::Reset(v8::Isolate::GetCurrent(), other); 30 | } 31 | 32 | template 33 | inline void Reset(const v8::PersistentBase &other) { 34 | v8::PersistentBase::Reset(v8::Isolate::GetCurrent(), other); 35 | } 36 | 37 | template 38 | inline void SetWeak( 39 | P *parameter 40 | , typename WeakCallbackInfo

::Callback callback 41 | , WeakCallbackType type); 42 | 43 | private: 44 | inline T *operator*() const { return *PersistentBase::persistent; } 45 | 46 | template 47 | inline void Copy(const Persistent &that) { 48 | TYPE_CHECK(T, S); 49 | 50 | this->Reset(); 51 | 52 | if (!that.IsEmpty()) { 53 | this->Reset(that); 54 | M::Copy(that, this); 55 | } 56 | } 57 | }; 58 | 59 | #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ 60 | (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) 61 | template 62 | class Global : public v8::Global { 63 | public: 64 | inline Global() : v8::Global() {} 65 | 66 | template inline Global(v8::Local that) : 67 | v8::Global(v8::Isolate::GetCurrent(), that) {} 68 | 69 | template 70 | inline 71 | Global(const v8::PersistentBase &that) : // NOLINT(runtime/explicit) 72 | v8::Global(v8::Isolate::GetCurrent(), that) {} 73 | 74 | inline void Reset() { v8::PersistentBase::Reset(); } 75 | 76 | template 77 | inline void Reset(const v8::Local &other) { 78 | v8::PersistentBase::Reset(v8::Isolate::GetCurrent(), other); 79 | } 80 | 81 | template 82 | inline void Reset(const v8::PersistentBase &other) { 83 | v8::PersistentBase::Reset(v8::Isolate::GetCurrent(), other); 84 | } 85 | 86 | template 87 | inline void SetWeak( 88 | P *parameter 89 | , typename WeakCallbackInfo

::Callback callback 90 | , WeakCallbackType type) { 91 | reinterpret_cast*>(this)->SetWeak( 92 | parameter, callback, type); 93 | } 94 | }; 95 | #else 96 | template 97 | class Global : public v8::UniquePersistent { 98 | public: 99 | inline Global() : v8::UniquePersistent() {} 100 | 101 | template inline Global(v8::Local that) : 102 | v8::UniquePersistent(v8::Isolate::GetCurrent(), that) {} 103 | 104 | template 105 | inline 106 | Global(const v8::PersistentBase &that) : // NOLINT(runtime/explicit) 107 | v8::UniquePersistent(v8::Isolate::GetCurrent(), that) {} 108 | 109 | inline void Reset() { v8::PersistentBase::Reset(); } 110 | 111 | template 112 | inline void Reset(const v8::Local &other) { 113 | v8::PersistentBase::Reset(v8::Isolate::GetCurrent(), other); 114 | } 115 | 116 | template 117 | inline void Reset(const v8::PersistentBase &other) { 118 | v8::PersistentBase::Reset(v8::Isolate::GetCurrent(), other); 119 | } 120 | 121 | template 122 | inline void SetWeak( 123 | P *parameter 124 | , typename WeakCallbackInfo

::Callback callback 125 | , WeakCallbackType type) { 126 | reinterpret_cast*>(this)->SetWeak( 127 | parameter, callback, type); 128 | } 129 | }; 130 | #endif 131 | 132 | #endif // NAN_PERSISTENT_12_INL_H_ 133 | -------------------------------------------------------------------------------- /node_modules/nan/nan_persistent_pre_12_inl.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * NAN - Native Abstractions for Node.js 3 | * 4 | * Copyright (c) 2018 NAN contributors 5 | * 6 | * MIT License 7 | ********************************************************************/ 8 | 9 | #ifndef NAN_PERSISTENT_PRE_12_INL_H_ 10 | #define NAN_PERSISTENT_PRE_12_INL_H_ 11 | 12 | template 13 | class PersistentBase { 14 | v8::Persistent persistent; 15 | template 16 | friend v8::Local New(const PersistentBase &p); 17 | template 18 | friend v8::Local New(const Persistent &p); 19 | template 20 | friend v8::Local New(const Global &p); 21 | template friend class ReturnValue; 22 | 23 | public: 24 | inline PersistentBase() : 25 | persistent() {} 26 | 27 | inline void Reset() { 28 | persistent.Dispose(); 29 | persistent.Clear(); 30 | } 31 | 32 | template 33 | inline void Reset(const v8::Local &other) { 34 | TYPE_CHECK(T, S); 35 | 36 | if (!persistent.IsEmpty()) { 37 | persistent.Dispose(); 38 | } 39 | 40 | if (other.IsEmpty()) { 41 | persistent.Clear(); 42 | } else { 43 | persistent = v8::Persistent::New(other); 44 | } 45 | } 46 | 47 | template 48 | inline void Reset(const PersistentBase &other) { 49 | TYPE_CHECK(T, S); 50 | 51 | if (!persistent.IsEmpty()) { 52 | persistent.Dispose(); 53 | } 54 | 55 | if (other.IsEmpty()) { 56 | persistent.Clear(); 57 | } else { 58 | persistent = v8::Persistent::New(other.persistent); 59 | } 60 | } 61 | 62 | inline bool IsEmpty() const { return persistent.IsEmpty(); } 63 | 64 | inline void Empty() { persistent.Clear(); } 65 | 66 | template 67 | inline bool operator==(const PersistentBase &that) const { 68 | return this->persistent == that.persistent; 69 | } 70 | 71 | template 72 | inline bool operator==(const v8::Local &that) const { 73 | return this->persistent == that; 74 | } 75 | 76 | template 77 | inline bool operator!=(const PersistentBase &that) const { 78 | return !operator==(that); 79 | } 80 | 81 | template 82 | inline bool operator!=(const v8::Local &that) const { 83 | return !operator==(that); 84 | } 85 | 86 | template 87 | inline void SetWeak( 88 | P *parameter 89 | , typename WeakCallbackInfo

::Callback callback 90 | , WeakCallbackType type); 91 | 92 | inline void ClearWeak() { persistent.ClearWeak(); } 93 | 94 | inline void MarkIndependent() { persistent.MarkIndependent(); } 95 | 96 | inline bool IsIndependent() const { return persistent.IsIndependent(); } 97 | 98 | inline bool IsNearDeath() const { return persistent.IsNearDeath(); } 99 | 100 | inline bool IsWeak() const { return persistent.IsWeak(); } 101 | 102 | private: 103 | inline explicit PersistentBase(v8::Persistent that) : 104 | persistent(that) { } 105 | inline explicit PersistentBase(T *val) : persistent(val) {} 106 | template friend class Persistent; 107 | template friend class Global; 108 | friend class ObjectWrap; 109 | }; 110 | 111 | template 112 | class NonCopyablePersistentTraits { 113 | public: 114 | typedef Persistent > 115 | NonCopyablePersistent; 116 | static const bool kResetInDestructor = false; 117 | template 118 | inline static void Copy(const Persistent &source, 119 | NonCopyablePersistent *dest) { 120 | Uncompilable(); 121 | } 122 | 123 | template inline static void Uncompilable() { 124 | TYPE_CHECK(O, v8::Primitive); 125 | } 126 | }; 127 | 128 | template 129 | struct CopyablePersistentTraits { 130 | typedef Persistent > CopyablePersistent; 131 | static const bool kResetInDestructor = true; 132 | template 133 | static inline void Copy(const Persistent &source, 134 | CopyablePersistent *dest) {} 135 | }; 136 | 137 | template class Persistent : 138 | public PersistentBase { 139 | public: 140 | inline Persistent() {} 141 | 142 | template inline Persistent(v8::Handle that) 143 | : PersistentBase(v8::Persistent::New(that)) { 144 | TYPE_CHECK(T, S); 145 | } 146 | 147 | inline Persistent(const Persistent &that) : PersistentBase() { 148 | Copy(that); 149 | } 150 | 151 | template 152 | inline Persistent(const Persistent &that) : 153 | PersistentBase() { 154 | Copy(that); 155 | } 156 | 157 | inline Persistent &operator=(const Persistent &that) { 158 | Copy(that); 159 | return *this; 160 | } 161 | 162 | template 163 | inline Persistent &operator=(const Persistent &that) { 164 | Copy(that); 165 | return *this; 166 | } 167 | 168 | inline ~Persistent() { 169 | if (M::kResetInDestructor) this->Reset(); 170 | } 171 | 172 | private: 173 | inline T *operator*() const { return *PersistentBase::persistent; } 174 | 175 | template 176 | inline void Copy(const Persistent &that) { 177 | TYPE_CHECK(T, S); 178 | 179 | this->Reset(); 180 | 181 | if (!that.IsEmpty()) { 182 | this->persistent = v8::Persistent::New(that.persistent); 183 | M::Copy(that, this); 184 | } 185 | } 186 | }; 187 | 188 | template 189 | class Global : public PersistentBase { 190 | struct RValue { 191 | inline explicit RValue(Global* obj) : object(obj) {} 192 | Global* object; 193 | }; 194 | 195 | public: 196 | inline Global() : PersistentBase(0) { } 197 | 198 | template 199 | inline Global(v8::Local that) // NOLINT(runtime/explicit) 200 | : PersistentBase(v8::Persistent::New(that)) { 201 | TYPE_CHECK(T, S); 202 | } 203 | 204 | template 205 | inline Global(const PersistentBase &that) // NOLINT(runtime/explicit) 206 | : PersistentBase(that) { 207 | TYPE_CHECK(T, S); 208 | } 209 | /** 210 | * Move constructor. 211 | */ 212 | inline Global(RValue rvalue) // NOLINT(runtime/explicit) 213 | : PersistentBase(rvalue.object->persistent) { 214 | rvalue.object->Reset(); 215 | } 216 | inline ~Global() { this->Reset(); } 217 | /** 218 | * Move via assignment. 219 | */ 220 | template 221 | inline Global &operator=(Global rhs) { 222 | TYPE_CHECK(T, S); 223 | this->Reset(rhs.persistent); 224 | rhs.Reset(); 225 | return *this; 226 | } 227 | /** 228 | * Cast operator for moves. 229 | */ 230 | inline operator RValue() { return RValue(this); } 231 | /** 232 | * Pass allows returning uniques from functions, etc. 233 | */ 234 | Global Pass() { return Global(RValue(this)); } 235 | 236 | private: 237 | Global(Global &); 238 | void operator=(Global &); 239 | template friend class ReturnValue; 240 | }; 241 | 242 | #endif // NAN_PERSISTENT_PRE_12_INL_H_ 243 | -------------------------------------------------------------------------------- /node_modules/nan/nan_private.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * NAN - Native Abstractions for Node.js 3 | * 4 | * Copyright (c) 2018 NAN contributors 5 | * 6 | * MIT License 7 | ********************************************************************/ 8 | 9 | #ifndef NAN_PRIVATE_H_ 10 | #define NAN_PRIVATE_H_ 11 | 12 | inline Maybe 13 | HasPrivate(v8::Local object, v8::Local key) { 14 | HandleScope scope; 15 | #if NODE_MODULE_VERSION >= NODE_6_0_MODULE_VERSION 16 | v8::Isolate *isolate = v8::Isolate::GetCurrent(); 17 | v8::Local context = isolate->GetCurrentContext(); 18 | v8::Local private_key = v8::Private::ForApi(isolate, key); 19 | return object->HasPrivate(context, private_key); 20 | #else 21 | return Just(!object->GetHiddenValue(key).IsEmpty()); 22 | #endif 23 | } 24 | 25 | inline MaybeLocal 26 | GetPrivate(v8::Local object, v8::Local key) { 27 | #if NODE_MODULE_VERSION >= NODE_6_0_MODULE_VERSION 28 | v8::Isolate *isolate = v8::Isolate::GetCurrent(); 29 | v8::EscapableHandleScope scope(isolate); 30 | v8::Local context = isolate->GetCurrentContext(); 31 | v8::Local private_key = v8::Private::ForApi(isolate, key); 32 | v8::MaybeLocal v = object->GetPrivate(context, private_key); 33 | return scope.Escape(v.ToLocalChecked()); 34 | #else 35 | EscapableHandleScope scope; 36 | v8::Local v = object->GetHiddenValue(key); 37 | if (v.IsEmpty()) { 38 | v = Undefined(); 39 | } 40 | return scope.Escape(v); 41 | #endif 42 | } 43 | 44 | inline Maybe SetPrivate( 45 | v8::Local object, 46 | v8::Local key, 47 | v8::Local value) { 48 | #if NODE_MODULE_VERSION >= NODE_6_0_MODULE_VERSION 49 | HandleScope scope; 50 | v8::Isolate *isolate = v8::Isolate::GetCurrent(); 51 | v8::Local context = isolate->GetCurrentContext(); 52 | v8::Local private_key = v8::Private::ForApi(isolate, key); 53 | return object->SetPrivate(context, private_key, value); 54 | #else 55 | return Just(object->SetHiddenValue(key, value)); 56 | #endif 57 | } 58 | 59 | inline Maybe DeletePrivate( 60 | v8::Local object, 61 | v8::Local key) { 62 | #if NODE_MODULE_VERSION >= NODE_6_0_MODULE_VERSION 63 | HandleScope scope; 64 | v8::Isolate *isolate = v8::Isolate::GetCurrent(); 65 | v8::Local private_key = v8::Private::ForApi(isolate, key); 66 | return object->DeletePrivate(isolate->GetCurrentContext(), private_key); 67 | #else 68 | return Just(object->DeleteHiddenValue(key)); 69 | #endif 70 | } 71 | 72 | #endif // NAN_PRIVATE_H_ 73 | 74 | -------------------------------------------------------------------------------- /node_modules/nan/nan_string_bytes.h: -------------------------------------------------------------------------------- 1 | // Copyright Joyent, Inc. and other Node contributors. 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a 4 | // copy of this software and associated documentation files (the 5 | // "Software"), to deal in the Software without restriction, including 6 | // without limitation the rights to use, copy, modify, merge, publish, 7 | // distribute, sublicense, and/or sell copies of the Software, and to permit 8 | // persons to whom the Software is furnished to do so, subject to the 9 | // following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included 12 | // in all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | #ifndef NAN_STRING_BYTES_H_ 23 | #define NAN_STRING_BYTES_H_ 24 | 25 | // Decodes a v8::Local or Buffer to a raw char* 26 | 27 | namespace imp { 28 | 29 | using v8::Local; 30 | using v8::Object; 31 | using v8::String; 32 | using v8::Value; 33 | 34 | 35 | //// Base 64 //// 36 | 37 | #define base64_encoded_size(size) ((size + 2 - ((size + 2) % 3)) / 3 * 4) 38 | 39 | 40 | 41 | //// HEX //// 42 | 43 | static bool contains_non_ascii_slow(const char* buf, size_t len) { 44 | for (size_t i = 0; i < len; ++i) { 45 | if (buf[i] & 0x80) return true; 46 | } 47 | return false; 48 | } 49 | 50 | 51 | static bool contains_non_ascii(const char* src, size_t len) { 52 | if (len < 16) { 53 | return contains_non_ascii_slow(src, len); 54 | } 55 | 56 | const unsigned bytes_per_word = sizeof(void*); 57 | const unsigned align_mask = bytes_per_word - 1; 58 | const unsigned unaligned = reinterpret_cast(src) & align_mask; 59 | 60 | if (unaligned > 0) { 61 | const unsigned n = bytes_per_word - unaligned; 62 | if (contains_non_ascii_slow(src, n)) return true; 63 | src += n; 64 | len -= n; 65 | } 66 | 67 | 68 | #if defined(__x86_64__) || defined(_WIN64) 69 | const uintptr_t mask = 0x8080808080808080ll; 70 | #else 71 | const uintptr_t mask = 0x80808080l; 72 | #endif 73 | 74 | const uintptr_t* srcw = reinterpret_cast(src); 75 | 76 | for (size_t i = 0, n = len / bytes_per_word; i < n; ++i) { 77 | if (srcw[i] & mask) return true; 78 | } 79 | 80 | const unsigned remainder = len & align_mask; 81 | if (remainder > 0) { 82 | const size_t offset = len - remainder; 83 | if (contains_non_ascii_slow(src + offset, remainder)) return true; 84 | } 85 | 86 | return false; 87 | } 88 | 89 | 90 | static void force_ascii_slow(const char* src, char* dst, size_t len) { 91 | for (size_t i = 0; i < len; ++i) { 92 | dst[i] = src[i] & 0x7f; 93 | } 94 | } 95 | 96 | 97 | static void force_ascii(const char* src, char* dst, size_t len) { 98 | if (len < 16) { 99 | force_ascii_slow(src, dst, len); 100 | return; 101 | } 102 | 103 | const unsigned bytes_per_word = sizeof(void*); 104 | const unsigned align_mask = bytes_per_word - 1; 105 | const unsigned src_unalign = reinterpret_cast(src) & align_mask; 106 | const unsigned dst_unalign = reinterpret_cast(dst) & align_mask; 107 | 108 | if (src_unalign > 0) { 109 | if (src_unalign == dst_unalign) { 110 | const unsigned unalign = bytes_per_word - src_unalign; 111 | force_ascii_slow(src, dst, unalign); 112 | src += unalign; 113 | dst += unalign; 114 | len -= src_unalign; 115 | } else { 116 | force_ascii_slow(src, dst, len); 117 | return; 118 | } 119 | } 120 | 121 | #if defined(__x86_64__) || defined(_WIN64) 122 | const uintptr_t mask = ~0x8080808080808080ll; 123 | #else 124 | const uintptr_t mask = ~0x80808080l; 125 | #endif 126 | 127 | const uintptr_t* srcw = reinterpret_cast(src); 128 | uintptr_t* dstw = reinterpret_cast(dst); 129 | 130 | for (size_t i = 0, n = len / bytes_per_word; i < n; ++i) { 131 | dstw[i] = srcw[i] & mask; 132 | } 133 | 134 | const unsigned remainder = len & align_mask; 135 | if (remainder > 0) { 136 | const size_t offset = len - remainder; 137 | force_ascii_slow(src + offset, dst + offset, remainder); 138 | } 139 | } 140 | 141 | 142 | static size_t base64_encode(const char* src, 143 | size_t slen, 144 | char* dst, 145 | size_t dlen) { 146 | // We know how much we'll write, just make sure that there's space. 147 | assert(dlen >= base64_encoded_size(slen) && 148 | "not enough space provided for base64 encode"); 149 | 150 | dlen = base64_encoded_size(slen); 151 | 152 | unsigned a; 153 | unsigned b; 154 | unsigned c; 155 | unsigned i; 156 | unsigned k; 157 | unsigned n; 158 | 159 | static const char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 160 | "abcdefghijklmnopqrstuvwxyz" 161 | "0123456789+/"; 162 | 163 | i = 0; 164 | k = 0; 165 | n = slen / 3 * 3; 166 | 167 | while (i < n) { 168 | a = src[i + 0] & 0xff; 169 | b = src[i + 1] & 0xff; 170 | c = src[i + 2] & 0xff; 171 | 172 | dst[k + 0] = table[a >> 2]; 173 | dst[k + 1] = table[((a & 3) << 4) | (b >> 4)]; 174 | dst[k + 2] = table[((b & 0x0f) << 2) | (c >> 6)]; 175 | dst[k + 3] = table[c & 0x3f]; 176 | 177 | i += 3; 178 | k += 4; 179 | } 180 | 181 | if (n != slen) { 182 | switch (slen - n) { 183 | case 1: 184 | a = src[i + 0] & 0xff; 185 | dst[k + 0] = table[a >> 2]; 186 | dst[k + 1] = table[(a & 3) << 4]; 187 | dst[k + 2] = '='; 188 | dst[k + 3] = '='; 189 | break; 190 | 191 | case 2: 192 | a = src[i + 0] & 0xff; 193 | b = src[i + 1] & 0xff; 194 | dst[k + 0] = table[a >> 2]; 195 | dst[k + 1] = table[((a & 3) << 4) | (b >> 4)]; 196 | dst[k + 2] = table[(b & 0x0f) << 2]; 197 | dst[k + 3] = '='; 198 | break; 199 | } 200 | } 201 | 202 | return dlen; 203 | } 204 | 205 | 206 | static size_t hex_encode(const char* src, size_t slen, char* dst, size_t dlen) { 207 | // We know how much we'll write, just make sure that there's space. 208 | assert(dlen >= slen * 2 && 209 | "not enough space provided for hex encode"); 210 | 211 | dlen = slen * 2; 212 | for (uint32_t i = 0, k = 0; k < dlen; i += 1, k += 2) { 213 | static const char hex[] = "0123456789abcdef"; 214 | uint8_t val = static_cast(src[i]); 215 | dst[k + 0] = hex[val >> 4]; 216 | dst[k + 1] = hex[val & 15]; 217 | } 218 | 219 | return dlen; 220 | } 221 | 222 | 223 | 224 | static Local Encode(const char* buf, 225 | size_t buflen, 226 | enum Encoding encoding) { 227 | assert(buflen <= node::Buffer::kMaxLength); 228 | if (!buflen && encoding != BUFFER) 229 | return New("").ToLocalChecked(); 230 | 231 | Local val; 232 | switch (encoding) { 233 | case BUFFER: 234 | return CopyBuffer(buf, buflen).ToLocalChecked(); 235 | 236 | case ASCII: 237 | if (contains_non_ascii(buf, buflen)) { 238 | char* out = new char[buflen]; 239 | force_ascii(buf, out, buflen); 240 | val = New(out, buflen).ToLocalChecked(); 241 | delete[] out; 242 | } else { 243 | val = New(buf, buflen).ToLocalChecked(); 244 | } 245 | break; 246 | 247 | case UTF8: 248 | val = New(buf, buflen).ToLocalChecked(); 249 | break; 250 | 251 | case BINARY: { 252 | // TODO(isaacs) use ExternalTwoByteString? 253 | const unsigned char *cbuf = reinterpret_cast(buf); 254 | uint16_t * twobytebuf = new uint16_t[buflen]; 255 | for (size_t i = 0; i < buflen; i++) { 256 | // XXX is the following line platform independent? 257 | twobytebuf[i] = cbuf[i]; 258 | } 259 | val = New(twobytebuf, buflen).ToLocalChecked(); 260 | delete[] twobytebuf; 261 | break; 262 | } 263 | 264 | case BASE64: { 265 | size_t dlen = base64_encoded_size(buflen); 266 | char* dst = new char[dlen]; 267 | 268 | size_t written = base64_encode(buf, buflen, dst, dlen); 269 | assert(written == dlen); 270 | 271 | val = New(dst, dlen).ToLocalChecked(); 272 | delete[] dst; 273 | break; 274 | } 275 | 276 | case UCS2: { 277 | const uint16_t* data = reinterpret_cast(buf); 278 | val = New(data, buflen / 2).ToLocalChecked(); 279 | break; 280 | } 281 | 282 | case HEX: { 283 | size_t dlen = buflen * 2; 284 | char* dst = new char[dlen]; 285 | size_t written = hex_encode(buf, buflen, dst, dlen); 286 | assert(written == dlen); 287 | 288 | val = New(dst, dlen).ToLocalChecked(); 289 | delete[] dst; 290 | break; 291 | } 292 | 293 | default: 294 | assert(0 && "unknown encoding"); 295 | break; 296 | } 297 | 298 | return val; 299 | } 300 | 301 | #undef base64_encoded_size 302 | 303 | } // end of namespace imp 304 | 305 | #endif // NAN_STRING_BYTES_H_ 306 | -------------------------------------------------------------------------------- /node_modules/nan/nan_typedarray_contents.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * NAN - Native Abstractions for Node.js 3 | * 4 | * Copyright (c) 2018 NAN contributors 5 | * 6 | * MIT License 7 | ********************************************************************/ 8 | 9 | #ifndef NAN_TYPEDARRAY_CONTENTS_H_ 10 | #define NAN_TYPEDARRAY_CONTENTS_H_ 11 | 12 | template 13 | class TypedArrayContents { 14 | public: 15 | inline explicit TypedArrayContents(v8::Local from) : 16 | length_(0), data_(NULL) { 17 | HandleScope scope; 18 | 19 | size_t length = 0; 20 | void* data = NULL; 21 | 22 | #if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \ 23 | (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3)) 24 | 25 | if (from->IsArrayBufferView()) { 26 | v8::Local array = 27 | v8::Local::Cast(from); 28 | 29 | const size_t byte_length = array->ByteLength(); 30 | const ptrdiff_t byte_offset = array->ByteOffset(); 31 | v8::Local buffer = array->Buffer(); 32 | 33 | length = byte_length / sizeof(T); 34 | data = static_cast(buffer->GetContents().Data()) + byte_offset; 35 | } 36 | 37 | #else 38 | 39 | if (from->IsObject() && !from->IsNull()) { 40 | v8::Local array = v8::Local::Cast(from); 41 | 42 | MaybeLocal buffer = Get(array, 43 | New("buffer").ToLocalChecked()); 44 | MaybeLocal byte_length = Get(array, 45 | New("byteLength").ToLocalChecked()); 46 | MaybeLocal byte_offset = Get(array, 47 | New("byteOffset").ToLocalChecked()); 48 | 49 | if (!buffer.IsEmpty() && 50 | !byte_length.IsEmpty() && byte_length.ToLocalChecked()->IsUint32() && 51 | !byte_offset.IsEmpty() && byte_offset.ToLocalChecked()->IsUint32()) { 52 | data = array->GetIndexedPropertiesExternalArrayData(); 53 | if(data) { 54 | length = byte_length.ToLocalChecked()->Uint32Value() / sizeof(T); 55 | } 56 | } 57 | } 58 | 59 | #endif 60 | 61 | #if defined(_MSC_VER) && _MSC_VER >= 1900 || __cplusplus >= 201103L 62 | assert(reinterpret_cast(data) % alignof (T) == 0); 63 | #elif defined(_MSC_VER) && _MSC_VER >= 1600 || defined(__GNUC__) 64 | assert(reinterpret_cast(data) % __alignof(T) == 0); 65 | #else 66 | assert(reinterpret_cast(data) % sizeof (T) == 0); 67 | #endif 68 | 69 | length_ = length; 70 | data_ = static_cast(data); 71 | } 72 | 73 | inline size_t length() const { return length_; } 74 | inline T* operator*() { return data_; } 75 | inline const T* operator*() const { return data_; } 76 | 77 | private: 78 | NAN_DISALLOW_ASSIGN_COPY_MOVE(TypedArrayContents) 79 | 80 | //Disable heap allocation 81 | void *operator new(size_t size); 82 | void operator delete(void *, size_t) { 83 | abort(); 84 | } 85 | 86 | size_t length_; 87 | T* data_; 88 | }; 89 | 90 | #endif // NAN_TYPEDARRAY_CONTENTS_H_ 91 | -------------------------------------------------------------------------------- /node_modules/nan/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nan", 3 | "version": "2.10.0", 4 | "description": "Native Abstractions for Node.js: C++ header for Node 0.8 -> 9 compatibility", 5 | "main": "include_dirs.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git://github.com/nodejs/nan.git" 9 | }, 10 | "scripts": { 11 | "test": "tap --gc --stderr test/js/*-test.js", 12 | "rebuild-tests": "node-gyp rebuild --msvs_version=2015 --directory test", 13 | "docs": "doc/.build.sh" 14 | }, 15 | "contributors": [ 16 | { 17 | "name": "Rod Vagg", 18 | "email": "r@va.gg", 19 | "url": "https://github.com/rvagg" 20 | }, 21 | { 22 | "name": "Benjamin Byholm", 23 | "email": "bbyholm@abo.fi", 24 | "url": "https://github.com/kkoopa/" 25 | }, 26 | { 27 | "name": "Trevor Norris", 28 | "email": "trev.norris@gmail.com", 29 | "url": "https://github.com/trevnorris" 30 | }, 31 | { 32 | "name": "Nathan Rajlich", 33 | "email": "nathan@tootallnate.net", 34 | "url": "https://github.com/TooTallNate" 35 | }, 36 | { 37 | "name": "Brett Lawson", 38 | "email": "brett19@gmail.com", 39 | "url": "https://github.com/brett19" 40 | }, 41 | { 42 | "name": "Ben Noordhuis", 43 | "email": "info@bnoordhuis.nl", 44 | "url": "https://github.com/bnoordhuis" 45 | }, 46 | { 47 | "name": "David Siegel", 48 | "email": "david@artcom.de", 49 | "url": "https://github.com/agnat" 50 | }, 51 | { 52 | "name": "Michael Ira Krufky", 53 | "email": "mkrufky@gmail.com", 54 | "url": "https://github.com/mkrufky" 55 | } 56 | ], 57 | "devDependencies": { 58 | "bindings": "~1.2.1", 59 | "commander": "^2.8.1", 60 | "glob": "^5.0.14", 61 | "request": "=2.81.0", 62 | "node-gyp": "~3.6.2", 63 | "readable-stream": "^2.1.4", 64 | "tap": "~0.7.1", 65 | "xtend": "~4.0.0" 66 | }, 67 | "license": "MIT", 68 | "bugs": { 69 | "url": "https://github.com/nodejs/nan/issues" 70 | }, 71 | "homepage": "https://github.com/nodejs/nan#readme", 72 | "_id": "nan@2.10.0", 73 | "_npmVersion": "5.6.0", 74 | "_nodeVersion": "9.6.0", 75 | "_npmUser": { 76 | "name": "kkoopa", 77 | "email": "bbyholm@abo.fi" 78 | }, 79 | "dist": { 80 | "integrity": "sha512-bAdJv7fBLhWC+/Bls0Oza+mvTaNQtP+1RyhhhvD95pgUJz6XM5IzgmxOkItJ9tkoCiplvAnXI1tNmmUD/eScyA==", 81 | "shasum": "96d0cd610ebd58d4b4de9cc0c6828cda99c7548f", 82 | "tarball": "https://registry.npmjs.org/nan/-/nan-2.10.0.tgz", 83 | "fileCount": 46, 84 | "unpackedSize": 409953 85 | }, 86 | "maintainers": [ 87 | { 88 | "name": "kkoopa", 89 | "email": "bbyholm@abo.fi" 90 | }, 91 | { 92 | "name": "rvagg", 93 | "email": "rod@vagg.org" 94 | } 95 | ], 96 | "directories": {}, 97 | "_npmOperationalInternal": { 98 | "host": "s3://npm-registry-packages", 99 | "tmp": "tmp/nan_2.10.0_1521216708687_0.31611161513830033" 100 | }, 101 | "_shasum": "96d0cd610ebd58d4b4de9cc0c6828cda99c7548f", 102 | "_resolved": "https://registry.npmjs.org/nan/-/nan-2.10.0.tgz", 103 | "_from": "nan@>=2.0.0 <3.0.0", 104 | "readme": "ERROR: No README data found!" 105 | } 106 | -------------------------------------------------------------------------------- /node_modules/nan/tools/README.md: -------------------------------------------------------------------------------- 1 | 1to2 naively converts source code files from NAN 1 to NAN 2. There will be erroneous conversions, 2 | false positives and missed opportunities. The input files are rewritten in place. Make sure that 3 | you have backups. You will have to manually review the changes afterwards and do some touchups. 4 | 5 | ```sh 6 | $ tools/1to2.js 7 | 8 | Usage: 1to2 [options] 9 | 10 | Options: 11 | 12 | -h, --help output usage information 13 | -V, --version output the version number 14 | ``` 15 | -------------------------------------------------------------------------------- /node_modules/nan/tools/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "1to2", 3 | "version": "1.0.0", 4 | "description": "NAN 1 -> 2 Migration Script", 5 | "main": "1to2.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git://github.com/nodejs/nan.git" 9 | }, 10 | "contributors": [ 11 | "Benjamin Byholm (https://github.com/kkoopa/)", 12 | "Mathias Küsel (https://github.com/mathiask88/)" 13 | ], 14 | "dependencies": { 15 | "glob": "~5.0.10", 16 | "commander": "~2.8.1" 17 | }, 18 | "license": "MIT" 19 | } 20 | -------------------------------------------------------------------------------- /oneWayFunction.c: -------------------------------------------------------------------------------- 1 | #include "oneWayFunction.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #ifndef SYS_OS_MAC 9 | #include 10 | #endif 11 | 12 | #include "my_time.h" 13 | #include "common.h" 14 | 15 | // OpenSSL Library 16 | #include "sha1.h" 17 | #include "sha256.h" 18 | #include "sha512.h" 19 | #include "sha3_256.h" 20 | #include "whirlpool.h" 21 | #include "ripemd160.h" 22 | #include "blake2s256.h" 23 | #include "aes128.h" 24 | #include "des.h" 25 | #include "crc32.h" 26 | #include "hmac_md5.h" 27 | #include "rc4.h" 28 | #include "camellia128.h" 29 | 30 | // JTR source code 31 | #include "gost.h" 32 | #include "haval5_256.h" 33 | #include "skein512_256.h" 34 | 35 | OneWayFunctionInfor funcInfor[FUNCTION_NUM] = { 36 | {"SHA3-256", sha3_256}, 37 | {"SHA1", sha1}, 38 | {"SHA256", sha256}, 39 | {"SHA512", sha512}, 40 | {"Whirlpool", whirlpool}, 41 | {"RIPEMD-160", ripemd160}, 42 | {"BLAKE2s(256bits)", blake2s256}, 43 | {"AES(128bits)", aes128}, 44 | {"DES", des}, 45 | {"RC4", rc4}, 46 | {"Camellia(128bits)", camellia128}, 47 | {"CRC32", hello_crc32}, 48 | {"HMAC(MD5)", hmac_md5}, 49 | {"GOST R 34.11-94", gost}, 50 | {"HAVAL-256/5", haval5_256}, 51 | {"Skein-512(256bits)", skein512_256} 52 | }; 53 | 54 | void initOneWayFunction() { 55 | gost_init_table(); 56 | CRC32_Table_Init(); 57 | } 58 | 59 | void testOneWayFunction(const char *mess, const int64_t iterNum) { 60 | /* 61 | int64_t j; 62 | uint32_t messLen = (uint32_t)strlen(mess); 63 | 64 | uint8_t input[INPUT_LEN], output[FUNCTION_NUM][OUTPUT_LEN]; 65 | memset(input, 0, INPUT_LEN*sizeof(uint8_t)); 66 | memcpy(input, mess, messLen*sizeof(char)); 67 | 68 | printf("**************************** Correctness test (One way function) ****************************\n"); 69 | printf("Test message: %s\n", mess); 70 | for (int i = 0; i < FUNCTION_NUM; ++i) { 71 | printf("%02d ", i); 72 | funcInfor[i].func(input, messLen, output[i]); 73 | view_data_u8(funcInfor[i].funcName, output[i], OUTPUT_LEN); 74 | } 75 | printf("*********************************************************************************************\n"); 76 | 77 | printf("************************************************* Performance test (One way function) *************************************************\n"); 78 | uint8_t *result = (uint8_t *)malloc(iterNum * OUTPUT_LEN * sizeof(uint8_t)); 79 | assert(NULL != result); 80 | memset(result, 0, iterNum * OUTPUT_LEN * sizeof(uint8_t)); 81 | 82 | uint32_t threadNumArr[] = {1, 4, 8, 12, 16, 20, 24, 32, 48, 64}; 83 | uint32_t threadNumTypes = sizeof(threadNumArr) / sizeof(uint32_t); 84 | printf(" %-18s", "Algorithm"); 85 | for (uint32_t ix = 0; ix < threadNumTypes; ++ix) 86 | printf("%12d", threadNumArr[ix]); 87 | printf("\n"); 88 | 89 | for (int i = 0; i < FUNCTION_NUM; ++i) { 90 | printf("%02d %-18s\t", i, funcInfor[i].funcName); 91 | for (uint32_t ix = 0; ix < threadNumTypes; ++ix) { 92 | omp_set_num_threads(threadNumArr[ix]); 93 | double startTime = get_wall_time(); 94 | if (threadNumArr[ix] == 1) { 95 | for (j = 0; j < iterNum; ++j) { 96 | funcInfor[i].func(input, messLen, result + j * OUTPUT_LEN); 97 | } 98 | } else { 99 | #pragma omp parallel for firstprivate(input), private(j) shared(result) 100 | for (j = 0; j < iterNum; ++j) { 101 | funcInfor[i].func(input, messLen, result + j * OUTPUT_LEN); 102 | } 103 | } 104 | double endTime = get_wall_time(); 105 | double costTime = endTime - startTime; 106 | printf("%5.0f Kps ", iterNum / 1000 / costTime); fflush(stdout); 107 | 108 | // Check result 109 | for (j = 0; j < iterNum; j += 1) { 110 | if (memcmp(output[i], result + j * OUTPUT_LEN, OUTPUT_LEN)) { 111 | printf("Thread num: %u, j: %ld\n", threadNumArr[ix], j); 112 | view_data_u8("output", output[i], OUTPUT_LEN); 113 | view_data_u8("result", result + j * OUTPUT_LEN, OUTPUT_LEN); 114 | abort(); 115 | } 116 | } 117 | } 118 | printf("\n"); 119 | } 120 | if (NULL != result) { 121 | free(result); 122 | result = NULL; 123 | } 124 | */ 125 | printf("***************************************************************************************************************************************\n"); 126 | } 127 | -------------------------------------------------------------------------------- /oneWayFunction.h: -------------------------------------------------------------------------------- 1 | #ifndef ONE_WAY_FUNCTION_H 2 | #define ONE_WAY_FUNCTION_H 3 | 4 | #include 5 | 6 | typedef void (*OneWayFunction)(uint8_t *, uint32_t, uint8_t *); 7 | 8 | typedef struct { 9 | const char *funcName; 10 | OneWayFunction func; 11 | } OneWayFunctionInfor; 12 | 13 | #define FUNCTION_NUM 16 14 | 15 | extern OneWayFunctionInfor funcInfor[FUNCTION_NUM]; 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | void initOneWayFunction(); 22 | void testOneWayFunction(const char *mess, const int64_t iterNum); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-multi-hashing", 3 | "version": "0.1.0", 4 | "main": "multihashing", 5 | "author": { 6 | "name": "Jackchen" 7 | }, 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/UlordChain/node-multi-hashing.git" 11 | }, 12 | "dependencies": { 13 | "bindings": "*", 14 | "nan": "^2.0.0" 15 | }, 16 | "keywords": [ 17 | "cryptohello", 18 | "scrypt", 19 | "scryptjane", 20 | "script-n", 21 | "quark", 22 | "keccak_hash", 23 | "skein", 24 | "bcrypt", 25 | "keccak", 26 | "blake", 27 | "shavite", 28 | "fugue", 29 | "yescrypt", 30 | "sha1", 31 | "neoscrypt", 32 | "decrypt" 33 | ], 34 | "scripts": { 35 | "install": "node-gyp rebuild" 36 | }, 37 | "gypfile": true, 38 | "readmeFilename": "README.md", 39 | "description": "node-multi-hashing", 40 | "bugs": { 41 | "url": "https://github.com/UlordChain/node-multi-hashing/issues" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /rc4.c: -------------------------------------------------------------------------------- 1 | #include "rc4.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "common.h" 12 | 13 | /* 14 | * 功能:单向函数 RC4 15 | * 输入:1. input :输入消息 16 | * 2. output:输出结果 17 | */ 18 | void rc4(uint8_t *input, uint32_t inputLen, uint8_t *output) { 19 | /** 20 | * $hash[0:31] = sha256($input) 21 | * $hash2[0:15] = md5($hash[0:31]) 22 | * $key = RC4_set_key($hash2[0:15]) 23 | * $output[0:31] = RC4($key, $hash[0:31]) 24 | **/ 25 | uint8_t sha256Digest[SHA256_DIGEST_LENGTH]; 26 | 27 | SHA256_CTX sha256_ctx; 28 | SHA256_Init(&sha256_ctx); 29 | SHA256_Update(&sha256_ctx, input, inputLen); 30 | SHA256_Final(sha256Digest, &sha256_ctx); 31 | 32 | uint8_t md5Digest[MD5_DIGEST_LENGTH]; 33 | 34 | MD5_CTX md5_ctx; 35 | MD5_Init(&md5_ctx); 36 | MD5_Update(&md5_ctx, sha256Digest, SHA256_DIGEST_LENGTH); 37 | MD5_Final(md5Digest, &md5_ctx); 38 | 39 | RC4_KEY akey; 40 | RC4_set_key(&akey, MD5_DIGEST_LENGTH, md5Digest); 41 | uint8_t result[SHA256_DIGEST_LENGTH]; 42 | RC4(&akey, SHA256_DIGEST_LENGTH, sha256Digest, result); 43 | 44 | memcpy(output, result, OUTPUT_LEN*sizeof(uint8_t)); 45 | } 46 | -------------------------------------------------------------------------------- /rc4.h: -------------------------------------------------------------------------------- 1 | #ifndef RC4_H 2 | #define RC4_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | void rc4(uint8_t *input, uint32_t inputLen, uint8_t *output) ; 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif -------------------------------------------------------------------------------- /ripemd160.c: -------------------------------------------------------------------------------- 1 | #include "ripemd160.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "common.h" 8 | 9 | /* 10 | * 功能:单向函数 RIPE-MD160 11 | * 输入:1. input :输入消息 12 | * 2. output:输出结果 13 | */ 14 | void ripemd160(uint8_t *input, uint32_t inputLen, uint8_t *output) { 15 | uint8_t result[(RIPEMD160_DIGEST_LENGTH) << 1]; 16 | 17 | RIPEMD160_CTX ctx; 18 | RIPEMD160_Init(&ctx); 19 | RIPEMD160_Update(&ctx, input, inputLen); 20 | RIPEMD160_Final(result, &ctx); 21 | 22 | uint8_t inputStr[INPUT_LEN]; 23 | for(uint32_t i = 0; i < inputLen; ++i) 24 | inputStr[i] = ~(input[i]); 25 | RIPEMD160_Init(&ctx); 26 | RIPEMD160_Update(&ctx, inputStr, inputLen); 27 | RIPEMD160_Final(result + RIPEMD160_DIGEST_LENGTH, &ctx); 28 | 29 | reduce_bit(result, (RIPEMD160_DIGEST_LENGTH) << 1, output, 256); 30 | } 31 | -------------------------------------------------------------------------------- /ripemd160.h: -------------------------------------------------------------------------------- 1 | #ifndef RIPEMD160_H 2 | #define RIPEMD160_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /* 11 | * 功能:单向函数 RipeMD160 12 | * 输入:1. input :输入消息 13 | * 2. output:输出结果 14 | */ 15 | void ripemd160(uint8_t *input, uint32_t inputLen, uint8_t *output); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | #endif -------------------------------------------------------------------------------- /sha1.c: -------------------------------------------------------------------------------- 1 | #include "sha1.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "common.h" 8 | 9 | /* 10 | * 功能:单向函数 SHA1 11 | * 输入:1. input :输入消息 12 | * 2. output:输出结果 13 | */ 14 | void sha1(uint8_t *input, uint32_t inputLen, uint8_t *output) { 15 | uint32_t i; 16 | uint8_t result[(SHA_DIGEST_LENGTH) << 1]; 17 | 18 | SHA_CTX ctx; 19 | SHA1_Init(&ctx); 20 | SHA1_Update(&ctx, input, inputLen); 21 | SHA1_Final(result, &ctx); 22 | 23 | uint8_t inputStr[INPUT_LEN]; 24 | for(i = 0; i < inputLen; ++i) 25 | inputStr[i] = ~(input[i]); 26 | SHA1_Init(&ctx); 27 | SHA1_Update(&ctx, inputStr, inputLen); 28 | SHA1_Final(result + SHA_DIGEST_LENGTH, &ctx); 29 | 30 | reduce_bit(result, (SHA_DIGEST_LENGTH) << 1, output, 256); 31 | } 32 | -------------------------------------------------------------------------------- /sha1.h: -------------------------------------------------------------------------------- 1 | #ifndef SHA1_H 2 | #define SHA1_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /* 11 | * 功能:单向函数 SHA1 12 | * 输入:1. input :输入消息 13 | * 2. output:输出结果 14 | */ 15 | void sha1(uint8_t *input, uint32_t inputLen, uint8_t *output); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /sha256.c: -------------------------------------------------------------------------------- 1 | #include "sha256.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "common.h" 8 | 9 | /* 10 | * 功能:单向函数 SHA256 11 | * 输入:1. input :输入消息 12 | * 2. output:输出结果 13 | */ 14 | void sha256(uint8_t *input, uint32_t inputLen, uint8_t *output) { 15 | uint8_t result[SHA256_DIGEST_LENGTH]; 16 | 17 | SHA256_CTX ctx; 18 | SHA256_Init(&ctx); 19 | SHA256_Update(&ctx, input, inputLen); 20 | SHA256_Final(result, &ctx); 21 | 22 | memcpy(output, result, OUTPUT_LEN*sizeof(uint8_t)); 23 | } -------------------------------------------------------------------------------- /sha256.h: -------------------------------------------------------------------------------- 1 | #ifndef SHA256_H 2 | #define SHA256_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /* 11 | * 功能:单向函数 SHA256 12 | * 输入:1. input :输入消息 13 | * 2. output:输出结果 14 | */ 15 | void sha256(uint8_t *input, uint32_t inputLen, uint8_t *output); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | 22 | #endif -------------------------------------------------------------------------------- /sha3_256.c: -------------------------------------------------------------------------------- 1 | #include "sha3_256.h" 2 | 3 | #include 4 | #include 5 | 6 | #include "keccak1600.h" 7 | #include "common.h" 8 | 9 | // SHA3-256 10 | void sha3_256(uint8_t *input, uint32_t inputLen, uint8_t *output) { 11 | unsigned char result[OUTPUT_LEN]; 12 | 13 | KECCAK1600_CTX ctx; 14 | sha3_init(&ctx, ((1600-512)/8), 256/8); 15 | sha3_update(&ctx, input, inputLen); 16 | sha3_final(&ctx, result); 17 | 18 | memcpy(output, result, OUTPUT_LEN*sizeof(uint8_t)); 19 | } 20 | -------------------------------------------------------------------------------- /sha3_256.h: -------------------------------------------------------------------------------- 1 | #ifndef SHA3_256_H 2 | #define SHA3_256_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /* 11 | * 功能:单向函数 SHA3-256 12 | * 输入:1. input :输入消息 13 | * 2. output:输出结果 14 | */ 15 | void sha3_256Init(); 16 | void sha3_256(uint8_t *input, uint32_t inputLen, uint8_t *output); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | 23 | #endif -------------------------------------------------------------------------------- /sha512.c: -------------------------------------------------------------------------------- 1 | #include "sha512.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "common.h" 8 | 9 | /* 10 | * 功能:单向函数 SHA512 11 | * 输入:1. input :输入消息 12 | * 2. output:输出结果 13 | */ 14 | void sha512(uint8_t *input, uint32_t inputLen, uint8_t *output) { 15 | uint8_t result[SHA512_DIGEST_LENGTH]; 16 | 17 | SHA512_CTX ctx; 18 | SHA512_Init(&ctx); 19 | SHA512_Update(&ctx, input, inputLen); 20 | SHA512_Final(result, &ctx); 21 | 22 | reduce_bit(result, SHA512_DIGEST_LENGTH, output, 256); 23 | } -------------------------------------------------------------------------------- /sha512.h: -------------------------------------------------------------------------------- 1 | #ifndef SHA512_H 2 | #define SHA512_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /* 11 | * 功能:单向函数 SHA512 12 | * 输入:1. input :输入消息 13 | * 2. output:输出结果 14 | */ 15 | extern void sha512(uint8_t *input, uint32_t inputLen, uint8_t *output); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | 22 | #endif -------------------------------------------------------------------------------- /skein512_256.c: -------------------------------------------------------------------------------- 1 | #include "skein512_256.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "common.h" 8 | #include "jtr_sph_skein.h" 9 | 10 | #define SKEIN512_256_BINARY_SIZE 32 11 | 12 | void skein512_256(uint8_t *input, uint32_t inputLen, uint8_t *output) { 13 | uint8_t result[SKEIN512_256_BINARY_SIZE]; 14 | 15 | sph_skein256_context ctx; 16 | sph_skein256_init(&ctx); 17 | sph_skein256(&ctx, input, inputLen); 18 | sph_skein256_close(&ctx, result); 19 | 20 | memcpy(output, result, OUTPUT_LEN*sizeof(uint8_t)); 21 | } 22 | -------------------------------------------------------------------------------- /skein512_256.h: -------------------------------------------------------------------------------- 1 | #ifndef SKEIN512_256_H 2 | #define SKEIN512_256_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /* 11 | * 功能:单向函数 Skein-512(256bits) 12 | * 输入:1. input :输入消息 13 | * 2. output:输出结果 14 | */ 15 | void skein512_256(uint8_t *input, uint32_t inputLen, uint8_t *output); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /whirlpool.c: -------------------------------------------------------------------------------- 1 | #include "whirlpool.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "common.h" 8 | 9 | /* 10 | * 功能:单向函数 Whirlpool 11 | * 输入:1. input :输入消息 12 | * 2. output:输出结果 13 | */ 14 | void whirlpool(uint8_t *input, uint32_t inputLen, uint8_t *output) { 15 | uint8_t result[WHIRLPOOL_DIGEST_LENGTH]; 16 | 17 | WHIRLPOOL_CTX ctx; 18 | WHIRLPOOL_Init(&ctx); 19 | WHIRLPOOL_Update(&ctx, input, inputLen); 20 | WHIRLPOOL_Final(result, &ctx); 21 | 22 | reduce_bit(result, WHIRLPOOL_DIGEST_LENGTH, output, 256); 23 | } -------------------------------------------------------------------------------- /whirlpool.h: -------------------------------------------------------------------------------- 1 | #ifndef WHIRLPOOL_H 2 | #define WHIRLPOOL_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /* 11 | * 功能:单向函数 Whirlpool 12 | * 输入:1. input :输入消息 13 | * 2. output:输出结果 14 | */ 15 | void whirlpool(uint8_t *input, uint32_t inputLen, uint8_t *output); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | #endif --------------------------------------------------------------------------------