JNI/JCE: fix unused imports and variable warnings reported by Cursor/VSCode
parent
2eeb8f1cbb
commit
3484adef93
|
@ -45,16 +45,12 @@ import java.security.InvalidKeyException;
|
||||||
import java.security.interfaces.RSAPrivateKey;
|
import java.security.interfaces.RSAPrivateKey;
|
||||||
import java.security.interfaces.RSAPublicKey;
|
import java.security.interfaces.RSAPublicKey;
|
||||||
|
|
||||||
import com.wolfssl.wolfcrypt.WolfCrypt;
|
|
||||||
import com.wolfssl.wolfcrypt.Asn;
|
|
||||||
import com.wolfssl.wolfcrypt.Aes;
|
import com.wolfssl.wolfcrypt.Aes;
|
||||||
import com.wolfssl.wolfcrypt.AesGcm;
|
import com.wolfssl.wolfcrypt.AesGcm;
|
||||||
import com.wolfssl.wolfcrypt.Des3;
|
import com.wolfssl.wolfcrypt.Des3;
|
||||||
import com.wolfssl.wolfcrypt.Rsa;
|
import com.wolfssl.wolfcrypt.Rsa;
|
||||||
import com.wolfssl.wolfcrypt.Rng;
|
import com.wolfssl.wolfcrypt.Rng;
|
||||||
|
|
||||||
import com.wolfssl.provider.jce.WolfCryptDebug;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wolfCrypt JCE Cipher (AES, 3DES) wrapper
|
* wolfCrypt JCE Cipher (AES, 3DES) wrapper
|
||||||
*/
|
*/
|
||||||
|
@ -144,6 +140,9 @@ public class WolfCryptCipher extends CipherSpi {
|
||||||
case WC_DES3:
|
case WC_DES3:
|
||||||
blockSize = Des3.BLOCK_SIZE;
|
blockSize = Des3.BLOCK_SIZE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case WC_RSA:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WolfCryptDebug.DEBUG) {
|
if (WolfCryptDebug.DEBUG) {
|
||||||
|
@ -450,8 +449,6 @@ public class WolfCryptCipher extends CipherSpi {
|
||||||
private void wolfCryptSetKey(Key key)
|
private void wolfCryptSetKey(Key key)
|
||||||
throws InvalidKeyException {
|
throws InvalidKeyException {
|
||||||
|
|
||||||
int ret = 0;
|
|
||||||
long[] idx = {0};
|
|
||||||
byte[] encodedKey;
|
byte[] encodedKey;
|
||||||
|
|
||||||
/* validate key class type */
|
/* validate key class type */
|
||||||
|
@ -611,27 +608,10 @@ public class WolfCryptCipher extends CipherSpi {
|
||||||
return isBlockCipher;
|
return isBlockCipher;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return 1 if cipher is a block cipher and lenth is a block
|
|
||||||
* length multiple, otherwise 0 */
|
|
||||||
private int isValidBlockLength(int length) {
|
|
||||||
|
|
||||||
/* skip if not a block cipher */
|
|
||||||
if (isBlockCipher() == false) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((length % this.blockSize) != 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private byte[] wolfCryptUpdate(byte[] input, int inputOffset, int len)
|
private byte[] wolfCryptUpdate(byte[] input, int inputOffset, int len)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
|
|
||||||
int blocks = 0;
|
int blocks = 0;
|
||||||
int remaining = 0;
|
|
||||||
int bytesToProcess = 0;
|
int bytesToProcess = 0;
|
||||||
byte[] output = null;
|
byte[] output = null;
|
||||||
byte[] tmpIn = null;
|
byte[] tmpIn = null;
|
||||||
|
@ -666,7 +646,6 @@ public class WolfCryptCipher extends CipherSpi {
|
||||||
|
|
||||||
/* calculate blocks and partial non-block size remaining */
|
/* calculate blocks and partial non-block size remaining */
|
||||||
blocks = buffered.length / blockSize;
|
blocks = buffered.length / blockSize;
|
||||||
remaining = buffered.length % blockSize;
|
|
||||||
bytesToProcess = blocks * blockSize;
|
bytesToProcess = blocks * blockSize;
|
||||||
|
|
||||||
/* if PKCS#5/7 padding, and decrypting, hold on to last block for
|
/* if PKCS#5/7 padding, and decrypting, hold on to last block for
|
||||||
|
|
|
@ -26,7 +26,6 @@ import javax.crypto.KeyAgreementSpi;
|
||||||
import javax.crypto.SecretKey;
|
import javax.crypto.SecretKey;
|
||||||
import javax.crypto.ShortBufferException;
|
import javax.crypto.ShortBufferException;
|
||||||
import javax.crypto.spec.DHParameterSpec;
|
import javax.crypto.spec.DHParameterSpec;
|
||||||
import javax.crypto.SecretKey;
|
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
import javax.crypto.spec.DESKeySpec;
|
import javax.crypto.spec.DESKeySpec;
|
||||||
import javax.crypto.spec.DESedeKeySpec;
|
import javax.crypto.spec.DESedeKeySpec;
|
||||||
|
@ -48,8 +47,6 @@ import java.security.interfaces.ECPrivateKey;
|
||||||
import com.wolfssl.wolfcrypt.Dh;
|
import com.wolfssl.wolfcrypt.Dh;
|
||||||
import com.wolfssl.wolfcrypt.Ecc;
|
import com.wolfssl.wolfcrypt.Ecc;
|
||||||
|
|
||||||
import com.wolfssl.provider.jce.WolfCryptDebug;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wolfCrypt JCE Key Agreement wrapper
|
* wolfCrypt JCE Key Agreement wrapper
|
||||||
*/
|
*/
|
||||||
|
@ -236,9 +233,7 @@ public class WolfCryptKeyAgreement extends KeyAgreementSpi {
|
||||||
protected int engineGenerateSecret(byte[] sharedSecret, int offset)
|
protected int engineGenerateSecret(byte[] sharedSecret, int offset)
|
||||||
throws IllegalStateException, ShortBufferException {
|
throws IllegalStateException, ShortBufferException {
|
||||||
|
|
||||||
int ret = 0;
|
|
||||||
byte tmp[] = null;
|
byte tmp[] = null;
|
||||||
long sz[] = null;
|
|
||||||
|
|
||||||
if (this.state != EngineState.WC_PUBKEY_DONE)
|
if (this.state != EngineState.WC_PUBKEY_DONE)
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
|
@ -355,7 +350,6 @@ public class WolfCryptKeyAgreement extends KeyAgreementSpi {
|
||||||
private void wcInitDHParams(Key key, AlgorithmParameterSpec params)
|
private void wcInitDHParams(Key key, AlgorithmParameterSpec params)
|
||||||
throws InvalidKeyException, InvalidAlgorithmParameterException {
|
throws InvalidKeyException, InvalidAlgorithmParameterException {
|
||||||
|
|
||||||
int ret = 0;
|
|
||||||
byte paramP[] = null;
|
byte paramP[] = null;
|
||||||
byte paramG[] = null;
|
byte paramG[] = null;
|
||||||
byte dhPriv[] = null;
|
byte dhPriv[] = null;
|
||||||
|
@ -433,8 +427,6 @@ public class WolfCryptKeyAgreement extends KeyAgreementSpi {
|
||||||
private void getCurveFromSpec(AlgorithmParameterSpec spec)
|
private void getCurveFromSpec(AlgorithmParameterSpec spec)
|
||||||
throws InvalidAlgorithmParameterException {
|
throws InvalidAlgorithmParameterException {
|
||||||
|
|
||||||
int fieldSz = 0;
|
|
||||||
|
|
||||||
if (spec instanceof ECGenParameterSpec) {
|
if (spec instanceof ECGenParameterSpec) {
|
||||||
|
|
||||||
ECGenParameterSpec gs = (ECGenParameterSpec)spec;
|
ECGenParameterSpec gs = (ECGenParameterSpec)spec;
|
||||||
|
|
|
@ -28,18 +28,13 @@ import java.security.KeyPair;
|
||||||
import java.security.InvalidAlgorithmParameterException;
|
import java.security.InvalidAlgorithmParameterException;
|
||||||
|
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.security.AlgorithmParameters;
|
|
||||||
import java.security.spec.AlgorithmParameterSpec;
|
import java.security.spec.AlgorithmParameterSpec;
|
||||||
import java.security.Key;
|
|
||||||
import java.security.KeyPair;
|
|
||||||
import java.security.KeyFactory;
|
import java.security.KeyFactory;
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.security.spec.KeySpec;
|
import java.security.spec.KeySpec;
|
||||||
import java.security.spec.PKCS8EncodedKeySpec;
|
import java.security.spec.PKCS8EncodedKeySpec;
|
||||||
import java.security.spec.X509EncodedKeySpec;
|
import java.security.spec.X509EncodedKeySpec;
|
||||||
import java.security.spec.ECGenParameterSpec;
|
import java.security.spec.ECGenParameterSpec;
|
||||||
import java.security.spec.RSAKeyGenParameterSpec;
|
import java.security.spec.RSAKeyGenParameterSpec;
|
||||||
import java.security.spec.InvalidKeySpecException;
|
|
||||||
import java.security.interfaces.RSAPrivateKey;
|
import java.security.interfaces.RSAPrivateKey;
|
||||||
import java.security.interfaces.RSAPublicKey;
|
import java.security.interfaces.RSAPublicKey;
|
||||||
import java.security.interfaces.ECPrivateKey;
|
import java.security.interfaces.ECPrivateKey;
|
||||||
|
@ -56,8 +51,6 @@ import com.wolfssl.wolfcrypt.Ecc;
|
||||||
import com.wolfssl.wolfcrypt.Dh;
|
import com.wolfssl.wolfcrypt.Dh;
|
||||||
import com.wolfssl.wolfcrypt.Rng;
|
import com.wolfssl.wolfcrypt.Rng;
|
||||||
|
|
||||||
import com.wolfssl.provider.jce.WolfCryptDebug;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wolfCrypt JCE KeyPairGenerator wrapper class
|
* wolfCrypt JCE KeyPairGenerator wrapper class
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -29,7 +29,6 @@ import java.security.InvalidAlgorithmParameterException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import javax.crypto.SecretKey;
|
import javax.crypto.SecretKey;
|
||||||
|
|
||||||
import com.wolfssl.wolfcrypt.WolfCrypt;
|
|
||||||
import com.wolfssl.wolfcrypt.Md5;
|
import com.wolfssl.wolfcrypt.Md5;
|
||||||
import com.wolfssl.wolfcrypt.Sha;
|
import com.wolfssl.wolfcrypt.Sha;
|
||||||
import com.wolfssl.wolfcrypt.Sha256;
|
import com.wolfssl.wolfcrypt.Sha256;
|
||||||
|
@ -37,8 +36,6 @@ import com.wolfssl.wolfcrypt.Sha384;
|
||||||
import com.wolfssl.wolfcrypt.Sha512;
|
import com.wolfssl.wolfcrypt.Sha512;
|
||||||
import com.wolfssl.wolfcrypt.Hmac;
|
import com.wolfssl.wolfcrypt.Hmac;
|
||||||
|
|
||||||
import com.wolfssl.provider.jce.WolfCryptDebug;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wolfCrypt JCE Mac wrapper
|
* wolfCrypt JCE Mac wrapper
|
||||||
*/
|
*/
|
||||||
|
@ -53,7 +50,6 @@ public class WolfCryptMac extends MacSpi {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Hmac hmac = null;
|
private Hmac hmac = null;
|
||||||
private HmacType hmacType = null;
|
|
||||||
private int nativeHmacType = 0;
|
private int nativeHmacType = 0;
|
||||||
private int digestSize = 0;
|
private int digestSize = 0;
|
||||||
|
|
||||||
|
@ -63,7 +59,6 @@ public class WolfCryptMac extends MacSpi {
|
||||||
private WolfCryptMac(HmacType type)
|
private WolfCryptMac(HmacType type)
|
||||||
throws NoSuchAlgorithmException {
|
throws NoSuchAlgorithmException {
|
||||||
|
|
||||||
this.hmacType = type;
|
|
||||||
hmac = new Hmac();
|
hmac = new Hmac();
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
@ -125,7 +120,6 @@ public class WolfCryptMac extends MacSpi {
|
||||||
protected void engineInit(Key key, AlgorithmParameterSpec params)
|
protected void engineInit(Key key, AlgorithmParameterSpec params)
|
||||||
throws InvalidKeyException, InvalidAlgorithmParameterException {
|
throws InvalidKeyException, InvalidAlgorithmParameterException {
|
||||||
|
|
||||||
int ret = 0;
|
|
||||||
byte[] encodedKey;
|
byte[] encodedKey;
|
||||||
|
|
||||||
/* key must be of type SecretKey */
|
/* key must be of type SecretKey */
|
||||||
|
|
|
@ -21,12 +21,10 @@
|
||||||
|
|
||||||
package com.wolfssl.provider.jce;
|
package com.wolfssl.provider.jce;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.security.MessageDigestSpi;
|
import java.security.MessageDigestSpi;
|
||||||
import javax.crypto.ShortBufferException;
|
import javax.crypto.ShortBufferException;
|
||||||
|
|
||||||
import com.wolfssl.wolfcrypt.Md5;
|
import com.wolfssl.wolfcrypt.Md5;
|
||||||
import com.wolfssl.provider.jce.WolfCryptDebug;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wolfCrypt JCE MD5 MessageDigest wrapper
|
* wolfCrypt JCE MD5 MessageDigest wrapper
|
||||||
|
|
|
@ -21,12 +21,10 @@
|
||||||
|
|
||||||
package com.wolfssl.provider.jce;
|
package com.wolfssl.provider.jce;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.security.MessageDigestSpi;
|
import java.security.MessageDigestSpi;
|
||||||
import javax.crypto.ShortBufferException;
|
import javax.crypto.ShortBufferException;
|
||||||
|
|
||||||
import com.wolfssl.wolfcrypt.Sha;
|
import com.wolfssl.wolfcrypt.Sha;
|
||||||
import com.wolfssl.provider.jce.WolfCryptDebug;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wolfCrypt JCE SHA-1 MessageDigest wrapper
|
* wolfCrypt JCE SHA-1 MessageDigest wrapper
|
||||||
|
|
|
@ -21,12 +21,10 @@
|
||||||
|
|
||||||
package com.wolfssl.provider.jce;
|
package com.wolfssl.provider.jce;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.security.MessageDigestSpi;
|
import java.security.MessageDigestSpi;
|
||||||
import javax.crypto.ShortBufferException;
|
import javax.crypto.ShortBufferException;
|
||||||
|
|
||||||
import com.wolfssl.wolfcrypt.Sha256;
|
import com.wolfssl.wolfcrypt.Sha256;
|
||||||
import com.wolfssl.provider.jce.WolfCryptDebug;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wolfCrypt JCE SHA2-256 MessageDigest wrapper
|
* wolfCrypt JCE SHA2-256 MessageDigest wrapper
|
||||||
|
|
|
@ -21,12 +21,10 @@
|
||||||
|
|
||||||
package com.wolfssl.provider.jce;
|
package com.wolfssl.provider.jce;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.security.MessageDigestSpi;
|
import java.security.MessageDigestSpi;
|
||||||
import javax.crypto.ShortBufferException;
|
import javax.crypto.ShortBufferException;
|
||||||
|
|
||||||
import com.wolfssl.wolfcrypt.Sha384;
|
import com.wolfssl.wolfcrypt.Sha384;
|
||||||
import com.wolfssl.provider.jce.WolfCryptDebug;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wolfCrypt JCE SHA2-384 MessageDigest wrapper
|
* wolfCrypt JCE SHA2-384 MessageDigest wrapper
|
||||||
|
|
|
@ -21,12 +21,10 @@
|
||||||
|
|
||||||
package com.wolfssl.provider.jce;
|
package com.wolfssl.provider.jce;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.security.MessageDigestSpi;
|
import java.security.MessageDigestSpi;
|
||||||
import javax.crypto.ShortBufferException;
|
import javax.crypto.ShortBufferException;
|
||||||
|
|
||||||
import com.wolfssl.wolfcrypt.Sha512;
|
import com.wolfssl.wolfcrypt.Sha512;
|
||||||
import com.wolfssl.provider.jce.WolfCryptDebug;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wolfCrypt JCE SHA2-512 MessageDigest wrapper
|
* wolfCrypt JCE SHA2-512 MessageDigest wrapper
|
||||||
|
|
|
@ -23,13 +23,12 @@ package com.wolfssl.provider.jce;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.security.spec.InvalidKeySpecException;
|
import java.security.spec.InvalidKeySpecException;
|
||||||
import javax.security.auth.Destroyable;
|
|
||||||
import javax.crypto.interfaces.PBEKey;
|
import javax.crypto.interfaces.PBEKey;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wolfCrypt PBEKey implementation.
|
* wolfCrypt PBEKey implementation.
|
||||||
*/
|
*/
|
||||||
public class WolfCryptPBEKey implements PBEKey, Destroyable {
|
public class WolfCryptPBEKey implements PBEKey {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|
|
@ -46,14 +46,12 @@ import java.security.cert.PKIXCertPathValidatorResult;
|
||||||
import java.security.cert.CRL;
|
import java.security.cert.CRL;
|
||||||
import java.security.cert.X509CRL;
|
import java.security.cert.X509CRL;
|
||||||
import java.security.cert.X509CRLSelector;
|
import java.security.cert.X509CRLSelector;
|
||||||
import java.security.InvalidAlgorithmParameterException;
|
|
||||||
import javax.security.auth.x500.X500Principal;
|
import javax.security.auth.x500.X500Principal;
|
||||||
|
|
||||||
import com.wolfssl.wolfcrypt.Fips;
|
import com.wolfssl.wolfcrypt.Fips;
|
||||||
import com.wolfssl.wolfcrypt.WolfCrypt;
|
import com.wolfssl.wolfcrypt.WolfCrypt;
|
||||||
import com.wolfssl.wolfcrypt.WolfSSLCertManager;
|
import com.wolfssl.wolfcrypt.WolfSSLCertManager;
|
||||||
import com.wolfssl.wolfcrypt.WolfCryptException;
|
import com.wolfssl.wolfcrypt.WolfCryptException;
|
||||||
import com.wolfssl.provider.jce.WolfCryptDebug;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wolfJCE implementation of CertPathValidator for PKIX (X.509)
|
* wolfJCE implementation of CertPathValidator for PKIX (X.509)
|
||||||
|
@ -265,7 +263,6 @@ public class WolfCryptPKIXCertPathValidator extends CertPathValidatorSpi {
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
List<PKIXCertPathChecker> pathCheckers = null;
|
List<PKIXCertPathChecker> pathCheckers = null;
|
||||||
PKIXCertPathChecker checker = null;
|
|
||||||
|
|
||||||
if (cert == null || params == null) {
|
if (cert == null || params == null) {
|
||||||
throw new CertPathValidatorException(
|
throw new CertPathValidatorException(
|
||||||
|
|
|
@ -27,7 +27,6 @@ import java.io.IOException;
|
||||||
import java.security.SecureRandomSpi;
|
import java.security.SecureRandomSpi;
|
||||||
|
|
||||||
import com.wolfssl.wolfcrypt.Rng;
|
import com.wolfssl.wolfcrypt.Rng;
|
||||||
import com.wolfssl.provider.jce.WolfCryptDebug;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wolfCrypt JCE RNG/SecureRandom wrapper
|
* wolfCrypt JCE RNG/SecureRandom wrapper
|
||||||
|
|
|
@ -36,7 +36,6 @@ import java.security.spec.InvalidKeySpecException;
|
||||||
|
|
||||||
import com.wolfssl.wolfcrypt.WolfCrypt;
|
import com.wolfssl.wolfcrypt.WolfCrypt;
|
||||||
import com.wolfssl.wolfcrypt.Pwdbased;
|
import com.wolfssl.wolfcrypt.Pwdbased;
|
||||||
import com.wolfssl.provider.jce.WolfCryptDebug;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wolfCrypt JCE SecretKeyFactory implementation.
|
* wolfCrypt JCE SecretKeyFactory implementation.
|
||||||
|
@ -435,12 +434,6 @@ public class WolfCryptSecretKeyFactory extends SecretKeyFactorySpi {
|
||||||
protected synchronized KeySpec engineGetKeySpec(SecretKey key,
|
protected synchronized KeySpec engineGetKeySpec(SecretKey key,
|
||||||
Class<?> keySpec) throws InvalidKeySpecException {
|
Class<?> keySpec) throws InvalidKeySpecException {
|
||||||
|
|
||||||
PBEKey pKey = null;
|
|
||||||
int iterations = 0;
|
|
||||||
char[] password = null;
|
|
||||||
byte[] salt = null;
|
|
||||||
byte[] encoded = null;
|
|
||||||
|
|
||||||
log("returning KeySpec from SecretKey in requested type");
|
log("returning KeySpec from SecretKey in requested type");
|
||||||
|
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
|
|
|
@ -21,8 +21,6 @@
|
||||||
|
|
||||||
package com.wolfssl.provider.jce;
|
package com.wolfssl.provider.jce;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import java.security.SignatureSpi;
|
import java.security.SignatureSpi;
|
||||||
import java.security.PrivateKey;
|
import java.security.PrivateKey;
|
||||||
import java.security.PublicKey;
|
import java.security.PublicKey;
|
||||||
|
@ -38,7 +36,6 @@ import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
import javax.crypto.ShortBufferException;
|
import javax.crypto.ShortBufferException;
|
||||||
|
|
||||||
import com.wolfssl.wolfcrypt.WolfCrypt;
|
|
||||||
import com.wolfssl.wolfcrypt.Asn;
|
import com.wolfssl.wolfcrypt.Asn;
|
||||||
import com.wolfssl.wolfcrypt.Md5;
|
import com.wolfssl.wolfcrypt.Md5;
|
||||||
import com.wolfssl.wolfcrypt.Sha;
|
import com.wolfssl.wolfcrypt.Sha;
|
||||||
|
@ -50,8 +47,6 @@ import com.wolfssl.wolfcrypt.Ecc;
|
||||||
import com.wolfssl.wolfcrypt.Rng;
|
import com.wolfssl.wolfcrypt.Rng;
|
||||||
import com.wolfssl.wolfcrypt.WolfCryptException;
|
import com.wolfssl.wolfcrypt.WolfCryptException;
|
||||||
|
|
||||||
import com.wolfssl.provider.jce.WolfCryptDebug;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wolfCrypt JCE Signature wrapper
|
* wolfCrypt JCE Signature wrapper
|
||||||
*/
|
*/
|
||||||
|
@ -77,9 +72,6 @@ public class WolfCryptSignature extends SignatureSpi {
|
||||||
private int SHA384h = 415;
|
private int SHA384h = 415;
|
||||||
private int SHA512h = 416;
|
private int SHA512h = 416;
|
||||||
|
|
||||||
/* internal asn object */
|
|
||||||
private Asn asn = null;
|
|
||||||
|
|
||||||
/* internal key objects */
|
/* internal key objects */
|
||||||
private Rsa rsa = null;
|
private Rsa rsa = null;
|
||||||
private Ecc ecc = null;
|
private Ecc ecc = null;
|
||||||
|
@ -121,9 +113,6 @@ public class WolfCryptSignature extends SignatureSpi {
|
||||||
this.rng.init();
|
this.rng.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* init asn object */
|
|
||||||
asn = new Asn();
|
|
||||||
|
|
||||||
/* init hash type */
|
/* init hash type */
|
||||||
switch (dtype) {
|
switch (dtype) {
|
||||||
case WC_MD5:
|
case WC_MD5:
|
||||||
|
@ -179,9 +168,6 @@ public class WolfCryptSignature extends SignatureSpi {
|
||||||
private void wolfCryptInitPrivateKey(PrivateKey key, byte[] encodedKey)
|
private void wolfCryptInitPrivateKey(PrivateKey key, byte[] encodedKey)
|
||||||
throws InvalidKeyException {
|
throws InvalidKeyException {
|
||||||
|
|
||||||
int ret;
|
|
||||||
long[] idx = {0};
|
|
||||||
|
|
||||||
switch (this.keyType) {
|
switch (this.keyType) {
|
||||||
|
|
||||||
case WC_RSA:
|
case WC_RSA:
|
||||||
|
@ -203,9 +189,6 @@ public class WolfCryptSignature extends SignatureSpi {
|
||||||
private void wolfCryptInitPublicKey(PublicKey key, byte[] encodedKey)
|
private void wolfCryptInitPublicKey(PublicKey key, byte[] encodedKey)
|
||||||
throws InvalidKeyException {
|
throws InvalidKeyException {
|
||||||
|
|
||||||
int ret;
|
|
||||||
long[] idx = {0};
|
|
||||||
|
|
||||||
switch(this.keyType) {
|
switch(this.keyType) {
|
||||||
|
|
||||||
case WC_RSA:
|
case WC_RSA:
|
||||||
|
@ -226,7 +209,6 @@ public class WolfCryptSignature extends SignatureSpi {
|
||||||
protected synchronized void engineInitSign(PrivateKey privateKey)
|
protected synchronized void engineInitSign(PrivateKey privateKey)
|
||||||
throws InvalidKeyException {
|
throws InvalidKeyException {
|
||||||
|
|
||||||
int ret;
|
|
||||||
byte[] encodedKey;
|
byte[] encodedKey;
|
||||||
|
|
||||||
if (this.keyType == KeyType.WC_RSA &&
|
if (this.keyType == KeyType.WC_RSA &&
|
||||||
|
@ -293,9 +275,7 @@ public class WolfCryptSignature extends SignatureSpi {
|
||||||
protected synchronized void engineInitVerify(PublicKey publicKey)
|
protected synchronized void engineInitVerify(PublicKey publicKey)
|
||||||
throws InvalidKeyException {
|
throws InvalidKeyException {
|
||||||
|
|
||||||
int ret;
|
|
||||||
byte[] encodedKey;
|
byte[] encodedKey;
|
||||||
long[] idx = {0};
|
|
||||||
|
|
||||||
if (this.keyType == KeyType.WC_RSA &&
|
if (this.keyType == KeyType.WC_RSA &&
|
||||||
!(publicKey instanceof RSAPublicKey)) {
|
!(publicKey instanceof RSAPublicKey)) {
|
||||||
|
@ -369,7 +349,6 @@ public class WolfCryptSignature extends SignatureSpi {
|
||||||
@Override
|
@Override
|
||||||
protected synchronized byte[] engineSign() throws SignatureException {
|
protected synchronized byte[] engineSign() throws SignatureException {
|
||||||
|
|
||||||
int ret = 0;
|
|
||||||
int encodedSz = 0;
|
int encodedSz = 0;
|
||||||
|
|
||||||
byte[] digest = new byte[this.digestSz];
|
byte[] digest = new byte[this.digestSz];
|
||||||
|
@ -493,7 +472,6 @@ public class WolfCryptSignature extends SignatureSpi {
|
||||||
protected synchronized boolean engineVerify(byte[] sigBytes)
|
protected synchronized boolean engineVerify(byte[] sigBytes)
|
||||||
throws SignatureException {
|
throws SignatureException {
|
||||||
|
|
||||||
int ret = 0;
|
|
||||||
long encodedSz = 0;
|
long encodedSz = 0;
|
||||||
boolean verified = true;
|
boolean verified = true;
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ import java.util.Date;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
@ -33,7 +32,6 @@ import java.io.ByteArrayOutputStream;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.security.Key;
|
import java.security.Key;
|
||||||
import java.security.KeyStoreSpi;
|
import java.security.KeyStoreSpi;
|
||||||
import java.security.PrivateKey;
|
import java.security.PrivateKey;
|
||||||
|
@ -42,7 +40,6 @@ import java.security.KeyFactory;
|
||||||
import java.security.Security;
|
import java.security.Security;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.UnrecoverableKeyException;
|
import java.security.UnrecoverableKeyException;
|
||||||
import java.security.UnrecoverableEntryException;
|
|
||||||
import java.security.KeyStoreException;
|
import java.security.KeyStoreException;
|
||||||
import java.security.NoSuchProviderException;
|
import java.security.NoSuchProviderException;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
|
@ -57,7 +54,6 @@ import java.security.cert.CertificateEncodingException;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import javax.crypto.Cipher;
|
import javax.crypto.Cipher;
|
||||||
import javax.crypto.SecretKey;
|
import javax.crypto.SecretKey;
|
||||||
import javax.crypto.SecretKeyFactory;
|
|
||||||
import javax.crypto.Mac;
|
import javax.crypto.Mac;
|
||||||
import javax.crypto.NoSuchPaddingException;
|
import javax.crypto.NoSuchPaddingException;
|
||||||
import javax.crypto.IllegalBlockSizeException;
|
import javax.crypto.IllegalBlockSizeException;
|
||||||
|
@ -72,7 +68,6 @@ import com.wolfssl.wolfcrypt.Pwdbased;
|
||||||
import com.wolfssl.wolfcrypt.WolfCrypt;
|
import com.wolfssl.wolfcrypt.WolfCrypt;
|
||||||
import com.wolfssl.wolfcrypt.WolfSSLCertManager;
|
import com.wolfssl.wolfcrypt.WolfSSLCertManager;
|
||||||
import com.wolfssl.wolfcrypt.WolfCryptException;
|
import com.wolfssl.wolfcrypt.WolfCryptException;
|
||||||
import com.wolfssl.provider.jce.WolfCryptDebug;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wolfSSL KeyStore implementation (WKS).
|
* wolfSSL KeyStore implementation (WKS).
|
||||||
|
@ -638,7 +633,6 @@ public class WolfSSLKeyStore extends KeyStoreSpi {
|
||||||
KeyFactory keyFact = null;
|
KeyFactory keyFact = null;
|
||||||
|
|
||||||
SecretKey sKey = null;
|
SecretKey sKey = null;
|
||||||
SecretKeySpec skSpec = null;
|
|
||||||
|
|
||||||
log("returning Key entry for alias: " + alias);
|
log("returning Key entry for alias: " + alias);
|
||||||
|
|
||||||
|
@ -1640,7 +1634,6 @@ public class WolfSSLKeyStore extends KeyStoreSpi {
|
||||||
int saltLen = 0;
|
int saltLen = 0;
|
||||||
int hmacLen = 0;
|
int hmacLen = 0;
|
||||||
int iterations = 0;
|
int iterations = 0;
|
||||||
byte[] streamBytes = null;
|
|
||||||
byte[] encodedEntry = null;
|
byte[] encodedEntry = null;
|
||||||
byte[] salt = null;
|
byte[] salt = null;
|
||||||
byte[] hmac = null;
|
byte[] hmac = null;
|
||||||
|
@ -1862,9 +1855,6 @@ public class WolfSSLKeyStore extends KeyStoreSpi {
|
||||||
Date creationDate; /* creation date for this object */
|
Date creationDate; /* creation date for this object */
|
||||||
byte[] hmacSha512; /* HMAC calculated over members and lengths */
|
byte[] hmacSha512; /* HMAC calculated over members and lengths */
|
||||||
|
|
||||||
protected WKSPrivateKey() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new WKSPrivateKey from plaintext key and certificate chain,
|
* Create new WKSPrivateKey from plaintext key and certificate chain,
|
||||||
* encrypt/protect plaintext key using provided password.
|
* encrypt/protect plaintext key using provided password.
|
||||||
|
@ -2336,7 +2326,6 @@ public class WolfSSLKeyStore extends KeyStoreSpi {
|
||||||
protected WKSCertificate(byte[] encoded)
|
protected WKSCertificate(byte[] encoded)
|
||||||
throws IOException, CertificateException {
|
throws IOException, CertificateException {
|
||||||
|
|
||||||
int i;
|
|
||||||
int tmp = 0;
|
int tmp = 0;
|
||||||
byte[] tmpArr = null;
|
byte[] tmpArr = null;
|
||||||
String tmpStr = null;
|
String tmpStr = null;
|
||||||
|
@ -2344,7 +2333,6 @@ public class WolfSSLKeyStore extends KeyStoreSpi {
|
||||||
ByteArrayInputStream certStream = null;
|
ByteArrayInputStream certStream = null;
|
||||||
DataInputStream dis = null;
|
DataInputStream dis = null;
|
||||||
CertificateFactory cf = null;
|
CertificateFactory cf = null;
|
||||||
Certificate tmpCert = null;
|
|
||||||
|
|
||||||
if (encoded == null || encoded.length == 0) {
|
if (encoded == null || encoded.length == 0) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
|
@ -2406,7 +2394,6 @@ public class WolfSSLKeyStore extends KeyStoreSpi {
|
||||||
protected synchronized byte[] getEncoded()
|
protected synchronized byte[] getEncoded()
|
||||||
throws IOException, CertificateEncodingException {
|
throws IOException, CertificateEncodingException {
|
||||||
|
|
||||||
int i;
|
|
||||||
byte[] out = null;
|
byte[] out = null;
|
||||||
ByteArrayOutputStream bos = null;
|
ByteArrayOutputStream bos = null;
|
||||||
DataOutputStream dos = null;
|
DataOutputStream dos = null;
|
||||||
|
@ -2472,9 +2459,6 @@ public class WolfSSLKeyStore extends KeyStoreSpi {
|
||||||
Date creationDate = null; /* creation date for this object */
|
Date creationDate = null; /* creation date for this object */
|
||||||
byte[] hmacSha512 = null; /* HMAC over members and lengths */
|
byte[] hmacSha512 = null; /* HMAC over members and lengths */
|
||||||
|
|
||||||
protected WKSSecretKey() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new WKSSecretKey from plaintext key, encrypt/protect using
|
* Create new WKSSecretKey from plaintext key, encrypt/protect using
|
||||||
* provided password.
|
* provided password.
|
||||||
|
@ -2595,12 +2579,8 @@ public class WolfSSLKeyStore extends KeyStoreSpi {
|
||||||
protected WKSSecretKey(byte[] encoded)
|
protected WKSSecretKey(byte[] encoded)
|
||||||
throws IOException, CertificateException {
|
throws IOException, CertificateException {
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
int tmp = 0;
|
int tmp = 0;
|
||||||
byte[] tmpArr = null;
|
|
||||||
String tmpStr = null;
|
|
||||||
ByteArrayInputStream bis = null;
|
ByteArrayInputStream bis = null;
|
||||||
ByteArrayInputStream certStream = null;
|
|
||||||
DataInputStream dis = null;
|
DataInputStream dis = null;
|
||||||
|
|
||||||
if (encoded == null || encoded.length == 0) {
|
if (encoded == null || encoded.length == 0) {
|
||||||
|
@ -2711,7 +2691,6 @@ public class WolfSSLKeyStore extends KeyStoreSpi {
|
||||||
protected synchronized byte[] getEncoded(boolean withHMAC)
|
protected synchronized byte[] getEncoded(boolean withHMAC)
|
||||||
throws IOException, CertificateEncodingException {
|
throws IOException, CertificateEncodingException {
|
||||||
|
|
||||||
int i;
|
|
||||||
byte[] out = null;
|
byte[] out = null;
|
||||||
ByteArrayOutputStream bos = null;
|
ByteArrayOutputStream bos = null;
|
||||||
DataOutputStream dos = null;
|
DataOutputStream dos = null;
|
||||||
|
|
|
@ -21,8 +21,6 @@
|
||||||
|
|
||||||
package com.wolfssl.wolfcrypt;
|
package com.wolfssl.wolfcrypt;
|
||||||
|
|
||||||
import java.security.InvalidAlgorithmParameterException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper for the native WolfCrypt ChaCha implementation.
|
* Wrapper for the native WolfCrypt ChaCha implementation.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -21,11 +21,6 @@
|
||||||
|
|
||||||
package com.wolfssl.wolfcrypt;
|
package com.wolfssl.wolfcrypt;
|
||||||
|
|
||||||
import java.security.InvalidAlgorithmParameterException;
|
|
||||||
import java.security.spec.EllipticCurve;
|
|
||||||
import java.security.spec.ECParameterSpec;
|
|
||||||
import java.security.spec.ECFieldFp;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper for the native WolfCrypt Curve25519 implementation.
|
* Wrapper for the native WolfCrypt Curve25519 implementation.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -311,8 +311,6 @@ public class Dh extends NativeStruct {
|
||||||
public synchronized byte[] makeSharedSecret(Dh pubKey)
|
public synchronized byte[] makeSharedSecret(Dh pubKey)
|
||||||
throws WolfCryptException, IllegalStateException {
|
throws WolfCryptException, IllegalStateException {
|
||||||
|
|
||||||
byte[] publicKey = null;
|
|
||||||
|
|
||||||
if (pubKey == null) {
|
if (pubKey == null) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"Provided public key is null");
|
"Provided public key is null");
|
||||||
|
|
|
@ -26,8 +26,6 @@ import java.security.spec.EllipticCurve;
|
||||||
import java.security.spec.ECParameterSpec;
|
import java.security.spec.ECParameterSpec;
|
||||||
import java.security.spec.ECFieldFp;
|
import java.security.spec.ECFieldFp;
|
||||||
|
|
||||||
import com.wolfssl.wolfcrypt.Rng;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper for the native WolfCrypt ECC implementation
|
* Wrapper for the native WolfCrypt ECC implementation
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -21,8 +21,6 @@
|
||||||
|
|
||||||
package com.wolfssl.wolfcrypt;
|
package com.wolfssl.wolfcrypt;
|
||||||
|
|
||||||
import java.security.InvalidAlgorithmParameterException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper for the native WolfCrypt Ed25519 implementation
|
* Wrapper for the native WolfCrypt Ed25519 implementation
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
package com.wolfssl.wolfcrypt;
|
package com.wolfssl.wolfcrypt;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import com.wolfssl.wolfcrypt.Aes;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thin JNI wrapper for the native WolfCrypt FIPS 140-2/3 specific APIs.
|
* Thin JNI wrapper for the native WolfCrypt FIPS 140-2/3 specific APIs.
|
||||||
|
|
|
@ -21,8 +21,6 @@
|
||||||
|
|
||||||
package com.wolfssl.wolfcrypt;
|
package com.wolfssl.wolfcrypt;
|
||||||
|
|
||||||
import com.wolfssl.wolfcrypt.WolfCrypt;
|
|
||||||
import com.wolfssl.wolfcrypt.WolfCryptException;
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,15 +21,6 @@
|
||||||
|
|
||||||
package com.wolfssl.wolfcrypt;
|
package com.wolfssl.wolfcrypt;
|
||||||
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.security.KeyStore;
|
|
||||||
import java.security.KeyStoreException;
|
|
||||||
import java.security.cert.Certificate;
|
|
||||||
import java.security.cert.X509Certificate;
|
|
||||||
import java.security.cert.X509CRL;
|
|
||||||
import java.security.cert.CRLException;
|
|
||||||
import java.security.cert.CertificateEncodingException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Password based key derivation class with wraps native wolfCrypt
|
* Password based key derivation class with wraps native wolfCrypt
|
||||||
* pwdbased.c/h APIs.
|
* pwdbased.c/h APIs.
|
||||||
|
|
|
@ -21,8 +21,6 @@
|
||||||
|
|
||||||
package com.wolfssl.wolfcrypt;
|
package com.wolfssl.wolfcrypt;
|
||||||
|
|
||||||
import com.wolfssl.wolfcrypt.WolfCryptError;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wolfCrypt exception class
|
* wolfCrypt exception class
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -21,8 +21,6 @@
|
||||||
|
|
||||||
package com.wolfssl.wolfcrypt;
|
package com.wolfssl.wolfcrypt;
|
||||||
|
|
||||||
import com.wolfssl.wolfcrypt.Fips;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loader for the native WolfCrypt implementation.
|
* Loader for the native WolfCrypt implementation.
|
||||||
* All classes in this package must inherit from it.
|
* All classes in this package must inherit from it.
|
||||||
|
|
|
@ -188,7 +188,6 @@ public class WolfSSLCertManager {
|
||||||
public synchronized void CertManagerLoadCAKeyStore(KeyStore ks)
|
public synchronized void CertManagerLoadCAKeyStore(KeyStore ks)
|
||||||
throws IllegalStateException, WolfCryptException {
|
throws IllegalStateException, WolfCryptException {
|
||||||
|
|
||||||
int ret = 0;
|
|
||||||
int loadedCerts = 0;
|
int loadedCerts = 0;
|
||||||
|
|
||||||
confirmObjectIsActive();
|
confirmObjectIsActive();
|
||||||
|
|
|
@ -60,7 +60,6 @@ import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
import java.security.InvalidAlgorithmParameterException;
|
import java.security.InvalidAlgorithmParameterException;
|
||||||
|
|
||||||
import com.wolfssl.wolfcrypt.WolfCrypt;
|
|
||||||
import com.wolfssl.wolfcrypt.FeatureDetect;
|
import com.wolfssl.wolfcrypt.FeatureDetect;
|
||||||
import com.wolfssl.wolfcrypt.Fips;
|
import com.wolfssl.wolfcrypt.Fips;
|
||||||
import com.wolfssl.provider.jce.WolfCryptProvider;
|
import com.wolfssl.provider.jce.WolfCryptProvider;
|
||||||
|
@ -116,8 +115,7 @@ public class WolfCryptCipherTest {
|
||||||
/* populate enabledJCEAlgos to test */
|
/* populate enabledJCEAlgos to test */
|
||||||
for (int i = 0; i < supportedJCEAlgos.length; i++) {
|
for (int i = 0; i < supportedJCEAlgos.length; i++) {
|
||||||
try {
|
try {
|
||||||
Cipher c = Cipher.getInstance(
|
Cipher.getInstance(supportedJCEAlgos[i], jceProvider);
|
||||||
supportedJCEAlgos[i], jceProvider);
|
|
||||||
enabledJCEAlgos.add(supportedJCEAlgos[i]);
|
enabledJCEAlgos.add(supportedJCEAlgos[i]);
|
||||||
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
@ -146,17 +144,15 @@ public class WolfCryptCipherTest {
|
||||||
throws NoSuchProviderException, NoSuchAlgorithmException,
|
throws NoSuchProviderException, NoSuchAlgorithmException,
|
||||||
NoSuchPaddingException {
|
NoSuchPaddingException {
|
||||||
|
|
||||||
Cipher cipher;
|
|
||||||
|
|
||||||
/* try to get all available options we expect to have */
|
/* try to get all available options we expect to have */
|
||||||
for (int i = 0; i < enabledJCEAlgos.size(); i++) {
|
for (int i = 0; i < enabledJCEAlgos.size(); i++) {
|
||||||
cipher = Cipher.getInstance(enabledJCEAlgos.get(i), jceProvider);
|
Cipher.getInstance(enabledJCEAlgos.get(i), jceProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* getting a garbage algorithm should throw
|
/* getting a garbage algorithm should throw
|
||||||
* a NoSuchAlgorithmException */
|
* a NoSuchAlgorithmException */
|
||||||
try {
|
try {
|
||||||
cipher = Cipher.getInstance("NotValid", jceProvider);
|
Cipher.getInstance("NotValid", jceProvider);
|
||||||
|
|
||||||
fail("Cipher.getInstance should throw NoSuchAlgorithmException " +
|
fail("Cipher.getInstance should throw NoSuchAlgorithmException " +
|
||||||
"when given bad algorithm value");
|
"when given bad algorithm value");
|
||||||
|
@ -2792,8 +2788,6 @@ public class WolfCryptCipherTest {
|
||||||
BadPaddingException {
|
BadPaddingException {
|
||||||
|
|
||||||
byte[] tmp = null;
|
byte[] tmp = null;
|
||||||
byte[] ciphertext = null;
|
|
||||||
byte[] plaintext = null;
|
|
||||||
|
|
||||||
byte[] inputA = new byte[2048];
|
byte[] inputA = new byte[2048];
|
||||||
byte[] inputB = new byte[100];
|
byte[] inputB = new byte[100];
|
||||||
|
@ -2824,7 +2818,7 @@ public class WolfCryptCipherTest {
|
||||||
assertEquals(tmp.length, 0);
|
assertEquals(tmp.length, 0);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ciphertext = ciph.doFinal();
|
ciph.doFinal();
|
||||||
fail("Cipher.doFinal should throw exception when data " +
|
fail("Cipher.doFinal should throw exception when data " +
|
||||||
"is larger than RSA key size");
|
"is larger than RSA key size");
|
||||||
} catch (WolfCryptException | IllegalBlockSizeException e) {
|
} catch (WolfCryptException | IllegalBlockSizeException e) {
|
||||||
|
@ -2843,7 +2837,7 @@ public class WolfCryptCipherTest {
|
||||||
assertEquals(tmp.length, 0);
|
assertEquals(tmp.length, 0);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
plaintext = ciph.doFinal();
|
ciph.doFinal();
|
||||||
fail("Cipher.doFinal should throw exception when data " +
|
fail("Cipher.doFinal should throw exception when data " +
|
||||||
"is larger than RSA key size");
|
"is larger than RSA key size");
|
||||||
} catch (WolfCryptException | IllegalBlockSizeException e) {
|
} catch (WolfCryptException | IllegalBlockSizeException e) {
|
||||||
|
@ -2862,7 +2856,7 @@ public class WolfCryptCipherTest {
|
||||||
assertEquals(tmp.length, 0);
|
assertEquals(tmp.length, 0);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ciphertext = ciph.doFinal();
|
ciph.doFinal();
|
||||||
fail("Cipher.doFinal should throw exception when data " +
|
fail("Cipher.doFinal should throw exception when data " +
|
||||||
"is larger than RSA key size");
|
"is larger than RSA key size");
|
||||||
} catch (WolfCryptException | IllegalBlockSizeException e) {
|
} catch (WolfCryptException | IllegalBlockSizeException e) {
|
||||||
|
@ -2881,7 +2875,7 @@ public class WolfCryptCipherTest {
|
||||||
assertEquals(tmp.length, 0);
|
assertEquals(tmp.length, 0);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
plaintext = ciph.doFinal();
|
ciph.doFinal();
|
||||||
fail("Cipher.doFinal should throw exception when data " +
|
fail("Cipher.doFinal should throw exception when data " +
|
||||||
"is larger than RSA key size");
|
"is larger than RSA key size");
|
||||||
} catch (WolfCryptException | IllegalBlockSizeException e) {
|
} catch (WolfCryptException | IllegalBlockSizeException e) {
|
||||||
|
@ -3033,30 +3027,6 @@ public class WolfCryptCipherTest {
|
||||||
this.aad = aad;
|
this.aad = aad;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKey(byte[] key) {
|
|
||||||
this.key = key;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIV(byte[] iv) {
|
|
||||||
this.iv = iv;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInput(byte[] input) {
|
|
||||||
this.input = input;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOutput(byte[] output) {
|
|
||||||
this.output = output;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTag(byte[] tag) {
|
|
||||||
this.tag = tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAad(byte[] aad) {
|
|
||||||
this.aad = aad;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getKey() {
|
public byte[] getKey() {
|
||||||
return this.key;
|
return this.key;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,8 +31,6 @@ import org.junit.BeforeClass;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
@ -108,7 +106,7 @@ public class WolfCryptKeyAgreementTest {
|
||||||
/* One static SecureRandom to share */
|
/* One static SecureRandom to share */
|
||||||
private static SecureRandom secureRandom = new SecureRandom();
|
private static SecureRandom secureRandom = new SecureRandom();
|
||||||
|
|
||||||
private static void printDisabledCurves() {
|
/*private static void printDisabledCurves() {
|
||||||
|
|
||||||
if (disabledCurves.size() > 0)
|
if (disabledCurves.size() > 0)
|
||||||
System.out.print("KeyAgreement: skipping disabled ECC curves:\n\t");
|
System.out.print("KeyAgreement: skipping disabled ECC curves:\n\t");
|
||||||
|
@ -123,7 +121,7 @@ public class WolfCryptKeyAgreementTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@Rule(order = Integer.MIN_VALUE)
|
@Rule(order = Integer.MIN_VALUE)
|
||||||
public TestRule testWatcher = new TestWatcher() {
|
public TestRule testWatcher = new TestWatcher() {
|
||||||
|
@ -135,8 +133,6 @@ public class WolfCryptKeyAgreementTest {
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void testProviderInstallationAtRuntime() {
|
public static void testProviderInstallationAtRuntime() {
|
||||||
|
|
||||||
int disabledCount = 0;
|
|
||||||
|
|
||||||
System.out.println("JCE WolfCryptKeyAgreementTest Class");
|
System.out.println("JCE WolfCryptKeyAgreementTest Class");
|
||||||
|
|
||||||
/* install wolfJCE provider at runtime */
|
/* install wolfJCE provider at runtime */
|
||||||
|
@ -147,10 +143,9 @@ public class WolfCryptKeyAgreementTest {
|
||||||
|
|
||||||
/* build list of enabled curves and key sizes,
|
/* build list of enabled curves and key sizes,
|
||||||
* getCurveSizeFromName() will return 0 if curve not found */
|
* getCurveSizeFromName() will return 0 if curve not found */
|
||||||
Ecc tmp = new Ecc();
|
|
||||||
for (int i = 0; i < supportedCurves.length; i++) {
|
for (int i = 0; i < supportedCurves.length; i++) {
|
||||||
|
|
||||||
int size = tmp.getCurveSizeFromName(
|
int size = Ecc.getCurveSizeFromName(
|
||||||
supportedCurves[i].toUpperCase());
|
supportedCurves[i].toUpperCase());
|
||||||
|
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
|
@ -160,7 +155,7 @@ public class WolfCryptKeyAgreementTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* uncomment this line to print disabled curves */
|
/* uncomment this line and method above to print disabled curves */
|
||||||
/* printDisabledCurves(); */
|
/* printDisabledCurves(); */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,16 +163,14 @@ public class WolfCryptKeyAgreementTest {
|
||||||
public void testGetKeyAgreementFromProvider()
|
public void testGetKeyAgreementFromProvider()
|
||||||
throws NoSuchProviderException, NoSuchAlgorithmException {
|
throws NoSuchProviderException, NoSuchAlgorithmException {
|
||||||
|
|
||||||
KeyAgreement ka;
|
|
||||||
|
|
||||||
/* try to get all available options we expect to have */
|
/* try to get all available options we expect to have */
|
||||||
for (int i = 0; i < wolfJCEAlgos.length; i++) {
|
for (int i = 0; i < wolfJCEAlgos.length; i++) {
|
||||||
ka = KeyAgreement.getInstance(wolfJCEAlgos[i], "wolfJCE");
|
KeyAgreement.getInstance(wolfJCEAlgos[i], "wolfJCE");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* getting a garbage algorithm should throw an exception */
|
/* getting a garbage algorithm should throw an exception */
|
||||||
try {
|
try {
|
||||||
ka = KeyAgreement.getInstance("NotValid", "wolfJCE");
|
KeyAgreement.getInstance("NotValid", "wolfJCE");
|
||||||
|
|
||||||
fail("KeyAgreement.getInstance should throw " +
|
fail("KeyAgreement.getInstance should throw " +
|
||||||
"NoSuchAlgorithmException when given bad algorithm value");
|
"NoSuchAlgorithmException when given bad algorithm value");
|
||||||
|
@ -272,6 +265,7 @@ public class WolfCryptKeyAgreementTest {
|
||||||
int secretASz = aKeyAgree.generateSecret(secretA, 0);
|
int secretASz = aKeyAgree.generateSecret(secretA, 0);
|
||||||
int secretBSz = bKeyAgree.generateSecret(secretB, 0);
|
int secretBSz = bKeyAgree.generateSecret(secretB, 0);
|
||||||
|
|
||||||
|
assertEquals(secretASz, secretBSz);
|
||||||
assertArrayEquals(secretA, secretB);
|
assertArrayEquals(secretA, secretB);
|
||||||
|
|
||||||
/* now, try reusing the A object without calling init() again */
|
/* now, try reusing the A object without calling init() again */
|
||||||
|
@ -287,6 +281,7 @@ public class WolfCryptKeyAgreementTest {
|
||||||
int secretA2Sz = aKeyAgree.generateSecret(secretA2, 0);
|
int secretA2Sz = aKeyAgree.generateSecret(secretA2, 0);
|
||||||
int secretCSz = cKeyAgree.generateSecret(secretC, 0);
|
int secretCSz = cKeyAgree.generateSecret(secretC, 0);
|
||||||
|
|
||||||
|
assertEquals(secretA2Sz, secretCSz);
|
||||||
assertArrayEquals(secretA2, secretC);
|
assertArrayEquals(secretA2, secretC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,14 +387,19 @@ public class WolfCryptKeyAgreementTest {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyAgreement ka = KeyAgreement.getInstance("ECDH", "wolfJCE");
|
KeyAgreement ka =
|
||||||
|
KeyAgreement.getInstance("ECDH", "wolfJCE");
|
||||||
|
|
||||||
|
assertNotNull(ka);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Trying to use a bad curve should throw an exception */
|
/* Trying to use a bad curve should throw an exception */
|
||||||
try {
|
try {
|
||||||
ecsp = new ECGenParameterSpec("invalidcurve");
|
ecsp = new ECGenParameterSpec("invalidcurve");
|
||||||
keyGen.initialize(ecsp);
|
keyGen.initialize(ecsp);
|
||||||
KeyAgreement ka = KeyAgreement.getInstance("ECDH", "wolfJCE");
|
KeyAgreement ka =
|
||||||
|
KeyAgreement.getInstance("ECDH", "wolfJCE");
|
||||||
|
assertNotNull(ka);
|
||||||
|
|
||||||
fail("Initializing KeyAgreement with invalid curve spec " +
|
fail("Initializing KeyAgreement with invalid curve spec " +
|
||||||
"should throw exception");
|
"should throw exception");
|
||||||
|
@ -478,6 +478,7 @@ public class WolfCryptKeyAgreementTest {
|
||||||
int secretASz = aKeyAgree.generateSecret(secretA, 0);
|
int secretASz = aKeyAgree.generateSecret(secretA, 0);
|
||||||
int secretBSz = bKeyAgree.generateSecret(secretB, 0);
|
int secretBSz = bKeyAgree.generateSecret(secretB, 0);
|
||||||
|
|
||||||
|
assertEquals(secretASz, secretBSz);
|
||||||
assertArrayEquals(secretA, secretB);
|
assertArrayEquals(secretA, secretB);
|
||||||
|
|
||||||
/* now, try reusing the A object without calling init() again */
|
/* now, try reusing the A object without calling init() again */
|
||||||
|
@ -493,6 +494,7 @@ public class WolfCryptKeyAgreementTest {
|
||||||
int secretA2Sz = aKeyAgree.generateSecret(secretA2, 0);
|
int secretA2Sz = aKeyAgree.generateSecret(secretA2, 0);
|
||||||
int secretCSz = cKeyAgree.generateSecret(secretC, 0);
|
int secretCSz = cKeyAgree.generateSecret(secretC, 0);
|
||||||
|
|
||||||
|
assertEquals(secretA2Sz, secretCSz);
|
||||||
assertArrayEquals(secretA2, secretC);
|
assertArrayEquals(secretA2, secretC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,25 +32,18 @@ import org.junit.BeforeClass;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
|
||||||
import javax.crypto.KeyAgreement;
|
|
||||||
import javax.crypto.ShortBufferException;
|
|
||||||
import javax.crypto.spec.DHParameterSpec;
|
import javax.crypto.spec.DHParameterSpec;
|
||||||
|
|
||||||
import java.security.Security;
|
import java.security.Security;
|
||||||
import java.security.Provider;
|
import java.security.Provider;
|
||||||
import java.security.NoSuchProviderException;
|
import java.security.NoSuchProviderException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.InvalidKeyException;
|
|
||||||
import java.security.KeyPair;
|
import java.security.KeyPair;
|
||||||
import java.security.KeyPairGenerator;
|
import java.security.KeyPairGenerator;
|
||||||
import java.security.AlgorithmParameters;
|
|
||||||
import java.security.AlgorithmParameterGenerator;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.security.PublicKey;
|
import java.security.PublicKey;
|
||||||
import java.security.PrivateKey;
|
import java.security.PrivateKey;
|
||||||
import java.security.KeyFactory;
|
import java.security.KeyFactory;
|
||||||
import java.security.InvalidAlgorithmParameterException;
|
import java.security.InvalidAlgorithmParameterException;
|
||||||
import java.security.spec.InvalidParameterSpecException;
|
|
||||||
import java.security.spec.InvalidKeySpecException;
|
import java.security.spec.InvalidKeySpecException;
|
||||||
import java.security.spec.RSAKeyGenParameterSpec;
|
import java.security.spec.RSAKeyGenParameterSpec;
|
||||||
import java.security.spec.ECGenParameterSpec;
|
import java.security.spec.ECGenParameterSpec;
|
||||||
|
@ -167,7 +160,6 @@ public class WolfCryptKeyPairGeneratorTest {
|
||||||
|
|
||||||
/* build list of enabled curves and key sizes,
|
/* build list of enabled curves and key sizes,
|
||||||
* getCurveSizeFromName() will return 0 if curve not found */
|
* getCurveSizeFromName() will return 0 if curve not found */
|
||||||
Ecc tmp = new Ecc();
|
|
||||||
String[] curves = null;
|
String[] curves = null;
|
||||||
|
|
||||||
if (Fips.enabled && Fips.fipsVersion >= 5) {
|
if (Fips.enabled && Fips.fipsVersion >= 5) {
|
||||||
|
@ -178,7 +170,7 @@ public class WolfCryptKeyPairGeneratorTest {
|
||||||
|
|
||||||
for (int i = 0; i < curves.length; i++) {
|
for (int i = 0; i < curves.length; i++) {
|
||||||
|
|
||||||
int size = tmp.getCurveSizeFromName(curves[i].toUpperCase());
|
int size = Ecc.getCurveSizeFromName(curves[i].toUpperCase());
|
||||||
|
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
enabledCurves.add(curves[i]);
|
enabledCurves.add(curves[i]);
|
||||||
|
@ -196,8 +188,11 @@ public class WolfCryptKeyPairGeneratorTest {
|
||||||
|
|
||||||
KeyPairGenerator kpg;
|
KeyPairGenerator kpg;
|
||||||
kpg = KeyPairGenerator.getInstance("EC", "wolfJCE");
|
kpg = KeyPairGenerator.getInstance("EC", "wolfJCE");
|
||||||
|
assertNotNull(kpg);
|
||||||
kpg = KeyPairGenerator.getInstance("RSA", "wolfJCE");
|
kpg = KeyPairGenerator.getInstance("RSA", "wolfJCE");
|
||||||
|
assertNotNull(kpg);
|
||||||
kpg = KeyPairGenerator.getInstance("DH", "wolfJCE");
|
kpg = KeyPairGenerator.getInstance("DH", "wolfJCE");
|
||||||
|
assertNotNull(kpg);
|
||||||
|
|
||||||
/* getting a garbage algorithm should throw an exception */
|
/* getting a garbage algorithm should throw an exception */
|
||||||
try {
|
try {
|
||||||
|
@ -271,6 +266,7 @@ public class WolfCryptKeyPairGeneratorTest {
|
||||||
kpg.initialize(rsaSpec);
|
kpg.initialize(rsaSpec);
|
||||||
|
|
||||||
KeyPair kp = kpg.generateKeyPair();
|
KeyPair kp = kpg.generateKeyPair();
|
||||||
|
assertNotNull(kp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,6 +306,8 @@ public class WolfCryptKeyPairGeneratorTest {
|
||||||
|
|
||||||
KeyPair kp1 = kpg.generateKeyPair();
|
KeyPair kp1 = kpg.generateKeyPair();
|
||||||
KeyPair kp2 = kpg.generateKeyPair();
|
KeyPair kp2 = kpg.generateKeyPair();
|
||||||
|
assertNotNull(kp1);
|
||||||
|
assertNotNull(kp2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,6 +333,8 @@ public class WolfCryptKeyPairGeneratorTest {
|
||||||
kp.getPublic().getEncoded()));
|
kp.getPublic().getEncoded()));
|
||||||
PrivateKey priv = kf.generatePrivate(new PKCS8EncodedKeySpec(
|
PrivateKey priv = kf.generatePrivate(new PKCS8EncodedKeySpec(
|
||||||
kp.getPrivate().getEncoded()));
|
kp.getPrivate().getEncoded()));
|
||||||
|
assertNotNull(pub);
|
||||||
|
assertNotNull(priv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -402,6 +402,7 @@ public class WolfCryptKeyPairGeneratorTest {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
KeyPair kp = kpg.generateKeyPair();
|
KeyPair kp = kpg.generateKeyPair();
|
||||||
|
assertNotNull(kp);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
/* Some JDK versions' ECKeyFactory may not support all
|
/* Some JDK versions' ECKeyFactory may not support all
|
||||||
* wolfCrypt's ECC curves */
|
* wolfCrypt's ECC curves */
|
||||||
|
@ -446,6 +447,9 @@ public class WolfCryptKeyPairGeneratorTest {
|
||||||
|
|
||||||
KeyPair kp1 = kpg.generateKeyPair();
|
KeyPair kp1 = kpg.generateKeyPair();
|
||||||
KeyPair kp2 = kpg.generateKeyPair();
|
KeyPair kp2 = kpg.generateKeyPair();
|
||||||
|
|
||||||
|
assertNotNull(kp1);
|
||||||
|
assertNotNull(kp2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,6 +474,9 @@ public class WolfCryptKeyPairGeneratorTest {
|
||||||
kp.getPublic().getEncoded()));
|
kp.getPublic().getEncoded()));
|
||||||
PrivateKey priv = kf.generatePrivate(new PKCS8EncodedKeySpec(
|
PrivateKey priv = kf.generatePrivate(new PKCS8EncodedKeySpec(
|
||||||
kp.getPrivate().getEncoded()));
|
kp.getPrivate().getEncoded()));
|
||||||
|
|
||||||
|
assertNotNull(pub);
|
||||||
|
assertNotNull(priv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -492,6 +499,8 @@ public class WolfCryptKeyPairGeneratorTest {
|
||||||
|
|
||||||
kpg.initialize(spec);
|
kpg.initialize(spec);
|
||||||
KeyPair pair = kpg.generateKeyPair();
|
KeyPair pair = kpg.generateKeyPair();
|
||||||
|
|
||||||
|
assertNotNull(pair);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -540,6 +549,9 @@ public class WolfCryptKeyPairGeneratorTest {
|
||||||
|
|
||||||
KeyPair kp1 = kpg.generateKeyPair();
|
KeyPair kp1 = kpg.generateKeyPair();
|
||||||
KeyPair kp2 = kpg.generateKeyPair();
|
KeyPair kp2 = kpg.generateKeyPair();
|
||||||
|
|
||||||
|
assertNotNull(kp1);
|
||||||
|
assertNotNull(kp2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ import org.junit.BeforeClass;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
@ -102,6 +101,7 @@ public class WolfCryptMacTest {
|
||||||
for (int i = 0; i < wolfJCEAlgos.length; i++) {
|
for (int i = 0; i < wolfJCEAlgos.length; i++) {
|
||||||
try {
|
try {
|
||||||
mac = Mac.getInstance(wolfJCEAlgos[i], "wolfJCE");
|
mac = Mac.getInstance(wolfJCEAlgos[i], "wolfJCE");
|
||||||
|
assertNotNull(mac);
|
||||||
enabledAlgos.add(wolfJCEAlgos[i]);
|
enabledAlgos.add(wolfJCEAlgos[i]);
|
||||||
enabledAlgoLengths.add(wolfJCEMacLengths[i]);
|
enabledAlgoLengths.add(wolfJCEMacLengths[i]);
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
@ -119,6 +119,7 @@ public class WolfCryptMacTest {
|
||||||
/* try to get all available options we expect to have */
|
/* try to get all available options we expect to have */
|
||||||
for (int i = 0; i < enabledAlgos.size(); i++) {
|
for (int i = 0; i < enabledAlgos.size(); i++) {
|
||||||
mac = Mac.getInstance(enabledAlgos.get(i), "wolfJCE");
|
mac = Mac.getInstance(enabledAlgos.get(i), "wolfJCE");
|
||||||
|
assertNotNull(mac);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* getting a garbage algorithm should throw an exception */
|
/* getting a garbage algorithm should throw an exception */
|
||||||
|
@ -964,18 +965,6 @@ public class WolfCryptMacTest {
|
||||||
this.output = output;
|
this.output = output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKey(byte[] key) {
|
|
||||||
this.key = key;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInput(byte[] input) {
|
|
||||||
this.input = input;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOutput(byte[] output) {
|
|
||||||
this.output = output;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getKey() {
|
public byte[] getKey() {
|
||||||
return this.key;
|
return this.key;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,8 @@ public class WolfCryptMessageDigestMd5Test {
|
||||||
try {
|
try {
|
||||||
MessageDigest md5 = MessageDigest.getInstance("MD5",
|
MessageDigest md5 = MessageDigest.getInstance("MD5",
|
||||||
"wolfJCE");
|
"wolfJCE");
|
||||||
|
assertNotNull(md5);
|
||||||
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
/* if we also detect algo is compiled out, skip tests */
|
/* if we also detect algo is compiled out, skip tests */
|
||||||
if (FeatureDetect.Md5Enabled() == false) {
|
if (FeatureDetect.Md5Enabled() == false) {
|
||||||
|
|
|
@ -72,6 +72,8 @@ public class WolfCryptMessageDigestSha256Test {
|
||||||
try {
|
try {
|
||||||
MessageDigest sha256 = MessageDigest.getInstance("SHA-256",
|
MessageDigest sha256 = MessageDigest.getInstance("SHA-256",
|
||||||
"wolfJCE");
|
"wolfJCE");
|
||||||
|
assertNotNull(sha256);
|
||||||
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
/* if we also detect algo is compiled out, skip tests */
|
/* if we also detect algo is compiled out, skip tests */
|
||||||
if (FeatureDetect.Sha256Enabled() == false) {
|
if (FeatureDetect.Sha256Enabled() == false) {
|
||||||
|
|
|
@ -72,6 +72,8 @@ public class WolfCryptMessageDigestSha384Test {
|
||||||
try {
|
try {
|
||||||
MessageDigest sha384 = MessageDigest.getInstance("SHA-384",
|
MessageDigest sha384 = MessageDigest.getInstance("SHA-384",
|
||||||
"wolfJCE");
|
"wolfJCE");
|
||||||
|
assertNotNull(sha384);
|
||||||
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
/* if we also detect algo is compiled out, skip tests */
|
/* if we also detect algo is compiled out, skip tests */
|
||||||
if (FeatureDetect.Sha384Enabled() == false) {
|
if (FeatureDetect.Sha384Enabled() == false) {
|
||||||
|
@ -85,40 +87,6 @@ public class WolfCryptMessageDigestSha384Test {
|
||||||
public void testSha384SingleUpdate()
|
public void testSha384SingleUpdate()
|
||||||
throws NoSuchProviderException, NoSuchAlgorithmException {
|
throws NoSuchProviderException, NoSuchAlgorithmException {
|
||||||
|
|
||||||
final String inputA = "abc";
|
|
||||||
final byte expectedA[] = new byte[] {
|
|
||||||
(byte)0xcb, (byte)0x00, (byte)0x75, (byte)0x3f,
|
|
||||||
(byte)0x45, (byte)0xa3, (byte)0x5e, (byte)0x8b,
|
|
||||||
(byte)0xb5, (byte)0xa0, (byte)0x3d, (byte)0x69,
|
|
||||||
(byte)0x9a, (byte)0xc6, (byte)0x50, (byte)0x07,
|
|
||||||
(byte)0x27, (byte)0x2c, (byte)0x32, (byte)0xab,
|
|
||||||
(byte)0x0e, (byte)0xde, (byte)0xd1, (byte)0x63,
|
|
||||||
(byte)0x1a, (byte)0x8b, (byte)0x60, (byte)0x5a,
|
|
||||||
(byte)0x43, (byte)0xff, (byte)0x5b, (byte)0xed,
|
|
||||||
(byte)0x80, (byte)0x86, (byte)0x07, (byte)0x2b,
|
|
||||||
(byte)0xa1, (byte)0xe7, (byte)0xcc, (byte)0x23,
|
|
||||||
(byte)0x58, (byte)0xba, (byte)0xec, (byte)0xa1,
|
|
||||||
(byte)0x34, (byte)0xc8, (byte)0x25, (byte)0xa7
|
|
||||||
};
|
|
||||||
|
|
||||||
final String inputB = "abcdefghbcdefghicdefghijdefghijkefgh" +
|
|
||||||
"ijklfghijklmghijklmnhijklmnoijklmnop" +
|
|
||||||
"jklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
|
|
||||||
final byte expectedB[] = new byte[] {
|
|
||||||
(byte)0x09, (byte)0x33, (byte)0x0c, (byte)0x33,
|
|
||||||
(byte)0xf7, (byte)0x11, (byte)0x47, (byte)0xe8,
|
|
||||||
(byte)0x3d, (byte)0x19, (byte)0x2f, (byte)0xc7,
|
|
||||||
(byte)0x82, (byte)0xcd, (byte)0x1b, (byte)0x47,
|
|
||||||
(byte)0x53, (byte)0x11, (byte)0x1b, (byte)0x17,
|
|
||||||
(byte)0x3b, (byte)0x3b, (byte)0x05, (byte)0xd2,
|
|
||||||
(byte)0x2f, (byte)0xa0, (byte)0x80, (byte)0x86,
|
|
||||||
(byte)0xe3, (byte)0xb0, (byte)0xf7, (byte)0x12,
|
|
||||||
(byte)0xfc, (byte)0xc7, (byte)0xc7, (byte)0x1a,
|
|
||||||
(byte)0x55, (byte)0x7e, (byte)0x2d, (byte)0xb9,
|
|
||||||
(byte)0x66, (byte)0xc3, (byte)0xe9, (byte)0xfa,
|
|
||||||
(byte)0x91, (byte)0x74, (byte)0x60, (byte)0x39
|
|
||||||
};
|
|
||||||
|
|
||||||
DigestVector vectors[] = new DigestVector[] {
|
DigestVector vectors[] = new DigestVector[] {
|
||||||
new DigestVector(
|
new DigestVector(
|
||||||
new String("abc").getBytes(),
|
new String("abc").getBytes(),
|
||||||
|
|
|
@ -72,6 +72,8 @@ public class WolfCryptMessageDigestSha512Test {
|
||||||
try {
|
try {
|
||||||
MessageDigest sha512 = MessageDigest.getInstance("SHA-512",
|
MessageDigest sha512 = MessageDigest.getInstance("SHA-512",
|
||||||
"wolfJCE");
|
"wolfJCE");
|
||||||
|
assertNotNull(sha512);
|
||||||
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
/* if we also detect algo is compiled out, skip tests */
|
/* if we also detect algo is compiled out, skip tests */
|
||||||
if (FeatureDetect.Sha512Enabled() == false) {
|
if (FeatureDetect.Sha512Enabled() == false) {
|
||||||
|
@ -85,48 +87,6 @@ public class WolfCryptMessageDigestSha512Test {
|
||||||
public void testSha512SingleUpdate()
|
public void testSha512SingleUpdate()
|
||||||
throws NoSuchProviderException, NoSuchAlgorithmException {
|
throws NoSuchProviderException, NoSuchAlgorithmException {
|
||||||
|
|
||||||
final String inputA = "abc";
|
|
||||||
final byte expectedA[] = new byte[] {
|
|
||||||
(byte)0xdd, (byte)0xaf, (byte)0x35, (byte)0xa1,
|
|
||||||
(byte)0x93, (byte)0x61, (byte)0x7a, (byte)0xba,
|
|
||||||
(byte)0xcc, (byte)0x41, (byte)0x73, (byte)0x49,
|
|
||||||
(byte)0xae, (byte)0x20, (byte)0x41, (byte)0x31,
|
|
||||||
(byte)0x12, (byte)0xe6, (byte)0xfa, (byte)0x4e,
|
|
||||||
(byte)0x89, (byte)0xa9, (byte)0x7e, (byte)0xa2,
|
|
||||||
(byte)0x0a, (byte)0x9e, (byte)0xee, (byte)0xe6,
|
|
||||||
(byte)0x4b, (byte)0x55, (byte)0xd3, (byte)0x9a,
|
|
||||||
(byte)0x21, (byte)0x92, (byte)0x99, (byte)0x2a,
|
|
||||||
(byte)0x27, (byte)0x4f, (byte)0xc1, (byte)0xa8,
|
|
||||||
(byte)0x36, (byte)0xba, (byte)0x3c, (byte)0x23,
|
|
||||||
(byte)0xa3, (byte)0xfe, (byte)0xeb, (byte)0xbd,
|
|
||||||
(byte)0x45, (byte)0x4d, (byte)0x44, (byte)0x23,
|
|
||||||
(byte)0x64, (byte)0x3c, (byte)0xe8, (byte)0x0e,
|
|
||||||
(byte)0x2a, (byte)0x9a, (byte)0xc9, (byte)0x4f,
|
|
||||||
(byte)0xa5, (byte)0x4c, (byte)0xa4, (byte)0x9f
|
|
||||||
};
|
|
||||||
|
|
||||||
final String inputB = "abcdefghbcdefghicdefghijdefghijkefgh" +
|
|
||||||
"ijklfghijklmghijklmnhijklmnoijklmnop" +
|
|
||||||
"jklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
|
|
||||||
final byte expectedB[] = new byte[] {
|
|
||||||
(byte)0x8e, (byte)0x95, (byte)0x9b, (byte)0x75,
|
|
||||||
(byte)0xda, (byte)0xe3, (byte)0x13, (byte)0xda,
|
|
||||||
(byte)0x8c, (byte)0xf4, (byte)0xf7, (byte)0x28,
|
|
||||||
(byte)0x14, (byte)0xfc, (byte)0x14, (byte)0x3f,
|
|
||||||
(byte)0x8f, (byte)0x77, (byte)0x79, (byte)0xc6,
|
|
||||||
(byte)0xeb, (byte)0x9f, (byte)0x7f, (byte)0xa1,
|
|
||||||
(byte)0x72, (byte)0x99, (byte)0xae, (byte)0xad,
|
|
||||||
(byte)0xb6, (byte)0x88, (byte)0x90, (byte)0x18,
|
|
||||||
(byte)0x50, (byte)0x1d, (byte)0x28, (byte)0x9e,
|
|
||||||
(byte)0x49, (byte)0x00, (byte)0xf7, (byte)0xe4,
|
|
||||||
(byte)0x33, (byte)0x1b, (byte)0x99, (byte)0xde,
|
|
||||||
(byte)0xc4, (byte)0xb5, (byte)0x43, (byte)0x3a,
|
|
||||||
(byte)0xc7, (byte)0xd3, (byte)0x29, (byte)0xee,
|
|
||||||
(byte)0xb6, (byte)0xdd, (byte)0x26, (byte)0x54,
|
|
||||||
(byte)0x5e, (byte)0x96, (byte)0xe5, (byte)0x5b,
|
|
||||||
(byte)0x87, (byte)0x4b, (byte)0xe9, (byte)0x09
|
|
||||||
};
|
|
||||||
|
|
||||||
DigestVector vectors[] = new DigestVector[] {
|
DigestVector vectors[] = new DigestVector[] {
|
||||||
new DigestVector(
|
new DigestVector(
|
||||||
new String("abc").getBytes(),
|
new String("abc").getBytes(),
|
||||||
|
|
|
@ -74,12 +74,16 @@ public class WolfCryptMessageDigestShaTest {
|
||||||
/* Try "SHA" and "SHA1" cipher strings, for SUN interop */
|
/* Try "SHA" and "SHA1" cipher strings, for SUN interop */
|
||||||
MessageDigest sha = MessageDigest.getInstance("SHA",
|
MessageDigest sha = MessageDigest.getInstance("SHA",
|
||||||
"wolfJCE");
|
"wolfJCE");
|
||||||
|
assertNotNull(sha);
|
||||||
|
|
||||||
MessageDigest sha1 = MessageDigest.getInstance("SHA1",
|
MessageDigest sha1 = MessageDigest.getInstance("SHA1",
|
||||||
"wolfJCE");
|
"wolfJCE");
|
||||||
|
assertNotNull(sha1);
|
||||||
|
|
||||||
MessageDigest shaDash1 = MessageDigest.getInstance("SHA-1",
|
MessageDigest shaDash1 = MessageDigest.getInstance("SHA-1",
|
||||||
"wolfJCE");
|
"wolfJCE");
|
||||||
|
assertNotNull(shaDash1);
|
||||||
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
/* if we also detect algo is compiled out, skip tests */
|
/* if we also detect algo is compiled out, skip tests */
|
||||||
if (FeatureDetect.ShaEnabled() == false) {
|
if (FeatureDetect.ShaEnabled() == false) {
|
||||||
|
|
|
@ -27,11 +27,9 @@ import org.junit.rules.TestRule;
|
||||||
import org.junit.rules.TestWatcher;
|
import org.junit.rules.TestWatcher;
|
||||||
import org.junit.runner.Description;
|
import org.junit.runner.Description;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.Assume;
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -54,13 +52,11 @@ import java.security.cert.CertificateFactory;
|
||||||
import java.security.cert.CertPath;
|
import java.security.cert.CertPath;
|
||||||
import java.security.cert.CertPathValidator;
|
import java.security.cert.CertPathValidator;
|
||||||
import java.security.cert.CertPathValidatorResult;
|
import java.security.cert.CertPathValidatorResult;
|
||||||
import java.security.cert.CertPathParameters;
|
|
||||||
import java.security.cert.PKIXParameters;
|
import java.security.cert.PKIXParameters;
|
||||||
import java.security.cert.PKIXCertPathValidatorResult;
|
import java.security.cert.PKIXCertPathValidatorResult;
|
||||||
import java.security.cert.CertificateException;
|
import java.security.cert.CertificateException;
|
||||||
import java.security.cert.CertPathValidatorException;
|
import java.security.cert.CertPathValidatorException;
|
||||||
import java.security.cert.TrustAnchor;
|
import java.security.cert.TrustAnchor;
|
||||||
import java.security.cert.PolicyNode;
|
|
||||||
import java.security.cert.X509CertSelector;
|
import java.security.cert.X509CertSelector;
|
||||||
import java.security.cert.CRL;
|
import java.security.cert.CRL;
|
||||||
import java.security.cert.CertStore;
|
import java.security.cert.CertStore;
|
||||||
|
@ -232,7 +228,6 @@ public class WolfCryptPKIXCertPathValidatorTest {
|
||||||
|
|
||||||
PKIXCertPathValidatorResult pResult = null;
|
PKIXCertPathValidatorResult pResult = null;
|
||||||
TrustAnchor anchor = null;
|
TrustAnchor anchor = null;
|
||||||
PolicyNode policyTree = null;
|
|
||||||
PublicKey pubKey = null;
|
PublicKey pubKey = null;
|
||||||
|
|
||||||
/* Check not null and of type PKIXCertPathValidatorResult */
|
/* Check not null and of type PKIXCertPathValidatorResult */
|
||||||
|
@ -247,6 +242,7 @@ public class WolfCryptPKIXCertPathValidatorTest {
|
||||||
assertEquals(anchor.getTrustedCert(), expectedAnchor);
|
assertEquals(anchor.getTrustedCert(), expectedAnchor);
|
||||||
|
|
||||||
/* Check PolicyTree matches expected - TODO */
|
/* Check PolicyTree matches expected - TODO */
|
||||||
|
//PolicyNode policyTree = null;
|
||||||
//policyTree = pResult.getPolicyTree();
|
//policyTree = pResult.getPolicyTree();
|
||||||
//assertNotNull(policyTree);
|
//assertNotNull(policyTree);
|
||||||
|
|
||||||
|
|
|
@ -74,9 +74,11 @@ public class WolfCryptRandomTest {
|
||||||
|
|
||||||
/* HashDRBG */
|
/* HashDRBG */
|
||||||
rand = SecureRandom.getInstance("HashDRBG", "wolfJCE");
|
rand = SecureRandom.getInstance("HashDRBG", "wolfJCE");
|
||||||
|
assertNotNull(rand);
|
||||||
|
|
||||||
/* DEFAULT */
|
/* DEFAULT */
|
||||||
rand = SecureRandom.getInstance("DEFAULT", "wolfJCE");
|
rand = SecureRandom.getInstance("DEFAULT", "wolfJCE");
|
||||||
|
assertNotNull(rand);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -214,11 +216,9 @@ public class WolfCryptRandomTest {
|
||||||
byte[] valuesA = new byte[128];
|
byte[] valuesA = new byte[128];
|
||||||
byte[] valuesB = new byte[128];
|
byte[] valuesB = new byte[128];
|
||||||
|
|
||||||
SecureRandom rand = SecureRandom.getInstance("HashDRBG", "wolfJCE");
|
valuesA = SecureRandom.getSeed(valuesA.length);
|
||||||
|
|
||||||
valuesA = rand.getSeed(valuesA.length);
|
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
valuesB = rand.getSeed(valuesB.length);
|
valuesB = SecureRandom.getSeed(valuesB.length);
|
||||||
|
|
||||||
if(Arrays.equals(valuesA, valuesB))
|
if(Arrays.equals(valuesA, valuesB))
|
||||||
fail("SecureRandom generated two equal consecutive arrays");
|
fail("SecureRandom generated two equal consecutive arrays");
|
||||||
|
@ -236,8 +236,6 @@ public class WolfCryptRandomTest {
|
||||||
ExecutorService service = Executors.newFixedThreadPool(numThreads);
|
ExecutorService service = Executors.newFixedThreadPool(numThreads);
|
||||||
final CountDownLatch latch = new CountDownLatch(numThreads);
|
final CountDownLatch latch = new CountDownLatch(numThreads);
|
||||||
final LinkedBlockingQueue<byte[]> results = new LinkedBlockingQueue<>();
|
final LinkedBlockingQueue<byte[]> results = new LinkedBlockingQueue<>();
|
||||||
final SecureRandom rand = SecureRandom.getInstance(
|
|
||||||
"HashDRBG", "wolfJCE");
|
|
||||||
|
|
||||||
for (int i = 0; i < numThreads; i++) {
|
for (int i = 0; i < numThreads; i++) {
|
||||||
service.submit(new Runnable() {
|
service.submit(new Runnable() {
|
||||||
|
@ -246,7 +244,7 @@ public class WolfCryptRandomTest {
|
||||||
|
|
||||||
/* generate 1000 random arrays per thread */
|
/* generate 1000 random arrays per thread */
|
||||||
for (int j = 0; j < 1000; j++) {
|
for (int j = 0; j < 1000; j++) {
|
||||||
tmp = rand.getSeed(tmp.length);
|
tmp = SecureRandom.getSeed(tmp.length);
|
||||||
results.add(tmp.clone());
|
results.add(tmp.clone());
|
||||||
}
|
}
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
|
|
|
@ -104,6 +104,7 @@ public class WolfCryptSecretKeyFactoryTest {
|
||||||
for (int i = 0; i < wolfJCEAlgos.length; i++) {
|
for (int i = 0; i < wolfJCEAlgos.length; i++) {
|
||||||
try {
|
try {
|
||||||
kf = SecretKeyFactory.getInstance(wolfJCEAlgos[i], provider);
|
kf = SecretKeyFactory.getInstance(wolfJCEAlgos[i], provider);
|
||||||
|
assertNotNull(kf);
|
||||||
enabledAlgos.add(wolfJCEAlgos[i]);
|
enabledAlgos.add(wolfJCEAlgos[i]);
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
/* algo not compiled in */
|
/* algo not compiled in */
|
||||||
|
@ -125,6 +126,7 @@ public class WolfCryptSecretKeyFactoryTest {
|
||||||
/* getting a garbage algorithm should throw an exception */
|
/* getting a garbage algorithm should throw an exception */
|
||||||
try {
|
try {
|
||||||
kf = SecretKeyFactory.getInstance("NotValid", provider);
|
kf = SecretKeyFactory.getInstance("NotValid", provider);
|
||||||
|
assertNotNull(kf);
|
||||||
|
|
||||||
fail("SecretKeyFactory.getInstance should throw " +
|
fail("SecretKeyFactory.getInstance should throw " +
|
||||||
"NoSuchAlgorithmException when given bad algorithm value");
|
"NoSuchAlgorithmException when given bad algorithm value");
|
||||||
|
@ -617,16 +619,8 @@ public class WolfCryptSecretKeyFactoryTest {
|
||||||
throws NoSuchAlgorithmException, InvalidKeySpecException,
|
throws NoSuchAlgorithmException, InvalidKeySpecException,
|
||||||
NoSuchProviderException {
|
NoSuchProviderException {
|
||||||
|
|
||||||
char[] pass = "passwordpassword".toCharArray();
|
|
||||||
byte[] salt = {
|
|
||||||
(byte)0x78, (byte)0x57, (byte)0x8E, (byte)0x5a,
|
|
||||||
(byte)0x5d, (byte)0x63, (byte)0xcb, (byte)0x06
|
|
||||||
};
|
|
||||||
int iterations = 2048;
|
|
||||||
int kLen = 192;
|
|
||||||
PBEKeySpec spec = null;
|
PBEKeySpec spec = null;
|
||||||
SecretKeyFactory sf = null;
|
SecretKeyFactory sf = null;
|
||||||
SecretKey key = null;
|
|
||||||
|
|
||||||
if (!FeatureDetect.Pbkdf2Enabled() ||
|
if (!FeatureDetect.Pbkdf2Enabled() ||
|
||||||
!FeatureDetect.HmacSha256Enabled() ||
|
!FeatureDetect.HmacSha256Enabled() ||
|
||||||
|
@ -640,7 +634,7 @@ public class WolfCryptSecretKeyFactoryTest {
|
||||||
|
|
||||||
/* null KeySpec should throw exception */
|
/* null KeySpec should throw exception */
|
||||||
try {
|
try {
|
||||||
key = sf.generateSecret(spec);
|
sf.generateSecret(spec);
|
||||||
fail("generateSecret() should fail with null KeySpec");
|
fail("generateSecret() should fail with null KeySpec");
|
||||||
} catch (InvalidKeySpecException e) {
|
} catch (InvalidKeySpecException e) {
|
||||||
/* expected */
|
/* expected */
|
||||||
|
|
|
@ -29,15 +29,11 @@ import org.junit.runner.Description;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
|
||||||
import java.util.concurrent.atomic.AtomicIntegerArray;
|
import java.util.concurrent.atomic.AtomicIntegerArray;
|
||||||
|
|
||||||
import java.security.Security;
|
import java.security.Security;
|
||||||
|
@ -103,6 +99,7 @@ public class WolfCryptSignatureTest {
|
||||||
for (int i = 0; i < wolfJCEAlgos.length; i++) {
|
for (int i = 0; i < wolfJCEAlgos.length; i++) {
|
||||||
try {
|
try {
|
||||||
sig = Signature.getInstance(wolfJCEAlgos[i], "wolfJCE");
|
sig = Signature.getInstance(wolfJCEAlgos[i], "wolfJCE");
|
||||||
|
assertNotNull(sig);
|
||||||
enabledAlgos.add(wolfJCEAlgos[i]);
|
enabledAlgos.add(wolfJCEAlgos[i]);
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
/* algo not compiled in */
|
/* algo not compiled in */
|
||||||
|
@ -119,6 +116,7 @@ public class WolfCryptSignatureTest {
|
||||||
/* try to get all available options we expect to have */
|
/* try to get all available options we expect to have */
|
||||||
for (int i = 0; i < enabledAlgos.size(); i++) {
|
for (int i = 0; i < enabledAlgos.size(); i++) {
|
||||||
sig = Signature.getInstance(enabledAlgos.get(i), "wolfJCE");
|
sig = Signature.getInstance(enabledAlgos.get(i), "wolfJCE");
|
||||||
|
assertNotNull(sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* asking for a bad algo should throw an exception */
|
/* asking for a bad algo should throw an exception */
|
||||||
|
|
|
@ -66,17 +66,11 @@ import java.security.spec.InvalidKeySpecException;
|
||||||
import javax.crypto.KeyGenerator;
|
import javax.crypto.KeyGenerator;
|
||||||
import javax.crypto.SecretKey;
|
import javax.crypto.SecretKey;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
|
|
||||||
import com.wolfssl.provider.jce.WolfCryptProvider;
|
import com.wolfssl.provider.jce.WolfCryptProvider;
|
||||||
|
|
||||||
public class WolfSSLKeyStoreTest {
|
public class WolfSSLKeyStoreTest {
|
||||||
|
|
||||||
private final String storeType = "WKS";
|
private final String storeType = "WKS";
|
||||||
private final String jksExt = ".wks";
|
|
||||||
private static final String storeProvider = "wolfJCE";
|
private static final String storeProvider = "wolfJCE";
|
||||||
/* Example pass is "wolfsslpassword" instead of normal
|
/* Example pass is "wolfsslpassword" instead of normal
|
||||||
* "wolfSSL test" because with wolfCrypt FIPS the HMAC minimum key
|
* "wolfSSL test" because with wolfCrypt FIPS the HMAC minimum key
|
||||||
|
@ -957,12 +951,8 @@ public class WolfSSLKeyStoreTest {
|
||||||
UnrecoverableKeyException {
|
UnrecoverableKeyException {
|
||||||
|
|
||||||
KeyStore store = null;
|
KeyStore store = null;
|
||||||
PrivateKey keyOut = null;
|
|
||||||
Certificate certOut = null;
|
|
||||||
Certificate[] chainOut = null;
|
|
||||||
KeyGenerator kg = null;
|
KeyGenerator kg = null;
|
||||||
SecretKey aesKey = null;
|
SecretKey aesKey = null;
|
||||||
SecretKey sKeyOut = null;
|
|
||||||
|
|
||||||
store = KeyStore.getInstance(storeType, storeProvider);
|
store = KeyStore.getInstance(storeType, storeProvider);
|
||||||
store.load(null, storePass.toCharArray());
|
store.load(null, storePass.toCharArray());
|
||||||
|
@ -1684,7 +1674,6 @@ public class WolfSSLKeyStoreTest {
|
||||||
service.submit(new Runnable() {
|
service.submit(new Runnable() {
|
||||||
@Override public void run() {
|
@Override public void run() {
|
||||||
|
|
||||||
int ret = 0;
|
|
||||||
KeyStore store = null;
|
KeyStore store = null;
|
||||||
PrivateKey keyOut = null;
|
PrivateKey keyOut = null;
|
||||||
Certificate certOut = null;
|
Certificate certOut = null;
|
||||||
|
|
|
@ -30,9 +30,6 @@ import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import javax.crypto.ShortBufferException;
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import javax.crypto.ShortBufferException;
|
|
||||||
|
|
||||||
import org.junit.Assume;
|
import org.junit.Assume;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
@ -255,7 +252,7 @@ public class AesGcmTest {
|
||||||
@Test
|
@Test
|
||||||
public void deprecatedConstructorThrows() {
|
public void deprecatedConstructorThrows() {
|
||||||
try {
|
try {
|
||||||
AesGcm aes = new AesGcm(new byte[] {0x0});
|
new AesGcm(new byte[] {0x0});
|
||||||
fail("Failed to throw expected exception");
|
fail("Failed to throw expected exception");
|
||||||
} catch (WolfCryptException e) {
|
} catch (WolfCryptException e) {
|
||||||
/* expected */
|
/* expected */
|
||||||
|
@ -857,7 +854,6 @@ public class AesGcmTest {
|
||||||
service.submit(new Runnable() {
|
service.submit(new Runnable() {
|
||||||
@Override public void run() {
|
@Override public void run() {
|
||||||
|
|
||||||
int ret = 0;
|
|
||||||
AesGcm enc = new AesGcm();
|
AesGcm enc = new AesGcm();
|
||||||
AesGcm dec = new AesGcm();
|
AesGcm dec = new AesGcm();
|
||||||
byte[] cipher = new byte[2048];
|
byte[] cipher = new byte[2048];
|
||||||
|
@ -929,7 +925,6 @@ public class AesGcmTest {
|
||||||
service.submit(new Runnable() {
|
service.submit(new Runnable() {
|
||||||
@Override public void run() {
|
@Override public void run() {
|
||||||
|
|
||||||
int ret = 0;
|
|
||||||
AesGcm enc = new AesGcm();
|
AesGcm enc = new AesGcm();
|
||||||
AesGcm dec = new AesGcm();
|
AesGcm dec = new AesGcm();
|
||||||
byte[] cipher = new byte[2048];
|
byte[] cipher = new byte[2048];
|
||||||
|
@ -1000,7 +995,6 @@ public class AesGcmTest {
|
||||||
service.submit(new Runnable() {
|
service.submit(new Runnable() {
|
||||||
@Override public void run() {
|
@Override public void run() {
|
||||||
|
|
||||||
int ret = 0;
|
|
||||||
AesGcm enc = new AesGcm();
|
AesGcm enc = new AesGcm();
|
||||||
AesGcm dec = new AesGcm();
|
AesGcm dec = new AesGcm();
|
||||||
byte[] cipher = new byte[2048];
|
byte[] cipher = new byte[2048];
|
||||||
|
|
|
@ -32,7 +32,6 @@ import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import javax.crypto.ShortBufferException;
|
import javax.crypto.ShortBufferException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import javax.crypto.ShortBufferException;
|
|
||||||
|
|
||||||
import org.junit.Assume;
|
import org.junit.Assume;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
@ -81,7 +80,7 @@ public class AesTest {
|
||||||
@Test
|
@Test
|
||||||
public void deprecatedConstructorThrows() {
|
public void deprecatedConstructorThrows() {
|
||||||
try {
|
try {
|
||||||
Aes aes = new Aes(null, null, Aes.ENCRYPT_MODE);
|
new Aes(null, null, Aes.ENCRYPT_MODE);
|
||||||
fail("Failed to throw expected exception");
|
fail("Failed to throw expected exception");
|
||||||
} catch (WolfCryptException e) {
|
} catch (WolfCryptException e) {
|
||||||
/* expected */
|
/* expected */
|
||||||
|
|
|
@ -23,11 +23,8 @@ package com.wolfssl.wolfcrypt.test;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import javax.crypto.ShortBufferException;
|
|
||||||
|
|
||||||
import org.junit.Assume;
|
import org.junit.Assume;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -331,7 +328,6 @@ public class ChachaTest {
|
||||||
};
|
};
|
||||||
|
|
||||||
int CHACHA_BIG_TEST_SIZE = 1305;
|
int CHACHA_BIG_TEST_SIZE = 1305;
|
||||||
byte cipher_big[] = new byte[CHACHA_BIG_TEST_SIZE];
|
|
||||||
byte plain_big[] = new byte[CHACHA_BIG_TEST_SIZE];
|
byte plain_big[] = new byte[CHACHA_BIG_TEST_SIZE];
|
||||||
byte input_big[] = new byte[CHACHA_BIG_TEST_SIZE];
|
byte input_big[] = new byte[CHACHA_BIG_TEST_SIZE];
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class Des3Test {
|
||||||
@Test
|
@Test
|
||||||
public void deprecatedConstructorThrows() {
|
public void deprecatedConstructorThrows() {
|
||||||
try {
|
try {
|
||||||
Des3 des = new Des3(null, null, Des3.ENCRYPT_MODE);
|
new Des3(null, null, Des3.ENCRYPT_MODE);
|
||||||
fail("Failed to throw expected exception");
|
fail("Failed to throw expected exception");
|
||||||
} catch (WolfCryptException e) {
|
} catch (WolfCryptException e) {
|
||||||
/* expected */
|
/* expected */
|
||||||
|
|
|
@ -32,8 +32,6 @@ import org.junit.rules.TestWatcher;
|
||||||
import org.junit.runner.Description;
|
import org.junit.runner.Description;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
|
@ -32,7 +32,6 @@ import org.junit.rules.TestWatcher;
|
||||||
import org.junit.runner.Description;
|
import org.junit.runner.Description;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
@ -162,7 +161,6 @@ public class EccTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void eccCurveSizeFromName() {
|
public void eccCurveSizeFromName() {
|
||||||
Ecc alice = new Ecc();
|
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
||||||
/* valid case */
|
/* valid case */
|
||||||
|
@ -204,7 +202,6 @@ public class EccTest {
|
||||||
public void eccPrivateToPkcs8() {
|
public void eccPrivateToPkcs8() {
|
||||||
Ecc alice = new Ecc();
|
Ecc alice = new Ecc();
|
||||||
byte[] pkcs8;
|
byte[] pkcs8;
|
||||||
int size;
|
|
||||||
|
|
||||||
byte[] prvKey = Util.h2b("30770201010420F8CF92"
|
byte[] prvKey = Util.h2b("30770201010420F8CF92"
|
||||||
+ "6BBD1E28F1A8ABA1234F3274188850AD7EC7EC92"
|
+ "6BBD1E28F1A8ABA1234F3274188850AD7EC7EC92"
|
||||||
|
|
|
@ -34,8 +34,6 @@ import org.junit.rules.TestWatcher;
|
||||||
import org.junit.runner.Description;
|
import org.junit.runner.Description;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
|
@ -62,6 +62,7 @@ public class Md5Test {
|
||||||
public static void checkMd5IsAvailable() {
|
public static void checkMd5IsAvailable() {
|
||||||
try {
|
try {
|
||||||
Md5 md5 = new Md5();
|
Md5 md5 = new Md5();
|
||||||
|
assertNotNull(md5);
|
||||||
System.out.println("JNI Md5 Class");
|
System.out.println("JNI Md5 Class");
|
||||||
} catch (WolfCryptException e) {
|
} catch (WolfCryptException e) {
|
||||||
if (e.getError() == WolfCryptError.NOT_COMPILED_IN) {
|
if (e.getError() == WolfCryptError.NOT_COMPILED_IN) {
|
||||||
|
|
|
@ -34,7 +34,6 @@ import org.junit.rules.TestWatcher;
|
||||||
import org.junit.runner.Description;
|
import org.junit.runner.Description;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
@ -83,14 +82,14 @@ public class RsaTest {
|
||||||
@Test
|
@Test
|
||||||
public void deprecatedConstructorThrows() {
|
public void deprecatedConstructorThrows() {
|
||||||
try {
|
try {
|
||||||
Rsa rsa = new Rsa( new byte[] {0x00} );
|
new Rsa( new byte[] {0x00} );
|
||||||
fail("Failed to throw expected exception");
|
fail("Failed to throw expected exception");
|
||||||
} catch (WolfCryptException e) {
|
} catch (WolfCryptException e) {
|
||||||
/* expected */
|
/* expected */
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Rsa rsa = new Rsa( new byte[] {0x00}, new byte[] {0x00} );
|
new Rsa( new byte[] {0x00}, new byte[] {0x00} );
|
||||||
fail("Failed to throw expected exception");
|
fail("Failed to throw expected exception");
|
||||||
} catch (WolfCryptException e) {
|
} catch (WolfCryptException e) {
|
||||||
/* expected */
|
/* expected */
|
||||||
|
@ -163,7 +162,6 @@ public class RsaTest {
|
||||||
public void rsaPrivateToPkcs8() {
|
public void rsaPrivateToPkcs8() {
|
||||||
Rsa key = new Rsa();
|
Rsa key = new Rsa();
|
||||||
byte[] pkcs8;
|
byte[] pkcs8;
|
||||||
int size;
|
|
||||||
byte[] prvKey = Util.h2b(
|
byte[] prvKey = Util.h2b(
|
||||||
"308204a40201000282010100c303d12bfe39a432453b53c8842b2a7c"
|
"308204a40201000282010100c303d12bfe39a432453b53c8842b2a7c"
|
||||||
+ "749abdaa2a520747d6a636b207328ed0ba697bc6c3449ed48148"
|
+ "749abdaa2a520747d6a636b207328ed0ba697bc6c3449ed48148"
|
||||||
|
|
|
@ -62,6 +62,7 @@ public class Sha256Test {
|
||||||
public static void checkSha256IsAvailable() {
|
public static void checkSha256IsAvailable() {
|
||||||
try {
|
try {
|
||||||
Sha256 sha = new Sha256();
|
Sha256 sha = new Sha256();
|
||||||
|
assertNotNull(sha);
|
||||||
System.out.println("JNI Sha256 Class");
|
System.out.println("JNI Sha256 Class");
|
||||||
} catch (WolfCryptException e) {
|
} catch (WolfCryptException e) {
|
||||||
if (e.getError() == WolfCryptError.NOT_COMPILED_IN) {
|
if (e.getError() == WolfCryptError.NOT_COMPILED_IN) {
|
||||||
|
|
|
@ -62,6 +62,7 @@ public class Sha384Test {
|
||||||
public static void checkSha384IsAvailable() {
|
public static void checkSha384IsAvailable() {
|
||||||
try {
|
try {
|
||||||
Sha384 sha = new Sha384();
|
Sha384 sha = new Sha384();
|
||||||
|
assertNotNull(sha);
|
||||||
System.out.println("JNI Sha384 Class");
|
System.out.println("JNI Sha384 Class");
|
||||||
} catch (WolfCryptException e) {
|
} catch (WolfCryptException e) {
|
||||||
if (e.getError() == WolfCryptError.NOT_COMPILED_IN) {
|
if (e.getError() == WolfCryptError.NOT_COMPILED_IN) {
|
||||||
|
|
|
@ -62,6 +62,7 @@ public class Sha512Test {
|
||||||
public static void checkSha512IsAvailable() {
|
public static void checkSha512IsAvailable() {
|
||||||
try {
|
try {
|
||||||
Sha512 sha = new Sha512();
|
Sha512 sha = new Sha512();
|
||||||
|
assertNotNull(sha);
|
||||||
System.out.println("JNI Sha512 Class");
|
System.out.println("JNI Sha512 Class");
|
||||||
} catch (WolfCryptException e) {
|
} catch (WolfCryptException e) {
|
||||||
if (e.getError() == WolfCryptError.NOT_COMPILED_IN) {
|
if (e.getError() == WolfCryptError.NOT_COMPILED_IN) {
|
||||||
|
|
|
@ -62,6 +62,7 @@ public class ShaTest {
|
||||||
public static void checkShaIsAvailable() {
|
public static void checkShaIsAvailable() {
|
||||||
try {
|
try {
|
||||||
Sha sha = new Sha();
|
Sha sha = new Sha();
|
||||||
|
assertNotNull(sha);
|
||||||
System.out.println("JNI Sha Class");
|
System.out.println("JNI Sha Class");
|
||||||
} catch (WolfCryptException e) {
|
} catch (WolfCryptException e) {
|
||||||
if (e.getError() == WolfCryptError.NOT_COMPILED_IN) {
|
if (e.getError() == WolfCryptError.NOT_COMPILED_IN) {
|
||||||
|
|
|
@ -47,10 +47,6 @@ public class RsaFipsTest extends FipsTest {
|
||||||
.allocateDirect(WolfCrypt.SIZE_OF_2048_BITS);
|
.allocateDirect(WolfCrypt.SIZE_OF_2048_BITS);
|
||||||
private ByteBuffer plain = ByteBuffer
|
private ByteBuffer plain = ByteBuffer
|
||||||
.allocateDirect(WolfCrypt.SIZE_OF_1024_BITS);
|
.allocateDirect(WolfCrypt.SIZE_OF_1024_BITS);
|
||||||
private ByteBuffer n = ByteBuffer
|
|
||||||
.allocateDirect(WolfCrypt.SIZE_OF_2048_BITS);
|
|
||||||
private ByteBuffer e = ByteBuffer
|
|
||||||
.allocateDirect(WolfCrypt.SIZE_OF_2048_BITS);
|
|
||||||
private ByteBuffer message = ByteBuffer
|
private ByteBuffer message = ByteBuffer
|
||||||
.allocateDirect(WolfCrypt.SIZE_OF_1024_BITS);
|
.allocateDirect(WolfCrypt.SIZE_OF_1024_BITS);
|
||||||
private ByteBuffer signature = ByteBuffer
|
private ByteBuffer signature = ByteBuffer
|
||||||
|
|
Loading…
Reference in New Issue