Java 类org.bouncycastle.crypto.params.GOST3410PrivateKeyParameters 实例源码

项目:gwt-crypto    文件:GOST3410Signer.java   
public void init(
    boolean                 forSigning,
    CipherParameters        param)
{
    if (forSigning)
    {
        if (param instanceof ParametersWithRandom)
        {
            ParametersWithRandom rParam = (ParametersWithRandom)param;

            this.random = rParam.getRandom();
            this.key = (GOST3410PrivateKeyParameters)rParam.getParameters();
        }
        else
        {
            this.random = new SecureRandom();
            this.key = (GOST3410PrivateKeyParameters)param;
        }
    }
    else
    {
        this.key = (GOST3410PublicKeyParameters)param;
    }
}
项目:Aki-SSL    文件:GOST3410Signer.java   
public void init(
    boolean                 forSigning,
    CipherParameters        param)
{
    if (forSigning)
    {
        if (param instanceof ParametersWithRandom)
        {
            ParametersWithRandom rParam = (ParametersWithRandom)param;

            this.random = rParam.getRandom();
            this.key = (GOST3410PrivateKeyParameters)rParam.getParameters();
        }
        else
        {
            this.random = new SecureRandom();
            this.key = (GOST3410PrivateKeyParameters)param;
        }
    }
    else
    {
        this.key = (GOST3410PublicKeyParameters)param;
    }
}
项目:TinyTravelTracker    文件:GOST3410Signer.java   
public void init(
    boolean                 forSigning,
    CipherParameters        param)
{
    if (forSigning)
    {
        if (param instanceof ParametersWithRandom)
        {
            ParametersWithRandom rParam = (ParametersWithRandom)param;

            this.random = rParam.getRandom();
            this.key = (GOST3410PrivateKeyParameters)rParam.getParameters();
        }
        else
        {
            this.random = new SecureRandom();
            this.key = (GOST3410PrivateKeyParameters)param;
        }
    }
    else
    {
        this.key = (GOST3410PublicKeyParameters)param;
    }
}
项目:CryptMeme    文件:GOST3410KeyPairGenerator.java   
public AsymmetricCipherKeyPair generateKeyPair()
{
    BigInteger      p, q, a, x, y;
    GOST3410Parameters   GOST3410Params = param.getParameters();
    SecureRandom    random = param.getRandom();

    q = GOST3410Params.getQ();
    p = GOST3410Params.getP();
    a = GOST3410Params.getA();

    do
    {
        x = new BigInteger(256, random);
    }
    while (x.equals(ZERO) || x.compareTo(q) >= 0);

    //
    // calculate the public key.
    //
    y = a.modPow(x, p);

    return new AsymmetricCipherKeyPair(
            new GOST3410PublicKeyParameters(y, GOST3410Params),
            new GOST3410PrivateKeyParameters(x, GOST3410Params));
}
项目:irma_future_id    文件:GOST3410KeyPairGenerator.java   
public AsymmetricCipherKeyPair generateKeyPair()
{
    BigInteger      p, q, a, x, y;
    GOST3410Parameters   GOST3410Params = param.getParameters();
    SecureRandom    random = param.getRandom();

    q = GOST3410Params.getQ();
    p = GOST3410Params.getP();
    a = GOST3410Params.getA();

    do
    {
        x = new BigInteger(256, random);
    }
    while (x.equals(ZERO) || x.compareTo(q) >= 0);

    //
    // calculate the public key.
    //
    y = a.modPow(x, p);

    return new AsymmetricCipherKeyPair(
            new GOST3410PublicKeyParameters(y, GOST3410Params),
            new GOST3410PrivateKeyParameters(x, GOST3410Params));
}
项目:bc-java    文件:GOST3410KeyPairGenerator.java   
public AsymmetricCipherKeyPair generateKeyPair()
{
    BigInteger      p, q, a, x, y;
    GOST3410Parameters   GOST3410Params = param.getParameters();
    SecureRandom    random = param.getRandom();

    q = GOST3410Params.getQ();
    p = GOST3410Params.getP();
    a = GOST3410Params.getA();

    do
    {
        x = new BigInteger(256, random);
    }
    while (x.equals(ZERO) || x.compareTo(q) >= 0);

    //
    // calculate the public key.
    //
    y = a.modPow(x, p);

    return new AsymmetricCipherKeyPair(
            new GOST3410PublicKeyParameters(y, GOST3410Params),
            new GOST3410PrivateKeyParameters(x, GOST3410Params));
}
项目:ipack    文件:BCGOST3410PrivateKey.java   
BCGOST3410PrivateKey(
    GOST3410PrivateKeyParameters params,
    GOST3410ParameterSpec spec)
{
    this.x = params.getX();
    this.gost3410Spec = spec;

    if (spec == null) 
    {
        throw new IllegalArgumentException("spec is null");
    }
}
项目:ipack    文件:KeyPairGeneratorSpi.java   
public KeyPair generateKeyPair()
{
    if (!initialised)
    {
        init(new GOST3410ParameterSpec(CryptoProObjectIdentifiers.gostR3410_94_CryptoPro_A.getId()), new SecureRandom());
    }

    AsymmetricCipherKeyPair pair = engine.generateKeyPair();
    GOST3410PublicKeyParameters pub = (GOST3410PublicKeyParameters)pair.getPublic();
    GOST3410PrivateKeyParameters priv = (GOST3410PrivateKeyParameters)pair.getPrivate();

    return new KeyPair(new BCGOST3410PublicKey(pub, gost3410Params), new BCGOST3410PrivateKey(priv, gost3410Params));
}
项目:ipack    文件:GOST3410Util.java   
static public AsymmetricKeyParameter generatePrivateKeyParameter(
    PrivateKey    key)
    throws InvalidKeyException
{
    if (key instanceof GOST3410PrivateKey)
    {
        GOST3410PrivateKey         k = (GOST3410PrivateKey)key;
        GOST3410PublicKeyParameterSetSpec p = k.getParameters().getPublicKeyParameters();

        return new GOST3410PrivateKeyParameters(k.getX(),
            new GOST3410Parameters(p.getP(), p.getQ(), p.getA()));
    }

    throw new InvalidKeyException("can't identify GOST3410 private key.");
}
项目:gwt-crypto    文件:GOST3410Signer.java   
/**
 * generate a signature for the given message using the key we were
 * initialised with. For conventional GOST3410 the message should be a GOST3411
 * hash of the message of interest.
 *
 * @param message the message that will be verified later.
 */
