use of com.google.crypto.tink.proto.HmacPrfKey in project tink by google.
the class HmacPrfKeyManagerTest method getPrimitive_worksForSha256.
@Test
public void getPrimitive_worksForSha256() throws Exception {
HmacPrfKey validKey = factory.createKey(makeHmacPrfKeyFormat(16, HashType.SHA256));
Prf managerPrf = manager.getPrimitive(validKey, Prf.class);
Prf directPrf = new PrfHmacJce("HMACSHA256", new SecretKeySpec(validKey.getKeyValue().toByteArray(), "HMAC"));
byte[] message = Random.randBytes(50);
assertThat(managerPrf.compute(message, 29)).isEqualTo(directPrf.compute(message, 29));
}
use of com.google.crypto.tink.proto.HmacPrfKey in project tink by google.
the class HmacPrfKeyManagerTest method getPrimitive_worksForSha512.
@Test
public void getPrimitive_worksForSha512() throws Exception {
HmacPrfKey validKey = factory.createKey(makeHmacPrfKeyFormat(16, HashType.SHA512));
Prf managerPrf = manager.getPrimitive(validKey, Prf.class);
Prf directPrf = new PrfHmacJce("HMACSHA512", new SecretKeySpec(validKey.getKeyValue().toByteArray(), "HMAC"));
byte[] message = Random.randBytes(50);
assertThat(managerPrf.compute(message, 33)).isEqualTo(directPrf.compute(message, 33));
}
use of com.google.crypto.tink.proto.HmacPrfKey in project tink by google.
the class HmacPrfKeyManagerTest method testDeriveKey_size27.
@Test
public void testDeriveKey_size27() throws Exception {
final int keySize = 27;
byte[] keyMaterial = Random.randBytes(100);
HmacPrfParams params = HmacPrfParams.newBuilder().setHash(HashType.SHA256).build();
HmacPrfKey key = factory.deriveKey(HmacPrfKeyFormat.newBuilder().setVersion(0).setParams(params).setKeySize(keySize).build(), new ByteArrayInputStream(keyMaterial));
assertThat(key.getKeyValue()).hasSize(keySize);
for (int i = 0; i < keySize; ++i) {
assertThat(key.getKeyValue().byteAt(i)).isEqualTo(keyMaterial[i]);
}
assertThat(key.getParams()).isEqualTo(params);
}
use of com.google.crypto.tink.proto.HmacPrfKey in project tink by google.
the class HmacPrfKeyManagerTest method getPrimitive_worksForSha1.
@Test
public void getPrimitive_worksForSha1() throws Exception {
HmacPrfKey validKey = factory.createKey(makeHmacPrfKeyFormat(16, HashType.SHA1));
Prf managerPrf = manager.getPrimitive(validKey, Prf.class);
Prf directPrf = new PrfHmacJce("HMACSHA1", new SecretKeySpec(validKey.getKeyValue().toByteArray(), "HMAC"));
byte[] message = Random.randBytes(50);
assertThat(managerPrf.compute(message, 19)).isEqualTo(directPrf.compute(message, 19));
}
use of com.google.crypto.tink.proto.HmacPrfKey in project tink by google.
the class HmacPrfKeyManagerTest method testDeriveKey_justEnoughKeyMaterial.
@Test
public void testDeriveKey_justEnoughKeyMaterial() throws Exception {
final int keySize = 32;
byte[] keyMaterial = Random.randBytes(keySize);
HmacPrfParams params = HmacPrfParams.newBuilder().setHash(HashType.SHA256).build();
HmacPrfKey key = factory.deriveKey(HmacPrfKeyFormat.newBuilder().setVersion(0).setParams(params).setKeySize(keySize).build(), new ByteArrayInputStream(keyMaterial));
assertThat(key.getKeyValue()).hasSize(keySize);
for (int i = 0; i < keySize; ++i) {
assertThat(key.getKeyValue().byteAt(i)).isEqualTo(keyMaterial[i]);
}
}
Aggregations