View | Details | Return to bug 26067 | Differences between
and this patch

Collapse All | Expand All

(-)hash/HavalSpi.java (-16 / +4 lines)
Lines 41-66 Link Here
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
42
43
/**
43
/**
44
 * The implementation of the <code>HAVAL</code> <i>Service Provider Interface</i>
44
 * The implementation of the HAVAL <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) Adapter.<p>
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public class HavalSpi extends MessageDigestAdapter
47
public class HavalSpi
48
    extends MessageDigestAdapter
48
{
49
{
49
50
  // Constants and variables
51
  // -------------------------------------------------------------------------
52
53
  // Constructor(s)
54
  // -------------------------------------------------------------------------
55
56
  public HavalSpi()
50
  public HavalSpi()
57
  {
51
  {
58
    super(Registry.HAVAL_HASH);
52
    super(Registry.HAVAL_HASH);
59
  }
53
  }
60
61
  // Class methods
62
  // -------------------------------------------------------------------------
63
64
  // Instance methods
65
  // -------------------------------------------------------------------------
66
}
54
}
(-)hash/MD2Spi.java (-16 / +4 lines)
Lines 41-67 Link Here
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
42
43
/**
43
/**
44
 * <p>The implementation of the MD2 <i>Service Provider Interface</i>
44
 * The implementation of the MD2 <i>Service Provider Interface</i> (<b>SPI</b>)
45
 * (<b>SPI</b>) adapter.</p>
45
 * adapter.
46
 */
46
 */
47
public class MD2Spi extends MessageDigestAdapter
47
public class MD2Spi
48
    extends MessageDigestAdapter
48
{
49
{
49
50
  // Constants and variables
51
  // -------------------------------------------------------------------------
52
53
  // Constructor(s)
54
  // -------------------------------------------------------------------------
55
56
  /** Trivial 0-arguments constructor. */
50
  /** Trivial 0-arguments constructor. */
57
  public MD2Spi()
51
  public MD2Spi()
58
  {
52
  {
59
    super(Registry.MD2_HASH);
53
    super(Registry.MD2_HASH);
60
  }
54
  }
61
62
  // Class methods
63
  // -------------------------------------------------------------------------
64
65
  // Instance methods
66
  // -------------------------------------------------------------------------
67
}
55
}
(-)hash/MD4Spi.java (-16 / +4 lines)
Lines 41-67 Link Here
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
42
43
/**
43
/**
44
 * <p>The implementation of the MD4 <i>Service Provider Interface</i>
44
 * The implementation of the MD4 <i>Service Provider Interface</i> (<b>SPI</b>)
45
 * (<b>SPI</b>) adapter.</p>
45
 * adapter.
46
 */
46
 */
47
public class MD4Spi extends MessageDigestAdapter
47
public class MD4Spi
48
    extends MessageDigestAdapter
48
{
49
{
49
50
  // Constants and variables
51
  // -------------------------------------------------------------------------
52
53
  // Constructor(s)
54
  // -------------------------------------------------------------------------
55
56
  /** Trivial 0-arguments constructor. */
50
  /** Trivial 0-arguments constructor. */
57
  public MD4Spi()
51
  public MD4Spi()
58
  {
52
  {
59
    super(Registry.MD4_HASH);
53
    super(Registry.MD4_HASH);
60
  }
54
  }
61
62
  // Class methods
63
  // -------------------------------------------------------------------------
64
65
  // Instance methods
66
  // -------------------------------------------------------------------------
67
}
55
}
(-)hash/MD5Spi.java (-15 / +3 lines)
Lines 42-66 Link Here
42
42
43
/**
43
/**
44
 * The implementation of the MD5 <i>Service Provider Interface</i> (<b>SPI</b>)
44
 * The implementation of the MD5 <i>Service Provider Interface</i> (<b>SPI</b>)
45
 * adapter.<p>
45
 * adapter.
46
 */
46
 */
47
public class MD5Spi extends MessageDigestAdapter
47
public class MD5Spi
48
    extends MessageDigestAdapter
48
{
49
{
49
50
  // Constants and variables
51
  // -------------------------------------------------------------------------
52
53
  // Constructor(s)
54
  // -------------------------------------------------------------------------
55
56
  public MD5Spi()
50
  public MD5Spi()
57
  {
51
  {
58
    super(Registry.MD5_HASH);
52
    super(Registry.MD5_HASH);
59
  }
53
  }
60
61
  // Class methods
62
  // -------------------------------------------------------------------------
63
64
  // Instance methods
65
  // -------------------------------------------------------------------------
66
}
54
}
(-)hash/MessageDigestAdapter.java (-31 / +19 lines)
Lines 46-80 Link Here
46
46
47
/**
47
/**
48
 * The implementation of a generic {@link java.security.MessageDigest} adapter
48
 * The implementation of a generic {@link java.security.MessageDigest} adapter
49
 * class to wrap gnu.crypto hash instances.<p>
49
 * class to wrap GNU hash instances.
50
 *
50
 * <p>
51
 * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) for the
51
 * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) for
52
 * {@link java.security.MessageDigest} class, which provides the functionality
52
 * the {@link java.security.MessageDigest} class, which provides the
53
 * of a message digest algorithm, such as MD5 or SHA. Message digests are secure
53
 * functionality of a message digest algorithm, such as MD5 or SHA. Message
54
 * one-way hash functions that take arbitrary-sized data and output a fixed-
54
 * digests are secure one-way hash functions that take arbitrary-sized data and
55
 * length hash value.<p>
55
 * output a fixed-length hash value.
56
 *
56
 * <p>
57
 * All the abstract methods in the {@link java.security.MessageDigestSpi} class
57
 * All the abstract methods in the {@link MessageDigestSpi} class are
58
 * are implemented by this class and all its sub-classes.<p>
58
 * implemented by this class and all its sub-classes.
59
 *
59
 * <p>
60
 * All the implementations which subclass this object, and which are serviced by
60
 * All the implementations which subclass this object, and which are serviced by
61
 * the GNU Crypto provider implement the {@link java.lang.Cloneable} interface.<p>
61
 * the GNU provider implement the {@link Cloneable} interface.
62
 */
62
 */
63
class MessageDigestAdapter extends MessageDigestSpi implements Cloneable
63
class MessageDigestAdapter
64
    extends MessageDigestSpi
65
    implements Cloneable
64
{
66
{
65
66
  // Constants and variables
67
  // -------------------------------------------------------------------------
68
69
  /** Our underlying hash instance. */
67
  /** Our underlying hash instance. */
70
  private IMessageDigest adaptee;
68
  private IMessageDigest adaptee;
71
69
72
  // Constructor(s)
73
  // -------------------------------------------------------------------------
74
75
  /**
70
  /**
76
   * Trivial protected constructor.
71
   * Trivial protected constructor.
77
   *
72
   * 
78
   * @param mdName the canonical name of the hash algorithm.
73
   * @param mdName the canonical name of the hash algorithm.
79
   */
74
   */
80
  protected MessageDigestAdapter(String mdName)
75
  protected MessageDigestAdapter(String mdName)
Lines 84-90 Link Here
84
79
85
  /**
80
  /**
86
   * Private constructor for cloning purposes.
81
   * Private constructor for cloning purposes.
87
   *
82
   * 
88
   * @param adaptee a clone of the underlying hash algorithm instance.
83
   * @param adaptee a clone of the underlying hash algorithm instance.
89
   */
84
   */
90
  private MessageDigestAdapter(IMessageDigest adaptee)
85
  private MessageDigestAdapter(IMessageDigest adaptee)
Lines 94-105 Link Here
94
    this.adaptee = adaptee;
89
    this.adaptee = adaptee;
95
  }
90
  }
96
91
97
  // Class methods
98
  // -------------------------------------------------------------------------
99
100
  // java.security.MessageDigestSpi interface implementation
101
  // -------------------------------------------------------------------------
102
103
  public Object clone()
92
  public Object clone()
