Don't pass a null provider to the Cipher constructor.

This commit is contained in:
akwizgran
2013-06-14 11:24:14 +01:00
parent 155a231292
commit a979cab43a

View File

@@ -15,6 +15,7 @@ import java.security.KeyFactory;
import java.security.KeyPair; import java.security.KeyPair;
import java.security.KeyPairGenerator; import java.security.KeyPairGenerator;
import java.security.PrivateKey; import java.security.PrivateKey;
import java.security.Provider;
import java.security.PublicKey; import java.security.PublicKey;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.security.Security; import java.security.Security;
@@ -136,13 +137,15 @@ class CryptoComponentImpl implements CryptoComponent {
private static final ECParameterSpec P_384_PARAMS = private static final ECParameterSpec P_384_PARAMS =
new ECParameterSpec(P_384_CURVE, P_384_G, P_384_N, P_384_H); new ECParameterSpec(P_384_CURVE, P_384_G, P_384_N, P_384_H);
private final Provider provider;
private final KeyParser agreementKeyParser, signatureKeyParser; private final KeyParser agreementKeyParser, signatureKeyParser;
private final KeyPairGenerator agreementKeyPairGenerator; private final KeyPairGenerator agreementKeyPairGenerator;
private final KeyPairGenerator signatureKeyPairGenerator; private final KeyPairGenerator signatureKeyPairGenerator;
private final SecureRandom secureRandom; private final SecureRandom secureRandom;
CryptoComponentImpl() { CryptoComponentImpl() {
Security.addProvider(new BouncyCastleProvider()); provider = new BouncyCastleProvider();
Security.addProvider(provider);
try { try {
KeyFactory agreementKeyFactory = KeyFactory.getInstance( KeyFactory agreementKeyFactory = KeyFactory.getInstance(
AGREEMENT_KEY_PAIR_ALGO, PROVIDER); AGREEMENT_KEY_PAIR_ALGO, PROVIDER);
@@ -356,7 +359,7 @@ class CryptoComponentImpl implements CryptoComponent {
} }
public Cipher getTagCipher() { public Cipher getTagCipher() {
return new CipherFromSpi(new AES.ECB(), TAG_CIPHER_ALGO); return new CipherFromSpi(new AES.ECB(), provider, TAG_CIPHER_ALGO);
} }
public AuthenticatedCipher getFrameCipher() { public AuthenticatedCipher getFrameCipher() {
@@ -511,7 +514,8 @@ class CryptoComponentImpl implements CryptoComponent {
ErasableKey key = new ErasableKeyImpl(secret, SECRET_KEY_ALGO); ErasableKey key = new ErasableKeyImpl(secret, SECRET_KEY_ALGO);
try { try {
CipherSpi spi = new AES.ECB(); CipherSpi spi = new AES.ECB();
Cipher cipher = new CipherFromSpi(spi, KEY_DERIVATION_ALGO); Cipher cipher = new CipherFromSpi(spi, provider,
KEY_DERIVATION_ALGO);
cipher.init(Cipher.ENCRYPT_MODE, key, iv); cipher.init(Cipher.ENCRYPT_MODE, key, iv);
byte[] output = cipher.doFinal(KEY_DERIVATION_BLANK_PLAINTEXT); byte[] output = cipher.doFinal(KEY_DERIVATION_BLANK_PLAINTEXT);
assert output.length == SECRET_KEY_BYTES; assert output.length == SECRET_KEY_BYTES;
@@ -550,8 +554,9 @@ class CryptoComponentImpl implements CryptoComponent {
private static class CipherFromSpi extends Cipher { private static class CipherFromSpi extends Cipher {
private CipherFromSpi(CipherSpi spi, String transformation) { private CipherFromSpi(CipherSpi spi, Provider provider,
super(spi, null, transformation); String transformation) {
super(spi, provider, transformation);
} }
} }
} }