xref: /titanic_50/usr/src/lib/libkmf/include/pem_encode.h (revision 9a7670889e9c36ec355371e6b02f2d9084f040dc)
1 /*
2  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 #ifndef _PEM_ENCODE_H
7 #define	_PEM_ENCODE_H
8 
9 #pragma ident	"%Z%%M%	%I%	%E% SMI"
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 /*
16  * Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
17  * All rights reserved.
18  *
19  * This package is an SSL implementation written
20  * by Eric Young (eay@cryptsoft.com).
21  * The implementation was written so as to conform with Netscapes SSL.
22  *
23  * This library is free for commercial and non-commercial use as long as
24  * the following conditions are aheared to.  The following conditions
25  * apply to all code found in this distribution, be it the RC4, RSA,
26  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
27  * included with this distribution is covered by the same copyright terms
28  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
29  *
30  * Copyright remains Eric Young's, and as such any Copyright notices in
31  * the code are not to be removed.
32  * If this package is used in a product, Eric Young should be given attribution
33  * as the author of the parts of the library used.
34  * This can be in the form of a textual message at program startup or
35  * in documentation (online or textual) provided with the package.
36  *
37  * Redistribution and use in source and binary forms, with or without
38  * modification, are permitted provided that the following conditions
39  * are met:
40  * 1. Redistributions of source code must retain the copyright
41  *    notice, this list of conditions and the following disclaimer.
42  * 2. Redistributions in binary form must reproduce the above copyright
43  *    notice, this list of conditions and the following disclaimer in the
44  *    documentation and/or other materials provided with the distribution.
45  * 3. All advertising materials mentioning features or use of this software
46  *    must display the following acknowledgement:
47  *    "This product includes cryptographic software written by
48  *     Eric Young (eay@cryptsoft.com)"
49  *    The word 'cryptographic' can be left out if the rouines from the library
50  *    being used are not cryptographic related :-).
51  * 4. If you include any Windows specific code (or a derivative thereof) from
52  *    the apps directory (application code) you must include an acknowledgement:
53  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
54  *
55  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
56  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
59  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65  * SUCH DAMAGE.
66  *
67  * The licence and distribution terms for any publically available version or
68  * derivative of this code cannot be changed.  i.e. this code cannot simply be
69  * copied and put under another distribution licence
70  * [including the GNU Public Licence.]
71  */
72 #define	PEM_STRING_X509		"CERTIFICATE"
73 #define	PEM_STRING_X509_REQ	"CERTIFICATE REQUEST"
74 #define	PEM_STRING_X509_CRL	"X509 CRL"
75 #define	PEM_BUFSIZE		1024
76 
77 /*
78  * 0xF0 is a EOLN
79  * 0xF1 is ignore but next needs to be 0xF0 (for \r\n processing).
80  * 0xF2 is EOF
81  * 0xE0 is ignore at start of line.
82  * 0xFF is error
83  */
84 
85 #define	B64_EOLN		0xF0
86 #define	B64_CR			0xF1
87 #define	B64_EOF			0xF2
88 #define	B64_WS			0xE0
89 #define	B64_ERROR		0xFF
90 #define	B64_NOT_BASE64(a)	(((a)|0x13) == 0xF3)
91 
92 typedef struct pem_encode_ctx_st
93 {
94 	int num;	/* number saved in a partial encode/decode */
95 	/*
96 	 * The length is either the output line length
97 	 * (in input bytes) or the shortest input line
98 	 * length that is ok.  Once decoding begins,
99 	 * the length is adjusted up each time a longer
100 	 * line is decoded.
101 	 */
102 	int length;
103 	unsigned char enc_data[80];	/* data to encode */
104 	int line_num;	/* number read on current line */
105 	int expect_nl;
106 } PEM_ENCODE_CTX;
107 
108 KMF_RETURN
109 Der2Pem(KMF_OBJECT_TYPE, unsigned char *, int, unsigned char **, int *);
110 
111 KMF_RETURN
112 Pem2Der(unsigned char *, int, unsigned char **, int *);
113 
114 #ifdef __cplusplus
115 }
116 #endif
117 #endif /* _PEM_ENCODE_H */
118