aboutsummaryrefslogtreecommitdiff
path: root/src/crypto/primitives
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-03-30 16:09:32 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-03-30 16:09:32 +0530
commitaaf950e2ad5c07d4423f9822e3a0ae9f7b8d2bdf (patch)
tree9274139660f30c4857d80044eb4ac283aac1775a /src/crypto/primitives
parent15e18440dbad55df19977a2eb7053681259afc18 (diff)
downloadwallet-core-aaf950e2ad5c07d4423f9822e3a0ae9f7b8d2bdf.tar.xz
re-format with prettier v2, fix HTML
Diffstat (limited to 'src/crypto/primitives')
-rw-r--r--src/crypto/primitives/nacl-fast.ts25
-rw-r--r--src/crypto/primitives/sha256.ts5
2 files changed, 12 insertions, 18 deletions
diff --git a/src/crypto/primitives/nacl-fast.ts b/src/crypto/primitives/nacl-fast.ts
index 66ab78162..14cf569db 100644
--- a/src/crypto/primitives/nacl-fast.ts
+++ b/src/crypto/primitives/nacl-fast.ts
@@ -5,14 +5,14 @@
// Implementation derived from TweetNaCl version 20140427.
// See for details: http://tweetnacl.cr.yp.to/
-const gf = function(init: number[] = []) {
+const gf = function (init: number[] = []) {
const r = new Float64Array(16);
if (init) for (let i = 0; i < init.length; i++) r[i] = init[i];
return r;
};
// Pluggable, initialized in high-level API below.
-let randombytes = function(x: Uint8Array, n: number): void {
+let randombytes = function (x: Uint8Array, n: number): void {
throw new Error("no PRNG");
};
@@ -2373,13 +2373,11 @@ function crypto_hash(out: Uint8Array, m: Uint8Array, n: number) {
ts64(x, n - 8, (b / 0x20000000) | 0, b << 3);
crypto_hashblocks_hl(hh, hl, x, n);
- for (let i = 0; i < 8; i++)
- ts64(out, 8 * i, hh[i], hl[i]);
+ for (let i = 0; i < 8; i++) ts64(out, 8 * i, hh[i], hl[i]);
return 0;
}
-
/**
* Incremental version of crypto_hash.
*/
@@ -2400,7 +2398,7 @@ export class HashState {
this.hh[5] = 0x9b05688c;
this.hh[6] = 0x1f83d9ab;
this.hh[7] = 0x5be0cd19;
-
+
this.hl[0] = 0xf3bcc908;
this.hl[1] = 0x84caa73b;
this.hl[2] = 0xfe94f82b;
@@ -2416,7 +2414,7 @@ export class HashState {
let i = 0;
while (i < data.length) {
const r = 128 - this.p;
- if (r > (data.length - i)) {
+ if (r > data.length - i) {
for (let j = 0; i + j < data.length; j++) {
this.next[this.p + j] = data[i + j];
}
@@ -2441,14 +2439,13 @@ export class HashState {
let b = this.total;
for (let i = 0; i < n; i++) x[i] = this.next[i];
x[n] = 128;
-
+
n = 256 - 128 * (n < 112 ? 1 : 0);
x[n - 9] = 0;
ts64(x, n - 8, (b / 0x20000000) | 0, b << 3);
crypto_hashblocks_hl(this.hh, this.hl, x, n);
-
- for (let i = 0; i < 8; i++)
- ts64(out, 8 * i, this.hh[i], this.hl[i]);
+
+ for (let i = 0; i < 8; i++) ts64(out, 8 * i, this.hh[i], this.hl[i]);
return out;
}
}
@@ -3078,7 +3075,7 @@ export function sign_ed25519_pk_to_curve25519(
return x25519_pk;
}
-(function() {
+(function () {
// Initialize PRNG if environment provides CSPRNG.
// If not, methods calling randombytes will throw.
const crypto =
@@ -3086,7 +3083,7 @@ export function sign_ed25519_pk_to_curve25519(
if (crypto && crypto.getRandomValues) {
// Browsers.
var QUOTA = 65536;
- setPRNG(function(x: Uint8Array, n: number) {
+ setPRNG(function (x: Uint8Array, n: number) {
var i,
v = new Uint8Array(n);
for (i = 0; i < n; i += QUOTA) {
@@ -3099,7 +3096,7 @@ export function sign_ed25519_pk_to_curve25519(
// Node.js.
const cr = require("crypto");
if (cr && cr.randomBytes) {
- setPRNG(function(x: Uint8Array, n: number) {
+ setPRNG(function (x: Uint8Array, n: number) {
var i,
v = cr.randomBytes(n);
for (i = 0; i < n; i++) x[i] = v[i];
diff --git a/src/crypto/primitives/sha256.ts b/src/crypto/primitives/sha256.ts
index f4f6690c7..c0f245bb3 100644
--- a/src/crypto/primitives/sha256.ts
+++ b/src/crypto/primitives/sha256.ts
@@ -339,10 +339,7 @@ export class HMAC {
constructor(key: Uint8Array) {
const pad = new Uint8Array(this.blockSize);
if (key.length > this.blockSize) {
- new HashSha256()
- .update(key)
- .finish(pad)
- .clean();
+ new HashSha256().update(key).finish(pad).clean();
} else {
for (let i = 0; i < key.length; i++) {
pad[i] = key[i];