Skip to content

Commit

Permalink
change hashing library
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Petrunic <[email protected]>
  • Loading branch information
mpetrunic committed Apr 27, 2023
1 parent de40989 commit 73cc41c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
6 changes: 3 additions & 3 deletions benchmarks/benchmark.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/* eslint-disable */

import { Noise } from '../dist/src/index.js'
import { noise } from '../dist/src/index.js'
import benchmark from 'benchmark'
import { duplexPair } from 'it-pair/duplex'
import { createFromJSON } from '@libp2p/peer-id-factory'

const bench = async function () {
console.log('Initializing handshake benchmark')
const initiator = new Noise()
const initiator = noise()()
const initiatorPeer = await createFromJSON({
id: '12D3KooWH45PiqBjfnEfDfCD6TqJrpqTBJvQDwGHvjGpaWwms46D',
privKey: 'CAESYBtKXrMwawAARmLScynQUuSwi/gGSkwqDPxi15N3dqDHa4T4iWupkMe5oYGwGH3Hyfvd/QcgSTqg71oYZJadJ6prhPiJa6mQx7mhgbAYfcfJ+939ByBJOqDvWhhklp0nqg==',
pubKey: 'CAESIGuE+IlrqZDHuaGBsBh9x8n73f0HIEk6oO9aGGSWnSeq'
})
const responder = new Noise()
const responder = noise()()
const responderPeer = await createFromJSON({
id: '12D3KooWP63uzL78BRMpkQ7augMdNi1h3VBrVWZucKjyhzGVaSi1',
privKey: 'CAESYPxO3SHyfc2578hDmfkGGBY255JjiLuVavJWy+9ivlpsxSyVKf36ipyRGL6szGzHuFs5ceEuuGVrPMg/rW2Ch1bFLJUp/fqKnJEYvqzMbMe4Wzlx4S64ZWs8yD+tbYKHVg==',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@
"@libp2p/logger": "^2.0.5",
"@libp2p/peer-id": "^2.0.0",
"@stablelib/chacha20poly1305": "^1.0.1",
"@stablelib/hkdf": "^1.0.1",
"@stablelib/sha256": "^1.0.1",
"@noble/hashes": "^1.3.0",
"@noble/curves": "^1.0.0",
"@stablelib/x25519": "^1.0.3",
"it-length-prefixed": "^8.0.2",
"it-pair": "^2.0.2",
Expand Down
10 changes: 4 additions & 6 deletions src/crypto/stablelib.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HKDF } from '@stablelib/hkdf'
import * as x25519 from '@stablelib/x25519'
import { SHA256, hash } from '@stablelib/sha256'
import { sha256 } from '@noble/hashes/sha256'
import { hkdf } from '@noble/hashes/hkdf'
import { ChaCha20Poly1305 } from '@stablelib/chacha20poly1305'
import type { bytes32, bytes } from '../@types/basic.js'
import type { Hkdf } from '../@types/handshake.js'
Expand All @@ -9,13 +9,11 @@ import type { ICryptoInterface } from '../crypto.js'

export const stablelib: ICryptoInterface = {
hashSHA256 (data: Uint8Array): Uint8Array {
return hash(data)
return sha256(data)
},

getHKDF (ck: bytes32, ikm: Uint8Array): Hkdf {
const hkdf = new HKDF(SHA256, ikm, ck)
const okmU8Array = hkdf.expand(96)
const okm = okmU8Array
const okm = hkdf(sha256, ikm, ck, undefined, 96)

const k1 = okm.subarray(0, 32)
const k2 = okm.subarray(32, 64)
Expand Down

0 comments on commit 73cc41c

Please sign in to comment.