I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 39343ce9 authored by jrandom's avatar jrandom Committed by zzz
Browse files

2005-04-16 jrandom

    * Migrated to Bouncycastle's SHA256 and HMAC implementations for efficiency
parent 7389cec7
No related branches found
No related tags found
No related merge requests found
...@@ -71,33 +71,29 @@ public class HMACSHA256Bench { ...@@ -71,33 +71,29 @@ public class HMACSHA256Bench {
buf.append("a"); buf.append("a");
} }
byte[] lmess = buf.toString().getBytes(); byte[] lmess = buf.toString().getBytes();
HMACSHA256Generator.Buffer sbuf = ctx.hmac().createBuffer(smess.length);
HMACSHA256Generator.Buffer mbuf = ctx.hmac().createBuffer(mmess.length);
HMACSHA256Generator.Buffer lbuf = ctx.hmac().createBuffer(lmess.length);
// warm up the engines // warm up the engines
ctx.hmac().calculate(key, smess, sbuf); ctx.hmac().calculate(key, smess);
ctx.hmac().calculate(key, mmess, mbuf); ctx.hmac().calculate(key, mmess);
ctx.hmac().calculate(key, lmess, lbuf); ctx.hmac().calculate(key, lmess);
long before = System.currentTimeMillis(); long before = System.currentTimeMillis();
for (int x = 0; x < times; x++) for (int x = 0; x < times; x++)
ctx.hmac().calculate(key, smess, sbuf); ctx.hmac().calculate(key, smess);
long after = System.currentTimeMillis(); long after = System.currentTimeMillis();
display(times, before, after, smess.length, "3 byte"); display(times, before, after, smess.length, "3 byte");
before = System.currentTimeMillis(); before = System.currentTimeMillis();
for (int x = 0; x < times; x++) for (int x = 0; x < times; x++)
ctx.hmac().calculate(key, mmess, mbuf); ctx.hmac().calculate(key, mmess);
after = System.currentTimeMillis(); after = System.currentTimeMillis();
display(times, before, after, mmess.length, "2KB"); display(times, before, after, mmess.length, "2KB");
before = System.currentTimeMillis(); before = System.currentTimeMillis();
for (int x = 0; x < times; x++) for (int x = 0; x < times; x++)
ctx.hmac().calculate(key, lmess, lbuf); ctx.hmac().calculate(key, lmess);
after = System.currentTimeMillis(); after = System.currentTimeMillis();
display(times, before, after, lmess.length, "10KB"); display(times, before, after, lmess.length, "10KB");
......
...@@ -68,11 +68,6 @@ public class SHA256Bench { ...@@ -68,11 +68,6 @@ public class SHA256Bench {
} }
byte[] lmess = buf.toString().getBytes(); byte[] lmess = buf.toString().getBytes();
SHA256EntryCache cache = new SHA256EntryCache();
SHA256EntryCache.CacheEntry scache = cache.acquire(smess.length);
SHA256EntryCache.CacheEntry mcache = cache.acquire(mmess.length);
SHA256EntryCache.CacheEntry lcache = cache.acquire(lmess.length);
// warm up the engines // warm up the engines
SHA256Generator.getInstance().calculateHash(smess); SHA256Generator.getInstance().calculateHash(smess);
SHA256Generator.getInstance().calculateHash(mmess); SHA256Generator.getInstance().calculateHash(mmess);
...@@ -88,35 +83,11 @@ public class SHA256Bench { ...@@ -88,35 +83,11 @@ public class SHA256Bench {
long endmedstartlong = System.currentTimeMillis(); long endmedstartlong = System.currentTimeMillis();
Hash l = cacheOnly ? null : SHA256Generator.getInstance().calculateHash(lmess); Hash l = cacheOnly ? null : SHA256Generator.getInstance().calculateHash(lmess);
long endlong = System.currentTimeMillis(); long endlong = System.currentTimeMillis();
// now do it with caching shorttime += endshortstartmed - startshort;
Hash s1 = SHA256Generator.getInstance().calculateHash(smess, 0, smess.length, scache);
long endshortstartmed1 = System.currentTimeMillis();
Hash m1 = SHA256Generator.getInstance().calculateHash(mmess, 0, mmess.length, mcache);
long endmedstartlong1 = System.currentTimeMillis();
Hash l1 = SHA256Generator.getInstance().calculateHash(lmess, 0, lmess.length, lcache);
long endlong1 = System.currentTimeMillis();
if (cacheOnly) {
// dont verify
} else {
if (!s.equals(s1) || !m.equals(m1) || !l.equals(l1)) {
System.err.println("*ERR* match failed on " + x
+ "s="+ s.equals(s1) + " m=" + m.equals(m1)
+ " l=" + l.equals(l1));
return;
}
}
//System.out.print(".");
shorttime += endshortstartmed - startshort;
medtime += endmedstartlong - endshortstartmed; medtime += endmedstartlong - endshortstartmed;
longtime += endlong - endmedstartlong; longtime += endlong - endmedstartlong;
shorttime1 += endshortstartmed1 - endlong;
medtime1 += endmedstartlong1 - endshortstartmed1;
longtime1 += endlong1 - endmedstartlong1;
if ((minShort == 0) && (minMed == 0) && (minLong == 0) ) { if ((minShort == 0) && (minMed == 0) && (minLong == 0) ) {
minShort = endshortstartmed - startshort; minShort = endshortstartmed - startshort;
maxShort = endshortstartmed - startshort; maxShort = endshortstartmed - startshort;
...@@ -124,13 +95,6 @@ public class SHA256Bench { ...@@ -124,13 +95,6 @@ public class SHA256Bench {
maxMed = endmedstartlong - endshortstartmed; maxMed = endmedstartlong - endshortstartmed;
minLong = endlong - endmedstartlong; minLong = endlong - endmedstartlong;
maxLong = endlong - endmedstartlong; maxLong = endlong - endmedstartlong;
minShort1 = endshortstartmed1 - endlong;
maxShort1 = endshortstartmed1 - endlong;
minMed1 = endmedstartlong1 - endshortstartmed1;
maxMed1 = endmedstartlong1 - endshortstartmed1;
minLong1 = endlong1 - endmedstartlong1;
maxLong1 = endlong1 - endmedstartlong1;
} else { } else {
if (minShort > endshortstartmed - startshort) minShort = endshortstartmed - startshort; if (minShort > endshortstartmed - startshort) minShort = endshortstartmed - startshort;
if (maxShort < endshortstartmed - startshort) maxShort = endshortstartmed - startshort; if (maxShort < endshortstartmed - startshort) maxShort = endshortstartmed - startshort;
...@@ -138,23 +102,12 @@ public class SHA256Bench { ...@@ -138,23 +102,12 @@ public class SHA256Bench {
if (maxMed < endmedstartlong - endshortstartmed) maxMed = endmedstartlong - endshortstartmed; if (maxMed < endmedstartlong - endshortstartmed) maxMed = endmedstartlong - endshortstartmed;
if (minLong > endlong - endmedstartlong) minLong = endlong - endmedstartlong; if (minLong > endlong - endmedstartlong) minLong = endlong - endmedstartlong;
if (maxLong < endlong - endmedstartlong) maxLong = endlong - endmedstartlong; if (maxLong < endlong - endmedstartlong) maxLong = endlong - endmedstartlong;
if (minShort1 > endshortstartmed1 - endlong) minShort1 = endshortstartmed1 - endlong;
if (maxShort1 < endshortstartmed1 - endlong) maxShort1 = endshortstartmed1 - endlong;
if (minMed1 > endmedstartlong1 - endshortstartmed1) minMed1 = endmedstartlong - endshortstartmed;
if (maxMed1 < endmedstartlong1 - endshortstartmed1) maxMed1 = endmedstartlong - endshortstartmed;
if (minLong1 > endlong1 - endmedstartlong1) minLong1 = endlong1 - endmedstartlong1;
if (maxLong1 < endlong1 - endmedstartlong1) maxLong1 = endlong1 - endmedstartlong1;
} }
} }
System.out.println(); System.out.println();
System.out.println("Short Message Time Average : " + (shorttime/times) + "\ttotal: " + shorttime + "\tmin: " + minShort + "\tmax: " + maxShort + "\tBps: " + (shorttime == 0 ? "NaN" : ""+(times*smess.length)/shorttime)); System.out.println("Short Message Time Average : " + (shorttime/times) + "\ttotal: " + shorttime + "\tmin: " + minShort + "\tmax: " + maxShort + "\tBps: " + (shorttime == 0 ? "NaN" : ""+(times*smess.length)/shorttime));
System.out.println("Medium Message Time Average : " + (medtime/times) + "\ttotal: " + medtime + "\tmin: " + minMed + "\tmax: " + maxMed + "\tBps: " + (medtime == 0 ? "NaN" : ""+(times*mmess.length*1000)/medtime)); System.out.println("Medium Message Time Average : " + (medtime/times) + "\ttotal: " + medtime + "\tmin: " + minMed + "\tmax: " + maxMed + "\tBps: " + (medtime == 0 ? "NaN" : ""+(times*mmess.length*1000)/medtime));
System.out.println("Long Message Time Average : " + (longtime/times) + "\ttotal: " + longtime + "\tmin: " + minLong + "\tmax: " + maxLong + "\tBps: " + (longtime == 0 ? "NaN" : "" + (times*lmess.length*1000)/longtime)); System.out.println("Long Message Time Average : " + (longtime/times) + "\ttotal: " + longtime + "\tmin: " + minLong + "\tmax: " + maxLong + "\tBps: " + (longtime == 0 ? "NaN" : "" + (times*lmess.length*1000)/longtime));
System.out.println("Short Message Time (cache) : " + (shorttime1/times) + "\ttotal: " + shorttime1 + "\tmin: " + minShort1 + "\tmax: " + maxShort1 + "\tBps: " + (shorttime1 == 0 ? "NaN" : ""+(times*smess.length)/shorttime1));
System.out.println("Medium Message Time (cache) : " + (medtime1/times) + "\ttotal: " + medtime1 + "\tmin: " + minMed1 + "\tmax: " + maxMed1 + "\tBps: " + (times*mmess.length*1000)/medtime1);
System.out.println("Long Message Time (cache) : " + (longtime1/times) + "\ttotal: " + longtime1 + "\tmin: " + minLong1 + "\tmax: " + maxLong1 + "\tBps: " + (times*lmess.length*1000)/longtime1);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment