Skip to content

Commit b8f29f9

Browse files
ShubhamChaturvedi7Shubham Chaturvedi
andauthored
fix(java): drop hkdf offset method (#2011)
* fix(java): drop hkdf offset method * clean up * chore: formatting * cleanup --------- Co-authored-by: Shubham Chaturvedi <scchatur@amazon.com>
1 parent f8d8f08 commit b8f29f9

1 file changed

Lines changed: 2 additions & 36 deletions

File tree

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

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

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -207,42 +207,7 @@ public byte[] deriveKey(final String info, final int length)
207207
public byte[] deriveKey(final byte[] info, final int length)
208208
throws IllegalStateException {
209209
byte[] result = new byte[length];
210-
try {
211-
deriveKey(info, length, result, 0);
212-
} catch (ShortBufferException ex) {
213-
// This exception is impossible as we ensure the buffer is long
214-
// enough
215-
throw new RuntimeException(ex);
216-
}
217-
return result;
218-
}
219-
220-
/**
221-
* Derives a pseudorandom key of <code>length</code> bytes and stores the result in <code>output
222-
* </code>.
223-
*
224-
* @param info optional context and application specific information (can be a zero-length array).
225-
* @param length the length of the output key in bytes
226-
* @param output the buffer where the pseudorandom key will be stored
227-
* @param offset the offset in <code>output</code> where the key will be stored
228-
* @throws ShortBufferException if the given output buffer is too small to hold the result
229-
* @throws IllegalStateException if this object has not been initialized
230-
*/
231-
public void deriveKey(
232-
final byte[] info,
233-
final int length,
234-
final byte[] output,
235-
final int offset
236-
) throws ShortBufferException, IllegalStateException {
237210
assertInitialized();
238-
if (length < 0) {
239-
throw new IllegalArgumentException(
240-
"Length must be a non-negative value."
241-
);
242-
}
243-
if (output.length < offset + length) {
244-
throw new ShortBufferException();
245-
}
246211
Mac mac = createMac();
247212

248213
if (length > 255 * mac.getMacLength()) {
@@ -262,14 +227,15 @@ public void deriveKey(
262227
t = mac.doFinal();
263228

264229
for (int x = 0; x < t.length && loc < length; x++, loc++) {
265-
output[loc] = t[x];
230+
result[loc] = t[x];
266231
}
267232

268233
i++;
269234
}
270235
} finally {
271236
Arrays.fill(t, (byte) 0); // Zeroize temporary array
272237
}
238+
return result;
273239
}
274240

275241
private Mac createMac() {

0 commit comments

Comments
 (0)