Search in sources :

Example 6 with DSAPrivateKeyParameters

use of org.bouncycastle.crypto.params.DSAPrivateKeyParameters in project robovm by robovm.

the class DSASigner method generateSignature.

/**
     * generate a signature for the given message using the key we were
     * initialised with. For conventional DSA the message should be a SHA-1
     * hash of the message of interest.
     *
     * @param message the message that will be verified later.
     */
public BigInteger[] generateSignature(byte[] message) {
    DSAParameters params = key.getParameters();
    BigInteger m = calculateE(params.getQ(), message);
    BigInteger k;
    int qBitLength = params.getQ().bitLength();
    do {
        k = new BigInteger(qBitLength, random);
    } while (k.compareTo(params.getQ()) >= 0);
    BigInteger r = params.getG().modPow(k, params.getP()).mod(params.getQ());
    k = k.modInverse(params.getQ()).multiply(m.add(((DSAPrivateKeyParameters) key).getX().multiply(r)));
    BigInteger s = k.mod(params.getQ());
    BigInteger[] res = new BigInteger[2];
    res[0] = r;
    res[1] = s;
    return res;
}
Also used : DSAPrivateKeyParameters(org.bouncycastle.crypto.params.DSAPrivateKeyParameters) BigInteger(java.math.BigInteger) DSAParameters(org.bouncycastle.crypto.params.DSAParameters)

Example 7 with DSAPrivateKeyParameters

use of org.bouncycastle.crypto.params.DSAPrivateKeyParameters in project Skein3Fish by wernerd.

the class DSASigner method generateSignature.

/**
     * generate a signature for the given message using the key we were
     * initialised with. For conventional DSA the message should be a SHA-1
     * hash of the message of interest.
     *
     * @param message the message that will be verified later.
     */
public BigInteger[] generateSignature(byte[] message) {
    DSAParameters params = key.getParameters();
    BigInteger m = calculateE(params.getQ(), message);
    BigInteger k;
    int qBitLength = params.getQ().bitLength();
    do {
        k = new BigInteger(qBitLength, random);
    } while (k.compareTo(params.getQ()) >= 0);
    BigInteger r = params.getG().modPow(k, params.getP()).mod(params.getQ());
    k = k.modInverse(params.getQ()).multiply(m.add(((DSAPrivateKeyParameters) key).getX().multiply(r)));
    BigInteger s = k.mod(params.getQ());
    BigInteger[] res = new BigInteger[2];
    res[0] = r;
    res[1] = s;
    return res;
}
Also used : DSAPrivateKeyParameters(org.bouncycastle.crypto.params.DSAPrivateKeyParameters) BigInteger(java.math.BigInteger) DSAParameters(org.bouncycastle.crypto.params.DSAParameters)

Example 8 with DSAPrivateKeyParameters

use of org.bouncycastle.crypto.params.DSAPrivateKeyParameters in project XobotOS by xamarin.

the class DSASigner method generateSignature.

/**
     * generate a signature for the given message using the key we were
     * initialised with. For conventional DSA the message should be a SHA-1
     * hash of the message of interest.
     *
     * @param message the message that will be verified later.
     */
public BigInteger[] generateSignature(byte[] message) {
    DSAParameters params = key.getParameters();
    BigInteger m = calculateE(params.getQ(), message);
    BigInteger k;
    int qBitLength = params.getQ().bitLength();
    do {
        k = new BigInteger(qBitLength, random);
    } while (k.compareTo(params.getQ()) >= 0);
    BigInteger r = params.getG().modPow(k, params.getP()).mod(params.getQ());
    k = k.modInverse(params.getQ()).multiply(m.add(((DSAPrivateKeyParameters) key).getX().multiply(r)));
    BigInteger s = k.mod(params.getQ());
    BigInteger[] res = new BigInteger[2];
    res[0] = r;
    res[1] = s;
    return res;
}
Also used : DSAPrivateKeyParameters(org.bouncycastle.crypto.params.DSAPrivateKeyParameters) BigInteger(java.math.BigInteger) DSAParameters(org.bouncycastle.crypto.params.DSAParameters)

Aggregations

DSAPrivateKeyParameters (org.bouncycastle.crypto.params.DSAPrivateKeyParameters)8 BigInteger (java.math.BigInteger)7 DSAParameters (org.bouncycastle.crypto.params.DSAParameters)7 AsymmetricCipherKeyPair (org.bouncycastle.crypto.AsymmetricCipherKeyPair)3 DSAPublicKeyParameters (org.bouncycastle.crypto.params.DSAPublicKeyParameters)3 DHParameter (org.bouncycastle.asn1.pkcs.DHParameter)2 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)2 DSAParameter (org.bouncycastle.asn1.x509.DSAParameter)2 X962Parameters (org.bouncycastle.asn1.x9.X962Parameters)2 X9ECParameters (org.bouncycastle.asn1.x9.X9ECParameters)2 DHParameters (org.bouncycastle.crypto.params.DHParameters)2 DHPrivateKeyParameters (org.bouncycastle.crypto.params.DHPrivateKeyParameters)2 ECDomainParameters (org.bouncycastle.crypto.params.ECDomainParameters)2 ECPrivateKeyParameters (org.bouncycastle.crypto.params.ECPrivateKeyParameters)2 RSAPrivateCrtKeyParameters (org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters)2 KeyPair (java.security.KeyPair)1 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)1 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)1 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)1 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)1