public BigInteger[] generateSignature(
    byte[] message)
{
    byte[] mRev = new byte[message.length]; // conversion is little-endian
    for (int i = 0; i != mRev.length; i++)
    {
        mRev[i] = message[mRev.length - 1 - i];
    }

    BigInteger      m = new BigInteger(1, mRev);
    GOST3410Parameters   params = key.getParameters();
    BigInteger      k;

    do
    {
        k = new BigInteger(params.getQ().bitLength(), random);
    }
    while (k.compareTo(params.getQ()) >= 0);

    BigInteger  r = params.getA().modPow(k, params.getP()).mod(params.getQ());

    BigInteger  s = k.multiply(m).
                        add(((GOST3410PrivateKeyParameters)key).getX().multiply(r)).
                            mod(params.getQ());

    BigInteger[]  res = new BigInteger[2];

    res[0] = r;
    res[1] = s;

    return res;
}
项目:gwt-crypto    文件:GOST3410KeyPairGenerator.java   
public AsymmetricCipherKeyPair generateKeyPair()
{
    BigInteger      p, q, a, x, y;
    GOST3410Parameters   GOST3410Params = param.getParameters();
    SecureRandom    random = param.getRandom();

    q = GOST3410Params.getQ();
    p = GOST3410Params.getP();
    a = GOST3410Params.getA();

    int minWeight = 64;
    for (;;)
    {
        x = new BigInteger(256, random);

        if (x.signum() < 1 || x.compareTo(q) >= 0)
        {
            continue;
        }

        if (WNafUtil.getNafWeight(x) < minWeight)
        {
            continue;
        }

        break;
    }

    //
    // calculate the public key.
    //
    y = a.modPow(x, p);

    return new AsymmetricCipherKeyPair(
            new GOST3410PublicKeyParameters(y, GOST3410Params),
            new GOST3410PrivateKeyParameters(x, GOST3410Params));
}
项目:Aki-SSL    文件:GOST3410Signer.java   
/**
 * generate a signature for the given message using the key we were
 * initialised with. For conventional GOST3410 the message should be a GOST3411
 * hash of the message of interest.
 *
 * @param message the message that will be verified later.
 */
