Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use constant time compare for password validation #97

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
use constant time compare for password validation
Use a constant time comparison function to compare password hashes
This guards against the possibility of leaking timing information when comparing hashes.
  • Loading branch information
ricecake authored Nov 11, 2021
commit ec7572f509b2714fdc029b544d0589c17757e6a9
6 changes: 3 additions & 3 deletions packet.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package radius

import (
"bytes"
"crypto/md5"
"crypto/rand"
"crypto/subtle"
"encoding/binary"
"errors"
)
Expand Down Expand Up @@ -155,7 +155,7 @@ func IsAuthenticResponse(response, request, secret []byte) bool {
hash.Write(response[20:])
hash.Write(secret)
var sum [md5.Size]byte
return bytes.Equal(hash.Sum(sum[:0]), response[4:20])
return subtle.ConstantTimeCompare(hash.Sum(sum[:0]), response[4:20])
}

// IsAuthenticRequest returns if the given RADIUS request is an authentic
Expand All @@ -176,7 +176,7 @@ func IsAuthenticRequest(request, secret []byte) bool {
hash.Write(request[20:])
hash.Write(secret)
var sum [md5.Size]byte
return bytes.Equal(hash.Sum(sum[:0]), request[4:20])
return subtle.ConstantTimeCompare(hash.Sum(sum[:0]), request[4:20])
default:
return false
}
Expand Down