Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
0cbd952
the fix
wangweij Mar 20, 2024
652d63f
no export, params from record to class
wangweij May 17, 2024
36993a3
Merge branch 'master' into 8325448
wangweij May 17, 2024
4419200
disabled algorithms
wangweij Jun 4, 2024
95f658c
remove debug lines
wangweij Jun 4, 2024
ed9f5d0
Merge branch 'master' into 8325448
wangweij Jun 4, 2024
80a188a
spec update
wangweij Dec 19, 2024
e7db8b8
Merge branch 'master' into 8325448
wangweij Dec 19, 2024
6d4bbfa
no scope for td
wangweij Dec 23, 2024
d77a1b2
Use KDF API
wangweij Feb 25, 2025
412efec
Merge branch 'master' into 8325448
wangweij Feb 25, 2025
5877364
add @since 25
wangweij Feb 25, 2025
7e525f1
example and KAT
wangweij Feb 27, 2025
8ae9a52
kevin comments
wangweij Feb 28, 2025
9271265
renames, precise req, more spec, wrappings
wangweij Mar 1, 2025
8342e7d
typo, and other cleanup
wangweij Mar 1, 2025
1839c73
unspecified id is -1 now
wangweij Mar 1, 2025
5b0f319
add mode_auth and mode_auth_psk, tiny spec change
wangweij Mar 3, 2025
9360dfd
of(kdf_id, aead_id) and constants
wangweij Mar 11, 2025
4bb1750
switch to Asserts.assertThrows in test; use traditional javadoc style
wangweij Mar 12, 2025
18e0538
getParameters
wangweij Mar 13, 2025
25d2fb1
remove disabled identifiers check
wangweij Mar 14, 2025
5d15f9d
remove unused imports
wangweij Mar 14, 2025
c578ef5
Merge branch 'master' into 8325448
wangweij Mar 14, 2025
30cbd4d
receiver must specify all algorithm identifiers
wangweij Mar 25, 2025
0796a42
put encapsulation in params from getParameters
wangweij Apr 2, 2025
17dceaa
toString, exportData, spec in HPKEParameters must have algorithm iden…
wangweij Apr 11, 2025
fff8e32
address Sean's comments
wangweij Apr 21, 2025
33a8e13
Merge branch 'master' into 8325448
wangweij Apr 21, 2025
15d0b85
change argument order for exporters, reject null exporter_context
wangweij Apr 22, 2025
a4f59e3
engineGetBlockSize and engineGetOutputSize returns 0 when not initial…
wangweij Apr 24, 2025
f819de2
merge
wangweij May 20, 2025
3906aa0
extract and expand
wangweij Jun 25, 2025
30c7994
no more of()
wangweij Jun 26, 2025
787702d
some spec change
wangweij Jun 27, 2025
653b56c
after initialization
wangweij Jun 27, 2025
e83a4a1
finetune the spec
wangweij Jun 27, 2025
8b13da1
test on SliceableSecretKey; fixed snippet comment
wangweij Aug 12, 2025
5a84603
Merge branch 'master' into 8325448
wangweij Aug 12, 2025
2c86d90
test fix
wangweij Aug 12, 2025
a67d06d
rename variables in a test
wangweij Aug 13, 2025
56730ee
more complete test
wangweij Aug 13, 2025
04a45d4
remove HPKEParameters
wangweij Aug 13, 2025
5b4767b
remove unused imports
wangweij Aug 14, 2025
008a5a6
HPKEParameterSpec.toString with human-readable info
wangweij Aug 15, 2025
2d7631e
put comments in correct places
wangweij Aug 15, 2025
31c3f69
cleaner comments
wangweij Aug 15, 2025
fba0da9
8325448: Hybrid Public Key Encryption
wangweij Aug 22, 2025
b42a855
address Sean's comments
wangweij Aug 26, 2025
4772004
more spec change
wangweij Aug 27, 2025
29cb254
use different exception type
wangweij Aug 27, 2025
8dbc050
receiver to recipient; different to specified
wangweij Aug 28, 2025
cbce830
duplicated "value" words
wangweij Aug 29, 2025
d4c237f
withMethods
wangweij Aug 29, 2025
bdd00bd
algorithm identifier
wangweij Aug 29, 2025
cef5557
cannot reset with withMethods
wangweij Sep 2, 2025
a6949f5
about transformation
wangweij Sep 2, 2025
1ec31cf
Merge branch 'master' into 8325448
wangweij Sep 10, 2025
b86797a
more key checks; some small spec change
wangweij Sep 16, 2025
cca3c8d
Tony's comment
wangweij Oct 27, 2025
8c6cffa
Merge branch 'master' into 8325448
wangweij Oct 27, 2025
b511215
merge
wangweij Nov 5, 2025
4d5b15f
check null and tests
wangweij Nov 7, 2025
52c4d84
java style method names
wangweij Nov 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
361 changes: 223 additions & 138 deletions src/java.base/share/classes/com/sun/crypto/provider/DHKEM.java

