diff --git a/DynamoDbEncryption/runtimes/java/src/main/sdkv2/com/amazonaws/services/dynamodbv2/datamodeling/sdkv2/internal/Hkdf.java b/DynamoDbEncryption/runtimes/java/src/main/sdkv2/com/amazonaws/services/dynamodbv2/datamodeling/sdkv2/internal/Hkdf.java index affda37b00..ebe7868c1c 100644 --- a/DynamoDbEncryption/runtimes/java/src/main/sdkv2/com/amazonaws/services/dynamodbv2/datamodeling/sdkv2/internal/Hkdf.java +++ b/DynamoDbEncryption/runtimes/java/src/main/sdkv2/com/amazonaws/services/dynamodbv2/datamodeling/sdkv2/internal/Hkdf.java @@ -234,49 +234,9 @@ 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()) { @@ -296,7 +256,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++; @@ -304,6 +264,7 @@ public void deriveKey( } finally { Arrays.fill(t, (byte) 0); // Zeroize temporary array } + return result; } private Mac createMac() {