Skip to content

Commit 9dfb3dc

Browse files
authored
perf(pg): use native crypto.pbkdf2Sync in sasl auth (#2815)
1 parent 9e2d7c4 commit 9dfb3dc

File tree

1 file changed

+1
-12
lines changed

1 file changed

+1
-12
lines changed

packages/pg/lib/sasl.js

+1-12
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function continueSession(session, password, serverData) {
3737

3838
var saltBytes = Buffer.from(sv.salt, 'base64')
3939

40-
var saltedPassword = Hi(password, saltBytes, sv.iteration)
40+
var saltedPassword = crypto.pbkdf2Sync(password, saltBytes, sv.iteration, 32, 'sha256')
4141

4242
var clientKey = hmacSha256(saltedPassword, 'Client Key')
4343
var storedKey = sha256(clientKey)
@@ -191,17 +191,6 @@ function hmacSha256(key, msg) {
191191
return crypto.createHmac('sha256', key).update(msg).digest()
192192
}
193193

194-
function Hi(password, saltBytes, iterations) {
195-
var ui1 = hmacSha256(password, Buffer.concat([saltBytes, Buffer.from([0, 0, 0, 1])]))
196-
var ui = ui1
197-
for (var i = 0; i < iterations - 1; i++) {
198-
ui1 = hmacSha256(password, ui1)
199-
ui = xorBuffers(ui, ui1)
200-
}
201-
202-
return ui
203-
}
204-
205194
module.exports = {
206195
startSession,
207196
continueSession,

0 commit comments

Comments
 (0)