Search in sources :

Example 1 with StreamingAead

use of com.google.crypto.tink.StreamingAead in project tink by google.

the class AesCtrHmacStreamingKeyManagerTest method testBasic.

@Test
public void testBasic() throws Exception {
    // Create primitive from a given key.
    AesCtrHmacStreamingKey key = AesCtrHmacStreamingKey.newBuilder().setVersion(0).setKeyValue(ByteString.copyFrom(Random.randBytes(20))).setParams(keyParams).build();
    StreamingAead streamingAead = keyManager.getPrimitive(key);
    StreamingTestUtil.testEncryptionAndDecryption(streamingAead);
    // Create a key from KeyFormat, and use the key.
    AesCtrHmacStreamingKeyFormat keyFormat = AesCtrHmacStreamingKeyFormat.newBuilder().setParams(keyParams).setKeySize(16).build();
    ByteString serializedKeyFormat = ByteString.copyFrom(keyFormat.toByteArray());
    key = (AesCtrHmacStreamingKey) keyManager.newKey(serializedKeyFormat);
    streamingAead = keyManager.getPrimitive(key);
    StreamingTestUtil.testEncryptionAndDecryption(streamingAead);
}
Also used : AesCtrHmacStreamingKey(com.google.crypto.tink.proto.AesCtrHmacStreamingKey) ByteString(com.google.protobuf.ByteString) AesCtrHmacStreamingKeyFormat(com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat) StreamingAead(com.google.crypto.tink.StreamingAead) Test(org.junit.Test)

Example 2 with StreamingAead

use of com.google.crypto.tink.StreamingAead in project tink by google.

the class StreamingAeadFactoryTest method testBasicAesCtrHmacStreamingAead.

@Test
public void testBasicAesCtrHmacStreamingAead() throws Exception {
    byte[] keyValue = Random.randBytes(AES_KEY_SIZE);
    int derivedKeySize = AES_KEY_SIZE;
    int ciphertextSegmentSize = 128;
    KeysetHandle keysetHandle = TestUtil.createKeysetHandle(TestUtil.createKeyset(TestUtil.createKey(TestUtil.createAesCtrHmacStreamingKeyData(keyValue, derivedKeySize, ciphertextSegmentSize), 42, KeyStatusType.ENABLED, OutputPrefixType.RAW)));
    StreamingAead streamingAead = StreamingAeadFactory.getPrimitive(keysetHandle);
    StreamingTestUtil.testEncryptionAndDecryption(streamingAead);
}
Also used : KeysetHandle(com.google.crypto.tink.KeysetHandle) StreamingAead(com.google.crypto.tink.StreamingAead) Test(org.junit.Test)

Example 3 with StreamingAead

use of com.google.crypto.tink.StreamingAead in project tink by google.

the class AesGcmHkdfStreamingKeyManagerTest method testBasic.

@Test
public void testBasic() throws Exception {
    // Create primitive from a given key.
    AesGcmHkdfStreamingKey key = AesGcmHkdfStreamingKey.newBuilder().setVersion(0).setKeyValue(ByteString.copyFrom(Random.randBytes(20))).setParams(keyParams).build();
    StreamingAead streamingAead = keyManager.getPrimitive(key);
    StreamingTestUtil.testEncryptionAndDecryption(streamingAead);
    // Create a key from KeyFormat, and use the key.
    AesGcmHkdfStreamingKeyFormat keyFormat = AesGcmHkdfStreamingKeyFormat.newBuilder().setParams(keyParams).setKeySize(16).build();
    ByteString serializedKeyFormat = ByteString.copyFrom(keyFormat.toByteArray());
    key = (AesGcmHkdfStreamingKey) keyManager.newKey(serializedKeyFormat);
    streamingAead = keyManager.getPrimitive(key);
    StreamingTestUtil.testEncryptionAndDecryption(streamingAead);
}
Also used : AesGcmHkdfStreamingKey(com.google.crypto.tink.proto.AesGcmHkdfStreamingKey) AesGcmHkdfStreamingKeyFormat(com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat) ByteString(com.google.protobuf.ByteString) StreamingAead(com.google.crypto.tink.StreamingAead) Test(org.junit.Test)

Example 4 with StreamingAead

use of com.google.crypto.tink.StreamingAead in project tink by google.

the class StreamingAeadCatalogueTest method testBasic.

