8
8
#![ deny( missing_docs) ] // Require all public interfaces to be documented
9
9
10
10
//! # Usage
11
- //! This crate implements the Stateless Hash-based Digital Signature Algorithm (SLH-DSA) based on the draft
11
+ //! This crate implements the Stateless Hash-based Digital Signature Algorithm (SLH-DSA) based on the finalized
12
12
//! standard by NIST in FIPS-205. SLH-DSA (based on the SPHINCS+ submission) is a signature algorithm designed
13
13
//! to be resistant to quantum computers.
14
14
//!
@@ -80,6 +80,7 @@ mod tests {
80
80
use super :: * ;
81
81
use rand:: Rng ;
82
82
use signature:: * ;
83
+ use util:: macros:: test_parameter_sets;
83
84
84
85
fn test_sign_verify < P : ParameterSet > ( ) {
85
86
let mut rng = rand:: thread_rng ( ) ;
@@ -89,66 +90,7 @@ mod tests {
89
90
let sig = sk. try_sign ( msg) . unwrap ( ) ;
90
91
vk. verify ( msg, & sig) . unwrap ( ) ;
91
92
}
92
-
93
- #[ test]
94
- fn test_sign_verify_shake_128f ( ) {
95
- test_sign_verify :: < Shake128f > ( ) ;
96
- }
97
-
98
- #[ test]
99
- fn test_sign_verify_shake_128s ( ) {
100
- test_sign_verify :: < Shake128s > ( ) ;
101
- }
102
-
103
- #[ test]
104
- fn test_sign_verify_shake_192f ( ) {
105
- test_sign_verify :: < Shake192f > ( ) ;
106
- }
107
-
108
- #[ test]
109
- fn test_sign_verify_shake_192s ( ) {
110
- test_sign_verify :: < Shake192s > ( ) ;
111
- }
112
-
113
- #[ test]
114
- fn test_sign_verify_shake_256f ( ) {
115
- test_sign_verify :: < Shake256f > ( ) ;
116
- }
117
-
118
- #[ test]
119
- fn test_sign_verify_shake_256s ( ) {
120
- test_sign_verify :: < Shake256s > ( ) ;
121
- }
122
-
123
- #[ test]
124
- fn test_sign_verify_sha2_128f ( ) {
125
- test_sign_verify :: < Sha2_128f > ( ) ;
126
- }
127
-
128
- #[ test]
129
- fn test_sign_verify_sha2_128s ( ) {
130
- test_sign_verify :: < Sha2_128s > ( ) ;
131
- }
132
-
133
- #[ test]
134
- fn test_sign_verify_sha2_192f ( ) {
135
- test_sign_verify :: < Sha2_192f > ( ) ;
136
- }
137
-
138
- #[ test]
139
- fn test_sign_verify_sha2_192s ( ) {
140
- test_sign_verify :: < Sha2_192s > ( ) ;
141
- }
142
-
143
- #[ test]
144
- fn test_sign_verify_sha2_256f ( ) {
145
- test_sign_verify :: < Sha2_256f > ( ) ;
146
- }
147
-
148
- #[ test]
149
- fn test_sign_verify_sha2_256s ( ) {
150
- test_sign_verify :: < Sha2_256s > ( ) ;
151
- }
93
+ test_parameter_sets ! ( test_sign_verify) ;
152
94
153
95
// Check signature fails on modified message
154
96
#[ test]
@@ -212,4 +154,27 @@ mod tests {
212
154
"Two successive randomized signatures over the same message should not be equal"
213
155
) ;
214
156
}
157
+
158
+ #[ test]
159
+ fn test_sign_verify_nonempty_context ( ) {
160
+ let mut rng = rand:: thread_rng ( ) ;
161
+ let sk = SigningKey :: < Shake128f > :: new ( & mut rng) ;
162
+ let vk = sk. verifying_key ( ) ;
163
+ let msg = b"Hello, world!" ;
164
+ let ctx = b"Test context" ;
165
+ let sig = sk. try_sign_with_context ( msg, ctx, None ) . unwrap ( ) ;
166
+ vk. try_verify_with_context ( msg, ctx, & sig) . unwrap ( ) ;
167
+ }
168
+
169
+ #[ test]
170
+ fn test_sign_verify_wrong_context ( ) {
171
+ let mut rng = rand:: thread_rng ( ) ;
172
+ let sk = SigningKey :: < Shake128f > :: new ( & mut rng) ;
173
+ let vk = sk. verifying_key ( ) ;
174
+ let msg = b"Hello, world!" ;
175
+ let ctx = b"Test context!" ;
176
+ let wrong_ctx = b"Wrong context" ;
177
+ let sig = sk. try_sign_with_context ( msg, ctx, None ) . unwrap ( ) ;
178
+ assert ! ( vk. try_verify_with_context( msg, wrong_ctx, & sig) . is_err( ) ) ;
179
+ }
215
180
}
0 commit comments