aboutsummaryrefslogtreecommitdiff
path: root/drivers/crypto/amcc/crypto4xx_sa.c
blob: fa4ff7ac66a2ceae5d6cf6a318bc503318886a96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/**
 * AMCC SoC PPC4xx Crypto Driver
 *
 * Copyright (c) 2008 Applied Micro Circuits Corporation.
 * All rights reserved. James Hsiao <jhsiao@amcc.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * @file crypto4xx_sa.c
 *
 * This file implements the security context
 * assoicate format.
 */
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/mod_devicetable.h>
#include <linux/interrupt.h>
#include <linux/spinlock_types.h>
#include <linux/highmem.h>
#include <linux/scatterlist.h>
#include <linux/crypto.h>
#include <crypto/algapi.h>
#include <crypto/des.h>
#include "crypto4xx_reg_def.h"
#include "crypto4xx_sa.h"
#include "crypto4xx_core.h"

u32 get_dynamic_sa_offset_iv_field(struct crypto4xx_ctx *ctx)
{
	u32 offset;
	union dynamic_sa_contents cts;

	if (ctx->direction == DIR_INBOUND)
		cts.w = ((struct dynamic_sa_ctl *)(ctx->sa_in))->sa_contents;
	else
		cts.w = ((struct dynamic_sa_ctl *)(ctx->sa_out))->sa_contents;
	offset = cts.bf.key_size
		+ cts.bf.inner_size
		+ cts.bf.outer_size
		+ cts.bf.spi
		+ cts.bf.seq_num0
		+ cts.bf.seq_num1
		+ cts.bf.seq_num_mask0
		+ cts.bf.seq_num_mask1
		+ cts.bf.seq_num_mask2
		+ cts.bf.seq_num_mask3;

	return sizeof(struct dynamic_sa_ctl) + offset * 4;
}

u32 get_dynamic_sa_offset_state_ptr_field(struct crypto4xx_ctx *ctx)
{
	u32 offset;
	union dynamic_sa_contents cts;

	if (ctx->direction == DIR_INBOUND)
		cts.w = ((struct dynamic_sa_ctl *) ctx->sa_in)->sa_contents;
	else
		cts.w = ((struct dynamic_sa_ctl *) ctx->sa_out)->sa_contents;
	offset = cts.bf.key_size
		+ cts.bf.inner_size
		+ cts.bf.outer_size
		+ cts.bf.spi
		+ cts.bf.seq_num0
		+ cts.bf.seq_num1
		+ cts.bf.seq_num_mask0
		+ cts.bf.seq_num_mask1
		+ cts.bf.seq_num_mask2
		+ cts.bf.seq_num_mask3
		+ cts.bf.iv0
		+ cts.bf.iv1
		+ cts.bf.iv2
		+ cts.bf.iv3;

	return sizeof(struct dynamic_sa_ctl) + offset * 4;
}

u32 get_dynamic_sa_offset_arc4_state_ptr(struct crypto4xx_ctx *ctx)
{
	u32 offset;
	union dynamic_sa_contents cts;

	if (ctx->direction == DIR_INBOUND)
		cts.w = ((struct dynamic_sa_ctl *)(ctx->sa_in))->sa_contents;
	else
		cts.w = ((struct dynamic_sa_ctl *)(ctx->sa_out))->sa_contents;
	offset = cts.bf.key_size
		+ cts.bf.inner_size
		+ cts.bf.outer_size
		+ cts.bf.spi
		+ cts.bf.seq_num0
		+ cts.bf.seq_num1
		+ cts.bf.seq_num_mask0
		+ cts.bf.seq_num_mask1
		+ cts.bf.seq_num_mask2
		+ cts.bf.seq_num_mask3
		+ cts.bf.iv0
		+ cts.bf.iv1
		+ cts.bf.iv2
		+ cts.bf.iv3
		+ cts.bf.state_ptr
		+ cts.bf.arc4_ij_ptr;

	return sizeof(struct dynamic_sa_ctl) + offset * 4;
}

