1 /* |
1 /* |
2 * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
174 verify(provider, "SHA1withECDSA", publicKey, data2Raw, sig, false); |
174 verify(provider, "SHA1withECDSA", publicKey, data2Raw, sig, false); |
175 |
175 |
176 verify(provider, "NONEwithECDSA", publicKey, data1SHA, sig, true); |
176 verify(provider, "NONEwithECDSA", publicKey, data1SHA, sig, true); |
177 verify(provider, "NONEwithECDSA", publicKey, data2SHA, sig, false); |
177 verify(provider, "NONEwithECDSA", publicKey, data2SHA, sig, false); |
178 |
178 |
179 testSigning(provider, privateKey, publicKey); |
179 System.out.println("Testing with default signature format: ASN.1"); |
180 } |
180 testSigning(provider, privateKey, publicKey, false); |
181 |
181 |
182 private void testSigning(Provider provider, PrivateKey privateKey, |
182 System.out.println("Testing with IEEE P1363 signature format"); |
183 PublicKey publicKey) throws Exception { |
183 testSigning(provider, privateKey, publicKey, true); |
|
184 } |
|
185 |
|
186 private void testSigning(Provider provider, |
|
187 PrivateKey privateKey, |
|
188 PublicKey publicKey, |
|
189 boolean p1363Format) throws Exception { |
184 byte[] data = new byte[2048]; |
190 byte[] data = new byte[2048]; |
185 new Random().nextBytes(data); |
191 new Random().nextBytes(data); |
186 |
192 |
187 // sign random data using SHA1withECDSA and verify using |
193 // sign random data using SHA1withECDSA and verify using |
188 // SHA1withECDSA and NONEwithECDSA |
194 // SHA1withECDSA and NONEwithECDSA |
189 Signature s = Signature.getInstance("SHA1withECDSA", provider); |
195 Signature s; |
|
196 if (p1363Format) { |
|
197 s = Signature.getInstance("SHA1withECDSAinP1363Format", provider); |
|
198 } else { |
|
199 s = Signature.getInstance("SHA1withECDSA", provider); |
|
200 } |
190 s.initSign(privateKey); |
201 s.initSign(privateKey); |
191 s.update(data); |
202 s.update(data); |
192 byte[] s1 = s.sign(); |
203 byte[] s1 = s.sign(); |
193 |
204 |
194 s.initVerify(publicKey); |
205 s.initVerify(publicKey); |
195 s.update(data); |
206 s.update(data); |
196 if (!s.verify(s1)) { |
207 if (!s.verify(s1)) { |
197 throw new Exception("Sign/verify 1 failed"); |
208 throw new Exception("Sign/verify 1 failed"); |
198 } |
209 } |
199 |
210 |
200 s = Signature.getInstance("NONEwithECDSA", provider); |
211 if (p1363Format) { |
|
212 s = Signature.getInstance("NONEwithECDSAinP1363Format", provider); |
|
213 } else { |
|
214 s = Signature.getInstance("NONEwithECDSA", provider); |
|
215 } |
201 MessageDigest md = MessageDigest.getInstance("SHA-1"); |
216 MessageDigest md = MessageDigest.getInstance("SHA-1"); |
202 byte[] digest = md.digest(data); |
217 byte[] digest = md.digest(data); |
203 s.initVerify(publicKey); |
218 s.initVerify(publicKey); |
204 s.update(digest); |
219 s.update(digest); |
205 if (!s.verify(s1)) { |
220 if (!s.verify(s1)) { |