Search in sources :

Example 1 with EdDSAParameterSpec

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

the class EdDSAEngineTest method testSign.

@Test
public void testSign() throws Exception {
    // Signature sgr = Signature.getInstance("EdDSA", "I2P");
    Signature sgr = new EdDSAEngine(MessageDigest.getInstance("SHA-512"));
    EdDSAParameterSpec spec = EdDSANamedCurveTable.getByName("ed25519-sha-512");
    for (Ed25519TestVectors.TestTuple testCase : Ed25519TestVectors.testCases) {
        EdDSAPrivateKeySpec privKey = new EdDSAPrivateKeySpec(testCase.seed, spec);
        PrivateKey sKey = new EdDSAPrivateKey(privKey);
        sgr.initSign(sKey);
        sgr.update(testCase.message);
        assertThat("Test case " + testCase.caseNum + " failed", sgr.sign(), is(equalTo(testCase.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)

Example 2 with EdDSAParameterSpec

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

the class EdDSAEngineTest method testSignOneShot.

@Test
public void testSignOneShot() throws Exception {
    EdDSAEngine 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);
    assertThat("signOneShot() failed", sgr.signOneShot(TEST_MSG), is(equalTo(TEST_MSG_SIG)));
}
Also used : EdDSAParameterSpec(net.i2p.crypto.eddsa.spec.EdDSAParameterSpec) PrivateKey(java.security.PrivateKey) EdDSAPrivateKeySpec(net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec) Test(org.junit.Test)

Example 3 with EdDSAParameterSpec

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

the class EdDSAEngineTest method testSignResetsForReuse.

@Test
public void testSignResetsForReuse() 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);
    // First usage
    sgr.update(new byte[] { 0 });
    sgr.sign();
    // Second usage
    sgr.update(TEST_MSG);
    assertThat("Second 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)

Example 4 with EdDSAParameterSpec

use of net.i2p.crypto.eddsa.spec.EdDSAParameterSpec 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 5 with EdDSAParameterSpec

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

the class EdDSAEngineTest method testVerify.

@Test
public void testVerify() throws Exception {
    // Signature sgr = Signature.getInstance("EdDSA", "I2P");
    Signature sgr = new EdDSAEngine(MessageDigest.getInstance("SHA-512"));
    EdDSAParameterSpec spec = EdDSANamedCurveTable.getByName("ed25519-sha-512");
    for (Ed25519TestVectors.TestTuple testCase : Ed25519TestVectors.testCases) {
        EdDSAPublicKeySpec pubKey = new EdDSAPublicKeySpec(testCase.pk, spec);
        PublicKey vKey = new EdDSAPublicKey(pubKey);
        sgr.initVerify(vKey);
        sgr.update(testCase.message);
        assertThat("Test case " + testCase.caseNum + " failed", sgr.verify(testCase.sig), is(true));
    }
}
Also used : EdDSAParameterSpec(net.i2p.crypto.eddsa.spec.EdDSAParameterSpec) EdDSAPublicKeySpec(net.i2p.crypto.eddsa.spec.EdDSAPublicKeySpec) PublicKey(java.security.PublicKey) Signature(java.security.Signature) Test(org.junit.Test)

Aggregations

EdDSAParameterSpec (net.i2p.crypto.eddsa.spec.EdDSAParameterSpec)6 Test (org.junit.Test)6 PrivateKey (java.security.PrivateKey)5 Signature (java.security.Signature)5 EdDSAPrivateKeySpec (net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec)5 PublicKey (java.security.PublicKey)1 EdDSAPublicKeySpec (net.i2p.crypto.eddsa.spec.EdDSAPublicKeySpec)1