use of com.google.crypto.tink.proto.HmacPrfKeyFormat in project tink by google.
the class HmacPrfKeyManagerTest method testHmacSha256Template.
@Test
public void testHmacSha256Template() throws Exception {
KeyTemplate template = HmacPrfKeyManager.hmacSha256Template();
assertThat(template.getTypeUrl()).isEqualTo(new HmacPrfKeyManager().getKeyType());
assertThat(template.getOutputPrefixType()).isEqualTo(KeyTemplate.OutputPrefixType.RAW);
HmacPrfKeyFormat format = HmacPrfKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
assertThat(format.getKeySize()).isEqualTo(32);
assertThat(format.getParams().getHash()).isEqualTo(HashType.SHA256);
}
use of com.google.crypto.tink.proto.HmacPrfKeyFormat in project tink by google.
the class HmacPrfKeyManagerTest method createKey_checkValues.
@Test
public void createKey_checkValues() throws Exception {
HmacPrfKeyFormat keyFormat = makeHmacPrfKeyFormat(16, HashType.SHA256);
HmacPrfKey key = factory.createKey(keyFormat);
assertThat(key.getKeyValue()).hasSize(keyFormat.getKeySize());
assertThat(key.getParams().getHash()).isEqualTo(keyFormat.getParams().getHash());
}
use of com.google.crypto.tink.proto.HmacPrfKeyFormat in project tink by google.
the class HmacPrfKeyManagerTest method testDeriveKey_badVersion_throws.
@Test
public void testDeriveKey_badVersion_throws() throws Exception {
final int keySize = 32;
byte[] keyMaterial = Random.randBytes(100);
HmacPrfParams params = HmacPrfParams.newBuilder().setHash(HashType.SHA256).build();
HmacPrfKeyFormat format = HmacPrfKeyFormat.newBuilder().setVersion(1).setParams(params).setKeySize(keySize).build();
assertThrows(GeneralSecurityException.class, () -> factory.deriveKey(format, new ByteArrayInputStream(keyMaterial)));
}
use of com.google.crypto.tink.proto.HmacPrfKeyFormat in project tink by google.
the class HmacPrfKeyManager method createTemplate.
/**
* @return a {@link KeyTemplate} containing a {@link HmacKeyFormat} with some specified
* parameters.
*/
private static KeyTemplate createTemplate(int keySize, HashType hashType) {
HmacPrfParams params = HmacPrfParams.newBuilder().setHash(hashType).build();
HmacPrfKeyFormat format = HmacPrfKeyFormat.newBuilder().setParams(params).setKeySize(keySize).build();
return KeyTemplate.create(new HmacPrfKeyManager().getKeyType(), format.toByteArray(), KeyTemplate.OutputPrefixType.RAW);
}
Aggregations