Skip to content
Snippets Groups Projects
Commit 0a952e4e authored by Benjamin Wenger's avatar Benjamin Wenger
Browse files

Merge branch 'jonah/checkFP' into 'agile/EphemeralReception'

Jonah/check fp

See merge request elixxir/crypto!254
parents b576829b 703f84c0
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@
package fingerprint
import (
"bytes"
"crypto"
"github.com/pkg/errors"
"gitlab.com/xx_network/primitives/id"
......@@ -34,3 +35,12 @@ func IdentityFP(encryptedMessagePayload []byte, recipientId *id.ID) ([]byte, err
}
return b2b.Sum(nil)[:identityFpSizeBytes], nil
}
// Check if a received fingerprint is correct based on message payload and ID
func CheckIdentityFP(receivedFP, encryptedMessagePayload []byte, recipientId *id.ID) (bool, error) {
identityFP, err := IdentityFP(encryptedMessagePayload, recipientId)
if err != nil {
return false, err
}
return bytes.Compare(identityFP, receivedFP) == 0, nil
}
......@@ -54,3 +54,19 @@ func TestIdentityFP(t *testing.T) {
t.Logf("\n\tID1 [%+v]\n\tID2 [%+v]\n\tID3 [%+v]\n\tID4 [%+v]\n\tID5 [%+v]\n", fp1, fp2, fp3, fp4, fp5)
}
}
func TestCheckIdentityFP(t *testing.T) {
message1 := []byte("I'm an encrypted message!")
user1 := id.NewIdFromString("zezima", id.User, t)
// Check that two fingerprints created from the same data are identical
fp1, err := IdentityFP(message1, user1)
if err != nil {
t.Errorf("Failed to create identity fingerprint 1: %+v", err)
}
ok, err := CheckIdentityFP(fp1, message1, user1)
if err != nil || !ok {
t.Errorf("Should have gotten ok from CheckIdentityFP. Instead got (%+v, %+v)", ok, err)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment