Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/main/java/com/wolfssl/provider/jce/WolfCryptCipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,6 @@ private WolfCryptCipher(CipherType type, CipherMode mode,
initOaepParamsSha1();
}

this.rng = new Rng();
this.rng.init();

switch (cipherType) {
case WC_AES:
blockSize = Aes.BLOCK_SIZE;
Expand Down Expand Up @@ -420,6 +417,10 @@ else if (cipherMode == CipherMode.WC_CTS) {
rsa.releaseNativeStruct();
rsa = null;
}
if (this.rng == null) {
this.rng = new Rng();
this.rng.init();
}
rsa = new Rsa();
rsa.setRng(this.rng);
Comment thread
cconlon marked this conversation as resolved.
Outdated
break;
Expand Down Expand Up @@ -1021,6 +1022,10 @@ else if (cipherMode == CipherMode.WC_OFB) {
if (this.rsa != null)
this.rsa.releaseNativeStruct();

if (this.rng == null) {
this.rng = new Rng();
this.rng.init();
}
Comment thread
cconlon marked this conversation as resolved.
this.rsa = new Rsa();
this.rsa.setRng(this.rng);

Expand Down Expand Up @@ -2023,6 +2028,7 @@ protected void finalize() throws Throwable {
}

if (this.rng != null) {
this.rng.free();
this.rng.releaseNativeStruct();
this.rng = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,35 +161,38 @@ else if (size == 8192) {
* wolfCrypt may return PRIME_GEN_E (-251) if it fails to
* find a suitable prime after the NIST FIPS 186-4 mandated
* number of attempts. */
while (retryCount < MAX_PARAM_GEN_RETRIES) {
Rng rng = null;
try {
/* Create and initialize RNG. */
rng = new Rng();
rng.init();

/* Generate DH parameters, may throw exception with
* bad function arg if size not supported natively. */
params = Dh.generateDhParams(rng, size);

/* Success, exit retry loop */
break;

} catch (WolfCryptException e) {
/* Only retry on PRIME_GEN_E error */
if (e.getError() == WolfCryptError.PRIME_GEN_E) {
lastPrimeGenException = e;
retryCount++;
}
else {
throw e;
Rng rng = null;
try {
/* Create and initialize RNG once for all retries */
rng = new Rng();
rng.init();

while (retryCount < MAX_PARAM_GEN_RETRIES) {
try {
/* Generate DH parameters, may throw exception
* with bad function arg if size not supported
* natively. */
params = Dh.generateDhParams(rng, size);

/* Success, exit retry loop */
break;

} catch (WolfCryptException e) {
/* Only retry on PRIME_GEN_E error */
if (e.getError() == WolfCryptError.PRIME_GEN_E) {
lastPrimeGenException = e;
retryCount++;
}
else {
throw e;
}
}
}
finally {
if (rng != null) {
rng.free();
rng.releaseNativeStruct();
}
}
finally {
if (rng != null) {
rng.free();
rng.releaseNativeStruct();
}
}

Expand Down
Loading