Search in sources :

Example 1 with HkdfPrfKey

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

the class HkdfPrfKeyManagerTest method createPrimitive_works.

@Test
public void createPrimitive_works() throws Exception {
    HkdfPrfKey key = HkdfPrfKey.newBuilder().setKeyValue(ByteString.copyFromUtf8("super secret key value")).setParams(HkdfPrfParams.newBuilder().setSalt(ByteString.copyFromUtf8("some salt")).setHash(HashType.SHA256)).build();
    StreamingPrf managerPrf = manager.getPrimitive(key, StreamingPrf.class);
    InputStream managerInput = managerPrf.computePrf("my input".getBytes(UTF_8));
    byte[] managerOutput = new byte[10];
    assertThat(managerInput.read(managerOutput)).isEqualTo(10);
    HkdfStreamingPrf directPrf = new HkdfStreamingPrf(Enums.HashType.SHA256, "super secret key value".getBytes(UTF_8), "some salt".getBytes(UTF_8));
    InputStream directInput = directPrf.computePrf("my input".getBytes(UTF_8));
    byte[] directOutput = new byte[10];
    assertThat(directInput.read(directOutput)).isEqualTo(10);
    assertThat(directOutput).isEqualTo(managerOutput);
}
Also used : HkdfStreamingPrf(com.google.crypto.tink.subtle.prf.HkdfStreamingPrf) StreamingPrf(com.google.crypto.tink.subtle.prf.StreamingPrf) HkdfStreamingPrf(com.google.crypto.tink.subtle.prf.HkdfStreamingPrf) InputStream(java.io.InputStream) HkdfPrfKey(com.google.crypto.tink.proto.HkdfPrfKey) Test(org.junit.Test)

Example 2 with HkdfPrfKey

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

the class HkdfPrfKeyManagerTest method validateKey_empty_throws.

@Test
public void validateKey_empty_throws() throws Exception {
    HkdfPrfKey key = HkdfPrfKey.getDefaultInstance();
    assertThrows(GeneralSecurityException.class, () -> manager.validateKey(key));
}
Also used : HkdfPrfKey(com.google.crypto.tink.proto.HkdfPrfKey) Test(org.junit.Test)

Example 3 with HkdfPrfKey

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

the class HkdfPrfKeyManagerTest method validateKey_invalid31ByteKey_throws.

@Test
public void validateKey_invalid31ByteKey_throws() throws Exception {
    HkdfPrfKey key = HkdfPrfKey.newBuilder().setVersion(0).setKeyValue(ByteString.copyFrom(Random.randBytes(31))).setParams(HkdfPrfParams.newBuilder().setHash(HashType.SHA256)).build();
    assertThrows(GeneralSecurityException.class, () -> manager.validateKey(key));
}
Also used : HkdfPrfKey(com.google.crypto.tink.proto.HkdfPrfKey) Test(org.junit.Test)

Example 4 with HkdfPrfKey

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

the class HkdfPrfKeyManagerTest method createKey_valuesAreOk.

@Test
public void createKey_valuesAreOk() throws Exception {
    HkdfPrfKeyFormat format = HkdfPrfKeyFormat.newBuilder().setKeySize(77).setParams(HkdfPrfParams.newBuilder().setSalt(ByteString.copyFrom(Random.randBytes(5))).setHash(HashType.SHA256)).build();
    HkdfPrfKey key = factory.createKey(format);
    assertThat(key.getVersion()).isEqualTo(0);
    assertThat(key.getKeyValue()).hasSize(77);
    assertThat(key.getParams()).isEqualTo(format.getParams());
}
Also used : HkdfPrfKeyFormat(com.google.crypto.tink.proto.HkdfPrfKeyFormat) HkdfPrfKey(com.google.crypto.tink.proto.HkdfPrfKey) Test(org.junit.Test)

Example 5 with HkdfPrfKey

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

the class HkdfPrfKeyManagerTest method createPrfSetPrimitive_works.

/**
 * Smoke test getPrimitive for PrfSet via the HkdfPrfKeymanager.
 */
@Test
public void createPrfSetPrimitive_works() throws Exception {
    HkdfPrfKey key = HkdfPrfKey.newBuilder().setKeyValue(ByteString.copyFromUtf8("super secret key value")).setParams(HkdfPrfParams.newBuilder().setSalt(ByteString.copyFromUtf8("some salt")).setHash(HashType.SHA256)).build();
    manager.getPrimitive(key, Prf.class);
}
Also used : HkdfPrfKey(com.google.crypto.tink.proto.HkdfPrfKey) Test(org.junit.Test)

Aggregations

HkdfPrfKey (com.google.crypto.tink.proto.HkdfPrfKey)7 Test (org.junit.Test)7 HkdfPrfKeyFormat (com.google.crypto.tink.proto.HkdfPrfKeyFormat)1 HkdfStreamingPrf (com.google.crypto.tink.subtle.prf.HkdfStreamingPrf)1 StreamingPrf (com.google.crypto.tink.subtle.prf.StreamingPrf)1 InputStream (java.io.InputStream)1