Skip to content

Commit

Permalink
Add HMAC length tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jchambers committed Mar 3, 2024
1 parent 578880c commit d21a726
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.eatthepath.noise.crypto;

import org.junit.jupiter.api.Test;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

import java.security.InvalidKeyException;
import java.security.Key;

import static org.junit.jupiter.api.Assertions.assertEquals;

abstract class AbstractBlake2HmacTest {

protected abstract Mac getHmac();

@Test
void getMacLength() throws InvalidKeyException {
final Key key = new SecretKeySpec(new byte[32], "RAW");

final Mac hmac = getHmac();
hmac.init(key);
hmac.update(new byte[32]);

assertEquals(hmac.getMacLength(), hmac.doFinal().length);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.eatthepath.noise.crypto;

import javax.crypto.Mac;

class HmacBlake2b512MacTest extends AbstractBlake2HmacTest {

@Override
protected Mac getHmac() {
return new HmacBlake2b512Mac();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.eatthepath.noise.crypto;

import javax.crypto.Mac;

class HmacBlake2s256MacTest extends AbstractBlake2HmacTest {

@Override
protected Mac getHmac() {
return new HmacBlake2s256Mac();
}
}

0 comments on commit d21a726

Please sign in to comment.