Search in sources :

Example 6 with AesCtrKey

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

the class TestUtil method createAesCtrHmacAeadKeyData.

/**
 * @return a {@code KeyData} containing a {@code AesCtrHmacAeadKey}.
 */
public static KeyData createAesCtrHmacAeadKeyData(byte[] aesCtrKeyValue, int ivSize, byte[] hmacKeyValue, int tagSize) throws Exception {
    AesCtrKey aesCtrKey = createAesCtrKey(aesCtrKeyValue, ivSize);
    HmacKey hmacKey = createHmacKey(hmacKeyValue, tagSize);
    AesCtrHmacAeadKey keyProto = AesCtrHmacAeadKey.newBuilder().setAesCtrKey(aesCtrKey).setHmacKey(hmacKey).build();
    return createKeyData(keyProto, AeadConfig.AES_CTR_HMAC_AEAD_TYPE_URL, KeyData.KeyMaterialType.SYMMETRIC);
}
Also used : AesCtrKey(com.google.crypto.tink.proto.AesCtrKey) HmacKey(com.google.crypto.tink.proto.HmacKey) AesCtrHmacAeadKey(com.google.crypto.tink.proto.AesCtrHmacAeadKey)

Example 7 with AesCtrKey

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

the class AesCtrHmacAeadKeyManager method keyFactory.

@Override
public KeyFactory<AesCtrHmacAeadKeyFormat, AesCtrHmacAeadKey> keyFactory() {
    return new KeyFactory<AesCtrHmacAeadKeyFormat, AesCtrHmacAeadKey>(AesCtrHmacAeadKeyFormat.class) {

        @Override
        public void validateKeyFormat(AesCtrHmacAeadKeyFormat format) throws GeneralSecurityException {
            new AesCtrKeyManager().keyFactory().validateKeyFormat(format.getAesCtrKeyFormat());
            new HmacKeyManager().keyFactory().validateKeyFormat(format.getHmacKeyFormat());
            Validators.validateAesKeySize(format.getAesCtrKeyFormat().getKeySize());
        }

        @Override
        public AesCtrHmacAeadKeyFormat parseKeyFormat(ByteString byteString) throws InvalidProtocolBufferException {
            return AesCtrHmacAeadKeyFormat.parseFrom(byteString, ExtensionRegistryLite.getEmptyRegistry());
        }

        @Override
        public AesCtrHmacAeadKey createKey(AesCtrHmacAeadKeyFormat format) throws GeneralSecurityException {
            AesCtrKey aesCtrKey = new AesCtrKeyManager().keyFactory().createKey(format.getAesCtrKeyFormat());
            HmacKey hmacKey = new HmacKeyManager().keyFactory().createKey(format.getHmacKeyFormat());
            return AesCtrHmacAeadKey.newBuilder().setAesCtrKey(aesCtrKey).setHmacKey(hmacKey).setVersion(getVersion()).build();
        }

        @Override
        public Map<String, KeyFactory.KeyFormat<AesCtrHmacAeadKeyFormat>> keyFormats() throws GeneralSecurityException {
            Map<String, KeyFactory.KeyFormat<AesCtrHmacAeadKeyFormat>> result = new HashMap<>();
            result.put("AES128_CTR_HMAC_SHA256", createKeyFormat(16, 16, 32, 16, HashType.SHA256, KeyTemplate.OutputPrefixType.TINK));
            result.put("AES128_CTR_HMAC_SHA256_RAW", createKeyFormat(16, 16, 32, 16, HashType.SHA256, KeyTemplate.OutputPrefixType.RAW));
            result.put("AES256_CTR_HMAC_SHA256", createKeyFormat(32, 16, 32, 32, HashType.SHA256, KeyTemplate.OutputPrefixType.TINK));
            result.put("AES256_CTR_HMAC_SHA256_RAW", createKeyFormat(32, 16, 32, 32, HashType.SHA256, KeyTemplate.OutputPrefixType.RAW));
            return Collections.unmodifiableMap(result);
        }
    };
}
Also used : AesCtrKey(com.google.crypto.tink.proto.AesCtrKey) HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString) HmacKeyManager(com.google.crypto.tink.mac.HmacKeyManager) AesCtrHmacAeadKeyFormat(com.google.crypto.tink.proto.AesCtrHmacAeadKeyFormat) ByteString(com.google.protobuf.ByteString) AesCtrHmacAeadKeyFormat(com.google.crypto.tink.proto.AesCtrHmacAeadKeyFormat) AesCtrKeyFormat(com.google.crypto.tink.proto.AesCtrKeyFormat) HmacKeyFormat(com.google.crypto.tink.proto.HmacKeyFormat) HmacKey(com.google.crypto.tink.proto.HmacKey)

Aggregations

AesCtrKey (com.google.crypto.tink.proto.AesCtrKey)7 HmacKey (com.google.crypto.tink.proto.HmacKey)4 AesCtrHmacAeadKey (com.google.crypto.tink.proto.AesCtrHmacAeadKey)2 AesCtrHmacAeadKeyFormat (com.google.crypto.tink.proto.AesCtrHmacAeadKeyFormat)2 AesCtrKeyFormat (com.google.crypto.tink.proto.AesCtrKeyFormat)2 AesCtrJceCipher (com.google.crypto.tink.subtle.AesCtrJceCipher)2 ByteString (com.google.protobuf.ByteString)2 GeneralSecurityException (java.security.GeneralSecurityException)2 Test (org.junit.Test)2 HmacKeyManager (com.google.crypto.tink.mac.HmacKeyManager)1 HmacKeyFormat (com.google.crypto.tink.proto.HmacKeyFormat)1 KeyData (com.google.crypto.tink.proto.KeyData)1 KeyTemplate (com.google.crypto.tink.proto.KeyTemplate)1 IndCpaCipher (com.google.crypto.tink.subtle.IndCpaCipher)1 HashMap (java.util.HashMap)1 TreeSet (java.util.TreeSet)1