Skip to content

Commit 039e73f

Browse files
committed
8346736: Java Security Standard Algorithm Names spec should include key algorithm names
Reviewed-by: mullan, hchao
1 parent aba60a9 commit 039e73f

File tree

9 files changed

+75
-33
lines changed

9 files changed

+75
-33
lines changed

src/java.base/share/classes/java/security/Key.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2025, 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
@@ -120,10 +120,9 @@ public interface Key extends java.io.Serializable {
120120

121121
/**
122122
* Returns the standard algorithm name for this key. For
123-
* example, "DSA" would indicate that this key is a DSA key.
124-
* See the key related sections (KeyFactory, KeyGenerator,
125-
* KeyPairGenerator, and SecretKeyFactory) in the <a href=
126-
* "{@docRoot}/../specs/security/standard-names.html">
123+
* example, "RSA" would indicate that this key is an RSA key.
124+
* See the Key Algorithms section in the
125+
* <a href="{@docRoot}/../specs/security/standard-names.html#key-algorithms">
127126
* Java Security Standard Algorithm Names Specification</a>
128127
* for information about standard key algorithm names.
129128
*

src/java.base/share/classes/java/security/spec/EncodedKeySpec.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,17 @@ public EncodedKeySpec(byte[] encodedKey) {
7474
*
7575
* @param encodedKey the encoded key. The contents of the
7676
* array are copied to protect against subsequent modification.
77-
* @param algorithm the algorithm name of the encoded key
78-
* See the KeyFactory section in the <a href=
79-
* "{@docRoot}/../specs/security/standard-names.html#keyfactory-algorithms">
77+
* @param algorithm the algorithm name of the encoded key.
78+
* See the AsymmetricKey Algorithms section in the
79+
* <a href="{@docRoot}/../specs/security/standard-names.html#asymmetrickey-algorithms">
8080
* Java Security Standard Algorithm Names Specification</a>
81-
* for information about standard algorithm names.
81+
* for information about standard asymmetric key algorithm names.
8282
* @spec security/standard-names.html Java Security Standard Algorithm Names
8383
* @throws NullPointerException if {@code encodedKey}
8484
* or {@code algorithm} is null.
8585
* @throws IllegalArgumentException if {@code algorithm} is
8686
* the empty string {@code ""}
87+
* @spec security/standard-names.html Java Security Standard Algorithm Names
8788
* @since 9
8889
*/
8990
protected EncodedKeySpec(byte[] encodedKey, String algorithm) {

src/java.base/share/classes/java/security/spec/PKCS8EncodedKeySpec.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,17 @@ public PKCS8EncodedKeySpec(byte[] encodedKey) {
8383
* @param encodedKey the key, which is assumed to be
8484
* encoded according to the PKCS #8 standard. The contents of
8585
* the array are copied to protect against subsequent modification.
86-
* @param algorithm the algorithm name of the encoded private key
87-
* See the KeyFactory section in the <a href=
88-
* "{@docRoot}/../specs/security/standard-names.html#keyfactory-algorithms">
86+
* @param algorithm the algorithm name of the encoded private key.
87+
* See the AsymmetricKey Algorithms section in the
88+
* <a href="{@docRoot}/../specs/security/standard-names.html#asymmetrickey-algorithms">
8989
* Java Security Standard Algorithm Names Specification</a>
90-
* for information about standard algorithm names.
90+
* for information about standard asymmetric key algorithm names.
9191
* @spec security/standard-names.html Java Security Standard Algorithm Names
9292
* @throws NullPointerException if {@code encodedKey}
9393
* or {@code algorithm} is null.
9494
* @throws IllegalArgumentException if {@code algorithm} is
9595
* the empty string {@code ""}
96+
* @spec security/standard-names.html Java Security Standard Algorithm Names
9697
* @since 9
9798
*/
9899
public PKCS8EncodedKeySpec(byte[] encodedKey, String algorithm) {

src/java.base/share/classes/java/security/spec/X509EncodedKeySpec.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,17 @@ public X509EncodedKeySpec(byte[] encodedKey) {
7373
* @param encodedKey the key, which is assumed to be
7474
* encoded according to the X.509 standard. The contents of the
7575
* array are copied to protect against subsequent modification.
76-
* @param algorithm the algorithm name of the encoded public key
77-
* See the KeyFactory section in the <a href=
78-
* "{@docRoot}/../specs/security/standard-names.html#keyfactory-algorithms">
76+
* @param algorithm the algorithm name of the encoded public key.
77+
* See the AsymmetricKey Algorithms section in the
78+
* <a href="{@docRoot}/../specs/security/standard-names.html#asymmetrickey-algorithms">
7979
* Java Security Standard Algorithm Names Specification</a>
80-
* for information about standard algorithm names.
80+
* for information about standard asymmetric key algorithm names.
8181
* @spec security/standard-names.html Java Security Standard Algorithm Names
8282
* @throws NullPointerException if {@code encodedKey}
8383
* or {@code algorithm} is null.
8484
* @throws IllegalArgumentException if {@code algorithm} is
8585
* the empty string {@code ""}
86+
* @spec security/standard-names.html Java Security Standard Algorithm Names
8687
* @since 9
8788
*/
8889
public X509EncodedKeySpec(byte[] encodedKey, String algorithm) {

src/java.base/share/classes/javax/crypto/KDF.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,11 @@ private static KDF handleException(NoSuchAlgorithmException e)
483483
* Derives a key, returned as a {@code SecretKey} object.
484484
*
485485
* @param alg
486-
* the algorithm of the resultant {@code SecretKey} object
486+
* the algorithm of the resultant {@code SecretKey} object.
487+
* See the SecretKey Algorithms section in the
488+
* <a href="{@docRoot}/../specs/security/standard-names.html#secretkey-algorithms">
489+
* Java Security Standard Algorithm Names Specification</a>
490+
* for information about standard secret key algorithm names.
487491
* @param derivationSpec
488492
* the object describing the inputs to the derivation function
489493
*
@@ -500,6 +504,7 @@ private static KDF handleException(NoSuchAlgorithmException e)
500504
*
501505
* @see <a href="#DelayedProviderSelection">Delayed Provider
502506
* Selection</a>
507+
* @spec security/standard-names.html Java Security Standard Algorithm Names
503508
*
504509
*/
505510
public SecretKey deriveKey(String alg,

src/java.base/share/classes/javax/crypto/KDFSpi.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2024, 2025, 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
@@ -115,7 +115,11 @@ protected KDFSpi(KDFParameters kdfParameters)
115115
* result of {@code deriveData}.
116116
*
117117
* @param alg
118-
* the algorithm of the resultant {@code SecretKey} object
118+
* the algorithm of the resultant {@code SecretKey} object.
119+
* See the SecretKey Algorithms section in the
120+
* <a href="{@docRoot}/../specs/security/standard-names.html#secretkey-algorithms">
121+
* Java Security Standard Algorithm Names Specification</a>
122+
* for information about standard secret key algorithm names.
119123
* @param derivationSpec
120124
* derivation parameters
121125
*
@@ -129,6 +133,7 @@ protected KDFSpi(KDFParameters kdfParameters)
129133
* if {@code alg} is empty or invalid
130134
* @throws NullPointerException
131135
* if {@code alg} or {@code derivationSpec} is null
136+
* @spec security/standard-names.html Java Security Standard Algorithm Names
132137
*/
133138
protected abstract SecretKey engineDeriveKey(String alg,
134139
AlgorithmParameterSpec derivationSpec)
@@ -154,4 +159,4 @@ protected abstract byte[] engineDeriveData(
154159
AlgorithmParameterSpec derivationSpec)
155160
throws InvalidAlgorithmParameterException;
156161

157-
}
162+
}

src/java.base/share/classes/javax/crypto/KEM.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,13 @@ public Encapsulated encapsulate() {
222222
* to be returned, inclusive
223223
* @param to the final index of the shared secret byte array
224224
* to be returned, exclusive
225-
* @param algorithm the algorithm name for the secret key that is returned
225+
* @param algorithm the algorithm name for the secret key that is returned.
226+
* See the SecretKey Algorithms section in the
227+
* <a href="{@docRoot}/../specs/security/standard-names.html#secretkey-algorithms">
228+
* Java Security Standard Algorithm Names Specification</a>
229+
* for information about standard secret key algorithm names.
230+
* Specify "Generic" if the output will be used as the input keying
231+
* material of a key derivation function (KDF).
226232
* @return a {@link Encapsulated} object containing a portion of
227233
* the shared secret, key encapsulation message, and optional
228234
* parameters. The portion of the shared secret is a
@@ -237,6 +243,7 @@ public Encapsulated encapsulate() {
237243
* @throws UnsupportedOperationException if the combination of
238244
* {@code from}, {@code to}, and {@code algorithm}
239245
* is not supported by the encapsulator
246+
* @spec security/standard-names.html Java Security Standard Algorithm Names
240247
*/
241248
public Encapsulated encapsulate(int from, int to, String algorithm) {
242249
return e.engineEncapsulate(from, to, algorithm);
@@ -345,7 +352,13 @@ public SecretKey decapsulate(byte[] encapsulation) throws DecapsulateException {
345352
* to be returned, inclusive
346353
* @param to the final index of the shared secret byte array
347354
* to be returned, exclusive
348-
* @param algorithm the algorithm name for the secret key that is returned
355+
* @param algorithm the algorithm name for the secret key that is returned.
356+
* See the SecretKey Algorithms section in the
357+
* <a href="{@docRoot}/../specs/security/standard-names.html#secretkey-algorithms">
358+
* Java Security Standard Algorithm Names Specification</a>
359+
* for information about standard secret key algorithm names.
360+
* Specify "Generic" if the output will be used as the input keying
361+
* material of a key derivation function (KDF).
349362
* @return a portion of the shared secret as a {@code SecretKey}
350363
* containing the bytes of the secret ranging from {@code from}
351364
* to {@code to}, exclusive, and an algorithm name as specified.
@@ -361,6 +374,7 @@ public SecretKey decapsulate(byte[] encapsulation) throws DecapsulateException {
361374
* @throws UnsupportedOperationException if the combination of
362375
* {@code from}, {@code to}, and {@code algorithm}
363376
* is not supported by the decapsulator
377+
* @spec security/standard-names.html Java Security Standard Algorithm Names
364378
*/
365379
public SecretKey decapsulate(byte[] encapsulation,
366380
int from, int to, String algorithm)

src/java.base/share/classes/javax/crypto/KEMSpi.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2025, 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
@@ -129,7 +129,13 @@ interface EncapsulatorSpi {
129129
* to be returned, inclusive
130130
* @param to the final index of the shared secret byte array
131131
* to be returned, exclusive
132-
* @param algorithm the algorithm name for the secret key that is returned
132+
* @param algorithm the algorithm name for the secret key that is returned.
133+
* See the SecretKey Algorithms section in the
134+
* <a href="{@docRoot}/../specs/security/standard-names.html#secretkey-algorithms">
135+
* Java Security Standard Algorithm Names Specification</a>
136+
* for information about standard secret key algorithm names.
137+
* Specify "Generic" if the output will be used as the input keying
138+
* material of a key derivation function (KDF).
133139
* @return an {@link KEM.Encapsulated} object containing a portion of
134140
* the shared secret as a key with the specified algorithm,
135141
* key encapsulation message, and optional parameters.
@@ -141,6 +147,7 @@ interface EncapsulatorSpi {
141147
* is not supported by the encapsulator
142148
* @see KEM.Encapsulated
143149
* @see KEM.Encapsulator#encapsulate(int, int, String)
150+
* @spec security/standard-names.html Java Security Standard Algorithm Names
144151
*/
145152
KEM.Encapsulated engineEncapsulate(int from, int to, String algorithm);
146153

@@ -188,7 +195,13 @@ interface DecapsulatorSpi {
188195
* to be returned, inclusive
189196
* @param to the final index of the shared secret byte array
190197
* to be returned, exclusive
191-
* @param algorithm the algorithm name for the secret key that is returned
198+
* @param algorithm the algorithm name for the secret key that is returned.
199+
* See the SecretKey Algorithms section in the
200+
* <a href="{@docRoot}/../specs/security/standard-names.html#secretkey-algorithms">
201+
* Java Security Standard Algorithm Names Specification</a>
202+
* for information about standard secret key algorithm names.
203+
* Specify "Generic" if the output will be used as the input keying
204+
* material of a key derivation function (KDF).
192205
* @return a portion of the shared secret as a {@code SecretKey} with
193206
* the specified algorithm
194207
* @throws DecapsulateException if an error occurs during the
@@ -201,6 +214,7 @@ interface DecapsulatorSpi {
201214
* {@code from}, {@code to}, and {@code algorithm}
202215
* is not supported by the decapsulator
203216
* @see KEM.Decapsulator#decapsulate(byte[], int, int, String)
217+
* @spec security/standard-names.html Java Security Standard Algorithm Names
204218
*/
205219
SecretKey engineDecapsulate(byte[] encapsulation, int from, int to, String algorithm)
206220
throws DecapsulateException;

src/java.base/share/classes/javax/crypto/spec/SecretKeySpec.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2025, 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
@@ -93,9 +93,10 @@ public class SecretKeySpec implements KeySpec, SecretKey {
9393
* the array are copied to protect against subsequent modification.
9494
* @param algorithm the name of the secret-key algorithm to be associated
9595
* with the given key material.
96-
* See the <a href="{@docRoot}/../specs/security/standard-names.html">
97-
* Java Security Standard Algorithm Names</a> document
98-
* for information about standard algorithm names.
96+
* See the SecretKey Algorithms section in the
97+
* <a href="{@docRoot}/../specs/security/standard-names.html#secretkey-algorithms">
98+
* Java Security Standard Algorithm Names Specification</a>
99+
* for information about standard secret key algorithm names.
99100
* @exception IllegalArgumentException if <code>algorithm</code>
100101
* is null or <code>key</code> is null or empty.
101102
*
@@ -137,9 +138,10 @@ public SecretKeySpec(byte[] key, String algorithm) {
137138
* @param len the length of the key material.
138139
* @param algorithm the name of the secret-key algorithm to be associated
139140
* with the given key material.
140-
* See the <a href="{@docRoot}/../specs/security/standard-names.html">
141-
* Java Security Standard Algorithm Names</a> document
142-
* for information about standard algorithm names.
141+
* See the SecretKey Algorithms section in the
142+
* <a href="{@docRoot}/../specs/security/standard-names.html#secretkey-algorithms">
143+
* Java Security Standard Algorithm Names Specification</a>
144+
* for information about standard secret key algorithm names.
143145
* @exception IllegalArgumentException if <code>algorithm</code>
144146
* is null or <code>key</code> is null, empty, or too short,
145147
* i.e. {@code key.length-offset<len}.

0 commit comments

Comments
 (0)