Search in sources :

Example 6 with EdDSAEngine

use of net.i2p.crypto.eddsa.EdDSAEngine in project i2p.i2p by i2p.

the class DSAEngine method altSign.

/**
 *  Generic sign any type.
 *
 *  @throws GeneralSecurityException if algorithm unvailable or on other errors
 *  @since 0.9.9 added off/len 0.9.12
 */
private Signature altSign(byte[] data, int offset, int len, SigningPrivateKey privateKey) throws GeneralSecurityException {
    SigType type = privateKey.getType();
    if (type == SigType.DSA_SHA1)
        return altSignSHA1(data, offset, len, privateKey);
    PrivateKey privKey = SigUtil.toJavaKey(privateKey);
    byte[] sigbytes;
    if (type.getBaseAlgorithm() == SigAlgo.EdDSA) {
        // take advantage of one-shot mode
        EdDSAEngine jsig = new EdDSAEngine(type.getDigestInstance());
        jsig.initSign(privKey);
        sigbytes = jsig.signOneShot(data, offset, len);
    } else {
        java.security.Signature jsig = java.security.Signature.getInstance(type.getAlgorithmName());
        jsig.initSign(privKey, _context.random());
        jsig.update(data, offset, len);
        sigbytes = jsig.sign();
    }
    return SigUtil.fromJavaSig(sigbytes, type);
}
Also used : EdDSAEngine(net.i2p.crypto.eddsa.EdDSAEngine) SigningPrivateKey(net.i2p.data.SigningPrivateKey) PrivateKey(java.security.PrivateKey)

Aggregations

EdDSAEngine (net.i2p.crypto.eddsa.EdDSAEngine)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 PostConstruct (javax.annotation.PostConstruct)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 InvalidKeyException (java.security.InvalidKeyException)1 KeyPair (java.security.KeyPair)1 PrivateKey (java.security.PrivateKey)1 PublicKey (java.security.PublicKey)1 EdDSAPrivateKey (net.i2p.crypto.eddsa.EdDSAPrivateKey)1 EdDSAPublicKey (net.i2p.crypto.eddsa.EdDSAPublicKey)1 KeyPairGenerator (net.i2p.crypto.eddsa.KeyPairGenerator)1 EdDSAPrivateKeySpec (net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec)1 EdDSAPublicKeySpec (net.i2p.crypto.eddsa.spec.EdDSAPublicKeySpec)1 SigningPrivateKey (net.i2p.data.SigningPrivateKey)1 SigningPublicKey (net.i2p.data.SigningPublicKey)1