de.flexiprovider.pqc.ots.merkle
Class MerkleOTSSignature

java.lang.Object
  |
  +--java.security.SignatureSpi
        |
        +--de.flexiprovider.api.Signature
              |
              +--de.flexiprovider.pqc.ots.merkle.MerkleOTSSignature
Direct Known Subclasses:
MerkleOTSSignature.SHA1andSHA1PRNG, MerkleOTSSignature.SHA256andSHA1PRNG, MerkleOTSSignature.SHA384andSHA1PRNG, MerkleOTSSignature.SHA512andSHA1PRNG

public abstract class MerkleOTSSignature
extends Signature

This class implements the MerkleOTS (one-time signature scheme). First the message that should be signed, is hashed with a message digest. Then the hash value is concatenate with the value z. z is the quantity of zeros in the bit representation of the hash value of the message. For every bit that is 1 in the bit representation of the concatenation, the corresponding private key part of the OTSPrivateKey is set. For every 0-bit, the corresponding public key part of the MerkleOTSPublicKey is set. So the signature is a concatenation of parts of the private and public key.

Verification of a given signature only succeeds if the hash value of the signature is the MerkleOTSPublicKey.

The MerkleOTSSignature can be used like the following:

 Signature merkleSign = Signature.getInstance("MerkleOTSwithSHA256", "FlexiPQC");
 // create signature
 merkleSign.initSign(privateKey);
 merkleSign.update(data, 0, data.length);
 byte[] sign = merkleSign.sign();
 
 // verify signature
 merkleSign.initVerify(publicKey);
 merkleSign.update(data, 0, data.length);
 boolean verify = merkleSign.verify(sign);
 System.out.println(verify);
 

Author:
Elena Klintsevich

Inner Class Summary
static class MerkleOTSSignature.SHA1andSHA1PRNG
          Merkle OTS signature with SHA1 and SHA1PRNG.
static class MerkleOTSSignature.SHA256andSHA1PRNG
          Merkle OTS signature with SHA256 and SHA1PRNG.
static class MerkleOTSSignature.SHA384andSHA1PRNG
          Merkle OTS signature with SHA384 and SHA1PRNG.
static class MerkleOTSSignature.SHA512andSHA1PRNG
          Merkle OTS signature with SHA512 and SHA1PRNG.
 
Fields inherited from class java.security.SignatureSpi
appRandom
 
Constructor Summary
protected MerkleOTSSignature(java.lang.String oid, MessageDigest md)
          Constructor.
 
Method Summary
 void initSign(PrivateKey key, SecureRandom random)
          Initialize the signature algorithm for signing a message.
 void initVerify(PublicKey key)
          Initialize the signature algorithm for verifying a signature.
 void setParameters(AlgorithmParameterSpec params)
          Initialize this signature engine with the specified parameter set (not used).
 byte[] sign()
          Sign a message.
 void update(byte input)
          Feed a message byte to the message digest.
 void update(byte[] input, int inOff, int inLen)
          Feed an array of message bytes to the message digest.
 boolean verify(byte[] sigBytes)
          Verify a signature.
 
Methods inherited from class de.flexiprovider.api.Signature
engineGetParameter, engineInitSign, engineInitSign, engineInitVerify, engineSetParameter, engineSetParameter, engineSign, engineUpdate, engineUpdate, engineVerify, engineVerify, initSign, sign, update, verify, verify, verify
 
Methods inherited from class java.security.SignatureSpi
clone, engineSign
 
Methods inherited from class java.lang.Object
, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MerkleOTSSignature

protected MerkleOTSSignature(java.lang.String oid,
                             MessageDigest md)
Constructor.
Parameters:
oid - the OID of the algorithm
md - name of the message digest
Method Detail

initSign

public void initSign(PrivateKey key,
                     SecureRandom random)
              throws InvalidKeyException
Initialize the signature algorithm for signing a message.
Overrides:
initSign in class Signature
Parameters:
key - the private key of the signer
random - a source of randomness (not used)
Throws:
InvalidKeyException - if the key is not an instance of OTSPrivateKey.

initVerify

public void initVerify(PublicKey key)
                throws InvalidKeyException
Initialize the signature algorithm for verifying a signature.
Overrides:
initVerify in class Signature
Parameters:
key - the public key of the signer.
Throws:
InvalidKeyException - if the public key is not an instance of MerkleOTSPublicKey.

setParameters

public void setParameters(AlgorithmParameterSpec params)
Initialize this signature engine with the specified parameter set (not used).
Overrides:
setParameters in class Signature
Parameters:
params - the parameters (not used)

update

public void update(byte input)
Feed a message byte to the message digest.
Overrides:
update in class Signature
Parameters:
input - the message byte

update

public void update(byte[] input,
                   int inOff,
                   int inLen)
Feed an array of message bytes to the message digest.
Overrides:
update in class Signature
Parameters:
input - the array of message bytes
inOff - index of message start
inLen - number of message bytes

sign

public byte[] sign()
Sign a message.
Overrides:
sign in class Signature
Returns:
the signature.

verify

public boolean verify(byte[] sigBytes)
Verify a signature.
Overrides:
verify in class Signature
Parameters:
sigBytes - the signature to be verified.
Returns:
true if the signature is correct - false otherwise.