Skip to content

Commit 1c6d12a

Browse files
committed
draft-ietf-lamps-dilithium-certificates-07 => RFC 9881
1 parent 060a9bb commit 1c6d12a

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

crypto/src/crypto/parameters/MLDsaPrivateKeyParameters.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ public sealed class MLDsaPrivateKeyParameters
1111
{
1212
public enum Format { SeedOnly, EncodingOnly, SeedAndEncoding };
1313

14+
/*
15+
* RFC 9881 8.1. [..] the seed format is RECOMMENDED for storage efficiency.
16+
*/
17+
public static readonly Format DefaultFormat = Format.SeedOnly;
18+
1419
public static MLDsaPrivateKeyParameters FromEncoding(MLDsaParameters parameters, byte[] encoding)
1520
{
1621
if (parameters == null)
@@ -52,7 +57,7 @@ public static MLDsaPrivateKeyParameters FromEncoding(MLDsaParameters parameters,
5257
}
5358

5459
public static MLDsaPrivateKeyParameters FromSeed(MLDsaParameters parameters, byte[] seed) =>
55-
FromSeed(parameters, seed, preferredFormat: Format.SeedOnly);
60+
FromSeed(parameters, seed, preferredFormat: DefaultFormat);
5661

5762
public static MLDsaPrivateKeyParameters FromSeed(MLDsaParameters parameters, byte[] seed,
5863
Format preferredFormat)

crypto/src/security/PrivateKeyFactory.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,12 @@ public static AsymmetricKeyParameter CreateKey(PrivateKeyInfo keyInfo)
338338
var fromSeed = MLDsaPrivateKeyParameters.FromSeed(mlDsaParameters, seed,
339339
preferredFormat: MLDsaPrivateKeyParameters.Format.SeedAndEncoding);
340340

341+
/*
342+
* RFC 9881 8.2. When receiving a private key that contains both the seed and the
343+
* expandedKey, the recipient SHOULD perform a seed consistency check to ensure that the
344+
* sender properly generated the private key. [..] If the check is done and the seed and the
345+
* expandedKey are not consistent, the recipient MUST reject the private key as malformed.
346+
*/
341347
if (!Arrays.FixedTimeEquals(fromSeed.GetEncoded(), encoding))
342348
throw new ArgumentException("inconsistent " + mlDsaParameters.Name + " private key");
343349

0 commit comments

Comments
 (0)