11/*
2- * Copyright (c) 2009, 2021 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2009, 2022 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
@@ -80,9 +80,6 @@ abstract class ECDSASignature extends SignatureSpi {
8080 // public key, if initialized for verifying
8181 private ECPublicKey publicKey ;
8282
83- // signature parameters
84- private ECParameterSpec sigParams = null ;
85-
8683 // The format. true for the IEEE P1363 format. false (default) for ASN.1
8784 private final boolean p1363Format ;
8885
@@ -347,10 +344,6 @@ public SHA3_512inP1363Format() {
347344 protected void engineInitVerify (PublicKey publicKey )
348345 throws InvalidKeyException {
349346 ECPublicKey key = (ECPublicKey ) ECKeyFactory .toECKey (publicKey );
350- if (!isCompatible (this .sigParams , key .getParams ())) {
351- throw new InvalidKeyException ("Key params does not match signature params" );
352- }
353-
354347 // Should check that the supplied key is appropriate for signature
355348 // algorithm (e.g. P-256 for SHA256withECDSA)
356349 this .publicKey = key ;
@@ -370,10 +363,6 @@ protected void engineInitSign(PrivateKey privateKey)
370363 protected void engineInitSign (PrivateKey privateKey , SecureRandom random )
371364 throws InvalidKeyException {
372365 ECPrivateKey key = (ECPrivateKey ) ECKeyFactory .toECKey (privateKey );
373- if (!isCompatible (this .sigParams , key .getParams ())) {
374- throw new InvalidKeyException ("Key params does not match signature params" );
375- }
376-
377366 ECUtil .checkPrivateKey (key );
378367 // Should check that the supplied key is appropriate for signature
379368 // algorithm (e.g. P-256 for SHA256withECDSA)
@@ -430,15 +419,6 @@ protected void engineUpdate(ByteBuffer byteBuffer) {
430419 needsReset = true ;
431420 }
432421
433- private static boolean isCompatible (ECParameterSpec sigParams ,
434- ECParameterSpec keyParams ) {
435- if (sigParams == null ) {
436- // no restriction on key param
437- return true ;
438- }
439- return ECUtil .equals (sigParams , keyParams );
440- }
441-
442422 private byte [] signDigestImpl (ECDSAOperations ops , int seedBits ,
443423 byte [] digest , ECPrivateKey priv , SecureRandom random )
444424 throws SignatureException {
@@ -528,17 +508,21 @@ protected void engineSetParameter(String param, Object value)
528508
529509 @ Override
530510 protected void engineSetParameter (AlgorithmParameterSpec params )
531- throws InvalidAlgorithmParameterException {
532- if (params != null && !(params instanceof ECParameterSpec )) {
533- throw new InvalidAlgorithmParameterException ("No parameter accepted" );
511+ throws InvalidAlgorithmParameterException {
512+ // Interop: some certificates include parameters in an ECDSA
513+ // algorithm identifier. We only accept one matching the key.
514+ if (params == null ) {
515+ return ;
516+ }
517+ if (!(params instanceof ECParameterSpec ecparams )) {
518+ throw new InvalidAlgorithmParameterException (
519+ "Parameters must be of type ECParameterSpec" );
534520 }
535521 ECKey key = (this .privateKey == null ? this .publicKey : this .privateKey );
536- if ((key != null ) && !isCompatible (( ECParameterSpec ) params , key .getParams ())) {
522+ if ((key != null ) && !ECUtil . equals ( ecparams , key .getParams ())) {
537523 throw new InvalidAlgorithmParameterException
538524 ("Signature params does not match key params" );
539525 }
540-
541- sigParams = (ECParameterSpec ) params ;
542526 }
543527
544528 // get parameter, not supported. See JCA doc
@@ -551,16 +535,9 @@ protected Object engineGetParameter(String param)
551535
552536 @ Override
553537 protected AlgorithmParameters engineGetParameters () {
554- if (sigParams == null ) {
555- return null ;
556- }
557- try {
558- AlgorithmParameters ap = AlgorithmParameters .getInstance ("EC" );
559- ap .init (sigParams );
560- return ap ;
561- } catch (Exception e ) {
562- // should never happen
563- throw new ProviderException ("Error retrieving EC parameters" , e );
564- }
538+ // Always return null even if setParameter is called before.
539+ // According to RFC 3279 2.2.3 and RFC 5758 3.2, no parameters is
540+ // defined for ECDSA AlgorithmIdentifiers.
541+ return null ;
565542 }
566543}
0 commit comments