From: Matthew Endsley Date: Wed, 13 Jan 2021 08:39:21 +0000 (-0800) Subject: Add ExpandSecret variant that takes label as a byte span X-Git-Tag: 1.0.0~20^2~26^2~1 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=34b4da8b6a3b86d6af80180e88093a506796836b;p=rhonda%2Fimpostor.hazel.git Add ExpandSecret variant that takes label as a byte span --- diff --git a/Hazel/Dtls/PrfSha256.cs b/Hazel/Dtls/PrfSha256.cs index 683e55f..276169a 100644 --- a/Hazel/Dtls/PrfSha256.cs +++ b/Hazel/Dtls/PrfSha256.cs @@ -17,14 +17,24 @@ namespace Hazel.Dtls /// Seed for expansion (treated as a salt) public static void ExpandSecret(ByteSpan output, ByteSpan key, string label, ByteSpan initialSeed) { - ByteSpan writer = output; - - ///TODO(mendsley): Look into pre-calculating all of these ByteSpan labelAsBytes = Encoding.ASCII.GetBytes(label); + ExpandSecret(output, key, labelAsBytes, initialSeed); + } + + /// + /// Expand a secret key + /// + /// Output span. Length determines how much data to generate + /// Original key to expand + /// Label (treated as a salt) + /// Seed for expansion (treated as a salt) + public static void ExpandSecret(ByteSpan output, ByteSpan key, ByteSpan label, ByteSpan initialSeed) + { + ByteSpan writer = output; - byte[] roundSeed = new byte[labelAsBytes.Length + initialSeed.Length]; - labelAsBytes.CopyTo(roundSeed); - initialSeed.CopyTo(roundSeed, labelAsBytes.Length)); + byte[] roundSeed = new byte[label.Length + initialSeed.Length]; + label.CopyTo(roundSeed); + initialSeed.CopyTo(roundSeed, label.Length)); byte[] hashA = roundSeed;