Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 26 Oct 2004 23:17:44 +0100
From:      Ian Grigg <iang@systemics.com>
To:        freebsd-java@freebsd.org
Subject:   Crypto takes 17 seconds to wind up for the throw...
Message-ID:  <417ECD08.8010805@systemics.com>

next in thread | raw e-mail | index | archive | help
It seems that a call into javax.crypto.Cipher.getInstance()
takes about 17 seconds to come back with the trivial object
of a cipher.  See follow-on test program and results.

Now, getting a Cipher should be a matter of milliseconds.
It's just an object that feeds some blocks into a bunch of
spinning rotors.  So there's definately a blockage in there
somewhere.

I'm pretty sure the blockage is deep within the SUN JCE code.
I'm pretty sure it's for a really dumb reason.  While I keep
looking, has anyone come across this?  Or got any clues?

iang




galland$  /usr/local/jdk1.4.2/bin/javac CipherSlowTest.java && CLASSPATH=::$CLASSPATH $JAVA CipherSlowTest
....................default provider: SUN
MessDig SHA-1:    126
....................default crypto provider: SunJCE
Cipher DES:       17025
....................addProvider(CryptixCrypto): 12
MessDig SHA-1:    16
Cipher DES:       349
Cipher Null:       5
Cipher AES:        30
Wfgalland$  /usr/local/jdk1.4.2/bin/javac CipherSlowTest.java && CLASSPATH=::$CLASSPATH $JAVA CipherSlowTest
.......................................default provider: SUN
MessDig SHA-1:    129
.......................................default crypto provider: SunJCE
Cipher DES:       17034
.......................................addProvider(CryptixCrypto): 11
MessDig SHA-1:    19
Cipher DES:       355
Cipher Null:      5
Cipher AES:       31
galland$





import javax.crypto.*;
import java.security.*;

/**
  *  JDK 1.4.2
  *  java version "1.4.2-p6"
  *  Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-p6-toor_21_jul_2004_13_48)
  *  Java HotSpot(TM) Client VM (build 1.4.2-p6-toor_21_jul_2004_13_48, mixed mode)
  *
  *  FreeBSD galland 4.9-RC FreeBSD 4.9-RC #7: Tue Sep 30 03:21:16 EDT 2003
  *
  */
public class CipherSlowTest
{
    public static void main(String[] args)
        throws Exception
    {
        long t1 = System.currentTimeMillis();
        long t2;
        String provider;
        String line = ".......................................";

        provider = "SUN";
        System.out.println(line+"default provider: " + provider);

        MessageDigest.getInstance("SHA-1", provider);
        t2 = System.currentTimeMillis();
        System.out.println("MessDig SHA-1:    "+(t2-t1)); t1 = t2;

        provider = "SunJCE";
        System.out.println(line+"default crypto provider: " + provider);
        Cipher.getInstance("DES", provider);

        t2 = System.currentTimeMillis();
        System.out.println("Cipher DES:       "+(t2-t1)); t1 = t2;

        provider = "CryptixCrypto";
        Security.addProvider(new cryptix.jce.provider.CryptixCrypto());

        t2 = System.currentTimeMillis();
        System.out.println(line+"addProvider("+provider+"): "+(t2-t1)); t1 = t2;

        MessageDigest.getInstance("SHA-1", provider);

        t2 = System.currentTimeMillis();
        System.out.println("MessDig SHA-1:    "+(t2-t1)); t1 = t2;

        Cipher.getInstance("DES", provider);

        t2 = System.currentTimeMillis();
        System.out.println("Cipher DES:       "+(t2-t1)); t1 = t2;

        Cipher.getInstance("null", provider);

        t2 = System.currentTimeMillis();
        System.out.println("Cipher Null:      "+(t2-t1)); t1 = t2;

        Cipher.getInstance("Rijndael/ECB/NoPadding", provider);

        t2 = System.currentTimeMillis();
        System.out.println("Cipher AES:       "+(t2-t1)); t1 = t2;
    }
}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?417ECD08.8010805>