Search in sources :

Example 6 with EdDSAPrivateKeySpec

use of net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec in project i2p.i2p by i2p.

the class EdDSAEngineTest method testSignOneShotModeMultipleUpdates.

@Test
public void testSignOneShotModeMultipleUpdates() throws Exception {
    Signature sgr = new EdDSAEngine(MessageDigest.getInstance("SHA-512"));
    EdDSAParameterSpec spec = EdDSANamedCurveTable.getByName("ed25519-sha-512");
    EdDSAPrivateKeySpec privKey = new EdDSAPrivateKeySpec(TEST_SEED, spec);
    PrivateKey sKey = new EdDSAPrivateKey(privKey);
    sgr.initSign(sKey);
    sgr.setParameter(EdDSAEngine.ONE_SHOT_MODE);
    sgr.update(TEST_MSG);
    exception.expect(SignatureException.class);
    exception.expectMessage("update() already called");
    sgr.update(TEST_MSG);
}
Also used : EdDSAParameterSpec(net.i2p.crypto.eddsa.spec.EdDSAParameterSpec) PrivateKey(java.security.PrivateKey) Signature(java.security.Signature) EdDSAPrivateKeySpec(net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec) Test(org.junit.Test)

Example 7 with EdDSAPrivateKeySpec

use of net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec in project i2p.i2p by i2p.

the class EdDSAEngineTest method testSignOneShotMode.

@Test
public void testSignOneShotMode() throws Exception {
    Signature sgr = new EdDSAEngine(MessageDigest.getInstance("SHA-512"));
    EdDSAParameterSpec spec = EdDSANamedCurveTable.getByName("ed25519-sha-512");
    EdDSAPrivateKeySpec privKey = new EdDSAPrivateKeySpec(TEST_SEED, spec);
    PrivateKey sKey = new EdDSAPrivateKey(privKey);
    sgr.initSign(sKey);
    sgr.setParameter(EdDSAEngine.ONE_SHOT_MODE);
    sgr.update(TEST_MSG);
    assertThat("One-shot mode sign failed", sgr.sign(), is(equalTo(TEST_MSG_SIG)));
}
Also used : EdDSAParameterSpec(net.i2p.crypto.eddsa.spec.EdDSAParameterSpec) PrivateKey(java.security.PrivateKey) Signature(java.security.Signature) EdDSAPrivateKeySpec(net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec) Test(org.junit.Test)

Aggregations

EdDSAPrivateKeySpec (net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec)7 PrivateKey (java.security.PrivateKey)5 EdDSAParameterSpec (net.i2p.crypto.eddsa.spec.EdDSAParameterSpec)5 Test (org.junit.Test)5 Signature (java.security.Signature)4 KeyPair (java.security.KeyPair)2 EdDSAPublicKeySpec (net.i2p.crypto.eddsa.spec.EdDSAPublicKeySpec)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 PostConstruct (javax.annotation.PostConstruct)1 EdDSAEngine (net.i2p.crypto.eddsa.EdDSAEngine)1 EdDSAPrivateKey (net.i2p.crypto.eddsa.EdDSAPrivateKey)1 EdDSAPublicKey (net.i2p.crypto.eddsa.EdDSAPublicKey)1 KeyPairGenerator (net.i2p.crypto.eddsa.KeyPairGenerator)1