blob: 69182e2cc3ea8a916f7e24fcf17365c32e242c20 [file] [log] [blame]
James Hsiao049359d2009-02-05 16:18:13 +11001/**
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 * @file crypto4xx_sa.c
18 *
19 * This file implements the security context
Lucas De Marchi25985ed2011-03-30 22:57:33 -030020 * associate format.
James Hsiao049359d2009-02-05 16:18:13 +110021 */
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/moduleparam.h>
25#include <linux/mod_devicetable.h>
26#include <linux/interrupt.h>
27#include <linux/spinlock_types.h>
28#include <linux/highmem.h>
29#include <linux/scatterlist.h>
30#include <linux/crypto.h>
31#include <crypto/algapi.h>
32#include <crypto/des.h>
33#include "crypto4xx_reg_def.h"
34#include "crypto4xx_sa.h"
35#include "crypto4xx_core.h"
36
James Hsiao049359d2009-02-05 16:18:13 +110037u32 get_dynamic_sa_offset_state_ptr_field(struct crypto4xx_ctx *ctx)
38{
39 u32 offset;
40 union dynamic_sa_contents cts;
41
42 if (ctx->direction == DIR_INBOUND)
43 cts.w = ((struct dynamic_sa_ctl *) ctx->sa_in)->sa_contents;
44 else
45 cts.w = ((struct dynamic_sa_ctl *) ctx->sa_out)->sa_contents;
46 offset = cts.bf.key_size
47 + cts.bf.inner_size
48 + cts.bf.outer_size
49 + cts.bf.spi
50 + cts.bf.seq_num0
51 + cts.bf.seq_num1
52 + cts.bf.seq_num_mask0
53 + cts.bf.seq_num_mask1
54 + cts.bf.seq_num_mask2
55 + cts.bf.seq_num_mask3
56 + cts.bf.iv0
57 + cts.bf.iv1
58 + cts.bf.iv2
59 + cts.bf.iv3;
60
61 return sizeof(struct dynamic_sa_ctl) + offset * 4;
62}
63
64u32 get_dynamic_sa_iv_size(struct crypto4xx_ctx *ctx)
65{
66 union dynamic_sa_contents cts;
67
68 if (ctx->direction == DIR_INBOUND)
69 cts.w = ((struct dynamic_sa_ctl *) ctx->sa_in)->sa_contents;
70 else
71 cts.w = ((struct dynamic_sa_ctl *) ctx->sa_out)->sa_contents;
72 return (cts.bf.iv0 + cts.bf.iv1 + cts.bf.iv2 + cts.bf.iv3) * 4;
73}
74
75u32 get_dynamic_sa_offset_key_field(struct crypto4xx_ctx *ctx)
76{
77 union dynamic_sa_contents cts;
78
79 if (ctx->direction == DIR_INBOUND)
80 cts.w = ((struct dynamic_sa_ctl *) ctx->sa_in)->sa_contents;
81 else
82 cts.w = ((struct dynamic_sa_ctl *) ctx->sa_out)->sa_contents;
83
84 return sizeof(struct dynamic_sa_ctl);
85}