From 04fc5fc55f4987228c27d7586d5ec337720bea11 Mon Sep 17 00:00:00 2001 From: xtaci Date: Wed, 31 Jul 2024 00:02:39 +0800 Subject: [PATCH] added Equal() for public key comparision --- hppk.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/hppk.go b/hppk.go index 8fb3700..5865490 100644 --- a/hppk.go +++ b/hppk.go @@ -67,6 +67,27 @@ type KEM struct { Q *big.Int } +// Equal checks if two public keys are equal +func (pub *PublicKey) Equal(other *PublicKey) bool { + if len(pub.P) != len(other.P) || len(pub.Q) != len(other.Q) { + return false + } + + for i := 0; i < len(pub.P); i++ { + if pub.P[i].Cmp(other.P[i]) != 0 { + return false + } + } + + for i := 0; i < len(pub.Q); i++ { + if pub.Q[i].Cmp(other.Q[i]) != 0 { + return false + } + } + + return true +} + // GenerateKey generates a new HPPK private key with the given order and default prime number. func GenerateKey(order int) (*PrivateKey, error) { // Ensure the order is at least 5