28 #include <linux/module.h>
29 #include <linux/slab.h>
40 #define CEX3A_MAX_MOD_SIZE 512
42 #define CEX2A_MAX_RESPONSE_SIZE 0x110
44 #define CEX3A_MAX_RESPONSE_SIZE 0x210
50 "Copyright IBM Corp. 2001, 2012");
75 #define TYPE50_TYPE_CODE 0x50
77 #define TYPE50_MEB1_FMT 0x0001
78 #define TYPE50_MEB2_FMT 0x0002
79 #define TYPE50_MEB3_FMT 0x0003
80 #define TYPE50_CRB1_FMT 0x0011
81 #define TYPE50_CRB2_FMT 0x0012
82 #define TYPE50_CRB3_FMT 0x0013
121 unsigned char dp[64];
122 unsigned char dq[64];
132 unsigned char p[128];
133 unsigned char q[128];
134 unsigned char dp[128];
135 unsigned char dq[128];
136 unsigned char u[128];
145 unsigned char p[256];
146 unsigned char q[256];
147 unsigned char dp[256];
148 unsigned char dq[256];
149 unsigned char u[256];
162 #define TYPE80_RSP_CODE 0x80
182 static int ICAMEX_msg_to_type50MEX_msg(
struct zcrypt_device *zdev,
191 if (mod_len <= 128) {
193 memset(meb1, 0,
sizeof(*meb1));
194 ap_msg->
length =
sizeof(*meb1);
196 meb1->
header.msg_len =
sizeof(*meb1);
201 }
else if (mod_len <= 256) {
203 memset(meb2, 0,
sizeof(*meb2));
204 ap_msg->
length =
sizeof(*meb2);
206 meb2->
header.msg_len =
sizeof(*meb2);
214 memset(meb3, 0,
sizeof(*meb3));
215 ap_msg->
length =
sizeof(*meb3);
217 meb3->
header.msg_len =
sizeof(*meb3);
240 static int ICACRT_msg_to_type50CRT_msg(
struct zcrypt_device *zdev,
248 short_len = mod_len / 2;
249 long_len = mod_len / 2 + 8;
261 if (long_len > limit) {
266 long_offset = long_len -
limit;
275 if (long_len <= 64) {
277 memset(crb1, 0,
sizeof(*crb1));
278 ap_msg->
length =
sizeof(*crb1);
280 crb1->
header.msg_len =
sizeof(*crb1);
282 p = crb1->
p +
sizeof(crb1->
p) - long_len;
283 q = crb1->
q +
sizeof(crb1->
q) - short_len;
284 dp = crb1->
dp +
sizeof(crb1->
dp) - long_len;
285 dq = crb1->
dq +
sizeof(crb1->
dq) - short_len;
286 u = crb1->
u +
sizeof(crb1->
u) - long_len;
288 }
else if (long_len <= 128) {
290 memset(crb2, 0,
sizeof(*crb2));
291 ap_msg->
length =
sizeof(*crb2);
293 crb2->
header.msg_len =
sizeof(*crb2);
295 p = crb2->
p +
sizeof(crb2->
p) - long_len;
296 q = crb2->
q +
sizeof(crb2->
q) - short_len;
297 dp = crb2->
dp +
sizeof(crb2->
dp) - long_len;
298 dq = crb2->
dq +
sizeof(crb2->
dq) - short_len;
299 u = crb2->
u +
sizeof(crb2->
u) - long_len;
304 memset(crb3, 0,
sizeof(*crb3));
305 ap_msg->
length =
sizeof(*crb3);
307 crb3->
header.msg_len =
sizeof(*crb3);
309 p = crb3->
p +
sizeof(crb3->
p) - long_len;
310 q = crb3->
q +
sizeof(crb3->
q) - short_len;
311 dp = crb3->
dp +
sizeof(crb3->
dp) - long_len;
312 dq = crb3->
dq +
sizeof(crb3->
dq) - short_len;
313 u = crb3->
u +
sizeof(crb3->
u) - long_len;
340 char __user *outputdata,
341 unsigned int outputdatalength)
346 if (t80h->
len <
sizeof(*t80h) + outputdatalength) {
355 data = reply->
message + t80h->
len - outputdatalength;
363 char __user *outputdata,
364 unsigned int outputdatalength)
367 switch (((
unsigned char *) reply->
message)[1]) {
370 return convert_error(zdev, reply);
372 return convert_type80(zdev, reply,
373 outputdata, outputdatalength);
388 static void zcrypt_cex2a_receive(
struct ap_device *ap_dev,
435 ap_init_message(&ap_msg);
444 ap_msg.
receive = zcrypt_cex2a_receive;
448 rc = ICAMEX_msg_to_type50MEX_msg(zdev, &ap_msg, mex);
451 init_completion(&
work);
455 rc = convert_response(zdev, &ap_msg, mex->
outputdata,
472 static long zcrypt_cex2a_modexpo_crt(
struct zcrypt_device *zdev,
479 ap_init_message(&ap_msg);
488 ap_msg.
receive = zcrypt_cex2a_receive;
492 rc = ICACRT_msg_to_type50CRT_msg(zdev, &ap_msg, crt);
495 init_completion(&
work);
499 rc = convert_response(zdev, &ap_msg, crt->
outputdata,
512 static struct zcrypt_ops zcrypt_msgtype50_ops = {
513 .rsa_modexpo = zcrypt_cex2a_modexpo,
514 .rsa_modexpo_crt = zcrypt_cex2a_modexpo_crt,