Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Do not reuse KeyPair context to generate second key pair #174

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ public void testGenerateSecretDH() {
public void generateSecretDH(byte keyAlg, short keySize, byte keyAgreementAlg) {
// generate keys
KeyPair kp = new KeyPair(keyAlg, keySize);
KeyPair kp2 = new KeyPair(keyAlg, keySize);
kp.genKeyPair();
PrivateKey privateKey1 = kp.getPrivate();
DHPublicKey publicKey1 = (DHPublicKey) kp.getPublic();
kp.genKeyPair();
PrivateKey privateKey2 = kp.getPrivate();
DHPublicKey publicKey2 = (DHPublicKey) kp.getPublic();
kp2.genKeyPair();
PrivateKey privateKey2 = kp2.getPrivate();
DHPublicKey publicKey2 = (DHPublicKey) kp2.getPublic();
// generate first secret
KeyAgreement ka = KeyAgreement.getInstance(keyAgreementAlg, false);
byte[] secret1 = new byte[256];
Expand Down Expand Up @@ -113,12 +114,13 @@ public void generateSecretDH(byte keyAlg, short keySize, byte keyAgreementAlg) {
public void testGenerateSecret(byte keyAlg, short keySize, byte keyAgreementAlg) {
// generate keys
KeyPair kp = new KeyPair(keyAlg, keySize);
KeyPair kp2 = new KeyPair(keyAlg, keySize);
kp.genKeyPair();
PrivateKey privateKey1 = kp.getPrivate();
ECPublicKey publicKey1 = (ECPublicKey) kp.getPublic();
kp.genKeyPair();
PrivateKey privateKey2 = kp.getPrivate();
ECPublicKey publicKey2 = (ECPublicKey) kp.getPublic();
kp2.genKeyPair();
PrivateKey privateKey2 = kp2.getPrivate();
ECPublicKey publicKey2 = (ECPublicKey) kp2.getPublic();
// generate first secret
KeyAgreement ka = KeyAgreement.getInstance(keyAgreementAlg, false);
byte[] secret1 = new byte[65];
Expand Down Expand Up @@ -159,4 +161,4 @@ public void testGenerateSecret(byte keyAlg, short keySize, byte keyAgreementAlg)
// check match of values
assertEquals(true, Arrays.areEqual(secret1, secret2));
}
}
}