Search in sources :

Example 1 with Ed25519Verify

use of com.google.crypto.tink.subtle.Ed25519Verify in project tink by google.

the class Ed25519PrivateKeyManagerTest method createPrimitive.

@Test
public void createPrimitive() throws Exception {
    Ed25519PrivateKey privateKey = factory.createKey(Ed25519KeyFormat.getDefaultInstance());
    PublicKeySign signer = manager.getPrimitive(privateKey, PublicKeySign.class);
    PublicKeyVerify verifier = new Ed25519Verify(privateKey.getPublicKey().getKeyValue().toByteArray());
    byte[] message = Random.randBytes(135);
    verifier.verify(signer.sign(message), message);
}
Also used : Ed25519PrivateKey(com.google.crypto.tink.proto.Ed25519PrivateKey) Ed25519Verify(com.google.crypto.tink.subtle.Ed25519Verify) PublicKeyVerify(com.google.crypto.tink.PublicKeyVerify) PublicKeySign(com.google.crypto.tink.PublicKeySign) Test(org.junit.Test)

Example 2 with Ed25519Verify

use of com.google.crypto.tink.subtle.Ed25519Verify in project tink by google.

the class Ed25519PublicKeyManager method getPrimitive.

@Override
public PublicKeyVerify getPrimitive(MessageLite key) throws GeneralSecurityException {
    if (!(key instanceof Ed25519PublicKey)) {
        throw new GeneralSecurityException("expected Ed25519PublicKey proto");
    }
    Ed25519PublicKey keyProto = (Ed25519PublicKey) key;
    validate(keyProto);
    return new Ed25519Verify(keyProto.getKeyValue().toByteArray());
}
Also used : Ed25519PublicKey(com.google.crypto.tink.proto.Ed25519PublicKey) Ed25519Verify(com.google.crypto.tink.subtle.Ed25519Verify) GeneralSecurityException(java.security.GeneralSecurityException)

Example 3 with Ed25519Verify

use of com.google.crypto.tink.subtle.Ed25519Verify in project tink by google.

the class Ed25519PrivateKeyManagerTest method testBasic.

@Test
public void testBasic() throws Exception {
    Ed25519PrivateKeyManager manager = new Ed25519PrivateKeyManager();
    KeyTemplate template = SignatureKeyTemplates.ED25519;
    MessageLite key = manager.newKey(template);
    assertTrue(key instanceof Ed25519PrivateKey);
    Ed25519PrivateKey keyProto = (Ed25519PrivateKey) key;
    assertEquals(32, keyProto.getKeyValue().size());
    PublicKeySign signer = manager.getPrimitive(key);
    assertTrue(signer instanceof Ed25519Sign);
    byte[] message = Random.randBytes(20);
    byte[] signature = signer.sign(message);
    assertEquals(64, signature.length);
    Ed25519PublicKeyManager publicKeyManager = new Ed25519PublicKeyManager();
    PublicKeyVerify verifier = publicKeyManager.getPrimitive(keyProto.getPublicKey());
    assertTrue(verifier instanceof Ed25519Verify);
    try {
        verifier.verify(signature, message);
    } catch (GeneralSecurityException e) {
        fail("Do not expect GeneralSecurityException: " + e);
    }
}
Also used : Ed25519PrivateKey(com.google.crypto.tink.proto.Ed25519PrivateKey) Ed25519Verify(com.google.crypto.tink.subtle.Ed25519Verify) GeneralSecurityException(java.security.GeneralSecurityException) PublicKeyVerify(com.google.crypto.tink.PublicKeyVerify) Ed25519Sign(com.google.crypto.tink.subtle.Ed25519Sign) KeyTemplate(com.google.crypto.tink.proto.KeyTemplate) MessageLite(com.google.protobuf.MessageLite) PublicKeySign(com.google.crypto.tink.PublicKeySign) Test(org.junit.Test)

Example 4 with Ed25519Verify

use of com.google.crypto.tink.subtle.Ed25519Verify in project tink by google.

the class Ed25519PrivateKeyManagerTest method testDeriveKeySignVerify.

@Test
public void testDeriveKeySignVerify() throws Exception {
    byte[] keyMaterial = Random.randBytes(100);
    Ed25519PrivateKey key = factory.deriveKey(Ed25519KeyFormat.newBuilder().setVersion(0).build(), new ByteArrayInputStream(keyMaterial));
    PublicKeySign signer = manager.getPrimitive(key, PublicKeySign.class);
    PublicKeyVerify verifier = new Ed25519Verify(key.getPublicKey().getKeyValue().toByteArray());
    byte[] message = Random.randBytes(135);
    verifier.verify(signer.sign(message), message);
}
Also used : Ed25519PrivateKey(com.google.crypto.tink.proto.Ed25519PrivateKey) ByteArrayInputStream(java.io.ByteArrayInputStream) Ed25519Verify(com.google.crypto.tink.subtle.Ed25519Verify) PublicKeyVerify(com.google.crypto.tink.PublicKeyVerify) PublicKeySign(com.google.crypto.tink.PublicKeySign) Test(org.junit.Test)

Aggregations

Ed25519Verify (com.google.crypto.tink.subtle.Ed25519Verify)4 PublicKeySign (com.google.crypto.tink.PublicKeySign)3 PublicKeyVerify (com.google.crypto.tink.PublicKeyVerify)3 Ed25519PrivateKey (com.google.crypto.tink.proto.Ed25519PrivateKey)3 Test (org.junit.Test)3 GeneralSecurityException (java.security.GeneralSecurityException)2 Ed25519PublicKey (com.google.crypto.tink.proto.Ed25519PublicKey)1 KeyTemplate (com.google.crypto.tink.proto.KeyTemplate)1 Ed25519Sign (com.google.crypto.tink.subtle.Ed25519Sign)1 MessageLite (com.google.protobuf.MessageLite)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1