Search in sources :

Example 1 with AesSivKeyFormat

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());
}
Also used : AesSivKeyFormat(com.google.crypto.tink.proto.AesSivKeyFormat) KeyTemplate(com.google.crypto.tink.proto.KeyTemplate) Test(org.junit.Test)

Example 2 with AesSivKeyFormat

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();
}
Also used : GeneralSecurityException(java.security.GeneralSecurityException) AesSivKeyFormat(com.google.crypto.tink.proto.AesSivKeyFormat)

Example 3 with AesSivKeyFormat

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());
}
Also used : AesSivKeyFormat(com.google.crypto.tink.proto.AesSivKeyFormat) KeyTemplate(com.google.crypto.tink.proto.KeyTemplate) Test(org.junit.Test)

Aggregations

AesSivKeyFormat (com.google.crypto.tink.proto.AesSivKeyFormat)3 KeyTemplate (com.google.crypto.tink.proto.KeyTemplate)2 Test (org.junit.Test)2 GeneralSecurityException (java.security.GeneralSecurityException)1