sha256-uint8array
Advanced tools
Comparing version 0.10.3 to 0.10.4
@@ -49,9 +49,9 @@ "use strict"; | ||
this._sp = 0; // surrogate pair | ||
if (!sharedBuffer || sharedOffset >= 8000 /* allocTotal */) { | ||
sharedBuffer = new ArrayBuffer(8000 /* allocTotal */); | ||
if (!sharedBuffer || sharedOffset >= 8000 /* N.allocTotal */) { | ||
sharedBuffer = new ArrayBuffer(8000 /* N.allocTotal */); | ||
sharedOffset = 0; | ||
} | ||
this._byte = new Uint8Array(sharedBuffer, sharedOffset, 80 /* allocBytes */); | ||
this._word = new Int32Array(sharedBuffer, sharedOffset, 20 /* allocWords */); | ||
sharedOffset += 80 /* allocBytes */; | ||
this._byte = new Uint8Array(sharedBuffer, sharedOffset, 80 /* N.allocBytes */); | ||
this._word = new Int32Array(sharedBuffer, sharedOffset, 20 /* N.allocWords */); | ||
sharedOffset += 80 /* N.allocBytes */; | ||
} | ||
@@ -69,10 +69,10 @@ update(data) { | ||
const length = data.byteLength; | ||
let blocks = (length / 64 /* inputBytes */) | 0; | ||
let blocks = (length / 64 /* N.inputBytes */) | 0; | ||
let offset = 0; | ||
// longer than 1 block | ||
if (blocks && !(byteOffset & 3) && !(this._size % 64 /* inputBytes */)) { | ||
const block = new Int32Array(data.buffer, byteOffset, blocks * 16 /* inputWords */); | ||
if (blocks && !(byteOffset & 3) && !(this._size % 64 /* N.inputBytes */)) { | ||
const block = new Int32Array(data.buffer, byteOffset, blocks * 16 /* N.inputWords */); | ||
while (blocks--) { | ||
this._int32(block, offset >> 2); | ||
offset += 64 /* inputBytes */; | ||
offset += 64 /* N.inputBytes */; | ||
} | ||
@@ -98,8 +98,8 @@ this._size += offset; | ||
while (offset < length) { | ||
const start = this._size % 64 /* inputBytes */; | ||
const start = this._size % 64 /* N.inputBytes */; | ||
let index = start; | ||
while (offset < length && index < 64 /* inputBytes */) { | ||
while (offset < length && index < 64 /* N.inputBytes */) { | ||
_byte[index++] = data[offset++]; | ||
} | ||
if (index >= 64 /* inputBytes */) { | ||
if (index >= 64 /* N.inputBytes */) { | ||
this._int32(_word); | ||
@@ -116,5 +116,5 @@ } | ||
for (let offset = 0; offset < length;) { | ||
const start = this._size % 64 /* inputBytes */; | ||
const start = this._size % 64 /* N.inputBytes */; | ||
let index = start; | ||
while (offset < length && index < 64 /* inputBytes */) { | ||
while (offset < length && index < 64 /* N.inputBytes */) { | ||
let code = text.charCodeAt(offset++) | 0; | ||
@@ -149,5 +149,5 @@ if (code < 0x80) { | ||
} | ||
if (index >= 64 /* inputBytes */) { | ||
if (index >= 64 /* N.inputBytes */) { | ||
this._int32(_word); | ||
_word[0] = _word[16 /* inputWords */]; | ||
_word[0] = _word[16 /* N.inputWords */]; | ||
} | ||
@@ -163,9 +163,9 @@ this._size += index - start; | ||
offset = offset | 0; | ||
while (i < 16 /* inputWords */) { | ||
while (i < 16 /* N.inputWords */) { | ||
W[i++] = swap32(data[offset++]); | ||
} | ||
for (i = 16 /* inputWords */; i < 64 /* workWords */; i++) { | ||
for (i = 16 /* N.inputWords */; i < 64 /* N.workWords */; i++) { | ||
W[i] = (gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16]) | 0; | ||
} | ||
for (i = 0; i < 64 /* workWords */; i++) { | ||
for (i = 0; i < 64 /* N.workWords */; i++) { | ||
const T1 = (H + sigma1(E) + ch(E, F, G) + K[i] + W[i]) | 0; | ||
@@ -193,3 +193,3 @@ const T2 = (sigma0(A) + maj(A, B, C)) | 0; | ||
const { _byte, _word } = this; | ||
let i = (this._size % 64 /* inputBytes */) | 0; | ||
let i = (this._size % 64 /* N.inputBytes */) | 0; | ||
_byte[i++] = 0x80; | ||
@@ -201,4 +201,4 @@ // pad 0 for current word | ||
i >>= 2; | ||
if (i > 14 /* highIndex */) { | ||
while (i < 16 /* inputWords */) { | ||
if (i > 14 /* N.highIndex */) { | ||
while (i < 16 /* N.inputWords */) { | ||
_word[i++] = 0; | ||
@@ -210,3 +210,3 @@ } | ||
// pad 0 for rest words | ||
while (i < 16 /* inputWords */) { | ||
while (i < 16 /* N.inputWords */) { | ||
_word[i++] = 0; | ||
@@ -219,5 +219,5 @@ } | ||
if (high32) | ||
_word[14 /* highIndex */] = swap32(high32); | ||
_word[14 /* N.highIndex */] = swap32(high32); | ||
if (low32) | ||
_word[15 /* lowIndex */] = swap32(low32); | ||
_word[15 /* N.lowIndex */] = swap32(low32); | ||
this._int32(_word); | ||
@@ -244,3 +244,3 @@ return (encoding === "hex") ? this._hex() : this._bin(); | ||
exports.Hash = Hash; | ||
const W = new Int32Array(64 /* workWords */); | ||
const W = new Int32Array(64 /* N.workWords */); | ||
let sharedBuffer; | ||
@@ -247,0 +247,0 @@ let sharedOffset = 0; |
{ | ||
"name": "sha256-uint8array", | ||
"description": "Fast SHA-256 digest hash based on Uint8Array, pure JavaScript.", | ||
"version": "0.10.3", | ||
"version": "0.10.4", | ||
"author": "Yusuke Kawasaki <u-suke@kawa.net>", | ||
@@ -13,5 +13,5 @@ "bugs": { | ||
"devDependencies": { | ||
"@aws-crypto/sha256-js": "^1.1.0", | ||
"@types/mocha": "^9.0.0", | ||
"@types/node": "^16.6.1", | ||
"@aws-crypto/sha256-js": "^3.0.0", | ||
"@types/mocha": "^10.0.1", | ||
"@types/node": "^18.14.0", | ||
"browserify": "^17.0.0", | ||
@@ -23,7 +23,7 @@ "browserify-sed": "^0.8.0", | ||
"jshashes": "^1.0.8", | ||
"jssha": "^3.2.0", | ||
"mocha": "^9.0.3", | ||
"jssha": "^3.3.0", | ||
"mocha": "^10.2.0", | ||
"sha.js": "^2.4.11", | ||
"terser": "^5.7.1", | ||
"typescript": "^4.3.5" | ||
"terser": "^5.16.4", | ||
"typescript": "^4.9.5" | ||
}, | ||
@@ -34,3 +34,4 @@ "files": [ | ||
"browser/import.js", | ||
"dist/*.js", | ||
"dist/*.min.js", | ||
"dist/*.mjs", | ||
"lib/*.js", | ||
@@ -49,2 +50,3 @@ "types/sha256-uint8array.d.ts" | ||
"main": "./lib/sha256-uint8array.js", | ||
"module": "./dist/sha256-uint8array.mjs", | ||
"repository": { | ||
@@ -55,11 +57,10 @@ "type": "git", | ||
"scripts": { | ||
"build": "./node_modules/.bin/tsc -p .", | ||
"build-browser": "make -C browser clean all", | ||
"build-test-es5": "make -C browser clean test-es5", | ||
"build": "make clean all", | ||
"fixpack": "fixpack", | ||
"mocha": "./node_modules/.bin/mocha -R spec test/*.js", | ||
"prepack": "npm run build-browser && REPEAT=1 npm test", | ||
"test": "npm run mocha" | ||
"prepack": "npm run build && npm test", | ||
"test": "REPEAT=1 make test", | ||
"test-browser": "make build/test.js && open browser/test.html" | ||
}, | ||
"type": "commonjs", | ||
"typings": "./types/sha256-uint8array.d.ts" | ||
} |
@@ -7,3 +7,2 @@ # sha256-uint8array | ||
Fast SHA-256 digest hash based on Uint8Array, pure JavaScript. | ||
@@ -14,3 +13,3 @@ | ||
```js | ||
const createHash = require("sha256-uint8array").createHash; | ||
const {createHash} = require("sha256-uint8array"); | ||
@@ -30,2 +29,8 @@ const text = ""; | ||
## ES MODULE | ||
```js | ||
import {createHash} from "sha256-uint8array"; | ||
``` | ||
## COMPATIBILITY | ||
@@ -147,3 +152,3 @@ | ||
Copyright (c) 2020-2021 Yusuke Kawasaki | ||
Copyright (c) 2020-2023 Yusuke Kawasaki | ||
@@ -150,0 +155,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
Sorry, the diff of this file is not supported yet
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
32978
8
508
163