104
  {
93
  {
105
    return new MessageDigestAdapter((IMessageDigest) adaptee.clone());
94
    return new MessageDigestAdapter((IMessageDigest) adaptee.clone());
Lines 130-138 Link Here
130
  {
119
  {
131
    int result = adaptee.hashSize();
120
    int result = adaptee.hashSize();
132
    if (len < result)
121
    if (len < result)
133
      {
122
      throw new DigestException();
134
        throw new DigestException();
123
135
      }
136
    byte[] md = adaptee.digest();
124
    byte[] md = adaptee.digest();
137
    System.arraycopy(md, 0, buf, offset, result);
125
    System.arraycopy(md, 0, buf, offset, result);
138
    return result;
126
    return result;
(-)hash/RipeMD128Spi.java (-15 / +3 lines)
Lines 42-66 Link Here
42
42
43
/**
43
/**
44
 * The implementation of the RIPEMD-128 <i>Service Provider Interface</i>
44
 * The implementation of the RIPEMD-128 <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) adapter.<p>
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public class RipeMD128Spi extends MessageDigestAdapter
47
public class RipeMD128Spi
48
    extends MessageDigestAdapter
48
{
49
{
49
50
  // Constants and variables
51
  // -------------------------------------------------------------------------
52
53
  // Constructor(s)
54
  // -------------------------------------------------------------------------
55
56
  public RipeMD128Spi()
50
  public RipeMD128Spi()
57
  {
51
  {
58
    super(Registry.RIPEMD128_HASH);
52
    super(Registry.RIPEMD128_HASH);
59
  }
53
  }
60
61
  // Class methods
62
  // -------------------------------------------------------------------------
63
64
  // Instance methods
65
  // -------------------------------------------------------------------------
66
}
54
}
(-)hash/RipeMD160Spi.java (-15 / +3 lines)
Lines 42-66 Link Here
42
42
43
/**
43
/**
44
 * The implementation of the RIPEMD-160 <i>Service Provider Interface</i>
44
 * The implementation of the RIPEMD-160 <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) adapter.<p>
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public class RipeMD160Spi extends MessageDigestAdapter
47
public class RipeMD160Spi
48
    extends MessageDigestAdapter
48
{
49
{
49
50
  // Constants and variables
51
  // -------------------------------------------------------------------------
52
53
  // Constructor(s)
54
  // -------------------------------------------------------------------------
55
56
  public RipeMD160Spi()
50
  public RipeMD160Spi()
57
  {
51
  {
58
    super(Registry.RIPEMD160_HASH);
52
    super(Registry.RIPEMD160_HASH);
59
  }
53
  }
60
61
  // Class methods
62
  // -------------------------------------------------------------------------
63
64
  // Instance methods
65
  // -------------------------------------------------------------------------
66
}
54
}
(-)hash/Sha160Spi.java (-15 / +3 lines)
Lines 42-66 Link Here
42
42
43
/**
43
/**
44
 * The implementation of the SHA-1 (160-bit) <i>Service Provider Interface</i>
44
 * The implementation of the SHA-1 (160-bit) <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) adapter.<p>
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public class Sha160Spi extends MessageDigestAdapter
47
public class Sha160Spi
48
    extends MessageDigestAdapter
48
{
49
{
49
50
  // Constants and variables
51
  // -------------------------------------------------------------------------
52
53
  // Constructor(s)
54
  // -------------------------------------------------------------------------
55
56
  public Sha160Spi()
50
  public Sha160Spi()
57
  {
51
  {
58
    super(Registry.SHA160_HASH);
52
    super(Registry.SHA160_HASH);
59
  }
53
  }
60
61
  // Class methods
62
  // -------------------------------------------------------------------------
63
64
  // Instance methods
65
  // -------------------------------------------------------------------------
66
}
54
}
(-)hash/Sha256Spi.java (-16 / +4 lines)
Lines 41-66 Link Here
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
42
43
/**
43
/**
44
 * <p>The implementation of the SHA-2-1 (256-bit) <i>Service Provider Interface</i>
44
 * The implementation of the SHA-2-1 (256-bit) <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) adapter.</p>
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public class Sha256Spi extends MessageDigestAdapter
47
public class Sha256Spi
48
    extends MessageDigestAdapter
48
{
49
{
49
50
  // Constants and variables
51
  // -------------------------------------------------------------------------
52
53
  // Constructor(s)
54
  // -------------------------------------------------------------------------
55
56
  public Sha256Spi()
50
  public Sha256Spi()
57
  {
51
  {
58
    super(Registry.SHA256_HASH);
52
    super(Registry.SHA256_HASH);
59
  }
53
  }
60
61
  // Class methods
62
  // -------------------------------------------------------------------------
63
64
  // Instance methods
65
  // -------------------------------------------------------------------------
66
}
54
}
(-)hash/Sha384Spi.java (-16 / +4 lines)
Lines 41-66 Link Here
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
42
43
/**
43
/**
44
 * <p>The implementation of the SHA-2-2 (384-bit) <i>Service Provider Interface</i>
44
 * The implementation of the SHA-2-2 (384-bit) <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) adapter.</p>
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public class Sha384Spi extends MessageDigestAdapter
47
public class Sha384Spi
48
    extends MessageDigestAdapter
48
{
49
{
49
50
  // Constants and variables
51
  // -------------------------------------------------------------------------
52
53
  // Constructor(s)
54
  // -------------------------------------------------------------------------
55
56
  public Sha384Spi()
50
  public Sha384Spi()
57
  {
51
  {
58
    super(Registry.SHA384_HASH);
52
    super(Registry.SHA384_HASH);
59
  }
53
  }
60
61
  // Class methods
62
  // -------------------------------------------------------------------------
63
64
  // Instance methods
65
  // -------------------------------------------------------------------------
66
}
54
}
(-)hash/Sha512Spi.java (-16 / +4 lines)
Lines 41-66 Link Here
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
42
43
/**
43
/**
44
 * <p>The implementation of the SHA-2-3 (512-bit) <i>Service Provider Interface</i>
44
 * The implementation of the SHA-2-3 (512-bit) <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) adapter.</p>
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public class Sha512Spi extends MessageDigestAdapter
47
public class Sha512Spi
48
    extends MessageDigestAdapter
48
{
49
{
49
50
  // Constants and variables
51
  // -------------------------------------------------------------------------
52
53
  // Constructor(s)
54
  // -------------------------------------------------------------------------
55
56
  public Sha512Spi()
50
  public Sha512Spi()
57
  {
51
  {
58
    super(Registry.SHA512_HASH);
52
    super(Registry.SHA512_HASH);
59
  }
53
  }
60
61
  // Class methods
62
  // -------------------------------------------------------------------------
63
64
  // Instance methods
65
  // -------------------------------------------------------------------------
66
}
54
}
(-)hash/TigerSpi.java (-16 / +4 lines)
Lines 41-67 Link Here
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
42
43
/**
43
/**
44
 * <p>The implementation of the Tiger <i>Service Provider Interface</i>
44
 * The implementation of the Tiger <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) adapter.</p>
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public class TigerSpi extends MessageDigestAdapter
47
public class TigerSpi
48
    extends MessageDigestAdapter
48
{
49
{
49
50
  // Constants and variables
51
  // -------------------------------------------------------------------------
52
53
  // Constructor(s)
54
  // -------------------------------------------------------------------------
55
56
  /** Trivial 0-arguments constructor. */
50
  /** Trivial 0-arguments constructor. */
57
  public TigerSpi()
51
  public TigerSpi()
58
  {
52
  {
59
    super(Registry.TIGER_HASH);
53
    super(Registry.TIGER_HASH);
60
  }
54
  }
61
62
  // Class methods
63
  // -------------------------------------------------------------------------
64
65
  // Instance methods
66
  // -------------------------------------------------------------------------
67
}
55
}
(-)hash/WhirlpoolSpi.java (-15 / +3 lines)
Lines 42-66 Link Here
42
42
43
/**
43
/**
44
 * The implementation of the Whirlpool <i>Service Provider Interface</i>
44
 * The implementation of the Whirlpool <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) adapter.<p>
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public class WhirlpoolSpi extends MessageDigestAdapter
47
public class WhirlpoolSpi
48
    extends MessageDigestAdapter
48
{
49
{
49
50
  // Constants and variables
51
  // -------------------------------------------------------------------------
52
53
  // Constructor(s)
54
  // -------------------------------------------------------------------------
55
56
  public WhirlpoolSpi()
50
  public WhirlpoolSpi()
57
  {
51
  {
58
    super(Registry.WHIRLPOOL_HASH);
52
    super(Registry.WHIRLPOOL_HASH);
59
  }
53
  }
60
61
  // Class methods
62
  // -------------------------------------------------------------------------
63
64
  // Instance methods
65
  // -------------------------------------------------------------------------
66
}
54
}
(-)prng/HavalRandomSpi.java (-15 / +3 lines)
Lines 42-66 Link Here
42
42
43
/**
43
/**
44
 * The implementation of the HAVAL-based SecureRandom <i>Service Provider
44
 * The implementation of the HAVAL-based SecureRandom <i>Service Provider
45
 * Interface</i> (<b>SPI</b>) Adapter.<p>
45
 * Interface</i> (<b>SPI</b>) adapter.
46
 */
46
 */
47
public class HavalRandomSpi extends SecureRandomAdapter
47
public class HavalRandomSpi
48
    extends SecureRandomAdapter
48
{
49
{
49
50
  // Constants and variables
51
  // -------------------------------------------------------------------------
52
53
  // Constructor(s)
54
  // -------------------------------------------------------------------------
55
56
  public HavalRandomSpi()
50
  public HavalRandomSpi()
57
  {
51
  {
58
    super(Registry.HAVAL_HASH);
52
    super(Registry.HAVAL_HASH);
59
  }
53
  }
60
61
  // Class methods
62
  // -------------------------------------------------------------------------
63
64
  // Instance methods
65
  // -------------------------------------------------------------------------
66
}
54
}
(-)prng/MD2RandomSpi.java (-15 / +3 lines)
Lines 42-66 Link Here
42
42
43
/**
43
/**
44
 * The implementation of the MD2-based SecureRandom <i>Service Provider
44
 * The implementation of the MD2-based SecureRandom <i>Service Provider
45
 * Interface</i> (<b>SPI</b>) adapter.<p>
45
 * Interface</i> (<b>SPI</b>) adapter.
46
 */
46
 */
47
public class MD2RandomSpi extends SecureRandomAdapter
47
public class MD2RandomSpi
48
    extends SecureRandomAdapter
48
{
49
{
49
50
  // Constants and variables
51
  // -------------------------------------------------------------------------
52
53
  // Constructor(s)
54
  // -------------------------------------------------------------------------
55
56
  public MD2RandomSpi()
50
  public MD2RandomSpi()
57
  {
51
  {
58
    super(Registry.MD2_HASH);
52
    super(Registry.MD2_HASH);
59
  }
53
  }
60
61
  // Class methods
62
  // -------------------------------------------------------------------------
63
64
  // Instance methods
65
  // -------------------------------------------------------------------------
66
}
54
}
(-)prng/MD4RandomSpi.java (-15 / +3 lines)
Lines 42-66 Link Here
42
42
43
/**
43
/**
44
 * The implementation of the MD4-based SecureRandom <i>Service Provider
44
 * The implementation of the MD4-based SecureRandom <i>Service Provider
45
 * Interface</i> (<b>SPI</b>) adapter.<p>
45
 * Interface</i> (<b>SPI</b>) adapter.
46
 */
46
 */
47
public class MD4RandomSpi extends SecureRandomAdapter
47
public class MD4RandomSpi
48
    extends SecureRandomAdapter
48
{
49
{
49
50
  // Constants and variables
51
  // -------------------------------------------------------------------------
52
53
  // Constructor(s)
54
  // -------------------------------------------------------------------------
55
56
  public MD4RandomSpi()
50
  public MD4RandomSpi()
57
  {
51
  {
58
    super(Registry.MD4_HASH);
52
    super(Registry.MD4_HASH);
59
  }
53
  }
60
61
  // Class methods
62
  // -------------------------------------------------------------------------
63
64
  // Instance methods
65
  // -------------------------------------------------------------------------
66
}
54
}
(-)prng/MD5RandomSpi.java (-15 / +3 lines)
Lines 42-66 Link Here
42
42
43
/**
43
/**
44
 * The implementation of the MD5-based SecureRandom <i>Service Provider
44
 * The implementation of the MD5-based SecureRandom <i>Service Provider
45
 * Interface</i> (<b>SPI</b>) adapter.<p>
45
 * Interface</i> (<b>SPI</b>) adapter.
46
 */
46
 */
47
public class MD5RandomSpi extends SecureRandomAdapter
47
public class MD5RandomSpi
48
    extends SecureRandomAdapter
48
{
49
{
49
50
  // Constants and variables
51
  // -------------------------------------------------------------------------
52
53
  // Constructor(s)
54
  // -------------------------------------------------------------------------
55
56
  public MD5RandomSpi()
50
  public MD5RandomSpi()
57
  {
51
  {
58
    super(Registry.MD5_HASH);
52
    super(Registry.MD5_HASH);
59
  }
53
  }
60
61
  // Class methods
62
  // -------------------------------------------------------------------------
63
64
  // Instance methods
65
  // -------------------------------------------------------------------------
66
}
54
}
(-)prng/RipeMD128RandomSpi.java (-16 / +4 lines)
Lines 41-66 Link Here
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
42
43
/**
43
/**
44
 * <p>The implementation of the RIPEMD128-based SecureRandom <i>Service Provider
44
 * The implementation of the RIPEMD128-based SecureRandom <i>Service Provider
45
 * Interface</i> (<b>SPI</b>) adapter.<p>
45
 * Interface</i> (<b>SPI</b>) adapter.
46
 */
46
 */
47
public class RipeMD128RandomSpi extends SecureRandomAdapter
47
public class RipeMD128RandomSpi
48
    extends SecureRandomAdapter
48
{
49
{
49
50
  // Constants and variables
51
  // -------------------------------------------------------------------------
52
53
  // Constructor(s)
54
  // -------------------------------------------------------------------------
55
56
  public RipeMD128RandomSpi()
50
  public RipeMD128RandomSpi()
57
  {
51
  {
58
    super(Registry.RIPEMD128_HASH);
52
    super(Registry.RIPEMD128_HASH);
59
  }
53
  }
60
61
  // Class methods
62
  // -------------------------------------------------------------------------
63
64
  // Instance methods
65
  // -------------------------------------------------------------------------
66
}
54
}
(-)prng/RipeMD160RandomSpi.java (-15 / +3 lines)
Lines 42-66 Link Here
42
42
43
/**
43
/**
44
 * The implementation of the RIPEMD160-based SecureRandom <i>Service Provider
44
 * The implementation of the RIPEMD160-based SecureRandom <i>Service Provider
45
 * Interface</i> (<b>SPI</b>) adapter.<p>
45
 * Interface</i> (<b>SPI</b>) adapter.
46
 */
46
 */
47
public class RipeMD160RandomSpi extends SecureRandomAdapter
47
public class RipeMD160RandomSpi
48
    extends SecureRandomAdapter
48
{
49
{
49
50
  // Constants and variables
51
  // -------------------------------------------------------------------------
52
53
  // Constructor(s)
54
  // -------------------------------------------------------------------------
55
56
  public RipeMD160RandomSpi()
50
  public RipeMD160RandomSpi()
57
  {
51
  {
58
    super(Registry.RIPEMD160_HASH);
52
    super(Registry.RIPEMD160_HASH);
59
  }
53
  }
60
61
  // Class methods
62
  // -------------------------------------------------------------------------
63
64
  // Instance methods
65
  // -------------------------------------------------------------------------
66
}
54
}
(-)prng/SecureRandomAdapter.java (-35 / +18 lines)
Lines 45-78 Link Here
45
import java.util.Collections;
45
import java.util.Collections;
46
46
47
/**
47
/**
48
 * <p>The implementation of a generic {@link java.security.SecureRandom} adapter
48
 * The implementation of a generic {@link java.security.SecureRandom} adapter
49
 * class to wrap gnu.crypto prng instances based on Message Digest algorithms.</p>
49
 * class to wrap GNU PRNG instances based on Message Digest algorithms.
50
 *
50
 * <p>
51
 * <p>This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) for
51
 * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) for
52
 * the {@link java.security.SecureRandom} class, which provides the
52
 * the {@link java.security.SecureRandom} class, which provides the
53
 * functionality of a cryptographically strong pseudo-random number generator.</p>
53
 * functionality of a cryptographically strong pseudo-random number generator.
54
 *
54
 * <p>
55
 * <p>All the abstract methods in the {@link SecureRandomSpi} class are
55
 * All the abstract methods in the {@link SecureRandomSpi} class are implemented
56
 * implemented by this class and all its sub-classes.</p>
56
 * by this class and all its sub-classes.
57
 */
57
 */
58
abstract class SecureRandomAdapter extends SecureRandomSpi
58
abstract class SecureRandomAdapter
59
    extends SecureRandomSpi
59
{
60
{
60
61
  // Constants and variables
62
  // -------------------------------------------------------------------------
63
64
  /** Our underlying prng instance. */
61
  /** Our underlying prng instance. */
65
  private MDGenerator adaptee = new MDGenerator();
62
  private MDGenerator adaptee = new MDGenerator();
66
63
67
  /** The name of the message digest algorithm used by the adaptee. */
64
  /** The name of the message digest algorithm used by the adaptee. */
68
  private String mdName;
65
  private String mdName;
69
66
70
  // Constructor(s)
71
  // -------------------------------------------------------------------------
72
73
  /**
67
  /**
74
   * <p>Trivial protected constructor.</p>
68
   * Trivial protected constructor.
75
   *
69
   * 
76
   * @param mdName the canonical name of the underlying hash algorithm.
70
   * @param mdName the canonical name of the underlying hash algorithm.
77
   */
71
   */
78
  protected SecureRandomAdapter(String mdName)
72
  protected SecureRandomAdapter(String mdName)
Lines 80-102 Link Here
80
    super();
74
    super();
81
75
82
    this.mdName = mdName;
76
    this.mdName = mdName;
83
    adaptee.init (Collections.singletonMap (MDGenerator.MD_NAME, mdName));
77
    adaptee.init(Collections.singletonMap(MDGenerator.MD_NAME, mdName));
84
  }
78
  }
85
79
86
  // Class methods
87
  // -------------------------------------------------------------------------
88
89
  // Instance methods
90
  // -------------------------------------------------------------------------
91
92
  // java.security.SecureRandomSpi interface implementation ------------------
93
94
  public byte[] engineGenerateSeed(int numBytes)
80
  public byte[] engineGenerateSeed(int numBytes)
95
  {
81
  {
96
    if (numBytes < 1)
82
    if (numBytes < 1)
97
      {
83
      return new byte[0];
98
        return new byte[0];
84
99
      }
100
    byte[] result = new byte[numBytes];
85
    byte[] result = new byte[numBytes];
101
    this.engineNextBytes(result);
86
    this.engineNextBytes(result);
102
    return result;
87
    return result;
Lines 104-113 Link Here
104
89
105
  public void engineNextBytes(byte[] bytes)
90
  public void engineNextBytes(byte[] bytes)
106
  {
91
  {
107
    if (!adaptee.isInitialised())
92
    if (! adaptee.isInitialised())
108
      {
93
      this.engineSetSeed(new byte[0]);
109
        this.engineSetSeed(new byte[0]);
110
      }
111
    try
94
    try
112
      {
95
      {
113
        adaptee.nextBytes(bytes, 0, bytes.length);
96
        adaptee.nextBytes(bytes, 0, bytes.length);
Lines 119-124 Link Here
119
102
120
  public void engineSetSeed(byte[] seed)
103
  public void engineSetSeed(byte[] seed)
121
  {
104
  {
122
    adaptee.addRandomBytes (seed);
105
    adaptee.addRandomBytes(seed);
123
  }
106
  }
124
}
107
}
(-)prng/Sha160RandomSpi.java (-15 / +3 lines)
Lines 42-66 Link Here
42
42
43
/**
43
/**
44
 * The implementation of the SHA1-based SecureRandom <i>Service Provider
44
 * The implementation of the SHA1-based SecureRandom <i>Service Provider
45
 * Interface</i> (<b>SPI</b>) adapter.<p>
45
 * Interface</i> (<b>SPI</b>) adapter.
46
 */
46
 */
47
public class Sha160RandomSpi extends SecureRandomAdapter
47
public class Sha160RandomSpi
48
    extends SecureRandomAdapter
48
{
49
{
49
50
  // Constants and variables
51
  // -------------------------------------------------------------------------
52
53
  // Constructor(s)
54
  // -------------------------------------------------------------------------
55
56
  public Sha160RandomSpi()
50
  public Sha160RandomSpi()
57
  {
51
  {
58
    super(Registry.SHA160_HASH);
52
    super(Registry.SHA160_HASH);
59
  }
53
  }
60
61
  // Class methods
62
  // -------------------------------------------------------------------------
63
64
  // Instance methods
65
  // -------------------------------------------------------------------------
66
}
54
}
(-)prng/Sha256RandomSpi.java (-16 / +4 lines)
Lines 41-66 Link Here
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
42
43
/**
43
/**
44
 * <p>The implementation of the SHA-256 based SecureRandom <i>Service Provider
44
 * The implementation of the SHA-256 based SecureRandom <i>Service Provider
45
 * Interface</i> (<b>SPI</b>) adapter.</p>
45
 * Interface</i> (<b>SPI</b>) adapter.
46
 */
46
 */
47
public class Sha256RandomSpi extends SecureRandomAdapter
47
public class Sha256RandomSpi
48
    extends SecureRandomAdapter
48
{
49
{
49
50
  // Constants and variables
51
  // -------------------------------------------------------------------------
52
53
  // Constructor(s)
54
  // -------------------------------------------------------------------------
55
56
  public Sha256RandomSpi()
50
  public Sha256RandomSpi()
57
  {
51
  {
58
    super(Registry.SHA256_HASH);
52
    super(Registry.SHA256_HASH);
59
  }
53
  }
60
61
  // Class methods
62
  // -------------------------------------------------------------------------
63
64
  // Instance methods
65
  // -------------------------------------------------------------------------
66
}
54
}
(-)prng/Sha384RandomSpi.java (-16 / +4 lines)
Lines 41-66 Link Here
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
42
43
/**
43
/**
44
 * <p>The implementation of the SHA-384 based SecureRandom <i>Service Provider
44
 * The implementation of the SHA-384 based SecureRandom <i>Service Provider
45
 * Interface</i> (<b>SPI</b>) adapter.</p>
45
 * Interface</i> (<b>SPI</b>) adapter.
46
 */
46
 */
47
public class Sha384RandomSpi extends SecureRandomAdapter
47
public class Sha384RandomSpi
48
    extends SecureRandomAdapter
48
{
49
{
49
50
  // Constants and variables
51
  // -------------------------------------------------------------------------
52
53
  // Constructor(s)
54
  // -------------------------------------------------------------------------
55
56
  public Sha384RandomSpi()
50
  public Sha384RandomSpi()
57
  {
51
  {
58
    super(Registry.SHA384_HASH);
52
    super(Registry.SHA384_HASH);
59
  }
53
  }
60
61
  // Class methods
62
  // -------------------------------------------------------------------------
63
64
  // Instance methods
65
  // -------------------------------------------------------------------------
66
}
54
}
(-)prng/Sha512RandomSpi.java (-16 / +4 lines)
Lines 41-66 Link Here
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
42
43
/**
43
/**
44
 * <p>The implementation of the SHA-512 based SecureRandom <i>Service Provider
44
 * The implementation of the SHA-512 based SecureRandom <i>Service Provider
45
 * Interface</i> (<b>SPI</b>) adapter.</p>
45
 * Interface</i> (<b>SPI</b>) adapter.
46
 */
46
 */
47
public class Sha512RandomSpi extends SecureRandomAdapter
47
public class Sha512RandomSpi
48
    extends SecureRandomAdapter
48
{
49
{
49
50
  // Constants and variables
51
  // -------------------------------------------------------------------------
52
53
  // Constructor(s)
54
  // -------------------------------------------------------------------------
55
56
  public Sha512RandomSpi()
50
  public Sha512RandomSpi()
57
  {
51
  {
58
    super(Registry.SHA512_HASH);
52
    super(Registry.SHA512_HASH);
59
  }
53
  }
60
61
  // Class methods
62
  // -------------------------------------------------------------------------
63
64
  // Instance methods
65
  // -------------------------------------------------------------------------
66
}
54
}
(-)prng/TigerRandomSpi.java (-15 / +3 lines)
Lines 42-66 Link Here
42
42
43
/**
43
/**
44
 * The implementation of the Tiger based SecureRandom <i>Service Provider
44
 * The implementation of the Tiger based SecureRandom <i>Service Provider
45
 * Interface</i> (<b>SPI</b>) adapter.<p>
45
 * Interface</i> (<b>SPI</b>) adapter.
46
 */
46
 */
47
public class TigerRandomSpi extends SecureRandomAdapter
47
public class TigerRandomSpi
48
    extends SecureRandomAdapter
48
{
49
{
49
50
  // Constants and variables
51
  // -------------------------------------------------------------------------
52
53
  // Constructor(s)
54
  // -------------------------------------------------------------------------
55
56
  public TigerRandomSpi()
50
  public TigerRandomSpi()
57
  {
51
  {
58
    super(Registry.TIGER_HASH);
52
    super(Registry.TIGER_HASH);
59
  }
53
  }
60
61
  // Class methods
62
  // -------------------------------------------------------------------------
63
64
  // Instance methods
65
  // -------------------------------------------------------------------------
66
}
54
}
(-)prng/WhirlpoolRandomSpi.java (-15 / +3 lines)
Lines 42-66 Link Here
42
42
43
/**
43
/**
44
 * The implementation of the Whirlpool-based SecureRandom <i>Service Provider
44
 * The implementation of the Whirlpool-based SecureRandom <i>Service Provider
45
 * Interface</i> (<b>SPI</b>) adapter.<p>
45
 * Interface</i> (<b>SPI</b>) adapter.
46
 */
46
 */
47
public class WhirlpoolRandomSpi extends SecureRandomAdapter
47
public class WhirlpoolRandomSpi
48
    extends SecureRandomAdapter
48
{
49
{
49
50
  // Constants and variables
51
  // -------------------------------------------------------------------------
52
53
  // Constructor(s)
54
  // -------------------------------------------------------------------------
55
56
  public WhirlpoolRandomSpi()
50
  public WhirlpoolRandomSpi()
57
  {
51
  {
58
    super(Registry.WHIRLPOOL_HASH);
52
    super(Registry.WHIRLPOOL_HASH);
59
  }
53
  }
60
61
  // Class methods
62
  // -------------------------------------------------------------------------
63
64
  // Instance methods
65
  // -------------------------------------------------------------------------
66
}
54
}
(-)sig/DSSKeyFactory.java (-26 / +9 lines)
Lines 61-70 Link Here
61
61
62
/**
62
/**
63
 * DSA key factory.
63
 * DSA key factory.
64
 *
64
 * 
65
 * @author Casey Marshall (rsdio@metastatic.org)
65
 * @author Casey Marshall (rsdio@metastatic.org)
66
 */
66
 */
67
public class DSSKeyFactory extends KeyFactorySpi
67
public class DSSKeyFactory
68
    extends KeyFactorySpi
68
{
69
{
69
  // implicit 0-arguments constructor
70
  // implicit 0-arguments constructor
70
71
Lines 80-86 Link Here
80
        BigInteger y = spec.getY();
81
        BigInteger y = spec.getY();
81
        return new DSSPublicKey(Registry.X509_ENCODING_ID, p, q, g, y);
82
        return new DSSPublicKey(Registry.X509_ENCODING_ID, p, q, g, y);
82
      }
83
      }
83
84
    if (keySpec instanceof X509EncodedKeySpec)
84
    if (keySpec instanceof X509EncodedKeySpec)
85
      {
85
      {
86
        X509EncodedKeySpec spec = (X509EncodedKeySpec) keySpec;
86
        X509EncodedKeySpec spec = (X509EncodedKeySpec) keySpec;
Lines 93-104 Link Here
93
          }
93
          }
94
        catch (RuntimeException x)
94
        catch (RuntimeException x)
95
          {
95
          {
96
            InvalidKeySpecException y = new InvalidKeySpecException();
96
            throw new InvalidKeySpecException(x.getMessage(), x);
97
            y.initCause(x);
98
            throw y;
99
          }
97
          }
100
      }
98
      }
101
102
    throw new InvalidKeySpecException("Unsupported (public) key specification");
99
    throw new InvalidKeySpecException("Unsupported (public) key specification");
103
  }
100
  }
104
101
Lines 114-120 Link Here
114
        BigInteger x = spec.getX();
111
        BigInteger x = spec.getX();
115
        return new DSSPrivateKey(Registry.PKCS8_ENCODING_ID, p, q, g, x);
112
        return new DSSPrivateKey(Registry.PKCS8_ENCODING_ID, p, q, g, x);
116
      }
113
      }
