aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/crypto/amcc/crypto4xx_alg.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/crypto/amcc/crypto4xx_alg.c')
-rw-r--r--drivers/crypto/amcc/crypto4xx_alg.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/drivers/crypto/amcc/crypto4xx_alg.c b/drivers/crypto/amcc/crypto4xx_alg.c
index 599b6326c3fb..c9597824a515 100644
--- a/drivers/crypto/amcc/crypto4xx_alg.c
+++ b/drivers/crypto/amcc/crypto4xx_alg.c
@@ -28,6 +28,7 @@
28#include <crypto/algapi.h> 28#include <crypto/algapi.h>
29#include <crypto/aes.h> 29#include <crypto/aes.h>
30#include <crypto/sha.h> 30#include <crypto/sha.h>
31#include <crypto/ctr.h>
31#include "crypto4xx_reg_def.h" 32#include "crypto4xx_reg_def.h"
32#include "crypto4xx_core.h" 33#include "crypto4xx_core.h"
33#include "crypto4xx_sa.h" 34#include "crypto4xx_sa.h"
@@ -171,6 +172,71 @@ int crypto4xx_setkey_aes_cbc(struct crypto_ablkcipher *cipher,
171 CRYPTO_FEEDBACK_MODE_NO_FB); 172 CRYPTO_FEEDBACK_MODE_NO_FB);
172} 173}
173 174
175int crypto4xx_setkey_aes_cfb(struct crypto_ablkcipher *cipher,
176 const u8 *key, unsigned int keylen)
177{
178 return crypto4xx_setkey_aes(cipher, key, keylen, CRYPTO_MODE_CFB,
179 CRYPTO_FEEDBACK_MODE_128BIT_CFB);
180}
181
182int crypto4xx_setkey_aes_ecb(struct crypto_ablkcipher *cipher,
183 const u8 *key, unsigned int keylen)
184{
185 return crypto4xx_setkey_aes(cipher, key, keylen, CRYPTO_MODE_ECB,
186 CRYPTO_FEEDBACK_MODE_NO_FB);
187}
188
189int crypto4xx_setkey_aes_ofb(struct crypto_ablkcipher *cipher,
190 const u8 *key, unsigned int keylen)
191{
192 return crypto4xx_setkey_aes(cipher, key, keylen, CRYPTO_MODE_OFB,
193 CRYPTO_FEEDBACK_MODE_64BIT_OFB);
194}
195
196int crypto4xx_setkey_rfc3686(struct crypto_ablkcipher *cipher,
197 const u8 *key, unsigned int keylen)
198{
199 struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher);
200 struct crypto4xx_ctx *ctx = crypto_tfm_ctx(tfm);
201 int rc;
202
203 rc = crypto4xx_setkey_aes(cipher, key, keylen - CTR_RFC3686_NONCE_SIZE,
204 CRYPTO_MODE_CTR, CRYPTO_FEEDBACK_MODE_NO_FB);
205 if (rc)
206 return rc;
207
208 memcpy(ctx->state_record,
209 key + keylen - CTR_RFC3686_NONCE_SIZE, CTR_RFC3686_NONCE_SIZE);
210
211 return 0;
212}
213
214int crypto4xx_rfc3686_encrypt(struct ablkcipher_request *req)
215{
216 struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
217 __be32 iv[AES_IV_SIZE / 4] = { *(u32 *)ctx->state_record,
218 *(u32 *) req->info, *(u32 *) (req->info + 4), cpu_to_be32(1) };
219
220 ctx->direction = DIR_OUTBOUND;
221 ctx->pd_ctl = 1;
222
223 return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst,
224 req->nbytes, iv, AES_IV_SIZE);
225}
226
227int crypto4xx_rfc3686_decrypt(struct ablkcipher_request *req)
228{
229 struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
230 __be32 iv[AES_IV_SIZE / 4] = { *(u32 *)ctx->state_record,
231 *(u32 *) req->info, *(u32 *) (req->info + 4), cpu_to_be32(1) };
232
233 ctx->direction = DIR_INBOUND;
234 ctx->pd_ctl = 1;
235
236 return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst,
237 req->nbytes, iv, AES_IV_SIZE);
238}
239
174/** 240/**
175 * HASH SHA1 Functions 241 * HASH SHA1 Functions
176 */ 242 */