Skip to content

Commit f8dc9ba

Browse files
committed
make prime a integral part of public key
1 parent dc9f092 commit f8dc9ba

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

hppk.go

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ func init() {
4949

5050
// PrivateKey represents a private key in the HPPK protocol.
5151
type PrivateKey struct {
52-
Prime *big.Int // Prime number used for cryptographic operations
5352
R1, S1 *big.Int // r1 and s1 are coprimes
5453
R2, S2 *big.Int // r2 and s2 are coprimes
5554
F0, F1 *big.Int // f(x) = f1x + f0
@@ -59,8 +58,9 @@ type PrivateKey struct {
5958

6059
// PublicKey represents a public key in the HPPK protocol.
6160
type PublicKey struct {
62-
P []*big.Int // Coefficients of the polynomial P(x)
63-
Q []*big.Int // Coefficients of the polynomial Q(x)
61+
Prime *big.Int // Prime number used for cryptographic operations
62+
P []*big.Int // Coefficients of the polynomial P(x)
63+
Q []*big.Int // Coefficients of the polynomial Q(x)
6464
}
6565

6666
// Signature represents a digital signature in the HPPK protocol.
@@ -218,30 +218,25 @@ RETRY:
218218

219219
// Return the generated private key
220220
return &PrivateKey{
221-
Prime: prime,
222-
R1: r1,
223-
S1: s1,
224-
R2: r2,
225-
S2: s2,
226-
F0: f0,
227-
F1: f1,
228-
H0: h0,
229-
H1: h1,
221+
R1: r1,
222+
S1: s1,
223+
R2: r2,
224+
S2: s2,
225+
F0: f0,
226+
F1: f1,
227+
H0: h0,
228+
H1: h1,
230229
PublicKey: PublicKey{
231-
P: P,
232-
Q: Q,
230+
Prime: prime,
231+
P: P,
232+
Q: Q,
233233
},
234234
}, nil
235235
}
236236

237-
// Encrypt encrypts a message using the given public key and custom prime number.
238-
func EncryptWithPrime(pub *PublicKey, msg []byte, prime *big.Int) (kem *KEM, err error) {
239-
return encrypt(pub, msg, prime)
240-
}
241-
242237
// Encrypt encrypts a message using the given public key and default prime number.
243238
func Encrypt(pub *PublicKey, msg []byte) (kem *KEM, err error) {
244-
return encrypt(pub, msg, defaultPrime)
239+
return encrypt(pub, msg, pub.Prime)
245240
}
246241

247242
// encrypt encrypts a message using the given public key.
@@ -466,14 +461,9 @@ func (priv *PrivateKey) Order() int {
466461
return len(priv.PublicKey.P) - 2
467462
}
468463

469-
// VerifySignature verifies the signature of the message digest using the public key and given prime
470-
func VerifySignatureWithPrime(sig *Signature, digest []byte, pub *PublicKey, prime *big.Int) bool {
471-
return verifySignature(sig, digest, pub, prime)
472-
}
473-
474464
// VerifySignature verifies the signature of the message digest using the public key and default prime
475465
func VerifySignature(sig *Signature, digest []byte, pub *PublicKey) bool {
476-
return verifySignature(sig, digest, pub, defaultPrime)
466+
return verifySignature(sig, digest, pub, pub.Prime)
477467
}
478468

479469
func verifySignature(sig *Signature, digest []byte, pub *PublicKey, prime *big.Int) bool {

0 commit comments

Comments
 (0)