1
0
mirror of https://github.com/bitwarden/mobile synced 2026-01-09 03:53:15 +00:00

add pbkdf2 key stretching

This commit is contained in:
Kyle Spearrin
2018-06-13 22:41:18 -04:00
parent a607a7f3ef
commit 7cac07c185
2 changed files with 61 additions and 4 deletions

View File

@@ -206,5 +206,24 @@ namespace Bit.App.Utilities
return code.ToString().PadLeft(6, '0');
}
// ref: https://tools.ietf.org/html/rfc5869
public static byte[] HkdfExpand(byte[] prk, byte[] info, int size)
{
var hashLen = 32; // sha256
var okm = new byte[size];
var previousT = new byte[0];
var n = (int)Math.Ceiling((double)size / hashLen);
for(int i = 0; i < n; i++)
{
var t = new byte[previousT.Length + info.Length + 1];
previousT.CopyTo(t, 0);
info.CopyTo(t, previousT.Length);
t[t.Length - 1] = (byte)(i + 1);
previousT = ComputeMac(t, prk);
previousT.CopyTo(okm, i * hashLen);
}
return okm;
}
}
}