use of com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat in project tink by google.
the class StreamingAeadKeyTemplatesTest method testAES256_CTR_HMAC_SHA256_4KB.
@Test
public void testAES256_CTR_HMAC_SHA256_4KB() throws Exception {
KeyTemplate template = StreamingAeadKeyTemplates.AES256_CTR_HMAC_SHA256_4KB;
assertEquals(AesCtrHmacStreamingKeyManager.TYPE_URL, template.getTypeUrl());
assertEquals(OutputPrefixType.RAW, template.getOutputPrefixType());
AesCtrHmacStreamingKeyFormat format = AesCtrHmacStreamingKeyFormat.parseFrom(template.getValue());
assertEquals(32, format.getKeySize());
assertEquals(32, format.getParams().getDerivedKeySize());
assertEquals(HashType.SHA256, format.getParams().getHkdfHashType());
assertEquals(4096, format.getParams().getCiphertextSegmentSize());
assertEquals(HashType.SHA256, format.getParams().getHmacParams().getHash());
assertEquals(32, format.getParams().getHmacParams().getTagSize());
}
use of com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat in project tink by google.
the class AesCtrHmacStreamingKeyManager method newKey.
/**
* @param keyFormat {@code AesCtrHmacStreamingKeyFormat} proto
* @return new {@code AesCtrHmacStreamingKey} proto
*/
@Override
public MessageLite newKey(MessageLite keyFormat) throws GeneralSecurityException {
if (!(keyFormat instanceof AesCtrHmacStreamingKeyFormat)) {
throw new GeneralSecurityException("expected AesCtrHmacStreamingKeyFormat proto");
}
AesCtrHmacStreamingKeyFormat format = (AesCtrHmacStreamingKeyFormat) keyFormat;
validate(format);
return AesCtrHmacStreamingKey.newBuilder().setKeyValue(ByteString.copyFrom(Random.randBytes(format.getKeySize()))).setParams(format.getParams()).setVersion(VERSION).build();
}
use of com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat in project tink by google.
the class AesCtrHmacStreamingKeyManagerTest method testAes128CtrHmacSha2564KBTemplate.
@Test
public void testAes128CtrHmacSha2564KBTemplate() throws Exception {
KeyTemplate template = AesCtrHmacStreamingKeyManager.aes128CtrHmacSha2564KBTemplate();
assertThat(template.getTypeUrl()).isEqualTo(new AesCtrHmacStreamingKeyManager().getKeyType());
assertThat(template.getOutputPrefixType()).isEqualTo(KeyTemplate.OutputPrefixType.RAW);
AesCtrHmacStreamingKeyFormat format = AesCtrHmacStreamingKeyFormat.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().getHmacParams().getHash()).isEqualTo(HashType.SHA256);
assertThat(format.getParams().getHmacParams().getTagSize()).isEqualTo(32);
assertThat(format.getParams().getCiphertextSegmentSize()).isEqualTo(4096);
}
use of com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat in project tink by google.
the class AesCtrHmacStreamingKeyManagerTest method testAes256CtrHmacSha2564KBTemplate.
@Test
public void testAes256CtrHmacSha2564KBTemplate() throws Exception {
KeyTemplate template = AesCtrHmacStreamingKeyManager.aes256CtrHmacSha2564KBTemplate();
assertThat(template.getTypeUrl()).isEqualTo(new AesCtrHmacStreamingKeyManager().getKeyType());
assertThat(template.getOutputPrefixType()).isEqualTo(KeyTemplate.OutputPrefixType.RAW);
AesCtrHmacStreamingKeyFormat format = AesCtrHmacStreamingKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
assertThat(format.getKeySize()).isEqualTo(32);
assertThat(format.getParams().getDerivedKeySize()).isEqualTo(32);
assertThat(format.getParams().getHkdfHashType()).isEqualTo(HashType.SHA256);
assertThat(format.getParams().getHmacParams().getHash()).isEqualTo(HashType.SHA256);
assertThat(format.getParams().getHmacParams().getTagSize()).isEqualTo(32);
assertThat(format.getParams().getCiphertextSegmentSize()).isEqualTo(4096);
}
use of com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat in project tink by google.
the class AesCtrHmacStreamingKeyManagerTest method validateKeyFormat_valid.
@Test
public void validateKeyFormat_valid() throws Exception {
AesCtrHmacStreamingKeyFormat format = createKeyFormat().build();
factory.validateKeyFormat(format);
}
Aggregations