0

Has anyone implemented or using Hmac-Whirlpool on Android phone?
I found whirlpool.java on internet but default security provider in Android SDK seems not to have Whirlpool nor Hmac-Whirlpool.

bob
  • 2,674
  • 1
  • 29
  • 46

1 Answers1

0

Android has cut-down version of Bouncy Castle and seems not to allow access to org.bouncycastle.crypto.macs.HMac class, instead javax.crypto.Mac.getInstance(String algorithm) should be used (here). Again only some MAC algorithms seems to be allowed (I saw "HMAC-SHA512" is working). But if you decide to use SpongyCastle library, you can do this (here):

        CipherParameters p = new KeyParameter(key.getBytes("UTF-8"));

        WhirlpoolDigest w = new WhirlpoolDigest();
        HMac hm = new HMac(w);
        hm.init(p);
        hm.update(inbytes, 0, inbytes.length);
        byte[] result = new byte[hm.getMacSize()];
        hm.doFinal(result, 0);

Including SpongyCastle may be problematic to many becuase it increased app size by 1.84MB in android 2.2. Then only relevant files could be imported into the project:

// interfaces
org.bouncycastle.crypto.CipherParameters
org.bouncycastle.crypto.Digest
org.bouncycastle.crypto.ExtendedDigest
org.bouncycastle.crypto.Mac

// classes
org.bouncycastle.crypto.params.KeyParameter
org.bouncycastle.crypto.digests.WhirlpoolDigest
org.bouncycastle.crypto.macs.HMac
org.bouncycastle.crypto.DataLengthException
org.bouncycastle.crypto.RuntimeCryptoException

Community
  • 1
  • 1
bob
  • 2,674
  • 1
  • 29
  • 46