forked from ImAspect/SRP6-Secure-Remote-Password
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SRP6-Verifier.js
26 lines (17 loc) · 888 Bytes
/
SRP6-Verifier.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const sha1 = require('js-sha1') /* Install Module js-sha1 */
const { BigInteger } = require('jsbn') /* Install Module jsbn */
const createVerifier = (username, password, salt) => {
const N = new BigInteger("894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7", 16)
const g = new BigInteger("7", 16)
const h1 = Buffer.from(sha1.arrayBuffer(`${username}:${password}`.toUpperCase()))
const h2 = Buffer.from(sha1.arrayBuffer(Buffer.concat([salt, h1]))).reverse()
const h2bigint = new BigInteger(h2.toString("hex"), 16)
const verifierBigint = g.modPow(h2bigint, N)
let verifier = Buffer.from(verifierBigint.toByteArray()).reverse()
verifier = verifier.slice(0, 32)
if (verifier.length != 32) {
verifier = Buffer.concat([verifier], 32)
}
return verifier
}
module.exports = { createVerifier }