Skip to content
This repository was archived by the owner on Jun 3, 2020. It is now read-only.

Commit 46f034a

Browse files
committed
Switch from sha256 to blake2b for peersocket topic hashing
1 parent 364e827 commit 46f034a

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

hyperswarm/peersocket.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const crypto = require('crypto')
33
const createSwarm = require('@hyperswarm/network')
44
const lpstream = require('length-prefixed-stream')
55
const pump = require('pump')
6+
const sodium = require('sodium')
67
const schemas = require('./peersocket-schemas')
78
const {extractOrigin} = require('../../../lib/strings')
89

@@ -116,12 +117,10 @@ function decodeMsg (msg) {
116117
// internal methods
117118
// =
118119

119-
function sha256 (str) {
120-
return crypto.createHash('sha256').update(str).digest()
121-
}
122-
123120
function createLobbyTopic (lobbyType, lobbyName) {
124-
return sha256(`peersocket-${lobbyType}-${lobbyName}`)
121+
var out = Buffer.allocUnsafe(32)
122+
sodium.crypto_generichash(out, Buffer.from(`peersocket-${lobbyType}-${lobbyName}`, 'utf8'))
123+
return out
125124
}
126125

127126
function getSwarmId (sender, tabIdentity) {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"slugify": "^1.3.1",
7575
"sodium-signatures": "^2.1.1",
7676
"spellchecker": "^3.5.0",
77+
"sodium-universal": "^2.0.0",
7778
"split2": "^2.2.0",
7879
"sqlite3": "^4.0.1",
7980
"stream-throttle": "^0.1.3",

0 commit comments

Comments
 (0)