author | prr |
Fri, 25 May 2018 12:12:24 -0700 | |
changeset 50347 | b2f046ae8eb6 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
9556
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
1 |
/* |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
2 |
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
4 |
* |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
8 |
* |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
13 |
* accompanied this code). |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
14 |
* |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
18 |
* |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
21 |
* questions. |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
22 |
*/ |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
23 |
|
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
24 |
/** |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
25 |
* @test |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
26 |
* @bug 6738532 |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
27 |
* @summary Check EllipticCurve.equals() does not compare seed value of curve. |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
28 |
* @author Mike StJohns |
30046 | 29 |
* @key randomness |
9556
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
30 |
*/ |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
31 |
|
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
32 |
import java.security.spec.*; |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
33 |
import java.math.BigInteger; |
10057 | 34 |
import java.util.Random; |
9556
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
35 |
|
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
36 |
public class EllipticCurveMatch { |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
37 |
static String primeP256 = |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
38 |
"0FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF"; |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
39 |
static String aP256 = |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
40 |
"0FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC"; |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
41 |
static String bP256 = |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
42 |
"05AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B"; |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
43 |
static String seedP256 = |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
44 |
"0C49D360886E704936A6678E1139D26B7819F7E90"; |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
45 |
|
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
46 |
private static EllipticCurve addSeedToCurve(EllipticCurve curve) |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
47 |
{ |
10057 | 48 |
Random rand = new Random(); |
9556
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
49 |
byte[] seed = new byte[12]; |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
50 |
rand.nextBytes(seed); |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
51 |
|
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
52 |
return new EllipticCurve (curve.getField(), curve.getA(), curve.getB(), |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
53 |
seed); |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
54 |
} |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
55 |
|
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
56 |
private static EllipticCurve getP256Curve() |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
57 |
{ |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
58 |
ECFieldFp field = new ECFieldFp(new BigInteger (primeP256,16)); |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
59 |
BigInteger a = new BigInteger (aP256, 16); |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
60 |
BigInteger b = new BigInteger (bP256, 16); |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
61 |
|
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
62 |
return new EllipticCurve (field, a, b); |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
63 |
} |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
64 |
|
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
65 |
public static void main (String[] argv) throws Exception { |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
66 |
EllipticCurve firstCurve = getP256Curve(); |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
67 |
EllipticCurve secondCurve = addSeedToCurve(firstCurve); |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
68 |
EllipticCurve thirdCurve = addSeedToCurve(firstCurve); |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
69 |
|
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
70 |
if (!firstCurve.equals(firstCurve)) |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
71 |
throw new Exception("Original curve doesn't equal itself"); |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
72 |
|
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
73 |
if (!firstCurve.equals(secondCurve)) |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
74 |
throw new Exception ("Original curve doesn't equal seeded curve"); |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
75 |
|
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
76 |
if (!secondCurve.equals(secondCurve)) |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
77 |
throw new Exception ("Seeded curve doesn't equal itself"); |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
78 |
|
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
79 |
if (!secondCurve.equals(thirdCurve)) |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
80 |
throw new Exception ("Seeded curve doesn't equal differently " + |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
81 |
"seeded curve"); |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
82 |
System.out.println("Curve equals test passed"); |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
83 |
} |
79c47f5e241b
6738532: Error in Elliptic Curve NamedCurve determination. (related to PKCS11)
vinnie
parents:
diff
changeset
|
84 |
} |