Search in sources :

Example 6 with AesCtrHmacStreamingKeyFormat

use of com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat in project tink by google.

the class AesCtrHmacStreamingKeyManagerTest method testAes256CtrHmacSha2561MBTemplate.

@Test
public void testAes256CtrHmacSha2561MBTemplate() throws Exception {
    KeyTemplate template = AesCtrHmacStreamingKeyManager.aes256CtrHmacSha2561MBTemplate();
    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(1 << 20);
}
Also used : AesCtrHmacStreamingKeyFormat(com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Example 7 with AesCtrHmacStreamingKeyFormat

use of com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat in project tink by google.

the class AesCtrHmacStreamingKeyManagerTest method validateKeyFormat_tagSizeTooBigSha512_throws.

@Test
public void validateKeyFormat_tagSizeTooBigSha512_throws() throws Exception {
    AesCtrHmacStreamingKeyFormat format = createKeyFormat().setParams(createParams().setHmacParams(createHmacParams().setHash(HashType.SHA512).setTagSize(65))).build();
    assertThrows(GeneralSecurityException.class, () -> factory.validateKeyFormat(format));
}
Also used : AesCtrHmacStreamingKeyFormat(com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat) Test(org.junit.Test)

Example 8 with AesCtrHmacStreamingKeyFormat

use of com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat in project tink by google.

the class AesCtrHmacStreamingKeyManagerTest method testSkip.

@Test
public void testSkip() throws Exception {
    AesCtrHmacStreamingKeyFormat format = createKeyFormat().build();
    AesCtrHmacStreamingKey key = factory.createKey(format);
    StreamingAead streamingAead = manager.getPrimitive(key, StreamingAead.class);
    int offset = 0;
    int plaintextSize = 1 << 16;
    // Runs the test with different sizes for the chunks to skip.
    StreamingTestUtil.testSkipWithStream(streamingAead, offset, plaintextSize, 1);
    StreamingTestUtil.testSkipWithStream(streamingAead, offset, plaintextSize, 64);
    StreamingTestUtil.testSkipWithStream(streamingAead, offset, plaintextSize, 300);
}
Also used : AesCtrHmacStreamingKey(com.google.crypto.tink.proto.AesCtrHmacStreamingKey) AesCtrHmacStreamingKeyFormat(com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat) StreamingAead(com.google.crypto.tink.StreamingAead) Test(org.junit.Test)

Example 9 with AesCtrHmacStreamingKeyFormat

use of com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat in project tink by google.

the class AesCtrHmacStreamingKeyManagerTest method validateKeyFormat_smallSegment_throws.

@Test
public void validateKeyFormat_smallSegment_throws() throws Exception {
    AesCtrHmacStreamingKeyFormat format = createKeyFormat().setParams(createParams().setCiphertextSegmentSize(45)).build();
    assertThrows(GeneralSecurityException.class, () -> factory.validateKeyFormat(format));
}
Also used : AesCtrHmacStreamingKeyFormat(com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat) Test(org.junit.Test)

Example 10 with AesCtrHmacStreamingKeyFormat

use of com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat in project tink by google.

the class AesCtrHmacStreamingKeyManagerTest method validateKeyFormat_tagSizeTooBigSha256_throws.

@Test
public void validateKeyFormat_tagSizeTooBigSha256_throws() throws Exception {
    AesCtrHmacStreamingKeyFormat format = createKeyFormat().setParams(createParams().setHmacParams(createHmacParams().setHash(HashType.SHA256).setTagSize(33))).build();
    assertThrows(GeneralSecurityException.class, () -> factory.validateKeyFormat(format));
}
Also used : AesCtrHmacStreamingKeyFormat(com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat) Test(org.junit.Test)

Aggregations

AesCtrHmacStreamingKeyFormat (com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat)28 Test (org.junit.Test)25 KeyTemplate (com.google.crypto.tink.proto.KeyTemplate)7 AesCtrHmacStreamingKey (com.google.crypto.tink.proto.AesCtrHmacStreamingKey)5 KeyTemplate (com.google.crypto.tink.KeyTemplate)4 ByteString (com.google.protobuf.ByteString)3 StreamingAead (com.google.crypto.tink.StreamingAead)2 AesCtrHmacStreamingParams (com.google.crypto.tink.proto.AesCtrHmacStreamingParams)2 TreeSet (java.util.TreeSet)2 HashType (com.google.crypto.tink.proto.HashType)1 HmacParams (com.google.crypto.tink.proto.HmacParams)1 KeyData (com.google.crypto.tink.proto.KeyData)1 GeneralSecurityException (java.security.GeneralSecurityException)1