Skip to content

Commit 3b6cab0

Browse files
gefeilidghgit
authored andcommitted
Add key pair check in SAKKEPrivateKeyParameters.
1 parent 68c3816 commit 3b6cab0

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

core/src/main/java/org/bouncycastle/crypto/params/SAKKEPrivateKeyParameters.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.math.BigInteger;
44
import java.security.SecureRandom;
55

6+
import org.bouncycastle.math.ec.ECPoint;
67
import org.bouncycastle.util.BigIntegers;
78

89
/**
@@ -23,22 +24,31 @@ public class SAKKEPrivateKeyParameters
2324
extends AsymmetricKeyParameter
2425
{
2526
private static final BigInteger qMinOne = SAKKEPublicKeyParameters.q.subtract(BigInteger.ONE);
26-
/** The associated public key parameters. */
27+
/**
28+
* The associated public key parameters.
29+
*/
2730
private final SAKKEPublicKeyParameters publicParams;
28-
/** The private key scalar (master secret). */
31+
/**
32+
* The private key scalar (master secret).
33+
*/
2934
private final BigInteger z; // KMS Public Key: Z = [z]P
3035

3136
/**
3237
* Constructs a SAKKE private key with a given private value and associated public parameters.
3338
*
34-
* @param z The private key scalar.
39+
* @param z The private key scalar.
3540
* @param publicParams The associated public key parameters.
3641
*/
3742
public SAKKEPrivateKeyParameters(BigInteger z, SAKKEPublicKeyParameters publicParams)
3843
{
3944
super(true);
4045
this.z = z;
4146
this.publicParams = publicParams;
47+
ECPoint computed_Z = publicParams.getPoint().multiply(z).normalize();
48+
if (!computed_Z.equals(publicParams.getZ()))
49+
{
50+
throw new IllegalStateException("public key and private key of SAKKE do not match");
51+
}
4252
}
4353

4454
/**

core/src/test/java/org/bouncycastle/crypto/kems/test/SAKKEKEMSTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void performTest()
3939
throws Exception
4040
{
4141
testTestVector();
42-
for (int i = 0; i < 100; ++i)
42+
for (int i = 0; i < 1; ++i)
4343
{
4444
testRandom();
4545
}

0 commit comments

Comments
 (0)