Large diffs are not rendered by default.

588 changes: 588 additions & 0 deletions src/java.base/share/classes/com/sun/crypto/provider/HPKE.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ void putEntries() {
ps("Cipher", "PBEWithHmacSHA512/256AndAES_256",
"com.sun.crypto.provider.PBES2Core$HmacSHA512_256AndAES_256");

ps("Cipher", "HPKE", "com.sun.crypto.provider.HPKE");

/*
* Key(pair) Generator engines
*/
Expand Down
443 changes: 443 additions & 0 deletions src/java.base/share/classes/javax/crypto/spec/HPKEParameterSpec.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import javax.crypto.Cipher;
import javax.crypto.spec.HPKEParameterSpec;
import java.nio.charset.StandardCharsets;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.util.Arrays;
import java.util.HexFormat;

class PackageSnippets {
public static void main(String[] args) throws Exception {

// @start region="hpke-spec-example"
// Recipient key pair generation
KeyPairGenerator g = KeyPairGenerator.getInstance("X25519");
KeyPair kp = g.generateKeyPair();

// The HPKE sender cipher is initialized with the recipient's public
// key and an HPKEParameterSpec using specified algorithm identifiers
// and application-supplied info.
Cipher senderCipher = Cipher.getInstance("HPKE");
HPKEParameterSpec ps = HPKEParameterSpec.of(
HPKEParameterSpec.KEM_DHKEM_X25519_HKDF_SHA256,
HPKEParameterSpec.KDF_HKDF_SHA256,
HPKEParameterSpec.AEAD_AES_128_GCM)
.withInfo(HexFormat.of().parseHex("010203040506"));
senderCipher.init(Cipher.ENCRYPT_MODE, kp.getPublic(), ps);

// Retrieve the key encapsulation message (from the KEM step) from
// the sender.
byte[] kemEncap = senderCipher.getIV();

// The HPKE recipient cipher is initialized with its own private key,
// an HPKEParameterSpec using the same algorithm identifiers as used by
// the sender, and the key encapsulation message from the sender.
Cipher recipientCipher = Cipher.getInstance("HPKE");
HPKEParameterSpec pr = HPKEParameterSpec.of(
HPKEParameterSpec.KEM_DHKEM_X25519_HKDF_SHA256,
HPKEParameterSpec.KDF_HKDF_SHA256,
HPKEParameterSpec.AEAD_AES_128_GCM)
.withInfo(HexFormat.of().parseHex("010203040506"))
.withEncapsulation(kemEncap);
recipientCipher.init(Cipher.DECRYPT_MODE, kp.getPrivate(), pr);

// Encryption and decryption
byte[] msg = "Hello World".getBytes(StandardCharsets.UTF_8);
byte[] ct = senderCipher.doFinal(msg);
byte[] pt = recipientCipher.doFinal(ct);

assert Arrays.equals(msg, pt);
// @end
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.security.util;

import javax.crypto.SecretKey;

/**
* An interface for <code>SecretKey</code>s that support using its slice as a new
* <code>SecretKey</code>.
* <p>
* This is mainly used by PKCS #11 implementations that support the
* EXTRACT_KEY_FROM_KEY mechanism even if the key itself is sensitive
* and non-extractable.
*/
public interface SliceableSecretKey {

/**
* Returns a slice as a new <code>SecretKey</code>.
*
* @param alg the new algorithm name
* @param from the byte offset of the new key in the full key
* @param to the to offset (exclusive) of the new key in the full key
* @return the new key
* @throws ArrayIndexOutOfBoundsException for improper <code>from</code>
* and <code>to</code> values
* @throws UnsupportedOperationException if slicing is not supported
*/
SecretKey slice(String alg, int from, int to);
}
Loading