1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  *  Copyright IBM Corp. 2001, 2006
4  *  Author(s): Robert Burroughs
5  *	       Eric Rossman (edrossma@us.ibm.com)
6  *
7  *  Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
8  *  Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
9  */
10 
11 #ifndef _ZCRYPT_CEX2A_H_
12 #define _ZCRYPT_CEX2A_H_
13 
14 /**
15  * The type 50 message family is associated with CEXxA cards.
16  *
17  * The four members of the family are described below.
18  *
19  * Note that all unsigned char arrays are right-justified and left-padded
20  * with zeroes.
21  *
22  * Note that all reserved fields must be zeroes.
23  */
24 struct type50_hdr {
25 	unsigned char	reserved1;
26 	unsigned char	msg_type_code;	/* 0x50 */
27 	unsigned short	msg_len;
28 	unsigned char	reserved2;
29 	unsigned char	ignored;
30 	unsigned short	reserved3;
31 } __packed;
32 
33 #define TYPE50_TYPE_CODE	0x50
34 
35 #define TYPE50_MEB1_FMT		0x0001
36 #define TYPE50_MEB2_FMT		0x0002
37 #define TYPE50_MEB3_FMT		0x0003
38 #define TYPE50_CRB1_FMT		0x0011
39 #define TYPE50_CRB2_FMT		0x0012
40 #define TYPE50_CRB3_FMT		0x0013
41 
42 /* Mod-Exp, with a small modulus */
43 struct type50_meb1_msg {
44 	struct type50_hdr header;
45 	unsigned short	keyblock_type;	/* 0x0001 */
46 	unsigned char	reserved[6];
47 	unsigned char	exponent[128];
48 	unsigned char	modulus[128];
49 	unsigned char	message[128];
50 } __packed;
51 
52 /* Mod-Exp, with a large modulus */
53 struct type50_meb2_msg {
54 	struct type50_hdr header;
55 	unsigned short	keyblock_type;	/* 0x0002 */
56 	unsigned char	reserved[6];
57 	unsigned char	exponent[256];
58 	unsigned char	modulus[256];
59 	unsigned char	message[256];
60 } __packed;
61 
62 /* Mod-Exp, with a larger modulus */
63 struct type50_meb3_msg {
64 	struct type50_hdr header;
65 	unsigned short	keyblock_type;	/* 0x0003 */
66 	unsigned char	reserved[6];
67 	unsigned char	exponent[512];
68 	unsigned char	modulus[512];
69 	unsigned char	message[512];
70 } __packed;
71 
72 /* CRT, with a small modulus */
73 struct type50_crb1_msg {
74 	struct type50_hdr header;
75 	unsigned short	keyblock_type;	/* 0x0011 */
76 	unsigned char	reserved[6];
77 	unsigned char	p[64];
78 	unsigned char	q[64];
79 	unsigned char	dp[64];
80 	unsigned char	dq[64];
81 	unsigned char	u[64];
82 	unsigned char	message[128];
83 } __packed;
84 
85 /* CRT, with a large modulus */
86 struct type50_crb2_msg {
87 	struct type50_hdr header;
88 	unsigned short	keyblock_type;	/* 0x0012 */
89 	unsigned char	reserved[6];
90 	unsigned char	p[128];
91 	unsigned char	q[128];
92 	unsigned char	dp[128];
93 	unsigned char	dq[128];
94 	unsigned char	u[128];
95 	unsigned char	message[256];
96 } __packed;
97 
98 /* CRT, with a larger modulus */
99 struct type50_crb3_msg {
100 	struct type50_hdr header;
101 	unsigned short	keyblock_type;	/* 0x0013 */
102 	unsigned char	reserved[6];
103 	unsigned char	p[256];
104 	unsigned char	q[256];
105 	unsigned char	dp[256];
106 	unsigned char	dq[256];
107 	unsigned char	u[256];
108 	unsigned char	message[512];
109 } __packed;
110 
111 /**
112  * The type 80 response family is associated with a CEXxA cards.
113  *
114  * Note that all unsigned char arrays are right-justified and left-padded
115  * with zeroes.
116  *
117  * Note that all reserved fields must be zeroes.
118  */
119 
120 #define TYPE80_RSP_CODE 0x80
121 
122 struct type80_hdr {
123 	unsigned char	reserved1;
124 	unsigned char	type;		/* 0x80 */
125 	unsigned short	len;
126 	unsigned char	code;		/* 0x00 */
127 	unsigned char	reserved2[3];
128 	unsigned char	reserved3[8];
129 } __packed;
130 
131 int zcrypt_cex2a_init(void);
132 void zcrypt_cex2a_exit(void);
133 
134 #endif /* _ZCRYPT_CEX2A_H_ */
135