]> git.deb.at Git - rhonda/impostor.hazel.git/commitdiff
Add ExpandSecret variant that takes label as a byte span
authorMatthew Endsley <mendsley@gmail.com>
Wed, 13 Jan 2021 08:39:21 +0000 (00:39 -0800)
committerMatthew Endsley <mendsley@gmail.com>
Tue, 2 Feb 2021 16:53:32 +0000 (08:53 -0800)
Hazel/Dtls/PrfSha256.cs

index 683e55f11125eb64cb1b64556bb84f7459979b19..276169a865710a8e9e91db552d1a2ce4a328fd3c 100644 (file)
@@ -17,14 +17,24 @@ namespace Hazel.Dtls
         /// <param name="initialSeed">Seed for expansion (treated as a salt)</param>
         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);
+        }
+
+        /// <summary>
+        /// Expand a secret key
+        /// </summary>
+        /// <param name="output">Output span. Length determines how much data to generate</param>
+        /// <param name="key">Original key to expand</param>
+        /// <param name="label">Label (treated as a salt)</param>
+        /// <param name="initialSeed">Seed for expansion (treated as a salt)</param>
+        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;