use of com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat in project tink by google.
the class StreamingAeadKeyTemplatesTest method testAES128_GCM_HKDF_4KB.
@Test
public void testAES128_GCM_HKDF_4KB() throws Exception {
KeyTemplate template = StreamingAeadKeyTemplates.AES128_GCM_HKDF_4KB;
assertEquals(AesGcmHkdfStreamingKeyManager.TYPE_URL, template.getTypeUrl());
assertEquals(OutputPrefixType.RAW, template.getOutputPrefixType());
AesGcmHkdfStreamingKeyFormat format = AesGcmHkdfStreamingKeyFormat.parseFrom(template.getValue());
assertEquals(16, format.getKeySize());
assertEquals(16, format.getParams().getDerivedKeySize());
assertEquals(HashType.SHA256, format.getParams().getHkdfHashType());
assertEquals(4096, format.getParams().getCiphertextSegmentSize());
}
use of com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat in project tink by google.
the class AesGcmHkdfStreamingKeyManager method newKey.
/**
* @param keyFormat {@code AesGcmHkdfStreamingKeyFormat} proto
* @return new {@code AesGcmHkdfStreamingKey} proto
*/
@Override
public MessageLite newKey(MessageLite keyFormat) throws GeneralSecurityException {
if (!(keyFormat instanceof AesGcmHkdfStreamingKeyFormat)) {
throw new GeneralSecurityException("expected AesGcmHkdfStreamingKeyFormat proto");
}
AesGcmHkdfStreamingKeyFormat format = (AesGcmHkdfStreamingKeyFormat) keyFormat;
validate(format);
return AesGcmHkdfStreamingKey.newBuilder().setKeyValue(ByteString.copyFrom(Random.randBytes(format.getKeySize()))).setParams(format.getParams()).setVersion(VERSION).build();
}
use of com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat in project tink by google.
the class StreamingAeadKeyTemplatesTest method testAes256GcmHkdf_1MB.
@Test
public void testAes256GcmHkdf_1MB() throws Exception {
KeyTemplate template = StreamingAeadKeyTemplates.AES256_GCM_HKDF_1MB;
assertEquals(new AesGcmHkdfStreamingKeyManager().getKeyType(), template.getTypeUrl());
assertEquals(OutputPrefixType.RAW, template.getOutputPrefixType());
AesGcmHkdfStreamingKeyFormat format = AesGcmHkdfStreamingKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
assertEquals(32, format.getKeySize());
assertEquals(32, format.getParams().getDerivedKeySize());
assertEquals(HashType.SHA256, format.getParams().getHkdfHashType());
assertEquals(1048576, format.getParams().getCiphertextSegmentSize());
}
use of com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat in project tink by google.
the class StreamingAeadKeyTemplatesTest method testAes128GcmHkdf_1MB.
@Test
public void testAes128GcmHkdf_1MB() throws Exception {
KeyTemplate template = StreamingAeadKeyTemplates.AES128_GCM_HKDF_1MB;
assertEquals(new AesGcmHkdfStreamingKeyManager().getKeyType(), template.getTypeUrl());
assertEquals(OutputPrefixType.RAW, template.getOutputPrefixType());
AesGcmHkdfStreamingKeyFormat format = AesGcmHkdfStreamingKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
assertEquals(16, format.getKeySize());
assertEquals(16, format.getParams().getDerivedKeySize());
assertEquals(HashType.SHA256, format.getParams().getHkdfHashType());
assertEquals(1048576, format.getParams().getCiphertextSegmentSize());
}
use of com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat in project tink by google.
the class AesGcmHkdfStreamingKeyManagerTest method testAes128GcmHkdf1MBTemplate.
@Test
public void testAes128GcmHkdf1MBTemplate() throws Exception {
KeyTemplate template = AesGcmHkdfStreamingKeyManager.aes128GcmHkdf1MBTemplate();
assertThat(template.getTypeUrl()).isEqualTo(new AesGcmHkdfStreamingKeyManager().getKeyType());
assertThat(template.getOutputPrefixType()).isEqualTo(KeyTemplate.OutputPrefixType.RAW);
AesGcmHkdfStreamingKeyFormat format = AesGcmHkdfStreamingKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
assertThat(format.getKeySize()).isEqualTo(16);
assertThat(format.getParams().getDerivedKeySize()).isEqualTo(16);
assertThat(format.getParams().getHkdfHashType()).isEqualTo(HashType.SHA256);
assertThat(format.getParams().getCiphertextSegmentSize()).isEqualTo(1 << 20);
}
Aggregations