117
118
    if (keySpec instanceof PKCS8EncodedKeySpec)
114
    if (keySpec instanceof PKCS8EncodedKeySpec)
119
      {
115
      {
120
        PKCS8EncodedKeySpec spec = (PKCS8EncodedKeySpec) keySpec;
116
        PKCS8EncodedKeySpec spec = (PKCS8EncodedKeySpec) keySpec;
Lines 127-138 Link Here
127
          }
123
          }
128
        catch (RuntimeException x)
124
        catch (RuntimeException x)
129
          {
125
          {
130
            InvalidKeySpecException y = new InvalidKeySpecException();
126
            throw new InvalidKeySpecException(x.getMessage(), x);
131
            y.initCause(x);
132
            throw y;
133
          }
127
          }
134
      }
128
      }
135
136
    throw new InvalidKeySpecException("Unsupported (private) key specification");
129
    throw new InvalidKeySpecException("Unsupported (private) key specification");
137
  }
130
  }
138
131
Lines 150-156 Link Here
150
            BigInteger y = dsaKey.getY();
143
            BigInteger y = dsaKey.getY();
151
            return new DSAPublicKeySpec(y, p, q, g);
144
            return new DSAPublicKeySpec(y, p, q, g);
152
          }
145
          }
153
154
        if (keySpec.isAssignableFrom(X509EncodedKeySpec.class))
