Skip to content

Commit

Permalink
Merge pull request #483 from WilburZjh/overlap-fixed
Browse files Browse the repository at this point in the history
Prevent overlapping arrays for AES-CBC
  • Loading branch information
keithc-ca committed Mar 3, 2022
2 parents ee602f3 + dc0ee85 commit 66baf11
Showing 1 changed file with 11 additions and 1 deletion.
Expand Up @@ -24,7 +24,7 @@
*/
/*
* ===========================================================================
* (c) Copyright IBM Corp. 2018, 2021 All Rights Reserved
* (c) Copyright IBM Corp. 2018, 2022 All Rights Reserved
* ===========================================================================
*/

Expand Down Expand Up @@ -260,6 +260,16 @@ int encrypt(byte[] plain, int plainOffset, int plainLen,
throw new ProviderException("Internal error in input buffering");
}

/**
* OpenSSL doesn't support overlapping buffers, make a copy of plain.
*/
if (plain == cipher) {
byte[] copyOfInput = new byte[plainLen];
System.arraycopy(plain, plainOffset, copyOfInput, 0, plainLen);
plain = copyOfInput;
plainOffset = 0;
}

int ret;
synchronized (this) {
ret = nativeCrypto.CBCUpdate(nativeContext, plain, plainOffset,
Expand Down

0 comments on commit 66baf11

Please sign in to comment.