Skip to content

Commit 7aad5fb

Browse files
fix(java): drop hkdf offset method (#2222)
1 parent 1fe60e3 commit 7aad5fb

1 file changed

Lines changed: 3 additions & 42 deletions

File tree

  • DynamoDbEncryption/runtimes/java/src/main/sdkv2/com/amazonaws/services/dynamodbv2/datamodeling/sdkv2/internal

DynamoDbEncryption/runtimes/java/src/main/sdkv2/com/amazonaws/services/dynamodbv2/datamodeling/sdkv2/internal/Hkdf.java

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -234,49 +234,9 @@ public byte[] deriveKey(final String info, final int length)
234234
public byte[] deriveKey(final byte[] info, final int length)
235235
throws IllegalStateException {
236236
byte[] result = new byte[length];
237-
try {
238-
deriveKey(info, length, result, 0);
239-
} catch (ShortBufferException ex) {
240-
// This exception is impossible as we ensure the buffer is long
241-
// enough
242-
throw new RuntimeException(ex);
243-
}
244-
return result;
245-
}
246237

247-
/**
248-
* Derives a pseudorandom key of <code>length</code> bytes and stores the
249-
* result in <code>output</code>.
250-
*
251-
* @param info
252-
* optional context and application specific information (can be
253-
* a zero-length array).
254-
* @param length
255-
* the length of the output key in bytes
256-
* @param output
257-
* the buffer where the pseudorandom key will be stored
258-
* @param offset
259-
* the offset in <code>output</code> where the key will be stored
260-
* @throws ShortBufferException
261-
* if the given output buffer is too small to hold the result
262-
* @throws IllegalStateException
263-
* if this object has not been initialized
264-
*/
265-
public void deriveKey(
266-
final byte[] info,
267-
final int length,
268-
final byte[] output,
269-
final int offset
270-
) throws ShortBufferException, IllegalStateException {
271238
assertInitialized();
272-
if (length < 0) {
273-
throw new IllegalArgumentException(
274-
"Length must be a non-negative value."
275-
);
276-
}
277-
if (output.length < offset + length) {
278-
throw new ShortBufferException();
279-
}
239+
280240
Mac mac = createMac();
281241

282242
if (length > 255 * mac.getMacLength()) {
@@ -296,14 +256,15 @@ public void deriveKey(
296256
t = mac.doFinal();
297257

298258
for (int x = 0; x < t.length && loc < length; x++, loc++) {
299-
output[loc] = t[x];
259+
result[loc] = t[x];
300260
}
301261

302262
i++;
303263
}
304264
} finally {
305265
Arrays.fill(t, (byte) 0); // Zeroize temporary array
306266
}
267+
return result;
307268
}
308269

309270
private Mac createMac() {

0 commit comments

Comments
 (0)