public BigInteger[] generateSignature(
    byte[] message)
{
    byte[] mRev = new byte[message.length]; // conversion is little-endian
    for (int i = 0; i != mRev.length; i++)
    {
        mRev[i] = message[mRev.length - 1 - i];
    }

    BigInteger      m = new BigInteger(1, mRev);
    GOST3410Parameters   params = key.getParameters();
    BigInteger      k;

    do
    {
        k = new BigInteger(params.getQ().bitLength(), random);
    }
    while (k.compareTo(params.getQ()) >= 0);

    BigInteger  r = params.getA().modPow(k, params.getP()).mod(params.getQ());

    BigInteger  s = k.multiply(m).
                        add(((GOST3410PrivateKeyParameters)key).getX().multiply(r)).
                            mod(params.getQ());

    BigInteger[]  res = new BigInteger[2];

    res[0] = r;
    res[1] = s;

    return res;
}
项目:Aki-SSL    文件:GOST3410KeyPairGenerator.java   
public AsymmetricCipherKeyPair generateKeyPair()
{
    BigInteger      p, q, a, x, y;
    GOST3410Parameters   GOST3410Params = param.getParameters();
    SecureRandom    random = param.getRandom();

    q = GOST3410Params.getQ();
    p = GOST3410Params.getP();
    a = GOST3410Params.getA();

    int minWeight = 64;
    for (;;)
    {
        x = new BigInteger(256, random);

        if (x.signum() < 1 || x.compareTo(q) >= 0)
        {
            continue;
        }

        if (WNafUtil.getNafWeight(x) < minWeight)
        {
            continue;
        }

        break;
    }

    //
    // calculate the public key.
    //
    y = a.modPow(x, p);

    return new AsymmetricCipherKeyPair(
            new GOST3410PublicKeyParameters(y, GOST3410Params),
            new GOST3410PrivateKeyParameters(x, GOST3410Params));
}
项目:Aki-SSL    文件:BCGOST3410PrivateKey.java   
BCGOST3410PrivateKey(
    GOST3410PrivateKeyParameters params,
    GOST3410ParameterSpec spec)
{
    this.x = params.getX();
    this.gost3410Spec = spec;

    if (spec == null) 
    {
        throw new IllegalArgumentException("spec is null");
    }
}
项目:Aki-SSL    文件:KeyPairGeneratorSpi.java   
public KeyPair generateKeyPair()
{
    if (!initialised)
    {
        init(new GOST3410ParameterSpec(CryptoProObjectIdentifiers.gostR3410_94_CryptoPro_A.getId()), new SecureRandom());
    }

    AsymmetricCipherKeyPair pair = engine.generateKeyPair();
    GOST3410PublicKeyParameters pub = (GOST3410PublicKeyParameters)pair.getPublic();
    GOST3410PrivateKeyParameters priv = (GOST3410PrivateKeyParameters)pair.getPrivate();

    return new KeyPair(new BCGOST3410PublicKey(pub, gost3410Params), new BCGOST3410PrivateKey(priv, gost3410Params));
}
项目:Aki-SSL    文件:GOST3410Util.java   
static public AsymmetricKeyParameter generatePrivateKeyParameter(
    PrivateKey    key)
    throws InvalidKeyException
{
    if (key instanceof GOST3410PrivateKey)
    {
        GOST3410PrivateKey         k = (GOST3410PrivateKey)key;
        GOST3410PublicKeyParameterSetSpec p = k.getParameters().getPublicKeyParameters();

        return new GOST3410PrivateKeyParameters(k.getX(),
            new GOST3410Parameters(p.getP(), p.getQ(), p.getA()));
    }

    throw new InvalidKeyException("can't identify GOST3410 private key.");
}
项目:TinyTravelTracker    文件:GOST3410Signer.java   
/**
 * generate a signature for the given message using the key we were
 * initialised with. For conventional GOST3410 the message should be a GOST3411
 * hash of the message of interest.
 *
 * @param message the message that will be verified later.
 */
