Path: blob/master/test/jdk/com/sun/crypto/provider/KeyAgreement/UnsupportedDHKeys.java
41155 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 807245226* @summary Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits27*/2829import java.math.BigInteger;3031import java.security.*;32import javax.crypto.*;33import javax.crypto.interfaces.*;34import javax.crypto.spec.*;3536public class UnsupportedDHKeys {3738/*39* Sizes and values for various lengths.40*/41private enum UnsupportedKeySize {42// not multiple of 6443dhp513(513), dhp769(769), dhp895(895),44dhp1023(1023), dhp1535(1535), dhp2047(2047),4546// unsupported47dhp2176(2176), dhp3008(3008), dhp4032(4032),48dhp5120(5120), dhp6400(6400), dhp7680(7680),49dhp8191(8191), dhp8128(8128), dhp8260(8260);5051final int primeSize;5253UnsupportedKeySize(int primeSize) {54this.primeSize = primeSize;55}56}5758public static void main(String[] args) throws Exception {59for (UnsupportedKeySize keySize : UnsupportedKeySize.values()) {60try {61System.out.println("Checking " + keySize.primeSize + " ...");62KeyPairGenerator kpg =63KeyPairGenerator.getInstance("DH", "SunJCE");64kpg.initialize(keySize.primeSize);6566throw new Exception("Should not support " + keySize.primeSize);67} catch (InvalidParameterException ipe) {68System.out.println("\tOk, unsupported");69}70}71}72}737475