Add node modules and compiled JavaScript from main (#54)
Co-authored-by: Oliver King <oking3@uncc.edu>
This commit is contained in:
committed by
GitHub
parent
4a983766a0
commit
52d71d28bd
40
node_modules/jose/lib/jwa/ecdh/derive.js
generated
vendored
Normal file
40
node_modules/jose/lib/jwa/ecdh/derive.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
const { createHash } = require('crypto')
|
||||
const ecdhComputeSecret = require('./compute_secret')
|
||||
|
||||
const concat = (key, length, value) => {
|
||||
const iterations = Math.ceil(length / 32)
|
||||
let res
|
||||
|
||||
for (let iter = 1; iter <= iterations; iter++) {
|
||||
const buf = Buffer.allocUnsafe(4 + key.length + value.length)
|
||||
buf.writeUInt32BE(iter, 0)
|
||||
key.copy(buf, 4)
|
||||
value.copy(buf, 4 + key.length)
|
||||
if (!res) {
|
||||
res = createHash('sha256').update(buf).digest()
|
||||
} else {
|
||||
res = Buffer.concat([res, createHash('sha256').update(buf).digest()])
|
||||
}
|
||||
}
|
||||
|
||||
return res.slice(0, length)
|
||||
}
|
||||
|
||||
const uint32be = (value, buf = Buffer.allocUnsafe(4)) => {
|
||||
buf.writeUInt32BE(value)
|
||||
return buf
|
||||
}
|
||||
|
||||
const lengthAndInput = input => Buffer.concat([uint32be(input.length), input])
|
||||
|
||||
module.exports = (alg, keyLen, privKey, pubKey, { apu = Buffer.alloc(0), apv = Buffer.alloc(0) } = {}, computeSecret = ecdhComputeSecret) => {
|
||||
const value = Buffer.concat([
|
||||
lengthAndInput(Buffer.from(alg)),
|
||||
lengthAndInput(apu),
|
||||
lengthAndInput(apv),
|
||||
uint32be(keyLen)
|
||||
])
|
||||
|
||||
const sharedSecret = computeSecret(privKey, pubKey)
|
||||
return concat(sharedSecret, keyLen / 8, value)
|
||||
}
|
Reference in New Issue
Block a user