author | valeriep |
Thu, 12 Jan 2012 16:04:03 -0800 | |
changeset 11523 | 85131f3172a1 |
permissions | -rw-r--r-- |
11523
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
1 |
/* |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
2 |
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
4 |
* |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
8 |
* |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
13 |
* accompanied this code). |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
14 |
* |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
18 |
* |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
21 |
* questions. |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
22 |
*/ |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
23 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
24 |
/* |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
25 |
* @test |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
26 |
* @bug 7088989 |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
27 |
* @summary Ensure the RSA ciphers and signatures works correctly |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
28 |
*/ |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
29 |
import java.io.*; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
30 |
import java.security.*; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
31 |
import java.security.spec.*; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
32 |
import java.util.*; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
33 |
import java.math.*; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
34 |
import javax.crypto.*; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
35 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
36 |
public class TestRSA extends UcryptoTest { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
37 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
38 |
// KAT |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
39 |
private static final byte PLAINTEXT[] = Arrays.copyOf |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
40 |
(new String("Known plaintext message utilized" + |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
41 |
"for RSA Encryption & Decryption" + |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
42 |
"block, SHA1, SHA256, SHA384 and" + |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
43 |
"SHA512 RSA Signature KAT tests.").getBytes(), 128); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
44 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
45 |
private static final byte MOD[] = { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
46 |
(byte)0xd5, (byte)0x84, (byte)0x95, (byte)0x07, (byte)0xf4, (byte)0xd0, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
47 |
(byte)0x1f, (byte)0x82, (byte)0xf3, (byte)0x79, (byte)0xf4, (byte)0x99, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
48 |
(byte)0x48, (byte)0x10, (byte)0xe1, (byte)0x71, (byte)0xa5, (byte)0x62, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
49 |
(byte)0x22, (byte)0xa3, (byte)0x4b, (byte)0x00, (byte)0xe3, (byte)0x5b, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
50 |
(byte)0x3a, (byte)0xcc, (byte)0x10, (byte)0x83, (byte)0xe0, (byte)0xaf, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
51 |
(byte)0x61, (byte)0x13, (byte)0x54, (byte)0x6a, (byte)0xa2, (byte)0x6a, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
52 |
(byte)0x2c, (byte)0x5e, (byte)0xb3, (byte)0xcc, (byte)0xa3, (byte)0x71, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
53 |
(byte)0x9a, (byte)0xb2, (byte)0x3e, (byte)0x78, (byte)0xec, (byte)0xb5, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
54 |
(byte)0x0e, (byte)0x6e, (byte)0x31, (byte)0x3b, (byte)0x77, (byte)0x1f, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
55 |
(byte)0x6e, (byte)0x94, (byte)0x41, (byte)0x60, (byte)0xd5, (byte)0x6e, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
56 |
(byte)0xd9, (byte)0xc6, (byte)0xf9, (byte)0x29, (byte)0xc3, (byte)0x40, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
57 |
(byte)0x36, (byte)0x25, (byte)0xdb, (byte)0xea, (byte)0x0b, (byte)0x07, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
58 |
(byte)0xae, (byte)0x76, (byte)0xfd, (byte)0x99, (byte)0x29, (byte)0xf4, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
59 |
(byte)0x22, (byte)0xc1, (byte)0x1a, (byte)0x8f, (byte)0x05, (byte)0xfe, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
60 |
(byte)0x98, (byte)0x09, (byte)0x07, (byte)0x05, (byte)0xc2, (byte)0x0f, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
61 |
(byte)0x0b, (byte)0x11, (byte)0x83, (byte)0x39, (byte)0xca, (byte)0xc7, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
62 |
(byte)0x43, (byte)0x63, (byte)0xff, (byte)0x33, (byte)0x80, (byte)0xe7, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
63 |
(byte)0xc3, (byte)0x78, (byte)0xae, (byte)0xf1, (byte)0x73, (byte)0x52, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
64 |
(byte)0x98, (byte)0x1d, (byte)0xde, (byte)0x5c, (byte)0x53, (byte)0x6e, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
65 |
(byte)0x01, (byte)0x73, (byte)0x0d, (byte)0x12, (byte)0x7e, (byte)0x77, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
66 |
(byte)0x03, (byte)0xf1, (byte)0xef, (byte)0x1b, (byte)0xc8, (byte)0xa8, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
67 |
(byte)0x0f, (byte)0x97 |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
68 |
}; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
69 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
70 |
private static final byte PUB_EXP[] = {(byte)0x01, (byte)0x00, (byte)0x01}; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
71 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
72 |
private static final byte PRIV_EXP[] = { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
73 |
(byte)0x85, (byte)0x27, (byte)0x47, (byte)0x61, (byte)0x4c, (byte)0xd4, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
74 |
(byte)0xb5, (byte)0xb2, (byte)0x0e, (byte)0x70, (byte)0x91, (byte)0x8f, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
75 |
(byte)0x3d, (byte)0x97, (byte)0xf9, (byte)0x5f, (byte)0xcc, (byte)0x09, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
76 |
(byte)0x65, (byte)0x1c, (byte)0x7c, (byte)0x5b, (byte)0xb3, (byte)0x6d, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
77 |
(byte)0x63, (byte)0x3f, (byte)0x7b, (byte)0x55, (byte)0x22, (byte)0xbb, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
78 |
(byte)0x7c, (byte)0x48, (byte)0x77, (byte)0xae, (byte)0x80, (byte)0x56, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
79 |
(byte)0xc2, (byte)0x10, (byte)0xd5, (byte)0x03, (byte)0xdb, (byte)0x31, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
80 |
(byte)0xaf, (byte)0x8d, (byte)0x54, (byte)0xd4, (byte)0x48, (byte)0x99, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
81 |
(byte)0xa8, (byte)0xc4, (byte)0x23, (byte)0x43, (byte)0xb8, (byte)0x48, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
82 |
(byte)0x0b, (byte)0xc7, (byte)0xbc, (byte)0xf5, (byte)0xcc, (byte)0x64, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
83 |
(byte)0x72, (byte)0xbf, (byte)0x59, (byte)0x06, (byte)0x04, (byte)0x1c, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
84 |
(byte)0x32, (byte)0xf5, (byte)0x14, (byte)0x2e, (byte)0x6e, (byte)0xe2, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
85 |
(byte)0x0f, (byte)0x5c, (byte)0xde, (byte)0x36, (byte)0x3c, (byte)0x6e, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
86 |
(byte)0x7c, (byte)0x4d, (byte)0xcc, (byte)0xd3, (byte)0x00, (byte)0x6e, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
87 |
(byte)0xe5, (byte)0x45, (byte)0x46, (byte)0xef, (byte)0x4d, (byte)0x25, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
88 |
(byte)0x46, (byte)0x6d, (byte)0x7f, (byte)0xed, (byte)0xbb, (byte)0x4f, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
89 |
(byte)0x4d, (byte)0x9f, (byte)0xda, (byte)0x87, (byte)0x47, (byte)0x8f, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
90 |
(byte)0x74, (byte)0x44, (byte)0xb7, (byte)0xbe, (byte)0x9d, (byte)0xf5, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
91 |
(byte)0xdd, (byte)0xd2, (byte)0x4c, (byte)0xa5, (byte)0xab, (byte)0x74, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
92 |
(byte)0xe5, (byte)0x29, (byte)0xa1, (byte)0xd2, (byte)0x45, (byte)0x3b, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
93 |
(byte)0x33, (byte)0xde, (byte)0xd5, (byte)0xae, (byte)0xf7, (byte)0x03, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
94 |
(byte)0x10, (byte)0x21 |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
95 |
}; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
96 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
97 |
private static final byte PRIME_P[] = { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
98 |
(byte)0xf9, (byte)0x74, (byte)0x8f, (byte)0x16, (byte)0x02, (byte)0x6b, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
99 |
(byte)0xa0, (byte)0xee, (byte)0x7f, (byte)0x28, (byte)0x97, (byte)0x91, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
100 |
(byte)0xdc, (byte)0xec, (byte)0xc0, (byte)0x7c, (byte)0x49, (byte)0xc2, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
101 |
(byte)0x85, (byte)0x76, (byte)0xee, (byte)0x66, (byte)0x74, (byte)0x2d, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
102 |
(byte)0x1a, (byte)0xb8, (byte)0xf7, (byte)0x2f, (byte)0x11, (byte)0x5b, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
103 |
(byte)0x36, (byte)0xd8, (byte)0x46, (byte)0x33, (byte)0x3b, (byte)0xd8, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
104 |
(byte)0xf3, (byte)0x2d, (byte)0xa1, (byte)0x03, (byte)0x83, (byte)0x2b, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
105 |
(byte)0xec, (byte)0x35, (byte)0x43, (byte)0x32, (byte)0xff, (byte)0xdd, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
106 |
(byte)0x81, (byte)0x7c, (byte)0xfd, (byte)0x65, (byte)0x13, (byte)0x04, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
107 |
(byte)0x7c, (byte)0xfc, (byte)0x03, (byte)0x97, (byte)0xf0, (byte)0xd5, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
108 |
(byte)0x62, (byte)0xdc, (byte)0x0d, (byte)0xbf |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
109 |
}; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
110 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
111 |
private static final byte PRIME_Q[] = { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
112 |
(byte)0xdb, (byte)0x1e, (byte)0xa7, (byte)0x3d, (byte)0xe7, (byte)0xfa, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
113 |
(byte)0x8b, (byte)0x04, (byte)0x83, (byte)0x48, (byte)0xf3, (byte)0xa5, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
114 |
(byte)0x31, (byte)0x9d, (byte)0x35, (byte)0x5e, (byte)0x4d, (byte)0x54, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
115 |
(byte)0x77, (byte)0xcc, (byte)0x84, (byte)0x09, (byte)0xf3, (byte)0x11, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
116 |
(byte)0x0d, (byte)0x54, (byte)0xed, (byte)0x85, (byte)0x39, (byte)0xa9, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
117 |
(byte)0xca, (byte)0xa8, (byte)0xea, (byte)0xae, (byte)0x19, (byte)0x9c, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
118 |
(byte)0x75, (byte)0xdb, (byte)0x88, (byte)0xb8, (byte)0x04, (byte)0x8d, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
119 |
(byte)0x54, (byte)0xc6, (byte)0xa4, (byte)0x80, (byte)0xf8, (byte)0x93, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
120 |
(byte)0xf0, (byte)0xdb, (byte)0x19, (byte)0xef, (byte)0xd7, (byte)0x87, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
121 |
(byte)0x8a, (byte)0x8f, (byte)0x5a, (byte)0x09, (byte)0x2e, (byte)0x54, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
122 |
(byte)0xf3, (byte)0x45, (byte)0x24, (byte)0x29 |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
123 |
}; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
124 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
125 |
private static final byte EXP_P[] = { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
126 |
(byte)0x6a, (byte)0xd1, (byte)0x25, (byte)0x80, (byte)0x18, (byte)0x33, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
127 |
(byte)0x3c, (byte)0x2b, (byte)0x44, (byte)0x19, (byte)0xfe, (byte)0xa5, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
128 |
(byte)0x40, (byte)0x03, (byte)0xc4, (byte)0xfc, (byte)0xb3, (byte)0x9c, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
129 |
(byte)0xef, (byte)0x07, (byte)0x99, (byte)0x58, (byte)0x17, (byte)0xc1, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
130 |
(byte)0x44, (byte)0xa3, (byte)0x15, (byte)0x7d, (byte)0x7b, (byte)0x22, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
131 |
(byte)0x22, (byte)0xdf, (byte)0x03, (byte)0x58, (byte)0x66, (byte)0xf5, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
132 |
(byte)0x24, (byte)0x54, (byte)0x52, (byte)0x91, (byte)0x2d, (byte)0x76, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
133 |
(byte)0xfe, (byte)0x63, (byte)0x64, (byte)0x4e, (byte)0x0f, (byte)0x50, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
134 |
(byte)0x2b, (byte)0x65, (byte)0x79, (byte)0x1f, (byte)0xf1, (byte)0xbf, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
135 |
(byte)0xc7, (byte)0x41, (byte)0x26, (byte)0xcc, (byte)0xc6, (byte)0x1c, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
136 |
(byte)0xa9, (byte)0x83, (byte)0x6f, (byte)0x03 |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
137 |
}; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
138 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
139 |
private static final byte EXP_Q[] = { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
140 |
(byte)0x12, (byte)0x84, (byte)0x1a, (byte)0x99, (byte)0xce, (byte)0x9a, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
141 |
(byte)0x8b, (byte)0x58, (byte)0xcc, (byte)0x47, (byte)0x43, (byte)0xdf, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
142 |
(byte)0x77, (byte)0xbb, (byte)0xd3, (byte)0x20, (byte)0xae, (byte)0xe4, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
143 |
(byte)0x2e, (byte)0x63, (byte)0x67, (byte)0xdc, (byte)0xf7, (byte)0x5f, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
144 |
(byte)0x3f, (byte)0x83, (byte)0x27, (byte)0xb7, (byte)0x14, (byte)0x52, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
145 |
(byte)0x56, (byte)0xbf, (byte)0xc3, (byte)0x65, (byte)0x06, (byte)0xe1, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
146 |
(byte)0x03, (byte)0xcc, (byte)0x93, (byte)0x57, (byte)0x09, (byte)0x7b, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
147 |
(byte)0x6f, (byte)0xe8, (byte)0x81, (byte)0x4a, (byte)0x2c, (byte)0xb7, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
148 |
(byte)0x43, (byte)0xa9, (byte)0x20, (byte)0x1d, (byte)0xf6, (byte)0x56, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
149 |
(byte)0x8b, (byte)0xcc, (byte)0xe5, (byte)0x4c, (byte)0xd5, (byte)0x4f, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
150 |
(byte)0x74, (byte)0x67, (byte)0x29, (byte)0x51 |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
151 |
}; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
152 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
153 |
private static final byte CRT_COEFF[] = { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
154 |
(byte)0x23, (byte)0xab, (byte)0xf4, (byte)0x03, (byte)0x2f, (byte)0x29, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
155 |
(byte)0x95, (byte)0x74, (byte)0xac, (byte)0x1a, (byte)0x33, (byte)0x96, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
156 |
(byte)0x62, (byte)0xed, (byte)0xf7, (byte)0xf6, (byte)0xae, (byte)0x07, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
157 |
(byte)0x2a, (byte)0x2e, (byte)0xe8, (byte)0xab, (byte)0xfb, (byte)0x1e, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
158 |
(byte)0xb9, (byte)0xb2, (byte)0x88, (byte)0x1e, (byte)0x85, (byte)0x05, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
159 |
(byte)0x42, (byte)0x64, (byte)0x03, (byte)0xb2, (byte)0x8b, (byte)0xc1, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
160 |
(byte)0x81, (byte)0x75, (byte)0xd7, (byte)0xba, (byte)0xaa, (byte)0xd4, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
161 |
(byte)0x31, (byte)0x3c, (byte)0x8a, (byte)0x96, (byte)0x23, (byte)0x9d, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
162 |
(byte)0x3f, (byte)0x06, (byte)0x3e, (byte)0x44, (byte)0xa9, (byte)0x62, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
163 |
(byte)0x2f, (byte)0x61, (byte)0x5a, (byte)0x51, (byte)0x82, (byte)0x2c, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
164 |
(byte)0x04, (byte)0x85, (byte)0x73, (byte)0xd1 |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
165 |
}; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
166 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
167 |
private static KeyPair genRSAKey(int keyLength) throws Exception { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
168 |
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA"); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
169 |
kpg.initialize(keyLength); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
170 |
return kpg.generateKeyPair(); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
171 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
172 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
173 |
private static KeyPair genPredefinedRSAKeyPair() throws Exception { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
174 |
KeyFactory kf = KeyFactory.getInstance("RSA"); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
175 |
BigInteger mod = new BigInteger(MOD); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
176 |
BigInteger pub = new BigInteger(PUB_EXP); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
177 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
178 |
PrivateKey privKey = kf.generatePrivate |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
179 |
(new RSAPrivateCrtKeySpec |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
180 |
(mod, pub, new BigInteger(PRIV_EXP), |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
181 |
new BigInteger(PRIME_P), new BigInteger(PRIME_Q), |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
182 |
new BigInteger(EXP_P), new BigInteger(EXP_Q), |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
183 |
new BigInteger(CRT_COEFF))); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
184 |
PublicKey pubKey = kf.generatePublic(new RSAPublicKeySpec(mod, pub)); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
185 |
return new KeyPair(pubKey, privKey); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
186 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
187 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
188 |
private static final String CIP_ALGOS[] = { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
189 |
"RSA/ECB/NoPadding", |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
190 |
"RSA/ECB/PKCS1Padding" |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
191 |
}; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
192 |
private static final int INPUT_SIZE_REDUCTION[] = { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
193 |
0, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
194 |
11, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
195 |
}; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
196 |
private static final String SIG_ALGOS[] = { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
197 |
"MD5WithRSA", |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
198 |
"SHA1WithRSA", |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
199 |
"SHA256WithRSA", |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
200 |
"SHA384WithRSA", |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
201 |
"SHA512WithRSA" |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
202 |
}; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
203 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
204 |
private static KeyPair kp[] = null; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
205 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
206 |
public static void main(String argv[]) throws Exception { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
207 |
main(new TestRSA(), null); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
208 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
209 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
210 |
public void doTest(Provider prov) throws Exception { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
211 |
// first test w/ predefine KeyPair |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
212 |
KeyPair pkp = genPredefinedRSAKeyPair(); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
213 |
System.out.println("Test against Predefined RSA Key Pair"); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
214 |
testCipher(pkp, 128, true, prov); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
215 |
testSignature(pkp, true, prov); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
216 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
217 |
for (int i = 0; i < 10; i++) { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
218 |
// then test w/ various key lengths |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
219 |
int keyLens[] = { 1024, 2048 }; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
220 |
kp = new KeyPair[keyLens.length]; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
221 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
222 |
testCipher(keyLens, false, prov); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
223 |
testSignature(keyLens, false, prov); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
224 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
225 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
226 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
227 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
228 |
private static void testCipher(KeyPair kp, int inputSizeInBytes, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
229 |
boolean checkInterop, Provider prov) |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
230 |
throws Exception { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
231 |
Cipher c1, c2; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
232 |
for (int i = 0; i < CIP_ALGOS.length; i++) { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
233 |
String algo = CIP_ALGOS[i]; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
234 |
try { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
235 |
c1 = Cipher.getInstance(algo, prov); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
236 |
} catch (NoSuchAlgorithmException nsae) { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
237 |
System.out.println("Skip unsupported Cipher algo: " + algo); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
238 |
continue; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
239 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
240 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
241 |
if (checkInterop) { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
242 |
c2 = Cipher.getInstance(algo, "SunJCE"); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
243 |
} else { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
244 |
c2 = Cipher.getInstance(algo, prov); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
245 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
246 |
byte[] data = Arrays.copyOf |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
247 |
(PLAINTEXT, inputSizeInBytes - INPUT_SIZE_REDUCTION[i]); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
248 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
249 |
testEncryption(c1, c2, kp, data); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
250 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
251 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
252 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
253 |
private static void testCipher(int keyLens[], boolean checkInterop, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
254 |
Provider prov) |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
255 |
throws Exception { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
256 |
// RSA CipherText will always differ due to the random nonce in padding |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
257 |
// so we check whether both |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
258 |
// 1) Java Encrypt/C Decrypt |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
259 |
// 2) C Encrypt/Java Decrypt |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
260 |
// works |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
261 |
Cipher c1, c2; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
262 |
for (int i = 0; i < CIP_ALGOS.length; i++) { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
263 |
String algo = CIP_ALGOS[i]; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
264 |
try { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
265 |
c1 = Cipher.getInstance(algo, prov); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
266 |
} catch (NoSuchAlgorithmException nsae) { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
267 |
System.out.println("Skip unsupported Cipher algo: " + algo); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
268 |
continue; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
269 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
270 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
271 |
if (checkInterop) { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
272 |
c2 = Cipher.getInstance(algo, "SunJCE"); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
273 |
} else { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
274 |
c2 = Cipher.getInstance(algo, prov); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
275 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
276 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
277 |
for (int h = 0; h < keyLens.length; h++) { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
278 |
// Defer key pair generation until now when it'll soon be used. |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
279 |
if (kp[h] == null) { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
280 |
kp[h] = genRSAKey(keyLens[h]); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
281 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
282 |
System.out.println("\tTesting Cipher " + algo + " w/ KeySize " + keyLens[h]); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
283 |
byte[] data = Arrays.copyOf |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
284 |
(PLAINTEXT, keyLens[h]/8 - INPUT_SIZE_REDUCTION[i]); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
285 |
testEncryption(c1, c2, kp[h], data); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
286 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
287 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
288 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
289 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
290 |
private static void testEncryption(Cipher c1, Cipher c2, KeyPair kp, byte[] data) |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
291 |
throws Exception { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
292 |
// C1 Encrypt + C2 Decrypt |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
293 |
byte[] out1 = null; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
294 |
byte[] recoveredText = null; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
295 |
try { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
296 |
c1.init(Cipher.ENCRYPT_MODE, kp.getPublic()); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
297 |
out1 = c1.doFinal(data); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
298 |
c2.init(Cipher.DECRYPT_MODE, kp.getPrivate()); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
299 |
recoveredText = c2.doFinal(out1); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
300 |
} catch (Exception ex) { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
301 |
System.out.println("\tDEC ERROR: unexpected exception"); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
302 |
ex.printStackTrace(); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
303 |
throw ex; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
304 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
305 |
if(!Arrays.equals(recoveredText, data)) { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
306 |
throw new RuntimeException("\tDEC ERROR: different PT bytes!"); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
307 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
308 |
// C2 Encrypt + C1 Decrypt |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
309 |
byte[] cipherText = null; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
310 |
try { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
311 |
c2.init(Cipher.ENCRYPT_MODE, kp.getPublic()); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
312 |
cipherText = c2.doFinal(data); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
313 |
c1.init(Cipher.DECRYPT_MODE, kp.getPrivate()); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
314 |
try { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
315 |
out1 = c1.doFinal(cipherText); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
316 |
} catch (Exception ex) { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
317 |
System.out.println("\tENC ERROR: invalid encrypted output"); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
318 |
ex.printStackTrace(); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
319 |
throw ex; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
320 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
321 |
} catch (Exception ex) { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
322 |
System.out.println("\tENC ERROR: unexpected exception"); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
323 |
ex.printStackTrace(); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
324 |
throw ex; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
325 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
326 |
if (!Arrays.equals(out1, data)) { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
327 |
throw new RuntimeException("\tENC ERROR: Decrypted result DIFF!"); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
328 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
329 |
System.out.println("\t=> PASS"); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
330 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
331 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
332 |
private static void testSignature(KeyPair kp, boolean checkInterop, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
333 |
Provider prov) throws Exception { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
334 |
byte[] data = PLAINTEXT; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
335 |
Signature sig1, sig2; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
336 |
for (int i = 0; i < SIG_ALGOS.length; i++) { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
337 |
String algo = SIG_ALGOS[i]; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
338 |
try { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
339 |
sig1 = Signature.getInstance(algo, prov); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
340 |
} catch (NoSuchAlgorithmException nsae) { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
341 |
System.out.println("Skip unsupported Signature algo: " + algo); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
342 |
continue; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
343 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
344 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
345 |
if (checkInterop) { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
346 |
sig2 = Signature.getInstance(algo, "SunRsaSign"); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
347 |
} else { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
348 |
sig2 = Signature.getInstance(algo, prov); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
349 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
350 |
testSigning(sig1, sig2, kp, data); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
351 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
352 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
353 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
354 |
private static void testSignature(int keyLens[], boolean checkInterop, |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
355 |
Provider prov) throws Exception { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
356 |
byte[] data = PLAINTEXT; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
357 |
Signature sig1, sig2; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
358 |
for (int i = 0; i < SIG_ALGOS.length; i++) { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
359 |
String algo = SIG_ALGOS[i]; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
360 |
try { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
361 |
sig1 = Signature.getInstance(algo, prov); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
362 |
} catch (NoSuchAlgorithmException nsae) { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
363 |
System.out.println("Skip unsupported Signature algo: " + algo); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
364 |
continue; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
365 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
366 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
367 |
if (checkInterop) { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
368 |
sig2 = Signature.getInstance(algo, "SunRsaSign"); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
369 |
} else { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
370 |
sig2 = Signature.getInstance(algo, prov); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
371 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
372 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
373 |
for (int h = 0; h < keyLens.length; h++) { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
374 |
// Defer key pair generation until now when it'll soon be used. |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
375 |
if (kp[h] == null) { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
376 |
kp[h] = genRSAKey(keyLens[h]); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
377 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
378 |
System.out.println("\tTesting Signature " + algo + " w/ KeySize " + keyLens[h]); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
379 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
380 |
testSigning(sig1, sig2, kp[h], data); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
381 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
382 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
383 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
384 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
385 |
private static void testSigning(Signature sig1, Signature sig2, KeyPair kp, byte[] data) |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
386 |
throws Exception { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
387 |
boolean sameSig = false; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
388 |
byte[] out = null; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
389 |
try { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
390 |
sig1.initSign(kp.getPrivate()); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
391 |
sig1.update(data); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
392 |
out = sig1.sign(); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
393 |
} catch (Exception ex) { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
394 |
System.out.println("\tSIGN ERROR: unexpected exception!"); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
395 |
ex.printStackTrace(); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
396 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
397 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
398 |
sig2.initSign(kp.getPrivate()); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
399 |
sig2.update(data); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
400 |
byte[] out2 = sig2.sign(); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
401 |
if (!Arrays.equals(out2, out)) { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
402 |
throw new RuntimeException("\tSIGN ERROR: Signature DIFF!"); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
403 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
404 |
|
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
405 |
boolean verify = false; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
406 |
try { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
407 |
System.out.println("\tVERIFY1 using native out"); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
408 |
sig1.initVerify(kp.getPublic()); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
409 |
sig1.update(data); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
410 |
verify = sig1.verify(out); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
411 |
if (!verify) { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
412 |
throw new RuntimeException("VERIFY1 FAIL!"); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
413 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
414 |
} catch (Exception ex) { |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
415 |
System.out.println("\tVERIFY1 ERROR: unexpected exception!"); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
416 |
ex.printStackTrace(); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
417 |
throw ex; |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
418 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
419 |
System.out.println("\t=> PASS"); |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
420 |
} |
85131f3172a1
7088989: Improve the performance for T4 by utilizing the newly provided crypto APIs
valeriep
parents:
diff
changeset
|
421 |
} |