in DynamoDbEncryption/runtimes/java/src/main/sdkv1/com/amazonaws/services/dynamodbv2/datamodeling/internal/Hkdf.java [231:273]
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()) {
throw new IllegalArgumentException(
"Requested keys may not be longer than 255 times the underlying HMAC length."
);
}
byte[] t = EMPTY_ARRAY;
try {
int loc = 0;
byte i = 1;
while (loc < length) {
mac.update(t);
mac.update(info);
mac.update(i);
t = mac.doFinal();
for (int x = 0; x < t.length && loc < length; x++, loc++) {
output[loc] = t[x];
}
i++;
}
} finally {
Arrays.fill(t, (byte) 0); // Zeroize temporary array
}
}