mirror of
https://github.com/fluencelabs/js-libp2p-crypto
synced 2025-07-31 00:32:14 +00:00
first pass at stretchKey
This commit is contained in:
@@ -7,11 +7,15 @@ const crypto = require('../src')
|
||||
|
||||
describe('generateEphemeralKeyPair', () => {
|
||||
it('returns a function that generates a shared secret', () => {
|
||||
const maker = crypto.generateEphemeralKeyPair('P-256')
|
||||
const res = crypto.generateEphemeralKeyPair('P-256')
|
||||
const ourPublic = '044374add0df35706db7dade25f3959fc051d2ef5166f8a6a0aa632d0ab41cdb4d30e1a064e121ac56155235a6b8d4c5d8fe35e019f507f4e2ff1445e229d7af43'
|
||||
|
||||
expect(
|
||||
maker(ourPublic)
|
||||
res.genSharedKey(ourPublic)
|
||||
).to.have.length(32)
|
||||
|
||||
expect(
|
||||
res.key
|
||||
).to.exist
|
||||
})
|
||||
})
|
||||
|
0
test/fixtures/go-rsa.key
vendored
Normal file
0
test/fixtures/go-rsa.key
vendored
Normal file
25
test/key-stretcher.spec.js
Normal file
25
test/key-stretcher.spec.js
Normal file
@@ -0,0 +1,25 @@
|
||||
/* eslint-env mocha */
|
||||
'use strict'
|
||||
|
||||
const expect = require('chai').expect
|
||||
|
||||
const crypto = require('../src')
|
||||
|
||||
describe('keyStretcher', () => {
|
||||
describe('generate', () => {
|
||||
const ciphers = ['AES-128', 'AES-256', 'Blowfish']
|
||||
const hashes = ['SHA1', 'SHA256'/*, 'SHA512'*/]
|
||||
const res = crypto.generateEphemeralKeyPair('P-256')
|
||||
const secret = res.genSharedKey(res.key)
|
||||
|
||||
ciphers.forEach((cipher) => {
|
||||
hashes.forEach((hash) => {
|
||||
it(`${cipher} - ${hash}`, () => {
|
||||
const keys = crypto.keyStretcher(cipher, hash, secret)
|
||||
expect(keys.k1).to.exist
|
||||
expect(keys.k2).to.exist
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user