From: Matthew Endsley Date: Wed, 13 Jan 2021 08:41:11 +0000 (-0800) Subject: Add common PRF labels as constants X-Git-Tag: 1.0.0~20^2~26^2 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=7caca83a6892d8b0f89b25462b5d4f3408a08a12;p=rhonda%2Fimpostor.hazel.git Add common PRF labels as constants --- diff --git a/Hazel/Dtls/PrfSha256.cs b/Hazel/Dtls/PrfSha256.cs index 276169a..1fa7f17 100644 --- a/Hazel/Dtls/PrfSha256.cs +++ b/Hazel/Dtls/PrfSha256.cs @@ -3,6 +3,25 @@ using System.Security.Cryptography; namespace Hazel.Dtls { + /// + /// Common Psuedorandom Function labels for TLS + /// + public struct PrfLabel + { + public static readonly ByteSpan MASTER_SECRET = LabelToBytes("master secert"); + public static readonly ByteSpan KEY_EXPANSION = LabelToBytes("key expansion"); + public static readonly ByteSpan CLIENT_FINISHED = LabelToBytes("client finished"); + public static readonly ByteSpan SERVER_FINISHED = LabelToBytes("server finished"); + + /// + /// Convert a text label to a byte sequence + /// + public static ByteSpan LabelToBytes(string label) + { + return Encoding.ASCII.GetBytes(label); + } + } + /// /// The P_SHA256 Psuedorandom Function /// @@ -17,8 +36,7 @@ namespace Hazel.Dtls /// Seed for expansion (treated as a salt) public static void ExpandSecret(ByteSpan output, ByteSpan key, string label, ByteSpan initialSeed) { - ByteSpan labelAsBytes = Encoding.ASCII.GetBytes(label); - ExpandSecret(output, key, labelAsBytes, initialSeed); + ExpandSecret(output, key, PrfLabel.LabelToBytes(label), initialSeed); } /// @@ -34,7 +52,7 @@ namespace Hazel.Dtls byte[] roundSeed = new byte[label.Length + initialSeed.Length]; label.CopyTo(roundSeed); - initialSeed.CopyTo(roundSeed, label.Length)); + initialSeed.CopyTo(roundSeed, label.Length); byte[] hashA = roundSeed;