public BigInteger[] generateSignature(
    byte[] message)
{
    byte[] mRev = new byte[message.length]; // conversion is little-endian
    for (int i = 0; i != mRev.length; i++)
    {
        mRev[i] = message[mRev.length - 1 - i];
    }

    BigInteger      m = new BigInteger(1, mRev);
    GOST3410Parameters   params = key.getParameters();
    BigInteger      k;

    do
    {
        k = new BigInteger(params.getQ().bitLength(), random);
    }
    while (k.compareTo(params.getQ()) >= 0);

    BigInteger  r = params.getA().modPow(k, params.getP()).mod(params.getQ());

    BigInteger  s = k.multiply(m).
                        add(((GOST3410PrivateKeyParameters)key).getX().multiply(r)).
                            mod(params.getQ());

    BigInteger[]  res = new BigInteger[2];

    res[0] = r;
    res[1] = s;

    return res;
}
项目:CryptMeme    文件:BCGOST3410PrivateKey.java   
BCGOST3410PrivateKey(
    GOST3410PrivateKeyParameters params,
    GOST3410ParameterSpec spec)
{
    this.x = params.getX();
    this.gost3410Spec = spec;

    if (spec == null) 
    {
        throw new IllegalArgumentException("spec is null");
    }
}
项目:CryptMeme    文件:KeyPairGeneratorSpi.java   
public KeyPair generateKeyPair()
{
    if (!initialised)
    {
        init(new GOST3410ParameterSpec(CryptoProObjectIdentifiers.gostR3410_94_CryptoPro_A.getId()), new SecureRandom());
    }

    AsymmetricCipherKeyPair pair = engine.generateKeyPair();
    GOST3410PublicKeyParameters pub = (GOST3410PublicKeyParameters)pair.getPublic();
    GOST3410PrivateKeyParameters priv = (GOST3410PrivateKeyParameters)pair.getPrivate();

    return new KeyPair(new BCGOST3410PublicKey(pub, gost3410Params), new BCGOST3410PrivateKey(priv, gost3410Params));
}
项目:CryptMeme    文件:GOST3410Util.java   
static public AsymmetricKeyParameter generatePrivateKeyParameter(
    PrivateKey    key)
    throws InvalidKeyException
{
    if (key instanceof GOST3410PrivateKey)
    {
        GOST3410PrivateKey         k = (GOST3410PrivateKey)key;
        GOST3410PublicKeyParameterSetSpec p = k.getParameters().getPublicKeyParameters();

        return new GOST3410PrivateKeyParameters(k.getX(),
            new GOST3410Parameters(p.getP(), p.getQ(), p.getA()));
    }

    throw new InvalidKeyException("can't identify GOST3410 private key.");
}
项目:irma_future_id    文件:BCGOST3410PrivateKey.java   
BCGOST3410PrivateKey(
    GOST3410PrivateKeyParameters params,
    GOST3410ParameterSpec spec)
{
    this.x = params.getX();
    this.gost3410Spec = spec;

    if (spec == null) 
    {
        throw new IllegalArgumentException("spec is null");
    }
}
项目:irma_future_id    文件:KeyPairGeneratorSpi.java   
public KeyPair generateKeyPair()
{
    if (!initialised)
    {
        init(new GOST3410ParameterSpec(CryptoProObjectIdentifiers.gostR3410_94_CryptoPro_A.getId()), new SecureRandom());
    }

    AsymmetricCipherKeyPair pair = engine.generateKeyPair();
    GOST3410PublicKeyParameters pub = (GOST3410PublicKeyParameters)pair.getPublic();
    GOST3410PrivateKeyParameters priv = (GOST3410PrivateKeyParameters)pair.getPrivate();

    return new KeyPair(new BCGOST3410PublicKey(pub, gost3410Params), new BCGOST3410PrivateKey(priv, gost3410Params));
}
项目:irma_future_id    文件:GOST3410Util.java   
static public AsymmetricKeyParameter generatePrivateKeyParameter(
    PrivateKey    key)
    throws InvalidKeyException
{
    if (key instanceof GOST3410PrivateKey)
    {
        GOST3410PrivateKey         k = (GOST3410PrivateKey)key;
        GOST3410PublicKeyParameterSetSpec p = k.getParameters().getPublicKeyParameters();

        return new GOST3410PrivateKeyParameters(k.getX(),
            new GOST3410Parameters(p.getP(), p.getQ(), p.getA()));
    }

    throw new InvalidKeyException("can't identify GOST3410 private key.");
}
项目:bc-java    文件:BCGOST3410PrivateKey.java   
BCGOST3410PrivateKey(
    GOST3410PrivateKeyParameters params,
    GOST3410ParameterSpec spec)
{
    this.x = params.getX();
    this.gost3410Spec = spec;

    if (spec == null) 
    {
        throw new IllegalArgumentException("spec is null");
    }
}
项目:bc-java    文件:KeyPairGeneratorSpi.java   
public KeyPair generateKeyPair()
{
    if (!initialised)
    {
        init(new GOST3410ParameterSpec(CryptoProObjectIdentifiers.gostR3410_94_CryptoPro_A.getId()), new SecureRandom());
    }

    AsymmetricCipherKeyPair pair = engine.generateKeyPair();
    GOST3410PublicKeyParameters pub = (GOST3410PublicKeyParameters)pair.getPublic();
    GOST3410PrivateKeyParameters priv = (GOST3410PrivateKeyParameters)pair.getPrivate();

    return new KeyPair(new BCGOST3410PublicKey(pub, gost3410Params), new BCGOST3410PrivateKey(priv, gost3410Params));
}
项目:bc-java    文件:GOST3410Util.java   
static public AsymmetricKeyParameter generatePrivateKeyParameter(
    PrivateKey    key)
    throws InvalidKeyException
{
    if (key instanceof GOST3410PrivateKey)
    {
        GOST3410PrivateKey         k = (GOST3410PrivateKey)key;
        GOST3410PublicKeyParameterSetSpec p = k.getParameters().getPublicKeyParameters();

        return new GOST3410PrivateKeyParameters(k.getX(),
            new GOST3410Parameters(p.getP(), p.getQ(), p.getA()));
    }

    throw new InvalidKeyException("can't identify GOST3410 private key.");
}
项目:TinyTravelTracker    文件:GOST3410KeyPairGenerator.java   
public AsymmetricCipherKeyPair generateKeyPair()
{
    BigInteger      p, q, a, x, y;
    GOST3410Parameters   GOST3410Params = param.getParameters();
    SecureRandom    random = param.getRandom();

    q = GOST3410Params.getQ();
    p = GOST3410Params.getP();
    a = GOST3410Params.getA();

    int minWeight = 64;
    for (;;)
    {
        x = new BigInteger(256, random);

        if (x.signum() < 1 || x.compareTo(q) >= 0)
        {
            continue;
        }

        /*
         * Require a minimum weight of the NAF representation, since low-weight primes may be
         * weak against a version of the number-field-sieve for the discrete-logarithm-problem.
         * 
         * See "The number field sieve for integers of low weight", Oliver Schirokauer.
         */
        if (WNafUtil.getNafWeight(x) < minWeight)
        {
            continue;
        }

        break;
    }

    //
    // calculate the public key.
    //
    y = a.modPow(x, p);

    return new AsymmetricCipherKeyPair(
            new GOST3410PublicKeyParameters(y, GOST3410Params),
            new GOST3410PrivateKeyParameters(x, GOST3410Params));
}