• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 Authenticated Encryption with Associated Data (AEAD).
23  *
24  * <h3>Security guarantees</h3>
25  *
26  * <p>Implementations of this interface are secure against adaptive chosen ciphertext attacks.
27  * Encryption with associated data ensures authenticity (who the sender is) and integrity (the data
28  * has not been tampered with) of that data, but not its secrecy. (see <a
29  * href="https://tools.ietf.org/html/rfc5116">RFC 5116</a> for more info)
30  *
31  * @since 1.0.0
32  */
33 public interface Aead {
34   /**
35    * Encrypts {@code plaintext} with {@code associatedData} as associated authenticated data.
36    * The resulting ciphertext allows for checking authenticity and integrity of associated data
37    * ({@code associatedData}), but does not guarantee its secrecy.
38    *
39    * @param plaintext       the plaintext to be encrypted. It must be non-null, but can also
40    *                        be an empty (zero-length) byte array
41    * @param associatedData  associated data to be authenticated, but not encrypted.  Associated data
42    *                        is optional, so this parameter can be null.  In this case the null value
43    *                        is equivalent to an empty (zero-length) byte array.
44    *                        For successful decryption the same associatedData must be provided
45    *                        along with the ciphertext.
46    * @return resulting ciphertext
47    */
encrypt(final byte[] plaintext, final byte[] associatedData)48   byte[] encrypt(final byte[] plaintext, final byte[] associatedData)
49       throws GeneralSecurityException;
50 
51   /**
52    * Decrypts {@code ciphertext} with {@code associatedData} as associated authenticated data. The
53    * decryption verifies the authenticity and integrity of the associated data, but there are no
54    * guarantees wrt. secrecy of that data.
55    *
56    * @param ciphertext the plaintext to be decrypted. It must be non-null.
57    * @param associatedData associated data to be authenticated. For successful decryption it must be
58    *     the same as associatedData used during encryption. Can be null, which is equivalent to an
59    *     empty (zero-length) byte array.
60    * @return resulting plaintext
61    * @throws GeneralSecurityException if decryption fails. Decryption must fail if {@code
62    *     ciphertext} is not correctly authenticated for the given {@code associatedData}.
63    */
decrypt(final byte[] ciphertext, final byte[] associatedData)64   byte[] decrypt(final byte[] ciphertext, final byte[] associatedData)
65       throws GeneralSecurityException;
66 }
67