Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/main/java/com/muquit/libsodiumjna/SodiumLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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
Expand Down