1
10
13
14
20
21
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
115
120
121
124
125
133
134
135
136
137
138
142
143
144
145
146
147
148
149
150
151
155
156
157
158
159
160
161
162
163
164
168
169
170
171
172
173
174
175
176
177
178
182
183
184
185
186
187
191
192
193
194
195
196
197
198
199
200
201
205
206
207
208
209
210
211
212
213
...
...
...
#define NX_SECURE_SOURCE_CODE
#include "nx_secure_x509.h"
...
...
UINT _nx_secure_x509_pkcs7_decode(const UCHAR *signature_pointer, UINT signature_length,
const UCHAR **signature_oid, UINT *signature_oid_length,
const UCHAR **hash_data, UINT *hash_length)
{
UINT i;
USHORT tlv_type;
USHORT tlv_type_class;
ULONG tlv_length;
const UCHAR *tlv_data = NX_CRYPTO_NULL;
ULONG header_length;
ULONG seq_length;
UINT status;
const UCHAR *signature_data = NX_CRYPTO_NULL;
ULONG remaining_length;
/* ... */
signature_data = signature_pointer;
remaining_length = signature_length;
if (signature_data[1] >= 2)
{
return(NX_SECURE_X509_PKCS7_PARSING_FAILED);
}if (signature_data[1] >= 2) { ... }
/* ... */
i = 2;
while (i < signature_length)
{
if (signature_data[i] == 0x00)
{
break;
}if (signature_data[i] == 0x00) { ... }
i++;
}while (i < signature_length) { ... }
i++;
if (i >= signature_length)
{
return(NX_SECURE_X509_PKCS7_PARSING_FAILED);
}if (i >= signature_length) { ... }
signature_data = &signature_data[i];
remaining_length -= i;
status = _nx_secure_x509_asn1_tlv_block_parse(signature_data, &remaining_length, &tlv_type, &tlv_type_class, &tlv_length, &tlv_data, &header_length);
if (status != 0 || tlv_type != NX_SECURE_ASN_TAG_SEQUENCE || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL)
{
return(NX_SECURE_X509_PKCS7_PARSING_FAILED);
}if (status != 0 || tlv_type != NX_SECURE_ASN_TAG_SEQUENCE || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL) { ... }
signature_data = tlv_data;
remaining_length = tlv_length;
status = _nx_secure_x509_asn1_tlv_block_parse(signature_data, &remaining_length, &tlv_type, &tlv_type_class, &tlv_length, &tlv_data, &header_length);
if (status != 0 || tlv_type != NX_SECURE_ASN_TAG_SEQUENCE || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL)
{
return(NX_SECURE_X509_PKCS7_PARSING_FAILED);
}if (status != 0 || tlv_type != NX_SECURE_ASN_TAG_SEQUENCE || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL) { ... }
signature_data = tlv_data;
seq_length = tlv_length;
do
{
status = _nx_secure_x509_asn1_tlv_block_parse(signature_data, &seq_length, &tlv_type, &tlv_type_class, &tlv_length, &tlv_data, &header_length);
if (status != 0 || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL)
{
return(NX_SECURE_X509_PKCS7_PARSING_FAILED);
}if (status != 0 || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL) { ... }
signature_data = &signature_data[tlv_length + header_length];
if (tlv_type == NX_SECURE_ASN_TAG_NULL)
{
break;
}if (tlv_type == NX_SECURE_ASN_TAG_NULL) { ... }
*signature_oid = tlv_data;
*signature_oid_length = tlv_length;
...} while (tlv_type == NX_SECURE_ASN_TAG_OID);
status = _nx_secure_x509_asn1_tlv_block_parse(signature_data, &remaining_length, &tlv_type, &tlv_type_class, &tlv_length, &tlv_data, &header_length);
if (status != 0 || tlv_type != NX_SECURE_ASN_TAG_OCTET_STRING || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL)
{
return(NX_SECURE_X509_PKCS7_PARSING_FAILED);
}if (status != 0 || tlv_type != NX_SECURE_ASN_TAG_OCTET_STRING || tlv_type_class != NX_SECURE_ASN_TAG_CLASS_UNIVERSAL) { ... }
*hash_data = tlv_data;
*hash_length = tlv_length;
return(NX_SECURE_X509_SUCCESS);
}{ ... }