@Test
public void testBasic() throws Exception {
    StreamingAeadCatalogue catalogue = new StreamingAeadCatalogue();
    // Check a single key type, incl. case-insensitve primitive name.
    String keyType = "type.googleapis.com/google.crypto.tink.AesGcmHkdfStreamingKey";
    {
        KeyManager<StreamingAead> manager = catalogue.getKeyManager(keyType, "StreamingAead", 0);
        assertThat(manager.doesSupport(keyType)).isTrue();
    }
    {
        KeyManager<StreamingAead> manager = catalogue.getKeyManager(keyType, "STReaMIngAeAD", 0);
        assertThat(manager.doesSupport(keyType)).isTrue();
    }
    {
        KeyManager<StreamingAead> manager = catalogue.getKeyManager(keyType, "STREAMINgaEAD", 0);
        assertThat(manager.doesSupport(keyType)).isTrue();
    }
    // Check all entries from the current StreamingAeadConfig.
    RegistryConfig config = StreamingAeadConfig.TINK_1_1_0;
    int count = 0;
    for (KeyTypeEntry entry : config.getEntryList()) {
        if ("StreamingAead".equals(entry.getPrimitiveName())) {
            count = count + 1;
            KeyManager<StreamingAead> manager = catalogue.getKeyManager(entry.getTypeUrl(), "streamingaead", entry.getKeyManagerVersion());
            assertThat(manager.doesSupport(entry.getTypeUrl())).isTrue();
        }
    }
    assertEquals(2, count);
}
Also used : RegistryConfig(com.google.crypto.tink.proto.RegistryConfig) KeyTypeEntry(com.google.crypto.tink.proto.KeyTypeEntry) KeyManager(com.google.crypto.tink.KeyManager) StreamingAead(com.google.crypto.tink.StreamingAead) Test(org.junit.Test)

Example 5 with StreamingAead

use of com.google.crypto.tink.StreamingAead in project tink by google.

the class StreamingAeadFactoryTest method testBasicAesGcmHkdfStreamingAead.

@Test
public void testBasicAesGcmHkdfStreamingAead() throws Exception {
    byte[] keyValue = Random.randBytes(AES_KEY_SIZE);
    int derivedKeySize = AES_KEY_SIZE;
    int ciphertextSegmentSize = 128;
    KeysetHandle keysetHandle = TestUtil.createKeysetHandle(TestUtil.createKeyset(TestUtil.createKey(TestUtil.createAesGcmHkdfStreamingKeyData(keyValue, derivedKeySize, ciphertextSegmentSize), 42, KeyStatusType.ENABLED, OutputPrefixType.RAW)));
    StreamingAead streamingAead = StreamingAeadFactory.getPrimitive(keysetHandle);
    StreamingTestUtil.testEncryptionAndDecryption(streamingAead);
}
Also used : KeysetHandle(com.google.crypto.tink.KeysetHandle) StreamingAead(com.google.crypto.tink.StreamingAead) Test(org.junit.Test)

Aggregations

StreamingAead (com.google.crypto.tink.StreamingAead)8 Test (org.junit.Test)6 KeysetHandle (com.google.crypto.tink.KeysetHandle)3 IOException (java.io.IOException)3 PrimitiveSet (com.google.crypto.tink.PrimitiveSet)2 ByteString (com.google.protobuf.ByteString)2 GeneralSecurityException (java.security.GeneralSecurityException)2 GuardedBy (javax.annotation.concurrent.GuardedBy)2 KeyManager (com.google.crypto.tink.KeyManager)1 AesCtrHmacStreamingKey (com.google.crypto.tink.proto.AesCtrHmacStreamingKey)1 AesCtrHmacStreamingKeyFormat (com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat)1 AesGcmHkdfStreamingKey (com.google.crypto.tink.proto.AesGcmHkdfStreamingKey)1 AesGcmHkdfStreamingKeyFormat (com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat)1 KeyTypeEntry (com.google.crypto.tink.proto.KeyTypeEntry)1 Key (com.google.crypto.tink.proto.Keyset.Key)1 RegistryConfig (com.google.crypto.tink.proto.RegistryConfig)1 RewindableReadableByteChannel (com.google.crypto.tink.subtle.RewindableReadableByteChannel)1 ReadableByteChannel (java.nio.channels.ReadableByteChannel)1 SeekableByteChannel (java.nio.channels.SeekableByteChannel)1