@@ -29,13 +29,17 @@ public SlhDsaMockImplementation(SlhDsaAlgorithm algorithm)
2929 public delegate bool TryExportPkcs8PrivateKeyCoreFunc ( Span < byte > destination , out int bytesWritten ) ;
3030 public delegate void SignDataCoreAction ( ReadOnlySpan < byte > data , ReadOnlySpan < byte > context , Span < byte > s ) ;
3131 public delegate bool VerifyDataCoreFunc ( ReadOnlySpan < byte > data , ReadOnlySpan < byte > context , ReadOnlySpan < byte > signature ) ;
32+ public delegate void SignPreHashCoreAction ( ReadOnlySpan < byte > hash , ReadOnlySpan < byte > context , string hashAlgorithmOid , Span < byte > destination ) ;
33+ public delegate bool VerifyPreHashCoreFunc ( ReadOnlySpan < byte > hash , ReadOnlySpan < byte > context , string hashAlgorithmOid , ReadOnlySpan < byte > signature ) ;
3234 public delegate void DisposeAction ( bool disposing ) ;
3335
3436 public TryExportPkcs8PrivateKeyCoreFunc BaseTryExportPkcs8PrivateKeyCore =>
3537 base . TryExportPkcs8PrivateKeyCore ;
3638
3739 public int VerifyDataCoreCallCount = 0 ;
3840 public int SignDataCoreCallCount = 0 ;
41+ public int VerifyPreHashCoreCallCount = 0 ;
42+ public int SignPreHashCoreCallCount = 0 ;
3943 public int ExportSlhDsaPublicKeyCoreCallCount = 0 ;
4044 public int ExportSlhDsaSecretKeyCoreCallCount = 0 ;
4145 public int TryExportPkcs8PrivateKeyCoreCallCount = 0 ;
@@ -47,6 +51,8 @@ public SlhDsaMockImplementation(SlhDsaAlgorithm algorithm)
4751 ( _ , out bytesWritten ) => { Assert. Fail ( ) ; bytesWritten = 0 ; return false ; } ;
4852 public SignDataCoreAction SignDataCoreHook { get ; set ; } = ( _ , _ , _ ) => Assert . Fail ( ) ;
4953 public VerifyDataCoreFunc VerifyDataCoreHook { get ; set ; } = ( _ , _ , _ ) => { Assert . Fail ( ) ; return false ; } ;
54+ public SignPreHashCoreAction SignPreHashCoreHook { get ; set ; } = ( _ , _ , _ , _ ) => Assert . Fail ( ) ;
55+ public VerifyPreHashCoreFunc VerifyPreHashCoreHook { get ; set ; } = ( _ , _ , _ , _ ) => { Assert . Fail ( ) ; return false ; } ;
5056 public DisposeAction DisposeHook { get ; set ; } = _ => { } ;
5157
5258 protected override void ExportSlhDsaPublicKeyCore ( Span < byte > destination )
@@ -85,6 +91,18 @@ protected override bool VerifyDataCore(ReadOnlySpan<byte> data, ReadOnlySpan<byt
8591 return VerifyDataCoreHook ( data , context , signature ) ;
8692 }
8793
94+ protected override void SignPreHashCore ( ReadOnlySpan < byte > hash , ReadOnlySpan < byte > context , string hashAlgorithmOid , Span < byte > destination )
95+ {
96+ SignPreHashCoreCallCount ++ ;
97+ SignPreHashCoreHook ( hash , context , hashAlgorithmOid , destination ) ;
98+ }
99+
100+ protected override bool VerifyPreHashCore ( ReadOnlySpan < byte > hash , ReadOnlySpan < byte > context , string hashAlgorithmOid , ReadOnlySpan < byte > signature )
101+ {
102+ VerifyPreHashCoreCallCount ++ ;
103+ return VerifyPreHashCoreHook ( hash , context , hashAlgorithmOid , signature ) ;
104+ }
105+
88106 public void AddLengthAssertion ( )
89107 {
90108 ExportSlhDsaPublicKeyCoreAction oldExportSlhDsaPublicKeyCoreHook = ExportSlhDsaPublicKeyCoreHook ;
@@ -115,6 +133,21 @@ public void AddLengthAssertion()
115133 Assert . Equal ( Algorithm . SignatureSizeInBytes , signature . Length ) ;
116134 return ret ;
117135 } ;
136+
137+ SignPreHashCoreAction oldSignPreHashCoreHook = SignPreHashCoreHook ;
138+ SignPreHashCoreHook = ( ReadOnlySpan < byte > hash , ReadOnlySpan < byte > context , string hashAlgorithmOid , Span < byte > destination ) =>
139+ {
140+ oldSignDataCoreHook ( hash , context , destination ) ;
141+ Assert . Equal ( Algorithm . SignatureSizeInBytes , destination . Length ) ;
142+ } ;
143+
144+ VerifyPreHashCoreFunc oldVerifyPreHashCoreHook = VerifyPreHashCoreHook ;
145+ VerifyPreHashCoreHook = ( ReadOnlySpan < byte > hash , ReadOnlySpan < byte > context , string hashAlgorithmOid , ReadOnlySpan < byte > signature ) =>
146+ {
147+ bool ret = oldVerifyPreHashCoreHook ( hash , context , hashAlgorithmOid , signature ) ;
148+ Assert . Equal ( Algorithm . SignatureSizeInBytes , signature . Length ) ;
149+ return ret ;
150+ } ;
118151 }
119152
120153 public void AddDestinationBufferIsSameAssertion ( ReadOnlyMemory < byte > buffer )
@@ -140,6 +173,13 @@ public void AddDestinationBufferIsSameAssertion(ReadOnlyMemory<byte> buffer)
140173 AssertExtensions . Same ( buffer . Span , destination ) ;
141174 } ;
142175
176+ SignPreHashCoreAction oldSignPreHashCoreHook = SignPreHashCoreHook ;
177+ SignPreHashCoreHook = ( ReadOnlySpan < byte > hash , ReadOnlySpan < byte > context , string hashAlgorithmOid , Span < byte > destination ) =>
178+ {
179+ oldSignPreHashCoreHook ( hash , context , hashAlgorithmOid , destination ) ;
180+ AssertExtensions . Same ( buffer . Span , destination ) ;
181+ } ;
182+
143183 TryExportPkcs8PrivateKeyCoreFunc oldTryExportPkcs8PrivateKeyCoreHook = TryExportPkcs8PrivateKeyCoreHook ;
144184 TryExportPkcs8PrivateKeyCoreHook = ( Span < byte > destination , out int bytesWritten ) =>
145185 {
@@ -165,6 +205,21 @@ public void AddContextBufferIsSameAssertion(ReadOnlyMemory<byte> buffer)
165205 AssertExtensions . Same ( buffer . Span , context ) ;
166206 return ret ;
167207 } ;
208+
209+ SignPreHashCoreAction oldSignPreHashCoreHook = SignPreHashCoreHook ;
210+ SignPreHashCoreHook = ( ReadOnlySpan < byte > hash , ReadOnlySpan < byte > context , string hashAlgorithmOid , Span < byte > destination ) =>
211+ {
212+ oldSignPreHashCoreHook ( hash , context , hashAlgorithmOid , destination ) ;
213+ AssertExtensions . Same ( buffer . Span , context ) ;
214+ } ;
215+
216+ VerifyPreHashCoreFunc oldVerifyPreHashCoreHook = VerifyPreHashCoreHook ;
217+ VerifyPreHashCoreHook = ( ReadOnlySpan < byte > hash , ReadOnlySpan < byte > context , string hashAlgorithmOid , ReadOnlySpan < byte > signature ) =>
218+ {
219+ bool ret = oldVerifyPreHashCoreHook ( hash , context , hashAlgorithmOid , signature ) ;
220+ AssertExtensions . Same ( buffer . Span , context ) ;
221+ return ret ;
222+ } ;
168223 }
169224
170225 public void AddSignatureBufferIsSameAssertion ( ReadOnlyMemory < byte > buffer )
@@ -176,6 +231,14 @@ public void AddSignatureBufferIsSameAssertion(ReadOnlyMemory<byte> buffer)
176231 AssertExtensions . Same ( buffer . Span , signature ) ;
177232 return ret ;
178233 } ;
234+
235+ VerifyPreHashCoreFunc oldVerifyPreHashCoreHook = VerifyPreHashCoreHook ;
236+ VerifyPreHashCoreHook = ( ReadOnlySpan < byte > hash , ReadOnlySpan < byte > context , string hashAlgorithmOid , ReadOnlySpan < byte > signature ) =>
237+ {
238+ bool ret = oldVerifyPreHashCoreHook ( hash , context , hashAlgorithmOid , signature ) ;
239+ AssertExtensions . Same ( buffer . Span , signature ) ;
240+ return ret ;
241+ } ;
179242 }
180243
181244 public void AddDataBufferIsSameAssertion ( ReadOnlyMemory < byte > buffer )
@@ -194,6 +257,39 @@ public void AddDataBufferIsSameAssertion(ReadOnlyMemory<byte> buffer)
194257 AssertExtensions . Same ( buffer . Span , data ) ;
195258 return ret ;
196259 } ;
260+
261+ SignPreHashCoreAction oldSignPreHashCoreHook = SignPreHashCoreHook ;
262+ SignPreHashCoreHook = ( ReadOnlySpan < byte > hash , ReadOnlySpan < byte > context , string hashAlgorithmOid , Span < byte > destination ) =>
263+ {
264+ oldSignPreHashCoreHook ( hash , context , hashAlgorithmOid , destination ) ;
265+ AssertExtensions . Same ( buffer . Span , hash ) ;
266+ } ;
267+
268+ VerifyPreHashCoreFunc oldVerifyPreHashCoreHook = VerifyPreHashCoreHook ;
269+ VerifyPreHashCoreHook = ( ReadOnlySpan < byte > hash , ReadOnlySpan < byte > context , string hashAlgorithmOid , ReadOnlySpan < byte > signature ) =>
270+ {
271+ bool ret = oldVerifyPreHashCoreHook ( hash , context , hashAlgorithmOid , signature ) ;
272+ AssertExtensions . Same ( buffer . Span , hash ) ;
273+ return ret ;
274+ } ;
275+ }
276+
277+ public void AddHashAlgorithmIsSameAssertion ( ReadOnlyMemory < char > buffer )
278+ {
279+ SignPreHashCoreAction oldSignPreHashCoreHook = SignPreHashCoreHook ;
280+ SignPreHashCoreHook = ( ReadOnlySpan < byte > hash , ReadOnlySpan < byte > context , string hashAlgorithmOid , Span < byte > destination ) =>
281+ {
282+ oldSignPreHashCoreHook ( hash , context , hashAlgorithmOid , destination ) ;
283+ AssertExtensions . Same ( buffer . Span , hashAlgorithmOid ) ;
284+ } ;
285+
286+ VerifyPreHashCoreFunc oldVerifyPreHashCoreHook = VerifyPreHashCoreHook ;
287+ VerifyPreHashCoreHook = ( ReadOnlySpan < byte > hash , ReadOnlySpan < byte > context , string hashAlgorithmOid , ReadOnlySpan < byte > signature ) =>
288+ {
289+ bool ret = oldVerifyPreHashCoreHook ( hash , context , hashAlgorithmOid , signature ) ;
290+ AssertExtensions . Same ( buffer . Span , hashAlgorithmOid ) ;
291+ return ret ;
292+ } ;
197293 }
198294
199295 public void AddFillDestination ( byte b )
@@ -219,6 +315,13 @@ public void AddFillDestination(byte b)
219315 destination . Fill ( b ) ;
220316 } ;
221317
318+ SignPreHashCoreAction oldSignPreHashCoreHook = SignPreHashCoreHook ;
319+ SignPreHashCoreHook = ( ReadOnlySpan < byte > hash , ReadOnlySpan < byte > context , string hashAlgorithmOid , Span < byte > destination ) =>
320+ {
321+ oldSignPreHashCoreHook ( hash , context , hashAlgorithmOid , destination ) ;
322+ destination . Fill ( b ) ;
323+ } ;
324+
222325 TryExportPkcs8PrivateKeyCoreFunc oldTryExportPkcs8PrivateKeyCoreHook = TryExportPkcs8PrivateKeyCoreHook ;
223326 TryExportPkcs8PrivateKeyCoreHook = ( Span < byte > destination , out int bytesWritten ) =>
224327 {
0 commit comments