From 2be59f90fdbfd1efef93f89f5966b6eeeb79cd00 Mon Sep 17 00:00:00 2001 From: Bradford Wetmore Date: Wed, 13 Apr 2011 11:59:18 -0700 Subject: [PATCH] 7031343: Provide API changes to support future GCM AEAD ciphers Reviewed-by: valeriep, xuelei --- .../javax/crypto/AEADBadTagException.java | 55 ++++ .../share/classes/javax/crypto/Cipher.java | 267 ++++++++++++++++-- .../share/classes/javax/crypto/CipherSpi.java | 112 +++++++- .../javax/crypto/spec/GCMParameterSpec.java | 149 ++++++++++ jdk/test/javax/crypto/Cipher/GCMAPI.java | 138 +++++++++ .../GCMParameterSpecTest.java | 130 +++++++++ 6 files changed, 826 insertions(+), 25 deletions(-) create mode 100644 jdk/src/share/classes/javax/crypto/AEADBadTagException.java create mode 100644 jdk/src/share/classes/javax/crypto/spec/GCMParameterSpec.java create mode 100644 jdk/test/javax/crypto/Cipher/GCMAPI.java create mode 100644 jdk/test/javax/crypto/spec/GCMParameterSpec/GCMParameterSpecTest.java diff --git a/jdk/src/share/classes/javax/crypto/AEADBadTagException.java b/jdk/src/share/classes/javax/crypto/AEADBadTagException.java new file mode 100644 index 00000000000..8587fcf3ce6 --- /dev/null +++ b/jdk/src/share/classes/javax/crypto/AEADBadTagException.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package javax.crypto; + +/** + * This exception is thrown when a {@link Cipher} operating in + * an AEAD mode (such as GCM/CCM) is unable to verify the supplied + * authentication tag. + * + * @since 1.7 + */ +public class AEADBadTagException extends BadPaddingException { + + private static final long serialVersionUID = -488059093241685509L; + + /** + * Constructs a AEADBadTagException with no detail message. + */ + public AEADBadTagException() { + super(); + } + + /** + * Constructs a AEADBadTagException with the specified + * detail message. + * + * @param msg the detail message. + */ + public AEADBadTagException(String msg) { + super(msg); + } +} diff --git a/jdk/src/share/classes/javax/crypto/Cipher.java b/jdk/src/share/classes/javax/crypto/Cipher.java index d6878d23eaf..bd17f023639 100644 --- a/jdk/src/share/classes/javax/crypto/Cipher.java +++ b/jdk/src/share/classes/javax/crypto/Cipher.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -88,8 +88,35 @@ import sun.security.jca.GetInstance.Instance; * example, the SunJCE provider uses a default of 64 bits for DES.) * Thus, block ciphers can be turned into byte-oriented stream ciphers by * using an 8 bit mode such as CFB8 or OFB8. + *

+ * Modes such as Authenticated Encryption with Associated Data (AEAD) + * provide authenticity assurances for both confidential data and + * Additional Associated Data (AAD) that is not encrypted. (Please see + * RFC 5116 for more + * information on AEAD and AEAD algorithms such as GCM/CCM.) Both + * confidential and AAD data can be used when calculating the + * authentication tag (similar to a {@link Mac}). This tag is appended + * to the ciphertext during encryption, and is verified on decryption. + *

+ * AEAD modes such as GCM/CCM perform all AAD authenticity calculations + * before starting the ciphertext authenticity calculations. To avoid + * implementations having to internally buffer ciphertext, all AAD data + * must be supplied to GCM/CCM implementations (via the {@code + * updateAAD} methods) before the ciphertext is processed (via + * the {@code update} and {@code doFinal} methods). * - *

Every implementation of the Java platform is required to support + *

+ *     GCMParameterSpec s = new GCMParameterSpec(...);
+ *     cipher.init(..., s);
+ *
+ *     // If the GCMParameterSpec is needed again
+ *     cipher.getParameters().getParameterSpec(GCMParameterSpec.class));
+ *
+ *     cipher.updateAAD(...);  // AAD
+ *     cipher.update(...);     // Multi-part update
+ *     cipher.doFinal(...);    // conclusion of operation
+ * 
+ * Every implementation of the Java platform is required to support * the following standard Cipher transformations with the keysizes * in parentheses: *