diff --git a/src/main/java/com/muquit/libsodiumjna/SodiumLibrary.java b/src/main/java/com/muquit/libsodiumjna/SodiumLibrary.java index a5adf31..d89756b 100755 --- a/src/main/java/com/muquit/libsodiumjna/SodiumLibrary.java +++ b/src/main/java/com/muquit/libsodiumjna/SodiumLibrary.java @@ -272,6 +272,7 @@ int crypto_box_open_easy(byte[] decrypted, byte[] cipher_text, long crypto_sign_secretkeybytes(); long crypto_sign_publickeybytes(); int crypto_sign_keypair(byte[] pk, byte[] sk); + int crypto_sign_seed_keypair(byte[] pk, byte[] sk, byte[] seed); int crypto_sign_ed25519_bytes(); int crypto_sign_bytes(); @@ -372,6 +373,25 @@ public static SodiumKeyPair cryptoSignKeyPair() throws SodiumLibraryException return kp; } + public static SodiumKeyPair cryptoSignSeedKeyPair(byte[] seed32) throws SodiumLibraryException + { + SodiumKeyPair kp = new SodiumKeyPair(); + byte[] publicKey = new byte[(int) sodium().crypto_sign_publickeybytes()]; + byte[] privateKey = new byte[(int) sodium().crypto_sign_secretkeybytes()]; + int rc = sodium().crypto_sign_seed_keypair(publicKey, privateKey, seed32); + if (rc != 0) + { + throw new SodiumLibraryException("libsodium crypto_sign_seed_keypair() failed, returned " + rc + ", expected 0"); + } + kp.setPublicKey(publicKey); + kp.setPrivateKey(privateKey); + if (logger.isDebugEnabled()) { + logger.debug("pk len: " + publicKey.length); + logger.debug("sk len: " + privateKey.length); + } + return kp; + } + // libsodium's generichash (blake2b), this function will only return 'length' number of bytes of the hash // this implementation does not expect key/key.length which blake does need, so we are setting them to null and 0 public static byte[] cryptoGenerichash(byte[] input, int length) throws SodiumLibraryException