22using System . IO ;
33
44using Org . BouncyCastle . Asn1 ;
5+ using Org . BouncyCastle . Crypto . Digests ;
56using Org . BouncyCastle . Crypto . Parameters ;
67using Org . BouncyCastle . Crypto . Signers . SlhDsa ;
78using Org . BouncyCastle . Security ;
@@ -23,15 +24,43 @@ public sealed class HashSlhDsaSigner
2324 private SlhDsaEngine m_engine ;
2425
2526 public HashSlhDsaSigner ( SlhDsaParameters parameters , bool deterministic )
27+ : this ( parameters , deterministic ,
28+ DigestUtilities . GetDigest ( parameters . PreHashOid ) ,
29+ parameters . PreHashOid )
30+ {
31+ if ( parameters == null )
32+ throw new ArgumentNullException ( nameof ( parameters ) ) ;
33+ if ( parameters . PreHashOid == null )
34+ throw new ArgumentException ( "cannot be used for SLH-DSA" , nameof ( parameters ) ) ;
35+ }
36+
37+ public static HashSlhDsaSigner CreatePrehashSigner ( SlhDsaParameters parameters , bool deterministic )
2638 {
2739 if ( parameters == null )
2840 throw new ArgumentNullException ( nameof ( parameters ) ) ;
2941 if ( parameters . PreHashOid == null )
3042 throw new ArgumentException ( "cannot be used for SLH-DSA" , nameof ( parameters ) ) ;
3143
44+ IDigest preHashDigest = DigestUtilities . GetDigest ( parameters . PreHashOid ) ;
45+ return new HashSlhDsaSigner ( parameters , deterministic , Prehash . ForDigest ( preHashDigest ) , parameters . PreHashOid ) ;
46+ }
47+
48+ public static HashSlhDsaSigner CreatePrehashSigner ( SlhDsaParameters parametersWithoutPrehash , bool deterministic , DerObjectIdentifier preHashOid )
49+ {
50+ if ( parametersWithoutPrehash == null )
51+ throw new ArgumentNullException ( nameof ( parametersWithoutPrehash ) ) ;
52+ if ( preHashOid == null )
53+ throw new ArgumentNullException ( nameof ( preHashOid ) ) ;
54+
55+ IDigest preHashDigest = DigestUtilities . GetDigest ( preHashOid ) ;
56+ return new HashSlhDsaSigner ( parametersWithoutPrehash , deterministic , Prehash . ForDigest ( preHashDigest ) , preHashOid ) ;
57+ }
58+
59+ private HashSlhDsaSigner ( SlhDsaParameters parameters , bool deterministic , IDigest preHashDigest , DerObjectIdentifier preHashOid )
60+ {
3261 m_parameters = parameters ;
33- m_preHashOidEncoding = parameters . PreHashOid . GetEncoded ( Asn1Encodable . Der ) ;
34- m_preHashDigest = DigestUtilities . GetDigest ( parameters . PreHashOid ) ;
62+ m_preHashOidEncoding = preHashOid . GetEncoded ( Asn1Encodable . Der ) ;
63+ m_preHashDigest = preHashDigest ;
3564 m_deterministic = deterministic ;
3665 }
3766
0 commit comments