@@ -175,18 +175,24 @@ impl SigningTranscript for Transcript {
175
175
/// You should use `merlin::Transcript`s directly if you must do
176
176
/// anything more complex, like use signatures in larger zero-knoweldge
177
177
/// protocols or sign several components but only reveal one later.
178
+ ///
179
+ /// We declare these methods `#[inline(always)]` because rustc does
180
+ /// not handle large returns as efficently as one might like.
181
+ /// https://github.com/rust-random/rand/issues/817
178
182
#[ derive( Clone ) ] // Debug
179
183
pub struct SigningContext ( Transcript ) ;
180
184
181
185
/// Initialize a signing context from a static byte string that
182
186
/// identifies the signature's role in the larger protocol.
187
+ #[ inline( always) ]
183
188
pub fn signing_context ( context : & ' static [ u8 ] ) -> SigningContext {
184
189
SigningContext :: new ( context)
185
190
}
186
191
187
192
impl SigningContext {
188
193
/// Initialize a signing context from a static byte string that
189
194
/// identifies the signature's role in the larger protocol.
195
+ #[ inline( always) ]
190
196
pub fn new ( context : & ' static [ u8 ] ) -> SigningContext {
191
197
SigningContext ( Transcript :: new ( context) )
192
198
}
@@ -196,13 +202,15 @@ impl SigningContext {
196
202
/// Avoid this method when processing large slices because it
197
203
/// calls `merlin::Transcript::append_message` directly and
198
204
/// `merlin` is designed for domain seperation, not performance.
205
+ #[ inline( always) ]
199
206
pub fn bytes ( & self , bytes : & [ u8 ] ) -> Transcript {
200
207
let mut t = self . 0 . clone ( ) ;
201
208
t. append_message ( b"sign-bytes" , bytes) ;
202
209
t
203
210
}
204
211
205
212
/// Initalize an owned signing transcript on a message provided as a hash function with extensible output
213
+ #[ inline( always) ]
206
214
pub fn xof < D : ExtendableOutput > ( & self , h : D ) -> Transcript {
207
215
let mut prehash = [ 0u8 ; 32 ] ;
208
216
h. xof_result ( ) . read ( & mut prehash) ;
@@ -213,6 +221,7 @@ impl SigningContext {
213
221
214
222
/// Initalize an owned signing transcript on a message provided as
215
223
/// a hash function with 256 bit output.
224
+ #[ inline( always) ]
216
225
pub fn hash256 < D : FixedOutput < OutputSize =U32 > > ( & self , h : D ) -> Transcript {
217
226
let mut prehash = [ 0u8 ; 32 ] ;
218
227
prehash. copy_from_slice ( h. fixed_result ( ) . as_slice ( ) ) ;
@@ -223,6 +232,7 @@ impl SigningContext {
223
232
224
233
/// Initalize an owned signing transcript on a message provided as
225
234
/// a hash function with 512 bit output, usually a gross over kill.
235
+ #[ inline( always) ]
226
236
pub fn hash512 < D : FixedOutput < OutputSize =U64 > > ( & self , h : D ) -> Transcript {
227
237
let mut prehash = [ 0u8 ; 64 ] ;
228
238
prehash. copy_from_slice ( h. fixed_result ( ) . as_slice ( ) ) ;
@@ -267,6 +277,7 @@ where H: Input + ExtendableOutput + Clone
267
277
/// We intentionally consume and never reexpose the hash function
268
278
/// provided, so that our domain seperation works correctly even
269
279
/// when using `&mut SimpleTranscript : SigningTranscript`.
280
+ #[ inline( always) ]
270
281
pub fn new ( h : H ) -> SimpleTranscript < H > { SimpleTranscript ( h) }
271
282
}
272
283
0 commit comments