Hi guys,

I am designing an Android application for a school project which
requires me to do chain hashing and i have realised that the SHA256
hashing method works really slow on my Android devices compared to an
old PC. I tried it on Nexus one using ice cream sandwhich, Nexus S and
HTC Incredible S using gingerbread.

Below is my implementation of the hash. Had tried with MD5 and SHA1
too and the speed is still slow.
Is there something wrong with my implementation, is there anyway to
speed up the hashing?

public static String SHA256(String toHash) {


        try {
            md = MessageDigest.getInstance("SHA-256");
        } catch (NoSuchAlgorithmException ex) {
        }

        md.update(toHash.getBytes());

        byte byteData[] = md.digest();
        sb = new StringBuilder(byteData.length * 2);
        for (byte b : byteData) {
            sb.append(HEX_CHARS[(b & 0xF0) >> 4]);
            sb.append(HEX_CHARS[b & 0x0F]);
        }
        return sb.toString();
    }

Thank in advance!

Here are some timings which i had collected from my Nexus One:
        Hash Based SHA256       SHA1       MD5  SHA512
No. of hashes   Maximum Time taken (ms)
10      1,024     250           229            213      283
11      2,048     506           465            443      597
12      4,096     998   925            869      1142
13      8,192    1993   1839           1801     2254
14      16,384   3977   3703           3658     4528
15      32,768   7933   7281            7234    8990
16      65,536  15934   14846   14723   18216
17      131,072 32105   29696   29325   36466
18      262,144 64314   59278   58279   73158
19      524,288 128484  119484  116894  146227
20      1,048,576       254778  237204  233112  294316
21      2,097,152       524359  473092  466695  582703

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to