Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some more tests and simple micro benchmark
- Loading branch information
1 parent
ad4f19c
commit 8105c01
Showing
4 changed files
with
91 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
# Releases | ||
|
||
## v0.1.0 | ||
## v1.0.0 | ||
|
||
* refactor 'expand' byte handling to use byte buffer | ||
|
||
|
||
## v0.2.1 | ||
|
||
initial version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package at.favre.crypto; | ||
|
||
import org.apache.commons.lang3.RandomUtils; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
public class HKDFBenchmarkTest { | ||
|
||
// i7-7700k, 16GB DDR4, Java 8.131 | ||
// count: 2042 | ||
// Run (0): 3873013044ns | ||
// Run (1): 3602475691ns | ||
// Run (2): 3602419370ns | ||
// Run (3): 3613280596ns | ||
// Run (4): 3609781686ns | ||
|
||
@Ignore | ||
@Test | ||
public void quickStarTest() throws Exception { | ||
|
||
Map<Integer, Long> runsMap = new HashMap<>(); | ||
|
||
int rounds = 5; | ||
byte[] input; | ||
for (int i = 0; i < rounds; i++) { | ||
int count = 0; | ||
long start = System.nanoTime(); | ||
|
||
//benchmark different input sizes | ||
for (int j = 1024; j < 1024 * 1024; j += 1024) { | ||
input = RandomUtils.nextBytes(j); | ||
byte[] pseudoRandomKey = HKDF.fromHmacSha256().extract(input, new byte[]{0x62, 0x58, (byte) 0x84, 0x2C}); | ||
byte[] outputKeyingMaterial = HKDF.fromHmacSha256().expand(pseudoRandomKey, null, 32); | ||
assertTrue(outputKeyingMaterial.length > 0); | ||
count++; | ||
} | ||
|
||
//benchmark different input sizes | ||
for (int j = 16; j < 255 * 64; j += 16) { | ||
input = RandomUtils.nextBytes(128); | ||
byte[] pseudoRandomKey = HKDF.fromHmacSha512().extract(input, new byte[]{0x62, 0x58, (byte) 0x84, 0x2C}); | ||
byte[] outputKeyingMaterial = HKDF.fromHmacSha512().expand(pseudoRandomKey, null, j); | ||
assertTrue(outputKeyingMaterial.length > 0); | ||
count++; | ||
} | ||
|
||
runsMap.put(i, System.nanoTime() - start); | ||
System.out.println("count (" + i + "):" + count); | ||
} | ||
|
||
for (Map.Entry<Integer, Long> entry : runsMap.entrySet()) { | ||
System.out.println("Run (" + entry.getKey() + "): " + entry.getValue() + "ns"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters