35
35
//!
36
36
//! let secp = Secp256k1::new();
37
37
//! let (secret_key, public_key) = secp.generate_keypair(&mut OsRng);
38
- //! let message = Message::from_hashed_data::< sha256::Hash> ("Hello World !".as_bytes());
38
+ //! let message = Message::from( sha256::Hash::hash ("Hello world !".as_bytes() ));
39
39
//!
40
40
//! let sig = secp.sign_ecdsa(&message, &secret_key);
41
41
//! assert!(secp.verify_ecdsa(&message, &sig, &public_key).is_ok());
50
50
//! use secp256k1::hashes::sha256;
51
51
//!
52
52
//! let (secret_key, public_key) = generate_keypair(&mut rand::thread_rng());
53
- //! let message = Message::from_hashed_data::< sha256::Hash> ("Hello World !".as_bytes());
53
+ //! let message = Message::from( sha256::Hash::hash ("Hello world !".as_bytes() ));
54
54
//!
55
55
//! let sig = secret_key.sign_ecdsa(message);
56
56
//! assert!(sig.verify(&message, &public_key).is_ok());
@@ -176,8 +176,6 @@ use core::{fmt, mem, str};
176
176
177
177
#[ cfg( all( feature = "global-context" , feature = "std" ) ) ]
178
178
pub use context:: global:: { self , SECP256K1 } ;
179
- #[ cfg( feature = "hashes" ) ]
180
- use hashes:: Hash ;
181
179
#[ cfg( feature = "rand" ) ]
182
180
pub use rand;
183
181
pub use secp256k1_sys as ffi;
@@ -198,34 +196,20 @@ pub use crate::scalar::Scalar;
198
196
/// Trait describing something that promises to be a 32-byte random number; in particular,
199
197
/// it has negligible probability of being zero or overflowing the group order. Such objects
200
198
/// may be converted to `Message`s without any error paths.
199
+ #[ deprecated( since = "0.29.0" , note = "this will be removed soon" ) ]
201
200
pub trait ThirtyTwoByteHash {
202
201
/// Converts the object into a 32-byte array
203
202
fn into_32 ( self ) -> [ u8 ; 32 ] ;
204
203
}
205
204
206
- #[ cfg( feature = "hashes" ) ]
207
- impl ThirtyTwoByteHash for hashes:: sha256:: Hash {
208
- fn into_32 ( self ) -> [ u8 ; 32 ] { self . to_byte_array ( ) }
209
- }
210
-
211
- #[ cfg( feature = "hashes" ) ]
212
- impl ThirtyTwoByteHash for hashes:: sha256d:: Hash {
213
- fn into_32 ( self ) -> [ u8 ; 32 ] { self . to_byte_array ( ) }
214
- }
215
-
216
- #[ cfg( feature = "hashes" ) ]
217
- impl < T : hashes:: sha256t:: Tag > ThirtyTwoByteHash for hashes:: sha256t:: Hash < T > {
218
- fn into_32 ( self ) -> [ u8 ; 32 ] { self . to_byte_array ( ) }
219
- }
220
-
221
205
/// A (hashed) message input to an ECDSA signature.
222
206
#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
223
207
pub struct Message ( [ u8 ; constants:: MESSAGE_SIZE ] ) ;
224
208
impl_array_newtype ! ( Message , u8 , constants:: MESSAGE_SIZE ) ;
225
209
impl_pretty_debug ! ( Message ) ;
226
210
227
211
impl Message {
228
- /// **If you just want to sign an arbitrary message use `Message::from_hashed_data` instead.**
212
+ /// Creates a [`Message`] from a 32 byte slice `digest`.
229
213
///
230
214
/// Converts a `MESSAGE_SIZE`-byte slice to a message object. **WARNING:** the slice has to be a
231
215
/// cryptographically secure hash of the actual message that's going to be signed. Otherwise
@@ -239,8 +223,6 @@ impl Message {
239
223
240
224
/// Creates a [`Message`] from a `digest`.
241
225
///
242
- /// **If you just want to sign an arbitrary message use `Message::from_hashed_data` instead.**
243
- ///
244
226
/// The `digest` array has to be a cryptographically secure hash of the actual message that's
245
227
/// going to be signed. Otherwise the result of signing isn't a [secure signature].
246
228
///
@@ -250,8 +232,6 @@ impl Message {
250
232
251
233
/// Creates a [`Message`] from a 32 byte slice `digest`.
252
234
///
253
- /// **If you just want to sign an arbitrary message use `Message::from_hashed_data` instead.**
254
- ///
255
235
/// The slice has to be 32 bytes long and be a cryptographically secure hash of the actual
256
236
/// message that's going to be signed. Otherwise the result of signing isn't a [secure
257
237
/// signature].
@@ -272,29 +252,6 @@ impl Message {
272
252
_ => Err ( Error :: InvalidMessage ) ,
273
253
}
274
254
}
275
-
276
- /// Constructs a [`Message`] by hashing `data` with hash algorithm `H`.
277
- ///
278
- /// Requires the feature `hashes` to be enabled.
279
- ///
280
- /// # Examples
281
- ///
282
- /// ```
283
- /// # #[cfg(feature = "hashes")] {
284
- /// use secp256k1::hashes::{sha256, Hash};
285
- /// use secp256k1::Message;
286
- ///
287
- /// let m1 = Message::from_hashed_data::<sha256::Hash>("Hello world!".as_bytes());
288
- /// // is equivalent to
289
- /// let m2 = Message::from(sha256::Hash::hash("Hello world!".as_bytes()));
290
- ///
291
- /// assert_eq!(m1, m2);
292
- /// # }
293
- /// ```
294
- #[ cfg( feature = "hashes" ) ]
295
- pub fn from_hashed_data < H : ThirtyTwoByteHash + hashes:: Hash > ( data : & [ u8 ] ) -> Self {
296
- <H as hashes:: Hash >:: hash ( data) . into ( )
297
- }
298
255
}
299
256
300
257
impl < T : ThirtyTwoByteHash > From < T > for Message {
@@ -1043,24 +1000,6 @@ mod tests {
1043
1000
let sig = SECP256K1 . sign_ecdsa ( & msg, & sk) ;
1044
1001
assert ! ( SECP256K1 . verify_ecdsa( & msg, & sig, & pk) . is_ok( ) ) ;
1045
1002
}
1046
-
1047
- #[ cfg( feature = "hashes" ) ]
1048
- #[ test]
1049
- fn test_from_hash ( ) {
1050
- use hashes:: { sha256, sha256d, Hash } ;
1051
-
1052
- let test_bytes = "Hello world!" . as_bytes ( ) ;
1053
-
1054
- let hash = sha256:: Hash :: hash ( test_bytes) ;
1055
- let msg = Message :: from ( hash) ;
1056
- assert_eq ! ( msg. 0 , hash. to_byte_array( ) ) ;
1057
- assert_eq ! ( msg, Message :: from_hashed_data:: <hashes:: sha256:: Hash >( test_bytes) ) ;
1058
-
1059
- let hash = sha256d:: Hash :: hash ( test_bytes) ;
1060
- let msg = Message :: from ( hash) ;
1061
- assert_eq ! ( msg. 0 , hash. to_byte_array( ) ) ;
1062
- assert_eq ! ( msg, Message :: from_hashed_data:: <hashes:: sha256d:: Hash >( test_bytes) ) ;
1063
- }
1064
1003
}
1065
1004
1066
1005
#[ cfg( bench) ]
0 commit comments