You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@tuweni.apache.org by "Brian Demers (Jira)" <ji...@apache.org> on 2019/12/04 22:17:00 UTC
[jira] [Created] (TUWENI-30) Crypto GenericHash does NOT allow for
setting a key
Brian Demers created TUWENI-30:
----------------------------------
Summary: Crypto GenericHash does NOT allow for setting a key
Key: TUWENI-30
URL: https://issues.apache.org/jira/browse/TUWENI-30
Project: Tuweni
Issue Type: Bug
Reporter: Brian Demers
The GenericHash class in the `crytpo` module does NOT allow setting the key/key length when hashing a BLAKE2b.
Maybe expose something like `GenericHash.hash(int hashLength, Input input, Input key)`?
This monstrosity is my current workaround:
{code:java}
public static byte[] hash(int hashLength, byte[] bytes, byte[] key) { // static int crypto_generichash_blake2b(byte[] out, long outlen, byte[] in, long inlen, byte[] key, long keylen) byte[] output = new byte[hashLength]; try {
Method blake2b = Sodium.class.getDeclaredMethod("crypto_generichash_blake2b",
byte[].class, long.class,
byte[].class, long.class,
byte[].class, long.class); blake2b.setAccessible(true);
blake2b.invoke(null,
output, output.length,
bytes, bytes.length,
key, key.length); return output; } catch (NoSuchMethodException e) {
throw new IllegalStateException("Failed to find method 'crypto_generichash_blake2b' in: " + Sodium.class, e);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new IllegalStateException("Failed to calculate BLAKE2b digest", e);
}
} {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@tuweni.apache.org
For additional commands, e-mail: issues-help@tuweni.apache.org