diff --git a/DynamoDbEncryption/runtimes/java/src/main/sdkv1/com/amazonaws/services/dynamodbv2/datamodeling/internal/Hkdf.java b/DynamoDbEncryption/runtimes/java/src/main/sdkv1/com/amazonaws/services/dynamodbv2/datamodeling/internal/Hkdf.java index 83e86a672e..3fb20e33a5 100644 --- a/DynamoDbEncryption/runtimes/java/src/main/sdkv1/com/amazonaws/services/dynamodbv2/datamodeling/internal/Hkdf.java +++ b/DynamoDbEncryption/runtimes/java/src/main/sdkv1/com/amazonaws/services/dynamodbv2/datamodeling/internal/Hkdf.java @@ -207,42 +207,7 @@ public byte[] deriveKey(final String info, final int length) public byte[] deriveKey(final byte[] info, final int length) throws IllegalStateException { byte[] result = new byte[length]; - try { - deriveKey(info, length, result, 0); - } catch (ShortBufferException ex) { - // This exception is impossible as we ensure the buffer is long - // enough - throw new RuntimeException(ex); - } - return result; - } - - /** - * Derives a pseudorandom key of length bytes and stores the result in output - * . - * - * @param info optional context and application specific information (can be a zero-length array). - * @param length the length of the output key in bytes - * @param output the buffer where the pseudorandom key will be stored - * @param offset the offset in output where the key will be stored - * @throws ShortBufferException if the given output buffer is too small to hold the result - * @throws IllegalStateException if this object has not been initialized - */ - public void deriveKey( - final byte[] info, - final int length, - final byte[] output, - final int offset - ) throws ShortBufferException, IllegalStateException { assertInitialized(); - if (length < 0) { - throw new IllegalArgumentException( - "Length must be a non-negative value." - ); - } - if (output.length < offset + length) { - throw new ShortBufferException(); - } Mac mac = createMac(); if (length > 255 * mac.getMacLength()) { @@ -262,7 +227,7 @@ public void deriveKey( t = mac.doFinal(); for (int x = 0; x < t.length && loc < length; x++, loc++) { - output[loc] = t[x]; + result[loc] = t[x]; } i++; @@ -270,6 +235,7 @@ public void deriveKey( } finally { Arrays.fill(t, (byte) 0); // Zeroize temporary array } + return result; } private Mac createMac() {