@@ -29,13 +29,17 @@ public SlhDsaMockImplementation(SlhDsaAlgorithm algorithm)
29
29
public delegate bool TryExportPkcs8PrivateKeyCoreFunc ( Span < byte > destination , out int bytesWritten ) ;
30
30
public delegate void SignDataCoreAction ( ReadOnlySpan < byte > data , ReadOnlySpan < byte > context , Span < byte > s ) ;
31
31
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 ) ;
32
34
public delegate void DisposeAction ( bool disposing ) ;
33
35
34
36
public TryExportPkcs8PrivateKeyCoreFunc BaseTryExportPkcs8PrivateKeyCore =>
35
37
base . TryExportPkcs8PrivateKeyCore ;
36
38
37
39
public int VerifyDataCoreCallCount = 0 ;
38
40
public int SignDataCoreCallCount = 0 ;
41
+ public int VerifyPreHashCoreCallCount = 0 ;
42
+ public int SignPreHashCoreCallCount = 0 ;
39
43
public int ExportSlhDsaPublicKeyCoreCallCount = 0 ;
40
44
public int ExportSlhDsaSecretKeyCoreCallCount = 0 ;
41
45
public int TryExportPkcs8PrivateKeyCoreCallCount = 0 ;
@@ -47,6 +51,8 @@ public SlhDsaMockImplementation(SlhDsaAlgorithm algorithm)
47
51
( _ , out bytesWritten ) => { Assert. Fail ( ) ; bytesWritten = 0 ; return false ; } ;
48
52
public SignDataCoreAction SignDataCoreHook { get ; set ; } = ( _ , _ , _ ) => Assert . Fail ( ) ;
49
53
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 ; } ;
50
56
public DisposeAction DisposeHook { get ; set ; } = _ => { } ;
51
57
52
58
protected override void ExportSlhDsaPublicKeyCore ( Span < byte > destination )
@@ -85,6 +91,18 @@ protected override bool VerifyDataCore(ReadOnlySpan<byte> data, ReadOnlySpan<byt
85
91
return VerifyDataCoreHook ( data , context , signature ) ;
86
92
}
87
93
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
+
88
106
public void AddLengthAssertion ( )
89
107
{
90
108
ExportSlhDsaPublicKeyCoreAction oldExportSlhDsaPublicKeyCoreHook = ExportSlhDsaPublicKeyCoreHook ;
@@ -115,6 +133,21 @@ public void AddLengthAssertion()
115
133
Assert . Equal ( Algorithm . SignatureSizeInBytes , signature . Length ) ;
116
134
return ret ;
117
135
} ;
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
+ } ;
118
151
}
119
152
120
153
public void AddDestinationBufferIsSameAssertion ( ReadOnlyMemory < byte > buffer )
@@ -140,6 +173,13 @@ public void AddDestinationBufferIsSameAssertion(ReadOnlyMemory<byte> buffer)
140
173
AssertExtensions . Same ( buffer . Span , destination ) ;
141
174
} ;
142
175
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
+
143
183
TryExportPkcs8PrivateKeyCoreFunc oldTryExportPkcs8PrivateKeyCoreHook = TryExportPkcs8PrivateKeyCoreHook ;
144
184
TryExportPkcs8PrivateKeyCoreHook = ( Span < byte > destination , out int bytesWritten ) =>
145
185
{
@@ -165,6 +205,21 @@ public void AddContextBufferIsSameAssertion(ReadOnlyMemory<byte> buffer)
165
205
AssertExtensions . Same ( buffer . Span , context ) ;
166
206
return ret ;
167
207
} ;
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
+ } ;
168
223
}
169
224
170
225
public void AddSignatureBufferIsSameAssertion ( ReadOnlyMemory < byte > buffer )
@@ -176,6 +231,14 @@ public void AddSignatureBufferIsSameAssertion(ReadOnlyMemory<byte> buffer)
176
231
AssertExtensions . Same ( buffer . Span , signature ) ;
177
232
return ret ;
178
233
} ;
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
+ } ;
179
242
}
180
243
181
244
public void AddDataBufferIsSameAssertion ( ReadOnlyMemory < byte > buffer )
@@ -194,6 +257,39 @@ public void AddDataBufferIsSameAssertion(ReadOnlyMemory<byte> buffer)
194
257
AssertExtensions . Same ( buffer . Span , data ) ;
195
258
return ret ;
196
259
} ;
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
+ } ;
197
293
}
198
294
199
295
public void AddFillDestination ( byte b )
@@ -219,6 +315,13 @@ public void AddFillDestination(byte b)
219
315
destination . Fill ( b ) ;
220
316
} ;
221
317
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
+
222
325
TryExportPkcs8PrivateKeyCoreFunc oldTryExportPkcs8PrivateKeyCoreHook = TryExportPkcs8PrivateKeyCoreHook ;
223
326
TryExportPkcs8PrivateKeyCoreHook = ( Span < byte > destination , out int bytesWritten ) =>
224
327
{
0 commit comments