Use constant time (#430)

This commit is contained in:
Jesse Peterson
2018-06-09 11:09:28 -07:00
committed by Victor Vrantchan
parent ee3f43d4c6
commit b857046412
2 changed files with 4 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ package main
import (
"bytes"
"context"
"crypto/subtle"
"crypto/tls"
"crypto/x509"
"encoding/base64"
@@ -796,7 +797,7 @@ func HasCN(db *boltdepot.Depot, cn string, allowTime int, cert *x509.Certificate
certKey := []byte(cert.Subject.CommonName + "." + cert.SerialNumber.String())
certCandidate := bucket.Get(certKey)
if certCandidate != nil {
hasCN = bytes.Compare(certCandidate, cert.Raw) == 0
hasCN = 1 == subtle.ConstantTimeCompare(certCandidate, cert.Raw)
}
return nil
})

View File

@@ -3,9 +3,9 @@
package password
import (
"bytes"
"crypto/rand"
"crypto/sha512"
"crypto/subtle"
"errors"
"math/big"
@@ -50,7 +50,7 @@ func SaltedSHA512PBKDF2(plaintext string) (SaltedSHA512PBKDF2Dictionary, error)
// password dictionary.
func Verify(plaintext string, h SaltedSHA512PBKDF2Dictionary) error {
hashed := pbkdf2.Key([]byte(plaintext), h.Salt, h.Iterations, macKeyLen, sha512.New)
if !bytes.Equal(h.Entropy, hashed) {
if 1 == subtle.ConstantTimeCompare(h.Entropy, hashed) {
return ErrNoMatch
}
return nil