Skip to content

Commit d7426e0

Browse files
committed
JCE: add proper toString() to WolfCryptRandom, throw NullInputException when input arrays are null
1 parent 2fd62a2 commit d7426e0

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/main/java/com/wolfssl/provider/jce/WolfCryptRandom.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,23 @@ protected synchronized byte[] engineGenerateSeed(int numBytes)
7575
@Override
7676
protected synchronized void engineNextBytes(byte[] bytes) {
7777

78+
if (bytes == null) {
79+
throw new NullPointerException("Input byte[] should not be null");
80+
}
81+
7882
rng.generateBlock(bytes);
7983
}
8084

8185
@Override
8286
protected synchronized void engineSetSeed(byte[] seed) {
87+
88+
if (seed == null) {
89+
throw new NullPointerException("Input seed[] should not be null");
90+
}
91+
8392
/* wolfCrypt reseeds internally automatically */
8493
log("setSeed() not supported by wolfJCE");
94+
8595
}
8696

8797
private void log(String msg) {
@@ -145,5 +155,21 @@ private synchronized void readObject(ObjectInputStream in)
145155

146156
in.defaultReadObject();
147157
}
158+
159+
@Override
160+
public String toString() {
161+
/* Native wolfCrypt DRBG details:
162+
* Hash_DRBG = DRBG implementation
163+
* SHA-256 = hash function used in Hash_DRBG implementation
164+
* 128 = security strength in bits
165+
* reseed_only = NIST implementation default, prediction resistance
166+
* not enabled for every generate call, onlky when explicitly
167+
* reseeded.
168+
*
169+
* This output format matches other JCE providers, some callers
170+
* may expect this format.
171+
*/
172+
return "Hash_DRBG,SHA-256,128,reseed_only";
173+
}
148174
}
149175

0 commit comments

Comments
 (0)