use of com.google.crypto.tink.proto.AesSivKeyFormat in project tink by google.
the class DeterministicAeadKeyTemplatesTest method testCreateAesSivKeyTemplate.
@Test
public void testCreateAesSivKeyTemplate() 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;
KeyTemplate template = DeterministicAeadKeyTemplates.createAesSivKeyTemplate(keySize);
assertEquals(AesSivKeyManager.TYPE_URL, template.getTypeUrl());
assertEquals(OutputPrefixType.TINK, template.getOutputPrefixType());
AesSivKeyFormat format = AesSivKeyFormat.parseFrom(template.getValue());
assertEquals(keySize, format.getKeySize());
}
use of com.google.crypto.tink.proto.AesSivKeyFormat in project tink by google.
the class AesSivKeyManager method newKey.
/**
* @param keyFormat {@code AesSivKeyFormat} proto
* @return new {@code AesSivKey} proto
*/
@Override
public MessageLite newKey(MessageLite keyFormat) throws GeneralSecurityException {
if (!(keyFormat instanceof AesSivKeyFormat)) {
throw new GeneralSecurityException("expected AesSivKeyFormat proto");
}
AesSivKeyFormat format = (AesSivKeyFormat) keyFormat;
validate(format);
return AesSivKey.newBuilder().setKeyValue(ByteString.copyFrom(Random.randBytes(format.getKeySize()))).setVersion(VERSION).build();
}
use of com.google.crypto.tink.proto.AesSivKeyFormat in project tink by google.
the class DeterministicAeadKeyTemplatesTest method testAES256_SIV.
@Test
public void testAES256_SIV() throws Exception {
KeyTemplate template = DeterministicAeadKeyTemplates.AES256_SIV;
assertEquals(AesSivKeyManager.TYPE_URL, template.getTypeUrl());
assertEquals(OutputPrefixType.TINK, template.getOutputPrefixType());
AesSivKeyFormat format = AesSivKeyFormat.parseFrom(template.getValue());
assertEquals(64, format.getKeySize());
}
Aggregations