You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
HKDF is a key derivation function
that has two parts: first "extract" and second "expand". For some encryption tasks, we need only the expand part.
I made a code for that for my project and, I guess, it would be great to add to the lib.
Future<SecretKey> expandKey({
required SecretKey secretKey,
List<int> info = const <int>[],
}) async {
// T(0)
var bytes = const <int>[];
// T(1), T(2), ...
final hashLength = hmac.hashAlgorithm.hashLengthInBytes;
final n = outputLength ~/ hashLength;
final result = Uint8List(outputLength);
for (var i = 0; i <= n; i++) {
final sink = await hmac.newMacSink(secretKey: secretKey);
sink.add(bytes);
if (info.isNotEmpty) {
sink.add(info);
}
final added = <int>[0xFF & (1 + i)];
sink.add(added);
sink.close();
final mac = await sink.mac();
bytes = mac.bytes;
final offset = i * hashLength;
if (offset + bytes.length <= result.length) {
result.setAll(offset, bytes);
} else {
result.setAll(offset, bytes.take(result.length - offset));
}
}
return SecretKey(result);
}
The text was updated successfully, but these errors were encountered:
HKDF is a key derivation function
that has two parts: first "extract" and second "expand". For some encryption tasks, we need only the
expand
part.I made a code for that for my project and, I guess, it would be great to add to the lib.
The text was updated successfully, but these errors were encountered: