mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8258915: Temporary buffer cleanup
Reviewed-by: valeriep
This commit is contained in:
parent
31d8a19e47
commit
f834557ae0
79 changed files with 1517 additions and 1039 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2021, 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
|
||||
|
@ -33,6 +33,7 @@ import java.nio.ByteBuffer;
|
|||
import java.nio.ByteOrder;
|
||||
import java.security.*;
|
||||
import java.security.spec.AlgorithmParameterSpec;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import javax.crypto.*;
|
||||
import javax.crypto.spec.ChaCha20ParameterSpec;
|
||||
|
@ -546,6 +547,9 @@ abstract class ChaCha20Cipher extends CipherSpi {
|
|||
// assigning them to the object.
|
||||
byte[] newKeyBytes = getEncodedKey(key);
|
||||
checkKeyAndNonce(newKeyBytes, newNonce);
|
||||
if (this.keyBytes != null) {
|
||||
Arrays.fill(this.keyBytes, (byte)0);
|
||||
}
|
||||
this.keyBytes = newKeyBytes;
|
||||
nonce = newNonce;
|
||||
|
||||
|
@ -612,6 +616,9 @@ abstract class ChaCha20Cipher extends CipherSpi {
|
|||
}
|
||||
byte[] encodedKey = key.getEncoded();
|
||||
if (encodedKey == null || encodedKey.length != 32) {
|
||||
if (encodedKey != null) {
|
||||
Arrays.fill(encodedKey, (byte)0);
|
||||
}
|
||||
throw new InvalidKeyException("Key length must be 256 bits");
|
||||
}
|
||||
return encodedKey;
|
||||
|
@ -790,6 +797,7 @@ abstract class ChaCha20Cipher extends CipherSpi {
|
|||
@Override
|
||||
protected int engineGetKeySize(Key key) throws InvalidKeyException {
|
||||
byte[] encodedKey = getEncodedKey(key);
|
||||
Arrays.fill(encodedKey, (byte)0);
|
||||
return encodedKey.length << 3;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue