Skip to content

Commit 83eb7dc

Browse files
committed
simpler spec creation, and one more clean
1 parent 2241bf8 commit 83eb7dc

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

src/java.base/share/classes/com/sun/crypto/provider/TlsKeyMaterialGenerator.java

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,11 @@ private SecretKey engineGenerateKey0(byte[] masterSecret) throws GeneralSecurity
172172

173173
int ofs = 0;
174174
if (macLength != 0) {
175-
byte[] tmp = new byte[macLength];
176-
177175
// mac keys
178-
System.arraycopy(keyBlock, ofs, tmp, 0, macLength);
176+
clientMacKey = new SecretKeySpec(keyBlock, ofs, macLength, "Mac");
179177
ofs += macLength;
180-
clientMacKey = new SecretKeySpec(tmp, "Mac");
181-
182-
System.arraycopy(keyBlock, ofs, tmp, 0, macLength);
178+
serverMacKey = new SecretKeySpec(keyBlock, ofs, macLength, "Mac");
183179
ofs += macLength;
184-
serverMacKey = new SecretKeySpec(tmp, "Mac");
185-
186-
Arrays.fill(tmp, (byte)0);
187180
}
188181

189182
if (keyLength == 0) { // SSL_RSA_WITH_NULL_* ciphersuites
@@ -209,15 +202,10 @@ private SecretKey engineGenerateKey0(byte[] masterSecret) throws GeneralSecurity
209202

210203
// IV keys if needed.
211204
if (ivLength != 0) {
212-
byte[] tmp = new byte[ivLength];
213-
214-
System.arraycopy(keyBlock, ofs, tmp, 0, ivLength);
205+
clientIv = new IvParameterSpec(keyBlock, ofs, ivLength);
215206
ofs += ivLength;
216-
clientIv = new IvParameterSpec(tmp);
217-
218-
System.arraycopy(keyBlock, ofs, tmp, 0, ivLength);
207+
serverIv = new IvParameterSpec(keyBlock, ofs, ivLength);
219208
ofs += ivLength;
220-
serverIv = new IvParameterSpec(tmp);
221209
}
222210
} else {
223211
// if exportable suites, calculate the alternate
@@ -242,13 +230,10 @@ private SecretKey engineGenerateKey0(byte[] masterSecret) throws GeneralSecurity
242230
Arrays.fill(tmp, (byte) 0);
243231

244232
if (ivLength != 0) {
245-
tmp = new byte[ivLength];
246233
byte[] block = doTLS10PRF(null, LABEL_IV_BLOCK, seed,
247234
ivLength << 1, md5, sha);
248-
System.arraycopy(block, 0, tmp, 0, ivLength);
249-
clientIv = new IvParameterSpec(tmp);
250-
System.arraycopy(block, ivLength, tmp, 0, ivLength);
251-
serverIv = new IvParameterSpec(tmp);
235+
clientIv = new IvParameterSpec(block, 0, ivLength);
236+
serverIv = new IvParameterSpec(block, ivLength, ivLength);
252237
}
253238
} else {
254239
// SSLv3

src/java.base/share/classes/com/sun/crypto/provider/TlsPrfGenerator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ private static void expand(MessageDigest digest, int hmacSize,
369369
}
370370
remaining -= k;
371371
}
372+
Arrays.fill(tmp, (byte)0);
372373
}
373374

374375
/**

0 commit comments

Comments
 (0)