Skip to content

Commit

Permalink
Removed re-encryption instead reuses encryptTestData
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack Tjaden committed Jan 2, 2025
1 parent ba751c9 commit a98fa33
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions examples/provider/CryptoBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ private static void runBenchmark(String algorithm, String mode) throws Exception
/* IV/Nonce generation variables */
byte[] ivBytes;
/* Using specific type instead of Object */
AlgorithmParameterSpec params;
AlgorithmParameterSpec params;
/* Test data variables */
byte[] encryptTestData;
byte[] decryptTestData;
byte[] encryptedData;
byte[] encrypted;
double encryptDataSizeMiB;
double decryptDataSizeMiB;

Expand Down Expand Up @@ -71,33 +69,29 @@ private static void runBenchmark(String algorithm, String mode) throws Exception

/* Generate test data filled with zeros */
encryptTestData = generateTestData(ENCRYPT_SIZE);
decryptTestData = encryptTestData; /* Reuse the same data for decryption test */

/* Initialize cipher */
cipher = Cipher.getInstance(algorithm);

/* Warm up phase */
for (int i = 0; i < WARMUP_ITERATIONS; i++) {
cipher.init(Cipher.ENCRYPT_MODE, key, params);
encrypted = cipher.doFinal(encryptTestData);
encryptedData = cipher.doFinal(encryptTestData);

cipher.init(Cipher.DECRYPT_MODE, key, params);
cipher.doFinal(encrypted);
cipher.doFinal(encryptedData);
}

/* Benchmark encryption */
startTime = System.nanoTime();
for (int i = 0; i < TEST_ITERATIONS; i++) {
cipher.init(Cipher.ENCRYPT_MODE, key, params);
cipher.doFinal(encryptTestData);
encryptedData = cipher.doFinal(encryptTestData);
}
endTime = System.nanoTime();
encryptTime = (endTime - startTime) / TEST_ITERATIONS;

/* Benchmark decryption */
cipher.init(Cipher.ENCRYPT_MODE, key, params);
encryptedData = cipher.doFinal(decryptTestData);

startTime = System.nanoTime();
for (int i = 0; i < TEST_ITERATIONS; i++) {
cipher.init(Cipher.DECRYPT_MODE, key, params);
Expand Down

0 comments on commit a98fa33

Please sign in to comment.