Skip to content

Commit

Permalink
Unslab hash where relevant
Browse files Browse the repository at this point in the history
  • Loading branch information
HDegroote committed Sep 18, 2024
1 parent 032e2ab commit f4f5430
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module.exports = function connect (dht, publicKey, opts = {}) {
relayAddresses: opts.relayAddresses || [],
pool,
round: 0,
target: hash(publicKey),
target: hash(publicKey, b4a.allocUnsafeSlow),
remotePublicKey: publicKey,
reusableSocket: !!opts.reusableSocket,
handshake: (opts.createHandshake || defaultCreateHandshake)(keyPair, publicKey),
Expand Down
4 changes: 2 additions & 2 deletions lib/crypto.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const sodium = require('sodium-universal')
const b4a = require('b4a')

function hash (data) {
const out = b4a.allocUnsafe(32)
function hash (data, alloc = b4a.allocUnsafe) {
const out = alloc(32)
sodium.crypto_generichash(out, data)
return out
}
Expand Down
2 changes: 1 addition & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ module.exports = class Server extends EventEmitter {
await this.dht.bind()
if (this._closing) return

this.target = hash(keyPair.publicKey)
this.target = hash(keyPair.publicKey, b4a.allocUnsafeSlow)

this._keyPair = keyPair
this._announcer = new Announcer(this.dht, keyPair, this.target, opts)
Expand Down

0 comments on commit f4f5430

Please sign in to comment.