1
1
/*
2
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
34
34
import sun .security .ssl .CipherSuite .HashAlg ;
35
35
36
36
final class SSLSecretDerivation implements SSLKeyDerivation {
37
+
38
+ /*
39
+ * Performance optimization:
40
+ *
41
+ * Derive-Secret(Secret, Label, Messages) =
42
+ * HKDF-Expand-Label(..., Transcript-Hash(""), ...);
43
+ *
44
+ * Hardcode tha Transcript-Hash("") result and skip a digest operation.
45
+ */
37
46
private static final byte [] sha256EmptyDigest = new byte [] {
38
47
(byte )0xE3 , (byte )0xB0 , (byte )0xC4 , (byte )0x42 ,
39
48
(byte )0x98 , (byte )0xFC , (byte )0x1C , (byte )0x14 ,
@@ -45,6 +54,7 @@ final class SSLSecretDerivation implements SSLKeyDerivation {
45
54
(byte )0x78 , (byte )0x52 , (byte )0xB8 , (byte )0x55
46
55
};
47
56
57
+ // See above.
48
58
private static final byte [] sha384EmptyDigest = new byte [] {
49
59
(byte )0x38 , (byte )0xB0 , (byte )0x60 , (byte )0xA7 ,
50
60
(byte )0x51 , (byte )0xAC , (byte )0x96 , (byte )0x38 ,
@@ -68,7 +78,6 @@ final class SSLSecretDerivation implements SSLKeyDerivation {
68
78
HandshakeContext context , SecretKey secret ) {
69
79
this .secret = secret ;
70
80
this .hashAlg = context .negotiatedCipherSuite .hashAlg ;
71
- String hkdfAlg = "HKDF-Expand/Hmac" + hashAlg .name .replace ("-" , "" );
72
81
context .handshakeHash .update ();
73
82
this .transcriptHash = context .handshakeHash .digest ();
74
83
}
@@ -141,7 +150,7 @@ private enum SecretSchedule {
141
150
142
151
private final byte [] label ;
143
152
144
- private SecretSchedule (String label ) {
153
+ SecretSchedule (String label ) {
145
154
this .label = ("tls13 " + label ).getBytes ();
146
155
}
147
156
}
0 commit comments