use of com.google.crypto.tink.proto.AesCtrHmacStreamingParams in project tink by google.
the class AesCtrHmacStreamingKeyManagerTest method testNewKeyWithBadFormat.
@Test
public void testNewKeyWithBadFormat() throws Exception {
// key_size too small.
AesCtrHmacStreamingKeyFormat keyFormat = AesCtrHmacStreamingKeyFormat.newBuilder().setParams(keyParams).setKeySize(15).build();
testNewKeyWithBadFormat(keyFormat);
// Unknown HKDF HashType.
AesCtrHmacStreamingParams badKeyParams = AesCtrHmacStreamingParams.newBuilder().setCiphertextSegmentSize(128).setDerivedKeySize(AES_KEY_SIZE).build();
testNewKeyWithBadFormat(badKeyParams);
// derived_key_size too small.
badKeyParams = AesCtrHmacStreamingParams.newBuilder().setCiphertextSegmentSize(128).setDerivedKeySize(10).setHkdfHashType(HashType.SHA256).build();
testNewKeyWithBadFormat(badKeyParams);
// ciphertext_segment_size too small.
badKeyParams = AesCtrHmacStreamingParams.newBuilder().setCiphertextSegmentSize(15).setDerivedKeySize(AES_KEY_SIZE).setHkdfHashType(HashType.SHA256).build();
testNewKeyWithBadFormat(badKeyParams);
// No HmacParams.
badKeyParams = AesCtrHmacStreamingParams.newBuilder().setCiphertextSegmentSize(130).setDerivedKeySize(AES_KEY_SIZE).setHkdfHashType(HashType.SHA256).build();
testNewKeyWithBadFormat(badKeyParams);
// Unknown HmacParams.hash.
badKeyParams = AesCtrHmacStreamingParams.newBuilder().setCiphertextSegmentSize(130).setDerivedKeySize(AES_KEY_SIZE).setHkdfHashType(HashType.SHA256).setHmacParams(HmacParams.newBuilder().build()).build();
testNewKeyWithBadFormat(badKeyParams);
// tag size too small.
badKeyParams = AesCtrHmacStreamingParams.newBuilder().setCiphertextSegmentSize(130).setDerivedKeySize(AES_KEY_SIZE).setHkdfHashType(HashType.SHA256).setHmacParams(HmacParams.newBuilder().setHash(HashType.SHA256).setTagSize(9).build()).build();
testNewKeyWithBadFormat(badKeyParams);
// tag size too big.
badKeyParams = AesCtrHmacStreamingParams.newBuilder().setCiphertextSegmentSize(130).setDerivedKeySize(AES_KEY_SIZE).setHkdfHashType(HashType.SHA256).setHmacParams(HmacParams.newBuilder().setHash(HashType.SHA256).setTagSize(33).build()).build();
testNewKeyWithBadFormat(badKeyParams);
// All params good.
AesCtrHmacStreamingParams goodKeyParams = AesCtrHmacStreamingParams.newBuilder().setCiphertextSegmentSize(130).setDerivedKeySize(AES_KEY_SIZE).setHkdfHashType(HashType.SHA256).setHmacParams(hmacParams).build();
keyFormat = AesCtrHmacStreamingKeyFormat.newBuilder().setParams(goodKeyParams).setKeySize(16).build();
ByteString serializedKeyFormat = ByteString.copyFrom(keyFormat.toByteArray());
AesCtrHmacStreamingKey unusedKey = (AesCtrHmacStreamingKey) keyManager.newKey(keyFormat);
unusedKey = (AesCtrHmacStreamingKey) keyManager.newKey(serializedKeyFormat);
}
use of com.google.crypto.tink.proto.AesCtrHmacStreamingParams 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.AesCtrHmacStreamingParams 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();
}
Aggregations