Changeset 0b85bff for core


Ignore:
Timestamp:
Jul 13, 2017 3:53:00 PM (3 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
d4a139f2
Parents:
5ddb4ed
Message:

Crypto: Preserve CRT parameters for RSA private keys (ticket #2005)

Location:
core/java/src/net/i2p/crypto
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/crypto/SigUtil.java

    r5ddb4ed r0b85bff  
    1818import java.security.interfaces.ECPublicKey;
    1919import java.security.interfaces.RSAPrivateKey;
     20import java.security.interfaces.RSAPrivateCrtKey;
    2021import java.security.interfaces.RSAPublicKey;
    2122import java.security.spec.AlgorithmParameterSpec;
     
    445446
    446447    /**
    447      *
     448     *  As of 0.9.31, if pk is a RSASigningPrivateCrtKey,
     449     *  this will return a RSAPrivateCrtKey.
    448450     */
    449451    public static RSAPrivateKey toJavaRSAKey(SigningPrivateKey pk)
    450452                              throws GeneralSecurityException {
     453        if (pk instanceof RSASigningPrivateCrtKey)
     454            return ((RSASigningPrivateCrtKey) pk).toJavaKey();
    451455        KeyFactory kf = KeyFactory.getInstance("RSA");
    452456        // private key is modulus (pubkey) + exponent
     
    469473
    470474    /**
    471      *  @deprecated unused
     475     *  As of 0.9.31, if pk is a RSAPrivateCrtKey,
     476     *  this will return a RSASigningPrivateCrtKey.
    472477     */
    473478    public static SigningPrivateKey fromJavaKey(RSAPrivateKey pk, SigType type)
     
    477482        BigInteger d = pk.getPrivateExponent();
    478483        byte[] b = combine(n, d, type.getPrivkeyLen());
     484        if (pk instanceof RSAPrivateCrtKey)
     485            return RSASigningPrivateCrtKey.fromJavaKey((RSAPrivateCrtKey) pk);
    479486        return new SigningPrivateKey(type, b);
    480487    }
     
    570577     *  Combine two BigIntegers of nominal length = len / 2
    571578     *  @return array of exactly len bytes
    572      *  @since 0.9.9
    573      */
    574     private static byte[] combine(BigInteger x, BigInteger y, int len)
     579     *  @since 0.9.9, package private since 0.9.31
     580     */
     581    static byte[] combine(BigInteger x, BigInteger y, int len)
    575582                              throws InvalidKeyException {
    576583        if ((len & 0x01) != 0)
Note: See TracChangeset for help on using the changeset viewer.