Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
decrypt: the "constant time" comparison, wasn't
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzorin committed Jul 30, 2019
1 parent 8b5c58d commit eac435b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"crypto/hmac"
"crypto/rand"
"crypto/sha1"
"crypto/subtle"
"encoding/base32"
"encoding/base64"
"encoding/binary"
Expand Down Expand Up @@ -115,11 +116,12 @@ func decryptToken(encryptedSeedB64, salt, passphrase string) (string, error) {
if paddingLen > aes.BlockSize || paddingStart >= len(out) || paddingStart <= 0 {
return "", errors.New("decryption failed")
}
cmp := true

var cmp byte
for _, pad := range out[paddingStart:] {
cmp = cmp && pad == paddingLen
cmp |= pad ^ paddingLen
}
if !cmp {
if subtle.ConstantTimeByteEq(cmp, 0) != 1 {
return "", errors.New("decryption failed")
}

Expand Down

0 comments on commit eac435b

Please sign in to comment.