146
        if (keySpec.isAssignableFrom(X509EncodedKeySpec.class))
155
          {
147
          {
156
            if (key instanceof DSSPublicKey)
148
            if (key instanceof DSSPublicKey)
Lines 159-177 Link Here
159
                byte[] encoded = dssKey.getEncoded(Registry.X509_ENCODING_ID);
151
                byte[] encoded = dssKey.getEncoded(Registry.X509_ENCODING_ID);
160
                return new X509EncodedKeySpec(encoded);
152
                return new X509EncodedKeySpec(encoded);
161
              }
153
              }
162
163
            if (Registry.X509_ENCODING_SORT_NAME.equalsIgnoreCase(key.getFormat()))
154
            if (Registry.X509_ENCODING_SORT_NAME.equalsIgnoreCase(key.getFormat()))
164
              {
155
              {
165
                byte[] encoded = key.getEncoded();
156
                byte[] encoded = key.getEncoded();
166
                return new X509EncodedKeySpec(encoded);
157
                return new X509EncodedKeySpec(encoded);
167
              }
158
              }
168
159
            throw new InvalidKeySpecException(
169
            throw new InvalidKeySpecException("Wrong key type or unsupported (public) key specification");
160
                "Wrong key type or unsupported (public) key specification");
170
          }
161
          }
171
172
        throw new InvalidKeySpecException("Unsupported (public) key specification");
162
        throw new InvalidKeySpecException("Unsupported (public) key specification");
173
      }
163
      }
174
175
    if (key instanceof DSAPrivateKey)
164
    if (key instanceof DSAPrivateKey)
176
      {
165
      {
177
        if (keySpec.isAssignableFrom(DSAPrivateKeySpec.class))
166
        if (keySpec.isAssignableFrom(DSAPrivateKeySpec.class))
Lines 183-189 Link Here
183
            BigInteger x = dsaKey.getX();
172
            BigInteger x = dsaKey.getX();
184
            return new DSAPrivateKeySpec(x, p, q, g);
173
            return new DSAPrivateKeySpec(x, p, q, g);
185
          }
174
          }
186
187
        if (keySpec.isAssignableFrom(PKCS8EncodedKeySpec.class))
175
        if (keySpec.isAssignableFrom(PKCS8EncodedKeySpec.class))
188
          {
176
          {
189
            if (key instanceof DSSPrivateKey)
177
            if (key instanceof DSSPrivateKey)
Lines 192-210 Link Here
192
                byte[] encoded = dssKey.getEncoded(Registry.PKCS8_ENCODING_ID);
180
                byte[] encoded = dssKey.getEncoded(Registry.PKCS8_ENCODING_ID);
193
                return new PKCS8EncodedKeySpec(encoded);
181
                return new PKCS8EncodedKeySpec(encoded);
194
              }
182
              }
195
196
            if (Registry.PKCS8_ENCODING_SHORT_NAME.equalsIgnoreCase(key.getFormat()))
183
            if (Registry.PKCS8_ENCODING_SHORT_NAME.equalsIgnoreCase(key.getFormat()))
197
              {
184
              {
198
                byte[] encoded = key.getEncoded();
185
                byte[] encoded = key.getEncoded();
199
                return new PKCS8EncodedKeySpec(encoded);
186
                return new PKCS8EncodedKeySpec(encoded);
200
              }
187
              }
201
188
            throw new InvalidKeySpecException(
202
            throw new InvalidKeySpecException("Wrong key type or unsupported (private) key specification");
189
                "Wrong key type or unsupported (private) key specification");
203
          }
190
          }
204
205
        throw new InvalidKeySpecException("Unsupported (private) key specification");
191
        throw new InvalidKeySpecException("Unsupported (private) key specification");
206
      }
192
      }
207
208
    throw new InvalidKeySpecException("Wrong key type or unsupported key specification");
193
    throw new InvalidKeySpecException("Wrong key type or unsupported key specification");
209
  }
194
  }
210
195
Lines 222-228 Link Here
222
        BigInteger y = dsaKey.getY();
207
        BigInteger y = dsaKey.getY();
223
        return new DSSPublicKey(Registry.X509_ENCODING_ID, p, q, g, y);
208
        return new DSSPublicKey(Registry.X509_ENCODING_ID, p, q, g, y);
224
      }
209
      }
225
226
    if (key instanceof DSAPrivateKey)
210
    if (key instanceof DSAPrivateKey)
227
      {
211
      {
228
        DSAPrivateKey dsaKey = (DSAPrivateKey) key;
212
        DSAPrivateKey dsaKey = (DSAPrivateKey) key;
Lines 232-238 Link Here
232
        BigInteger x = dsaKey.getX();
216
        BigInteger x = dsaKey.getX();
233
        return new DSSPrivateKey(Registry.PKCS8_ENCODING_ID, p, q, g, x);
217
        return new DSSPrivateKey(Registry.PKCS8_ENCODING_ID, p, q, g, x);
234
      }
218
      }
235
236
    throw new InvalidKeyException("Wrong key type");
219
    throw new InvalidKeyException("Wrong key type");
237
  }
220
  }
238
}
221
}
(-)sig/DSSKeyPairGeneratorSpi.java (-39 / +18 lines)
Lines 52-84 Link Here
52
52
53
/**
53
/**
54
 * The implementation of a {@link java.security.KeyPairGenerator} adapter class
54
 * The implementation of a {@link java.security.KeyPairGenerator} adapter class
55
 * to wrap gnu.crypto DSS keypair generator instances.<p>
55
 * to wrap GNU DSS keypair generator instances.
56
 *
56
 * <p>
57
 * In case the client does not explicitly initialize the KeyPairGenerator (via
57
 * In case the client does not explicitly initialize the KeyPairGenerator (via a
58
 * a call to an <code>initialize()</code> method), the GNU Crypto provider
58
 * call to an <code>initialize()</code> method), the GNU provider uses a
59
 * uses a default <i>modulus</i> size (keysize) of 1024 bits.<p>
59
 * default <i>modulus</i> size (keysize) of 1024 bits.
60
 */
