From e82f18fab47b698d93971f576f962a3068132912 Mon Sep 17 00:00:00 2001 From: cvs2svn Date: Mon, 5 Oct 1998 20:13:17 +0000 Subject: This commit was manufactured by cvs2git to create tag 'SSLeay_0_9_0b'. --- src/lib/libcrypto/asn1/Makefile.ssl | 120 +++++++++++++++ src/lib/libcrypto/asn1/a_bmp.c | 90 +++++++++++ src/lib/libcrypto/asn1/asn1.err | 182 ++++++++++++++++++++++ src/lib/libcrypto/asn1/d2i_dhp.c | 108 +++++++++++++ src/lib/libcrypto/asn1/d2i_dsap.c | 101 ++++++++++++ src/lib/libcrypto/asn1/d2i_r_pr.c | 129 ++++++++++++++++ src/lib/libcrypto/asn1/d2i_r_pu.c | 100 ++++++++++++ src/lib/libcrypto/asn1/d2i_s_pr.c | 113 ++++++++++++++ src/lib/libcrypto/asn1/d2i_s_pu.c | 124 +++++++++++++++ src/lib/libcrypto/asn1/f.c | 80 ++++++++++ src/lib/libcrypto/asn1/i2d_dhp.c | 128 +++++++++++++++ src/lib/libcrypto/asn1/i2d_dsap.c | 121 +++++++++++++++ src/lib/libcrypto/asn1/i2d_r_pr.c | 132 ++++++++++++++++ src/lib/libcrypto/asn1/i2d_r_pu.c | 118 ++++++++++++++ src/lib/libcrypto/asn1/i2d_s_pr.c | 128 +++++++++++++++ src/lib/libcrypto/asn1/i2d_s_pu.c | 133 ++++++++++++++++ src/lib/libcrypto/asn1/p7_dgst.c | 130 ++++++++++++++++ src/lib/libcrypto/asn1/p7_enc.c | 120 +++++++++++++++ src/lib/libcrypto/asn1/p7_enc_c.c | 127 +++++++++++++++ src/lib/libcrypto/asn1/p7_evp.c | 125 +++++++++++++++ src/lib/libcrypto/asn1/p7_i_s.c | 120 +++++++++++++++ src/lib/libcrypto/asn1/p7_lib.c | 299 ++++++++++++++++++++++++++++++++++++ src/lib/libcrypto/asn1/p7_recip.c | 132 ++++++++++++++++ src/lib/libcrypto/asn1/p7_s_e.c | 146 ++++++++++++++++++ src/lib/libcrypto/asn1/p7_signd.c | 140 +++++++++++++++++ src/lib/libcrypto/asn1/p7_signi.c | 149 ++++++++++++++++++ src/lib/libcrypto/asn1/pkcs8.c | 142 +++++++++++++++++ src/lib/libcrypto/asn1/x_cinf.c | 197 ++++++++++++++++++++++++ 28 files changed, 3734 insertions(+) create mode 100644 src/lib/libcrypto/asn1/Makefile.ssl create mode 100644 src/lib/libcrypto/asn1/a_bmp.c create mode 100644 src/lib/libcrypto/asn1/asn1.err create mode 100644 src/lib/libcrypto/asn1/d2i_dhp.c create mode 100644 src/lib/libcrypto/asn1/d2i_dsap.c create mode 100644 src/lib/libcrypto/asn1/d2i_r_pr.c create mode 100644 src/lib/libcrypto/asn1/d2i_r_pu.c create mode 100644 src/lib/libcrypto/asn1/d2i_s_pr.c create mode 100644 src/lib/libcrypto/asn1/d2i_s_pu.c create mode 100644 src/lib/libcrypto/asn1/f.c create mode 100644 src/lib/libcrypto/asn1/i2d_dhp.c create mode 100644 src/lib/libcrypto/asn1/i2d_dsap.c create mode 100644 src/lib/libcrypto/asn1/i2d_r_pr.c create mode 100644 src/lib/libcrypto/asn1/i2d_r_pu.c create mode 100644 src/lib/libcrypto/asn1/i2d_s_pr.c create mode 100644 src/lib/libcrypto/asn1/i2d_s_pu.c create mode 100644 src/lib/libcrypto/asn1/p7_dgst.c create mode 100644 src/lib/libcrypto/asn1/p7_enc.c create mode 100644 src/lib/libcrypto/asn1/p7_enc_c.c create mode 100644 src/lib/libcrypto/asn1/p7_evp.c create mode 100644 src/lib/libcrypto/asn1/p7_i_s.c create mode 100644 src/lib/libcrypto/asn1/p7_lib.c create mode 100644 src/lib/libcrypto/asn1/p7_recip.c create mode 100644 src/lib/libcrypto/asn1/p7_s_e.c create mode 100644 src/lib/libcrypto/asn1/p7_signd.c create mode 100644 src/lib/libcrypto/asn1/p7_signi.c create mode 100644 src/lib/libcrypto/asn1/pkcs8.c create mode 100644 src/lib/libcrypto/asn1/x_cinf.c (limited to 'src/lib/libcrypto/asn1') diff --git a/src/lib/libcrypto/asn1/Makefile.ssl b/src/lib/libcrypto/asn1/Makefile.ssl new file mode 100644 index 0000000000..30751bd156 --- /dev/null +++ b/src/lib/libcrypto/asn1/Makefile.ssl @@ -0,0 +1,120 @@ +# +# SSLeay/crypto/asn1/Makefile +# + +DIR= asn1 +TOP= ../.. +CC= cc +INCLUDES= -I.. -I../../include +CFLAG=-g +INSTALLTOP=/usr/local/ssl +MAKE= make -f Makefile.ssl +MAKEDEPEND= makedepend -f Makefile.ssl +MAKEFILE= Makefile.ssl +AR= ar r + +CFLAGS= $(INCLUDES) $(CFLAG) + +ERR=asn1 +ERRC=asn1_err +GENERAL=Makefile README +TEST= +APPS= + +LIB=$(TOP)/libcrypto.a +LIBSRC= a_object.c a_bitstr.c a_utctm.c a_int.c a_octet.c a_print.c \ + a_type.c a_set.c a_dup.c a_d2i_fp.c a_i2d_fp.c \ + a_sign.c a_digest.c a_verify.c \ + x_algor.c x_val.c x_pubkey.c x_sig.c x_req.c x_attrib.c \ + x_name.c x_cinf.c x_x509.c x_crl.c x_info.c x_spki.c \ + d2i_r_pr.c i2d_r_pr.c d2i_r_pu.c i2d_r_pu.c \ + d2i_s_pr.c i2d_s_pr.c d2i_s_pu.c i2d_s_pu.c \ + d2i_pu.c d2i_pr.c i2d_pu.c i2d_pr.c\ + t_req.c t_x509.c t_pkey.c \ + p7_i_s.c p7_signi.c p7_signd.c p7_recip.c p7_enc_c.c p7_evp.c \ + p7_dgst.c p7_s_e.c p7_enc.c p7_lib.c \ + f_int.c f_string.c i2d_dhp.c i2d_dsap.c d2i_dhp.c d2i_dsap.c n_pkey.c \ + a_hdr.c x_pkey.c a_bool.c x_exten.c \ + asn1_par.c asn1_lib.c $(ERRC).c a_meth.c a_bytes.c \ + evp_asn1.c +LIBOBJ= a_object.o a_bitstr.o a_utctm.o a_int.o a_octet.o a_print.o \ + a_type.o a_set.o a_dup.o a_d2i_fp.o a_i2d_fp.o \ + a_sign.o a_digest.o a_verify.o \ + x_algor.o x_val.o x_pubkey.o x_sig.o x_req.o x_attrib.o \ + x_name.o x_cinf.o x_x509.o x_crl.o x_info.o x_spki.o \ + d2i_r_pr.o i2d_r_pr.o d2i_r_pu.o i2d_r_pu.o \ + d2i_s_pr.o i2d_s_pr.o d2i_s_pu.o i2d_s_pu.o \ + d2i_pu.o d2i_pr.o i2d_pu.o i2d_pr.o \ + t_req.o t_x509.o t_pkey.o \ + p7_i_s.o p7_signi.o p7_signd.o p7_recip.o p7_enc_c.o p7_evp.o \ + p7_dgst.o p7_s_e.o p7_enc.o p7_lib.o \ + f_int.o f_string.o i2d_dhp.o i2d_dsap.o d2i_dhp.o d2i_dsap.o n_pkey.o \ + a_hdr.o x_pkey.o a_bool.o x_exten.o \ + asn1_par.o asn1_lib.o $(ERRC).o a_meth.o a_bytes.o \ + evp_asn1.o + +SRC= $(LIBSRC) + +EXHEADER= asn1.h asn1_mac.h +HEADER= $(EXHEADER) + +ALL= $(GENERAL) $(SRC) $(HEADER) + +top: + (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) + +test: test.c + cc -g -I../../include -c test.c + cc -g -I../../include -o test test.o -L../.. -lcrypto + +pk: pk.c + cc -g -I../../include -c pk.c + cc -g -I../../include -o pk pk.o -L../.. -lcrypto + +all: lib + +lib: $(LIBOBJ) + $(AR) $(LIB) $(LIBOBJ) + sh $(TOP)/util/ranlib.sh $(LIB) + @touch lib + +files: + perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + +links: + /bin/rm -f Makefile + $(TOP)/util/point.sh Makefile.ssl Makefile ; + $(TOP)/util/mklink.sh ../../include $(EXHEADER) + $(TOP)/util/mklink.sh ../../test $(TEST) + $(TOP)/util/mklink.sh ../../apps $(APPS) + +install: + @for i in $(EXHEADER) ; \ + do \ + (cp $$i $(INSTALLTOP)/include/$$i; \ + chmod 644 $(INSTALLTOP)/include/$$i ); \ + done; + +tags: + ctags $(SRC) + +tests: + +lint: + lint -DLINT $(INCLUDES) $(SRC)>fluff + +depend: + $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + +dclean: + perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + mv -f Makefile.new $(MAKEFILE) + +clean: + /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff + +errors: + perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h + perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c + +# DO NOT DELETE THIS LINE -- make depend depends on it. diff --git a/src/lib/libcrypto/asn1/a_bmp.c b/src/lib/libcrypto/asn1/a_bmp.c new file mode 100644 index 0000000000..774502b1fc --- /dev/null +++ b/src/lib/libcrypto/asn1/a_bmp.c @@ -0,0 +1,90 @@ +/* crypto/asn1/a_bmp.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include "asn1.h" + +/* ASN1err(ASN1_F_D2I_ASN1_INTEGER,ASN1_R_EXPECTING_AN_INTEGER); + */ + +int i2d_ASN1_BMPSTRING(a, pp) +ASN1_BMPSTRING *a; +unsigned char **pp; + { + return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, + V_ASN1_BMPSTRING,V_ASN1_UNIVERSAL)); + } + +ASN1_BMPSTRING *d2i_ASN1_BMPSTRING(a, pp, length) +ASN1_BMPSTRING **a; +unsigned char **pp; +long length; + { + ASN1_BMPSTRING *ret=NULL; + + ret=(ASN1_BMPSTRING *)d2i_ASN1_bytes((ASN1_STRING **)a, + pp,length,V_ASN1_BMPSTRING,V_ASN1_UNIVERSAL); + if (ret == NULL) + { + ASN1err(ASN1_F_D2I_ASN1_BMPSTRING,ASN1_R_ERROR_STACK); + return(NULL); + } + return(ret); + } + diff --git a/src/lib/libcrypto/asn1/asn1.err b/src/lib/libcrypto/asn1/asn1.err new file mode 100644 index 0000000000..c8b7011488 --- /dev/null +++ b/src/lib/libcrypto/asn1/asn1.err @@ -0,0 +1,182 @@ +/* Error codes for the ASN1 functions. */ + +/* Function codes. */ +#define ASN1_F_A2D_ASN1_OBJECT 100 +#define ASN1_F_A2I_ASN1_INTEGER 101 +#define ASN1_F_A2I_ASN1_STRING 102 +#define ASN1_F_ASN1_COLLATE_PRIMATIVE 103 +#define ASN1_F_ASN1_D2I_BIO 104 +#define ASN1_F_ASN1_D2I_FP 105 +#define ASN1_F_ASN1_DUP 106 +#define ASN1_F_ASN1_GET_OBJECT 107 +#define ASN1_F_ASN1_HEADER_NEW 108 +#define ASN1_F_ASN1_I2D_BIO 109 +#define ASN1_F_ASN1_I2D_FP 110 +#define ASN1_F_ASN1_INTEGER_SET 111 +#define ASN1_F_ASN1_INTEGER_TO_BN 112 +#define ASN1_F_ASN1_OBJECT_NEW 113 +#define ASN1_F_ASN1_SIGN 114 +#define ASN1_F_ASN1_STRING_NEW 115 +#define ASN1_F_ASN1_STRING_TYPE_NEW 116 +#define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 117 +#define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 118 +#define ASN1_F_ASN1_TYPE_NEW 119 +#define ASN1_F_ASN1_UTCTIME_NEW 120 +#define ASN1_F_ASN1_VERIFY 121 +#define ASN1_F_BN_TO_ASN1_INTEGER 122 +#define ASN1_F_D2I_ASN1_BIT_STRING 123 +#define ASN1_F_D2I_ASN1_BMPSTRING 124 +#define ASN1_F_D2I_ASN1_BOOLEAN 125 +#define ASN1_F_D2I_ASN1_BYTES 126 +#define ASN1_F_D2I_ASN1_HEADER 127 +#define ASN1_F_D2I_ASN1_INTEGER 128 +#define ASN1_F_D2I_ASN1_OBJECT 129 +#define ASN1_F_D2I_ASN1_OCTET_STRING 130 +#define ASN1_F_D2I_ASN1_PRINT_TYPE 131 +#define ASN1_F_D2I_ASN1_SET 132 +#define ASN1_F_D2I_ASN1_TYPE 133 +#define ASN1_F_D2I_ASN1_TYPE_BYTES 134 +#define ASN1_F_D2I_ASN1_UTCTIME 135 +#define ASN1_F_D2I_DHPARAMS 136 +#define ASN1_F_D2I_DSAPARAMS 137 +#define ASN1_F_D2I_DSAPRIVATEKEY 138 +#define ASN1_F_D2I_DSAPUBLICKEY 139 +#define ASN1_F_D2I_NETSCAPE_PKEY 140 +#define ASN1_F_D2I_NETSCAPE_RSA 141 +#define ASN1_F_D2I_NETSCAPE_RSA_2 142 +#define ASN1_F_D2I_NETSCAPE_SPKAC 143 +#define ASN1_F_D2I_NETSCAPE_SPKI 144 +#define ASN1_F_D2I_PKCS7 145 +#define ASN1_F_D2I_PKCS7_DIGEST 146 +#define ASN1_F_D2I_PKCS7_ENCRYPT 147 +#define ASN1_F_D2I_PKCS7_ENC_CONTENT 148 +#define ASN1_F_D2I_PKCS7_ENVELOPE 149 +#define ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL 150 +#define ASN1_F_D2I_PKCS7_RECIP_INFO 151 +#define ASN1_F_D2I_PKCS7_SIGNED 152 +#define ASN1_F_D2I_PKCS7_SIGNER_INFO 153 +#define ASN1_F_D2I_PKCS7_SIGN_ENVELOPE 154 +#define ASN1_F_D2I_PRIVATEKEY 155 +#define ASN1_F_D2I_PUBLICKEY 156 +#define ASN1_F_D2I_RSAPRIVATEKEY 157 +#define ASN1_F_D2I_RSAPUBLICKEY 158 +#define ASN1_F_D2I_X509 159 +#define ASN1_F_D2I_X509_ALGOR 160 +#define ASN1_F_D2I_X509_ATTRIBUTE 161 +#define ASN1_F_D2I_X509_CINF 162 +#define ASN1_F_D2I_X509_CRL 163 +#define ASN1_F_D2I_X509_CRL_INFO 164 +#define ASN1_F_D2I_X509_EXTENSION 165 +#define ASN1_F_D2I_X509_KEY 166 +#define ASN1_F_D2I_X509_NAME 167 +#define ASN1_F_D2I_X509_NAME_ENTRY 168 +#define ASN1_F_D2I_X509_PKEY 169 +#define ASN1_F_D2I_X509_PUBKEY 170 +#define ASN1_F_D2I_X509_REQ 171 +#define ASN1_F_D2I_X509_REQ_INFO 172 +#define ASN1_F_D2I_X509_REVOKED 173 +#define ASN1_F_D2I_X509_SIG 174 +#define ASN1_F_D2I_X509_VAL 175 +#define ASN1_F_I2D_ASN1_HEADER 176 +#define ASN1_F_I2D_DHPARAMS 177 +#define ASN1_F_I2D_DSAPARAMS 178 +#define ASN1_F_I2D_DSAPRIVATEKEY 179 +#define ASN1_F_I2D_DSAPUBLICKEY 180 +#define ASN1_F_I2D_NETSCAPE_RSA 181 +#define ASN1_F_I2D_PKCS7 182 +#define ASN1_F_I2D_PRIVATEKEY 183 +#define ASN1_F_I2D_PUBLICKEY 184 +#define ASN1_F_I2D_RSAPRIVATEKEY 185 +#define ASN1_F_I2D_RSAPUBLICKEY 186 +#define ASN1_F_I2D_X509_ATTRIBUTE 187 +#define ASN1_F_I2T_ASN1_OBJECT 188 +#define ASN1_F_NETSCAPE_PKEY_NEW 189 +#define ASN1_F_NETSCAPE_SPKAC_NEW 190 +#define ASN1_F_NETSCAPE_SPKI_NEW 191 +#define ASN1_F_PKCS7_DIGEST_NEW 192 +#define ASN1_F_PKCS7_ENCRYPT_NEW 193 +#define ASN1_F_PKCS7_ENC_CONTENT_NEW 194 +#define ASN1_F_PKCS7_ENVELOPE_NEW 195 +#define ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW 196 +#define ASN1_F_PKCS7_NEW 197 +#define ASN1_F_PKCS7_RECIP_INFO_NEW 198 +#define ASN1_F_PKCS7_SIGNED_NEW 199 +#define ASN1_F_PKCS7_SIGNER_INFO_NEW 200 +#define ASN1_F_PKCS7_SIGN_ENVELOPE_NEW 201 +#define ASN1_F_X509_ALGOR_NEW 202 +#define ASN1_F_X509_ATTRIBUTE_NEW 203 +#define ASN1_F_X509_CINF_NEW 204 +#define ASN1_F_X509_CRL_INFO_NEW 205 +#define ASN1_F_X509_CRL_NEW 206 +#define ASN1_F_X509_DHPARAMS_NEW 207 +#define ASN1_F_X509_EXTENSION_NEW 208 +#define ASN1_F_X509_INFO_NEW 209 +#define ASN1_F_X509_KEY_NEW 210 +#define ASN1_F_X509_NAME_ENTRY_NEW 211 +#define ASN1_F_X509_NAME_NEW 212 +#define ASN1_F_X509_NEW 213 +#define ASN1_F_X509_PKEY_NEW 214 +#define ASN1_F_X509_PUBKEY_NEW 215 +#define ASN1_F_X509_REQ_INFO_NEW 216 +#define ASN1_F_X509_REQ_NEW 217 +#define ASN1_F_X509_REVOKED_NEW 218 +#define ASN1_F_X509_SIG_NEW 219 +#define ASN1_F_X509_VAL_FREE 220 +#define ASN1_F_X509_VAL_NEW 221 + +/* Reason codes. */ +#define ASN1_R_BAD_CLASS 100 +#define ASN1_R_BAD_GET_OBJECT 101 +#define ASN1_R_BAD_OBJECT_HEADER 102 +#define ASN1_R_BAD_PASSWORD_READ 103 +#define ASN1_R_BAD_PKCS7_CONTENT 104 +#define ASN1_R_BAD_PKCS7_TYPE 105 +#define ASN1_R_BAD_TAG 106 +#define ASN1_R_BAD_TYPE 107 +#define ASN1_R_BN_LIB 108 +#define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 109 +#define ASN1_R_BUFFER_TOO_SMALL 110 +#define ASN1_R_DATA_IS_WRONG 111 +#define ASN1_R_DECODING_ERROR 112 +#define ASN1_R_ERROR_STACK 113 +#define ASN1_R_EXPECTING_AN_INTEGER 114 +#define ASN1_R_EXPECTING_AN_OBJECT 115 +#define ASN1_R_EXPECTING_AN_OCTET_STRING 116 +#define ASN1_R_EXPECTING_A_BIT_STRING 117 +#define ASN1_R_EXPECTING_A_BOOLEAN 118 +#define ASN1_R_EXPECTING_A_SEQUENCE 119 +#define ASN1_R_EXPECTING_A_UTCTIME 120 +#define ASN1_R_FIRST_NUM_TOO_LARGE 121 +#define ASN1_R_HEADER_TOO_LONG 122 +#define ASN1_R_INVALID_DIGIT 123 +#define ASN1_R_INVALID_SEPARATOR 124 +#define ASN1_R_INVALID_TIME_FORMAT 125 +#define ASN1_R_IV_TOO_LARGE 126 +#define ASN1_R_LENGTH_ERROR 127 +#define ASN1_R_LENGTH_MISMATCH 128 +#define ASN1_R_MISSING_EOS 129 +#define ASN1_R_MISSING_SECOND_NUMBER 130 +#define ASN1_R_NON_HEX_CHARACTERS 131 +#define ASN1_R_NOT_ENOUGH_DATA 132 +#define ASN1_R_ODD_NUMBER_OF_CHARS 133 +#define ASN1_R_PARSING 134 +#define ASN1_R_PRIVATE_KEY_HEADER_MISSING 135 +#define ASN1_R_SECOND_NUMBER_TOO_LARGE 136 +#define ASN1_R_SHORT_LINE 137 +#define ASN1_R_STRING_TOO_SHORT 138 +#define ASN1_R_TAG_VALUE_TOO_HIGH 139 +#define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 140 +#define ASN1_R_TOO_LONG 141 +#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 142 +#define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 143 +#define ASN1_R_UNKNOWN_ATTRIBUTE_TYPE 144 +#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 145 +#define ASN1_R_UNKNOWN_OBJECT_TYPE 146 +#define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 147 +#define ASN1_R_UNSUPPORTED_CIPHER 148 +#define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 149 +#define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 150 +#define ASN1_R_UTCTIME_TOO_LONG 151 +#define ASN1_R_WRONG_PRINTABLE_TYPE 152 +#define ASN1_R_WRONG_TAG 153 +#define ASN1_R_WRONG_TYPE 154 diff --git a/src/lib/libcrypto/asn1/d2i_dhp.c b/src/lib/libcrypto/asn1/d2i_dhp.c new file mode 100644 index 0000000000..616a308100 --- /dev/null +++ b/src/lib/libcrypto/asn1/d2i_dhp.c @@ -0,0 +1,108 @@ +/* crypto/asn1/d2i_dhp.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include "bn.h" +#include "dh.h" +#include "objects.h" +#include "asn1_mac.h" + +/* + * ASN1err(ASN1_F_D2I_DHPARAMS,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_I2D_DHPARAMS,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); + */ + +DH *d2i_DHparams(a,pp,length) +DH **a; +unsigned char **pp; +long length; + { + int i=ASN1_R_ERROR_STACK; + ASN1_INTEGER *bs=NULL; + long v=0; + M_ASN1_D2I_vars(a,DH *,DH_new); + + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->p=BN_bin2bn(bs->data,bs->length,ret->p)) == NULL) goto err_bn; + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->g=BN_bin2bn(bs->data,bs->length,ret->g)) == NULL) goto err_bn; + + if (!M_ASN1_D2I_end_sequence()) + { + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + for (i=0; ilength; i++) + v=(v<<8)|(bs->data[i]); + ret->length=(int)v; + } + + ASN1_BIT_STRING_free(bs); + + M_ASN1_D2I_Finish_2(a); + +err_bn: + i=ERR_R_BN_LIB; +err: + ASN1err(ASN1_F_D2I_DHPARAMS,i); + if ((ret != NULL) && ((a == NULL) || (*a != ret))) DH_free(ret); + if (bs != NULL) ASN1_BIT_STRING_free(bs); + return(NULL); + } + diff --git a/src/lib/libcrypto/asn1/d2i_dsap.c b/src/lib/libcrypto/asn1/d2i_dsap.c new file mode 100644 index 0000000000..2c8ac7bbcf --- /dev/null +++ b/src/lib/libcrypto/asn1/d2i_dsap.c @@ -0,0 +1,101 @@ +/* crypto/asn1/d2i_dsap.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include "bn.h" +#include "dsa.h" +#include "objects.h" +#include "asn1_mac.h" + +/* + * ASN1err(ASN1_F_D2I_DSAPARAMS,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_I2D_DSAPARAMS,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); + */ + +DSA *d2i_DSAparams(a,pp,length) +DSA **a; +unsigned char **pp; +long length; + { + int i=ASN1_R_ERROR_STACK; + ASN1_INTEGER *bs=NULL; + M_ASN1_D2I_vars(a,DSA *,DSA_new); + + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->p=BN_bin2bn(bs->data,bs->length,ret->p)) == NULL) goto err_bn; + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->q=BN_bin2bn(bs->data,bs->length,ret->q)) == NULL) goto err_bn; + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->g=BN_bin2bn(bs->data,bs->length,ret->g)) == NULL) goto err_bn; + + ASN1_BIT_STRING_free(bs); + + M_ASN1_D2I_Finish_2(a); + +err_bn: + i=ERR_R_BN_LIB; +err: + ASN1err(ASN1_F_D2I_DSAPARAMS,i); + if ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_free(ret); + if (bs != NULL) ASN1_BIT_STRING_free(bs); + return(NULL); + } + diff --git a/src/lib/libcrypto/asn1/d2i_r_pr.c b/src/lib/libcrypto/asn1/d2i_r_pr.c new file mode 100644 index 0000000000..0c53aa94bf --- /dev/null +++ b/src/lib/libcrypto/asn1/d2i_r_pr.c @@ -0,0 +1,129 @@ +/* crypto/asn1/d2i_r_pr.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include "bn.h" +#include "rsa.h" +#include "objects.h" +#include "asn1_mac.h" + +/* + * ASN1err(ASN1_F_D2I_RSAPRIVATEKEY,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_I2D_RSAPRIVATEKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); + * ASN1err(ASN1_F_I2D_RSAPRIVATEKEY,ASN1_R_PARSING); + */ + +static ASN1_METHOD method={ + (int (*)()) i2d_RSAPrivateKey, + (char *(*)())d2i_RSAPrivateKey, + (char *(*)())RSA_new, + (void (*)()) RSA_free}; + +ASN1_METHOD *RSAPrivateKey_asn1_meth() + { + return(&method); + } + +RSA *d2i_RSAPrivateKey(a,pp,length) +RSA **a; +unsigned char **pp; +long length; + { + int i=ASN1_R_PARSING; + ASN1_INTEGER *bs=NULL; + M_ASN1_D2I_vars(a,RSA *,RSA_new); + + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if (bs->length == 0) + ret->version=0; + else ret->version=bs->data[0]; + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->n=BN_bin2bn(bs->data,bs->length,ret->n)) == NULL) goto err_bn; + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->e=BN_bin2bn(bs->data,bs->length,ret->e)) == NULL) goto err_bn; + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->d=BN_bin2bn(bs->data,bs->length,ret->d)) == NULL) goto err_bn; + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->p=BN_bin2bn(bs->data,bs->length,ret->p)) == NULL) goto err_bn; + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->q=BN_bin2bn(bs->data,bs->length,ret->q)) == NULL) goto err_bn; + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->dmp1=BN_bin2bn(bs->data,bs->length,ret->dmp1)) == NULL) + goto err_bn; + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->dmq1=BN_bin2bn(bs->data,bs->length,ret->dmq1)) == NULL) + goto err_bn; + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->iqmp=BN_bin2bn(bs->data,bs->length,ret->iqmp)) == NULL) + goto err_bn; + + ASN1_INTEGER_free(bs); + + M_ASN1_D2I_Finish_2(a); +err_bn: + i=ERR_R_BN_LIB; +err: + ASN1err(ASN1_F_D2I_RSAPRIVATEKEY,i); + if ((ret != NULL) && ((a == NULL) || (*a != ret))) RSA_free(ret); + if (bs != NULL) ASN1_INTEGER_free(bs); + return(NULL); + } + diff --git a/src/lib/libcrypto/asn1/d2i_r_pu.c b/src/lib/libcrypto/asn1/d2i_r_pu.c new file mode 100644 index 0000000000..778b792b1e --- /dev/null +++ b/src/lib/libcrypto/asn1/d2i_r_pu.c @@ -0,0 +1,100 @@ +/* crypto/asn1/d2i_r_pu.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include "bn.h" +#include "rsa.h" +#include "objects.h" +#include "asn1_mac.h" + +/* + * ASN1err(ASN1_F_D2I_RSAPUBLICKEY,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_I2D_RSAPUBLICKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); + */ + +RSA *d2i_RSAPublicKey(a,pp,length) +RSA **a; +unsigned char **pp; +long length; + { + int i=ASN1_R_PARSING; + ASN1_INTEGER *bs=NULL; + M_ASN1_D2I_vars(a,RSA *,RSA_new); + + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->n=BN_bin2bn(bs->data,bs->length,ret->n)) == NULL) goto err_bn; + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->e=BN_bin2bn(bs->data,bs->length,ret->e)) == NULL) goto err_bn; + + ASN1_INTEGER_free(bs); + bs=NULL; + + M_ASN1_D2I_Finish_2(a); + +err_bn: + i=ERR_R_BN_LIB; +err: + ASN1err(ASN1_F_D2I_RSAPUBLICKEY,i); + if ((ret != NULL) && ((a == NULL) || (*a != ret))) RSA_free(ret); + if (bs != NULL) ASN1_INTEGER_free(bs); + return(NULL); + } + diff --git a/src/lib/libcrypto/asn1/d2i_s_pr.c b/src/lib/libcrypto/asn1/d2i_s_pr.c new file mode 100644 index 0000000000..32ff8ba4b3 --- /dev/null +++ b/src/lib/libcrypto/asn1/d2i_s_pr.c @@ -0,0 +1,113 @@ +/* crypto/asn1/d2i_s_pr.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +/* Origional version from Steven Schoch */ + +#include +#include "cryptlib.h" +#include "bn.h" +#include "dsa.h" +#include "objects.h" +#include "asn1_mac.h" + +/* + * ASN1err(ASN1_F_D2I_DSAPRIVATEKEY,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_I2D_DSAPRIVATEKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); + * ASN1err(ASN1_F_I2D_DSAPRIVATEKEY,ASN1_R_PARSING); + */ + +DSA *d2i_DSAPrivateKey(a,pp,length) +DSA **a; +unsigned char **pp; +long length; + { + int i=ASN1_R_PARSING; + ASN1_INTEGER *bs=NULL; + M_ASN1_D2I_vars(a,DSA *,DSA_new); + + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if (bs->length == 0) + ret->version=0; + else ret->version=bs->data[0]; + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->p=BN_bin2bn(bs->data,bs->length,ret->p)) == NULL) goto err_bn; + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->q=BN_bin2bn(bs->data,bs->length,ret->q)) == NULL) goto err_bn; + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->g=BN_bin2bn(bs->data,bs->length,ret->g)) == NULL) goto err_bn; + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->pub_key=BN_bin2bn(bs->data,bs->length,ret->pub_key)) + == NULL) goto err_bn; + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->priv_key=BN_bin2bn(bs->data,bs->length,ret->priv_key)) + == NULL) goto err_bn; + + ASN1_INTEGER_free(bs); + + M_ASN1_D2I_Finish_2(a); +err_bn: + i=ERR_R_BN_LIB; +err: + ASN1err(ASN1_F_D2I_DSAPRIVATEKEY,i); + if ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_free(ret); + if (bs != NULL) ASN1_INTEGER_free(bs); + return(NULL); + } + diff --git a/src/lib/libcrypto/asn1/d2i_s_pu.c b/src/lib/libcrypto/asn1/d2i_s_pu.c new file mode 100644 index 0000000000..1002f41cd8 --- /dev/null +++ b/src/lib/libcrypto/asn1/d2i_s_pu.c @@ -0,0 +1,124 @@ +/* crypto/asn1/d2i_s_pu.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +/* Origional version from Steven Schoch */ + +#include +#include "cryptlib.h" +#include "bn.h" +#include "dsa.h" +#include "objects.h" +#include "asn1_mac.h" + +/* + * ASN1err(ASN1_F_D2I_DSAPUBLICKEY,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_I2D_DSAPUBLICKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); + */ + +DSA *d2i_DSAPublicKey(a,pp,length) +DSA **a; +unsigned char **pp; +long length; + { + int i=ASN1_R_PARSING; + ASN1_INTEGER *bs=NULL; + M_ASN1_D2I_vars(a,DSA *,DSA_new); + + M_ASN1_D2I_Init(); + if ((length != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) + == (V_ASN1_UNIVERSAL|(V_ASN1_INTEGER)))) + { + c.slen=length; + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->pub_key=BN_bin2bn(bs->data,bs->length,ret->pub_key)) + == NULL) + goto err_bn; + ret->write_params=0; + } + else + { + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->pub_key=BN_bin2bn(bs->data,bs->length,ret->pub_key)) + == NULL) + goto err_bn; + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->p=BN_bin2bn(bs->data,bs->length,ret->p)) == NULL) + goto err_bn; + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->q=BN_bin2bn(bs->data,bs->length,ret->q)) == NULL) + goto err_bn; + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->g=BN_bin2bn(bs->data,bs->length,ret->g)) == NULL) + goto err_bn; + + ret->write_params=1; + } + + ASN1_INTEGER_free(bs); + bs=NULL; + M_ASN1_D2I_Finish_2(a); +err_bn: + i=ERR_R_BN_LIB; +err: + ASN1err(ASN1_F_D2I_DSAPUBLICKEY,i); + if ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_free(ret); + if (bs != NULL) ASN1_INTEGER_free(bs); + return(NULL); + } + diff --git a/src/lib/libcrypto/asn1/f.c b/src/lib/libcrypto/asn1/f.c new file mode 100644 index 0000000000..2ab3a262ac --- /dev/null +++ b/src/lib/libcrypto/asn1/f.c @@ -0,0 +1,80 @@ +/* crypto/asn1/f.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ +#include +#include "asn1.h" +#include "err.h" + +main() + { + ASN1_TYPE *at; + char buf[512]; + int n; + long l; + + at=ASN1_TYPE_new(); + + n=ASN1_TYPE_set_int_octetstring(at,98736,"01234567",8); + printf("%d\n",n); + n=ASN1_TYPE_get_int_octetstring(at,&l,buf,8); + buf[8]='\0'; + printf("%ld %d %d\n",l,n,buf[8]); + buf[8]='\0'; + printf("%s\n",buf); + ERR_load_crypto_strings(); + ERR_print_errors_fp(stderr); + } diff --git a/src/lib/libcrypto/asn1/i2d_dhp.c b/src/lib/libcrypto/asn1/i2d_dhp.c new file mode 100644 index 0000000000..a454025ce3 --- /dev/null +++ b/src/lib/libcrypto/asn1/i2d_dhp.c @@ -0,0 +1,128 @@ +/* crypto/asn1/i2d_dhp.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include "bn.h" +#include "asn1_mac.h" +#include "dh.h" + +/* + * ASN1err(ASN1_F_D2I_DHPARAMS,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_X509_DHPARAMS_NEW,ASN1_R_LENGTH_MISMATCH); + */ + +int i2d_DHparams(a,pp) +DH *a; +unsigned char **pp; + { + BIGNUM *num[3]; + ASN1_INTEGER bs; + unsigned int j,i,tot=0,len,max=0; + int t,ret= -1; + unsigned char *p; + + if (a == NULL) return(0); + num[0]=a->p; + num[1]=a->g; + if (a->length != 0) + { + if ((num[2]=BN_new()) == NULL) goto err; + if (!BN_set_word(num[2],a->length)) goto err; + } + else + num[2]=NULL; + + for (i=0; i<3; i++) + { + if (num[i] == NULL) continue; + j=BN_num_bits(num[i]); + len=((j == 0)?0:((j/8)+1)); + if (len > max) max=len; + len=ASN1_object_size(0,len, + (num[i]->neg)?V_ASN1_NEG_INTEGER:V_ASN1_INTEGER); + tot+=len; + } + + t=ASN1_object_size(1,tot,V_ASN1_SEQUENCE); + if (pp == NULL) return(t); + + p= *pp; + ASN1_put_object(&p,1,tot,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); + + bs.type=V_ASN1_INTEGER; + bs.data=(unsigned char *)Malloc(max+4); + if (bs.data == NULL) + { + ASN1err(ASN1_F_I2D_DHPARAMS,ERR_R_MALLOC_FAILURE); + goto err; + } + + for (i=0; i<3; i++) + { + if (num[i] == NULL) continue; + bs.length=BN_bn2bin(num[i],bs.data); + i2d_ASN1_INTEGER(&bs,&p); + } + Free((char *)bs.data); + ret=t; +err: + if (num[2] != NULL) BN_free(num[2]); + *pp=p; + return(ret); + } diff --git a/src/lib/libcrypto/asn1/i2d_dsap.c b/src/lib/libcrypto/asn1/i2d_dsap.c new file mode 100644 index 0000000000..94ecff1525 --- /dev/null +++ b/src/lib/libcrypto/asn1/i2d_dsap.c @@ -0,0 +1,121 @@ +/* crypto/asn1/i2d_dsap.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include "bn.h" +#include "asn1_mac.h" +#include "dsa.h" + +/* + * ASN1err(ASN1_F_D2I_DSAPARAMS,ASN1_R_LENGTH_MISMATCH); + */ + +int i2d_DSAparams(a,pp) +DSA *a; +unsigned char **pp; + { + BIGNUM *num[3]; + ASN1_INTEGER bs; + unsigned int j,i,tot=0,len,max=0; + int t,ret= -1; + unsigned char *p; + + if (a == NULL) return(0); + num[0]=a->p; + num[1]=a->q; + num[2]=a->g; + + for (i=0; i<3; i++) + { + if (num[i] == NULL) continue; + j=BN_num_bits(num[i]); + len=((j == 0)?0:((j/8)+1)); + if (len > max) max=len; + len=ASN1_object_size(0,len, + (num[i]->neg)?V_ASN1_NEG_INTEGER:V_ASN1_INTEGER); + tot+=len; + } + + t=ASN1_object_size(1,tot,V_ASN1_SEQUENCE); + if (pp == NULL) return(t); + + p= *pp; + ASN1_put_object(&p,1,tot,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); + + bs.type=V_ASN1_INTEGER; + bs.data=(unsigned char *)Malloc(max+4); + if (bs.data == NULL) + { + ASN1err(ASN1_F_I2D_DSAPARAMS,ERR_R_MALLOC_FAILURE); + goto err; + } + + for (i=0; i<3; i++) + { + if (num[i] == NULL) continue; + bs.length=BN_bn2bin(num[i],bs.data); + i2d_ASN1_INTEGER(&bs,&p); + } + Free((char *)bs.data); + ret=t; +err: + *pp=p; + return(ret); + } + diff --git a/src/lib/libcrypto/asn1/i2d_r_pr.c b/src/lib/libcrypto/asn1/i2d_r_pr.c new file mode 100644 index 0000000000..aadbb92d8e --- /dev/null +++ b/src/lib/libcrypto/asn1/i2d_r_pr.c @@ -0,0 +1,132 @@ +/* crypto/asn1/i2d_r_pr.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include "bn.h" +#include "rsa.h" +#include "objects.h" +#include "asn1_mac.h" + +/* + * ASN1err(ASN1_F_D2I_RSAPRIVATEKEY,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_I2D_RSAPRIVATEKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); + */ + +int i2d_RSAPrivateKey(a,pp) +RSA *a; +unsigned char **pp; + { + BIGNUM *num[9]; + unsigned char data[1]; + ASN1_INTEGER bs; + unsigned int j,i,tot,t,len,max=0; + unsigned char *p; + + if (a == NULL) return(0); + + num[1]=a->n; + num[2]=a->e; + num[3]=a->d; + num[4]=a->p; + num[5]=a->q; + num[6]=a->dmp1; + num[7]=a->dmq1; + num[8]=a->iqmp; + + bs.length=1; + bs.data=data; + bs.type=V_ASN1_INTEGER; + data[0]=a->version&0x7f; + + tot=i2d_ASN1_INTEGER(&(bs),NULL); + for (i=1; i<9; i++) + { + j=BN_num_bits(num[i]); + len=((j == 0)?0:((j/8)+1)); + if (len > max) max=len; + len=ASN1_object_size(0,len, + (num[i]->neg)?V_ASN1_NEG_INTEGER:V_ASN1_INTEGER); + tot+=len; + } + + t=ASN1_object_size(1,tot,V_ASN1_SEQUENCE); + if (pp == NULL) return(t); + + p= *pp; + ASN1_put_object(&p,1,tot,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); + + i2d_ASN1_INTEGER(&bs,&p); + + bs.data=(unsigned char *)Malloc(max+4); + if (bs.data == NULL) + { + ASN1err(ASN1_F_I2D_RSAPRIVATEKEY,ERR_R_MALLOC_FAILURE); + return(-1); + } + + for (i=1; i<9; i++) + { + bs.length=BN_bn2bin(num[i],bs.data); + i2d_ASN1_INTEGER(&bs,&p); + } + Free((char *)bs.data); + *pp=p; + return(t); + } + diff --git a/src/lib/libcrypto/asn1/i2d_r_pu.c b/src/lib/libcrypto/asn1/i2d_r_pu.c new file mode 100644 index 0000000000..3c54f6709d --- /dev/null +++ b/src/lib/libcrypto/asn1/i2d_r_pu.c @@ -0,0 +1,118 @@ +/* crypto/asn1/i2d_r_pu.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include "bn.h" +#include "rsa.h" +#include "objects.h" +#include "asn1_mac.h" + +/* + * ASN1err(ASN1_F_D2I_RSAPUBLICKEY,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_I2D_RSAPUBLICKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); + */ + +int i2d_RSAPublicKey(a,pp) +RSA *a; +unsigned char **pp; + { + BIGNUM *num[2]; + ASN1_INTEGER bs; + unsigned int j,i,tot=0,len,max=0,t; + unsigned char *p; + + if (a == NULL) return(0); + + num[0]=a->n; + num[1]=a->e; + + for (i=0; i<2; i++) + { + j=BN_num_bits(num[i]); + len=((j == 0)?0:((j/8)+1)); + if (len > max) max=len; + len=ASN1_object_size(0,len, + (num[i]->neg)?V_ASN1_NEG_INTEGER:V_ASN1_INTEGER); + tot+=len; + } + + t=ASN1_object_size(1,tot,V_ASN1_SEQUENCE); + if (pp == NULL) return(t); + + p= *pp; + ASN1_put_object(&p,1,tot,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); + + bs.type=V_ASN1_INTEGER; + bs.data=(unsigned char *)Malloc(max+4); + if (bs.data == NULL) + { + ASN1err(ASN1_F_I2D_RSAPUBLICKEY,ERR_R_MALLOC_FAILURE); + return(-1); + } + + for (i=0; i<2; i++) + { + bs.length=BN_bn2bin(num[i],bs.data); + i2d_ASN1_INTEGER(&bs,&p); + } + Free((char *)bs.data); + *pp=p; + return(t); + } + diff --git a/src/lib/libcrypto/asn1/i2d_s_pr.c b/src/lib/libcrypto/asn1/i2d_s_pr.c new file mode 100644 index 0000000000..6e95305548 --- /dev/null +++ b/src/lib/libcrypto/asn1/i2d_s_pr.c @@ -0,0 +1,128 @@ +/* crypto/asn1/i2d_s_pr.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include "bn.h" +#include "dsa.h" +#include "objects.h" +#include "asn1_mac.h" + +/* + * ASN1err(ASN1_F_I2D_DSAPRIVATEKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); + */ + +int i2d_DSAPrivateKey(a,pp) +DSA *a; +unsigned char **pp; + { + BIGNUM *num[6]; + unsigned char data[1]; + ASN1_INTEGER bs; + unsigned int j,i,tot,t,len,max=0; + unsigned char *p; + + if (a == NULL) return(0); + + num[1]=a->p; + num[2]=a->q; + num[3]=a->g; + num[4]=a->pub_key; + num[5]=a->priv_key; + + bs.length=1; + bs.data=data; + bs.type=V_ASN1_INTEGER; + data[0]=a->version&0x7f; + + tot=i2d_ASN1_INTEGER(&(bs),NULL); + for (i=1; i<6; i++) + { + j=BN_num_bits(num[i]); + len=((j == 0)?0:((j/8)+1)); + if (len > max) max=len; + len=ASN1_object_size(0,len, + (num[i]->neg)?V_ASN1_NEG_INTEGER:V_ASN1_INTEGER); + tot+=len; + } + + t=ASN1_object_size(1,tot,V_ASN1_SEQUENCE); + if (pp == NULL) return(t); + + p= *pp; + ASN1_put_object(&p,1,tot,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); + + i2d_ASN1_INTEGER(&bs,&p); + + bs.data=(unsigned char *)Malloc(max+4); + if (bs.data == NULL) + { + ASN1err(ASN1_F_I2D_DSAPRIVATEKEY,ERR_R_MALLOC_FAILURE); + return(-1); + } + + for (i=1; i<6; i++) + { + bs.length=BN_bn2bin(num[i],bs.data); + i2d_ASN1_INTEGER(&bs,&p); + } + Free((char *)bs.data); + *pp=p; + return(t); + } + diff --git a/src/lib/libcrypto/asn1/i2d_s_pu.c b/src/lib/libcrypto/asn1/i2d_s_pu.c new file mode 100644 index 0000000000..5cf2877069 --- /dev/null +++ b/src/lib/libcrypto/asn1/i2d_s_pu.c @@ -0,0 +1,133 @@ +/* crypto/asn1/i2d_s_pu.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include "bn.h" +#include "dsa.h" +#include "objects.h" +#include "asn1_mac.h" + +/* + * ASN1err(ASN1_F_I2D_DSAPUBLICKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); + */ + +int i2d_DSAPublicKey(a,pp) +DSA *a; +unsigned char **pp; + { + BIGNUM *num[4]; + ASN1_INTEGER bs; + unsigned int j,i,tot=0,len,max=0,t=0,all,n=1; + unsigned char *p; + + if (a == NULL) return(0); + + all=a->write_params; + + num[0]=a->pub_key; + if (all) + { + num[1]=a->p; + num[2]=a->q; + num[3]=a->g; + n=4; + } + + for (i=0; i max) max=len; + len=ASN1_object_size(0,len, + (num[i]->neg)?V_ASN1_NEG_INTEGER:V_ASN1_INTEGER); + tot+=len; + } + + if (all) + { + t=ASN1_object_size(1,tot,V_ASN1_SEQUENCE); + if (pp == NULL) return(t); + } + else + { + if (pp == NULL) return(tot); + } + + p= *pp; + if (all) + ASN1_put_object(&p,1,tot,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); + + bs.type=V_ASN1_INTEGER; + bs.data=(unsigned char *)Malloc(max+4); + if (bs.data == NULL) + { + ASN1err(ASN1_F_I2D_DSAPUBLICKEY,ERR_R_MALLOC_FAILURE); + return(-1); + } + + for (i=0; i +#include "cryptlib.h" +#include "asn1_mac.h" +#include "x509.h" + +/* + * ASN1err(ASN1_F_PKCS7_DIGEST_NEW,ASN1_R_MISSING_EOS); + * ASN1err(ASN1_F_D2I_PKCS7_DIGEST,ASN1_R_LENGTH_MISMATCH); + */ + +int i2d_PKCS7_DIGEST(a,pp) +PKCS7_DIGEST *a; +unsigned char **pp; + { + M_ASN1_I2D_vars(a); + + M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); + M_ASN1_I2D_len(a->md,i2d_X509_ALGOR); + M_ASN1_I2D_len(a->contents,i2d_PKCS7); + M_ASN1_I2D_len(a->digest,i2d_ASN1_OCTET_STRING); + + M_ASN1_I2D_seq_total(); + + M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER); + M_ASN1_I2D_put(a->md,i2d_X509_ALGOR); + M_ASN1_I2D_put(a->contents,i2d_PKCS7); + M_ASN1_I2D_put(a->digest,i2d_ASN1_OCTET_STRING); + + M_ASN1_I2D_finish(); + } + +PKCS7_DIGEST *d2i_PKCS7_DIGEST(a,pp,length) +PKCS7_DIGEST **a; +unsigned char **pp; +long length; + { + M_ASN1_D2I_vars(a,PKCS7_DIGEST *,PKCS7_DIGEST_new); + + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); + M_ASN1_D2I_get(ret->md,d2i_X509_ALGOR); + M_ASN1_D2I_get(ret->contents,d2i_PKCS7); + M_ASN1_D2I_get(ret->digest,d2i_ASN1_OCTET_STRING); + + M_ASN1_D2I_Finish(a,PKCS7_DIGEST_free,ASN1_F_D2I_PKCS7_DIGEST); + } + +PKCS7_DIGEST *PKCS7_DIGEST_new() + { + PKCS7_DIGEST *ret=NULL; + + M_ASN1_New_Malloc(ret,PKCS7_DIGEST); + M_ASN1_New(ret->version,ASN1_INTEGER_new); + M_ASN1_New(ret->md,X509_ALGOR_new); + M_ASN1_New(ret->contents,PKCS7_new); + M_ASN1_New(ret->digest,ASN1_OCTET_STRING_new); + return(ret); + M_ASN1_New_Error(ASN1_F_PKCS7_DIGEST_NEW); + } + +void PKCS7_DIGEST_free(a) +PKCS7_DIGEST *a; + { + if (a == NULL) return; + ASN1_INTEGER_free(a->version); + X509_ALGOR_free(a->md); + PKCS7_free(a->contents); + ASN1_OCTET_STRING_free(a->digest); + Free((char *)a); + } + diff --git a/src/lib/libcrypto/asn1/p7_enc.c b/src/lib/libcrypto/asn1/p7_enc.c new file mode 100644 index 0000000000..874dd78389 --- /dev/null +++ b/src/lib/libcrypto/asn1/p7_enc.c @@ -0,0 +1,120 @@ +/* crypto/asn1/p7_enc.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include "asn1_mac.h" +#include "x509.h" + +/* + * ASN1err(ASN1_F_PKCS7_ENCRYPT_NEW,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_PKCS7_ENCRYPT,ASN1_R_LENGTH_MISMATCH); + */ + +int i2d_PKCS7_ENCRYPT(a,pp) +PKCS7_ENCRYPT *a; +unsigned char **pp; + { + M_ASN1_I2D_vars(a); + + M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); + M_ASN1_I2D_len(a->enc_data,i2d_PKCS7_ENC_CONTENT); + + M_ASN1_I2D_seq_total(); + + M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER); + M_ASN1_I2D_put(a->enc_data,i2d_PKCS7_ENC_CONTENT); + + M_ASN1_I2D_finish(); + } + +PKCS7_ENCRYPT *d2i_PKCS7_ENCRYPT(a,pp,length) +PKCS7_ENCRYPT **a; +unsigned char **pp; +long length; + { + M_ASN1_D2I_vars(a,PKCS7_ENCRYPT *,PKCS7_ENCRYPT_new); + + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); + M_ASN1_D2I_get(ret->enc_data,d2i_PKCS7_ENC_CONTENT); + + M_ASN1_D2I_Finish(a,PKCS7_ENCRYPT_free,ASN1_F_D2I_PKCS7_ENCRYPT); + } + +PKCS7_ENCRYPT *PKCS7_ENCRYPT_new() + { + PKCS7_ENCRYPT *ret=NULL; + + M_ASN1_New_Malloc(ret,PKCS7_ENCRYPT); + M_ASN1_New(ret->version,ASN1_INTEGER_new); + M_ASN1_New(ret->enc_data,PKCS7_ENC_CONTENT_new); + return(ret); + M_ASN1_New_Error(ASN1_F_PKCS7_ENCRYPT_NEW); + } + +void PKCS7_ENCRYPT_free(a) +PKCS7_ENCRYPT *a; + { + if (a == NULL) return; + ASN1_INTEGER_free(a->version); + PKCS7_ENC_CONTENT_free(a->enc_data); + Free((char *)a); + } + diff --git a/src/lib/libcrypto/asn1/p7_enc_c.c b/src/lib/libcrypto/asn1/p7_enc_c.c new file mode 100644 index 0000000000..2860d3e925 --- /dev/null +++ b/src/lib/libcrypto/asn1/p7_enc_c.c @@ -0,0 +1,127 @@ +/* crypto/asn1/p7_enc_c.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include "asn1_mac.h" +#include "x509.h" + +/* + * ASN1err(ASN1_F_PKCS7_ENC_CONTENT_NEW,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_PKCS7_ENC_CONTENT,ASN1_R_LENGTH_MISMATCH); + */ + +int i2d_PKCS7_ENC_CONTENT(a,pp) +PKCS7_ENC_CONTENT *a; +unsigned char **pp; + { + M_ASN1_I2D_vars(a); + + M_ASN1_I2D_len(a->content_type,i2d_ASN1_OBJECT); + M_ASN1_I2D_len(a->algorithm,i2d_X509_ALGOR); + M_ASN1_I2D_len_IMP_opt(a->enc_data,i2d_ASN1_OCTET_STRING); + + M_ASN1_I2D_seq_total(); + + M_ASN1_I2D_put(a->content_type,i2d_ASN1_OBJECT); + M_ASN1_I2D_put(a->algorithm,i2d_X509_ALGOR); + M_ASN1_I2D_put_IMP_opt(a->enc_data,i2d_ASN1_OCTET_STRING,0); + + M_ASN1_I2D_finish(); + } + +PKCS7_ENC_CONTENT *d2i_PKCS7_ENC_CONTENT(a,pp,length) +PKCS7_ENC_CONTENT **a; +unsigned char **pp; +long length; + { + M_ASN1_D2I_vars(a,PKCS7_ENC_CONTENT *,PKCS7_ENC_CONTENT_new); + + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get(ret->content_type,d2i_ASN1_OBJECT); + M_ASN1_D2I_get(ret->algorithm,d2i_X509_ALGOR); + M_ASN1_D2I_get_IMP_opt(ret->enc_data,d2i_ASN1_OCTET_STRING,0, + V_ASN1_OCTET_STRING); + + M_ASN1_D2I_Finish(a,PKCS7_ENC_CONTENT_free, + ASN1_F_D2I_PKCS7_ENC_CONTENT); + } + +PKCS7_ENC_CONTENT *PKCS7_ENC_CONTENT_new() + { + PKCS7_ENC_CONTENT *ret=NULL; + + M_ASN1_New_Malloc(ret,PKCS7_ENC_CONTENT); + M_ASN1_New(ret->content_type,ASN1_OBJECT_new); + M_ASN1_New(ret->algorithm,X509_ALGOR_new); + ret->enc_data=NULL; + return(ret); + M_ASN1_New_Error(ASN1_F_PKCS7_ENC_CONTENT_NEW); + } + +void PKCS7_ENC_CONTENT_free(a) +PKCS7_ENC_CONTENT *a; + { + if (a == NULL) return; + ASN1_OBJECT_free(a->content_type); + X509_ALGOR_free(a->algorithm); + ASN1_OCTET_STRING_free(a->enc_data); + Free((char *)a); + } + diff --git a/src/lib/libcrypto/asn1/p7_evp.c b/src/lib/libcrypto/asn1/p7_evp.c new file mode 100644 index 0000000000..4db0a7fe62 --- /dev/null +++ b/src/lib/libcrypto/asn1/p7_evp.c @@ -0,0 +1,125 @@ +/* crypto/asn1/p7_evp.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include "asn1_mac.h" +#include "x509.h" + +/* + * ASN1err(ASN1_F_PKCS7_ENVELOPE_NEW,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_PKCS7_ENVELOPE,ASN1_R_LENGTH_MISMATCH); + */ + +int i2d_PKCS7_ENVELOPE(a,pp) +PKCS7_ENVELOPE *a; +unsigned char **pp; + { + M_ASN1_I2D_vars(a); + + M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); + M_ASN1_I2D_len_SET(a->recipientinfo,i2d_PKCS7_RECIP_INFO); + M_ASN1_I2D_len(a->enc_data,i2d_PKCS7_ENC_CONTENT); + + M_ASN1_I2D_seq_total(); + + M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER); + M_ASN1_I2D_put_SET(a->recipientinfo,i2d_PKCS7_RECIP_INFO); + M_ASN1_I2D_put(a->enc_data,i2d_PKCS7_ENC_CONTENT); + + M_ASN1_I2D_finish(); + } + +PKCS7_ENVELOPE *d2i_PKCS7_ENVELOPE(a,pp,length) +PKCS7_ENVELOPE **a; +unsigned char **pp; +long length; + { + M_ASN1_D2I_vars(a,PKCS7_ENVELOPE *,PKCS7_ENVELOPE_new); + + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); + M_ASN1_D2I_get_set(ret->recipientinfo,d2i_PKCS7_RECIP_INFO); + M_ASN1_D2I_get(ret->enc_data,d2i_PKCS7_ENC_CONTENT); + + M_ASN1_D2I_Finish(a,PKCS7_ENVELOPE_free,ASN1_F_D2I_PKCS7_ENVELOPE); + } + +PKCS7_ENVELOPE *PKCS7_ENVELOPE_new() + { + PKCS7_ENVELOPE *ret=NULL; + + M_ASN1_New_Malloc(ret,PKCS7_ENVELOPE); + M_ASN1_New(ret->version,ASN1_INTEGER_new); + M_ASN1_New(ret->recipientinfo,sk_new_null); + M_ASN1_New(ret->enc_data,PKCS7_ENC_CONTENT_new); + return(ret); + M_ASN1_New_Error(ASN1_F_PKCS7_ENVELOPE_NEW); + } + +void PKCS7_ENVELOPE_free(a) +PKCS7_ENVELOPE *a; + { + if (a == NULL) return; + ASN1_INTEGER_free(a->version); + sk_pop_free(a->recipientinfo,PKCS7_RECIP_INFO_free); + PKCS7_ENC_CONTENT_free(a->enc_data); + Free((char *)a); + } + diff --git a/src/lib/libcrypto/asn1/p7_i_s.c b/src/lib/libcrypto/asn1/p7_i_s.c new file mode 100644 index 0000000000..9b00c556d9 --- /dev/null +++ b/src/lib/libcrypto/asn1/p7_i_s.c @@ -0,0 +1,120 @@ +/* crypto/asn1/p7_i_s.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include "asn1_mac.h" +#include "x509.h" + +/* + * ASN1err(ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL,ASN1_R_LENGTH_MISMATCH); + */ + +int i2d_PKCS7_ISSUER_AND_SERIAL(a,pp) +PKCS7_ISSUER_AND_SERIAL *a; +unsigned char **pp; + { + M_ASN1_I2D_vars(a); + + M_ASN1_I2D_len(a->issuer,i2d_X509_NAME); + M_ASN1_I2D_len(a->serial,i2d_ASN1_INTEGER); + + M_ASN1_I2D_seq_total(); + + M_ASN1_I2D_put(a->issuer,i2d_X509_NAME); + M_ASN1_I2D_put(a->serial,i2d_ASN1_INTEGER); + + M_ASN1_I2D_finish(); + } + +PKCS7_ISSUER_AND_SERIAL *d2i_PKCS7_ISSUER_AND_SERIAL(a,pp,length) +PKCS7_ISSUER_AND_SERIAL **a; +unsigned char **pp; +long length; + { + M_ASN1_D2I_vars(a,PKCS7_ISSUER_AND_SERIAL *,PKCS7_ISSUER_AND_SERIAL_new); + + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get(ret->issuer,d2i_X509_NAME); + M_ASN1_D2I_get(ret->serial,d2i_ASN1_INTEGER); + M_ASN1_D2I_Finish(a,PKCS7_ISSUER_AND_SERIAL_free, + ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL); + } + +PKCS7_ISSUER_AND_SERIAL *PKCS7_ISSUER_AND_SERIAL_new() + { + PKCS7_ISSUER_AND_SERIAL *ret=NULL; + + M_ASN1_New_Malloc(ret,PKCS7_ISSUER_AND_SERIAL); + M_ASN1_New(ret->issuer,X509_NAME_new); + M_ASN1_New(ret->serial,ASN1_INTEGER_new); + return(ret); + M_ASN1_New_Error(ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW); + } + +void PKCS7_ISSUER_AND_SERIAL_free(a) +PKCS7_ISSUER_AND_SERIAL *a; + { + if (a == NULL) return; + X509_NAME_free(a->issuer); + ASN1_INTEGER_free(a->serial); + Free((char *)a); + } + diff --git a/src/lib/libcrypto/asn1/p7_lib.c b/src/lib/libcrypto/asn1/p7_lib.c new file mode 100644 index 0000000000..2134e0974a --- /dev/null +++ b/src/lib/libcrypto/asn1/p7_lib.c @@ -0,0 +1,299 @@ +/* crypto/asn1/p7_lib.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include "asn1_mac.h" +#include "objects.h" + +/* ASN1err(ASN1_F_D2I_PKCS7,ASN1_R_BAD_PKCS7_CONTENT); + * ASN1err(ASN1_F_I2D_PKCS7,ASN1_R_BAD_PKCS7_TYPE); + * ASN1err(ASN1_F_PKCS7_NEW,ASN1_R_BAD_PKCS7_TYPE); + */ + +int i2d_PKCS7(a,pp) +PKCS7 *a; +unsigned char **pp; + { + M_ASN1_I2D_vars(a); + + if (a->asn1 != NULL) + { + if (pp == NULL) + return((int)a->length); + memcpy(*pp,a->asn1,(int)a->length); + *pp+=a->length; + return((int)a->length); + } + + ret+=4; /* sequence, BER header plus '0 0' end padding */ + M_ASN1_I2D_len(a->type,i2d_ASN1_OBJECT); + if (a->d.ptr != NULL) + { + ret+=4; /* explicit tag [ 0 ] BER plus '0 0' */ + switch (OBJ_obj2nid(a->type)) + { + case NID_pkcs7_data: + M_ASN1_I2D_len(a->d.data,i2d_ASN1_OCTET_STRING); + break; + case NID_pkcs7_signed: + M_ASN1_I2D_len(a->d.sign,i2d_PKCS7_SIGNED); + break; + case NID_pkcs7_enveloped: + M_ASN1_I2D_len(a->d.enveloped,i2d_PKCS7_ENVELOPE); + break; + case NID_pkcs7_signedAndEnveloped: + M_ASN1_I2D_len(a->d.signed_and_enveloped, + i2d_PKCS7_SIGN_ENVELOPE); + break; + case NID_pkcs7_digest: + M_ASN1_I2D_len(a->d.digest,i2d_PKCS7_DIGEST); + break; + case NID_pkcs7_encrypted: + M_ASN1_I2D_len(a->d.encrypted,i2d_PKCS7_ENCRYPT); + break; + default: + break; + } + } + r=ret; + if (pp == NULL) return(r); + p= *pp; + M_ASN1_I2D_INF_seq_start(V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); + M_ASN1_I2D_put(a->type,i2d_ASN1_OBJECT); + + if (a->d.ptr != NULL) + { + M_ASN1_I2D_INF_seq_start(0,V_ASN1_CONTEXT_SPECIFIC); + switch (OBJ_obj2nid(a->type)) + { + case NID_pkcs7_data: + M_ASN1_I2D_put(a->d.data,i2d_ASN1_OCTET_STRING); + break; + case NID_pkcs7_signed: + M_ASN1_I2D_put(a->d.sign,i2d_PKCS7_SIGNED); + break; + case NID_pkcs7_enveloped: + M_ASN1_I2D_put(a->d.enveloped,i2d_PKCS7_ENVELOPE); + break; + case NID_pkcs7_signedAndEnveloped: + M_ASN1_I2D_put(a->d.signed_and_enveloped, + i2d_PKCS7_SIGN_ENVELOPE); + break; + case NID_pkcs7_digest: + M_ASN1_I2D_put(a->d.digest,i2d_PKCS7_DIGEST); + break; + case NID_pkcs7_encrypted: + M_ASN1_I2D_put(a->d.encrypted,i2d_PKCS7_ENCRYPT); + break; + default: + break; + } + M_ASN1_I2D_INF_seq_end(); + } + M_ASN1_I2D_INF_seq_end(); + M_ASN1_I2D_finish(); + } + +PKCS7 *d2i_PKCS7(a,pp,length) +PKCS7 **a; +unsigned char **pp; +long length; + { + M_ASN1_D2I_vars(a,PKCS7 *,PKCS7_new); + + if ((a != NULL) && ((*a) != NULL)) + { + if ((*a)->asn1 != NULL) + { + Free((char *)(*a)->asn1); + (*a)->asn1=NULL; + } + (*a)->length=0; + } + + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get(ret->type,d2i_ASN1_OBJECT); + if (!M_ASN1_D2I_end_sequence()) + { + int Tinf,Ttag,Tclass; + long Tlen; + + if (M_ASN1_next != (V_ASN1_CONSTRUCTED| + V_ASN1_CONTEXT_SPECIFIC|0)) + { + c.error=ASN1_R_BAD_PKCS7_CONTENT; + goto err; + } + + ret->detached=0; + + c.q=c.p; + Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass, + (c.inf & 1)?(length+ *pp-c.q):c.slen); + if (Tinf & 0x80) goto err; + c.slen-=(c.p-c.q); + + switch (OBJ_obj2nid(ret->type)) + { + case NID_pkcs7_data: + M_ASN1_D2I_get(ret->d.data,d2i_ASN1_OCTET_STRING); + break; + case NID_pkcs7_signed: + M_ASN1_D2I_get(ret->d.sign,d2i_PKCS7_SIGNED); + if (ret->d.sign->contents->d.ptr == NULL) + ret->detached=1; + break; + case NID_pkcs7_enveloped: + M_ASN1_D2I_get(ret->d.enveloped,d2i_PKCS7_ENVELOPE); + break; + case NID_pkcs7_signedAndEnveloped: + M_ASN1_D2I_get(ret->d.signed_and_enveloped, + d2i_PKCS7_SIGN_ENVELOPE); + break; + case NID_pkcs7_digest: + M_ASN1_D2I_get(ret->d.digest,d2i_PKCS7_DIGEST); + break; + case NID_pkcs7_encrypted: + M_ASN1_D2I_get(ret->d.encrypted,d2i_PKCS7_ENCRYPT); + break; + default: + c.error=ASN1_R_BAD_PKCS7_TYPE; + goto err; + break; + } + if (Tinf == (1|V_ASN1_CONSTRUCTED)) + { + if (!ASN1_check_infinite_end(&c.p,c.slen)) + { + c.error=ASN1_R_MISSING_EOS; + goto err; + } + } + } + else + ret->detached=1; + + M_ASN1_D2I_Finish(a,PKCS7_free,ASN1_F_D2I_PKCS7); + } + +PKCS7 *PKCS7_new() + { + PKCS7 *ret=NULL; + + M_ASN1_New_Malloc(ret,PKCS7); + ret->type=ASN1_OBJECT_new(); + ret->asn1=NULL; + ret->length=0; + ret->detached=0; + ret->d.ptr=NULL; + return(ret); + M_ASN1_New_Error(ASN1_F_PKCS7_NEW); + } + +void PKCS7_free(a) +PKCS7 *a; + { + if (a == NULL) return; + + PKCS7_content_free(a); + if (a->type != NULL) + { + ASN1_OBJECT_free(a->type); + } + Free((char *)(char *)a); + } + +void PKCS7_content_free(a) +PKCS7 *a; + { + if (a->asn1 != NULL) Free((char *)a->asn1); + + if (a->d.ptr != NULL) + { + if (a->type == NULL) return; + + switch (OBJ_obj2nid(a->type)) + { + case NID_pkcs7_data: + ASN1_OCTET_STRING_free(a->d.data); + break; + case NID_pkcs7_signed: + PKCS7_SIGNED_free(a->d.sign); + break; + case NID_pkcs7_enveloped: + PKCS7_ENVELOPE_free(a->d.enveloped); + break; + case NID_pkcs7_signedAndEnveloped: + PKCS7_SIGN_ENVELOPE_free(a->d.signed_and_enveloped); + break; + case NID_pkcs7_digest: + PKCS7_DIGEST_free(a->d.digest); + break; + case NID_pkcs7_encrypted: + PKCS7_ENCRYPT_free(a->d.encrypted); + break; + default: + /* MEMORY LEAK */ + break; + } + } + a->d.ptr=NULL; + } + diff --git a/src/lib/libcrypto/asn1/p7_recip.c b/src/lib/libcrypto/asn1/p7_recip.c new file mode 100644 index 0000000000..f02233f5a8 --- /dev/null +++ b/src/lib/libcrypto/asn1/p7_recip.c @@ -0,0 +1,132 @@ +/* crypto/asn1/p7_recip.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include "asn1_mac.h" +#include "x509.h" + +/* + * ASN1err(ASN1_F_PKCS7_RECIP_INFO_NEW,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_PKCS7_RECIP_INFO,ASN1_R_LENGTH_MISMATCH); + */ + +int i2d_PKCS7_RECIP_INFO(a,pp) +PKCS7_RECIP_INFO *a; +unsigned char **pp; + { + M_ASN1_I2D_vars(a); + + M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); + M_ASN1_I2D_len(a->issuer_and_serial,i2d_PKCS7_ISSUER_AND_SERIAL); + M_ASN1_I2D_len(a->key_enc_algor,i2d_X509_ALGOR); + M_ASN1_I2D_len(a->enc_key,i2d_ASN1_OCTET_STRING); + + M_ASN1_I2D_seq_total(); + + M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER); + M_ASN1_I2D_put(a->issuer_and_serial,i2d_PKCS7_ISSUER_AND_SERIAL); + M_ASN1_I2D_put(a->key_enc_algor,i2d_X509_ALGOR); + M_ASN1_I2D_put(a->enc_key,i2d_ASN1_OCTET_STRING); + + M_ASN1_I2D_finish(); + } + +PKCS7_RECIP_INFO *d2i_PKCS7_RECIP_INFO(a,pp,length) +PKCS7_RECIP_INFO **a; +unsigned char **pp; +long length; + { + M_ASN1_D2I_vars(a,PKCS7_RECIP_INFO *,PKCS7_RECIP_INFO_new); + + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); + M_ASN1_D2I_get(ret->issuer_and_serial,d2i_PKCS7_ISSUER_AND_SERIAL); + M_ASN1_D2I_get(ret->key_enc_algor,d2i_X509_ALGOR); + M_ASN1_D2I_get(ret->enc_key,d2i_ASN1_OCTET_STRING); + + M_ASN1_D2I_Finish(a,PKCS7_RECIP_INFO_free,ASN1_F_D2I_PKCS7_RECIP_INFO); + } + +PKCS7_RECIP_INFO *PKCS7_RECIP_INFO_new() + { + PKCS7_RECIP_INFO *ret=NULL; + + M_ASN1_New_Malloc(ret,PKCS7_RECIP_INFO); + M_ASN1_New(ret->version,ASN1_INTEGER_new); + M_ASN1_New(ret->issuer_and_serial,PKCS7_ISSUER_AND_SERIAL_new); + M_ASN1_New(ret->key_enc_algor,X509_ALGOR_new); + M_ASN1_New(ret->enc_key,ASN1_OCTET_STRING_new); + ret->cert=NULL; + return(ret); + M_ASN1_New_Error(ASN1_F_PKCS7_RECIP_INFO_NEW); + } + +void PKCS7_RECIP_INFO_free(a) +PKCS7_RECIP_INFO *a; + { + if (a == NULL) return; + ASN1_INTEGER_free(a->version); + PKCS7_ISSUER_AND_SERIAL_free(a->issuer_and_serial); + X509_ALGOR_free(a->key_enc_algor); + ASN1_OCTET_STRING_free(a->enc_key); + if (a->cert != NULL) X509_free(a->cert); + Free((char *)a); + } + diff --git a/src/lib/libcrypto/asn1/p7_s_e.c b/src/lib/libcrypto/asn1/p7_s_e.c new file mode 100644 index 0000000000..d344211456 --- /dev/null +++ b/src/lib/libcrypto/asn1/p7_s_e.c @@ -0,0 +1,146 @@ +/* crypto/asn1/p7_s_e.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include "asn1_mac.h" +#include "x509.h" + +/* + * ASN1err(ASN1_F_PKCS7_SIGN_ENVELOPE_NEW,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_PKCS7_SIGN_ENVELOPE,ASN1_R_LENGTH_MISMATCH); + */ + +int i2d_PKCS7_SIGN_ENVELOPE(a,pp) +PKCS7_SIGN_ENVELOPE *a; +unsigned char **pp; + { + M_ASN1_I2D_vars(a); + + M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); + M_ASN1_I2D_len_SET(a->recipientinfo,i2d_PKCS7_RECIP_INFO); + M_ASN1_I2D_len_SET(a->md_algs,i2d_X509_ALGOR); + M_ASN1_I2D_len(a->enc_data,i2d_PKCS7_ENC_CONTENT); + M_ASN1_I2D_len_IMP_set_opt(a->cert,i2d_X509,0); + M_ASN1_I2D_len_IMP_set_opt(a->crl,i2d_X509_CRL,1); + M_ASN1_I2D_len_SET(a->signer_info,i2d_PKCS7_SIGNER_INFO); + + M_ASN1_I2D_seq_total(); + + M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER); + M_ASN1_I2D_put_SET(a->recipientinfo,i2d_PKCS7_RECIP_INFO); + M_ASN1_I2D_put_SET(a->md_algs,i2d_X509_ALGOR); + M_ASN1_I2D_put(a->enc_data,i2d_PKCS7_ENC_CONTENT); + M_ASN1_I2D_put_IMP_set_opt(a->cert,i2d_X509,0); + M_ASN1_I2D_put_IMP_set_opt(a->crl,i2d_X509_CRL,1); + M_ASN1_I2D_put_SET(a->signer_info,i2d_PKCS7_SIGNER_INFO); + + M_ASN1_I2D_finish(); + } + +PKCS7_SIGN_ENVELOPE *d2i_PKCS7_SIGN_ENVELOPE(a,pp,length) +PKCS7_SIGN_ENVELOPE **a; +unsigned char **pp; +long length; + { + M_ASN1_D2I_vars(a,PKCS7_SIGN_ENVELOPE *,PKCS7_SIGN_ENVELOPE_new); + + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); + M_ASN1_D2I_get_set(ret->recipientinfo,d2i_PKCS7_RECIP_INFO); + M_ASN1_D2I_get_set(ret->md_algs,d2i_X509_ALGOR); + M_ASN1_D2I_get(ret->enc_data,d2i_PKCS7_ENC_CONTENT); + M_ASN1_D2I_get_IMP_set_opt(ret->cert,d2i_X509,0); + M_ASN1_D2I_get_IMP_set_opt(ret->crl,d2i_X509_CRL,1); + M_ASN1_D2I_get_set(ret->signer_info,d2i_PKCS7_SIGNER_INFO); + + M_ASN1_D2I_Finish(a,PKCS7_SIGN_ENVELOPE_free, + ASN1_F_D2I_PKCS7_SIGN_ENVELOPE); + } + +PKCS7_SIGN_ENVELOPE *PKCS7_SIGN_ENVELOPE_new() + { + PKCS7_SIGN_ENVELOPE *ret=NULL; + + M_ASN1_New_Malloc(ret,PKCS7_SIGN_ENVELOPE); + M_ASN1_New(ret->version,ASN1_INTEGER_new); + M_ASN1_New(ret->recipientinfo,sk_new_null); + M_ASN1_New(ret->md_algs,sk_new_null); + M_ASN1_New(ret->enc_data,PKCS7_ENC_CONTENT_new); + ret->cert=NULL; + ret->crl=NULL; + M_ASN1_New(ret->signer_info,sk_new_null); + return(ret); + M_ASN1_New_Error(ASN1_F_PKCS7_SIGN_ENVELOPE_NEW); + } + +void PKCS7_SIGN_ENVELOPE_free(a) +PKCS7_SIGN_ENVELOPE *a; + { + if (a == NULL) return; + ASN1_INTEGER_free(a->version); + sk_pop_free(a->recipientinfo,PKCS7_RECIP_INFO_free); + sk_pop_free(a->md_algs,X509_ALGOR_free); + PKCS7_ENC_CONTENT_free(a->enc_data); + sk_pop_free(a->cert,X509_free); + sk_pop_free(a->crl,X509_CRL_free); + sk_pop_free(a->signer_info,PKCS7_SIGNER_INFO_free); + Free((char *)a); + } + diff --git a/src/lib/libcrypto/asn1/p7_signd.c b/src/lib/libcrypto/asn1/p7_signd.c new file mode 100644 index 0000000000..40f9a44fa8 --- /dev/null +++ b/src/lib/libcrypto/asn1/p7_signd.c @@ -0,0 +1,140 @@ +/* crypto/asn1/p7_signd.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include "asn1_mac.h" +#include "x509.h" + +/* + * ASN1err(ASN1_F_PKCS7_SIGNED_NEW,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_PKCS7_SIGNED,ASN1_R_LENGTH_MISMATCH); + */ + +int i2d_PKCS7_SIGNED(a,pp) +PKCS7_SIGNED *a; +unsigned char **pp; + { + M_ASN1_I2D_vars(a); + + M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); + M_ASN1_I2D_len_SET(a->md_algs,i2d_X509_ALGOR); + M_ASN1_I2D_len(a->contents,i2d_PKCS7); + M_ASN1_I2D_len_IMP_set_opt(a->cert,i2d_X509,0); + M_ASN1_I2D_len_IMP_set_opt(a->crl,i2d_X509_CRL,1); + M_ASN1_I2D_len_SET(a->signer_info,i2d_PKCS7_SIGNER_INFO); + + M_ASN1_I2D_seq_total(); + + M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER); + M_ASN1_I2D_put_SET(a->md_algs,i2d_X509_ALGOR); + M_ASN1_I2D_put(a->contents,i2d_PKCS7); + M_ASN1_I2D_put_IMP_set_opt(a->cert,i2d_X509,0); + M_ASN1_I2D_put_IMP_set_opt(a->crl,i2d_X509_CRL,1); + M_ASN1_I2D_put_SET(a->signer_info,i2d_PKCS7_SIGNER_INFO); + + M_ASN1_I2D_finish(); + } + +PKCS7_SIGNED *d2i_PKCS7_SIGNED(a,pp,length) +PKCS7_SIGNED **a; +unsigned char **pp; +long length; + { + M_ASN1_D2I_vars(a,PKCS7_SIGNED *,PKCS7_SIGNED_new); + + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); + M_ASN1_D2I_get_set(ret->md_algs,d2i_X509_ALGOR); + M_ASN1_D2I_get(ret->contents,d2i_PKCS7); + M_ASN1_D2I_get_IMP_set_opt(ret->cert,d2i_X509,0); + M_ASN1_D2I_get_IMP_set_opt(ret->crl,d2i_X509_CRL,1); + M_ASN1_D2I_get_set(ret->signer_info,d2i_PKCS7_SIGNER_INFO); + + M_ASN1_D2I_Finish(a,PKCS7_SIGNED_free,ASN1_F_D2I_PKCS7_SIGNED); + } + +PKCS7_SIGNED *PKCS7_SIGNED_new() + { + PKCS7_SIGNED *ret=NULL; + + M_ASN1_New_Malloc(ret,PKCS7_SIGNED); + M_ASN1_New(ret->version,ASN1_INTEGER_new); + M_ASN1_New(ret->md_algs,sk_new_null); + M_ASN1_New(ret->contents,PKCS7_new); + ret->cert=NULL; + ret->crl=NULL; + M_ASN1_New(ret->signer_info,sk_new_null); + return(ret); + M_ASN1_New_Error(ASN1_F_PKCS7_SIGNED_NEW); + } + +void PKCS7_SIGNED_free(a) +PKCS7_SIGNED *a; + { + if (a == NULL) return; + ASN1_INTEGER_free(a->version); + sk_pop_free(a->md_algs,X509_ALGOR_free); + PKCS7_free(a->contents); + sk_pop_free(a->cert,X509_free); + sk_pop_free(a->crl,X509_CRL_free); + sk_pop_free(a->signer_info,PKCS7_SIGNER_INFO_free); + Free((char *)a); + } + diff --git a/src/lib/libcrypto/asn1/p7_signi.c b/src/lib/libcrypto/asn1/p7_signi.c new file mode 100644 index 0000000000..0da92169fc --- /dev/null +++ b/src/lib/libcrypto/asn1/p7_signi.c @@ -0,0 +1,149 @@ +/* crypto/asn1/p7_signi.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include "asn1_mac.h" +#include "x509.h" + +/* + * ASN1err(ASN1_F_PKCS7_SIGNER_INFO_NEW,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_D2I_PKCS7_SIGNER_INFO,ASN1_R_LENGTH_MISMATCH); + */ + +int i2d_PKCS7_SIGNER_INFO(a,pp) +PKCS7_SIGNER_INFO *a; +unsigned char **pp; + { + M_ASN1_I2D_vars(a); + + M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); + M_ASN1_I2D_len(a->issuer_and_serial,i2d_PKCS7_ISSUER_AND_SERIAL); + M_ASN1_I2D_len(a->digest_alg,i2d_X509_ALGOR); + M_ASN1_I2D_len_IMP_set_opt(a->auth_attr,i2d_X509_ATTRIBUTE,0); + M_ASN1_I2D_len(a->digest_enc_alg,i2d_X509_ALGOR); + M_ASN1_I2D_len(a->enc_digest,i2d_ASN1_OCTET_STRING); + M_ASN1_I2D_len_IMP_set_opt(a->unauth_attr,i2d_X509_ATTRIBUTE,1); + + M_ASN1_I2D_seq_total(); + + M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER); + M_ASN1_I2D_put(a->issuer_and_serial,i2d_PKCS7_ISSUER_AND_SERIAL); + M_ASN1_I2D_put(a->digest_alg,i2d_X509_ALGOR); + M_ASN1_I2D_put_IMP_set_opt(a->auth_attr,i2d_X509_ATTRIBUTE,0); + M_ASN1_I2D_put(a->digest_enc_alg,i2d_X509_ALGOR); + M_ASN1_I2D_put(a->enc_digest,i2d_ASN1_OCTET_STRING); + M_ASN1_I2D_put_IMP_set_opt(a->unauth_attr,i2d_X509_ATTRIBUTE,1); + + M_ASN1_I2D_finish(); + } + +PKCS7_SIGNER_INFO *d2i_PKCS7_SIGNER_INFO(a,pp,length) +PKCS7_SIGNER_INFO **a; +unsigned char **pp; +long length; + { + M_ASN1_D2I_vars(a,PKCS7_SIGNER_INFO *,PKCS7_SIGNER_INFO_new); + + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); + M_ASN1_D2I_get(ret->issuer_and_serial,d2i_PKCS7_ISSUER_AND_SERIAL); + M_ASN1_D2I_get(ret->digest_alg,d2i_X509_ALGOR); + M_ASN1_D2I_get_IMP_set_opt(ret->auth_attr,d2i_X509_ATTRIBUTE,0); + M_ASN1_D2I_get(ret->digest_enc_alg,d2i_X509_ALGOR); + M_ASN1_D2I_get(ret->enc_digest,d2i_ASN1_OCTET_STRING); + M_ASN1_D2I_get_IMP_set_opt(ret->unauth_attr,d2i_X509_ATTRIBUTE,1); + + M_ASN1_D2I_Finish(a,PKCS7_SIGNER_INFO_free, + ASN1_F_D2I_PKCS7_SIGNER_INFO); + } + +PKCS7_SIGNER_INFO *PKCS7_SIGNER_INFO_new() + { + PKCS7_SIGNER_INFO *ret=NULL; + + M_ASN1_New_Malloc(ret,PKCS7_SIGNER_INFO); + M_ASN1_New(ret->version,ASN1_INTEGER_new); + M_ASN1_New(ret->issuer_and_serial,PKCS7_ISSUER_AND_SERIAL_new); + M_ASN1_New(ret->digest_alg,X509_ALGOR_new); + ret->auth_attr=NULL; + M_ASN1_New(ret->digest_enc_alg,X509_ALGOR_new); + M_ASN1_New(ret->enc_digest,ASN1_OCTET_STRING_new); + ret->unauth_attr=NULL; + ret->pkey=NULL; + return(ret); + M_ASN1_New_Error(ASN1_F_PKCS7_SIGNER_INFO_NEW); + } + +void PKCS7_SIGNER_INFO_free(a) +PKCS7_SIGNER_INFO *a; + { + if (a == NULL) return; + ASN1_INTEGER_free(a->version); + PKCS7_ISSUER_AND_SERIAL_free(a->issuer_and_serial); + X509_ALGOR_free(a->digest_alg); + sk_pop_free(a->auth_attr,X509_ATTRIBUTE_free); + X509_ALGOR_free(a->digest_enc_alg); + ASN1_OCTET_STRING_free(a->enc_digest); + sk_pop_free(a->unauth_attr,X509_ATTRIBUTE_free); + if (a->pkey != NULL) + EVP_PKEY_free(a->pkey); + Free((char *)a); + } + diff --git a/src/lib/libcrypto/asn1/pkcs8.c b/src/lib/libcrypto/asn1/pkcs8.c new file mode 100644 index 0000000000..03fdadd51a --- /dev/null +++ b/src/lib/libcrypto/asn1/pkcs8.c @@ -0,0 +1,142 @@ +/* crypto/asn1/pkcs8.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include "asn1_mac.h" +#include "objects.h" + +/* + * ASN1err(ASN1_F_D2I_X509_KEY,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_X509_KEY_NEW,ASN1_R_BAD_GET_OBJECT); + */ + +int i2d_X509_KEY(a,pp) +X509 *a; +unsigned char **pp; + { + M_ASN1_I2D_vars(a); + + M_ASN1_I2D_len(a->cert_info, i2d_X509_CINF); + M_ASN1_I2D_len(a->sig_alg, i2d_X509_ALGOR); + M_ASN1_I2D_len(a->signature, i2d_ASN1_BIT_STRING); + + M_ASN1_I2D_seq_total(); + + M_ASN1_I2D_put(a->cert_info, i2d_X509_CINF); + M_ASN1_I2D_put(a->sig_alg, i2d_X509_ALGOR); + M_ASN1_I2D_put(a->signature, i2d_ASN1_BIT_STRING); + + M_ASN1_I2D_finish(); + } + +X509 *d2i_X509_KEY(a,pp,length) +X509 **a; +unsigned char **pp; +long length; + { + M_ASN1_D2I_vars(a,X509 *,X509_new); + + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get(ret->cert_info,d2i_X509_CINF); + M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR); + M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING); + M_ASN1_D2I_Finish(a,X509_free,ASN1_F_D2I_X509); + } + +X509 *X509_KEY_new() + { + X509_KEY *ret=NULL; + + M_ASN1_New_Malloc(ret,X509_KEY); + ret->references=1; + ret->type=NID + M_ASN1_New(ret->cert_info,X509_CINF_new); + M_ASN1_New(ret->sig_alg,X509_ALGOR_new); + M_ASN1_New(ret->signature,ASN1_BIT_STRING_new); + return(ret); + M_ASN1_New_Error(ASN1_F_X509_NEW); + } + +void X509_KEY_free(a) +X509 *a; + { + int i; + + if (a == NULL) return; + + i=CRYPTO_add_lock(&a->references,-1,CRYPTO_LOCK_X509_KEY); +#ifdef REF_PRINT + REF_PRINT("X509_KEY",a); +#endif + if (i > 0) return; +#ifdef REF_CHECK + if (i < 0) + { + fprintf(stderr,"X509_KEY_free, bad reference count\n"); + abort(); + } +#endif + + X509_CINF_free(a->cert_info); + X509_ALGOR_free(a->sig_alg); + ASN1_BIT_STRING_free(a->signature); + Free((char *)a); + } + diff --git a/src/lib/libcrypto/asn1/x_cinf.c b/src/lib/libcrypto/asn1/x_cinf.c new file mode 100644 index 0000000000..4fc2cc9f6e --- /dev/null +++ b/src/lib/libcrypto/asn1/x_cinf.c @@ -0,0 +1,197 @@ +/* crypto/asn1/x_cinf.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include "asn1_mac.h" + +/* + * ASN1err(ASN1_F_D2I_X509_CINF,ASN1_R_LENGTH_MISMATCH); + * ASN1err(ASN1_F_X509_CINF_NEW,ASN1_R_LENGTH_MISMATCH); + */ + +int i2d_X509_CINF(a,pp) +X509_CINF *a; +unsigned char **pp; + { + int v1=0,v2=0; + M_ASN1_I2D_vars(a); + + M_ASN1_I2D_len_EXP_opt(a->version,i2d_ASN1_INTEGER,0,v1); + M_ASN1_I2D_len(a->serialNumber, i2d_ASN1_INTEGER); + M_ASN1_I2D_len(a->signature, i2d_X509_ALGOR); + M_ASN1_I2D_len(a->issuer, i2d_X509_NAME); + M_ASN1_I2D_len(a->validity, i2d_X509_VAL); + M_ASN1_I2D_len(a->subject, i2d_X509_NAME); + M_ASN1_I2D_len(a->key, i2d_X509_PUBKEY); + M_ASN1_I2D_len_IMP_opt(a->issuerUID, i2d_ASN1_BIT_STRING); + M_ASN1_I2D_len_IMP_opt(a->subjectUID, i2d_ASN1_BIT_STRING); + M_ASN1_I2D_len_EXP_set_opt(a->extensions,i2d_X509_EXTENSION,3,V_ASN1_SEQUENCE,v2); + + M_ASN1_I2D_seq_total(); + + M_ASN1_I2D_put_EXP_opt(a->version,i2d_ASN1_INTEGER,0,v1); + M_ASN1_I2D_put(a->serialNumber, i2d_ASN1_INTEGER); + M_ASN1_I2D_put(a->signature, i2d_X509_ALGOR); + M_ASN1_I2D_put(a->issuer, i2d_X509_NAME); + M_ASN1_I2D_put(a->validity, i2d_X509_VAL); + M_ASN1_I2D_put(a->subject, i2d_X509_NAME); + M_ASN1_I2D_put(a->key, i2d_X509_PUBKEY); + M_ASN1_I2D_put_IMP_opt(a->issuerUID, i2d_ASN1_BIT_STRING,1); + M_ASN1_I2D_put_IMP_opt(a->subjectUID, i2d_ASN1_BIT_STRING,2); + M_ASN1_I2D_put_EXP_set_opt(a->extensions,i2d_X509_EXTENSION,3,V_ASN1_SEQUENCE,v2); + + M_ASN1_I2D_finish(); + } + +X509_CINF *d2i_X509_CINF(a,pp,length) +X509_CINF **a; +unsigned char **pp; +long length; + { + int ver=0; + M_ASN1_D2I_vars(a,X509_CINF *,X509_CINF_new); + + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + /* we have the optional version field */ + if (M_ASN1_next == (V_ASN1_CONTEXT_SPECIFIC | V_ASN1_CONSTRUCTED | 0)) + { + M_ASN1_D2I_get_EXP_opt(ret->version,d2i_ASN1_INTEGER,0); + if (ret->version->data != NULL) + ver=ret->version->data[0]; + } + else + { + if (ret->version != NULL) + { + ASN1_INTEGER_free(ret->version); + ret->version=NULL; + } + } + M_ASN1_D2I_get(ret->serialNumber,d2i_ASN1_INTEGER); + M_ASN1_D2I_get(ret->signature,d2i_X509_ALGOR); + M_ASN1_D2I_get(ret->issuer,d2i_X509_NAME); + M_ASN1_D2I_get(ret->validity,d2i_X509_VAL); + M_ASN1_D2I_get(ret->subject,d2i_X509_NAME); + M_ASN1_D2I_get(ret->key,d2i_X509_PUBKEY); + if (ver >= 1) /* version 2 extensions */ + { + if (ret->issuerUID != NULL) + { + ASN1_BIT_STRING_free(ret->issuerUID); + ret->issuerUID=NULL; + } + if (ret->subjectUID != NULL) + { + ASN1_BIT_STRING_free(ret->subjectUID); + ret->issuerUID=NULL; + } + M_ASN1_D2I_get_IMP_opt(ret->issuerUID,d2i_ASN1_BIT_STRING, 1, + V_ASN1_BIT_STRING); + M_ASN1_D2I_get_IMP_opt(ret->subjectUID,d2i_ASN1_BIT_STRING, 2, + V_ASN1_BIT_STRING); + } + if (ver >= 2) /* version 3 extensions */ + { + if (ret->extensions != NULL) + while (sk_num(ret->extensions)) + X509_EXTENSION_free((X509_EXTENSION *) + sk_pop(ret->extensions)); + M_ASN1_D2I_get_EXP_set_opt(ret->extensions,d2i_X509_EXTENSION,3, + V_ASN1_SEQUENCE); + } + M_ASN1_D2I_Finish(a,X509_CINF_free,ASN1_F_D2I_X509_CINF); + } + +X509_CINF *X509_CINF_new() + { + X509_CINF *ret=NULL; + + M_ASN1_New_Malloc(ret,X509_CINF); + ret->version=NULL; + M_ASN1_New(ret->serialNumber,ASN1_INTEGER_new); + M_ASN1_New(ret->signature,X509_ALGOR_new); + M_ASN1_New(ret->issuer,X509_NAME_new); + M_ASN1_New(ret->validity,X509_VAL_new); + M_ASN1_New(ret->subject,X509_NAME_new); + M_ASN1_New(ret->key,X509_PUBKEY_new); + ret->issuerUID=NULL; + ret->subjectUID=NULL; + ret->extensions=NULL; + return(ret); + M_ASN1_New_Error(ASN1_F_X509_CINF_NEW); + } + +void X509_CINF_free(a) +X509_CINF *a; + { + if (a == NULL) return; + ASN1_INTEGER_free(a->version); + ASN1_INTEGER_free(a->serialNumber); + X509_ALGOR_free(a->signature); + X509_NAME_free(a->issuer); + X509_VAL_free(a->validity); + X509_NAME_free(a->subject); + X509_PUBKEY_free(a->key); + ASN1_BIT_STRING_free(a->issuerUID); + ASN1_BIT_STRING_free(a->subjectUID); + sk_pop_free(a->extensions,X509_EXTENSION_free); + Free((char *)a); + } + -- cgit v1.2.3-55-g6feb