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);
}
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();
}
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();
}
Aggregations