@noble/hashes
Advanced tools
Comparing version 1.1.2 to 1.1.3
24
eskdf.js
@@ -33,13 +33,2 @@ "use strict"; | ||
} | ||
function bytesToNumber(bytes) { | ||
return BigInt('0x' + (0, utils_js_1.bytesToHex)(bytes)); | ||
} | ||
function numberToBytes(num, byteLength) { | ||
if (num < BigInt(0)) | ||
throw new Error('expected positive number'); | ||
const res = (0, utils_js_1.hexToBytes)(num.toString(16).padStart(byteLength * 2, '0')); | ||
if (res.length !== byteLength) | ||
throw new Error('invalid length of result key'); | ||
return res; | ||
} | ||
function strHasLength(str, min, max) { | ||
@@ -125,6 +114,13 @@ return typeof str === 'string' && str.length >= min && str.length <= max; | ||
function modReduceKey(key, modulus) { | ||
const num = bytesToNumber(key); | ||
const _1 = BigInt(1); | ||
const reduced = (num % (modulus - _1)) + _1; | ||
return numberToBytes(reduced, key.length - 8); // .reverse() for LE | ||
const num = BigInt('0x' + (0, utils_js_1.bytesToHex)(key)); // check for ui8a, then bytesToNumber() | ||
const res = (num % (modulus - _1)) + _1; // Remove 0 from output | ||
if (res < _1) | ||
throw new Error('expected positive number'); // Guard against bad values | ||
const len = key.length - 8; // FIPS requires 64 more bits = 8 bytes | ||
const hex = res.toString(16).padStart(len * 2, '0'); // numberToHex() | ||
const bytes = (0, utils_js_1.hexToBytes)(hex); | ||
if (bytes.length !== len) | ||
throw new Error('invalid length of result key'); | ||
return bytes; | ||
} | ||
@@ -131,0 +127,0 @@ /** |
@@ -28,13 +28,2 @@ import { bytes as assertBytes } from './_assert.js'; | ||
} | ||
function bytesToNumber(bytes) { | ||
return BigInt('0x' + bytesToHex(bytes)); | ||
} | ||
function numberToBytes(num, byteLength) { | ||
if (num < BigInt(0)) | ||
throw new Error('expected positive number'); | ||
const res = hexToBytes(num.toString(16).padStart(byteLength * 2, '0')); | ||
if (res.length !== byteLength) | ||
throw new Error('invalid length of result key'); | ||
return res; | ||
} | ||
function strHasLength(str, min, max) { | ||
@@ -119,6 +108,13 @@ return typeof str === 'string' && str.length >= min && str.length <= max; | ||
function modReduceKey(key, modulus) { | ||
const num = bytesToNumber(key); | ||
const _1 = BigInt(1); | ||
const reduced = (num % (modulus - _1)) + _1; | ||
return numberToBytes(reduced, key.length - 8); // .reverse() for LE | ||
const num = BigInt('0x' + bytesToHex(key)); // check for ui8a, then bytesToNumber() | ||
const res = (num % (modulus - _1)) + _1; // Remove 0 from output | ||
if (res < _1) | ||
throw new Error('expected positive number'); // Guard against bad values | ||
const len = key.length - 8; // FIPS requires 64 more bits = 8 bytes | ||
const hex = res.toString(16).padStart(len * 2, '0'); // numberToHex() | ||
const bytes = hexToBytes(hex); | ||
if (bytes.length !== len) | ||
throw new Error('invalid length of result key'); | ||
return bytes; | ||
} | ||
@@ -125,0 +121,0 @@ /** |
@@ -12,9 +12,10 @@ import assert from './_assert.js'; | ||
this.iHash = hash.create(); | ||
if (!(this.iHash instanceof Hash)) | ||
if (typeof this.iHash.update !== 'function') | ||
throw new TypeError('Expected instance of class which extends utils.Hash'); | ||
const blockLen = (this.blockLen = this.iHash.blockLen); | ||
this.blockLen = this.iHash.blockLen; | ||
this.outputLen = this.iHash.outputLen; | ||
const blockLen = this.blockLen; | ||
const pad = new Uint8Array(blockLen); | ||
// blockLen can be bigger than outputLen | ||
pad.set(key.length > this.iHash.blockLen ? hash.create().update(key).digest() : key); | ||
pad.set(key.length > blockLen ? hash.create().update(key).digest() : key); | ||
for (let i = 0; i < pad.length; i++) | ||
@@ -21,0 +22,0 @@ pad[i] ^= 0x36; |
@@ -15,9 +15,10 @@ "use strict"; | ||
this.iHash = hash.create(); | ||
if (!(this.iHash instanceof utils_js_1.Hash)) | ||
if (typeof this.iHash.update !== 'function') | ||
throw new TypeError('Expected instance of class which extends utils.Hash'); | ||
const blockLen = (this.blockLen = this.iHash.blockLen); | ||
this.blockLen = this.iHash.blockLen; | ||
this.outputLen = this.iHash.outputLen; | ||
const blockLen = this.blockLen; | ||
const pad = new Uint8Array(blockLen); | ||
// blockLen can be bigger than outputLen | ||
pad.set(key.length > this.iHash.blockLen ? hash.create().update(key).digest() : key); | ||
pad.set(key.length > blockLen ? hash.create().update(key).digest() : key); | ||
for (let i = 0; i < pad.length; i++) | ||
@@ -24,0 +25,0 @@ pad[i] ^= 0x36; |
{ | ||
"name": "@noble/hashes", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "Audited & minimal 0-dependency JS implementation of SHA2, SHA3, RIPEMD, BLAKE2/3, HMAC, HKDF, PBKDF2, Scrypt", | ||
@@ -16,4 +16,5 @@ "files": [ | ||
"bench:install": "cd test/benchmark && npm install && cd ../../", | ||
"build": "tsc -d && tsc -p tsconfig.esm.json", | ||
"build": "tsc && tsc -p tsconfig.esm.json", | ||
"build:release": "rollup -c rollup.config.js", | ||
"build:clean": "rm *.d.ts *.js", | ||
"lint": "prettier --check 'src/**/*.{js,ts}' 'test/**/*.{js,ts}'", | ||
@@ -38,4 +39,4 @@ "format": "prettier --write 'src/**/*.{js,ts}' 'test/**/*.{js,ts}'", | ||
"@rollup/plugin-node-resolve": "13.3.0", | ||
"micro-bmark": "^0.1.3", | ||
"micro-should": "^0.2.0", | ||
"micro-bmark": "0.2.0", | ||
"micro-should": "0.2.0", | ||
"prettier": "2.6.2", | ||
@@ -46,3 +47,4 @@ "rollup": "2.75.5", | ||
"exports": { | ||
"./index": { | ||
".": { | ||
"types": "./index.d.ts", | ||
"import": "./esm/index.js", | ||
@@ -52,2 +54,3 @@ "default": "./index.js" | ||
"./crypto": { | ||
"types": "./crypto.d.ts", | ||
"browser": { | ||
@@ -61,2 +64,3 @@ "import": "./esm/cryptoBrowser.js", | ||
"./_assert": { | ||
"types": "./_assert.d.ts", | ||
"import": "./esm/_assert.js", | ||
@@ -66,2 +70,3 @@ "default": "./_assert.js" | ||
"./_sha2": { | ||
"types": "./_sha2.d.ts", | ||
"import": "./esm/_sha2.js", | ||
@@ -71,76 +76,76 @@ "default": "./_sha2.js" | ||
"./blake2b": { | ||
"types": "./blake2b.d.ts", | ||
"import": "./esm/blake2b.js", | ||
"default": "./blake2b.js" | ||
}, | ||
"./blake2b.d.ts": "blake2b.d.ts", | ||
"./blake2s": { | ||
"types": "./blake2s.d.ts", | ||
"import": "./esm/blake2s.js", | ||
"default": "./blake2s.js" | ||
}, | ||
"./blake2s.d.ts": "blake2s.d.ts", | ||
"./blake3": { | ||
"types": "./blake3.d.ts", | ||
"import": "./esm/blake3.js", | ||
"default": "./blake3.js" | ||
}, | ||
"./blake3.d.ts": "blake3.d.ts", | ||
"./eskdf": { | ||
"types": "./eskdf.d.ts", | ||
"import": "./esm/eskdf.js", | ||
"default": "./eskdf.js" | ||
}, | ||
"./eskdf.d.ts": "eskdf.d.ts", | ||
"./hkdf": { | ||
"types": "./hkdf.d.ts", | ||
"import": "./esm/hkdf.js", | ||
"default": "./hkdf.js" | ||
}, | ||
"./hkdf.d.ts": "hkdf.d.ts", | ||
"./hmac": { | ||
"types": "./hmac.d.ts", | ||
"import": "./esm/hmac.js", | ||
"default": "./hmac.js" | ||
}, | ||
"./hmac.d.ts": "hmac.d.ts", | ||
"./pbkdf2": { | ||
"types": "./pbkdf2.d.ts", | ||
"import": "./esm/pbkdf2.js", | ||
"default": "./pbkdf2.js" | ||
}, | ||
"./pbkdf2.d.ts": "pbkdf2.d.ts", | ||
"./ripemd160": { | ||
"types": "./ripemd160.d.ts", | ||
"import": "./esm/ripemd160.js", | ||
"default": "./ripemd160.js" | ||
}, | ||
"./ripemd160.d.ts": "ripemd160.d.ts", | ||
"./scrypt": { | ||
"types": "./scrypt.d.ts", | ||
"import": "./esm/scrypt.js", | ||
"default": "./scrypt.js" | ||
}, | ||
"./scrypt.d.ts": "scrypt.d.ts", | ||
"./sha1": { | ||
"types": "./sha1.d.ts", | ||
"import": "./esm/sha1.js", | ||
"default": "./sha1.js" | ||
}, | ||
"./sha1.d.ts": "sha1.d.ts", | ||
"./sha3-addons": { | ||
"types": "./sha3-addons.d.ts", | ||
"import": "./esm/sha3-addons.js", | ||
"default": "./sha3-addons.js" | ||
}, | ||
"./sha3-addons.d.ts": "sha3-addons.d.ts", | ||
"./sha3": { | ||
"types": "./sha3.d.ts", | ||
"import": "./esm/sha3.js", | ||
"default": "./sha3.js" | ||
}, | ||
"./sha3.d.ts": "sha3.d.ts", | ||
"./sha256": { | ||
"types": "./sha256.d.ts", | ||
"import": "./esm/sha256.js", | ||
"default": "./sha256.js" | ||
}, | ||
"./sha256.d.ts": "sha256.d.ts", | ||
"./sha512": { | ||
"types": "./sha512.d.ts", | ||
"import": "./esm/sha512.js", | ||
"default": "./sha512.js" | ||
}, | ||
"./sha512.d.ts": "sha512.d.ts", | ||
"./utils": { | ||
"types": "./utils.d.ts", | ||
"import": "./esm/utils.js", | ||
"default": "./utils.js" | ||
}, | ||
"./utils.d.ts": "utils.d.ts" | ||
} | ||
}, | ||
@@ -147,0 +152,0 @@ "keywords": [ |
@@ -292,3 +292,3 @@ # noble-hashes ![Node CI](https://github.com/paulmillr/noble-hashes/workflows/Node%20CI/badge.svg) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) | ||
const mac1 = hmac(sha256, 'key', 'message'); | ||
const mac2 = hmac.create(sha256, Uint8Array.from([1, 2, 3])).update(Uint8Array.from([4, 5, 6]).digest(); | ||
const mac2 = hmac.create(sha256, Uint8Array.from([1, 2, 3])).update(Uint8Array.from([4, 5, 6])).digest(); | ||
``` | ||
@@ -295,0 +295,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
275396
6258