IAIK ECC
version 2.18

iaik.security.ecc.ecdsa
Class ECDSASignature

java.lang.Object
  extended byjava.security.SignatureSpi
      extended byjava.security.Signature
          extended byiaik.security.ecc.ecdsa.ECDSASignature
Direct Known Subclasses:
RIPEMD160withECDSASignature, SHA224withECDSASignature, SHA256withECDSASignature, SHA384withECDSASignature, SHA512withECDSASignature, WHIRLPOOLwithECDSASignature

public class ECDSASignature
extends java.security.Signature

The signature class for the ECDSA algorithm. It is responsible for signature creation and verification. Use this class with the JCE/JCA framework.


Field Summary
protected  java.security.MessageDigest md_
          The message digest.
protected  ECPrivateKey privateKey_
          The private key, used for signing.
protected  ECPublicKey publicKey_
          The public key used for verification.
protected  java.security.SecureRandom secureRandom_
          Source of randomness.
 
Fields inherited from class java.security.Signature
SIGN, state, UNINITIALIZED, VERIFY
 
Fields inherited from class java.security.SignatureSpi
appRandom
 
Constructor Summary
ECDSASignature()
          Applications shouldn't use this constructor, but the Signature.getInstance("ECDSA") method.
 
Method Summary
protected  java.lang.Object engineGetParameter(java.lang.String param)
          Method not implemented.
protected  void engineInitSign(java.security.PrivateKey privateKey)
          Initializes the engine for signature creation.
protected  void engineInitSign(java.security.PrivateKey privateKey, java.security.SecureRandom random)
          Initializes the engine for signature creation.
protected  void engineInitVerify(java.security.PublicKey publicKey)
          Initializes the engine for signature verification.
protected  void engineSetParameter(java.security.spec.AlgorithmParameterSpec params)
          Method not implemented.
protected  void engineSetParameter(java.lang.String param, java.lang.Object value)
          Method not implemented.
protected  byte[] engineSign()
          Implements the sign algorithm according to the rules: k = random([1,n-1]) kP = (x1,y1) r = x1 mod n e = H(M) s = k1(e+dr) mod n Signature: (r,s)
protected  void engineUpdate(byte b)
          Updates the hash to be signed or verified.
protected  void engineUpdate(byte[] b, int off, int len)
          SPI: Updates the data to be signed or verified with the specified number of bytes, beginning at the specified offset within the given byte array.
protected  boolean engineVerify(byte[] sigBytes)
          Verifies a given signature according to the following rules: extract r and s from the given byte[] if r is not an integer in the interval [1, n-1] reject sig.
 
Methods inherited from class java.security.Signature
clone, getAlgorithm, getInstance, getInstance, getInstance, getParameter, getParameters, getProvider, initSign, initSign, initVerify, initVerify, setParameter, setParameter, sign, sign, toString, update, update, update, verify, verify
 
Methods inherited from class java.security.SignatureSpi
engineGetParameters, engineSign, engineVerify
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

md_

protected java.security.MessageDigest md_
The message digest.


privateKey_

protected ECPrivateKey privateKey_
The private key, used for signing.


publicKey_

protected ECPublicKey publicKey_
The public key used for verification.


secureRandom_

protected java.security.SecureRandom secureRandom_
Source of randomness.

Constructor Detail

ECDSASignature

public ECDSASignature()
               throws java.security.NoSuchAlgorithmException
Applications shouldn't use this constructor, but the Signature.getInstance("ECDSA") method.

Method Detail

engineGetParameter

protected java.lang.Object engineGetParameter(java.lang.String param)
                                       throws java.security.InvalidParameterException
Method not implemented. Just throws an InvalidParameterException.

Throws:
java.security.InvalidParameterException

engineInitSign

protected void engineInitSign(java.security.PrivateKey privateKey)
                       throws java.security.InvalidKeyException
Initializes the engine for signature creation.

Parameters:
privateKey - the ECDSA private key used for signing.
Throws:
java.security.InvalidKeyException - if a key encoding error occurs.

engineInitSign

protected void engineInitSign(java.security.PrivateKey privateKey,
                              java.security.SecureRandom random)
                       throws java.security.InvalidKeyException
Initializes the engine for signature creation.

Parameters:
privateKey - the ECDSA private key used for signing.
random - the source for randomness.
Throws:
java.security.InvalidKeyException - if a key encoding error occurs.

engineInitVerify

protected void engineInitVerify(java.security.PublicKey publicKey)
                         throws java.security.InvalidKeyException
Initializes the engine for signature verification.

Parameters:
publicKey - the ECDSA public key used for the signature verification.
Throws:
java.security.InvalidKeyException - if a key encoding error occurs.

engineSetParameter

protected void engineSetParameter(java.security.spec.AlgorithmParameterSpec params)
                           throws java.security.InvalidAlgorithmParameterException
Method not implemented. Just throws an InvalidAlgorithmParameterException.

Throws:
java.security.InvalidAlgorithmParameterException

engineSetParameter

protected void engineSetParameter(java.lang.String param,
                                  java.lang.Object value)
                           throws java.security.InvalidParameterException
Method not implemented. Just throws an InvalidParameterException.

Throws:
java.security.InvalidParameterException

engineSign

protected byte[] engineSign()
                     throws java.security.SignatureException
Implements the sign algorithm according to the rules:
  1. k = random([1,n-1])
  2. kP = (x1,y1)
  3. r = x1 mod n
  4. e = H(M)
  5. s = k1(e+dr) mod n
  6. Signature: (r,s)

Returns:
(r,s) as byte array
Throws:
java.security.SignatureException

engineUpdate

protected void engineUpdate(byte b)
Updates the hash to be signed or verified.

Parameters:
b - the "new" byte.

engineUpdate

protected void engineUpdate(byte[] b,
                            int off,
                            int len)
SPI: Updates the data to be signed or verified with the specified number of bytes, beginning at the specified offset within the given byte array.

Parameters:
b - the byte array holding the data to be used for this update operation.
off - the offset, indicating the start position within the given byte array.
len - the number of bytes to be obtained from the given byte array, starting at the given position.

engineVerify

protected boolean engineVerify(byte[] sigBytes)
                        throws java.security.SignatureException
Verifies a given signature according to the following rules:
  1. extract r and s from the given byte[]
  2. if r is not an integer in the interval [1, n-1] reject sig.
  3. if s is not an integer in the interval [1, n-1] reject sig.
  4. compute digest e = SHA-1(M)
  5. c = s^(-1) mod n
  6. u1 = e*c mod n
  7. u2 = r*c mod n
  8. (x1, y1) = u1*G + u2*Q
  9. if (x1, y1) is the point at infinity, then reject sig.
  10. convert x1 to integer x
  11. v = x mod n
  12. if r = v then accept sig.
  13. if r != v then reject sig.

Parameters:
sigBytes - the encoded r and s values of the signature.
Returns:
true if the signature is valid.
Throws:
java.security.SignatureException - if an error occurs when verifying the signature.

IAIK ECC
version 2.18

IAIK-ECC 2.18, (c) 2002 IAIK, (c) 2003 SIC