3131#include <crypto/gcm.h>
3232#include <crypto/sha.h>
3333#include <crypto/ctr.h>
34+ #include <crypto/skcipher.h>
3435#include "crypto4xx_reg_def.h"
3536#include "crypto4xx_core.h"
3637#include "crypto4xx_sa.h"
@@ -74,57 +75,57 @@ static void set_dynamic_sa_command_1(struct dynamic_sa_ctl *sa, u32 cm,
7475 sa -> sa_command_1 .bf .copy_hdr = cp_hdr ;
7576}
7677
77- static inline int crypto4xx_crypt (struct ablkcipher_request * req ,
78+ static inline int crypto4xx_crypt (struct skcipher_request * req ,
7879 const unsigned int ivlen , bool decrypt )
7980{
80- struct crypto4xx_ctx * ctx = crypto_tfm_ctx (req -> base .tfm );
81+ struct crypto_skcipher * cipher = crypto_skcipher_reqtfm (req );
82+ struct crypto4xx_ctx * ctx = crypto_skcipher_ctx (cipher );
8183 __le32 iv [ivlen ];
8284
8385 if (ivlen )
84- crypto4xx_memcpy_to_le32 (iv , req -> info , ivlen );
86+ crypto4xx_memcpy_to_le32 (iv , req -> iv , ivlen );
8587
8688 return crypto4xx_build_pd (& req -> base , ctx , req -> src , req -> dst ,
87- req -> nbytes , iv , ivlen , decrypt ? ctx -> sa_in : ctx -> sa_out ,
89+ req -> cryptlen , iv , ivlen , decrypt ? ctx -> sa_in : ctx -> sa_out ,
8890 ctx -> sa_len , 0 );
8991}
9092
91- int crypto4xx_encrypt_noiv (struct ablkcipher_request * req )
93+ int crypto4xx_encrypt_noiv (struct skcipher_request * req )
9294{
9395 return crypto4xx_crypt (req , 0 , false);
9496}
9597
96- int crypto4xx_encrypt_iv (struct ablkcipher_request * req )
98+ int crypto4xx_encrypt_iv (struct skcipher_request * req )
9799{
98100 return crypto4xx_crypt (req , AES_IV_SIZE , false);
99101}
100102
101- int crypto4xx_decrypt_noiv (struct ablkcipher_request * req )
103+ int crypto4xx_decrypt_noiv (struct skcipher_request * req )
102104{
103105 return crypto4xx_crypt (req , 0 , true);
104106}
105107
106- int crypto4xx_decrypt_iv (struct ablkcipher_request * req )
108+ int crypto4xx_decrypt_iv (struct skcipher_request * req )
107109{
108110 return crypto4xx_crypt (req , AES_IV_SIZE , true);
109111}
110112
111113/**
112114 * AES Functions
113115 */
114- static int crypto4xx_setkey_aes (struct crypto_ablkcipher * cipher ,
116+ static int crypto4xx_setkey_aes (struct crypto_skcipher * cipher ,
115117 const u8 * key ,
116118 unsigned int keylen ,
117119 unsigned char cm ,
118120 u8 fb )
119121{
120- struct crypto_tfm * tfm = crypto_ablkcipher_tfm (cipher );
121- struct crypto4xx_ctx * ctx = crypto_tfm_ctx (tfm );
122+ struct crypto4xx_ctx * ctx = crypto_skcipher_ctx (cipher );
122123 struct dynamic_sa_ctl * sa ;
123124 int rc ;
124125
125126 if (keylen != AES_KEYSIZE_256 &&
126127 keylen != AES_KEYSIZE_192 && keylen != AES_KEYSIZE_128 ) {
127- crypto_ablkcipher_set_flags (cipher ,
128+ crypto_skcipher_set_flags (cipher ,
128129 CRYPTO_TFM_RES_BAD_KEY_LEN );
129130 return - EINVAL ;
130131 }
@@ -164,39 +165,38 @@ static int crypto4xx_setkey_aes(struct crypto_ablkcipher *cipher,
164165 return 0 ;
165166}
166167
167- int crypto4xx_setkey_aes_cbc (struct crypto_ablkcipher * cipher ,
168+ int crypto4xx_setkey_aes_cbc (struct crypto_skcipher * cipher ,
168169 const u8 * key , unsigned int keylen )
169170{
170171 return crypto4xx_setkey_aes (cipher , key , keylen , CRYPTO_MODE_CBC ,
171172 CRYPTO_FEEDBACK_MODE_NO_FB );
172173}
173174
174- int crypto4xx_setkey_aes_cfb (struct crypto_ablkcipher * cipher ,
175+ int crypto4xx_setkey_aes_cfb (struct crypto_skcipher * cipher ,
175176 const u8 * key , unsigned int keylen )
176177{
177178 return crypto4xx_setkey_aes (cipher , key , keylen , CRYPTO_MODE_CFB ,
178179 CRYPTO_FEEDBACK_MODE_128BIT_CFB );
179180}
180181
181- int crypto4xx_setkey_aes_ecb (struct crypto_ablkcipher * cipher ,
182+ int crypto4xx_setkey_aes_ecb (struct crypto_skcipher * cipher ,
182183 const u8 * key , unsigned int keylen )
183184{
184185 return crypto4xx_setkey_aes (cipher , key , keylen , CRYPTO_MODE_ECB ,
185186 CRYPTO_FEEDBACK_MODE_NO_FB );
186187}
187188
188- int crypto4xx_setkey_aes_ofb (struct crypto_ablkcipher * cipher ,
189+ int crypto4xx_setkey_aes_ofb (struct crypto_skcipher * cipher ,
189190 const u8 * key , unsigned int keylen )
190191{
191192 return crypto4xx_setkey_aes (cipher , key , keylen , CRYPTO_MODE_OFB ,
192193 CRYPTO_FEEDBACK_MODE_64BIT_OFB );
193194}
194195
195- int crypto4xx_setkey_rfc3686 (struct crypto_ablkcipher * cipher ,
196+ int crypto4xx_setkey_rfc3686 (struct crypto_skcipher * cipher ,
196197 const u8 * key , unsigned int keylen )
197198{
198- struct crypto_tfm * tfm = crypto_ablkcipher_tfm (cipher );
199- struct crypto4xx_ctx * ctx = crypto_tfm_ctx (tfm );
199+ struct crypto4xx_ctx * ctx = crypto_skcipher_ctx (cipher );
200200 int rc ;
201201
202202 rc = crypto4xx_setkey_aes (cipher , key , keylen - CTR_RFC3686_NONCE_SIZE ,
@@ -210,31 +210,33 @@ int crypto4xx_setkey_rfc3686(struct crypto_ablkcipher *cipher,
210210 return 0 ;
211211}
212212
213- int crypto4xx_rfc3686_encrypt (struct ablkcipher_request * req )
213+ int crypto4xx_rfc3686_encrypt (struct skcipher_request * req )
214214{
215- struct crypto4xx_ctx * ctx = crypto_tfm_ctx (req -> base .tfm );
215+ struct crypto_skcipher * cipher = crypto_skcipher_reqtfm (req );
216+ struct crypto4xx_ctx * ctx = crypto_skcipher_ctx (cipher );
216217 __le32 iv [AES_IV_SIZE / 4 ] = {
217218 ctx -> iv_nonce ,
218- cpu_to_le32p ((u32 * ) req -> info ),
219- cpu_to_le32p ((u32 * ) (req -> info + 4 )),
219+ cpu_to_le32p ((u32 * ) req -> iv ),
220+ cpu_to_le32p ((u32 * ) (req -> iv + 4 )),
220221 cpu_to_le32 (1 ) };
221222
222223 return crypto4xx_build_pd (& req -> base , ctx , req -> src , req -> dst ,
223- req -> nbytes , iv , AES_IV_SIZE ,
224+ req -> cryptlen , iv , AES_IV_SIZE ,
224225 ctx -> sa_out , ctx -> sa_len , 0 );
225226}
226227
227- int crypto4xx_rfc3686_decrypt (struct ablkcipher_request * req )
228+ int crypto4xx_rfc3686_decrypt (struct skcipher_request * req )
228229{
229- struct crypto4xx_ctx * ctx = crypto_tfm_ctx (req -> base .tfm );
230+ struct crypto_skcipher * cipher = crypto_skcipher_reqtfm (req );
231+ struct crypto4xx_ctx * ctx = crypto_skcipher_ctx (cipher );
230232 __le32 iv [AES_IV_SIZE / 4 ] = {
231233 ctx -> iv_nonce ,
232- cpu_to_le32p ((u32 * ) req -> info ),
233- cpu_to_le32p ((u32 * ) (req -> info + 4 )),
234+ cpu_to_le32p ((u32 * ) req -> iv ),
235+ cpu_to_le32p ((u32 * ) (req -> iv + 4 )),
234236 cpu_to_le32 (1 ) };
235237
236238 return crypto4xx_build_pd (& req -> base , ctx , req -> src , req -> dst ,
237- req -> nbytes , iv , AES_IV_SIZE ,
239+ req -> cryptlen , iv , AES_IV_SIZE ,
238240 ctx -> sa_out , ctx -> sa_len , 0 );
239241}
240242
0 commit comments