60
 */
61
public class DSSKeyPairGeneratorSpi extends KeyPairGeneratorAdapter implements
61
public class DSSKeyPairGeneratorSpi
62
    DSAKeyPairGenerator
62
    extends KeyPairGeneratorAdapter
63
    implements DSAKeyPairGenerator
63
{
64
{
64
65
  // Constants and variables
66
  // -------------------------------------------------------------------------
67
68
  // Constructor(s)
69
  // -------------------------------------------------------------------------
70
71
  public DSSKeyPairGeneratorSpi()
65
  public DSSKeyPairGeneratorSpi()
72
  {
66
  {
73
    super(Registry.DSS_KPG);
67
    super(Registry.DSS_KPG);
74
  }
68
  }
75
69
76
  // Class methods
77
  // -------------------------------------------------------------------------
78
79
  // Instance methods
80
  // -------------------------------------------------------------------------
81
82
  public void initialize(int keysize, SecureRandom random)
70
  public void initialize(int keysize, SecureRandom random)
83
  {
71
  {
84
    this.initialize(keysize, false, random);
72
    this.initialize(keysize, false, random);
Lines 90-107 Link Here
90
    HashMap attributes = new HashMap();
78
    HashMap attributes = new HashMap();
91
    if (params != null)
79
    if (params != null)
92
      {
80
      {
93
        if (!(params instanceof DSAParameterSpec))
81
        if (! (params instanceof DSAParameterSpec))
94
          throw new InvalidAlgorithmParameterException(
82
          throw new InvalidAlgorithmParameterException(
95
              "Parameters argument is not a non-null instance, or " +
83
              "Parameters argument is not a non-null instance, or "
96
              "sub-instance, of java.security.spec.DSAParameterSpec");
84
              + "sub-instance, of java.security.spec.DSAParameterSpec");
97
98
        attributes.put(DSSKeyPairGenerator.DSS_PARAMETERS, params);
85
        attributes.put(DSSKeyPairGenerator.DSS_PARAMETERS, params);
99
      }
86
      }
100
101
    if (random != null)
87
    if (random != null)
102
      {
88
      attributes.put(DSSKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);
103
        attributes.put(DSSKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);
104
      }
105
89
106
    attributes.put(DSSKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
90
    attributes.put(DSSKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
107
                   Integer.valueOf(Registry.ASN1_ENCODING_ID));
91
                   Integer.valueOf(Registry.ASN1_ENCODING_ID));
Lines 111-132 Link Here
111
      }
95
      }
112
    catch (IllegalArgumentException x)
96
    catch (IllegalArgumentException x)
113
      {
97
      {
114
        InvalidAlgorithmParameterException y =
98
        throw new InvalidAlgorithmParameterException(x.getMessage(), x);
115
            new InvalidAlgorithmParameterException();
116
        y.initCause(x);
117
        throw y;
118
      }
99
      }
119
  }
100
  }
120
101
121
  // java.security.interfaces.DSAKeyPairGenerator interface implementation -----
122
123
  public void initialize(DSAParams params, SecureRandom random)
102
  public void initialize(DSAParams params, SecureRandom random)
124
      throws InvalidParameterException
103
      throws InvalidParameterException
125
  {
104
  {
126
    if (params == null || !(params instanceof DSAParameterSpec))
105
    if (params == null || !(params instanceof DSAParameterSpec))
127
      throw new InvalidParameterException(
106
      throw new InvalidParameterException(
128
          "Parameters argument is either null or is not an instance, or " +
107
          "Parameters argument is either null or is not an instance, or "
129
          "sub-instance, of java.security.spec.DSAParameterSpec");
108
          + "sub-instance, of java.security.spec.DSAParameterSpec");
130
    DSAParameterSpec spec = (DSAParameterSpec) params;
109
    DSAParameterSpec spec = (DSAParameterSpec) params;
131
    try
110
    try
132
      {
111
      {
Lines 134-140 Link Here
134
      }
113
      }
135
    catch (InvalidAlgorithmParameterException x)
114
    catch (InvalidAlgorithmParameterException x)
136
      {
115
      {
137
        InvalidParameterException y = new InvalidParameterException();
116
        InvalidParameterException y = new InvalidParameterException(x.getMessage());
138
        y.initCause(x);
117
        y.initCause(x);
139
        throw y;
118
        throw y;
140
      }
119
      }
Lines 149-155 Link Here
149
      attributes.put(DSSKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);
128
      attributes.put(DSSKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);
150
129
151
    attributes.put(DSSKeyPairGenerator.USE_DEFAULTS,
130
    attributes.put(DSSKeyPairGenerator.USE_DEFAULTS,
152
                   Boolean.valueOf(!genParams));
131
                   Boolean.valueOf(! genParams));
153
    attributes.put(DSSKeyPairGenerator.STRICT_DEFAULTS, Boolean.TRUE);
132
    attributes.put(DSSKeyPairGenerator.STRICT_DEFAULTS, Boolean.TRUE);
154
    attributes.put(DSSKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
133
    attributes.put(DSSKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
155
                   Integer.valueOf(Registry.ASN1_ENCODING_ID));
134
                   Integer.valueOf(Registry.ASN1_ENCODING_ID));
Lines 159-165 Link Here
159
      }
138
      }
160
    catch (IllegalArgumentException x)
139
    catch (IllegalArgumentException x)
161
      {
140
      {
162
        InvalidParameterException y = new InvalidParameterException();
141
        InvalidParameterException y = new InvalidParameterException(x.getMessage());
163
        y.initCause(x);
142
        y.initCause(x);
164
        throw y;
143
        throw y;
165
      }
144
      }
(-)sig/DSSParameters.java (-2 lines)
Lines 136-142 Link Here
136
        if (! format.equalsIgnoreCase(Registry.ASN1_ENCODING_SHORT_NAME))
136
        if (! format.equalsIgnoreCase(Registry.ASN1_ENCODING_SHORT_NAME))
137
          throw new IOException("Unknown or unsupported format: " + format);
137
          throw new IOException("Unknown or unsupported format: " + format);
138
      }
138
      }
139
140
    engineInit(params);
139
    engineInit(params);
141
  }
140
  }
142
141
Lines 191-197 Link Here
191
        if (! format.equalsIgnoreCase(Registry.ASN1_ENCODING_SHORT_NAME))
190
        if (! format.equalsIgnoreCase(Registry.ASN1_ENCODING_SHORT_NAME))
192
          throw new IOException("Unknown or unsupported format: " + format);
191
          throw new IOException("Unknown or unsupported format: " + format);
193
      }
192
      }
194
195
    return engineGetEncoded();
193
    return engineGetEncoded();
196
  }
194
  }
197
195
(-)sig/DSSRawSignatureSpi.java (-17 / +5 lines)
Lines 42-68 Link Here
42
import gnu.java.security.sig.dss.DSSSignatureRawCodec;
42
import gnu.java.security.sig.dss.DSSSignatureRawCodec;
43
43
44
/**
44
/**
45
 * The implementation of <i>Service Provider Interface</i> (<b>SPI</b>) adapter
45
 * The implementation of <i>Service Provider Interface</i> (<b>SPI</b>)
46
 * for the DSS (Digital Signature Standard) signature scheme, encoded and/or
46
 * adapter for the DSS (Digital Signature Standard) signature scheme, encoded
47
 * decoded in RAW format.<p>
47
 * and/or decoded in RAW format.
48
 */
48
 */
49
public class DSSRawSignatureSpi extends SignatureAdapter
49
public class DSSRawSignatureSpi
50
    extends SignatureAdapter
50
{
51
{
51
52
  // Constants and variables
53
  // -------------------------------------------------------------------------
54
55
  // Constructor(s)
56
  // -------------------------------------------------------------------------
57
58
  public DSSRawSignatureSpi()
52
  public DSSRawSignatureSpi()
59
  {
53
  {
60
    super(Registry.DSS_SIG, new DSSSignatureRawCodec());
54
    super(Registry.DSS_SIG, new DSSSignatureRawCodec());
61
  }
55
  }
62
63
  // Class methods
64
  // -------------------------------------------------------------------------
65
66
  // Instance methods
67
  // -------------------------------------------------------------------------
68
}
56
}
(-)sig/EncodedKeyFactory.java (-42 / +12 lines)
Lines 80-90 Link Here
80
{
80
{
81
  private static final Logger log = Logger.getLogger(EncodedKeyFactory.class.getName());
81
  private static final Logger log = Logger.getLogger(EncodedKeyFactory.class.getName());
82
82
83
  // implicit 0-arguments constructor
84
85
  // Class methods
86
  // --------------------------------------------------------------------------
87
88
  private static Object invokeConstructor(String className, Object[] params)
83
  private static Object invokeConstructor(String className, Object[] params)
89
      throws InvalidKeySpecException
84
      throws InvalidKeySpecException
90
  {
85
  {
Lines 97-117 Link Here
97
      }
92
      }
98
    catch (InstantiationException x)
93
    catch (InstantiationException x)
99
      {
94
      {
100
        InvalidKeySpecException y = new InvalidKeySpecException();
95
        throw new InvalidKeySpecException(x.getMessage(), x);
101
        y.initCause(x);
102
        throw y;
103
      }
96
      }
104
    catch (IllegalAccessException x)
97
    catch (IllegalAccessException x)
105
      {
98
      {
106
        InvalidKeySpecException y = new InvalidKeySpecException();
99
        throw new InvalidKeySpecException(x.getMessage(), x);
107
        y.initCause(y);
108
        throw y;
109
      }
100
      }
110
    catch (InvocationTargetException x)
101
    catch (InvocationTargetException x)
111
      {
102
      {
112
        InvalidKeySpecException y = new InvalidKeySpecException();
103
        throw new InvalidKeySpecException(x.getMessage(), x);
113
        y.initCause(x);
114
        throw y;
115
      }
104
      }
116
  }
105
  }
117
106
Lines 125-133 Link Here
125
      }
114
      }
126
    catch (ClassNotFoundException x)
115
    catch (ClassNotFoundException x)
127
      {
116
      {
128
        InvalidKeySpecException y = new InvalidKeySpecException();
117
        throw new InvalidKeySpecException(x.getMessage(), x);
129
        y.initCause(x);
130
        throw y;
131
      }
118
      }
132
  }
119
  }
133
120
Lines 145-153 Link Here
145
      }
132
      }
146
    catch (NoSuchMethodException x)
133
    catch (NoSuchMethodException x)
147
      {
134
      {
148
        InvalidKeySpecException y = new InvalidKeySpecException();
135
        throw new InvalidKeySpecException(x.getMessage(), x);
149
        y.initCause(x);
150
        throw y;
151
      }
136
      }
