1 // Copyright 2017 Google Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 //////////////////////////////////////////////////////////////////////////////// 16 17 package com.google.crypto.tink; 18 19 import java.security.GeneralSecurityException; 20 21 /** 22 * Interface for Deterministic Authenticated Encryption with Associated Data (Deterministic AEAD). 23 * 24 * <p>For why this interface is desirable and some of its use cases, see for example <a 25 * href="https://tools.ietf.org/html/rfc5297#section-1.3">RFC 5297 section 1.3</a>. 26 * 27 * <h3>Warning</h3> 28 * 29 * <p>Unlike {@link Aead}, implementations of this interface are not semantically secure, because 30 * encrypting the same plaintex always yields the same ciphertext. 31 * 32 * <h3>Security guarantees</h3> 33 * 34 * <p>Implementations of this interface provide 128-bit security level against multi-user attacks 35 * with up to 2^32 keys. That means if an adversary obtains 2^32 ciphertexts of the same message 36 * encrypted under 2^32 keys, they need to do 2^128 computations to obtain a single key. 37 * 38 * <p>Encryption with associated data ensures authenticity (who the sender is) and integrity (the 39 * data has not been tampered with) of that data, but not its secrecy. (see <a 40 * href="https://tools.ietf.org/html/rfc5116">RFC 5116</a>) 41 * 42 * @since 1.1.0 43 */ 44 public interface DeterministicAead { 45 /** 46 * Deterministically encrypts {@code plaintext} with {@code associatedData} as associated 47 * authenticated data. 48 * 49 * <p><b>Warning</b> 50 * 51 * <p>Encrypting the same {@code plaintext} multiple times protects the integrity of that 52 * plaintext, but confidentiality is compromised to the extent that an attacker can determine that 53 * the same plaintext was encrypted. 54 * 55 * <p>The resulting ciphertext allows for checking authenticity and integrity of associated data 56 * ({@code associatedData}), but does not guarantee its secrecy. 57 * 58 * @return resulting ciphertext 59 */ encryptDeterministically(final byte[] plaintext, final byte[] associatedData)60 byte[] encryptDeterministically(final byte[] plaintext, final byte[] associatedData) 61 throws GeneralSecurityException; 62 63 /** 64 * Deterministically decrypts {@code ciphertext} with {@code associatedData} as associated 65 * authenticated data. 66 * 67 * <p>The decryption verifies the authenticity and integrity of the associated data, but there are 68 * no guarantees wrt. secrecy of that data. 69 * 70 * @return resulting plaintext 71 */ decryptDeterministically(final byte[] ciphertext, final byte[] associatedData)72 byte[] decryptDeterministically(final byte[] ciphertext, final byte[] associatedData) 73 throws GeneralSecurityException; 74 } 75