public byte[] generateSignature() throws CryptoException {
  int digSize=digest.getDigestSize();
  byte[] m2Hash=new byte[digSize];
  digest.doFinal(m2Hash,0);
  byte[] C=new byte[8];
  LtoOSP(messageLength * 8,C);
  digest.update(C,0,C.length);
  digest.update(mBuf,0,messageLength);
  digest.update(m2Hash,0,m2Hash.length);
  byte[] salt;
  if (standardSalt != null) {
    salt=standardSalt;
  }
 else {
    salt=new byte[saltLength];
    random.nextBytes(salt);
  }
  digest.update(salt,0,salt.length);
  byte[] hash=new byte[digest.getDigestSize()];
  digest.doFinal(hash,0);
  int tLength=2;
  if (trailer == TRAILER_IMPLICIT) {
    tLength=1;
  }
  int off=block.length - messageLength - salt.length- hLen- tLength- 1;
  block[off]=0x01;
  System.arraycopy(mBuf,0,block,off + 1,messageLength);
  System.arraycopy(salt,0,block,off + 1 + messageLength,salt.length);
  byte[] dbMask=maskGeneratorFunction1(hash,0,hash.length,block.length - hLen - tLength);
  for (int i=0; i != dbMask.length; i++) {
    block[i]^=dbMask[i];
  }
  System.arraycopy(hash,0,block,block.length - hLen - tLength,hLen);
  if (trailer == TRAILER_IMPLICIT) {
    block[block.length - 1]=(byte)TRAILER_IMPLICIT;
  }
 else {
    block[block.length - 2]=(byte)(trailer >>> 8);
    block[block.length - 1]=(byte)trailer;
  }
  block[0]&=0x7f;
  byte[] b=cipher.processBlock(block,0,block.length);
  clearBlock(mBuf);
  clearBlock(block);
  messageLength=0;
  return b;
}

public byte [ ] generateSignature ( ) throws CryptoException { int digSize = digest . getDigestSize ( ) ; byte [ ] m2Hash = new byte [ digSize ] ; digest . doFinal ( m2Hash , 0 ) ; byte [ ] C = new byte [ 8 ] ; LtoOSP ( messageLength * 8 , C ) ; digest . update ( C , 0 , C . length ) ; digest . update ( mBuf , 0 , messageLength ) ; digest . update ( m2Hash , 0 , m2Hash . length ) ; byte [ ] salt ; if ( standardSalt != null ) { salt = standardSalt ; } else { salt = new byte [ saltLength ] ; random . nextBytes ( salt ) ; } digest . update ( salt , 0 , salt . length ) ; byte [ ] hash = new byte [ digest . getDigestSize ( ) ] ; digest . doFinal ( hash , 0 ) ; int tLength = 2 ; if ( trailer == TRAILER_IMPLICIT ) { tLength = 1 ; } int off = block . length - messageLength - salt . length - hLen - tLength - 1 ; block [ off ] = 0x01 ; System . arraycopy ( mBuf , 0 , block , off + 1 , messageLength ) ; System . arraycopy ( salt , 0 , block , off + 1 + messageLength , salt . length ) ; byte [ ] dbMask = maskGeneratorFunction1 ( hash , 0 , hash . length , block . length - hLen - tLength ) ; for ( int i = 0 ; i != dbMask . length ; i ++ ) { block [ i ] ^= dbMask [ i ] ; } System . arraycopy ( hash , 0 , block , block . length - hLen - tLength , hLen ) ; if ( trailer == TRAILER_IMPLICIT ) { block [ block . length - 1 ] = ( byte ) TRAILER_IMPLICIT ; } else { block [ block . length - 2 ] = ( byte ) ( trailer > > > 8 ) ; block [ block . length - 1 ] = ( byte ) trailer ; } block [ 0 ] &= 0x7f ; byte [ ] b = cipher . processBlock ( block , 0 , block . length ) ; clearBlock ( mBuf ) ; clearBlock ( block ) ; messageLength = 0 ; return b ; }
generate a signature for the loaded message using the key we were initialised with .