152
  }
137
  }
153
138
Lines 163-177 Link Here
163
      }
148
      }
164
    catch (IllegalAccessException x)
149
    catch (IllegalAccessException x)
165
      {
150
      {
166
        InvalidKeySpecException y = new InvalidKeySpecException();
151
        throw new InvalidKeySpecException(x.getMessage(), x);
167
        y.initCause(x);
168
        throw y;
169
      }
152
      }
170
    catch (InvocationTargetException x)
153
    catch (InvocationTargetException x)
171
      {
154
      {
172
        InvalidKeySpecException y = new InvalidKeySpecException();
155
        throw new InvalidKeySpecException(x.getMessage(), x);
173
        y.initCause(x);
174
        throw y;
175
      }
156
      }
176
  }
157
  }
177
158
Lines 185-205 Link Here
185
      }
166
      }
186
    catch (NoSuchMethodException x)
167
    catch (NoSuchMethodException x)
187
      {
168
      {
188
        InvalidKeySpecException y = new InvalidKeySpecException();
169
        throw new InvalidKeySpecException(x.getMessage(), x);
189
        y.initCause(x);
190
        throw y;
191
      }
170
      }
192
  }
171
  }
193
172
194
  // Instance methods
195
  // --------------------------------------------------------------------------
196
197
  protected PublicKey engineGeneratePublic(KeySpec keySpec)
173
  protected PublicKey engineGeneratePublic(KeySpec keySpec)
198
      throws InvalidKeySpecException
174
      throws InvalidKeySpecException
199
  {
175
  {
200
    if (Configuration.DEBUG)
176
    if (Configuration.DEBUG)
201
      log.entering(this.getClass().getName(), "engineGeneratePublic()", keySpec);
177
      log.entering(this.getClass().getName(), "engineGeneratePublic()", keySpec);
202
203
    PublicKey result = null;
178
    PublicKey result = null;
204
    if (keySpec instanceof DSAPublicKeySpec)
179
    if (keySpec instanceof DSAPublicKeySpec)
205
      result = decodeDSSPublicKey((DSAPublicKeySpec) keySpec);
180
      result = decodeDSSPublicKey((DSAPublicKeySpec) keySpec);
Lines 226-232 Link Here
226
              log.log(Level.FINE, "Exception in DSSPublicKey.valueOf(). Ignore",
201
              log.log(Level.FINE, "Exception in DSSPublicKey.valueOf(). Ignore",
227
                      ignored);
202
                      ignored);
228
          }
203
          }
229
230
        if (! ok) // try RSA
204
        if (! ok) // try RSA
231
          try
205
          try
232
            {
206
            {
Lines 240-246 Link Here
240
                        "Exception in GnuRSAPublicKey.valueOf(). Ignore",
214
                        "Exception in GnuRSAPublicKey.valueOf(). Ignore",
241
                        ignored);
215
                        ignored);
242
            }
216
            }
243
244
          if (! ok) // try DH
217
          if (! ok) // try DH
245
            result = decodeDHPublicKey(input);
218
            result = decodeDHPublicKey(input);
246
      }
219
      }
Lines 254-260 Link Here
254
  {
227
  {
255
    if (Configuration.DEBUG)
228
    if (Configuration.DEBUG)
256
      log.entering(this.getClass().getName(), "engineGeneratePrivate()", keySpec);
229
      log.entering(this.getClass().getName(), "engineGeneratePrivate()", keySpec);
257
258
    PrivateKey result = null;
230
    PrivateKey result = null;
259
    if (keySpec instanceof DSAPrivateKeySpec)
231
    if (keySpec instanceof DSAPrivateKeySpec)
260
      result = decodeDSSPrivateKey((DSAPrivateKeySpec) keySpec);
232
      result = decodeDSSPrivateKey((DSAPrivateKeySpec) keySpec);
Lines 281-287 Link Here
281
              log.log(Level.FINE, "Exception in DSSPrivateKey.valueOf(). Ignore",
253
              log.log(Level.FINE, "Exception in DSSPrivateKey.valueOf(). Ignore",
282
                      ignored);
254
                      ignored);
283
          }
255
          }
284
285
        if (! ok) // try RSA
256
        if (! ok) // try RSA
286
          try
257
          try
287
            {
258
            {
Lines 295-301 Link Here
295
                        "Exception in GnuRSAPrivateKey.valueOf(). Ignore",
266
                        "Exception in GnuRSAPrivateKey.valueOf(). Ignore",
296
                        ignored);
267
                        ignored);
297
            }
268
            }
298
299
        if (! ok) // try DH
269
        if (! ok) // try DH
300
          result = decodeDHPrivateKey(input);
270
          result = decodeDHPrivateKey(input);
301
      }
271
      }
Lines 328-334 Link Here
328
  /**
298
  /**
329
   * @param spec an instance of {@link DSAPublicKeySpec} to decode.
299
   * @param spec an instance of {@link DSAPublicKeySpec} to decode.
330
   * @return an instance of {@link DSSPublicKey} constructed from the
300
   * @return an instance of {@link DSSPublicKey} constructed from the
331
   * information in the designated key-specification.
301
   *         information in the designated key-specification.
332
   */
302
   */
333
  private DSSPublicKey decodeDSSPublicKey(DSAPublicKeySpec spec)
303
  private DSSPublicKey decodeDSSPublicKey(DSAPublicKeySpec spec)
334
  {
304
  {
Lines 342-348 Link Here
342
  /**
312
  /**
343
   * @param spec an instance of {@link RSAPublicKeySpec} to decode.
313
   * @param spec an instance of {@link RSAPublicKeySpec} to decode.
344
   * @return an instance of {@link GnuRSAPublicKey} constructed from the
314
   * @return an instance of {@link GnuRSAPublicKey} constructed from the
345
   * information in the designated key-specification.
315
   *         information in the designated key-specification.
346
   */
316
   */
347
  private GnuRSAPublicKey decodeRSAPublicKey(RSAPublicKeySpec spec)
317
  private GnuRSAPublicKey decodeRSAPublicKey(RSAPublicKeySpec spec)
348
  {
318
  {
Lines 391-397 Link Here
391
  /**
361
  /**
392
   * @param spec an instance of {@link DSAPrivateKeySpec} to decode.
362
   * @param spec an instance of {@link DSAPrivateKeySpec} to decode.
393
   * @return an instance of {@link DSSPrivateKey} constructed from the
363
   * @return an instance of {@link DSSPrivateKey} constructed from the
394
   * information in the designated key-specification. 
364
   *         information in the designated key-specification.
395
   */
365
   */
396
  private PrivateKey decodeDSSPrivateKey(DSAPrivateKeySpec spec)
366
  private PrivateKey decodeDSSPrivateKey(DSAPrivateKeySpec spec)
397
  {
367
  {
Lines 405-411 Link Here
405
  /**
375
  /**
406
   * @param spec an instance of {@link RSAPrivateCrtKeySpec} to decode.
376
   * @param spec an instance of {@link RSAPrivateCrtKeySpec} to decode.
407
   * @return an instance of {@link GnuRSAPrivateKey} constructed from the
377
   * @return an instance of {@link GnuRSAPrivateKey} constructed from the
408
   * information in the designated key-specification.
378
   *         information in the designated key-specification.
409
   */
379
   */
410
  private PrivateKey decodeRSAPrivateKey(RSAPrivateCrtKeySpec spec)
380
  private PrivateKey decodeRSAPrivateKey(RSAPrivateCrtKeySpec spec)
411
  {
381
  {
(-)sig/KeyPairGeneratorAdapter.java (-28 / +16 lines)
Lines 49-84 Link Here
49
49
50
/**
50
/**
51
 * The implementation of a generic {@link java.security.KeyPairGenerator}
51
 * The implementation of a generic {@link java.security.KeyPairGenerator}
52
 * adapter class to wrap gnu.crypto keypair generator instances.<p>
52
 * adapter class to wrap GNU keypair generator instances.
53
 *
53
 * <p>
54
 * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) for the
54
 * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) for
55
 * {@link java.security.KeyPairGenerator} class, which is used to generate pairs
55
 * the {@link java.security.KeyPairGenerator} class, which is used to generate
56
 * of public and private keys.<p>
56
 * pairs of public and private keys.
57
 *
57
 * <p>
58
 * All the abstract methods in the {@link java.security.KeyPairGeneratorSpi}
58
 * All the abstract methods in the {@link java.security.KeyPairGeneratorSpi}
59
 * class are implemented by this class and all its sub-classes.<p>
59
 * class are implemented by this class and all its sub-classes.
60
 *
60
 * <p>
61
 * In case the client does not explicitly initialize the KeyPairGenerator (via
61
 * In case the client does not explicitly initialize the KeyPairGenerator (via a
62
 * a call to an <code>initialize()</code> method), the GNU Crypto provider
62
 * call to an <code>initialize()</code> method), the GNU provider supplies
63
 * supplies (and document) default values to be used. For example, the GNU
63
 * (and document) default values to be used. For example, the GNU provider uses
64
 * Crypto provider uses a default <i>modulus</i> size (keysize) of 1024 bits for
64
 * a default <i>modulus</i> size (keysize) of 1024 bits for the DSS (Digital
65
 * the DSS (Digital Signature Standard) a.k.a <i>DSA</i>.<p>
65
 * Signature Standard) a.k.a <i>DSA</i>.
66
 */
66
 */
67
public abstract class KeyPairGeneratorAdapter extends KeyPairGenerator
67
public abstract class KeyPairGeneratorAdapter
68
    extends KeyPairGenerator
68
{
69
{
69
70
  // Constants and variables
71
  // -------------------------------------------------------------------------
72
73
  /** Our underlying keypair instance. */
70
  /** Our underlying keypair instance. */
74
  protected IKeyPairGenerator adaptee;
71
  protected IKeyPairGenerator adaptee;
75
72
76
  // Constructor(s)
77
  // -------------------------------------------------------------------------
78
79
  /**
73
  /**
80
   * Trivial protected constructor.
74
   * Trivial protected constructor.
81
   *
75
   * 
82
   * @param kpgName the canonical name of the keypair generator algorithm.
76
   * @param kpgName the canonical name of the keypair generator algorithm.
83
   */
77
   */
84
  protected KeyPairGeneratorAdapter(String kpgName)
78
  protected KeyPairGeneratorAdapter(String kpgName)
Lines 88-99 Link Here
88
    this.adaptee = KeyPairGeneratorFactory.getInstance(kpgName);
82
    this.adaptee = KeyPairGeneratorFactory.getInstance(kpgName);
89
  }
83
  }
90
84
91
  // Class methods
92
  // -------------------------------------------------------------------------
93
94
  // java.security.KeyPairGeneratorSpi interface implementation
95
  // -------------------------------------------------------------------------
96
97
  public abstract void initialize(int keysize, SecureRandom random);
85
  public abstract void initialize(int keysize, SecureRandom random);
98
86
99
  public abstract void initialize(AlgorithmParameterSpec params,
87
  public abstract void initialize(AlgorithmParameterSpec params,
(-)sig/RSAKeyFactory.java (-42 / +8 lines)
Lines 76-82 Link Here
76
        BigInteger e = spec.getPublicExponent();
76
        BigInteger e = spec.getPublicExponent();
77
        return new GnuRSAPublicKey(Registry.X509_ENCODING_ID, n, e);
77
        return new GnuRSAPublicKey(Registry.X509_ENCODING_ID, n, e);
78
      }
78
      }
79
80
    if (keySpec instanceof X509EncodedKeySpec)
79
    if (keySpec instanceof X509EncodedKeySpec)
81
      {
80
      {
82
        X509EncodedKeySpec spec = (X509EncodedKeySpec) keySpec;
81
        X509EncodedKeySpec spec = (X509EncodedKeySpec) keySpec;
Lines 88-99 Link Here
88
          }
87
          }
89
        catch (RuntimeException x)
88
        catch (RuntimeException x)
90
          {
89
          {
91
            InvalidKeySpecException y = new InvalidKeySpecException();
90
            throw new InvalidKeySpecException(x.getMessage(), x);
92
            y.initCause(x);
93
            throw y;
94
          }
91
          }
95
      }
92
      }
96
97
    throw new InvalidKeySpecException("Unsupported (public) key specification");
93
    throw new InvalidKeySpecException("Unsupported (public) key specification");
98
  }
94
  }
99
95
Lines 114-129 Link Here
114
        return new GnuRSAPrivateKey(Registry.PKCS8_ENCODING_ID,
110
        return new GnuRSAPrivateKey(Registry.PKCS8_ENCODING_ID,
115
                                    n, e, d, p, q, dP, dQ, qInv);
111
                                    n, e, d, p, q, dP, dQ, qInv);
116
      }
112
      }
117
118
//    if (keySpec instanceof RSAPrivateKeySpec)
119
//      {
120
//        RSAPrivateKeySpec spec = (RSAPrivateKeySpec) keySpec;
121
//        BigInteger n = spec.getModulus();
122
//        BigInteger d = spec.getPrivateExponent();
123
//        return new GnuRSAPrivateKey(Registry.PKCS8_ENCODING_ID,
124
//                                    n, null, d, null, null, null, null, null);
125
//      }
126
127
    if (keySpec instanceof PKCS8EncodedKeySpec)
113
    if (keySpec instanceof PKCS8EncodedKeySpec)
128
      {
114
      {
129
        PKCS8EncodedKeySpec spec = (PKCS8EncodedKeySpec) keySpec;
115
        PKCS8EncodedKeySpec spec = (PKCS8EncodedKeySpec) keySpec;
Lines 135-146 Link Here
135
          }
121
          }
136
        catch (RuntimeException x)
122
        catch (RuntimeException x)
137
          {
123
          {
138
            InvalidKeySpecException y = new InvalidKeySpecException();
124
            throw new InvalidKeySpecException(x.getMessage(), x);
139
            y.initCause(x);
140
            throw y;
141
          }
125
          }
142
      }
126
      }
