use of com.google.crypto.tink.proto.HmacKeyFormat in project tink by google.
the class MacKeyTemplates method createHmacKeyTemplate.
/**
* @return a {@link KeyTemplate} containing a {@link HmacKeyFormat} with some specified
* parameters.
*/
public static KeyTemplate createHmacKeyTemplate(int keySize, int tagSize, HashType hashType) {
HmacParams params = HmacParams.newBuilder().setHash(hashType).setTagSize(tagSize).build();
HmacKeyFormat format = HmacKeyFormat.newBuilder().setParams(params).setKeySize(keySize).build();
return KeyTemplate.newBuilder().setValue(format.toByteString()).setTypeUrl(HmacKeyManager.TYPE_URL).setOutputPrefixType(OutputPrefixType.TINK).build();
}
use of com.google.crypto.tink.proto.HmacKeyFormat in project tink by google.
the class MacKeyTemplatesTest method testCreateHmacKeyTemplate.
@Test
public void testCreateHmacKeyTemplate() throws Exception {
// Intentionally using "weird" or invalid values for parameters,
// to test that the function correctly puts them in the resulting template.
int keySize = 42;
int tagSize = 24;
HashType hashType = HashType.SHA512;
KeyTemplate template = MacKeyTemplates.createHmacKeyTemplate(keySize, tagSize, hashType);
assertEquals(HmacKeyManager.TYPE_URL, template.getTypeUrl());
assertEquals(OutputPrefixType.TINK, template.getOutputPrefixType());
HmacKeyFormat format = HmacKeyFormat.parseFrom(template.getValue());
assertEquals(keySize, format.getKeySize());
assertEquals(tagSize, format.getParams().getTagSize());
assertEquals(hashType, format.getParams().getHash());
}
use of com.google.crypto.tink.proto.HmacKeyFormat in project tink by google.
the class MacKeyTemplatesTest method testHMAC_SHA256_128BITTAG.
@Test
public void testHMAC_SHA256_128BITTAG() throws Exception {
KeyTemplate template = MacKeyTemplates.HMAC_SHA256_128BITTAG;
assertEquals(HmacKeyManager.TYPE_URL, template.getTypeUrl());
assertEquals(OutputPrefixType.TINK, template.getOutputPrefixType());
HmacKeyFormat format = HmacKeyFormat.parseFrom(template.getValue());
assertEquals(32, format.getKeySize());
assertEquals(16, format.getParams().getTagSize());
assertEquals(HashType.SHA256, format.getParams().getHash());
}
Aggregations