Skip to content

Commit d21a726

Browse files
committed
Add HMAC length tests
1 parent 578880c commit d21a726

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.eatthepath.noise.crypto;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import javax.crypto.Mac;
6+
import javax.crypto.spec.SecretKeySpec;
7+
8+
import java.security.InvalidKeyException;
9+
import java.security.Key;
10+
11+
import static org.junit.jupiter.api.Assertions.assertEquals;
12+
13+
abstract class AbstractBlake2HmacTest {
14+
15+
protected abstract Mac getHmac();
16+
17+
@Test
18+
void getMacLength() throws InvalidKeyException {
19+
final Key key = new SecretKeySpec(new byte[32], "RAW");
20+
21+
final Mac hmac = getHmac();
22+
hmac.init(key);
23+
hmac.update(new byte[32]);
24+
25+
assertEquals(hmac.getMacLength(), hmac.doFinal().length);
26+
}
27+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.eatthepath.noise.crypto;
2+
3+
import javax.crypto.Mac;
4+
5+
class HmacBlake2b512MacTest extends AbstractBlake2HmacTest {
6+
7+
@Override
8+
protected Mac getHmac() {
9+
return new HmacBlake2b512Mac();
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.eatthepath.noise.crypto;
2+
3+
import javax.crypto.Mac;
4+
5+
class HmacBlake2s256MacTest extends AbstractBlake2HmacTest {
6+
7+
@Override
8+
protected Mac getHmac() {
9+
return new HmacBlake2s256Mac();
10+
}
11+
}

0 commit comments

Comments
 (0)