2 * linux/drivers/s390/crypto/z90hardware.c
6 * Copyright (C) 2001, 2005 IBM Corporation
7 * Author(s): Robert Burroughs (burrough@us.ibm.com)
8 * Eric Rossman (edrossma@us.ibm.com)
10 * Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <asm/uaccess.h>
28 #include <linux/compiler.h>
29 #include <linux/delay.h>
30 #include <linux/init.h>
31 #include <linux/module.h>
33 #include "z90common.h"
35 struct cca_token_hdr
{
36 unsigned char token_identifier
;
37 unsigned char version
;
38 unsigned short token_length
;
39 unsigned char reserved
[4];
42 #define CCA_TKN_HDR_ID_EXT 0x1E
44 struct cca_private_ext_ME_sec
{
45 unsigned char section_identifier
;
46 unsigned char version
;
47 unsigned short section_length
;
48 unsigned char private_key_hash
[20];
49 unsigned char reserved1
[4];
50 unsigned char key_format
;
51 unsigned char reserved2
;
52 unsigned char key_name_hash
[20];
53 unsigned char key_use_flags
[4];
54 unsigned char reserved3
[6];
55 unsigned char reserved4
[24];
56 unsigned char confounder
[24];
57 unsigned char exponent
[128];
58 unsigned char modulus
[128];
61 #define CCA_PVT_USAGE_ALL 0x80
63 struct cca_public_sec
{
64 unsigned char section_identifier
;
65 unsigned char version
;
66 unsigned short section_length
;
67 unsigned char reserved
[2];
68 unsigned short exponent_len
;
69 unsigned short modulus_bit_len
;
70 unsigned short modulus_byte_len
;
71 unsigned char exponent
[3];
74 struct cca_private_ext_ME
{
75 struct cca_token_hdr pvtMEHdr
;
76 struct cca_private_ext_ME_sec pvtMESec
;
77 struct cca_public_sec pubMESec
;
80 struct cca_public_key
{
81 struct cca_token_hdr pubHdr
;
82 struct cca_public_sec pubSec
;
85 struct cca_pvt_ext_CRT_sec
{
86 unsigned char section_identifier
;
87 unsigned char version
;
88 unsigned short section_length
;
89 unsigned char private_key_hash
[20];
90 unsigned char reserved1
[4];
91 unsigned char key_format
;
92 unsigned char reserved2
;
93 unsigned char key_name_hash
[20];
94 unsigned char key_use_flags
[4];
97 unsigned short dp_len
;
98 unsigned short dq_len
;
100 unsigned short mod_len
;
101 unsigned char reserved3
[4];
102 unsigned short pad_len
;
103 unsigned char reserved4
[52];
104 unsigned char confounder
[8];
107 #define CCA_PVT_EXT_CRT_SEC_ID_PVT 0x08
108 #define CCA_PVT_EXT_CRT_SEC_FMT_CL 0x40
110 struct cca_private_ext_CRT
{
111 struct cca_token_hdr pvtCrtHdr
;
112 struct cca_pvt_ext_CRT_sec pvtCrtSec
;
113 struct cca_public_sec pubCrtSec
;
116 struct ap_status_word
{
117 unsigned char q_stat_flags
;
118 unsigned char response_code
;
119 unsigned char reserved
[2];
122 #define AP_Q_STATUS_EMPTY 0x80
123 #define AP_Q_STATUS_REPLIES_WAITING 0x40
124 #define AP_Q_STATUS_ARRAY_FULL 0x20
126 #define AP_RESPONSE_NORMAL 0x00
127 #define AP_RESPONSE_Q_NOT_AVAIL 0x01
128 #define AP_RESPONSE_RESET_IN_PROGRESS 0x02
129 #define AP_RESPONSE_DECONFIGURED 0x03
130 #define AP_RESPONSE_CHECKSTOPPED 0x04
131 #define AP_RESPONSE_BUSY 0x05
132 #define AP_RESPONSE_Q_FULL 0x10
133 #define AP_RESPONSE_NO_PENDING_REPLY 0x10
134 #define AP_RESPONSE_INDEX_TOO_BIG 0x11
135 #define AP_RESPONSE_NO_FIRST_PART 0x13
136 #define AP_RESPONSE_MESSAGE_TOO_BIG 0x15
138 #define AP_MAX_CDX_BITL 4
139 #define AP_RQID_RESERVED_BITL 4
140 #define SKIP_BITL (AP_MAX_CDX_BITL + AP_RQID_RESERVED_BITL)
143 unsigned char reserved1
;
144 unsigned char msg_type_code
;
145 unsigned short msg_len
;
146 unsigned char request_code
;
147 unsigned char msg_fmt
;
148 unsigned short reserved2
;
151 #define TYPE4_TYPE_CODE 0x04
152 #define TYPE4_REQU_CODE 0x40
154 #define TYPE4_SME_LEN 0x0188
155 #define TYPE4_LME_LEN 0x0308
156 #define TYPE4_SCR_LEN 0x01E0
157 #define TYPE4_LCR_LEN 0x03A0
159 #define TYPE4_SME_FMT 0x00
160 #define TYPE4_LME_FMT 0x10
161 #define TYPE4_SCR_FMT 0x40
162 #define TYPE4_LCR_FMT 0x50
165 struct type4_hdr header
;
166 unsigned char message
[128];
167 unsigned char exponent
[128];
168 unsigned char modulus
[128];
172 struct type4_hdr header
;
173 unsigned char message
[256];
174 unsigned char exponent
[256];
175 unsigned char modulus
[256];
179 struct type4_hdr header
;
180 unsigned char message
[128];
181 unsigned char dp
[72];
182 unsigned char dq
[64];
189 struct type4_hdr header
;
190 unsigned char message
[256];
191 unsigned char dp
[136];
192 unsigned char dq
[128];
193 unsigned char p
[136];
194 unsigned char q
[128];
195 unsigned char u
[136];
199 struct type4_sme sme
;
200 struct type4_lme lme
;
201 struct type4_scr scr
;
202 struct type4_lcr lcr
;
206 unsigned char reserved1
;
209 unsigned char reserved2
[4];
212 #define TYPE84_RSP_CODE 0x84
215 unsigned char reserved1
;
217 unsigned char reserved2
[2];
218 unsigned char right
[4];
219 unsigned char reserved3
[2];
220 unsigned char reserved4
[2];
221 unsigned char apfs
[4];
222 unsigned int offset1
;
223 unsigned int offset2
;
224 unsigned int offset3
;
225 unsigned int offset4
;
226 unsigned char agent_id
[16];
227 unsigned char rqid
[2];
228 unsigned char reserved5
[2];
229 unsigned char function_code
[2];
230 unsigned char reserved6
[2];
231 unsigned int ToCardLen1
;
232 unsigned int ToCardLen2
;
233 unsigned int ToCardLen3
;
234 unsigned int ToCardLen4
;
235 unsigned int FromCardLen1
;
236 unsigned int FromCardLen2
;
237 unsigned int FromCardLen3
;
238 unsigned int FromCardLen4
;
242 unsigned char cprb_len
[2];
243 unsigned char cprb_ver_id
;
244 unsigned char pad_000
;
245 unsigned char srpi_rtcode
[4];
246 unsigned char srpi_verb
;
248 unsigned char func_id
[2];
249 unsigned char checkpoint_flag
;
251 unsigned char req_parml
[2];
252 unsigned char req_parmp
[4];
253 unsigned char req_datal
[4];
254 unsigned char req_datap
[4];
255 unsigned char rpl_parml
[2];
256 unsigned char pad_001
[2];
257 unsigned char rpl_parmp
[4];
258 unsigned char rpl_datal
[4];
259 unsigned char rpl_datap
[4];
260 unsigned char ccp_rscode
[2];
261 unsigned char ccp_rtcode
[2];
262 unsigned char repd_parml
[2];
263 unsigned char mac_data_len
[2];
264 unsigned char repd_datal
[4];
265 unsigned char req_pc
[2];
266 unsigned char res_origin
[8];
267 unsigned char mac_value
[8];
268 unsigned char logon_id
[8];
269 unsigned char usage_domain
[2];
270 unsigned char resv3
[18];
271 unsigned char svr_namel
[2];
272 unsigned char svr_name
[8];
276 struct type6_hdr header
;
281 unsigned char reserved1
;
283 unsigned char format
;
284 unsigned char reserved2
;
285 unsigned char reply_code
;
286 unsigned char reserved3
[3];
289 #define TYPE86_RSP_CODE 0x86
290 #define TYPE86_FMT2 0x02
292 struct type86_fmt2_msg
{
293 struct type86_hdr header
;
294 unsigned char reserved
[4];
295 unsigned char apfs
[4];
297 unsigned int offset1
;
299 unsigned int offset2
;
301 unsigned int offset3
;
303 unsigned int offset4
;
306 static struct type6_hdr static_type6_hdr
= {
310 {0x00,0x00,0x00,0x00},
313 {0x00,0x00,0x00,0x00},
318 {0x01,0x00,0x43,0x43,0x41,0x2D,0x41,0x50,
319 0x50,0x4C,0x20,0x20,0x20,0x01,0x01,0x01},
334 static struct type6_hdr static_type6_hdrX
= {
338 {0x00,0x00,0x00,0x00},
341 {0x00,0x00,0x00,0x00},
346 {0x43,0x41,0x00,0x00,0x00,0x00,0x00,0x00,
347 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
362 static struct CPRB static_cprb
= {
366 {0x00,0x00,0x00,0x00},
373 {0x00,0x00,0x00,0x00},
374 {0x00,0x00,0x00,0x00},
375 {0x00,0x00,0x00,0x00},
378 {0x00,0x00,0x00,0x00},
379 {0x00,0x00,0x00,0x00},
380 {0x00,0x00,0x00,0x00},
385 {0x00,0x00,0x00,0x00},
387 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
388 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
389 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
391 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
392 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
395 {0x49,0x43,0x53,0x46,0x20,0x20,0x20,0x20}
398 struct function_and_rules_block
{
399 unsigned char function_code
[2];
400 unsigned char ulen
[2];
401 unsigned char only_rule
[8];
404 static struct function_and_rules_block static_pkd_function_and_rules
= {
407 {'P','K','C','S','-','1','.','2'}
410 static struct function_and_rules_block static_pke_function_and_rules
= {
413 {'P','K','C','S','-','1','.','2'}
416 struct T6_keyBlock_hdr
{
417 unsigned char blen
[2];
418 unsigned char ulen
[2];
419 unsigned char flags
[2];
422 static struct T6_keyBlock_hdr static_T6_keyBlock_hdr
= {
428 static struct CPRBX static_cprbx
= {
433 {0x00,0x00,0x00,0x00},
441 {0x00,0x00,0x00,0x00},
443 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
444 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
445 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
446 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
447 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
448 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
449 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
450 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
451 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
452 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
453 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
454 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
458 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
459 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
463 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
464 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
465 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
466 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}
469 static struct function_and_rules_block static_pkd_function_and_rulesX_MCL2
= {
472 {'P','K','C','S','-','1','.','2'}
475 static struct function_and_rules_block static_pke_function_and_rulesX_MCL2
= {
478 {'Z','E','R','O','-','P','A','D'}
481 static struct function_and_rules_block static_pkd_function_and_rulesX
= {
484 {'Z','E','R','O','-','P','A','D'}
487 static struct function_and_rules_block static_pke_function_and_rulesX
= {
490 {'M','R','P',' ',' ',' ',' ',' '}
493 static unsigned char static_PKE_function_code
[2] = {0x50, 0x4B};
495 struct T6_keyBlock_hdrX
{
498 unsigned char flags
[2];
501 static unsigned char static_pad
[256] = {
502 0x1B,0x7B,0x5D,0xB5,0x75,0x01,0x3D,0xFD,0x8D,0xD1,0xC7,0x03,0x2D,0x09,0x23,0x57,
503 0x89,0x49,0xB9,0x3F,0xBB,0x99,0x41,0x5B,0x75,0x21,0x7B,0x9D,0x3B,0x6B,0x51,0x39,
504 0xBB,0x0D,0x35,0xB9,0x89,0x0F,0x93,0xA5,0x0B,0x47,0xF1,0xD3,0xBB,0xCB,0xF1,0x9D,
505 0x23,0x73,0x71,0xFF,0xF3,0xF5,0x45,0xFB,0x61,0x29,0x23,0xFD,0xF1,0x29,0x3F,0x7F,
506 0x17,0xB7,0x1B,0xA9,0x19,0xBD,0x57,0xA9,0xD7,0x95,0xA3,0xCB,0xED,0x1D,0xDB,0x45,
507 0x7D,0x11,0xD1,0x51,0x1B,0xED,0x71,0xE9,0xB1,0xD1,0xAB,0xAB,0x21,0x2B,0x1B,0x9F,
508 0x3B,0x9F,0xF7,0xF7,0xBD,0x63,0xEB,0xAD,0xDF,0xB3,0x6F,0x5B,0xDB,0x8D,0xA9,0x5D,
509 0xE3,0x7D,0x77,0x49,0x47,0xF5,0xA7,0xFD,0xAB,0x2F,0x27,0x35,0x77,0xD3,0x49,0xC9,
510 0x09,0xEB,0xB1,0xF9,0xBF,0x4B,0xCB,0x2B,0xEB,0xEB,0x05,0xFF,0x7D,0xC7,0x91,0x8B,
511 0x09,0x83,0xB9,0xB9,0x69,0x33,0x39,0x6B,0x79,0x75,0x19,0xBF,0xBB,0x07,0x1D,0xBD,
512 0x29,0xBF,0x39,0x95,0x93,0x1D,0x35,0xC7,0xC9,0x4D,0xE5,0x97,0x0B,0x43,0x9B,0xF1,
513 0x16,0x93,0x03,0x1F,0xA5,0xFB,0xDB,0xF3,0x27,0x4F,0x27,0x61,0x05,0x1F,0xB9,0x23,
514 0x2F,0xC3,0x81,0xA9,0x23,0x71,0x55,0x55,0xEB,0xED,0x41,0xE5,0xF3,0x11,0xF1,0x43,
515 0x69,0x03,0xBD,0x0B,0x37,0x0F,0x51,0x8F,0x0B,0xB5,0x89,0x5B,0x67,0xA9,0xD9,0x4F,
516 0x01,0xF9,0x21,0x77,0x37,0x73,0x79,0xC5,0x7F,0x51,0xC1,0xCF,0x97,0xA1,0x75,0xAD,
517 0x35,0x9D,0xD3,0xD3,0xA7,0x9D,0x5D,0x41,0x6F,0x65,0x1B,0xCF,0xA9,0x87,0x91,0x09
520 static struct cca_private_ext_ME static_pvt_me_key
= {
525 {0x00,0x00,0x00,0x00}
532 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
533 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
534 0x00,0x00,0x00,0x00},
535 {0x00,0x00,0x00,0x00},
538 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
539 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
540 0x00,0x00,0x00,0x00},
541 {0x80,0x00,0x00,0x00},
542 {0x00,0x00,0x00,0x00,0x00,0x00},
543 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
544 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
545 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
546 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
547 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
548 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
549 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
550 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
551 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
552 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
553 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
554 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
555 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
556 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
557 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
558 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
559 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
560 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
561 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
562 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
563 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
564 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
565 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
566 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
567 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
568 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
569 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
570 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
571 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
572 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
573 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
574 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
575 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
576 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
577 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
578 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
579 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
580 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}
595 static struct cca_public_key static_public_key
= {
600 {0x00,0x00,0x00,0x00}
615 #define FIXED_TYPE6_ME_LEN 0x0000025F
617 #define FIXED_TYPE6_ME_EN_LEN 0x000000F0
619 #define FIXED_TYPE6_ME_LENX 0x000002CB
621 #define FIXED_TYPE6_ME_EN_LENX 0x0000015C
623 static struct cca_public_sec static_cca_pub_sec
= {
634 #define FIXED_TYPE6_CR_LEN 0x00000177
636 #define FIXED_TYPE6_CR_LENX 0x000001E3
638 #define MAX_RESPONSE_SIZE 0x00000710
640 #define MAX_RESPONSEX_SIZE 0x0000077C
642 #define RESPONSE_CPRB_SIZE 0x000006B8
643 #define RESPONSE_CPRBX_SIZE 0x00000724
654 #define TYPE50_TYPE_CODE 0x50
656 #define TYPE50_MEB1_LEN (sizeof(struct type50_meb1_msg))
657 #define TYPE50_MEB2_LEN (sizeof(struct type50_meb2_msg))
658 #define TYPE50_CRB1_LEN (sizeof(struct type50_crb1_msg))
659 #define TYPE50_CRB2_LEN (sizeof(struct type50_crb2_msg))
661 #define TYPE50_MEB1_FMT 0x0001
662 #define TYPE50_MEB2_FMT 0x0002
663 #define TYPE50_CRB1_FMT 0x0011
664 #define TYPE50_CRB2_FMT 0x0012
666 struct type50_meb1_msg
{
667 struct type50_hdr header
;
675 struct type50_meb2_msg
{
676 struct type50_hdr header
;
684 struct type50_crb1_msg
{
685 struct type50_hdr header
;
696 struct type50_crb2_msg
{
697 struct type50_hdr header
;
709 struct type50_meb1_msg meb1
;
710 struct type50_meb2_msg meb2
;
711 struct type50_crb1_msg crb1
;
712 struct type50_crb2_msg crb2
;
724 #define TYPE80_RSP_CODE 0x80
727 unsigned char reserved1
;
729 unsigned char reserved2
[2];
730 unsigned char reply_code
;
731 unsigned char reserved3
[3];
734 #define TYPE82_RSP_CODE 0x82
735 #define TYPE88_RSP_CODE 0x88
737 #define REP82_ERROR_MACHINE_FAILURE 0x10
738 #define REP82_ERROR_PREEMPT_FAILURE 0x12
739 #define REP82_ERROR_CHECKPT_FAILURE 0x14
740 #define REP82_ERROR_MESSAGE_TYPE 0x20
741 #define REP82_ERROR_INVALID_COMM_CD 0x21
742 #define REP82_ERROR_INVALID_MSG_LEN 0x23
743 #define REP82_ERROR_RESERVD_FIELD 0x24
744 #define REP82_ERROR_FORMAT_FIELD 0x29
745 #define REP82_ERROR_INVALID_COMMAND 0x30
746 #define REP82_ERROR_MALFORMED_MSG 0x40
747 #define REP82_ERROR_RESERVED_FIELDO 0x50
748 #define REP82_ERROR_WORD_ALIGNMENT 0x60
749 #define REP82_ERROR_MESSAGE_LENGTH 0x80
750 #define REP82_ERROR_OPERAND_INVALID 0x82
751 #define REP82_ERROR_OPERAND_SIZE 0x84
752 #define REP82_ERROR_EVEN_MOD_IN_OPND 0x85
753 #define REP82_ERROR_RESERVED_FIELD 0x88
754 #define REP82_ERROR_TRANSPORT_FAIL 0x90
755 #define REP82_ERROR_PACKET_TRUNCATED 0xA0
756 #define REP82_ERROR_ZERO_BUFFER_LEN 0xB0
758 #define REP88_ERROR_MODULE_FAILURE 0x10
759 #define REP88_ERROR_MODULE_TIMEOUT 0x11
760 #define REP88_ERROR_MODULE_NOTINIT 0x13
761 #define REP88_ERROR_MODULE_NOTAVAIL 0x14
762 #define REP88_ERROR_MODULE_DISABLED 0x15
763 #define REP88_ERROR_MODULE_IN_DIAGN 0x17
764 #define REP88_ERROR_FASTPATH_DISABLD 0x19
765 #define REP88_ERROR_MESSAGE_TYPE 0x20
766 #define REP88_ERROR_MESSAGE_MALFORMD 0x22
767 #define REP88_ERROR_MESSAGE_LENGTH 0x23
768 #define REP88_ERROR_RESERVED_FIELD 0x24
769 #define REP88_ERROR_KEY_TYPE 0x34
770 #define REP88_ERROR_INVALID_KEY 0x82
771 #define REP88_ERROR_OPERAND 0x84
772 #define REP88_ERROR_OPERAND_EVEN_MOD 0x85
774 #define CALLER_HEADER 12
777 testq(int q_nr
, int *q_depth
, int *dev_type
, struct ap_status_word
*stat
)
786 "0: .long 0xb2af0000 \n"
798 ".section .fixup,\"ax\" \n"
803 ".section __ex_table,\"a\" \n"
808 :"=d" (ccode
),"=d" (*stat
),"=d" (*q_depth
), "=d" (*dev_type
)
809 :"d" (q_nr
), "K" (DEV_TSQ_EXCEPTION
)
810 :"cc","0","1","2","memory");
815 "0: .long 0xb2af0000 \n"
825 ".section .fixup,\"ax\" \n"
834 ".section __ex_table,\"a\" \n"
839 :"=d" (ccode
),"=d" (*stat
),"=d" (*q_depth
), "=d" (*dev_type
)
840 :"d" (q_nr
), "K" (DEV_TSQ_EXCEPTION
)
841 :"cc","0","1","2","memory");
847 resetq(int q_nr
, struct ap_status_word
*stat_p
)
859 "0: .long 0xb2af0000 \n"
866 ".section .fixup,\"ax\" \n"
871 ".section __ex_table,\"a\" \n"
876 :"=d" (ccode
),"=d" (*stat_p
)
877 :"d" (q_nr
), "K" (DEV_RSQ_EXCEPTION
)
878 :"cc","0","1","2","memory");
886 "0: .long 0xb2af0000 \n"
891 ".section .fixup,\"ax\" \n"
900 ".section __ex_table,\"a\" \n"
905 :"=d" (ccode
),"=d" (*stat_p
)
906 :"d" (q_nr
), "K" (DEV_RSQ_EXCEPTION
)
907 :"cc","0","1","2","memory");
913 sen(int msg_len
, unsigned char *msg_ext
, struct ap_status_word
*stat
)
930 "0: .long 0xb2ad0026 \n"
938 ".section .fixup,\"ax\" \n"
943 ".section __ex_table,\"a\" \n"
948 :"=d" (ccode
),"=d" (*stat
)
949 :"d" (msg_len
),"a" (msg_ext
), "K" (DEV_SEN_EXCEPTION
)
950 :"cc","0","1","2","3","6","7","memory");
963 "0: .long 0xb2ad0026 \n"
969 ".section .fixup,\"ax\" \n"
978 ".section __ex_table,\"a\" \n"
983 :"=d" (ccode
),"=d" (*stat
)
984 :"d" (msg_len
),"a" (msg_ext
), "K" (DEV_SEN_EXCEPTION
)
985 :"cc","0","1","2","3","6","7","memory");
991 rec(int q_nr
, int buff_l
, unsigned char *rsp
, unsigned char *id
,
992 struct ap_status_word
*st
)
1009 "0: .long 0xb2ae0046 \n"
1020 ".section .fixup,\"ax\" \n"
1025 ".section __ex_table,\"a\" \n"
1030 :"=d"(ccode
),"=d"(*st
)
1031 :"d" (q_nr
), "d" (rsp
), "d" (id
), "d" (buff_l
), "K" (DEV_REC_EXCEPTION
)
1032 :"cc","0","1","2","3","4","5","6","7","memory");
1045 "0: .long 0xb2ae0046 \n"
1054 ".section .fixup,\"ax\" \n"
1063 ".section __ex_table,\"a\" \n"
1068 :"=d"(ccode
),"=d"(*st
)
1069 :"d" (q_nr
), "d" (rsp
), "d" (id
), "d" (buff_l
), "K" (DEV_REC_EXCEPTION
)
1070 :"cc","0","1","2","3","4","5","6","7","memory");
1076 itoLe2(int *i_p
, unsigned char *lechars
)
1078 *lechars
= *((unsigned char *) i_p
+ sizeof(int) - 1);
1079 *(lechars
+ 1) = *((unsigned char *) i_p
+ sizeof(int) - 2);
1083 le2toI(unsigned char *lechars
, int *i_p
)
1085 unsigned char *ic_p
;
1087 ic_p
= (unsigned char *) i_p
;
1088 *(ic_p
+ 2) = *(lechars
+ 1);
1089 *(ic_p
+ 3) = *(lechars
);
1093 is_empty(unsigned char *ptr
, int len
)
1095 return !memcmp(ptr
, (unsigned char *) &static_pvt_me_key
+60, len
);
1099 query_online(int deviceNr
, int cdx
, int resetNr
, int *q_depth
, int *dev_type
)
1101 int q_nr
, i
, t_depth
, t_dev_type
;
1103 struct ap_status_word stat_word
;
1107 q_nr
= (deviceNr
<< SKIP_BITL
) + cdx
;
1109 ccode
= testq(q_nr
, &t_depth
, &t_dev_type
, &stat_word
);
1110 PDEBUG("ccode %d response_code %02X\n", ccode
, stat_word
.response_code
);
1112 for (i
= 0; i
< resetNr
; i
++) {
1114 PRINTKC("Exception testing device %d\n", i
);
1115 return HD_TSQ_EXCEPTION
;
1119 PDEBUG("t_dev_type %d\n", t_dev_type
);
1122 *q_depth
= t_depth
+ 1;
1123 switch (t_dev_type
) {
1131 *dev_type
= PCIXCC_UNK
;
1143 PDEBUG("available device %d: Q depth = %d, dev "
1144 "type = %d, stat = %02X%02X%02X%02X\n",
1145 deviceNr
, *q_depth
, *dev_type
,
1146 stat_word
.q_stat_flags
,
1147 stat_word
.response_code
,
1148 stat_word
.reserved
[0],
1149 stat_word
.reserved
[1]);
1152 switch (stat_word
.response_code
) {
1153 case AP_RESPONSE_NORMAL
:
1156 *q_depth
= t_depth
+ 1;
1157 *dev_type
= t_dev_type
;
1158 PDEBUG("cc3, available device "
1159 "%d: Q depth = %d, dev "
1160 "type = %d, stat = "
1161 "%02X%02X%02X%02X\n",
1164 stat_word
.q_stat_flags
,
1165 stat_word
.response_code
,
1166 stat_word
.reserved
[0],
1167 stat_word
.reserved
[1]);
1169 case AP_RESPONSE_Q_NOT_AVAIL
:
1170 stat
= HD_NOT_THERE
;
1173 case AP_RESPONSE_RESET_IN_PROGRESS
:
1174 PDEBUG("device %d in reset\n",
1177 case AP_RESPONSE_DECONFIGURED
:
1178 stat
= HD_DECONFIGURED
;
1181 case AP_RESPONSE_CHECKSTOPPED
:
1182 stat
= HD_CHECKSTOPPED
;
1185 case AP_RESPONSE_BUSY
:
1186 PDEBUG("device %d busy\n",
1194 stat
= HD_NOT_THERE
;
1203 ccode
= testq(q_nr
, &t_depth
, &t_dev_type
, &stat_word
);
1209 reset_device(int deviceNr
, int cdx
, int resetNr
)
1211 int q_nr
, ccode
= 0, dummy_qdepth
, dummy_devType
, i
;
1212 struct ap_status_word stat_word
;
1216 q_nr
= (deviceNr
<< SKIP_BITL
) + cdx
;
1218 ccode
= resetq(q_nr
, &stat_word
);
1220 return DEV_RSQ_EXCEPTION
;
1223 for (i
= 0; i
< resetNr
; i
++) {
1227 if (stat_word
.q_stat_flags
& AP_Q_STATUS_EMPTY
)
1231 switch (stat_word
.response_code
) {
1232 case AP_RESPONSE_NORMAL
:
1234 if (stat_word
.q_stat_flags
& AP_Q_STATUS_EMPTY
)
1237 case AP_RESPONSE_Q_NOT_AVAIL
:
1238 case AP_RESPONSE_DECONFIGURED
:
1239 case AP_RESPONSE_CHECKSTOPPED
:
1243 case AP_RESPONSE_RESET_IN_PROGRESS
:
1244 case AP_RESPONSE_BUSY
:
1258 ccode
= testq(q_nr
, &dummy_qdepth
, &dummy_devType
, &stat_word
);
1260 stat
= DEV_TSQ_EXCEPTION
;
1264 PDEBUG("Number of testq's needed for reset: %d\n", i
);
1273 #ifdef DEBUG_HYDRA_MSGS
1275 print_buffer(unsigned char *buffer
, int bufflen
)
1278 for (i
= 0; i
< bufflen
; i
+= 16) {
1279 PRINTK("%04X: %02X%02X%02X%02X %02X%02X%02X%02X "
1280 "%02X%02X%02X%02X %02X%02X%02X%02X\n", i
,
1281 buffer
[i
+0], buffer
[i
+1], buffer
[i
+2], buffer
[i
+3],
1282 buffer
[i
+4], buffer
[i
+5], buffer
[i
+6], buffer
[i
+7],
1283 buffer
[i
+8], buffer
[i
+9], buffer
[i
+10], buffer
[i
+11],
1284 buffer
[i
+12], buffer
[i
+13], buffer
[i
+14], buffer
[i
+15]);
1290 send_to_AP(int dev_nr
, int cdx
, int msg_len
, unsigned char *msg_ext
)
1292 struct ap_status_word stat_word
;
1295 u32
*q_nr_p
= (u32
*)msg_ext
;
1297 *q_nr_p
= (dev_nr
<< SKIP_BITL
) + cdx
;
1298 PDEBUG("msg_len passed to sen: %d\n", msg_len
);
1299 PDEBUG("q number passed to sen: %02x%02x%02x%02x\n",
1300 msg_ext
[0], msg_ext
[1], msg_ext
[2], msg_ext
[3]);
1303 #ifdef DEBUG_HYDRA_MSGS
1304 PRINTK("Request header: %02X%02X%02X%02X %02X%02X%02X%02X "
1305 "%02X%02X%02X%02X\n",
1306 msg_ext
[0], msg_ext
[1], msg_ext
[2], msg_ext
[3],
1307 msg_ext
[4], msg_ext
[5], msg_ext
[6], msg_ext
[7],
1308 msg_ext
[8], msg_ext
[9], msg_ext
[10], msg_ext
[11]);
1309 print_buffer(msg_ext
+CALLER_HEADER
, msg_len
);
1312 ccode
= sen(msg_len
, msg_ext
, &stat_word
);
1314 return DEV_SEN_EXCEPTION
;
1316 PDEBUG("nq cc: %u, st: %02x%02x%02x%02x\n",
1317 ccode
, stat_word
.q_stat_flags
, stat_word
.response_code
,
1318 stat_word
.reserved
[0], stat_word
.reserved
[1]);
1327 switch (stat_word
.response_code
) {
1328 case AP_RESPONSE_NORMAL
:
1331 case AP_RESPONSE_Q_FULL
:
1332 stat
= DEV_QUEUE_FULL
;
1348 receive_from_AP(int dev_nr
, int cdx
, int resplen
, unsigned char *resp
,
1349 unsigned char *psmid
)
1352 struct ap_status_word stat_word
;
1355 memset(resp
, 0x00, 8);
1357 ccode
= rec((dev_nr
<< SKIP_BITL
) + cdx
, resplen
, resp
, psmid
,
1360 return DEV_REC_EXCEPTION
;
1362 PDEBUG("dq cc: %u, st: %02x%02x%02x%02x\n",
1363 ccode
, stat_word
.q_stat_flags
, stat_word
.response_code
,
1364 stat_word
.reserved
[0], stat_word
.reserved
[1]);
1370 #ifdef DEBUG_HYDRA_MSGS
1371 print_buffer(resp
, resplen
);
1375 switch (stat_word
.response_code
) {
1376 case AP_RESPONSE_NORMAL
:
1379 case AP_RESPONSE_NO_PENDING_REPLY
:
1380 if (stat_word
.q_stat_flags
& AP_Q_STATUS_EMPTY
)
1385 case AP_RESPONSE_INDEX_TOO_BIG
:
1386 case AP_RESPONSE_NO_FIRST_PART
:
1387 case AP_RESPONSE_MESSAGE_TOO_BIG
:
1388 stat
= DEV_BAD_MESSAGE
;
1402 pad_msg(unsigned char *buffer
, int totalLength
, int msgLength
)
1406 for (pad_len
= 0; pad_len
< (totalLength
- msgLength
); pad_len
++)
1407 if (buffer
[pad_len
] != 0x00)
1411 return SEN_PAD_ERROR
;
1416 memcpy(buffer
+2, static_pad
, pad_len
);
1418 buffer
[pad_len
+ 2] = 0x00;
1424 is_common_public_key(unsigned char *key
, int len
)
1428 for (i
= 0; i
< len
; i
++)
1433 if (((len
== 1) && (key
[0] == 3)) ||
1434 ((len
== 3) && (key
[0] == 1) && (key
[1] == 0) && (key
[2] == 1)))
1441 ICAMEX_msg_to_type4MEX_msg(struct ica_rsa_modexpo
*icaMex_p
, int *z90cMsg_l_p
,
1442 union type4_msg
*z90cMsg_p
)
1444 int mod_len
, msg_size
, mod_tgt_len
, exp_tgt_len
, inp_tgt_len
;
1445 unsigned char *mod_tgt
, *exp_tgt
, *inp_tgt
;
1446 union type4_msg
*tmp_type4_msg
;
1448 mod_len
= icaMex_p
->inputdatalength
;
1450 msg_size
= ((mod_len
<= 128) ? TYPE4_SME_LEN
: TYPE4_LME_LEN
) +
1453 memset(z90cMsg_p
, 0, msg_size
);
1455 tmp_type4_msg
= (union type4_msg
*)
1456 ((unsigned char *) z90cMsg_p
+ CALLER_HEADER
);
1458 tmp_type4_msg
->sme
.header
.msg_type_code
= TYPE4_TYPE_CODE
;
1459 tmp_type4_msg
->sme
.header
.request_code
= TYPE4_REQU_CODE
;
1461 if (mod_len
<= 128) {
1462 tmp_type4_msg
->sme
.header
.msg_fmt
= TYPE4_SME_FMT
;
1463 tmp_type4_msg
->sme
.header
.msg_len
= TYPE4_SME_LEN
;
1464 mod_tgt
= tmp_type4_msg
->sme
.modulus
;
1465 mod_tgt_len
= sizeof(tmp_type4_msg
->sme
.modulus
);
1466 exp_tgt
= tmp_type4_msg
->sme
.exponent
;
1467 exp_tgt_len
= sizeof(tmp_type4_msg
->sme
.exponent
);
1468 inp_tgt
= tmp_type4_msg
->sme
.message
;
1469 inp_tgt_len
= sizeof(tmp_type4_msg
->sme
.message
);
1471 tmp_type4_msg
->lme
.header
.msg_fmt
= TYPE4_LME_FMT
;
1472 tmp_type4_msg
->lme
.header
.msg_len
= TYPE4_LME_LEN
;
1473 mod_tgt
= tmp_type4_msg
->lme
.modulus
;
1474 mod_tgt_len
= sizeof(tmp_type4_msg
->lme
.modulus
);
1475 exp_tgt
= tmp_type4_msg
->lme
.exponent
;
1476 exp_tgt_len
= sizeof(tmp_type4_msg
->lme
.exponent
);
1477 inp_tgt
= tmp_type4_msg
->lme
.message
;
1478 inp_tgt_len
= sizeof(tmp_type4_msg
->lme
.message
);
1481 mod_tgt
+= (mod_tgt_len
- mod_len
);
1482 if (copy_from_user(mod_tgt
, icaMex_p
->n_modulus
, mod_len
))
1483 return SEN_RELEASED
;
1484 if (is_empty(mod_tgt
, mod_len
))
1485 return SEN_USER_ERROR
;
1486 exp_tgt
+= (exp_tgt_len
- mod_len
);
1487 if (copy_from_user(exp_tgt
, icaMex_p
->b_key
, mod_len
))
1488 return SEN_RELEASED
;
1489 if (is_empty(exp_tgt
, mod_len
))
1490 return SEN_USER_ERROR
;
1491 inp_tgt
+= (inp_tgt_len
- mod_len
);
1492 if (copy_from_user(inp_tgt
, icaMex_p
->inputdata
, mod_len
))
1493 return SEN_RELEASED
;
1494 if (is_empty(inp_tgt
, mod_len
))
1495 return SEN_USER_ERROR
;
1497 *z90cMsg_l_p
= msg_size
- CALLER_HEADER
;
1503 ICACRT_msg_to_type4CRT_msg(struct ica_rsa_modexpo_crt
*icaMsg_p
,
1504 int *z90cMsg_l_p
, union type4_msg
*z90cMsg_p
)
1506 int mod_len
, short_len
, long_len
, tmp_size
, p_tgt_len
, q_tgt_len
,
1507 dp_tgt_len
, dq_tgt_len
, u_tgt_len
, inp_tgt_len
;
1508 unsigned char *p_tgt
, *q_tgt
, *dp_tgt
, *dq_tgt
, *u_tgt
, *inp_tgt
;
1509 union type4_msg
*tmp_type4_msg
;
1511 mod_len
= icaMsg_p
->inputdatalength
;
1512 short_len
= mod_len
/ 2;
1513 long_len
= mod_len
/ 2 + 8;
1515 tmp_size
= ((mod_len
<= 128) ? TYPE4_SCR_LEN
: TYPE4_LCR_LEN
) +
1518 memset(z90cMsg_p
, 0, tmp_size
);
1520 tmp_type4_msg
= (union type4_msg
*)
1521 ((unsigned char *) z90cMsg_p
+ CALLER_HEADER
);
1523 tmp_type4_msg
->scr
.header
.msg_type_code
= TYPE4_TYPE_CODE
;
1524 tmp_type4_msg
->scr
.header
.request_code
= TYPE4_REQU_CODE
;
1525 if (mod_len
<= 128) {
1526 tmp_type4_msg
->scr
.header
.msg_fmt
= TYPE4_SCR_FMT
;
1527 tmp_type4_msg
->scr
.header
.msg_len
= TYPE4_SCR_LEN
;
1528 p_tgt
= tmp_type4_msg
->scr
.p
;
1529 p_tgt_len
= sizeof(tmp_type4_msg
->scr
.p
);
1530 q_tgt
= tmp_type4_msg
->scr
.q
;
1531 q_tgt_len
= sizeof(tmp_type4_msg
->scr
.q
);
1532 dp_tgt
= tmp_type4_msg
->scr
.dp
;
1533 dp_tgt_len
= sizeof(tmp_type4_msg
->scr
.dp
);
1534 dq_tgt
= tmp_type4_msg
->scr
.dq
;
1535 dq_tgt_len
= sizeof(tmp_type4_msg
->scr
.dq
);
1536 u_tgt
= tmp_type4_msg
->scr
.u
;
1537 u_tgt_len
= sizeof(tmp_type4_msg
->scr
.u
);
1538 inp_tgt
= tmp_type4_msg
->scr
.message
;
1539 inp_tgt_len
= sizeof(tmp_type4_msg
->scr
.message
);
1541 tmp_type4_msg
->lcr
.header
.msg_fmt
= TYPE4_LCR_FMT
;
1542 tmp_type4_msg
->lcr
.header
.msg_len
= TYPE4_LCR_LEN
;
1543 p_tgt
= tmp_type4_msg
->lcr
.p
;
1544 p_tgt_len
= sizeof(tmp_type4_msg
->lcr
.p
);
1545 q_tgt
= tmp_type4_msg
->lcr
.q
;
1546 q_tgt_len
= sizeof(tmp_type4_msg
->lcr
.q
);
1547 dp_tgt
= tmp_type4_msg
->lcr
.dp
;
1548 dp_tgt_len
= sizeof(tmp_type4_msg
->lcr
.dp
);
1549 dq_tgt
= tmp_type4_msg
->lcr
.dq
;
1550 dq_tgt_len
= sizeof(tmp_type4_msg
->lcr
.dq
);
1551 u_tgt
= tmp_type4_msg
->lcr
.u
;
1552 u_tgt_len
= sizeof(tmp_type4_msg
->lcr
.u
);
1553 inp_tgt
= tmp_type4_msg
->lcr
.message
;
1554 inp_tgt_len
= sizeof(tmp_type4_msg
->lcr
.message
);
1557 p_tgt
+= (p_tgt_len
- long_len
);
1558 if (copy_from_user(p_tgt
, icaMsg_p
->np_prime
, long_len
))
1559 return SEN_RELEASED
;
1560 if (is_empty(p_tgt
, long_len
))
1561 return SEN_USER_ERROR
;
1562 q_tgt
+= (q_tgt_len
- short_len
);
1563 if (copy_from_user(q_tgt
, icaMsg_p
->nq_prime
, short_len
))
1564 return SEN_RELEASED
;
1565 if (is_empty(q_tgt
, short_len
))
1566 return SEN_USER_ERROR
;
1567 dp_tgt
+= (dp_tgt_len
- long_len
);
1568 if (copy_from_user(dp_tgt
, icaMsg_p
->bp_key
, long_len
))
1569 return SEN_RELEASED
;
1570 if (is_empty(dp_tgt
, long_len
))
1571 return SEN_USER_ERROR
;
1572 dq_tgt
+= (dq_tgt_len
- short_len
);
1573 if (copy_from_user(dq_tgt
, icaMsg_p
->bq_key
, short_len
))
1574 return SEN_RELEASED
;
1575 if (is_empty(dq_tgt
, short_len
))
1576 return SEN_USER_ERROR
;
1577 u_tgt
+= (u_tgt_len
- long_len
);
1578 if (copy_from_user(u_tgt
, icaMsg_p
->u_mult_inv
, long_len
))
1579 return SEN_RELEASED
;
1580 if (is_empty(u_tgt
, long_len
))
1581 return SEN_USER_ERROR
;
1582 inp_tgt
+= (inp_tgt_len
- mod_len
);
1583 if (copy_from_user(inp_tgt
, icaMsg_p
->inputdata
, mod_len
))
1584 return SEN_RELEASED
;
1585 if (is_empty(inp_tgt
, mod_len
))
1586 return SEN_USER_ERROR
;
1588 *z90cMsg_l_p
= tmp_size
- CALLER_HEADER
;
1594 ICAMEX_msg_to_type6MEX_de_msg(struct ica_rsa_modexpo
*icaMsg_p
, int cdx
,
1595 int *z90cMsg_l_p
, struct type6_msg
*z90cMsg_p
)
1597 int mod_len
, vud_len
, tmp_size
, total_CPRB_len
, parmBlock_l
;
1598 unsigned char *temp
;
1599 struct type6_hdr
*tp6Hdr_p
;
1600 struct CPRB
*cprb_p
;
1601 struct cca_private_ext_ME
*key_p
;
1602 static int deprecated_msg_count
= 0;
1604 mod_len
= icaMsg_p
->inputdatalength
;
1605 tmp_size
= FIXED_TYPE6_ME_LEN
+ mod_len
;
1606 total_CPRB_len
= tmp_size
- sizeof(struct type6_hdr
);
1607 parmBlock_l
= total_CPRB_len
- sizeof(struct CPRB
);
1608 tmp_size
= 4*((tmp_size
+ 3)/4) + CALLER_HEADER
;
1610 memset(z90cMsg_p
, 0, tmp_size
);
1612 temp
= (unsigned char *)z90cMsg_p
+ CALLER_HEADER
;
1613 memcpy(temp
, &static_type6_hdr
, sizeof(struct type6_hdr
));
1614 tp6Hdr_p
= (struct type6_hdr
*)temp
;
1615 tp6Hdr_p
->ToCardLen1
= 4*((total_CPRB_len
+3)/4);
1616 tp6Hdr_p
->FromCardLen1
= RESPONSE_CPRB_SIZE
;
1618 temp
+= sizeof(struct type6_hdr
);
1619 memcpy(temp
, &static_cprb
, sizeof(struct CPRB
));
1620 cprb_p
= (struct CPRB
*) temp
;
1621 cprb_p
->usage_domain
[0]= (unsigned char)cdx
;
1622 itoLe2(&parmBlock_l
, cprb_p
->req_parml
);
1623 itoLe2((int *)&(tp6Hdr_p
->FromCardLen1
), cprb_p
->rpl_parml
);
1625 temp
+= sizeof(struct CPRB
);
1626 memcpy(temp
, &static_pkd_function_and_rules
,
1627 sizeof(struct function_and_rules_block
));
1629 temp
+= sizeof(struct function_and_rules_block
);
1630 vud_len
= 2 + icaMsg_p
->inputdatalength
;
1631 itoLe2(&vud_len
, temp
);
1634 if (copy_from_user(temp
, icaMsg_p
->inputdata
, mod_len
))
1635 return SEN_RELEASED
;
1636 if (is_empty(temp
, mod_len
))
1637 return SEN_USER_ERROR
;
1640 memcpy(temp
, &static_T6_keyBlock_hdr
, sizeof(struct T6_keyBlock_hdr
));
1642 temp
+= sizeof(struct T6_keyBlock_hdr
);
1643 memcpy(temp
, &static_pvt_me_key
, sizeof(struct cca_private_ext_ME
));
1644 key_p
= (struct cca_private_ext_ME
*)temp
;
1645 temp
= key_p
->pvtMESec
.exponent
+ sizeof(key_p
->pvtMESec
.exponent
)
1647 if (copy_from_user(temp
, icaMsg_p
->b_key
, mod_len
))
1648 return SEN_RELEASED
;
1649 if (is_empty(temp
, mod_len
))
1650 return SEN_USER_ERROR
;
1652 if (is_common_public_key(temp
, mod_len
)) {
1653 if (deprecated_msg_count
< 20) {
1654 PRINTK("Common public key used for modex decrypt\n");
1655 deprecated_msg_count
++;
1656 if (deprecated_msg_count
== 20)
1657 PRINTK("No longer issuing messages about common"
1658 " public key for modex decrypt.\n");
1660 return SEN_NOT_AVAIL
;
1663 temp
= key_p
->pvtMESec
.modulus
+ sizeof(key_p
->pvtMESec
.modulus
)
1665 if (copy_from_user(temp
, icaMsg_p
->n_modulus
, mod_len
))
1666 return SEN_RELEASED
;
1667 if (is_empty(temp
, mod_len
))
1668 return SEN_USER_ERROR
;
1670 key_p
->pubMESec
.modulus_bit_len
= 8 * mod_len
;
1672 *z90cMsg_l_p
= tmp_size
- CALLER_HEADER
;
1678 ICAMEX_msg_to_type6MEX_en_msg(struct ica_rsa_modexpo
*icaMsg_p
, int cdx
,
1679 int *z90cMsg_l_p
, struct type6_msg
*z90cMsg_p
)
1681 int mod_len
, vud_len
, exp_len
, key_len
;
1682 int pad_len
, tmp_size
, total_CPRB_len
, parmBlock_l
, i
;
1683 unsigned char *temp_exp
, *exp_p
, *temp
;
1684 struct type6_hdr
*tp6Hdr_p
;
1685 struct CPRB
*cprb_p
;
1686 struct cca_public_key
*key_p
;
1687 struct T6_keyBlock_hdr
*keyb_p
;
1689 temp_exp
= kmalloc(256, GFP_KERNEL
);
1692 mod_len
= icaMsg_p
->inputdatalength
;
1693 if (copy_from_user(temp_exp
, icaMsg_p
->b_key
, mod_len
)) {
1695 return SEN_RELEASED
;
1697 if (is_empty(temp_exp
, mod_len
)) {
1699 return SEN_USER_ERROR
;
1703 for (i
= 0; i
< mod_len
; i
++)
1708 return SEN_USER_ERROR
;
1711 exp_len
= mod_len
- i
;
1714 PDEBUG("exp_len after computation: %08x\n", exp_len
);
1715 tmp_size
= FIXED_TYPE6_ME_EN_LEN
+ 2 * mod_len
+ exp_len
;
1716 total_CPRB_len
= tmp_size
- sizeof(struct type6_hdr
);
1717 parmBlock_l
= total_CPRB_len
- sizeof(struct CPRB
);
1718 tmp_size
= 4*((tmp_size
+ 3)/4) + CALLER_HEADER
;
1720 vud_len
= 2 + mod_len
;
1721 memset(z90cMsg_p
, 0, tmp_size
);
1723 temp
= (unsigned char *)z90cMsg_p
+ CALLER_HEADER
;
1724 memcpy(temp
, &static_type6_hdr
, sizeof(struct type6_hdr
));
1725 tp6Hdr_p
= (struct type6_hdr
*)temp
;
1726 tp6Hdr_p
->ToCardLen1
= 4*((total_CPRB_len
+3)/4);
1727 tp6Hdr_p
->FromCardLen1
= RESPONSE_CPRB_SIZE
;
1728 memcpy(tp6Hdr_p
->function_code
, static_PKE_function_code
,
1729 sizeof(static_PKE_function_code
));
1730 temp
+= sizeof(struct type6_hdr
);
1731 memcpy(temp
, &static_cprb
, sizeof(struct CPRB
));
1732 cprb_p
= (struct CPRB
*) temp
;
1733 cprb_p
->usage_domain
[0]= (unsigned char)cdx
;
1734 itoLe2((int *)&(tp6Hdr_p
->FromCardLen1
), cprb_p
->rpl_parml
);
1735 temp
+= sizeof(struct CPRB
);
1736 memcpy(temp
, &static_pke_function_and_rules
,
1737 sizeof(struct function_and_rules_block
));
1738 temp
+= sizeof(struct function_and_rules_block
);
1740 if (copy_from_user(temp
, icaMsg_p
->inputdata
, mod_len
)) {
1742 return SEN_RELEASED
;
1744 if (is_empty(temp
, mod_len
)) {
1746 return SEN_USER_ERROR
;
1748 if ((temp
[0] != 0x00) || (temp
[1] != 0x02)) {
1750 return SEN_NOT_AVAIL
;
1752 for (i
= 2; i
< mod_len
; i
++)
1753 if (temp
[i
] == 0x00)
1755 if ((i
< 9) || (i
> (mod_len
- 2))) {
1757 return SEN_NOT_AVAIL
;
1760 vud_len
= mod_len
- pad_len
;
1761 memmove(temp
, temp
+pad_len
, vud_len
);
1764 itoLe2(&vud_len
, temp
);
1766 keyb_p
= (struct T6_keyBlock_hdr
*)temp
;
1767 temp
+= sizeof(struct T6_keyBlock_hdr
);
1768 memcpy(temp
, &static_public_key
, sizeof(static_public_key
));
1769 key_p
= (struct cca_public_key
*)temp
;
1770 temp
= key_p
->pubSec
.exponent
;
1771 memcpy(temp
, exp_p
, exp_len
);
1774 if (copy_from_user(temp
, icaMsg_p
->n_modulus
, mod_len
))
1775 return SEN_RELEASED
;
1776 if (is_empty(temp
, mod_len
))
1777 return SEN_USER_ERROR
;
1778 key_p
->pubSec
.modulus_bit_len
= 8 * mod_len
;
1779 key_p
->pubSec
.modulus_byte_len
= mod_len
;
1780 key_p
->pubSec
.exponent_len
= exp_len
;
1781 key_p
->pubSec
.section_length
= CALLER_HEADER
+ mod_len
+ exp_len
;
1782 key_len
= key_p
->pubSec
.section_length
+ sizeof(struct cca_token_hdr
);
1783 key_p
->pubHdr
.token_length
= key_len
;
1785 itoLe2(&key_len
, keyb_p
->ulen
);
1787 itoLe2(&key_len
, keyb_p
->blen
);
1788 parmBlock_l
-= pad_len
;
1789 itoLe2(&parmBlock_l
, cprb_p
->req_parml
);
1790 *z90cMsg_l_p
= tmp_size
- CALLER_HEADER
;
1796 ICACRT_msg_to_type6CRT_msg(struct ica_rsa_modexpo_crt
*icaMsg_p
, int cdx
,
1797 int *z90cMsg_l_p
, struct type6_msg
*z90cMsg_p
)
1799 int mod_len
, vud_len
, tmp_size
, total_CPRB_len
, parmBlock_l
, short_len
;
1800 int long_len
, pad_len
, keyPartsLen
, tmp_l
;
1801 unsigned char *tgt_p
, *temp
;
1802 struct type6_hdr
*tp6Hdr_p
;
1803 struct CPRB
*cprb_p
;
1804 struct cca_token_hdr
*keyHdr_p
;
1805 struct cca_pvt_ext_CRT_sec
*pvtSec_p
;
1806 struct cca_public_sec
*pubSec_p
;
1808 mod_len
= icaMsg_p
->inputdatalength
;
1809 short_len
= mod_len
/ 2;
1810 long_len
= 8 + short_len
;
1811 keyPartsLen
= 3 * long_len
+ 2 * short_len
;
1812 pad_len
= (8 - (keyPartsLen
% 8)) % 8;
1813 keyPartsLen
+= pad_len
+ mod_len
;
1814 tmp_size
= FIXED_TYPE6_CR_LEN
+ keyPartsLen
+ mod_len
;
1815 total_CPRB_len
= tmp_size
- sizeof(struct type6_hdr
);
1816 parmBlock_l
= total_CPRB_len
- sizeof(struct CPRB
);
1817 vud_len
= 2 + mod_len
;
1818 tmp_size
= 4*((tmp_size
+ 3)/4) + CALLER_HEADER
;
1820 memset(z90cMsg_p
, 0, tmp_size
);
1821 tgt_p
= (unsigned char *)z90cMsg_p
+ CALLER_HEADER
;
1822 memcpy(tgt_p
, &static_type6_hdr
, sizeof(struct type6_hdr
));
1823 tp6Hdr_p
= (struct type6_hdr
*)tgt_p
;
1824 tp6Hdr_p
->ToCardLen1
= 4*((total_CPRB_len
+3)/4);
1825 tp6Hdr_p
->FromCardLen1
= RESPONSE_CPRB_SIZE
;
1826 tgt_p
+= sizeof(struct type6_hdr
);
1827 cprb_p
= (struct CPRB
*) tgt_p
;
1828 memcpy(tgt_p
, &static_cprb
, sizeof(struct CPRB
));
1829 cprb_p
->usage_domain
[0]= *((unsigned char *)(&(cdx
))+3);
1830 itoLe2(&parmBlock_l
, cprb_p
->req_parml
);
1831 memcpy(cprb_p
->rpl_parml
, cprb_p
->req_parml
,
1832 sizeof(cprb_p
->req_parml
));
1833 tgt_p
+= sizeof(struct CPRB
);
1834 memcpy(tgt_p
, &static_pkd_function_and_rules
,
1835 sizeof(struct function_and_rules_block
));
1836 tgt_p
+= sizeof(struct function_and_rules_block
);
1837 itoLe2(&vud_len
, tgt_p
);
1839 if (copy_from_user(tgt_p
, icaMsg_p
->inputdata
, mod_len
))
1840 return SEN_RELEASED
;
1841 if (is_empty(tgt_p
, mod_len
))
1842 return SEN_USER_ERROR
;
1844 tmp_l
= sizeof(struct T6_keyBlock_hdr
) + sizeof(struct cca_token_hdr
) +
1845 sizeof(struct cca_pvt_ext_CRT_sec
) + 0x0F + keyPartsLen
;
1846 itoLe2(&tmp_l
, tgt_p
);
1849 itoLe2(&tmp_l
, temp
);
1850 tgt_p
+= sizeof(struct T6_keyBlock_hdr
);
1851 keyHdr_p
= (struct cca_token_hdr
*)tgt_p
;
1852 keyHdr_p
->token_identifier
= CCA_TKN_HDR_ID_EXT
;
1854 keyHdr_p
->token_length
= tmp_l
;
1855 tgt_p
+= sizeof(struct cca_token_hdr
);
1856 pvtSec_p
= (struct cca_pvt_ext_CRT_sec
*)tgt_p
;
1857 pvtSec_p
->section_identifier
= CCA_PVT_EXT_CRT_SEC_ID_PVT
;
1858 pvtSec_p
->section_length
=
1859 sizeof(struct cca_pvt_ext_CRT_sec
) + keyPartsLen
;
1860 pvtSec_p
->key_format
= CCA_PVT_EXT_CRT_SEC_FMT_CL
;
1861 pvtSec_p
->key_use_flags
[0] = CCA_PVT_USAGE_ALL
;
1862 pvtSec_p
->p_len
= long_len
;
1863 pvtSec_p
->q_len
= short_len
;
1864 pvtSec_p
->dp_len
= long_len
;
1865 pvtSec_p
->dq_len
= short_len
;
1866 pvtSec_p
->u_len
= long_len
;
1867 pvtSec_p
->mod_len
= mod_len
;
1868 pvtSec_p
->pad_len
= pad_len
;
1869 tgt_p
+= sizeof(struct cca_pvt_ext_CRT_sec
);
1870 if (copy_from_user(tgt_p
, icaMsg_p
->np_prime
, long_len
))
1871 return SEN_RELEASED
;
1872 if (is_empty(tgt_p
, long_len
))
1873 return SEN_USER_ERROR
;
1875 if (copy_from_user(tgt_p
, icaMsg_p
->nq_prime
, short_len
))
1876 return SEN_RELEASED
;
1877 if (is_empty(tgt_p
, short_len
))
1878 return SEN_USER_ERROR
;
1880 if (copy_from_user(tgt_p
, icaMsg_p
->bp_key
, long_len
))
1881 return SEN_RELEASED
;
1882 if (is_empty(tgt_p
, long_len
))
1883 return SEN_USER_ERROR
;
1885 if (copy_from_user(tgt_p
, icaMsg_p
->bq_key
, short_len
))
1886 return SEN_RELEASED
;
1887 if (is_empty(tgt_p
, short_len
))
1888 return SEN_USER_ERROR
;
1890 if (copy_from_user(tgt_p
, icaMsg_p
->u_mult_inv
, long_len
))
1891 return SEN_RELEASED
;
1892 if (is_empty(tgt_p
, long_len
))
1893 return SEN_USER_ERROR
;
1896 memset(tgt_p
, 0xFF, mod_len
);
1898 memcpy(tgt_p
, &static_cca_pub_sec
, sizeof(struct cca_public_sec
));
1899 pubSec_p
= (struct cca_public_sec
*) tgt_p
;
1900 pubSec_p
->modulus_bit_len
= 8 * mod_len
;
1901 *z90cMsg_l_p
= tmp_size
- CALLER_HEADER
;
1907 ICAMEX_msg_to_type6MEX_msgX(struct ica_rsa_modexpo
*icaMsg_p
, int cdx
,
1908 int *z90cMsg_l_p
, struct type6_msg
*z90cMsg_p
,
1911 int mod_len
, exp_len
, vud_len
, tmp_size
, total_CPRB_len
, parmBlock_l
;
1913 unsigned char *temp_exp
, *tgt_p
, *temp
, *exp_p
;
1914 struct type6_hdr
*tp6Hdr_p
;
1915 struct CPRBX
*cprbx_p
;
1916 struct cca_public_key
*key_p
;
1917 struct T6_keyBlock_hdrX
*keyb_p
;
1919 temp_exp
= kmalloc(256, GFP_KERNEL
);
1922 mod_len
= icaMsg_p
->inputdatalength
;
1923 if (copy_from_user(temp_exp
, icaMsg_p
->b_key
, mod_len
)) {
1925 return SEN_RELEASED
;
1927 if (is_empty(temp_exp
, mod_len
)) {
1929 return SEN_USER_ERROR
;
1932 for (i
= 0; i
< mod_len
; i
++)
1937 return SEN_USER_ERROR
;
1939 exp_len
= mod_len
- i
;
1941 PDEBUG("exp_len after computation: %08x\n", exp_len
);
1942 tmp_size
= FIXED_TYPE6_ME_EN_LENX
+ 2 * mod_len
+ exp_len
;
1943 total_CPRB_len
= tmp_size
- sizeof(struct type6_hdr
);
1944 parmBlock_l
= total_CPRB_len
- sizeof(struct CPRBX
);
1945 tmp_size
= tmp_size
+ CALLER_HEADER
;
1946 vud_len
= 2 + mod_len
;
1947 memset(z90cMsg_p
, 0, tmp_size
);
1948 tgt_p
= (unsigned char *)z90cMsg_p
+ CALLER_HEADER
;
1949 memcpy(tgt_p
, &static_type6_hdrX
, sizeof(struct type6_hdr
));
1950 tp6Hdr_p
= (struct type6_hdr
*)tgt_p
;
1951 tp6Hdr_p
->ToCardLen1
= total_CPRB_len
;
1952 tp6Hdr_p
->FromCardLen1
= RESPONSE_CPRBX_SIZE
;
1953 memcpy(tp6Hdr_p
->function_code
, static_PKE_function_code
,
1954 sizeof(static_PKE_function_code
));
1955 tgt_p
+= sizeof(struct type6_hdr
);
1956 memcpy(tgt_p
, &static_cprbx
, sizeof(struct CPRBX
));
1957 cprbx_p
= (struct CPRBX
*) tgt_p
;
1958 cprbx_p
->domain
= (unsigned short)cdx
;
1959 cprbx_p
->rpl_msgbl
= RESPONSE_CPRBX_SIZE
;
1960 tgt_p
+= sizeof(struct CPRBX
);
1961 if (dev_type
== PCIXCC_MCL2
)
1962 memcpy(tgt_p
, &static_pke_function_and_rulesX_MCL2
,
1963 sizeof(struct function_and_rules_block
));
1965 memcpy(tgt_p
, &static_pke_function_and_rulesX
,
1966 sizeof(struct function_and_rules_block
));
1967 tgt_p
+= sizeof(struct function_and_rules_block
);
1970 if (copy_from_user(tgt_p
, icaMsg_p
->inputdata
, mod_len
)) {
1972 return SEN_RELEASED
;
1974 if (is_empty(tgt_p
, mod_len
)) {
1976 return SEN_USER_ERROR
;
1979 *((short *)tgt_p
) = (short) vud_len
;
1981 keyb_p
= (struct T6_keyBlock_hdrX
*)tgt_p
;
1982 tgt_p
+= sizeof(struct T6_keyBlock_hdrX
);
1983 memcpy(tgt_p
, &static_public_key
, sizeof(static_public_key
));
1984 key_p
= (struct cca_public_key
*)tgt_p
;
1985 temp
= key_p
->pubSec
.exponent
;
1986 memcpy(temp
, exp_p
, exp_len
);
1989 if (copy_from_user(temp
, icaMsg_p
->n_modulus
, mod_len
))
1990 return SEN_RELEASED
;
1991 if (is_empty(temp
, mod_len
))
1992 return SEN_USER_ERROR
;
1993 key_p
->pubSec
.modulus_bit_len
= 8 * mod_len
;
1994 key_p
->pubSec
.modulus_byte_len
= mod_len
;
1995 key_p
->pubSec
.exponent_len
= exp_len
;
1996 key_p
->pubSec
.section_length
= CALLER_HEADER
+ mod_len
+ exp_len
;
1997 key_len
= key_p
->pubSec
.section_length
+ sizeof(struct cca_token_hdr
);
1998 key_p
->pubHdr
.token_length
= key_len
;
2000 keyb_p
->ulen
= (unsigned short)key_len
;
2002 keyb_p
->blen
= (unsigned short)key_len
;
2003 cprbx_p
->req_parml
= parmBlock_l
;
2004 *z90cMsg_l_p
= tmp_size
- CALLER_HEADER
;
2010 ICACRT_msg_to_type6CRT_msgX(struct ica_rsa_modexpo_crt
*icaMsg_p
, int cdx
,
2011 int *z90cMsg_l_p
, struct type6_msg
*z90cMsg_p
,
2014 int mod_len
, vud_len
, tmp_size
, total_CPRB_len
, parmBlock_l
, short_len
;
2015 int long_len
, pad_len
, keyPartsLen
, tmp_l
;
2016 unsigned char *tgt_p
, *temp
;
2017 struct type6_hdr
*tp6Hdr_p
;
2018 struct CPRBX
*cprbx_p
;
2019 struct cca_token_hdr
*keyHdr_p
;
2020 struct cca_pvt_ext_CRT_sec
*pvtSec_p
;
2021 struct cca_public_sec
*pubSec_p
;
2023 mod_len
= icaMsg_p
->inputdatalength
;
2024 short_len
= mod_len
/ 2;
2025 long_len
= 8 + short_len
;
2026 keyPartsLen
= 3 * long_len
+ 2 * short_len
;
2027 pad_len
= (8 - (keyPartsLen
% 8)) % 8;
2028 keyPartsLen
+= pad_len
+ mod_len
;
2029 tmp_size
= FIXED_TYPE6_CR_LENX
+ keyPartsLen
+ mod_len
;
2030 total_CPRB_len
= tmp_size
- sizeof(struct type6_hdr
);
2031 parmBlock_l
= total_CPRB_len
- sizeof(struct CPRBX
);
2032 vud_len
= 2 + mod_len
;
2033 tmp_size
= tmp_size
+ CALLER_HEADER
;
2034 memset(z90cMsg_p
, 0, tmp_size
);
2035 tgt_p
= (unsigned char *)z90cMsg_p
+ CALLER_HEADER
;
2036 memcpy(tgt_p
, &static_type6_hdrX
, sizeof(struct type6_hdr
));
2037 tp6Hdr_p
= (struct type6_hdr
*)tgt_p
;
2038 tp6Hdr_p
->ToCardLen1
= total_CPRB_len
;
2039 tp6Hdr_p
->FromCardLen1
= RESPONSE_CPRBX_SIZE
;
2040 tgt_p
+= sizeof(struct type6_hdr
);
2041 cprbx_p
= (struct CPRBX
*) tgt_p
;
2042 memcpy(tgt_p
, &static_cprbx
, sizeof(struct CPRBX
));
2043 cprbx_p
->domain
= (unsigned short)cdx
;
2044 cprbx_p
->req_parml
= parmBlock_l
;
2045 cprbx_p
->rpl_msgbl
= parmBlock_l
;
2046 tgt_p
+= sizeof(struct CPRBX
);
2047 if (dev_type
== PCIXCC_MCL2
)
2048 memcpy(tgt_p
, &static_pkd_function_and_rulesX_MCL2
,
2049 sizeof(struct function_and_rules_block
));
2051 memcpy(tgt_p
, &static_pkd_function_and_rulesX
,
2052 sizeof(struct function_and_rules_block
));
2053 tgt_p
+= sizeof(struct function_and_rules_block
);
2054 *((short *)tgt_p
) = (short) vud_len
;
2056 if (copy_from_user(tgt_p
, icaMsg_p
->inputdata
, mod_len
))
2057 return SEN_RELEASED
;
2058 if (is_empty(tgt_p
, mod_len
))
2059 return SEN_USER_ERROR
;
2061 tmp_l
= sizeof(struct T6_keyBlock_hdr
) + sizeof(struct cca_token_hdr
) +
2062 sizeof(struct cca_pvt_ext_CRT_sec
) + 0x0F + keyPartsLen
;
2063 *((short *)tgt_p
) = (short) tmp_l
;
2066 *((short *)temp
) = (short) tmp_l
;
2067 tgt_p
+= sizeof(struct T6_keyBlock_hdr
);
2068 keyHdr_p
= (struct cca_token_hdr
*)tgt_p
;
2069 keyHdr_p
->token_identifier
= CCA_TKN_HDR_ID_EXT
;
2071 keyHdr_p
->token_length
= tmp_l
;
2072 tgt_p
+= sizeof(struct cca_token_hdr
);
2073 pvtSec_p
= (struct cca_pvt_ext_CRT_sec
*)tgt_p
;
2074 pvtSec_p
->section_identifier
= CCA_PVT_EXT_CRT_SEC_ID_PVT
;
2075 pvtSec_p
->section_length
=
2076 sizeof(struct cca_pvt_ext_CRT_sec
) + keyPartsLen
;
2077 pvtSec_p
->key_format
= CCA_PVT_EXT_CRT_SEC_FMT_CL
;
2078 pvtSec_p
->key_use_flags
[0] = CCA_PVT_USAGE_ALL
;
2079 pvtSec_p
->p_len
= long_len
;
2080 pvtSec_p
->q_len
= short_len
;
2081 pvtSec_p
->dp_len
= long_len
;
2082 pvtSec_p
->dq_len
= short_len
;
2083 pvtSec_p
->u_len
= long_len
;
2084 pvtSec_p
->mod_len
= mod_len
;
2085 pvtSec_p
->pad_len
= pad_len
;
2086 tgt_p
+= sizeof(struct cca_pvt_ext_CRT_sec
);
2087 if (copy_from_user(tgt_p
, icaMsg_p
->np_prime
, long_len
))
2088 return SEN_RELEASED
;
2089 if (is_empty(tgt_p
, long_len
))
2090 return SEN_USER_ERROR
;
2092 if (copy_from_user(tgt_p
, icaMsg_p
->nq_prime
, short_len
))
2093 return SEN_RELEASED
;
2094 if (is_empty(tgt_p
, short_len
))
2095 return SEN_USER_ERROR
;
2097 if (copy_from_user(tgt_p
, icaMsg_p
->bp_key
, long_len
))
2098 return SEN_RELEASED
;
2099 if (is_empty(tgt_p
, long_len
))
2100 return SEN_USER_ERROR
;
2102 if (copy_from_user(tgt_p
, icaMsg_p
->bq_key
, short_len
))
2103 return SEN_RELEASED
;
2104 if (is_empty(tgt_p
, short_len
))
2105 return SEN_USER_ERROR
;
2107 if (copy_from_user(tgt_p
, icaMsg_p
->u_mult_inv
, long_len
))
2108 return SEN_RELEASED
;
2109 if (is_empty(tgt_p
, long_len
))
2110 return SEN_USER_ERROR
;
2113 memset(tgt_p
, 0xFF, mod_len
);
2115 memcpy(tgt_p
, &static_cca_pub_sec
, sizeof(struct cca_public_sec
));
2116 pubSec_p
= (struct cca_public_sec
*) tgt_p
;
2117 pubSec_p
->modulus_bit_len
= 8 * mod_len
;
2118 *z90cMsg_l_p
= tmp_size
- CALLER_HEADER
;
2124 ICAMEX_msg_to_type50MEX_msg(struct ica_rsa_modexpo
*icaMex_p
, int *z90cMsg_l_p
,
2125 union type50_msg
*z90cMsg_p
)
2127 int mod_len
, msg_size
, mod_tgt_len
, exp_tgt_len
, inp_tgt_len
;
2128 unsigned char *mod_tgt
, *exp_tgt
, *inp_tgt
;
2129 union type50_msg
*tmp_type50_msg
;
2131 mod_len
= icaMex_p
->inputdatalength
;
2133 msg_size
= ((mod_len
<= 128) ? TYPE50_MEB1_LEN
: TYPE50_MEB2_LEN
) +
2136 memset(z90cMsg_p
, 0, msg_size
);
2138 tmp_type50_msg
= (union type50_msg
*)
2139 ((unsigned char *) z90cMsg_p
+ CALLER_HEADER
);
2141 tmp_type50_msg
->meb1
.header
.msg_type_code
= TYPE50_TYPE_CODE
;
2143 if (mod_len
<= 128) {
2144 tmp_type50_msg
->meb1
.header
.msg_len
= TYPE50_MEB1_LEN
;
2145 tmp_type50_msg
->meb1
.keyblock_type
= TYPE50_MEB1_FMT
;
2146 mod_tgt
= tmp_type50_msg
->meb1
.modulus
;
2147 mod_tgt_len
= sizeof(tmp_type50_msg
->meb1
.modulus
);
2148 exp_tgt
= tmp_type50_msg
->meb1
.exponent
;
2149 exp_tgt_len
= sizeof(tmp_type50_msg
->meb1
.exponent
);
2150 inp_tgt
= tmp_type50_msg
->meb1
.message
;
2151 inp_tgt_len
= sizeof(tmp_type50_msg
->meb1
.message
);
2153 tmp_type50_msg
->meb2
.header
.msg_len
= TYPE50_MEB2_LEN
;
2154 tmp_type50_msg
->meb2
.keyblock_type
= TYPE50_MEB2_FMT
;
2155 mod_tgt
= tmp_type50_msg
->meb2
.modulus
;
2156 mod_tgt_len
= sizeof(tmp_type50_msg
->meb2
.modulus
);
2157 exp_tgt
= tmp_type50_msg
->meb2
.exponent
;
2158 exp_tgt_len
= sizeof(tmp_type50_msg
->meb2
.exponent
);
2159 inp_tgt
= tmp_type50_msg
->meb2
.message
;
2160 inp_tgt_len
= sizeof(tmp_type50_msg
->meb2
.message
);
2163 mod_tgt
+= (mod_tgt_len
- mod_len
);
2164 if (copy_from_user(mod_tgt
, icaMex_p
->n_modulus
, mod_len
))
2165 return SEN_RELEASED
;
2166 if (is_empty(mod_tgt
, mod_len
))
2167 return SEN_USER_ERROR
;
2168 exp_tgt
+= (exp_tgt_len
- mod_len
);
2169 if (copy_from_user(exp_tgt
, icaMex_p
->b_key
, mod_len
))
2170 return SEN_RELEASED
;
2171 if (is_empty(exp_tgt
, mod_len
))
2172 return SEN_USER_ERROR
;
2173 inp_tgt
+= (inp_tgt_len
- mod_len
);
2174 if (copy_from_user(inp_tgt
, icaMex_p
->inputdata
, mod_len
))
2175 return SEN_RELEASED
;
2176 if (is_empty(inp_tgt
, mod_len
))
2177 return SEN_USER_ERROR
;
2179 *z90cMsg_l_p
= msg_size
- CALLER_HEADER
;
2185 ICACRT_msg_to_type50CRT_msg(struct ica_rsa_modexpo_crt
*icaMsg_p
,
2186 int *z90cMsg_l_p
, union type50_msg
*z90cMsg_p
)
2188 int mod_len
, short_len
, long_len
, tmp_size
, p_tgt_len
, q_tgt_len
,
2189 dp_tgt_len
, dq_tgt_len
, u_tgt_len
, inp_tgt_len
, long_offset
;
2190 unsigned char *p_tgt
, *q_tgt
, *dp_tgt
, *dq_tgt
, *u_tgt
, *inp_tgt
,
2192 union type50_msg
*tmp_type50_msg
;
2194 mod_len
= icaMsg_p
->inputdatalength
;
2195 short_len
= mod_len
/ 2;
2196 long_len
= mod_len
/ 2 + 8;
2199 if (long_len
> 128) {
2200 memset(temp
, 0x00, sizeof(temp
));
2201 if (copy_from_user(temp
, icaMsg_p
->np_prime
, long_len
-128))
2202 return SEN_RELEASED
;
2203 if (!is_empty(temp
, 8))
2204 return SEN_NOT_AVAIL
;
2205 if (copy_from_user(temp
, icaMsg_p
->bp_key
, long_len
-128))
2206 return SEN_RELEASED
;
2207 if (!is_empty(temp
, 8))
2208 return SEN_NOT_AVAIL
;
2209 if (copy_from_user(temp
, icaMsg_p
->u_mult_inv
, long_len
-128))
2210 return SEN_RELEASED
;
2211 if (!is_empty(temp
, 8))
2212 return SEN_NOT_AVAIL
;
2213 long_offset
= long_len
- 128;
2217 tmp_size
= ((long_len
<= 64) ? TYPE50_CRB1_LEN
: TYPE50_CRB2_LEN
) +
2220 memset(z90cMsg_p
, 0, tmp_size
);
2222 tmp_type50_msg
= (union type50_msg
*)
2223 ((unsigned char *) z90cMsg_p
+ CALLER_HEADER
);
2225 tmp_type50_msg
->crb1
.header
.msg_type_code
= TYPE50_TYPE_CODE
;
2226 if (long_len
<= 64) {
2227 tmp_type50_msg
->crb1
.header
.msg_len
= TYPE50_CRB1_LEN
;
2228 tmp_type50_msg
->crb1
.keyblock_type
= TYPE50_CRB1_FMT
;
2229 p_tgt
= tmp_type50_msg
->crb1
.p
;
2230 p_tgt_len
= sizeof(tmp_type50_msg
->crb1
.p
);
2231 q_tgt
= tmp_type50_msg
->crb1
.q
;
2232 q_tgt_len
= sizeof(tmp_type50_msg
->crb1
.q
);
2233 dp_tgt
= tmp_type50_msg
->crb1
.dp
;
2234 dp_tgt_len
= sizeof(tmp_type50_msg
->crb1
.dp
);
2235 dq_tgt
= tmp_type50_msg
->crb1
.dq
;
2236 dq_tgt_len
= sizeof(tmp_type50_msg
->crb1
.dq
);
2237 u_tgt
= tmp_type50_msg
->crb1
.u
;
2238 u_tgt_len
= sizeof(tmp_type50_msg
->crb1
.u
);
2239 inp_tgt
= tmp_type50_msg
->crb1
.message
;
2240 inp_tgt_len
= sizeof(tmp_type50_msg
->crb1
.message
);
2242 tmp_type50_msg
->crb2
.header
.msg_len
= TYPE50_CRB2_LEN
;
2243 tmp_type50_msg
->crb2
.keyblock_type
= TYPE50_CRB2_FMT
;
2244 p_tgt
= tmp_type50_msg
->crb2
.p
;
2245 p_tgt_len
= sizeof(tmp_type50_msg
->crb2
.p
);
2246 q_tgt
= tmp_type50_msg
->crb2
.q
;
2247 q_tgt_len
= sizeof(tmp_type50_msg
->crb2
.q
);
2248 dp_tgt
= tmp_type50_msg
->crb2
.dp
;
2249 dp_tgt_len
= sizeof(tmp_type50_msg
->crb2
.dp
);
2250 dq_tgt
= tmp_type50_msg
->crb2
.dq
;
2251 dq_tgt_len
= sizeof(tmp_type50_msg
->crb2
.dq
);
2252 u_tgt
= tmp_type50_msg
->crb2
.u
;
2253 u_tgt_len
= sizeof(tmp_type50_msg
->crb2
.u
);
2254 inp_tgt
= tmp_type50_msg
->crb2
.message
;
2255 inp_tgt_len
= sizeof(tmp_type50_msg
->crb2
.message
);
2258 p_tgt
+= (p_tgt_len
- long_len
);
2259 if (copy_from_user(p_tgt
, icaMsg_p
->np_prime
+ long_offset
, long_len
))
2260 return SEN_RELEASED
;
2261 if (is_empty(p_tgt
, long_len
))
2262 return SEN_USER_ERROR
;
2263 q_tgt
+= (q_tgt_len
- short_len
);
2264 if (copy_from_user(q_tgt
, icaMsg_p
->nq_prime
, short_len
))
2265 return SEN_RELEASED
;
2266 if (is_empty(q_tgt
, short_len
))
2267 return SEN_USER_ERROR
;
2268 dp_tgt
+= (dp_tgt_len
- long_len
);
2269 if (copy_from_user(dp_tgt
, icaMsg_p
->bp_key
+ long_offset
, long_len
))
2270 return SEN_RELEASED
;
2271 if (is_empty(dp_tgt
, long_len
))
2272 return SEN_USER_ERROR
;
2273 dq_tgt
+= (dq_tgt_len
- short_len
);
2274 if (copy_from_user(dq_tgt
, icaMsg_p
->bq_key
, short_len
))
2275 return SEN_RELEASED
;
2276 if (is_empty(dq_tgt
, short_len
))
2277 return SEN_USER_ERROR
;
2278 u_tgt
+= (u_tgt_len
- long_len
);
2279 if (copy_from_user(u_tgt
, icaMsg_p
->u_mult_inv
+ long_offset
, long_len
))
2280 return SEN_RELEASED
;
2281 if (is_empty(u_tgt
, long_len
))
2282 return SEN_USER_ERROR
;
2283 inp_tgt
+= (inp_tgt_len
- mod_len
);
2284 if (copy_from_user(inp_tgt
, icaMsg_p
->inputdata
, mod_len
))
2285 return SEN_RELEASED
;
2286 if (is_empty(inp_tgt
, mod_len
))
2287 return SEN_USER_ERROR
;
2289 *z90cMsg_l_p
= tmp_size
- CALLER_HEADER
;
2295 convert_request(unsigned char *buffer
, int func
, unsigned short function
,
2296 int cdx
, int dev_type
, int *msg_l_p
, unsigned char *msg_p
)
2298 if (dev_type
== PCICA
) {
2299 if (func
== ICARSACRT
)
2300 return ICACRT_msg_to_type4CRT_msg(
2301 (struct ica_rsa_modexpo_crt
*) buffer
,
2302 msg_l_p
, (union type4_msg
*) msg_p
);
2304 return ICAMEX_msg_to_type4MEX_msg(
2305 (struct ica_rsa_modexpo
*) buffer
,
2306 msg_l_p
, (union type4_msg
*) msg_p
);
2308 if (dev_type
== PCICC
) {
2309 if (func
== ICARSACRT
)
2310 return ICACRT_msg_to_type6CRT_msg(
2311 (struct ica_rsa_modexpo_crt
*) buffer
,
2312 cdx
, msg_l_p
, (struct type6_msg
*)msg_p
);
2313 if (function
== PCI_FUNC_KEY_ENCRYPT
)
2314 return ICAMEX_msg_to_type6MEX_en_msg(
2315 (struct ica_rsa_modexpo
*) buffer
,
2316 cdx
, msg_l_p
, (struct type6_msg
*) msg_p
);
2318 return ICAMEX_msg_to_type6MEX_de_msg(
2319 (struct ica_rsa_modexpo
*) buffer
,
2320 cdx
, msg_l_p
, (struct type6_msg
*) msg_p
);
2322 if ((dev_type
== PCIXCC_MCL2
) ||
2323 (dev_type
== PCIXCC_MCL3
) ||
2324 (dev_type
== CEX2C
)) {
2325 if (func
== ICARSACRT
)
2326 return ICACRT_msg_to_type6CRT_msgX(
2327 (struct ica_rsa_modexpo_crt
*) buffer
,
2328 cdx
, msg_l_p
, (struct type6_msg
*) msg_p
,
2331 return ICAMEX_msg_to_type6MEX_msgX(
2332 (struct ica_rsa_modexpo
*) buffer
,
2333 cdx
, msg_l_p
, (struct type6_msg
*) msg_p
,
2336 if (dev_type
== CEX2A
) {
2337 if (func
== ICARSACRT
)
2338 return ICACRT_msg_to_type50CRT_msg(
2339 (struct ica_rsa_modexpo_crt
*) buffer
,
2340 msg_l_p
, (union type50_msg
*) msg_p
);
2342 return ICAMEX_msg_to_type50MEX_msg(
2343 (struct ica_rsa_modexpo
*) buffer
,
2344 msg_l_p
, (union type50_msg
*) msg_p
);
2350 int ext_bitlens_msg_count
= 0;
2352 unset_ext_bitlens(void)
2354 if (!ext_bitlens_msg_count
) {
2355 PRINTK("Unable to use coprocessors for extended bitlengths. "
2356 "Using PCICAs/CEX2As (if present) for extended "
2357 "bitlengths. This is not an error.\n");
2358 ext_bitlens_msg_count
++;
2364 convert_response(unsigned char *response
, unsigned char *buffer
,
2365 int *respbufflen_p
, unsigned char *resp_buff
)
2367 struct ica_rsa_modexpo
*icaMsg_p
= (struct ica_rsa_modexpo
*) buffer
;
2368 struct error_hdr
*errh_p
= (struct error_hdr
*) response
;
2369 struct type80_hdr
*t80h_p
= (struct type80_hdr
*) response
;
2370 struct type84_hdr
*t84h_p
= (struct type84_hdr
*) response
;
2371 struct type86_fmt2_msg
*t86m_p
= (struct type86_fmt2_msg
*) response
;
2372 int reply_code
, service_rc
, service_rs
, src_l
;
2373 unsigned char *src_p
, *tgt_p
;
2374 struct CPRB
*cprb_p
;
2375 struct CPRBX
*cprbx_p
;
2382 switch (errh_p
->type
) {
2383 case TYPE82_RSP_CODE
:
2384 case TYPE88_RSP_CODE
:
2385 reply_code
= errh_p
->reply_code
;
2386 src_p
= (unsigned char *)errh_p
;
2387 PRINTK("Hardware error: Type %02X Message Header: "
2388 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
2390 src_p
[0], src_p
[1], src_p
[2], src_p
[3],
2391 src_p
[4], src_p
[5], src_p
[6], src_p
[7]);
2393 case TYPE80_RSP_CODE
:
2394 src_l
= icaMsg_p
->outputdatalength
;
2395 src_p
= response
+ (int)t80h_p
->len
- src_l
;
2397 case TYPE84_RSP_CODE
:
2398 src_l
= icaMsg_p
->outputdatalength
;
2399 src_p
= response
+ (int)t84h_p
->len
- src_l
;
2401 case TYPE86_RSP_CODE
:
2402 reply_code
= t86m_p
->header
.reply_code
;
2403 if (reply_code
!= 0)
2405 cprb_p
= (struct CPRB
*)
2406 (response
+ sizeof(struct type86_fmt2_msg
));
2407 cprbx_p
= (struct CPRBX
*) cprb_p
;
2408 if (cprb_p
->cprb_ver_id
!= 0x02) {
2409 le2toI(cprb_p
->ccp_rtcode
, &service_rc
);
2410 if (service_rc
!= 0) {
2411 le2toI(cprb_p
->ccp_rscode
, &service_rs
);
2412 if ((service_rc
== 8) && (service_rs
== 66))
2413 PDEBUG("Bad block format on PCICC\n");
2414 else if ((service_rc
== 8) && (service_rs
== 65))
2415 PDEBUG("Probably an even modulus on "
2417 else if ((service_rc
== 8) && (service_rs
== 770)) {
2418 PDEBUG("Invalid key length on PCICC\n");
2419 unset_ext_bitlens();
2420 return REC_USE_PCICA
;
2422 else if ((service_rc
== 8) && (service_rs
== 783)) {
2423 PDEBUG("Extended bitlengths not enabled"
2425 unset_ext_bitlens();
2426 return REC_USE_PCICA
;
2429 PRINTK("service rc/rs (PCICC): %d/%d\n",
2430 service_rc
, service_rs
);
2431 return REC_OPERAND_INV
;
2433 src_p
= (unsigned char *)cprb_p
+ sizeof(struct CPRB
);
2435 le2toI(src_p
, &src_l
);
2439 service_rc
= (int)cprbx_p
->ccp_rtcode
;
2440 if (service_rc
!= 0) {
2441 service_rs
= (int) cprbx_p
->ccp_rscode
;
2442 if ((service_rc
== 8) && (service_rs
== 66))
2443 PDEBUG("Bad block format on PCIXCC\n");
2444 else if ((service_rc
== 8) && (service_rs
== 65))
2445 PDEBUG("Probably an even modulus on "
2447 else if ((service_rc
== 8) && (service_rs
== 770)) {
2448 PDEBUG("Invalid key length on PCIXCC\n");
2449 unset_ext_bitlens();
2450 return REC_USE_PCICA
;
2452 else if ((service_rc
== 8) && (service_rs
== 783)) {
2453 PDEBUG("Extended bitlengths not enabled"
2455 unset_ext_bitlens();
2456 return REC_USE_PCICA
;
2459 PRINTK("service rc/rs (PCIXCC): %d/%d\n",
2460 service_rc
, service_rs
);
2461 return REC_OPERAND_INV
;
2463 src_p
= (unsigned char *)
2464 cprbx_p
+ sizeof(struct CPRBX
);
2466 src_l
= (int)(*((short *) src_p
));
2472 src_p
= (unsigned char *)errh_p
;
2473 PRINTK("Unrecognized Message Header: "
2474 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
2475 src_p
[0], src_p
[1], src_p
[2], src_p
[3],
2476 src_p
[4], src_p
[5], src_p
[6], src_p
[7]);
2477 return REC_BAD_MESSAGE
;
2481 switch (reply_code
) {
2482 case REP82_ERROR_MACHINE_FAILURE
:
2483 if (errh_p
->type
== TYPE82_RSP_CODE
)
2484 PRINTKW("Machine check failure\n");
2486 PRINTKW("Module failure\n");
2487 return REC_HARDWAR_ERR
;
2488 case REP82_ERROR_OPERAND_INVALID
:
2489 return REC_OPERAND_INV
;
2490 case REP88_ERROR_MESSAGE_MALFORMD
:
2491 PRINTKW("Message malformed\n");
2492 return REC_OPERAND_INV
;
2493 case REP82_ERROR_OPERAND_SIZE
:
2494 return REC_OPERAND_SIZE
;
2495 case REP82_ERROR_EVEN_MOD_IN_OPND
:
2496 return REC_EVEN_MOD
;
2497 case REP82_ERROR_MESSAGE_TYPE
:
2498 return WRONG_DEVICE_TYPE
;
2499 case REP82_ERROR_TRANSPORT_FAIL
:
2500 PRINTKW("Transport failed (APFS = %02X%02X%02X%02X)\n",
2501 t86m_p
->apfs
[0], t86m_p
->apfs
[1],
2502 t86m_p
->apfs
[2], t86m_p
->apfs
[3]);
2503 return REC_HARDWAR_ERR
;
2505 PRINTKW("reply code = %d\n", reply_code
);
2506 return REC_HARDWAR_ERR
;
2509 if (service_rc
!= 0)
2510 return REC_OPERAND_INV
;
2512 if ((src_l
> icaMsg_p
->outputdatalength
) ||
2513 (src_l
> RESPBUFFSIZE
) ||
2515 return REC_OPERAND_SIZE
;
2517 PDEBUG("Length returned = %d\n", src_l
);
2518 tgt_p
= resp_buff
+ icaMsg_p
->outputdatalength
- src_l
;
2519 memcpy(tgt_p
, src_p
, src_l
);
2520 if ((errh_p
->type
== TYPE86_RSP_CODE
) && (resp_buff
< tgt_p
)) {
2521 memset(resp_buff
, 0, icaMsg_p
->outputdatalength
- src_l
);
2522 if (pad_msg(resp_buff
, icaMsg_p
->outputdatalength
, src_l
))
2523 return REC_INVALID_PAD
;
2525 *respbufflen_p
= icaMsg_p
->outputdatalength
;
2526 if (*respbufflen_p
== 0)
2527 PRINTK("Zero *respbufflen_p\n");