diff options
author | ryker <> | 1998-10-05 20:13:16 +0000 |
---|---|---|
committer | ryker <> | 1998-10-05 20:13:16 +0000 |
commit | 9e43e2ac1373d5be5c6500c1bc3b1dd6ee9584b4 (patch) | |
tree | 51ff319f3510104698e541954d10ad98f9125f36 /src/lib/libcrypto/asn1 | |
parent | 9e77c62555877f9a64805c49d0dcd7dbfbb40f4e (diff) | |
download | openbsd-9e43e2ac1373d5be5c6500c1bc3b1dd6ee9584b4.tar.gz openbsd-9e43e2ac1373d5be5c6500c1bc3b1dd6ee9584b4.tar.bz2 openbsd-9e43e2ac1373d5be5c6500c1bc3b1dd6ee9584b4.zip |
Import of SSLeay-0.9.0b with RSA and IDEA stubbed + OpenBSD build
functionality for shared libs.
Note that routines such as sslv2_init and friends that use RSA will
not work due to lack of RSA in this library.
Needs documentation and help from ports for easy upgrade to full
functionality where legally possible.
Diffstat (limited to 'src/lib/libcrypto/asn1')
25 files changed, 3337 insertions, 0 deletions
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 @@ | |||
1 | /* crypto/asn1/a_bmp.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "asn1.h" | ||
62 | |||
63 | /* ASN1err(ASN1_F_D2I_ASN1_INTEGER,ASN1_R_EXPECTING_AN_INTEGER); | ||
64 | */ | ||
65 | |||
66 | int i2d_ASN1_BMPSTRING(a, pp) | ||
67 | ASN1_BMPSTRING *a; | ||
68 | unsigned char **pp; | ||
69 | { | ||
70 | return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, | ||
71 | V_ASN1_BMPSTRING,V_ASN1_UNIVERSAL)); | ||
72 | } | ||
73 | |||
74 | ASN1_BMPSTRING *d2i_ASN1_BMPSTRING(a, pp, length) | ||
75 | ASN1_BMPSTRING **a; | ||
76 | unsigned char **pp; | ||
77 | long length; | ||
78 | { | ||
79 | ASN1_BMPSTRING *ret=NULL; | ||
80 | |||
81 | ret=(ASN1_BMPSTRING *)d2i_ASN1_bytes((ASN1_STRING **)a, | ||
82 | pp,length,V_ASN1_BMPSTRING,V_ASN1_UNIVERSAL); | ||
83 | if (ret == NULL) | ||
84 | { | ||
85 | ASN1err(ASN1_F_D2I_ASN1_BMPSTRING,ASN1_R_ERROR_STACK); | ||
86 | return(NULL); | ||
87 | } | ||
88 | return(ret); | ||
89 | } | ||
90 | |||
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 @@ | |||
1 | /* Error codes for the ASN1 functions. */ | ||
2 | |||
3 | /* Function codes. */ | ||
4 | #define ASN1_F_A2D_ASN1_OBJECT 100 | ||
5 | #define ASN1_F_A2I_ASN1_INTEGER 101 | ||
6 | #define ASN1_F_A2I_ASN1_STRING 102 | ||
7 | #define ASN1_F_ASN1_COLLATE_PRIMATIVE 103 | ||
8 | #define ASN1_F_ASN1_D2I_BIO 104 | ||
9 | #define ASN1_F_ASN1_D2I_FP 105 | ||
10 | #define ASN1_F_ASN1_DUP 106 | ||
11 | #define ASN1_F_ASN1_GET_OBJECT 107 | ||
12 | #define ASN1_F_ASN1_HEADER_NEW 108 | ||
13 | #define ASN1_F_ASN1_I2D_BIO 109 | ||
14 | #define ASN1_F_ASN1_I2D_FP 110 | ||
15 | #define ASN1_F_ASN1_INTEGER_SET 111 | ||
16 | #define ASN1_F_ASN1_INTEGER_TO_BN 112 | ||
17 | #define ASN1_F_ASN1_OBJECT_NEW 113 | ||
18 | #define ASN1_F_ASN1_SIGN 114 | ||
19 | #define ASN1_F_ASN1_STRING_NEW 115 | ||
20 | #define ASN1_F_ASN1_STRING_TYPE_NEW 116 | ||
21 | #define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 117 | ||
22 | #define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 118 | ||
23 | #define ASN1_F_ASN1_TYPE_NEW 119 | ||
24 | #define ASN1_F_ASN1_UTCTIME_NEW 120 | ||
25 | #define ASN1_F_ASN1_VERIFY 121 | ||
26 | #define ASN1_F_BN_TO_ASN1_INTEGER 122 | ||
27 | #define ASN1_F_D2I_ASN1_BIT_STRING 123 | ||
28 | #define ASN1_F_D2I_ASN1_BMPSTRING 124 | ||
29 | #define ASN1_F_D2I_ASN1_BOOLEAN 125 | ||
30 | #define ASN1_F_D2I_ASN1_BYTES 126 | ||
31 | #define ASN1_F_D2I_ASN1_HEADER 127 | ||
32 | #define ASN1_F_D2I_ASN1_INTEGER 128 | ||
33 | #define ASN1_F_D2I_ASN1_OBJECT 129 | ||
34 | #define ASN1_F_D2I_ASN1_OCTET_STRING 130 | ||
35 | #define ASN1_F_D2I_ASN1_PRINT_TYPE 131 | ||
36 | #define ASN1_F_D2I_ASN1_SET 132 | ||
37 | #define ASN1_F_D2I_ASN1_TYPE 133 | ||
38 | #define ASN1_F_D2I_ASN1_TYPE_BYTES 134 | ||
39 | #define ASN1_F_D2I_ASN1_UTCTIME 135 | ||
40 | #define ASN1_F_D2I_DHPARAMS 136 | ||
41 | #define ASN1_F_D2I_DSAPARAMS 137 | ||
42 | #define ASN1_F_D2I_DSAPRIVATEKEY 138 | ||
43 | #define ASN1_F_D2I_DSAPUBLICKEY 139 | ||
44 | #define ASN1_F_D2I_NETSCAPE_PKEY 140 | ||
45 | #define ASN1_F_D2I_NETSCAPE_RSA 141 | ||
46 | #define ASN1_F_D2I_NETSCAPE_RSA_2 142 | ||
47 | #define ASN1_F_D2I_NETSCAPE_SPKAC 143 | ||
48 | #define ASN1_F_D2I_NETSCAPE_SPKI 144 | ||
49 | #define ASN1_F_D2I_PKCS7 145 | ||
50 | #define ASN1_F_D2I_PKCS7_DIGEST 146 | ||
51 | #define ASN1_F_D2I_PKCS7_ENCRYPT 147 | ||
52 | #define ASN1_F_D2I_PKCS7_ENC_CONTENT 148 | ||
53 | #define ASN1_F_D2I_PKCS7_ENVELOPE 149 | ||
54 | #define ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL 150 | ||
55 | #define ASN1_F_D2I_PKCS7_RECIP_INFO 151 | ||
56 | #define ASN1_F_D2I_PKCS7_SIGNED 152 | ||
57 | #define ASN1_F_D2I_PKCS7_SIGNER_INFO 153 | ||
58 | #define ASN1_F_D2I_PKCS7_SIGN_ENVELOPE 154 | ||
59 | #define ASN1_F_D2I_PRIVATEKEY 155 | ||
60 | #define ASN1_F_D2I_PUBLICKEY 156 | ||
61 | #define ASN1_F_D2I_RSAPRIVATEKEY 157 | ||
62 | #define ASN1_F_D2I_RSAPUBLICKEY 158 | ||
63 | #define ASN1_F_D2I_X509 159 | ||
64 | #define ASN1_F_D2I_X509_ALGOR 160 | ||
65 | #define ASN1_F_D2I_X509_ATTRIBUTE 161 | ||
66 | #define ASN1_F_D2I_X509_CINF 162 | ||
67 | #define ASN1_F_D2I_X509_CRL 163 | ||
68 | #define ASN1_F_D2I_X509_CRL_INFO 164 | ||
69 | #define ASN1_F_D2I_X509_EXTENSION 165 | ||
70 | #define ASN1_F_D2I_X509_KEY 166 | ||
71 | #define ASN1_F_D2I_X509_NAME 167 | ||
72 | #define ASN1_F_D2I_X509_NAME_ENTRY 168 | ||
73 | #define ASN1_F_D2I_X509_PKEY 169 | ||
74 | #define ASN1_F_D2I_X509_PUBKEY 170 | ||
75 | #define ASN1_F_D2I_X509_REQ 171 | ||
76 | #define ASN1_F_D2I_X509_REQ_INFO 172 | ||
77 | #define ASN1_F_D2I_X509_REVOKED 173 | ||
78 | #define ASN1_F_D2I_X509_SIG 174 | ||
79 | #define ASN1_F_D2I_X509_VAL 175 | ||
80 | #define ASN1_F_I2D_ASN1_HEADER 176 | ||
81 | #define ASN1_F_I2D_DHPARAMS 177 | ||
82 | #define ASN1_F_I2D_DSAPARAMS 178 | ||
83 | #define ASN1_F_I2D_DSAPRIVATEKEY 179 | ||
84 | #define ASN1_F_I2D_DSAPUBLICKEY 180 | ||
85 | #define ASN1_F_I2D_NETSCAPE_RSA 181 | ||
86 | #define ASN1_F_I2D_PKCS7 182 | ||
87 | #define ASN1_F_I2D_PRIVATEKEY 183 | ||
88 | #define ASN1_F_I2D_PUBLICKEY 184 | ||
89 | #define ASN1_F_I2D_RSAPRIVATEKEY 185 | ||
90 | #define ASN1_F_I2D_RSAPUBLICKEY 186 | ||
91 | #define ASN1_F_I2D_X509_ATTRIBUTE 187 | ||
92 | #define ASN1_F_I2T_ASN1_OBJECT 188 | ||
93 | #define ASN1_F_NETSCAPE_PKEY_NEW 189 | ||
94 | #define ASN1_F_NETSCAPE_SPKAC_NEW 190 | ||
95 | #define ASN1_F_NETSCAPE_SPKI_NEW 191 | ||
96 | #define ASN1_F_PKCS7_DIGEST_NEW 192 | ||
97 | #define ASN1_F_PKCS7_ENCRYPT_NEW 193 | ||
98 | #define ASN1_F_PKCS7_ENC_CONTENT_NEW 194 | ||
99 | #define ASN1_F_PKCS7_ENVELOPE_NEW 195 | ||
100 | #define ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW 196 | ||
101 | #define ASN1_F_PKCS7_NEW 197 | ||
102 | #define ASN1_F_PKCS7_RECIP_INFO_NEW 198 | ||
103 | #define ASN1_F_PKCS7_SIGNED_NEW 199 | ||
104 | #define ASN1_F_PKCS7_SIGNER_INFO_NEW 200 | ||
105 | #define ASN1_F_PKCS7_SIGN_ENVELOPE_NEW 201 | ||
106 | #define ASN1_F_X509_ALGOR_NEW 202 | ||
107 | #define ASN1_F_X509_ATTRIBUTE_NEW 203 | ||
108 | #define ASN1_F_X509_CINF_NEW 204 | ||
109 | #define ASN1_F_X509_CRL_INFO_NEW 205 | ||
110 | #define ASN1_F_X509_CRL_NEW 206 | ||
111 | #define ASN1_F_X509_DHPARAMS_NEW 207 | ||
112 | #define ASN1_F_X509_EXTENSION_NEW 208 | ||
113 | #define ASN1_F_X509_INFO_NEW 209 | ||
114 | #define ASN1_F_X509_KEY_NEW 210 | ||
115 | #define ASN1_F_X509_NAME_ENTRY_NEW 211 | ||
116 | #define ASN1_F_X509_NAME_NEW 212 | ||
117 | #define ASN1_F_X509_NEW 213 | ||
118 | #define ASN1_F_X509_PKEY_NEW 214 | ||
119 | #define ASN1_F_X509_PUBKEY_NEW 215 | ||
120 | #define ASN1_F_X509_REQ_INFO_NEW 216 | ||
121 | #define ASN1_F_X509_REQ_NEW 217 | ||
122 | #define ASN1_F_X509_REVOKED_NEW 218 | ||
123 | #define ASN1_F_X509_SIG_NEW 219 | ||
124 | #define ASN1_F_X509_VAL_FREE 220 | ||
125 | #define ASN1_F_X509_VAL_NEW 221 | ||
126 | |||
127 | /* Reason codes. */ | ||
128 | #define ASN1_R_BAD_CLASS 100 | ||
129 | #define ASN1_R_BAD_GET_OBJECT 101 | ||
130 | #define ASN1_R_BAD_OBJECT_HEADER 102 | ||
131 | #define ASN1_R_BAD_PASSWORD_READ 103 | ||
132 | #define ASN1_R_BAD_PKCS7_CONTENT 104 | ||
133 | #define ASN1_R_BAD_PKCS7_TYPE 105 | ||
134 | #define ASN1_R_BAD_TAG 106 | ||
135 | #define ASN1_R_BAD_TYPE 107 | ||
136 | #define ASN1_R_BN_LIB 108 | ||
137 | #define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 109 | ||
138 | #define ASN1_R_BUFFER_TOO_SMALL 110 | ||
139 | #define ASN1_R_DATA_IS_WRONG 111 | ||
140 | #define ASN1_R_DECODING_ERROR 112 | ||
141 | #define ASN1_R_ERROR_STACK 113 | ||
142 | #define ASN1_R_EXPECTING_AN_INTEGER 114 | ||
143 | #define ASN1_R_EXPECTING_AN_OBJECT 115 | ||
144 | #define ASN1_R_EXPECTING_AN_OCTET_STRING 116 | ||
145 | #define ASN1_R_EXPECTING_A_BIT_STRING 117 | ||
146 | #define ASN1_R_EXPECTING_A_BOOLEAN 118 | ||
147 | #define ASN1_R_EXPECTING_A_SEQUENCE 119 | ||
148 | #define ASN1_R_EXPECTING_A_UTCTIME 120 | ||
149 | #define ASN1_R_FIRST_NUM_TOO_LARGE 121 | ||
150 | #define ASN1_R_HEADER_TOO_LONG 122 | ||
151 | #define ASN1_R_INVALID_DIGIT 123 | ||
152 | #define ASN1_R_INVALID_SEPARATOR 124 | ||
153 | #define ASN1_R_INVALID_TIME_FORMAT 125 | ||
154 | #define ASN1_R_IV_TOO_LARGE 126 | ||
155 | #define ASN1_R_LENGTH_ERROR 127 | ||
156 | #define ASN1_R_LENGTH_MISMATCH 128 | ||
157 | #define ASN1_R_MISSING_EOS 129 | ||
158 | #define ASN1_R_MISSING_SECOND_NUMBER 130 | ||
159 | #define ASN1_R_NON_HEX_CHARACTERS 131 | ||
160 | #define ASN1_R_NOT_ENOUGH_DATA 132 | ||
161 | #define ASN1_R_ODD_NUMBER_OF_CHARS 133 | ||
162 | #define ASN1_R_PARSING 134 | ||
163 | #define ASN1_R_PRIVATE_KEY_HEADER_MISSING 135 | ||
164 | #define ASN1_R_SECOND_NUMBER_TOO_LARGE 136 | ||
165 | #define ASN1_R_SHORT_LINE 137 | ||
166 | #define ASN1_R_STRING_TOO_SHORT 138 | ||
167 | #define ASN1_R_TAG_VALUE_TOO_HIGH 139 | ||
168 | #define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 140 | ||
169 | #define ASN1_R_TOO_LONG 141 | ||
170 | #define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 142 | ||
171 | #define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 143 | ||
172 | #define ASN1_R_UNKNOWN_ATTRIBUTE_TYPE 144 | ||
173 | #define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 145 | ||
174 | #define ASN1_R_UNKNOWN_OBJECT_TYPE 146 | ||
175 | #define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 147 | ||
176 | #define ASN1_R_UNSUPPORTED_CIPHER 148 | ||
177 | #define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 149 | ||
178 | #define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 150 | ||
179 | #define ASN1_R_UTCTIME_TOO_LONG 151 | ||
180 | #define ASN1_R_WRONG_PRINTABLE_TYPE 152 | ||
181 | #define ASN1_R_WRONG_TAG 153 | ||
182 | #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 @@ | |||
1 | /* crypto/asn1/d2i_dhp.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "bn.h" | ||
62 | #include "dh.h" | ||
63 | #include "objects.h" | ||
64 | #include "asn1_mac.h" | ||
65 | |||
66 | /* | ||
67 | * ASN1err(ASN1_F_D2I_DHPARAMS,ASN1_R_LENGTH_MISMATCH); | ||
68 | * ASN1err(ASN1_F_I2D_DHPARAMS,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); | ||
69 | */ | ||
70 | |||
71 | DH *d2i_DHparams(a,pp,length) | ||
72 | DH **a; | ||
73 | unsigned char **pp; | ||
74 | long length; | ||
75 | { | ||
76 | int i=ASN1_R_ERROR_STACK; | ||
77 | ASN1_INTEGER *bs=NULL; | ||
78 | long v=0; | ||
79 | M_ASN1_D2I_vars(a,DH *,DH_new); | ||
80 | |||
81 | M_ASN1_D2I_Init(); | ||
82 | M_ASN1_D2I_start_sequence(); | ||
83 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
84 | if ((ret->p=BN_bin2bn(bs->data,bs->length,ret->p)) == NULL) goto err_bn; | ||
85 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
86 | if ((ret->g=BN_bin2bn(bs->data,bs->length,ret->g)) == NULL) goto err_bn; | ||
87 | |||
88 | if (!M_ASN1_D2I_end_sequence()) | ||
89 | { | ||
90 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
91 | for (i=0; i<bs->length; i++) | ||
92 | v=(v<<8)|(bs->data[i]); | ||
93 | ret->length=(int)v; | ||
94 | } | ||
95 | |||
96 | ASN1_BIT_STRING_free(bs); | ||
97 | |||
98 | M_ASN1_D2I_Finish_2(a); | ||
99 | |||
100 | err_bn: | ||
101 | i=ERR_R_BN_LIB; | ||
102 | err: | ||
103 | ASN1err(ASN1_F_D2I_DHPARAMS,i); | ||
104 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) DH_free(ret); | ||
105 | if (bs != NULL) ASN1_BIT_STRING_free(bs); | ||
106 | return(NULL); | ||
107 | } | ||
108 | |||
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 @@ | |||
1 | /* crypto/asn1/d2i_dsap.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "bn.h" | ||
62 | #include "dsa.h" | ||
63 | #include "objects.h" | ||
64 | #include "asn1_mac.h" | ||
65 | |||
66 | /* | ||
67 | * ASN1err(ASN1_F_D2I_DSAPARAMS,ASN1_R_LENGTH_MISMATCH); | ||
68 | * ASN1err(ASN1_F_I2D_DSAPARAMS,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); | ||
69 | */ | ||
70 | |||
71 | DSA *d2i_DSAparams(a,pp,length) | ||
72 | DSA **a; | ||
73 | unsigned char **pp; | ||
74 | long length; | ||
75 | { | ||
76 | int i=ASN1_R_ERROR_STACK; | ||
77 | ASN1_INTEGER *bs=NULL; | ||
78 | M_ASN1_D2I_vars(a,DSA *,DSA_new); | ||
79 | |||
80 | M_ASN1_D2I_Init(); | ||
81 | M_ASN1_D2I_start_sequence(); | ||
82 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
83 | if ((ret->p=BN_bin2bn(bs->data,bs->length,ret->p)) == NULL) goto err_bn; | ||
84 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
85 | if ((ret->q=BN_bin2bn(bs->data,bs->length,ret->q)) == NULL) goto err_bn; | ||
86 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
87 | if ((ret->g=BN_bin2bn(bs->data,bs->length,ret->g)) == NULL) goto err_bn; | ||
88 | |||
89 | ASN1_BIT_STRING_free(bs); | ||
90 | |||
91 | M_ASN1_D2I_Finish_2(a); | ||
92 | |||
93 | err_bn: | ||
94 | i=ERR_R_BN_LIB; | ||
95 | err: | ||
96 | ASN1err(ASN1_F_D2I_DSAPARAMS,i); | ||
97 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_free(ret); | ||
98 | if (bs != NULL) ASN1_BIT_STRING_free(bs); | ||
99 | return(NULL); | ||
100 | } | ||
101 | |||
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 @@ | |||
1 | /* crypto/asn1/d2i_r_pr.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "bn.h" | ||
62 | #include "rsa.h" | ||
63 | #include "objects.h" | ||
64 | #include "asn1_mac.h" | ||
65 | |||
66 | /* | ||
67 | * ASN1err(ASN1_F_D2I_RSAPRIVATEKEY,ASN1_R_LENGTH_MISMATCH); | ||
68 | * ASN1err(ASN1_F_I2D_RSAPRIVATEKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); | ||
69 | * ASN1err(ASN1_F_I2D_RSAPRIVATEKEY,ASN1_R_PARSING); | ||
70 | */ | ||
71 | |||
72 | static ASN1_METHOD method={ | ||
73 | (int (*)()) i2d_RSAPrivateKey, | ||
74 | (char *(*)())d2i_RSAPrivateKey, | ||
75 | (char *(*)())RSA_new, | ||
76 | (void (*)()) RSA_free}; | ||
77 | |||
78 | ASN1_METHOD *RSAPrivateKey_asn1_meth() | ||
79 | { | ||
80 | return(&method); | ||
81 | } | ||
82 | |||
83 | RSA *d2i_RSAPrivateKey(a,pp,length) | ||
84 | RSA **a; | ||
85 | unsigned char **pp; | ||
86 | long length; | ||
87 | { | ||
88 | int i=ASN1_R_PARSING; | ||
89 | ASN1_INTEGER *bs=NULL; | ||
90 | M_ASN1_D2I_vars(a,RSA *,RSA_new); | ||
91 | |||
92 | M_ASN1_D2I_Init(); | ||
93 | M_ASN1_D2I_start_sequence(); | ||
94 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
95 | if (bs->length == 0) | ||
96 | ret->version=0; | ||
97 | else ret->version=bs->data[0]; | ||
98 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
99 | if ((ret->n=BN_bin2bn(bs->data,bs->length,ret->n)) == NULL) goto err_bn; | ||
100 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
101 | if ((ret->e=BN_bin2bn(bs->data,bs->length,ret->e)) == NULL) goto err_bn; | ||
102 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
103 | if ((ret->d=BN_bin2bn(bs->data,bs->length,ret->d)) == NULL) goto err_bn; | ||
104 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
105 | if ((ret->p=BN_bin2bn(bs->data,bs->length,ret->p)) == NULL) goto err_bn; | ||
106 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
107 | if ((ret->q=BN_bin2bn(bs->data,bs->length,ret->q)) == NULL) goto err_bn; | ||
108 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
109 | if ((ret->dmp1=BN_bin2bn(bs->data,bs->length,ret->dmp1)) == NULL) | ||
110 | goto err_bn; | ||
111 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
112 | if ((ret->dmq1=BN_bin2bn(bs->data,bs->length,ret->dmq1)) == NULL) | ||
113 | goto err_bn; | ||
114 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
115 | if ((ret->iqmp=BN_bin2bn(bs->data,bs->length,ret->iqmp)) == NULL) | ||
116 | goto err_bn; | ||
117 | |||
118 | ASN1_INTEGER_free(bs); | ||
119 | |||
120 | M_ASN1_D2I_Finish_2(a); | ||
121 | err_bn: | ||
122 | i=ERR_R_BN_LIB; | ||
123 | err: | ||
124 | ASN1err(ASN1_F_D2I_RSAPRIVATEKEY,i); | ||
125 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) RSA_free(ret); | ||
126 | if (bs != NULL) ASN1_INTEGER_free(bs); | ||
127 | return(NULL); | ||
128 | } | ||
129 | |||
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 @@ | |||
1 | /* crypto/asn1/d2i_r_pu.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "bn.h" | ||
62 | #include "rsa.h" | ||
63 | #include "objects.h" | ||
64 | #include "asn1_mac.h" | ||
65 | |||
66 | /* | ||
67 | * ASN1err(ASN1_F_D2I_RSAPUBLICKEY,ASN1_R_LENGTH_MISMATCH); | ||
68 | * ASN1err(ASN1_F_I2D_RSAPUBLICKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); | ||
69 | */ | ||
70 | |||
71 | RSA *d2i_RSAPublicKey(a,pp,length) | ||
72 | RSA **a; | ||
73 | unsigned char **pp; | ||
74 | long length; | ||
75 | { | ||
76 | int i=ASN1_R_PARSING; | ||
77 | ASN1_INTEGER *bs=NULL; | ||
78 | M_ASN1_D2I_vars(a,RSA *,RSA_new); | ||
79 | |||
80 | M_ASN1_D2I_Init(); | ||
81 | M_ASN1_D2I_start_sequence(); | ||
82 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
83 | if ((ret->n=BN_bin2bn(bs->data,bs->length,ret->n)) == NULL) goto err_bn; | ||
84 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
85 | if ((ret->e=BN_bin2bn(bs->data,bs->length,ret->e)) == NULL) goto err_bn; | ||
86 | |||
87 | ASN1_INTEGER_free(bs); | ||
88 | bs=NULL; | ||
89 | |||
90 | M_ASN1_D2I_Finish_2(a); | ||
91 | |||
92 | err_bn: | ||
93 | i=ERR_R_BN_LIB; | ||
94 | err: | ||
95 | ASN1err(ASN1_F_D2I_RSAPUBLICKEY,i); | ||
96 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) RSA_free(ret); | ||
97 | if (bs != NULL) ASN1_INTEGER_free(bs); | ||
98 | return(NULL); | ||
99 | } | ||
100 | |||
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 @@ | |||
1 | /* crypto/asn1/d2i_s_pr.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | /* Origional version from Steven Schoch <schoch@sheba.arc.nasa.gov> */ | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include "cryptlib.h" | ||
63 | #include "bn.h" | ||
64 | #include "dsa.h" | ||
65 | #include "objects.h" | ||
66 | #include "asn1_mac.h" | ||
67 | |||
68 | /* | ||
69 | * ASN1err(ASN1_F_D2I_DSAPRIVATEKEY,ASN1_R_LENGTH_MISMATCH); | ||
70 | * ASN1err(ASN1_F_I2D_DSAPRIVATEKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); | ||
71 | * ASN1err(ASN1_F_I2D_DSAPRIVATEKEY,ASN1_R_PARSING); | ||
72 | */ | ||
73 | |||
74 | DSA *d2i_DSAPrivateKey(a,pp,length) | ||
75 | DSA **a; | ||
76 | unsigned char **pp; | ||
77 | long length; | ||
78 | { | ||
79 | int i=ASN1_R_PARSING; | ||
80 | ASN1_INTEGER *bs=NULL; | ||
81 | M_ASN1_D2I_vars(a,DSA *,DSA_new); | ||
82 | |||
83 | M_ASN1_D2I_Init(); | ||
84 | M_ASN1_D2I_start_sequence(); | ||
85 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
86 | if (bs->length == 0) | ||
87 | ret->version=0; | ||
88 | else ret->version=bs->data[0]; | ||
89 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
90 | if ((ret->p=BN_bin2bn(bs->data,bs->length,ret->p)) == NULL) goto err_bn; | ||
91 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
92 | if ((ret->q=BN_bin2bn(bs->data,bs->length,ret->q)) == NULL) goto err_bn; | ||
93 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
94 | if ((ret->g=BN_bin2bn(bs->data,bs->length,ret->g)) == NULL) goto err_bn; | ||
95 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
96 | if ((ret->pub_key=BN_bin2bn(bs->data,bs->length,ret->pub_key)) | ||
97 | == NULL) goto err_bn; | ||
98 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
99 | if ((ret->priv_key=BN_bin2bn(bs->data,bs->length,ret->priv_key)) | ||
100 | == NULL) goto err_bn; | ||
101 | |||
102 | ASN1_INTEGER_free(bs); | ||
103 | |||
104 | M_ASN1_D2I_Finish_2(a); | ||
105 | err_bn: | ||
106 | i=ERR_R_BN_LIB; | ||
107 | err: | ||
108 | ASN1err(ASN1_F_D2I_DSAPRIVATEKEY,i); | ||
109 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_free(ret); | ||
110 | if (bs != NULL) ASN1_INTEGER_free(bs); | ||
111 | return(NULL); | ||
112 | } | ||
113 | |||
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 @@ | |||
1 | /* crypto/asn1/d2i_s_pu.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | /* Origional version from Steven Schoch <schoch@sheba.arc.nasa.gov> */ | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include "cryptlib.h" | ||
63 | #include "bn.h" | ||
64 | #include "dsa.h" | ||
65 | #include "objects.h" | ||
66 | #include "asn1_mac.h" | ||
67 | |||
68 | /* | ||
69 | * ASN1err(ASN1_F_D2I_DSAPUBLICKEY,ASN1_R_LENGTH_MISMATCH); | ||
70 | * ASN1err(ASN1_F_I2D_DSAPUBLICKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); | ||
71 | */ | ||
72 | |||
73 | DSA *d2i_DSAPublicKey(a,pp,length) | ||
74 | DSA **a; | ||
75 | unsigned char **pp; | ||
76 | long length; | ||
77 | { | ||
78 | int i=ASN1_R_PARSING; | ||
79 | ASN1_INTEGER *bs=NULL; | ||
80 | M_ASN1_D2I_vars(a,DSA *,DSA_new); | ||
81 | |||
82 | M_ASN1_D2I_Init(); | ||
83 | if ((length != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) | ||
84 | == (V_ASN1_UNIVERSAL|(V_ASN1_INTEGER)))) | ||
85 | { | ||
86 | c.slen=length; | ||
87 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
88 | if ((ret->pub_key=BN_bin2bn(bs->data,bs->length,ret->pub_key)) | ||
89 | == NULL) | ||
90 | goto err_bn; | ||
91 | ret->write_params=0; | ||
92 | } | ||
93 | else | ||
94 | { | ||
95 | M_ASN1_D2I_start_sequence(); | ||
96 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
97 | if ((ret->pub_key=BN_bin2bn(bs->data,bs->length,ret->pub_key)) | ||
98 | == NULL) | ||
99 | goto err_bn; | ||
100 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
101 | if ((ret->p=BN_bin2bn(bs->data,bs->length,ret->p)) == NULL) | ||
102 | goto err_bn; | ||
103 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
104 | if ((ret->q=BN_bin2bn(bs->data,bs->length,ret->q)) == NULL) | ||
105 | goto err_bn; | ||
106 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
107 | if ((ret->g=BN_bin2bn(bs->data,bs->length,ret->g)) == NULL) | ||
108 | goto err_bn; | ||
109 | |||
110 | ret->write_params=1; | ||
111 | } | ||
112 | |||
113 | ASN1_INTEGER_free(bs); | ||
114 | bs=NULL; | ||
115 | M_ASN1_D2I_Finish_2(a); | ||
116 | err_bn: | ||
117 | i=ERR_R_BN_LIB; | ||
118 | err: | ||
119 | ASN1err(ASN1_F_D2I_DSAPUBLICKEY,i); | ||
120 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_free(ret); | ||
121 | if (bs != NULL) ASN1_INTEGER_free(bs); | ||
122 | return(NULL); | ||
123 | } | ||
124 | |||
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 @@ | |||
1 | /* crypto/asn1/i2d_dhp.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "bn.h" | ||
62 | #include "asn1_mac.h" | ||
63 | #include "dh.h" | ||
64 | |||
65 | /* | ||
66 | * ASN1err(ASN1_F_D2I_DHPARAMS,ASN1_R_LENGTH_MISMATCH); | ||
67 | * ASN1err(ASN1_F_X509_DHPARAMS_NEW,ASN1_R_LENGTH_MISMATCH); | ||
68 | */ | ||
69 | |||
70 | int i2d_DHparams(a,pp) | ||
71 | DH *a; | ||
72 | unsigned char **pp; | ||
73 | { | ||
74 | BIGNUM *num[3]; | ||
75 | ASN1_INTEGER bs; | ||
76 | unsigned int j,i,tot=0,len,max=0; | ||
77 | int t,ret= -1; | ||
78 | unsigned char *p; | ||
79 | |||
80 | if (a == NULL) return(0); | ||
81 | num[0]=a->p; | ||
82 | num[1]=a->g; | ||
83 | if (a->length != 0) | ||
84 | { | ||
85 | if ((num[2]=BN_new()) == NULL) goto err; | ||
86 | if (!BN_set_word(num[2],a->length)) goto err; | ||
87 | } | ||
88 | else | ||
89 | num[2]=NULL; | ||
90 | |||
91 | for (i=0; i<3; i++) | ||
92 | { | ||
93 | if (num[i] == NULL) continue; | ||
94 | j=BN_num_bits(num[i]); | ||
95 | len=((j == 0)?0:((j/8)+1)); | ||
96 | if (len > max) max=len; | ||
97 | len=ASN1_object_size(0,len, | ||
98 | (num[i]->neg)?V_ASN1_NEG_INTEGER:V_ASN1_INTEGER); | ||
99 | tot+=len; | ||
100 | } | ||
101 | |||
102 | t=ASN1_object_size(1,tot,V_ASN1_SEQUENCE); | ||
103 | if (pp == NULL) return(t); | ||
104 | |||
105 | p= *pp; | ||
106 | ASN1_put_object(&p,1,tot,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); | ||
107 | |||
108 | bs.type=V_ASN1_INTEGER; | ||
109 | bs.data=(unsigned char *)Malloc(max+4); | ||
110 | if (bs.data == NULL) | ||
111 | { | ||
112 | ASN1err(ASN1_F_I2D_DHPARAMS,ERR_R_MALLOC_FAILURE); | ||
113 | goto err; | ||
114 | } | ||
115 | |||
116 | for (i=0; i<3; i++) | ||
117 | { | ||
118 | if (num[i] == NULL) continue; | ||
119 | bs.length=BN_bn2bin(num[i],bs.data); | ||
120 | i2d_ASN1_INTEGER(&bs,&p); | ||
121 | } | ||
122 | Free((char *)bs.data); | ||
123 | ret=t; | ||
124 | err: | ||
125 | if (num[2] != NULL) BN_free(num[2]); | ||
126 | *pp=p; | ||
127 | return(ret); | ||
128 | } | ||
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 @@ | |||
1 | /* crypto/asn1/i2d_dsap.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "bn.h" | ||
62 | #include "asn1_mac.h" | ||
63 | #include "dsa.h" | ||
64 | |||
65 | /* | ||
66 | * ASN1err(ASN1_F_D2I_DSAPARAMS,ASN1_R_LENGTH_MISMATCH); | ||
67 | */ | ||
68 | |||
69 | int i2d_DSAparams(a,pp) | ||
70 | DSA *a; | ||
71 | unsigned char **pp; | ||
72 | { | ||
73 | BIGNUM *num[3]; | ||
74 | ASN1_INTEGER bs; | ||
75 | unsigned int j,i,tot=0,len,max=0; | ||
76 | int t,ret= -1; | ||
77 | unsigned char *p; | ||
78 | |||
79 | if (a == NULL) return(0); | ||
80 | num[0]=a->p; | ||
81 | num[1]=a->q; | ||
82 | num[2]=a->g; | ||
83 | |||
84 | for (i=0; i<3; i++) | ||
85 | { | ||
86 | if (num[i] == NULL) continue; | ||
87 | j=BN_num_bits(num[i]); | ||
88 | len=((j == 0)?0:((j/8)+1)); | ||
89 | if (len > max) max=len; | ||
90 | len=ASN1_object_size(0,len, | ||
91 | (num[i]->neg)?V_ASN1_NEG_INTEGER:V_ASN1_INTEGER); | ||
92 | tot+=len; | ||
93 | } | ||
94 | |||
95 | t=ASN1_object_size(1,tot,V_ASN1_SEQUENCE); | ||
96 | if (pp == NULL) return(t); | ||
97 | |||
98 | p= *pp; | ||
99 | ASN1_put_object(&p,1,tot,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); | ||
100 | |||
101 | bs.type=V_ASN1_INTEGER; | ||
102 | bs.data=(unsigned char *)Malloc(max+4); | ||
103 | if (bs.data == NULL) | ||
104 | { | ||
105 | ASN1err(ASN1_F_I2D_DSAPARAMS,ERR_R_MALLOC_FAILURE); | ||
106 | goto err; | ||
107 | } | ||
108 | |||
109 | for (i=0; i<3; i++) | ||
110 | { | ||
111 | if (num[i] == NULL) continue; | ||
112 | bs.length=BN_bn2bin(num[i],bs.data); | ||
113 | i2d_ASN1_INTEGER(&bs,&p); | ||
114 | } | ||
115 | Free((char *)bs.data); | ||
116 | ret=t; | ||
117 | err: | ||
118 | *pp=p; | ||
119 | return(ret); | ||
120 | } | ||
121 | |||
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 @@ | |||
1 | /* crypto/asn1/i2d_r_pr.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "bn.h" | ||
62 | #include "rsa.h" | ||
63 | #include "objects.h" | ||
64 | #include "asn1_mac.h" | ||
65 | |||
66 | /* | ||
67 | * ASN1err(ASN1_F_D2I_RSAPRIVATEKEY,ASN1_R_LENGTH_MISMATCH); | ||
68 | * ASN1err(ASN1_F_I2D_RSAPRIVATEKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); | ||
69 | */ | ||
70 | |||
71 | int i2d_RSAPrivateKey(a,pp) | ||
72 | RSA *a; | ||
73 | unsigned char **pp; | ||
74 | { | ||
75 | BIGNUM *num[9]; | ||
76 | unsigned char data[1]; | ||
77 | ASN1_INTEGER bs; | ||
78 | unsigned int j,i,tot,t,len,max=0; | ||
79 | unsigned char *p; | ||
80 | |||
81 | if (a == NULL) return(0); | ||
82 | |||
83 | num[1]=a->n; | ||
84 | num[2]=a->e; | ||
85 | num[3]=a->d; | ||
86 | num[4]=a->p; | ||
87 | num[5]=a->q; | ||
88 | num[6]=a->dmp1; | ||
89 | num[7]=a->dmq1; | ||
90 | num[8]=a->iqmp; | ||
91 | |||
92 | bs.length=1; | ||
93 | bs.data=data; | ||
94 | bs.type=V_ASN1_INTEGER; | ||
95 | data[0]=a->version&0x7f; | ||
96 | |||
97 | tot=i2d_ASN1_INTEGER(&(bs),NULL); | ||
98 | for (i=1; i<9; i++) | ||
99 | { | ||
100 | j=BN_num_bits(num[i]); | ||
101 | len=((j == 0)?0:((j/8)+1)); | ||
102 | if (len > max) max=len; | ||
103 | len=ASN1_object_size(0,len, | ||
104 | (num[i]->neg)?V_ASN1_NEG_INTEGER:V_ASN1_INTEGER); | ||
105 | tot+=len; | ||
106 | } | ||
107 | |||
108 | t=ASN1_object_size(1,tot,V_ASN1_SEQUENCE); | ||
109 | if (pp == NULL) return(t); | ||
110 | |||
111 | p= *pp; | ||
112 | ASN1_put_object(&p,1,tot,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); | ||
113 | |||
114 | i2d_ASN1_INTEGER(&bs,&p); | ||
115 | |||
116 | bs.data=(unsigned char *)Malloc(max+4); | ||
117 | if (bs.data == NULL) | ||
118 | { | ||
119 | ASN1err(ASN1_F_I2D_RSAPRIVATEKEY,ERR_R_MALLOC_FAILURE); | ||
120 | return(-1); | ||
121 | } | ||
122 | |||
123 | for (i=1; i<9; i++) | ||
124 | { | ||
125 | bs.length=BN_bn2bin(num[i],bs.data); | ||
126 | i2d_ASN1_INTEGER(&bs,&p); | ||
127 | } | ||
128 | Free((char *)bs.data); | ||
129 | *pp=p; | ||
130 | return(t); | ||
131 | } | ||
132 | |||
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 @@ | |||
1 | /* crypto/asn1/i2d_r_pu.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "bn.h" | ||
62 | #include "rsa.h" | ||
63 | #include "objects.h" | ||
64 | #include "asn1_mac.h" | ||
65 | |||
66 | /* | ||
67 | * ASN1err(ASN1_F_D2I_RSAPUBLICKEY,ASN1_R_LENGTH_MISMATCH); | ||
68 | * ASN1err(ASN1_F_I2D_RSAPUBLICKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); | ||
69 | */ | ||
70 | |||
71 | int i2d_RSAPublicKey(a,pp) | ||
72 | RSA *a; | ||
73 | unsigned char **pp; | ||
74 | { | ||
75 | BIGNUM *num[2]; | ||
76 | ASN1_INTEGER bs; | ||
77 | unsigned int j,i,tot=0,len,max=0,t; | ||
78 | unsigned char *p; | ||
79 | |||
80 | if (a == NULL) return(0); | ||
81 | |||
82 | num[0]=a->n; | ||
83 | num[1]=a->e; | ||
84 | |||
85 | for (i=0; i<2; i++) | ||
86 | { | ||
87 | j=BN_num_bits(num[i]); | ||
88 | len=((j == 0)?0:((j/8)+1)); | ||
89 | if (len > max) max=len; | ||
90 | len=ASN1_object_size(0,len, | ||
91 | (num[i]->neg)?V_ASN1_NEG_INTEGER:V_ASN1_INTEGER); | ||
92 | tot+=len; | ||
93 | } | ||
94 | |||
95 | t=ASN1_object_size(1,tot,V_ASN1_SEQUENCE); | ||
96 | if (pp == NULL) return(t); | ||
97 | |||
98 | p= *pp; | ||
99 | ASN1_put_object(&p,1,tot,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); | ||
100 | |||
101 | bs.type=V_ASN1_INTEGER; | ||
102 | bs.data=(unsigned char *)Malloc(max+4); | ||
103 | if (bs.data == NULL) | ||
104 | { | ||
105 | ASN1err(ASN1_F_I2D_RSAPUBLICKEY,ERR_R_MALLOC_FAILURE); | ||
106 | return(-1); | ||
107 | } | ||
108 | |||
109 | for (i=0; i<2; i++) | ||
110 | { | ||
111 | bs.length=BN_bn2bin(num[i],bs.data); | ||
112 | i2d_ASN1_INTEGER(&bs,&p); | ||
113 | } | ||
114 | Free((char *)bs.data); | ||
115 | *pp=p; | ||
116 | return(t); | ||
117 | } | ||
118 | |||
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 @@ | |||
1 | /* crypto/asn1/i2d_s_pr.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "bn.h" | ||
62 | #include "dsa.h" | ||
63 | #include "objects.h" | ||
64 | #include "asn1_mac.h" | ||
65 | |||
66 | /* | ||
67 | * ASN1err(ASN1_F_I2D_DSAPRIVATEKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); | ||
68 | */ | ||
69 | |||
70 | int i2d_DSAPrivateKey(a,pp) | ||
71 | DSA *a; | ||
72 | unsigned char **pp; | ||
73 | { | ||
74 | BIGNUM *num[6]; | ||
75 | unsigned char data[1]; | ||
76 | ASN1_INTEGER bs; | ||
77 | unsigned int j,i,tot,t,len,max=0; | ||
78 | unsigned char *p; | ||
79 | |||
80 | if (a == NULL) return(0); | ||
81 | |||
82 | num[1]=a->p; | ||
83 | num[2]=a->q; | ||
84 | num[3]=a->g; | ||
85 | num[4]=a->pub_key; | ||
86 | num[5]=a->priv_key; | ||
87 | |||
88 | bs.length=1; | ||
89 | bs.data=data; | ||
90 | bs.type=V_ASN1_INTEGER; | ||
91 | data[0]=a->version&0x7f; | ||
92 | |||
93 | tot=i2d_ASN1_INTEGER(&(bs),NULL); | ||
94 | for (i=1; i<6; i++) | ||
95 | { | ||
96 | j=BN_num_bits(num[i]); | ||
97 | len=((j == 0)?0:((j/8)+1)); | ||
98 | if (len > max) max=len; | ||
99 | len=ASN1_object_size(0,len, | ||
100 | (num[i]->neg)?V_ASN1_NEG_INTEGER:V_ASN1_INTEGER); | ||
101 | tot+=len; | ||
102 | } | ||
103 | |||
104 | t=ASN1_object_size(1,tot,V_ASN1_SEQUENCE); | ||
105 | if (pp == NULL) return(t); | ||
106 | |||
107 | p= *pp; | ||
108 | ASN1_put_object(&p,1,tot,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); | ||
109 | |||
110 | i2d_ASN1_INTEGER(&bs,&p); | ||
111 | |||
112 | bs.data=(unsigned char *)Malloc(max+4); | ||
113 | if (bs.data == NULL) | ||
114 | { | ||
115 | ASN1err(ASN1_F_I2D_DSAPRIVATEKEY,ERR_R_MALLOC_FAILURE); | ||
116 | return(-1); | ||
117 | } | ||
118 | |||
119 | for (i=1; i<6; i++) | ||
120 | { | ||
121 | bs.length=BN_bn2bin(num[i],bs.data); | ||
122 | i2d_ASN1_INTEGER(&bs,&p); | ||
123 | } | ||
124 | Free((char *)bs.data); | ||
125 | *pp=p; | ||
126 | return(t); | ||
127 | } | ||
128 | |||
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 @@ | |||
1 | /* crypto/asn1/i2d_s_pu.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "bn.h" | ||
62 | #include "dsa.h" | ||
63 | #include "objects.h" | ||
64 | #include "asn1_mac.h" | ||
65 | |||
66 | /* | ||
67 | * ASN1err(ASN1_F_I2D_DSAPUBLICKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); | ||
68 | */ | ||
69 | |||
70 | int i2d_DSAPublicKey(a,pp) | ||
71 | DSA *a; | ||
72 | unsigned char **pp; | ||
73 | { | ||
74 | BIGNUM *num[4]; | ||
75 | ASN1_INTEGER bs; | ||
76 | unsigned int j,i,tot=0,len,max=0,t=0,all,n=1; | ||
77 | unsigned char *p; | ||
78 | |||
79 | if (a == NULL) return(0); | ||
80 | |||
81 | all=a->write_params; | ||
82 | |||
83 | num[0]=a->pub_key; | ||
84 | if (all) | ||
85 | { | ||
86 | num[1]=a->p; | ||
87 | num[2]=a->q; | ||
88 | num[3]=a->g; | ||
89 | n=4; | ||
90 | } | ||
91 | |||
92 | for (i=0; i<n; i++) | ||
93 | { | ||
94 | j=BN_num_bits(num[i]); | ||
95 | len=((j == 0)?0:((j/8)+1)); | ||
96 | if (len > max) max=len; | ||
97 | len=ASN1_object_size(0,len, | ||
98 | (num[i]->neg)?V_ASN1_NEG_INTEGER:V_ASN1_INTEGER); | ||
99 | tot+=len; | ||
100 | } | ||
101 | |||
102 | if (all) | ||
103 | { | ||
104 | t=ASN1_object_size(1,tot,V_ASN1_SEQUENCE); | ||
105 | if (pp == NULL) return(t); | ||
106 | } | ||
107 | else | ||
108 | { | ||
109 | if (pp == NULL) return(tot); | ||
110 | } | ||
111 | |||
112 | p= *pp; | ||
113 | if (all) | ||
114 | ASN1_put_object(&p,1,tot,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); | ||
115 | |||
116 | bs.type=V_ASN1_INTEGER; | ||
117 | bs.data=(unsigned char *)Malloc(max+4); | ||
118 | if (bs.data == NULL) | ||
119 | { | ||
120 | ASN1err(ASN1_F_I2D_DSAPUBLICKEY,ERR_R_MALLOC_FAILURE); | ||
121 | return(-1); | ||
122 | } | ||
123 | |||
124 | for (i=0; i<n; i++) | ||
125 | { | ||
126 | bs.length=BN_bn2bin(num[i],bs.data); | ||
127 | i2d_ASN1_INTEGER(&bs,&p); | ||
128 | } | ||
129 | Free((char *)bs.data); | ||
130 | *pp=p; | ||
131 | return(t); | ||
132 | } | ||
133 | |||
diff --git a/src/lib/libcrypto/asn1/p7_dgst.c b/src/lib/libcrypto/asn1/p7_dgst.c new file mode 100644 index 0000000000..f71ed8eb1d --- /dev/null +++ b/src/lib/libcrypto/asn1/p7_dgst.c | |||
@@ -0,0 +1,130 @@ | |||
1 | /* crypto/asn1/p7_dgst.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "asn1_mac.h" | ||
62 | #include "x509.h" | ||
63 | |||
64 | /* | ||
65 | * ASN1err(ASN1_F_PKCS7_DIGEST_NEW,ASN1_R_MISSING_EOS); | ||
66 | * ASN1err(ASN1_F_D2I_PKCS7_DIGEST,ASN1_R_LENGTH_MISMATCH); | ||
67 | */ | ||
68 | |||
69 | int i2d_PKCS7_DIGEST(a,pp) | ||
70 | PKCS7_DIGEST *a; | ||
71 | unsigned char **pp; | ||
72 | { | ||
73 | M_ASN1_I2D_vars(a); | ||
74 | |||
75 | M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); | ||
76 | M_ASN1_I2D_len(a->md,i2d_X509_ALGOR); | ||
77 | M_ASN1_I2D_len(a->contents,i2d_PKCS7); | ||
78 | M_ASN1_I2D_len(a->digest,i2d_ASN1_OCTET_STRING); | ||
79 | |||
80 | M_ASN1_I2D_seq_total(); | ||
81 | |||
82 | M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER); | ||
83 | M_ASN1_I2D_put(a->md,i2d_X509_ALGOR); | ||
84 | M_ASN1_I2D_put(a->contents,i2d_PKCS7); | ||
85 | M_ASN1_I2D_put(a->digest,i2d_ASN1_OCTET_STRING); | ||
86 | |||
87 | M_ASN1_I2D_finish(); | ||
88 | } | ||
89 | |||
90 | PKCS7_DIGEST *d2i_PKCS7_DIGEST(a,pp,length) | ||
91 | PKCS7_DIGEST **a; | ||
92 | unsigned char **pp; | ||
93 | long length; | ||
94 | { | ||
95 | M_ASN1_D2I_vars(a,PKCS7_DIGEST *,PKCS7_DIGEST_new); | ||
96 | |||
97 | M_ASN1_D2I_Init(); | ||
98 | M_ASN1_D2I_start_sequence(); | ||
99 | M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); | ||
100 | M_ASN1_D2I_get(ret->md,d2i_X509_ALGOR); | ||
101 | M_ASN1_D2I_get(ret->contents,d2i_PKCS7); | ||
102 | M_ASN1_D2I_get(ret->digest,d2i_ASN1_OCTET_STRING); | ||
103 | |||
104 | M_ASN1_D2I_Finish(a,PKCS7_DIGEST_free,ASN1_F_D2I_PKCS7_DIGEST); | ||
105 | } | ||
106 | |||
107 | PKCS7_DIGEST *PKCS7_DIGEST_new() | ||
108 | { | ||
109 | PKCS7_DIGEST *ret=NULL; | ||
110 | |||
111 | M_ASN1_New_Malloc(ret,PKCS7_DIGEST); | ||
112 | M_ASN1_New(ret->version,ASN1_INTEGER_new); | ||
113 | M_ASN1_New(ret->md,X509_ALGOR_new); | ||
114 | M_ASN1_New(ret->contents,PKCS7_new); | ||
115 | M_ASN1_New(ret->digest,ASN1_OCTET_STRING_new); | ||
116 | return(ret); | ||
117 | M_ASN1_New_Error(ASN1_F_PKCS7_DIGEST_NEW); | ||
118 | } | ||
119 | |||
120 | void PKCS7_DIGEST_free(a) | ||
121 | PKCS7_DIGEST *a; | ||
122 | { | ||
123 | if (a == NULL) return; | ||
124 | ASN1_INTEGER_free(a->version); | ||
125 | X509_ALGOR_free(a->md); | ||
126 | PKCS7_free(a->contents); | ||
127 | ASN1_OCTET_STRING_free(a->digest); | ||
128 | Free((char *)a); | ||
129 | } | ||
130 | |||
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 @@ | |||
1 | /* crypto/asn1/p7_enc.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "asn1_mac.h" | ||
62 | #include "x509.h" | ||
63 | |||
64 | /* | ||
65 | * ASN1err(ASN1_F_PKCS7_ENCRYPT_NEW,ASN1_R_LENGTH_MISMATCH); | ||
66 | * ASN1err(ASN1_F_D2I_PKCS7_ENCRYPT,ASN1_R_LENGTH_MISMATCH); | ||
67 | */ | ||
68 | |||
69 | int i2d_PKCS7_ENCRYPT(a,pp) | ||
70 | PKCS7_ENCRYPT *a; | ||
71 | unsigned char **pp; | ||
72 | { | ||
73 | M_ASN1_I2D_vars(a); | ||
74 | |||
75 | M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); | ||
76 | M_ASN1_I2D_len(a->enc_data,i2d_PKCS7_ENC_CONTENT); | ||
77 | |||
78 | M_ASN1_I2D_seq_total(); | ||
79 | |||
80 | M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER); | ||
81 | M_ASN1_I2D_put(a->enc_data,i2d_PKCS7_ENC_CONTENT); | ||
82 | |||
83 | M_ASN1_I2D_finish(); | ||
84 | } | ||
85 | |||
86 | PKCS7_ENCRYPT *d2i_PKCS7_ENCRYPT(a,pp,length) | ||
87 | PKCS7_ENCRYPT **a; | ||
88 | unsigned char **pp; | ||
89 | long length; | ||
90 | { | ||
91 | M_ASN1_D2I_vars(a,PKCS7_ENCRYPT *,PKCS7_ENCRYPT_new); | ||
92 | |||
93 | M_ASN1_D2I_Init(); | ||
94 | M_ASN1_D2I_start_sequence(); | ||
95 | M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); | ||
96 | M_ASN1_D2I_get(ret->enc_data,d2i_PKCS7_ENC_CONTENT); | ||
97 | |||
98 | M_ASN1_D2I_Finish(a,PKCS7_ENCRYPT_free,ASN1_F_D2I_PKCS7_ENCRYPT); | ||
99 | } | ||
100 | |||
101 | PKCS7_ENCRYPT *PKCS7_ENCRYPT_new() | ||
102 | { | ||
103 | PKCS7_ENCRYPT *ret=NULL; | ||
104 | |||
105 | M_ASN1_New_Malloc(ret,PKCS7_ENCRYPT); | ||
106 | M_ASN1_New(ret->version,ASN1_INTEGER_new); | ||
107 | M_ASN1_New(ret->enc_data,PKCS7_ENC_CONTENT_new); | ||
108 | return(ret); | ||
109 | M_ASN1_New_Error(ASN1_F_PKCS7_ENCRYPT_NEW); | ||
110 | } | ||
111 | |||
112 | void PKCS7_ENCRYPT_free(a) | ||
113 | PKCS7_ENCRYPT *a; | ||
114 | { | ||
115 | if (a == NULL) return; | ||
116 | ASN1_INTEGER_free(a->version); | ||
117 | PKCS7_ENC_CONTENT_free(a->enc_data); | ||
118 | Free((char *)a); | ||
119 | } | ||
120 | |||
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 @@ | |||
1 | /* crypto/asn1/p7_enc_c.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "asn1_mac.h" | ||
62 | #include "x509.h" | ||
63 | |||
64 | /* | ||
65 | * ASN1err(ASN1_F_PKCS7_ENC_CONTENT_NEW,ASN1_R_LENGTH_MISMATCH); | ||
66 | * ASN1err(ASN1_F_D2I_PKCS7_ENC_CONTENT,ASN1_R_LENGTH_MISMATCH); | ||
67 | */ | ||
68 | |||
69 | int i2d_PKCS7_ENC_CONTENT(a,pp) | ||
70 | PKCS7_ENC_CONTENT *a; | ||
71 | unsigned char **pp; | ||
72 | { | ||
73 | M_ASN1_I2D_vars(a); | ||
74 | |||
75 | M_ASN1_I2D_len(a->content_type,i2d_ASN1_OBJECT); | ||
76 | M_ASN1_I2D_len(a->algorithm,i2d_X509_ALGOR); | ||
77 | M_ASN1_I2D_len_IMP_opt(a->enc_data,i2d_ASN1_OCTET_STRING); | ||
78 | |||
79 | M_ASN1_I2D_seq_total(); | ||
80 | |||
81 | M_ASN1_I2D_put(a->content_type,i2d_ASN1_OBJECT); | ||
82 | M_ASN1_I2D_put(a->algorithm,i2d_X509_ALGOR); | ||
83 | M_ASN1_I2D_put_IMP_opt(a->enc_data,i2d_ASN1_OCTET_STRING,0); | ||
84 | |||
85 | M_ASN1_I2D_finish(); | ||
86 | } | ||
87 | |||
88 | PKCS7_ENC_CONTENT *d2i_PKCS7_ENC_CONTENT(a,pp,length) | ||
89 | PKCS7_ENC_CONTENT **a; | ||
90 | unsigned char **pp; | ||
91 | long length; | ||
92 | { | ||
93 | M_ASN1_D2I_vars(a,PKCS7_ENC_CONTENT *,PKCS7_ENC_CONTENT_new); | ||
94 | |||
95 | M_ASN1_D2I_Init(); | ||
96 | M_ASN1_D2I_start_sequence(); | ||
97 | M_ASN1_D2I_get(ret->content_type,d2i_ASN1_OBJECT); | ||
98 | M_ASN1_D2I_get(ret->algorithm,d2i_X509_ALGOR); | ||
99 | M_ASN1_D2I_get_IMP_opt(ret->enc_data,d2i_ASN1_OCTET_STRING,0, | ||
100 | V_ASN1_OCTET_STRING); | ||
101 | |||
102 | M_ASN1_D2I_Finish(a,PKCS7_ENC_CONTENT_free, | ||
103 | ASN1_F_D2I_PKCS7_ENC_CONTENT); | ||
104 | } | ||
105 | |||
106 | PKCS7_ENC_CONTENT *PKCS7_ENC_CONTENT_new() | ||
107 | { | ||
108 | PKCS7_ENC_CONTENT *ret=NULL; | ||
109 | |||
110 | M_ASN1_New_Malloc(ret,PKCS7_ENC_CONTENT); | ||
111 | M_ASN1_New(ret->content_type,ASN1_OBJECT_new); | ||
112 | M_ASN1_New(ret->algorithm,X509_ALGOR_new); | ||
113 | ret->enc_data=NULL; | ||
114 | return(ret); | ||
115 | M_ASN1_New_Error(ASN1_F_PKCS7_ENC_CONTENT_NEW); | ||
116 | } | ||
117 | |||
118 | void PKCS7_ENC_CONTENT_free(a) | ||
119 | PKCS7_ENC_CONTENT *a; | ||
120 | { | ||
121 | if (a == NULL) return; | ||
122 | ASN1_OBJECT_free(a->content_type); | ||
123 | X509_ALGOR_free(a->algorithm); | ||
124 | ASN1_OCTET_STRING_free(a->enc_data); | ||
125 | Free((char *)a); | ||
126 | } | ||
127 | |||
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 @@ | |||
1 | /* crypto/asn1/p7_evp.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "asn1_mac.h" | ||
62 | #include "x509.h" | ||
63 | |||
64 | /* | ||
65 | * ASN1err(ASN1_F_PKCS7_ENVELOPE_NEW,ASN1_R_LENGTH_MISMATCH); | ||
66 | * ASN1err(ASN1_F_D2I_PKCS7_ENVELOPE,ASN1_R_LENGTH_MISMATCH); | ||
67 | */ | ||
68 | |||
69 | int i2d_PKCS7_ENVELOPE(a,pp) | ||
70 | PKCS7_ENVELOPE *a; | ||
71 | unsigned char **pp; | ||
72 | { | ||
73 | M_ASN1_I2D_vars(a); | ||
74 | |||
75 | M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); | ||
76 | M_ASN1_I2D_len_SET(a->recipientinfo,i2d_PKCS7_RECIP_INFO); | ||
77 | M_ASN1_I2D_len(a->enc_data,i2d_PKCS7_ENC_CONTENT); | ||
78 | |||
79 | M_ASN1_I2D_seq_total(); | ||
80 | |||
81 | M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER); | ||
82 | M_ASN1_I2D_put_SET(a->recipientinfo,i2d_PKCS7_RECIP_INFO); | ||
83 | M_ASN1_I2D_put(a->enc_data,i2d_PKCS7_ENC_CONTENT); | ||
84 | |||
85 | M_ASN1_I2D_finish(); | ||
86 | } | ||
87 | |||
88 | PKCS7_ENVELOPE *d2i_PKCS7_ENVELOPE(a,pp,length) | ||
89 | PKCS7_ENVELOPE **a; | ||
90 | unsigned char **pp; | ||
91 | long length; | ||
92 | { | ||
93 | M_ASN1_D2I_vars(a,PKCS7_ENVELOPE *,PKCS7_ENVELOPE_new); | ||
94 | |||
95 | M_ASN1_D2I_Init(); | ||
96 | M_ASN1_D2I_start_sequence(); | ||
97 | M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); | ||
98 | M_ASN1_D2I_get_set(ret->recipientinfo,d2i_PKCS7_RECIP_INFO); | ||
99 | M_ASN1_D2I_get(ret->enc_data,d2i_PKCS7_ENC_CONTENT); | ||
100 | |||
101 | M_ASN1_D2I_Finish(a,PKCS7_ENVELOPE_free,ASN1_F_D2I_PKCS7_ENVELOPE); | ||
102 | } | ||
103 | |||
104 | PKCS7_ENVELOPE *PKCS7_ENVELOPE_new() | ||
105 | { | ||
106 | PKCS7_ENVELOPE *ret=NULL; | ||
107 | |||
108 | M_ASN1_New_Malloc(ret,PKCS7_ENVELOPE); | ||
109 | M_ASN1_New(ret->version,ASN1_INTEGER_new); | ||
110 | M_ASN1_New(ret->recipientinfo,sk_new_null); | ||
111 | M_ASN1_New(ret->enc_data,PKCS7_ENC_CONTENT_new); | ||
112 | return(ret); | ||
113 | M_ASN1_New_Error(ASN1_F_PKCS7_ENVELOPE_NEW); | ||
114 | } | ||
115 | |||
116 | void PKCS7_ENVELOPE_free(a) | ||
117 | PKCS7_ENVELOPE *a; | ||
118 | { | ||
119 | if (a == NULL) return; | ||
120 | ASN1_INTEGER_free(a->version); | ||
121 | sk_pop_free(a->recipientinfo,PKCS7_RECIP_INFO_free); | ||
122 | PKCS7_ENC_CONTENT_free(a->enc_data); | ||
123 | Free((char *)a); | ||
124 | } | ||
125 | |||
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 @@ | |||
1 | /* crypto/asn1/p7_i_s.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "asn1_mac.h" | ||
62 | #include "x509.h" | ||
63 | |||
64 | /* | ||
65 | * ASN1err(ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW,ASN1_R_LENGTH_MISMATCH); | ||
66 | * ASN1err(ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL,ASN1_R_LENGTH_MISMATCH); | ||
67 | */ | ||
68 | |||
69 | int i2d_PKCS7_ISSUER_AND_SERIAL(a,pp) | ||
70 | PKCS7_ISSUER_AND_SERIAL *a; | ||
71 | unsigned char **pp; | ||
72 | { | ||
73 | M_ASN1_I2D_vars(a); | ||
74 | |||
75 | M_ASN1_I2D_len(a->issuer,i2d_X509_NAME); | ||
76 | M_ASN1_I2D_len(a->serial,i2d_ASN1_INTEGER); | ||
77 | |||
78 | M_ASN1_I2D_seq_total(); | ||
79 | |||
80 | M_ASN1_I2D_put(a->issuer,i2d_X509_NAME); | ||
81 | M_ASN1_I2D_put(a->serial,i2d_ASN1_INTEGER); | ||
82 | |||
83 | M_ASN1_I2D_finish(); | ||
84 | } | ||
85 | |||
86 | PKCS7_ISSUER_AND_SERIAL *d2i_PKCS7_ISSUER_AND_SERIAL(a,pp,length) | ||
87 | PKCS7_ISSUER_AND_SERIAL **a; | ||
88 | unsigned char **pp; | ||
89 | long length; | ||
90 | { | ||
91 | M_ASN1_D2I_vars(a,PKCS7_ISSUER_AND_SERIAL *,PKCS7_ISSUER_AND_SERIAL_new); | ||
92 | |||
93 | M_ASN1_D2I_Init(); | ||
94 | M_ASN1_D2I_start_sequence(); | ||
95 | M_ASN1_D2I_get(ret->issuer,d2i_X509_NAME); | ||
96 | M_ASN1_D2I_get(ret->serial,d2i_ASN1_INTEGER); | ||
97 | M_ASN1_D2I_Finish(a,PKCS7_ISSUER_AND_SERIAL_free, | ||
98 | ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL); | ||
99 | } | ||
100 | |||
101 | PKCS7_ISSUER_AND_SERIAL *PKCS7_ISSUER_AND_SERIAL_new() | ||
102 | { | ||
103 | PKCS7_ISSUER_AND_SERIAL *ret=NULL; | ||
104 | |||
105 | M_ASN1_New_Malloc(ret,PKCS7_ISSUER_AND_SERIAL); | ||
106 | M_ASN1_New(ret->issuer,X509_NAME_new); | ||
107 | M_ASN1_New(ret->serial,ASN1_INTEGER_new); | ||
108 | return(ret); | ||
109 | M_ASN1_New_Error(ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW); | ||
110 | } | ||
111 | |||
112 | void PKCS7_ISSUER_AND_SERIAL_free(a) | ||
113 | PKCS7_ISSUER_AND_SERIAL *a; | ||
114 | { | ||
115 | if (a == NULL) return; | ||
116 | X509_NAME_free(a->issuer); | ||
117 | ASN1_INTEGER_free(a->serial); | ||
118 | Free((char *)a); | ||
119 | } | ||
120 | |||
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 @@ | |||
1 | /* crypto/asn1/p7_lib.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "asn1_mac.h" | ||
62 | #include "objects.h" | ||
63 | |||
64 | /* ASN1err(ASN1_F_D2I_PKCS7,ASN1_R_BAD_PKCS7_CONTENT); | ||
65 | * ASN1err(ASN1_F_I2D_PKCS7,ASN1_R_BAD_PKCS7_TYPE); | ||
66 | * ASN1err(ASN1_F_PKCS7_NEW,ASN1_R_BAD_PKCS7_TYPE); | ||
67 | */ | ||
68 | |||
69 | int i2d_PKCS7(a,pp) | ||
70 | PKCS7 *a; | ||
71 | unsigned char **pp; | ||
72 | { | ||
73 | M_ASN1_I2D_vars(a); | ||
74 | |||
75 | if (a->asn1 != NULL) | ||
76 | { | ||
77 | if (pp == NULL) | ||
78 | return((int)a->length); | ||
79 | memcpy(*pp,a->asn1,(int)a->length); | ||
80 | *pp+=a->length; | ||
81 | return((int)a->length); | ||
82 | } | ||
83 | |||
84 | ret+=4; /* sequence, BER header plus '0 0' end padding */ | ||
85 | M_ASN1_I2D_len(a->type,i2d_ASN1_OBJECT); | ||
86 | if (a->d.ptr != NULL) | ||
87 | { | ||
88 | ret+=4; /* explicit tag [ 0 ] BER plus '0 0' */ | ||
89 | switch (OBJ_obj2nid(a->type)) | ||
90 | { | ||
91 | case NID_pkcs7_data: | ||
92 | M_ASN1_I2D_len(a->d.data,i2d_ASN1_OCTET_STRING); | ||
93 | break; | ||
94 | case NID_pkcs7_signed: | ||
95 | M_ASN1_I2D_len(a->d.sign,i2d_PKCS7_SIGNED); | ||
96 | break; | ||
97 | case NID_pkcs7_enveloped: | ||
98 | M_ASN1_I2D_len(a->d.enveloped,i2d_PKCS7_ENVELOPE); | ||
99 | break; | ||
100 | case NID_pkcs7_signedAndEnveloped: | ||
101 | M_ASN1_I2D_len(a->d.signed_and_enveloped, | ||
102 | i2d_PKCS7_SIGN_ENVELOPE); | ||
103 | break; | ||
104 | case NID_pkcs7_digest: | ||
105 | M_ASN1_I2D_len(a->d.digest,i2d_PKCS7_DIGEST); | ||
106 | break; | ||
107 | case NID_pkcs7_encrypted: | ||
108 | M_ASN1_I2D_len(a->d.encrypted,i2d_PKCS7_ENCRYPT); | ||
109 | break; | ||
110 | default: | ||
111 | break; | ||
112 | } | ||
113 | } | ||
114 | r=ret; | ||
115 | if (pp == NULL) return(r); | ||
116 | p= *pp; | ||
117 | M_ASN1_I2D_INF_seq_start(V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); | ||
118 | M_ASN1_I2D_put(a->type,i2d_ASN1_OBJECT); | ||
119 | |||
120 | if (a->d.ptr != NULL) | ||
121 | { | ||
122 | M_ASN1_I2D_INF_seq_start(0,V_ASN1_CONTEXT_SPECIFIC); | ||
123 | switch (OBJ_obj2nid(a->type)) | ||
124 | { | ||
125 | case NID_pkcs7_data: | ||
126 | M_ASN1_I2D_put(a->d.data,i2d_ASN1_OCTET_STRING); | ||
127 | break; | ||
128 | case NID_pkcs7_signed: | ||
129 | M_ASN1_I2D_put(a->d.sign,i2d_PKCS7_SIGNED); | ||
130 | break; | ||
131 | case NID_pkcs7_enveloped: | ||
132 | M_ASN1_I2D_put(a->d.enveloped,i2d_PKCS7_ENVELOPE); | ||
133 | break; | ||
134 | case NID_pkcs7_signedAndEnveloped: | ||
135 | M_ASN1_I2D_put(a->d.signed_and_enveloped, | ||
136 | i2d_PKCS7_SIGN_ENVELOPE); | ||
137 | break; | ||
138 | case NID_pkcs7_digest: | ||
139 | M_ASN1_I2D_put(a->d.digest,i2d_PKCS7_DIGEST); | ||
140 | break; | ||
141 | case NID_pkcs7_encrypted: | ||
142 | M_ASN1_I2D_put(a->d.encrypted,i2d_PKCS7_ENCRYPT); | ||
143 | break; | ||
144 | default: | ||
145 | break; | ||
146 | } | ||
147 | M_ASN1_I2D_INF_seq_end(); | ||
148 | } | ||
149 | M_ASN1_I2D_INF_seq_end(); | ||
150 | M_ASN1_I2D_finish(); | ||
151 | } | ||
152 | |||
153 | PKCS7 *d2i_PKCS7(a,pp,length) | ||
154 | PKCS7 **a; | ||
155 | unsigned char **pp; | ||
156 | long length; | ||
157 | { | ||
158 | M_ASN1_D2I_vars(a,PKCS7 *,PKCS7_new); | ||
159 | |||
160 | if ((a != NULL) && ((*a) != NULL)) | ||
161 | { | ||
162 | if ((*a)->asn1 != NULL) | ||
163 | { | ||
164 | Free((char *)(*a)->asn1); | ||
165 | (*a)->asn1=NULL; | ||
166 | } | ||
167 | (*a)->length=0; | ||
168 | } | ||
169 | |||
170 | M_ASN1_D2I_Init(); | ||
171 | M_ASN1_D2I_start_sequence(); | ||
172 | M_ASN1_D2I_get(ret->type,d2i_ASN1_OBJECT); | ||
173 | if (!M_ASN1_D2I_end_sequence()) | ||
174 | { | ||
175 | int Tinf,Ttag,Tclass; | ||
176 | long Tlen; | ||
177 | |||
178 | if (M_ASN1_next != (V_ASN1_CONSTRUCTED| | ||
179 | V_ASN1_CONTEXT_SPECIFIC|0)) | ||
180 | { | ||
181 | c.error=ASN1_R_BAD_PKCS7_CONTENT; | ||
182 | goto err; | ||
183 | } | ||
184 | |||
185 | ret->detached=0; | ||
186 | |||
187 | c.q=c.p; | ||
188 | Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass, | ||
189 | (c.inf & 1)?(length+ *pp-c.q):c.slen); | ||
190 | if (Tinf & 0x80) goto err; | ||
191 | c.slen-=(c.p-c.q); | ||
192 | |||
193 | switch (OBJ_obj2nid(ret->type)) | ||
194 | { | ||
195 | case NID_pkcs7_data: | ||
196 | M_ASN1_D2I_get(ret->d.data,d2i_ASN1_OCTET_STRING); | ||
197 | break; | ||
198 | case NID_pkcs7_signed: | ||
199 | M_ASN1_D2I_get(ret->d.sign,d2i_PKCS7_SIGNED); | ||
200 | if (ret->d.sign->contents->d.ptr == NULL) | ||
201 | ret->detached=1; | ||
202 | break; | ||
203 | case NID_pkcs7_enveloped: | ||
204 | M_ASN1_D2I_get(ret->d.enveloped,d2i_PKCS7_ENVELOPE); | ||
205 | break; | ||
206 | case NID_pkcs7_signedAndEnveloped: | ||
207 | M_ASN1_D2I_get(ret->d.signed_and_enveloped, | ||
208 | d2i_PKCS7_SIGN_ENVELOPE); | ||
209 | break; | ||
210 | case NID_pkcs7_digest: | ||
211 | M_ASN1_D2I_get(ret->d.digest,d2i_PKCS7_DIGEST); | ||
212 | break; | ||
213 | case NID_pkcs7_encrypted: | ||
214 | M_ASN1_D2I_get(ret->d.encrypted,d2i_PKCS7_ENCRYPT); | ||
215 | break; | ||
216 | default: | ||
217 | c.error=ASN1_R_BAD_PKCS7_TYPE; | ||
218 | goto err; | ||
219 | break; | ||
220 | } | ||
221 | if (Tinf == (1|V_ASN1_CONSTRUCTED)) | ||
222 | { | ||
223 | if (!ASN1_check_infinite_end(&c.p,c.slen)) | ||
224 | { | ||
225 | c.error=ASN1_R_MISSING_EOS; | ||
226 | goto err; | ||
227 | } | ||
228 | } | ||
229 | } | ||
230 | else | ||
231 | ret->detached=1; | ||
232 | |||
233 | M_ASN1_D2I_Finish(a,PKCS7_free,ASN1_F_D2I_PKCS7); | ||
234 | } | ||
235 | |||
236 | PKCS7 *PKCS7_new() | ||
237 | { | ||
238 | PKCS7 *ret=NULL; | ||
239 | |||
240 | M_ASN1_New_Malloc(ret,PKCS7); | ||
241 | ret->type=ASN1_OBJECT_new(); | ||
242 | ret->asn1=NULL; | ||
243 | ret->length=0; | ||
244 | ret->detached=0; | ||
245 | ret->d.ptr=NULL; | ||
246 | return(ret); | ||
247 | M_ASN1_New_Error(ASN1_F_PKCS7_NEW); | ||
248 | } | ||
249 | |||
250 | void PKCS7_free(a) | ||
251 | PKCS7 *a; | ||
252 | { | ||
253 | if (a == NULL) return; | ||
254 | |||
255 | PKCS7_content_free(a); | ||
256 | if (a->type != NULL) | ||
257 | { | ||
258 | ASN1_OBJECT_free(a->type); | ||
259 | } | ||
260 | Free((char *)(char *)a); | ||
261 | } | ||
262 | |||
263 | void PKCS7_content_free(a) | ||
264 | PKCS7 *a; | ||
265 | { | ||
266 | if (a->asn1 != NULL) Free((char *)a->asn1); | ||
267 | |||
268 | if (a->d.ptr != NULL) | ||
269 | { | ||
270 | if (a->type == NULL) return; | ||
271 | |||
272 | switch (OBJ_obj2nid(a->type)) | ||
273 | { | ||
274 | case NID_pkcs7_data: | ||
275 | ASN1_OCTET_STRING_free(a->d.data); | ||
276 | break; | ||
277 | case NID_pkcs7_signed: | ||
278 | PKCS7_SIGNED_free(a->d.sign); | ||
279 | break; | ||
280 | case NID_pkcs7_enveloped: | ||
281 | PKCS7_ENVELOPE_free(a->d.enveloped); | ||
282 | break; | ||
283 | case NID_pkcs7_signedAndEnveloped: | ||
284 | PKCS7_SIGN_ENVELOPE_free(a->d.signed_and_enveloped); | ||
285 | break; | ||
286 | case NID_pkcs7_digest: | ||
287 | PKCS7_DIGEST_free(a->d.digest); | ||
288 | break; | ||
289 | case NID_pkcs7_encrypted: | ||
290 | PKCS7_ENCRYPT_free(a->d.encrypted); | ||
291 | break; | ||
292 | default: | ||
293 | /* MEMORY LEAK */ | ||
294 | break; | ||
295 | } | ||
296 | } | ||
297 | a->d.ptr=NULL; | ||
298 | } | ||
299 | |||
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 @@ | |||
1 | /* crypto/asn1/p7_recip.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "asn1_mac.h" | ||
62 | #include "x509.h" | ||
63 | |||
64 | /* | ||
65 | * ASN1err(ASN1_F_PKCS7_RECIP_INFO_NEW,ASN1_R_LENGTH_MISMATCH); | ||
66 | * ASN1err(ASN1_F_D2I_PKCS7_RECIP_INFO,ASN1_R_LENGTH_MISMATCH); | ||
67 | */ | ||
68 | |||
69 | int i2d_PKCS7_RECIP_INFO(a,pp) | ||
70 | PKCS7_RECIP_INFO *a; | ||
71 | unsigned char **pp; | ||
72 | { | ||
73 | M_ASN1_I2D_vars(a); | ||
74 | |||
75 | M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); | ||
76 | M_ASN1_I2D_len(a->issuer_and_serial,i2d_PKCS7_ISSUER_AND_SERIAL); | ||
77 | M_ASN1_I2D_len(a->key_enc_algor,i2d_X509_ALGOR); | ||
78 | M_ASN1_I2D_len(a->enc_key,i2d_ASN1_OCTET_STRING); | ||
79 | |||
80 | M_ASN1_I2D_seq_total(); | ||
81 | |||
82 | M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER); | ||
83 | M_ASN1_I2D_put(a->issuer_and_serial,i2d_PKCS7_ISSUER_AND_SERIAL); | ||
84 | M_ASN1_I2D_put(a->key_enc_algor,i2d_X509_ALGOR); | ||
85 | M_ASN1_I2D_put(a->enc_key,i2d_ASN1_OCTET_STRING); | ||
86 | |||
87 | M_ASN1_I2D_finish(); | ||
88 | } | ||
89 | |||
90 | PKCS7_RECIP_INFO *d2i_PKCS7_RECIP_INFO(a,pp,length) | ||
91 | PKCS7_RECIP_INFO **a; | ||
92 | unsigned char **pp; | ||
93 | long length; | ||
94 | { | ||
95 | M_ASN1_D2I_vars(a,PKCS7_RECIP_INFO *,PKCS7_RECIP_INFO_new); | ||
96 | |||
97 | M_ASN1_D2I_Init(); | ||
98 | M_ASN1_D2I_start_sequence(); | ||
99 | M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); | ||
100 | M_ASN1_D2I_get(ret->issuer_and_serial,d2i_PKCS7_ISSUER_AND_SERIAL); | ||
101 | M_ASN1_D2I_get(ret->key_enc_algor,d2i_X509_ALGOR); | ||
102 | M_ASN1_D2I_get(ret->enc_key,d2i_ASN1_OCTET_STRING); | ||
103 | |||
104 | M_ASN1_D2I_Finish(a,PKCS7_RECIP_INFO_free,ASN1_F_D2I_PKCS7_RECIP_INFO); | ||
105 | } | ||
106 | |||
107 | PKCS7_RECIP_INFO *PKCS7_RECIP_INFO_new() | ||
108 | { | ||
109 | PKCS7_RECIP_INFO *ret=NULL; | ||
110 | |||
111 | M_ASN1_New_Malloc(ret,PKCS7_RECIP_INFO); | ||
112 | M_ASN1_New(ret->version,ASN1_INTEGER_new); | ||
113 | M_ASN1_New(ret->issuer_and_serial,PKCS7_ISSUER_AND_SERIAL_new); | ||
114 | M_ASN1_New(ret->key_enc_algor,X509_ALGOR_new); | ||
115 | M_ASN1_New(ret->enc_key,ASN1_OCTET_STRING_new); | ||
116 | ret->cert=NULL; | ||
117 | return(ret); | ||
118 | M_ASN1_New_Error(ASN1_F_PKCS7_RECIP_INFO_NEW); | ||
119 | } | ||
120 | |||
121 | void PKCS7_RECIP_INFO_free(a) | ||
122 | PKCS7_RECIP_INFO *a; | ||
123 | { | ||
124 | if (a == NULL) return; | ||
125 | ASN1_INTEGER_free(a->version); | ||
126 | PKCS7_ISSUER_AND_SERIAL_free(a->issuer_and_serial); | ||
127 | X509_ALGOR_free(a->key_enc_algor); | ||
128 | ASN1_OCTET_STRING_free(a->enc_key); | ||
129 | if (a->cert != NULL) X509_free(a->cert); | ||
130 | Free((char *)a); | ||
131 | } | ||
132 | |||
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 @@ | |||
1 | /* crypto/asn1/p7_s_e.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "asn1_mac.h" | ||
62 | #include "x509.h" | ||
63 | |||
64 | /* | ||
65 | * ASN1err(ASN1_F_PKCS7_SIGN_ENVELOPE_NEW,ASN1_R_LENGTH_MISMATCH); | ||
66 | * ASN1err(ASN1_F_D2I_PKCS7_SIGN_ENVELOPE,ASN1_R_LENGTH_MISMATCH); | ||
67 | */ | ||
68 | |||
69 | int i2d_PKCS7_SIGN_ENVELOPE(a,pp) | ||
70 | PKCS7_SIGN_ENVELOPE *a; | ||
71 | unsigned char **pp; | ||
72 | { | ||
73 | M_ASN1_I2D_vars(a); | ||
74 | |||
75 | M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); | ||
76 | M_ASN1_I2D_len_SET(a->recipientinfo,i2d_PKCS7_RECIP_INFO); | ||
77 | M_ASN1_I2D_len_SET(a->md_algs,i2d_X509_ALGOR); | ||
78 | M_ASN1_I2D_len(a->enc_data,i2d_PKCS7_ENC_CONTENT); | ||
79 | M_ASN1_I2D_len_IMP_set_opt(a->cert,i2d_X509,0); | ||
80 | M_ASN1_I2D_len_IMP_set_opt(a->crl,i2d_X509_CRL,1); | ||
81 | M_ASN1_I2D_len_SET(a->signer_info,i2d_PKCS7_SIGNER_INFO); | ||
82 | |||
83 | M_ASN1_I2D_seq_total(); | ||
84 | |||
85 | M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER); | ||
86 | M_ASN1_I2D_put_SET(a->recipientinfo,i2d_PKCS7_RECIP_INFO); | ||
87 | M_ASN1_I2D_put_SET(a->md_algs,i2d_X509_ALGOR); | ||
88 | M_ASN1_I2D_put(a->enc_data,i2d_PKCS7_ENC_CONTENT); | ||
89 | M_ASN1_I2D_put_IMP_set_opt(a->cert,i2d_X509,0); | ||
90 | M_ASN1_I2D_put_IMP_set_opt(a->crl,i2d_X509_CRL,1); | ||
91 | M_ASN1_I2D_put_SET(a->signer_info,i2d_PKCS7_SIGNER_INFO); | ||
92 | |||
93 | M_ASN1_I2D_finish(); | ||
94 | } | ||
95 | |||
96 | PKCS7_SIGN_ENVELOPE *d2i_PKCS7_SIGN_ENVELOPE(a,pp,length) | ||
97 | PKCS7_SIGN_ENVELOPE **a; | ||
98 | unsigned char **pp; | ||
99 | long length; | ||
100 | { | ||
101 | M_ASN1_D2I_vars(a,PKCS7_SIGN_ENVELOPE *,PKCS7_SIGN_ENVELOPE_new); | ||
102 | |||
103 | M_ASN1_D2I_Init(); | ||
104 | M_ASN1_D2I_start_sequence(); | ||
105 | M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); | ||
106 | M_ASN1_D2I_get_set(ret->recipientinfo,d2i_PKCS7_RECIP_INFO); | ||
107 | M_ASN1_D2I_get_set(ret->md_algs,d2i_X509_ALGOR); | ||
108 | M_ASN1_D2I_get(ret->enc_data,d2i_PKCS7_ENC_CONTENT); | ||
109 | M_ASN1_D2I_get_IMP_set_opt(ret->cert,d2i_X509,0); | ||
110 | M_ASN1_D2I_get_IMP_set_opt(ret->crl,d2i_X509_CRL,1); | ||
111 | M_ASN1_D2I_get_set(ret->signer_info,d2i_PKCS7_SIGNER_INFO); | ||
112 | |||
113 | M_ASN1_D2I_Finish(a,PKCS7_SIGN_ENVELOPE_free, | ||
114 | ASN1_F_D2I_PKCS7_SIGN_ENVELOPE); | ||
115 | } | ||
116 | |||
117 | PKCS7_SIGN_ENVELOPE *PKCS7_SIGN_ENVELOPE_new() | ||
118 | { | ||
119 | PKCS7_SIGN_ENVELOPE *ret=NULL; | ||
120 | |||
121 | M_ASN1_New_Malloc(ret,PKCS7_SIGN_ENVELOPE); | ||
122 | M_ASN1_New(ret->version,ASN1_INTEGER_new); | ||
123 | M_ASN1_New(ret->recipientinfo,sk_new_null); | ||
124 | M_ASN1_New(ret->md_algs,sk_new_null); | ||
125 | M_ASN1_New(ret->enc_data,PKCS7_ENC_CONTENT_new); | ||
126 | ret->cert=NULL; | ||
127 | ret->crl=NULL; | ||
128 | M_ASN1_New(ret->signer_info,sk_new_null); | ||
129 | return(ret); | ||
130 | M_ASN1_New_Error(ASN1_F_PKCS7_SIGN_ENVELOPE_NEW); | ||
131 | } | ||
132 | |||
133 | void PKCS7_SIGN_ENVELOPE_free(a) | ||
134 | PKCS7_SIGN_ENVELOPE *a; | ||
135 | { | ||
136 | if (a == NULL) return; | ||
137 | ASN1_INTEGER_free(a->version); | ||
138 | sk_pop_free(a->recipientinfo,PKCS7_RECIP_INFO_free); | ||
139 | sk_pop_free(a->md_algs,X509_ALGOR_free); | ||
140 | PKCS7_ENC_CONTENT_free(a->enc_data); | ||
141 | sk_pop_free(a->cert,X509_free); | ||
142 | sk_pop_free(a->crl,X509_CRL_free); | ||
143 | sk_pop_free(a->signer_info,PKCS7_SIGNER_INFO_free); | ||
144 | Free((char *)a); | ||
145 | } | ||
146 | |||
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 @@ | |||
1 | /* crypto/asn1/p7_signd.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "asn1_mac.h" | ||
62 | #include "x509.h" | ||
63 | |||
64 | /* | ||
65 | * ASN1err(ASN1_F_PKCS7_SIGNED_NEW,ASN1_R_LENGTH_MISMATCH); | ||
66 | * ASN1err(ASN1_F_D2I_PKCS7_SIGNED,ASN1_R_LENGTH_MISMATCH); | ||
67 | */ | ||
68 | |||
69 | int i2d_PKCS7_SIGNED(a,pp) | ||
70 | PKCS7_SIGNED *a; | ||
71 | unsigned char **pp; | ||
72 | { | ||
73 | M_ASN1_I2D_vars(a); | ||
74 | |||
75 | M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); | ||
76 | M_ASN1_I2D_len_SET(a->md_algs,i2d_X509_ALGOR); | ||
77 | M_ASN1_I2D_len(a->contents,i2d_PKCS7); | ||
78 | M_ASN1_I2D_len_IMP_set_opt(a->cert,i2d_X509,0); | ||
79 | M_ASN1_I2D_len_IMP_set_opt(a->crl,i2d_X509_CRL,1); | ||
80 | M_ASN1_I2D_len_SET(a->signer_info,i2d_PKCS7_SIGNER_INFO); | ||
81 | |||
82 | M_ASN1_I2D_seq_total(); | ||
83 | |||
84 | M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER); | ||
85 | M_ASN1_I2D_put_SET(a->md_algs,i2d_X509_ALGOR); | ||
86 | M_ASN1_I2D_put(a->contents,i2d_PKCS7); | ||
87 | M_ASN1_I2D_put_IMP_set_opt(a->cert,i2d_X509,0); | ||
88 | M_ASN1_I2D_put_IMP_set_opt(a->crl,i2d_X509_CRL,1); | ||
89 | M_ASN1_I2D_put_SET(a->signer_info,i2d_PKCS7_SIGNER_INFO); | ||
90 | |||
91 | M_ASN1_I2D_finish(); | ||
92 | } | ||
93 | |||
94 | PKCS7_SIGNED *d2i_PKCS7_SIGNED(a,pp,length) | ||
95 | PKCS7_SIGNED **a; | ||
96 | unsigned char **pp; | ||
97 | long length; | ||
98 | { | ||
99 | M_ASN1_D2I_vars(a,PKCS7_SIGNED *,PKCS7_SIGNED_new); | ||
100 | |||
101 | M_ASN1_D2I_Init(); | ||
102 | M_ASN1_D2I_start_sequence(); | ||
103 | M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); | ||
104 | M_ASN1_D2I_get_set(ret->md_algs,d2i_X509_ALGOR); | ||
105 | M_ASN1_D2I_get(ret->contents,d2i_PKCS7); | ||
106 | M_ASN1_D2I_get_IMP_set_opt(ret->cert,d2i_X509,0); | ||
107 | M_ASN1_D2I_get_IMP_set_opt(ret->crl,d2i_X509_CRL,1); | ||
108 | M_ASN1_D2I_get_set(ret->signer_info,d2i_PKCS7_SIGNER_INFO); | ||
109 | |||
110 | M_ASN1_D2I_Finish(a,PKCS7_SIGNED_free,ASN1_F_D2I_PKCS7_SIGNED); | ||
111 | } | ||
112 | |||
113 | PKCS7_SIGNED *PKCS7_SIGNED_new() | ||
114 | { | ||
115 | PKCS7_SIGNED *ret=NULL; | ||
116 | |||
117 | M_ASN1_New_Malloc(ret,PKCS7_SIGNED); | ||
118 | M_ASN1_New(ret->version,ASN1_INTEGER_new); | ||
119 | M_ASN1_New(ret->md_algs,sk_new_null); | ||
120 | M_ASN1_New(ret->contents,PKCS7_new); | ||
121 | ret->cert=NULL; | ||
122 | ret->crl=NULL; | ||
123 | M_ASN1_New(ret->signer_info,sk_new_null); | ||
124 | return(ret); | ||
125 | M_ASN1_New_Error(ASN1_F_PKCS7_SIGNED_NEW); | ||
126 | } | ||
127 | |||
128 | void PKCS7_SIGNED_free(a) | ||
129 | PKCS7_SIGNED *a; | ||
130 | { | ||
131 | if (a == NULL) return; | ||
132 | ASN1_INTEGER_free(a->version); | ||
133 | sk_pop_free(a->md_algs,X509_ALGOR_free); | ||
134 | PKCS7_free(a->contents); | ||
135 | sk_pop_free(a->cert,X509_free); | ||
136 | sk_pop_free(a->crl,X509_CRL_free); | ||
137 | sk_pop_free(a->signer_info,PKCS7_SIGNER_INFO_free); | ||
138 | Free((char *)a); | ||
139 | } | ||
140 | |||
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 @@ | |||
1 | /* crypto/asn1/p7_signi.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "asn1_mac.h" | ||
62 | #include "x509.h" | ||
63 | |||
64 | /* | ||
65 | * ASN1err(ASN1_F_PKCS7_SIGNER_INFO_NEW,ASN1_R_LENGTH_MISMATCH); | ||
66 | * ASN1err(ASN1_F_D2I_PKCS7_SIGNER_INFO,ASN1_R_LENGTH_MISMATCH); | ||
67 | */ | ||
68 | |||
69 | int i2d_PKCS7_SIGNER_INFO(a,pp) | ||
70 | PKCS7_SIGNER_INFO *a; | ||
71 | unsigned char **pp; | ||
72 | { | ||
73 | M_ASN1_I2D_vars(a); | ||
74 | |||
75 | M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); | ||
76 | M_ASN1_I2D_len(a->issuer_and_serial,i2d_PKCS7_ISSUER_AND_SERIAL); | ||
77 | M_ASN1_I2D_len(a->digest_alg,i2d_X509_ALGOR); | ||
78 | M_ASN1_I2D_len_IMP_set_opt(a->auth_attr,i2d_X509_ATTRIBUTE,0); | ||
79 | M_ASN1_I2D_len(a->digest_enc_alg,i2d_X509_ALGOR); | ||
80 | M_ASN1_I2D_len(a->enc_digest,i2d_ASN1_OCTET_STRING); | ||
81 | M_ASN1_I2D_len_IMP_set_opt(a->unauth_attr,i2d_X509_ATTRIBUTE,1); | ||
82 | |||
83 | M_ASN1_I2D_seq_total(); | ||
84 | |||
85 | M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER); | ||
86 | M_ASN1_I2D_put(a->issuer_and_serial,i2d_PKCS7_ISSUER_AND_SERIAL); | ||
87 | M_ASN1_I2D_put(a->digest_alg,i2d_X509_ALGOR); | ||
88 | M_ASN1_I2D_put_IMP_set_opt(a->auth_attr,i2d_X509_ATTRIBUTE,0); | ||
89 | M_ASN1_I2D_put(a->digest_enc_alg,i2d_X509_ALGOR); | ||
90 | M_ASN1_I2D_put(a->enc_digest,i2d_ASN1_OCTET_STRING); | ||
91 | M_ASN1_I2D_put_IMP_set_opt(a->unauth_attr,i2d_X509_ATTRIBUTE,1); | ||
92 | |||
93 | M_ASN1_I2D_finish(); | ||
94 | } | ||
95 | |||
96 | PKCS7_SIGNER_INFO *d2i_PKCS7_SIGNER_INFO(a,pp,length) | ||
97 | PKCS7_SIGNER_INFO **a; | ||
98 | unsigned char **pp; | ||
99 | long length; | ||
100 | { | ||
101 | M_ASN1_D2I_vars(a,PKCS7_SIGNER_INFO *,PKCS7_SIGNER_INFO_new); | ||
102 | |||
103 | M_ASN1_D2I_Init(); | ||
104 | M_ASN1_D2I_start_sequence(); | ||
105 | M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); | ||
106 | M_ASN1_D2I_get(ret->issuer_and_serial,d2i_PKCS7_ISSUER_AND_SERIAL); | ||
107 | M_ASN1_D2I_get(ret->digest_alg,d2i_X509_ALGOR); | ||
108 | M_ASN1_D2I_get_IMP_set_opt(ret->auth_attr,d2i_X509_ATTRIBUTE,0); | ||
109 | M_ASN1_D2I_get(ret->digest_enc_alg,d2i_X509_ALGOR); | ||
110 | M_ASN1_D2I_get(ret->enc_digest,d2i_ASN1_OCTET_STRING); | ||
111 | M_ASN1_D2I_get_IMP_set_opt(ret->unauth_attr,d2i_X509_ATTRIBUTE,1); | ||
112 | |||
113 | M_ASN1_D2I_Finish(a,PKCS7_SIGNER_INFO_free, | ||
114 | ASN1_F_D2I_PKCS7_SIGNER_INFO); | ||
115 | } | ||
116 | |||
117 | PKCS7_SIGNER_INFO *PKCS7_SIGNER_INFO_new() | ||
118 | { | ||
119 | PKCS7_SIGNER_INFO *ret=NULL; | ||
120 | |||
121 | M_ASN1_New_Malloc(ret,PKCS7_SIGNER_INFO); | ||
122 | M_ASN1_New(ret->version,ASN1_INTEGER_new); | ||
123 | M_ASN1_New(ret->issuer_and_serial,PKCS7_ISSUER_AND_SERIAL_new); | ||
124 | M_ASN1_New(ret->digest_alg,X509_ALGOR_new); | ||
125 | ret->auth_attr=NULL; | ||
126 | M_ASN1_New(ret->digest_enc_alg,X509_ALGOR_new); | ||
127 | M_ASN1_New(ret->enc_digest,ASN1_OCTET_STRING_new); | ||
128 | ret->unauth_attr=NULL; | ||
129 | ret->pkey=NULL; | ||
130 | return(ret); | ||
131 | M_ASN1_New_Error(ASN1_F_PKCS7_SIGNER_INFO_NEW); | ||
132 | } | ||
133 | |||
134 | void PKCS7_SIGNER_INFO_free(a) | ||
135 | PKCS7_SIGNER_INFO *a; | ||
136 | { | ||
137 | if (a == NULL) return; | ||
138 | ASN1_INTEGER_free(a->version); | ||
139 | PKCS7_ISSUER_AND_SERIAL_free(a->issuer_and_serial); | ||
140 | X509_ALGOR_free(a->digest_alg); | ||
141 | sk_pop_free(a->auth_attr,X509_ATTRIBUTE_free); | ||
142 | X509_ALGOR_free(a->digest_enc_alg); | ||
143 | ASN1_OCTET_STRING_free(a->enc_digest); | ||
144 | sk_pop_free(a->unauth_attr,X509_ATTRIBUTE_free); | ||
145 | if (a->pkey != NULL) | ||
146 | EVP_PKEY_free(a->pkey); | ||
147 | Free((char *)a); | ||
148 | } | ||
149 | |||
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 @@ | |||
1 | /* crypto/asn1/pkcs8.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include "asn1_mac.h" | ||
62 | #include "objects.h" | ||
63 | |||
64 | /* | ||
65 | * ASN1err(ASN1_F_D2I_X509_KEY,ASN1_R_LENGTH_MISMATCH); | ||
66 | * ASN1err(ASN1_F_X509_KEY_NEW,ASN1_R_BAD_GET_OBJECT); | ||
67 | */ | ||
68 | |||
69 | int i2d_X509_KEY(a,pp) | ||
70 | X509 *a; | ||
71 | unsigned char **pp; | ||
72 | { | ||
73 | M_ASN1_I2D_vars(a); | ||
74 | |||
75 | M_ASN1_I2D_len(a->cert_info, i2d_X509_CINF); | ||
76 | M_ASN1_I2D_len(a->sig_alg, i2d_X509_ALGOR); | ||
77 | M_ASN1_I2D_len(a->signature, i2d_ASN1_BIT_STRING); | ||
78 | |||
79 | M_ASN1_I2D_seq_total(); | ||
80 | |||
81 | M_ASN1_I2D_put(a->cert_info, i2d_X509_CINF); | ||
82 | M_ASN1_I2D_put(a->sig_alg, i2d_X509_ALGOR); | ||
83 | M_ASN1_I2D_put(a->signature, i2d_ASN1_BIT_STRING); | ||
84 | |||
85 | M_ASN1_I2D_finish(); | ||
86 | } | ||
87 | |||
88 | X509 *d2i_X509_KEY(a,pp,length) | ||
89 | X509 **a; | ||
90 | unsigned char **pp; | ||
91 | long length; | ||
92 | { | ||
93 | M_ASN1_D2I_vars(a,X509 *,X509_new); | ||
94 | |||
95 | M_ASN1_D2I_Init(); | ||
96 | M_ASN1_D2I_start_sequence(); | ||
97 | M_ASN1_D2I_get(ret->cert_info,d2i_X509_CINF); | ||
98 | M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR); | ||
99 | M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING); | ||
100 | M_ASN1_D2I_Finish(a,X509_free,ASN1_F_D2I_X509); | ||
101 | } | ||
102 | |||
103 | X509 *X509_KEY_new() | ||
104 | { | ||
105 | X509_KEY *ret=NULL; | ||
106 | |||
107 | M_ASN1_New_Malloc(ret,X509_KEY); | ||
108 | ret->references=1; | ||
109 | ret->type=NID | ||
110 | M_ASN1_New(ret->cert_info,X509_CINF_new); | ||
111 | M_ASN1_New(ret->sig_alg,X509_ALGOR_new); | ||
112 | M_ASN1_New(ret->signature,ASN1_BIT_STRING_new); | ||
113 | return(ret); | ||
114 | M_ASN1_New_Error(ASN1_F_X509_NEW); | ||
115 | } | ||
116 | |||
117 | void X509_KEY_free(a) | ||
118 | X509 *a; | ||
119 | { | ||
120 | int i; | ||
121 | |||
122 | if (a == NULL) return; | ||
123 | |||
124 | i=CRYPTO_add_lock(&a->references,-1,CRYPTO_LOCK_X509_KEY); | ||
125 | #ifdef REF_PRINT | ||
126 | REF_PRINT("X509_KEY",a); | ||
127 | #endif | ||
128 | if (i > 0) return; | ||
129 | #ifdef REF_CHECK | ||
130 | if (i < 0) | ||
131 | { | ||
132 | fprintf(stderr,"X509_KEY_free, bad reference count\n"); | ||
133 | abort(); | ||
134 | } | ||
135 | #endif | ||
136 | |||
137 | X509_CINF_free(a->cert_info); | ||
138 | X509_ALGOR_free(a->sig_alg); | ||
139 | ASN1_BIT_STRING_free(a->signature); | ||
140 | Free((char *)a); | ||
141 | } | ||
142 | |||