143
144
    throw new InvalidKeySpecException("Unsupported (private) key specification");
127
    throw new InvalidKeySpecException("Unsupported (private) key specification");
145
  }
128
  }
146
129
Lines 156-162 Link Here
156
          BigInteger e = rsaKey.getPublicExponent();
139
          BigInteger e = rsaKey.getPublicExponent();
157
          return new RSAPublicKeySpec(n, e);
140
          return new RSAPublicKeySpec(n, e);
158
        }
141
        }
159
160
        if (keySpec.isAssignableFrom(X509EncodedKeySpec.class))
142
        if (keySpec.isAssignableFrom(X509EncodedKeySpec.class))
161
          {
143
          {
162
            if (key instanceof GnuRSAPublicKey)
144
            if (key instanceof GnuRSAPublicKey)
Lines 171-183 Link Here
171
                byte[] encoded = key.getEncoded();
153
                byte[] encoded = key.getEncoded();
172
                return new X509EncodedKeySpec(encoded);
154
                return new X509EncodedKeySpec(encoded);
173
              }
155
              }
174
156
            throw new InvalidKeySpecException(
175
            throw new InvalidKeySpecException("Wrong key type or unsupported (public) key specification");
157
                "Wrong key type or unsupported (public) key specification");
176
          }
158
          }
177
178
        throw new InvalidKeySpecException("Unsupported (public) key specification");
159
        throw new InvalidKeySpecException("Unsupported (public) key specification");
179
      }
160
      }
180
181
    if ((key instanceof RSAPrivateCrtKey)
161
    if ((key instanceof RSAPrivateCrtKey)
182
        && keySpec.isAssignableFrom(RSAPrivateCrtKeySpec.class))
162
        && keySpec.isAssignableFrom(RSAPrivateCrtKeySpec.class))
183
      {
163
      {
Lines 192-198 Link Here
192
        BigInteger qInv = rsaKey.getCrtCoefficient();
172
        BigInteger qInv = rsaKey.getCrtCoefficient();
193
        return new RSAPrivateCrtKeySpec(n, e, d, p, q, dP, dQ, qInv);
173
        return new RSAPrivateCrtKeySpec(n, e, d, p, q, dP, dQ, qInv);
194
      }
174
      }
195
196
    if ((key instanceof RSAPrivateKey)
175
    if ((key instanceof RSAPrivateKey)
197
        && keySpec.isAssignableFrom(RSAPrivateKeySpec.class))
176
        && keySpec.isAssignableFrom(RSAPrivateKeySpec.class))
198
      {
177
      {
Lines 201-207 Link Here
201
        BigInteger d = rsaKey.getPrivateExponent();
180
        BigInteger d = rsaKey.getPrivateExponent();
202
        return new RSAPrivateKeySpec(n, d);
181
        return new RSAPrivateKeySpec(n, d);
203
      }
182
      }
204
205
    if (keySpec.isAssignableFrom(PKCS8EncodedKeySpec.class))
183
    if (keySpec.isAssignableFrom(PKCS8EncodedKeySpec.class))
206
      {
184
      {
207
        if (key instanceof GnuRSAPrivateKey)
185
        if (key instanceof GnuRSAPrivateKey)
Lines 210-226 Link Here
210
            byte[] encoded = rsaKey.getEncoded(Registry.PKCS8_ENCODING_ID);
188
            byte[] encoded = rsaKey.getEncoded(Registry.PKCS8_ENCODING_ID);
211
            return new PKCS8EncodedKeySpec(encoded);
189
            return new PKCS8EncodedKeySpec(encoded);
212
          }
190
          }
213
214
        if (Registry.PKCS8_ENCODING_SHORT_NAME.equalsIgnoreCase(key.getFormat()))
191
        if (Registry.PKCS8_ENCODING_SHORT_NAME.equalsIgnoreCase(key.getFormat()))
215
          {
192
          {
216
            byte[] encoded = key.getEncoded();
193
            byte[] encoded = key.getEncoded();
217
            return new PKCS8EncodedKeySpec(encoded);
194
            return new PKCS8EncodedKeySpec(encoded);
218
          }
195
          }
219
196
        throw new InvalidKeySpecException(
220
        throw new InvalidKeySpecException("Wrong key type or unsupported (private) key specification");
197
            "Wrong key type or unsupported (private) key specification");
221
      }
198
      }
222
199
    throw new InvalidKeySpecException(
223
    throw new InvalidKeySpecException("Wrong key type or unsupported key specification");
200
        "Wrong key type or unsupported key specification");
224
  }
201
  }
225
202
226
  protected Key engineTranslateKey(Key key) throws InvalidKeyException
203
  protected Key engineTranslateKey(Key key) throws InvalidKeyException
Lines 235-241 Link Here
235
        BigInteger e = rsaKey.getPublicExponent();
212
        BigInteger e = rsaKey.getPublicExponent();
236
        return new GnuRSAPublicKey(Registry.X509_ENCODING_ID, n, e);
213
        return new GnuRSAPublicKey(Registry.X509_ENCODING_ID, n, e);
237
      }
214
      }
238
239
    if (key instanceof RSAPrivateCrtKey)
215
    if (key instanceof RSAPrivateCrtKey)
240
      {
216
      {
241
        RSAPrivateCrtKey rsaKey = (RSAPrivateCrtKey) key;
217
        RSAPrivateCrtKey rsaKey = (RSAPrivateCrtKey) key;
Lines 250-265 Link Here
250
        return new GnuRSAPrivateKey(Registry.PKCS8_ENCODING_ID,
226
        return new GnuRSAPrivateKey(Registry.PKCS8_ENCODING_ID,
251
                                    n, e, d, p, q, dP, dQ, qInv);
227
                                    n, e, d, p, q, dP, dQ, qInv);
252
      }
228
      }
253
254
//    if (key instanceof RSAPrivateKey)
255
//      {
256
//        RSAPrivateKey rsaKey = (RSAPrivateKey) key;
257
//        BigInteger n = rsaKey.getModulus();
258
//        BigInteger d = rsaKey.getPrivateExponent();
259
//        return new GnuRSAPrivateKey(Registry.PKCS8_ENCODING_ID,
260
//                                    n, null, d, null, null, null, null, null);
261
//      }
262
263
    throw new InvalidKeyException("Unsupported key type");
229
    throw new InvalidKeyException("Unsupported key type");
264
  }
230
  }
265
}
231
}
(-)sig/RSAKeyPairGeneratorSpi.java (-30 / +11 lines)
Lines 49-88 Link Here
49
49
50
/**
50
/**
51
 * The implementation of a {@link java.security.KeyPairGenerator} adapter class
51
 * The implementation of a {@link java.security.KeyPairGenerator} adapter class
52
 * to wrap gnu.crypto RSA keypair generator instances.<p>
52
 * to wrap GNU RSA keypair generator instances.
53
 *
53
 * <p>
54
 * In case the client does not explicitly initialize the KeyPairGenerator (via
54
 * In case the client does not explicitly initialize the KeyPairGenerator (via a
55
 * a call to an <code>initialize()</code> method), the GNU Crypto provider
55
 * call to an <code>initialize()</code> method), the GNU provider uses a
56
 * uses a default <i>modulus</i> size (keysize) of 1024 bits.<p>
56
 * default <i>modulus</i> size (keysize) of 1024 bits.
57
 */
57
 */
58
public class RSAKeyPairGeneratorSpi extends KeyPairGeneratorAdapter
58
public class RSAKeyPairGeneratorSpi
59
    extends KeyPairGeneratorAdapter
