Search in sources :

Example 1 with HmacParams

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

the class TestUtil method createAesCtrHmacStreamingKeyData.

/**
 * @return a {@code KeyData} containing a {@code AesCtrHmacStreamingKey}.
 */
public static KeyData createAesCtrHmacStreamingKeyData(byte[] keyValue, int derivedKeySize, int ciphertextSegmentSize) throws Exception {
    HmacParams hmacParams = HmacParams.newBuilder().setHash(HashType.SHA256).setTagSize(16).build();
    AesCtrHmacStreamingParams keyParams = AesCtrHmacStreamingParams.newBuilder().setCiphertextSegmentSize(ciphertextSegmentSize).setDerivedKeySize(derivedKeySize).setHkdfHashType(HashType.SHA256).setHmacParams(hmacParams).build();
    AesCtrHmacStreamingKey keyProto = AesCtrHmacStreamingKey.newBuilder().setVersion(0).setKeyValue(ByteString.copyFrom(keyValue)).setParams(keyParams).build();
    return createKeyData(keyProto, StreamingAeadConfig.AES_CTR_HMAC_STREAMINGAEAD_TYPE_URL, KeyData.KeyMaterialType.SYMMETRIC);
}
Also used : AesCtrHmacStreamingParams(com.google.crypto.tink.proto.AesCtrHmacStreamingParams) AesCtrHmacStreamingKey(com.google.crypto.tink.proto.AesCtrHmacStreamingKey) HmacParams(com.google.crypto.tink.proto.HmacParams)

Example 2 with HmacParams

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

the class StreamingAeadKeyTemplates method createAesCtrHmacStreamingKeyTemplate.

/**
 * @return a {@link KeyTemplate} containing a {@link AesCtrHmacStreamingKeyFormat} with some
 *     specified parameters.
 */
public static KeyTemplate createAesCtrHmacStreamingKeyTemplate(int mainKeySize, HashType hkdfHashType, int derivedKeySize, HashType macHashType, int tagSize, int ciphertextSegmentSize) {
    HmacParams hmacParams = HmacParams.newBuilder().setHash(macHashType).setTagSize(tagSize).build();
    AesCtrHmacStreamingParams params = AesCtrHmacStreamingParams.newBuilder().setCiphertextSegmentSize(ciphertextSegmentSize).setDerivedKeySize(derivedKeySize).setHkdfHashType(hkdfHashType).setHmacParams(hmacParams).build();
    AesCtrHmacStreamingKeyFormat format = AesCtrHmacStreamingKeyFormat.newBuilder().setParams(params).setKeySize(mainKeySize).build();
    return KeyTemplate.newBuilder().setValue(format.toByteString()).setTypeUrl(AesCtrHmacStreamingKeyManager.TYPE_URL).setOutputPrefixType(OutputPrefixType.RAW).build();
}
Also used : AesCtrHmacStreamingParams(com.google.crypto.tink.proto.AesCtrHmacStreamingParams) HmacParams(com.google.crypto.tink.proto.HmacParams) AesCtrHmacStreamingKeyFormat(com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat)

Example 3 with HmacParams

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

the class MacKeyTemplates method createHmacKeyTemplate.

/**
 * @return a {@link KeyTemplate} containing a {@link HmacKeyFormat} with some specified
 *     parameters.
 */
public static KeyTemplate createHmacKeyTemplate(int keySize, int tagSize, HashType hashType) {
    HmacParams params = HmacParams.newBuilder().setHash(hashType).setTagSize(tagSize).build();
    HmacKeyFormat format = HmacKeyFormat.newBuilder().setParams(params).setKeySize(keySize).build();
    return KeyTemplate.newBuilder().setValue(format.toByteString()).setTypeUrl(HmacKeyManager.TYPE_URL).setOutputPrefixType(OutputPrefixType.TINK).build();
}
Also used : HmacParams(com.google.crypto.tink.proto.HmacParams) HmacKeyFormat(com.google.crypto.tink.proto.HmacKeyFormat)

Aggregations

HmacParams (com.google.crypto.tink.proto.HmacParams)3 AesCtrHmacStreamingParams (com.google.crypto.tink.proto.AesCtrHmacStreamingParams)2 AesCtrHmacStreamingKey (com.google.crypto.tink.proto.AesCtrHmacStreamingKey)1 AesCtrHmacStreamingKeyFormat (com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat)1 HmacKeyFormat (com.google.crypto.tink.proto.HmacKeyFormat)1