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