59
{
60
{
60
61
  // Constants and variables
62
  // -------------------------------------------------------------------------
63
64
  // Constructor(s)
65
  // -------------------------------------------------------------------------
66
67
  public RSAKeyPairGeneratorSpi()
61
  public RSAKeyPairGeneratorSpi()
68
  {
62
  {
69
    super(Registry.RSA_KPG);
63
    super(Registry.RSA_KPG);
70
  }
64
  }
71
65
72
  // Class methods
73
  // -------------------------------------------------------------------------
74
75
  // Instance methods
76
  // -------------------------------------------------------------------------
77
78
  public void initialize(int keysize, SecureRandom random)
66
  public void initialize(int keysize, SecureRandom random)
79
  {
67
  {
80
    HashMap attributes = new HashMap();
68
    HashMap attributes = new HashMap();
81
    attributes.put(RSAKeyPairGenerator.MODULUS_LENGTH, Integer.valueOf(keysize));
69
    attributes.put(RSAKeyPairGenerator.MODULUS_LENGTH, Integer.valueOf(keysize));
82
    if (random != null)
70
    if (random != null)
83
      {
71
      attributes.put(RSAKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);
84
        attributes.put(RSAKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);
85
      }
86
72
87
    attributes.put(RSAKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
73
    attributes.put(RSAKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
88
                   Integer.valueOf(Registry.ASN1_ENCODING_ID));
74
                   Integer.valueOf(Registry.ASN1_ENCODING_ID));
Lines 95-112 Link Here
95
    HashMap attributes = new HashMap();
81
    HashMap attributes = new HashMap();
96
    if (params != null)
82
    if (params != null)
97
      {
83
      {
98
        if (!(params instanceof RSAKeyGenParameterSpec))
84
        if (! (params instanceof RSAKeyGenParameterSpec))
99
          {
85
          throw new InvalidAlgorithmParameterException("params");
100
            throw new InvalidAlgorithmParameterException("params");
101
          }
102
86
103
        attributes.put(RSAKeyPairGenerator.RSA_PARAMETERS, params);
87
        attributes.put(RSAKeyPairGenerator.RSA_PARAMETERS, params);
104
      }
88
      }
105
106
    if (random != null)
89
    if (random != null)
107
      {
90
      attributes.put(RSAKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);
108
        attributes.put(RSAKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);
109
      }
110
91
111
    attributes.put(RSAKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
92
    attributes.put(RSAKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
112
                   Integer.valueOf(Registry.ASN1_ENCODING_ID));
93
                   Integer.valueOf(Registry.ASN1_ENCODING_ID));
(-)sig/RSAPSSRawSignatureSpi.java (-16 / +5 lines)
Lines 42-67 Link Here
42
import gnu.java.security.sig.rsa.RSAPSSSignatureRawCodec;
42
import gnu.java.security.sig.rsa.RSAPSSSignatureRawCodec;
43
43
44
/**
44
/**
45
 * The implementation of <i>Service Provider Interface</i> (<b>SPI</b>) adapter
45
 * The implementation of <i>Service Provider Interface</i> (<b>SPI</b>)
46
 * for the RSA-PSS signature scheme, encoded and/or decoded in RAW format.<p>
46
 * adapter for the RSA-PSS signature scheme, encoded and/or decoded in RAW
47
 * format.
47
 */
48
 */
48
public class RSAPSSRawSignatureSpi extends SignatureAdapter
49
public class RSAPSSRawSignatureSpi
50
    extends SignatureAdapter
49
{
51
{
50
51
  // Constants and variables
52
  // -------------------------------------------------------------------------
53
54
  // Constructor(s)
55
  // -------------------------------------------------------------------------
56
57
  public RSAPSSRawSignatureSpi()
52
  public RSAPSSRawSignatureSpi()
58
  {
53
  {
59
    super(Registry.RSA_PSS_SIG, new RSAPSSSignatureRawCodec());
54
    super(Registry.RSA_PSS_SIG, new RSAPSSSignatureRawCodec());
60
  }
55
  }
61
62
  // Class methods
63
  // -------------------------------------------------------------------------
64
65
  // Instance methods
66
  // -------------------------------------------------------------------------
67
}
56
}
(-)sig/SignatureAdapter.java (-41 / +28 lines)
Lines 58-95 Link Here
58
58
59
/**
59
/**
60
 * The implementation of a generic {@link java.security.Signature} adapter class
60
 * The implementation of a generic {@link java.security.Signature} adapter class
61
 * to wrap gnu.crypto signature instances.<p>
61
 * to wrap GNU signature instances.
62
 *
62
 * <p>
63
 * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) for the
63
 * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) for
64
 * {@link java.security.Signature} class, which provides the functionality of a
64
 * the {@link java.security.Signature} class, which provides the functionality
65
 * digital signature algorithm. Digital signatures are used for authentication
65
 * of a digital signature algorithm. Digital signatures are used for
66
 * and integrity assurance of digital data.<p>
66
 * authentication and integrity assurance of digital data.
67
 *
67
 * <p>
68
 * All the abstract methods in the {@link java.security.SignatureSpi} class are
68
 * All the abstract methods in the {@link SignatureSpi} class are implemented by
69
 * implemented by this class and all its sub-classes.<p>
69
 * this class and all its sub-classes.
70
 *
70
 * <p>
71
 * All the implementations which subclass this object, and which are serviced by
71
 * All the implementations which subclass this object, and which are serviced by
72
 * the GNU Crypto provider implement the {@link java.lang.Cloneable} interface.<p>
72
 * the GNU provider implement the {@link Cloneable} interface.
73
 */
73
 */
74
class SignatureAdapter extends SignatureSpi implements Cloneable
74
class SignatureAdapter
75
    extends SignatureSpi
76
    implements Cloneable
75
{
77
{
76
  private static final Logger log = Logger.getLogger(SignatureAdapter.class.getName());
78
  private static final Logger log = Logger.getLogger(SignatureAdapter.class.getName());
77
79
78
  // Constants and variables
79
  // -------------------------------------------------------------------------
80
81
  /** Our underlying signature instance. */
80
  /** Our underlying signature instance. */
82
  private ISignature adaptee;
81
  private ISignature adaptee;
83
82
84
  /** Our underlying signature encoder/decoder engine. */
83
  /** Our underlying signature encoder/decoder engine. */
85
  private ISignatureCodec codec;
84
  private ISignatureCodec codec;
86
85
87
  // Constructor(s)
88
  // -------------------------------------------------------------------------
89
90
  /**
86
  /**
91
   * Trivial protected constructor.<p>
87
   * Trivial protected constructor.
92
   *
88
   * 
93
   * @param sigName the canonical name of the signature scheme.
89
   * @param sigName the canonical name of the signature scheme.
94
   * @param codec the signature codec engine to use with this scheme.
90
   * @param codec the signature codec engine to use with this scheme.
95
   */
91
   */
Lines 99-106 Link Here
99
  }
95
  }
100
96
101
  /**
97
  /**
102
   * Private constructor for cloning purposes.<p>
98
   * Private constructor for cloning purposes.
103
   *
99
   * 
104
   * @param adaptee a clone of the underlying signature scheme instance.
100
   * @param adaptee a clone of the underlying signature scheme instance.
105
   * @param codec the signature codec engine to use with this scheme.
101
   * @param codec the signature codec engine to use with this scheme.
106
   */
102
   */
Lines 112-123 Link Here
112
    this.codec = codec;
108
    this.codec = codec;
113
  }
109
  }
114
110
115
  // Class methods
116
  // -------------------------------------------------------------------------
117
118
  // java.security.SignatureSpi interface implementation
119
  // -------------------------------------------------------------------------
120
121
  public Object clone()
111
  public Object clone()
122
  {
112
  {
123
    return new SignatureAdapter((ISignature) adaptee.clone(), codec);
113
    return new SignatureAdapter((ISignature) adaptee.clone(), codec);
Lines 133-139 Link Here
133
      }
123
      }
134
    catch (IllegalArgumentException x)
124
    catch (IllegalArgumentException x)
135
      {
125
      {
136
        throw new InvalidKeyException(String.valueOf(x));
126
        throw new InvalidKeyException(x.getMessage(), x);
137
      }
127
      }
138
  }
128
  }
139
129
Lines 147-153 Link Here
147
      }
137
      }
148
    catch (IllegalArgumentException x)
138
    catch (IllegalArgumentException x)
149
      {
139
      {
150
        throw new InvalidKeyException(String.valueOf(x));
140
        throw new InvalidKeyException(x.getMessage(), x);
151
      }
141
      }
152
  }
142
  }
153
143
Lines 163-169 Link Here
163
      }
153
      }
164
    catch (IllegalArgumentException x)
154
    catch (IllegalArgumentException x)
165
      {
155
      {
166
        throw new InvalidKeyException(String.valueOf(x));
156
        throw new InvalidKeyException(x.getMessage(), x);
167
      }
157
      }
168
  }
158
  }
169
159
Lines 175-181 Link Here
175
      }
165
      }
176
    catch (IllegalStateException x)
166
    catch (IllegalStateException x)
177
      {
167
      {
178
        throw new SignatureException(String.valueOf(x));
168
        throw new SignatureException(x.getMessage(), x);
179
      }
169
      }
180
  }
170
  }
181
171
Lines 188-194 Link Here
188
      }
178
      }
189
    catch (IllegalStateException x)
179
    catch (IllegalStateException x)
190
      {
180
      {
191
        throw new SignatureException(String.valueOf(x));
181
        throw new SignatureException(x.getMessage(), x);
192
      }
182
      }
193
  }
183
  }
194
184
Lines 201-209 Link Here
201
      }
191
      }
202
    catch (IllegalStateException x)
192
    catch (IllegalStateException x)
203
      {
193
      {
204
        throw new SignatureException(String.valueOf(x));
194
        throw new SignatureException(x.getMessage(), x);
205
      }
195
      }
206
207
    byte[] result = codec.encodeSignature(signature);
196
    byte[] result = codec.encodeSignature(signature);
208
    return result;
197
    return result;
209
  }
198
  }
Lines 214-222 Link Here
214
    byte[] signature = this.engineSign();
203
    byte[] signature = this.engineSign();
215
    int result = signature.length;
204
    int result = signature.length;
216
    if (result > len)
205
    if (result > len)
217
      {
206
      throw new SignatureException("Not enough room to store signature");
218
        throw new SignatureException("len");
219
      }
220
207
221
    System.arraycopy(signature, 0, outbuf, offset, result);
208
    System.arraycopy(signature, 0, outbuf, offset, result);
222
    return result;
209
    return result;
Lines 226-232 Link Here
226
  {
213
  {
227
    if (Configuration.DEBUG)
214
    if (Configuration.DEBUG)
228
      log.entering(this.getClass().getName(), "engineVerify");
215
      log.entering(this.getClass().getName(), "engineVerify");
229
230
    Object signature = codec.decodeSignature(sigBytes);
216
    Object signature = codec.decodeSignature(sigBytes);
231
    boolean result = false;
217
    boolean result = false;
232
    try
218
    try
Lines 235-244 Link Here
235
      }
221
      }
236
    catch (IllegalStateException x)
222
    catch (IllegalStateException x)
237
      {
223
      {
238
        throw new SignatureException(String.valueOf(x));
224
        throw new SignatureException(x.getMessage(), x);
239
      }
225
      }
240
    if (Configuration.DEBUG)
226
    if (Configuration.DEBUG)
241
      log.exiting(this.getClass().getName(), "engineVerify", Boolean.valueOf(result));
227
      log.exiting(this.getClass().getName(), "engineVerify",
228
                  Boolean.valueOf(result));
242
    return result;
229
    return result;
243
  }
230
  }
244
231

Return to bug 26067