Skip to content
Snippets Groups Projects
Commit d0464e6f authored by Jono Wenger's avatar Jono Wenger
Browse files

Make ResponseFingerprint set the first bit to zero

parent 8c764de8
No related branches found
No related tags found
No related merge requests found
......@@ -21,8 +21,10 @@ const responseFPConstant = "responseFPConstant"
// the given key number.
func ResponseFingerprint(dhKey *cyclic.Int, keyNum uint64) format.Fingerprint {
// Create fingerprint
fp := format.Fingerprint{}
copy(fp[:], makeKeyHash(dhKey, keyNum, responseFPConstant))
fp := format.NewFingerprint(makeKeyHash(dhKey, keyNum, responseFPConstant))
// Set the first bit as zero to ensure everything stays in the group
fp[0] &= 0b01111111
return fp
}
......
......@@ -24,13 +24,12 @@ func TestResponseFingerprint(t *testing.T) {
dhKey := diffieHellman.GeneratePublicKey(diffieHellman.GeneratePrivateKey(
diffieHellman.DefaultPrivateKeyLength, grp, prng), grp)
testFP := ResponseFingerprint(dhKey, 0)
testFPBase64 := base64.StdEncoding.EncodeToString(testFP[:])
if expectedFP != testFPBase64 {
if expectedFP != testFP.String() {
t.Errorf("ResponseFingerprint() did not return the expected "+
"fingerprint for public key %s."+
"\nexpected: %s\nreceived: %s",
dhKey.Text(10), expectedFP, testFPBase64)
dhKey.Text(10), expectedFP, testFP)
}
}
......
......@@ -18,8 +18,7 @@ const transmitFPConstant = "transmitFPConstant"
// message.
func TransmitFingerprint(dhKey *cyclic.Int) format.Fingerprint {
// Create fingerprint
fp := format.Fingerprint{}
copy(fp[:], makeHash(dhKey, []byte(transmitFPConstant)))
fp := format.NewFingerprint(makeHash(dhKey, []byte(transmitFPConstant)))
// Set the first bit as zero to ensure everything stays in the group
fp[0] &= 0b01111111
......
......@@ -38,13 +38,12 @@ func TestTransmitFingerprint_Consistency(t *testing.T) {
dhKey := diffieHellman.GeneratePublicKey(diffieHellman.GeneratePrivateKey(
diffieHellman.DefaultPrivateKeyLength, grp, prng), grp)
testFP := TransmitFingerprint(dhKey)
testFPBase64 := base64.StdEncoding.EncodeToString(testFP[:])
if expected != testFPBase64 {
if expected != testFP.String() {
t.Errorf("TransmitFingerprint() did not return the expected "+
"fingerprint for public key %s at index %d."+
"\nexpected: %s\nreceived: %s",
dhKey.Text(10), i, expected, testFPBase64)
dhKey.Text(10), i, expected, testFP)
}
}
}
......
......@@ -5,7 +5,7 @@ go 1.13
require (
github.com/pkg/errors v0.9.1
github.com/spf13/jwalterweatherman v1.1.0
gitlab.com/elixxir/primitives v0.0.3-0.20210107183456-9cf6fe2de1e5
gitlab.com/elixxir/primitives v0.0.3-0.20210120174718-802bdcda9dbb
gitlab.com/xx_network/crypto v0.0.5-0.20210107183440-804e0f8b7d22
gitlab.com/xx_network/primitives v0.0.4-0.20210106014326-691ebfca3b07
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de
......
......@@ -61,6 +61,8 @@ gitlab.com/elixxir/primitives v0.0.3-0.20210104223605-0e47af99d9d5 h1:gFnu6lXLNG
gitlab.com/elixxir/primitives v0.0.3-0.20210104223605-0e47af99d9d5/go.mod h1:BLL0lkR9foigqmsz1p3OLnwACBhS9fd3mVk9Ftflg9E=
gitlab.com/elixxir/primitives v0.0.3-0.20210107183456-9cf6fe2de1e5 h1:50HbCJWirpX2Q+NNhIHcs0M9f45H1UJ/7LNMu81Bnn0=
gitlab.com/elixxir/primitives v0.0.3-0.20210107183456-9cf6fe2de1e5/go.mod h1:Ph6isHUDVjmRUd9DioyKpd8W9J52gKBiDeue4DCygXA=
gitlab.com/elixxir/primitives v0.0.3-0.20210120174718-802bdcda9dbb h1:BA/qishMQwdNU7NJTq9WzkSIR45Fi35OrIJ8zqOy3lE=
gitlab.com/elixxir/primitives v0.0.3-0.20210120174718-802bdcda9dbb/go.mod h1:Ph6isHUDVjmRUd9DioyKpd8W9J52gKBiDeue4DCygXA=
gitlab.com/xx_network/crypto v0.0.5-0.20201217195719-cc31e1d1eee3 h1:xXJAkvhHZl5CUX8/9rqe8hod5FbqZrxwMuT8cG48Mxs=
gitlab.com/xx_network/crypto v0.0.5-0.20201217195719-cc31e1d1eee3/go.mod h1:iHCS8UOFndbXivLTeIarxN8TKbi3NcanZj29KtMzs2o=
gitlab.com/xx_network/crypto v0.0.5-0.20210107183440-804e0f8b7d22 h1:SQga1vOuAGzbYURnBjG0f37r7WmWKZRdiqmdopaNMb4=
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment