@@ -163,10 +163,6 @@ static int rsassa_pkcs1_sign(struct crypto_sig *tfm,
163
163
struct rsassa_pkcs1_inst_ctx * ictx = sig_instance_ctx (inst );
164
164
const struct hash_prefix * hash_prefix = ictx -> hash_prefix ;
165
165
struct rsassa_pkcs1_ctx * ctx = crypto_sig_ctx (tfm );
166
- unsigned int child_reqsize = crypto_akcipher_reqsize (ctx -> child );
167
- struct akcipher_request * child_req __free (kfree_sensitive ) = NULL ;
168
- struct scatterlist in_sg [3 ], out_sg ;
169
- struct crypto_wait cwait ;
170
166
unsigned int pad_len ;
171
167
unsigned int ps_end ;
172
168
unsigned int len ;
@@ -187,37 +183,25 @@ static int rsassa_pkcs1_sign(struct crypto_sig *tfm,
187
183
188
184
pad_len = ctx -> key_size - slen - hash_prefix -> size - 1 ;
189
185
190
- child_req = kmalloc (sizeof (* child_req ) + child_reqsize + pad_len ,
191
- GFP_KERNEL );
192
- if (!child_req )
193
- return - ENOMEM ;
194
-
195
186
/* RFC 8017 sec 8.2.1 step 1 - EMSA-PKCS1-v1_5 encoding generation */
196
- in_buf = (u8 * )(child_req + 1 ) + child_reqsize ;
187
+ in_buf = dst ;
188
+ memmove (in_buf + pad_len + hash_prefix -> size , src , slen );
189
+ memcpy (in_buf + pad_len , hash_prefix -> data , hash_prefix -> size );
190
+
197
191
ps_end = pad_len - 1 ;
198
192
in_buf [0 ] = 0x01 ;
199
193
memset (in_buf + 1 , 0xff , ps_end - 1 );
200
194
in_buf [ps_end ] = 0x00 ;
201
195
202
- /* RFC 8017 sec 8.2.1 step 2 - RSA signature */
203
- crypto_init_wait (& cwait );
204
- sg_init_table (in_sg , 3 );
205
- sg_set_buf (& in_sg [0 ], in_buf , pad_len );
206
- sg_set_buf (& in_sg [1 ], hash_prefix -> data , hash_prefix -> size );
207
- sg_set_buf (& in_sg [2 ], src , slen );
208
- sg_init_one (& out_sg , dst , dlen );
209
- akcipher_request_set_tfm (child_req , ctx -> child );
210
- akcipher_request_set_crypt (child_req , in_sg , & out_sg ,
211
- ctx -> key_size - 1 , dlen );
212
- akcipher_request_set_callback (child_req , CRYPTO_TFM_REQ_MAY_SLEEP ,
213
- crypto_req_done , & cwait );
214
196
215
- err = crypto_akcipher_decrypt (child_req );
216
- err = crypto_wait_req (err , & cwait );
217
- if (err )
197
+ /* RFC 8017 sec 8.2.1 step 2 - RSA signature */
198
+ err = crypto_akcipher_sync_decrypt (ctx -> child , in_buf ,
199
+ ctx -> key_size - 1 , in_buf ,
200
+ ctx -> key_size );
201
+ if (err < 0 )
218
202
return err ;
219
203
220
- len = child_req -> dst_len ;
204
+ len = err ;
221
205
pad_len = ctx -> key_size - len ;
222
206
223
207
/* Four billion to one */
@@ -239,8 +223,8 @@ static int rsassa_pkcs1_verify(struct crypto_sig *tfm,
239
223
struct rsassa_pkcs1_ctx * ctx = crypto_sig_ctx (tfm );
240
224
unsigned int child_reqsize = crypto_akcipher_reqsize (ctx -> child );
241
225
struct akcipher_request * child_req __free (kfree_sensitive ) = NULL ;
242
- struct scatterlist in_sg , out_sg ;
243
226
struct crypto_wait cwait ;
227
+ struct scatterlist sg ;
244
228
unsigned int dst_len ;
245
229
unsigned int pos ;
246
230
u8 * out_buf ;
@@ -259,13 +243,12 @@ static int rsassa_pkcs1_verify(struct crypto_sig *tfm,
259
243
return - ENOMEM ;
260
244
261
245
out_buf = (u8 * )(child_req + 1 ) + child_reqsize ;
246
+ memcpy (out_buf , src , slen );
262
247
263
248
crypto_init_wait (& cwait );
264
- sg_init_one (& in_sg , src , slen );
265
- sg_init_one (& out_sg , out_buf , ctx -> key_size );
249
+ sg_init_one (& sg , out_buf , slen );
266
250
akcipher_request_set_tfm (child_req , ctx -> child );
267
- akcipher_request_set_crypt (child_req , & in_sg , & out_sg ,
268
- slen , ctx -> key_size );
251
+ akcipher_request_set_crypt (child_req , & sg , & sg , slen , slen );
269
252
akcipher_request_set_callback (child_req , CRYPTO_TFM_REQ_MAY_SLEEP ,
270
253
crypto_req_done , & cwait );
271
254
0 commit comments