xref: /onnv-gate/usr/src/lib/libkmf/include/pem_encode.h (revision 3433:2971a4d3cf72)
13089Swyllys /*
2*3433Shaimay  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
33089Swyllys  * Use is subject to license terms.
43089Swyllys  */
53089Swyllys 
63089Swyllys #ifndef _PEM_ENCODE_H
73089Swyllys #define	_PEM_ENCODE_H
83089Swyllys 
93089Swyllys #pragma ident	"%Z%%M%	%I%	%E% SMI"
103089Swyllys 
113089Swyllys #ifdef __cplusplus
123089Swyllys extern "C" {
133089Swyllys #endif
143089Swyllys 
153089Swyllys /*
163089Swyllys  * Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
173089Swyllys  * All rights reserved.
183089Swyllys  *
193089Swyllys  * This package is an SSL implementation written
203089Swyllys  * by Eric Young (eay@cryptsoft.com).
213089Swyllys  * The implementation was written so as to conform with Netscapes SSL.
223089Swyllys  *
233089Swyllys  * This library is free for commercial and non-commercial use as long as
243089Swyllys  * the following conditions are aheared to.  The following conditions
253089Swyllys  * apply to all code found in this distribution, be it the RC4, RSA,
263089Swyllys  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
273089Swyllys  * included with this distribution is covered by the same copyright terms
283089Swyllys  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
293089Swyllys  *
303089Swyllys  * Copyright remains Eric Young's, and as such any Copyright notices in
313089Swyllys  * the code are not to be removed.
323089Swyllys  * If this package is used in a product, Eric Young should be given attribution
333089Swyllys  * as the author of the parts of the library used.
343089Swyllys  * This can be in the form of a textual message at program startup or
353089Swyllys  * in documentation (online or textual) provided with the package.
363089Swyllys  *
373089Swyllys  * Redistribution and use in source and binary forms, with or without
383089Swyllys  * modification, are permitted provided that the following conditions
393089Swyllys  * are met:
403089Swyllys  * 1. Redistributions of source code must retain the copyright
413089Swyllys  *    notice, this list of conditions and the following disclaimer.
423089Swyllys  * 2. Redistributions in binary form must reproduce the above copyright
433089Swyllys  *    notice, this list of conditions and the following disclaimer in the
443089Swyllys  *    documentation and/or other materials provided with the distribution.
453089Swyllys  * 3. All advertising materials mentioning features or use of this software
463089Swyllys  *    must display the following acknowledgement:
473089Swyllys  *    "This product includes cryptographic software written by
483089Swyllys  *     Eric Young (eay@cryptsoft.com)"
493089Swyllys  *    The word 'cryptographic' can be left out if the rouines from the library
503089Swyllys  *    being used are not cryptographic related :-).
513089Swyllys  * 4. If you include any Windows specific code (or a derivative thereof) from
523089Swyllys  *    the apps directory (application code) you must include an acknowledgement:
533089Swyllys  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
543089Swyllys  *
553089Swyllys  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
563089Swyllys  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
573089Swyllys  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
583089Swyllys  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
593089Swyllys  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
603089Swyllys  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
613089Swyllys  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
623089Swyllys  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
633089Swyllys  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
643089Swyllys  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
653089Swyllys  * SUCH DAMAGE.
663089Swyllys  *
673089Swyllys  * The licence and distribution terms for any publically available version or
683089Swyllys  * derivative of this code cannot be changed.  i.e. this code cannot simply be
693089Swyllys  * copied and put under another distribution licence
703089Swyllys  * [including the GNU Public Licence.]
713089Swyllys  */
723089Swyllys #define	PEM_STRING_X509		"CERTIFICATE"
733089Swyllys #define	PEM_STRING_X509_REQ	"CERTIFICATE REQUEST"
743089Swyllys #define	PEM_STRING_X509_CRL	"X509 CRL"
753089Swyllys #define	PEM_BUFSIZE		1024
763089Swyllys 
773089Swyllys /*
783089Swyllys  * 0xF0 is a EOLN
793089Swyllys  * 0xF1 is ignore but next needs to be 0xF0 (for \r\n processing).
803089Swyllys  * 0xF2 is EOF
813089Swyllys  * 0xE0 is ignore at start of line.
823089Swyllys  * 0xFF is error
833089Swyllys  */
843089Swyllys 
853089Swyllys #define	B64_EOLN		0xF0
863089Swyllys #define	B64_CR			0xF1
873089Swyllys #define	B64_EOF			0xF2
883089Swyllys #define	B64_WS			0xE0
893089Swyllys #define	B64_ERROR		0xFF
903089Swyllys #define	B64_NOT_BASE64(a)	(((a)|0x13) == 0xF3)
913089Swyllys 
923089Swyllys typedef struct pem_encode_ctx_st
933089Swyllys {
943089Swyllys 	int num;	/* number saved in a partial encode/decode */
953089Swyllys 	/*
963089Swyllys 	 * The length is either the output line length
973089Swyllys 	 * (in input bytes) or the shortest input line
983089Swyllys 	 * length that is ok.  Once decoding begins,
993089Swyllys 	 * the length is adjusted up each time a longer
1003089Swyllys 	 * line is decoded.
1013089Swyllys 	 */
1023089Swyllys 	int length;
1033089Swyllys 	unsigned char enc_data[80];	/* data to encode */
1043089Swyllys 	int line_num;	/* number read on current line */
1053089Swyllys 	int expect_nl;
1063089Swyllys } PEM_ENCODE_CTX;
1073089Swyllys 
1083089Swyllys KMF_RETURN
1093089Swyllys Der2Pem(KMF_OBJECT_TYPE, unsigned char *, int, unsigned char **, int *);
1103089Swyllys 
1113089Swyllys KMF_RETURN
1123089Swyllys Pem2Der(unsigned char *, int, unsigned char **, int *);
1133089Swyllys 
1143089Swyllys #ifdef __cplusplus
1153089Swyllys }
1163089Swyllys #endif
1173089Swyllys #endif /* _PEM_ENCODE_H */
118