| 1 |
|
| 2 | |
| 3 | * NH hash function for Adiantum
|
| 4 |
|
| 5 |
|
| 6 | #ifndef _CRYPTO_NH_H
|
| 7 | #define _CRYPTO_NH_H
|
| 8 |
|
| 9 | #include <linux/types.h>
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 | #define NH_PAIR_STRIDE 2
|
| 18 | #define NH_MESSAGE_UNIT (NH_PAIR_STRIDE * 2 * sizeof(u32))
|
| 19 |
|
| 20 |
|
| 21 | #define NH_NUM_PASSES 4
|
| 22 | #define NH_HASH_BYTES (NH_NUM_PASSES * sizeof(u64))
|
| 23 |
|
| 24 |
|
| 25 | #define NH_NUM_STRIDES 64
|
| 26 | #define NH_MESSAGE_WORDS (NH_PAIR_STRIDE * 2 * NH_NUM_STRIDES)
|
| 27 | #define NH_MESSAGE_BYTES (NH_MESSAGE_WORDS * sizeof(u32))
|
| 28 | #define NH_KEY_WORDS (NH_MESSAGE_WORDS + \
|
| 29 | NH_PAIR_STRIDE * 2 * (NH_NUM_PASSES - 1))
|
| 30 | #define NH_KEY_BYTES (NH_KEY_WORDS * sizeof(u32))
|
| 31 |
|
| 32 | |
| 33 | * nh() - NH hash function for Adiantum
|
| 34 | * @key: The key. @message_len + 48 bytes of it are used. This is NH_KEY_BYTES
|
| 35 | * if @message_len has its maximum length of NH_MESSAGE_BYTES.
|
| 36 | * @message: The message
|
| 37 | * @message_len: The message length in bytes. Must be a multiple of 16
|
| 38 | * (NH_MESSAGE_UNIT) and at most 1024 (NH_MESSAGE_BYTES).
|
| 39 | * @hash: (output) The resulting hash value
|
| 40 | *
|
| 41 | * Note: the pseudocode for NH in the Adiantum paper iterates over 1024-byte
|
| 42 | * segments of the message, computes a 32-byte hash for each, and returns all
|
| 43 | * the hashes concatenated together. In contrast, this function just hashes one
|
| 44 | * segment and returns one hash. It's the caller's responsibility to call this
|
| 45 | * function for each 1024-byte segment and collect all the hashes.
|
| 46 | *
|
| 47 | * Context: Any context.
|
| 48 |
|
| 49 | void nh(const u32 *key, const u8 *message, size_t message_len,
|
| 50 | __le64 hash[NH_NUM_PASSES]);
|
| 51 |
|
| 52 | #endif
|