Package com.google.crypto.tink.internal
Class Ed25519
- java.lang.Object
-
- com.google.crypto.tink.internal.Ed25519
-
public final class Ed25519 extends java.lang.ObjectThis implementation is based on the ed25519/ref10 implementation in NaCl.It implements this twisted Edwards curve:
-x^2 + y^2 = 1 + (-121665 / 121666 mod 2^255-19)*x^2*y^2
-
-
Field Summary
Fields Modifier and Type Field Description static intPUBLIC_KEY_LENstatic intSECRET_KEY_LENstatic intSIGNATURE_LEN
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]getHashedScalar(byte[] privateKey)static voidinit()Initializes Ed25519 if not yet initialized.static byte[]scalarMultWithBaseToBytes(byte[] a)Computesa*B where a = a[0]+256*a[1]+...+256^31 a[31] and B is the Ed25519 base point (x,4/5) with x positive.static byte[]sign(byte[] message, byte[] publicKey, byte[] hashedPrivateKey)Returns the EdDSA signature for themessagebased on thehashedPrivateKey.static booleanverify(byte[] message, byte[] signature, byte[] publicKey)Returns true if the EdDSAsignaturewithmessage, can be verified withpublicKey.
-
-
-
Field Detail
-
SECRET_KEY_LEN
public static final int SECRET_KEY_LEN
- See Also:
- Constant Field Values
-
PUBLIC_KEY_LEN
public static final int PUBLIC_KEY_LEN
- See Also:
- Constant Field Values
-
SIGNATURE_LEN
public static final int SIGNATURE_LEN
- See Also:
- Constant Field Values
-
-
Method Detail
-
scalarMultWithBaseToBytes
public static byte[] scalarMultWithBaseToBytes(byte[] a)
Computesa*B where a = a[0]+256*a[1]+...+256^31 a[31] and B is the Ed25519 base point (x,4/5) with x positive. Preconditions: a[31] <= 127
-
getHashedScalar
public static byte[] getHashedScalar(byte[] privateKey) throws java.security.GeneralSecurityException- Throws:
java.security.GeneralSecurityException
-
sign
public static byte[] sign(byte[] message, byte[] publicKey, byte[] hashedPrivateKey) throws java.security.GeneralSecurityExceptionReturns the EdDSA signature for themessagebased on thehashedPrivateKey.- Parameters:
message- to signpublicKey-scalarMultWithBaseToBytes(byte[])ofhashedPrivateKeyhashedPrivateKey-getHashedScalar(byte[])of the private key- Returns:
- signature for the
message. - Throws:
java.security.GeneralSecurityException- if there is no SHA-512 algorithm defined inEngineFactory.MESSAGE_DIGEST.
-
verify
public static boolean verify(byte[] message, byte[] signature, byte[] publicKey) throws java.security.GeneralSecurityExceptionReturns true if the EdDSAsignaturewithmessage, can be verified withpublicKey.- Throws:
java.security.GeneralSecurityException- if there is no SHA-512 algorithm defined inEngineFactory.MESSAGE_DIGEST.
-
init
public static void init()
Initializes Ed25519 if not yet initialized.
-
-