-
Notifications
You must be signed in to change notification settings - Fork 48
/
ShortHash.java
69 lines (49 loc) · 1.93 KB
/
ShortHash.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* Copyright (c) Terl Tech Ltd • 01/04/2021, 12:31 • goterl.com
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.goterl.lazysodium.interfaces;
import com.goterl.lazysodium.exceptions.SodiumException;
import com.goterl.lazysodium.utils.Key;
public interface ShortHash {
int SIPHASH24_BYTES = 8,
SIPHASH24_KEYBYTES = 16,
SIPHASHX24_BYTES = 16,
SIPHASHX24_KEYBYTES = 16,
BYTES = SIPHASH24_BYTES,
KEYBYTES = SIPHASH24_KEYBYTES;
interface Native {
/**
* Short-input hash some text.
* @param out The hashed text of size {@link #SIPHASH24_BYTES} or
* {@link #SIPHASHX24_BYTES} depending on {@code in} size.
* @param in The short-input text to hash of size {@link #BYTES} or of size {@link #SIPHASHX24_BYTES}.
* @param inLen The length of the short-input.
* @param key The key generated via {@link #cryptoShortHashKeygen(byte[])}.
* @return true if success, false if fail.
*/
boolean cryptoShortHash(byte[] out, byte[] in, long inLen, byte[] key);
/**
* Output a 64-bit key.
* @param k The key of size {@link #SIPHASH24_KEYBYTES}.
*/
void cryptoShortHashKeygen(byte[] k);
}
interface Lazy {
/**
* Generate a 64-bit key for short-input hashing.
* @return Key in string format.
*/
Key cryptoShortHashKeygen();
/**
* Hash a short message using a key.
* @param in The short message to hash.
* @param key The key generated via {@link #cryptoShortHashKeygen()}.
* @return Your message hashed of size {@link #BYTES}.
*/
String cryptoShortHash(String in, Key key) throws SodiumException;
}
}