Commit 5190ad6 1 parent 1b86ff1 commit 5190ad6 Copy full SHA for 5190ad6
File tree 2 files changed +15
-0
lines changed
2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -163,6 +163,15 @@ impl VerifyingKey {
163
163
Context :: new ( self , context_value)
164
164
}
165
165
166
+ /// Returns whether this is a _weak_ public key, i.e., if this public key has low order.
167
+ ///
168
+ /// A weak public key can be used to generate a siganture that's valid for almost every
169
+ /// message. [`Self::verify_strict`] denies weak keys, but if you want to check for this
170
+ /// property before verification, then use this method.
171
+ pub fn is_weak ( & self ) -> bool {
172
+ self . 1 . is_small_order ( )
173
+ }
174
+
166
175
/// Internal utility function for clamping a scalar representation and multiplying by the
167
176
/// basepont to produce a public key.
168
177
fn clamp_and_mul_base ( bits : [ u8 ; 32 ] ) -> VerifyingKey {
Original file line number Diff line number Diff line change @@ -228,6 +228,9 @@ mod vectors {
228
228
assert ! ( vk. verify( message1, & sig) . is_ok( ) ) ;
229
229
assert ! ( vk. verify( message2, & sig) . is_ok( ) ) ;
230
230
231
+ // Check that this public key appears as weak
232
+ assert ! ( vk. is_weak( ) ) ;
233
+
231
234
// Now check that the sigs fail under verify_strict. This is because verify_strict rejects
232
235
// small order pubkeys.
233
236
assert ! ( vk. verify_strict( message1, & sig) . is_err( ) ) ;
@@ -306,6 +309,9 @@ mod integrations {
306
309
good_sig = signing_key. sign ( & good) ;
307
310
bad_sig = signing_key. sign ( & bad) ;
308
311
312
+ // Check that an honestly generated public key is not weak
313
+ assert ! ( !verifying_key. is_weak( ) ) ;
314
+
309
315
assert ! (
310
316
signing_key. verify( & good, & good_sig) . is_ok( ) ,
311
317
"Verification of a valid signature failed!"
You can’t perform that action at this time.
0 commit comments