Search in sources :

Example 1 with DSAPublicKeyParameters

use of org.spongycastle.crypto.params.DSAPublicKeyParameters in project Zom-Android by zom.

the class OtrCryptoEngineImpl method verify.

private Boolean verify(byte[] b, PublicKey pubKey, BigInteger r, BigInteger s) throws OtrCryptoException {
    if (!(pubKey instanceof DSAPublicKey))
        throw new IllegalArgumentException();
    DSAParams dsaParams = ((DSAPublicKey) pubKey).getParams();
    BigInteger q = dsaParams.getQ();
    DSAParameters bcDSAParams = new DSAParameters(dsaParams.getP(), q, dsaParams.getG());
    DSAPublicKey dsaPrivateKey = (DSAPublicKey) pubKey;
    DSAPublicKeyParameters dsaPrivParms = new DSAPublicKeyParameters(dsaPrivateKey.getY(), bcDSAParams);
    // Ian: Note that if you can get the standard DSA implementation you're
    // using to not hash its input, you should be able to pass it ((256-bit
    // value) mod q), (rather than truncating the 256-bit value) and all
    // should be well.
    // ref: Interop problems with libotr - DSA signature
    DSASigner dsaSigner = new DSASigner();
    dsaSigner.init(false, dsaPrivParms);
    BigInteger bmpi = new BigInteger(1, b);
    Boolean result = dsaSigner.verifySignature(BigIntegers.asUnsignedByteArray(bmpi.mod(q)), r, s);
    return result;
}
Also used : DSAPublicKeyParameters(org.spongycastle.crypto.params.DSAPublicKeyParameters) DSASigner(org.spongycastle.crypto.signers.DSASigner) BigInteger(java.math.BigInteger) DSAParams(java.security.interfaces.DSAParams) DSAParameters(org.spongycastle.crypto.params.DSAParameters) DSAPublicKey(java.security.interfaces.DSAPublicKey)

Aggregations

BigInteger (java.math.BigInteger)1 DSAParams (java.security.interfaces.DSAParams)1 DSAPublicKey (java.security.interfaces.DSAPublicKey)1 DSAParameters (org.spongycastle.crypto.params.DSAParameters)1 DSAPublicKeyParameters (org.spongycastle.crypto.params.DSAPublicKeyParameters)1 DSASigner (org.spongycastle.crypto.signers.DSASigner)1