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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
/**
2626
* Used with external seeds that are estimated to be strong. The strong seed will
27-
* used in quasi directly (only HKDF after each call will be preformed additional to
28-
* adding an monotonic counter, to generate different outputs each call)
27+
* be used in quasi directly (only HKDF after each call will be preformed additional to
28+
* adding a monotonic counter, to generate different outputs each call)
2929
*/
3030
public final class ExternalStrongSeedEntropySource implements ExpandableEntropySource {
3131
private static final byte[] SALT = new byte[]{0x57, 0x58, 0x6E, (byte) 0x9A, 0x7C, (byte) 0xE4, 0x2E, 0x57, 0x61, 0x07, 0x18, (byte) 0xD9, (byte) 0x90, (byte) 0xFE,
@@ -43,7 +43,7 @@ public ExternalStrongSeedEntropySource(byte[] seed) {
4343
}
4444

4545
private void regenerateInternalSeed(byte[] seed) {
46-
if (counter >= Long.MAX_VALUE) {
46+
if (counter == Long.MAX_VALUE) {
4747
throw new IllegalStateException("counter reached max value (2^64)");
4848
}
4949

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
/**
2626
* This is a port of the Thread Seed Generator in SUN's SeedGenerator class.
27-
* It use some faster timings which may make it less secure but the original
27+
* It uses some faster timings which may make it less secure but the original
2828
* implementation is awfully slow (min 250 ms per byte).
2929
* <p>
3030
* This is the fallback if neither the personalization nor the secureRandom
@@ -58,7 +58,7 @@ private static class ThreadedSeedGenerator implements Runnable {
5858
// data and using it to mix the trivial permutation.
5959
// It should be evenly distributed. The specific values
6060
// are not crucial to the security of this class.
61-
private static byte[] rndTab = {
61+
private static final byte[] rndTab = {
6262
56, 30, -107, -6, -86, 25, -83, 75, -12, -64,
6363
5, -128, 78, 21, 16, 32, 70, -81, 37, -51,
6464
-43, -46, -108, 87, 29, 17, -55, 22, -11, -111,
@@ -89,7 +89,7 @@ private static class ThreadedSeedGenerator implements Runnable {
8989
// Thread group for our threads
9090
ThreadGroup seedGroup;
9191
// Queue is used to collect seed bytes
92-
private byte[] pool;
92+
private final byte[] pool;
9393
private int start, end, count;
9494

9595
/**
@@ -190,7 +190,7 @@ void getSeedBytes(byte[] result) {
190190
}
191191

192192
byte getSeedByte() {
193-
byte b = 0;
193+
byte b;
194194

195195
try {
196196
// Wait for it...

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626

2727
/**
2828
* Nonce generate as described in SP800-90Ar1. This implementation uses a monotonic sequence number
29-
* starting with the VM uptime time in millis and the current nano second timestamp
29+
* starting with the VM uptime time in millis and the current nanosecond timestamp
3030
* <p>
31-
* See http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf Section 8.6.7.
31+
* See <a href="http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf">NIST.SP.800-90Ar1</a> Section 8.6.7.
3232
*/
3333
public final class NonceEntropySource implements ExpandableEntropySource {
3434
private static final byte[] SALT = new byte[]{0x48, (byte) 0xB8, (byte) 0x96, (byte) 0xC6, (byte) 0x87, 0x5C, (byte) 0xD0, (byte) 0xF9, (byte) 0x9D,
@@ -44,7 +44,7 @@ public NonceEntropySource() {
4444

4545
@Override
4646
public byte[] generateEntropy(int lengthByte) {
47-
if (sequenceCounter >= Long.MAX_VALUE) {
47+
if (sequenceCounter == Long.MAX_VALUE) {
4848
throw new IllegalStateException("sequence counter reached max value (2^64)");
4949
}
5050

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ private byte[] readTempDirContent() {
6262

6363
try (DirectoryStream<Path> stream = Files.newDirectoryStream(f.toPath())) {
6464
// We use a Random object to choose what file names
65-
// should be used. Otherwise on a machine with too
65+
// should be used. Otherwise, on a machine with too
6666
// many files, the same first 1024 files always get
67-
// used. Any, We make sure the first 512 files are
67+
// used. Anyway,we make sure the first 512 files are
6868
// always used.
6969
Random r = new Random();
7070
for (Path entry : stream) {

src/main/java/at/favre/tools/dice/service/ServiceHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public interface ServiceHandler<T> {
3535
Single<Result<T>> asObservable();
3636

3737
/**
38-
* Get the user friendly and readable name for this service
38+
* Get the user-friendly and readable name for this service
3939
*
4040
* @return name
4141
*/

src/main/java/at/favre/tools/dice/service/anuquantum/AnuQuantumServiceHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* ANU Quantum Random Numbers Server
3232
* Quantum true random number generator from Australian university
3333
* <p>
34-
* See https://qrng.anu.edu.au/
34+
* See <a href="https://qrng.anu.edu.au/">qrng.anu.edu.au</a>
3535
*/
3636
public final class AnuQuantumServiceHandler extends AServiceHandler {
3737
static final int ENTROPY_SEED_LENGTH_BYTE = 24;
@@ -58,7 +58,7 @@ public Result<AnuQuantumResponse> getRandom() {
5858

5959
try {
6060
Response<AnuQuantumResponse> response = service.getRandom(createHeaderMap(), ENTROPY_SEED_LENGTH_BYTE).execute();
61-
if (response != null && response.isSuccessful() && response.body() != null) {
61+
if (response.isSuccessful() && response.body() != null) {
6262
byte[] rawResponse = Bytes.parseHex(response.body().data.get(0)).array();
6363
return new Result<>(getName(), rawResponse, response.body(), Duration.between(startTime, Instant.now()).toNanos());
6464
}

src/main/java/at/favre/tools/dice/service/randomorg/RandomOrgServiceHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public Result<RandomOrgBlobResponse> getRandom() {
6868
final RandomOrgBlobRequest randomOrgBlobRequest = new RandomOrgBlobRequest(new RandomOrgBlobRequest.Params(k, 1, ENTROPY_SEED_LENGTH_BIT));
6969

7070
Response<String> response = service.getRandom(createHeaderMap(), randomOrgBlobRequest).execute();
71-
if (response != null && response.isSuccessful() && response.body() != null) {
71+
if (response.isSuccessful() && response.body() != null) {
7272
String rawResponse = response.body();
7373
RandomOrgBlobResponse orgBlobResponse = new Gson().fromJson(rawResponse, RandomOrgBlobResponse.class);
7474

src/main/java/at/favre/tools/dice/service/randomorg/RandomOrgUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
/**
3434
* Util for verifying the signature format of random.org's signed request
3535
* <p>
36-
* See https://api.random.org/verify/manual
36+
* See <a href="https://api.random.org/verify/manual">api.random.org</a>
3737
*/
3838
final class RandomOrgUtil {
3939
static final String RANDOM_ORG_PUB_KEY =

src/main/java/at/favre/tools/dice/ui/CLIParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private static Options setupOptions() {
119119
Options options = new Options();
120120

121121
Option count = Option.builder(ARG_COUNT).longOpt("count").argName("number").desc("How many randoms should be generated. Automatically chosen if this argument is omitted.").hasArgs().build();
122-
Option encodeing = Option.builder(ARG_ENCODING).longOpt("encoding").argName("string").hasArgs().desc("Output byte-to-text encoding. Available encodings include:\n" + new EncoderHandler().getSupportedEncodingList()).build();
122+
Option encoding = Option.builder(ARG_ENCODING).longOpt("encoding").argName("string").hasArgs().desc("Output byte-to-text encoding. Available encodings include:\n" + new EncoderHandler().getSupportedEncodingList()).build();
123123
Option seed = Option.builder(ARG_SEED).longOpt("seed").argName("string|number").hasArgs().desc("Uses either the 64-bit integer interpretation or the utf-8 byte representation of given parameter to seed the internal random generator. Warns if entropy is low.").build();
124124
Option debugOpt = Option.builder(ARG_DEBUG).longOpt("debug").hasArg(false).desc("Prints additional info for debugging.").build();
125125
Option onlineOpt = Option.builder(ARG_ONLINE).longOpt("offline").hasArg(false).desc("Skips request to external random generators (random.org) for seeding (use when offline).").build();
@@ -136,7 +136,7 @@ private static Options setupOptions() {
136136
OptionGroup mainArgs = new OptionGroup();
137137

138138
options.addOptionGroup(mainArgs);
139-
options.addOption(count).addOption(encodeing)
139+
options.addOption(count).addOption(encoding)
140140
.addOption(seed).addOption(onlineOpt)
141141
.addOption(anuQuantumOpt)
142142
.addOption(urlencodeOpt).addOption(paddingOpt)

src/main/java/at/favre/tools/dice/ui/ColumnRenderer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public ColumnRenderer(EncoderFormat encoderFormat, RandomGenerator randomGenerat
4343
/**
4444
* Will take a list and a target count and tries to create even columns
4545
*
46-
* @param targetCount approximate count you want to render (may be filled by the auto algorithm)
46+
* @param targetCount approximate count you want to render (maybe filled by the auto algorithm)
4747
* @param outStream to write the output to
4848
* @return the actual used count
4949
*/
@@ -128,7 +128,7 @@ public long render(long count, PrintStream outStream, boolean toFile) {
128128
}
129129

130130
} else {
131-
outStream.write(encoderFormat.asBytes(toFile ? encoderFormat.separatorFile() : encoderFormat.separatorFile()));
131+
outStream.write(encoderFormat.asBytes(encoderFormat.separatorFile()));
132132
}
133133
} catch (Exception e) {
134134
throw new IllegalStateException("could not write random to output stream", e);

0 commit comments

Comments
 (0)