u32 get_dynamic_sa_offset_inner_digest(struct crypto4xx_ctx *ctx)
{
	u32 offset;
	union dynamic_sa_contents cts;

	if (ctx->direction == DIR_INBOUND)
		cts.w = ((struct dynamic_sa_ctl *)(ctx->sa_in))->sa_contents;
	else
		cts.w = ((struct dynamic_sa_ctl *)(ctx->sa_out))->sa_contents;
	offset = cts.bf.key_size;

	return sizeof(struct dynamic_sa_ctl) + offset * 4;
}

u32 get_dynamic_sa_offset_outer_digest(struct crypto4xx_ctx *ctx)
{
	u32 offset;
	union dynamic_sa_contents cts;

	if (ctx->direction == DIR_INBOUND)
		cts.w = ((struct dynamic_sa_ctl *)(ctx->sa_in))->sa_contents;
	else
		cts.w = ((struct dynamic_sa_ctl *)(ctx->sa_out))->sa_contents;

	offset = cts.bf.key_size
		+ cts.bf.inner_size;

	return sizeof(struct dynamic_sa_ctl) + offset * 4;
}

u32 get_dynamic_sa_offset_spi(struct crypto4xx_ctx *ctx)
{
	u32 offset;
	union dynamic_sa_contents cts;

	if (ctx->direction == DIR_INBOUND)
		cts.w = ((struct dynamic_sa_ctl *)(ctx->sa_in))->sa_contents;
	else
		cts.w = ((struct dynamic_sa_ctl *)(ctx->sa_out))->sa_contents;

	offset = cts.bf.key_size
		+ cts.bf.inner_size
		+ cts.bf.outer_size;

	return sizeof(struct dynamic_sa_ctl) + offset * 4;
}

u32 get_dynamic_sa_offset_seq_num(struct crypto4xx_ctx *ctx)
{
	u32 offset;
	union dynamic_sa_contents cts;

	if (ctx->direction == DIR_INBOUND)
		cts.w = ((struct dynamic_sa_ctl *)(ctx->sa_in))->sa_contents;
	else
		cts.w = ((struct dynamic_sa_ctl *)(ctx->sa_out))->sa_contents;

	offset = cts.bf.key_size
		+ cts.bf.inner_size
		+ cts.bf.outer_size
		+ cts.bf.spi;
	return sizeof(struct dynamic_sa_ctl) + offset * 4;
}

u32 get_dynamic_sa_offset_seq_num_mask(struct crypto4xx_ctx *ctx)
{
	u32 offset;
	union dynamic_sa_contents cts;

	if (ctx->direction == DIR_INBOUND)
		cts.w = ((struct dynamic_sa_ctl *)(ctx->sa_in))->sa_contents;
	else
		cts.w = ((struct dynamic_sa_ctl *)(ctx->sa_out))->sa_contents;

	offset = cts.bf.key_size
		+ cts.bf.inner_size
		+ cts.bf.outer_size
		+ cts.bf.spi
		+ cts.bf.seq_num0
		+ cts.bf.seq_num1;

	return sizeof(struct dynamic_sa_ctl) + offset * 4;
}

u32 get_dynamic_sa_iv_size(struct crypto4xx_ctx *ctx)
{
	union dynamic_sa_contents cts;

	if (ctx->direction == DIR_INBOUND)
		cts.w = ((struct dynamic_sa_ctl *) ctx->sa_in)->sa_contents;
	else
		cts.w = ((struct dynamic_sa_ctl *) ctx->sa_out)->sa_contents;

	return (cts.bf.iv0 + cts.bf.iv1 + cts.bf.iv2 + cts.bf.iv3) * 4;
}

u32 get_dynamic_sa_offset_key_field(struct crypto4xx_ctx *ctx)
{
	union dynamic_sa_contents cts;

	if (ctx->direction == DIR_INBOUND)
		cts.w = ((struct dynamic_sa_ctl *) ctx->sa_in)->sa_contents;
	else
		cts.w = ((struct dynamic_sa_ctl *) ctx->sa_out)->sa_contents;

	return sizeof(struct dynamic_sa_ctl);
}