Skip to content

Commit 04fc5fc

Browse files
committed
added Equal() for public key comparision
1 parent 162d3ea commit 04fc5fc

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

hppk.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,27 @@ type KEM struct {
6767
Q *big.Int
6868
}
6969

70+
// Equal checks if two public keys are equal
71+
func (pub *PublicKey) Equal(other *PublicKey) bool {
72+
if len(pub.P) != len(other.P) || len(pub.Q) != len(other.Q) {
73+
return false
74+
}
75+
76+
for i := 0; i < len(pub.P); i++ {
77+
if pub.P[i].Cmp(other.P[i]) != 0 {
78+
return false
79+
}
80+
}
81+
82+
for i := 0; i < len(pub.Q); i++ {
83+
if pub.Q[i].Cmp(other.Q[i]) != 0 {
84+
return false
85+
}
86+
}
87+
88+
return true
89+
}
90+
7091
// GenerateKey generates a new HPPK private key with the given order and default prime number.
7192
func GenerateKey(order int) (*PrivateKey, error) {
7293
// Ensure the order is at least 5

0 commit comments

Comments
 (0)