in java/src/main/java/com/alexa/awisapi/AuthenticationHelper.java [424:459]
private void deriveKey(byte[] info, int length, byte[] output, int offset)
throws ShortBufferException {
this.assertInitialized();
if (length < 0) {
throw new IllegalArgumentException("Length must be a non-negative value.");
} else if (output.length < offset + length) {
throw new ShortBufferException();
} else {
final Mac mac = this.createMac();
if (length > MAX_KEY_SIZE * mac.getMacLength()) {
throw new IllegalArgumentException(
"Requested keys may not be longer than 255 times the underlying HMAC length.");
} else {
byte[] t = EMPTY_ARRAY;
try {
int loc = 0;
for (byte i = 1; loc < length; ++i) {
mac.update(t);
mac.update(info);
mac.update(i);
t = mac.doFinal();
for (int x = 0; x < t.length && loc < length; ++loc) {
output[loc] = t[x];
++x;
}
}
} finally {
Arrays.fill(t, (byte) 0);
}
}
}
}