[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[iaik-jce] RSA keypair generation with explicit public exponent



It seems that specifying an explicit public exponent to the RSA keypair
generator makes some routine loop forever.

I tried the program listed below: generation with an implicit
(implementation chosen) exponent ends in less than one minute, while
generation with an explicit exponent doesn't terminate even after more than
one hour of computation. The explicit exponent is specified as the only
command line argument in decimal notation: I tried 65537 (which is a usual
recommended value along with 3), and 5 which is the exponent chosen by the
implementation in many cases. No chance :-(

Because getting the private exponent from the public one involves modular
inversion which can be implemented efficiently, I'm wondering if there is a
bug somewhere.

I'm using IAIK-JCE2.6beta1 (commercial version) on JDK1.2.2-001

Thanks for any good suggestion

Raffaello Giulietti
Sobaco Software SA


--------------------------------

import java.math.*;
import java.security.*;

import iaik.security.provider.*;
import iaik.security.random.*;
import iaik.security.rsa.*;

public class RSAKeyPair {
    private int exponent;
    private KeyPair keyPair;

    public void generateImplicitExponentPair() {
        System.out.println("Generating RSA key pair with 1024 bits with
implicit exponent");
        System.out.print("this can take a few minutes... ");
        RSAKeyPairGenerator generator = new RSAKeyPairGenerator();
        generator.initialize(1024, SecRandom.getDefault());
        keyPair = generator.generateKeyPair();
        System.out.println("done");
        System.out.println("The implicit exponent is " +
((RSAPublicKey)keyPair.getPublic()).getPublicExponent());
    }

    public void generateExplicitExponentPair() {
        System.out.println("Generating RSA key pair with 1024 bits with
exponent " + exponent);
        System.out.print("this can take a few minutes... ");
        RSAKeyPairGenerator generator = new RSAKeyPairGenerator();
        generator.initialize(
            1024, BigInteger.valueOf(exponent), SecRandom.getDefault());
        keyPair = generator.generateKeyPair();
        System.out.println("done");
    }

    public static void main(String[] args) {
        try {
            IAIK.addAsProvider();
            RSAKeyPair rsaPair = new RSAKeyPair();
            rsaPair.exponent = Integer.parseInt(args[0]);
            rsaPair.generateImplicitExponentPair();
            System.out.println();
            rsaPair.generateExplicitExponentPair();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}



--
Mailinglist-archive at http://jcewww.iaik.at/mailarchive/iaik-jce/jcethreads.html

To unsubscribe send an email to listserv@iaik.at with the folowing content: UNSUBSCRIBE iaik-jce