javacryptographyhsmgemaltoed25519

EDDSA Signature with Luna HSM using Java


I am trying to implement EDDSA signature with Luna HSM(Gemalto)

Signature signature = null;
signature = Signature.getInstance("EDDSA", "LunaProvider");
PrivateKey privateKey = getPrivateByAlias(privateKeyLabel);
signature.initSign(privateKey);
signature.update(payload);
byte[] byteArray = signature.sign();

But after the signing, the byteArray size is coming as 71, but EDDSA signature size is 64 as per specification. I am not sure what i am missing here. I couldn't find any document either online.


Solution

  • This is exactly a size you would expect for an X9.63 compatible signature, which consists of a DER encoding of two signed big endian integers. If you want to have a 64 byte signature then you should convert the 2 integers inside using the following explanation. An implementation in Java of I2OSP and OS2IP can be found here.

    So the steps are:

    1. parse ASN.1 signature;
    2. convert to BigInteger values using the new BigInteger(byte[]) constructor;
    3. use I2OSP to create the r and s values as byte array (32 octet output size);
    4. concatenate the r and s to create the 64 byte signature.