forked from witnet/sheikah
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(file name): implement project layout defined in witnet#126
BREAKING CHANGE: everyone need to update what they are working on in order to follow the new project structure fix witnet#144
- Loading branch information
Anler Hernández Peral
committed
Jun 14, 2018
1 parent
cc20f79
commit 9119c24
Showing
73 changed files
with
183 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,3 +44,4 @@ main.js.map | |
|
||
.idea | ||
.vscode | ||
/config/tsconfig.tslint.json |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Errors } from "./errors" | ||
|
||
const assert = require("assert") | ||
const crypto = require("crypto") | ||
|
||
/** | ||
* PBKDF2 | ||
* https://github.com/stayradiated/pbkdf2-sha512 | ||
* @param {string | Buffer} key | ||
* @param {string | Buffer} salt | ||
* @param {number} iterations | ||
* @param {number} dkLen | ||
* @returns {Buffer} | ||
*/ | ||
export const pbkdf2 = | ||
(key: string | Buffer, salt: string | Buffer, iterations: number, dkLen: number) => { | ||
const hLen = 64 // SHA512 Mac length | ||
const validKeyLength = dkLen <= (Math.pow(2, 32) - 1) * hLen | ||
assert(validKeyLength, Errors.INVALID_KEY_LENGTH) | ||
|
||
const saltBuffer = (typeof salt === "string") ? Buffer.from(salt) : salt | ||
const keyBuffer = (typeof key === "string") ? Buffer.from(key) : key | ||
|
||
const DK = Buffer.alloc(dkLen) | ||
const T = Buffer.alloc(hLen) | ||
|
||
const block1 = Buffer.alloc(saltBuffer.length + 4) | ||
|
||
const l = Math.ceil(dkLen / hLen) | ||
const r = dkLen - (l - 1) * hLen | ||
|
||
saltBuffer.copy(block1, 0, 0, saltBuffer.length) | ||
for (let i = 1; i <= l; i++) { | ||
block1[saltBuffer.length + 0] = (i >> 24 & 0xFF) | ||
block1[saltBuffer.length + 1] = (i >> 16 & 0xFF) | ||
block1[saltBuffer.length + 2] = (i >> 8 & 0xFF) | ||
block1[saltBuffer.length + 3] = (i >> 0 & 0xFF) | ||
|
||
let U = crypto.createHmac("sha512", keyBuffer) | ||
.update(block1) | ||
.digest() | ||
|
||
U.copy(T, 0, 0, hLen) | ||
|
||
for (let j = 1; j < iterations; j++) { | ||
U = crypto.createHmac("sha512", keyBuffer) | ||
.update(U) | ||
.digest() | ||
|
||
for (let k = 0; k < hLen; k++) { | ||
T[k] ^= U[k] | ||
} | ||
} | ||
|
||
const destPos = (i - 1) * hLen | ||
const len = (i === l ? r : hLen) | ||
T.copy(DK, destPos, 0, len) | ||
} | ||
|
||
return DK | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "./tsconfig", | ||
"include": [ | ||
"../test/**/*.ts", | ||
"../test/**/*.tsx" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.