James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 1 | /** |
| 2 | * AMCC SoC PPC4xx Crypto Driver |
| 3 | * |
| 4 | * Copyright (c) 2008 Applied Micro Circuits Corporation. |
| 5 | * All rights reserved. James Hsiao <jhsiao@amcc.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * This file implements the Linux crypto algorithms. |
| 18 | */ |
| 19 | |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/interrupt.h> |
| 22 | #include <linux/spinlock_types.h> |
| 23 | #include <linux/scatterlist.h> |
| 24 | #include <linux/crypto.h> |
| 25 | #include <linux/hash.h> |
| 26 | #include <crypto/internal/hash.h> |
| 27 | #include <linux/dma-mapping.h> |
| 28 | #include <crypto/algapi.h> |
| 29 | #include <crypto/aes.h> |
| 30 | #include <crypto/sha.h> |
Christian Lamparter | f2a13e7 | 2017-08-25 15:47:21 +0200 | [diff] [blame] | 31 | #include <crypto/ctr.h> |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 32 | #include "crypto4xx_reg_def.h" |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 33 | #include "crypto4xx_core.h" |
Christian Lamparter | 249c8d9 | 2017-08-25 15:47:20 +0200 | [diff] [blame] | 34 | #include "crypto4xx_sa.h" |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 35 | |
Jingoo Han | 3a4eac7 | 2013-08-09 16:59:57 +0900 | [diff] [blame] | 36 | static void set_dynamic_sa_command_0(struct dynamic_sa_ctl *sa, u32 save_h, |
| 37 | u32 save_iv, u32 ld_h, u32 ld_iv, |
| 38 | u32 hdr_proc, u32 h, u32 c, u32 pad_type, |
| 39 | u32 op_grp, u32 op, u32 dir) |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 40 | { |
| 41 | sa->sa_command_0.w = 0; |
| 42 | sa->sa_command_0.bf.save_hash_state = save_h; |
| 43 | sa->sa_command_0.bf.save_iv = save_iv; |
| 44 | sa->sa_command_0.bf.load_hash_state = ld_h; |
| 45 | sa->sa_command_0.bf.load_iv = ld_iv; |
| 46 | sa->sa_command_0.bf.hdr_proc = hdr_proc; |
| 47 | sa->sa_command_0.bf.hash_alg = h; |
| 48 | sa->sa_command_0.bf.cipher_alg = c; |
| 49 | sa->sa_command_0.bf.pad_type = pad_type & 3; |
| 50 | sa->sa_command_0.bf.extend_pad = pad_type >> 2; |
| 51 | sa->sa_command_0.bf.op_group = op_grp; |
| 52 | sa->sa_command_0.bf.opcode = op; |
| 53 | sa->sa_command_0.bf.dir = dir; |
| 54 | } |
| 55 | |
Jingoo Han | 3a4eac7 | 2013-08-09 16:59:57 +0900 | [diff] [blame] | 56 | static void set_dynamic_sa_command_1(struct dynamic_sa_ctl *sa, u32 cm, |
| 57 | u32 hmac_mc, u32 cfb, u32 esn, |
| 58 | u32 sn_mask, u32 mute, u32 cp_pad, |
| 59 | u32 cp_pay, u32 cp_hdr) |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 60 | { |
| 61 | sa->sa_command_1.w = 0; |
| 62 | sa->sa_command_1.bf.crypto_mode31 = (cm & 4) >> 2; |
| 63 | sa->sa_command_1.bf.crypto_mode9_8 = cm & 3; |
| 64 | sa->sa_command_1.bf.feedback_mode = cfb, |
| 65 | sa->sa_command_1.bf.sa_rev = 1; |
Christian Lamparter | 5a4326d3 | 2017-10-04 01:00:05 +0200 | [diff] [blame] | 66 | sa->sa_command_1.bf.hmac_muting = hmac_mc; |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 67 | sa->sa_command_1.bf.extended_seq_num = esn; |
| 68 | sa->sa_command_1.bf.seq_num_mask = sn_mask; |
| 69 | sa->sa_command_1.bf.mutable_bit_proc = mute; |
| 70 | sa->sa_command_1.bf.copy_pad = cp_pad; |
| 71 | sa->sa_command_1.bf.copy_payload = cp_pay; |
| 72 | sa->sa_command_1.bf.copy_hdr = cp_hdr; |
| 73 | } |
| 74 | |
| 75 | int crypto4xx_encrypt(struct ablkcipher_request *req) |
| 76 | { |
| 77 | struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm); |
Christian Lamparter | cd4dcd6 | 2017-10-04 01:00:11 +0200 | [diff] [blame] | 78 | unsigned int ivlen = crypto_ablkcipher_ivsize( |
| 79 | crypto_ablkcipher_reqtfm(req)); |
| 80 | __le32 iv[ivlen]; |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 81 | |
Christian Lamparter | cd4dcd6 | 2017-10-04 01:00:11 +0200 | [diff] [blame] | 82 | if (ivlen) |
| 83 | crypto4xx_memcpy_to_le32(iv, req->info, ivlen); |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 84 | |
| 85 | return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst, |
Christian Lamparter | cd4dcd6 | 2017-10-04 01:00:11 +0200 | [diff] [blame] | 86 | req->nbytes, iv, ivlen, ctx->sa_out, ctx->sa_len); |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | int crypto4xx_decrypt(struct ablkcipher_request *req) |
| 90 | { |
| 91 | struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm); |
Christian Lamparter | cd4dcd6 | 2017-10-04 01:00:11 +0200 | [diff] [blame] | 92 | unsigned int ivlen = crypto_ablkcipher_ivsize( |
| 93 | crypto_ablkcipher_reqtfm(req)); |
| 94 | __le32 iv[ivlen]; |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 95 | |
Christian Lamparter | cd4dcd6 | 2017-10-04 01:00:11 +0200 | [diff] [blame] | 96 | if (ivlen) |
| 97 | crypto4xx_memcpy_to_le32(iv, req->info, ivlen); |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 98 | |
| 99 | return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst, |
Christian Lamparter | cd4dcd6 | 2017-10-04 01:00:11 +0200 | [diff] [blame] | 100 | req->nbytes, iv, ivlen, ctx->sa_in, ctx->sa_len); |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /** |
| 104 | * AES Functions |
| 105 | */ |
| 106 | static int crypto4xx_setkey_aes(struct crypto_ablkcipher *cipher, |
| 107 | const u8 *key, |
| 108 | unsigned int keylen, |
| 109 | unsigned char cm, |
| 110 | u8 fb) |
| 111 | { |
| 112 | struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher); |
| 113 | struct crypto4xx_ctx *ctx = crypto_tfm_ctx(tfm); |
| 114 | struct dynamic_sa_ctl *sa; |
| 115 | int rc; |
| 116 | |
| 117 | if (keylen != AES_KEYSIZE_256 && |
| 118 | keylen != AES_KEYSIZE_192 && keylen != AES_KEYSIZE_128) { |
| 119 | crypto_ablkcipher_set_flags(cipher, |
| 120 | CRYPTO_TFM_RES_BAD_KEY_LEN); |
| 121 | return -EINVAL; |
| 122 | } |
| 123 | |
| 124 | /* Create SA */ |
Christian Lamparter | 2f77690 | 2017-10-04 01:00:14 +0200 | [diff] [blame^] | 125 | if (ctx->sa_in || ctx->sa_out) |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 126 | crypto4xx_free_sa(ctx); |
| 127 | |
| 128 | rc = crypto4xx_alloc_sa(ctx, SA_AES128_LEN + (keylen-16) / 4); |
| 129 | if (rc) |
| 130 | return rc; |
| 131 | |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 132 | /* Setup SA */ |
Christian Lamparter | 9e0a0b3 | 2017-08-25 15:47:25 +0200 | [diff] [blame] | 133 | sa = ctx->sa_in; |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 134 | |
| 135 | set_dynamic_sa_command_0(sa, SA_NOT_SAVE_HASH, SA_NOT_SAVE_IV, |
| 136 | SA_LOAD_HASH_FROM_SA, SA_LOAD_IV_FROM_STATE, |
| 137 | SA_NO_HEADER_PROC, SA_HASH_ALG_NULL, |
| 138 | SA_CIPHER_ALG_AES, SA_PAD_TYPE_ZERO, |
| 139 | SA_OP_GROUP_BASIC, SA_OPCODE_DECRYPT, |
| 140 | DIR_INBOUND); |
| 141 | |
| 142 | set_dynamic_sa_command_1(sa, cm, SA_HASH_MODE_HASH, |
| 143 | fb, SA_EXTENDED_SN_OFF, |
| 144 | SA_SEQ_MASK_OFF, SA_MC_ENABLE, |
| 145 | SA_NOT_COPY_PAD, SA_NOT_COPY_PAYLOAD, |
| 146 | SA_NOT_COPY_HDR); |
Christian Lamparter | 4865b122 | 2017-10-04 01:00:10 +0200 | [diff] [blame] | 147 | crypto4xx_memcpy_to_le32(get_dynamic_sa_key_field(sa), |
| 148 | key, keylen); |
Christian Lamparter | 453e309 | 2017-08-25 15:47:19 +0200 | [diff] [blame] | 149 | sa->sa_contents.w = SA_AES_CONTENTS | (keylen << 2); |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 150 | sa->sa_command_1.bf.key_len = keylen >> 3; |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 151 | |
| 152 | memcpy(ctx->sa_out, ctx->sa_in, ctx->sa_len * 4); |
Christian Lamparter | 9e0a0b3 | 2017-08-25 15:47:25 +0200 | [diff] [blame] | 153 | sa = ctx->sa_out; |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 154 | sa->sa_command_0.bf.dir = DIR_OUTBOUND; |
| 155 | |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | int crypto4xx_setkey_aes_cbc(struct crypto_ablkcipher *cipher, |
| 160 | const u8 *key, unsigned int keylen) |
| 161 | { |
| 162 | return crypto4xx_setkey_aes(cipher, key, keylen, CRYPTO_MODE_CBC, |
| 163 | CRYPTO_FEEDBACK_MODE_NO_FB); |
| 164 | } |
| 165 | |
Christian Lamparter | f2a13e7 | 2017-08-25 15:47:21 +0200 | [diff] [blame] | 166 | int crypto4xx_setkey_aes_cfb(struct crypto_ablkcipher *cipher, |
| 167 | const u8 *key, unsigned int keylen) |
| 168 | { |
| 169 | return crypto4xx_setkey_aes(cipher, key, keylen, CRYPTO_MODE_CFB, |
| 170 | CRYPTO_FEEDBACK_MODE_128BIT_CFB); |
| 171 | } |
| 172 | |
| 173 | int crypto4xx_setkey_aes_ecb(struct crypto_ablkcipher *cipher, |
| 174 | const u8 *key, unsigned int keylen) |
| 175 | { |
| 176 | return crypto4xx_setkey_aes(cipher, key, keylen, CRYPTO_MODE_ECB, |
| 177 | CRYPTO_FEEDBACK_MODE_NO_FB); |
| 178 | } |
| 179 | |
| 180 | int crypto4xx_setkey_aes_ofb(struct crypto_ablkcipher *cipher, |
| 181 | const u8 *key, unsigned int keylen) |
| 182 | { |
| 183 | return crypto4xx_setkey_aes(cipher, key, keylen, CRYPTO_MODE_OFB, |
| 184 | CRYPTO_FEEDBACK_MODE_64BIT_OFB); |
| 185 | } |
| 186 | |
| 187 | int crypto4xx_setkey_rfc3686(struct crypto_ablkcipher *cipher, |
| 188 | const u8 *key, unsigned int keylen) |
| 189 | { |
| 190 | struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher); |
| 191 | struct crypto4xx_ctx *ctx = crypto_tfm_ctx(tfm); |
| 192 | int rc; |
| 193 | |
| 194 | rc = crypto4xx_setkey_aes(cipher, key, keylen - CTR_RFC3686_NONCE_SIZE, |
| 195 | CRYPTO_MODE_CTR, CRYPTO_FEEDBACK_MODE_NO_FB); |
| 196 | if (rc) |
| 197 | return rc; |
| 198 | |
Christian Lamparter | 2f77690 | 2017-10-04 01:00:14 +0200 | [diff] [blame^] | 199 | ctx->iv_nonce = cpu_to_le32p((u32 *)&key[keylen - |
| 200 | CTR_RFC3686_NONCE_SIZE]); |
Christian Lamparter | f2a13e7 | 2017-08-25 15:47:21 +0200 | [diff] [blame] | 201 | |
| 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | int crypto4xx_rfc3686_encrypt(struct ablkcipher_request *req) |
| 206 | { |
| 207 | struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm); |
Christian Lamparter | cd4dcd6 | 2017-10-04 01:00:11 +0200 | [diff] [blame] | 208 | __le32 iv[AES_IV_SIZE / 4] = { |
Christian Lamparter | 2f77690 | 2017-10-04 01:00:14 +0200 | [diff] [blame^] | 209 | ctx->iv_nonce, |
Christian Lamparter | cd4dcd6 | 2017-10-04 01:00:11 +0200 | [diff] [blame] | 210 | cpu_to_le32p((u32 *) req->info), |
| 211 | cpu_to_le32p((u32 *) (req->info + 4)), |
| 212 | cpu_to_le32(1) }; |
Christian Lamparter | f2a13e7 | 2017-08-25 15:47:21 +0200 | [diff] [blame] | 213 | |
| 214 | return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst, |
Christian Lamparter | cd4dcd6 | 2017-10-04 01:00:11 +0200 | [diff] [blame] | 215 | req->nbytes, iv, AES_IV_SIZE, |
| 216 | ctx->sa_out, ctx->sa_len); |
Christian Lamparter | f2a13e7 | 2017-08-25 15:47:21 +0200 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | int crypto4xx_rfc3686_decrypt(struct ablkcipher_request *req) |
| 220 | { |
| 221 | struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm); |
Christian Lamparter | cd4dcd6 | 2017-10-04 01:00:11 +0200 | [diff] [blame] | 222 | __le32 iv[AES_IV_SIZE / 4] = { |
Christian Lamparter | 2f77690 | 2017-10-04 01:00:14 +0200 | [diff] [blame^] | 223 | ctx->iv_nonce, |
Christian Lamparter | cd4dcd6 | 2017-10-04 01:00:11 +0200 | [diff] [blame] | 224 | cpu_to_le32p((u32 *) req->info), |
| 225 | cpu_to_le32p((u32 *) (req->info + 4)), |
| 226 | cpu_to_le32(1) }; |
Christian Lamparter | f2a13e7 | 2017-08-25 15:47:21 +0200 | [diff] [blame] | 227 | |
| 228 | return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst, |
Christian Lamparter | cd4dcd6 | 2017-10-04 01:00:11 +0200 | [diff] [blame] | 229 | req->nbytes, iv, AES_IV_SIZE, |
| 230 | ctx->sa_out, ctx->sa_len); |
Christian Lamparter | f2a13e7 | 2017-08-25 15:47:21 +0200 | [diff] [blame] | 231 | } |
| 232 | |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 233 | /** |
| 234 | * HASH SHA1 Functions |
| 235 | */ |
| 236 | static int crypto4xx_hash_alg_init(struct crypto_tfm *tfm, |
| 237 | unsigned int sa_len, |
| 238 | unsigned char ha, |
| 239 | unsigned char hm) |
| 240 | { |
| 241 | struct crypto_alg *alg = tfm->__crt_alg; |
| 242 | struct crypto4xx_alg *my_alg = crypto_alg_to_crypto4xx_alg(alg); |
| 243 | struct crypto4xx_ctx *ctx = crypto_tfm_ctx(tfm); |
Christian Lamparter | 9e0a0b3 | 2017-08-25 15:47:25 +0200 | [diff] [blame] | 244 | struct dynamic_sa_hash160 *sa; |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 245 | int rc; |
| 246 | |
| 247 | ctx->dev = my_alg->dev; |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 248 | |
| 249 | /* Create SA */ |
Christian Lamparter | 2f77690 | 2017-10-04 01:00:14 +0200 | [diff] [blame^] | 250 | if (ctx->sa_in || ctx->sa_out) |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 251 | crypto4xx_free_sa(ctx); |
| 252 | |
| 253 | rc = crypto4xx_alloc_sa(ctx, sa_len); |
| 254 | if (rc) |
| 255 | return rc; |
| 256 | |
Herbert Xu | 6b1679f | 2009-07-12 23:08:28 +0800 | [diff] [blame] | 257 | crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm), |
| 258 | sizeof(struct crypto4xx_ctx)); |
Christian Lamparter | 9e0a0b3 | 2017-08-25 15:47:25 +0200 | [diff] [blame] | 259 | sa = (struct dynamic_sa_hash160 *)ctx->sa_in; |
| 260 | set_dynamic_sa_command_0(&sa->ctrl, SA_SAVE_HASH, SA_NOT_SAVE_IV, |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 261 | SA_NOT_LOAD_HASH, SA_LOAD_IV_FROM_SA, |
| 262 | SA_NO_HEADER_PROC, ha, SA_CIPHER_ALG_NULL, |
| 263 | SA_PAD_TYPE_ZERO, SA_OP_GROUP_BASIC, |
| 264 | SA_OPCODE_HASH, DIR_INBOUND); |
Christian Lamparter | 9e0a0b3 | 2017-08-25 15:47:25 +0200 | [diff] [blame] | 265 | set_dynamic_sa_command_1(&sa->ctrl, 0, SA_HASH_MODE_HASH, |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 266 | CRYPTO_FEEDBACK_MODE_NO_FB, SA_EXTENDED_SN_OFF, |
| 267 | SA_SEQ_MASK_OFF, SA_MC_ENABLE, |
| 268 | SA_NOT_COPY_PAD, SA_NOT_COPY_PAYLOAD, |
| 269 | SA_NOT_COPY_HDR); |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 270 | /* Need to zero hash digest in SA */ |
Christian Lamparter | 9e0a0b3 | 2017-08-25 15:47:25 +0200 | [diff] [blame] | 271 | memset(sa->inner_digest, 0, sizeof(sa->inner_digest)); |
| 272 | memset(sa->outer_digest, 0, sizeof(sa->outer_digest)); |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 273 | |
| 274 | return 0; |
| 275 | } |
| 276 | |
| 277 | int crypto4xx_hash_init(struct ahash_request *req) |
| 278 | { |
| 279 | struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm); |
| 280 | int ds; |
| 281 | struct dynamic_sa_ctl *sa; |
| 282 | |
Christian Lamparter | 9e0a0b3 | 2017-08-25 15:47:25 +0200 | [diff] [blame] | 283 | sa = ctx->sa_in; |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 284 | ds = crypto_ahash_digestsize( |
| 285 | __crypto_ahash_cast(req->base.tfm)); |
| 286 | sa->sa_command_0.bf.digest_len = ds >> 2; |
| 287 | sa->sa_command_0.bf.load_hash_state = SA_LOAD_HASH_FROM_SA; |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 288 | |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | int crypto4xx_hash_update(struct ahash_request *req) |
| 293 | { |
Christian Lamparter | cd4dcd6 | 2017-10-04 01:00:11 +0200 | [diff] [blame] | 294 | struct crypto_ahash *ahash = crypto_ahash_reqtfm(req); |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 295 | struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm); |
Christian Lamparter | cd4dcd6 | 2017-10-04 01:00:11 +0200 | [diff] [blame] | 296 | struct scatterlist dst; |
| 297 | unsigned int ds = crypto_ahash_digestsize(ahash); |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 298 | |
Christian Lamparter | cd4dcd6 | 2017-10-04 01:00:11 +0200 | [diff] [blame] | 299 | sg_init_one(&dst, req->result, ds); |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 300 | |
Christian Lamparter | cd4dcd6 | 2017-10-04 01:00:11 +0200 | [diff] [blame] | 301 | return crypto4xx_build_pd(&req->base, ctx, req->src, &dst, |
| 302 | req->nbytes, NULL, 0, ctx->sa_in, |
| 303 | ctx->sa_len); |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | int crypto4xx_hash_final(struct ahash_request *req) |
| 307 | { |
| 308 | return 0; |
| 309 | } |
| 310 | |
| 311 | int crypto4xx_hash_digest(struct ahash_request *req) |
| 312 | { |
Christian Lamparter | cd4dcd6 | 2017-10-04 01:00:11 +0200 | [diff] [blame] | 313 | struct crypto_ahash *ahash = crypto_ahash_reqtfm(req); |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 314 | struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm); |
Christian Lamparter | cd4dcd6 | 2017-10-04 01:00:11 +0200 | [diff] [blame] | 315 | struct scatterlist dst; |
| 316 | unsigned int ds = crypto_ahash_digestsize(ahash); |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 317 | |
Christian Lamparter | cd4dcd6 | 2017-10-04 01:00:11 +0200 | [diff] [blame] | 318 | sg_init_one(&dst, req->result, ds); |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 319 | |
Christian Lamparter | cd4dcd6 | 2017-10-04 01:00:11 +0200 | [diff] [blame] | 320 | return crypto4xx_build_pd(&req->base, ctx, req->src, &dst, |
| 321 | req->nbytes, NULL, 0, ctx->sa_in, |
| 322 | ctx->sa_len); |
James Hsiao | 049359d | 2009-02-05 16:18:13 +1100 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | /** |
| 326 | * SHA1 Algorithm |
| 327 | */ |
| 328 | int crypto4xx_sha1_alg_init(struct crypto_tfm *tfm) |
| 329 | { |
| 330 | return crypto4xx_hash_alg_init(tfm, SA_HASH160_LEN, SA_HASH_ALG_SHA1, |
| 331 | SA_HASH_MODE_HASH); |
| 332 | } |
| 333 | |
| 334 | |