1
10
13
14
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
118
119
123
124
125
126
127
128
129
130
131
135
136
140
141
142
143
144
145
146
147
151
152
153
154
155
156
157
158
159
160
164
165
169
170
171
172
173
174
179
180
181
182
183
184
185
186
187
191
192
196
197
198
199
200
201
202
203
204
205
209
210
214
215
216
217
218
219
224
225
226
227
228
...
...
...
#define NX_SECURE_SOURCE_CODE
#include "nx_secure_x509.h"
#ifdef NX_SECURE_ENABLE_ECC_CIPHERSUITE
...
UINT _nx_secure_x509_ec_private_key_parse(const UCHAR *buffer, UINT length,
UINT *bytes_processed,
NX_SECURE_EC_PRIVATE_KEY *ec_key)
{
USHORT tlv_type;
USHORT tlv_type_class;
ULONG tlv_length;
ULONG seq_length;
const UCHAR *tlv_data;
ULONG header_length;
UINT status;
USHORT version;
status = _nx_secure_x509_asn1_tlv_block_parse(buffer, (ULONG *)&length, &tlv_type, &tlv_type_class, &tlv_length, &tlv_data, &header_length);
if (status != 0)
{
return(status);
}if (status != 0) { ... }
if (tlv_type != NX_SECURE_ASN_TAG_SEQUENCE || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL)
{
return(NX_SECURE_X509_INVALID_CERTIFICATE_SEQUENCE);
}if (tlv_type != NX_SECURE_ASN_TAG_SEQUENCE || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL) { ... }
*bytes_processed = header_length;
length = tlv_length;
status = _nx_secure_x509_asn1_tlv_block_parse(tlv_data, (ULONG *)&length, &tlv_type, &tlv_type_class, &tlv_length, &tlv_data, &header_length);
if (status != 0)
{
return(status);
}if (status != 0) { ... }
if (tlv_type != NX_SECURE_ASN_TAG_INTEGER || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL)
{
return(NX_SECURE_PKCS1_INVALID_PRIVATE_KEY);
}if (tlv_type != NX_SECURE_ASN_TAG_INTEGER || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL) { ... }
*bytes_processed += (header_length + tlv_length);
version = tlv_data[0];
if (version != 0x01)
{
return(NX_SECURE_PKCS1_INVALID_PRIVATE_KEY);
}if (version != 0x01) { ... }
tlv_data = &tlv_data[tlv_length];
status = _nx_secure_x509_asn1_tlv_block_parse(tlv_data, (ULONG *)&length, &tlv_type, &tlv_type_class, &tlv_length, &tlv_data, &header_length);
if (status != 0)
{
return(status);
}if (status != 0) { ... }
if (tlv_type != NX_SECURE_ASN_TAG_OCTET_STRING || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL)
{
return(NX_SECURE_PKCS1_INVALID_PRIVATE_KEY);
}if (tlv_type != NX_SECURE_ASN_TAG_OCTET_STRING || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL) { ... }
*bytes_processed += (header_length + tlv_length);
if (ec_key != NULL)
{
ec_key -> nx_secure_ec_private_key = tlv_data;
ec_key -> nx_secure_ec_private_key_length = (USHORT)tlv_length;
}if (ec_key != NULL) { ... }
tlv_data = &tlv_data[tlv_length];
status = _nx_secure_x509_asn1_tlv_block_parse(tlv_data, (ULONG *)&length, &tlv_type, &tlv_type_class, &tlv_length, &tlv_data, &header_length);
if (status != 0)
{
return(status);
}if (status != 0) { ... }
if (tlv_type != 0 || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_CONTEXT)
{
return(NX_SECURE_PKCS1_INVALID_PRIVATE_KEY);
}if (tlv_type != 0 || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_CONTEXT) { ... }
*bytes_processed += header_length;
seq_length = tlv_length;
status = _nx_secure_x509_asn1_tlv_block_parse(tlv_data, &seq_length, &tlv_type, &tlv_type_class, &tlv_length, &tlv_data, &header_length);
if (status != 0)
{
return(status);
}if (status != 0) { ... }
if (tlv_type != NX_SECURE_ASN_TAG_OID || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL)
{
return(NX_SECURE_PKCS1_INVALID_PRIVATE_KEY);
}if (tlv_type != NX_SECURE_ASN_TAG_OID || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL) { ... }
*bytes_processed += (header_length + tlv_length);
if (ec_key != NULL)
{
_nx_secure_x509_oid_parse(tlv_data, tlv_length, &ec_key -> nx_secure_ec_named_curve);
}if (ec_key != NULL) { ... }
return(NX_SECURE_X509_SUCCESS);
}{ ... }
#endif... /* ... */