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