diff options
author | Sergio Giro <sgiro@google.com> | 2016-02-01 18:54:35 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2016-02-01 18:54:35 +0000 |
commit | 3e75bd6b407dd472c834a50f16aae54cca67ea9c (patch) | |
tree | b5eb091b97b2aade28e5b45a15352125a4a776d7 /bcprov/src/main/java/org/bouncycastle/pqc/crypto/DigestingMessageSigner.java | |
parent | 9218edabd1ef9852bc2f13115dcadc81b442dd6c (diff) | |
parent | c1040cb5656c3299f1c2d0fe0bd7c44b10466aaf (diff) | |
download | android_external_bouncycastle-3e75bd6b407dd472c834a50f16aae54cca67ea9c.tar.gz android_external_bouncycastle-3e75bd6b407dd472c834a50f16aae54cca67ea9c.tar.bz2 android_external_bouncycastle-3e75bd6b407dd472c834a50f16aae54cca67ea9c.zip |
Merge "Restoring the contents of aosp after"
Diffstat (limited to 'bcprov/src/main/java/org/bouncycastle/pqc/crypto/DigestingMessageSigner.java')
-rw-r--r-- | bcprov/src/main/java/org/bouncycastle/pqc/crypto/DigestingMessageSigner.java | 117 |
1 files changed, 0 insertions, 117 deletions
diff --git a/bcprov/src/main/java/org/bouncycastle/pqc/crypto/DigestingMessageSigner.java b/bcprov/src/main/java/org/bouncycastle/pqc/crypto/DigestingMessageSigner.java deleted file mode 100644 index 6b5b251..0000000 --- a/bcprov/src/main/java/org/bouncycastle/pqc/crypto/DigestingMessageSigner.java +++ /dev/null @@ -1,117 +0,0 @@ -package org.bouncycastle.pqc.crypto; - -import org.bouncycastle.crypto.CipherParameters; -import org.bouncycastle.crypto.Digest; -import org.bouncycastle.crypto.Signer; -import org.bouncycastle.crypto.params.AsymmetricKeyParameter; -import org.bouncycastle.crypto.params.ParametersWithRandom; - - -/** - * Implements the sign and verify functions for a Signature Scheme which can use a hash function. - */ -public class DigestingMessageSigner - implements Signer -{ - private final Digest messDigest; - private final MessageSigner messSigner; - private boolean forSigning; - - public DigestingMessageSigner(MessageSigner messSigner, Digest messDigest) - { - this.messSigner = messSigner; - this.messDigest = messDigest; - } - - public void init(boolean forSigning, - CipherParameters param) - { - - this.forSigning = forSigning; - AsymmetricKeyParameter k; - - if (param instanceof ParametersWithRandom) - { - k = (AsymmetricKeyParameter)((ParametersWithRandom)param).getParameters(); - } - else - { - k = (AsymmetricKeyParameter)param; - } - - if (forSigning && !k.isPrivate()) - { - throw new IllegalArgumentException("Signing Requires Private Key."); - } - - if (!forSigning && k.isPrivate()) - { - throw new IllegalArgumentException("Verification Requires Public Key."); - } - - reset(); - - messSigner.init(forSigning, param); - } - - - /** - * This function signs the message that has been updated, making use of the - * private key. - * - * @return the signature of the message. - */ - public byte[] generateSignature() - { - if (!forSigning) - { - throw new IllegalStateException("RainbowDigestSigner not initialised for signature generation."); - } - - byte[] hash = new byte[messDigest.getDigestSize()]; - messDigest.doFinal(hash, 0); - - return messSigner.generateSignature(hash); - } - - /** - * This function verifies the signature of the message that has been - * updated, with the aid of the public key. - * - * @param signature the signature of the message is given as a byte array. - * @return true if the signature has been verified, false otherwise. - */ - public boolean verify(byte[] signature) - { - if (forSigning) - { - throw new IllegalStateException("RainbowDigestSigner not initialised for verification"); - } - - byte[] hash = new byte[messDigest.getDigestSize()]; - messDigest.doFinal(hash, 0); - - return messSigner.verifySignature(hash, signature); - - } - - public void update(byte b) - { - messDigest.update(b); - } - - public void update(byte[] in, int off, int len) - { - messDigest.update(in, off, len); - } - - public void reset() - { - messDigest.reset(); - } - - public boolean verifySignature(byte[] signature) - { - return this.verify(signature); - } -} |