1
/**************************************************************************
2
*** COPYRIGHT (c) 2002 by TransNexus, Inc. ***
4
*** This software is property of TransNexus, Inc. ***
5
*** This software is freely available under license from TransNexus. ***
6
*** The license terms and conditions for free use of this software by ***
7
*** third parties are defined in the OSP Toolkit Software License ***
8
*** Agreement (LICENSE.txt). Any use of this software by third ***
9
*** parties, which does not comply with the terms and conditions of the ***
10
*** OSP Toolkit Software License Agreement is prohibited without ***
11
*** the prior, express, written consent of TransNexus, Inc. ***
13
*** Thank you for using the OSP ToolKit(TM). Please report any bugs, ***
14
*** suggestions or feedback to support@transnexus.com ***
16
**************************************************************************/
25
* ospasn1.h - Constants and typedefs for ASN.1
31
#include "osp/ospasn1ids.h"
33
#define OSPC_ASN1_SIGNERINFO_VERSION 1
35
/* ASN1 ENCODED DATA KNOWN TO THE PARSER THAT GETS ACCESSED */
36
#define OSPC_ASN1_DATAREFID_CERTIFICATE 0x01
37
#define OSPC_ASN1_DATAREFID_CERT_TBSCERTIFICATE 0x01
38
#define OSPC_ASN1_DATAREFID_CERT_EXPLICIT_VERSION 0x01
39
#define OSPC_ASN1_DATAREFID_CERT_VERSION 0x01
40
#define OSPC_ASN1_DATAREFID_CERT_SERIALNUMBER 0x02
41
#define OSPC_ASN1_DATAREFID_CERT_SIGNATURE_TBS 0x03
42
#define OSPC_ASN1_DATAREFID_CERT_ISSUER 0x04
43
#define OSPC_ASN1_DATAREFID_CERT_VALIDITY 0x05
44
#define OSPC_ASN1_DATAREFID_CERT_NOTBEFORE 0x01
45
#define OSPC_ASN1_DATAREFID_CERT_NOTAFTER 0x02
46
#define OSPC_ASN1_DATAREFID_CERT_SUBJECT 0x06
47
#define OSPC_ASN1_DATAREFID_CERT_SUBJPUBKEYINFO 0x07
48
#define OSPC_ASN1_DATAREFID_CERT_PUBLICKEYALG 0x01
49
#define OSPC_ASN1_DATAREFID_CERT_PUBLICKEY 0x02
50
#define OSPC_ASN1_DATAREFID_CERT_ISSUERUNIQUEID 0x08
51
#define OSPC_ASN1_DATAREFID_CERT_SUBJECTUNIQUEID 0x09
52
#define OSPC_ASN1_DATAREFID_CERT_EXPLICIT_EXTENSIONS 0x0a
53
#define OSPC_ASN1_DATAREFID_CERT_EXTENSIONS 0x01
54
#define OSPC_ASN1_DATAREFID_CERT_EXTENSION 0x01
55
#define OSPC_ASN1_DATAREFID_CERT_SIGNATUREALGORITHM 0x02
56
#define OSPC_ASN1_DATAREFID_CERT_SIGNATURE 0x03
58
/* ASN1 ENCODED CONTENT INFO ELEMENT */
59
#define OSPC_ASN1_DATAREFID_CONTENTINFO 0x02
60
#define OSPC_ASN1_DATAREFID_CNTINF_CONTENTTYPE 0x01
61
#define OSPC_ASN1_DATAREFID_CNTINF_EXPLICIT_CONTENT 0x02
62
#define OSPC_ASN1_DATAREFID_CNTINF_CONTENT 0x01
65
/* ASN1 ENCODED SIGNED DATA ELEMENTS */
66
#define OSPC_ASN1_DATAREFID_SIGNEDDATA 0x03
67
#define OSPC_ASN1_DATAREFID_SGNDAT_VERSION 0x01
68
#define OSPC_ASN1_DATAREFID_SGNDAT_DIGESTALGORITHMS 0x02
69
#define OSPC_ASN1_DATAREFID_SGNDAT_DIGESTALGORITHM 0x01
70
#define OSPC_ASN1_DATAREFID_SGNDAT_CONTENTINFO 0x03
71
#define OSPC_ASN1_DATAREFID_SGNDAT_CERTIFICATES 0x04
72
#define OSPC_ASN1_DATAREFID_SGNDAT_CERTIFICATE 0x01
73
#define OSPC_ASN1_DATAREFID_SGNDAT_CERTREVLISTS 0x05
74
#define OSPC_ASN1_DATAREFID_SGNDAT_CERTREVLIST 0x01
75
#define OSPC_ASN1_DATAREFID_SGNDAT_SIGNERINFOS 0x06
76
#define OSPC_ASN1_DATAREFID_SGNDAT_SIGNERINFO 0x01
78
/* ASN1 ENCODED SIGNER INFO ELEMENTS */
79
#define OSPC_ASN1_DATAREFID_SIGNERINFO 0x04
80
#define OSPC_ASN1_DATAREFID_SGNINF_VERSION 0x01
81
#define OSPC_ASN1_DATAREFID_SGNINF_ISSUERANDSERNUM 0x02
82
#define OSPC_ASN1_DATAREFID_SGNINF_ISSUER 0x01
83
#define OSPC_ASN1_DATAREFID_SGNINF_SERIALNUMBER 0x02
84
#define OSPC_ASN1_DATAREFID_SGNINF_DIGESTALGORITHM 0x03
85
#define OSPC_ASN1_DATAREFID_SGNINF_AUTHATTRIBUTES 0x04
86
#define OSPC_ASN1_DATAREFID_SGNINF_AUTHATTRIBUTE 0x01
87
#define OSPC_ASN1_DATAREFID_SGNINF_DIGENCRYPTALG 0x05
88
#define OSPC_ASN1_DATAREFID_SGNINF_ENCRYPTEDDIGEST 0x06
89
#define OSPC_ASN1_DATAREFID_SGNINF_UNAUTHATTRIBUTES 0x07
90
#define OSPC_ASN1_DATAREFID_SGNINF_UNAUTHATTRIBUTE 0x01
92
/* ASN1 ENCODED SIGNER INFO ELEMENTS */
93
#define OSPC_ASN1_DATAREFID_DIGESTINFO 0x05
94
#define OSPC_ASN1_DATAREFID_DIGINF_DIGESTALGORITHM 0x01
95
#define OSPC_ASN1_DATAREFID_DIGINF_DIGEST 0x02
97
/* ASN1 ENCODED ALGORITHM ID ELEMENTS */
98
#define OSPC_ASN1_DATAREFID_ALGORITHMID 0x06
99
#define OSPC_ASN1_DATAREFID_ALGID_OID 0x01
100
#define OSPC_ASN1_DATAREFID_ALGID_ATTRTYPEANDVAL 0x02
101
#define OSPC_ASN1_DATAREFID_ALGID_TERMINATOR 0x03
103
/* ASN1 ENCODED PRIVATE KEY INFO ELEMENTS */
104
#define OSPC_ASN1_DATAREFID_PRIVATEKEYINFO 0x07
105
#define OSPC_ASN1_DATAREFID_PVTKEYINF_VERSION 0x01
106
#define OSPC_ASN1_DATAREFID_PVTKEYINF_ALGORITHM 0x02
107
#define OSPC_ASN1_DATAREFID_PVTKEYINF_PRIVATEKEY 0x03
108
#define OSPC_ASN1_DATAREFID_PVTKEYINF_ATTRIBUTES 0x04
109
#define OSPC_ASN1_DATAREFID_PVTKEYINF_ATTRIBUTE 0x01
111
/* These are defined for parsing a PKCS#10 certificate request.
112
* A certificate request contains a CertificateRequestInfo structure
113
* ( with the version, subject, public key, and optional attributes ) and
116
#define OSPC_ASN1_DATAREFID_CERTREQ 0x01
117
#define OSPC_ASN1_DATAREFID_CERTREQINFO 0x01
118
#define OSPC_ASN1_DATAREFID_CERTREQINFO_VERSION 0x01
119
#define OSPC_ASN1_DATAREFID_CERTREQINFO_SUBJECT 0x02
120
#define OSPC_ASN1_DATAREFID_CERTREQINFO_SUBJPUBKEYINFO 0x03
121
#define OSPC_ASN1_DATAREFID_CERTREQINFO_ATTRIBUTES 0x04
122
#define OSPC_ASN1_DATAREFID_CERTREQ_SIGNATURE_ALGORITHM 0x02
123
#define OSPC_ASN1_DATAREFID_CERTREQ_SIGNATURE 0x03
125
/* The definition for a subjectPublicKeyInfo is separate from
126
* that of those for the PKCS#10 certificate request and X.509 certificates.
128
#define OSPC_ASN1_DATAREFID_SUBJPUBKEYINFO 0x01
130
/* NOTE: THE OSPEASN1PARSETABLEID enum list must stay in sync with
131
ospgParseTableIndex[]. The enum values are the index into the
132
ParseTableIndex for the parse table array.
135
typedef enum _OSPEASN1PARSETABLEID
137
/* DO NOT CHANGE THIS TABLE WITHOUT UPDATING THE POSITIONS OF
138
THE PARSE TABLES IN ospgParseTableIndex */
139
OSPEPTID_NOTDEFINED=0,
140
OSPEPTID_CERTIFICATE,
141
OSPEPTID_TBSCERTIFICATE,
142
OSPEPTID_SIGNATUREALGORITHM,
143
OSPEPTID_DERALGORITHMID,
144
OSPEPTID_EXPLICIT_VERSION,
146
OSPEPTID_CERTSERIALNUM,
148
OSPEPTID_RDNSEQUENCE,
150
OSPEPTID_ATTRTYPEANDVAL,
151
OSPEPTID_ATTRIBUTETYPE,
152
OSPEPTID_ATTRIBUTEVALUE,
156
OSPEPTID_SUBJPUBKEYINFO,
157
OSPEPTID_ISSUERUNIQUEID,
158
OSPEPTID_SUBJECTUNIQUEID,
160
OSPEPTID_EXPLICIT_EXTENSIONS,
163
OSPEPTID_CONTENTINFO_DATA,
164
OSPEPTID_EXPLICIT_DATA,
166
OSPEPTID_CONTENTINFO_SIGNEDDATA,
167
OSPEPTID_EXPLICIT_SIGNEDDATA,
169
OSPEPTID_DIGESTALGORITHMS,
170
OSPEPTID_CERTIFICATES,
171
OSPEPTID_CERTREVLISTS,
172
OSPEPTID_CERTREVLIST,
173
OSPEPTID_SIGNERINFOS,
175
OSPEPTID_ENCRYPTEDDIGEST,
176
OSPEPTID_AUTHATTRIBUTES,
177
OSPEPTID_UNAUTHATTRIBUTES,
178
OSPEPTID_ISSUERANDSERNUM,
180
OSPEPTID_ALGORITHMID,
181
OSPEPTID_PRIVATEKEYINFO,
182
OSPEPTID_PRIVATEKEYINFO_ATTRIBUTES,
184
/* These were added for parsing the certificate requests used for
185
* enrolling devices; they represent the same entities described
189
OSPEPTID_CERTREQINFO,
192
} OSPEASN1PARSETABLEID;
194
typedef enum _OSPEASN1DATAREFID
196
/* CERTIFICATE ELEMENTS THAT GET ASKED FOR */
197
OSPEDRID_CERTIFICATE,
198
OSPEDRID_CERT_TBSCERTIFICATE,
199
OSPEDRID_CERT_SIGNATUREALGORITHM,
200
OSPEDRID_CERT_SIGNATURE,
201
OSPEDRID_CERT_EXPLICIT_VERSION,
202
OSPEDRID_CERT_VERSION,
203
OSPEDRID_CERT_SERIALNUMBER,
204
OSPEDRID_CERT_SIGNATURE_TBS,
205
OSPEDRID_CERT_ISSUER,
206
OSPEDRID_CERT_NOTBEFORE,
207
OSPEDRID_CERT_NOTAFTER,
208
OSPEDRID_CERT_SUBJECT,
209
OSPEDRID_CERT_SUBJPUBKEYINFO,
210
OSPEDRID_CERT_PUBLICKEYALG,
211
OSPEDRID_CERT_PUBLICKEY,
212
OSPEDRID_CERT_ISSUERUNIQUEID,
213
OSPEDRID_CERT_SUBJECTUNIQUEID,
214
OSPEDRID_CERT_EXPLICIT_EXTENSIONS,
215
OSPEDRID_CERT_EXTENSIONS,
216
OSPEDRID_CERT_EXTENSION,
218
/* SIGNED DATA ELEMENTS THAT GET ASKED FOR */
220
OSPEDRID_SGNDAT_VERSION,
221
OSPEDRID_SGNDAT_DIGESTALGORITHMS,
222
OSPEDRID_SGNDAT_DIGESTALGORITHM,
223
OSPEDRID_SGNDAT_CONTENTINFO,
224
OSPEDRID_SGNDAT_CERTIFICATES,
225
OSPEDRID_SGNDAT_CERTIFICATE,
226
OSPEDRID_SGNDAT_CERTIFICATE_SUBJPUBKEYINFO,
227
OSPEDRID_SGNDAT_CERTREVLISTS,
228
OSPEDRID_SGNDAT_CERTREVLIST,
229
OSPEDRID_SGNDAT_SIGNERINFOS,
230
OSPEDRID_SGNDAT_SIGNERINFO,
233
/* SIGNED INFO DATA ELEMENTS */
235
OSPEDRID_SGNINF_VERSION,
236
OSPEDRID_SGNINF_ISSUER ,
237
OSPEDRID_SGNINF_SERIALNUMBER,
238
OSPEDRID_SGNINF_DIGESTALGORITHM ,
239
OSPEDRID_SGNINF_AUTHATTRIBUTES,
240
OSPEDRID_SGNINF_DIGENCRYPTALG ,
241
OSPEDRID_SGNINF_ENCRYPTEDDIGEST ,
242
OSPEDRID_SGNINF_UNAUTHATTRIBUTES ,
244
/* CONTENT INFO DATA ELEMENTS */
245
OSPEDRID_CONTENTINFO,
246
OSPEDRID_CNTINF_CONTENTTYPE,
247
OSPEDRID_CNTINF_EXPLICIT_CONTENT,
248
OSPEDRID_CNTINF_CONTENT,
250
/* DIGEST INFO DATA ELEMENTS */
252
OSPEDRID_DIGINF_DIGESTALGORITHM,
253
OSPEDRID_DIGINF_DIGEST,
255
/* ALGORITHM ID DATA ELEMENTS */
256
OSPEDRID_ALGORITHMID,
258
OSPEDRID_ALGID_ATTRIBUTES,
259
OSPEDRID_ALGID_TERMINATOR,
261
/* PRIVATEKEYINFO DATA ELEMENTS */
262
OSPEDRID_PRIVATEKEYINFO,
263
OSPEDRID_PVTKEYINF_VERSION,
264
OSPEDRID_PVTKEYINF_ALGORITHM,
265
OSPEDRID_PVTKEYINF_PRIVATEKEY,
266
OSPEDRID_PVTKEYINF_ATTRIBUTES,
267
OSPEDRID_PVTKEYINF_ATTRIBUTE,
270
OSPEDRID_SIG_CONTENTTYPE,
271
OSPEDRID_SIG_SIGNEDDATA,
272
OSPEDRID_SIG_SGNDAT_VERSION,
273
OSPEDRID_SIG_SGNDAT_DIGESTALGORITHM,
274
OSPEDRID_SIG_SGNDAT_DATA,
275
OSPEDRID_SIG_SGNDAT_CERTIFICATE,
276
OSPEDRID_SIG_SGNDAT_CERTIFICATE_SUBJPUBKEYINFO,
277
OSPEDRID_SIG_SGNDAT_CERTREVLIST,
278
OSPEDRID_SIG_SGNDAT_SIGNERINFO,
279
OSPEDRID_SIG_SGNDAT_SGNINF_DIGESTALGORITHM,
280
OSPEDRID_SIG_SGNDAT_SGNINF_DIGENCRYPTALG,
281
OSPEDRID_SIG_SGNDAT_SGNINF_ENCRYPTEDDIGEST,
283
/* These are defined for parsing certificate requests; all possible
284
* elements of a certificate request ( with the exception of the possible
285
* values of the optional attributes list, which is unknown at compile
286
* time anyway ) is given here. This listing is based off of PKCS#10.
289
OSPEDRID_CERTREQINFO,
290
OSPEDRID_CERTREQINFO_VERSION,
291
OSPEDRID_CERTREQINFO_SUBJECT,
292
OSPEDRID_CERTREQINFO_SUBJPUBKEYINFO,
293
OSPEDRID_CERTREQINFO_ATTRIBUTES,
294
OSPEDRID_CERTREQ_SIGNATUREALGID,
295
OSPEDRID_CERTREQ_SIGNATURE,
302
typedef struct _OSPTASN1ELEMENTINFO
304
unsigned char Tag; /* ASN1 Data Type Tag Number */
305
unsigned char *Element; /* Pointer to beginning of encoded
306
data for this element.*/
307
unsigned int ElementLength; /* Length of data pointed to by
309
unsigned int ElementSpaceAllocated; /* Space for element and possibly for
310
children is allocated by this element
311
and must be deleted when this element
312
is deleted (after child elements are
313
deleted of course) */
315
unsigned char *Content; /* Pointer to encoded content data
316
that defines this element */
317
unsigned int ContentLength; /* Length of data pointed to by
319
struct _OSPTASN1ELEMENTINFO *ContentElementInfo;
321
points to this element's
323
constructed elements only.*/
324
struct _OSPTASN1ELEMENTINFO *NextElementInfo;
325
/* Pointer to next peer element */
326
} OSPTASN1ELEMENTINFO;
328
#define OSPC_ASN1_DATAREF_MAXLENGTH 30
331
typedef struct _OSPTASN1PARSERESULT
333
unsigned char DataReference[OSPC_ASN1_DATAREF_MAXLENGTH];
334
struct _OSPTASN1PARSERESULT *NextResult;
335
OSPTASN1ELEMENTINFO *ElementInfo;
337
} OSPTASN1PARSERESULT;
340
typedef struct _OSPASN1OBJECT
342
OSPTASN1ELEMENTINFO *ElementInfo;
343
OSPTASN1PARSERESULT *ParseResults;
347
typedef struct _OSPTASN1PARSERULE
350
unsigned char Tag; /* ASN1 Type Tag that the current element must
351
match. If the Tag is 0xFF, then this rule is
352
a content rule and directs the parser to a
353
differnt parse table to continue parsing.
355
OSPEASN1PARSETABLEID ParseTableId;
356
/* Enum identifier the parse table that
357
describes this elements contents. Only used
358
for elements whose Tag is 0xFF indicating that
359
the element is constructed.*/
361
unsigned char DataReference;
362
/* Reference for this rule data in the Result's
364
unsigned int MinimumCount;
365
/* Minimum number of occurances of this item
366
that are allowed. If the data element is
367
optional, then Minimum occurances will be 0 */
368
unsigned int MaximumCount;
369
/* Maximum number of occurances of this item
370
that are allowed. Usually 1, unless the
371
element contains a list (SET/SET_OF). */
373
/* Indicates that the value can have a default
374
value. The default value must be assigned by
376
unsigned char ClassTag;
377
/* Tag number used with explicit and implicit
378
tagging. Used in body rules, not in the id
379
rule (index 0). Passed to Parser to modify tag
380
within new rule table.*/
383
typedef OSPTASN1PARSERULE OSPTASN1PARSETABLE;
385
typedef struct _OSPTOBJECTID {
386
unsigned int *Elements;
387
unsigned int ElementCount;
390
typedef int OSPTASN1BOOLEAN;
392
typedef struct _OSPTASN1UTCTIME {
394
int FractionalSeconds;
397
typedef struct _OSPTASN1BUFFER
399
unsigned char *Buffer;
400
unsigned int BufferLength;
404
typedef struct _OSPTBITSTRING {
406
OSPTASN1BUFFER *Buffer;
411
The integer structure holds DER encoded big integers.
412
Assumes base 256, two's complement encoding. digits[0] contains the
413
MOST Significate digit in the integer.
415
typedef struct _OSPTASN1INTEGER {
416
unsigned int DigitCount;
417
unsigned char *Digits;
418
int *SmallValue; /* Pointer to value if less than +|- 0x7fffffff */
422
typedef enum _OSPEALGORITHMID
424
OSPE_ALGORITHMID_NONE,
425
OSPE_ALGORITHMID_RSA_ENCRYPTION,
438
OSPPASN1UTCTimeEncode(
439
OSPTASN1ELEMENTINFO *ospvElementInfo);
442
OSPPASN1PrintableStringEncode(
443
OSPTASN1ELEMENTINFO *ospvElementInfo);
446
OSPPASN1IntegerEncode(
447
OSPTASN1ELEMENTINFO *ospvElementInfo);
450
OSPPASN1EndOfContentEncode(
451
OSPTASN1ELEMENTINFO *ospvElementInfo);
454
OSPPASN1BitStringEncode(
455
OSPTASN1ELEMENTINFO *ospvElementInfo);
458
OSPPASN1ElementEncode(
459
OSPTASN1ELEMENTINFO *ospvElementInfo);
462
OSPPASN1ObjectGetElementByDataRef(
463
OSPTASN1OBJECT *ospvObject,
464
OSPTASN1ELEMENTINFO **ospvElementInfo,
465
OSPEASN1DATAREFID OospvDataRefId);
468
OSPPASN1ElementCopyElementData(
469
OSPTASN1ELEMENTINFO *ospvElementInfo,
470
unsigned char **ospvData,
471
unsigned int *ospvDataLength);
474
OSPPASN1SmallInt2UnsignedChar(
475
unsigned ospvIntegerValue,
477
unsigned char **ospvBuffer,
478
unsigned *ospvBufferLength);
481
OSPPASN1SmallIntegerEncode(
482
OSPTASN1OBJECT **ospvIntegerObject,
483
unsigned ospvInteger,
484
OSPEASN1DATAREFID ospvDataRefId);
487
OSPPASN1ElementFormat(
488
OSPTASN1ELEMENTINFO **ospvElement,
489
unsigned char *ospvTag,
490
unsigned char ospvTagFlags,
491
unsigned ospvTagLength,
492
unsigned char *ospvData,
493
unsigned ospvDataLength);
496
OSPPASN1ObjectFormat(
497
OSPTASN1OBJECT **ospvObject,
498
OSPTASN1ELEMENTINFO *ospvElement,
499
OSPEASN1DATAREFID ospvDataRefId);
502
OSPPASN1ObjectEncode(
503
OSPTASN1OBJECT **ospvEncodedObject,
504
unsigned char *ospvTag,
505
unsigned ospvTagLength,
506
unsigned char ospvTagFlags,
507
unsigned char *ospvContent,
508
unsigned ospvContentLength,
509
OSPEASN1DATAREFID ospvDataRefId);
512
OSPPASN1ObjectDeparse(
513
OSPTASN1OBJECT *ospvObject,
514
OSPEASN1PARSETABLEID ospvParseTableId,
515
OSPEASN1DATAREFID ospvDataRefId);
518
OSPPASN1ObjectCopyElementObject(
519
OSPTASN1OBJECT **ospvDstObject,
520
OSPTASN1OBJECT *ospvSrcObject,
521
OSPEASN1DATAREFID ospvDataRefId);
525
OSPPASN1ObjectGetElementInfo(
526
OSPTASN1OBJECT *ospvObject,
527
OSPTASN1ELEMENTINFO **ospvElementInfo);
530
OSPPASN1ObjectGetContentElementInfo(
531
OSPTASN1OBJECT *ospvObject,
532
OSPTASN1ELEMENTINFO **ospvContentElementInfo);
535
OSPPASN1ObjectGetParseResults(
536
OSPTASN1OBJECT *ospvObject,
537
OSPTASN1PARSERESULT **ospvParseResults);
541
OSPTASN1ELEMENTINFO **ospvToElement,
542
OSPTASN1ELEMENTINFO *ospvFromElement);
545
OSPPASN1ElementDeparse(
546
OSPTASN1ELEMENTINFO **ospvElementInfo,
547
OSPTASN1PARSERESULT **ospvParseResults,
548
OSPEASN1PARSETABLEID ospvParseTableId,
549
unsigned char *ospvDataReference);
553
OSPPASN1IntegerGetSmallValue(
554
OSPTASN1ELEMENTINFO *ospvInteger,
558
OSPPASN1ElementGetContentValue(
559
OSPTASN1ELEMENTINFO *ospvElement,
560
void **ospvContentValue);
563
OSPPASN1ElementGetContentData(
564
OSPTASN1ELEMENTINFO *ospvElement,
565
unsigned char **ospvContent,
566
unsigned int *ospvContentLength);
569
OSPPASN1ElementGetElementData(
570
OSPTASN1ELEMENTINFO *ospvElementInfo,
571
unsigned char **ospvData,
572
unsigned int *ospvDataLength);
576
OSPTASN1OBJECT **ospvToObject,
577
OSPTASN1OBJECT *ospvFromObject);
580
OSPPASN1AlgorithmIdEncode(
581
OSPTASN1OBJECT **ospvAlgorithIdObject,
582
OSPEASN1ID ospvAlgorithmIdCode,
583
OSPEASN1DATAREFID ospvDataRefId);
586
PTPResultUpdateDataRef(
587
unsigned char ospvDataRef,
588
OSPTASN1PARSERESULT *ospvParseResult);
591
PTPDataRefIdGetValue(
592
OSPEASN1DATAREFID ospvDataRefId,
593
unsigned char **ospvDataRefIdValue);
597
unsigned char ospvDataReference[OSPC_ASN1_DATAREF_MAXLENGTH],
598
unsigned char ospvNewReference);
601
/* If primitive can be a list (max >= 1), then all peers of
602
this element should be the same element and should all be
603
added to the list. Add Parse Result assumes this and adds a
604
result for the element passed, and then traverses the
605
element's "next" pointer to add entries for each of the
606
elements it finds. It returns when an element's
607
"next" pointer is NULL.
611
OSPTASN1PARSERULE *ospvParseRule,
612
OSPTASN1ELEMENTINFO *ospvElementInfo,
613
OSPTASN1PARSERESULT **ospvParseResult,
614
unsigned char ospvDataRef);
617
PTPDataReferencesMatch(
618
unsigned char *ospvDataReferenceId1,
619
unsigned char *ospvDataReferenceId2);
622
PTPResultIsRuleComponent(
623
unsigned char *ospvRuleDataReference,
624
unsigned char *ospvResultDataReference);
628
OSPTASN1PARSERESULT **ospvDstParseResults,
629
OSPTASN1PARSERESULT *ospvSrcParseResults);
632
PTPResultsGetElement(
633
OSPEASN1DATAREFID ospvDataReferenceId,
634
OSPTASN1PARSERESULT *ospvParseResults,
635
OSPTASN1ELEMENTINFO **ospvFoundElement);
639
OSPTASN1PARSERESULT **ospvParseResult,
640
OSPTASN1ELEMENTINFO *ospvElementInfo,
641
OSPEASN1DATAREFID ospvDataRefId);
643
OSPTASN1PARSERESULT *
645
OSPTASN1PARSERESULT *ospvResults);
648
PTPParseResultAppend(
649
OSPTASN1PARSERESULT **ospvLastResult,
650
OSPTASN1PARSERESULT *ospvNewResults);
654
OSPTASN1PARSERESULT **ospvParseResult);
658
OSPTASN1PARSERULE *ospvParseRule);
664
OSPTASN1PARSERULE *ospvParseRule);
668
OSPTASN1PARSERULE *ospvParseRule);
672
OSPTASN1PARSERULE *ospvParseRule);
676
OSPTASN1PARSERULE *ospvParseRule);
680
OSPPASN1ElementParse(
681
OSPTASN1ELEMENTINFO *ospvElementInfo,
682
OSPEASN1PARSETABLEID ospvParseTableId,
683
OSPTASN1PARSERULE *ospvParentParseRule,
684
OSPTASN1PARSERESULT **ospvParseResult,
685
unsigned char ospvDataRef);
688
OSPPASN1ElementParseDelete(
689
OSPTASN1PARSERESULT **ospvParseResult);
693
OSPEASN1PARSETABLEID ospvParseTableId,
694
OSPTASN1PARSETABLE *ospvParseTable[]);
698
OSPEASN1PARSETABLEID ospvParseTableId,
699
OSPTASN1PARSERULE **ospvParseRule,
700
unsigned int *ospvRuleIndex); /* Updated to point to next rule */
703
PTPRuleGetParseTableId(
704
OSPTASN1PARSERULE *ospvParseRule,
705
OSPEASN1PARSETABLEID *ospvParseTableId);
709
OSPPASN1IntegerDelete(
710
OSPTASN1INTEGER **ospvInteger);
713
OSPPASN1IntegerCreate(
714
unsigned char *ospvContent,
715
unsigned int ospvContentLength,
716
OSPTASN1INTEGER **ospvInteger);
719
OSPPASN1BitStringDelete(
720
OSPTASN1BITSTRING **ospvBitString);
723
OSPPASN1BitStringCreate(
724
unsigned char *ospvContent,
725
unsigned ospvContentLength,
726
unsigned ospvUnusedBits,
727
OSPTASN1BITSTRING **ospvBitString);
730
OSPPASN1ObjectAddChild(
731
OSPTASN1OBJECT *ospvParent,
732
OSPTASN1OBJECT *ospvChild,
733
OSPEASN1DATAREFID ospvDataRefId);
737
OSPTASN1OBJECT **ospvASN1Object,
738
OSPEASN1DATAREFID ospvDataRefId);
741
OSPPASN1ObjectCreate(
742
OSPTASN1OBJECT **ospvASN1Object,
743
OSPTASN1ELEMENTINFO *ospvElementInfo,
744
OSPTASN1PARSERESULT *ospvParseResults);
747
OSPPASN1ObjectDelete(
748
OSPTASN1OBJECT **ospvASN1Object);
751
OSPPASN1ElementTestContext(
752
OSPTASN1ELEMENTINFO *ospvElementInfo);
755
OSPPASN1PrimitiveDecode(
756
OSPTASN1ELEMENTINFO *ospvElementInfo);
759
OSPPASN1PrimitiveDelete(
760
OSPTASN1ELEMENTINFO *ospvElementInfo);
763
OSPPASN1ElementDecode(
764
unsigned char *ospvASN1Element,
765
OSPTASN1ELEMENTINFO **ospvASN1ElementInfo,
766
unsigned int ospvLevel);
769
OSPPASN1ElementCreate(
770
OSPTASN1ELEMENTINFO **ospvElementInfo);
773
OSPPASN1ElementDelete(
774
OSPTASN1ELEMENTINFO **ospvElement,
775
unsigned int ospvLevel);
779
OSPEASN1DATAREFID ospvDataRefId,
780
OSPTASN1PARSERESULT *ospvParseResults,
781
OSPTASN1ELEMENTINFO **ospvFoundElement);
784
OSPPASN1EndOfContentDelete(
785
OSPTASN1ELEMENTINFO *ospvElementInfo);
789
OSPTASN1ELEMENTINFO *ospvElementInfo);
792
OSPPASN1ObjectIdentifierDelete(
793
OSPTASN1ELEMENTINFO *ospvElementInfo);
796
OSPPASN1PrintableStringDelete(
797
OSPTASN1ELEMENTINFO *ospvElementInfo);
800
OSPPASN1UTCTimeDelete(
801
OSPTASN1ELEMENTINFO *ospvElementInfo);
804
OSPPASN1IntegerDecode(
805
void *ospvContentValue,
806
unsigned char *ospvContent,
807
unsigned int ospvContentLength);
810
OSPPASN1ObjectIdentifierDecode(
811
void *ospvContentValue,
812
unsigned char *ospvContent,
813
unsigned int ospvContentLength);
816
OSPPASN1PrintableStringDecode(
817
void *ospvContentValue,
818
unsigned char *ospvContent,
819
unsigned int ospvContentLength);
822
OSPPASN1UTCTimeDecode(
823
void *ospvContentValue,
824
unsigned char *ospvContent,
825
unsigned int ospvContentLength);
828
OSPPASN1BitStringDecode(
829
void *ospvContentValue,
830
unsigned char *ospvContent,
831
unsigned int ospvContentLength);
834
OSPPASN1OctetStringDecode(
835
void *ospvContentValue,
836
unsigned char *ospvContent,
837
unsigned int ospvContentLength);
841
OSPTASN1OBJECT **ospvNullObject);
844
OSPPASN1BigIntegerEncode(
845
OSPTASN1OBJECT **ospvIntegerObject,
846
unsigned char *ospvIntegerData,
847
unsigned int ospvIntegerLength);
850
OSPPASN1ObjectIdentifierEncode(
851
OSPTASN1OBJECT **ospvOIDObject,
852
OSPEASN1ID ospvObjectId,
853
OSPEASN1DATAREFID ospvDataRefId);
856
OSPPASN1OctetStringEncode(
857
OSPTASN1OBJECT **ospvOctetStringObject,
858
unsigned char *ospvContent,
859
unsigned ospvContentLength,
860
OSPEASN1DATAREFID ospvDataRefId);
863
OSPPASN1BufferCreate(
864
unsigned char *ospvContent,
865
unsigned ospvContentLength,
866
OSPTASN1BUFFER **ospvBuffer);
869
OSPPASN1BufferDelete(
870
OSPTASN1BUFFER **ospvBuffer);
873
OSPPASN1PrimitiveEncode(
874
OSPTASN1ELEMENTINFO *ospvElementInfo);
883
typedef struct _OSPTDERBUF
885
unsigned char *data; /* Pointer to storage for the certificate */
886
unsigned char *ptr; /* Pointer to beginning of buffer remainder */
889
/*****************************************************************
891
*****************************************************************/
892
#define OSPC_ASN1_OID_MAX_ELEMENTS 20
894
typedef struct _OSPTOBJID
896
int element[OSPC_ASN1_OID_MAX_ELEMENTS];
906
#define OSPC_OID_VALUE_TERMINATOR (-1) /* Not a legal OID value */
907
#define OSPC_OID_VALUE_DIGIT_MASK 0x7F /* Base 128 */
908
#define OSPC_OID_VALUE_END_MASK 0x80 /* MSB = 0 in last octet of value */
911
/*****************************************************************
912
OBJECT ID DEFINITIONS/XREF/TAGS
913
*****************************************************************/
914
#define OSPC_OID_CODE_NOT_FOUND 0
915
#define OSPC_OID_CODE_ALGORITHM 1, 3, 14, 3, 2
917
#define OSPC_OID_CODE_RSADSI 1, 2, 840, 113549
918
#define OSPC_OID_CODE_PKCS OID_CODE_RSADSI, 1
919
#define OSPC_OID_CODE_PKCS9 OID_CODE_PKCS, 9
920
#define OSPC_OID_CODE_ALG_RSAENCRYPTION \
921
OSPC_OID_CODE_PKCS, 1, 1
922
#define OSPC_OID_CODE_ALG_MD2WITHRSAENCRYPTION \
923
OSPC_OID_CODE_PKCS, 1, 2
924
#define OSPC_OID_CODE_ALG_MD5WITHRSAENCRYPTION \
925
OSPC_OID_CODE_PKCS, 1, 4
927
#define OSPC_OID_CODE_MD2 OID_CODE_RSADSI, 2, 2
928
#define OSPC_OID_CODE_MD5 OID_CODE_RSADSI, 2, 5
929
#define OSPC_OID_CODE_RC4 OID_CODE_RSADSI, 3, 4
931
#define OSPC_OID_CODE_X500 2, 5
932
#define OSPC_OID_CODE_X509 OID_CODE_X500, 4
933
#define OSPC_OID_CODE_DN_COUNTRY OID_CODE_X509, 6
934
#define OSPC_OID_CODE_DN_STATE OID_CODE_X509, 8
935
#define OSPC_OID_CODE_DN_LOCALITY OID_CODE_X509, 7
936
#define OSPC_OID_CODE_DN_ORGANIZATION \
937
OSPC_OID_CODE_X509, 10
938
#define OSPC_OID_CODE_DN_ORG_UNIT OID_CODE_X509, 11
939
#define OSPC_OID_CODE_DN_COMMON_NAME OID_CODE_X509, 3
941
#define OSPC_OID_CODE_RSA OID_CODE_X500, 8, 1, 1
943
#define OSPC_OID_CODE_LD_CE OID_CODE_X500, 29
944
#define OSPC_OID_CODE_EXT_KEY_USAGE OID_CODE_LD_CE, 15
945
#define OSPC_OID_CODE_EXT_SUBJECT_KEY_ID \
946
OSPC_OID_CODE_LD_CE, 14
949
/* ***************************************************************
950
ENTRIES IN THE ARRAY THAT FOLLOWS MUST BE IN THE SAME ORDER AS
955
OSPC_OID_TAG_DN_COUNTRY,
956
OSPC_OID_TAG_DN_STATE,
957
OSPC_OID_TAG_DN_LOCALITY,
958
OSPC_OID_TAG_DN_ORGANIZATION,
959
OSPC_OID_TAG_DN_ORG_UNIT,
960
OSPC_OID_TAG_DN_COMMON_NAME,
961
OSPC_OID_TAG_ALG_RSAENCRYPTION,
962
OSPC_OID_TAG_ALG_MD5WITHRSAENCRYPTION,
963
OSPC_OID_TAG_EXT_KEY_USAGE,
964
OSPC_OID_TAG_EXT_SUBJECT_KEY_ID,
965
OSPC_OID_TAG_NOT_FOUND
975
#define OSPC_OID_XX OSPC_OID_VALUE_TERMINATOR
976
/* ************************************************************** */
982
unsigned char *value;
986
#define OSPC_ATV_MAX_PARAMS 10
990
OSPTPARAMETER *params[OSPC_ATV_MAX_PARAMS]; /* Dynamically allocated */
994
/* typedef OSPTALGORITHMID OSPTDIGESTALGORITHMID; */
996
/**************************************************
997
DER/BER (Encoding/Decoding Rules) Definitions
998
***************************************************/
1000
#define OSPC_BER_MAX_TAG_LENGTH 10
1002
#define OSPC_BER_MODE_MASK 0x20
1003
#define OSPC_BER_MODE_PRIMITIVE 0x00
1004
#define OSPC_BER_MODE_CONSTRUCTED 0x20
1005
#define OSPM_CONSTRUCTED_TAG(a) \
1006
((a) | OSPC_BER_MODE_CONSTRUCTED)
1007
#define OSPM_IS_PRIMITIVE(a) \
1008
(((a)&OSPC_BER_MODE_MASK) == OSPC_BER_MODE_PRIMITIVE)
1009
#define OSPM_IS_CONSTRUCTED(a) \
1010
(((a)&OSPC_BER_MODE_MASK) == OSPC_BER_MODE_CONSTRUCTED)
1011
#define OSPC_BER_CLASS_MASK 0xc0
1012
#define OSPC_BER_CLASS_UNIVERSAL 0x00
1013
#define OSPC_BER_CLASS_APPLICATION 0x40
1014
#define OSPC_BER_CLASS_CONTEXT_SENS 0x80
1015
#define OSPC_BER_CLASS_PRIVATE 0xc0
1017
#define OSPC_BER_EXPLICIT_MASK \
1018
(OSPC_BER_MODE_CONSTRUCTED | OSPC_BER_CLASS_CONTEXT_SENS)
1021
#define OSPC_BER_IMPLICIT_MASK \
1022
(OSPC_BER_MODE_CONSTRUCTED | OSPC_BER_CLASS_CONTEXT_SENS)
1025
#define OSPC_BER_LENGTH_MODE_MASK 0x80
1026
#define OSPC_BER_LENGTH_MODE_SHORT 0x00
1027
#define OSPC_BER_LENGTH_MODE_LONG 0x80
1029
#define OSPC_BER_LENGTH_MASK 0x7f
1030
#define OSPM_IS_SHORT_LENGTH(a) \
1031
(((a)&OSPC_BER_LENGTH_MODE_MASK)==OSPC_BER_LENGTH_MODE_SHORT)
1032
#define OSPM_IS_LONG_LENGTH(a) \
1033
(((a)&OSPC_BER_LENGTH_MODE_MASK)==OSPC_BER_LENGTH_MODE_LONG)
1034
#define OSPM_BER_LENGTH(a) (((a)&OSPC_BER_LENGTH_MASK))
1036
#define OSPC_BER_TAG_MASK 0x1f
1037
#define OSPC_BER_TAG_HIGH 0x1f
1040
#define OSPM_BASE_TAG(a) ((a) & (OSPC_BER_TAG_MASK))
1041
#define OSPM_IS_HIGH_TAG(a) \
1042
(((a) & (OSPC_BER_TAG_HIGH)) == OSPC_BER_TAG_HIGH)
1044
#define OSPC_TAG_TYPE_EOC 0x00
1045
#define OSPC_TAG_TYPE_BOOLEAN 0x01
1046
#define OSPC_TAG_TYPE_INTEGER 0x02
1047
#define OSPC_TAG_TYPE_BIT_STRING 0x03
1048
#define OSPC_TAG_TYPE_OCTET_STRING 0x04
1049
#define OSPC_TAG_TYPE_NULL 0x05
1050
#define OSPC_TAG_TYPE_OBJECT_IDENTIFIER 0x06
1051
#define OSPC_TAG_TYPE_SEQUENCE 0x10
1052
#define OSPC_TAG_TYPE_SET 0x11
1053
#define OSPC_TAG_TYPE_PRINTABLESTRING 0x13
1054
#define OSPC_TAG_TYPE_T61STRING 0x14
1055
#define OSPC_TAG_TYPE_IA5STRING 0x16
1056
#define OSPC_TAG_TYPE_UTCTIME 0x17
1057
#define OSPC_TAG_TYPE_GENERALIZEDTIME 0x18
1058
#define OSPC_TAG_TYPE_BMPSTRING 0x1e
1060
#define OSPC_TAG_TYPE_IMPLICIT 0xa0
1061
#define OSPM_TAG_TYPE_IMPLICIT_TAG(a) ((OSPC_TAG_TYPE_IMPLICIT) | (a))
1062
#define OSPM_IS_IMPLICIT(a) \
1063
(((a) & OSPC_BER_IMPLICIT_MASK) == OSPC_BER_IMPLICIT_MASK)
1065
#define OSPC_TAG_TYPE_EXPLICIT 0xa0
1066
#define OSPM_TAG_TYPE_EXPLICIT_TAG(a) ((OSPC_TAG_TYPE_EXPLICIT) | (a))
1067
#define OSPM_IS_EXPLICIT(a) \
1068
(((a) & OSPC_BER_EXPLICIT_MASK) == OSPC_BER_EXPLICIT_MASK)
1071
/* SPECIAL NOT-REALLY-A-TAG TAGS */
1072
#define OSPC_TAG_TYPE_DER_FORMAT 0xFE
1073
#define OSPC_TAG_TYPE_DERIVED 0xFF
1076
#define OSPM_EXPLICIT_CLASSNUMBER(a) ((a) & OSPC_BER_TAG_MASK)
1077
#define OSPC_BER_MAX_EXTENSIONS 10
1079
typedef union char2int_union {
1081
unsigned char buf[sizeof(OSPTUINT64)];
1085
unsigned char tag[OSPC_BER_MAX_TAG_LENGTH]; /* Complete tag */
1086
unsigned int type; /* Element's type */
1087
unsigned int taglength; /* Length of tag and length fields */
1088
unsigned int length; /* Element's length */
1089
unsigned char *value; /* Pointer to element's data */
1095
unsigned char *buffer;
1098
#define OSPC_BER_MAX_EXTENSIONS 10
1103
} OSPTTEXTLISTELEMENT;