org.bouncycastle.crypto.signers
Class ISO9796d2PSSSigner

java.lang.Object
  extended by org.bouncycastle.crypto.signers.ISO9796d2PSSSigner
All Implemented Interfaces:
Signer, SignerWithRecovery

public class ISO9796d2PSSSigner
extends java.lang.Object
implements SignerWithRecovery

ISO9796-2 - mechanism using a hash function with recovery (scheme 2 and 3).

Note: the usual length for the salt is the length of the hash function used in bytes.


Field Summary
private  byte[] block
           
private  AsymmetricBlockCipher cipher
           
private  Digest digest
           
private  boolean fullMessage
           
private  int hLen
           
private  int keyBits
           
private  byte[] mBuf
           
private  int messageLength
           
private  java.security.SecureRandom random
           
private  byte[] recoveredMessage
           
private  int saltLength
           
private  byte[] standardSalt
           
private  int trailer
           
static int TRAILER_IMPLICIT
           
static int TRAILER_RIPEMD128
           
static int TRAILER_RIPEMD160
           
static int TRAILER_SHA1
           
 
Constructor Summary
ISO9796d2PSSSigner(AsymmetricBlockCipher cipher, Digest digest, int saltLength)
          Constructor for a signer with an explicit digest trailer.
ISO9796d2PSSSigner(AsymmetricBlockCipher cipher, Digest digest, int saltLength, boolean implicit)
          Generate a signer for the with either implicit or explicit trailers for ISO9796-2, scheme 2 or 3.
 
Method Summary
private  void clearBlock(byte[] block)
          clear possible sensitive data
 byte[] generateSignature()
          generate a signature for the loaded message using the key we were initialised with.
 byte[] getRecoveredMessage()
          Return a reference to the recoveredMessage message.
 boolean hasFullMessage()
          Return true if the full message was recoveredMessage.
 void init(boolean forSigning, CipherParameters param)
          Initialise the signer.
private  boolean isSameAs(byte[] a, byte[] b)
          compare two byte arrays.
private  void ItoOSP(int i, byte[] sp)
          int to octet string.
private  void LtoOSP(long l, byte[] sp)
          long to octet string.
private  byte[] maskGeneratorFunction1(byte[] Z, int zOff, int zLen, int length)
          mask generator function, as described in PKCS1v2.
 void reset()
          reset the internal state
 void update(byte b)
          update the internal digest with the byte b
 void update(byte[] in, int off, int len)
          update the internal digest with the byte array in
 boolean verifySignature(byte[] signature)
          return true if the signature represents a ISO9796-2 signature for the passed in message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRAILER_IMPLICIT

public static final int TRAILER_IMPLICIT
See Also:
Constant Field Values

TRAILER_RIPEMD160

public static final int TRAILER_RIPEMD160
See Also:
Constant Field Values

TRAILER_RIPEMD128

public static final int TRAILER_RIPEMD128
See Also:
Constant Field Values

TRAILER_SHA1

public static final int TRAILER_SHA1
See Also:
Constant Field Values

digest

private Digest digest

cipher

private AsymmetricBlockCipher cipher

random

private java.security.SecureRandom random

standardSalt

private byte[] standardSalt

hLen

private int hLen

trailer

private int trailer

keyBits

private int keyBits

block

private byte[] block

mBuf

private byte[] mBuf

messageLength

private int messageLength

saltLength

private int saltLength

fullMessage

private boolean fullMessage

recoveredMessage

private byte[] recoveredMessage
Constructor Detail

ISO9796d2PSSSigner

public ISO9796d2PSSSigner(AsymmetricBlockCipher cipher,
                          Digest digest,
                          int saltLength,
                          boolean implicit)
Generate a signer for the with either implicit or explicit trailers for ISO9796-2, scheme 2 or 3.

Parameters:
cipher - base cipher to use for signature creation/verification
digest - digest to use.
saltLength - length of salt in bytes.
implicit - whether or not the trailer is implicit or gives the hash.

ISO9796d2PSSSigner

public ISO9796d2PSSSigner(AsymmetricBlockCipher cipher,
                          Digest digest,
                          int saltLength)
Constructor for a signer with an explicit digest trailer.

Parameters:
cipher - cipher to use.
digest - digest to sign with.
saltLength - length of salt in bytes.
Method Detail

init

public void init(boolean forSigning,
                 CipherParameters param)
Initialise the signer.

Specified by:
init in interface Signer
Parameters:
forSigning - true if for signing, false if for verification.
param - parameters for signature generation/verification. If the parameters are for generation they should be a ParametersWithRandom, a ParametersWithSalt, or just an RSAKeyParameters object. If RSAKeyParameters are passed in a SecureRandom will be created.
Throws:
java.lang.IllegalArgumentException - if wrong parameter type or a fixed salt is passed in which is the wrong length.

isSameAs

private boolean isSameAs(byte[] a,
                         byte[] b)
compare two byte arrays.


clearBlock

private void clearBlock(byte[] block)
clear possible sensitive data


update

public void update(byte b)
update the internal digest with the byte b

Specified by:
update in interface Signer

update

public void update(byte[] in,
                   int off,
                   int len)
update the internal digest with the byte array in

Specified by:
update in interface Signer

reset

public void reset()
reset the internal state

Specified by:
reset in interface Signer

generateSignature

public byte[] generateSignature()
                         throws CryptoException
generate a signature for the loaded message using the key we were initialised with.

Specified by:
generateSignature in interface Signer
Throws:
CryptoException

verifySignature

public boolean verifySignature(byte[] signature)
return true if the signature represents a ISO9796-2 signature for the passed in message.

Specified by:
verifySignature in interface Signer

hasFullMessage

public boolean hasFullMessage()
Return true if the full message was recoveredMessage.

Specified by:
hasFullMessage in interface SignerWithRecovery
Returns:
true on full message recovery, false otherwise, or if not sure.
See Also:
SignerWithRecovery.hasFullMessage()

getRecoveredMessage

public byte[] getRecoveredMessage()
Return a reference to the recoveredMessage message.

Specified by:
getRecoveredMessage in interface SignerWithRecovery
Returns:
the full/partial recoveredMessage message.
See Also:
SignerWithRecovery.getRecoveredMessage()

ItoOSP

private void ItoOSP(int i,
                    byte[] sp)
int to octet string.


LtoOSP

private void LtoOSP(long l,
                    byte[] sp)
long to octet string.


maskGeneratorFunction1

private byte[] maskGeneratorFunction1(byte[] Z,
                                      int zOff,
                                      int zLen,
                                      int length)
mask generator function, as described in PKCS1v2.