1818#include <linux/module.h>
1919#include <linux/slab.h>
2020#include <linux/key.h>
21- #include <linux/crypto.h>
22- #include <crypto/hash.h>
2321#include <crypto/sha1.h>
2422#include <keys/user-type.h>
2523#include <linux/mpi.h>
2624#include <linux/digsig.h>
2725
28- static struct crypto_shash * shash ;
29-
3026static const char * pkcs_1_v1_5_decode_emsa (const unsigned char * msg ,
3127 unsigned long msglen ,
3228 unsigned long modulus_bitlen ,
@@ -199,12 +195,12 @@ static int digsig_verify_rsa(struct key *key,
199195int digsig_verify (struct key * keyring , const char * sig , int siglen ,
200196 const char * data , int datalen )
201197{
202- int err = - ENOMEM ;
203198 struct signature_hdr * sh = (struct signature_hdr * )sig ;
204- struct shash_desc * desc = NULL ;
199+ struct sha1_ctx ctx ;
205200 unsigned char hash [SHA1_DIGEST_SIZE ];
206201 struct key * key ;
207202 char name [20 ];
203+ int err ;
208204
209205 if (siglen < sizeof (* sh ) + 2 )
210206 return - EINVAL ;
@@ -231,49 +227,19 @@ int digsig_verify(struct key *keyring, const char *sig, int siglen,
231227 return PTR_ERR (key );
232228 }
233229
234- desc = kzalloc (sizeof (* desc ) + crypto_shash_descsize (shash ),
235- GFP_KERNEL );
236- if (!desc )
237- goto err ;
238-
239- desc -> tfm = shash ;
240-
241- crypto_shash_init (desc );
242- crypto_shash_update (desc , data , datalen );
243- crypto_shash_update (desc , sig , sizeof (* sh ));
244- crypto_shash_final (desc , hash );
245-
246- kfree (desc );
230+ sha1_init (& ctx );
231+ sha1_update (& ctx , data , datalen );
232+ sha1_update (& ctx , sig , sizeof (* sh ));
233+ sha1_final (& ctx , hash );
247234
248235 /* pass signature mpis address */
249236 err = digsig_verify_rsa (key , sig + sizeof (* sh ), siglen - sizeof (* sh ),
250237 hash , sizeof (hash ));
251238
252- err :
253239 key_put (key );
254240
255241 return err ? - EINVAL : 0 ;
256242}
257243EXPORT_SYMBOL_GPL (digsig_verify );
258244
259- static int __init digsig_init (void )
260- {
261- shash = crypto_alloc_shash ("sha1" , 0 , 0 );
262- if (IS_ERR (shash )) {
263- pr_err ("shash allocation failed\n" );
264- return PTR_ERR (shash );
265- }
266-
267- return 0 ;
268-
269- }
270-
271- static void __exit digsig_cleanup (void )
272- {
273- crypto_free_shash (shash );
274- }
275-
276- module_init (digsig_init );
277- module_exit (digsig_cleanup );
278-
279245MODULE_LICENSE ("GPL" );
0 commit comments