@@ -59,24 +59,108 @@ static int hash_setkey(struct crypto_hash *crt, const u8 *key,
5959 return alg -> setkey (crt , key , keylen );
6060}
6161
62- static int crypto_init_hash_ops (struct crypto_tfm * tfm , u32 type , u32 mask )
62+ static int hash_async_setkey (struct crypto_ahash * tfm_async , const u8 * key ,
63+ unsigned int keylen )
64+ {
65+ struct crypto_tfm * tfm = crypto_ahash_tfm (tfm_async );
66+ struct crypto_hash * tfm_hash = __crypto_hash_cast (tfm );
67+ struct hash_alg * alg = & tfm -> __crt_alg -> cra_hash ;
68+
69+ return alg -> setkey (tfm_hash , key , keylen );
70+ }
71+
72+ static int hash_async_init (struct ahash_request * req )
73+ {
74+ struct crypto_tfm * tfm = req -> base .tfm ;
75+ struct hash_alg * alg = & tfm -> __crt_alg -> cra_hash ;
76+ struct hash_desc desc = {
77+ .tfm = __crypto_hash_cast (tfm ),
78+ .flags = req -> base .flags ,
79+ };
80+
81+ return alg -> init (& desc );
82+ }
83+
84+ static int hash_async_update (struct ahash_request * req )
85+ {
86+ struct crypto_tfm * tfm = req -> base .tfm ;
87+ struct hash_alg * alg = & tfm -> __crt_alg -> cra_hash ;
88+ struct hash_desc desc = {
89+ .tfm = __crypto_hash_cast (tfm ),
90+ .flags = req -> base .flags ,
91+ };
92+
93+ return alg -> update (& desc , req -> src , req -> nbytes );
94+ }
95+
96+ static int hash_async_final (struct ahash_request * req )
97+ {
98+ struct crypto_tfm * tfm = req -> base .tfm ;
99+ struct hash_alg * alg = & tfm -> __crt_alg -> cra_hash ;
100+ struct hash_desc desc = {
101+ .tfm = __crypto_hash_cast (tfm ),
102+ .flags = req -> base .flags ,
103+ };
104+
105+ return alg -> final (& desc , req -> result );
106+ }
107+
108+ static int hash_async_digest (struct ahash_request * req )
109+ {
110+ struct crypto_tfm * tfm = req -> base .tfm ;
111+ struct hash_alg * alg = & tfm -> __crt_alg -> cra_hash ;
112+ struct hash_desc desc = {
113+ .tfm = __crypto_hash_cast (tfm ),
114+ .flags = req -> base .flags ,
115+ };
116+
117+ return alg -> digest (& desc , req -> src , req -> nbytes , req -> result );
118+ }
119+
120+ static int crypto_init_hash_ops_async (struct crypto_tfm * tfm )
121+ {
122+ struct ahash_tfm * crt = & tfm -> crt_ahash ;
123+ struct hash_alg * alg = & tfm -> __crt_alg -> cra_hash ;
124+
125+ crt -> init = hash_async_init ;
126+ crt -> update = hash_async_update ;
127+ crt -> final = hash_async_final ;
128+ crt -> digest = hash_async_digest ;
129+ crt -> setkey = hash_async_setkey ;
130+ crt -> digestsize = alg -> digestsize ;
131+ crt -> base = __crypto_ahash_cast (tfm );
132+
133+ return 0 ;
134+ }
135+
136+ static int crypto_init_hash_ops_sync (struct crypto_tfm * tfm )
63137{
64138 struct hash_tfm * crt = & tfm -> crt_hash ;
65139 struct hash_alg * alg = & tfm -> __crt_alg -> cra_hash ;
66140
67- if (alg -> digestsize > crypto_tfm_alg_blocksize (tfm ))
68- return - EINVAL ;
69-
70- crt -> init = alg -> init ;
71- crt -> update = alg -> update ;
72- crt -> final = alg -> final ;
73- crt -> digest = alg -> digest ;
74- crt -> setkey = hash_setkey ;
141+ crt -> init = alg -> init ;
142+ crt -> update = alg -> update ;
143+ crt -> final = alg -> final ;
144+ crt -> digest = alg -> digest ;
145+ crt -> setkey = hash_setkey ;
75146 crt -> digestsize = alg -> digestsize ;
76147
77148 return 0 ;
78149}
79150
151+ static int crypto_init_hash_ops (struct crypto_tfm * tfm , u32 type , u32 mask )
152+ {
153+ struct hash_alg * alg = & tfm -> __crt_alg -> cra_hash ;
154+
155+ if (alg -> digestsize > crypto_tfm_alg_blocksize (tfm ))
156+ return - EINVAL ;
157+
158+ if ((mask & CRYPTO_ALG_TYPE_HASH_MASK ) != CRYPTO_ALG_TYPE_HASH_MASK )
159+ return crypto_init_hash_ops_async (tfm );
160+ else
161+ return crypto_init_hash_ops_sync (tfm );
162+ }
163+
80164static void crypto_hash_show (struct seq_file * m , struct crypto_alg * alg )
81165 __attribute__ ((unused ));
82166static void crypto_hash_show (struct seq_file * m , struct crypto_alg * alg )
0 commit comments