199ebb4caSwyllys /*
2*9a767088Shaimay  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
399ebb4caSwyllys  * Use is subject to license terms.
499ebb4caSwyllys  */
599ebb4caSwyllys 
699ebb4caSwyllys #ifndef _PEM_ENCODE_H
799ebb4caSwyllys #define	_PEM_ENCODE_H
899ebb4caSwyllys 
999ebb4caSwyllys #ifdef __cplusplus
1099ebb4caSwyllys extern "C" {
1199ebb4caSwyllys #endif
1299ebb4caSwyllys 
1399ebb4caSwyllys /*
1499ebb4caSwyllys  * Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
1599ebb4caSwyllys  * All rights reserved.
1699ebb4caSwyllys  *
1799ebb4caSwyllys  * This package is an SSL implementation written
1899ebb4caSwyllys  * by Eric Young (eay@cryptsoft.com).
1999ebb4caSwyllys  * The implementation was written so as to conform with Netscapes SSL.
2099ebb4caSwyllys  *
2199ebb4caSwyllys  * This library is free for commercial and non-commercial use as long as
2299ebb4caSwyllys  * the following conditions are aheared to.  The following conditions
2399ebb4caSwyllys  * apply to all code found in this distribution, be it the RC4, RSA,
2499ebb4caSwyllys  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
2599ebb4caSwyllys  * included with this distribution is covered by the same copyright terms
2699ebb4caSwyllys  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
2799ebb4caSwyllys  *
2899ebb4caSwyllys  * Copyright remains Eric Young's, and as such any Copyright notices in
2999ebb4caSwyllys  * the code are not to be removed.
3099ebb4caSwyllys  * If this package is used in a product, Eric Young should be given attribution
3199ebb4caSwyllys  * as the author of the parts of the library used.
3299ebb4caSwyllys  * This can be in the form of a textual message at program startup or
3399ebb4caSwyllys  * in documentation (online or textual) provided with the package.
3499ebb4caSwyllys  *
3599ebb4caSwyllys  * Redistribution and use in source and binary forms, with or without
3699ebb4caSwyllys  * modification, are permitted provided that the following conditions
3799ebb4caSwyllys  * are met:
3899ebb4caSwyllys  * 1. Redistributions of source code must retain the copyright
3999ebb4caSwyllys  *    notice, this list of conditions and the following disclaimer.
4099ebb4caSwyllys  * 2. Redistributions in binary form must reproduce the above copyright
4199ebb4caSwyllys  *    notice, this list of conditions and the following disclaimer in the
4299ebb4caSwyllys  *    documentation and/or other materials provided with the distribution.
4399ebb4caSwyllys  * 3. All advertising materials mentioning features or use of this software
4499ebb4caSwyllys  *    must display the following acknowledgement:
4599ebb4caSwyllys  *    "This product includes cryptographic software written by
4699ebb4caSwyllys  *     Eric Young (eay@cryptsoft.com)"
4799ebb4caSwyllys  *    The word 'cryptographic' can be left out if the rouines from the library
4899ebb4caSwyllys  *    being used are not cryptographic related :-).
4999ebb4caSwyllys  * 4. If you include any Windows specific code (or a derivative thereof) from
5099ebb4caSwyllys  *    the apps directory (application code) you must include an acknowledgement:
5199ebb4caSwyllys  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
5299ebb4caSwyllys  *
5399ebb4caSwyllys  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
5499ebb4caSwyllys  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5599ebb4caSwyllys  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5699ebb4caSwyllys  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
5799ebb4caSwyllys  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5899ebb4caSwyllys  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5999ebb4caSwyllys  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
6099ebb4caSwyllys  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
6199ebb4caSwyllys  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
6299ebb4caSwyllys  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6399ebb4caSwyllys  * SUCH DAMAGE.
6499ebb4caSwyllys  *
6599ebb4caSwyllys  * The licence and distribution terms for any publically available version or
6699ebb4caSwyllys  * derivative of this code cannot be changed.  i.e. this code cannot simply be
6799ebb4caSwyllys  * copied and put under another distribution licence
6899ebb4caSwyllys  * [including the GNU Public Licence.]
6999ebb4caSwyllys  */
7099ebb4caSwyllys #define	PEM_STRING_X509		"CERTIFICATE"
7199ebb4caSwyllys #define	PEM_STRING_X509_REQ	"CERTIFICATE REQUEST"
7299ebb4caSwyllys #define	PEM_STRING_X509_CRL	"X509 CRL"
7399ebb4caSwyllys #define	PEM_BUFSIZE		1024
7499ebb4caSwyllys 
7599ebb4caSwyllys /*
7699ebb4caSwyllys  * 0xF0 is a EOLN
7799ebb4caSwyllys  * 0xF1 is ignore but next needs to be 0xF0 (for \r\n processing).
7899ebb4caSwyllys  * 0xF2 is EOF
7999ebb4caSwyllys  * 0xE0 is ignore at start of line.
8099ebb4caSwyllys  * 0xFF is error
8199ebb4caSwyllys  */
8299ebb4caSwyllys 
8399ebb4caSwyllys #define	B64_EOLN		0xF0
8499ebb4caSwyllys #define	B64_CR			0xF1
8599ebb4caSwyllys #define	B64_EOF			0xF2
8699ebb4caSwyllys #define	B64_WS			0xE0
8799ebb4caSwyllys #define	B64_ERROR		0xFF
8899ebb4caSwyllys #define	B64_NOT_BASE64(a)	(((a)|0x13) == 0xF3)
8999ebb4caSwyllys 
9099ebb4caSwyllys typedef struct pem_encode_ctx_st
9199ebb4caSwyllys {
9299ebb4caSwyllys 	int num;	/* number saved in a partial encode/decode */
9399ebb4caSwyllys 	/*
9499ebb4caSwyllys 	 * The length is either the output line length
9599ebb4caSwyllys 	 * (in input bytes) or the shortest input line
9699ebb4caSwyllys 	 * length that is ok.  Once decoding begins,
9799ebb4caSwyllys 	 * the length is adjusted up each time a longer
9899ebb4caSwyllys 	 * line is decoded.
9999ebb4caSwyllys 	 */
10099ebb4caSwyllys 	int length;
10199ebb4caSwyllys 	unsigned char enc_data[80];	/* data to encode */
10299ebb4caSwyllys 	int line_num;	/* number read on current line */
10399ebb4caSwyllys 	int expect_nl;
10499ebb4caSwyllys } PEM_ENCODE_CTX;
10599ebb4caSwyllys 
10699ebb4caSwyllys KMF_RETURN
10799ebb4caSwyllys Der2Pem(KMF_OBJECT_TYPE, unsigned char *, int, unsigned char **, int *);
10899ebb4caSwyllys 
10999ebb4caSwyllys KMF_RETURN
11099ebb4caSwyllys Pem2Der(unsigned char *, int, unsigned char **, int *);
11199ebb4caSwyllys 
11299ebb4caSwyllys #ifdef __cplusplus
11399ebb4caSwyllys }
11499ebb4caSwyllys #endif
11599ebb4caSwyllys #endif /* _PEM_ENCODE_H */
116