Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Hook <dgh@cryptoworkshop.com>2014-03-07 02:46:08 +0400
committerDavid Hook <dgh@cryptoworkshop.com>2014-03-07 02:46:08 +0400
commitaf1a83718375ec22f676a690118d789d3645b7c7 (patch)
tree391c3adbbcdb96c4cf2584846b9c47b9231d7c76 /core/src/main/java/org/bouncycastle
parentb80f04eb783e6e5436753fc0e743801f21a1f662 (diff)
added getBlockSize() method
Diffstat (limited to 'core/src/main/java/org/bouncycastle')
-rw-r--r--core/src/main/java/org/bouncycastle/crypto/prng/drbg/CTRSP800DRBG.java10
-rw-r--r--core/src/main/java/org/bouncycastle/crypto/prng/drbg/DualECSP800DRBG.java10
-rw-r--r--core/src/main/java/org/bouncycastle/crypto/prng/drbg/HMacSP800DRBG.java10
-rw-r--r--core/src/main/java/org/bouncycastle/crypto/prng/drbg/HashSP800DRBG.java25
-rw-r--r--core/src/main/java/org/bouncycastle/crypto/prng/drbg/SP80090DRBG.java7
5 files changed, 57 insertions, 5 deletions
diff --git a/core/src/main/java/org/bouncycastle/crypto/prng/drbg/CTRSP800DRBG.java b/core/src/main/java/org/bouncycastle/crypto/prng/drbg/CTRSP800DRBG.java
index 84fe4a40..5ab8f469 100644
--- a/core/src/main/java/org/bouncycastle/crypto/prng/drbg/CTRSP800DRBG.java
+++ b/core/src/main/java/org/bouncycastle/crypto/prng/drbg/CTRSP800DRBG.java
@@ -310,6 +310,16 @@ public class CTRSP800DRBG
}
/**
+ * Return the block size (in bits) of the DRBG.
+ *
+ * @return the number of bits produced on each internal round of the DRBG.
+ */
+ public int getBlockSize()
+ {
+ return _V.length * 8;
+ }
+
+ /**
* Populate a passed in array with random data.
*
* @param output output array for generated bits.
diff --git a/core/src/main/java/org/bouncycastle/crypto/prng/drbg/DualECSP800DRBG.java b/core/src/main/java/org/bouncycastle/crypto/prng/drbg/DualECSP800DRBG.java
index a5607d5a..4e1b881d 100644
--- a/core/src/main/java/org/bouncycastle/crypto/prng/drbg/DualECSP800DRBG.java
+++ b/core/src/main/java/org/bouncycastle/crypto/prng/drbg/DualECSP800DRBG.java
@@ -149,6 +149,16 @@ public class DualECSP800DRBG
}
/**
+ * Return the block size (in bits) of the DRBG.
+ *
+ * @return the number of bits produced on each internal round of the DRBG.
+ */
+ public int getBlockSize()
+ {
+ return _outlen * 8;
+ }
+
+ /**
* Populate a passed in array with random data.
*
* @param output output array for generated bits.
diff --git a/core/src/main/java/org/bouncycastle/crypto/prng/drbg/HMacSP800DRBG.java b/core/src/main/java/org/bouncycastle/crypto/prng/drbg/HMacSP800DRBG.java
index 3ddeaac6..f4ef2c45 100644
--- a/core/src/main/java/org/bouncycastle/crypto/prng/drbg/HMacSP800DRBG.java
+++ b/core/src/main/java/org/bouncycastle/crypto/prng/drbg/HMacSP800DRBG.java
@@ -88,6 +88,16 @@ public class HMacSP800DRBG
}
/**
+ * Return the block size (in bits) of the DRBG.
+ *
+ * @return the number of bits produced on each round of the DRBG.
+ */
+ public int getBlockSize()
+ {
+ return _V.length * 8;
+ }
+
+ /**
* Populate a passed in array with random data.
*
* @param output output array for generated bits.
diff --git a/core/src/main/java/org/bouncycastle/crypto/prng/drbg/HashSP800DRBG.java b/core/src/main/java/org/bouncycastle/crypto/prng/drbg/HashSP800DRBG.java
index 4ed57163..d6ab4f53 100644
--- a/core/src/main/java/org/bouncycastle/crypto/prng/drbg/HashSP800DRBG.java
+++ b/core/src/main/java/org/bouncycastle/crypto/prng/drbg/HashSP800DRBG.java
@@ -88,6 +88,16 @@ public class HashSP800DRBG
}
/**
+ * Return the block size (in bits) of the DRBG.
+ *
+ * @return the number of bits produced on each internal round of the DRBG.
+ */
+ public int getBlockSize()
+ {
+ return _digest.getDigestSize() * 8;
+ }
+
+ /**
* Populate a passed in array with random data.
*
* @param output output array for generated bits.
@@ -226,12 +236,17 @@ public class HashSP800DRBG
private byte[] hash(byte[] input)
{
- _digest.update(input, 0, input.length);
byte[] hash = new byte[_digest.getDigestSize()];
- _digest.doFinal(hash, 0);
+ doHash(input, hash);
return hash;
}
-
+
+ private void doHash(byte[] input, byte[] output)
+ {
+ _digest.update(input, 0, input.length);
+ _digest.doFinal(output, 0);
+ }
+
// 1. m = [requested_number_of_bits / outlen]
// 2. data = V.
// 3. W = the Null string.
@@ -251,10 +266,10 @@ public class HashSP800DRBG
byte[] W = new byte[lengthInBits / 8];
- byte[] dig;
+ byte[] dig = new byte[_digest.getDigestSize()];
for (int i = 0; i <= m; i++)
{
- dig = hash(data);
+ doHash(data, dig);
int bytesToCopy = ((W.length - i * dig.length) > dig.length)
? dig.length
diff --git a/core/src/main/java/org/bouncycastle/crypto/prng/drbg/SP80090DRBG.java b/core/src/main/java/org/bouncycastle/crypto/prng/drbg/SP80090DRBG.java
index 93bc8945..7a919f31 100644
--- a/core/src/main/java/org/bouncycastle/crypto/prng/drbg/SP80090DRBG.java
+++ b/core/src/main/java/org/bouncycastle/crypto/prng/drbg/SP80090DRBG.java
@@ -6,6 +6,13 @@ package org.bouncycastle.crypto.prng.drbg;
public interface SP80090DRBG
{
/**
+ * Return the block size of the DRBG.
+ *
+ * @return the block size (in bits) produced by each round of the DRBG.
+ */
+ int getBlockSize();
+
+ /**
* Populate a passed in array with random data.
*
* @param output output array for generated bits.