Search in sources :

Example 1 with Signer

use of org.spongycastle.crypto.Signer in project universa by UniversaBlockchain.

the class RSAOAEPPublicKey method checkSignature.

/**
 * {@inheritDoc}
 */
@NonNull
@Override
public boolean checkSignature(InputStream input, byte[] signature, HashType hashType, int saltLength) throws IllegalStateException, IOException {
    if (state == null) {
        throw new IllegalStateException();
    } else {
        final Digest primaryDigest = hashType.makeDigest();
        if (saltLength == MAX_SALT_LENGTH) {
            saltLength = getMaxSaltLength(getBitStrength(), primaryDigest.getDigestSize());
        }
        if (saltLength < 0) {
            throw new RuntimeException(String.format("Incorrect salt length %s", saltLength));
        }
        final Signer signatureChecker = new PSSSigner(RSAEngineFactory.make(), primaryDigest, state.mgf1HashType.makeDigest(), saltLength);
        signatureChecker.init(false, new ParametersWithRandom(state.keyParameters, state.rng));
        boolean done = false;
        while (!done) {
            int availableBytes = input.available();
            if (availableBytes <= 0) {
                done = true;
            } else {
                byte[] buffer = new byte[availableBytes];
                int howManyBytesRead = input.read(buffer);
                if (howManyBytesRead <= 0) {
                    done = true;
                } else {
                    signatureChecker.update(buffer, 0, howManyBytesRead);
                }
            }
        }
        return signatureChecker.verifySignature(signature);
    }
}
Also used : PSSSigner(org.spongycastle.crypto.signers.PSSSigner) Signer(org.spongycastle.crypto.Signer) Digest(org.spongycastle.crypto.Digest) SHA1Digest(org.spongycastle.crypto.digests.SHA1Digest) PSSSigner(org.spongycastle.crypto.signers.PSSSigner) ParametersWithRandom(org.spongycastle.crypto.params.ParametersWithRandom) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Aggregations

NonNull (org.checkerframework.checker.nullness.qual.NonNull)1 Digest (org.spongycastle.crypto.Digest)1 Signer (org.spongycastle.crypto.Signer)1 SHA1Digest (org.spongycastle.crypto.digests.SHA1Digest)1 ParametersWithRandom (org.spongycastle.crypto.params.ParametersWithRandom)1 PSSSigner (org.spongycastle.crypto.signers.PSSSigner)1