Skip to content

Commit 2f3438b

Browse files
committed
Fix lots of typos and minor bugs
1 parent 3eac4df commit 2f3438b

21 files changed

+103
-108
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* update various dependencies
77
* update to github actions & sonaqube
88
* add OWASP dependency checker
9+
* fix lots of typos and minor bugs
910

1011
## v1.6.0
1112
* use better implementations of Base64 and Hex encoder

README.md

Lines changed: 53 additions & 53 deletions
Large diffs are not rendered by default.

src/main/java/at/favre/tools/dice/RndTool.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ static void execute(Arg arguments) throws AppException {
8888
throw new AppException("Count parameter must be greater than 0", 402);
8989
}
9090

91-
if ((arguments.count() != null && (arguments.count() * (long) arguments.length() > MAX_BYTE_PER_CALL))
92-
|| (long) arguments.length() > MAX_BYTE_PER_CALL) {
91+
if ((arguments.count() != null && (arguments.count() * (long) arguments.length() > MAX_BYTE_PER_CALL))) {
9392
throw new AppException("This PRNG can only generate " + MAX_BYTE_PER_CALL + " bytes at once.", 403);
93+
} else {
94+
arguments.length();
9495
}
9596

9697
if (arguments.outFile() != null && arguments.outFile().getParentFile() != null
@@ -131,7 +132,7 @@ private static byte[] parseSeed(String seed) {
131132
}
132133
}
133134

134-
private static void wrapInErrorHandling(Arg arguments, Callable r) {
135+
private static <T> void wrapInErrorHandling(Arg arguments, Callable<T> r) {
135136
try {
136137
r.call();
137138
} catch (Exception e) {

src/main/java/at/favre/tools/dice/rnd/DeterministicRandomBitGenerator.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,19 @@
1616

1717
package at.favre.tools.dice.rnd;
1818

19-
import org.jetbrains.annotations.Nullable;
20-
2119
/**
2220
* A Deterministic Random Bit Generator as defined by NIST, will output
2321
* pseudo random data depending on a given seed.
2422
*/
2523
public interface DeterministicRandomBitGenerator {
2624

2725
/**
28-
* Requests a reseed of this DRBG. Uses the internal entropy sources,
26+
* Requests a re-seed of this DRBG. Uses the internal entropy sources,
2927
* provided through {@link DrbgParameter}
3028
*
3129
* @param additionalInfo optional parameter to increase the security cushion see NIST SP 800-90Ar1 Section 8.7.2
3230
*/
33-
void requestReseed(@Nullable byte[] additionalInfo);
31+
void requestReseed(byte[] additionalInfo);
3432

3533
/**
3634
* Get the next pseudo random data
@@ -47,5 +45,5 @@ public interface DeterministicRandomBitGenerator {
4745
* @param additionalInfo can be null, additional information that is used to increase the security cushion,
4846
* see NIST SP 800-90Ar1 Section 8.7.2
4947
*/
50-
void nextBytes(byte[] out, @Nullable byte[] additionalInfo);
48+
void nextBytes(byte[] out, byte[] additionalInfo);
5149
}

src/main/java/at/favre/tools/dice/rnd/DrbgParameter.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package at.favre.tools.dice.rnd;
1818

1919
public class DrbgParameter {
20-
private static final int MAX_BYTES_PER_SEED = 1024 * 1024 * 1024; //1 MiB - increasing this value wont't enhance bandwidth
20+
private static final int MAX_BYTES_PER_SEED = 1024 * 1024 * 1024; //1 MiB - increasing this value won't enhance bandwidth
2121

2222
public final MacFactory macFactory;
2323
public final int securityStrengthBit;
@@ -37,10 +37,6 @@ public DrbgParameter(MacFactory macFactory, ExpandableEntropySource entropySourc
3737
this.reseedIntervalByte = reseedIntervalByte;
3838
}
3939

40-
public DrbgParameter(MacFactory macFactory, ExpandableEntropySource entropySource, ExpandableEntropySource nonceSource, byte[] personalizationString, boolean reseedAllowed) {
41-
this(macFactory, entropySource, nonceSource, personalizationString, reseedAllowed, MAX_BYTES_PER_SEED);
42-
}
43-
4440
public DrbgParameter(MacFactory macFactory, ExpandableEntropySource entropySource, ExpandableEntropySource nonceSource, byte[] personalizationString) {
4541
this(macFactory, entropySource, nonceSource, personalizationString, true, MAX_BYTES_PER_SEED);
4642
}

src/main/java/at/favre/tools/dice/rnd/EntropyPool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public interface EntropyPool extends ExpandableEntropySource {
2525
/**
2626
* Add new entropy source to the pool
2727
*
28-
* @param source
28+
* @param source to add
2929
*/
3030
void add(ExpandableEntropySource source);
3131
}

src/main/java/at/favre/tools/dice/rnd/ExpandableEntropySource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package at.favre.tools.dice.rnd;
1818

1919
/**
20-
* Interface for a entropy source with arbitrary length
20+
* Interface for an entropy source with arbitrary length
2121
*/
2222
public interface ExpandableEntropySource {
2323

src/main/java/at/favre/tools/dice/rnd/HmacDrbg.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package at.favre.tools.dice.rnd;
1818

1919
import at.favre.lib.bytes.Bytes;
20-
import org.jetbrains.annotations.Nullable;
2120

2221
import javax.crypto.Mac;
2322
import java.util.Arrays;
@@ -26,21 +25,21 @@
2625
* Deterministic Random Bit Generator based on any HMAC implementation available to {@link Mac}
2726
* <p>
2827
* Also known as: HMAC_DRBG.
29-
* See http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf for thorough specification.
28+
* See <a href="http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf">NIST.SP.800-90Ar1</a> for thorough specification.
3029
* <p>
3130
* Reseeding and additional info is supported.
3231
* <p>
33-
* See http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf Section 8.6.8.
32+
* See <a href="http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf">NIST.SP.800-90Ar1</a> Section 8.6.8.
3433
*/
3534
public final class HmacDrbg implements DeterministicRandomBitGenerator {
3635

3736
// floor(7500/8); see: http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf D.2 #5.
3837
private static final int MAX_BYTES_PER_REQUEST = 937;
3938
private static final byte[] BYTE_ARRAY_0 = {0};
4039
private static final byte[] BYTE_ARRAY_1 = {1};
41-
private final DrbgParameter paramter;
40+
private final DrbgParameter parameter;
4241

43-
// "V" from the the spec.
42+
// "V" from the spec.
4443
private byte[] value;
4544
// An instance of HMAC configured with "Key" from the spec.
4645
private Mac hmac;
@@ -59,7 +58,7 @@ public final class HmacDrbg implements DeterministicRandomBitGenerator {
5958
* @param drbgParameter parameter defining this DRBG
6059
*/
6160
public HmacDrbg(DrbgParameter drbgParameter) {
62-
this.paramter = drbgParameter;
61+
this.parameter = drbgParameter;
6362

6463
// HMAC_DRBG Instantiate Process
6564
// See: http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf 10.1.1.2
@@ -87,16 +86,16 @@ private byte[] generateSeedMaterial() {
8786
// Note: We are using the 8.6.7 interpretation, where the entropy_input and
8887
// nonce are acquired at the same time from the same source.
8988
return Bytes.from(
90-
paramter.entropySource.generateEntropy(getSecurityStrengthBytes()),
91-
paramter.nonceSource.generateEntropy(getSecurityStrengthBytes() / 2),
92-
paramter.personalizationString == null ? new byte[0] : paramter.personalizationString).array();
89+
parameter.entropySource.generateEntropy(getSecurityStrengthBytes()),
90+
parameter.nonceSource.generateEntropy(getSecurityStrengthBytes() / 2),
91+
parameter.personalizationString == null ? new byte[0] : parameter.personalizationString).array();
9392
}
9493

9594
/**
9695
* Set's the "Key" state from the spec.
9796
*/
9897
private void initHmac(byte[] key) {
99-
hmac = paramter.macFactory.create(key);
98+
hmac = parameter.macFactory.create(key);
10099
}
101100

102101
/**
@@ -125,8 +124,8 @@ private void hmacDrbgUpdate(byte[] providedData) {
125124
* This uses the provided entropy sources as well as an optional additionalInfo
126125
*/
127126
@Override
128-
public void requestReseed(@Nullable byte[] additionalInfo) {
129-
hmacDrbgReseed(paramter.entropySource.generateEntropy(getSecurityStrengthBytes()), paramter.nonceSource.generateEntropy(getSecurityStrengthBytes() / 2), additionalInfo);
127+
public void requestReseed(byte[] additionalInfo) {
128+
hmacDrbgReseed(parameter.entropySource.generateEntropy(getSecurityStrengthBytes()), parameter.nonceSource.generateEntropy(getSecurityStrengthBytes() / 2), additionalInfo);
130129
}
131130

132131
/**
@@ -180,10 +179,10 @@ private void hmacDrbgGenerate(byte[] out, int start, int count, byte[] additiona
180179
/**
181180
* Security Strength in Bits; depending on the used HMAC hash
182181
*
183-
* @return bit length
182+
* @return a bit length
184183
*/
185184
private int getSecurityStrengthBytes() {
186-
return paramter.securityStrengthBit / 8;
185+
return parameter.securityStrengthBit / 8;
187186
}
188187

189188
/**
@@ -220,7 +219,7 @@ private void generateBytesProcess(byte[] out, int start, int count, byte[] addit
220219
hmacDrbgUpdate(additionalInput);
221220
}
222221

223-
if (paramter.reseedAllowed && bytesGenerated + count > paramter.reseedIntervalByte) {
222+
if (parameter.reseedAllowed && bytesGenerated + count > parameter.reseedIntervalByte) {
224223
requestReseed(null);
225224
}
226225

src/main/java/at/favre/tools/dice/rnd/MacFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static MacFactory hmacSha512() {
6464
* Creates a factory creating HMAC with SHA-1
6565
*
6666
* @return factory
67-
* @deprecated sha1 with HMAC should be fine, but not recommended for new protocols; see https://crypto.stackexchange.com/questions/26510/why-is-hmac-sha1-still-considered-secure
67+
* @deprecated sha1 with HMAC should be fine, but not recommended for new protocols; see <a href="https://crypto.stackexchange.com/questions/26510/why-is-hmac-sha1-still-considered-secure">why-is-hmac-sha1-still-considered-secure</a>
6868
*/
6969
@Deprecated
7070
public static MacFactory hmacSha1() {

src/main/java/at/favre/tools/dice/rnd/entropy/BCThreadedEntropySource.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.nio.charset.StandardCharsets;
2323
import java.util.concurrent.ArrayBlockingQueue;
2424
import java.util.concurrent.BlockingQueue;
25+
import java.util.concurrent.atomic.AtomicLong;
2526

2627
/**
2728
* Threaded Seed Generator based on the one found in Bouncy Castle implementation

0 commit comments

Comments
 (0)