1717package at .favre .tools .dice .rnd ;
1818
1919import at .favre .lib .bytes .Bytes ;
20- import org .jetbrains .annotations .Nullable ;
2120
2221import javax .crypto .Mac ;
2322import java .util .Arrays ;
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 */
3534public 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
0 commit comments