public byte[] blake2(byte[] message) throws UnsupportedOperationException { byte[] buffer = new byte[CRYPTO_GENERICHASH_BLAKE2B_BYTES]; sodium().crypto_generichash_blake2b(buffer, CRYPTO_GENERICHASH_BLAKE2B_BYTES, message, message.length, null, 0); return buffer; }
public static Sodium sodium() { Sodium sodium = SingletonHolder.SODIUM_INSTANCE; checkVersion(sodium); return sodium; }
/** * This is a Java synchronized wrapper around libsodium's init function. * LibSodium's init function is not thread-safe. * * Check libsodium's documentation for more info. */ public static synchronized int init() { return sodium().sodium_init(); } }
public static Sodium sodium() { Sodium sodium = SingletonHolder.SODIUM_INSTANCE; checkVersion(sodium); return sodium; }
public Aead useAesGcm() { if (sodium().crypto_aead_aes256gcm_is_available() != 1) { throw new RuntimeException("AES-GCM requires hardware support"); } aesGcm = true; return this; }
public byte[] sha512(byte[] message) { byte[] buffer = new byte[CRYPTO_HASH_SHA512_BYTES]; sodium().crypto_hash_sha512(buffer, message, message.length); return buffer; }
public byte[] deriveKey(int length, byte[] passwd, byte[] salt, int opslimit, long memlimit) { byte[] buffer = new byte[length]; sodium().crypto_pwhash_scryptsalsa208sha256(buffer, buffer.length, passwd, passwd.length, salt, opslimit, memlimit); return buffer; }
public boolean verify(byte[] hashed_passwd, byte[] passwd) { int result = sodium().crypto_pwhash_scryptsalsa208sha256_str_verify(hashed_passwd, passwd, passwd.length); return result == 0; } }
public byte[] randomBytes() { byte[] buffer = new byte[DEFAULT_SIZE]; sodium().randombytes(buffer, DEFAULT_SIZE); return buffer; } }
public byte[] blake2(byte[] message, byte[] key, byte[] salt, byte[] personal) throws UnsupportedOperationException { byte[] buffer = new byte[CRYPTO_GENERICHASH_BLAKE2B_BYTES]; sodium().crypto_generichash_blake2b_salt_personal(buffer, CRYPTO_GENERICHASH_BLAKE2B_BYTES, message, message.length, key, key.length, salt, personal); return buffer; } }
public byte[] randomBytes() { byte[] buffer = new byte[DEFAULT_SIZE]; sodium().randombytes(buffer, DEFAULT_SIZE); return buffer; } }
@Override public NaclFacade create() { LOGGER.debug("Creating a Kalium implementation of NaclFacadeFactory"); final NaCl.Sodium sodium = NaCl.sodium(); return new Kalium(sodium); }
/** * This is a Java synchronized wrapper around libsodium's init function. * LibSodium's init function is not thread-safe. * * Check libsodium's documentation for more info. */ public static synchronized int init() { return sodium().sodium_init(); } }
public byte[] sha256(byte[] message) { byte[] buffer = new byte[CRYPTO_HASH_SHA256_BYTES]; sodium().crypto_hash_sha256(buffer, message, message.length); return buffer; }
/** * Generate random bytes * * @param n number or random bytes * @return */ public byte[] randomBytes(int n) { byte[] buffer = new byte[n]; sodium().randombytes(buffer, n); return buffer; }
public Aead useAesGcm() { if (sodium().crypto_aead_aes256gcm_is_available() != 1) { throw new RuntimeException("AES-GCM requires hardware support"); } aesGcm = true; return this; }
public byte[] deriveKey(int length, byte[] passwd, byte[] salt, int opslimit, long memlimit) { byte[] buffer = new byte[length]; sodium().crypto_pwhash_scryptsalsa208sha256(buffer, buffer.length, passwd, passwd.length, salt, opslimit, memlimit); return buffer; }
public byte[] sha256(byte[] message) { byte[] buffer = new byte[CRYPTO_HASH_SHA256_BYTES]; sodium().crypto_hash_sha256(buffer, message, message.length); return buffer; }
public byte[] sha512(byte[] message) { byte[] buffer = new byte[CRYPTO_HASH_SHA512_BYTES]; sodium().crypto_hash_sha512(buffer, message, message.length); return buffer; }
public byte[] blake2(byte[] message, byte[] key, byte[] salt, byte[] personal) throws UnsupportedOperationException { byte[] buffer = new byte[CRYPTO_GENERICHASH_BLAKE2B_BYTES]; sodium().crypto_generichash_blake2b_salt_personal(buffer, CRYPTO_GENERICHASH_BLAKE2B_BYTES, message, message.length, key, key.length, salt, personal); return buffer; } }