Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

HMAC_SHA1 encryption using javax.crypto.MAC performance problems in SPARC

danielfjbMay 4 2011 — edited May 9 2011
Hi, I'm trying to implement a method to synchronize TOTP cards. In case the server clock and the card clock were different. So I generate a lot of TOTP keys in case to compare it with the real key so at the end I get both of the times in the server. That works in x86 (Sunfire x2200) perfectly and does not take a lot of time doing that (like 2 minutes generating 800000 keys). But when I test it on Oracle BM SPARC (T1000 LDOM 1.1) takes I lot of time. I did all kind of profiling stuff but all point to the method of the generation the TOTP in the HMAC_SHA1.

here is the code (based on JBoss 6 OTP implementation)
public synchronized static String generateTOTP(String key, String time,  int returnDigits, String crypto) throws GeneralSecurityException { 
		String result = null;
		byte[] hash;
		// Using the counter
		// First 8 bytes are for the movingFactor
		// Complaint with base RFC 4226 (HOTP)
		while(time.length() < 16 ) {
			time = "0" + time;
		}
		// Get the HEX in a Byte[]
		byte[] msg = hexStr2Bytes(time);
		// Adding one byte to get the right conversion
		byte[] k = hexStr2Bytes(key);
		hash = hmac_sha1(crypto, k, msg);
		// put selected bytes into result int
		int offset = hash[hash.length - 1] & 0xf;
		int binary =
			((hash[offset] & 0x7f) << 24) |
			((hash[offset + 1] & 0xff) << 16) |
			((hash[offset + 2] & 0xff) << 8) |
			(hash[offset + 3] & 0xff);
		int otp = binary % DIGITS_POWER[ returnDigits ];
		result = Integer.toString(otp);
		while (result.length() < returnDigits ) {
			result = "0" + result;
		}
		return result;
}

private static byte[] hmac_sha1(String crypto, byte[] keyBytes, byte[] text) throws GeneralSecurityException {
		Mac hmac;
		hmac = Mac.getInstance(crypto);
		SecretKeySpec macKey = new SecretKeySpec(keyBytes, "RAW");
		hmac.init(macKey);
		return hmac.doFinal(text);
}
The release of the version to production is delayed about this. I need help either to use another library or finding the right configuration for the SPARC.

Thanks in advance to everybody.

danielfjb
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 6 2011
Added on May 4 2011
4 comments
627 views