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#ifndef _ZCRYPT_MSGTYPE6_H_
28#define _ZCRYPT_MSGTYPE6_H_
29
30#include <asm/zcrypt.h>
31
32#define MSGTYPE06_NAME "zcrypt_msgtype6"
33#define MSGTYPE06_VARIANT_DEFAULT 0
34#define MSGTYPE06_VARIANT_NORNG 1
35
36#define MSGTYPE06_MAX_MSG_SIZE (12*1024)
37
38
39
40
41
42
43
44
45
46struct type6_hdr {
47 unsigned char reserved1;
48 unsigned char type;
49 unsigned char reserved2[2];
50 unsigned char right[4];
51 unsigned char reserved3[2];
52 unsigned char reserved4[2];
53 unsigned char apfs[4];
54 unsigned int offset1;
55 unsigned int offset2;
56 unsigned int offset3;
57 unsigned int offset4;
58 unsigned char agent_id[16];
59
60
61
62
63
64
65 unsigned char rqid[2];
66 unsigned char reserved5[2];
67 unsigned char function_code[2];
68 unsigned char reserved6[2];
69 unsigned int ToCardLen1;
70 unsigned int ToCardLen2;
71 unsigned int ToCardLen3;
72 unsigned int ToCardLen4;
73 unsigned int FromCardLen1;
74 unsigned int FromCardLen2;
75 unsigned int FromCardLen3;
76 unsigned int FromCardLen4;
77} __packed;
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92struct type86_hdr {
93 unsigned char reserved1;
94 unsigned char type;
95 unsigned char format;
96 unsigned char reserved2;
97 unsigned char reply_code;
98 unsigned char reserved3[3];
99} __packed;
100
101#define TYPE86_RSP_CODE 0x86
102#define TYPE86_FMT2 0x02
103
104struct type86_fmt2_ext {
105 unsigned char reserved[4];
106 unsigned char apfs[4];
107 unsigned int count1;
108 unsigned int offset1;
109 unsigned int count2;
110 unsigned int offset2;
111 unsigned int count3;
112 unsigned int offset3;
113 unsigned int count4;
114 unsigned int offset4;
115} __packed;
116
117
118
119
120
121
122
123static inline void rng_type6CPRB_msgX(struct ap_device *ap_dev,
124 struct ap_message *ap_msg,
125 unsigned random_number_length)
126{
127 struct {
128 struct type6_hdr hdr;
129 struct CPRBX cprbx;
130 char function_code[2];
131 short int rule_length;
132 char rule[8];
133 short int verb_length;
134 short int key_length;
135 } __packed * msg = ap_msg->message;
136 static struct type6_hdr static_type6_hdrX = {
137 .type = 0x06,
138 .offset1 = 0x00000058,
139 .agent_id = {'C', 'A'},
140 .function_code = {'R', 'L'},
141 .ToCardLen1 = sizeof(*msg) - sizeof(msg->hdr),
142 .FromCardLen1 = sizeof(*msg) - sizeof(msg->hdr),
143 };
144 static struct CPRBX local_cprbx = {
145 .cprb_len = 0x00dc,
146 .cprb_ver_id = 0x02,
147 .func_id = {0x54, 0x32},
148 .req_parml = sizeof(*msg) - sizeof(msg->hdr) -
149 sizeof(msg->cprbx),
150 .rpl_msgbl = sizeof(*msg) - sizeof(msg->hdr),
151 };
152
153 msg->hdr = static_type6_hdrX;
154 msg->hdr.FromCardLen2 = random_number_length,
155 msg->cprbx = local_cprbx;
156 msg->cprbx.rpl_datal = random_number_length,
157 msg->cprbx.domain = AP_QID_QUEUE(ap_dev->qid);
158 memcpy(msg->function_code, msg->hdr.function_code, 0x02);
159 msg->rule_length = 0x0a;
160 memcpy(msg->rule, "RANDOM ", 8);
161 msg->verb_length = 0x02;
162 msg->key_length = 0x02;
163 ap_msg->length = sizeof(*msg);
164}
165
166int zcrypt_msgtype6_init(void);
167void zcrypt_msgtype6_exit(void);
168
169#endif
170