Skip to content

Commit

Permalink
Remove duplicate public key parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
romanstrobl committed Jun 27, 2023
1 parent 4c3e612 commit 2cbb55d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.getlime.security.powerauth.crypto.lib.util.ByteUtils;
import io.getlime.security.powerauth.crypto.lib.util.HMACHashUtilities;
import io.getlime.security.powerauth.crypto.lib.util.Hash;
import io.getlime.security.powerauth.crypto.lib.util.KeyConvertor;

import java.nio.ByteBuffer;
import java.security.interfaces.ECPrivateKey;
Expand All @@ -37,6 +38,7 @@
public class EciesFactory {

private final HMACHashUtilities hmacHashUtilities = new HMACHashUtilities();
private final KeyConvertor keyConvertor = new KeyConvertor();

/**
* Get ECIES encryptor instance for application scope.
Expand All @@ -45,15 +47,14 @@ public class EciesFactory {
* @param applicationSecret Application secret.
* @param sharedInfo1 Additional information for sharedInfo1 parameter using pre-defined constants.
* @param eciesParameters ECIES parameters for protocol V3.2+.
* @param ephemeralPublicKey Ephemeral public key.
* @return Initialized ECIES encryptor.
* @throws GenericCryptoException In case encryptor could not be initialized.
* @throws CryptoProviderException In case cryptography provider is incorrectly initialized.
*/
public EciesEncryptor getEciesEncryptorForApplication(final ECPublicKey publicKey, final byte[] applicationSecret, final EciesSharedInfo1 sharedInfo1,
final EciesParameters eciesParameters, final byte[] ephemeralPublicKey) throws GenericCryptoException, CryptoProviderException {
final EciesParameters eciesParameters) throws GenericCryptoException, CryptoProviderException {
byte[] sharedInfo1Value = sharedInfo1 == null ? EciesSharedInfo1.APPLICATION_SCOPE_GENERIC.value() : sharedInfo1.value();
return getEciesEncryptor(EciesScope.APPLICATION_SCOPE, publicKey, applicationSecret, null, sharedInfo1Value, eciesParameters, ephemeralPublicKey);
return getEciesEncryptor(EciesScope.APPLICATION_SCOPE, publicKey, applicationSecret, null, sharedInfo1Value, eciesParameters);
}

/**
Expand All @@ -64,15 +65,14 @@ public EciesEncryptor getEciesEncryptorForApplication(final ECPublicKey publicKe
* @param transportKey Transport key.
* @param sharedInfo1 Additional information for sharedInfo1 parameter using pre-defined constants.
* @param eciesParameters ECIES parameters for protocol V3.2+.
* @param ephemeralPublicKey Ephemeral public key.
* @return Initialized ECIES encryptor.
* @throws GenericCryptoException In case encryptor could not be initialized.
* @throws CryptoProviderException In case cryptography provider is incorrectly initialized.
*/
public EciesEncryptor getEciesEncryptorForActivation(final ECPublicKey publicKey, final byte[] applicationSecret, final byte[] transportKey,
final EciesSharedInfo1 sharedInfo1, final EciesParameters eciesParameters, final byte[] ephemeralPublicKey) throws GenericCryptoException, CryptoProviderException {
final EciesSharedInfo1 sharedInfo1, final EciesParameters eciesParameters) throws GenericCryptoException, CryptoProviderException {
byte[] sharedInfo1Value = sharedInfo1 == null ? EciesSharedInfo1.ACTIVATION_SCOPE_GENERIC.value() : sharedInfo1.value();
return getEciesEncryptor(EciesScope.ACTIVATION_SCOPE, publicKey, applicationSecret, transportKey, sharedInfo1Value, eciesParameters, ephemeralPublicKey);
return getEciesEncryptor(EciesScope.ACTIVATION_SCOPE, publicKey, applicationSecret, transportKey, sharedInfo1Value, eciesParameters);
}

/**
Expand Down Expand Up @@ -120,8 +120,9 @@ public EciesEncryptor getEciesEncryptor(final EciesScope eciesScope, final Ecies
*/
private EciesEncryptor getEciesEncryptor(final EciesScope eciesScope, final ECPublicKey publicKey, final byte[] applicationSecret,
final byte[] transportKey, final byte[] sharedInfo1,
final EciesParameters eciesParameters, final byte[] ephemeralPublicKey) throws GenericCryptoException, CryptoProviderException {
final byte[] sharedInfo2 = generateSharedInfo2(eciesScope, applicationSecret, transportKey, eciesParameters, ephemeralPublicKey);
final EciesParameters eciesParameters) throws GenericCryptoException, CryptoProviderException {
final byte[] publicKeyBytes = keyConvertor.convertPublicKeyToBytes(publicKey);
final byte[] sharedInfo2 = generateSharedInfo2(eciesScope, applicationSecret, transportKey, eciesParameters, publicKeyBytes);
return new EciesEncryptor(publicKey, sharedInfo1, sharedInfo2);
}

Expand Down Expand Up @@ -208,6 +209,7 @@ public EciesDecryptor getEciesDecryptor(final EciesScope eciesScope, final Ecies
private EciesDecryptor getEciesDecryptor(final EciesScope eciesScope, final ECPrivateKey privateKey, final byte[] applicationSecret,
final byte[] transportKey, final byte[] sharedInfo1, final EciesParameters eciesParameters,
final byte[] ephemeralPublickey) throws GenericCryptoException, CryptoProviderException {

final byte[] sharedInfo2 = generateSharedInfo2(eciesScope, applicationSecret, transportKey, eciesParameters, ephemeralPublickey);
return new EciesDecryptor(privateKey, sharedInfo1, sharedInfo2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ public void testEncryptDecrypt() throws Exception {
.associatedData(associatedData)
.timestamp(timestampRequest)
.build();
final EciesEncryptor encryptorRequest = eciesFactory.getEciesEncryptorForApplication(publicKey, applicationSecret, EciesSharedInfo1.APPLICATION_SCOPE_GENERIC,
eciesParametersRequest, publicKeyBytes);
final EciesEncryptor encryptorRequest = eciesFactory.getEciesEncryptorForApplication(publicKey, applicationSecret, EciesSharedInfo1.APPLICATION_SCOPE_GENERIC, eciesParametersRequest);
final EciesPayload payloadRequest = encryptorRequest.encrypt(request, eciesParametersRequest);
final EciesCryptogram cryptogram = payloadRequest.getCryptogram();
final EciesParameters parameters = payloadRequest.getParameters();
Expand Down Expand Up @@ -193,8 +192,7 @@ public void testInvalidMacReject() throws Exception {
.associatedData(associatedData)
.timestamp(timestampRequest)
.build();
final EciesEncryptor encryptorRequest = eciesFactory.getEciesEncryptorForApplication(publicKey, applicationSecret, EciesSharedInfo1.APPLICATION_SCOPE_GENERIC,
eciesParametersRequest, publicKeyBytes);
final EciesEncryptor encryptorRequest = eciesFactory.getEciesEncryptorForApplication(publicKey, applicationSecret, EciesSharedInfo1.APPLICATION_SCOPE_GENERIC, eciesParametersRequest);
final EciesPayload payloadRequest = encryptorRequest.encrypt(request, eciesParametersRequest);
final EciesCryptogram cryptogram = payloadRequest.getCryptogram();
final EciesParameters parameters = payloadRequest.getParameters();
Expand Down

0 comments on commit 2cbb55d

Please sign in to comment.