@@ -616,8 +616,8 @@ public bool TryExportPkcs8PrivateKey(Span<byte> destination, out int bytesWritte
616
616
3 + // Version Integer
617
617
2 + // AlgorithmIdentifier Sequence
618
618
3 + // AlgorithmIdentifier OID value, undervalued to be safe
619
- 2 + // Secret key Octet String prefix, undervalued to be safe
620
- Algorithm . SecretKeySizeInBytes ;
619
+ 2 + // Private key Octet String prefix, undervalued to be safe
620
+ Algorithm . PrivateKeySizeInBytes ;
621
621
622
622
if ( destination . Length < MinimumPossiblePkcs8SlhDsaKey )
623
623
{
@@ -650,19 +650,19 @@ public bool TryExportPkcs8PrivateKey(Span<byte> destination, out int bytesWritte
650
650
/// </exception>
651
651
protected virtual bool TryExportPkcs8PrivateKeyCore ( Span < byte > destination , out int bytesWritten )
652
652
{
653
- // Secret key size for SLH-DSA is at most 128 bytes so we can stack allocate it.
654
- int secretKeySizeInBytes = Algorithm . SecretKeySizeInBytes ;
655
- Debug . Assert ( secretKeySizeInBytes is <= 128 ) ;
656
- Span < byte > secretKey = ( stackalloc byte [ 128 ] ) [ ..secretKeySizeInBytes ] ;
653
+ // Private key size for SLH-DSA is at most 128 bytes so we can stack allocate it.
654
+ int privateKeySizeInBytes = Algorithm . PrivateKeySizeInBytes ;
655
+ Debug . Assert ( privateKeySizeInBytes is <= 128 ) ;
656
+ Span < byte > privateKey = ( stackalloc byte [ 128 ] ) [ ..privateKeySizeInBytes ] ;
657
657
658
658
try
659
659
{
660
- ExportSlhDsaSecretKey ( secretKey ) ;
660
+ ExportSlhDsaPrivateKey ( privateKey ) ;
661
661
662
662
// The ASN.1 overhead of a PrivateKeyInfo encoding a private key is 22 bytes.
663
663
// Round it off to 32. This checked operation should never throw because the inputs are not
664
664
// user provided.
665
- int capacity = checked ( 32 + secretKeySizeInBytes ) ;
665
+ int capacity = checked ( 32 + privateKeySizeInBytes ) ;
666
666
AsnWriter writer = new AsnWriter ( AsnEncodingRules . DER , capacity ) ;
667
667
668
668
using ( writer . PushSequence ( ) )
@@ -674,15 +674,15 @@ protected virtual bool TryExportPkcs8PrivateKeyCore(Span<byte> destination, out
674
674
writer . WriteObjectIdentifier ( Algorithm . Oid ) ;
675
675
}
676
676
677
- writer . WriteOctetString ( secretKey ) ;
677
+ writer . WriteOctetString ( privateKey ) ;
678
678
}
679
679
680
680
Debug . Assert ( writer . GetEncodedLength ( ) <= capacity ) ;
681
681
return writer . TryEncode ( destination , out bytesWritten ) ;
682
682
}
683
683
finally
684
684
{
685
- CryptographicOperations . ZeroMemory ( secretKey ) ;
685
+ CryptographicOperations . ZeroMemory ( privateKey ) ;
686
686
}
687
687
}
688
688
@@ -1108,55 +1108,55 @@ public byte[] ExportSlhDsaPublicKey()
1108
1108
}
1109
1109
1110
1110
/// <summary>
1111
- /// Exports the current key in the FIPS 205 secret key format.
1111
+ /// Exports the current key in the FIPS 205 private key format.
1112
1112
/// </summary>
1113
1113
/// <param name="destination">
1114
- /// The buffer to receive the secret key. Its length must be exactly
1115
- /// <see cref="SlhDsaAlgorithm.SecretKeySizeInBytes "/>.
1114
+ /// The buffer to receive the private key. Its length must be exactly
1115
+ /// <see cref="SlhDsaAlgorithm.PrivateKeySizeInBytes "/>.
1116
1116
/// </param>
1117
1117
/// <exception cref="ArgumentException">
1118
- /// <paramref name="destination"/> is the incorrect length to receive the secret key.
1118
+ /// <paramref name="destination"/> is the incorrect length to receive the private key.
1119
1119
/// </exception>
1120
1120
/// <exception cref="CryptographicException">
1121
- /// <para>The current instance cannot export a secret key.</para>
1121
+ /// <para>The current instance cannot export a private key.</para>
1122
1122
/// <para>-or-</para>
1123
1123
/// <para>An error occurred while exporting the key.</para>
1124
1124
/// </exception>
1125
1125
/// <exception cref="ObjectDisposedException">The object has already been disposed.</exception>
1126
- public void ExportSlhDsaSecretKey ( Span < byte > destination )
1126
+ public void ExportSlhDsaPrivateKey ( Span < byte > destination )
1127
1127
{
1128
- int secretKeySizeInBytes = Algorithm . SecretKeySizeInBytes ;
1128
+ int privateKeySizeInBytes = Algorithm . PrivateKeySizeInBytes ;
1129
1129
1130
- if ( destination . Length != secretKeySizeInBytes )
1130
+ if ( destination . Length != privateKeySizeInBytes )
1131
1131
{
1132
1132
throw new ArgumentException (
1133
- SR . Format ( SR . Argument_DestinationImprecise , secretKeySizeInBytes ) ,
1133
+ SR . Format ( SR . Argument_DestinationImprecise , privateKeySizeInBytes ) ,
1134
1134
nameof ( destination ) ) ;
1135
1135
}
1136
1136
1137
1137
ThrowIfDisposed ( ) ;
1138
1138
1139
- ExportSlhDsaSecretKeyCore ( destination ) ;
1139
+ ExportSlhDsaPrivateKeyCore ( destination ) ;
1140
1140
}
1141
1141
1142
1142
/// <summary>
1143
- /// Exports the current key in the FIPS 205 secret key format.
1143
+ /// Exports the current key in the FIPS 205 private key format.
1144
1144
/// </summary>
1145
1145
/// <returns>
1146
- /// The FIPS 205 secret key.
1146
+ /// The FIPS 205 private key.
1147
1147
/// </returns>
1148
1148
/// <exception cref="CryptographicException">
1149
- /// <para>The current instance cannot export a secret key.</para>
1149
+ /// <para>The current instance cannot export a private key.</para>
1150
1150
/// <para>-or-</para>
1151
1151
/// <para>An error occurred while exporting the key.</para>
1152
1152
/// </exception>
1153
1153
/// <exception cref="ObjectDisposedException">The object has already been disposed.</exception>
1154
- public byte [ ] ExportSlhDsaSecretKey ( )
1154
+ public byte [ ] ExportSlhDsaPrivateKey ( )
1155
1155
{
1156
1156
ThrowIfDisposed ( ) ;
1157
1157
1158
- byte [ ] destination = new byte [ Algorithm . SecretKeySizeInBytes ] ;
1159
- ExportSlhDsaSecretKeyCore ( destination ) ;
1158
+ byte [ ] destination = new byte [ Algorithm . PrivateKeySizeInBytes ] ;
1159
+ ExportSlhDsaPrivateKeyCore ( destination ) ;
1160
1160
return destination ;
1161
1161
}
1162
1162
@@ -1293,12 +1293,12 @@ public static SlhDsa ImportPkcs8PrivateKey(ReadOnlySpan<byte> source)
1293
1293
SlhDsaAlgorithm info = GetAlgorithmIdentifier ( in algId ) ;
1294
1294
ReadOnlySpan < byte > privateKey = key . Span ;
1295
1295
1296
- if ( privateKey . Length != info . SecretKeySizeInBytes )
1296
+ if ( privateKey . Length != info . PrivateKeySizeInBytes )
1297
1297
{
1298
1298
throw new CryptographicException ( SR . Cryptography_Der_Invalid_Encoding ) ;
1299
1299
}
1300
1300
1301
- ret = ImportSlhDsaSecretKey ( info , key . Span ) ;
1301
+ ret = ImportSlhDsaPrivateKey ( info , key . Span ) ;
1302
1302
} ,
1303
1303
out int read ,
1304
1304
out SlhDsa slhDsa ) ;
@@ -1704,13 +1704,13 @@ public static SlhDsa ImportSlhDsaPublicKey(SlhDsaAlgorithm algorithm, byte[] sou
1704
1704
}
1705
1705
1706
1706
/// <summary>
1707
- /// Imports an SLH-DSA private key in the FIPS 205 secret key format.
1707
+ /// Imports an SLH-DSA private key in the FIPS 205 private key format.
1708
1708
/// </summary>
1709
1709
/// <param name="algorithm">
1710
1710
/// The specific SLH-DSA algorithm for this key.
1711
1711
/// </param>
1712
1712
/// <param name="source">
1713
- /// The bytes of a FIPS 205 secret key.
1713
+ /// The bytes of a FIPS 205 private key.
1714
1714
/// </param>
1715
1715
/// <returns>
1716
1716
/// The imported key.
@@ -1728,29 +1728,29 @@ public static SlhDsa ImportSlhDsaPublicKey(SlhDsaAlgorithm algorithm, byte[] sou
1728
1728
/// The platform does not support SLH-DSA. Callers can use the <see cref="IsSupported" /> property
1729
1729
/// to determine if the platform supports SLH-DSA.
1730
1730
/// </exception>
1731
- public static SlhDsa ImportSlhDsaSecretKey ( SlhDsaAlgorithm algorithm , ReadOnlySpan < byte > source )
1731
+ public static SlhDsa ImportSlhDsaPrivateKey ( SlhDsaAlgorithm algorithm , ReadOnlySpan < byte > source )
1732
1732
{
1733
1733
ArgumentNullException . ThrowIfNull ( algorithm ) ;
1734
1734
1735
- if ( source . Length != algorithm . SecretKeySizeInBytes )
1735
+ if ( source . Length != algorithm . PrivateKeySizeInBytes )
1736
1736
{
1737
- throw new ArgumentException ( SR . Argument_SecretKeyWrongSizeForAlgorithm , nameof ( source ) ) ;
1737
+ throw new ArgumentException ( SR . Argument_PrivateKeyWrongSizeForAlgorithm , nameof ( source ) ) ;
1738
1738
}
1739
1739
1740
1740
ThrowIfNotSupported ( ) ;
1741
1741
1742
- return SlhDsaImplementation . ImportSecretKey ( algorithm , source ) ;
1742
+ return SlhDsaImplementation . ImportPrivateKey ( algorithm , source ) ;
1743
1743
}
1744
1744
1745
- /// <inheritdoc cref="ImportSlhDsaSecretKey (SlhDsaAlgorithm, ReadOnlySpan{byte})" />
1745
+ /// <inheritdoc cref="ImportSlhDsaPrivateKey (SlhDsaAlgorithm, ReadOnlySpan{byte})" />
1746
1746
/// <exception cref="ArgumentNullException">
1747
1747
/// <paramref name="algorithm"/> or <paramref name="source" /> is <see langword="null" />.
1748
1748
/// </exception>
1749
- public static SlhDsa ImportSlhDsaSecretKey ( SlhDsaAlgorithm algorithm , byte [ ] source )
1749
+ public static SlhDsa ImportSlhDsaPrivateKey ( SlhDsaAlgorithm algorithm , byte [ ] source )
1750
1750
{
1751
1751
ArgumentNullException . ThrowIfNull ( source ) ;
1752
1752
1753
- return ImportSlhDsaSecretKey ( algorithm , new ReadOnlySpan < byte > ( source ) ) ;
1753
+ return ImportSlhDsaPrivateKey ( algorithm , new ReadOnlySpan < byte > ( source ) ) ;
1754
1754
}
1755
1755
1756
1756
/// <summary>
@@ -1856,12 +1856,12 @@ protected virtual void Dispose(bool disposing)
1856
1856
protected abstract void ExportSlhDsaPublicKeyCore ( Span < byte > destination ) ;
1857
1857
1858
1858
/// <summary>
1859
- /// When overridden in a derived class, exports the FIPS 205 secret key to the specified buffer.
1859
+ /// When overridden in a derived class, exports the FIPS 205 private key to the specified buffer.
1860
1860
/// </summary>
1861
1861
/// <param name="destination">
1862
- /// The buffer to receive the secret key.
1862
+ /// The buffer to receive the private key.
1863
1863
/// </param>
1864
- protected abstract void ExportSlhDsaSecretKeyCore ( Span < byte > destination ) ;
1864
+ protected abstract void ExportSlhDsaPrivateKeyCore ( Span < byte > destination ) ;
1865
1865
1866
1866
private AsnWriter ExportSubjectPublicKeyInfoCore ( )
1867
1867
{
@@ -1952,7 +1952,7 @@ private TResult ExportPkcs8PrivateKeyCallback<TResult>(ExportPkcs8PrivateKeyFunc
1952
1952
{
1953
1953
// A PKCS#8 SLH-DSA-SHA2-256s private key has an ASN.1 overhead of 22 bytes, assuming no attributes.
1954
1954
// Make it an even 32 and that should give a good starting point for a buffer size.
1955
- int size = Algorithm . SecretKeySizeInBytes + 32 ;
1955
+ int size = Algorithm . PrivateKeySizeInBytes + 32 ;
1956
1956
// The buffer is only being passed out as a span, so the derived type can't meaningfully
1957
1957
// hold on to it without being malicious.
1958
1958
byte [ ] buffer = CryptoPool . Rent ( size ) ;
0 commit comments