diff options
| author | ryker <> | 1998-10-05 20:13:14 +0000 |
|---|---|---|
| committer | ryker <> | 1998-10-05 20:13:14 +0000 |
| commit | fe5d0717e2760d02faf23bf5a714f17b33ae4abb (patch) | |
| tree | 8d4ad346f10a36bdd90b503d222bda6b4ecd0037 | |
| parent | 75bf5ead4149b2b67781def7ace1ec720ae1753e (diff) | |
| parent | aeeae06a79815dc190061534d47236cec09f9e32 (diff) | |
| download | openbsd-fe5d0717e2760d02faf23bf5a714f17b33ae4abb.tar.gz openbsd-fe5d0717e2760d02faf23bf5a714f17b33ae4abb.tar.bz2 openbsd-fe5d0717e2760d02faf23bf5a714f17b33ae4abb.zip | |
This commit was generated by cvs2git to track changes on a CVS vendor
branch.
Diffstat (limited to '')
350 files changed, 81718 insertions, 0 deletions
diff --git a/src/lib/libcrypto/asn1/a_bitstr.c b/src/lib/libcrypto/asn1/a_bitstr.c new file mode 100644 index 0000000000..2c10120651 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_bitstr.c | |||
| @@ -0,0 +1,204 @@ | |||
| 1 | /* crypto/asn1/a_bitstr.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_ASN1_STRING_NEW,ASN1_R_STRING_TOO_SHORT); | ||
| 64 | * ASN1err(ASN1_F_D2I_ASN1_BIT_STRING,ASN1_R_EXPECTING_A_BIT_STRING); | ||
| 65 | */ | ||
| 66 | |||
| 67 | int i2d_ASN1_BIT_STRING(a,pp) | ||
| 68 | ASN1_BIT_STRING *a; | ||
| 69 | unsigned char **pp; | ||
| 70 | { | ||
| 71 | int ret,j,r,bits; | ||
| 72 | unsigned char *p,*d; | ||
| 73 | |||
| 74 | if (a == NULL) return(0); | ||
| 75 | |||
| 76 | /* our bit strings are always a multiple of 8 :-) */ | ||
| 77 | bits=0; | ||
| 78 | ret=1+a->length; | ||
| 79 | r=ASN1_object_size(0,ret,V_ASN1_BIT_STRING); | ||
| 80 | if (pp == NULL) return(r); | ||
| 81 | p= *pp; | ||
| 82 | |||
| 83 | ASN1_put_object(&p,0,ret,V_ASN1_BIT_STRING,V_ASN1_UNIVERSAL); | ||
| 84 | if (bits == 0) | ||
| 85 | j=0; | ||
| 86 | else j=8-bits; | ||
| 87 | *(p++)=(unsigned char)j; | ||
| 88 | d=a->data; | ||
| 89 | memcpy(p,d,a->length); | ||
| 90 | p+=a->length; | ||
| 91 | if (a->length > 0) p[-1]&=(0xff<<j); | ||
| 92 | *pp=p; | ||
| 93 | return(r); | ||
| 94 | } | ||
| 95 | |||
| 96 | ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(a, pp, length) | ||
| 97 | ASN1_BIT_STRING **a; | ||
| 98 | unsigned char **pp; | ||
| 99 | long length; | ||
| 100 | { | ||
| 101 | ASN1_BIT_STRING *ret=NULL; | ||
| 102 | unsigned char *p,*s; | ||
| 103 | long len; | ||
| 104 | int inf,tag,xclass; | ||
| 105 | int i; | ||
| 106 | |||
| 107 | if ((a == NULL) || ((*a) == NULL)) | ||
| 108 | { | ||
| 109 | if ((ret=ASN1_BIT_STRING_new()) == NULL) return(NULL); | ||
| 110 | } | ||
| 111 | else | ||
| 112 | ret=(*a); | ||
| 113 | |||
| 114 | p= *pp; | ||
| 115 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | ||
| 116 | if (inf & 0x80) | ||
| 117 | { | ||
| 118 | i=ASN1_R_BAD_OBJECT_HEADER; | ||
| 119 | goto err; | ||
| 120 | } | ||
| 121 | |||
| 122 | if (tag != V_ASN1_BIT_STRING) | ||
| 123 | { | ||
| 124 | i=ASN1_R_EXPECTING_A_BIT_STRING; | ||
| 125 | goto err; | ||
| 126 | } | ||
| 127 | if (len < 1) { i=ASN1_R_STRING_TOO_SHORT; goto err; } | ||
| 128 | |||
| 129 | i= *(p++); | ||
| 130 | if (len-- > 1) /* using one because of the bits left byte */ | ||
| 131 | { | ||
| 132 | s=(unsigned char *)Malloc((int)len); | ||
| 133 | if (s == NULL) | ||
| 134 | { | ||
| 135 | i=ERR_R_MALLOC_FAILURE; | ||
| 136 | goto err; | ||
| 137 | } | ||
| 138 | memcpy(s,p,(int)len); | ||
| 139 | s[len-1]&=(0xff<<i); | ||
| 140 | p+=len; | ||
| 141 | } | ||
| 142 | else | ||
| 143 | s=NULL; | ||
| 144 | |||
| 145 | ret->length=(int)len; | ||
| 146 | if (ret->data != NULL) Free((char *)ret->data); | ||
| 147 | ret->data=s; | ||
| 148 | ret->type=V_ASN1_BIT_STRING; | ||
| 149 | if (a != NULL) (*a)=ret; | ||
| 150 | *pp=p; | ||
| 151 | return(ret); | ||
| 152 | err: | ||
| 153 | ASN1err(ASN1_F_D2I_ASN1_BIT_STRING,i); | ||
| 154 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | ||
| 155 | ASN1_BIT_STRING_free(ret); | ||
| 156 | return(NULL); | ||
| 157 | } | ||
| 158 | |||
| 159 | /* These next 2 functions from Goetz Babin-Ebell <babinebell@trustcenter.de> | ||
| 160 | */ | ||
| 161 | int ASN1_BIT_STRING_set_bit(a,n,value) | ||
| 162 | ASN1_BIT_STRING *a; | ||
| 163 | int n; | ||
| 164 | int value; | ||
| 165 | { | ||
| 166 | int w,v,iv; | ||
| 167 | unsigned char *c; | ||
| 168 | |||
| 169 | w=n/8; | ||
| 170 | v=1<<(7-(n&0x07)); | ||
| 171 | iv= ~v; | ||
| 172 | |||
| 173 | if (a == NULL) return(0); | ||
| 174 | if ((a->length < (w+1)) || (a->data == NULL)) | ||
| 175 | { | ||
| 176 | if (!value) return(1); /* Don't need to set */ | ||
| 177 | if (a->data == NULL) | ||
| 178 | c=(unsigned char *)Malloc(w+1); | ||
| 179 | else | ||
| 180 | c=(unsigned char *)Realloc(a->data,w+1); | ||
| 181 | if (c == NULL) return(0); | ||
| 182 | a->data=c; | ||
| 183 | a->length=w+1; | ||
| 184 | c[w]=0; | ||
| 185 | } | ||
| 186 | a->data[w]=((a->data[w])&iv)|v; | ||
| 187 | while ((a->length > 0) && (a->data[a->length-1] == 0)) | ||
| 188 | a->length--; | ||
| 189 | return(1); | ||
| 190 | } | ||
| 191 | |||
| 192 | int ASN1_BIT_STRING_get_bit(a,n) | ||
| 193 | ASN1_BIT_STRING *a; | ||
| 194 | int n; | ||
| 195 | { | ||
| 196 | int w,v; | ||
| 197 | |||
| 198 | w=n/8; | ||
| 199 | v=1<<(7-(n&0x07)); | ||
| 200 | if ((a == NULL) || (a->length < (w+1)) || (a->data == NULL)) | ||
| 201 | return(0); | ||
| 202 | return((a->data[w]&v) != 0); | ||
| 203 | } | ||
| 204 | |||
diff --git a/src/lib/libcrypto/asn1/a_bool.c b/src/lib/libcrypto/asn1/a_bool.c new file mode 100644 index 0000000000..41a95aa278 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_bool.c | |||
| @@ -0,0 +1,121 @@ | |||
| 1 | /* crypto/asn1/a_bool.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_BOOLEAN,ASN1_R_EXPECTING_A_BOOLEAN); | ||
| 64 | * ASN1err(ASN1_F_D2I_ASN1_BOOLEAN,ASN1_R_BOOLEAN_IS_WRONG_LENGTH); | ||
| 65 | */ | ||
| 66 | |||
| 67 | int i2d_ASN1_BOOLEAN(a,pp) | ||
| 68 | int a; | ||
| 69 | unsigned char **pp; | ||
| 70 | { | ||
| 71 | int r; | ||
| 72 | unsigned char *p; | ||
| 73 | |||
| 74 | r=ASN1_object_size(0,1,V_ASN1_BOOLEAN); | ||
| 75 | if (pp == NULL) return(r); | ||
| 76 | p= *pp; | ||
| 77 | |||
| 78 | ASN1_put_object(&p,0,1,V_ASN1_BOOLEAN,V_ASN1_UNIVERSAL); | ||
| 79 | *(p++)= (unsigned char)a; | ||
| 80 | *pp=p; | ||
| 81 | return(r); | ||
| 82 | } | ||
| 83 | |||
| 84 | int d2i_ASN1_BOOLEAN(a, pp, length) | ||
| 85 | int *a; | ||
| 86 | unsigned char **pp; | ||
| 87 | long length; | ||
| 88 | { | ||
| 89 | int ret= -1; | ||
| 90 | unsigned char *p; | ||
| 91 | long len; | ||
| 92 | int inf,tag,xclass; | ||
| 93 | int i=0; | ||
| 94 | |||
| 95 | p= *pp; | ||
| 96 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | ||
| 97 | if (inf & 0x80) | ||
| 98 | { | ||
| 99 | i=ASN1_R_BAD_OBJECT_HEADER; | ||
| 100 | goto err; | ||
| 101 | } | ||
| 102 | |||
| 103 | if (tag != V_ASN1_BOOLEAN) | ||
| 104 | { | ||
| 105 | i=ASN1_R_EXPECTING_A_BOOLEAN; | ||
| 106 | goto err; | ||
| 107 | } | ||
| 108 | |||
| 109 | if (len != 1) | ||
| 110 | { | ||
| 111 | i=ASN1_R_BOOLEAN_IS_WRONG_LENGTH; | ||
| 112 | goto err; | ||
| 113 | } | ||
| 114 | ret= (int)*(p++); | ||
| 115 | if (a != NULL) (*a)=ret; | ||
| 116 | *pp=p; | ||
| 117 | return(ret); | ||
| 118 | err: | ||
| 119 | ASN1err(ASN1_F_D2I_ASN1_BOOLEAN,i); | ||
| 120 | return(ret); | ||
| 121 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_bytes.c b/src/lib/libcrypto/asn1/a_bytes.c new file mode 100644 index 0000000000..14168d61ad --- /dev/null +++ b/src/lib/libcrypto/asn1/a_bytes.c | |||
| @@ -0,0 +1,346 @@ | |||
| 1 | /* crypto/asn1/a_bytes.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 | |||
| 63 | /* ASN1err(ASN1_F_ASN1_TYPE_NEW,ASN1_R_ERROR_STACK); | ||
| 64 | * ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES,ASN1_R_ERROR_STACK); | ||
| 65 | * ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES,ASN1_R_WRONG_TYPE); | ||
| 66 | * ASN1err(ASN1_F_ASN1_COLLATE_PRIMATIVE,ASN1_R_WRONG_TAG); | ||
| 67 | */ | ||
| 68 | |||
| 69 | static unsigned long tag2bit[32]={ | ||
| 70 | 0, 0, 0, B_ASN1_BIT_STRING, /* tags 0 - 3 */ | ||
| 71 | B_ASN1_OCTET_STRING, 0, 0, B_ASN1_UNKNOWN,/* tags 4- 7 */ | ||
| 72 | B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 8-11 */ | ||
| 73 | B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 12-15 */ | ||
| 74 | 0, 0, B_ASN1_NUMERICSTRING,B_ASN1_PRINTABLESTRING, | ||
| 75 | B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING,0, | ||
| 76 | 0,B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING, | ||
| 77 | B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN, | ||
| 78 | }; | ||
| 79 | |||
| 80 | #ifndef NOPROTO | ||
| 81 | static int asn1_collate_primative(ASN1_STRING *a, ASN1_CTX *c); | ||
| 82 | #else | ||
| 83 | static int asn1_collate_primative(); | ||
| 84 | #endif | ||
| 85 | |||
| 86 | /* type is a 'bitmap' of acceptable string types to be accepted. | ||
| 87 | */ | ||
| 88 | ASN1_STRING *d2i_ASN1_type_bytes(a, pp, length, type) | ||
| 89 | ASN1_STRING **a; | ||
| 90 | unsigned char **pp; | ||
| 91 | long length; | ||
| 92 | int type; | ||
| 93 | { | ||
| 94 | ASN1_STRING *ret=NULL; | ||
| 95 | unsigned char *p,*s; | ||
| 96 | long len; | ||
| 97 | int inf,tag,xclass; | ||
| 98 | int i=0; | ||
| 99 | |||
| 100 | p= *pp; | ||
| 101 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | ||
| 102 | if (inf & 0x80) goto err; | ||
| 103 | |||
| 104 | if (tag >= 32) | ||
| 105 | { | ||
| 106 | i=ASN1_R_TAG_VALUE_TOO_HIGH;; | ||
| 107 | goto err; | ||
| 108 | } | ||
| 109 | if (!(tag2bit[tag] & type)) | ||
| 110 | { | ||
| 111 | i=ASN1_R_WRONG_TYPE; | ||
| 112 | goto err; | ||
| 113 | } | ||
| 114 | |||
| 115 | /* If a bit-string, exit early */ | ||
| 116 | if (tag == V_ASN1_BIT_STRING) | ||
| 117 | return(d2i_ASN1_BIT_STRING(a,pp,length)); | ||
| 118 | |||
| 119 | if ((a == NULL) || ((*a) == NULL)) | ||
| 120 | { | ||
| 121 | if ((ret=ASN1_STRING_new()) == NULL) return(NULL); | ||
| 122 | } | ||
| 123 | else | ||
| 124 | ret=(*a); | ||
| 125 | |||
| 126 | if (len != 0) | ||
| 127 | { | ||
| 128 | s=(unsigned char *)Malloc((int)len+1); | ||
| 129 | if (s == NULL) | ||
| 130 | { | ||
| 131 | i=ERR_R_MALLOC_FAILURE; | ||
| 132 | goto err; | ||
| 133 | } | ||
| 134 | memcpy(s,p,(int)len); | ||
| 135 | s[len]='\0'; | ||
| 136 | p+=len; | ||
| 137 | } | ||
| 138 | else | ||
| 139 | s=NULL; | ||
| 140 | |||
| 141 | if (ret->data != NULL) Free((char *)ret->data); | ||
| 142 | ret->length=(int)len; | ||
| 143 | ret->data=s; | ||
| 144 | ret->type=tag; | ||
| 145 | if (a != NULL) (*a)=ret; | ||
| 146 | *pp=p; | ||
| 147 | return(ret); | ||
| 148 | err: | ||
| 149 | ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES,i); | ||
| 150 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | ||
| 151 | ASN1_STRING_free(ret); | ||
| 152 | return(NULL); | ||
| 153 | } | ||
| 154 | |||
| 155 | int i2d_ASN1_bytes(a, pp, tag, xclass) | ||
| 156 | ASN1_STRING *a; | ||
| 157 | unsigned char **pp; | ||
| 158 | int tag; | ||
| 159 | int xclass; | ||
| 160 | { | ||
| 161 | int ret,r,constructed; | ||
| 162 | unsigned char *p; | ||
| 163 | |||
| 164 | if (a == NULL) return(0); | ||
| 165 | |||
| 166 | if (tag == V_ASN1_BIT_STRING) | ||
| 167 | return(i2d_ASN1_BIT_STRING(a,pp)); | ||
| 168 | |||
| 169 | ret=a->length; | ||
| 170 | r=ASN1_object_size(0,ret,tag); | ||
| 171 | if (pp == NULL) return(r); | ||
| 172 | p= *pp; | ||
| 173 | |||
| 174 | if ((tag == V_ASN1_SEQUENCE) || (tag == V_ASN1_SET)) | ||
| 175 | constructed=1; | ||
| 176 | else | ||
| 177 | constructed=0; | ||
| 178 | ASN1_put_object(&p,constructed,ret,tag,xclass); | ||
| 179 | memcpy(p,a->data,a->length); | ||
| 180 | p+=a->length; | ||
| 181 | *pp= p; | ||
| 182 | return(r); | ||
| 183 | } | ||
| 184 | |||
| 185 | ASN1_STRING *d2i_ASN1_bytes(a, pp, length, Ptag, Pclass) | ||
| 186 | ASN1_STRING **a; | ||
| 187 | unsigned char **pp; | ||
| 188 | long length; | ||
| 189 | int Ptag; | ||
| 190 | int Pclass; | ||
| 191 | { | ||
| 192 | ASN1_STRING *ret=NULL; | ||
| 193 | unsigned char *p,*s; | ||
| 194 | long len; | ||
| 195 | int inf,tag,xclass; | ||
| 196 | int i=0; | ||
| 197 | |||
| 198 | if ((a == NULL) || ((*a) == NULL)) | ||
| 199 | { | ||
| 200 | if ((ret=ASN1_STRING_new()) == NULL) return(NULL); | ||
| 201 | } | ||
| 202 | else | ||
| 203 | ret=(*a); | ||
| 204 | |||
| 205 | p= *pp; | ||
| 206 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | ||
| 207 | if (inf & 0x80) | ||
| 208 | { | ||
| 209 | i=ASN1_R_BAD_OBJECT_HEADER; | ||
| 210 | goto err; | ||
| 211 | } | ||
| 212 | |||
| 213 | if (tag != Ptag) | ||
| 214 | { | ||
| 215 | i=ASN1_R_WRONG_TAG; | ||
| 216 | goto err; | ||
| 217 | } | ||
| 218 | |||
| 219 | if (inf & V_ASN1_CONSTRUCTED) | ||
| 220 | { | ||
| 221 | ASN1_CTX c; | ||
| 222 | |||
| 223 | c.pp=pp; | ||
| 224 | c.p=p; | ||
| 225 | c.inf=inf; | ||
| 226 | c.slen=len; | ||
| 227 | c.tag=Ptag; | ||
| 228 | c.xclass=Pclass; | ||
| 229 | c.max=(length == 0)?0:(p+length); | ||
| 230 | if (!asn1_collate_primative(ret,&c)) | ||
| 231 | goto err; | ||
| 232 | else | ||
| 233 | { | ||
| 234 | p=c.p; | ||
| 235 | } | ||
| 236 | } | ||
| 237 | else | ||
| 238 | { | ||
| 239 | if (len != 0) | ||
| 240 | { | ||
| 241 | if ((ret->length < len) || (ret->data == NULL)) | ||
| 242 | { | ||
| 243 | if (ret->data != NULL) Free((char *)ret->data); | ||
| 244 | s=(unsigned char *)Malloc((int)len); | ||
| 245 | if (s == NULL) | ||
| 246 | { | ||
| 247 | i=ERR_R_MALLOC_FAILURE; | ||
| 248 | goto err; | ||
| 249 | } | ||
| 250 | } | ||
| 251 | else | ||
| 252 | s=ret->data; | ||
| 253 | memcpy(s,p,(int)len); | ||
| 254 | p+=len; | ||
| 255 | } | ||
| 256 | else | ||
| 257 | { | ||
| 258 | s=NULL; | ||
| 259 | if (ret->data != NULL) Free((char *)ret->data); | ||
| 260 | } | ||
| 261 | |||
| 262 | ret->length=(int)len; | ||
| 263 | ret->data=s; | ||
| 264 | ret->type=Ptag; | ||
| 265 | } | ||
| 266 | |||
| 267 | if (a != NULL) (*a)=ret; | ||
| 268 | *pp=p; | ||
| 269 | return(ret); | ||
| 270 | err: | ||
| 271 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | ||
| 272 | ASN1_STRING_free(ret); | ||
| 273 | ASN1err(ASN1_F_D2I_ASN1_BYTES,i); | ||
| 274 | return(NULL); | ||
| 275 | } | ||
| 276 | |||
| 277 | |||
| 278 | /* We are about to parse 0..n d2i_ASN1_bytes objects, we are to collapes | ||
| 279 | * them into the one struture that is then returned */ | ||
| 280 | /* There have been a few bug fixes for this function from | ||
| 281 | * Paul Keogh <paul.keogh@sse.ie>, many thanks to him */ | ||
| 282 | static int asn1_collate_primative(a,c) | ||
| 283 | ASN1_STRING *a; | ||
| 284 | ASN1_CTX *c; | ||
| 285 | { | ||
| 286 | ASN1_STRING *os=NULL; | ||
| 287 | BUF_MEM b; | ||
| 288 | int num; | ||
| 289 | |||
| 290 | b.length=0; | ||
| 291 | b.max=0; | ||
| 292 | b.data=NULL; | ||
| 293 | |||
| 294 | if (a == NULL) | ||
| 295 | { | ||
| 296 | c->error=ERR_R_PASSED_NULL_PARAMETER; | ||
| 297 | goto err; | ||
| 298 | } | ||
| 299 | |||
| 300 | num=0; | ||
| 301 | for (;;) | ||
| 302 | { | ||
| 303 | if (c->inf & 1) | ||
| 304 | { | ||
| 305 | c->eos=ASN1_check_infinite_end(&c->p, | ||
| 306 | (long)(c->max-c->p)); | ||
| 307 | if (c->eos) break; | ||
| 308 | } | ||
| 309 | else | ||
| 310 | { | ||
| 311 | if (c->slen <= 0) break; | ||
| 312 | } | ||
| 313 | |||
| 314 | c->q=c->p; | ||
| 315 | if (d2i_ASN1_bytes(&os,&c->p,c->max-c->p,c->tag,c->xclass) | ||
| 316 | == NULL) | ||
| 317 | { | ||
| 318 | c->error=ERR_R_ASN1_LIB; | ||
| 319 | goto err; | ||
| 320 | } | ||
| 321 | |||
| 322 | if (!BUF_MEM_grow(&b,num+os->length)) | ||
| 323 | { | ||
| 324 | c->error=ERR_R_BUF_LIB; | ||
| 325 | goto err; | ||
| 326 | } | ||
| 327 | memcpy(&(b.data[num]),os->data,os->length); | ||
| 328 | if (!(c->inf & 1)) | ||
| 329 | c->slen-=(c->p-c->q); | ||
| 330 | num+=os->length; | ||
| 331 | } | ||
| 332 | |||
| 333 | if (!asn1_Finish(c)) goto err; | ||
| 334 | |||
| 335 | a->length=num; | ||
| 336 | if (a->data != NULL) Free(a->data); | ||
| 337 | a->data=(unsigned char *)b.data; | ||
| 338 | if (os != NULL) ASN1_STRING_free(os); | ||
| 339 | return(1); | ||
| 340 | err: | ||
| 341 | ASN1err(ASN1_F_ASN1_COLLATE_PRIMATIVE,c->error); | ||
| 342 | if (os != NULL) ASN1_STRING_free(os); | ||
| 343 | if (b.data != NULL) Free(b.data); | ||
| 344 | return(0); | ||
| 345 | } | ||
| 346 | |||
diff --git a/src/lib/libcrypto/asn1/a_d2i_fp.c b/src/lib/libcrypto/asn1/a_d2i_fp.c new file mode 100644 index 0000000000..d952836a91 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_d2i_fp.c | |||
| @@ -0,0 +1,201 @@ | |||
| 1 | /* crypto/asn1/a_d2i_fp.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 "buffer.h" | ||
| 62 | #include "asn1_mac.h" | ||
| 63 | |||
| 64 | #define HEADER_SIZE 8 | ||
| 65 | |||
| 66 | #ifndef NO_FP_API | ||
| 67 | char *ASN1_d2i_fp(xnew,d2i,in,x) | ||
| 68 | char *(*xnew)(); | ||
| 69 | char *(*d2i)(); | ||
| 70 | FILE *in; | ||
| 71 | unsigned char **x; | ||
| 72 | { | ||
| 73 | BIO *b; | ||
| 74 | char *ret; | ||
| 75 | |||
| 76 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 77 | { | ||
| 78 | ASN1err(ASN1_F_ASN1_D2I_FP,ERR_R_BUF_LIB); | ||
| 79 | return(NULL); | ||
| 80 | } | ||
| 81 | BIO_set_fp(b,in,BIO_NOCLOSE); | ||
| 82 | ret=ASN1_d2i_bio(xnew,d2i,b,x); | ||
| 83 | BIO_free(b); | ||
| 84 | return(ret); | ||
| 85 | } | ||
| 86 | #endif | ||
| 87 | |||
| 88 | char *ASN1_d2i_bio(xnew,d2i,in,x) | ||
| 89 | char *(*xnew)(); | ||
| 90 | char *(*d2i)(); | ||
| 91 | BIO *in; | ||
| 92 | unsigned char **x; | ||
| 93 | { | ||
| 94 | BUF_MEM *b; | ||
| 95 | unsigned char *p; | ||
| 96 | int i; | ||
| 97 | char *ret=NULL; | ||
| 98 | ASN1_CTX c; | ||
| 99 | int want=HEADER_SIZE; | ||
| 100 | int eos=0; | ||
| 101 | int off=0; | ||
| 102 | int len=0; | ||
| 103 | |||
| 104 | b=BUF_MEM_new(); | ||
| 105 | if (b == NULL) | ||
| 106 | { | ||
| 107 | ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE); | ||
| 108 | return(NULL); | ||
| 109 | } | ||
| 110 | |||
| 111 | ERR_clear_error(); | ||
| 112 | for (;;) | ||
| 113 | { | ||
| 114 | if (want >= (len-off)) | ||
| 115 | { | ||
| 116 | want-=(len-off); | ||
| 117 | |||
| 118 | if (!BUF_MEM_grow(b,len+want)) | ||
| 119 | { | ||
| 120 | ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE); | ||
| 121 | goto err; | ||
| 122 | } | ||
| 123 | i=BIO_read(in,&(b->data[len]),want); | ||
| 124 | if ((i < 0) && ((len-off) == 0)) | ||
| 125 | { | ||
| 126 | ASN1err(ASN1_F_ASN1_D2I_BIO,ASN1_R_NOT_ENOUGH_DATA); | ||
| 127 | goto err; | ||
| 128 | } | ||
| 129 | if (i > 0) | ||
| 130 | len+=i; | ||
| 131 | } | ||
| 132 | /* else data already loaded */ | ||
| 133 | |||
| 134 | p=(unsigned char *)&(b->data[off]); | ||
| 135 | c.p=p; | ||
| 136 | c.inf=ASN1_get_object(&(c.p),&(c.slen),&(c.tag),&(c.xclass), | ||
| 137 | len-off); | ||
| 138 | if (c.inf & 0x80) | ||
| 139 | { | ||
| 140 | unsigned long e; | ||
| 141 | |||
| 142 | e=ERR_GET_REASON(ERR_peek_error()); | ||
| 143 | if (e != ASN1_R_TOO_LONG) | ||
| 144 | goto err; | ||
| 145 | else | ||
| 146 | ERR_get_error(); /* clear error */ | ||
| 147 | } | ||
| 148 | i=c.p-p;/* header length */ | ||
| 149 | off+=i; /* end of data */ | ||
| 150 | |||
| 151 | if (c.inf & 1) | ||
| 152 | { | ||
| 153 | /* no data body so go round again */ | ||
| 154 | eos++; | ||
| 155 | want=HEADER_SIZE; | ||
| 156 | } | ||
| 157 | else if (eos && (c.slen == 0) && (c.tag == V_ASN1_EOC)) | ||
| 158 | { | ||
| 159 | /* eos value, so go back and read another header */ | ||
| 160 | eos--; | ||
| 161 | if (eos <= 0) | ||
| 162 | break; | ||
| 163 | else | ||
| 164 | want=HEADER_SIZE; | ||
| 165 | } | ||
| 166 | else | ||
| 167 | { | ||
| 168 | /* suck in c.slen bytes of data */ | ||
| 169 | want=(int)c.slen; | ||
| 170 | if (want > (len-off)) | ||
| 171 | { | ||
| 172 | want-=(len-off); | ||
| 173 | if (!BUF_MEM_grow(b,len+want)) | ||
| 174 | { | ||
| 175 | ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE); | ||
| 176 | goto err; | ||
| 177 | } | ||
| 178 | i=BIO_read(in,&(b->data[len]),want); | ||
| 179 | if (i <= 0) | ||
| 180 | { | ||
| 181 | ASN1err(ASN1_F_ASN1_D2I_BIO,ASN1_R_NOT_ENOUGH_DATA); | ||
| 182 | goto err; | ||
| 183 | } | ||
| 184 | len+=i; | ||
| 185 | } | ||
| 186 | off+=(int)c.slen; | ||
| 187 | if (eos <= 0) | ||
| 188 | { | ||
| 189 | break; | ||
| 190 | } | ||
| 191 | else | ||
| 192 | want=HEADER_SIZE; | ||
| 193 | } | ||
| 194 | } | ||
| 195 | |||
| 196 | p=(unsigned char *)b->data; | ||
| 197 | ret=d2i(x,&p,off); | ||
| 198 | err: | ||
| 199 | if (b != NULL) BUF_MEM_free(b); | ||
| 200 | return(ret); | ||
| 201 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_digest.c b/src/lib/libcrypto/asn1/a_digest.c new file mode 100644 index 0000000000..8ddb65b0dc --- /dev/null +++ b/src/lib/libcrypto/asn1/a_digest.c | |||
| @@ -0,0 +1,91 @@ | |||
| 1 | /* crypto/asn1/a_digest.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 <time.h> | ||
| 61 | #include <sys/types.h> | ||
| 62 | #include <sys/stat.h> | ||
| 63 | |||
| 64 | #include "cryptlib.h" | ||
| 65 | #include "evp.h" | ||
| 66 | #include "x509.h" | ||
| 67 | #include "buffer.h" | ||
| 68 | |||
| 69 | int ASN1_digest(i2d,type,data,md,len) | ||
| 70 | int (*i2d)(); | ||
| 71 | EVP_MD *type; | ||
| 72 | char *data; | ||
| 73 | unsigned char *md; | ||
| 74 | unsigned int *len; | ||
| 75 | { | ||
| 76 | EVP_MD_CTX ctx; | ||
| 77 | int i; | ||
| 78 | unsigned char *str,*p; | ||
| 79 | |||
| 80 | i=i2d(data,NULL); | ||
| 81 | if ((str=(unsigned char *)Malloc(i)) == NULL) return(0); | ||
| 82 | p=str; | ||
| 83 | i2d(data,&p); | ||
| 84 | |||
| 85 | EVP_DigestInit(&ctx,type); | ||
| 86 | EVP_DigestUpdate(&ctx,str,i); | ||
| 87 | EVP_DigestFinal(&ctx,md,len); | ||
| 88 | Free(str); | ||
| 89 | return(1); | ||
| 90 | } | ||
| 91 | |||
diff --git a/src/lib/libcrypto/asn1/a_dup.c b/src/lib/libcrypto/asn1/a_dup.c new file mode 100644 index 0000000000..961b4cb069 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_dup.c | |||
| @@ -0,0 +1,86 @@ | |||
| 1 | /* crypto/asn1/a_dup.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 | |||
| 63 | #define READ_CHUNK 2048 | ||
| 64 | |||
| 65 | char *ASN1_dup(i2d,d2i,x) | ||
| 66 | int (*i2d)(); | ||
| 67 | char *(*d2i)(); | ||
| 68 | char *x; | ||
| 69 | { | ||
| 70 | unsigned char *b,*p; | ||
| 71 | long i; | ||
| 72 | char *ret; | ||
| 73 | |||
| 74 | if (x == NULL) return(NULL); | ||
| 75 | |||
| 76 | i=(long)i2d(x,NULL); | ||
| 77 | b=(unsigned char *)Malloc((unsigned int)i+10); | ||
| 78 | if (b == NULL) | ||
| 79 | { ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); } | ||
| 80 | p= b; | ||
| 81 | i=i2d(x,&p); | ||
| 82 | p= b; | ||
| 83 | ret=d2i(NULL,&p,i); | ||
| 84 | Free((char *)b); | ||
| 85 | return(ret); | ||
| 86 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_i2d_fp.c b/src/lib/libcrypto/asn1/a_i2d_fp.c new file mode 100644 index 0000000000..66c3df68d5 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_i2d_fp.c | |||
| @@ -0,0 +1,119 @@ | |||
| 1 | /* crypto/asn1/a_i2d_fp.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 "buffer.h" | ||
| 62 | #include "asn1_mac.h" | ||
| 63 | |||
| 64 | #ifndef NO_FP_API | ||
| 65 | int ASN1_i2d_fp(i2d,out,x) | ||
| 66 | int (*i2d)(); | ||
| 67 | FILE *out; | ||
| 68 | unsigned char *x; | ||
| 69 | { | ||
| 70 | BIO *b; | ||
| 71 | int ret; | ||
| 72 | |||
| 73 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 74 | { | ||
| 75 | ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB); | ||
| 76 | return(0); | ||
| 77 | } | ||
| 78 | BIO_set_fp(b,out,BIO_NOCLOSE); | ||
| 79 | ret=ASN1_i2d_bio(i2d,b,x); | ||
| 80 | BIO_free(b); | ||
| 81 | return(ret); | ||
| 82 | } | ||
| 83 | #endif | ||
| 84 | |||
| 85 | int ASN1_i2d_bio(i2d,out,x) | ||
| 86 | int (*i2d)(); | ||
| 87 | BIO *out; | ||
| 88 | unsigned char *x; | ||
| 89 | { | ||
| 90 | char *b; | ||
| 91 | unsigned char *p; | ||
| 92 | int i,j=0,n,ret=1; | ||
| 93 | |||
| 94 | n=i2d(x,NULL); | ||
| 95 | b=(char *)Malloc(n); | ||
| 96 | if (b == NULL) | ||
| 97 | { | ||
| 98 | ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE); | ||
| 99 | return(0); | ||
| 100 | } | ||
| 101 | |||
| 102 | p=(unsigned char *)b; | ||
| 103 | i2d(x,&p); | ||
| 104 | |||
| 105 | for (;;) | ||
| 106 | { | ||
| 107 | i=BIO_write(out,&(b[j]),n); | ||
| 108 | if (i == n) break; | ||
| 109 | if (i <= 0) | ||
| 110 | { | ||
| 111 | ret=0; | ||
| 112 | break; | ||
| 113 | } | ||
| 114 | j+=i; | ||
| 115 | n-=i; | ||
| 116 | } | ||
| 117 | Free((char *)b); | ||
| 118 | return(ret); | ||
| 119 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_int.c b/src/lib/libcrypto/asn1/a_int.c new file mode 100644 index 0000000000..df79cf99bb --- /dev/null +++ b/src/lib/libcrypto/asn1/a_int.c | |||
| @@ -0,0 +1,305 @@ | |||
| 1 | /* crypto/asn1/a_int.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_INTEGER(a,pp) | ||
| 67 | ASN1_INTEGER *a; | ||
| 68 | unsigned char **pp; | ||
| 69 | { | ||
| 70 | int pad=0,ret,r,i,t; | ||
| 71 | unsigned char *p,*pt,*n,pb=0; | ||
| 72 | |||
| 73 | if ((a == NULL) || (a->data == NULL)) return(0); | ||
| 74 | t=a->type; | ||
| 75 | if (a->length == 0) | ||
| 76 | ret=1; | ||
| 77 | else | ||
| 78 | { | ||
| 79 | ret=a->length; | ||
| 80 | i=a->data[0]; | ||
| 81 | if ((t == V_ASN1_INTEGER) && (i > 127)) | ||
| 82 | { | ||
| 83 | pad=1; | ||
| 84 | pb=0; | ||
| 85 | } | ||
| 86 | else if ((t == V_ASN1_NEG_INTEGER) && (i>128)) | ||
| 87 | { | ||
| 88 | pad=1; | ||
| 89 | pb=0xFF; | ||
| 90 | } | ||
| 91 | ret+=pad; | ||
| 92 | } | ||
| 93 | r=ASN1_object_size(0,ret,V_ASN1_INTEGER); | ||
| 94 | if (pp == NULL) return(r); | ||
| 95 | p= *pp; | ||
| 96 | |||
| 97 | ASN1_put_object(&p,0,ret,V_ASN1_INTEGER,V_ASN1_UNIVERSAL); | ||
| 98 | if (pad) *(p++)=pb; | ||
| 99 | if (a->length == 0) | ||
| 100 | *(p++)=0; | ||
| 101 | else if (t == V_ASN1_INTEGER) | ||
| 102 | { | ||
| 103 | memcpy(p,a->data,(unsigned int)a->length); | ||
| 104 | p+=a->length; | ||
| 105 | } | ||
| 106 | else | ||
| 107 | { | ||
| 108 | n=a->data; | ||
| 109 | pt=p; | ||
| 110 | for (i=a->length; i>0; i--) | ||
| 111 | *(p++)= (*(n++)^0xFF)+1; | ||
| 112 | if (!pad) *pt|=0x80; | ||
| 113 | } | ||
| 114 | |||
| 115 | *pp=p; | ||
| 116 | return(r); | ||
| 117 | } | ||
| 118 | |||
| 119 | ASN1_INTEGER *d2i_ASN1_INTEGER(a, pp, length) | ||
| 120 | ASN1_INTEGER **a; | ||
| 121 | unsigned char **pp; | ||
| 122 | long length; | ||
| 123 | { | ||
| 124 | ASN1_INTEGER *ret=NULL; | ||
| 125 | unsigned char *p,*to,*s; | ||
| 126 | long len; | ||
| 127 | int inf,tag,xclass; | ||
| 128 | int i; | ||
| 129 | |||
| 130 | if ((a == NULL) || ((*a) == NULL)) | ||
| 131 | { | ||
| 132 | if ((ret=ASN1_INTEGER_new()) == NULL) return(NULL); | ||
| 133 | ret->type=V_ASN1_INTEGER; | ||
| 134 | } | ||
| 135 | else | ||
| 136 | ret=(*a); | ||
| 137 | |||
| 138 | p= *pp; | ||
| 139 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | ||
| 140 | if (inf & 0x80) | ||
| 141 | { | ||
| 142 | i=ASN1_R_BAD_OBJECT_HEADER; | ||
| 143 | goto err; | ||
| 144 | } | ||
| 145 | |||
| 146 | if (tag != V_ASN1_INTEGER) | ||
| 147 | { | ||
| 148 | i=ASN1_R_EXPECTING_AN_INTEGER; | ||
| 149 | goto err; | ||
| 150 | } | ||
| 151 | |||
| 152 | /* We must Malloc stuff, even for 0 bytes otherwise it | ||
| 153 | * signifies a missing NULL parameter. */ | ||
| 154 | s=(unsigned char *)Malloc((int)len+1); | ||
| 155 | if (s == NULL) | ||
| 156 | { | ||
| 157 | i=ERR_R_MALLOC_FAILURE; | ||
| 158 | goto err; | ||
| 159 | } | ||
| 160 | to=s; | ||
| 161 | if (*p & 0x80) /* a negative number */ | ||
| 162 | { | ||
| 163 | ret->type=V_ASN1_NEG_INTEGER; | ||
| 164 | if (*p == 0xff) | ||
| 165 | { | ||
| 166 | p++; | ||
| 167 | len--; | ||
| 168 | } | ||
| 169 | for (i=(int)len; i>0; i--) | ||
| 170 | *(to++)= (*(p++)^0xFF)+1; | ||
| 171 | } | ||
| 172 | else | ||
| 173 | { | ||
| 174 | ret->type=V_ASN1_INTEGER; | ||
| 175 | if ((*p == 0) && (len != 1)) | ||
| 176 | { | ||
| 177 | p++; | ||
| 178 | len--; | ||
| 179 | } | ||
| 180 | memcpy(s,p,(int)len); | ||
| 181 | p+=len; | ||
| 182 | } | ||
| 183 | |||
| 184 | if (ret->data != NULL) Free((char *)ret->data); | ||
| 185 | ret->data=s; | ||
| 186 | ret->length=(int)len; | ||
| 187 | if (a != NULL) (*a)=ret; | ||
| 188 | *pp=p; | ||
| 189 | return(ret); | ||
| 190 | err: | ||
| 191 | ASN1err(ASN1_F_D2I_ASN1_INTEGER,i); | ||
| 192 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | ||
| 193 | ASN1_INTEGER_free(ret); | ||
| 194 | return(NULL); | ||
| 195 | } | ||
| 196 | |||
| 197 | int ASN1_INTEGER_set(a,v) | ||
| 198 | ASN1_INTEGER *a; | ||
| 199 | long v; | ||
| 200 | { | ||
| 201 | int i,j,k; | ||
| 202 | unsigned char buf[sizeof(long)+1]; | ||
| 203 | long d; | ||
| 204 | |||
| 205 | a->type=V_ASN1_INTEGER; | ||
| 206 | if (a->length < (sizeof(long)+1)) | ||
| 207 | { | ||
| 208 | if (a->data != NULL) | ||
| 209 | Free((char *)a->data); | ||
| 210 | if ((a->data=(unsigned char *)Malloc(sizeof(long)+1)) != NULL) | ||
| 211 | memset((char *)a->data,0,sizeof(long)+1); | ||
| 212 | } | ||
| 213 | if (a->data == NULL) | ||
| 214 | { | ||
| 215 | ASN1err(ASN1_F_ASN1_INTEGER_SET,ERR_R_MALLOC_FAILURE); | ||
| 216 | return(0); | ||
| 217 | } | ||
| 218 | d=v; | ||
| 219 | if (d < 0) | ||
| 220 | { | ||
| 221 | d= -d; | ||
| 222 | a->type=V_ASN1_NEG_INTEGER; | ||
| 223 | } | ||
| 224 | |||
| 225 | for (i=0; i<sizeof(long); i++) | ||
| 226 | { | ||
| 227 | if (d == 0) break; | ||
| 228 | buf[i]=(int)d&0xff; | ||
| 229 | d>>=8; | ||
| 230 | } | ||
| 231 | j=0; | ||
| 232 | if (v < 0) a->data[j++]=0; | ||
| 233 | for (k=i-1; k >=0; k--) | ||
| 234 | a->data[j++]=buf[k]; | ||
| 235 | a->length=j; | ||
| 236 | return(1); | ||
| 237 | } | ||
| 238 | |||
| 239 | long ASN1_INTEGER_get(a) | ||
| 240 | ASN1_INTEGER *a; | ||
| 241 | { | ||
| 242 | int neg=0,i; | ||
| 243 | long r=0; | ||
| 244 | |||
| 245 | if (a == NULL) return(0L); | ||
| 246 | i=a->type; | ||
| 247 | if (i == V_ASN1_NEG_INTEGER) | ||
| 248 | neg=1; | ||
| 249 | else if (i != V_ASN1_INTEGER) | ||
| 250 | return(0); | ||
| 251 | |||
| 252 | if (a->length > sizeof(long)) | ||
| 253 | { | ||
| 254 | /* hmm... a bit ugly */ | ||
| 255 | return(0xffffffffL); | ||
| 256 | } | ||
| 257 | if (a->data == NULL) | ||
| 258 | return(0); | ||
| 259 | |||
| 260 | for (i=0; i<a->length; i++) | ||
| 261 | { | ||
| 262 | r<<=8; | ||
| 263 | r|=(unsigned char)a->data[i]; | ||
| 264 | } | ||
| 265 | if (neg) r= -r; | ||
| 266 | return(r); | ||
| 267 | } | ||
| 268 | |||
| 269 | ASN1_INTEGER *BN_to_ASN1_INTEGER(bn,ai) | ||
| 270 | BIGNUM *bn; | ||
| 271 | ASN1_INTEGER *ai; | ||
| 272 | { | ||
| 273 | ASN1_INTEGER *ret; | ||
| 274 | int len,j; | ||
| 275 | |||
| 276 | if (ai == NULL) | ||
| 277 | ret=ASN1_INTEGER_new(); | ||
| 278 | else | ||
| 279 | ret=ai; | ||
| 280 | if (ret == NULL) | ||
| 281 | { | ||
| 282 | ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ASN1_R_ERROR_STACK); | ||
| 283 | goto err; | ||
| 284 | } | ||
| 285 | ret->type=V_ASN1_INTEGER; | ||
| 286 | j=BN_num_bits(bn); | ||
| 287 | len=((j == 0)?0:((j/8)+1)); | ||
| 288 | ret->data=(unsigned char *)Malloc(len+4); | ||
| 289 | ret->length=BN_bn2bin(bn,ret->data); | ||
| 290 | return(ret); | ||
| 291 | err: | ||
| 292 | if (ret != ai) ASN1_INTEGER_free(ret); | ||
| 293 | return(NULL); | ||
| 294 | } | ||
| 295 | |||
| 296 | BIGNUM *ASN1_INTEGER_to_BN(ai,bn) | ||
| 297 | ASN1_INTEGER *ai; | ||
| 298 | BIGNUM *bn; | ||
| 299 | { | ||
| 300 | BIGNUM *ret; | ||
| 301 | |||
| 302 | if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL) | ||
| 303 | ASN1err(ASN1_F_ASN1_INTEGER_TO_BN,ASN1_R_BN_LIB); | ||
| 304 | return(ret); | ||
| 305 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c new file mode 100644 index 0000000000..5a7eeef8d8 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_object.c | |||
| @@ -0,0 +1,389 @@ | |||
| 1 | /* crypto/asn1/a_object.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 "buffer.h" | ||
| 62 | #include "asn1.h" | ||
| 63 | #include "objects.h" | ||
| 64 | |||
| 65 | /* ASN1err(ASN1_F_ASN1_OBJECT_NEW,ASN1_R_EXPECTING_AN_OBJECT); | ||
| 66 | * ASN1err(ASN1_F_D2I_ASN1_OBJECT,ASN1_R_BAD_OBJECT_HEADER); | ||
| 67 | * ASN1err(ASN1_F_I2T_ASN1_OBJECT,ASN1_R_BAD_OBJECT_HEADER); | ||
| 68 | */ | ||
| 69 | |||
| 70 | int i2d_ASN1_OBJECT(a, pp) | ||
| 71 | ASN1_OBJECT *a; | ||
| 72 | unsigned char **pp; | ||
| 73 | { | ||
| 74 | unsigned char *p; | ||
| 75 | |||
| 76 | if ((a == NULL) || (a->data == NULL)) return(0); | ||
| 77 | |||
| 78 | if (pp == NULL) | ||
| 79 | return(ASN1_object_size(0,a->length,V_ASN1_OBJECT)); | ||
| 80 | |||
| 81 | p= *pp; | ||
| 82 | ASN1_put_object(&p,0,a->length,V_ASN1_OBJECT,V_ASN1_UNIVERSAL); | ||
| 83 | memcpy(p,a->data,a->length); | ||
| 84 | p+=a->length; | ||
| 85 | |||
| 86 | *pp=p; | ||
| 87 | return(a->length); | ||
| 88 | } | ||
| 89 | |||
| 90 | int a2d_ASN1_OBJECT(out,olen,buf,num) | ||
| 91 | unsigned char *out; | ||
| 92 | int olen; | ||
| 93 | char *buf; | ||
| 94 | int num; | ||
| 95 | { | ||
| 96 | int i,first,len=0,c; | ||
| 97 | char tmp[24],*p; | ||
| 98 | unsigned long l; | ||
| 99 | |||
| 100 | if (num == 0) | ||
| 101 | return(0); | ||
| 102 | else if (num == -1) | ||
| 103 | num=strlen(buf); | ||
| 104 | |||
| 105 | p=buf; | ||
| 106 | c= *(p++); | ||
| 107 | num--; | ||
| 108 | if ((c >= '0') && (c <= '2')) | ||
| 109 | { | ||
| 110 | first=(c-'0')*40; | ||
| 111 | } | ||
| 112 | else | ||
| 113 | { | ||
| 114 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_FIRST_NUM_TOO_LARGE); | ||
| 115 | goto err; | ||
| 116 | } | ||
| 117 | |||
| 118 | if (num <= 0) | ||
| 119 | { | ||
| 120 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_MISSING_SECOND_NUMBER); | ||
| 121 | goto err; | ||
| 122 | } | ||
| 123 | c= *(p++); | ||
| 124 | num--; | ||
| 125 | for (;;) | ||
| 126 | { | ||
| 127 | if (num <= 0) break; | ||
| 128 | if ((c != '.') && (c != ' ')) | ||
| 129 | { | ||
| 130 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_SEPARATOR); | ||
| 131 | goto err; | ||
| 132 | } | ||
| 133 | l=0; | ||
| 134 | for (;;) | ||
| 135 | { | ||
| 136 | if (num <= 0) break; | ||
| 137 | num--; | ||
| 138 | c= *(p++); | ||
| 139 | if ((c == ' ') || (c == '.')) | ||
| 140 | break; | ||
| 141 | if ((c < '0') || (c > '9')) | ||
| 142 | { | ||
| 143 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT); | ||
| 144 | goto err; | ||
| 145 | } | ||
| 146 | l=l*10L+(long)(c-'0'); | ||
| 147 | } | ||
| 148 | if (len == 0) | ||
| 149 | { | ||
| 150 | if ((first < 2) && (l >= 40)) | ||
| 151 | { | ||
| 152 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_SECOND_NUMBER_TOO_LARGE); | ||
| 153 | goto err; | ||
| 154 | } | ||
| 155 | l+=(long)first; | ||
| 156 | } | ||
| 157 | i=0; | ||
| 158 | for (;;) | ||
| 159 | { | ||
| 160 | tmp[i++]=(unsigned char)l&0x7f; | ||
| 161 | l>>=7L; | ||
| 162 | if (l == 0L) break; | ||
| 163 | } | ||
| 164 | if (out != NULL) | ||
| 165 | { | ||
| 166 | if (len+i > olen) | ||
| 167 | { | ||
| 168 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_BUFFER_TOO_SMALL); | ||
| 169 | goto err; | ||
| 170 | } | ||
| 171 | while (--i > 0) | ||
| 172 | out[len++]=tmp[i]|0x80; | ||
| 173 | out[len++]=tmp[0]; | ||
| 174 | } | ||
| 175 | else | ||
| 176 | len+=i; | ||
| 177 | } | ||
| 178 | return(len); | ||
| 179 | err: | ||
| 180 | return(0); | ||
| 181 | } | ||
| 182 | |||
| 183 | int i2t_ASN1_OBJECT(buf,buf_len,a) | ||
| 184 | char *buf; | ||
| 185 | int buf_len; | ||
| 186 | ASN1_OBJECT *a; | ||
| 187 | { | ||
| 188 | int i,idx=0,n=0,len,nid; | ||
| 189 | unsigned long l; | ||
| 190 | unsigned char *p; | ||
| 191 | char *s; | ||
| 192 | char tbuf[32]; | ||
| 193 | |||
| 194 | if (buf_len <= 0) return(0); | ||
| 195 | |||
| 196 | if ((a == NULL) || (a->data == NULL)) | ||
| 197 | { | ||
| 198 | buf[0]='\0'; | ||
| 199 | return(0); | ||
| 200 | } | ||
| 201 | |||
| 202 | nid=OBJ_obj2nid(a); | ||
| 203 | if (nid == NID_undef) | ||
| 204 | { | ||
| 205 | len=a->length; | ||
| 206 | p=a->data; | ||
| 207 | |||
| 208 | idx=0; | ||
| 209 | l=0; | ||
| 210 | while (idx < a->length) | ||
| 211 | { | ||
| 212 | l|=(p[idx]&0x7f); | ||
| 213 | if (!(p[idx] & 0x80)) break; | ||
| 214 | l<<=7L; | ||
| 215 | idx++; | ||
| 216 | } | ||
| 217 | idx++; | ||
| 218 | i=(int)(l/40); | ||
| 219 | if (i > 2) i=2; | ||
| 220 | l-=(long)(i*40); | ||
| 221 | |||
| 222 | sprintf(tbuf,"%d.%ld",i,l); | ||
| 223 | i=strlen(tbuf); | ||
| 224 | strncpy(buf,tbuf,buf_len); | ||
| 225 | buf_len-=i; | ||
| 226 | buf+=i; | ||
| 227 | n+=i; | ||
| 228 | |||
| 229 | l=0; | ||
| 230 | for (; idx<len; idx++) | ||
| 231 | { | ||
| 232 | l|=p[idx]&0x7f; | ||
| 233 | if (!(p[idx] & 0x80)) | ||
| 234 | { | ||
| 235 | sprintf(tbuf,".%ld",l); | ||
| 236 | i=strlen(tbuf); | ||
| 237 | if (buf_len > 0) | ||
| 238 | strncpy(buf,tbuf,buf_len); | ||
| 239 | buf_len-=i; | ||
| 240 | buf+=i; | ||
| 241 | n+=i; | ||
| 242 | l=0; | ||
| 243 | } | ||
| 244 | l<<=7L; | ||
| 245 | } | ||
| 246 | } | ||
| 247 | else | ||
| 248 | { | ||
| 249 | s=(char *)OBJ_nid2ln(nid); | ||
| 250 | if (s == NULL) | ||
| 251 | s=(char *)OBJ_nid2sn(nid); | ||
| 252 | strncpy(buf,s,buf_len); | ||
| 253 | n=strlen(s); | ||
| 254 | } | ||
| 255 | buf[buf_len-1]='\0'; | ||
| 256 | return(n); | ||
| 257 | } | ||
| 258 | |||
| 259 | int i2a_ASN1_OBJECT(bp,a) | ||
| 260 | BIO *bp; | ||
| 261 | ASN1_OBJECT *a; | ||
| 262 | { | ||
| 263 | char buf[80]; | ||
| 264 | int i; | ||
| 265 | |||
| 266 | if ((a == NULL) || (a->data == NULL)) | ||
| 267 | return(BIO_write(bp,"NULL",4)); | ||
| 268 | i=i2t_ASN1_OBJECT(buf,80,a); | ||
| 269 | if (i > 80) i=80; | ||
| 270 | BIO_write(bp,buf,i); | ||
| 271 | return(i); | ||
| 272 | } | ||
| 273 | |||
| 274 | ASN1_OBJECT *d2i_ASN1_OBJECT(a, pp, length) | ||
| 275 | ASN1_OBJECT **a; | ||
| 276 | unsigned char **pp; | ||
| 277 | long length; | ||
| 278 | { | ||
| 279 | ASN1_OBJECT *ret=NULL; | ||
| 280 | unsigned char *p; | ||
| 281 | long len; | ||
| 282 | int tag,xclass; | ||
| 283 | int inf,i; | ||
| 284 | |||
| 285 | /* only the ASN1_OBJECTs from the 'table' will have values | ||
| 286 | * for ->sn or ->ln */ | ||
| 287 | if ((a == NULL) || ((*a) == NULL) || | ||
| 288 | !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) | ||
| 289 | { | ||
| 290 | if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL); | ||
| 291 | } | ||
| 292 | else ret=(*a); | ||
| 293 | |||
| 294 | p= *pp; | ||
| 295 | |||
| 296 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | ||
| 297 | if (inf & 0x80) | ||
| 298 | { | ||
| 299 | i=ASN1_R_BAD_OBJECT_HEADER; | ||
| 300 | goto err; | ||
| 301 | } | ||
| 302 | |||
| 303 | if (tag != V_ASN1_OBJECT) | ||
| 304 | { | ||
| 305 | i=ASN1_R_EXPECTING_AN_OBJECT; | ||
| 306 | goto err; | ||
| 307 | } | ||
| 308 | if ((ret->data == NULL) || (ret->length < len)) | ||
| 309 | { | ||
| 310 | if (ret->data != NULL) Free((char *)ret->data); | ||
| 311 | ret->data=(unsigned char *)Malloc((int)len); | ||
| 312 | ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA; | ||
| 313 | if (ret->data == NULL) | ||
| 314 | { i=ERR_R_MALLOC_FAILURE; goto err; } | ||
| 315 | } | ||
| 316 | memcpy(ret->data,p,(int)len); | ||
| 317 | ret->length=(int)len; | ||
| 318 | ret->sn=NULL; | ||
| 319 | ret->ln=NULL; | ||
| 320 | /* ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; we know it is dynamic */ | ||
| 321 | p+=len; | ||
| 322 | |||
| 323 | if (a != NULL) (*a)=ret; | ||
| 324 | *pp=p; | ||
| 325 | return(ret); | ||
| 326 | err: | ||
| 327 | ASN1err(ASN1_F_D2I_ASN1_OBJECT,i); | ||
| 328 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | ||
| 329 | ASN1_OBJECT_free(ret); | ||
| 330 | return(NULL); | ||
| 331 | } | ||
| 332 | |||
| 333 | ASN1_OBJECT *ASN1_OBJECT_new() | ||
| 334 | { | ||
| 335 | ASN1_OBJECT *ret; | ||
| 336 | |||
| 337 | ret=(ASN1_OBJECT *)Malloc(sizeof(ASN1_OBJECT)); | ||
| 338 | if (ret == NULL) | ||
| 339 | { | ||
| 340 | ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE); | ||
| 341 | return(NULL); | ||
| 342 | } | ||
| 343 | ret->length=0; | ||
| 344 | ret->data=NULL; | ||
| 345 | ret->nid=0; | ||
| 346 | ret->sn=NULL; | ||
| 347 | ret->ln=NULL; | ||
| 348 | ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; | ||
| 349 | return(ret); | ||
| 350 | } | ||
| 351 | |||
| 352 | void ASN1_OBJECT_free(a) | ||
| 353 | ASN1_OBJECT *a; | ||
| 354 | { | ||
| 355 | if (a == NULL) return; | ||
| 356 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) | ||
| 357 | { | ||
| 358 | if (a->sn != NULL) Free(a->sn); | ||
| 359 | if (a->ln != NULL) Free(a->ln); | ||
| 360 | a->sn=a->ln=NULL; | ||
| 361 | } | ||
| 362 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) | ||
| 363 | { | ||
| 364 | if (a->data != NULL) Free(a->data); | ||
| 365 | a->data=NULL; | ||
| 366 | a->length=0; | ||
| 367 | } | ||
| 368 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC) | ||
| 369 | Free((char *)a); | ||
| 370 | } | ||
| 371 | |||
| 372 | ASN1_OBJECT *ASN1_OBJECT_create(nid,data,len,sn,ln) | ||
| 373 | int nid; | ||
| 374 | unsigned char *data; | ||
| 375 | int len; | ||
| 376 | char *sn,*ln; | ||
| 377 | { | ||
| 378 | ASN1_OBJECT o; | ||
| 379 | |||
| 380 | o.sn=sn; | ||
| 381 | o.ln=ln; | ||
| 382 | o.data=data; | ||
| 383 | o.nid=nid; | ||
| 384 | o.length=len; | ||
| 385 | o.flags=ASN1_OBJECT_FLAG_DYNAMIC| | ||
| 386 | ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|ASN1_OBJECT_FLAG_DYNAMIC_DATA; | ||
| 387 | return(OBJ_dup(&o)); | ||
| 388 | } | ||
| 389 | |||
diff --git a/src/lib/libcrypto/asn1/a_octet.c b/src/lib/libcrypto/asn1/a_octet.c new file mode 100644 index 0000000000..be3f172a8c --- /dev/null +++ b/src/lib/libcrypto/asn1/a_octet.c | |||
| @@ -0,0 +1,90 @@ | |||
| 1 | /* crypto/asn1/a_octet.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_OCTET_STRING,ASN1_R_EXPECTING_AN_OCTET_STRING); | ||
| 64 | */ | ||
| 65 | |||
| 66 | int i2d_ASN1_OCTET_STRING(a, pp) | ||
| 67 | ASN1_OCTET_STRING *a; | ||
| 68 | unsigned char **pp; | ||
| 69 | { | ||
| 70 | return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, | ||
| 71 | V_ASN1_OCTET_STRING,V_ASN1_UNIVERSAL)); | ||
| 72 | } | ||
| 73 | |||
| 74 | ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(a, pp, length) | ||
| 75 | ASN1_OCTET_STRING **a; | ||
| 76 | unsigned char **pp; | ||
| 77 | long length; | ||
| 78 | { | ||
| 79 | ASN1_OCTET_STRING *ret=NULL; | ||
| 80 | |||
| 81 | ret=(ASN1_OCTET_STRING *)d2i_ASN1_bytes((ASN1_STRING **)a, | ||
| 82 | pp,length,V_ASN1_OCTET_STRING,V_ASN1_UNIVERSAL); | ||
| 83 | if (ret == NULL) | ||
| 84 | { | ||
| 85 | ASN1err(ASN1_F_D2I_ASN1_OCTET_STRING,ASN1_R_ERROR_STACK); | ||
| 86 | return(NULL); | ||
| 87 | } | ||
| 88 | return(ret); | ||
| 89 | } | ||
| 90 | |||
diff --git a/src/lib/libcrypto/asn1/a_print.c b/src/lib/libcrypto/asn1/a_print.c new file mode 100644 index 0000000000..3023361dee --- /dev/null +++ b/src/lib/libcrypto/asn1/a_print.c | |||
| @@ -0,0 +1,161 @@ | |||
| 1 | /* crypto/asn1/a_print.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_PRINT_TYPE,ASN1_R_WRONG_PRINTABLE_TYPE); | ||
| 64 | * ASN1err(ASN1_F_D2I_ASN1_PRINT_TYPE,ASN1_R_TAG_VALUE_TOO_HIGH); | ||
| 65 | */ | ||
| 66 | |||
| 67 | int i2d_ASN1_IA5STRING(a,pp) | ||
| 68 | ASN1_IA5STRING *a; | ||
| 69 | unsigned char **pp; | ||
| 70 | { return(M_i2d_ASN1_IA5STRING(a,pp)); } | ||
| 71 | |||
| 72 | ASN1_IA5STRING *d2i_ASN1_IA5STRING(a,pp,l) | ||
| 73 | ASN1_IA5STRING **a; | ||
| 74 | unsigned char **pp; | ||
| 75 | long l; | ||
| 76 | { return(M_d2i_ASN1_IA5STRING(a,pp,l)); } | ||
| 77 | |||
| 78 | ASN1_T61STRING *d2i_ASN1_T61STRING(a,pp,l) | ||
| 79 | ASN1_T61STRING **a; | ||
| 80 | unsigned char **pp; | ||
| 81 | long l; | ||
| 82 | { return(M_d2i_ASN1_T61STRING(a,pp,l)); } | ||
| 83 | |||
| 84 | ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING(a,pp,l) | ||
| 85 | ASN1_PRINTABLESTRING **a; | ||
| 86 | unsigned char **pp; | ||
| 87 | long l; | ||
| 88 | { return(M_d2i_ASN1_PRINTABLESTRING(a,pp,l)); } | ||
| 89 | |||
| 90 | int i2d_ASN1_PRINTABLE(a,pp) | ||
| 91 | ASN1_STRING *a; | ||
| 92 | unsigned char **pp; | ||
| 93 | { return(M_i2d_ASN1_PRINTABLE(a,pp)); } | ||
| 94 | |||
| 95 | ASN1_STRING *d2i_ASN1_PRINTABLE(a,pp,l) | ||
| 96 | ASN1_STRING **a; | ||
| 97 | unsigned char **pp; | ||
| 98 | long l; | ||
| 99 | { return(M_d2i_ASN1_PRINTABLE(a,pp,l)); } | ||
| 100 | |||
| 101 | int ASN1_PRINTABLE_type(s,len) | ||
| 102 | unsigned char *s; | ||
| 103 | int len; | ||
| 104 | { | ||
| 105 | int c; | ||
| 106 | int ia5=0; | ||
| 107 | int t61=0; | ||
| 108 | |||
| 109 | if (len <= 0) len= -1; | ||
| 110 | if (s == NULL) return(V_ASN1_PRINTABLESTRING); | ||
| 111 | |||
| 112 | while ((*s) && (len-- != 0)) | ||
| 113 | { | ||
| 114 | c= *(s++); | ||
| 115 | if (!( ((c >= 'a') && (c <= 'z')) || | ||
| 116 | ((c >= 'A') && (c <= 'Z')) || | ||
| 117 | (c == ' ') || | ||
| 118 | ((c >= '0') && (c <= '9')) || | ||
| 119 | (c == ' ') || (c == '\'') || | ||
| 120 | (c == '(') || (c == ')') || | ||
| 121 | (c == '+') || (c == ',') || | ||
| 122 | (c == '-') || (c == '.') || | ||
| 123 | (c == '/') || (c == ':') || | ||
| 124 | (c == '=') || (c == '?'))) | ||
| 125 | ia5=1; | ||
| 126 | if (c&0x80) | ||
| 127 | t61=1; | ||
| 128 | } | ||
| 129 | if (t61) return(V_ASN1_T61STRING); | ||
| 130 | if (ia5) return(V_ASN1_IA5STRING); | ||
| 131 | return(V_ASN1_PRINTABLESTRING); | ||
| 132 | } | ||
| 133 | |||
| 134 | int ASN1_UNIVERSALSTRING_to_string(s) | ||
| 135 | ASN1_UNIVERSALSTRING *s; | ||
| 136 | { | ||
| 137 | int i; | ||
| 138 | unsigned char *p; | ||
| 139 | |||
| 140 | if (s->type != V_ASN1_UNIVERSALSTRING) return(0); | ||
| 141 | if ((s->length%4) != 0) return(0); | ||
| 142 | p=s->data; | ||
| 143 | for (i=0; i<s->length; i+=4) | ||
| 144 | { | ||
| 145 | if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0')) | ||
| 146 | break; | ||
| 147 | else | ||
| 148 | p+=4; | ||
| 149 | } | ||
| 150 | if (i < s->length) return(0); | ||
| 151 | p=s->data; | ||
| 152 | for (i=3; i<s->length; i+=4) | ||
| 153 | { | ||
| 154 | *(p++)=s->data[i]; | ||
| 155 | } | ||
| 156 | *(p)='\0'; | ||
| 157 | s->length/=4; | ||
| 158 | s->type=ASN1_PRINTABLE_type(s->data,s->length); | ||
| 159 | return(1); | ||
| 160 | } | ||
| 161 | |||
diff --git a/src/lib/libcrypto/asn1/a_set.c b/src/lib/libcrypto/asn1/a_set.c new file mode 100644 index 0000000000..17c49946cf --- /dev/null +++ b/src/lib/libcrypto/asn1/a_set.c | |||
| @@ -0,0 +1,149 @@ | |||
| 1 | /* crypto/asn1/a_set.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 | |||
| 63 | /* ASN1err(ASN1_F_ASN1_TYPE_NEW,ERR_R_MALLOC_FAILURE); | ||
| 64 | */ | ||
| 65 | |||
| 66 | int i2d_ASN1_SET(a,pp,func,ex_tag,ex_class) | ||
| 67 | STACK *a; | ||
| 68 | unsigned char **pp; | ||
| 69 | int (*func)(); | ||
| 70 | int ex_tag; | ||
| 71 | int ex_class; | ||
| 72 | { | ||
| 73 | int ret=0,r; | ||
| 74 | int i; | ||
| 75 | unsigned char *p; | ||
| 76 | |||
| 77 | if (a == NULL) return(0); | ||
| 78 | for (i=sk_num(a)-1; i>=0; i--) | ||
| 79 | ret+=func(sk_value(a,i),NULL); | ||
| 80 | r=ASN1_object_size(1,ret,ex_tag); | ||
| 81 | if (pp == NULL) return(r); | ||
| 82 | |||
| 83 | p= *pp; | ||
| 84 | ASN1_put_object(&p,1,ret,ex_tag,ex_class); | ||
| 85 | for (i=0; i<sk_num(a); i++) | ||
| 86 | func(sk_value(a,i),&p); | ||
| 87 | |||
| 88 | *pp=p; | ||
| 89 | return(r); | ||
| 90 | } | ||
| 91 | |||
| 92 | STACK *d2i_ASN1_SET(a,pp,length,func,ex_tag,ex_class) | ||
| 93 | STACK **a; | ||
| 94 | unsigned char **pp; | ||
| 95 | long length; | ||
| 96 | char *(*func)(); | ||
| 97 | int ex_tag; | ||
| 98 | int ex_class; | ||
| 99 | { | ||
| 100 | ASN1_CTX c; | ||
| 101 | STACK *ret=NULL; | ||
| 102 | |||
| 103 | if ((a == NULL) || ((*a) == NULL)) | ||
| 104 | { if ((ret=sk_new(NULL)) == NULL) goto err; } | ||
| 105 | else | ||
| 106 | ret=(*a); | ||
| 107 | |||
| 108 | c.p= *pp; | ||
| 109 | c.max=(length == 0)?0:(c.p+length); | ||
| 110 | |||
| 111 | c.inf=ASN1_get_object(&c.p,&c.slen,&c.tag,&c.xclass,c.max-c.p); | ||
| 112 | if (c.inf & 0x80) goto err; | ||
| 113 | if (ex_class != c.xclass) | ||
| 114 | { | ||
| 115 | ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_BAD_CLASS); | ||
| 116 | goto err; | ||
| 117 | } | ||
| 118 | if (ex_tag != c.tag) | ||
| 119 | { | ||
| 120 | ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_BAD_TAG); | ||
| 121 | goto err; | ||
| 122 | } | ||
| 123 | if ((c.slen+c.p) > c.max) | ||
| 124 | { | ||
| 125 | ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_LENGTH_ERROR); | ||
| 126 | goto err; | ||
| 127 | } | ||
| 128 | /* check for infinite constructed - it can be as long | ||
| 129 | * as the amount of data passed to us */ | ||
| 130 | if (c.inf == (V_ASN1_CONSTRUCTED+1)) | ||
| 131 | c.slen=length+ *pp-c.p; | ||
| 132 | c.max=c.p+c.slen; | ||
| 133 | |||
| 134 | while (c.p < c.max) | ||
| 135 | { | ||
| 136 | char *s; | ||
| 137 | |||
| 138 | if (M_ASN1_D2I_end_sequence()) break; | ||
| 139 | if ((s=func(NULL,&c.p,c.slen,c.max-c.p)) == NULL) goto err; | ||
| 140 | if (!sk_push(ret,s)) goto err; | ||
| 141 | } | ||
| 142 | if (a != NULL) (*a)=ret; | ||
| 143 | *pp=c.p; | ||
| 144 | return(ret); | ||
| 145 | err: | ||
| 146 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) sk_free(ret); | ||
| 147 | return(NULL); | ||
| 148 | } | ||
| 149 | |||
diff --git a/src/lib/libcrypto/asn1/a_sign.c b/src/lib/libcrypto/asn1/a_sign.c new file mode 100644 index 0000000000..02188e68c4 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_sign.c | |||
| @@ -0,0 +1,147 @@ | |||
| 1 | /* crypto/asn1/a_sign.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 <time.h> | ||
| 61 | #include <sys/types.h> | ||
| 62 | #include <sys/stat.h> | ||
| 63 | |||
| 64 | #include "cryptlib.h" | ||
| 65 | #include "bn.h" | ||
| 66 | #include "evp.h" | ||
| 67 | #include "x509.h" | ||
| 68 | #include "objects.h" | ||
| 69 | #include "buffer.h" | ||
| 70 | #include "pem.h" | ||
| 71 | |||
| 72 | int ASN1_sign(i2d,algor1,algor2,signature,data,pkey,type) | ||
| 73 | int (*i2d)(); | ||
| 74 | X509_ALGOR *algor1; | ||
| 75 | X509_ALGOR *algor2; | ||
| 76 | ASN1_BIT_STRING *signature; | ||
| 77 | char *data; | ||
| 78 | EVP_PKEY *pkey; | ||
| 79 | EVP_MD *type; | ||
| 80 | { | ||
| 81 | EVP_MD_CTX ctx; | ||
| 82 | unsigned char *p,*buf_in=NULL,*buf_out=NULL; | ||
| 83 | int i,inl=0,outl=0,outll=0; | ||
| 84 | X509_ALGOR *a; | ||
| 85 | |||
| 86 | for (i=0; i<2; i++) | ||
| 87 | { | ||
| 88 | if (i == 0) | ||
| 89 | a=algor1; | ||
| 90 | else | ||
| 91 | a=algor2; | ||
| 92 | if (a == NULL) continue; | ||
| 93 | if ( (a->parameter == NULL) || | ||
| 94 | (a->parameter->type != V_ASN1_NULL)) | ||
| 95 | { | ||
| 96 | ASN1_TYPE_free(a->parameter); | ||
| 97 | if ((a->parameter=ASN1_TYPE_new()) == NULL) goto err; | ||
| 98 | a->parameter->type=V_ASN1_NULL; | ||
| 99 | } | ||
| 100 | ASN1_OBJECT_free(a->algorithm); | ||
| 101 | a->algorithm=OBJ_nid2obj(type->pkey_type); | ||
| 102 | if (a->algorithm == NULL) | ||
| 103 | { | ||
| 104 | ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_UNKNOWN_OBJECT_TYPE); | ||
| 105 | goto err; | ||
| 106 | } | ||
| 107 | if (a->algorithm->length == 0) | ||
| 108 | { | ||
| 109 | ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD); | ||
| 110 | goto err; | ||
| 111 | } | ||
| 112 | } | ||
| 113 | inl=i2d(data,NULL); | ||
| 114 | buf_in=(unsigned char *)Malloc((unsigned int)inl); | ||
| 115 | outll=outl=EVP_PKEY_size(pkey); | ||
| 116 | buf_out=(unsigned char *)Malloc((unsigned int)outl); | ||
| 117 | if ((buf_in == NULL) || (buf_out == NULL)) | ||
| 118 | { | ||
| 119 | outl=0; | ||
| 120 | ASN1err(ASN1_F_ASN1_SIGN,ERR_R_MALLOC_FAILURE); | ||
| 121 | goto err; | ||
| 122 | } | ||
| 123 | p=buf_in; | ||
| 124 | |||
| 125 | i2d(data,&p); | ||
| 126 | EVP_SignInit(&ctx,type); | ||
| 127 | EVP_SignUpdate(&ctx,(unsigned char *)buf_in,inl); | ||
| 128 | if (!EVP_SignFinal(&ctx,(unsigned char *)buf_out, | ||
| 129 | (unsigned int *)&outl,pkey)) | ||
| 130 | { | ||
| 131 | outl=0; | ||
| 132 | ASN1err(ASN1_F_ASN1_SIGN,ERR_R_EVP_LIB); | ||
| 133 | goto err; | ||
| 134 | } | ||
| 135 | if (signature->data != NULL) Free((char *)signature->data); | ||
| 136 | signature->data=buf_out; | ||
| 137 | buf_out=NULL; | ||
| 138 | signature->length=outl; | ||
| 139 | |||
| 140 | err: | ||
| 141 | memset(&ctx,0,sizeof(ctx)); | ||
| 142 | if (buf_in != NULL) | ||
| 143 | { memset((char *)buf_in,0,(unsigned int)inl); Free((char *)buf_in); } | ||
| 144 | if (buf_out != NULL) | ||
| 145 | { memset((char *)buf_out,0,outll); Free((char *)buf_out); } | ||
| 146 | return(outl); | ||
| 147 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_type.c b/src/lib/libcrypto/asn1/a_type.c new file mode 100644 index 0000000000..7c0004084c --- /dev/null +++ b/src/lib/libcrypto/asn1/a_type.c | |||
| @@ -0,0 +1,325 @@ | |||
| 1 | /* crypto/asn1/a_type.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 | |||
| 63 | /* ASN1err(ASN1_F_ASN1_TYPE_NEW,ASN1_R_ERROR_STACK); | ||
| 64 | * ASN1err(ASN1_F_D2I_ASN1_BYTES,ASN1_R_ERROR_STACK); | ||
| 65 | * ASN1err(ASN1_F_D2I_ASN1_BYTES,ASN1_R_WRONG_TAG); | ||
| 66 | * ASN1err(ASN1_F_ASN1_COLLATE_PRIMATIVE,ASN1_R_WRONG_TAG); | ||
| 67 | */ | ||
| 68 | |||
| 69 | #ifndef NOPROTO | ||
| 70 | static void ASN1_TYPE_component_free(ASN1_TYPE *a); | ||
| 71 | #else | ||
| 72 | static void ASN1_TYPE_component_free(); | ||
| 73 | #endif | ||
| 74 | |||
| 75 | int i2d_ASN1_TYPE(a,pp) | ||
| 76 | ASN1_TYPE *a; | ||
| 77 | unsigned char **pp; | ||
| 78 | { | ||
| 79 | int r=0; | ||
| 80 | |||
| 81 | if (a == NULL) return(0); | ||
| 82 | |||
| 83 | switch (a->type) | ||
| 84 | { | ||
| 85 | case V_ASN1_NULL: | ||
| 86 | if (pp != NULL) | ||
| 87 | ASN1_put_object(pp,0,0,V_ASN1_NULL,V_ASN1_UNIVERSAL); | ||
| 88 | r=2; | ||
| 89 | break; | ||
| 90 | case V_ASN1_INTEGER: | ||
| 91 | case V_ASN1_NEG_INTEGER: | ||
| 92 | r=i2d_ASN1_INTEGER(a->value.integer,pp); | ||
| 93 | break; | ||
| 94 | case V_ASN1_BIT_STRING: | ||
| 95 | r=i2d_ASN1_BIT_STRING(a->value.bit_string,pp); | ||
| 96 | break; | ||
| 97 | case V_ASN1_OCTET_STRING: | ||
| 98 | r=i2d_ASN1_OCTET_STRING(a->value.octet_string,pp); | ||
| 99 | break; | ||
| 100 | case V_ASN1_OBJECT: | ||
| 101 | r=i2d_ASN1_OBJECT(a->value.object,pp); | ||
| 102 | break; | ||
| 103 | case V_ASN1_PRINTABLESTRING: | ||
| 104 | r=M_i2d_ASN1_PRINTABLESTRING(a->value.printablestring,pp); | ||
| 105 | break; | ||
| 106 | case V_ASN1_T61STRING: | ||
| 107 | r=M_i2d_ASN1_T61STRING(a->value.t61string,pp); | ||
| 108 | break; | ||
| 109 | case V_ASN1_IA5STRING: | ||
| 110 | r=M_i2d_ASN1_IA5STRING(a->value.ia5string,pp); | ||
| 111 | break; | ||
| 112 | case V_ASN1_GENERALSTRING: | ||
| 113 | r=M_i2d_ASN1_GENERALSTRING(a->value.generalstring,pp); | ||
| 114 | break; | ||
| 115 | case V_ASN1_UNIVERSALSTRING: | ||
| 116 | r=M_i2d_ASN1_UNIVERSALSTRING(a->value.universalstring,pp); | ||
| 117 | break; | ||
| 118 | case V_ASN1_BMPSTRING: | ||
| 119 | r=M_i2d_ASN1_BMPSTRING(a->value.bmpstring,pp); | ||
| 120 | break; | ||
| 121 | case V_ASN1_UTCTIME: | ||
| 122 | r=i2d_ASN1_UTCTIME(a->value.utctime,pp); | ||
| 123 | break; | ||
| 124 | case V_ASN1_SET: | ||
| 125 | case V_ASN1_SEQUENCE: | ||
| 126 | if (a->value.set == NULL) | ||
| 127 | r=0; | ||
| 128 | else | ||
| 129 | { | ||
| 130 | r=a->value.set->length; | ||
| 131 | if (pp != NULL) | ||
| 132 | { | ||
| 133 | memcpy(*pp,a->value.set->data,r); | ||
| 134 | *pp+=r; | ||
| 135 | } | ||
| 136 | } | ||
| 137 | break; | ||
| 138 | } | ||
| 139 | return(r); | ||
| 140 | } | ||
| 141 | |||
| 142 | ASN1_TYPE *d2i_ASN1_TYPE(a,pp,length) | ||
| 143 | ASN1_TYPE **a; | ||
| 144 | unsigned char **pp; | ||
| 145 | long length; | ||
| 146 | { | ||
| 147 | ASN1_TYPE *ret=NULL; | ||
| 148 | unsigned char *q,*p,*max; | ||
| 149 | int inf,tag,xclass; | ||
| 150 | long len; | ||
| 151 | |||
| 152 | if ((a == NULL) || ((*a) == NULL)) | ||
| 153 | { | ||
| 154 | if ((ret=ASN1_TYPE_new()) == NULL) goto err; | ||
| 155 | } | ||
| 156 | else | ||
| 157 | ret=(*a); | ||
| 158 | |||
| 159 | p= *pp; | ||
| 160 | q=p; | ||
| 161 | max=(p+length); | ||
| 162 | |||
| 163 | inf=ASN1_get_object(&q,&len,&tag,&xclass,length); | ||
| 164 | if (inf & 0x80) goto err; | ||
| 165 | |||
| 166 | ASN1_TYPE_component_free(ret); | ||
| 167 | |||
| 168 | switch (tag) | ||
| 169 | { | ||
| 170 | case V_ASN1_NULL: | ||
| 171 | p=q; | ||
| 172 | ret->value.ptr=NULL; | ||
| 173 | break; | ||
| 174 | case V_ASN1_INTEGER: | ||
| 175 | if ((ret->value.integer= | ||
| 176 | d2i_ASN1_INTEGER(NULL,&p,max-p)) == NULL) | ||
| 177 | goto err; | ||
| 178 | break; | ||
| 179 | case V_ASN1_BIT_STRING: | ||
| 180 | if ((ret->value.bit_string= | ||
| 181 | d2i_ASN1_BIT_STRING(NULL,&p,max-p)) == NULL) | ||
| 182 | goto err; | ||
| 183 | break; | ||
| 184 | case V_ASN1_OCTET_STRING: | ||
| 185 | if ((ret->value.octet_string= | ||
| 186 | d2i_ASN1_OCTET_STRING(NULL,&p,max-p)) == NULL) | ||
| 187 | goto err; | ||
| 188 | break; | ||
| 189 | case V_ASN1_OBJECT: | ||
| 190 | if ((ret->value.object= | ||
| 191 | d2i_ASN1_OBJECT(NULL,&p,max-p)) == NULL) | ||
| 192 | goto err; | ||
| 193 | break; | ||
| 194 | case V_ASN1_PRINTABLESTRING: | ||
| 195 | if ((ret->value.printablestring= | ||
| 196 | d2i_ASN1_PRINTABLESTRING(NULL,&p,max-p)) == NULL) | ||
| 197 | goto err; | ||
| 198 | break; | ||
| 199 | case V_ASN1_T61STRING: | ||
| 200 | if ((ret->value.t61string= | ||
| 201 | M_d2i_ASN1_T61STRING(NULL,&p,max-p)) == NULL) | ||
| 202 | goto err; | ||
| 203 | break; | ||
| 204 | case V_ASN1_IA5STRING: | ||
| 205 | if ((ret->value.ia5string= | ||
| 206 | M_d2i_ASN1_IA5STRING(NULL,&p,max-p)) == NULL) | ||
| 207 | goto err; | ||
| 208 | break; | ||
| 209 | case V_ASN1_GENERALSTRING: | ||
| 210 | if ((ret->value.generalstring= | ||
| 211 | M_d2i_ASN1_GENERALSTRING(NULL,&p,max-p)) == NULL) | ||
| 212 | goto err; | ||
| 213 | break; | ||
| 214 | case V_ASN1_UNIVERSALSTRING: | ||
| 215 | if ((ret->value.universalstring= | ||
| 216 | M_d2i_ASN1_UNIVERSALSTRING(NULL,&p,max-p)) == NULL) | ||
| 217 | goto err; | ||
| 218 | break; | ||
| 219 | case V_ASN1_BMPSTRING: | ||
| 220 | if ((ret->value.bmpstring= | ||
| 221 | M_d2i_ASN1_BMPSTRING(NULL,&p,max-p)) == NULL) | ||
| 222 | goto err; | ||
| 223 | break; | ||
| 224 | case V_ASN1_UTCTIME: | ||
| 225 | if ((ret->value.utctime= | ||
| 226 | d2i_ASN1_UTCTIME(NULL,&p,max-p)) == NULL) | ||
| 227 | goto err; | ||
| 228 | break; | ||
| 229 | case V_ASN1_SET: | ||
| 230 | case V_ASN1_SEQUENCE: | ||
| 231 | /* Sets and sequences are left complete */ | ||
| 232 | if ((ret->value.set=ASN1_STRING_new()) == NULL) goto err; | ||
| 233 | ret->value.set->type=tag; | ||
| 234 | len+=(q-p); | ||
| 235 | if (!ASN1_STRING_set(ret->value.set,p,(int)len)) goto err; | ||
| 236 | p+=len; | ||
| 237 | break; | ||
| 238 | default: | ||
| 239 | ASN1err(ASN1_F_D2I_ASN1_TYPE,ASN1_R_BAD_TYPE); | ||
| 240 | goto err; | ||
| 241 | } | ||
| 242 | |||
| 243 | ret->type=tag; | ||
| 244 | if (a != NULL) (*a)=ret; | ||
| 245 | *pp=p; | ||
| 246 | return(ret); | ||
| 247 | err: | ||
| 248 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) ASN1_TYPE_free(ret); | ||
| 249 | return(NULL); | ||
| 250 | } | ||
| 251 | |||
| 252 | ASN1_TYPE *ASN1_TYPE_new() | ||
| 253 | { | ||
| 254 | ASN1_TYPE *ret=NULL; | ||
| 255 | |||
| 256 | M_ASN1_New_Malloc(ret,ASN1_TYPE); | ||
| 257 | ret->type= -1; | ||
| 258 | ret->value.ptr=NULL; | ||
| 259 | return(ret); | ||
| 260 | M_ASN1_New_Error(ASN1_F_ASN1_TYPE_NEW); | ||
| 261 | } | ||
| 262 | |||
| 263 | void ASN1_TYPE_free(a) | ||
| 264 | ASN1_TYPE *a; | ||
| 265 | { | ||
| 266 | if (a == NULL) return; | ||
| 267 | ASN1_TYPE_component_free(a); | ||
| 268 | Free((char *)(char *)a); | ||
| 269 | } | ||
| 270 | |||
| 271 | int ASN1_TYPE_get(a) | ||
| 272 | ASN1_TYPE *a; | ||
| 273 | { | ||
| 274 | if (a->value.ptr != NULL) | ||
| 275 | return(a->type); | ||
| 276 | else | ||
| 277 | return(0); | ||
| 278 | } | ||
| 279 | |||
| 280 | void ASN1_TYPE_set(a,type,value) | ||
| 281 | ASN1_TYPE *a; | ||
| 282 | int type; | ||
| 283 | char *value; | ||
| 284 | { | ||
| 285 | if (a->value.ptr != NULL) | ||
| 286 | ASN1_TYPE_component_free(a); | ||
| 287 | a->type=type; | ||
| 288 | a->value.ptr=value; | ||
| 289 | } | ||
| 290 | |||
| 291 | static void ASN1_TYPE_component_free(a) | ||
| 292 | ASN1_TYPE *a; | ||
| 293 | { | ||
| 294 | if (a == NULL) return; | ||
| 295 | |||
| 296 | if (a->value.ptr != NULL) | ||
| 297 | { | ||
| 298 | switch (a->type) | ||
| 299 | { | ||
| 300 | case V_ASN1_OBJECT: | ||
| 301 | ASN1_OBJECT_free(a->value.object); | ||
| 302 | break; | ||
| 303 | case V_ASN1_INTEGER: | ||
| 304 | case V_ASN1_NEG_INTEGER: | ||
| 305 | case V_ASN1_BIT_STRING: | ||
| 306 | case V_ASN1_OCTET_STRING: | ||
| 307 | case V_ASN1_PRINTABLESTRING: | ||
| 308 | case V_ASN1_T61STRING: | ||
| 309 | case V_ASN1_IA5STRING: | ||
| 310 | case V_ASN1_UNIVERSALSTRING: | ||
| 311 | case V_ASN1_GENERALSTRING: | ||
| 312 | case V_ASN1_UTCTIME: | ||
| 313 | case V_ASN1_SET: | ||
| 314 | case V_ASN1_SEQUENCE: | ||
| 315 | ASN1_STRING_free((ASN1_STRING *)a->value.ptr); | ||
| 316 | break; | ||
| 317 | default: | ||
| 318 | /* MEMORY LEAK */ | ||
| 319 | break; | ||
| 320 | } | ||
| 321 | a->type=0; | ||
| 322 | a->value.ptr=NULL; | ||
| 323 | } | ||
| 324 | } | ||
| 325 | |||
diff --git a/src/lib/libcrypto/asn1/a_verify.c b/src/lib/libcrypto/asn1/a_verify.c new file mode 100644 index 0000000000..03fc63dbef --- /dev/null +++ b/src/lib/libcrypto/asn1/a_verify.c | |||
| @@ -0,0 +1,121 @@ | |||
| 1 | /* crypto/asn1/a_verify.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 <time.h> | ||
| 61 | #include <sys/types.h> | ||
| 62 | #include <sys/stat.h> | ||
| 63 | |||
| 64 | #include "cryptlib.h" | ||
| 65 | #include "bn.h" | ||
| 66 | #include "x509.h" | ||
| 67 | #include "objects.h" | ||
| 68 | #include "buffer.h" | ||
| 69 | #include "evp.h" | ||
| 70 | #include "pem.h" | ||
| 71 | |||
| 72 | int ASN1_verify(i2d,a,signature,data,pkey) | ||
| 73 | int (*i2d)(); | ||
| 74 | X509_ALGOR *a; | ||
| 75 | ASN1_BIT_STRING *signature; | ||
| 76 | char *data; | ||
| 77 | EVP_PKEY *pkey; | ||
| 78 | { | ||
| 79 | EVP_MD_CTX ctx; | ||
| 80 | EVP_MD *type; | ||
| 81 | unsigned char *p,*buf_in=NULL; | ||
| 82 | int ret= -1,i,inl; | ||
| 83 | |||
| 84 | i=OBJ_obj2nid(a->algorithm); | ||
| 85 | type=EVP_get_digestbyname(OBJ_nid2sn(i)); | ||
| 86 | if (type == NULL) | ||
| 87 | { | ||
| 88 | ASN1err(ASN1_F_ASN1_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM); | ||
| 89 | goto err; | ||
| 90 | } | ||
| 91 | |||
| 92 | inl=i2d(data,NULL); | ||
| 93 | buf_in=(unsigned char *)Malloc((unsigned int)inl); | ||
| 94 | if (buf_in == NULL) | ||
| 95 | { | ||
| 96 | ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_MALLOC_FAILURE); | ||
| 97 | goto err; | ||
| 98 | } | ||
| 99 | p=buf_in; | ||
| 100 | |||
| 101 | i2d(data,&p); | ||
| 102 | EVP_VerifyInit(&ctx,type); | ||
| 103 | EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl); | ||
| 104 | |||
| 105 | memset(buf_in,0,(unsigned int)inl); | ||
| 106 | Free((char *)buf_in); | ||
| 107 | |||
| 108 | if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data, | ||
| 109 | (unsigned int)signature->length,pkey) <= 0) | ||
| 110 | { | ||
| 111 | ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB); | ||
| 112 | ret=0; | ||
| 113 | goto err; | ||
| 114 | } | ||
| 115 | /* we don't need to zero the 'ctx' because we just checked | ||
| 116 | * public information */ | ||
| 117 | /* memset(&ctx,0,sizeof(ctx)); */ | ||
| 118 | ret=1; | ||
| 119 | err: | ||
| 120 | return(ret); | ||
| 121 | } | ||
diff --git a/src/lib/libcrypto/asn1/asn1.h b/src/lib/libcrypto/asn1/asn1.h new file mode 100644 index 0000000000..9793db365d --- /dev/null +++ b/src/lib/libcrypto/asn1/asn1.h | |||
| @@ -0,0 +1,859 @@ | |||
| 1 | /* crypto/asn1/asn1.h */ | ||
| 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 | #ifndef HEADER_ASN1_H | ||
| 60 | #define HEADER_ASN1_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #include <time.h> | ||
| 67 | #include "bn.h" | ||
| 68 | #include "stack.h" | ||
| 69 | |||
| 70 | #define V_ASN1_UNIVERSAL 0x00 | ||
| 71 | #define V_ASN1_APPLICATION 0x40 | ||
| 72 | #define V_ASN1_CONTEXT_SPECIFIC 0x80 | ||
| 73 | #define V_ASN1_PRIVATE 0xc0 | ||
| 74 | |||
| 75 | #define V_ASN1_CONSTRUCTED 0x20 | ||
| 76 | #define V_ASN1_PRIMATIVE_TAG 0x1f | ||
| 77 | |||
| 78 | #define V_ASN1_APP_CHOOSE -2 /* let the recipent choose */ | ||
| 79 | |||
| 80 | #define V_ASN1_UNDEF -1 | ||
| 81 | #define V_ASN1_EOC 0 | ||
| 82 | #define V_ASN1_BOOLEAN 1 /**/ | ||
| 83 | #define V_ASN1_INTEGER 2 | ||
| 84 | #define V_ASN1_NEG_INTEGER (2+0x100) | ||
| 85 | #define V_ASN1_BIT_STRING 3 | ||
| 86 | #define V_ASN1_OCTET_STRING 4 | ||
| 87 | #define V_ASN1_NULL 5 | ||
| 88 | #define V_ASN1_OBJECT 6 | ||
| 89 | #define V_ASN1_OBJECT_DESCRIPTOR 7 | ||
| 90 | #define V_ASN1_EXTERNAL 8 | ||
| 91 | #define V_ASN1_REAL 9 | ||
| 92 | #define V_ASN1_ENUMERATED 10 /* microsoft weirdness */ | ||
| 93 | #define V_ASN1_SEQUENCE 16 | ||
| 94 | #define V_ASN1_SET 17 | ||
| 95 | #define V_ASN1_NUMERICSTRING 18 /**/ | ||
| 96 | #define V_ASN1_PRINTABLESTRING 19 | ||
| 97 | #define V_ASN1_T61STRING 20 | ||
| 98 | #define V_ASN1_TELETEXSTRING 20 /* alias */ | ||
| 99 | #define V_ASN1_VIDEOTEXSTRING 21 /**/ | ||
| 100 | #define V_ASN1_IA5STRING 22 | ||
| 101 | #define V_ASN1_UTCTIME 23 | ||
| 102 | #define V_ASN1_GENERALIZEDTIME 24 /**/ | ||
| 103 | #define V_ASN1_GRAPHICSTRING 25 /**/ | ||
| 104 | #define V_ASN1_ISO64STRING 26 /**/ | ||
| 105 | #define V_ASN1_VISIBLESTRING 26 /* alias */ | ||
| 106 | #define V_ASN1_GENERALSTRING 27 /**/ | ||
| 107 | #define V_ASN1_UNIVERSALSTRING 28 /**/ | ||
| 108 | #define V_ASN1_BMPSTRING 30 | ||
| 109 | |||
| 110 | /* For use with d2i_ASN1_type_bytes() */ | ||
| 111 | #define B_ASN1_NUMERICSTRING 0x0001 | ||
| 112 | #define B_ASN1_PRINTABLESTRING 0x0002 | ||
| 113 | #define B_ASN1_T61STRING 0x0004 | ||
| 114 | #define B_ASN1_VIDEOTEXSTRING 0x0008 | ||
| 115 | #define B_ASN1_IA5STRING 0x0010 | ||
| 116 | #define B_ASN1_GRAPHICSTRING 0x0020 | ||
| 117 | #define B_ASN1_ISO64STRING 0x0040 | ||
| 118 | #define B_ASN1_GENERALSTRING 0x0080 | ||
| 119 | #define B_ASN1_UNIVERSALSTRING 0x0100 | ||
| 120 | #define B_ASN1_OCTET_STRING 0x0200 | ||
| 121 | #define B_ASN1_BIT_STRING 0x0400 | ||
| 122 | #define B_ASN1_BMPSTRING 0x0800 | ||
| 123 | #define B_ASN1_UNKNOWN 0x1000 | ||
| 124 | |||
| 125 | #ifndef DEBUG | ||
| 126 | |||
| 127 | #define ASN1_INTEGER ASN1_STRING | ||
| 128 | #define ASN1_BIT_STRING ASN1_STRING | ||
| 129 | #define ASN1_OCTET_STRING ASN1_STRING | ||
| 130 | #define ASN1_PRINTABLESTRING ASN1_STRING | ||
| 131 | #define ASN1_T61STRING ASN1_STRING | ||
| 132 | #define ASN1_IA5STRING ASN1_STRING | ||
| 133 | #define ASN1_UTCTIME ASN1_STRING | ||
| 134 | #define ASN1_GENERALIZEDTIME ASN1_STRING | ||
| 135 | #define ASN1_GENERALSTRING ASN1_STRING | ||
| 136 | #define ASN1_UNIVERSALSTRING ASN1_STRING | ||
| 137 | #define ASN1_BMPSTRING ASN1_STRING | ||
| 138 | |||
| 139 | #else | ||
| 140 | |||
| 141 | typedef struct asn1_integer_st | ||
| 142 | { | ||
| 143 | int length; | ||
| 144 | int type; | ||
| 145 | unsigned char *data; | ||
| 146 | } ASN1_INTEGER; | ||
| 147 | |||
| 148 | typedef struct asn1_bit_string_st | ||
| 149 | { | ||
| 150 | int length; | ||
| 151 | int type; | ||
| 152 | unsigned char *data; | ||
| 153 | } ASN1_BIT_STRING; | ||
| 154 | |||
| 155 | typedef struct asn1_octet_string_st | ||
| 156 | { | ||
| 157 | int length; | ||
| 158 | int type; | ||
| 159 | unsigned char *data; | ||
| 160 | } ASN1_OCTET_STRING; | ||
| 161 | |||
| 162 | typedef struct asn1_printablestring_st | ||
| 163 | { | ||
| 164 | int length; | ||
| 165 | int type; | ||
| 166 | unsigned char *data; | ||
| 167 | } ASN1_PRINTABLESTRING; | ||
| 168 | |||
| 169 | typedef struct asn1_t61string_st | ||
| 170 | { | ||
| 171 | int length; | ||
| 172 | int type; | ||
| 173 | unsigned char *data; | ||
| 174 | } ASN1_T61STRING; | ||
| 175 | |||
| 176 | typedef struct asn1_ia5string_st | ||
| 177 | { | ||
| 178 | int length; | ||
| 179 | int type; | ||
| 180 | unsigned char *data; | ||
| 181 | } ASN1_IA5STRING; | ||
| 182 | |||
| 183 | typedef struct asn1_generalstring_st | ||
| 184 | { | ||
| 185 | int length; | ||
| 186 | int type; | ||
| 187 | unsigned char *data; | ||
| 188 | } ASN1_GENERALSTRING; | ||
| 189 | |||
| 190 | typedef struct asn1_universalstring_st | ||
| 191 | { | ||
| 192 | int length; | ||
| 193 | int type; | ||
| 194 | unsigned char *data; | ||
| 195 | } ASN1_UNIVERSALSTRING; | ||
| 196 | |||
| 197 | typedef struct asn1_bmpstring_st | ||
| 198 | { | ||
| 199 | int length; | ||
| 200 | int type; | ||
| 201 | unsigned char *data; | ||
| 202 | } ASN1_BMPSTRING; | ||
| 203 | |||
| 204 | typedef struct asn1_utctime_st | ||
| 205 | { | ||
| 206 | int length; | ||
| 207 | int type; | ||
| 208 | unsigned char *data; | ||
| 209 | } ASN1_UTCTIME; | ||
| 210 | |||
| 211 | typedef struct asn1_generalizedtime_st | ||
| 212 | { | ||
| 213 | int length; | ||
| 214 | int type; | ||
| 215 | unsigned char *data; | ||
| 216 | } ASN1_GENERALIZEDTIME; | ||
| 217 | |||
| 218 | #endif | ||
| 219 | |||
| 220 | typedef struct asn1_ctx_st | ||
| 221 | { | ||
| 222 | unsigned char *p;/* work char pointer */ | ||
| 223 | int eos; /* end of sequence read for indefinite encoding */ | ||
| 224 | int error; /* error code to use when returning an error */ | ||
| 225 | int inf; /* constructed if 0x20, indefinite is 0x21 */ | ||
| 226 | int tag; /* tag from last 'get object' */ | ||
| 227 | int xclass; /* class from last 'get object' */ | ||
| 228 | long slen; /* length of last 'get object' */ | ||
| 229 | unsigned char *max; /* largest value of p alowed */ | ||
| 230 | unsigned char *q;/* temporary variable */ | ||
| 231 | unsigned char **pp;/* variable */ | ||
| 232 | } ASN1_CTX; | ||
| 233 | |||
| 234 | /* These are used internally in the ASN1_OBJECT to keep track of | ||
| 235 | * whether the names and data need to be free()ed */ | ||
| 236 | #define ASN1_OBJECT_FLAG_DYNAMIC 0x01 /* internal use */ | ||
| 237 | #define ASN1_OBJECT_FLAG_CRITICAL 0x02 /* critical x509v3 object id */ | ||
| 238 | #define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04 /* internal use */ | ||
| 239 | #define ASN1_OBJECT_FLAG_DYNAMIC_DATA 0x08 /* internal use */ | ||
| 240 | typedef struct asn1_object_st | ||
| 241 | { | ||
| 242 | char *sn,*ln; | ||
| 243 | int nid; | ||
| 244 | int length; | ||
| 245 | unsigned char *data; | ||
| 246 | int flags; /* Should we free this one */ | ||
| 247 | } ASN1_OBJECT; | ||
| 248 | |||
| 249 | /* This is the base type that holds just about everything :-) */ | ||
| 250 | typedef struct asn1_string_st | ||
| 251 | { | ||
| 252 | int length; | ||
| 253 | int type; | ||
| 254 | unsigned char *data; | ||
| 255 | } ASN1_STRING; | ||
| 256 | |||
| 257 | typedef struct asn1_type_st | ||
| 258 | { | ||
| 259 | int type; | ||
| 260 | union { | ||
| 261 | char *ptr; | ||
| 262 | ASN1_STRING * asn1_string; | ||
| 263 | ASN1_OBJECT * object; | ||
| 264 | ASN1_INTEGER * integer; | ||
| 265 | ASN1_BIT_STRING * bit_string; | ||
| 266 | ASN1_OCTET_STRING * octet_string; | ||
| 267 | ASN1_PRINTABLESTRING * printablestring; | ||
| 268 | ASN1_T61STRING * t61string; | ||
| 269 | ASN1_IA5STRING * ia5string; | ||
| 270 | ASN1_GENERALSTRING * generalstring; | ||
| 271 | ASN1_BMPSTRING * bmpstring; | ||
| 272 | ASN1_UNIVERSALSTRING * universalstring; | ||
| 273 | ASN1_UTCTIME * utctime; | ||
| 274 | ASN1_GENERALIZEDTIME * generalizedtime; | ||
| 275 | /* set and sequence are left complete and still | ||
| 276 | * contain the set or sequence bytes */ | ||
| 277 | ASN1_STRING * set; | ||
| 278 | ASN1_STRING * sequence; | ||
| 279 | } value; | ||
| 280 | } ASN1_TYPE; | ||
| 281 | |||
| 282 | typedef struct asn1_method_st | ||
| 283 | { | ||
| 284 | int (*i2d)(); | ||
| 285 | char *(*d2i)(); | ||
| 286 | char *(*create)(); | ||
| 287 | void (*destroy)(); | ||
| 288 | } ASN1_METHOD; | ||
| 289 | |||
| 290 | /* This is used when parsing some Netscape objects */ | ||
| 291 | typedef struct asn1_header_st | ||
| 292 | { | ||
| 293 | ASN1_OCTET_STRING *header; | ||
| 294 | char *data; | ||
| 295 | ASN1_METHOD *meth; | ||
| 296 | } ASN1_HEADER; | ||
| 297 | |||
| 298 | #define ASN1_STRING_length(x) ((x)->length) | ||
| 299 | #define ASN1_STRING_type(x) ((x)->type) | ||
| 300 | #define ASN1_STRING_data(x) ((x)->data) | ||
| 301 | |||
| 302 | /* Macros for string operations */ | ||
| 303 | #define ASN1_BIT_STRING_new() (ASN1_BIT_STRING *)\ | ||
| 304 | ASN1_STRING_type_new(V_ASN1_BIT_STRING) | ||
| 305 | #define ASN1_BIT_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 306 | #define ASN1_BIT_STRING_dup(a) (ASN1_BIT_STRING *)\ | ||
| 307 | ASN1_STRING_dup((ASN1_STRING *)a) | ||
| 308 | #define ASN1_BIT_STRING_cmp(a,b) ASN1_STRING_cmp(\ | ||
| 309 | (ASN1_STRING *)a,(ASN1_STRING *)b) | ||
| 310 | #define ASN1_BIT_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c) | ||
| 311 | /* i2d_ASN1_BIT_STRING() is a function */ | ||
| 312 | /* d2i_ASN1_BIT_STRING() is a function */ | ||
| 313 | |||
| 314 | #define ASN1_INTEGER_new() (ASN1_INTEGER *)\ | ||
| 315 | ASN1_STRING_type_new(V_ASN1_INTEGER) | ||
| 316 | #define ASN1_INTEGER_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 317 | #define ASN1_INTEGER_dup(a) (ASN1_INTEGER *)ASN1_STRING_dup((ASN1_STRING *)a) | ||
| 318 | #define ASN1_INTEGER_cmp(a,b) ASN1_STRING_cmp(\ | ||
| 319 | (ASN1_STRING *)a,(ASN1_STRING *)b) | ||
| 320 | /* ASN1_INTEGER_set() is a function, also see BN_to_ASN1_INTEGER() */ | ||
| 321 | /* ASN1_INTEGER_get() is a function, also see ASN1_INTEGER_to_BN() */ | ||
| 322 | /* i2d_ASN1_INTEGER() is a function */ | ||
| 323 | /* d2i_ASN1_INTEGER() is a function */ | ||
| 324 | |||
| 325 | #define ASN1_OCTET_STRING_new() (ASN1_OCTET_STRING *)\ | ||
| 326 | ASN1_STRING_type_new(V_ASN1_OCTET_STRING) | ||
| 327 | #define ASN1_OCTET_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 328 | #define ASN1_OCTET_STRING_dup(a) (ASN1_OCTET_STRING *)\ | ||
| 329 | ASN1_STRING_dup((ASN1_STRING *)a) | ||
| 330 | #define ASN1_OCTET_STRING_cmp(a,b) ASN1_STRING_cmp(\ | ||
| 331 | (ASN1_STRING *)a,(ASN1_STRING *)b) | ||
| 332 | #define ASN1_OCTET_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c) | ||
| 333 | #define ASN1_OCTET_STRING_print(a,b) ASN1_STRING_print(a,(ASN1_STRING *)b) | ||
| 334 | #define M_i2d_ASN1_OCTET_STRING(a,pp) \ | ||
| 335 | i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_OCTET_STRING,\ | ||
| 336 | V_ASN1_OCTET_STRING) | ||
| 337 | /* d2i_ASN1_OCTET_STRING() is a function */ | ||
| 338 | |||
| 339 | #define ASN1_PRINTABLE_new() ASN1_STRING_type_new(V_ASN1_T61STRING) | ||
| 340 | #define ASN1_PRINTABLE_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 341 | #define M_i2d_ASN1_PRINTABLE(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\ | ||
| 342 | pp,a->type,V_ASN1_UNIVERSAL) | ||
| 343 | #define M_d2i_ASN1_PRINTABLE(a,pp,l) \ | ||
| 344 | d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \ | ||
| 345 | B_ASN1_PRINTABLESTRING| \ | ||
| 346 | B_ASN1_T61STRING| \ | ||
| 347 | B_ASN1_IA5STRING| \ | ||
| 348 | B_ASN1_BIT_STRING| \ | ||
| 349 | B_ASN1_UNIVERSALSTRING|\ | ||
| 350 | B_ASN1_BMPSTRING|\ | ||
| 351 | B_ASN1_UNKNOWN) | ||
| 352 | |||
| 353 | #define ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING_STRING *)\ | ||
| 354 | ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING) | ||
| 355 | #define ASN1_PRINTABLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 356 | #define M_i2d_ASN1_PRINTABLESTRING(a,pp) \ | ||
| 357 | i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_PRINTABLESTRING,\ | ||
| 358 | V_ASN1_UNIVERSAL) | ||
| 359 | #define M_d2i_ASN1_PRINTABLESTRING(a,pp,l) \ | ||
| 360 | (ASN1_PRINTABLESTRING *)d2i_ASN1_type_bytes\ | ||
| 361 | ((ASN1_STRING **)a,pp,l,B_ASN1_PRINTABLESTRING) | ||
| 362 | |||
| 363 | #define ASN1_T61STRING_new() (ASN1_T61STRING_STRING *)\ | ||
| 364 | ASN1_STRING_type_new(V_ASN1_T61STRING) | ||
| 365 | #define ASN1_T61STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 366 | #define M_i2d_ASN1_T61STRING(a,pp) \ | ||
| 367 | i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_T61STRING,\ | ||
| 368 | V_ASN1_UNIVERSAL) | ||
| 369 | #define M_d2i_ASN1_T61STRING(a,pp,l) \ | ||
| 370 | (ASN1_T61STRING *)d2i_ASN1_type_bytes\ | ||
| 371 | ((ASN1_STRING **)a,pp,l,B_ASN1_T61STRING) | ||
| 372 | |||
| 373 | #define ASN1_IA5STRING_new() (ASN1_IA5STRING *)\ | ||
| 374 | ASN1_STRING_type_new(V_ASN1_IA5STRING) | ||
| 375 | #define ASN1_IA5STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 376 | #define M_i2d_ASN1_IA5STRING(a,pp) \ | ||
| 377 | i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\ | ||
| 378 | V_ASN1_UNIVERSAL) | ||
| 379 | #define M_d2i_ASN1_IA5STRING(a,pp,l) \ | ||
| 380 | (ASN1_IA5STRING *)d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l,\ | ||
| 381 | B_ASN1_IA5STRING) | ||
| 382 | |||
| 383 | #define ASN1_UTCTIME_new() (ASN1_UTCTIME *)\ | ||
| 384 | ASN1_STRING_type_new(V_ASN1_UTCTIME) | ||
| 385 | #define ASN1_UTCTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 386 | #define ASN1_UTCTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup((ASN1_STRING *)a) | ||
| 387 | /* i2d_ASN1_UTCTIME() is a function */ | ||
| 388 | /* d2i_ASN1_UTCTIME() is a function */ | ||
| 389 | /* ASN1_UTCTIME_set() is a function */ | ||
| 390 | /* ASN1_UTCTIME_check() is a function */ | ||
| 391 | |||
| 392 | #define ASN1_GENERALIZEDTIME_new() (ASN1_GENERALIZEDTIME *)\ | ||
| 393 | ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME) | ||
| 394 | #define ASN1_GENERALIZEDTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 395 | #define ASN1_GENERALIZEDTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup(\ | ||
| 396 | (ASN1_STRING *)a) | ||
| 397 | /* DOES NOT EXIST YET i2d_ASN1_GENERALIZEDTIME() is a function */ | ||
| 398 | /* DOES NOT EXIST YET d2i_ASN1_GENERALIZEDTIME() is a function */ | ||
| 399 | /* DOES NOT EXIST YET ASN1_GENERALIZEDTIME_set() is a function */ | ||
| 400 | /* DOES NOT EXIST YET ASN1_GENERALIZEDTIME_check() is a function */ | ||
| 401 | |||
| 402 | #define ASN1_GENERALSTRING_new() (ASN1_GENERALSTRING *)\ | ||
| 403 | ASN1_STRING_type_new(V_ASN1_GENERALSTRING) | ||
| 404 | #define ASN1_GENERALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 405 | #define M_i2d_ASN1_GENERALSTRING(a,pp) \ | ||
| 406 | i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_GENERALSTRING,\ | ||
| 407 | V_ASN1_UNIVERSAL) | ||
| 408 | #define M_d2i_ASN1_GENERALSTRING(a,pp,l) \ | ||
| 409 | (ASN1_GENERALSTRING *)d2i_ASN1_type_bytes\ | ||
| 410 | ((ASN1_STRING **)a,pp,l,B_ASN1_GENERALSTRING) | ||
| 411 | |||
| 412 | #define ASN1_UNIVERSALSTRING_new() (ASN1_UNIVERSALSTRING *)\ | ||
| 413 | ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING) | ||
| 414 | #define ASN1_UNIVERSALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 415 | #define M_i2d_ASN1_UNIVERSALSTRING(a,pp) \ | ||
| 416 | i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UNIVERSALSTRING,\ | ||
| 417 | V_ASN1_UNIVERSAL) | ||
| 418 | #define M_d2i_ASN1_UNIVERSALSTRING(a,pp,l) \ | ||
| 419 | (ASN1_UNIVERSALSTRING *)d2i_ASN1_type_bytes\ | ||
| 420 | ((ASN1_STRING **)a,pp,l,B_ASN1_UNIVERSALSTRING) | ||
| 421 | |||
| 422 | #define ASN1_BMPSTRING_new() (ASN1_BMPSTRING *)\ | ||
| 423 | ASN1_STRING_type_new(V_ASN1_BMPSTRING) | ||
| 424 | #define ASN1_BMPSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
| 425 | #define M_i2d_ASN1_BMPSTRING(a,pp) \ | ||
| 426 | i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_BMPSTRING,\ | ||
| 427 | V_ASN1_UNIVERSAL) | ||
| 428 | #define M_d2i_ASN1_BMPSTRING(a,pp,l) \ | ||
| 429 | (ASN1_BMPSTRING *)d2i_ASN1_type_bytes\ | ||
| 430 | ((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING) | ||
| 431 | |||
| 432 | #ifndef NOPROTO | ||
| 433 | ASN1_TYPE * ASN1_TYPE_new(void ); | ||
| 434 | void ASN1_TYPE_free(ASN1_TYPE *a); | ||
| 435 | int i2d_ASN1_TYPE(ASN1_TYPE *a,unsigned char **pp); | ||
| 436 | ASN1_TYPE * d2i_ASN1_TYPE(ASN1_TYPE **a,unsigned char **pp,long length); | ||
| 437 | int ASN1_TYPE_get(ASN1_TYPE *a); | ||
| 438 | void ASN1_TYPE_set(ASN1_TYPE *a, int type, char *value); | ||
| 439 | |||
| 440 | ASN1_OBJECT * ASN1_OBJECT_new(void ); | ||
| 441 | void ASN1_OBJECT_free(ASN1_OBJECT *a); | ||
| 442 | int i2d_ASN1_OBJECT(ASN1_OBJECT *a,unsigned char **pp); | ||
| 443 | ASN1_OBJECT * d2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp, | ||
| 444 | long length); | ||
| 445 | |||
| 446 | ASN1_STRING * ASN1_STRING_new(void ); | ||
| 447 | void ASN1_STRING_free(ASN1_STRING *a); | ||
| 448 | ASN1_STRING * ASN1_STRING_dup(ASN1_STRING *a); | ||
| 449 | ASN1_STRING * ASN1_STRING_type_new(int type ); | ||
| 450 | int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b); | ||
| 451 | int ASN1_STRING_set(ASN1_STRING *str,unsigned char *data, int len); | ||
| 452 | |||
| 453 | int i2d_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp); | ||
| 454 | ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,unsigned char **pp, | ||
| 455 | long length); | ||
| 456 | int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value); | ||
| 457 | int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n); | ||
| 458 | |||
| 459 | |||
| 460 | int i2d_ASN1_BOOLEAN(int a,unsigned char **pp); | ||
| 461 | int d2i_ASN1_BOOLEAN(int *a,unsigned char **pp,long length); | ||
| 462 | |||
| 463 | int i2d_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp); | ||
| 464 | ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp, | ||
| 465 | long length); | ||
| 466 | |||
| 467 | int ASN1_UTCTIME_check(ASN1_UTCTIME *a); | ||
| 468 | ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s,time_t t); | ||
| 469 | int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, char *str); | ||
| 470 | |||
| 471 | int i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a,unsigned char **pp); | ||
| 472 | ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(ASN1_OCTET_STRING **a, | ||
| 473 | unsigned char **pp,long length); | ||
| 474 | |||
| 475 | int i2d_ASN1_PRINTABLE(ASN1_STRING *a,unsigned char **pp); | ||
| 476 | ASN1_STRING *d2i_ASN1_PRINTABLE(ASN1_STRING **a, | ||
| 477 | unsigned char **pp, long l); | ||
| 478 | ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING **a, | ||
| 479 | unsigned char **pp, long l); | ||
| 480 | |||
| 481 | ASN1_T61STRING *d2i_ASN1_T61STRING(ASN1_T61STRING **a, | ||
| 482 | unsigned char **pp, long l); | ||
| 483 | int i2d_ASN1_IA5STRING(ASN1_IA5STRING *a,unsigned char **pp); | ||
| 484 | ASN1_IA5STRING *d2i_ASN1_IA5STRING(ASN1_IA5STRING **a, | ||
| 485 | unsigned char **pp, long l); | ||
| 486 | |||
| 487 | int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a,unsigned char **pp); | ||
| 488 | ASN1_UTCTIME * d2i_ASN1_UTCTIME(ASN1_UTCTIME **a,unsigned char **pp, | ||
| 489 | long length); | ||
| 490 | |||
| 491 | int i2d_ASN1_SET(STACK *a, unsigned char **pp, | ||
| 492 | int (*func)(), int ex_tag, int ex_class); | ||
| 493 | STACK * d2i_ASN1_SET(STACK **a, unsigned char **pp, long length, | ||
| 494 | char *(*func)(), int ex_tag, int ex_class); | ||
| 495 | |||
| 496 | #ifdef HEADER_BIO_H | ||
| 497 | int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a); | ||
| 498 | int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size); | ||
| 499 | int i2a_ASN1_OBJECT(BIO *bp,ASN1_OBJECT *a); | ||
| 500 | int a2i_ASN1_STRING(BIO *bp,ASN1_STRING *bs,char *buf,int size); | ||
| 501 | int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type); | ||
| 502 | #endif | ||
| 503 | int i2t_ASN1_OBJECT(char *buf,int buf_len,ASN1_OBJECT *a); | ||
| 504 | |||
| 505 | int a2d_ASN1_OBJECT(unsigned char *out,int olen, char *buf, int num); | ||
| 506 | ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data,int len, | ||
| 507 | char *sn, char *ln); | ||
| 508 | |||
| 509 | int ASN1_INTEGER_set(ASN1_INTEGER *a, long v); | ||
| 510 | long ASN1_INTEGER_get(ASN1_INTEGER *a); | ||
| 511 | ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai); | ||
| 512 | BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn); | ||
| 513 | |||
| 514 | /* General */ | ||
| 515 | /* given a string, return the correct type, max is the maximum length */ | ||
| 516 | int ASN1_PRINTABLE_type(unsigned char *s, int max); | ||
| 517 | |||
| 518 | int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass); | ||
| 519 | ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp, | ||
| 520 | long length, int Ptag, int Pclass); | ||
| 521 | /* type is one or more of the B_ASN1_ values. */ | ||
| 522 | ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a,unsigned char **pp, | ||
| 523 | long length,int type); | ||
| 524 | |||
| 525 | /* PARSING */ | ||
| 526 | int asn1_Finish(ASN1_CTX *c); | ||
| 527 | |||
| 528 | /* SPECIALS */ | ||
| 529 | int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, | ||
| 530 | int *pclass, long omax); | ||
| 531 | int ASN1_check_infinite_end(unsigned char **p,long len); | ||
| 532 | void ASN1_put_object(unsigned char **pp, int constructed, int length, | ||
| 533 | int tag, int xclass); | ||
| 534 | int ASN1_object_size(int constructed, int length, int tag); | ||
| 535 | |||
| 536 | /* Used to implement other functions */ | ||
| 537 | char *ASN1_dup(int (*i2d)(),char *(*d2i)(),char *x); | ||
| 538 | |||
| 539 | #ifndef NO_FP_API | ||
| 540 | char *ASN1_d2i_fp(char *(*xnew)(),char *(*d2i)(),FILE *fp,unsigned char **x); | ||
| 541 | int ASN1_i2d_fp(int (*i2d)(),FILE *out,unsigned char *x); | ||
| 542 | #endif | ||
| 543 | |||
| 544 | #ifdef HEADER_BIO_H | ||
| 545 | char *ASN1_d2i_bio(char *(*xnew)(),char *(*d2i)(),BIO *bp,unsigned char **x); | ||
| 546 | int ASN1_i2d_bio(int (*i2d)(),BIO *out,unsigned char *x); | ||
| 547 | int ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a); | ||
| 548 | int ASN1_STRING_print(BIO *bp,ASN1_STRING *v); | ||
| 549 | int ASN1_parse(BIO *bp,unsigned char *pp,long len,int indent); | ||
| 550 | #endif | ||
| 551 | |||
| 552 | /* Used to load and write netscape format cert/key */ | ||
| 553 | int i2d_ASN1_HEADER(ASN1_HEADER *a,unsigned char **pp); | ||
| 554 | ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a,unsigned char **pp, long length); | ||
| 555 | ASN1_HEADER *ASN1_HEADER_new(void ); | ||
| 556 | void ASN1_HEADER_free(ASN1_HEADER *a); | ||
| 557 | |||
| 558 | int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s); | ||
| 559 | |||
| 560 | void ERR_load_ASN1_strings(void); | ||
| 561 | |||
| 562 | /* Not used that much at this point, except for the first two */ | ||
| 563 | ASN1_METHOD *X509_asn1_meth(void); | ||
| 564 | ASN1_METHOD *RSAPrivateKey_asn1_meth(void); | ||
| 565 | ASN1_METHOD *ASN1_IA5STRING_asn1_meth(void); | ||
| 566 | ASN1_METHOD *ASN1_BIT_STRING_asn1_meth(void); | ||
| 567 | |||
| 568 | int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, | ||
| 569 | unsigned char *data, int len); | ||
| 570 | int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, | ||
| 571 | unsigned char *data, int max_len); | ||
| 572 | int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, | ||
| 573 | unsigned char *data, int len); | ||
| 574 | int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num, | ||
| 575 | unsigned char *data, int max_len); | ||
| 576 | |||
| 577 | #else | ||
| 578 | |||
| 579 | ASN1_TYPE * ASN1_TYPE_new(); | ||
| 580 | void ASN1_TYPE_free(); | ||
| 581 | int i2d_ASN1_TYPE(); | ||
| 582 | ASN1_TYPE * d2i_ASN1_TYPE(); | ||
| 583 | int ASN1_TYPE_get(); | ||
| 584 | void ASN1_TYPE_set(); | ||
| 585 | |||
| 586 | ASN1_OBJECT * ASN1_OBJECT_new(); | ||
| 587 | void ASN1_OBJECT_free(); | ||
| 588 | int i2d_ASN1_OBJECT(); | ||
| 589 | ASN1_OBJECT * d2i_ASN1_OBJECT(); | ||
| 590 | ASN1_STRING * ASN1_STRING_new(); | ||
| 591 | void ASN1_STRING_free(); | ||
| 592 | ASN1_STRING * ASN1_STRING_dup(); | ||
| 593 | ASN1_STRING * ASN1_STRING_type_new(); | ||
| 594 | int ASN1_STRING_cmp(); | ||
| 595 | int ASN1_STRING_set(); | ||
| 596 | int i2d_ASN1_BIT_STRING(); | ||
| 597 | ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(); | ||
| 598 | int ASN1_BIT_STRING_set_bit(); | ||
| 599 | int ASN1_BIT_STRING_get_bit(); | ||
| 600 | int i2d_ASN1_BOOLEAN(); | ||
| 601 | int d2i_ASN1_BOOLEAN(); | ||
| 602 | int i2d_ASN1_INTEGER(); | ||
| 603 | ASN1_INTEGER *d2i_ASN1_INTEGER(); | ||
| 604 | int ASN1_UTCTIME_check(); | ||
| 605 | ASN1_UTCTIME *ASN1_UTCTIME_set(); | ||
| 606 | int ASN1_UTCTIME_set_string(); | ||
| 607 | int i2d_ASN1_OCTET_STRING(); | ||
| 608 | ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(); | ||
| 609 | int i2d_ASN1_PRINTABLE(); | ||
| 610 | ASN1_STRING *d2i_ASN1_PRINTABLE(); | ||
| 611 | ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING(); | ||
| 612 | ASN1_T61STRING *d2i_ASN1_T61STRING(); | ||
| 613 | int i2d_ASN1_IA5STRING(); | ||
| 614 | ASN1_IA5STRING *d2i_ASN1_IA5STRING(); | ||
| 615 | int i2d_ASN1_UTCTIME(); | ||
| 616 | ASN1_UTCTIME * d2i_ASN1_UTCTIME(); | ||
| 617 | int i2d_ASN1_SET(); | ||
| 618 | STACK * d2i_ASN1_SET(); | ||
| 619 | int a2d_ASN1_OBJECT(); | ||
| 620 | ASN1_OBJECT *ASN1_OBJECT_create(); | ||
| 621 | int ASN1_INTEGER_set(); | ||
| 622 | long ASN1_INTEGER_get(); | ||
| 623 | ASN1_INTEGER *BN_to_ASN1_INTEGER(); | ||
| 624 | BIGNUM *ASN1_INTEGER_to_BN(); | ||
| 625 | int ASN1_PRINTABLE_type(); | ||
| 626 | int i2d_ASN1_bytes(); | ||
| 627 | ASN1_STRING *d2i_ASN1_bytes(); | ||
| 628 | ASN1_STRING *d2i_ASN1_type_bytes(); | ||
| 629 | int asn1_Finish(); | ||
| 630 | int ASN1_get_object(); | ||
| 631 | int ASN1_check_infinite_end(); | ||
| 632 | void ASN1_put_object(); | ||
| 633 | int ASN1_object_size(); | ||
| 634 | char *ASN1_dup(); | ||
| 635 | #ifndef NO_FP_API | ||
| 636 | char *ASN1_d2i_fp(); | ||
| 637 | int ASN1_i2d_fp(); | ||
| 638 | #endif | ||
| 639 | |||
| 640 | char *ASN1_d2i_bio(); | ||
| 641 | int ASN1_i2d_bio(); | ||
| 642 | int ASN1_UTCTIME_print(); | ||
| 643 | int ASN1_STRING_print(); | ||
| 644 | int ASN1_parse(); | ||
| 645 | int i2a_ASN1_INTEGER(); | ||
| 646 | int a2i_ASN1_INTEGER(); | ||
| 647 | int i2a_ASN1_OBJECT(); | ||
| 648 | int i2t_ASN1_OBJECT(); | ||
| 649 | int a2i_ASN1_STRING(); | ||
| 650 | int i2a_ASN1_STRING(); | ||
| 651 | |||
| 652 | int i2d_ASN1_HEADER(); | ||
| 653 | ASN1_HEADER *d2i_ASN1_HEADER(); | ||
| 654 | ASN1_HEADER *ASN1_HEADER_new(); | ||
| 655 | void ASN1_HEADER_free(); | ||
| 656 | void ERR_load_ASN1_strings(); | ||
| 657 | ASN1_METHOD *X509_asn1_meth(); | ||
| 658 | ASN1_METHOD *RSAPrivateKey_asn1_meth(); | ||
| 659 | ASN1_METHOD *ASN1_IA5STRING_asn1_meth(); | ||
| 660 | ASN1_METHOD *ASN1_BIT_STRING_asn1_meth(); | ||
| 661 | |||
| 662 | int ASN1_UNIVERSALSTRING_to_string(); | ||
| 663 | |||
| 664 | int ASN1_TYPE_set_octetstring(); | ||
| 665 | int ASN1_TYPE_get_octetstring(); | ||
| 666 | int ASN1_TYPE_set_int_octetstring(); | ||
| 667 | int ASN1_TYPE_get_int_octetstring(); | ||
| 668 | |||
| 669 | #endif | ||
| 670 | |||
| 671 | /* BEGIN ERROR CODES */ | ||
| 672 | /* Error codes for the ASN1 functions. */ | ||
| 673 | |||
| 674 | /* Function codes. */ | ||
| 675 | #define ASN1_F_A2D_ASN1_OBJECT 100 | ||
| 676 | #define ASN1_F_A2I_ASN1_INTEGER 101 | ||
| 677 | #define ASN1_F_A2I_ASN1_STRING 102 | ||
| 678 | #define ASN1_F_ASN1_COLLATE_PRIMATIVE 103 | ||
| 679 | #define ASN1_F_ASN1_D2I_BIO 104 | ||
| 680 | #define ASN1_F_ASN1_D2I_FP 105 | ||
| 681 | #define ASN1_F_ASN1_DUP 106 | ||
| 682 | #define ASN1_F_ASN1_GET_OBJECT 107 | ||
| 683 | #define ASN1_F_ASN1_HEADER_NEW 108 | ||
| 684 | #define ASN1_F_ASN1_I2D_BIO 109 | ||
| 685 | #define ASN1_F_ASN1_I2D_FP 110 | ||
| 686 | #define ASN1_F_ASN1_INTEGER_SET 111 | ||
| 687 | #define ASN1_F_ASN1_INTEGER_TO_BN 112 | ||
| 688 | #define ASN1_F_ASN1_OBJECT_NEW 113 | ||
| 689 | #define ASN1_F_ASN1_SIGN 114 | ||
| 690 | #define ASN1_F_ASN1_STRING_NEW 115 | ||
| 691 | #define ASN1_F_ASN1_STRING_TYPE_NEW 116 | ||
| 692 | #define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 117 | ||
| 693 | #define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 118 | ||
| 694 | #define ASN1_F_ASN1_TYPE_NEW 119 | ||
| 695 | #define ASN1_F_ASN1_UTCTIME_NEW 120 | ||
| 696 | #define ASN1_F_ASN1_VERIFY 121 | ||
| 697 | #define ASN1_F_BN_TO_ASN1_INTEGER 122 | ||
| 698 | #define ASN1_F_D2I_ASN1_BIT_STRING 123 | ||
| 699 | #define ASN1_F_D2I_ASN1_BMPSTRING 124 | ||
| 700 | #define ASN1_F_D2I_ASN1_BOOLEAN 125 | ||
| 701 | #define ASN1_F_D2I_ASN1_BYTES 126 | ||
| 702 | #define ASN1_F_D2I_ASN1_HEADER 127 | ||
| 703 | #define ASN1_F_D2I_ASN1_INTEGER 128 | ||
| 704 | #define ASN1_F_D2I_ASN1_OBJECT 129 | ||
| 705 | #define ASN1_F_D2I_ASN1_OCTET_STRING 130 | ||
| 706 | #define ASN1_F_D2I_ASN1_PRINT_TYPE 131 | ||
| 707 | #define ASN1_F_D2I_ASN1_SET 132 | ||
| 708 | #define ASN1_F_D2I_ASN1_TYPE 133 | ||
| 709 | #define ASN1_F_D2I_ASN1_TYPE_BYTES 134 | ||
| 710 | #define ASN1_F_D2I_ASN1_UTCTIME 135 | ||
| 711 | #define ASN1_F_D2I_DHPARAMS 136 | ||
| 712 | #define ASN1_F_D2I_DSAPARAMS 137 | ||
| 713 | #define ASN1_F_D2I_DSAPRIVATEKEY 138 | ||
| 714 | #define ASN1_F_D2I_DSAPUBLICKEY 139 | ||
| 715 | #define ASN1_F_D2I_NETSCAPE_PKEY 140 | ||
| 716 | #define ASN1_F_D2I_NETSCAPE_RSA 141 | ||
| 717 | #define ASN1_F_D2I_NETSCAPE_RSA_2 142 | ||
| 718 | #define ASN1_F_D2I_NETSCAPE_SPKAC 143 | ||
| 719 | #define ASN1_F_D2I_NETSCAPE_SPKI 144 | ||
| 720 | #define ASN1_F_D2I_PKCS7 145 | ||
| 721 | #define ASN1_F_D2I_PKCS7_DIGEST 146 | ||
| 722 | #define ASN1_F_D2I_PKCS7_ENCRYPT 147 | ||
| 723 | #define ASN1_F_D2I_PKCS7_ENC_CONTENT 148 | ||
| 724 | #define ASN1_F_D2I_PKCS7_ENVELOPE 149 | ||
| 725 | #define ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL 150 | ||
| 726 | #define ASN1_F_D2I_PKCS7_RECIP_INFO 151 | ||
| 727 | #define ASN1_F_D2I_PKCS7_SIGNED 152 | ||
| 728 | #define ASN1_F_D2I_PKCS7_SIGNER_INFO 153 | ||
| 729 | #define ASN1_F_D2I_PKCS7_SIGN_ENVELOPE 154 | ||
| 730 | #define ASN1_F_D2I_PRIVATEKEY 155 | ||
| 731 | #define ASN1_F_D2I_PUBLICKEY 156 | ||
| 732 | #define ASN1_F_D2I_RSAPRIVATEKEY 157 | ||
| 733 | #define ASN1_F_D2I_RSAPUBLICKEY 158 | ||
| 734 | #define ASN1_F_D2I_X509 159 | ||
| 735 | #define ASN1_F_D2I_X509_ALGOR 160 | ||
| 736 | #define ASN1_F_D2I_X509_ATTRIBUTE 161 | ||
| 737 | #define ASN1_F_D2I_X509_CINF 162 | ||
| 738 | #define ASN1_F_D2I_X509_CRL 163 | ||
| 739 | #define ASN1_F_D2I_X509_CRL_INFO 164 | ||
| 740 | #define ASN1_F_D2I_X509_EXTENSION 165 | ||
| 741 | #define ASN1_F_D2I_X509_KEY 166 | ||
| 742 | #define ASN1_F_D2I_X509_NAME 167 | ||
| 743 | #define ASN1_F_D2I_X509_NAME_ENTRY 168 | ||
| 744 | #define ASN1_F_D2I_X509_PKEY 169 | ||
| 745 | #define ASN1_F_D2I_X509_PUBKEY 170 | ||
| 746 | #define ASN1_F_D2I_X509_REQ 171 | ||
| 747 | #define ASN1_F_D2I_X509_REQ_INFO 172 | ||
| 748 | #define ASN1_F_D2I_X509_REVOKED 173 | ||
| 749 | #define ASN1_F_D2I_X509_SIG 174 | ||
| 750 | #define ASN1_F_D2I_X509_VAL 175 | ||
| 751 | #define ASN1_F_I2D_ASN1_HEADER 176 | ||
| 752 | #define ASN1_F_I2D_DHPARAMS 177 | ||
| 753 | #define ASN1_F_I2D_DSAPARAMS 178 | ||
| 754 | #define ASN1_F_I2D_DSAPRIVATEKEY 179 | ||
| 755 | #define ASN1_F_I2D_DSAPUBLICKEY 180 | ||
| 756 | #define ASN1_F_I2D_NETSCAPE_RSA 181 | ||
| 757 | #define ASN1_F_I2D_PKCS7 182 | ||
| 758 | #define ASN1_F_I2D_PRIVATEKEY 183 | ||
| 759 | #define ASN1_F_I2D_PUBLICKEY 184 | ||
| 760 | #define ASN1_F_I2D_RSAPRIVATEKEY 185 | ||
| 761 | #define ASN1_F_I2D_RSAPUBLICKEY 186 | ||
| 762 | #define ASN1_F_I2D_X509_ATTRIBUTE 187 | ||
| 763 | #define ASN1_F_I2T_ASN1_OBJECT 188 | ||
| 764 | #define ASN1_F_NETSCAPE_PKEY_NEW 189 | ||
| 765 | #define ASN1_F_NETSCAPE_SPKAC_NEW 190 | ||
| 766 | #define ASN1_F_NETSCAPE_SPKI_NEW 191 | ||
| 767 | #define ASN1_F_PKCS7_DIGEST_NEW 192 | ||
| 768 | #define ASN1_F_PKCS7_ENCRYPT_NEW 193 | ||
| 769 | #define ASN1_F_PKCS7_ENC_CONTENT_NEW 194 | ||
| 770 | #define ASN1_F_PKCS7_ENVELOPE_NEW 195 | ||
| 771 | #define ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW 196 | ||
| 772 | #define ASN1_F_PKCS7_NEW 197 | ||
| 773 | #define ASN1_F_PKCS7_RECIP_INFO_NEW 198 | ||
| 774 | #define ASN1_F_PKCS7_SIGNED_NEW 199 | ||
| 775 | #define ASN1_F_PKCS7_SIGNER_INFO_NEW 200 | ||
| 776 | #define ASN1_F_PKCS7_SIGN_ENVELOPE_NEW 201 | ||
| 777 | #define ASN1_F_X509_ALGOR_NEW 202 | ||
| 778 | #define ASN1_F_X509_ATTRIBUTE_NEW 203 | ||
| 779 | #define ASN1_F_X509_CINF_NEW 204 | ||
| 780 | #define ASN1_F_X509_CRL_INFO_NEW 205 | ||
| 781 | #define ASN1_F_X509_CRL_NEW 206 | ||
| 782 | #define ASN1_F_X509_DHPARAMS_NEW 207 | ||
| 783 | #define ASN1_F_X509_EXTENSION_NEW 208 | ||
| 784 | #define ASN1_F_X509_INFO_NEW 209 | ||
| 785 | #define ASN1_F_X509_KEY_NEW 210 | ||
| 786 | #define ASN1_F_X509_NAME_ENTRY_NEW 211 | ||
| 787 | #define ASN1_F_X509_NAME_NEW 212 | ||
| 788 | #define ASN1_F_X509_NEW 213 | ||
| 789 | #define ASN1_F_X509_PKEY_NEW 214 | ||
| 790 | #define ASN1_F_X509_PUBKEY_NEW 215 | ||
| 791 | #define ASN1_F_X509_REQ_INFO_NEW 216 | ||
| 792 | #define ASN1_F_X509_REQ_NEW 217 | ||
| 793 | #define ASN1_F_X509_REVOKED_NEW 218 | ||
| 794 | #define ASN1_F_X509_SIG_NEW 219 | ||
| 795 | #define ASN1_F_X509_VAL_FREE 220 | ||
| 796 | #define ASN1_F_X509_VAL_NEW 221 | ||
| 797 | |||
| 798 | /* Reason codes. */ | ||
| 799 | #define ASN1_R_BAD_CLASS 100 | ||
| 800 | #define ASN1_R_BAD_GET_OBJECT 101 | ||
| 801 | #define ASN1_R_BAD_OBJECT_HEADER 102 | ||
| 802 | #define ASN1_R_BAD_PASSWORD_READ 103 | ||
| 803 | #define ASN1_R_BAD_PKCS7_CONTENT 104 | ||
| 804 | #define ASN1_R_BAD_PKCS7_TYPE 105 | ||
| 805 | #define ASN1_R_BAD_TAG 106 | ||
| 806 | #define ASN1_R_BAD_TYPE 107 | ||
| 807 | #define ASN1_R_BN_LIB 108 | ||
| 808 | #define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 109 | ||
| 809 | #define ASN1_R_BUFFER_TOO_SMALL 110 | ||
| 810 | #define ASN1_R_DATA_IS_WRONG 111 | ||
| 811 | #define ASN1_R_DECODING_ERROR 112 | ||
| 812 | #define ASN1_R_ERROR_STACK 113 | ||
| 813 | #define ASN1_R_EXPECTING_AN_INTEGER 114 | ||
| 814 | #define ASN1_R_EXPECTING_AN_OBJECT 115 | ||
| 815 | #define ASN1_R_EXPECTING_AN_OCTET_STRING 116 | ||
| 816 | #define ASN1_R_EXPECTING_A_BIT_STRING 117 | ||
| 817 | #define ASN1_R_EXPECTING_A_BOOLEAN 118 | ||
| 818 | #define ASN1_R_EXPECTING_A_SEQUENCE 119 | ||
| 819 | #define ASN1_R_EXPECTING_A_UTCTIME 120 | ||
| 820 | #define ASN1_R_FIRST_NUM_TOO_LARGE 121 | ||
| 821 | #define ASN1_R_HEADER_TOO_LONG 122 | ||
| 822 | #define ASN1_R_INVALID_DIGIT 123 | ||
| 823 | #define ASN1_R_INVALID_SEPARATOR 124 | ||
| 824 | #define ASN1_R_INVALID_TIME_FORMAT 125 | ||
| 825 | #define ASN1_R_IV_TOO_LARGE 126 | ||
| 826 | #define ASN1_R_LENGTH_ERROR 127 | ||
| 827 | #define ASN1_R_LENGTH_MISMATCH 128 | ||
| 828 | #define ASN1_R_MISSING_EOS 129 | ||
| 829 | #define ASN1_R_MISSING_SECOND_NUMBER 130 | ||
| 830 | #define ASN1_R_NON_HEX_CHARACTERS 131 | ||
| 831 | #define ASN1_R_NOT_ENOUGH_DATA 132 | ||
| 832 | #define ASN1_R_ODD_NUMBER_OF_CHARS 133 | ||
| 833 | #define ASN1_R_PARSING 134 | ||
| 834 | #define ASN1_R_PRIVATE_KEY_HEADER_MISSING 135 | ||
| 835 | #define ASN1_R_SECOND_NUMBER_TOO_LARGE 136 | ||
| 836 | #define ASN1_R_SHORT_LINE 137 | ||
| 837 | #define ASN1_R_STRING_TOO_SHORT 138 | ||
| 838 | #define ASN1_R_TAG_VALUE_TOO_HIGH 139 | ||
| 839 | #define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 140 | ||
| 840 | #define ASN1_R_TOO_LONG 141 | ||
| 841 | #define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 142 | ||
| 842 | #define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 143 | ||
| 843 | #define ASN1_R_UNKNOWN_ATTRIBUTE_TYPE 144 | ||
| 844 | #define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 145 | ||
| 845 | #define ASN1_R_UNKNOWN_OBJECT_TYPE 146 | ||
| 846 | #define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 147 | ||
| 847 | #define ASN1_R_UNSUPPORTED_CIPHER 148 | ||
| 848 | #define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 149 | ||
| 849 | #define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 150 | ||
| 850 | #define ASN1_R_UTCTIME_TOO_LONG 151 | ||
| 851 | #define ASN1_R_WRONG_PRINTABLE_TYPE 152 | ||
| 852 | #define ASN1_R_WRONG_TAG 153 | ||
| 853 | #define ASN1_R_WRONG_TYPE 154 | ||
| 854 | |||
| 855 | #ifdef __cplusplus | ||
| 856 | } | ||
| 857 | #endif | ||
| 858 | #endif | ||
| 859 | |||
diff --git a/src/lib/libcrypto/asn1/asn1_err.c b/src/lib/libcrypto/asn1/asn1_err.c new file mode 100644 index 0000000000..03c2858e7d --- /dev/null +++ b/src/lib/libcrypto/asn1/asn1_err.c | |||
| @@ -0,0 +1,266 @@ | |||
| 1 | /* lib/asn1/asn1_err.c */ | ||
| 2 | /* Copyright (C) 1995-1997 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 | #include <stdio.h> | ||
| 59 | #include "err.h" | ||
| 60 | #include "asn1.h" | ||
| 61 | |||
| 62 | /* BEGIN ERROR CODES */ | ||
| 63 | #ifndef NO_ERR | ||
| 64 | static ERR_STRING_DATA ASN1_str_functs[]= | ||
| 65 | { | ||
| 66 | {ERR_PACK(0,ASN1_F_A2D_ASN1_OBJECT,0), "a2d_ASN1_OBJECT"}, | ||
| 67 | {ERR_PACK(0,ASN1_F_A2I_ASN1_INTEGER,0), "a2i_ASN1_INTEGER"}, | ||
| 68 | {ERR_PACK(0,ASN1_F_A2I_ASN1_STRING,0), "a2i_ASN1_STRING"}, | ||
| 69 | {ERR_PACK(0,ASN1_F_ASN1_COLLATE_PRIMATIVE,0), "ASN1_COLLATE_PRIMATIVE"}, | ||
| 70 | {ERR_PACK(0,ASN1_F_ASN1_D2I_BIO,0), "ASN1_d2i_bio"}, | ||
| 71 | {ERR_PACK(0,ASN1_F_ASN1_D2I_FP,0), "ASN1_d2i_fp"}, | ||
| 72 | {ERR_PACK(0,ASN1_F_ASN1_DUP,0), "ASN1_dup"}, | ||
| 73 | {ERR_PACK(0,ASN1_F_ASN1_GET_OBJECT,0), "ASN1_get_object"}, | ||
| 74 | {ERR_PACK(0,ASN1_F_ASN1_HEADER_NEW,0), "ASN1_HEADER_new"}, | ||
| 75 | {ERR_PACK(0,ASN1_F_ASN1_I2D_BIO,0), "ASN1_i2d_bio"}, | ||
| 76 | {ERR_PACK(0,ASN1_F_ASN1_I2D_FP,0), "ASN1_i2d_fp"}, | ||
| 77 | {ERR_PACK(0,ASN1_F_ASN1_INTEGER_SET,0), "ASN1_INTEGER_set"}, | ||
| 78 | {ERR_PACK(0,ASN1_F_ASN1_INTEGER_TO_BN,0), "ASN1_INTEGER_to_BN"}, | ||
| 79 | {ERR_PACK(0,ASN1_F_ASN1_OBJECT_NEW,0), "ASN1_OBJECT_new"}, | ||
| 80 | {ERR_PACK(0,ASN1_F_ASN1_SIGN,0), "ASN1_SIGN"}, | ||
| 81 | {ERR_PACK(0,ASN1_F_ASN1_STRING_NEW,0), "ASN1_STRING_new"}, | ||
| 82 | {ERR_PACK(0,ASN1_F_ASN1_STRING_TYPE_NEW,0), "ASN1_STRING_type_new"}, | ||
| 83 | {ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,0), "ASN1_TYPE_get_int_octetstring"}, | ||
| 84 | {ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_OCTETSTRING,0), "ASN1_TYPE_get_octetstring"}, | ||
| 85 | {ERR_PACK(0,ASN1_F_ASN1_TYPE_NEW,0), "ASN1_TYPE_new"}, | ||
| 86 | {ERR_PACK(0,ASN1_F_ASN1_UTCTIME_NEW,0), "ASN1_UTCTIME_NEW"}, | ||
| 87 | {ERR_PACK(0,ASN1_F_ASN1_VERIFY,0), "ASN1_VERIFY"}, | ||
| 88 | {ERR_PACK(0,ASN1_F_BN_TO_ASN1_INTEGER,0), "BN_to_ASN1_INTEGER"}, | ||
| 89 | {ERR_PACK(0,ASN1_F_D2I_ASN1_BIT_STRING,0), "d2i_ASN1_BIT_STRING"}, | ||
| 90 | {ERR_PACK(0,ASN1_F_D2I_ASN1_BMPSTRING,0), "D2I_ASN1_BMPSTRING"}, | ||
| 91 | {ERR_PACK(0,ASN1_F_D2I_ASN1_BOOLEAN,0), "d2i_ASN1_BOOLEAN"}, | ||
| 92 | {ERR_PACK(0,ASN1_F_D2I_ASN1_BYTES,0), "d2i_ASN1_bytes"}, | ||
| 93 | {ERR_PACK(0,ASN1_F_D2I_ASN1_HEADER,0), "d2i_ASN1_HEADER"}, | ||
| 94 | {ERR_PACK(0,ASN1_F_D2I_ASN1_INTEGER,0), "d2i_ASN1_INTEGER"}, | ||
| 95 | {ERR_PACK(0,ASN1_F_D2I_ASN1_OBJECT,0), "d2i_ASN1_OBJECT"}, | ||
| 96 | {ERR_PACK(0,ASN1_F_D2I_ASN1_OCTET_STRING,0), "d2i_ASN1_OCTET_STRING"}, | ||
| 97 | {ERR_PACK(0,ASN1_F_D2I_ASN1_PRINT_TYPE,0), "D2I_ASN1_PRINT_TYPE"}, | ||
| 98 | {ERR_PACK(0,ASN1_F_D2I_ASN1_SET,0), "d2i_ASN1_SET"}, | ||
| 99 | {ERR_PACK(0,ASN1_F_D2I_ASN1_TYPE,0), "d2i_ASN1_TYPE"}, | ||
| 100 | {ERR_PACK(0,ASN1_F_D2I_ASN1_TYPE_BYTES,0), "d2i_ASN1_type_bytes"}, | ||
| 101 | {ERR_PACK(0,ASN1_F_D2I_ASN1_UTCTIME,0), "d2i_ASN1_UTCTIME"}, | ||
| 102 | {ERR_PACK(0,ASN1_F_D2I_DHPARAMS,0), "D2I_DHPARAMS"}, | ||
| 103 | {ERR_PACK(0,ASN1_F_D2I_DSAPARAMS,0), "D2I_DSAPARAMS"}, | ||
| 104 | {ERR_PACK(0,ASN1_F_D2I_DSAPRIVATEKEY,0), "D2I_DSAPRIVATEKEY"}, | ||
| 105 | {ERR_PACK(0,ASN1_F_D2I_DSAPUBLICKEY,0), "D2I_DSAPUBLICKEY"}, | ||
| 106 | {ERR_PACK(0,ASN1_F_D2I_NETSCAPE_PKEY,0), "D2I_NETSCAPE_PKEY"}, | ||
| 107 | {ERR_PACK(0,ASN1_F_D2I_NETSCAPE_RSA,0), "D2I_NETSCAPE_RSA"}, | ||
| 108 | {ERR_PACK(0,ASN1_F_D2I_NETSCAPE_RSA_2,0), "D2I_NETSCAPE_RSA_2"}, | ||
| 109 | {ERR_PACK(0,ASN1_F_D2I_NETSCAPE_SPKAC,0), "D2I_NETSCAPE_SPKAC"}, | ||
| 110 | {ERR_PACK(0,ASN1_F_D2I_NETSCAPE_SPKI,0), "D2I_NETSCAPE_SPKI"}, | ||
| 111 | {ERR_PACK(0,ASN1_F_D2I_PKCS7,0), "D2I_PKCS7"}, | ||
| 112 | {ERR_PACK(0,ASN1_F_D2I_PKCS7_DIGEST,0), "D2I_PKCS7_DIGEST"}, | ||
| 113 | {ERR_PACK(0,ASN1_F_D2I_PKCS7_ENCRYPT,0), "D2I_PKCS7_ENCRYPT"}, | ||
| 114 | {ERR_PACK(0,ASN1_F_D2I_PKCS7_ENC_CONTENT,0), "D2I_PKCS7_ENC_CONTENT"}, | ||
| 115 | {ERR_PACK(0,ASN1_F_D2I_PKCS7_ENVELOPE,0), "D2I_PKCS7_ENVELOPE"}, | ||
| 116 | {ERR_PACK(0,ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL,0), "D2I_PKCS7_ISSUER_AND_SERIAL"}, | ||
| 117 | {ERR_PACK(0,ASN1_F_D2I_PKCS7_RECIP_INFO,0), "D2I_PKCS7_RECIP_INFO"}, | ||
| 118 | {ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGNED,0), "D2I_PKCS7_SIGNED"}, | ||
| 119 | {ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGNER_INFO,0), "D2I_PKCS7_SIGNER_INFO"}, | ||
| 120 | {ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGN_ENVELOPE,0), "D2I_PKCS7_SIGN_ENVELOPE"}, | ||
| 121 | {ERR_PACK(0,ASN1_F_D2I_PRIVATEKEY,0), "D2I_PRIVATEKEY"}, | ||
| 122 | {ERR_PACK(0,ASN1_F_D2I_PUBLICKEY,0), "D2I_PUBLICKEY"}, | ||
| 123 | {ERR_PACK(0,ASN1_F_D2I_RSAPRIVATEKEY,0), "D2I_RSAPRIVATEKEY"}, | ||
| 124 | {ERR_PACK(0,ASN1_F_D2I_RSAPUBLICKEY,0), "D2I_RSAPUBLICKEY"}, | ||
| 125 | {ERR_PACK(0,ASN1_F_D2I_X509,0), "D2I_X509"}, | ||
| 126 | {ERR_PACK(0,ASN1_F_D2I_X509_ALGOR,0), "D2I_X509_ALGOR"}, | ||
| 127 | {ERR_PACK(0,ASN1_F_D2I_X509_ATTRIBUTE,0), "D2I_X509_ATTRIBUTE"}, | ||
| 128 | {ERR_PACK(0,ASN1_F_D2I_X509_CINF,0), "D2I_X509_CINF"}, | ||
| 129 | {ERR_PACK(0,ASN1_F_D2I_X509_CRL,0), "D2I_X509_CRL"}, | ||
| 130 | {ERR_PACK(0,ASN1_F_D2I_X509_CRL_INFO,0), "D2I_X509_CRL_INFO"}, | ||
| 131 | {ERR_PACK(0,ASN1_F_D2I_X509_EXTENSION,0), "D2I_X509_EXTENSION"}, | ||
| 132 | {ERR_PACK(0,ASN1_F_D2I_X509_KEY,0), "D2I_X509_KEY"}, | ||
| 133 | {ERR_PACK(0,ASN1_F_D2I_X509_NAME,0), "D2I_X509_NAME"}, | ||
| 134 | {ERR_PACK(0,ASN1_F_D2I_X509_NAME_ENTRY,0), "D2I_X509_NAME_ENTRY"}, | ||
| 135 | {ERR_PACK(0,ASN1_F_D2I_X509_PKEY,0), "D2I_X509_PKEY"}, | ||
| 136 | {ERR_PACK(0,ASN1_F_D2I_X509_PUBKEY,0), "D2I_X509_PUBKEY"}, | ||
| 137 | {ERR_PACK(0,ASN1_F_D2I_X509_REQ,0), "D2I_X509_REQ"}, | ||
| 138 | {ERR_PACK(0,ASN1_F_D2I_X509_REQ_INFO,0), "D2I_X509_REQ_INFO"}, | ||
| 139 | {ERR_PACK(0,ASN1_F_D2I_X509_REVOKED,0), "D2I_X509_REVOKED"}, | ||
| 140 | {ERR_PACK(0,ASN1_F_D2I_X509_SIG,0), "D2I_X509_SIG"}, | ||
| 141 | {ERR_PACK(0,ASN1_F_D2I_X509_VAL,0), "D2I_X509_VAL"}, | ||
| 142 | {ERR_PACK(0,ASN1_F_I2D_ASN1_HEADER,0), "i2d_ASN1_HEADER"}, | ||
| 143 | {ERR_PACK(0,ASN1_F_I2D_DHPARAMS,0), "I2D_DHPARAMS"}, | ||
| 144 | {ERR_PACK(0,ASN1_F_I2D_DSAPARAMS,0), "I2D_DSAPARAMS"}, | ||
| 145 | {ERR_PACK(0,ASN1_F_I2D_DSAPRIVATEKEY,0), "I2D_DSAPRIVATEKEY"}, | ||
| 146 | {ERR_PACK(0,ASN1_F_I2D_DSAPUBLICKEY,0), "I2D_DSAPUBLICKEY"}, | ||
| 147 | {ERR_PACK(0,ASN1_F_I2D_NETSCAPE_RSA,0), "I2D_NETSCAPE_RSA"}, | ||
| 148 | {ERR_PACK(0,ASN1_F_I2D_PKCS7,0), "I2D_PKCS7"}, | ||
| 149 | {ERR_PACK(0,ASN1_F_I2D_PRIVATEKEY,0), "I2D_PRIVATEKEY"}, | ||
| 150 | {ERR_PACK(0,ASN1_F_I2D_PUBLICKEY,0), "I2D_PUBLICKEY"}, | ||
| 151 | {ERR_PACK(0,ASN1_F_I2D_RSAPRIVATEKEY,0), "I2D_RSAPRIVATEKEY"}, | ||
| 152 | {ERR_PACK(0,ASN1_F_I2D_RSAPUBLICKEY,0), "I2D_RSAPUBLICKEY"}, | ||
| 153 | {ERR_PACK(0,ASN1_F_I2D_X509_ATTRIBUTE,0), "I2D_X509_ATTRIBUTE"}, | ||
| 154 | {ERR_PACK(0,ASN1_F_I2T_ASN1_OBJECT,0), "i2t_ASN1_OBJECT"}, | ||
| 155 | {ERR_PACK(0,ASN1_F_NETSCAPE_PKEY_NEW,0), "NETSCAPE_PKEY_NEW"}, | ||
| 156 | {ERR_PACK(0,ASN1_F_NETSCAPE_SPKAC_NEW,0), "NETSCAPE_SPKAC_NEW"}, | ||
| 157 | {ERR_PACK(0,ASN1_F_NETSCAPE_SPKI_NEW,0), "NETSCAPE_SPKI_NEW"}, | ||
| 158 | {ERR_PACK(0,ASN1_F_PKCS7_DIGEST_NEW,0), "PKCS7_DIGEST_NEW"}, | ||
| 159 | {ERR_PACK(0,ASN1_F_PKCS7_ENCRYPT_NEW,0), "PKCS7_ENCRYPT_NEW"}, | ||
| 160 | {ERR_PACK(0,ASN1_F_PKCS7_ENC_CONTENT_NEW,0), "PKCS7_ENC_CONTENT_NEW"}, | ||
| 161 | {ERR_PACK(0,ASN1_F_PKCS7_ENVELOPE_NEW,0), "PKCS7_ENVELOPE_NEW"}, | ||
| 162 | {ERR_PACK(0,ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW,0), "PKCS7_ISSUER_AND_SERIAL_NEW"}, | ||
| 163 | {ERR_PACK(0,ASN1_F_PKCS7_NEW,0), "PKCS7_NEW"}, | ||
| 164 | {ERR_PACK(0,ASN1_F_PKCS7_RECIP_INFO_NEW,0), "PKCS7_RECIP_INFO_NEW"}, | ||
| 165 | {ERR_PACK(0,ASN1_F_PKCS7_SIGNED_NEW,0), "PKCS7_SIGNED_NEW"}, | ||
| 166 | {ERR_PACK(0,ASN1_F_PKCS7_SIGNER_INFO_NEW,0), "PKCS7_SIGNER_INFO_NEW"}, | ||
| 167 | {ERR_PACK(0,ASN1_F_PKCS7_SIGN_ENVELOPE_NEW,0), "PKCS7_SIGN_ENVELOPE_NEW"}, | ||
| 168 | {ERR_PACK(0,ASN1_F_X509_ALGOR_NEW,0), "X509_ALGOR_NEW"}, | ||
| 169 | {ERR_PACK(0,ASN1_F_X509_ATTRIBUTE_NEW,0), "X509_ATTRIBUTE_NEW"}, | ||
| 170 | {ERR_PACK(0,ASN1_F_X509_CINF_NEW,0), "X509_CINF_NEW"}, | ||
| 171 | {ERR_PACK(0,ASN1_F_X509_CRL_INFO_NEW,0), "X509_CRL_INFO_NEW"}, | ||
| 172 | {ERR_PACK(0,ASN1_F_X509_CRL_NEW,0), "X509_CRL_NEW"}, | ||
| 173 | {ERR_PACK(0,ASN1_F_X509_DHPARAMS_NEW,0), "X509_DHPARAMS_NEW"}, | ||
| 174 | {ERR_PACK(0,ASN1_F_X509_EXTENSION_NEW,0), "X509_EXTENSION_NEW"}, | ||
| 175 | {ERR_PACK(0,ASN1_F_X509_INFO_NEW,0), "X509_INFO_NEW"}, | ||
| 176 | {ERR_PACK(0,ASN1_F_X509_KEY_NEW,0), "X509_KEY_NEW"}, | ||
| 177 | {ERR_PACK(0,ASN1_F_X509_NAME_ENTRY_NEW,0), "X509_NAME_ENTRY_NEW"}, | ||
| 178 | {ERR_PACK(0,ASN1_F_X509_NAME_NEW,0), "X509_NAME_NEW"}, | ||
| 179 | {ERR_PACK(0,ASN1_F_X509_NEW,0), "X509_NEW"}, | ||
| 180 | {ERR_PACK(0,ASN1_F_X509_PKEY_NEW,0), "X509_PKEY_NEW"}, | ||
| 181 | {ERR_PACK(0,ASN1_F_X509_PUBKEY_NEW,0), "X509_PUBKEY_NEW"}, | ||
| 182 | {ERR_PACK(0,ASN1_F_X509_REQ_INFO_NEW,0), "X509_REQ_INFO_NEW"}, | ||
| 183 | {ERR_PACK(0,ASN1_F_X509_REQ_NEW,0), "X509_REQ_NEW"}, | ||
| 184 | {ERR_PACK(0,ASN1_F_X509_REVOKED_NEW,0), "X509_REVOKED_NEW"}, | ||
| 185 | {ERR_PACK(0,ASN1_F_X509_SIG_NEW,0), "X509_SIG_NEW"}, | ||
| 186 | {ERR_PACK(0,ASN1_F_X509_VAL_FREE,0), "X509_VAL_FREE"}, | ||
| 187 | {ERR_PACK(0,ASN1_F_X509_VAL_NEW,0), "X509_VAL_NEW"}, | ||
| 188 | {0,NULL}, | ||
| 189 | }; | ||
| 190 | |||
| 191 | static ERR_STRING_DATA ASN1_str_reasons[]= | ||
| 192 | { | ||
| 193 | {ASN1_R_BAD_CLASS ,"bad class"}, | ||
| 194 | {ASN1_R_BAD_GET_OBJECT ,"bad get object"}, | ||
| 195 | {ASN1_R_BAD_OBJECT_HEADER ,"bad object header"}, | ||
| 196 | {ASN1_R_BAD_PASSWORD_READ ,"bad password read"}, | ||
| 197 | {ASN1_R_BAD_PKCS7_CONTENT ,"bad pkcs7 content"}, | ||
| 198 | {ASN1_R_BAD_PKCS7_TYPE ,"bad pkcs7 type"}, | ||
| 199 | {ASN1_R_BAD_TAG ,"bad tag"}, | ||
| 200 | {ASN1_R_BAD_TYPE ,"bad type"}, | ||
| 201 | {ASN1_R_BN_LIB ,"bn lib"}, | ||
| 202 | {ASN1_R_BOOLEAN_IS_WRONG_LENGTH ,"boolean is wrong length"}, | ||
| 203 | {ASN1_R_BUFFER_TOO_SMALL ,"buffer too small"}, | ||
| 204 | {ASN1_R_DATA_IS_WRONG ,"data is wrong"}, | ||
| 205 | {ASN1_R_DECODING_ERROR ,"decoding error"}, | ||
| 206 | {ASN1_R_ERROR_STACK ,"error stack"}, | ||
| 207 | {ASN1_R_EXPECTING_AN_INTEGER ,"expecting an integer"}, | ||
| 208 | {ASN1_R_EXPECTING_AN_OBJECT ,"expecting an object"}, | ||
| 209 | {ASN1_R_EXPECTING_AN_OCTET_STRING ,"expecting an octet string"}, | ||
| 210 | {ASN1_R_EXPECTING_A_BIT_STRING ,"expecting a bit string"}, | ||
| 211 | {ASN1_R_EXPECTING_A_BOOLEAN ,"expecting a boolean"}, | ||
| 212 | {ASN1_R_EXPECTING_A_SEQUENCE ,"expecting a sequence"}, | ||
| 213 | {ASN1_R_EXPECTING_A_UTCTIME ,"expecting a utctime"}, | ||
| 214 | {ASN1_R_FIRST_NUM_TOO_LARGE ,"first num too large"}, | ||
| 215 | {ASN1_R_HEADER_TOO_LONG ,"header too long"}, | ||
| 216 | {ASN1_R_INVALID_DIGIT ,"invalid digit"}, | ||
| 217 | {ASN1_R_INVALID_SEPARATOR ,"invalid separator"}, | ||
| 218 | {ASN1_R_INVALID_TIME_FORMAT ,"invalid time format"}, | ||
| 219 | {ASN1_R_IV_TOO_LARGE ,"iv too large"}, | ||
| 220 | {ASN1_R_LENGTH_ERROR ,"length error"}, | ||
| 221 | {ASN1_R_LENGTH_MISMATCH ,"length mismatch"}, | ||
| 222 | {ASN1_R_MISSING_EOS ,"missing eos"}, | ||
| 223 | {ASN1_R_MISSING_SECOND_NUMBER ,"missing second number"}, | ||
| 224 | {ASN1_R_NON_HEX_CHARACTERS ,"non hex characters"}, | ||
| 225 | {ASN1_R_NOT_ENOUGH_DATA ,"not enough data"}, | ||
| 226 | {ASN1_R_ODD_NUMBER_OF_CHARS ,"odd number of chars"}, | ||
| 227 | {ASN1_R_PARSING ,"parsing"}, | ||
| 228 | {ASN1_R_PRIVATE_KEY_HEADER_MISSING ,"private key header missing"}, | ||
| 229 | {ASN1_R_SECOND_NUMBER_TOO_LARGE ,"second number too large"}, | ||
| 230 | {ASN1_R_SHORT_LINE ,"short line"}, | ||
| 231 | {ASN1_R_STRING_TOO_SHORT ,"string too short"}, | ||
| 232 | {ASN1_R_TAG_VALUE_TOO_HIGH ,"tag value too high"}, | ||
| 233 | {ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD,"the asn1 object identifier is not known for this md"}, | ||
| 234 | {ASN1_R_TOO_LONG ,"too long"}, | ||
| 235 | {ASN1_R_UNABLE_TO_DECODE_RSA_KEY ,"unable to decode rsa key"}, | ||
| 236 | {ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY ,"unable to decode rsa private key"}, | ||
| 237 | {ASN1_R_UNKNOWN_ATTRIBUTE_TYPE ,"unknown attribute type"}, | ||
| 238 | {ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM ,"unknown message digest algorithm"}, | ||
| 239 | {ASN1_R_UNKNOWN_OBJECT_TYPE ,"unknown object type"}, | ||
| 240 | {ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE ,"unknown public key type"}, | ||
| 241 | {ASN1_R_UNSUPPORTED_CIPHER ,"unsupported cipher"}, | ||
| 242 | {ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM ,"unsupported encryption algorithm"}, | ||
| 243 | {ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE ,"unsupported public key type"}, | ||
| 244 | {ASN1_R_UTCTIME_TOO_LONG ,"utctime too long"}, | ||
| 245 | {ASN1_R_WRONG_PRINTABLE_TYPE ,"wrong printable type"}, | ||
| 246 | {ASN1_R_WRONG_TAG ,"wrong tag"}, | ||
| 247 | {ASN1_R_WRONG_TYPE ,"wrong type"}, | ||
| 248 | {0,NULL}, | ||
| 249 | }; | ||
| 250 | |||
| 251 | #endif | ||
| 252 | |||
| 253 | void ERR_load_ASN1_strings() | ||
| 254 | { | ||
| 255 | static int init=1; | ||
| 256 | |||
| 257 | if (init); | ||
| 258 | {; | ||
| 259 | init=0; | ||
| 260 | #ifndef NO_ERR | ||
| 261 | ERR_load_strings(ERR_LIB_ASN1,ASN1_str_functs); | ||
| 262 | ERR_load_strings(ERR_LIB_ASN1,ASN1_str_reasons); | ||
| 263 | #endif | ||
| 264 | |||
| 265 | } | ||
| 266 | } | ||
diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c new file mode 100644 index 0000000000..ff30b25836 --- /dev/null +++ b/src/lib/libcrypto/asn1/asn1_lib.c | |||
| @@ -0,0 +1,444 @@ | |||
| 1 | /* crypto/asn1/asn1_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.h" | ||
| 62 | #include "asn1_mac.h" | ||
| 63 | |||
| 64 | #ifndef NOPROTO | ||
| 65 | static int asn1_get_length(unsigned char **pp,int *inf,long *rl,int max); | ||
| 66 | static void asn1_put_length(unsigned char **pp, int length); | ||
| 67 | #else | ||
| 68 | static int asn1_get_length(); | ||
| 69 | static void asn1_put_length(); | ||
| 70 | #endif | ||
| 71 | |||
| 72 | char *ASN1_version="ASN1 part of SSLeay 0.9.0b 29-Jun-1998"; | ||
| 73 | |||
| 74 | int ASN1_check_infinite_end(p,len) | ||
| 75 | unsigned char **p; | ||
| 76 | long len; | ||
| 77 | { | ||
| 78 | /* If there is 0 or 1 byte left, the length check should pick | ||
| 79 | * things up */ | ||
| 80 | if (len <= 0) | ||
| 81 | return(1); | ||
| 82 | else if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0)) | ||
| 83 | { | ||
| 84 | (*p)+=2; | ||
| 85 | return(1); | ||
| 86 | } | ||
| 87 | return(0); | ||
| 88 | } | ||
| 89 | |||
| 90 | |||
| 91 | int ASN1_get_object(pp, plength, ptag, pclass, omax) | ||
| 92 | unsigned char **pp; | ||
| 93 | long *plength; | ||
| 94 | int *ptag; | ||
| 95 | int *pclass; | ||
| 96 | long omax; | ||
| 97 | { | ||
| 98 | int i,ret; | ||
| 99 | long l; | ||
| 100 | unsigned char *p= *pp; | ||
| 101 | int tag,xclass,inf; | ||
| 102 | long max=omax; | ||
| 103 | |||
| 104 | if (!max) goto err; | ||
| 105 | ret=(*p&V_ASN1_CONSTRUCTED); | ||
| 106 | xclass=(*p&V_ASN1_PRIVATE); | ||
| 107 | i= *p&V_ASN1_PRIMATIVE_TAG; | ||
| 108 | if (i == V_ASN1_PRIMATIVE_TAG) | ||
| 109 | { /* high-tag */ | ||
| 110 | p++; | ||
| 111 | if (--max == 0) goto err; | ||
| 112 | l=0; | ||
| 113 | while (*p&0x80) | ||
| 114 | { | ||
| 115 | l<<=7L; | ||
| 116 | l|= *(p++)&0x7f; | ||
| 117 | if (--max == 0) goto err; | ||
| 118 | } | ||
| 119 | l<<=7L; | ||
| 120 | l|= *(p++)&0x7f; | ||
| 121 | tag=(int)l; | ||
| 122 | } | ||
| 123 | else | ||
| 124 | { | ||
| 125 | tag=i; | ||
| 126 | p++; | ||
| 127 | if (--max == 0) goto err; | ||
| 128 | } | ||
| 129 | *ptag=tag; | ||
| 130 | *pclass=xclass; | ||
| 131 | if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err; | ||
| 132 | |||
| 133 | #ifdef undef | ||
| 134 | fprintf(stderr,"p=%d + *plength=%d > omax=%d + *pp=%d (%d > %d)\n", | ||
| 135 | p,*plength,omax,*pp,(p+ *plength),omax+ *pp); | ||
| 136 | |||
| 137 | #endif | ||
| 138 | if ((p+ *plength) > (omax+ *pp)) | ||
| 139 | { | ||
| 140 | ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG); | ||
| 141 | /* Set this so that even if things are not long enough | ||
| 142 | * the values are set correctly */ | ||
| 143 | ret|=0x80; | ||
| 144 | } | ||
| 145 | *pp=p; | ||
| 146 | return(ret+inf); | ||
| 147 | err: | ||
| 148 | ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG); | ||
| 149 | return(0x80); | ||
| 150 | } | ||
| 151 | |||
| 152 | static int asn1_get_length(pp,inf,rl,max) | ||
| 153 | unsigned char **pp; | ||
| 154 | int *inf; | ||
| 155 | long *rl; | ||
| 156 | int max; | ||
| 157 | { | ||
| 158 | unsigned char *p= *pp; | ||
| 159 | long ret=0; | ||
| 160 | int i; | ||
| 161 | |||
| 162 | if (max-- < 1) return(0); | ||
| 163 | if (*p == 0x80) | ||
| 164 | { | ||
| 165 | *inf=1; | ||
| 166 | ret=0; | ||
| 167 | p++; | ||
| 168 | } | ||
| 169 | else | ||
| 170 | { | ||
| 171 | *inf=0; | ||
| 172 | i= *p&0x7f; | ||
| 173 | if (*(p++) & 0x80) | ||
| 174 | { | ||
| 175 | if (max-- == 0) return(0); | ||
| 176 | while (i-- > 0) | ||
| 177 | { | ||
| 178 | ret<<=8L; | ||
| 179 | ret|= *(p++); | ||
| 180 | if (max-- == 0) return(0); | ||
| 181 | } | ||
| 182 | } | ||
| 183 | else | ||
| 184 | ret=i; | ||
| 185 | } | ||
| 186 | *pp=p; | ||
| 187 | *rl=ret; | ||
| 188 | return(1); | ||
| 189 | } | ||
| 190 | |||
| 191 | /* class 0 is constructed | ||
| 192 | * constructed == 2 for indefinitle length constructed */ | ||
| 193 | void ASN1_put_object(pp,constructed,length,tag,xclass) | ||
| 194 | unsigned char **pp; | ||
| 195 | int constructed; | ||
| 196 | int length; | ||
| 197 | int tag; | ||
| 198 | int xclass; | ||
| 199 | { | ||
| 200 | unsigned char *p= *pp; | ||
| 201 | int i; | ||
| 202 | |||
| 203 | i=(constructed)?V_ASN1_CONSTRUCTED:0; | ||
| 204 | i|=(xclass&V_ASN1_PRIVATE); | ||
| 205 | if (tag < 31) | ||
| 206 | *(p++)=i|(tag&V_ASN1_PRIMATIVE_TAG); | ||
| 207 | else | ||
| 208 | { | ||
| 209 | *(p++)=i|V_ASN1_PRIMATIVE_TAG; | ||
| 210 | while (tag > 0x7f) | ||
| 211 | { | ||
| 212 | *(p++)=(tag&0x7f)|0x80; | ||
| 213 | tag>>=7; | ||
| 214 | } | ||
| 215 | *(p++)=(tag&0x7f); | ||
| 216 | } | ||
| 217 | if ((constructed == 2) && (length == 0)) | ||
| 218 | *(p++)=0x80; /* der_put_length would output 0 instead */ | ||
| 219 | else | ||
| 220 | asn1_put_length(&p,length); | ||
| 221 | *pp=p; | ||
| 222 | } | ||
| 223 | |||
| 224 | static void asn1_put_length(pp, length) | ||
| 225 | unsigned char **pp; | ||
| 226 | int length; | ||
| 227 | { | ||
| 228 | unsigned char *p= *pp; | ||
| 229 | int i,l; | ||
| 230 | if (length <= 127) | ||
| 231 | *(p++)=(unsigned char)length; | ||
| 232 | else | ||
| 233 | { | ||
| 234 | l=length; | ||
| 235 | for (i=0; l > 0; i++) | ||
| 236 | l>>=8; | ||
| 237 | *(p++)=i|0x80; | ||
| 238 | l=i; | ||
| 239 | while (i-- > 0) | ||
| 240 | { | ||
| 241 | p[i]=length&0xff; | ||
| 242 | length>>=8; | ||
| 243 | } | ||
| 244 | p+=l; | ||
| 245 | } | ||
| 246 | *pp=p; | ||
| 247 | } | ||
| 248 | |||
| 249 | int ASN1_object_size(constructed, length, tag) | ||
| 250 | int constructed; | ||
| 251 | int length; | ||
| 252 | int tag; | ||
| 253 | { | ||
| 254 | int ret; | ||
| 255 | |||
| 256 | ret=length; | ||
| 257 | ret++; | ||
| 258 | if (tag >= 31) | ||
| 259 | { | ||
| 260 | while (tag > 0) | ||
| 261 | { | ||
| 262 | tag>>=7; | ||
| 263 | ret++; | ||
| 264 | } | ||
| 265 | } | ||
| 266 | if ((length == 0) && (constructed == 2)) | ||
| 267 | ret+=2; | ||
| 268 | ret++; | ||
| 269 | if (length > 127) | ||
| 270 | { | ||
| 271 | while (length > 0) | ||
| 272 | { | ||
| 273 | length>>=8; | ||
| 274 | ret++; | ||
| 275 | } | ||
| 276 | } | ||
| 277 | return(ret); | ||
| 278 | } | ||
| 279 | |||
| 280 | int asn1_Finish(c) | ||
| 281 | ASN1_CTX *c; | ||
| 282 | { | ||
| 283 | if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos)) | ||
| 284 | { | ||
| 285 | if (!ASN1_check_infinite_end(&c->p,c->slen)) | ||
| 286 | { | ||
| 287 | c->error=ASN1_R_MISSING_EOS; | ||
| 288 | return(0); | ||
| 289 | } | ||
| 290 | } | ||
| 291 | if ( ((c->slen != 0) && !(c->inf & 1)) || | ||
| 292 | ((c->slen < 0) && (c->inf & 1))) | ||
| 293 | { | ||
| 294 | c->error=ASN1_R_LENGTH_MISMATCH; | ||
| 295 | return(0); | ||
| 296 | } | ||
| 297 | return(1); | ||
| 298 | } | ||
| 299 | |||
| 300 | int asn1_GetSequence(c,length) | ||
| 301 | ASN1_CTX *c; | ||
| 302 | long *length; | ||
| 303 | { | ||
| 304 | unsigned char *q; | ||
| 305 | |||
| 306 | q=c->p; | ||
| 307 | c->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass), | ||
| 308 | *length); | ||
| 309 | if (c->inf & 0x80) | ||
| 310 | { | ||
| 311 | c->error=ASN1_R_BAD_GET_OBJECT; | ||
| 312 | return(0); | ||
| 313 | } | ||
| 314 | if (c->tag != V_ASN1_SEQUENCE) | ||
| 315 | { | ||
| 316 | c->error=ASN1_R_EXPECTING_A_SEQUENCE; | ||
| 317 | return(0); | ||
| 318 | } | ||
| 319 | (*length)-=(c->p-q); | ||
| 320 | if (c->max && (*length < 0)) | ||
| 321 | { | ||
| 322 | c->error=ASN1_R_LENGTH_MISMATCH; | ||
| 323 | return(0); | ||
| 324 | } | ||
| 325 | if (c->inf == (1|V_ASN1_CONSTRUCTED)) | ||
| 326 | c->slen= *length+ *(c->pp)-c->p; | ||
| 327 | c->eos=0; | ||
| 328 | return(1); | ||
| 329 | } | ||
| 330 | |||
| 331 | ASN1_STRING *ASN1_STRING_dup(str) | ||
| 332 | ASN1_STRING *str; | ||
| 333 | { | ||
| 334 | ASN1_STRING *ret; | ||
| 335 | |||
| 336 | if (str == NULL) return(NULL); | ||
| 337 | if ((ret=ASN1_STRING_type_new(str->type)) == NULL) | ||
| 338 | return(NULL); | ||
| 339 | if (!ASN1_STRING_set(ret,str->data,str->length)) | ||
| 340 | { | ||
| 341 | ASN1_STRING_free(ret); | ||
| 342 | return(NULL); | ||
| 343 | } | ||
| 344 | return(ret); | ||
| 345 | } | ||
| 346 | |||
| 347 | int ASN1_STRING_set(str,data,len) | ||
| 348 | ASN1_STRING *str; | ||
| 349 | unsigned char *data; | ||
| 350 | int len; | ||
| 351 | { | ||
| 352 | char *c; | ||
| 353 | |||
| 354 | if (len < 0) | ||
| 355 | { | ||
| 356 | if (data == NULL) | ||
| 357 | return(0); | ||
| 358 | else | ||
| 359 | len=strlen((char *)data); | ||
| 360 | } | ||
| 361 | if ((str->length < len) || (str->data == NULL)) | ||
| 362 | { | ||
| 363 | c=(char *)str->data; | ||
| 364 | if (c == NULL) | ||
| 365 | str->data=(unsigned char *)Malloc(len+1); | ||
| 366 | else | ||
| 367 | str->data=(unsigned char *)Realloc(c,len+1); | ||
| 368 | |||
| 369 | if (str->data == NULL) | ||
| 370 | { | ||
| 371 | str->data=(unsigned char *)c; | ||
| 372 | return(0); | ||
| 373 | } | ||
| 374 | } | ||
| 375 | str->length=len; | ||
| 376 | if (data != NULL) | ||
| 377 | { | ||
| 378 | memcpy(str->data,data,len); | ||
| 379 | /* an alowance for strings :-) */ | ||
| 380 | str->data[len]='\0'; | ||
| 381 | } | ||
| 382 | return(1); | ||
| 383 | } | ||
| 384 | |||
| 385 | ASN1_STRING *ASN1_STRING_new() | ||
| 386 | { | ||
| 387 | return(ASN1_STRING_type_new(V_ASN1_OCTET_STRING)); | ||
| 388 | } | ||
| 389 | |||
| 390 | |||
| 391 | ASN1_STRING *ASN1_STRING_type_new(type) | ||
| 392 | int type; | ||
| 393 | { | ||
| 394 | ASN1_STRING *ret; | ||
| 395 | |||
| 396 | ret=(ASN1_STRING *)Malloc(sizeof(ASN1_STRING)); | ||
| 397 | if (ret == NULL) | ||
| 398 | { | ||
| 399 | ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW,ERR_R_MALLOC_FAILURE); | ||
| 400 | return(NULL); | ||
| 401 | } | ||
| 402 | ret->length=0; | ||
| 403 | ret->type=type; | ||
| 404 | ret->data=NULL; | ||
| 405 | return(ret); | ||
| 406 | } | ||
| 407 | |||
| 408 | void ASN1_STRING_free(a) | ||
| 409 | ASN1_STRING *a; | ||
| 410 | { | ||
| 411 | if (a == NULL) return; | ||
| 412 | if (a->data != NULL) Free((char *)a->data); | ||
| 413 | Free((char *)a); | ||
| 414 | } | ||
| 415 | |||
| 416 | int ASN1_STRING_cmp(a,b) | ||
| 417 | ASN1_STRING *a,*b; | ||
| 418 | { | ||
| 419 | int i; | ||
| 420 | |||
| 421 | i=(a->length-b->length); | ||
| 422 | if (i == 0) | ||
| 423 | { | ||
| 424 | i=memcmp(a->data,b->data,a->length); | ||
| 425 | if (i == 0) | ||
| 426 | return(a->type-b->type); | ||
| 427 | else | ||
| 428 | return(i); | ||
| 429 | } | ||
| 430 | else | ||
| 431 | return(i); | ||
| 432 | } | ||
| 433 | |||
| 434 | void asn1_add_error(address,offset) | ||
| 435 | unsigned char *address; | ||
| 436 | int offset; | ||
| 437 | { | ||
| 438 | char buf1[16],buf2[16]; | ||
| 439 | |||
| 440 | sprintf(buf1,"%lu",(unsigned long)address); | ||
| 441 | sprintf(buf2,"%d",offset); | ||
| 442 | ERR_add_error_data(4,"address=",buf1," offset=",buf2); | ||
| 443 | } | ||
| 444 | |||
diff --git a/src/lib/libcrypto/asn1/asn1_mac.h b/src/lib/libcrypto/asn1/asn1_mac.h new file mode 100644 index 0000000000..4fba70e4bb --- /dev/null +++ b/src/lib/libcrypto/asn1/asn1_mac.h | |||
| @@ -0,0 +1,321 @@ | |||
| 1 | /* crypto/asn1/asn1_mac.h */ | ||
| 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 | #ifndef HEADER_ASN1_MAC_H | ||
| 60 | #define HEADER_ASN1_MAC_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #include "asn1.h" | ||
| 67 | #include "x509.h" | ||
| 68 | #include "pkcs7.h" | ||
| 69 | |||
| 70 | #define M_ASN1_D2I_vars(a,type,func) \ | ||
| 71 | ASN1_CTX c; \ | ||
| 72 | type ret=NULL; \ | ||
| 73 | \ | ||
| 74 | c.pp=pp; \ | ||
| 75 | c.error=ASN1_R_ERROR_STACK; \ | ||
| 76 | if ((a == NULL) || ((*a) == NULL)) \ | ||
| 77 | { if ((ret=(type)func()) == NULL) goto err; } \ | ||
| 78 | else ret=(*a); | ||
| 79 | |||
| 80 | #define M_ASN1_D2I_Init() \ | ||
| 81 | c.p= *pp; \ | ||
| 82 | c.max=(length == 0)?0:(c.p+length); | ||
| 83 | |||
| 84 | #define M_ASN1_D2I_Finish_2(a) \ | ||
| 85 | if (!asn1_Finish(&c)) goto err; \ | ||
| 86 | *pp=c.p; \ | ||
| 87 | if (a != NULL) (*a)=ret; \ | ||
| 88 | return(ret); | ||
| 89 | |||
| 90 | #define M_ASN1_D2I_Finish(a,func,e) \ | ||
| 91 | M_ASN1_D2I_Finish_2(a); \ | ||
| 92 | err:\ | ||
| 93 | ASN1err((e),c.error); \ | ||
| 94 | asn1_add_error(*pp,(int)(c.q- *pp)); \ | ||
| 95 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \ | ||
| 96 | return(NULL) | ||
| 97 | |||
| 98 | #define M_ASN1_D2I_start_sequence() \ | ||
| 99 | if (!asn1_GetSequence(&c,&length)) goto err; | ||
| 100 | |||
| 101 | #define M_ASN1_D2I_end_sequence() \ | ||
| 102 | (((c.inf&1) == 0)?(c.slen <= 0): \ | ||
| 103 | (c.eos=ASN1_check_infinite_end(&c.p,c.slen))) | ||
| 104 | |||
| 105 | #define M_ASN1_D2I_get(b,func) \ | ||
| 106 | c.q=c.p; \ | ||
| 107 | if (func(&(b),&c.p,c.slen) == NULL) goto err; \ | ||
| 108 | c.slen-=(c.p-c.q); | ||
| 109 | |||
| 110 | #define M_ASN1_D2I_get_opt(b,func,type) \ | ||
| 111 | if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) \ | ||
| 112 | == (V_ASN1_UNIVERSAL|(type)))) \ | ||
| 113 | { \ | ||
| 114 | M_ASN1_D2I_get(b,func); \ | ||
| 115 | } | ||
| 116 | |||
| 117 | #define M_ASN1_D2I_get_IMP_opt(b,func,tag,type) \ | ||
| 118 | if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == \ | ||
| 119 | (V_ASN1_CONTEXT_SPECIFIC|(tag)))) \ | ||
| 120 | { \ | ||
| 121 | unsigned char tmp; \ | ||
| 122 | tmp=M_ASN1_next; \ | ||
| 123 | M_ASN1_next=(tmp& ~V_ASN1_PRIMATIVE_TAG)|type; \ | ||
| 124 | M_ASN1_D2I_get(b,func); \ | ||
| 125 | M_ASN1_next_prev=tmp; \ | ||
| 126 | } | ||
| 127 | |||
| 128 | #define M_ASN1_D2I_get_set(r,func) \ | ||
| 129 | M_ASN1_D2I_get_imp_set(r,func,V_ASN1_SET,V_ASN1_UNIVERSAL); | ||
| 130 | |||
| 131 | #define M_ASN1_D2I_get_IMP_set_opt(b,func,tag) \ | ||
| 132 | if ((c.slen != 0) && \ | ||
| 133 | (M_ASN1_next == \ | ||
| 134 | (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\ | ||
| 135 | { \ | ||
| 136 | M_ASN1_D2I_get_imp_set(b,func,tag,V_ASN1_CONTEXT_SPECIFIC); \ | ||
| 137 | } | ||
| 138 | |||
| 139 | #define M_ASN1_D2I_get_seq(r,func) \ | ||
| 140 | M_ASN1_D2I_get_imp_set(r,func,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); | ||
| 141 | |||
| 142 | #define M_ASN1_D2I_get_seq_opt(r,func) \ | ||
| 143 | if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ | ||
| 144 | V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\ | ||
| 145 | { M_ASN1_D2I_get_seq(r,func); } | ||
| 146 | |||
| 147 | #define M_ASN1_D2I_get_IMP_set(r,func,x) \ | ||
| 148 | M_ASN1_D2I_get_imp_set(r,func,x,V_ASN1_CONTEXT_SPECIFIC); | ||
| 149 | |||
| 150 | #define M_ASN1_D2I_get_imp_set(r,func,a,b) \ | ||
| 151 | c.q=c.p; \ | ||
| 152 | if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,a,b) == NULL) \ | ||
| 153 | goto err; \ | ||
| 154 | c.slen-=(c.p-c.q); | ||
| 155 | |||
| 156 | #define M_ASN1_D2I_get_set_strings(r,func,a,b) \ | ||
| 157 | c.q=c.p; \ | ||
| 158 | if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \ | ||
| 159 | goto err; \ | ||
| 160 | c.slen-=(c.p-c.q); | ||
| 161 | |||
| 162 | #define M_ASN1_D2I_get_EXP_opt(r,func,tag) \ | ||
| 163 | if ((c.slen != 0L) && (M_ASN1_next == \ | ||
| 164 | (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \ | ||
| 165 | { \ | ||
| 166 | int Tinf,Ttag,Tclass; \ | ||
| 167 | long Tlen; \ | ||
| 168 | \ | ||
| 169 | c.q=c.p; \ | ||
| 170 | Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ | ||
| 171 | if (Tinf & 0x80) \ | ||
| 172 | { c.error=ASN1_R_BAD_OBJECT_HEADER; goto err; } \ | ||
| 173 | if (func(&(r),&c.p,Tlen) == NULL) \ | ||
| 174 | goto err; \ | ||
| 175 | c.slen-=(c.p-c.q); \ | ||
| 176 | } | ||
| 177 | |||
| 178 | #define M_ASN1_D2I_get_EXP_set_opt(r,func,tag,b) \ | ||
| 179 | if ((c.slen != 0) && (M_ASN1_next == \ | ||
| 180 | (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \ | ||
| 181 | { \ | ||
| 182 | int Tinf,Ttag,Tclass; \ | ||
| 183 | long Tlen; \ | ||
| 184 | \ | ||
| 185 | c.q=c.p; \ | ||
| 186 | Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ | ||
| 187 | if (Tinf & 0x80) \ | ||
| 188 | { c.error=ASN1_R_BAD_OBJECT_HEADER; goto err; } \ | ||
| 189 | if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \ | ||
| 190 | b,V_ASN1_UNIVERSAL) == NULL) \ | ||
| 191 | goto err; \ | ||
| 192 | c.slen-=(c.p-c.q); \ | ||
| 193 | } | ||
| 194 | |||
| 195 | /* New macros */ | ||
| 196 | #define M_ASN1_New_Malloc(ret,type) \ | ||
| 197 | if ((ret=(type *)Malloc(sizeof(type))) == NULL) goto err2; | ||
| 198 | |||
| 199 | #define M_ASN1_New(arg,func) \ | ||
| 200 | if (((arg)=func()) == NULL) return(NULL) | ||
| 201 | |||
| 202 | #define M_ASN1_New_Error(a) \ | ||
| 203 | /* err: ASN1err((a),ASN1_R_ERROR_STACK); \ | ||
| 204 | return(NULL);*/ \ | ||
| 205 | err2: ASN1err((a),ERR_R_MALLOC_FAILURE); \ | ||
| 206 | return(NULL) | ||
| 207 | |||
| 208 | |||
| 209 | #define M_ASN1_next (*c.p) | ||
| 210 | #define M_ASN1_next_prev (*c.q) | ||
| 211 | |||
| 212 | /*************************************************/ | ||
| 213 | |||
| 214 | #define M_ASN1_I2D_vars(a) int r=0,ret=0; \ | ||
| 215 | unsigned char *p; \ | ||
| 216 | if (a == NULL) return(0) | ||
| 217 | |||
| 218 | /* Length Macros */ | ||
| 219 | #define M_ASN1_I2D_len(a,f) ret+=f(a,NULL) | ||
| 220 | #define M_ASN1_I2D_len_IMP_opt(a,f) if (a != NULL) M_ASN1_I2D_len(a,f) | ||
| 221 | |||
| 222 | #define M_ASN1_I2D_len_SET(a,f) \ | ||
| 223 | ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL); | ||
| 224 | |||
| 225 | #define M_ASN1_I2D_len_SEQ(a,f) \ | ||
| 226 | ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); | ||
| 227 | |||
| 228 | #define M_ASN1_I2D_len_SEQ_opt(a,f) \ | ||
| 229 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
| 230 | M_ASN1_I2D_len_SEQ(a,f); | ||
| 231 | |||
| 232 | #define M_ASN1_I2D_len_IMP_set(a,f,x) \ | ||
| 233 | ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC); | ||
| 234 | |||
| 235 | #define M_ASN1_I2D_len_IMP_set_opt(a,f,x) \ | ||
| 236 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
| 237 | ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC); | ||
| 238 | |||
| 239 | #define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \ | ||
| 240 | if (a != NULL)\ | ||
| 241 | { \ | ||
| 242 | v=f(a,NULL); \ | ||
| 243 | ret+=ASN1_object_size(1,v,mtag); \ | ||
| 244 | } | ||
| 245 | |||
| 246 | #define M_ASN1_I2D_len_EXP_set_opt(a,f,mtag,tag,v) \ | ||
| 247 | if ((a != NULL) && (sk_num(a) != 0))\ | ||
| 248 | { \ | ||
| 249 | v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL); \ | ||
| 250 | ret+=ASN1_object_size(1,v,mtag); \ | ||
| 251 | } | ||
| 252 | |||
| 253 | /* Put Macros */ | ||
| 254 | #define M_ASN1_I2D_put(a,f) f(a,&p) | ||
| 255 | |||
| 256 | #define M_ASN1_I2D_put_IMP_opt(a,f,t) \ | ||
| 257 | if (a != NULL) \ | ||
| 258 | { \ | ||
| 259 | unsigned char *q=p; \ | ||
| 260 | f(a,&p); \ | ||
| 261 | *q=(V_ASN1_CONTEXT_SPECIFIC|t|(*q&V_ASN1_CONSTRUCTED));\ | ||
| 262 | } | ||
| 263 | |||
| 264 | #define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\ | ||
| 265 | V_ASN1_UNIVERSAL) | ||
| 266 | #define M_ASN1_I2D_put_IMP_set(a,f,x) i2d_ASN1_SET(a,&p,f,x,\ | ||
| 267 | V_ASN1_CONTEXT_SPECIFIC) | ||
| 268 | |||
| 269 | #define M_ASN1_I2D_put_SEQ(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\ | ||
| 270 | V_ASN1_UNIVERSAL) | ||
| 271 | |||
| 272 | #define M_ASN1_I2D_put_SEQ_opt(a,f) \ | ||
| 273 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
| 274 | M_ASN1_I2D_put_SEQ(a,f); | ||
| 275 | |||
| 276 | #define M_ASN1_I2D_put_IMP_set_opt(a,f,x) \ | ||
| 277 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
| 278 | { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC); } | ||
| 279 | |||
| 280 | #define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \ | ||
| 281 | if (a != NULL) \ | ||
| 282 | { \ | ||
| 283 | ASN1_put_object(&p,1,v,tag,V_ASN1_CONTEXT_SPECIFIC); \ | ||
| 284 | f(a,&p); \ | ||
| 285 | } | ||
| 286 | |||
| 287 | #define M_ASN1_I2D_put_EXP_set_opt(a,f,mtag,tag,v) \ | ||
| 288 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
| 289 | { \ | ||
| 290 | ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \ | ||
| 291 | i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL); \ | ||
| 292 | } | ||
| 293 | |||
| 294 | #define M_ASN1_I2D_seq_total() \ | ||
| 295 | r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); \ | ||
| 296 | if (pp == NULL) return(r); \ | ||
| 297 | p= *pp; \ | ||
| 298 | ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL) | ||
| 299 | |||
| 300 | #define M_ASN1_I2D_INF_seq_start(tag,ctx) \ | ||
| 301 | *(p++)=(V_ASN1_CONSTRUCTED|(tag)|(ctx)); \ | ||
| 302 | *(p++)=0x80 | ||
| 303 | |||
| 304 | #define M_ASN1_I2D_INF_seq_end() *(p++)=0x00; *(p++)=0x00 | ||
| 305 | |||
| 306 | #define M_ASN1_I2D_finish() *pp=p; \ | ||
| 307 | return(r); | ||
| 308 | |||
| 309 | #ifndef NOPROTO | ||
| 310 | int asn1_GetSequence(ASN1_CTX *c, long *length); | ||
| 311 | void asn1_add_error(unsigned char *address,int offset); | ||
| 312 | #else | ||
| 313 | int asn1_GetSequence(); | ||
| 314 | void asn1_add_error(); | ||
| 315 | #endif | ||
| 316 | |||
| 317 | #ifdef __cplusplus | ||
| 318 | } | ||
| 319 | #endif | ||
| 320 | |||
| 321 | #endif | ||
diff --git a/src/lib/libcrypto/asn1/asn1_par.c b/src/lib/libcrypto/asn1/asn1_par.c new file mode 100644 index 0000000000..3906227d21 --- /dev/null +++ b/src/lib/libcrypto/asn1/asn1_par.c | |||
| @@ -0,0 +1,393 @@ | |||
| 1 | /* crypto/asn1/asn1_par.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 "buffer.h" | ||
| 62 | #include "objects.h" | ||
| 63 | #include "x509.h" | ||
| 64 | |||
| 65 | #ifndef NOPROTO | ||
| 66 | static int asn1_print_info(BIO *bp, int tag, int xclass,int constructed, | ||
| 67 | int indent); | ||
| 68 | static int asn1_parse2(BIO *bp, unsigned char **pp, long length, | ||
| 69 | int offset, int depth, int indent); | ||
| 70 | #else | ||
| 71 | static int asn1_print_info(); | ||
| 72 | static int asn1_parse2(); | ||
| 73 | #endif | ||
| 74 | |||
| 75 | static int asn1_print_info(bp, tag, xclass, constructed,indent) | ||
| 76 | BIO *bp; | ||
| 77 | int tag; | ||
| 78 | int xclass; | ||
| 79 | int constructed; | ||
| 80 | int indent; | ||
| 81 | { | ||
| 82 | static char *fmt="%-18s"; | ||
| 83 | static char *fmt2="%2d %-15s"; | ||
| 84 | char *p,str[128],*p2=NULL; | ||
| 85 | |||
| 86 | if (constructed & V_ASN1_CONSTRUCTED) | ||
| 87 | p="cons: "; | ||
| 88 | else | ||
| 89 | p="prim: "; | ||
| 90 | if (BIO_write(bp,p,6) < 6) goto err; | ||
| 91 | if (indent) | ||
| 92 | { | ||
| 93 | if (indent > 128) indent=128; | ||
| 94 | memset(str,' ',indent); | ||
| 95 | if (BIO_write(bp,str,indent) < indent) goto err; | ||
| 96 | } | ||
| 97 | |||
| 98 | p=str; | ||
| 99 | if ((xclass & V_ASN1_PRIVATE) == V_ASN1_PRIVATE) | ||
| 100 | sprintf(str,"priv [ %d ] ",tag); | ||
| 101 | else if ((xclass & V_ASN1_CONTEXT_SPECIFIC) == V_ASN1_CONTEXT_SPECIFIC) | ||
| 102 | sprintf(str,"cont [ %d ]",tag); | ||
| 103 | else if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION) | ||
| 104 | sprintf(str,"appl [ %d ]",tag); | ||
| 105 | else if ((tag == V_ASN1_EOC) /* && (xclass == V_ASN1_UNIVERSAL) */) | ||
| 106 | p="EOC"; | ||
| 107 | else if (tag == V_ASN1_BOOLEAN) | ||
| 108 | p="BOOLEAN"; | ||
| 109 | else if (tag == V_ASN1_INTEGER) | ||
| 110 | p="INTEGER"; | ||
| 111 | else if (tag == V_ASN1_BIT_STRING) | ||
| 112 | p="BIT STRING"; | ||
| 113 | else if (tag == V_ASN1_OCTET_STRING) | ||
| 114 | p="OCTET STRING"; | ||
| 115 | else if (tag == V_ASN1_NULL) | ||
| 116 | p="NULL"; | ||
| 117 | else if (tag == V_ASN1_OBJECT) | ||
| 118 | p="OBJECT"; | ||
| 119 | else if (tag == V_ASN1_SEQUENCE) | ||
| 120 | p="SEQUENCE"; | ||
| 121 | else if (tag == V_ASN1_SET) | ||
| 122 | p="SET"; | ||
| 123 | else if (tag == V_ASN1_PRINTABLESTRING) | ||
| 124 | p="PRINTABLESTRING"; | ||
| 125 | else if (tag == V_ASN1_T61STRING) | ||
| 126 | p="T61STRING"; | ||
| 127 | else if (tag == V_ASN1_IA5STRING) | ||
| 128 | p="IA5STRING"; | ||
| 129 | else if (tag == V_ASN1_UTCTIME) | ||
| 130 | p="UTCTIME"; | ||
| 131 | |||
| 132 | /* extras */ | ||
| 133 | else if (tag == V_ASN1_NUMERICSTRING) | ||
| 134 | p="NUMERICSTRING"; | ||
| 135 | else if (tag == V_ASN1_VIDEOTEXSTRING) | ||
| 136 | p="VIDEOTEXSTRING"; | ||
| 137 | else if (tag == V_ASN1_GENERALIZEDTIME) | ||
| 138 | p="GENERALIZEDTIME"; | ||
| 139 | else if (tag == V_ASN1_GRAPHICSTRING) | ||
| 140 | p="GRAPHICSTRING"; | ||
| 141 | else if (tag == V_ASN1_ISO64STRING) | ||
| 142 | p="ISO64STRING"; | ||
| 143 | else if (tag == V_ASN1_GENERALSTRING) | ||
| 144 | p="GENERALSTRING"; | ||
| 145 | else if (tag == V_ASN1_UNIVERSALSTRING) | ||
| 146 | p="UNIVERSALSTRING"; | ||
| 147 | else if (tag == V_ASN1_BMPSTRING) | ||
| 148 | p="BMPSTRING"; | ||
| 149 | else | ||
| 150 | p2="(unknown)"; | ||
| 151 | |||
| 152 | if (p2 != NULL) | ||
| 153 | { | ||
| 154 | if (BIO_printf(bp,fmt2,tag,p2) <= 0) goto err; | ||
| 155 | } | ||
| 156 | else | ||
| 157 | { | ||
| 158 | if (BIO_printf(bp,fmt,p) <= 0) goto err; | ||
| 159 | } | ||
| 160 | return(1); | ||
| 161 | err: | ||
| 162 | return(0); | ||
| 163 | } | ||
| 164 | |||
| 165 | int ASN1_parse(bp, pp, len, indent) | ||
| 166 | BIO *bp; | ||
| 167 | unsigned char *pp; | ||
| 168 | long len; | ||
| 169 | int indent; | ||
| 170 | { | ||
| 171 | return(asn1_parse2(bp,&pp,len,0,0,indent)); | ||
| 172 | } | ||
| 173 | |||
| 174 | static int asn1_parse2(bp, pp, length, offset, depth, indent) | ||
| 175 | BIO *bp; | ||
| 176 | unsigned char **pp; | ||
| 177 | long length; | ||
| 178 | int offset; | ||
| 179 | int depth; | ||
| 180 | int indent; | ||
| 181 | { | ||
| 182 | unsigned char *p,*ep,*tot,*op,*opp; | ||
| 183 | long len; | ||
| 184 | int tag,xclass,ret=0; | ||
| 185 | int nl,hl,j,r; | ||
| 186 | ASN1_OBJECT *o=NULL; | ||
| 187 | ASN1_OCTET_STRING *os=NULL; | ||
| 188 | /* ASN1_BMPSTRING *bmp=NULL;*/ | ||
| 189 | |||
| 190 | p= *pp; | ||
| 191 | tot=p+length; | ||
| 192 | op=p-1; | ||
| 193 | while ((p < tot) && (op < p)) | ||
| 194 | { | ||
| 195 | op=p; | ||
| 196 | j=ASN1_get_object(&p,&len,&tag,&xclass,length); | ||
| 197 | #ifdef LINT | ||
| 198 | j=j; | ||
| 199 | #endif | ||
| 200 | if (j & 0x80) | ||
| 201 | { | ||
| 202 | if (BIO_write(bp,"Error in encoding\n",18) <= 0) | ||
| 203 | goto end; | ||
| 204 | ret=0; | ||
| 205 | goto end; | ||
| 206 | } | ||
| 207 | hl=(p-op); | ||
| 208 | length-=hl; | ||
| 209 | /* if j == 0x21 it is a constructed indefinite length object */ | ||
| 210 | if (BIO_printf(bp,"%5ld:",(long)offset+(long)(op- *pp)) | ||
| 211 | <= 0) goto end; | ||
| 212 | |||
| 213 | if (j != (V_ASN1_CONSTRUCTED | 1)) | ||
| 214 | { | ||
| 215 | if (BIO_printf(bp,"d=%-2d hl=%ld l=%4ld ", | ||
| 216 | depth,(long)hl,len) <= 0) | ||
| 217 | goto end; | ||
| 218 | } | ||
| 219 | else | ||
| 220 | { | ||
| 221 | if (BIO_printf(bp,"d=%-2d hl=%ld l=inf ", | ||
| 222 | depth,(long)hl) <= 0) | ||
| 223 | goto end; | ||
| 224 | } | ||
| 225 | if (!asn1_print_info(bp,tag,xclass,j,(indent)?depth:0)) | ||
| 226 | goto end; | ||
| 227 | if (j & V_ASN1_CONSTRUCTED) | ||
| 228 | { | ||
| 229 | ep=p+len; | ||
| 230 | if (BIO_write(bp,"\n",1) <= 0) goto end; | ||
| 231 | if (len > length) | ||
| 232 | { | ||
| 233 | BIO_printf(bp, | ||
| 234 | "length is greater than %ld\n",length); | ||
| 235 | ret=0; | ||
| 236 | goto end; | ||
| 237 | } | ||
| 238 | if ((j == 0x21) && (len == 0)) | ||
| 239 | { | ||
| 240 | for (;;) | ||
| 241 | { | ||
| 242 | r=asn1_parse2(bp,&p,(long)(tot-p), | ||
| 243 | offset+(p - *pp),depth+1, | ||
| 244 | indent); | ||
| 245 | if (r == 0) { ret=0; goto end; } | ||
| 246 | if ((r == 2) || (p >= tot)) break; | ||
| 247 | } | ||
| 248 | } | ||
| 249 | else | ||
| 250 | while (p < ep) | ||
| 251 | { | ||
| 252 | r=asn1_parse2(bp,&p,(long)len, | ||
| 253 | offset+(p - *pp),depth+1, | ||
| 254 | indent); | ||
| 255 | if (r == 0) { ret=0; goto end; } | ||
| 256 | } | ||
| 257 | } | ||
| 258 | else if (xclass != 0) | ||
| 259 | { | ||
| 260 | p+=len; | ||
| 261 | if (BIO_write(bp,"\n",1) <= 0) goto end; | ||
| 262 | } | ||
| 263 | else | ||
| 264 | { | ||
| 265 | nl=0; | ||
| 266 | if ( (tag == V_ASN1_PRINTABLESTRING) || | ||
| 267 | (tag == V_ASN1_T61STRING) || | ||
| 268 | (tag == V_ASN1_IA5STRING) || | ||
| 269 | (tag == V_ASN1_UTCTIME)) | ||
| 270 | { | ||
| 271 | if (BIO_write(bp,":",1) <= 0) goto end; | ||
| 272 | if ((len > 0) && | ||
| 273 | BIO_write(bp,(char *)p,(int)len) | ||
| 274 | != (int)len) | ||
| 275 | goto end; | ||
| 276 | } | ||
| 277 | else if (tag == V_ASN1_OBJECT) | ||
| 278 | { | ||
| 279 | opp=op; | ||
| 280 | if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL) | ||
| 281 | { | ||
| 282 | if (BIO_write(bp,":",1) <= 0) goto end; | ||
| 283 | i2a_ASN1_OBJECT(bp,o); | ||
| 284 | } | ||
| 285 | else | ||
| 286 | { | ||
| 287 | if (BIO_write(bp,":BAD OBJECT",11) <= 0) | ||
| 288 | goto end; | ||
| 289 | } | ||
| 290 | } | ||
| 291 | else if (tag == V_ASN1_BOOLEAN) | ||
| 292 | { | ||
| 293 | int ii; | ||
| 294 | |||
| 295 | opp=op; | ||
| 296 | ii=d2i_ASN1_BOOLEAN(NULL,&opp,len+hl); | ||
| 297 | if (ii < 0) | ||
| 298 | { | ||
| 299 | if (BIO_write(bp,"Bad boolean\n",12)) | ||
| 300 | goto end; | ||
| 301 | } | ||
| 302 | BIO_printf(bp,":%d",ii); | ||
| 303 | } | ||
| 304 | else if (tag == V_ASN1_BMPSTRING) | ||
| 305 | { | ||
| 306 | /* do the BMP thang */ | ||
| 307 | } | ||
| 308 | else if (tag == V_ASN1_OCTET_STRING) | ||
| 309 | { | ||
| 310 | int i,printable=1; | ||
| 311 | |||
| 312 | opp=op; | ||
| 313 | os=d2i_ASN1_OCTET_STRING(NULL,&opp,len+hl); | ||
| 314 | if (os != NULL) | ||
| 315 | { | ||
| 316 | opp=os->data; | ||
| 317 | for (i=0; i<os->length; i++) | ||
| 318 | { | ||
| 319 | if (( (opp[i] < ' ') && | ||
| 320 | (opp[i] != '\n') && | ||
| 321 | (opp[i] != '\r') && | ||
| 322 | (opp[i] != '\t')) || | ||
| 323 | (opp[i] > '~')) | ||
| 324 | { | ||
| 325 | printable=0; | ||
| 326 | break; | ||
| 327 | } | ||
| 328 | } | ||
| 329 | if (printable && (os->length > 0)) | ||
| 330 | { | ||
| 331 | if (BIO_write(bp,":",1) <= 0) | ||
| 332 | goto end; | ||
| 333 | if (BIO_write(bp,(char *)opp, | ||
| 334 | os->length) <= 0) | ||
| 335 | goto end; | ||
| 336 | } | ||
| 337 | ASN1_OCTET_STRING_free(os); | ||
| 338 | os=NULL; | ||
| 339 | } | ||
| 340 | } | ||
| 341 | else if (tag == V_ASN1_INTEGER) | ||
| 342 | { | ||
| 343 | ASN1_INTEGER *bs; | ||
| 344 | int i; | ||
| 345 | |||
| 346 | opp=op; | ||
| 347 | bs=d2i_ASN1_INTEGER(NULL,&opp,len+hl); | ||
| 348 | if (bs != NULL) | ||
| 349 | { | ||
| 350 | if (BIO_write(bp,":",1) <= 0) goto end; | ||
| 351 | if (bs->type == V_ASN1_NEG_INTEGER) | ||
| 352 | if (BIO_write(bp,"-",1) <= 0) | ||
| 353 | goto end; | ||
| 354 | for (i=0; i<bs->length; i++) | ||
| 355 | { | ||
| 356 | if (BIO_printf(bp,"%02X", | ||
| 357 | bs->data[i]) <= 0) | ||
| 358 | goto end; | ||
| 359 | } | ||
| 360 | if (bs->length == 0) | ||
| 361 | { | ||
| 362 | if (BIO_write(bp,"00",2) <= 0) | ||
| 363 | goto end; | ||
| 364 | } | ||
| 365 | } | ||
| 366 | else | ||
| 367 | { | ||
| 368 | if (BIO_write(bp,"BAD INTEGER",11) <= 0) | ||
| 369 | goto end; | ||
| 370 | } | ||
| 371 | ASN1_INTEGER_free(bs); | ||
| 372 | } | ||
| 373 | |||
| 374 | if (!nl) | ||
| 375 | { | ||
| 376 | if (BIO_write(bp,"\n",1) <= 0) goto end; | ||
| 377 | } | ||
| 378 | p+=len; | ||
| 379 | if ((tag == V_ASN1_EOC) && (xclass == 0)) | ||
| 380 | { | ||
| 381 | ret=2; /* End of sequence */ | ||
| 382 | goto end; | ||
| 383 | } | ||
| 384 | } | ||
| 385 | length-=len; | ||
| 386 | } | ||
| 387 | ret=1; | ||
| 388 | end: | ||
| 389 | if (o != NULL) ASN1_OBJECT_free(o); | ||
| 390 | if (os != NULL) ASN1_OCTET_STRING_free(os); | ||
| 391 | *pp=p; | ||
| 392 | return(ret); | ||
| 393 | } | ||
diff --git a/src/lib/libcrypto/asn1/d2i_pr.c b/src/lib/libcrypto/asn1/d2i_pr.c new file mode 100644 index 0000000000..b9eaa9629b --- /dev/null +++ b/src/lib/libcrypto/asn1/d2i_pr.c | |||
| @@ -0,0 +1,117 @@ | |||
| 1 | /* crypto/asn1/d2i_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 "evp.h" | ||
| 63 | #include "objects.h" | ||
| 64 | #include "x509.h" | ||
| 65 | |||
| 66 | EVP_PKEY *d2i_PrivateKey(type,a,pp,length) | ||
| 67 | int type; | ||
| 68 | EVP_PKEY **a; | ||
| 69 | unsigned char **pp; | ||
| 70 | long length; | ||
| 71 | { | ||
| 72 | EVP_PKEY *ret; | ||
| 73 | |||
| 74 | if ((a == NULL) || (*a == NULL)) | ||
| 75 | { | ||
| 76 | if ((ret=EVP_PKEY_new()) == NULL) | ||
| 77 | { | ||
| 78 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_EVP_LIB); | ||
| 79 | return(NULL); | ||
| 80 | } | ||
| 81 | } | ||
| 82 | else ret= *a; | ||
| 83 | |||
| 84 | ret->save_type=type; | ||
| 85 | ret->type=EVP_PKEY_type(type); | ||
| 86 | switch (ret->type) | ||
| 87 | { | ||
| 88 | #ifndef NO_RSA | ||
| 89 | case EVP_PKEY_RSA: | ||
| 90 | if ((ret->pkey.rsa=d2i_RSAPrivateKey(NULL,pp,length)) == NULL) | ||
| 91 | { | ||
| 92 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB); | ||
| 93 | goto err; | ||
| 94 | } | ||
| 95 | break; | ||
| 96 | #endif | ||
| 97 | #ifndef NO_DSA | ||
| 98 | case EVP_PKEY_DSA: | ||
| 99 | if ((ret->pkey.dsa=d2i_DSAPrivateKey(NULL,pp,length)) == NULL) | ||
| 100 | { | ||
| 101 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB); | ||
| 102 | goto err; | ||
| 103 | } | ||
| 104 | break; | ||
| 105 | #endif | ||
| 106 | default: | ||
| 107 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); | ||
| 108 | goto err; | ||
| 109 | break; | ||
| 110 | } | ||
| 111 | if (a != NULL) (*a)=ret; | ||
| 112 | return(ret); | ||
| 113 | err: | ||
| 114 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret); | ||
| 115 | return(NULL); | ||
| 116 | } | ||
| 117 | |||
diff --git a/src/lib/libcrypto/asn1/d2i_pu.c b/src/lib/libcrypto/asn1/d2i_pu.c new file mode 100644 index 0000000000..5d6192f1e5 --- /dev/null +++ b/src/lib/libcrypto/asn1/d2i_pu.c | |||
| @@ -0,0 +1,117 @@ | |||
| 1 | /* crypto/asn1/d2i_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 "evp.h" | ||
| 63 | #include "objects.h" | ||
| 64 | #include "x509.h" | ||
| 65 | |||
| 66 | EVP_PKEY *d2i_PublicKey(type,a,pp,length) | ||
| 67 | int type; | ||
| 68 | EVP_PKEY **a; | ||
| 69 | unsigned char **pp; | ||
| 70 | long length; | ||
| 71 | { | ||
| 72 | EVP_PKEY *ret; | ||
| 73 | |||
| 74 | if ((a == NULL) || (*a == NULL)) | ||
| 75 | { | ||
| 76 | if ((ret=EVP_PKEY_new()) == NULL) | ||
| 77 | { | ||
| 78 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB); | ||
| 79 | return(NULL); | ||
| 80 | } | ||
| 81 | } | ||
| 82 | else ret= *a; | ||
| 83 | |||
| 84 | ret->save_type=type; | ||
| 85 | ret->type=EVP_PKEY_type(type); | ||
| 86 | switch (ret->type) | ||
| 87 | { | ||
| 88 | #ifndef NO_RSA | ||
| 89 | case EVP_PKEY_RSA: | ||
| 90 | if ((ret->pkey.rsa=d2i_RSAPublicKey(NULL,pp,length)) == NULL) | ||
| 91 | { | ||
| 92 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB); | ||
| 93 | goto err; | ||
| 94 | } | ||
| 95 | break; | ||
| 96 | #endif | ||
| 97 | #ifndef NO_DSA | ||
| 98 | case EVP_PKEY_DSA: | ||
| 99 | if ((ret->pkey.dsa=d2i_DSAPublicKey(NULL,pp,length)) == NULL) | ||
| 100 | { | ||
| 101 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB); | ||
| 102 | goto err; | ||
| 103 | } | ||
| 104 | break; | ||
| 105 | #endif | ||
| 106 | default: | ||
| 107 | ASN1err(ASN1_F_D2I_PUBLICKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); | ||
| 108 | goto err; | ||
| 109 | break; | ||
| 110 | } | ||
| 111 | if (a != NULL) (*a)=ret; | ||
| 112 | return(ret); | ||
| 113 | err: | ||
| 114 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret); | ||
| 115 | return(NULL); | ||
| 116 | } | ||
| 117 | |||
diff --git a/src/lib/libcrypto/asn1/evp_asn1.c b/src/lib/libcrypto/asn1/evp_asn1.c new file mode 100644 index 0000000000..ebe34a3362 --- /dev/null +++ b/src/lib/libcrypto/asn1/evp_asn1.c | |||
| @@ -0,0 +1,193 @@ | |||
| 1 | /* crypto/asn1/evp_asn1.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 | #include "asn1_mac.h" | ||
| 63 | |||
| 64 | int ASN1_TYPE_set_octetstring(a,data,len) | ||
| 65 | ASN1_TYPE *a; | ||
| 66 | unsigned char *data; | ||
| 67 | int len; | ||
| 68 | { | ||
| 69 | ASN1_STRING *os; | ||
| 70 | |||
| 71 | if ((os=ASN1_OCTET_STRING_new()) == NULL) return(0); | ||
| 72 | if (!ASN1_OCTET_STRING_set(os,data,len)) return(0); | ||
| 73 | ASN1_TYPE_set(a,V_ASN1_OCTET_STRING,(char *)os); | ||
| 74 | return(1); | ||
| 75 | } | ||
| 76 | |||
| 77 | int ASN1_TYPE_get_octetstring(a,data,max_len) | ||
| 78 | ASN1_TYPE *a; | ||
| 79 | unsigned char *data; | ||
| 80 | int max_len; /* for returned value */ | ||
| 81 | { | ||
| 82 | int ret,num; | ||
| 83 | unsigned char *p; | ||
| 84 | |||
| 85 | if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL)) | ||
| 86 | { | ||
| 87 | ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING,ASN1_R_DATA_IS_WRONG); | ||
| 88 | return(-1); | ||
| 89 | } | ||
| 90 | p=ASN1_STRING_data(a->value.octet_string); | ||
| 91 | ret=ASN1_STRING_length(a->value.octet_string); | ||
| 92 | if (ret < max_len) | ||
| 93 | num=ret; | ||
| 94 | else | ||
| 95 | num=max_len; | ||
| 96 | memcpy(data,p,num); | ||
| 97 | return(ret); | ||
| 98 | } | ||
| 99 | |||
| 100 | int ASN1_TYPE_set_int_octetstring(a,num,data,len) | ||
| 101 | ASN1_TYPE *a; | ||
| 102 | long num; | ||
| 103 | unsigned char *data; | ||
| 104 | int len; | ||
| 105 | { | ||
| 106 | int n,size; | ||
| 107 | ASN1_OCTET_STRING os,*osp; | ||
| 108 | ASN1_INTEGER in; | ||
| 109 | unsigned char *p; | ||
| 110 | unsigned char buf[32]; /* when they have 256bit longs, | ||
| 111 | * I'll be in trouble */ | ||
| 112 | in.data=buf; | ||
| 113 | in.length=32; | ||
| 114 | os.data=data; | ||
| 115 | os.type=V_ASN1_OCTET_STRING; | ||
| 116 | os.length=len; | ||
| 117 | ASN1_INTEGER_set(&in,num); | ||
| 118 | n = i2d_ASN1_INTEGER(&in,NULL); | ||
| 119 | n+=M_i2d_ASN1_OCTET_STRING(&os,NULL); | ||
| 120 | |||
| 121 | size=ASN1_object_size(1,n,V_ASN1_SEQUENCE); | ||
| 122 | |||
| 123 | if ((osp=ASN1_STRING_new()) == NULL) return(0); | ||
| 124 | /* Grow the 'string' */ | ||
| 125 | ASN1_STRING_set(osp,NULL,size); | ||
| 126 | |||
| 127 | ASN1_STRING_length(osp)=size; | ||
| 128 | p=ASN1_STRING_data(osp); | ||
| 129 | |||
| 130 | ASN1_put_object(&p,1,n,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); | ||
| 131 | i2d_ASN1_INTEGER(&in,&p); | ||
| 132 | M_i2d_ASN1_OCTET_STRING(&os,&p); | ||
| 133 | |||
| 134 | ASN1_TYPE_set(a,V_ASN1_SEQUENCE,(char *)osp); | ||
| 135 | return(1); | ||
| 136 | } | ||
| 137 | |||
| 138 | /* we return the actual length... */ | ||
| 139 | int ASN1_TYPE_get_int_octetstring(a,num,data,max_len) | ||
| 140 | ASN1_TYPE *a; | ||
| 141 | long *num; | ||
| 142 | unsigned char *data; | ||
| 143 | int max_len; /* for returned value */ | ||
| 144 | { | ||
| 145 | int ret= -1,n; | ||
| 146 | ASN1_INTEGER *ai=NULL; | ||
| 147 | ASN1_OCTET_STRING *os=NULL; | ||
| 148 | unsigned char *p; | ||
| 149 | long length; | ||
| 150 | ASN1_CTX c; | ||
| 151 | |||
| 152 | if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL)) | ||
| 153 | { | ||
| 154 | goto err; | ||
| 155 | } | ||
| 156 | p=ASN1_STRING_data(a->value.sequence); | ||
| 157 | length=ASN1_STRING_length(a->value.sequence); | ||
| 158 | |||
| 159 | c.pp= &p; | ||
| 160 | c.p=p; | ||
| 161 | c.max=p+length; | ||
| 162 | c.error=ASN1_R_DATA_IS_WRONG; | ||
| 163 | |||
| 164 | M_ASN1_D2I_start_sequence(); | ||
| 165 | c.q=c.p; | ||
| 166 | if ((ai=d2i_ASN1_INTEGER(NULL,&c.p,c.slen)) == NULL) goto err; | ||
| 167 | c.slen-=(c.p-c.q); | ||
| 168 | c.q=c.p; | ||
| 169 | if ((os=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL) goto err; | ||
| 170 | c.slen-=(c.p-c.q); | ||
| 171 | if (!M_ASN1_D2I_end_sequence()) goto err; | ||
| 172 | |||
| 173 | if (num != NULL) | ||
| 174 | *num=ASN1_INTEGER_get(ai); | ||
| 175 | |||
| 176 | ret=ASN1_STRING_length(os); | ||
| 177 | if (max_len > ret) | ||
| 178 | n=ret; | ||
| 179 | else | ||
| 180 | n=max_len; | ||
| 181 | |||
| 182 | if (data != NULL) | ||
| 183 | memcpy(data,ASN1_STRING_data(os),n); | ||
| 184 | if (0) | ||
| 185 | { | ||
| 186 | err: | ||
| 187 | ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,ASN1_R_DATA_IS_WRONG); | ||
| 188 | } | ||
| 189 | if (os != NULL) ASN1_OCTET_STRING_free(os); | ||
| 190 | if (ai != NULL) ASN1_INTEGER_free(ai); | ||
| 191 | return(ret); | ||
| 192 | } | ||
| 193 | |||
diff --git a/src/lib/libcrypto/asn1/f_int.c b/src/lib/libcrypto/asn1/f_int.c new file mode 100644 index 0000000000..4817c45cb7 --- /dev/null +++ b/src/lib/libcrypto/asn1/f_int.c | |||
| @@ -0,0 +1,211 @@ | |||
| 1 | /* crypto/asn1/f_int.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 "buffer.h" | ||
| 62 | #include "x509.h" | ||
| 63 | |||
| 64 | int i2a_ASN1_INTEGER(bp, a) | ||
| 65 | BIO *bp; | ||
| 66 | ASN1_INTEGER *a; | ||
| 67 | { | ||
| 68 | int i,n=0; | ||
| 69 | static char *h="0123456789ABCDEF"; | ||
| 70 | char buf[2]; | ||
| 71 | |||
| 72 | if (a == NULL) return(0); | ||
| 73 | |||
| 74 | if (a->length == 0) | ||
| 75 | { | ||
| 76 | if (BIO_write(bp,"00",2) != 2) goto err; | ||
| 77 | n=2; | ||
| 78 | } | ||
| 79 | else | ||
| 80 | { | ||
| 81 | for (i=0; i<a->length; i++) | ||
| 82 | { | ||
| 83 | if ((i != 0) && (i%35 == 0)) | ||
| 84 | { | ||
| 85 | if (BIO_write(bp,"\\\n",2) != 2) goto err; | ||
| 86 | n+=2; | ||
| 87 | } | ||
| 88 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; | ||
| 89 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; | ||
| 90 | if (BIO_write(bp,buf,2) != 2) goto err; | ||
| 91 | n+=2; | ||
| 92 | } | ||
| 93 | } | ||
| 94 | return(n); | ||
| 95 | err: | ||
| 96 | return(-1); | ||
| 97 | } | ||
| 98 | |||
| 99 | int a2i_ASN1_INTEGER(bp,bs,buf,size) | ||
| 100 | BIO *bp; | ||
| 101 | ASN1_INTEGER *bs; | ||
| 102 | char *buf; | ||
| 103 | int size; | ||
| 104 | { | ||
| 105 | int ret=0; | ||
| 106 | int i,j,k,m,n,again,bufsize; | ||
| 107 | unsigned char *s=NULL,*sp; | ||
| 108 | unsigned char *bufp; | ||
| 109 | int num=0,slen=0,first=1; | ||
| 110 | |||
| 111 | bs->type=V_ASN1_INTEGER; | ||
| 112 | |||
| 113 | bufsize=BIO_gets(bp,buf,size); | ||
| 114 | for (;;) | ||
| 115 | { | ||
| 116 | if (bufsize < 1) goto err_sl; | ||
| 117 | i=bufsize; | ||
| 118 | if (buf[i-1] == '\n') buf[--i]='\0'; | ||
| 119 | if (i == 0) goto err_sl; | ||
| 120 | if (buf[i-1] == '\r') buf[--i]='\0'; | ||
| 121 | if (i == 0) goto err_sl; | ||
| 122 | again=(buf[i-1] == '\\'); | ||
| 123 | |||
| 124 | for (j=0; j<i; j++) | ||
| 125 | { | ||
| 126 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || | ||
| 127 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || | ||
| 128 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) | ||
| 129 | { | ||
| 130 | i=j; | ||
| 131 | break; | ||
| 132 | } | ||
| 133 | } | ||
| 134 | buf[i]='\0'; | ||
| 135 | /* We have now cleared all the crap off the end of the | ||
| 136 | * line */ | ||
| 137 | if (i < 2) goto err_sl; | ||
| 138 | |||
| 139 | bufp=(unsigned char *)buf; | ||
| 140 | if (first) | ||
| 141 | { | ||
| 142 | first=0; | ||
| 143 | if ((bufp[0] == '0') && (buf[1] == '0')) | ||
| 144 | { | ||
| 145 | bufp+=2; | ||
| 146 | i-=2; | ||
| 147 | } | ||
| 148 | } | ||
| 149 | k=0; | ||
| 150 | i-=again; | ||
| 151 | if (i%2 != 0) | ||
| 152 | { | ||
| 153 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_ODD_NUMBER_OF_CHARS); | ||
| 154 | goto err; | ||
| 155 | } | ||
| 156 | i/=2; | ||
| 157 | if (num+i > slen) | ||
| 158 | { | ||
| 159 | if (s == NULL) | ||
| 160 | sp=(unsigned char *)Malloc( | ||
| 161 | (unsigned int)num+i*2); | ||
| 162 | else | ||
| 163 | sp=(unsigned char *)Realloc(s, | ||
| 164 | (unsigned int)num+i*2); | ||
| 165 | if (sp == NULL) | ||
| 166 | { | ||
| 167 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); | ||
| 168 | if (s != NULL) Free((char *)s); | ||
| 169 | goto err; | ||
| 170 | } | ||
| 171 | s=sp; | ||
| 172 | slen=num+i*2; | ||
| 173 | } | ||
| 174 | for (j=0; j<i; j++,k+=2) | ||
| 175 | { | ||
| 176 | for (n=0; n<2; n++) | ||
| 177 | { | ||
| 178 | m=bufp[k+n]; | ||
| 179 | if ((m >= '0') && (m <= '9')) | ||
| 180 | m-='0'; | ||
| 181 | else if ((m >= 'a') && (m <= 'f')) | ||
| 182 | m=m-'a'+10; | ||
| 183 | else if ((m >= 'A') && (m <= 'F')) | ||
| 184 | m=m-'A'+10; | ||
| 185 | else | ||
| 186 | { | ||
| 187 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_NON_HEX_CHARACTERS); | ||
| 188 | goto err; | ||
| 189 | } | ||
| 190 | s[num+j]<<=4; | ||
| 191 | s[num+j]|=m; | ||
| 192 | } | ||
| 193 | } | ||
| 194 | num+=i; | ||
| 195 | if (again) | ||
| 196 | bufsize=BIO_gets(bp,buf,size); | ||
| 197 | else | ||
| 198 | break; | ||
| 199 | } | ||
| 200 | bs->length=num; | ||
| 201 | bs->data=s; | ||
| 202 | ret=1; | ||
| 203 | err: | ||
| 204 | if (0) | ||
| 205 | { | ||
| 206 | err_sl: | ||
| 207 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_SHORT_LINE); | ||
| 208 | } | ||
| 209 | return(ret); | ||
| 210 | } | ||
| 211 | |||
diff --git a/src/lib/libcrypto/asn1/f_string.c b/src/lib/libcrypto/asn1/f_string.c new file mode 100644 index 0000000000..ab2837824e --- /dev/null +++ b/src/lib/libcrypto/asn1/f_string.c | |||
| @@ -0,0 +1,210 @@ | |||
| 1 | /* crypto/asn1/f_string.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 "buffer.h" | ||
| 62 | #include "x509.h" | ||
| 63 | |||
| 64 | int i2a_ASN1_STRING(bp, a, type) | ||
| 65 | BIO *bp; | ||
| 66 | ASN1_STRING *a; | ||
| 67 | int type; | ||
| 68 | { | ||
| 69 | int i,n=0; | ||
| 70 | static char *h="0123456789ABCDEF"; | ||
| 71 | char buf[2]; | ||
| 72 | |||
| 73 | if (a == NULL) return(0); | ||
| 74 | |||
| 75 | if (a->length == 0) | ||
| 76 | { | ||
| 77 | if (BIO_write(bp,"0",1) != 1) goto err; | ||
| 78 | n=1; | ||
| 79 | } | ||
| 80 | else | ||
| 81 | { | ||
| 82 | for (i=0; i<a->length; i++) | ||
| 83 | { | ||
| 84 | if ((i != 0) && (i%35 == 0)) | ||
| 85 | { | ||
| 86 | if (BIO_write(bp,"\\\n",2) != 2) goto err; | ||
| 87 | n+=2; | ||
| 88 | } | ||
| 89 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; | ||
| 90 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; | ||
| 91 | if (BIO_write(bp,buf,2) != 2) goto err; | ||
| 92 | n+=2; | ||
| 93 | } | ||
| 94 | } | ||
| 95 | return(n); | ||
| 96 | err: | ||
| 97 | return(-1); | ||
| 98 | } | ||
| 99 | |||
| 100 | int a2i_ASN1_STRING(bp,bs,buf,size) | ||
| 101 | BIO *bp; | ||
| 102 | ASN1_STRING *bs; | ||
| 103 | char *buf; | ||
| 104 | int size; | ||
| 105 | { | ||
| 106 | int ret=0; | ||
| 107 | int i,j,k,m,n,again,bufsize; | ||
| 108 | unsigned char *s=NULL,*sp; | ||
| 109 | unsigned char *bufp; | ||
| 110 | int num=0,slen=0,first=1; | ||
| 111 | |||
| 112 | bufsize=BIO_gets(bp,buf,size); | ||
| 113 | for (;;) | ||
| 114 | { | ||
| 115 | if (bufsize < 1) | ||
| 116 | { | ||
| 117 | if (first) | ||
| 118 | break; | ||
| 119 | else | ||
| 120 | goto err_sl; | ||
| 121 | } | ||
| 122 | first=0; | ||
| 123 | |||
| 124 | i=bufsize; | ||
| 125 | if (buf[i-1] == '\n') buf[--i]='\0'; | ||
| 126 | if (i == 0) goto err_sl; | ||
| 127 | if (buf[i-1] == '\r') buf[--i]='\0'; | ||
| 128 | if (i == 0) goto err_sl; | ||
| 129 | again=(buf[i-1] == '\\'); | ||
| 130 | |||
| 131 | for (j=i-1; j>0; j--) | ||
| 132 | { | ||
| 133 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || | ||
| 134 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || | ||
| 135 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) | ||
| 136 | { | ||
| 137 | i=j; | ||
| 138 | break; | ||
| 139 | } | ||
| 140 | } | ||
| 141 | buf[i]='\0'; | ||
| 142 | /* We have now cleared all the crap off the end of the | ||
| 143 | * line */ | ||
| 144 | if (i < 2) goto err_sl; | ||
| 145 | |||
| 146 | bufp=(unsigned char *)buf; | ||
| 147 | |||
| 148 | k=0; | ||
| 149 | i-=again; | ||
| 150 | if (i%2 != 0) | ||
| 151 | { | ||
| 152 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_ODD_NUMBER_OF_CHARS); | ||
| 153 | goto err; | ||
| 154 | } | ||
| 155 | i/=2; | ||
| 156 | if (num+i > slen) | ||
| 157 | { | ||
| 158 | if (s == NULL) | ||
| 159 | sp=(unsigned char *)Malloc( | ||
| 160 | (unsigned int)num+i*2); | ||
| 161 | else | ||
| 162 | sp=(unsigned char *)Realloc(s, | ||
| 163 | (unsigned int)num+i*2); | ||
| 164 | if (sp == NULL) | ||
| 165 | { | ||
| 166 | ASN1err(ASN1_F_A2I_ASN1_STRING,ERR_R_MALLOC_FAILURE); | ||
| 167 | if (s != NULL) Free((char *)s); | ||
| 168 | goto err; | ||
| 169 | } | ||
| 170 | s=sp; | ||
| 171 | slen=num+i*2; | ||
| 172 | } | ||
| 173 | for (j=0; j<i; j++,k+=2) | ||
| 174 | { | ||
| 175 | for (n=0; n<2; n++) | ||
| 176 | { | ||
| 177 | m=bufp[k+n]; | ||
| 178 | if ((m >= '0') && (m <= '9')) | ||
| 179 | m-='0'; | ||
| 180 | else if ((m >= 'a') && (m <= 'f')) | ||
| 181 | m=m-'a'+10; | ||
| 182 | else if ((m >= 'A') && (m <= 'F')) | ||
| 183 | m=m-'A'+10; | ||
| 184 | else | ||
| 185 | { | ||
| 186 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_NON_HEX_CHARACTERS); | ||
| 187 | goto err; | ||
| 188 | } | ||
| 189 | s[num+j]<<=4; | ||
| 190 | s[num+j]|=m; | ||
| 191 | } | ||
| 192 | } | ||
| 193 | num+=i; | ||
| 194 | if (again) | ||
| 195 | bufsize=BIO_gets(bp,buf,size); | ||
| 196 | else | ||
| 197 | break; | ||
| 198 | } | ||
| 199 | bs->length=num; | ||
| 200 | bs->data=s; | ||
| 201 | ret=1; | ||
| 202 | err: | ||
| 203 | if (0) | ||
| 204 | { | ||
| 205 | err_sl: | ||
| 206 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_SHORT_LINE); | ||
| 207 | } | ||
| 208 | return(ret); | ||
| 209 | } | ||
| 210 | |||
diff --git a/src/lib/libcrypto/asn1/i2d_pr.c b/src/lib/libcrypto/asn1/i2d_pr.c new file mode 100644 index 0000000000..b6b821d73c --- /dev/null +++ b/src/lib/libcrypto/asn1/i2d_pr.c | |||
| @@ -0,0 +1,86 @@ | |||
| 1 | /* crypto/asn1/i2d_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 "evp.h" | ||
| 63 | #include "objects.h" | ||
| 64 | |||
| 65 | int i2d_PrivateKey(a,pp) | ||
| 66 | EVP_PKEY *a; | ||
| 67 | unsigned char **pp; | ||
| 68 | { | ||
| 69 | #ifndef NO_RSA | ||
| 70 | if (a->type == EVP_PKEY_RSA) | ||
| 71 | { | ||
| 72 | return(i2d_RSAPrivateKey(a->pkey.rsa,pp)); | ||
| 73 | } | ||
| 74 | else | ||
| 75 | #endif | ||
| 76 | #ifndef NO_DSA | ||
| 77 | if (a->type == EVP_PKEY_DSA) | ||
| 78 | { | ||
| 79 | return(i2d_DSAPrivateKey(a->pkey.dsa,pp)); | ||
| 80 | } | ||
| 81 | #endif | ||
| 82 | |||
| 83 | ASN1err(ASN1_F_I2D_PRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); | ||
| 84 | return(-1); | ||
| 85 | } | ||
| 86 | |||
diff --git a/src/lib/libcrypto/asn1/i2d_pu.c b/src/lib/libcrypto/asn1/i2d_pu.c new file mode 100644 index 0000000000..1b854252b7 --- /dev/null +++ b/src/lib/libcrypto/asn1/i2d_pu.c | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | /* crypto/asn1/i2d_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 "evp.h" | ||
| 63 | #include "objects.h" | ||
| 64 | |||
| 65 | int i2d_PublicKey(a,pp) | ||
| 66 | EVP_PKEY *a; | ||
| 67 | unsigned char **pp; | ||
| 68 | { | ||
| 69 | switch (a->type) | ||
| 70 | { | ||
| 71 | #ifndef NO_RSA | ||
| 72 | case EVP_PKEY_RSA: | ||
| 73 | return(i2d_RSAPublicKey(a->pkey.rsa,pp)); | ||
| 74 | #endif | ||
| 75 | #ifndef NO_DSA | ||
| 76 | case EVP_PKEY_DSA: | ||
| 77 | return(i2d_DSAPublicKey(a->pkey.dsa,pp)); | ||
| 78 | #endif | ||
| 79 | default: | ||
| 80 | ASN1err(ASN1_F_I2D_PUBLICKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); | ||
| 81 | return(-1); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
diff --git a/src/lib/libcrypto/asn1/n_pkey.c b/src/lib/libcrypto/asn1/n_pkey.c new file mode 100644 index 0000000000..5110c91bec --- /dev/null +++ b/src/lib/libcrypto/asn1/n_pkey.c | |||
| @@ -0,0 +1,365 @@ | |||
| 1 | /* crypto/asn1/n_pkey.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 "rsa.h" | ||
| 62 | #include "objects.h" | ||
| 63 | #include "asn1_mac.h" | ||
| 64 | #include "evp.h" | ||
| 65 | #include "x509.h" | ||
| 66 | |||
| 67 | |||
| 68 | #ifndef NO_RC4 | ||
| 69 | |||
| 70 | typedef struct netscape_pkey_st | ||
| 71 | { | ||
| 72 | ASN1_INTEGER *version; | ||
| 73 | X509_ALGOR *algor; | ||
| 74 | ASN1_OCTET_STRING *private_key; | ||
| 75 | } NETSCAPE_PKEY; | ||
| 76 | |||
| 77 | /* | ||
| 78 | * ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_LENGTH_MISMATCH); | ||
| 79 | * ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_DECODING_ERROR); | ||
| 80 | * ASN1err(ASN1_F_D2I_NETSCAPE_PKEY,ASN1_R_DECODING_ERROR); | ||
| 81 | * ASN1err(ASN1_F_NETSCAPE_PKEY_NEW,ASN1_R_DECODING_ERROR); | ||
| 82 | */ | ||
| 83 | #ifndef NOPROTO | ||
| 84 | static int i2d_NETSCAPE_PKEY(NETSCAPE_PKEY *a, unsigned char **pp); | ||
| 85 | static NETSCAPE_PKEY *d2i_NETSCAPE_PKEY(NETSCAPE_PKEY **a,unsigned char **pp, long length); | ||
| 86 | static NETSCAPE_PKEY *NETSCAPE_PKEY_new(void); | ||
| 87 | static void NETSCAPE_PKEY_free(NETSCAPE_PKEY *); | ||
| 88 | #else | ||
| 89 | static int i2d_NETSCAPE_PKEY(); | ||
| 90 | static NETSCAPE_PKEY *d2i_NETSCAPE_PKEY(); | ||
| 91 | static NETSCAPE_PKEY *NETSCAPE_PKEY_new(); | ||
| 92 | static void NETSCAPE_PKEY_free(); | ||
| 93 | #endif | ||
| 94 | |||
| 95 | int i2d_Netscape_RSA(a,pp,cb) | ||
| 96 | RSA *a; | ||
| 97 | unsigned char **pp; | ||
| 98 | int (*cb)(); | ||
| 99 | { | ||
| 100 | int i,j,l[6]; | ||
| 101 | NETSCAPE_PKEY *pkey; | ||
| 102 | unsigned char buf[256],*zz; | ||
| 103 | unsigned char key[EVP_MAX_KEY_LENGTH]; | ||
| 104 | EVP_CIPHER_CTX ctx; | ||
| 105 | X509_ALGOR *alg=NULL; | ||
| 106 | ASN1_OCTET_STRING os,os2; | ||
| 107 | M_ASN1_I2D_vars(a); | ||
| 108 | |||
| 109 | if (a == NULL) return(0); | ||
| 110 | |||
| 111 | #ifdef WIN32 | ||
| 112 | r=r; /* shut the damn compiler up :-) */ | ||
| 113 | #endif | ||
| 114 | |||
| 115 | os.data=os2.data=NULL; | ||
| 116 | if ((pkey=NETSCAPE_PKEY_new()) == NULL) goto err; | ||
| 117 | if (!ASN1_INTEGER_set(pkey->version,0)) goto err; | ||
| 118 | |||
| 119 | if (pkey->algor->algorithm != NULL) | ||
| 120 | ASN1_OBJECT_free(pkey->algor->algorithm); | ||
| 121 | pkey->algor->algorithm=OBJ_nid2obj(NID_rsaEncryption); | ||
| 122 | if ((pkey->algor->parameter=ASN1_TYPE_new()) == NULL) goto err; | ||
| 123 | pkey->algor->parameter->type=V_ASN1_NULL; | ||
| 124 | |||
| 125 | l[0]=i2d_RSAPrivateKey(a,NULL); | ||
| 126 | pkey->private_key->length=l[0]; | ||
| 127 | |||
| 128 | os2.length=i2d_NETSCAPE_PKEY(pkey,NULL); | ||
| 129 | l[1]=i2d_ASN1_OCTET_STRING(&os2,NULL); | ||
| 130 | |||
| 131 | if ((alg=X509_ALGOR_new()) == NULL) goto err; | ||
| 132 | if (alg->algorithm != NULL) | ||
| 133 | ASN1_OBJECT_free(alg->algorithm); | ||
| 134 | alg->algorithm=OBJ_nid2obj(NID_rc4); | ||
| 135 | if ((alg->parameter=ASN1_TYPE_new()) == NULL) goto err; | ||
| 136 | alg->parameter->type=V_ASN1_NULL; | ||
| 137 | |||
| 138 | l[2]=i2d_X509_ALGOR(alg,NULL); | ||
| 139 | l[3]=ASN1_object_size(1,l[2]+l[1],V_ASN1_SEQUENCE); | ||
| 140 | |||
| 141 | os.data=(unsigned char *)"private-key"; | ||
| 142 | os.length=11; | ||
| 143 | l[4]=i2d_ASN1_OCTET_STRING(&os,NULL); | ||
| 144 | |||
| 145 | l[5]=ASN1_object_size(1,l[4]+l[3],V_ASN1_SEQUENCE); | ||
| 146 | |||
| 147 | if (pp == NULL) | ||
| 148 | { | ||
| 149 | if (pkey != NULL) NETSCAPE_PKEY_free(pkey); | ||
| 150 | if (alg != NULL) X509_ALGOR_free(alg); | ||
| 151 | return(l[5]); | ||
| 152 | } | ||
| 153 | |||
| 154 | if (pkey->private_key->data != NULL) | ||
| 155 | Free((char *)pkey->private_key->data); | ||
| 156 | if ((pkey->private_key->data=(unsigned char *)Malloc(l[0])) == NULL) | ||
| 157 | { | ||
| 158 | ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE); | ||
| 159 | goto err; | ||
| 160 | } | ||
| 161 | zz=pkey->private_key->data; | ||
| 162 | i2d_RSAPrivateKey(a,&zz); | ||
| 163 | |||
| 164 | if ((os2.data=(unsigned char *)Malloc(os2.length)) == NULL) | ||
| 165 | { | ||
| 166 | ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE); | ||
| 167 | goto err; | ||
| 168 | } | ||
| 169 | zz=os2.data; | ||
| 170 | i2d_NETSCAPE_PKEY(pkey,&zz); | ||
| 171 | |||
| 172 | if (cb == NULL) | ||
| 173 | cb=EVP_read_pw_string; | ||
| 174 | i=cb(buf,256,"Enter Private Key password:",1); | ||
| 175 | if (i != 0) | ||
| 176 | { | ||
| 177 | ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ASN1_R_BAD_PASSWORD_READ); | ||
| 178 | goto err; | ||
| 179 | } | ||
| 180 | EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf, | ||
| 181 | strlen((char *)buf),1,key,NULL); | ||
| 182 | memset(buf,0,256); | ||
| 183 | |||
| 184 | EVP_CIPHER_CTX_init(&ctx); | ||
| 185 | EVP_EncryptInit(&ctx,EVP_rc4(),key,NULL); | ||
| 186 | EVP_EncryptUpdate(&ctx,os2.data,&i,os2.data,os2.length); | ||
| 187 | EVP_EncryptFinal(&ctx,&(os2.data[i]),&j); | ||
| 188 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
| 189 | |||
| 190 | p= *pp; | ||
| 191 | ASN1_put_object(&p,1,l[4]+l[3],V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); | ||
| 192 | i2d_ASN1_OCTET_STRING(&os,&p); | ||
| 193 | ASN1_put_object(&p,1,l[2]+l[1],V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); | ||
| 194 | i2d_X509_ALGOR(alg,&p); | ||
| 195 | i2d_ASN1_OCTET_STRING(&os2,&p); | ||
| 196 | ret=l[5]; | ||
| 197 | err: | ||
| 198 | if (os2.data != NULL) Free((char *)os2.data); | ||
| 199 | if (alg != NULL) X509_ALGOR_free(alg); | ||
| 200 | if (pkey != NULL) NETSCAPE_PKEY_free(pkey); | ||
| 201 | r=r; | ||
| 202 | return(ret); | ||
| 203 | } | ||
| 204 | |||
| 205 | RSA *d2i_Netscape_RSA(a,pp,length,cb) | ||
| 206 | RSA **a; | ||
| 207 | unsigned char **pp; | ||
| 208 | long length; | ||
| 209 | int (*cb)(); | ||
| 210 | { | ||
| 211 | RSA *ret=NULL; | ||
| 212 | ASN1_OCTET_STRING *os=NULL; | ||
| 213 | ASN1_CTX c; | ||
| 214 | |||
| 215 | c.pp=pp; | ||
| 216 | c.error=ASN1_R_DECODING_ERROR; | ||
| 217 | |||
| 218 | M_ASN1_D2I_Init(); | ||
| 219 | M_ASN1_D2I_start_sequence(); | ||
| 220 | M_ASN1_D2I_get(os,d2i_ASN1_OCTET_STRING); | ||
| 221 | if ((os->length != 11) || (strncmp("private-key", | ||
| 222 | (char *)os->data,os->length) != 0)) | ||
| 223 | { | ||
| 224 | ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_PRIVATE_KEY_HEADER_MISSING); | ||
| 225 | ASN1_BIT_STRING_free(os); | ||
| 226 | goto err; | ||
| 227 | } | ||
| 228 | ASN1_BIT_STRING_free(os); | ||
| 229 | c.q=c.p; | ||
| 230 | if ((ret=d2i_Netscape_RSA_2(a,&c.p,c.slen,cb)) == NULL) goto err; | ||
| 231 | c.slen-=(c.p-c.q); | ||
| 232 | |||
| 233 | M_ASN1_D2I_Finish(a,RSA_free,ASN1_F_D2I_NETSCAPE_RSA); | ||
| 234 | } | ||
| 235 | |||
| 236 | RSA *d2i_Netscape_RSA_2(a,pp,length,cb) | ||
| 237 | RSA **a; | ||
| 238 | unsigned char **pp; | ||
| 239 | long length; | ||
| 240 | int (*cb)(); | ||
| 241 | { | ||
| 242 | NETSCAPE_PKEY *pkey=NULL; | ||
| 243 | RSA *ret=NULL; | ||
| 244 | int i,j; | ||
| 245 | unsigned char buf[256],*zz; | ||
| 246 | unsigned char key[EVP_MAX_KEY_LENGTH]; | ||
| 247 | EVP_CIPHER_CTX ctx; | ||
| 248 | X509_ALGOR *alg=NULL; | ||
| 249 | ASN1_OCTET_STRING *os=NULL; | ||
| 250 | ASN1_CTX c; | ||
| 251 | |||
| 252 | c.error=ASN1_R_ERROR_STACK; | ||
| 253 | c.pp=pp; | ||
| 254 | |||
| 255 | M_ASN1_D2I_Init(); | ||
| 256 | M_ASN1_D2I_start_sequence(); | ||
| 257 | M_ASN1_D2I_get(alg,d2i_X509_ALGOR); | ||
| 258 | if (OBJ_obj2nid(alg->algorithm) != NID_rc4) | ||
| 259 | { | ||
| 260 | ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM); | ||
| 261 | goto err; | ||
| 262 | } | ||
| 263 | M_ASN1_D2I_get(os,d2i_ASN1_OCTET_STRING); | ||
| 264 | if (cb == NULL) | ||
| 265 | cb=EVP_read_pw_string; | ||
| 266 | i=cb(buf,256,"Enter Private Key password:",0); | ||
| 267 | if (i != 0) | ||
| 268 | { | ||
| 269 | ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_BAD_PASSWORD_READ); | ||
| 270 | goto err; | ||
| 271 | } | ||
| 272 | |||
| 273 | EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf, | ||
| 274 | strlen((char *)buf),1,key,NULL); | ||
| 275 | memset(buf,0,256); | ||
| 276 | |||
| 277 | EVP_CIPHER_CTX_init(&ctx); | ||
| 278 | EVP_DecryptInit(&ctx,EVP_rc4(),key,NULL); | ||
| 279 | EVP_DecryptUpdate(&ctx,os->data,&i,os->data,os->length); | ||
| 280 | EVP_DecryptFinal(&ctx,&(os->data[i]),&j); | ||
| 281 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
| 282 | os->length=i+j; | ||
| 283 | |||
| 284 | zz=os->data; | ||
| 285 | |||
| 286 | if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL) | ||
| 287 | { | ||
| 288 | ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY); | ||
| 289 | goto err; | ||
| 290 | } | ||
| 291 | |||
| 292 | zz=pkey->private_key->data; | ||
| 293 | if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL) | ||
| 294 | { | ||
| 295 | ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNABLE_TO_DECODE_RSA_KEY); | ||
| 296 | goto err; | ||
| 297 | } | ||
| 298 | if (!asn1_Finish(&c)) goto err; | ||
| 299 | *pp=c.p; | ||
| 300 | err: | ||
| 301 | if (pkey != NULL) NETSCAPE_PKEY_free(pkey); | ||
| 302 | if (os != NULL) ASN1_BIT_STRING_free(os); | ||
| 303 | if (alg != NULL) X509_ALGOR_free(alg); | ||
| 304 | return(ret); | ||
| 305 | } | ||
| 306 | |||
| 307 | static int i2d_NETSCAPE_PKEY(a,pp) | ||
| 308 | NETSCAPE_PKEY *a; | ||
| 309 | unsigned char **pp; | ||
| 310 | { | ||
| 311 | M_ASN1_I2D_vars(a); | ||
| 312 | |||
| 313 | |||
| 314 | M_ASN1_I2D_len(a->version, i2d_ASN1_INTEGER); | ||
| 315 | M_ASN1_I2D_len(a->algor, i2d_X509_ALGOR); | ||
| 316 | M_ASN1_I2D_len(a->private_key, i2d_ASN1_OCTET_STRING); | ||
| 317 | |||
| 318 | M_ASN1_I2D_seq_total(); | ||
| 319 | |||
| 320 | M_ASN1_I2D_put(a->version, i2d_ASN1_INTEGER); | ||
| 321 | M_ASN1_I2D_put(a->algor, i2d_X509_ALGOR); | ||
| 322 | M_ASN1_I2D_put(a->private_key, i2d_ASN1_OCTET_STRING); | ||
| 323 | |||
| 324 | M_ASN1_I2D_finish(); | ||
| 325 | } | ||
| 326 | |||
| 327 | static NETSCAPE_PKEY *d2i_NETSCAPE_PKEY(a,pp,length) | ||
| 328 | NETSCAPE_PKEY **a; | ||
| 329 | unsigned char **pp; | ||
| 330 | long length; | ||
| 331 | { | ||
| 332 | M_ASN1_D2I_vars(a,NETSCAPE_PKEY *,NETSCAPE_PKEY_new); | ||
| 333 | |||
| 334 | M_ASN1_D2I_Init(); | ||
| 335 | M_ASN1_D2I_start_sequence(); | ||
| 336 | M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); | ||
| 337 | M_ASN1_D2I_get(ret->algor,d2i_X509_ALGOR); | ||
| 338 | M_ASN1_D2I_get(ret->private_key,d2i_ASN1_OCTET_STRING); | ||
| 339 | M_ASN1_D2I_Finish(a,NETSCAPE_PKEY_free,ASN1_F_D2I_NETSCAPE_PKEY); | ||
| 340 | } | ||
| 341 | |||
| 342 | static NETSCAPE_PKEY *NETSCAPE_PKEY_new() | ||
| 343 | { | ||
| 344 | NETSCAPE_PKEY *ret=NULL; | ||
| 345 | |||
| 346 | M_ASN1_New_Malloc(ret,NETSCAPE_PKEY); | ||
| 347 | M_ASN1_New(ret->version,ASN1_INTEGER_new); | ||
| 348 | M_ASN1_New(ret->algor,X509_ALGOR_new); | ||
| 349 | M_ASN1_New(ret->private_key,ASN1_OCTET_STRING_new); | ||
| 350 | return(ret); | ||
| 351 | M_ASN1_New_Error(ASN1_F_NETSCAPE_PKEY_NEW); | ||
| 352 | } | ||
| 353 | |||
| 354 | static void NETSCAPE_PKEY_free(a) | ||
| 355 | NETSCAPE_PKEY *a; | ||
| 356 | { | ||
| 357 | if (a == NULL) return; | ||
| 358 | ASN1_INTEGER_free(a->version); | ||
| 359 | X509_ALGOR_free(a->algor); | ||
| 360 | ASN1_OCTET_STRING_free(a->private_key); | ||
| 361 | Free((char *)a); | ||
| 362 | } | ||
| 363 | |||
| 364 | #endif /* NO_RC4 */ | ||
| 365 | |||
diff --git a/src/lib/libcrypto/asn1/t_pkey.c b/src/lib/libcrypto/asn1/t_pkey.c new file mode 100644 index 0000000000..bc518d59a2 --- /dev/null +++ b/src/lib/libcrypto/asn1/t_pkey.c | |||
| @@ -0,0 +1,392 @@ | |||
| 1 | /* crypto/asn1/t_pkey.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 "buffer.h" | ||
| 62 | #include "bn.h" | ||
| 63 | #ifndef NO_RSA | ||
| 64 | #include "rsa.h" | ||
| 65 | #endif | ||
| 66 | #ifndef NO_DH | ||
| 67 | #include "dh.h" | ||
| 68 | #endif | ||
| 69 | #ifndef NO_DSA | ||
| 70 | #include "dsa.h" | ||
| 71 | #endif | ||
| 72 | |||
| 73 | /* DHerr(DH_F_DHPARAMS_PRINT,ERR_R_MALLOC_FAILURE); | ||
| 74 | * DSAerr(DSA_F_DSAPARAMS_PRINT,ERR_R_MALLOC_FAILURE); | ||
| 75 | */ | ||
| 76 | |||
| 77 | #ifndef NOPROTO | ||
| 78 | static int print(BIO *fp,char *str,BIGNUM *num, | ||
| 79 | unsigned char *buf,int off); | ||
| 80 | #else | ||
| 81 | static int print(); | ||
| 82 | #endif | ||
| 83 | |||
| 84 | #ifndef NO_RSA | ||
| 85 | #ifndef NO_FP_API | ||
| 86 | int RSA_print_fp(fp,x,off) | ||
| 87 | FILE *fp; | ||
| 88 | RSA *x; | ||
| 89 | int off; | ||
| 90 | { | ||
| 91 | BIO *b; | ||
| 92 | int ret; | ||
| 93 | |||
| 94 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 95 | { | ||
| 96 | RSAerr(RSA_F_RSA_PRINT_FP,ERR_R_BUF_LIB); | ||
| 97 | return(0); | ||
| 98 | } | ||
| 99 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 100 | ret=RSA_print(b,x,off); | ||
| 101 | BIO_free(b); | ||
| 102 | return(ret); | ||
| 103 | } | ||
| 104 | #endif | ||
| 105 | |||
| 106 | int RSA_print(bp,x,off) | ||
| 107 | BIO *bp; | ||
| 108 | RSA *x; | ||
| 109 | int off; | ||
| 110 | { | ||
| 111 | char str[128],*s; | ||
| 112 | unsigned char *m=NULL; | ||
| 113 | int i,ret=0; | ||
| 114 | |||
| 115 | i=RSA_size(x); | ||
| 116 | m=(unsigned char *)Malloc((unsigned int)i+10); | ||
| 117 | if (m == NULL) | ||
| 118 | { | ||
| 119 | RSAerr(RSA_F_RSA_PRINT,ERR_R_MALLOC_FAILURE); | ||
| 120 | goto err; | ||
| 121 | } | ||
| 122 | |||
| 123 | if (off) | ||
| 124 | { | ||
| 125 | if (off > 128) off=128; | ||
| 126 | memset(str,' ',off); | ||
| 127 | } | ||
| 128 | if (x->d != NULL) | ||
| 129 | { | ||
| 130 | if (off && (BIO_write(bp,str,off) <= 0)) goto err; | ||
| 131 | if (BIO_printf(bp,"Private-Key: (%d bit)\n",BN_num_bits(x->n)) | ||
| 132 | <= 0) goto err; | ||
| 133 | } | ||
| 134 | |||
| 135 | if (x->d == NULL) | ||
| 136 | sprintf(str,"Modulus (%d bit):",BN_num_bits(x->n)); | ||
| 137 | else | ||
| 138 | strcpy(str,"modulus:"); | ||
| 139 | if (!print(bp,str,x->n,m,off)) goto err; | ||
| 140 | s=(x->d == NULL)?"Exponent:":"publicExponent:"; | ||
| 141 | if (!print(bp,s,x->e,m,off)) goto err; | ||
| 142 | if (!print(bp,"privateExponent:",x->d,m,off)) goto err; | ||
| 143 | if (!print(bp,"prime1:",x->p,m,off)) goto err; | ||
| 144 | if (!print(bp,"prime2:",x->q,m,off)) goto err; | ||
| 145 | if (!print(bp,"exponent1:",x->dmp1,m,off)) goto err; | ||
| 146 | if (!print(bp,"exponent2:",x->dmq1,m,off)) goto err; | ||
| 147 | if (!print(bp,"coefficient:",x->iqmp,m,off)) goto err; | ||
| 148 | ret=1; | ||
| 149 | err: | ||
| 150 | if (m != NULL) Free((char *)m); | ||
| 151 | return(ret); | ||
| 152 | } | ||
| 153 | #endif /* NO_RSA */ | ||
| 154 | |||
| 155 | #ifndef NO_DSA | ||
| 156 | #ifndef NO_FP_API | ||
| 157 | int DSA_print_fp(fp,x,off) | ||
| 158 | FILE *fp; | ||
| 159 | DSA *x; | ||
| 160 | int off; | ||
| 161 | { | ||
| 162 | BIO *b; | ||
| 163 | int ret; | ||
| 164 | |||
| 165 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 166 | { | ||
| 167 | DSAerr(DSA_F_DSA_PRINT_FP,ERR_R_BUF_LIB); | ||
| 168 | return(0); | ||
| 169 | } | ||
| 170 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 171 | ret=DSA_print(b,x,off); | ||
| 172 | BIO_free(b); | ||
| 173 | return(ret); | ||
| 174 | } | ||
| 175 | #endif | ||
| 176 | |||
| 177 | int DSA_print(bp,x,off) | ||
| 178 | BIO *bp; | ||
| 179 | DSA *x; | ||
| 180 | int off; | ||
| 181 | { | ||
| 182 | char str[128]; | ||
| 183 | unsigned char *m=NULL; | ||
| 184 | int i,ret=0; | ||
| 185 | BIGNUM *bn=NULL; | ||
| 186 | |||
| 187 | if (x->p != NULL) | ||
| 188 | bn=x->p; | ||
| 189 | else if (x->priv_key != NULL) | ||
| 190 | bn=x->priv_key; | ||
| 191 | else if (x->pub_key != NULL) | ||
| 192 | bn=x->pub_key; | ||
| 193 | |||
| 194 | /* larger than needed but what the hell :-) */ | ||
| 195 | if (bn != NULL) | ||
| 196 | i=BN_num_bytes(bn)*2; | ||
| 197 | else | ||
| 198 | i=256; | ||
| 199 | m=(unsigned char *)Malloc((unsigned int)i+10); | ||
| 200 | if (m == NULL) | ||
| 201 | { | ||
| 202 | DSAerr(DSA_F_DSA_PRINT,ERR_R_MALLOC_FAILURE); | ||
| 203 | goto err; | ||
| 204 | } | ||
| 205 | |||
| 206 | if (off) | ||
| 207 | { | ||
| 208 | if (off > 128) off=128; | ||
| 209 | memset(str,' ',off); | ||
| 210 | } | ||
| 211 | if (x->priv_key != NULL) | ||
| 212 | { | ||
| 213 | if (off && (BIO_write(bp,str,off) <= 0)) goto err; | ||
| 214 | if (BIO_printf(bp,"Private-Key: (%d bit)\n",BN_num_bits(x->p)) | ||
| 215 | <= 0) goto err; | ||
| 216 | } | ||
| 217 | |||
| 218 | if ((x->priv_key != NULL) && !print(bp,"priv:",x->priv_key,m,off)) | ||
| 219 | goto err; | ||
| 220 | if ((x->pub_key != NULL) && !print(bp,"pub: ",x->pub_key,m,off)) | ||
| 221 | goto err; | ||
| 222 | if ((x->p != NULL) && !print(bp,"P: ",x->p,m,off)) goto err; | ||
| 223 | if ((x->q != NULL) && !print(bp,"Q: ",x->q,m,off)) goto err; | ||
| 224 | if ((x->g != NULL) && !print(bp,"G: ",x->g,m,off)) goto err; | ||
| 225 | ret=1; | ||
| 226 | err: | ||
| 227 | if (m != NULL) Free((char *)m); | ||
| 228 | return(ret); | ||
| 229 | } | ||
| 230 | #endif /* !NO_DSA */ | ||
| 231 | |||
| 232 | static int print(bp,number,num,buf,off) | ||
| 233 | BIO *bp; | ||
| 234 | char *number; | ||
| 235 | BIGNUM *num; | ||
| 236 | unsigned char *buf; | ||
| 237 | int off; | ||
| 238 | { | ||
| 239 | int n,i; | ||
| 240 | char str[128],*neg; | ||
| 241 | |||
| 242 | if (num == NULL) return(1); | ||
| 243 | neg=(num->neg)?"-":""; | ||
| 244 | if (off) | ||
| 245 | { | ||
| 246 | if (off > 128) off=128; | ||
| 247 | memset(str,' ',off); | ||
| 248 | if (BIO_write(bp,str,off) <= 0) return(0); | ||
| 249 | } | ||
| 250 | |||
| 251 | if (BN_num_bytes(num) <= BN_BYTES) | ||
| 252 | { | ||
| 253 | if (BIO_printf(bp,"%s %s%lu (%s0x%lx)\n",number,neg, | ||
| 254 | (unsigned long)num->d[0],neg,(unsigned long)num->d[0]) | ||
| 255 | <= 0) return(0); | ||
| 256 | } | ||
| 257 | else | ||
| 258 | { | ||
| 259 | buf[0]=0; | ||
| 260 | if (BIO_printf(bp,"%s%s",number, | ||
| 261 | (neg[0] == '-')?" (Negative)":"") <= 0) | ||
| 262 | return(0); | ||
| 263 | n=BN_bn2bin(num,&buf[1]); | ||
| 264 | |||
| 265 | if (buf[1] & 0x80) | ||
| 266 | n++; | ||
| 267 | else buf++; | ||
| 268 | |||
| 269 | for (i=0; i<n; i++) | ||
| 270 | { | ||
| 271 | if ((i%15) == 0) | ||
| 272 | { | ||
| 273 | str[0]='\n'; | ||
| 274 | memset(&(str[1]),' ',off+4); | ||
| 275 | if (BIO_write(bp,str,off+1+4) <= 0) return(0); | ||
| 276 | } | ||
| 277 | if (BIO_printf(bp,"%02x%s",buf[i],((i+1) == n)?"":":") | ||
| 278 | <= 0) return(0); | ||
| 279 | } | ||
| 280 | if (BIO_write(bp,"\n",1) <= 0) return(0); | ||
| 281 | } | ||
| 282 | return(1); | ||
| 283 | } | ||
| 284 | |||
| 285 | #ifndef NO_DH | ||
| 286 | #ifndef NO_FP_API | ||
| 287 | int DHparams_print_fp(fp,x) | ||
| 288 | FILE *fp; | ||
| 289 | DH *x; | ||
| 290 | { | ||
| 291 | BIO *b; | ||
| 292 | int ret; | ||
| 293 | |||
| 294 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 295 | { | ||
| 296 | DHerr(DH_F_DHPARAMS_PRINT_FP,ERR_R_BUF_LIB); | ||
| 297 | return(0); | ||
| 298 | } | ||
| 299 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 300 | ret=DHparams_print(b, x); | ||
| 301 | BIO_free(b); | ||
| 302 | return(ret); | ||
| 303 | } | ||
| 304 | #endif | ||
| 305 | |||
| 306 | int DHparams_print(bp,x) | ||
| 307 | BIO *bp; | ||
| 308 | DH *x; | ||
| 309 | { | ||
| 310 | unsigned char *m=NULL; | ||
| 311 | int reason=ERR_R_BUF_LIB,i,ret=0; | ||
| 312 | |||
| 313 | i=BN_num_bytes(x->p); | ||
| 314 | m=(unsigned char *)Malloc((unsigned int)i+10); | ||
| 315 | if (m == NULL) | ||
| 316 | { | ||
| 317 | reason=ERR_R_MALLOC_FAILURE; | ||
| 318 | goto err; | ||
| 319 | } | ||
| 320 | |||
| 321 | if (BIO_printf(bp,"Diffie-Hellman-Parameters: (%d bit)\n", | ||
| 322 | BN_num_bits(x->p)) <= 0) | ||
| 323 | goto err; | ||
| 324 | if (!print(bp,"prime:",x->p,m,4)) goto err; | ||
| 325 | if (!print(bp,"generator:",x->g,m,4)) goto err; | ||
| 326 | if (x->length != 0) | ||
| 327 | { | ||
| 328 | if (BIO_printf(bp," recomented-private-length: %d bits\n", | ||
| 329 | (int)x->length) <= 0) goto err; | ||
| 330 | } | ||
| 331 | ret=1; | ||
| 332 | if (0) | ||
| 333 | { | ||
| 334 | err: | ||
| 335 | DHerr(DH_F_DHPARAMS_PRINT,reason); | ||
| 336 | } | ||
| 337 | if (m != NULL) Free((char *)m); | ||
| 338 | return(ret); | ||
| 339 | } | ||
| 340 | #endif | ||
| 341 | |||
| 342 | #ifndef NO_DSA | ||
| 343 | #ifndef NO_FP_API | ||
| 344 | int DSAparams_print_fp(fp,x) | ||
| 345 | FILE *fp; | ||
| 346 | DSA *x; | ||
| 347 | { | ||
| 348 | BIO *b; | ||
| 349 | int ret; | ||
| 350 | |||
| 351 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 352 | { | ||
| 353 | DSAerr(DSA_F_DSAPARAMS_PRINT_FP,ERR_R_BUF_LIB); | ||
| 354 | return(0); | ||
| 355 | } | ||
| 356 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 357 | ret=DSAparams_print(b, x); | ||
| 358 | BIO_free(b); | ||
| 359 | return(ret); | ||
| 360 | } | ||
| 361 | #endif | ||
| 362 | |||
| 363 | int DSAparams_print(bp,x) | ||
| 364 | BIO *bp; | ||
| 365 | DSA *x; | ||
| 366 | { | ||
| 367 | unsigned char *m=NULL; | ||
| 368 | int reason=ERR_R_BUF_LIB,i,ret=0; | ||
| 369 | |||
| 370 | i=BN_num_bytes(x->p); | ||
| 371 | m=(unsigned char *)Malloc((unsigned int)i+10); | ||
| 372 | if (m == NULL) | ||
| 373 | { | ||
| 374 | reason=ERR_R_MALLOC_FAILURE; | ||
| 375 | goto err; | ||
| 376 | } | ||
| 377 | |||
| 378 | if (BIO_printf(bp,"DSA-Parameters: (%d bit)\n", | ||
| 379 | BN_num_bits(x->p)) <= 0) | ||
| 380 | goto err; | ||
| 381 | if (!print(bp,"p:",x->p,m,4)) goto err; | ||
| 382 | if (!print(bp,"q:",x->q,m,4)) goto err; | ||
| 383 | if (!print(bp,"g:",x->g,m,4)) goto err; | ||
| 384 | ret=1; | ||
| 385 | err: | ||
| 386 | if (m != NULL) Free((char *)m); | ||
| 387 | DSAerr(DSA_F_DSAPARAMS_PRINT,reason); | ||
| 388 | return(ret); | ||
| 389 | } | ||
| 390 | |||
| 391 | #endif /* !NO_DSA */ | ||
| 392 | |||
diff --git a/src/lib/libcrypto/asn1/t_req.c b/src/lib/libcrypto/asn1/t_req.c new file mode 100644 index 0000000000..7df749a48f --- /dev/null +++ b/src/lib/libcrypto/asn1/t_req.c | |||
| @@ -0,0 +1,226 @@ | |||
| 1 | /* crypto/asn1/t_req.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 "buffer.h" | ||
| 62 | #include "bn.h" | ||
| 63 | #include "objects.h" | ||
| 64 | #include "x509.h" | ||
| 65 | |||
| 66 | #ifndef NO_FP_API | ||
| 67 | int X509_REQ_print_fp(fp,x) | ||
| 68 | FILE *fp; | ||
| 69 | X509_REQ *x; | ||
| 70 | { | ||
| 71 | BIO *b; | ||
| 72 | int ret; | ||
| 73 | |||
| 74 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 75 | { | ||
| 76 | X509err(X509_F_X509_REQ_PRINT_FP,ERR_R_BUF_LIB); | ||
| 77 | return(0); | ||
| 78 | } | ||
| 79 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 80 | ret=X509_REQ_print(b, x); | ||
| 81 | BIO_free(b); | ||
| 82 | return(ret); | ||
| 83 | } | ||
| 84 | #endif | ||
| 85 | |||
| 86 | int X509_REQ_print(bp,x) | ||
| 87 | BIO *bp; | ||
| 88 | X509_REQ *x; | ||
| 89 | { | ||
| 90 | unsigned long l; | ||
| 91 | int i,n; | ||
| 92 | char *s,*neg; | ||
| 93 | X509_REQ_INFO *ri; | ||
| 94 | EVP_PKEY *pkey; | ||
| 95 | STACK *sk; | ||
| 96 | char str[128]; | ||
| 97 | |||
| 98 | ri=x->req_info; | ||
| 99 | sprintf(str,"Certificate Request:\n"); | ||
| 100 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 101 | sprintf(str,"%4sData:\n",""); | ||
| 102 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 103 | |||
| 104 | neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":""; | ||
| 105 | l=0; | ||
| 106 | for (i=0; i<ri->version->length; i++) | ||
| 107 | { l<<=8; l+=ri->version->data[i]; } | ||
| 108 | sprintf(str,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg,l); | ||
| 109 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 110 | sprintf(str,"%8sSubject: ",""); | ||
| 111 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 112 | |||
| 113 | X509_NAME_print(bp,ri->subject,16); | ||
| 114 | sprintf(str,"\n%8sSubject Public Key Info:\n",""); | ||
| 115 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 116 | i=OBJ_obj2nid(ri->pubkey->algor->algorithm); | ||
| 117 | sprintf(str,"%12sPublic Key Algorithm: %s\n","", | ||
| 118 | (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)); | ||
| 119 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 120 | |||
| 121 | pkey=X509_REQ_get_pubkey(x); | ||
| 122 | #ifndef NO_RSA | ||
| 123 | if (pkey->type == EVP_PKEY_RSA) | ||
| 124 | { | ||
| 125 | BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","", | ||
| 126 | BN_num_bits(pkey->pkey.rsa->n)); | ||
| 127 | RSA_print(bp,pkey->pkey.rsa,16); | ||
| 128 | } | ||
| 129 | else | ||
| 130 | #endif | ||
| 131 | #ifndef NO_DSA | ||
| 132 | if (pkey->type == EVP_PKEY_DSA) | ||
| 133 | { | ||
| 134 | BIO_printf(bp,"%12sDSA Public Key:\n",""); | ||
| 135 | DSA_print(bp,pkey->pkey.dsa,16); | ||
| 136 | } | ||
| 137 | else | ||
| 138 | #endif | ||
| 139 | BIO_printf(bp,"%12sUnknown Public Key:\n",""); | ||
| 140 | |||
| 141 | /* may not be */ | ||
| 142 | sprintf(str,"%8sAttributes:\n",""); | ||
| 143 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 144 | |||
| 145 | sk=x->req_info->attributes; | ||
| 146 | if ((sk == NULL) || (sk_num(sk) == 0)) | ||
| 147 | { | ||
| 148 | if (!x->req_info->req_kludge) | ||
| 149 | { | ||
| 150 | sprintf(str,"%12sa0:00\n",""); | ||
| 151 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 152 | } | ||
| 153 | } | ||
| 154 | else | ||
| 155 | { | ||
| 156 | for (i=0; i<sk_num(sk); i++) | ||
| 157 | { | ||
| 158 | ASN1_TYPE *at; | ||
| 159 | X509_ATTRIBUTE *a; | ||
| 160 | ASN1_BIT_STRING *bs=NULL; | ||
| 161 | ASN1_TYPE *t; | ||
| 162 | int j,type=0,count=1,ii=0; | ||
| 163 | |||
| 164 | a=(X509_ATTRIBUTE *)sk_value(sk,i); | ||
| 165 | sprintf(str,"%12s",""); | ||
| 166 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 167 | if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0) | ||
| 168 | |||
| 169 | if (a->set) | ||
| 170 | { | ||
| 171 | ii=0; | ||
| 172 | count=sk_num(a->value.set); | ||
| 173 | get_next: | ||
| 174 | at=(ASN1_TYPE *)sk_value(a->value.set,ii); | ||
| 175 | type=at->type; | ||
| 176 | bs=at->value.asn1_string; | ||
| 177 | } | ||
| 178 | else | ||
| 179 | { | ||
| 180 | t=a->value.single; | ||
| 181 | type=t->type; | ||
| 182 | bs=t->value.bit_string; | ||
| 183 | } | ||
| 184 | for (j=25-j; j>0; j--) | ||
| 185 | if (BIO_write(bp," ",1) != 1) goto err; | ||
| 186 | if (BIO_puts(bp,":") <= 0) goto err; | ||
| 187 | if ( (type == V_ASN1_PRINTABLESTRING) || | ||
| 188 | (type == V_ASN1_T61STRING) || | ||
| 189 | (type == V_ASN1_IA5STRING)) | ||
| 190 | { | ||
| 191 | if (BIO_write(bp,(char *)bs->data,bs->length) | ||
| 192 | != bs->length) | ||
| 193 | goto err; | ||
| 194 | BIO_puts(bp,"\n"); | ||
| 195 | } | ||
| 196 | else | ||
| 197 | { | ||
| 198 | BIO_puts(bp,"unable to print attribute\n"); | ||
| 199 | } | ||
| 200 | if (++ii < count) goto get_next; | ||
| 201 | } | ||
| 202 | } | ||
| 203 | |||
| 204 | i=OBJ_obj2nid(x->sig_alg->algorithm); | ||
| 205 | sprintf(str,"%4sSignature Algorithm: %s","", | ||
| 206 | (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)); | ||
| 207 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 208 | |||
| 209 | n=x->signature->length; | ||
| 210 | s=(char *)x->signature->data; | ||
| 211 | for (i=0; i<n; i++) | ||
| 212 | { | ||
| 213 | if ((i%18) == 0) | ||
| 214 | { | ||
| 215 | sprintf(str,"\n%8s",""); | ||
| 216 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 217 | } | ||
| 218 | sprintf(str,"%02x%s",(unsigned char)s[i],((i+1) == n)?"":":"); | ||
| 219 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 220 | } | ||
| 221 | if (BIO_puts(bp,"\n") <= 0) goto err; | ||
| 222 | return(1); | ||
| 223 | err: | ||
| 224 | X509err(X509_F_X509_REQ_PRINT,ERR_R_BUF_LIB); | ||
| 225 | return(0); | ||
| 226 | } | ||
diff --git a/src/lib/libcrypto/asn1/t_x509.c b/src/lib/libcrypto/asn1/t_x509.c new file mode 100644 index 0000000000..b10fbbb992 --- /dev/null +++ b/src/lib/libcrypto/asn1/t_x509.c | |||
| @@ -0,0 +1,386 @@ | |||
| 1 | /* crypto/asn1/t_x509.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 "buffer.h" | ||
| 62 | #include "bn.h" | ||
| 63 | #ifndef NO_RSA | ||
| 64 | #include "rsa.h" | ||
| 65 | #endif | ||
| 66 | #ifndef NO_DSA | ||
| 67 | #include "dsa.h" | ||
| 68 | #endif | ||
| 69 | #include "objects.h" | ||
| 70 | #include "x509.h" | ||
| 71 | |||
| 72 | #ifndef NO_FP_API | ||
| 73 | int X509_print_fp(fp,x) | ||
| 74 | FILE *fp; | ||
| 75 | X509 *x; | ||
| 76 | { | ||
| 77 | BIO *b; | ||
| 78 | int ret; | ||
| 79 | |||
| 80 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 81 | { | ||
| 82 | X509err(X509_F_X509_PRINT_FP,ERR_R_BUF_LIB); | ||
| 83 | return(0); | ||
| 84 | } | ||
| 85 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 86 | ret=X509_print(b, x); | ||
| 87 | BIO_free(b); | ||
| 88 | return(ret); | ||
| 89 | } | ||
| 90 | #endif | ||
| 91 | |||
| 92 | int X509_print(bp,x) | ||
| 93 | BIO *bp; | ||
| 94 | X509 *x; | ||
| 95 | { | ||
| 96 | long l; | ||
| 97 | int ret=0,i,j,n; | ||
| 98 | char *m=NULL,*s; | ||
| 99 | X509_CINF *ci; | ||
| 100 | ASN1_INTEGER *bs; | ||
| 101 | EVP_PKEY *pkey=NULL; | ||
| 102 | char *neg; | ||
| 103 | X509_EXTENSION *ex; | ||
| 104 | ASN1_STRING *str=NULL; | ||
| 105 | |||
| 106 | ci=x->cert_info; | ||
| 107 | if (BIO_write(bp,"Certificate:\n",13) <= 0) goto err; | ||
| 108 | if (BIO_write(bp," Data:\n",10) <= 0) goto err; | ||
| 109 | l=X509_get_version(x); | ||
| 110 | if (BIO_printf(bp,"%8sVersion: %lu (0x%lx)\n","",l+1,l) <= 0) goto err; | ||
| 111 | if (BIO_write(bp," Serial Number:",22) <= 0) goto err; | ||
| 112 | |||
| 113 | bs=X509_get_serialNumber(x); | ||
| 114 | if (bs->length <= 4) | ||
| 115 | { | ||
| 116 | l=ASN1_INTEGER_get(bs); | ||
| 117 | if (l < 0) | ||
| 118 | { | ||
| 119 | l= -l; | ||
| 120 | neg="-"; | ||
| 121 | } | ||
| 122 | else | ||
| 123 | neg=""; | ||
| 124 | if (BIO_printf(bp," %s%lu (%s0x%lx)\n",neg,l,neg,l) <= 0) | ||
| 125 | goto err; | ||
| 126 | } | ||
| 127 | else | ||
| 128 | { | ||
| 129 | neg=(bs->type == V_ASN1_NEG_INTEGER)?" (Negative)":""; | ||
| 130 | if (BIO_printf(bp,"\n%12s%s","",neg) <= 0) goto err; | ||
| 131 | |||
| 132 | for (i=0; i<bs->length; i++) | ||
| 133 | { | ||
| 134 | if (BIO_printf(bp,"%02x%c",bs->data[i], | ||
| 135 | ((i+1 == bs->length)?'\n':':')) <= 0) | ||
| 136 | goto err; | ||
| 137 | } | ||
| 138 | } | ||
| 139 | |||
| 140 | i=OBJ_obj2nid(ci->signature->algorithm); | ||
| 141 | if (BIO_printf(bp,"%8sSignature Algorithm: %s\n","", | ||
| 142 | (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)) <= 0) | ||
| 143 | goto err; | ||
| 144 | |||
| 145 | if (BIO_write(bp," Issuer: ",16) <= 0) goto err; | ||
| 146 | if (!X509_NAME_print(bp,X509_get_issuer_name(x),16)) goto err; | ||
| 147 | if (BIO_write(bp,"\n Validity\n",18) <= 0) goto err; | ||
| 148 | if (BIO_write(bp," Not Before: ",24) <= 0) goto err; | ||
| 149 | if (!ASN1_UTCTIME_print(bp,X509_get_notBefore(x))) goto err; | ||
| 150 | if (BIO_write(bp,"\n Not After : ",25) <= 0) goto err; | ||
| 151 | if (!ASN1_UTCTIME_print(bp,X509_get_notAfter(x))) goto err; | ||
| 152 | if (BIO_write(bp,"\n Subject: ",18) <= 0) goto err; | ||
| 153 | if (!X509_NAME_print(bp,X509_get_subject_name(x),16)) goto err; | ||
| 154 | if (BIO_write(bp,"\n Subject Public Key Info:\n",34) <= 0) | ||
| 155 | goto err; | ||
| 156 | i=OBJ_obj2nid(ci->key->algor->algorithm); | ||
| 157 | if (BIO_printf(bp,"%12sPublic Key Algorithm: %s\n","", | ||
| 158 | (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)) <= 0) goto err; | ||
| 159 | |||
| 160 | pkey=X509_get_pubkey(x); | ||
| 161 | #ifndef NO_RSA | ||
| 162 | if (pkey->type == EVP_PKEY_RSA) | ||
| 163 | { | ||
| 164 | BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","", | ||
| 165 | BN_num_bits(pkey->pkey.rsa->n)); | ||
| 166 | RSA_print(bp,pkey->pkey.rsa,16); | ||
| 167 | } | ||
| 168 | else | ||
| 169 | #endif | ||
| 170 | #ifndef NO_DSA | ||
| 171 | if (pkey->type == EVP_PKEY_DSA) | ||
| 172 | { | ||
| 173 | BIO_printf(bp,"%12sDSA Public Key:\n",""); | ||
| 174 | DSA_print(bp,pkey->pkey.dsa,16); | ||
| 175 | } | ||
| 176 | else | ||
| 177 | #endif | ||
| 178 | BIO_printf(bp,"%12sDSA Public Key:\n",""); | ||
| 179 | |||
| 180 | n=X509_get_ext_count(x); | ||
| 181 | if (n > 0) | ||
| 182 | { | ||
| 183 | BIO_printf(bp,"%8sX509v3 extensions:\n",""); | ||
| 184 | for (i=0; i<n; i++) | ||
| 185 | { | ||
| 186 | int data_type,pack_type; | ||
| 187 | ASN1_OBJECT *obj; | ||
| 188 | |||
| 189 | ex=X509_get_ext(x,i); | ||
| 190 | if (BIO_printf(bp,"%12s","") <= 0) goto err; | ||
| 191 | obj=X509_EXTENSION_get_object(ex); | ||
| 192 | i2a_ASN1_OBJECT(bp,obj); | ||
| 193 | j=X509_EXTENSION_get_critical(ex); | ||
| 194 | if (BIO_printf(bp,": %s\n%16s",j?"critical":"","") <= 0) | ||
| 195 | goto err; | ||
| 196 | |||
| 197 | pack_type=X509v3_pack_type_by_OBJ(obj); | ||
| 198 | data_type=X509v3_data_type_by_OBJ(obj); | ||
| 199 | |||
| 200 | if (pack_type == X509_EXT_PACK_STRING) | ||
| 201 | { | ||
| 202 | if (X509v3_unpack_string( | ||
| 203 | &str,data_type, | ||
| 204 | X509_EXTENSION_get_data(ex)) == NULL) | ||
| 205 | { | ||
| 206 | /* hmm... */ | ||
| 207 | goto err; | ||
| 208 | } | ||
| 209 | if ( (data_type == V_ASN1_IA5STRING) || | ||
| 210 | (data_type == V_ASN1_PRINTABLESTRING) || | ||
| 211 | (data_type == V_ASN1_T61STRING)) | ||
| 212 | { | ||
| 213 | if (BIO_write(bp,(char *)str->data, | ||
| 214 | str->length) <= 0) | ||
| 215 | goto err; | ||
| 216 | } | ||
| 217 | else if (data_type == V_ASN1_BIT_STRING) | ||
| 218 | { | ||
| 219 | BIO_printf(bp,"0x"); | ||
| 220 | for (j=0; j<str->length; j++) | ||
| 221 | { | ||
| 222 | BIO_printf(bp,"%02X", | ||
| 223 | str->data[j]); | ||
| 224 | } | ||
| 225 | } | ||
| 226 | } | ||
| 227 | else | ||
| 228 | { | ||
| 229 | ASN1_OCTET_STRING_print(bp,ex->value); | ||
| 230 | } | ||
| 231 | if (BIO_write(bp,"\n",1) <= 0) goto err; | ||
| 232 | } | ||
| 233 | } | ||
| 234 | |||
| 235 | i=OBJ_obj2nid(x->sig_alg->algorithm); | ||
| 236 | if (BIO_printf(bp,"%4sSignature Algorithm: %s","", | ||
| 237 | (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)) <= 0) goto err; | ||
| 238 | |||
| 239 | n=x->signature->length; | ||
| 240 | s=(char *)x->signature->data; | ||
| 241 | for (i=0; i<n; i++) | ||
| 242 | { | ||
| 243 | if ((i%18) == 0) | ||
| 244 | if (BIO_write(bp,"\n ",9) <= 0) goto err; | ||
| 245 | if (BIO_printf(bp,"%02x%s",(unsigned char)s[i], | ||
| 246 | ((i+1) == n)?"":":") <= 0) goto err; | ||
| 247 | } | ||
| 248 | if (BIO_write(bp,"\n",1) != 1) goto err; | ||
| 249 | ret=1; | ||
| 250 | err: | ||
| 251 | if (str != NULL) ASN1_STRING_free(str); | ||
| 252 | if (m != NULL) Free((char *)m); | ||
| 253 | return(ret); | ||
| 254 | } | ||
| 255 | |||
| 256 | int ASN1_STRING_print(bp,v) | ||
| 257 | BIO *bp; | ||
| 258 | ASN1_STRING *v; | ||
| 259 | { | ||
| 260 | int i,n; | ||
| 261 | char buf[80],*p;; | ||
| 262 | |||
| 263 | if (v == NULL) return(0); | ||
| 264 | n=0; | ||
| 265 | p=(char *)v->data; | ||
| 266 | for (i=0; i<v->length; i++) | ||
| 267 | { | ||
| 268 | if ((p[i] > '~') || ((p[i] < ' ') && | ||
| 269 | (p[i] != '\n') && (p[i] != '\r'))) | ||
| 270 | buf[n]='.'; | ||
| 271 | else | ||
| 272 | buf[n]=p[i]; | ||
| 273 | n++; | ||
| 274 | if (n >= 80) | ||
| 275 | { | ||
| 276 | if (BIO_write(bp,buf,n) <= 0) | ||
| 277 | return(0); | ||
| 278 | n=0; | ||
| 279 | } | ||
| 280 | } | ||
| 281 | if (n > 0) | ||
| 282 | if (BIO_write(bp,buf,n) <= 0) | ||
| 283 | return(0); | ||
| 284 | return(1); | ||
| 285 | } | ||
| 286 | |||
| 287 | int ASN1_UTCTIME_print(bp,tm) | ||
| 288 | BIO *bp; | ||
| 289 | ASN1_UTCTIME *tm; | ||
| 290 | { | ||
| 291 | char *v; | ||
| 292 | int gmt=0; | ||
| 293 | static char *mon[12]={ | ||
| 294 | "Jan","Feb","Mar","Apr","May","Jun", | ||
| 295 | "Jul","Aug","Sep","Oct","Nov","Dec"}; | ||
| 296 | int i; | ||
| 297 | int y=0,M=0,d=0,h=0,m=0,s=0; | ||
| 298 | |||
| 299 | i=tm->length; | ||
| 300 | v=(char *)tm->data; | ||
| 301 | |||
| 302 | if (i < 10) goto err; | ||
| 303 | if (v[i-1] == 'Z') gmt=1; | ||
| 304 | for (i=0; i<10; i++) | ||
| 305 | if ((v[i] > '9') || (v[i] < '0')) goto err; | ||
| 306 | y= (v[0]-'0')*10+(v[1]-'0'); | ||
| 307 | if (y < 50) y+=100; | ||
| 308 | M= (v[2]-'0')*10+(v[3]-'0'); | ||
| 309 | if ((M > 12) || (M < 1)) goto err; | ||
| 310 | d= (v[4]-'0')*10+(v[5]-'0'); | ||
| 311 | h= (v[6]-'0')*10+(v[7]-'0'); | ||
| 312 | m= (v[8]-'0')*10+(v[9]-'0'); | ||
| 313 | if ( (v[10] >= '0') && (v[10] <= '9') && | ||
| 314 | (v[11] >= '0') && (v[11] <= '9')) | ||
| 315 | s= (v[10]-'0')*10+(v[11]-'0'); | ||
| 316 | |||
| 317 | if (BIO_printf(bp,"%s %2d %02d:%02d:%02d %d%s", | ||
| 318 | mon[M-1],d,h,m,s,y+1900,(gmt)?" GMT":"") <= 0) | ||
| 319 | return(0); | ||
| 320 | else | ||
| 321 | return(1); | ||
| 322 | err: | ||
| 323 | BIO_write(bp,"Bad time value",14); | ||
| 324 | return(0); | ||
| 325 | } | ||
| 326 | |||
| 327 | int X509_NAME_print(bp,name,obase) | ||
| 328 | BIO *bp; | ||
| 329 | X509_NAME *name; | ||
| 330 | int obase; | ||
| 331 | { | ||
| 332 | char *s,*c; | ||
| 333 | int ret=0,l,ll,i,first=1; | ||
| 334 | char buf[256]; | ||
| 335 | |||
| 336 | ll=80-2-obase; | ||
| 337 | |||
| 338 | s=X509_NAME_oneline(name,buf,256); | ||
| 339 | s++; /* skip the first slash */ | ||
| 340 | |||
| 341 | l=ll; | ||
| 342 | c=s; | ||
| 343 | for (;;) | ||
| 344 | { | ||
| 345 | if ( ((*s == '/') && | ||
| 346 | ((s[1] >= 'A') && (s[1] <= 'Z') && ( | ||
| 347 | (s[2] == '=') || | ||
| 348 | ((s[2] >= 'A') && (s[2] <= 'Z') && | ||
| 349 | (s[3] == '=')) | ||
| 350 | ))) || | ||
| 351 | (*s == '\0')) | ||
| 352 | { | ||
| 353 | if ((l <= 0) && !first) | ||
| 354 | { | ||
| 355 | first=0; | ||
| 356 | if (BIO_write(bp,"\n",1) != 1) goto err; | ||
| 357 | for (i=0; i<obase; i++) | ||
| 358 | { | ||
| 359 | if (BIO_write(bp," ",1) != 1) goto err; | ||
| 360 | } | ||
| 361 | l=ll; | ||
| 362 | } | ||
| 363 | i=s-c; | ||
| 364 | if (BIO_write(bp,c,i) != i) goto err; | ||
| 365 | c+=i; | ||
| 366 | c++; | ||
| 367 | if (*s != '\0') | ||
| 368 | { | ||
| 369 | if (BIO_write(bp,", ",2) != 2) goto err; | ||
| 370 | } | ||
| 371 | l--; | ||
| 372 | } | ||
| 373 | if (*s == '\0') break; | ||
| 374 | s++; | ||
| 375 | l--; | ||
| 376 | } | ||
| 377 | |||
| 378 | ret=1; | ||
| 379 | if (0) | ||
| 380 | { | ||
| 381 | err: | ||
| 382 | X509err(X509_F_X509_NAME_PRINT,ERR_R_BUF_LIB); | ||
| 383 | } | ||
| 384 | return(ret); | ||
| 385 | } | ||
| 386 | |||
diff --git a/src/lib/libcrypto/asn1/x_algor.c b/src/lib/libcrypto/asn1/x_algor.c new file mode 100644 index 0000000000..0ed2c87b64 --- /dev/null +++ b/src/lib/libcrypto/asn1/x_algor.c | |||
| @@ -0,0 +1,126 @@ | |||
| 1 | /* crypto/asn1/x_algor.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 | |||
| 63 | /* | ||
| 64 | * ASN1err(ASN1_F_D2I_X509_ALGOR,ASN1_R_LENGTH_MISMATCH); | ||
| 65 | * ASN1err(ASN1_F_X509_ALGOR_NEW,ASN1_R_EXPECTING_A_SEQUENCE); | ||
| 66 | * ASN1err(ASN1_F_D2I_X509_ALGOR,ASN1_R_LENGTH_MISMATCH); | ||
| 67 | */ | ||
| 68 | |||
| 69 | int i2d_X509_ALGOR(a,pp) | ||
| 70 | X509_ALGOR *a; | ||
| 71 | unsigned char **pp; | ||
| 72 | { | ||
| 73 | M_ASN1_I2D_vars(a); | ||
| 74 | |||
| 75 | M_ASN1_I2D_len(a->algorithm,i2d_ASN1_OBJECT); | ||
| 76 | if (a->parameter != NULL) | ||
| 77 | { M_ASN1_I2D_len(a->parameter,i2d_ASN1_TYPE); } | ||
| 78 | |||
| 79 | M_ASN1_I2D_seq_total(); | ||
| 80 | M_ASN1_I2D_put(a->algorithm,i2d_ASN1_OBJECT); | ||
| 81 | if (a->parameter != NULL) | ||
| 82 | { M_ASN1_I2D_put(a->parameter,i2d_ASN1_TYPE); } | ||
| 83 | |||
| 84 | M_ASN1_I2D_finish(); | ||
| 85 | } | ||
| 86 | |||
| 87 | X509_ALGOR *d2i_X509_ALGOR(a,pp,length) | ||
| 88 | X509_ALGOR **a; | ||
| 89 | unsigned char **pp; | ||
| 90 | long length; | ||
| 91 | { | ||
| 92 | M_ASN1_D2I_vars(a,X509_ALGOR *,X509_ALGOR_new); | ||
| 93 | |||
| 94 | M_ASN1_D2I_Init(); | ||
| 95 | M_ASN1_D2I_start_sequence(); | ||
| 96 | M_ASN1_D2I_get(ret->algorithm,d2i_ASN1_OBJECT); | ||
| 97 | if (!M_ASN1_D2I_end_sequence()) | ||
| 98 | { M_ASN1_D2I_get(ret->parameter,d2i_ASN1_TYPE); } | ||
| 99 | else | ||
| 100 | { | ||
| 101 | ASN1_TYPE_free(ret->parameter); | ||
| 102 | ret->parameter=NULL; | ||
| 103 | } | ||
| 104 | M_ASN1_D2I_Finish(a,X509_ALGOR_free,ASN1_F_D2I_X509_ALGOR); | ||
| 105 | } | ||
| 106 | |||
| 107 | X509_ALGOR *X509_ALGOR_new() | ||
| 108 | { | ||
| 109 | X509_ALGOR *ret=NULL; | ||
| 110 | |||
| 111 | M_ASN1_New_Malloc(ret,X509_ALGOR); | ||
| 112 | M_ASN1_New(ret->algorithm,ASN1_OBJECT_new); | ||
| 113 | ret->parameter=NULL; | ||
| 114 | return(ret); | ||
| 115 | M_ASN1_New_Error(ASN1_F_X509_ALGOR_NEW); | ||
| 116 | } | ||
| 117 | |||
| 118 | void X509_ALGOR_free(a) | ||
| 119 | X509_ALGOR *a; | ||
| 120 | { | ||
| 121 | if (a == NULL) return; | ||
| 122 | ASN1_OBJECT_free(a->algorithm); | ||
| 123 | ASN1_TYPE_free(a->parameter); | ||
| 124 | Free((char *)a); | ||
| 125 | } | ||
| 126 | |||
diff --git a/src/lib/libcrypto/asn1/x_attrib.c b/src/lib/libcrypto/asn1/x_attrib.c new file mode 100644 index 0000000000..e52ced8627 --- /dev/null +++ b/src/lib/libcrypto/asn1/x_attrib.c | |||
| @@ -0,0 +1,152 @@ | |||
| 1 | /* crypto/asn1/x_attrib.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 "objects.h" | ||
| 62 | #include "asn1_mac.h" | ||
| 63 | |||
| 64 | /* | ||
| 65 | * ASN1err(ASN1_F_D2I_X509_ATTRIBUTE,ASN1_R_LENGTH_MISMATCH); | ||
| 66 | * ASN1err(ASN1_F_X509_ATTRIBUTE_NEW,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); | ||
| 67 | * ASN1err(ASN1_F_I2D_X509_ATTRIBUTE,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); | ||
| 68 | */ | ||
| 69 | |||
| 70 | /* sequence */ | ||
| 71 | int i2d_X509_ATTRIBUTE(a,pp) | ||
| 72 | X509_ATTRIBUTE *a; | ||
| 73 | unsigned char **pp; | ||
| 74 | { | ||
| 75 | int k=0; | ||
| 76 | int r=0,ret=0; | ||
| 77 | unsigned char **p=NULL; | ||
| 78 | |||
| 79 | if (a == NULL) return(0); | ||
| 80 | |||
| 81 | p=NULL; | ||
| 82 | for (;;) | ||
| 83 | { | ||
| 84 | if (k) | ||
| 85 | { | ||
| 86 | r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); | ||
| 87 | if (pp == NULL) return(r); | ||
| 88 | p=pp; | ||
| 89 | ASN1_put_object(p,1,ret,V_ASN1_SEQUENCE, | ||
| 90 | V_ASN1_UNIVERSAL); | ||
| 91 | } | ||
| 92 | |||
| 93 | ret+=i2d_ASN1_OBJECT(a->object,p); | ||
| 94 | if (a->set) | ||
| 95 | ret+=i2d_ASN1_SET(a->value.set,p,i2d_ASN1_TYPE, | ||
| 96 | V_ASN1_SET,V_ASN1_UNIVERSAL); | ||
| 97 | else | ||
| 98 | ret+=i2d_ASN1_TYPE(a->value.single,p); | ||
| 99 | if (k++) return(r); | ||
| 100 | } | ||
| 101 | } | ||
| 102 | |||
| 103 | X509_ATTRIBUTE *d2i_X509_ATTRIBUTE(a,pp,length) | ||
| 104 | X509_ATTRIBUTE **a; | ||
| 105 | unsigned char **pp; | ||
| 106 | long length; | ||
| 107 | { | ||
| 108 | M_ASN1_D2I_vars(a,X509_ATTRIBUTE *,X509_ATTRIBUTE_new); | ||
| 109 | |||
| 110 | M_ASN1_D2I_Init(); | ||
| 111 | M_ASN1_D2I_start_sequence(); | ||
| 112 | M_ASN1_D2I_get(ret->object,d2i_ASN1_OBJECT); | ||
| 113 | |||
| 114 | if ((c.slen != 0) && | ||
| 115 | (M_ASN1_next == (V_ASN1_CONSTRUCTED|V_ASN1_UNIVERSAL|V_ASN1_SET))) | ||
| 116 | { | ||
| 117 | ret->set=1; | ||
| 118 | M_ASN1_D2I_get_set(ret->value.set,d2i_ASN1_TYPE); | ||
| 119 | } | ||
| 120 | else | ||
| 121 | { | ||
| 122 | ret->set=0; | ||
| 123 | M_ASN1_D2I_get(ret->value.single,d2i_ASN1_TYPE); | ||
| 124 | } | ||
| 125 | |||
| 126 | M_ASN1_D2I_Finish(a,X509_ATTRIBUTE_free,ASN1_F_D2I_X509_ATTRIBUTE); | ||
| 127 | } | ||
| 128 | |||
| 129 | X509_ATTRIBUTE *X509_ATTRIBUTE_new() | ||
| 130 | { | ||
| 131 | X509_ATTRIBUTE *ret=NULL; | ||
| 132 | |||
| 133 | M_ASN1_New_Malloc(ret,X509_ATTRIBUTE); | ||
| 134 | M_ASN1_New(ret->object,ASN1_OBJECT_new); | ||
| 135 | ret->set=0; | ||
| 136 | ret->value.ptr=NULL; | ||
| 137 | return(ret); | ||
| 138 | M_ASN1_New_Error(ASN1_F_X509_ATTRIBUTE_NEW); | ||
| 139 | } | ||
| 140 | |||
| 141 | void X509_ATTRIBUTE_free(a) | ||
| 142 | X509_ATTRIBUTE *a; | ||
| 143 | { | ||
| 144 | if (a == NULL) return; | ||
| 145 | ASN1_OBJECT_free(a->object); | ||
| 146 | if (a->set) | ||
| 147 | sk_pop_free(a->value.set,ASN1_TYPE_free); | ||
| 148 | else | ||
| 149 | ASN1_TYPE_free(a->value.single); | ||
| 150 | Free((char *)a); | ||
| 151 | } | ||
| 152 | |||
diff --git a/src/lib/libcrypto/asn1/x_crl.c b/src/lib/libcrypto/asn1/x_crl.c new file mode 100644 index 0000000000..13acdab427 --- /dev/null +++ b/src/lib/libcrypto/asn1/x_crl.c | |||
| @@ -0,0 +1,353 @@ | |||
| 1 | /* crypto/asn1/x_crl.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_D2I_X509_CRL,ASN1_R_LENGTH_MISMATCH); | ||
| 66 | * ASN1err(ASN1_F_D2I_X509_CRL_INFO,ASN1_R_EXPECTING_A_SEQUENCE); | ||
| 67 | * ASN1err(ASN1_F_D2I_X509_REVOKED,ASN1_R_LENGTH_MISMATCH); | ||
| 68 | * ASN1err(ASN1_F_X509_CRL_NEW,ASN1_R_LENGTH_MISMATCH); | ||
| 69 | * ASN1err(ASN1_F_X509_CRL_INFO_NEW,ASN1_R_EXPECTING_A_SEQUENCE); | ||
| 70 | * ASN1err(ASN1_F_X509_REVOKED_NEW,ASN1_R_LENGTH_MISMATCH); | ||
| 71 | */ | ||
| 72 | |||
| 73 | #ifndef NOPROTO | ||
| 74 | static int X509_REVOKED_cmp(X509_REVOKED **a,X509_REVOKED **b); | ||
| 75 | static int X509_REVOKED_seq_cmp(X509_REVOKED **a,X509_REVOKED **b); | ||
| 76 | #else | ||
| 77 | static int X509_REVOKED_cmp(); | ||
| 78 | static int X509_REVOKED_seq_cmp(); | ||
| 79 | #endif | ||
| 80 | |||
| 81 | int i2d_X509_REVOKED(a,pp) | ||
| 82 | X509_REVOKED *a; | ||
| 83 | unsigned char **pp; | ||
| 84 | { | ||
| 85 | M_ASN1_I2D_vars(a); | ||
| 86 | |||
| 87 | M_ASN1_I2D_len(a->serialNumber,i2d_ASN1_INTEGER); | ||
| 88 | M_ASN1_I2D_len(a->revocationDate,i2d_ASN1_UTCTIME); | ||
| 89 | M_ASN1_I2D_len_SEQ_opt(a->extensions,i2d_X509_EXTENSION); | ||
| 90 | |||
| 91 | M_ASN1_I2D_seq_total(); | ||
| 92 | |||
| 93 | M_ASN1_I2D_put(a->serialNumber,i2d_ASN1_INTEGER); | ||
| 94 | M_ASN1_I2D_put(a->revocationDate,i2d_ASN1_UTCTIME); | ||
| 95 | M_ASN1_I2D_put_SEQ_opt(a->extensions,i2d_X509_EXTENSION); | ||
| 96 | |||
| 97 | M_ASN1_I2D_finish(); | ||
| 98 | } | ||
| 99 | |||
| 100 | X509_REVOKED *d2i_X509_REVOKED(a,pp,length) | ||
| 101 | X509_REVOKED **a; | ||
| 102 | unsigned char **pp; | ||
| 103 | long length; | ||
| 104 | { | ||
| 105 | M_ASN1_D2I_vars(a,X509_REVOKED *,X509_REVOKED_new); | ||
| 106 | |||
| 107 | M_ASN1_D2I_Init(); | ||
| 108 | M_ASN1_D2I_start_sequence(); | ||
| 109 | M_ASN1_D2I_get(ret->serialNumber,d2i_ASN1_INTEGER); | ||
| 110 | M_ASN1_D2I_get(ret->revocationDate,d2i_ASN1_UTCTIME); | ||
| 111 | M_ASN1_D2I_get_seq_opt(ret->extensions,d2i_X509_EXTENSION); | ||
| 112 | M_ASN1_D2I_Finish(a,X509_REVOKED_free,ASN1_F_D2I_X509_REVOKED); | ||
| 113 | } | ||
| 114 | |||
| 115 | int i2d_X509_CRL_INFO(a,pp) | ||
| 116 | X509_CRL_INFO *a; | ||
| 117 | unsigned char **pp; | ||
| 118 | { | ||
| 119 | int v1=0; | ||
| 120 | long l=0; | ||
| 121 | M_ASN1_I2D_vars(a); | ||
| 122 | |||
| 123 | if (sk_num(a->revoked) != 0) | ||
| 124 | qsort((char *)a->revoked->data,sk_num(a->revoked), | ||
| 125 | sizeof(X509_REVOKED *),(int (*)(P_CC_CC))X509_REVOKED_seq_cmp); | ||
| 126 | if ((a->version != NULL) && ((l=ASN1_INTEGER_get(a->version)) != 0)) | ||
| 127 | { | ||
| 128 | M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); | ||
| 129 | } | ||
| 130 | M_ASN1_I2D_len(a->sig_alg,i2d_X509_ALGOR); | ||
| 131 | M_ASN1_I2D_len(a->issuer,i2d_X509_NAME); | ||
| 132 | M_ASN1_I2D_len(a->lastUpdate,i2d_ASN1_UTCTIME); | ||
| 133 | if (a->nextUpdate != NULL) | ||
| 134 | { M_ASN1_I2D_len(a->nextUpdate,i2d_ASN1_UTCTIME); } | ||
| 135 | M_ASN1_I2D_len_SEQ_opt(a->revoked,i2d_X509_REVOKED); | ||
| 136 | M_ASN1_I2D_len_EXP_set_opt(a->extensions,i2d_X509_EXTENSION,0, | ||
| 137 | V_ASN1_SEQUENCE,v1); | ||
| 138 | |||
| 139 | M_ASN1_I2D_seq_total(); | ||
| 140 | |||
| 141 | if ((a->version != NULL) && (l != 0)) | ||
| 142 | { | ||
| 143 | M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER); | ||
| 144 | } | ||
| 145 | M_ASN1_I2D_put(a->sig_alg,i2d_X509_ALGOR); | ||
| 146 | M_ASN1_I2D_put(a->issuer,i2d_X509_NAME); | ||
| 147 | M_ASN1_I2D_put(a->lastUpdate,i2d_ASN1_UTCTIME); | ||
| 148 | if (a->nextUpdate != NULL) | ||
| 149 | { M_ASN1_I2D_put(a->nextUpdate,i2d_ASN1_UTCTIME); } | ||
| 150 | M_ASN1_I2D_put_SEQ_opt(a->revoked,i2d_X509_REVOKED); | ||
| 151 | M_ASN1_I2D_put_EXP_set_opt(a->extensions,i2d_X509_EXTENSION,0, | ||
| 152 | V_ASN1_SEQUENCE,v1); | ||
| 153 | |||
| 154 | M_ASN1_I2D_finish(); | ||
| 155 | } | ||
| 156 | |||
| 157 | X509_CRL_INFO *d2i_X509_CRL_INFO(a,pp,length) | ||
| 158 | X509_CRL_INFO **a; | ||
| 159 | unsigned char **pp; | ||
| 160 | long length; | ||
| 161 | { | ||
| 162 | int i,ver=0; | ||
| 163 | M_ASN1_D2I_vars(a,X509_CRL_INFO *,X509_CRL_INFO_new); | ||
| 164 | |||
| 165 | |||
| 166 | M_ASN1_D2I_Init(); | ||
| 167 | M_ASN1_D2I_start_sequence(); | ||
| 168 | M_ASN1_D2I_get_opt(ret->version,d2i_ASN1_INTEGER,V_ASN1_INTEGER); | ||
| 169 | if (ret->version != NULL) | ||
| 170 | ver=ret->version->data[0]; | ||
| 171 | |||
| 172 | if ((ver == 0) && (ret->version != NULL)) | ||
| 173 | { | ||
| 174 | ASN1_INTEGER_free(ret->version); | ||
| 175 | ret->version=NULL; | ||
| 176 | } | ||
| 177 | M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR); | ||
| 178 | M_ASN1_D2I_get(ret->issuer,d2i_X509_NAME); | ||
| 179 | M_ASN1_D2I_get(ret->lastUpdate,d2i_ASN1_UTCTIME); | ||
| 180 | M_ASN1_D2I_get_opt(ret->nextUpdate,d2i_ASN1_UTCTIME,V_ASN1_UTCTIME); | ||
| 181 | if (ret->revoked != NULL) | ||
| 182 | { | ||
| 183 | while (sk_num(ret->revoked)) | ||
| 184 | X509_REVOKED_free((X509_REVOKED *)sk_pop(ret->revoked)); | ||
| 185 | } | ||
| 186 | M_ASN1_D2I_get_seq_opt(ret->revoked,d2i_X509_REVOKED); | ||
| 187 | |||
| 188 | if (ret->revoked != NULL) | ||
| 189 | { | ||
| 190 | for (i=0; i<sk_num(ret->revoked); i++) | ||
| 191 | { | ||
| 192 | ((X509_REVOKED *)sk_value(ret->revoked,i))->sequence=i; | ||
| 193 | } | ||
| 194 | } | ||
| 195 | |||
| 196 | if (ver >= 1) | ||
| 197 | { | ||
| 198 | if (ret->extensions != NULL) | ||
| 199 | { | ||
| 200 | while (sk_num(ret->extensions)) | ||
| 201 | X509_EXTENSION_free((X509_EXTENSION *) | ||
| 202 | sk_pop(ret->extensions)); | ||
| 203 | } | ||
| 204 | |||
| 205 | M_ASN1_D2I_get_EXP_set_opt(ret->extensions,d2i_X509_EXTENSION, | ||
| 206 | 0,V_ASN1_SEQUENCE); | ||
| 207 | } | ||
| 208 | |||
| 209 | M_ASN1_D2I_Finish(a,X509_CRL_INFO_free,ASN1_F_D2I_X509_CRL_INFO); | ||
| 210 | } | ||
| 211 | |||
| 212 | int i2d_X509_CRL(a,pp) | ||
| 213 | X509_CRL *a; | ||
| 214 | unsigned char **pp; | ||
| 215 | { | ||
| 216 | M_ASN1_I2D_vars(a); | ||
| 217 | |||
| 218 | M_ASN1_I2D_len(a->crl,i2d_X509_CRL_INFO); | ||
| 219 | M_ASN1_I2D_len(a->sig_alg,i2d_X509_ALGOR); | ||
| 220 | M_ASN1_I2D_len(a->signature,i2d_ASN1_BIT_STRING); | ||
| 221 | |||
| 222 | M_ASN1_I2D_seq_total(); | ||
| 223 | |||
| 224 | M_ASN1_I2D_put(a->crl,i2d_X509_CRL_INFO); | ||
| 225 | M_ASN1_I2D_put(a->sig_alg,i2d_X509_ALGOR); | ||
| 226 | M_ASN1_I2D_put(a->signature,i2d_ASN1_BIT_STRING); | ||
| 227 | |||
| 228 | M_ASN1_I2D_finish(); | ||
| 229 | } | ||
| 230 | |||
| 231 | X509_CRL *d2i_X509_CRL(a,pp,length) | ||
| 232 | X509_CRL **a; | ||
| 233 | unsigned char **pp; | ||
| 234 | long length; | ||
| 235 | { | ||
| 236 | M_ASN1_D2I_vars(a,X509_CRL *,X509_CRL_new); | ||
| 237 | |||
| 238 | M_ASN1_D2I_Init(); | ||
| 239 | M_ASN1_D2I_start_sequence(); | ||
| 240 | M_ASN1_D2I_get(ret->crl,d2i_X509_CRL_INFO); | ||
| 241 | M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR); | ||
| 242 | M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING); | ||
| 243 | |||
| 244 | M_ASN1_D2I_Finish(a,X509_CRL_free,ASN1_F_D2I_X509_CRL); | ||
| 245 | } | ||
| 246 | |||
| 247 | |||
| 248 | X509_REVOKED *X509_REVOKED_new() | ||
| 249 | { | ||
| 250 | X509_REVOKED *ret=NULL; | ||
| 251 | |||
| 252 | M_ASN1_New_Malloc(ret,X509_REVOKED); | ||
| 253 | M_ASN1_New(ret->serialNumber,ASN1_INTEGER_new); | ||
| 254 | M_ASN1_New(ret->revocationDate,ASN1_UTCTIME_new); | ||
| 255 | ret->extensions=NULL; | ||
| 256 | return(ret); | ||
| 257 | M_ASN1_New_Error(ASN1_F_X509_REVOKED_NEW); | ||
| 258 | } | ||
| 259 | |||
| 260 | X509_CRL_INFO *X509_CRL_INFO_new() | ||
| 261 | { | ||
| 262 | X509_CRL_INFO *ret=NULL; | ||
| 263 | |||
| 264 | M_ASN1_New_Malloc(ret,X509_CRL_INFO); | ||
| 265 | ret->version=NULL; | ||
| 266 | M_ASN1_New(ret->sig_alg,X509_ALGOR_new); | ||
| 267 | M_ASN1_New(ret->issuer,X509_NAME_new); | ||
| 268 | M_ASN1_New(ret->lastUpdate,ASN1_UTCTIME_new); | ||
| 269 | ret->nextUpdate=NULL; | ||
| 270 | M_ASN1_New(ret->revoked,sk_new_null); | ||
| 271 | M_ASN1_New(ret->extensions,sk_new_null); | ||
| 272 | ret->revoked->comp=(int (*)())X509_REVOKED_cmp; | ||
| 273 | return(ret); | ||
| 274 | M_ASN1_New_Error(ASN1_F_X509_CRL_INFO_NEW); | ||
| 275 | } | ||
| 276 | |||
| 277 | X509_CRL *X509_CRL_new() | ||
| 278 | { | ||
| 279 | X509_CRL *ret=NULL; | ||
| 280 | |||
| 281 | M_ASN1_New_Malloc(ret,X509_CRL); | ||
| 282 | ret->references=1; | ||
| 283 | M_ASN1_New(ret->crl,X509_CRL_INFO_new); | ||
| 284 | M_ASN1_New(ret->sig_alg,X509_ALGOR_new); | ||
| 285 | M_ASN1_New(ret->signature,ASN1_BIT_STRING_new); | ||
| 286 | return(ret); | ||
| 287 | M_ASN1_New_Error(ASN1_F_X509_CRL_NEW); | ||
| 288 | } | ||
| 289 | |||
| 290 | void X509_REVOKED_free(a) | ||
| 291 | X509_REVOKED *a; | ||
| 292 | { | ||
| 293 | if (a == NULL) return; | ||
| 294 | ASN1_INTEGER_free(a->serialNumber); | ||
| 295 | ASN1_UTCTIME_free(a->revocationDate); | ||
| 296 | sk_pop_free(a->extensions,X509_EXTENSION_free); | ||
| 297 | Free((char *)a); | ||
| 298 | } | ||
| 299 | |||
| 300 | void X509_CRL_INFO_free(a) | ||
| 301 | X509_CRL_INFO *a; | ||
| 302 | { | ||
| 303 | if (a == NULL) return; | ||
| 304 | ASN1_INTEGER_free(a->version); | ||
| 305 | X509_ALGOR_free(a->sig_alg); | ||
| 306 | X509_NAME_free(a->issuer); | ||
| 307 | ASN1_UTCTIME_free(a->lastUpdate); | ||
| 308 | if (a->nextUpdate) | ||
| 309 | ASN1_UTCTIME_free(a->nextUpdate); | ||
| 310 | sk_pop_free(a->revoked,X509_REVOKED_free); | ||
| 311 | sk_pop_free(a->extensions,X509_EXTENSION_free); | ||
| 312 | Free((char *)a); | ||
| 313 | } | ||
| 314 | |||
| 315 | void X509_CRL_free(a) | ||
| 316 | X509_CRL *a; | ||
| 317 | { | ||
| 318 | int i; | ||
| 319 | |||
| 320 | if (a == NULL) return; | ||
| 321 | |||
| 322 | i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_X509_CRL); | ||
| 323 | #ifdef REF_PRINT | ||
| 324 | REF_PRINT("X509_CRL",a); | ||
| 325 | #endif | ||
| 326 | if (i > 0) return; | ||
| 327 | #ifdef REF_CHECK | ||
| 328 | if (i < 0) | ||
| 329 | { | ||
| 330 | fprintf(stderr,"X509_CRL_free, bad reference count\n"); | ||
| 331 | abort(); | ||
| 332 | } | ||
| 333 | #endif | ||
| 334 | |||
| 335 | X509_CRL_INFO_free(a->crl); | ||
| 336 | X509_ALGOR_free(a->sig_alg); | ||
| 337 | ASN1_BIT_STRING_free(a->signature); | ||
| 338 | Free((char *)a); | ||
| 339 | } | ||
| 340 | |||
| 341 | static int X509_REVOKED_cmp(a,b) | ||
| 342 | X509_REVOKED **a,**b; | ||
| 343 | { | ||
| 344 | return(ASN1_STRING_cmp( | ||
| 345 | (ASN1_STRING *)(*a)->serialNumber, | ||
| 346 | (ASN1_STRING *)(*b)->serialNumber)); | ||
| 347 | } | ||
| 348 | |||
| 349 | static int X509_REVOKED_seq_cmp(a,b) | ||
| 350 | X509_REVOKED **a,**b; | ||
| 351 | { | ||
| 352 | return((*a)->sequence-(*b)->sequence); | ||
| 353 | } | ||
diff --git a/src/lib/libcrypto/asn1/x_exten.c b/src/lib/libcrypto/asn1/x_exten.c new file mode 100644 index 0000000000..54ffe2f00b --- /dev/null +++ b/src/lib/libcrypto/asn1/x_exten.c | |||
| @@ -0,0 +1,156 @@ | |||
| 1 | /* crypto/asn1/x_exten.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 "objects.h" | ||
| 62 | #include "asn1_mac.h" | ||
| 63 | |||
| 64 | /* | ||
| 65 | * ASN1err(ASN1_F_D2I_X509_EXTENSION,ASN1_R_LENGTH_MISMATCH); | ||
| 66 | * ASN1err(ASN1_F_X509_EXTENSION_NEW,ASN1_R_LENGTH_MISMATCH); | ||
| 67 | */ | ||
| 68 | |||
| 69 | int i2d_X509_EXTENSION(a,pp) | ||
| 70 | X509_EXTENSION *a; | ||
| 71 | unsigned char **pp; | ||
| 72 | { | ||
| 73 | int k=0; | ||
| 74 | int r=0,ret=0; | ||
| 75 | unsigned char **p=NULL; | ||
| 76 | |||
| 77 | if (a == NULL) return(0); | ||
| 78 | |||
| 79 | p=NULL; | ||
| 80 | for (;;) | ||
| 81 | { | ||
| 82 | if (k) | ||
| 83 | { | ||
| 84 | r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); | ||
| 85 | if (pp == NULL) return(r); | ||
| 86 | p=pp; | ||
| 87 | ASN1_put_object(p,1,ret,V_ASN1_SEQUENCE, | ||
| 88 | V_ASN1_UNIVERSAL); | ||
| 89 | } | ||
| 90 | |||
| 91 | ret+=i2d_ASN1_OBJECT(a->object,p); | ||
| 92 | if ((a->critical) || a->netscape_hack) | ||
| 93 | ret+=i2d_ASN1_BOOLEAN(a->critical,p); | ||
| 94 | ret+=i2d_ASN1_OCTET_STRING(a->value,p); | ||
| 95 | if (k++) return(r); | ||
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 99 | X509_EXTENSION *d2i_X509_EXTENSION(a,pp,length) | ||
| 100 | X509_EXTENSION **a; | ||
| 101 | unsigned char **pp; | ||
| 102 | long length; | ||
| 103 | { | ||
| 104 | int i; | ||
| 105 | M_ASN1_D2I_vars(a,X509_EXTENSION *,X509_EXTENSION_new); | ||
| 106 | |||
| 107 | M_ASN1_D2I_Init(); | ||
| 108 | M_ASN1_D2I_start_sequence(); | ||
| 109 | M_ASN1_D2I_get(ret->object,d2i_ASN1_OBJECT); | ||
| 110 | |||
| 111 | if ((ret->argp != NULL) && (ret->ex_free != NULL)) | ||
| 112 | ret->ex_free(ret); | ||
| 113 | ret->argl=0; | ||
| 114 | ret->argp=NULL; | ||
| 115 | ret->netscape_hack=0; | ||
| 116 | if ((c.slen != 0) && | ||
| 117 | (M_ASN1_next == (V_ASN1_UNIVERSAL|V_ASN1_BOOLEAN))) | ||
| 118 | { | ||
| 119 | c.q=c.p; | ||
| 120 | if (d2i_ASN1_BOOLEAN(&i,&c.p,c.slen) < 0) goto err; | ||
| 121 | ret->critical=i; | ||
| 122 | c.slen-=(c.p-c.q); | ||
| 123 | if (ret->critical == 0) ret->netscape_hack=1; | ||
| 124 | } | ||
| 125 | M_ASN1_D2I_get(ret->value,d2i_ASN1_OCTET_STRING); | ||
| 126 | |||
| 127 | M_ASN1_D2I_Finish(a,X509_EXTENSION_free,ASN1_F_D2I_X509_EXTENSION); | ||
| 128 | } | ||
| 129 | |||
| 130 | X509_EXTENSION *X509_EXTENSION_new() | ||
| 131 | { | ||
| 132 | X509_EXTENSION *ret=NULL; | ||
| 133 | |||
| 134 | M_ASN1_New_Malloc(ret,X509_EXTENSION); | ||
| 135 | M_ASN1_New(ret->object,ASN1_OBJECT_new); | ||
| 136 | M_ASN1_New(ret->value,ASN1_OCTET_STRING_new); | ||
| 137 | ret->critical=0; | ||
| 138 | ret->netscape_hack=0; | ||
| 139 | ret->argl=0L; | ||
| 140 | ret->argp=NULL; | ||
| 141 | ret->ex_free=NULL; | ||
| 142 | return(ret); | ||
| 143 | M_ASN1_New_Error(ASN1_F_X509_EXTENSION_NEW); | ||
| 144 | } | ||
| 145 | |||
| 146 | void X509_EXTENSION_free(a) | ||
| 147 | X509_EXTENSION *a; | ||
| 148 | { | ||
| 149 | if (a == NULL) return; | ||
| 150 | if ((a->argp != NULL) && (a->ex_free != NULL)) | ||
| 151 | a->ex_free(a); | ||
| 152 | ASN1_OBJECT_free(a->object); | ||
| 153 | ASN1_OCTET_STRING_free(a->value); | ||
| 154 | Free((char *)a); | ||
| 155 | } | ||
| 156 | |||
diff --git a/src/lib/libcrypto/asn1/x_info.c b/src/lib/libcrypto/asn1/x_info.c new file mode 100644 index 0000000000..b55f0ce77a --- /dev/null +++ b/src/lib/libcrypto/asn1/x_info.c | |||
| @@ -0,0 +1,111 @@ | |||
| 1 | /* crypto/asn1/x_info.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 "evp.h" | ||
| 62 | #include "asn1_mac.h" | ||
| 63 | #include "x509.h" | ||
| 64 | |||
| 65 | X509_INFO *X509_INFO_new() | ||
| 66 | { | ||
| 67 | X509_INFO *ret=NULL; | ||
| 68 | |||
| 69 | ret=(X509_INFO *)Malloc(sizeof(X509_INFO)); | ||
| 70 | if (ret == NULL) | ||
| 71 | { | ||
| 72 | ASN1err(ASN1_F_X509_INFO_NEW,ERR_R_MALLOC_FAILURE); | ||
| 73 | return(NULL); | ||
| 74 | } | ||
| 75 | |||
| 76 | ret->enc_cipher.cipher=NULL; | ||
| 77 | ret->enc_len=0; | ||
| 78 | ret->enc_data=NULL; | ||
| 79 | |||
| 80 | ret->references=1; | ||
| 81 | ret->x509=NULL; | ||
| 82 | ret->crl=NULL; | ||
| 83 | ret->x_pkey=NULL; | ||
| 84 | return(ret); | ||
| 85 | } | ||
| 86 | |||
| 87 | void X509_INFO_free(x) | ||
| 88 | X509_INFO *x; | ||
| 89 | { | ||
| 90 | int i; | ||
| 91 | |||
| 92 | if (x == NULL) return; | ||
| 93 | |||
| 94 | i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_X509_INFO); | ||
| 95 | #ifdef REF_PRINT | ||
| 96 | REF_PRINT("X509_INFO",x); | ||
| 97 | #endif | ||
| 98 | if (i > 0) return; | ||
| 99 | #ifdef REF_CHECK | ||
| 100 | if (i < 0) | ||
| 101 | { | ||
| 102 | fprintf(stderr,"X509_INFO_free, bad reference count\n"); | ||
| 103 | abort(); | ||
| 104 | } | ||
| 105 | #endif | ||
| 106 | |||
| 107 | if (x->x509 != NULL) X509_free(x->x509); | ||
| 108 | if (x->crl != NULL) X509_CRL_free(x->crl); | ||
| 109 | if (x->x_pkey != NULL) X509_PKEY_free(x->x_pkey); | ||
| 110 | Free((char *)x); | ||
| 111 | } | ||
diff --git a/src/lib/libcrypto/asn1/x_name.c b/src/lib/libcrypto/asn1/x_name.c new file mode 100644 index 0000000000..28b9c34b58 --- /dev/null +++ b/src/lib/libcrypto/asn1/x_name.c | |||
| @@ -0,0 +1,295 @@ | |||
| 1 | /* crypto/asn1/x_name.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 "objects.h" | ||
| 62 | #include "asn1_mac.h" | ||
| 63 | |||
| 64 | /* | ||
| 65 | * ASN1err(ASN1_F_D2I_X509_NAME,ASN1_R_LENGTH_MISMATCH); | ||
| 66 | * ASN1err(ASN1_F_X509_NAME_NEW,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); | ||
| 67 | * ASN1err(ASN1_F_D2I_X509_NAME_ENTRY,ASN1_R_LENGTH_MISMATCH); | ||
| 68 | * ASN1err(ASN1_F_X509_NAME_ENTRY_NEW,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); | ||
| 69 | */ | ||
| 70 | |||
| 71 | #ifndef NOPROTO | ||
| 72 | static int i2d_X509_NAME_entries(X509_NAME *a); | ||
| 73 | #else | ||
| 74 | static int i2d_X509_NAME_entries(); | ||
| 75 | #endif | ||
| 76 | |||
| 77 | int i2d_X509_NAME_ENTRY(a,pp) | ||
| 78 | X509_NAME_ENTRY *a; | ||
| 79 | unsigned char **pp; | ||
| 80 | { | ||
| 81 | M_ASN1_I2D_vars(a); | ||
| 82 | |||
| 83 | M_ASN1_I2D_len(a->object,i2d_ASN1_OBJECT); | ||
| 84 | M_ASN1_I2D_len(a->value,i2d_ASN1_PRINTABLE); | ||
| 85 | |||
| 86 | M_ASN1_I2D_seq_total(); | ||
| 87 | |||
| 88 | M_ASN1_I2D_put(a->object,i2d_ASN1_OBJECT); | ||
| 89 | M_ASN1_I2D_put(a->value,i2d_ASN1_PRINTABLE); | ||
| 90 | |||
| 91 | M_ASN1_I2D_finish(); | ||
| 92 | } | ||
| 93 | |||
| 94 | X509_NAME_ENTRY *d2i_X509_NAME_ENTRY(a,pp,length) | ||
| 95 | X509_NAME_ENTRY **a; | ||
| 96 | unsigned char **pp; | ||
| 97 | long length; | ||
| 98 | { | ||
| 99 | M_ASN1_D2I_vars(a,X509_NAME_ENTRY *,X509_NAME_ENTRY_new); | ||
| 100 | |||
| 101 | M_ASN1_D2I_Init(); | ||
| 102 | M_ASN1_D2I_start_sequence(); | ||
| 103 | M_ASN1_D2I_get(ret->object,d2i_ASN1_OBJECT); | ||
| 104 | M_ASN1_D2I_get(ret->value,d2i_ASN1_PRINTABLE); | ||
| 105 | ret->set=0; | ||
| 106 | M_ASN1_D2I_Finish(a,X509_NAME_ENTRY_free,ASN1_F_D2I_X509_NAME_ENTRY); | ||
| 107 | } | ||
| 108 | |||
| 109 | int i2d_X509_NAME(a,pp) | ||
| 110 | X509_NAME *a; | ||
| 111 | unsigned char **pp; | ||
| 112 | { | ||
| 113 | int ret; | ||
| 114 | |||
| 115 | if (a == NULL) return(0); | ||
| 116 | if (a->modified) | ||
| 117 | { | ||
| 118 | ret=i2d_X509_NAME_entries(a); | ||
| 119 | if (ret < 0) return(ret); | ||
| 120 | } | ||
| 121 | |||
| 122 | ret=a->bytes->length; | ||
| 123 | if (pp != NULL) | ||
| 124 | { | ||
| 125 | memcpy(*pp,a->bytes->data,ret); | ||
| 126 | *pp+=ret; | ||
| 127 | } | ||
| 128 | return(ret); | ||
| 129 | } | ||
| 130 | |||
| 131 | static int i2d_X509_NAME_entries(a) | ||
| 132 | X509_NAME *a; | ||
| 133 | { | ||
| 134 | X509_NAME_ENTRY *ne,*fe=NULL; | ||
| 135 | STACK *sk; | ||
| 136 | BUF_MEM *buf=NULL; | ||
| 137 | int set=0,r,ret=0; | ||
| 138 | int i; | ||
| 139 | unsigned char *p; | ||
| 140 | int size=0; | ||
| 141 | |||
| 142 | sk=a->entries; | ||
| 143 | for (i=0; i<sk_num(sk); i++) | ||
| 144 | { | ||
| 145 | ne=(X509_NAME_ENTRY *)sk_value(sk,i); | ||
| 146 | if (fe == NULL) | ||
| 147 | { | ||
| 148 | fe=ne; | ||
| 149 | size=0; | ||
| 150 | } | ||
| 151 | |||
| 152 | if (ne->set != set) | ||
| 153 | { | ||
| 154 | ret+=ASN1_object_size(1,size,V_ASN1_SET); | ||
| 155 | fe->size=size; | ||
| 156 | fe=ne; | ||
| 157 | size=0; | ||
| 158 | set=ne->set; | ||
| 159 | } | ||
| 160 | size+=i2d_X509_NAME_ENTRY(ne,NULL); | ||
| 161 | } | ||
| 162 | |||
| 163 | ret+=ASN1_object_size(1,size,V_ASN1_SET); | ||
| 164 | if (fe != NULL) | ||
| 165 | fe->size=size; | ||
| 166 | |||
| 167 | r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); | ||
| 168 | |||
| 169 | buf=a->bytes; | ||
| 170 | if (!BUF_MEM_grow(buf,r)) goto err; | ||
| 171 | p=(unsigned char *)buf->data; | ||
| 172 | |||
| 173 | ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); | ||
| 174 | |||
| 175 | set= -1; | ||
| 176 | for (i=0; i<sk_num(sk); i++) | ||
| 177 | { | ||
| 178 | ne=(X509_NAME_ENTRY *)sk_value(sk,i); | ||
| 179 | if (set != ne->set) | ||
| 180 | { | ||
| 181 | set=ne->set; | ||
| 182 | ASN1_put_object(&p,1,ne->size, | ||
| 183 | V_ASN1_SET,V_ASN1_UNIVERSAL); | ||
| 184 | } | ||
| 185 | i2d_X509_NAME_ENTRY(ne,&p); | ||
| 186 | } | ||
| 187 | a->modified=0; | ||
| 188 | return(r); | ||
| 189 | err: | ||
| 190 | return(-1); | ||
| 191 | } | ||
| 192 | |||
| 193 | X509_NAME *d2i_X509_NAME(a,pp,length) | ||
| 194 | X509_NAME **a; | ||
| 195 | unsigned char **pp; | ||
| 196 | long length; | ||
| 197 | { | ||
| 198 | int set=0,i; | ||
| 199 | int idx=0; | ||
| 200 | unsigned char *orig; | ||
| 201 | M_ASN1_D2I_vars(a,X509_NAME *,X509_NAME_new); | ||
| 202 | |||
| 203 | orig= *pp; | ||
| 204 | if (sk_num(ret->entries) > 0) | ||
| 205 | { | ||
| 206 | while (sk_num(ret->entries) > 0) | ||
| 207 | X509_NAME_ENTRY_free((X509_NAME_ENTRY *) | ||
| 208 | sk_pop(ret->entries)); | ||
| 209 | } | ||
| 210 | |||
| 211 | M_ASN1_D2I_Init(); | ||
| 212 | M_ASN1_D2I_start_sequence(); | ||
| 213 | for (;;) | ||
| 214 | { | ||
| 215 | if (M_ASN1_D2I_end_sequence()) break; | ||
| 216 | M_ASN1_D2I_get_set(ret->entries,d2i_X509_NAME_ENTRY); | ||
| 217 | for (; idx < sk_num(ret->entries); idx++) | ||
| 218 | { | ||
| 219 | ((X509_NAME_ENTRY *)sk_value(ret->entries,idx))->set= | ||
| 220 | set; | ||
| 221 | } | ||
| 222 | set++; | ||
| 223 | } | ||
| 224 | |||
| 225 | i=(int)(c.p-orig); | ||
| 226 | if (!BUF_MEM_grow(ret->bytes,i)) goto err; | ||
| 227 | memcpy(ret->bytes->data,orig,i); | ||
| 228 | ret->bytes->length=i; | ||
| 229 | ret->modified=0; | ||
| 230 | |||
| 231 | M_ASN1_D2I_Finish(a,X509_NAME_free,ASN1_F_D2I_X509_NAME); | ||
| 232 | } | ||
| 233 | |||
| 234 | X509_NAME *X509_NAME_new() | ||
| 235 | { | ||
| 236 | X509_NAME *ret=NULL; | ||
| 237 | |||
| 238 | M_ASN1_New_Malloc(ret,X509_NAME); | ||
| 239 | if ((ret->entries=sk_new(NULL)) == NULL) goto err2; | ||
| 240 | M_ASN1_New(ret->bytes,BUF_MEM_new); | ||
| 241 | ret->modified=1; | ||
| 242 | return(ret); | ||
| 243 | M_ASN1_New_Error(ASN1_F_X509_NAME_NEW); | ||
| 244 | } | ||
| 245 | |||
| 246 | X509_NAME_ENTRY *X509_NAME_ENTRY_new() | ||
| 247 | { | ||
| 248 | X509_NAME_ENTRY *ret=NULL; | ||
| 249 | |||
| 250 | M_ASN1_New_Malloc(ret,X509_NAME_ENTRY); | ||
| 251 | /* M_ASN1_New(ret->object,ASN1_OBJECT_new);*/ | ||
| 252 | ret->object=NULL; | ||
| 253 | ret->set=0; | ||
| 254 | M_ASN1_New(ret->value,ASN1_STRING_new); | ||
| 255 | return(ret); | ||
| 256 | M_ASN1_New_Error(ASN1_F_X509_NAME_ENTRY_NEW); | ||
| 257 | } | ||
| 258 | |||
| 259 | void X509_NAME_free(a) | ||
| 260 | X509_NAME *a; | ||
| 261 | { | ||
| 262 | BUF_MEM_free(a->bytes); | ||
| 263 | sk_pop_free(a->entries,X509_NAME_ENTRY_free); | ||
| 264 | Free((char *)a); | ||
| 265 | } | ||
| 266 | |||
| 267 | void X509_NAME_ENTRY_free(a) | ||
| 268 | X509_NAME_ENTRY *a; | ||
| 269 | { | ||
| 270 | if (a == NULL) return; | ||
| 271 | ASN1_OBJECT_free(a->object); | ||
| 272 | ASN1_BIT_STRING_free(a->value); | ||
| 273 | Free((char *)a); | ||
| 274 | } | ||
| 275 | |||
| 276 | int X509_NAME_set(xn,name) | ||
| 277 | X509_NAME **xn; | ||
| 278 | X509_NAME *name; | ||
| 279 | { | ||
| 280 | X509_NAME *in; | ||
| 281 | |||
| 282 | if (*xn == NULL) return(0); | ||
| 283 | |||
| 284 | if (*xn != name) | ||
| 285 | { | ||
| 286 | in=X509_NAME_dup(name); | ||
| 287 | if (in != NULL) | ||
| 288 | { | ||
| 289 | X509_NAME_free(*xn); | ||
| 290 | *xn=in; | ||
| 291 | } | ||
| 292 | } | ||
| 293 | return(*xn != NULL); | ||
| 294 | } | ||
| 295 | |||
diff --git a/src/lib/libcrypto/asn1/x_pkey.c b/src/lib/libcrypto/asn1/x_pkey.c new file mode 100644 index 0000000000..1d4d926129 --- /dev/null +++ b/src/lib/libcrypto/asn1/x_pkey.c | |||
| @@ -0,0 +1,156 @@ | |||
| 1 | /* crypto/asn1/x_pkey.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 "evp.h" | ||
| 62 | #include "objects.h" | ||
| 63 | #include "asn1_mac.h" | ||
| 64 | |||
| 65 | /* ASN1err(ASN1_F_D2I_X509_PKEY,ASN1_R_UNSUPPORTED_CIPHER); */ | ||
| 66 | /* ASN1err(ASN1_F_X509_PKEY_NEW,ASN1_R_IV_TOO_LARGE); */ | ||
| 67 | |||
| 68 | /* need to implement */ | ||
| 69 | int i2d_X509_PKEY(a,pp) | ||
| 70 | X509_PKEY *a; | ||
| 71 | unsigned char **pp; | ||
| 72 | { | ||
| 73 | return(0); | ||
| 74 | } | ||
| 75 | |||
| 76 | X509_PKEY *d2i_X509_PKEY(a,pp,length) | ||
| 77 | X509_PKEY **a; | ||
| 78 | unsigned char **pp; | ||
| 79 | long length; | ||
| 80 | { | ||
| 81 | int i; | ||
| 82 | M_ASN1_D2I_vars(a,X509_PKEY *,X509_PKEY_new); | ||
| 83 | |||
| 84 | M_ASN1_D2I_Init(); | ||
| 85 | M_ASN1_D2I_start_sequence(); | ||
| 86 | M_ASN1_D2I_get(ret->enc_algor,d2i_X509_ALGOR); | ||
| 87 | M_ASN1_D2I_get(ret->enc_pkey,d2i_ASN1_OCTET_STRING); | ||
| 88 | |||
| 89 | ret->cipher.cipher=EVP_get_cipherbyname( | ||
| 90 | OBJ_nid2ln(OBJ_obj2nid(ret->enc_algor->algorithm))); | ||
| 91 | if (ret->cipher.cipher == NULL) | ||
| 92 | { | ||
| 93 | c.error=ASN1_R_UNSUPPORTED_CIPHER; | ||
| 94 | goto err; | ||
| 95 | } | ||
| 96 | if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING) | ||
| 97 | { | ||
| 98 | i=ret->enc_algor->parameter->value.octet_string->length; | ||
| 99 | if (i > EVP_MAX_IV_LENGTH) | ||
| 100 | { | ||
| 101 | c.error=ASN1_R_IV_TOO_LARGE; | ||
| 102 | goto err; | ||
| 103 | } | ||
| 104 | memcpy(ret->cipher.iv, | ||
| 105 | ret->enc_algor->parameter->value.octet_string->data,i); | ||
| 106 | } | ||
| 107 | else | ||
| 108 | memset(ret->cipher.iv,0,EVP_MAX_IV_LENGTH); | ||
| 109 | M_ASN1_D2I_Finish(a,X509_PKEY_free,ASN1_F_D2I_X509_PKEY); | ||
| 110 | } | ||
| 111 | |||
| 112 | X509_PKEY *X509_PKEY_new() | ||
| 113 | { | ||
| 114 | X509_PKEY *ret=NULL; | ||
| 115 | |||
| 116 | M_ASN1_New_Malloc(ret,X509_PKEY); | ||
| 117 | ret->version=0; | ||
| 118 | M_ASN1_New(ret->enc_algor,X509_ALGOR_new); | ||
| 119 | M_ASN1_New(ret->enc_pkey,ASN1_OCTET_STRING_new); | ||
| 120 | ret->dec_pkey=NULL; | ||
| 121 | ret->key_length=0; | ||
| 122 | ret->key_data=NULL; | ||
| 123 | ret->key_free=0; | ||
| 124 | ret->cipher.cipher=NULL; | ||
| 125 | memset(ret->cipher.iv,0,EVP_MAX_IV_LENGTH); | ||
| 126 | ret->references=1; | ||
| 127 | return(ret); | ||
| 128 | M_ASN1_New_Error(ASN1_F_X509_PKEY_NEW); | ||
| 129 | } | ||
| 130 | |||
| 131 | void X509_PKEY_free(x) | ||
| 132 | X509_PKEY *x; | ||
| 133 | { | ||
| 134 | int i; | ||
| 135 | |||
| 136 | if (x == NULL) return; | ||
| 137 | |||
| 138 | i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_X509_PKEY); | ||
| 139 | #ifdef REF_PRINT | ||
| 140 | REF_PRINT("X509_PKEY",x); | ||
| 141 | #endif | ||
| 142 | if (i > 0) return; | ||
| 143 | #ifdef REF_CHECK | ||
| 144 | if (i < 0) | ||
| 145 | { | ||
| 146 | fprintf(stderr,"X509_PKEY_free, bad reference count\n"); | ||
| 147 | abort(); | ||
| 148 | } | ||
| 149 | #endif | ||
| 150 | |||
| 151 | if (x->enc_algor != NULL) X509_ALGOR_free(x->enc_algor); | ||
| 152 | if (x->enc_pkey != NULL) ASN1_OCTET_STRING_free(x->enc_pkey); | ||
| 153 | if (x->dec_pkey != NULL)EVP_PKEY_free(x->dec_pkey); | ||
| 154 | if ((x->key_data != NULL) && (x->key_free)) Free((char *)x->key_data); | ||
| 155 | Free((char *)(char *)x); | ||
| 156 | } | ||
diff --git a/src/lib/libcrypto/asn1/x_pubkey.c b/src/lib/libcrypto/asn1/x_pubkey.c new file mode 100644 index 0000000000..a309cf74a7 --- /dev/null +++ b/src/lib/libcrypto/asn1/x_pubkey.c | |||
| @@ -0,0 +1,256 @@ | |||
| 1 | /* crypto/asn1/x_pubkey.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 | |||
| 63 | /* | ||
| 64 | * ASN1err(ASN1_F_D2I_X509_PUBKEY,ASN1_R_LENGTH_MISMATCH); | ||
| 65 | * ASN1err(ASN1_F_X509_PUBKEY_NEW,ASN1_R_LENGTH_MISMATCH); | ||
| 66 | */ | ||
| 67 | |||
| 68 | int i2d_X509_PUBKEY(a,pp) | ||
| 69 | X509_PUBKEY *a; | ||
| 70 | unsigned char **pp; | ||
| 71 | { | ||
| 72 | M_ASN1_I2D_vars(a); | ||
| 73 | |||
| 74 | M_ASN1_I2D_len(a->algor, i2d_X509_ALGOR); | ||
| 75 | M_ASN1_I2D_len(a->public_key, i2d_ASN1_BIT_STRING); | ||
| 76 | |||
| 77 | M_ASN1_I2D_seq_total(); | ||
| 78 | |||
| 79 | M_ASN1_I2D_put(a->algor, i2d_X509_ALGOR); | ||
| 80 | M_ASN1_I2D_put(a->public_key, i2d_ASN1_BIT_STRING); | ||
| 81 | |||
| 82 | M_ASN1_I2D_finish(); | ||
| 83 | } | ||
| 84 | |||
| 85 | X509_PUBKEY *d2i_X509_PUBKEY(a,pp,length) | ||
| 86 | X509_PUBKEY **a; | ||
| 87 | unsigned char **pp; | ||
| 88 | long length; | ||
| 89 | { | ||
| 90 | M_ASN1_D2I_vars(a,X509_PUBKEY *,X509_PUBKEY_new); | ||
| 91 | |||
| 92 | M_ASN1_D2I_Init(); | ||
| 93 | M_ASN1_D2I_start_sequence(); | ||
| 94 | M_ASN1_D2I_get(ret->algor,d2i_X509_ALGOR); | ||
| 95 | M_ASN1_D2I_get(ret->public_key,d2i_ASN1_BIT_STRING); | ||
| 96 | if (ret->pkey != NULL) | ||
| 97 | { | ||
| 98 | EVP_PKEY_free(ret->pkey); | ||
| 99 | ret->pkey=NULL; | ||
| 100 | } | ||
| 101 | M_ASN1_D2I_Finish(a,X509_PUBKEY_free,ASN1_F_D2I_X509_PUBKEY); | ||
| 102 | } | ||
| 103 | |||
| 104 | X509_PUBKEY *X509_PUBKEY_new() | ||
| 105 | { | ||
| 106 | X509_PUBKEY *ret=NULL; | ||
| 107 | |||
| 108 | M_ASN1_New_Malloc(ret,X509_PUBKEY); | ||
| 109 | M_ASN1_New(ret->algor,X509_ALGOR_new); | ||
| 110 | M_ASN1_New(ret->public_key,ASN1_BIT_STRING_new); | ||
| 111 | ret->pkey=NULL; | ||
| 112 | return(ret); | ||
| 113 | M_ASN1_New_Error(ASN1_F_X509_PUBKEY_NEW); | ||
| 114 | } | ||
| 115 | |||
| 116 | void X509_PUBKEY_free(a) | ||
| 117 | X509_PUBKEY *a; | ||
| 118 | { | ||
| 119 | if (a == NULL) return; | ||
| 120 | X509_ALGOR_free(a->algor); | ||
| 121 | ASN1_BIT_STRING_free(a->public_key); | ||
| 122 | if (a->pkey != NULL) EVP_PKEY_free(a->pkey); | ||
| 123 | Free((char *)a); | ||
| 124 | } | ||
| 125 | |||
| 126 | int X509_PUBKEY_set(x,pkey) | ||
| 127 | X509_PUBKEY **x; | ||
| 128 | EVP_PKEY *pkey; | ||
| 129 | { | ||
| 130 | int ok=0; | ||
| 131 | X509_PUBKEY *pk; | ||
| 132 | X509_ALGOR *a; | ||
| 133 | ASN1_OBJECT *o; | ||
| 134 | unsigned char *s,*p; | ||
| 135 | int i; | ||
| 136 | |||
| 137 | if (x == NULL) return(0); | ||
| 138 | |||
| 139 | if ((pk=X509_PUBKEY_new()) == NULL) goto err; | ||
| 140 | a=pk->algor; | ||
| 141 | |||
| 142 | /* set the algorithm id */ | ||
| 143 | if ((o=OBJ_nid2obj(pkey->type)) == NULL) goto err; | ||
| 144 | ASN1_OBJECT_free(a->algorithm); | ||
| 145 | a->algorithm=o; | ||
| 146 | |||
| 147 | /* Set the parameter list */ | ||
| 148 | if (!pkey->save_parameters || (pkey->type == EVP_PKEY_RSA)) | ||
| 149 | { | ||
| 150 | if ((a->parameter == NULL) || | ||
| 151 | (a->parameter->type != V_ASN1_NULL)) | ||
| 152 | { | ||
| 153 | ASN1_TYPE_free(a->parameter); | ||
| 154 | a->parameter=ASN1_TYPE_new(); | ||
| 155 | a->parameter->type=V_ASN1_NULL; | ||
| 156 | } | ||
| 157 | } | ||
| 158 | else | ||
| 159 | #ifndef NO_DSA | ||
| 160 | if (pkey->type == EVP_PKEY_DSA) | ||
| 161 | { | ||
| 162 | unsigned char *pp; | ||
| 163 | DSA *dsa; | ||
| 164 | |||
| 165 | dsa=pkey->pkey.dsa; | ||
| 166 | dsa->write_params=0; | ||
| 167 | ASN1_TYPE_free(a->parameter); | ||
| 168 | i=i2d_DSAparams(dsa,NULL); | ||
| 169 | p=(unsigned char *)Malloc(i); | ||
| 170 | pp=p; | ||
| 171 | i2d_DSAparams(dsa,&pp); | ||
| 172 | a->parameter=ASN1_TYPE_new(); | ||
| 173 | a->parameter->type=V_ASN1_SEQUENCE; | ||
| 174 | a->parameter->value.sequence=ASN1_STRING_new(); | ||
| 175 | ASN1_STRING_set(a->parameter->value.sequence,p,i); | ||
| 176 | Free(p); | ||
| 177 | } | ||
| 178 | else | ||
| 179 | #endif | ||
| 180 | { | ||
| 181 | X509err(X509_F_X509_PUBKEY_SET,X509_R_UNSUPPORTED_ALGORITHM); | ||
| 182 | goto err; | ||
| 183 | } | ||
| 184 | |||
| 185 | i=i2d_PublicKey(pkey,NULL); | ||
| 186 | if ((s=(unsigned char *)Malloc(i+1)) == NULL) goto err; | ||
| 187 | p=s; | ||
| 188 | i2d_PublicKey(pkey,&p); | ||
| 189 | if (!ASN1_BIT_STRING_set(pk->public_key,s,i)) goto err; | ||
| 190 | Free(s); | ||
| 191 | |||
| 192 | CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY); | ||
| 193 | pk->pkey=pkey; | ||
| 194 | |||
| 195 | if (*x != NULL) | ||
| 196 | X509_PUBKEY_free(*x); | ||
| 197 | |||
| 198 | *x=pk; | ||
| 199 | pk=NULL; | ||
| 200 | |||
| 201 | ok=1; | ||
| 202 | err: | ||
| 203 | if (pk != NULL) X509_PUBKEY_free(pk); | ||
| 204 | return(ok); | ||
| 205 | } | ||
| 206 | |||
| 207 | EVP_PKEY *X509_PUBKEY_get(key) | ||
| 208 | X509_PUBKEY *key; | ||
| 209 | { | ||
| 210 | EVP_PKEY *ret=NULL; | ||
| 211 | long j; | ||
| 212 | int type; | ||
| 213 | unsigned char *p; | ||
| 214 | #ifndef NO_DSA | ||
| 215 | X509_ALGOR *a; | ||
| 216 | #endif | ||
| 217 | |||
| 218 | if (key == NULL) goto err; | ||
| 219 | |||
| 220 | if (key->pkey != NULL) return(key->pkey); | ||
| 221 | |||
| 222 | if (key->public_key == NULL) goto err; | ||
| 223 | |||
| 224 | type=OBJ_obj2nid(key->algor->algorithm); | ||
| 225 | p=key->public_key->data; | ||
| 226 | j=key->public_key->length; | ||
| 227 | if ((ret=d2i_PublicKey(type,NULL,&p,(long)j)) == NULL) | ||
| 228 | { | ||
| 229 | X509err(X509_F_X509_PUBKEY_GET,X509_R_ERR_ASN1_LIB); | ||
| 230 | goto err; | ||
| 231 | } | ||
| 232 | ret->save_parameters=0; | ||
| 233 | |||
| 234 | #ifndef NO_DSA | ||
| 235 | a=key->algor; | ||
| 236 | if (ret->type == EVP_PKEY_DSA) | ||
| 237 | { | ||
| 238 | if (a->parameter->type == V_ASN1_SEQUENCE) | ||
| 239 | { | ||
| 240 | ret->pkey.dsa->write_params=0; | ||
| 241 | p=a->parameter->value.sequence->data; | ||
| 242 | j=a->parameter->value.sequence->length; | ||
| 243 | if (!d2i_DSAparams(&ret->pkey.dsa,&p,(long)j)) | ||
| 244 | goto err; | ||
| 245 | } | ||
| 246 | ret->save_parameters=1; | ||
| 247 | } | ||
| 248 | #endif | ||
| 249 | key->pkey=ret; | ||
| 250 | return(ret); | ||
| 251 | err: | ||
| 252 | if (ret != NULL) | ||
| 253 | EVP_PKEY_free(ret); | ||
| 254 | return(NULL); | ||
| 255 | } | ||
| 256 | |||
diff --git a/src/lib/libcrypto/asn1/x_req.c b/src/lib/libcrypto/asn1/x_req.c new file mode 100644 index 0000000000..ff0be13d37 --- /dev/null +++ b/src/lib/libcrypto/asn1/x_req.c | |||
| @@ -0,0 +1,247 @@ | |||
| 1 | /* crypto/asn1/x_req.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_D2I_X509_REQ,ASN1_R_LENGTH_MISMATCH); | ||
| 66 | * ASN1err(ASN1_F_D2I_X509_REQ_INFO,ASN1_R_LENGTH_MISMATCH); | ||
| 67 | * ASN1err(ASN1_F_X509_REQ_NEW,ASN1_R_LENGTH_MISMATCH); | ||
| 68 | * ASN1err(ASN1_F_X509_REQ_INFO_NEW,ASN1_R_LENGTH_MISMATCH); | ||
| 69 | */ | ||
| 70 | |||
| 71 | int i2d_X509_REQ_INFO(a,pp) | ||
| 72 | X509_REQ_INFO *a; | ||
| 73 | unsigned char **pp; | ||
| 74 | { | ||
| 75 | M_ASN1_I2D_vars(a); | ||
| 76 | |||
| 77 | M_ASN1_I2D_len(a->version, i2d_ASN1_INTEGER); | ||
| 78 | M_ASN1_I2D_len(a->subject, i2d_X509_NAME); | ||
| 79 | M_ASN1_I2D_len(a->pubkey, i2d_X509_PUBKEY); | ||
| 80 | |||
| 81 | /* this is a *nasty* hack reported to be required to | ||
| 82 | * allow some CA Software to accept the cert request. | ||
| 83 | * It is not following the PKCS standards ... | ||
| 84 | * PKCS#10 pg 5 | ||
| 85 | * attributes [0] IMPLICIT Attibutes | ||
| 86 | * NOTE: no OPTIONAL ... so it *must* be there | ||
| 87 | */ | ||
| 88 | if (a->req_kludge) | ||
| 89 | { | ||
| 90 | M_ASN1_I2D_len_IMP_set_opt(a->attributes,i2d_X509_ATTRIBUTE,0); | ||
| 91 | } | ||
| 92 | else | ||
| 93 | { | ||
| 94 | M_ASN1_I2D_len_IMP_set(a->attributes, i2d_X509_ATTRIBUTE,0); | ||
| 95 | } | ||
| 96 | |||
| 97 | M_ASN1_I2D_seq_total(); | ||
| 98 | M_ASN1_I2D_put(a->version, i2d_ASN1_INTEGER); | ||
| 99 | M_ASN1_I2D_put(a->subject, i2d_X509_NAME); | ||
| 100 | M_ASN1_I2D_put(a->pubkey, i2d_X509_PUBKEY); | ||
| 101 | |||
| 102 | /* this is a *nasty* hack reported to be required by some CA's. | ||
| 103 | * It is not following the PKCS standards ... | ||
| 104 | * PKCS#10 pg 5 | ||
| 105 | * attributes [0] IMPLICIT Attibutes | ||
| 106 | * NOTE: no OPTIONAL ... so it *must* be there | ||
| 107 | */ | ||
| 108 | if (a->req_kludge) | ||
| 109 | { | ||
| 110 | M_ASN1_I2D_put_IMP_set_opt(a->attributes,i2d_X509_ATTRIBUTE,0); | ||
| 111 | } | ||
| 112 | else | ||
| 113 | { | ||
| 114 | M_ASN1_I2D_put_IMP_set(a->attributes,i2d_X509_ATTRIBUTE,0); | ||
| 115 | } | ||
| 116 | |||
| 117 | M_ASN1_I2D_finish(); | ||
| 118 | } | ||
| 119 | |||
| 120 | X509_REQ_INFO *d2i_X509_REQ_INFO(a,pp,length) | ||
| 121 | X509_REQ_INFO **a; | ||
| 122 | unsigned char **pp; | ||
| 123 | long length; | ||
| 124 | { | ||
| 125 | M_ASN1_D2I_vars(a,X509_REQ_INFO *,X509_REQ_INFO_new); | ||
| 126 | |||
| 127 | M_ASN1_D2I_Init(); | ||
| 128 | M_ASN1_D2I_start_sequence(); | ||
| 129 | M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); | ||
| 130 | M_ASN1_D2I_get(ret->subject,d2i_X509_NAME); | ||
| 131 | M_ASN1_D2I_get(ret->pubkey,d2i_X509_PUBKEY); | ||
| 132 | |||
| 133 | /* this is a *nasty* hack to allow for some CA's that | ||
| 134 | * have been reported as requiring it. | ||
| 135 | * It is not following the PKCS standards ... | ||
| 136 | * PKCS#10 pg 5 | ||
| 137 | * attributes [0] IMPLICIT Attibutes | ||
| 138 | * NOTE: no OPTIONAL ... so it *must* be there | ||
| 139 | */ | ||
| 140 | if (asn1_Finish(&c)) | ||
| 141 | ret->req_kludge=1; | ||
| 142 | else | ||
| 143 | { | ||
| 144 | M_ASN1_D2I_get_IMP_set(ret->attributes,d2i_X509_ATTRIBUTE,0); | ||
| 145 | } | ||
| 146 | |||
| 147 | M_ASN1_D2I_Finish(a,X509_REQ_INFO_free,ASN1_F_D2I_X509_REQ_INFO); | ||
| 148 | } | ||
| 149 | |||
| 150 | X509_REQ_INFO *X509_REQ_INFO_new() | ||
| 151 | { | ||
| 152 | X509_REQ_INFO *ret=NULL; | ||
| 153 | |||
| 154 | M_ASN1_New_Malloc(ret,X509_REQ_INFO); | ||
| 155 | M_ASN1_New(ret->version,ASN1_INTEGER_new); | ||
| 156 | M_ASN1_New(ret->subject,X509_NAME_new); | ||
| 157 | M_ASN1_New(ret->pubkey,X509_PUBKEY_new); | ||
| 158 | M_ASN1_New(ret->attributes,sk_new_null); | ||
| 159 | ret->req_kludge=0; | ||
| 160 | return(ret); | ||
| 161 | M_ASN1_New_Error(ASN1_F_X509_REQ_INFO_NEW); | ||
| 162 | } | ||
| 163 | |||
| 164 | void X509_REQ_INFO_free(a) | ||
| 165 | X509_REQ_INFO *a; | ||
| 166 | { | ||
| 167 | if (a == NULL) return; | ||
| 168 | ASN1_INTEGER_free(a->version); | ||
| 169 | X509_NAME_free(a->subject); | ||
| 170 | X509_PUBKEY_free(a->pubkey); | ||
| 171 | sk_pop_free(a->attributes,X509_ATTRIBUTE_free); | ||
| 172 | Free((char *)a); | ||
| 173 | } | ||
| 174 | |||
| 175 | int i2d_X509_REQ(a,pp) | ||
| 176 | X509_REQ *a; | ||
| 177 | unsigned char **pp; | ||
| 178 | { | ||
| 179 | M_ASN1_I2D_vars(a); | ||
| 180 | M_ASN1_I2D_len(a->req_info, i2d_X509_REQ_INFO); | ||
| 181 | M_ASN1_I2D_len(a->sig_alg, i2d_X509_ALGOR); | ||
| 182 | M_ASN1_I2D_len(a->signature, i2d_ASN1_BIT_STRING); | ||
| 183 | |||
| 184 | M_ASN1_I2D_seq_total(); | ||
| 185 | |||
| 186 | M_ASN1_I2D_put(a->req_info, i2d_X509_REQ_INFO); | ||
| 187 | M_ASN1_I2D_put(a->sig_alg, i2d_X509_ALGOR); | ||
| 188 | M_ASN1_I2D_put(a->signature, i2d_ASN1_BIT_STRING); | ||
| 189 | |||
| 190 | M_ASN1_I2D_finish(); | ||
| 191 | } | ||
| 192 | |||
| 193 | X509_REQ *d2i_X509_REQ(a,pp,length) | ||
| 194 | X509_REQ **a; | ||
| 195 | unsigned char **pp; | ||
| 196 | long length; | ||
| 197 | { | ||
| 198 | M_ASN1_D2I_vars(a,X509_REQ *,X509_REQ_new); | ||
| 199 | |||
| 200 | M_ASN1_D2I_Init(); | ||
| 201 | M_ASN1_D2I_start_sequence(); | ||
| 202 | M_ASN1_D2I_get(ret->req_info,d2i_X509_REQ_INFO); | ||
| 203 | M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR); | ||
| 204 | M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING); | ||
| 205 | M_ASN1_D2I_Finish(a,X509_REQ_free,ASN1_F_D2I_X509_REQ); | ||
| 206 | } | ||
| 207 | |||
| 208 | X509_REQ *X509_REQ_new() | ||
| 209 | { | ||
| 210 | X509_REQ *ret=NULL; | ||
| 211 | |||
| 212 | M_ASN1_New_Malloc(ret,X509_REQ); | ||
| 213 | ret->references=1; | ||
| 214 | M_ASN1_New(ret->req_info,X509_REQ_INFO_new); | ||
| 215 | M_ASN1_New(ret->sig_alg,X509_ALGOR_new); | ||
| 216 | M_ASN1_New(ret->signature,ASN1_BIT_STRING_new); | ||
| 217 | return(ret); | ||
| 218 | M_ASN1_New_Error(ASN1_F_X509_REQ_NEW); | ||
| 219 | } | ||
| 220 | |||
| 221 | void X509_REQ_free(a) | ||
| 222 | X509_REQ *a; | ||
| 223 | { | ||
| 224 | int i; | ||
| 225 | |||
| 226 | if (a == NULL) return; | ||
| 227 | |||
| 228 | i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_X509_REQ); | ||
| 229 | #ifdef REF_PRINT | ||
| 230 | REF_PRINT("X509_REQ",a); | ||
| 231 | #endif | ||
| 232 | if (i > 0) return; | ||
| 233 | #ifdef REF_CHECK | ||
| 234 | if (i < 0) | ||
| 235 | { | ||
| 236 | fprintf(stderr,"X509_REQ_free, bad reference count\n"); | ||
| 237 | abort(); | ||
| 238 | } | ||
| 239 | #endif | ||
| 240 | |||
| 241 | X509_REQ_INFO_free(a->req_info); | ||
| 242 | X509_ALGOR_free(a->sig_alg); | ||
| 243 | ASN1_BIT_STRING_free(a->signature); | ||
| 244 | Free((char *)a); | ||
| 245 | } | ||
| 246 | |||
| 247 | |||
diff --git a/src/lib/libcrypto/asn1/x_sig.c b/src/lib/libcrypto/asn1/x_sig.c new file mode 100644 index 0000000000..f0a2e4c27a --- /dev/null +++ b/src/lib/libcrypto/asn1/x_sig.c | |||
| @@ -0,0 +1,119 @@ | |||
| 1 | /* crypto/asn1/x_sig.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 | |||
| 63 | /* | ||
| 64 | * ASN1err(ASN1_F_D2I_X509_SIG,ASN1_R_LENGTH_MISMATCH); | ||
| 65 | * ASN1err(ASN1_F_X509_SIG_NEW,ASN1_R_LENGTH_MISMATCH); | ||
| 66 | */ | ||
| 67 | |||
| 68 | int i2d_X509_SIG(a,pp) | ||
| 69 | X509_SIG *a; | ||
| 70 | unsigned char **pp; | ||
| 71 | { | ||
| 72 | M_ASN1_I2D_vars(a); | ||
| 73 | |||
| 74 | M_ASN1_I2D_len(a->algor, i2d_X509_ALGOR); | ||
| 75 | M_ASN1_I2D_len(a->digest, i2d_ASN1_OCTET_STRING); | ||
| 76 | |||
| 77 | M_ASN1_I2D_seq_total(); | ||
| 78 | |||
| 79 | M_ASN1_I2D_put(a->algor, i2d_X509_ALGOR); | ||
| 80 | M_ASN1_I2D_put(a->digest, i2d_ASN1_OCTET_STRING); | ||
| 81 | |||
| 82 | M_ASN1_I2D_finish(); | ||
| 83 | } | ||
| 84 | |||
| 85 | X509_SIG *d2i_X509_SIG(a,pp,length) | ||
| 86 | X509_SIG **a; | ||
| 87 | unsigned char **pp; | ||
| 88 | long length; | ||
| 89 | { | ||
| 90 | M_ASN1_D2I_vars(a,X509_SIG *,X509_SIG_new); | ||
| 91 | |||
| 92 | M_ASN1_D2I_Init(); | ||
| 93 | M_ASN1_D2I_start_sequence(); | ||
| 94 | M_ASN1_D2I_get(ret->algor,d2i_X509_ALGOR); | ||
| 95 | M_ASN1_D2I_get(ret->digest,d2i_ASN1_OCTET_STRING); | ||
| 96 | M_ASN1_D2I_Finish(a,X509_SIG_free,ASN1_F_D2I_X509_SIG); | ||
| 97 | } | ||
| 98 | |||
| 99 | X509_SIG *X509_SIG_new() | ||
| 100 | { | ||
| 101 | X509_SIG *ret=NULL; | ||
| 102 | |||
| 103 | M_ASN1_New_Malloc(ret,X509_SIG); | ||
| 104 | M_ASN1_New(ret->algor,X509_ALGOR_new); | ||
| 105 | M_ASN1_New(ret->digest,ASN1_OCTET_STRING_new); | ||
| 106 | return(ret); | ||
| 107 | M_ASN1_New_Error(ASN1_F_X509_SIG_NEW); | ||
| 108 | } | ||
| 109 | |||
| 110 | void X509_SIG_free(a) | ||
| 111 | X509_SIG *a; | ||
| 112 | { | ||
| 113 | if (a == NULL) return; | ||
| 114 | X509_ALGOR_free(a->algor); | ||
| 115 | ASN1_OCTET_STRING_free(a->digest); | ||
| 116 | Free((char *)a); | ||
| 117 | } | ||
| 118 | |||
| 119 | |||
diff --git a/src/lib/libcrypto/asn1/x_spki.c b/src/lib/libcrypto/asn1/x_spki.c new file mode 100644 index 0000000000..4a80df44b8 --- /dev/null +++ b/src/lib/libcrypto/asn1/x_spki.c | |||
| @@ -0,0 +1,181 @@ | |||
| 1 | /* crypto/asn1/x_spki.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 | /* This module was send to me my Pat Richards <patr@x509.com> who | ||
| 60 | * wrote it. It is under my Copyright with his permision | ||
| 61 | */ | ||
| 62 | |||
| 63 | #include <stdio.h> | ||
| 64 | #include "cryptlib.h" | ||
| 65 | #include "x509.h" | ||
| 66 | #include "asn1_mac.h" | ||
| 67 | |||
| 68 | /* | ||
| 69 | * ASN1err(ASN1_F_D2I_NETSCAPE_SPKAC,ASN1_R_LENGTH_MISMATCH); | ||
| 70 | * ASN1err(ASN1_F_NETSCAPE_SPKAC_NEW,ASN1_R_LENGTH_MISMATCH); | ||
| 71 | * ASN1err(ASN1_F_D2I_NETSCAPE_SPKI,ASN1_R_LENGTH_MISMATCH); | ||
| 72 | * ASN1err(ASN1_F_NETSCAPE_SPKI_NEW,ASN1_R_LENGTH_MISMATCH); | ||
| 73 | */ | ||
| 74 | |||
| 75 | int i2d_NETSCAPE_SPKAC(a,pp) | ||
| 76 | NETSCAPE_SPKAC *a; | ||
| 77 | unsigned char **pp; | ||
| 78 | { | ||
| 79 | M_ASN1_I2D_vars(a); | ||
| 80 | |||
| 81 | M_ASN1_I2D_len(a->pubkey, i2d_X509_PUBKEY); | ||
| 82 | M_ASN1_I2D_len(a->challenge, i2d_ASN1_IA5STRING); | ||
| 83 | |||
| 84 | M_ASN1_I2D_seq_total(); | ||
| 85 | |||
| 86 | M_ASN1_I2D_put(a->pubkey, i2d_X509_PUBKEY); | ||
| 87 | M_ASN1_I2D_put(a->challenge, i2d_ASN1_IA5STRING); | ||
| 88 | |||
| 89 | M_ASN1_I2D_finish(); | ||
| 90 | } | ||
| 91 | |||
| 92 | NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC(a,pp,length) | ||
| 93 | NETSCAPE_SPKAC **a; | ||
| 94 | unsigned char **pp; | ||
| 95 | long length; | ||
| 96 | { | ||
| 97 | M_ASN1_D2I_vars(a,NETSCAPE_SPKAC *,NETSCAPE_SPKAC_new); | ||
| 98 | |||
| 99 | M_ASN1_D2I_Init(); | ||
| 100 | M_ASN1_D2I_start_sequence(); | ||
| 101 | M_ASN1_D2I_get(ret->pubkey,d2i_X509_PUBKEY); | ||
| 102 | M_ASN1_D2I_get(ret->challenge,d2i_ASN1_IA5STRING); | ||
| 103 | M_ASN1_D2I_Finish(a,NETSCAPE_SPKAC_free,ASN1_F_D2I_NETSCAPE_SPKAC); | ||
| 104 | } | ||
| 105 | |||
| 106 | NETSCAPE_SPKAC *NETSCAPE_SPKAC_new() | ||
| 107 | { | ||
| 108 | NETSCAPE_SPKAC *ret=NULL; | ||
| 109 | |||
| 110 | M_ASN1_New_Malloc(ret,NETSCAPE_SPKAC); | ||
| 111 | M_ASN1_New(ret->pubkey,X509_PUBKEY_new); | ||
| 112 | M_ASN1_New(ret->challenge,ASN1_IA5STRING_new); | ||
| 113 | return(ret); | ||
| 114 | M_ASN1_New_Error(ASN1_F_NETSCAPE_SPKAC_NEW); | ||
| 115 | } | ||
| 116 | |||
| 117 | void NETSCAPE_SPKAC_free(a) | ||
| 118 | NETSCAPE_SPKAC *a; | ||
| 119 | { | ||
| 120 | if (a == NULL) return; | ||
| 121 | X509_PUBKEY_free(a->pubkey); | ||
| 122 | ASN1_IA5STRING_free(a->challenge); | ||
| 123 | Free((char *)a); | ||
| 124 | } | ||
| 125 | |||
| 126 | int i2d_NETSCAPE_SPKI(a,pp) | ||
| 127 | NETSCAPE_SPKI *a; | ||
| 128 | unsigned char **pp; | ||
| 129 | { | ||
| 130 | M_ASN1_I2D_vars(a); | ||
| 131 | |||
| 132 | M_ASN1_I2D_len(a->spkac, i2d_NETSCAPE_SPKAC); | ||
| 133 | M_ASN1_I2D_len(a->sig_algor, i2d_X509_ALGOR); | ||
| 134 | M_ASN1_I2D_len(a->signature, i2d_ASN1_BIT_STRING); | ||
| 135 | |||
| 136 | M_ASN1_I2D_seq_total(); | ||
| 137 | |||
| 138 | M_ASN1_I2D_put(a->spkac, i2d_NETSCAPE_SPKAC); | ||
| 139 | M_ASN1_I2D_put(a->sig_algor, i2d_X509_ALGOR); | ||
| 140 | M_ASN1_I2D_put(a->signature, i2d_ASN1_BIT_STRING); | ||
| 141 | |||
| 142 | M_ASN1_I2D_finish(); | ||
| 143 | } | ||
| 144 | |||
| 145 | NETSCAPE_SPKI *d2i_NETSCAPE_SPKI(a,pp,length) | ||
| 146 | NETSCAPE_SPKI **a; | ||
| 147 | unsigned char **pp; | ||
| 148 | long length; | ||
| 149 | { | ||
| 150 | M_ASN1_D2I_vars(a,NETSCAPE_SPKI *,NETSCAPE_SPKI_new); | ||
| 151 | |||
| 152 | M_ASN1_D2I_Init(); | ||
| 153 | M_ASN1_D2I_start_sequence(); | ||
| 154 | M_ASN1_D2I_get(ret->spkac,d2i_NETSCAPE_SPKAC); | ||
| 155 | M_ASN1_D2I_get(ret->sig_algor,d2i_X509_ALGOR); | ||
| 156 | M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING); | ||
| 157 | M_ASN1_D2I_Finish(a,NETSCAPE_SPKI_free,ASN1_F_D2I_NETSCAPE_SPKI); | ||
| 158 | } | ||
| 159 | |||
| 160 | NETSCAPE_SPKI *NETSCAPE_SPKI_new() | ||
| 161 | { | ||
| 162 | NETSCAPE_SPKI *ret=NULL; | ||
| 163 | |||
| 164 | M_ASN1_New_Malloc(ret,NETSCAPE_SPKI); | ||
| 165 | M_ASN1_New(ret->spkac,NETSCAPE_SPKAC_new); | ||
| 166 | M_ASN1_New(ret->sig_algor,X509_ALGOR_new); | ||
| 167 | M_ASN1_New(ret->signature,ASN1_BIT_STRING_new); | ||
| 168 | return(ret); | ||
| 169 | M_ASN1_New_Error(ASN1_F_NETSCAPE_SPKI_NEW); | ||
| 170 | } | ||
| 171 | |||
| 172 | void NETSCAPE_SPKI_free(a) | ||
| 173 | NETSCAPE_SPKI *a; | ||
| 174 | { | ||
| 175 | if (a == NULL) return; | ||
| 176 | NETSCAPE_SPKAC_free(a->spkac); | ||
| 177 | X509_ALGOR_free(a->sig_algor); | ||
| 178 | ASN1_BIT_STRING_free(a->signature); | ||
| 179 | Free((char *)a); | ||
| 180 | } | ||
| 181 | |||
diff --git a/src/lib/libcrypto/asn1/x_val.c b/src/lib/libcrypto/asn1/x_val.c new file mode 100644 index 0000000000..a9c390f88c --- /dev/null +++ b/src/lib/libcrypto/asn1/x_val.c | |||
| @@ -0,0 +1,118 @@ | |||
| 1 | /* crypto/asn1/x_val.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 | |||
| 63 | /* ASN1err(ASN1_F_X509_VAL_NEW,ERR_R_MALLOC_FAILURE); | ||
| 64 | * ASN1err(ASN1_F_X509_VAL_FREE,ERR_R_MALLOC_FAILURE); | ||
| 65 | * ASN1err(ASN1_F_D2I_X509_VAL,ERR_R_MALLOC_FAILURE); | ||
| 66 | */ | ||
| 67 | |||
| 68 | int i2d_X509_VAL(a,pp) | ||
| 69 | X509_VAL *a; | ||
| 70 | unsigned char **pp; | ||
| 71 | { | ||
| 72 | M_ASN1_I2D_vars(a); | ||
| 73 | |||
| 74 | M_ASN1_I2D_len(a->notBefore,i2d_ASN1_UTCTIME); | ||
| 75 | M_ASN1_I2D_len(a->notAfter,i2d_ASN1_UTCTIME); | ||
| 76 | |||
| 77 | M_ASN1_I2D_seq_total(); | ||
| 78 | |||
| 79 | M_ASN1_I2D_put(a->notBefore,i2d_ASN1_UTCTIME); | ||
| 80 | M_ASN1_I2D_put(a->notAfter,i2d_ASN1_UTCTIME); | ||
| 81 | |||
| 82 | M_ASN1_I2D_finish(); | ||
| 83 | } | ||
| 84 | |||
| 85 | X509_VAL *d2i_X509_VAL(a,pp,length) | ||
| 86 | X509_VAL **a; | ||
| 87 | unsigned char **pp; | ||
| 88 | long length; | ||
| 89 | { | ||
| 90 | M_ASN1_D2I_vars(a,X509_VAL *,X509_VAL_new); | ||
| 91 | |||
| 92 | M_ASN1_D2I_Init(); | ||
| 93 | M_ASN1_D2I_start_sequence(); | ||
| 94 | M_ASN1_D2I_get(ret->notBefore,d2i_ASN1_UTCTIME); | ||
| 95 | M_ASN1_D2I_get(ret->notAfter,d2i_ASN1_UTCTIME); | ||
| 96 | M_ASN1_D2I_Finish(a,X509_VAL_free,ASN1_F_D2I_X509_VAL); | ||
| 97 | } | ||
| 98 | |||
| 99 | X509_VAL *X509_VAL_new() | ||
| 100 | { | ||
| 101 | X509_VAL *ret=NULL; | ||
| 102 | |||
| 103 | M_ASN1_New_Malloc(ret,X509_VAL); | ||
| 104 | M_ASN1_New(ret->notBefore,ASN1_UTCTIME_new); | ||
| 105 | M_ASN1_New(ret->notAfter,ASN1_UTCTIME_new); | ||
| 106 | return(ret); | ||
| 107 | M_ASN1_New_Error(ASN1_F_X509_VAL_NEW); | ||
| 108 | } | ||
| 109 | |||
| 110 | void X509_VAL_free(a) | ||
| 111 | X509_VAL *a; | ||
| 112 | { | ||
| 113 | if (a == NULL) return; | ||
| 114 | ASN1_UTCTIME_free(a->notBefore); | ||
| 115 | ASN1_UTCTIME_free(a->notAfter); | ||
| 116 | Free((char *)a); | ||
| 117 | } | ||
| 118 | |||
diff --git a/src/lib/libcrypto/asn1/x_x509.c b/src/lib/libcrypto/asn1/x_x509.c new file mode 100644 index 0000000000..bc466ce0f6 --- /dev/null +++ b/src/lib/libcrypto/asn1/x_x509.c | |||
| @@ -0,0 +1,158 @@ | |||
| 1 | /* crypto/asn1/x_x509.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 "evp.h" | ||
| 62 | #include "asn1_mac.h" | ||
| 63 | |||
| 64 | /* | ||
| 65 | * ASN1err(ASN1_F_D2I_X509,ASN1_R_LENGTH_MISMATCH); | ||
| 66 | * ASN1err(ASN1_F_X509_NEW,ASN1_R_BAD_GET_OBJECT); | ||
| 67 | */ | ||
| 68 | |||
| 69 | static ASN1_METHOD meth={ | ||
| 70 | (int (*)()) i2d_X509, | ||
| 71 | (char *(*)())d2i_X509, | ||
| 72 | (char *(*)())X509_new, | ||
| 73 | (void (*)()) X509_free}; | ||
| 74 | |||
| 75 | ASN1_METHOD *X509_asn1_meth() | ||
| 76 | { | ||
| 77 | return(&meth); | ||
| 78 | } | ||
| 79 | |||
| 80 | int i2d_X509(a,pp) | ||
| 81 | X509 *a; | ||
| 82 | unsigned char **pp; | ||
| 83 | { | ||
| 84 | M_ASN1_I2D_vars(a); | ||
| 85 | |||
| 86 | M_ASN1_I2D_len(a->cert_info, i2d_X509_CINF); | ||
| 87 | M_ASN1_I2D_len(a->sig_alg, i2d_X509_ALGOR); | ||
| 88 | M_ASN1_I2D_len(a->signature, i2d_ASN1_BIT_STRING); | ||
| 89 | |||
| 90 | M_ASN1_I2D_seq_total(); | ||
| 91 | |||
| 92 | M_ASN1_I2D_put(a->cert_info, i2d_X509_CINF); | ||
| 93 | M_ASN1_I2D_put(a->sig_alg, i2d_X509_ALGOR); | ||
| 94 | M_ASN1_I2D_put(a->signature, i2d_ASN1_BIT_STRING); | ||
| 95 | |||
| 96 | M_ASN1_I2D_finish(); | ||
| 97 | } | ||
| 98 | |||
| 99 | X509 *d2i_X509(a,pp,length) | ||
| 100 | X509 **a; | ||
| 101 | unsigned char **pp; | ||
| 102 | long length; | ||
| 103 | { | ||
| 104 | M_ASN1_D2I_vars(a,X509 *,X509_new); | ||
| 105 | |||
| 106 | M_ASN1_D2I_Init(); | ||
| 107 | M_ASN1_D2I_start_sequence(); | ||
| 108 | M_ASN1_D2I_get(ret->cert_info,d2i_X509_CINF); | ||
| 109 | M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR); | ||
| 110 | M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING); | ||
| 111 | if (ret->name != NULL) Free(ret->name); | ||
| 112 | ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0); | ||
| 113 | |||
| 114 | M_ASN1_D2I_Finish(a,X509_free,ASN1_F_D2I_X509); | ||
| 115 | } | ||
| 116 | |||
| 117 | X509 *X509_new() | ||
| 118 | { | ||
| 119 | X509 *ret=NULL; | ||
| 120 | |||
| 121 | M_ASN1_New_Malloc(ret,X509); | ||
| 122 | ret->references=1; | ||
| 123 | ret->valid=0; | ||
| 124 | ret->name=NULL; | ||
| 125 | M_ASN1_New(ret->cert_info,X509_CINF_new); | ||
| 126 | M_ASN1_New(ret->sig_alg,X509_ALGOR_new); | ||
| 127 | M_ASN1_New(ret->signature,ASN1_BIT_STRING_new); | ||
| 128 | return(ret); | ||
| 129 | M_ASN1_New_Error(ASN1_F_X509_NEW); | ||
| 130 | } | ||
| 131 | |||
| 132 | void X509_free(a) | ||
| 133 | X509 *a; | ||
| 134 | { | ||
| 135 | int i; | ||
| 136 | |||
| 137 | if (a == NULL) return; | ||
| 138 | |||
| 139 | i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_X509); | ||
| 140 | #ifdef REF_PRINT | ||
| 141 | REF_PRINT("X509",a); | ||
| 142 | #endif | ||
| 143 | if (i > 0) return; | ||
| 144 | #ifdef REF_CHECK | ||
| 145 | if (i < 0) | ||
| 146 | { | ||
| 147 | fprintf(stderr,"X509_free, bad reference count\n"); | ||
| 148 | abort(); | ||
| 149 | } | ||
| 150 | #endif | ||
| 151 | |||
| 152 | X509_CINF_free(a->cert_info); | ||
| 153 | X509_ALGOR_free(a->sig_alg); | ||
| 154 | ASN1_BIT_STRING_free(a->signature); | ||
| 155 | if (a->name != NULL) Free(a->name); | ||
| 156 | Free((char *)a); | ||
| 157 | } | ||
| 158 | |||
diff --git a/src/lib/libcrypto/bf/COPYRIGHT b/src/lib/libcrypto/bf/COPYRIGHT new file mode 100644 index 0000000000..6857223506 --- /dev/null +++ b/src/lib/libcrypto/bf/COPYRIGHT | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) | ||
| 2 | All rights reserved. | ||
| 3 | |||
| 4 | This package is an Blowfish implementation written | ||
| 5 | by Eric Young (eay@cryptsoft.com). | ||
| 6 | |||
| 7 | This library is free for commercial and non-commercial use as long as | ||
| 8 | the following conditions are aheared to. The following conditions | ||
| 9 | apply to all code found in this distribution. | ||
| 10 | |||
| 11 | Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 12 | the code are not to be removed. | ||
| 13 | |||
| 14 | Redistribution and use in source and binary forms, with or without | ||
| 15 | modification, are permitted provided that the following conditions | ||
| 16 | are met: | ||
| 17 | 1. Redistributions of source code must retain the copyright | ||
| 18 | notice, this list of conditions and the following disclaimer. | ||
| 19 | 2. Redistributions in binary form must reproduce the above copyright | ||
| 20 | notice, this list of conditions and the following disclaimer in the | ||
| 21 | documentation and/or other materials provided with the distribution. | ||
| 22 | 3. All advertising materials mentioning features or use of this software | ||
| 23 | must display the following acknowledgement: | ||
| 24 | This product includes software developed by Eric Young (eay@cryptsoft.com) | ||
| 25 | |||
| 26 | THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 27 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 28 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 29 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 30 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 31 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 32 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 33 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 34 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 35 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 36 | SUCH DAMAGE. | ||
| 37 | |||
| 38 | The license and distribution terms for any publically available version or | ||
| 39 | derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 40 | copied and put under another distrubution license | ||
| 41 | [including the GNU Public License.] | ||
| 42 | |||
| 43 | The reason behind this being stated in this direct manner is past | ||
| 44 | experience in code simply being copied and the attribution removed | ||
| 45 | from it and then being distributed as part of other packages. This | ||
| 46 | implementation was a non-trivial and unpaid effort. | ||
diff --git a/src/lib/libcrypto/bf/INSTALL b/src/lib/libcrypto/bf/INSTALL new file mode 100644 index 0000000000..3b25923532 --- /dev/null +++ b/src/lib/libcrypto/bf/INSTALL | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | This Eric Young's blowfish implementation, taken from his SSLeay library | ||
| 2 | and made available as a separate library. | ||
| 3 | |||
| 4 | The version number (0.7.2m) is the SSLeay version that this library was | ||
| 5 | taken from. | ||
| 6 | |||
| 7 | To build, just unpack and type make. | ||
| 8 | If you are not using gcc, edit the Makefile. | ||
| 9 | If you are compiling for an x86 box, try the assembler (it needs improving). | ||
| 10 | There are also some compile time options that can improve performance, | ||
| 11 | these are documented in the Makefile. | ||
| 12 | |||
| 13 | eric 15-Apr-1997 | ||
| 14 | |||
diff --git a/src/lib/libcrypto/bf/README b/src/lib/libcrypto/bf/README new file mode 100644 index 0000000000..f2712fd0e7 --- /dev/null +++ b/src/lib/libcrypto/bf/README | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | This is a quick packaging up of my blowfish code into a library. | ||
| 2 | It has been lifted from SSLeay. | ||
| 3 | The copyright notices seem a little harsh because I have not spent the | ||
| 4 | time to rewrite the conditions from the normal SSLeay ones. | ||
| 5 | |||
| 6 | Basically if you just want to play with the library, not a problem. | ||
| 7 | |||
| 8 | eric 15-Apr-1997 | ||
diff --git a/src/lib/libcrypto/bf/VERSION b/src/lib/libcrypto/bf/VERSION new file mode 100644 index 0000000000..be995855e4 --- /dev/null +++ b/src/lib/libcrypto/bf/VERSION | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | The version numbers will follow my SSL implementation | ||
| 2 | |||
| 3 | 0.7.2r - Some reasonable default compiler options from | ||
| 4 | Peter Gutman <pgut001@cs.auckland.ac.nz> | ||
| 5 | |||
| 6 | 0.7.2m - the first release | ||
diff --git a/src/lib/libcrypto/bf/asm/bf-586.pl b/src/lib/libcrypto/bf/asm/bf-586.pl new file mode 100644 index 0000000000..5c7ab14ab0 --- /dev/null +++ b/src/lib/libcrypto/bf/asm/bf-586.pl | |||
| @@ -0,0 +1,136 @@ | |||
| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | push(@INC,"perlasm","../../perlasm"); | ||
| 4 | require "x86asm.pl"; | ||
| 5 | require "cbc.pl"; | ||
| 6 | |||
| 7 | &asm_init($ARGV[0],"bf-586.pl"); | ||
| 8 | |||
| 9 | $BF_ROUNDS=16; | ||
| 10 | $BF_OFF=($BF_ROUNDS+2)*4; | ||
| 11 | $L="edi"; | ||
| 12 | $R="esi"; | ||
| 13 | $P="ebp"; | ||
| 14 | $tmp1="eax"; | ||
| 15 | $tmp2="ebx"; | ||
| 16 | $tmp3="ecx"; | ||
| 17 | $tmp4="edx"; | ||
| 18 | |||
| 19 | &BF_encrypt("BF_encrypt",1); | ||
| 20 | &BF_encrypt("BF_decrypt",0); | ||
| 21 | &cbc("BF_cbc_encrypt","BF_encrypt","BF_decrypt",1,4,5,3,-1,-1); | ||
| 22 | &asm_finish(); | ||
| 23 | |||
| 24 | sub BF_encrypt | ||
| 25 | { | ||
| 26 | local($name,$enc)=@_; | ||
| 27 | |||
| 28 | &function_begin_B($name,""); | ||
| 29 | |||
| 30 | &comment(""); | ||
| 31 | |||
| 32 | &push("ebp"); | ||
| 33 | &push("ebx"); | ||
| 34 | &mov($tmp2,&wparam(0)); | ||
| 35 | &mov($P,&wparam(1)); | ||
| 36 | &push("esi"); | ||
| 37 | &push("edi"); | ||
| 38 | |||
| 39 | &comment("Load the 2 words"); | ||
| 40 | &mov($L,&DWP(0,$tmp2,"",0)); | ||
| 41 | &mov($R,&DWP(4,$tmp2,"",0)); | ||
| 42 | |||
| 43 | &xor( $tmp1, $tmp1); | ||
| 44 | |||
| 45 | # encrypting part | ||
| 46 | |||
| 47 | if ($enc) | ||
| 48 | { | ||
| 49 | &mov($tmp2,&DWP(0,$P,"",0)); | ||
| 50 | &xor( $tmp3, $tmp3); | ||
| 51 | |||
| 52 | &xor($L,$tmp2); | ||
| 53 | for ($i=0; $i<$BF_ROUNDS; $i+=2) | ||
| 54 | { | ||
| 55 | &comment(""); | ||
| 56 | &comment("Round $i"); | ||
| 57 | &BF_ENCRYPT($i+1,$R,$L,$P,$tmp1,$tmp2,$tmp3,$tmp4,1); | ||
| 58 | |||
| 59 | &comment(""); | ||
| 60 | &comment("Round ".sprintf("%d",$i+1)); | ||
| 61 | &BF_ENCRYPT($i+2,$L,$R,$P,$tmp1,$tmp2,$tmp3,$tmp4,1); | ||
| 62 | } | ||
| 63 | # &mov($tmp1,&wparam(0)); In last loop | ||
| 64 | &mov($tmp4,&DWP(($BF_ROUNDS+1)*4,$P,"",0)); | ||
| 65 | } | ||
| 66 | else | ||
| 67 | { | ||
| 68 | &mov($tmp2,&DWP(($BF_ROUNDS+1)*4,$P,"",0)); | ||
| 69 | &xor( $tmp3, $tmp3); | ||
| 70 | |||
| 71 | &xor($L,$tmp2); | ||
| 72 | for ($i=$BF_ROUNDS; $i>0; $i-=2) | ||
| 73 | { | ||
| 74 | &comment(""); | ||
| 75 | &comment("Round $i"); | ||
| 76 | &BF_ENCRYPT($i,$R,$L,$P,$tmp1,$tmp2,$tmp3,$tmp4,0); | ||
| 77 | &comment(""); | ||
| 78 | &comment("Round ".sprintf("%d",$i-1)); | ||
| 79 | &BF_ENCRYPT($i-1,$L,$R,$P,$tmp1,$tmp2,$tmp3,$tmp4,0); | ||
| 80 | } | ||
| 81 | # &mov($tmp1,&wparam(0)); In last loop | ||
| 82 | &mov($tmp4,&DWP(0,$P,"",0)); | ||
| 83 | } | ||
| 84 | |||
| 85 | &xor($R,$tmp4); | ||
| 86 | &mov(&DWP(4,$tmp1,"",0),$L); | ||
| 87 | |||
| 88 | &mov(&DWP(0,$tmp1,"",0),$R); | ||
| 89 | &function_end($name); | ||
| 90 | } | ||
| 91 | |||
| 92 | sub BF_ENCRYPT | ||
| 93 | { | ||
| 94 | local($i,$L,$R,$P,$tmp1,$tmp2,$tmp3,$tmp4,$enc)=@_; | ||
| 95 | |||
| 96 | &mov( $tmp4, &DWP(&n2a($i*4),$P,"",0)); # for next round | ||
| 97 | |||
| 98 | &mov( $tmp2, $R); | ||
| 99 | &xor( $L, $tmp4); | ||
| 100 | |||
| 101 | &shr( $tmp2, 16); | ||
| 102 | &mov( $tmp4, $R); | ||
| 103 | |||
| 104 | &movb( &LB($tmp1), &HB($tmp2)); # A | ||
| 105 | &and( $tmp2, 0xff); # B | ||
| 106 | |||
| 107 | &movb( &LB($tmp3), &HB($tmp4)); # C | ||
| 108 | &and( $tmp4, 0xff); # D | ||
| 109 | |||
| 110 | &mov( $tmp1, &DWP(&n2a($BF_OFF+0x0000),$P,$tmp1,4)); | ||
| 111 | &mov( $tmp2, &DWP(&n2a($BF_OFF+0x0400),$P,$tmp2,4)); | ||
| 112 | |||
| 113 | &add( $tmp2, $tmp1); | ||
| 114 | &mov( $tmp1, &DWP(&n2a($BF_OFF+0x0800),$P,$tmp3,4)); | ||
| 115 | |||
| 116 | &xor( $tmp2, $tmp1); | ||
| 117 | &mov( $tmp4, &DWP(&n2a($BF_OFF+0x0C00),$P,$tmp4,4)); | ||
| 118 | |||
| 119 | &add( $tmp2, $tmp4); | ||
| 120 | if (($enc && ($i != 16)) || ((!$enc) && ($i != 1))) | ||
| 121 | { &xor( $tmp1, $tmp1); } | ||
| 122 | else | ||
| 123 | { | ||
| 124 | &comment("Load parameter 0 ($i) enc=$enc"); | ||
| 125 | &mov($tmp1,&wparam(0)); | ||
| 126 | } # In last loop | ||
| 127 | |||
| 128 | &xor( $L, $tmp2); | ||
| 129 | # delay | ||
| 130 | } | ||
| 131 | |||
| 132 | sub n2a | ||
| 133 | { | ||
| 134 | sprintf("%d",$_[0]); | ||
| 135 | } | ||
| 136 | |||
diff --git a/src/lib/libcrypto/bf/bf_cbc.c b/src/lib/libcrypto/bf/bf_cbc.c new file mode 100644 index 0000000000..e0fa9ad763 --- /dev/null +++ b/src/lib/libcrypto/bf/bf_cbc.c | |||
| @@ -0,0 +1,148 @@ | |||
| 1 | /* crypto/bf/bf_cbc.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 "blowfish.h" | ||
| 60 | #include "bf_locl.h" | ||
| 61 | |||
| 62 | void BF_cbc_encrypt(in, out, length, ks, iv, encrypt) | ||
| 63 | unsigned char *in; | ||
| 64 | unsigned char *out; | ||
| 65 | long length; | ||
| 66 | BF_KEY *ks; | ||
| 67 | unsigned char *iv; | ||
| 68 | int encrypt; | ||
| 69 | { | ||
| 70 | register BF_LONG tin0,tin1; | ||
| 71 | register BF_LONG tout0,tout1,xor0,xor1; | ||
| 72 | register long l=length; | ||
| 73 | BF_LONG tin[2]; | ||
| 74 | |||
| 75 | if (encrypt) | ||
| 76 | { | ||
| 77 | n2l(iv,tout0); | ||
| 78 | n2l(iv,tout1); | ||
| 79 | iv-=8; | ||
| 80 | for (l-=8; l>=0; l-=8) | ||
| 81 | { | ||
| 82 | n2l(in,tin0); | ||
| 83 | n2l(in,tin1); | ||
| 84 | tin0^=tout0; | ||
| 85 | tin1^=tout1; | ||
| 86 | tin[0]=tin0; | ||
| 87 | tin[1]=tin1; | ||
| 88 | BF_encrypt(tin,ks); | ||
| 89 | tout0=tin[0]; | ||
| 90 | tout1=tin[1]; | ||
| 91 | l2n(tout0,out); | ||
| 92 | l2n(tout1,out); | ||
| 93 | } | ||
| 94 | if (l != -8) | ||
| 95 | { | ||
| 96 | n2ln(in,tin0,tin1,l+8); | ||
| 97 | tin0^=tout0; | ||
| 98 | tin1^=tout1; | ||
| 99 | tin[0]=tin0; | ||
| 100 | tin[1]=tin1; | ||
| 101 | BF_encrypt(tin,ks); | ||
| 102 | tout0=tin[0]; | ||
| 103 | tout1=tin[1]; | ||
| 104 | l2n(tout0,out); | ||
| 105 | l2n(tout1,out); | ||
| 106 | } | ||
| 107 | l2n(tout0,iv); | ||
| 108 | l2n(tout1,iv); | ||
| 109 | } | ||
| 110 | else | ||
| 111 | { | ||
| 112 | n2l(iv,xor0); | ||
| 113 | n2l(iv,xor1); | ||
| 114 | iv-=8; | ||
| 115 | for (l-=8; l>=0; l-=8) | ||
| 116 | { | ||
| 117 | n2l(in,tin0); | ||
| 118 | n2l(in,tin1); | ||
| 119 | tin[0]=tin0; | ||
| 120 | tin[1]=tin1; | ||
| 121 | BF_decrypt(tin,ks); | ||
| 122 | tout0=tin[0]^xor0; | ||
| 123 | tout1=tin[1]^xor1; | ||
| 124 | l2n(tout0,out); | ||
| 125 | l2n(tout1,out); | ||
| 126 | xor0=tin0; | ||
| 127 | xor1=tin1; | ||
| 128 | } | ||
| 129 | if (l != -8) | ||
| 130 | { | ||
| 131 | n2l(in,tin0); | ||
| 132 | n2l(in,tin1); | ||
| 133 | tin[0]=tin0; | ||
| 134 | tin[1]=tin1; | ||
| 135 | BF_decrypt(tin,ks); | ||
| 136 | tout0=tin[0]^xor0; | ||
| 137 | tout1=tin[1]^xor1; | ||
| 138 | l2nn(tout0,tout1,out,l+8); | ||
| 139 | xor0=tin0; | ||
| 140 | xor1=tin1; | ||
| 141 | } | ||
| 142 | l2n(xor0,iv); | ||
| 143 | l2n(xor1,iv); | ||
| 144 | } | ||
| 145 | tin0=tin1=tout0=tout1=xor0=xor1=0; | ||
| 146 | tin[0]=tin[1]=0; | ||
| 147 | } | ||
| 148 | |||
diff --git a/src/lib/libcrypto/bf/bf_cfb64.c b/src/lib/libcrypto/bf/bf_cfb64.c new file mode 100644 index 0000000000..f9c66e7ced --- /dev/null +++ b/src/lib/libcrypto/bf/bf_cfb64.c | |||
| @@ -0,0 +1,127 @@ | |||
| 1 | /* crypto/bf/bf_cfb64.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 "blowfish.h" | ||
| 60 | #include "bf_locl.h" | ||
| 61 | |||
| 62 | /* The input and output encrypted as though 64bit cfb mode is being | ||
| 63 | * used. The extra state information to record how much of the | ||
| 64 | * 64bit block we have used is contained in *num; | ||
| 65 | */ | ||
| 66 | |||
| 67 | void BF_cfb64_encrypt(in, out, length, schedule, ivec, num, encrypt) | ||
| 68 | unsigned char *in; | ||
| 69 | unsigned char *out; | ||
| 70 | long length; | ||
| 71 | BF_KEY *schedule; | ||
| 72 | unsigned char *ivec; | ||
| 73 | int *num; | ||
| 74 | int encrypt; | ||
| 75 | { | ||
| 76 | register BF_LONG v0,v1,t; | ||
| 77 | register int n= *num; | ||
| 78 | register long l=length; | ||
| 79 | BF_LONG ti[2]; | ||
| 80 | unsigned char *iv,c,cc; | ||
| 81 | |||
| 82 | iv=(unsigned char *)ivec; | ||
| 83 | if (encrypt) | ||
| 84 | { | ||
| 85 | while (l--) | ||
| 86 | { | ||
| 87 | if (n == 0) | ||
| 88 | { | ||
| 89 | n2l(iv,v0); ti[0]=v0; | ||
| 90 | n2l(iv,v1); ti[1]=v1; | ||
| 91 | BF_encrypt((BF_LONG *)ti,schedule); | ||
| 92 | iv=(unsigned char *)ivec; | ||
| 93 | t=ti[0]; l2n(t,iv); | ||
| 94 | t=ti[1]; l2n(t,iv); | ||
| 95 | iv=(unsigned char *)ivec; | ||
| 96 | } | ||
| 97 | c= *(in++)^iv[n]; | ||
| 98 | *(out++)=c; | ||
| 99 | iv[n]=c; | ||
| 100 | n=(n+1)&0x07; | ||
| 101 | } | ||
| 102 | } | ||
| 103 | else | ||
| 104 | { | ||
| 105 | while (l--) | ||
| 106 | { | ||
| 107 | if (n == 0) | ||
| 108 | { | ||
| 109 | n2l(iv,v0); ti[0]=v0; | ||
| 110 | n2l(iv,v1); ti[1]=v1; | ||
| 111 | BF_encrypt((BF_LONG *)ti,schedule); | ||
| 112 | iv=(unsigned char *)ivec; | ||
| 113 | t=ti[0]; l2n(t,iv); | ||
| 114 | t=ti[1]; l2n(t,iv); | ||
| 115 | iv=(unsigned char *)ivec; | ||
| 116 | } | ||
| 117 | cc= *(in++); | ||
| 118 | c=iv[n]; | ||
| 119 | iv[n]=cc; | ||
| 120 | *(out++)=c^cc; | ||
| 121 | n=(n+1)&0x07; | ||
| 122 | } | ||
| 123 | } | ||
| 124 | v0=v1=ti[0]=ti[1]=t=c=cc=0; | ||
| 125 | *num=n; | ||
| 126 | } | ||
| 127 | |||
diff --git a/src/lib/libcrypto/bf/bf_ecb.c b/src/lib/libcrypto/bf/bf_ecb.c new file mode 100644 index 0000000000..6d16360bd9 --- /dev/null +++ b/src/lib/libcrypto/bf/bf_ecb.c | |||
| @@ -0,0 +1,98 @@ | |||
| 1 | /* crypto/bf/bf_ecb.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 "blowfish.h" | ||
| 60 | #include "bf_locl.h" | ||
| 61 | |||
| 62 | /* Blowfish as implemented from 'Blowfish: Springer-Verlag paper' | ||
| 63 | * (From LECTURE NOTES IN COIMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION, | ||
| 64 | * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993) | ||
| 65 | */ | ||
| 66 | |||
| 67 | char *BF_version="BlowFish part of SSLeay 0.9.0b 29-Jun-1998"; | ||
| 68 | |||
| 69 | char *BF_options() | ||
| 70 | { | ||
| 71 | #ifdef BF_PTR | ||
| 72 | return("blowfish(ptr)"); | ||
| 73 | #elif defined(BF_PTR2) | ||
| 74 | return("blowfish(ptr2)"); | ||
| 75 | #else | ||
| 76 | return("blowfish(idx)"); | ||
| 77 | #endif | ||
| 78 | } | ||
| 79 | |||
| 80 | void BF_ecb_encrypt(in, out, ks, encrypt) | ||
| 81 | unsigned char *in; | ||
| 82 | unsigned char *out; | ||
| 83 | BF_KEY *ks; | ||
| 84 | int encrypt; | ||
| 85 | { | ||
| 86 | BF_LONG l,d[2]; | ||
| 87 | |||
| 88 | n2l(in,l); d[0]=l; | ||
| 89 | n2l(in,l); d[1]=l; | ||
| 90 | if (encrypt) | ||
| 91 | BF_encrypt(d,ks); | ||
| 92 | else | ||
| 93 | BF_decrypt(d,ks); | ||
| 94 | l=d[0]; l2n(l,out); | ||
| 95 | l=d[1]; l2n(l,out); | ||
| 96 | l=d[0]=d[1]=0; | ||
| 97 | } | ||
| 98 | |||
diff --git a/src/lib/libcrypto/bf/bf_enc.c b/src/lib/libcrypto/bf/bf_enc.c new file mode 100644 index 0000000000..66a8604c59 --- /dev/null +++ b/src/lib/libcrypto/bf/bf_enc.c | |||
| @@ -0,0 +1,241 @@ | |||
| 1 | /* crypto/bf/bf_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 "blowfish.h" | ||
| 60 | #include "bf_locl.h" | ||
| 61 | |||
| 62 | /* Blowfish as implemented from 'Blowfish: Springer-Verlag paper' | ||
| 63 | * (From LECTURE NOTES IN COIMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION, | ||
| 64 | * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993) | ||
| 65 | */ | ||
| 66 | |||
| 67 | #if (BF_ROUNDS != 16) && (BF_ROUNDS != 20) | ||
| 68 | If you set BF_ROUNDS to some value other than 16 or 20, you will have | ||
| 69 | to modify the code. | ||
| 70 | #endif | ||
| 71 | |||
| 72 | void BF_encrypt(data,key) | ||
| 73 | BF_LONG *data; | ||
| 74 | BF_KEY *key; | ||
| 75 | { | ||
| 76 | register BF_LONG l,r,*p,*s; | ||
| 77 | |||
| 78 | p=key->P; | ||
| 79 | s= &(key->S[0]); | ||
| 80 | l=data[0]; | ||
| 81 | r=data[1]; | ||
| 82 | |||
| 83 | l^=p[0]; | ||
| 84 | BF_ENC(r,l,s,p[ 1]); | ||
| 85 | BF_ENC(l,r,s,p[ 2]); | ||
| 86 | BF_ENC(r,l,s,p[ 3]); | ||
| 87 | BF_ENC(l,r,s,p[ 4]); | ||
| 88 | BF_ENC(r,l,s,p[ 5]); | ||
| 89 | BF_ENC(l,r,s,p[ 6]); | ||
| 90 | BF_ENC(r,l,s,p[ 7]); | ||
| 91 | BF_ENC(l,r,s,p[ 8]); | ||
| 92 | BF_ENC(r,l,s,p[ 9]); | ||
| 93 | BF_ENC(l,r,s,p[10]); | ||
| 94 | BF_ENC(r,l,s,p[11]); | ||
| 95 | BF_ENC(l,r,s,p[12]); | ||
| 96 | BF_ENC(r,l,s,p[13]); | ||
| 97 | BF_ENC(l,r,s,p[14]); | ||
| 98 | BF_ENC(r,l,s,p[15]); | ||
| 99 | BF_ENC(l,r,s,p[16]); | ||
| 100 | #if BF_ROUNDS == 20 | ||
| 101 | BF_ENC(r,l,s,p[17]); | ||
| 102 | BF_ENC(l,r,s,p[18]); | ||
| 103 | BF_ENC(r,l,s,p[19]); | ||
| 104 | BF_ENC(l,r,s,p[20]); | ||
| 105 | #endif | ||
| 106 | r^=p[BF_ROUNDS+1]; | ||
| 107 | |||
| 108 | data[1]=l&0xffffffffL; | ||
| 109 | data[0]=r&0xffffffffL; | ||
| 110 | } | ||
| 111 | |||
| 112 | #ifndef BF_DEFAULT_OPTIONS | ||
| 113 | |||
| 114 | void BF_decrypt(data,key) | ||
| 115 | BF_LONG *data; | ||
| 116 | BF_KEY *key; | ||
| 117 | { | ||
| 118 | register BF_LONG l,r,*p,*s; | ||
| 119 | |||
| 120 | p=key->P; | ||
| 121 | s= &(key->S[0]); | ||
| 122 | l=data[0]; | ||
| 123 | r=data[1]; | ||
| 124 | |||
| 125 | l^=p[BF_ROUNDS+1]; | ||
| 126 | #if BF_ROUNDS == 20 | ||
| 127 | BF_ENC(r,l,s,p[20]); | ||
| 128 | BF_ENC(l,r,s,p[19]); | ||
| 129 | BF_ENC(r,l,s,p[18]); | ||
| 130 | BF_ENC(l,r,s,p[17]); | ||
| 131 | #endif | ||
| 132 | BF_ENC(r,l,s,p[16]); | ||
| 133 | BF_ENC(l,r,s,p[15]); | ||
| 134 | BF_ENC(r,l,s,p[14]); | ||
| 135 | BF_ENC(l,r,s,p[13]); | ||
| 136 | BF_ENC(r,l,s,p[12]); | ||
| 137 | BF_ENC(l,r,s,p[11]); | ||
| 138 | BF_ENC(r,l,s,p[10]); | ||
| 139 | BF_ENC(l,r,s,p[ 9]); | ||
| 140 | BF_ENC(r,l,s,p[ 8]); | ||
| 141 | BF_ENC(l,r,s,p[ 7]); | ||
| 142 | BF_ENC(r,l,s,p[ 6]); | ||
| 143 | BF_ENC(l,r,s,p[ 5]); | ||
| 144 | BF_ENC(r,l,s,p[ 4]); | ||
| 145 | BF_ENC(l,r,s,p[ 3]); | ||
| 146 | BF_ENC(r,l,s,p[ 2]); | ||
| 147 | BF_ENC(l,r,s,p[ 1]); | ||
| 148 | r^=p[0]; | ||
| 149 | |||
| 150 | data[1]=l&0xffffffffL; | ||
| 151 | data[0]=r&0xffffffffL; | ||
| 152 | } | ||
| 153 | |||
| 154 | void BF_cbc_encrypt(in, out, length, ks, iv, encrypt) | ||
| 155 | unsigned char *in; | ||
| 156 | unsigned char *out; | ||
| 157 | long length; | ||
| 158 | BF_KEY *ks; | ||
| 159 | unsigned char *iv; | ||
| 160 | int encrypt; | ||
| 161 | { | ||
| 162 | register BF_LONG tin0,tin1; | ||
| 163 | register BF_LONG tout0,tout1,xor0,xor1; | ||
| 164 | register long l=length; | ||
| 165 | BF_LONG tin[2]; | ||
| 166 | |||
| 167 | if (encrypt) | ||
| 168 | { | ||
| 169 | n2l(iv,tout0); | ||
| 170 | n2l(iv,tout1); | ||
| 171 | iv-=8; | ||
| 172 | for (l-=8; l>=0; l-=8) | ||
| 173 | { | ||
| 174 | n2l(in,tin0); | ||
| 175 | n2l(in,tin1); | ||
| 176 | tin0^=tout0; | ||
| 177 | tin1^=tout1; | ||
| 178 | tin[0]=tin0; | ||
| 179 | tin[1]=tin1; | ||
| 180 | BF_encrypt(tin,ks); | ||
| 181 | tout0=tin[0]; | ||
| 182 | tout1=tin[1]; | ||
| 183 | l2n(tout0,out); | ||
| 184 | l2n(tout1,out); | ||
| 185 | } | ||
| 186 | if (l != -8) | ||
| 187 | { | ||
| 188 | n2ln(in,tin0,tin1,l+8); | ||
| 189 | tin0^=tout0; | ||
| 190 | tin1^=tout1; | ||
| 191 | tin[0]=tin0; | ||
| 192 | tin[1]=tin1; | ||
| 193 | BF_encrypt(tin,ks); | ||
| 194 | tout0=tin[0]; | ||
| 195 | tout1=tin[1]; | ||
| 196 | l2n(tout0,out); | ||
| 197 | l2n(tout1,out); | ||
| 198 | } | ||
| 199 | l2n(tout0,iv); | ||
| 200 | l2n(tout1,iv); | ||
| 201 | } | ||
| 202 | else | ||
| 203 | { | ||
| 204 | n2l(iv,xor0); | ||
| 205 | n2l(iv,xor1); | ||
| 206 | iv-=8; | ||
| 207 | for (l-=8; l>=0; l-=8) | ||
| 208 | { | ||
| 209 | n2l(in,tin0); | ||
| 210 | n2l(in,tin1); | ||
| 211 | tin[0]=tin0; | ||
| 212 | tin[1]=tin1; | ||
| 213 | BF_decrypt(tin,ks); | ||
| 214 | tout0=tin[0]^xor0; | ||
| 215 | tout1=tin[1]^xor1; | ||
| 216 | l2n(tout0,out); | ||
| 217 | l2n(tout1,out); | ||
| 218 | xor0=tin0; | ||
| 219 | xor1=tin1; | ||
| 220 | } | ||
| 221 | if (l != -8) | ||
| 222 | { | ||
| 223 | n2l(in,tin0); | ||
| 224 | n2l(in,tin1); | ||
| 225 | tin[0]=tin0; | ||
| 226 | tin[1]=tin1; | ||
| 227 | BF_decrypt(tin,ks); | ||
| 228 | tout0=tin[0]^xor0; | ||
| 229 | tout1=tin[1]^xor1; | ||
| 230 | l2nn(tout0,tout1,out,l+8); | ||
| 231 | xor0=tin0; | ||
| 232 | xor1=tin1; | ||
| 233 | } | ||
| 234 | l2n(xor0,iv); | ||
| 235 | l2n(xor1,iv); | ||
| 236 | } | ||
| 237 | tin0=tin1=tout0=tout1=xor0=xor1=0; | ||
| 238 | tin[0]=tin[1]=0; | ||
| 239 | } | ||
| 240 | |||
| 241 | #endif | ||
diff --git a/src/lib/libcrypto/bf/bf_ofb64.c b/src/lib/libcrypto/bf/bf_ofb64.c new file mode 100644 index 0000000000..5d844ac760 --- /dev/null +++ b/src/lib/libcrypto/bf/bf_ofb64.c | |||
| @@ -0,0 +1,115 @@ | |||
| 1 | /* crypto/bf/bf_ofb64.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 "blowfish.h" | ||
| 60 | #include "bf_locl.h" | ||
| 61 | |||
| 62 | /* The input and output encrypted as though 64bit ofb mode is being | ||
| 63 | * used. The extra state information to record how much of the | ||
| 64 | * 64bit block we have used is contained in *num; | ||
| 65 | */ | ||
| 66 | void BF_ofb64_encrypt(in, out, length, schedule, ivec, num) | ||
| 67 | unsigned char *in; | ||
| 68 | unsigned char *out; | ||
| 69 | long length; | ||
| 70 | BF_KEY *schedule; | ||
| 71 | unsigned char *ivec; | ||
| 72 | int *num; | ||
| 73 | { | ||
| 74 | register BF_LONG v0,v1,t; | ||
| 75 | register int n= *num; | ||
| 76 | register long l=length; | ||
| 77 | unsigned char d[8]; | ||
| 78 | register char *dp; | ||
| 79 | BF_LONG ti[2]; | ||
| 80 | unsigned char *iv; | ||
| 81 | int save=0; | ||
| 82 | |||
| 83 | iv=(unsigned char *)ivec; | ||
| 84 | n2l(iv,v0); | ||
| 85 | n2l(iv,v1); | ||
| 86 | ti[0]=v0; | ||
| 87 | ti[1]=v1; | ||
| 88 | dp=(char *)d; | ||
| 89 | l2n(v0,dp); | ||
| 90 | l2n(v1,dp); | ||
| 91 | while (l--) | ||
| 92 | { | ||
| 93 | if (n == 0) | ||
| 94 | { | ||
| 95 | BF_encrypt((BF_LONG *)ti,schedule); | ||
| 96 | dp=(char *)d; | ||
| 97 | t=ti[0]; l2n(t,dp); | ||
| 98 | t=ti[1]; l2n(t,dp); | ||
| 99 | save++; | ||
| 100 | } | ||
| 101 | *(out++)= *(in++)^d[n]; | ||
| 102 | n=(n+1)&0x07; | ||
| 103 | } | ||
| 104 | if (save) | ||
| 105 | { | ||
| 106 | v0=ti[0]; | ||
| 107 | v1=ti[1]; | ||
| 108 | iv=(unsigned char *)ivec; | ||
| 109 | l2n(v0,iv); | ||
| 110 | l2n(v1,iv); | ||
| 111 | } | ||
| 112 | t=v0=v1=ti[0]=ti[1]=0; | ||
| 113 | *num=n; | ||
| 114 | } | ||
| 115 | |||
diff --git a/src/lib/libcrypto/bf/bf_pi.h b/src/lib/libcrypto/bf/bf_pi.h new file mode 100644 index 0000000000..417b935538 --- /dev/null +++ b/src/lib/libcrypto/bf/bf_pi.h | |||
| @@ -0,0 +1,325 @@ | |||
| 1 | /* crypto/bf/bf_pi.h */ | ||
| 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 | static BF_KEY bf_init= { | ||
| 60 | { | ||
| 61 | 0x243f6a88L, 0x85a308d3L, 0x13198a2eL, 0x03707344L, | ||
| 62 | 0xa4093822L, 0x299f31d0L, 0x082efa98L, 0xec4e6c89L, | ||
| 63 | 0x452821e6L, 0x38d01377L, 0xbe5466cfL, 0x34e90c6cL, | ||
| 64 | 0xc0ac29b7L, 0xc97c50ddL, 0x3f84d5b5L, 0xb5470917L, | ||
| 65 | 0x9216d5d9L, 0x8979fb1b | ||
| 66 | },{ | ||
| 67 | 0xd1310ba6L, 0x98dfb5acL, 0x2ffd72dbL, 0xd01adfb7L, | ||
| 68 | 0xb8e1afedL, 0x6a267e96L, 0xba7c9045L, 0xf12c7f99L, | ||
| 69 | 0x24a19947L, 0xb3916cf7L, 0x0801f2e2L, 0x858efc16L, | ||
| 70 | 0x636920d8L, 0x71574e69L, 0xa458fea3L, 0xf4933d7eL, | ||
| 71 | 0x0d95748fL, 0x728eb658L, 0x718bcd58L, 0x82154aeeL, | ||
| 72 | 0x7b54a41dL, 0xc25a59b5L, 0x9c30d539L, 0x2af26013L, | ||
| 73 | 0xc5d1b023L, 0x286085f0L, 0xca417918L, 0xb8db38efL, | ||
| 74 | 0x8e79dcb0L, 0x603a180eL, 0x6c9e0e8bL, 0xb01e8a3eL, | ||
| 75 | 0xd71577c1L, 0xbd314b27L, 0x78af2fdaL, 0x55605c60L, | ||
| 76 | 0xe65525f3L, 0xaa55ab94L, 0x57489862L, 0x63e81440L, | ||
| 77 | 0x55ca396aL, 0x2aab10b6L, 0xb4cc5c34L, 0x1141e8ceL, | ||
| 78 | 0xa15486afL, 0x7c72e993L, 0xb3ee1411L, 0x636fbc2aL, | ||
| 79 | 0x2ba9c55dL, 0x741831f6L, 0xce5c3e16L, 0x9b87931eL, | ||
| 80 | 0xafd6ba33L, 0x6c24cf5cL, 0x7a325381L, 0x28958677L, | ||
| 81 | 0x3b8f4898L, 0x6b4bb9afL, 0xc4bfe81bL, 0x66282193L, | ||
| 82 | 0x61d809ccL, 0xfb21a991L, 0x487cac60L, 0x5dec8032L, | ||
| 83 | 0xef845d5dL, 0xe98575b1L, 0xdc262302L, 0xeb651b88L, | ||
| 84 | 0x23893e81L, 0xd396acc5L, 0x0f6d6ff3L, 0x83f44239L, | ||
| 85 | 0x2e0b4482L, 0xa4842004L, 0x69c8f04aL, 0x9e1f9b5eL, | ||
| 86 | 0x21c66842L, 0xf6e96c9aL, 0x670c9c61L, 0xabd388f0L, | ||
| 87 | 0x6a51a0d2L, 0xd8542f68L, 0x960fa728L, 0xab5133a3L, | ||
| 88 | 0x6eef0b6cL, 0x137a3be4L, 0xba3bf050L, 0x7efb2a98L, | ||
| 89 | 0xa1f1651dL, 0x39af0176L, 0x66ca593eL, 0x82430e88L, | ||
| 90 | 0x8cee8619L, 0x456f9fb4L, 0x7d84a5c3L, 0x3b8b5ebeL, | ||
| 91 | 0xe06f75d8L, 0x85c12073L, 0x401a449fL, 0x56c16aa6L, | ||
| 92 | 0x4ed3aa62L, 0x363f7706L, 0x1bfedf72L, 0x429b023dL, | ||
| 93 | 0x37d0d724L, 0xd00a1248L, 0xdb0fead3L, 0x49f1c09bL, | ||
| 94 | 0x075372c9L, 0x80991b7bL, 0x25d479d8L, 0xf6e8def7L, | ||
| 95 | 0xe3fe501aL, 0xb6794c3bL, 0x976ce0bdL, 0x04c006baL, | ||
| 96 | 0xc1a94fb6L, 0x409f60c4L, 0x5e5c9ec2L, 0x196a2463L, | ||
| 97 | 0x68fb6fafL, 0x3e6c53b5L, 0x1339b2ebL, 0x3b52ec6fL, | ||
| 98 | 0x6dfc511fL, 0x9b30952cL, 0xcc814544L, 0xaf5ebd09L, | ||
| 99 | 0xbee3d004L, 0xde334afdL, 0x660f2807L, 0x192e4bb3L, | ||
| 100 | 0xc0cba857L, 0x45c8740fL, 0xd20b5f39L, 0xb9d3fbdbL, | ||
| 101 | 0x5579c0bdL, 0x1a60320aL, 0xd6a100c6L, 0x402c7279L, | ||
| 102 | 0x679f25feL, 0xfb1fa3ccL, 0x8ea5e9f8L, 0xdb3222f8L, | ||
| 103 | 0x3c7516dfL, 0xfd616b15L, 0x2f501ec8L, 0xad0552abL, | ||
| 104 | 0x323db5faL, 0xfd238760L, 0x53317b48L, 0x3e00df82L, | ||
| 105 | 0x9e5c57bbL, 0xca6f8ca0L, 0x1a87562eL, 0xdf1769dbL, | ||
| 106 | 0xd542a8f6L, 0x287effc3L, 0xac6732c6L, 0x8c4f5573L, | ||
| 107 | 0x695b27b0L, 0xbbca58c8L, 0xe1ffa35dL, 0xb8f011a0L, | ||
| 108 | 0x10fa3d98L, 0xfd2183b8L, 0x4afcb56cL, 0x2dd1d35bL, | ||
| 109 | 0x9a53e479L, 0xb6f84565L, 0xd28e49bcL, 0x4bfb9790L, | ||
| 110 | 0xe1ddf2daL, 0xa4cb7e33L, 0x62fb1341L, 0xcee4c6e8L, | ||
| 111 | 0xef20cadaL, 0x36774c01L, 0xd07e9efeL, 0x2bf11fb4L, | ||
| 112 | 0x95dbda4dL, 0xae909198L, 0xeaad8e71L, 0x6b93d5a0L, | ||
| 113 | 0xd08ed1d0L, 0xafc725e0L, 0x8e3c5b2fL, 0x8e7594b7L, | ||
| 114 | 0x8ff6e2fbL, 0xf2122b64L, 0x8888b812L, 0x900df01cL, | ||
| 115 | 0x4fad5ea0L, 0x688fc31cL, 0xd1cff191L, 0xb3a8c1adL, | ||
| 116 | 0x2f2f2218L, 0xbe0e1777L, 0xea752dfeL, 0x8b021fa1L, | ||
| 117 | 0xe5a0cc0fL, 0xb56f74e8L, 0x18acf3d6L, 0xce89e299L, | ||
| 118 | 0xb4a84fe0L, 0xfd13e0b7L, 0x7cc43b81L, 0xd2ada8d9L, | ||
| 119 | 0x165fa266L, 0x80957705L, 0x93cc7314L, 0x211a1477L, | ||
| 120 | 0xe6ad2065L, 0x77b5fa86L, 0xc75442f5L, 0xfb9d35cfL, | ||
| 121 | 0xebcdaf0cL, 0x7b3e89a0L, 0xd6411bd3L, 0xae1e7e49L, | ||
| 122 | 0x00250e2dL, 0x2071b35eL, 0x226800bbL, 0x57b8e0afL, | ||
| 123 | 0x2464369bL, 0xf009b91eL, 0x5563911dL, 0x59dfa6aaL, | ||
| 124 | 0x78c14389L, 0xd95a537fL, 0x207d5ba2L, 0x02e5b9c5L, | ||
| 125 | 0x83260376L, 0x6295cfa9L, 0x11c81968L, 0x4e734a41L, | ||
| 126 | 0xb3472dcaL, 0x7b14a94aL, 0x1b510052L, 0x9a532915L, | ||
| 127 | 0xd60f573fL, 0xbc9bc6e4L, 0x2b60a476L, 0x81e67400L, | ||
| 128 | 0x08ba6fb5L, 0x571be91fL, 0xf296ec6bL, 0x2a0dd915L, | ||
| 129 | 0xb6636521L, 0xe7b9f9b6L, 0xff34052eL, 0xc5855664L, | ||
| 130 | 0x53b02d5dL, 0xa99f8fa1L, 0x08ba4799L, 0x6e85076aL, | ||
| 131 | 0x4b7a70e9L, 0xb5b32944L, 0xdb75092eL, 0xc4192623L, | ||
| 132 | 0xad6ea6b0L, 0x49a7df7dL, 0x9cee60b8L, 0x8fedb266L, | ||
| 133 | 0xecaa8c71L, 0x699a17ffL, 0x5664526cL, 0xc2b19ee1L, | ||
| 134 | 0x193602a5L, 0x75094c29L, 0xa0591340L, 0xe4183a3eL, | ||
| 135 | 0x3f54989aL, 0x5b429d65L, 0x6b8fe4d6L, 0x99f73fd6L, | ||
| 136 | 0xa1d29c07L, 0xefe830f5L, 0x4d2d38e6L, 0xf0255dc1L, | ||
| 137 | 0x4cdd2086L, 0x8470eb26L, 0x6382e9c6L, 0x021ecc5eL, | ||
| 138 | 0x09686b3fL, 0x3ebaefc9L, 0x3c971814L, 0x6b6a70a1L, | ||
| 139 | 0x687f3584L, 0x52a0e286L, 0xb79c5305L, 0xaa500737L, | ||
| 140 | 0x3e07841cL, 0x7fdeae5cL, 0x8e7d44ecL, 0x5716f2b8L, | ||
| 141 | 0xb03ada37L, 0xf0500c0dL, 0xf01c1f04L, 0x0200b3ffL, | ||
| 142 | 0xae0cf51aL, 0x3cb574b2L, 0x25837a58L, 0xdc0921bdL, | ||
| 143 | 0xd19113f9L, 0x7ca92ff6L, 0x94324773L, 0x22f54701L, | ||
| 144 | 0x3ae5e581L, 0x37c2dadcL, 0xc8b57634L, 0x9af3dda7L, | ||
| 145 | 0xa9446146L, 0x0fd0030eL, 0xecc8c73eL, 0xa4751e41L, | ||
| 146 | 0xe238cd99L, 0x3bea0e2fL, 0x3280bba1L, 0x183eb331L, | ||
| 147 | 0x4e548b38L, 0x4f6db908L, 0x6f420d03L, 0xf60a04bfL, | ||
| 148 | 0x2cb81290L, 0x24977c79L, 0x5679b072L, 0xbcaf89afL, | ||
| 149 | 0xde9a771fL, 0xd9930810L, 0xb38bae12L, 0xdccf3f2eL, | ||
| 150 | 0x5512721fL, 0x2e6b7124L, 0x501adde6L, 0x9f84cd87L, | ||
| 151 | 0x7a584718L, 0x7408da17L, 0xbc9f9abcL, 0xe94b7d8cL, | ||
| 152 | 0xec7aec3aL, 0xdb851dfaL, 0x63094366L, 0xc464c3d2L, | ||
| 153 | 0xef1c1847L, 0x3215d908L, 0xdd433b37L, 0x24c2ba16L, | ||
| 154 | 0x12a14d43L, 0x2a65c451L, 0x50940002L, 0x133ae4ddL, | ||
| 155 | 0x71dff89eL, 0x10314e55L, 0x81ac77d6L, 0x5f11199bL, | ||
| 156 | 0x043556f1L, 0xd7a3c76bL, 0x3c11183bL, 0x5924a509L, | ||
| 157 | 0xf28fe6edL, 0x97f1fbfaL, 0x9ebabf2cL, 0x1e153c6eL, | ||
| 158 | 0x86e34570L, 0xeae96fb1L, 0x860e5e0aL, 0x5a3e2ab3L, | ||
| 159 | 0x771fe71cL, 0x4e3d06faL, 0x2965dcb9L, 0x99e71d0fL, | ||
| 160 | 0x803e89d6L, 0x5266c825L, 0x2e4cc978L, 0x9c10b36aL, | ||
| 161 | 0xc6150ebaL, 0x94e2ea78L, 0xa5fc3c53L, 0x1e0a2df4L, | ||
| 162 | 0xf2f74ea7L, 0x361d2b3dL, 0x1939260fL, 0x19c27960L, | ||
| 163 | 0x5223a708L, 0xf71312b6L, 0xebadfe6eL, 0xeac31f66L, | ||
| 164 | 0xe3bc4595L, 0xa67bc883L, 0xb17f37d1L, 0x018cff28L, | ||
| 165 | 0xc332ddefL, 0xbe6c5aa5L, 0x65582185L, 0x68ab9802L, | ||
| 166 | 0xeecea50fL, 0xdb2f953bL, 0x2aef7dadL, 0x5b6e2f84L, | ||
| 167 | 0x1521b628L, 0x29076170L, 0xecdd4775L, 0x619f1510L, | ||
| 168 | 0x13cca830L, 0xeb61bd96L, 0x0334fe1eL, 0xaa0363cfL, | ||
| 169 | 0xb5735c90L, 0x4c70a239L, 0xd59e9e0bL, 0xcbaade14L, | ||
| 170 | 0xeecc86bcL, 0x60622ca7L, 0x9cab5cabL, 0xb2f3846eL, | ||
| 171 | 0x648b1eafL, 0x19bdf0caL, 0xa02369b9L, 0x655abb50L, | ||
| 172 | 0x40685a32L, 0x3c2ab4b3L, 0x319ee9d5L, 0xc021b8f7L, | ||
| 173 | 0x9b540b19L, 0x875fa099L, 0x95f7997eL, 0x623d7da8L, | ||
| 174 | 0xf837889aL, 0x97e32d77L, 0x11ed935fL, 0x16681281L, | ||
| 175 | 0x0e358829L, 0xc7e61fd6L, 0x96dedfa1L, 0x7858ba99L, | ||
| 176 | 0x57f584a5L, 0x1b227263L, 0x9b83c3ffL, 0x1ac24696L, | ||
| 177 | 0xcdb30aebL, 0x532e3054L, 0x8fd948e4L, 0x6dbc3128L, | ||
| 178 | 0x58ebf2efL, 0x34c6ffeaL, 0xfe28ed61L, 0xee7c3c73L, | ||
| 179 | 0x5d4a14d9L, 0xe864b7e3L, 0x42105d14L, 0x203e13e0L, | ||
| 180 | 0x45eee2b6L, 0xa3aaabeaL, 0xdb6c4f15L, 0xfacb4fd0L, | ||
| 181 | 0xc742f442L, 0xef6abbb5L, 0x654f3b1dL, 0x41cd2105L, | ||
| 182 | 0xd81e799eL, 0x86854dc7L, 0xe44b476aL, 0x3d816250L, | ||
| 183 | 0xcf62a1f2L, 0x5b8d2646L, 0xfc8883a0L, 0xc1c7b6a3L, | ||
| 184 | 0x7f1524c3L, 0x69cb7492L, 0x47848a0bL, 0x5692b285L, | ||
| 185 | 0x095bbf00L, 0xad19489dL, 0x1462b174L, 0x23820e00L, | ||
| 186 | 0x58428d2aL, 0x0c55f5eaL, 0x1dadf43eL, 0x233f7061L, | ||
| 187 | 0x3372f092L, 0x8d937e41L, 0xd65fecf1L, 0x6c223bdbL, | ||
| 188 | 0x7cde3759L, 0xcbee7460L, 0x4085f2a7L, 0xce77326eL, | ||
| 189 | 0xa6078084L, 0x19f8509eL, 0xe8efd855L, 0x61d99735L, | ||
| 190 | 0xa969a7aaL, 0xc50c06c2L, 0x5a04abfcL, 0x800bcadcL, | ||
| 191 | 0x9e447a2eL, 0xc3453484L, 0xfdd56705L, 0x0e1e9ec9L, | ||
| 192 | 0xdb73dbd3L, 0x105588cdL, 0x675fda79L, 0xe3674340L, | ||
| 193 | 0xc5c43465L, 0x713e38d8L, 0x3d28f89eL, 0xf16dff20L, | ||
| 194 | 0x153e21e7L, 0x8fb03d4aL, 0xe6e39f2bL, 0xdb83adf7L, | ||
| 195 | 0xe93d5a68L, 0x948140f7L, 0xf64c261cL, 0x94692934L, | ||
| 196 | 0x411520f7L, 0x7602d4f7L, 0xbcf46b2eL, 0xd4a20068L, | ||
| 197 | 0xd4082471L, 0x3320f46aL, 0x43b7d4b7L, 0x500061afL, | ||
| 198 | 0x1e39f62eL, 0x97244546L, 0x14214f74L, 0xbf8b8840L, | ||
| 199 | 0x4d95fc1dL, 0x96b591afL, 0x70f4ddd3L, 0x66a02f45L, | ||
| 200 | 0xbfbc09ecL, 0x03bd9785L, 0x7fac6dd0L, 0x31cb8504L, | ||
| 201 | 0x96eb27b3L, 0x55fd3941L, 0xda2547e6L, 0xabca0a9aL, | ||
| 202 | 0x28507825L, 0x530429f4L, 0x0a2c86daL, 0xe9b66dfbL, | ||
| 203 | 0x68dc1462L, 0xd7486900L, 0x680ec0a4L, 0x27a18deeL, | ||
| 204 | 0x4f3ffea2L, 0xe887ad8cL, 0xb58ce006L, 0x7af4d6b6L, | ||
| 205 | 0xaace1e7cL, 0xd3375fecL, 0xce78a399L, 0x406b2a42L, | ||
| 206 | 0x20fe9e35L, 0xd9f385b9L, 0xee39d7abL, 0x3b124e8bL, | ||
| 207 | 0x1dc9faf7L, 0x4b6d1856L, 0x26a36631L, 0xeae397b2L, | ||
| 208 | 0x3a6efa74L, 0xdd5b4332L, 0x6841e7f7L, 0xca7820fbL, | ||
| 209 | 0xfb0af54eL, 0xd8feb397L, 0x454056acL, 0xba489527L, | ||
| 210 | 0x55533a3aL, 0x20838d87L, 0xfe6ba9b7L, 0xd096954bL, | ||
| 211 | 0x55a867bcL, 0xa1159a58L, 0xcca92963L, 0x99e1db33L, | ||
| 212 | 0xa62a4a56L, 0x3f3125f9L, 0x5ef47e1cL, 0x9029317cL, | ||
| 213 | 0xfdf8e802L, 0x04272f70L, 0x80bb155cL, 0x05282ce3L, | ||
| 214 | 0x95c11548L, 0xe4c66d22L, 0x48c1133fL, 0xc70f86dcL, | ||
| 215 | 0x07f9c9eeL, 0x41041f0fL, 0x404779a4L, 0x5d886e17L, | ||
| 216 | 0x325f51ebL, 0xd59bc0d1L, 0xf2bcc18fL, 0x41113564L, | ||
| 217 | 0x257b7834L, 0x602a9c60L, 0xdff8e8a3L, 0x1f636c1bL, | ||
| 218 | 0x0e12b4c2L, 0x02e1329eL, 0xaf664fd1L, 0xcad18115L, | ||
| 219 | 0x6b2395e0L, 0x333e92e1L, 0x3b240b62L, 0xeebeb922L, | ||
| 220 | 0x85b2a20eL, 0xe6ba0d99L, 0xde720c8cL, 0x2da2f728L, | ||
| 221 | 0xd0127845L, 0x95b794fdL, 0x647d0862L, 0xe7ccf5f0L, | ||
| 222 | 0x5449a36fL, 0x877d48faL, 0xc39dfd27L, 0xf33e8d1eL, | ||
| 223 | 0x0a476341L, 0x992eff74L, 0x3a6f6eabL, 0xf4f8fd37L, | ||
| 224 | 0xa812dc60L, 0xa1ebddf8L, 0x991be14cL, 0xdb6e6b0dL, | ||
| 225 | 0xc67b5510L, 0x6d672c37L, 0x2765d43bL, 0xdcd0e804L, | ||
| 226 | 0xf1290dc7L, 0xcc00ffa3L, 0xb5390f92L, 0x690fed0bL, | ||
| 227 | 0x667b9ffbL, 0xcedb7d9cL, 0xa091cf0bL, 0xd9155ea3L, | ||
| 228 | 0xbb132f88L, 0x515bad24L, 0x7b9479bfL, 0x763bd6ebL, | ||
| 229 | 0x37392eb3L, 0xcc115979L, 0x8026e297L, 0xf42e312dL, | ||
| 230 | 0x6842ada7L, 0xc66a2b3bL, 0x12754cccL, 0x782ef11cL, | ||
| 231 | 0x6a124237L, 0xb79251e7L, 0x06a1bbe6L, 0x4bfb6350L, | ||
| 232 | 0x1a6b1018L, 0x11caedfaL, 0x3d25bdd8L, 0xe2e1c3c9L, | ||
| 233 | 0x44421659L, 0x0a121386L, 0xd90cec6eL, 0xd5abea2aL, | ||
| 234 | 0x64af674eL, 0xda86a85fL, 0xbebfe988L, 0x64e4c3feL, | ||
| 235 | 0x9dbc8057L, 0xf0f7c086L, 0x60787bf8L, 0x6003604dL, | ||
| 236 | 0xd1fd8346L, 0xf6381fb0L, 0x7745ae04L, 0xd736fcccL, | ||
| 237 | 0x83426b33L, 0xf01eab71L, 0xb0804187L, 0x3c005e5fL, | ||
| 238 | 0x77a057beL, 0xbde8ae24L, 0x55464299L, 0xbf582e61L, | ||
| 239 | 0x4e58f48fL, 0xf2ddfda2L, 0xf474ef38L, 0x8789bdc2L, | ||
| 240 | 0x5366f9c3L, 0xc8b38e74L, 0xb475f255L, 0x46fcd9b9L, | ||
| 241 | 0x7aeb2661L, 0x8b1ddf84L, 0x846a0e79L, 0x915f95e2L, | ||
| 242 | 0x466e598eL, 0x20b45770L, 0x8cd55591L, 0xc902de4cL, | ||
| 243 | 0xb90bace1L, 0xbb8205d0L, 0x11a86248L, 0x7574a99eL, | ||
| 244 | 0xb77f19b6L, 0xe0a9dc09L, 0x662d09a1L, 0xc4324633L, | ||
| 245 | 0xe85a1f02L, 0x09f0be8cL, 0x4a99a025L, 0x1d6efe10L, | ||
| 246 | 0x1ab93d1dL, 0x0ba5a4dfL, 0xa186f20fL, 0x2868f169L, | ||
| 247 | 0xdcb7da83L, 0x573906feL, 0xa1e2ce9bL, 0x4fcd7f52L, | ||
| 248 | 0x50115e01L, 0xa70683faL, 0xa002b5c4L, 0x0de6d027L, | ||
| 249 | 0x9af88c27L, 0x773f8641L, 0xc3604c06L, 0x61a806b5L, | ||
| 250 | 0xf0177a28L, 0xc0f586e0L, 0x006058aaL, 0x30dc7d62L, | ||
| 251 | 0x11e69ed7L, 0x2338ea63L, 0x53c2dd94L, 0xc2c21634L, | ||
| 252 | 0xbbcbee56L, 0x90bcb6deL, 0xebfc7da1L, 0xce591d76L, | ||
| 253 | 0x6f05e409L, 0x4b7c0188L, 0x39720a3dL, 0x7c927c24L, | ||
| 254 | 0x86e3725fL, 0x724d9db9L, 0x1ac15bb4L, 0xd39eb8fcL, | ||
| 255 | 0xed545578L, 0x08fca5b5L, 0xd83d7cd3L, 0x4dad0fc4L, | ||
| 256 | 0x1e50ef5eL, 0xb161e6f8L, 0xa28514d9L, 0x6c51133cL, | ||
| 257 | 0x6fd5c7e7L, 0x56e14ec4L, 0x362abfceL, 0xddc6c837L, | ||
| 258 | 0xd79a3234L, 0x92638212L, 0x670efa8eL, 0x406000e0L, | ||
| 259 | 0x3a39ce37L, 0xd3faf5cfL, 0xabc27737L, 0x5ac52d1bL, | ||
| 260 | 0x5cb0679eL, 0x4fa33742L, 0xd3822740L, 0x99bc9bbeL, | ||
| 261 | 0xd5118e9dL, 0xbf0f7315L, 0xd62d1c7eL, 0xc700c47bL, | ||
| 262 | 0xb78c1b6bL, 0x21a19045L, 0xb26eb1beL, 0x6a366eb4L, | ||
| 263 | 0x5748ab2fL, 0xbc946e79L, 0xc6a376d2L, 0x6549c2c8L, | ||
| 264 | 0x530ff8eeL, 0x468dde7dL, 0xd5730a1dL, 0x4cd04dc6L, | ||
| 265 | 0x2939bbdbL, 0xa9ba4650L, 0xac9526e8L, 0xbe5ee304L, | ||
| 266 | 0xa1fad5f0L, 0x6a2d519aL, 0x63ef8ce2L, 0x9a86ee22L, | ||
| 267 | 0xc089c2b8L, 0x43242ef6L, 0xa51e03aaL, 0x9cf2d0a4L, | ||
| 268 | 0x83c061baL, 0x9be96a4dL, 0x8fe51550L, 0xba645bd6L, | ||
| 269 | 0x2826a2f9L, 0xa73a3ae1L, 0x4ba99586L, 0xef5562e9L, | ||
| 270 | 0xc72fefd3L, 0xf752f7daL, 0x3f046f69L, 0x77fa0a59L, | ||
| 271 | 0x80e4a915L, 0x87b08601L, 0x9b09e6adL, 0x3b3ee593L, | ||
| 272 | 0xe990fd5aL, 0x9e34d797L, 0x2cf0b7d9L, 0x022b8b51L, | ||
| 273 | 0x96d5ac3aL, 0x017da67dL, 0xd1cf3ed6L, 0x7c7d2d28L, | ||
| 274 | 0x1f9f25cfL, 0xadf2b89bL, 0x5ad6b472L, 0x5a88f54cL, | ||
| 275 | 0xe029ac71L, 0xe019a5e6L, 0x47b0acfdL, 0xed93fa9bL, | ||
| 276 | 0xe8d3c48dL, 0x283b57ccL, 0xf8d56629L, 0x79132e28L, | ||
| 277 | 0x785f0191L, 0xed756055L, 0xf7960e44L, 0xe3d35e8cL, | ||
| 278 | 0x15056dd4L, 0x88f46dbaL, 0x03a16125L, 0x0564f0bdL, | ||
| 279 | 0xc3eb9e15L, 0x3c9057a2L, 0x97271aecL, 0xa93a072aL, | ||
| 280 | 0x1b3f6d9bL, 0x1e6321f5L, 0xf59c66fbL, 0x26dcf319L, | ||
| 281 | 0x7533d928L, 0xb155fdf5L, 0x03563482L, 0x8aba3cbbL, | ||
| 282 | 0x28517711L, 0xc20ad9f8L, 0xabcc5167L, 0xccad925fL, | ||
| 283 | 0x4de81751L, 0x3830dc8eL, 0x379d5862L, 0x9320f991L, | ||
| 284 | 0xea7a90c2L, 0xfb3e7bceL, 0x5121ce64L, 0x774fbe32L, | ||
| 285 | 0xa8b6e37eL, 0xc3293d46L, 0x48de5369L, 0x6413e680L, | ||
| 286 | 0xa2ae0810L, 0xdd6db224L, 0x69852dfdL, 0x09072166L, | ||
| 287 | 0xb39a460aL, 0x6445c0ddL, 0x586cdecfL, 0x1c20c8aeL, | ||
| 288 | 0x5bbef7ddL, 0x1b588d40L, 0xccd2017fL, 0x6bb4e3bbL, | ||
| 289 | 0xdda26a7eL, 0x3a59ff45L, 0x3e350a44L, 0xbcb4cdd5L, | ||
| 290 | 0x72eacea8L, 0xfa6484bbL, 0x8d6612aeL, 0xbf3c6f47L, | ||
| 291 | 0xd29be463L, 0x542f5d9eL, 0xaec2771bL, 0xf64e6370L, | ||
| 292 | 0x740e0d8dL, 0xe75b1357L, 0xf8721671L, 0xaf537d5dL, | ||
| 293 | 0x4040cb08L, 0x4eb4e2ccL, 0x34d2466aL, 0x0115af84L, | ||
| 294 | 0xe1b00428L, 0x95983a1dL, 0x06b89fb4L, 0xce6ea048L, | ||
| 295 | 0x6f3f3b82L, 0x3520ab82L, 0x011a1d4bL, 0x277227f8L, | ||
| 296 | 0x611560b1L, 0xe7933fdcL, 0xbb3a792bL, 0x344525bdL, | ||
| 297 | 0xa08839e1L, 0x51ce794bL, 0x2f32c9b7L, 0xa01fbac9L, | ||
| 298 | 0xe01cc87eL, 0xbcc7d1f6L, 0xcf0111c3L, 0xa1e8aac7L, | ||
| 299 | 0x1a908749L, 0xd44fbd9aL, 0xd0dadecbL, 0xd50ada38L, | ||
| 300 | 0x0339c32aL, 0xc6913667L, 0x8df9317cL, 0xe0b12b4fL, | ||
| 301 | 0xf79e59b7L, 0x43f5bb3aL, 0xf2d519ffL, 0x27d9459cL, | ||
| 302 | 0xbf97222cL, 0x15e6fc2aL, 0x0f91fc71L, 0x9b941525L, | ||
| 303 | 0xfae59361L, 0xceb69cebL, 0xc2a86459L, 0x12baa8d1L, | ||
| 304 | 0xb6c1075eL, 0xe3056a0cL, 0x10d25065L, 0xcb03a442L, | ||
| 305 | 0xe0ec6e0eL, 0x1698db3bL, 0x4c98a0beL, 0x3278e964L, | ||
| 306 | 0x9f1f9532L, 0xe0d392dfL, 0xd3a0342bL, 0x8971f21eL, | ||
| 307 | 0x1b0a7441L, 0x4ba3348cL, 0xc5be7120L, 0xc37632d8L, | ||
| 308 | 0xdf359f8dL, 0x9b992f2eL, 0xe60b6f47L, 0x0fe3f11dL, | ||
| 309 | 0xe54cda54L, 0x1edad891L, 0xce6279cfL, 0xcd3e7e6fL, | ||
| 310 | 0x1618b166L, 0xfd2c1d05L, 0x848fd2c5L, 0xf6fb2299L, | ||
| 311 | 0xf523f357L, 0xa6327623L, 0x93a83531L, 0x56cccd02L, | ||
| 312 | 0xacf08162L, 0x5a75ebb5L, 0x6e163697L, 0x88d273ccL, | ||
| 313 | 0xde966292L, 0x81b949d0L, 0x4c50901bL, 0x71c65614L, | ||
| 314 | 0xe6c6c7bdL, 0x327a140aL, 0x45e1d006L, 0xc3f27b9aL, | ||
| 315 | 0xc9aa53fdL, 0x62a80f00L, 0xbb25bfe2L, 0x35bdd2f6L, | ||
| 316 | 0x71126905L, 0xb2040222L, 0xb6cbcf7cL, 0xcd769c2bL, | ||
| 317 | 0x53113ec0L, 0x1640e3d3L, 0x38abbd60L, 0x2547adf0L, | ||
| 318 | 0xba38209cL, 0xf746ce76L, 0x77afa1c5L, 0x20756060L, | ||
| 319 | 0x85cbfe4eL, 0x8ae88dd8L, 0x7aaaf9b0L, 0x4cf9aa7eL, | ||
| 320 | 0x1948c25cL, 0x02fb8a8cL, 0x01c36ae4L, 0xd6ebe1f9L, | ||
| 321 | 0x90d4f869L, 0xa65cdea0L, 0x3f09252dL, 0xc208e69fL, | ||
| 322 | 0xb74e6132L, 0xce77e25bL, 0x578fdfe3L, 0x3ac372e6L, | ||
| 323 | } | ||
| 324 | }; | ||
| 325 | |||
diff --git a/src/lib/libcrypto/bf/bf_skey.c b/src/lib/libcrypto/bf/bf_skey.c new file mode 100644 index 0000000000..86574c0acc --- /dev/null +++ b/src/lib/libcrypto/bf/bf_skey.c | |||
| @@ -0,0 +1,119 @@ | |||
| 1 | /* crypto/bf/bf_skey.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 <string.h> | ||
| 61 | #include "blowfish.h" | ||
| 62 | #include "bf_locl.h" | ||
| 63 | #include "bf_pi.h" | ||
| 64 | |||
| 65 | void BF_set_key(key,len,data) | ||
| 66 | BF_KEY *key; | ||
| 67 | int len; | ||
| 68 | unsigned char *data; | ||
| 69 | { | ||
| 70 | int i; | ||
| 71 | BF_LONG *p,ri,in[2]; | ||
| 72 | unsigned char *d,*end; | ||
| 73 | |||
| 74 | |||
| 75 | memcpy((char *)key,(char *)&bf_init,sizeof(BF_KEY)); | ||
| 76 | p=key->P; | ||
| 77 | |||
| 78 | if (len > ((BF_ROUNDS+2)*4)) len=(BF_ROUNDS+2)*4; | ||
| 79 | |||
| 80 | d=data; | ||
| 81 | end= &(data[len]); | ||
| 82 | for (i=0; i<(BF_ROUNDS+2); i++) | ||
| 83 | { | ||
| 84 | ri= *(d++); | ||
| 85 | if (d >= end) d=data; | ||
| 86 | |||
| 87 | ri<<=8; | ||
| 88 | ri|= *(d++); | ||
| 89 | if (d >= end) d=data; | ||
| 90 | |||
| 91 | ri<<=8; | ||
| 92 | ri|= *(d++); | ||
| 93 | if (d >= end) d=data; | ||
| 94 | |||
| 95 | ri<<=8; | ||
| 96 | ri|= *(d++); | ||
| 97 | if (d >= end) d=data; | ||
| 98 | |||
| 99 | p[i]^=ri; | ||
| 100 | } | ||
| 101 | |||
| 102 | in[0]=0L; | ||
| 103 | in[1]=0L; | ||
| 104 | for (i=0; i<(BF_ROUNDS+2); i+=2) | ||
| 105 | { | ||
| 106 | BF_encrypt(in,key); | ||
| 107 | p[i ]=in[0]; | ||
| 108 | p[i+1]=in[1]; | ||
| 109 | } | ||
| 110 | |||
| 111 | p=key->S; | ||
| 112 | for (i=0; i<4*256; i+=2) | ||
| 113 | { | ||
| 114 | BF_encrypt(in,key); | ||
| 115 | p[i ]=in[0]; | ||
| 116 | p[i+1]=in[1]; | ||
| 117 | } | ||
| 118 | } | ||
| 119 | |||
diff --git a/src/lib/libcrypto/bf/blowfish.h b/src/lib/libcrypto/bf/blowfish.h new file mode 100644 index 0000000000..c4a8085a29 --- /dev/null +++ b/src/lib/libcrypto/bf/blowfish.h | |||
| @@ -0,0 +1,116 @@ | |||
| 1 | /* crypto/bf/blowfish.h */ | ||
| 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 | #ifndef HEADER_BLOWFISH_H | ||
| 60 | #define HEADER_BLOWFISH_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #define BF_ENCRYPT 1 | ||
| 67 | #define BF_DECRYPT 0 | ||
| 68 | |||
| 69 | /* If you make this 'unsigned int' the pointer variants will work on | ||
| 70 | * the Alpha, otherwise they will not. Strangly using the '8 byte' | ||
| 71 | * BF_LONG and the default 'non-pointer' inner loop is the best configuration | ||
| 72 | * for the Alpha */ | ||
| 73 | #define BF_LONG unsigned long | ||
| 74 | |||
| 75 | #define BF_ROUNDS 16 | ||
| 76 | #define BF_BLOCK 8 | ||
| 77 | |||
| 78 | typedef struct bf_key_st | ||
| 79 | { | ||
| 80 | BF_LONG P[BF_ROUNDS+2]; | ||
| 81 | BF_LONG S[4*256]; | ||
| 82 | } BF_KEY; | ||
| 83 | |||
| 84 | #ifndef NOPROTO | ||
| 85 | |||
| 86 | void BF_set_key(BF_KEY *key, int len, unsigned char *data); | ||
| 87 | void BF_ecb_encrypt(unsigned char *in,unsigned char *out,BF_KEY *key, | ||
| 88 | int enc); | ||
| 89 | void BF_encrypt(BF_LONG *data,BF_KEY *key); | ||
| 90 | void BF_decrypt(BF_LONG *data,BF_KEY *key); | ||
| 91 | void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length, | ||
| 92 | BF_KEY *ks, unsigned char *iv, int enc); | ||
| 93 | void BF_cfb64_encrypt(unsigned char *in, unsigned char *out, long length, | ||
| 94 | BF_KEY *schedule, unsigned char *ivec, int *num, int enc); | ||
| 95 | void BF_ofb64_encrypt(unsigned char *in, unsigned char *out, long length, | ||
| 96 | BF_KEY *schedule, unsigned char *ivec, int *num); | ||
| 97 | char *BF_options(void); | ||
| 98 | |||
| 99 | #else | ||
| 100 | |||
| 101 | void BF_set_key(); | ||
| 102 | void BF_ecb_encrypt(); | ||
| 103 | void BF_encrypt(); | ||
| 104 | void BF_decrypt(); | ||
| 105 | void BF_cbc_encrypt(); | ||
| 106 | void BF_cfb64_encrypt(); | ||
| 107 | void BF_ofb64_encrypt(); | ||
| 108 | char *BF_options(); | ||
| 109 | |||
| 110 | #endif | ||
| 111 | |||
| 112 | #ifdef __cplusplus | ||
| 113 | } | ||
| 114 | #endif | ||
| 115 | |||
| 116 | #endif | ||
diff --git a/src/lib/libcrypto/bio/b_dump.c b/src/lib/libcrypto/bio/b_dump.c new file mode 100644 index 0000000000..db84ad3d47 --- /dev/null +++ b/src/lib/libcrypto/bio/b_dump.c | |||
| @@ -0,0 +1,125 @@ | |||
| 1 | /* crypto/bio/b_dump.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 | /* | ||
| 60 | * Stolen from tjh's ssl/ssl_trc.c stuff. | ||
| 61 | */ | ||
| 62 | |||
| 63 | #include <stdio.h> | ||
| 64 | #include "cryptlib.h" | ||
| 65 | #include "bio.h" | ||
| 66 | |||
| 67 | #define TRUNCATE | ||
| 68 | #define DUMP_WIDTH 16 | ||
| 69 | |||
| 70 | int BIO_dump(bio,s,len) | ||
| 71 | BIO *bio; | ||
| 72 | char *s; | ||
| 73 | int len; | ||
| 74 | { | ||
| 75 | int ret=0; | ||
| 76 | char buf[160+1],tmp[20]; | ||
| 77 | int i,j,rows,trunc; | ||
| 78 | unsigned char ch; | ||
| 79 | |||
| 80 | trunc=0; | ||
| 81 | |||
| 82 | #ifdef TRUNCATE | ||
| 83 | for(; (len > 0) && ((s[len-1] == ' ') || (s[len-1] == '\0')); len--) | ||
| 84 | trunc++; | ||
| 85 | #endif | ||
| 86 | |||
| 87 | rows=(len/DUMP_WIDTH); | ||
| 88 | if ((rows*DUMP_WIDTH)<len) | ||
| 89 | rows++; | ||
| 90 | for(i=0;i<rows;i++) { | ||
| 91 | buf[0]='\0'; /* start with empty string */ | ||
| 92 | sprintf(tmp,"%04x - ",i*DUMP_WIDTH); | ||
| 93 | strcpy(buf,tmp); | ||
| 94 | for(j=0;j<DUMP_WIDTH;j++) { | ||
| 95 | if (((i*DUMP_WIDTH)+j)>=len) { | ||
| 96 | strcat(buf," "); | ||
| 97 | } else { | ||
| 98 | ch=((unsigned char)*((char *)(s)+i*DUMP_WIDTH+j)) & 0xff; | ||
| 99 | sprintf(tmp,"%02x%c",ch,j==7?'-':' '); | ||
| 100 | strcat(buf,tmp); | ||
| 101 | } | ||
| 102 | } | ||
| 103 | strcat(buf," "); | ||
| 104 | for(j=0;j<DUMP_WIDTH;j++) { | ||
| 105 | if (((i*DUMP_WIDTH)+j)>=len) | ||
| 106 | break; | ||
| 107 | ch=((unsigned char)*((char *)(s)+i*DUMP_WIDTH+j)) & 0xff; | ||
| 108 | sprintf(tmp,"%c",((ch>=' ')&&(ch<='~'))?ch:'.'); | ||
| 109 | strcat(buf,tmp); | ||
| 110 | } | ||
| 111 | strcat(buf,"\n"); | ||
| 112 | /* if this is the last call then update the ddt_dump thing so that | ||
| 113 | * we will move the selection point in the debug window | ||
| 114 | */ | ||
| 115 | ret+=BIO_write(bio,(char *)buf,strlen(buf)); | ||
| 116 | } | ||
| 117 | #ifdef TRUNCATE | ||
| 118 | if (trunc > 0) { | ||
| 119 | sprintf(buf,"%04x - <SPACES/NULS>\n",len+trunc); | ||
| 120 | ret+=BIO_write(bio,(char *)buf,strlen(buf)); | ||
| 121 | } | ||
| 122 | #endif | ||
| 123 | return(ret); | ||
| 124 | } | ||
| 125 | |||
diff --git a/src/lib/libcrypto/bio/b_print.c b/src/lib/libcrypto/bio/b_print.c new file mode 100644 index 0000000000..cdadeb839a --- /dev/null +++ b/src/lib/libcrypto/bio/b_print.c | |||
| @@ -0,0 +1,92 @@ | |||
| 1 | /* crypto/bio/b_print.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 | /* | ||
| 60 | * Stolen from tjh's ssl/ssl_trc.c stuff. | ||
| 61 | */ | ||
| 62 | |||
| 63 | #include <stdio.h> | ||
| 64 | #include "cryptlib.h" | ||
| 65 | #include "bio.h" | ||
| 66 | |||
| 67 | int BIO_printf ( VAR_PLIST( BIO *, bio ) ) | ||
| 68 | VAR_ALIST | ||
| 69 | { | ||
| 70 | VAR_BDEFN(args, BIO *, bio); | ||
| 71 | char *format; | ||
| 72 | int ret; | ||
| 73 | MS_STATIC char hugebuf[1024*2]; /* 10k in one chunk is the limit */ | ||
| 74 | |||
| 75 | VAR_INIT(args, BIO *, bio); | ||
| 76 | VAR_ARG(args, char *, format); | ||
| 77 | |||
| 78 | hugebuf[0]='\0'; | ||
| 79 | |||
| 80 | /* no-one uses _doprnt anymore and it appears to be broken under SunOS 4.1.4 */ | ||
| 81 | #if 0 && defined(sun) && !defined(VAR_ANSI) /**/ | ||
| 82 | _doprnt(hugebuf,format,args); | ||
| 83 | #else /* !sun */ | ||
| 84 | vsprintf(hugebuf,format,args); | ||
| 85 | #endif /* sun */ | ||
| 86 | |||
| 87 | ret=BIO_write(bio,hugebuf,strlen(hugebuf)); | ||
| 88 | |||
| 89 | VAR_END( args ); | ||
| 90 | return(ret); | ||
| 91 | } | ||
| 92 | |||
diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c new file mode 100644 index 0000000000..a45909527c --- /dev/null +++ b/src/lib/libcrypto/bio/b_sock.c | |||
| @@ -0,0 +1,628 @@ | |||
| 1 | /* crypto/bio/b_sock.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 | #ifndef NO_SOCK | ||
| 60 | |||
| 61 | #include <stdio.h> | ||
| 62 | #include <stdlib.h> | ||
| 63 | #include <errno.h> | ||
| 64 | #define USE_SOCKETS | ||
| 65 | #include "cryptlib.h" | ||
| 66 | #include "bio.h" | ||
| 67 | |||
| 68 | /* BIOerr(BIO_F_WSASTARTUP,BIO_R_WSASTARTUP ); */ | ||
| 69 | |||
| 70 | #ifdef WIN16 | ||
| 71 | #define SOCKET_PROTOCOL 0 /* more microsoft stupidity */ | ||
| 72 | #else | ||
| 73 | #define SOCKET_PROTOCOL IPPROTO_TCP | ||
| 74 | #endif | ||
| 75 | |||
| 76 | #ifdef SO_MAXCONN | ||
| 77 | #define MAX_LISTEN SOMAXCONN | ||
| 78 | #elif defined(SO_MAXCONN) | ||
| 79 | #define MAX_LISTEN SO_MAXCONN | ||
| 80 | #else | ||
| 81 | #define MAX_LISTEN 32 | ||
| 82 | #endif | ||
| 83 | |||
| 84 | #ifdef WINDOWS | ||
| 85 | static int wsa_init_done=0; | ||
| 86 | #endif | ||
| 87 | |||
| 88 | static unsigned long BIO_ghbn_hits=0L; | ||
| 89 | static unsigned long BIO_ghbn_miss=0L; | ||
| 90 | |||
| 91 | #define GHBN_NUM 4 | ||
| 92 | static struct ghbn_cache_st | ||
| 93 | { | ||
| 94 | char name[129]; | ||
| 95 | struct hostent *ent; | ||
| 96 | unsigned long order; | ||
| 97 | } ghbn_cache[GHBN_NUM]; | ||
| 98 | |||
| 99 | #ifndef NOPROTO | ||
| 100 | static int get_ip(char *str,unsigned char *ip); | ||
| 101 | static void ghbn_free(struct hostent *a); | ||
| 102 | static struct hostent *ghbn_dup(struct hostent *a); | ||
| 103 | #else | ||
| 104 | static int get_ip(); | ||
| 105 | static void ghbn_free(); | ||
| 106 | static struct hostent *ghbn_dup(); | ||
| 107 | #endif | ||
| 108 | |||
| 109 | int BIO_get_host_ip(str,ip) | ||
| 110 | char *str; | ||
| 111 | unsigned char *ip; | ||
| 112 | { | ||
| 113 | int i; | ||
| 114 | struct hostent *he; | ||
| 115 | |||
| 116 | i=get_ip(str,ip); | ||
| 117 | if (i > 0) return(1); | ||
| 118 | if (i < 0) | ||
| 119 | { | ||
| 120 | BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_INVALID_IP_ADDRESS); | ||
| 121 | ERR_add_error_data(2,"host=",str); | ||
| 122 | return(0); | ||
| 123 | } | ||
| 124 | else | ||
| 125 | { /* do a gethostbyname */ | ||
| 126 | if (!BIO_sock_init()) return(0); | ||
| 127 | |||
| 128 | he=BIO_gethostbyname(str); | ||
| 129 | if (he == NULL) | ||
| 130 | { | ||
| 131 | BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_BAD_HOSTNAME_LOOKUP); | ||
| 132 | ERR_add_error_data(2,"host=",str); | ||
| 133 | return(0); | ||
| 134 | } | ||
| 135 | |||
| 136 | /* cast to short because of win16 winsock definition */ | ||
| 137 | if ((short)he->h_addrtype != AF_INET) | ||
| 138 | { | ||
| 139 | BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET); | ||
| 140 | ERR_add_error_data(2,"host=",str); | ||
| 141 | return(0); | ||
| 142 | } | ||
| 143 | for (i=0; i<4; i++) | ||
| 144 | ip[i]=he->h_addr_list[0][i]; | ||
| 145 | } | ||
| 146 | return(1); | ||
| 147 | } | ||
| 148 | |||
| 149 | int BIO_get_port(str,port_ptr) | ||
| 150 | char *str; | ||
| 151 | short *port_ptr; | ||
| 152 | { | ||
| 153 | int i; | ||
| 154 | struct servent *s; | ||
| 155 | |||
| 156 | if (str == NULL) | ||
| 157 | { | ||
| 158 | BIOerr(BIO_F_BIO_GET_PORT,BIO_R_NO_PORT_DEFINED); | ||
| 159 | return(0); | ||
| 160 | } | ||
| 161 | i=atoi(str); | ||
| 162 | if (i != 0) | ||
| 163 | *port_ptr=(unsigned short)i; | ||
| 164 | else | ||
| 165 | { | ||
| 166 | s=getservbyname(str,"tcp"); | ||
| 167 | if (s == NULL) | ||
| 168 | { | ||
| 169 | if (strcmp(str,"http") == 0) | ||
| 170 | *port_ptr=80; | ||
| 171 | else if (strcmp(str,"telnet") == 0) | ||
| 172 | *port_ptr=23; | ||
| 173 | else if (strcmp(str,"socks") == 0) | ||
| 174 | *port_ptr=1080; | ||
| 175 | else if (strcmp(str,"https") == 0) | ||
| 176 | *port_ptr=443; | ||
| 177 | else if (strcmp(str,"ssl") == 0) | ||
| 178 | *port_ptr=443; | ||
| 179 | else if (strcmp(str,"ftp") == 0) | ||
| 180 | *port_ptr=21; | ||
| 181 | else if (strcmp(str,"gopher") == 0) | ||
| 182 | *port_ptr=70; | ||
| 183 | #if 0 | ||
| 184 | else if (strcmp(str,"wais") == 0) | ||
| 185 | *port_ptr=21; | ||
| 186 | #endif | ||
| 187 | else | ||
| 188 | { | ||
| 189 | SYSerr(SYS_F_GETSERVBYNAME,get_last_socket_error()); | ||
| 190 | ERR_add_error_data(3,"service='",str,"'"); | ||
| 191 | return(0); | ||
| 192 | } | ||
| 193 | return(1); | ||
| 194 | } | ||
| 195 | *port_ptr=htons((unsigned short)s->s_port); | ||
| 196 | } | ||
| 197 | return(1); | ||
| 198 | } | ||
| 199 | |||
| 200 | int BIO_sock_error(sock) | ||
| 201 | int sock; | ||
| 202 | { | ||
| 203 | int j,i,size; | ||
| 204 | |||
| 205 | size=sizeof(int); | ||
| 206 | |||
| 207 | i=getsockopt(sock,SOL_SOCKET,SO_ERROR,(char *)&j,&size); | ||
| 208 | if (i < 0) | ||
| 209 | return(1); | ||
| 210 | else | ||
| 211 | return(j); | ||
| 212 | } | ||
| 213 | |||
| 214 | long BIO_ghbn_ctrl(cmd,iarg,parg) | ||
| 215 | int cmd; | ||
| 216 | int iarg; | ||
| 217 | char *parg; | ||
| 218 | { | ||
| 219 | int i; | ||
| 220 | char **p; | ||
| 221 | |||
| 222 | switch (cmd) | ||
| 223 | { | ||
| 224 | case BIO_GHBN_CTRL_HITS: | ||
| 225 | return(BIO_ghbn_hits); | ||
| 226 | break; | ||
| 227 | case BIO_GHBN_CTRL_MISSES: | ||
| 228 | return(BIO_ghbn_miss); | ||
| 229 | break; | ||
| 230 | case BIO_GHBN_CTRL_CACHE_SIZE: | ||
| 231 | return(GHBN_NUM); | ||
| 232 | break; | ||
| 233 | case BIO_GHBN_CTRL_GET_ENTRY: | ||
| 234 | if ((iarg >= 0) && (iarg <GHBN_NUM) && | ||
| 235 | (ghbn_cache[iarg].order > 0)) | ||
| 236 | { | ||
| 237 | p=(char **)parg; | ||
| 238 | if (p == NULL) return(0); | ||
| 239 | *p=ghbn_cache[iarg].name; | ||
| 240 | ghbn_cache[iarg].name[128]='\0'; | ||
| 241 | return(1); | ||
| 242 | } | ||
| 243 | return(0); | ||
| 244 | break; | ||
| 245 | case BIO_GHBN_CTRL_FLUSH: | ||
| 246 | for (i=0; i<GHBN_NUM; i++) | ||
| 247 | ghbn_cache[i].order=0; | ||
| 248 | break; | ||
| 249 | default: | ||
| 250 | return(0); | ||
| 251 | } | ||
| 252 | return(1); | ||
| 253 | } | ||
| 254 | |||
| 255 | static struct hostent *ghbn_dup(a) | ||
| 256 | struct hostent *a; | ||
| 257 | { | ||
| 258 | struct hostent *ret; | ||
| 259 | int i,j; | ||
| 260 | |||
| 261 | ret=(struct hostent *)malloc(sizeof(struct hostent)); | ||
| 262 | if (ret == NULL) return(NULL); | ||
| 263 | memset(ret,0,sizeof(struct hostent)); | ||
| 264 | |||
| 265 | for (i=0; a->h_aliases[i] != NULL; i++) | ||
| 266 | ; | ||
| 267 | i++; | ||
| 268 | ret->h_aliases=(char **)malloc(sizeof(char *)*i); | ||
| 269 | memset(ret->h_aliases,0,sizeof(char *)*i); | ||
| 270 | if (ret == NULL) goto err; | ||
| 271 | |||
| 272 | for (i=0; a->h_addr_list[i] != NULL; i++) | ||
| 273 | ; | ||
| 274 | i++; | ||
| 275 | ret->h_addr_list=(char **)malloc(sizeof(char *)*i); | ||
| 276 | memset(ret->h_addr_list,0,sizeof(char *)*i); | ||
| 277 | if (ret->h_addr_list == NULL) goto err; | ||
| 278 | |||
| 279 | j=strlen(a->h_name)+1; | ||
| 280 | if ((ret->h_name=malloc(j)) == NULL) goto err; | ||
| 281 | memcpy((char *)ret->h_name,a->h_name,j); | ||
| 282 | for (i=0; a->h_aliases[i] != NULL; i++) | ||
| 283 | { | ||
| 284 | j=strlen(a->h_aliases[i])+1; | ||
| 285 | if ((ret->h_aliases[i]=malloc(j)) == NULL) goto err; | ||
| 286 | memcpy(ret->h_aliases[i],a->h_aliases[i],j); | ||
| 287 | } | ||
| 288 | ret->h_length=a->h_length; | ||
| 289 | ret->h_addrtype=a->h_addrtype; | ||
| 290 | for (i=0; a->h_addr_list[i] != NULL; i++) | ||
| 291 | { | ||
| 292 | if ((ret->h_addr_list[i]=malloc(a->h_length)) == NULL) | ||
| 293 | goto err; | ||
| 294 | memcpy(ret->h_addr_list[i],a->h_addr_list[i],a->h_length); | ||
| 295 | } | ||
| 296 | return(ret); | ||
| 297 | err: | ||
| 298 | if (ret != NULL) | ||
| 299 | ghbn_free(ret); | ||
| 300 | return(NULL); | ||
| 301 | } | ||
| 302 | |||
| 303 | static void ghbn_free(a) | ||
| 304 | struct hostent *a; | ||
| 305 | { | ||
| 306 | int i; | ||
| 307 | |||
| 308 | if (a->h_aliases != NULL) | ||
| 309 | { | ||
| 310 | for (i=0; a->h_aliases[i] != NULL; i++) | ||
| 311 | free(a->h_aliases[i]); | ||
| 312 | free(a->h_aliases); | ||
| 313 | } | ||
| 314 | if (a->h_addr_list != NULL) | ||
| 315 | { | ||
| 316 | for (i=0; a->h_addr_list[i] != NULL; i++) | ||
| 317 | free(a->h_addr_list[i]); | ||
| 318 | free(a->h_addr_list); | ||
| 319 | } | ||
| 320 | if (a->h_name != NULL) free((char *)a->h_name); | ||
| 321 | free(a); | ||
| 322 | } | ||
| 323 | |||
| 324 | struct hostent *BIO_gethostbyname(name) | ||
| 325 | char *name; | ||
| 326 | { | ||
| 327 | struct hostent *ret; | ||
| 328 | int i,lowi=0,j; | ||
| 329 | unsigned long low= (unsigned long)-1; | ||
| 330 | |||
| 331 | /* return(gethostbyname(name)); */ | ||
| 332 | |||
| 333 | CRYPTO_w_lock(CRYPTO_LOCK_BIO_GETHOSTBYNAME); | ||
| 334 | j=strlen(name); | ||
| 335 | if (j < 128) | ||
| 336 | { | ||
| 337 | for (i=0; i<GHBN_NUM; i++) | ||
| 338 | { | ||
| 339 | if (low > ghbn_cache[i].order) | ||
| 340 | { | ||
| 341 | low=ghbn_cache[i].order; | ||
| 342 | lowi=i; | ||
| 343 | } | ||
| 344 | if (ghbn_cache[i].order > 0) | ||
| 345 | { | ||
| 346 | if (strncmp(name,ghbn_cache[i].name,128) == 0) | ||
| 347 | break; | ||
| 348 | } | ||
| 349 | } | ||
| 350 | } | ||
| 351 | else | ||
| 352 | i=GHBN_NUM; | ||
| 353 | |||
| 354 | if (i == GHBN_NUM) /* no hit*/ | ||
| 355 | { | ||
| 356 | BIO_ghbn_miss++; | ||
| 357 | ret=gethostbyname(name); | ||
| 358 | |||
| 359 | if (ret == NULL) return(NULL); | ||
| 360 | if (j > 128) return(ret); /* too big to cache */ | ||
| 361 | |||
| 362 | /* else add to cache */ | ||
| 363 | if (ghbn_cache[lowi].ent != NULL) | ||
| 364 | ghbn_free(ghbn_cache[lowi].ent); | ||
| 365 | |||
| 366 | strncpy(ghbn_cache[lowi].name,name,128); | ||
| 367 | ghbn_cache[lowi].ent=ghbn_dup(ret); | ||
| 368 | ghbn_cache[lowi].order=BIO_ghbn_miss+BIO_ghbn_hits; | ||
| 369 | } | ||
| 370 | else | ||
| 371 | { | ||
| 372 | BIO_ghbn_hits++; | ||
| 373 | ret= ghbn_cache[i].ent; | ||
| 374 | ghbn_cache[i].order=BIO_ghbn_miss+BIO_ghbn_hits; | ||
| 375 | } | ||
| 376 | CRYPTO_w_unlock(CRYPTO_LOCK_BIO_GETHOSTBYNAME); | ||
| 377 | return(ret); | ||
| 378 | } | ||
| 379 | |||
| 380 | int BIO_sock_init() | ||
| 381 | { | ||
| 382 | #ifdef WINDOWS | ||
| 383 | static struct WSAData wsa_state; | ||
| 384 | |||
| 385 | if (!wsa_init_done) | ||
| 386 | { | ||
| 387 | int err; | ||
| 388 | |||
| 389 | #ifdef SIGINT | ||
| 390 | signal(SIGINT,(void (*)(int))BIO_sock_cleanup); | ||
| 391 | #endif | ||
| 392 | wsa_init_done=1; | ||
| 393 | memset(&wsa_state,0,sizeof(wsa_state)); | ||
| 394 | if (WSAStartup(0x0101,&wsa_state)!=0) | ||
| 395 | { | ||
| 396 | err=WSAGetLastError(); | ||
| 397 | SYSerr(SYS_F_WSASTARTUP,err); | ||
| 398 | BIOerr(BIO_F_BIO_SOCK_INIT,BIO_R_WSASTARTUP); | ||
| 399 | return(-1); | ||
| 400 | } | ||
| 401 | } | ||
| 402 | #endif /* WINDOWS */ | ||
| 403 | return(1); | ||
| 404 | } | ||
| 405 | |||
| 406 | void BIO_sock_cleanup() | ||
| 407 | { | ||
| 408 | #ifdef WINDOWS | ||
| 409 | if (wsa_init_done) | ||
| 410 | { | ||
| 411 | wsa_init_done=0; | ||
| 412 | WSACancelBlockingCall(); | ||
| 413 | WSACleanup(); | ||
| 414 | } | ||
| 415 | #endif | ||
| 416 | } | ||
| 417 | |||
| 418 | int BIO_socket_ioctl(fd,type,arg) | ||
| 419 | int fd; | ||
| 420 | long type; | ||
| 421 | unsigned long *arg; | ||
| 422 | { | ||
| 423 | int i; | ||
| 424 | |||
| 425 | i=ioctlsocket(fd,type,arg); | ||
| 426 | if (i < 0) | ||
| 427 | SYSerr(SYS_F_IOCTLSOCKET,get_last_socket_error()); | ||
| 428 | return(i); | ||
| 429 | } | ||
| 430 | |||
| 431 | /* The reason I have implemented this instead of using sscanf is because | ||
| 432 | * Visual C 1.52c gives an unresolved external when linking a DLL :-( */ | ||
| 433 | static int get_ip(str,ip) | ||
| 434 | char *str; | ||
| 435 | unsigned char ip[4]; | ||
| 436 | { | ||
| 437 | unsigned int tmp[4]; | ||
| 438 | int num=0,c,ok=0; | ||
| 439 | |||
| 440 | tmp[0]=tmp[1]=tmp[2]=tmp[3]=0; | ||
| 441 | |||
| 442 | for (;;) | ||
| 443 | { | ||
| 444 | c= *(str++); | ||
| 445 | if ((c >= '0') && (c <= '9')) | ||
| 446 | { | ||
| 447 | ok=1; | ||
| 448 | tmp[num]=tmp[num]*10+c-'0'; | ||
| 449 | if (tmp[num] > 255) return(-1); | ||
| 450 | } | ||
| 451 | else if (c == '.') | ||
| 452 | { | ||
| 453 | if (!ok) return(-1); | ||
| 454 | if (num == 3) break; | ||
| 455 | num++; | ||
| 456 | ok=0; | ||
| 457 | } | ||
| 458 | else if ((num == 3) && ok) | ||
| 459 | break; | ||
| 460 | else | ||
| 461 | return(0); | ||
| 462 | } | ||
| 463 | ip[0]=tmp[0]; | ||
| 464 | ip[1]=tmp[1]; | ||
| 465 | ip[2]=tmp[2]; | ||
| 466 | ip[3]=tmp[3]; | ||
| 467 | return(1); | ||
| 468 | } | ||
| 469 | |||
| 470 | int BIO_get_accept_socket(host) | ||
| 471 | char *host; | ||
| 472 | { | ||
| 473 | int ret=0; | ||
| 474 | struct sockaddr_in server; | ||
| 475 | int s= -1; | ||
| 476 | unsigned char ip[4]; | ||
| 477 | short port; | ||
| 478 | char *str,*h,*p,*e; | ||
| 479 | unsigned long l; | ||
| 480 | |||
| 481 | if (!BIO_sock_init()) return(INVALID_SOCKET); | ||
| 482 | |||
| 483 | if ((str=BUF_strdup(host)) == NULL) return(INVALID_SOCKET); | ||
| 484 | |||
| 485 | h=p=NULL; | ||
| 486 | h=str; | ||
| 487 | for (e=str; *e; e++) | ||
| 488 | { | ||
| 489 | if (*e == ':') | ||
| 490 | { | ||
| 491 | p= &(e[1]); | ||
| 492 | *e='\0'; | ||
| 493 | } | ||
| 494 | else if (*e == '/') | ||
| 495 | { | ||
| 496 | *e='\0'; | ||
| 497 | break; | ||
| 498 | } | ||
| 499 | } | ||
| 500 | |||
| 501 | if (p == NULL) | ||
| 502 | { | ||
| 503 | p=h; | ||
| 504 | h="*"; | ||
| 505 | } | ||
| 506 | |||
| 507 | if (!BIO_get_port(p,&port)) return(INVALID_SOCKET); | ||
| 508 | |||
| 509 | memset((char *)&server,0,sizeof(server)); | ||
| 510 | server.sin_family=AF_INET; | ||
| 511 | server.sin_port=htons((unsigned short)port); | ||
| 512 | |||
| 513 | if (strcmp(h,"*") == 0) | ||
| 514 | server.sin_addr.s_addr=INADDR_ANY; | ||
| 515 | else | ||
| 516 | { | ||
| 517 | if (!BIO_get_host_ip(h,&(ip[0]))) return(INVALID_SOCKET); | ||
| 518 | l=(unsigned long) | ||
| 519 | ((unsigned long)ip[0]<<24L)| | ||
| 520 | ((unsigned long)ip[0]<<16L)| | ||
| 521 | ((unsigned long)ip[0]<< 8L)| | ||
| 522 | ((unsigned long)ip[0]); | ||
| 523 | server.sin_addr.s_addr=htonl(l); | ||
| 524 | } | ||
| 525 | |||
| 526 | s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL); | ||
| 527 | if (s == INVALID_SOCKET) | ||
| 528 | { | ||
| 529 | SYSerr(SYS_F_SOCKET,get_last_socket_error()); | ||
| 530 | ERR_add_error_data(3,"port='",host,"'"); | ||
| 531 | BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_CREATE_SOCKET); | ||
| 532 | goto err; | ||
| 533 | } | ||
| 534 | if (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1) | ||
| 535 | { | ||
| 536 | SYSerr(SYS_F_BIND,get_last_socket_error()); | ||
| 537 | ERR_add_error_data(3,"port='",host,"'"); | ||
| 538 | BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_BIND_SOCKET); | ||
| 539 | goto err; | ||
| 540 | } | ||
| 541 | if (listen(s,MAX_LISTEN) == -1) | ||
| 542 | { | ||
| 543 | SYSerr(SYS_F_BIND,get_last_socket_error()); | ||
| 544 | ERR_add_error_data(3,"port='",host,"'"); | ||
| 545 | BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_LISTEN_SOCKET); | ||
| 546 | goto err; | ||
| 547 | } | ||
| 548 | ret=1; | ||
| 549 | err: | ||
| 550 | if (str != NULL) Free(str); | ||
| 551 | if ((ret == 0) && (s != INVALID_SOCKET)) | ||
| 552 | { | ||
| 553 | #ifdef WINDOWS | ||
| 554 | closesocket(s); | ||
| 555 | #else | ||
| 556 | close(s); | ||
| 557 | #endif | ||
| 558 | s= INVALID_SOCKET; | ||
| 559 | } | ||
| 560 | return(s); | ||
| 561 | } | ||
| 562 | |||
| 563 | int BIO_accept(sock,addr) | ||
| 564 | int sock; | ||
| 565 | char **addr; | ||
| 566 | { | ||
| 567 | int ret=INVALID_SOCKET; | ||
| 568 | static struct sockaddr_in from; | ||
| 569 | unsigned long l; | ||
| 570 | short port; | ||
| 571 | int len; | ||
| 572 | char *p; | ||
| 573 | |||
| 574 | memset((char *)&from,0,sizeof(from)); | ||
| 575 | len=sizeof(from); | ||
| 576 | ret=accept(sock,(struct sockaddr *)&from,&len); | ||
| 577 | if (ret == INVALID_SOCKET) | ||
| 578 | { | ||
| 579 | SYSerr(SYS_F_ACCEPT,get_last_socket_error()); | ||
| 580 | BIOerr(BIO_F_BIO_ACCEPT,BIO_R_ACCEPT_ERROR); | ||
| 581 | goto end; | ||
| 582 | } | ||
| 583 | |||
| 584 | if (addr == NULL) goto end; | ||
| 585 | |||
| 586 | l=ntohl(from.sin_addr.s_addr); | ||
| 587 | port=ntohs(from.sin_port); | ||
| 588 | if (*addr == NULL) | ||
| 589 | { | ||
| 590 | if ((p=Malloc(24)) == NULL) | ||
| 591 | { | ||
| 592 | BIOerr(BIO_F_BIO_ACCEPT,ERR_R_MALLOC_FAILURE); | ||
| 593 | goto end; | ||
| 594 | } | ||
| 595 | *addr=p; | ||
| 596 | } | ||
| 597 | sprintf(*addr,"%d.%d.%d.%d:%d", | ||
| 598 | (unsigned char)(l>>24L)&0xff, | ||
| 599 | (unsigned char)(l>>16L)&0xff, | ||
| 600 | (unsigned char)(l>> 8L)&0xff, | ||
| 601 | (unsigned char)(l )&0xff, | ||
| 602 | port); | ||
| 603 | end: | ||
| 604 | return(ret); | ||
| 605 | } | ||
| 606 | |||
| 607 | int BIO_set_tcp_ndelay(s,on) | ||
| 608 | int s; | ||
| 609 | int on; | ||
| 610 | { | ||
| 611 | int ret=0; | ||
| 612 | #if defined(TCP_NODELAY) && (defined(IPPROTO_TCP) || defined(SOL_TCP)) | ||
| 613 | int opt; | ||
| 614 | |||
| 615 | #ifdef SOL_TCP | ||
| 616 | opt=SOL_TCP; | ||
| 617 | #else | ||
| 618 | #ifdef IPPROTO_TCP | ||
| 619 | opt=IPPROTO_TCP; | ||
| 620 | #endif | ||
| 621 | #endif | ||
| 622 | |||
| 623 | ret=setsockopt(s,opt,TCP_NODELAY,(char *)&on,sizeof(on)); | ||
| 624 | #endif | ||
| 625 | return(ret == 0); | ||
| 626 | } | ||
| 627 | #endif | ||
| 628 | |||
diff --git a/src/lib/libcrypto/bio/bf_buff.c b/src/lib/libcrypto/bio/bf_buff.c new file mode 100644 index 0000000000..7912b88473 --- /dev/null +++ b/src/lib/libcrypto/bio/bf_buff.c | |||
| @@ -0,0 +1,512 @@ | |||
| 1 | /* crypto/bio/bf_buff.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 <errno.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "bio.h" | ||
| 63 | #include "evp.h" | ||
| 64 | |||
| 65 | #ifndef NOPROTO | ||
| 66 | static int buffer_write(BIO *h,char *buf,int num); | ||
| 67 | static int buffer_read(BIO *h,char *buf,int size); | ||
| 68 | static int buffer_puts(BIO *h,char *str); | ||
| 69 | static int buffer_gets(BIO *h,char *str,int size); | ||
| 70 | static long buffer_ctrl(BIO *h,int cmd,long arg1,char *arg2); | ||
| 71 | static int buffer_new(BIO *h); | ||
| 72 | static int buffer_free(BIO *data); | ||
| 73 | #else | ||
| 74 | static int buffer_write(); | ||
| 75 | static int buffer_read(); | ||
| 76 | static int buffer_puts(); | ||
| 77 | static int buffer_gets(); | ||
| 78 | static long buffer_ctrl(); | ||
| 79 | static int buffer_new(); | ||
| 80 | static int buffer_free(); | ||
| 81 | #endif | ||
| 82 | |||
| 83 | #define DEFAULT_BUFFER_SIZE 1024 | ||
| 84 | |||
| 85 | static BIO_METHOD methods_buffer= | ||
| 86 | { | ||
| 87 | BIO_TYPE_BUFFER, | ||
| 88 | "buffer", | ||
| 89 | buffer_write, | ||
| 90 | buffer_read, | ||
| 91 | buffer_puts, | ||
| 92 | buffer_gets, | ||
| 93 | buffer_ctrl, | ||
| 94 | buffer_new, | ||
| 95 | buffer_free, | ||
| 96 | }; | ||
| 97 | |||
| 98 | BIO_METHOD *BIO_f_buffer() | ||
| 99 | { | ||
| 100 | return(&methods_buffer); | ||
| 101 | } | ||
| 102 | |||
| 103 | static int buffer_new(bi) | ||
| 104 | BIO *bi; | ||
| 105 | { | ||
| 106 | BIO_F_BUFFER_CTX *ctx; | ||
| 107 | |||
| 108 | ctx=(BIO_F_BUFFER_CTX *)Malloc(sizeof(BIO_F_BUFFER_CTX)); | ||
| 109 | if (ctx == NULL) return(0); | ||
| 110 | ctx->ibuf=(char *)Malloc(DEFAULT_BUFFER_SIZE); | ||
| 111 | if (ctx->ibuf == NULL) { Free(ctx); return(0); } | ||
| 112 | ctx->obuf=(char *)Malloc(DEFAULT_BUFFER_SIZE); | ||
| 113 | if (ctx->obuf == NULL) { Free(ctx->ibuf); Free(ctx); return(0); } | ||
| 114 | ctx->ibuf_size=DEFAULT_BUFFER_SIZE; | ||
| 115 | ctx->obuf_size=DEFAULT_BUFFER_SIZE; | ||
| 116 | ctx->ibuf_len=0; | ||
| 117 | ctx->ibuf_off=0; | ||
| 118 | ctx->obuf_len=0; | ||
| 119 | ctx->obuf_off=0; | ||
| 120 | |||
| 121 | bi->init=1; | ||
| 122 | bi->ptr=(char *)ctx; | ||
| 123 | bi->flags=0; | ||
| 124 | return(1); | ||
| 125 | } | ||
| 126 | |||
| 127 | static int buffer_free(a) | ||
| 128 | BIO *a; | ||
| 129 | { | ||
| 130 | BIO_F_BUFFER_CTX *b; | ||
| 131 | |||
| 132 | if (a == NULL) return(0); | ||
| 133 | b=(BIO_F_BUFFER_CTX *)a->ptr; | ||
| 134 | if (b->ibuf != NULL) Free(b->ibuf); | ||
| 135 | if (b->obuf != NULL) Free(b->obuf); | ||
| 136 | Free(a->ptr); | ||
| 137 | a->ptr=NULL; | ||
| 138 | a->init=0; | ||
| 139 | a->flags=0; | ||
| 140 | return(1); | ||
| 141 | } | ||
| 142 | |||
| 143 | static int buffer_read(b,out,outl) | ||
| 144 | BIO *b; | ||
| 145 | char *out; | ||
| 146 | int outl; | ||
| 147 | { | ||
| 148 | int i,num=0; | ||
| 149 | BIO_F_BUFFER_CTX *ctx; | ||
| 150 | |||
| 151 | if (out == NULL) return(0); | ||
| 152 | ctx=(BIO_F_BUFFER_CTX *)b->ptr; | ||
| 153 | |||
| 154 | if ((ctx == NULL) || (b->next_bio == NULL)) return(0); | ||
| 155 | num=0; | ||
| 156 | BIO_clear_retry_flags(b); | ||
| 157 | |||
| 158 | start: | ||
| 159 | i=ctx->ibuf_len; | ||
| 160 | /* If there is stuff left over, grab it */ | ||
| 161 | if (i != 0) | ||
| 162 | { | ||
| 163 | if (i > outl) i=outl; | ||
| 164 | memcpy(out,&(ctx->ibuf[ctx->ibuf_off]),i); | ||
| 165 | ctx->ibuf_off+=i; | ||
| 166 | ctx->ibuf_len-=i; | ||
| 167 | num+=i; | ||
| 168 | if (outl == i) return(num); | ||
| 169 | outl-=i; | ||
| 170 | out+=i; | ||
| 171 | } | ||
| 172 | |||
| 173 | /* We may have done a partial read. try to do more. | ||
| 174 | * We have nothing in the buffer. | ||
| 175 | * If we get an error and have read some data, just return it | ||
| 176 | * and let them retry to get the error again. | ||
| 177 | * copy direct to parent address space */ | ||
| 178 | if (outl > ctx->ibuf_size) | ||
| 179 | { | ||
| 180 | for (;;) | ||
| 181 | { | ||
| 182 | i=BIO_read(b->next_bio,out,outl); | ||
| 183 | if (i <= 0) | ||
| 184 | { | ||
| 185 | BIO_copy_next_retry(b); | ||
| 186 | if (i < 0) return((num > 0)?num:i); | ||
| 187 | if (i == 0) return(num); | ||
| 188 | } | ||
| 189 | num+=i; | ||
| 190 | if (outl == i) return(num); | ||
| 191 | out+=i; | ||
| 192 | outl-=i; | ||
| 193 | } | ||
| 194 | } | ||
| 195 | /* else */ | ||
| 196 | |||
| 197 | /* we are going to be doing some buffering */ | ||
| 198 | i=BIO_read(b->next_bio,ctx->ibuf,ctx->ibuf_size); | ||
| 199 | if (i <= 0) | ||
| 200 | { | ||
| 201 | BIO_copy_next_retry(b); | ||
| 202 | if (i < 0) return((num > 0)?num:i); | ||
| 203 | if (i == 0) return(num); | ||
| 204 | } | ||
| 205 | ctx->ibuf_off=0; | ||
| 206 | ctx->ibuf_len=i; | ||
| 207 | |||
| 208 | /* Lets re-read using ourselves :-) */ | ||
| 209 | goto start; | ||
| 210 | } | ||
| 211 | |||
| 212 | static int buffer_write(b,in,inl) | ||
| 213 | BIO *b; | ||
| 214 | char *in; | ||
| 215 | int inl; | ||
| 216 | { | ||
| 217 | int i,num=0; | ||
| 218 | BIO_F_BUFFER_CTX *ctx; | ||
| 219 | |||
| 220 | if ((in == NULL) || (inl <= 0)) return(0); | ||
| 221 | ctx=(BIO_F_BUFFER_CTX *)b->ptr; | ||
| 222 | if ((ctx == NULL) || (b->next_bio == NULL)) return(0); | ||
| 223 | |||
| 224 | BIO_clear_retry_flags(b); | ||
| 225 | start: | ||
| 226 | i=ctx->obuf_size-(ctx->obuf_len+ctx->obuf_off); | ||
| 227 | /* add to buffer and return */ | ||
| 228 | if (i >= inl) | ||
| 229 | { | ||
| 230 | memcpy(&(ctx->obuf[ctx->obuf_len]),in,inl); | ||
| 231 | ctx->obuf_len+=inl; | ||
| 232 | return(num+inl); | ||
| 233 | } | ||
| 234 | /* else */ | ||
| 235 | /* stuff already in buffer, so add to it first, then flush */ | ||
| 236 | if (ctx->obuf_len != 0) | ||
| 237 | { | ||
| 238 | if (i > 0) /* lets fill it up if we can */ | ||
| 239 | { | ||
| 240 | memcpy(&(ctx->obuf[ctx->obuf_len]),in,i); | ||
| 241 | in+=i; | ||
| 242 | inl-=i; | ||
| 243 | num+=i; | ||
| 244 | ctx->obuf_len+=i; | ||
| 245 | } | ||
| 246 | /* we now have a full buffer needing flushing */ | ||
| 247 | for (;;) | ||
| 248 | { | ||
| 249 | i=BIO_write(b->next_bio,&(ctx->obuf[ctx->obuf_off]), | ||
| 250 | ctx->obuf_len); | ||
| 251 | if (i <= 0) | ||
| 252 | { | ||
| 253 | BIO_copy_next_retry(b); | ||
| 254 | |||
| 255 | if (i < 0) return((num > 0)?num:i); | ||
| 256 | if (i == 0) return(num); | ||
| 257 | } | ||
| 258 | ctx->obuf_off+=i; | ||
| 259 | ctx->obuf_len-=i; | ||
| 260 | if (ctx->obuf_len == 0) break; | ||
| 261 | } | ||
| 262 | } | ||
| 263 | /* we only get here if the buffer has been flushed and we | ||
| 264 | * still have stuff to write */ | ||
| 265 | ctx->obuf_off=0; | ||
| 266 | |||
| 267 | /* we now have inl bytes to write */ | ||
| 268 | while (inl >= ctx->obuf_size) | ||
| 269 | { | ||
| 270 | i=BIO_write(b->next_bio,in,inl); | ||
| 271 | if (i <= 0) | ||
| 272 | { | ||
| 273 | BIO_copy_next_retry(b); | ||
| 274 | if (i < 0) return((num > 0)?num:i); | ||
| 275 | if (i == 0) return(num); | ||
| 276 | } | ||
| 277 | num+=i; | ||
| 278 | in+=i; | ||
| 279 | inl-=i; | ||
| 280 | if (inl == 0) return(num); | ||
| 281 | } | ||
| 282 | |||
| 283 | /* copy the rest into the buffer since we have only a small | ||
| 284 | * amount left */ | ||
| 285 | goto start; | ||
| 286 | } | ||
| 287 | |||
| 288 | static long buffer_ctrl(b,cmd,num,ptr) | ||
| 289 | BIO *b; | ||
| 290 | int cmd; | ||
| 291 | long num; | ||
| 292 | char *ptr; | ||
| 293 | { | ||
| 294 | BIO *dbio; | ||
| 295 | BIO_F_BUFFER_CTX *ctx; | ||
| 296 | long ret=1; | ||
| 297 | char *p1,*p2; | ||
| 298 | int r,i,*ip; | ||
| 299 | int ibs,obs; | ||
| 300 | |||
| 301 | ctx=(BIO_F_BUFFER_CTX *)b->ptr; | ||
| 302 | |||
| 303 | switch (cmd) | ||
| 304 | { | ||
| 305 | case BIO_CTRL_RESET: | ||
| 306 | ctx->ibuf_off=0; | ||
| 307 | ctx->ibuf_len=0; | ||
| 308 | ctx->obuf_off=0; | ||
| 309 | ctx->obuf_len=0; | ||
| 310 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 311 | break; | ||
| 312 | case BIO_CTRL_INFO: | ||
| 313 | ret=(long)ctx->obuf_len; | ||
| 314 | break; | ||
| 315 | case BIO_C_GET_BUFF_NUM_LINES: | ||
| 316 | ret=0; | ||
| 317 | p1=ctx->ibuf; | ||
| 318 | for (i=ctx->ibuf_off; i<ctx->ibuf_len; i++) | ||
| 319 | { | ||
| 320 | if (p1[i] == '\n') ret++; | ||
| 321 | } | ||
| 322 | break; | ||
| 323 | case BIO_CTRL_WPENDING: | ||
| 324 | ret=(long)ctx->obuf_len; | ||
| 325 | if (ret == 0) | ||
| 326 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 327 | break; | ||
| 328 | case BIO_CTRL_PENDING: | ||
| 329 | ret=(long)ctx->ibuf_len; | ||
| 330 | if (ret == 0) | ||
| 331 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 332 | break; | ||
| 333 | case BIO_C_SET_BUFF_READ_DATA: | ||
| 334 | if (num > ctx->ibuf_size) | ||
| 335 | { | ||
| 336 | p1=Malloc((int)num); | ||
| 337 | if (p1 == NULL) goto malloc_error; | ||
| 338 | if (ctx->ibuf != NULL) Free(ctx->ibuf); | ||
| 339 | ctx->ibuf=p1; | ||
| 340 | } | ||
| 341 | ctx->ibuf_off=0; | ||
| 342 | ctx->ibuf_len=(int)num; | ||
| 343 | memcpy(ctx->ibuf,ptr,(int)num); | ||
| 344 | ret=1; | ||
| 345 | break; | ||
| 346 | case BIO_C_SET_BUFF_SIZE: | ||
| 347 | if (ptr != NULL) | ||
| 348 | { | ||
| 349 | ip=(int *)ptr; | ||
| 350 | if (*ip == 0) | ||
| 351 | { | ||
| 352 | ibs=(int)num; | ||
| 353 | obs=ctx->obuf_size; | ||
| 354 | } | ||
| 355 | else /* if (*ip == 1) */ | ||
| 356 | { | ||
| 357 | ibs=ctx->ibuf_size; | ||
| 358 | obs=(int)num; | ||
| 359 | } | ||
| 360 | } | ||
| 361 | else | ||
| 362 | { | ||
| 363 | ibs=(int)num; | ||
| 364 | obs=(int)num; | ||
| 365 | } | ||
| 366 | p1=ctx->ibuf; | ||
| 367 | p2=ctx->obuf; | ||
| 368 | if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size)) | ||
| 369 | { | ||
| 370 | p1=(char *)Malloc((int)num); | ||
| 371 | if (p1 == NULL) goto malloc_error; | ||
| 372 | } | ||
| 373 | if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size)) | ||
| 374 | { | ||
| 375 | p2=(char *)Malloc((int)num); | ||
| 376 | if (p2 == NULL) | ||
| 377 | { | ||
| 378 | if (p1 != ctx->ibuf) Free(p1); | ||
| 379 | goto malloc_error; | ||
| 380 | } | ||
| 381 | } | ||
| 382 | if (ctx->ibuf != p1) | ||
| 383 | { | ||
| 384 | Free(ctx->ibuf); | ||
| 385 | ctx->ibuf=p1; | ||
| 386 | ctx->ibuf_off=0; | ||
| 387 | ctx->ibuf_len=0; | ||
| 388 | ctx->ibuf_size=ibs; | ||
| 389 | } | ||
| 390 | if (ctx->obuf != p2) | ||
| 391 | { | ||
| 392 | Free(ctx->obuf); | ||
| 393 | ctx->obuf=p2; | ||
| 394 | ctx->obuf_off=0; | ||
| 395 | ctx->obuf_len=0; | ||
| 396 | ctx->obuf_size=obs; | ||
| 397 | } | ||
| 398 | break; | ||
| 399 | case BIO_C_DO_STATE_MACHINE: | ||
| 400 | BIO_clear_retry_flags(b); | ||
| 401 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 402 | BIO_copy_next_retry(b); | ||
| 403 | break; | ||
| 404 | |||
| 405 | case BIO_CTRL_FLUSH: | ||
| 406 | if (ctx->obuf_len <= 0) | ||
| 407 | { | ||
| 408 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 409 | break; | ||
| 410 | } | ||
| 411 | |||
| 412 | for (;;) | ||
| 413 | { | ||
| 414 | BIO_clear_retry_flags(b); | ||
| 415 | if (ctx->obuf_len > ctx->obuf_off) | ||
| 416 | { | ||
| 417 | r=BIO_write(b->next_bio, | ||
| 418 | &(ctx->obuf[ctx->obuf_off]), | ||
| 419 | ctx->obuf_len-ctx->obuf_off); | ||
| 420 | #if 0 | ||
| 421 | fprintf(stderr,"FLUSH [%3d] %3d -> %3d\n",ctx->obuf_off,ctx->obuf_len-ctx->obuf_off,r); | ||
| 422 | #endif | ||
| 423 | BIO_copy_next_retry(b); | ||
| 424 | if (r <= 0) return((long)r); | ||
| 425 | ctx->obuf_off+=r; | ||
| 426 | } | ||
| 427 | else | ||
| 428 | { | ||
| 429 | ctx->obuf_len=0; | ||
| 430 | ctx->obuf_off=0; | ||
| 431 | ret=1; | ||
| 432 | break; | ||
| 433 | } | ||
| 434 | } | ||
| 435 | break; | ||
| 436 | case BIO_CTRL_DUP: | ||
| 437 | dbio=(BIO *)ptr; | ||
| 438 | if ( !BIO_set_read_buffer_size(dbio,ctx->ibuf_size) || | ||
| 439 | !BIO_set_write_buffer_size(dbio,ctx->obuf_size)) | ||
| 440 | ret=0; | ||
| 441 | break; | ||
| 442 | default: | ||
| 443 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 444 | break; | ||
| 445 | } | ||
| 446 | return(ret); | ||
| 447 | malloc_error: | ||
| 448 | BIOerr(BIO_F_BUFFER_CTRL,ERR_R_MALLOC_FAILURE); | ||
| 449 | return(0); | ||
| 450 | } | ||
| 451 | |||
| 452 | static int buffer_gets(b,buf,size) | ||
| 453 | BIO *b; | ||
| 454 | char *buf; | ||
| 455 | int size; | ||
| 456 | { | ||
| 457 | BIO_F_BUFFER_CTX *ctx; | ||
| 458 | int num=0,i,flag; | ||
| 459 | char *p; | ||
| 460 | |||
| 461 | ctx=(BIO_F_BUFFER_CTX *)b->ptr; | ||
| 462 | size--; /* reserve space for a '\0' */ | ||
| 463 | BIO_clear_retry_flags(b); | ||
| 464 | |||
| 465 | for (;;) | ||
| 466 | { | ||
| 467 | if (ctx->ibuf_len > 0) | ||
| 468 | { | ||
| 469 | p= &(ctx->ibuf[ctx->ibuf_off]); | ||
| 470 | flag=0; | ||
| 471 | for (i=0; (i<ctx->ibuf_len) && (i<size); i++) | ||
| 472 | { | ||
| 473 | *(buf++)=p[i]; | ||
| 474 | if (p[i] == '\n') | ||
| 475 | { | ||
| 476 | flag=1; | ||
| 477 | i++; | ||
| 478 | break; | ||
| 479 | } | ||
| 480 | } | ||
| 481 | num+=i; | ||
| 482 | size-=i; | ||
| 483 | ctx->ibuf_len-=i; | ||
| 484 | ctx->ibuf_off+=i; | ||
| 485 | if ((flag) || (i == size)) | ||
| 486 | { | ||
| 487 | *buf='\0'; | ||
| 488 | return(num); | ||
| 489 | } | ||
| 490 | } | ||
| 491 | else /* read another chunk */ | ||
| 492 | { | ||
| 493 | i=BIO_read(b->next_bio,ctx->ibuf,ctx->ibuf_size); | ||
| 494 | if (i <= 0) | ||
| 495 | { | ||
| 496 | BIO_copy_next_retry(b); | ||
| 497 | if (i < 0) return((num > 0)?num:i); | ||
| 498 | if (i == 0) return(num); | ||
| 499 | } | ||
| 500 | ctx->ibuf_len=i; | ||
| 501 | ctx->ibuf_off=0; | ||
| 502 | } | ||
| 503 | } | ||
| 504 | } | ||
| 505 | |||
| 506 | static int buffer_puts(b,str) | ||
| 507 | BIO *b; | ||
| 508 | char *str; | ||
| 509 | { | ||
| 510 | return(BIO_write(b,str,strlen(str))); | ||
| 511 | } | ||
| 512 | |||
diff --git a/src/lib/libcrypto/bio/bf_nbio.c b/src/lib/libcrypto/bio/bf_nbio.c new file mode 100644 index 0000000000..034b3024df --- /dev/null +++ b/src/lib/libcrypto/bio/bf_nbio.c | |||
| @@ -0,0 +1,268 @@ | |||
| 1 | /* crypto/bio/bf_nbio.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 <errno.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "rand.h" | ||
| 63 | #include "bio.h" | ||
| 64 | #include "evp.h" | ||
| 65 | |||
| 66 | /* BIO_put and BIO_get both add to the digest, | ||
| 67 | * BIO_gets returns the digest */ | ||
| 68 | |||
| 69 | #ifndef NOPROTO | ||
| 70 | static int nbiof_write(BIO *h,char *buf,int num); | ||
| 71 | static int nbiof_read(BIO *h,char *buf,int size); | ||
| 72 | static int nbiof_puts(BIO *h,char *str); | ||
| 73 | static int nbiof_gets(BIO *h,char *str,int size); | ||
| 74 | static long nbiof_ctrl(BIO *h,int cmd,long arg1,char *arg2); | ||
| 75 | static int nbiof_new(BIO *h); | ||
| 76 | static int nbiof_free(BIO *data); | ||
| 77 | #else | ||
| 78 | static int nbiof_write(); | ||
| 79 | static int nbiof_read(); | ||
| 80 | static int nbiof_puts(); | ||
| 81 | static int nbiof_gets(); | ||
| 82 | static long nbiof_ctrl(); | ||
| 83 | static int nbiof_new(); | ||
| 84 | static int nbiof_free(); | ||
| 85 | #endif | ||
| 86 | |||
| 87 | typedef struct nbio_test_st | ||
| 88 | { | ||
| 89 | /* only set if we sent a 'should retry' error */ | ||
| 90 | int lrn; | ||
| 91 | int lwn; | ||
| 92 | } NBIO_TEST; | ||
| 93 | |||
| 94 | static BIO_METHOD methods_nbiof= | ||
| 95 | { | ||
| 96 | BIO_TYPE_NBIO_TEST, | ||
| 97 | "non-blocking IO test filter", | ||
| 98 | nbiof_write, | ||
| 99 | nbiof_read, | ||
| 100 | nbiof_puts, | ||
| 101 | nbiof_gets, | ||
| 102 | nbiof_ctrl, | ||
| 103 | nbiof_new, | ||
| 104 | nbiof_free, | ||
| 105 | }; | ||
| 106 | |||
| 107 | BIO_METHOD *BIO_f_nbio_test() | ||
| 108 | { | ||
| 109 | return(&methods_nbiof); | ||
| 110 | } | ||
| 111 | |||
| 112 | static int nbiof_new(bi) | ||
| 113 | BIO *bi; | ||
| 114 | { | ||
| 115 | NBIO_TEST *nt; | ||
| 116 | |||
| 117 | nt=(NBIO_TEST *)Malloc(sizeof(NBIO_TEST)); | ||
| 118 | nt->lrn= -1; | ||
| 119 | nt->lwn= -1; | ||
| 120 | bi->ptr=(char *)nt; | ||
| 121 | bi->init=1; | ||
| 122 | bi->flags=0; | ||
| 123 | return(1); | ||
| 124 | } | ||
| 125 | |||
| 126 | static int nbiof_free(a) | ||
| 127 | BIO *a; | ||
| 128 | { | ||
| 129 | if (a == NULL) return(0); | ||
| 130 | if (a->ptr != NULL) | ||
| 131 | Free(a->ptr); | ||
| 132 | a->ptr=NULL; | ||
| 133 | a->init=0; | ||
| 134 | a->flags=0; | ||
| 135 | return(1); | ||
| 136 | } | ||
| 137 | |||
| 138 | static int nbiof_read(b,out,outl) | ||
| 139 | BIO *b; | ||
| 140 | char *out; | ||
| 141 | int outl; | ||
| 142 | { | ||
| 143 | NBIO_TEST *nt; | ||
| 144 | int ret=0; | ||
| 145 | #if 0 | ||
| 146 | int num; | ||
| 147 | unsigned char n; | ||
| 148 | #endif | ||
| 149 | |||
| 150 | if (out == NULL) return(0); | ||
| 151 | if (b->next_bio == NULL) return(0); | ||
| 152 | nt=(NBIO_TEST *)b->ptr; | ||
| 153 | |||
| 154 | BIO_clear_retry_flags(b); | ||
| 155 | #if 0 | ||
| 156 | RAND_bytes(&n,1); | ||
| 157 | num=(n&0x07); | ||
| 158 | |||
| 159 | if (outl > num) outl=num; | ||
| 160 | |||
| 161 | if (num == 0) | ||
| 162 | { | ||
| 163 | ret= -1; | ||
| 164 | BIO_set_retry_read(b); | ||
| 165 | } | ||
| 166 | else | ||
| 167 | #endif | ||
| 168 | { | ||
| 169 | ret=BIO_read(b->next_bio,out,outl); | ||
| 170 | if (ret < 0) | ||
| 171 | BIO_copy_next_retry(b); | ||
| 172 | } | ||
| 173 | return(ret); | ||
| 174 | } | ||
| 175 | |||
| 176 | static int nbiof_write(b,in,inl) | ||
| 177 | BIO *b; | ||
| 178 | char *in; | ||
| 179 | int inl; | ||
| 180 | { | ||
| 181 | NBIO_TEST *nt; | ||
| 182 | int ret=0; | ||
| 183 | int num; | ||
| 184 | unsigned char n; | ||
| 185 | |||
| 186 | if ((in == NULL) || (inl <= 0)) return(0); | ||
| 187 | if (b->next_bio == NULL) return(0); | ||
| 188 | nt=(NBIO_TEST *)b->ptr; | ||
| 189 | |||
| 190 | BIO_clear_retry_flags(b); | ||
| 191 | |||
| 192 | #if 1 | ||
| 193 | if (nt->lwn > 0) | ||
| 194 | { | ||
| 195 | num=nt->lwn; | ||
| 196 | nt->lwn=0; | ||
| 197 | } | ||
| 198 | else | ||
| 199 | { | ||
| 200 | RAND_bytes(&n,1); | ||
| 201 | num=(n&7); | ||
| 202 | } | ||
| 203 | |||
| 204 | if (inl > num) inl=num; | ||
| 205 | |||
| 206 | if (num == 0) | ||
| 207 | { | ||
| 208 | ret= -1; | ||
| 209 | BIO_set_retry_write(b); | ||
| 210 | } | ||
| 211 | else | ||
| 212 | #endif | ||
| 213 | { | ||
| 214 | ret=BIO_write(b->next_bio,in,inl); | ||
| 215 | if (ret < 0) | ||
| 216 | { | ||
| 217 | BIO_copy_next_retry(b); | ||
| 218 | nt->lwn=inl; | ||
| 219 | } | ||
| 220 | } | ||
| 221 | return(ret); | ||
| 222 | } | ||
| 223 | |||
| 224 | static long nbiof_ctrl(b,cmd,num,ptr) | ||
| 225 | BIO *b; | ||
| 226 | int cmd; | ||
| 227 | long num; | ||
| 228 | char *ptr; | ||
| 229 | { | ||
| 230 | long ret; | ||
| 231 | |||
| 232 | if (b->next_bio == NULL) return(0); | ||
| 233 | switch (cmd) | ||
| 234 | { | ||
| 235 | case BIO_C_DO_STATE_MACHINE: | ||
| 236 | BIO_clear_retry_flags(b); | ||
| 237 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 238 | BIO_copy_next_retry(b); | ||
| 239 | break; | ||
| 240 | case BIO_CTRL_DUP: | ||
| 241 | ret=0L; | ||
| 242 | break; | ||
| 243 | default: | ||
| 244 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 245 | break; | ||
| 246 | } | ||
| 247 | return(ret); | ||
| 248 | } | ||
| 249 | |||
| 250 | static int nbiof_gets(bp,buf,size) | ||
| 251 | BIO *bp; | ||
| 252 | char *buf; | ||
| 253 | int size; | ||
| 254 | { | ||
| 255 | if (bp->next_bio == NULL) return(0); | ||
| 256 | return(BIO_gets(bp->next_bio,buf,size)); | ||
| 257 | } | ||
| 258 | |||
| 259 | |||
| 260 | static int nbiof_puts(bp,str) | ||
| 261 | BIO *bp; | ||
| 262 | char *str; | ||
| 263 | { | ||
| 264 | if (bp->next_bio == NULL) return(0); | ||
| 265 | return(BIO_puts(bp->next_bio,str)); | ||
| 266 | } | ||
| 267 | |||
| 268 | |||
diff --git a/src/lib/libcrypto/bio/bf_null.c b/src/lib/libcrypto/bio/bf_null.c new file mode 100644 index 0000000000..a47a65741a --- /dev/null +++ b/src/lib/libcrypto/bio/bf_null.c | |||
| @@ -0,0 +1,196 @@ | |||
| 1 | /* crypto/bio/bf_null.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 <errno.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "bio.h" | ||
| 63 | #include "evp.h" | ||
| 64 | |||
| 65 | /* BIO_put and BIO_get both add to the digest, | ||
| 66 | * BIO_gets returns the digest */ | ||
| 67 | |||
| 68 | #ifndef NOPROTO | ||
| 69 | static int nullf_write(BIO *h,char *buf,int num); | ||
| 70 | static int nullf_read(BIO *h,char *buf,int size); | ||
| 71 | static int nullf_puts(BIO *h,char *str); | ||
| 72 | static int nullf_gets(BIO *h,char *str,int size); | ||
| 73 | static long nullf_ctrl(BIO *h,int cmd,long arg1,char *arg2); | ||
| 74 | static int nullf_new(BIO *h); | ||
| 75 | static int nullf_free(BIO *data); | ||
| 76 | #else | ||
| 77 | static int nullf_write(); | ||
| 78 | static int nullf_read(); | ||
| 79 | static int nullf_puts(); | ||
| 80 | static int nullf_gets(); | ||
| 81 | static long nullf_ctrl(); | ||
| 82 | static int nullf_new(); | ||
| 83 | static int nullf_free(); | ||
| 84 | #endif | ||
| 85 | |||
| 86 | static BIO_METHOD methods_nullf= | ||
| 87 | { | ||
| 88 | BIO_TYPE_NULL_FILTER, | ||
| 89 | "NULL filter", | ||
| 90 | nullf_write, | ||
| 91 | nullf_read, | ||
| 92 | nullf_puts, | ||
| 93 | nullf_gets, | ||
| 94 | nullf_ctrl, | ||
| 95 | nullf_new, | ||
| 96 | nullf_free, | ||
| 97 | }; | ||
| 98 | |||
| 99 | BIO_METHOD *BIO_f_null() | ||
| 100 | { | ||
| 101 | return(&methods_nullf); | ||
| 102 | } | ||
| 103 | |||
| 104 | static int nullf_new(bi) | ||
| 105 | BIO *bi; | ||
| 106 | { | ||
| 107 | bi->init=1; | ||
| 108 | bi->ptr=NULL; | ||
| 109 | bi->flags=0; | ||
| 110 | return(1); | ||
| 111 | } | ||
| 112 | |||
| 113 | static int nullf_free(a) | ||
| 114 | BIO *a; | ||
| 115 | { | ||
| 116 | if (a == NULL) return(0); | ||
| 117 | /* a->ptr=NULL; | ||
| 118 | a->init=0; | ||
| 119 | a->flags=0;*/ | ||
| 120 | return(1); | ||
| 121 | } | ||
| 122 | |||
| 123 | static int nullf_read(b,out,outl) | ||
| 124 | BIO *b; | ||
| 125 | char *out; | ||
| 126 | int outl; | ||
| 127 | { | ||
| 128 | int ret=0; | ||
| 129 | |||
| 130 | if (out == NULL) return(0); | ||
| 131 | if (b->next_bio == NULL) return(0); | ||
| 132 | ret=BIO_read(b->next_bio,out,outl); | ||
| 133 | BIO_clear_retry_flags(b); | ||
| 134 | BIO_copy_next_retry(b); | ||
| 135 | return(ret); | ||
| 136 | } | ||
| 137 | |||
| 138 | static int nullf_write(b,in,inl) | ||
| 139 | BIO *b; | ||
| 140 | char *in; | ||
| 141 | int inl; | ||
| 142 | { | ||
| 143 | int ret=0; | ||
| 144 | |||
| 145 | if ((in == NULL) || (inl <= 0)) return(0); | ||
| 146 | if (b->next_bio == NULL) return(0); | ||
| 147 | ret=BIO_write(b->next_bio,in,inl); | ||
| 148 | BIO_clear_retry_flags(b); | ||
| 149 | BIO_copy_next_retry(b); | ||
| 150 | return(ret); | ||
| 151 | } | ||
| 152 | |||
| 153 | static long nullf_ctrl(b,cmd,num,ptr) | ||
| 154 | BIO *b; | ||
| 155 | int cmd; | ||
| 156 | long num; | ||
| 157 | char *ptr; | ||
| 158 | { | ||
| 159 | long ret; | ||
| 160 | |||
| 161 | if (b->next_bio == NULL) return(0); | ||
| 162 | switch(cmd) | ||
| 163 | { | ||
| 164 | case BIO_C_DO_STATE_MACHINE: | ||
| 165 | BIO_clear_retry_flags(b); | ||
| 166 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 167 | BIO_copy_next_retry(b); | ||
| 168 | break; | ||
| 169 | case BIO_CTRL_DUP: | ||
| 170 | ret=0L; | ||
| 171 | break; | ||
| 172 | default: | ||
| 173 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 174 | } | ||
| 175 | return(ret); | ||
| 176 | } | ||
| 177 | |||
| 178 | static int nullf_gets(bp,buf,size) | ||
| 179 | BIO *bp; | ||
| 180 | char *buf; | ||
| 181 | int size; | ||
| 182 | { | ||
| 183 | if (bp->next_bio == NULL) return(0); | ||
| 184 | return(BIO_gets(bp->next_bio,buf,size)); | ||
| 185 | } | ||
| 186 | |||
| 187 | |||
| 188 | static int nullf_puts(bp,str) | ||
| 189 | BIO *bp; | ||
| 190 | char *str; | ||
| 191 | { | ||
| 192 | if (bp->next_bio == NULL) return(0); | ||
| 193 | return(BIO_puts(bp->next_bio,str)); | ||
| 194 | } | ||
| 195 | |||
| 196 | |||
diff --git a/src/lib/libcrypto/bio/bio.h b/src/lib/libcrypto/bio/bio.h new file mode 100644 index 0000000000..300b330e00 --- /dev/null +++ b/src/lib/libcrypto/bio/bio.h | |||
| @@ -0,0 +1,688 @@ | |||
| 1 | /* crypto/bio/bio.h */ | ||
| 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 | #ifndef HEADER_BIO_H | ||
| 60 | #define HEADER_BIO_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #include "crypto.h" | ||
| 67 | |||
| 68 | /* These are the 'types' of BIOs */ | ||
| 69 | #define BIO_TYPE_NONE 0 | ||
| 70 | #define BIO_TYPE_MEM (1|0x0400) | ||
| 71 | #define BIO_TYPE_FILE (2|0x0400) | ||
| 72 | |||
| 73 | #define BIO_TYPE_FD (4|0x0400|0x0100) | ||
| 74 | #define BIO_TYPE_SOCKET (5|0x0400|0x0100) | ||
| 75 | #define BIO_TYPE_NULL (6|0x0400) | ||
| 76 | #define BIO_TYPE_SSL (7|0x0200) | ||
| 77 | #define BIO_TYPE_MD (8|0x0200) /* pasive filter */ | ||
| 78 | #define BIO_TYPE_BUFFER (9|0x0200) /* filter */ | ||
| 79 | #define BIO_TYPE_CIPHER (10|0x0200) /* filter */ | ||
| 80 | #define BIO_TYPE_BASE64 (11|0x0200) /* filter */ | ||
| 81 | #define BIO_TYPE_CONNECT (12|0x0400|0x0100) /* socket - connect */ | ||
| 82 | #define BIO_TYPE_ACCEPT (13|0x0400|0x0100) /* socket for accept */ | ||
| 83 | #define BIO_TYPE_PROXY_CLIENT (14|0x0200) /* client proxy BIO */ | ||
| 84 | #define BIO_TYPE_PROXY_SERVER (15|0x0200) /* server proxy BIO */ | ||
| 85 | #define BIO_TYPE_NBIO_TEST (16|0x0200) /* server proxy BIO */ | ||
| 86 | #define BIO_TYPE_NULL_FILTER (17|0x0200) | ||
| 87 | |||
| 88 | #define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */ | ||
| 89 | #define BIO_TYPE_FILTER 0x0200 | ||
| 90 | #define BIO_TYPE_SOURCE_SINK 0x0400 | ||
| 91 | |||
| 92 | /* BIO_FILENAME_READ|BIO_CLOSE to open or close on free. | ||
| 93 | * BIO_set_fp(in,stdin,BIO_NOCLOSE); */ | ||
| 94 | #define BIO_NOCLOSE 0x00 | ||
| 95 | #define BIO_CLOSE 0x01 | ||
| 96 | |||
| 97 | /* These are used in the following macros and are passed to | ||
| 98 | * BIO_ctrl() */ | ||
| 99 | #define BIO_CTRL_RESET 1 /* opt - rewind/zero etc */ | ||
| 100 | #define BIO_CTRL_EOF 2 /* opt - are we at the eof */ | ||
| 101 | #define BIO_CTRL_INFO 3 /* opt - extra tit-bits */ | ||
| 102 | #define BIO_CTRL_SET 4 /* man - set the 'IO' type */ | ||
| 103 | #define BIO_CTRL_GET 5 /* man - get the 'IO' type */ | ||
| 104 | #define BIO_CTRL_PUSH 6 /* opt - internal, used to signify change */ | ||
| 105 | #define BIO_CTRL_POP 7 /* opt - internal, used to signify change */ | ||
| 106 | #define BIO_CTRL_GET_CLOSE 8 /* man - set the 'close' on free */ | ||
| 107 | #define BIO_CTRL_SET_CLOSE 9 /* man - set the 'close' on free */ | ||
| 108 | #define BIO_CTRL_PENDING 10 /* opt - is their more data buffered */ | ||
| 109 | #define BIO_CTRL_FLUSH 11 /* opt - 'flush' buffered output */ | ||
| 110 | #define BIO_CTRL_DUP 12 /* man - extra stuff for 'duped' BIO */ | ||
| 111 | #define BIO_CTRL_WPENDING 13 /* opt - number of bytes still to write */ | ||
| 112 | /* callback is int cb(BIO *bio,state,ret); */ | ||
| 113 | #define BIO_CTRL_SET_CALLBACK 14 /* opt - set callback function */ | ||
| 114 | #define BIO_CTRL_GET_CALLBACK 15 /* opt - set callback function */ | ||
| 115 | |||
| 116 | #define BIO_CTRL_SET_FILENAME 30 /* BIO_s_file special */ | ||
| 117 | |||
| 118 | /* modifiers */ | ||
| 119 | #define BIO_FP_READ 0x02 | ||
| 120 | #define BIO_FP_WRITE 0x04 | ||
| 121 | #define BIO_FP_APPEND 0x08 | ||
| 122 | #define BIO_FP_TEXT 0x10 | ||
| 123 | |||
| 124 | #define BIO_FLAGS_READ 0x01 | ||
| 125 | #define BIO_FLAGS_WRITE 0x02 | ||
| 126 | #define BIO_FLAGS_IO_SPECIAL 0x04 | ||
| 127 | #define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL) | ||
| 128 | #define BIO_FLAGS_SHOULD_RETRY 0x08 | ||
| 129 | |||
| 130 | /* Used in BIO_gethostbyname() */ | ||
| 131 | #define BIO_GHBN_CTRL_HITS 1 | ||
| 132 | #define BIO_GHBN_CTRL_MISSES 2 | ||
| 133 | #define BIO_GHBN_CTRL_CACHE_SIZE 3 | ||
| 134 | #define BIO_GHBN_CTRL_GET_ENTRY 4 | ||
| 135 | #define BIO_GHBN_CTRL_FLUSH 5 | ||
| 136 | |||
| 137 | /* Mostly used in the SSL BIO */ | ||
| 138 | /* Not used anymore | ||
| 139 | * #define BIO_FLAGS_PROTOCOL_DELAYED_READ 0x10 | ||
| 140 | * #define BIO_FLAGS_PROTOCOL_DELAYED_WRITE 0x20 | ||
| 141 | * #define BIO_FLAGS_PROTOCOL_STARTUP 0x40 | ||
| 142 | */ | ||
| 143 | |||
| 144 | #define BIO_FLAGS_BASE64_NO_NL 0x100 | ||
| 145 | |||
| 146 | #define BIO_set_flags(b,f) ((b)->flags|=(f)) | ||
| 147 | #define BIO_get_flags(b) ((b)->flags) | ||
| 148 | #define BIO_set_retry_special(b) \ | ||
| 149 | ((b)->flags|=(BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY)) | ||
| 150 | #define BIO_set_retry_read(b) \ | ||
| 151 | ((b)->flags|=(BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY)) | ||
| 152 | #define BIO_set_retry_write(b) \ | ||
| 153 | ((b)->flags|=(BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY)) | ||
| 154 | |||
| 155 | /* These are normally used internally in BIOs */ | ||
| 156 | #define BIO_clear_flags(b,f) ((b)->flags&= ~(f)) | ||
| 157 | #define BIO_clear_retry_flags(b) \ | ||
| 158 | ((b)->flags&= ~(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY)) | ||
| 159 | #define BIO_get_retry_flags(b) \ | ||
| 160 | ((b)->flags&(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY)) | ||
| 161 | |||
| 162 | /* These shouldbe used by the application to tell why we should retry */ | ||
| 163 | #define BIO_should_read(a) ((a)->flags & BIO_FLAGS_READ) | ||
| 164 | #define BIO_should_write(a) ((a)->flags & BIO_FLAGS_WRITE) | ||
| 165 | #define BIO_should_io_special(a) ((a)->flags & BIO_FLAGS_IO_SPECIAL) | ||
| 166 | #define BIO_retry_type(a) ((a)->flags & BIO_FLAGS_RWS) | ||
| 167 | #define BIO_should_retry(a) ((a)->flags & BIO_FLAGS_SHOULD_RETRY) | ||
| 168 | |||
| 169 | /* The next two are used in conjunction with the | ||
| 170 | * BIO_should_io_special() condition. After this returns true, | ||
| 171 | * BIO *BIO_get_retry_BIO(BIO *bio, int *reason); will walk the BIO | ||
| 172 | * stack and return the 'reason' for the special and the offending BIO. | ||
| 173 | * Given a BIO, BIO_get_retry_reason(bio) will return the code. */ | ||
| 174 | /* Returned from the SSL bio when the certificate retrieval code had an error */ | ||
| 175 | #define BIO_RR_SSL_X509_LOOKUP 0x01 | ||
| 176 | /* Returned from the connect BIO when a connect would have blocked */ | ||
| 177 | #define BIO_RR_CONNECT 0x02 | ||
| 178 | |||
| 179 | /* These are passed by the BIO callback */ | ||
| 180 | #define BIO_CB_FREE 0x01 | ||
| 181 | #define BIO_CB_READ 0x02 | ||
| 182 | #define BIO_CB_WRITE 0x03 | ||
| 183 | #define BIO_CB_PUTS 0x04 | ||
| 184 | #define BIO_CB_GETS 0x05 | ||
| 185 | #define BIO_CB_CTRL 0x06 | ||
| 186 | |||
| 187 | /* The callback is called before and after the underling operation, | ||
| 188 | * The BIO_CB_RETURN flag indicates if it is after the call */ | ||
| 189 | #define BIO_CB_RETURN 0x80 | ||
| 190 | #define BIO_CB_return(a) ((a)|BIO_CB_RETURN)) | ||
| 191 | #define BIO_cb_pre(a) (!((a)&BIO_CB_RETURN)) | ||
| 192 | #define BIO_cb_post(a) ((a)&BIO_CB_RETURN) | ||
| 193 | |||
| 194 | #define BIO_set_callback(b,cb) ((b)->callback=(cb)) | ||
| 195 | #define BIO_set_callback_arg(b,arg) ((b)->cb_arg=(char *)(arg)) | ||
| 196 | #define BIO_get_callback_arg(b) ((b)->cb_arg) | ||
| 197 | #define BIO_get_callback(b) ((b)->callback) | ||
| 198 | #define BIO_method_name(b) ((b)->method->name) | ||
| 199 | #define BIO_method_type(b) ((b)->method->type) | ||
| 200 | |||
| 201 | #ifndef WIN16 | ||
| 202 | typedef struct bio_method_st | ||
| 203 | { | ||
| 204 | int type; | ||
| 205 | char *name; | ||
| 206 | int (*bwrite)(); | ||
| 207 | int (*bread)(); | ||
| 208 | int (*bputs)(); | ||
| 209 | int (*bgets)(); | ||
| 210 | long (*ctrl)(); | ||
| 211 | int (*create)(); | ||
| 212 | int (*destroy)(); | ||
| 213 | } BIO_METHOD; | ||
| 214 | #else | ||
| 215 | typedef struct bio_method_st | ||
| 216 | { | ||
| 217 | int type; | ||
| 218 | char *name; | ||
| 219 | int (_far *bwrite)(); | ||
| 220 | int (_far *bread)(); | ||
| 221 | int (_far *bputs)(); | ||
| 222 | int (_far *bgets)(); | ||
| 223 | long (_far *ctrl)(); | ||
| 224 | int (_far *create)(); | ||
| 225 | int (_far *destroy)(); | ||
| 226 | } BIO_METHOD; | ||
| 227 | #endif | ||
| 228 | |||
| 229 | typedef struct bio_st | ||
| 230 | { | ||
| 231 | BIO_METHOD *method; | ||
| 232 | #ifndef NOPROTO | ||
| 233 | /* bio, mode, argp, argi, argl, ret */ | ||
| 234 | long (*callback)(struct bio_st *,int,char *,int, long,long); | ||
| 235 | #else | ||
| 236 | long (*callback)(); | ||
| 237 | #endif | ||
| 238 | char *cb_arg; /* first argument for the callback */ | ||
| 239 | |||
| 240 | int init; | ||
| 241 | int shutdown; | ||
| 242 | int flags; /* extra storage */ | ||
| 243 | int retry_reason; | ||
| 244 | int num; | ||
| 245 | char *ptr; | ||
| 246 | struct bio_st *next_bio; /* used by filter BIOs */ | ||
| 247 | struct bio_st *prev_bio; /* used by filter BIOs */ | ||
| 248 | int references; | ||
| 249 | unsigned long num_read; | ||
| 250 | unsigned long num_write; | ||
| 251 | |||
| 252 | CRYPTO_EX_DATA ex_data; | ||
| 253 | } BIO; | ||
| 254 | |||
| 255 | typedef struct bio_f_buffer_ctx_struct | ||
| 256 | { | ||
| 257 | /* BIO *bio; */ /* this is now in the BIO struct */ | ||
| 258 | int ibuf_size; /* how big is the input buffer */ | ||
| 259 | int obuf_size; /* how big is the output buffer */ | ||
| 260 | |||
| 261 | char *ibuf; /* the char array */ | ||
| 262 | int ibuf_len; /* how many bytes are in it */ | ||
| 263 | int ibuf_off; /* write/read offset */ | ||
| 264 | |||
| 265 | char *obuf; /* the char array */ | ||
| 266 | int obuf_len; /* how many bytes are in it */ | ||
| 267 | int obuf_off; /* write/read offset */ | ||
| 268 | } BIO_F_BUFFER_CTX; | ||
| 269 | |||
| 270 | /* connect BIO stuff */ | ||
| 271 | #define BIO_CONN_S_BEFORE 1 | ||
| 272 | #define BIO_CONN_S_GET_IP 2 | ||
| 273 | #define BIO_CONN_S_GET_PORT 3 | ||
| 274 | #define BIO_CONN_S_CREATE_SOCKET 4 | ||
| 275 | #define BIO_CONN_S_CONNECT 5 | ||
| 276 | #define BIO_CONN_S_OK 6 | ||
| 277 | #define BIO_CONN_S_BLOCKED_CONNECT 7 | ||
| 278 | #define BIO_CONN_S_NBIO 8 | ||
| 279 | #define BIO_CONN_get_param_hostname BIO_ctrl | ||
| 280 | |||
| 281 | #define BIO_number_read(b) ((b)->num_read) | ||
| 282 | #define BIO_number_written(b) ((b)->num_write) | ||
| 283 | |||
| 284 | #define BIO_C_SET_CONNECT 100 | ||
| 285 | #define BIO_C_DO_STATE_MACHINE 101 | ||
| 286 | #define BIO_C_SET_NBIO 102 | ||
| 287 | #define BIO_C_SET_PROXY_PARAM 103 | ||
| 288 | #define BIO_C_SET_FD 104 | ||
| 289 | #define BIO_C_GET_FD 105 | ||
| 290 | #define BIO_C_SET_FILE_PTR 106 | ||
| 291 | #define BIO_C_GET_FILE_PTR 107 | ||
| 292 | #define BIO_C_SET_FILENAME 108 | ||
| 293 | #define BIO_C_SET_SSL 109 | ||
| 294 | #define BIO_C_GET_SSL 110 | ||
| 295 | #define BIO_C_SET_MD 111 | ||
| 296 | #define BIO_C_GET_MD 112 | ||
| 297 | #define BIO_C_GET_CIPHER_STATUS 113 | ||
| 298 | #define BIO_C_SET_BUF_MEM 114 | ||
| 299 | #define BIO_C_GET_BUF_MEM_PTR 115 | ||
| 300 | #define BIO_C_GET_BUFF_NUM_LINES 116 | ||
| 301 | #define BIO_C_SET_BUFF_SIZE 117 | ||
| 302 | #define BIO_C_SET_ACCEPT 118 | ||
| 303 | #define BIO_C_SSL_MODE 119 | ||
| 304 | #define BIO_C_GET_MD_CTX 120 | ||
| 305 | #define BIO_C_GET_PROXY_PARAM 121 | ||
| 306 | #define BIO_C_SET_BUFF_READ_DATA 122 /* data to read first */ | ||
| 307 | #define BIO_C_GET_CONNECT 123 | ||
| 308 | #define BIO_C_GET_ACCEPT 124 | ||
| 309 | #define BIO_C_SET_SSL_RENEGOTIATE_BYTES 125 | ||
| 310 | #define BIO_C_GET_SSL_NUM_RENEGOTIATES 126 | ||
| 311 | #define BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT 127 | ||
| 312 | |||
| 313 | #define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,(char *)arg) | ||
| 314 | #define BIO_get_app_data(s) BIO_get_ex_data(s,0) | ||
| 315 | |||
| 316 | int BIO_get_ex_num(BIO *bio); | ||
| 317 | int BIO_set_ex_data(BIO *bio,int idx,char *data); | ||
| 318 | char *BIO_get_ex_data(BIO *bio,int idx); | ||
| 319 | void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); | ||
| 320 | int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), | ||
| 321 | int (*dup_func)(), void (*free_func)()); | ||
| 322 | |||
| 323 | /* BIO_s_connect_socket() */ | ||
| 324 | #define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0,(char *)name) | ||
| 325 | #define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1,(char *)port) | ||
| 326 | #define BIO_set_conn_ip(b,ip) BIO_ctrl(b,BIO_C_SET_CONNECT,2,(char *)ip) | ||
| 327 | #define BIO_set_conn_int_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,3,(char *)port) | ||
| 328 | #define BIO_get_conn_hostname(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0) | ||
| 329 | #define BIO_get_conn_port(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1) | ||
| 330 | #define BIO_get_conn_ip(b,ip) BIO_ptr_ctrl(b,BIO_C_SET_CONNECT,2) | ||
| 331 | #define BIO_get_conn_int port(b,port) BIO_int_ctrl(b,BIO_C_SET_CONNECT,3,port) | ||
| 332 | |||
| 333 | #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) | ||
| 334 | |||
| 335 | /* BIO_s_accept_socket() */ | ||
| 336 | #define BIO_set_accept_port(b,name) BIO_ctrl(b,BIO_C_SET_ACCEPT,0,(char *)name) | ||
| 337 | #define BIO_get_accept_port(b) BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,0) | ||
| 338 | /* #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) */ | ||
| 339 | #define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(n)?"a":NULL) | ||
| 340 | #define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(char *)bio) | ||
| 341 | |||
| 342 | #define BIO_do_connect(b) BIO_do_handshake(b) | ||
| 343 | #define BIO_do_accept(b) BIO_do_handshake(b) | ||
| 344 | #define BIO_do_handshake(b) BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL) | ||
| 345 | |||
| 346 | /* BIO_s_proxy_client() */ | ||
| 347 | #define BIO_set_url(b,url) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,0,(char *)(url)) | ||
| 348 | #define BIO_set_proxies(b,p) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,1,(char *)(p)) | ||
| 349 | /* BIO_set_nbio(b,n) */ | ||
| 350 | #define BIO_set_filter_bio(b,s) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,2,(char *)(s)) | ||
| 351 | /* BIO *BIO_get_filter_bio(BIO *bio); */ | ||
| 352 | #define BIO_set_proxy_cb(b,cb) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,3,(char *)(cb)) | ||
| 353 | #define BIO_set_proxy_header(b,sk) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,4,(char *)sk) | ||
| 354 | #define BIO_set_no_connect_return(b,bool) BIO_int_ctrl(b,BIO_C_SET_PROXY_PARAM,5,bool) | ||
| 355 | |||
| 356 | #define BIO_get_proxy_header(b,skp) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,0,(char *)skp) | ||
| 357 | #define BIO_get_proxies(b,pxy_p) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,1,(char *)(pxy_p)) | ||
| 358 | #define BIO_get_url(b,url) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,2,(char *)(url)) | ||
| 359 | #define BIO_get_no_connect_return(b) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,5,NULL) | ||
| 360 | |||
| 361 | #define BIO_set_fd(b,fd,c) BIO_int_ctrl(b,BIO_C_SET_FD,c,fd) | ||
| 362 | #define BIO_get_fd(b,c) BIO_ctrl(b,BIO_C_GET_FD,0,(char *)c) | ||
| 363 | |||
| 364 | #define BIO_set_fp(b,fp,c) BIO_ctrl(b,BIO_C_SET_FILE_PTR,c,(char *)fp) | ||
| 365 | #define BIO_get_fp(b,fpp) BIO_ctrl(b,BIO_C_GET_FILE_PTR,0,(char *)fpp) | ||
| 366 | |||
| 367 | #define BIO_read_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ | ||
| 368 | BIO_CLOSE|BIO_FP_READ,name) | ||
| 369 | #define BIO_write_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ | ||
| 370 | BIO_CLOSE|BIO_FP_WRITE,name) | ||
| 371 | #define BIO_append_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ | ||
| 372 | BIO_CLOSE|BIO_FP_APPEND,name) | ||
| 373 | |||
| 374 | /* WARNING WARNING, this ups the reference count on the read bio of the | ||
| 375 | * SSL structure. This is because the ssl read BIO is now pointed to by | ||
| 376 | * the next_bio field in the bio. So when you free the BIO, make sure | ||
| 377 | * you are doing a BIO_free_all() to catch the underlying BIO. */ | ||
| 378 | #define BIO_set_ssl(b,ssl,c) BIO_ctrl(b,BIO_C_SET_SSL,c,(char *)ssl) | ||
| 379 | #define BIO_get_ssl(b,sslp) BIO_ctrl(b,BIO_C_GET_SSL,0,(char *)sslp) | ||
| 380 | #define BIO_set_ssl_mode(b,client) BIO_ctrl(b,BIO_C_SSL_MODE,client,NULL) | ||
| 381 | #define BIO_set_ssl_renegotiate_bytes(b,num) \ | ||
| 382 | BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_BYTES,num,NULL); | ||
| 383 | #define BIO_get_num_renegotiates(b) \ | ||
| 384 | BIO_ctrl(b,BIO_C_SET_SSL_NUM_RENEGOTIATES,0,NULL); | ||
| 385 | #define BIO_set_ssl_renegotiate_timeout(b,seconds) \ | ||
| 386 | BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT,seconds,NULL); | ||
| 387 | |||
| 388 | /* defined in evp.h */ | ||
| 389 | /* #define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,1,(char *)md) */ | ||
| 390 | |||
| 391 | #define BIO_set_mem_buf(b,bm,c) BIO_ctrl(b,BIO_C_SET_BUF_MEM,c,(char *)bm) | ||
| 392 | #define BIO_get_mem_ptr(b,pp) BIO_ctrl(b,BIO_C_GET_BUF_MEM_PTR,0,(char *)pp) | ||
| 393 | |||
| 394 | /* For the BIO_f_buffer() type */ | ||
| 395 | #define BIO_get_buffer_num_lines(b) BIO_ctrl(b,BIO_C_GET_BUFF_NUM_LINES,0,NULL) | ||
| 396 | #define BIO_set_buffer_size(b,size) BIO_ctrl(b,BIO_C_SET_BUFF_SIZE,size,NULL) | ||
| 397 | #define BIO_set_read_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,0) | ||
| 398 | #define BIO_set_write_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,1) | ||
| 399 | #define BIO_set_buffer_read_data(b,buf,num) BIO_ctrl(b,BIO_C_SET_BUFF_READ_DATA,num,buf) | ||
| 400 | |||
| 401 | /* Don't use the next one unless you know what you are doing :-) */ | ||
| 402 | #define BIO_dup_state(b,ret) BIO_ctrl(b,BIO_CTRL_DUP,0,(char *)(ret)) | ||
| 403 | |||
| 404 | #define BIO_reset(b) (int)BIO_ctrl(b,BIO_CTRL_RESET,0,NULL) | ||
| 405 | #define BIO_eof(b) (int)BIO_ctrl(b,BIO_CTRL_EOF,0,NULL) | ||
| 406 | #define BIO_set_close(b,c) (int)BIO_ctrl(b,BIO_CTRL_SET_CLOSE,(c),NULL) | ||
| 407 | #define BIO_get_close(b) (int)BIO_ctrl(b,BIO_CTRL_GET_CLOSE,0,NULL) | ||
| 408 | #define BIO_pending(b) (int)BIO_ctrl(b,BIO_CTRL_PENDING,0,NULL) | ||
| 409 | #define BIO_wpending(b) (int)BIO_ctrl(b,BIO_CTRL_WPENDING,0,NULL) | ||
| 410 | #define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL) | ||
| 411 | #define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0,(char *)cbp) | ||
| 412 | #define BIO_set_info_callback(b,cb) (int)BIO_ctrl(b,BIO_CTRL_SET_CALLBACK,0,(char *)cb) | ||
| 413 | |||
| 414 | /* For the BIO_f_buffer() type */ | ||
| 415 | #define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL) | ||
| 416 | |||
| 417 | #ifdef NO_STDIO | ||
| 418 | #define NO_FP_API | ||
| 419 | #endif | ||
| 420 | |||
| 421 | #ifndef NOPROTO | ||
| 422 | # if defined(WIN16) && defined(_WINDLL) | ||
| 423 | BIO_METHOD *BIO_s_file_internal(void); | ||
| 424 | BIO *BIO_new_file_internal(char *filename, char *mode); | ||
| 425 | BIO *BIO_new_fp_internal(FILE *stream, int close_flag); | ||
| 426 | # define BIO_s_file BIO_s_file_internal | ||
| 427 | # define BIO_new_file BIO_new_file_internal | ||
| 428 | # define BIO_new_fp BIO_new_fp_internal | ||
| 429 | # else /* FP_API */ | ||
| 430 | BIO_METHOD *BIO_s_file(void ); | ||
| 431 | BIO *BIO_new_file(char *filename, char *mode); | ||
| 432 | BIO *BIO_new_fp(FILE *stream, int close_flag); | ||
| 433 | # define BIO_s_file_internal BIO_s_file | ||
| 434 | # define BIO_new_file_internal BIO_new_file | ||
| 435 | # define BIO_new_fp_internal BIO_s_file | ||
| 436 | # endif /* FP_API */ | ||
| 437 | #else | ||
| 438 | # if defined(WIN16) && defined(_WINDLL) | ||
| 439 | BIO_METHOD *BIO_s_file_internal(); | ||
| 440 | BIO *BIO_new_file_internal(); | ||
| 441 | BIO *BIO_new_fp_internal(); | ||
| 442 | # define BIO_s_file BIO_s_file_internal | ||
| 443 | # define BIO_new_file BIO_new_file_internal | ||
| 444 | # define BIO_new_fp BIO_new_fp_internal | ||
| 445 | # else /* FP_API */ | ||
| 446 | BIO_METHOD *BIO_s_file(); | ||
| 447 | BIO *BIO_new_file(); | ||
| 448 | BIO *BIO_new_fp(); | ||
| 449 | # define BIO_s_file_internal BIO_s_file | ||
| 450 | # define BIO_new_file_internal BIO_new_file | ||
| 451 | # define BIO_new_fp_internal BIO_s_file | ||
| 452 | # endif /* FP_API */ | ||
| 453 | #endif | ||
| 454 | |||
| 455 | #ifndef NOPROTO | ||
| 456 | BIO * BIO_new(BIO_METHOD *type); | ||
| 457 | int BIO_set(BIO *a,BIO_METHOD *type); | ||
| 458 | int BIO_free(BIO *a); | ||
| 459 | int BIO_read(BIO *b, char *data, int len); | ||
| 460 | int BIO_gets(BIO *bp,char *buf, int size); | ||
| 461 | int BIO_write(BIO *b, char *data, int len); | ||
| 462 | int BIO_puts(BIO *bp,char *buf); | ||
| 463 | long BIO_ctrl(BIO *bp,int cmd,long larg,char *parg); | ||
| 464 | char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg); | ||
| 465 | long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg); | ||
| 466 | BIO * BIO_push(BIO *b,BIO *append); | ||
| 467 | BIO * BIO_pop(BIO *b); | ||
| 468 | void BIO_free_all(BIO *a); | ||
| 469 | BIO * BIO_find_type(BIO *b,int bio_type); | ||
| 470 | BIO * BIO_get_retry_BIO(BIO *bio, int *reason); | ||
| 471 | int BIO_get_retry_reason(BIO *bio); | ||
| 472 | BIO * BIO_dup_chain(BIO *in); | ||
| 473 | |||
| 474 | #ifndef WIN16 | ||
| 475 | long BIO_debug_callback(BIO *bio,int cmd,char *argp,int argi, | ||
| 476 | long argl,long ret); | ||
| 477 | #else | ||
| 478 | long _far _loadds BIO_debug_callback(BIO *bio,int cmd,char *argp,int argi, | ||
| 479 | long argl,long ret); | ||
| 480 | #endif | ||
| 481 | |||
| 482 | BIO_METHOD *BIO_s_mem(void); | ||
| 483 | BIO_METHOD *BIO_s_socket(void); | ||
| 484 | BIO_METHOD *BIO_s_connect(void); | ||
| 485 | BIO_METHOD *BIO_s_accept(void); | ||
| 486 | BIO_METHOD *BIO_s_fd(void); | ||
| 487 | BIO_METHOD *BIO_s_null(void); | ||
| 488 | BIO_METHOD *BIO_f_null(void); | ||
| 489 | BIO_METHOD *BIO_f_nbio_test(void); | ||
| 490 | BIO_METHOD *BIO_f_buffer(void); | ||
| 491 | |||
| 492 | int BIO_sock_should_retry(int i); | ||
| 493 | int BIO_sock_non_fatal_error(int error); | ||
| 494 | int BIO_fd_should_retry(int i); | ||
| 495 | int BIO_fd_non_fatal_error(int error); | ||
| 496 | int BIO_dump(BIO *b,char *bytes,int len); | ||
| 497 | |||
| 498 | struct hostent *BIO_gethostbyname(char *name); | ||
| 499 | int BIO_sock_error(int sock); | ||
| 500 | int BIO_socket_ioctl(int fd, long type, unsigned long *arg); | ||
| 501 | int BIO_get_port(char *str, short *port_ptr); | ||
| 502 | int BIO_get_host_ip(char *str, unsigned char *ip); | ||
| 503 | int BIO_get_accept_socket(char *host_port); | ||
| 504 | int BIO_accept(int sock,char **ip_port); | ||
| 505 | int BIO_sock_init(void ); | ||
| 506 | void BIO_sock_cleanup(void); | ||
| 507 | int BIO_set_tcp_ndelay(int sock,int turn_on); | ||
| 508 | |||
| 509 | void ERR_load_BIO_strings(void ); | ||
| 510 | |||
| 511 | BIO *BIO_new_socket(int sock, int close_flag); | ||
| 512 | BIO *BIO_new_fd(int fd, int close_flag); | ||
| 513 | BIO *BIO_new_connect(char *host_port); | ||
| 514 | BIO *BIO_new_accept(char *host_port); | ||
| 515 | |||
| 516 | void BIO_copy_next_retry(BIO *b); | ||
| 517 | |||
| 518 | long BIO_ghbn_ctrl(int cmd,int iarg,char *parg); | ||
| 519 | |||
| 520 | #else | ||
| 521 | |||
| 522 | BIO * BIO_new(); | ||
| 523 | int BIO_set(); | ||
| 524 | int BIO_free(); | ||
| 525 | int BIO_read(); | ||
| 526 | int BIO_gets(); | ||
| 527 | int BIO_write(); | ||
| 528 | int BIO_puts(); | ||
| 529 | char * BIO_ptr_ctrl(); | ||
| 530 | long BIO_ctrl(); | ||
| 531 | long BIO_int_ctrl(); | ||
| 532 | BIO * BIO_push(); | ||
| 533 | BIO * BIO_pop(); | ||
| 534 | void BIO_free_all(); | ||
| 535 | BIO * BIO_find_type(); | ||
| 536 | BIO * BIO_get_retry_BIO(); | ||
| 537 | int BIO_get_retry_reason(); | ||
| 538 | BIO * BIO_dup_chain(); | ||
| 539 | |||
| 540 | #ifndef WIN16 | ||
| 541 | long BIO_debug_callback(); | ||
| 542 | #else | ||
| 543 | long _far _loadds BIO_debug_callback(); | ||
| 544 | #endif | ||
| 545 | |||
| 546 | BIO_METHOD *BIO_s_mem(); | ||
| 547 | BIO_METHOD *BIO_s_socket(); | ||
| 548 | BIO_METHOD *BIO_s_connect(); | ||
| 549 | BIO_METHOD *BIO_s_accept(); | ||
| 550 | BIO_METHOD *BIO_s_fd(); | ||
| 551 | BIO_METHOD *BIO_s_null(); | ||
| 552 | BIO_METHOD *BIO_f_null(); | ||
| 553 | BIO_METHOD *BIO_f_buffer(); | ||
| 554 | BIO_METHOD *BIO_f_nbio_test(); | ||
| 555 | |||
| 556 | int BIO_sock_should_retry(); | ||
| 557 | int BIO_sock_non_fatal_error(); | ||
| 558 | int BIO_fd_should_retry(); | ||
| 559 | int BIO_fd_non_fatal_error(); | ||
| 560 | int BIO_dump(); | ||
| 561 | |||
| 562 | struct hostent *BIO_gethostbyname(); | ||
| 563 | int BIO_sock_error(); | ||
| 564 | int BIO_socket_ioctl(); | ||
| 565 | int BIO_get_port(); | ||
| 566 | int BIO_get_host_ip(); | ||
| 567 | int BIO_get_accept_socket(); | ||
| 568 | int BIO_accept(); | ||
| 569 | int BIO_sock_init(); | ||
| 570 | void BIO_sock_cleanup(); | ||
| 571 | int BIO_set_tcp_ndelay(); | ||
| 572 | |||
| 573 | void ERR_load_BIO_strings(); | ||
| 574 | |||
| 575 | BIO *BIO_new_socket(); | ||
| 576 | BIO *BIO_new_fd(); | ||
| 577 | BIO *BIO_new_connect(); | ||
| 578 | BIO *BIO_new_accept(); | ||
| 579 | |||
| 580 | void BIO_copy_next_retry(); | ||
| 581 | |||
| 582 | int BIO_ghbn_ctrl(); | ||
| 583 | |||
| 584 | #endif | ||
| 585 | |||
| 586 | /* Tim Hudson's portable varargs stuff */ | ||
| 587 | |||
| 588 | #ifndef NOPROTO | ||
| 589 | #define VAR_ANSI /* select ANSI version by default */ | ||
| 590 | #endif | ||
| 591 | |||
| 592 | #ifdef VAR_ANSI | ||
| 593 | /* ANSI version of a "portable" macro set for variable length args */ | ||
| 594 | #ifndef __STDARG_H__ /**/ | ||
| 595 | #include <stdarg.h> | ||
| 596 | #endif /**/ | ||
| 597 | |||
| 598 | #define VAR_PLIST(arg1type,arg1) arg1type arg1, ... | ||
| 599 | #define VAR_PLIST2(arg1type,arg1,arg2type,arg2) arg1type arg1,arg2type arg2,... | ||
| 600 | #define VAR_ALIST | ||
| 601 | #define VAR_BDEFN(args,arg1type,arg1) va_list args | ||
| 602 | #define VAR_BDEFN2(args,arg1type,arg1,arg2type,arg2) va_list args | ||
| 603 | #define VAR_INIT(args,arg1type,arg1) va_start(args,arg1); | ||
| 604 | #define VAR_INIT2(args,arg1type,arg1,arg2type,arg2) va_start(args,arg2); | ||
| 605 | #define VAR_ARG(args,type,arg) arg=va_arg(args,type) | ||
| 606 | #define VAR_END(args) va_end(args); | ||
| 607 | |||
| 608 | #else | ||
| 609 | |||
| 610 | /* K&R version of a "portable" macro set for variable length args */ | ||
| 611 | #ifndef __VARARGS_H__ | ||
| 612 | #include <varargs.h> | ||
| 613 | #endif | ||
| 614 | |||
| 615 | #define VAR_PLIST(arg1type,arg1) va_alist | ||
| 616 | #define VAR_PLIST2(arg1type,arg1,arg2type,arg2) va_alist | ||
| 617 | #define VAR_ALIST va_dcl | ||
| 618 | #define VAR_BDEFN(args,arg1type,arg1) va_list args; arg1type arg1 | ||
| 619 | #define VAR_BDEFN2(args,arg1type,arg1,arg2type,arg2) va_list args; \ | ||
| 620 | arg1type arg1; arg2type arg2 | ||
| 621 | #define VAR_INIT(args,arg1type,arg1) va_start(args); \ | ||
| 622 | arg1=va_arg(args,arg1type); | ||
| 623 | #define VAR_INIT2(args,arg1type,arg1,arg2type,arg2) va_start(args); \ | ||
| 624 | arg1=va_arg(args,arg1type); arg2=va_arg(args,arg2type); | ||
| 625 | #define VAR_ARG(args,type,arg) arg=va_arg(args,type) | ||
| 626 | #define VAR_END(args) va_end(args); | ||
| 627 | |||
| 628 | #endif | ||
| 629 | |||
| 630 | #ifndef NOPROTO | ||
| 631 | int BIO_printf( VAR_PLIST( BIO *, bio ) ); | ||
| 632 | #else | ||
| 633 | int BIO_printf(); | ||
| 634 | #endif | ||
| 635 | |||
| 636 | /* BEGIN ERROR CODES */ | ||
| 637 | /* Error codes for the BIO functions. */ | ||
| 638 | |||
| 639 | /* Function codes. */ | ||
| 640 | #define BIO_F_ACPT_STATE 100 | ||
| 641 | #define BIO_F_BIO_ACCEPT 101 | ||
| 642 | #define BIO_F_BIO_CTRL 102 | ||
| 643 | #define BIO_F_BIO_GETS 103 | ||
| 644 | #define BIO_F_BIO_GET_ACCEPT_SOCKET 104 | ||
| 645 | #define BIO_F_BIO_GET_HOST_IP 105 | ||
| 646 | #define BIO_F_BIO_GET_PORT 106 | ||
| 647 | #define BIO_F_BIO_NEW 107 | ||
| 648 | #define BIO_F_BIO_NEW_FILE 108 | ||
| 649 | #define BIO_F_BIO_PUTS 109 | ||
| 650 | #define BIO_F_BIO_READ 110 | ||
| 651 | #define BIO_F_BIO_SOCK_INIT 111 | ||
| 652 | #define BIO_F_BIO_WRITE 112 | ||
| 653 | #define BIO_F_BUFFER_CTRL 113 | ||
| 654 | #define BIO_F_CONN_STATE 114 | ||
| 655 | #define BIO_F_FILE_CTRL 115 | ||
| 656 | #define BIO_F_MEM_WRITE 116 | ||
| 657 | #define BIO_F_SSL_NEW 117 | ||
| 658 | #define BIO_F_WSASTARTUP 118 | ||
| 659 | |||
| 660 | /* Reason codes. */ | ||
| 661 | #define BIO_R_ACCEPT_ERROR 100 | ||
| 662 | #define BIO_R_BAD_FOPEN_MODE 101 | ||
| 663 | #define BIO_R_BAD_HOSTNAME_LOOKUP 102 | ||
| 664 | #define BIO_R_CONNECT_ERROR 103 | ||
| 665 | #define BIO_R_ERROR_SETTING_NBIO 104 | ||
| 666 | #define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET 105 | ||
| 667 | #define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET 106 | ||
| 668 | #define BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET 107 | ||
| 669 | #define BIO_R_INVALID_IP_ADDRESS 108 | ||
| 670 | #define BIO_R_KEEPALIVE 109 | ||
| 671 | #define BIO_R_NBIO_CONNECT_ERROR 110 | ||
| 672 | #define BIO_R_NO_ACCEPT_PORT_SPECIFIED 111 | ||
| 673 | #define BIO_R_NO_HOSTHNAME_SPECIFIED 112 | ||
| 674 | #define BIO_R_NO_PORT_DEFINED 113 | ||
| 675 | #define BIO_R_NO_PORT_SPECIFIED 114 | ||
| 676 | #define BIO_R_NULL_PARAMETER 115 | ||
| 677 | #define BIO_R_UNABLE_TO_BIND_SOCKET 116 | ||
| 678 | #define BIO_R_UNABLE_TO_CREATE_SOCKET 117 | ||
| 679 | #define BIO_R_UNABLE_TO_LISTEN_SOCKET 118 | ||
| 680 | #define BIO_R_UNINITALISED 119 | ||
| 681 | #define BIO_R_UNSUPPORTED_METHOD 120 | ||
| 682 | #define BIO_R_WSASTARTUP 121 | ||
| 683 | |||
| 684 | #ifdef __cplusplus | ||
| 685 | } | ||
| 686 | #endif | ||
| 687 | #endif | ||
| 688 | |||
diff --git a/src/lib/libcrypto/bio/bio_cb.c b/src/lib/libcrypto/bio/bio_cb.c new file mode 100644 index 0000000000..bc6ed9eda1 --- /dev/null +++ b/src/lib/libcrypto/bio/bio_cb.c | |||
| @@ -0,0 +1,138 @@ | |||
| 1 | /* crypto/bio/bio_cb.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 <string.h> | ||
| 61 | #include <stdlib.h> | ||
| 62 | #include "cryptlib.h" | ||
| 63 | #include "bio.h" | ||
| 64 | #include "err.h" | ||
| 65 | |||
| 66 | long MS_CALLBACK BIO_debug_callback(bio,cmd,argp,argi,argl,ret) | ||
| 67 | BIO *bio; | ||
| 68 | int cmd; | ||
| 69 | char *argp; | ||
| 70 | int argi; | ||
| 71 | long argl; | ||
| 72 | long ret; | ||
| 73 | { | ||
| 74 | BIO *b; | ||
| 75 | MS_STATIC char buf[256]; | ||
| 76 | char *p; | ||
| 77 | long r=1; | ||
| 78 | |||
| 79 | if (BIO_CB_RETURN & cmd) | ||
| 80 | r=ret; | ||
| 81 | |||
| 82 | sprintf(buf,"BIO[%08lX]:",(unsigned long)bio); | ||
| 83 | p= &(buf[14]); | ||
| 84 | switch (cmd) | ||
| 85 | { | ||
| 86 | case BIO_CB_FREE: | ||
| 87 | sprintf(p,"Free - %s\n",bio->method->name); | ||
| 88 | break; | ||
| 89 | case BIO_CB_READ: | ||
| 90 | if (bio->method->type & BIO_TYPE_DESCRIPTOR) | ||
| 91 | sprintf(p,"read(%d,%d) - %s fd=%d\n",bio->num,argi,bio->method->name,bio->num); | ||
| 92 | else | ||
| 93 | sprintf(p,"read(%d,%d) - %s\n",bio->num,argi,bio->method->name); | ||
| 94 | break; | ||
| 95 | case BIO_CB_WRITE: | ||
| 96 | if (bio->method->type & BIO_TYPE_DESCRIPTOR) | ||
| 97 | sprintf(p,"write(%d,%d) - %s fd=%d\n",bio->num,argi,bio->method->name,bio->num); | ||
| 98 | else | ||
| 99 | sprintf(p,"write(%d,%d) - %s\n",bio->num,argi,bio->method->name); | ||
| 100 | break; | ||
| 101 | case BIO_CB_PUTS: | ||
| 102 | sprintf(p,"puts() - %s\n",bio->method->name); | ||
| 103 | break; | ||
| 104 | case BIO_CB_GETS: | ||
| 105 | sprintf(p,"gets(%d) - %s\n",argi,bio->method->name); | ||
| 106 | break; | ||
| 107 | case BIO_CB_CTRL: | ||
| 108 | sprintf(p,"ctrl(%d) - %s\n",argi,bio->method->name); | ||
| 109 | break; | ||
| 110 | case BIO_CB_RETURN|BIO_CB_READ: | ||
| 111 | sprintf(p,"read return %ld\n",ret); | ||
| 112 | break; | ||
| 113 | case BIO_CB_RETURN|BIO_CB_WRITE: | ||
| 114 | sprintf(p,"write return %ld\n",ret); | ||
| 115 | break; | ||
| 116 | case BIO_CB_RETURN|BIO_CB_GETS: | ||
| 117 | sprintf(p,"gets return %ld\n",ret); | ||
| 118 | break; | ||
| 119 | case BIO_CB_RETURN|BIO_CB_PUTS: | ||
| 120 | sprintf(p,"puts return %ld\n",ret); | ||
| 121 | break; | ||
| 122 | case BIO_CB_RETURN|BIO_CB_CTRL: | ||
| 123 | sprintf(p,"ctrl return %ld\n",ret); | ||
| 124 | break; | ||
| 125 | default: | ||
| 126 | sprintf(p,"bio callback - unknown type (%d)\n",cmd); | ||
| 127 | break; | ||
| 128 | } | ||
| 129 | |||
| 130 | b=(BIO *)bio->cb_arg; | ||
| 131 | if (b != NULL) | ||
| 132 | BIO_write(b,buf,strlen(buf)); | ||
| 133 | #if !defined(NO_STDIO) && !defined(WIN16) | ||
| 134 | else | ||
| 135 | fputs(buf,stderr); | ||
| 136 | #endif | ||
| 137 | return(r); | ||
| 138 | } | ||
diff --git a/src/lib/libcrypto/bio/bio_err.c b/src/lib/libcrypto/bio/bio_err.c new file mode 100644 index 0000000000..37e14ca107 --- /dev/null +++ b/src/lib/libcrypto/bio/bio_err.c | |||
| @@ -0,0 +1,130 @@ | |||
| 1 | /* lib/bio/bio_err.c */ | ||
| 2 | /* Copyright (C) 1995-1997 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 | #include <stdio.h> | ||
| 59 | #include "err.h" | ||
| 60 | #include "bio.h" | ||
| 61 | |||
| 62 | /* BEGIN ERROR CODES */ | ||
| 63 | #ifndef NO_ERR | ||
| 64 | static ERR_STRING_DATA BIO_str_functs[]= | ||
| 65 | { | ||
| 66 | {ERR_PACK(0,BIO_F_ACPT_STATE,0), "ACPT_STATE"}, | ||
| 67 | {ERR_PACK(0,BIO_F_BIO_ACCEPT,0), "BIO_accept"}, | ||
| 68 | {ERR_PACK(0,BIO_F_BIO_CTRL,0), "BIO_ctrl"}, | ||
| 69 | {ERR_PACK(0,BIO_F_BIO_GETS,0), "BIO_gets"}, | ||
| 70 | {ERR_PACK(0,BIO_F_BIO_GET_ACCEPT_SOCKET,0), "BIO_get_accept_socket"}, | ||
| 71 | {ERR_PACK(0,BIO_F_BIO_GET_HOST_IP,0), "BIO_get_host_ip"}, | ||
| 72 | {ERR_PACK(0,BIO_F_BIO_GET_PORT,0), "BIO_get_port"}, | ||
| 73 | {ERR_PACK(0,BIO_F_BIO_NEW,0), "BIO_new"}, | ||
| 74 | {ERR_PACK(0,BIO_F_BIO_NEW_FILE,0), "BIO_new_file"}, | ||
| 75 | {ERR_PACK(0,BIO_F_BIO_PUTS,0), "BIO_puts"}, | ||
| 76 | {ERR_PACK(0,BIO_F_BIO_READ,0), "BIO_read"}, | ||
| 77 | {ERR_PACK(0,BIO_F_BIO_SOCK_INIT,0), "BIO_sock_init"}, | ||
| 78 | {ERR_PACK(0,BIO_F_BIO_WRITE,0), "BIO_write"}, | ||
| 79 | {ERR_PACK(0,BIO_F_BUFFER_CTRL,0), "BUFFER_CTRL"}, | ||
| 80 | {ERR_PACK(0,BIO_F_CONN_STATE,0), "CONN_STATE"}, | ||
| 81 | {ERR_PACK(0,BIO_F_FILE_CTRL,0), "FILE_CTRL"}, | ||
| 82 | {ERR_PACK(0,BIO_F_MEM_WRITE,0), "MEM_WRITE"}, | ||
| 83 | {ERR_PACK(0,BIO_F_SSL_NEW,0), "SSL_NEW"}, | ||
| 84 | {ERR_PACK(0,BIO_F_WSASTARTUP,0), "WSASTARTUP"}, | ||
| 85 | {0,NULL}, | ||
| 86 | }; | ||
| 87 | |||
| 88 | static ERR_STRING_DATA BIO_str_reasons[]= | ||
| 89 | { | ||
| 90 | {BIO_R_ACCEPT_ERROR ,"accept error"}, | ||
| 91 | {BIO_R_BAD_FOPEN_MODE ,"bad fopen mode"}, | ||
| 92 | {BIO_R_BAD_HOSTNAME_LOOKUP ,"bad hostname lookup"}, | ||
| 93 | {BIO_R_CONNECT_ERROR ,"connect error"}, | ||
| 94 | {BIO_R_ERROR_SETTING_NBIO ,"error setting nbio"}, | ||
| 95 | {BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET,"error setting nbio on accepted socket"}, | ||
| 96 | {BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET,"error setting nbio on accept socket"}, | ||
| 97 | {BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET ,"gethostbyname addr is not af inet"}, | ||
| 98 | {BIO_R_INVALID_IP_ADDRESS ,"invalid ip address"}, | ||
| 99 | {BIO_R_KEEPALIVE ,"keepalive"}, | ||
| 100 | {BIO_R_NBIO_CONNECT_ERROR ,"nbio connect error"}, | ||
| 101 | {BIO_R_NO_ACCEPT_PORT_SPECIFIED ,"no accept port specified"}, | ||
| 102 | {BIO_R_NO_HOSTHNAME_SPECIFIED ,"no hosthname specified"}, | ||
| 103 | {BIO_R_NO_PORT_DEFINED ,"no port defined"}, | ||
| 104 | {BIO_R_NO_PORT_SPECIFIED ,"no port specified"}, | ||
| 105 | {BIO_R_NULL_PARAMETER ,"null parameter"}, | ||
| 106 | {BIO_R_UNABLE_TO_BIND_SOCKET ,"unable to bind socket"}, | ||
| 107 | {BIO_R_UNABLE_TO_CREATE_SOCKET ,"unable to create socket"}, | ||
| 108 | {BIO_R_UNABLE_TO_LISTEN_SOCKET ,"unable to listen socket"}, | ||
| 109 | {BIO_R_UNINITALISED ,"uninitalised"}, | ||
| 110 | {BIO_R_UNSUPPORTED_METHOD ,"unsupported method"}, | ||
| 111 | {BIO_R_WSASTARTUP ,"wsastartup"}, | ||
| 112 | {0,NULL}, | ||
| 113 | }; | ||
| 114 | |||
| 115 | #endif | ||
| 116 | |||
| 117 | void ERR_load_BIO_strings() | ||
| 118 | { | ||
| 119 | static int init=1; | ||
| 120 | |||
| 121 | if (init); | ||
| 122 | {; | ||
| 123 | init=0; | ||
| 124 | #ifndef NO_ERR | ||
| 125 | ERR_load_strings(ERR_LIB_BIO,BIO_str_functs); | ||
| 126 | ERR_load_strings(ERR_LIB_BIO,BIO_str_reasons); | ||
| 127 | #endif | ||
| 128 | |||
| 129 | } | ||
| 130 | } | ||
diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c new file mode 100644 index 0000000000..7a66b0892e --- /dev/null +++ b/src/lib/libcrypto/bio/bio_lib.c | |||
| @@ -0,0 +1,519 @@ | |||
| 1 | /* crypto/bio/bio_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 <errno.h> | ||
| 61 | #include "crypto.h" | ||
| 62 | #include "cryptlib.h" | ||
| 63 | #include "bio.h" | ||
| 64 | #include "stack.h" | ||
| 65 | |||
| 66 | static STACK *bio_meth=NULL; | ||
| 67 | static int bio_meth_num=0; | ||
| 68 | |||
| 69 | BIO *BIO_new(method) | ||
| 70 | BIO_METHOD *method; | ||
| 71 | { | ||
| 72 | BIO *ret=NULL; | ||
| 73 | |||
| 74 | ret=(BIO *)Malloc(sizeof(BIO)); | ||
| 75 | if (ret == NULL) | ||
| 76 | { | ||
| 77 | BIOerr(BIO_F_BIO_NEW,ERR_R_MALLOC_FAILURE); | ||
| 78 | return(NULL); | ||
| 79 | } | ||
| 80 | if (!BIO_set(ret,method)) | ||
| 81 | { | ||
| 82 | Free(ret); | ||
| 83 | ret=NULL; | ||
| 84 | } | ||
| 85 | return(ret); | ||
| 86 | } | ||
| 87 | |||
| 88 | int BIO_set(bio,method) | ||
| 89 | BIO *bio; | ||
| 90 | BIO_METHOD *method; | ||
| 91 | { | ||
| 92 | bio->method=method; | ||
| 93 | bio->callback=NULL; | ||
| 94 | bio->cb_arg=NULL; | ||
| 95 | bio->init=0; | ||
| 96 | bio->shutdown=1; | ||
| 97 | bio->flags=0; | ||
| 98 | bio->retry_reason=0; | ||
| 99 | bio->num=0; | ||
| 100 | bio->ptr=NULL; | ||
| 101 | bio->prev_bio=NULL; | ||
| 102 | bio->next_bio=NULL; | ||
| 103 | bio->references=1; | ||
| 104 | bio->num_read=0L; | ||
| 105 | bio->num_write=0L; | ||
| 106 | CRYPTO_new_ex_data(bio_meth,(char *)bio,&bio->ex_data); | ||
| 107 | if (method->create != NULL) | ||
| 108 | if (!method->create(bio)) | ||
| 109 | return(0); | ||
| 110 | return(1); | ||
| 111 | } | ||
| 112 | |||
| 113 | int BIO_free(a) | ||
| 114 | BIO *a; | ||
| 115 | { | ||
| 116 | int ret=0,i; | ||
| 117 | |||
| 118 | if (a == NULL) return(0); | ||
| 119 | |||
| 120 | i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_BIO); | ||
| 121 | #ifdef REF_PRINT | ||
| 122 | REF_PRINT("BIO",a); | ||
| 123 | #endif | ||
| 124 | if (i > 0) return(1); | ||
| 125 | #ifdef REF_CHECK | ||
| 126 | if (i < 0) | ||
| 127 | { | ||
| 128 | fprintf(stderr,"BIO_free, bad reference count\n"); | ||
| 129 | abort(); | ||
| 130 | } | ||
| 131 | #endif | ||
| 132 | if ((a->callback != NULL) && | ||
| 133 | ((i=(int)a->callback(a,BIO_CB_FREE,NULL,0,0L,1L)) <= 0)) | ||
| 134 | return(i); | ||
| 135 | |||
| 136 | CRYPTO_free_ex_data(bio_meth,(char *)a,&a->ex_data); | ||
| 137 | |||
| 138 | if ((a->method == NULL) || (a->method->destroy == NULL)) return(1); | ||
| 139 | ret=a->method->destroy(a); | ||
| 140 | Free(a); | ||
| 141 | return(1); | ||
| 142 | } | ||
| 143 | |||
| 144 | int BIO_read(b,out,outl) | ||
| 145 | BIO *b; | ||
| 146 | char *out; | ||
| 147 | int outl; | ||
| 148 | { | ||
| 149 | int i; | ||
| 150 | long (*cb)(); | ||
| 151 | |||
| 152 | if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL)) | ||
| 153 | { | ||
| 154 | BIOerr(BIO_F_BIO_READ,BIO_R_UNSUPPORTED_METHOD); | ||
| 155 | return(-2); | ||
| 156 | } | ||
| 157 | |||
| 158 | cb=b->callback; | ||
| 159 | if ((cb != NULL) && | ||
| 160 | ((i=(int)cb(b,BIO_CB_READ,out,outl,0L,1L)) <= 0)) | ||
| 161 | return(i); | ||
| 162 | |||
| 163 | if (!b->init) | ||
| 164 | { | ||
| 165 | BIOerr(BIO_F_BIO_READ,BIO_R_UNINITALISED); | ||
| 166 | return(-2); | ||
| 167 | } | ||
| 168 | |||
| 169 | i=b->method->bread(b,out,outl); | ||
| 170 | if (i > 0) b->num_read+=(unsigned long)i; | ||
| 171 | |||
| 172 | if (cb != NULL) | ||
| 173 | i=(int)cb(b,BIO_CB_READ|BIO_CB_RETURN,out,outl, | ||
| 174 | 0L,(long)i); | ||
| 175 | return(i); | ||
| 176 | } | ||
| 177 | |||
| 178 | int BIO_write(b,in,inl) | ||
| 179 | BIO *b; | ||
| 180 | char *in; | ||
| 181 | int inl; | ||
| 182 | { | ||
| 183 | int i; | ||
| 184 | long (*cb)(); | ||
| 185 | |||
| 186 | if (b == NULL) | ||
| 187 | return(0); | ||
| 188 | |||
| 189 | cb=b->callback; | ||
| 190 | if ((b->method == NULL) || (b->method->bwrite == NULL)) | ||
| 191 | { | ||
| 192 | BIOerr(BIO_F_BIO_WRITE,BIO_R_UNSUPPORTED_METHOD); | ||
| 193 | return(-2); | ||
| 194 | } | ||
| 195 | |||
| 196 | if ((cb != NULL) && | ||
| 197 | ((i=(int)cb(b,BIO_CB_WRITE,in,inl,0L,1L)) <= 0)) | ||
| 198 | return(i); | ||
| 199 | |||
| 200 | if (!b->init) | ||
| 201 | { | ||
| 202 | BIOerr(BIO_F_BIO_WRITE,BIO_R_UNINITALISED); | ||
| 203 | return(-2); | ||
| 204 | } | ||
| 205 | |||
| 206 | i=b->method->bwrite(b,in,inl); | ||
| 207 | if (i > 0) b->num_write+=(unsigned long)i; | ||
| 208 | |||
| 209 | if (cb != NULL) | ||
| 210 | i=(int)cb(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl, | ||
| 211 | 0L,(long)i); | ||
| 212 | return(i); | ||
| 213 | } | ||
| 214 | |||
| 215 | int BIO_puts(b,in) | ||
| 216 | BIO *b; | ||
| 217 | char *in; | ||
| 218 | { | ||
| 219 | int i; | ||
| 220 | long (*cb)(); | ||
| 221 | |||
| 222 | if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL)) | ||
| 223 | { | ||
| 224 | BIOerr(BIO_F_BIO_PUTS,BIO_R_UNSUPPORTED_METHOD); | ||
| 225 | return(-2); | ||
| 226 | } | ||
| 227 | |||
| 228 | cb=b->callback; | ||
| 229 | |||
| 230 | if ((cb != NULL) && | ||
| 231 | ((i=(int)cb(b,BIO_CB_PUTS,in,0,0L,1L)) <= 0)) | ||
| 232 | return(i); | ||
| 233 | |||
| 234 | if (!b->init) | ||
| 235 | { | ||
| 236 | BIOerr(BIO_F_BIO_PUTS,BIO_R_UNINITALISED); | ||
| 237 | return(-2); | ||
| 238 | } | ||
| 239 | |||
| 240 | i=b->method->bputs(b,in); | ||
| 241 | |||
| 242 | if (cb != NULL) | ||
| 243 | i=(int)cb(b,BIO_CB_PUTS|BIO_CB_RETURN,in,0, | ||
| 244 | 0L,(long)i); | ||
| 245 | return(i); | ||
| 246 | } | ||
| 247 | |||
| 248 | int BIO_gets(b,in,inl) | ||
| 249 | BIO *b; | ||
| 250 | char *in; | ||
| 251 | int inl; | ||
| 252 | { | ||
| 253 | int i; | ||
| 254 | long (*cb)(); | ||
| 255 | |||
| 256 | if ((b == NULL) || (b->method == NULL) || (b->method->bgets == NULL)) | ||
| 257 | { | ||
| 258 | BIOerr(BIO_F_BIO_GETS,BIO_R_UNSUPPORTED_METHOD); | ||
| 259 | return(-2); | ||
| 260 | } | ||
| 261 | |||
| 262 | cb=b->callback; | ||
| 263 | |||
| 264 | if ((cb != NULL) && | ||
| 265 | ((i=(int)cb(b,BIO_CB_GETS,in,inl,0L,1L)) <= 0)) | ||
| 266 | return(i); | ||
| 267 | |||
| 268 | if (!b->init) | ||
| 269 | { | ||
| 270 | BIOerr(BIO_F_BIO_GETS,BIO_R_UNINITALISED); | ||
| 271 | return(-2); | ||
| 272 | } | ||
| 273 | |||
| 274 | i=b->method->bgets(b,in,inl); | ||
| 275 | |||
| 276 | if (cb != NULL) | ||
| 277 | i=(int)cb(b,BIO_CB_GETS|BIO_CB_RETURN,in,inl, | ||
| 278 | 0L,(long)i); | ||
| 279 | return(i); | ||
| 280 | } | ||
| 281 | |||
| 282 | long BIO_int_ctrl(b,cmd,larg,iarg) | ||
| 283 | BIO *b; | ||
| 284 | int cmd; | ||
| 285 | long larg; | ||
| 286 | int iarg; | ||
| 287 | { | ||
| 288 | int i; | ||
| 289 | |||
| 290 | i=iarg; | ||
| 291 | return(BIO_ctrl(b,cmd,larg,(char *)&i)); | ||
| 292 | } | ||
| 293 | |||
| 294 | char *BIO_ptr_ctrl(b,cmd,larg) | ||
| 295 | BIO *b; | ||
| 296 | int cmd; | ||
| 297 | long larg; | ||
| 298 | { | ||
| 299 | char *p=NULL; | ||
| 300 | |||
| 301 | if (BIO_ctrl(b,cmd,larg,(char *)&p) <= 0) | ||
| 302 | return(NULL); | ||
| 303 | else | ||
| 304 | return(p); | ||
| 305 | } | ||
| 306 | |||
| 307 | long BIO_ctrl(b,cmd,larg,parg) | ||
| 308 | BIO *b; | ||
| 309 | int cmd; | ||
| 310 | long larg; | ||
| 311 | char *parg; | ||
| 312 | { | ||
| 313 | long ret; | ||
| 314 | long (*cb)(); | ||
| 315 | |||
| 316 | if (b == NULL) return(0); | ||
| 317 | |||
| 318 | if ((b->method == NULL) || (b->method->ctrl == NULL)) | ||
| 319 | { | ||
| 320 | BIOerr(BIO_F_BIO_CTRL,BIO_R_UNSUPPORTED_METHOD); | ||
| 321 | return(-2); | ||
| 322 | } | ||
| 323 | |||
| 324 | cb=b->callback; | ||
| 325 | |||
| 326 | if ((cb != NULL) && | ||
| 327 | ((ret=cb(b,BIO_CB_CTRL,parg,cmd,larg,1L)) <= 0)) | ||
| 328 | return(ret); | ||
| 329 | |||
| 330 | ret=b->method->ctrl(b,cmd,larg,parg); | ||
| 331 | |||
| 332 | if (cb != NULL) | ||
| 333 | ret=cb(b,BIO_CB_CTRL|BIO_CB_RETURN,parg,cmd, | ||
| 334 | larg,ret); | ||
| 335 | return(ret); | ||
| 336 | } | ||
| 337 | |||
| 338 | /* put the 'bio' on the end of b's list of operators */ | ||
| 339 | BIO *BIO_push(b,bio) | ||
| 340 | BIO *b,*bio; | ||
| 341 | { | ||
| 342 | BIO *lb; | ||
| 343 | |||
| 344 | if (b == NULL) return(bio); | ||
| 345 | lb=b; | ||
| 346 | while (lb->next_bio != NULL) | ||
| 347 | lb=lb->next_bio; | ||
| 348 | lb->next_bio=bio; | ||
| 349 | if (bio != NULL) | ||
| 350 | bio->prev_bio=lb; | ||
| 351 | /* called to do internal processing */ | ||
| 352 | BIO_ctrl(b,BIO_CTRL_PUSH,0,NULL); | ||
| 353 | return(b); | ||
| 354 | } | ||
| 355 | |||
| 356 | /* Remove the first and return the rest */ | ||
| 357 | BIO *BIO_pop(b) | ||
| 358 | BIO *b; | ||
| 359 | { | ||
| 360 | BIO *ret; | ||
| 361 | |||
| 362 | if (b == NULL) return(NULL); | ||
| 363 | ret=b->next_bio; | ||
| 364 | |||
| 365 | if (b->prev_bio != NULL) | ||
| 366 | b->prev_bio->next_bio=b->next_bio; | ||
| 367 | if (b->next_bio != NULL) | ||
| 368 | b->next_bio->prev_bio=b->prev_bio; | ||
| 369 | |||
| 370 | b->next_bio=NULL; | ||
| 371 | b->prev_bio=NULL; | ||
| 372 | BIO_ctrl(b,BIO_CTRL_POP,0,NULL); | ||
| 373 | return(ret); | ||
| 374 | } | ||
| 375 | |||
| 376 | BIO *BIO_get_retry_BIO(bio,reason) | ||
| 377 | BIO *bio; | ||
| 378 | int *reason; | ||
| 379 | { | ||
| 380 | BIO *b,*last; | ||
| 381 | |||
| 382 | b=last=bio; | ||
| 383 | for (;;) | ||
| 384 | { | ||
| 385 | if (!BIO_should_retry(b)) break; | ||
| 386 | last=b; | ||
| 387 | b=b->next_bio; | ||
| 388 | if (b == NULL) break; | ||
| 389 | } | ||
| 390 | if (reason != NULL) *reason=last->retry_reason; | ||
| 391 | return(last); | ||
| 392 | } | ||
| 393 | |||
| 394 | int BIO_get_retry_reason(bio) | ||
| 395 | BIO *bio; | ||
| 396 | { | ||
| 397 | return(bio->retry_reason); | ||
| 398 | } | ||
| 399 | |||
| 400 | BIO *BIO_find_type(bio,type) | ||
| 401 | BIO *bio; | ||
| 402 | int type; | ||
| 403 | { | ||
| 404 | int mt,mask; | ||
| 405 | |||
| 406 | mask=type&0xff; | ||
| 407 | do { | ||
| 408 | if (bio->method != NULL) | ||
| 409 | { | ||
| 410 | mt=bio->method->type; | ||
| 411 | |||
| 412 | if (!mask) | ||
| 413 | { | ||
| 414 | if (mt & type) return(bio); | ||
| 415 | } | ||
| 416 | else if (mt == type) | ||
| 417 | return(bio); | ||
| 418 | } | ||
| 419 | bio=bio->next_bio; | ||
| 420 | } while (bio != NULL); | ||
| 421 | return(NULL); | ||
| 422 | } | ||
| 423 | |||
| 424 | void BIO_free_all(bio) | ||
| 425 | BIO *bio; | ||
| 426 | { | ||
| 427 | BIO *b; | ||
| 428 | int ref; | ||
| 429 | |||
| 430 | while (bio != NULL) | ||
| 431 | { | ||
| 432 | b=bio; | ||
| 433 | ref=b->references; | ||
| 434 | bio=bio->next_bio; | ||
| 435 | BIO_free(b); | ||
| 436 | /* Since ref count > 1, don't free anyone else. */ | ||
| 437 | if (ref > 1) break; | ||
| 438 | } | ||
| 439 | } | ||
| 440 | |||
| 441 | BIO *BIO_dup_chain(in) | ||
| 442 | BIO *in; | ||
| 443 | { | ||
| 444 | BIO *ret=NULL,*eoc=NULL,*bio,*new; | ||
| 445 | |||
| 446 | for (bio=in; bio != NULL; bio=bio->next_bio) | ||
| 447 | { | ||
| 448 | if ((new=BIO_new(bio->method)) == NULL) goto err; | ||
| 449 | new->callback=bio->callback; | ||
| 450 | new->cb_arg=bio->cb_arg; | ||
| 451 | new->init=bio->init; | ||
| 452 | new->shutdown=bio->shutdown; | ||
| 453 | new->flags=bio->flags; | ||
| 454 | |||
| 455 | /* This will let SSL_s_sock() work with stdin/stdout */ | ||
| 456 | new->num=bio->num; | ||
| 457 | |||
| 458 | if (!BIO_dup_state(bio,(char *)new)) | ||
| 459 | { | ||
| 460 | BIO_free(new); | ||
| 461 | goto err; | ||
| 462 | } | ||
| 463 | |||
| 464 | /* copy app data */ | ||
| 465 | if (!CRYPTO_dup_ex_data(bio_meth,&new->ex_data,&bio->ex_data)) | ||
| 466 | goto err; | ||
| 467 | |||
| 468 | if (ret == NULL) | ||
| 469 | { | ||
| 470 | eoc=new; | ||
| 471 | ret=eoc; | ||
| 472 | } | ||
| 473 | else | ||
| 474 | { | ||
| 475 | BIO_push(eoc,new); | ||
| 476 | eoc=new; | ||
| 477 | } | ||
| 478 | } | ||
| 479 | return(ret); | ||
| 480 | err: | ||
| 481 | if (ret != NULL) | ||
| 482 | BIO_free(ret); | ||
| 483 | return(NULL); | ||
| 484 | } | ||
| 485 | |||
| 486 | void BIO_copy_next_retry(b) | ||
| 487 | BIO *b; | ||
| 488 | { | ||
| 489 | BIO_set_flags(b,BIO_get_retry_flags(b->next_bio)); | ||
| 490 | b->retry_reason=b->next_bio->retry_reason; | ||
| 491 | } | ||
| 492 | |||
| 493 | int BIO_get_ex_new_index(argl,argp,new_func,dup_func,free_func) | ||
| 494 | long argl; | ||
| 495 | char *argp; | ||
| 496 | int (*new_func)(); | ||
| 497 | int (*dup_func)(); | ||
| 498 | void (*free_func)(); | ||
| 499 | { | ||
| 500 | bio_meth_num++; | ||
| 501 | return(CRYPTO_get_ex_new_index(bio_meth_num-1,&bio_meth, | ||
| 502 | argl,argp,new_func,dup_func,free_func)); | ||
| 503 | } | ||
| 504 | |||
| 505 | int BIO_set_ex_data(bio,idx,data) | ||
| 506 | BIO *bio; | ||
| 507 | int idx; | ||
| 508 | char *data; | ||
| 509 | { | ||
| 510 | return(CRYPTO_set_ex_data(&(bio->ex_data),idx,data)); | ||
| 511 | } | ||
| 512 | |||
| 513 | char *BIO_get_ex_data(bio,idx) | ||
| 514 | BIO *bio; | ||
| 515 | int idx; | ||
| 516 | { | ||
| 517 | return(CRYPTO_get_ex_data(&(bio->ex_data),idx)); | ||
| 518 | } | ||
| 519 | |||
diff --git a/src/lib/libcrypto/bio/bss_acpt.c b/src/lib/libcrypto/bio/bss_acpt.c new file mode 100644 index 0000000000..e49902fa9f --- /dev/null +++ b/src/lib/libcrypto/bio/bss_acpt.c | |||
| @@ -0,0 +1,500 @@ | |||
| 1 | /* crypto/bio/bss_acpt.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 | #ifndef NO_SOCK | ||
| 60 | |||
| 61 | #include <stdio.h> | ||
| 62 | #include <errno.h> | ||
| 63 | #define USE_SOCKETS | ||
| 64 | #include "cryptlib.h" | ||
| 65 | #include "bio.h" | ||
| 66 | |||
| 67 | /* BIOerr(BIO_F_WSASTARTUP,BIO_R_WSASTARTUP ); */ | ||
| 68 | |||
| 69 | #ifdef WIN16 | ||
| 70 | #define SOCKET_PROTOCOL 0 /* more microsoft stupidity */ | ||
| 71 | #else | ||
| 72 | #define SOCKET_PROTOCOL IPPROTO_TCP | ||
| 73 | #endif | ||
| 74 | |||
| 75 | typedef struct bio_accept_st | ||
| 76 | { | ||
| 77 | int state; | ||
| 78 | char *param_addr; | ||
| 79 | |||
| 80 | int accept_sock; | ||
| 81 | int accept_nbio; | ||
| 82 | |||
| 83 | char *addr; | ||
| 84 | int nbio; | ||
| 85 | BIO *bio_chain; | ||
| 86 | } BIO_ACCEPT; | ||
| 87 | |||
| 88 | #ifndef NOPROTO | ||
| 89 | static int acpt_write(BIO *h,char *buf,int num); | ||
| 90 | static int acpt_read(BIO *h,char *buf,int size); | ||
| 91 | static int acpt_puts(BIO *h,char *str); | ||
| 92 | static long acpt_ctrl(BIO *h,int cmd,long arg1,char *arg2); | ||
| 93 | static int acpt_new(BIO *h); | ||
| 94 | static int acpt_free(BIO *data); | ||
| 95 | #else | ||
| 96 | static int acpt_write(); | ||
| 97 | static int acpt_read(); | ||
| 98 | static int acpt_puts(); | ||
| 99 | static long acpt_ctrl(); | ||
| 100 | static int acpt_new(); | ||
| 101 | static int acpt_free(); | ||
| 102 | #endif | ||
| 103 | |||
| 104 | #ifndef NOPROTO | ||
| 105 | static int acpt_state(BIO *b, BIO_ACCEPT *c); | ||
| 106 | static void acpt_close_socket(BIO *data); | ||
| 107 | BIO_ACCEPT *BIO_ACCEPT_new(void ); | ||
| 108 | void BIO_ACCEPT_free(BIO_ACCEPT *a); | ||
| 109 | |||
| 110 | #else | ||
| 111 | |||
| 112 | static int acpt_state(); | ||
| 113 | static void acpt_close_socket(); | ||
| 114 | BIO_ACCEPT *BIO_ACCEPT_new(); | ||
| 115 | void BIO_ACCEPT_free(); | ||
| 116 | #endif | ||
| 117 | |||
| 118 | #define ACPT_S_BEFORE 1 | ||
| 119 | #define ACPT_S_GET_ACCEPT_SOCKET 2 | ||
| 120 | #define ACPT_S_OK 3 | ||
| 121 | |||
| 122 | static BIO_METHOD methods_acceptp= | ||
| 123 | { | ||
| 124 | BIO_TYPE_ACCEPT, | ||
| 125 | "socket accept", | ||
| 126 | acpt_write, | ||
| 127 | acpt_read, | ||
| 128 | acpt_puts, | ||
| 129 | NULL, /* connect_gets, */ | ||
| 130 | acpt_ctrl, | ||
| 131 | acpt_new, | ||
| 132 | acpt_free, | ||
| 133 | }; | ||
| 134 | |||
| 135 | BIO_METHOD *BIO_s_accept() | ||
| 136 | { | ||
| 137 | return(&methods_acceptp); | ||
| 138 | } | ||
| 139 | |||
| 140 | static int acpt_new(bi) | ||
| 141 | BIO *bi; | ||
| 142 | { | ||
| 143 | BIO_ACCEPT *ba; | ||
| 144 | |||
| 145 | bi->init=0; | ||
| 146 | bi->num=INVALID_SOCKET; | ||
| 147 | bi->flags=0; | ||
| 148 | if ((ba=BIO_ACCEPT_new()) == NULL) | ||
| 149 | return(0); | ||
| 150 | bi->ptr=(char *)ba; | ||
| 151 | ba->state=ACPT_S_BEFORE; | ||
| 152 | bi->shutdown=1; | ||
| 153 | return(1); | ||
| 154 | } | ||
| 155 | |||
| 156 | BIO_ACCEPT *BIO_ACCEPT_new() | ||
| 157 | { | ||
| 158 | BIO_ACCEPT *ret; | ||
| 159 | |||
| 160 | if ((ret=(BIO_ACCEPT *)Malloc(sizeof(BIO_ACCEPT))) == NULL) | ||
| 161 | return(NULL); | ||
| 162 | |||
| 163 | memset(ret,0,sizeof(BIO_ACCEPT)); | ||
| 164 | ret->accept_sock=INVALID_SOCKET; | ||
| 165 | return(ret); | ||
| 166 | } | ||
| 167 | |||
| 168 | void BIO_ACCEPT_free(a) | ||
| 169 | BIO_ACCEPT *a; | ||
| 170 | { | ||
| 171 | if (a->param_addr != NULL) Free(a->param_addr); | ||
| 172 | if (a->addr != NULL) Free(a->addr); | ||
| 173 | if (a->bio_chain != NULL) BIO_free(a->bio_chain); | ||
| 174 | Free(a); | ||
| 175 | } | ||
| 176 | |||
| 177 | static void acpt_close_socket(bio) | ||
| 178 | BIO *bio; | ||
| 179 | { | ||
| 180 | BIO_ACCEPT *c; | ||
| 181 | |||
| 182 | c=(BIO_ACCEPT *)bio->ptr; | ||
| 183 | if (c->accept_sock != INVALID_SOCKET) | ||
| 184 | { | ||
| 185 | shutdown(c->accept_sock,2); | ||
| 186 | # ifdef WINDOWS | ||
| 187 | closesocket(c->accept_sock); | ||
| 188 | # else | ||
| 189 | close(c->accept_sock); | ||
| 190 | # endif | ||
| 191 | c->accept_sock=INVALID_SOCKET; | ||
| 192 | bio->num=INVALID_SOCKET; | ||
| 193 | } | ||
| 194 | } | ||
| 195 | |||
| 196 | static int acpt_free(a) | ||
| 197 | BIO *a; | ||
| 198 | { | ||
| 199 | BIO_ACCEPT *data; | ||
| 200 | |||
| 201 | if (a == NULL) return(0); | ||
| 202 | data=(BIO_ACCEPT *)a->ptr; | ||
| 203 | |||
| 204 | if (a->shutdown) | ||
| 205 | { | ||
| 206 | acpt_close_socket(a); | ||
| 207 | BIO_ACCEPT_free(data); | ||
| 208 | a->ptr=NULL; | ||
| 209 | a->flags=0; | ||
| 210 | a->init=0; | ||
| 211 | } | ||
| 212 | return(1); | ||
| 213 | } | ||
| 214 | |||
| 215 | static int acpt_state(b,c) | ||
| 216 | BIO *b; | ||
| 217 | BIO_ACCEPT *c; | ||
| 218 | { | ||
| 219 | BIO *bio=NULL,*dbio; | ||
| 220 | unsigned long l=1; | ||
| 221 | int s= -1; | ||
| 222 | int i; | ||
| 223 | |||
| 224 | again: | ||
| 225 | switch (c->state) | ||
| 226 | { | ||
| 227 | case ACPT_S_BEFORE: | ||
| 228 | if (c->param_addr == NULL) | ||
| 229 | { | ||
| 230 | BIOerr(BIO_F_ACPT_STATE,BIO_R_NO_ACCEPT_PORT_SPECIFIED); | ||
| 231 | return(-1); | ||
| 232 | } | ||
| 233 | s=BIO_get_accept_socket(c->param_addr); | ||
| 234 | if (s == INVALID_SOCKET) | ||
| 235 | return(-1); | ||
| 236 | |||
| 237 | #ifdef FIONBIO | ||
| 238 | if (c->accept_nbio) | ||
| 239 | { | ||
| 240 | i=BIO_socket_ioctl(b->num,FIONBIO,&l); | ||
| 241 | if (i < 0) | ||
| 242 | { | ||
| 243 | #ifdef WINDOWS | ||
| 244 | closesocket(s); | ||
| 245 | #else | ||
| 246 | close(s); | ||
| 247 | # endif | ||
| 248 | BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET); | ||
| 249 | return(-1); | ||
| 250 | } | ||
| 251 | } | ||
| 252 | #endif | ||
| 253 | c->accept_sock=s; | ||
| 254 | b->num=s; | ||
| 255 | c->state=ACPT_S_GET_ACCEPT_SOCKET; | ||
| 256 | return(1); | ||
| 257 | break; | ||
| 258 | case ACPT_S_GET_ACCEPT_SOCKET: | ||
| 259 | if (b->next_bio != NULL) | ||
| 260 | { | ||
| 261 | c->state=ACPT_S_OK; | ||
| 262 | goto again; | ||
| 263 | } | ||
| 264 | i=BIO_accept(c->accept_sock,&(c->addr)); | ||
| 265 | if (i < 0) return(i); | ||
| 266 | bio=BIO_new_socket(i,BIO_CLOSE); | ||
| 267 | if (bio == NULL) goto err; | ||
| 268 | |||
| 269 | BIO_set_callback(bio,BIO_get_callback(b)); | ||
| 270 | BIO_set_callback_arg(bio,BIO_get_callback_arg(b)); | ||
| 271 | |||
| 272 | #ifdef FIONBIO | ||
| 273 | if (c->nbio) | ||
| 274 | { | ||
| 275 | i=BIO_socket_ioctl(i,FIONBIO,&l); | ||
| 276 | if (i < 0) | ||
| 277 | { | ||
| 278 | BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET); | ||
| 279 | goto err; | ||
| 280 | } | ||
| 281 | } | ||
| 282 | #endif | ||
| 283 | |||
| 284 | /* If the accept BIO has an bio_chain, we dup it and | ||
| 285 | * put the new socket at the end. */ | ||
| 286 | if (c->bio_chain != NULL) | ||
| 287 | { | ||
| 288 | if ((dbio=BIO_dup_chain(c->bio_chain)) == NULL) | ||
| 289 | goto err; | ||
| 290 | if (!BIO_push(dbio,bio)) goto err; | ||
| 291 | bio=dbio; | ||
| 292 | } | ||
| 293 | if (BIO_push(b,bio) == NULL) goto err; | ||
| 294 | |||
| 295 | c->state=ACPT_S_OK; | ||
| 296 | return(1); | ||
| 297 | err: | ||
| 298 | if (bio != NULL) | ||
| 299 | BIO_free(bio); | ||
| 300 | else if (s >= 0) | ||
| 301 | { | ||
| 302 | #ifdef WINDOWS | ||
| 303 | closesocket(s); | ||
| 304 | #else | ||
| 305 | close(s); | ||
| 306 | # endif | ||
| 307 | } | ||
| 308 | return(0); | ||
| 309 | break; | ||
| 310 | case ACPT_S_OK: | ||
| 311 | if (b->next_bio == NULL) | ||
| 312 | { | ||
| 313 | c->state=ACPT_S_GET_ACCEPT_SOCKET; | ||
| 314 | goto again; | ||
| 315 | } | ||
| 316 | return(1); | ||
| 317 | break; | ||
| 318 | default: | ||
| 319 | return(0); | ||
| 320 | break; | ||
| 321 | } | ||
| 322 | |||
| 323 | } | ||
| 324 | |||
| 325 | static int acpt_read(b,out,outl) | ||
| 326 | BIO *b; | ||
| 327 | char *out; | ||
| 328 | int outl; | ||
| 329 | { | ||
| 330 | int ret=0; | ||
| 331 | BIO_ACCEPT *data; | ||
| 332 | |||
| 333 | BIO_clear_retry_flags(b); | ||
| 334 | data=(BIO_ACCEPT *)b->ptr; | ||
| 335 | |||
| 336 | while (b->next_bio == NULL) | ||
| 337 | { | ||
| 338 | ret=acpt_state(b,data); | ||
| 339 | if (ret <= 0) return(ret); | ||
| 340 | } | ||
| 341 | |||
| 342 | ret=BIO_read(b->next_bio,out,outl); | ||
| 343 | BIO_copy_next_retry(b); | ||
| 344 | return(ret); | ||
| 345 | } | ||
| 346 | |||
| 347 | static int acpt_write(b,in,inl) | ||
| 348 | BIO *b; | ||
| 349 | char *in; | ||
| 350 | int inl; | ||
| 351 | { | ||
| 352 | int ret; | ||
| 353 | BIO_ACCEPT *data; | ||
| 354 | |||
| 355 | BIO_clear_retry_flags(b); | ||
| 356 | data=(BIO_ACCEPT *)b->ptr; | ||
| 357 | |||
| 358 | while (b->next_bio == NULL) | ||
| 359 | { | ||
| 360 | ret=acpt_state(b,data); | ||
| 361 | if (ret <= 0) return(ret); | ||
| 362 | } | ||
| 363 | |||
| 364 | ret=BIO_write(b->next_bio,in,inl); | ||
| 365 | BIO_copy_next_retry(b); | ||
| 366 | return(ret); | ||
| 367 | } | ||
| 368 | |||
| 369 | static long acpt_ctrl(b,cmd,num,ptr) | ||
| 370 | BIO *b; | ||
| 371 | int cmd; | ||
| 372 | long num; | ||
| 373 | char *ptr; | ||
| 374 | { | ||
| 375 | BIO *dbio; | ||
| 376 | int *ip; | ||
| 377 | long ret=1; | ||
| 378 | BIO_ACCEPT *data; | ||
| 379 | char **pp; | ||
| 380 | |||
| 381 | data=(BIO_ACCEPT *)b->ptr; | ||
| 382 | |||
| 383 | switch (cmd) | ||
| 384 | { | ||
| 385 | case BIO_CTRL_RESET: | ||
| 386 | ret=0; | ||
| 387 | data->state=ACPT_S_BEFORE; | ||
| 388 | acpt_close_socket(b); | ||
| 389 | b->flags=0; | ||
| 390 | break; | ||
| 391 | case BIO_C_DO_STATE_MACHINE: | ||
| 392 | /* use this one to start the connection */ | ||
| 393 | ret=(long)acpt_state(b,data); | ||
| 394 | break; | ||
| 395 | case BIO_C_SET_ACCEPT: | ||
| 396 | if (ptr != NULL) | ||
| 397 | { | ||
| 398 | if (num == 0) | ||
| 399 | { | ||
| 400 | b->init=1; | ||
| 401 | if (data->param_addr != NULL) | ||
| 402 | Free(data->param_addr); | ||
| 403 | data->param_addr=BUF_strdup(ptr); | ||
| 404 | } | ||
| 405 | else if (num == 1) | ||
| 406 | { | ||
| 407 | data->accept_nbio=(ptr != NULL); | ||
| 408 | } | ||
| 409 | else if (num == 2) | ||
| 410 | { | ||
| 411 | if (data->bio_chain != NULL) | ||
| 412 | BIO_free(data->bio_chain); | ||
| 413 | data->bio_chain=(BIO *)ptr; | ||
| 414 | } | ||
| 415 | } | ||
| 416 | break; | ||
| 417 | case BIO_C_SET_NBIO: | ||
| 418 | data->nbio=(int)num; | ||
| 419 | break; | ||
| 420 | case BIO_C_GET_FD: | ||
| 421 | if (b->init) | ||
| 422 | { | ||
| 423 | ip=(int *)ptr; | ||
| 424 | if (ip != NULL) | ||
| 425 | *ip=data->accept_sock; | ||
| 426 | ret=b->num; | ||
| 427 | } | ||
| 428 | else | ||
| 429 | ret= -1; | ||
| 430 | break; | ||
| 431 | case BIO_C_GET_ACCEPT: | ||
| 432 | if (b->init) | ||
| 433 | { | ||
| 434 | if (ptr != NULL) | ||
| 435 | { | ||
| 436 | pp=(char **)ptr; | ||
| 437 | *pp=data->param_addr; | ||
| 438 | } | ||
| 439 | else | ||
| 440 | ret= -1; | ||
| 441 | } | ||
| 442 | else | ||
| 443 | ret= -1; | ||
| 444 | break; | ||
| 445 | case BIO_CTRL_GET_CLOSE: | ||
| 446 | ret=b->shutdown; | ||
| 447 | break; | ||
| 448 | case BIO_CTRL_SET_CLOSE: | ||
| 449 | b->shutdown=(int)num; | ||
| 450 | break; | ||
| 451 | case BIO_CTRL_PENDING: | ||
| 452 | case BIO_CTRL_WPENDING: | ||
| 453 | ret=0; | ||
| 454 | break; | ||
| 455 | case BIO_CTRL_FLUSH: | ||
| 456 | break; | ||
| 457 | case BIO_CTRL_DUP: | ||
| 458 | dbio=(BIO *)ptr; | ||
| 459 | /* if (data->param_port) EAY EAY | ||
| 460 | BIO_set_port(dbio,data->param_port); | ||
| 461 | if (data->param_hostname) | ||
| 462 | BIO_set_hostname(dbio,data->param_hostname); | ||
| 463 | BIO_set_nbio(dbio,data->nbio); */ | ||
| 464 | break; | ||
| 465 | |||
| 466 | default: | ||
| 467 | ret=0; | ||
| 468 | break; | ||
| 469 | } | ||
| 470 | return(ret); | ||
| 471 | } | ||
| 472 | |||
| 473 | static int acpt_puts(bp,str) | ||
| 474 | BIO *bp; | ||
| 475 | char *str; | ||
| 476 | { | ||
| 477 | int n,ret; | ||
| 478 | |||
| 479 | n=strlen(str); | ||
| 480 | ret=acpt_write(bp,str,n); | ||
| 481 | return(ret); | ||
| 482 | } | ||
| 483 | |||
| 484 | BIO *BIO_new_accept(str) | ||
| 485 | char *str; | ||
| 486 | { | ||
| 487 | BIO *ret; | ||
| 488 | |||
| 489 | ret=BIO_new(BIO_s_accept()); | ||
| 490 | if (ret == NULL) return(NULL); | ||
| 491 | if (BIO_set_accept_port(ret,str)) | ||
| 492 | return(ret); | ||
| 493 | else | ||
| 494 | { | ||
| 495 | BIO_free(ret); | ||
| 496 | return(NULL); | ||
| 497 | } | ||
| 498 | } | ||
| 499 | |||
| 500 | #endif | ||
diff --git a/src/lib/libcrypto/bio/bss_conn.c b/src/lib/libcrypto/bio/bss_conn.c new file mode 100644 index 0000000000..6e547bf866 --- /dev/null +++ b/src/lib/libcrypto/bio/bss_conn.c | |||
| @@ -0,0 +1,648 @@ | |||
| 1 | /* crypto/bio/bss_conn.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 | #ifndef NO_SOCK | ||
| 60 | |||
| 61 | #include <stdio.h> | ||
| 62 | #include <errno.h> | ||
| 63 | #define USE_SOCKETS | ||
| 64 | #include "cryptlib.h" | ||
| 65 | #include "bio.h" | ||
| 66 | |||
| 67 | /* BIOerr(BIO_F_WSASTARTUP,BIO_R_WSASTARTUP ); */ | ||
| 68 | |||
| 69 | #ifdef WIN16 | ||
| 70 | #define SOCKET_PROTOCOL 0 /* more microsoft stupidity */ | ||
| 71 | #else | ||
| 72 | #define SOCKET_PROTOCOL IPPROTO_TCP | ||
| 73 | #endif | ||
| 74 | |||
| 75 | typedef struct bio_connect_st | ||
| 76 | { | ||
| 77 | int state; | ||
| 78 | |||
| 79 | char *param_hostname; | ||
| 80 | char *param_port; | ||
| 81 | int nbio; | ||
| 82 | |||
| 83 | unsigned char ip[4]; | ||
| 84 | short port; | ||
| 85 | |||
| 86 | struct sockaddr_in them; | ||
| 87 | |||
| 88 | /* int socket; this will be kept in bio->num so that it is | ||
| 89 | * compatable with the bss_sock bio */ | ||
| 90 | int error; | ||
| 91 | |||
| 92 | /* called when the connection is initially made | ||
| 93 | * callback(BIO,state,ret); The callback should return | ||
| 94 | * 'ret'. state is for compatablity with the ssl info_callback */ | ||
| 95 | int (*info_callback)(); | ||
| 96 | } BIO_CONNECT; | ||
| 97 | |||
| 98 | #ifndef NOPROTO | ||
| 99 | static int conn_write(BIO *h,char *buf,int num); | ||
| 100 | static int conn_read(BIO *h,char *buf,int size); | ||
| 101 | static int conn_puts(BIO *h,char *str); | ||
| 102 | static long conn_ctrl(BIO *h,int cmd,long arg1,char *arg2); | ||
| 103 | static int conn_new(BIO *h); | ||
| 104 | static int conn_free(BIO *data); | ||
| 105 | #else | ||
| 106 | static int conn_write(); | ||
| 107 | static int conn_read(); | ||
| 108 | static int conn_puts(); | ||
| 109 | static long conn_ctrl(); | ||
| 110 | static int conn_new(); | ||
| 111 | static int conn_free(); | ||
| 112 | #endif | ||
| 113 | |||
| 114 | #ifndef NOPROTO | ||
| 115 | |||
| 116 | static int conn_state(BIO *b, BIO_CONNECT *c); | ||
| 117 | static void conn_close_socket(BIO *data); | ||
| 118 | BIO_CONNECT *BIO_CONNECT_new(void ); | ||
| 119 | void BIO_CONNECT_free(BIO_CONNECT *a); | ||
| 120 | |||
| 121 | #else | ||
| 122 | |||
| 123 | static int conn_state(); | ||
| 124 | static void conn_close_socket(); | ||
| 125 | BIO_CONNECT *BIO_CONNECT_new(); | ||
| 126 | void BIO_CONNECT_free(); | ||
| 127 | |||
| 128 | #endif | ||
| 129 | |||
| 130 | static BIO_METHOD methods_connectp= | ||
| 131 | { | ||
| 132 | BIO_TYPE_CONNECT, | ||
| 133 | "socket connect", | ||
| 134 | conn_write, | ||
| 135 | conn_read, | ||
| 136 | conn_puts, | ||
| 137 | NULL, /* connect_gets, */ | ||
| 138 | conn_ctrl, | ||
| 139 | conn_new, | ||
| 140 | conn_free, | ||
| 141 | }; | ||
| 142 | |||
| 143 | static int conn_state(b,c) | ||
| 144 | BIO *b; | ||
| 145 | BIO_CONNECT *c; | ||
| 146 | { | ||
| 147 | int ret= -1,i; | ||
| 148 | unsigned long l; | ||
| 149 | char *p,*q; | ||
| 150 | int (*cb)()=NULL; | ||
| 151 | |||
| 152 | if (c->info_callback != NULL) | ||
| 153 | cb=c->info_callback; | ||
| 154 | |||
| 155 | for (;;) | ||
| 156 | { | ||
| 157 | switch (c->state) | ||
| 158 | { | ||
| 159 | case BIO_CONN_S_BEFORE: | ||
| 160 | p=c->param_hostname; | ||
| 161 | if (p == NULL) | ||
| 162 | { | ||
| 163 | BIOerr(BIO_F_CONN_STATE,BIO_R_NO_HOSTHNAME_SPECIFIED); | ||
| 164 | goto exit_loop; | ||
| 165 | } | ||
| 166 | for ( ; *p != '\0'; p++) | ||
| 167 | { | ||
| 168 | if ((*p == ':') || (*p == '/')) break; | ||
| 169 | } | ||
| 170 | |||
| 171 | i= *p; | ||
| 172 | if ((i == ':') || (i == '/')) | ||
| 173 | { | ||
| 174 | |||
| 175 | *(p++)='\0'; | ||
| 176 | if (i == ':') | ||
| 177 | { | ||
| 178 | for (q=p; *q; q++) | ||
| 179 | if (*q == '/') | ||
| 180 | { | ||
| 181 | *q='\0'; | ||
| 182 | break; | ||
| 183 | } | ||
| 184 | if (c->param_port != NULL) | ||
| 185 | Free(c->param_port); | ||
| 186 | c->param_port=BUF_strdup(p); | ||
| 187 | } | ||
| 188 | } | ||
| 189 | |||
| 190 | if (p == NULL) | ||
| 191 | { | ||
| 192 | BIOerr(BIO_F_CONN_STATE,BIO_R_NO_PORT_SPECIFIED); | ||
| 193 | ERR_add_error_data(2,"host=",c->param_hostname); | ||
| 194 | goto exit_loop; | ||
| 195 | } | ||
| 196 | c->state=BIO_CONN_S_GET_IP; | ||
| 197 | break; | ||
| 198 | |||
| 199 | case BIO_CONN_S_GET_IP: | ||
| 200 | if (BIO_get_host_ip(c->param_hostname,&(c->ip[0])) <= 0) | ||
| 201 | goto exit_loop; | ||
| 202 | c->state=BIO_CONN_S_GET_PORT; | ||
| 203 | break; | ||
| 204 | |||
| 205 | case BIO_CONN_S_GET_PORT: | ||
| 206 | if (BIO_get_port(c->param_port,&c->port) <= 0) | ||
| 207 | goto exit_loop; | ||
| 208 | c->state=BIO_CONN_S_CREATE_SOCKET; | ||
| 209 | break; | ||
| 210 | |||
| 211 | case BIO_CONN_S_CREATE_SOCKET: | ||
| 212 | /* now setup address */ | ||
| 213 | memset((char *)&c->them,0,sizeof(c->them)); | ||
| 214 | c->them.sin_family=AF_INET; | ||
| 215 | c->them.sin_port=htons((unsigned short)c->port); | ||
| 216 | l=(unsigned long) | ||
| 217 | ((unsigned long)c->ip[0]<<24L)| | ||
| 218 | ((unsigned long)c->ip[1]<<16L)| | ||
| 219 | ((unsigned long)c->ip[2]<< 8L)| | ||
| 220 | ((unsigned long)c->ip[3]); | ||
| 221 | c->them.sin_addr.s_addr=htonl(l); | ||
| 222 | c->state=BIO_CONN_S_CREATE_SOCKET; | ||
| 223 | |||
| 224 | ret=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL); | ||
| 225 | if (ret == INVALID_SOCKET) | ||
| 226 | { | ||
| 227 | SYSerr(SYS_F_SOCKET,get_last_socket_error()); | ||
| 228 | ERR_add_error_data(4,"host=",c->param_hostname, | ||
| 229 | ":",c->param_port); | ||
| 230 | BIOerr(BIO_F_CONN_STATE,BIO_R_UNABLE_TO_CREATE_SOCKET); | ||
| 231 | goto exit_loop; | ||
| 232 | } | ||
| 233 | b->num=ret; | ||
| 234 | c->state=BIO_CONN_S_NBIO; | ||
| 235 | break; | ||
| 236 | |||
| 237 | case BIO_CONN_S_NBIO: | ||
| 238 | #ifdef FIONBIO | ||
| 239 | if (c->nbio) | ||
| 240 | { | ||
| 241 | l=1; | ||
| 242 | ret=BIO_socket_ioctl(b->num,FIONBIO,&l); | ||
| 243 | if (ret < 0) | ||
| 244 | { | ||
| 245 | BIOerr(BIO_F_CONN_STATE,BIO_R_ERROR_SETTING_NBIO); | ||
| 246 | ERR_add_error_data(4,"host=", | ||
| 247 | c->param_hostname, | ||
| 248 | ":",c->param_port); | ||
| 249 | goto exit_loop; | ||
| 250 | } | ||
| 251 | } | ||
| 252 | #endif | ||
| 253 | c->state=BIO_CONN_S_CONNECT; | ||
| 254 | |||
| 255 | #ifdef SO_KEEPALIVE | ||
| 256 | i=1; | ||
| 257 | i=setsockopt(b->num,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i)); | ||
| 258 | if (i < 0) | ||
| 259 | { | ||
| 260 | SYSerr(SYS_F_SOCKET,get_last_socket_error()); | ||
| 261 | ERR_add_error_data(4,"host=",c->param_hostname, | ||
| 262 | ":",c->param_port); | ||
| 263 | BIOerr(BIO_F_CONN_STATE,BIO_R_KEEPALIVE); | ||
| 264 | goto exit_loop; | ||
| 265 | } | ||
| 266 | #endif | ||
| 267 | break; | ||
| 268 | |||
| 269 | case BIO_CONN_S_CONNECT: | ||
| 270 | BIO_clear_retry_flags(b); | ||
| 271 | ret=connect(b->num, | ||
| 272 | (struct sockaddr *)&c->them, | ||
| 273 | sizeof(c->them)); | ||
| 274 | b->retry_reason=0; | ||
| 275 | if (ret < 0) | ||
| 276 | { | ||
| 277 | if (BIO_sock_should_retry(ret)) | ||
| 278 | { | ||
| 279 | BIO_set_retry_special(b); | ||
| 280 | c->state=BIO_CONN_S_BLOCKED_CONNECT; | ||
| 281 | b->retry_reason=BIO_RR_CONNECT; | ||
| 282 | } | ||
| 283 | else | ||
| 284 | { | ||
| 285 | SYSerr(SYS_F_CONNECT,get_last_socket_error()); | ||
| 286 | ERR_add_error_data(4,"host=", | ||
| 287 | c->param_hostname, | ||
| 288 | ":",c->param_port); | ||
| 289 | BIOerr(BIO_F_CONN_STATE,BIO_R_CONNECT_ERROR); | ||
| 290 | } | ||
| 291 | goto exit_loop; | ||
| 292 | } | ||
| 293 | else | ||
| 294 | c->state=BIO_CONN_S_OK; | ||
| 295 | break; | ||
| 296 | |||
| 297 | case BIO_CONN_S_BLOCKED_CONNECT: | ||
| 298 | i=BIO_sock_error(b->num); | ||
| 299 | if (i) | ||
| 300 | { | ||
| 301 | BIO_clear_retry_flags(b); | ||
| 302 | SYSerr(SYS_F_CONNECT,i); | ||
| 303 | ERR_add_error_data(4,"host=", | ||
| 304 | c->param_hostname, | ||
| 305 | ":",c->param_port); | ||
| 306 | BIOerr(BIO_F_CONN_STATE,BIO_R_NBIO_CONNECT_ERROR); | ||
| 307 | ret=0; | ||
| 308 | goto exit_loop; | ||
| 309 | } | ||
| 310 | else | ||
| 311 | c->state=BIO_CONN_S_OK; | ||
| 312 | break; | ||
| 313 | |||
| 314 | case BIO_CONN_S_OK: | ||
| 315 | ret=1; | ||
| 316 | goto exit_loop; | ||
| 317 | default: | ||
| 318 | abort(); | ||
| 319 | goto exit_loop; | ||
| 320 | } | ||
| 321 | |||
| 322 | if (cb != NULL) | ||
| 323 | { | ||
| 324 | if (!(ret=cb((BIO *)b,c->state,ret))) | ||
| 325 | goto end; | ||
| 326 | } | ||
| 327 | } | ||
| 328 | |||
| 329 | if (1) | ||
| 330 | { | ||
| 331 | exit_loop: | ||
| 332 | if (cb != NULL) | ||
| 333 | ret=cb((BIO *)b,c->state,ret); | ||
| 334 | } | ||
| 335 | end: | ||
| 336 | return(ret); | ||
| 337 | } | ||
| 338 | |||
| 339 | BIO_CONNECT *BIO_CONNECT_new() | ||
| 340 | { | ||
| 341 | BIO_CONNECT *ret; | ||
| 342 | |||
| 343 | if ((ret=(BIO_CONNECT *)Malloc(sizeof(BIO_CONNECT))) == NULL) | ||
| 344 | return(NULL); | ||
| 345 | ret->state=BIO_CONN_S_BEFORE; | ||
| 346 | ret->param_hostname=NULL; | ||
| 347 | ret->param_port=NULL; | ||
| 348 | ret->info_callback=NULL; | ||
| 349 | ret->nbio=0; | ||
| 350 | ret->ip[0]=0; | ||
| 351 | ret->ip[1]=0; | ||
| 352 | ret->ip[2]=0; | ||
| 353 | ret->ip[3]=0; | ||
| 354 | ret->port=0; | ||
| 355 | memset((char *)&ret->them,0,sizeof(ret->them)); | ||
| 356 | ret->error=0; | ||
| 357 | return(ret); | ||
| 358 | } | ||
| 359 | |||
| 360 | void BIO_CONNECT_free(a) | ||
| 361 | BIO_CONNECT *a; | ||
| 362 | { | ||
| 363 | if (a->param_hostname != NULL) | ||
| 364 | Free(a->param_hostname); | ||
| 365 | if (a->param_port != NULL) | ||
| 366 | Free(a->param_port); | ||
| 367 | Free(a); | ||
| 368 | } | ||
| 369 | |||
| 370 | BIO_METHOD *BIO_s_connect() | ||
| 371 | { | ||
| 372 | return(&methods_connectp); | ||
| 373 | } | ||
| 374 | |||
| 375 | static int conn_new(bi) | ||
| 376 | BIO *bi; | ||
| 377 | { | ||
| 378 | bi->init=0; | ||
| 379 | bi->num=INVALID_SOCKET; | ||
| 380 | bi->flags=0; | ||
| 381 | if ((bi->ptr=(char *)BIO_CONNECT_new()) == NULL) | ||
| 382 | return(0); | ||
| 383 | else | ||
| 384 | return(1); | ||
| 385 | } | ||
| 386 | |||
| 387 | static void conn_close_socket(bio) | ||
| 388 | BIO *bio; | ||
| 389 | { | ||
| 390 | BIO_CONNECT *c; | ||
| 391 | |||
| 392 | c=(BIO_CONNECT *)bio->ptr; | ||
| 393 | if (bio->num != INVALID_SOCKET) | ||
| 394 | { | ||
| 395 | /* Only do a shutdown if things were established */ | ||
| 396 | if (c->state == BIO_CONN_S_OK) | ||
| 397 | shutdown(bio->num,2); | ||
| 398 | # ifdef WINDOWS | ||
| 399 | closesocket(bio->num); | ||
| 400 | # else | ||
| 401 | close(bio->num); | ||
| 402 | # endif | ||
| 403 | bio->num=INVALID_SOCKET; | ||
| 404 | } | ||
| 405 | } | ||
| 406 | |||
| 407 | static int conn_free(a) | ||
| 408 | BIO *a; | ||
| 409 | { | ||
| 410 | BIO_CONNECT *data; | ||
| 411 | |||
| 412 | if (a == NULL) return(0); | ||
| 413 | data=(BIO_CONNECT *)a->ptr; | ||
| 414 | |||
| 415 | if (a->shutdown) | ||
| 416 | { | ||
| 417 | conn_close_socket(a); | ||
| 418 | BIO_CONNECT_free(data); | ||
| 419 | a->ptr=NULL; | ||
| 420 | a->flags=0; | ||
| 421 | a->init=0; | ||
| 422 | } | ||
| 423 | return(1); | ||
| 424 | } | ||
| 425 | |||
| 426 | static int conn_read(b,out,outl) | ||
| 427 | BIO *b; | ||
| 428 | char *out; | ||
| 429 | int outl; | ||
| 430 | { | ||
| 431 | int ret=0; | ||
| 432 | BIO_CONNECT *data; | ||
| 433 | |||
| 434 | data=(BIO_CONNECT *)b->ptr; | ||
| 435 | if (data->state != BIO_CONN_S_OK) | ||
| 436 | { | ||
| 437 | ret=conn_state(b,data); | ||
| 438 | if (ret <= 0) | ||
| 439 | return(ret); | ||
| 440 | } | ||
| 441 | |||
| 442 | if (out != NULL) | ||
| 443 | { | ||
| 444 | clear_socket_error(); | ||
| 445 | #if defined(WINDOWS) | ||
| 446 | ret=recv(b->num,out,outl,0); | ||
| 447 | #else | ||
| 448 | ret=read(b->num,out,outl); | ||
| 449 | #endif | ||
| 450 | BIO_clear_retry_flags(b); | ||
| 451 | if (ret <= 0) | ||
| 452 | { | ||
| 453 | if (BIO_sock_should_retry(ret)) | ||
| 454 | BIO_set_retry_read(b); | ||
| 455 | } | ||
| 456 | } | ||
| 457 | return(ret); | ||
| 458 | } | ||
| 459 | |||
| 460 | static int conn_write(b,in,inl) | ||
| 461 | BIO *b; | ||
| 462 | char *in; | ||
| 463 | int inl; | ||
| 464 | { | ||
| 465 | int ret; | ||
| 466 | BIO_CONNECT *data; | ||
| 467 | |||
| 468 | data=(BIO_CONNECT *)b->ptr; | ||
| 469 | if (data->state != BIO_CONN_S_OK) | ||
| 470 | { | ||
| 471 | ret=conn_state(b,data); | ||
| 472 | if (ret <= 0) return(ret); | ||
| 473 | } | ||
| 474 | |||
| 475 | clear_socket_error(); | ||
| 476 | #if defined(WINDOWS) | ||
| 477 | ret=send(b->num,in,inl,0); | ||
| 478 | #else | ||
| 479 | ret=write(b->num,in,inl); | ||
| 480 | #endif | ||
| 481 | BIO_clear_retry_flags(b); | ||
| 482 | if (ret <= 0) | ||
| 483 | { | ||
| 484 | if (BIO_sock_should_retry(ret)) | ||
| 485 | BIO_set_retry_write(b); | ||
| 486 | } | ||
| 487 | return(ret); | ||
| 488 | } | ||
| 489 | |||
| 490 | static long conn_ctrl(b,cmd,num,ptr) | ||
| 491 | BIO *b; | ||
| 492 | int cmd; | ||
| 493 | long num; | ||
| 494 | char *ptr; | ||
| 495 | { | ||
| 496 | BIO *dbio; | ||
| 497 | int *ip; | ||
| 498 | char **pptr; | ||
| 499 | long ret=1; | ||
| 500 | BIO_CONNECT *data; | ||
| 501 | |||
| 502 | data=(BIO_CONNECT *)b->ptr; | ||
| 503 | |||
| 504 | switch (cmd) | ||
| 505 | { | ||
| 506 | case BIO_CTRL_RESET: | ||
| 507 | ret=0; | ||
| 508 | data->state=BIO_CONN_S_BEFORE; | ||
| 509 | conn_close_socket(b); | ||
| 510 | b->flags=0; | ||
| 511 | break; | ||
| 512 | case BIO_C_DO_STATE_MACHINE: | ||
| 513 | /* use this one to start the connection */ | ||
| 514 | if (!data->state != BIO_CONN_S_OK) | ||
| 515 | ret=(long)conn_state(b,data); | ||
| 516 | else | ||
| 517 | ret=1; | ||
| 518 | break; | ||
| 519 | case BIO_C_GET_CONNECT: | ||
| 520 | if (ptr != NULL) | ||
| 521 | { | ||
| 522 | pptr=(char **)ptr; | ||
| 523 | if (num == 0) | ||
| 524 | { | ||
| 525 | *pptr=data->param_hostname; | ||
| 526 | |||
| 527 | } | ||
| 528 | else if (num == 1) | ||
| 529 | { | ||
| 530 | *pptr=data->param_port; | ||
| 531 | } | ||
| 532 | else if (num == 2) | ||
| 533 | { | ||
| 534 | *pptr= (char *)&(data->ip[0]); | ||
| 535 | } | ||
| 536 | else if (num == 3) | ||
| 537 | { | ||
| 538 | *((int *)ptr)=data->port; | ||
| 539 | } | ||
| 540 | if ((!b->init) || (ptr == NULL)) | ||
| 541 | *pptr="not initalised"; | ||
| 542 | ret=1; | ||
| 543 | } | ||
| 544 | break; | ||
| 545 | case BIO_C_SET_CONNECT: | ||
| 546 | if (ptr != NULL) | ||
| 547 | { | ||
| 548 | b->init=1; | ||
| 549 | if (num == 0) | ||
| 550 | { | ||
| 551 | if (data->param_hostname != NULL) | ||
| 552 | Free(data->param_hostname); | ||
| 553 | data->param_hostname=BUF_strdup(ptr); | ||
| 554 | } | ||
| 555 | else if (num == 1) | ||
| 556 | { | ||
| 557 | if (data->param_port != NULL) | ||
| 558 | Free(data->param_port); | ||
| 559 | data->param_port=BUF_strdup(ptr); | ||
| 560 | } | ||
| 561 | else if (num == 2) | ||
| 562 | memcpy(data->ip,ptr,4); | ||
| 563 | else if (num == 3) | ||
| 564 | data->port= *(int *)ptr; | ||
| 565 | } | ||
| 566 | break; | ||
| 567 | case BIO_C_SET_NBIO: | ||
| 568 | data->nbio=(int)num; | ||
| 569 | break; | ||
| 570 | case BIO_C_GET_FD: | ||
| 571 | if (b->init) | ||
| 572 | { | ||
| 573 | ip=(int *)ptr; | ||
| 574 | if (ip != NULL) | ||
| 575 | *ip=b->num; | ||
| 576 | ret=b->num; | ||
| 577 | } | ||
| 578 | else | ||
| 579 | ret= -1; | ||
| 580 | break; | ||
| 581 | case BIO_CTRL_GET_CLOSE: | ||
| 582 | ret=b->shutdown; | ||
| 583 | break; | ||
| 584 | case BIO_CTRL_SET_CLOSE: | ||
| 585 | b->shutdown=(int)num; | ||
| 586 | break; | ||
| 587 | case BIO_CTRL_PENDING: | ||
| 588 | case BIO_CTRL_WPENDING: | ||
| 589 | ret=0; | ||
| 590 | break; | ||
| 591 | case BIO_CTRL_FLUSH: | ||
| 592 | break; | ||
| 593 | case BIO_CTRL_DUP: | ||
| 594 | dbio=(BIO *)ptr; | ||
| 595 | if (data->param_port) | ||
| 596 | BIO_set_conn_port(dbio,data->param_port); | ||
| 597 | if (data->param_hostname) | ||
| 598 | BIO_set_conn_hostname(dbio,data->param_hostname); | ||
| 599 | BIO_set_nbio(dbio,data->nbio); | ||
| 600 | BIO_set_info_callback(dbio,data->info_callback); | ||
| 601 | break; | ||
| 602 | case BIO_CTRL_SET_CALLBACK: | ||
| 603 | data->info_callback=(int (*)())ptr; | ||
| 604 | break; | ||
| 605 | case BIO_CTRL_GET_CALLBACK: | ||
| 606 | { | ||
| 607 | int (**fptr)(); | ||
| 608 | |||
| 609 | fptr=(int (**)())ptr; | ||
| 610 | *fptr=data->info_callback; | ||
| 611 | } | ||
| 612 | break; | ||
| 613 | default: | ||
| 614 | ret=0; | ||
| 615 | break; | ||
| 616 | } | ||
| 617 | return(ret); | ||
| 618 | } | ||
| 619 | |||
| 620 | static int conn_puts(bp,str) | ||
| 621 | BIO *bp; | ||
| 622 | char *str; | ||
| 623 | { | ||
| 624 | int n,ret; | ||
| 625 | |||
| 626 | n=strlen(str); | ||
| 627 | ret=conn_write(bp,str,n); | ||
| 628 | return(ret); | ||
| 629 | } | ||
| 630 | |||
| 631 | BIO *BIO_new_connect(str) | ||
| 632 | char *str; | ||
| 633 | { | ||
| 634 | BIO *ret; | ||
| 635 | |||
| 636 | ret=BIO_new(BIO_s_connect()); | ||
| 637 | if (ret == NULL) return(NULL); | ||
| 638 | if (BIO_set_conn_hostname(ret,str)) | ||
| 639 | return(ret); | ||
| 640 | else | ||
| 641 | { | ||
| 642 | BIO_free(ret); | ||
| 643 | return(NULL); | ||
| 644 | } | ||
| 645 | } | ||
| 646 | |||
| 647 | #endif | ||
| 648 | |||
diff --git a/src/lib/libcrypto/bio/bss_fd.c b/src/lib/libcrypto/bio/bss_fd.c new file mode 100644 index 0000000000..686c4909a2 --- /dev/null +++ b/src/lib/libcrypto/bio/bss_fd.c | |||
| @@ -0,0 +1,62 @@ | |||
| 1 | /* crypto/bio/bss_fd.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 | #define BIO_FD | ||
| 60 | #include "bss_sock.c" | ||
| 61 | #undef BIO_FD | ||
| 62 | |||
diff --git a/src/lib/libcrypto/bio/bss_file.c b/src/lib/libcrypto/bio/bss_file.c new file mode 100644 index 0000000000..1484cf849e --- /dev/null +++ b/src/lib/libcrypto/bio/bss_file.c | |||
| @@ -0,0 +1,339 @@ | |||
| 1 | /* crypto/bio/bss_file.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 | /* | ||
| 60 | * 03-Dec-1997 rdenny@dc3.com Fix bug preventing use of stdin/stdout | ||
| 61 | * with binary data (e.g. asn1parse -inform DER < xxx) under | ||
| 62 | * Windows | ||
| 63 | */ | ||
| 64 | |||
| 65 | #ifndef HEADER_BSS_FILE_C | ||
| 66 | #define HEADER_BSS_FILE_C | ||
| 67 | |||
| 68 | #include <stdio.h> | ||
| 69 | #include <errno.h> | ||
| 70 | #include "cryptlib.h" | ||
| 71 | #include "bio.h" | ||
| 72 | #include "err.h" | ||
| 73 | |||
| 74 | #if !defined(NO_STDIO) | ||
| 75 | |||
| 76 | #ifndef NOPROTO | ||
| 77 | static int MS_CALLBACK file_write(BIO *h,char *buf,int num); | ||
| 78 | static int MS_CALLBACK file_read(BIO *h,char *buf,int size); | ||
| 79 | static int MS_CALLBACK file_puts(BIO *h,char *str); | ||
| 80 | static int MS_CALLBACK file_gets(BIO *h,char *str,int size); | ||
| 81 | static long MS_CALLBACK file_ctrl(BIO *h,int cmd,long arg1,char *arg2); | ||
| 82 | static int MS_CALLBACK file_new(BIO *h); | ||
| 83 | static int MS_CALLBACK file_free(BIO *data); | ||
| 84 | #else | ||
| 85 | static int MS_CALLBACK file_write(); | ||
| 86 | static int MS_CALLBACK file_read(); | ||
| 87 | static int MS_CALLBACK file_puts(); | ||
| 88 | static int MS_CALLBACK file_gets(); | ||
| 89 | static long MS_CALLBACK file_ctrl(); | ||
| 90 | static int MS_CALLBACK file_new(); | ||
| 91 | static int MS_CALLBACK file_free(); | ||
| 92 | #endif | ||
| 93 | |||
| 94 | static BIO_METHOD methods_filep= | ||
| 95 | { | ||
| 96 | BIO_TYPE_FILE, | ||
| 97 | "FILE pointer", | ||
| 98 | file_write, | ||
| 99 | file_read, | ||
| 100 | file_puts, | ||
| 101 | file_gets, | ||
| 102 | file_ctrl, | ||
| 103 | file_new, | ||
| 104 | file_free, | ||
| 105 | }; | ||
| 106 | |||
| 107 | BIO *BIO_new_file(filename,mode) | ||
| 108 | char *filename; | ||
| 109 | char *mode; | ||
| 110 | { | ||
| 111 | BIO *ret; | ||
| 112 | FILE *file; | ||
| 113 | |||
| 114 | if ((file=fopen(filename,mode)) == NULL) | ||
| 115 | { | ||
| 116 | SYSerr(SYS_F_FOPEN,get_last_sys_error()); | ||
| 117 | ERR_add_error_data(5,"fopen('",filename,"','",mode,"')"); | ||
| 118 | BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB); | ||
| 119 | return(NULL); | ||
| 120 | } | ||
| 121 | if ((ret=BIO_new(BIO_s_file_internal())) == NULL) | ||
| 122 | return(NULL); | ||
| 123 | |||
| 124 | BIO_set_fp(ret,file,BIO_CLOSE); | ||
| 125 | return(ret); | ||
| 126 | } | ||
| 127 | |||
| 128 | BIO *BIO_new_fp(stream,close_flag) | ||
| 129 | FILE *stream; | ||
| 130 | int close_flag; | ||
| 131 | { | ||
| 132 | BIO *ret; | ||
| 133 | |||
| 134 | if ((ret=BIO_new(BIO_s_file())) == NULL) | ||
| 135 | return(NULL); | ||
| 136 | |||
| 137 | BIO_set_fp(ret,stream,close_flag); | ||
| 138 | return(ret); | ||
| 139 | } | ||
| 140 | |||
| 141 | BIO_METHOD *BIO_s_file() | ||
| 142 | { | ||
| 143 | return(&methods_filep); | ||
| 144 | } | ||
| 145 | |||
| 146 | static int MS_CALLBACK file_new(bi) | ||
| 147 | BIO *bi; | ||
| 148 | { | ||
| 149 | bi->init=0; | ||
| 150 | bi->num=0; | ||
| 151 | bi->ptr=NULL; | ||
| 152 | return(1); | ||
| 153 | } | ||
| 154 | |||
| 155 | static int MS_CALLBACK file_free(a) | ||
| 156 | BIO *a; | ||
| 157 | { | ||
| 158 | if (a == NULL) return(0); | ||
| 159 | if (a->shutdown) | ||
| 160 | { | ||
| 161 | if ((a->init) && (a->ptr != NULL)) | ||
| 162 | { | ||
| 163 | fclose((FILE *)a->ptr); | ||
| 164 | a->ptr=NULL; | ||
| 165 | } | ||
| 166 | a->init=0; | ||
| 167 | } | ||
| 168 | return(1); | ||
| 169 | } | ||
| 170 | |||
| 171 | static int MS_CALLBACK file_read(b,out,outl) | ||
| 172 | BIO *b; | ||
| 173 | char *out; | ||
| 174 | int outl; | ||
| 175 | { | ||
| 176 | int ret=0; | ||
| 177 | |||
| 178 | if (b->init && (out != NULL)) | ||
| 179 | { | ||
| 180 | ret=fread(out,1,(int)outl,(FILE *)b->ptr); | ||
| 181 | } | ||
| 182 | return(ret); | ||
| 183 | } | ||
| 184 | |||
| 185 | static int MS_CALLBACK file_write(b,in,inl) | ||
| 186 | BIO *b; | ||
| 187 | char *in; | ||
| 188 | int inl; | ||
| 189 | { | ||
| 190 | int ret=0; | ||
| 191 | |||
| 192 | if (b->init && (in != NULL)) | ||
| 193 | { | ||
| 194 | if (fwrite(in,(int)inl,1,(FILE *)b->ptr)) | ||
| 195 | ret=inl; | ||
| 196 | /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */ | ||
| 197 | /* acording to Tim Hudson <tjh@cryptsoft.com>, the commented | ||
| 198 | * out version above can cause 'inl' write calls under | ||
| 199 | * some stupid stdio implementations (VMS) */ | ||
| 200 | } | ||
| 201 | return(ret); | ||
| 202 | } | ||
| 203 | |||
| 204 | static long MS_CALLBACK file_ctrl(b,cmd,num,ptr) | ||
| 205 | BIO *b; | ||
| 206 | int cmd; | ||
| 207 | long num; | ||
| 208 | char *ptr; | ||
| 209 | { | ||
| 210 | long ret=1; | ||
| 211 | FILE *fp=(FILE *)b->ptr; | ||
| 212 | FILE **fpp; | ||
| 213 | char p[4]; | ||
| 214 | |||
| 215 | switch (cmd) | ||
| 216 | { | ||
| 217 | case BIO_CTRL_RESET: | ||
| 218 | ret=(long)fseek(fp,num,0); | ||
| 219 | break; | ||
| 220 | case BIO_CTRL_EOF: | ||
| 221 | ret=(long)feof(fp); | ||
| 222 | break; | ||
| 223 | case BIO_CTRL_INFO: | ||
| 224 | ret=ftell(fp); | ||
| 225 | break; | ||
| 226 | case BIO_C_SET_FILE_PTR: | ||
| 227 | file_free(b); | ||
| 228 | b->shutdown=(int)num; | ||
| 229 | b->ptr=(char *)ptr; | ||
| 230 | b->init=1; | ||
| 231 | #if defined(MSDOS) || defined(WINDOWS) | ||
| 232 | /* Set correct text/binary mode */ | ||
| 233 | if (num & BIO_FP_TEXT) | ||
| 234 | _setmode(fileno((FILE *)ptr),_O_TEXT); | ||
| 235 | else | ||
| 236 | _setmode(fileno((FILE *)ptr),_O_BINARY); | ||
| 237 | #endif | ||
| 238 | break; | ||
| 239 | case BIO_C_SET_FILENAME: | ||
| 240 | file_free(b); | ||
| 241 | b->shutdown=(int)num&BIO_CLOSE; | ||
| 242 | if (num & BIO_FP_APPEND) | ||
| 243 | { | ||
| 244 | if (num & BIO_FP_READ) | ||
| 245 | strcpy(p,"a+"); | ||
| 246 | else strcpy(p,"a"); | ||
| 247 | } | ||
| 248 | else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE)) | ||
| 249 | strcpy(p,"r+"); | ||
| 250 | else if (num & BIO_FP_WRITE) | ||
| 251 | strcpy(p,"w"); | ||
| 252 | else if (num & BIO_FP_READ) | ||
| 253 | strcpy(p,"r"); | ||
| 254 | else | ||
| 255 | { | ||
| 256 | BIOerr(BIO_F_FILE_CTRL,BIO_R_BAD_FOPEN_MODE); | ||
| 257 | ret=0; | ||
| 258 | break; | ||
| 259 | } | ||
| 260 | #if defined(MSDOS) || defined(WINDOWS) | ||
| 261 | if (!(num & BIO_FP_TEXT)) | ||
| 262 | strcat(p,"b"); | ||
| 263 | else | ||
| 264 | strcat(p,"t"); | ||
| 265 | #endif | ||
| 266 | fp=fopen(ptr,p); | ||
| 267 | if (fp == NULL) | ||
| 268 | { | ||
| 269 | SYSerr(SYS_F_FOPEN,get_last_sys_error()); | ||
| 270 | ERR_add_error_data(5,"fopen('",ptr,"','",p,"')"); | ||
| 271 | BIOerr(BIO_F_FILE_CTRL,ERR_R_SYS_LIB); | ||
| 272 | ret=0; | ||
| 273 | break; | ||
| 274 | } | ||
| 275 | b->ptr=(char *)fp; | ||
| 276 | b->init=1; | ||
| 277 | break; | ||
| 278 | case BIO_C_GET_FILE_PTR: | ||
| 279 | /* the ptr parameter is actually a FILE ** in this case. */ | ||
| 280 | if (ptr != NULL) | ||
| 281 | { | ||
| 282 | fpp=(FILE **)ptr; | ||
| 283 | *fpp=(FILE *)b->ptr; | ||
| 284 | } | ||
| 285 | break; | ||
| 286 | case BIO_CTRL_GET_CLOSE: | ||
| 287 | ret=(long)b->shutdown; | ||
| 288 | break; | ||
| 289 | case BIO_CTRL_SET_CLOSE: | ||
| 290 | b->shutdown=(int)num; | ||
| 291 | break; | ||
| 292 | case BIO_CTRL_FLUSH: | ||
| 293 | fflush((FILE *)b->ptr); | ||
| 294 | break; | ||
| 295 | case BIO_CTRL_DUP: | ||
| 296 | ret=1; | ||
| 297 | break; | ||
| 298 | |||
| 299 | case BIO_CTRL_WPENDING: | ||
| 300 | case BIO_CTRL_PENDING: | ||
| 301 | case BIO_CTRL_PUSH: | ||
| 302 | case BIO_CTRL_POP: | ||
| 303 | default: | ||
| 304 | ret=0; | ||
| 305 | break; | ||
| 306 | } | ||
| 307 | return(ret); | ||
| 308 | } | ||
| 309 | |||
| 310 | static int MS_CALLBACK file_gets(bp,buf,size) | ||
| 311 | BIO *bp; | ||
| 312 | char *buf; | ||
| 313 | int size; | ||
| 314 | { | ||
| 315 | int ret=0; | ||
| 316 | |||
| 317 | buf[0]='\0'; | ||
| 318 | fgets(buf,size,(FILE *)bp->ptr); | ||
| 319 | if (buf[0] != '\0') | ||
| 320 | ret=strlen(buf); | ||
| 321 | return(ret); | ||
| 322 | } | ||
| 323 | |||
| 324 | static int MS_CALLBACK file_puts(bp,str) | ||
| 325 | BIO *bp; | ||
| 326 | char *str; | ||
| 327 | { | ||
| 328 | int n,ret; | ||
| 329 | |||
| 330 | n=strlen(str); | ||
| 331 | ret=file_write(bp,str,n); | ||
| 332 | return(ret); | ||
| 333 | } | ||
| 334 | |||
| 335 | #endif /* NO_STDIO */ | ||
| 336 | |||
| 337 | #endif /* HEADER_BSS_FILE_C */ | ||
| 338 | |||
| 339 | |||
diff --git a/src/lib/libcrypto/bio/bss_mem.c b/src/lib/libcrypto/bio/bss_mem.c new file mode 100644 index 0000000000..40c4e39f02 --- /dev/null +++ b/src/lib/libcrypto/bio/bss_mem.c | |||
| @@ -0,0 +1,297 @@ | |||
| 1 | /* crypto/bio/bss_mem.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 <errno.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "bio.h" | ||
| 63 | |||
| 64 | #ifndef NOPROTO | ||
| 65 | static int mem_write(BIO *h,char *buf,int num); | ||
| 66 | static int mem_read(BIO *h,char *buf,int size); | ||
| 67 | static int mem_puts(BIO *h,char *str); | ||
| 68 | static int mem_gets(BIO *h,char *str,int size); | ||
| 69 | static long mem_ctrl(BIO *h,int cmd,long arg1,char *arg2); | ||
| 70 | static int mem_new(BIO *h); | ||
| 71 | static int mem_free(BIO *data); | ||
| 72 | #else | ||
| 73 | static int mem_write(); | ||
| 74 | static int mem_read(); | ||
| 75 | static int mem_puts(); | ||
| 76 | static int mem_gets(); | ||
| 77 | static long mem_ctrl(); | ||
| 78 | static int mem_new(); | ||
| 79 | static int mem_free(); | ||
| 80 | #endif | ||
| 81 | |||
| 82 | static BIO_METHOD mem_method= | ||
| 83 | { | ||
| 84 | BIO_TYPE_MEM, | ||
| 85 | "memory buffer", | ||
| 86 | mem_write, | ||
| 87 | mem_read, | ||
| 88 | mem_puts, | ||
| 89 | mem_gets, | ||
| 90 | mem_ctrl, | ||
| 91 | mem_new, | ||
| 92 | mem_free, | ||
| 93 | }; | ||
| 94 | |||
| 95 | BIO_METHOD *BIO_s_mem() | ||
| 96 | { | ||
| 97 | return(&mem_method); | ||
| 98 | } | ||
| 99 | |||
| 100 | static int mem_new(bi) | ||
| 101 | BIO *bi; | ||
| 102 | { | ||
| 103 | BUF_MEM *b; | ||
| 104 | |||
| 105 | if ((b=BUF_MEM_new()) == NULL) | ||
| 106 | return(0); | ||
| 107 | bi->shutdown=1; | ||
| 108 | bi->init=1; | ||
| 109 | bi->num=0; | ||
| 110 | bi->ptr=(char *)b; | ||
| 111 | return(1); | ||
| 112 | } | ||
| 113 | |||
| 114 | static int mem_free(a) | ||
| 115 | BIO *a; | ||
| 116 | { | ||
| 117 | if (a == NULL) return(0); | ||
| 118 | if (a->shutdown) | ||
| 119 | { | ||
| 120 | if ((a->init) && (a->ptr != NULL)) | ||
| 121 | { | ||
| 122 | BUF_MEM_free((BUF_MEM *)a->ptr); | ||
| 123 | a->ptr=NULL; | ||
| 124 | } | ||
| 125 | } | ||
| 126 | return(1); | ||
| 127 | } | ||
| 128 | |||
| 129 | static int mem_read(b,out,outl) | ||
| 130 | BIO *b; | ||
| 131 | char *out; | ||
| 132 | int outl; | ||
| 133 | { | ||
| 134 | int ret= -1; | ||
| 135 | BUF_MEM *bm; | ||
| 136 | int i; | ||
| 137 | char *from,*to; | ||
| 138 | |||
| 139 | bm=(BUF_MEM *)b->ptr; | ||
| 140 | BIO_clear_retry_flags(b); | ||
| 141 | ret=(outl > bm->length)?bm->length:outl; | ||
| 142 | if ((out != NULL) && (ret > 0)) | ||
| 143 | { | ||
| 144 | memcpy(out,bm->data,ret); | ||
| 145 | bm->length-=ret; | ||
| 146 | /* memmove(&(bm->data[0]),&(bm->data[ret]), bm->length); */ | ||
| 147 | from=(char *)&(bm->data[ret]); | ||
| 148 | to=(char *)&(bm->data[0]); | ||
| 149 | for (i=0; i<bm->length; i++) | ||
| 150 | to[i]=from[i]; | ||
| 151 | } | ||
| 152 | else if (bm->length == 0) | ||
| 153 | { | ||
| 154 | BIO_set_retry_read(b); | ||
| 155 | ret= -1; | ||
| 156 | } | ||
| 157 | return(ret); | ||
| 158 | } | ||
| 159 | |||
| 160 | static int mem_write(b,in,inl) | ||
| 161 | BIO *b; | ||
| 162 | char *in; | ||
| 163 | int inl; | ||
| 164 | { | ||
| 165 | int ret= -1; | ||
| 166 | int blen; | ||
| 167 | BUF_MEM *bm; | ||
| 168 | |||
| 169 | bm=(BUF_MEM *)b->ptr; | ||
| 170 | if (in == NULL) | ||
| 171 | { | ||
| 172 | BIOerr(BIO_F_MEM_WRITE,BIO_R_NULL_PARAMETER); | ||
| 173 | goto end; | ||
| 174 | } | ||
| 175 | |||
| 176 | BIO_clear_retry_flags(b); | ||
| 177 | blen=bm->length; | ||
| 178 | if (BUF_MEM_grow(bm,blen+inl) != (blen+inl)) | ||
| 179 | goto end; | ||
| 180 | memcpy(&(bm->data[blen]),in,inl); | ||
| 181 | ret=inl; | ||
| 182 | end: | ||
| 183 | return(ret); | ||
| 184 | } | ||
| 185 | |||
| 186 | static long mem_ctrl(b,cmd,num,ptr) | ||
| 187 | BIO *b; | ||
| 188 | int cmd; | ||
| 189 | long num; | ||
| 190 | char *ptr; | ||
| 191 | { | ||
| 192 | long ret=1; | ||
| 193 | char **pptr; | ||
| 194 | |||
| 195 | BUF_MEM *bm=(BUF_MEM *)b->ptr; | ||
| 196 | |||
| 197 | switch (cmd) | ||
| 198 | { | ||
| 199 | case BIO_CTRL_RESET: | ||
| 200 | if (bm->data != NULL) | ||
| 201 | memset(bm->data,0,bm->max); | ||
| 202 | bm->length=0; | ||
| 203 | break; | ||
| 204 | case BIO_CTRL_EOF: | ||
| 205 | ret=(long)(bm->length == 0); | ||
| 206 | break; | ||
| 207 | case BIO_CTRL_INFO: | ||
| 208 | ret=(long)bm->length; | ||
| 209 | if (ptr != NULL) | ||
| 210 | { | ||
| 211 | pptr=(char **)ptr; | ||
| 212 | *pptr=(char *)&(bm->data[0]); | ||
| 213 | } | ||
| 214 | break; | ||
| 215 | case BIO_C_SET_BUF_MEM: | ||
| 216 | mem_free(b); | ||
| 217 | b->shutdown=(int)num; | ||
| 218 | b->ptr=ptr; | ||
| 219 | break; | ||
| 220 | case BIO_C_GET_BUF_MEM_PTR: | ||
| 221 | if (ptr != NULL) | ||
| 222 | { | ||
| 223 | pptr=(char **)ptr; | ||
| 224 | *pptr=(char *)bm; | ||
| 225 | } | ||
| 226 | break; | ||
| 227 | case BIO_CTRL_GET_CLOSE: | ||
| 228 | ret=(long)b->shutdown; | ||
| 229 | break; | ||
| 230 | case BIO_CTRL_SET_CLOSE: | ||
| 231 | b->shutdown=(int)num; | ||
| 232 | break; | ||
| 233 | |||
| 234 | case BIO_CTRL_WPENDING: | ||
| 235 | ret=0L; | ||
| 236 | break; | ||
| 237 | case BIO_CTRL_PENDING: | ||
| 238 | ret=(long)bm->length; | ||
| 239 | break; | ||
| 240 | case BIO_CTRL_DUP: | ||
| 241 | case BIO_CTRL_FLUSH: | ||
| 242 | ret=1; | ||
| 243 | break; | ||
| 244 | case BIO_CTRL_PUSH: | ||
| 245 | case BIO_CTRL_POP: | ||
| 246 | default: | ||
| 247 | ret=0; | ||
| 248 | break; | ||
| 249 | } | ||
| 250 | return(ret); | ||
| 251 | } | ||
| 252 | |||
| 253 | static int mem_gets(bp,buf,size) | ||
| 254 | BIO *bp; | ||
| 255 | char *buf; | ||
| 256 | int size; | ||
| 257 | { | ||
| 258 | int i,j; | ||
| 259 | int ret= -1; | ||
| 260 | char *p; | ||
| 261 | BUF_MEM *bm=(BUF_MEM *)bp->ptr; | ||
| 262 | |||
| 263 | BIO_clear_retry_flags(bp); | ||
| 264 | j=bm->length; | ||
| 265 | if (j <= 0) return(0); | ||
| 266 | p=bm->data; | ||
| 267 | for (i=0; i<j; i++) | ||
| 268 | { | ||
| 269 | if (p[i] == '\n') break; | ||
| 270 | } | ||
| 271 | if (i == j) | ||
| 272 | { | ||
| 273 | BIO_set_retry_read(bp); | ||
| 274 | /* return(-1); change the semantics 0.6.6a */ | ||
| 275 | } | ||
| 276 | else | ||
| 277 | i++; | ||
| 278 | /* i is the max to copy */ | ||
| 279 | if ((size-1) < i) i=size-1; | ||
| 280 | i=mem_read(bp,buf,i); | ||
| 281 | if (i > 0) buf[i]='\0'; | ||
| 282 | ret=i; | ||
| 283 | return(ret); | ||
| 284 | } | ||
| 285 | |||
| 286 | static int mem_puts(bp,str) | ||
| 287 | BIO *bp; | ||
| 288 | char *str; | ||
| 289 | { | ||
| 290 | int n,ret; | ||
| 291 | |||
| 292 | n=strlen(str); | ||
| 293 | ret=mem_write(bp,str,n); | ||
| 294 | /* memory semantics is that it will always work */ | ||
| 295 | return(ret); | ||
| 296 | } | ||
| 297 | |||
diff --git a/src/lib/libcrypto/bio/bss_null.c b/src/lib/libcrypto/bio/bss_null.c new file mode 100644 index 0000000000..0791a2471a --- /dev/null +++ b/src/lib/libcrypto/bio/bss_null.c | |||
| @@ -0,0 +1,177 @@ | |||
| 1 | /* crypto/bio/bss_null.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 <errno.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "bio.h" | ||
| 63 | |||
| 64 | #ifndef NOPROTO | ||
| 65 | static int null_write(BIO *h,char *buf,int num); | ||
| 66 | static int null_read(BIO *h,char *buf,int size); | ||
| 67 | static int null_puts(BIO *h,char *str); | ||
| 68 | static int null_gets(BIO *h,char *str,int size); | ||
| 69 | static long null_ctrl(BIO *h,int cmd,long arg1,char *arg2); | ||
| 70 | static int null_new(BIO *h); | ||
| 71 | static int null_free(BIO *data); | ||
| 72 | #else | ||
| 73 | static int null_write(); | ||
| 74 | static int null_read(); | ||
| 75 | static int null_puts(); | ||
| 76 | static int null_gets(); | ||
| 77 | static long null_ctrl(); | ||
| 78 | static int null_new(); | ||
| 79 | static int null_free(); | ||
| 80 | #endif | ||
| 81 | |||
| 82 | static BIO_METHOD null_method= | ||
| 83 | { | ||
| 84 | BIO_TYPE_NULL, | ||
| 85 | "NULL", | ||
| 86 | null_write, | ||
| 87 | null_read, | ||
| 88 | null_puts, | ||
| 89 | null_gets, | ||
| 90 | null_ctrl, | ||
| 91 | null_new, | ||
| 92 | null_free, | ||
| 93 | }; | ||
| 94 | |||
| 95 | BIO_METHOD *BIO_s_null() | ||
| 96 | { | ||
| 97 | return(&null_method); | ||
| 98 | } | ||
| 99 | |||
| 100 | static int null_new(bi) | ||
| 101 | BIO *bi; | ||
| 102 | { | ||
| 103 | bi->init=1; | ||
| 104 | bi->num=0; | ||
| 105 | bi->ptr=(NULL); | ||
| 106 | return(1); | ||
| 107 | } | ||
| 108 | |||
| 109 | static int null_free(a) | ||
| 110 | BIO *a; | ||
| 111 | { | ||
| 112 | if (a == NULL) return(0); | ||
| 113 | return(1); | ||
| 114 | } | ||
| 115 | |||
| 116 | static int null_read(b,out,outl) | ||
| 117 | BIO *b; | ||
| 118 | char *out; | ||
| 119 | int outl; | ||
| 120 | { | ||
| 121 | return(0); | ||
| 122 | } | ||
| 123 | |||
| 124 | static int null_write(b,in,inl) | ||
| 125 | BIO *b; | ||
| 126 | char *in; | ||
| 127 | int inl; | ||
| 128 | { | ||
| 129 | return(inl); | ||
| 130 | } | ||
| 131 | |||
| 132 | static long null_ctrl(b,cmd,num,ptr) | ||
| 133 | BIO *b; | ||
| 134 | int cmd; | ||
| 135 | long num; | ||
| 136 | char *ptr; | ||
| 137 | { | ||
| 138 | long ret=1; | ||
| 139 | |||
| 140 | switch (cmd) | ||
| 141 | { | ||
| 142 | case BIO_CTRL_RESET: | ||
| 143 | case BIO_CTRL_EOF: | ||
| 144 | case BIO_CTRL_SET: | ||
| 145 | case BIO_CTRL_SET_CLOSE: | ||
| 146 | case BIO_CTRL_FLUSH: | ||
| 147 | case BIO_CTRL_DUP: | ||
| 148 | ret=1; | ||
| 149 | break; | ||
| 150 | case BIO_CTRL_GET_CLOSE: | ||
| 151 | case BIO_CTRL_INFO: | ||
| 152 | case BIO_CTRL_GET: | ||
| 153 | case BIO_CTRL_PENDING: | ||
| 154 | case BIO_CTRL_WPENDING: | ||
| 155 | default: | ||
| 156 | ret=0; | ||
| 157 | break; | ||
| 158 | } | ||
| 159 | return(ret); | ||
| 160 | } | ||
| 161 | |||
| 162 | static int null_gets(bp,buf,size) | ||
| 163 | BIO *bp; | ||
| 164 | char *buf; | ||
| 165 | int size; | ||
| 166 | { | ||
| 167 | return(0); | ||
| 168 | } | ||
| 169 | |||
| 170 | static int null_puts(bp,str) | ||
| 171 | BIO *bp; | ||
| 172 | char *str; | ||
| 173 | { | ||
| 174 | if (str == NULL) return(0); | ||
| 175 | return(strlen(str)); | ||
| 176 | } | ||
| 177 | |||
diff --git a/src/lib/libcrypto/bio/bss_sock.c b/src/lib/libcrypto/bio/bss_sock.c new file mode 100644 index 0000000000..d907a2867b --- /dev/null +++ b/src/lib/libcrypto/bio/bss_sock.c | |||
| @@ -0,0 +1,461 @@ | |||
| 1 | /* crypto/bio/bss_sock.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 | #if !defined(NO_SOCK) || defined(BIO_FD) | ||
| 60 | |||
| 61 | #include <stdio.h> | ||
| 62 | #include <errno.h> | ||
| 63 | #define USE_SOCKETS | ||
| 64 | #include "cryptlib.h" | ||
| 65 | #include "bio.h" | ||
| 66 | |||
| 67 | #ifndef BIO_FD | ||
| 68 | #ifndef NOPROTO | ||
| 69 | static int sock_write(BIO *h,char *buf,int num); | ||
| 70 | static int sock_read(BIO *h,char *buf,int size); | ||
| 71 | static int sock_puts(BIO *h,char *str); | ||
| 72 | static long sock_ctrl(BIO *h,int cmd,long arg1,char *arg2); | ||
| 73 | static int sock_new(BIO *h); | ||
| 74 | static int sock_free(BIO *data); | ||
| 75 | int BIO_sock_should_retry(int s); | ||
| 76 | #else | ||
| 77 | static int sock_write(); | ||
| 78 | static int sock_read(); | ||
| 79 | static int sock_puts(); | ||
| 80 | static long sock_ctrl(); | ||
| 81 | static int sock_new(); | ||
| 82 | static int sock_free(); | ||
| 83 | int BIO_sock_should_retry(); | ||
| 84 | #endif | ||
| 85 | |||
| 86 | #else | ||
| 87 | |||
| 88 | #ifndef NOPROTO | ||
| 89 | static int fd_write(BIO *h,char *buf,int num); | ||
| 90 | static int fd_read(BIO *h,char *buf,int size); | ||
| 91 | static int fd_puts(BIO *h,char *str); | ||
| 92 | static long fd_ctrl(BIO *h,int cmd,long arg1,char *arg2); | ||
| 93 | static int fd_new(BIO *h); | ||
| 94 | static int fd_free(BIO *data); | ||
| 95 | int BIO_fd_should_retry(int s); | ||
| 96 | #else | ||
| 97 | static int fd_write(); | ||
| 98 | static int fd_read(); | ||
| 99 | static int fd_puts(); | ||
| 100 | static long fd_ctrl(); | ||
| 101 | static int fd_new(); | ||
| 102 | static int fd_free(); | ||
| 103 | int BIO_fd_should_retry(); | ||
| 104 | #endif | ||
| 105 | #endif | ||
| 106 | |||
| 107 | #ifndef BIO_FD | ||
| 108 | static BIO_METHOD methods_sockp= | ||
| 109 | { | ||
| 110 | BIO_TYPE_SOCKET, | ||
| 111 | "socket", | ||
| 112 | sock_write, | ||
| 113 | sock_read, | ||
| 114 | sock_puts, | ||
| 115 | NULL, /* sock_gets, */ | ||
| 116 | sock_ctrl, | ||
| 117 | sock_new, | ||
| 118 | sock_free, | ||
| 119 | }; | ||
| 120 | |||
| 121 | BIO_METHOD *BIO_s_socket() | ||
| 122 | { | ||
| 123 | return(&methods_sockp); | ||
| 124 | } | ||
| 125 | #else | ||
| 126 | static BIO_METHOD methods_fdp= | ||
| 127 | { | ||
| 128 | BIO_TYPE_FD,"file descriptor", | ||
| 129 | fd_write, | ||
| 130 | fd_read, | ||
| 131 | fd_puts, | ||
| 132 | NULL, /* fd_gets, */ | ||
| 133 | fd_ctrl, | ||
| 134 | fd_new, | ||
| 135 | fd_free, | ||
| 136 | }; | ||
| 137 | |||
| 138 | BIO_METHOD *BIO_s_fd() | ||
| 139 | { | ||
| 140 | return(&methods_fdp); | ||
| 141 | } | ||
| 142 | #endif | ||
| 143 | |||
| 144 | #ifndef BIO_FD | ||
| 145 | BIO *BIO_new_socket(fd,close_flag) | ||
| 146 | #else | ||
| 147 | BIO *BIO_new_fd(fd,close_flag) | ||
| 148 | #endif | ||
| 149 | int fd; | ||
| 150 | int close_flag; | ||
| 151 | { | ||
| 152 | BIO *ret; | ||
| 153 | |||
| 154 | #ifndef BIO_FD | ||
| 155 | ret=BIO_new(BIO_s_socket()); | ||
| 156 | #else | ||
| 157 | ret=BIO_new(BIO_s_fd()); | ||
| 158 | #endif | ||
| 159 | if (ret == NULL) return(NULL); | ||
| 160 | BIO_set_fd(ret,fd,close_flag); | ||
| 161 | return(ret); | ||
| 162 | } | ||
| 163 | |||
| 164 | #ifndef BIO_FD | ||
| 165 | static int sock_new(bi) | ||
| 166 | #else | ||
| 167 | static int fd_new(bi) | ||
| 168 | #endif | ||
| 169 | BIO *bi; | ||
| 170 | { | ||
| 171 | bi->init=0; | ||
| 172 | bi->num=0; | ||
| 173 | bi->ptr=NULL; | ||
| 174 | bi->flags=0; | ||
| 175 | return(1); | ||
| 176 | } | ||
| 177 | |||
| 178 | #ifndef BIO_FD | ||
| 179 | static int sock_free(a) | ||
| 180 | #else | ||
| 181 | static int fd_free(a) | ||
| 182 | #endif | ||
| 183 | BIO *a; | ||
| 184 | { | ||
| 185 | if (a == NULL) return(0); | ||
| 186 | if (a->shutdown) | ||
| 187 | { | ||
| 188 | if (a->init) | ||
| 189 | { | ||
| 190 | #ifndef BIO_FD | ||
| 191 | shutdown(a->num,2); | ||
| 192 | # ifdef WINDOWS | ||
| 193 | closesocket(a->num); | ||
| 194 | # else | ||
| 195 | close(a->num); | ||
| 196 | # endif | ||
| 197 | #else /* BIO_FD */ | ||
| 198 | close(a->num); | ||
| 199 | #endif | ||
| 200 | |||
| 201 | } | ||
| 202 | a->init=0; | ||
| 203 | a->flags=0; | ||
| 204 | } | ||
| 205 | return(1); | ||
| 206 | } | ||
| 207 | |||
| 208 | #ifndef BIO_FD | ||
| 209 | static int sock_read(b,out,outl) | ||
| 210 | #else | ||
| 211 | static int fd_read(b,out,outl) | ||
| 212 | #endif | ||
| 213 | BIO *b; | ||
| 214 | char *out; | ||
| 215 | int outl; | ||
| 216 | { | ||
| 217 | int ret=0; | ||
| 218 | |||
| 219 | if (out != NULL) | ||
| 220 | { | ||
| 221 | #if defined(WINDOWS) && !defined(BIO_FD) | ||
| 222 | clear_socket_error(); | ||
| 223 | ret=recv(b->num,out,outl,0); | ||
| 224 | #else | ||
| 225 | clear_sys_error(); | ||
| 226 | ret=read(b->num,out,outl); | ||
| 227 | #endif | ||
| 228 | BIO_clear_retry_flags(b); | ||
| 229 | if (ret <= 0) | ||
| 230 | { | ||
| 231 | #ifndef BIO_FD | ||
| 232 | if (BIO_sock_should_retry(ret)) | ||
| 233 | #else | ||
| 234 | if (BIO_fd_should_retry(ret)) | ||
| 235 | #endif | ||
| 236 | BIO_set_retry_read(b); | ||
| 237 | } | ||
| 238 | } | ||
| 239 | return(ret); | ||
| 240 | } | ||
| 241 | |||
| 242 | #ifndef BIO_FD | ||
| 243 | static int sock_write(b,in,inl) | ||
| 244 | #else | ||
| 245 | static int fd_write(b,in,inl) | ||
| 246 | #endif | ||
| 247 | BIO *b; | ||
| 248 | char *in; | ||
| 249 | int inl; | ||
| 250 | { | ||
| 251 | int ret; | ||
| 252 | |||
| 253 | #if defined(WINDOWS) && !defined(BIO_FD) | ||
| 254 | clear_socket_error(); | ||
| 255 | ret=send(b->num,in,inl,0); | ||
| 256 | #else | ||
| 257 | clear_sys_error(); | ||
| 258 | ret=write(b->num,in,inl); | ||
| 259 | #endif | ||
| 260 | BIO_clear_retry_flags(b); | ||
| 261 | if (ret <= 0) | ||
| 262 | { | ||
| 263 | #ifndef BIO_FD | ||
| 264 | if (BIO_sock_should_retry(ret)) | ||
| 265 | #else | ||
| 266 | if (BIO_fd_should_retry(ret)) | ||
| 267 | #endif | ||
| 268 | BIO_set_retry_write(b); | ||
| 269 | } | ||
| 270 | return(ret); | ||
| 271 | } | ||
| 272 | |||
| 273 | #ifndef BIO_FD | ||
| 274 | static long sock_ctrl(b,cmd,num,ptr) | ||
| 275 | #else | ||
| 276 | static long fd_ctrl(b,cmd,num,ptr) | ||
| 277 | #endif | ||
| 278 | BIO *b; | ||
| 279 | int cmd; | ||
| 280 | long num; | ||
| 281 | char *ptr; | ||
| 282 | { | ||
| 283 | long ret=1; | ||
| 284 | int *ip; | ||
| 285 | |||
| 286 | switch (cmd) | ||
| 287 | { | ||
| 288 | case BIO_CTRL_RESET: | ||
| 289 | #ifdef BIO_FD | ||
| 290 | ret=(long)lseek(b->num,0,0); | ||
| 291 | #else | ||
| 292 | ret=0; | ||
| 293 | #endif | ||
| 294 | break; | ||
| 295 | case BIO_CTRL_INFO: | ||
| 296 | ret=0; | ||
| 297 | break; | ||
| 298 | case BIO_C_SET_FD: | ||
| 299 | #ifndef BIO_FD | ||
| 300 | sock_free(b); | ||
| 301 | #else | ||
| 302 | fd_free(b); | ||
| 303 | #endif | ||
| 304 | b->num= *((int *)ptr); | ||
| 305 | b->shutdown=(int)num; | ||
| 306 | b->init=1; | ||
| 307 | break; | ||
| 308 | case BIO_C_GET_FD: | ||
| 309 | if (b->init) | ||
| 310 | { | ||
| 311 | ip=(int *)ptr; | ||
| 312 | if (ip != NULL) *ip=b->num; | ||
| 313 | ret=b->num; | ||
| 314 | } | ||
| 315 | else | ||
| 316 | ret= -1; | ||
| 317 | break; | ||
| 318 | case BIO_CTRL_GET_CLOSE: | ||
| 319 | ret=b->shutdown; | ||
| 320 | break; | ||
| 321 | case BIO_CTRL_SET_CLOSE: | ||
| 322 | b->shutdown=(int)num; | ||
| 323 | break; | ||
| 324 | case BIO_CTRL_PENDING: | ||
| 325 | case BIO_CTRL_WPENDING: | ||
| 326 | ret=0; | ||
| 327 | break; | ||
| 328 | case BIO_CTRL_DUP: | ||
| 329 | case BIO_CTRL_FLUSH: | ||
| 330 | ret=1; | ||
| 331 | break; | ||
| 332 | break; | ||
| 333 | default: | ||
| 334 | ret=0; | ||
| 335 | break; | ||
| 336 | } | ||
| 337 | return(ret); | ||
| 338 | } | ||
| 339 | |||
| 340 | #ifdef undef | ||
| 341 | static int sock_gets(bp,buf,size) | ||
| 342 | BIO *bp; | ||
| 343 | char *buf; | ||
| 344 | int size; | ||
| 345 | { | ||
| 346 | return(-1); | ||
| 347 | } | ||
| 348 | #endif | ||
| 349 | |||
| 350 | #ifndef BIO_FD | ||
| 351 | static int sock_puts(bp,str) | ||
| 352 | #else | ||
| 353 | static int fd_puts(bp,str) | ||
| 354 | #endif | ||
| 355 | BIO *bp; | ||
| 356 | char *str; | ||
| 357 | { | ||
| 358 | int n,ret; | ||
| 359 | |||
| 360 | n=strlen(str); | ||
| 361 | #ifndef BIO_FD | ||
| 362 | ret=sock_write(bp,str,n); | ||
| 363 | #else | ||
| 364 | ret=fd_write(bp,str,n); | ||
| 365 | #endif | ||
| 366 | return(ret); | ||
| 367 | } | ||
| 368 | |||
| 369 | #ifndef BIO_FD | ||
| 370 | int BIO_sock_should_retry(i) | ||
| 371 | #else | ||
| 372 | int BIO_fd_should_retry(i) | ||
| 373 | #endif | ||
| 374 | int i; | ||
| 375 | { | ||
| 376 | int err; | ||
| 377 | |||
| 378 | if ((i == 0) || (i == -1)) | ||
| 379 | { | ||
| 380 | #if !defined(BIO_FD) && defined(WINDOWS) | ||
| 381 | err=get_last_socket_error(); | ||
| 382 | #else | ||
| 383 | err=get_last_sys_error(); | ||
| 384 | #endif | ||
| 385 | |||
| 386 | #if defined(WINDOWS) /* more microsoft stupidity */ | ||
| 387 | if ((i == -1) && (err == 0)) | ||
| 388 | return(1); | ||
| 389 | #endif | ||
| 390 | |||
| 391 | #ifndef BIO_FD | ||
| 392 | return(BIO_sock_non_fatal_error(err)); | ||
| 393 | #else | ||
| 394 | return(BIO_fd_non_fatal_error(err)); | ||
| 395 | #endif | ||
| 396 | } | ||
| 397 | return(0); | ||
| 398 | } | ||
| 399 | |||
| 400 | #ifndef BIO_FD | ||
| 401 | int BIO_sock_non_fatal_error(err) | ||
| 402 | #else | ||
| 403 | int BIO_fd_non_fatal_error(err) | ||
| 404 | #endif | ||
| 405 | int err; | ||
| 406 | { | ||
| 407 | switch (err) | ||
| 408 | { | ||
| 409 | #if !defined(BIO_FD) && defined(WINDOWS) | ||
| 410 | # if defined(WSAEWOULDBLOCK) | ||
| 411 | case WSAEWOULDBLOCK: | ||
| 412 | # endif | ||
| 413 | |||
| 414 | # if defined(WSAENOTCONN) | ||
| 415 | case WSAENOTCONN: | ||
| 416 | # endif | ||
| 417 | #endif | ||
| 418 | |||
| 419 | #ifdef EWOULDBLOCK | ||
| 420 | # ifdef WSAEWOULDBLOCK | ||
| 421 | # if WSAEWOULDBLOCK != EWOULDBLOCK | ||
| 422 | case EWOULDBLOCK: | ||
| 423 | # endif | ||
| 424 | # else | ||
| 425 | case EWOULDBLOCK: | ||
| 426 | # endif | ||
| 427 | #endif | ||
| 428 | |||
| 429 | #if defined(ENOTCONN) | ||
| 430 | case ENOTCONN: | ||
| 431 | #endif | ||
| 432 | |||
| 433 | #ifdef EINTR | ||
| 434 | case EINTR: | ||
| 435 | #endif | ||
| 436 | |||
| 437 | #ifdef EAGAIN | ||
| 438 | #if EWOULDBLOCK != EAGAIN | ||
| 439 | case EAGAIN: | ||
| 440 | # endif | ||
| 441 | #endif | ||
| 442 | |||
| 443 | #ifdef EPROTO | ||
| 444 | case EPROTO: | ||
| 445 | #endif | ||
| 446 | |||
| 447 | #ifdef EINPROGRESS | ||
| 448 | case EINPROGRESS: | ||
| 449 | #endif | ||
| 450 | |||
| 451 | #ifdef EALREADY | ||
| 452 | case EALREADY: | ||
| 453 | #endif | ||
| 454 | return(1); | ||
| 455 | break; | ||
| 456 | default: | ||
| 457 | break; | ||
| 458 | } | ||
| 459 | return(0); | ||
| 460 | } | ||
| 461 | #endif | ||
diff --git a/src/lib/libcrypto/bn/asm/bn-586.pl b/src/lib/libcrypto/bn/asm/bn-586.pl new file mode 100644 index 0000000000..19d425ee96 --- /dev/null +++ b/src/lib/libcrypto/bn/asm/bn-586.pl | |||
| @@ -0,0 +1,314 @@ | |||
| 1 | #!/usr/bin/perl | ||
| 2 | # | ||
| 3 | |||
| 4 | #!/usr/local/bin/perl | ||
| 5 | |||
| 6 | push(@INC,"perlasm","../../perlasm"); | ||
| 7 | require "x86asm.pl"; | ||
| 8 | |||
| 9 | &asm_init($ARGV[0],"bn-586.pl"); | ||
| 10 | |||
| 11 | &bn_mul_add_words("bn_mul_add_words"); | ||
| 12 | &bn_mul_words("bn_mul_words"); | ||
| 13 | &bn_sqr_words("bn_sqr_words"); | ||
| 14 | &bn_div64("bn_div64"); | ||
| 15 | &bn_add_words("bn_add_words"); | ||
| 16 | |||
| 17 | &asm_finish(); | ||
| 18 | |||
| 19 | sub bn_mul_add_words | ||
| 20 | { | ||
| 21 | local($name)=@_; | ||
| 22 | |||
| 23 | &function_begin($name,""); | ||
| 24 | |||
| 25 | &comment(""); | ||
| 26 | $Low="eax"; | ||
| 27 | $High="edx"; | ||
| 28 | $a="ebx"; | ||
| 29 | $w="ebp"; | ||
| 30 | $r="edi"; | ||
| 31 | $c="esi"; | ||
| 32 | |||
| 33 | &xor($c,$c); # clear carry | ||
| 34 | &mov($r,&wparam(0)); # | ||
| 35 | |||
| 36 | &mov("ecx",&wparam(2)); # | ||
| 37 | &mov($a,&wparam(1)); # | ||
| 38 | |||
| 39 | &and("ecx",0xfffffff8); # num / 8 | ||
| 40 | &mov($w,&wparam(3)); # | ||
| 41 | |||
| 42 | &push("ecx"); # Up the stack for a tmp variable | ||
| 43 | |||
| 44 | &jz(&label("maw_finish")); | ||
| 45 | |||
| 46 | &set_label("maw_loop",0); | ||
| 47 | |||
| 48 | &mov(&swtmp(0),"ecx"); # | ||
| 49 | |||
| 50 | for ($i=0; $i<32; $i+=4) | ||
| 51 | { | ||
| 52 | &comment("Round $i"); | ||
| 53 | |||
| 54 | &mov("eax",&DWP($i,$a,"",0)); # *a | ||
| 55 | &mul($w); # *a * w | ||
| 56 | &add("eax",$c); # L(t)+= *r | ||
| 57 | &mov($c,&DWP($i,$r,"",0)); # L(t)+= *r | ||
| 58 | &adc("edx",0); # H(t)+=carry | ||
| 59 | &add("eax",$c); # L(t)+=c | ||
| 60 | &adc("edx",0); # H(t)+=carry | ||
| 61 | &mov(&DWP($i,$r,"",0),"eax"); # *r= L(t); | ||
| 62 | &mov($c,"edx"); # c= H(t); | ||
| 63 | } | ||
| 64 | |||
| 65 | &comment(""); | ||
| 66 | &mov("ecx",&swtmp(0)); # | ||
| 67 | &add($a,32); | ||
| 68 | &add($r,32); | ||
| 69 | &sub("ecx",8); | ||
| 70 | &jnz(&label("maw_loop")); | ||
| 71 | |||
| 72 | &set_label("maw_finish",0); | ||
| 73 | &mov("ecx",&wparam(2)); # get num | ||
| 74 | &and("ecx",7); | ||
| 75 | &jnz(&label("maw_finish2")); # helps branch prediction | ||
| 76 | &jmp(&label("maw_end")); | ||
| 77 | |||
| 78 | &set_label("maw_finish2",1); | ||
| 79 | for ($i=0; $i<7; $i++) | ||
| 80 | { | ||
| 81 | &comment("Tail Round $i"); | ||
| 82 | &mov("eax",&DWP($i*4,$a,"",0));# *a | ||
| 83 | &mul($w); # *a * w | ||
| 84 | &add("eax",$c); # L(t)+=c | ||
| 85 | &mov($c,&DWP($i*4,$r,"",0)); # L(t)+= *r | ||
| 86 | &adc("edx",0); # H(t)+=carry | ||
| 87 | &add("eax",$c); | ||
| 88 | &adc("edx",0); # H(t)+=carry | ||
| 89 | &dec("ecx") if ($i != 7-1); | ||
| 90 | &mov(&DWP($i*4,$r,"",0),"eax"); # *r= L(t); | ||
| 91 | &mov($c,"edx"); # c= H(t); | ||
| 92 | &jz(&label("maw_end")) if ($i != 7-1); | ||
| 93 | } | ||
| 94 | &set_label("maw_end",0); | ||
| 95 | &mov("eax",$c); | ||
| 96 | |||
| 97 | &pop("ecx"); # clear variable from | ||
| 98 | |||
| 99 | &function_end($name); | ||
| 100 | } | ||
| 101 | |||
| 102 | sub bn_mul_words | ||
| 103 | { | ||
| 104 | local($name)=@_; | ||
| 105 | |||
| 106 | &function_begin($name,""); | ||
| 107 | |||
| 108 | &comment(""); | ||
| 109 | $Low="eax"; | ||
| 110 | $High="edx"; | ||
| 111 | $a="ebx"; | ||
| 112 | $w="ecx"; | ||
| 113 | $r="edi"; | ||
| 114 | $c="esi"; | ||
| 115 | $num="ebp"; | ||
| 116 | |||
| 117 | &xor($c,$c); # clear carry | ||
| 118 | &mov($r,&wparam(0)); # | ||
| 119 | &mov($a,&wparam(1)); # | ||
| 120 | &mov($num,&wparam(2)); # | ||
| 121 | &mov($w,&wparam(3)); # | ||
| 122 | |||
| 123 | &and($num,0xfffffff8); # num / 8 | ||
| 124 | &jz(&label("mw_finish")); | ||
| 125 | |||
| 126 | &set_label("mw_loop",0); | ||
| 127 | for ($i=0; $i<32; $i+=4) | ||
| 128 | { | ||
| 129 | &comment("Round $i"); | ||
| 130 | |||
| 131 | &mov("eax",&DWP($i,$a,"",0)); # *a | ||
| 132 | &mul($w); # *a * w | ||
| 133 | &add("eax",$c); # L(t)+=c | ||
| 134 | # XXX | ||
| 135 | |||
| 136 | &adc("edx",0); # H(t)+=carry | ||
| 137 | &mov(&DWP($i,$r,"",0),"eax"); # *r= L(t); | ||
| 138 | |||
| 139 | &mov($c,"edx"); # c= H(t); | ||
| 140 | } | ||
| 141 | |||
| 142 | &comment(""); | ||
| 143 | &add($a,32); | ||
| 144 | &add($r,32); | ||
| 145 | &sub($num,8); | ||
| 146 | &jz(&label("mw_finish")); | ||
| 147 | &jmp(&label("mw_loop")); | ||
| 148 | |||
| 149 | &set_label("mw_finish",0); | ||
| 150 | &mov($num,&wparam(2)); # get num | ||
| 151 | &and($num,7); | ||
| 152 | &jnz(&label("mw_finish2")); | ||
| 153 | &jmp(&label("mw_end")); | ||
| 154 | |||
| 155 | &set_label("mw_finish2",1); | ||
| 156 | for ($i=0; $i<7; $i++) | ||
| 157 | { | ||
| 158 | &comment("Tail Round $i"); | ||
| 159 | &mov("eax",&DWP($i*4,$a,"",0));# *a | ||
| 160 | &mul($w); # *a * w | ||
| 161 | &add("eax",$c); # L(t)+=c | ||
| 162 | # XXX | ||
| 163 | &adc("edx",0); # H(t)+=carry | ||
| 164 | &mov(&DWP($i*4,$r,"",0),"eax");# *r= L(t); | ||
| 165 | &mov($c,"edx"); # c= H(t); | ||
| 166 | &dec($num) if ($i != 7-1); | ||
| 167 | &jz(&label("mw_end")) if ($i != 7-1); | ||
| 168 | } | ||
| 169 | &set_label("mw_end",0); | ||
| 170 | &mov("eax",$c); | ||
| 171 | |||
| 172 | &function_end($name); | ||
| 173 | } | ||
| 174 | |||
| 175 | sub bn_sqr_words | ||
| 176 | { | ||
| 177 | local($name)=@_; | ||
| 178 | |||
| 179 | &function_begin($name,""); | ||
| 180 | |||
| 181 | &comment(""); | ||
| 182 | $r="esi"; | ||
| 183 | $a="edi"; | ||
| 184 | $num="ebx"; | ||
| 185 | |||
| 186 | &mov($r,&wparam(0)); # | ||
| 187 | &mov($a,&wparam(1)); # | ||
| 188 | &mov($num,&wparam(2)); # | ||
| 189 | |||
| 190 | &and($num,0xfffffff8); # num / 8 | ||
| 191 | &jz(&label("sw_finish")); | ||
| 192 | |||
| 193 | &set_label("sw_loop",0); | ||
| 194 | for ($i=0; $i<32; $i+=4) | ||
| 195 | { | ||
| 196 | &comment("Round $i"); | ||
| 197 | &mov("eax",&DWP($i,$a,"",0)); # *a | ||
| 198 | # XXX | ||
| 199 | &mul("eax"); # *a * *a | ||
| 200 | &mov(&DWP($i*2,$r,"",0),"eax"); # | ||
| 201 | &mov(&DWP($i*2+4,$r,"",0),"edx");# | ||
| 202 | } | ||
| 203 | |||
| 204 | &comment(""); | ||
| 205 | &add($a,32); | ||
| 206 | &add($r,64); | ||
| 207 | &sub($num,8); | ||
| 208 | &jnz(&label("sw_loop")); | ||
| 209 | |||
| 210 | &set_label("sw_finish",0); | ||
| 211 | &mov($num,&wparam(2)); # get num | ||
| 212 | &and($num,7); | ||
| 213 | &jz(&label("sw_end")); | ||
| 214 | |||
| 215 | for ($i=0; $i<7; $i++) | ||
| 216 | { | ||
| 217 | &comment("Tail Round $i"); | ||
| 218 | &mov("eax",&DWP($i*4,$a,"",0)); # *a | ||
| 219 | # XXX | ||
| 220 | &mul("eax"); # *a * *a | ||
| 221 | &mov(&DWP($i*8,$r,"",0),"eax"); # | ||
| 222 | &dec($num) if ($i != 7-1); | ||
| 223 | &mov(&DWP($i*8+4,$r,"",0),"edx"); | ||
| 224 | &jz(&label("sw_end")) if ($i != 7-1); | ||
| 225 | } | ||
| 226 | &set_label("sw_end",0); | ||
| 227 | |||
| 228 | &function_end($name); | ||
| 229 | } | ||
| 230 | |||
| 231 | sub bn_div64 | ||
| 232 | { | ||
| 233 | local($name)=@_; | ||
| 234 | |||
| 235 | &function_begin($name,""); | ||
| 236 | &mov("edx",&wparam(0)); # | ||
| 237 | &mov("eax",&wparam(1)); # | ||
| 238 | &mov("ebx",&wparam(2)); # | ||
| 239 | &div("ebx"); | ||
| 240 | &function_end($name); | ||
| 241 | } | ||
| 242 | |||
| 243 | sub bn_add_words | ||
| 244 | { | ||
| 245 | local($name)=@_; | ||
| 246 | |||
| 247 | &function_begin($name,""); | ||
| 248 | |||
| 249 | &comment(""); | ||
| 250 | $a="esi"; | ||
| 251 | $b="edi"; | ||
| 252 | $c="eax"; | ||
| 253 | $r="ebx"; | ||
| 254 | $tmp1="ecx"; | ||
| 255 | $tmp2="edx"; | ||
| 256 | $num="ebp"; | ||
| 257 | |||
| 258 | &mov($r,&wparam(0)); # get r | ||
| 259 | &mov($a,&wparam(1)); # get a | ||
| 260 | &mov($b,&wparam(2)); # get b | ||
| 261 | &mov($num,&wparam(3)); # get num | ||
| 262 | &xor($c,$c); # clear carry | ||
| 263 | &and($num,0xfffffff8); # num / 8 | ||
| 264 | |||
| 265 | &jz(&label("aw_finish")); | ||
| 266 | |||
| 267 | &set_label("aw_loop",0); | ||
| 268 | for ($i=0; $i<8; $i++) | ||
| 269 | { | ||
| 270 | &comment("Round $i"); | ||
| 271 | |||
| 272 | &mov($tmp1,&DWP($i*4,$a,"",0)); # *a | ||
| 273 | &mov($tmp2,&DWP($i*4,$b,"",0)); # *b | ||
| 274 | &add($tmp1,$c); | ||
| 275 | &mov($c,0); | ||
| 276 | &adc($c,$c); | ||
| 277 | &add($tmp1,$tmp2); | ||
| 278 | &adc($c,0); | ||
| 279 | &mov(&DWP($i*4,$r,"",0),$tmp1); # *r | ||
| 280 | } | ||
| 281 | |||
| 282 | &comment(""); | ||
| 283 | &add($a,32); | ||
| 284 | &add($b,32); | ||
| 285 | &add($r,32); | ||
| 286 | &sub($num,8); | ||
| 287 | &jnz(&label("aw_loop")); | ||
| 288 | |||
| 289 | &set_label("aw_finish",0); | ||
| 290 | &mov($num,&wparam(3)); # get num | ||
| 291 | &and($num,7); | ||
| 292 | &jz(&label("aw_end")); | ||
| 293 | |||
| 294 | for ($i=0; $i<7; $i++) | ||
| 295 | { | ||
| 296 | &comment("Tail Round $i"); | ||
| 297 | &mov($tmp1,&DWP($i*4,$a,"",0)); # *a | ||
| 298 | &mov($tmp2,&DWP($i*4,$b,"",0));# *b | ||
| 299 | &add($tmp1,$c); | ||
| 300 | &mov($c,0); | ||
| 301 | &adc($c,$c); | ||
| 302 | &add($tmp1,$tmp2); | ||
| 303 | &adc($c,0); | ||
| 304 | &dec($num) if ($i != 6); | ||
| 305 | &mov(&DWP($i*4,$r,"",0),$tmp1); # *a | ||
| 306 | &jz(&label("aw_end")) if ($i != 6); | ||
| 307 | } | ||
| 308 | &set_label("aw_end",0); | ||
| 309 | |||
| 310 | &mov("eax",$c); | ||
| 311 | |||
| 312 | &function_end($name); | ||
| 313 | } | ||
| 314 | |||
diff --git a/src/lib/libcrypto/bn/asm/pa-risc2.s b/src/lib/libcrypto/bn/asm/pa-risc2.s new file mode 100644 index 0000000000..c2725996a4 --- /dev/null +++ b/src/lib/libcrypto/bn/asm/pa-risc2.s | |||
| @@ -0,0 +1,416 @@ | |||
| 1 | .SPACE $PRIVATE$ | ||
| 2 | .SUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31 | ||
| 3 | .SUBSPA $BSS$,QUAD=1,ALIGN=8,ACCESS=31,ZERO,SORT=82 | ||
| 4 | .SPACE $TEXT$ | ||
| 5 | .SUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=44 | ||
| 6 | .SUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY | ||
| 7 | .IMPORT $global$,DATA | ||
| 8 | .IMPORT $$dyncall,MILLICODE | ||
| 9 | ; gcc_compiled.: | ||
| 10 | .SPACE $TEXT$ | ||
| 11 | .SUBSPA $CODE$ | ||
| 12 | |||
| 13 | .align 4 | ||
| 14 | .EXPORT bn_mul_add_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,ARGW3=GR,RTNVAL=GR | ||
| 15 | bn_mul_add_words | ||
| 16 | .PROC | ||
| 17 | .CALLINFO FRAME=64,CALLS,SAVE_RP,ENTRY_GR=4 | ||
| 18 | .ENTRY | ||
| 19 | stw %r2,-20(0,%r30) | ||
| 20 | stwm %r4,64(0,%r30) | ||
| 21 | copy %r24,%r31 | ||
| 22 | stw %r3,-60(0,%r30) | ||
| 23 | ldi 0,%r20 | ||
| 24 | ldo 12(%r26),%r2 | ||
| 25 | stw %r23,-16(0,%r30) | ||
| 26 | copy %r25,%r3 | ||
| 27 | ldo 12(%r3),%r1 | ||
| 28 | fldws -16(0,%r30),%fr8L | ||
| 29 | L$0010 | ||
| 30 | copy %r20,%r25 | ||
| 31 | ldi 0,%r24 | ||
| 32 | fldws 0(0,%r3),%fr9L | ||
| 33 | ldw 0(0,%r26),%r19 | ||
| 34 | xmpyu %fr8L,%fr9L,%fr9 | ||
| 35 | fstds %fr9,-16(0,%r30) | ||
| 36 | copy %r19,%r23 | ||
| 37 | ldw -16(0,%r30),%r28 | ||
| 38 | ldw -12(0,%r30),%r29 | ||
| 39 | ldi 0,%r22 | ||
| 40 | add %r23,%r29,%r29 | ||
| 41 | addc %r22,%r28,%r28 | ||
| 42 | add %r25,%r29,%r29 | ||
| 43 | addc %r24,%r28,%r28 | ||
| 44 | copy %r28,%r21 | ||
| 45 | ldi 0,%r20 | ||
| 46 | copy %r21,%r20 | ||
| 47 | addib,= -1,%r31,L$0011 | ||
| 48 | stw %r29,0(0,%r26) | ||
| 49 | copy %r20,%r25 | ||
| 50 | ldi 0,%r24 | ||
| 51 | fldws -8(0,%r1),%fr9L | ||
| 52 | ldw -8(0,%r2),%r19 | ||
| 53 | xmpyu %fr8L,%fr9L,%fr9 | ||
| 54 | fstds %fr9,-16(0,%r30) | ||
| 55 | copy %r19,%r23 | ||
| 56 | ldw -16(0,%r30),%r28 | ||
| 57 | ldw -12(0,%r30),%r29 | ||
| 58 | ldi 0,%r22 | ||
| 59 | add %r23,%r29,%r29 | ||
| 60 | addc %r22,%r28,%r28 | ||
| 61 | add %r25,%r29,%r29 | ||
| 62 | addc %r24,%r28,%r28 | ||
| 63 | copy %r28,%r21 | ||
| 64 | ldi 0,%r20 | ||
| 65 | copy %r21,%r20 | ||
| 66 | addib,= -1,%r31,L$0011 | ||
| 67 | stw %r29,-8(0,%r2) | ||
| 68 | copy %r20,%r25 | ||
| 69 | ldi 0,%r24 | ||
| 70 | fldws -4(0,%r1),%fr9L | ||
| 71 | ldw -4(0,%r2),%r19 | ||
| 72 | xmpyu %fr8L,%fr9L,%fr9 | ||
| 73 | fstds %fr9,-16(0,%r30) | ||
| 74 | copy %r19,%r23 | ||
| 75 | ldw -16(0,%r30),%r28 | ||
| 76 | ldw -12(0,%r30),%r29 | ||
| 77 | ldi 0,%r22 | ||
| 78 | add %r23,%r29,%r29 | ||
| 79 | addc %r22,%r28,%r28 | ||
| 80 | add %r25,%r29,%r29 | ||
| 81 | addc %r24,%r28,%r28 | ||
| 82 | copy %r28,%r21 | ||
| 83 | ldi 0,%r20 | ||
| 84 | copy %r21,%r20 | ||
| 85 | addib,= -1,%r31,L$0011 | ||
| 86 | stw %r29,-4(0,%r2) | ||
| 87 | copy %r20,%r25 | ||
| 88 | ldi 0,%r24 | ||
| 89 | fldws 0(0,%r1),%fr9L | ||
| 90 | ldw 0(0,%r2),%r19 | ||
| 91 | xmpyu %fr8L,%fr9L,%fr9 | ||
| 92 | fstds %fr9,-16(0,%r30) | ||
| 93 | copy %r19,%r23 | ||
| 94 | ldw -16(0,%r30),%r28 | ||
| 95 | ldw -12(0,%r30),%r29 | ||
| 96 | ldi 0,%r22 | ||
| 97 | add %r23,%r29,%r29 | ||
| 98 | addc %r22,%r28,%r28 | ||
| 99 | add %r25,%r29,%r29 | ||
| 100 | addc %r24,%r28,%r28 | ||
| 101 | copy %r28,%r21 | ||
| 102 | ldi 0,%r20 | ||
| 103 | copy %r21,%r20 | ||
| 104 | addib,= -1,%r31,L$0011 | ||
| 105 | stw %r29,0(0,%r2) | ||
| 106 | ldo 16(%r1),%r1 | ||
| 107 | ldo 16(%r3),%r3 | ||
| 108 | ldo 16(%r2),%r2 | ||
| 109 | bl L$0010,0 | ||
| 110 | ldo 16(%r26),%r26 | ||
| 111 | L$0011 | ||
| 112 | copy %r20,%r28 | ||
| 113 | ldw -84(0,%r30),%r2 | ||
| 114 | ldw -60(0,%r30),%r3 | ||
| 115 | bv 0(%r2) | ||
| 116 | ldwm -64(0,%r30),%r4 | ||
| 117 | .EXIT | ||
| 118 | .PROCEND | ||
| 119 | .align 4 | ||
| 120 | .EXPORT bn_mul_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,ARGW3=GR,RTNVAL=GR | ||
| 121 | bn_mul_words | ||
| 122 | .PROC | ||
| 123 | .CALLINFO FRAME=64,CALLS,SAVE_RP,ENTRY_GR=3 | ||
| 124 | .ENTRY | ||
| 125 | stw %r2,-20(0,%r30) | ||
| 126 | copy %r25,%r2 | ||
| 127 | stwm %r4,64(0,%r30) | ||
| 128 | copy %r24,%r19 | ||
| 129 | ldi 0,%r28 | ||
| 130 | stw %r23,-16(0,%r30) | ||
| 131 | ldo 12(%r26),%r31 | ||
| 132 | ldo 12(%r2),%r29 | ||
| 133 | fldws -16(0,%r30),%fr8L | ||
| 134 | L$0026 | ||
| 135 | fldws 0(0,%r2),%fr9L | ||
| 136 | xmpyu %fr8L,%fr9L,%fr9 | ||
| 137 | fstds %fr9,-16(0,%r30) | ||
| 138 | copy %r28,%r21 | ||
| 139 | ldi 0,%r20 | ||
| 140 | ldw -16(0,%r30),%r24 | ||
| 141 | ldw -12(0,%r30),%r25 | ||
| 142 | add %r21,%r25,%r25 | ||
| 143 | addc %r20,%r24,%r24 | ||
| 144 | copy %r24,%r23 | ||
| 145 | ldi 0,%r22 | ||
| 146 | copy %r23,%r28 | ||
| 147 | addib,= -1,%r19,L$0027 | ||
| 148 | stw %r25,0(0,%r26) | ||
| 149 | fldws -8(0,%r29),%fr9L | ||
| 150 | xmpyu %fr8L,%fr9L,%fr9 | ||
| 151 | fstds %fr9,-16(0,%r30) | ||
| 152 | copy %r28,%r21 | ||
| 153 | ldi 0,%r20 | ||
| 154 | ldw -16(0,%r30),%r24 | ||
| 155 | ldw -12(0,%r30),%r25 | ||
| 156 | add %r21,%r25,%r25 | ||
| 157 | addc %r20,%r24,%r24 | ||
| 158 | copy %r24,%r23 | ||
| 159 | ldi 0,%r22 | ||
| 160 | copy %r23,%r28 | ||
| 161 | addib,= -1,%r19,L$0027 | ||
| 162 | stw %r25,-8(0,%r31) | ||
| 163 | fldws -4(0,%r29),%fr9L | ||
| 164 | xmpyu %fr8L,%fr9L,%fr9 | ||
| 165 | fstds %fr9,-16(0,%r30) | ||
| 166 | copy %r28,%r21 | ||
| 167 | ldi 0,%r20 | ||
| 168 | ldw -16(0,%r30),%r24 | ||
| 169 | ldw -12(0,%r30),%r25 | ||
| 170 | add %r21,%r25,%r25 | ||
| 171 | addc %r20,%r24,%r24 | ||
| 172 | copy %r24,%r23 | ||
| 173 | ldi 0,%r22 | ||
| 174 | copy %r23,%r28 | ||
| 175 | addib,= -1,%r19,L$0027 | ||
| 176 | stw %r25,-4(0,%r31) | ||
| 177 | fldws 0(0,%r29),%fr9L | ||
| 178 | xmpyu %fr8L,%fr9L,%fr9 | ||
| 179 | fstds %fr9,-16(0,%r30) | ||
| 180 | copy %r28,%r21 | ||
| 181 | ldi 0,%r20 | ||
| 182 | ldw -16(0,%r30),%r24 | ||
| 183 | ldw -12(0,%r30),%r25 | ||
| 184 | add %r21,%r25,%r25 | ||
| 185 | addc %r20,%r24,%r24 | ||
| 186 | copy %r24,%r23 | ||
| 187 | ldi 0,%r22 | ||
| 188 | copy %r23,%r28 | ||
| 189 | addib,= -1,%r19,L$0027 | ||
| 190 | stw %r25,0(0,%r31) | ||
| 191 | ldo 16(%r29),%r29 | ||
| 192 | ldo 16(%r2),%r2 | ||
| 193 | ldo 16(%r31),%r31 | ||
| 194 | bl L$0026,0 | ||
| 195 | ldo 16(%r26),%r26 | ||
| 196 | L$0027 | ||
| 197 | ldw -84(0,%r30),%r2 | ||
| 198 | bv 0(%r2) | ||
| 199 | ldwm -64(0,%r30),%r4 | ||
| 200 | .EXIT | ||
| 201 | .PROCEND | ||
| 202 | .align 4 | ||
| 203 | .EXPORT bn_sqr_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR | ||
| 204 | bn_sqr_words | ||
| 205 | .PROC | ||
| 206 | .CALLINFO FRAME=0,NO_CALLS | ||
| 207 | .ENTRY | ||
| 208 | ldo 28(%r26),%r19 | ||
| 209 | ldo 12(%r25),%r28 | ||
| 210 | L$0042 | ||
| 211 | fldws 0(0,%r25),%fr8L | ||
| 212 | fldws 0(0,%r25),%fr8R | ||
| 213 | xmpyu %fr8L,%fr8R,%fr8 | ||
| 214 | fstds %fr8,-16(0,%r30) | ||
| 215 | ldw -16(0,%r30),%r22 | ||
| 216 | ldw -12(0,%r30),%r23 | ||
| 217 | stw %r23,0(0,%r26) | ||
| 218 | copy %r22,%r21 | ||
| 219 | ldi 0,%r20 | ||
| 220 | addib,= -1,%r24,L$0049 | ||
| 221 | stw %r21,-24(0,%r19) | ||
| 222 | fldws -8(0,%r28),%fr8L | ||
| 223 | fldws -8(0,%r28),%fr8R | ||
| 224 | xmpyu %fr8L,%fr8R,%fr8 | ||
| 225 | fstds %fr8,-16(0,%r30) | ||
| 226 | ldw -16(0,%r30),%r22 | ||
| 227 | ldw -12(0,%r30),%r23 | ||
| 228 | stw %r23,-20(0,%r19) | ||
| 229 | copy %r22,%r21 | ||
| 230 | ldi 0,%r20 | ||
| 231 | addib,= -1,%r24,L$0049 | ||
| 232 | stw %r21,-16(0,%r19) | ||
| 233 | fldws -4(0,%r28),%fr8L | ||
| 234 | fldws -4(0,%r28),%fr8R | ||
| 235 | xmpyu %fr8L,%fr8R,%fr8 | ||
| 236 | fstds %fr8,-16(0,%r30) | ||
| 237 | ldw -16(0,%r30),%r22 | ||
| 238 | ldw -12(0,%r30),%r23 | ||
| 239 | stw %r23,-12(0,%r19) | ||
| 240 | copy %r22,%r21 | ||
| 241 | ldi 0,%r20 | ||
| 242 | addib,= -1,%r24,L$0049 | ||
| 243 | stw %r21,-8(0,%r19) | ||
| 244 | fldws 0(0,%r28),%fr8L | ||
| 245 | fldws 0(0,%r28),%fr8R | ||
| 246 | xmpyu %fr8L,%fr8R,%fr8 | ||
| 247 | fstds %fr8,-16(0,%r30) | ||
| 248 | ldw -16(0,%r30),%r22 | ||
| 249 | ldw -12(0,%r30),%r23 | ||
| 250 | stw %r23,-4(0,%r19) | ||
| 251 | copy %r22,%r21 | ||
| 252 | ldi 0,%r20 | ||
| 253 | addib,= -1,%r24,L$0049 | ||
| 254 | stw %r21,0(0,%r19) | ||
| 255 | ldo 16(%r28),%r28 | ||
| 256 | ldo 16(%r25),%r25 | ||
| 257 | ldo 32(%r19),%r19 | ||
| 258 | bl L$0042,0 | ||
| 259 | ldo 32(%r26),%r26 | ||
| 260 | L$0049 | ||
| 261 | bv,n 0(%r2) | ||
| 262 | .EXIT | ||
| 263 | .PROCEND | ||
| 264 | .IMPORT BN_num_bits_word,CODE | ||
| 265 | .IMPORT fprintf,CODE | ||
| 266 | .IMPORT __iob,DATA | ||
| 267 | .SPACE $TEXT$ | ||
| 268 | .SUBSPA $LIT$ | ||
| 269 | |||
| 270 | .align 4 | ||
| 271 | L$C0000 | ||
| 272 | .STRING "Division would overflow (%d)\x0a\x00" | ||
| 273 | .IMPORT abort,CODE | ||
| 274 | .SPACE $TEXT$ | ||
| 275 | .SUBSPA $CODE$ | ||
| 276 | |||
| 277 | .align 4 | ||
| 278 | .EXPORT bn_div64,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,RTNVAL=GR | ||
| 279 | bn_div64 | ||
| 280 | .PROC | ||
| 281 | .CALLINFO FRAME=128,CALLS,SAVE_RP,ENTRY_GR=8 | ||
| 282 | .ENTRY | ||
| 283 | stw %r2,-20(0,%r30) | ||
| 284 | stwm %r8,128(0,%r30) | ||
| 285 | stw %r7,-124(0,%r30) | ||
| 286 | stw %r4,-112(0,%r30) | ||
| 287 | stw %r3,-108(0,%r30) | ||
| 288 | copy %r26,%r3 | ||
| 289 | copy %r25,%r4 | ||
| 290 | stw %r6,-120(0,%r30) | ||
| 291 | ldi 0,%r7 | ||
| 292 | stw %r5,-116(0,%r30) | ||
| 293 | movb,<> %r24,%r5,L$0051 | ||
| 294 | ldi 2,%r6 | ||
| 295 | bl L$0068,0 | ||
| 296 | ldi -1,%r28 | ||
| 297 | L$0051 | ||
| 298 | .CALL ARGW0=GR | ||
| 299 | bl BN_num_bits_word,%r2 | ||
| 300 | copy %r5,%r26 | ||
| 301 | copy %r28,%r24 | ||
| 302 | ldi 32,%r19 | ||
| 303 | comb,= %r19,%r24,L$0052 | ||
| 304 | subi 31,%r24,%r19 | ||
| 305 | mtsar %r19 | ||
| 306 | zvdepi 1,32,%r19 | ||
| 307 | comb,>>= %r19,%r3,L$0052 | ||
| 308 | addil LR'__iob-$global$+32,%r27 | ||
| 309 | ldo RR'__iob-$global$+32(%r1),%r26 | ||
| 310 | ldil LR'L$C0000,%r25 | ||
| 311 | .CALL ARGW0=GR,ARGW1=GR,ARGW2=GR | ||
| 312 | bl fprintf,%r2 | ||
| 313 | ldo RR'L$C0000(%r25),%r25 | ||
| 314 | .CALL | ||
| 315 | bl abort,%r2 | ||
| 316 | nop | ||
| 317 | L$0052 | ||
| 318 | comb,>> %r5,%r3,L$0053 | ||
| 319 | subi 32,%r24,%r24 | ||
| 320 | sub %r3,%r5,%r3 | ||
| 321 | L$0053 | ||
| 322 | comib,= 0,%r24,L$0054 | ||
| 323 | subi 31,%r24,%r19 | ||
| 324 | mtsar %r19 | ||
| 325 | zvdep %r5,32,%r5 | ||
| 326 | zvdep %r3,32,%r21 | ||
| 327 | subi 32,%r24,%r20 | ||
| 328 | mtsar %r20 | ||
| 329 | vshd 0,%r4,%r20 | ||
| 330 | or %r21,%r20,%r3 | ||
| 331 | mtsar %r19 | ||
| 332 | zvdep %r4,32,%r4 | ||
| 333 | L$0054 | ||
| 334 | extru %r5,15,16,%r23 | ||
| 335 | extru %r5,31,16,%r28 | ||
| 336 | L$0055 | ||
| 337 | extru %r3,15,16,%r19 | ||
| 338 | comb,<> %r23,%r19,L$0058 | ||
| 339 | copy %r3,%r26 | ||
| 340 | bl L$0059,0 | ||
| 341 | zdepi -1,31,16,%r29 | ||
| 342 | L$0058 | ||
| 343 | .IMPORT $$divU,MILLICODE | ||
| 344 | bl $$divU,%r31 | ||
| 345 | copy %r23,%r25 | ||
| 346 | L$0059 | ||
| 347 | stw %r29,-16(0,%r30) | ||
| 348 | fldws -16(0,%r30),%fr10L | ||
| 349 | stw %r28,-16(0,%r30) | ||
| 350 | fldws -16(0,%r30),%fr10R | ||
| 351 | stw %r23,-16(0,%r30) | ||
| 352 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 353 | fldws -16(0,%r30),%fr10R | ||
| 354 | fstws %fr8R,-16(0,%r30) | ||
| 355 | xmpyu %fr10L,%fr10R,%fr9 | ||
| 356 | ldw -16(0,%r30),%r8 | ||
| 357 | fstws %fr9R,-16(0,%r30) | ||
| 358 | copy %r8,%r22 | ||
| 359 | ldw -16(0,%r30),%r8 | ||
| 360 | extru %r4,15,16,%r24 | ||
| 361 | copy %r8,%r21 | ||
| 362 | L$0060 | ||
| 363 | sub %r3,%r21,%r20 | ||
| 364 | copy %r20,%r19 | ||
| 365 | depi 0,31,16,%r19 | ||
| 366 | comib,<> 0,%r19,L$0061 | ||
| 367 | zdep %r20,15,16,%r19 | ||
| 368 | addl %r19,%r24,%r19 | ||
| 369 | comb,>>= %r19,%r22,L$0061 | ||
| 370 | sub %r22,%r28,%r22 | ||
| 371 | sub %r21,%r23,%r21 | ||
| 372 | bl L$0060,0 | ||
| 373 | ldo -1(%r29),%r29 | ||
| 374 | L$0061 | ||
| 375 | stw %r29,-16(0,%r30) | ||
| 376 | fldws -16(0,%r30),%fr10L | ||
| 377 | stw %r28,-16(0,%r30) | ||
| 378 | fldws -16(0,%r30),%fr10R | ||
| 379 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 380 | fstws %fr8R,-16(0,%r30) | ||
| 381 | ldw -16(0,%r30),%r8 | ||
| 382 | stw %r23,-16(0,%r30) | ||
| 383 | fldws -16(0,%r30),%fr10R | ||
| 384 | copy %r8,%r19 | ||
| 385 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 386 | fstws %fr8R,-16(0,%r30) | ||
| 387 | extru %r19,15,16,%r20 | ||
| 388 | ldw -16(0,%r30),%r8 | ||
| 389 | zdep %r19,15,16,%r19 | ||
| 390 | addl %r8,%r20,%r20 | ||
| 391 | comclr,<<= %r19,%r4,0 | ||
| 392 | addi 1,%r20,%r20 | ||
| 393 | comb,<<= %r20,%r3,L$0066 | ||
| 394 | sub %r4,%r19,%r4 | ||
| 395 | addl %r3,%r5,%r3 | ||
| 396 | ldo -1(%r29),%r29 | ||
| 397 | L$0066 | ||
| 398 | addib,= -1,%r6,L$0056 | ||
| 399 | sub %r3,%r20,%r3 | ||
| 400 | zdep %r29,15,16,%r7 | ||
| 401 | shd %r3,%r4,16,%r3 | ||
| 402 | bl L$0055,0 | ||
| 403 | zdep %r4,15,16,%r4 | ||
| 404 | L$0056 | ||
| 405 | or %r7,%r29,%r28 | ||
| 406 | L$0068 | ||
| 407 | ldw -148(0,%r30),%r2 | ||
| 408 | ldw -124(0,%r30),%r7 | ||
| 409 | ldw -120(0,%r30),%r6 | ||
| 410 | ldw -116(0,%r30),%r5 | ||
| 411 | ldw -112(0,%r30),%r4 | ||
| 412 | ldw -108(0,%r30),%r3 | ||
| 413 | bv 0(%r2) | ||
| 414 | ldwm -128(0,%r30),%r8 | ||
| 415 | .EXIT | ||
| 416 | .PROCEND | ||
diff --git a/src/lib/libcrypto/bn/bn_add.c b/src/lib/libcrypto/bn/bn_add.c new file mode 100644 index 0000000000..efb2e312e8 --- /dev/null +++ b/src/lib/libcrypto/bn/bn_add.c | |||
| @@ -0,0 +1,167 @@ | |||
| 1 | /* crypto/bn/bn_add.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_lcl.h" | ||
| 62 | |||
| 63 | /* r can == a or b */ | ||
| 64 | int BN_add(r, a, b) | ||
| 65 | BIGNUM *r; | ||
| 66 | BIGNUM *a; | ||
| 67 | BIGNUM *b; | ||
| 68 | { | ||
| 69 | int i; | ||
| 70 | BIGNUM *tmp; | ||
| 71 | |||
| 72 | /* a + b a+b | ||
| 73 | * a + -b a-b | ||
| 74 | * -a + b b-a | ||
| 75 | * -a + -b -(a+b) | ||
| 76 | */ | ||
| 77 | if (a->neg ^ b->neg) | ||
| 78 | { | ||
| 79 | /* only one is negative */ | ||
| 80 | if (a->neg) | ||
| 81 | { tmp=a; a=b; b=tmp; } | ||
| 82 | |||
| 83 | /* we are now a - b */ | ||
| 84 | |||
| 85 | if (BN_ucmp(a,b) < 0) | ||
| 86 | { | ||
| 87 | if (bn_wexpand(r,b->top) == NULL) return(0); | ||
| 88 | bn_qsub(r,b,a); | ||
| 89 | r->neg=1; | ||
| 90 | } | ||
| 91 | else | ||
| 92 | { | ||
| 93 | if (bn_wexpand(r,a->top) == NULL) return(0); | ||
| 94 | bn_qsub(r,a,b); | ||
| 95 | r->neg=0; | ||
| 96 | } | ||
| 97 | return(1); | ||
| 98 | } | ||
| 99 | |||
| 100 | if (a->neg) /* both are neg */ | ||
| 101 | r->neg=1; | ||
| 102 | else | ||
| 103 | r->neg=0; | ||
| 104 | |||
| 105 | i=(a->top > b->top); | ||
| 106 | |||
| 107 | if (i) | ||
| 108 | { | ||
| 109 | if (bn_wexpand(r,a->top+1) == NULL) return(0); | ||
| 110 | bn_qadd(r,a,b); | ||
| 111 | } | ||
| 112 | else | ||
| 113 | { | ||
| 114 | if (bn_wexpand(r,b->top+1) == NULL) return(0); | ||
| 115 | bn_qadd(r,b,a); | ||
| 116 | } | ||
| 117 | return(1); | ||
| 118 | } | ||
| 119 | |||
| 120 | /* unsigned add of b to a, r must be large enough */ | ||
| 121 | void bn_qadd(r,a,b) | ||
| 122 | BIGNUM *r; | ||
| 123 | BIGNUM *a; | ||
| 124 | BIGNUM *b; | ||
| 125 | { | ||
| 126 | register int i; | ||
| 127 | int max,min; | ||
| 128 | BN_ULONG *ap,*bp,*rp,carry,t1; | ||
| 129 | |||
| 130 | max=a->top; | ||
| 131 | min=b->top; | ||
| 132 | r->top=max; | ||
| 133 | |||
| 134 | ap=a->d; | ||
| 135 | bp=b->d; | ||
| 136 | rp=r->d; | ||
| 137 | carry=0; | ||
| 138 | |||
| 139 | carry=bn_add_words(rp,ap,bp,min); | ||
| 140 | rp+=min; | ||
| 141 | ap+=min; | ||
| 142 | bp+=min; | ||
| 143 | i=min; | ||
| 144 | |||
| 145 | if (carry) | ||
| 146 | { | ||
| 147 | while (i < max) | ||
| 148 | { | ||
| 149 | i++; | ||
| 150 | t1= *(ap++); | ||
| 151 | if ((*(rp++)=(t1+1)&BN_MASK2) >= t1) | ||
| 152 | { | ||
| 153 | carry=0; | ||
| 154 | break; | ||
| 155 | } | ||
| 156 | } | ||
| 157 | if ((i >= max) && carry) | ||
| 158 | { | ||
| 159 | *(rp++)=1; | ||
| 160 | r->top++; | ||
| 161 | } | ||
| 162 | } | ||
| 163 | for (; i<max; i++) | ||
| 164 | *(rp++)= *(ap++); | ||
| 165 | /* memcpy(rp,ap,sizeof(*ap)*(max-i));*/ | ||
| 166 | } | ||
| 167 | |||
diff --git a/src/lib/libcrypto/bn/bn_blind.c b/src/lib/libcrypto/bn/bn_blind.c new file mode 100644 index 0000000000..a7b34f0bf0 --- /dev/null +++ b/src/lib/libcrypto/bn/bn_blind.c | |||
| @@ -0,0 +1,143 @@ | |||
| 1 | /* crypto/bn/bn_blind.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_lcl.h" | ||
| 62 | |||
| 63 | BN_BLINDING *BN_BLINDING_new(A,Ai,mod) | ||
| 64 | BIGNUM *A; | ||
| 65 | BIGNUM *Ai; | ||
| 66 | BIGNUM *mod; | ||
| 67 | { | ||
| 68 | BN_BLINDING *ret=NULL; | ||
| 69 | |||
| 70 | if ((ret=(BN_BLINDING *)Malloc(sizeof(BN_BLINDING))) == NULL) | ||
| 71 | BNerr(BN_F_BN_BLINDING_NEW,ERR_R_MALLOC_FAILURE); | ||
| 72 | memset(ret,0,sizeof(BN_BLINDING)); | ||
| 73 | if ((ret->A=BN_new()) == NULL) goto err; | ||
| 74 | if ((ret->Ai=BN_new()) == NULL) goto err; | ||
| 75 | if (!BN_copy(ret->A,A)) goto err; | ||
| 76 | if (!BN_copy(ret->Ai,Ai)) goto err; | ||
| 77 | ret->mod=mod; | ||
| 78 | return(ret); | ||
| 79 | err: | ||
| 80 | if (ret != NULL) BN_BLINDING_free(ret); | ||
| 81 | return(ret); | ||
| 82 | } | ||
| 83 | |||
| 84 | void BN_BLINDING_free(r) | ||
| 85 | BN_BLINDING *r; | ||
| 86 | { | ||
| 87 | if (r->A != NULL) BN_free(r->A ); | ||
| 88 | if (r->Ai != NULL) BN_free(r->Ai); | ||
| 89 | Free(r); | ||
| 90 | } | ||
| 91 | |||
| 92 | int BN_BLINDING_update(b,ctx) | ||
| 93 | BN_BLINDING *b; | ||
| 94 | BN_CTX *ctx; | ||
| 95 | { | ||
| 96 | int ret=0; | ||
| 97 | |||
| 98 | if ((b->A == NULL) || (b->Ai == NULL)) | ||
| 99 | { | ||
| 100 | BNerr(BN_F_BN_BLINDING_UPDATE,BN_R_NOT_INITALISED); | ||
| 101 | goto err; | ||
| 102 | } | ||
| 103 | |||
| 104 | if (!BN_mod_mul(b->A,b->A,b->A,b->mod,ctx)) goto err; | ||
| 105 | if (!BN_mod_mul(b->Ai,b->Ai,b->Ai,b->mod,ctx)) goto err; | ||
| 106 | |||
| 107 | ret=1; | ||
| 108 | err: | ||
| 109 | return(ret); | ||
| 110 | } | ||
| 111 | |||
| 112 | int BN_BLINDING_convert(n,b,ctx) | ||
| 113 | BIGNUM *n; | ||
| 114 | BN_BLINDING *b; | ||
| 115 | BN_CTX *ctx; | ||
| 116 | { | ||
| 117 | if ((b->A == NULL) || (b->Ai == NULL)) | ||
| 118 | { | ||
| 119 | BNerr(BN_F_BN_BLINDING_CONVERT,BN_R_NOT_INITALISED); | ||
| 120 | return(0); | ||
| 121 | } | ||
| 122 | return(BN_mod_mul(n,n,b->A,b->mod,ctx)); | ||
| 123 | } | ||
| 124 | |||
| 125 | int BN_BLINDING_invert(n,b,ctx) | ||
| 126 | BIGNUM *n; | ||
| 127 | BN_BLINDING *b; | ||
| 128 | BN_CTX *ctx; | ||
| 129 | { | ||
| 130 | int ret; | ||
| 131 | if ((b->A == NULL) || (b->Ai == NULL)) | ||
| 132 | { | ||
| 133 | BNerr(BN_F_BN_BLINDING_INVERT,BN_R_NOT_INITALISED); | ||
| 134 | return(0); | ||
| 135 | } | ||
| 136 | if ((ret=BN_mod_mul(n,n,b->Ai,b->mod,ctx)) >= 0) | ||
| 137 | { | ||
| 138 | if (!BN_BLINDING_update(b,ctx)) | ||
| 139 | return(0); | ||
| 140 | } | ||
| 141 | return(ret); | ||
| 142 | } | ||
| 143 | |||
diff --git a/src/lib/libcrypto/bn/bn_div.c b/src/lib/libcrypto/bn/bn_div.c new file mode 100644 index 0000000000..2263bdc7da --- /dev/null +++ b/src/lib/libcrypto/bn/bn_div.c | |||
| @@ -0,0 +1,286 @@ | |||
| 1 | /* crypto/bn/bn_div.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_lcl.h" | ||
| 62 | |||
| 63 | /* The old slow way */ | ||
| 64 | #if 0 | ||
| 65 | int BN_div(dv, rem, m, d,ctx) | ||
| 66 | BIGNUM *dv; | ||
| 67 | BIGNUM *rem; | ||
| 68 | BIGNUM *m; | ||
| 69 | BIGNUM *d; | ||
| 70 | BN_CTX *ctx; | ||
| 71 | { | ||
| 72 | int i,nm,nd; | ||
| 73 | BIGNUM *D; | ||
| 74 | |||
| 75 | if (BN_is_zero(d)) | ||
| 76 | { | ||
| 77 | BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO); | ||
| 78 | return(0); | ||
| 79 | } | ||
| 80 | |||
| 81 | if (BN_ucmp(m,d) < 0) | ||
| 82 | { | ||
| 83 | if (rem != NULL) | ||
| 84 | { if (BN_copy(rem,m) == NULL) return(0); } | ||
| 85 | if (dv != NULL) BN_zero(dv); | ||
| 86 | return(1); | ||
| 87 | } | ||
| 88 | |||
| 89 | D=ctx->bn[ctx->tos]; | ||
| 90 | if (dv == NULL) dv=ctx->bn[ctx->tos+1]; | ||
| 91 | if (rem == NULL) rem=ctx->bn[ctx->tos+2]; | ||
| 92 | |||
| 93 | nd=BN_num_bits(d); | ||
| 94 | nm=BN_num_bits(m); | ||
| 95 | if (BN_copy(D,d) == NULL) return(0); | ||
| 96 | if (BN_copy(rem,m) == NULL) return(0); | ||
| 97 | |||
| 98 | /* The next 2 are needed so we can do a dv->d[0]|=1 later | ||
| 99 | * since BN_lshift1 will only work once there is a value :-) */ | ||
| 100 | BN_zero(dv); | ||
| 101 | dv->top=1; | ||
| 102 | |||
| 103 | if (!BN_lshift(D,D,nm-nd)) return(0); | ||
| 104 | for (i=nm-nd; i>=0; i--) | ||
| 105 | { | ||
| 106 | if (!BN_lshift1(dv,dv)) return(0); | ||
| 107 | if (BN_ucmp(rem,D) >= 0) | ||
| 108 | { | ||
| 109 | dv->d[0]|=1; | ||
| 110 | bn_qsub(rem,rem,D); | ||
| 111 | } | ||
| 112 | /* CAN IMPROVE (and have now :=) */ | ||
| 113 | if (!BN_rshift1(D,D)) return(0); | ||
| 114 | } | ||
| 115 | rem->neg=BN_is_zero(rem)?0:m->neg; | ||
| 116 | dv->neg=m->neg^d->neg; | ||
| 117 | return(1); | ||
| 118 | } | ||
| 119 | |||
| 120 | #else | ||
| 121 | |||
| 122 | int BN_div(dv, rm, num, divisor,ctx) | ||
| 123 | BIGNUM *dv; | ||
| 124 | BIGNUM *rm; | ||
| 125 | BIGNUM *num; | ||
| 126 | BIGNUM *divisor; | ||
| 127 | BN_CTX *ctx; | ||
| 128 | { | ||
| 129 | int norm_shift,i,j,loop; | ||
| 130 | BIGNUM *tmp,wnum,*snum,*sdiv,*res; | ||
| 131 | BN_ULONG *resp,*wnump; | ||
| 132 | BN_ULONG d0,d1; | ||
| 133 | int num_n,div_n; | ||
| 134 | |||
| 135 | if (BN_is_zero(divisor)) | ||
| 136 | { | ||
| 137 | BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO); | ||
| 138 | return(0); | ||
| 139 | } | ||
| 140 | |||
| 141 | if (BN_ucmp(num,divisor) < 0) | ||
| 142 | { | ||
| 143 | if (rm != NULL) | ||
| 144 | { if (BN_copy(rm,num) == NULL) return(0); } | ||
| 145 | if (dv != NULL) BN_zero(dv); | ||
| 146 | return(1); | ||
| 147 | } | ||
| 148 | |||
| 149 | tmp=ctx->bn[ctx->tos]; | ||
| 150 | tmp->neg=0; | ||
| 151 | snum=ctx->bn[ctx->tos+1]; | ||
| 152 | sdiv=ctx->bn[ctx->tos+2]; | ||
| 153 | if (dv == NULL) | ||
| 154 | res=ctx->bn[ctx->tos+3]; | ||
| 155 | else res=dv; | ||
| 156 | |||
| 157 | /* First we normalise the numbers */ | ||
| 158 | norm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2); | ||
| 159 | BN_lshift(sdiv,divisor,norm_shift); | ||
| 160 | sdiv->neg=0; | ||
| 161 | norm_shift+=BN_BITS2; | ||
| 162 | BN_lshift(snum,num,norm_shift); | ||
| 163 | snum->neg=0; | ||
| 164 | div_n=sdiv->top; | ||
| 165 | num_n=snum->top; | ||
| 166 | loop=num_n-div_n; | ||
| 167 | |||
| 168 | /* Lets setup a 'window' into snum | ||
| 169 | * This is the part that corresponds to the current | ||
| 170 | * 'area' being divided */ | ||
| 171 | wnum.d= &(snum->d[loop]); | ||
| 172 | wnum.top= div_n; | ||
| 173 | wnum.max= snum->max; /* a bit of a lie */ | ||
| 174 | wnum.neg= 0; | ||
| 175 | |||
| 176 | /* Get the top 2 words of sdiv */ | ||
| 177 | /* i=sdiv->top; */ | ||
| 178 | d0=sdiv->d[div_n-1]; | ||
| 179 | d1=(div_n == 1)?0:sdiv->d[div_n-2]; | ||
| 180 | |||
| 181 | /* pointer to the 'top' of snum */ | ||
| 182 | wnump= &(snum->d[num_n-1]); | ||
| 183 | |||
| 184 | /* Setup to 'res' */ | ||
| 185 | res->neg= (num->neg^divisor->neg); | ||
| 186 | res->top=loop; | ||
| 187 | if (!bn_wexpand(res,(loop+1))) goto err; | ||
| 188 | resp= &(res->d[loop-1]); | ||
| 189 | |||
| 190 | /* space for temp */ | ||
| 191 | if (!bn_wexpand(tmp,(div_n+1))) goto err; | ||
| 192 | |||
| 193 | if (BN_ucmp(&wnum,sdiv) >= 0) | ||
| 194 | { | ||
| 195 | bn_qsub(&wnum,&wnum,sdiv); | ||
| 196 | *resp=1; | ||
| 197 | res->d[res->top-1]=1; | ||
| 198 | } | ||
| 199 | else | ||
| 200 | res->top--; | ||
| 201 | resp--; | ||
| 202 | |||
| 203 | for (i=0; i<loop-1; i++) | ||
| 204 | { | ||
| 205 | BN_ULONG q,n0,n1; | ||
| 206 | BN_ULONG l0; | ||
| 207 | |||
| 208 | wnum.d--; wnum.top++; | ||
| 209 | n0=wnump[0]; | ||
| 210 | n1=wnump[-1]; | ||
| 211 | if (n0 == d0) | ||
| 212 | q=BN_MASK2; | ||
| 213 | else | ||
| 214 | q=bn_div64(n0,n1,d0); | ||
| 215 | { | ||
| 216 | #ifdef BN_LLONG | ||
| 217 | BN_ULLONG t1,t2,rem; | ||
| 218 | t1=((BN_ULLONG)n0<<BN_BITS2)|n1; | ||
| 219 | for (;;) | ||
| 220 | { | ||
| 221 | t2=(BN_ULLONG)d1*q; | ||
| 222 | rem=t1-(BN_ULLONG)q*d0; | ||
| 223 | if ((rem>>BN_BITS2) || | ||
| 224 | (t2 <= ((BN_ULLONG)(rem<<BN_BITS2)+wnump[-2]))) | ||
| 225 | break; | ||
| 226 | q--; | ||
| 227 | } | ||
| 228 | #else | ||
| 229 | BN_ULONG t1l,t1h,t2l,t2h,t3l,t3h,ql,qh,t3t; | ||
| 230 | t1h=n0; | ||
| 231 | t1l=n1; | ||
| 232 | for (;;) | ||
| 233 | { | ||
| 234 | t2l=LBITS(d1); t2h=HBITS(d1); | ||
| 235 | ql =LBITS(q); qh =HBITS(q); | ||
| 236 | mul64(t2l,t2h,ql,qh); /* t2=(BN_ULLONG)d1*q; */ | ||
| 237 | |||
| 238 | t3t=LBITS(d0); t3h=HBITS(d0); | ||
| 239 | mul64(t3t,t3h,ql,qh); /* t3=t1-(BN_ULLONG)q*d0; */ | ||
| 240 | t3l=(t1l-t3t)&BN_MASK2; | ||
| 241 | if (t3l > t1l) t3h++; | ||
| 242 | t3h=(t1h-t3h)&BN_MASK2; | ||
| 243 | |||
| 244 | /*if ((t3>>BN_BITS2) || | ||
| 245 | (t2 <= ((t3<<BN_BITS2)+wnump[-2]))) | ||
| 246 | break; */ | ||
| 247 | if (t3h) break; | ||
| 248 | if (t2h < t3l) break; | ||
| 249 | if ((t2h == t3l) && (t2l <= wnump[-2])) break; | ||
| 250 | |||
| 251 | q--; | ||
| 252 | } | ||
| 253 | #endif | ||
| 254 | } | ||
| 255 | l0=bn_mul_words(tmp->d,sdiv->d,div_n,q); | ||
| 256 | tmp->d[div_n]=l0; | ||
| 257 | for (j=div_n+1; j>0; j--) | ||
| 258 | if (tmp->d[j-1]) break; | ||
| 259 | tmp->top=j; | ||
| 260 | |||
| 261 | j=wnum.top; | ||
| 262 | BN_sub(&wnum,&wnum,tmp); | ||
| 263 | |||
| 264 | snum->top=snum->top+wnum.top-j; | ||
| 265 | |||
| 266 | if (wnum.neg) | ||
| 267 | { | ||
| 268 | q--; | ||
| 269 | j=wnum.top; | ||
| 270 | BN_add(&wnum,&wnum,sdiv); | ||
| 271 | snum->top+=wnum.top-j; | ||
| 272 | } | ||
| 273 | *(resp--)=q; | ||
| 274 | wnump--; | ||
| 275 | } | ||
| 276 | if (rm != NULL) | ||
| 277 | { | ||
| 278 | BN_rshift(rm,snum,norm_shift); | ||
| 279 | rm->neg=num->neg; | ||
| 280 | } | ||
| 281 | return(1); | ||
| 282 | err: | ||
| 283 | return(0); | ||
| 284 | } | ||
| 285 | |||
| 286 | #endif | ||
diff --git a/src/lib/libcrypto/bn/bn_err.c b/src/lib/libcrypto/bn/bn_err.c new file mode 100644 index 0000000000..029ae810d5 --- /dev/null +++ b/src/lib/libcrypto/bn/bn_err.c | |||
| @@ -0,0 +1,111 @@ | |||
| 1 | /* lib/bn/bn_err.c */ | ||
| 2 | /* Copyright (C) 1995-1997 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 | #include <stdio.h> | ||
| 59 | #include "err.h" | ||
| 60 | #include "bn.h" | ||
| 61 | |||
| 62 | /* BEGIN ERROR CODES */ | ||
| 63 | #ifndef NO_ERR | ||
| 64 | static ERR_STRING_DATA BN_str_functs[]= | ||
| 65 | { | ||
| 66 | {ERR_PACK(0,BN_F_BN_BLINDING_CONVERT,0), "BN_BLINDING_convert"}, | ||
| 67 | {ERR_PACK(0,BN_F_BN_BLINDING_INVERT,0), "BN_BLINDING_invert"}, | ||
| 68 | {ERR_PACK(0,BN_F_BN_BLINDING_NEW,0), "BN_BLINDING_new"}, | ||
| 69 | {ERR_PACK(0,BN_F_BN_BLINDING_UPDATE,0), "BN_BLINDING_update"}, | ||
| 70 | {ERR_PACK(0,BN_F_BN_BN2DEC,0), "BN_bn2dec"}, | ||
| 71 | {ERR_PACK(0,BN_F_BN_BN2HEX,0), "BN_bn2hex"}, | ||
| 72 | {ERR_PACK(0,BN_F_BN_CTX_NEW,0), "BN_CTX_new"}, | ||
| 73 | {ERR_PACK(0,BN_F_BN_DIV,0), "BN_div"}, | ||
| 74 | {ERR_PACK(0,BN_F_BN_EXPAND2,0), "bn_expand2"}, | ||
| 75 | {ERR_PACK(0,BN_F_BN_MOD_EXP_MONT,0), "BN_mod_exp_mont"}, | ||
| 76 | {ERR_PACK(0,BN_F_BN_MOD_INVERSE,0), "BN_mod_inverse"}, | ||
| 77 | {ERR_PACK(0,BN_F_BN_MOD_MUL_RECIPROCAL,0), "BN_mod_mul_reciprocal"}, | ||
| 78 | {ERR_PACK(0,BN_F_BN_MPI2BN,0), "BN_mpi2bn"}, | ||
| 79 | {ERR_PACK(0,BN_F_BN_NEW,0), "BN_new"}, | ||
| 80 | {ERR_PACK(0,BN_F_BN_RAND,0), "BN_rand"}, | ||
| 81 | {0,NULL}, | ||
| 82 | }; | ||
| 83 | |||
| 84 | static ERR_STRING_DATA BN_str_reasons[]= | ||
| 85 | { | ||
| 86 | {BN_R_BAD_RECIPROCAL ,"bad reciprocal"}, | ||
| 87 | {BN_R_CALLED_WITH_EVEN_MODULUS ,"called with even modulus"}, | ||
| 88 | {BN_R_DIV_BY_ZERO ,"div by zero"}, | ||
| 89 | {BN_R_ENCODING_ERROR ,"encoding error"}, | ||
| 90 | {BN_R_INVALID_LENGTH ,"invalid length"}, | ||
| 91 | {BN_R_NOT_INITALISED ,"not initalised"}, | ||
| 92 | {BN_R_NO_INVERSE ,"no inverse"}, | ||
| 93 | {0,NULL}, | ||
| 94 | }; | ||
| 95 | |||
| 96 | #endif | ||
| 97 | |||
| 98 | void ERR_load_BN_strings() | ||
| 99 | { | ||
| 100 | static int init=1; | ||
| 101 | |||
| 102 | if (init); | ||
| 103 | {; | ||
| 104 | init=0; | ||
| 105 | #ifndef NO_ERR | ||
| 106 | ERR_load_strings(ERR_LIB_BN,BN_str_functs); | ||
| 107 | ERR_load_strings(ERR_LIB_BN,BN_str_reasons); | ||
| 108 | #endif | ||
| 109 | |||
| 110 | } | ||
| 111 | } | ||
diff --git a/src/lib/libcrypto/bn/bn_exp.c b/src/lib/libcrypto/bn/bn_exp.c new file mode 100644 index 0000000000..c056a5083f --- /dev/null +++ b/src/lib/libcrypto/bn/bn_exp.c | |||
| @@ -0,0 +1,553 @@ | |||
| 1 | /* crypto/bn/bn_exp.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_lcl.h" | ||
| 62 | |||
| 63 | /* slow but works */ | ||
| 64 | int BN_mod_mul(ret, a, b, m, ctx) | ||
| 65 | BIGNUM *ret; | ||
| 66 | BIGNUM *a; | ||
| 67 | BIGNUM *b; | ||
| 68 | BIGNUM *m; | ||
| 69 | BN_CTX *ctx; | ||
| 70 | { | ||
| 71 | BIGNUM *t; | ||
| 72 | int r=0; | ||
| 73 | |||
| 74 | t=ctx->bn[ctx->tos++]; | ||
| 75 | if (a == b) | ||
| 76 | { if (!BN_sqr(t,a,ctx)) goto err; } | ||
| 77 | else | ||
| 78 | { if (!BN_mul(t,a,b)) goto err; } | ||
| 79 | if (!BN_mod(ret,t,m,ctx)) goto err; | ||
| 80 | r=1; | ||
| 81 | err: | ||
| 82 | ctx->tos--; | ||
| 83 | return(r); | ||
| 84 | } | ||
| 85 | |||
| 86 | #if 0 | ||
| 87 | /* this one works - simple but works */ | ||
| 88 | int BN_mod_exp(r,a,p,m,ctx) | ||
| 89 | BIGNUM *r,*a,*p,*m; | ||
| 90 | BN_CTX *ctx; | ||
| 91 | { | ||
| 92 | int i,bits,ret=0; | ||
| 93 | BIGNUM *v,*tmp; | ||
| 94 | |||
| 95 | v=ctx->bn[ctx->tos++]; | ||
| 96 | tmp=ctx->bn[ctx->tos++]; | ||
| 97 | |||
| 98 | if (BN_copy(v,a) == NULL) goto err; | ||
| 99 | bits=BN_num_bits(p); | ||
| 100 | |||
| 101 | if (BN_is_odd(p)) | ||
| 102 | { if (BN_copy(r,a) == NULL) goto err; } | ||
| 103 | else { if (BN_one(r)) goto err; } | ||
| 104 | |||
| 105 | for (i=1; i<bits; i++) | ||
| 106 | { | ||
| 107 | if (!BN_sqr(tmp,v,ctx)) goto err; | ||
| 108 | if (!BN_mod(v,tmp,m,ctx)) goto err; | ||
| 109 | if (BN_is_bit_set(p,i)) | ||
| 110 | { | ||
| 111 | if (!BN_mul(tmp,r,v)) goto err; | ||
| 112 | if (!BN_mod(r,tmp,m,ctx)) goto err; | ||
| 113 | } | ||
| 114 | } | ||
| 115 | ret=1; | ||
| 116 | err: | ||
| 117 | ctx->tos-=2; | ||
| 118 | return(ret); | ||
| 119 | } | ||
| 120 | |||
| 121 | #endif | ||
| 122 | |||
| 123 | /* this one works - simple but works */ | ||
| 124 | int BN_exp(r,a,p,ctx) | ||
| 125 | BIGNUM *r,*a,*p; | ||
| 126 | BN_CTX *ctx; | ||
| 127 | { | ||
| 128 | int i,bits,ret=0; | ||
| 129 | BIGNUM *v,*tmp; | ||
| 130 | |||
| 131 | v=ctx->bn[ctx->tos++]; | ||
| 132 | tmp=ctx->bn[ctx->tos++]; | ||
| 133 | |||
| 134 | if (BN_copy(v,a) == NULL) goto err; | ||
| 135 | bits=BN_num_bits(p); | ||
| 136 | |||
| 137 | if (BN_is_odd(p)) | ||
| 138 | { if (BN_copy(r,a) == NULL) goto err; } | ||
| 139 | else { if (BN_one(r)) goto err; } | ||
| 140 | |||
| 141 | for (i=1; i<bits; i++) | ||
| 142 | { | ||
| 143 | if (!BN_sqr(tmp,v,ctx)) goto err; | ||
| 144 | if (BN_is_bit_set(p,i)) | ||
| 145 | { | ||
| 146 | if (!BN_mul(tmp,r,v)) goto err; | ||
| 147 | } | ||
| 148 | } | ||
| 149 | ret=1; | ||
| 150 | err: | ||
| 151 | ctx->tos-=2; | ||
| 152 | return(ret); | ||
| 153 | } | ||
| 154 | |||
| 155 | int BN_mod_exp(r,a,p,m,ctx) | ||
| 156 | BIGNUM *r; | ||
| 157 | BIGNUM *a; | ||
| 158 | BIGNUM *p; | ||
| 159 | BIGNUM *m; | ||
| 160 | BN_CTX *ctx; | ||
| 161 | { | ||
| 162 | int ret; | ||
| 163 | |||
| 164 | #ifdef MONT_MUL_MOD | ||
| 165 | /* I have finally been able to take out this pre-condition of | ||
| 166 | * the top bit being set. It was caused by an error in BN_div | ||
| 167 | * with negatives. There was also another problem when for a^b%m | ||
| 168 | * a >= m. eay 07-May-97 */ | ||
| 169 | /* if ((m->d[m->top-1]&BN_TBIT) && BN_is_odd(m)) */ | ||
| 170 | |||
| 171 | if (BN_is_odd(m)) | ||
| 172 | { ret=BN_mod_exp_mont(r,a,p,m,ctx,NULL); } | ||
| 173 | else | ||
| 174 | #endif | ||
| 175 | #ifdef RECP_MUL_MOD | ||
| 176 | { ret=BN_mod_exp_recp(r,a,p,m,ctx); } | ||
| 177 | #else | ||
| 178 | { ret=BN_mod_exp_simple(r,a,p,m,ctx); } | ||
| 179 | #endif | ||
| 180 | |||
| 181 | return(ret); | ||
| 182 | } | ||
| 183 | |||
| 184 | /* #ifdef RECP_MUL_MOD */ | ||
| 185 | int BN_mod_exp_recp(r,a,p,m,ctx) | ||
| 186 | BIGNUM *r; | ||
| 187 | BIGNUM *a; | ||
| 188 | BIGNUM *p; | ||
| 189 | BIGNUM *m; | ||
| 190 | BN_CTX *ctx; | ||
| 191 | { | ||
| 192 | int nb,i,j,bits,ret=0,wstart,wend,window,wvalue; | ||
| 193 | int start=1; | ||
| 194 | BIGNUM *d,*aa; | ||
| 195 | BIGNUM *val[16]; | ||
| 196 | |||
| 197 | d=ctx->bn[ctx->tos++]; | ||
| 198 | aa=ctx->bn[ctx->tos++]; | ||
| 199 | bits=BN_num_bits(p); | ||
| 200 | |||
| 201 | if (bits == 0) | ||
| 202 | { | ||
| 203 | BN_one(r); | ||
| 204 | return(1); | ||
| 205 | } | ||
| 206 | nb=BN_reciprocal(d,m,ctx); | ||
| 207 | if (nb == -1) goto err; | ||
| 208 | |||
| 209 | val[0]=BN_new(); | ||
| 210 | if (!BN_mod(val[0],a,m,ctx)) goto err; /* 1 */ | ||
| 211 | if (!BN_mod_mul_reciprocal(aa,val[0],val[0],m,d,nb,ctx)) | ||
| 212 | goto err; /* 2 */ | ||
| 213 | |||
| 214 | if (bits <= 17) /* This is probably 3 or 0x10001, so just do singles */ | ||
| 215 | window=1; | ||
| 216 | else if (bits >= 256) | ||
| 217 | window=5; /* max size of window */ | ||
| 218 | else if (bits >= 128) | ||
| 219 | window=4; | ||
| 220 | else | ||
| 221 | window=3; | ||
| 222 | |||
| 223 | j=1<<(window-1); | ||
| 224 | for (i=1; i<j; i++) | ||
| 225 | { | ||
| 226 | val[i]=BN_new(); | ||
| 227 | if (!BN_mod_mul_reciprocal(val[i],val[i-1],aa,m,d,nb,ctx)) | ||
| 228 | goto err; | ||
| 229 | } | ||
| 230 | for (; i<16; i++) | ||
| 231 | val[i]=NULL; | ||
| 232 | |||
| 233 | start=1; /* This is used to avoid multiplication etc | ||
| 234 | * when there is only the value '1' in the | ||
| 235 | * buffer. */ | ||
| 236 | wvalue=0; /* The 'value' of the window */ | ||
| 237 | wstart=bits-1; /* The top bit of the window */ | ||
| 238 | wend=0; /* The bottom bit of the window */ | ||
| 239 | |||
| 240 | if (!BN_one(r)) goto err; | ||
| 241 | |||
| 242 | for (;;) | ||
| 243 | { | ||
| 244 | if (BN_is_bit_set(p,wstart) == 0) | ||
| 245 | { | ||
| 246 | if (!start) | ||
| 247 | if (!BN_mod_mul_reciprocal(r,r,r,m,d,nb,ctx)) | ||
| 248 | goto err; | ||
| 249 | if (wstart == 0) break; | ||
| 250 | wstart--; | ||
| 251 | continue; | ||
| 252 | } | ||
| 253 | /* We now have wstart on a 'set' bit, we now need to work out | ||
| 254 | * how bit a window to do. To do this we need to scan | ||
| 255 | * forward until the last set bit before the end of the | ||
| 256 | * window */ | ||
| 257 | j=wstart; | ||
| 258 | wvalue=1; | ||
| 259 | wend=0; | ||
| 260 | for (i=1; i<window; i++) | ||
| 261 | { | ||
| 262 | if (wstart-i < 0) break; | ||
| 263 | if (BN_is_bit_set(p,wstart-i)) | ||
| 264 | { | ||
| 265 | wvalue<<=(i-wend); | ||
| 266 | wvalue|=1; | ||
| 267 | wend=i; | ||
| 268 | } | ||
| 269 | } | ||
| 270 | |||
| 271 | /* wend is the size of the current window */ | ||
| 272 | j=wend+1; | ||
| 273 | /* add the 'bytes above' */ | ||
| 274 | if (!start) | ||
| 275 | for (i=0; i<j; i++) | ||
| 276 | { | ||
| 277 | if (!BN_mod_mul_reciprocal(r,r,r,m,d,nb,ctx)) | ||
| 278 | goto err; | ||
| 279 | } | ||
| 280 | |||
| 281 | /* wvalue will be an odd number < 2^window */ | ||
| 282 | if (!BN_mod_mul_reciprocal(r,r,val[wvalue>>1],m,d,nb,ctx)) | ||
| 283 | goto err; | ||
| 284 | |||
| 285 | /* move the 'window' down further */ | ||
| 286 | wstart-=wend+1; | ||
| 287 | wvalue=0; | ||
| 288 | start=0; | ||
| 289 | if (wstart < 0) break; | ||
| 290 | } | ||
| 291 | ret=1; | ||
| 292 | err: | ||
| 293 | ctx->tos-=2; | ||
| 294 | for (i=0; i<16; i++) | ||
| 295 | if (val[i] != NULL) BN_clear_free(val[i]); | ||
| 296 | return(ret); | ||
| 297 | } | ||
| 298 | /* #endif */ | ||
| 299 | |||
| 300 | /* #ifdef MONT_MUL_MOD */ | ||
| 301 | int BN_mod_exp_mont(r,a,p,m,ctx,in_mont) | ||
| 302 | BIGNUM *r; | ||
| 303 | BIGNUM *a; | ||
| 304 | BIGNUM *p; | ||
| 305 | BIGNUM *m; | ||
| 306 | BN_CTX *ctx; | ||
| 307 | BN_MONT_CTX *in_mont; | ||
| 308 | { | ||
| 309 | #define TABLE_SIZE 16 | ||
| 310 | int i,j,bits,ret=0,wstart,wend,window,wvalue; | ||
| 311 | int start=1; | ||
| 312 | BIGNUM *d,*aa; | ||
| 313 | BIGNUM *val[TABLE_SIZE]; | ||
| 314 | BN_MONT_CTX *mont=NULL; | ||
| 315 | |||
| 316 | if (!(m->d[0] & 1)) | ||
| 317 | { | ||
| 318 | BNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS); | ||
| 319 | return(0); | ||
| 320 | } | ||
| 321 | d=ctx->bn[ctx->tos++]; | ||
| 322 | bits=BN_num_bits(p); | ||
| 323 | if (bits == 0) | ||
| 324 | { | ||
| 325 | BN_one(r); | ||
| 326 | return(1); | ||
| 327 | } | ||
| 328 | |||
| 329 | /* If this is not done, things will break in the montgomery | ||
| 330 | * part */ | ||
| 331 | |||
| 332 | #if 1 | ||
| 333 | if (in_mont != NULL) | ||
| 334 | mont=in_mont; | ||
| 335 | else | ||
| 336 | #endif | ||
| 337 | { | ||
| 338 | if ((mont=BN_MONT_CTX_new()) == NULL) goto err; | ||
| 339 | if (!BN_MONT_CTX_set(mont,m,ctx)) goto err; | ||
| 340 | } | ||
| 341 | |||
| 342 | val[0]=BN_new(); | ||
| 343 | if (BN_ucmp(a,m) >= 0) | ||
| 344 | { | ||
| 345 | BN_mod(val[0],a,m,ctx); | ||
| 346 | aa=val[0]; | ||
| 347 | } | ||
| 348 | else | ||
| 349 | aa=a; | ||
| 350 | if (!BN_to_montgomery(val[0],aa,mont,ctx)) goto err; /* 1 */ | ||
| 351 | if (!BN_mod_mul_montgomery(d,val[0],val[0],mont,ctx)) goto err; /* 2 */ | ||
| 352 | |||
| 353 | if (bits <= 20) /* This is probably 3 or 0x10001, so just do singles */ | ||
| 354 | window=1; | ||
| 355 | else if (bits > 250) | ||
| 356 | window=5; /* max size of window */ | ||
| 357 | else if (bits >= 120) | ||
| 358 | window=4; | ||
| 359 | else | ||
| 360 | window=3; | ||
| 361 | |||
| 362 | j=1<<(window-1); | ||
| 363 | for (i=1; i<j; i++) | ||
| 364 | { | ||
| 365 | val[i]=BN_new(); | ||
| 366 | if (!BN_mod_mul_montgomery(val[i],val[i-1],d,mont,ctx)) | ||
| 367 | goto err; | ||
| 368 | } | ||
| 369 | for (; i<TABLE_SIZE; i++) | ||
| 370 | val[i]=NULL; | ||
| 371 | |||
| 372 | start=1; /* This is used to avoid multiplication etc | ||
| 373 | * when there is only the value '1' in the | ||
| 374 | * buffer. */ | ||
| 375 | wvalue=0; /* The 'value' of the window */ | ||
| 376 | wstart=bits-1; /* The top bit of the window */ | ||
| 377 | wend=0; /* The bottom bit of the window */ | ||
| 378 | |||
| 379 | if (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err; | ||
| 380 | for (;;) | ||
| 381 | { | ||
| 382 | if (BN_is_bit_set(p,wstart) == 0) | ||
| 383 | { | ||
| 384 | if (!start) | ||
| 385 | { | ||
| 386 | if (!BN_mod_mul_montgomery(r,r,r,mont,ctx)) | ||
| 387 | goto err; | ||
| 388 | } | ||
| 389 | if (wstart == 0) break; | ||
| 390 | wstart--; | ||
| 391 | continue; | ||
| 392 | } | ||
| 393 | /* We now have wstart on a 'set' bit, we now need to work out | ||
| 394 | * how bit a window to do. To do this we need to scan | ||
| 395 | * forward until the last set bit before the end of the | ||
| 396 | * window */ | ||
| 397 | j=wstart; | ||
| 398 | wvalue=1; | ||
| 399 | wend=0; | ||
| 400 | for (i=1; i<window; i++) | ||
| 401 | { | ||
| 402 | if (wstart-i < 0) break; | ||
| 403 | if (BN_is_bit_set(p,wstart-i)) | ||
| 404 | { | ||
| 405 | wvalue<<=(i-wend); | ||
| 406 | wvalue|=1; | ||
| 407 | wend=i; | ||
| 408 | } | ||
| 409 | } | ||
| 410 | |||
| 411 | /* wend is the size of the current window */ | ||
| 412 | j=wend+1; | ||
| 413 | /* add the 'bytes above' */ | ||
| 414 | if (!start) | ||
| 415 | for (i=0; i<j; i++) | ||
| 416 | { | ||
| 417 | if (!BN_mod_mul_montgomery(r,r,r,mont,ctx)) | ||
| 418 | goto err; | ||
| 419 | } | ||
| 420 | |||
| 421 | /* wvalue will be an odd number < 2^window */ | ||
| 422 | if (!BN_mod_mul_montgomery(r,r,val[wvalue>>1],mont,ctx)) | ||
| 423 | goto err; | ||
| 424 | |||
| 425 | /* move the 'window' down further */ | ||
| 426 | wstart-=wend+1; | ||
| 427 | wvalue=0; | ||
| 428 | start=0; | ||
| 429 | if (wstart < 0) break; | ||
| 430 | } | ||
| 431 | BN_from_montgomery(r,r,mont,ctx); | ||
| 432 | ret=1; | ||
| 433 | err: | ||
| 434 | if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont); | ||
| 435 | ctx->tos--; | ||
| 436 | for (i=0; i<TABLE_SIZE; i++) | ||
| 437 | if (val[i] != NULL) BN_clear_free(val[i]); | ||
| 438 | return(ret); | ||
| 439 | } | ||
| 440 | /* #endif */ | ||
| 441 | |||
| 442 | /* The old fallback, simple version :-) */ | ||
| 443 | int BN_mod_exp_simple(r,a,p,m,ctx) | ||
| 444 | BIGNUM *r; | ||
| 445 | BIGNUM *a; | ||
| 446 | BIGNUM *p; | ||
| 447 | BIGNUM *m; | ||
| 448 | BN_CTX *ctx; | ||
| 449 | { | ||
| 450 | int i,j,bits,ret=0,wstart,wend,window,wvalue; | ||
| 451 | int start=1; | ||
| 452 | BIGNUM *d; | ||
| 453 | BIGNUM *val[16]; | ||
| 454 | |||
| 455 | d=ctx->bn[ctx->tos++]; | ||
| 456 | bits=BN_num_bits(p); | ||
| 457 | |||
| 458 | if (bits == 0) | ||
| 459 | { | ||
| 460 | BN_one(r); | ||
| 461 | return(1); | ||
| 462 | } | ||
| 463 | |||
| 464 | val[0]=BN_new(); | ||
| 465 | if (!BN_mod(val[0],a,m,ctx)) goto err; /* 1 */ | ||
| 466 | if (!BN_mod_mul(d,val[0],val[0],m,ctx)) | ||
| 467 | goto err; /* 2 */ | ||
| 468 | |||
| 469 | if (bits <= 17) /* This is probably 3 or 0x10001, so just do singles */ | ||
| 470 | window=1; | ||
| 471 | else if (bits >= 256) | ||
| 472 | window=5; /* max size of window */ | ||
| 473 | else if (bits >= 128) | ||
| 474 | window=4; | ||
| 475 | else | ||
| 476 | window=3; | ||
| 477 | |||
| 478 | j=1<<(window-1); | ||
| 479 | for (i=1; i<j; i++) | ||
| 480 | { | ||
| 481 | val[i]=BN_new(); | ||
| 482 | if (!BN_mod_mul(val[i],val[i-1],d,m,ctx)) | ||
| 483 | goto err; | ||
| 484 | } | ||
| 485 | for (; i<16; i++) | ||
| 486 | val[i]=NULL; | ||
| 487 | |||
| 488 | start=1; /* This is used to avoid multiplication etc | ||
| 489 | * when there is only the value '1' in the | ||
| 490 | * buffer. */ | ||
| 491 | wvalue=0; /* The 'value' of the window */ | ||
| 492 | wstart=bits-1; /* The top bit of the window */ | ||
| 493 | wend=0; /* The bottom bit of the window */ | ||
| 494 | |||
| 495 | if (!BN_one(r)) goto err; | ||
| 496 | |||
| 497 | for (;;) | ||
| 498 | { | ||
| 499 | if (BN_is_bit_set(p,wstart) == 0) | ||
| 500 | { | ||
| 501 | if (!start) | ||
| 502 | if (!BN_mod_mul(r,r,r,m,ctx)) | ||
| 503 | goto err; | ||
| 504 | if (wstart == 0) break; | ||
| 505 | wstart--; | ||
| 506 | continue; | ||
| 507 | } | ||
| 508 | /* We now have wstart on a 'set' bit, we now need to work out | ||
| 509 | * how bit a window to do. To do this we need to scan | ||
| 510 | * forward until the last set bit before the end of the | ||
| 511 | * window */ | ||
| 512 | j=wstart; | ||
| 513 | wvalue=1; | ||
| 514 | wend=0; | ||
| 515 | for (i=1; i<window; i++) | ||
| 516 | { | ||
| 517 | if (wstart-i < 0) break; | ||
| 518 | if (BN_is_bit_set(p,wstart-i)) | ||
| 519 | { | ||
| 520 | wvalue<<=(i-wend); | ||
| 521 | wvalue|=1; | ||
| 522 | wend=i; | ||
| 523 | } | ||
| 524 | } | ||
| 525 | |||
| 526 | /* wend is the size of the current window */ | ||
| 527 | j=wend+1; | ||
| 528 | /* add the 'bytes above' */ | ||
| 529 | if (!start) | ||
| 530 | for (i=0; i<j; i++) | ||
| 531 | { | ||
| 532 | if (!BN_mod_mul(r,r,r,m,ctx)) | ||
| 533 | goto err; | ||
| 534 | } | ||
| 535 | |||
| 536 | /* wvalue will be an odd number < 2^window */ | ||
| 537 | if (!BN_mod_mul(r,r,val[wvalue>>1],m,ctx)) | ||
| 538 | goto err; | ||
| 539 | |||
| 540 | /* move the 'window' down further */ | ||
| 541 | wstart-=wend+1; | ||
| 542 | wvalue=0; | ||
| 543 | start=0; | ||
| 544 | if (wstart < 0) break; | ||
| 545 | } | ||
| 546 | ret=1; | ||
| 547 | err: | ||
| 548 | ctx->tos--; | ||
| 549 | for (i=0; i<16; i++) | ||
| 550 | if (val[i] != NULL) BN_clear_free(val[i]); | ||
| 551 | return(ret); | ||
| 552 | } | ||
| 553 | |||
diff --git a/src/lib/libcrypto/bn/bn_gcd.c b/src/lib/libcrypto/bn/bn_gcd.c new file mode 100644 index 0000000000..071bba3b4b --- /dev/null +++ b/src/lib/libcrypto/bn/bn_gcd.c | |||
| @@ -0,0 +1,203 @@ | |||
| 1 | /* crypto/bn/bn_gcd.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_lcl.h" | ||
| 62 | |||
| 63 | #ifndef NOPROTO | ||
| 64 | static BIGNUM *euclid(BIGNUM *a, BIGNUM *b); | ||
| 65 | #else | ||
| 66 | static BIGNUM *euclid(); | ||
| 67 | #endif | ||
| 68 | |||
| 69 | int BN_gcd(r,in_a,in_b,ctx) | ||
| 70 | BIGNUM *r,*in_a,*in_b; | ||
| 71 | BN_CTX *ctx; | ||
| 72 | { | ||
| 73 | BIGNUM *a,*b,*t; | ||
| 74 | int ret=0; | ||
| 75 | |||
| 76 | a=ctx->bn[ctx->tos]; | ||
| 77 | b=ctx->bn[ctx->tos+1]; | ||
| 78 | |||
| 79 | if (BN_copy(a,in_a) == NULL) goto err; | ||
| 80 | if (BN_copy(b,in_b) == NULL) goto err; | ||
| 81 | |||
| 82 | if (BN_cmp(a,b) < 0) { t=a; a=b; b=t; } | ||
| 83 | t=euclid(a,b); | ||
| 84 | if (t == NULL) goto err; | ||
| 85 | |||
| 86 | if (BN_copy(r,t) == NULL) goto err; | ||
| 87 | ret=1; | ||
| 88 | err: | ||
| 89 | return(ret); | ||
| 90 | } | ||
| 91 | |||
| 92 | static BIGNUM *euclid(a,b) | ||
| 93 | BIGNUM *a,*b; | ||
| 94 | { | ||
| 95 | BIGNUM *t; | ||
| 96 | int shifts=0; | ||
| 97 | |||
| 98 | for (;;) | ||
| 99 | { | ||
| 100 | if (BN_is_zero(b)) | ||
| 101 | break; | ||
| 102 | |||
| 103 | if (BN_is_odd(a)) | ||
| 104 | { | ||
| 105 | if (BN_is_odd(b)) | ||
| 106 | { | ||
| 107 | if (!BN_sub(a,a,b)) goto err; | ||
| 108 | if (!BN_rshift1(a,a)) goto err; | ||
| 109 | if (BN_cmp(a,b) < 0) | ||
| 110 | { t=a; a=b; b=t; } | ||
| 111 | } | ||
| 112 | else /* a odd - b even */ | ||
| 113 | { | ||
| 114 | if (!BN_rshift1(b,b)) goto err; | ||
| 115 | if (BN_cmp(a,b) < 0) | ||
| 116 | { t=a; a=b; b=t; } | ||
| 117 | } | ||
| 118 | } | ||
| 119 | else /* a is even */ | ||
| 120 | { | ||
| 121 | if (BN_is_odd(b)) | ||
| 122 | { | ||
| 123 | if (!BN_rshift1(a,a)) goto err; | ||
| 124 | if (BN_cmp(a,b) < 0) | ||
| 125 | { t=a; a=b; b=t; } | ||
| 126 | } | ||
| 127 | else /* a even - b even */ | ||
| 128 | { | ||
| 129 | if (!BN_rshift1(a,a)) goto err; | ||
| 130 | if (!BN_rshift1(b,b)) goto err; | ||
| 131 | shifts++; | ||
| 132 | } | ||
| 133 | } | ||
| 134 | } | ||
| 135 | if (shifts) | ||
| 136 | { | ||
| 137 | if (!BN_lshift(a,a,shifts)) goto err; | ||
| 138 | } | ||
| 139 | return(a); | ||
| 140 | err: | ||
| 141 | return(NULL); | ||
| 142 | } | ||
| 143 | |||
| 144 | /* solves ax == 1 (mod n) */ | ||
| 145 | BIGNUM *BN_mod_inverse(a, n, ctx) | ||
| 146 | BIGNUM *a; | ||
| 147 | BIGNUM *n; | ||
| 148 | BN_CTX *ctx; | ||
| 149 | { | ||
| 150 | BIGNUM *A,*B,*X,*Y,*M,*D,*R; | ||
| 151 | BIGNUM *ret=NULL,*T; | ||
| 152 | int sign; | ||
| 153 | |||
| 154 | A=ctx->bn[ctx->tos]; | ||
| 155 | B=ctx->bn[ctx->tos+1]; | ||
| 156 | X=ctx->bn[ctx->tos+2]; | ||
| 157 | D=ctx->bn[ctx->tos+3]; | ||
| 158 | M=ctx->bn[ctx->tos+4]; | ||
| 159 | Y=ctx->bn[ctx->tos+5]; | ||
| 160 | ctx->tos+=6; | ||
| 161 | R=BN_new(); | ||
| 162 | if (R == NULL) goto err; | ||
| 163 | |||
| 164 | BN_zero(X); | ||
| 165 | BN_one(Y); | ||
| 166 | if (BN_copy(A,a) == NULL) goto err; | ||
| 167 | if (BN_copy(B,n) == NULL) goto err; | ||
| 168 | sign=1; | ||
| 169 | |||
| 170 | while (!BN_is_zero(B)) | ||
| 171 | { | ||
| 172 | if (!BN_div(D,M,A,B,ctx)) goto err; | ||
| 173 | T=A; | ||
| 174 | A=B; | ||
| 175 | B=M; | ||
| 176 | /* T has a struct, M does not */ | ||
| 177 | |||
| 178 | if (!BN_mul(T,D,X)) goto err; | ||
| 179 | if (!BN_add(T,T,Y)) goto err; | ||
| 180 | M=Y; | ||
| 181 | Y=X; | ||
| 182 | X=T; | ||
| 183 | sign= -sign; | ||
| 184 | } | ||
| 185 | if (sign < 0) | ||
| 186 | { | ||
| 187 | if (!BN_sub(Y,n,Y)) goto err; | ||
| 188 | } | ||
| 189 | |||
| 190 | if (BN_is_one(A)) | ||
| 191 | { if (!BN_mod(R,Y,n,ctx)) goto err; } | ||
| 192 | else | ||
| 193 | { | ||
| 194 | BNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE); | ||
| 195 | goto err; | ||
| 196 | } | ||
| 197 | ret=R; | ||
| 198 | err: | ||
| 199 | if ((ret == NULL) && (R != NULL)) BN_free(R); | ||
| 200 | ctx->tos-=6; | ||
| 201 | return(ret); | ||
| 202 | } | ||
| 203 | |||
diff --git a/src/lib/libcrypto/bn/bn_lcl.h b/src/lib/libcrypto/bn/bn_lcl.h new file mode 100644 index 0000000000..edfd788338 --- /dev/null +++ b/src/lib/libcrypto/bn/bn_lcl.h | |||
| @@ -0,0 +1,199 @@ | |||
| 1 | /* crypto/bn/bn_lcl.h */ | ||
| 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 | #ifndef HEADER_BN_LCL_H | ||
| 60 | #define HEADER_BN_LCL_H | ||
| 61 | |||
| 62 | #include "bn.h" | ||
| 63 | |||
| 64 | #ifdef __cplusplus | ||
| 65 | extern "C" { | ||
| 66 | #endif | ||
| 67 | |||
| 68 | /************************************************************* | ||
| 69 | * Using the long long type | ||
| 70 | */ | ||
| 71 | #define Lw(t) (((BN_ULONG)(t))&BN_MASK2) | ||
| 72 | #define Hw(t) (((BN_ULONG)((t)>>BN_BITS2))&BN_MASK2) | ||
| 73 | |||
| 74 | #define bn_fix_top(a) \ | ||
| 75 | { \ | ||
| 76 | BN_ULONG *fix_top_l; \ | ||
| 77 | for (fix_top_l= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \ | ||
| 78 | if (*(fix_top_l--)) break; \ | ||
| 79 | } | ||
| 80 | |||
| 81 | /* #define bn_expand(n,b) ((((b)/BN_BITS2) <= (n)->max)?(n):bn_expand2((n),(b))) */ | ||
| 82 | |||
| 83 | #ifdef BN_LLONG | ||
| 84 | #define mul_add(r,a,w,c) { \ | ||
| 85 | BN_ULLONG t; \ | ||
| 86 | t=(BN_ULLONG)w * (a) + (r) + (c); \ | ||
| 87 | (r)= Lw(t); \ | ||
| 88 | (c)= Hw(t); \ | ||
| 89 | } | ||
| 90 | |||
| 91 | #define mul(r,a,w,c) { \ | ||
| 92 | BN_ULLONG t; \ | ||
| 93 | t=(BN_ULLONG)w * (a) + (c); \ | ||
| 94 | (r)= Lw(t); \ | ||
| 95 | (c)= Hw(t); \ | ||
| 96 | } | ||
| 97 | |||
| 98 | #else | ||
| 99 | /************************************************************* | ||
| 100 | * No long long type | ||
| 101 | */ | ||
| 102 | |||
| 103 | #define LBITS(a) ((a)&BN_MASK2l) | ||
| 104 | #define HBITS(a) (((a)>>BN_BITS4)&BN_MASK2l) | ||
| 105 | #define L2HBITS(a) ((BN_ULONG)((a)&BN_MASK2l)<<BN_BITS4) | ||
| 106 | |||
| 107 | #define LLBITS(a) ((a)&BN_MASKl) | ||
| 108 | #define LHBITS(a) (((a)>>BN_BITS2)&BN_MASKl) | ||
| 109 | #define LL2HBITS(a) ((BN_ULLONG)((a)&BN_MASKl)<<BN_BITS2) | ||
| 110 | |||
| 111 | #define mul64(l,h,bl,bh) \ | ||
| 112 | { \ | ||
| 113 | BN_ULONG m,m1,lt,ht; \ | ||
| 114 | \ | ||
| 115 | lt=l; \ | ||
| 116 | ht=h; \ | ||
| 117 | m =(bh)*(lt); \ | ||
| 118 | lt=(bl)*(lt); \ | ||
| 119 | m1=(bl)*(ht); \ | ||
| 120 | ht =(bh)*(ht); \ | ||
| 121 | m=(m+m1)&BN_MASK2; if (m < m1) ht+=L2HBITS(1L); \ | ||
| 122 | ht+=HBITS(m); \ | ||
| 123 | m1=L2HBITS(m); \ | ||
| 124 | lt=(lt+m1)&BN_MASK2; if (lt < m1) ht++; \ | ||
| 125 | (l)=lt; \ | ||
| 126 | (h)=ht; \ | ||
| 127 | } | ||
| 128 | |||
| 129 | #define sqr64(lo,ho,in) \ | ||
| 130 | { \ | ||
| 131 | BN_ULONG l,h,m; \ | ||
| 132 | \ | ||
| 133 | h=(in); \ | ||
| 134 | l=LBITS(h); \ | ||
| 135 | h=HBITS(h); \ | ||
| 136 | m =(l)*(h); \ | ||
| 137 | l*=l; \ | ||
| 138 | h*=h; \ | ||
| 139 | h+=(m&BN_MASK2h1)>>(BN_BITS4-1); \ | ||
| 140 | m =(m&BN_MASK2l)<<(BN_BITS4+1); \ | ||
| 141 | l=(l+m)&BN_MASK2; if (l < m) h++; \ | ||
| 142 | (lo)=l; \ | ||
| 143 | (ho)=h; \ | ||
| 144 | } | ||
| 145 | |||
| 146 | #define mul_add(r,a,bl,bh,c) { \ | ||
| 147 | BN_ULONG l,h; \ | ||
| 148 | \ | ||
| 149 | h= (a); \ | ||
| 150 | l=LBITS(h); \ | ||
| 151 | h=HBITS(h); \ | ||
| 152 | mul64(l,h,(bl),(bh)); \ | ||
| 153 | \ | ||
| 154 | /* non-multiply part */ \ | ||
| 155 | l=(l+(c))&BN_MASK2; if (l < (c)) h++; \ | ||
| 156 | (c)=(r); \ | ||
| 157 | l=(l+(c))&BN_MASK2; if (l < (c)) h++; \ | ||
| 158 | (c)=h&BN_MASK2; \ | ||
| 159 | (r)=l; \ | ||
| 160 | } | ||
| 161 | |||
| 162 | #define mul(r,a,bl,bh,c) { \ | ||
| 163 | BN_ULONG l,h; \ | ||
| 164 | \ | ||
| 165 | h= (a); \ | ||
| 166 | l=LBITS(h); \ | ||
| 167 | h=HBITS(h); \ | ||
| 168 | mul64(l,h,(bl),(bh)); \ | ||
| 169 | \ | ||
| 170 | /* non-multiply part */ \ | ||
| 171 | l+=(c); if ((l&BN_MASK2) < (c)) h++; \ | ||
| 172 | (c)=h&BN_MASK2; \ | ||
| 173 | (r)=l&BN_MASK2; \ | ||
| 174 | } | ||
| 175 | |||
| 176 | #endif | ||
| 177 | |||
| 178 | #ifndef NOPROTO | ||
| 179 | |||
| 180 | BIGNUM *bn_expand2(BIGNUM *b, int bits); | ||
| 181 | |||
| 182 | #ifdef X86_ASM | ||
| 183 | void bn_add_words(BN_ULONG *r,BN_ULONG *a,int num); | ||
| 184 | #endif | ||
| 185 | |||
| 186 | #else | ||
| 187 | |||
| 188 | BIGNUM *bn_expand2(); | ||
| 189 | #ifdef X86_ASM | ||
| 190 | BN_ULONG bn_add_words(); | ||
| 191 | #endif | ||
| 192 | |||
| 193 | #endif | ||
| 194 | |||
| 195 | #ifdef __cplusplus | ||
| 196 | } | ||
| 197 | #endif | ||
| 198 | |||
| 199 | #endif | ||
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c new file mode 100644 index 0000000000..bfe7628ad4 --- /dev/null +++ b/src/lib/libcrypto/bn/bn_lib.c | |||
| @@ -0,0 +1,611 @@ | |||
| 1 | /* crypto/bn/bn_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 "bn_lcl.h" | ||
| 62 | |||
| 63 | char *BN_version="Big Number part of SSLeay 0.9.0b 29-Jun-1998"; | ||
| 64 | |||
| 65 | BIGNUM *BN_value_one() | ||
| 66 | { | ||
| 67 | static BN_ULONG data_one=1L; | ||
| 68 | static BIGNUM const_one={&data_one,1,1,0}; | ||
| 69 | |||
| 70 | return(&const_one); | ||
| 71 | } | ||
| 72 | |||
| 73 | char *BN_options() | ||
| 74 | { | ||
| 75 | static int init=0; | ||
| 76 | static char data[16]; | ||
| 77 | |||
| 78 | if (!init) | ||
| 79 | { | ||
| 80 | init++; | ||
| 81 | #ifdef BN_LLONG | ||
| 82 | sprintf(data,"bn(%d,%d)",(int)sizeof(BN_ULLONG)*8, | ||
| 83 | (int)sizeof(BN_ULONG)*8); | ||
| 84 | #else | ||
| 85 | sprintf(data,"bn(%d,%d)",(int)sizeof(BN_ULONG)*8, | ||
| 86 | (int)sizeof(BN_ULONG)*8); | ||
| 87 | #endif | ||
| 88 | } | ||
| 89 | return(data); | ||
| 90 | } | ||
| 91 | |||
| 92 | int BN_num_bits_word(l) | ||
| 93 | BN_ULONG l; | ||
| 94 | { | ||
| 95 | static char bits[256]={ | ||
| 96 | 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4, | ||
| 97 | 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, | ||
| 98 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, | ||
| 99 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, | ||
| 100 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
| 101 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
| 102 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
| 103 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
| 104 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | ||
| 105 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | ||
| 106 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | ||
| 107 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | ||
| 108 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | ||
| 109 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | ||
| 110 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | ||
| 111 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | ||
| 112 | }; | ||
| 113 | |||
| 114 | #ifdef SIXTY_FOUR_BIT_LONG | ||
| 115 | if (l & 0xffffffff00000000L) | ||
| 116 | { | ||
| 117 | if (l & 0xffff000000000000L) | ||
| 118 | { | ||
| 119 | if (l & 0xff00000000000000L) | ||
| 120 | { | ||
| 121 | return(bits[l>>56]+56); | ||
| 122 | } | ||
| 123 | else return(bits[l>>48]+48); | ||
| 124 | } | ||
| 125 | else | ||
| 126 | { | ||
| 127 | if (l & 0x0000ff0000000000L) | ||
| 128 | { | ||
| 129 | return(bits[l>>40]+40); | ||
| 130 | } | ||
| 131 | else return(bits[l>>32]+32); | ||
| 132 | } | ||
| 133 | } | ||
| 134 | else | ||
| 135 | #else | ||
| 136 | #ifdef SIXTY_FOUR_BIT | ||
| 137 | if (l & 0xffffffff00000000LL) | ||
| 138 | { | ||
| 139 | if (l & 0xffff000000000000LL) | ||
| 140 | { | ||
| 141 | if (l & 0xff00000000000000LL) | ||
| 142 | { | ||
| 143 | return(bits[l>>56]+56); | ||
| 144 | } | ||
| 145 | else return(bits[l>>48]+48); | ||
| 146 | } | ||
| 147 | else | ||
| 148 | { | ||
| 149 | if (l & 0x0000ff0000000000LL) | ||
| 150 | { | ||
| 151 | return(bits[l>>40]+40); | ||
| 152 | } | ||
| 153 | else return(bits[l>>32]+32); | ||
| 154 | } | ||
| 155 | } | ||
| 156 | else | ||
| 157 | #endif | ||
| 158 | #endif | ||
| 159 | { | ||
| 160 | #if defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG) | ||
| 161 | if (l & 0xffff0000L) | ||
| 162 | { | ||
| 163 | if (l & 0xff000000L) | ||
| 164 | return(bits[l>>24L]+24); | ||
| 165 | else return(bits[l>>16L]+16); | ||
| 166 | } | ||
| 167 | else | ||
| 168 | #endif | ||
| 169 | { | ||
| 170 | #if defined(SIXTEEN_BIT) || defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG) | ||
| 171 | if (l & 0xff00L) | ||
| 172 | return(bits[l>>8]+8); | ||
| 173 | else | ||
| 174 | #endif | ||
| 175 | return(bits[l ] ); | ||
| 176 | } | ||
| 177 | } | ||
| 178 | } | ||
| 179 | |||
| 180 | int BN_num_bits(a) | ||
| 181 | BIGNUM *a; | ||
| 182 | { | ||
| 183 | BN_ULONG l; | ||
| 184 | int i; | ||
| 185 | |||
| 186 | if (a->top == 0) return(0); | ||
| 187 | l=a->d[a->top-1]; | ||
| 188 | i=(a->top-1)*BN_BITS2; | ||
| 189 | if (l == 0) | ||
| 190 | { | ||
| 191 | #if !defined(NO_STDIO) && !defined(WIN16) | ||
| 192 | fprintf(stderr,"BAD TOP VALUE\n"); | ||
| 193 | #endif | ||
| 194 | abort(); | ||
| 195 | } | ||
| 196 | return(i+BN_num_bits_word(l)); | ||
| 197 | } | ||
| 198 | |||
| 199 | void BN_clear_free(a) | ||
| 200 | BIGNUM *a; | ||
| 201 | { | ||
| 202 | if (a == NULL) return; | ||
| 203 | if (a->d != NULL) | ||
| 204 | { | ||
| 205 | memset(a->d,0,a->max*sizeof(a->d[0])); | ||
| 206 | Free(a->d); | ||
| 207 | } | ||
| 208 | memset(a,0,sizeof(BIGNUM)); | ||
| 209 | Free(a); | ||
| 210 | } | ||
| 211 | |||
| 212 | void BN_free(a) | ||
| 213 | BIGNUM *a; | ||
| 214 | { | ||
| 215 | if (a == NULL) return; | ||
| 216 | if (a->d != NULL) Free(a->d); | ||
| 217 | Free(a); | ||
| 218 | } | ||
| 219 | |||
| 220 | BIGNUM *BN_new() | ||
| 221 | { | ||
| 222 | BIGNUM *ret; | ||
| 223 | BN_ULONG *p; | ||
| 224 | |||
| 225 | ret=(BIGNUM *)Malloc(sizeof(BIGNUM)); | ||
| 226 | if (ret == NULL) goto err; | ||
| 227 | ret->top=0; | ||
| 228 | ret->neg=0; | ||
| 229 | ret->max=(BN_DEFAULT_BITS/BN_BITS2); | ||
| 230 | p=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(ret->max+1)); | ||
| 231 | if (p == NULL) goto err; | ||
| 232 | ret->d=p; | ||
| 233 | |||
| 234 | memset(p,0,(ret->max+1)*sizeof(p[0])); | ||
| 235 | return(ret); | ||
| 236 | err: | ||
| 237 | BNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE); | ||
| 238 | return(NULL); | ||
| 239 | } | ||
| 240 | |||
| 241 | BN_CTX *BN_CTX_new() | ||
| 242 | { | ||
| 243 | BN_CTX *ret; | ||
| 244 | BIGNUM *n; | ||
| 245 | int i,j; | ||
| 246 | |||
| 247 | ret=(BN_CTX *)Malloc(sizeof(BN_CTX)); | ||
| 248 | if (ret == NULL) goto err2; | ||
| 249 | |||
| 250 | for (i=0; i<BN_CTX_NUM; i++) | ||
| 251 | { | ||
| 252 | n=BN_new(); | ||
| 253 | if (n == NULL) goto err; | ||
| 254 | ret->bn[i]=n; | ||
| 255 | } | ||
| 256 | |||
| 257 | /* There is actually an extra one, this is for debugging my | ||
| 258 | * stuff */ | ||
| 259 | ret->bn[BN_CTX_NUM]=NULL; | ||
| 260 | |||
| 261 | ret->tos=0; | ||
| 262 | return(ret); | ||
| 263 | err: | ||
| 264 | for (j=0; j<i; j++) | ||
| 265 | BN_free(ret->bn[j]); | ||
| 266 | Free(ret); | ||
| 267 | err2: | ||
| 268 | BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE); | ||
| 269 | return(NULL); | ||
| 270 | } | ||
| 271 | |||
| 272 | void BN_CTX_free(c) | ||
| 273 | BN_CTX *c; | ||
| 274 | { | ||
| 275 | int i; | ||
| 276 | |||
| 277 | for (i=0; i<BN_CTX_NUM; i++) | ||
| 278 | BN_clear_free(c->bn[i]); | ||
| 279 | Free(c); | ||
| 280 | } | ||
| 281 | |||
| 282 | BIGNUM *bn_expand2(b, words) | ||
| 283 | BIGNUM *b; | ||
| 284 | int words; | ||
| 285 | { | ||
| 286 | BN_ULONG *p; | ||
| 287 | |||
| 288 | if (words > b->max) | ||
| 289 | { | ||
| 290 | p=(BN_ULONG *)Realloc(b->d,sizeof(BN_ULONG)*(words+1)); | ||
| 291 | if (p == NULL) | ||
| 292 | { | ||
| 293 | BNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE); | ||
| 294 | return(NULL); | ||
| 295 | } | ||
| 296 | b->d=p; | ||
| 297 | memset(&(p[b->max]),0,((words+1)-b->max)*sizeof(BN_ULONG)); | ||
| 298 | b->max=words; | ||
| 299 | } | ||
| 300 | return(b); | ||
| 301 | } | ||
| 302 | |||
| 303 | BIGNUM *BN_dup(a) | ||
| 304 | BIGNUM *a; | ||
| 305 | { | ||
| 306 | BIGNUM *r; | ||
| 307 | |||
| 308 | r=BN_new(); | ||
| 309 | if (r == NULL) return(NULL); | ||
| 310 | return((BIGNUM *)BN_copy(r,a)); | ||
| 311 | } | ||
| 312 | |||
| 313 | BIGNUM *BN_copy(a, b) | ||
| 314 | BIGNUM *a; | ||
| 315 | BIGNUM *b; | ||
| 316 | { | ||
| 317 | int i; | ||
| 318 | BN_ULONG *A,*B; | ||
| 319 | |||
| 320 | if (a == b) return(a); | ||
| 321 | if (bn_wexpand(a,b->top) == NULL) return(NULL); | ||
| 322 | |||
| 323 | #if 1 | ||
| 324 | A=a->d; | ||
| 325 | B=b->d; | ||
| 326 | for (i=b->top&(~7); i>0; i-=8) | ||
| 327 | { | ||
| 328 | A[0]=B[0]; | ||
| 329 | A[1]=B[1]; | ||
| 330 | A[2]=B[2]; | ||
| 331 | A[3]=B[3]; | ||
| 332 | A[4]=B[4]; | ||
| 333 | A[5]=B[5]; | ||
| 334 | A[6]=B[6]; | ||
| 335 | A[7]=B[7]; | ||
| 336 | A+=8; | ||
| 337 | B+=8; | ||
| 338 | } | ||
| 339 | switch (b->top&7) | ||
| 340 | { | ||
| 341 | case 7: | ||
| 342 | A[6]=B[6]; | ||
| 343 | case 6: | ||
| 344 | A[5]=B[5]; | ||
| 345 | case 5: | ||
| 346 | A[4]=B[4]; | ||
| 347 | case 4: | ||
| 348 | A[3]=B[3]; | ||
| 349 | case 3: | ||
| 350 | A[2]=B[2]; | ||
| 351 | case 2: | ||
| 352 | A[1]=B[1]; | ||
| 353 | case 1: | ||
| 354 | A[0]=B[0]; | ||
| 355 | } | ||
| 356 | #else | ||
| 357 | memcpy(a->d,b->d,sizeof(b->d[0])*b->top); | ||
| 358 | #endif | ||
| 359 | |||
| 360 | /* memset(&(a->d[b->top]),0,sizeof(a->d[0])*(a->max-b->top));*/ | ||
| 361 | a->top=b->top; | ||
| 362 | if (a->top == 0) | ||
| 363 | a->d[0]=0; | ||
| 364 | a->neg=b->neg; | ||
| 365 | return(a); | ||
| 366 | } | ||
| 367 | |||
| 368 | void BN_clear(a) | ||
| 369 | BIGNUM *a; | ||
| 370 | { | ||
| 371 | memset(a->d,0,a->max*sizeof(a->d[0])); | ||
| 372 | a->top=0; | ||
| 373 | a->neg=0; | ||
| 374 | } | ||
| 375 | |||
| 376 | unsigned long BN_get_word(a) | ||
| 377 | BIGNUM *a; | ||
| 378 | { | ||
| 379 | int i,n; | ||
| 380 | unsigned long ret=0; | ||
| 381 | |||
| 382 | n=BN_num_bytes(a); | ||
| 383 | if (n > sizeof(unsigned long)) | ||
| 384 | #ifdef SIXTY_FOUR_BIT_LONG | ||
| 385 | return(BN_MASK2); | ||
| 386 | #else | ||
| 387 | return(0xFFFFFFFFL); | ||
| 388 | #endif | ||
| 389 | for (i=a->top-1; i>=0; i--) | ||
| 390 | { | ||
| 391 | #ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */ | ||
| 392 | ret<<=BN_BITS4; /* stops the compiler complaining */ | ||
| 393 | ret<<=BN_BITS4; | ||
| 394 | #endif | ||
| 395 | ret|=a->d[i]; | ||
| 396 | } | ||
| 397 | return(ret); | ||
| 398 | } | ||
| 399 | |||
| 400 | int BN_set_word(a,w) | ||
| 401 | BIGNUM *a; | ||
| 402 | unsigned long w; | ||
| 403 | { | ||
| 404 | int i,n; | ||
| 405 | if (bn_expand(a,sizeof(unsigned long)*8) == NULL) return(0); | ||
| 406 | |||
| 407 | n=sizeof(unsigned long)/BN_BYTES; | ||
| 408 | a->neg=0; | ||
| 409 | a->top=0; | ||
| 410 | a->d[0]=(BN_ULONG)w&BN_MASK2; | ||
| 411 | if (a->d[0] != 0) a->top=1; | ||
| 412 | for (i=1; i<n; i++) | ||
| 413 | { | ||
| 414 | /* the following is done instead of | ||
| 415 | * w>>=BN_BITS2 so compilers don't complain | ||
| 416 | * on builds where sizeof(long) == BN_TYPES */ | ||
| 417 | #ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */ | ||
| 418 | w>>=BN_BITS4; | ||
| 419 | w>>=BN_BITS4; | ||
| 420 | #endif | ||
| 421 | a->d[i]=(BN_ULONG)w&BN_MASK2; | ||
| 422 | if (a->d[i] != 0) a->top=i+1; | ||
| 423 | } | ||
| 424 | return(1); | ||
| 425 | } | ||
| 426 | |||
| 427 | /* ignore negative */ | ||
| 428 | BIGNUM *BN_bin2bn(s, len, ret) | ||
| 429 | unsigned char *s; | ||
| 430 | int len; | ||
| 431 | BIGNUM *ret; | ||
| 432 | { | ||
| 433 | unsigned int i,m; | ||
| 434 | unsigned int n; | ||
| 435 | BN_ULONG l; | ||
| 436 | |||
| 437 | if (ret == NULL) ret=BN_new(); | ||
| 438 | if (ret == NULL) return(NULL); | ||
| 439 | l=0; | ||
| 440 | n=len; | ||
| 441 | if (n == 0) | ||
| 442 | { | ||
| 443 | ret->top=0; | ||
| 444 | return(ret); | ||
| 445 | } | ||
| 446 | if (bn_expand(ret,(int)(n+2)*8) == NULL) | ||
| 447 | return(NULL); | ||
| 448 | i=((n-1)/BN_BYTES)+1; | ||
| 449 | m=((n-1)%(BN_BYTES)); | ||
| 450 | ret->top=i; | ||
| 451 | while (n-- > 0) | ||
| 452 | { | ||
| 453 | l=(l<<8L)| *(s++); | ||
| 454 | if (m-- == 0) | ||
| 455 | { | ||
| 456 | ret->d[--i]=l; | ||
| 457 | l=0; | ||
| 458 | m=BN_BYTES-1; | ||
| 459 | } | ||
| 460 | } | ||
| 461 | /* need to call this due to clear byte at top if avoiding | ||
| 462 | * having the top bit set (-ve number) */ | ||
| 463 | bn_fix_top(ret); | ||
| 464 | return(ret); | ||
| 465 | } | ||
| 466 | |||
| 467 | /* ignore negative */ | ||
| 468 | int BN_bn2bin(a, to) | ||
| 469 | BIGNUM *a; | ||
| 470 | unsigned char *to; | ||
| 471 | { | ||
| 472 | int n,i; | ||
| 473 | BN_ULONG l; | ||
| 474 | |||
| 475 | n=i=BN_num_bytes(a); | ||
| 476 | while (i-- > 0) | ||
| 477 | { | ||
| 478 | l=a->d[i/BN_BYTES]; | ||
| 479 | *(to++)=(unsigned char)(l>>(8*(i%BN_BYTES)))&0xff; | ||
| 480 | } | ||
| 481 | return(n); | ||
| 482 | } | ||
| 483 | |||
| 484 | int BN_ucmp(a, b) | ||
| 485 | BIGNUM *a; | ||
| 486 | BIGNUM *b; | ||
| 487 | { | ||
| 488 | int i; | ||
| 489 | BN_ULONG t1,t2,*ap,*bp; | ||
| 490 | |||
| 491 | i=a->top-b->top; | ||
| 492 | if (i != 0) return(i); | ||
| 493 | ap=a->d; | ||
| 494 | bp=b->d; | ||
| 495 | for (i=a->top-1; i>=0; i--) | ||
| 496 | { | ||
| 497 | t1= ap[i]; | ||
| 498 | t2= bp[i]; | ||
| 499 | if (t1 != t2) | ||
| 500 | return(t1 > t2?1:-1); | ||
| 501 | } | ||
| 502 | return(0); | ||
| 503 | } | ||
| 504 | |||
| 505 | int BN_cmp(a, b) | ||
| 506 | BIGNUM *a; | ||
| 507 | BIGNUM *b; | ||
| 508 | { | ||
| 509 | int i; | ||
| 510 | int gt,lt; | ||
| 511 | BN_ULONG t1,t2; | ||
| 512 | |||
| 513 | if ((a == NULL) || (b == NULL)) | ||
| 514 | { | ||
| 515 | if (a != NULL) | ||
| 516 | return(-1); | ||
| 517 | else if (b != NULL) | ||
| 518 | return(1); | ||
| 519 | else | ||
| 520 | return(0); | ||
| 521 | } | ||
| 522 | if (a->neg != b->neg) | ||
| 523 | { | ||
| 524 | if (a->neg) | ||
| 525 | return(-1); | ||
| 526 | else return(1); | ||
| 527 | } | ||
| 528 | if (a->neg == 0) | ||
| 529 | { gt=1; lt= -1; } | ||
| 530 | else { gt= -1; lt=1; } | ||
| 531 | |||
| 532 | if (a->top > b->top) return(gt); | ||
| 533 | if (a->top < b->top) return(lt); | ||
| 534 | for (i=a->top-1; i>=0; i--) | ||
| 535 | { | ||
| 536 | t1=a->d[i]; | ||
| 537 | t2=b->d[i]; | ||
| 538 | if (t1 > t2) return(gt); | ||
| 539 | if (t1 < t2) return(lt); | ||
| 540 | } | ||
| 541 | return(0); | ||
| 542 | } | ||
| 543 | |||
| 544 | int BN_set_bit(a, n) | ||
| 545 | BIGNUM *a; | ||
| 546 | int n; | ||
| 547 | { | ||
| 548 | int i,j; | ||
| 549 | |||
| 550 | i=n/BN_BITS2; | ||
| 551 | j=n%BN_BITS2; | ||
| 552 | if (a->top <= i) | ||
| 553 | { | ||
| 554 | if (bn_expand(a,n) == NULL) return(0); | ||
| 555 | a->top=i+1; | ||
| 556 | } | ||
| 557 | |||
| 558 | a->d[i]|=(1L<<j); | ||
| 559 | return(1); | ||
| 560 | } | ||
| 561 | |||
| 562 | int BN_clear_bit(a, n) | ||
| 563 | BIGNUM *a; | ||
| 564 | int n; | ||
| 565 | { | ||
| 566 | int i,j; | ||
| 567 | |||
| 568 | i=n/BN_BITS2; | ||
| 569 | j=n%BN_BITS2; | ||
| 570 | if (a->top <= i) return(0); | ||
| 571 | |||
| 572 | a->d[i]&=(~(1L<<j)); | ||
| 573 | return(1); | ||
| 574 | } | ||
| 575 | |||
| 576 | int BN_is_bit_set(a, n) | ||
| 577 | BIGNUM *a; | ||
| 578 | int n; | ||
| 579 | { | ||
| 580 | int i,j; | ||
| 581 | |||
| 582 | if (n < 0) return(0); | ||
| 583 | i=n/BN_BITS2; | ||
| 584 | j=n%BN_BITS2; | ||
| 585 | if (a->top <= i) return(0); | ||
| 586 | return((a->d[i]&(((BN_ULONG)1)<<j))?1:0); | ||
| 587 | } | ||
| 588 | |||
| 589 | int BN_mask_bits(a,n) | ||
| 590 | BIGNUM *a; | ||
| 591 | int n; | ||
| 592 | { | ||
| 593 | int b,w; | ||
| 594 | |||
| 595 | w=n/BN_BITS2; | ||
| 596 | b=n%BN_BITS2; | ||
| 597 | if (w >= a->top) return(0); | ||
| 598 | if (b == 0) | ||
| 599 | a->top=w; | ||
| 600 | else | ||
| 601 | { | ||
| 602 | a->top=w+1; | ||
| 603 | a->d[w]&= ~(BN_MASK2<<b); | ||
| 604 | while ((w >= 0) && (a->d[w] == 0)) | ||
| 605 | { | ||
| 606 | a->top--; | ||
| 607 | w--; | ||
| 608 | } | ||
| 609 | } | ||
| 610 | return(1); | ||
| 611 | } | ||
diff --git a/src/lib/libcrypto/bn/bn_mod.c b/src/lib/libcrypto/bn/bn_mod.c new file mode 100644 index 0000000000..c351aac14f --- /dev/null +++ b/src/lib/libcrypto/bn/bn_mod.c | |||
| @@ -0,0 +1,97 @@ | |||
| 1 | /* crypto/bn/bn_mod.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_lcl.h" | ||
| 62 | |||
| 63 | /* rem != m */ | ||
| 64 | int BN_mod(rem, m, d,ctx) | ||
| 65 | BIGNUM *rem; | ||
| 66 | BIGNUM *m; | ||
| 67 | BIGNUM *d; | ||
| 68 | BN_CTX *ctx; | ||
| 69 | { | ||
| 70 | #if 0 /* The old slow way */ | ||
| 71 | int i,nm,nd; | ||
| 72 | BIGNUM *dv; | ||
| 73 | |||
| 74 | if (BN_ucmp(m,d) < 0) | ||
| 75 | return((BN_copy(rem,m) == NULL)?0:1); | ||
| 76 | |||
| 77 | dv=ctx->bn[ctx->tos]; | ||
| 78 | |||
| 79 | if (!BN_copy(rem,m)) return(0); | ||
| 80 | |||
| 81 | nm=BN_num_bits(rem); | ||
| 82 | nd=BN_num_bits(d); | ||
| 83 | if (!BN_lshift(dv,d,nm-nd)) return(0); | ||
| 84 | for (i=nm-nd; i>=0; i--) | ||
| 85 | { | ||
| 86 | if (BN_cmp(rem,dv) >= 0) | ||
| 87 | { | ||
| 88 | if (!BN_sub(rem,rem,dv)) return(0); | ||
| 89 | } | ||
| 90 | if (!BN_rshift1(dv,dv)) return(0); | ||
| 91 | } | ||
| 92 | return(1); | ||
| 93 | #else | ||
| 94 | return(BN_div(NULL,rem,m,d,ctx)); | ||
| 95 | #endif | ||
| 96 | } | ||
| 97 | |||
diff --git a/src/lib/libcrypto/bn/bn_mont.c b/src/lib/libcrypto/bn/bn_mont.c new file mode 100644 index 0000000000..e435df61f8 --- /dev/null +++ b/src/lib/libcrypto/bn/bn_mont.c | |||
| @@ -0,0 +1,306 @@ | |||
| 1 | /* crypto/bn/bn_mont.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_lcl.h" | ||
| 62 | |||
| 63 | int BN_mod_mul_montgomery(r,a,b,mont,ctx) | ||
| 64 | BIGNUM *r,*a,*b; | ||
| 65 | BN_MONT_CTX *mont; | ||
| 66 | BN_CTX *ctx; | ||
| 67 | { | ||
| 68 | BIGNUM *tmp; | ||
| 69 | |||
| 70 | tmp=ctx->bn[ctx->tos++]; | ||
| 71 | |||
| 72 | if (a == b) | ||
| 73 | { | ||
| 74 | if (!BN_sqr(tmp,a,ctx)) goto err; | ||
| 75 | } | ||
| 76 | else | ||
| 77 | { | ||
| 78 | if (!BN_mul(tmp,a,b)) goto err; | ||
| 79 | } | ||
| 80 | /* reduce from aRR to aR */ | ||
| 81 | if (!BN_from_montgomery(r,tmp,mont,ctx)) goto err; | ||
| 82 | ctx->tos--; | ||
| 83 | return(1); | ||
| 84 | err: | ||
| 85 | return(0); | ||
| 86 | } | ||
| 87 | |||
| 88 | #define MONT_WORD | ||
| 89 | |||
| 90 | #ifdef MONT_WORD | ||
| 91 | int BN_from_montgomery(ret,a,mont,ctx) | ||
| 92 | BIGNUM *ret; | ||
| 93 | BIGNUM *a; | ||
| 94 | BN_MONT_CTX *mont; | ||
| 95 | BN_CTX *ctx; | ||
| 96 | { | ||
| 97 | BIGNUM *n,*t1,*r; | ||
| 98 | BN_ULONG *ap,*np,*rp,n0,v; | ||
| 99 | int al,nl,max,i,x,ri; | ||
| 100 | int retn=0; | ||
| 101 | |||
| 102 | t1=ctx->bn[ctx->tos]; | ||
| 103 | r=ctx->bn[ctx->tos+1]; | ||
| 104 | |||
| 105 | if (!BN_copy(r,a)) goto err; | ||
| 106 | n=mont->N; | ||
| 107 | |||
| 108 | ap=a->d; | ||
| 109 | /* mont->ri is the size of mont->N in bits/words */ | ||
| 110 | al=ri=mont->ri/BN_BITS2; | ||
| 111 | |||
| 112 | nl=n->top; | ||
| 113 | if ((al == 0) || (nl == 0)) { r->top=0; return(1); } | ||
| 114 | |||
| 115 | max=(nl+al+1); /* allow for overflow (no?) XXX */ | ||
| 116 | if (bn_wexpand(r,max) == NULL) goto err; | ||
| 117 | if (bn_wexpand(ret,max) == NULL) goto err; | ||
| 118 | |||
| 119 | r->neg=a->neg^n->neg; | ||
| 120 | np=n->d; | ||
| 121 | rp=r->d; | ||
| 122 | |||
| 123 | /* clear the top words of T */ | ||
| 124 | #if 1 | ||
| 125 | for (i=r->top; i<max; i++) /* memset? XXX */ | ||
| 126 | r->d[i]=0; | ||
| 127 | #else | ||
| 128 | memset(&(r->d[r->top]),0,(max-r->top)*sizeof(BN_ULONG)); | ||
| 129 | #endif | ||
| 130 | |||
| 131 | r->top=max; | ||
| 132 | n0=mont->n0; | ||
| 133 | |||
| 134 | for (i=0; i<nl; i++) | ||
| 135 | { | ||
| 136 | #if 0 | ||
| 137 | int x1,x2; | ||
| 138 | |||
| 139 | if (i+4 > nl) | ||
| 140 | { | ||
| 141 | x2=nl; | ||
| 142 | x1=0; | ||
| 143 | } | ||
| 144 | else | ||
| 145 | { | ||
| 146 | x2=i+4; | ||
| 147 | x1=nl-x2; | ||
| 148 | } | ||
| 149 | v=bn_mul_add_words(&(rp[x1]),&(np[x1]),x2,(rp[x1]*n0)&BN_MASK2); | ||
| 150 | #else | ||
| 151 | v=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2); | ||
| 152 | #endif | ||
| 153 | |||
| 154 | if (((rp[nl]+=v)&BN_MASK2) < v) | ||
| 155 | { | ||
| 156 | for (x=(nl+1); (((++rp[x])&BN_MASK2) == 0); x++) | ||
| 157 | ; | ||
| 158 | } | ||
| 159 | rp++; | ||
| 160 | } | ||
| 161 | while (r->d[r->top-1] == 0) | ||
| 162 | r->top--; | ||
| 163 | |||
| 164 | /* mont->ri will be a multiple of the word size */ | ||
| 165 | #if 0 | ||
| 166 | BN_rshift(ret,r,mont->ri); | ||
| 167 | #else | ||
| 168 | ap=r->d; | ||
| 169 | rp=ret->d; | ||
| 170 | x=ri; | ||
| 171 | al=r->top-x; | ||
| 172 | for (i=0; i<al; i++) | ||
| 173 | { | ||
| 174 | rp[i]=ap[i+x]; | ||
| 175 | } | ||
| 176 | ret->top=al; | ||
| 177 | #endif | ||
| 178 | |||
| 179 | if (BN_ucmp(ret,mont->N) >= 0) | ||
| 180 | { | ||
| 181 | bn_qsub(ret,ret,mont->N); /* XXX */ | ||
| 182 | } | ||
| 183 | retn=1; | ||
| 184 | err: | ||
| 185 | return(retn); | ||
| 186 | } | ||
| 187 | #else | ||
| 188 | int BN_from_montgomery(r,a,mont,ctx) | ||
| 189 | BIGNUM *r; | ||
| 190 | BIGNUM *a; | ||
| 191 | BN_MONT_CTX *mont; | ||
| 192 | BN_CTX *ctx; | ||
| 193 | { | ||
| 194 | BIGNUM *t1,*t2; | ||
| 195 | |||
| 196 | t1=ctx->bn[ctx->tos]; | ||
| 197 | t2=ctx->bn[ctx->tos+1]; | ||
| 198 | |||
| 199 | if (!BN_copy(t1,a)) goto err; | ||
| 200 | /* can cheat */ | ||
| 201 | BN_mask_bits(t1,mont->ri); | ||
| 202 | |||
| 203 | if (!BN_mul(t2,t1,mont->Ni)) goto err; | ||
| 204 | BN_mask_bits(t2,mont->ri); | ||
| 205 | |||
| 206 | if (!BN_mul(t1,t2,mont->N)) goto err; | ||
| 207 | if (!BN_add(t2,a,t1)) goto err; | ||
| 208 | BN_rshift(r,t2,mont->ri); | ||
| 209 | |||
| 210 | if (BN_ucmp(r,mont->N) >= 0) | ||
| 211 | bn_qsub(r,r,mont->N); | ||
| 212 | |||
| 213 | return(1); | ||
| 214 | err: | ||
| 215 | return(0); | ||
| 216 | } | ||
| 217 | #endif | ||
| 218 | |||
| 219 | BN_MONT_CTX *BN_MONT_CTX_new() | ||
| 220 | { | ||
| 221 | BN_MONT_CTX *ret; | ||
| 222 | |||
| 223 | if ((ret=(BN_MONT_CTX *)Malloc(sizeof(BN_MONT_CTX))) == NULL) | ||
| 224 | return(NULL); | ||
| 225 | ret->ri=0; | ||
| 226 | ret->RR=BN_new(); | ||
| 227 | ret->N=BN_new(); | ||
| 228 | ret->Ni=NULL; | ||
| 229 | if ((ret->RR == NULL) || (ret->N == NULL)) | ||
| 230 | { | ||
| 231 | BN_MONT_CTX_free(ret); | ||
| 232 | return(NULL); | ||
| 233 | } | ||
| 234 | return(ret); | ||
| 235 | } | ||
| 236 | |||
| 237 | void BN_MONT_CTX_free(mont) | ||
| 238 | BN_MONT_CTX *mont; | ||
| 239 | { | ||
| 240 | if (mont->RR != NULL) BN_free(mont->RR); | ||
| 241 | if (mont->N != NULL) BN_free(mont->N); | ||
| 242 | if (mont->Ni != NULL) BN_free(mont->Ni); | ||
| 243 | Free(mont); | ||
| 244 | } | ||
| 245 | |||
| 246 | int BN_MONT_CTX_set(mont,mod,ctx) | ||
| 247 | BN_MONT_CTX *mont; | ||
| 248 | BIGNUM *mod; | ||
| 249 | BN_CTX *ctx; | ||
| 250 | { | ||
| 251 | BIGNUM *Ri=NULL,*R=NULL; | ||
| 252 | |||
| 253 | if (mont->RR == NULL) mont->RR=BN_new(); | ||
| 254 | if (mont->N == NULL) mont->N=BN_new(); | ||
| 255 | |||
| 256 | R=mont->RR; /* grab RR as a temp */ | ||
| 257 | BN_copy(mont->N,mod); /* Set N */ | ||
| 258 | |||
| 259 | #ifdef MONT_WORD | ||
| 260 | { | ||
| 261 | BIGNUM tmod; | ||
| 262 | BN_ULONG buf[2]; | ||
| 263 | /* int z; */ | ||
| 264 | |||
| 265 | mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2; | ||
| 266 | BN_lshift(R,BN_value_one(),BN_BITS2); /* R */ | ||
| 267 | /* I was bad, this modification of a passed variable was | ||
| 268 | * breaking the multithreaded stuff :-( | ||
| 269 | * z=mod->top; | ||
| 270 | * mod->top=1; */ | ||
| 271 | |||
| 272 | buf[0]=mod->d[0]; | ||
| 273 | buf[1]=0; | ||
| 274 | tmod.d=buf; | ||
| 275 | tmod.top=1; | ||
| 276 | tmod.max=mod->max; | ||
| 277 | tmod.neg=mod->neg; | ||
| 278 | |||
| 279 | if ((Ri=BN_mod_inverse(R,&tmod,ctx)) == NULL) goto err; /* Ri */ | ||
| 280 | BN_lshift(Ri,Ri,BN_BITS2); /* R*Ri */ | ||
| 281 | bn_qsub(Ri,Ri,BN_value_one()); /* R*Ri - 1 */ | ||
| 282 | BN_div(Ri,NULL,Ri,&tmod,ctx); | ||
| 283 | mont->n0=Ri->d[0]; | ||
| 284 | BN_free(Ri); | ||
| 285 | /* mod->top=z; */ | ||
| 286 | } | ||
| 287 | #else | ||
| 288 | mont->ri=BN_num_bits(mod); | ||
| 289 | BN_lshift(R,BN_value_one(),mont->ri); /* R */ | ||
| 290 | if ((Ri=BN_mod_inverse(R,mod,ctx)) == NULL) goto err; /* Ri */ | ||
| 291 | BN_lshift(Ri,Ri,mont->ri); /* R*Ri */ | ||
| 292 | bn_qsub(Ri,Ri,BN_value_one()); /* R*Ri - 1 */ | ||
| 293 | BN_div(Ri,NULL,Ri,mod,ctx); | ||
| 294 | if (mont->Ni != NULL) BN_free(mont->Ni); | ||
| 295 | mont->Ni=Ri; /* Ni=(R*Ri-1)/N */ | ||
| 296 | #endif | ||
| 297 | |||
| 298 | /* setup RR for conversions */ | ||
| 299 | BN_lshift(mont->RR,BN_value_one(),mont->ri*2); | ||
| 300 | BN_mod(mont->RR,mont->RR,mont->N,ctx); | ||
| 301 | |||
| 302 | return(1); | ||
| 303 | err: | ||
| 304 | return(0); | ||
| 305 | } | ||
| 306 | |||
diff --git a/src/lib/libcrypto/bn/bn_mpi.c b/src/lib/libcrypto/bn/bn_mpi.c new file mode 100644 index 0000000000..53945c1057 --- /dev/null +++ b/src/lib/libcrypto/bn/bn_mpi.c | |||
| @@ -0,0 +1,134 @@ | |||
| 1 | /* crypto/bn/bn_mpi.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_lcl.h" | ||
| 62 | |||
| 63 | int BN_bn2mpi(a,d) | ||
| 64 | BIGNUM *a; | ||
| 65 | unsigned char *d; | ||
| 66 | { | ||
| 67 | int bits; | ||
| 68 | int num=0; | ||
| 69 | int ext=0; | ||
| 70 | long l; | ||
| 71 | |||
| 72 | bits=BN_num_bits(a); | ||
| 73 | num=(bits+7)/8; | ||
| 74 | if (bits > 0) | ||
| 75 | { | ||
| 76 | ext=((bits & 0x07) == 0); | ||
| 77 | } | ||
| 78 | if (d == NULL) | ||
| 79 | return(num+4+ext); | ||
| 80 | |||
| 81 | l=num+ext; | ||
| 82 | d[0]=(unsigned char)(l>>24)&0xff; | ||
| 83 | d[1]=(unsigned char)(l>>16)&0xff; | ||
| 84 | d[2]=(unsigned char)(l>> 8)&0xff; | ||
| 85 | d[3]=(unsigned char)(l )&0xff; | ||
| 86 | if (ext) d[4]=0; | ||
| 87 | num=BN_bn2bin(a,&(d[4+ext])); | ||
| 88 | if (a->neg) | ||
| 89 | d[4]|=0x80; | ||
| 90 | return(num+4+ext); | ||
| 91 | } | ||
| 92 | |||
| 93 | BIGNUM *BN_mpi2bn(d,n,a) | ||
| 94 | unsigned char *d; | ||
| 95 | int n; | ||
| 96 | BIGNUM *a; | ||
| 97 | { | ||
| 98 | long len; | ||
| 99 | int neg=0; | ||
| 100 | |||
| 101 | if (n < 4) | ||
| 102 | { | ||
| 103 | BNerr(BN_F_BN_MPI2BN,BN_R_INVALID_LENGTH); | ||
| 104 | return(NULL); | ||
| 105 | } | ||
| 106 | len=(d[0]<<24)|(d[1]<<16)|(d[2]<<8)|d[3]; | ||
| 107 | if ((len+4) != n) | ||
| 108 | { | ||
| 109 | BNerr(BN_F_BN_MPI2BN,BN_R_ENCODING_ERROR); | ||
| 110 | return(NULL); | ||
| 111 | } | ||
| 112 | |||
| 113 | if (a == NULL) a=BN_new(); | ||
| 114 | if (a == NULL) return(NULL); | ||
| 115 | |||
| 116 | if (len == 0) | ||
| 117 | { | ||
| 118 | a->neg=0; | ||
| 119 | a->top=0; | ||
| 120 | return(a); | ||
| 121 | } | ||
| 122 | d+=4; | ||
| 123 | if ((*d) & 0x80) | ||
| 124 | neg=1; | ||
| 125 | if (BN_bin2bn(d,(int)len,a) == NULL) | ||
| 126 | return(NULL); | ||
| 127 | a->neg=neg; | ||
| 128 | if (neg) | ||
| 129 | { | ||
| 130 | BN_clear_bit(a,BN_num_bits(a)-1); | ||
| 131 | } | ||
| 132 | return(a); | ||
| 133 | } | ||
| 134 | |||
diff --git a/src/lib/libcrypto/bn/bn_mul.c b/src/lib/libcrypto/bn/bn_mul.c new file mode 100644 index 0000000000..d0c04e1d4b --- /dev/null +++ b/src/lib/libcrypto/bn/bn_mul.c | |||
| @@ -0,0 +1,209 @@ | |||
| 1 | /* crypto/bn/bn_mul.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_lcl.h" | ||
| 62 | |||
| 63 | /* r must be different to a and b */ | ||
| 64 | /* int BN_mmul(r, a, b) */ | ||
| 65 | int BN_mul(r, a, b) | ||
| 66 | BIGNUM *r; | ||
| 67 | BIGNUM *a; | ||
| 68 | BIGNUM *b; | ||
| 69 | { | ||
| 70 | int i; | ||
| 71 | int max,al,bl; | ||
| 72 | BN_ULONG *ap,*bp,*rp; | ||
| 73 | |||
| 74 | al=a->top; | ||
| 75 | bl=b->top; | ||
| 76 | if ((al == 0) || (bl == 0)) | ||
| 77 | { | ||
| 78 | r->top=0; | ||
| 79 | return(1); | ||
| 80 | } | ||
| 81 | |||
| 82 | max=(al+bl); | ||
| 83 | if (bn_wexpand(r,max) == NULL) return(0); | ||
| 84 | r->top=max; | ||
| 85 | r->neg=a->neg^b->neg; | ||
| 86 | ap=a->d; | ||
| 87 | bp=b->d; | ||
| 88 | rp=r->d; | ||
| 89 | |||
| 90 | rp[al]=bn_mul_words(rp,ap,al,*(bp++)); | ||
| 91 | rp++; | ||
| 92 | for (i=1; i<bl; i++) | ||
| 93 | { | ||
| 94 | rp[al]=bn_mul_add_words(rp,ap,al,*(bp++)); | ||
| 95 | rp++; | ||
| 96 | } | ||
| 97 | if (r->d[max-1] == 0) r->top--; | ||
| 98 | return(1); | ||
| 99 | } | ||
| 100 | |||
| 101 | #if 0 | ||
| 102 | #include "stack.h" | ||
| 103 | |||
| 104 | int limit=16; | ||
| 105 | |||
| 106 | typedef struct bn_pool_st | ||
| 107 | { | ||
| 108 | int used; | ||
| 109 | int tos; | ||
| 110 | STACK *sk; | ||
| 111 | } BN_POOL; | ||
| 112 | |||
| 113 | BIGNUM *BN_POOL_push(bp) | ||
| 114 | BN_POOL *bp; | ||
| 115 | { | ||
| 116 | BIGNUM *ret; | ||
| 117 | |||
| 118 | if (bp->used >= bp->tos) | ||
| 119 | { | ||
| 120 | ret=BN_new(); | ||
| 121 | sk_push(bp->sk,(char *)ret); | ||
| 122 | bp->tos++; | ||
| 123 | bp->used++; | ||
| 124 | } | ||
| 125 | else | ||
| 126 | { | ||
| 127 | ret=(BIGNUM *)sk_value(bp->sk,bp->used); | ||
| 128 | bp->used++; | ||
| 129 | } | ||
| 130 | return(ret); | ||
| 131 | } | ||
| 132 | |||
| 133 | void BN_POOL_pop(bp,num) | ||
| 134 | BN_POOL *bp; | ||
| 135 | int num; | ||
| 136 | { | ||
| 137 | bp->used-=num; | ||
| 138 | } | ||
| 139 | |||
| 140 | int BN_mul(r,a,b) | ||
| 141 | BIGNUM *r,*a,*b; | ||
| 142 | { | ||
| 143 | static BN_POOL bp; | ||
| 144 | static init=1; | ||
| 145 | |||
| 146 | if (init) | ||
| 147 | { | ||
| 148 | bp.used=0; | ||
| 149 | bp.tos=0; | ||
| 150 | bp.sk=sk_new_null(); | ||
| 151 | init=0; | ||
| 152 | } | ||
| 153 | return(BN_mm(r,a,b,&bp)); | ||
| 154 | } | ||
| 155 | |||
| 156 | /* r must be different to a and b */ | ||
| 157 | int BN_mm(m, A, B, bp) | ||
| 158 | BIGNUM *m,*A,*B; | ||
| 159 | BN_POOL *bp; | ||
| 160 | { | ||
| 161 | int i,num; | ||
| 162 | int an,bn; | ||
| 163 | BIGNUM *a,*b,*c,*d,*ac,*bd; | ||
| 164 | |||
| 165 | an=A->top; | ||
| 166 | bn=B->top; | ||
| 167 | if ((an <= limit) || (bn <= limit)) | ||
| 168 | { | ||
| 169 | return(BN_mmul(m,A,B)); | ||
| 170 | } | ||
| 171 | |||
| 172 | a=BN_POOL_push(bp); | ||
| 173 | b=BN_POOL_push(bp); | ||
| 174 | c=BN_POOL_push(bp); | ||
| 175 | d=BN_POOL_push(bp); | ||
| 176 | ac=BN_POOL_push(bp); | ||
| 177 | bd=BN_POOL_push(bp); | ||
| 178 | |||
| 179 | num=(an <= bn)?an:bn; | ||
| 180 | num=1<<(BN_num_bits_word(num-1)-1); | ||
| 181 | |||
| 182 | /* Are going to now chop things into 'num' word chunks. */ | ||
| 183 | num*=BN_BITS2; | ||
| 184 | |||
| 185 | BN_copy(a,A); | ||
| 186 | BN_mask_bits(a,num); | ||
| 187 | BN_rshift(b,A,num); | ||
| 188 | |||
| 189 | BN_copy(c,B); | ||
| 190 | BN_mask_bits(c,num); | ||
| 191 | BN_rshift(d,B,num); | ||
| 192 | |||
| 193 | BN_sub(ac ,b,a); | ||
| 194 | BN_sub(bd,c,d); | ||
| 195 | BN_mm(m,ac,bd,bp); | ||
| 196 | BN_mm(ac,a,c,bp); | ||
| 197 | BN_mm(bd,b,d,bp); | ||
| 198 | |||
| 199 | BN_add(m,m,ac); | ||
| 200 | BN_add(m,m,bd); | ||
| 201 | BN_lshift(m,m,num); | ||
| 202 | BN_lshift(bd,bd,num*2); | ||
| 203 | |||
| 204 | BN_add(m,m,ac); | ||
| 205 | BN_add(m,m,bd); | ||
| 206 | BN_POOL_pop(bp,6); | ||
| 207 | return(1); | ||
| 208 | } | ||
| 209 | #endif | ||
diff --git a/src/lib/libcrypto/bn/bn_prime.c b/src/lib/libcrypto/bn/bn_prime.c new file mode 100644 index 0000000000..0c85f70b59 --- /dev/null +++ b/src/lib/libcrypto/bn/bn_prime.c | |||
| @@ -0,0 +1,473 @@ | |||
| 1 | /* crypto/bn/bn_prime.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 <time.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "bn_lcl.h" | ||
| 63 | #include "rand.h" | ||
| 64 | |||
| 65 | /* The quick seive algorithm approach to weeding out primes is | ||
| 66 | * Philip Zimmermann's, as implemented in PGP. I have had a read of | ||
| 67 | * his comments and implemented my own version. | ||
| 68 | */ | ||
| 69 | #include "bn_prime.h" | ||
| 70 | |||
| 71 | #ifndef NOPROTO | ||
| 72 | static int witness(BIGNUM *a, BIGNUM *n, BN_CTX *ctx,BN_CTX *ctx2, | ||
| 73 | BN_MONT_CTX *mont); | ||
| 74 | static int probable_prime(BIGNUM *rnd, int bits); | ||
| 75 | static int probable_prime_dh(BIGNUM *rnd, int bits, | ||
| 76 | BIGNUM *add, BIGNUM *rem, BN_CTX *ctx); | ||
| 77 | static int probable_prime_dh_strong(BIGNUM *rnd, int bits, | ||
| 78 | BIGNUM *add, BIGNUM *rem, BN_CTX *ctx); | ||
| 79 | #else | ||
| 80 | static int witness(); | ||
| 81 | static int probable_prime(); | ||
| 82 | static int probable_prime_dh(); | ||
| 83 | static int probable_prime_dh_strong(); | ||
| 84 | #endif | ||
| 85 | |||
| 86 | BIGNUM *BN_generate_prime(bits,strong,add,rem,callback,cb_arg) | ||
| 87 | int bits; | ||
| 88 | int strong; | ||
| 89 | BIGNUM *add; | ||
| 90 | BIGNUM *rem; | ||
| 91 | void (*callback)(P_I_I_P); | ||
| 92 | char *cb_arg; | ||
| 93 | { | ||
| 94 | BIGNUM *rnd=NULL; | ||
| 95 | BIGNUM *ret=NULL; | ||
| 96 | BIGNUM *t=NULL; | ||
| 97 | int i,j,c1=0; | ||
| 98 | BN_CTX *ctx; | ||
| 99 | |||
| 100 | ctx=BN_CTX_new(); | ||
| 101 | if (ctx == NULL) goto err; | ||
| 102 | if ((rnd=BN_new()) == NULL) goto err; | ||
| 103 | if (strong) | ||
| 104 | if ((t=BN_new()) == NULL) goto err; | ||
| 105 | loop: | ||
| 106 | /* make a random number and set the top and bottom bits */ | ||
| 107 | if (add == NULL) | ||
| 108 | { | ||
| 109 | if (!probable_prime(rnd,bits)) goto err; | ||
| 110 | } | ||
| 111 | else | ||
| 112 | { | ||
| 113 | if (strong) | ||
| 114 | { | ||
| 115 | if (!probable_prime_dh_strong(rnd,bits,add,rem,ctx)) | ||
| 116 | goto err; | ||
| 117 | } | ||
| 118 | else | ||
| 119 | { | ||
| 120 | if (!probable_prime_dh(rnd,bits,add,rem,ctx)) | ||
| 121 | goto err; | ||
| 122 | } | ||
| 123 | } | ||
| 124 | /* if (BN_mod_word(rnd,(BN_ULONG)3) == 1) goto loop; */ | ||
| 125 | if (callback != NULL) callback(0,c1++,cb_arg); | ||
| 126 | |||
| 127 | if (!strong) | ||
| 128 | { | ||
| 129 | i=BN_is_prime(rnd,BN_prime_checks,callback,ctx,cb_arg); | ||
| 130 | if (i == -1) goto err; | ||
| 131 | if (i == 0) goto loop; | ||
| 132 | } | ||
| 133 | else | ||
| 134 | { | ||
| 135 | /* for a strong prime generation, | ||
| 136 | * check that (p-1)/2 is prime. | ||
| 137 | * Since a prime is odd, We just | ||
| 138 | * need to divide by 2 */ | ||
| 139 | if (!BN_rshift1(t,rnd)) goto err; | ||
| 140 | |||
| 141 | for (i=0; i<BN_prime_checks; i++) | ||
| 142 | { | ||
| 143 | j=BN_is_prime(rnd,1,callback,ctx,cb_arg); | ||
| 144 | if (j == -1) goto err; | ||
| 145 | if (j == 0) goto loop; | ||
| 146 | |||
| 147 | j=BN_is_prime(t,1,callback,ctx,cb_arg); | ||
| 148 | if (j == -1) goto err; | ||
| 149 | if (j == 0) goto loop; | ||
| 150 | |||
| 151 | if (callback != NULL) callback(2,c1-1,cb_arg); | ||
| 152 | /* We have a strong prime test pass */ | ||
| 153 | } | ||
| 154 | } | ||
| 155 | /* we have a prime :-) */ | ||
| 156 | ret=rnd; | ||
| 157 | err: | ||
| 158 | if ((ret == NULL) && (rnd != NULL)) BN_free(rnd); | ||
| 159 | if (t != NULL) BN_free(t); | ||
| 160 | if (ctx != NULL) BN_CTX_free(ctx); | ||
| 161 | return(ret); | ||
| 162 | } | ||
| 163 | |||
| 164 | int BN_is_prime(a,checks,callback,ctx_passed,cb_arg) | ||
| 165 | BIGNUM *a; | ||
| 166 | int checks; | ||
| 167 | void (*callback)(P_I_I_P); | ||
| 168 | BN_CTX *ctx_passed; | ||
| 169 | char *cb_arg; | ||
| 170 | { | ||
| 171 | int i,j,c2=0,ret= -1; | ||
| 172 | BIGNUM *check; | ||
| 173 | BN_CTX *ctx=NULL,*ctx2=NULL; | ||
| 174 | BN_MONT_CTX *mont=NULL; | ||
| 175 | |||
| 176 | if (!BN_is_odd(a)) | ||
| 177 | return(0); | ||
| 178 | if (ctx_passed != NULL) | ||
| 179 | ctx=ctx_passed; | ||
| 180 | else | ||
| 181 | if ((ctx=BN_CTX_new()) == NULL) goto err; | ||
| 182 | |||
| 183 | if ((ctx2=BN_CTX_new()) == NULL) goto err; | ||
| 184 | if ((mont=BN_MONT_CTX_new()) == NULL) goto err; | ||
| 185 | |||
| 186 | check=ctx->bn[ctx->tos++]; | ||
| 187 | |||
| 188 | /* Setup the montgomery structure */ | ||
| 189 | if (!BN_MONT_CTX_set(mont,a,ctx2)) goto err; | ||
| 190 | |||
| 191 | for (i=0; i<checks; i++) | ||
| 192 | { | ||
| 193 | if (!BN_rand(check,BN_num_bits(a)-1,0,0)) goto err; | ||
| 194 | j=witness(check,a,ctx,ctx2,mont); | ||
| 195 | if (j == -1) goto err; | ||
| 196 | if (j) | ||
| 197 | { | ||
| 198 | ret=0; | ||
| 199 | goto err; | ||
| 200 | } | ||
| 201 | if (callback != NULL) callback(1,c2++,cb_arg); | ||
| 202 | } | ||
| 203 | ret=1; | ||
| 204 | err: | ||
| 205 | ctx->tos--; | ||
| 206 | if ((ctx_passed == NULL) && (ctx != NULL)) | ||
| 207 | BN_CTX_free(ctx); | ||
| 208 | if (ctx2 != NULL) | ||
| 209 | BN_CTX_free(ctx2); | ||
| 210 | if (mont != NULL) BN_MONT_CTX_free(mont); | ||
| 211 | |||
| 212 | return(ret); | ||
| 213 | } | ||
| 214 | |||
| 215 | #define RECP_MUL_MOD | ||
| 216 | |||
| 217 | static int witness(a,n,ctx,ctx2,mont) | ||
| 218 | BIGNUM *a; | ||
| 219 | BIGNUM *n; | ||
| 220 | BN_CTX *ctx,*ctx2; | ||
| 221 | BN_MONT_CTX *mont; | ||
| 222 | { | ||
| 223 | int k,i,ret= -1,good; | ||
| 224 | BIGNUM *d,*dd,*tmp,*d1,*d2,*n1; | ||
| 225 | BIGNUM *mont_one,*mont_n1,*mont_a; | ||
| 226 | |||
| 227 | d1=ctx->bn[ctx->tos]; | ||
| 228 | d2=ctx->bn[ctx->tos+1]; | ||
| 229 | n1=ctx->bn[ctx->tos+2]; | ||
| 230 | ctx->tos+=3; | ||
| 231 | |||
| 232 | mont_one=ctx2->bn[ctx2->tos]; | ||
| 233 | mont_n1=ctx2->bn[ctx2->tos+1]; | ||
| 234 | mont_a=ctx2->bn[ctx2->tos+2]; | ||
| 235 | ctx2->tos+=3; | ||
| 236 | |||
| 237 | d=d1; | ||
| 238 | dd=d2; | ||
| 239 | if (!BN_one(d)) goto err; | ||
| 240 | if (!BN_sub(n1,n,d)) goto err; /* n1=n-1; */ | ||
| 241 | k=BN_num_bits(n1); | ||
| 242 | |||
| 243 | if (!BN_to_montgomery(mont_one,BN_value_one(),mont,ctx2)) goto err; | ||
| 244 | if (!BN_to_montgomery(mont_n1,n1,mont,ctx2)) goto err; | ||
| 245 | if (!BN_to_montgomery(mont_a,a,mont,ctx2)) goto err; | ||
| 246 | |||
| 247 | BN_copy(d,mont_one); | ||
| 248 | for (i=k-1; i>=0; i--) | ||
| 249 | { | ||
| 250 | if ( (BN_cmp(d,mont_one) != 0) && | ||
| 251 | (BN_cmp(d,mont_n1) != 0)) | ||
| 252 | good=1; | ||
| 253 | else | ||
| 254 | good=0; | ||
| 255 | |||
| 256 | BN_mod_mul_montgomery(dd,d,d,mont,ctx2); | ||
| 257 | |||
| 258 | if (good && (BN_cmp(dd,mont_one) == 0)) | ||
| 259 | { | ||
| 260 | ret=1; | ||
| 261 | goto err; | ||
| 262 | } | ||
| 263 | if (BN_is_bit_set(n1,i)) | ||
| 264 | { | ||
| 265 | BN_mod_mul_montgomery(d,dd,mont_a,mont,ctx2); | ||
| 266 | } | ||
| 267 | else | ||
| 268 | { | ||
| 269 | tmp=d; | ||
| 270 | d=dd; | ||
| 271 | dd=tmp; | ||
| 272 | } | ||
| 273 | } | ||
| 274 | if (BN_cmp(d,mont_one) == 0) | ||
| 275 | i=0; | ||
| 276 | else i=1; | ||
| 277 | ret=i; | ||
| 278 | err: | ||
| 279 | ctx->tos-=3; | ||
| 280 | ctx2->tos-=3; | ||
| 281 | return(ret); | ||
| 282 | } | ||
| 283 | |||
| 284 | static int probable_prime(rnd, bits) | ||
| 285 | BIGNUM *rnd; | ||
| 286 | int bits; | ||
| 287 | { | ||
| 288 | int i; | ||
| 289 | MS_STATIC BN_ULONG mods[NUMPRIMES]; | ||
| 290 | BN_ULONG delta; | ||
| 291 | |||
| 292 | if (!BN_rand(rnd,bits,1,1)) return(0); | ||
| 293 | /* we now have a random number 'rand' to test. */ | ||
| 294 | for (i=1; i<NUMPRIMES; i++) | ||
| 295 | mods[i]=BN_mod_word(rnd,(BN_ULONG)primes[i]); | ||
| 296 | delta=0; | ||
| 297 | loop: for (i=1; i<NUMPRIMES; i++) | ||
| 298 | { | ||
| 299 | /* check that rnd is not a prime and also | ||
| 300 | * that gcd(rnd-1,primes) == 1 (except for 2) */ | ||
| 301 | if (((mods[i]+delta)%primes[i]) <= 1) | ||
| 302 | { | ||
| 303 | delta+=2; | ||
| 304 | /* perhaps need to check for overflow of | ||
| 305 | * delta (but delta can be upto 2^32) */ | ||
| 306 | goto loop; | ||
| 307 | } | ||
| 308 | } | ||
| 309 | if (!BN_add_word(rnd,delta)) return(0); | ||
| 310 | return(1); | ||
| 311 | } | ||
| 312 | |||
| 313 | static int probable_prime_dh(rnd, bits, add, rem,ctx) | ||
| 314 | BIGNUM *rnd; | ||
| 315 | int bits; | ||
| 316 | BIGNUM *add; | ||
| 317 | BIGNUM *rem; | ||
| 318 | BN_CTX *ctx; | ||
| 319 | { | ||
| 320 | int i,ret=0; | ||
| 321 | BIGNUM *t1; | ||
| 322 | |||
| 323 | t1=ctx->bn[ctx->tos++]; | ||
| 324 | |||
| 325 | if (!BN_rand(rnd,bits,0,1)) goto err; | ||
| 326 | |||
| 327 | /* we need ((rnd-rem) % add) == 0 */ | ||
| 328 | |||
| 329 | if (!BN_mod(t1,rnd,add,ctx)) goto err; | ||
| 330 | if (!BN_sub(rnd,rnd,t1)) goto err; | ||
| 331 | if (rem == NULL) | ||
| 332 | { if (!BN_add_word(rnd,1)) goto err; } | ||
| 333 | else | ||
| 334 | { if (!BN_add(rnd,rnd,rem)) goto err; } | ||
| 335 | |||
| 336 | /* we now have a random number 'rand' to test. */ | ||
| 337 | |||
| 338 | loop: for (i=1; i<NUMPRIMES; i++) | ||
| 339 | { | ||
| 340 | /* check that rnd is a prime */ | ||
| 341 | if (BN_mod_word(rnd,(BN_LONG)primes[i]) <= 1) | ||
| 342 | { | ||
| 343 | if (!BN_add(rnd,rnd,add)) goto err; | ||
| 344 | goto loop; | ||
| 345 | } | ||
| 346 | } | ||
| 347 | ret=1; | ||
| 348 | err: | ||
| 349 | ctx->tos--; | ||
| 350 | return(ret); | ||
| 351 | } | ||
| 352 | |||
| 353 | static int probable_prime_dh_strong(p, bits, padd, rem,ctx) | ||
| 354 | BIGNUM *p; | ||
| 355 | int bits; | ||
| 356 | BIGNUM *padd; | ||
| 357 | BIGNUM *rem; | ||
| 358 | BN_CTX *ctx; | ||
| 359 | { | ||
| 360 | int i,ret=0; | ||
| 361 | BIGNUM *t1,*qadd=NULL,*q=NULL; | ||
| 362 | |||
| 363 | bits--; | ||
| 364 | t1=ctx->bn[ctx->tos++]; | ||
| 365 | q=ctx->bn[ctx->tos++]; | ||
| 366 | qadd=ctx->bn[ctx->tos++]; | ||
| 367 | |||
| 368 | if (!BN_rshift1(qadd,padd)) goto err; | ||
| 369 | |||
| 370 | if (!BN_rand(q,bits,0,1)) goto err; | ||
| 371 | |||
| 372 | /* we need ((rnd-rem) % add) == 0 */ | ||
| 373 | if (!BN_mod(t1,q,qadd,ctx)) goto err; | ||
| 374 | if (!BN_sub(q,q,t1)) goto err; | ||
| 375 | if (rem == NULL) | ||
| 376 | { if (!BN_add_word(q,1)) goto err; } | ||
| 377 | else | ||
| 378 | { | ||
| 379 | if (!BN_rshift1(t1,rem)) goto err; | ||
| 380 | if (!BN_add(q,q,t1)) goto err; | ||
| 381 | } | ||
| 382 | |||
| 383 | /* we now have a random number 'rand' to test. */ | ||
| 384 | if (!BN_lshift1(p,q)) goto err; | ||
| 385 | if (!BN_add_word(p,1)) goto err; | ||
| 386 | |||
| 387 | loop: for (i=1; i<NUMPRIMES; i++) | ||
| 388 | { | ||
| 389 | /* check that p and q are prime */ | ||
| 390 | /* check that for p and q | ||
| 391 | * gcd(p-1,primes) == 1 (except for 2) */ | ||
| 392 | if ( (BN_mod_word(p,(BN_LONG)primes[i]) == 0) || | ||
| 393 | (BN_mod_word(q,(BN_LONG)primes[i]) == 0)) | ||
| 394 | { | ||
| 395 | if (!BN_add(p,p,padd)) goto err; | ||
| 396 | if (!BN_add(q,q,qadd)) goto err; | ||
| 397 | goto loop; | ||
| 398 | } | ||
| 399 | } | ||
| 400 | ret=1; | ||
| 401 | err: | ||
| 402 | ctx->tos-=3; | ||
| 403 | return(ret); | ||
| 404 | } | ||
| 405 | |||
| 406 | #if 0 | ||
| 407 | static int witness(a, n,ctx) | ||
| 408 | BIGNUM *a; | ||
| 409 | BIGNUM *n; | ||
| 410 | BN_CTX *ctx; | ||
| 411 | { | ||
| 412 | int k,i,nb,ret= -1; | ||
| 413 | BIGNUM *d,*dd,*tmp; | ||
| 414 | BIGNUM *d1,*d2,*x,*n1,*inv; | ||
| 415 | |||
| 416 | d1=ctx->bn[ctx->tos]; | ||
| 417 | d2=ctx->bn[ctx->tos+1]; | ||
| 418 | x=ctx->bn[ctx->tos+2]; | ||
| 419 | n1=ctx->bn[ctx->tos+3]; | ||
| 420 | inv=ctx->bn[ctx->tos+4]; | ||
| 421 | ctx->tos+=5; | ||
| 422 | |||
| 423 | d=d1; | ||
| 424 | dd=d2; | ||
| 425 | if (!BN_one(d)) goto err; | ||
| 426 | if (!BN_sub(n1,n,d)) goto err; /* n1=n-1; */ | ||
| 427 | k=BN_num_bits(n1); | ||
| 428 | |||
| 429 | /* i=BN_num_bits(n); */ | ||
| 430 | #ifdef RECP_MUL_MOD | ||
| 431 | nb=BN_reciprocal(inv,n,ctx); /**/ | ||
| 432 | if (nb == -1) goto err; | ||
| 433 | #endif | ||
| 434 | |||
| 435 | for (i=k-1; i>=0; i--) | ||
| 436 | { | ||
| 437 | if (BN_copy(x,d) == NULL) goto err; | ||
| 438 | #ifndef RECP_MUL_MOD | ||
| 439 | if (!BN_mod_mul(dd,d,d,n,ctx)) goto err; | ||
| 440 | #else | ||
| 441 | if (!BN_mod_mul_reciprocal(dd,d,d,n,inv,nb,ctx)) goto err; | ||
| 442 | #endif | ||
| 443 | if ( BN_is_one(dd) && | ||
| 444 | !BN_is_one(x) && | ||
| 445 | (BN_cmp(x,n1) != 0)) | ||
| 446 | { | ||
| 447 | ret=1; | ||
| 448 | goto err; | ||
| 449 | } | ||
| 450 | if (BN_is_bit_set(n1,i)) | ||
| 451 | { | ||
| 452 | #ifndef RECP_MUL_MOD | ||
| 453 | if (!BN_mod_mul(d,dd,a,n,ctx)) goto err; | ||
| 454 | #else | ||
| 455 | if (!BN_mod_mul_reciprocal(d,dd,a,n,inv,nb,ctx)) goto err; | ||
| 456 | #endif | ||
| 457 | } | ||
| 458 | else | ||
| 459 | { | ||
| 460 | tmp=d; | ||
| 461 | d=dd; | ||
| 462 | dd=tmp; | ||
| 463 | } | ||
| 464 | } | ||
| 465 | if (BN_is_one(d)) | ||
| 466 | i=0; | ||
| 467 | else i=1; | ||
| 468 | ret=i; | ||
| 469 | err: | ||
| 470 | ctx->tos-=5; | ||
| 471 | return(ret); | ||
| 472 | } | ||
| 473 | #endif | ||
diff --git a/src/lib/libcrypto/bn/bn_prime.h b/src/lib/libcrypto/bn/bn_prime.h new file mode 100644 index 0000000000..6fce0210cd --- /dev/null +++ b/src/lib/libcrypto/bn/bn_prime.h | |||
| @@ -0,0 +1,325 @@ | |||
| 1 | /* crypto/bn/bn_prime.h */ | ||
| 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 | #ifndef EIGHT_BIT | ||
| 60 | #define NUMPRIMES 2048 | ||
| 61 | #else | ||
| 62 | #define NUMPRIMES 54 | ||
| 63 | #endif | ||
| 64 | static unsigned int primes[NUMPRIMES]= | ||
| 65 | { | ||
| 66 | 2, 3, 5, 7, 11, 13, 17, 19, | ||
| 67 | 23, 29, 31, 37, 41, 43, 47, 53, | ||
| 68 | 59, 61, 67, 71, 73, 79, 83, 89, | ||
| 69 | 97, 101, 103, 107, 109, 113, 127, 131, | ||
| 70 | 137, 139, 149, 151, 157, 163, 167, 173, | ||
| 71 | 179, 181, 191, 193, 197, 199, 211, 223, | ||
| 72 | 227, 229, 233, 239, 241, 251, | ||
| 73 | #ifndef EIGHT_BIT | ||
| 74 | 257, 263, | ||
| 75 | 269, 271, 277, 281, 283, 293, 307, 311, | ||
| 76 | 313, 317, 331, 337, 347, 349, 353, 359, | ||
| 77 | 367, 373, 379, 383, 389, 397, 401, 409, | ||
| 78 | 419, 421, 431, 433, 439, 443, 449, 457, | ||
| 79 | 461, 463, 467, 479, 487, 491, 499, 503, | ||
| 80 | 509, 521, 523, 541, 547, 557, 563, 569, | ||
| 81 | 571, 577, 587, 593, 599, 601, 607, 613, | ||
| 82 | 617, 619, 631, 641, 643, 647, 653, 659, | ||
| 83 | 661, 673, 677, 683, 691, 701, 709, 719, | ||
| 84 | 727, 733, 739, 743, 751, 757, 761, 769, | ||
| 85 | 773, 787, 797, 809, 811, 821, 823, 827, | ||
| 86 | 829, 839, 853, 857, 859, 863, 877, 881, | ||
| 87 | 883, 887, 907, 911, 919, 929, 937, 941, | ||
| 88 | 947, 953, 967, 971, 977, 983, 991, 997, | ||
| 89 | 1009,1013,1019,1021,1031,1033,1039,1049, | ||
| 90 | 1051,1061,1063,1069,1087,1091,1093,1097, | ||
| 91 | 1103,1109,1117,1123,1129,1151,1153,1163, | ||
| 92 | 1171,1181,1187,1193,1201,1213,1217,1223, | ||
| 93 | 1229,1231,1237,1249,1259,1277,1279,1283, | ||
| 94 | 1289,1291,1297,1301,1303,1307,1319,1321, | ||
| 95 | 1327,1361,1367,1373,1381,1399,1409,1423, | ||
| 96 | 1427,1429,1433,1439,1447,1451,1453,1459, | ||
| 97 | 1471,1481,1483,1487,1489,1493,1499,1511, | ||
| 98 | 1523,1531,1543,1549,1553,1559,1567,1571, | ||
| 99 | 1579,1583,1597,1601,1607,1609,1613,1619, | ||
| 100 | 1621,1627,1637,1657,1663,1667,1669,1693, | ||
| 101 | 1697,1699,1709,1721,1723,1733,1741,1747, | ||
| 102 | 1753,1759,1777,1783,1787,1789,1801,1811, | ||
| 103 | 1823,1831,1847,1861,1867,1871,1873,1877, | ||
| 104 | 1879,1889,1901,1907,1913,1931,1933,1949, | ||
| 105 | 1951,1973,1979,1987,1993,1997,1999,2003, | ||
| 106 | 2011,2017,2027,2029,2039,2053,2063,2069, | ||
| 107 | 2081,2083,2087,2089,2099,2111,2113,2129, | ||
| 108 | 2131,2137,2141,2143,2153,2161,2179,2203, | ||
| 109 | 2207,2213,2221,2237,2239,2243,2251,2267, | ||
| 110 | 2269,2273,2281,2287,2293,2297,2309,2311, | ||
| 111 | 2333,2339,2341,2347,2351,2357,2371,2377, | ||
| 112 | 2381,2383,2389,2393,2399,2411,2417,2423, | ||
| 113 | 2437,2441,2447,2459,2467,2473,2477,2503, | ||
| 114 | 2521,2531,2539,2543,2549,2551,2557,2579, | ||
| 115 | 2591,2593,2609,2617,2621,2633,2647,2657, | ||
| 116 | 2659,2663,2671,2677,2683,2687,2689,2693, | ||
| 117 | 2699,2707,2711,2713,2719,2729,2731,2741, | ||
| 118 | 2749,2753,2767,2777,2789,2791,2797,2801, | ||
| 119 | 2803,2819,2833,2837,2843,2851,2857,2861, | ||
| 120 | 2879,2887,2897,2903,2909,2917,2927,2939, | ||
| 121 | 2953,2957,2963,2969,2971,2999,3001,3011, | ||
| 122 | 3019,3023,3037,3041,3049,3061,3067,3079, | ||
| 123 | 3083,3089,3109,3119,3121,3137,3163,3167, | ||
| 124 | 3169,3181,3187,3191,3203,3209,3217,3221, | ||
| 125 | 3229,3251,3253,3257,3259,3271,3299,3301, | ||
| 126 | 3307,3313,3319,3323,3329,3331,3343,3347, | ||
| 127 | 3359,3361,3371,3373,3389,3391,3407,3413, | ||
| 128 | 3433,3449,3457,3461,3463,3467,3469,3491, | ||
| 129 | 3499,3511,3517,3527,3529,3533,3539,3541, | ||
| 130 | 3547,3557,3559,3571,3581,3583,3593,3607, | ||
| 131 | 3613,3617,3623,3631,3637,3643,3659,3671, | ||
| 132 | 3673,3677,3691,3697,3701,3709,3719,3727, | ||
| 133 | 3733,3739,3761,3767,3769,3779,3793,3797, | ||
| 134 | 3803,3821,3823,3833,3847,3851,3853,3863, | ||
| 135 | 3877,3881,3889,3907,3911,3917,3919,3923, | ||
| 136 | 3929,3931,3943,3947,3967,3989,4001,4003, | ||
| 137 | 4007,4013,4019,4021,4027,4049,4051,4057, | ||
| 138 | 4073,4079,4091,4093,4099,4111,4127,4129, | ||
| 139 | 4133,4139,4153,4157,4159,4177,4201,4211, | ||
| 140 | 4217,4219,4229,4231,4241,4243,4253,4259, | ||
| 141 | 4261,4271,4273,4283,4289,4297,4327,4337, | ||
| 142 | 4339,4349,4357,4363,4373,4391,4397,4409, | ||
| 143 | 4421,4423,4441,4447,4451,4457,4463,4481, | ||
| 144 | 4483,4493,4507,4513,4517,4519,4523,4547, | ||
| 145 | 4549,4561,4567,4583,4591,4597,4603,4621, | ||
| 146 | 4637,4639,4643,4649,4651,4657,4663,4673, | ||
| 147 | 4679,4691,4703,4721,4723,4729,4733,4751, | ||
| 148 | 4759,4783,4787,4789,4793,4799,4801,4813, | ||
| 149 | 4817,4831,4861,4871,4877,4889,4903,4909, | ||
| 150 | 4919,4931,4933,4937,4943,4951,4957,4967, | ||
| 151 | 4969,4973,4987,4993,4999,5003,5009,5011, | ||
| 152 | 5021,5023,5039,5051,5059,5077,5081,5087, | ||
| 153 | 5099,5101,5107,5113,5119,5147,5153,5167, | ||
| 154 | 5171,5179,5189,5197,5209,5227,5231,5233, | ||
| 155 | 5237,5261,5273,5279,5281,5297,5303,5309, | ||
| 156 | 5323,5333,5347,5351,5381,5387,5393,5399, | ||
| 157 | 5407,5413,5417,5419,5431,5437,5441,5443, | ||
| 158 | 5449,5471,5477,5479,5483,5501,5503,5507, | ||
| 159 | 5519,5521,5527,5531,5557,5563,5569,5573, | ||
| 160 | 5581,5591,5623,5639,5641,5647,5651,5653, | ||
| 161 | 5657,5659,5669,5683,5689,5693,5701,5711, | ||
| 162 | 5717,5737,5741,5743,5749,5779,5783,5791, | ||
| 163 | 5801,5807,5813,5821,5827,5839,5843,5849, | ||
| 164 | 5851,5857,5861,5867,5869,5879,5881,5897, | ||
| 165 | 5903,5923,5927,5939,5953,5981,5987,6007, | ||
| 166 | 6011,6029,6037,6043,6047,6053,6067,6073, | ||
| 167 | 6079,6089,6091,6101,6113,6121,6131,6133, | ||
| 168 | 6143,6151,6163,6173,6197,6199,6203,6211, | ||
| 169 | 6217,6221,6229,6247,6257,6263,6269,6271, | ||
| 170 | 6277,6287,6299,6301,6311,6317,6323,6329, | ||
| 171 | 6337,6343,6353,6359,6361,6367,6373,6379, | ||
| 172 | 6389,6397,6421,6427,6449,6451,6469,6473, | ||
| 173 | 6481,6491,6521,6529,6547,6551,6553,6563, | ||
| 174 | 6569,6571,6577,6581,6599,6607,6619,6637, | ||
| 175 | 6653,6659,6661,6673,6679,6689,6691,6701, | ||
| 176 | 6703,6709,6719,6733,6737,6761,6763,6779, | ||
| 177 | 6781,6791,6793,6803,6823,6827,6829,6833, | ||
| 178 | 6841,6857,6863,6869,6871,6883,6899,6907, | ||
| 179 | 6911,6917,6947,6949,6959,6961,6967,6971, | ||
| 180 | 6977,6983,6991,6997,7001,7013,7019,7027, | ||
| 181 | 7039,7043,7057,7069,7079,7103,7109,7121, | ||
| 182 | 7127,7129,7151,7159,7177,7187,7193,7207, | ||
| 183 | 7211,7213,7219,7229,7237,7243,7247,7253, | ||
| 184 | 7283,7297,7307,7309,7321,7331,7333,7349, | ||
| 185 | 7351,7369,7393,7411,7417,7433,7451,7457, | ||
| 186 | 7459,7477,7481,7487,7489,7499,7507,7517, | ||
| 187 | 7523,7529,7537,7541,7547,7549,7559,7561, | ||
| 188 | 7573,7577,7583,7589,7591,7603,7607,7621, | ||
| 189 | 7639,7643,7649,7669,7673,7681,7687,7691, | ||
| 190 | 7699,7703,7717,7723,7727,7741,7753,7757, | ||
| 191 | 7759,7789,7793,7817,7823,7829,7841,7853, | ||
| 192 | 7867,7873,7877,7879,7883,7901,7907,7919, | ||
| 193 | 7927,7933,7937,7949,7951,7963,7993,8009, | ||
| 194 | 8011,8017,8039,8053,8059,8069,8081,8087, | ||
| 195 | 8089,8093,8101,8111,8117,8123,8147,8161, | ||
| 196 | 8167,8171,8179,8191,8209,8219,8221,8231, | ||
| 197 | 8233,8237,8243,8263,8269,8273,8287,8291, | ||
| 198 | 8293,8297,8311,8317,8329,8353,8363,8369, | ||
| 199 | 8377,8387,8389,8419,8423,8429,8431,8443, | ||
| 200 | 8447,8461,8467,8501,8513,8521,8527,8537, | ||
| 201 | 8539,8543,8563,8573,8581,8597,8599,8609, | ||
| 202 | 8623,8627,8629,8641,8647,8663,8669,8677, | ||
| 203 | 8681,8689,8693,8699,8707,8713,8719,8731, | ||
| 204 | 8737,8741,8747,8753,8761,8779,8783,8803, | ||
| 205 | 8807,8819,8821,8831,8837,8839,8849,8861, | ||
| 206 | 8863,8867,8887,8893,8923,8929,8933,8941, | ||
| 207 | 8951,8963,8969,8971,8999,9001,9007,9011, | ||
| 208 | 9013,9029,9041,9043,9049,9059,9067,9091, | ||
| 209 | 9103,9109,9127,9133,9137,9151,9157,9161, | ||
| 210 | 9173,9181,9187,9199,9203,9209,9221,9227, | ||
| 211 | 9239,9241,9257,9277,9281,9283,9293,9311, | ||
| 212 | 9319,9323,9337,9341,9343,9349,9371,9377, | ||
| 213 | 9391,9397,9403,9413,9419,9421,9431,9433, | ||
| 214 | 9437,9439,9461,9463,9467,9473,9479,9491, | ||
| 215 | 9497,9511,9521,9533,9539,9547,9551,9587, | ||
| 216 | 9601,9613,9619,9623,9629,9631,9643,9649, | ||
| 217 | 9661,9677,9679,9689,9697,9719,9721,9733, | ||
| 218 | 9739,9743,9749,9767,9769,9781,9787,9791, | ||
| 219 | 9803,9811,9817,9829,9833,9839,9851,9857, | ||
| 220 | 9859,9871,9883,9887,9901,9907,9923,9929, | ||
| 221 | 9931,9941,9949,9967,9973,10007,10009,10037, | ||
| 222 | 10039,10061,10067,10069,10079,10091,10093,10099, | ||
| 223 | 10103,10111,10133,10139,10141,10151,10159,10163, | ||
| 224 | 10169,10177,10181,10193,10211,10223,10243,10247, | ||
| 225 | 10253,10259,10267,10271,10273,10289,10301,10303, | ||
| 226 | 10313,10321,10331,10333,10337,10343,10357,10369, | ||
| 227 | 10391,10399,10427,10429,10433,10453,10457,10459, | ||
| 228 | 10463,10477,10487,10499,10501,10513,10529,10531, | ||
| 229 | 10559,10567,10589,10597,10601,10607,10613,10627, | ||
| 230 | 10631,10639,10651,10657,10663,10667,10687,10691, | ||
| 231 | 10709,10711,10723,10729,10733,10739,10753,10771, | ||
| 232 | 10781,10789,10799,10831,10837,10847,10853,10859, | ||
| 233 | 10861,10867,10883,10889,10891,10903,10909,10937, | ||
| 234 | 10939,10949,10957,10973,10979,10987,10993,11003, | ||
| 235 | 11027,11047,11057,11059,11069,11071,11083,11087, | ||
| 236 | 11093,11113,11117,11119,11131,11149,11159,11161, | ||
| 237 | 11171,11173,11177,11197,11213,11239,11243,11251, | ||
| 238 | 11257,11261,11273,11279,11287,11299,11311,11317, | ||
| 239 | 11321,11329,11351,11353,11369,11383,11393,11399, | ||
| 240 | 11411,11423,11437,11443,11447,11467,11471,11483, | ||
| 241 | 11489,11491,11497,11503,11519,11527,11549,11551, | ||
| 242 | 11579,11587,11593,11597,11617,11621,11633,11657, | ||
| 243 | 11677,11681,11689,11699,11701,11717,11719,11731, | ||
| 244 | 11743,11777,11779,11783,11789,11801,11807,11813, | ||
| 245 | 11821,11827,11831,11833,11839,11863,11867,11887, | ||
| 246 | 11897,11903,11909,11923,11927,11933,11939,11941, | ||
| 247 | 11953,11959,11969,11971,11981,11987,12007,12011, | ||
| 248 | 12037,12041,12043,12049,12071,12073,12097,12101, | ||
| 249 | 12107,12109,12113,12119,12143,12149,12157,12161, | ||
| 250 | 12163,12197,12203,12211,12227,12239,12241,12251, | ||
| 251 | 12253,12263,12269,12277,12281,12289,12301,12323, | ||
| 252 | 12329,12343,12347,12373,12377,12379,12391,12401, | ||
| 253 | 12409,12413,12421,12433,12437,12451,12457,12473, | ||
| 254 | 12479,12487,12491,12497,12503,12511,12517,12527, | ||
| 255 | 12539,12541,12547,12553,12569,12577,12583,12589, | ||
| 256 | 12601,12611,12613,12619,12637,12641,12647,12653, | ||
| 257 | 12659,12671,12689,12697,12703,12713,12721,12739, | ||
| 258 | 12743,12757,12763,12781,12791,12799,12809,12821, | ||
| 259 | 12823,12829,12841,12853,12889,12893,12899,12907, | ||
| 260 | 12911,12917,12919,12923,12941,12953,12959,12967, | ||
| 261 | 12973,12979,12983,13001,13003,13007,13009,13033, | ||
| 262 | 13037,13043,13049,13063,13093,13099,13103,13109, | ||
| 263 | 13121,13127,13147,13151,13159,13163,13171,13177, | ||
| 264 | 13183,13187,13217,13219,13229,13241,13249,13259, | ||
| 265 | 13267,13291,13297,13309,13313,13327,13331,13337, | ||
| 266 | 13339,13367,13381,13397,13399,13411,13417,13421, | ||
| 267 | 13441,13451,13457,13463,13469,13477,13487,13499, | ||
| 268 | 13513,13523,13537,13553,13567,13577,13591,13597, | ||
| 269 | 13613,13619,13627,13633,13649,13669,13679,13681, | ||
| 270 | 13687,13691,13693,13697,13709,13711,13721,13723, | ||
| 271 | 13729,13751,13757,13759,13763,13781,13789,13799, | ||
| 272 | 13807,13829,13831,13841,13859,13873,13877,13879, | ||
| 273 | 13883,13901,13903,13907,13913,13921,13931,13933, | ||
| 274 | 13963,13967,13997,13999,14009,14011,14029,14033, | ||
| 275 | 14051,14057,14071,14081,14083,14087,14107,14143, | ||
| 276 | 14149,14153,14159,14173,14177,14197,14207,14221, | ||
| 277 | 14243,14249,14251,14281,14293,14303,14321,14323, | ||
| 278 | 14327,14341,14347,14369,14387,14389,14401,14407, | ||
| 279 | 14411,14419,14423,14431,14437,14447,14449,14461, | ||
| 280 | 14479,14489,14503,14519,14533,14537,14543,14549, | ||
| 281 | 14551,14557,14561,14563,14591,14593,14621,14627, | ||
| 282 | 14629,14633,14639,14653,14657,14669,14683,14699, | ||
| 283 | 14713,14717,14723,14731,14737,14741,14747,14753, | ||
| 284 | 14759,14767,14771,14779,14783,14797,14813,14821, | ||
| 285 | 14827,14831,14843,14851,14867,14869,14879,14887, | ||
| 286 | 14891,14897,14923,14929,14939,14947,14951,14957, | ||
| 287 | 14969,14983,15013,15017,15031,15053,15061,15073, | ||
| 288 | 15077,15083,15091,15101,15107,15121,15131,15137, | ||
| 289 | 15139,15149,15161,15173,15187,15193,15199,15217, | ||
| 290 | 15227,15233,15241,15259,15263,15269,15271,15277, | ||
| 291 | 15287,15289,15299,15307,15313,15319,15329,15331, | ||
| 292 | 15349,15359,15361,15373,15377,15383,15391,15401, | ||
| 293 | 15413,15427,15439,15443,15451,15461,15467,15473, | ||
| 294 | 15493,15497,15511,15527,15541,15551,15559,15569, | ||
| 295 | 15581,15583,15601,15607,15619,15629,15641,15643, | ||
| 296 | 15647,15649,15661,15667,15671,15679,15683,15727, | ||
| 297 | 15731,15733,15737,15739,15749,15761,15767,15773, | ||
| 298 | 15787,15791,15797,15803,15809,15817,15823,15859, | ||
| 299 | 15877,15881,15887,15889,15901,15907,15913,15919, | ||
| 300 | 15923,15937,15959,15971,15973,15991,16001,16007, | ||
| 301 | 16033,16057,16061,16063,16067,16069,16073,16087, | ||
| 302 | 16091,16097,16103,16111,16127,16139,16141,16183, | ||
| 303 | 16187,16189,16193,16217,16223,16229,16231,16249, | ||
| 304 | 16253,16267,16273,16301,16319,16333,16339,16349, | ||
| 305 | 16361,16363,16369,16381,16411,16417,16421,16427, | ||
| 306 | 16433,16447,16451,16453,16477,16481,16487,16493, | ||
| 307 | 16519,16529,16547,16553,16561,16567,16573,16603, | ||
| 308 | 16607,16619,16631,16633,16649,16651,16657,16661, | ||
| 309 | 16673,16691,16693,16699,16703,16729,16741,16747, | ||
| 310 | 16759,16763,16787,16811,16823,16829,16831,16843, | ||
| 311 | 16871,16879,16883,16889,16901,16903,16921,16927, | ||
| 312 | 16931,16937,16943,16963,16979,16981,16987,16993, | ||
| 313 | 17011,17021,17027,17029,17033,17041,17047,17053, | ||
| 314 | 17077,17093,17099,17107,17117,17123,17137,17159, | ||
| 315 | 17167,17183,17189,17191,17203,17207,17209,17231, | ||
| 316 | 17239,17257,17291,17293,17299,17317,17321,17327, | ||
| 317 | 17333,17341,17351,17359,17377,17383,17387,17389, | ||
| 318 | 17393,17401,17417,17419,17431,17443,17449,17467, | ||
| 319 | 17471,17477,17483,17489,17491,17497,17509,17519, | ||
| 320 | 17539,17551,17569,17573,17579,17581,17597,17599, | ||
| 321 | 17609,17623,17627,17657,17659,17669,17681,17683, | ||
| 322 | 17707,17713,17729,17737,17747,17749,17761,17783, | ||
| 323 | 17789,17791,17807,17827,17837,17839,17851,17863, | ||
| 324 | #endif | ||
| 325 | }; | ||
diff --git a/src/lib/libcrypto/bn/bn_prime.pl b/src/lib/libcrypto/bn/bn_prime.pl new file mode 100644 index 0000000000..1b00c21a77 --- /dev/null +++ b/src/lib/libcrypto/bn/bn_prime.pl | |||
| @@ -0,0 +1,56 @@ | |||
| 1 | #!/usr/bin/perl | ||
| 2 | # bn_prime.pl | ||
| 3 | |||
| 4 | $num=2048; | ||
| 5 | $num=$ARGV[0] if ($#ARGV >= 0); | ||
| 6 | |||
| 7 | push(@primes,2); | ||
| 8 | $p=1; | ||
| 9 | loop: while ($#primes < $num-1) | ||
| 10 | { | ||
| 11 | $p+=2; | ||
| 12 | $s=int(sqrt($p)); | ||
| 13 | |||
| 14 | for ($i=0; $primes[$i]<=$s; $i++) | ||
| 15 | { | ||
| 16 | next loop if (($p%$primes[$i]) == 0); | ||
| 17 | } | ||
| 18 | push(@primes,$p); | ||
| 19 | } | ||
| 20 | |||
| 21 | print <<"EOF"; | ||
| 22 | /* Auto generated by bn_prime.pl */ | ||
| 23 | /* Copyright (C) 1995-1997 Eric Young (eay\@mincom.oz.au). | ||
| 24 | * All rights reserved. | ||
| 25 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 26 | * the code are not to be removed. | ||
| 27 | * See the COPYRIGHT file in the SSLeay distribution for more details. | ||
| 28 | */ | ||
| 29 | |||
| 30 | EOF | ||
| 31 | |||
| 32 | for ($i=0; $i <= $#primes; $i++) | ||
| 33 | { | ||
| 34 | if ($primes[$i] > 256) | ||
| 35 | { | ||
| 36 | $eight=$i; | ||
| 37 | last; | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | printf "#ifndef EIGHT_BIT\n"; | ||
| 42 | printf "#define NUMPRIMES %d\n",$num; | ||
| 43 | printf "#else\n"; | ||
| 44 | printf "#define NUMPRIMES %d\n",$eight; | ||
| 45 | printf "#endif\n"; | ||
| 46 | print "static unsigned int primes[NUMPRIMES]=\n\t{\n\t"; | ||
| 47 | $init=0; | ||
| 48 | for ($i=0; $i <= $#primes; $i++) | ||
| 49 | { | ||
| 50 | printf "\n#ifndef EIGHT_BIT\n\t" if ($primes[$i] > 256) && !($init++); | ||
| 51 | printf("\n\t") if (($i%8) == 0) && ($i != 0); | ||
| 52 | printf("%4d,",$primes[$i]); | ||
| 53 | } | ||
| 54 | print "\n#endif\n\t};\n"; | ||
| 55 | |||
| 56 | |||
diff --git a/src/lib/libcrypto/bn/bn_print.c b/src/lib/libcrypto/bn/bn_print.c new file mode 100644 index 0000000000..2bcc11c852 --- /dev/null +++ b/src/lib/libcrypto/bn/bn_print.c | |||
| @@ -0,0 +1,333 @@ | |||
| 1 | /* crypto/bn/bn_print.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 <ctype.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "buffer.h" | ||
| 63 | #include "bn_lcl.h" | ||
| 64 | |||
| 65 | static char *Hex="0123456789ABCDEF"; | ||
| 66 | |||
| 67 | /* Must 'Free' the returned data */ | ||
| 68 | char *BN_bn2hex(a) | ||
| 69 | BIGNUM *a; | ||
| 70 | { | ||
| 71 | int i,j,v,z=0; | ||
| 72 | char *buf; | ||
| 73 | char *p; | ||
| 74 | |||
| 75 | buf=(char *)Malloc(a->top*BN_BYTES*2+2); | ||
| 76 | if (buf == NULL) | ||
| 77 | { | ||
| 78 | BNerr(BN_F_BN_BN2HEX,ERR_R_MALLOC_FAILURE); | ||
| 79 | goto err; | ||
| 80 | } | ||
| 81 | p=buf; | ||
| 82 | if (a->neg) *(p++)='-'; | ||
| 83 | if (a->top == 0) *(p++)='0'; | ||
| 84 | for (i=a->top-1; i >=0; i--) | ||
| 85 | { | ||
| 86 | for (j=BN_BITS2-8; j >= 0; j-=8) | ||
| 87 | { | ||
| 88 | /* strip leading zeros */ | ||
| 89 | v=((int)(a->d[i]>>(long)j))&0xff; | ||
| 90 | if (z || (v != 0)) | ||
| 91 | { | ||
| 92 | *(p++)=Hex[v>>4]; | ||
| 93 | *(p++)=Hex[v&0x0f]; | ||
| 94 | z=1; | ||
| 95 | } | ||
| 96 | } | ||
| 97 | } | ||
| 98 | *p='\0'; | ||
| 99 | err: | ||
| 100 | return(buf); | ||
| 101 | } | ||
| 102 | |||
| 103 | /* Must 'Free' the returned data */ | ||
| 104 | char *BN_bn2dec(a) | ||
| 105 | BIGNUM *a; | ||
| 106 | { | ||
| 107 | int i=0,num; | ||
| 108 | char *buf=NULL; | ||
| 109 | char *p; | ||
| 110 | BIGNUM *t=NULL; | ||
| 111 | BN_ULONG *bn_data=NULL,*lp; | ||
| 112 | |||
| 113 | i=BN_num_bits(a)*3; | ||
| 114 | num=(i/10+i/1000+3)+1; | ||
| 115 | bn_data=(BN_ULONG *)Malloc((num/BN_DEC_NUM+1)*sizeof(BN_ULONG)); | ||
| 116 | buf=(char *)Malloc(num+3); | ||
| 117 | if ((buf == NULL) || (bn_data == NULL)) | ||
| 118 | { | ||
| 119 | BNerr(BN_F_BN_BN2DEC,ERR_R_MALLOC_FAILURE); | ||
| 120 | goto err; | ||
| 121 | } | ||
| 122 | if ((t=BN_dup(a)) == NULL) goto err; | ||
| 123 | |||
| 124 | p=buf; | ||
| 125 | lp=bn_data; | ||
| 126 | if (t->neg) *(p++)='-'; | ||
| 127 | if (t->top == 0) | ||
| 128 | { | ||
| 129 | *(p++)='0'; | ||
| 130 | *(p++)='\0'; | ||
| 131 | } | ||
| 132 | else | ||
| 133 | { | ||
| 134 | i=0; | ||
| 135 | while (!BN_is_zero(t)) | ||
| 136 | { | ||
| 137 | *lp=BN_div_word(t,BN_DEC_CONV); | ||
| 138 | lp++; | ||
| 139 | } | ||
| 140 | lp--; | ||
| 141 | /* We now have a series of blocks, BN_DEC_NUM chars | ||
| 142 | * in length, where the last one needs trucation. | ||
| 143 | * The blocks need to be reversed in order. */ | ||
| 144 | sprintf(p,BN_DEC_FMT1,*lp); | ||
| 145 | while (*p) p++; | ||
| 146 | while (lp != bn_data) | ||
| 147 | { | ||
| 148 | lp--; | ||
| 149 | sprintf(p,BN_DEC_FMT2,*lp); | ||
| 150 | while (*p) p++; | ||
| 151 | } | ||
| 152 | } | ||
| 153 | err: | ||
| 154 | if (bn_data != NULL) Free(bn_data); | ||
| 155 | if (t != NULL) BN_free(t); | ||
| 156 | return(buf); | ||
| 157 | } | ||
| 158 | |||
| 159 | int BN_hex2bn(bn,a) | ||
| 160 | BIGNUM **bn; | ||
| 161 | char *a; | ||
| 162 | { | ||
| 163 | BIGNUM *ret=NULL; | ||
| 164 | BN_ULONG l=0; | ||
| 165 | int neg=0,h,m,i,j,k,c; | ||
| 166 | int num; | ||
| 167 | |||
| 168 | if ((a == NULL) || (*a == '\0')) return(0); | ||
| 169 | |||
| 170 | if (*a == '-') { neg=1; a++; } | ||
| 171 | |||
| 172 | for (i=0; isxdigit(a[i]); i++) | ||
| 173 | ; | ||
| 174 | |||
| 175 | num=i+neg; | ||
| 176 | if (bn == NULL) return(num); | ||
| 177 | |||
| 178 | /* a is the start of the hex digets, and it is 'i' long */ | ||
| 179 | if (*bn == NULL) | ||
| 180 | { | ||
| 181 | if ((ret=BN_new()) == NULL) return(0); | ||
| 182 | } | ||
| 183 | else | ||
| 184 | { | ||
| 185 | ret= *bn; | ||
| 186 | BN_zero(ret); | ||
| 187 | } | ||
| 188 | |||
| 189 | /* i is the number of hex digests; */ | ||
| 190 | if (bn_expand(ret,i*4) == NULL) goto err; | ||
| 191 | |||
| 192 | j=i; /* least significate 'hex' */ | ||
| 193 | m=0; | ||
| 194 | h=0; | ||
| 195 | while (j > 0) | ||
| 196 | { | ||
| 197 | m=((BN_BYTES*2) <= j)?(BN_BYTES*2):j; | ||
| 198 | l=0; | ||
| 199 | for (;;) | ||
| 200 | { | ||
| 201 | c=a[j-m]; | ||
| 202 | if ((c >= '0') && (c <= '9')) k=c-'0'; | ||
| 203 | else if ((c >= 'a') && (c <= 'f')) k=c-'a'+10; | ||
| 204 | else if ((c >= 'A') && (c <= 'F')) k=c-'A'+10; | ||
| 205 | else k=0; /* paranoia */ | ||
| 206 | l=(l<<4)|k; | ||
| 207 | |||
| 208 | if (--m <= 0) | ||
| 209 | { | ||
| 210 | ret->d[h++]=l; | ||
| 211 | break; | ||
| 212 | } | ||
| 213 | } | ||
| 214 | j-=(BN_BYTES*2); | ||
| 215 | } | ||
| 216 | ret->top=h; | ||
| 217 | bn_fix_top(ret); | ||
| 218 | ret->neg=neg; | ||
| 219 | |||
| 220 | *bn=ret; | ||
| 221 | return(num); | ||
| 222 | err: | ||
| 223 | if (*bn == NULL) BN_free(ret); | ||
| 224 | return(0); | ||
| 225 | } | ||
| 226 | |||
| 227 | int BN_dec2bn(bn,a) | ||
| 228 | BIGNUM **bn; | ||
| 229 | char *a; | ||
| 230 | { | ||
| 231 | BIGNUM *ret=NULL; | ||
| 232 | BN_ULONG l=0; | ||
| 233 | int neg=0,i,j; | ||
| 234 | int num; | ||
| 235 | |||
| 236 | if ((a == NULL) || (*a == '\0')) return(0); | ||
| 237 | if (*a == '-') { neg=1; a++; } | ||
| 238 | |||
| 239 | for (i=0; isdigit(a[i]); i++) | ||
| 240 | ; | ||
| 241 | |||
| 242 | num=i+neg; | ||
| 243 | if (bn == NULL) return(num); | ||
| 244 | |||
| 245 | /* a is the start of the digets, and it is 'i' long. | ||
| 246 | * We chop it into BN_DEC_NUM digets at a time */ | ||
| 247 | if (*bn == NULL) | ||
| 248 | { | ||
| 249 | if ((ret=BN_new()) == NULL) return(0); | ||
| 250 | } | ||
| 251 | else | ||
| 252 | { | ||
| 253 | ret= *bn; | ||
| 254 | BN_zero(ret); | ||
| 255 | } | ||
| 256 | |||
| 257 | /* i is the number of digests, a bit of an over expand; */ | ||
| 258 | if (bn_expand(ret,i*4) == NULL) goto err; | ||
| 259 | |||
| 260 | j=BN_DEC_NUM-(i%BN_DEC_NUM); | ||
| 261 | if (j == BN_DEC_NUM) j=0; | ||
| 262 | l=0; | ||
| 263 | while (*a) | ||
| 264 | { | ||
| 265 | l*=10; | ||
| 266 | l+= *a-'0'; | ||
| 267 | a++; | ||
| 268 | if (++j == BN_DEC_NUM) | ||
| 269 | { | ||
| 270 | BN_mul_word(ret,BN_DEC_CONV); | ||
| 271 | BN_add_word(ret,l); | ||
| 272 | l=0; | ||
| 273 | j=0; | ||
| 274 | } | ||
| 275 | } | ||
| 276 | ret->neg=neg; | ||
| 277 | |||
| 278 | bn_fix_top(ret); | ||
| 279 | *bn=ret; | ||
| 280 | return(num); | ||
| 281 | err: | ||
| 282 | if (*bn == NULL) BN_free(ret); | ||
| 283 | return(0); | ||
| 284 | } | ||
| 285 | |||
| 286 | #ifndef NO_BIO | ||
| 287 | |||
| 288 | #ifndef NO_FP_API | ||
| 289 | int BN_print_fp(fp, a) | ||
| 290 | FILE *fp; | ||
| 291 | BIGNUM *a; | ||
| 292 | { | ||
| 293 | BIO *b; | ||
| 294 | int ret; | ||
| 295 | |||
| 296 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 297 | return(0); | ||
| 298 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 299 | ret=BN_print(b,a); | ||
| 300 | BIO_free(b); | ||
| 301 | return(ret); | ||
| 302 | } | ||
| 303 | #endif | ||
| 304 | |||
| 305 | int BN_print(bp, a) | ||
| 306 | BIO *bp; | ||
| 307 | BIGNUM *a; | ||
| 308 | { | ||
| 309 | int i,j,v,z=0; | ||
| 310 | int ret=0; | ||
| 311 | |||
| 312 | if ((a->neg) && (BIO_write(bp,"-",1) != 1)) goto end; | ||
| 313 | if ((a->top == 0) && (BIO_write(bp,"0",1) != 1)) goto end; | ||
| 314 | for (i=a->top-1; i >=0; i--) | ||
| 315 | { | ||
| 316 | for (j=BN_BITS2-4; j >= 0; j-=4) | ||
| 317 | { | ||
| 318 | /* strip leading zeros */ | ||
| 319 | v=((int)(a->d[i]>>(long)j))&0x0f; | ||
| 320 | if (z || (v != 0)) | ||
| 321 | { | ||
| 322 | if (BIO_write(bp,&(Hex[v]),1) != 1) | ||
| 323 | goto end; | ||
| 324 | z=1; | ||
| 325 | } | ||
| 326 | } | ||
| 327 | } | ||
| 328 | ret=1; | ||
| 329 | end: | ||
| 330 | return(ret); | ||
| 331 | } | ||
| 332 | |||
| 333 | #endif | ||
diff --git a/src/lib/libcrypto/bn/bn_rand.c b/src/lib/libcrypto/bn/bn_rand.c new file mode 100644 index 0000000000..75b6b0493b --- /dev/null +++ b/src/lib/libcrypto/bn/bn_rand.c | |||
| @@ -0,0 +1,121 @@ | |||
| 1 | /* crypto/bn/bn_rand.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 <time.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "bn_lcl.h" | ||
| 63 | #include "rand.h" | ||
| 64 | |||
| 65 | int BN_rand(rnd, bits, top, bottom) | ||
| 66 | BIGNUM *rnd; | ||
| 67 | int bits; | ||
| 68 | int top; | ||
| 69 | int bottom; | ||
| 70 | { | ||
| 71 | unsigned char *buf=NULL; | ||
| 72 | int ret=0,bit,bytes,mask; | ||
| 73 | time_t tim; | ||
| 74 | |||
| 75 | bytes=(bits+7)/8; | ||
| 76 | bit=(bits-1)%8; | ||
| 77 | mask=0xff<<bit; | ||
| 78 | |||
| 79 | buf=(unsigned char *)Malloc(bytes); | ||
| 80 | if (buf == NULL) | ||
| 81 | { | ||
| 82 | BNerr(BN_F_BN_RAND,ERR_R_MALLOC_FAILURE); | ||
| 83 | goto err; | ||
| 84 | } | ||
| 85 | |||
| 86 | /* make a random number and set the top and bottom bits */ | ||
| 87 | time(&tim); | ||
| 88 | RAND_seed((unsigned char *)&tim,sizeof(tim)); | ||
| 89 | |||
| 90 | RAND_bytes(buf,(int)bytes); | ||
| 91 | if (top) | ||
| 92 | { | ||
| 93 | if (bit == 0) | ||
| 94 | { | ||
| 95 | buf[0]=1; | ||
| 96 | buf[1]|=0x80; | ||
| 97 | } | ||
| 98 | else | ||
| 99 | { | ||
| 100 | buf[0]|=(3<<(bit-1)); | ||
| 101 | buf[0]&= ~(mask<<1); | ||
| 102 | } | ||
| 103 | } | ||
| 104 | else | ||
| 105 | { | ||
| 106 | buf[0]|=(1<<bit); | ||
| 107 | buf[0]&= ~(mask<<1); | ||
| 108 | } | ||
| 109 | if (bottom) /* set bottom bits to whatever odd is */ | ||
| 110 | buf[bytes-1]|=1; | ||
| 111 | if (!BN_bin2bn(buf,bytes,rnd)) goto err; | ||
| 112 | ret=1; | ||
| 113 | err: | ||
| 114 | if (buf != NULL) | ||
| 115 | { | ||
| 116 | memset(buf,0,bytes); | ||
| 117 | Free(buf); | ||
| 118 | } | ||
| 119 | return(ret); | ||
| 120 | } | ||
| 121 | |||
diff --git a/src/lib/libcrypto/bn/bn_recp.c b/src/lib/libcrypto/bn/bn_recp.c new file mode 100644 index 0000000000..72cd69d3fc --- /dev/null +++ b/src/lib/libcrypto/bn/bn_recp.c | |||
| @@ -0,0 +1,125 @@ | |||
| 1 | /* crypto/bn/bn_recp.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_lcl.h" | ||
| 62 | |||
| 63 | int BN_mod_mul_reciprocal(r, x, y, m, i, nb, ctx) | ||
| 64 | BIGNUM *r; | ||
| 65 | BIGNUM *x; | ||
| 66 | BIGNUM *y; | ||
| 67 | BIGNUM *m; | ||
| 68 | BIGNUM *i; | ||
| 69 | int nb; | ||
| 70 | BN_CTX *ctx; | ||
| 71 | { | ||
| 72 | int ret=0,j; | ||
| 73 | BIGNUM *a,*b,*c,*d; | ||
| 74 | |||
| 75 | a=ctx->bn[ctx->tos++]; | ||
| 76 | b=ctx->bn[ctx->tos++]; | ||
| 77 | c=ctx->bn[ctx->tos++]; | ||
| 78 | d=ctx->bn[ctx->tos++]; | ||
| 79 | |||
| 80 | if (x == y) | ||
| 81 | { if (!BN_sqr(a,x,ctx)) goto err; } | ||
| 82 | else | ||
| 83 | { if (!BN_mul(a,x,y)) goto err; } | ||
| 84 | if (!BN_rshift(d,a,nb)) goto err; | ||
| 85 | if (!BN_mul(b,d,i)) goto err; | ||
| 86 | if (!BN_rshift(c,b,nb)) goto err; | ||
| 87 | if (!BN_mul(b,m,c)) goto err; | ||
| 88 | if (!BN_sub(r,a,b)) goto err; | ||
| 89 | j=0; | ||
| 90 | while (BN_cmp(r,m) >= 0) | ||
| 91 | { | ||
| 92 | if (j++ > 2) | ||
| 93 | { | ||
| 94 | BNerr(BN_F_BN_MOD_MUL_RECIPROCAL,BN_R_BAD_RECIPROCAL); | ||
| 95 | goto err; | ||
| 96 | } | ||
| 97 | if (!BN_sub(r,r,m)) goto err; | ||
| 98 | } | ||
| 99 | |||
| 100 | ret=1; | ||
| 101 | err: | ||
| 102 | ctx->tos-=4; | ||
| 103 | return(ret); | ||
| 104 | } | ||
| 105 | |||
| 106 | int BN_reciprocal(r, m,ctx) | ||
| 107 | BIGNUM *r; | ||
| 108 | BIGNUM *m; | ||
| 109 | BN_CTX *ctx; | ||
| 110 | { | ||
| 111 | int nm,ret= -1; | ||
| 112 | BIGNUM *t; | ||
| 113 | |||
| 114 | t=ctx->bn[ctx->tos++]; | ||
| 115 | |||
| 116 | nm=BN_num_bits(m); | ||
| 117 | if (!BN_lshift(t,BN_value_one(),nm*2)) goto err; | ||
| 118 | |||
| 119 | if (!BN_div(r,NULL,t,m,ctx)) goto err; | ||
| 120 | ret=nm; | ||
| 121 | err: | ||
| 122 | ctx->tos--; | ||
| 123 | return(ret); | ||
| 124 | } | ||
| 125 | |||
diff --git a/src/lib/libcrypto/bn/bn_shift.c b/src/lib/libcrypto/bn/bn_shift.c new file mode 100644 index 0000000000..944bf1794b --- /dev/null +++ b/src/lib/libcrypto/bn/bn_shift.c | |||
| @@ -0,0 +1,210 @@ | |||
| 1 | /* crypto/bn/bn_shift.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_lcl.h" | ||
| 62 | |||
| 63 | int BN_lshift1(r, a) | ||
| 64 | BIGNUM *r; | ||
| 65 | BIGNUM *a; | ||
| 66 | { | ||
| 67 | register BN_ULONG *ap,*rp,t,c; | ||
| 68 | int i; | ||
| 69 | |||
| 70 | if (r != a) | ||
| 71 | { | ||
| 72 | r->neg=a->neg; | ||
| 73 | if (bn_wexpand(r,a->top+1) == NULL) return(0); | ||
| 74 | r->top=a->top; | ||
| 75 | } | ||
| 76 | else | ||
| 77 | { | ||
| 78 | if (bn_wexpand(r,a->top+1) == NULL) return(0); | ||
| 79 | } | ||
| 80 | ap=a->d; | ||
| 81 | rp=r->d; | ||
| 82 | c=0; | ||
| 83 | for (i=0; i<a->top; i++) | ||
| 84 | { | ||
| 85 | t= *(ap++); | ||
| 86 | *(rp++)=((t<<1)|c)&BN_MASK2; | ||
| 87 | c=(t & BN_TBIT)?1:0; | ||
| 88 | } | ||
| 89 | if (c) | ||
| 90 | { | ||
| 91 | *rp=1; | ||
| 92 | r->top++; | ||
| 93 | } | ||
| 94 | return(1); | ||
| 95 | } | ||
| 96 | |||
| 97 | int BN_rshift1(r, a) | ||
| 98 | BIGNUM *r; | ||
| 99 | BIGNUM *a; | ||
| 100 | { | ||
| 101 | BN_ULONG *ap,*rp,t,c; | ||
| 102 | int i; | ||
| 103 | |||
| 104 | if (BN_is_zero(a)) | ||
| 105 | { | ||
| 106 | BN_zero(r); | ||
| 107 | return(1); | ||
| 108 | } | ||
| 109 | if (a != r) | ||
| 110 | { | ||
| 111 | if (bn_wexpand(r,a->top) == NULL) return(0); | ||
| 112 | r->top=a->top; | ||
| 113 | r->neg=a->neg; | ||
| 114 | } | ||
| 115 | ap=a->d; | ||
| 116 | rp=r->d; | ||
| 117 | c=0; | ||
| 118 | for (i=a->top-1; i>=0; i--) | ||
| 119 | { | ||
| 120 | t=ap[i]; | ||
| 121 | rp[i]=((t>>1)&BN_MASK2)|c; | ||
| 122 | c=(t&1)?BN_TBIT:0; | ||
| 123 | } | ||
| 124 | bn_fix_top(r); | ||
| 125 | return(1); | ||
| 126 | } | ||
| 127 | |||
| 128 | int BN_lshift(r, a, n) | ||
| 129 | BIGNUM *r; | ||
| 130 | BIGNUM *a; | ||
| 131 | int n; | ||
| 132 | { | ||
| 133 | int i,nw,lb,rb; | ||
| 134 | BN_ULONG *t,*f; | ||
| 135 | BN_ULONG l; | ||
| 136 | |||
| 137 | r->neg=a->neg; | ||
| 138 | if (bn_wexpand(r,a->top+(n/BN_BITS2)+1) == NULL) return(0); | ||
| 139 | nw=n/BN_BITS2; | ||
| 140 | lb=n%BN_BITS2; | ||
| 141 | rb=BN_BITS2-lb; | ||
| 142 | f=a->d; | ||
| 143 | t=r->d; | ||
| 144 | t[a->top+nw]=0; | ||
| 145 | if (lb == 0) | ||
| 146 | for (i=a->top-1; i>=0; i--) | ||
| 147 | t[nw+i]=f[i]; | ||
| 148 | else | ||
| 149 | for (i=a->top-1; i>=0; i--) | ||
| 150 | { | ||
| 151 | l=f[i]; | ||
| 152 | t[nw+i+1]|=(l>>rb)&BN_MASK2; | ||
| 153 | t[nw+i]=(l<<lb)&BN_MASK2; | ||
| 154 | } | ||
| 155 | memset(t,0,nw*sizeof(t[0])); | ||
| 156 | /* for (i=0; i<nw; i++) | ||
| 157 | t[i]=0;*/ | ||
| 158 | r->top=a->top+nw+1; | ||
| 159 | bn_fix_top(r); | ||
| 160 | return(1); | ||
| 161 | } | ||
| 162 | |||
| 163 | int BN_rshift(r, a, n) | ||
| 164 | BIGNUM *r; | ||
| 165 | BIGNUM *a; | ||
| 166 | int n; | ||
| 167 | { | ||
| 168 | int i,j,nw,lb,rb; | ||
| 169 | BN_ULONG *t,*f; | ||
| 170 | BN_ULONG l,tmp; | ||
| 171 | |||
| 172 | nw=n/BN_BITS2; | ||
| 173 | rb=n%BN_BITS2; | ||
| 174 | lb=BN_BITS2-rb; | ||
| 175 | if (nw > a->top) | ||
| 176 | { | ||
| 177 | BN_zero(r); | ||
| 178 | return(1); | ||
| 179 | } | ||
| 180 | if (r != a) | ||
| 181 | { | ||
| 182 | r->neg=a->neg; | ||
| 183 | if (bn_wexpand(r,a->top-nw+1) == NULL) return(0); | ||
| 184 | } | ||
| 185 | |||
| 186 | f= &(a->d[nw]); | ||
| 187 | t=r->d; | ||
| 188 | j=a->top-nw; | ||
| 189 | r->top=j; | ||
| 190 | |||
| 191 | if (rb == 0) | ||
| 192 | { | ||
| 193 | for (i=j+1; i > 0; i--) | ||
| 194 | *(t++)= *(f++); | ||
| 195 | } | ||
| 196 | else | ||
| 197 | { | ||
| 198 | l= *(f++); | ||
| 199 | for (i=1; i<j; i++) | ||
| 200 | { | ||
| 201 | tmp =(l>>rb)&BN_MASK2; | ||
| 202 | l= *(f++); | ||
| 203 | *(t++) =(tmp|(l<<lb))&BN_MASK2; | ||
| 204 | } | ||
| 205 | *(t++) =(l>>rb)&BN_MASK2; | ||
| 206 | } | ||
| 207 | *t=0; | ||
| 208 | bn_fix_top(r); | ||
| 209 | return(1); | ||
| 210 | } | ||
diff --git a/src/lib/libcrypto/bn/bn_sqr.c b/src/lib/libcrypto/bn/bn_sqr.c new file mode 100644 index 0000000000..a8464610e5 --- /dev/null +++ b/src/lib/libcrypto/bn/bn_sqr.c | |||
| @@ -0,0 +1,122 @@ | |||
| 1 | /* crypto/bn/bn_sqr.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_lcl.h" | ||
| 62 | |||
| 63 | /* r must not be a */ | ||
| 64 | /* I've just gone over this and it is now %20 faster on x86 - eay - 27 Jun 96 */ | ||
| 65 | int BN_sqr(r, a, ctx) | ||
| 66 | BIGNUM *r; | ||
| 67 | BIGNUM *a; | ||
| 68 | BN_CTX *ctx; | ||
| 69 | { | ||
| 70 | int i,j,max,al; | ||
| 71 | BIGNUM *tmp; | ||
| 72 | BN_ULONG *ap,*rp; | ||
| 73 | |||
| 74 | tmp=ctx->bn[ctx->tos]; | ||
| 75 | |||
| 76 | al=a->top; | ||
| 77 | if (al == 0) | ||
| 78 | { | ||
| 79 | r->top=0; | ||
| 80 | return(1); | ||
| 81 | } | ||
| 82 | |||
| 83 | max=(al*2); | ||
| 84 | if (bn_wexpand(r,1+max) == NULL) return(0); | ||
| 85 | if (bn_wexpand(tmp,1+max) == NULL) return(0); | ||
| 86 | |||
| 87 | r->neg=0; | ||
| 88 | |||
| 89 | ap=a->d; | ||
| 90 | rp=r->d; | ||
| 91 | rp[0]=rp[max-1]=0; | ||
| 92 | rp++; | ||
| 93 | j=al; | ||
| 94 | |||
| 95 | if (--j > 0) | ||
| 96 | { | ||
| 97 | ap++; | ||
| 98 | rp[j]=bn_mul_words(rp,ap,j,ap[-1]); | ||
| 99 | rp+=2; | ||
| 100 | } | ||
| 101 | |||
| 102 | for (i=2; i<al; i++) | ||
| 103 | { | ||
| 104 | j--; | ||
| 105 | ap++; | ||
| 106 | rp[j]=bn_mul_add_words(rp,ap,j,ap[-1]); | ||
| 107 | rp+=2; | ||
| 108 | } | ||
| 109 | |||
| 110 | bn_add_words(r->d,r->d,r->d,max); | ||
| 111 | |||
| 112 | /* There will not be a carry */ | ||
| 113 | |||
| 114 | bn_sqr_words(tmp->d,a->d,al); | ||
| 115 | |||
| 116 | bn_add_words(r->d,r->d,tmp->d,max); | ||
| 117 | |||
| 118 | r->top=max; | ||
| 119 | if (r->d[max-1] == 0) r->top--; | ||
| 120 | return(1); | ||
| 121 | } | ||
| 122 | |||
diff --git a/src/lib/libcrypto/bn/bn_word.c b/src/lib/libcrypto/bn/bn_word.c new file mode 100644 index 0000000000..4b3d0f011d --- /dev/null +++ b/src/lib/libcrypto/bn/bn_word.c | |||
| @@ -0,0 +1,204 @@ | |||
| 1 | /* crypto/bn/bn_word.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_lcl.h" | ||
| 62 | |||
| 63 | BN_ULONG BN_mod_word(a, w) | ||
| 64 | BIGNUM *a; | ||
| 65 | unsigned long w; | ||
| 66 | { | ||
| 67 | #ifndef BN_LLONG | ||
| 68 | BN_ULONG ret=0; | ||
| 69 | #else | ||
| 70 | BN_ULLONG ret=0; | ||
| 71 | #endif | ||
| 72 | int i; | ||
| 73 | |||
| 74 | w&=BN_MASK2; | ||
| 75 | for (i=a->top-1; i>=0; i--) | ||
| 76 | { | ||
| 77 | #ifndef BN_LLONG | ||
| 78 | ret=((ret<<BN_BITS4)|((a->d[i]>>BN_BITS4)&BN_MASK2l))%(unsigned long)w; | ||
| 79 | ret=((ret<<BN_BITS4)|(a->d[i]&BN_MASK2l))%(unsigned long)w; | ||
| 80 | #else | ||
| 81 | ret=(BN_ULLONG)(((ret<<(BN_ULLONG)BN_BITS2)|a->d[i])% | ||
| 82 | (BN_ULLONG)w); | ||
| 83 | #endif | ||
| 84 | } | ||
| 85 | return((BN_ULONG)ret); | ||
| 86 | } | ||
| 87 | |||
| 88 | BN_ULONG BN_div_word(a, w) | ||
| 89 | BIGNUM *a; | ||
| 90 | unsigned long w; | ||
| 91 | { | ||
| 92 | BN_ULONG ret; | ||
| 93 | int i; | ||
| 94 | |||
| 95 | if (a->top == 0) return(0); | ||
| 96 | ret=0; | ||
| 97 | w&=BN_MASK2; | ||
| 98 | for (i=a->top-1; i>=0; i--) | ||
| 99 | { | ||
| 100 | BN_ULONG l,d; | ||
| 101 | |||
| 102 | l=a->d[i]; | ||
| 103 | d=bn_div64(ret,l,w); | ||
| 104 | ret=(l-((d*w)&BN_MASK2))&BN_MASK2; | ||
| 105 | a->d[i]=d; | ||
| 106 | } | ||
| 107 | if (a->d[a->top-1] == 0) | ||
| 108 | a->top--; | ||
| 109 | return(ret); | ||
| 110 | } | ||
| 111 | |||
| 112 | int BN_add_word(a, w) | ||
| 113 | BIGNUM *a; | ||
| 114 | unsigned long w; | ||
| 115 | { | ||
| 116 | BN_ULONG l; | ||
| 117 | int i; | ||
| 118 | |||
| 119 | if (a->neg) | ||
| 120 | { | ||
| 121 | a->neg=0; | ||
| 122 | i=BN_sub_word(a,w); | ||
| 123 | if (!BN_is_zero(a)) | ||
| 124 | a->neg=1; | ||
| 125 | return(i); | ||
| 126 | } | ||
| 127 | w&=BN_MASK2; | ||
| 128 | if (bn_wexpand(a,a->top+1) == NULL) return(0); | ||
| 129 | i=0; | ||
| 130 | for (;;) | ||
| 131 | { | ||
| 132 | l=(a->d[i]+(BN_ULONG)w)&BN_MASK2; | ||
| 133 | a->d[i]=l; | ||
| 134 | if (w > l) | ||
| 135 | w=1; | ||
| 136 | else | ||
| 137 | break; | ||
| 138 | i++; | ||
| 139 | } | ||
| 140 | if (i >= a->top) | ||
| 141 | a->top++; | ||
| 142 | return(1); | ||
| 143 | } | ||
| 144 | |||
| 145 | int BN_sub_word(a, w) | ||
| 146 | BIGNUM *a; | ||
| 147 | unsigned long w; | ||
| 148 | { | ||
| 149 | int i; | ||
| 150 | |||
| 151 | if (a->neg) | ||
| 152 | { | ||
| 153 | a->neg=0; | ||
| 154 | i=BN_add_word(a,w); | ||
| 155 | a->neg=1; | ||
| 156 | return(i); | ||
| 157 | } | ||
| 158 | |||
| 159 | w&=BN_MASK2; | ||
| 160 | if ((a->top == 1) && (a->d[0] < w)) | ||
| 161 | { | ||
| 162 | a->d[0]=w-a->d[0]; | ||
| 163 | a->neg=1; | ||
| 164 | return(1); | ||
| 165 | } | ||
| 166 | i=0; | ||
| 167 | for (;;) | ||
| 168 | { | ||
| 169 | if (a->d[i] >= w) | ||
| 170 | { | ||
| 171 | a->d[i]-=w; | ||
| 172 | break; | ||
| 173 | } | ||
| 174 | else | ||
| 175 | { | ||
| 176 | a->d[i]=(a->d[i]-w)&BN_MASK2; | ||
| 177 | i++; | ||
| 178 | w=1; | ||
| 179 | } | ||
| 180 | } | ||
| 181 | if ((a->d[i] == 0) && (i == (a->top-1))) | ||
| 182 | a->top--; | ||
| 183 | return(1); | ||
| 184 | } | ||
| 185 | |||
| 186 | int BN_mul_word(a,w) | ||
| 187 | BIGNUM *a; | ||
| 188 | unsigned long w; | ||
| 189 | { | ||
| 190 | BN_ULONG ll; | ||
| 191 | |||
| 192 | w&=BN_MASK2; | ||
| 193 | if (a->top) | ||
| 194 | { | ||
| 195 | ll=bn_mul_words(a->d,a->d,a->top,w); | ||
| 196 | if (ll) | ||
| 197 | { | ||
| 198 | if (bn_wexpand(a,a->top+1) == NULL) return(0); | ||
| 199 | a->d[a->top++]=ll; | ||
| 200 | } | ||
| 201 | } | ||
| 202 | return(0); | ||
| 203 | } | ||
| 204 | |||
diff --git a/src/lib/libcrypto/buffer/buf_err.c b/src/lib/libcrypto/buffer/buf_err.c new file mode 100644 index 0000000000..ff988852cc --- /dev/null +++ b/src/lib/libcrypto/buffer/buf_err.c | |||
| @@ -0,0 +1,87 @@ | |||
| 1 | /* lib/buf/buf_err.c */ | ||
| 2 | /* Copyright (C) 1995-1997 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 | #include <stdio.h> | ||
| 59 | #include "err.h" | ||
| 60 | #include "buffer.h" | ||
| 61 | |||
| 62 | /* BEGIN ERROR CODES */ | ||
| 63 | #ifndef NO_ERR | ||
| 64 | static ERR_STRING_DATA BUF_str_functs[]= | ||
| 65 | { | ||
| 66 | {ERR_PACK(0,BUF_F_BUF_MEM_GROW,0), "BUF_MEM_grow"}, | ||
| 67 | {ERR_PACK(0,BUF_F_BUF_MEM_NEW,0), "BUF_MEM_new"}, | ||
| 68 | {ERR_PACK(0,BUF_F_BUF_STRDUP,0), "BUF_strdup"}, | ||
| 69 | {ERR_PACK(0,BUF_F_PXYCLNT_READ,0), "PXYCLNT_READ"}, | ||
| 70 | {0,NULL}, | ||
| 71 | }; | ||
| 72 | |||
| 73 | #endif | ||
| 74 | |||
| 75 | void ERR_load_BUF_strings() | ||
| 76 | { | ||
| 77 | static int init=1; | ||
| 78 | |||
| 79 | if (init); | ||
| 80 | {; | ||
| 81 | init=0; | ||
| 82 | #ifndef NO_ERR | ||
| 83 | ERR_load_strings(ERR_LIB_BUF,BUF_str_functs); | ||
| 84 | #endif | ||
| 85 | |||
| 86 | } | ||
| 87 | } | ||
diff --git a/src/lib/libcrypto/buffer/buffer.c b/src/lib/libcrypto/buffer/buffer.c new file mode 100644 index 0000000000..7e8af9e2fa --- /dev/null +++ b/src/lib/libcrypto/buffer/buffer.c | |||
| @@ -0,0 +1,145 @@ | |||
| 1 | /* crypto/buffer/buffer.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 "buffer.h" | ||
| 62 | |||
| 63 | BUF_MEM *BUF_MEM_new() | ||
| 64 | { | ||
| 65 | BUF_MEM *ret; | ||
| 66 | |||
| 67 | ret=(BUF_MEM *)Malloc(sizeof(BUF_MEM)); | ||
| 68 | if (ret == NULL) | ||
| 69 | { | ||
| 70 | BUFerr(BUF_F_BUF_MEM_NEW,ERR_R_MALLOC_FAILURE); | ||
| 71 | return(NULL); | ||
| 72 | } | ||
| 73 | ret->length=0; | ||
| 74 | ret->max=0; | ||
| 75 | ret->data=NULL; | ||
| 76 | return(ret); | ||
| 77 | } | ||
| 78 | |||
| 79 | void BUF_MEM_free(a) | ||
| 80 | BUF_MEM *a; | ||
| 81 | { | ||
| 82 | if (a->data != NULL) | ||
| 83 | { | ||
| 84 | memset(a->data,0,(unsigned int)a->max); | ||
| 85 | Free(a->data); | ||
| 86 | } | ||
| 87 | Free(a); | ||
| 88 | } | ||
| 89 | |||
| 90 | int BUF_MEM_grow(str, len) | ||
| 91 | BUF_MEM *str; | ||
| 92 | int len; | ||
| 93 | { | ||
| 94 | char *ret; | ||
| 95 | unsigned int n; | ||
| 96 | |||
| 97 | if (str->length >= len) | ||
| 98 | { | ||
| 99 | str->length=len; | ||
| 100 | return(len); | ||
| 101 | } | ||
| 102 | if (str->max >= len) | ||
| 103 | { | ||
| 104 | memset(&(str->data[str->length]),0,len-str->length); | ||
| 105 | str->length=len; | ||
| 106 | return(len); | ||
| 107 | } | ||
| 108 | n=(len+3)/3*4; | ||
| 109 | if (str->data == NULL) | ||
| 110 | ret=(char *)Malloc(n); | ||
| 111 | else | ||
| 112 | ret=(char *)Realloc(str->data,n); | ||
| 113 | if (ret == NULL) | ||
| 114 | { | ||
| 115 | BUFerr(BUF_F_BUF_MEM_GROW,ERR_R_MALLOC_FAILURE); | ||
| 116 | len=0; | ||
| 117 | } | ||
| 118 | else | ||
| 119 | { | ||
| 120 | str->data=ret; | ||
| 121 | str->length=len; | ||
| 122 | str->max=n; | ||
| 123 | } | ||
| 124 | return(len); | ||
| 125 | } | ||
| 126 | |||
| 127 | char *BUF_strdup(str) | ||
| 128 | char *str; | ||
| 129 | { | ||
| 130 | char *ret; | ||
| 131 | int n; | ||
| 132 | |||
| 133 | if (str == NULL) return(NULL); | ||
| 134 | |||
| 135 | n=strlen(str); | ||
| 136 | ret=Malloc(n+1); | ||
| 137 | if (ret == NULL) | ||
| 138 | { | ||
| 139 | BUFerr(BUF_F_BUF_STRDUP,ERR_R_MALLOC_FAILURE); | ||
| 140 | return(NULL); | ||
| 141 | } | ||
| 142 | memcpy(ret,str,n+1); | ||
| 143 | return(ret); | ||
| 144 | } | ||
| 145 | |||
diff --git a/src/lib/libcrypto/buffer/buffer.h b/src/lib/libcrypto/buffer/buffer.h new file mode 100644 index 0000000000..417548c04a --- /dev/null +++ b/src/lib/libcrypto/buffer/buffer.h | |||
| @@ -0,0 +1,107 @@ | |||
| 1 | /* crypto/buffer/buffer.h */ | ||
| 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 | #ifndef HEADER_BUFFER_H | ||
| 60 | #define HEADER_BUFFER_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | typedef struct buf_mem_st | ||
| 67 | { | ||
| 68 | int length; /* current number of bytes */ | ||
| 69 | char *data; | ||
| 70 | int max; /* size of buffer */ | ||
| 71 | } BUF_MEM; | ||
| 72 | |||
| 73 | #ifndef NOPROTO | ||
| 74 | BUF_MEM *BUF_MEM_new(void); | ||
| 75 | void BUF_MEM_free(BUF_MEM *a); | ||
| 76 | int BUF_MEM_grow(BUF_MEM *str, int len); | ||
| 77 | char * BUF_strdup(char *str); | ||
| 78 | |||
| 79 | void ERR_load_BUF_strings(void ); | ||
| 80 | |||
| 81 | #else | ||
| 82 | |||
| 83 | BUF_MEM *BUF_MEM_new(); | ||
| 84 | void BUF_MEM_free(); | ||
| 85 | int BUF_MEM_grow(); | ||
| 86 | char * BUF_strdup(); | ||
| 87 | |||
| 88 | void ERR_load_BUF_strings(); | ||
| 89 | |||
| 90 | #endif | ||
| 91 | |||
| 92 | /* BEGIN ERROR CODES */ | ||
| 93 | /* Error codes for the BUF functions. */ | ||
| 94 | |||
| 95 | /* Function codes. */ | ||
| 96 | #define BUF_F_BUF_MEM_GROW 100 | ||
| 97 | #define BUF_F_BUF_MEM_NEW 101 | ||
| 98 | #define BUF_F_BUF_STRDUP 102 | ||
| 99 | #define BUF_F_PXYCLNT_READ 103 | ||
| 100 | |||
| 101 | /* Reason codes. */ | ||
| 102 | |||
| 103 | #ifdef __cplusplus | ||
| 104 | } | ||
| 105 | #endif | ||
| 106 | #endif | ||
| 107 | |||
diff --git a/src/lib/libcrypto/cast/asm/cast-586.pl b/src/lib/libcrypto/cast/asm/cast-586.pl new file mode 100644 index 0000000000..d0be004c99 --- /dev/null +++ b/src/lib/libcrypto/cast/asm/cast-586.pl | |||
| @@ -0,0 +1,167 @@ | |||
| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | # define for pentium pro friendly version | ||
| 4 | $ppro=1; | ||
| 5 | |||
| 6 | push(@INC,"perlasm","../../perlasm"); | ||
| 7 | require "x86asm.pl"; | ||
| 8 | require "cbc.pl"; | ||
| 9 | |||
| 10 | &asm_init($ARGV[0],"cast-586.pl"); | ||
| 11 | |||
| 12 | $CAST_ROUNDS=16; | ||
| 13 | $L="edi"; | ||
| 14 | $R="esi"; | ||
| 15 | $K="ebp"; | ||
| 16 | $tmp1="ecx"; | ||
| 17 | $tmp2="ebx"; | ||
| 18 | $tmp3="eax"; | ||
| 19 | $tmp4="edx"; | ||
| 20 | $S1="CAST_S_table0"; | ||
| 21 | $S2="CAST_S_table1"; | ||
| 22 | $S3="CAST_S_table2"; | ||
| 23 | $S4="CAST_S_table3"; | ||
| 24 | |||
| 25 | @F1=("add","xor","sub"); | ||
| 26 | @F2=("xor","sub","add"); | ||
| 27 | @F3=("sub","add","xor"); | ||
| 28 | |||
| 29 | &CAST_encrypt("CAST_encrypt",1); | ||
| 30 | &CAST_encrypt("CAST_decrypt",0); | ||
| 31 | &cbc("CAST_cbc_encrypt","CAST_encrypt","CAST_decrypt",1,4,5,3,-1,-1); | ||
| 32 | |||
| 33 | &asm_finish(); | ||
| 34 | |||
| 35 | sub CAST_encrypt | ||
| 36 | { | ||
| 37 | local($name,$enc)=@_; | ||
| 38 | |||
| 39 | local($win_ex)=<<"EOF"; | ||
| 40 | EXTERN _CAST_S_table0:DWORD | ||
| 41 | EXTERN _CAST_S_table1:DWORD | ||
| 42 | EXTERN _CAST_S_table2:DWORD | ||
| 43 | EXTERN _CAST_S_table3:DWORD | ||
| 44 | EOF | ||
| 45 | &main'external_label( | ||
| 46 | "CAST_S_table0", | ||
| 47 | "CAST_S_table1", | ||
| 48 | "CAST_S_table2", | ||
| 49 | "CAST_S_table3", | ||
| 50 | ); | ||
| 51 | |||
| 52 | &function_begin_B($name,$win_ex); | ||
| 53 | |||
| 54 | &comment(""); | ||
| 55 | |||
| 56 | &push("ebp"); | ||
| 57 | &push("ebx"); | ||
| 58 | &mov($tmp2,&wparam(0)); | ||
| 59 | &mov($K,&wparam(1)); | ||
| 60 | &push("esi"); | ||
| 61 | &push("edi"); | ||
| 62 | |||
| 63 | &comment("Load the 2 words"); | ||
| 64 | &mov($L,&DWP(0,$tmp2,"",0)); | ||
| 65 | &mov($R,&DWP(4,$tmp2,"",0)); | ||
| 66 | |||
| 67 | &xor( $tmp3, $tmp3); | ||
| 68 | |||
| 69 | # encrypting part | ||
| 70 | |||
| 71 | if ($enc) | ||
| 72 | { | ||
| 73 | &E_CAST( 0,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 74 | &E_CAST( 1,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 75 | &E_CAST( 2,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 76 | &E_CAST( 3,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 77 | &E_CAST( 4,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 78 | &E_CAST( 5,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 79 | &E_CAST( 6,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 80 | &E_CAST( 7,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 81 | &E_CAST( 8,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 82 | &E_CAST( 9,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 83 | &E_CAST(10,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 84 | &E_CAST(11,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 85 | &E_CAST(12,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 86 | &E_CAST(13,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 87 | &E_CAST(14,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 88 | &E_CAST(15,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4,1); | ||
| 89 | } | ||
| 90 | else | ||
| 91 | { | ||
| 92 | &E_CAST(15,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 93 | &E_CAST(14,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 94 | &E_CAST(13,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 95 | &E_CAST(12,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 96 | &E_CAST(11,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 97 | &E_CAST(10,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 98 | &E_CAST( 9,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 99 | &E_CAST( 8,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 100 | &E_CAST( 7,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 101 | &E_CAST( 6,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 102 | &E_CAST( 5,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 103 | &E_CAST( 4,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 104 | &E_CAST( 3,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 105 | &E_CAST( 2,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 106 | &E_CAST( 1,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); | ||
| 107 | &E_CAST( 0,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4,1); | ||
| 108 | } | ||
| 109 | |||
| 110 | &nop(); | ||
| 111 | &mov(&DWP(4,$tmp3,"",0),$L); | ||
| 112 | &mov(&DWP(0,$tmp3,"",0),$R); | ||
| 113 | &function_end($name); | ||
| 114 | } | ||
| 115 | |||
| 116 | sub E_CAST | ||
| 117 | { | ||
| 118 | local($i,$S,$L,$R,$K,$OP1,$OP2,$OP3,$tmp1,$tmp2,$tmp3,$tmp4,$lst)=@_; | ||
| 119 | # Ri needs to have 16 pre added. | ||
| 120 | |||
| 121 | &comment("round $i"); | ||
| 122 | &mov( $tmp4, &DWP($i*8,$K,"",1)); | ||
| 123 | |||
| 124 | &mov( $tmp1, &DWP($i*8+4,$K,"",1));# must be word | ||
| 125 | &$OP1( $tmp4, $R); | ||
| 126 | |||
| 127 | &rotl( $tmp4, &LB($tmp1)); | ||
| 128 | |||
| 129 | if ($ppro) | ||
| 130 | { | ||
| 131 | &mov( $tmp2, $tmp4); # B | ||
| 132 | &xor( $tmp1, $tmp1); | ||
| 133 | |||
| 134 | &movb( &LB($tmp1), &HB($tmp4)); # A | ||
| 135 | &and( $tmp2, 0xff); | ||
| 136 | |||
| 137 | &shr( $tmp4, 16); # | ||
| 138 | &xor( $tmp3, $tmp3); | ||
| 139 | } | ||
| 140 | else | ||
| 141 | { | ||
| 142 | &mov( $tmp2, $tmp4); # B | ||
| 143 | &movb( &LB($tmp1), &HB($tmp4)); # A # BAD BAD BAD | ||
| 144 | |||
| 145 | &shr( $tmp4, 16); # | ||
| 146 | &and( $tmp2, 0xff); | ||
| 147 | } | ||
| 148 | |||
| 149 | &movb( &LB($tmp3), &HB($tmp4)); # C # BAD BAD BAD | ||
| 150 | &and( $tmp4, 0xff); # D | ||
| 151 | |||
| 152 | &mov( $tmp1, &DWP($S1,"",$tmp1,4)); | ||
| 153 | &mov( $tmp2, &DWP($S2,"",$tmp2,4)); | ||
| 154 | |||
| 155 | &$OP2( $tmp1, $tmp2); | ||
| 156 | &mov( $tmp2, &DWP($S3,"",$tmp3,4)); | ||
| 157 | |||
| 158 | &$OP3( $tmp1, $tmp2); | ||
| 159 | &mov( $tmp2, &DWP($S4,"",$tmp4,4)); | ||
| 160 | |||
| 161 | &$OP1( $tmp1, $tmp2); | ||
| 162 | &mov($tmp3,&wparam(0)) if $lst; | ||
| 163 | # XXX | ||
| 164 | |||
| 165 | &xor( $L, $tmp1); | ||
| 166 | # XXX | ||
| 167 | } | ||
diff --git a/src/lib/libcrypto/cast/c_cfb64.c b/src/lib/libcrypto/cast/c_cfb64.c new file mode 100644 index 0000000000..c46c375f75 --- /dev/null +++ b/src/lib/libcrypto/cast/c_cfb64.c | |||
| @@ -0,0 +1,127 @@ | |||
| 1 | /* crypto/cast/c_cfb64.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 "cast.h" | ||
| 60 | #include "cast_lcl.h" | ||
| 61 | |||
| 62 | /* The input and output encrypted as though 64bit cfb mode is being | ||
| 63 | * used. The extra state information to record how much of the | ||
| 64 | * 64bit block we have used is contained in *num; | ||
| 65 | */ | ||
| 66 | |||
| 67 | void CAST_cfb64_encrypt(in, out, length, schedule, ivec, num, encrypt) | ||
| 68 | unsigned char *in; | ||
| 69 | unsigned char *out; | ||
| 70 | long length; | ||
| 71 | CAST_KEY *schedule; | ||
| 72 | unsigned char *ivec; | ||
| 73 | int *num; | ||
| 74 | int encrypt; | ||
| 75 | { | ||
| 76 | register CAST_LONG v0,v1,t; | ||
| 77 | register int n= *num; | ||
| 78 | register long l=length; | ||
| 79 | CAST_LONG ti[2]; | ||
| 80 | unsigned char *iv,c,cc; | ||
| 81 | |||
| 82 | iv=(unsigned char *)ivec; | ||
| 83 | if (encrypt) | ||
| 84 | { | ||
| 85 | while (l--) | ||
| 86 | { | ||
| 87 | if (n == 0) | ||
| 88 | { | ||
| 89 | n2l(iv,v0); ti[0]=v0; | ||
| 90 | n2l(iv,v1); ti[1]=v1; | ||
| 91 | CAST_encrypt((CAST_LONG *)ti,schedule); | ||
| 92 | iv=(unsigned char *)ivec; | ||
| 93 | t=ti[0]; l2n(t,iv); | ||
| 94 | t=ti[1]; l2n(t,iv); | ||
| 95 | iv=(unsigned char *)ivec; | ||
| 96 | } | ||
| 97 | c= *(in++)^iv[n]; | ||
| 98 | *(out++)=c; | ||
| 99 | iv[n]=c; | ||
| 100 | n=(n+1)&0x07; | ||
| 101 | } | ||
| 102 | } | ||
| 103 | else | ||
| 104 | { | ||
| 105 | while (l--) | ||
| 106 | { | ||
| 107 | if (n == 0) | ||
| 108 | { | ||
| 109 | n2l(iv,v0); ti[0]=v0; | ||
| 110 | n2l(iv,v1); ti[1]=v1; | ||
| 111 | CAST_encrypt((CAST_LONG *)ti,schedule); | ||
| 112 | iv=(unsigned char *)ivec; | ||
| 113 | t=ti[0]; l2n(t,iv); | ||
| 114 | t=ti[1]; l2n(t,iv); | ||
| 115 | iv=(unsigned char *)ivec; | ||
| 116 | } | ||
| 117 | cc= *(in++); | ||
| 118 | c=iv[n]; | ||
| 119 | iv[n]=cc; | ||
| 120 | *(out++)=c^cc; | ||
| 121 | n=(n+1)&0x07; | ||
| 122 | } | ||
| 123 | } | ||
| 124 | v0=v1=ti[0]=ti[1]=t=c=cc=0; | ||
| 125 | *num=n; | ||
| 126 | } | ||
| 127 | |||
diff --git a/src/lib/libcrypto/cast/c_ecb.c b/src/lib/libcrypto/cast/c_ecb.c new file mode 100644 index 0000000000..f0f2f4df0e --- /dev/null +++ b/src/lib/libcrypto/cast/c_ecb.c | |||
| @@ -0,0 +1,82 @@ | |||
| 1 | /* crypto/cast/c_ecb.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 "cast.h" | ||
| 60 | #include "cast_lcl.h" | ||
| 61 | |||
| 62 | char *CAST_version="CAST part of SSLeay 0.9.0b 29-Jun-1998"; | ||
| 63 | |||
| 64 | void CAST_ecb_encrypt(in, out, ks, encrypt) | ||
| 65 | unsigned char *in; | ||
| 66 | unsigned char *out; | ||
| 67 | CAST_KEY *ks; | ||
| 68 | int encrypt; | ||
| 69 | { | ||
| 70 | CAST_LONG l,d[2]; | ||
| 71 | |||
| 72 | n2l(in,l); d[0]=l; | ||
| 73 | n2l(in,l); d[1]=l; | ||
| 74 | if (encrypt) | ||
| 75 | CAST_encrypt(d,ks); | ||
| 76 | else | ||
| 77 | CAST_decrypt(d,ks); | ||
| 78 | l=d[0]; l2n(l,out); | ||
| 79 | l=d[1]; l2n(l,out); | ||
| 80 | l=d[0]=d[1]=0; | ||
| 81 | } | ||
| 82 | |||
diff --git a/src/lib/libcrypto/cast/c_enc.c b/src/lib/libcrypto/cast/c_enc.c new file mode 100644 index 0000000000..d998dd4953 --- /dev/null +++ b/src/lib/libcrypto/cast/c_enc.c | |||
| @@ -0,0 +1,210 @@ | |||
| 1 | /* crypto/cast/c_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 "cast.h" | ||
| 60 | #include "cast_lcl.h" | ||
| 61 | |||
| 62 | void CAST_encrypt(data,key) | ||
| 63 | CAST_LONG *data; | ||
| 64 | CAST_KEY *key; | ||
| 65 | { | ||
| 66 | register CAST_LONG l,r,*k,t; | ||
| 67 | |||
| 68 | k= &(key->data[0]); | ||
| 69 | l=data[0]; | ||
| 70 | r=data[1]; | ||
| 71 | |||
| 72 | E_CAST( 0,k,l,r,+,^,-); | ||
| 73 | E_CAST( 1,k,r,l,^,-,+); | ||
| 74 | E_CAST( 2,k,l,r,-,+,^); | ||
| 75 | E_CAST( 3,k,r,l,+,^,-); | ||
| 76 | E_CAST( 4,k,l,r,^,-,+); | ||
| 77 | E_CAST( 5,k,r,l,-,+,^); | ||
| 78 | E_CAST( 6,k,l,r,+,^,-); | ||
| 79 | E_CAST( 7,k,r,l,^,-,+); | ||
| 80 | E_CAST( 8,k,l,r,-,+,^); | ||
| 81 | E_CAST( 9,k,r,l,+,^,-); | ||
| 82 | E_CAST(10,k,l,r,^,-,+); | ||
| 83 | E_CAST(11,k,r,l,-,+,^); | ||
| 84 | E_CAST(12,k,l,r,+,^,-); | ||
| 85 | E_CAST(13,k,r,l,^,-,+); | ||
| 86 | E_CAST(14,k,l,r,-,+,^); | ||
| 87 | E_CAST(15,k,r,l,+,^,-); | ||
| 88 | |||
| 89 | data[1]=l&0xffffffffL; | ||
| 90 | data[0]=r&0xffffffffL; | ||
| 91 | } | ||
| 92 | |||
| 93 | void CAST_decrypt(data,key) | ||
| 94 | CAST_LONG *data; | ||
| 95 | CAST_KEY *key; | ||
| 96 | { | ||
| 97 | register CAST_LONG l,r,*k,t; | ||
| 98 | |||
| 99 | k= &(key->data[0]); | ||
| 100 | l=data[0]; | ||
| 101 | r=data[1]; | ||
| 102 | |||
| 103 | E_CAST(15,k,l,r,+,^,-); | ||
| 104 | E_CAST(14,k,r,l,-,+,^); | ||
| 105 | E_CAST(13,k,l,r,^,-,+); | ||
| 106 | E_CAST(12,k,r,l,+,^,-); | ||
| 107 | E_CAST(11,k,l,r,-,+,^); | ||
| 108 | E_CAST(10,k,r,l,^,-,+); | ||
| 109 | E_CAST( 9,k,l,r,+,^,-); | ||
| 110 | E_CAST( 8,k,r,l,-,+,^); | ||
| 111 | E_CAST( 7,k,l,r,^,-,+); | ||
| 112 | E_CAST( 6,k,r,l,+,^,-); | ||
| 113 | E_CAST( 5,k,l,r,-,+,^); | ||
| 114 | E_CAST( 4,k,r,l,^,-,+); | ||
| 115 | E_CAST( 3,k,l,r,+,^,-); | ||
| 116 | E_CAST( 2,k,r,l,-,+,^); | ||
| 117 | E_CAST( 1,k,l,r,^,-,+); | ||
| 118 | E_CAST( 0,k,r,l,+,^,-); | ||
| 119 | |||
| 120 | data[1]=l&0xffffffffL; | ||
| 121 | data[0]=r&0xffffffffL; | ||
| 122 | } | ||
| 123 | |||
| 124 | void CAST_cbc_encrypt(in, out, length, ks, iv, encrypt) | ||
| 125 | unsigned char *in; | ||
| 126 | unsigned char *out; | ||
| 127 | long length; | ||
| 128 | CAST_KEY *ks; | ||
| 129 | unsigned char *iv; | ||
| 130 | int encrypt; | ||
| 131 | { | ||
| 132 | register CAST_LONG tin0,tin1; | ||
| 133 | register CAST_LONG tout0,tout1,xor0,xor1; | ||
| 134 | register long l=length; | ||
| 135 | CAST_LONG tin[2]; | ||
| 136 | |||
| 137 | if (encrypt) | ||
| 138 | { | ||
| 139 | n2l(iv,tout0); | ||
| 140 | n2l(iv,tout1); | ||
| 141 | iv-=8; | ||
| 142 | for (l-=8; l>=0; l-=8) | ||
| 143 | { | ||
| 144 | n2l(in,tin0); | ||
| 145 | n2l(in,tin1); | ||
| 146 | tin0^=tout0; | ||
| 147 | tin1^=tout1; | ||
| 148 | tin[0]=tin0; | ||
| 149 | tin[1]=tin1; | ||
| 150 | CAST_encrypt(tin,ks); | ||
| 151 | tout0=tin[0]; | ||
| 152 | tout1=tin[1]; | ||
| 153 | l2n(tout0,out); | ||
| 154 | l2n(tout1,out); | ||
| 155 | } | ||
| 156 | if (l != -8) | ||
| 157 | { | ||
| 158 | n2ln(in,tin0,tin1,l+8); | ||
| 159 | tin0^=tout0; | ||
| 160 | tin1^=tout1; | ||
| 161 | tin[0]=tin0; | ||
| 162 | tin[1]=tin1; | ||
| 163 | CAST_encrypt(tin,ks); | ||
| 164 | tout0=tin[0]; | ||
| 165 | tout1=tin[1]; | ||
| 166 | l2n(tout0,out); | ||
| 167 | l2n(tout1,out); | ||
| 168 | } | ||
| 169 | l2n(tout0,iv); | ||
| 170 | l2n(tout1,iv); | ||
| 171 | } | ||
| 172 | else | ||
| 173 | { | ||
| 174 | n2l(iv,xor0); | ||
| 175 | n2l(iv,xor1); | ||
| 176 | iv-=8; | ||
| 177 | for (l-=8; l>=0; l-=8) | ||
| 178 | { | ||
| 179 | n2l(in,tin0); | ||
| 180 | n2l(in,tin1); | ||
| 181 | tin[0]=tin0; | ||
| 182 | tin[1]=tin1; | ||
| 183 | CAST_decrypt(tin,ks); | ||
| 184 | tout0=tin[0]^xor0; | ||
| 185 | tout1=tin[1]^xor1; | ||
| 186 | l2n(tout0,out); | ||
| 187 | l2n(tout1,out); | ||
| 188 | xor0=tin0; | ||
| 189 | xor1=tin1; | ||
| 190 | } | ||
| 191 | if (l != -8) | ||
| 192 | { | ||
| 193 | n2l(in,tin0); | ||
| 194 | n2l(in,tin1); | ||
| 195 | tin[0]=tin0; | ||
| 196 | tin[1]=tin1; | ||
| 197 | CAST_decrypt(tin,ks); | ||
| 198 | tout0=tin[0]^xor0; | ||
| 199 | tout1=tin[1]^xor1; | ||
| 200 | l2nn(tout0,tout1,out,l+8); | ||
| 201 | xor0=tin0; | ||
| 202 | xor1=tin1; | ||
| 203 | } | ||
| 204 | l2n(xor0,iv); | ||
| 205 | l2n(xor1,iv); | ||
| 206 | } | ||
| 207 | tin0=tin1=tout0=tout1=xor0=xor1=0; | ||
| 208 | tin[0]=tin[1]=0; | ||
| 209 | } | ||
| 210 | |||
diff --git a/src/lib/libcrypto/cast/c_ofb64.c b/src/lib/libcrypto/cast/c_ofb64.c new file mode 100644 index 0000000000..2aad2d6d96 --- /dev/null +++ b/src/lib/libcrypto/cast/c_ofb64.c | |||
| @@ -0,0 +1,115 @@ | |||
| 1 | /* crypto/cast/c_ofb64.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 "cast.h" | ||
| 60 | #include "cast_lcl.h" | ||
| 61 | |||
| 62 | /* The input and output encrypted as though 64bit ofb mode is being | ||
| 63 | * used. The extra state information to record how much of the | ||
| 64 | * 64bit block we have used is contained in *num; | ||
| 65 | */ | ||
| 66 | void CAST_ofb64_encrypt(in, out, length, schedule, ivec, num) | ||
| 67 | unsigned char *in; | ||
| 68 | unsigned char *out; | ||
| 69 | long length; | ||
| 70 | CAST_KEY *schedule; | ||
| 71 | unsigned char *ivec; | ||
| 72 | int *num; | ||
| 73 | { | ||
| 74 | register CAST_LONG v0,v1,t; | ||
| 75 | register int n= *num; | ||
| 76 | register long l=length; | ||
| 77 | unsigned char d[8]; | ||
| 78 | register char *dp; | ||
| 79 | CAST_LONG ti[2]; | ||
| 80 | unsigned char *iv; | ||
| 81 | int save=0; | ||
| 82 | |||
| 83 | iv=(unsigned char *)ivec; | ||
| 84 | n2l(iv,v0); | ||
| 85 | n2l(iv,v1); | ||
| 86 | ti[0]=v0; | ||
| 87 | ti[1]=v1; | ||
| 88 | dp=(char *)d; | ||
| 89 | l2n(v0,dp); | ||
| 90 | l2n(v1,dp); | ||
| 91 | while (l--) | ||
| 92 | { | ||
| 93 | if (n == 0) | ||
| 94 | { | ||
| 95 | CAST_encrypt((CAST_LONG *)ti,schedule); | ||
| 96 | dp=(char *)d; | ||
| 97 | t=ti[0]; l2n(t,dp); | ||
| 98 | t=ti[1]; l2n(t,dp); | ||
| 99 | save++; | ||
| 100 | } | ||
| 101 | *(out++)= *(in++)^d[n]; | ||
| 102 | n=(n+1)&0x07; | ||
| 103 | } | ||
| 104 | if (save) | ||
| 105 | { | ||
| 106 | v0=ti[0]; | ||
| 107 | v1=ti[1]; | ||
| 108 | iv=(unsigned char *)ivec; | ||
| 109 | l2n(v0,iv); | ||
| 110 | l2n(v1,iv); | ||
| 111 | } | ||
| 112 | t=v0=v1=ti[0]=ti[1]=0; | ||
| 113 | *num=n; | ||
| 114 | } | ||
| 115 | |||
diff --git a/src/lib/libcrypto/cast/c_skey.c b/src/lib/libcrypto/cast/c_skey.c new file mode 100644 index 0000000000..2fc3363dcd --- /dev/null +++ b/src/lib/libcrypto/cast/c_skey.c | |||
| @@ -0,0 +1,165 @@ | |||
| 1 | /* crypto/cast/c_skey.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 "cast.h" | ||
| 60 | #include "cast_lcl.h" | ||
| 61 | #include "cast_s.h" | ||
| 62 | |||
| 63 | #define CAST_exp(l,A,a,n) \ | ||
| 64 | A[n/4]=l; \ | ||
| 65 | a[n+3]=(l )&0xff; \ | ||
| 66 | a[n+2]=(l>> 8)&0xff; \ | ||
| 67 | a[n+1]=(l>>16)&0xff; \ | ||
| 68 | a[n+0]=(l>>24)&0xff; | ||
| 69 | |||
| 70 | #define S4 CAST_S_table4 | ||
| 71 | #define S5 CAST_S_table5 | ||
| 72 | #define S6 CAST_S_table6 | ||
| 73 | #define S7 CAST_S_table7 | ||
| 74 | |||
| 75 | void CAST_set_key(key,len,data) | ||
| 76 | CAST_KEY *key; | ||
| 77 | int len; | ||
| 78 | unsigned char *data; | ||
| 79 | { | ||
| 80 | CAST_LONG x[16]; | ||
| 81 | CAST_LONG z[16]; | ||
| 82 | CAST_LONG k[32]; | ||
| 83 | CAST_LONG X[4],Z[4]; | ||
| 84 | CAST_LONG l,*K; | ||
| 85 | int i; | ||
| 86 | |||
| 87 | for (i=0; i<16; i++) x[i]=0; | ||
| 88 | if (len > 16) len=16; | ||
| 89 | for (i=0; i<len; i++) | ||
| 90 | x[i]=data[i]; | ||
| 91 | |||
| 92 | K= &k[0]; | ||
| 93 | X[0]=((x[ 0]<<24)|(x[ 1]<<16)|(x[ 2]<<8)|x[ 3])&0xffffffffL; | ||
| 94 | X[1]=((x[ 4]<<24)|(x[ 5]<<16)|(x[ 6]<<8)|x[ 7])&0xffffffffL; | ||
| 95 | X[2]=((x[ 8]<<24)|(x[ 9]<<16)|(x[10]<<8)|x[11])&0xffffffffL; | ||
| 96 | X[3]=((x[12]<<24)|(x[13]<<16)|(x[14]<<8)|x[15])&0xffffffffL; | ||
| 97 | |||
| 98 | for (;;) | ||
| 99 | { | ||
| 100 | l=X[0]^S4[x[13]]^S5[x[15]]^S6[x[12]]^S7[x[14]]^S6[x[ 8]]; | ||
| 101 | CAST_exp(l,Z,z, 0); | ||
| 102 | l=X[2]^S4[z[ 0]]^S5[z[ 2]]^S6[z[ 1]]^S7[z[ 3]]^S7[x[10]]; | ||
| 103 | CAST_exp(l,Z,z, 4); | ||
| 104 | l=X[3]^S4[z[ 7]]^S5[z[ 6]]^S6[z[ 5]]^S7[z[ 4]]^S4[x[ 9]]; | ||
| 105 | CAST_exp(l,Z,z, 8); | ||
| 106 | l=X[1]^S4[z[10]]^S5[z[ 9]]^S6[z[11]]^S7[z[ 8]]^S5[x[11]]; | ||
| 107 | CAST_exp(l,Z,z,12); | ||
| 108 | |||
| 109 | K[ 0]= S4[z[ 8]]^S5[z[ 9]]^S6[z[ 7]]^S7[z[ 6]]^S4[z[ 2]]; | ||
| 110 | K[ 1]= S4[z[10]]^S5[z[11]]^S6[z[ 5]]^S7[z[ 4]]^S5[z[ 6]]; | ||
| 111 | K[ 2]= S4[z[12]]^S5[z[13]]^S6[z[ 3]]^S7[z[ 2]]^S6[z[ 9]]; | ||
| 112 | K[ 3]= S4[z[14]]^S5[z[15]]^S6[z[ 1]]^S7[z[ 0]]^S7[z[12]]; | ||
| 113 | |||
| 114 | l=Z[2]^S4[z[ 5]]^S5[z[ 7]]^S6[z[ 4]]^S7[z[ 6]]^S6[z[ 0]]; | ||
| 115 | CAST_exp(l,X,x, 0); | ||
| 116 | l=Z[0]^S4[x[ 0]]^S5[x[ 2]]^S6[x[ 1]]^S7[x[ 3]]^S7[z[ 2]]; | ||
| 117 | CAST_exp(l,X,x, 4); | ||
| 118 | l=Z[1]^S4[x[ 7]]^S5[x[ 6]]^S6[x[ 5]]^S7[x[ 4]]^S4[z[ 1]]; | ||
| 119 | CAST_exp(l,X,x, 8); | ||
| 120 | l=Z[3]^S4[x[10]]^S5[x[ 9]]^S6[x[11]]^S7[x[ 8]]^S5[z[ 3]]; | ||
| 121 | CAST_exp(l,X,x,12); | ||
| 122 | |||
| 123 | K[ 4]= S4[x[ 3]]^S5[x[ 2]]^S6[x[12]]^S7[x[13]]^S4[x[ 8]]; | ||
| 124 | K[ 5]= S4[x[ 1]]^S5[x[ 0]]^S6[x[14]]^S7[x[15]]^S5[x[13]]; | ||
| 125 | K[ 6]= S4[x[ 7]]^S5[x[ 6]]^S6[x[ 8]]^S7[x[ 9]]^S6[x[ 3]]; | ||
| 126 | K[ 7]= S4[x[ 5]]^S5[x[ 4]]^S6[x[10]]^S7[x[11]]^S7[x[ 7]]; | ||
| 127 | |||
| 128 | l=X[0]^S4[x[13]]^S5[x[15]]^S6[x[12]]^S7[x[14]]^S6[x[ 8]]; | ||
| 129 | CAST_exp(l,Z,z, 0); | ||
| 130 | l=X[2]^S4[z[ 0]]^S5[z[ 2]]^S6[z[ 1]]^S7[z[ 3]]^S7[x[10]]; | ||
| 131 | CAST_exp(l,Z,z, 4); | ||
| 132 | l=X[3]^S4[z[ 7]]^S5[z[ 6]]^S6[z[ 5]]^S7[z[ 4]]^S4[x[ 9]]; | ||
| 133 | CAST_exp(l,Z,z, 8); | ||
| 134 | l=X[1]^S4[z[10]]^S5[z[ 9]]^S6[z[11]]^S7[z[ 8]]^S5[x[11]]; | ||
| 135 | CAST_exp(l,Z,z,12); | ||
| 136 | |||
| 137 | K[ 8]= S4[z[ 3]]^S5[z[ 2]]^S6[z[12]]^S7[z[13]]^S4[z[ 9]]; | ||
| 138 | K[ 9]= S4[z[ 1]]^S5[z[ 0]]^S6[z[14]]^S7[z[15]]^S5[z[12]]; | ||
| 139 | K[10]= S4[z[ 7]]^S5[z[ 6]]^S6[z[ 8]]^S7[z[ 9]]^S6[z[ 2]]; | ||
| 140 | K[11]= S4[z[ 5]]^S5[z[ 4]]^S6[z[10]]^S7[z[11]]^S7[z[ 6]]; | ||
| 141 | |||
| 142 | l=Z[2]^S4[z[ 5]]^S5[z[ 7]]^S6[z[ 4]]^S7[z[ 6]]^S6[z[ 0]]; | ||
| 143 | CAST_exp(l,X,x, 0); | ||
| 144 | l=Z[0]^S4[x[ 0]]^S5[x[ 2]]^S6[x[ 1]]^S7[x[ 3]]^S7[z[ 2]]; | ||
| 145 | CAST_exp(l,X,x, 4); | ||
| 146 | l=Z[1]^S4[x[ 7]]^S5[x[ 6]]^S6[x[ 5]]^S7[x[ 4]]^S4[z[ 1]]; | ||
| 147 | CAST_exp(l,X,x, 8); | ||
| 148 | l=Z[3]^S4[x[10]]^S5[x[ 9]]^S6[x[11]]^S7[x[ 8]]^S5[z[ 3]]; | ||
| 149 | CAST_exp(l,X,x,12); | ||
| 150 | |||
| 151 | K[12]= S4[x[ 8]]^S5[x[ 9]]^S6[x[ 7]]^S7[x[ 6]]^S4[x[ 3]]; | ||
| 152 | K[13]= S4[x[10]]^S5[x[11]]^S6[x[ 5]]^S7[x[ 4]]^S5[x[ 7]]; | ||
| 153 | K[14]= S4[x[12]]^S5[x[13]]^S6[x[ 3]]^S7[x[ 2]]^S6[x[ 8]]; | ||
| 154 | K[15]= S4[x[14]]^S5[x[15]]^S6[x[ 1]]^S7[x[ 0]]^S7[x[13]]; | ||
| 155 | if (K != k) break; | ||
| 156 | K+=16; | ||
| 157 | } | ||
| 158 | |||
| 159 | for (i=0; i<16; i++) | ||
| 160 | { | ||
| 161 | key->data[i*2]=k[i]; | ||
| 162 | key->data[i*2+1]=((k[i+16])+16)&0x1f; | ||
| 163 | } | ||
| 164 | } | ||
| 165 | |||
diff --git a/src/lib/libcrypto/cast/cast.h b/src/lib/libcrypto/cast/cast.h new file mode 100644 index 0000000000..528cb7c824 --- /dev/null +++ b/src/lib/libcrypto/cast/cast.h | |||
| @@ -0,0 +1,109 @@ | |||
| 1 | /* crypto/cast/cast.h */ | ||
| 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 | #ifndef HEADER_CAST_H | ||
| 60 | #define HEADER_CAST_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #define CAST_ENCRYPT 1 | ||
| 67 | #define CAST_DECRYPT 0 | ||
| 68 | |||
| 69 | #define CAST_LONG unsigned long | ||
| 70 | |||
| 71 | #define CAST_BLOCK 8 | ||
| 72 | #define CAST_KEY_LENGTH 16 | ||
| 73 | |||
| 74 | typedef struct cast_key_st | ||
| 75 | { | ||
| 76 | CAST_LONG data[32]; | ||
| 77 | } CAST_KEY; | ||
| 78 | |||
| 79 | #ifndef NOPROTO | ||
| 80 | |||
| 81 | void CAST_set_key(CAST_KEY *key, int len, unsigned char *data); | ||
| 82 | void CAST_ecb_encrypt(unsigned char *in,unsigned char *out,CAST_KEY *key, | ||
| 83 | int enc); | ||
| 84 | void CAST_encrypt(CAST_LONG *data,CAST_KEY *key); | ||
| 85 | void CAST_decrypt(CAST_LONG *data,CAST_KEY *key); | ||
| 86 | void CAST_cbc_encrypt(unsigned char *in, unsigned char *out, long length, | ||
| 87 | CAST_KEY *ks, unsigned char *iv, int enc); | ||
| 88 | void CAST_cfb64_encrypt(unsigned char *in, unsigned char *out, long length, | ||
| 89 | CAST_KEY *schedule, unsigned char *ivec, int *num, int enc); | ||
| 90 | void CAST_ofb64_encrypt(unsigned char *in, unsigned char *out, long length, | ||
| 91 | CAST_KEY *schedule, unsigned char *ivec, int *num); | ||
| 92 | |||
| 93 | #else | ||
| 94 | |||
| 95 | void CAST_set_key(); | ||
| 96 | void CAST_ecb_encrypt(); | ||
| 97 | void CAST_encrypt(); | ||
| 98 | void CAST_decrypt(); | ||
| 99 | void CAST_cbc_encrypt(); | ||
| 100 | void CAST_cfb64_encrypt(); | ||
| 101 | void CAST_ofb64_encrypt(); | ||
| 102 | |||
| 103 | #endif | ||
| 104 | |||
| 105 | #ifdef __cplusplus | ||
| 106 | } | ||
| 107 | #endif | ||
| 108 | |||
| 109 | #endif | ||
diff --git a/src/lib/libcrypto/cast/cast_lcl.h b/src/lib/libcrypto/cast/cast_lcl.h new file mode 100644 index 0000000000..6587952a96 --- /dev/null +++ b/src/lib/libcrypto/cast/cast_lcl.h | |||
| @@ -0,0 +1,224 @@ | |||
| 1 | /* crypto/cast/cast_lcl.h */ | ||
| 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 | #ifdef WIN32 | ||
| 60 | #include <stdlib.h> | ||
| 61 | #endif | ||
| 62 | |||
| 63 | #undef c2l | ||
| 64 | #define c2l(c,l) (l =((unsigned long)(*((c)++))) , \ | ||
| 65 | l|=((unsigned long)(*((c)++)))<< 8L, \ | ||
| 66 | l|=((unsigned long)(*((c)++)))<<16L, \ | ||
| 67 | l|=((unsigned long)(*((c)++)))<<24L) | ||
| 68 | |||
| 69 | /* NOTE - c is not incremented as per c2l */ | ||
| 70 | #undef c2ln | ||
| 71 | #define c2ln(c,l1,l2,n) { \ | ||
| 72 | c+=n; \ | ||
| 73 | l1=l2=0; \ | ||
| 74 | switch (n) { \ | ||
| 75 | case 8: l2 =((unsigned long)(*(--(c))))<<24L; \ | ||
| 76 | case 7: l2|=((unsigned long)(*(--(c))))<<16L; \ | ||
| 77 | case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \ | ||
| 78 | case 5: l2|=((unsigned long)(*(--(c)))); \ | ||
| 79 | case 4: l1 =((unsigned long)(*(--(c))))<<24L; \ | ||
| 80 | case 3: l1|=((unsigned long)(*(--(c))))<<16L; \ | ||
| 81 | case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \ | ||
| 82 | case 1: l1|=((unsigned long)(*(--(c)))); \ | ||
| 83 | } \ | ||
| 84 | } | ||
| 85 | |||
| 86 | #undef l2c | ||
| 87 | #define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ | ||
| 88 | *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ | ||
| 89 | *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ | ||
| 90 | *((c)++)=(unsigned char)(((l)>>24L)&0xff)) | ||
| 91 | |||
| 92 | /* NOTE - c is not incremented as per l2c */ | ||
| 93 | #undef l2cn | ||
| 94 | #define l2cn(l1,l2,c,n) { \ | ||
| 95 | c+=n; \ | ||
| 96 | switch (n) { \ | ||
| 97 | case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \ | ||
| 98 | case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \ | ||
| 99 | case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \ | ||
| 100 | case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \ | ||
| 101 | case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \ | ||
| 102 | case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \ | ||
| 103 | case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \ | ||
| 104 | case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \ | ||
| 105 | } \ | ||
| 106 | } | ||
| 107 | |||
| 108 | /* NOTE - c is not incremented as per n2l */ | ||
| 109 | #define n2ln(c,l1,l2,n) { \ | ||
| 110 | c+=n; \ | ||
| 111 | l1=l2=0; \ | ||
| 112 | switch (n) { \ | ||
| 113 | case 8: l2 =((unsigned long)(*(--(c)))) ; \ | ||
| 114 | case 7: l2|=((unsigned long)(*(--(c))))<< 8; \ | ||
| 115 | case 6: l2|=((unsigned long)(*(--(c))))<<16; \ | ||
| 116 | case 5: l2|=((unsigned long)(*(--(c))))<<24; \ | ||
| 117 | case 4: l1 =((unsigned long)(*(--(c)))) ; \ | ||
| 118 | case 3: l1|=((unsigned long)(*(--(c))))<< 8; \ | ||
| 119 | case 2: l1|=((unsigned long)(*(--(c))))<<16; \ | ||
| 120 | case 1: l1|=((unsigned long)(*(--(c))))<<24; \ | ||
| 121 | } \ | ||
| 122 | } | ||
| 123 | |||
| 124 | /* NOTE - c is not incremented as per l2n */ | ||
| 125 | #define l2nn(l1,l2,c,n) { \ | ||
| 126 | c+=n; \ | ||
| 127 | switch (n) { \ | ||
| 128 | case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \ | ||
| 129 | case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \ | ||
| 130 | case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \ | ||
| 131 | case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \ | ||
| 132 | case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \ | ||
| 133 | case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \ | ||
| 134 | case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \ | ||
| 135 | case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \ | ||
| 136 | } \ | ||
| 137 | } | ||
| 138 | |||
| 139 | #undef n2l | ||
| 140 | #define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \ | ||
| 141 | l|=((unsigned long)(*((c)++)))<<16L, \ | ||
| 142 | l|=((unsigned long)(*((c)++)))<< 8L, \ | ||
| 143 | l|=((unsigned long)(*((c)++)))) | ||
| 144 | |||
| 145 | #undef l2n | ||
| 146 | #define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \ | ||
| 147 | *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ | ||
| 148 | *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ | ||
| 149 | *((c)++)=(unsigned char)(((l) )&0xff)) | ||
| 150 | |||
| 151 | #if defined(WIN32) | ||
| 152 | #define ROTL(a,n) (_lrotl(a,n)) | ||
| 153 | #else | ||
| 154 | #define ROTL(a,n) ((((a)<<(n))&0xffffffffL)|((a)>>(32-(n)))) | ||
| 155 | #endif | ||
| 156 | |||
| 157 | #define C_M 0x3fc | ||
| 158 | #define C_0 22L | ||
| 159 | #define C_1 14L | ||
| 160 | #define C_2 6L | ||
| 161 | #define C_3 2L /* left shift */ | ||
| 162 | |||
| 163 | /* The rotate has an extra 16 added to it to help the x86 asm */ | ||
| 164 | #if defined(CAST_PTR) | ||
| 165 | #define E_CAST(n,key,L,R,OP1,OP2,OP3) \ | ||
| 166 | { \ | ||
| 167 | int i; \ | ||
| 168 | t=(key[n*2] OP1 R)&0xffffffffL; \ | ||
| 169 | i=key[n*2+1]; \ | ||
| 170 | t=ROTL(t,i); \ | ||
| 171 | L^= (((((*(CAST_LONG *)((unsigned char *) \ | ||
| 172 | CAST_S_table0+((t>>C_2)&C_M)) OP2 \ | ||
| 173 | *(CAST_LONG *)((unsigned char *) \ | ||
| 174 | CAST_S_table1+((t<<C_3)&C_M)))&0xffffffffL) OP3 \ | ||
| 175 | *(CAST_LONG *)((unsigned char *) \ | ||
| 176 | CAST_S_table2+((t>>C_0)&C_M)))&0xffffffffL) OP1 \ | ||
| 177 | *(CAST_LONG *)((unsigned char *) \ | ||
| 178 | CAST_S_table3+((t>>C_1)&C_M)))&0xffffffffL; \ | ||
| 179 | } | ||
| 180 | #elif defined(CAST_PTR2) | ||
| 181 | #define E_CAST(n,key,L,R,OP1,OP2,OP3) \ | ||
| 182 | { \ | ||
| 183 | int i; \ | ||
| 184 | CAST_LONG u,v,w; \ | ||
| 185 | w=(key[n*2] OP1 R)&0xffffffffL; \ | ||
| 186 | i=key[n*2+1]; \ | ||
| 187 | w=ROTL(w,i); \ | ||
| 188 | u=w>>C_2; \ | ||
| 189 | v=w<<C_3; \ | ||
| 190 | u&=C_M; \ | ||
| 191 | v&=C_M; \ | ||
| 192 | t= *(CAST_LONG *)((unsigned char *)CAST_S_table0+u); \ | ||
| 193 | u=w>>C_0; \ | ||
| 194 | t=(t OP2 *(CAST_LONG *)((unsigned char *)CAST_S_table1+v))&0xffffffffL;\ | ||
| 195 | v=w>>C_1; \ | ||
| 196 | u&=C_M; \ | ||
| 197 | v&=C_M; \ | ||
| 198 | t=(t OP3 *(CAST_LONG *)((unsigned char *)CAST_S_table2+u)&0xffffffffL);\ | ||
| 199 | t=(t OP1 *(CAST_LONG *)((unsigned char *)CAST_S_table3+v)&0xffffffffL);\ | ||
| 200 | L^=(t&0xffffffff); \ | ||
| 201 | } | ||
| 202 | #else | ||
| 203 | #define E_CAST(n,key,L,R,OP1,OP2,OP3) \ | ||
| 204 | { \ | ||
| 205 | CAST_LONG a,b,c,d; \ | ||
| 206 | t=(key[n*2] OP1 R)&0xffffffff; \ | ||
| 207 | t=ROTL(t,(key[n*2+1])); \ | ||
| 208 | a=CAST_S_table0[(t>> 8)&0xff]; \ | ||
| 209 | b=CAST_S_table1[(t )&0xff]; \ | ||
| 210 | c=CAST_S_table2[(t>>24)&0xff]; \ | ||
| 211 | d=CAST_S_table3[(t>>16)&0xff]; \ | ||
| 212 | L^=(((((a OP2 b)&0xffffffffL) OP3 c)&0xffffffffL) OP1 d)&0xffffffffL; \ | ||
| 213 | } | ||
| 214 | #endif | ||
| 215 | |||
| 216 | extern CAST_LONG CAST_S_table0[256]; | ||
| 217 | extern CAST_LONG CAST_S_table1[256]; | ||
| 218 | extern CAST_LONG CAST_S_table2[256]; | ||
| 219 | extern CAST_LONG CAST_S_table3[256]; | ||
| 220 | extern CAST_LONG CAST_S_table4[256]; | ||
| 221 | extern CAST_LONG CAST_S_table5[256]; | ||
| 222 | extern CAST_LONG CAST_S_table6[256]; | ||
| 223 | extern CAST_LONG CAST_S_table7[256]; | ||
| 224 | |||
diff --git a/src/lib/libcrypto/cast/cast_s.h b/src/lib/libcrypto/cast/cast_s.h new file mode 100644 index 0000000000..8fe0152149 --- /dev/null +++ b/src/lib/libcrypto/cast/cast_s.h | |||
| @@ -0,0 +1,585 @@ | |||
| 1 | /* crypto/cast/cast_s.h */ | ||
| 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 | CAST_LONG CAST_S_table0[256]={ | ||
| 59 | 0x30fb40d4,0x9fa0ff0b,0x6beccd2f,0x3f258c7a, | ||
| 60 | 0x1e213f2f,0x9c004dd3,0x6003e540,0xcf9fc949, | ||
| 61 | 0xbfd4af27,0x88bbbdb5,0xe2034090,0x98d09675, | ||
| 62 | 0x6e63a0e0,0x15c361d2,0xc2e7661d,0x22d4ff8e, | ||
| 63 | 0x28683b6f,0xc07fd059,0xff2379c8,0x775f50e2, | ||
| 64 | 0x43c340d3,0xdf2f8656,0x887ca41a,0xa2d2bd2d, | ||
| 65 | 0xa1c9e0d6,0x346c4819,0x61b76d87,0x22540f2f, | ||
| 66 | 0x2abe32e1,0xaa54166b,0x22568e3a,0xa2d341d0, | ||
| 67 | 0x66db40c8,0xa784392f,0x004dff2f,0x2db9d2de, | ||
| 68 | 0x97943fac,0x4a97c1d8,0x527644b7,0xb5f437a7, | ||
| 69 | 0xb82cbaef,0xd751d159,0x6ff7f0ed,0x5a097a1f, | ||
| 70 | 0x827b68d0,0x90ecf52e,0x22b0c054,0xbc8e5935, | ||
| 71 | 0x4b6d2f7f,0x50bb64a2,0xd2664910,0xbee5812d, | ||
| 72 | 0xb7332290,0xe93b159f,0xb48ee411,0x4bff345d, | ||
| 73 | 0xfd45c240,0xad31973f,0xc4f6d02e,0x55fc8165, | ||
| 74 | 0xd5b1caad,0xa1ac2dae,0xa2d4b76d,0xc19b0c50, | ||
| 75 | 0x882240f2,0x0c6e4f38,0xa4e4bfd7,0x4f5ba272, | ||
| 76 | 0x564c1d2f,0xc59c5319,0xb949e354,0xb04669fe, | ||
| 77 | 0xb1b6ab8a,0xc71358dd,0x6385c545,0x110f935d, | ||
| 78 | 0x57538ad5,0x6a390493,0xe63d37e0,0x2a54f6b3, | ||
| 79 | 0x3a787d5f,0x6276a0b5,0x19a6fcdf,0x7a42206a, | ||
| 80 | 0x29f9d4d5,0xf61b1891,0xbb72275e,0xaa508167, | ||
| 81 | 0x38901091,0xc6b505eb,0x84c7cb8c,0x2ad75a0f, | ||
| 82 | 0x874a1427,0xa2d1936b,0x2ad286af,0xaa56d291, | ||
| 83 | 0xd7894360,0x425c750d,0x93b39e26,0x187184c9, | ||
| 84 | 0x6c00b32d,0x73e2bb14,0xa0bebc3c,0x54623779, | ||
| 85 | 0x64459eab,0x3f328b82,0x7718cf82,0x59a2cea6, | ||
| 86 | 0x04ee002e,0x89fe78e6,0x3fab0950,0x325ff6c2, | ||
| 87 | 0x81383f05,0x6963c5c8,0x76cb5ad6,0xd49974c9, | ||
| 88 | 0xca180dcf,0x380782d5,0xc7fa5cf6,0x8ac31511, | ||
| 89 | 0x35e79e13,0x47da91d0,0xf40f9086,0xa7e2419e, | ||
| 90 | 0x31366241,0x051ef495,0xaa573b04,0x4a805d8d, | ||
| 91 | 0x548300d0,0x00322a3c,0xbf64cddf,0xba57a68e, | ||
| 92 | 0x75c6372b,0x50afd341,0xa7c13275,0x915a0bf5, | ||
| 93 | 0x6b54bfab,0x2b0b1426,0xab4cc9d7,0x449ccd82, | ||
| 94 | 0xf7fbf265,0xab85c5f3,0x1b55db94,0xaad4e324, | ||
| 95 | 0xcfa4bd3f,0x2deaa3e2,0x9e204d02,0xc8bd25ac, | ||
| 96 | 0xeadf55b3,0xd5bd9e98,0xe31231b2,0x2ad5ad6c, | ||
| 97 | 0x954329de,0xadbe4528,0xd8710f69,0xaa51c90f, | ||
| 98 | 0xaa786bf6,0x22513f1e,0xaa51a79b,0x2ad344cc, | ||
| 99 | 0x7b5a41f0,0xd37cfbad,0x1b069505,0x41ece491, | ||
| 100 | 0xb4c332e6,0x032268d4,0xc9600acc,0xce387e6d, | ||
| 101 | 0xbf6bb16c,0x6a70fb78,0x0d03d9c9,0xd4df39de, | ||
| 102 | 0xe01063da,0x4736f464,0x5ad328d8,0xb347cc96, | ||
| 103 | 0x75bb0fc3,0x98511bfb,0x4ffbcc35,0xb58bcf6a, | ||
| 104 | 0xe11f0abc,0xbfc5fe4a,0xa70aec10,0xac39570a, | ||
| 105 | 0x3f04442f,0x6188b153,0xe0397a2e,0x5727cb79, | ||
| 106 | 0x9ceb418f,0x1cacd68d,0x2ad37c96,0x0175cb9d, | ||
| 107 | 0xc69dff09,0xc75b65f0,0xd9db40d8,0xec0e7779, | ||
| 108 | 0x4744ead4,0xb11c3274,0xdd24cb9e,0x7e1c54bd, | ||
| 109 | 0xf01144f9,0xd2240eb1,0x9675b3fd,0xa3ac3755, | ||
| 110 | 0xd47c27af,0x51c85f4d,0x56907596,0xa5bb15e6, | ||
| 111 | 0x580304f0,0xca042cf1,0x011a37ea,0x8dbfaadb, | ||
| 112 | 0x35ba3e4a,0x3526ffa0,0xc37b4d09,0xbc306ed9, | ||
| 113 | 0x98a52666,0x5648f725,0xff5e569d,0x0ced63d0, | ||
| 114 | 0x7c63b2cf,0x700b45e1,0xd5ea50f1,0x85a92872, | ||
| 115 | 0xaf1fbda7,0xd4234870,0xa7870bf3,0x2d3b4d79, | ||
| 116 | 0x42e04198,0x0cd0ede7,0x26470db8,0xf881814c, | ||
| 117 | 0x474d6ad7,0x7c0c5e5c,0xd1231959,0x381b7298, | ||
| 118 | 0xf5d2f4db,0xab838653,0x6e2f1e23,0x83719c9e, | ||
| 119 | 0xbd91e046,0x9a56456e,0xdc39200c,0x20c8c571, | ||
| 120 | 0x962bda1c,0xe1e696ff,0xb141ab08,0x7cca89b9, | ||
| 121 | 0x1a69e783,0x02cc4843,0xa2f7c579,0x429ef47d, | ||
| 122 | 0x427b169c,0x5ac9f049,0xdd8f0f00,0x5c8165bf, | ||
| 123 | }; | ||
| 124 | CAST_LONG CAST_S_table1[256]={ | ||
| 125 | 0x1f201094,0xef0ba75b,0x69e3cf7e,0x393f4380, | ||
| 126 | 0xfe61cf7a,0xeec5207a,0x55889c94,0x72fc0651, | ||
| 127 | 0xada7ef79,0x4e1d7235,0xd55a63ce,0xde0436ba, | ||
| 128 | 0x99c430ef,0x5f0c0794,0x18dcdb7d,0xa1d6eff3, | ||
| 129 | 0xa0b52f7b,0x59e83605,0xee15b094,0xe9ffd909, | ||
| 130 | 0xdc440086,0xef944459,0xba83ccb3,0xe0c3cdfb, | ||
| 131 | 0xd1da4181,0x3b092ab1,0xf997f1c1,0xa5e6cf7b, | ||
| 132 | 0x01420ddb,0xe4e7ef5b,0x25a1ff41,0xe180f806, | ||
| 133 | 0x1fc41080,0x179bee7a,0xd37ac6a9,0xfe5830a4, | ||
| 134 | 0x98de8b7f,0x77e83f4e,0x79929269,0x24fa9f7b, | ||
| 135 | 0xe113c85b,0xacc40083,0xd7503525,0xf7ea615f, | ||
| 136 | 0x62143154,0x0d554b63,0x5d681121,0xc866c359, | ||
| 137 | 0x3d63cf73,0xcee234c0,0xd4d87e87,0x5c672b21, | ||
| 138 | 0x071f6181,0x39f7627f,0x361e3084,0xe4eb573b, | ||
| 139 | 0x602f64a4,0xd63acd9c,0x1bbc4635,0x9e81032d, | ||
| 140 | 0x2701f50c,0x99847ab4,0xa0e3df79,0xba6cf38c, | ||
| 141 | 0x10843094,0x2537a95e,0xf46f6ffe,0xa1ff3b1f, | ||
| 142 | 0x208cfb6a,0x8f458c74,0xd9e0a227,0x4ec73a34, | ||
| 143 | 0xfc884f69,0x3e4de8df,0xef0e0088,0x3559648d, | ||
| 144 | 0x8a45388c,0x1d804366,0x721d9bfd,0xa58684bb, | ||
| 145 | 0xe8256333,0x844e8212,0x128d8098,0xfed33fb4, | ||
| 146 | 0xce280ae1,0x27e19ba5,0xd5a6c252,0xe49754bd, | ||
| 147 | 0xc5d655dd,0xeb667064,0x77840b4d,0xa1b6a801, | ||
| 148 | 0x84db26a9,0xe0b56714,0x21f043b7,0xe5d05860, | ||
| 149 | 0x54f03084,0x066ff472,0xa31aa153,0xdadc4755, | ||
| 150 | 0xb5625dbf,0x68561be6,0x83ca6b94,0x2d6ed23b, | ||
| 151 | 0xeccf01db,0xa6d3d0ba,0xb6803d5c,0xaf77a709, | ||
| 152 | 0x33b4a34c,0x397bc8d6,0x5ee22b95,0x5f0e5304, | ||
| 153 | 0x81ed6f61,0x20e74364,0xb45e1378,0xde18639b, | ||
| 154 | 0x881ca122,0xb96726d1,0x8049a7e8,0x22b7da7b, | ||
| 155 | 0x5e552d25,0x5272d237,0x79d2951c,0xc60d894c, | ||
| 156 | 0x488cb402,0x1ba4fe5b,0xa4b09f6b,0x1ca815cf, | ||
| 157 | 0xa20c3005,0x8871df63,0xb9de2fcb,0x0cc6c9e9, | ||
| 158 | 0x0beeff53,0xe3214517,0xb4542835,0x9f63293c, | ||
| 159 | 0xee41e729,0x6e1d2d7c,0x50045286,0x1e6685f3, | ||
| 160 | 0xf33401c6,0x30a22c95,0x31a70850,0x60930f13, | ||
| 161 | 0x73f98417,0xa1269859,0xec645c44,0x52c877a9, | ||
| 162 | 0xcdff33a6,0xa02b1741,0x7cbad9a2,0x2180036f, | ||
| 163 | 0x50d99c08,0xcb3f4861,0xc26bd765,0x64a3f6ab, | ||
| 164 | 0x80342676,0x25a75e7b,0xe4e6d1fc,0x20c710e6, | ||
| 165 | 0xcdf0b680,0x17844d3b,0x31eef84d,0x7e0824e4, | ||
| 166 | 0x2ccb49eb,0x846a3bae,0x8ff77888,0xee5d60f6, | ||
| 167 | 0x7af75673,0x2fdd5cdb,0xa11631c1,0x30f66f43, | ||
| 168 | 0xb3faec54,0x157fd7fa,0xef8579cc,0xd152de58, | ||
| 169 | 0xdb2ffd5e,0x8f32ce19,0x306af97a,0x02f03ef8, | ||
| 170 | 0x99319ad5,0xc242fa0f,0xa7e3ebb0,0xc68e4906, | ||
| 171 | 0xb8da230c,0x80823028,0xdcdef3c8,0xd35fb171, | ||
| 172 | 0x088a1bc8,0xbec0c560,0x61a3c9e8,0xbca8f54d, | ||
| 173 | 0xc72feffa,0x22822e99,0x82c570b4,0xd8d94e89, | ||
| 174 | 0x8b1c34bc,0x301e16e6,0x273be979,0xb0ffeaa6, | ||
| 175 | 0x61d9b8c6,0x00b24869,0xb7ffce3f,0x08dc283b, | ||
| 176 | 0x43daf65a,0xf7e19798,0x7619b72f,0x8f1c9ba4, | ||
| 177 | 0xdc8637a0,0x16a7d3b1,0x9fc393b7,0xa7136eeb, | ||
| 178 | 0xc6bcc63e,0x1a513742,0xef6828bc,0x520365d6, | ||
| 179 | 0x2d6a77ab,0x3527ed4b,0x821fd216,0x095c6e2e, | ||
| 180 | 0xdb92f2fb,0x5eea29cb,0x145892f5,0x91584f7f, | ||
| 181 | 0x5483697b,0x2667a8cc,0x85196048,0x8c4bacea, | ||
| 182 | 0x833860d4,0x0d23e0f9,0x6c387e8a,0x0ae6d249, | ||
| 183 | 0xb284600c,0xd835731d,0xdcb1c647,0xac4c56ea, | ||
| 184 | 0x3ebd81b3,0x230eabb0,0x6438bc87,0xf0b5b1fa, | ||
| 185 | 0x8f5ea2b3,0xfc184642,0x0a036b7a,0x4fb089bd, | ||
| 186 | 0x649da589,0xa345415e,0x5c038323,0x3e5d3bb9, | ||
| 187 | 0x43d79572,0x7e6dd07c,0x06dfdf1e,0x6c6cc4ef, | ||
| 188 | 0x7160a539,0x73bfbe70,0x83877605,0x4523ecf1, | ||
| 189 | }; | ||
| 190 | CAST_LONG CAST_S_table2[256]={ | ||
| 191 | 0x8defc240,0x25fa5d9f,0xeb903dbf,0xe810c907, | ||
| 192 | 0x47607fff,0x369fe44b,0x8c1fc644,0xaececa90, | ||
| 193 | 0xbeb1f9bf,0xeefbcaea,0xe8cf1950,0x51df07ae, | ||
| 194 | 0x920e8806,0xf0ad0548,0xe13c8d83,0x927010d5, | ||
| 195 | 0x11107d9f,0x07647db9,0xb2e3e4d4,0x3d4f285e, | ||
| 196 | 0xb9afa820,0xfade82e0,0xa067268b,0x8272792e, | ||
| 197 | 0x553fb2c0,0x489ae22b,0xd4ef9794,0x125e3fbc, | ||
| 198 | 0x21fffcee,0x825b1bfd,0x9255c5ed,0x1257a240, | ||
| 199 | 0x4e1a8302,0xbae07fff,0x528246e7,0x8e57140e, | ||
| 200 | 0x3373f7bf,0x8c9f8188,0xa6fc4ee8,0xc982b5a5, | ||
| 201 | 0xa8c01db7,0x579fc264,0x67094f31,0xf2bd3f5f, | ||
| 202 | 0x40fff7c1,0x1fb78dfc,0x8e6bd2c1,0x437be59b, | ||
| 203 | 0x99b03dbf,0xb5dbc64b,0x638dc0e6,0x55819d99, | ||
| 204 | 0xa197c81c,0x4a012d6e,0xc5884a28,0xccc36f71, | ||
| 205 | 0xb843c213,0x6c0743f1,0x8309893c,0x0feddd5f, | ||
| 206 | 0x2f7fe850,0xd7c07f7e,0x02507fbf,0x5afb9a04, | ||
| 207 | 0xa747d2d0,0x1651192e,0xaf70bf3e,0x58c31380, | ||
| 208 | 0x5f98302e,0x727cc3c4,0x0a0fb402,0x0f7fef82, | ||
| 209 | 0x8c96fdad,0x5d2c2aae,0x8ee99a49,0x50da88b8, | ||
| 210 | 0x8427f4a0,0x1eac5790,0x796fb449,0x8252dc15, | ||
| 211 | 0xefbd7d9b,0xa672597d,0xada840d8,0x45f54504, | ||
| 212 | 0xfa5d7403,0xe83ec305,0x4f91751a,0x925669c2, | ||
| 213 | 0x23efe941,0xa903f12e,0x60270df2,0x0276e4b6, | ||
| 214 | 0x94fd6574,0x927985b2,0x8276dbcb,0x02778176, | ||
| 215 | 0xf8af918d,0x4e48f79e,0x8f616ddf,0xe29d840e, | ||
| 216 | 0x842f7d83,0x340ce5c8,0x96bbb682,0x93b4b148, | ||
| 217 | 0xef303cab,0x984faf28,0x779faf9b,0x92dc560d, | ||
| 218 | 0x224d1e20,0x8437aa88,0x7d29dc96,0x2756d3dc, | ||
| 219 | 0x8b907cee,0xb51fd240,0xe7c07ce3,0xe566b4a1, | ||
| 220 | 0xc3e9615e,0x3cf8209d,0x6094d1e3,0xcd9ca341, | ||
| 221 | 0x5c76460e,0x00ea983b,0xd4d67881,0xfd47572c, | ||
| 222 | 0xf76cedd9,0xbda8229c,0x127dadaa,0x438a074e, | ||
| 223 | 0x1f97c090,0x081bdb8a,0x93a07ebe,0xb938ca15, | ||
| 224 | 0x97b03cff,0x3dc2c0f8,0x8d1ab2ec,0x64380e51, | ||
| 225 | 0x68cc7bfb,0xd90f2788,0x12490181,0x5de5ffd4, | ||
| 226 | 0xdd7ef86a,0x76a2e214,0xb9a40368,0x925d958f, | ||
| 227 | 0x4b39fffa,0xba39aee9,0xa4ffd30b,0xfaf7933b, | ||
| 228 | 0x6d498623,0x193cbcfa,0x27627545,0x825cf47a, | ||
| 229 | 0x61bd8ba0,0xd11e42d1,0xcead04f4,0x127ea392, | ||
| 230 | 0x10428db7,0x8272a972,0x9270c4a8,0x127de50b, | ||
| 231 | 0x285ba1c8,0x3c62f44f,0x35c0eaa5,0xe805d231, | ||
| 232 | 0x428929fb,0xb4fcdf82,0x4fb66a53,0x0e7dc15b, | ||
| 233 | 0x1f081fab,0x108618ae,0xfcfd086d,0xf9ff2889, | ||
| 234 | 0x694bcc11,0x236a5cae,0x12deca4d,0x2c3f8cc5, | ||
| 235 | 0xd2d02dfe,0xf8ef5896,0xe4cf52da,0x95155b67, | ||
| 236 | 0x494a488c,0xb9b6a80c,0x5c8f82bc,0x89d36b45, | ||
| 237 | 0x3a609437,0xec00c9a9,0x44715253,0x0a874b49, | ||
| 238 | 0xd773bc40,0x7c34671c,0x02717ef6,0x4feb5536, | ||
| 239 | 0xa2d02fff,0xd2bf60c4,0xd43f03c0,0x50b4ef6d, | ||
| 240 | 0x07478cd1,0x006e1888,0xa2e53f55,0xb9e6d4bc, | ||
| 241 | 0xa2048016,0x97573833,0xd7207d67,0xde0f8f3d, | ||
| 242 | 0x72f87b33,0xabcc4f33,0x7688c55d,0x7b00a6b0, | ||
| 243 | 0x947b0001,0x570075d2,0xf9bb88f8,0x8942019e, | ||
| 244 | 0x4264a5ff,0x856302e0,0x72dbd92b,0xee971b69, | ||
| 245 | 0x6ea22fde,0x5f08ae2b,0xaf7a616d,0xe5c98767, | ||
| 246 | 0xcf1febd2,0x61efc8c2,0xf1ac2571,0xcc8239c2, | ||
| 247 | 0x67214cb8,0xb1e583d1,0xb7dc3e62,0x7f10bdce, | ||
| 248 | 0xf90a5c38,0x0ff0443d,0x606e6dc6,0x60543a49, | ||
| 249 | 0x5727c148,0x2be98a1d,0x8ab41738,0x20e1be24, | ||
| 250 | 0xaf96da0f,0x68458425,0x99833be5,0x600d457d, | ||
| 251 | 0x282f9350,0x8334b362,0xd91d1120,0x2b6d8da0, | ||
| 252 | 0x642b1e31,0x9c305a00,0x52bce688,0x1b03588a, | ||
| 253 | 0xf7baefd5,0x4142ed9c,0xa4315c11,0x83323ec5, | ||
| 254 | 0xdfef4636,0xa133c501,0xe9d3531c,0xee353783, | ||
| 255 | }; | ||
| 256 | CAST_LONG CAST_S_table3[256]={ | ||
| 257 | 0x9db30420,0x1fb6e9de,0xa7be7bef,0xd273a298, | ||
| 258 | 0x4a4f7bdb,0x64ad8c57,0x85510443,0xfa020ed1, | ||
| 259 | 0x7e287aff,0xe60fb663,0x095f35a1,0x79ebf120, | ||
| 260 | 0xfd059d43,0x6497b7b1,0xf3641f63,0x241e4adf, | ||
| 261 | 0x28147f5f,0x4fa2b8cd,0xc9430040,0x0cc32220, | ||
| 262 | 0xfdd30b30,0xc0a5374f,0x1d2d00d9,0x24147b15, | ||
| 263 | 0xee4d111a,0x0fca5167,0x71ff904c,0x2d195ffe, | ||
| 264 | 0x1a05645f,0x0c13fefe,0x081b08ca,0x05170121, | ||
| 265 | 0x80530100,0xe83e5efe,0xac9af4f8,0x7fe72701, | ||
| 266 | 0xd2b8ee5f,0x06df4261,0xbb9e9b8a,0x7293ea25, | ||
| 267 | 0xce84ffdf,0xf5718801,0x3dd64b04,0xa26f263b, | ||
| 268 | 0x7ed48400,0x547eebe6,0x446d4ca0,0x6cf3d6f5, | ||
| 269 | 0x2649abdf,0xaea0c7f5,0x36338cc1,0x503f7e93, | ||
| 270 | 0xd3772061,0x11b638e1,0x72500e03,0xf80eb2bb, | ||
| 271 | 0xabe0502e,0xec8d77de,0x57971e81,0xe14f6746, | ||
| 272 | 0xc9335400,0x6920318f,0x081dbb99,0xffc304a5, | ||
| 273 | 0x4d351805,0x7f3d5ce3,0xa6c866c6,0x5d5bcca9, | ||
| 274 | 0xdaec6fea,0x9f926f91,0x9f46222f,0x3991467d, | ||
| 275 | 0xa5bf6d8e,0x1143c44f,0x43958302,0xd0214eeb, | ||
| 276 | 0x022083b8,0x3fb6180c,0x18f8931e,0x281658e6, | ||
| 277 | 0x26486e3e,0x8bd78a70,0x7477e4c1,0xb506e07c, | ||
| 278 | 0xf32d0a25,0x79098b02,0xe4eabb81,0x28123b23, | ||
| 279 | 0x69dead38,0x1574ca16,0xdf871b62,0x211c40b7, | ||
| 280 | 0xa51a9ef9,0x0014377b,0x041e8ac8,0x09114003, | ||
| 281 | 0xbd59e4d2,0xe3d156d5,0x4fe876d5,0x2f91a340, | ||
| 282 | 0x557be8de,0x00eae4a7,0x0ce5c2ec,0x4db4bba6, | ||
| 283 | 0xe756bdff,0xdd3369ac,0xec17b035,0x06572327, | ||
| 284 | 0x99afc8b0,0x56c8c391,0x6b65811c,0x5e146119, | ||
| 285 | 0x6e85cb75,0xbe07c002,0xc2325577,0x893ff4ec, | ||
| 286 | 0x5bbfc92d,0xd0ec3b25,0xb7801ab7,0x8d6d3b24, | ||
| 287 | 0x20c763ef,0xc366a5fc,0x9c382880,0x0ace3205, | ||
| 288 | 0xaac9548a,0xeca1d7c7,0x041afa32,0x1d16625a, | ||
| 289 | 0x6701902c,0x9b757a54,0x31d477f7,0x9126b031, | ||
| 290 | 0x36cc6fdb,0xc70b8b46,0xd9e66a48,0x56e55a79, | ||
| 291 | 0x026a4ceb,0x52437eff,0x2f8f76b4,0x0df980a5, | ||
| 292 | 0x8674cde3,0xedda04eb,0x17a9be04,0x2c18f4df, | ||
| 293 | 0xb7747f9d,0xab2af7b4,0xefc34d20,0x2e096b7c, | ||
| 294 | 0x1741a254,0xe5b6a035,0x213d42f6,0x2c1c7c26, | ||
| 295 | 0x61c2f50f,0x6552daf9,0xd2c231f8,0x25130f69, | ||
| 296 | 0xd8167fa2,0x0418f2c8,0x001a96a6,0x0d1526ab, | ||
| 297 | 0x63315c21,0x5e0a72ec,0x49bafefd,0x187908d9, | ||
| 298 | 0x8d0dbd86,0x311170a7,0x3e9b640c,0xcc3e10d7, | ||
| 299 | 0xd5cad3b6,0x0caec388,0xf73001e1,0x6c728aff, | ||
| 300 | 0x71eae2a1,0x1f9af36e,0xcfcbd12f,0xc1de8417, | ||
| 301 | 0xac07be6b,0xcb44a1d8,0x8b9b0f56,0x013988c3, | ||
| 302 | 0xb1c52fca,0xb4be31cd,0xd8782806,0x12a3a4e2, | ||
| 303 | 0x6f7de532,0x58fd7eb6,0xd01ee900,0x24adffc2, | ||
| 304 | 0xf4990fc5,0x9711aac5,0x001d7b95,0x82e5e7d2, | ||
| 305 | 0x109873f6,0x00613096,0xc32d9521,0xada121ff, | ||
| 306 | 0x29908415,0x7fbb977f,0xaf9eb3db,0x29c9ed2a, | ||
| 307 | 0x5ce2a465,0xa730f32c,0xd0aa3fe8,0x8a5cc091, | ||
| 308 | 0xd49e2ce7,0x0ce454a9,0xd60acd86,0x015f1919, | ||
| 309 | 0x77079103,0xdea03af6,0x78a8565e,0xdee356df, | ||
| 310 | 0x21f05cbe,0x8b75e387,0xb3c50651,0xb8a5c3ef, | ||
| 311 | 0xd8eeb6d2,0xe523be77,0xc2154529,0x2f69efdf, | ||
| 312 | 0xafe67afb,0xf470c4b2,0xf3e0eb5b,0xd6cc9876, | ||
| 313 | 0x39e4460c,0x1fda8538,0x1987832f,0xca007367, | ||
| 314 | 0xa99144f8,0x296b299e,0x492fc295,0x9266beab, | ||
| 315 | 0xb5676e69,0x9bd3ddda,0xdf7e052f,0xdb25701c, | ||
| 316 | 0x1b5e51ee,0xf65324e6,0x6afce36c,0x0316cc04, | ||
| 317 | 0x8644213e,0xb7dc59d0,0x7965291f,0xccd6fd43, | ||
| 318 | 0x41823979,0x932bcdf6,0xb657c34d,0x4edfd282, | ||
| 319 | 0x7ae5290c,0x3cb9536b,0x851e20fe,0x9833557e, | ||
| 320 | 0x13ecf0b0,0xd3ffb372,0x3f85c5c1,0x0aef7ed2, | ||
| 321 | }; | ||
| 322 | CAST_LONG CAST_S_table4[256]={ | ||
| 323 | 0x7ec90c04,0x2c6e74b9,0x9b0e66df,0xa6337911, | ||
| 324 | 0xb86a7fff,0x1dd358f5,0x44dd9d44,0x1731167f, | ||
| 325 | 0x08fbf1fa,0xe7f511cc,0xd2051b00,0x735aba00, | ||
| 326 | 0x2ab722d8,0x386381cb,0xacf6243a,0x69befd7a, | ||
| 327 | 0xe6a2e77f,0xf0c720cd,0xc4494816,0xccf5c180, | ||
| 328 | 0x38851640,0x15b0a848,0xe68b18cb,0x4caadeff, | ||
| 329 | 0x5f480a01,0x0412b2aa,0x259814fc,0x41d0efe2, | ||
| 330 | 0x4e40b48d,0x248eb6fb,0x8dba1cfe,0x41a99b02, | ||
| 331 | 0x1a550a04,0xba8f65cb,0x7251f4e7,0x95a51725, | ||
| 332 | 0xc106ecd7,0x97a5980a,0xc539b9aa,0x4d79fe6a, | ||
| 333 | 0xf2f3f763,0x68af8040,0xed0c9e56,0x11b4958b, | ||
| 334 | 0xe1eb5a88,0x8709e6b0,0xd7e07156,0x4e29fea7, | ||
| 335 | 0x6366e52d,0x02d1c000,0xc4ac8e05,0x9377f571, | ||
| 336 | 0x0c05372a,0x578535f2,0x2261be02,0xd642a0c9, | ||
| 337 | 0xdf13a280,0x74b55bd2,0x682199c0,0xd421e5ec, | ||
| 338 | 0x53fb3ce8,0xc8adedb3,0x28a87fc9,0x3d959981, | ||
| 339 | 0x5c1ff900,0xfe38d399,0x0c4eff0b,0x062407ea, | ||
| 340 | 0xaa2f4fb1,0x4fb96976,0x90c79505,0xb0a8a774, | ||
| 341 | 0xef55a1ff,0xe59ca2c2,0xa6b62d27,0xe66a4263, | ||
| 342 | 0xdf65001f,0x0ec50966,0xdfdd55bc,0x29de0655, | ||
| 343 | 0x911e739a,0x17af8975,0x32c7911c,0x89f89468, | ||
| 344 | 0x0d01e980,0x524755f4,0x03b63cc9,0x0cc844b2, | ||
| 345 | 0xbcf3f0aa,0x87ac36e9,0xe53a7426,0x01b3d82b, | ||
| 346 | 0x1a9e7449,0x64ee2d7e,0xcddbb1da,0x01c94910, | ||
| 347 | 0xb868bf80,0x0d26f3fd,0x9342ede7,0x04a5c284, | ||
| 348 | 0x636737b6,0x50f5b616,0xf24766e3,0x8eca36c1, | ||
| 349 | 0x136e05db,0xfef18391,0xfb887a37,0xd6e7f7d4, | ||
| 350 | 0xc7fb7dc9,0x3063fcdf,0xb6f589de,0xec2941da, | ||
| 351 | 0x26e46695,0xb7566419,0xf654efc5,0xd08d58b7, | ||
| 352 | 0x48925401,0xc1bacb7f,0xe5ff550f,0xb6083049, | ||
| 353 | 0x5bb5d0e8,0x87d72e5a,0xab6a6ee1,0x223a66ce, | ||
| 354 | 0xc62bf3cd,0x9e0885f9,0x68cb3e47,0x086c010f, | ||
| 355 | 0xa21de820,0xd18b69de,0xf3f65777,0xfa02c3f6, | ||
| 356 | 0x407edac3,0xcbb3d550,0x1793084d,0xb0d70eba, | ||
| 357 | 0x0ab378d5,0xd951fb0c,0xded7da56,0x4124bbe4, | ||
| 358 | 0x94ca0b56,0x0f5755d1,0xe0e1e56e,0x6184b5be, | ||
| 359 | 0x580a249f,0x94f74bc0,0xe327888e,0x9f7b5561, | ||
| 360 | 0xc3dc0280,0x05687715,0x646c6bd7,0x44904db3, | ||
| 361 | 0x66b4f0a3,0xc0f1648a,0x697ed5af,0x49e92ff6, | ||
| 362 | 0x309e374f,0x2cb6356a,0x85808573,0x4991f840, | ||
| 363 | 0x76f0ae02,0x083be84d,0x28421c9a,0x44489406, | ||
| 364 | 0x736e4cb8,0xc1092910,0x8bc95fc6,0x7d869cf4, | ||
| 365 | 0x134f616f,0x2e77118d,0xb31b2be1,0xaa90b472, | ||
| 366 | 0x3ca5d717,0x7d161bba,0x9cad9010,0xaf462ba2, | ||
| 367 | 0x9fe459d2,0x45d34559,0xd9f2da13,0xdbc65487, | ||
| 368 | 0xf3e4f94e,0x176d486f,0x097c13ea,0x631da5c7, | ||
| 369 | 0x445f7382,0x175683f4,0xcdc66a97,0x70be0288, | ||
| 370 | 0xb3cdcf72,0x6e5dd2f3,0x20936079,0x459b80a5, | ||
| 371 | 0xbe60e2db,0xa9c23101,0xeba5315c,0x224e42f2, | ||
| 372 | 0x1c5c1572,0xf6721b2c,0x1ad2fff3,0x8c25404e, | ||
| 373 | 0x324ed72f,0x4067b7fd,0x0523138e,0x5ca3bc78, | ||
| 374 | 0xdc0fd66e,0x75922283,0x784d6b17,0x58ebb16e, | ||
| 375 | 0x44094f85,0x3f481d87,0xfcfeae7b,0x77b5ff76, | ||
| 376 | 0x8c2302bf,0xaaf47556,0x5f46b02a,0x2b092801, | ||
| 377 | 0x3d38f5f7,0x0ca81f36,0x52af4a8a,0x66d5e7c0, | ||
| 378 | 0xdf3b0874,0x95055110,0x1b5ad7a8,0xf61ed5ad, | ||
| 379 | 0x6cf6e479,0x20758184,0xd0cefa65,0x88f7be58, | ||
| 380 | 0x4a046826,0x0ff6f8f3,0xa09c7f70,0x5346aba0, | ||
| 381 | 0x5ce96c28,0xe176eda3,0x6bac307f,0x376829d2, | ||
| 382 | 0x85360fa9,0x17e3fe2a,0x24b79767,0xf5a96b20, | ||
| 383 | 0xd6cd2595,0x68ff1ebf,0x7555442c,0xf19f06be, | ||
| 384 | 0xf9e0659a,0xeeb9491d,0x34010718,0xbb30cab8, | ||
| 385 | 0xe822fe15,0x88570983,0x750e6249,0xda627e55, | ||
| 386 | 0x5e76ffa8,0xb1534546,0x6d47de08,0xefe9e7d4, | ||
| 387 | }; | ||
| 388 | CAST_LONG CAST_S_table5[256]={ | ||
| 389 | 0xf6fa8f9d,0x2cac6ce1,0x4ca34867,0xe2337f7c, | ||
| 390 | 0x95db08e7,0x016843b4,0xeced5cbc,0x325553ac, | ||
| 391 | 0xbf9f0960,0xdfa1e2ed,0x83f0579d,0x63ed86b9, | ||
| 392 | 0x1ab6a6b8,0xde5ebe39,0xf38ff732,0x8989b138, | ||
| 393 | 0x33f14961,0xc01937bd,0xf506c6da,0xe4625e7e, | ||
| 394 | 0xa308ea99,0x4e23e33c,0x79cbd7cc,0x48a14367, | ||
| 395 | 0xa3149619,0xfec94bd5,0xa114174a,0xeaa01866, | ||
| 396 | 0xa084db2d,0x09a8486f,0xa888614a,0x2900af98, | ||
| 397 | 0x01665991,0xe1992863,0xc8f30c60,0x2e78ef3c, | ||
| 398 | 0xd0d51932,0xcf0fec14,0xf7ca07d2,0xd0a82072, | ||
| 399 | 0xfd41197e,0x9305a6b0,0xe86be3da,0x74bed3cd, | ||
| 400 | 0x372da53c,0x4c7f4448,0xdab5d440,0x6dba0ec3, | ||
| 401 | 0x083919a7,0x9fbaeed9,0x49dbcfb0,0x4e670c53, | ||
| 402 | 0x5c3d9c01,0x64bdb941,0x2c0e636a,0xba7dd9cd, | ||
| 403 | 0xea6f7388,0xe70bc762,0x35f29adb,0x5c4cdd8d, | ||
| 404 | 0xf0d48d8c,0xb88153e2,0x08a19866,0x1ae2eac8, | ||
| 405 | 0x284caf89,0xaa928223,0x9334be53,0x3b3a21bf, | ||
| 406 | 0x16434be3,0x9aea3906,0xefe8c36e,0xf890cdd9, | ||
| 407 | 0x80226dae,0xc340a4a3,0xdf7e9c09,0xa694a807, | ||
| 408 | 0x5b7c5ecc,0x221db3a6,0x9a69a02f,0x68818a54, | ||
| 409 | 0xceb2296f,0x53c0843a,0xfe893655,0x25bfe68a, | ||
| 410 | 0xb4628abc,0xcf222ebf,0x25ac6f48,0xa9a99387, | ||
| 411 | 0x53bddb65,0xe76ffbe7,0xe967fd78,0x0ba93563, | ||
| 412 | 0x8e342bc1,0xe8a11be9,0x4980740d,0xc8087dfc, | ||
| 413 | 0x8de4bf99,0xa11101a0,0x7fd37975,0xda5a26c0, | ||
| 414 | 0xe81f994f,0x9528cd89,0xfd339fed,0xb87834bf, | ||
| 415 | 0x5f04456d,0x22258698,0xc9c4c83b,0x2dc156be, | ||
| 416 | 0x4f628daa,0x57f55ec5,0xe2220abe,0xd2916ebf, | ||
| 417 | 0x4ec75b95,0x24f2c3c0,0x42d15d99,0xcd0d7fa0, | ||
| 418 | 0x7b6e27ff,0xa8dc8af0,0x7345c106,0xf41e232f, | ||
| 419 | 0x35162386,0xe6ea8926,0x3333b094,0x157ec6f2, | ||
| 420 | 0x372b74af,0x692573e4,0xe9a9d848,0xf3160289, | ||
| 421 | 0x3a62ef1d,0xa787e238,0xf3a5f676,0x74364853, | ||
| 422 | 0x20951063,0x4576698d,0xb6fad407,0x592af950, | ||
| 423 | 0x36f73523,0x4cfb6e87,0x7da4cec0,0x6c152daa, | ||
| 424 | 0xcb0396a8,0xc50dfe5d,0xfcd707ab,0x0921c42f, | ||
| 425 | 0x89dff0bb,0x5fe2be78,0x448f4f33,0x754613c9, | ||
| 426 | 0x2b05d08d,0x48b9d585,0xdc049441,0xc8098f9b, | ||
| 427 | 0x7dede786,0xc39a3373,0x42410005,0x6a091751, | ||
| 428 | 0x0ef3c8a6,0x890072d6,0x28207682,0xa9a9f7be, | ||
| 429 | 0xbf32679d,0xd45b5b75,0xb353fd00,0xcbb0e358, | ||
| 430 | 0x830f220a,0x1f8fb214,0xd372cf08,0xcc3c4a13, | ||
| 431 | 0x8cf63166,0x061c87be,0x88c98f88,0x6062e397, | ||
| 432 | 0x47cf8e7a,0xb6c85283,0x3cc2acfb,0x3fc06976, | ||
| 433 | 0x4e8f0252,0x64d8314d,0xda3870e3,0x1e665459, | ||
| 434 | 0xc10908f0,0x513021a5,0x6c5b68b7,0x822f8aa0, | ||
| 435 | 0x3007cd3e,0x74719eef,0xdc872681,0x073340d4, | ||
| 436 | 0x7e432fd9,0x0c5ec241,0x8809286c,0xf592d891, | ||
| 437 | 0x08a930f6,0x957ef305,0xb7fbffbd,0xc266e96f, | ||
| 438 | 0x6fe4ac98,0xb173ecc0,0xbc60b42a,0x953498da, | ||
| 439 | 0xfba1ae12,0x2d4bd736,0x0f25faab,0xa4f3fceb, | ||
| 440 | 0xe2969123,0x257f0c3d,0x9348af49,0x361400bc, | ||
| 441 | 0xe8816f4a,0x3814f200,0xa3f94043,0x9c7a54c2, | ||
| 442 | 0xbc704f57,0xda41e7f9,0xc25ad33a,0x54f4a084, | ||
| 443 | 0xb17f5505,0x59357cbe,0xedbd15c8,0x7f97c5ab, | ||
| 444 | 0xba5ac7b5,0xb6f6deaf,0x3a479c3a,0x5302da25, | ||
| 445 | 0x653d7e6a,0x54268d49,0x51a477ea,0x5017d55b, | ||
| 446 | 0xd7d25d88,0x44136c76,0x0404a8c8,0xb8e5a121, | ||
| 447 | 0xb81a928a,0x60ed5869,0x97c55b96,0xeaec991b, | ||
| 448 | 0x29935913,0x01fdb7f1,0x088e8dfa,0x9ab6f6f5, | ||
| 449 | 0x3b4cbf9f,0x4a5de3ab,0xe6051d35,0xa0e1d855, | ||
| 450 | 0xd36b4cf1,0xf544edeb,0xb0e93524,0xbebb8fbd, | ||
| 451 | 0xa2d762cf,0x49c92f54,0x38b5f331,0x7128a454, | ||
| 452 | 0x48392905,0xa65b1db8,0x851c97bd,0xd675cf2f, | ||
| 453 | }; | ||
| 454 | CAST_LONG CAST_S_table6[256]={ | ||
| 455 | 0x85e04019,0x332bf567,0x662dbfff,0xcfc65693, | ||
| 456 | 0x2a8d7f6f,0xab9bc912,0xde6008a1,0x2028da1f, | ||
| 457 | 0x0227bce7,0x4d642916,0x18fac300,0x50f18b82, | ||
| 458 | 0x2cb2cb11,0xb232e75c,0x4b3695f2,0xb28707de, | ||
| 459 | 0xa05fbcf6,0xcd4181e9,0xe150210c,0xe24ef1bd, | ||
| 460 | 0xb168c381,0xfde4e789,0x5c79b0d8,0x1e8bfd43, | ||
| 461 | 0x4d495001,0x38be4341,0x913cee1d,0x92a79c3f, | ||
| 462 | 0x089766be,0xbaeeadf4,0x1286becf,0xb6eacb19, | ||
| 463 | 0x2660c200,0x7565bde4,0x64241f7a,0x8248dca9, | ||
| 464 | 0xc3b3ad66,0x28136086,0x0bd8dfa8,0x356d1cf2, | ||
| 465 | 0x107789be,0xb3b2e9ce,0x0502aa8f,0x0bc0351e, | ||
| 466 | 0x166bf52a,0xeb12ff82,0xe3486911,0xd34d7516, | ||
| 467 | 0x4e7b3aff,0x5f43671b,0x9cf6e037,0x4981ac83, | ||
| 468 | 0x334266ce,0x8c9341b7,0xd0d854c0,0xcb3a6c88, | ||
| 469 | 0x47bc2829,0x4725ba37,0xa66ad22b,0x7ad61f1e, | ||
| 470 | 0x0c5cbafa,0x4437f107,0xb6e79962,0x42d2d816, | ||
| 471 | 0x0a961288,0xe1a5c06e,0x13749e67,0x72fc081a, | ||
| 472 | 0xb1d139f7,0xf9583745,0xcf19df58,0xbec3f756, | ||
| 473 | 0xc06eba30,0x07211b24,0x45c28829,0xc95e317f, | ||
| 474 | 0xbc8ec511,0x38bc46e9,0xc6e6fa14,0xbae8584a, | ||
| 475 | 0xad4ebc46,0x468f508b,0x7829435f,0xf124183b, | ||
| 476 | 0x821dba9f,0xaff60ff4,0xea2c4e6d,0x16e39264, | ||
| 477 | 0x92544a8b,0x009b4fc3,0xaba68ced,0x9ac96f78, | ||
| 478 | 0x06a5b79a,0xb2856e6e,0x1aec3ca9,0xbe838688, | ||
| 479 | 0x0e0804e9,0x55f1be56,0xe7e5363b,0xb3a1f25d, | ||
| 480 | 0xf7debb85,0x61fe033c,0x16746233,0x3c034c28, | ||
| 481 | 0xda6d0c74,0x79aac56c,0x3ce4e1ad,0x51f0c802, | ||
| 482 | 0x98f8f35a,0x1626a49f,0xeed82b29,0x1d382fe3, | ||
| 483 | 0x0c4fb99a,0xbb325778,0x3ec6d97b,0x6e77a6a9, | ||
| 484 | 0xcb658b5c,0xd45230c7,0x2bd1408b,0x60c03eb7, | ||
| 485 | 0xb9068d78,0xa33754f4,0xf430c87d,0xc8a71302, | ||
| 486 | 0xb96d8c32,0xebd4e7be,0xbe8b9d2d,0x7979fb06, | ||
| 487 | 0xe7225308,0x8b75cf77,0x11ef8da4,0xe083c858, | ||
| 488 | 0x8d6b786f,0x5a6317a6,0xfa5cf7a0,0x5dda0033, | ||
| 489 | 0xf28ebfb0,0xf5b9c310,0xa0eac280,0x08b9767a, | ||
| 490 | 0xa3d9d2b0,0x79d34217,0x021a718d,0x9ac6336a, | ||
| 491 | 0x2711fd60,0x438050e3,0x069908a8,0x3d7fedc4, | ||
| 492 | 0x826d2bef,0x4eeb8476,0x488dcf25,0x36c9d566, | ||
| 493 | 0x28e74e41,0xc2610aca,0x3d49a9cf,0xbae3b9df, | ||
| 494 | 0xb65f8de6,0x92aeaf64,0x3ac7d5e6,0x9ea80509, | ||
| 495 | 0xf22b017d,0xa4173f70,0xdd1e16c3,0x15e0d7f9, | ||
| 496 | 0x50b1b887,0x2b9f4fd5,0x625aba82,0x6a017962, | ||
| 497 | 0x2ec01b9c,0x15488aa9,0xd716e740,0x40055a2c, | ||
| 498 | 0x93d29a22,0xe32dbf9a,0x058745b9,0x3453dc1e, | ||
| 499 | 0xd699296e,0x496cff6f,0x1c9f4986,0xdfe2ed07, | ||
| 500 | 0xb87242d1,0x19de7eae,0x053e561a,0x15ad6f8c, | ||
| 501 | 0x66626c1c,0x7154c24c,0xea082b2a,0x93eb2939, | ||
| 502 | 0x17dcb0f0,0x58d4f2ae,0x9ea294fb,0x52cf564c, | ||
| 503 | 0x9883fe66,0x2ec40581,0x763953c3,0x01d6692e, | ||
| 504 | 0xd3a0c108,0xa1e7160e,0xe4f2dfa6,0x693ed285, | ||
| 505 | 0x74904698,0x4c2b0edd,0x4f757656,0x5d393378, | ||
| 506 | 0xa132234f,0x3d321c5d,0xc3f5e194,0x4b269301, | ||
| 507 | 0xc79f022f,0x3c997e7e,0x5e4f9504,0x3ffafbbd, | ||
| 508 | 0x76f7ad0e,0x296693f4,0x3d1fce6f,0xc61e45be, | ||
| 509 | 0xd3b5ab34,0xf72bf9b7,0x1b0434c0,0x4e72b567, | ||
| 510 | 0x5592a33d,0xb5229301,0xcfd2a87f,0x60aeb767, | ||
| 511 | 0x1814386b,0x30bcc33d,0x38a0c07d,0xfd1606f2, | ||
| 512 | 0xc363519b,0x589dd390,0x5479f8e6,0x1cb8d647, | ||
| 513 | 0x97fd61a9,0xea7759f4,0x2d57539d,0x569a58cf, | ||
| 514 | 0xe84e63ad,0x462e1b78,0x6580f87e,0xf3817914, | ||
| 515 | 0x91da55f4,0x40a230f3,0xd1988f35,0xb6e318d2, | ||
| 516 | 0x3ffa50bc,0x3d40f021,0xc3c0bdae,0x4958c24c, | ||
| 517 | 0x518f36b2,0x84b1d370,0x0fedce83,0x878ddada, | ||
| 518 | 0xf2a279c7,0x94e01be8,0x90716f4b,0x954b8aa3, | ||
| 519 | }; | ||
| 520 | CAST_LONG CAST_S_table7[256]={ | ||
| 521 | 0xe216300d,0xbbddfffc,0xa7ebdabd,0x35648095, | ||
| 522 | 0x7789f8b7,0xe6c1121b,0x0e241600,0x052ce8b5, | ||
| 523 | 0x11a9cfb0,0xe5952f11,0xece7990a,0x9386d174, | ||
| 524 | 0x2a42931c,0x76e38111,0xb12def3a,0x37ddddfc, | ||
| 525 | 0xde9adeb1,0x0a0cc32c,0xbe197029,0x84a00940, | ||
| 526 | 0xbb243a0f,0xb4d137cf,0xb44e79f0,0x049eedfd, | ||
| 527 | 0x0b15a15d,0x480d3168,0x8bbbde5a,0x669ded42, | ||
| 528 | 0xc7ece831,0x3f8f95e7,0x72df191b,0x7580330d, | ||
| 529 | 0x94074251,0x5c7dcdfa,0xabbe6d63,0xaa402164, | ||
| 530 | 0xb301d40a,0x02e7d1ca,0x53571dae,0x7a3182a2, | ||
| 531 | 0x12a8ddec,0xfdaa335d,0x176f43e8,0x71fb46d4, | ||
| 532 | 0x38129022,0xce949ad4,0xb84769ad,0x965bd862, | ||
| 533 | 0x82f3d055,0x66fb9767,0x15b80b4e,0x1d5b47a0, | ||
| 534 | 0x4cfde06f,0xc28ec4b8,0x57e8726e,0x647a78fc, | ||
| 535 | 0x99865d44,0x608bd593,0x6c200e03,0x39dc5ff6, | ||
| 536 | 0x5d0b00a3,0xae63aff2,0x7e8bd632,0x70108c0c, | ||
| 537 | 0xbbd35049,0x2998df04,0x980cf42a,0x9b6df491, | ||
| 538 | 0x9e7edd53,0x06918548,0x58cb7e07,0x3b74ef2e, | ||
| 539 | 0x522fffb1,0xd24708cc,0x1c7e27cd,0xa4eb215b, | ||
| 540 | 0x3cf1d2e2,0x19b47a38,0x424f7618,0x35856039, | ||
| 541 | 0x9d17dee7,0x27eb35e6,0xc9aff67b,0x36baf5b8, | ||
| 542 | 0x09c467cd,0xc18910b1,0xe11dbf7b,0x06cd1af8, | ||
| 543 | 0x7170c608,0x2d5e3354,0xd4de495a,0x64c6d006, | ||
| 544 | 0xbcc0c62c,0x3dd00db3,0x708f8f34,0x77d51b42, | ||
| 545 | 0x264f620f,0x24b8d2bf,0x15c1b79e,0x46a52564, | ||
| 546 | 0xf8d7e54e,0x3e378160,0x7895cda5,0x859c15a5, | ||
| 547 | 0xe6459788,0xc37bc75f,0xdb07ba0c,0x0676a3ab, | ||
| 548 | 0x7f229b1e,0x31842e7b,0x24259fd7,0xf8bef472, | ||
| 549 | 0x835ffcb8,0x6df4c1f2,0x96f5b195,0xfd0af0fc, | ||
| 550 | 0xb0fe134c,0xe2506d3d,0x4f9b12ea,0xf215f225, | ||
| 551 | 0xa223736f,0x9fb4c428,0x25d04979,0x34c713f8, | ||
| 552 | 0xc4618187,0xea7a6e98,0x7cd16efc,0x1436876c, | ||
| 553 | 0xf1544107,0xbedeee14,0x56e9af27,0xa04aa441, | ||
| 554 | 0x3cf7c899,0x92ecbae6,0xdd67016d,0x151682eb, | ||
| 555 | 0xa842eedf,0xfdba60b4,0xf1907b75,0x20e3030f, | ||
| 556 | 0x24d8c29e,0xe139673b,0xefa63fb8,0x71873054, | ||
| 557 | 0xb6f2cf3b,0x9f326442,0xcb15a4cc,0xb01a4504, | ||
| 558 | 0xf1e47d8d,0x844a1be5,0xbae7dfdc,0x42cbda70, | ||
| 559 | 0xcd7dae0a,0x57e85b7a,0xd53f5af6,0x20cf4d8c, | ||
| 560 | 0xcea4d428,0x79d130a4,0x3486ebfb,0x33d3cddc, | ||
| 561 | 0x77853b53,0x37effcb5,0xc5068778,0xe580b3e6, | ||
| 562 | 0x4e68b8f4,0xc5c8b37e,0x0d809ea2,0x398feb7c, | ||
| 563 | 0x132a4f94,0x43b7950e,0x2fee7d1c,0x223613bd, | ||
| 564 | 0xdd06caa2,0x37df932b,0xc4248289,0xacf3ebc3, | ||
| 565 | 0x5715f6b7,0xef3478dd,0xf267616f,0xc148cbe4, | ||
| 566 | 0x9052815e,0x5e410fab,0xb48a2465,0x2eda7fa4, | ||
| 567 | 0xe87b40e4,0xe98ea084,0x5889e9e1,0xefd390fc, | ||
| 568 | 0xdd07d35b,0xdb485694,0x38d7e5b2,0x57720101, | ||
| 569 | 0x730edebc,0x5b643113,0x94917e4f,0x503c2fba, | ||
| 570 | 0x646f1282,0x7523d24a,0xe0779695,0xf9c17a8f, | ||
| 571 | 0x7a5b2121,0xd187b896,0x29263a4d,0xba510cdf, | ||
| 572 | 0x81f47c9f,0xad1163ed,0xea7b5965,0x1a00726e, | ||
| 573 | 0x11403092,0x00da6d77,0x4a0cdd61,0xad1f4603, | ||
| 574 | 0x605bdfb0,0x9eedc364,0x22ebe6a8,0xcee7d28a, | ||
| 575 | 0xa0e736a0,0x5564a6b9,0x10853209,0xc7eb8f37, | ||
| 576 | 0x2de705ca,0x8951570f,0xdf09822b,0xbd691a6c, | ||
| 577 | 0xaa12e4f2,0x87451c0f,0xe0f6a27a,0x3ada4819, | ||
| 578 | 0x4cf1764f,0x0d771c2b,0x67cdb156,0x350d8384, | ||
| 579 | 0x5938fa0f,0x42399ef3,0x36997b07,0x0e84093d, | ||
| 580 | 0x4aa93e61,0x8360d87b,0x1fa98b0c,0x1149382c, | ||
| 581 | 0xe97625a5,0x0614d1b7,0x0e25244b,0x0c768347, | ||
| 582 | 0x589e8d82,0x0d2059d1,0xa466bb1e,0xf8da0a82, | ||
| 583 | 0x04f19130,0xba6e4ec0,0x99265164,0x1ee7230d, | ||
| 584 | 0x50b2ad80,0xeaee6801,0x8db2a283,0xea8bf59e, | ||
| 585 | }; | ||
diff --git a/src/lib/libcrypto/conf/conf.h b/src/lib/libcrypto/conf/conf.h new file mode 100644 index 0000000000..1446226a16 --- /dev/null +++ b/src/lib/libcrypto/conf/conf.h | |||
| @@ -0,0 +1,114 @@ | |||
| 1 | /* crypto/conf/conf.h */ | ||
| 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 | #ifndef HEADER_CONF_H | ||
| 60 | #define HEADER_CONF_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #include "stack.h" | ||
| 67 | #include "lhash.h" | ||
| 68 | |||
| 69 | typedef struct | ||
| 70 | { | ||
| 71 | char *section; | ||
| 72 | char *name; | ||
| 73 | char *value; | ||
| 74 | } CONF_VALUE; | ||
| 75 | |||
| 76 | #ifndef NOPROTO | ||
| 77 | |||
| 78 | LHASH *CONF_load(LHASH *conf,char *file,long *eline); | ||
| 79 | STACK *CONF_get_section(LHASH *conf,char *section); | ||
| 80 | char *CONF_get_string(LHASH *conf,char *group,char *name); | ||
| 81 | long CONF_get_number(LHASH *conf,char *group,char *name); | ||
| 82 | void CONF_free(LHASH *conf); | ||
| 83 | void ERR_load_CONF_strings(void ); | ||
| 84 | |||
| 85 | #else | ||
| 86 | |||
| 87 | LHASH *CONF_load(); | ||
| 88 | STACK *CONF_get_section(); | ||
| 89 | char *CONF_get_string(); | ||
| 90 | long CONF_get_number(); | ||
| 91 | void CONF_free(); | ||
| 92 | void ERR_load_CONF_strings(); | ||
| 93 | |||
| 94 | #endif | ||
| 95 | |||
| 96 | /* BEGIN ERROR CODES */ | ||
| 97 | /* Error codes for the CONF functions. */ | ||
| 98 | |||
| 99 | /* Function codes. */ | ||
| 100 | #define CONF_F_CONF_LOAD 100 | ||
| 101 | #define CONF_F_STR_COPY 101 | ||
| 102 | |||
| 103 | /* Reason codes. */ | ||
| 104 | #define CONF_R_MISSING_CLOSE_SQUARE_BRACKET 100 | ||
| 105 | #define CONF_R_MISSING_EQUAL_SIGN 101 | ||
| 106 | #define CONF_R_NO_CLOSE_BRACE 102 | ||
| 107 | #define CONF_R_UNABLE_TO_CREATE_NEW_SECTION 103 | ||
| 108 | #define CONF_R_VARIABLE_HAS_NO_VALUE 104 | ||
| 109 | |||
| 110 | #ifdef __cplusplus | ||
| 111 | } | ||
| 112 | #endif | ||
| 113 | #endif | ||
| 114 | |||
diff --git a/src/lib/libcrypto/conf/conf_err.c b/src/lib/libcrypto/conf/conf_err.c new file mode 100644 index 0000000000..a8db8f266f --- /dev/null +++ b/src/lib/libcrypto/conf/conf_err.c | |||
| @@ -0,0 +1,96 @@ | |||
| 1 | /* lib/conf/conf_err.c */ | ||
| 2 | /* Copyright (C) 1995-1997 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 | #include <stdio.h> | ||
| 59 | #include "err.h" | ||
| 60 | #include "conf.h" | ||
| 61 | |||
| 62 | /* BEGIN ERROR CODES */ | ||
| 63 | #ifndef NO_ERR | ||
| 64 | static ERR_STRING_DATA CONF_str_functs[]= | ||
| 65 | { | ||
| 66 | {ERR_PACK(0,CONF_F_CONF_LOAD,0), "CONF_load"}, | ||
| 67 | {ERR_PACK(0,CONF_F_STR_COPY,0), "STR_COPY"}, | ||
| 68 | {0,NULL}, | ||
| 69 | }; | ||
| 70 | |||
| 71 | static ERR_STRING_DATA CONF_str_reasons[]= | ||
| 72 | { | ||
| 73 | {CONF_R_MISSING_CLOSE_SQUARE_BRACKET ,"missing close square bracket"}, | ||
| 74 | {CONF_R_MISSING_EQUAL_SIGN ,"missing equal sign"}, | ||
| 75 | {CONF_R_NO_CLOSE_BRACE ,"no close brace"}, | ||
| 76 | {CONF_R_UNABLE_TO_CREATE_NEW_SECTION ,"unable to create new section"}, | ||
| 77 | {CONF_R_VARIABLE_HAS_NO_VALUE ,"variable has no value"}, | ||
| 78 | {0,NULL}, | ||
| 79 | }; | ||
| 80 | |||
| 81 | #endif | ||
| 82 | |||
| 83 | void ERR_load_CONF_strings() | ||
| 84 | { | ||
| 85 | static int init=1; | ||
| 86 | |||
| 87 | if (init); | ||
| 88 | {; | ||
| 89 | init=0; | ||
| 90 | #ifndef NO_ERR | ||
| 91 | ERR_load_strings(ERR_LIB_CONF,CONF_str_functs); | ||
| 92 | ERR_load_strings(ERR_LIB_CONF,CONF_str_reasons); | ||
| 93 | #endif | ||
| 94 | |||
| 95 | } | ||
| 96 | } | ||
diff --git a/src/lib/libcrypto/conf/keysets.pl b/src/lib/libcrypto/conf/keysets.pl new file mode 100644 index 0000000000..e40fed0ca1 --- /dev/null +++ b/src/lib/libcrypto/conf/keysets.pl | |||
| @@ -0,0 +1,61 @@ | |||
| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | $NUMBER=0x01; | ||
| 4 | $UPPER=0x02; | ||
| 5 | $LOWER=0x04; | ||
| 6 | $EOF=0x08; | ||
| 7 | $WS=0x10; | ||
| 8 | $ESC=0x20; | ||
| 9 | $QUOTE=0x40; | ||
| 10 | $COMMENT=0x80; | ||
| 11 | $UNDER=0x100; | ||
| 12 | |||
| 13 | foreach (0 .. 127) | ||
| 14 | { | ||
| 15 | $v=0; | ||
| 16 | $c=sprintf("%c",$_); | ||
| 17 | $v|=$NUMBER if ($c =~ /[0-9]/); | ||
| 18 | $v|=$UPPER if ($c =~ /[A-Z]/); | ||
| 19 | $v|=$LOWER if ($c =~ /[a-z]/); | ||
| 20 | $v|=$UNDER if ($c =~ /_/); | ||
| 21 | $v|=$WS if ($c =~ / \t\r\n/); | ||
| 22 | $v|=$ESC if ($c =~ /\\/); | ||
| 23 | $v|=$QUOTE if ($c =~ /['`"]/); | ||
| 24 | $v|=$COMMENT if ($c =~ /\#/); | ||
| 25 | $v|=$EOF if ($c =~ /\0/); | ||
| 26 | |||
| 27 | push(@V,$v); | ||
| 28 | } | ||
| 29 | |||
| 30 | print <<"EOF"; | ||
| 31 | #define CONF_NUMBER $NUMBER | ||
| 32 | #define CONF_UPPER $UPPER | ||
| 33 | #define CONF_LOWER $LOWER | ||
| 34 | #define CONF_EOF $EOF | ||
| 35 | #define CONF_WS $WS | ||
| 36 | #define CONF_ESC $ESC | ||
| 37 | #define CONF_QUOTE $QUOTE | ||
| 38 | #define CONF_COMMENT $COMMENT | ||
| 39 | #define CONF_ALPHA (CONF_UPPER|CONF_LOWER) | ||
| 40 | #define CONF_ALPHA_NUMERIC (CONF_ALPHA|CONF_NUMBER|CONF_UNDER) | ||
| 41 | #define CONF_UNDER $UNDER | ||
| 42 | |||
| 43 | #define IS_COMMENT(a) (CONF_COMMENT&(CONF_type[(a)&0x7f])) | ||
| 44 | #define IS_EOF(a) ((a) == '\\0') | ||
| 45 | #define IS_ESC(a) ((a) == '\\\\') | ||
| 46 | #define IS_NUMER(a) (CONF_type[(a)&0x7f]&CONF_NUMBER) | ||
| 47 | #define IS_WS(a) (CONF_type[(a)&0x7f]&CONF_WS) | ||
| 48 | #define IS_ALPHA_NUMERIC(a) (CONF_type[(a)&0x7f]&CONF_ALPHA_NUMERIC) | ||
| 49 | #define IS_QUOTE(a) (CONF_type[(a)&0x7f]&CONF_QUOTE) | ||
| 50 | |||
| 51 | EOF | ||
| 52 | |||
| 53 | print "static unsigned short CONF_type[128]={"; | ||
| 54 | |||
| 55 | for ($i=0; $i<128; $i++) | ||
| 56 | { | ||
| 57 | print "\n\t" if ($i % 8) == 0; | ||
| 58 | printf "0x%03X,",$V[$i]; | ||
| 59 | } | ||
| 60 | |||
| 61 | print "\n\t};\n"; | ||
diff --git a/src/lib/libcrypto/conf/ssleay.cnf b/src/lib/libcrypto/conf/ssleay.cnf new file mode 100644 index 0000000000..ed33af601e --- /dev/null +++ b/src/lib/libcrypto/conf/ssleay.cnf | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | # | ||
| 2 | # This is a test configuration file for use in SSLeay etc... | ||
| 3 | # | ||
| 4 | |||
| 5 | init = 5 | ||
| 6 | in\#it1 =10 | ||
| 7 | init2='10' | ||
| 8 | init3='10\'' | ||
| 9 | init4="10'" | ||
| 10 | init5='='10\'' again' | ||
| 11 | |||
| 12 | SSLeay::version = 0.5.0 | ||
| 13 | |||
| 14 | [genrsa] | ||
| 15 | default_bits = 512 | ||
| 16 | SSLEAY::version = 0.5.0 | ||
| 17 | |||
| 18 | [gendh] | ||
| 19 | default_bits = 512 | ||
| 20 | def_generator = 2 | ||
| 21 | |||
| 22 | [s_client] | ||
| 23 | cipher1 = DES_CBC_MD5:DES_CBC_SHA:DES_EDE_SHA:RC4_MD5\ | ||
| 24 | cipher2 = 'DES_CBC_MD5 DES_CBC_SHA DES_EDE_SHA RC4_MD5' | ||
| 25 | cipher3 = "DES_CBC_MD5 DES_CBC_SHA DES_EDE_SHA RC4_MD5" | ||
| 26 | cipher4 = DES_CBC_MD5 DES_CBC_SHA DES_EDE_SHA RC4_MD5 | ||
| 27 | |||
| 28 | [ default ] | ||
| 29 | cert_dir = $ENV::HOME/.ca_certs | ||
| 30 | |||
| 31 | HOME = /tmp/eay | ||
| 32 | |||
| 33 | tmp_cert_dir = $HOME/.ca_certs | ||
| 34 | tmp2_cert_dir = thisis$(HOME)stuff | ||
| 35 | |||
| 36 | LOGNAME = Eric Young (home=$HOME) | ||
| 37 | |||
| 38 | [ special ] | ||
| 39 | |||
| 40 | H=$HOME | ||
| 41 | H=$default::HOME | ||
| 42 | H=$ENV::HOME | ||
| 43 | # | ||
| 44 | # SSLeay example configuration file. | ||
| 45 | # This is mostly being used for generation of certificate requests. | ||
| 46 | # | ||
| 47 | |||
| 48 | RANDFILE = $HOME/.rand | ||
| 49 | |||
| 50 | [ req ] | ||
| 51 | default_bits = 512 | ||
| 52 | default_keyfile = privkey.pem | ||
| 53 | |||
| 54 | Attribute_type_1 = countryName | ||
| 55 | Attribute_text_1 = Country Name (2 letter code) | ||
| 56 | Attribute_default_1 = AU | ||
| 57 | |||
| 58 | Attribute_type_2 = stateOrProvinceName | ||
| 59 | Attribute_text_2 = State or Province Name (full name) | ||
| 60 | Attribute_default_2 = Queensland | ||
| 61 | |||
| 62 | Attribute_type_3 = localityName | ||
| 63 | Attribute_text_3 = Locality Name (eg, city) | ||
| 64 | |||
| 65 | Attribute_type_4 = organizationName | ||
| 66 | Attribute_text_4 = Organization Name (eg, company) | ||
| 67 | Attribute_default_4 = Mincom Pty Ltd | ||
| 68 | |||
| 69 | Attribute_type_5 = organizationalUnitName | ||
| 70 | Attribute_text_5 = Organizational Unit Name (eg, section) | ||
| 71 | Attribute_default_5 = TR | ||
| 72 | |||
| 73 | Attribute_type_6 = commonName | ||
| 74 | Attribute_text_6 = Common Name (eg, YOUR name) | ||
| 75 | |||
| 76 | Attribute_type_7 = emailAddress | ||
| 77 | Attribute_text_7 = Email Address | ||
| 78 | |||
diff --git a/src/lib/libcrypto/cpt_err.c b/src/lib/libcrypto/cpt_err.c new file mode 100644 index 0000000000..ea3c135d39 --- /dev/null +++ b/src/lib/libcrypto/cpt_err.c | |||
| @@ -0,0 +1,86 @@ | |||
| 1 | /* lib/crypto/crypto_err.c */ | ||
| 2 | /* Copyright (C) 1995-1997 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 | #include <stdio.h> | ||
| 59 | #include "err.h" | ||
| 60 | #include "crypto.h" | ||
| 61 | |||
| 62 | /* BEGIN ERROR CODES */ | ||
| 63 | #ifndef NO_ERR | ||
| 64 | static ERR_STRING_DATA CRYPTO_str_functs[]= | ||
| 65 | { | ||
| 66 | {ERR_PACK(0,CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,0), "CRYPTO_get_ex_new_index"}, | ||
| 67 | {ERR_PACK(0,CRYPTO_F_CRYPTO_GET_NEW_LOCKID,0), "CRYPTO_get_new_lockid"}, | ||
| 68 | {ERR_PACK(0,CRYPTO_F_CRYPTO_SET_EX_DATA,0), "CRYPTO_set_ex_data"}, | ||
| 69 | {0,NULL}, | ||
| 70 | }; | ||
| 71 | |||
| 72 | #endif | ||
| 73 | |||
| 74 | void ERR_load_CRYPTO_strings() | ||
| 75 | { | ||
| 76 | static int init=1; | ||
| 77 | |||
| 78 | if (init); | ||
| 79 | {; | ||
| 80 | init=0; | ||
| 81 | #ifndef NO_ERR | ||
| 82 | ERR_load_strings(ERR_LIB_CRYPTO,CRYPTO_str_functs); | ||
| 83 | #endif | ||
| 84 | |||
| 85 | } | ||
| 86 | } | ||
diff --git a/src/lib/libcrypto/cryptlib.c b/src/lib/libcrypto/cryptlib.c new file mode 100644 index 0000000000..9a7e80b7f8 --- /dev/null +++ b/src/lib/libcrypto/cryptlib.c | |||
| @@ -0,0 +1,307 @@ | |||
| 1 | /* crypto/cryptlib.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 <string.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "crypto.h" | ||
| 63 | #include "date.h" | ||
| 64 | |||
| 65 | #if defined(WIN32) || defined(WIN16) | ||
| 66 | static double SSLeay_MSVC5_hack=0.0; /* and for VC1.5 */ | ||
| 67 | #endif | ||
| 68 | |||
| 69 | /* real #defines in crypto.h, keep these upto date */ | ||
| 70 | static char* lock_names[CRYPTO_NUM_LOCKS] = | ||
| 71 | { | ||
| 72 | "<<ERROR>>", | ||
| 73 | "err", | ||
| 74 | "err_hash", | ||
| 75 | "x509", | ||
| 76 | "x509_info", | ||
| 77 | "x509_pkey", | ||
| 78 | "x509_crl", | ||
| 79 | "x509_req", | ||
| 80 | "dsa", | ||
| 81 | "rsa", | ||
| 82 | "evp_pkey", | ||
| 83 | "x509_store", | ||
| 84 | "ssl_ctx", | ||
| 85 | "ssl_cert", | ||
| 86 | "ssl_session", | ||
| 87 | "ssl", | ||
| 88 | "rand", | ||
| 89 | "debug_malloc", | ||
| 90 | "BIO", | ||
| 91 | "bio_gethostbyname", | ||
| 92 | "RSA_blinding", | ||
| 93 | }; | ||
| 94 | |||
| 95 | static STACK *app_locks=NULL; | ||
| 96 | |||
| 97 | #ifndef NOPROTO | ||
| 98 | static void (MS_FAR *locking_callback)(int mode,int type, | ||
| 99 | char *file,int line)=NULL; | ||
| 100 | static int (MS_FAR *add_lock_callback)(int *pointer,int amount, | ||
| 101 | int type,char *file,int line)=NULL; | ||
| 102 | static unsigned long (MS_FAR *id_callback)(void)=NULL; | ||
| 103 | #else | ||
| 104 | static void (MS_FAR *locking_callback)()=NULL; | ||
| 105 | static int (MS_FAR *add_lock_callback)()=NULL; | ||
| 106 | static unsigned long (MS_FAR *id_callback)()=NULL; | ||
| 107 | #endif | ||
| 108 | |||
| 109 | int CRYPTO_get_new_lockid(name) | ||
| 110 | char *name; | ||
| 111 | { | ||
| 112 | char *str; | ||
| 113 | int i; | ||
| 114 | |||
| 115 | /* A hack to make Visual C++ 5.0 work correctly when linking as | ||
| 116 | * a DLL using /MT. Without this, the application cannot use | ||
| 117 | * and floating point printf's. | ||
| 118 | * It also seems to be needed for Visual C 1.5 (win16) */ | ||
| 119 | #if defined(WIN32) || defined(WIN16) | ||
| 120 | SSLeay_MSVC5_hack=(double)name[0]*(double)name[1]; | ||
| 121 | #endif | ||
| 122 | |||
| 123 | if (app_locks == NULL) | ||
| 124 | if ((app_locks=sk_new_null()) == NULL) | ||
| 125 | CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID,ERR_R_MALLOC_FAILURE); | ||
| 126 | return(0); | ||
| 127 | if ((str=BUF_strdup(name)) == NULL) | ||
| 128 | return(0); | ||
| 129 | i=sk_push(app_locks,str); | ||
| 130 | if (!i) | ||
| 131 | Free(str); | ||
| 132 | else | ||
| 133 | i+=CRYPTO_NUM_LOCKS; /* gap of one :-) */ | ||
| 134 | return(i); | ||
| 135 | } | ||
| 136 | |||
| 137 | void (*CRYPTO_get_locking_callback(P_V))(P_I_I_P_I) | ||
| 138 | { | ||
| 139 | return(locking_callback); | ||
| 140 | } | ||
| 141 | |||
| 142 | int (*CRYPTO_get_add_lock_callback(P_V))(P_IP_I_I_P_I) | ||
| 143 | { | ||
| 144 | return(add_lock_callback); | ||
| 145 | } | ||
| 146 | |||
| 147 | void CRYPTO_set_locking_callback(func) | ||
| 148 | void (*func)(P_I_I_P_I); | ||
| 149 | { | ||
| 150 | locking_callback=func; | ||
| 151 | } | ||
| 152 | |||
| 153 | void CRYPTO_set_add_lock_callback(func) | ||
| 154 | int (*func)(P_IP_I_I_P_I); | ||
| 155 | { | ||
| 156 | add_lock_callback=func; | ||
| 157 | } | ||
| 158 | |||
| 159 | unsigned long (*CRYPTO_get_id_callback(P_V))(P_V) | ||
| 160 | { | ||
| 161 | return(id_callback); | ||
| 162 | } | ||
| 163 | |||
| 164 | void CRYPTO_set_id_callback(func) | ||
| 165 | unsigned long (*func)(P_V); | ||
| 166 | { | ||
| 167 | id_callback=func; | ||
| 168 | } | ||
| 169 | |||
| 170 | unsigned long CRYPTO_thread_id() | ||
| 171 | { | ||
| 172 | unsigned long ret=0; | ||
| 173 | |||
| 174 | if (id_callback == NULL) | ||
| 175 | { | ||
| 176 | #ifdef WIN16 | ||
| 177 | ret=(unsigned long)GetCurrentTask(); | ||
| 178 | #elif defined(WIN32) | ||
| 179 | ret=(unsigned long)GetCurrentThreadId(); | ||
| 180 | #elif defined(MSDOS) | ||
| 181 | ret=1L; | ||
| 182 | #else | ||
| 183 | ret=(unsigned long)getpid(); | ||
| 184 | #endif | ||
| 185 | } | ||
| 186 | else | ||
| 187 | ret=id_callback(); | ||
| 188 | return(ret); | ||
| 189 | } | ||
| 190 | |||
| 191 | void CRYPTO_lock(mode,type,file,line) | ||
| 192 | int mode; | ||
| 193 | int type; | ||
| 194 | char *file; | ||
| 195 | int line; | ||
| 196 | { | ||
| 197 | #ifdef LOCK_DEBUG | ||
| 198 | { | ||
| 199 | char *rw_text,*operation_text; | ||
| 200 | |||
| 201 | if (mode & CRYPTO_LOCK) | ||
| 202 | operation_text="lock "; | ||
| 203 | else if (mode & CRYPTO_UNLOCK) | ||
| 204 | operation_text="unlock"; | ||
| 205 | else | ||
| 206 | operation_text="ERROR "; | ||
| 207 | |||
| 208 | if (mode & CRYPTO_READ) | ||
| 209 | rw_text="r"; | ||
| 210 | else if (mode & CRYPTO_WRITE) | ||
| 211 | rw_text="w"; | ||
| 212 | else | ||
| 213 | rw_text="ERROR"; | ||
| 214 | |||
| 215 | fprintf(stderr,"lock:%08lx:(%s)%s %-18s %s:%d\n", | ||
| 216 | CRYPTO_thread_id(), rw_text, operation_text, | ||
| 217 | CRYPTO_get_lock_name(type), file, line); | ||
| 218 | } | ||
| 219 | #endif | ||
| 220 | if (locking_callback != NULL) | ||
| 221 | locking_callback(mode,type,file,line); | ||
| 222 | } | ||
| 223 | |||
| 224 | int CRYPTO_add_lock(pointer,amount,type,file,line) | ||
| 225 | int *pointer; | ||
| 226 | int amount; | ||
| 227 | int type; | ||
| 228 | char *file; | ||
| 229 | int line; | ||
| 230 | { | ||
| 231 | int ret; | ||
| 232 | |||
| 233 | if (add_lock_callback != NULL) | ||
| 234 | { | ||
| 235 | #ifdef LOCK_DEBUG | ||
| 236 | int before= *pointer; | ||
| 237 | #endif | ||
| 238 | |||
| 239 | ret=add_lock_callback(pointer,amount,type,file,line); | ||
| 240 | #ifdef LOCK_DEBUG | ||
| 241 | fprintf(stderr,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n", | ||
| 242 | CRYPTO_thread_id(), | ||
| 243 | before,amount,ret, | ||
| 244 | CRYPTO_get_lock_name(type), | ||
| 245 | file,line); | ||
| 246 | #endif | ||
| 247 | *pointer=ret; | ||
| 248 | } | ||
| 249 | else | ||
| 250 | { | ||
| 251 | CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,file,line); | ||
| 252 | |||
| 253 | ret= *pointer+amount; | ||
| 254 | #ifdef LOCK_DEBUG | ||
| 255 | fprintf(stderr,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n", | ||
| 256 | CRYPTO_thread_id(), | ||
| 257 | *pointer,amount,ret, | ||
| 258 | CRYPTO_get_lock_name(type), | ||
| 259 | file,line); | ||
| 260 | #endif | ||
| 261 | *pointer=ret; | ||
| 262 | CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,file,line); | ||
| 263 | } | ||
| 264 | return(ret); | ||
| 265 | } | ||
| 266 | |||
| 267 | char *CRYPTO_get_lock_name(type) | ||
| 268 | int type; | ||
| 269 | { | ||
| 270 | if (type < 0) | ||
| 271 | return("ERROR"); | ||
| 272 | else if (type < CRYPTO_NUM_LOCKS) | ||
| 273 | return(lock_names[type]); | ||
| 274 | else if (type-CRYPTO_NUM_LOCKS >= sk_num(app_locks)) | ||
| 275 | return("ERROR"); | ||
| 276 | else | ||
| 277 | return(sk_value(app_locks,type-CRYPTO_NUM_LOCKS)); | ||
| 278 | } | ||
| 279 | |||
| 280 | #ifdef _DLL | ||
| 281 | #ifdef WIN32 | ||
| 282 | |||
| 283 | /* All we really need to do is remove the 'error' state when a thread | ||
| 284 | * detaches */ | ||
| 285 | |||
| 286 | BOOL WINAPI DLLEntryPoint(hinstDLL,fdwReason,lpvReserved) | ||
| 287 | HINSTANCE hinstDLL; | ||
| 288 | DWORD fdwReason; | ||
| 289 | LPVOID lpvReserved; | ||
| 290 | { | ||
| 291 | switch(fdwReason) | ||
| 292 | { | ||
| 293 | case DLL_PROCESS_ATTACH: | ||
| 294 | break; | ||
| 295 | case DLL_THREAD_ATTACH: | ||
| 296 | break; | ||
| 297 | case DLL_THREAD_DETACH: | ||
| 298 | ERR_remove_state(0); | ||
| 299 | break; | ||
| 300 | case DLL_PROCESS_DETACH: | ||
| 301 | break; | ||
| 302 | } | ||
| 303 | return(TRUE); | ||
| 304 | } | ||
| 305 | #endif | ||
| 306 | |||
| 307 | #endif | ||
diff --git a/src/lib/libcrypto/cryptlib.h b/src/lib/libcrypto/cryptlib.h new file mode 100644 index 0000000000..32757c9efb --- /dev/null +++ b/src/lib/libcrypto/cryptlib.h | |||
| @@ -0,0 +1,100 @@ | |||
| 1 | /* crypto/cryptlib.h */ | ||
| 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 | #ifndef HEADER_CRYPTLIB_H | ||
| 60 | #define HEADER_CRYPTLIB_H | ||
| 61 | |||
| 62 | #include <stdlib.h> | ||
| 63 | #include <string.h> | ||
| 64 | |||
| 65 | #ifdef __cplusplus | ||
| 66 | extern "C" { | ||
| 67 | #endif | ||
| 68 | |||
| 69 | /* #ifdef FLAT_INC */ | ||
| 70 | |||
| 71 | #include "e_os.h" | ||
| 72 | #include "crypto.h" | ||
| 73 | #include "buffer.h" | ||
| 74 | #include "bio.h" | ||
| 75 | #include "err.h" | ||
| 76 | |||
| 77 | /* | ||
| 78 | #else | ||
| 79 | |||
| 80 | #include "../e_os.h" | ||
| 81 | #include "crypto.h" | ||
| 82 | #include "buffer/buffer.h" | ||
| 83 | #include "bio/bio.h" | ||
| 84 | #include "err/err.h" | ||
| 85 | #endif | ||
| 86 | */ | ||
| 87 | |||
| 88 | #define X509_CERT_AREA "/etc/ssl" | ||
| 89 | #define X509_CERT_DIR "/etc/ssl/certs" | ||
| 90 | #define X509_CERT_FILE "/etc/ssl/cert.pem" | ||
| 91 | #define X509_PRIVATE_DIR "/etc/ssl/private" | ||
| 92 | |||
| 93 | #define X509_CERT_DIR_EVP "SSL_CERT_DIR" | ||
| 94 | #define X509_CERT_FILE_EVP "SSL_CERT_FILE" | ||
| 95 | |||
| 96 | #ifdef __cplusplus | ||
| 97 | } | ||
| 98 | #endif | ||
| 99 | |||
| 100 | #endif | ||
diff --git a/src/lib/libcrypto/crypto.h b/src/lib/libcrypto/crypto.h new file mode 100644 index 0000000000..0a38b5b87c --- /dev/null +++ b/src/lib/libcrypto/crypto.h | |||
| @@ -0,0 +1,319 @@ | |||
| 1 | /* crypto/crypto.h */ | ||
| 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 | #ifndef HEADER_CRYPTO_H | ||
| 60 | #define HEADER_CRYPTO_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #include "stack.h" | ||
| 67 | |||
| 68 | /* This is more to be used to check the correct DLL is being used | ||
| 69 | * in the MS world. */ | ||
| 70 | #define SSLEAY_VERSION_NUMBER 0x0902 /* Version 0.5.1c would be 0513 */ | ||
| 71 | |||
| 72 | #define SSLEAY_VERSION 0 | ||
| 73 | /* #define SSLEAY_OPTIONS 1 no longer supported */ | ||
| 74 | #define SSLEAY_CFLAGS 2 | ||
| 75 | #define SSLEAY_BUILT_ON 3 | ||
| 76 | |||
| 77 | /* When changing the CRYPTO_LOCK_* list, be sure to maintin the text lock | ||
| 78 | * names in cryptlib.c | ||
| 79 | */ | ||
| 80 | |||
| 81 | #define CRYPTO_LOCK_ERR 1 | ||
| 82 | #define CRYPTO_LOCK_ERR_HASH 2 | ||
| 83 | #define CRYPTO_LOCK_X509 3 | ||
| 84 | #define CRYPTO_LOCK_X509_INFO 4 | ||
| 85 | #define CRYPTO_LOCK_X509_PKEY 5 | ||
| 86 | #define CRYPTO_LOCK_X509_CRL 6 | ||
| 87 | #define CRYPTO_LOCK_X509_REQ 7 | ||
| 88 | #define CRYPTO_LOCK_DSA 8 | ||
| 89 | #define CRYPTO_LOCK_RSA 9 | ||
| 90 | #define CRYPTO_LOCK_EVP_PKEY 10 | ||
| 91 | #define CRYPTO_LOCK_X509_STORE 11 | ||
| 92 | #define CRYPTO_LOCK_SSL_CTX 12 | ||
| 93 | #define CRYPTO_LOCK_SSL_CERT 13 | ||
| 94 | #define CRYPTO_LOCK_SSL_SESSION 14 | ||
| 95 | #define CRYPTO_LOCK_SSL 15 | ||
| 96 | #define CRYPTO_LOCK_RAND 16 | ||
| 97 | #define CRYPTO_LOCK_MALLOC 17 | ||
| 98 | #define CRYPTO_LOCK_BIO 18 | ||
| 99 | #define CRYPTO_LOCK_BIO_GETHOSTBYNAME 19 | ||
| 100 | #define CRYPTO_LOCK_RSA_BLINDING 20 | ||
| 101 | #define CRYPTO_NUM_LOCKS 21 | ||
| 102 | |||
| 103 | #define CRYPTO_LOCK 1 | ||
| 104 | #define CRYPTO_UNLOCK 2 | ||
| 105 | #define CRYPTO_READ 4 | ||
| 106 | #define CRYPTO_WRITE 8 | ||
| 107 | |||
| 108 | #ifndef CRYPTO_w_lock | ||
| 109 | #define CRYPTO_w_lock(type) \ | ||
| 110 | CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,__FILE__,__LINE__) | ||
| 111 | #define CRYPTO_w_unlock(type) \ | ||
| 112 | CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,__FILE__,__LINE__) | ||
| 113 | #define CRYPTO_r_lock(type) \ | ||
| 114 | CRYPTO_lock(CRYPTO_LOCK|CRYPTO_READ,type,__FILE__,__LINE__) | ||
| 115 | #define CRYPTO_r_unlock(type) \ | ||
| 116 | CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_READ,type,__FILE__,__LINE__) | ||
| 117 | #define CRYPTO_add(addr,amount,type) \ | ||
| 118 | CRYPTO_add_lock(addr,amount,type,__FILE__,__LINE__) | ||
| 119 | |||
| 120 | #endif | ||
| 121 | |||
| 122 | /* The following can be used to detect memory leaks in the SSLeay library. | ||
| 123 | * It used, it turns on malloc checking */ | ||
| 124 | |||
| 125 | #define CRYPTO_MEM_CHECK_OFF 0x0 | ||
| 126 | #define CRYPTO_MEM_CHECK_ON 0x1 | ||
| 127 | |||
| 128 | /* | ||
| 129 | typedef struct crypto_mem_st | ||
| 130 | { | ||
| 131 | char *(*malloc_func)(); | ||
| 132 | char *(*realloc_func)(); | ||
| 133 | void (*free_func)(); | ||
| 134 | } CRYPTO_MEM_FUNC; | ||
| 135 | */ | ||
| 136 | |||
| 137 | /* predec of the BIO type */ | ||
| 138 | typedef struct bio_st BIO_dummy; | ||
| 139 | |||
| 140 | typedef struct crypto_ex_data_st | ||
| 141 | { | ||
| 142 | STACK *sk; | ||
| 143 | int dummy; /* gcc is screwing up this data structure :-( */ | ||
| 144 | } CRYPTO_EX_DATA; | ||
| 145 | |||
| 146 | /* This stuff is basically class callback functions | ||
| 147 | * The current classes are SSL_CTX, SSL, SSL_SESION, and a few more */ | ||
| 148 | typedef struct crypto_ex_data_func_st | ||
| 149 | { | ||
| 150 | long argl; /* Arbitary long */ | ||
| 151 | char *argp; /* Arbitary char * */ | ||
| 152 | /* Called when a new object is created */ | ||
| 153 | int (*new_func)(/*char *obj, | ||
| 154 | char *item,int index,long argl,char *argp*/); | ||
| 155 | /* Called when this object is free()ed */ | ||
| 156 | void (*free_func)(/*char *obj, | ||
| 157 | char *item,int index,long argl,char *argp*/); | ||
| 158 | |||
| 159 | /* Called when we need to dup this one */ | ||
| 160 | int (*dup_func)(/*char *obj_to,char *obj_from, | ||
| 161 | char **new,int index,long argl,char *argp*/); | ||
| 162 | } CRYPTO_EX_DATA_FUNCS; | ||
| 163 | |||
| 164 | /* Per class, we have a STACK of CRYPTO_EX_DATA_FUNCS for each CRYPTO_EX_DATA | ||
| 165 | * entry. | ||
| 166 | */ | ||
| 167 | |||
| 168 | #define CRYPTO_EX_INDEX_BIO 0 | ||
| 169 | #define CRYPTO_EX_INDEX_SSL 1 | ||
| 170 | #define CRYPTO_EX_INDEX_SSL_CTX 2 | ||
| 171 | #define CRYPTO_EX_INDEX_SSL_SESSION 3 | ||
| 172 | #define CRYPTO_EX_INDEX_X509_STORE 4 | ||
| 173 | #define CRYPTO_EX_INDEX_X509_STORE_CTX 5 | ||
| 174 | |||
| 175 | /* Use this for win32 DLL's */ | ||
| 176 | #define CRYPTO_malloc_init() CRYPTO_set_mem_functions(\ | ||
| 177 | (char *(*)())malloc,\ | ||
| 178 | (char *(*)())realloc,\ | ||
| 179 | (void (*)())free) | ||
| 180 | |||
| 181 | #ifdef CRYPTO_MDEBUG | ||
| 182 | #define Malloc(num) CRYPTO_dbg_malloc((int)num,__FILE__,__LINE__) | ||
| 183 | #define Realloc(addr,num) \ | ||
| 184 | CRYPTO_dbg_realloc((char *)addr,(int)num,__FILE__,__LINE__) | ||
| 185 | #define Remalloc(addr,num) \ | ||
| 186 | CRYPTO_dbg_remalloc((char **)addr,(int)num,__FILE__,__LINE__) | ||
| 187 | #define FreeFunc CRYPTO_dbg_free | ||
| 188 | #define Free(addr) CRYPTO_dbg_free((char *)(addr)) | ||
| 189 | #else | ||
| 190 | #define Remalloc CRYPTO_remalloc | ||
| 191 | #if defined(WIN32) || defined(MFUNC) | ||
| 192 | #define Malloc CRYPTO_malloc | ||
| 193 | #define Realloc(a,n) CRYPTO_realloc((char *)(a),(n)) | ||
| 194 | #define FreeFunc CRYPTO_free | ||
| 195 | #define Free(addr) CRYPTO_free((char *)(addr)) | ||
| 196 | #else | ||
| 197 | #define Malloc malloc | ||
| 198 | #define Realloc realloc | ||
| 199 | #define FreeFunc free | ||
| 200 | #define Free(addr) free((char *)(addr)) | ||
| 201 | #endif /* WIN32 || MFUNC */ | ||
| 202 | #endif /* MDEBUG */ | ||
| 203 | |||
| 204 | /* Case insensiteve linking causes problems.... */ | ||
| 205 | #ifdef WIN16 | ||
| 206 | #define ERR_load_CRYPTO_strings ERR_load_CRYPTOlib_strings | ||
| 207 | #endif | ||
| 208 | |||
| 209 | #ifndef NOPROTO | ||
| 210 | |||
| 211 | char *SSLeay_version(int type); | ||
| 212 | unsigned long SSLeay(void); | ||
| 213 | |||
| 214 | int CRYPTO_get_ex_new_index(int idx,STACK **sk,long argl,char *argp, | ||
| 215 | int (*new_func)(),int (*dup_func)(),void (*free_func)()); | ||
| 216 | int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad,int idx,char *val); | ||
| 217 | char *CRYPTO_get_ex_data(CRYPTO_EX_DATA *ad,int idx); | ||
| 218 | int CRYPTO_dup_ex_data(STACK *meth,CRYPTO_EX_DATA *from,CRYPTO_EX_DATA *to); | ||
| 219 | void CRYPTO_free_ex_data(STACK *meth,char *obj,CRYPTO_EX_DATA *ad); | ||
| 220 | void CRYPTO_new_ex_data(STACK *meth, char *obj, CRYPTO_EX_DATA *ad); | ||
| 221 | |||
| 222 | int CRYPTO_mem_ctrl(int mode); | ||
| 223 | int CRYPTO_get_new_lockid(char *name); | ||
| 224 | void CRYPTO_lock(int mode, int type,char *file,int line); | ||
| 225 | void CRYPTO_set_locking_callback(void (*func)(int mode,int type,char *file, | ||
| 226 | int line)); | ||
| 227 | void (*CRYPTO_get_locking_callback(void))(int mode,int type,char *file, | ||
| 228 | int line); | ||
| 229 | void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount, | ||
| 230 | int type,char *file, int line)); | ||
| 231 | int (*CRYPTO_get_add_lock_callback(void))(int *num,int mount, | ||
| 232 | int type,char *file,int line); | ||
| 233 | void CRYPTO_set_id_callback(unsigned long (*func)(void)); | ||
| 234 | unsigned long (*CRYPTO_get_id_callback(void))(void); | ||
| 235 | unsigned long CRYPTO_thread_id(void); | ||
| 236 | char *CRYPTO_get_lock_name(int type); | ||
| 237 | int CRYPTO_add_lock(int *pointer,int amount,int type, char *file,int line); | ||
| 238 | |||
| 239 | void CRYPTO_set_mem_functions(char *(*m)(),char *(*r)(), void (*free_func)()); | ||
| 240 | void CRYPTO_get_mem_functions(char *(**m)(),char *(**r)(), void (**f)()); | ||
| 241 | |||
| 242 | char *CRYPTO_malloc(int num); | ||
| 243 | char *CRYPTO_realloc(char *addr,int num); | ||
| 244 | void CRYPTO_free(char *); | ||
| 245 | char *CRYPTO_remalloc(char *addr,int num); | ||
| 246 | |||
| 247 | char *CRYPTO_dbg_malloc(int num,char *file,int line); | ||
| 248 | char *CRYPTO_dbg_realloc(char *addr,int num,char *file,int line); | ||
| 249 | void CRYPTO_dbg_free(char *); | ||
| 250 | char *CRYPTO_dbg_remalloc(char *addr,int num,char *file,int line); | ||
| 251 | #ifndef NO_FP_API | ||
| 252 | void CRYPTO_mem_leaks_fp(FILE *); | ||
| 253 | #endif | ||
| 254 | void CRYPTO_mem_leaks(struct bio_st *bio); | ||
| 255 | /* unsigned long order, char *file, int line, int num_bytes, char *addr */ | ||
| 256 | void CRYPTO_mem_leaks_cb(void (*cb)()); | ||
| 257 | |||
| 258 | void ERR_load_CRYPTO_strings(void ); | ||
| 259 | |||
| 260 | #else | ||
| 261 | |||
| 262 | int CRYPTO_get_ex_new_index(); | ||
| 263 | int CRYPTO_set_ex_data(); | ||
| 264 | char *CRYPTO_get_ex_data(); | ||
| 265 | int CRYPTO_dup_ex_data(); | ||
| 266 | void CRYPTO_free_ex_data(); | ||
| 267 | void CRYPTO_new_ex_data(); | ||
| 268 | |||
| 269 | int CRYPTO_mem_ctrl(); | ||
| 270 | char *SSLeay_version(); | ||
| 271 | unsigned long SSLeay(); | ||
| 272 | |||
| 273 | int CRYPTO_get_new_lockid(); | ||
| 274 | void CRYPTO_lock(); | ||
| 275 | void CRYPTO_set_locking_callback(); | ||
| 276 | void (*CRYPTO_get_locking_callback())(); | ||
| 277 | void CRYPTO_set_add_lock_callback(); | ||
| 278 | int (*CRYPTO_get_add_lock_callback())(); | ||
| 279 | void CRYPTO_set_id_callback(); | ||
| 280 | unsigned long (*CRYPTO_get_id_callback())(); | ||
| 281 | unsigned long CRYPTO_thread_id(); | ||
| 282 | char *CRYPTO_get_lock_name(); | ||
| 283 | int CRYPTO_add_lock(); | ||
| 284 | |||
| 285 | void CRYPTO_set_mem_functions(); | ||
| 286 | void CRYPTO_get_mem_functions(); | ||
| 287 | char *CRYPTO_malloc(); | ||
| 288 | char *CRYPTO_realloc(); | ||
| 289 | void CRYPTO_free(); | ||
| 290 | char *CRYPTO_remalloc(); | ||
| 291 | char *CRYPTO_dbg_remalloc(); | ||
| 292 | char *CRYPTO_dbg_malloc(); | ||
| 293 | char *CRYPTO_dbg_realloc(); | ||
| 294 | void CRYPTO_dbg_free(); | ||
| 295 | #ifndef NO_FP_API | ||
| 296 | void CRYPTO_mem_leaks_fp(); | ||
| 297 | #endif | ||
| 298 | void CRYPTO_mem_leaks(); | ||
| 299 | void CRYPTO_mem_leaks_cb(); | ||
| 300 | |||
| 301 | void ERR_load_CRYPTO_strings(); | ||
| 302 | |||
| 303 | #endif | ||
| 304 | |||
| 305 | /* BEGIN ERROR CODES */ | ||
| 306 | /* Error codes for the CRYPTO functions. */ | ||
| 307 | |||
| 308 | /* Function codes. */ | ||
| 309 | #define CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX 100 | ||
| 310 | #define CRYPTO_F_CRYPTO_GET_NEW_LOCKID 101 | ||
| 311 | #define CRYPTO_F_CRYPTO_SET_EX_DATA 102 | ||
| 312 | |||
| 313 | /* Reason codes. */ | ||
| 314 | |||
| 315 | #ifdef __cplusplus | ||
| 316 | } | ||
| 317 | #endif | ||
| 318 | #endif | ||
| 319 | |||
diff --git a/src/lib/libcrypto/cversion.c b/src/lib/libcrypto/cversion.c new file mode 100644 index 0000000000..4e823be52f --- /dev/null +++ b/src/lib/libcrypto/cversion.c | |||
| @@ -0,0 +1,99 @@ | |||
| 1 | /* crypto/cversion.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 <string.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "crypto.h" | ||
| 63 | #include "date.h" | ||
| 64 | |||
| 65 | char *SSLeay_version(t) | ||
| 66 | int t; | ||
| 67 | { | ||
| 68 | if (t == SSLEAY_VERSION) | ||
| 69 | return("SSLeay 0.9.0b 29-Jun-1998"); | ||
| 70 | if (t == SSLEAY_BUILT_ON) | ||
| 71 | { | ||
| 72 | #ifdef DATE | ||
| 73 | static char buf[sizeof(DATE)+10]; | ||
| 74 | |||
| 75 | sprintf(buf,"built on %s",DATE); | ||
| 76 | return(buf); | ||
| 77 | #else | ||
| 78 | return("build date not available"); | ||
| 79 | #endif | ||
| 80 | } | ||
| 81 | if (t == SSLEAY_CFLAGS) | ||
| 82 | { | ||
| 83 | #ifdef CFLAGS | ||
| 84 | static char buf[sizeof(CFLAGS)+10]; | ||
| 85 | |||
| 86 | sprintf(buf,"C flags:%s",CFLAGS); | ||
| 87 | return(buf); | ||
| 88 | #else | ||
| 89 | return("C flags not available"); | ||
| 90 | #endif | ||
| 91 | } | ||
| 92 | return("not available"); | ||
| 93 | } | ||
| 94 | |||
| 95 | unsigned long SSLeay() | ||
| 96 | { | ||
| 97 | return(SSLEAY_VERSION_NUMBER); | ||
| 98 | } | ||
| 99 | |||
diff --git a/src/lib/libcrypto/des/COPYRIGHT b/src/lib/libcrypto/des/COPYRIGHT new file mode 100644 index 0000000000..5469e1e469 --- /dev/null +++ b/src/lib/libcrypto/des/COPYRIGHT | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) | ||
| 2 | All rights reserved. | ||
| 3 | |||
| 4 | This package is an DES implementation written by Eric Young (eay@cryptsoft.com). | ||
| 5 | The implementation was written so as to conform with MIT's libdes. | ||
| 6 | |||
| 7 | This library is free for commercial and non-commercial use as long as | ||
| 8 | the following conditions are aheared to. The following conditions | ||
| 9 | apply to all code found in this distribution. | ||
| 10 | |||
| 11 | Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 12 | the code are not to be removed. | ||
| 13 | If this package is used in a product, Eric Young should be given attribution | ||
| 14 | as the author of that the SSL library. This can be in the form of a textual | ||
| 15 | message at program startup or in documentation (online or textual) provided | ||
| 16 | with the package. | ||
| 17 | |||
| 18 | Redistribution and use in source and binary forms, with or without | ||
| 19 | modification, are permitted provided that the following conditions | ||
| 20 | are met: | ||
| 21 | 1. Redistributions of source code must retain the copyright | ||
| 22 | notice, this list of conditions and the following disclaimer. | ||
| 23 | 2. Redistributions in binary form must reproduce the above copyright | ||
| 24 | notice, this list of conditions and the following disclaimer in the | ||
| 25 | documentation and/or other materials provided with the distribution. | ||
| 26 | 3. All advertising materials mentioning features or use of this software | ||
| 27 | must display the following acknowledgement: | ||
| 28 | This product includes software developed by Eric Young (eay@cryptsoft.com) | ||
| 29 | |||
| 30 | THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 31 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 32 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 33 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 34 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 35 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 36 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 37 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 38 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 39 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 40 | SUCH DAMAGE. | ||
| 41 | |||
| 42 | The license and distribution terms for any publically available version or | ||
| 43 | derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 44 | copied and put under another distrubution license | ||
| 45 | [including the GNU Public License.] | ||
| 46 | |||
| 47 | The reason behind this being stated in this direct manner is past | ||
| 48 | experience in code simply being copied and the attribution removed | ||
| 49 | from it and then being distributed as part of other packages. This | ||
| 50 | implementation was a non-trivial and unpaid effort. | ||
diff --git a/src/lib/libcrypto/des/asm/crypt586.pl b/src/lib/libcrypto/des/asm/crypt586.pl new file mode 100644 index 0000000000..297e38dec8 --- /dev/null +++ b/src/lib/libcrypto/des/asm/crypt586.pl | |||
| @@ -0,0 +1,204 @@ | |||
| 1 | #!/usr/bin/perl | ||
| 2 | # | ||
| 3 | # The inner loop instruction sequence and the IP/FP modifications are from | ||
| 4 | # Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk> | ||
| 5 | # I've added the stuff needed for crypt() but I've not worried about making | ||
| 6 | # things perfect. | ||
| 7 | # | ||
| 8 | |||
| 9 | push(@INC,"perlasm","../../perlasm"); | ||
| 10 | require "x86asm.pl"; | ||
| 11 | |||
| 12 | &asm_init($ARGV[0],"crypt586.pl"); | ||
| 13 | |||
| 14 | $L="edi"; | ||
| 15 | $R="esi"; | ||
| 16 | |||
| 17 | &external_label("des_SPtrans"); | ||
| 18 | &fcrypt_body("fcrypt_body"); | ||
| 19 | &asm_finish(); | ||
| 20 | |||
| 21 | sub fcrypt_body | ||
| 22 | { | ||
| 23 | local($name,$do_ip)=@_; | ||
| 24 | |||
| 25 | &function_begin($name,"EXTRN _des_SPtrans:DWORD"); | ||
| 26 | |||
| 27 | &comment(""); | ||
| 28 | &comment("Load the 2 words"); | ||
| 29 | $ks="ebp"; | ||
| 30 | |||
| 31 | &xor( $L, $L); | ||
| 32 | &xor( $R, $R); | ||
| 33 | &mov($ks,&wparam(1)); | ||
| 34 | |||
| 35 | &push(25); # add a variable | ||
| 36 | |||
| 37 | &set_label("start"); | ||
| 38 | for ($i=0; $i<16; $i+=2) | ||
| 39 | { | ||
| 40 | &comment(""); | ||
| 41 | &comment("Round $i"); | ||
| 42 | &D_ENCRYPT($i,$L,$R,$i*2,$ks,"des_SPtrans","eax","ebx","ecx","edx"); | ||
| 43 | |||
| 44 | &comment(""); | ||
| 45 | &comment("Round ".sprintf("%d",$i+1)); | ||
| 46 | &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$ks,"des_SPtrans","eax","ebx","ecx","edx"); | ||
| 47 | } | ||
| 48 | &mov("ebx", &swtmp(0)); | ||
| 49 | &mov("eax", $L); | ||
| 50 | &dec("ebx"); | ||
| 51 | &mov($L, $R); | ||
| 52 | &mov($R, "eax"); | ||
| 53 | &mov(&swtmp(0), "ebx"); | ||
| 54 | &jnz(&label("start")); | ||
| 55 | |||
| 56 | &comment(""); | ||
| 57 | &comment("FP"); | ||
| 58 | &mov("edx",&wparam(0)); | ||
| 59 | |||
| 60 | &FP_new($R,$L,"eax",3); | ||
| 61 | &mov(&DWP(0,"edx","",0),"eax"); | ||
| 62 | &mov(&DWP(4,"edx","",0),$L); | ||
| 63 | |||
| 64 | &pop("ecx"); # remove variable | ||
| 65 | |||
| 66 | &function_end($name); | ||
| 67 | } | ||
| 68 | |||
| 69 | sub D_ENCRYPT | ||
| 70 | { | ||
| 71 | local($r,$L,$R,$S,$ks,$desSP,$u,$tmp1,$tmp2,$t)=@_; | ||
| 72 | |||
| 73 | &mov( $u, &wparam(2)); # 2 | ||
| 74 | &mov( $t, $R); | ||
| 75 | &shr( $t, 16); # 1 | ||
| 76 | &mov( $tmp2, &wparam(3)); # 2 | ||
| 77 | &xor( $t, $R); # 1 | ||
| 78 | |||
| 79 | &and( $u, $t); # 2 | ||
| 80 | &and( $t, $tmp2); # 2 | ||
| 81 | |||
| 82 | &mov( $tmp1, $u); | ||
| 83 | &shl( $tmp1, 16); # 1 | ||
| 84 | &mov( $tmp2, $t); | ||
| 85 | &shl( $tmp2, 16); # 1 | ||
| 86 | &xor( $u, $tmp1); # 2 | ||
| 87 | &xor( $t, $tmp2); # 2 | ||
| 88 | &mov( $tmp1, &DWP(&n2a($S*4),$ks,"",0)); # 2 | ||
| 89 | &xor( $u, $tmp1); | ||
| 90 | &mov( $tmp2, &DWP(&n2a(($S+1)*4),$ks,"",0)); # 2 | ||
| 91 | &xor( $u, $R); | ||
| 92 | &xor( $t, $R); | ||
| 93 | &xor( $t, $tmp2); | ||
| 94 | |||
| 95 | &and( $u, "0xfcfcfcfc" ); # 2 | ||
| 96 | &xor( $tmp1, $tmp1); # 1 | ||
| 97 | &and( $t, "0xcfcfcfcf" ); # 2 | ||
| 98 | &xor( $tmp2, $tmp2); | ||
| 99 | &movb( &LB($tmp1), &LB($u) ); | ||
| 100 | &movb( &LB($tmp2), &HB($u) ); | ||
| 101 | &rotr( $t, 4 ); | ||
| 102 | &mov( $ks, &DWP(" $desSP",$tmp1,"",0)); | ||
| 103 | &movb( &LB($tmp1), &LB($t) ); | ||
| 104 | &xor( $L, $ks); | ||
| 105 | &mov( $ks, &DWP("0x200+$desSP",$tmp2,"",0)); | ||
| 106 | &xor( $L, $ks); | ||
| 107 | &movb( &LB($tmp2), &HB($t) ); | ||
| 108 | &shr( $u, 16); | ||
| 109 | &mov( $ks, &DWP("0x100+$desSP",$tmp1,"",0)); | ||
| 110 | &xor( $L, $ks); | ||
| 111 | &movb( &LB($tmp1), &HB($u) ); | ||
| 112 | &shr( $t, 16); | ||
| 113 | &mov( $ks, &DWP("0x300+$desSP",$tmp2,"",0)); | ||
| 114 | &xor( $L, $ks); | ||
| 115 | &mov( $ks, &wparam(1)); | ||
| 116 | &movb( &LB($tmp2), &HB($t) ); | ||
| 117 | &and( $u, "0xff" ); | ||
| 118 | &and( $t, "0xff" ); | ||
| 119 | &mov( $tmp1, &DWP("0x600+$desSP",$tmp1,"",0)); | ||
| 120 | &xor( $L, $tmp1); | ||
| 121 | &mov( $tmp1, &DWP("0x700+$desSP",$tmp2,"",0)); | ||
| 122 | &xor( $L, $tmp1); | ||
| 123 | &mov( $tmp1, &DWP("0x400+$desSP",$u,"",0)); | ||
| 124 | &xor( $L, $tmp1); | ||
| 125 | &mov( $tmp1, &DWP("0x500+$desSP",$t,"",0)); | ||
| 126 | &xor( $L, $tmp1); | ||
| 127 | } | ||
| 128 | |||
| 129 | sub n2a | ||
| 130 | { | ||
| 131 | sprintf("%d",$_[0]); | ||
| 132 | } | ||
| 133 | |||
| 134 | # now has a side affect of rotating $a by $shift | ||
| 135 | sub R_PERM_OP | ||
| 136 | { | ||
| 137 | local($a,$b,$tt,$shift,$mask,$last)=@_; | ||
| 138 | |||
| 139 | &rotl( $a, $shift ) if ($shift != 0); | ||
| 140 | &mov( $tt, $a ); | ||
| 141 | &xor( $a, $b ); | ||
| 142 | &and( $a, $mask ); | ||
| 143 | if ($notlast eq $b) | ||
| 144 | { | ||
| 145 | &xor( $b, $a ); | ||
| 146 | &xor( $tt, $a ); | ||
| 147 | } | ||
| 148 | else | ||
| 149 | { | ||
| 150 | &xor( $tt, $a ); | ||
| 151 | &xor( $b, $a ); | ||
| 152 | } | ||
| 153 | &comment(""); | ||
| 154 | } | ||
| 155 | |||
| 156 | sub IP_new | ||
| 157 | { | ||
| 158 | local($l,$r,$tt,$lr)=@_; | ||
| 159 | |||
| 160 | &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l); | ||
| 161 | &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l); | ||
| 162 | &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r); | ||
| 163 | &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r); | ||
| 164 | &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r); | ||
| 165 | |||
| 166 | if ($lr != 3) | ||
| 167 | { | ||
| 168 | if (($lr-3) < 0) | ||
| 169 | { &rotr($tt, 3-$lr); } | ||
| 170 | else { &rotl($tt, $lr-3); } | ||
| 171 | } | ||
| 172 | if ($lr != 2) | ||
| 173 | { | ||
| 174 | if (($lr-2) < 0) | ||
| 175 | { &rotr($r, 2-$lr); } | ||
| 176 | else { &rotl($r, $lr-2); } | ||
| 177 | } | ||
| 178 | } | ||
| 179 | |||
| 180 | sub FP_new | ||
| 181 | { | ||
| 182 | local($l,$r,$tt,$lr)=@_; | ||
| 183 | |||
| 184 | if ($lr != 2) | ||
| 185 | { | ||
| 186 | if (($lr-2) < 0) | ||
| 187 | { &rotl($r, 2-$lr); } | ||
| 188 | else { &rotr($r, $lr-2); } | ||
| 189 | } | ||
| 190 | if ($lr != 3) | ||
| 191 | { | ||
| 192 | if (($lr-3) < 0) | ||
| 193 | { &rotl($l, 3-$lr); } | ||
| 194 | else { &rotr($l, $lr-3); } | ||
| 195 | } | ||
| 196 | |||
| 197 | &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r); | ||
| 198 | &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r); | ||
| 199 | &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l); | ||
| 200 | &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l); | ||
| 201 | &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r); | ||
| 202 | &rotr($tt , 4); | ||
| 203 | } | ||
| 204 | |||
diff --git a/src/lib/libcrypto/des/asm/des-586.pl b/src/lib/libcrypto/des/asm/des-586.pl new file mode 100644 index 0000000000..7f2e09fa7a --- /dev/null +++ b/src/lib/libcrypto/des/asm/des-586.pl | |||
| @@ -0,0 +1,251 @@ | |||
| 1 | #!/usr/bin/perl | ||
| 2 | # | ||
| 3 | # The inner loop instruction sequence and the IP/FP modifications are from | ||
| 4 | # Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk> | ||
| 5 | # | ||
| 6 | |||
| 7 | push(@INC,"perlasm","../../perlasm"); | ||
| 8 | require "x86asm.pl"; | ||
| 9 | require "cbc.pl"; | ||
| 10 | require "desboth.pl"; | ||
| 11 | |||
| 12 | # base code is in microsft | ||
| 13 | # op dest, source | ||
| 14 | # format. | ||
| 15 | # | ||
| 16 | |||
| 17 | &asm_init($ARGV[0],"des-586.pl"); | ||
| 18 | |||
| 19 | $L="edi"; | ||
| 20 | $R="esi"; | ||
| 21 | |||
| 22 | &external_label("des_SPtrans"); | ||
| 23 | &des_encrypt("des_encrypt",1); | ||
| 24 | &des_encrypt("des_encrypt2",0); | ||
| 25 | &des_encrypt3("des_encrypt3",1); | ||
| 26 | &des_encrypt3("des_decrypt3",0); | ||
| 27 | &cbc("des_ncbc_encrypt","des_encrypt","des_encrypt",0,4,5,3,5,-1); | ||
| 28 | &cbc("des_ede3_cbc_encrypt","des_encrypt3","des_decrypt3",0,6,7,3,4,5); | ||
| 29 | |||
| 30 | &asm_finish(); | ||
| 31 | |||
| 32 | sub des_encrypt | ||
| 33 | { | ||
| 34 | local($name,$do_ip)=@_; | ||
| 35 | |||
| 36 | &function_begin_B($name,"EXTRN _des_SPtrans:DWORD"); | ||
| 37 | |||
| 38 | &push("esi"); | ||
| 39 | &push("edi"); | ||
| 40 | |||
| 41 | &comment(""); | ||
| 42 | &comment("Load the 2 words"); | ||
| 43 | $ks="ebp"; | ||
| 44 | |||
| 45 | if ($do_ip) | ||
| 46 | { | ||
| 47 | &mov($R,&wparam(0)); | ||
| 48 | &xor( "ecx", "ecx" ); | ||
| 49 | |||
| 50 | &push("ebx"); | ||
| 51 | &push("ebp"); | ||
| 52 | |||
| 53 | &mov("eax",&DWP(0,$R,"",0)); | ||
| 54 | &mov("ebx",&wparam(2)); # get encrypt flag | ||
| 55 | &mov($L,&DWP(4,$R,"",0)); | ||
| 56 | &comment(""); | ||
| 57 | &comment("IP"); | ||
| 58 | &IP_new("eax",$L,$R,3); | ||
| 59 | } | ||
| 60 | else | ||
| 61 | { | ||
| 62 | &mov("eax",&wparam(0)); | ||
| 63 | &xor( "ecx", "ecx" ); | ||
| 64 | |||
| 65 | &push("ebx"); | ||
| 66 | &push("ebp"); | ||
| 67 | |||
| 68 | &mov($R,&DWP(0,"eax","",0)); | ||
| 69 | &mov("ebx",&wparam(2)); # get encrypt flag | ||
| 70 | &rotl($R,3); | ||
| 71 | &mov($L,&DWP(4,"eax","",0)); | ||
| 72 | &rotl($L,3); | ||
| 73 | } | ||
| 74 | |||
| 75 | &mov( $ks, &wparam(1) ); | ||
| 76 | &cmp("ebx","0"); | ||
| 77 | &je(&label("start_decrypt")); | ||
| 78 | |||
| 79 | for ($i=0; $i<16; $i+=2) | ||
| 80 | { | ||
| 81 | &comment(""); | ||
| 82 | &comment("Round $i"); | ||
| 83 | &D_ENCRYPT($i,$L,$R,$i*2,$ks,"des_SPtrans","eax","ebx","ecx","edx"); | ||
| 84 | |||
| 85 | &comment(""); | ||
| 86 | &comment("Round ".sprintf("%d",$i+1)); | ||
| 87 | &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$ks,"des_SPtrans","eax","ebx","ecx","edx"); | ||
| 88 | } | ||
| 89 | &jmp(&label("end")); | ||
| 90 | |||
| 91 | &set_label("start_decrypt"); | ||
| 92 | |||
| 93 | for ($i=15; $i>0; $i-=2) | ||
| 94 | { | ||
| 95 | &comment(""); | ||
| 96 | &comment("Round $i"); | ||
| 97 | &D_ENCRYPT(15-$i,$L,$R,$i*2,$ks,"des_SPtrans","eax","ebx","ecx","edx"); | ||
| 98 | &comment(""); | ||
| 99 | &comment("Round ".sprintf("%d",$i-1)); | ||
| 100 | &D_ENCRYPT(15-$i+1,$R,$L,($i-1)*2,$ks,"des_SPtrans","eax","ebx","ecx","edx"); | ||
| 101 | } | ||
| 102 | |||
| 103 | &set_label("end"); | ||
| 104 | |||
| 105 | if ($do_ip) | ||
| 106 | { | ||
| 107 | &comment(""); | ||
| 108 | &comment("FP"); | ||
| 109 | &mov("edx",&wparam(0)); | ||
| 110 | &FP_new($L,$R,"eax",3); | ||
| 111 | |||
| 112 | &mov(&DWP(0,"edx","",0),"eax"); | ||
| 113 | &mov(&DWP(4,"edx","",0),$R); | ||
| 114 | } | ||
| 115 | else | ||
| 116 | { | ||
| 117 | &comment(""); | ||
| 118 | &comment("Fixup"); | ||
| 119 | &rotr($L,3); # r | ||
| 120 | &mov("eax",&wparam(0)); | ||
| 121 | &rotr($R,3); # l | ||
| 122 | &mov(&DWP(0,"eax","",0),$L); | ||
| 123 | &mov(&DWP(4,"eax","",0),$R); | ||
| 124 | } | ||
| 125 | |||
| 126 | &pop("ebp"); | ||
| 127 | &pop("ebx"); | ||
| 128 | &pop("edi"); | ||
| 129 | &pop("esi"); | ||
| 130 | &ret(); | ||
| 131 | |||
| 132 | &function_end_B($name); | ||
| 133 | } | ||
| 134 | |||
| 135 | sub D_ENCRYPT | ||
| 136 | { | ||
| 137 | local($r,$L,$R,$S,$ks,$desSP,$u,$tmp1,$tmp2,$t)=@_; | ||
| 138 | |||
| 139 | &mov( $u, &DWP(&n2a($S*4),$ks,"",0)); | ||
| 140 | &xor( $tmp1, $tmp1); | ||
| 141 | &mov( $t, &DWP(&n2a(($S+1)*4),$ks,"",0)); | ||
| 142 | &xor( $u, $R); | ||
| 143 | &xor( $t, $R); | ||
| 144 | &and( $u, "0xfcfcfcfc" ); | ||
| 145 | &and( $t, "0xcfcfcfcf" ); | ||
| 146 | &movb( &LB($tmp1), &LB($u) ); | ||
| 147 | &movb( &LB($tmp2), &HB($u) ); | ||
| 148 | &rotr( $t, 4 ); | ||
| 149 | &mov( $ks, &DWP(" $desSP",$tmp1,"",0)); | ||
| 150 | &movb( &LB($tmp1), &LB($t) ); | ||
| 151 | &xor( $L, $ks); | ||
| 152 | &mov( $ks, &DWP("0x200+$desSP",$tmp2,"",0)); | ||
| 153 | &xor( $L, $ks); ###### | ||
| 154 | &movb( &LB($tmp2), &HB($t) ); | ||
| 155 | &shr( $u, 16); | ||
| 156 | &mov( $ks, &DWP("0x100+$desSP",$tmp1,"",0)); | ||
| 157 | &xor( $L, $ks); ###### | ||
| 158 | &movb( &LB($tmp1), &HB($u) ); | ||
| 159 | &shr( $t, 16); | ||
| 160 | &mov( $ks, &DWP("0x300+$desSP",$tmp2,"",0)); | ||
| 161 | &xor( $L, $ks); | ||
| 162 | &mov( $ks, &wparam(1) ); | ||
| 163 | &movb( &LB($tmp2), &HB($t) ); | ||
| 164 | &and( $u, "0xff" ); | ||
| 165 | &and( $t, "0xff" ); | ||
| 166 | &mov( $tmp1, &DWP("0x600+$desSP",$tmp1,"",0)); | ||
| 167 | &xor( $L, $tmp1); | ||
| 168 | &mov( $tmp1, &DWP("0x700+$desSP",$tmp2,"",0)); | ||
| 169 | &xor( $L, $tmp1); | ||
| 170 | &mov( $tmp1, &DWP("0x400+$desSP",$u,"",0)); | ||
| 171 | &xor( $L, $tmp1); | ||
| 172 | &mov( $tmp1, &DWP("0x500+$desSP",$t,"",0)); | ||
| 173 | &xor( $L, $tmp1); | ||
| 174 | } | ||
| 175 | |||
| 176 | sub n2a | ||
| 177 | { | ||
| 178 | sprintf("%d",$_[0]); | ||
| 179 | } | ||
| 180 | |||
| 181 | # now has a side affect of rotating $a by $shift | ||
| 182 | sub R_PERM_OP | ||
| 183 | { | ||
| 184 | local($a,$b,$tt,$shift,$mask,$last)=@_; | ||
| 185 | |||
| 186 | &rotl( $a, $shift ) if ($shift != 0); | ||
| 187 | &mov( $tt, $a ); | ||
| 188 | &xor( $a, $b ); | ||
| 189 | &and( $a, $mask ); | ||
| 190 | if (!$last eq $b) | ||
| 191 | { | ||
| 192 | &xor( $b, $a ); | ||
| 193 | &xor( $tt, $a ); | ||
| 194 | } | ||
| 195 | else | ||
| 196 | { | ||
| 197 | &xor( $tt, $a ); | ||
| 198 | &xor( $b, $a ); | ||
| 199 | } | ||
| 200 | &comment(""); | ||
| 201 | } | ||
| 202 | |||
| 203 | sub IP_new | ||
| 204 | { | ||
| 205 | local($l,$r,$tt,$lr)=@_; | ||
| 206 | |||
| 207 | &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l); | ||
| 208 | &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l); | ||
| 209 | &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r); | ||
| 210 | &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r); | ||
| 211 | &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r); | ||
| 212 | |||
| 213 | if ($lr != 3) | ||
| 214 | { | ||
| 215 | if (($lr-3) < 0) | ||
| 216 | { &rotr($tt, 3-$lr); } | ||
| 217 | else { &rotl($tt, $lr-3); } | ||
| 218 | } | ||
| 219 | if ($lr != 2) | ||
| 220 | { | ||
| 221 | if (($lr-2) < 0) | ||
| 222 | { &rotr($r, 2-$lr); } | ||
| 223 | else { &rotl($r, $lr-2); } | ||
| 224 | } | ||
| 225 | } | ||
| 226 | |||
| 227 | sub FP_new | ||
| 228 | { | ||
| 229 | local($l,$r,$tt,$lr)=@_; | ||
| 230 | |||
| 231 | if ($lr != 2) | ||
| 232 | { | ||
| 233 | if (($lr-2) < 0) | ||
| 234 | { &rotl($r, 2-$lr); } | ||
| 235 | else { &rotr($r, $lr-2); } | ||
| 236 | } | ||
| 237 | if ($lr != 3) | ||
| 238 | { | ||
| 239 | if (($lr-3) < 0) | ||
| 240 | { &rotl($l, 3-$lr); } | ||
| 241 | else { &rotr($l, $lr-3); } | ||
| 242 | } | ||
| 243 | |||
| 244 | &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r); | ||
| 245 | &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r); | ||
| 246 | &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l); | ||
| 247 | &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l); | ||
| 248 | &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r); | ||
| 249 | &rotr($tt , 4); | ||
| 250 | } | ||
| 251 | |||
diff --git a/src/lib/libcrypto/des/asm/desboth.pl b/src/lib/libcrypto/des/asm/desboth.pl new file mode 100644 index 0000000000..8f939953a6 --- /dev/null +++ b/src/lib/libcrypto/des/asm/desboth.pl | |||
| @@ -0,0 +1,79 @@ | |||
| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | $L="edi"; | ||
| 4 | $R="esi"; | ||
| 5 | |||
| 6 | sub des_encrypt3 | ||
| 7 | { | ||
| 8 | local($name,$enc)=@_; | ||
| 9 | |||
| 10 | &function_begin_B($name,""); | ||
| 11 | &push("ebx"); | ||
| 12 | &mov("ebx",&wparam(0)); | ||
| 13 | |||
| 14 | &push("ebp"); | ||
| 15 | &push("esi"); | ||
| 16 | |||
| 17 | &push("edi"); | ||
| 18 | |||
| 19 | &comment(""); | ||
| 20 | &comment("Load the data words"); | ||
| 21 | &mov($L,&DWP(0,"ebx","",0)); | ||
| 22 | &mov($R,&DWP(4,"ebx","",0)); | ||
| 23 | &stack_push(3); | ||
| 24 | |||
| 25 | &comment(""); | ||
| 26 | &comment("IP"); | ||
| 27 | &IP_new($L,$R,"edx",0); | ||
| 28 | |||
| 29 | # put them back | ||
| 30 | |||
| 31 | if ($enc) | ||
| 32 | { | ||
| 33 | &mov(&DWP(4,"ebx","",0),$R); | ||
| 34 | &mov("eax",&wparam(1)); | ||
| 35 | &mov(&DWP(0,"ebx","",0),"edx"); | ||
| 36 | &mov("edi",&wparam(2)); | ||
| 37 | &mov("esi",&wparam(3)); | ||
| 38 | } | ||
| 39 | else | ||
| 40 | { | ||
| 41 | &mov(&DWP(4,"ebx","",0),$R); | ||
| 42 | &mov("esi",&wparam(1)); | ||
| 43 | &mov(&DWP(0,"ebx","",0),"edx"); | ||
| 44 | &mov("edi",&wparam(2)); | ||
| 45 | &mov("eax",&wparam(3)); | ||
| 46 | } | ||
| 47 | &mov(&swtmp(2), (($enc)?"1":"0")); | ||
| 48 | &mov(&swtmp(1), "eax"); | ||
| 49 | &mov(&swtmp(0), "ebx"); | ||
| 50 | &call("des_encrypt2"); | ||
| 51 | &mov(&swtmp(2), (($enc)?"0":"1")); | ||
| 52 | &mov(&swtmp(1), "edi"); | ||
| 53 | &mov(&swtmp(0), "ebx"); | ||
| 54 | &call("des_encrypt2"); | ||
| 55 | &mov(&swtmp(2), (($enc)?"1":"0")); | ||
| 56 | &mov(&swtmp(1), "esi"); | ||
| 57 | &mov(&swtmp(0), "ebx"); | ||
| 58 | &call("des_encrypt2"); | ||
| 59 | |||
| 60 | &stack_pop(3); | ||
| 61 | &mov($L,&DWP(0,"ebx","",0)); | ||
| 62 | &mov($R,&DWP(4,"ebx","",0)); | ||
| 63 | |||
| 64 | &comment(""); | ||
| 65 | &comment("FP"); | ||
| 66 | &FP_new($L,$R,"eax",0); | ||
| 67 | |||
| 68 | &mov(&DWP(0,"ebx","",0),"eax"); | ||
| 69 | &mov(&DWP(4,"ebx","",0),$R); | ||
| 70 | |||
| 71 | &pop("edi"); | ||
| 72 | &pop("esi"); | ||
| 73 | &pop("ebp"); | ||
| 74 | &pop("ebx"); | ||
| 75 | &ret(); | ||
| 76 | &function_end_B($name); | ||
| 77 | } | ||
| 78 | |||
| 79 | |||
diff --git a/src/lib/libcrypto/des/cbc_cksm.c b/src/lib/libcrypto/des/cbc_cksm.c new file mode 100644 index 0000000000..edfdec8a0f --- /dev/null +++ b/src/lib/libcrypto/des/cbc_cksm.c | |||
| @@ -0,0 +1,103 @@ | |||
| 1 | /* crypto/des/cbc_cksm.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 "des_locl.h" | ||
| 60 | |||
| 61 | DES_LONG des_cbc_cksum(input, output, length, schedule, ivec) | ||
| 62 | des_cblock (*input); | ||
| 63 | des_cblock (*output); | ||
| 64 | long length; | ||
| 65 | des_key_schedule schedule; | ||
| 66 | des_cblock (*ivec); | ||
| 67 | { | ||
| 68 | register DES_LONG tout0,tout1,tin0,tin1; | ||
| 69 | register long l=length; | ||
| 70 | DES_LONG tin[2]; | ||
| 71 | unsigned char *in,*out,*iv; | ||
| 72 | |||
| 73 | in=(unsigned char *)input; | ||
| 74 | out=(unsigned char *)output; | ||
| 75 | iv=(unsigned char *)ivec; | ||
| 76 | |||
| 77 | c2l(iv,tout0); | ||
| 78 | c2l(iv,tout1); | ||
| 79 | for (; l>0; l-=8) | ||
| 80 | { | ||
| 81 | if (l >= 8) | ||
| 82 | { | ||
| 83 | c2l(in,tin0); | ||
| 84 | c2l(in,tin1); | ||
| 85 | } | ||
| 86 | else | ||
| 87 | c2ln(in,tin0,tin1,l); | ||
| 88 | |||
| 89 | tin0^=tout0; tin[0]=tin0; | ||
| 90 | tin1^=tout1; tin[1]=tin1; | ||
| 91 | des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); | ||
| 92 | /* fix 15/10/91 eay - thanks to keithr@sco.COM */ | ||
| 93 | tout0=tin[0]; | ||
| 94 | tout1=tin[1]; | ||
| 95 | } | ||
| 96 | if (out != NULL) | ||
| 97 | { | ||
| 98 | l2c(tout0,out); | ||
| 99 | l2c(tout1,out); | ||
| 100 | } | ||
| 101 | tout0=tin0=tin1=tin[0]=tin[1]=0; | ||
| 102 | return(tout1); | ||
| 103 | } | ||
diff --git a/src/lib/libcrypto/des/cbc_enc.c b/src/lib/libcrypto/des/cbc_enc.c new file mode 100644 index 0000000000..a84a53633c --- /dev/null +++ b/src/lib/libcrypto/des/cbc_enc.c | |||
| @@ -0,0 +1,135 @@ | |||
| 1 | /* crypto/des/cbc_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 "des_locl.h" | ||
| 60 | |||
| 61 | void des_cbc_encrypt(input, output, length, schedule, ivec, enc) | ||
| 62 | des_cblock (*input); | ||
| 63 | des_cblock (*output); | ||
| 64 | long length; | ||
| 65 | des_key_schedule schedule; | ||
| 66 | des_cblock (*ivec); | ||
| 67 | int enc; | ||
| 68 | { | ||
| 69 | register DES_LONG tin0,tin1; | ||
| 70 | register DES_LONG tout0,tout1,xor0,xor1; | ||
| 71 | register unsigned char *in,*out; | ||
| 72 | register long l=length; | ||
| 73 | DES_LONG tin[2]; | ||
| 74 | unsigned char *iv; | ||
| 75 | |||
| 76 | in=(unsigned char *)input; | ||
| 77 | out=(unsigned char *)output; | ||
| 78 | iv=(unsigned char *)ivec; | ||
| 79 | |||
| 80 | if (enc) | ||
| 81 | { | ||
| 82 | c2l(iv,tout0); | ||
| 83 | c2l(iv,tout1); | ||
| 84 | for (l-=8; l>=0; l-=8) | ||
| 85 | { | ||
| 86 | c2l(in,tin0); | ||
| 87 | c2l(in,tin1); | ||
| 88 | tin0^=tout0; tin[0]=tin0; | ||
| 89 | tin1^=tout1; tin[1]=tin1; | ||
| 90 | des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); | ||
| 91 | tout0=tin[0]; l2c(tout0,out); | ||
| 92 | tout1=tin[1]; l2c(tout1,out); | ||
| 93 | } | ||
| 94 | if (l != -8) | ||
| 95 | { | ||
| 96 | c2ln(in,tin0,tin1,l+8); | ||
| 97 | tin0^=tout0; tin[0]=tin0; | ||
| 98 | tin1^=tout1; tin[1]=tin1; | ||
| 99 | des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); | ||
| 100 | tout0=tin[0]; l2c(tout0,out); | ||
| 101 | tout1=tin[1]; l2c(tout1,out); | ||
| 102 | } | ||
| 103 | } | ||
| 104 | else | ||
| 105 | { | ||
| 106 | c2l(iv,xor0); | ||
| 107 | c2l(iv,xor1); | ||
| 108 | for (l-=8; l>=0; l-=8) | ||
| 109 | { | ||
| 110 | c2l(in,tin0); tin[0]=tin0; | ||
| 111 | c2l(in,tin1); tin[1]=tin1; | ||
| 112 | des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); | ||
| 113 | tout0=tin[0]^xor0; | ||
| 114 | tout1=tin[1]^xor1; | ||
| 115 | l2c(tout0,out); | ||
| 116 | l2c(tout1,out); | ||
| 117 | xor0=tin0; | ||
| 118 | xor1=tin1; | ||
| 119 | } | ||
| 120 | if (l != -8) | ||
| 121 | { | ||
| 122 | c2l(in,tin0); tin[0]=tin0; | ||
| 123 | c2l(in,tin1); tin[1]=tin1; | ||
| 124 | des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); | ||
| 125 | tout0=tin[0]^xor0; | ||
| 126 | tout1=tin[1]^xor1; | ||
| 127 | l2cn(tout0,tout1,out,l+8); | ||
| 128 | /* xor0=tin0; | ||
| 129 | xor1=tin1; */ | ||
| 130 | } | ||
| 131 | } | ||
| 132 | tin0=tin1=tout0=tout1=xor0=xor1=0; | ||
| 133 | tin[0]=tin[1]=0; | ||
| 134 | } | ||
| 135 | |||
diff --git a/src/lib/libcrypto/des/cfb64ede.c b/src/lib/libcrypto/des/cfb64ede.c new file mode 100644 index 0000000000..80b8a9eaaa --- /dev/null +++ b/src/lib/libcrypto/des/cfb64ede.c | |||
| @@ -0,0 +1,151 @@ | |||
| 1 | /* crypto/des/cfb64ede.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 "des_locl.h" | ||
| 60 | |||
| 61 | /* The input and output encrypted as though 64bit cfb mode is being | ||
| 62 | * used. The extra state information to record how much of the | ||
| 63 | * 64bit block we have used is contained in *num; | ||
| 64 | */ | ||
| 65 | |||
| 66 | void des_ede3_cfb64_encrypt(in, out, length, ks1,ks2,ks3, ivec, num, enc) | ||
| 67 | unsigned char *in; | ||
| 68 | unsigned char *out; | ||
| 69 | long length; | ||
| 70 | des_key_schedule ks1,ks2,ks3; | ||
| 71 | des_cblock (*ivec); | ||
| 72 | int *num; | ||
| 73 | int enc; | ||
| 74 | { | ||
| 75 | register DES_LONG v0,v1; | ||
| 76 | register long l=length; | ||
| 77 | register int n= *num; | ||
| 78 | DES_LONG ti[2]; | ||
| 79 | unsigned char *iv,c,cc; | ||
| 80 | |||
| 81 | iv=(unsigned char *)ivec; | ||
| 82 | if (enc) | ||
| 83 | { | ||
| 84 | while (l--) | ||
| 85 | { | ||
| 86 | if (n == 0) | ||
| 87 | { | ||
| 88 | c2l(iv,v0); | ||
| 89 | c2l(iv,v1); | ||
| 90 | |||
| 91 | ti[0]=v0; | ||
| 92 | ti[1]=v1; | ||
| 93 | des_encrypt3((DES_LONG *)ti,ks1,ks2,ks3); | ||
| 94 | v0=ti[0]; | ||
| 95 | v1=ti[1]; | ||
| 96 | |||
| 97 | iv=(unsigned char *)ivec; | ||
| 98 | l2c(v0,iv); | ||
| 99 | l2c(v1,iv); | ||
| 100 | iv=(unsigned char *)ivec; | ||
| 101 | } | ||
| 102 | c= *(in++)^iv[n]; | ||
| 103 | *(out++)=c; | ||
| 104 | iv[n]=c; | ||
| 105 | n=(n+1)&0x07; | ||
| 106 | } | ||
| 107 | } | ||
| 108 | else | ||
| 109 | { | ||
| 110 | while (l--) | ||
| 111 | { | ||
| 112 | if (n == 0) | ||
| 113 | { | ||
| 114 | c2l(iv,v0); | ||
| 115 | c2l(iv,v1); | ||
| 116 | |||
| 117 | ti[0]=v0; | ||
| 118 | ti[1]=v1; | ||
| 119 | des_encrypt3((DES_LONG *)ti,ks1,ks2,ks3); | ||
| 120 | v0=ti[0]; | ||
| 121 | v1=ti[1]; | ||
| 122 | |||
| 123 | iv=(unsigned char *)ivec; | ||
| 124 | l2c(v0,iv); | ||
| 125 | l2c(v1,iv); | ||
| 126 | iv=(unsigned char *)ivec; | ||
| 127 | } | ||
| 128 | cc= *(in++); | ||
| 129 | c=iv[n]; | ||
| 130 | iv[n]=cc; | ||
| 131 | *(out++)=c^cc; | ||
| 132 | n=(n+1)&0x07; | ||
| 133 | } | ||
| 134 | } | ||
| 135 | v0=v1=ti[0]=ti[1]=c=cc=0; | ||
| 136 | *num=n; | ||
| 137 | } | ||
| 138 | |||
| 139 | #ifdef undef /* MACRO */ | ||
| 140 | void des_ede2_cfb64_encrypt(in, out, length, ks1,ks2, ivec, num, enc) | ||
| 141 | unsigned char *in; | ||
| 142 | unsigned char *out; | ||
| 143 | long length; | ||
| 144 | des_key_schedule ks1,ks2; | ||
| 145 | des_cblock (*ivec); | ||
| 146 | int *num; | ||
| 147 | int enc; | ||
| 148 | { | ||
| 149 | des_ede3_cfb64_encrypt(in,out,length,ks1,ks2,ks1,ivec,num,enc); | ||
| 150 | } | ||
| 151 | #endif | ||
diff --git a/src/lib/libcrypto/des/cfb64enc.c b/src/lib/libcrypto/des/cfb64enc.c new file mode 100644 index 0000000000..403da479df --- /dev/null +++ b/src/lib/libcrypto/des/cfb64enc.c | |||
| @@ -0,0 +1,128 @@ | |||
| 1 | /* crypto/des/cfb64enc.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 "des_locl.h" | ||
| 60 | |||
| 61 | /* The input and output encrypted as though 64bit cfb mode is being | ||
| 62 | * used. The extra state information to record how much of the | ||
| 63 | * 64bit block we have used is contained in *num; | ||
| 64 | */ | ||
| 65 | |||
| 66 | void des_cfb64_encrypt(in, out, length, schedule, ivec, num, enc) | ||
| 67 | unsigned char *in; | ||
| 68 | unsigned char *out; | ||
| 69 | long length; | ||
| 70 | des_key_schedule schedule; | ||
| 71 | des_cblock (*ivec); | ||
| 72 | int *num; | ||
| 73 | int enc; | ||
| 74 | { | ||
| 75 | register DES_LONG v0,v1; | ||
| 76 | register long l=length; | ||
| 77 | register int n= *num; | ||
| 78 | DES_LONG ti[2]; | ||
| 79 | unsigned char *iv,c,cc; | ||
| 80 | |||
| 81 | iv=(unsigned char *)ivec; | ||
| 82 | if (enc) | ||
| 83 | { | ||
| 84 | while (l--) | ||
| 85 | { | ||
| 86 | if (n == 0) | ||
| 87 | { | ||
| 88 | c2l(iv,v0); ti[0]=v0; | ||
| 89 | c2l(iv,v1); ti[1]=v1; | ||
| 90 | des_encrypt((DES_LONG *)ti, | ||
| 91 | schedule,DES_ENCRYPT); | ||
| 92 | iv=(unsigned char *)ivec; | ||
| 93 | v0=ti[0]; l2c(v0,iv); | ||
| 94 | v0=ti[1]; l2c(v0,iv); | ||
| 95 | iv=(unsigned char *)ivec; | ||
| 96 | } | ||
| 97 | c= *(in++)^iv[n]; | ||
| 98 | *(out++)=c; | ||
| 99 | iv[n]=c; | ||
| 100 | n=(n+1)&0x07; | ||
| 101 | } | ||
| 102 | } | ||
| 103 | else | ||
| 104 | { | ||
| 105 | while (l--) | ||
| 106 | { | ||
| 107 | if (n == 0) | ||
| 108 | { | ||
| 109 | c2l(iv,v0); ti[0]=v0; | ||
| 110 | c2l(iv,v1); ti[1]=v1; | ||
| 111 | des_encrypt((DES_LONG *)ti, | ||
| 112 | schedule,DES_ENCRYPT); | ||
| 113 | iv=(unsigned char *)ivec; | ||
| 114 | v0=ti[0]; l2c(v0,iv); | ||
| 115 | v0=ti[1]; l2c(v0,iv); | ||
| 116 | iv=(unsigned char *)ivec; | ||
| 117 | } | ||
| 118 | cc= *(in++); | ||
| 119 | c=iv[n]; | ||
| 120 | iv[n]=cc; | ||
| 121 | *(out++)=c^cc; | ||
| 122 | n=(n+1)&0x07; | ||
| 123 | } | ||
| 124 | } | ||
| 125 | v0=v1=ti[0]=ti[1]=c=cc=0; | ||
| 126 | *num=n; | ||
| 127 | } | ||
| 128 | |||
diff --git a/src/lib/libcrypto/des/cfb_enc.c b/src/lib/libcrypto/des/cfb_enc.c new file mode 100644 index 0000000000..342e785691 --- /dev/null +++ b/src/lib/libcrypto/des/cfb_enc.c | |||
| @@ -0,0 +1,171 @@ | |||
| 1 | /* crypto/des/cfb_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 "des_locl.h" | ||
| 60 | |||
| 61 | /* The input and output are loaded in multiples of 8 bits. | ||
| 62 | * What this means is that if you hame numbits=12 and length=2 | ||
| 63 | * the first 12 bits will be retrieved from the first byte and half | ||
| 64 | * the second. The second 12 bits will come from the 3rd and half the 4th | ||
| 65 | * byte. | ||
| 66 | */ | ||
| 67 | void des_cfb_encrypt(in, out, numbits, length, schedule, ivec, enc) | ||
| 68 | unsigned char *in; | ||
| 69 | unsigned char *out; | ||
| 70 | int numbits; | ||
| 71 | long length; | ||
| 72 | des_key_schedule schedule; | ||
| 73 | des_cblock (*ivec); | ||
| 74 | int enc; | ||
| 75 | { | ||
| 76 | register DES_LONG d0,d1,v0,v1,n=(numbits+7)/8; | ||
| 77 | register DES_LONG mask0,mask1; | ||
| 78 | register unsigned long l=length; | ||
| 79 | register int num=numbits; | ||
| 80 | DES_LONG ti[2]; | ||
| 81 | unsigned char *iv; | ||
| 82 | |||
| 83 | if (num > 64) return; | ||
| 84 | if (num > 32) | ||
| 85 | { | ||
| 86 | mask0=0xffffffffL; | ||
| 87 | if (num == 64) | ||
| 88 | mask1=mask0; | ||
| 89 | else mask1=(1L<<(num-32))-1; | ||
| 90 | } | ||
| 91 | else | ||
| 92 | { | ||
| 93 | if (num == 32) | ||
| 94 | mask0=0xffffffffL; | ||
| 95 | else mask0=(1L<<num)-1; | ||
| 96 | mask1=0x00000000L; | ||
| 97 | } | ||
| 98 | |||
| 99 | iv=(unsigned char *)ivec; | ||
| 100 | c2l(iv,v0); | ||
| 101 | c2l(iv,v1); | ||
| 102 | if (enc) | ||
| 103 | { | ||
| 104 | while (l >= n) | ||
| 105 | { | ||
| 106 | l-=n; | ||
| 107 | ti[0]=v0; | ||
| 108 | ti[1]=v1; | ||
| 109 | des_encrypt((DES_LONG *)ti,schedule,DES_ENCRYPT); | ||
| 110 | c2ln(in,d0,d1,n); | ||
| 111 | in+=n; | ||
| 112 | d0=(d0^ti[0])&mask0; | ||
| 113 | d1=(d1^ti[1])&mask1; | ||
| 114 | l2cn(d0,d1,out,n); | ||
| 115 | out+=n; | ||
| 116 | /* 30-08-94 - eay - changed because l>>32 and | ||
| 117 | * l<<32 are bad under gcc :-( */ | ||
| 118 | if (num == 32) | ||
| 119 | { v0=v1; v1=d0; } | ||
| 120 | else if (num == 64) | ||
| 121 | { v0=d0; v1=d1; } | ||
| 122 | else if (num > 32) /* && num != 64 */ | ||
| 123 | { | ||
| 124 | v0=((v1>>(num-32))|(d0<<(64-num)))&0xffffffffL; | ||
| 125 | v1=((d0>>(num-32))|(d1<<(64-num)))&0xffffffffL; | ||
| 126 | } | ||
| 127 | else /* num < 32 */ | ||
| 128 | { | ||
| 129 | v0=((v0>>num)|(v1<<(32-num)))&0xffffffffL; | ||
| 130 | v1=((v1>>num)|(d0<<(32-num)))&0xffffffffL; | ||
| 131 | } | ||
| 132 | } | ||
| 133 | } | ||
| 134 | else | ||
| 135 | { | ||
| 136 | while (l >= n) | ||
| 137 | { | ||
| 138 | l-=n; | ||
| 139 | ti[0]=v0; | ||
| 140 | ti[1]=v1; | ||
| 141 | des_encrypt((DES_LONG *)ti,schedule,DES_ENCRYPT); | ||
| 142 | c2ln(in,d0,d1,n); | ||
| 143 | in+=n; | ||
| 144 | /* 30-08-94 - eay - changed because l>>32 and | ||
| 145 | * l<<32 are bad under gcc :-( */ | ||
| 146 | if (num == 32) | ||
| 147 | { v0=v1; v1=d0; } | ||
| 148 | else if (num == 64) | ||
| 149 | { v0=d0; v1=d1; } | ||
| 150 | else if (num > 32) /* && num != 64 */ | ||
| 151 | { | ||
| 152 | v0=((v1>>(num-32))|(d0<<(64-num)))&0xffffffffL; | ||
| 153 | v1=((d0>>(num-32))|(d1<<(64-num)))&0xffffffffL; | ||
| 154 | } | ||
| 155 | else /* num < 32 */ | ||
| 156 | { | ||
| 157 | v0=((v0>>num)|(v1<<(32-num)))&0xffffffffL; | ||
| 158 | v1=((v1>>num)|(d0<<(32-num)))&0xffffffffL; | ||
| 159 | } | ||
| 160 | d0=(d0^ti[0])&mask0; | ||
| 161 | d1=(d1^ti[1])&mask1; | ||
| 162 | l2cn(d0,d1,out,n); | ||
| 163 | out+=n; | ||
| 164 | } | ||
| 165 | } | ||
| 166 | iv=(unsigned char *)ivec; | ||
| 167 | l2c(v0,iv); | ||
| 168 | l2c(v1,iv); | ||
| 169 | v0=v1=d0=d1=ti[0]=ti[1]=0; | ||
| 170 | } | ||
| 171 | |||
diff --git a/src/lib/libcrypto/des/des_enc.c b/src/lib/libcrypto/des/des_enc.c new file mode 100644 index 0000000000..e4db09299e --- /dev/null +++ b/src/lib/libcrypto/des/des_enc.c | |||
| @@ -0,0 +1,502 @@ | |||
| 1 | /* crypto/des/des_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 "des_locl.h" | ||
| 60 | |||
| 61 | void des_encrypt(data, ks, enc) | ||
| 62 | DES_LONG *data; | ||
| 63 | des_key_schedule ks; | ||
| 64 | int enc; | ||
| 65 | { | ||
| 66 | register DES_LONG l,r,t,u; | ||
| 67 | #ifdef DES_PTR | ||
| 68 | register unsigned char *des_SP=(unsigned char *)des_SPtrans; | ||
| 69 | #endif | ||
| 70 | #ifndef DES_UNROLL | ||
| 71 | register int i; | ||
| 72 | #endif | ||
| 73 | register DES_LONG *s; | ||
| 74 | |||
| 75 | r=data[0]; | ||
| 76 | l=data[1]; | ||
| 77 | |||
| 78 | IP(r,l); | ||
| 79 | /* Things have been modified so that the initial rotate is | ||
| 80 | * done outside the loop. This required the | ||
| 81 | * des_SPtrans values in sp.h to be rotated 1 bit to the right. | ||
| 82 | * One perl script later and things have a 5% speed up on a sparc2. | ||
| 83 | * Thanks to Richard Outerbridge <71755.204@CompuServe.COM> | ||
| 84 | * for pointing this out. */ | ||
| 85 | /* clear the top bits on machines with 8byte longs */ | ||
| 86 | /* shift left by 2 */ | ||
| 87 | r=ROTATE(r,29)&0xffffffffL; | ||
| 88 | l=ROTATE(l,29)&0xffffffffL; | ||
| 89 | |||
| 90 | s=(DES_LONG *)ks; | ||
| 91 | /* I don't know if it is worth the effort of loop unrolling the | ||
| 92 | * inner loop */ | ||
| 93 | if (enc) | ||
| 94 | { | ||
| 95 | #ifdef DES_UNROLL | ||
| 96 | D_ENCRYPT(l,r, 0); /* 1 */ | ||
| 97 | D_ENCRYPT(r,l, 2); /* 2 */ | ||
| 98 | D_ENCRYPT(l,r, 4); /* 3 */ | ||
| 99 | D_ENCRYPT(r,l, 6); /* 4 */ | ||
| 100 | D_ENCRYPT(l,r, 8); /* 5 */ | ||
| 101 | D_ENCRYPT(r,l,10); /* 6 */ | ||
| 102 | D_ENCRYPT(l,r,12); /* 7 */ | ||
| 103 | D_ENCRYPT(r,l,14); /* 8 */ | ||
| 104 | D_ENCRYPT(l,r,16); /* 9 */ | ||
| 105 | D_ENCRYPT(r,l,18); /* 10 */ | ||
| 106 | D_ENCRYPT(l,r,20); /* 11 */ | ||
| 107 | D_ENCRYPT(r,l,22); /* 12 */ | ||
| 108 | D_ENCRYPT(l,r,24); /* 13 */ | ||
| 109 | D_ENCRYPT(r,l,26); /* 14 */ | ||
| 110 | D_ENCRYPT(l,r,28); /* 15 */ | ||
| 111 | D_ENCRYPT(r,l,30); /* 16 */ | ||
| 112 | #else | ||
| 113 | for (i=0; i<32; i+=8) | ||
| 114 | { | ||
| 115 | D_ENCRYPT(l,r,i+0); /* 1 */ | ||
| 116 | D_ENCRYPT(r,l,i+2); /* 2 */ | ||
| 117 | D_ENCRYPT(l,r,i+4); /* 3 */ | ||
| 118 | D_ENCRYPT(r,l,i+6); /* 4 */ | ||
| 119 | } | ||
| 120 | #endif | ||
| 121 | } | ||
| 122 | else | ||
| 123 | { | ||
| 124 | #ifdef DES_UNROLL | ||
| 125 | D_ENCRYPT(l,r,30); /* 16 */ | ||
| 126 | D_ENCRYPT(r,l,28); /* 15 */ | ||
| 127 | D_ENCRYPT(l,r,26); /* 14 */ | ||
| 128 | D_ENCRYPT(r,l,24); /* 13 */ | ||
| 129 | D_ENCRYPT(l,r,22); /* 12 */ | ||
| 130 | D_ENCRYPT(r,l,20); /* 11 */ | ||
| 131 | D_ENCRYPT(l,r,18); /* 10 */ | ||
| 132 | D_ENCRYPT(r,l,16); /* 9 */ | ||
| 133 | D_ENCRYPT(l,r,14); /* 8 */ | ||
| 134 | D_ENCRYPT(r,l,12); /* 7 */ | ||
| 135 | D_ENCRYPT(l,r,10); /* 6 */ | ||
| 136 | D_ENCRYPT(r,l, 8); /* 5 */ | ||
| 137 | D_ENCRYPT(l,r, 6); /* 4 */ | ||
| 138 | D_ENCRYPT(r,l, 4); /* 3 */ | ||
| 139 | D_ENCRYPT(l,r, 2); /* 2 */ | ||
| 140 | D_ENCRYPT(r,l, 0); /* 1 */ | ||
| 141 | #else | ||
| 142 | for (i=30; i>0; i-=8) | ||
| 143 | { | ||
| 144 | D_ENCRYPT(l,r,i-0); /* 16 */ | ||
| 145 | D_ENCRYPT(r,l,i-2); /* 15 */ | ||
| 146 | D_ENCRYPT(l,r,i-4); /* 14 */ | ||
| 147 | D_ENCRYPT(r,l,i-6); /* 13 */ | ||
| 148 | } | ||
| 149 | #endif | ||
| 150 | } | ||
| 151 | |||
| 152 | /* rotate and clear the top bits on machines with 8byte longs */ | ||
| 153 | l=ROTATE(l,3)&0xffffffffL; | ||
| 154 | r=ROTATE(r,3)&0xffffffffL; | ||
| 155 | |||
| 156 | FP(r,l); | ||
| 157 | data[0]=l; | ||
| 158 | data[1]=r; | ||
| 159 | l=r=t=u=0; | ||
| 160 | } | ||
| 161 | |||
| 162 | void des_encrypt2(data, ks, enc) | ||
| 163 | DES_LONG *data; | ||
| 164 | des_key_schedule ks; | ||
| 165 | int enc; | ||
| 166 | { | ||
| 167 | register DES_LONG l,r,t,u; | ||
| 168 | #ifdef DES_PTR | ||
| 169 | register unsigned char *des_SP=(unsigned char *)des_SPtrans; | ||
| 170 | #endif | ||
| 171 | #ifndef DES_UNROLL | ||
| 172 | register int i; | ||
| 173 | #endif | ||
| 174 | register DES_LONG *s; | ||
| 175 | |||
| 176 | r=data[0]; | ||
| 177 | l=data[1]; | ||
| 178 | |||
| 179 | /* Things have been modified so that the initial rotate is | ||
| 180 | * done outside the loop. This required the | ||
| 181 | * des_SPtrans values in sp.h to be rotated 1 bit to the right. | ||
| 182 | * One perl script later and things have a 5% speed up on a sparc2. | ||
| 183 | * Thanks to Richard Outerbridge <71755.204@CompuServe.COM> | ||
| 184 | * for pointing this out. */ | ||
| 185 | /* clear the top bits on machines with 8byte longs */ | ||
| 186 | r=ROTATE(r,29)&0xffffffffL; | ||
| 187 | l=ROTATE(l,29)&0xffffffffL; | ||
| 188 | |||
| 189 | s=(DES_LONG *)ks; | ||
| 190 | /* I don't know if it is worth the effort of loop unrolling the | ||
| 191 | * inner loop */ | ||
| 192 | if (enc) | ||
| 193 | { | ||
| 194 | #ifdef DES_UNROLL | ||
| 195 | D_ENCRYPT(l,r, 0); /* 1 */ | ||
| 196 | D_ENCRYPT(r,l, 2); /* 2 */ | ||
| 197 | D_ENCRYPT(l,r, 4); /* 3 */ | ||
| 198 | D_ENCRYPT(r,l, 6); /* 4 */ | ||
| 199 | D_ENCRYPT(l,r, 8); /* 5 */ | ||
| 200 | D_ENCRYPT(r,l,10); /* 6 */ | ||
| 201 | D_ENCRYPT(l,r,12); /* 7 */ | ||
| 202 | D_ENCRYPT(r,l,14); /* 8 */ | ||
| 203 | D_ENCRYPT(l,r,16); /* 9 */ | ||
| 204 | D_ENCRYPT(r,l,18); /* 10 */ | ||
| 205 | D_ENCRYPT(l,r,20); /* 11 */ | ||
| 206 | D_ENCRYPT(r,l,22); /* 12 */ | ||
| 207 | D_ENCRYPT(l,r,24); /* 13 */ | ||
| 208 | D_ENCRYPT(r,l,26); /* 14 */ | ||
| 209 | D_ENCRYPT(l,r,28); /* 15 */ | ||
| 210 | D_ENCRYPT(r,l,30); /* 16 */ | ||
| 211 | #else | ||
| 212 | for (i=0; i<32; i+=8) | ||
| 213 | { | ||
| 214 | D_ENCRYPT(l,r,i+0); /* 1 */ | ||
| 215 | D_ENCRYPT(r,l,i+2); /* 2 */ | ||
| 216 | D_ENCRYPT(l,r,i+4); /* 3 */ | ||
| 217 | D_ENCRYPT(r,l,i+6); /* 4 */ | ||
| 218 | } | ||
| 219 | #endif | ||
| 220 | } | ||
| 221 | else | ||
| 222 | { | ||
| 223 | #ifdef DES_UNROLL | ||
| 224 | D_ENCRYPT(l,r,30); /* 16 */ | ||
| 225 | D_ENCRYPT(r,l,28); /* 15 */ | ||
| 226 | D_ENCRYPT(l,r,26); /* 14 */ | ||
| 227 | D_ENCRYPT(r,l,24); /* 13 */ | ||
| 228 | D_ENCRYPT(l,r,22); /* 12 */ | ||
| 229 | D_ENCRYPT(r,l,20); /* 11 */ | ||
| 230 | D_ENCRYPT(l,r,18); /* 10 */ | ||
| 231 | D_ENCRYPT(r,l,16); /* 9 */ | ||
| 232 | D_ENCRYPT(l,r,14); /* 8 */ | ||
| 233 | D_ENCRYPT(r,l,12); /* 7 */ | ||
| 234 | D_ENCRYPT(l,r,10); /* 6 */ | ||
| 235 | D_ENCRYPT(r,l, 8); /* 5 */ | ||
| 236 | D_ENCRYPT(l,r, 6); /* 4 */ | ||
| 237 | D_ENCRYPT(r,l, 4); /* 3 */ | ||
| 238 | D_ENCRYPT(l,r, 2); /* 2 */ | ||
| 239 | D_ENCRYPT(r,l, 0); /* 1 */ | ||
| 240 | #else | ||
| 241 | for (i=30; i>0; i-=8) | ||
| 242 | { | ||
| 243 | D_ENCRYPT(l,r,i-0); /* 16 */ | ||
| 244 | D_ENCRYPT(r,l,i-2); /* 15 */ | ||
| 245 | D_ENCRYPT(l,r,i-4); /* 14 */ | ||
| 246 | D_ENCRYPT(r,l,i-6); /* 13 */ | ||
| 247 | } | ||
| 248 | #endif | ||
| 249 | } | ||
| 250 | /* rotate and clear the top bits on machines with 8byte longs */ | ||
| 251 | data[0]=ROTATE(l,3)&0xffffffffL; | ||
| 252 | data[1]=ROTATE(r,3)&0xffffffffL; | ||
| 253 | l=r=t=u=0; | ||
| 254 | } | ||
| 255 | |||
| 256 | void des_encrypt3(data,ks1,ks2,ks3) | ||
| 257 | DES_LONG *data; | ||
| 258 | des_key_schedule ks1; | ||
| 259 | des_key_schedule ks2; | ||
| 260 | des_key_schedule ks3; | ||
| 261 | { | ||
| 262 | register DES_LONG l,r; | ||
| 263 | |||
| 264 | l=data[0]; | ||
| 265 | r=data[1]; | ||
| 266 | IP(l,r); | ||
| 267 | data[0]=l; | ||
| 268 | data[1]=r; | ||
| 269 | des_encrypt2((DES_LONG *)data,ks1,DES_ENCRYPT); | ||
| 270 | des_encrypt2((DES_LONG *)data,ks2,DES_DECRYPT); | ||
| 271 | des_encrypt2((DES_LONG *)data,ks3,DES_ENCRYPT); | ||
| 272 | l=data[0]; | ||
| 273 | r=data[1]; | ||
| 274 | FP(r,l); | ||
| 275 | data[0]=l; | ||
| 276 | data[1]=r; | ||
| 277 | } | ||
| 278 | |||
| 279 | void des_decrypt3(data,ks1,ks2,ks3) | ||
| 280 | DES_LONG *data; | ||
| 281 | des_key_schedule ks1; | ||
| 282 | des_key_schedule ks2; | ||
| 283 | des_key_schedule ks3; | ||
| 284 | { | ||
| 285 | register DES_LONG l,r; | ||
| 286 | |||
| 287 | l=data[0]; | ||
| 288 | r=data[1]; | ||
| 289 | IP(l,r); | ||
| 290 | data[0]=l; | ||
| 291 | data[1]=r; | ||
| 292 | des_encrypt2((DES_LONG *)data,ks3,DES_DECRYPT); | ||
| 293 | des_encrypt2((DES_LONG *)data,ks2,DES_ENCRYPT); | ||
| 294 | des_encrypt2((DES_LONG *)data,ks1,DES_DECRYPT); | ||
| 295 | l=data[0]; | ||
| 296 | r=data[1]; | ||
| 297 | FP(r,l); | ||
| 298 | data[0]=l; | ||
| 299 | data[1]=r; | ||
| 300 | } | ||
| 301 | |||
| 302 | #ifndef DES_DEFAULT_OPTIONS | ||
| 303 | |||
| 304 | void des_ncbc_encrypt(input, output, length, schedule, ivec, enc) | ||
| 305 | des_cblock (*input); | ||
| 306 | des_cblock (*output); | ||
| 307 | long length; | ||
| 308 | des_key_schedule schedule; | ||
| 309 | des_cblock (*ivec); | ||
| 310 | int enc; | ||
| 311 | { | ||
| 312 | register DES_LONG tin0,tin1; | ||
| 313 | register DES_LONG tout0,tout1,xor0,xor1; | ||
| 314 | register unsigned char *in,*out; | ||
| 315 | register long l=length; | ||
| 316 | DES_LONG tin[2]; | ||
| 317 | unsigned char *iv; | ||
| 318 | |||
| 319 | in=(unsigned char *)input; | ||
| 320 | out=(unsigned char *)output; | ||
| 321 | iv=(unsigned char *)ivec; | ||
| 322 | |||
| 323 | if (enc) | ||
| 324 | { | ||
| 325 | c2l(iv,tout0); | ||
| 326 | c2l(iv,tout1); | ||
| 327 | for (l-=8; l>=0; l-=8) | ||
| 328 | { | ||
| 329 | c2l(in,tin0); | ||
| 330 | c2l(in,tin1); | ||
| 331 | tin0^=tout0; tin[0]=tin0; | ||
| 332 | tin1^=tout1; tin[1]=tin1; | ||
| 333 | des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); | ||
| 334 | tout0=tin[0]; l2c(tout0,out); | ||
| 335 | tout1=tin[1]; l2c(tout1,out); | ||
| 336 | } | ||
| 337 | if (l != -8) | ||
| 338 | { | ||
| 339 | c2ln(in,tin0,tin1,l+8); | ||
| 340 | tin0^=tout0; tin[0]=tin0; | ||
| 341 | tin1^=tout1; tin[1]=tin1; | ||
| 342 | des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); | ||
| 343 | tout0=tin[0]; l2c(tout0,out); | ||
| 344 | tout1=tin[1]; l2c(tout1,out); | ||
| 345 | } | ||
| 346 | iv=(unsigned char *)ivec; | ||
| 347 | l2c(tout0,iv); | ||
| 348 | l2c(tout1,iv); | ||
| 349 | } | ||
| 350 | else | ||
| 351 | { | ||
| 352 | c2l(iv,xor0); | ||
| 353 | c2l(iv,xor1); | ||
| 354 | for (l-=8; l>=0; l-=8) | ||
| 355 | { | ||
| 356 | c2l(in,tin0); tin[0]=tin0; | ||
| 357 | c2l(in,tin1); tin[1]=tin1; | ||
| 358 | des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); | ||
| 359 | tout0=tin[0]^xor0; | ||
| 360 | tout1=tin[1]^xor1; | ||
| 361 | l2c(tout0,out); | ||
| 362 | l2c(tout1,out); | ||
| 363 | xor0=tin0; | ||
| 364 | xor1=tin1; | ||
| 365 | } | ||
| 366 | if (l != -8) | ||
| 367 | { | ||
| 368 | c2l(in,tin0); tin[0]=tin0; | ||
| 369 | c2l(in,tin1); tin[1]=tin1; | ||
| 370 | des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); | ||
| 371 | tout0=tin[0]^xor0; | ||
| 372 | tout1=tin[1]^xor1; | ||
| 373 | l2cn(tout0,tout1,out,l+8); | ||
| 374 | xor0=tin0; | ||
| 375 | xor1=tin1; | ||
| 376 | } | ||
| 377 | |||
| 378 | iv=(unsigned char *)ivec; | ||
| 379 | l2c(xor0,iv); | ||
| 380 | l2c(xor1,iv); | ||
| 381 | } | ||
| 382 | tin0=tin1=tout0=tout1=xor0=xor1=0; | ||
| 383 | tin[0]=tin[1]=0; | ||
| 384 | } | ||
| 385 | |||
| 386 | void des_ede3_cbc_encrypt(input, output, length, ks1, ks2, ks3, ivec, enc) | ||
| 387 | des_cblock (*input); | ||
| 388 | des_cblock (*output); | ||
| 389 | long length; | ||
| 390 | des_key_schedule ks1; | ||
| 391 | des_key_schedule ks2; | ||
| 392 | des_key_schedule ks3; | ||
| 393 | des_cblock (*ivec); | ||
| 394 | int enc; | ||
| 395 | { | ||
| 396 | register DES_LONG tin0,tin1; | ||
| 397 | register DES_LONG tout0,tout1,xor0,xor1; | ||
| 398 | register unsigned char *in,*out; | ||
| 399 | register long l=length; | ||
| 400 | DES_LONG tin[2]; | ||
| 401 | unsigned char *iv; | ||
| 402 | |||
| 403 | in=(unsigned char *)input; | ||
| 404 | out=(unsigned char *)output; | ||
| 405 | iv=(unsigned char *)ivec; | ||
| 406 | |||
| 407 | if (enc) | ||
| 408 | { | ||
| 409 | c2l(iv,tout0); | ||
| 410 | c2l(iv,tout1); | ||
| 411 | for (l-=8; l>=0; l-=8) | ||
| 412 | { | ||
| 413 | c2l(in,tin0); | ||
| 414 | c2l(in,tin1); | ||
| 415 | tin0^=tout0; | ||
| 416 | tin1^=tout1; | ||
| 417 | |||
| 418 | tin[0]=tin0; | ||
| 419 | tin[1]=tin1; | ||
| 420 | des_encrypt3((DES_LONG *)tin,ks1,ks2,ks3); | ||
| 421 | tout0=tin[0]; | ||
| 422 | tout1=tin[1]; | ||
| 423 | |||
| 424 | l2c(tout0,out); | ||
| 425 | l2c(tout1,out); | ||
| 426 | } | ||
| 427 | if (l != -8) | ||
| 428 | { | ||
| 429 | c2ln(in,tin0,tin1,l+8); | ||
| 430 | tin0^=tout0; | ||
| 431 | tin1^=tout1; | ||
| 432 | |||
| 433 | tin[0]=tin0; | ||
| 434 | tin[1]=tin1; | ||
| 435 | des_encrypt3((DES_LONG *)tin,ks1,ks2,ks3); | ||
| 436 | tout0=tin[0]; | ||
| 437 | tout1=tin[1]; | ||
| 438 | |||
| 439 | l2c(tout0,out); | ||
| 440 | l2c(tout1,out); | ||
| 441 | } | ||
| 442 | iv=(unsigned char *)ivec; | ||
| 443 | l2c(tout0,iv); | ||
| 444 | l2c(tout1,iv); | ||
| 445 | } | ||
| 446 | else | ||
| 447 | { | ||
| 448 | register DES_LONG t0,t1; | ||
| 449 | |||
| 450 | c2l(iv,xor0); | ||
| 451 | c2l(iv,xor1); | ||
| 452 | for (l-=8; l>=0; l-=8) | ||
| 453 | { | ||
| 454 | c2l(in,tin0); | ||
| 455 | c2l(in,tin1); | ||
| 456 | |||
| 457 | t0=tin0; | ||
| 458 | t1=tin1; | ||
| 459 | |||
| 460 | tin[0]=tin0; | ||
| 461 | tin[1]=tin1; | ||
| 462 | des_decrypt3((DES_LONG *)tin,ks1,ks2,ks3); | ||
| 463 | tout0=tin[0]; | ||
| 464 | tout1=tin[1]; | ||
| 465 | |||
| 466 | tout0^=xor0; | ||
| 467 | tout1^=xor1; | ||
| 468 | l2c(tout0,out); | ||
| 469 | l2c(tout1,out); | ||
| 470 | xor0=t0; | ||
| 471 | xor1=t1; | ||
| 472 | } | ||
| 473 | if (l != -8) | ||
| 474 | { | ||
| 475 | c2l(in,tin0); | ||
| 476 | c2l(in,tin1); | ||
| 477 | |||
| 478 | t0=tin0; | ||
| 479 | t1=tin1; | ||
| 480 | |||
| 481 | tin[0]=tin0; | ||
| 482 | tin[1]=tin1; | ||
| 483 | des_decrypt3((DES_LONG *)tin,ks1,ks2,ks3); | ||
| 484 | tout0=tin[0]; | ||
| 485 | tout1=tin[1]; | ||
| 486 | |||
| 487 | tout0^=xor0; | ||
| 488 | tout1^=xor1; | ||
| 489 | l2cn(tout0,tout1,out,l+8); | ||
| 490 | xor0=t0; | ||
| 491 | xor1=t1; | ||
| 492 | } | ||
| 493 | |||
| 494 | iv=(unsigned char *)ivec; | ||
| 495 | l2c(xor0,iv); | ||
| 496 | l2c(xor1,iv); | ||
| 497 | } | ||
| 498 | tin0=tin1=tout0=tout1=xor0=xor1=0; | ||
| 499 | tin[0]=tin[1]=0; | ||
| 500 | } | ||
| 501 | |||
| 502 | #endif /* DES_DEFAULT_OPTIONS */ | ||
diff --git a/src/lib/libcrypto/des/ecb3_enc.c b/src/lib/libcrypto/des/ecb3_enc.c new file mode 100644 index 0000000000..140f6b5285 --- /dev/null +++ b/src/lib/libcrypto/des/ecb3_enc.c | |||
| @@ -0,0 +1,87 @@ | |||
| 1 | /* crypto/des/ecb3_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 "des_locl.h" | ||
| 60 | |||
| 61 | void des_ecb3_encrypt(input, output, ks1, ks2, ks3, enc) | ||
| 62 | des_cblock (*input); | ||
| 63 | des_cblock (*output); | ||
| 64 | des_key_schedule ks1; | ||
| 65 | des_key_schedule ks2; | ||
| 66 | des_key_schedule ks3; | ||
| 67 | int enc; | ||
| 68 | { | ||
| 69 | register DES_LONG l0,l1; | ||
| 70 | register unsigned char *in,*out; | ||
| 71 | DES_LONG ll[2]; | ||
| 72 | |||
| 73 | in=(unsigned char *)input; | ||
| 74 | out=(unsigned char *)output; | ||
| 75 | c2l(in,l0); | ||
| 76 | c2l(in,l1); | ||
| 77 | ll[0]=l0; | ||
| 78 | ll[1]=l1; | ||
| 79 | if (enc) | ||
| 80 | des_encrypt3(ll,ks1,ks2,ks3); | ||
| 81 | else | ||
| 82 | des_decrypt3(ll,ks1,ks2,ks3); | ||
| 83 | l0=ll[0]; | ||
| 84 | l1=ll[1]; | ||
| 85 | l2c(l0,out); | ||
| 86 | l2c(l1,out); | ||
| 87 | } | ||
diff --git a/src/lib/libcrypto/des/ecb_enc.c b/src/lib/libcrypto/des/ecb_enc.c new file mode 100644 index 0000000000..acf23fdd00 --- /dev/null +++ b/src/lib/libcrypto/des/ecb_enc.c | |||
| @@ -0,0 +1,124 @@ | |||
| 1 | /* crypto/des/ecb_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 "des_locl.h" | ||
| 60 | #include "spr.h" | ||
| 61 | |||
| 62 | char *libdes_version="libdes v 3.24 - 20-Apr-1996 - eay"; | ||
| 63 | char *DES_version="DES part of SSLeay 0.9.0b 29-Jun-1998"; | ||
| 64 | |||
| 65 | char *des_options() | ||
| 66 | { | ||
| 67 | static int init=1; | ||
| 68 | static char buf[32]; | ||
| 69 | |||
| 70 | if (init) | ||
| 71 | { | ||
| 72 | char *ptr,*unroll,*risc,*size; | ||
| 73 | |||
| 74 | init=0; | ||
| 75 | #ifdef DES_PTR | ||
| 76 | ptr="ptr"; | ||
| 77 | #else | ||
| 78 | ptr="idx"; | ||
| 79 | #endif | ||
| 80 | #if defined(DES_RISC1) || defined(DES_RISC2) | ||
| 81 | #ifdef DES_RISC1 | ||
| 82 | risc="risc1"; | ||
| 83 | #endif | ||
| 84 | #ifdef DES_RISC2 | ||
| 85 | risc="risc2"; | ||
| 86 | #endif | ||
| 87 | #else | ||
| 88 | risc="cisc"; | ||
| 89 | #endif | ||
| 90 | #ifdef DES_UNROLL | ||
| 91 | unroll="16"; | ||
| 92 | #else | ||
| 93 | unroll="4"; | ||
| 94 | #endif | ||
| 95 | if (sizeof(DES_LONG) != sizeof(long)) | ||
| 96 | size="int"; | ||
| 97 | else | ||
| 98 | size="long"; | ||
| 99 | sprintf(buf,"des(%s,%s,%s,%s)",ptr,risc,unroll,size); | ||
| 100 | } | ||
| 101 | return(buf); | ||
| 102 | } | ||
| 103 | |||
| 104 | |||
| 105 | void des_ecb_encrypt(input, output, ks, enc) | ||
| 106 | des_cblock (*input); | ||
| 107 | des_cblock (*output); | ||
| 108 | des_key_schedule ks; | ||
| 109 | int enc; | ||
| 110 | { | ||
| 111 | register DES_LONG l; | ||
| 112 | register unsigned char *in,*out; | ||
| 113 | DES_LONG ll[2]; | ||
| 114 | |||
| 115 | in=(unsigned char *)input; | ||
| 116 | out=(unsigned char *)output; | ||
| 117 | c2l(in,l); ll[0]=l; | ||
| 118 | c2l(in,l); ll[1]=l; | ||
| 119 | des_encrypt(ll,ks,enc); | ||
| 120 | l=ll[0]; l2c(l,out); | ||
| 121 | l=ll[1]; l2c(l,out); | ||
| 122 | l=ll[0]=ll[1]=0; | ||
| 123 | } | ||
| 124 | |||
diff --git a/src/lib/libcrypto/des/enc_read.c b/src/lib/libcrypto/des/enc_read.c new file mode 100644 index 0000000000..e08a904d75 --- /dev/null +++ b/src/lib/libcrypto/des/enc_read.c | |||
| @@ -0,0 +1,218 @@ | |||
| 1 | /* crypto/des/enc_read.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 <errno.h> | ||
| 61 | #include "des_locl.h" | ||
| 62 | |||
| 63 | /* This has some uglies in it but it works - even over sockets. */ | ||
| 64 | /*extern int errno;*/ | ||
| 65 | int des_rw_mode=DES_PCBC_MODE; | ||
| 66 | |||
| 67 | int des_enc_read(fd, buf, len, sched, iv) | ||
| 68 | int fd; | ||
| 69 | char *buf; | ||
| 70 | int len; | ||
| 71 | des_key_schedule sched; | ||
| 72 | des_cblock (*iv); | ||
| 73 | { | ||
| 74 | /* data to be unencrypted */ | ||
| 75 | int net_num=0; | ||
| 76 | static unsigned char *net=NULL; | ||
| 77 | /* extra unencrypted data | ||
| 78 | * for when a block of 100 comes in but is des_read one byte at | ||
| 79 | * a time. */ | ||
| 80 | static char *unnet=NULL; | ||
| 81 | static int unnet_start=0; | ||
| 82 | static int unnet_left=0; | ||
| 83 | static char *tmpbuf=NULL; | ||
| 84 | int i; | ||
| 85 | long num=0,rnum; | ||
| 86 | unsigned char *p; | ||
| 87 | |||
| 88 | if (tmpbuf == NULL) | ||
| 89 | { | ||
| 90 | tmpbuf=(char *)malloc(BSIZE); | ||
| 91 | if (tmpbuf == NULL) return(-1); | ||
| 92 | } | ||
| 93 | if (net == NULL) | ||
| 94 | { | ||
| 95 | net=(unsigned char *)malloc(BSIZE); | ||
| 96 | if (net == NULL) return(-1); | ||
| 97 | } | ||
| 98 | if (unnet == NULL) | ||
| 99 | { | ||
| 100 | unnet=(char *)malloc(BSIZE); | ||
| 101 | if (unnet == NULL) return(-1); | ||
| 102 | } | ||
| 103 | /* left over data from last decrypt */ | ||
| 104 | if (unnet_left != 0) | ||
| 105 | { | ||
| 106 | if (unnet_left < len) | ||
| 107 | { | ||
| 108 | /* we still still need more data but will return | ||
| 109 | * with the number of bytes we have - should always | ||
| 110 | * check the return value */ | ||
| 111 | memcpy(buf,&(unnet[unnet_start]), | ||
| 112 | (unsigned int)unnet_left); | ||
| 113 | /* eay 26/08/92 I had the next 2 lines | ||
| 114 | * reversed :-( */ | ||
| 115 | i=unnet_left; | ||
| 116 | unnet_start=unnet_left=0; | ||
| 117 | } | ||
| 118 | else | ||
| 119 | { | ||
| 120 | memcpy(buf,&(unnet[unnet_start]),(unsigned int)len); | ||
| 121 | unnet_start+=len; | ||
| 122 | unnet_left-=len; | ||
| 123 | i=len; | ||
| 124 | } | ||
| 125 | return(i); | ||
| 126 | } | ||
| 127 | |||
| 128 | /* We need to get more data. */ | ||
| 129 | if (len > MAXWRITE) len=MAXWRITE; | ||
| 130 | |||
| 131 | /* first - get the length */ | ||
| 132 | while (net_num < HDRSIZE) | ||
| 133 | { | ||
| 134 | i=read(fd,&(net[net_num]),(unsigned int)HDRSIZE-net_num); | ||
| 135 | #ifdef EINTR | ||
| 136 | if ((i == -1) && (errno == EINTR)) continue; | ||
| 137 | #endif | ||
| 138 | if (i <= 0) return(0); | ||
| 139 | net_num+=i; | ||
| 140 | } | ||
| 141 | |||
| 142 | /* we now have at net_num bytes in net */ | ||
| 143 | p=net; | ||
| 144 | /* num=0; */ | ||
| 145 | n2l(p,num); | ||
| 146 | /* num should be rounded up to the next group of eight | ||
| 147 | * we make sure that we have read a multiple of 8 bytes from the net. | ||
| 148 | */ | ||
| 149 | if ((num > MAXWRITE) || (num < 0)) /* error */ | ||
| 150 | return(-1); | ||
| 151 | rnum=(num < 8)?8:((num+7)/8*8); | ||
| 152 | |||
| 153 | net_num=0; | ||
| 154 | while (net_num < rnum) | ||
| 155 | { | ||
| 156 | i=read(fd,&(net[net_num]),(unsigned int)rnum-net_num); | ||
| 157 | #ifdef EINTR | ||
| 158 | if ((i == -1) && (errno == EINTR)) continue; | ||
| 159 | #endif | ||
| 160 | if (i <= 0) return(0); | ||
| 161 | net_num+=i; | ||
| 162 | } | ||
| 163 | |||
| 164 | /* Check if there will be data left over. */ | ||
| 165 | if (len < num) | ||
| 166 | { | ||
| 167 | if (des_rw_mode & DES_PCBC_MODE) | ||
| 168 | des_pcbc_encrypt((des_cblock *)net,(des_cblock *)unnet, | ||
| 169 | num,sched,iv,DES_DECRYPT); | ||
| 170 | else | ||
| 171 | des_cbc_encrypt((des_cblock *)net,(des_cblock *)unnet, | ||
| 172 | num,sched,iv,DES_DECRYPT); | ||
| 173 | memcpy(buf,unnet,(unsigned int)len); | ||
| 174 | unnet_start=len; | ||
| 175 | unnet_left=(int)num-len; | ||
| 176 | |||
| 177 | /* The following line is done because we return num | ||
| 178 | * as the number of bytes read. */ | ||
| 179 | num=len; | ||
| 180 | } | ||
| 181 | else | ||
| 182 | { | ||
| 183 | /* >output is a multiple of 8 byes, if len < rnum | ||
| 184 | * >we must be careful. The user must be aware that this | ||
| 185 | * >routine will write more bytes than he asked for. | ||
| 186 | * >The length of the buffer must be correct. | ||
| 187 | * FIXED - Should be ok now 18-9-90 - eay */ | ||
| 188 | if (len < rnum) | ||
| 189 | { | ||
| 190 | |||
| 191 | if (des_rw_mode & DES_PCBC_MODE) | ||
| 192 | des_pcbc_encrypt((des_cblock *)net, | ||
| 193 | (des_cblock *)tmpbuf, | ||
| 194 | num,sched,iv,DES_DECRYPT); | ||
| 195 | else | ||
| 196 | des_cbc_encrypt((des_cblock *)net, | ||
| 197 | (des_cblock *)tmpbuf, | ||
| 198 | num,sched,iv,DES_DECRYPT); | ||
| 199 | |||
| 200 | /* eay 26/08/92 fix a bug that returned more | ||
| 201 | * bytes than you asked for (returned len bytes :-( */ | ||
| 202 | memcpy(buf,tmpbuf,(unsigned int)num); | ||
| 203 | } | ||
| 204 | else | ||
| 205 | { | ||
| 206 | if (des_rw_mode & DES_PCBC_MODE) | ||
| 207 | des_pcbc_encrypt((des_cblock *)net, | ||
| 208 | (des_cblock *)buf,num,sched,iv, | ||
| 209 | DES_DECRYPT); | ||
| 210 | else | ||
| 211 | des_cbc_encrypt((des_cblock *)net, | ||
| 212 | (des_cblock *)buf,num,sched,iv, | ||
| 213 | DES_DECRYPT); | ||
| 214 | } | ||
| 215 | } | ||
| 216 | return((int)num); | ||
| 217 | } | ||
| 218 | |||
diff --git a/src/lib/libcrypto/des/enc_writ.c b/src/lib/libcrypto/des/enc_writ.c new file mode 100644 index 0000000000..29a7330fb0 --- /dev/null +++ b/src/lib/libcrypto/des/enc_writ.c | |||
| @@ -0,0 +1,160 @@ | |||
| 1 | /* crypto/des/enc_writ.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 <errno.h> | ||
| 60 | #include <time.h> | ||
| 61 | #include "des_locl.h" | ||
| 62 | |||
| 63 | int des_enc_write(fd, buf, len, sched, iv) | ||
| 64 | int fd; | ||
| 65 | char *buf; | ||
| 66 | int len; | ||
| 67 | des_key_schedule sched; | ||
| 68 | des_cblock (*iv); | ||
| 69 | { | ||
| 70 | #ifdef _LIBC | ||
| 71 | extern int srandom(); | ||
| 72 | extern unsigned long time(); | ||
| 73 | extern int random(); | ||
| 74 | extern int write(); | ||
| 75 | #endif | ||
| 76 | |||
| 77 | long rnum; | ||
| 78 | int i,j,k,outnum; | ||
| 79 | static char *outbuf=NULL; | ||
| 80 | char shortbuf[8]; | ||
| 81 | char *p; | ||
| 82 | static int start=1; | ||
| 83 | |||
| 84 | if (outbuf == NULL) | ||
| 85 | { | ||
| 86 | outbuf=(char *)malloc(BSIZE+HDRSIZE); | ||
| 87 | if (outbuf == NULL) return(-1); | ||
| 88 | } | ||
| 89 | /* If we are sending less than 8 bytes, the same char will look | ||
| 90 | * the same if we don't pad it out with random bytes */ | ||
| 91 | if (start) | ||
| 92 | { | ||
| 93 | start=0; | ||
| 94 | srandom((unsigned int)time(NULL)); | ||
| 95 | } | ||
| 96 | |||
| 97 | /* lets recurse if we want to send the data in small chunks */ | ||
| 98 | if (len > MAXWRITE) | ||
| 99 | { | ||
| 100 | j=0; | ||
| 101 | for (i=0; i<len; i+=k) | ||
| 102 | { | ||
| 103 | k=des_enc_write(fd,&(buf[i]), | ||
| 104 | ((len-i) > MAXWRITE)?MAXWRITE:(len-i),sched,iv); | ||
| 105 | if (k < 0) | ||
| 106 | return(k); | ||
| 107 | else | ||
| 108 | j+=k; | ||
| 109 | } | ||
| 110 | return(j); | ||
| 111 | } | ||
| 112 | |||
| 113 | /* write length first */ | ||
| 114 | p=outbuf; | ||
| 115 | l2n(len,p); | ||
| 116 | |||
| 117 | /* pad short strings */ | ||
| 118 | if (len < 8) | ||
| 119 | { | ||
| 120 | p=shortbuf; | ||
| 121 | memcpy(shortbuf,buf,(unsigned int)len); | ||
| 122 | for (i=len; i<8; i++) | ||
| 123 | shortbuf[i]=random(); | ||
| 124 | rnum=8; | ||
| 125 | } | ||
| 126 | else | ||
| 127 | { | ||
| 128 | p=buf; | ||
| 129 | rnum=((len+7)/8*8); /* round up to nearest eight */ | ||
| 130 | } | ||
| 131 | |||
| 132 | if (des_rw_mode & DES_PCBC_MODE) | ||
| 133 | des_pcbc_encrypt((des_cblock *)p, | ||
| 134 | (des_cblock *)&(outbuf[HDRSIZE]), | ||
| 135 | (long)((len<8)?8:len),sched,iv,DES_ENCRYPT); | ||
| 136 | else | ||
| 137 | des_cbc_encrypt((des_cblock *)p, | ||
| 138 | (des_cblock *)&(outbuf[HDRSIZE]), | ||
| 139 | (long)((len<8)?8:len),sched,iv,DES_ENCRYPT); | ||
| 140 | |||
| 141 | /* output */ | ||
| 142 | outnum=(int)rnum+HDRSIZE; | ||
| 143 | |||
| 144 | for (j=0; j<outnum; j+=i) | ||
| 145 | { | ||
| 146 | /* eay 26/08/92 I was not doing writing from where we | ||
| 147 | * got upto. */ | ||
| 148 | i=write(fd,&(outbuf[j]),(unsigned int)(outnum-j)); | ||
| 149 | if (i == -1) | ||
| 150 | { | ||
| 151 | if (errno == EINTR) | ||
| 152 | i=0; | ||
| 153 | else /* This is really a bad error - very bad | ||
| 154 | * It will stuff-up both ends. */ | ||
| 155 | return(-1); | ||
| 156 | } | ||
| 157 | } | ||
| 158 | |||
| 159 | return(len); | ||
| 160 | } | ||
diff --git a/src/lib/libcrypto/des/fcrypt.c b/src/lib/libcrypto/des/fcrypt.c new file mode 100644 index 0000000000..129beb27da --- /dev/null +++ b/src/lib/libcrypto/des/fcrypt.c | |||
| @@ -0,0 +1,153 @@ | |||
| 1 | /* NOCW */ | ||
| 2 | #include <stdio.h> | ||
| 3 | |||
| 4 | /* This version of crypt has been developed from my MIT compatable | ||
| 5 | * DES library. | ||
| 6 | * The library is available at pub/Crypto/DES at ftp.psy.uq.oz.au | ||
| 7 | * Eric Young (eay@cryptsoft.com) | ||
| 8 | */ | ||
| 9 | |||
| 10 | /* Modification by Jens Kupferschmidt (Cu) | ||
| 11 | * I have included directive PARA for shared memory computers. | ||
| 12 | * I have included a directive LONGCRYPT to using this routine to cipher | ||
| 13 | * passwords with more then 8 bytes like HP-UX 10.x it used. The MAXPLEN | ||
| 14 | * definition is the maximum of lenght of password and can changed. I have | ||
| 15 | * defined 24. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include "des_locl.h" | ||
| 19 | |||
| 20 | /* Added more values to handle illegal salt values the way normal | ||
| 21 | * crypt() implementations do. The patch was sent by | ||
| 22 | * Bjorn Gronvall <bg@sics.se> | ||
| 23 | */ | ||
| 24 | static unsigned const char con_salt[128]={ | ||
| 25 | 0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9, | ||
| 26 | 0xDA,0xDB,0xDC,0xDD,0xDE,0xDF,0xE0,0xE1, | ||
| 27 | 0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9, | ||
| 28 | 0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1, | ||
| 29 | 0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9, | ||
| 30 | 0xFA,0xFB,0xFC,0xFD,0xFE,0xFF,0x00,0x01, | ||
| 31 | 0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09, | ||
| 32 | 0x0A,0x0B,0x05,0x06,0x07,0x08,0x09,0x0A, | ||
| 33 | 0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12, | ||
| 34 | 0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A, | ||
| 35 | 0x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22, | ||
| 36 | 0x23,0x24,0x25,0x20,0x21,0x22,0x23,0x24, | ||
| 37 | 0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C, | ||
| 38 | 0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34, | ||
| 39 | 0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C, | ||
| 40 | 0x3D,0x3E,0x3F,0x40,0x41,0x42,0x43,0x44, | ||
| 41 | }; | ||
| 42 | |||
| 43 | static unsigned const char cov_2char[64]={ | ||
| 44 | 0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35, | ||
| 45 | 0x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44, | ||
| 46 | 0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C, | ||
| 47 | 0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54, | ||
| 48 | 0x55,0x56,0x57,0x58,0x59,0x5A,0x61,0x62, | ||
| 49 | 0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A, | ||
| 50 | 0x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72, | ||
| 51 | 0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A | ||
| 52 | }; | ||
| 53 | |||
| 54 | #ifndef NOPROTO | ||
| 55 | void fcrypt_body(DES_LONG *out,des_key_schedule ks, | ||
| 56 | DES_LONG Eswap0, DES_LONG Eswap1); | ||
| 57 | |||
| 58 | #if defined(PERL5) || defined(FreeBSD) | ||
| 59 | char *des_crypt(const char *buf,const char *salt); | ||
| 60 | #else | ||
| 61 | char *crypt(const char *buf,const char *salt); | ||
| 62 | #endif | ||
| 63 | #else | ||
| 64 | void fcrypt_body(); | ||
| 65 | #ifdef PERL5 | ||
| 66 | char *des_crypt(); | ||
| 67 | #else | ||
| 68 | char *crypt(); | ||
| 69 | #endif | ||
| 70 | #endif | ||
| 71 | |||
| 72 | #if defined(PERL5) || defined(FreeBSD) | ||
| 73 | char *des_crypt(buf,salt) | ||
| 74 | #else | ||
| 75 | char *crypt(buf,salt) | ||
| 76 | #endif | ||
| 77 | const char *buf; | ||
| 78 | const char *salt; | ||
| 79 | { | ||
| 80 | static char buff[14]; | ||
| 81 | |||
| 82 | return(des_fcrypt(buf,salt,buff)); | ||
| 83 | } | ||
| 84 | |||
| 85 | |||
| 86 | char *des_fcrypt(buf,salt,ret) | ||
| 87 | const char *buf; | ||
| 88 | const char *salt; | ||
| 89 | char *ret; | ||
| 90 | { | ||
| 91 | unsigned int i,j,x,y; | ||
| 92 | DES_LONG Eswap0,Eswap1; | ||
| 93 | DES_LONG out[2],ll; | ||
| 94 | des_cblock key; | ||
| 95 | des_key_schedule ks; | ||
| 96 | unsigned char bb[9]; | ||
| 97 | unsigned char *b=bb; | ||
| 98 | unsigned char c,u; | ||
| 99 | |||
| 100 | /* eay 25/08/92 | ||
| 101 | * If you call crypt("pwd","*") as often happens when you | ||
| 102 | * have * as the pwd field in /etc/passwd, the function | ||
| 103 | * returns *\0XXXXXXXXX | ||
| 104 | * The \0 makes the string look like * so the pwd "*" would | ||
| 105 | * crypt to "*". This was found when replacing the crypt in | ||
| 106 | * our shared libraries. People found that the disbled | ||
| 107 | * accounts effectivly had no passwd :-(. */ | ||
| 108 | x=ret[0]=((salt[0] == '\0')?'A':salt[0]); | ||
| 109 | Eswap0=con_salt[x]<<2; | ||
| 110 | x=ret[1]=((salt[1] == '\0')?'A':salt[1]); | ||
| 111 | Eswap1=con_salt[x]<<6; | ||
| 112 | |||
| 113 | /* EAY | ||
| 114 | r=strlen(buf); | ||
| 115 | r=(r+7)/8; | ||
| 116 | */ | ||
| 117 | for (i=0; i<8; i++) | ||
| 118 | { | ||
| 119 | c= *(buf++); | ||
| 120 | if (!c) break; | ||
| 121 | key[i]=(c<<1); | ||
| 122 | } | ||
| 123 | for (; i<8; i++) | ||
| 124 | key[i]=0; | ||
| 125 | |||
| 126 | des_set_key((des_cblock *)(key),ks); | ||
| 127 | fcrypt_body(&(out[0]),ks,Eswap0,Eswap1); | ||
| 128 | |||
| 129 | ll=out[0]; l2c(ll,b); | ||
| 130 | ll=out[1]; l2c(ll,b); | ||
| 131 | y=0; | ||
| 132 | u=0x80; | ||
| 133 | bb[8]=0; | ||
| 134 | for (i=2; i<13; i++) | ||
| 135 | { | ||
| 136 | c=0; | ||
| 137 | for (j=0; j<6; j++) | ||
| 138 | { | ||
| 139 | c<<=1; | ||
| 140 | if (bb[y] & u) c|=1; | ||
| 141 | u>>=1; | ||
| 142 | if (!u) | ||
| 143 | { | ||
| 144 | y++; | ||
| 145 | u=0x80; | ||
| 146 | } | ||
| 147 | } | ||
| 148 | ret[i]=cov_2char[c]; | ||
| 149 | } | ||
| 150 | ret[13]='\0'; | ||
| 151 | return(ret); | ||
| 152 | } | ||
| 153 | |||
diff --git a/src/lib/libcrypto/des/fcrypt_b.c b/src/lib/libcrypto/des/fcrypt_b.c new file mode 100644 index 0000000000..1544634bc1 --- /dev/null +++ b/src/lib/libcrypto/des/fcrypt_b.c | |||
| @@ -0,0 +1,148 @@ | |||
| 1 | /* crypto/des/fcrypt_b.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 | |||
| 61 | /* This version of crypt has been developed from my MIT compatable | ||
| 62 | * DES library. | ||
| 63 | * The library is available at pub/Crypto/DES at ftp.psy.uq.oz.au | ||
| 64 | * Eric Young (eay@cryptsoft.com) | ||
| 65 | */ | ||
| 66 | |||
| 67 | #define DES_FCRYPT | ||
| 68 | #include "des_locl.h" | ||
| 69 | #undef DES_FCRYPT | ||
| 70 | |||
| 71 | #undef PERM_OP | ||
| 72 | #define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\ | ||
| 73 | (b)^=(t),\ | ||
| 74 | (a)^=((t)<<(n))) | ||
| 75 | |||
| 76 | #undef HPERM_OP | ||
| 77 | #define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\ | ||
| 78 | (a)=(a)^(t)^(t>>(16-(n))))\ | ||
| 79 | |||
| 80 | void fcrypt_body(out, ks, Eswap0, Eswap1) | ||
| 81 | DES_LONG *out; | ||
| 82 | des_key_schedule ks; | ||
| 83 | DES_LONG Eswap0; | ||
| 84 | DES_LONG Eswap1; | ||
| 85 | { | ||
| 86 | register DES_LONG l,r,t,u; | ||
| 87 | #ifdef DES_PTR | ||
| 88 | register unsigned char *des_SP=(unsigned char *)des_SPtrans; | ||
| 89 | #endif | ||
| 90 | register DES_LONG *s; | ||
| 91 | register int j; | ||
| 92 | register DES_LONG E0,E1; | ||
| 93 | |||
| 94 | l=0; | ||
| 95 | r=0; | ||
| 96 | |||
| 97 | s=(DES_LONG *)ks; | ||
| 98 | E0=Eswap0; | ||
| 99 | E1=Eswap1; | ||
| 100 | |||
| 101 | for (j=0; j<25; j++) | ||
| 102 | { | ||
| 103 | #ifdef DES_UNROLL | ||
| 104 | register int i; | ||
| 105 | |||
| 106 | for (i=0; i<32; i+=8) | ||
| 107 | { | ||
| 108 | D_ENCRYPT(l,r,i+0); /* 1 */ | ||
| 109 | D_ENCRYPT(r,l,i+2); /* 2 */ | ||
| 110 | D_ENCRYPT(l,r,i+4); /* 1 */ | ||
| 111 | D_ENCRYPT(r,l,i+6); /* 2 */ | ||
| 112 | } | ||
| 113 | #else | ||
| 114 | D_ENCRYPT(l,r, 0); /* 1 */ | ||
| 115 | D_ENCRYPT(r,l, 2); /* 2 */ | ||
| 116 | D_ENCRYPT(l,r, 4); /* 3 */ | ||
| 117 | D_ENCRYPT(r,l, 6); /* 4 */ | ||
| 118 | D_ENCRYPT(l,r, 8); /* 5 */ | ||
| 119 | D_ENCRYPT(r,l,10); /* 6 */ | ||
| 120 | D_ENCRYPT(l,r,12); /* 7 */ | ||
| 121 | D_ENCRYPT(r,l,14); /* 8 */ | ||
| 122 | D_ENCRYPT(l,r,16); /* 9 */ | ||
| 123 | D_ENCRYPT(r,l,18); /* 10 */ | ||
| 124 | D_ENCRYPT(l,r,20); /* 11 */ | ||
| 125 | D_ENCRYPT(r,l,22); /* 12 */ | ||
| 126 | D_ENCRYPT(l,r,24); /* 13 */ | ||
| 127 | D_ENCRYPT(r,l,26); /* 14 */ | ||
| 128 | D_ENCRYPT(l,r,28); /* 15 */ | ||
| 129 | D_ENCRYPT(r,l,30); /* 16 */ | ||
| 130 | #endif | ||
| 131 | |||
| 132 | t=l; | ||
| 133 | l=r; | ||
| 134 | r=t; | ||
| 135 | } | ||
| 136 | l=ROTATE(l,3)&0xffffffffL; | ||
| 137 | r=ROTATE(r,3)&0xffffffffL; | ||
| 138 | |||
| 139 | PERM_OP(l,r,t, 1,0x55555555L); | ||
| 140 | PERM_OP(r,l,t, 8,0x00ff00ffL); | ||
| 141 | PERM_OP(l,r,t, 2,0x33333333L); | ||
| 142 | PERM_OP(r,l,t,16,0x0000ffffL); | ||
| 143 | PERM_OP(l,r,t, 4,0x0f0f0f0fL); | ||
| 144 | |||
| 145 | out[0]=r; | ||
| 146 | out[1]=l; | ||
| 147 | } | ||
| 148 | |||
diff --git a/src/lib/libcrypto/des/ncbc_enc.c b/src/lib/libcrypto/des/ncbc_enc.c new file mode 100644 index 0000000000..1d1a368c22 --- /dev/null +++ b/src/lib/libcrypto/des/ncbc_enc.c | |||
| @@ -0,0 +1,130 @@ | |||
| 1 | /* crypto/des/ncbc_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 "des_locl.h" | ||
| 60 | |||
| 61 | void des_ncbc_encrypt(input, output, length, schedule, ivec, enc) | ||
| 62 | des_cblock (*input); | ||
| 63 | des_cblock (*output); | ||
| 64 | long length; | ||
| 65 | des_key_schedule schedule; | ||
| 66 | des_cblock (*ivec); | ||
| 67 | int enc; | ||
| 68 | { | ||
| 69 | register DES_LONG tin0,tin1; | ||
| 70 | register DES_LONG tout0,tout1,xor0,xor1; | ||
| 71 | register unsigned char *in,*out; | ||
| 72 | register long l=length; | ||
| 73 | DES_LONG tin[2]; | ||
| 74 | unsigned char *iv; | ||
| 75 | |||
| 76 | in=(unsigned char *)input; | ||
| 77 | out=(unsigned char *)output; | ||
| 78 | iv=(unsigned char *)ivec; | ||
| 79 | |||
| 80 | if (enc) | ||
| 81 | { | ||
| 82 | c2l(iv,tout0); | ||
| 83 | c2l(iv,tout1); | ||
| 84 | for (l-=8; l>=0; l-=8) | ||
| 85 | { | ||
| 86 | c2l(in,tin0); | ||
| 87 | c2l(in,tin1); | ||
| 88 | tin0^=tout0; tin[0]=tin0; | ||
| 89 | tin1^=tout1; tin[1]=tin1; | ||
| 90 | des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); | ||
| 91 | tout0=tin[0]; l2c(tout0,out); | ||
| 92 | tout1=tin[1]; l2c(tout1,out); | ||
| 93 | } | ||
| 94 | if (l != -8) | ||
| 95 | { | ||
| 96 | c2ln(in,tin0,tin1,l+8); | ||
| 97 | tin0^=tout0; tin[0]=tin0; | ||
| 98 | tin1^=tout1; tin[1]=tin1; | ||
| 99 | des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); | ||
| 100 | tout0=tin[0]; l2c(tout0,out); | ||
| 101 | tout1=tin[1]; l2c(tout1,out); | ||
| 102 | } | ||
| 103 | iv=(unsigned char *)ivec; | ||
| 104 | l2c(tout0,iv); | ||
| 105 | l2c(tout1,iv); | ||
| 106 | } | ||
| 107 | else | ||
| 108 | { | ||
| 109 | c2l(iv,xor0); | ||
| 110 | c2l(iv,xor1); | ||
| 111 | for (l-=8; l>=0; l-=8) | ||
| 112 | { | ||
| 113 | c2l(in,tin0); tin[0]=tin0; | ||
| 114 | c2l(in,tin1); tin[1]=tin1; | ||
| 115 | des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); | ||
| 116 | tout0=tin[0]^xor0; | ||
| 117 | tout1=tin[1]^xor1; | ||
| 118 | l2c(tout0,out); | ||
| 119 | l2c(tout1,out); | ||
| 120 | xor0=tin0; | ||
| 121 | xor1=tin1; | ||
| 122 | } | ||
| 123 | iv=(unsigned char *)ivec; | ||
| 124 | l2c(xor0,iv); | ||
| 125 | l2c(xor1,iv); | ||
| 126 | } | ||
| 127 | tin0=tin1=tout0=tout1=xor0=xor1=0; | ||
| 128 | tin[0]=tin[1]=0; | ||
| 129 | } | ||
| 130 | |||
diff --git a/src/lib/libcrypto/des/ofb64ede.c b/src/lib/libcrypto/des/ofb64ede.c new file mode 100644 index 0000000000..4b1b0199f1 --- /dev/null +++ b/src/lib/libcrypto/des/ofb64ede.c | |||
| @@ -0,0 +1,131 @@ | |||
| 1 | /* crypto/des/ofb64ede.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 "des_locl.h" | ||
| 60 | |||
| 61 | /* The input and output encrypted as though 64bit ofb mode is being | ||
| 62 | * used. The extra state information to record how much of the | ||
| 63 | * 64bit block we have used is contained in *num; | ||
| 64 | */ | ||
| 65 | void des_ede3_ofb64_encrypt(in, out, length, k1,k2,k3, ivec, num) | ||
| 66 | register unsigned char *in; | ||
| 67 | register unsigned char *out; | ||
| 68 | long length; | ||
| 69 | des_key_schedule k1,k2,k3; | ||
| 70 | des_cblock (*ivec); | ||
| 71 | int *num; | ||
| 72 | { | ||
| 73 | register DES_LONG v0,v1; | ||
| 74 | register int n= *num; | ||
| 75 | register long l=length; | ||
| 76 | des_cblock d; | ||
| 77 | register char *dp; | ||
| 78 | DES_LONG ti[2]; | ||
| 79 | unsigned char *iv; | ||
| 80 | int save=0; | ||
| 81 | |||
| 82 | iv=(unsigned char *)ivec; | ||
| 83 | c2l(iv,v0); | ||
| 84 | c2l(iv,v1); | ||
| 85 | ti[0]=v0; | ||
| 86 | ti[1]=v1; | ||
| 87 | dp=(char *)d; | ||
| 88 | l2c(v0,dp); | ||
| 89 | l2c(v1,dp); | ||
| 90 | while (l--) | ||
| 91 | { | ||
| 92 | if (n == 0) | ||
| 93 | { | ||
| 94 | /* ti[0]=v0; */ | ||
| 95 | /* ti[1]=v1; */ | ||
| 96 | des_encrypt3((DES_LONG *)ti,k1,k2,k3); | ||
| 97 | v0=ti[0]; | ||
| 98 | v1=ti[1]; | ||
| 99 | |||
| 100 | dp=(char *)d; | ||
| 101 | l2c(v0,dp); | ||
| 102 | l2c(v1,dp); | ||
| 103 | save++; | ||
| 104 | } | ||
| 105 | *(out++)= *(in++)^d[n]; | ||
| 106 | n=(n+1)&0x07; | ||
| 107 | } | ||
| 108 | if (save) | ||
| 109 | { | ||
| 110 | /* v0=ti[0]; | ||
| 111 | v1=ti[1];*/ | ||
| 112 | iv=(unsigned char *)ivec; | ||
| 113 | l2c(v0,iv); | ||
| 114 | l2c(v1,iv); | ||
| 115 | } | ||
| 116 | v0=v1=ti[0]=ti[1]=0; | ||
| 117 | *num=n; | ||
| 118 | } | ||
| 119 | |||
| 120 | #ifdef undef /* MACRO */ | ||
| 121 | void des_ede2_ofb64_encrypt(in, out, length, k1,k2, ivec, num) | ||
| 122 | register unsigned char *in; | ||
| 123 | register unsigned char *out; | ||
| 124 | long length; | ||
| 125 | des_key_schedule k1,k2; | ||
| 126 | des_cblock (*ivec); | ||
| 127 | int *num; | ||
| 128 | { | ||
| 129 | des_ede3_ofb64_encrypt(in, out, length, k1,k2,k1, ivec, num); | ||
| 130 | } | ||
| 131 | #endif | ||
diff --git a/src/lib/libcrypto/des/ofb64enc.c b/src/lib/libcrypto/des/ofb64enc.c new file mode 100644 index 0000000000..ea7e612697 --- /dev/null +++ b/src/lib/libcrypto/des/ofb64enc.c | |||
| @@ -0,0 +1,114 @@ | |||
| 1 | /* crypto/des/ofb64enc.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 "des_locl.h" | ||
| 60 | |||
| 61 | /* The input and output encrypted as though 64bit ofb mode is being | ||
| 62 | * used. The extra state information to record how much of the | ||
| 63 | * 64bit block we have used is contained in *num; | ||
| 64 | */ | ||
| 65 | void des_ofb64_encrypt(in, out, length, schedule, ivec, num) | ||
| 66 | register unsigned char *in; | ||
| 67 | register unsigned char *out; | ||
| 68 | long length; | ||
| 69 | des_key_schedule schedule; | ||
| 70 | des_cblock (*ivec); | ||
| 71 | int *num; | ||
| 72 | { | ||
| 73 | register DES_LONG v0,v1,t; | ||
| 74 | register int n= *num; | ||
| 75 | register long l=length; | ||
| 76 | des_cblock d; | ||
| 77 | register char *dp; | ||
| 78 | DES_LONG ti[2]; | ||
| 79 | unsigned char *iv; | ||
| 80 | int save=0; | ||
| 81 | |||
| 82 | iv=(unsigned char *)ivec; | ||
| 83 | c2l(iv,v0); | ||
| 84 | c2l(iv,v1); | ||
| 85 | ti[0]=v0; | ||
| 86 | ti[1]=v1; | ||
| 87 | dp=(char *)d; | ||
| 88 | l2c(v0,dp); | ||
| 89 | l2c(v1,dp); | ||
| 90 | while (l--) | ||
| 91 | { | ||
| 92 | if (n == 0) | ||
| 93 | { | ||
| 94 | des_encrypt((DES_LONG *)ti,schedule,DES_ENCRYPT); | ||
| 95 | dp=(char *)d; | ||
| 96 | t=ti[0]; l2c(t,dp); | ||
| 97 | t=ti[1]; l2c(t,dp); | ||
| 98 | save++; | ||
| 99 | } | ||
| 100 | *(out++)= *(in++)^d[n]; | ||
| 101 | n=(n+1)&0x07; | ||
| 102 | } | ||
| 103 | if (save) | ||
| 104 | { | ||
| 105 | v0=ti[0]; | ||
| 106 | v1=ti[1]; | ||
| 107 | iv=(unsigned char *)ivec; | ||
| 108 | l2c(v0,iv); | ||
| 109 | l2c(v1,iv); | ||
| 110 | } | ||
| 111 | t=v0=v1=ti[0]=ti[1]=0; | ||
| 112 | *num=n; | ||
| 113 | } | ||
| 114 | |||
diff --git a/src/lib/libcrypto/des/ofb_enc.c b/src/lib/libcrypto/des/ofb_enc.c new file mode 100644 index 0000000000..4db0cdbd60 --- /dev/null +++ b/src/lib/libcrypto/des/ofb_enc.c | |||
| @@ -0,0 +1,139 @@ | |||
| 1 | /* crypto/des/ofb_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 "des_locl.h" | ||
| 60 | |||
| 61 | /* The input and output are loaded in multiples of 8 bits. | ||
| 62 | * What this means is that if you hame numbits=12 and length=2 | ||
| 63 | * the first 12 bits will be retrieved from the first byte and half | ||
| 64 | * the second. The second 12 bits will come from the 3rd and half the 4th | ||
| 65 | * byte. | ||
| 66 | */ | ||
| 67 | void des_ofb_encrypt(in, out, numbits, length, schedule, ivec) | ||
| 68 | unsigned char *in; | ||
| 69 | unsigned char *out; | ||
| 70 | int numbits; | ||
| 71 | long length; | ||
| 72 | des_key_schedule schedule; | ||
| 73 | des_cblock (*ivec); | ||
| 74 | { | ||
| 75 | register DES_LONG d0,d1,vv0,vv1,v0,v1,n=(numbits+7)/8; | ||
| 76 | register DES_LONG mask0,mask1; | ||
| 77 | register long l=length; | ||
| 78 | register int num=numbits; | ||
| 79 | DES_LONG ti[2]; | ||
| 80 | unsigned char *iv; | ||
| 81 | |||
| 82 | if (num > 64) return; | ||
| 83 | if (num > 32) | ||
| 84 | { | ||
| 85 | mask0=0xffffffffL; | ||
| 86 | if (num >= 64) | ||
| 87 | mask1=mask0; | ||
| 88 | else | ||
| 89 | mask1=(1L<<(num-32))-1; | ||
| 90 | } | ||
| 91 | else | ||
| 92 | { | ||
| 93 | if (num == 32) | ||
| 94 | mask0=0xffffffffL; | ||
| 95 | else | ||
| 96 | mask0=(1L<<num)-1; | ||
| 97 | mask1=0x00000000L; | ||
| 98 | } | ||
| 99 | |||
| 100 | iv=(unsigned char *)ivec; | ||
| 101 | c2l(iv,v0); | ||
| 102 | c2l(iv,v1); | ||
| 103 | ti[0]=v0; | ||
| 104 | ti[1]=v1; | ||
| 105 | while (l-- > 0) | ||
| 106 | { | ||
| 107 | ti[0]=v0; | ||
| 108 | ti[1]=v1; | ||
| 109 | des_encrypt((DES_LONG *)ti,schedule,DES_ENCRYPT); | ||
| 110 | vv0=ti[0]; | ||
| 111 | vv1=ti[1]; | ||
| 112 | c2ln(in,d0,d1,n); | ||
| 113 | in+=n; | ||
| 114 | d0=(d0^vv0)&mask0; | ||
| 115 | d1=(d1^vv1)&mask1; | ||
| 116 | l2cn(d0,d1,out,n); | ||
| 117 | out+=n; | ||
| 118 | |||
| 119 | if (num == 32) | ||
| 120 | { v0=v1; v1=vv0; } | ||
| 121 | else if (num == 64) | ||
| 122 | { v0=vv0; v1=vv1; } | ||
| 123 | else if (num > 32) /* && num != 64 */ | ||
| 124 | { | ||
| 125 | v0=((v1>>(num-32))|(vv0<<(64-num)))&0xffffffffL; | ||
| 126 | v1=((vv0>>(num-32))|(vv1<<(64-num)))&0xffffffffL; | ||
| 127 | } | ||
| 128 | else /* num < 32 */ | ||
| 129 | { | ||
| 130 | v0=((v0>>num)|(v1<<(32-num)))&0xffffffffL; | ||
| 131 | v1=((v1>>num)|(vv0<<(32-num)))&0xffffffffL; | ||
| 132 | } | ||
| 133 | } | ||
| 134 | iv=(unsigned char *)ivec; | ||
| 135 | l2c(v0,iv); | ||
| 136 | l2c(v1,iv); | ||
| 137 | v0=v1=d0=d1=ti[0]=ti[1]=vv0=vv1=0; | ||
| 138 | } | ||
| 139 | |||
diff --git a/src/lib/libcrypto/des/pcbc_enc.c b/src/lib/libcrypto/des/pcbc_enc.c new file mode 100644 index 0000000000..4513207d90 --- /dev/null +++ b/src/lib/libcrypto/des/pcbc_enc.c | |||
| @@ -0,0 +1,126 @@ | |||
| 1 | /* crypto/des/pcbc_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 "des_locl.h" | ||
| 60 | |||
| 61 | void des_pcbc_encrypt(input, output, length, schedule, ivec, enc) | ||
| 62 | des_cblock (*input); | ||
| 63 | des_cblock (*output); | ||
| 64 | long length; | ||
| 65 | des_key_schedule schedule; | ||
| 66 | des_cblock (*ivec); | ||
| 67 | int enc; | ||
| 68 | { | ||
| 69 | register DES_LONG sin0,sin1,xor0,xor1,tout0,tout1; | ||
| 70 | DES_LONG tin[2]; | ||
| 71 | unsigned char *in,*out,*iv; | ||
| 72 | |||
| 73 | in=(unsigned char *)input; | ||
| 74 | out=(unsigned char *)output; | ||
| 75 | iv=(unsigned char *)ivec; | ||
| 76 | |||
| 77 | if (enc) | ||
| 78 | { | ||
| 79 | c2l(iv,xor0); | ||
| 80 | c2l(iv,xor1); | ||
| 81 | for (; length>0; length-=8) | ||
| 82 | { | ||
| 83 | if (length >= 8) | ||
| 84 | { | ||
| 85 | c2l(in,sin0); | ||
| 86 | c2l(in,sin1); | ||
| 87 | } | ||
| 88 | else | ||
| 89 | c2ln(in,sin0,sin1,length); | ||
| 90 | tin[0]=sin0^xor0; | ||
| 91 | tin[1]=sin1^xor1; | ||
| 92 | des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); | ||
| 93 | tout0=tin[0]; | ||
| 94 | tout1=tin[1]; | ||
| 95 | xor0=sin0^tout0; | ||
| 96 | xor1=sin1^tout1; | ||
| 97 | l2c(tout0,out); | ||
| 98 | l2c(tout1,out); | ||
| 99 | } | ||
| 100 | } | ||
| 101 | else | ||
| 102 | { | ||
| 103 | c2l(iv,xor0); c2l(iv,xor1); | ||
| 104 | for (; length>0; length-=8) | ||
| 105 | { | ||
| 106 | c2l(in,sin0); | ||
| 107 | c2l(in,sin1); | ||
| 108 | tin[0]=sin0; | ||
| 109 | tin[1]=sin1; | ||
| 110 | des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); | ||
| 111 | tout0=tin[0]^xor0; | ||
| 112 | tout1=tin[1]^xor1; | ||
| 113 | if (length >= 8) | ||
| 114 | { | ||
| 115 | l2c(tout0,out); | ||
| 116 | l2c(tout1,out); | ||
| 117 | } | ||
| 118 | else | ||
| 119 | l2cn(tout0,tout1,out,length); | ||
| 120 | xor0=tout0^sin0; | ||
| 121 | xor1=tout1^sin1; | ||
| 122 | } | ||
| 123 | } | ||
| 124 | tin[0]=tin[1]=0; | ||
| 125 | sin0=sin1=xor0=xor1=tout0=tout1=0; | ||
| 126 | } | ||
diff --git a/src/lib/libcrypto/des/qud_cksm.c b/src/lib/libcrypto/des/qud_cksm.c new file mode 100644 index 0000000000..8526abf334 --- /dev/null +++ b/src/lib/libcrypto/des/qud_cksm.c | |||
| @@ -0,0 +1,144 @@ | |||
| 1 | /* crypto/des/qud_cksm.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 | /* From "Message Authentication" R.R. Jueneman, S.M. Matyas, C.H. Meyer | ||
| 60 | * IEEE Communications Magazine Sept 1985 Vol. 23 No. 9 p 29-40 | ||
| 61 | * This module in only based on the code in this paper and is | ||
| 62 | * almost definitely not the same as the MIT implementation. | ||
| 63 | */ | ||
| 64 | #include "des_locl.h" | ||
| 65 | |||
| 66 | /* bug fix for dos - 7/6/91 - Larry hughes@logos.ucs.indiana.edu */ | ||
| 67 | #define Q_B0(a) (((DES_LONG)(a))) | ||
| 68 | #define Q_B1(a) (((DES_LONG)(a))<<8) | ||
| 69 | #define Q_B2(a) (((DES_LONG)(a))<<16) | ||
| 70 | #define Q_B3(a) (((DES_LONG)(a))<<24) | ||
| 71 | |||
| 72 | /* used to scramble things a bit */ | ||
| 73 | /* Got the value MIT uses via brute force :-) 2/10/90 eay */ | ||
| 74 | #define NOISE ((DES_LONG)83653421L) | ||
| 75 | |||
| 76 | DES_LONG des_quad_cksum(input, output, length, out_count, seed) | ||
| 77 | des_cblock (*input); | ||
| 78 | des_cblock (*output); | ||
| 79 | long length; | ||
| 80 | int out_count; | ||
| 81 | des_cblock (*seed); | ||
| 82 | { | ||
| 83 | DES_LONG z0,z1,t0,t1; | ||
| 84 | int i; | ||
| 85 | long l; | ||
| 86 | unsigned char *cp; | ||
| 87 | unsigned char *lp; | ||
| 88 | |||
| 89 | if (out_count < 1) out_count=1; | ||
| 90 | lp=(unsigned char *)output; | ||
| 91 | |||
| 92 | z0=Q_B0((*seed)[0])|Q_B1((*seed)[1])|Q_B2((*seed)[2])|Q_B3((*seed)[3]); | ||
| 93 | z1=Q_B0((*seed)[4])|Q_B1((*seed)[5])|Q_B2((*seed)[6])|Q_B3((*seed)[7]); | ||
| 94 | |||
| 95 | for (i=0; ((i<4)&&(i<out_count)); i++) | ||
| 96 | { | ||
| 97 | cp=(unsigned char *)input; | ||
| 98 | l=length; | ||
| 99 | while (l > 0) | ||
| 100 | { | ||
| 101 | if (l > 1) | ||
| 102 | { | ||
| 103 | t0= (DES_LONG)(*(cp++)); | ||
| 104 | t0|=(DES_LONG)Q_B1(*(cp++)); | ||
| 105 | l--; | ||
| 106 | } | ||
| 107 | else | ||
| 108 | t0= (DES_LONG)(*(cp++)); | ||
| 109 | l--; | ||
| 110 | /* add */ | ||
| 111 | t0+=z0; | ||
| 112 | t0&=0xffffffffL; | ||
| 113 | t1=z1; | ||
| 114 | /* square, well sort of square */ | ||
| 115 | z0=((((t0*t0)&0xffffffffL)+((t1*t1)&0xffffffffL)) | ||
| 116 | &0xffffffffL)%0x7fffffffL; | ||
| 117 | z1=((t0*((t1+NOISE)&0xffffffffL))&0xffffffffL)%0x7fffffffL; | ||
| 118 | } | ||
| 119 | if (lp != NULL) | ||
| 120 | { | ||
| 121 | /* I believe I finally have things worked out. | ||
| 122 | * The MIT library assumes that the checksum | ||
| 123 | * is one huge number and it is returned in a | ||
| 124 | * host dependant byte order. | ||
| 125 | */ | ||
| 126 | static DES_LONG ltmp=1; | ||
| 127 | static unsigned char *c=(unsigned char *)<mp; | ||
| 128 | |||
| 129 | if (c[0]) | ||
| 130 | { | ||
| 131 | l2c(z0,lp); | ||
| 132 | l2c(z1,lp); | ||
| 133 | } | ||
| 134 | else | ||
| 135 | { | ||
| 136 | lp=output[out_count-i-1]; | ||
| 137 | l2n(z1,lp); | ||
| 138 | l2n(z0,lp); | ||
| 139 | } | ||
| 140 | } | ||
| 141 | } | ||
| 142 | return(z0); | ||
| 143 | } | ||
| 144 | |||
diff --git a/src/lib/libcrypto/des/rand_key.c b/src/lib/libcrypto/des/rand_key.c new file mode 100644 index 0000000000..8c30bd029a --- /dev/null +++ b/src/lib/libcrypto/des/rand_key.c | |||
| @@ -0,0 +1,118 @@ | |||
| 1 | /* crypto/des/rand_key.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 "des_locl.h" | ||
| 60 | #include <time.h> | ||
| 61 | |||
| 62 | static int seed=0; | ||
| 63 | static des_cblock init; | ||
| 64 | |||
| 65 | void des_random_seed(key) | ||
| 66 | des_cblock key; | ||
| 67 | { | ||
| 68 | memcpy(init,key,sizeof(des_cblock)); | ||
| 69 | seed=1; | ||
| 70 | } | ||
| 71 | |||
| 72 | void des_random_key(ret) | ||
| 73 | unsigned char *ret; | ||
| 74 | { | ||
| 75 | des_key_schedule ks; | ||
| 76 | static DES_LONG c=0; | ||
| 77 | static unsigned short pid=0; | ||
| 78 | static des_cblock data={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}; | ||
| 79 | des_cblock key; | ||
| 80 | unsigned char *p; | ||
| 81 | DES_LONG t; | ||
| 82 | int i; | ||
| 83 | |||
| 84 | #ifdef MSDOS | ||
| 85 | pid=1; | ||
| 86 | #else | ||
| 87 | if (!pid) pid=getpid(); | ||
| 88 | #endif | ||
| 89 | p=key; | ||
| 90 | if (seed) | ||
| 91 | { | ||
| 92 | for (i=0; i<8; i++) | ||
| 93 | { | ||
| 94 | data[i] ^= init[i]; | ||
| 95 | init[i]=0; | ||
| 96 | } | ||
| 97 | seed=0; | ||
| 98 | } | ||
| 99 | t=(DES_LONG)time(NULL); | ||
| 100 | l2c(t,p); | ||
| 101 | t=(DES_LONG)((pid)|((c++)<<16)); | ||
| 102 | l2c(t,p); | ||
| 103 | |||
| 104 | des_set_odd_parity((des_cblock *)data); | ||
| 105 | des_set_key((des_cblock *)data,ks); | ||
| 106 | des_cbc_cksum((des_cblock *)key,(des_cblock *)key, | ||
| 107 | (long)sizeof(key),ks,(des_cblock *)data); | ||
| 108 | |||
| 109 | des_set_odd_parity((des_cblock *)key); | ||
| 110 | des_set_key((des_cblock *)key,ks); | ||
| 111 | des_cbc_cksum((des_cblock *)key,(des_cblock *)data, | ||
| 112 | (long)sizeof(key),ks,(des_cblock *)key); | ||
| 113 | |||
| 114 | memcpy(ret,data,sizeof(key)); | ||
| 115 | memset(key,0,sizeof(key)); | ||
| 116 | memset(ks,0,sizeof(ks)); | ||
| 117 | t=0; | ||
| 118 | } | ||
diff --git a/src/lib/libcrypto/des/set_key.c b/src/lib/libcrypto/des/set_key.c new file mode 100644 index 0000000000..c3bcd7ee2b --- /dev/null +++ b/src/lib/libcrypto/des/set_key.c | |||
| @@ -0,0 +1,246 @@ | |||
| 1 | /* crypto/des/set_key.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 | /* set_key.c v 1.4 eay 24/9/91 | ||
| 60 | * 1.4 Speed up by 400% :-) | ||
| 61 | * 1.3 added register declarations. | ||
| 62 | * 1.2 unrolled make_key_sched a bit more | ||
| 63 | * 1.1 added norm_expand_bits | ||
| 64 | * 1.0 First working version | ||
| 65 | */ | ||
| 66 | #include "des_locl.h" | ||
| 67 | #include "podd.h" | ||
| 68 | #include "sk.h" | ||
| 69 | |||
| 70 | #ifndef NOPROTO | ||
| 71 | static int check_parity(des_cblock (*key)); | ||
| 72 | #else | ||
| 73 | static int check_parity(); | ||
| 74 | #endif | ||
| 75 | |||
| 76 | int des_check_key=0; | ||
| 77 | |||
| 78 | void des_set_odd_parity(key) | ||
| 79 | des_cblock (*key); | ||
| 80 | { | ||
| 81 | int i; | ||
| 82 | |||
| 83 | for (i=0; i<DES_KEY_SZ; i++) | ||
| 84 | (*key)[i]=odd_parity[(*key)[i]]; | ||
| 85 | } | ||
| 86 | |||
| 87 | static int check_parity(key) | ||
| 88 | des_cblock (*key); | ||
| 89 | { | ||
| 90 | int i; | ||
| 91 | |||
| 92 | for (i=0; i<DES_KEY_SZ; i++) | ||
| 93 | { | ||
| 94 | if ((*key)[i] != odd_parity[(*key)[i]]) | ||
| 95 | return(0); | ||
| 96 | } | ||
| 97 | return(1); | ||
| 98 | } | ||
| 99 | |||
| 100 | /* Weak and semi week keys as take from | ||
| 101 | * %A D.W. Davies | ||
| 102 | * %A W.L. Price | ||
| 103 | * %T Security for Computer Networks | ||
| 104 | * %I John Wiley & Sons | ||
| 105 | * %D 1984 | ||
| 106 | * Many thanks to smb@ulysses.att.com (Steven Bellovin) for the reference | ||
| 107 | * (and actual cblock values). | ||
| 108 | */ | ||
| 109 | #define NUM_WEAK_KEY 16 | ||
| 110 | static des_cblock weak_keys[NUM_WEAK_KEY]={ | ||
| 111 | /* weak keys */ | ||
| 112 | {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01}, | ||
| 113 | {0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE}, | ||
| 114 | {0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, | ||
| 115 | {0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0}, | ||
| 116 | /* semi-weak keys */ | ||
| 117 | {0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE}, | ||
| 118 | {0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01}, | ||
| 119 | {0x1F,0xE0,0x1F,0xE0,0x0E,0xF1,0x0E,0xF1}, | ||
| 120 | {0xE0,0x1F,0xE0,0x1F,0xF1,0x0E,0xF1,0x0E}, | ||
| 121 | {0x01,0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1}, | ||
| 122 | {0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1,0x01}, | ||
| 123 | {0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E,0xFE}, | ||
| 124 | {0xFE,0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E}, | ||
| 125 | {0x01,0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E}, | ||
| 126 | {0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E,0x01}, | ||
| 127 | {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE}, | ||
| 128 | {0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1}}; | ||
| 129 | |||
| 130 | int des_is_weak_key(key) | ||
| 131 | des_cblock (*key); | ||
| 132 | { | ||
| 133 | int i; | ||
| 134 | |||
| 135 | for (i=0; i<NUM_WEAK_KEY; i++) | ||
| 136 | /* Added == 0 to comparision, I obviously don't run | ||
| 137 | * this section very often :-(, thanks to | ||
| 138 | * engineering@MorningStar.Com for the fix | ||
| 139 | * eay 93/06/29 | ||
| 140 | * Another problem, I was comparing only the first 4 | ||
| 141 | * bytes, 97/03/18 */ | ||
| 142 | if (memcmp(weak_keys[i],key,sizeof(des_cblock)) == 0) return(1); | ||
| 143 | return(0); | ||
| 144 | } | ||
| 145 | |||
| 146 | /* NOW DEFINED IN des_local.h | ||
| 147 | * See ecb_encrypt.c for a pseudo description of these macros. | ||
| 148 | * #define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\ | ||
| 149 | * (b)^=(t),\ | ||
| 150 | * (a)=((a)^((t)<<(n)))) | ||
| 151 | */ | ||
| 152 | |||
| 153 | #define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\ | ||
| 154 | (a)=(a)^(t)^(t>>(16-(n)))) | ||
| 155 | |||
| 156 | /* return 0 if key parity is odd (correct), | ||
| 157 | * return -1 if key parity error, | ||
| 158 | * return -2 if illegal weak key. | ||
| 159 | */ | ||
| 160 | int des_set_key(key, schedule) | ||
| 161 | des_cblock (*key); | ||
| 162 | des_key_schedule schedule; | ||
| 163 | { | ||
| 164 | static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0}; | ||
| 165 | register DES_LONG c,d,t,s,t2; | ||
| 166 | register unsigned char *in; | ||
| 167 | register DES_LONG *k; | ||
| 168 | register int i; | ||
| 169 | |||
| 170 | if (des_check_key) | ||
| 171 | { | ||
| 172 | if (!check_parity(key)) | ||
| 173 | return(-1); | ||
| 174 | |||
| 175 | if (des_is_weak_key(key)) | ||
| 176 | return(-2); | ||
| 177 | } | ||
| 178 | |||
| 179 | k=(DES_LONG *)schedule; | ||
| 180 | in=(unsigned char *)key; | ||
| 181 | |||
| 182 | c2l(in,c); | ||
| 183 | c2l(in,d); | ||
| 184 | |||
| 185 | /* do PC1 in 60 simple operations */ | ||
| 186 | /* PERM_OP(d,c,t,4,0x0f0f0f0fL); | ||
| 187 | HPERM_OP(c,t,-2, 0xcccc0000L); | ||
| 188 | HPERM_OP(c,t,-1, 0xaaaa0000L); | ||
| 189 | HPERM_OP(c,t, 8, 0x00ff0000L); | ||
| 190 | HPERM_OP(c,t,-1, 0xaaaa0000L); | ||
| 191 | HPERM_OP(d,t,-8, 0xff000000L); | ||
| 192 | HPERM_OP(d,t, 8, 0x00ff0000L); | ||
| 193 | HPERM_OP(d,t, 2, 0x33330000L); | ||
| 194 | d=((d&0x00aa00aaL)<<7L)|((d&0x55005500L)>>7L)|(d&0xaa55aa55L); | ||
| 195 | d=(d>>8)|((c&0xf0000000L)>>4); | ||
| 196 | c&=0x0fffffffL; */ | ||
| 197 | |||
| 198 | /* I now do it in 47 simple operations :-) | ||
| 199 | * Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov) | ||
| 200 | * for the inspiration. :-) */ | ||
| 201 | PERM_OP (d,c,t,4,0x0f0f0f0fL); | ||
| 202 | HPERM_OP(c,t,-2,0xcccc0000L); | ||
| 203 | HPERM_OP(d,t,-2,0xcccc0000L); | ||
| 204 | PERM_OP (d,c,t,1,0x55555555L); | ||
| 205 | PERM_OP (c,d,t,8,0x00ff00ffL); | ||
| 206 | PERM_OP (d,c,t,1,0x55555555L); | ||
| 207 | d= (((d&0x000000ffL)<<16L)| (d&0x0000ff00L) | | ||
| 208 | ((d&0x00ff0000L)>>16L)|((c&0xf0000000L)>>4L)); | ||
| 209 | c&=0x0fffffffL; | ||
| 210 | |||
| 211 | for (i=0; i<ITERATIONS; i++) | ||
| 212 | { | ||
| 213 | if (shifts2[i]) | ||
| 214 | { c=((c>>2L)|(c<<26L)); d=((d>>2L)|(d<<26L)); } | ||
| 215 | else | ||
| 216 | { c=((c>>1L)|(c<<27L)); d=((d>>1L)|(d<<27L)); } | ||
| 217 | c&=0x0fffffffL; | ||
| 218 | d&=0x0fffffffL; | ||
| 219 | /* could be a few less shifts but I am to lazy at this | ||
| 220 | * point in time to investigate */ | ||
| 221 | s= des_skb[0][ (c )&0x3f ]| | ||
| 222 | des_skb[1][((c>> 6)&0x03)|((c>> 7L)&0x3c)]| | ||
| 223 | des_skb[2][((c>>13)&0x0f)|((c>>14L)&0x30)]| | ||
| 224 | des_skb[3][((c>>20)&0x01)|((c>>21L)&0x06) | | ||
| 225 | ((c>>22L)&0x38)]; | ||
| 226 | t= des_skb[4][ (d )&0x3f ]| | ||
| 227 | des_skb[5][((d>> 7L)&0x03)|((d>> 8L)&0x3c)]| | ||
| 228 | des_skb[6][ (d>>15L)&0x3f ]| | ||
| 229 | des_skb[7][((d>>21L)&0x0f)|((d>>22L)&0x30)]; | ||
| 230 | |||
| 231 | /* table contained 0213 4657 */ | ||
| 232 | t2=((t<<16L)|(s&0x0000ffffL))&0xffffffffL; | ||
| 233 | *(k++)=ROTATE(t2,30)&0xffffffffL; | ||
| 234 | |||
| 235 | t2=((s>>16L)|(t&0xffff0000L)); | ||
| 236 | *(k++)=ROTATE(t2,26)&0xffffffffL; | ||
| 237 | } | ||
| 238 | return(0); | ||
| 239 | } | ||
| 240 | |||
| 241 | int des_key_sched(key, schedule) | ||
| 242 | des_cblock (*key); | ||
| 243 | des_key_schedule schedule; | ||
| 244 | { | ||
| 245 | return(des_set_key(key,schedule)); | ||
| 246 | } | ||
diff --git a/src/lib/libcrypto/des/spr.h b/src/lib/libcrypto/des/spr.h new file mode 100644 index 0000000000..81813f9f7a --- /dev/null +++ b/src/lib/libcrypto/des/spr.h | |||
| @@ -0,0 +1,204 @@ | |||
| 1 | /* crypto/des/spr.h */ | ||
| 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 | const DES_LONG des_SPtrans[8][64]={ | ||
| 60 | { | ||
| 61 | /* nibble 0 */ | ||
| 62 | 0x02080800L, 0x00080000L, 0x02000002L, 0x02080802L, | ||
| 63 | 0x02000000L, 0x00080802L, 0x00080002L, 0x02000002L, | ||
| 64 | 0x00080802L, 0x02080800L, 0x02080000L, 0x00000802L, | ||
| 65 | 0x02000802L, 0x02000000L, 0x00000000L, 0x00080002L, | ||
| 66 | 0x00080000L, 0x00000002L, 0x02000800L, 0x00080800L, | ||
| 67 | 0x02080802L, 0x02080000L, 0x00000802L, 0x02000800L, | ||
| 68 | 0x00000002L, 0x00000800L, 0x00080800L, 0x02080002L, | ||
| 69 | 0x00000800L, 0x02000802L, 0x02080002L, 0x00000000L, | ||
| 70 | 0x00000000L, 0x02080802L, 0x02000800L, 0x00080002L, | ||
| 71 | 0x02080800L, 0x00080000L, 0x00000802L, 0x02000800L, | ||
| 72 | 0x02080002L, 0x00000800L, 0x00080800L, 0x02000002L, | ||
| 73 | 0x00080802L, 0x00000002L, 0x02000002L, 0x02080000L, | ||
| 74 | 0x02080802L, 0x00080800L, 0x02080000L, 0x02000802L, | ||
| 75 | 0x02000000L, 0x00000802L, 0x00080002L, 0x00000000L, | ||
| 76 | 0x00080000L, 0x02000000L, 0x02000802L, 0x02080800L, | ||
| 77 | 0x00000002L, 0x02080002L, 0x00000800L, 0x00080802L, | ||
| 78 | },{ | ||
| 79 | /* nibble 1 */ | ||
| 80 | 0x40108010L, 0x00000000L, 0x00108000L, 0x40100000L, | ||
| 81 | 0x40000010L, 0x00008010L, 0x40008000L, 0x00108000L, | ||
| 82 | 0x00008000L, 0x40100010L, 0x00000010L, 0x40008000L, | ||
| 83 | 0x00100010L, 0x40108000L, 0x40100000L, 0x00000010L, | ||
| 84 | 0x00100000L, 0x40008010L, 0x40100010L, 0x00008000L, | ||
| 85 | 0x00108010L, 0x40000000L, 0x00000000L, 0x00100010L, | ||
| 86 | 0x40008010L, 0x00108010L, 0x40108000L, 0x40000010L, | ||
| 87 | 0x40000000L, 0x00100000L, 0x00008010L, 0x40108010L, | ||
| 88 | 0x00100010L, 0x40108000L, 0x40008000L, 0x00108010L, | ||
| 89 | 0x40108010L, 0x00100010L, 0x40000010L, 0x00000000L, | ||
| 90 | 0x40000000L, 0x00008010L, 0x00100000L, 0x40100010L, | ||
| 91 | 0x00008000L, 0x40000000L, 0x00108010L, 0x40008010L, | ||
| 92 | 0x40108000L, 0x00008000L, 0x00000000L, 0x40000010L, | ||
| 93 | 0x00000010L, 0x40108010L, 0x00108000L, 0x40100000L, | ||
| 94 | 0x40100010L, 0x00100000L, 0x00008010L, 0x40008000L, | ||
| 95 | 0x40008010L, 0x00000010L, 0x40100000L, 0x00108000L, | ||
| 96 | },{ | ||
| 97 | /* nibble 2 */ | ||
| 98 | 0x04000001L, 0x04040100L, 0x00000100L, 0x04000101L, | ||
| 99 | 0x00040001L, 0x04000000L, 0x04000101L, 0x00040100L, | ||
| 100 | 0x04000100L, 0x00040000L, 0x04040000L, 0x00000001L, | ||
| 101 | 0x04040101L, 0x00000101L, 0x00000001L, 0x04040001L, | ||
| 102 | 0x00000000L, 0x00040001L, 0x04040100L, 0x00000100L, | ||
| 103 | 0x00000101L, 0x04040101L, 0x00040000L, 0x04000001L, | ||
| 104 | 0x04040001L, 0x04000100L, 0x00040101L, 0x04040000L, | ||
| 105 | 0x00040100L, 0x00000000L, 0x04000000L, 0x00040101L, | ||
| 106 | 0x04040100L, 0x00000100L, 0x00000001L, 0x00040000L, | ||
| 107 | 0x00000101L, 0x00040001L, 0x04040000L, 0x04000101L, | ||
| 108 | 0x00000000L, 0x04040100L, 0x00040100L, 0x04040001L, | ||
| 109 | 0x00040001L, 0x04000000L, 0x04040101L, 0x00000001L, | ||
| 110 | 0x00040101L, 0x04000001L, 0x04000000L, 0x04040101L, | ||
| 111 | 0x00040000L, 0x04000100L, 0x04000101L, 0x00040100L, | ||
| 112 | 0x04000100L, 0x00000000L, 0x04040001L, 0x00000101L, | ||
| 113 | 0x04000001L, 0x00040101L, 0x00000100L, 0x04040000L, | ||
| 114 | },{ | ||
| 115 | /* nibble 3 */ | ||
| 116 | 0x00401008L, 0x10001000L, 0x00000008L, 0x10401008L, | ||
| 117 | 0x00000000L, 0x10400000L, 0x10001008L, 0x00400008L, | ||
| 118 | 0x10401000L, 0x10000008L, 0x10000000L, 0x00001008L, | ||
| 119 | 0x10000008L, 0x00401008L, 0x00400000L, 0x10000000L, | ||
| 120 | 0x10400008L, 0x00401000L, 0x00001000L, 0x00000008L, | ||
| 121 | 0x00401000L, 0x10001008L, 0x10400000L, 0x00001000L, | ||
| 122 | 0x00001008L, 0x00000000L, 0x00400008L, 0x10401000L, | ||
| 123 | 0x10001000L, 0x10400008L, 0x10401008L, 0x00400000L, | ||
| 124 | 0x10400008L, 0x00001008L, 0x00400000L, 0x10000008L, | ||
| 125 | 0x00401000L, 0x10001000L, 0x00000008L, 0x10400000L, | ||
| 126 | 0x10001008L, 0x00000000L, 0x00001000L, 0x00400008L, | ||
| 127 | 0x00000000L, 0x10400008L, 0x10401000L, 0x00001000L, | ||
| 128 | 0x10000000L, 0x10401008L, 0x00401008L, 0x00400000L, | ||
| 129 | 0x10401008L, 0x00000008L, 0x10001000L, 0x00401008L, | ||
| 130 | 0x00400008L, 0x00401000L, 0x10400000L, 0x10001008L, | ||
| 131 | 0x00001008L, 0x10000000L, 0x10000008L, 0x10401000L, | ||
| 132 | },{ | ||
| 133 | /* nibble 4 */ | ||
| 134 | 0x08000000L, 0x00010000L, 0x00000400L, 0x08010420L, | ||
| 135 | 0x08010020L, 0x08000400L, 0x00010420L, 0x08010000L, | ||
| 136 | 0x00010000L, 0x00000020L, 0x08000020L, 0x00010400L, | ||
| 137 | 0x08000420L, 0x08010020L, 0x08010400L, 0x00000000L, | ||
| 138 | 0x00010400L, 0x08000000L, 0x00010020L, 0x00000420L, | ||
| 139 | 0x08000400L, 0x00010420L, 0x00000000L, 0x08000020L, | ||
| 140 | 0x00000020L, 0x08000420L, 0x08010420L, 0x00010020L, | ||
| 141 | 0x08010000L, 0x00000400L, 0x00000420L, 0x08010400L, | ||
| 142 | 0x08010400L, 0x08000420L, 0x00010020L, 0x08010000L, | ||
| 143 | 0x00010000L, 0x00000020L, 0x08000020L, 0x08000400L, | ||
| 144 | 0x08000000L, 0x00010400L, 0x08010420L, 0x00000000L, | ||
| 145 | 0x00010420L, 0x08000000L, 0x00000400L, 0x00010020L, | ||
| 146 | 0x08000420L, 0x00000400L, 0x00000000L, 0x08010420L, | ||
| 147 | 0x08010020L, 0x08010400L, 0x00000420L, 0x00010000L, | ||
| 148 | 0x00010400L, 0x08010020L, 0x08000400L, 0x00000420L, | ||
| 149 | 0x00000020L, 0x00010420L, 0x08010000L, 0x08000020L, | ||
| 150 | },{ | ||
| 151 | /* nibble 5 */ | ||
| 152 | 0x80000040L, 0x00200040L, 0x00000000L, 0x80202000L, | ||
| 153 | 0x00200040L, 0x00002000L, 0x80002040L, 0x00200000L, | ||
| 154 | 0x00002040L, 0x80202040L, 0x00202000L, 0x80000000L, | ||
| 155 | 0x80002000L, 0x80000040L, 0x80200000L, 0x00202040L, | ||
| 156 | 0x00200000L, 0x80002040L, 0x80200040L, 0x00000000L, | ||
| 157 | 0x00002000L, 0x00000040L, 0x80202000L, 0x80200040L, | ||
| 158 | 0x80202040L, 0x80200000L, 0x80000000L, 0x00002040L, | ||
| 159 | 0x00000040L, 0x00202000L, 0x00202040L, 0x80002000L, | ||
| 160 | 0x00002040L, 0x80000000L, 0x80002000L, 0x00202040L, | ||
| 161 | 0x80202000L, 0x00200040L, 0x00000000L, 0x80002000L, | ||
| 162 | 0x80000000L, 0x00002000L, 0x80200040L, 0x00200000L, | ||
| 163 | 0x00200040L, 0x80202040L, 0x00202000L, 0x00000040L, | ||
| 164 | 0x80202040L, 0x00202000L, 0x00200000L, 0x80002040L, | ||
| 165 | 0x80000040L, 0x80200000L, 0x00202040L, 0x00000000L, | ||
| 166 | 0x00002000L, 0x80000040L, 0x80002040L, 0x80202000L, | ||
| 167 | 0x80200000L, 0x00002040L, 0x00000040L, 0x80200040L, | ||
| 168 | },{ | ||
| 169 | /* nibble 6 */ | ||
| 170 | 0x00004000L, 0x00000200L, 0x01000200L, 0x01000004L, | ||
| 171 | 0x01004204L, 0x00004004L, 0x00004200L, 0x00000000L, | ||
| 172 | 0x01000000L, 0x01000204L, 0x00000204L, 0x01004000L, | ||
| 173 | 0x00000004L, 0x01004200L, 0x01004000L, 0x00000204L, | ||
| 174 | 0x01000204L, 0x00004000L, 0x00004004L, 0x01004204L, | ||
| 175 | 0x00000000L, 0x01000200L, 0x01000004L, 0x00004200L, | ||
| 176 | 0x01004004L, 0x00004204L, 0x01004200L, 0x00000004L, | ||
| 177 | 0x00004204L, 0x01004004L, 0x00000200L, 0x01000000L, | ||
| 178 | 0x00004204L, 0x01004000L, 0x01004004L, 0x00000204L, | ||
| 179 | 0x00004000L, 0x00000200L, 0x01000000L, 0x01004004L, | ||
| 180 | 0x01000204L, 0x00004204L, 0x00004200L, 0x00000000L, | ||
| 181 | 0x00000200L, 0x01000004L, 0x00000004L, 0x01000200L, | ||
| 182 | 0x00000000L, 0x01000204L, 0x01000200L, 0x00004200L, | ||
| 183 | 0x00000204L, 0x00004000L, 0x01004204L, 0x01000000L, | ||
| 184 | 0x01004200L, 0x00000004L, 0x00004004L, 0x01004204L, | ||
| 185 | 0x01000004L, 0x01004200L, 0x01004000L, 0x00004004L, | ||
| 186 | },{ | ||
| 187 | /* nibble 7 */ | ||
| 188 | 0x20800080L, 0x20820000L, 0x00020080L, 0x00000000L, | ||
| 189 | 0x20020000L, 0x00800080L, 0x20800000L, 0x20820080L, | ||
| 190 | 0x00000080L, 0x20000000L, 0x00820000L, 0x00020080L, | ||
| 191 | 0x00820080L, 0x20020080L, 0x20000080L, 0x20800000L, | ||
| 192 | 0x00020000L, 0x00820080L, 0x00800080L, 0x20020000L, | ||
| 193 | 0x20820080L, 0x20000080L, 0x00000000L, 0x00820000L, | ||
| 194 | 0x20000000L, 0x00800000L, 0x20020080L, 0x20800080L, | ||
| 195 | 0x00800000L, 0x00020000L, 0x20820000L, 0x00000080L, | ||
| 196 | 0x00800000L, 0x00020000L, 0x20000080L, 0x20820080L, | ||
| 197 | 0x00020080L, 0x20000000L, 0x00000000L, 0x00820000L, | ||
| 198 | 0x20800080L, 0x20020080L, 0x20020000L, 0x00800080L, | ||
| 199 | 0x20820000L, 0x00000080L, 0x00800080L, 0x20020000L, | ||
| 200 | 0x20820080L, 0x00800000L, 0x20800000L, 0x20000080L, | ||
| 201 | 0x00820000L, 0x00020080L, 0x20020080L, 0x20800000L, | ||
| 202 | 0x00000080L, 0x20820000L, 0x00820080L, 0x00000000L, | ||
| 203 | 0x20000000L, 0x20800080L, 0x00020000L, 0x00820080L, | ||
| 204 | }}; | ||
diff --git a/src/lib/libcrypto/des/str2key.c b/src/lib/libcrypto/des/str2key.c new file mode 100644 index 0000000000..3365c1bcf3 --- /dev/null +++ b/src/lib/libcrypto/des/str2key.c | |||
| @@ -0,0 +1,171 @@ | |||
| 1 | /* crypto/des/str2key.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 "des_locl.h" | ||
| 60 | |||
| 61 | extern int des_check_key; | ||
| 62 | |||
| 63 | void des_string_to_key(str, key) | ||
| 64 | char *str; | ||
| 65 | des_cblock (*key); | ||
| 66 | { | ||
| 67 | des_key_schedule ks; | ||
| 68 | int i,length; | ||
| 69 | register unsigned char j; | ||
| 70 | |||
| 71 | memset(key,0,8); | ||
| 72 | length=strlen(str); | ||
| 73 | #ifdef OLD_STR_TO_KEY | ||
| 74 | for (i=0; i<length; i++) | ||
| 75 | (*key)[i%8]^=(str[i]<<1); | ||
| 76 | #else /* MIT COMPATIBLE */ | ||
| 77 | for (i=0; i<length; i++) | ||
| 78 | { | ||
| 79 | j=str[i]; | ||
| 80 | if ((i%16) < 8) | ||
| 81 | (*key)[i%8]^=(j<<1); | ||
| 82 | else | ||
| 83 | { | ||
| 84 | /* Reverse the bit order 05/05/92 eay */ | ||
| 85 | j=((j<<4)&0xf0)|((j>>4)&0x0f); | ||
| 86 | j=((j<<2)&0xcc)|((j>>2)&0x33); | ||
| 87 | j=((j<<1)&0xaa)|((j>>1)&0x55); | ||
| 88 | (*key)[7-(i%8)]^=j; | ||
| 89 | } | ||
| 90 | } | ||
| 91 | #endif | ||
| 92 | des_set_odd_parity((des_cblock *)key); | ||
| 93 | i=des_check_key; | ||
| 94 | des_check_key=0; | ||
| 95 | des_set_key((des_cblock *)key,ks); | ||
| 96 | des_check_key=i; | ||
| 97 | des_cbc_cksum((des_cblock *)str,(des_cblock *)key,(long)length,ks, | ||
| 98 | (des_cblock *)key); | ||
| 99 | memset(ks,0,sizeof(ks)); | ||
| 100 | des_set_odd_parity((des_cblock *)key); | ||
| 101 | } | ||
| 102 | |||
| 103 | void des_string_to_2keys(str, key1, key2) | ||
| 104 | char *str; | ||
| 105 | des_cblock (*key1); | ||
| 106 | des_cblock (*key2); | ||
| 107 | { | ||
| 108 | des_key_schedule ks; | ||
| 109 | int i,length; | ||
| 110 | register unsigned char j; | ||
| 111 | |||
| 112 | memset(key1,0,8); | ||
| 113 | memset(key2,0,8); | ||
| 114 | length=strlen(str); | ||
| 115 | #ifdef OLD_STR_TO_KEY | ||
| 116 | if (length <= 8) | ||
| 117 | { | ||
| 118 | for (i=0; i<length; i++) | ||
| 119 | { | ||
| 120 | (*key2)[i]=(*key1)[i]=(str[i]<<1); | ||
| 121 | } | ||
| 122 | } | ||
| 123 | else | ||
| 124 | { | ||
| 125 | for (i=0; i<length; i++) | ||
| 126 | { | ||
| 127 | if ((i/8)&1) | ||
| 128 | (*key2)[i%8]^=(str[i]<<1); | ||
| 129 | else | ||
| 130 | (*key1)[i%8]^=(str[i]<<1); | ||
| 131 | } | ||
| 132 | } | ||
| 133 | #else /* MIT COMPATIBLE */ | ||
| 134 | for (i=0; i<length; i++) | ||
| 135 | { | ||
| 136 | j=str[i]; | ||
| 137 | if ((i%32) < 16) | ||
| 138 | { | ||
| 139 | if ((i%16) < 8) | ||
| 140 | (*key1)[i%8]^=(j<<1); | ||
| 141 | else | ||
| 142 | (*key2)[i%8]^=(j<<1); | ||
| 143 | } | ||
| 144 | else | ||
| 145 | { | ||
| 146 | j=((j<<4)&0xf0)|((j>>4)&0x0f); | ||
| 147 | j=((j<<2)&0xcc)|((j>>2)&0x33); | ||
| 148 | j=((j<<1)&0xaa)|((j>>1)&0x55); | ||
| 149 | if ((i%16) < 8) | ||
| 150 | (*key1)[7-(i%8)]^=j; | ||
| 151 | else | ||
| 152 | (*key2)[7-(i%8)]^=j; | ||
| 153 | } | ||
| 154 | } | ||
| 155 | if (length <= 8) memcpy(key2,key1,8); | ||
| 156 | #endif | ||
| 157 | des_set_odd_parity((des_cblock *)key1); | ||
| 158 | des_set_odd_parity((des_cblock *)key2); | ||
| 159 | i=des_check_key; | ||
| 160 | des_check_key=0; | ||
| 161 | des_set_key((des_cblock *)key1,ks); | ||
| 162 | des_cbc_cksum((des_cblock *)str,(des_cblock *)key1,(long)length,ks, | ||
| 163 | (des_cblock *)key1); | ||
| 164 | des_set_key((des_cblock *)key2,ks); | ||
| 165 | des_cbc_cksum((des_cblock *)str,(des_cblock *)key2,(long)length,ks, | ||
| 166 | (des_cblock *)key2); | ||
| 167 | des_check_key=i; | ||
| 168 | memset(ks,0,sizeof(ks)); | ||
| 169 | des_set_odd_parity(key1); | ||
| 170 | des_set_odd_parity(key2); | ||
| 171 | } | ||
diff --git a/src/lib/libcrypto/des/xcbc_enc.c b/src/lib/libcrypto/des/xcbc_enc.c new file mode 100644 index 0000000000..031589bf50 --- /dev/null +++ b/src/lib/libcrypto/des/xcbc_enc.c | |||
| @@ -0,0 +1,206 @@ | |||
| 1 | /* crypto/des/xcbc_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 "des_locl.h" | ||
| 60 | |||
| 61 | /* RSA's DESX */ | ||
| 62 | |||
| 63 | static unsigned char desx_white_in2out[256]={ | ||
| 64 | 0xBD,0x56,0xEA,0xF2,0xA2,0xF1,0xAC,0x2A,0xB0,0x93,0xD1,0x9C,0x1B,0x33,0xFD,0xD0, | ||
| 65 | 0x30,0x04,0xB6,0xDC,0x7D,0xDF,0x32,0x4B,0xF7,0xCB,0x45,0x9B,0x31,0xBB,0x21,0x5A, | ||
| 66 | 0x41,0x9F,0xE1,0xD9,0x4A,0x4D,0x9E,0xDA,0xA0,0x68,0x2C,0xC3,0x27,0x5F,0x80,0x36, | ||
| 67 | 0x3E,0xEE,0xFB,0x95,0x1A,0xFE,0xCE,0xA8,0x34,0xA9,0x13,0xF0,0xA6,0x3F,0xD8,0x0C, | ||
| 68 | 0x78,0x24,0xAF,0x23,0x52,0xC1,0x67,0x17,0xF5,0x66,0x90,0xE7,0xE8,0x07,0xB8,0x60, | ||
| 69 | 0x48,0xE6,0x1E,0x53,0xF3,0x92,0xA4,0x72,0x8C,0x08,0x15,0x6E,0x86,0x00,0x84,0xFA, | ||
| 70 | 0xF4,0x7F,0x8A,0x42,0x19,0xF6,0xDB,0xCD,0x14,0x8D,0x50,0x12,0xBA,0x3C,0x06,0x4E, | ||
| 71 | 0xEC,0xB3,0x35,0x11,0xA1,0x88,0x8E,0x2B,0x94,0x99,0xB7,0x71,0x74,0xD3,0xE4,0xBF, | ||
| 72 | 0x3A,0xDE,0x96,0x0E,0xBC,0x0A,0xED,0x77,0xFC,0x37,0x6B,0x03,0x79,0x89,0x62,0xC6, | ||
| 73 | 0xD7,0xC0,0xD2,0x7C,0x6A,0x8B,0x22,0xA3,0x5B,0x05,0x5D,0x02,0x75,0xD5,0x61,0xE3, | ||
| 74 | 0x18,0x8F,0x55,0x51,0xAD,0x1F,0x0B,0x5E,0x85,0xE5,0xC2,0x57,0x63,0xCA,0x3D,0x6C, | ||
| 75 | 0xB4,0xC5,0xCC,0x70,0xB2,0x91,0x59,0x0D,0x47,0x20,0xC8,0x4F,0x58,0xE0,0x01,0xE2, | ||
| 76 | 0x16,0x38,0xC4,0x6F,0x3B,0x0F,0x65,0x46,0xBE,0x7E,0x2D,0x7B,0x82,0xF9,0x40,0xB5, | ||
| 77 | 0x1D,0x73,0xF8,0xEB,0x26,0xC7,0x87,0x97,0x25,0x54,0xB1,0x28,0xAA,0x98,0x9D,0xA5, | ||
| 78 | 0x64,0x6D,0x7A,0xD4,0x10,0x81,0x44,0xEF,0x49,0xD6,0xAE,0x2E,0xDD,0x76,0x5C,0x2F, | ||
| 79 | 0xA7,0x1C,0xC9,0x09,0x69,0x9A,0x83,0xCF,0x29,0x39,0xB9,0xE9,0x4C,0xFF,0x43,0xAB, | ||
| 80 | }; | ||
| 81 | |||
| 82 | void des_xwhite_in2out(des_key,in_white,out_white) | ||
| 83 | des_cblock (*des_key); | ||
| 84 | des_cblock (*in_white); | ||
| 85 | des_cblock (*out_white); | ||
| 86 | { | ||
| 87 | unsigned char *key,*in,*out; | ||
| 88 | int out0,out1; | ||
| 89 | int i; | ||
| 90 | |||
| 91 | key=(unsigned char *)des_key; | ||
| 92 | in=(unsigned char *)in_white; | ||
| 93 | out=(unsigned char *)out_white; | ||
| 94 | |||
| 95 | out[0]=out[1]=out[2]=out[3]=out[4]=out[5]=out[6]=out[7]=0; | ||
| 96 | out0=out1=0; | ||
| 97 | for (i=0; i<8; i++) | ||
| 98 | { | ||
| 99 | out[i]=key[i]^desx_white_in2out[out0^out1]; | ||
| 100 | out0=out1; | ||
| 101 | out1=(int)out[i&0x07]; | ||
| 102 | } | ||
| 103 | |||
| 104 | out0=out[0]; | ||
| 105 | out1=out[i]; | ||
| 106 | for (i=0; i<8; i++) | ||
| 107 | { | ||
| 108 | out[i]=in[i]^desx_white_in2out[out0^out1]; | ||
| 109 | out0=out1; | ||
| 110 | out1=(int)out[i&0x07]; | ||
| 111 | } | ||
| 112 | } | ||
| 113 | |||
| 114 | void des_xcbc_encrypt(input, output, length, schedule, ivec, inw,outw,enc) | ||
| 115 | des_cblock (*input); | ||
| 116 | des_cblock (*output); | ||
| 117 | long length; | ||
| 118 | des_key_schedule schedule; | ||
| 119 | des_cblock (*ivec); | ||
| 120 | des_cblock (*inw); | ||
| 121 | des_cblock (*outw); | ||
| 122 | int enc; | ||
| 123 | { | ||
| 124 | register DES_LONG tin0,tin1; | ||
| 125 | register DES_LONG tout0,tout1,xor0,xor1; | ||
| 126 | register DES_LONG inW0,inW1,outW0,outW1; | ||
| 127 | register unsigned char *in,*out; | ||
| 128 | register long l=length; | ||
| 129 | DES_LONG tin[2]; | ||
| 130 | unsigned char *iv; | ||
| 131 | |||
| 132 | in=(unsigned char *)inw; | ||
| 133 | c2l(in,inW0); | ||
| 134 | c2l(in,inW1); | ||
| 135 | in=(unsigned char *)outw; | ||
| 136 | c2l(in,outW0); | ||
| 137 | c2l(in,outW1); | ||
| 138 | |||
| 139 | in=(unsigned char *)input; | ||
| 140 | out=(unsigned char *)output; | ||
| 141 | iv=(unsigned char *)ivec; | ||
| 142 | |||
| 143 | if (enc) | ||
| 144 | { | ||
| 145 | c2l(iv,tout0); | ||
| 146 | c2l(iv,tout1); | ||
| 147 | for (l-=8; l>=0; l-=8) | ||
| 148 | { | ||
| 149 | c2l(in,tin0); | ||
| 150 | c2l(in,tin1); | ||
| 151 | tin0^=tout0^inW0; tin[0]=tin0; | ||
| 152 | tin1^=tout1^inW1; tin[1]=tin1; | ||
| 153 | des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); | ||
| 154 | tout0=tin[0]^outW0; l2c(tout0,out); | ||
| 155 | tout1=tin[1]^outW1; l2c(tout1,out); | ||
| 156 | } | ||
| 157 | if (l != -8) | ||
| 158 | { | ||
| 159 | c2ln(in,tin0,tin1,l+8); | ||
| 160 | tin0^=tout0^inW0; tin[0]=tin0; | ||
| 161 | tin1^=tout1^inW1; tin[1]=tin1; | ||
| 162 | des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); | ||
| 163 | tout0=tin[0]^outW0; l2c(tout0,out); | ||
| 164 | tout1=tin[1]^outW1; l2c(tout1,out); | ||
| 165 | } | ||
| 166 | iv=(unsigned char *)ivec; | ||
| 167 | l2c(tout0,iv); | ||
| 168 | l2c(tout1,iv); | ||
| 169 | } | ||
| 170 | else | ||
| 171 | { | ||
| 172 | c2l(iv,xor0); | ||
| 173 | c2l(iv,xor1); | ||
| 174 | for (l-=8; l>0; l-=8) | ||
| 175 | { | ||
| 176 | c2l(in,tin0); tin[0]=tin0^outW0; | ||
| 177 | c2l(in,tin1); tin[1]=tin1^outW1; | ||
| 178 | des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); | ||
| 179 | tout0=tin[0]^xor0^inW0; | ||
| 180 | tout1=tin[1]^xor1^inW1; | ||
| 181 | l2c(tout0,out); | ||
| 182 | l2c(tout1,out); | ||
| 183 | xor0=tin0; | ||
| 184 | xor1=tin1; | ||
| 185 | } | ||
| 186 | if (l != -8) | ||
| 187 | { | ||
| 188 | c2l(in,tin0); tin[0]=tin0^outW0; | ||
| 189 | c2l(in,tin1); tin[1]=tin1^outW1; | ||
| 190 | des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); | ||
| 191 | tout0=tin[0]^xor0^inW0; | ||
| 192 | tout1=tin[1]^xor1^inW1; | ||
| 193 | l2cn(tout0,tout1,out,l+8); | ||
| 194 | xor0=tin0; | ||
| 195 | xor1=tin1; | ||
| 196 | } | ||
| 197 | |||
| 198 | iv=(unsigned char *)ivec; | ||
| 199 | l2c(xor0,iv); | ||
| 200 | l2c(xor1,iv); | ||
| 201 | } | ||
| 202 | tin0=tin1=tout0=tout1=xor0=xor1=0; | ||
| 203 | inW0=inW1=outW0=outW1=0; | ||
| 204 | tin[0]=tin[1]=0; | ||
| 205 | } | ||
| 206 | |||
diff --git a/src/lib/libcrypto/dh/dh.h b/src/lib/libcrypto/dh/dh.h new file mode 100644 index 0000000000..4cc1df2650 --- /dev/null +++ b/src/lib/libcrypto/dh/dh.h | |||
| @@ -0,0 +1,162 @@ | |||
| 1 | /* crypto/dh/dh.h */ | ||
| 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 | #ifndef HEADER_DH_H | ||
| 60 | #define HEADER_DH_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #ifndef HEADER_BN_H | ||
| 67 | #define BIGNUM char | ||
| 68 | #endif | ||
| 69 | |||
| 70 | typedef struct dh_st | ||
| 71 | { | ||
| 72 | /* This first argument is used to pick up errors when | ||
| 73 | * a DH is passed instead of a EVP_PKEY */ | ||
| 74 | int pad; | ||
| 75 | int version; | ||
| 76 | BIGNUM *p; | ||
| 77 | BIGNUM *g; | ||
| 78 | int length; /* optional */ | ||
| 79 | BIGNUM *pub_key; /* y */ | ||
| 80 | BIGNUM *priv_key; /* x */ | ||
| 81 | } DH; | ||
| 82 | |||
| 83 | #define DH_GENERATOR_2 2 | ||
| 84 | /* #define DH_GENERATOR_3 3 */ | ||
| 85 | #define DH_GENERATOR_5 5 | ||
| 86 | |||
| 87 | /* DH_check error codes */ | ||
| 88 | #define DH_CHECK_P_NOT_PRIME 0x01 | ||
| 89 | #define DH_CHECK_P_NOT_STRONG_PRIME 0x02 | ||
| 90 | #define DH_UNABLE_TO_CHECK_GENERATOR 0x04 | ||
| 91 | #define DH_NOT_SUITABLE_GENERATOR 0x08 | ||
| 92 | |||
| 93 | #define DHparams_dup(x) (DH *)ASN1_dup((int (*)())i2d_DHparams, \ | ||
| 94 | (char *(*)())d2i_DHparams,(char *)(x)) | ||
| 95 | #define d2i_DHparams_fp(fp,x) (DH *)ASN1_d2i_fp((char *(*)())DH_new, \ | ||
| 96 | (char *(*)())d2i_DHparams,(fp),(unsigned char **)(x)) | ||
| 97 | #define i2d_DHparams_fp(fp,x) ASN1_i2d_fp(i2d_DHparams,(fp), \ | ||
| 98 | (unsigned char *)(x)) | ||
| 99 | #define d2i_DHparams_bio(bp,x) (DH *)ASN1_d2i_bio((char *(*)())DH_new, \ | ||
| 100 | (char *(*)())d2i_DHparams,(bp),(unsigned char **)(x)) | ||
| 101 | #define i2d_DHparams_bio(bp,x) ASN1_i2d_bio(i2d_DHparams,(bp), \ | ||
| 102 | (unsigned char *)(x)) | ||
| 103 | |||
| 104 | #ifndef NOPROTO | ||
| 105 | DH * DH_new(void); | ||
| 106 | void DH_free(DH *dh); | ||
| 107 | int DH_size(DH *dh); | ||
| 108 | DH * DH_generate_parameters(int prime_len,int generator, | ||
| 109 | void (*callback)(int,int,char *),char *cb_arg); | ||
| 110 | int DH_check(DH *dh,int *codes); | ||
| 111 | int DH_generate_key(DH *dh); | ||
| 112 | int DH_compute_key(unsigned char *key,BIGNUM *pub_key,DH *dh); | ||
| 113 | DH * d2i_DHparams(DH **a,unsigned char **pp, long length); | ||
| 114 | int i2d_DHparams(DH *a,unsigned char **pp); | ||
| 115 | #ifndef NO_FP_API | ||
| 116 | int DHparams_print_fp(FILE *fp, DH *x); | ||
| 117 | #endif | ||
| 118 | #ifdef HEADER_BIO_H | ||
| 119 | int DHparams_print(BIO *bp, DH *x); | ||
| 120 | #else | ||
| 121 | int DHparams_print(char *bp, DH *x); | ||
| 122 | #endif | ||
| 123 | void ERR_load_DH_strings(void ); | ||
| 124 | |||
| 125 | #else | ||
| 126 | |||
| 127 | DH * DH_new(); | ||
| 128 | void DH_free(); | ||
| 129 | int DH_size(); | ||
| 130 | DH * DH_generate_parameters(); | ||
| 131 | int DH_check(); | ||
| 132 | int DH_generate_key(); | ||
| 133 | int DH_compute_key(); | ||
| 134 | DH * d2i_DHparams(); | ||
| 135 | int i2d_DHparams(); | ||
| 136 | #ifndef NO_FP_API | ||
| 137 | int DHparams_print_fp(); | ||
| 138 | #endif | ||
| 139 | int DHparams_print(); | ||
| 140 | void ERR_load_DH_strings(); | ||
| 141 | |||
| 142 | #endif | ||
| 143 | |||
| 144 | /* BEGIN ERROR CODES */ | ||
| 145 | /* Error codes for the DH functions. */ | ||
| 146 | |||
| 147 | /* Function codes. */ | ||
| 148 | #define DH_F_DHPARAMS_PRINT 100 | ||
| 149 | #define DH_F_DHPARAMS_PRINT_FP 101 | ||
| 150 | #define DH_F_DH_COMPUTE_KEY 102 | ||
| 151 | #define DH_F_DH_GENERATE_KEY 103 | ||
| 152 | #define DH_F_DH_GENERATE_PARAMETERS 104 | ||
| 153 | #define DH_F_DH_NEW 105 | ||
| 154 | |||
| 155 | /* Reason codes. */ | ||
| 156 | #define DH_R_NO_PRIVATE_VALUE 100 | ||
| 157 | |||
| 158 | #ifdef __cplusplus | ||
| 159 | } | ||
| 160 | #endif | ||
| 161 | #endif | ||
| 162 | |||
diff --git a/src/lib/libcrypto/dh/dh_check.c b/src/lib/libcrypto/dh/dh_check.c new file mode 100644 index 0000000000..65602e494f --- /dev/null +++ b/src/lib/libcrypto/dh/dh_check.c | |||
| @@ -0,0 +1,120 @@ | |||
| 1 | /* crypto/dh/dh_check.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 | |||
| 64 | /* Check that p is a strong prime and | ||
| 65 | * if g is 2, 3 or 5, check that is is a suitable generator | ||
| 66 | * where | ||
| 67 | * for 2, p mod 24 == 11 | ||
| 68 | * for 3, p mod 12 == 5 | ||
| 69 | * for 5, p mod 10 == 3 or 7 | ||
| 70 | * should hold. | ||
| 71 | */ | ||
| 72 | |||
| 73 | int DH_check(dh,ret) | ||
| 74 | DH *dh; | ||
| 75 | int *ret; | ||
| 76 | { | ||
| 77 | int ok=0; | ||
| 78 | BN_CTX *ctx=NULL; | ||
| 79 | BN_ULONG l; | ||
| 80 | BIGNUM *q=NULL; | ||
| 81 | |||
| 82 | *ret=0; | ||
| 83 | ctx=BN_CTX_new(); | ||
| 84 | if (ctx == NULL) goto err; | ||
| 85 | q=BN_new(); | ||
| 86 | if (q == NULL) goto err; | ||
| 87 | |||
| 88 | if (BN_is_word(dh->g,DH_GENERATOR_2)) | ||
| 89 | { | ||
| 90 | l=BN_mod_word(dh->p,24); | ||
| 91 | if (l != 11) *ret|=DH_NOT_SUITABLE_GENERATOR; | ||
| 92 | } | ||
| 93 | /* else if (BN_is_word(dh->g,DH_GENERATOR_3)) | ||
| 94 | { | ||
| 95 | l=BN_mod_word(dh->p,12); | ||
| 96 | if (l != 5) *ret|=DH_NOT_SUITABLE_GENERATOR; | ||
| 97 | }*/ | ||
| 98 | else if (BN_is_word(dh->g,DH_GENERATOR_5)) | ||
| 99 | { | ||
| 100 | l=BN_mod_word(dh->p,10); | ||
| 101 | if ((l != 3) && (l != 7)) | ||
| 102 | *ret|=DH_NOT_SUITABLE_GENERATOR; | ||
| 103 | } | ||
| 104 | else | ||
| 105 | *ret|=DH_UNABLE_TO_CHECK_GENERATOR; | ||
| 106 | |||
| 107 | if (!BN_is_prime(dh->p,BN_prime_checks,NULL,ctx,NULL)) | ||
| 108 | *ret|=DH_CHECK_P_NOT_PRIME; | ||
| 109 | else | ||
| 110 | { | ||
| 111 | if (!BN_rshift1(q,dh->p)) goto err; | ||
| 112 | if (!BN_is_prime(q,BN_prime_checks,NULL,ctx,NULL)) | ||
| 113 | *ret|=DH_CHECK_P_NOT_STRONG_PRIME; | ||
| 114 | } | ||
| 115 | ok=1; | ||
| 116 | err: | ||
| 117 | if (ctx != NULL) BN_CTX_free(ctx); | ||
| 118 | if (q != NULL) BN_free(q); | ||
| 119 | return(ok); | ||
| 120 | } | ||
diff --git a/src/lib/libcrypto/dh/dh_err.c b/src/lib/libcrypto/dh/dh_err.c new file mode 100644 index 0000000000..9d5c06ac24 --- /dev/null +++ b/src/lib/libcrypto/dh/dh_err.c | |||
| @@ -0,0 +1,96 @@ | |||
| 1 | /* lib/dh/dh_err.c */ | ||
| 2 | /* Copyright (C) 1995-1997 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 | #include <stdio.h> | ||
| 59 | #include "err.h" | ||
| 60 | #include "dh.h" | ||
| 61 | |||
| 62 | /* BEGIN ERROR CODES */ | ||
| 63 | #ifndef NO_ERR | ||
| 64 | static ERR_STRING_DATA DH_str_functs[]= | ||
| 65 | { | ||
| 66 | {ERR_PACK(0,DH_F_DHPARAMS_PRINT,0), "DHparams_print"}, | ||
| 67 | {ERR_PACK(0,DH_F_DHPARAMS_PRINT_FP,0), "DHparams_print_fp"}, | ||
| 68 | {ERR_PACK(0,DH_F_DH_COMPUTE_KEY,0), "DH_compute_key"}, | ||
| 69 | {ERR_PACK(0,DH_F_DH_GENERATE_KEY,0), "DH_generate_key"}, | ||
| 70 | {ERR_PACK(0,DH_F_DH_GENERATE_PARAMETERS,0), "DH_generate_parameters"}, | ||
| 71 | {ERR_PACK(0,DH_F_DH_NEW,0), "DH_new"}, | ||
| 72 | {0,NULL}, | ||
| 73 | }; | ||
| 74 | |||
| 75 | static ERR_STRING_DATA DH_str_reasons[]= | ||
| 76 | { | ||
| 77 | {DH_R_NO_PRIVATE_VALUE ,"no private value"}, | ||
| 78 | {0,NULL}, | ||
| 79 | }; | ||
| 80 | |||
| 81 | #endif | ||
| 82 | |||
| 83 | void ERR_load_DH_strings() | ||
| 84 | { | ||
| 85 | static int init=1; | ||
| 86 | |||
| 87 | if (init); | ||
| 88 | {; | ||
| 89 | init=0; | ||
| 90 | #ifndef NO_ERR | ||
| 91 | ERR_load_strings(ERR_LIB_DH,DH_str_functs); | ||
| 92 | ERR_load_strings(ERR_LIB_DH,DH_str_reasons); | ||
| 93 | #endif | ||
| 94 | |||
| 95 | } | ||
| 96 | } | ||
diff --git a/src/lib/libcrypto/dh/dh_gen.c b/src/lib/libcrypto/dh/dh_gen.c new file mode 100644 index 0000000000..04c7046a7b --- /dev/null +++ b/src/lib/libcrypto/dh/dh_gen.c | |||
| @@ -0,0 +1,150 @@ | |||
| 1 | /* crypto/dh/dh_gen.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 | |||
| 64 | /* We generate DH parameters as follows | ||
| 65 | * find a prime q which is prime_len/2 bits long. | ||
| 66 | * p=(2*q)+1 or (p-1)/2 = q | ||
| 67 | * For this case, g is a generator if | ||
| 68 | * g^((p-1)/q) mod p != 1 for values of q which are the factors of p-1. | ||
| 69 | * Since the factors of p-1 are q and 2, we just need to check | ||
| 70 | * g^2 mod p != 1 and g^q mod p != 1. | ||
| 71 | * | ||
| 72 | * Having said all that, | ||
| 73 | * there is another special case method for the generators 2, 3 and 5. | ||
| 74 | * for 2, p mod 24 == 11 | ||
| 75 | * for 3, p mod 12 == 5 <<<<< does not work for strong primes. | ||
| 76 | * for 5, p mod 10 == 3 or 7 | ||
| 77 | * | ||
| 78 | * Thanks to Phil Karn <karn@qualcomm.com> for the pointers about the | ||
| 79 | * special generators and for answering some of my questions. | ||
| 80 | * | ||
| 81 | * I've implemented the second simple method :-). | ||
| 82 | * Since DH should be using a strong prime (both p and q are prime), | ||
| 83 | * this generator function can take a very very long time to run. | ||
| 84 | */ | ||
| 85 | |||
| 86 | DH *DH_generate_parameters(prime_len,generator,callback,cb_arg) | ||
| 87 | int prime_len; | ||
| 88 | int generator; | ||
| 89 | void (*callback)(P_I_I_P); | ||
| 90 | char *cb_arg; | ||
| 91 | { | ||
| 92 | BIGNUM *p=NULL,*t1,*t2; | ||
| 93 | DH *ret=NULL; | ||
| 94 | int g,ok= -1; | ||
| 95 | BN_CTX *ctx=NULL; | ||
| 96 | |||
| 97 | ret=DH_new(); | ||
| 98 | ctx=BN_CTX_new(); | ||
| 99 | if (ctx == NULL) goto err; | ||
| 100 | t1=ctx->bn[0]; | ||
| 101 | t2=ctx->bn[1]; | ||
| 102 | ctx->tos=2; | ||
| 103 | |||
| 104 | if (generator == DH_GENERATOR_2) | ||
| 105 | { | ||
| 106 | BN_set_word(t1,24); | ||
| 107 | BN_set_word(t2,11); | ||
| 108 | g=2; | ||
| 109 | } | ||
| 110 | #ifdef undef /* does not work for strong primes */ | ||
| 111 | else if (generator == DH_GENERATOR_3) | ||
| 112 | { | ||
| 113 | BN_set_word(t1,12); | ||
| 114 | BN_set_word(t2,5); | ||
| 115 | g=3; | ||
| 116 | } | ||
| 117 | #endif | ||
| 118 | else if (generator == DH_GENERATOR_5) | ||
| 119 | { | ||
| 120 | BN_set_word(t1,10); | ||
| 121 | BN_set_word(t2,3); | ||
| 122 | /* BN_set_word(t3,7); just have to miss | ||
| 123 | * out on these ones :-( */ | ||
| 124 | g=5; | ||
| 125 | } | ||
| 126 | else | ||
| 127 | g=generator; | ||
| 128 | |||
| 129 | p=BN_generate_prime(prime_len,1,t1,t2,callback,cb_arg); | ||
| 130 | if (p == NULL) goto err; | ||
| 131 | if (callback != NULL) callback(3,0,cb_arg); | ||
| 132 | ret->p=p; | ||
| 133 | ret->g=BN_new(); | ||
| 134 | if (!BN_set_word(ret->g,g)) goto err; | ||
| 135 | ok=1; | ||
| 136 | err: | ||
| 137 | if (ok == -1) | ||
| 138 | { | ||
| 139 | DHerr(DH_F_DH_GENERATE_PARAMETERS,ERR_R_BN_LIB); | ||
| 140 | ok=0; | ||
| 141 | } | ||
| 142 | |||
| 143 | if (ctx != NULL) BN_CTX_free(ctx); | ||
| 144 | if (!ok && (ret != NULL)) | ||
| 145 | { | ||
| 146 | DH_free(ret); | ||
| 147 | ret=NULL; | ||
| 148 | } | ||
| 149 | return(ret); | ||
| 150 | } | ||
diff --git a/src/lib/libcrypto/dh/dh_key.c b/src/lib/libcrypto/dh/dh_key.c new file mode 100644 index 0000000000..7576772bcd --- /dev/null +++ b/src/lib/libcrypto/dh/dh_key.c | |||
| @@ -0,0 +1,142 @@ | |||
| 1 | /* crypto/dh/dh_key.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 "rand.h" | ||
| 63 | #include "dh.h" | ||
| 64 | |||
| 65 | int DH_generate_key(dh) | ||
| 66 | DH *dh; | ||
| 67 | { | ||
| 68 | int ok=0; | ||
| 69 | unsigned int i; | ||
| 70 | BN_CTX *ctx=NULL; | ||
| 71 | BIGNUM *pub_key=NULL,*priv_key=NULL; | ||
| 72 | |||
| 73 | ctx=BN_CTX_new(); | ||
| 74 | if (ctx == NULL) goto err; | ||
| 75 | |||
| 76 | if (dh->priv_key == NULL) | ||
| 77 | { | ||
| 78 | i=dh->length; | ||
| 79 | if (i == 0) | ||
| 80 | { | ||
| 81 | /* Make the number p-1 bits long */ | ||
| 82 | i=BN_num_bits(dh->p)-1; | ||
| 83 | } | ||
| 84 | priv_key=BN_new(); | ||
| 85 | if (priv_key == NULL) goto err; | ||
| 86 | if (!BN_rand(priv_key,i,0,0)) goto err; | ||
| 87 | } | ||
| 88 | else | ||
| 89 | priv_key=dh->priv_key; | ||
| 90 | |||
| 91 | if (dh->pub_key == NULL) | ||
| 92 | { | ||
| 93 | pub_key=BN_new(); | ||
| 94 | if (pub_key == NULL) goto err; | ||
| 95 | } | ||
| 96 | else | ||
| 97 | pub_key=dh->pub_key; | ||
| 98 | |||
| 99 | if (!BN_mod_exp(pub_key,dh->g,priv_key,dh->p,ctx)) goto err; | ||
| 100 | |||
| 101 | dh->pub_key=pub_key; | ||
| 102 | dh->priv_key=priv_key; | ||
| 103 | ok=1; | ||
| 104 | err: | ||
| 105 | if (ok != 1) | ||
| 106 | DHerr(DH_F_DH_GENERATE_KEY,ERR_R_BN_LIB); | ||
| 107 | |||
| 108 | if ((pub_key != NULL) && (dh->pub_key == NULL)) BN_free(pub_key); | ||
| 109 | if ((priv_key != NULL) && (dh->priv_key == NULL)) BN_free(priv_key); | ||
| 110 | if (ctx != NULL) BN_CTX_free(ctx); | ||
| 111 | return(ok); | ||
| 112 | } | ||
| 113 | |||
| 114 | int DH_compute_key(key,pub_key,dh) | ||
| 115 | unsigned char *key; | ||
| 116 | BIGNUM *pub_key; | ||
| 117 | DH *dh; | ||
| 118 | { | ||
| 119 | BN_CTX *ctx; | ||
| 120 | BIGNUM *tmp; | ||
| 121 | int ret= -1; | ||
| 122 | |||
| 123 | ctx=BN_CTX_new(); | ||
| 124 | if (ctx == NULL) goto err; | ||
| 125 | tmp=ctx->bn[ctx->tos++]; | ||
| 126 | |||
| 127 | if (dh->priv_key == NULL) | ||
| 128 | { | ||
| 129 | DHerr(DH_F_DH_COMPUTE_KEY,DH_R_NO_PRIVATE_VALUE); | ||
| 130 | goto err; | ||
| 131 | } | ||
| 132 | if (!BN_mod_exp(tmp,pub_key,dh->priv_key,dh->p,ctx)) | ||
| 133 | { | ||
| 134 | DHerr(DH_F_DH_COMPUTE_KEY,ERR_R_BN_LIB); | ||
| 135 | goto err; | ||
| 136 | } | ||
| 137 | |||
| 138 | ret=BN_bn2bin(tmp,key); | ||
| 139 | err: | ||
| 140 | if (ctx != NULL) BN_CTX_free(ctx); | ||
| 141 | return(ret); | ||
| 142 | } | ||
diff --git a/src/lib/libcrypto/dh/dh_lib.c b/src/lib/libcrypto/dh/dh_lib.c new file mode 100644 index 0000000000..a300b38396 --- /dev/null +++ b/src/lib/libcrypto/dh/dh_lib.c | |||
| @@ -0,0 +1,100 @@ | |||
| 1 | /* crypto/dh/dh_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 "bn.h" | ||
| 62 | #include "dh.h" | ||
| 63 | |||
| 64 | char *DH_version="Diffie-Hellman part of SSLeay 0.9.0b 29-Jun-1998"; | ||
| 65 | |||
| 66 | DH *DH_new() | ||
| 67 | { | ||
| 68 | DH *ret; | ||
| 69 | |||
| 70 | ret=(DH *)Malloc(sizeof(DH)); | ||
| 71 | if (ret == NULL) | ||
| 72 | { | ||
| 73 | DHerr(DH_F_DH_NEW,ERR_R_MALLOC_FAILURE); | ||
| 74 | return(NULL); | ||
| 75 | } | ||
| 76 | ret->pad=0; | ||
| 77 | ret->version=0; | ||
| 78 | ret->p=NULL; | ||
| 79 | ret->g=NULL; | ||
| 80 | ret->length=0; | ||
| 81 | ret->pub_key=NULL; | ||
| 82 | ret->priv_key=NULL; | ||
| 83 | return(ret); | ||
| 84 | } | ||
| 85 | |||
| 86 | void DH_free(r) | ||
| 87 | DH *r; | ||
| 88 | { | ||
| 89 | if (r->p != NULL) BN_clear_free(r->p); | ||
| 90 | if (r->g != NULL) BN_clear_free(r->g); | ||
| 91 | if (r->pub_key != NULL) BN_clear_free(r->pub_key); | ||
| 92 | if (r->priv_key != NULL) BN_clear_free(r->priv_key); | ||
| 93 | Free(r); | ||
| 94 | } | ||
| 95 | |||
| 96 | int DH_size(dh) | ||
| 97 | DH *dh; | ||
| 98 | { | ||
| 99 | return(BN_num_bytes(dh->p)); | ||
| 100 | } | ||
diff --git a/src/lib/libcrypto/dsa/dsa.h b/src/lib/libcrypto/dsa/dsa.h new file mode 100644 index 0000000000..1ca87c1cbe --- /dev/null +++ b/src/lib/libcrypto/dsa/dsa.h | |||
| @@ -0,0 +1,194 @@ | |||
| 1 | /* crypto/dsa/dsa.h */ | ||
| 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 | /* | ||
| 60 | * The DSS routines are based on patches supplied by | ||
| 61 | * Steven Schoch <schoch@sheba.arc.nasa.gov>. He basically did the | ||
| 62 | * work and I have just tweaked them a little to fit into my | ||
| 63 | * stylistic vision for SSLeay :-) */ | ||
| 64 | |||
| 65 | #ifndef HEADER_DSA_H | ||
| 66 | #define HEADER_DSA_H | ||
| 67 | |||
| 68 | #ifdef __cplusplus | ||
| 69 | extern "C" { | ||
| 70 | #endif | ||
| 71 | |||
| 72 | #include "bn.h" | ||
| 73 | |||
| 74 | typedef struct dsa_st | ||
| 75 | { | ||
| 76 | /* This first variable is used to pick up errors where | ||
| 77 | * a DSA is passed instead of of a EVP_PKEY */ | ||
| 78 | int pad; | ||
| 79 | int version; | ||
| 80 | int write_params; | ||
| 81 | BIGNUM *p; | ||
| 82 | BIGNUM *q; /* == 20 */ | ||
| 83 | BIGNUM *g; | ||
| 84 | |||
| 85 | BIGNUM *pub_key; /* y public key */ | ||
| 86 | BIGNUM *priv_key; /* x private key */ | ||
| 87 | |||
| 88 | BIGNUM *kinv; /* Signing pre-calc */ | ||
| 89 | BIGNUM *r; /* Signing pre-calc */ | ||
| 90 | |||
| 91 | int references; | ||
| 92 | } DSA; | ||
| 93 | |||
| 94 | #define DSAparams_dup(x) (DSA *)ASN1_dup((int (*)())i2d_DSAparams, \ | ||
| 95 | (char *(*)())d2i_DSAparams,(char *)(x)) | ||
| 96 | #define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \ | ||
| 97 | (char *(*)())d2i_DSAparams,(fp),(unsigned char **)(x)) | ||
| 98 | #define i2d_DSAparams_fp(fp,x) ASN1_i2d_fp(i2d_DSAparams,(fp), \ | ||
| 99 | (unsigned char *)(x)) | ||
| 100 | #define d2i_DSAparams_bio(bp,x) (DSA *)ASN1_d2i_bio((char *(*)())DSA_new, \ | ||
| 101 | (char *(*)())d2i_DSAparams,(bp),(unsigned char **)(x)) | ||
| 102 | #define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio(i2d_DSAparams,(bp), \ | ||
| 103 | (unsigned char *)(x)) | ||
| 104 | |||
| 105 | #ifndef NOPROTO | ||
| 106 | |||
| 107 | DSA * DSA_new(void); | ||
| 108 | int DSA_size(DSA *); | ||
| 109 | /* next 4 return -1 on error */ | ||
| 110 | int DSA_sign_setup( DSA *dsa,BN_CTX *ctx_in,BIGNUM **kinvp,BIGNUM **rp); | ||
| 111 | int DSA_sign(int type,unsigned char *dgst,int dlen, | ||
| 112 | unsigned char *sig, unsigned int *siglen, DSA *dsa); | ||
| 113 | int DSA_verify(int type,unsigned char *dgst,int dgst_len, | ||
| 114 | unsigned char *sigbuf, int siglen, DSA *dsa); | ||
| 115 | void DSA_free (DSA *r); | ||
| 116 | |||
| 117 | void ERR_load_DSA_strings(void ); | ||
| 118 | |||
| 119 | DSA * d2i_DSAPublicKey(DSA **a, unsigned char **pp, long length); | ||
| 120 | DSA * d2i_DSAPrivateKey(DSA **a, unsigned char **pp, long length); | ||
| 121 | DSA * d2i_DSAparams(DSA **a, unsigned char **pp, long length); | ||
| 122 | DSA * DSA_generate_parameters(int bits, unsigned char *seed,int seed_len, | ||
| 123 | int *counter_ret, unsigned long *h_ret,void | ||
| 124 | (*callback)(),char *cb_arg); | ||
| 125 | int DSA_generate_key(DSA *a); | ||
| 126 | int i2d_DSAPublicKey(DSA *a, unsigned char **pp); | ||
| 127 | int i2d_DSAPrivateKey(DSA *a, unsigned char **pp); | ||
| 128 | int i2d_DSAparams(DSA *a,unsigned char **pp); | ||
| 129 | |||
| 130 | #ifdef HEADER_BIO_H | ||
| 131 | int DSAparams_print(BIO *bp, DSA *x); | ||
| 132 | int DSA_print(BIO *bp, DSA *x, int off); | ||
| 133 | #endif | ||
| 134 | #ifndef NO_FP_API | ||
| 135 | int DSAparams_print_fp(FILE *fp, DSA *x); | ||
| 136 | int DSA_print_fp(FILE *bp, DSA *x, int off); | ||
| 137 | #endif | ||
| 138 | |||
| 139 | int DSA_is_prime(BIGNUM *q,void (*callback)(),char *cb_arg); | ||
| 140 | |||
| 141 | #else | ||
| 142 | |||
| 143 | DSA * DSA_new(); | ||
| 144 | int DSA_size(); | ||
| 145 | int DSA_sign_setup(); | ||
| 146 | int DSA_sign(); | ||
| 147 | int DSA_verify(); | ||
| 148 | void DSA_free (); | ||
| 149 | |||
| 150 | void ERR_load_DSA_strings(); | ||
| 151 | |||
| 152 | DSA * d2i_DSAPublicKey(); | ||
| 153 | DSA * d2i_DSAPrivateKey(); | ||
| 154 | DSA * d2i_DSAparams(); | ||
| 155 | DSA * DSA_generate_parameters(); | ||
| 156 | int DSA_generate_key(); | ||
| 157 | int i2d_DSAPublicKey(); | ||
| 158 | int i2d_DSAPrivateKey(); | ||
| 159 | int i2d_DSAparams(); | ||
| 160 | |||
| 161 | int DSA_is_prime(); | ||
| 162 | |||
| 163 | int DSAparams_print(); | ||
| 164 | int DSA_print(); | ||
| 165 | |||
| 166 | #ifndef NO_FP_API | ||
| 167 | int DSAparams_print_fp(); | ||
| 168 | int DSA_print_fp(); | ||
| 169 | #endif | ||
| 170 | |||
| 171 | #endif | ||
| 172 | |||
| 173 | /* BEGIN ERROR CODES */ | ||
| 174 | /* Error codes for the DSA functions. */ | ||
| 175 | |||
| 176 | /* Function codes. */ | ||
| 177 | #define DSA_F_DSAPARAMS_PRINT 100 | ||
| 178 | #define DSA_F_DSAPARAMS_PRINT_FP 101 | ||
| 179 | #define DSA_F_DSA_IS_PRIME 102 | ||
| 180 | #define DSA_F_DSA_NEW 103 | ||
| 181 | #define DSA_F_DSA_PRINT 104 | ||
| 182 | #define DSA_F_DSA_PRINT_FP 105 | ||
| 183 | #define DSA_F_DSA_SIGN 106 | ||
| 184 | #define DSA_F_DSA_SIGN_SETUP 107 | ||
| 185 | #define DSA_F_DSA_VERIFY 108 | ||
| 186 | |||
| 187 | /* Reason codes. */ | ||
| 188 | #define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 100 | ||
| 189 | |||
| 190 | #ifdef __cplusplus | ||
| 191 | } | ||
| 192 | #endif | ||
| 193 | #endif | ||
| 194 | |||
diff --git a/src/lib/libcrypto/dsa/dsa_err.c b/src/lib/libcrypto/dsa/dsa_err.c new file mode 100644 index 0000000000..318e9f31aa --- /dev/null +++ b/src/lib/libcrypto/dsa/dsa_err.c | |||
| @@ -0,0 +1,99 @@ | |||
| 1 | /* lib/dsa/dsa_err.c */ | ||
| 2 | /* Copyright (C) 1995-1997 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 | #include <stdio.h> | ||
| 59 | #include "err.h" | ||
| 60 | #include "dsa.h" | ||
| 61 | |||
| 62 | /* BEGIN ERROR CODES */ | ||
| 63 | #ifndef NO_ERR | ||
| 64 | static ERR_STRING_DATA DSA_str_functs[]= | ||
| 65 | { | ||
| 66 | {ERR_PACK(0,DSA_F_DSAPARAMS_PRINT,0), "DSAparams_print"}, | ||
| 67 | {ERR_PACK(0,DSA_F_DSAPARAMS_PRINT_FP,0), "DSAparams_print_fp"}, | ||
| 68 | {ERR_PACK(0,DSA_F_DSA_IS_PRIME,0), "DSA_is_prime"}, | ||
| 69 | {ERR_PACK(0,DSA_F_DSA_NEW,0), "DSA_new"}, | ||
| 70 | {ERR_PACK(0,DSA_F_DSA_PRINT,0), "DSA_print"}, | ||
| 71 | {ERR_PACK(0,DSA_F_DSA_PRINT_FP,0), "DSA_print_fp"}, | ||
| 72 | {ERR_PACK(0,DSA_F_DSA_SIGN,0), "DSA_sign"}, | ||
| 73 | {ERR_PACK(0,DSA_F_DSA_SIGN_SETUP,0), "DSA_sign_setup"}, | ||
| 74 | {ERR_PACK(0,DSA_F_DSA_VERIFY,0), "DSA_verify"}, | ||
| 75 | {0,NULL}, | ||
| 76 | }; | ||
| 77 | |||
| 78 | static ERR_STRING_DATA DSA_str_reasons[]= | ||
| 79 | { | ||
| 80 | {DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE ,"data too large for key size"}, | ||
| 81 | {0,NULL}, | ||
| 82 | }; | ||
| 83 | |||
| 84 | #endif | ||
| 85 | |||
| 86 | void ERR_load_DSA_strings() | ||
| 87 | { | ||
| 88 | static int init=1; | ||
| 89 | |||
| 90 | if (init); | ||
| 91 | {; | ||
| 92 | init=0; | ||
| 93 | #ifndef NO_ERR | ||
| 94 | ERR_load_strings(ERR_LIB_DSA,DSA_str_functs); | ||
| 95 | ERR_load_strings(ERR_LIB_DSA,DSA_str_reasons); | ||
| 96 | #endif | ||
| 97 | |||
| 98 | } | ||
| 99 | } | ||
diff --git a/src/lib/libcrypto/dsa/dsa_gen.c b/src/lib/libcrypto/dsa/dsa_gen.c new file mode 100644 index 0000000000..d7d30bf90a --- /dev/null +++ b/src/lib/libcrypto/dsa/dsa_gen.c | |||
| @@ -0,0 +1,328 @@ | |||
| 1 | /* crypto/dsa/dsa_gen.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 | #undef GENUINE_DSA | ||
| 60 | |||
| 61 | #ifdef GENUINE_DSA | ||
| 62 | #define HASH SHA | ||
| 63 | #else | ||
| 64 | #define HASH SHA1 | ||
| 65 | #endif | ||
| 66 | |||
| 67 | #include <stdio.h> | ||
| 68 | #include <time.h> | ||
| 69 | #include "cryptlib.h" | ||
| 70 | #include "sha.h" | ||
| 71 | #include "bn.h" | ||
| 72 | #include "dsa.h" | ||
| 73 | #include "rand.h" | ||
| 74 | |||
| 75 | DSA *DSA_generate_parameters(bits,seed_in,seed_len,counter_ret,h_ret,callback, | ||
| 76 | cb_arg) | ||
| 77 | int bits; | ||
| 78 | unsigned char *seed_in; | ||
| 79 | int seed_len; | ||
| 80 | int *counter_ret; | ||
| 81 | unsigned long *h_ret; | ||
| 82 | void (*callback)(); | ||
| 83 | char *cb_arg; | ||
| 84 | { | ||
| 85 | int ok=0; | ||
| 86 | unsigned char seed[SHA_DIGEST_LENGTH]; | ||
| 87 | unsigned char md[SHA_DIGEST_LENGTH]; | ||
| 88 | unsigned char buf[SHA_DIGEST_LENGTH],buf2[SHA_DIGEST_LENGTH]; | ||
| 89 | BIGNUM *r0,*W,*X,*c,*test; | ||
| 90 | BIGNUM *g=NULL,*q=NULL,*p=NULL; | ||
| 91 | int k,n=0,i,b,m=0; | ||
| 92 | int counter=0; | ||
| 93 | BN_CTX *ctx=NULL,*ctx2=NULL; | ||
| 94 | unsigned int h=2; | ||
| 95 | DSA *ret=NULL; | ||
| 96 | |||
| 97 | if (bits < 512) bits=512; | ||
| 98 | bits=(bits+63)/64*64; | ||
| 99 | |||
| 100 | if ((seed_in != NULL) && (seed_len == 20)) | ||
| 101 | memcpy(seed,seed_in,seed_len); | ||
| 102 | |||
| 103 | ctx=BN_CTX_new(); | ||
| 104 | if (ctx == NULL) goto err; | ||
| 105 | ctx2=BN_CTX_new(); | ||
| 106 | if (ctx2 == NULL) goto err; | ||
| 107 | ret=DSA_new(); | ||
| 108 | if (ret == NULL) goto err; | ||
| 109 | r0=ctx2->bn[0]; | ||
| 110 | g=ctx2->bn[1]; | ||
| 111 | W=ctx2->bn[2]; | ||
| 112 | q=ctx2->bn[3]; | ||
| 113 | X=ctx2->bn[4]; | ||
| 114 | c=ctx2->bn[5]; | ||
| 115 | p=ctx2->bn[6]; | ||
| 116 | test=ctx2->bn[7]; | ||
| 117 | |||
| 118 | BN_lshift(test,BN_value_one(),bits-1); | ||
| 119 | |||
| 120 | for (;;) | ||
| 121 | { | ||
| 122 | for (;;) | ||
| 123 | { | ||
| 124 | /* step 1 */ | ||
| 125 | if (callback != NULL) callback(0,m++,cb_arg); | ||
| 126 | |||
| 127 | if (!seed_len) | ||
| 128 | RAND_bytes(seed,SHA_DIGEST_LENGTH); | ||
| 129 | else | ||
| 130 | seed_len=0; | ||
| 131 | |||
| 132 | memcpy(buf,seed,SHA_DIGEST_LENGTH); | ||
| 133 | memcpy(buf2,seed,SHA_DIGEST_LENGTH); | ||
| 134 | for (i=SHA_DIGEST_LENGTH-1; i >= 0; i--) | ||
| 135 | { | ||
| 136 | buf[i]++; | ||
| 137 | if (buf[i] != 0) break; | ||
| 138 | } | ||
| 139 | |||
| 140 | /* step 2 */ | ||
| 141 | HASH(seed,SHA_DIGEST_LENGTH,md); | ||
| 142 | HASH(buf,SHA_DIGEST_LENGTH,buf2); | ||
| 143 | for (i=0; i<SHA_DIGEST_LENGTH; i++) | ||
| 144 | md[i]^=buf2[i]; | ||
| 145 | |||
| 146 | /* step 3 */ | ||
| 147 | md[0]|=0x80; | ||
| 148 | md[SHA_DIGEST_LENGTH-1]|=0x01; | ||
| 149 | if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,q)) abort(); | ||
| 150 | |||
| 151 | /* step 4 */ | ||
| 152 | if (DSA_is_prime(q,callback,cb_arg) > 0) break; | ||
| 153 | /* do a callback call */ | ||
| 154 | /* step 5 */ | ||
| 155 | } | ||
| 156 | |||
| 157 | if (callback != NULL) callback(2,0,cb_arg); | ||
| 158 | if (callback != NULL) callback(3,0,cb_arg); | ||
| 159 | |||
| 160 | /* step 6 */ | ||
| 161 | counter=0; | ||
| 162 | |||
| 163 | n=(bits-1)/160; | ||
| 164 | b=(bits-1)-n*160; | ||
| 165 | |||
| 166 | for (;;) | ||
| 167 | { | ||
| 168 | /* step 7 */ | ||
| 169 | BN_zero(W); | ||
| 170 | for (k=0; k<=n; k++) | ||
| 171 | { | ||
| 172 | for (i=SHA_DIGEST_LENGTH-1; i >= 0; i--) | ||
| 173 | { | ||
| 174 | buf[i]++; | ||
| 175 | if (buf[i] != 0) break; | ||
| 176 | } | ||
| 177 | |||
| 178 | HASH(buf,SHA_DIGEST_LENGTH,md); | ||
| 179 | |||
| 180 | /* step 8 */ | ||
| 181 | if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,r0)) abort(); | ||
| 182 | BN_lshift(r0,r0,160*k); | ||
| 183 | BN_add(W,W,r0); | ||
| 184 | } | ||
| 185 | |||
| 186 | /* more of step 8 */ | ||
| 187 | BN_mask_bits(W,bits-1); | ||
| 188 | BN_copy(X,W); /* this should be ok */ | ||
| 189 | BN_add(X,X,test); /* this should be ok */ | ||
| 190 | |||
| 191 | /* step 9 */ | ||
| 192 | BN_lshift1(r0,q); | ||
| 193 | BN_mod(c,X,r0,ctx); | ||
| 194 | BN_sub(r0,c,BN_value_one()); | ||
| 195 | BN_sub(p,X,r0); | ||
| 196 | |||
| 197 | /* step 10 */ | ||
| 198 | if (BN_cmp(p,test) >= 0) | ||
| 199 | { | ||
| 200 | /* step 11 */ | ||
| 201 | if (DSA_is_prime(p,callback,cb_arg) > 0) | ||
| 202 | goto end; | ||
| 203 | } | ||
| 204 | |||
| 205 | /* step 13 */ | ||
| 206 | counter++; | ||
| 207 | |||
| 208 | /* step 14 */ | ||
| 209 | if (counter >= 4096) break; | ||
| 210 | |||
| 211 | if (callback != NULL) callback(0,counter,cb_arg); | ||
| 212 | } | ||
| 213 | } | ||
| 214 | end: | ||
| 215 | if (callback != NULL) callback(2,1,cb_arg); | ||
| 216 | |||
| 217 | /* We now need to gernerate g */ | ||
| 218 | /* Set r0=(p-1)/q */ | ||
| 219 | BN_sub(test,p,BN_value_one()); | ||
| 220 | BN_div(r0,NULL,test,q,ctx); | ||
| 221 | |||
| 222 | BN_set_word(test,h); | ||
| 223 | for (;;) | ||
| 224 | { | ||
| 225 | /* g=test^r0%p */ | ||
| 226 | BN_mod_exp(g,test,r0,p,ctx); | ||
| 227 | if (!BN_is_one(g)) break; | ||
| 228 | BN_add(test,test,BN_value_one()); | ||
| 229 | h++; | ||
| 230 | } | ||
| 231 | |||
| 232 | if (callback != NULL) callback(3,1,cb_arg); | ||
| 233 | |||
| 234 | ok=1; | ||
| 235 | err: | ||
| 236 | if (!ok) | ||
| 237 | { | ||
| 238 | if (ret != NULL) DSA_free(ret); | ||
| 239 | } | ||
| 240 | else | ||
| 241 | { | ||
| 242 | ret->p=BN_dup(p); | ||
| 243 | ret->q=BN_dup(q); | ||
| 244 | ret->g=BN_dup(g); | ||
| 245 | if ((m > 1) && (seed_in != NULL)) memcpy(seed_in,seed,20); | ||
| 246 | if (counter_ret != NULL) *counter_ret=counter; | ||
| 247 | if (h_ret != NULL) *h_ret=h; | ||
| 248 | } | ||
| 249 | BN_CTX_free(ctx); | ||
| 250 | BN_CTX_free(ctx2); | ||
| 251 | return(ok?ret:NULL); | ||
| 252 | } | ||
| 253 | |||
| 254 | int DSA_is_prime(w, callback,cb_arg) | ||
| 255 | BIGNUM *w; | ||
| 256 | void (*callback)(); | ||
| 257 | char *cb_arg; | ||
| 258 | { | ||
| 259 | int ok= -1,j,i,n; | ||
| 260 | BN_CTX *ctx=NULL,*ctx2=NULL; | ||
| 261 | BIGNUM *w_1,*b,*m,*z; | ||
| 262 | int a; | ||
| 263 | |||
| 264 | if (!BN_is_bit_set(w,0)) return(0); | ||
| 265 | |||
| 266 | ctx=BN_CTX_new(); | ||
| 267 | if (ctx == NULL) goto err; | ||
| 268 | ctx2=BN_CTX_new(); | ||
| 269 | if (ctx2 == NULL) goto err; | ||
| 270 | |||
| 271 | m= ctx2->bn[2]; | ||
| 272 | b= ctx2->bn[3]; | ||
| 273 | z= ctx2->bn[4]; | ||
| 274 | w_1=ctx2->bn[5]; | ||
| 275 | |||
| 276 | /* step 1 */ | ||
| 277 | n=50; | ||
| 278 | |||
| 279 | /* step 2 */ | ||
| 280 | if (!BN_sub(w_1,w,BN_value_one())) goto err; | ||
| 281 | for (a=1; !BN_is_bit_set(w_1,a); a++) | ||
| 282 | ; | ||
| 283 | if (!BN_rshift(m,w_1,a)) goto err; | ||
| 284 | |||
| 285 | for (i=1; i < n; i++) | ||
| 286 | { | ||
| 287 | /* step 3 */ | ||
| 288 | BN_rand(b,BN_num_bits(w)-2/*-1*/,0,0); | ||
| 289 | BN_set_word(b,0x10001L); | ||
| 290 | |||
| 291 | /* step 4 */ | ||
| 292 | j=0; | ||
| 293 | if (!BN_mod_exp(z,b,m,w,ctx)) goto err; | ||
| 294 | |||
| 295 | /* step 5 */ | ||
| 296 | for (;;) | ||
| 297 | { | ||
| 298 | if (((j == 0) && BN_is_one(z)) || (BN_cmp(z,w_1) == 0)) | ||
| 299 | break; | ||
| 300 | |||
| 301 | /* step 6 */ | ||
| 302 | if ((j > 0) && BN_is_one(z)) | ||
| 303 | { | ||
| 304 | ok=0; | ||
| 305 | goto err; | ||
| 306 | } | ||
| 307 | |||
| 308 | j++; | ||
| 309 | if (j >= a) | ||
| 310 | { | ||
| 311 | ok=0; | ||
| 312 | goto err; | ||
| 313 | } | ||
| 314 | |||
| 315 | if (!BN_mod_mul(z,z,z,w,ctx)) goto err; | ||
| 316 | if (callback != NULL) callback(1,j,cb_arg); | ||
| 317 | } | ||
| 318 | } | ||
| 319 | |||
| 320 | ok=1; | ||
| 321 | err: | ||
| 322 | if (ok == -1) DSAerr(DSA_F_DSA_IS_PRIME,ERR_R_BN_LIB); | ||
| 323 | BN_CTX_free(ctx); | ||
| 324 | BN_CTX_free(ctx2); | ||
| 325 | |||
| 326 | return(ok); | ||
| 327 | } | ||
| 328 | |||
diff --git a/src/lib/libcrypto/dsa/dsa_key.c b/src/lib/libcrypto/dsa/dsa_key.c new file mode 100644 index 0000000000..d51ed9395f --- /dev/null +++ b/src/lib/libcrypto/dsa/dsa_key.c | |||
| @@ -0,0 +1,112 @@ | |||
| 1 | /* crypto/dsa/dsa_key.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 <time.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "sha.h" | ||
| 63 | #include "bn.h" | ||
| 64 | #include "dsa.h" | ||
| 65 | #include "rand.h" | ||
| 66 | |||
| 67 | int DSA_generate_key(dsa) | ||
| 68 | DSA *dsa; | ||
| 69 | { | ||
| 70 | int ok=0; | ||
| 71 | unsigned int i; | ||
| 72 | BN_CTX *ctx=NULL; | ||
| 73 | BIGNUM *pub_key=NULL,*priv_key=NULL; | ||
| 74 | |||
| 75 | if ((ctx=BN_CTX_new()) == NULL) goto err; | ||
| 76 | |||
| 77 | if (dsa->priv_key == NULL) | ||
| 78 | { | ||
| 79 | if ((priv_key=BN_new()) == NULL) goto err; | ||
| 80 | } | ||
| 81 | else | ||
| 82 | priv_key=dsa->priv_key; | ||
| 83 | |||
| 84 | i=BN_num_bits(dsa->q); | ||
| 85 | for (;;) | ||
| 86 | { | ||
| 87 | BN_rand(priv_key,i,1,0); | ||
| 88 | if (BN_cmp(priv_key,dsa->q) >= 0) | ||
| 89 | BN_sub(priv_key,priv_key,dsa->q); | ||
| 90 | if (!BN_is_zero(priv_key)) break; | ||
| 91 | } | ||
| 92 | |||
| 93 | if (dsa->pub_key == NULL) | ||
| 94 | { | ||
| 95 | if ((pub_key=BN_new()) == NULL) goto err; | ||
| 96 | } | ||
| 97 | else | ||
| 98 | pub_key=dsa->pub_key; | ||
| 99 | |||
| 100 | if (!BN_mod_exp(pub_key,dsa->g,priv_key,dsa->p,ctx)) goto err; | ||
| 101 | |||
| 102 | dsa->priv_key=priv_key; | ||
| 103 | dsa->pub_key=pub_key; | ||
| 104 | ok=1; | ||
| 105 | |||
| 106 | err: | ||
| 107 | if ((pub_key != NULL) && (dsa->pub_key == NULL)) BN_free(pub_key); | ||
| 108 | if ((priv_key != NULL) && (dsa->priv_key == NULL)) BN_free(priv_key); | ||
| 109 | if (ctx != NULL) BN_CTX_free(ctx); | ||
| 110 | return(ok); | ||
| 111 | } | ||
| 112 | |||
diff --git a/src/lib/libcrypto/dsa/dsa_lib.c b/src/lib/libcrypto/dsa/dsa_lib.c new file mode 100644 index 0000000000..b647257f9f --- /dev/null +++ b/src/lib/libcrypto/dsa/dsa_lib.c | |||
| @@ -0,0 +1,145 @@ | |||
| 1 | /* crypto/dsa/dsa_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 | /* 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 "asn1.h" | ||
| 66 | |||
| 67 | char *DSA_version="\0DSA part of SSLeay 0.9.0b 29-Jun-1998"; | ||
| 68 | |||
| 69 | DSA *DSA_new() | ||
| 70 | { | ||
| 71 | DSA *ret; | ||
| 72 | |||
| 73 | ret=(DSA *)Malloc(sizeof(DSA)); | ||
| 74 | if (ret == NULL) | ||
| 75 | { | ||
| 76 | DSAerr(DSA_F_DSA_NEW,ERR_R_MALLOC_FAILURE); | ||
| 77 | return(NULL); | ||
| 78 | } | ||
| 79 | ret->pad=0; | ||
| 80 | ret->version=0; | ||
| 81 | ret->write_params=1; | ||
| 82 | ret->p=NULL; | ||
| 83 | ret->q=NULL; | ||
| 84 | ret->g=NULL; | ||
| 85 | |||
| 86 | ret->pub_key=NULL; | ||
| 87 | ret->priv_key=NULL; | ||
| 88 | |||
| 89 | ret->kinv=NULL; | ||
| 90 | ret->r=NULL; | ||
| 91 | |||
| 92 | ret->references=1; | ||
| 93 | return(ret); | ||
| 94 | } | ||
| 95 | |||
| 96 | void DSA_free(r) | ||
| 97 | DSA *r; | ||
| 98 | { | ||
| 99 | int i; | ||
| 100 | |||
| 101 | if (r == NULL) return; | ||
| 102 | |||
| 103 | i=CRYPTO_add(&r->references,-1,CRYPTO_LOCK_DSA); | ||
| 104 | #ifdef REF_PRINT | ||
| 105 | REF_PRINT("DSA",r); | ||
| 106 | #endif | ||
| 107 | if (i > 0) return; | ||
| 108 | #ifdef REF_CHECK | ||
| 109 | if (i < 0) | ||
| 110 | { | ||
| 111 | fprintf(stderr,"DSA_free, bad reference count\n"); | ||
| 112 | abort(); | ||
| 113 | } | ||
| 114 | #endif | ||
| 115 | |||
| 116 | if (r->p != NULL) BN_clear_free(r->p); | ||
| 117 | if (r->q != NULL) BN_clear_free(r->q); | ||
| 118 | if (r->g != NULL) BN_clear_free(r->g); | ||
| 119 | if (r->pub_key != NULL) BN_clear_free(r->pub_key); | ||
| 120 | if (r->priv_key != NULL) BN_clear_free(r->priv_key); | ||
| 121 | if (r->kinv != NULL) BN_clear_free(r->kinv); | ||
| 122 | if (r->r != NULL) BN_clear_free(r->r); | ||
| 123 | Free(r); | ||
| 124 | } | ||
| 125 | |||
| 126 | int DSA_size(r) | ||
| 127 | DSA *r; | ||
| 128 | { | ||
| 129 | int ret,i; | ||
| 130 | ASN1_INTEGER bs; | ||
| 131 | unsigned char buf[4]; | ||
| 132 | |||
| 133 | i=BN_num_bits(r->q); | ||
| 134 | bs.length=(i+7)/8; | ||
| 135 | bs.data=buf; | ||
| 136 | bs.type=V_ASN1_INTEGER; | ||
| 137 | /* If the top bit is set the asn1 encoding is 1 larger. */ | ||
| 138 | buf[0]=0xff; | ||
| 139 | |||
| 140 | i=i2d_ASN1_INTEGER(&bs,NULL); | ||
| 141 | i+=i; /* r and s */ | ||
| 142 | ret=ASN1_object_size(1,i,V_ASN1_SEQUENCE); | ||
| 143 | return(ret); | ||
| 144 | } | ||
| 145 | |||
diff --git a/src/lib/libcrypto/dsa/dsa_sign.c b/src/lib/libcrypto/dsa/dsa_sign.c new file mode 100644 index 0000000000..6ca1c318f2 --- /dev/null +++ b/src/lib/libcrypto/dsa/dsa_sign.c | |||
| @@ -0,0 +1,215 @@ | |||
| 1 | /* crypto/dsa/dsa_sign.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 "rand.h" | ||
| 66 | #include "asn1.h" | ||
| 67 | |||
| 68 | /* data has already been hashed (probably with SHA or SHA-1). */ | ||
| 69 | /* DSAerr(DSA_F_DSA_SIGN,DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); */ | ||
| 70 | |||
| 71 | int DSA_sign(type,dgst,dlen,sig,siglen,dsa) | ||
| 72 | int type; | ||
| 73 | unsigned char *dgst; | ||
| 74 | int dlen; | ||
| 75 | unsigned char *sig; /* out */ | ||
| 76 | unsigned int *siglen; /* out */ | ||
| 77 | DSA *dsa; | ||
| 78 | { | ||
| 79 | BIGNUM *kinv=NULL,*r=NULL; | ||
| 80 | BIGNUM *m=NULL; | ||
| 81 | BIGNUM *xr=NULL,*s=NULL; | ||
| 82 | BN_CTX *ctx=NULL; | ||
| 83 | unsigned char *p; | ||
| 84 | int i,len=0,ret=0,reason=ERR_R_BN_LIB; | ||
| 85 | ASN1_INTEGER rbs,sbs; | ||
| 86 | MS_STATIC unsigned char rbuf[50]; /* assuming r is 20 bytes +extra */ | ||
| 87 | MS_STATIC unsigned char sbuf[50]; /* assuming s is 20 bytes +extra */ | ||
| 88 | |||
| 89 | i=BN_num_bytes(dsa->q); /* should be 20 */ | ||
| 90 | if ((dlen > i) || (dlen > 50)) | ||
| 91 | { | ||
| 92 | reason=DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE; | ||
| 93 | goto err; | ||
| 94 | } | ||
| 95 | |||
| 96 | ctx=BN_CTX_new(); | ||
| 97 | if (ctx == NULL) goto err; | ||
| 98 | |||
| 99 | if ((dsa->kinv == NULL) || (dsa->r == NULL)) | ||
| 100 | { | ||
| 101 | if (!DSA_sign_setup(dsa,ctx,&kinv,&r)) goto err; | ||
| 102 | } | ||
| 103 | else | ||
| 104 | { | ||
| 105 | kinv=dsa->kinv; | ||
| 106 | dsa->kinv=NULL; | ||
| 107 | r=dsa->r; | ||
| 108 | dsa->r=NULL; | ||
| 109 | } | ||
| 110 | |||
| 111 | m=BN_new(); | ||
| 112 | xr=BN_new(); | ||
| 113 | s=BN_new(); | ||
| 114 | if (m == NULL || xr == NULL || s == NULL) goto err; | ||
| 115 | |||
| 116 | if (BN_bin2bn(dgst,dlen,m) == NULL) goto err; | ||
| 117 | |||
| 118 | /* Compute s = inv(k) (m + xr) mod q */ | ||
| 119 | if (!BN_mul(xr, dsa->priv_key, r)) goto err; /* s = xr */ | ||
| 120 | if (!BN_add(s, xr, m)) goto err; /* s = m + xr */ | ||
| 121 | if (!BN_mod_mul(s,s,kinv,dsa->q,ctx)) goto err; | ||
| 122 | |||
| 123 | /* | ||
| 124 | * Now create a ASN.1 sequence of the integers R and S. | ||
| 125 | */ | ||
| 126 | rbs.data=rbuf; | ||
| 127 | sbs.data=sbuf; | ||
| 128 | rbs.type = V_ASN1_INTEGER; | ||
| 129 | sbs.type = V_ASN1_INTEGER; | ||
| 130 | rbs.length=BN_bn2bin(r,rbs.data); | ||
| 131 | sbs.length=BN_bn2bin(s,sbs.data); | ||
| 132 | |||
| 133 | len =i2d_ASN1_INTEGER(&rbs,NULL); | ||
| 134 | len+=i2d_ASN1_INTEGER(&sbs,NULL); | ||
| 135 | |||
| 136 | p=sig; | ||
| 137 | ASN1_put_object(&p,1,len,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); | ||
| 138 | i2d_ASN1_INTEGER(&rbs,&p); | ||
| 139 | i2d_ASN1_INTEGER(&sbs,&p); | ||
| 140 | *siglen=(p-sig); | ||
| 141 | ret=1; | ||
| 142 | err: | ||
| 143 | if (!ret) DSAerr(DSA_F_DSA_SIGN,reason); | ||
| 144 | |||
| 145 | #if 1 /* do the right thing :-) */ | ||
| 146 | if (kinv != NULL) BN_clear_free(kinv); | ||
| 147 | if (r != NULL) BN_clear_free(r); | ||
| 148 | #endif | ||
| 149 | if (ctx != NULL) BN_CTX_free(ctx); | ||
| 150 | if (m != NULL) BN_clear_free(m); | ||
| 151 | if (xr != NULL) BN_clear_free(xr); | ||
| 152 | if (s != NULL) BN_clear_free(s); | ||
| 153 | return(ret); | ||
| 154 | } | ||
| 155 | |||
| 156 | int DSA_sign_setup(dsa,ctx_in,kinvp,rp) | ||
| 157 | DSA *dsa; | ||
| 158 | BN_CTX *ctx_in; | ||
| 159 | BIGNUM **kinvp; | ||
| 160 | BIGNUM **rp; | ||
| 161 | { | ||
| 162 | BN_CTX *ctx; | ||
| 163 | BIGNUM *k=NULL,*kinv=NULL,*r=NULL; | ||
| 164 | int ret=0; | ||
| 165 | |||
| 166 | if (ctx_in == NULL) | ||
| 167 | { | ||
| 168 | if ((ctx=BN_CTX_new()) == NULL) goto err; | ||
| 169 | } | ||
| 170 | else | ||
| 171 | ctx=ctx_in; | ||
| 172 | |||
| 173 | r=BN_new(); | ||
| 174 | k=BN_new(); | ||
| 175 | if ((r == NULL) || (k == NULL)) | ||
| 176 | goto err; | ||
| 177 | kinv=NULL; | ||
| 178 | |||
| 179 | if (r == NULL) goto err; | ||
| 180 | |||
| 181 | /* Get random k */ | ||
| 182 | for (;;) | ||
| 183 | { | ||
| 184 | if (!BN_rand(k, BN_num_bits(dsa->q), 1, 0)) goto err; | ||
| 185 | if (BN_cmp(k,dsa->q) >= 0) | ||
| 186 | BN_sub(k,k,dsa->q); | ||
| 187 | if (!BN_is_zero(k)) break; | ||
| 188 | } | ||
| 189 | |||
| 190 | /* Compute r = (g^k mod p) mod q */ | ||
| 191 | if (!BN_mod_exp(r,dsa->g,k,dsa->p,ctx)) goto err; | ||
| 192 | if (!BN_mod(r,r,dsa->q,ctx)) goto err; | ||
| 193 | |||
| 194 | /* Compute part of 's = inv(k) (m + xr) mod q' */ | ||
| 195 | if ((kinv=BN_mod_inverse(k,dsa->q,ctx)) == NULL) goto err; | ||
| 196 | |||
| 197 | if (*kinvp != NULL) BN_clear_free(*kinvp); | ||
| 198 | *kinvp=kinv; | ||
| 199 | kinv=NULL; | ||
| 200 | if (*rp != NULL) BN_clear_free(*rp); | ||
| 201 | *rp=r; | ||
| 202 | ret=1; | ||
| 203 | err: | ||
| 204 | if (!ret) | ||
| 205 | { | ||
| 206 | DSAerr(DSA_F_DSA_SIGN_SETUP,ERR_R_BN_LIB); | ||
| 207 | if (kinv != NULL) BN_clear_free(kinv); | ||
| 208 | if (r != NULL) BN_clear_free(r); | ||
| 209 | } | ||
| 210 | if (ctx_in == NULL) BN_CTX_free(ctx); | ||
| 211 | if (k != NULL) BN_clear_free(k); | ||
| 212 | if (kinv != NULL) BN_clear_free(kinv); | ||
| 213 | return(ret); | ||
| 214 | } | ||
| 215 | |||
diff --git a/src/lib/libcrypto/dsa/dsa_vrf.c b/src/lib/libcrypto/dsa/dsa_vrf.c new file mode 100644 index 0000000000..0f860984ed --- /dev/null +++ b/src/lib/libcrypto/dsa/dsa_vrf.c | |||
| @@ -0,0 +1,152 @@ | |||
| 1 | /* crypto/dsa/dsa_vrf.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 "rand.h" | ||
| 66 | #include "asn1.h" | ||
| 67 | #include "asn1_mac.h" | ||
| 68 | |||
| 69 | /* data has already been hashed (probably with SHA or SHA-1). */ | ||
| 70 | /* returns | ||
| 71 | * 1: correct signature | ||
| 72 | * 0: incorrect signature | ||
| 73 | * -1: error | ||
| 74 | */ | ||
| 75 | int DSA_verify(type,dgst,dgst_len,sigbuf,siglen, dsa) | ||
| 76 | int type; | ||
| 77 | unsigned char *dgst; | ||
| 78 | int dgst_len; | ||
| 79 | unsigned char *sigbuf; | ||
| 80 | int siglen; | ||
| 81 | DSA *dsa; | ||
| 82 | { | ||
| 83 | /* The next 3 are used by the M_ASN1 macros */ | ||
| 84 | long length=siglen; | ||
| 85 | ASN1_CTX c; | ||
| 86 | unsigned char **pp= &sigbuf; | ||
| 87 | BN_CTX *ctx; | ||
| 88 | BIGNUM *r=NULL; | ||
| 89 | BIGNUM *t1=NULL,*t2=NULL; | ||
| 90 | BIGNUM *u1=NULL,*u2=NULL; | ||
| 91 | ASN1_INTEGER *bs=NULL; | ||
| 92 | int ret = -1; | ||
| 93 | |||
| 94 | ctx=BN_CTX_new(); | ||
| 95 | if (ctx == NULL) goto err; | ||
| 96 | |||
| 97 | t1=BN_new(); | ||
| 98 | t2=BN_new(); | ||
| 99 | if (t1 == NULL || t2 == NULL) goto err; | ||
| 100 | |||
| 101 | M_ASN1_D2I_Init(); | ||
| 102 | M_ASN1_D2I_start_sequence(); | ||
| 103 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
| 104 | if ((r=BN_bin2bn(bs->data,bs->length,NULL)) == NULL) goto err_bn; | ||
| 105 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
| 106 | if ((u1=BN_bin2bn(bs->data,bs->length,NULL)) == NULL) goto err_bn; | ||
| 107 | if (!asn1_Finish(&c)) goto err; | ||
| 108 | |||
| 109 | /* Calculate W = inv(S) mod Q | ||
| 110 | * save W in u2 */ | ||
| 111 | if ((u2=BN_mod_inverse(u1,dsa->q,ctx)) == NULL) goto err_bn; | ||
| 112 | |||
| 113 | /* save M in u1 */ | ||
| 114 | if (BN_bin2bn(dgst,dgst_len,u1) == NULL) goto err_bn; | ||
| 115 | |||
| 116 | /* u1 = M * w mod q */ | ||
| 117 | if (!BN_mod_mul(u1,u1,u2,dsa->q,ctx)) goto err_bn; | ||
| 118 | |||
| 119 | /* u2 = r * w mod q */ | ||
| 120 | if (!BN_mod_mul(u2,r,u2,dsa->q,ctx)) goto err_bn; | ||
| 121 | |||
| 122 | /* v = ( g^u1 * y^u2 mod p ) mod q */ | ||
| 123 | /* let t1 = g ^ u1 mod p */ | ||
| 124 | if (!BN_mod_exp(t1,dsa->g,u1,dsa->p,ctx)) goto err_bn; | ||
| 125 | /* let t2 = y ^ u2 mod p */ | ||
| 126 | if (!BN_mod_exp(t2,dsa->pub_key,u2,dsa->p,ctx)) goto err_bn; | ||
| 127 | /* let u1 = t1 * t2 mod p */ | ||
| 128 | if (!BN_mod_mul(u1,t1,t2,dsa->p,ctx)) goto err_bn; | ||
| 129 | /* let u1 = u1 mod q */ | ||
| 130 | if (!BN_mod(u1,u1,dsa->q,ctx)) goto err_bn; | ||
| 131 | /* V is now in u1. If the signature is correct, it will be | ||
| 132 | * equal to R. */ | ||
| 133 | ret=(BN_ucmp(u1, r) == 0); | ||
| 134 | if (0) | ||
| 135 | { | ||
| 136 | err: /* ASN1 error */ | ||
| 137 | DSAerr(DSA_F_DSA_VERIFY,c.error); | ||
| 138 | } | ||
| 139 | if (0) | ||
| 140 | { | ||
| 141 | err_bn: /* BN error */ | ||
| 142 | DSAerr(DSA_F_DSA_VERIFY,ERR_R_BN_LIB); | ||
| 143 | } | ||
| 144 | if (ctx != NULL) BN_CTX_free(ctx); | ||
| 145 | if (r != NULL) BN_free(r); | ||
| 146 | if (t1 != NULL) BN_free(t1); | ||
| 147 | if (t2 != NULL) BN_free(t2); | ||
| 148 | if (u1 != NULL) BN_free(u1); | ||
| 149 | if (u2 != NULL) BN_free(u2); | ||
| 150 | if (bs != NULL) ASN1_BIT_STRING_free(bs); | ||
| 151 | return(ret); | ||
| 152 | } | ||
diff --git a/src/lib/libcrypto/err/err.c b/src/lib/libcrypto/err/err.c new file mode 100644 index 0000000000..5aef6a1259 --- /dev/null +++ b/src/lib/libcrypto/err/err.c | |||
| @@ -0,0 +1,642 @@ | |||
| 1 | /* crypto/err/err.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 "lhash.h" | ||
| 61 | #include "crypto.h" | ||
| 62 | #include "cryptlib.h" | ||
| 63 | #include "buffer.h" | ||
| 64 | #include "err.h" | ||
| 65 | #include "crypto.h" | ||
| 66 | |||
| 67 | |||
| 68 | static LHASH *error_hash=NULL; | ||
| 69 | static LHASH *thread_hash=NULL; | ||
| 70 | |||
| 71 | #ifndef NOPROTO | ||
| 72 | static unsigned long err_hash(ERR_STRING_DATA *a); | ||
| 73 | static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b); | ||
| 74 | static unsigned long pid_hash(ERR_STATE *pid); | ||
| 75 | static int pid_cmp(ERR_STATE *a,ERR_STATE *pid); | ||
| 76 | static unsigned long get_error_values(int inc,char **file,int *line, | ||
| 77 | char **data,int *flags); | ||
| 78 | static void ERR_STATE_free(ERR_STATE *s); | ||
| 79 | #else | ||
| 80 | static unsigned long err_hash(); | ||
| 81 | static int err_cmp(); | ||
| 82 | static unsigned long pid_hash(); | ||
| 83 | static int pid_cmp(); | ||
| 84 | static void ERR_STATE_free(); | ||
| 85 | ERR_STATE *s; | ||
| 86 | #endif | ||
| 87 | |||
| 88 | #ifndef NO_ERR | ||
| 89 | static ERR_STRING_DATA ERR_str_libraries[]= | ||
| 90 | { | ||
| 91 | {ERR_PACK(ERR_LIB_NONE,0,0) ,"unknown library"}, | ||
| 92 | {ERR_PACK(ERR_LIB_SYS,0,0) ,"system library"}, | ||
| 93 | {ERR_PACK(ERR_LIB_BN,0,0) ,"bignum routines"}, | ||
| 94 | {ERR_PACK(ERR_LIB_RSA,0,0) ,"rsa routines"}, | ||
| 95 | {ERR_PACK(ERR_LIB_DH,0,0) ,"Diffie-Hellman routines"}, | ||
| 96 | {ERR_PACK(ERR_LIB_EVP,0,0) ,"digital envelope routines"}, | ||
| 97 | {ERR_PACK(ERR_LIB_BUF,0,0) ,"memory buffer routines"}, | ||
| 98 | {ERR_PACK(ERR_LIB_BIO,0,0) ,"BIO routines"}, | ||
| 99 | {ERR_PACK(ERR_LIB_OBJ,0,0) ,"object identifier routines"}, | ||
| 100 | {ERR_PACK(ERR_LIB_PEM,0,0) ,"PEM routines"}, | ||
| 101 | {ERR_PACK(ERR_LIB_ASN1,0,0) ,"asn1 encoding routines"}, | ||
| 102 | {ERR_PACK(ERR_LIB_X509,0,0) ,"x509 certificate routines"}, | ||
| 103 | {ERR_PACK(ERR_LIB_CONF,0,0) ,"configuation file routines"}, | ||
| 104 | {ERR_PACK(ERR_LIB_METH,0,0) ,"X509 lookup 'method' routines"}, | ||
| 105 | {ERR_PACK(ERR_LIB_SSL,0,0) ,"SSL routines"}, | ||
| 106 | {ERR_PACK(ERR_LIB_RSAREF,0,0) ,"RSAref routines"}, | ||
| 107 | {ERR_PACK(ERR_LIB_PROXY,0,0) ,"Proxy routines"}, | ||
| 108 | {ERR_PACK(ERR_LIB_BIO,0,0) ,"BIO routines"}, | ||
| 109 | {ERR_PACK(ERR_LIB_PKCS7,0,0) ,"PKCS7 routines"}, | ||
| 110 | {0,NULL}, | ||
| 111 | }; | ||
| 112 | |||
| 113 | static ERR_STRING_DATA ERR_str_functs[]= | ||
| 114 | { | ||
| 115 | {ERR_PACK(0,SYS_F_FOPEN,0), "fopen"}, | ||
| 116 | {ERR_PACK(0,SYS_F_CONNECT,0), "connect"}, | ||
| 117 | {ERR_PACK(0,SYS_F_GETSERVBYNAME,0), "getservbyname"}, | ||
| 118 | {ERR_PACK(0,SYS_F_SOCKET,0), "socket"}, | ||
| 119 | {ERR_PACK(0,SYS_F_IOCTLSOCKET,0), "ioctlsocket"}, | ||
| 120 | {ERR_PACK(0,SYS_F_BIND,0), "bind"}, | ||
| 121 | {ERR_PACK(0,SYS_F_LISTEN,0), "listen"}, | ||
| 122 | {ERR_PACK(0,SYS_F_ACCEPT,0), "accept"}, | ||
| 123 | #ifdef WINDOWS | ||
| 124 | {ERR_PACK(0,SYS_F_WSASTARTUP,0), "WSAstartup"}, | ||
| 125 | #endif | ||
| 126 | {0,NULL}, | ||
| 127 | }; | ||
| 128 | |||
| 129 | static ERR_STRING_DATA ERR_str_reasons[]= | ||
| 130 | { | ||
| 131 | {ERR_R_FATAL ,"fatal"}, | ||
| 132 | {ERR_R_SYS_LIB ,"system lib"}, | ||
| 133 | {ERR_R_BN_LIB ,"BN lib"}, | ||
| 134 | {ERR_R_RSA_LIB ,"RSA lib"}, | ||
| 135 | {ERR_R_DH_LIB ,"DH lib"}, | ||
| 136 | {ERR_R_EVP_LIB ,"EVP lib"}, | ||
| 137 | {ERR_R_BUF_LIB ,"BUF lib"}, | ||
| 138 | {ERR_R_BIO_LIB ,"BIO lib"}, | ||
| 139 | {ERR_R_OBJ_LIB ,"OBJ lib"}, | ||
| 140 | {ERR_R_PEM_LIB ,"PEM lib"}, | ||
| 141 | {ERR_R_X509_LIB ,"X509 lib"}, | ||
| 142 | {ERR_R_METH_LIB ,"METH lib"}, | ||
| 143 | {ERR_R_ASN1_LIB ,"ASN1 lib"}, | ||
| 144 | {ERR_R_CONF_LIB ,"CONF lib"}, | ||
| 145 | {ERR_R_SSL_LIB ,"SSL lib"}, | ||
| 146 | {ERR_R_PROXY_LIB ,"PROXY lib"}, | ||
| 147 | {ERR_R_BIO_LIB ,"BIO lib"}, | ||
| 148 | {ERR_R_PKCS7_LIB ,"PKCS7 lib"}, | ||
| 149 | {ERR_R_MALLOC_FAILURE ,"Malloc failure"}, | ||
| 150 | {ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED ,"called a fuction you should not call"}, | ||
| 151 | {0,NULL}, | ||
| 152 | }; | ||
| 153 | #endif | ||
| 154 | |||
| 155 | #define err_clear_data(p,i) \ | ||
| 156 | if (((p)->err_data[i] != NULL) && \ | ||
| 157 | (p)->err_data_flags[i] & ERR_TXT_MALLOCED) \ | ||
| 158 | { \ | ||
| 159 | Free((p)->err_data[i]); \ | ||
| 160 | (p)->err_data[i]=NULL; \ | ||
| 161 | } \ | ||
| 162 | (p)->err_data_flags[i]=0; | ||
| 163 | |||
| 164 | static void ERR_STATE_free(s) | ||
| 165 | ERR_STATE *s; | ||
| 166 | { | ||
| 167 | int i; | ||
| 168 | |||
| 169 | for (i=0; i<ERR_NUM_ERRORS; i++) | ||
| 170 | { | ||
| 171 | err_clear_data(s,i); | ||
| 172 | } | ||
| 173 | Free(s); | ||
| 174 | } | ||
| 175 | |||
| 176 | void ERR_load_ERR_strings() | ||
| 177 | { | ||
| 178 | static int init=1; | ||
| 179 | |||
| 180 | if (init) | ||
| 181 | { | ||
| 182 | CRYPTO_w_lock(CRYPTO_LOCK_ERR); | ||
| 183 | if (init == 0) | ||
| 184 | { | ||
| 185 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); | ||
| 186 | return; | ||
| 187 | } | ||
| 188 | init=0; | ||
| 189 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); | ||
| 190 | |||
| 191 | #ifndef NO_ERR | ||
| 192 | ERR_load_strings(0,ERR_str_libraries); | ||
| 193 | ERR_load_strings(0,ERR_str_reasons); | ||
| 194 | ERR_load_strings(ERR_LIB_SYS,ERR_str_functs); | ||
| 195 | #endif | ||
| 196 | } | ||
| 197 | } | ||
| 198 | |||
| 199 | void ERR_load_strings(lib,str) | ||
| 200 | int lib; | ||
| 201 | ERR_STRING_DATA *str; | ||
| 202 | { | ||
| 203 | if (error_hash == NULL) | ||
| 204 | { | ||
| 205 | CRYPTO_w_lock(CRYPTO_LOCK_ERR_HASH); | ||
| 206 | error_hash=lh_new(err_hash,err_cmp); | ||
| 207 | if (error_hash == NULL) | ||
| 208 | { | ||
| 209 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH); | ||
| 210 | return; | ||
| 211 | } | ||
| 212 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH); | ||
| 213 | |||
| 214 | ERR_load_ERR_strings(); | ||
| 215 | } | ||
| 216 | |||
| 217 | CRYPTO_w_lock(CRYPTO_LOCK_ERR_HASH); | ||
| 218 | while (str->error) | ||
| 219 | { | ||
| 220 | str->error|=ERR_PACK(lib,0,0); | ||
| 221 | lh_insert(error_hash,(char *)str); | ||
| 222 | str++; | ||
| 223 | } | ||
| 224 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH); | ||
| 225 | } | ||
| 226 | |||
| 227 | void ERR_free_strings() | ||
| 228 | { | ||
| 229 | CRYPTO_w_lock(CRYPTO_LOCK_ERR); | ||
| 230 | |||
| 231 | if (error_hash != NULL) | ||
| 232 | { | ||
| 233 | lh_free(error_hash); | ||
| 234 | error_hash=NULL; | ||
| 235 | } | ||
| 236 | |||
| 237 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); | ||
| 238 | } | ||
| 239 | |||
| 240 | /********************************************************/ | ||
| 241 | |||
| 242 | void ERR_put_error(lib,func,reason,file,line) | ||
| 243 | int lib,func,reason; | ||
| 244 | char *file; | ||
| 245 | int line; | ||
| 246 | { | ||
| 247 | ERR_STATE *es; | ||
| 248 | |||
| 249 | es=ERR_get_state(); | ||
| 250 | |||
| 251 | es->top=(es->top+1)%ERR_NUM_ERRORS; | ||
| 252 | if (es->top == es->bottom) | ||
| 253 | es->bottom=(es->bottom+1)%ERR_NUM_ERRORS; | ||
| 254 | es->err_buffer[es->top]=ERR_PACK(lib,func,reason); | ||
| 255 | es->err_file[es->top]=file; | ||
| 256 | es->err_line[es->top]=line; | ||
| 257 | err_clear_data(es,es->top); | ||
| 258 | } | ||
| 259 | |||
| 260 | void ERR_clear_error() | ||
| 261 | { | ||
| 262 | ERR_STATE *es; | ||
| 263 | |||
| 264 | es=ERR_get_state(); | ||
| 265 | |||
| 266 | #if 0 | ||
| 267 | /* hmm... is this needed */ | ||
| 268 | for (i=0; i<ERR_NUM_ERRORS; i++) | ||
| 269 | { | ||
| 270 | es->err_buffer[i]=0; | ||
| 271 | es->err_file[i]=NULL; | ||
| 272 | es->err_line[i]= -1; | ||
| 273 | err_clear_data(es,i); | ||
| 274 | } | ||
| 275 | #endif | ||
| 276 | es->top=es->bottom=0; | ||
| 277 | } | ||
| 278 | |||
| 279 | |||
| 280 | unsigned long ERR_get_error() | ||
| 281 | { return(get_error_values(1,NULL,NULL,NULL,NULL)); } | ||
| 282 | |||
| 283 | unsigned long ERR_get_error_line(file,line) | ||
| 284 | char **file; | ||
| 285 | int *line; | ||
| 286 | { return(get_error_values(1,file,line,NULL,NULL)); } | ||
| 287 | |||
| 288 | unsigned long ERR_get_error_line_data(file,line,data,flags) | ||
| 289 | char **file; | ||
| 290 | int *line; | ||
| 291 | char **data; | ||
| 292 | int *flags; | ||
| 293 | { return(get_error_values(1,file,line,data,flags)); } | ||
| 294 | |||
| 295 | unsigned long ERR_peek_error() | ||
| 296 | { return(get_error_values(0,NULL,NULL,NULL,NULL)); } | ||
| 297 | |||
| 298 | unsigned long ERR_peek_error_line(file,line) | ||
| 299 | char **file; | ||
| 300 | int *line; | ||
| 301 | { return(get_error_values(0,file,line,NULL,NULL)); } | ||
| 302 | |||
| 303 | unsigned long ERR_peek_error_line_data(file,line,data,flags) | ||
| 304 | char **file; | ||
| 305 | int *line; | ||
| 306 | char **data; | ||
| 307 | int *flags; | ||
| 308 | { return(get_error_values(0,file,line,data,flags)); } | ||
| 309 | |||
| 310 | static unsigned long get_error_values(inc,file,line,data,flags) | ||
| 311 | int inc; | ||
| 312 | char **file; | ||
| 313 | int *line; | ||
| 314 | char **data; | ||
| 315 | int *flags; | ||
| 316 | { | ||
| 317 | int i=0; | ||
| 318 | ERR_STATE *es; | ||
| 319 | unsigned long ret; | ||
| 320 | |||
| 321 | es=ERR_get_state(); | ||
| 322 | |||
| 323 | if (es->bottom == es->top) return(0); | ||
| 324 | i=(es->bottom+1)%ERR_NUM_ERRORS; | ||
| 325 | |||
| 326 | ret=es->err_buffer[i]; | ||
| 327 | if (inc) | ||
| 328 | { | ||
| 329 | es->bottom=i; | ||
| 330 | es->err_buffer[i]=0; | ||
| 331 | } | ||
| 332 | |||
| 333 | if ((file != NULL) && (line != NULL)) | ||
| 334 | { | ||
| 335 | if (es->err_file[i] == NULL) | ||
| 336 | { | ||
| 337 | *file="NA"; | ||
| 338 | if (line != NULL) *line=0; | ||
| 339 | } | ||
| 340 | else | ||
| 341 | { | ||
| 342 | *file=es->err_file[i]; | ||
| 343 | if (line != NULL) *line=es->err_line[i]; | ||
| 344 | } | ||
| 345 | } | ||
| 346 | |||
| 347 | if (data != NULL) | ||
| 348 | { | ||
| 349 | if (es->err_data[i] == NULL) | ||
| 350 | { | ||
| 351 | *data=""; | ||
| 352 | if (flags != NULL) *flags=0; | ||
| 353 | } | ||
| 354 | else | ||
| 355 | { | ||
| 356 | *data=es->err_data[i]; | ||
| 357 | if (flags != NULL) *flags=es->err_data_flags[i]; | ||
| 358 | } | ||
| 359 | } | ||
| 360 | return(ret); | ||
| 361 | } | ||
| 362 | |||
| 363 | /* BAD for multi-threaded, uses a local buffer if ret == NULL */ | ||
| 364 | char *ERR_error_string(e,ret) | ||
| 365 | unsigned long e; | ||
| 366 | char *ret; | ||
| 367 | { | ||
| 368 | static char buf[256]; | ||
| 369 | char *ls,*fs,*rs; | ||
| 370 | unsigned long l,f,r; | ||
| 371 | int i; | ||
| 372 | |||
| 373 | l=ERR_GET_LIB(e); | ||
| 374 | f=ERR_GET_FUNC(e); | ||
| 375 | r=ERR_GET_REASON(e); | ||
| 376 | |||
| 377 | ls=ERR_lib_error_string(e); | ||
| 378 | fs=ERR_func_error_string(e); | ||
| 379 | rs=ERR_reason_error_string(e); | ||
| 380 | |||
| 381 | if (ret == NULL) ret=buf; | ||
| 382 | |||
| 383 | sprintf(&(ret[0]),"error:%08lX:",e); | ||
| 384 | i=strlen(ret); | ||
| 385 | if (ls == NULL) | ||
| 386 | sprintf(&(ret[i]),":lib(%lu) ",l); | ||
| 387 | else sprintf(&(ret[i]),"%s",ls); | ||
| 388 | i=strlen(ret); | ||
| 389 | if (fs == NULL) | ||
| 390 | sprintf(&(ret[i]),":func(%lu) ",f); | ||
| 391 | else sprintf(&(ret[i]),":%s",fs); | ||
| 392 | i=strlen(ret); | ||
| 393 | if (rs == NULL) | ||
| 394 | sprintf(&(ret[i]),":reason(%lu)",r); | ||
| 395 | else sprintf(&(ret[i]),":%s",rs); | ||
| 396 | |||
| 397 | return(ret); | ||
| 398 | } | ||
| 399 | |||
| 400 | LHASH *ERR_get_string_table() | ||
| 401 | { | ||
| 402 | return(error_hash); | ||
| 403 | } | ||
| 404 | |||
| 405 | LHASH *ERR_get_err_state_table() | ||
| 406 | { | ||
| 407 | return(thread_hash); | ||
| 408 | } | ||
| 409 | |||
| 410 | char *ERR_lib_error_string(e) | ||
| 411 | unsigned long e; | ||
| 412 | { | ||
| 413 | ERR_STRING_DATA d,*p=NULL; | ||
| 414 | unsigned long l; | ||
| 415 | |||
| 416 | l=ERR_GET_LIB(e); | ||
| 417 | |||
| 418 | CRYPTO_r_lock(CRYPTO_LOCK_ERR_HASH); | ||
| 419 | |||
| 420 | if (error_hash != NULL) | ||
| 421 | { | ||
| 422 | d.error=ERR_PACK(l,0,0); | ||
| 423 | p=(ERR_STRING_DATA *)lh_retrieve(error_hash,(char *)&d); | ||
| 424 | } | ||
| 425 | |||
| 426 | CRYPTO_r_unlock(CRYPTO_LOCK_ERR_HASH); | ||
| 427 | |||
| 428 | return((p == NULL)?NULL:p->string); | ||
| 429 | } | ||
| 430 | |||
| 431 | char *ERR_func_error_string(e) | ||
| 432 | unsigned long e; | ||
| 433 | { | ||
| 434 | ERR_STRING_DATA d,*p=NULL; | ||
| 435 | unsigned long l,f; | ||
| 436 | |||
| 437 | l=ERR_GET_LIB(e); | ||
| 438 | f=ERR_GET_FUNC(e); | ||
| 439 | |||
| 440 | CRYPTO_r_lock(CRYPTO_LOCK_ERR_HASH); | ||
| 441 | |||
| 442 | if (error_hash != NULL) | ||
| 443 | { | ||
| 444 | d.error=ERR_PACK(l,f,0); | ||
| 445 | p=(ERR_STRING_DATA *)lh_retrieve(error_hash,(char *)&d); | ||
| 446 | } | ||
| 447 | |||
| 448 | CRYPTO_r_unlock(CRYPTO_LOCK_ERR_HASH); | ||
| 449 | |||
| 450 | return((p == NULL)?NULL:p->string); | ||
| 451 | } | ||
| 452 | |||
| 453 | char *ERR_reason_error_string(e) | ||
| 454 | unsigned long e; | ||
| 455 | { | ||
| 456 | ERR_STRING_DATA d,*p=NULL; | ||
| 457 | unsigned long l,r; | ||
| 458 | |||
| 459 | l=ERR_GET_LIB(e); | ||
| 460 | r=ERR_GET_REASON(e); | ||
| 461 | |||
| 462 | CRYPTO_r_lock(CRYPTO_LOCK_ERR_HASH); | ||
| 463 | |||
| 464 | if (error_hash != NULL) | ||
| 465 | { | ||
| 466 | d.error=ERR_PACK(l,0,r); | ||
| 467 | p=(ERR_STRING_DATA *)lh_retrieve(error_hash,(char *)&d); | ||
| 468 | if (p == NULL) | ||
| 469 | { | ||
| 470 | d.error=ERR_PACK(0,0,r); | ||
| 471 | p=(ERR_STRING_DATA *)lh_retrieve(error_hash, | ||
| 472 | (char *)&d); | ||
| 473 | } | ||
| 474 | } | ||
| 475 | |||
| 476 | CRYPTO_r_unlock(CRYPTO_LOCK_ERR_HASH); | ||
| 477 | |||
| 478 | return((p == NULL)?NULL:p->string); | ||
| 479 | } | ||
| 480 | |||
| 481 | static unsigned long err_hash(a) | ||
| 482 | ERR_STRING_DATA *a; | ||
| 483 | { | ||
| 484 | unsigned long ret,l; | ||
| 485 | |||
| 486 | l=a->error; | ||
| 487 | ret=l^ERR_GET_LIB(l)^ERR_GET_FUNC(l); | ||
| 488 | return(ret^ret%19*13); | ||
| 489 | } | ||
| 490 | |||
| 491 | static int err_cmp(a,b) | ||
| 492 | ERR_STRING_DATA *a,*b; | ||
| 493 | { | ||
| 494 | return((int)(a->error-b->error)); | ||
| 495 | } | ||
| 496 | |||
| 497 | static unsigned long pid_hash(a) | ||
| 498 | ERR_STATE *a; | ||
| 499 | { | ||
| 500 | return(a->pid*13); | ||
| 501 | } | ||
| 502 | |||
| 503 | static int pid_cmp(a,b) | ||
| 504 | ERR_STATE *a,*b; | ||
| 505 | { | ||
| 506 | return((int)((long)a->pid - (long)b->pid)); | ||
| 507 | } | ||
| 508 | |||
| 509 | void ERR_remove_state(pid) | ||
| 510 | unsigned long pid; | ||
| 511 | { | ||
| 512 | ERR_STATE *p,tmp; | ||
| 513 | |||
| 514 | if (thread_hash == NULL) | ||
| 515 | return; | ||
| 516 | if (pid == 0) | ||
| 517 | pid=(unsigned long)CRYPTO_thread_id(); | ||
| 518 | tmp.pid=pid; | ||
| 519 | CRYPTO_w_lock(CRYPTO_LOCK_ERR); | ||
| 520 | p=(ERR_STATE *)lh_delete(thread_hash,(char *)&tmp); | ||
| 521 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); | ||
| 522 | |||
| 523 | if (p != NULL) ERR_STATE_free(p); | ||
| 524 | } | ||
| 525 | |||
| 526 | ERR_STATE *ERR_get_state() | ||
| 527 | { | ||
| 528 | static ERR_STATE fallback; | ||
| 529 | ERR_STATE *ret=NULL,tmp,*tmpp; | ||
| 530 | int i; | ||
| 531 | unsigned long pid; | ||
| 532 | |||
| 533 | pid=(unsigned long)CRYPTO_thread_id(); | ||
| 534 | |||
| 535 | CRYPTO_r_lock(CRYPTO_LOCK_ERR); | ||
| 536 | if (thread_hash == NULL) | ||
| 537 | { | ||
| 538 | CRYPTO_r_unlock(CRYPTO_LOCK_ERR); | ||
| 539 | CRYPTO_w_lock(CRYPTO_LOCK_ERR); | ||
| 540 | if (thread_hash == NULL) | ||
| 541 | { | ||
| 542 | thread_hash=lh_new(pid_hash,pid_cmp); | ||
| 543 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); | ||
| 544 | if (thread_hash == NULL) return(&fallback); | ||
| 545 | } | ||
| 546 | else | ||
| 547 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); | ||
| 548 | } | ||
| 549 | else | ||
| 550 | { | ||
| 551 | tmp.pid=pid; | ||
| 552 | ret=(ERR_STATE *)lh_retrieve(thread_hash,(char *)&tmp); | ||
| 553 | CRYPTO_r_unlock(CRYPTO_LOCK_ERR); | ||
| 554 | } | ||
| 555 | |||
| 556 | /* ret == the error state, if NULL, make a new one */ | ||
| 557 | if (ret == NULL) | ||
| 558 | { | ||
| 559 | ret=(ERR_STATE *)Malloc(sizeof(ERR_STATE)); | ||
| 560 | if (ret == NULL) return(&fallback); | ||
| 561 | ret->pid=pid; | ||
| 562 | ret->top=0; | ||
| 563 | ret->bottom=0; | ||
| 564 | for (i=0; i<ERR_NUM_ERRORS; i++) | ||
| 565 | { | ||
| 566 | ret->err_data[i]=NULL; | ||
| 567 | ret->err_data_flags[i]=0; | ||
| 568 | } | ||
| 569 | CRYPTO_w_lock(CRYPTO_LOCK_ERR); | ||
| 570 | tmpp=(ERR_STATE *)lh_insert(thread_hash,(char *)ret); | ||
| 571 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); | ||
| 572 | if (tmpp != NULL) /* old entry - should not happen */ | ||
| 573 | { | ||
| 574 | ERR_STATE_free(tmpp); | ||
| 575 | } | ||
| 576 | } | ||
| 577 | return(ret); | ||
| 578 | } | ||
| 579 | |||
| 580 | int ERR_get_next_error_library() | ||
| 581 | { | ||
| 582 | static int value=ERR_LIB_USER; | ||
| 583 | |||
| 584 | return(value++); | ||
| 585 | } | ||
| 586 | |||
| 587 | void ERR_set_error_data(data,flags) | ||
| 588 | char *data; | ||
| 589 | int flags; | ||
| 590 | { | ||
| 591 | ERR_STATE *es; | ||
| 592 | int i; | ||
| 593 | |||
| 594 | es=ERR_get_state(); | ||
| 595 | |||
| 596 | i=es->top; | ||
| 597 | if (i == 0) | ||
| 598 | i=ERR_NUM_ERRORS-1; | ||
| 599 | |||
| 600 | es->err_data[i]=data; | ||
| 601 | es->err_data_flags[es->top]=flags; | ||
| 602 | } | ||
| 603 | |||
| 604 | void ERR_add_error_data( VAR_PLIST(int , num)) | ||
| 605 | VAR_ALIST | ||
| 606 | { | ||
| 607 | VAR_BDEFN(args, int, num); | ||
| 608 | int i,n,s; | ||
| 609 | char *str,*p,*a; | ||
| 610 | |||
| 611 | s=64; | ||
| 612 | str=Malloc(s+1); | ||
| 613 | if (str == NULL) return; | ||
| 614 | str[0]='\0'; | ||
| 615 | |||
| 616 | VAR_INIT(args,int,num); | ||
| 617 | n=0; | ||
| 618 | for (i=0; i<num; i++) | ||
| 619 | { | ||
| 620 | VAR_ARG(args,char *,a); | ||
| 621 | if (a != NULL) { | ||
| 622 | n+=strlen(a); | ||
| 623 | if (n > s) | ||
| 624 | { | ||
| 625 | s=n+20; | ||
| 626 | p=Realloc(str,s+1); | ||
| 627 | if (p == NULL) | ||
| 628 | { | ||
| 629 | Free(str); | ||
| 630 | return; | ||
| 631 | } | ||
| 632 | else | ||
| 633 | str=p; | ||
| 634 | } | ||
| 635 | strcat(str,a); | ||
| 636 | } | ||
| 637 | } | ||
| 638 | ERR_set_error_data(str,ERR_TXT_MALLOCED|ERR_TXT_STRING); | ||
| 639 | |||
| 640 | VAR_END( args ); | ||
| 641 | } | ||
| 642 | |||
diff --git a/src/lib/libcrypto/err/err.h b/src/lib/libcrypto/err/err.h new file mode 100644 index 0000000000..75f931be11 --- /dev/null +++ b/src/lib/libcrypto/err/err.h | |||
| @@ -0,0 +1,287 @@ | |||
| 1 | /* crypto/err/err.h */ | ||
| 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 | #ifndef HEADER_ERR_H | ||
| 60 | #define HEADER_ERR_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | /* The following is a bit of a trick to help the object files only contain | ||
| 67 | * the 'name of the file' string once. Since 'err.h' is protected by the | ||
| 68 | * HEADER_ERR_H stuff, this should be included only once per file. */ | ||
| 69 | |||
| 70 | #define ERR_file_name __FILE__ | ||
| 71 | |||
| 72 | #ifndef NO_ERR | ||
| 73 | #define ERR_PUT_error(a,b,c,d,e) ERR_put_error(a,b,c,d,e) | ||
| 74 | #else | ||
| 75 | #define ERR_PUT_error(a,b,c,d,e) ERR_put_error(a,b,c,NULL,0) | ||
| 76 | #endif | ||
| 77 | |||
| 78 | #include <errno.h> | ||
| 79 | |||
| 80 | #define ERR_TXT_MALLOCED 0x01 | ||
| 81 | #define ERR_TXT_STRING 0x02 | ||
| 82 | |||
| 83 | #define ERR_NUM_ERRORS 16 | ||
| 84 | typedef struct err_state_st | ||
| 85 | { | ||
| 86 | unsigned long pid; | ||
| 87 | unsigned long err_buffer[ERR_NUM_ERRORS]; | ||
| 88 | char *err_data[ERR_NUM_ERRORS]; | ||
| 89 | int err_data_flags[ERR_NUM_ERRORS]; | ||
| 90 | char *err_file[ERR_NUM_ERRORS]; | ||
| 91 | int err_line[ERR_NUM_ERRORS]; | ||
| 92 | int top,bottom; | ||
| 93 | } ERR_STATE; | ||
| 94 | |||
| 95 | /* library */ | ||
| 96 | #define ERR_LIB_NONE 1 | ||
| 97 | #define ERR_LIB_SYS 2 | ||
| 98 | #define ERR_LIB_BN 3 | ||
| 99 | #define ERR_LIB_RSA 4 | ||
| 100 | #define ERR_LIB_DH 5 | ||
| 101 | #define ERR_LIB_EVP 6 | ||
| 102 | #define ERR_LIB_BUF 7 | ||
| 103 | #define ERR_LIB_OBJ 8 | ||
| 104 | #define ERR_LIB_PEM 9 | ||
| 105 | #define ERR_LIB_DSA 10 | ||
| 106 | #define ERR_LIB_X509 11 | ||
| 107 | #define ERR_LIB_METH 12 | ||
| 108 | #define ERR_LIB_ASN1 13 | ||
| 109 | #define ERR_LIB_CONF 14 | ||
| 110 | #define ERR_LIB_CRYPTO 15 | ||
| 111 | #define ERR_LIB_SSL 20 | ||
| 112 | #define ERR_LIB_SSL23 21 | ||
| 113 | #define ERR_LIB_SSL2 22 | ||
| 114 | #define ERR_LIB_SSL3 23 | ||
| 115 | #define ERR_LIB_RSAREF 30 | ||
| 116 | #define ERR_LIB_PROXY 31 | ||
| 117 | #define ERR_LIB_BIO 32 | ||
| 118 | #define ERR_LIB_PKCS7 33 | ||
| 119 | |||
| 120 | #define ERR_LIB_USER 128 | ||
| 121 | |||
| 122 | #define SYSerr(f,r) ERR_PUT_error(ERR_LIB_SYS,(f),(r),ERR_file_name,__LINE__) | ||
| 123 | #define BNerr(f,r) ERR_PUT_error(ERR_LIB_BN,(f),(r),ERR_file_name,__LINE__) | ||
| 124 | #define RSAerr(f,r) ERR_PUT_error(ERR_LIB_RSA,(f),(r),ERR_file_name,__LINE__) | ||
| 125 | #define DHerr(f,r) ERR_PUT_error(ERR_LIB_DH,(f),(r),ERR_file_name,__LINE__) | ||
| 126 | #define EVPerr(f,r) ERR_PUT_error(ERR_LIB_EVP,(f),(r),ERR_file_name,__LINE__) | ||
| 127 | #define BUFerr(f,r) ERR_PUT_error(ERR_LIB_BUF,(f),(r),ERR_file_name,__LINE__) | ||
| 128 | #define BIOerr(f,r) ERR_PUT_error(ERR_LIB_BIO,(f),(r),ERR_file_name,__LINE__) | ||
| 129 | #define OBJerr(f,r) ERR_PUT_error(ERR_LIB_OBJ,(f),(r),ERR_file_name,__LINE__) | ||
| 130 | #define PEMerr(f,r) ERR_PUT_error(ERR_LIB_PEM,(f),(r),ERR_file_name,__LINE__) | ||
| 131 | #define DSAerr(f,r) ERR_PUT_error(ERR_LIB_DSA,(f),(r),ERR_file_name,__LINE__) | ||
| 132 | #define X509err(f,r) ERR_PUT_error(ERR_LIB_X509,(f),(r),ERR_file_name,__LINE__) | ||
| 133 | #define METHerr(f,r) ERR_PUT_error(ERR_LIB_METH,(f),(r),ERR_file_name,__LINE__) | ||
| 134 | #define ASN1err(f,r) ERR_PUT_error(ERR_LIB_ASN1,(f),(r),ERR_file_name,__LINE__) | ||
| 135 | #define CONFerr(f,r) ERR_PUT_error(ERR_LIB_CONF,(f),(r),ERR_file_name,__LINE__) | ||
| 136 | #define CRYPTOerr(f,r) ERR_PUT_error(ERR_LIB_CRYPTO,(f),(r),ERR_file_name,__LINE__) | ||
| 137 | #define SSLerr(f,r) ERR_PUT_error(ERR_LIB_SSL,(f),(r),ERR_file_name,__LINE__) | ||
| 138 | #define SSL23err(f,r) ERR_PUT_error(ERR_LIB_SSL23,(f),(r),ERR_file_name,__LINE__) | ||
| 139 | #define SSL2err(f,r) ERR_PUT_error(ERR_LIB_SSL2,(f),(r),ERR_file_name,__LINE__) | ||
| 140 | #define SSL3err(f,r) ERR_PUT_error(ERR_LIB_SSL3,(f),(r),ERR_file_name,__LINE__) | ||
| 141 | #define RSAREFerr(f,r) ERR_PUT_error(ERR_LIB_RSAREF,(f),(r),ERR_file_name,__LINE__) | ||
| 142 | #define PROXYerr(f,r) ERR_PUT_error(ERR_LIB_PROXY,(f),(r),ERR_file_name,__LINE__) | ||
| 143 | #define PKCS7err(f,r) ERR_PUT_error(ERR_LIB_PKCS7,(f),(r),ERR_file_name,__LINE__) | ||
| 144 | |||
| 145 | /* Borland C seems too stupid to be able to shift and do longs in | ||
| 146 | * the pre-processor :-( */ | ||
| 147 | #define ERR_PACK(l,f,r) (((((unsigned long)l)&0xffL)*0x1000000)| \ | ||
| 148 | ((((unsigned long)f)&0xfffL)*0x1000)| \ | ||
| 149 | ((((unsigned long)r)&0xfffL))) | ||
| 150 | #define ERR_GET_LIB(l) (int)((((unsigned long)l)>>24L)&0xffL) | ||
| 151 | #define ERR_GET_FUNC(l) (int)((((unsigned long)l)>>12L)&0xfffL) | ||
| 152 | #define ERR_GET_REASON(l) (int)((l)&0xfffL) | ||
| 153 | #define ERR_FATAL_ERROR(l) (int)((l)&ERR_R_FATAL) | ||
| 154 | |||
| 155 | /* OS fuctions */ | ||
| 156 | #define SYS_F_FOPEN 1 | ||
| 157 | #define SYS_F_CONNECT 2 | ||
| 158 | #define SYS_F_GETSERVBYNAME 3 | ||
| 159 | #define SYS_F_SOCKET 4 | ||
| 160 | #define SYS_F_IOCTLSOCKET 5 | ||
| 161 | #define SYS_F_BIND 6 | ||
| 162 | #define SYS_F_LISTEN 7 | ||
| 163 | #define SYS_F_ACCEPT 8 | ||
| 164 | #define SYS_F_WSASTARTUP 9 /* Winsock stuff */ | ||
| 165 | |||
| 166 | #define ERR_R_FATAL 32 | ||
| 167 | /* reasons */ | ||
| 168 | #define ERR_R_SYS_LIB ERR_LIB_SYS | ||
| 169 | #define ERR_R_BN_LIB ERR_LIB_BN | ||
| 170 | #define ERR_R_RSA_LIB ERR_LIB_RSA | ||
| 171 | #define ERR_R_DSA_LIB ERR_LIB_DSA | ||
| 172 | #define ERR_R_DH_LIB ERR_LIB_DH | ||
| 173 | #define ERR_R_EVP_LIB ERR_LIB_EVP | ||
| 174 | #define ERR_R_BUF_LIB ERR_LIB_BUF | ||
| 175 | #define ERR_R_BIO_LIB ERR_LIB_BIO | ||
| 176 | #define ERR_R_OBJ_LIB ERR_LIB_OBJ | ||
| 177 | #define ERR_R_PEM_LIB ERR_LIB_PEM | ||
| 178 | #define ERR_R_X509_LIB ERR_LIB_X509 | ||
| 179 | #define ERR_R_METH_LIB ERR_LIB_METH | ||
| 180 | #define ERR_R_ASN1_LIB ERR_LIB_ASN1 | ||
| 181 | #define ERR_R_CONF_LIB ERR_LIB_CONF | ||
| 182 | #define ERR_R_CRYPTO_LIB ERR_LIB_CRYPTO | ||
| 183 | #define ERR_R_SSL_LIB ERR_LIB_SSL | ||
| 184 | #define ERR_R_SSL23_LIB ERR_LIB_SSL23 | ||
| 185 | #define ERR_R_SSL2_LIB ERR_LIB_SSL2 | ||
| 186 | #define ERR_R_SSL3_LIB ERR_LIB_SSL3 | ||
| 187 | #define ERR_R_PROXY_LIB ERR_LIB_PROXY | ||
| 188 | #define ERR_R_BIO_LIB ERR_LIB_BIO | ||
| 189 | #define ERR_R_PKCS7_LIB ERR_LIB_PKCS7 | ||
| 190 | |||
| 191 | /* fatal error */ | ||
| 192 | #define ERR_R_MALLOC_FAILURE (1|ERR_R_FATAL) | ||
| 193 | #define ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED (2|ERR_R_FATAL) | ||
| 194 | #define ERR_R_PASSED_NULL_PARAMETER (3|ERR_R_FATAL) | ||
| 195 | |||
| 196 | typedef struct ERR_string_data_st | ||
| 197 | { | ||
| 198 | unsigned long error; | ||
| 199 | char *string; | ||
| 200 | } ERR_STRING_DATA; | ||
| 201 | |||
| 202 | #ifndef NOPROTO | ||
| 203 | void ERR_put_error(int lib, int func,int reason,char *file,int line); | ||
| 204 | void ERR_set_error_data(char *data,int flags); | ||
| 205 | |||
| 206 | unsigned long ERR_get_error(void ); | ||
| 207 | unsigned long ERR_get_error_line(char **file,int *line); | ||
| 208 | unsigned long ERR_get_error_line_data(char **file,int *line, | ||
| 209 | char **data, int *flags); | ||
| 210 | unsigned long ERR_peek_error(void ); | ||
| 211 | unsigned long ERR_peek_error_line(char **file,int *line); | ||
| 212 | unsigned long ERR_peek_error_line_data(char **file,int *line, | ||
| 213 | char **data,int *flags); | ||
| 214 | void ERR_clear_error(void ); | ||
| 215 | char *ERR_error_string(unsigned long e,char *buf); | ||
| 216 | char *ERR_lib_error_string(unsigned long e); | ||
| 217 | char *ERR_func_error_string(unsigned long e); | ||
| 218 | char *ERR_reason_error_string(unsigned long e); | ||
| 219 | #ifndef NO_FP_API | ||
| 220 | void ERR_print_errors_fp(FILE *fp); | ||
| 221 | #endif | ||
| 222 | #ifdef HEADER_BIO_H | ||
| 223 | void ERR_print_errors(BIO *bp); | ||
| 224 | void ERR_add_error_data( VAR_PLIST( int, num ) ); | ||
| 225 | #endif | ||
| 226 | void ERR_load_strings(int lib,ERR_STRING_DATA str[]); | ||
| 227 | void ERR_load_ERR_strings(void ); | ||
| 228 | void ERR_load_crypto_strings(void ); | ||
| 229 | void ERR_free_strings(void ); | ||
| 230 | |||
| 231 | void ERR_remove_state(unsigned long pid); /* if zero we look it up */ | ||
| 232 | ERR_STATE *ERR_get_state(void); | ||
| 233 | |||
| 234 | #ifdef HEADER_LHASH_H | ||
| 235 | LHASH *ERR_get_string_table(void ); | ||
| 236 | LHASH *ERR_get_err_state_table(void ); | ||
| 237 | #else | ||
| 238 | char *ERR_get_string_table(void ); | ||
| 239 | char *ERR_get_err_state_table(void ); | ||
| 240 | #endif | ||
| 241 | |||
| 242 | int ERR_get_next_error_library(void ); | ||
| 243 | |||
| 244 | #else | ||
| 245 | |||
| 246 | void ERR_put_error(); | ||
| 247 | void ERR_set_error_data(); | ||
| 248 | |||
| 249 | unsigned long ERR_get_error(); | ||
| 250 | unsigned long ERR_get_error_line(); | ||
| 251 | unsigned long ERR_peek_error(); | ||
| 252 | unsigned long ERR_peek_error_line(); | ||
| 253 | void ERR_clear_error(); | ||
| 254 | char *ERR_error_string(); | ||
| 255 | char *ERR_lib_error_string(); | ||
| 256 | char *ERR_func_error_string(); | ||
| 257 | char *ERR_reason_error_string(); | ||
| 258 | #ifndef NO_FP_API | ||
| 259 | void ERR_print_errors_fp(); | ||
| 260 | #endif | ||
| 261 | void ERR_print_errors(); | ||
| 262 | void ERR_add_error_data(); | ||
| 263 | void ERR_load_strings(); | ||
| 264 | void ERR_load_ERR_strings(); | ||
| 265 | void ERR_load_crypto_strings(); | ||
| 266 | void ERR_free_strings(); | ||
| 267 | |||
| 268 | void ERR_remove_state(); | ||
| 269 | ERR_STATE *ERR_get_state(); | ||
| 270 | |||
| 271 | #ifdef HEADER_LHASH_H | ||
| 272 | LHASH *ERR_get_string_table(); | ||
| 273 | LHASH *ERR_get_err_state_table(); | ||
| 274 | #else | ||
| 275 | char *ERR_get_string_table(); | ||
| 276 | char *ERR_get_err_state_table(); | ||
| 277 | #endif | ||
| 278 | |||
| 279 | int ERR_get_next_error_library(); | ||
| 280 | |||
| 281 | #endif | ||
| 282 | |||
| 283 | #ifdef __cplusplus | ||
| 284 | } | ||
| 285 | #endif | ||
| 286 | |||
| 287 | #endif | ||
diff --git a/src/lib/libcrypto/err/err_all.c b/src/lib/libcrypto/err/err_all.c new file mode 100644 index 0000000000..f874268e1a --- /dev/null +++ b/src/lib/libcrypto/err/err_all.c | |||
| @@ -0,0 +1,116 @@ | |||
| 1 | /* crypto/err/err_all.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 "asn1.h" | ||
| 61 | #include "bn.h" | ||
| 62 | #include "buffer.h" | ||
| 63 | #include "bio.h" | ||
| 64 | #ifndef NO_RSA | ||
| 65 | #include "rsa.h" | ||
| 66 | #endif | ||
| 67 | #ifdef RSAref | ||
| 68 | #include "rsaref.h" | ||
| 69 | #endif | ||
| 70 | #ifndef NO_DH | ||
| 71 | #include "dh.h" | ||
| 72 | #endif | ||
| 73 | #ifndef NO_DSA | ||
| 74 | #include "dsa.h" | ||
| 75 | #endif | ||
| 76 | #include "evp.h" | ||
| 77 | #include "objects.h" | ||
| 78 | #include "pem.h" | ||
| 79 | #include "x509.h" | ||
| 80 | #include "conf.h" | ||
| 81 | #include "err.h" | ||
| 82 | |||
| 83 | void ERR_load_crypto_strings() | ||
| 84 | { | ||
| 85 | static int done=0; | ||
| 86 | |||
| 87 | if (done) return; | ||
| 88 | done=1; | ||
| 89 | #ifndef NO_ERR | ||
| 90 | ERR_load_ASN1_strings(); | ||
| 91 | ERR_load_BN_strings(); | ||
| 92 | ERR_load_BUF_strings(); | ||
| 93 | ERR_load_BIO_strings(); | ||
| 94 | ERR_load_CONF_strings(); | ||
| 95 | #ifndef NO_RSA | ||
| 96 | #ifdef RSAref | ||
| 97 | ERR_load_RSAREF_strings(); | ||
| 98 | #else | ||
| 99 | ERR_load_RSA_strings(); | ||
| 100 | #endif | ||
| 101 | #endif | ||
| 102 | #ifndef NO_DH | ||
| 103 | ERR_load_DH_strings(); | ||
| 104 | #endif | ||
| 105 | #ifndef NO_DSA | ||
| 106 | ERR_load_DSA_strings(); | ||
| 107 | #endif | ||
| 108 | ERR_load_ERR_strings(); | ||
| 109 | ERR_load_EVP_strings(); | ||
| 110 | ERR_load_OBJ_strings(); | ||
| 111 | ERR_load_PEM_strings(); | ||
| 112 | ERR_load_X509_strings(); | ||
| 113 | ERR_load_CRYPTO_strings(); | ||
| 114 | ERR_load_PKCS7_strings(); | ||
| 115 | #endif | ||
| 116 | } | ||
diff --git a/src/lib/libcrypto/err/err_prn.c b/src/lib/libcrypto/err/err_prn.c new file mode 100644 index 0000000000..ecd0e7c4fa --- /dev/null +++ b/src/lib/libcrypto/err/err_prn.c | |||
| @@ -0,0 +1,107 @@ | |||
| 1 | /* crypto/err/err_prn.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 "lhash.h" | ||
| 61 | #include "crypto.h" | ||
| 62 | #include "cryptlib.h" | ||
| 63 | #include "buffer.h" | ||
| 64 | #include "err.h" | ||
| 65 | #include "crypto.h" | ||
| 66 | |||
| 67 | #ifndef NO_FP_API | ||
| 68 | void ERR_print_errors_fp(fp) | ||
| 69 | FILE *fp; | ||
| 70 | { | ||
| 71 | unsigned long l; | ||
| 72 | char buf[200]; | ||
| 73 | char *file,*data; | ||
| 74 | int line,flags; | ||
| 75 | unsigned long es; | ||
| 76 | |||
| 77 | es=CRYPTO_thread_id(); | ||
| 78 | while ((l=ERR_get_error_line_data(&file,&line,&data,&flags)) != 0) | ||
| 79 | { | ||
| 80 | fprintf(fp,"%lu:%s:%s:%d:%s\n",es,ERR_error_string(l,buf), | ||
| 81 | file,line,(flags&ERR_TXT_STRING)?data:""); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | #endif | ||
| 85 | |||
| 86 | void ERR_print_errors(bp) | ||
| 87 | BIO *bp; | ||
| 88 | { | ||
| 89 | unsigned long l; | ||
| 90 | char buf[256]; | ||
| 91 | char buf2[256]; | ||
| 92 | char *file,*data; | ||
| 93 | int line,flags; | ||
| 94 | unsigned long es; | ||
| 95 | |||
| 96 | es=CRYPTO_thread_id(); | ||
| 97 | while ((l=ERR_get_error_line_data(&file,&line,&data,&flags)) != 0) | ||
| 98 | { | ||
| 99 | sprintf(buf2,"%lu:%s:%s:%d:",es,ERR_error_string(l,buf), | ||
| 100 | file,line); | ||
| 101 | BIO_write(bp,buf2,strlen(buf2)); | ||
| 102 | if (flags & ERR_TXT_STRING) | ||
| 103 | BIO_write(bp,data,strlen(data)); | ||
| 104 | BIO_write(bp,"\n",1); | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
diff --git a/src/lib/libcrypto/evp/bio_b64.c b/src/lib/libcrypto/evp/bio_b64.c new file mode 100644 index 0000000000..73172b9a07 --- /dev/null +++ b/src/lib/libcrypto/evp/bio_b64.c | |||
| @@ -0,0 +1,547 @@ | |||
| 1 | /* crypto/evp/bio_b64.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 <errno.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "buffer.h" | ||
| 63 | #include "evp.h" | ||
| 64 | |||
| 65 | #ifndef NOPROTO | ||
| 66 | static int b64_write(BIO *h,char *buf,int num); | ||
| 67 | static int b64_read(BIO *h,char *buf,int size); | ||
| 68 | /*static int b64_puts(BIO *h,char *str); */ | ||
| 69 | /*static int b64_gets(BIO *h,char *str,int size); */ | ||
| 70 | static long b64_ctrl(BIO *h,int cmd,long arg1,char *arg2); | ||
| 71 | static int b64_new(BIO *h); | ||
| 72 | static int b64_free(BIO *data); | ||
| 73 | #else | ||
| 74 | static int b64_write(); | ||
| 75 | static int b64_read(); | ||
| 76 | /*static int b64_puts(); */ | ||
| 77 | /*static int b64_gets(); */ | ||
| 78 | static long b64_ctrl(); | ||
| 79 | static int b64_new(); | ||
| 80 | static int b64_free(); | ||
| 81 | #endif | ||
| 82 | |||
| 83 | #define B64_BLOCK_SIZE 1024 | ||
| 84 | #define B64_BLOCK_SIZE2 768 | ||
| 85 | #define B64_NONE 0 | ||
| 86 | #define B64_ENCODE 1 | ||
| 87 | #define B64_DECODE 2 | ||
| 88 | |||
| 89 | typedef struct b64_struct | ||
| 90 | { | ||
| 91 | /*BIO *bio; moved to the BIO structure */ | ||
| 92 | int buf_len; | ||
| 93 | int buf_off; | ||
| 94 | int tmp_len; /* used to find the start when decoding */ | ||
| 95 | int tmp_nl; /* If true, scan until '\n' */ | ||
| 96 | int encode; | ||
| 97 | int start; /* have we started decoding yet? */ | ||
| 98 | int cont; /* <= 0 when finished */ | ||
| 99 | EVP_ENCODE_CTX base64; | ||
| 100 | char buf[EVP_ENCODE_LENGTH(B64_BLOCK_SIZE)+10]; | ||
| 101 | char tmp[B64_BLOCK_SIZE]; | ||
| 102 | } BIO_B64_CTX; | ||
| 103 | |||
| 104 | static BIO_METHOD methods_b64= | ||
| 105 | { | ||
| 106 | BIO_TYPE_BASE64,"base64 encoding", | ||
| 107 | b64_write, | ||
| 108 | b64_read, | ||
| 109 | NULL, /* b64_puts, */ | ||
| 110 | NULL, /* b64_gets, */ | ||
| 111 | b64_ctrl, | ||
| 112 | b64_new, | ||
| 113 | b64_free, | ||
| 114 | }; | ||
| 115 | |||
| 116 | BIO_METHOD *BIO_f_base64() | ||
| 117 | { | ||
| 118 | return(&methods_b64); | ||
| 119 | } | ||
| 120 | |||
| 121 | static int b64_new(bi) | ||
| 122 | BIO *bi; | ||
| 123 | { | ||
| 124 | BIO_B64_CTX *ctx; | ||
| 125 | |||
| 126 | ctx=(BIO_B64_CTX *)Malloc(sizeof(BIO_B64_CTX)); | ||
| 127 | if (ctx == NULL) return(0); | ||
| 128 | |||
| 129 | ctx->buf_len=0; | ||
| 130 | ctx->tmp_len=0; | ||
| 131 | ctx->tmp_nl=0; | ||
| 132 | ctx->buf_off=0; | ||
| 133 | ctx->cont=1; | ||
| 134 | ctx->start=1; | ||
| 135 | ctx->encode=0; | ||
| 136 | |||
| 137 | bi->init=1; | ||
| 138 | bi->ptr=(char *)ctx; | ||
| 139 | bi->flags=0; | ||
| 140 | return(1); | ||
| 141 | } | ||
| 142 | |||
| 143 | static int b64_free(a) | ||
| 144 | BIO *a; | ||
| 145 | { | ||
| 146 | if (a == NULL) return(0); | ||
| 147 | Free(a->ptr); | ||
| 148 | a->ptr=NULL; | ||
| 149 | a->init=0; | ||
| 150 | a->flags=0; | ||
| 151 | return(1); | ||
| 152 | } | ||
| 153 | |||
| 154 | static int b64_read(b,out,outl) | ||
| 155 | BIO *b; | ||
| 156 | char *out; | ||
| 157 | int outl; | ||
| 158 | { | ||
| 159 | int ret=0,i,ii,j,k,x,n,num,ret_code=0; | ||
| 160 | BIO_B64_CTX *ctx; | ||
| 161 | unsigned char *p,*q; | ||
| 162 | |||
| 163 | if (out == NULL) return(0); | ||
| 164 | ctx=(BIO_B64_CTX *)b->ptr; | ||
| 165 | |||
| 166 | if ((ctx == NULL) || (b->next_bio == NULL)) return(0); | ||
| 167 | |||
| 168 | if (ctx->encode != B64_DECODE) | ||
| 169 | { | ||
| 170 | ctx->encode=B64_DECODE; | ||
| 171 | ctx->buf_len=0; | ||
| 172 | ctx->buf_off=0; | ||
| 173 | ctx->tmp_len=0; | ||
| 174 | EVP_DecodeInit(&(ctx->base64)); | ||
| 175 | } | ||
| 176 | |||
| 177 | /* First check if there are bytes decoded/encoded */ | ||
| 178 | if (ctx->buf_len > 0) | ||
| 179 | { | ||
| 180 | i=ctx->buf_len-ctx->buf_off; | ||
| 181 | if (i > outl) i=outl; | ||
| 182 | memcpy(out,&(ctx->buf[ctx->buf_off]),i); | ||
| 183 | ret=i; | ||
| 184 | out+=i; | ||
| 185 | outl-=i; | ||
| 186 | ctx->buf_off+=i; | ||
| 187 | if (ctx->buf_len == ctx->buf_off) | ||
| 188 | { | ||
| 189 | ctx->buf_len=0; | ||
| 190 | ctx->buf_off=0; | ||
| 191 | } | ||
| 192 | } | ||
| 193 | |||
| 194 | /* At this point, we have room of outl bytes and an empty | ||
| 195 | * buffer, so we should read in some more. */ | ||
| 196 | |||
| 197 | ret_code=0; | ||
| 198 | while (outl > 0) | ||
| 199 | { | ||
| 200 | if (ctx->cont <= 0) break; | ||
| 201 | |||
| 202 | i=BIO_read(b->next_bio,&(ctx->tmp[ctx->tmp_len]), | ||
| 203 | B64_BLOCK_SIZE-ctx->tmp_len); | ||
| 204 | |||
| 205 | if (i <= 0) | ||
| 206 | { | ||
| 207 | ret_code=i; | ||
| 208 | |||
| 209 | /* Should be continue next time we are called? */ | ||
| 210 | if (!BIO_should_retry(b->next_bio)) | ||
| 211 | ctx->cont=i; | ||
| 212 | /* else we should continue when called again */ | ||
| 213 | break; | ||
| 214 | } | ||
| 215 | i+=ctx->tmp_len; | ||
| 216 | |||
| 217 | /* We need to scan, a line at a time until we | ||
| 218 | * have a valid line if we are starting. */ | ||
| 219 | if (ctx->start && (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL)) | ||
| 220 | { | ||
| 221 | /* ctx->start=1; */ | ||
| 222 | ctx->tmp_len=0; | ||
| 223 | } | ||
| 224 | else if (ctx->start) | ||
| 225 | { | ||
| 226 | q=p=(unsigned char *)ctx->tmp; | ||
| 227 | for (j=0; j<i; j++) | ||
| 228 | { | ||
| 229 | if (*(q++) != '\n') continue; | ||
| 230 | |||
| 231 | /* due to a previous very long line, | ||
| 232 | * we need to keep on scanning for a '\n' | ||
| 233 | * before we even start looking for | ||
| 234 | * base64 encoded stuff. */ | ||
| 235 | if (ctx->tmp_nl) | ||
| 236 | { | ||
| 237 | p=q; | ||
| 238 | ctx->tmp_nl=0; | ||
| 239 | continue; | ||
| 240 | } | ||
| 241 | |||
| 242 | k=EVP_DecodeUpdate(&(ctx->base64), | ||
| 243 | (unsigned char *)ctx->buf, | ||
| 244 | &num,p,q-p); | ||
| 245 | if ((k <= 0) && (num == 0) && (ctx->start)) | ||
| 246 | EVP_DecodeInit(&ctx->base64); | ||
| 247 | else | ||
| 248 | { | ||
| 249 | if (p != (unsigned char *) | ||
| 250 | &(ctx->tmp[0])) | ||
| 251 | { | ||
| 252 | i-=(p- (unsigned char *) | ||
| 253 | &(ctx->tmp[0])); | ||
| 254 | for (x=0; x < i; x++) | ||
| 255 | ctx->tmp[x]=p[x]; | ||
| 256 | EVP_DecodeInit(&ctx->base64); | ||
| 257 | } | ||
| 258 | ctx->start=0; | ||
| 259 | break; | ||
| 260 | } | ||
| 261 | p=q; | ||
| 262 | } | ||
| 263 | |||
| 264 | /* we fell off the end without starting */ | ||
| 265 | if (j == i) | ||
| 266 | { | ||
| 267 | /* Is this is one long chunk?, if so, keep on | ||
| 268 | * reading until a new line. */ | ||
| 269 | if (p == (unsigned char *)&(ctx->tmp[0])) | ||
| 270 | { | ||
| 271 | ctx->tmp_nl=1; | ||
| 272 | ctx->tmp_len=0; | ||
| 273 | } | ||
| 274 | else if (p != q) /* finished on a '\n' */ | ||
| 275 | { | ||
| 276 | n=q-p; | ||
| 277 | for (ii=0; ii<n; ii++) | ||
| 278 | ctx->tmp[ii]=p[ii]; | ||
| 279 | ctx->tmp_len=n; | ||
| 280 | } | ||
| 281 | /* else finished on a '\n' */ | ||
| 282 | continue; | ||
| 283 | } | ||
| 284 | else | ||
| 285 | ctx->tmp_len=0; | ||
| 286 | } | ||
| 287 | |||
| 288 | if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL) | ||
| 289 | { | ||
| 290 | int z,jj; | ||
| 291 | |||
| 292 | jj=(i>>2)<<2; | ||
| 293 | z=EVP_DecodeBlock((unsigned char *)ctx->buf, | ||
| 294 | (unsigned char *)ctx->tmp,jj); | ||
| 295 | if (jj > 2) | ||
| 296 | { | ||
| 297 | if (ctx->tmp[jj-1] == '=') | ||
| 298 | { | ||
| 299 | z--; | ||
| 300 | if (ctx->tmp[jj-2] == '=') | ||
| 301 | z--; | ||
| 302 | } | ||
| 303 | } | ||
| 304 | /* z is now number of output bytes and jj is the | ||
| 305 | * number consumed */ | ||
| 306 | if (jj != i) | ||
| 307 | { | ||
| 308 | memcpy((unsigned char *)ctx->tmp, | ||
| 309 | (unsigned char *)&(ctx->tmp[jj]),i-jj); | ||
| 310 | ctx->tmp_len=i-jj; | ||
| 311 | } | ||
| 312 | ctx->buf_len=0; | ||
| 313 | if (z > 0) | ||
| 314 | { | ||
| 315 | ctx->buf_len=z; | ||
| 316 | i=1; | ||
| 317 | } | ||
| 318 | else | ||
| 319 | i=z; | ||
| 320 | } | ||
| 321 | else | ||
| 322 | { | ||
| 323 | i=EVP_DecodeUpdate(&(ctx->base64), | ||
| 324 | (unsigned char *)ctx->buf,&ctx->buf_len, | ||
| 325 | (unsigned char *)ctx->tmp,i); | ||
| 326 | } | ||
| 327 | ctx->cont=i; | ||
| 328 | ctx->buf_off=0; | ||
| 329 | if (i < 0) | ||
| 330 | { | ||
| 331 | ret_code=0; | ||
| 332 | ctx->buf_len=0; | ||
| 333 | break; | ||
| 334 | } | ||
| 335 | |||
| 336 | if (ctx->buf_len <= outl) | ||
| 337 | i=ctx->buf_len; | ||
| 338 | else | ||
| 339 | i=outl; | ||
| 340 | |||
| 341 | memcpy(out,ctx->buf,i); | ||
| 342 | ret+=i; | ||
| 343 | ctx->buf_off=i; | ||
| 344 | if (ctx->buf_off == ctx->buf_len) | ||
| 345 | { | ||
| 346 | ctx->buf_len=0; | ||
| 347 | ctx->buf_off=0; | ||
| 348 | } | ||
| 349 | outl-=i; | ||
| 350 | out+=i; | ||
| 351 | } | ||
| 352 | BIO_clear_retry_flags(b); | ||
| 353 | BIO_copy_next_retry(b); | ||
| 354 | return((ret == 0)?ret_code:ret); | ||
| 355 | } | ||
| 356 | |||
| 357 | static int b64_write(b,in,inl) | ||
| 358 | BIO *b; | ||
| 359 | char *in; | ||
| 360 | int inl; | ||
| 361 | { | ||
| 362 | int ret=inl,n,i; | ||
| 363 | BIO_B64_CTX *ctx; | ||
| 364 | |||
| 365 | ctx=(BIO_B64_CTX *)b->ptr; | ||
| 366 | BIO_clear_retry_flags(b); | ||
| 367 | |||
| 368 | if (ctx->encode != B64_ENCODE) | ||
| 369 | { | ||
| 370 | ctx->encode=B64_ENCODE; | ||
| 371 | ctx->buf_len=0; | ||
| 372 | ctx->buf_off=0; | ||
| 373 | ctx->tmp_len=0; | ||
| 374 | EVP_EncodeInit(&(ctx->base64)); | ||
| 375 | } | ||
| 376 | |||
| 377 | n=ctx->buf_len-ctx->buf_off; | ||
| 378 | while (n > 0) | ||
| 379 | { | ||
| 380 | i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n); | ||
| 381 | if (i <= 0) | ||
| 382 | { | ||
| 383 | BIO_copy_next_retry(b); | ||
| 384 | return(i); | ||
| 385 | } | ||
| 386 | ctx->buf_off+=i; | ||
| 387 | n-=i; | ||
| 388 | } | ||
| 389 | /* at this point all pending data has been written */ | ||
| 390 | |||
| 391 | if ((in == NULL) || (inl <= 0)) return(0); | ||
| 392 | |||
| 393 | ctx->buf_off=0; | ||
| 394 | while (inl > 0) | ||
| 395 | { | ||
| 396 | n=(inl > B64_BLOCK_SIZE)?B64_BLOCK_SIZE:inl; | ||
| 397 | |||
| 398 | if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL) | ||
| 399 | { | ||
| 400 | if (ctx->tmp_len > 0) | ||
| 401 | { | ||
| 402 | n=3-ctx->tmp_len; | ||
| 403 | memcpy(&(ctx->tmp[ctx->tmp_len]),in,n); | ||
| 404 | ctx->tmp_len+=n; | ||
| 405 | n=ctx->tmp_len; | ||
| 406 | if (n < 3) | ||
| 407 | break; | ||
| 408 | ctx->buf_len=EVP_EncodeBlock( | ||
| 409 | (unsigned char *)ctx->buf, | ||
| 410 | (unsigned char *)ctx->tmp,n); | ||
| 411 | } | ||
| 412 | else | ||
| 413 | { | ||
| 414 | if (n < 3) | ||
| 415 | { | ||
| 416 | memcpy(&(ctx->tmp[0]),in,n); | ||
| 417 | ctx->tmp_len=n; | ||
| 418 | break; | ||
| 419 | } | ||
| 420 | n-=n%3; | ||
| 421 | ctx->buf_len=EVP_EncodeBlock( | ||
| 422 | (unsigned char *)ctx->buf, | ||
| 423 | (unsigned char *)in,n); | ||
| 424 | } | ||
| 425 | } | ||
| 426 | else | ||
| 427 | { | ||
| 428 | EVP_EncodeUpdate(&(ctx->base64), | ||
| 429 | (unsigned char *)ctx->buf,&ctx->buf_len, | ||
| 430 | (unsigned char *)in,n); | ||
| 431 | } | ||
| 432 | inl-=n; | ||
| 433 | in+=n; | ||
| 434 | |||
| 435 | ctx->buf_off=0; | ||
| 436 | n=ctx->buf_len; | ||
| 437 | while (n > 0) | ||
| 438 | { | ||
| 439 | i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n); | ||
| 440 | if (i <= 0) | ||
| 441 | { | ||
| 442 | BIO_copy_next_retry(b); | ||
| 443 | return((ret == 0)?i:ret); | ||
| 444 | } | ||
| 445 | n-=i; | ||
| 446 | ctx->buf_off+=i; | ||
| 447 | } | ||
| 448 | ctx->buf_len=0; | ||
| 449 | ctx->buf_off=0; | ||
| 450 | } | ||
| 451 | return(ret); | ||
| 452 | } | ||
| 453 | |||
| 454 | static long b64_ctrl(b,cmd,num,ptr) | ||
| 455 | BIO *b; | ||
| 456 | int cmd; | ||
| 457 | long num; | ||
| 458 | char *ptr; | ||
| 459 | { | ||
| 460 | BIO_B64_CTX *ctx; | ||
| 461 | long ret=1; | ||
| 462 | int i; | ||
| 463 | |||
| 464 | ctx=(BIO_B64_CTX *)b->ptr; | ||
| 465 | |||
| 466 | switch (cmd) | ||
| 467 | { | ||
| 468 | case BIO_CTRL_RESET: | ||
| 469 | ctx->cont=1; | ||
| 470 | ctx->start=1; | ||
| 471 | ctx->encode=B64_NONE; | ||
| 472 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 473 | break; | ||
| 474 | case BIO_CTRL_EOF: /* More to read */ | ||
| 475 | if (ctx->cont <= 0) | ||
| 476 | ret=1; | ||
| 477 | else | ||
| 478 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 479 | break; | ||
| 480 | case BIO_CTRL_WPENDING: /* More to write in buffer */ | ||
| 481 | ret=ctx->buf_len-ctx->buf_off; | ||
| 482 | if ((ret == 0) && (ctx->base64.num != 0)) | ||
| 483 | ret=1; | ||
| 484 | else if (ret <= 0) | ||
| 485 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 486 | break; | ||
| 487 | case BIO_CTRL_PENDING: /* More to read in buffer */ | ||
| 488 | ret=ctx->buf_len-ctx->buf_off; | ||
| 489 | if (ret <= 0) | ||
| 490 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 491 | break; | ||
| 492 | case BIO_CTRL_FLUSH: | ||
| 493 | /* do a final write */ | ||
| 494 | again: | ||
| 495 | while (ctx->buf_len != ctx->buf_off) | ||
| 496 | { | ||
| 497 | i=b64_write(b,NULL,0); | ||
| 498 | if (i < 0) | ||
| 499 | { | ||
| 500 | ret=i; | ||
| 501 | break; | ||
| 502 | } | ||
| 503 | } | ||
| 504 | if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL) | ||
| 505 | { | ||
| 506 | if (ctx->tmp_len != 0) | ||
| 507 | { | ||
| 508 | ctx->buf_len=EVP_EncodeBlock( | ||
| 509 | (unsigned char *)ctx->buf, | ||
| 510 | (unsigned char *)ctx->tmp, | ||
| 511 | ctx->tmp_len); | ||
| 512 | ctx->buf_off=0; | ||
| 513 | ctx->tmp_len=0; | ||
| 514 | goto again; | ||
| 515 | } | ||
| 516 | } | ||
| 517 | else if (ctx->base64.num != 0) | ||
| 518 | { | ||
| 519 | ctx->buf_off=0; | ||
| 520 | EVP_EncodeFinal(&(ctx->base64), | ||
| 521 | (unsigned char *)ctx->buf, | ||
| 522 | &(ctx->buf_len)); | ||
| 523 | /* push out the bytes */ | ||
| 524 | goto again; | ||
| 525 | } | ||
| 526 | /* Finally flush the underlying BIO */ | ||
| 527 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 528 | break; | ||
| 529 | |||
| 530 | case BIO_C_DO_STATE_MACHINE: | ||
| 531 | BIO_clear_retry_flags(b); | ||
| 532 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 533 | BIO_copy_next_retry(b); | ||
| 534 | break; | ||
| 535 | |||
| 536 | case BIO_CTRL_DUP: | ||
| 537 | break; | ||
| 538 | case BIO_CTRL_INFO: | ||
| 539 | case BIO_CTRL_GET: | ||
| 540 | case BIO_CTRL_SET: | ||
| 541 | default: | ||
| 542 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 543 | break; | ||
| 544 | } | ||
| 545 | return(ret); | ||
| 546 | } | ||
| 547 | |||
diff --git a/src/lib/libcrypto/evp/bio_enc.c b/src/lib/libcrypto/evp/bio_enc.c new file mode 100644 index 0000000000..6c30ddfc54 --- /dev/null +++ b/src/lib/libcrypto/evp/bio_enc.c | |||
| @@ -0,0 +1,423 @@ | |||
| 1 | /* crypto/evp/bio_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 <errno.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "buffer.h" | ||
| 63 | #include "evp.h" | ||
| 64 | |||
| 65 | #ifndef NOPROTO | ||
| 66 | static int enc_write(BIO *h,char *buf,int num); | ||
| 67 | static int enc_read(BIO *h,char *buf,int size); | ||
| 68 | /*static int enc_puts(BIO *h,char *str); */ | ||
| 69 | /*static int enc_gets(BIO *h,char *str,int size); */ | ||
| 70 | static long enc_ctrl(BIO *h,int cmd,long arg1,char *arg2); | ||
| 71 | static int enc_new(BIO *h); | ||
| 72 | static int enc_free(BIO *data); | ||
| 73 | #else | ||
| 74 | static int enc_write(); | ||
| 75 | static int enc_read(); | ||
| 76 | /*static int enc_puts(); */ | ||
| 77 | /*static int enc_gets(); */ | ||
| 78 | static long enc_ctrl(); | ||
| 79 | static int enc_new(); | ||
| 80 | static int enc_free(); | ||
| 81 | #endif | ||
| 82 | |||
| 83 | #define ENC_BLOCK_SIZE (1024*4) | ||
| 84 | |||
| 85 | typedef struct enc_struct | ||
| 86 | { | ||
| 87 | int buf_len; | ||
| 88 | int buf_off; | ||
| 89 | int cont; /* <= 0 when finished */ | ||
| 90 | int finished; | ||
| 91 | int ok; /* bad decrypt */ | ||
| 92 | EVP_CIPHER_CTX cipher; | ||
| 93 | char buf[ENC_BLOCK_SIZE+10]; | ||
| 94 | } BIO_ENC_CTX; | ||
| 95 | |||
| 96 | static BIO_METHOD methods_enc= | ||
| 97 | { | ||
| 98 | BIO_TYPE_CIPHER,"cipher", | ||
| 99 | enc_write, | ||
| 100 | enc_read, | ||
| 101 | NULL, /* enc_puts, */ | ||
| 102 | NULL, /* enc_gets, */ | ||
| 103 | enc_ctrl, | ||
| 104 | enc_new, | ||
| 105 | enc_free, | ||
| 106 | }; | ||
| 107 | |||
| 108 | BIO_METHOD *BIO_f_cipher() | ||
| 109 | { | ||
| 110 | return(&methods_enc); | ||
| 111 | } | ||
| 112 | |||
| 113 | static int enc_new(bi) | ||
| 114 | BIO *bi; | ||
| 115 | { | ||
| 116 | BIO_ENC_CTX *ctx; | ||
| 117 | |||
| 118 | ctx=(BIO_ENC_CTX *)Malloc(sizeof(BIO_ENC_CTX)); | ||
| 119 | EVP_CIPHER_CTX_init(&ctx->cipher); | ||
| 120 | if (ctx == NULL) return(0); | ||
| 121 | |||
| 122 | ctx->buf_len=0; | ||
| 123 | ctx->buf_off=0; | ||
| 124 | ctx->cont=1; | ||
| 125 | ctx->finished=0; | ||
| 126 | ctx->ok=1; | ||
| 127 | |||
| 128 | bi->init=0; | ||
| 129 | bi->ptr=(char *)ctx; | ||
| 130 | bi->flags=0; | ||
| 131 | return(1); | ||
| 132 | } | ||
| 133 | |||
| 134 | static int enc_free(a) | ||
| 135 | BIO *a; | ||
| 136 | { | ||
| 137 | BIO_ENC_CTX *b; | ||
| 138 | |||
| 139 | if (a == NULL) return(0); | ||
| 140 | b=(BIO_ENC_CTX *)a->ptr; | ||
| 141 | EVP_CIPHER_CTX_cleanup(&(b->cipher)); | ||
| 142 | memset(a->ptr,0,sizeof(BIO_ENC_CTX)); | ||
| 143 | Free(a->ptr); | ||
| 144 | a->ptr=NULL; | ||
| 145 | a->init=0; | ||
| 146 | a->flags=0; | ||
| 147 | return(1); | ||
| 148 | } | ||
| 149 | |||
| 150 | static int enc_read(b,out,outl) | ||
| 151 | BIO *b; | ||
| 152 | char *out; | ||
| 153 | int outl; | ||
| 154 | { | ||
| 155 | int ret=0,i; | ||
| 156 | BIO_ENC_CTX *ctx; | ||
| 157 | |||
| 158 | if (out == NULL) return(0); | ||
| 159 | ctx=(BIO_ENC_CTX *)b->ptr; | ||
| 160 | |||
| 161 | if ((ctx == NULL) || (b->next_bio == NULL)) return(0); | ||
| 162 | |||
| 163 | /* First check if there are bytes decoded/encoded */ | ||
| 164 | if (ctx->buf_len > 0) | ||
| 165 | { | ||
| 166 | i=ctx->buf_len-ctx->buf_off; | ||
| 167 | if (i > outl) i=outl; | ||
| 168 | memcpy(out,&(ctx->buf[ctx->buf_off]),i); | ||
| 169 | ret=i; | ||
| 170 | out+=i; | ||
| 171 | outl-=i; | ||
| 172 | ctx->buf_off+=i; | ||
| 173 | if (ctx->buf_len == ctx->buf_off) | ||
| 174 | { | ||
| 175 | ctx->buf_len=0; | ||
| 176 | ctx->buf_off=0; | ||
| 177 | } | ||
| 178 | } | ||
| 179 | |||
| 180 | /* At this point, we have room of outl bytes and an empty | ||
| 181 | * buffer, so we should read in some more. */ | ||
| 182 | |||
| 183 | while (outl > 0) | ||
| 184 | { | ||
| 185 | if (ctx->cont <= 0) break; | ||
| 186 | |||
| 187 | /* read in at offset 8, read the EVP_Cipher | ||
| 188 | * documentation about why */ | ||
| 189 | i=BIO_read(b->next_bio,&(ctx->buf[8]),ENC_BLOCK_SIZE); | ||
| 190 | |||
| 191 | if (i <= 0) | ||
| 192 | { | ||
| 193 | /* Should be continue next time we are called? */ | ||
| 194 | if (!BIO_should_retry(b->next_bio)) | ||
| 195 | { | ||
| 196 | ctx->cont=i; | ||
| 197 | i=EVP_CipherFinal(&(ctx->cipher), | ||
| 198 | (unsigned char *)ctx->buf, | ||
| 199 | &(ctx->buf_len)); | ||
| 200 | ctx->ok=i; | ||
| 201 | ctx->buf_off=0; | ||
| 202 | } | ||
| 203 | else | ||
| 204 | ret=(ret == 0)?i:ret; | ||
| 205 | break; | ||
| 206 | } | ||
| 207 | else | ||
| 208 | { | ||
| 209 | EVP_CipherUpdate(&(ctx->cipher), | ||
| 210 | (unsigned char *)ctx->buf,&ctx->buf_len, | ||
| 211 | (unsigned char *)&(ctx->buf[8]),i); | ||
| 212 | ctx->cont=1; | ||
| 213 | } | ||
| 214 | |||
| 215 | if (ctx->buf_len <= outl) | ||
| 216 | i=ctx->buf_len; | ||
| 217 | else | ||
| 218 | i=outl; | ||
| 219 | |||
| 220 | if (i <= 0) break; | ||
| 221 | memcpy(out,ctx->buf,i); | ||
| 222 | ret+=i; | ||
| 223 | ctx->buf_off=i; | ||
| 224 | outl-=i; | ||
| 225 | out+=i; | ||
| 226 | } | ||
| 227 | |||
| 228 | BIO_clear_retry_flags(b); | ||
| 229 | BIO_copy_next_retry(b); | ||
| 230 | return((ret == 0)?ctx->cont:ret); | ||
| 231 | } | ||
| 232 | |||
| 233 | static int enc_write(b,in,inl) | ||
| 234 | BIO *b; | ||
| 235 | char *in; | ||
| 236 | int inl; | ||
| 237 | { | ||
| 238 | int ret=0,n,i; | ||
| 239 | BIO_ENC_CTX *ctx; | ||
| 240 | |||
| 241 | ctx=(BIO_ENC_CTX *)b->ptr; | ||
| 242 | ret=inl; | ||
| 243 | |||
| 244 | BIO_clear_retry_flags(b); | ||
| 245 | n=ctx->buf_len-ctx->buf_off; | ||
| 246 | while (n > 0) | ||
| 247 | { | ||
| 248 | i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n); | ||
| 249 | if (i <= 0) | ||
| 250 | { | ||
| 251 | BIO_copy_next_retry(b); | ||
| 252 | return(i); | ||
| 253 | } | ||
| 254 | ctx->buf_off+=i; | ||
| 255 | n-=i; | ||
| 256 | } | ||
| 257 | /* at this point all pending data has been written */ | ||
| 258 | |||
| 259 | if ((in == NULL) || (inl <= 0)) return(0); | ||
| 260 | |||
| 261 | ctx->buf_off=0; | ||
| 262 | while (inl > 0) | ||
| 263 | { | ||
| 264 | n=(inl > ENC_BLOCK_SIZE)?ENC_BLOCK_SIZE:inl; | ||
| 265 | EVP_CipherUpdate(&(ctx->cipher), | ||
| 266 | (unsigned char *)ctx->buf,&ctx->buf_len, | ||
| 267 | (unsigned char *)in,n); | ||
| 268 | inl-=n; | ||
| 269 | in+=n; | ||
| 270 | |||
| 271 | ctx->buf_off=0; | ||
| 272 | n=ctx->buf_len; | ||
| 273 | while (n > 0) | ||
| 274 | { | ||
| 275 | i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n); | ||
| 276 | if (i <= 0) | ||
| 277 | { | ||
| 278 | BIO_copy_next_retry(b); | ||
| 279 | return(i); | ||
| 280 | } | ||
| 281 | n-=i; | ||
| 282 | ctx->buf_off+=i; | ||
| 283 | } | ||
| 284 | ctx->buf_len=0; | ||
| 285 | ctx->buf_off=0; | ||
| 286 | } | ||
| 287 | BIO_copy_next_retry(b); | ||
| 288 | return(ret); | ||
| 289 | } | ||
| 290 | |||
| 291 | static long enc_ctrl(b,cmd,num,ptr) | ||
| 292 | BIO *b; | ||
| 293 | int cmd; | ||
| 294 | long num; | ||
| 295 | char *ptr; | ||
| 296 | { | ||
| 297 | BIO *dbio; | ||
| 298 | BIO_ENC_CTX *ctx,*dctx; | ||
| 299 | long ret=1; | ||
| 300 | int i; | ||
| 301 | |||
| 302 | ctx=(BIO_ENC_CTX *)b->ptr; | ||
| 303 | |||
| 304 | switch (cmd) | ||
| 305 | { | ||
| 306 | case BIO_CTRL_RESET: | ||
| 307 | ctx->ok=1; | ||
| 308 | ctx->finished=0; | ||
| 309 | EVP_CipherInit(&(ctx->cipher),NULL,NULL,NULL, | ||
| 310 | ctx->cipher.encrypt); | ||
| 311 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 312 | break; | ||
| 313 | case BIO_CTRL_EOF: /* More to read */ | ||
| 314 | if (ctx->cont <= 0) | ||
| 315 | ret=1; | ||
| 316 | else | ||
| 317 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 318 | break; | ||
| 319 | case BIO_CTRL_WPENDING: | ||
| 320 | ret=ctx->buf_len-ctx->buf_off; | ||
| 321 | if (ret <= 0) | ||
| 322 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 323 | break; | ||
| 324 | case BIO_CTRL_PENDING: /* More to read in buffer */ | ||
| 325 | ret=ctx->buf_len-ctx->buf_off; | ||
| 326 | if (ret <= 0) | ||
| 327 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 328 | break; | ||
| 329 | case BIO_CTRL_FLUSH: | ||
| 330 | /* do a final write */ | ||
| 331 | again: | ||
| 332 | while (ctx->buf_len != ctx->buf_off) | ||
| 333 | { | ||
| 334 | i=enc_write(b,NULL,0); | ||
| 335 | if (i < 0) | ||
| 336 | { | ||
| 337 | ret=i; | ||
| 338 | break; | ||
| 339 | } | ||
| 340 | } | ||
| 341 | |||
| 342 | if (!ctx->finished) | ||
| 343 | { | ||
| 344 | ctx->finished=1; | ||
| 345 | ctx->buf_off=0; | ||
| 346 | ret=EVP_CipherFinal(&(ctx->cipher), | ||
| 347 | (unsigned char *)ctx->buf, | ||
| 348 | &(ctx->buf_len)); | ||
| 349 | ctx->ok=(int)ret; | ||
| 350 | if (ret <= 0) break; | ||
| 351 | |||
| 352 | /* push out the bytes */ | ||
| 353 | goto again; | ||
| 354 | } | ||
| 355 | |||
| 356 | /* Finally flush the underlying BIO */ | ||
| 357 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 358 | break; | ||
| 359 | case BIO_C_GET_CIPHER_STATUS: | ||
| 360 | ret=(long)ctx->ok; | ||
| 361 | break; | ||
| 362 | case BIO_C_DO_STATE_MACHINE: | ||
| 363 | BIO_clear_retry_flags(b); | ||
| 364 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 365 | BIO_copy_next_retry(b); | ||
| 366 | break; | ||
| 367 | |||
| 368 | case BIO_CTRL_DUP: | ||
| 369 | dbio=(BIO *)ptr; | ||
| 370 | dctx=(BIO_ENC_CTX *)dbio->ptr; | ||
| 371 | memcpy(&(dctx->cipher),&(ctx->cipher),sizeof(ctx->cipher)); | ||
| 372 | dbio->init=1; | ||
| 373 | break; | ||
| 374 | default: | ||
| 375 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 376 | break; | ||
| 377 | } | ||
| 378 | return(ret); | ||
| 379 | } | ||
| 380 | |||
| 381 | /* | ||
| 382 | void BIO_set_cipher_ctx(b,c) | ||
| 383 | BIO *b; | ||
| 384 | EVP_CIPHER_ctx *c; | ||
| 385 | { | ||
| 386 | if (b == NULL) return; | ||
| 387 | |||
| 388 | if ((b->callback != NULL) && | ||
| 389 | (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0)) | ||
| 390 | return; | ||
| 391 | |||
| 392 | b->init=1; | ||
| 393 | ctx=(BIO_ENC_CTX *)b->ptr; | ||
| 394 | memcpy(ctx->cipher,c,sizeof(EVP_CIPHER_CTX)); | ||
| 395 | |||
| 396 | if (b->callback != NULL) | ||
| 397 | b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L); | ||
| 398 | } | ||
| 399 | */ | ||
| 400 | |||
| 401 | void BIO_set_cipher(b,c,k,i,e) | ||
| 402 | BIO *b; | ||
| 403 | EVP_CIPHER *c; | ||
| 404 | unsigned char *k; | ||
| 405 | unsigned char *i; | ||
| 406 | int e; | ||
| 407 | { | ||
| 408 | BIO_ENC_CTX *ctx; | ||
| 409 | |||
| 410 | if (b == NULL) return; | ||
| 411 | |||
| 412 | if ((b->callback != NULL) && | ||
| 413 | (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0)) | ||
| 414 | return; | ||
| 415 | |||
| 416 | b->init=1; | ||
| 417 | ctx=(BIO_ENC_CTX *)b->ptr; | ||
| 418 | EVP_CipherInit(&(ctx->cipher),c,k,i,e); | ||
| 419 | |||
| 420 | if (b->callback != NULL) | ||
| 421 | b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L); | ||
| 422 | } | ||
| 423 | |||
diff --git a/src/lib/libcrypto/evp/bio_md.c b/src/lib/libcrypto/evp/bio_md.c new file mode 100644 index 0000000000..fa5fdc055b --- /dev/null +++ b/src/lib/libcrypto/evp/bio_md.c | |||
| @@ -0,0 +1,270 @@ | |||
| 1 | /* crypto/evp/bio_md.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 <errno.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "buffer.h" | ||
| 63 | #include "evp.h" | ||
| 64 | |||
| 65 | /* BIO_put and BIO_get both add to the digest, | ||
| 66 | * BIO_gets returns the digest */ | ||
| 67 | |||
| 68 | #ifndef NOPROTO | ||
| 69 | static int md_write(BIO *h,char *buf,int num); | ||
| 70 | static int md_read(BIO *h,char *buf,int size); | ||
| 71 | /*static int md_puts(BIO *h,char *str); */ | ||
| 72 | static int md_gets(BIO *h,char *str,int size); | ||
| 73 | static long md_ctrl(BIO *h,int cmd,long arg1,char *arg2); | ||
| 74 | static int md_new(BIO *h); | ||
| 75 | static int md_free(BIO *data); | ||
| 76 | #else | ||
| 77 | static int md_write(); | ||
| 78 | static int md_read(); | ||
| 79 | /*static int md_puts(); */ | ||
| 80 | static int md_gets(); | ||
| 81 | static long md_ctrl(); | ||
| 82 | static int md_new(); | ||
| 83 | static int md_free(); | ||
| 84 | #endif | ||
| 85 | |||
| 86 | static BIO_METHOD methods_md= | ||
| 87 | { | ||
| 88 | BIO_TYPE_MD,"message digest", | ||
| 89 | md_write, | ||
| 90 | md_read, | ||
| 91 | NULL, /* md_puts, */ | ||
| 92 | md_gets, | ||
| 93 | md_ctrl, | ||
| 94 | md_new, | ||
| 95 | md_free, | ||
| 96 | }; | ||
| 97 | |||
| 98 | BIO_METHOD *BIO_f_md() | ||
| 99 | { | ||
| 100 | return(&methods_md); | ||
| 101 | } | ||
| 102 | |||
| 103 | static int md_new(bi) | ||
| 104 | BIO *bi; | ||
| 105 | { | ||
| 106 | EVP_MD_CTX *ctx; | ||
| 107 | |||
| 108 | ctx=(EVP_MD_CTX *)Malloc(sizeof(EVP_MD_CTX)); | ||
| 109 | if (ctx == NULL) return(0); | ||
| 110 | |||
| 111 | bi->init=0; | ||
| 112 | bi->ptr=(char *)ctx; | ||
| 113 | bi->flags=0; | ||
| 114 | return(1); | ||
| 115 | } | ||
| 116 | |||
| 117 | static int md_free(a) | ||
| 118 | BIO *a; | ||
| 119 | { | ||
| 120 | if (a == NULL) return(0); | ||
| 121 | Free(a->ptr); | ||
| 122 | a->ptr=NULL; | ||
| 123 | a->init=0; | ||
| 124 | a->flags=0; | ||
| 125 | return(1); | ||
| 126 | } | ||
| 127 | |||
| 128 | static int md_read(b,out,outl) | ||
| 129 | BIO *b; | ||
| 130 | char *out; | ||
| 131 | int outl; | ||
| 132 | { | ||
| 133 | int ret=0; | ||
| 134 | EVP_MD_CTX *ctx; | ||
| 135 | |||
| 136 | if (out == NULL) return(0); | ||
| 137 | ctx=(EVP_MD_CTX *)b->ptr; | ||
| 138 | |||
| 139 | if ((ctx == NULL) || (b->next_bio == NULL)) return(0); | ||
| 140 | |||
| 141 | ret=BIO_read(b->next_bio,out,outl); | ||
| 142 | if (b->init) | ||
| 143 | { | ||
| 144 | if (ret > 0) | ||
| 145 | { | ||
| 146 | EVP_DigestUpdate(ctx,(unsigned char *)out, | ||
| 147 | (unsigned int)ret); | ||
| 148 | } | ||
| 149 | } | ||
| 150 | BIO_clear_retry_flags(b); | ||
| 151 | BIO_copy_next_retry(b); | ||
| 152 | return(ret); | ||
| 153 | } | ||
| 154 | |||
| 155 | static int md_write(b,in,inl) | ||
| 156 | BIO *b; | ||
| 157 | char *in; | ||
| 158 | int inl; | ||
| 159 | { | ||
| 160 | int ret=0; | ||
| 161 | EVP_MD_CTX *ctx; | ||
| 162 | |||
| 163 | if ((in == NULL) || (inl <= 0)) return(0); | ||
| 164 | ctx=(EVP_MD_CTX *)b->ptr; | ||
| 165 | |||
| 166 | if ((ctx != NULL) && (b->next_bio != NULL)) | ||
| 167 | ret=BIO_write(b->next_bio,in,inl); | ||
| 168 | if (b->init) | ||
| 169 | { | ||
| 170 | if (ret > 0) | ||
| 171 | { | ||
| 172 | EVP_DigestUpdate(ctx,(unsigned char *)in, | ||
| 173 | (unsigned int)ret); | ||
| 174 | } | ||
| 175 | } | ||
| 176 | BIO_clear_retry_flags(b); | ||
| 177 | BIO_copy_next_retry(b); | ||
| 178 | return(ret); | ||
| 179 | } | ||
| 180 | |||
| 181 | static long md_ctrl(b,cmd,num,ptr) | ||
| 182 | BIO *b; | ||
| 183 | int cmd; | ||
| 184 | long num; | ||
| 185 | char *ptr; | ||
| 186 | { | ||
| 187 | EVP_MD_CTX *ctx,*dctx,**pctx; | ||
| 188 | EVP_MD **ppmd; | ||
| 189 | EVP_MD *md; | ||
| 190 | long ret=1; | ||
| 191 | BIO *dbio; | ||
| 192 | |||
| 193 | ctx=(EVP_MD_CTX *)b->ptr; | ||
| 194 | |||
| 195 | switch (cmd) | ||
| 196 | { | ||
| 197 | case BIO_CTRL_RESET: | ||
| 198 | if (b->init) | ||
| 199 | EVP_DigestInit(ctx,ctx->digest); | ||
| 200 | else | ||
| 201 | ret=0; | ||
| 202 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 203 | break; | ||
| 204 | case BIO_C_GET_MD: | ||
| 205 | if (b->init) | ||
| 206 | { | ||
| 207 | ppmd=(EVP_MD **)ptr; | ||
| 208 | *ppmd=ctx->digest; | ||
| 209 | } | ||
| 210 | else | ||
| 211 | ret=0; | ||
| 212 | break; | ||
| 213 | case BIO_C_GET_MD_CTX: | ||
| 214 | if (b->init) | ||
| 215 | { | ||
| 216 | pctx=(EVP_MD_CTX **)ptr; | ||
| 217 | *pctx=ctx; | ||
| 218 | } | ||
| 219 | else | ||
| 220 | ret=0; | ||
| 221 | break; | ||
| 222 | case BIO_C_DO_STATE_MACHINE: | ||
| 223 | BIO_clear_retry_flags(b); | ||
| 224 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 225 | BIO_copy_next_retry(b); | ||
| 226 | break; | ||
| 227 | |||
| 228 | case BIO_C_SET_MD: | ||
| 229 | md=(EVP_MD *)ptr; | ||
| 230 | EVP_DigestInit(ctx,md); | ||
| 231 | b->init=1; | ||
| 232 | break; | ||
| 233 | case BIO_CTRL_DUP: | ||
| 234 | dbio=(BIO *)ptr; | ||
| 235 | dctx=(EVP_MD_CTX *)dbio->ptr; | ||
| 236 | memcpy(dctx,ctx,sizeof(ctx)); | ||
| 237 | b->init=1; | ||
| 238 | break; | ||
| 239 | default: | ||
| 240 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 241 | break; | ||
| 242 | } | ||
| 243 | return(ret); | ||
| 244 | } | ||
| 245 | |||
| 246 | static int md_gets(bp,buf,size) | ||
| 247 | BIO *bp; | ||
| 248 | char *buf; | ||
| 249 | int size; | ||
| 250 | { | ||
| 251 | EVP_MD_CTX *ctx; | ||
| 252 | unsigned int ret; | ||
| 253 | |||
| 254 | |||
| 255 | ctx=(EVP_MD_CTX *)bp->ptr; | ||
| 256 | if (size < ctx->digest->md_size) | ||
| 257 | return(0); | ||
| 258 | EVP_DigestFinal(ctx,(unsigned char *)buf,&ret); | ||
| 259 | return((int)ret); | ||
| 260 | } | ||
| 261 | |||
| 262 | /* | ||
| 263 | static int md_puts(bp,str) | ||
| 264 | BIO *bp; | ||
| 265 | char *str; | ||
| 266 | { | ||
| 267 | return(-1); | ||
| 268 | } | ||
| 269 | */ | ||
| 270 | |||
diff --git a/src/lib/libcrypto/evp/c_all.c b/src/lib/libcrypto/evp/c_all.c new file mode 100644 index 0000000000..e77d1c896b --- /dev/null +++ b/src/lib/libcrypto/evp/c_all.c | |||
| @@ -0,0 +1,190 @@ | |||
| 1 | /* crypto/evp/c_all.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 "evp.h" | ||
| 62 | #include "objects.h" | ||
| 63 | |||
| 64 | void SSLeay_add_all_algorithms() | ||
| 65 | { | ||
| 66 | SSLeay_add_all_ciphers(); | ||
| 67 | SSLeay_add_all_digests(); | ||
| 68 | } | ||
| 69 | |||
| 70 | void SSLeay_add_all_ciphers() | ||
| 71 | { | ||
| 72 | #ifndef NO_DES | ||
| 73 | EVP_add_cipher(EVP_des_cfb()); | ||
| 74 | EVP_add_cipher(EVP_des_ede_cfb()); | ||
| 75 | EVP_add_cipher(EVP_des_ede3_cfb()); | ||
| 76 | |||
| 77 | EVP_add_cipher(EVP_des_ofb()); | ||
| 78 | EVP_add_cipher(EVP_des_ede_ofb()); | ||
| 79 | EVP_add_cipher(EVP_des_ede3_ofb()); | ||
| 80 | |||
| 81 | EVP_add_cipher(EVP_desx_cbc()); | ||
| 82 | EVP_add_alias(SN_desx_cbc,"DESX"); | ||
| 83 | EVP_add_alias(SN_desx_cbc,"desx"); | ||
| 84 | |||
| 85 | EVP_add_cipher(EVP_des_cbc()); | ||
| 86 | EVP_add_alias(SN_des_cbc,"DES"); | ||
| 87 | EVP_add_alias(SN_des_cbc,"des"); | ||
| 88 | EVP_add_cipher(EVP_des_ede_cbc()); | ||
| 89 | EVP_add_cipher(EVP_des_ede3_cbc()); | ||
| 90 | EVP_add_alias(SN_des_ede3_cbc,"DES3"); | ||
| 91 | EVP_add_alias(SN_des_ede3_cbc,"des3"); | ||
| 92 | |||
| 93 | EVP_add_cipher(EVP_des_ecb()); | ||
| 94 | EVP_add_cipher(EVP_des_ede()); | ||
| 95 | EVP_add_cipher(EVP_des_ede3()); | ||
| 96 | #endif | ||
| 97 | |||
| 98 | #ifndef NO_RC4 | ||
| 99 | EVP_add_cipher(EVP_rc4()); | ||
| 100 | EVP_add_cipher(EVP_rc4_40()); | ||
| 101 | #endif | ||
| 102 | |||
| 103 | #ifndef NO_IDEA | ||
| 104 | EVP_add_cipher(EVP_idea_ecb()); | ||
| 105 | EVP_add_cipher(EVP_idea_cfb()); | ||
| 106 | EVP_add_cipher(EVP_idea_ofb()); | ||
| 107 | EVP_add_cipher(EVP_idea_cbc()); | ||
| 108 | EVP_add_alias(SN_idea_cbc,"IDEA"); | ||
| 109 | EVP_add_alias(SN_idea_cbc,"idea"); | ||
| 110 | #endif | ||
| 111 | |||
| 112 | #ifndef NO_RC2 | ||
| 113 | EVP_add_cipher(EVP_rc2_ecb()); | ||
| 114 | EVP_add_cipher(EVP_rc2_cfb()); | ||
| 115 | EVP_add_cipher(EVP_rc2_ofb()); | ||
| 116 | EVP_add_cipher(EVP_rc2_cbc()); | ||
| 117 | EVP_add_cipher(EVP_rc2_40_cbc()); | ||
| 118 | EVP_add_alias(SN_rc2_cbc,"RC2"); | ||
| 119 | EVP_add_alias(SN_rc2_cbc,"rc2"); | ||
| 120 | #endif | ||
| 121 | |||
| 122 | #ifndef NO_BLOWFISH | ||
| 123 | EVP_add_cipher(EVP_bf_ecb()); | ||
| 124 | EVP_add_cipher(EVP_bf_cfb()); | ||
| 125 | EVP_add_cipher(EVP_bf_ofb()); | ||
| 126 | EVP_add_cipher(EVP_bf_cbc()); | ||
| 127 | EVP_add_alias(SN_bf_cbc,"BF"); | ||
| 128 | EVP_add_alias(SN_bf_cbc,"bf"); | ||
| 129 | EVP_add_alias(SN_bf_cbc,"blowfish"); | ||
| 130 | #endif | ||
| 131 | |||
| 132 | #ifndef NO_CAST | ||
| 133 | EVP_add_cipher(EVP_cast5_ecb()); | ||
| 134 | EVP_add_cipher(EVP_cast5_cfb()); | ||
| 135 | EVP_add_cipher(EVP_cast5_ofb()); | ||
| 136 | EVP_add_cipher(EVP_cast5_cbc()); | ||
| 137 | EVP_add_alias(SN_cast5_cbc,"CAST"); | ||
| 138 | EVP_add_alias(SN_cast5_cbc,"cast"); | ||
| 139 | EVP_add_alias(SN_cast5_cbc,"CAST-cbc"); | ||
| 140 | EVP_add_alias(SN_cast5_cbc,"cast-cbc"); | ||
| 141 | #endif | ||
| 142 | |||
| 143 | #ifndef NO_RC5 | ||
| 144 | EVP_add_cipher(EVP_rc5_32_12_16_ecb()); | ||
| 145 | EVP_add_cipher(EVP_rc5_32_12_16_cfb()); | ||
| 146 | EVP_add_cipher(EVP_rc5_32_12_16_ofb()); | ||
| 147 | EVP_add_cipher(EVP_rc5_32_12_16_cbc()); | ||
| 148 | EVP_add_alias(SN_rc5_cbc,"rc5"); | ||
| 149 | EVP_add_alias(SN_rc5_cbc,"RC5"); | ||
| 150 | EVP_add_alias(SN_rc5_cbc,"rc5-cbc"); | ||
| 151 | EVP_add_alias(SN_rc5_cbc,"RC5-cbc"); | ||
| 152 | #endif | ||
| 153 | } | ||
| 154 | |||
| 155 | |||
| 156 | void SSLeay_add_all_digests() | ||
| 157 | { | ||
| 158 | #ifndef NO_MD2 | ||
| 159 | EVP_add_digest(EVP_md2()); | ||
| 160 | #endif | ||
| 161 | #ifndef NO_MD5 | ||
| 162 | EVP_add_digest(EVP_md5()); | ||
| 163 | EVP_add_alias(SN_md5,"ssl2-md5"); | ||
| 164 | EVP_add_alias(SN_md5,"ssl3-md5"); | ||
| 165 | #endif | ||
| 166 | #ifndef NO_SHA | ||
| 167 | EVP_add_digest(EVP_sha()); | ||
| 168 | #ifndef NO_DSA | ||
| 169 | EVP_add_digest(EVP_dss()); | ||
| 170 | #endif | ||
| 171 | #endif | ||
| 172 | #ifndef NO_SHA1 | ||
| 173 | EVP_add_digest(EVP_sha1()); | ||
| 174 | EVP_add_alias(SN_sha1,"ssl3-sha1"); | ||
| 175 | #ifndef NO_DSA | ||
| 176 | EVP_add_digest(EVP_dss1()); | ||
| 177 | EVP_add_alias(SN_dsaWithSHA1,SN_dsaWithSHA1_2); | ||
| 178 | EVP_add_alias(SN_dsaWithSHA1,"DSS1"); | ||
| 179 | EVP_add_alias(SN_dsaWithSHA1,"dss1"); | ||
| 180 | #endif | ||
| 181 | #endif | ||
| 182 | #if !defined(NO_MDC2) && !defined(NO_DES) | ||
| 183 | EVP_add_digest(EVP_mdc2()); | ||
| 184 | #endif | ||
| 185 | #ifndef NO_RIPEMD160 | ||
| 186 | EVP_add_digest(EVP_ripemd160()); | ||
| 187 | EVP_add_alias(SN_ripemd160,"ripemd"); | ||
| 188 | EVP_add_alias(SN_ripemd160,"rmd160"); | ||
| 189 | #endif | ||
| 190 | } | ||
diff --git a/src/lib/libcrypto/evp/digest.c b/src/lib/libcrypto/evp/digest.c new file mode 100644 index 0000000000..d65f0036f7 --- /dev/null +++ b/src/lib/libcrypto/evp/digest.c | |||
| @@ -0,0 +1,89 @@ | |||
| 1 | /* crypto/evp/digest.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 "objects.h" | ||
| 62 | #include "evp.h" | ||
| 63 | |||
| 64 | void EVP_DigestInit(ctx,type) | ||
| 65 | EVP_MD_CTX *ctx; | ||
| 66 | EVP_MD *type; | ||
| 67 | { | ||
| 68 | ctx->digest=type; | ||
| 69 | type->init(&(ctx->md)); | ||
| 70 | } | ||
| 71 | |||
| 72 | void EVP_DigestUpdate(ctx,data,count) | ||
| 73 | EVP_MD_CTX *ctx; | ||
| 74 | unsigned char *data; | ||
| 75 | unsigned int count; | ||
| 76 | { | ||
| 77 | ctx->digest->update(&(ctx->md.base[0]),data,(unsigned long)count); | ||
| 78 | } | ||
| 79 | |||
| 80 | void EVP_DigestFinal(ctx,md,size) | ||
| 81 | EVP_MD_CTX *ctx; | ||
| 82 | unsigned char *md; | ||
| 83 | unsigned int *size; | ||
| 84 | { | ||
| 85 | ctx->digest->final(md,&(ctx->md.base[0])); | ||
| 86 | if (size != NULL) | ||
| 87 | *size=ctx->digest->md_size; | ||
| 88 | memset(&(ctx->md),0,sizeof(ctx->md)); | ||
| 89 | } | ||
diff --git a/src/lib/libcrypto/evp/e_null.c b/src/lib/libcrypto/evp/e_null.c new file mode 100644 index 0000000000..e4e7ca7606 --- /dev/null +++ b/src/lib/libcrypto/evp/e_null.c | |||
| @@ -0,0 +1,109 @@ | |||
| 1 | /* crypto/evp/e_null.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 "evp.h" | ||
| 62 | #include "objects.h" | ||
| 63 | |||
| 64 | #ifndef NOPROTO | ||
| 65 | static void null_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, | ||
| 66 | unsigned char *iv,int enc); | ||
| 67 | static void null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
| 68 | unsigned char *in, unsigned int inl); | ||
| 69 | #else | ||
| 70 | static void null_init_key(); | ||
| 71 | static void null_cipher(); | ||
| 72 | #endif | ||
| 73 | |||
| 74 | static EVP_CIPHER n_cipher= | ||
| 75 | { | ||
| 76 | NID_undef, | ||
| 77 | 1,0,0, | ||
| 78 | null_init_key, | ||
| 79 | null_cipher, | ||
| 80 | NULL, | ||
| 81 | 0, | ||
| 82 | NULL, | ||
| 83 | NULL, | ||
| 84 | }; | ||
| 85 | |||
| 86 | EVP_CIPHER *EVP_enc_null() | ||
| 87 | { | ||
| 88 | return(&n_cipher); | ||
| 89 | } | ||
| 90 | |||
| 91 | static void null_init_key(ctx,key,iv,enc) | ||
| 92 | EVP_CIPHER_CTX *ctx; | ||
| 93 | unsigned char *key; | ||
| 94 | unsigned char *iv; | ||
| 95 | int enc; | ||
| 96 | { | ||
| 97 | memset(&(ctx->c),0,sizeof(ctx->c)); | ||
| 98 | } | ||
| 99 | |||
| 100 | static void null_cipher(ctx,out,in,inl) | ||
| 101 | EVP_CIPHER_CTX *ctx; | ||
| 102 | unsigned char *out; | ||
| 103 | unsigned char *in; | ||
| 104 | unsigned int inl; | ||
| 105 | { | ||
| 106 | if (in != out) | ||
| 107 | memcpy((char *)out,(char *)in,(int)inl); | ||
| 108 | } | ||
| 109 | |||
diff --git a/src/lib/libcrypto/evp/e_rc4.c b/src/lib/libcrypto/evp/e_rc4.c new file mode 100644 index 0000000000..7e9790a94c --- /dev/null +++ b/src/lib/libcrypto/evp/e_rc4.c | |||
| @@ -0,0 +1,127 @@ | |||
| 1 | /* crypto/evp/e_rc4.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 | #ifndef NO_RC4 | ||
| 60 | |||
| 61 | #include <stdio.h> | ||
| 62 | #include "cryptlib.h" | ||
| 63 | #include "evp.h" | ||
| 64 | #include "objects.h" | ||
| 65 | |||
| 66 | #ifndef NOPROTO | ||
| 67 | static void rc4_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, | ||
| 68 | unsigned char *iv,int enc); | ||
| 69 | static void rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
| 70 | unsigned char *in, unsigned int inl); | ||
| 71 | #else | ||
| 72 | static void rc4_init_key(); | ||
| 73 | static void rc4_cipher(); | ||
| 74 | #endif | ||
| 75 | |||
| 76 | static EVP_CIPHER r4_cipher= | ||
| 77 | { | ||
| 78 | NID_rc4, | ||
| 79 | 1,EVP_RC4_KEY_SIZE,0, | ||
| 80 | rc4_init_key, | ||
| 81 | rc4_cipher, | ||
| 82 | NULL, | ||
| 83 | sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ | ||
| 84 | sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc4)), | ||
| 85 | NULL, | ||
| 86 | NULL, | ||
| 87 | }; | ||
| 88 | |||
| 89 | static EVP_CIPHER r4_40_cipher= | ||
| 90 | { | ||
| 91 | NID_rc4_40, | ||
| 92 | 1,5 /* 40 bit */,0, | ||
| 93 | rc4_init_key, | ||
| 94 | rc4_cipher, | ||
| 95 | }; | ||
| 96 | |||
| 97 | EVP_CIPHER *EVP_rc4() | ||
| 98 | { | ||
| 99 | return(&r4_cipher); | ||
| 100 | } | ||
| 101 | |||
| 102 | EVP_CIPHER *EVP_rc4_40() | ||
| 103 | { | ||
| 104 | return(&r4_40_cipher); | ||
| 105 | } | ||
| 106 | |||
| 107 | static void rc4_init_key(ctx,key,iv,enc) | ||
| 108 | EVP_CIPHER_CTX *ctx; | ||
| 109 | unsigned char *key; | ||
| 110 | unsigned char *iv; | ||
| 111 | int enc; | ||
| 112 | { | ||
| 113 | if (key != NULL) | ||
| 114 | memcpy(&(ctx->c.rc4.key[0]),key,EVP_CIPHER_CTX_key_length(ctx)); | ||
| 115 | RC4_set_key(&(ctx->c.rc4.ks),EVP_CIPHER_CTX_key_length(ctx), | ||
| 116 | ctx->c.rc4.key); | ||
| 117 | } | ||
| 118 | |||
| 119 | static void rc4_cipher(ctx,out,in,inl) | ||
| 120 | EVP_CIPHER_CTX *ctx; | ||
| 121 | unsigned char *out; | ||
| 122 | unsigned char *in; | ||
| 123 | unsigned int inl; | ||
| 124 | { | ||
| 125 | RC4(&(ctx->c.rc4.ks),inl,in,out); | ||
| 126 | } | ||
| 127 | #endif | ||
diff --git a/src/lib/libcrypto/evp/e_xcbc_d.c b/src/lib/libcrypto/evp/e_xcbc_d.c new file mode 100644 index 0000000000..0d7fda0c47 --- /dev/null +++ b/src/lib/libcrypto/evp/e_xcbc_d.c | |||
| @@ -0,0 +1,122 @@ | |||
| 1 | /* crypto/evp/e_xcbc_d.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 "evp.h" | ||
| 62 | #include "objects.h" | ||
| 63 | |||
| 64 | #ifndef NOPROTO | ||
| 65 | static void desx_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, | ||
| 66 | unsigned char *iv,int enc); | ||
| 67 | static void desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
| 68 | unsigned char *in, unsigned int inl); | ||
| 69 | #else | ||
| 70 | static void desx_cbc_init_key(); | ||
| 71 | static void desx_cbc_cipher(); | ||
| 72 | #endif | ||
| 73 | |||
| 74 | static EVP_CIPHER d_xcbc_cipher= | ||
| 75 | { | ||
| 76 | NID_desx_cbc, | ||
| 77 | 8,24,8, | ||
| 78 | desx_cbc_init_key, | ||
| 79 | desx_cbc_cipher, | ||
| 80 | NULL, | ||
| 81 | sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ | ||
| 82 | sizeof((((EVP_CIPHER_CTX *)NULL)->c.desx_cbc)), | ||
| 83 | EVP_CIPHER_set_asn1_iv, | ||
| 84 | EVP_CIPHER_get_asn1_iv, | ||
| 85 | }; | ||
| 86 | |||
| 87 | EVP_CIPHER *EVP_desx_cbc() | ||
| 88 | { | ||
| 89 | return(&d_xcbc_cipher); | ||
| 90 | } | ||
| 91 | |||
| 92 | static void desx_cbc_init_key(ctx,key,iv,enc) | ||
| 93 | EVP_CIPHER_CTX *ctx; | ||
| 94 | unsigned char *key; | ||
| 95 | unsigned char *iv; | ||
| 96 | int enc; | ||
| 97 | { | ||
| 98 | if (iv != NULL) | ||
| 99 | memcpy(&(ctx->oiv[0]),iv,8); | ||
| 100 | memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); | ||
| 101 | if (key != NULL) | ||
| 102 | { | ||
| 103 | des_set_key((des_cblock *)key,ctx->c.desx_cbc.ks); | ||
| 104 | memcpy(&(ctx->c.desx_cbc.inw[0]),&(key[8]),8); | ||
| 105 | memcpy(&(ctx->c.desx_cbc.outw[0]),&(key[16]),8); | ||
| 106 | } | ||
| 107 | } | ||
| 108 | |||
| 109 | static void desx_cbc_cipher(ctx,out,in,inl) | ||
| 110 | EVP_CIPHER_CTX *ctx; | ||
| 111 | unsigned char *out; | ||
| 112 | unsigned char *in; | ||
| 113 | unsigned int inl; | ||
| 114 | { | ||
| 115 | des_xcbc_encrypt( | ||
| 116 | (des_cblock *)in,(des_cblock *)out, | ||
| 117 | (long)inl, ctx->c.desx_cbc.ks, | ||
| 118 | (des_cblock *)&(ctx->iv[0]), | ||
| 119 | (des_cblock *)&(ctx->c.desx_cbc.inw[0]), | ||
| 120 | (des_cblock *)&(ctx->c.desx_cbc.outw[0]), | ||
| 121 | ctx->encrypt); | ||
| 122 | } | ||
diff --git a/src/lib/libcrypto/evp/encode.c b/src/lib/libcrypto/evp/encode.c new file mode 100644 index 0000000000..14d47c1eed --- /dev/null +++ b/src/lib/libcrypto/evp/encode.c | |||
| @@ -0,0 +1,438 @@ | |||
| 1 | /* crypto/evp/encode.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 "evp.h" | ||
| 62 | |||
| 63 | #define conv_bin2ascii(a) (data_bin2ascii[(a)&0x3f]) | ||
| 64 | #define conv_ascii2bin(a) (data_ascii2bin[(a)&0x7f]) | ||
| 65 | |||
| 66 | /* 64 char lines | ||
| 67 | * pad input with 0 | ||
| 68 | * left over chars are set to = | ||
| 69 | * 1 byte => xx== | ||
| 70 | * 2 bytes => xxx= | ||
| 71 | * 3 bytes => xxxx | ||
| 72 | */ | ||
| 73 | #define BIN_PER_LINE (64/4*3) | ||
| 74 | #define CHUNKS_PER_LINE (64/4) | ||
| 75 | #define CHAR_PER_LINE (64+1) | ||
| 76 | |||
| 77 | static unsigned char data_bin2ascii[65]="ABCDEFGHIJKLMNOPQRSTUVWXYZ\ | ||
| 78 | abcdefghijklmnopqrstuvwxyz0123456789+/"; | ||
| 79 | |||
| 80 | /* 0xF0 is a EOLN | ||
| 81 | * 0xF1 is ignore but next needs to be 0xF0 (for \r\n processing). | ||
| 82 | * 0xF2 is EOF | ||
| 83 | * 0xE0 is ignore at start of line. | ||
| 84 | * 0xFF is error | ||
| 85 | */ | ||
| 86 | |||
| 87 | #define B64_EOLN 0xF0 | ||
| 88 | #define B64_CR 0xF1 | ||
| 89 | #define B64_EOF 0xF2 | ||
| 90 | #define B64_WS 0xE0 | ||
| 91 | #define B64_ERROR 0xFF | ||
| 92 | #define B64_NOT_BASE64(a) (((a)|0x13) == 0xF3) | ||
| 93 | |||
| 94 | static unsigned char data_ascii2bin[128]={ | ||
| 95 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, | ||
| 96 | 0xFF,0xE0,0xF0,0xFF,0xFF,0xF1,0xFF,0xFF, | ||
| 97 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, | ||
| 98 | 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, | ||
| 99 | 0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, | ||
| 100 | 0xFF,0xFF,0xFF,0x3E,0xFF,0xF2,0xFF,0x3F, | ||
| 101 | 0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B, | ||
| 102 | 0x3C,0x3D,0xFF,0xFF,0xFF,0x00,0xFF,0xFF, | ||
| 103 | 0xFF,0x00,0x01,0x02,0x03,0x04,0x05,0x06, | ||
| 104 | 0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E, | ||
| 105 | 0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16, | ||
| 106 | 0x17,0x18,0x19,0xFF,0xFF,0xFF,0xFF,0xFF, | ||
| 107 | 0xFF,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20, | ||
| 108 | 0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28, | ||
| 109 | 0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30, | ||
| 110 | 0x31,0x32,0x33,0xFF,0xFF,0xFF,0xFF,0xFF, | ||
| 111 | }; | ||
| 112 | |||
| 113 | void EVP_EncodeInit(ctx) | ||
| 114 | EVP_ENCODE_CTX *ctx; | ||
| 115 | { | ||
| 116 | ctx->length=48; | ||
| 117 | ctx->num=0; | ||
| 118 | ctx->line_num=0; | ||
| 119 | } | ||
| 120 | |||
| 121 | void EVP_EncodeUpdate(ctx,out,outl,in,inl) | ||
| 122 | EVP_ENCODE_CTX *ctx; | ||
| 123 | unsigned char *out; | ||
| 124 | int *outl; | ||
| 125 | unsigned char *in; | ||
| 126 | int inl; | ||
| 127 | { | ||
| 128 | int i,j; | ||
| 129 | unsigned int total=0; | ||
| 130 | |||
| 131 | *outl=0; | ||
| 132 | if (inl == 0) return; | ||
| 133 | if ((ctx->num+inl) < ctx->length) | ||
| 134 | { | ||
| 135 | memcpy(&(ctx->enc_data[ctx->num]),in,inl); | ||
| 136 | ctx->num+=inl; | ||
| 137 | return; | ||
| 138 | } | ||
| 139 | if (ctx->num != 0) | ||
| 140 | { | ||
| 141 | i=ctx->length-ctx->num; | ||
| 142 | memcpy(&(ctx->enc_data[ctx->num]),in,i); | ||
| 143 | in+=i; | ||
| 144 | inl-=i; | ||
| 145 | j=EVP_EncodeBlock(out,ctx->enc_data,ctx->length); | ||
| 146 | ctx->num=0; | ||
| 147 | out+=j; | ||
| 148 | *(out++)='\n'; | ||
| 149 | *out='\0'; | ||
| 150 | total=j+1; | ||
| 151 | } | ||
| 152 | while (inl >= ctx->length) | ||
| 153 | { | ||
| 154 | j=EVP_EncodeBlock(out,in,ctx->length); | ||
| 155 | in+=ctx->length; | ||
| 156 | inl-=ctx->length; | ||
| 157 | out+=j; | ||
| 158 | *(out++)='\n'; | ||
| 159 | *out='\0'; | ||
| 160 | total+=j+1; | ||
| 161 | } | ||
| 162 | if (inl != 0) | ||
| 163 | memcpy(&(ctx->enc_data[0]),in,inl); | ||
| 164 | ctx->num=inl; | ||
| 165 | *outl=total; | ||
| 166 | } | ||
| 167 | |||
| 168 | void EVP_EncodeFinal(ctx,out,outl) | ||
| 169 | EVP_ENCODE_CTX *ctx; | ||
| 170 | unsigned char *out; | ||
| 171 | int *outl; | ||
| 172 | { | ||
| 173 | unsigned int ret=0; | ||
| 174 | |||
| 175 | if (ctx->num != 0) | ||
| 176 | { | ||
| 177 | ret=EVP_EncodeBlock(out,ctx->enc_data,ctx->num); | ||
| 178 | out[ret++]='\n'; | ||
| 179 | out[ret]='\0'; | ||
| 180 | ctx->num=0; | ||
| 181 | } | ||
| 182 | *outl=ret; | ||
| 183 | } | ||
| 184 | |||
| 185 | int EVP_EncodeBlock(t,f,dlen) | ||
| 186 | unsigned char *t,*f; | ||
| 187 | int dlen; | ||
| 188 | { | ||
| 189 | int i,ret=0; | ||
| 190 | unsigned long l; | ||
| 191 | |||
| 192 | for (i=dlen; i > 0; i-=3) | ||
| 193 | { | ||
| 194 | if (i >= 3) | ||
| 195 | { | ||
| 196 | l= (((unsigned long)f[0])<<16L)| | ||
| 197 | (((unsigned long)f[1])<< 8L)|f[2]; | ||
| 198 | *(t++)=conv_bin2ascii(l>>18L); | ||
| 199 | *(t++)=conv_bin2ascii(l>>12L); | ||
| 200 | *(t++)=conv_bin2ascii(l>> 6L); | ||
| 201 | *(t++)=conv_bin2ascii(l ); | ||
| 202 | } | ||
| 203 | else | ||
| 204 | { | ||
| 205 | l=((unsigned long)f[0])<<16L; | ||
| 206 | if (i == 2) l|=((unsigned long)f[1]<<8L); | ||
| 207 | |||
| 208 | *(t++)=conv_bin2ascii(l>>18L); | ||
| 209 | *(t++)=conv_bin2ascii(l>>12L); | ||
| 210 | *(t++)=(i == 1)?'=':conv_bin2ascii(l>> 6L); | ||
| 211 | *(t++)='='; | ||
| 212 | } | ||
| 213 | ret+=4; | ||
| 214 | f+=3; | ||
| 215 | } | ||
| 216 | |||
| 217 | *t='\0'; | ||
| 218 | return(ret); | ||
| 219 | } | ||
| 220 | |||
| 221 | void EVP_DecodeInit(ctx) | ||
| 222 | EVP_ENCODE_CTX *ctx; | ||
| 223 | { | ||
| 224 | ctx->length=30; | ||
| 225 | ctx->num=0; | ||
| 226 | ctx->line_num=0; | ||
| 227 | ctx->expect_nl=0; | ||
| 228 | } | ||
| 229 | |||
| 230 | /* -1 for error | ||
| 231 | * 0 for last line | ||
| 232 | * 1 for full line | ||
| 233 | */ | ||
| 234 | int EVP_DecodeUpdate(ctx,out,outl,in,inl) | ||
| 235 | EVP_ENCODE_CTX *ctx; | ||
| 236 | unsigned char *out; | ||
| 237 | int *outl; | ||
| 238 | unsigned char *in; | ||
| 239 | int inl; | ||
| 240 | { | ||
| 241 | int seof= -1,eof=0,rv= -1,ret=0,i,v,tmp,n,ln,tmp2,exp_nl; | ||
| 242 | unsigned char *d; | ||
| 243 | |||
| 244 | n=ctx->num; | ||
| 245 | d=ctx->enc_data; | ||
| 246 | ln=ctx->line_num; | ||
| 247 | exp_nl=ctx->expect_nl; | ||
| 248 | |||
| 249 | /* last line of input. */ | ||
| 250 | if ((inl == 0) || ((n == 0) && (conv_ascii2bin(in[0]) == B64_EOF))) | ||
| 251 | { rv=0; goto end; } | ||
| 252 | |||
| 253 | /* We parse the input data */ | ||
| 254 | for (i=0; i<inl; i++) | ||
| 255 | { | ||
| 256 | /* If the current line is > 80 characters, scream alot */ | ||
| 257 | if (ln >= 80) { rv= -1; goto end; } | ||
| 258 | |||
| 259 | /* Get char and put it into the buffer */ | ||
| 260 | tmp= *(in++); | ||
| 261 | v=conv_ascii2bin(tmp); | ||
| 262 | /* only save the good data :-) */ | ||
| 263 | if (!B64_NOT_BASE64(v)) | ||
| 264 | { | ||
| 265 | d[n++]=tmp; | ||
| 266 | ln++; | ||
| 267 | } | ||
| 268 | else if (v == B64_ERROR) | ||
| 269 | { | ||
| 270 | rv= -1; | ||
| 271 | goto end; | ||
| 272 | } | ||
| 273 | |||
| 274 | /* have we seen a '=' which is 'definitly' the last | ||
| 275 | * input line. seof will point to the character that | ||
| 276 | * holds it. and eof will hold how many characters to | ||
| 277 | * chop off. */ | ||
| 278 | if (tmp == '=') | ||
| 279 | { | ||
| 280 | if (seof == -1) seof=n; | ||
| 281 | eof++; | ||
| 282 | } | ||
| 283 | |||
| 284 | /* eoln */ | ||
| 285 | if (v == B64_EOLN) | ||
| 286 | { | ||
| 287 | ln=0; | ||
| 288 | if (exp_nl) | ||
| 289 | { | ||
| 290 | exp_nl=0; | ||
| 291 | continue; | ||
| 292 | } | ||
| 293 | } | ||
| 294 | exp_nl=0; | ||
| 295 | |||
| 296 | /* If we are at the end of input and it looks like a | ||
| 297 | * line, process it. */ | ||
| 298 | if (((i+1) == inl) && (((n&3) == 0) || eof)) | ||
| 299 | v=B64_EOF; | ||
| 300 | |||
| 301 | if ((v == B64_EOF) || (n >= 64)) | ||
| 302 | { | ||
| 303 | /* This is needed to work correctly on 64 byte input | ||
| 304 | * lines. We process the line and then need to | ||
| 305 | * accept the '\n' */ | ||
| 306 | if ((v != B64_EOF) && (n >= 64)) exp_nl=1; | ||
| 307 | tmp2=v; | ||
| 308 | if (n > 0) | ||
| 309 | { | ||
| 310 | v=EVP_DecodeBlock(out,d,n); | ||
| 311 | if (v < 0) { rv=0; goto end; } | ||
| 312 | n=0; | ||
| 313 | ret+=(v-eof); | ||
| 314 | } | ||
| 315 | else | ||
| 316 | { | ||
| 317 | eof=1; | ||
| 318 | v=0; | ||
| 319 | } | ||
| 320 | |||
| 321 | /* This is the case where we have had a short | ||
| 322 | * but valid input line */ | ||
| 323 | if ((v < ctx->length) && eof) | ||
| 324 | { | ||
| 325 | rv=0; | ||
| 326 | goto end; | ||
| 327 | } | ||
| 328 | else | ||
| 329 | ctx->length=v; | ||
| 330 | |||
| 331 | if (seof >= 0) { rv=0; goto end; } | ||
| 332 | out+=v; | ||
| 333 | } | ||
| 334 | } | ||
| 335 | rv=1; | ||
| 336 | end: | ||
| 337 | *outl=ret; | ||
| 338 | ctx->num=n; | ||
| 339 | ctx->line_num=ln; | ||
| 340 | ctx->expect_nl=exp_nl; | ||
| 341 | return(rv); | ||
| 342 | } | ||
| 343 | |||
| 344 | int EVP_DecodeBlock(t,f,n) | ||
| 345 | unsigned char *t,*f; | ||
| 346 | int n; | ||
| 347 | { | ||
| 348 | int i,ret=0,a,b,c,d; | ||
| 349 | unsigned long l; | ||
| 350 | |||
| 351 | /* trim white space from the start of the line. */ | ||
| 352 | while ((conv_ascii2bin(*f) == B64_WS) && (n > 0)) | ||
| 353 | { | ||
| 354 | f++; | ||
| 355 | n--; | ||
| 356 | } | ||
| 357 | |||
| 358 | /* strip off stuff at the end of the line | ||
| 359 | * ascii2bin values B64_WS, B64_EOLN, B64_EOLN and B64_EOF */ | ||
| 360 | while ((n > 3) && (B64_NOT_BASE64(conv_ascii2bin(f[n-1])))) | ||
| 361 | n--; | ||
| 362 | |||
| 363 | if (n%4 != 0) return(-1); | ||
| 364 | |||
| 365 | for (i=0; i<n; i+=4) | ||
| 366 | { | ||
| 367 | a=conv_ascii2bin(*(f++)); | ||
| 368 | b=conv_ascii2bin(*(f++)); | ||
| 369 | c=conv_ascii2bin(*(f++)); | ||
| 370 | d=conv_ascii2bin(*(f++)); | ||
| 371 | if ( (a & 0x80) || (b & 0x80) || | ||
| 372 | (c & 0x80) || (d & 0x80)) | ||
| 373 | return(-1); | ||
| 374 | l=( (((unsigned long)a)<<18L)| | ||
| 375 | (((unsigned long)b)<<12L)| | ||
| 376 | (((unsigned long)c)<< 6L)| | ||
| 377 | (((unsigned long)d) )); | ||
| 378 | *(t++)=(unsigned char)(l>>16L)&0xff; | ||
| 379 | *(t++)=(unsigned char)(l>> 8L)&0xff; | ||
| 380 | *(t++)=(unsigned char)(l )&0xff; | ||
| 381 | ret+=3; | ||
| 382 | } | ||
| 383 | return(ret); | ||
| 384 | } | ||
| 385 | |||
| 386 | int EVP_DecodeFinal(ctx,out,outl) | ||
| 387 | EVP_ENCODE_CTX *ctx; | ||
| 388 | unsigned char *out; | ||
| 389 | int *outl; | ||
| 390 | { | ||
| 391 | int i; | ||
| 392 | |||
| 393 | *outl=0; | ||
| 394 | if (ctx->num != 0) | ||
| 395 | { | ||
| 396 | i=EVP_DecodeBlock(out,ctx->enc_data,ctx->num); | ||
| 397 | if (i < 0) return(-1); | ||
| 398 | ctx->num=0; | ||
| 399 | *outl=i; | ||
| 400 | return(1); | ||
| 401 | } | ||
| 402 | else | ||
| 403 | return(1); | ||
| 404 | } | ||
| 405 | |||
| 406 | #ifdef undef | ||
| 407 | int EVP_DecodeValid(buf,len) | ||
| 408 | unsigned char *buf; | ||
| 409 | int len; | ||
| 410 | { | ||
| 411 | int i,num=0,bad=0; | ||
| 412 | |||
| 413 | if (len == 0) return(-1); | ||
| 414 | while (conv_ascii2bin(*buf) == B64_WS) | ||
| 415 | { | ||
| 416 | buf++; | ||
| 417 | len--; | ||
| 418 | if (len == 0) return(-1); | ||
| 419 | } | ||
| 420 | |||
| 421 | for (i=len; i >= 4; i-=4) | ||
| 422 | { | ||
| 423 | if ( (conv_ascii2bin(buf[0]) >= 0x40) || | ||
| 424 | (conv_ascii2bin(buf[1]) >= 0x40) || | ||
| 425 | (conv_ascii2bin(buf[2]) >= 0x40) || | ||
| 426 | (conv_ascii2bin(buf[3]) >= 0x40)) | ||
| 427 | return(-1); | ||
| 428 | buf+=4; | ||
| 429 | num+=1+(buf[2] != '=')+(buf[3] != '='); | ||
| 430 | } | ||
| 431 | if ((i == 1) && (conv_ascii2bin(buf[0]) == B64_EOLN)) | ||
| 432 | return(num); | ||
| 433 | if ((i == 2) && (conv_ascii2bin(buf[0]) == B64_EOLN) && | ||
| 434 | (conv_ascii2bin(buf[0]) == B64_EOLN)) | ||
| 435 | return(num); | ||
| 436 | return(1); | ||
| 437 | } | ||
| 438 | #endif | ||
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h new file mode 100644 index 0000000000..b39fad93a4 --- /dev/null +++ b/src/lib/libcrypto/evp/evp.h | |||
| @@ -0,0 +1,793 @@ | |||
| 1 | /* crypto/evp/evp.h */ | ||
| 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 | #ifndef HEADER_ENVELOPE_H | ||
| 60 | #define HEADER_ENVELOPE_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #ifndef NO_MD2 | ||
| 67 | #include "md2.h" | ||
| 68 | #endif | ||
| 69 | #ifndef NO_MD5 | ||
| 70 | #include "md5.h" | ||
| 71 | #endif | ||
| 72 | #if !defined(NO_SHA) || !defined(NO_SHA1) | ||
| 73 | #include "sha.h" | ||
| 74 | #endif | ||
| 75 | #ifndef NO_RIPEMD | ||
| 76 | #include "ripemd.h" | ||
| 77 | #endif | ||
| 78 | #ifndef NO_DES | ||
| 79 | #include "des.h" | ||
| 80 | #endif | ||
| 81 | #ifndef NO_RC4 | ||
| 82 | #include "rc4.h" | ||
| 83 | #endif | ||
| 84 | #ifndef NO_RC2 | ||
| 85 | #include "rc2.h" | ||
| 86 | #endif | ||
| 87 | #ifndef NO_RC5 | ||
| 88 | #include "rc5.h" | ||
| 89 | #endif | ||
| 90 | #ifndef NO_BLOWFISH | ||
| 91 | #include "blowfish.h" | ||
| 92 | #endif | ||
| 93 | #ifndef NO_CAST | ||
| 94 | #include "cast.h" | ||
| 95 | #endif | ||
| 96 | #ifndef NO_IDEA | ||
| 97 | #include "idea.h" | ||
| 98 | #endif | ||
| 99 | #ifndef NO_MDC2 | ||
| 100 | #include "mdc2.h" | ||
| 101 | #endif | ||
| 102 | |||
| 103 | #define EVP_RC2_KEY_SIZE 16 | ||
| 104 | #define EVP_RC4_KEY_SIZE 16 | ||
| 105 | #define EVP_BLOWFISH_KEY_SIZE 16 | ||
| 106 | #define EVP_CAST5_KEY_SIZE 16 | ||
| 107 | #define EVP_RC5_32_12_16_KEY_SIZE 16 | ||
| 108 | #define EVP_MAX_MD_SIZE (16+20) /* The SSLv3 md5+sha1 type */ | ||
| 109 | #define EVP_MAX_KEY_LENGTH 24 | ||
| 110 | #define EVP_MAX_IV_LENGTH 8 | ||
| 111 | |||
| 112 | #ifndef NO_RSA | ||
| 113 | #include "rsa.h" | ||
| 114 | #else | ||
| 115 | #define RSA long | ||
| 116 | #endif | ||
| 117 | |||
| 118 | #ifndef NO_DSA | ||
| 119 | #include "dsa.h" | ||
| 120 | #else | ||
| 121 | #define DSA long | ||
| 122 | #endif | ||
| 123 | |||
| 124 | #ifndef NO_DH | ||
| 125 | #include "dh.h" | ||
| 126 | #else | ||
| 127 | #define DH long | ||
| 128 | #endif | ||
| 129 | |||
| 130 | #include "objects.h" | ||
| 131 | |||
| 132 | #define EVP_PK_RSA 0x0001 | ||
| 133 | #define EVP_PK_DSA 0x0002 | ||
| 134 | #define EVP_PK_DH 0x0004 | ||
| 135 | #define EVP_PKT_SIGN 0x0010 | ||
| 136 | #define EVP_PKT_ENC 0x0020 | ||
| 137 | #define EVP_PKT_EXCH 0x0040 | ||
| 138 | #define EVP_PKS_RSA 0x0100 | ||
| 139 | #define EVP_PKS_DSA 0x0200 | ||
| 140 | #define EVP_PKT_EXP 0x1000 /* <= 512 bit key */ | ||
| 141 | |||
| 142 | #define EVP_PKEY_NONE NID_undef | ||
| 143 | #define EVP_PKEY_RSA NID_rsaEncryption | ||
| 144 | #define EVP_PKEY_RSA2 NID_rsa | ||
| 145 | #define EVP_PKEY_DSA NID_dsa | ||
| 146 | #define EVP_PKEY_DSA1 NID_dsa_2 | ||
| 147 | #define EVP_PKEY_DSA2 NID_dsaWithSHA | ||
| 148 | #define EVP_PKEY_DSA3 NID_dsaWithSHA1 | ||
| 149 | #define EVP_PKEY_DSA4 NID_dsaWithSHA1_2 | ||
| 150 | #define EVP_PKEY_DH NID_dhKeyAgreement | ||
| 151 | |||
| 152 | /* Type needs to be a bit field | ||
| 153 | * Sub-type needs to be for variations on the method, as in, can it do | ||
| 154 | * arbitary encryption.... */ | ||
| 155 | typedef struct evp_pkey_st | ||
| 156 | { | ||
| 157 | int type; | ||
| 158 | int save_type; | ||
| 159 | int references; | ||
| 160 | union { | ||
| 161 | char *ptr; | ||
| 162 | struct rsa_st *rsa; /* RSA */ | ||
| 163 | struct dsa_st *dsa; /* DSA */ | ||
| 164 | struct dh_st *dh; /* DH */ | ||
| 165 | } pkey; | ||
| 166 | int save_parameters; | ||
| 167 | #ifdef HEADER_STACK_H | ||
| 168 | STACK /* X509_ATTRIBUTE */ *attributes; /* [ 0 ] */ | ||
| 169 | #else | ||
| 170 | char /* X509_ATTRIBUTE */ *attributes; /* [ 0 ] */ | ||
| 171 | #endif | ||
| 172 | } EVP_PKEY; | ||
| 173 | |||
| 174 | #define EVP_PKEY_MO_SIGN 0x0001 | ||
| 175 | #define EVP_PKEY_MO_VERIFY 0x0002 | ||
| 176 | #define EVP_PKEY_MO_ENCRYPT 0x0004 | ||
| 177 | #define EVP_PKEY_MO_DECRYPT 0x0008 | ||
| 178 | |||
| 179 | #if 0 | ||
| 180 | /* This structure is required to tie the message digest and signing together. | ||
| 181 | * The lookup can be done by md/pkey_method, oid, oid/pkey_method, or | ||
| 182 | * oid, md and pkey. | ||
| 183 | * This is required because for various smart-card perform the digest and | ||
| 184 | * signing/verification on-board. To handle this case, the specific | ||
| 185 | * EVP_MD and EVP_PKEY_METHODs need to be closely associated. | ||
| 186 | * When a PKEY is created, it will have a EVP_PKEY_METHOD ossociated with it. | ||
| 187 | * This can either be software or a token to provide the required low level | ||
| 188 | * routines. | ||
| 189 | */ | ||
| 190 | typedef struct evp_pkey_md_st | ||
| 191 | { | ||
| 192 | int oid; | ||
| 193 | EVP_MD *md; | ||
| 194 | EVP_PKEY_METHOD *pkey; | ||
| 195 | } EVP_PKEY_MD; | ||
| 196 | |||
| 197 | #define EVP_rsa_md2() | ||
| 198 | EVP_PKEY_MD_add(NID_md2WithRSAEncryption,\ | ||
| 199 | EVP_rsa_pkcs1(),EVP_md2()) | ||
| 200 | #define EVP_rsa_md5() | ||
| 201 | EVP_PKEY_MD_add(NID_md5WithRSAEncryption,\ | ||
| 202 | EVP_rsa_pkcs1(),EVP_md5()) | ||
| 203 | #define EVP_rsa_sha0() | ||
| 204 | EVP_PKEY_MD_add(NID_shaWithRSAEncryption,\ | ||
| 205 | EVP_rsa_pkcs1(),EVP_sha()) | ||
| 206 | #define EVP_rsa_sha1() | ||
| 207 | EVP_PKEY_MD_add(NID_sha1WithRSAEncryption,\ | ||
| 208 | EVP_rsa_pkcs1(),EVP_sha1()) | ||
| 209 | #define EVP_rsa_ripemd160() | ||
| 210 | EVP_PKEY_MD_add(NID_ripemd160WithRSA,\ | ||
| 211 | EVP_rsa_pkcs1(),EVP_ripemd160()) | ||
| 212 | #define EVP_rsa_mdc2() | ||
| 213 | EVP_PKEY_MD_add(NID_mdc2WithRSA,\ | ||
| 214 | EVP_rsa_octet_string(),EVP_mdc2()) | ||
| 215 | #define EVP_dsa_sha() | ||
| 216 | EVP_PKEY_MD_add(NID_dsaWithSHA,\ | ||
| 217 | EVP_dsa(),EVP_mdc2()) | ||
| 218 | #define EVP_dsa_sha1() | ||
| 219 | EVP_PKEY_MD_add(NID_dsaWithSHA1,\ | ||
| 220 | EVP_dsa(),EVP_sha1()) | ||
| 221 | |||
| 222 | typedef struct evp_pkey_method_st | ||
| 223 | { | ||
| 224 | char *name; | ||
| 225 | int flags; | ||
| 226 | int type; /* RSA, DSA, an SSLeay specific constant */ | ||
| 227 | int oid; /* For the pub-key type */ | ||
| 228 | int encrypt_oid; /* pub/priv key encryption */ | ||
| 229 | |||
| 230 | int (*sign)(); | ||
| 231 | int (*verify)(); | ||
| 232 | struct { | ||
| 233 | int | ||
| 234 | int (*set)(); /* get and/or set the underlying type */ | ||
| 235 | int (*get)(); | ||
| 236 | int (*encrypt)(); | ||
| 237 | int (*decrypt)(); | ||
| 238 | int (*i2d)(); | ||
| 239 | int (*d2i)(); | ||
| 240 | int (*dup)(); | ||
| 241 | } pub,priv; | ||
| 242 | int (*set_asn1_parameters)(); | ||
| 243 | int (*get_asn1_parameters)(); | ||
| 244 | } EVP_PKEY_METHOD; | ||
| 245 | #endif | ||
| 246 | |||
| 247 | #ifndef EVP_MD | ||
| 248 | typedef struct env_md_st | ||
| 249 | { | ||
| 250 | int type; | ||
| 251 | int pkey_type; | ||
| 252 | int md_size; | ||
| 253 | void (*init)(); | ||
| 254 | void (*update)(); | ||
| 255 | void (*final)(); | ||
| 256 | |||
| 257 | int (*sign)(); | ||
| 258 | int (*verify)(); | ||
| 259 | int required_pkey_type[5]; /*EVP_PKEY_xxx */ | ||
| 260 | int block_size; | ||
| 261 | int ctx_size; /* how big does the ctx need to be */ | ||
| 262 | } EVP_MD; | ||
| 263 | |||
| 264 | #define EVP_PKEY_NULL_method NULL,NULL,{0,0,0,0} | ||
| 265 | |||
| 266 | #ifndef NO_DSA | ||
| 267 | #define EVP_PKEY_DSA_method DSA_sign,DSA_verify, \ | ||
| 268 | {EVP_PKEY_DSA,EVP_PKEY_DSA2,EVP_PKEY_DSA3, \ | ||
| 269 | EVP_PKEY_DSA4,0} | ||
| 270 | #else | ||
| 271 | #define EVP_PKEY_DSA_method EVP_PKEY_NULL_method | ||
| 272 | #endif | ||
| 273 | |||
| 274 | #ifndef NO_RSA | ||
| 275 | #define EVP_PKEY_RSA_method RSA_sign,RSA_verify, \ | ||
| 276 | {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0} | ||
| 277 | #define EVP_PKEY_RSA_ASN1_OCTET_STRING_method \ | ||
| 278 | RSA_sign_ASN1_OCTET_STRING, \ | ||
| 279 | RSA_verify_ASN1_OCTET_STRING, \ | ||
| 280 | {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0} | ||
| 281 | #else | ||
| 282 | #define EVP_PKEY_RSA_method EVP_PKEY_NULL_method | ||
| 283 | #define EVP_PKEY_RSA_ASN1_OCTET_STRING_method EVP_PKEY_NULL_method | ||
| 284 | #endif | ||
| 285 | |||
| 286 | #endif /* !EVP_MD */ | ||
| 287 | |||
| 288 | typedef struct env_md_ctx_st | ||
| 289 | { | ||
| 290 | EVP_MD *digest; | ||
| 291 | union { | ||
| 292 | unsigned char base[4]; | ||
| 293 | #ifndef NO_MD2 | ||
| 294 | MD2_CTX md2; | ||
| 295 | #endif | ||
| 296 | #ifndef NO_MD5 | ||
| 297 | MD5_CTX md5; | ||
| 298 | #endif | ||
| 299 | #ifndef NO_MD5 | ||
| 300 | RIPEMD160_CTX ripemd160; | ||
| 301 | #endif | ||
| 302 | #if !defined(NO_SHA) || !defined(NO_SHA1) | ||
| 303 | SHA_CTX sha; | ||
| 304 | #endif | ||
| 305 | #ifndef NO_MDC2 | ||
| 306 | MDC2_CTX mdc2; | ||
| 307 | #endif | ||
| 308 | } md; | ||
| 309 | } EVP_MD_CTX; | ||
| 310 | |||
| 311 | typedef struct evp_cipher_st | ||
| 312 | { | ||
| 313 | int nid; | ||
| 314 | int block_size; | ||
| 315 | int key_len; | ||
| 316 | int iv_len; | ||
| 317 | void (*init)(); /* init for encryption */ | ||
| 318 | void (*do_cipher)(); /* encrypt data */ | ||
| 319 | void (*cleanup)(); /* used by cipher method */ | ||
| 320 | int ctx_size; /* how big the ctx needs to be */ | ||
| 321 | /* int set_asn1_parameters(EVP_CIPHER_CTX,ASN1_TYPE *); */ | ||
| 322 | int (*set_asn1_parameters)(); /* Populate a ASN1_TYPE with parameters */ | ||
| 323 | /* int get_asn1_parameters(EVP_CIPHER_CTX,ASN1_TYPE *); */ | ||
| 324 | int (*get_asn1_parameters)(); /* Get parameters from a ASN1_TYPE */ | ||
| 325 | } EVP_CIPHER; | ||
| 326 | |||
| 327 | typedef struct evp_cipher_info_st | ||
| 328 | { | ||
| 329 | EVP_CIPHER *cipher; | ||
| 330 | unsigned char iv[EVP_MAX_IV_LENGTH]; | ||
| 331 | } EVP_CIPHER_INFO; | ||
| 332 | |||
| 333 | typedef struct evp_cipher_ctx_st | ||
| 334 | { | ||
| 335 | EVP_CIPHER *cipher; | ||
| 336 | int encrypt; /* encrypt or decrypt */ | ||
| 337 | int buf_len; /* number we have left */ | ||
| 338 | |||
| 339 | unsigned char oiv[EVP_MAX_IV_LENGTH]; /* original iv */ | ||
| 340 | unsigned char iv[EVP_MAX_IV_LENGTH]; /* working iv */ | ||
| 341 | unsigned char buf[EVP_MAX_IV_LENGTH]; /* saved partial block */ | ||
| 342 | int num; /* used by cfb/ofb mode */ | ||
| 343 | |||
| 344 | char *app_data; /* aplication stuff */ | ||
| 345 | union { | ||
| 346 | #ifndef NO_RC4 | ||
| 347 | struct | ||
| 348 | { | ||
| 349 | unsigned char key[EVP_RC4_KEY_SIZE]; | ||
| 350 | RC4_KEY ks; /* working key */ | ||
| 351 | } rc4; | ||
| 352 | #endif | ||
| 353 | #ifndef NO_DES | ||
| 354 | des_key_schedule des_ks;/* key schedule */ | ||
| 355 | struct | ||
| 356 | { | ||
| 357 | des_key_schedule ks;/* key schedule */ | ||
| 358 | C_Block inw; | ||
| 359 | C_Block outw; | ||
| 360 | } desx_cbc; | ||
| 361 | struct | ||
| 362 | { | ||
| 363 | des_key_schedule ks1;/* key schedule */ | ||
| 364 | des_key_schedule ks2;/* key schedule (for ede) */ | ||
| 365 | des_key_schedule ks3;/* key schedule (for ede3) */ | ||
| 366 | } des_ede; | ||
| 367 | #endif | ||
| 368 | #ifndef NO_IDEA | ||
| 369 | IDEA_KEY_SCHEDULE idea_ks;/* key schedule */ | ||
| 370 | #endif | ||
| 371 | #ifndef NO_RC2 | ||
| 372 | RC2_KEY rc2_ks;/* key schedule */ | ||
| 373 | #endif | ||
| 374 | #ifndef NO_RC5 | ||
| 375 | RC5_32_KEY rc5_ks;/* key schedule */ | ||
| 376 | #endif | ||
| 377 | #ifndef NO_BLOWFISH | ||
| 378 | BF_KEY bf_ks;/* key schedule */ | ||
| 379 | #endif | ||
| 380 | #ifndef NO_CAST | ||
| 381 | CAST_KEY cast_ks;/* key schedule */ | ||
| 382 | #endif | ||
| 383 | } c; | ||
| 384 | } EVP_CIPHER_CTX; | ||
| 385 | |||
| 386 | typedef struct evp_Encode_Ctx_st | ||
| 387 | { | ||
| 388 | int num; /* number saved in a partial encode/decode */ | ||
| 389 | int length; /* The length is either the output line length | ||
| 390 | * (in input bytes) or the shortest input line | ||
| 391 | * length that is ok. Once decoding begins, | ||
| 392 | * the length is adjusted up each time a longer | ||
| 393 | * line is decoded */ | ||
| 394 | unsigned char enc_data[80]; /* data to encode */ | ||
| 395 | int line_num; /* number read on current line */ | ||
| 396 | int expect_nl; | ||
| 397 | } EVP_ENCODE_CTX; | ||
| 398 | |||
| 399 | #define EVP_PKEY_assign_RSA(pkey,rsa) EVP_PKEY_assign((pkey),EVP_PKEY_RSA,\ | ||
| 400 | (char *)(rsa)) | ||
| 401 | #define EVP_PKEY_assign_DSA(pkey,dsa) EVP_PKEY_assign((pkey),EVP_PKEY_DSA,\ | ||
| 402 | (char *)(dsa)) | ||
| 403 | #define EVP_PKEY_assign_DH(pkey,dh) EVP_PKEY_assign((pkey),EVP_PKEY_DH,\ | ||
| 404 | (char *)(dh)) | ||
| 405 | |||
| 406 | /* Add some extra combinations */ | ||
| 407 | #define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a)) | ||
| 408 | #define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a)) | ||
| 409 | #define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a)) | ||
| 410 | #define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a)) | ||
| 411 | |||
| 412 | #define EVP_MD_type(e) ((e)->type) | ||
| 413 | #define EVP_MD_pkey_type(e) ((e)->pkey_type) | ||
| 414 | #define EVP_MD_size(e) ((e)->md_size) | ||
| 415 | #define EVP_MD_block_size(e) ((e)->block_size) | ||
| 416 | |||
| 417 | #define EVP_MD_CTX_size(e) EVP_MD_size((e)->digest) | ||
| 418 | #define EVP_MD_CTX_block_size(e) EVP_MD_block_size((e)->digest) | ||
| 419 | #define EVP_MD_CTX_type(e) ((e)->digest) | ||
| 420 | |||
| 421 | #define EVP_CIPHER_nid(e) ((e)->nid) | ||
| 422 | #define EVP_CIPHER_block_size(e) ((e)->block_size) | ||
| 423 | #define EVP_CIPHER_key_length(e) ((e)->key_len) | ||
| 424 | #define EVP_CIPHER_iv_length(e) ((e)->iv_len) | ||
| 425 | |||
| 426 | #define EVP_CIPHER_CTX_cipher(e) ((e)->cipher) | ||
| 427 | #define EVP_CIPHER_CTX_nid(e) ((e)->cipher->nid) | ||
| 428 | #define EVP_CIPHER_CTX_block_size(e) ((e)->cipher->block_size) | ||
| 429 | #define EVP_CIPHER_CTX_key_length(e) ((e)->cipher->key_len) | ||
| 430 | #define EVP_CIPHER_CTX_iv_length(e) ((e)->cipher->iv_len) | ||
| 431 | #define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data) | ||
| 432 | #define EVP_CIPHER_CTX_set_app_data(e,d) ((e)->app_data=(char *)(d)) | ||
| 433 | |||
| 434 | #define EVP_ENCODE_LENGTH(l) (((l+2)/3*4)+(l/48+1)*2+80) | ||
| 435 | #define EVP_DECODE_LENGTH(l) ((l+3)/4*3+80) | ||
| 436 | |||
| 437 | #define EVP_SignInit(a,b) EVP_DigestInit(a,b) | ||
| 438 | #define EVP_SignUpdate(a,b,c) EVP_DigestUpdate(a,b,c) | ||
| 439 | #define EVP_VerifyInit(a,b) EVP_DigestInit(a,b) | ||
| 440 | #define EVP_VerifyUpdate(a,b,c) EVP_DigestUpdate(a,b,c) | ||
| 441 | #define EVP_OpenUpdate(a,b,c,d,e) EVP_DecryptUpdate(a,b,c,d,e) | ||
| 442 | #define EVP_SealUpdate(a,b,c,d,e) EVP_EncryptUpdate(a,b,c,d,e) | ||
| 443 | |||
| 444 | #define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,0,(char *)md) | ||
| 445 | #define BIO_get_md(b,mdp) BIO_ctrl(b,BIO_C_GET_MD,0,(char *)mdp) | ||
| 446 | #define BIO_get_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_GET_MD_CTX,0,(char *)mdcp) | ||
| 447 | #define BIO_get_cipher_status(b) BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,NULL) | ||
| 448 | |||
| 449 | #define EVP_Cipher(c,o,i,l) (c)->cipher->do_cipher((c),(o),(i),(l)) | ||
| 450 | |||
| 451 | #ifndef NOPROTO | ||
| 452 | |||
| 453 | void EVP_DigestInit(EVP_MD_CTX *ctx, EVP_MD *type); | ||
| 454 | void EVP_DigestUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt); | ||
| 455 | void EVP_DigestFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s); | ||
| 456 | |||
| 457 | int EVP_read_pw_string(char *buf,int length,char *prompt,int verify); | ||
| 458 | void EVP_set_pw_prompt(char *prompt); | ||
| 459 | char * EVP_get_pw_prompt(void); | ||
| 460 | |||
| 461 | int EVP_BytesToKey(EVP_CIPHER *type,EVP_MD *md,unsigned char *salt, | ||
| 462 | unsigned char *data, int datal, int count, | ||
| 463 | unsigned char *key,unsigned char *iv); | ||
| 464 | |||
| 465 | EVP_CIPHER *EVP_get_cipherbyname(char *name); | ||
| 466 | |||
| 467 | void EVP_EncryptInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type, | ||
| 468 | unsigned char *key, unsigned char *iv); | ||
| 469 | void EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
| 470 | int *outl, unsigned char *in, int inl); | ||
| 471 | void EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); | ||
| 472 | |||
| 473 | void EVP_DecryptInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type, | ||
| 474 | unsigned char *key, unsigned char *iv); | ||
| 475 | void EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
| 476 | int *outl, unsigned char *in, int inl); | ||
| 477 | int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); | ||
| 478 | |||
| 479 | void EVP_CipherInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type, unsigned char *key, | ||
| 480 | unsigned char *iv,int enc); | ||
| 481 | void EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
| 482 | int *outl, unsigned char *in, int inl); | ||
| 483 | int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); | ||
| 484 | |||
| 485 | int EVP_SignFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s, | ||
| 486 | EVP_PKEY *pkey); | ||
| 487 | |||
| 488 | int EVP_VerifyFinal(EVP_MD_CTX *ctx,unsigned char *sigbuf, | ||
| 489 | unsigned int siglen,EVP_PKEY *pkey); | ||
| 490 | |||
| 491 | int EVP_OpenInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type,unsigned char *ek, | ||
| 492 | int ekl,unsigned char *iv,EVP_PKEY *priv); | ||
| 493 | int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); | ||
| 494 | |||
| 495 | int EVP_SealInit(EVP_CIPHER_CTX *ctx, EVP_CIPHER *type, unsigned char **ek, | ||
| 496 | int *ekl, unsigned char *iv,EVP_PKEY **pubk, int npubk); | ||
| 497 | void EVP_SealFinal(EVP_CIPHER_CTX *ctx,unsigned char *out,int *outl); | ||
| 498 | |||
| 499 | void EVP_EncodeInit(EVP_ENCODE_CTX *ctx); | ||
| 500 | void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out, | ||
| 501 | int *outl,unsigned char *in,int inl); | ||
| 502 | void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl); | ||
| 503 | int EVP_EncodeBlock(unsigned char *t, unsigned char *f, int n); | ||
| 504 | |||
| 505 | void EVP_DecodeInit(EVP_ENCODE_CTX *ctx); | ||
| 506 | int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl, | ||
| 507 | unsigned char *in, int inl); | ||
| 508 | int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned | ||
| 509 | char *out, int *outl); | ||
| 510 | int EVP_DecodeBlock(unsigned char *t, unsigned | ||
| 511 | char *f, int n); | ||
| 512 | |||
| 513 | void ERR_load_EVP_strings(void ); | ||
| 514 | |||
| 515 | void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *a); | ||
| 516 | void EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a); | ||
| 517 | |||
| 518 | #ifdef HEADER_BIO_H | ||
| 519 | BIO_METHOD *BIO_f_md(void); | ||
| 520 | BIO_METHOD *BIO_f_base64(void); | ||
| 521 | BIO_METHOD *BIO_f_cipher(void); | ||
| 522 | void BIO_set_cipher(BIO *b,EVP_CIPHER *c,unsigned char *k, | ||
| 523 | unsigned char *i, int enc); | ||
| 524 | #endif | ||
| 525 | |||
| 526 | EVP_MD *EVP_md_null(void); | ||
| 527 | EVP_MD *EVP_md2(void); | ||
| 528 | EVP_MD *EVP_md5(void); | ||
| 529 | EVP_MD *EVP_sha(void); | ||
| 530 | EVP_MD *EVP_sha1(void); | ||
| 531 | EVP_MD *EVP_dss(void); | ||
| 532 | EVP_MD *EVP_dss1(void); | ||
| 533 | EVP_MD *EVP_mdc2(void); | ||
| 534 | EVP_MD *EVP_ripemd160(void); | ||
| 535 | |||
| 536 | EVP_CIPHER *EVP_enc_null(void); /* does nothing :-) */ | ||
| 537 | EVP_CIPHER *EVP_des_ecb(void); | ||
| 538 | EVP_CIPHER *EVP_des_ede(void); | ||
| 539 | EVP_CIPHER *EVP_des_ede3(void); | ||
| 540 | EVP_CIPHER *EVP_des_cfb(void); | ||
| 541 | EVP_CIPHER *EVP_des_ede_cfb(void); | ||
| 542 | EVP_CIPHER *EVP_des_ede3_cfb(void); | ||
| 543 | EVP_CIPHER *EVP_des_ofb(void); | ||
| 544 | EVP_CIPHER *EVP_des_ede_ofb(void); | ||
| 545 | EVP_CIPHER *EVP_des_ede3_ofb(void); | ||
| 546 | EVP_CIPHER *EVP_des_cbc(void); | ||
| 547 | EVP_CIPHER *EVP_des_ede_cbc(void); | ||
| 548 | EVP_CIPHER *EVP_des_ede3_cbc(void); | ||
| 549 | EVP_CIPHER *EVP_desx_cbc(void); | ||
| 550 | EVP_CIPHER *EVP_rc4(void); | ||
| 551 | EVP_CIPHER *EVP_rc4_40(void); | ||
| 552 | EVP_CIPHER *EVP_idea_ecb(void); | ||
| 553 | EVP_CIPHER *EVP_idea_cfb(void); | ||
| 554 | EVP_CIPHER *EVP_idea_ofb(void); | ||
| 555 | EVP_CIPHER *EVP_idea_cbc(void); | ||
| 556 | EVP_CIPHER *EVP_rc2_ecb(void); | ||
| 557 | EVP_CIPHER *EVP_rc2_cbc(void); | ||
| 558 | EVP_CIPHER *EVP_rc2_40_cbc(void); | ||
| 559 | EVP_CIPHER *EVP_rc2_cfb(void); | ||
| 560 | EVP_CIPHER *EVP_rc2_ofb(void); | ||
| 561 | EVP_CIPHER *EVP_bf_ecb(void); | ||
| 562 | EVP_CIPHER *EVP_bf_cbc(void); | ||
| 563 | EVP_CIPHER *EVP_bf_cfb(void); | ||
| 564 | EVP_CIPHER *EVP_bf_ofb(void); | ||
| 565 | EVP_CIPHER *EVP_cast5_ecb(void); | ||
| 566 | EVP_CIPHER *EVP_cast5_cbc(void); | ||
| 567 | EVP_CIPHER *EVP_cast5_cfb(void); | ||
| 568 | EVP_CIPHER *EVP_cast5_ofb(void); | ||
| 569 | EVP_CIPHER *EVP_rc5_32_12_16_cbc(void); | ||
| 570 | EVP_CIPHER *EVP_rc5_32_12_16_ecb(void); | ||
| 571 | EVP_CIPHER *EVP_rc5_32_12_16_cfb(void); | ||
| 572 | EVP_CIPHER *EVP_rc5_32_12_16_ofb(void); | ||
| 573 | |||
| 574 | void SSLeay_add_all_algorithms(void); | ||
| 575 | void SSLeay_add_all_ciphers(void); | ||
| 576 | void SSLeay_add_all_digests(void); | ||
| 577 | |||
| 578 | int EVP_add_cipher(EVP_CIPHER *cipher); | ||
| 579 | int EVP_add_digest(EVP_MD *digest); | ||
| 580 | int EVP_add_alias(char *name,char *alias); | ||
| 581 | int EVP_delete_alias(char *name); | ||
| 582 | |||
| 583 | EVP_CIPHER *EVP_get_cipherbyname(char *name); | ||
| 584 | EVP_MD *EVP_get_digestbyname(char *name); | ||
| 585 | void EVP_cleanup(void); | ||
| 586 | |||
| 587 | int EVP_PKEY_decrypt(unsigned char *dec_key,unsigned char *enc_key, | ||
| 588 | int enc_key_len,EVP_PKEY *private_key); | ||
| 589 | int EVP_PKEY_encrypt(unsigned char *enc_key, | ||
| 590 | unsigned char *key,int key_len,EVP_PKEY *pub_key); | ||
| 591 | int EVP_PKEY_type(int type); | ||
| 592 | int EVP_PKEY_bits(EVP_PKEY *pkey); | ||
| 593 | int EVP_PKEY_size(EVP_PKEY *pkey); | ||
| 594 | int EVP_PKEY_assign(EVP_PKEY *pkey,int type,char *key); | ||
| 595 | EVP_PKEY * EVP_PKEY_new(void); | ||
| 596 | void EVP_PKEY_free(EVP_PKEY *pkey); | ||
| 597 | EVP_PKEY * d2i_PublicKey(int type,EVP_PKEY **a, unsigned char **pp, | ||
| 598 | long length); | ||
| 599 | int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp); | ||
| 600 | |||
| 601 | EVP_PKEY * d2i_PrivateKey(int type,EVP_PKEY **a, unsigned char **pp, | ||
| 602 | long length); | ||
| 603 | int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp); | ||
| 604 | |||
| 605 | int EVP_PKEY_copy_parameters(EVP_PKEY *to,EVP_PKEY *from); | ||
| 606 | int EVP_PKEY_missing_parameters(EVP_PKEY *pkey); | ||
| 607 | int EVP_PKEY_save_parameters(EVP_PKEY *pkey,int mode); | ||
| 608 | int EVP_PKEY_cmp_parameters(EVP_PKEY *a,EVP_PKEY *b); | ||
| 609 | |||
| 610 | /* calls methods */ | ||
| 611 | int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type); | ||
| 612 | int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type); | ||
| 613 | |||
| 614 | /* These are used by EVP_CIPHER methods */ | ||
| 615 | int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type); | ||
| 616 | int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type); | ||
| 617 | |||
| 618 | #else | ||
| 619 | |||
| 620 | void EVP_DigestInit(); | ||
| 621 | void EVP_DigestUpdate(); | ||
| 622 | void EVP_DigestFinal(); | ||
| 623 | |||
| 624 | int EVP_read_pw_string(); | ||
| 625 | void EVP_set_pw_prompt(); | ||
| 626 | char * EVP_get_pw_prompt(); | ||
| 627 | |||
| 628 | int EVP_BytesToKey(); | ||
| 629 | |||
| 630 | EVP_CIPHER *EVP_get_cipherbyname(); | ||
| 631 | |||
| 632 | void EVP_EncryptInit(); | ||
| 633 | void EVP_EncryptUpdate(); | ||
| 634 | void EVP_EncryptFinal(); | ||
| 635 | |||
| 636 | void EVP_DecryptInit(); | ||
| 637 | void EVP_DecryptUpdate(); | ||
| 638 | int EVP_DecryptFinal(); | ||
| 639 | |||
| 640 | void EVP_CipherInit(); | ||
| 641 | void EVP_CipherUpdate(); | ||
| 642 | int EVP_CipherFinal(); | ||
| 643 | |||
| 644 | int EVP_SignFinal(); | ||
| 645 | |||
| 646 | int EVP_VerifyFinal(); | ||
| 647 | |||
| 648 | int EVP_OpenInit(); | ||
| 649 | int EVP_OpenFinal(); | ||
| 650 | |||
| 651 | int EVP_SealInit(); | ||
| 652 | void EVP_SealFinal(); | ||
| 653 | |||
| 654 | void EVP_EncodeInit(); | ||
| 655 | void EVP_EncodeUpdate(); | ||
| 656 | void EVP_EncodeFinal(); | ||
| 657 | int EVP_EncodeBlock(); | ||
| 658 | |||
| 659 | void EVP_DecodeInit(); | ||
| 660 | int EVP_DecodeUpdate(); | ||
| 661 | int EVP_DecodeFinal(); | ||
| 662 | int EVP_DecodeBlock(); | ||
| 663 | |||
| 664 | void ERR_load_EVP_strings(); | ||
| 665 | |||
| 666 | void EVP_CIPHER_CTX_init(); | ||
| 667 | void EVP_CIPHER_CTX_cleanup(); | ||
| 668 | |||
| 669 | #ifdef HEADER_BIO_H | ||
| 670 | BIO_METHOD *BIO_f_md(); | ||
| 671 | BIO_METHOD *BIO_f_base64(); | ||
| 672 | BIO_METHOD *BIO_f_cipher(); | ||
| 673 | void BIO_set_cipher(); | ||
| 674 | #endif | ||
| 675 | |||
| 676 | EVP_MD *EVP_md_null(); | ||
| 677 | EVP_MD *EVP_md2(); | ||
| 678 | EVP_MD *EVP_md5(); | ||
| 679 | EVP_MD *EVP_sha(); | ||
| 680 | EVP_MD *EVP_sha1(); | ||
| 681 | EVP_MD *EVP_dss(); | ||
| 682 | EVP_MD *EVP_dss1(); | ||
| 683 | EVP_MD *EVP_mdc2(); | ||
| 684 | |||
| 685 | EVP_CIPHER *EVP_enc_null(); | ||
| 686 | EVP_CIPHER *EVP_des_ecb(); | ||
| 687 | EVP_CIPHER *EVP_des_ede(); | ||
| 688 | EVP_CIPHER *EVP_des_ede3(); | ||
| 689 | EVP_CIPHER *EVP_des_cfb(); | ||
| 690 | EVP_CIPHER *EVP_des_ede_cfb(); | ||
| 691 | EVP_CIPHER *EVP_des_ede3_cfb(); | ||
| 692 | EVP_CIPHER *EVP_des_ofb(); | ||
| 693 | EVP_CIPHER *EVP_des_ede_ofb(); | ||
| 694 | EVP_CIPHER *EVP_des_ede3_ofb(); | ||
| 695 | EVP_CIPHER *EVP_des_cbc(); | ||
| 696 | EVP_CIPHER *EVP_des_ede_cbc(); | ||
| 697 | EVP_CIPHER *EVP_des_ede3_cbc(); | ||
| 698 | EVP_CIPHER *EVP_desx_cbc(); | ||
| 699 | EVP_CIPHER *EVP_rc4(); | ||
| 700 | EVP_CIPHER *EVP_rc4_40(); | ||
| 701 | EVP_CIPHER *EVP_idea_ecb(); | ||
| 702 | EVP_CIPHER *EVP_idea_cfb(); | ||
| 703 | EVP_CIPHER *EVP_idea_ofb(); | ||
| 704 | EVP_CIPHER *EVP_idea_cbc(); | ||
| 705 | EVP_CIPHER *EVP_rc2_ecb(); | ||
| 706 | EVP_CIPHER *EVP_rc2_cbc(); | ||
| 707 | EVP_CIPHER *EVP_rc2_40_cbc(); | ||
| 708 | EVP_CIPHER *EVP_rc2_cfb(); | ||
| 709 | EVP_CIPHER *EVP_rc2_ofb(); | ||
| 710 | EVP_CIPHER *EVP_bf_ecb(); | ||
| 711 | EVP_CIPHER *EVP_bf_cbc(); | ||
| 712 | EVP_CIPHER *EVP_bf_cfb(); | ||
| 713 | EVP_CIPHER *EVP_bf_ofb(); | ||
| 714 | EVP_CIPHER *EVP_cast5_ecb(); | ||
| 715 | EVP_CIPHER *EVP_cast5_cbc(); | ||
| 716 | EVP_CIPHER *EVP_cast5_cfb(); | ||
| 717 | EVP_CIPHER *EVP_cast5_ofb(); | ||
| 718 | EVP_CIPHER *EVP_rc5_32_12_16_cbc(); | ||
| 719 | EVP_CIPHER *EVP_rc5_32_12_16_ecb(); | ||
| 720 | EVP_CIPHER *EVP_rc5_32_12_16_cfb(); | ||
| 721 | EVP_CIPHER *EVP_rc5_32_12_16_ofb(); | ||
| 722 | |||
| 723 | void SSLeay_add_all_algorithms(); | ||
| 724 | void SSLeay_add_all_ciphers(); | ||
| 725 | void SSLeay_add_all_digests(); | ||
| 726 | |||
| 727 | int EVP_add_cipher(); | ||
| 728 | int EVP_add_digest(); | ||
| 729 | int EVP_add_alias(); | ||
| 730 | int EVP_delete_alias(); | ||
| 731 | |||
| 732 | EVP_CIPHER *EVP_get_cipherbyname(); | ||
| 733 | EVP_MD *EVP_get_digestbyname(); | ||
| 734 | void EVP_cleanup(); | ||
| 735 | |||
| 736 | int EVP_PKEY_decrypt(); | ||
| 737 | int EVP_PKEY_encrypt(); | ||
| 738 | int EVP_PKEY_type(); | ||
| 739 | int EVP_PKEY_bits(); | ||
| 740 | int EVP_PKEY_size(); | ||
| 741 | int EVP_PKEY_assign(); | ||
| 742 | EVP_PKEY * EVP_PKEY_new(); | ||
| 743 | void EVP_PKEY_free(); | ||
| 744 | EVP_PKEY * d2i_PublicKey(); | ||
| 745 | int i2d_PublicKey(); | ||
| 746 | |||
| 747 | EVP_PKEY * d2i_PrivateKey(); | ||
| 748 | int i2d_PrivateKey(); | ||
| 749 | |||
| 750 | int EVP_PKEY_copy_parameters(); | ||
| 751 | int EVP_PKEY_missing_parameters(); | ||
| 752 | int EVP_PKEY_save_parameters(); | ||
| 753 | int EVP_PKEY_cmp_parameters(); | ||
| 754 | |||
| 755 | int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type); | ||
| 756 | int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type); | ||
| 757 | |||
| 758 | int EVP_CIPHER_set_asn1_iv(); | ||
| 759 | int EVP_CIPHER_get_asn1_iv(); | ||
| 760 | |||
| 761 | #endif | ||
| 762 | |||
| 763 | /* BEGIN ERROR CODES */ | ||
| 764 | /* Error codes for the EVP functions. */ | ||
| 765 | |||
| 766 | /* Function codes. */ | ||
| 767 | #define EVP_F_D2I_PKEY 100 | ||
| 768 | #define EVP_F_EVP_DECRYPTFINAL 101 | ||
| 769 | #define EVP_F_EVP_OPENINIT 102 | ||
| 770 | #define EVP_F_EVP_PKEY_COPY_PARAMETERS 103 | ||
| 771 | #define EVP_F_EVP_PKEY_DECRYPT 104 | ||
| 772 | #define EVP_F_EVP_PKEY_ENCRYPT 105 | ||
| 773 | #define EVP_F_EVP_PKEY_NEW 106 | ||
| 774 | #define EVP_F_EVP_SIGNFINAL 107 | ||
| 775 | #define EVP_F_EVP_VERIFYFINAL 108 | ||
| 776 | |||
| 777 | /* Reason codes. */ | ||
| 778 | #define EVP_R_BAD_DECRYPT 100 | ||
| 779 | #define EVP_R_DIFFERENT_KEY_TYPES 101 | ||
| 780 | #define EVP_R_IV_TOO_LARGE 102 | ||
| 781 | #define EVP_R_MISSING_PARMATERS 103 | ||
| 782 | #define EVP_R_NO_SIGN_FUNCTION_CONFIGURED 104 | ||
| 783 | #define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED 105 | ||
| 784 | #define EVP_R_PUBLIC_KEY_NOT_RSA 106 | ||
| 785 | #define EVP_R_UNSUPPORTED_CIPHER 107 | ||
| 786 | #define EVP_R_WRONG_FINAL_BLOCK_LENGTH 108 | ||
| 787 | #define EVP_R_WRONG_PUBLIC_KEY_TYPE 109 | ||
| 788 | |||
| 789 | #ifdef __cplusplus | ||
| 790 | } | ||
| 791 | #endif | ||
| 792 | #endif | ||
| 793 | |||
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c new file mode 100644 index 0000000000..93cc3a9464 --- /dev/null +++ b/src/lib/libcrypto/evp/evp_enc.c | |||
| @@ -0,0 +1,303 @@ | |||
| 1 | /* crypto/evp/evp_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 "evp.h" | ||
| 62 | |||
| 63 | char *EVP_version="EVP part of SSLeay 0.9.0b 29-Jun-1998"; | ||
| 64 | |||
| 65 | void EVP_CIPHER_CTX_init(ctx) | ||
| 66 | EVP_CIPHER_CTX *ctx; | ||
| 67 | { | ||
| 68 | memset(ctx,0,sizeof(EVP_CIPHER_CTX)); | ||
| 69 | /* ctx->cipher=NULL; */ | ||
| 70 | } | ||
| 71 | |||
| 72 | void EVP_CipherInit(ctx,data,key,iv,enc) | ||
| 73 | EVP_CIPHER_CTX *ctx; | ||
| 74 | EVP_CIPHER *data; | ||
| 75 | unsigned char *key; | ||
| 76 | unsigned char *iv; | ||
| 77 | int enc; | ||
| 78 | { | ||
| 79 | if (enc) | ||
| 80 | EVP_EncryptInit(ctx,data,key,iv); | ||
| 81 | else | ||
| 82 | EVP_DecryptInit(ctx,data,key,iv); | ||
| 83 | } | ||
| 84 | |||
| 85 | void EVP_CipherUpdate(ctx,out,outl,in,inl) | ||
| 86 | EVP_CIPHER_CTX *ctx; | ||
| 87 | unsigned char *out; | ||
| 88 | int *outl; | ||
| 89 | unsigned char *in; | ||
| 90 | int inl; | ||
| 91 | { | ||
| 92 | if (ctx->encrypt) | ||
| 93 | EVP_EncryptUpdate(ctx,out,outl,in,inl); | ||
| 94 | else EVP_DecryptUpdate(ctx,out,outl,in,inl); | ||
| 95 | } | ||
| 96 | |||
| 97 | int EVP_CipherFinal(ctx,out,outl) | ||
| 98 | EVP_CIPHER_CTX *ctx; | ||
| 99 | unsigned char *out; | ||
| 100 | int *outl; | ||
| 101 | { | ||
| 102 | if (ctx->encrypt) | ||
| 103 | { | ||
| 104 | EVP_EncryptFinal(ctx,out,outl); | ||
| 105 | return(1); | ||
| 106 | } | ||
| 107 | else return(EVP_DecryptFinal(ctx,out,outl)); | ||
| 108 | } | ||
| 109 | |||
| 110 | void EVP_EncryptInit(ctx,cipher,key,iv) | ||
| 111 | EVP_CIPHER_CTX *ctx; | ||
| 112 | EVP_CIPHER *cipher; | ||
| 113 | unsigned char *key; | ||
| 114 | unsigned char *iv; | ||
| 115 | { | ||
| 116 | if (cipher != NULL) | ||
| 117 | ctx->cipher=cipher; | ||
| 118 | ctx->cipher->init(ctx,key,iv,1); | ||
| 119 | ctx->encrypt=1; | ||
| 120 | ctx->buf_len=0; | ||
| 121 | } | ||
| 122 | |||
| 123 | void EVP_DecryptInit(ctx,cipher,key,iv) | ||
| 124 | EVP_CIPHER_CTX *ctx; | ||
| 125 | EVP_CIPHER *cipher; | ||
| 126 | unsigned char *key; | ||
| 127 | unsigned char *iv; | ||
| 128 | { | ||
| 129 | if (cipher != NULL) | ||
| 130 | ctx->cipher=cipher; | ||
| 131 | ctx->cipher->init(ctx,key,iv,0); | ||
| 132 | ctx->encrypt=0; | ||
| 133 | ctx->buf_len=0; | ||
| 134 | } | ||
| 135 | |||
| 136 | |||
| 137 | void EVP_EncryptUpdate(ctx,out,outl,in,inl) | ||
| 138 | EVP_CIPHER_CTX *ctx; | ||
| 139 | unsigned char *out; | ||
| 140 | int *outl; | ||
| 141 | unsigned char *in; | ||
| 142 | int inl; | ||
| 143 | { | ||
| 144 | int i,j,bl; | ||
| 145 | |||
| 146 | i=ctx->buf_len; | ||
| 147 | bl=ctx->cipher->block_size; | ||
| 148 | *outl=0; | ||
| 149 | if ((inl == 0) && (i != bl)) return; | ||
| 150 | if (i != 0) | ||
| 151 | { | ||
| 152 | if (i+inl < bl) | ||
| 153 | { | ||
| 154 | memcpy(&(ctx->buf[i]),in,inl); | ||
| 155 | ctx->buf_len+=inl; | ||
| 156 | return; | ||
| 157 | } | ||
| 158 | else | ||
| 159 | { | ||
| 160 | j=bl-i; | ||
| 161 | if (j != 0) memcpy(&(ctx->buf[i]),in,j); | ||
| 162 | ctx->cipher->do_cipher(ctx,out,ctx->buf,bl); | ||
| 163 | inl-=j; | ||
| 164 | in+=j; | ||
| 165 | out+=bl; | ||
| 166 | *outl+=bl; | ||
| 167 | } | ||
| 168 | } | ||
| 169 | i=inl%bl; /* how much is left */ | ||
| 170 | inl-=i; | ||
| 171 | if (inl > 0) | ||
| 172 | { | ||
| 173 | ctx->cipher->do_cipher(ctx,out,in,inl); | ||
| 174 | *outl+=inl; | ||
| 175 | } | ||
| 176 | |||
| 177 | if (i != 0) | ||
| 178 | memcpy(ctx->buf,&(in[inl]),i); | ||
| 179 | ctx->buf_len=i; | ||
| 180 | } | ||
| 181 | |||
| 182 | void EVP_EncryptFinal(ctx,out,outl) | ||
| 183 | EVP_CIPHER_CTX *ctx; | ||
| 184 | unsigned char *out; | ||
| 185 | int *outl; | ||
| 186 | { | ||
| 187 | int i,n,b,bl; | ||
| 188 | |||
| 189 | b=ctx->cipher->block_size; | ||
| 190 | if (b == 1) | ||
| 191 | { | ||
| 192 | *outl=0; | ||
| 193 | return; | ||
| 194 | } | ||
| 195 | bl=ctx->buf_len; | ||
| 196 | n=b-bl; | ||
| 197 | for (i=bl; i<b; i++) | ||
| 198 | ctx->buf[i]=n; | ||
| 199 | ctx->cipher->do_cipher(ctx,out,ctx->buf,b); | ||
| 200 | *outl=b; | ||
| 201 | } | ||
| 202 | |||
| 203 | void EVP_DecryptUpdate(ctx,out,outl,in,inl) | ||
| 204 | EVP_CIPHER_CTX *ctx; | ||
| 205 | unsigned char *out; | ||
| 206 | int *outl; | ||
| 207 | unsigned char *in; | ||
| 208 | int inl; | ||
| 209 | { | ||
| 210 | int b,bl,n; | ||
| 211 | int keep_last=0; | ||
| 212 | |||
| 213 | *outl=0; | ||
| 214 | if (inl == 0) return; | ||
| 215 | |||
| 216 | b=ctx->cipher->block_size; | ||
| 217 | if (b > 1) | ||
| 218 | { | ||
| 219 | /* Is the input a multiple of the block size? */ | ||
| 220 | bl=ctx->buf_len; | ||
| 221 | n=inl+bl; | ||
| 222 | if (n%b == 0) | ||
| 223 | { | ||
| 224 | if (inl < b) /* must be 'just one' buff */ | ||
| 225 | { | ||
| 226 | memcpy(&(ctx->buf[bl]),in,inl); | ||
| 227 | ctx->buf_len=b; | ||
| 228 | *outl=0; | ||
| 229 | return; | ||
| 230 | } | ||
| 231 | keep_last=1; | ||
| 232 | inl-=b; /* don't do the last block */ | ||
| 233 | } | ||
| 234 | } | ||
| 235 | EVP_EncryptUpdate(ctx,out,outl,in,inl); | ||
| 236 | |||
| 237 | /* if we have 'decrypted' a multiple of block size, make sure | ||
| 238 | * we have a copy of this last block */ | ||
| 239 | if (keep_last) | ||
| 240 | { | ||
| 241 | memcpy(&(ctx->buf[0]),&(in[inl]),b); | ||
| 242 | #ifdef DEBUG | ||
| 243 | if (ctx->buf_len != 0) | ||
| 244 | { | ||
| 245 | abort(); | ||
| 246 | } | ||
| 247 | #endif | ||
| 248 | ctx->buf_len=b; | ||
| 249 | } | ||
| 250 | } | ||
| 251 | |||
| 252 | int EVP_DecryptFinal(ctx,out,outl) | ||
| 253 | EVP_CIPHER_CTX *ctx; | ||
| 254 | unsigned char *out; | ||
| 255 | int *outl; | ||
| 256 | { | ||
| 257 | int i,b; | ||
| 258 | int n; | ||
| 259 | |||
| 260 | *outl=0; | ||
| 261 | b=ctx->cipher->block_size; | ||
| 262 | if (b > 1) | ||
| 263 | { | ||
| 264 | if (ctx->buf_len != b) | ||
| 265 | { | ||
| 266 | EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_WRONG_FINAL_BLOCK_LENGTH); | ||
| 267 | return(0); | ||
| 268 | } | ||
| 269 | EVP_EncryptUpdate(ctx,ctx->buf,&n,ctx->buf,0); | ||
| 270 | if (n != b) | ||
| 271 | return(0); | ||
| 272 | n=ctx->buf[b-1]; | ||
| 273 | if (n > b) | ||
| 274 | { | ||
| 275 | EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT); | ||
| 276 | return(0); | ||
| 277 | } | ||
| 278 | for (i=0; i<n; i++) | ||
| 279 | { | ||
| 280 | if (ctx->buf[--b] != n) | ||
| 281 | { | ||
| 282 | EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT); | ||
| 283 | return(0); | ||
| 284 | } | ||
| 285 | } | ||
| 286 | n=ctx->cipher->block_size-n; | ||
| 287 | for (i=0; i<n; i++) | ||
| 288 | out[i]=ctx->buf[i]; | ||
| 289 | *outl=n; | ||
| 290 | } | ||
| 291 | else | ||
| 292 | *outl=0; | ||
| 293 | return(1); | ||
| 294 | } | ||
| 295 | |||
| 296 | void EVP_CIPHER_CTX_cleanup(c) | ||
| 297 | EVP_CIPHER_CTX *c; | ||
| 298 | { | ||
| 299 | if ((c->cipher != NULL) && (c->cipher->cleanup != NULL)) | ||
| 300 | c->cipher->cleanup(c); | ||
| 301 | memset(c,0,sizeof(EVP_CIPHER_CTX)); | ||
| 302 | } | ||
| 303 | |||
diff --git a/src/lib/libcrypto/evp/evp_err.c b/src/lib/libcrypto/evp/evp_err.c new file mode 100644 index 0000000000..2b0a0ab93f --- /dev/null +++ b/src/lib/libcrypto/evp/evp_err.c | |||
| @@ -0,0 +1,108 @@ | |||
| 1 | /* lib/evp/evp_err.c */ | ||
| 2 | /* Copyright (C) 1995-1997 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 | #include <stdio.h> | ||
| 59 | #include "err.h" | ||
| 60 | #include "evp.h" | ||
| 61 | |||
| 62 | /* BEGIN ERROR CODES */ | ||
| 63 | #ifndef NO_ERR | ||
| 64 | static ERR_STRING_DATA EVP_str_functs[]= | ||
| 65 | { | ||
| 66 | {ERR_PACK(0,EVP_F_D2I_PKEY,0), "D2I_PKEY"}, | ||
| 67 | {ERR_PACK(0,EVP_F_EVP_DECRYPTFINAL,0), "EVP_DecryptFinal"}, | ||
| 68 | {ERR_PACK(0,EVP_F_EVP_OPENINIT,0), "EVP_OpenInit"}, | ||
| 69 | {ERR_PACK(0,EVP_F_EVP_PKEY_COPY_PARAMETERS,0), "EVP_PKEY_copy_parameters"}, | ||
| 70 | {ERR_PACK(0,EVP_F_EVP_PKEY_DECRYPT,0), "EVP_PKEY_decrypt"}, | ||
| 71 | {ERR_PACK(0,EVP_F_EVP_PKEY_ENCRYPT,0), "EVP_PKEY_encrypt"}, | ||
| 72 | {ERR_PACK(0,EVP_F_EVP_PKEY_NEW,0), "EVP_PKEY_new"}, | ||
| 73 | {ERR_PACK(0,EVP_F_EVP_SIGNFINAL,0), "EVP_SignFinal"}, | ||
| 74 | {ERR_PACK(0,EVP_F_EVP_VERIFYFINAL,0), "EVP_VerifyFinal"}, | ||
| 75 | {0,NULL}, | ||
| 76 | }; | ||
| 77 | |||
| 78 | static ERR_STRING_DATA EVP_str_reasons[]= | ||
| 79 | { | ||
| 80 | {EVP_R_BAD_DECRYPT ,"bad decrypt"}, | ||
| 81 | {EVP_R_DIFFERENT_KEY_TYPES ,"different key types"}, | ||
| 82 | {EVP_R_IV_TOO_LARGE ,"iv too large"}, | ||
| 83 | {EVP_R_MISSING_PARMATERS ,"missing parmaters"}, | ||
| 84 | {EVP_R_NO_SIGN_FUNCTION_CONFIGURED ,"no sign function configured"}, | ||
| 85 | {EVP_R_NO_VERIFY_FUNCTION_CONFIGURED ,"no verify function configured"}, | ||
| 86 | {EVP_R_PUBLIC_KEY_NOT_RSA ,"public key not rsa"}, | ||
| 87 | {EVP_R_UNSUPPORTED_CIPHER ,"unsupported cipher"}, | ||
| 88 | {EVP_R_WRONG_FINAL_BLOCK_LENGTH ,"wrong final block length"}, | ||
| 89 | {EVP_R_WRONG_PUBLIC_KEY_TYPE ,"wrong public key type"}, | ||
| 90 | {0,NULL}, | ||
| 91 | }; | ||
| 92 | |||
| 93 | #endif | ||
| 94 | |||
| 95 | void ERR_load_EVP_strings() | ||
| 96 | { | ||
| 97 | static int init=1; | ||
| 98 | |||
| 99 | if (init); | ||
| 100 | {; | ||
| 101 | init=0; | ||
| 102 | #ifndef NO_ERR | ||
| 103 | ERR_load_strings(ERR_LIB_EVP,EVP_str_functs); | ||
| 104 | ERR_load_strings(ERR_LIB_EVP,EVP_str_reasons); | ||
| 105 | #endif | ||
| 106 | |||
| 107 | } | ||
| 108 | } | ||
diff --git a/src/lib/libcrypto/evp/evp_key.c b/src/lib/libcrypto/evp/evp_key.c new file mode 100644 index 0000000000..dafa686f64 --- /dev/null +++ b/src/lib/libcrypto/evp/evp_key.c | |||
| @@ -0,0 +1,167 @@ | |||
| 1 | /* crypto/evp/evp_key.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 "x509.h" | ||
| 62 | #include "objects.h" | ||
| 63 | #include "evp.h" | ||
| 64 | |||
| 65 | /* should be init to zeros. */ | ||
| 66 | static char prompt_string[80]; | ||
| 67 | |||
| 68 | void EVP_set_pw_prompt(prompt) | ||
| 69 | char *prompt; | ||
| 70 | { | ||
| 71 | if (prompt == NULL) | ||
| 72 | prompt_string[0]='\0'; | ||
| 73 | else | ||
| 74 | strncpy(prompt_string,prompt,79); | ||
| 75 | } | ||
| 76 | |||
| 77 | char *EVP_get_pw_prompt() | ||
| 78 | { | ||
| 79 | if (prompt_string[0] == '\0') | ||
| 80 | return(NULL); | ||
| 81 | else | ||
| 82 | return(prompt_string); | ||
| 83 | } | ||
| 84 | |||
| 85 | #ifdef NO_DES | ||
| 86 | int des_read_pw_string(char *buf,int len,char *prompt,int verify); | ||
| 87 | #endif | ||
| 88 | |||
| 89 | int EVP_read_pw_string(buf,len,prompt,verify) | ||
| 90 | char *buf; | ||
| 91 | int len; | ||
| 92 | char *prompt; | ||
| 93 | int verify; | ||
| 94 | { | ||
| 95 | if ((prompt == NULL) && (prompt_string[0] != '\0')) | ||
| 96 | prompt=prompt_string; | ||
| 97 | return(des_read_pw_string(buf,len,prompt,verify)); | ||
| 98 | } | ||
| 99 | |||
| 100 | int EVP_BytesToKey(type,md,salt,data,datal,count,key,iv) | ||
| 101 | EVP_CIPHER *type; | ||
| 102 | EVP_MD *md; | ||
| 103 | unsigned char *salt; | ||
| 104 | unsigned char *data; | ||
| 105 | int datal; | ||
| 106 | int count; | ||
| 107 | unsigned char *key; | ||
| 108 | unsigned char *iv; | ||
| 109 | { | ||
| 110 | EVP_MD_CTX c; | ||
| 111 | unsigned char md_buf[EVP_MAX_MD_SIZE]; | ||
| 112 | int niv,nkey,addmd=0; | ||
| 113 | unsigned int mds=0,i; | ||
| 114 | |||
| 115 | nkey=type->key_len; | ||
| 116 | niv=type->iv_len; | ||
| 117 | |||
| 118 | if (data == NULL) return(nkey); | ||
| 119 | |||
| 120 | for (;;) | ||
| 121 | { | ||
| 122 | EVP_DigestInit(&c,md); | ||
| 123 | if (addmd++) | ||
| 124 | EVP_DigestUpdate(&c,&(md_buf[0]),mds); | ||
| 125 | EVP_DigestUpdate(&c,data,datal); | ||
| 126 | if (salt != NULL) | ||
| 127 | EVP_DigestUpdate(&c,salt,8); | ||
| 128 | EVP_DigestFinal(&c,&(md_buf[0]),&mds); | ||
| 129 | |||
| 130 | for (i=1; i<(unsigned int)count; i++) | ||
| 131 | { | ||
| 132 | EVP_DigestInit(&c,md); | ||
| 133 | EVP_DigestUpdate(&c,&(md_buf[0]),mds); | ||
| 134 | EVP_DigestFinal(&c,&(md_buf[0]),&mds); | ||
| 135 | } | ||
| 136 | i=0; | ||
| 137 | if (nkey) | ||
| 138 | { | ||
| 139 | for (;;) | ||
| 140 | { | ||
| 141 | if (nkey == 0) break; | ||
| 142 | if (i == mds) break; | ||
| 143 | if (key != NULL) | ||
| 144 | *(key++)=md_buf[i]; | ||
| 145 | nkey--; | ||
| 146 | i++; | ||
| 147 | } | ||
| 148 | } | ||
| 149 | if (niv && (i != mds)) | ||
| 150 | { | ||
| 151 | for (;;) | ||
| 152 | { | ||
| 153 | if (niv == 0) break; | ||
| 154 | if (i == mds) break; | ||
| 155 | if (iv != NULL) | ||
| 156 | *(iv++)=md_buf[i]; | ||
| 157 | niv--; | ||
| 158 | i++; | ||
| 159 | } | ||
| 160 | } | ||
| 161 | if ((nkey == 0) && (niv == 0)) break; | ||
| 162 | } | ||
| 163 | memset(&c,0,sizeof(c)); | ||
| 164 | memset(&(md_buf[0]),0,EVP_MAX_MD_SIZE); | ||
| 165 | return(type->key_len); | ||
| 166 | } | ||
| 167 | |||
diff --git a/src/lib/libcrypto/evp/evp_lib.c b/src/lib/libcrypto/evp/evp_lib.c new file mode 100644 index 0000000000..69784eb555 --- /dev/null +++ b/src/lib/libcrypto/evp/evp_lib.c | |||
| @@ -0,0 +1,117 @@ | |||
| 1 | /* crypto/evp/evp_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 "evp.h" | ||
| 62 | #include "objects.h" | ||
| 63 | |||
| 64 | int EVP_CIPHER_param_to_asn1(c,type) | ||
| 65 | EVP_CIPHER_CTX *c; | ||
| 66 | ASN1_TYPE *type; | ||
| 67 | { | ||
| 68 | int ret; | ||
| 69 | |||
| 70 | if (c->cipher->set_asn1_parameters != NULL) | ||
| 71 | ret=c->cipher->set_asn1_parameters(c,type); | ||
| 72 | else | ||
| 73 | ret=1; | ||
| 74 | return(ret); | ||
| 75 | } | ||
| 76 | |||
| 77 | int EVP_CIPHER_asn1_to_param(c,type) | ||
| 78 | EVP_CIPHER_CTX *c; | ||
| 79 | ASN1_TYPE *type; | ||
| 80 | { | ||
| 81 | int ret; | ||
| 82 | |||
| 83 | if (c->cipher->get_asn1_parameters != NULL) | ||
| 84 | ret=c->cipher->get_asn1_parameters(c,type); | ||
| 85 | else | ||
| 86 | ret=1; | ||
| 87 | return(ret); | ||
| 88 | } | ||
| 89 | |||
| 90 | int EVP_CIPHER_get_asn1_iv(c,type) | ||
| 91 | EVP_CIPHER_CTX *c; | ||
| 92 | ASN1_TYPE *type; | ||
| 93 | { | ||
| 94 | int i=0,l; | ||
| 95 | |||
| 96 | if (type != NULL) | ||
| 97 | { | ||
| 98 | l=EVP_CIPHER_CTX_iv_length(c); | ||
| 99 | i=ASN1_TYPE_get_octetstring(type,c->oiv,l); | ||
| 100 | memcpy(c->iv,c->oiv,l); | ||
| 101 | } | ||
| 102 | return(i); | ||
| 103 | } | ||
| 104 | |||
| 105 | int EVP_CIPHER_set_asn1_iv(c,type) | ||
| 106 | EVP_CIPHER_CTX *c; | ||
| 107 | ASN1_TYPE *type; | ||
| 108 | { | ||
| 109 | int i=0,j; | ||
| 110 | |||
| 111 | if (type != NULL) | ||
| 112 | { | ||
| 113 | j=EVP_CIPHER_CTX_iv_length(c); | ||
| 114 | i=ASN1_TYPE_set_octetstring(type,c->oiv,j); | ||
| 115 | } | ||
| 116 | return(i); | ||
| 117 | } | ||
diff --git a/src/lib/libcrypto/evp/m_dss.c b/src/lib/libcrypto/evp/m_dss.c new file mode 100644 index 0000000000..3549b1699c --- /dev/null +++ b/src/lib/libcrypto/evp/m_dss.c | |||
| @@ -0,0 +1,82 @@ | |||
| 1 | /* crypto/evp/m_dss.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 "evp.h" | ||
| 62 | #include "objects.h" | ||
| 63 | #include "x509.h" | ||
| 64 | |||
| 65 | static EVP_MD dsa_md= | ||
| 66 | { | ||
| 67 | NID_dsaWithSHA, | ||
| 68 | NID_dsaWithSHA, | ||
| 69 | SHA_DIGEST_LENGTH, | ||
| 70 | SHA1_Init, | ||
| 71 | SHA1_Update, | ||
| 72 | SHA1_Final, | ||
| 73 | EVP_PKEY_DSA_method, | ||
| 74 | SHA_CBLOCK, | ||
| 75 | sizeof(EVP_MD *)+sizeof(SHA_CTX), | ||
| 76 | }; | ||
| 77 | |||
| 78 | EVP_MD *EVP_dss() | ||
| 79 | { | ||
| 80 | return(&dsa_md); | ||
| 81 | } | ||
| 82 | |||
diff --git a/src/lib/libcrypto/evp/m_dss1.c b/src/lib/libcrypto/evp/m_dss1.c new file mode 100644 index 0000000000..ff256b7b20 --- /dev/null +++ b/src/lib/libcrypto/evp/m_dss1.c | |||
| @@ -0,0 +1,81 @@ | |||
| 1 | /* crypto/evp/m_dss1.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 "evp.h" | ||
| 62 | #include "objects.h" | ||
| 63 | #include "x509.h" | ||
| 64 | |||
| 65 | static EVP_MD dss1_md= | ||
| 66 | { | ||
| 67 | NID_dsa, | ||
| 68 | NID_dsaWithSHA1, | ||
| 69 | SHA_DIGEST_LENGTH, | ||
| 70 | SHA1_Init, | ||
| 71 | SHA1_Update, | ||
| 72 | SHA1_Final, | ||
| 73 | EVP_PKEY_DSA_method, | ||
| 74 | SHA_CBLOCK, | ||
| 75 | sizeof(EVP_MD *)+sizeof(SHA_CTX), | ||
| 76 | }; | ||
| 77 | |||
| 78 | EVP_MD *EVP_dss1() | ||
| 79 | { | ||
| 80 | return(&dss1_md); | ||
| 81 | } | ||
diff --git a/src/lib/libcrypto/evp/m_md5.c b/src/lib/libcrypto/evp/m_md5.c new file mode 100644 index 0000000000..d65db9aa1d --- /dev/null +++ b/src/lib/libcrypto/evp/m_md5.c | |||
| @@ -0,0 +1,81 @@ | |||
| 1 | /* crypto/evp/m_md5.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 "evp.h" | ||
| 62 | #include "objects.h" | ||
| 63 | #include "x509.h" | ||
| 64 | |||
| 65 | static EVP_MD md5_md= | ||
| 66 | { | ||
| 67 | NID_md5, | ||
| 68 | NID_md5WithRSAEncryption, | ||
| 69 | MD5_DIGEST_LENGTH, | ||
| 70 | MD5_Init, | ||
| 71 | MD5_Update, | ||
| 72 | MD5_Final, | ||
| 73 | EVP_PKEY_RSA_method, | ||
| 74 | MD5_CBLOCK, | ||
| 75 | sizeof(EVP_MD *)+sizeof(MD5_CTX), | ||
| 76 | }; | ||
| 77 | |||
| 78 | EVP_MD *EVP_md5() | ||
| 79 | { | ||
| 80 | return(&md5_md); | ||
| 81 | } | ||
diff --git a/src/lib/libcrypto/evp/m_null.c b/src/lib/libcrypto/evp/m_null.c new file mode 100644 index 0000000000..6d80560df2 --- /dev/null +++ b/src/lib/libcrypto/evp/m_null.c | |||
| @@ -0,0 +1,88 @@ | |||
| 1 | /* crypto/evp/m_null.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 "evp.h" | ||
| 62 | #include "objects.h" | ||
| 63 | #include "x509.h" | ||
| 64 | |||
| 65 | static void function() | ||
| 66 | { | ||
| 67 | } | ||
| 68 | |||
| 69 | static EVP_MD null_md= | ||
| 70 | { | ||
| 71 | NID_undef, | ||
| 72 | NID_undef, | ||
| 73 | 0, | ||
| 74 | function, | ||
| 75 | function, | ||
| 76 | function, | ||
| 77 | |||
| 78 | EVP_PKEY_NULL_method, | ||
| 79 | 0, | ||
| 80 | sizeof(EVP_MD *), | ||
| 81 | }; | ||
| 82 | |||
| 83 | EVP_MD *EVP_md_null() | ||
| 84 | { | ||
| 85 | return(&null_md); | ||
| 86 | } | ||
| 87 | |||
| 88 | |||
diff --git a/src/lib/libcrypto/evp/m_ripemd.c b/src/lib/libcrypto/evp/m_ripemd.c new file mode 100644 index 0000000000..04c5d8897b --- /dev/null +++ b/src/lib/libcrypto/evp/m_ripemd.c | |||
| @@ -0,0 +1,81 @@ | |||
| 1 | /* crypto/evp/m_ripemd.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 "evp.h" | ||
| 62 | #include "objects.h" | ||
| 63 | #include "x509.h" | ||
| 64 | |||
| 65 | static EVP_MD ripemd160_md= | ||
| 66 | { | ||
| 67 | NID_ripemd160, | ||
| 68 | NID_ripemd160WithRSA, | ||
| 69 | RIPEMD160_DIGEST_LENGTH, | ||
| 70 | RIPEMD160_Init, | ||
| 71 | RIPEMD160_Update, | ||
| 72 | RIPEMD160_Final, | ||
| 73 | EVP_PKEY_RSA_method, | ||
| 74 | RIPEMD160_CBLOCK, | ||
| 75 | sizeof(EVP_MD *)+sizeof(RIPEMD160_CTX), | ||
| 76 | }; | ||
| 77 | |||
| 78 | EVP_MD *EVP_ripemd160() | ||
| 79 | { | ||
| 80 | return(&ripemd160_md); | ||
| 81 | } | ||
diff --git a/src/lib/libcrypto/evp/m_sha1.c b/src/lib/libcrypto/evp/m_sha1.c new file mode 100644 index 0000000000..87135a9cf2 --- /dev/null +++ b/src/lib/libcrypto/evp/m_sha1.c | |||
| @@ -0,0 +1,81 @@ | |||
| 1 | /* crypto/evp/m_sha1.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 "evp.h" | ||
| 62 | #include "objects.h" | ||
| 63 | #include "x509.h" | ||
| 64 | |||
| 65 | static EVP_MD sha1_md= | ||
| 66 | { | ||
| 67 | NID_sha1, | ||
| 68 | NID_sha1WithRSAEncryption, | ||
| 69 | SHA_DIGEST_LENGTH, | ||
| 70 | SHA1_Init, | ||
| 71 | SHA1_Update, | ||
| 72 | SHA1_Final, | ||
| 73 | EVP_PKEY_RSA_method, | ||
| 74 | SHA_CBLOCK, | ||
| 75 | sizeof(EVP_MD *)+sizeof(SHA_CTX), | ||
| 76 | }; | ||
| 77 | |||
| 78 | EVP_MD *EVP_sha1() | ||
| 79 | { | ||
| 80 | return(&sha1_md); | ||
| 81 | } | ||
diff --git a/src/lib/libcrypto/evp/names.c b/src/lib/libcrypto/evp/names.c new file mode 100644 index 0000000000..e0774da20d --- /dev/null +++ b/src/lib/libcrypto/evp/names.c | |||
| @@ -0,0 +1,285 @@ | |||
| 1 | /* crypto/evp/names.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 "evp.h" | ||
| 62 | #include "objects.h" | ||
| 63 | |||
| 64 | typedef struct aliases_st { | ||
| 65 | char *alias; | ||
| 66 | /* This must be the last field becaue I will allocate things | ||
| 67 | * so they go off the end of it */ | ||
| 68 | char name[4]; | ||
| 69 | } ALIASES; | ||
| 70 | |||
| 71 | static STACK /* ALIASES */ *aliases=NULL; | ||
| 72 | static STACK /* EVP_CIPHERS */ *ciphers=NULL; | ||
| 73 | static STACK /* EVP_MD */ *digests=NULL; | ||
| 74 | |||
| 75 | static int cipher_nid_cmp(a,b) | ||
| 76 | EVP_CIPHER **a,**b; | ||
| 77 | { return((*a)->nid - (*b)->nid); } | ||
| 78 | |||
| 79 | static int digest_type_cmp(a,b) | ||
| 80 | EVP_MD **a,**b; | ||
| 81 | { return((*a)->pkey_type - (*b)->pkey_type); } | ||
| 82 | |||
| 83 | int EVP_add_cipher(c) | ||
| 84 | EVP_CIPHER *c; | ||
| 85 | { | ||
| 86 | int i; | ||
| 87 | |||
| 88 | if (ciphers == NULL) | ||
| 89 | { | ||
| 90 | ciphers=sk_new(cipher_nid_cmp); | ||
| 91 | if (ciphers == NULL) return(0); | ||
| 92 | } | ||
| 93 | if ((i=sk_find(ciphers,(char *)c)) >= 0) | ||
| 94 | { | ||
| 95 | if (sk_value(ciphers,i) == (char *)c) | ||
| 96 | return(1); | ||
| 97 | sk_delete(ciphers,i); | ||
| 98 | } | ||
| 99 | return(sk_push(ciphers,(char *)c)); | ||
| 100 | } | ||
| 101 | |||
| 102 | int EVP_add_digest(md) | ||
| 103 | EVP_MD *md; | ||
| 104 | { | ||
| 105 | int i; | ||
| 106 | char *n; | ||
| 107 | |||
| 108 | if (digests == NULL) | ||
| 109 | { | ||
| 110 | digests=sk_new(digest_type_cmp); | ||
| 111 | if (digests == NULL) return(0); | ||
| 112 | } | ||
| 113 | if ((i=sk_find(digests,(char *)md)) >= 0) | ||
| 114 | { | ||
| 115 | if (sk_value(digests,i) == (char *)md) | ||
| 116 | return(1); | ||
| 117 | sk_delete(digests,i); | ||
| 118 | } | ||
| 119 | if (md->type != md->pkey_type) | ||
| 120 | { | ||
| 121 | n=OBJ_nid2sn(md->pkey_type); | ||
| 122 | EVP_add_alias(n,OBJ_nid2sn(md->type)); | ||
| 123 | EVP_add_alias(n,OBJ_nid2ln(md->type)); | ||
| 124 | } | ||
| 125 | sk_push(digests,(char *)md); | ||
| 126 | return(1); | ||
| 127 | } | ||
| 128 | |||
| 129 | static int alias_cmp(a,b) | ||
| 130 | ALIASES **a,**b; | ||
| 131 | { | ||
| 132 | return(strcmp((*a)->alias,(*b)->alias)); | ||
| 133 | } | ||
| 134 | |||
| 135 | int EVP_add_alias(name,aname) | ||
| 136 | char *name; | ||
| 137 | char *aname; | ||
| 138 | { | ||
| 139 | int l1,l2,i; | ||
| 140 | ALIASES *a; | ||
| 141 | char *p; | ||
| 142 | |||
| 143 | if ((name == NULL) || (aname == NULL)) return(0); | ||
| 144 | l1=strlen(name)+1; | ||
| 145 | l2=strlen(aname)+1; | ||
| 146 | i=sizeof(ALIASES)+l1+l2; | ||
| 147 | if ((a=(ALIASES *)Malloc(i)) == NULL) | ||
| 148 | return(0); | ||
| 149 | strcpy(a->name,name); | ||
| 150 | p= &(a->name[l1]); | ||
| 151 | strcpy(p,aname); | ||
| 152 | a->alias=p; | ||
| 153 | |||
| 154 | if (aliases == NULL) | ||
| 155 | { | ||
| 156 | aliases=sk_new(alias_cmp); | ||
| 157 | if (aliases == NULL) goto err; | ||
| 158 | } | ||
| 159 | |||
| 160 | if ((i=sk_find(aliases,(char *)a)) >= 0) | ||
| 161 | { | ||
| 162 | Free(sk_delete(aliases,i)); | ||
| 163 | } | ||
| 164 | if (!sk_push(aliases,(char *)a)) goto err; | ||
| 165 | return(1); | ||
| 166 | err: | ||
| 167 | return(0); | ||
| 168 | } | ||
| 169 | |||
| 170 | int EVP_delete_alias(name) | ||
| 171 | char *name; | ||
| 172 | { | ||
| 173 | ALIASES a; | ||
| 174 | int i; | ||
| 175 | |||
| 176 | if (aliases != NULL) | ||
| 177 | { | ||
| 178 | a.alias=name; | ||
| 179 | if ((i=sk_find(aliases,(char *)&a)) >= 0) | ||
| 180 | { | ||
| 181 | Free(sk_delete(aliases,i)); | ||
| 182 | return(1); | ||
| 183 | } | ||
| 184 | } | ||
| 185 | return(0); | ||
| 186 | } | ||
| 187 | |||
| 188 | EVP_CIPHER *EVP_get_cipherbyname(name) | ||
| 189 | char *name; | ||
| 190 | { | ||
| 191 | int nid,num=6,i; | ||
| 192 | EVP_CIPHER c,*cp; | ||
| 193 | ALIASES a,*ap; | ||
| 194 | |||
| 195 | if (ciphers == NULL) return(NULL); | ||
| 196 | for (;;) | ||
| 197 | { | ||
| 198 | if (num-- <= 0) return(NULL); | ||
| 199 | if (aliases != NULL) | ||
| 200 | { | ||
| 201 | a.alias=name; | ||
| 202 | i=sk_find(aliases,(char *)&a); | ||
| 203 | if (i >= 0) | ||
| 204 | { | ||
| 205 | ap=(ALIASES *)sk_value(aliases,i); | ||
| 206 | name=ap->name; | ||
| 207 | continue; | ||
| 208 | } | ||
| 209 | } | ||
| 210 | |||
| 211 | nid=OBJ_txt2nid(name); | ||
| 212 | if (nid == NID_undef) return(NULL); | ||
| 213 | c.nid=nid; | ||
| 214 | i=sk_find(ciphers,(char *)&c); | ||
| 215 | if (i >= 0) | ||
| 216 | { | ||
| 217 | cp=(EVP_CIPHER *)sk_value(ciphers,i); | ||
| 218 | return(cp); | ||
| 219 | } | ||
| 220 | else | ||
| 221 | return(NULL); | ||
| 222 | } | ||
| 223 | } | ||
| 224 | |||
| 225 | EVP_MD *EVP_get_digestbyname(name) | ||
| 226 | char *name; | ||
| 227 | { | ||
| 228 | int nid,num=6,i; | ||
| 229 | EVP_MD c,*cp; | ||
| 230 | ALIASES a,*ap; | ||
| 231 | |||
| 232 | if (digests == NULL) return(NULL); | ||
| 233 | |||
| 234 | for (;;) | ||
| 235 | { | ||
| 236 | if (num-- <= 0) return(NULL); | ||
| 237 | |||
| 238 | if (aliases != NULL) | ||
| 239 | { | ||
| 240 | a.alias=name; | ||
| 241 | i=sk_find(aliases,(char *)&a); | ||
| 242 | if (i >= 0) | ||
| 243 | { | ||
| 244 | ap=(ALIASES *)sk_value(aliases,i); | ||
| 245 | name=ap->name; | ||
| 246 | continue; | ||
| 247 | } | ||
| 248 | } | ||
| 249 | |||
| 250 | nid=OBJ_txt2nid(name); | ||
| 251 | if (nid == NID_undef) return(NULL); | ||
| 252 | c.pkey_type=nid; | ||
| 253 | i=sk_find(digests,(char *)&c); | ||
| 254 | if (i >= 0) | ||
| 255 | { | ||
| 256 | cp=(EVP_MD *)sk_value(digests,i); | ||
| 257 | return(cp); | ||
| 258 | } | ||
| 259 | else | ||
| 260 | return(NULL); | ||
| 261 | } | ||
| 262 | } | ||
| 263 | |||
| 264 | void EVP_cleanup() | ||
| 265 | { | ||
| 266 | int i; | ||
| 267 | |||
| 268 | if (aliases != NULL) | ||
| 269 | { | ||
| 270 | for (i=0; i<sk_num(aliases); i++) | ||
| 271 | Free(sk_value(aliases,i)); | ||
| 272 | sk_free(aliases); | ||
| 273 | aliases=NULL; | ||
| 274 | } | ||
| 275 | if (ciphers != NULL) | ||
| 276 | { | ||
| 277 | sk_free(ciphers); | ||
| 278 | ciphers=NULL; | ||
| 279 | } | ||
| 280 | if (digests != NULL) | ||
| 281 | { | ||
| 282 | sk_free(digests); | ||
| 283 | digests=NULL; | ||
| 284 | } | ||
| 285 | } | ||
diff --git a/src/lib/libcrypto/evp/p_dec.c b/src/lib/libcrypto/evp/p_dec.c new file mode 100644 index 0000000000..e845ce70c7 --- /dev/null +++ b/src/lib/libcrypto/evp/p_dec.c | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | /* crypto/evp/p_dec.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 "rand.h" | ||
| 62 | #include "rsa.h" | ||
| 63 | #include "evp.h" | ||
| 64 | #include "objects.h" | ||
| 65 | #include "x509.h" | ||
| 66 | |||
| 67 | int EVP_PKEY_decrypt(key,ek,ekl,priv) | ||
| 68 | unsigned char *key; | ||
| 69 | unsigned char *ek; | ||
| 70 | int ekl; | ||
| 71 | EVP_PKEY *priv; | ||
| 72 | { | ||
| 73 | int ret= -1; | ||
| 74 | |||
| 75 | if (priv->type != EVP_PKEY_RSA) | ||
| 76 | { | ||
| 77 | EVPerr(EVP_F_EVP_PKEY_DECRYPT,EVP_R_PUBLIC_KEY_NOT_RSA); | ||
| 78 | goto err; | ||
| 79 | } | ||
| 80 | |||
| 81 | ret=RSA_private_decrypt(ekl,ek,key,priv->pkey.rsa,RSA_PKCS1_PADDING); | ||
| 82 | err: | ||
| 83 | return(ret); | ||
| 84 | } | ||
diff --git a/src/lib/libcrypto/evp/p_enc.c b/src/lib/libcrypto/evp/p_enc.c new file mode 100644 index 0000000000..a26bfad02a --- /dev/null +++ b/src/lib/libcrypto/evp/p_enc.c | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | /* crypto/evp/p_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 "rand.h" | ||
| 62 | #include "rsa.h" | ||
| 63 | #include "evp.h" | ||
| 64 | #include "objects.h" | ||
| 65 | #include "x509.h" | ||
| 66 | |||
| 67 | int EVP_PKEY_encrypt(ek,key,key_len,pubk) | ||
| 68 | unsigned char *ek; | ||
| 69 | unsigned char *key; | ||
| 70 | int key_len; | ||
| 71 | EVP_PKEY *pubk; | ||
| 72 | { | ||
| 73 | int ret=0; | ||
| 74 | |||
| 75 | if (pubk->type != EVP_PKEY_RSA) | ||
| 76 | { | ||
| 77 | EVPerr(EVP_F_EVP_PKEY_ENCRYPT,EVP_R_PUBLIC_KEY_NOT_RSA); | ||
| 78 | goto err; | ||
| 79 | } | ||
| 80 | ret=RSA_public_encrypt(key_len,key,ek,pubk->pkey.rsa,RSA_PKCS1_PADDING); | ||
| 81 | err: | ||
| 82 | return(ret); | ||
| 83 | } | ||
diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c new file mode 100644 index 0000000000..395351b373 --- /dev/null +++ b/src/lib/libcrypto/evp/p_lib.c | |||
| @@ -0,0 +1,294 @@ | |||
| 1 | /* crypto/evp/p_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 "objects.h" | ||
| 62 | #include "evp.h" | ||
| 63 | #include "asn1_mac.h" | ||
| 64 | #include "x509.h" | ||
| 65 | |||
| 66 | /* EVPerr(EVP_F_D2I_PKEY,EVP_R_UNSUPPORTED_CIPHER); */ | ||
| 67 | /* EVPerr(EVP_F_D2I_PKEY,EVP_R_IV_TOO_LARGE); */ | ||
| 68 | |||
| 69 | #ifndef NOPROTO | ||
| 70 | static void EVP_PKEY_free_it(EVP_PKEY *x); | ||
| 71 | #else | ||
| 72 | static void EVP_PKEY_free_it(); | ||
| 73 | #endif | ||
| 74 | |||
| 75 | int EVP_PKEY_bits(pkey) | ||
| 76 | EVP_PKEY *pkey; | ||
| 77 | { | ||
| 78 | #ifndef NO_RSA | ||
| 79 | if (pkey->type == EVP_PKEY_RSA) | ||
| 80 | return(BN_num_bits(pkey->pkey.rsa->n)); | ||
| 81 | else | ||
| 82 | #endif | ||
| 83 | #ifndef NO_DSA | ||
| 84 | if (pkey->type == EVP_PKEY_DSA) | ||
| 85 | return(BN_num_bits(pkey->pkey.dsa->p)); | ||
| 86 | #endif | ||
| 87 | return(0); | ||
| 88 | } | ||
| 89 | |||
| 90 | int EVP_PKEY_size(pkey) | ||
| 91 | EVP_PKEY *pkey; | ||
| 92 | { | ||
| 93 | #ifndef NO_RSA | ||
| 94 | if (pkey->type == EVP_PKEY_RSA) | ||
| 95 | return(RSA_size(pkey->pkey.rsa)); | ||
| 96 | else | ||
| 97 | #endif | ||
| 98 | #ifndef NO_DSA | ||
| 99 | if (pkey->type == EVP_PKEY_DSA) | ||
| 100 | return(DSA_size(pkey->pkey.dsa)); | ||
| 101 | #endif | ||
| 102 | return(0); | ||
| 103 | } | ||
| 104 | |||
| 105 | int EVP_PKEY_save_parameters(pkey,mode) | ||
| 106 | EVP_PKEY *pkey; | ||
| 107 | int mode; | ||
| 108 | { | ||
| 109 | #ifndef NO_DSA | ||
| 110 | if (pkey->type == EVP_PKEY_DSA) | ||
| 111 | { | ||
| 112 | int ret=pkey->save_parameters=mode; | ||
| 113 | |||
| 114 | if (mode >= 0) | ||
| 115 | pkey->save_parameters=mode; | ||
| 116 | return(ret); | ||
| 117 | } | ||
| 118 | #endif | ||
| 119 | return(0); | ||
| 120 | } | ||
| 121 | |||
| 122 | int EVP_PKEY_copy_parameters(to,from) | ||
| 123 | EVP_PKEY *to,*from; | ||
| 124 | { | ||
| 125 | if (to->type != from->type) | ||
| 126 | { | ||
| 127 | EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_DIFFERENT_KEY_TYPES); | ||
| 128 | goto err; | ||
| 129 | } | ||
| 130 | |||
| 131 | if (EVP_PKEY_missing_parameters(from)) | ||
| 132 | { | ||
| 133 | EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_MISSING_PARMATERS); | ||
| 134 | goto err; | ||
| 135 | } | ||
| 136 | #ifndef NO_DSA | ||
| 137 | if (to->type == EVP_PKEY_DSA) | ||
| 138 | { | ||
| 139 | BIGNUM *a; | ||
| 140 | |||
| 141 | if ((a=BN_dup(from->pkey.dsa->p)) == NULL) goto err; | ||
| 142 | if (to->pkey.dsa->p != NULL) BN_free(to->pkey.dsa->p); | ||
| 143 | to->pkey.dsa->p=a; | ||
| 144 | |||
| 145 | if ((a=BN_dup(from->pkey.dsa->q)) == NULL) goto err; | ||
| 146 | if (to->pkey.dsa->q != NULL) BN_free(to->pkey.dsa->q); | ||
| 147 | to->pkey.dsa->q=a; | ||
| 148 | |||
| 149 | if ((a=BN_dup(from->pkey.dsa->g)) == NULL) goto err; | ||
| 150 | if (to->pkey.dsa->g != NULL) BN_free(to->pkey.dsa->g); | ||
| 151 | to->pkey.dsa->g=a; | ||
| 152 | } | ||
| 153 | #endif | ||
| 154 | return(1); | ||
| 155 | err: | ||
| 156 | return(0); | ||
| 157 | } | ||
| 158 | |||
| 159 | int EVP_PKEY_missing_parameters(pkey) | ||
| 160 | EVP_PKEY *pkey; | ||
| 161 | { | ||
| 162 | #ifndef NO_DSA | ||
| 163 | if (pkey->type == EVP_PKEY_DSA) | ||
| 164 | { | ||
| 165 | DSA *dsa; | ||
| 166 | |||
| 167 | dsa=pkey->pkey.dsa; | ||
| 168 | if ((dsa->p == NULL) || (dsa->q == NULL) || (dsa->g == NULL)) | ||
| 169 | return(1); | ||
| 170 | } | ||
| 171 | #endif | ||
| 172 | return(0); | ||
| 173 | } | ||
| 174 | |||
| 175 | int EVP_PKEY_cmp_parameters(a,b) | ||
| 176 | EVP_PKEY *a,*b; | ||
| 177 | { | ||
| 178 | #ifndef NO_DSA | ||
| 179 | if ((a->type == EVP_PKEY_DSA) && (b->type == EVP_PKEY_DSA)) | ||
| 180 | { | ||
| 181 | if ( BN_cmp(a->pkey.dsa->p,b->pkey.dsa->p) || | ||
| 182 | BN_cmp(a->pkey.dsa->q,b->pkey.dsa->q) || | ||
| 183 | BN_cmp(a->pkey.dsa->g,b->pkey.dsa->g)) | ||
| 184 | return(0); | ||
| 185 | else | ||
| 186 | return(1); | ||
| 187 | } | ||
| 188 | #endif | ||
| 189 | return(-1); | ||
| 190 | } | ||
| 191 | |||
| 192 | EVP_PKEY *EVP_PKEY_new() | ||
| 193 | { | ||
| 194 | EVP_PKEY *ret; | ||
| 195 | |||
| 196 | ret=(EVP_PKEY *)Malloc(sizeof(EVP_PKEY)); | ||
| 197 | if (ret == NULL) | ||
| 198 | { | ||
| 199 | EVPerr(EVP_F_EVP_PKEY_NEW,ERR_R_MALLOC_FAILURE); | ||
| 200 | return(NULL); | ||
| 201 | } | ||
| 202 | ret->type=EVP_PKEY_NONE; | ||
| 203 | ret->references=1; | ||
| 204 | ret->pkey.ptr=NULL; | ||
| 205 | ret->attributes=NULL; | ||
| 206 | ret->save_parameters=1; | ||
| 207 | return(ret); | ||
| 208 | } | ||
| 209 | |||
| 210 | int EVP_PKEY_assign(pkey,type,key) | ||
| 211 | EVP_PKEY *pkey; | ||
| 212 | int type; | ||
| 213 | char *key; | ||
| 214 | { | ||
| 215 | if (pkey == NULL) return(0); | ||
| 216 | if (pkey->pkey.ptr != NULL) | ||
| 217 | EVP_PKEY_free_it(pkey); | ||
| 218 | pkey->type=EVP_PKEY_type(type); | ||
| 219 | pkey->save_type=type; | ||
| 220 | pkey->pkey.ptr=key; | ||
| 221 | return(1); | ||
| 222 | } | ||
| 223 | |||
| 224 | int EVP_PKEY_type(type) | ||
| 225 | int type; | ||
| 226 | { | ||
| 227 | switch (type) | ||
| 228 | { | ||
| 229 | case EVP_PKEY_RSA: | ||
| 230 | case EVP_PKEY_RSA2: | ||
| 231 | return(EVP_PKEY_RSA); | ||
| 232 | case EVP_PKEY_DSA: | ||
| 233 | case EVP_PKEY_DSA1: | ||
| 234 | case EVP_PKEY_DSA2: | ||
| 235 | case EVP_PKEY_DSA3: | ||
| 236 | case EVP_PKEY_DSA4: | ||
| 237 | return(EVP_PKEY_DSA); | ||
| 238 | case EVP_PKEY_DH: | ||
| 239 | return(EVP_PKEY_DH); | ||
| 240 | default: | ||
| 241 | return(NID_undef); | ||
| 242 | } | ||
| 243 | } | ||
| 244 | |||
| 245 | void EVP_PKEY_free(x) | ||
| 246 | EVP_PKEY *x; | ||
| 247 | { | ||
| 248 | int i; | ||
| 249 | |||
| 250 | if (x == NULL) return; | ||
| 251 | |||
| 252 | i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_EVP_PKEY); | ||
| 253 | #ifdef REF_PRINT | ||
| 254 | REF_PRINT("EVP_PKEY",x); | ||
| 255 | #endif | ||
| 256 | if (i > 0) return; | ||
| 257 | #ifdef REF_CHECK | ||
| 258 | if (i < 0) | ||
| 259 | { | ||
| 260 | fprintf(stderr,"EVP_PKEY_free, bad reference count\n"); | ||
| 261 | abort(); | ||
| 262 | } | ||
| 263 | #endif | ||
| 264 | EVP_PKEY_free_it(x); | ||
| 265 | Free((char *)x); | ||
| 266 | } | ||
| 267 | |||
| 268 | static void EVP_PKEY_free_it(x) | ||
| 269 | EVP_PKEY *x; | ||
| 270 | { | ||
| 271 | switch (x->type) | ||
| 272 | { | ||
| 273 | #ifndef NO_RSA | ||
| 274 | case EVP_PKEY_RSA: | ||
| 275 | case EVP_PKEY_RSA2: | ||
| 276 | RSA_free(x->pkey.rsa); | ||
| 277 | break; | ||
| 278 | #endif | ||
| 279 | #ifndef NO_DSA | ||
| 280 | case EVP_PKEY_DSA: | ||
| 281 | case EVP_PKEY_DSA2: | ||
| 282 | case EVP_PKEY_DSA3: | ||
| 283 | case EVP_PKEY_DSA4: | ||
| 284 | DSA_free(x->pkey.dsa); | ||
| 285 | break; | ||
| 286 | #endif | ||
| 287 | #ifndef NO_DH | ||
| 288 | case EVP_PKEY_DH: | ||
| 289 | DH_free(x->pkey.dh); | ||
| 290 | break; | ||
| 291 | #endif | ||
| 292 | } | ||
| 293 | } | ||
| 294 | |||
diff --git a/src/lib/libcrypto/evp/p_open.c b/src/lib/libcrypto/evp/p_open.c new file mode 100644 index 0000000000..28a8e02252 --- /dev/null +++ b/src/lib/libcrypto/evp/p_open.c | |||
| @@ -0,0 +1,119 @@ | |||
| 1 | /* crypto/evp/p_open.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 "evp.h" | ||
| 62 | #include "objects.h" | ||
| 63 | #include "x509.h" | ||
| 64 | |||
| 65 | int EVP_OpenInit(ctx,type,ek,ekl,iv,priv) | ||
| 66 | EVP_CIPHER_CTX *ctx; | ||
| 67 | EVP_CIPHER *type; | ||
| 68 | unsigned char *ek; | ||
| 69 | int ekl; | ||
| 70 | unsigned char *iv; | ||
| 71 | EVP_PKEY *priv; | ||
| 72 | { | ||
| 73 | unsigned char *key=NULL; | ||
| 74 | int i,size=0,ret=0; | ||
| 75 | |||
| 76 | if (priv->type != EVP_PKEY_RSA) | ||
| 77 | { | ||
| 78 | EVPerr(EVP_F_EVP_OPENINIT,EVP_R_PUBLIC_KEY_NOT_RSA); | ||
| 79 | ret= -1; | ||
| 80 | goto err; | ||
| 81 | } | ||
| 82 | |||
| 83 | size=RSA_size(priv->pkey.rsa); | ||
| 84 | key=(unsigned char *)Malloc(size+2); | ||
| 85 | if (key == NULL) | ||
| 86 | { | ||
| 87 | /* ERROR */ | ||
| 88 | EVPerr(EVP_F_EVP_OPENINIT,ERR_R_MALLOC_FAILURE); | ||
| 89 | ret= -1; | ||
| 90 | goto err; | ||
| 91 | } | ||
| 92 | |||
| 93 | i=EVP_PKEY_decrypt(key,ek,ekl,priv); | ||
| 94 | if (i != type->key_len) | ||
| 95 | { | ||
| 96 | /* ERROR */ | ||
| 97 | goto err; | ||
| 98 | } | ||
| 99 | |||
| 100 | EVP_CIPHER_CTX_init(ctx); | ||
| 101 | EVP_DecryptInit(ctx,type,key,iv); | ||
| 102 | ret=1; | ||
| 103 | err: | ||
| 104 | if (key != NULL) memset(key,0,size); | ||
| 105 | Free(key); | ||
| 106 | return(ret); | ||
| 107 | } | ||
| 108 | |||
| 109 | int EVP_OpenFinal(ctx,out,outl) | ||
| 110 | EVP_CIPHER_CTX *ctx; | ||
| 111 | unsigned char *out; | ||
| 112 | int *outl; | ||
| 113 | { | ||
| 114 | int i; | ||
| 115 | |||
| 116 | i=EVP_DecryptFinal(ctx,out,outl); | ||
| 117 | EVP_DecryptInit(ctx,NULL,NULL,NULL); | ||
| 118 | return(i); | ||
| 119 | } | ||
diff --git a/src/lib/libcrypto/evp/p_seal.c b/src/lib/libcrypto/evp/p_seal.c new file mode 100644 index 0000000000..09a408de35 --- /dev/null +++ b/src/lib/libcrypto/evp/p_seal.c | |||
| @@ -0,0 +1,115 @@ | |||
| 1 | /* crypto/evp/p_seal.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 "rand.h" | ||
| 62 | #include "rsa.h" | ||
| 63 | #include "evp.h" | ||
| 64 | #include "objects.h" | ||
| 65 | #include "x509.h" | ||
| 66 | |||
| 67 | int EVP_SealInit(ctx,type,ek,ekl,iv,pubk,npubk) | ||
| 68 | EVP_CIPHER_CTX *ctx; | ||
| 69 | EVP_CIPHER *type; | ||
| 70 | unsigned char **ek; | ||
| 71 | int *ekl; | ||
| 72 | unsigned char *iv; | ||
| 73 | EVP_PKEY **pubk; | ||
| 74 | int npubk; | ||
| 75 | { | ||
| 76 | unsigned char key[EVP_MAX_KEY_LENGTH]; | ||
| 77 | int i; | ||
| 78 | |||
| 79 | if (npubk <= 0) return(0); | ||
| 80 | RAND_bytes(key,EVP_MAX_KEY_LENGTH); | ||
| 81 | if (type->iv_len > 0) | ||
| 82 | RAND_bytes(iv,type->iv_len); | ||
| 83 | |||
| 84 | EVP_CIPHER_CTX_init(ctx); | ||
| 85 | EVP_EncryptInit(ctx,type,key,iv); | ||
| 86 | |||
| 87 | for (i=0; i<npubk; i++) | ||
| 88 | { | ||
| 89 | ekl[i]=EVP_PKEY_encrypt(ek[i],key,EVP_CIPHER_key_length(type), | ||
| 90 | pubk[i]); | ||
| 91 | if (ekl[i] <= 0) return(-1); | ||
| 92 | } | ||
| 93 | return(npubk); | ||
| 94 | } | ||
| 95 | |||
| 96 | /* MACRO | ||
| 97 | void EVP_SealUpdate(ctx,out,outl,in,inl) | ||
| 98 | EVP_CIPHER_CTX *ctx; | ||
| 99 | unsigned char *out; | ||
| 100 | int *outl; | ||
| 101 | unsigned char *in; | ||
| 102 | int inl; | ||
| 103 | { | ||
| 104 | EVP_EncryptUpdate(ctx,out,outl,in,inl); | ||
| 105 | } | ||
| 106 | */ | ||
| 107 | |||
| 108 | void EVP_SealFinal(ctx,out,outl) | ||
| 109 | EVP_CIPHER_CTX *ctx; | ||
| 110 | unsigned char *out; | ||
| 111 | int *outl; | ||
| 112 | { | ||
| 113 | EVP_EncryptFinal(ctx,out,outl); | ||
| 114 | EVP_EncryptInit(ctx,NULL,NULL,NULL); | ||
| 115 | } | ||
diff --git a/src/lib/libcrypto/evp/p_sign.c b/src/lib/libcrypto/evp/p_sign.c new file mode 100644 index 0000000000..073270ce31 --- /dev/null +++ b/src/lib/libcrypto/evp/p_sign.c | |||
| @@ -0,0 +1,119 @@ | |||
| 1 | /* crypto/evp/p_sign.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 "evp.h" | ||
| 62 | #include "objects.h" | ||
| 63 | #include "x509.h" | ||
| 64 | |||
| 65 | #ifdef undef | ||
| 66 | void EVP_SignInit(ctx,type) | ||
| 67 | EVP_MD_CTX *ctx; | ||
| 68 | EVP_MD *type; | ||
| 69 | { | ||
| 70 | EVP_DigestInit(ctx,type); | ||
| 71 | } | ||
| 72 | |||
| 73 | void EVP_SignUpdate(ctx,data,count) | ||
| 74 | EVP_MD_CTX *ctx; | ||
| 75 | unsigned char *data; | ||
| 76 | unsigned int count; | ||
| 77 | { | ||
| 78 | EVP_DigestUpdate(ctx,data,count); | ||
| 79 | } | ||
| 80 | #endif | ||
| 81 | |||
| 82 | int EVP_SignFinal(ctx,sigret,siglen,pkey) | ||
| 83 | EVP_MD_CTX *ctx; | ||
| 84 | unsigned char *sigret; | ||
| 85 | unsigned int *siglen; | ||
| 86 | EVP_PKEY *pkey; | ||
| 87 | { | ||
| 88 | unsigned char m[EVP_MAX_MD_SIZE]; | ||
| 89 | unsigned int m_len; | ||
| 90 | int i,ok=0,v; | ||
| 91 | MS_STATIC EVP_MD_CTX tmp_ctx; | ||
| 92 | |||
| 93 | *siglen=0; | ||
| 94 | memcpy(&tmp_ctx,ctx,sizeof(EVP_MD_CTX)); | ||
| 95 | EVP_DigestFinal(&tmp_ctx,&(m[0]),&m_len); | ||
| 96 | for (i=0; i<4; i++) | ||
| 97 | { | ||
| 98 | v=ctx->digest->required_pkey_type[i]; | ||
| 99 | if (v == 0) break; | ||
| 100 | if (pkey->type == v) | ||
| 101 | { | ||
| 102 | ok=1; | ||
| 103 | break; | ||
| 104 | } | ||
| 105 | } | ||
| 106 | if (!ok) | ||
| 107 | { | ||
| 108 | EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE); | ||
| 109 | return(0); | ||
| 110 | } | ||
| 111 | if (ctx->digest->sign == NULL) | ||
| 112 | { | ||
| 113 | EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_NO_SIGN_FUNCTION_CONFIGURED); | ||
| 114 | return(0); | ||
| 115 | } | ||
| 116 | return(ctx->digest->sign(ctx->digest->type,m,m_len,sigret,siglen, | ||
| 117 | pkey->pkey.ptr)); | ||
| 118 | } | ||
| 119 | |||
diff --git a/src/lib/libcrypto/evp/p_verify.c b/src/lib/libcrypto/evp/p_verify.c new file mode 100644 index 0000000000..8d727d8f02 --- /dev/null +++ b/src/lib/libcrypto/evp/p_verify.c | |||
| @@ -0,0 +1,102 @@ | |||
| 1 | /* crypto/evp/p_verify.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 "evp.h" | ||
| 62 | #include "objects.h" | ||
| 63 | #include "x509.h" | ||
| 64 | |||
| 65 | int EVP_VerifyFinal(ctx,sigbuf,siglen,pkey) | ||
| 66 | EVP_MD_CTX *ctx; | ||
| 67 | unsigned char *sigbuf; | ||
| 68 | unsigned int siglen; | ||
| 69 | EVP_PKEY *pkey; | ||
| 70 | { | ||
| 71 | unsigned char m[EVP_MAX_MD_SIZE]; | ||
| 72 | unsigned int m_len; | ||
| 73 | int i,ok=0,v; | ||
| 74 | MS_STATIC EVP_MD_CTX tmp_ctx; | ||
| 75 | |||
| 76 | for (i=0; i<4; i++) | ||
| 77 | { | ||
| 78 | v=ctx->digest->required_pkey_type[i]; | ||
| 79 | if (v == 0) break; | ||
| 80 | if (pkey->type == v) | ||
| 81 | { | ||
| 82 | ok=1; | ||
| 83 | break; | ||
| 84 | } | ||
| 85 | } | ||
| 86 | if (!ok) | ||
| 87 | { | ||
| 88 | EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE); | ||
| 89 | return(-1); | ||
| 90 | } | ||
| 91 | memcpy(&tmp_ctx,ctx,sizeof(EVP_MD_CTX)); | ||
| 92 | EVP_DigestFinal(&tmp_ctx,&(m[0]),&m_len); | ||
| 93 | if (ctx->digest->verify == NULL) | ||
| 94 | { | ||
| 95 | EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_NO_VERIFY_FUNCTION_CONFIGURED); | ||
| 96 | return(0); | ||
| 97 | } | ||
| 98 | |||
| 99 | return(ctx->digest->verify(ctx->digest->type,m,m_len, | ||
| 100 | sigbuf,siglen,pkey->pkey.ptr)); | ||
| 101 | } | ||
| 102 | |||
diff --git a/src/lib/libcrypto/ex_data.c b/src/lib/libcrypto/ex_data.c new file mode 100644 index 0000000000..c858b518ff --- /dev/null +++ b/src/lib/libcrypto/ex_data.c | |||
| @@ -0,0 +1,236 @@ | |||
| 1 | /* crypto/ex_data.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 <stdlib.h> | ||
| 61 | #include "buffer.h" | ||
| 62 | #include "bio.h" | ||
| 63 | #include "lhash.h" | ||
| 64 | #include "cryptlib.h" | ||
| 65 | |||
| 66 | int CRYPTO_get_ex_new_index(idx,skp,argl,argp,new_func,dup_func,free_func) | ||
| 67 | int idx; | ||
| 68 | STACK **skp; | ||
| 69 | long argl; | ||
| 70 | char *argp; | ||
| 71 | int (*new_func)(); | ||
| 72 | int (*dup_func)(); | ||
| 73 | void (*free_func)(); | ||
| 74 | { | ||
| 75 | CRYPTO_EX_DATA_FUNCS *a; | ||
| 76 | |||
| 77 | if (*skp == NULL) | ||
| 78 | *skp=sk_new_null(); | ||
| 79 | if (*skp == NULL) | ||
| 80 | { | ||
| 81 | CRYPTOerr(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,ERR_R_MALLOC_FAILURE); | ||
| 82 | return(-1); | ||
| 83 | } | ||
| 84 | a=(CRYPTO_EX_DATA_FUNCS *)Malloc(sizeof(CRYPTO_EX_DATA_FUNCS)); | ||
| 85 | if (a == NULL) | ||
| 86 | { | ||
| 87 | CRYPTOerr(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,ERR_R_MALLOC_FAILURE); | ||
| 88 | return(-1); | ||
| 89 | } | ||
| 90 | a->argl=argl; | ||
| 91 | a->argp=argp; | ||
| 92 | a->new_func=new_func; | ||
| 93 | a->dup_func=dup_func; | ||
| 94 | a->free_func=free_func; | ||
| 95 | while (sk_num(*skp) <= idx) | ||
| 96 | { | ||
| 97 | if (!sk_push(*skp,NULL)) | ||
| 98 | { | ||
| 99 | CRYPTOerr(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,ERR_R_MALLOC_FAILURE); | ||
| 100 | Free(a); | ||
| 101 | return(-1); | ||
| 102 | } | ||
| 103 | } | ||
| 104 | sk_value(*skp,idx)=(char *)a; | ||
| 105 | return(idx); | ||
| 106 | } | ||
| 107 | |||
| 108 | int CRYPTO_set_ex_data(ad,idx,val) | ||
| 109 | CRYPTO_EX_DATA *ad; | ||
| 110 | int idx; | ||
| 111 | char *val; | ||
| 112 | { | ||
| 113 | int i; | ||
| 114 | |||
| 115 | if (ad->sk == NULL) | ||
| 116 | { | ||
| 117 | if ((ad->sk=sk_new_null()) == NULL) | ||
| 118 | { | ||
| 119 | CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA,ERR_R_MALLOC_FAILURE); | ||
| 120 | return(0); | ||
| 121 | } | ||
| 122 | } | ||
| 123 | i=sk_num(ad->sk); | ||
| 124 | |||
| 125 | while (i <= idx) | ||
| 126 | { | ||
| 127 | if (!sk_push(ad->sk,NULL)) | ||
| 128 | { | ||
| 129 | CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA,ERR_R_MALLOC_FAILURE); | ||
| 130 | return(0); | ||
| 131 | } | ||
| 132 | i++; | ||
| 133 | } | ||
| 134 | sk_value(ad->sk,idx)=val; | ||
| 135 | return(1); | ||
| 136 | } | ||
| 137 | |||
| 138 | char *CRYPTO_get_ex_data(ad,idx) | ||
| 139 | CRYPTO_EX_DATA *ad; | ||
| 140 | int idx; | ||
| 141 | { | ||
| 142 | if (ad->sk == NULL) | ||
| 143 | return(0); | ||
| 144 | else if (idx >= sk_num(ad->sk)) | ||
| 145 | return(0); | ||
| 146 | else | ||
| 147 | return(sk_value(ad->sk,idx)); | ||
| 148 | } | ||
| 149 | |||
| 150 | /* The callback is called with the 'object', which is the origional data object | ||
| 151 | * being duplicated, a pointer to the | ||
| 152 | * 'new' object to be inserted, the index, and the argi/argp | ||
| 153 | */ | ||
| 154 | int CRYPTO_dup_ex_data(meth,to,from) | ||
| 155 | STACK *meth; | ||
| 156 | CRYPTO_EX_DATA *to,*from; | ||
| 157 | { | ||
| 158 | int i,j,m,r; | ||
| 159 | CRYPTO_EX_DATA_FUNCS *mm; | ||
| 160 | char *from_d; | ||
| 161 | |||
| 162 | if (meth == NULL) return(1); | ||
| 163 | if (from->sk == NULL) return(1); | ||
| 164 | m=sk_num(meth); | ||
| 165 | j=sk_num(from->sk); | ||
| 166 | for (i=0; i<j; i++) | ||
| 167 | { | ||
| 168 | from_d=CRYPTO_get_ex_data(from,i); | ||
| 169 | if (i < m) | ||
| 170 | { | ||
| 171 | mm=(CRYPTO_EX_DATA_FUNCS *)sk_value(meth,i); | ||
| 172 | if (mm->dup_func != NULL) | ||
| 173 | r=mm->dup_func(to,from,(char **)&from_d,i, | ||
| 174 | mm->argl,mm->argp); | ||
| 175 | } | ||
| 176 | CRYPTO_set_ex_data(to,i,from_d); | ||
| 177 | } | ||
| 178 | return(1); | ||
| 179 | } | ||
| 180 | |||
| 181 | /* Call each free callback */ | ||
| 182 | void CRYPTO_free_ex_data(meth,obj,ad) | ||
| 183 | STACK *meth; | ||
| 184 | char *obj; | ||
| 185 | CRYPTO_EX_DATA *ad; | ||
| 186 | { | ||
| 187 | CRYPTO_EX_DATA_FUNCS *m; | ||
| 188 | char *ptr; | ||
| 189 | int i,max; | ||
| 190 | |||
| 191 | if (meth != NULL) | ||
| 192 | { | ||
| 193 | max=sk_num(meth); | ||
| 194 | for (i=0; i<max; i++) | ||
| 195 | { | ||
| 196 | m=(CRYPTO_EX_DATA_FUNCS *)sk_value(meth,i); | ||
| 197 | if ((m != NULL) && (m->free_func != NULL)) | ||
| 198 | { | ||
| 199 | ptr=CRYPTO_get_ex_data(ad,i); | ||
| 200 | m->free_func(obj,ptr,ad,i,m->argl,m->argp); | ||
| 201 | } | ||
| 202 | } | ||
| 203 | } | ||
| 204 | if (ad->sk != NULL) | ||
| 205 | { | ||
| 206 | sk_free(ad->sk); | ||
| 207 | ad->sk=NULL; | ||
| 208 | } | ||
| 209 | } | ||
| 210 | |||
| 211 | void CRYPTO_new_ex_data(meth,obj,ad) | ||
| 212 | STACK *meth; | ||
| 213 | char *obj; | ||
| 214 | CRYPTO_EX_DATA *ad; | ||
| 215 | { | ||
| 216 | CRYPTO_EX_DATA_FUNCS *m; | ||
| 217 | char *ptr; | ||
| 218 | int i,max; | ||
| 219 | |||
| 220 | ad->sk=NULL; | ||
| 221 | if (meth != NULL) | ||
| 222 | { | ||
| 223 | max=sk_num(meth); | ||
| 224 | for (i=0; i<max; i++) | ||
| 225 | { | ||
| 226 | m=(CRYPTO_EX_DATA_FUNCS *)sk_value(meth,i); | ||
| 227 | if ((m != NULL) && (m->new_func != NULL)) | ||
| 228 | { | ||
| 229 | ptr=CRYPTO_get_ex_data(ad,i); | ||
| 230 | m->new_func(obj,ptr,ad,i,m->argl,m->argp); | ||
| 231 | } | ||
| 232 | } | ||
| 233 | } | ||
| 234 | } | ||
| 235 | |||
| 236 | |||
diff --git a/src/lib/libcrypto/hmac/hmac.c b/src/lib/libcrypto/hmac/hmac.c new file mode 100644 index 0000000000..fb09129963 --- /dev/null +++ b/src/lib/libcrypto/hmac/hmac.c | |||
| @@ -0,0 +1,165 @@ | |||
| 1 | /* crypto/hmac/hmac.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 | #include <stdio.h> | ||
| 59 | #include <stdlib.h> | ||
| 60 | #include <string.h> | ||
| 61 | #include "hmac.h" | ||
| 62 | |||
| 63 | void HMAC_Init(ctx,key,len,md) | ||
| 64 | HMAC_CTX *ctx; | ||
| 65 | unsigned char *key; | ||
| 66 | int len; | ||
| 67 | EVP_MD *md; | ||
| 68 | { | ||
| 69 | int i,j,reset=0; | ||
| 70 | unsigned char pad[HMAC_MAX_MD_CBLOCK]; | ||
| 71 | |||
| 72 | if (md != NULL) | ||
| 73 | { | ||
| 74 | reset=1; | ||
| 75 | ctx->md=md; | ||
| 76 | } | ||
| 77 | else | ||
| 78 | md=ctx->md; | ||
| 79 | |||
| 80 | if (key != NULL) | ||
| 81 | { | ||
| 82 | reset=1; | ||
| 83 | j=EVP_MD_block_size(md); | ||
| 84 | if (j < len) | ||
| 85 | { | ||
| 86 | EVP_DigestInit(&ctx->md_ctx,md); | ||
| 87 | EVP_DigestUpdate(&ctx->md_ctx,key,len); | ||
| 88 | EVP_DigestFinal(&(ctx->md_ctx),ctx->key, | ||
| 89 | &ctx->key_length); | ||
| 90 | } | ||
| 91 | else | ||
| 92 | { | ||
| 93 | memcpy(ctx->key,key,len); | ||
| 94 | memset(&(ctx->key[len]),0,sizeof(ctx->key)-len); | ||
| 95 | ctx->key_length=len; | ||
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 99 | if (reset) | ||
| 100 | { | ||
| 101 | for (i=0; i<HMAC_MAX_MD_CBLOCK; i++) | ||
| 102 | pad[i]=0x36^ctx->key[i]; | ||
| 103 | EVP_DigestInit(&ctx->i_ctx,md); | ||
| 104 | EVP_DigestUpdate(&ctx->i_ctx,pad,EVP_MD_block_size(md)); | ||
| 105 | |||
| 106 | for (i=0; i<HMAC_MAX_MD_CBLOCK; i++) | ||
| 107 | pad[i]=0x5c^ctx->key[i]; | ||
| 108 | EVP_DigestInit(&ctx->o_ctx,md); | ||
| 109 | EVP_DigestUpdate(&ctx->o_ctx,pad,EVP_MD_block_size(md)); | ||
| 110 | } | ||
| 111 | |||
| 112 | memcpy(&ctx->md_ctx,&ctx->i_ctx,sizeof(ctx->i_ctx)); | ||
| 113 | } | ||
| 114 | |||
| 115 | void HMAC_Update(ctx,data,len) | ||
| 116 | HMAC_CTX *ctx; | ||
| 117 | unsigned char *data; | ||
| 118 | int len; | ||
| 119 | { | ||
| 120 | EVP_DigestUpdate(&(ctx->md_ctx),data,len); | ||
| 121 | } | ||
| 122 | |||
| 123 | void HMAC_Final(ctx,md,len) | ||
| 124 | HMAC_CTX *ctx; | ||
| 125 | unsigned char *md; | ||
| 126 | unsigned int *len; | ||
| 127 | { | ||
| 128 | int j; | ||
| 129 | unsigned int i; | ||
| 130 | unsigned char buf[EVP_MAX_MD_SIZE]; | ||
| 131 | |||
| 132 | j=EVP_MD_block_size(ctx->md); | ||
| 133 | |||
| 134 | EVP_DigestFinal(&(ctx->md_ctx),buf,&i); | ||
| 135 | memcpy(&(ctx->md_ctx),&(ctx->o_ctx),sizeof(ctx->o_ctx)); | ||
| 136 | EVP_DigestUpdate(&(ctx->md_ctx),buf,i); | ||
| 137 | EVP_DigestFinal(&(ctx->md_ctx),md,len); | ||
| 138 | } | ||
| 139 | |||
| 140 | void HMAC_cleanup(ctx) | ||
| 141 | HMAC_CTX *ctx; | ||
| 142 | { | ||
| 143 | memset(ctx,0,sizeof(HMAC_CTX)); | ||
| 144 | } | ||
| 145 | |||
| 146 | unsigned char *HMAC(evp_md,key,key_len,d,n,md,md_len) | ||
| 147 | EVP_MD *evp_md; | ||
| 148 | unsigned char *key; | ||
| 149 | int key_len; | ||
| 150 | unsigned char *d; | ||
| 151 | int n; | ||
| 152 | unsigned char *md; | ||
| 153 | unsigned int *md_len; | ||
| 154 | { | ||
| 155 | HMAC_CTX c; | ||
| 156 | static unsigned char m[EVP_MAX_MD_SIZE]; | ||
| 157 | |||
| 158 | if (md == NULL) md=m; | ||
| 159 | HMAC_Init(&c,key,key_len,evp_md); | ||
| 160 | HMAC_Update(&c,d,n); | ||
| 161 | HMAC_Final(&c,md,md_len); | ||
| 162 | HMAC_cleanup(&c); | ||
| 163 | return(md); | ||
| 164 | } | ||
| 165 | |||
diff --git a/src/lib/libcrypto/hmac/hmac.h b/src/lib/libcrypto/hmac/hmac.h new file mode 100644 index 0000000000..e6b43f52c4 --- /dev/null +++ b/src/lib/libcrypto/hmac/hmac.h | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | /* crypto/hmac/hmac.h */ | ||
| 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 | #ifndef HEADER_HMAC_H | ||
| 59 | #define HEADER_HMAC_H | ||
| 60 | |||
| 61 | #ifdef __cplusplus | ||
| 62 | extern "C" { | ||
| 63 | #endif | ||
| 64 | |||
| 65 | #include "evp.h" | ||
| 66 | |||
| 67 | #define HMAC_MAX_MD_CBLOCK 64 | ||
| 68 | |||
| 69 | typedef struct hmac_ctx_st | ||
| 70 | { | ||
| 71 | EVP_MD *md; | ||
| 72 | EVP_MD_CTX md_ctx; | ||
| 73 | EVP_MD_CTX i_ctx; | ||
| 74 | EVP_MD_CTX o_ctx; | ||
| 75 | unsigned int key_length; | ||
| 76 | unsigned char key[HMAC_MAX_MD_CBLOCK]; | ||
| 77 | } HMAC_CTX; | ||
| 78 | |||
| 79 | #define HMAC_size(e) (EVP_MD_size((e)->md)) | ||
| 80 | |||
| 81 | #ifndef NOPROTO | ||
| 82 | |||
| 83 | void HMAC_Init(HMAC_CTX *ctx, unsigned char *key, int len, | ||
| 84 | EVP_MD *md); | ||
| 85 | void HMAC_Update(HMAC_CTX *ctx,unsigned char *key, int len); | ||
| 86 | void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len); | ||
| 87 | void HMAC_cleanup(HMAC_CTX *ctx); | ||
| 88 | unsigned char *HMAC(EVP_MD *evp_md, unsigned char *key, int key_len, | ||
| 89 | unsigned char *d, int n, unsigned char *md, unsigned int *md_len); | ||
| 90 | |||
| 91 | |||
| 92 | #else | ||
| 93 | |||
| 94 | void HMAC_Init(); | ||
| 95 | void HMAC_Update(); | ||
| 96 | void HMAC_Final(); | ||
| 97 | void HMAC_cleanup(); | ||
| 98 | unsigned char *HMAC(); | ||
| 99 | |||
| 100 | #endif | ||
| 101 | |||
| 102 | #ifdef __cplusplus | ||
| 103 | } | ||
| 104 | #endif | ||
| 105 | |||
| 106 | #endif | ||
diff --git a/src/lib/libcrypto/lhash/lh_stats.c b/src/lib/libcrypto/lhash/lh_stats.c new file mode 100644 index 0000000000..23fe82f777 --- /dev/null +++ b/src/lib/libcrypto/lhash/lh_stats.c | |||
| @@ -0,0 +1,289 @@ | |||
| 1 | /* crypto/lhash/lh_stats.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 <string.h> | ||
| 61 | #include <stdlib.h> | ||
| 62 | /* If you wish to build this outside of SSLeay, remove the following lines | ||
| 63 | * and things should work as expected */ | ||
| 64 | #include "cryptlib.h" | ||
| 65 | |||
| 66 | #include "lhash.h" | ||
| 67 | |||
| 68 | #ifndef HEADER_BIO_H | ||
| 69 | |||
| 70 | void lh_stats(lh, out) | ||
| 71 | LHASH *lh; | ||
| 72 | FILE *out; | ||
| 73 | { | ||
| 74 | fprintf(out,"num_items = %lu\n",lh->num_items); | ||
| 75 | fprintf(out,"num_nodes = %u\n",lh->num_nodes); | ||
| 76 | fprintf(out,"num_alloc_nodes = %u\n",lh->num_alloc_nodes); | ||
| 77 | fprintf(out,"num_expands = %lu\n",lh->num_expands); | ||
| 78 | fprintf(out,"num_expand_reallocs = %lu\n",lh->num_expand_reallocs); | ||
| 79 | fprintf(out,"num_contracts = %lu\n",lh->num_contracts); | ||
| 80 | fprintf(out,"num_contract_reallocs = %lu\n",lh->num_contract_reallocs); | ||
| 81 | fprintf(out,"num_hash_calls = %lu\n",lh->num_hash_calls); | ||
| 82 | fprintf(out,"num_comp_calls = %lu\n",lh->num_comp_calls); | ||
| 83 | fprintf(out,"num_insert = %lu\n",lh->num_insert); | ||
| 84 | fprintf(out,"num_replace = %lu\n",lh->num_replace); | ||
| 85 | fprintf(out,"num_delete = %lu\n",lh->num_delete); | ||
| 86 | fprintf(out,"num_no_delete = %lu\n",lh->num_no_delete); | ||
| 87 | fprintf(out,"num_retrieve = %lu\n",lh->num_retrieve); | ||
| 88 | fprintf(out,"num_retrieve_miss = %lu\n",lh->num_retrieve_miss); | ||
| 89 | fprintf(out,"num_hash_comps = %lu\n",lh->num_hash_comps); | ||
| 90 | #ifdef DEBUG | ||
| 91 | fprintf(out,"p = %u\n",lh->p); | ||
| 92 | fprintf(out,"pmax = %u\n",lh->pmax); | ||
| 93 | fprintf(out,"up_load = %lu\n",lh->up_load); | ||
| 94 | fprintf(out,"down_load = %lu\n",lh->down_load); | ||
| 95 | #endif | ||
| 96 | } | ||
| 97 | |||
| 98 | void lh_node_stats(lh, out) | ||
| 99 | LHASH *lh; | ||
| 100 | FILE *out; | ||
| 101 | { | ||
| 102 | LHASH_NODE *n; | ||
| 103 | unsigned int i,num; | ||
| 104 | |||
| 105 | for (i=0; i<lh->num_nodes; i++) | ||
| 106 | { | ||
| 107 | for (n=lh->b[i],num=0; n != NULL; n=n->next) | ||
| 108 | num++; | ||
| 109 | fprintf(out,"node %6u -> %3u\n",i,num); | ||
| 110 | } | ||
| 111 | } | ||
| 112 | |||
| 113 | void lh_node_usage_stats(lh, out) | ||
| 114 | LHASH *lh; | ||
| 115 | FILE *out; | ||
| 116 | { | ||
| 117 | LHASH_NODE *n; | ||
| 118 | unsigned long num; | ||
| 119 | unsigned int i; | ||
| 120 | unsigned long total=0,n_used=0; | ||
| 121 | |||
| 122 | for (i=0; i<lh->num_nodes; i++) | ||
| 123 | { | ||
| 124 | for (n=lh->b[i],num=0; n != NULL; n=n->next) | ||
| 125 | num++; | ||
| 126 | if (num != 0) | ||
| 127 | { | ||
| 128 | n_used++; | ||
| 129 | total+=num; | ||
| 130 | } | ||
| 131 | } | ||
| 132 | fprintf(out,"%lu nodes used out of %u\n",n_used,lh->num_nodes); | ||
| 133 | fprintf(out,"%lu items\n",total); | ||
| 134 | if (n_used == 0) return; | ||
| 135 | fprintf(out,"load %d.%02d actual load %d.%02d\n", | ||
| 136 | (int)(total/lh->num_nodes), | ||
| 137 | (int)((total%lh->num_nodes)*100/lh->num_nodes), | ||
| 138 | (int)(total/n_used), | ||
| 139 | (int)((total%n_used)*100/n_used)); | ||
| 140 | } | ||
| 141 | |||
| 142 | #else | ||
| 143 | |||
| 144 | #ifndef NO_FP_API | ||
| 145 | void lh_stats(lh,fp) | ||
| 146 | LHASH *lh; | ||
| 147 | FILE *fp; | ||
| 148 | { | ||
| 149 | BIO *bp; | ||
| 150 | |||
| 151 | bp=BIO_new(BIO_s_file()); | ||
| 152 | if (bp == NULL) goto end; | ||
| 153 | BIO_set_fp(bp,fp,BIO_NOCLOSE); | ||
| 154 | lh_stats_bio(lh,bp); | ||
| 155 | BIO_free(bp); | ||
| 156 | end:; | ||
| 157 | } | ||
| 158 | |||
| 159 | void lh_node_stats(lh,fp) | ||
| 160 | LHASH *lh; | ||
| 161 | FILE *fp; | ||
| 162 | { | ||
| 163 | BIO *bp; | ||
| 164 | |||
| 165 | bp=BIO_new(BIO_s_file()); | ||
| 166 | if (bp == NULL) goto end; | ||
| 167 | BIO_set_fp(bp,fp,BIO_NOCLOSE); | ||
| 168 | lh_node_stats_bio(lh,bp); | ||
| 169 | BIO_free(bp); | ||
| 170 | end:; | ||
| 171 | } | ||
| 172 | |||
| 173 | void lh_node_usage_stats(lh,fp) | ||
| 174 | LHASH *lh; | ||
| 175 | FILE *fp; | ||
| 176 | { | ||
| 177 | BIO *bp; | ||
| 178 | |||
| 179 | bp=BIO_new(BIO_s_file()); | ||
| 180 | if (bp == NULL) goto end; | ||
| 181 | BIO_set_fp(bp,fp,BIO_NOCLOSE); | ||
| 182 | lh_node_usage_stats_bio(lh,bp); | ||
| 183 | BIO_free(bp); | ||
| 184 | end:; | ||
| 185 | } | ||
| 186 | |||
| 187 | #endif | ||
| 188 | |||
| 189 | void lh_stats_bio(lh, out) | ||
| 190 | LHASH *lh; | ||
| 191 | BIO *out; | ||
| 192 | { | ||
| 193 | char buf[128]; | ||
| 194 | |||
| 195 | sprintf(buf,"num_items = %lu\n",lh->num_items); | ||
| 196 | BIO_puts(out,buf); | ||
| 197 | sprintf(buf,"num_nodes = %u\n",lh->num_nodes); | ||
| 198 | BIO_puts(out,buf); | ||
| 199 | sprintf(buf,"num_alloc_nodes = %u\n",lh->num_alloc_nodes); | ||
| 200 | BIO_puts(out,buf); | ||
| 201 | sprintf(buf,"num_expands = %lu\n",lh->num_expands); | ||
| 202 | BIO_puts(out,buf); | ||
| 203 | sprintf(buf,"num_expand_reallocs = %lu\n",lh->num_expand_reallocs); | ||
| 204 | BIO_puts(out,buf); | ||
| 205 | sprintf(buf,"num_contracts = %lu\n",lh->num_contracts); | ||
| 206 | BIO_puts(out,buf); | ||
| 207 | sprintf(buf,"num_contract_reallocs = %lu\n",lh->num_contract_reallocs); | ||
| 208 | BIO_puts(out,buf); | ||
| 209 | sprintf(buf,"num_hash_calls = %lu\n",lh->num_hash_calls); | ||
| 210 | BIO_puts(out,buf); | ||
| 211 | sprintf(buf,"num_comp_calls = %lu\n",lh->num_comp_calls); | ||
| 212 | BIO_puts(out,buf); | ||
| 213 | sprintf(buf,"num_insert = %lu\n",lh->num_insert); | ||
| 214 | BIO_puts(out,buf); | ||
| 215 | sprintf(buf,"num_replace = %lu\n",lh->num_replace); | ||
| 216 | BIO_puts(out,buf); | ||
| 217 | sprintf(buf,"num_delete = %lu\n",lh->num_delete); | ||
| 218 | BIO_puts(out,buf); | ||
| 219 | sprintf(buf,"num_no_delete = %lu\n",lh->num_no_delete); | ||
| 220 | BIO_puts(out,buf); | ||
| 221 | sprintf(buf,"num_retrieve = %lu\n",lh->num_retrieve); | ||
| 222 | BIO_puts(out,buf); | ||
| 223 | sprintf(buf,"num_retrieve_miss = %lu\n",lh->num_retrieve_miss); | ||
| 224 | BIO_puts(out,buf); | ||
| 225 | sprintf(buf,"num_hash_comps = %lu\n",lh->num_hash_comps); | ||
| 226 | BIO_puts(out,buf); | ||
| 227 | #ifdef DEBUG | ||
| 228 | sprintf(buf,"p = %u\n",lh->p); | ||
| 229 | BIO_puts(out,buf); | ||
| 230 | sprintf(buf,"pmax = %u\n",lh->pmax); | ||
| 231 | BIO_puts(out,buf); | ||
| 232 | sprintf(buf,"up_load = %lu\n",lh->up_load); | ||
| 233 | BIO_puts(out,buf); | ||
| 234 | sprintf(buf,"down_load = %lu\n",lh->down_load); | ||
| 235 | BIO_puts(out,buf); | ||
| 236 | #endif | ||
| 237 | } | ||
| 238 | |||
| 239 | void lh_node_stats_bio(lh, out) | ||
| 240 | LHASH *lh; | ||
| 241 | BIO *out; | ||
| 242 | { | ||
| 243 | LHASH_NODE *n; | ||
| 244 | unsigned int i,num; | ||
| 245 | char buf[128]; | ||
| 246 | |||
| 247 | for (i=0; i<lh->num_nodes; i++) | ||
| 248 | { | ||
| 249 | for (n=lh->b[i],num=0; n != NULL; n=n->next) | ||
| 250 | num++; | ||
| 251 | sprintf(buf,"node %6u -> %3u\n",i,num); | ||
| 252 | BIO_puts(out,buf); | ||
| 253 | } | ||
| 254 | } | ||
| 255 | |||
| 256 | void lh_node_usage_stats_bio(lh, out) | ||
| 257 | LHASH *lh; | ||
| 258 | BIO *out; | ||
| 259 | { | ||
| 260 | LHASH_NODE *n; | ||
| 261 | unsigned long num; | ||
| 262 | unsigned int i; | ||
| 263 | unsigned long total=0,n_used=0; | ||
| 264 | char buf[128]; | ||
| 265 | |||
| 266 | for (i=0; i<lh->num_nodes; i++) | ||
| 267 | { | ||
| 268 | for (n=lh->b[i],num=0; n != NULL; n=n->next) | ||
| 269 | num++; | ||
| 270 | if (num != 0) | ||
| 271 | { | ||
| 272 | n_used++; | ||
| 273 | total+=num; | ||
| 274 | } | ||
| 275 | } | ||
| 276 | sprintf(buf,"%lu nodes used out of %u\n",n_used,lh->num_nodes); | ||
| 277 | BIO_puts(out,buf); | ||
| 278 | sprintf(buf,"%lu items\n",total); | ||
| 279 | BIO_puts(out,buf); | ||
| 280 | if (n_used == 0) return; | ||
| 281 | sprintf(buf,"load %d.%02d actual load %d.%02d\n", | ||
| 282 | (int)(total/lh->num_nodes), | ||
| 283 | (int)((total%lh->num_nodes)*100/lh->num_nodes), | ||
| 284 | (int)(total/n_used), | ||
| 285 | (int)((total%n_used)*100/n_used)); | ||
| 286 | BIO_puts(out,buf); | ||
| 287 | } | ||
| 288 | |||
| 289 | #endif | ||
diff --git a/src/lib/libcrypto/lhash/lhash.c b/src/lib/libcrypto/lhash/lhash.c new file mode 100644 index 0000000000..6dfb5c9ccc --- /dev/null +++ b/src/lib/libcrypto/lhash/lhash.c | |||
| @@ -0,0 +1,489 @@ | |||
| 1 | /* crypto/lhash/lhash.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 | char *lh_version="lhash part of SSLeay 0.9.0b 29-Jun-1998"; | ||
| 60 | |||
| 61 | /* Code for dynamic hash table routines | ||
| 62 | * Author - Eric Young v 2.0 | ||
| 63 | * | ||
| 64 | * 2.0 eay - Fixed a bug that occured when using lh_delete | ||
| 65 | * from inside lh_doall(). As entries were deleted, | ||
| 66 | * the 'table' was 'contract()ed', making some entries | ||
| 67 | * jump from the end of the table to the start, there by | ||
| 68 | * skiping the lh_doall() processing. eay - 4/12/95 | ||
| 69 | * | ||
| 70 | * 1.9 eay - Fixed a memory leak in lh_free, the LHASH_NODEs | ||
| 71 | * were not being free()ed. 21/11/95 | ||
| 72 | * | ||
| 73 | * 1.8 eay - Put the stats routines into a separate file, lh_stats.c | ||
| 74 | * 19/09/95 | ||
| 75 | * | ||
| 76 | * 1.7 eay - Removed the fputs() for realloc failures - the code | ||
| 77 | * should silently tolerate them. I have also fixed things | ||
| 78 | * lint complained about 04/05/95 | ||
| 79 | * | ||
| 80 | * 1.6 eay - Fixed an invalid pointers in contract/expand 27/07/92 | ||
| 81 | * | ||
| 82 | * 1.5 eay - Fixed a misuse of realloc in expand 02/03/1992 | ||
| 83 | * | ||
| 84 | * 1.4 eay - Fixed lh_doall so the function can call lh_delete 28/05/91 | ||
| 85 | * | ||
| 86 | * 1.3 eay - Fixed a few lint problems 19/3/1991 | ||
| 87 | * | ||
| 88 | * 1.2 eay - Fixed lh_doall problem 13/3/1991 | ||
| 89 | * | ||
| 90 | * 1.1 eay - Added lh_doall | ||
| 91 | * | ||
| 92 | * 1.0 eay - First version | ||
| 93 | */ | ||
| 94 | #include <stdio.h> | ||
| 95 | #include <string.h> | ||
| 96 | #include <stdlib.h> | ||
| 97 | #include "lhash.h" | ||
| 98 | |||
| 99 | #undef MIN_NODES | ||
| 100 | #define MIN_NODES 16 | ||
| 101 | #define UP_LOAD (2*LH_LOAD_MULT) /* load times 256 (default 2) */ | ||
| 102 | #define DOWN_LOAD (LH_LOAD_MULT) /* load times 256 (default 1) */ | ||
| 103 | |||
| 104 | #ifndef NOPROTO | ||
| 105 | |||
| 106 | #define P_CP char * | ||
| 107 | #define P_CPP char *,char * | ||
| 108 | static void expand(LHASH *lh); | ||
| 109 | static void contract(LHASH *lh); | ||
| 110 | static LHASH_NODE **getrn(LHASH *lh, char *data, unsigned long *rhash); | ||
| 111 | |||
| 112 | #else | ||
| 113 | |||
| 114 | #define P_CP | ||
| 115 | #define P_CPP | ||
| 116 | static void expand(); | ||
| 117 | static void contract(); | ||
| 118 | static LHASH_NODE **getrn(); | ||
| 119 | |||
| 120 | #endif | ||
| 121 | |||
| 122 | LHASH *lh_new(h, c) | ||
| 123 | unsigned long (*h)(); | ||
| 124 | int (*c)(); | ||
| 125 | { | ||
| 126 | LHASH *ret; | ||
| 127 | int i; | ||
| 128 | |||
| 129 | if ((ret=(LHASH *)malloc(sizeof(LHASH))) == NULL) | ||
| 130 | goto err0; | ||
| 131 | if ((ret->b=(LHASH_NODE **)malloc(sizeof(LHASH_NODE *)*MIN_NODES)) == NULL) | ||
| 132 | goto err1; | ||
| 133 | for (i=0; i<MIN_NODES; i++) | ||
| 134 | ret->b[i]=NULL; | ||
| 135 | ret->comp=((c == NULL)?(int (*)())strcmp:c); | ||
| 136 | ret->hash=((h == NULL)?(unsigned long (*)())lh_strhash:h); | ||
| 137 | ret->num_nodes=MIN_NODES/2; | ||
| 138 | ret->num_alloc_nodes=MIN_NODES; | ||
| 139 | ret->p=0; | ||
| 140 | ret->pmax=MIN_NODES/2; | ||
| 141 | ret->up_load=UP_LOAD; | ||
| 142 | ret->down_load=DOWN_LOAD; | ||
| 143 | ret->num_items=0; | ||
| 144 | |||
| 145 | ret->num_expands=0; | ||
| 146 | ret->num_expand_reallocs=0; | ||
| 147 | ret->num_contracts=0; | ||
| 148 | ret->num_contract_reallocs=0; | ||
| 149 | ret->num_hash_calls=0; | ||
| 150 | ret->num_comp_calls=0; | ||
| 151 | ret->num_insert=0; | ||
| 152 | ret->num_replace=0; | ||
| 153 | ret->num_delete=0; | ||
| 154 | ret->num_no_delete=0; | ||
| 155 | ret->num_retrieve=0; | ||
| 156 | ret->num_retrieve_miss=0; | ||
| 157 | ret->num_hash_comps=0; | ||
| 158 | |||
| 159 | return(ret); | ||
| 160 | err1: | ||
| 161 | free((char *)ret); | ||
| 162 | err0: | ||
| 163 | return(NULL); | ||
| 164 | } | ||
| 165 | |||
| 166 | void lh_free(lh) | ||
| 167 | LHASH *lh; | ||
| 168 | { | ||
| 169 | unsigned int i; | ||
| 170 | LHASH_NODE *n,*nn; | ||
| 171 | |||
| 172 | for (i=0; i<lh->num_nodes; i++) | ||
| 173 | { | ||
| 174 | n=lh->b[i]; | ||
| 175 | while (n != NULL) | ||
| 176 | { | ||
| 177 | nn=n->next; | ||
| 178 | free(n); | ||
| 179 | n=nn; | ||
| 180 | } | ||
| 181 | } | ||
| 182 | free((char *)lh->b); | ||
| 183 | free((char *)lh); | ||
| 184 | } | ||
| 185 | |||
| 186 | char *lh_insert(lh, data) | ||
| 187 | LHASH *lh; | ||
| 188 | char *data; | ||
| 189 | { | ||
| 190 | unsigned long hash; | ||
| 191 | LHASH_NODE *nn,**rn; | ||
| 192 | char *ret; | ||
| 193 | |||
| 194 | if (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)) | ||
| 195 | expand(lh); | ||
| 196 | |||
| 197 | rn=getrn(lh,data,&hash); | ||
| 198 | |||
| 199 | if (*rn == NULL) | ||
| 200 | { | ||
| 201 | if ((nn=(LHASH_NODE *)malloc(sizeof(LHASH_NODE))) == NULL) | ||
| 202 | return(NULL); | ||
| 203 | nn->data=data; | ||
| 204 | nn->next=NULL; | ||
| 205 | #ifndef NO_HASH_COMP | ||
| 206 | nn->hash=hash; | ||
| 207 | #endif | ||
| 208 | *rn=nn; | ||
| 209 | ret=NULL; | ||
| 210 | lh->num_insert++; | ||
| 211 | lh->num_items++; | ||
| 212 | } | ||
| 213 | else /* replace same key */ | ||
| 214 | { | ||
| 215 | ret= (*rn)->data; | ||
| 216 | (*rn)->data=data; | ||
| 217 | lh->num_replace++; | ||
| 218 | } | ||
| 219 | return(ret); | ||
| 220 | } | ||
| 221 | |||
| 222 | char *lh_delete(lh, data) | ||
| 223 | LHASH *lh; | ||
| 224 | char *data; | ||
| 225 | { | ||
| 226 | unsigned long hash; | ||
| 227 | LHASH_NODE *nn,**rn; | ||
| 228 | char *ret; | ||
| 229 | |||
| 230 | rn=getrn(lh,data,&hash); | ||
| 231 | |||
| 232 | if (*rn == NULL) | ||
| 233 | { | ||
| 234 | lh->num_no_delete++; | ||
| 235 | return(NULL); | ||
| 236 | } | ||
| 237 | else | ||
| 238 | { | ||
| 239 | nn= *rn; | ||
| 240 | *rn=nn->next; | ||
| 241 | ret=nn->data; | ||
| 242 | free((char *)nn); | ||
| 243 | lh->num_delete++; | ||
| 244 | } | ||
| 245 | |||
| 246 | lh->num_items--; | ||
| 247 | if ((lh->num_nodes > MIN_NODES) && | ||
| 248 | (lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))) | ||
| 249 | contract(lh); | ||
| 250 | |||
| 251 | return(ret); | ||
| 252 | } | ||
| 253 | |||
| 254 | char *lh_retrieve(lh, data) | ||
| 255 | LHASH *lh; | ||
| 256 | char *data; | ||
| 257 | { | ||
| 258 | unsigned long hash; | ||
| 259 | LHASH_NODE **rn; | ||
| 260 | char *ret; | ||
| 261 | |||
| 262 | rn=getrn(lh,data,&hash); | ||
| 263 | |||
| 264 | if (*rn == NULL) | ||
| 265 | { | ||
| 266 | lh->num_retrieve_miss++; | ||
| 267 | return(NULL); | ||
| 268 | } | ||
| 269 | else | ||
| 270 | { | ||
| 271 | ret= (*rn)->data; | ||
| 272 | lh->num_retrieve++; | ||
| 273 | } | ||
| 274 | return(ret); | ||
| 275 | } | ||
| 276 | |||
| 277 | void lh_doall(lh, func) | ||
| 278 | LHASH *lh; | ||
| 279 | void (*func)(); | ||
| 280 | { | ||
| 281 | lh_doall_arg(lh,func,NULL); | ||
| 282 | } | ||
| 283 | |||
| 284 | void lh_doall_arg(lh, func, arg) | ||
| 285 | LHASH *lh; | ||
| 286 | void (*func)(); | ||
| 287 | char *arg; | ||
| 288 | { | ||
| 289 | int i; | ||
| 290 | LHASH_NODE *a,*n; | ||
| 291 | |||
| 292 | /* reverse the order so we search from 'top to bottom' | ||
| 293 | * We were having memory leaks otherwise */ | ||
| 294 | for (i=lh->num_nodes-1; i>=0; i--) | ||
| 295 | { | ||
| 296 | a=lh->b[i]; | ||
| 297 | while (a != NULL) | ||
| 298 | { | ||
| 299 | /* 28/05/91 - eay - n added so items can be deleted | ||
| 300 | * via lh_doall */ | ||
| 301 | n=a->next; | ||
| 302 | func(a->data,arg); | ||
| 303 | a=n; | ||
| 304 | } | ||
| 305 | } | ||
| 306 | } | ||
| 307 | |||
| 308 | static void expand(lh) | ||
| 309 | LHASH *lh; | ||
| 310 | { | ||
| 311 | LHASH_NODE **n,**n1,**n2,*np; | ||
| 312 | unsigned int p,i,j; | ||
| 313 | unsigned long hash,nni; | ||
| 314 | |||
| 315 | lh->num_nodes++; | ||
| 316 | lh->num_expands++; | ||
| 317 | p=(int)lh->p++; | ||
| 318 | n1= &(lh->b[p]); | ||
| 319 | n2= &(lh->b[p+(int)lh->pmax]); | ||
| 320 | *n2=NULL; /* 27/07/92 - eay - undefined pointer bug */ | ||
| 321 | nni=lh->num_alloc_nodes; | ||
| 322 | |||
| 323 | for (np= *n1; np != NULL; ) | ||
| 324 | { | ||
| 325 | #ifndef NO_HASH_COMP | ||
| 326 | hash=np->hash; | ||
| 327 | #else | ||
| 328 | hash=(*(lh->hash))(np->data); | ||
| 329 | lh->num_hash_calls++; | ||
| 330 | #endif | ||
| 331 | if ((hash%nni) != p) | ||
| 332 | { /* move it */ | ||
| 333 | *n1= (*n1)->next; | ||
| 334 | np->next= *n2; | ||
| 335 | *n2=np; | ||
| 336 | } | ||
| 337 | else | ||
| 338 | n1= &((*n1)->next); | ||
| 339 | np= *n1; | ||
| 340 | } | ||
| 341 | |||
| 342 | if ((lh->p) >= lh->pmax) | ||
| 343 | { | ||
| 344 | j=(int)lh->num_alloc_nodes*2; | ||
| 345 | n=(LHASH_NODE **)realloc((char *)lh->b, | ||
| 346 | (unsigned int)sizeof(LHASH_NODE *)*j); | ||
| 347 | if (n == NULL) | ||
| 348 | { | ||
| 349 | /* fputs("realloc error in lhash",stderr); */ | ||
| 350 | lh->p=0; | ||
| 351 | return; | ||
| 352 | } | ||
| 353 | /* else */ | ||
| 354 | for (i=(int)lh->num_alloc_nodes; i<j; i++)/* 26/02/92 eay */ | ||
| 355 | n[i]=NULL; /* 02/03/92 eay */ | ||
| 356 | lh->pmax=lh->num_alloc_nodes; | ||
| 357 | lh->num_alloc_nodes=j; | ||
| 358 | lh->num_expand_reallocs++; | ||
| 359 | lh->p=0; | ||
| 360 | lh->b=n; | ||
| 361 | } | ||
| 362 | } | ||
| 363 | |||
| 364 | static void contract(lh) | ||
| 365 | LHASH *lh; | ||
| 366 | { | ||
| 367 | LHASH_NODE **n,*n1,*np; | ||
| 368 | |||
| 369 | np=lh->b[lh->p+lh->pmax-1]; | ||
| 370 | lh->b[lh->p+lh->pmax-1]=NULL; /* 24/07-92 - eay - weird but :-( */ | ||
| 371 | if (lh->p == 0) | ||
| 372 | { | ||
| 373 | n=(LHASH_NODE **)realloc((char *)lh->b, | ||
| 374 | (unsigned int)(sizeof(LHASH_NODE *)*lh->pmax)); | ||
| 375 | if (n == NULL) | ||
| 376 | { | ||
| 377 | /* fputs("realloc error in lhash",stderr); */ | ||
| 378 | return; | ||
| 379 | } | ||
| 380 | lh->num_contract_reallocs++; | ||
| 381 | lh->num_alloc_nodes/=2; | ||
| 382 | lh->pmax/=2; | ||
| 383 | lh->p=lh->pmax-1; | ||
| 384 | lh->b=n; | ||
| 385 | } | ||
| 386 | else | ||
| 387 | lh->p--; | ||
| 388 | |||
| 389 | lh->num_nodes--; | ||
| 390 | lh->num_contracts++; | ||
| 391 | |||
| 392 | n1=lh->b[(int)lh->p]; | ||
| 393 | if (n1 == NULL) | ||
| 394 | lh->b[(int)lh->p]=np; | ||
| 395 | else | ||
| 396 | { | ||
| 397 | while (n1->next != NULL) | ||
| 398 | n1=n1->next; | ||
| 399 | n1->next=np; | ||
| 400 | } | ||
| 401 | } | ||
| 402 | |||
| 403 | static LHASH_NODE **getrn(lh, data, rhash) | ||
| 404 | LHASH *lh; | ||
| 405 | char *data; | ||
| 406 | unsigned long *rhash; | ||
| 407 | { | ||
| 408 | LHASH_NODE **ret,*n1; | ||
| 409 | unsigned long hash,nn; | ||
| 410 | int (*cf)(); | ||
| 411 | |||
| 412 | hash=(*(lh->hash))(data); | ||
| 413 | lh->num_hash_calls++; | ||
| 414 | *rhash=hash; | ||
| 415 | |||
| 416 | nn=hash%lh->pmax; | ||
| 417 | if (nn < lh->p) | ||
| 418 | nn=hash%lh->num_alloc_nodes; | ||
| 419 | |||
| 420 | cf=lh->comp; | ||
| 421 | ret= &(lh->b[(int)nn]); | ||
| 422 | for (n1= *ret; n1 != NULL; n1=n1->next) | ||
| 423 | { | ||
| 424 | #ifndef NO_HASH_COMP | ||
| 425 | lh->num_hash_comps++; | ||
| 426 | if (n1->hash != hash) | ||
| 427 | { | ||
| 428 | ret= &(n1->next); | ||
| 429 | continue; | ||
| 430 | } | ||
| 431 | #endif | ||
| 432 | lh->num_comp_calls++; | ||
| 433 | if ((*cf)(n1->data,data) == 0) | ||
| 434 | break; | ||
| 435 | ret= &(n1->next); | ||
| 436 | } | ||
| 437 | return(ret); | ||
| 438 | } | ||
| 439 | |||
| 440 | /* | ||
| 441 | static unsigned long lh_strhash(str) | ||
| 442 | char *str; | ||
| 443 | { | ||
| 444 | int i,l; | ||
| 445 | unsigned long ret=0; | ||
| 446 | unsigned short *s; | ||
| 447 | |||
| 448 | if (str == NULL) return(0); | ||
| 449 | l=(strlen(str)+1)/2; | ||
| 450 | s=(unsigned short *)str; | ||
| 451 | for (i=0; i<l; i++) | ||
| 452 | ret^=(s[i]<<(i&0x0f)); | ||
| 453 | return(ret); | ||
| 454 | } */ | ||
| 455 | |||
| 456 | /* The following hash seems to work very well on normal text strings | ||
| 457 | * no collisions on /usr/dict/words and it distributes on %2^n quite | ||
| 458 | * well, not as good as MD5, but still good. | ||
| 459 | */ | ||
| 460 | unsigned long lh_strhash(c) | ||
| 461 | char *c; | ||
| 462 | { | ||
| 463 | unsigned long ret=0; | ||
| 464 | long n; | ||
| 465 | unsigned long v; | ||
| 466 | int r; | ||
| 467 | |||
| 468 | if ((c == NULL) || (*c == '\0')) | ||
| 469 | return(ret); | ||
| 470 | /* | ||
| 471 | unsigned char b[16]; | ||
| 472 | MD5(c,strlen(c),b); | ||
| 473 | return(b[0]|(b[1]<<8)|(b[2]<<16)|(b[3]<<24)); | ||
| 474 | */ | ||
| 475 | |||
| 476 | n=0x100; | ||
| 477 | while (*c) | ||
| 478 | { | ||
| 479 | v=n|(*c); | ||
| 480 | n+=0x100; | ||
| 481 | r= (int)((v>>2)^v)&0x0f; | ||
| 482 | ret=(ret<<r)|(ret>>(32-r)); | ||
| 483 | ret&=0xFFFFFFFFL; | ||
| 484 | ret^=v*v; | ||
| 485 | c++; | ||
| 486 | } | ||
| 487 | return((ret>>16)^ret); | ||
| 488 | } | ||
| 489 | |||
diff --git a/src/lib/libcrypto/lhash/lhash.h b/src/lib/libcrypto/lhash/lhash.h new file mode 100644 index 0000000000..70cbc6dfe7 --- /dev/null +++ b/src/lib/libcrypto/lhash/lhash.h | |||
| @@ -0,0 +1,155 @@ | |||
| 1 | /* crypto/lhash/lhash.h */ | ||
| 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 | /* Header for dynamic hash table routines | ||
| 60 | * Author - Eric Young | ||
| 61 | */ | ||
| 62 | |||
| 63 | #ifndef HEADER_LHASH_H | ||
| 64 | #define HEADER_LHASH_H | ||
| 65 | |||
| 66 | #ifdef __cplusplus | ||
| 67 | extern "C" { | ||
| 68 | #endif | ||
| 69 | |||
| 70 | typedef struct lhash_node_st | ||
| 71 | { | ||
| 72 | char *data; | ||
| 73 | struct lhash_node_st *next; | ||
| 74 | #ifndef NO_HASH_COMP | ||
| 75 | unsigned long hash; | ||
| 76 | #endif | ||
| 77 | } LHASH_NODE; | ||
| 78 | |||
| 79 | typedef struct lhash_st | ||
| 80 | { | ||
| 81 | LHASH_NODE **b; | ||
| 82 | int (*comp)(); | ||
| 83 | unsigned long (*hash)(); | ||
| 84 | unsigned int num_nodes; | ||
| 85 | unsigned int num_alloc_nodes; | ||
| 86 | unsigned int p; | ||
| 87 | unsigned int pmax; | ||
| 88 | unsigned long up_load; /* load times 256 */ | ||
| 89 | unsigned long down_load; /* load times 256 */ | ||
| 90 | unsigned long num_items; | ||
| 91 | |||
| 92 | unsigned long num_expands; | ||
| 93 | unsigned long num_expand_reallocs; | ||
| 94 | unsigned long num_contracts; | ||
| 95 | unsigned long num_contract_reallocs; | ||
| 96 | unsigned long num_hash_calls; | ||
| 97 | unsigned long num_comp_calls; | ||
| 98 | unsigned long num_insert; | ||
| 99 | unsigned long num_replace; | ||
| 100 | unsigned long num_delete; | ||
| 101 | unsigned long num_no_delete; | ||
| 102 | unsigned long num_retrieve; | ||
| 103 | unsigned long num_retrieve_miss; | ||
| 104 | unsigned long num_hash_comps; | ||
| 105 | } LHASH; | ||
| 106 | |||
| 107 | #define LH_LOAD_MULT 256 | ||
| 108 | |||
| 109 | #ifndef NOPROTO | ||
| 110 | LHASH *lh_new(unsigned long (*h)(), int (*c)()); | ||
| 111 | void lh_free(LHASH *lh); | ||
| 112 | char *lh_insert(LHASH *lh, char *data); | ||
| 113 | char *lh_delete(LHASH *lh, char *data); | ||
| 114 | char *lh_retrieve(LHASH *lh, char *data); | ||
| 115 | void lh_doall(LHASH *lh, void (*func)(/* char *b */)); | ||
| 116 | void lh_doall_arg(LHASH *lh, void (*func)(/*char *a,char *b*/),char *arg); | ||
| 117 | unsigned long lh_strhash(char *c); | ||
| 118 | |||
| 119 | #ifndef NO_FP_API | ||
| 120 | void lh_stats(LHASH *lh, FILE *out); | ||
| 121 | void lh_node_stats(LHASH *lh, FILE *out); | ||
| 122 | void lh_node_usage_stats(LHASH *lh, FILE *out); | ||
| 123 | #endif | ||
| 124 | |||
| 125 | #ifdef HEADER_BIO_H | ||
| 126 | void lh_stats_bio(LHASH *lh, BIO *out); | ||
| 127 | void lh_node_stats_bio(LHASH *lh, BIO *out); | ||
| 128 | void lh_node_usage_stats_bio(LHASH *lh, BIO *out); | ||
| 129 | #endif | ||
| 130 | #else | ||
| 131 | LHASH *lh_new(); | ||
| 132 | void lh_free(); | ||
| 133 | char *lh_insert(); | ||
| 134 | char *lh_delete(); | ||
| 135 | char *lh_retrieve(); | ||
| 136 | void lh_doall(); | ||
| 137 | void lh_doall_arg(); | ||
| 138 | unsigned long lh_strhash(); | ||
| 139 | |||
| 140 | #ifndef NO_FP_API | ||
| 141 | void lh_stats(); | ||
| 142 | void lh_node_stats(); | ||
| 143 | void lh_node_usage_stats(); | ||
| 144 | #endif | ||
| 145 | void lh_stats_bio(); | ||
| 146 | void lh_node_stats_bio(); | ||
| 147 | void lh_node_usage_stats_bio(); | ||
| 148 | #endif | ||
| 149 | |||
| 150 | #ifdef __cplusplus | ||
| 151 | } | ||
| 152 | #endif | ||
| 153 | |||
| 154 | #endif | ||
| 155 | |||
diff --git a/src/lib/libcrypto/md5/asm/md5-586.pl b/src/lib/libcrypto/md5/asm/md5-586.pl new file mode 100644 index 0000000000..2c7fb7dd98 --- /dev/null +++ b/src/lib/libcrypto/md5/asm/md5-586.pl | |||
| @@ -0,0 +1,304 @@ | |||
| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | # Normal is the | ||
| 4 | # md5_block_x86(MD5_CTX *c, ULONG *X); | ||
| 5 | # version, non-normal is the | ||
| 6 | # md5_block_x86(MD5_CTX *c, ULONG *X,int blocks); | ||
| 7 | |||
| 8 | $normal=0; | ||
| 9 | |||
| 10 | push(@INC,"perlasm","../../perlasm"); | ||
| 11 | require "x86asm.pl"; | ||
| 12 | |||
| 13 | &asm_init($ARGV[0],$0); | ||
| 14 | |||
| 15 | $A="eax"; | ||
| 16 | $B="ebx"; | ||
| 17 | $C="ecx"; | ||
| 18 | $D="edx"; | ||
| 19 | $tmp1="edi"; | ||
| 20 | $tmp2="ebp"; | ||
| 21 | $X="esi"; | ||
| 22 | |||
| 23 | # What we need to load into $tmp for the next round | ||
| 24 | %Ltmp1=("R0",&Np($C), "R1",&Np($C), "R2",&Np($C), "R3",&Np($D)); | ||
| 25 | @xo=( | ||
| 26 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, # R0 | ||
| 27 | 1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, # R1 | ||
| 28 | 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, # R2 | ||
| 29 | 0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9, # R3 | ||
| 30 | ); | ||
| 31 | |||
| 32 | &md5_block("md5_block_x86"); | ||
| 33 | &asm_finish(); | ||
| 34 | |||
| 35 | sub Np | ||
| 36 | { | ||
| 37 | local($p)=@_; | ||
| 38 | local(%n)=($A,$D,$B,$A,$C,$B,$D,$C); | ||
| 39 | return($n{$p}); | ||
| 40 | } | ||
| 41 | |||
| 42 | sub R0 | ||
| 43 | { | ||
| 44 | local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_; | ||
| 45 | |||
| 46 | &mov($tmp1,$C) if $pos < 0; | ||
| 47 | &mov($tmp2,&DWP($xo[$ki]*4,$K,"",0)) if $pos < 0; # very first one | ||
| 48 | |||
| 49 | # body proper | ||
| 50 | |||
| 51 | &comment("R0 $ki"); | ||
| 52 | &xor($tmp1,$d); # F function - part 2 | ||
| 53 | |||
| 54 | &and($tmp1,$b); # F function - part 3 | ||
| 55 | &lea($a,&DWP($t,$a,$tmp2,1)); | ||
| 56 | |||
| 57 | &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2); | ||
| 58 | &xor($tmp1,$d); # F function - part 4 | ||
| 59 | |||
| 60 | &add($a,$tmp1); | ||
| 61 | &mov($tmp1,&Np($c)) if $pos < 1; # next tmp1 for R0 | ||
| 62 | &mov($tmp1,&Np($c)) if $pos == 1; # next tmp1 for R1 | ||
| 63 | |||
| 64 | &rotl($a,$s); | ||
| 65 | &add($a,$b); | ||
| 66 | |||
| 67 | } | ||
| 68 | |||
| 69 | sub R1 | ||
| 70 | { | ||
| 71 | local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_; | ||
| 72 | |||
| 73 | &comment("R1 $ki"); | ||
| 74 | |||
| 75 | &lea($a,&DWP($t,$a,$tmp2,1)); | ||
| 76 | |||
| 77 | &xor($tmp1,$b); # G function - part 2 | ||
| 78 | &and($tmp1,$d); # G function - part 3 | ||
| 79 | |||
| 80 | &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2); | ||
| 81 | &xor($tmp1,$c); # G function - part 4 | ||
| 82 | |||
| 83 | &add($a,$tmp1); | ||
| 84 | &mov($tmp1,&Np($c)) if $pos < 1; # G function - part 1 | ||
| 85 | &mov($tmp1,&Np($c)) if $pos == 1; # G function - part 1 | ||
| 86 | |||
| 87 | &rotl($a,$s); | ||
| 88 | |||
| 89 | &add($a,$b); | ||
| 90 | } | ||
| 91 | |||
| 92 | sub R2 | ||
| 93 | { | ||
| 94 | local($n,$pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_; | ||
| 95 | # This one is different, only 3 logical operations | ||
| 96 | |||
| 97 | if (($n & 1) == 0) | ||
| 98 | { | ||
| 99 | &comment("R2 $ki"); | ||
| 100 | # make sure to do 'D' first, not 'B', else we clash with | ||
| 101 | # the last add from the previous round. | ||
| 102 | |||
| 103 | &xor($tmp1,$d); # H function - part 2 | ||
| 104 | |||
| 105 | &xor($tmp1,$b); # H function - part 3 | ||
| 106 | &lea($a,&DWP($t,$a,$tmp2,1)); | ||
| 107 | |||
| 108 | &add($a,$tmp1); | ||
| 109 | &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)); | ||
| 110 | |||
| 111 | &rotl($a,$s); | ||
| 112 | |||
| 113 | &mov($tmp1,&Np($c)); | ||
| 114 | } | ||
| 115 | else | ||
| 116 | { | ||
| 117 | &comment("R2 $ki"); | ||
| 118 | # make sure to do 'D' first, not 'B', else we clash with | ||
| 119 | # the last add from the previous round. | ||
| 120 | |||
| 121 | &lea($a,&DWP($t,$a,$tmp2,1)); | ||
| 122 | |||
| 123 | &add($b,$c); # MOVED FORWARD | ||
| 124 | &xor($tmp1,$d); # H function - part 2 | ||
| 125 | |||
| 126 | &xor($tmp1,$b); # H function - part 3 | ||
| 127 | &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2); | ||
| 128 | |||
| 129 | &add($a,$tmp1); | ||
| 130 | &mov($tmp1,&Np($c)) if $pos < 1; # H function - part 1 | ||
| 131 | &mov($tmp1,-1) if $pos == 1; # I function - part 1 | ||
| 132 | |||
| 133 | &rotl($a,$s); | ||
| 134 | |||
| 135 | &add($a,$b); | ||
| 136 | } | ||
| 137 | } | ||
| 138 | |||
| 139 | sub R3 | ||
| 140 | { | ||
| 141 | local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_; | ||
| 142 | |||
| 143 | &comment("R3 $ki"); | ||
| 144 | |||
| 145 | # ¬($tmp1) | ||
| 146 | &xor($tmp1,$d) if $pos < 0; # I function - part 2 | ||
| 147 | |||
| 148 | &or($tmp1,$b); # I function - part 3 | ||
| 149 | &lea($a,&DWP($t,$a,$tmp2,1)); | ||
| 150 | |||
| 151 | &xor($tmp1,$c); # I function - part 4 | ||
| 152 | &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if $pos != 2; # load X/k value | ||
| 153 | &mov($tmp2,&wparam(0)) if $pos == 2; | ||
| 154 | |||
| 155 | &add($a,$tmp1); | ||
| 156 | &mov($tmp1,-1) if $pos < 1; # H function - part 1 | ||
| 157 | &add($K,64) if $pos >=1 && !$normal; | ||
| 158 | |||
| 159 | &rotl($a,$s); | ||
| 160 | |||
| 161 | &xor($tmp1,&Np($d)) if $pos <= 0; # I function - part = first time | ||
| 162 | &mov($tmp1,&DWP( 0,$tmp2,"",0)) if $pos > 0; | ||
| 163 | &add($a,$b); | ||
| 164 | } | ||
| 165 | |||
| 166 | |||
| 167 | sub md5_block | ||
| 168 | { | ||
| 169 | local($name)=@_; | ||
| 170 | |||
| 171 | &function_begin_B($name,"",3); | ||
| 172 | |||
| 173 | # parameter 1 is the MD5_CTX structure. | ||
| 174 | # A 0 | ||
| 175 | # B 4 | ||
| 176 | # C 8 | ||
| 177 | # D 12 | ||
| 178 | |||
| 179 | &push("esi"); | ||
| 180 | &push("edi"); | ||
| 181 | &mov($tmp1, &wparam(0)); # edi | ||
| 182 | &mov($X, &wparam(1)); # esi | ||
| 183 | &mov($C, &wparam(2)); | ||
| 184 | &push("ebp"); | ||
| 185 | &push("ebx"); | ||
| 186 | &add($C, $X); # offset we end at | ||
| 187 | &sub($C, 64); | ||
| 188 | &mov($A, &DWP( 0,$tmp1,"",0)); | ||
| 189 | &push($C); # Put on the TOS | ||
| 190 | &mov($B, &DWP( 4,$tmp1,"",0)); | ||
| 191 | &mov($C, &DWP( 8,$tmp1,"",0)); | ||
| 192 | &mov($D, &DWP(12,$tmp1,"",0)); | ||
| 193 | |||
| 194 | &set_label("start") unless $normal; | ||
| 195 | &comment(""); | ||
| 196 | &comment("R0 section"); | ||
| 197 | |||
| 198 | &R0(-2,$A,$B,$C,$D,$X, 0, 7,0xd76aa478); | ||
| 199 | &R0( 0,$D,$A,$B,$C,$X, 1,12,0xe8c7b756); | ||
| 200 | &R0( 0,$C,$D,$A,$B,$X, 2,17,0x242070db); | ||
| 201 | &R0( 0,$B,$C,$D,$A,$X, 3,22,0xc1bdceee); | ||
| 202 | &R0( 0,$A,$B,$C,$D,$X, 4, 7,0xf57c0faf); | ||
| 203 | &R0( 0,$D,$A,$B,$C,$X, 5,12,0x4787c62a); | ||
| 204 | &R0( 0,$C,$D,$A,$B,$X, 6,17,0xa8304613); | ||
| 205 | &R0( 0,$B,$C,$D,$A,$X, 7,22,0xfd469501); | ||
| 206 | &R0( 0,$A,$B,$C,$D,$X, 8, 7,0x698098d8); | ||
| 207 | &R0( 0,$D,$A,$B,$C,$X, 9,12,0x8b44f7af); | ||
| 208 | &R0( 0,$C,$D,$A,$B,$X,10,17,0xffff5bb1); | ||
| 209 | &R0( 0,$B,$C,$D,$A,$X,11,22,0x895cd7be); | ||
| 210 | &R0( 0,$A,$B,$C,$D,$X,12, 7,0x6b901122); | ||
| 211 | &R0( 0,$D,$A,$B,$C,$X,13,12,0xfd987193); | ||
| 212 | &R0( 0,$C,$D,$A,$B,$X,14,17,0xa679438e); | ||
| 213 | &R0( 1,$B,$C,$D,$A,$X,15,22,0x49b40821); | ||
| 214 | |||
| 215 | &comment(""); | ||
| 216 | &comment("R1 section"); | ||
| 217 | &R1(-1,$A,$B,$C,$D,$X,16, 5,0xf61e2562); | ||
| 218 | &R1( 0,$D,$A,$B,$C,$X,17, 9,0xc040b340); | ||
| 219 | &R1( 0,$C,$D,$A,$B,$X,18,14,0x265e5a51); | ||
| 220 | &R1( 0,$B,$C,$D,$A,$X,19,20,0xe9b6c7aa); | ||
| 221 | &R1( 0,$A,$B,$C,$D,$X,20, 5,0xd62f105d); | ||
| 222 | &R1( 0,$D,$A,$B,$C,$X,21, 9,0x02441453); | ||
| 223 | &R1( 0,$C,$D,$A,$B,$X,22,14,0xd8a1e681); | ||
| 224 | &R1( 0,$B,$C,$D,$A,$X,23,20,0xe7d3fbc8); | ||
| 225 | &R1( 0,$A,$B,$C,$D,$X,24, 5,0x21e1cde6); | ||
| 226 | &R1( 0,$D,$A,$B,$C,$X,25, 9,0xc33707d6); | ||
| 227 | &R1( 0,$C,$D,$A,$B,$X,26,14,0xf4d50d87); | ||
| 228 | &R1( 0,$B,$C,$D,$A,$X,27,20,0x455a14ed); | ||
| 229 | &R1( 0,$A,$B,$C,$D,$X,28, 5,0xa9e3e905); | ||
| 230 | &R1( 0,$D,$A,$B,$C,$X,29, 9,0xfcefa3f8); | ||
| 231 | &R1( 0,$C,$D,$A,$B,$X,30,14,0x676f02d9); | ||
| 232 | &R1( 1,$B,$C,$D,$A,$X,31,20,0x8d2a4c8a); | ||
| 233 | |||
| 234 | &comment(""); | ||
| 235 | &comment("R2 section"); | ||
| 236 | &R2( 0,-1,$A,$B,$C,$D,$X,32, 4,0xfffa3942); | ||
| 237 | &R2( 1, 0,$D,$A,$B,$C,$X,33,11,0x8771f681); | ||
| 238 | &R2( 2, 0,$C,$D,$A,$B,$X,34,16,0x6d9d6122); | ||
| 239 | &R2( 3, 0,$B,$C,$D,$A,$X,35,23,0xfde5380c); | ||
| 240 | &R2( 4, 0,$A,$B,$C,$D,$X,36, 4,0xa4beea44); | ||
| 241 | &R2( 5, 0,$D,$A,$B,$C,$X,37,11,0x4bdecfa9); | ||
| 242 | &R2( 6, 0,$C,$D,$A,$B,$X,38,16,0xf6bb4b60); | ||
| 243 | &R2( 7, 0,$B,$C,$D,$A,$X,39,23,0xbebfbc70); | ||
| 244 | &R2( 8, 0,$A,$B,$C,$D,$X,40, 4,0x289b7ec6); | ||
| 245 | &R2( 9, 0,$D,$A,$B,$C,$X,41,11,0xeaa127fa); | ||
| 246 | &R2(10, 0,$C,$D,$A,$B,$X,42,16,0xd4ef3085); | ||
| 247 | &R2(11, 0,$B,$C,$D,$A,$X,43,23,0x04881d05); | ||
| 248 | &R2(12, 0,$A,$B,$C,$D,$X,44, 4,0xd9d4d039); | ||
| 249 | &R2(13, 0,$D,$A,$B,$C,$X,45,11,0xe6db99e5); | ||
| 250 | &R2(14, 0,$C,$D,$A,$B,$X,46,16,0x1fa27cf8); | ||
| 251 | &R2(15, 1,$B,$C,$D,$A,$X,47,23,0xc4ac5665); | ||
| 252 | |||
| 253 | &comment(""); | ||
| 254 | &comment("R3 section"); | ||
| 255 | &R3(-1,$A,$B,$C,$D,$X,48, 6,0xf4292244); | ||
| 256 | &R3( 0,$D,$A,$B,$C,$X,49,10,0x432aff97); | ||
| 257 | &R3( 0,$C,$D,$A,$B,$X,50,15,0xab9423a7); | ||
| 258 | &R3( 0,$B,$C,$D,$A,$X,51,21,0xfc93a039); | ||
| 259 | &R3( 0,$A,$B,$C,$D,$X,52, 6,0x655b59c3); | ||
| 260 | &R3( 0,$D,$A,$B,$C,$X,53,10,0x8f0ccc92); | ||
| 261 | &R3( 0,$C,$D,$A,$B,$X,54,15,0xffeff47d); | ||
| 262 | &R3( 0,$B,$C,$D,$A,$X,55,21,0x85845dd1); | ||
| 263 | &R3( 0,$A,$B,$C,$D,$X,56, 6,0x6fa87e4f); | ||
| 264 | &R3( 0,$D,$A,$B,$C,$X,57,10,0xfe2ce6e0); | ||
| 265 | &R3( 0,$C,$D,$A,$B,$X,58,15,0xa3014314); | ||
| 266 | &R3( 0,$B,$C,$D,$A,$X,59,21,0x4e0811a1); | ||
| 267 | &R3( 0,$A,$B,$C,$D,$X,60, 6,0xf7537e82); | ||
| 268 | &R3( 0,$D,$A,$B,$C,$X,61,10,0xbd3af235); | ||
| 269 | &R3( 0,$C,$D,$A,$B,$X,62,15,0x2ad7d2bb); | ||
| 270 | &R3( 2,$B,$C,$D,$A,$X,63,21,0xeb86d391); | ||
| 271 | |||
| 272 | # &mov($tmp2,&wparam(0)); # done in the last R3 | ||
| 273 | # &mov($tmp1, &DWP( 0,$tmp2,"",0)); # done is the last R3 | ||
| 274 | |||
| 275 | &add($A,$tmp1); | ||
| 276 | &mov($tmp1, &DWP( 4,$tmp2,"",0)); | ||
| 277 | |||
| 278 | &add($B,$tmp1); | ||
| 279 | &mov($tmp1, &DWP( 8,$tmp2,"",0)); | ||
| 280 | |||
| 281 | &add($C,$tmp1); | ||
| 282 | &mov($tmp1, &DWP(12,$tmp2,"",0)); | ||
| 283 | |||
| 284 | &add($D,$tmp1); | ||
| 285 | &mov(&DWP( 0,$tmp2,"",0),$A); | ||
| 286 | |||
| 287 | &mov(&DWP( 4,$tmp2,"",0),$B); | ||
| 288 | &mov($tmp1,&swtmp(0)) unless $normal; | ||
| 289 | |||
| 290 | &mov(&DWP( 8,$tmp2,"",0),$C); | ||
| 291 | &mov(&DWP(12,$tmp2,"",0),$D); | ||
| 292 | |||
| 293 | &cmp($tmp1,$X) unless $normal; # check count | ||
| 294 | &jge(&label("start")) unless $normal; | ||
| 295 | |||
| 296 | &pop("eax"); # pop the temp variable off the stack | ||
| 297 | &pop("ebx"); | ||
| 298 | &pop("ebp"); | ||
| 299 | &pop("edi"); | ||
| 300 | &pop("esi"); | ||
| 301 | &ret(); | ||
| 302 | &function_end_B($name); | ||
| 303 | } | ||
| 304 | |||
diff --git a/src/lib/libcrypto/md5/md5.h b/src/lib/libcrypto/md5/md5.h new file mode 100644 index 0000000000..357c6c625d --- /dev/null +++ b/src/lib/libcrypto/md5/md5.h | |||
| @@ -0,0 +1,99 @@ | |||
| 1 | /* crypto/md5/md5.h */ | ||
| 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 | #ifndef HEADER_MD5_H | ||
| 60 | #define HEADER_MD5_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #define MD5_CBLOCK 64 | ||
| 67 | #define MD5_LBLOCK 16 | ||
| 68 | #define MD5_BLOCK 16 | ||
| 69 | #define MD5_LAST_BLOCK 56 | ||
| 70 | #define MD5_LENGTH_BLOCK 8 | ||
| 71 | #define MD5_DIGEST_LENGTH 16 | ||
| 72 | |||
| 73 | typedef struct MD5state_st | ||
| 74 | { | ||
| 75 | unsigned long A,B,C,D; | ||
| 76 | unsigned long Nl,Nh; | ||
| 77 | unsigned long data[MD5_LBLOCK]; | ||
| 78 | int num; | ||
| 79 | } MD5_CTX; | ||
| 80 | |||
| 81 | #ifndef NOPROTO | ||
| 82 | void MD5_Init(MD5_CTX *c); | ||
| 83 | void MD5_Update(MD5_CTX *c, unsigned char *data, unsigned long len); | ||
| 84 | void MD5_Final(unsigned char *md, MD5_CTX *c); | ||
| 85 | unsigned char *MD5(unsigned char *d, unsigned long n, unsigned char *md); | ||
| 86 | void MD5_Transform(MD5_CTX *c, unsigned char *b); | ||
| 87 | #else | ||
| 88 | void MD5_Init(); | ||
| 89 | void MD5_Update(); | ||
| 90 | void MD5_Final(); | ||
| 91 | unsigned char *MD5(); | ||
| 92 | void MD5_Transform(); | ||
| 93 | #endif | ||
| 94 | |||
| 95 | #ifdef __cplusplus | ||
| 96 | } | ||
| 97 | #endif | ||
| 98 | |||
| 99 | #endif | ||
diff --git a/src/lib/libcrypto/md5/md5_dgst.c b/src/lib/libcrypto/md5/md5_dgst.c new file mode 100644 index 0000000000..43b3498d92 --- /dev/null +++ b/src/lib/libcrypto/md5/md5_dgst.c | |||
| @@ -0,0 +1,440 @@ | |||
| 1 | /* crypto/md5/md5_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 "md5_locl.h" | ||
| 61 | |||
| 62 | char *MD5_version="MD5 part of SSLeay 0.9.0b 29-Jun-1998"; | ||
| 63 | |||
| 64 | /* Implemented from RFC1321 The MD5 Message-Digest Algorithm | ||
| 65 | */ | ||
| 66 | |||
| 67 | #define INIT_DATA_A (unsigned long)0x67452301L | ||
| 68 | #define INIT_DATA_B (unsigned long)0xefcdab89L | ||
| 69 | #define INIT_DATA_C (unsigned long)0x98badcfeL | ||
| 70 | #define INIT_DATA_D (unsigned long)0x10325476L | ||
| 71 | |||
| 72 | #ifndef NOPROTO | ||
| 73 | # ifdef MD5_ASM | ||
| 74 | void md5_block_x86(MD5_CTX *c, unsigned long *p,int num); | ||
| 75 | # define md5_block md5_block_x86 | ||
| 76 | # else | ||
| 77 | static void md5_block(MD5_CTX *c, unsigned long *p,int num); | ||
| 78 | # endif | ||
| 79 | #else | ||
| 80 | # ifdef MD5_ASM | ||
| 81 | void md5_block_x86(); | ||
| 82 | # define md5_block md5_block_x86 | ||
| 83 | # else | ||
| 84 | static void md5_block(); | ||
| 85 | # endif | ||
| 86 | #endif | ||
| 87 | |||
| 88 | void MD5_Init(c) | ||
| 89 | MD5_CTX *c; | ||
| 90 | { | ||
| 91 | c->A=INIT_DATA_A; | ||
| 92 | c->B=INIT_DATA_B; | ||
| 93 | c->C=INIT_DATA_C; | ||
| 94 | c->D=INIT_DATA_D; | ||
| 95 | c->Nl=0; | ||
| 96 | c->Nh=0; | ||
| 97 | c->num=0; | ||
| 98 | } | ||
| 99 | |||
| 100 | void MD5_Update(c, data, len) | ||
| 101 | MD5_CTX *c; | ||
| 102 | register unsigned char *data; | ||
| 103 | unsigned long len; | ||
| 104 | { | ||
| 105 | register ULONG *p; | ||
| 106 | int sw,sc; | ||
| 107 | ULONG l; | ||
| 108 | |||
| 109 | if (len == 0) return; | ||
| 110 | |||
| 111 | l=(c->Nl+(len<<3))&0xffffffffL; | ||
| 112 | /* 95-05-24 eay Fixed a bug with the overflow handling, thanks to | ||
| 113 | * Wei Dai <weidai@eskimo.com> for pointing it out. */ | ||
| 114 | if (l < c->Nl) /* overflow */ | ||
| 115 | c->Nh++; | ||
| 116 | c->Nh+=(len>>29); | ||
| 117 | c->Nl=l; | ||
| 118 | |||
| 119 | if (c->num != 0) | ||
| 120 | { | ||
| 121 | p=c->data; | ||
| 122 | sw=c->num>>2; | ||
| 123 | sc=c->num&0x03; | ||
| 124 | |||
| 125 | if ((c->num+len) >= MD5_CBLOCK) | ||
| 126 | { | ||
| 127 | l= p[sw]; | ||
| 128 | p_c2l(data,l,sc); | ||
| 129 | p[sw++]=l; | ||
| 130 | for (; sw<MD5_LBLOCK; sw++) | ||
| 131 | { | ||
| 132 | c2l(data,l); | ||
| 133 | p[sw]=l; | ||
| 134 | } | ||
| 135 | len-=(MD5_CBLOCK-c->num); | ||
| 136 | |||
| 137 | md5_block(c,p,64); | ||
| 138 | c->num=0; | ||
| 139 | /* drop through and do the rest */ | ||
| 140 | } | ||
| 141 | else | ||
| 142 | { | ||
| 143 | int ew,ec; | ||
| 144 | |||
| 145 | c->num+=(int)len; | ||
| 146 | if ((sc+len) < 4) /* ugly, add char's to a word */ | ||
| 147 | { | ||
| 148 | l= p[sw]; | ||
| 149 | p_c2l_p(data,l,sc,len); | ||
| 150 | p[sw]=l; | ||
| 151 | } | ||
| 152 | else | ||
| 153 | { | ||
| 154 | ew=(c->num>>2); | ||
| 155 | ec=(c->num&0x03); | ||
| 156 | l= p[sw]; | ||
| 157 | p_c2l(data,l,sc); | ||
| 158 | p[sw++]=l; | ||
| 159 | for (; sw < ew; sw++) | ||
| 160 | { c2l(data,l); p[sw]=l; } | ||
| 161 | if (ec) | ||
| 162 | { | ||
| 163 | c2l_p(data,l,ec); | ||
| 164 | p[sw]=l; | ||
| 165 | } | ||
| 166 | } | ||
| 167 | return; | ||
| 168 | } | ||
| 169 | } | ||
| 170 | /* we now can process the input data in blocks of MD5_CBLOCK | ||
| 171 | * chars and save the leftovers to c->data. */ | ||
| 172 | #ifdef L_ENDIAN | ||
| 173 | if ((((unsigned long)data)%sizeof(ULONG)) == 0) | ||
| 174 | { | ||
| 175 | sw=(int)len/MD5_CBLOCK; | ||
| 176 | if (sw > 0) | ||
| 177 | { | ||
| 178 | sw*=MD5_CBLOCK; | ||
| 179 | md5_block(c,(ULONG *)data,sw); | ||
| 180 | data+=sw; | ||
| 181 | len-=sw; | ||
| 182 | } | ||
| 183 | } | ||
| 184 | #endif | ||
| 185 | p=c->data; | ||
| 186 | while (len >= MD5_CBLOCK) | ||
| 187 | { | ||
| 188 | #if defined(L_ENDIAN) || defined(B_ENDIAN) | ||
| 189 | if (p != (unsigned long *)data) | ||
| 190 | memcpy(p,data,MD5_CBLOCK); | ||
| 191 | data+=MD5_CBLOCK; | ||
| 192 | #ifdef B_ENDIAN | ||
| 193 | for (sw=(MD5_LBLOCK/4); sw; sw--) | ||
| 194 | { | ||
| 195 | Endian_Reverse32(p[0]); | ||
| 196 | Endian_Reverse32(p[1]); | ||
| 197 | Endian_Reverse32(p[2]); | ||
| 198 | Endian_Reverse32(p[3]); | ||
| 199 | p+=4; | ||
| 200 | } | ||
| 201 | #endif | ||
| 202 | #else | ||
| 203 | for (sw=(MD5_LBLOCK/4); sw; sw--) | ||
| 204 | { | ||
| 205 | c2l(data,l); *(p++)=l; | ||
| 206 | c2l(data,l); *(p++)=l; | ||
| 207 | c2l(data,l); *(p++)=l; | ||
| 208 | c2l(data,l); *(p++)=l; | ||
| 209 | } | ||
| 210 | #endif | ||
| 211 | p=c->data; | ||
| 212 | md5_block(c,p,64); | ||
| 213 | len-=MD5_CBLOCK; | ||
| 214 | } | ||
| 215 | sc=(int)len; | ||
| 216 | c->num=sc; | ||
| 217 | if (sc) | ||
| 218 | { | ||
| 219 | sw=sc>>2; /* words to copy */ | ||
| 220 | #ifdef L_ENDIAN | ||
| 221 | p[sw]=0; | ||
| 222 | memcpy(p,data,sc); | ||
| 223 | #else | ||
| 224 | sc&=0x03; | ||
| 225 | for ( ; sw; sw--) | ||
| 226 | { c2l(data,l); *(p++)=l; } | ||
| 227 | c2l_p(data,l,sc); | ||
| 228 | *p=l; | ||
| 229 | #endif | ||
| 230 | } | ||
| 231 | } | ||
| 232 | |||
| 233 | void MD5_Transform(c,b) | ||
| 234 | MD5_CTX *c; | ||
| 235 | unsigned char *b; | ||
| 236 | { | ||
| 237 | ULONG p[16]; | ||
| 238 | #if !defined(L_ENDIAN) | ||
| 239 | ULONG *q; | ||
| 240 | int i; | ||
| 241 | #endif | ||
| 242 | |||
| 243 | #if defined(B_ENDIAN) || defined(L_ENDIAN) | ||
| 244 | memcpy(p,b,64); | ||
| 245 | #ifdef B_ENDIAN | ||
| 246 | q=p; | ||
| 247 | for (i=(MD5_LBLOCK/4); i; i--) | ||
| 248 | { | ||
| 249 | Endian_Reverse32(q[0]); | ||
| 250 | Endian_Reverse32(q[1]); | ||
| 251 | Endian_Reverse32(q[2]); | ||
| 252 | Endian_Reverse32(q[3]); | ||
| 253 | q+=4; | ||
| 254 | } | ||
| 255 | #endif | ||
| 256 | #else | ||
| 257 | q=p; | ||
| 258 | for (i=(MD5_LBLOCK/4); i; i--) | ||
| 259 | { | ||
| 260 | ULONG l; | ||
| 261 | c2l(b,l); *(q++)=l; | ||
| 262 | c2l(b,l); *(q++)=l; | ||
| 263 | c2l(b,l); *(q++)=l; | ||
| 264 | c2l(b,l); *(q++)=l; | ||
| 265 | } | ||
| 266 | #endif | ||
| 267 | md5_block(c,p,64); | ||
| 268 | } | ||
| 269 | |||
| 270 | #ifndef MD5_ASM | ||
| 271 | |||
| 272 | static void md5_block(c, X, num) | ||
| 273 | MD5_CTX *c; | ||
| 274 | register ULONG *X; | ||
| 275 | int num; | ||
| 276 | { | ||
| 277 | register ULONG A,B,C,D; | ||
| 278 | |||
| 279 | A=c->A; | ||
| 280 | B=c->B; | ||
| 281 | C=c->C; | ||
| 282 | D=c->D; | ||
| 283 | for (;;) | ||
| 284 | { | ||
| 285 | /* Round 0 */ | ||
| 286 | R0(A,B,C,D,X[ 0], 7,0xd76aa478L); | ||
| 287 | R0(D,A,B,C,X[ 1],12,0xe8c7b756L); | ||
| 288 | R0(C,D,A,B,X[ 2],17,0x242070dbL); | ||
| 289 | R0(B,C,D,A,X[ 3],22,0xc1bdceeeL); | ||
| 290 | R0(A,B,C,D,X[ 4], 7,0xf57c0fafL); | ||
| 291 | R0(D,A,B,C,X[ 5],12,0x4787c62aL); | ||
| 292 | R0(C,D,A,B,X[ 6],17,0xa8304613L); | ||
| 293 | R0(B,C,D,A,X[ 7],22,0xfd469501L); | ||
| 294 | R0(A,B,C,D,X[ 8], 7,0x698098d8L); | ||
| 295 | R0(D,A,B,C,X[ 9],12,0x8b44f7afL); | ||
| 296 | R0(C,D,A,B,X[10],17,0xffff5bb1L); | ||
| 297 | R0(B,C,D,A,X[11],22,0x895cd7beL); | ||
| 298 | R0(A,B,C,D,X[12], 7,0x6b901122L); | ||
| 299 | R0(D,A,B,C,X[13],12,0xfd987193L); | ||
| 300 | R0(C,D,A,B,X[14],17,0xa679438eL); | ||
| 301 | R0(B,C,D,A,X[15],22,0x49b40821L); | ||
| 302 | /* Round 1 */ | ||
| 303 | R1(A,B,C,D,X[ 1], 5,0xf61e2562L); | ||
| 304 | R1(D,A,B,C,X[ 6], 9,0xc040b340L); | ||
| 305 | R1(C,D,A,B,X[11],14,0x265e5a51L); | ||
| 306 | R1(B,C,D,A,X[ 0],20,0xe9b6c7aaL); | ||
| 307 | R1(A,B,C,D,X[ 5], 5,0xd62f105dL); | ||
| 308 | R1(D,A,B,C,X[10], 9,0x02441453L); | ||
| 309 | R1(C,D,A,B,X[15],14,0xd8a1e681L); | ||
| 310 | R1(B,C,D,A,X[ 4],20,0xe7d3fbc8L); | ||
| 311 | R1(A,B,C,D,X[ 9], 5,0x21e1cde6L); | ||
| 312 | R1(D,A,B,C,X[14], 9,0xc33707d6L); | ||
| 313 | R1(C,D,A,B,X[ 3],14,0xf4d50d87L); | ||
| 314 | R1(B,C,D,A,X[ 8],20,0x455a14edL); | ||
| 315 | R1(A,B,C,D,X[13], 5,0xa9e3e905L); | ||
| 316 | R1(D,A,B,C,X[ 2], 9,0xfcefa3f8L); | ||
| 317 | R1(C,D,A,B,X[ 7],14,0x676f02d9L); | ||
| 318 | R1(B,C,D,A,X[12],20,0x8d2a4c8aL); | ||
| 319 | /* Round 2 */ | ||
| 320 | R2(A,B,C,D,X[ 5], 4,0xfffa3942L); | ||
| 321 | R2(D,A,B,C,X[ 8],11,0x8771f681L); | ||
| 322 | R2(C,D,A,B,X[11],16,0x6d9d6122L); | ||
| 323 | R2(B,C,D,A,X[14],23,0xfde5380cL); | ||
| 324 | R2(A,B,C,D,X[ 1], 4,0xa4beea44L); | ||
| 325 | R2(D,A,B,C,X[ 4],11,0x4bdecfa9L); | ||
| 326 | R2(C,D,A,B,X[ 7],16,0xf6bb4b60L); | ||
| 327 | R2(B,C,D,A,X[10],23,0xbebfbc70L); | ||
| 328 | R2(A,B,C,D,X[13], 4,0x289b7ec6L); | ||
| 329 | R2(D,A,B,C,X[ 0],11,0xeaa127faL); | ||
| 330 | R2(C,D,A,B,X[ 3],16,0xd4ef3085L); | ||
| 331 | R2(B,C,D,A,X[ 6],23,0x04881d05L); | ||
| 332 | R2(A,B,C,D,X[ 9], 4,0xd9d4d039L); | ||
| 333 | R2(D,A,B,C,X[12],11,0xe6db99e5L); | ||
| 334 | R2(C,D,A,B,X[15],16,0x1fa27cf8L); | ||
| 335 | R2(B,C,D,A,X[ 2],23,0xc4ac5665L); | ||
| 336 | /* Round 3 */ | ||
| 337 | R3(A,B,C,D,X[ 0], 6,0xf4292244L); | ||
| 338 | R3(D,A,B,C,X[ 7],10,0x432aff97L); | ||
| 339 | R3(C,D,A,B,X[14],15,0xab9423a7L); | ||
| 340 | R3(B,C,D,A,X[ 5],21,0xfc93a039L); | ||
| 341 | R3(A,B,C,D,X[12], 6,0x655b59c3L); | ||
| 342 | R3(D,A,B,C,X[ 3],10,0x8f0ccc92L); | ||
| 343 | R3(C,D,A,B,X[10],15,0xffeff47dL); | ||
| 344 | R3(B,C,D,A,X[ 1],21,0x85845dd1L); | ||
| 345 | R3(A,B,C,D,X[ 8], 6,0x6fa87e4fL); | ||
| 346 | R3(D,A,B,C,X[15],10,0xfe2ce6e0L); | ||
| 347 | R3(C,D,A,B,X[ 6],15,0xa3014314L); | ||
| 348 | R3(B,C,D,A,X[13],21,0x4e0811a1L); | ||
| 349 | R3(A,B,C,D,X[ 4], 6,0xf7537e82L); | ||
| 350 | R3(D,A,B,C,X[11],10,0xbd3af235L); | ||
| 351 | R3(C,D,A,B,X[ 2],15,0x2ad7d2bbL); | ||
| 352 | R3(B,C,D,A,X[ 9],21,0xeb86d391L); | ||
| 353 | |||
| 354 | A+=c->A&0xffffffffL; | ||
| 355 | B+=c->B&0xffffffffL; | ||
| 356 | c->A=A; | ||
| 357 | c->B=B; | ||
| 358 | C+=c->C&0xffffffffL; | ||
| 359 | D+=c->D&0xffffffffL; | ||
| 360 | c->C=C; | ||
| 361 | c->D=D; | ||
| 362 | X+=16; | ||
| 363 | num-=64; | ||
| 364 | if (num <= 0) break; | ||
| 365 | } | ||
| 366 | } | ||
| 367 | #endif | ||
| 368 | |||
| 369 | void MD5_Final(md, c) | ||
| 370 | unsigned char *md; | ||
| 371 | MD5_CTX *c; | ||
| 372 | { | ||
| 373 | register int i,j; | ||
| 374 | register ULONG l; | ||
| 375 | register ULONG *p; | ||
| 376 | static unsigned char end[4]={0x80,0x00,0x00,0x00}; | ||
| 377 | unsigned char *cp=end; | ||
| 378 | |||
| 379 | /* c->num should definitly have room for at least one more byte. */ | ||
| 380 | p=c->data; | ||
| 381 | j=c->num; | ||
| 382 | i=j>>2; | ||
| 383 | |||
| 384 | /* purify often complains about the following line as an | ||
| 385 | * Uninitialized Memory Read. While this can be true, the | ||
| 386 | * following p_c2l macro will reset l when that case is true. | ||
| 387 | * This is because j&0x03 contains the number of 'valid' bytes | ||
| 388 | * already in p[i]. If and only if j&0x03 == 0, the UMR will | ||
| 389 | * occur but this is also the only time p_c2l will do | ||
| 390 | * l= *(cp++) instead of l|= *(cp++) | ||
| 391 | * Many thanks to Alex Tang <altitude@cic.net> for pickup this | ||
| 392 | * 'potential bug' */ | ||
| 393 | #ifdef PURIFY | ||
| 394 | if ((j&0x03) == 0) p[i]=0; | ||
| 395 | #endif | ||
| 396 | l=p[i]; | ||
| 397 | p_c2l(cp,l,j&0x03); | ||
| 398 | p[i]=l; | ||
| 399 | i++; | ||
| 400 | /* i is the next 'undefined word' */ | ||
| 401 | if (c->num >= MD5_LAST_BLOCK) | ||
| 402 | { | ||
| 403 | for (; i<MD5_LBLOCK; i++) | ||
| 404 | p[i]=0; | ||
| 405 | md5_block(c,p,64); | ||
| 406 | i=0; | ||
| 407 | } | ||
| 408 | for (; i<(MD5_LBLOCK-2); i++) | ||
| 409 | p[i]=0; | ||
| 410 | p[MD5_LBLOCK-2]=c->Nl; | ||
| 411 | p[MD5_LBLOCK-1]=c->Nh; | ||
| 412 | md5_block(c,p,64); | ||
| 413 | cp=md; | ||
| 414 | l=c->A; l2c(l,cp); | ||
| 415 | l=c->B; l2c(l,cp); | ||
| 416 | l=c->C; l2c(l,cp); | ||
| 417 | l=c->D; l2c(l,cp); | ||
| 418 | |||
| 419 | /* clear stuff, md5_block may be leaving some stuff on the stack | ||
| 420 | * but I'm not worried :-) */ | ||
| 421 | c->num=0; | ||
| 422 | /* memset((char *)&c,0,sizeof(c));*/ | ||
| 423 | } | ||
| 424 | |||
| 425 | #ifdef undef | ||
| 426 | int printit(l) | ||
| 427 | unsigned long *l; | ||
| 428 | { | ||
| 429 | int i,ii; | ||
| 430 | |||
| 431 | for (i=0; i<2; i++) | ||
| 432 | { | ||
| 433 | for (ii=0; ii<8; ii++) | ||
| 434 | { | ||
| 435 | fprintf(stderr,"%08lx ",l[i*8+ii]); | ||
| 436 | } | ||
| 437 | fprintf(stderr,"\n"); | ||
| 438 | } | ||
| 439 | } | ||
| 440 | #endif | ||
diff --git a/src/lib/libcrypto/md5/md5_locl.h b/src/lib/libcrypto/md5/md5_locl.h new file mode 100644 index 0000000000..dbbe1b71ca --- /dev/null +++ b/src/lib/libcrypto/md5/md5_locl.h | |||
| @@ -0,0 +1,195 @@ | |||
| 1 | /* crypto/md5/md5_locl.h */ | ||
| 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 | /* On sparc, this actually slows things down :-( */ | ||
| 60 | #if defined(sun) | ||
| 61 | #undef B_ENDIAN | ||
| 62 | #endif | ||
| 63 | |||
| 64 | #include <stdlib.h> | ||
| 65 | #include <string.h> | ||
| 66 | #include "md5.h" | ||
| 67 | |||
| 68 | #define ULONG unsigned long | ||
| 69 | #define UCHAR unsigned char | ||
| 70 | #define UINT unsigned int | ||
| 71 | |||
| 72 | #if defined(NOCONST) | ||
| 73 | #define const | ||
| 74 | #endif | ||
| 75 | |||
| 76 | #undef c2l | ||
| 77 | #define c2l(c,l) (l = ((unsigned long)(*((c)++))) , \ | ||
| 78 | l|=(((unsigned long)(*((c)++)))<< 8), \ | ||
| 79 | l|=(((unsigned long)(*((c)++)))<<16), \ | ||
| 80 | l|=(((unsigned long)(*((c)++)))<<24)) | ||
| 81 | |||
| 82 | #undef p_c2l | ||
| 83 | #define p_c2l(c,l,n) { \ | ||
| 84 | switch (n) { \ | ||
| 85 | case 0: l =((unsigned long)(*((c)++))); \ | ||
| 86 | case 1: l|=((unsigned long)(*((c)++)))<< 8; \ | ||
| 87 | case 2: l|=((unsigned long)(*((c)++)))<<16; \ | ||
| 88 | case 3: l|=((unsigned long)(*((c)++)))<<24; \ | ||
| 89 | } \ | ||
| 90 | } | ||
| 91 | |||
| 92 | /* NOTE the pointer is not incremented at the end of this */ | ||
| 93 | #undef c2l_p | ||
| 94 | #define c2l_p(c,l,n) { \ | ||
| 95 | l=0; \ | ||
| 96 | (c)+=n; \ | ||
| 97 | switch (n) { \ | ||
| 98 | case 3: l =((unsigned long)(*(--(c))))<<16; \ | ||
| 99 | case 2: l|=((unsigned long)(*(--(c))))<< 8; \ | ||
| 100 | case 1: l|=((unsigned long)(*(--(c)))) ; \ | ||
| 101 | } \ | ||
| 102 | } | ||
| 103 | |||
| 104 | #undef p_c2l_p | ||
| 105 | #define p_c2l_p(c,l,sc,len) { \ | ||
| 106 | switch (sc) \ | ||
| 107 | { \ | ||
| 108 | case 0: l =((unsigned long)(*((c)++))); \ | ||
| 109 | if (--len == 0) break; \ | ||
| 110 | case 1: l|=((unsigned long)(*((c)++)))<< 8; \ | ||
| 111 | if (--len == 0) break; \ | ||
| 112 | case 2: l|=((unsigned long)(*((c)++)))<<16; \ | ||
| 113 | } \ | ||
| 114 | } | ||
| 115 | |||
| 116 | #undef l2c | ||
| 117 | #define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ | ||
| 118 | *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ | ||
| 119 | *((c)++)=(unsigned char)(((l)>>16)&0xff), \ | ||
| 120 | *((c)++)=(unsigned char)(((l)>>24)&0xff)) | ||
| 121 | |||
| 122 | /* NOTE - c is not incremented as per l2c */ | ||
| 123 | #undef l2cn | ||
| 124 | #define l2cn(l1,l2,c,n) { \ | ||
| 125 | c+=n; \ | ||
| 126 | switch (n) { \ | ||
| 127 | case 8: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \ | ||
| 128 | case 7: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \ | ||
| 129 | case 6: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \ | ||
| 130 | case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \ | ||
| 131 | case 4: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \ | ||
| 132 | case 3: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \ | ||
| 133 | case 2: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \ | ||
| 134 | case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \ | ||
| 135 | } \ | ||
| 136 | } | ||
| 137 | |||
| 138 | /* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */ | ||
| 139 | #if defined(WIN32) | ||
| 140 | /* 5 instructions with rotate instruction, else 9 */ | ||
| 141 | #define Endian_Reverse32(a) \ | ||
| 142 | { \ | ||
| 143 | unsigned long l=(a); \ | ||
| 144 | (a)=((ROTATE(l,8)&0x00FF00FF)|(ROTATE(l,24)&0xFF00FF00)); \ | ||
| 145 | } | ||
| 146 | #else | ||
| 147 | /* 6 instructions with rotate instruction, else 8 */ | ||
| 148 | #define Endian_Reverse32(a) \ | ||
| 149 | { \ | ||
| 150 | unsigned long l=(a); \ | ||
| 151 | l=(((l&0xFF00FF00)>>8L)|((l&0x00FF00FF)<<8L)); \ | ||
| 152 | (a)=ROTATE(l,16L); \ | ||
| 153 | } | ||
| 154 | #endif | ||
| 155 | /* | ||
| 156 | #define F(x,y,z) (((x) & (y)) | ((~(x)) & (z))) | ||
| 157 | #define G(x,y,z) (((x) & (z)) | ((y) & (~(z)))) | ||
| 158 | */ | ||
| 159 | |||
| 160 | /* As pointed out by Wei Dai <weidai@eskimo.com>, the above can be | ||
| 161 | * simplified to the code below. Wei attributes these optimisations | ||
| 162 | * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel. | ||
| 163 | */ | ||
| 164 | #define F(b,c,d) ((((c) ^ (d)) & (b)) ^ (d)) | ||
| 165 | #define G(b,c,d) ((((b) ^ (c)) & (d)) ^ (c)) | ||
| 166 | #define H(b,c,d) ((b) ^ (c) ^ (d)) | ||
| 167 | #define I(b,c,d) (((~(d)) | (b)) ^ (c)) | ||
| 168 | |||
| 169 | #undef ROTATE | ||
| 170 | #if defined(WIN32) | ||
| 171 | #define ROTATE(a,n) _lrotl(a,n) | ||
| 172 | #else | ||
| 173 | #define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n)))) | ||
| 174 | #endif | ||
| 175 | |||
| 176 | |||
| 177 | #define R0(a,b,c,d,k,s,t) { \ | ||
| 178 | a+=((k)+(t)+F((b),(c),(d))); \ | ||
| 179 | a=ROTATE(a,s); \ | ||
| 180 | a+=b; };\ | ||
| 181 | |||
| 182 | #define R1(a,b,c,d,k,s,t) { \ | ||
| 183 | a+=((k)+(t)+G((b),(c),(d))); \ | ||
| 184 | a=ROTATE(a,s); \ | ||
| 185 | a+=b; }; | ||
| 186 | |||
| 187 | #define R2(a,b,c,d,k,s,t) { \ | ||
| 188 | a+=((k)+(t)+H((b),(c),(d))); \ | ||
| 189 | a=ROTATE(a,s); \ | ||
| 190 | a+=b; }; | ||
| 191 | |||
| 192 | #define R3(a,b,c,d,k,s,t) { \ | ||
| 193 | a+=((k)+(t)+I((b),(c),(d))); \ | ||
| 194 | a=ROTATE(a,s); \ | ||
| 195 | a+=b; }; | ||
diff --git a/src/lib/libcrypto/md5/md5_one.c b/src/lib/libcrypto/md5/md5_one.c new file mode 100644 index 0000000000..ab6bb435f9 --- /dev/null +++ b/src/lib/libcrypto/md5/md5_one.c | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | /* crypto/md5/md5_one.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 "md5_locl.h" | ||
| 61 | |||
| 62 | unsigned char *MD5(d, n, md) | ||
| 63 | unsigned char *d; | ||
| 64 | unsigned long n; | ||
| 65 | unsigned char *md; | ||
| 66 | { | ||
| 67 | MD5_CTX c; | ||
| 68 | static unsigned char m[MD5_DIGEST_LENGTH]; | ||
| 69 | |||
| 70 | if (md == NULL) md=m; | ||
| 71 | MD5_Init(&c); | ||
| 72 | MD5_Update(&c,d,n); | ||
| 73 | MD5_Final(md,&c); | ||
| 74 | memset(&c,0,sizeof(c)); /* security consideration */ | ||
| 75 | return(md); | ||
| 76 | } | ||
| 77 | |||
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c new file mode 100644 index 0000000000..34866ebbd2 --- /dev/null +++ b/src/lib/libcrypto/objects/obj_dat.c | |||
| @@ -0,0 +1,578 @@ | |||
| 1 | /* crypto/objects/obj_dat.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 <ctype.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "lhash.h" | ||
| 63 | #include "asn1.h" | ||
| 64 | #include "objects.h" | ||
| 65 | |||
| 66 | /* obj_dat.h is generated from objects.h by obj_dat.pl */ | ||
| 67 | #include "obj_dat.h" | ||
| 68 | |||
| 69 | #ifndef NOPROTO | ||
| 70 | static int sn_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b); | ||
| 71 | static int ln_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b); | ||
| 72 | static int obj_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b); | ||
| 73 | #else | ||
| 74 | static int sn_cmp(); | ||
| 75 | static int ln_cmp(); | ||
| 76 | static int obj_cmp(); | ||
| 77 | #endif | ||
| 78 | |||
| 79 | #define ADDED_DATA 0 | ||
| 80 | #define ADDED_SNAME 1 | ||
| 81 | #define ADDED_LNAME 2 | ||
| 82 | #define ADDED_NID 3 | ||
| 83 | |||
| 84 | typedef struct added_obj_st | ||
| 85 | { | ||
| 86 | int type; | ||
| 87 | ASN1_OBJECT *obj; | ||
| 88 | } ADDED_OBJ; | ||
| 89 | |||
| 90 | static int new_nid=NUM_NID; | ||
| 91 | static LHASH *added=NULL; | ||
| 92 | |||
| 93 | static int sn_cmp(ap,bp) | ||
| 94 | ASN1_OBJECT **ap; | ||
| 95 | ASN1_OBJECT **bp; | ||
| 96 | { return(strcmp((*ap)->sn,(*bp)->sn)); } | ||
| 97 | |||
| 98 | static int ln_cmp(ap,bp) | ||
| 99 | ASN1_OBJECT **ap; | ||
| 100 | ASN1_OBJECT **bp; | ||
| 101 | { return(strcmp((*ap)->ln,(*bp)->ln)); } | ||
| 102 | |||
| 103 | static unsigned long add_hash(ca) | ||
| 104 | ADDED_OBJ *ca; | ||
| 105 | { | ||
| 106 | ASN1_OBJECT *a; | ||
| 107 | int i; | ||
| 108 | unsigned long ret=0; | ||
| 109 | unsigned char *p; | ||
| 110 | |||
| 111 | a=ca->obj; | ||
| 112 | switch (ca->type) | ||
| 113 | { | ||
| 114 | case ADDED_DATA: | ||
| 115 | ret=a->length<<20L; | ||
| 116 | p=(unsigned char *)a->data; | ||
| 117 | for (i=0; i<a->length; i++) | ||
| 118 | ret^=p[i]<<((i*3)%24); | ||
| 119 | break; | ||
| 120 | case ADDED_SNAME: | ||
| 121 | ret=lh_strhash(a->sn); | ||
| 122 | break; | ||
| 123 | case ADDED_LNAME: | ||
| 124 | ret=lh_strhash(a->ln); | ||
| 125 | break; | ||
| 126 | case ADDED_NID: | ||
| 127 | ret=a->nid; | ||
| 128 | break; | ||
| 129 | default: | ||
| 130 | abort(); | ||
| 131 | } | ||
| 132 | ret&=0x3fffffffL; | ||
| 133 | ret|=ca->type<<30L; | ||
| 134 | return(ret); | ||
| 135 | } | ||
| 136 | |||
| 137 | static int add_cmp(ca,cb) | ||
| 138 | ADDED_OBJ *ca,*cb; | ||
| 139 | { | ||
| 140 | ASN1_OBJECT *a,*b; | ||
| 141 | int i; | ||
| 142 | |||
| 143 | i=ca->type-cb->type; | ||
| 144 | if (i) return(i); | ||
| 145 | a=ca->obj; | ||
| 146 | b=cb->obj; | ||
| 147 | switch (ca->type) | ||
| 148 | { | ||
| 149 | case ADDED_DATA: | ||
| 150 | i=(a->length - b->length); | ||
| 151 | if (i) return(i); | ||
| 152 | return(memcmp(a->data,b->data,a->length)); | ||
| 153 | case ADDED_SNAME: | ||
| 154 | if (a->sn == NULL) return(-1); | ||
| 155 | else if (b->sn == NULL) return(1); | ||
| 156 | else return(strcmp(a->sn,b->sn)); | ||
| 157 | case ADDED_LNAME: | ||
| 158 | if (a->ln == NULL) return(-1); | ||
| 159 | else if (b->ln == NULL) return(1); | ||
| 160 | else return(strcmp(a->ln,b->ln)); | ||
| 161 | case ADDED_NID: | ||
| 162 | return(a->nid-b->nid); | ||
| 163 | default: | ||
| 164 | abort(); | ||
| 165 | } | ||
| 166 | } | ||
| 167 | |||
| 168 | static int init_added() | ||
| 169 | { | ||
| 170 | if (added != NULL) return(1); | ||
| 171 | added=lh_new(add_hash,add_cmp); | ||
| 172 | return(added != NULL); | ||
| 173 | } | ||
| 174 | |||
| 175 | static void cleanup1(a) | ||
| 176 | ADDED_OBJ *a; | ||
| 177 | { | ||
| 178 | a->obj->nid=0; | ||
| 179 | a->obj->flags|=ASN1_OBJECT_FLAG_DYNAMIC| | ||
| 180 | ASN1_OBJECT_FLAG_DYNAMIC_STRINGS; | ||
| 181 | } | ||
| 182 | |||
| 183 | static void cleanup2(a) | ||
| 184 | ADDED_OBJ *a; | ||
| 185 | { a->obj->nid++; } | ||
| 186 | |||
| 187 | static void cleanup3(a) | ||
| 188 | ADDED_OBJ *a; | ||
| 189 | { | ||
| 190 | if (--a->obj->nid == 0) | ||
| 191 | ASN1_OBJECT_free(a->obj); | ||
| 192 | Free(a); | ||
| 193 | } | ||
| 194 | |||
| 195 | void OBJ_cleanup() | ||
| 196 | { | ||
| 197 | if (added == NULL) return; | ||
| 198 | added->down_load=0; | ||
| 199 | lh_doall(added,cleanup1); /* zero counters */ | ||
| 200 | lh_doall(added,cleanup2); /* set counters */ | ||
| 201 | lh_doall(added,cleanup3); /* free objects */ | ||
| 202 | lh_free(added); | ||
| 203 | added=NULL; | ||
| 204 | } | ||
| 205 | |||
| 206 | int OBJ_new_nid(num) | ||
| 207 | int num; | ||
| 208 | { | ||
| 209 | int i; | ||
| 210 | |||
| 211 | i=new_nid; | ||
| 212 | new_nid+=num; | ||
| 213 | return(i); | ||
| 214 | } | ||
| 215 | |||
| 216 | int OBJ_add_object(obj) | ||
| 217 | ASN1_OBJECT *obj; | ||
| 218 | { | ||
| 219 | ASN1_OBJECT *o; | ||
| 220 | ADDED_OBJ *ao[4],*aop; | ||
| 221 | int i; | ||
| 222 | |||
| 223 | if (added == NULL) | ||
| 224 | if (!init_added()) return(0); | ||
| 225 | if ((o=OBJ_dup(obj)) == NULL) goto err; | ||
| 226 | ao[ADDED_DATA]=NULL; | ||
| 227 | ao[ADDED_SNAME]=NULL; | ||
| 228 | ao[ADDED_LNAME]=NULL; | ||
| 229 | ao[ADDED_NID]=NULL; | ||
| 230 | ao[ADDED_NID]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ)); | ||
| 231 | if ((o->length != 0) && (obj->data != NULL)) | ||
| 232 | ao[ADDED_DATA]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ)); | ||
| 233 | if (o->sn != NULL) | ||
| 234 | ao[ADDED_SNAME]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ)); | ||
| 235 | if (o->ln != NULL) | ||
| 236 | ao[ADDED_LNAME]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ)); | ||
| 237 | |||
| 238 | for (i=ADDED_DATA; i<=ADDED_NID; i++) | ||
| 239 | { | ||
| 240 | if (ao[i] != NULL) | ||
| 241 | { | ||
| 242 | ao[i]->type=i; | ||
| 243 | ao[i]->obj=o; | ||
| 244 | aop=(ADDED_OBJ *)lh_insert(added,(char *)ao[i]); | ||
| 245 | /* memory leak, buit should not normally matter */ | ||
| 246 | if (aop != NULL) | ||
| 247 | Free(aop); | ||
| 248 | } | ||
| 249 | } | ||
| 250 | o->flags&= ~(ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS); | ||
| 251 | return(o->nid); | ||
| 252 | err: | ||
| 253 | for (i=ADDED_DATA; i<=ADDED_NID; i++) | ||
| 254 | if (ao[i] != NULL) Free(ao[i]); | ||
| 255 | if (o != NULL) Free(o); | ||
| 256 | return(NID_undef); | ||
| 257 | } | ||
| 258 | |||
| 259 | ASN1_OBJECT *OBJ_nid2obj(n) | ||
| 260 | int n; | ||
| 261 | { | ||
| 262 | ADDED_OBJ ad,*adp; | ||
| 263 | ASN1_OBJECT ob; | ||
| 264 | |||
| 265 | if ((n >= 0) && (n < NUM_NID)) | ||
| 266 | { | ||
| 267 | if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) | ||
| 268 | { | ||
| 269 | OBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID); | ||
| 270 | return(NULL); | ||
| 271 | } | ||
| 272 | return((ASN1_OBJECT *)&(nid_objs[n])); | ||
| 273 | } | ||
| 274 | else if (added == NULL) | ||
| 275 | return(NULL); | ||
| 276 | else | ||
| 277 | { | ||
| 278 | ad.type=ADDED_NID; | ||
| 279 | ad.obj= &ob; | ||
| 280 | ob.nid=n; | ||
| 281 | adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad); | ||
| 282 | if (adp != NULL) | ||
| 283 | return(adp->obj); | ||
| 284 | else | ||
| 285 | { | ||
| 286 | OBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID); | ||
| 287 | return(NULL); | ||
| 288 | } | ||
| 289 | } | ||
| 290 | } | ||
| 291 | |||
| 292 | char *OBJ_nid2sn(n) | ||
| 293 | int n; | ||
| 294 | { | ||
| 295 | ADDED_OBJ ad,*adp; | ||
| 296 | ASN1_OBJECT ob; | ||
| 297 | |||
| 298 | if ((n >= 0) && (n < NUM_NID)) | ||
| 299 | { | ||
| 300 | if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) | ||
| 301 | { | ||
| 302 | OBJerr(OBJ_F_OBJ_NID2SN,OBJ_R_UNKNOWN_NID); | ||
| 303 | return(NULL); | ||
| 304 | } | ||
| 305 | return(nid_objs[n].sn); | ||
| 306 | } | ||
| 307 | else if (added == NULL) | ||
| 308 | return(NULL); | ||
| 309 | else | ||
| 310 | { | ||
| 311 | ad.type=ADDED_NID; | ||
| 312 | ad.obj= &ob; | ||
| 313 | ob.nid=n; | ||
| 314 | adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad); | ||
| 315 | if (adp != NULL) | ||
| 316 | return(adp->obj->sn); | ||
| 317 | else | ||
| 318 | { | ||
| 319 | OBJerr(OBJ_F_OBJ_NID2SN,OBJ_R_UNKNOWN_NID); | ||
| 320 | return(NULL); | ||
| 321 | } | ||
| 322 | } | ||
| 323 | } | ||
| 324 | |||
| 325 | char *OBJ_nid2ln(n) | ||
| 326 | int n; | ||
| 327 | { | ||
| 328 | ADDED_OBJ ad,*adp; | ||
| 329 | ASN1_OBJECT ob; | ||
| 330 | |||
| 331 | if ((n >= 0) && (n < NUM_NID)) | ||
| 332 | { | ||
| 333 | if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) | ||
| 334 | { | ||
| 335 | OBJerr(OBJ_F_OBJ_NID2LN,OBJ_R_UNKNOWN_NID); | ||
| 336 | return(NULL); | ||
| 337 | } | ||
| 338 | return(nid_objs[n].ln); | ||
| 339 | } | ||
| 340 | else if (added == NULL) | ||
| 341 | return(NULL); | ||
| 342 | else | ||
| 343 | { | ||
| 344 | ad.type=ADDED_NID; | ||
| 345 | ad.obj= &ob; | ||
| 346 | ob.nid=n; | ||
| 347 | adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad); | ||
| 348 | if (adp != NULL) | ||
| 349 | return(adp->obj->ln); | ||
| 350 | else | ||
| 351 | { | ||
| 352 | OBJerr(OBJ_F_OBJ_NID2LN,OBJ_R_UNKNOWN_NID); | ||
| 353 | return(NULL); | ||
| 354 | } | ||
| 355 | } | ||
| 356 | } | ||
| 357 | |||
| 358 | int OBJ_obj2nid(a) | ||
| 359 | ASN1_OBJECT *a; | ||
| 360 | { | ||
| 361 | ASN1_OBJECT **op; | ||
| 362 | ADDED_OBJ ad,*adp; | ||
| 363 | |||
| 364 | if (a == NULL) | ||
| 365 | return(NID_undef); | ||
| 366 | if (a->nid != 0) | ||
| 367 | return(a->nid); | ||
| 368 | |||
| 369 | if (added != NULL) | ||
| 370 | { | ||
| 371 | ad.type=ADDED_DATA; | ||
| 372 | ad.obj=a; | ||
| 373 | adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad); | ||
| 374 | if (adp != NULL) return (adp->obj->nid); | ||
| 375 | } | ||
| 376 | op=(ASN1_OBJECT **)OBJ_bsearch((char *)&a,(char *)obj_objs,NUM_OBJ, | ||
| 377 | sizeof(ASN1_OBJECT *),(int (*)())obj_cmp); | ||
| 378 | if (op == NULL) | ||
| 379 | return(NID_undef); | ||
| 380 | return((*op)->nid); | ||
| 381 | } | ||
| 382 | |||
| 383 | int OBJ_txt2nid(s) | ||
| 384 | char *s; | ||
| 385 | { | ||
| 386 | int ret; | ||
| 387 | |||
| 388 | ret=OBJ_sn2nid(s); | ||
| 389 | if (ret == NID_undef) | ||
| 390 | { | ||
| 391 | ret=OBJ_ln2nid(s); | ||
| 392 | if (ret == NID_undef) | ||
| 393 | { | ||
| 394 | ASN1_OBJECT *op=NULL; | ||
| 395 | unsigned char *buf,*p; | ||
| 396 | int i; | ||
| 397 | |||
| 398 | i=a2d_ASN1_OBJECT(NULL,0,s,-1); | ||
| 399 | if (i <= 0) | ||
| 400 | { | ||
| 401 | /* clear the error */ | ||
| 402 | ERR_get_error(); | ||
| 403 | return(0); | ||
| 404 | } | ||
| 405 | |||
| 406 | if ((buf=(unsigned char *)Malloc(i)) == NULL) | ||
| 407 | return(NID_undef); | ||
| 408 | a2d_ASN1_OBJECT(buf,i,s,-1); | ||
| 409 | p=buf; | ||
| 410 | op=d2i_ASN1_OBJECT(NULL,&p,i); | ||
| 411 | if (op == NULL) return(NID_undef); | ||
| 412 | ret=OBJ_obj2nid(op); | ||
| 413 | ASN1_OBJECT_free(op); | ||
| 414 | Free(buf); | ||
| 415 | } | ||
| 416 | } | ||
| 417 | return(ret); | ||
| 418 | } | ||
| 419 | |||
| 420 | int OBJ_ln2nid(s) | ||
| 421 | char *s; | ||
| 422 | { | ||
| 423 | ASN1_OBJECT o,*oo= &o,**op; | ||
| 424 | ADDED_OBJ ad,*adp; | ||
| 425 | |||
| 426 | o.ln=s; | ||
| 427 | if (added != NULL) | ||
| 428 | { | ||
| 429 | ad.type=ADDED_LNAME; | ||
| 430 | ad.obj= &o; | ||
| 431 | adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad); | ||
| 432 | if (adp != NULL) return (adp->obj->nid); | ||
| 433 | } | ||
| 434 | op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)ln_objs,NUM_LN, | ||
| 435 | sizeof(ASN1_OBJECT *),(int (*)())ln_cmp); | ||
| 436 | if (op == NULL) return(NID_undef); | ||
| 437 | return((*op)->nid); | ||
| 438 | } | ||
| 439 | |||
| 440 | int OBJ_sn2nid(s) | ||
| 441 | char *s; | ||
| 442 | { | ||
| 443 | ASN1_OBJECT o,*oo= &o,**op; | ||
| 444 | ADDED_OBJ ad,*adp; | ||
| 445 | |||
| 446 | o.sn=s; | ||
| 447 | if (added != NULL) | ||
| 448 | { | ||
| 449 | ad.type=ADDED_SNAME; | ||
| 450 | ad.obj= &o; | ||
| 451 | adp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad); | ||
| 452 | if (adp != NULL) return (adp->obj->nid); | ||
| 453 | } | ||
| 454 | op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)sn_objs,NUM_SN, | ||
| 455 | sizeof(ASN1_OBJECT *),(int (*)())sn_cmp); | ||
| 456 | if (op == NULL) return(NID_undef); | ||
| 457 | return((*op)->nid); | ||
| 458 | } | ||
| 459 | |||
| 460 | static int obj_cmp(ap, bp) | ||
| 461 | ASN1_OBJECT **ap; | ||
| 462 | ASN1_OBJECT **bp; | ||
| 463 | { | ||
| 464 | int j; | ||
| 465 | ASN1_OBJECT *a= *ap; | ||
| 466 | ASN1_OBJECT *b= *bp; | ||
| 467 | |||
| 468 | j=(a->length - b->length); | ||
| 469 | if (j) return(j); | ||
| 470 | return(memcmp(a->data,b->data,a->length)); | ||
| 471 | } | ||
| 472 | |||
| 473 | char *OBJ_bsearch(key,base,num,size,cmp) | ||
| 474 | char *key; | ||
| 475 | char *base; | ||
| 476 | int num; | ||
| 477 | int size; | ||
| 478 | int (*cmp)(); | ||
| 479 | { | ||
| 480 | int l,h,i,c; | ||
| 481 | char *p; | ||
| 482 | |||
| 483 | if (num == 0) return(NULL); | ||
| 484 | l=0; | ||
| 485 | h=num; | ||
| 486 | while (l < h) | ||
| 487 | { | ||
| 488 | i=(l+h)/2; | ||
| 489 | p= &(base[i*size]); | ||
| 490 | c=(*cmp)(key,p); | ||
| 491 | if (c < 0) | ||
| 492 | h=i; | ||
| 493 | else if (c > 0) | ||
| 494 | l=i+1; | ||
| 495 | else | ||
| 496 | return(p); | ||
| 497 | } | ||
| 498 | return(NULL); | ||
| 499 | } | ||
| 500 | |||
| 501 | int OBJ_create_objects(in) | ||
| 502 | BIO *in; | ||
| 503 | { | ||
| 504 | MS_STATIC char buf[512]; | ||
| 505 | int i,num= -1; | ||
| 506 | char *o,*s,*l=NULL; | ||
| 507 | |||
| 508 | for (;;) | ||
| 509 | { | ||
| 510 | s=o=NULL; | ||
| 511 | i=BIO_gets(in,buf,512); | ||
| 512 | if (i <= 0) return(num); | ||
| 513 | buf[i-1]='\0'; | ||
| 514 | if (!isalnum(buf[0])) return(num); | ||
| 515 | o=s=buf; | ||
| 516 | while (isdigit(*s) || (*s == '.')) | ||
| 517 | s++; | ||
| 518 | if (*s != '\0') | ||
| 519 | { | ||
| 520 | *(s++)='\0'; | ||
| 521 | while (isspace(*s)) | ||
| 522 | s++; | ||
| 523 | if (*s == '\0') | ||
| 524 | s=NULL; | ||
| 525 | else | ||
| 526 | { | ||
| 527 | l=s; | ||
| 528 | while ((*l != '\0') && !isspace(*l)) | ||
| 529 | l++; | ||
| 530 | if (*l != '\0') | ||
| 531 | { | ||
| 532 | *(l++)='\0'; | ||
| 533 | while (isspace(*l)) | ||
| 534 | l++; | ||
| 535 | if (*l == '\0') l=NULL; | ||
| 536 | } | ||
| 537 | else | ||
| 538 | l=NULL; | ||
| 539 | } | ||
| 540 | } | ||
| 541 | else | ||
| 542 | s=NULL; | ||
| 543 | if ((o == NULL) || (*o == '\0')) return(num); | ||
| 544 | if (!OBJ_create(o,s,l)) return(num); | ||
| 545 | num++; | ||
| 546 | } | ||
| 547 | return(num); | ||
| 548 | } | ||
| 549 | |||
| 550 | int OBJ_create(oid,sn,ln) | ||
| 551 | char *oid; | ||
| 552 | char *sn; | ||
| 553 | char *ln; | ||
| 554 | { | ||
| 555 | int ok=0; | ||
| 556 | ASN1_OBJECT *op=NULL; | ||
| 557 | unsigned char *buf; | ||
| 558 | int i; | ||
| 559 | |||
| 560 | i=a2d_ASN1_OBJECT(NULL,0,oid,-1); | ||
| 561 | if (i <= 0) return(0); | ||
| 562 | |||
| 563 | if ((buf=(unsigned char *)Malloc(i)) == NULL) | ||
| 564 | { | ||
| 565 | OBJerr(OBJ_F_OBJ_CREATE,OBJ_R_MALLOC_FAILURE); | ||
| 566 | return(0); | ||
| 567 | } | ||
| 568 | i=a2d_ASN1_OBJECT(buf,i,oid,-1); | ||
| 569 | op=(ASN1_OBJECT *)ASN1_OBJECT_create(OBJ_new_nid(1),buf,i,sn,ln); | ||
| 570 | if (op == NULL) | ||
| 571 | goto err; | ||
| 572 | ok=OBJ_add_object(op); | ||
| 573 | err: | ||
| 574 | ASN1_OBJECT_free(op); | ||
| 575 | Free((char *)buf); | ||
| 576 | return(ok); | ||
| 577 | } | ||
| 578 | |||
diff --git a/src/lib/libcrypto/objects/obj_dat.pl b/src/lib/libcrypto/objects/obj_dat.pl new file mode 100644 index 0000000000..4e7879d3f3 --- /dev/null +++ b/src/lib/libcrypto/objects/obj_dat.pl | |||
| @@ -0,0 +1,269 @@ | |||
| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | sub obj_cmp | ||
| 4 | { | ||
| 5 | local(@a,@b,$_,$r); | ||
| 6 | |||
| 7 | $A=$obj_len{$obj{$nid{$a}}}; | ||
| 8 | $B=$obj_len{$obj{$nid{$b}}}; | ||
| 9 | |||
| 10 | $r=($A-$B); | ||
| 11 | return($r) if $r != 0; | ||
| 12 | |||
| 13 | $A=$obj_der{$obj{$nid{$a}}}; | ||
| 14 | $B=$obj_der{$obj{$nid{$b}}}; | ||
| 15 | |||
| 16 | return($A cmp $B); | ||
| 17 | } | ||
| 18 | |||
| 19 | sub expand_obj | ||
| 20 | { | ||
| 21 | local(*v)=@_; | ||
| 22 | local($k,$d); | ||
| 23 | local($i); | ||
| 24 | |||
| 25 | do { | ||
| 26 | $i=0; | ||
| 27 | foreach $k (keys %v) | ||
| 28 | { | ||
| 29 | if (($v{$k} =~ s/(OBJ_[^,]+),/$v{$1},/)) | ||
| 30 | { $i++; } | ||
| 31 | } | ||
| 32 | } while($i); | ||
| 33 | foreach $k (keys %v) | ||
| 34 | { | ||
| 35 | @a=split(/,/,$v{$k}); | ||
| 36 | $objn{$k}=$#a+1; | ||
| 37 | } | ||
| 38 | return(%objn); | ||
| 39 | } | ||
| 40 | |||
| 41 | while (<>) | ||
| 42 | { | ||
| 43 | next unless /^\#define\s+(\S+)\s+(.*)$/; | ||
| 44 | $v=$1; | ||
| 45 | $d=$2; | ||
| 46 | if ($v =~ /^SN_(.*)$/) | ||
| 47 | { $sn{$1}=$d; } | ||
| 48 | elsif ($v =~ /^LN_(.*)$/) | ||
| 49 | { $ln{$1}=$d; } | ||
| 50 | elsif ($v =~ /^NID_(.*)$/) | ||
| 51 | { $nid{$d}=$1; } | ||
| 52 | elsif ($v =~ /^OBJ_(.*)$/) | ||
| 53 | { | ||
| 54 | $obj{$1}=$v; | ||
| 55 | $objd{$v}=$d; | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | %ob=&expand_obj(*objd); | ||
| 60 | |||
| 61 | @a=sort { $a <=> $b } keys %nid; | ||
| 62 | $n=$a[$#a]+1; | ||
| 63 | |||
| 64 | @lvalues=(); | ||
| 65 | $lvalues=0; | ||
| 66 | |||
| 67 | for ($i=0; $i<$n; $i++) | ||
| 68 | { | ||
| 69 | if (!defined($nid{$i})) | ||
| 70 | { | ||
| 71 | push(@out,"{NULL,NULL,NID_undef,0,NULL},\n"); | ||
| 72 | } | ||
| 73 | else | ||
| 74 | { | ||
| 75 | $sn=defined($sn{$nid{$i}})?"$sn{$nid{$i}}":"NULL"; | ||
| 76 | $ln=defined($ln{$nid{$i}})?"$ln{$nid{$i}}":"NULL"; | ||
| 77 | $sn=$ln if ($sn eq "NULL"); | ||
| 78 | $ln=$sn if ($ln eq "NULL"); | ||
| 79 | $out ="{"; | ||
| 80 | $out.=$sn; | ||
| 81 | $out.=",".$ln; | ||
| 82 | $out.=",NID_$nid{$i},"; | ||
| 83 | if (defined($obj{$nid{$i}})) | ||
| 84 | { | ||
| 85 | $v=$objd{$obj{$nid{$i}}}; | ||
| 86 | $v =~ s/L//g; | ||
| 87 | $v =~ s/,/ /g; | ||
| 88 | $r=&der_it($v); | ||
| 89 | $z=""; | ||
| 90 | $length=0; | ||
| 91 | foreach (unpack("C*",$r)) | ||
| 92 | { | ||
| 93 | $z.=sprintf("0x%02X,",$_); | ||
| 94 | $length++; | ||
| 95 | } | ||
| 96 | $obj_der{$obj{$nid{$i}}}=$z; | ||
| 97 | $obj_len{$obj{$nid{$i}}}=$length; | ||
| 98 | |||
| 99 | push(@lvalues,sprintf("%-45s/* [%3d] %s */\n", | ||
| 100 | $z,$lvalues,$obj{$nid{$i}})); | ||
| 101 | $out.="$length,&(lvalues[$lvalues]),0"; | ||
| 102 | $lvalues+=$length; | ||
| 103 | } | ||
| 104 | else | ||
| 105 | { | ||
| 106 | $out.="0,NULL"; | ||
| 107 | } | ||
| 108 | $out.="},\n"; | ||
| 109 | push(@out,$out); | ||
| 110 | } | ||
| 111 | } | ||
| 112 | |||
| 113 | @a=grep(defined($sn{$nid{$_}}),0 .. $n); | ||
| 114 | foreach (sort { $sn{$nid{$a}} cmp $sn{$nid{$b}} } @a) | ||
| 115 | { | ||
| 116 | push(@sn,sprintf("&(nid_objs[%2d]),/* $sn{$nid{$_}} */\n",$_)); | ||
| 117 | } | ||
| 118 | |||
| 119 | @a=grep(defined($ln{$nid{$_}}),0 .. $n); | ||
| 120 | foreach (sort { $ln{$nid{$a}} cmp $ln{$nid{$b}} } @a) | ||
| 121 | { | ||
| 122 | push(@ln,sprintf("&(nid_objs[%2d]),/* $ln{$nid{$_}} */\n",$_)); | ||
| 123 | } | ||
| 124 | |||
| 125 | @a=grep(defined($obj{$nid{$_}}),0 .. $n); | ||
| 126 | foreach (sort obj_cmp @a) | ||
| 127 | { | ||
| 128 | $m=$obj{$nid{$_}}; | ||
| 129 | $v=$objd{$m}; | ||
| 130 | $v =~ s/L//g; | ||
| 131 | $v =~ s/,/ /g; | ||
| 132 | push(@ob,sprintf("&(nid_objs[%2d]),/* %-32s %s */\n",$_,$m,$v)); | ||
| 133 | } | ||
| 134 | |||
| 135 | print <<'EOF'; | ||
| 136 | /* lib/obj/obj_dat.h */ | ||
| 137 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) | ||
| 138 | * All rights reserved. | ||
| 139 | * | ||
| 140 | * This package is an SSL implementation written | ||
| 141 | * by Eric Young (eay@cryptsoft.com). | ||
| 142 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 143 | * | ||
| 144 | * This library is free for commercial and non-commercial use as long as | ||
| 145 | * the following conditions are aheared to. The following conditions | ||
| 146 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 147 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 148 | * included with this distribution is covered by the same copyright terms | ||
| 149 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 150 | * | ||
| 151 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 152 | * the code are not to be removed. | ||
| 153 | * If this package is used in a product, Eric Young should be given attribution | ||
| 154 | * as the author of the parts of the library used. | ||
| 155 | * This can be in the form of a textual message at program startup or | ||
| 156 | * in documentation (online or textual) provided with the package. | ||
| 157 | * | ||
| 158 | * Redistribution and use in source and binary forms, with or without | ||
| 159 | * modification, are permitted provided that the following conditions | ||
| 160 | * are met: | ||
| 161 | * 1. Redistributions of source code must retain the copyright | ||
| 162 | * notice, this list of conditions and the following disclaimer. | ||
| 163 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 164 | * notice, this list of conditions and the following disclaimer in the | ||
| 165 | * documentation and/or other materials provided with the distribution. | ||
| 166 | * 3. All advertising materials mentioning features or use of this software | ||
| 167 | * must display the following acknowledgement: | ||
| 168 | * "This product includes cryptographic software written by | ||
| 169 | * Eric Young (eay@cryptsoft.com)" | ||
| 170 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 171 | * being used are not cryptographic related :-). | ||
| 172 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 173 | * the apps directory (application code) you must include an acknowledgement: | ||
| 174 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 175 | * | ||
| 176 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 177 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 178 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 179 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 180 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 181 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 182 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 183 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 184 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 185 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 186 | * SUCH DAMAGE. | ||
| 187 | * | ||
| 188 | * The licence and distribution terms for any publically available version or | ||
| 189 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 190 | * copied and put under another distribution licence | ||
| 191 | * [including the GNU Public Licence.] | ||
| 192 | */ | ||
| 193 | |||
| 194 | /* THIS FILE IS GENERATED FROM Objects.h by obj_dat.pl via the | ||
| 195 | * following command: | ||
| 196 | * perl obj_dat.pl < objects.h > obj_dat.h | ||
| 197 | */ | ||
| 198 | |||
| 199 | EOF | ||
| 200 | |||
| 201 | printf "#define NUM_NID %d\n",$n; | ||
| 202 | printf "#define NUM_SN %d\n",$#sn+1; | ||
| 203 | printf "#define NUM_LN %d\n",$#ln+1; | ||
| 204 | printf "#define NUM_OBJ %d\n\n",$#ob+1; | ||
| 205 | |||
| 206 | printf "static unsigned char lvalues[%d]={\n",$lvalues+1; | ||
| 207 | print @lvalues; | ||
| 208 | print "};\n\n"; | ||
| 209 | |||
| 210 | printf "static ASN1_OBJECT nid_objs[NUM_NID]={\n"; | ||
| 211 | foreach (@out) | ||
| 212 | { | ||
| 213 | if (length($_) > 75) | ||
| 214 | { | ||
| 215 | $out=""; | ||
| 216 | foreach (split(/,/)) | ||
| 217 | { | ||
| 218 | $t=$out.$_.","; | ||
| 219 | if (length($t) > 70) | ||
| 220 | { | ||
| 221 | print "$out\n"; | ||
| 222 | $t="\t$_,"; | ||
| 223 | } | ||
| 224 | $out=$t; | ||
| 225 | } | ||
| 226 | chop $out; | ||
| 227 | print "$out"; | ||
| 228 | } | ||
| 229 | else | ||
| 230 | { print $_; } | ||
| 231 | } | ||
| 232 | print "};\n\n"; | ||
| 233 | |||
| 234 | printf "static ASN1_OBJECT *sn_objs[NUM_SN]={\n"; | ||
| 235 | print @sn; | ||
| 236 | print "};\n\n"; | ||
| 237 | |||
| 238 | printf "static ASN1_OBJECT *ln_objs[NUM_LN]={\n"; | ||
| 239 | print @ln; | ||
| 240 | print "};\n\n"; | ||
| 241 | |||
| 242 | printf "static ASN1_OBJECT *obj_objs[NUM_OBJ]={\n"; | ||
| 243 | print @ob; | ||
| 244 | print "};\n\n"; | ||
| 245 | |||
| 246 | sub der_it | ||
| 247 | { | ||
| 248 | local($v)=@_; | ||
| 249 | local(@a,$i,$ret,@r); | ||
| 250 | |||
| 251 | @a=split(/\s+/,$v); | ||
| 252 | $ret.=pack("C*",$a[0]*40+$a[1]); | ||
| 253 | shift @a; | ||
| 254 | shift @a; | ||
| 255 | while ($_=shift(@a)) | ||
| 256 | { | ||
| 257 | @r=(); | ||
| 258 | $t=0; | ||
| 259 | while ($_ >= 128) | ||
| 260 | { | ||
| 261 | $x=$_%128; | ||
| 262 | $_/=128; | ||
| 263 | push(@r,((($t++)?0x80:0)|$x)); | ||
| 264 | } | ||
| 265 | push(@r,((($t++)?0x80:0)|$_)); | ||
| 266 | $ret.=pack("C*",reverse(@r)); | ||
| 267 | } | ||
| 268 | return($ret); | ||
| 269 | } | ||
diff --git a/src/lib/libcrypto/objects/obj_err.c b/src/lib/libcrypto/objects/obj_err.c new file mode 100644 index 0000000000..45206c616c --- /dev/null +++ b/src/lib/libcrypto/objects/obj_err.c | |||
| @@ -0,0 +1,96 @@ | |||
| 1 | /* lib/obj/obj_err.c */ | ||
| 2 | /* Copyright (C) 1995-1997 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 | #include <stdio.h> | ||
| 59 | #include "err.h" | ||
| 60 | #include "objects.h" | ||
| 61 | |||
| 62 | /* BEGIN ERROR CODES */ | ||
| 63 | #ifndef NO_ERR | ||
| 64 | static ERR_STRING_DATA OBJ_str_functs[]= | ||
| 65 | { | ||
| 66 | {ERR_PACK(0,OBJ_F_OBJ_CREATE,0), "OBJ_create"}, | ||
| 67 | {ERR_PACK(0,OBJ_F_OBJ_DUP,0), "OBJ_dup"}, | ||
| 68 | {ERR_PACK(0,OBJ_F_OBJ_NID2LN,0), "OBJ_nid2ln"}, | ||
| 69 | {ERR_PACK(0,OBJ_F_OBJ_NID2OBJ,0), "OBJ_nid2obj"}, | ||
| 70 | {ERR_PACK(0,OBJ_F_OBJ_NID2SN,0), "OBJ_nid2sn"}, | ||
| 71 | {0,NULL}, | ||
| 72 | }; | ||
| 73 | |||
| 74 | static ERR_STRING_DATA OBJ_str_reasons[]= | ||
| 75 | { | ||
| 76 | {OBJ_R_MALLOC_FAILURE ,"malloc failure"}, | ||
| 77 | {OBJ_R_UNKNOWN_NID ,"unknown nid"}, | ||
| 78 | {0,NULL}, | ||
| 79 | }; | ||
| 80 | |||
| 81 | #endif | ||
| 82 | |||
| 83 | void ERR_load_OBJ_strings() | ||
| 84 | { | ||
| 85 | static int init=1; | ||
| 86 | |||
| 87 | if (init); | ||
| 88 | {; | ||
| 89 | init=0; | ||
| 90 | #ifndef NO_ERR | ||
| 91 | ERR_load_strings(ERR_LIB_OBJ,OBJ_str_functs); | ||
| 92 | ERR_load_strings(ERR_LIB_OBJ,OBJ_str_reasons); | ||
| 93 | #endif | ||
| 94 | |||
| 95 | } | ||
| 96 | } | ||
diff --git a/src/lib/libcrypto/objects/obj_lib.c b/src/lib/libcrypto/objects/obj_lib.c new file mode 100644 index 0000000000..0a9c756197 --- /dev/null +++ b/src/lib/libcrypto/objects/obj_lib.c | |||
| @@ -0,0 +1,126 @@ | |||
| 1 | /* crypto/objects/obj_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 "lhash.h" | ||
| 62 | #include "objects.h" | ||
| 63 | #include "buffer.h" | ||
| 64 | |||
| 65 | ASN1_OBJECT *OBJ_dup(o) | ||
| 66 | ASN1_OBJECT *o; | ||
| 67 | { | ||
| 68 | ASN1_OBJECT *r; | ||
| 69 | int i; | ||
| 70 | |||
| 71 | if (o == NULL) return(NULL); | ||
| 72 | if (!(o->flags & ASN1_OBJECT_FLAG_DYNAMIC)) | ||
| 73 | return(o); | ||
| 74 | |||
| 75 | r=(ASN1_OBJECT *)ASN1_OBJECT_new(); | ||
| 76 | if (r == NULL) | ||
| 77 | { | ||
| 78 | OBJerr(OBJ_F_OBJ_DUP,ERR_R_ASN1_LIB); | ||
| 79 | return(NULL); | ||
| 80 | } | ||
| 81 | r->data=(unsigned char *)Malloc(o->length); | ||
| 82 | if (r->data == NULL) | ||
| 83 | goto err; | ||
| 84 | memcpy(r->data,o->data,o->length); | ||
| 85 | r->length=o->length; | ||
| 86 | r->nid=o->nid; | ||
| 87 | r->ln=r->sn=NULL; | ||
| 88 | if (o->ln != NULL) | ||
| 89 | { | ||
| 90 | i=strlen(o->ln)+1; | ||
| 91 | r->ln=(char *)Malloc(i); | ||
| 92 | if (r->ln == NULL) goto err; | ||
| 93 | memcpy(r->ln,o->ln,i); | ||
| 94 | } | ||
| 95 | |||
| 96 | if (o->sn != NULL) | ||
| 97 | { | ||
| 98 | i=strlen(o->sn)+1; | ||
| 99 | r->sn=(char *)Malloc(i); | ||
| 100 | if (r->sn == NULL) goto err; | ||
| 101 | memcpy(r->sn,o->sn,i); | ||
| 102 | } | ||
| 103 | r->flags=o->flags|(ASN1_OBJECT_FLAG_DYNAMIC| | ||
| 104 | ASN1_OBJECT_FLAG_DYNAMIC_STRINGS); | ||
| 105 | return(r); | ||
| 106 | err: | ||
| 107 | OBJerr(OBJ_F_OBJ_DUP,ERR_R_MALLOC_FAILURE); | ||
| 108 | if (r != NULL) | ||
| 109 | { | ||
| 110 | if (r->ln != NULL) Free(r->ln); | ||
| 111 | if (r->data != NULL) Free(r->data); | ||
| 112 | Free(r); | ||
| 113 | } | ||
| 114 | return(NULL); | ||
| 115 | } | ||
| 116 | |||
| 117 | int OBJ_cmp(a,b) | ||
| 118 | ASN1_OBJECT *a; | ||
| 119 | ASN1_OBJECT *b; | ||
| 120 | { | ||
| 121 | int ret; | ||
| 122 | |||
| 123 | ret=(a->length-b->length); | ||
| 124 | if (ret) return(ret); | ||
| 125 | return(memcmp(a->data,b->data,a->length)); | ||
| 126 | } | ||
diff --git a/src/lib/libcrypto/objects/objects.h b/src/lib/libcrypto/objects/objects.h new file mode 100644 index 0000000000..e1d555b47c --- /dev/null +++ b/src/lib/libcrypto/objects/objects.h | |||
| @@ -0,0 +1,724 @@ | |||
| 1 | /* crypto/objects/objects.h */ | ||
| 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 | #ifndef HEADER_OBJECTS_H | ||
| 60 | #define HEADER_OBJECTS_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #define SN_undef "UNDEF" | ||
| 67 | #define LN_undef "undefined" | ||
| 68 | #define NID_undef 0 | ||
| 69 | |||
| 70 | #define SN_Algorithm "Algorithm" | ||
| 71 | #define LN_algorithm "algorithm" | ||
| 72 | #define NID_algorithm 38 | ||
| 73 | #define OBJ_algorithm 1L,3L,14L,3L,2L | ||
| 74 | |||
| 75 | #define LN_rsadsi "rsadsi" | ||
| 76 | #define NID_rsadsi 1 | ||
| 77 | #define OBJ_rsadsi 1L,2L,840L,113549L | ||
| 78 | |||
| 79 | #define LN_pkcs "pkcs" | ||
| 80 | #define NID_pkcs 2 | ||
| 81 | #define OBJ_pkcs OBJ_rsadsi,1L | ||
| 82 | |||
| 83 | #define SN_md2 "MD2" | ||
| 84 | #define LN_md2 "md2" | ||
| 85 | #define NID_md2 3 | ||
| 86 | #define OBJ_md2 OBJ_rsadsi,2L,2L | ||
| 87 | |||
| 88 | #define SN_md5 "MD5" | ||
| 89 | #define LN_md5 "md5" | ||
| 90 | #define NID_md5 4 | ||
| 91 | #define OBJ_md5 OBJ_rsadsi,2L,5L | ||
| 92 | |||
| 93 | #define SN_rc4 "RC4" | ||
| 94 | #define LN_rc4 "rc4" | ||
| 95 | #define NID_rc4 5 | ||
| 96 | #define OBJ_rc4 OBJ_rsadsi,3L,4L | ||
| 97 | |||
| 98 | #define LN_rsaEncryption "rsaEncryption" | ||
| 99 | #define NID_rsaEncryption 6 | ||
| 100 | #define OBJ_rsaEncryption OBJ_pkcs,1L,1L | ||
| 101 | |||
| 102 | #define SN_md2WithRSAEncryption "RSA-MD2" | ||
| 103 | #define LN_md2WithRSAEncryption "md2WithRSAEncryption" | ||
| 104 | #define NID_md2WithRSAEncryption 7 | ||
| 105 | #define OBJ_md2WithRSAEncryption OBJ_pkcs,1L,2L | ||
| 106 | |||
| 107 | #define SN_md5WithRSAEncryption "RSA-MD5" | ||
| 108 | #define LN_md5WithRSAEncryption "md5WithRSAEncryption" | ||
| 109 | #define NID_md5WithRSAEncryption 8 | ||
| 110 | #define OBJ_md5WithRSAEncryption OBJ_pkcs,1L,4L | ||
| 111 | |||
| 112 | #define LN_pbeWithMD2AndDES_CBC "pbeWithMD2AndDES-CBC" | ||
| 113 | #define NID_pbeWithMD2AndDES_CBC 9 | ||
| 114 | #define OBJ_pbeWithMD2AndDES_CBC OBJ_pkcs,5L,1L | ||
| 115 | |||
| 116 | #define LN_pbeWithMD5AndDES_CBC "pbeWithMD5AndDES-CBC" | ||
| 117 | #define NID_pbeWithMD5AndDES_CBC 10 | ||
| 118 | #define OBJ_pbeWithMD5AndDES_CBC OBJ_pkcs,5L,3L | ||
| 119 | |||
| 120 | #define LN_X500 "X500" | ||
| 121 | #define NID_X500 11 | ||
| 122 | #define OBJ_X500 2L,5L | ||
| 123 | |||
| 124 | #define LN_X509 "X509" | ||
| 125 | #define NID_X509 12 | ||
| 126 | #define OBJ_X509 OBJ_X500,4L | ||
| 127 | |||
| 128 | #define SN_commonName "CN" | ||
| 129 | #define LN_commonName "commonName" | ||
| 130 | #define NID_commonName 13 | ||
| 131 | #define OBJ_commonName OBJ_X509,3L | ||
| 132 | |||
| 133 | #define SN_countryName "C" | ||
| 134 | #define LN_countryName "countryName" | ||
| 135 | #define NID_countryName 14 | ||
| 136 | #define OBJ_countryName OBJ_X509,6L | ||
| 137 | |||
| 138 | #define SN_localityName "L" | ||
| 139 | #define LN_localityName "localityName" | ||
| 140 | #define NID_localityName 15 | ||
| 141 | #define OBJ_localityName OBJ_X509,7L | ||
| 142 | |||
| 143 | /* Postal Address? PA */ | ||
| 144 | |||
| 145 | /* should be "ST" (rfc1327) but MS uses 'S' */ | ||
| 146 | #define SN_stateOrProvinceName "ST" | ||
| 147 | #define LN_stateOrProvinceName "stateOrProvinceName" | ||
| 148 | #define NID_stateOrProvinceName 16 | ||
| 149 | #define OBJ_stateOrProvinceName OBJ_X509,8L | ||
| 150 | |||
| 151 | #define SN_organizationName "O" | ||
| 152 | #define LN_organizationName "organizationName" | ||
| 153 | #define NID_organizationName 17 | ||
| 154 | #define OBJ_organizationName OBJ_X509,10L | ||
| 155 | |||
| 156 | #define SN_organizationalUnitName "OU" | ||
| 157 | #define LN_organizationalUnitName "organizationalUnitName" | ||
| 158 | #define NID_organizationalUnitName 18 | ||
| 159 | #define OBJ_organizationalUnitName OBJ_X509,11L | ||
| 160 | |||
| 161 | #define SN_rsa "RSA" | ||
| 162 | #define LN_rsa "rsa" | ||
| 163 | #define NID_rsa 19 | ||
| 164 | #define OBJ_rsa OBJ_X500,8L,1L,1L | ||
| 165 | |||
| 166 | #define LN_pkcs7 "pkcs7" | ||
| 167 | #define NID_pkcs7 20 | ||
| 168 | #define OBJ_pkcs7 OBJ_pkcs,7L | ||
| 169 | |||
| 170 | #define LN_pkcs7_data "pkcs7-data" | ||
| 171 | #define NID_pkcs7_data 21 | ||
| 172 | #define OBJ_pkcs7_data OBJ_pkcs7,1L | ||
| 173 | |||
| 174 | #define LN_pkcs7_signed "pkcs7-signedData" | ||
| 175 | #define NID_pkcs7_signed 22 | ||
| 176 | #define OBJ_pkcs7_signed OBJ_pkcs7,2L | ||
| 177 | |||
| 178 | #define LN_pkcs7_enveloped "pkcs7-envelopedData" | ||
| 179 | #define NID_pkcs7_enveloped 23 | ||
| 180 | #define OBJ_pkcs7_enveloped OBJ_pkcs7,3L | ||
| 181 | |||
| 182 | #define LN_pkcs7_signedAndEnveloped "pkcs7-signedAndEnvelopedData" | ||
| 183 | #define NID_pkcs7_signedAndEnveloped 24 | ||
| 184 | #define OBJ_pkcs7_signedAndEnveloped OBJ_pkcs7,4L | ||
| 185 | |||
| 186 | #define LN_pkcs7_digest "pkcs7-digestData" | ||
| 187 | #define NID_pkcs7_digest 25 | ||
| 188 | #define OBJ_pkcs7_digest OBJ_pkcs7,5L | ||
| 189 | |||
| 190 | #define LN_pkcs7_encrypted "pkcs7-encryptedData" | ||
| 191 | #define NID_pkcs7_encrypted 26 | ||
| 192 | #define OBJ_pkcs7_encrypted OBJ_pkcs7,6L | ||
| 193 | |||
| 194 | #define LN_pkcs3 "pkcs3" | ||
| 195 | #define NID_pkcs3 27 | ||
| 196 | #define OBJ_pkcs3 OBJ_pkcs,3L | ||
| 197 | |||
| 198 | #define LN_dhKeyAgreement "dhKeyAgreement" | ||
| 199 | #define NID_dhKeyAgreement 28 | ||
| 200 | #define OBJ_dhKeyAgreement OBJ_pkcs3,1L | ||
| 201 | |||
| 202 | #define SN_des_ecb "DES-ECB" | ||
| 203 | #define LN_des_ecb "des-ecb" | ||
| 204 | #define NID_des_ecb 29 | ||
| 205 | #define OBJ_des_ecb OBJ_algorithm,6L | ||
| 206 | |||
| 207 | #define SN_des_cfb64 "DES-CFB" | ||
| 208 | #define LN_des_cfb64 "des-cfb" | ||
| 209 | #define NID_des_cfb64 30 | ||
| 210 | /* IV + num */ | ||
| 211 | #define OBJ_des_cfb64 OBJ_algorithm,9L | ||
| 212 | |||
| 213 | #define SN_des_cbc "DES-CBC" | ||
| 214 | #define LN_des_cbc "des-cbc" | ||
| 215 | #define NID_des_cbc 31 | ||
| 216 | /* IV */ | ||
| 217 | #define OBJ_des_cbc OBJ_algorithm,7L | ||
| 218 | |||
| 219 | #define SN_des_ede "DES-EDE" | ||
| 220 | #define LN_des_ede "des-ede" | ||
| 221 | #define NID_des_ede 32 | ||
| 222 | /* ?? */ | ||
| 223 | #define OBJ_des_ede OBJ_algorithm,17L | ||
| 224 | |||
| 225 | #define SN_des_ede3 "DES-EDE3" | ||
| 226 | #define LN_des_ede3 "des-ede3" | ||
| 227 | #define NID_des_ede3 33 | ||
| 228 | |||
| 229 | #define SN_idea_cbc "IDEA-CBC" | ||
| 230 | #define LN_idea_cbc "idea-cbc" | ||
| 231 | #define NID_idea_cbc 34 | ||
| 232 | |||
| 233 | #define SN_idea_cfb64 "IDEA-CFB" | ||
| 234 | #define LN_idea_cfb64 "idea-cfb" | ||
| 235 | #define NID_idea_cfb64 35 | ||
| 236 | |||
| 237 | #define SN_idea_ecb "IDEA-ECB" | ||
| 238 | #define LN_idea_ecb "idea-ecb" | ||
| 239 | #define NID_idea_ecb 36 | ||
| 240 | |||
| 241 | #define SN_rc2_cbc "RC2-CBC" | ||
| 242 | #define LN_rc2_cbc "rc2-cbc" | ||
| 243 | #define NID_rc2_cbc 37 | ||
| 244 | #define OBJ_rc2_cbc OBJ_rsadsi,3L,2L | ||
| 245 | |||
| 246 | #define SN_rc2_ecb "RC2-ECB" | ||
| 247 | #define LN_rc2_ecb "rc2-ecb" | ||
| 248 | #define NID_rc2_ecb 38 | ||
| 249 | |||
| 250 | #define SN_rc2_cfb64 "RC2-CFB" | ||
| 251 | #define LN_rc2_cfb64 "rc2-cfb" | ||
| 252 | #define NID_rc2_cfb64 39 | ||
| 253 | |||
| 254 | #define SN_rc2_ofb64 "RC2-OFB" | ||
| 255 | #define LN_rc2_ofb64 "rc2-ofb" | ||
| 256 | #define NID_rc2_ofb64 40 | ||
| 257 | |||
| 258 | #define SN_sha "SHA" | ||
| 259 | #define LN_sha "sha" | ||
| 260 | #define NID_sha 41 | ||
| 261 | #define OBJ_sha OBJ_algorithm,18L | ||
| 262 | |||
| 263 | #define SN_shaWithRSAEncryption "RSA-SHA" | ||
| 264 | #define LN_shaWithRSAEncryption "shaWithRSAEncryption" | ||
| 265 | #define NID_shaWithRSAEncryption 42 | ||
| 266 | #define OBJ_shaWithRSAEncryption OBJ_algorithm,15L | ||
| 267 | |||
| 268 | #define SN_des_ede_cbc "DES-EDE-CBC" | ||
| 269 | #define LN_des_ede_cbc "des-ede-cbc" | ||
| 270 | #define NID_des_ede_cbc 43 | ||
| 271 | |||
| 272 | #define SN_des_ede3_cbc "DES-EDE3-CBC" | ||
| 273 | #define LN_des_ede3_cbc "des-ede3-cbc" | ||
| 274 | #define NID_des_ede3_cbc 44 | ||
| 275 | #define OBJ_des_ede3_cbc OBJ_rsadsi,3L,7L | ||
| 276 | |||
| 277 | #define SN_des_ofb64 "DES-OFB" | ||
| 278 | #define LN_des_ofb64 "des-ofb" | ||
| 279 | #define NID_des_ofb64 45 | ||
| 280 | #define OBJ_des_ofb64 OBJ_algorithm,8L | ||
| 281 | |||
| 282 | #define SN_idea_ofb64 "IDEA-OFB" | ||
| 283 | #define LN_idea_ofb64 "idea-ofb" | ||
| 284 | #define NID_idea_ofb64 46 | ||
| 285 | |||
| 286 | #define LN_pkcs9 "pkcs9" | ||
| 287 | #define NID_pkcs9 47 | ||
| 288 | #define OBJ_pkcs9 OBJ_pkcs,9L | ||
| 289 | |||
| 290 | #define SN_pkcs9_emailAddress "Email" | ||
| 291 | #define LN_pkcs9_emailAddress "emailAddress" | ||
| 292 | #define NID_pkcs9_emailAddress 48 | ||
| 293 | #define OBJ_pkcs9_emailAddress OBJ_pkcs9,1L | ||
| 294 | |||
| 295 | #define LN_pkcs9_unstructuredName "unstructuredName" | ||
| 296 | #define NID_pkcs9_unstructuredName 49 | ||
| 297 | #define OBJ_pkcs9_unstructuredName OBJ_pkcs9,2L | ||
| 298 | |||
| 299 | #define LN_pkcs9_contentType "contentType" | ||
| 300 | #define NID_pkcs9_contentType 50 | ||
| 301 | #define OBJ_pkcs9_contentType OBJ_pkcs9,3L | ||
| 302 | |||
| 303 | #define LN_pkcs9_messageDigest "messageDigest" | ||
| 304 | #define NID_pkcs9_messageDigest 51 | ||
| 305 | #define OBJ_pkcs9_messageDigest OBJ_pkcs9,4L | ||
| 306 | |||
| 307 | #define LN_pkcs9_signingTime "signingTime" | ||
| 308 | #define NID_pkcs9_signingTime 52 | ||
| 309 | #define OBJ_pkcs9_signingTime OBJ_pkcs9,5L | ||
| 310 | |||
| 311 | #define LN_pkcs9_countersignature "countersignature" | ||
| 312 | #define NID_pkcs9_countersignature 53 | ||
| 313 | #define OBJ_pkcs9_countersignature OBJ_pkcs9,6L | ||
| 314 | |||
| 315 | #define LN_pkcs9_challengePassword "challengePassword" | ||
| 316 | #define NID_pkcs9_challengePassword 54 | ||
| 317 | #define OBJ_pkcs9_challengePassword OBJ_pkcs9,7L | ||
| 318 | |||
| 319 | #define LN_pkcs9_unstructuredAddress "unstructuredAddress" | ||
| 320 | #define NID_pkcs9_unstructuredAddress 55 | ||
| 321 | #define OBJ_pkcs9_unstructuredAddress OBJ_pkcs9,8L | ||
| 322 | |||
| 323 | #define LN_pkcs9_extCertAttributes "extendedCertificateAttributes" | ||
| 324 | #define NID_pkcs9_extCertAttributes 56 | ||
| 325 | #define OBJ_pkcs9_extCertAttributes OBJ_pkcs9,9L | ||
| 326 | |||
| 327 | #define SN_netscape "Netscape" | ||
| 328 | #define LN_netscape "Netscape Communications Corp." | ||
| 329 | #define NID_netscape 57 | ||
| 330 | #define OBJ_netscape 2L,16L,840L,1L,113730L | ||
| 331 | |||
| 332 | #define SN_netscape_cert_extension "nsCertExt" | ||
| 333 | #define LN_netscape_cert_extension "Netscape Certificate Extension" | ||
| 334 | #define NID_netscape_cert_extension 58 | ||
| 335 | #define OBJ_netscape_cert_extension OBJ_netscape,1L | ||
| 336 | |||
| 337 | #define SN_netscape_data_type "nsDataType" | ||
| 338 | #define LN_netscape_data_type "Netscape Data Type" | ||
| 339 | #define NID_netscape_data_type 59 | ||
| 340 | #define OBJ_netscape_data_type OBJ_netscape,2L | ||
| 341 | |||
| 342 | #define SN_des_ede_cfb64 "DES-EDE-CFB" | ||
| 343 | #define LN_des_ede_cfb64 "des-ede-cfb" | ||
| 344 | #define NID_des_ede_cfb64 60 | ||
| 345 | |||
| 346 | #define SN_des_ede3_cfb64 "DES-EDE3-CFB" | ||
| 347 | #define LN_des_ede3_cfb64 "des-ede3-cfb" | ||
| 348 | #define NID_des_ede3_cfb64 61 | ||
| 349 | |||
| 350 | #define SN_des_ede_ofb64 "DES-EDE-OFB" | ||
| 351 | #define LN_des_ede_ofb64 "des-ede-ofb" | ||
| 352 | #define NID_des_ede_ofb64 62 | ||
| 353 | |||
| 354 | #define SN_des_ede3_ofb64 "DES-EDE3-OFB" | ||
| 355 | #define LN_des_ede3_ofb64 "des-ede3-ofb" | ||
| 356 | #define NID_des_ede3_ofb64 63 | ||
| 357 | |||
| 358 | /* I'm not sure about the object ID */ | ||
| 359 | #define SN_sha1 "SHA1" | ||
| 360 | #define LN_sha1 "sha1" | ||
| 361 | #define NID_sha1 64 | ||
| 362 | #define OBJ_sha1 OBJ_algorithm,26L | ||
| 363 | /* 28 Jun 1996 - eay */ | ||
| 364 | /* #define OBJ_sha1 1L,3L,14L,2L,26L,05L <- wrong */ | ||
| 365 | |||
| 366 | #define SN_sha1WithRSAEncryption "RSA-SHA1" | ||
| 367 | #define LN_sha1WithRSAEncryption "sha1WithRSAEncryption" | ||
| 368 | #define NID_sha1WithRSAEncryption 65 | ||
| 369 | #define OBJ_sha1WithRSAEncryption OBJ_pkcs,1L,5L | ||
| 370 | |||
| 371 | #define SN_dsaWithSHA "DSA-SHA" | ||
| 372 | #define LN_dsaWithSHA "dsaWithSHA" | ||
| 373 | #define NID_dsaWithSHA 66 | ||
| 374 | #define OBJ_dsaWithSHA OBJ_algorithm,13L | ||
| 375 | |||
| 376 | #define SN_dsa_2 "DSA-old" | ||
| 377 | #define LN_dsa_2 "dsaEncryption-old" | ||
| 378 | #define NID_dsa_2 67 | ||
| 379 | #define OBJ_dsa_2 OBJ_algorithm,12L | ||
| 380 | |||
| 381 | /* proposed by microsoft to RSA */ | ||
| 382 | #define LN_pbeWithSHA1AndRC2_CBC "pbeWithSHA1AndRC2-CBC" | ||
| 383 | #define NID_pbeWithSHA1AndRC2_CBC 68 | ||
| 384 | #define OBJ_pbeWithSHA1AndRC2_CBC OBJ_pkcs,5L,11L | ||
| 385 | |||
| 386 | /* proposed by microsoft to RSA */ | ||
| 387 | #define LN_pbeWithSHA1AndRC4 "pbeWithSHA1AndRC4" | ||
| 388 | #define NID_pbeWithSHA1AndRC4 69 | ||
| 389 | #define OBJ_pbeWithSHA1AndRC4 OBJ_pkcs,5L,12L | ||
| 390 | |||
| 391 | #define SN_dsaWithSHA1_2 "DSA-SHA1-old" | ||
| 392 | #define LN_dsaWithSHA1_2 "dsaWithSHA1" | ||
| 393 | #define NID_dsaWithSHA1_2 70 | ||
| 394 | /* Got this one from 'sdn706r20.pdf' which is actually an NSA document :-) */ | ||
| 395 | #define OBJ_dsaWithSHA1_2 OBJ_algorithm,27L | ||
| 396 | |||
| 397 | #define SN_netscape_cert_type "nsCertType" | ||
| 398 | #define LN_netscape_cert_type "Netscape Cert Type" | ||
| 399 | #define NID_netscape_cert_type 71 | ||
| 400 | #define OBJ_netscape_cert_type OBJ_netscape_cert_extension,1L | ||
| 401 | |||
| 402 | #define SN_netscape_base_url "nsBaseUrl" | ||
| 403 | #define LN_netscape_base_url "Netscape Base Url" | ||
| 404 | #define NID_netscape_base_url 72 | ||
| 405 | #define OBJ_netscape_base_url OBJ_netscape_cert_extension,2L | ||
| 406 | |||
| 407 | #define SN_netscape_revocation_url "nsRevocationUrl" | ||
| 408 | #define LN_netscape_revocation_url "Netscape Revocation Url" | ||
| 409 | #define NID_netscape_revocation_url 73 | ||
| 410 | #define OBJ_netscape_revocation_url OBJ_netscape_cert_extension,3L | ||
| 411 | |||
| 412 | #define SN_netscape_ca_revocation_url "nsCaRevocationUrl" | ||
| 413 | #define LN_netscape_ca_revocation_url "Netscape CA Revocation Url" | ||
| 414 | #define NID_netscape_ca_revocation_url 74 | ||
| 415 | #define OBJ_netscape_ca_revocation_url OBJ_netscape_cert_extension,4L | ||
| 416 | |||
| 417 | #define SN_netscape_renewal_url "nsRenewalUrl" | ||
| 418 | #define LN_netscape_renewal_url "Netscape Renewal Url" | ||
| 419 | #define NID_netscape_renewal_url 75 | ||
| 420 | #define OBJ_netscape_renewal_url OBJ_netscape_cert_extension,7L | ||
| 421 | |||
| 422 | #define SN_netscape_ca_policy_url "nsCaPolicyUrl" | ||
| 423 | #define LN_netscape_ca_policy_url "Netscape CA Policy Url" | ||
| 424 | #define NID_netscape_ca_policy_url 76 | ||
| 425 | #define OBJ_netscape_ca_policy_url OBJ_netscape_cert_extension,8L | ||
| 426 | |||
| 427 | #define SN_netscape_ssl_server_name "nsSslServerName" | ||
| 428 | #define LN_netscape_ssl_server_name "Netscape SSL Server Name" | ||
| 429 | #define NID_netscape_ssl_server_name 77 | ||
| 430 | #define OBJ_netscape_ssl_server_name OBJ_netscape_cert_extension,12L | ||
| 431 | |||
| 432 | #define SN_netscape_comment "nsComment" | ||
| 433 | #define LN_netscape_comment "Netscape Comment" | ||
| 434 | #define NID_netscape_comment 78 | ||
| 435 | #define OBJ_netscape_comment OBJ_netscape_cert_extension,13L | ||
| 436 | |||
| 437 | #define SN_netscape_cert_sequence "nsCertSequence" | ||
| 438 | #define LN_netscape_cert_sequence "Netscape Certificate Sequence" | ||
| 439 | #define NID_netscape_cert_sequence 79 | ||
| 440 | #define OBJ_netscape_cert_sequence OBJ_netscape_data_type,5L | ||
| 441 | |||
| 442 | #define SN_desx_cbc "DESX-CBC" | ||
| 443 | #define LN_desx_cbc "desx-cbc" | ||
| 444 | #define NID_desx_cbc 80 | ||
| 445 | |||
| 446 | #define SN_ld_ce "ld-ce" | ||
| 447 | #define NID_ld_ce 81 | ||
| 448 | #define OBJ_ld_ce 2L,5L,29L | ||
| 449 | |||
| 450 | #define SN_subject_key_identifier "subjectKeyIdentifier" | ||
| 451 | #define LN_subject_key_identifier "X509v3 Subject Key Identifier" | ||
| 452 | #define NID_subject_key_identifier 82 | ||
| 453 | #define OBJ_subject_key_identifier OBJ_ld_ce,14L | ||
| 454 | |||
| 455 | #define SN_key_usage "keyUsage" | ||
| 456 | #define LN_key_usage "X509v3 Key Usage" | ||
| 457 | #define NID_key_usage 83 | ||
| 458 | #define OBJ_key_usage OBJ_ld_ce,15L | ||
| 459 | |||
| 460 | #define SN_private_key_usage_period "privateKeyUsagePeriod" | ||
| 461 | #define LN_private_key_usage_period "X509v3 Private Key Usage Period" | ||
| 462 | #define NID_private_key_usage_period 84 | ||
| 463 | #define OBJ_private_key_usage_period OBJ_ld_ce,16L | ||
| 464 | |||
| 465 | #define SN_subject_alt_name "subjectAltName" | ||
| 466 | #define LN_subject_alt_name "X509v3 Subject Alternative Name" | ||
| 467 | #define NID_subject_alt_name 85 | ||
| 468 | #define OBJ_subject_alt_name OBJ_ld_ce,17L | ||
| 469 | |||
| 470 | #define SN_issuer_alt_name "issuerAltName" | ||
| 471 | #define LN_issuer_alt_name "X509v3 Issuer Alternative Name" | ||
| 472 | #define NID_issuer_alt_name 86 | ||
| 473 | #define OBJ_issuer_alt_name OBJ_ld_ce,18L | ||
| 474 | |||
| 475 | #define SN_basic_constraints "basicConstraints" | ||
| 476 | #define LN_basic_constraints "X509v3 Basic Constraints" | ||
| 477 | #define NID_basic_constraints 87 | ||
| 478 | #define OBJ_basic_constraints OBJ_ld_ce,19L | ||
| 479 | |||
| 480 | #define SN_crl_number "crlNumber" | ||
| 481 | #define LN_crl_number "X509v3 CRL Number" | ||
| 482 | #define NID_crl_number 88 | ||
| 483 | #define OBJ_crl_number OBJ_ld_ce,20L | ||
| 484 | |||
| 485 | #define SN_certificate_policies "certificatePolicies" | ||
| 486 | #define LN_certificate_policies "X509v3 Certificate Policies" | ||
| 487 | #define NID_certificate_policies 89 | ||
| 488 | #define OBJ_certificate_policies OBJ_ld_ce,32L | ||
| 489 | |||
| 490 | #define SN_authority_key_identifier "authorityKeyIdentifier" | ||
| 491 | #define LN_authority_key_identifier "X509v3 Authority Key Identifier" | ||
| 492 | #define NID_authority_key_identifier 90 | ||
| 493 | #define OBJ_authority_key_identifier OBJ_ld_ce,35L | ||
| 494 | |||
| 495 | #define SN_bf_cbc "BF-CBC" | ||
| 496 | #define LN_bf_cbc "bf-cbc" | ||
| 497 | #define NID_bf_cbc 91 | ||
| 498 | |||
| 499 | #define SN_bf_ecb "BF-ECB" | ||
| 500 | #define LN_bf_ecb "bf-ecb" | ||
| 501 | #define NID_bf_ecb 92 | ||
| 502 | |||
| 503 | #define SN_bf_cfb64 "BF-CFB" | ||
| 504 | #define LN_bf_cfb64 "bf-cfb" | ||
| 505 | #define NID_bf_cfb64 93 | ||
| 506 | |||
| 507 | #define SN_bf_ofb64 "BF-OFB" | ||
| 508 | #define LN_bf_ofb64 "bf-ofb" | ||
| 509 | #define NID_bf_ofb64 94 | ||
| 510 | |||
| 511 | #define SN_mdc2 "MDC2" | ||
| 512 | #define LN_mdc2 "mdc2" | ||
| 513 | #define NID_mdc2 95 | ||
| 514 | #define OBJ_mdc2 2L,5L,8L,3L,101L | ||
| 515 | /* An alternative? 1L,3L,14L,3L,2L,19L */ | ||
| 516 | |||
| 517 | #define SN_mdc2WithRSA "RSA-MDC2" | ||
| 518 | #define LN_mdc2WithRSA "mdc2withRSA" | ||
| 519 | #define NID_mdc2WithRSA 96 | ||
| 520 | #define OBJ_mdc2WithRSA 2L,5L,8L,3L,100L | ||
| 521 | |||
| 522 | #define SN_rc4_40 "RC4-40" | ||
| 523 | #define LN_rc4_40 "rc4-40" | ||
| 524 | #define NID_rc4_40 97 | ||
| 525 | |||
| 526 | #define SN_rc2_40_cbc "RC2-40-CBC" | ||
| 527 | #define LN_rc2_40_cbc "rc2-40-cbc" | ||
| 528 | #define NID_rc2_40_cbc 98 | ||
| 529 | |||
| 530 | #define SN_givenName "G" | ||
| 531 | #define LN_givenName "givenName" | ||
| 532 | #define NID_givenName 99 | ||
| 533 | #define OBJ_givenName OBJ_X509,42L | ||
| 534 | |||
| 535 | #define SN_surname "S" | ||
| 536 | #define LN_surname "surname" | ||
| 537 | #define NID_surname 100 | ||
| 538 | #define OBJ_surname OBJ_X509,4L | ||
| 539 | |||
| 540 | #define SN_initials "I" | ||
| 541 | #define LN_initials "initials" | ||
| 542 | #define NID_initials 101 | ||
| 543 | #define OBJ_initials OBJ_X509,43L | ||
| 544 | |||
| 545 | #define SN_uniqueIdentifier "UID" | ||
| 546 | #define LN_uniqueIdentifier "uniqueIdentifier" | ||
| 547 | #define NID_uniqueIdentifier 102 | ||
| 548 | #define OBJ_uniqueIdentifier OBJ_X509,45L | ||
| 549 | |||
| 550 | #define SN_crl_distribution_points "crlDistributionPoints" | ||
| 551 | #define LN_crl_distribution_points "X509v3 CRL Distribution Points" | ||
| 552 | #define NID_crl_distribution_points 103 | ||
| 553 | #define OBJ_crl_distribution_points OBJ_ld_ce,31L | ||
| 554 | |||
| 555 | #define SN_md5WithRSA "RSA-NP-MD5" | ||
| 556 | #define LN_md5WithRSA "md5WithRSA" | ||
| 557 | #define NID_md5WithRSA 104 | ||
| 558 | #define OBJ_md5WithRSA OBJ_algorithm,3L | ||
| 559 | |||
| 560 | #define SN_serialNumber "SN" | ||
| 561 | #define LN_serialNumber "serialNumber" | ||
| 562 | #define NID_serialNumber 105 | ||
| 563 | #define OBJ_serialNumber OBJ_X509,5L | ||
| 564 | |||
| 565 | #define SN_title "T" | ||
| 566 | #define LN_title "title" | ||
| 567 | #define NID_title 106 | ||
| 568 | #define OBJ_title OBJ_X509,12L | ||
| 569 | |||
| 570 | #define SN_description "D" | ||
| 571 | #define LN_description "description" | ||
| 572 | #define NID_description 107 | ||
| 573 | #define OBJ_description OBJ_X509,13L | ||
| 574 | |||
| 575 | /* CAST5 is CAST-128, I'm just sticking with the documentation */ | ||
| 576 | #define SN_cast5_cbc "CAST5-CBC" | ||
| 577 | #define LN_cast5_cbc "cast5-cbc" | ||
| 578 | #define NID_cast5_cbc 108 | ||
| 579 | #define OBJ_cast5_cbc 1L,2L,840L,113533L,7L,66L,10L | ||
| 580 | |||
| 581 | #define SN_cast5_ecb "CAST5-ECB" | ||
| 582 | #define LN_cast5_ecb "cast5-ecb" | ||
| 583 | #define NID_cast5_ecb 109 | ||
| 584 | |||
| 585 | #define SN_cast5_cfb64 "CAST5-CFB" | ||
| 586 | #define LN_cast5_cfb64 "cast5-cfb" | ||
| 587 | #define NID_cast5_cfb64 110 | ||
| 588 | |||
| 589 | #define SN_cast5_ofb64 "CAST5-OFB" | ||
| 590 | #define LN_cast5_ofb64 "cast5-ofb" | ||
| 591 | #define NID_cast5_ofb64 111 | ||
| 592 | |||
| 593 | #define LN_pbeWithMD5AndCast5_CBC "pbeWithMD5AndCast5CBC" | ||
| 594 | #define NID_pbeWithMD5AndCast5_CBC 112 | ||
| 595 | #define OBJ_pbeWithMD5AndCast5_CBC 1L,2L,840L,113533L,7L,66L,12L | ||
| 596 | |||
| 597 | /* This is one sun will soon be using :-( | ||
| 598 | * id-dsa-with-sha1 ID ::= { | ||
| 599 | * iso(1) member-body(2) us(840) x9-57 (10040) x9cm(4) 3 } | ||
| 600 | */ | ||
| 601 | #define SN_dsaWithSHA1 "DSA-SHA1" | ||
| 602 | #define LN_dsaWithSHA1 "dsaWithSHA1" | ||
| 603 | #define NID_dsaWithSHA1 113 | ||
| 604 | #define OBJ_dsaWithSHA1 1L,2L,840L,10040L,4L,3L | ||
| 605 | |||
| 606 | #define NID_md5_sha1 114 | ||
| 607 | #define SN_md5_sha1 "MD5-SHA1" | ||
| 608 | #define LN_md5_sha1 "md5-sha1" | ||
| 609 | |||
| 610 | #define SN_sha1WithRSA "RSA-SHA1-2" | ||
| 611 | #define LN_sha1WithRSA "sha1WithRSA" | ||
| 612 | #define NID_sha1WithRSA 115 | ||
| 613 | #define OBJ_sha1WithRSA OBJ_algorithm,29L | ||
| 614 | |||
| 615 | #define SN_dsa "DSA" | ||
| 616 | #define LN_dsa "dsaEncryption" | ||
| 617 | #define NID_dsa 116 | ||
| 618 | #define OBJ_dsa 1L,2L,840L,10040L,4L,1L | ||
| 619 | |||
| 620 | #define SN_ripemd160 "RIPEMD160" | ||
| 621 | #define LN_ripemd160 "ripemd160" | ||
| 622 | #define NID_ripemd160 117 | ||
| 623 | #define OBJ_ripemd160 1L,3L,36L,3L,2L,1L | ||
| 624 | |||
| 625 | /* The name should actually be rsaSignatureWithripemd160, but I'm going | ||
| 626 | * to contiune using the convention I'm using with the other ciphers */ | ||
| 627 | #define SN_ripemd160WithRSA "RSA-RIPEMD160" | ||
| 628 | #define LN_ripemd160WithRSA "ripemd160WithRSA" | ||
| 629 | #define NID_ripemd160WithRSA 119 | ||
| 630 | #define OBJ_ripemd160WithRSA 1L,3L,36L,3L,3L,1L,2L | ||
| 631 | |||
| 632 | /* Taken from rfc2040 | ||
| 633 | * RC5_CBC_Parameters ::= SEQUENCE { | ||
| 634 | * version INTEGER (v1_0(16)), | ||
| 635 | * rounds INTEGER (8..127), | ||
| 636 | * blockSizeInBits INTEGER (64, 128), | ||
| 637 | * iv OCTET STRING OPTIONAL | ||
| 638 | * } | ||
| 639 | */ | ||
| 640 | #define SN_rc5_cbc "RC5-CBC" | ||
| 641 | #define LN_rc5_cbc "rc5-cbc" | ||
| 642 | #define NID_rc5_cbc 120 | ||
| 643 | #define OBJ_rc5_cbc OBJ_rsadsi,3L,8L | ||
| 644 | |||
| 645 | #define SN_rc5_ecb "RC5-ECB" | ||
| 646 | #define LN_rc5_ecb "rc5-ecb" | ||
| 647 | #define NID_rc5_ecb 121 | ||
| 648 | |||
| 649 | #define SN_rc5_cfb64 "RC5-CFB" | ||
| 650 | #define LN_rc5_cfb64 "rc5-cfb" | ||
| 651 | #define NID_rc5_cfb64 122 | ||
| 652 | |||
| 653 | #define SN_rc5_ofb64 "RC5-OFB" | ||
| 654 | #define LN_rc5_ofb64 "rc5-ofb" | ||
| 655 | #define NID_rc5_ofb64 123 | ||
| 656 | |||
| 657 | #include "bio.h" | ||
| 658 | #include "asn1.h" | ||
| 659 | |||
| 660 | #define OBJ_create_and_add_object(a,b,c) OBJ_create(a,b,c) | ||
| 661 | |||
| 662 | #ifndef NOPROTO | ||
| 663 | |||
| 664 | ASN1_OBJECT * OBJ_dup(ASN1_OBJECT *o); | ||
| 665 | ASN1_OBJECT * OBJ_nid2obj(int n); | ||
| 666 | char * OBJ_nid2ln(int n); | ||
| 667 | char * OBJ_nid2sn(int n); | ||
| 668 | int OBJ_obj2nid(ASN1_OBJECT *o); | ||
| 669 | int OBJ_txt2nid(char *s); | ||
| 670 | int OBJ_ln2nid(char *s); | ||
| 671 | int OBJ_sn2nid(char *s); | ||
| 672 | int OBJ_cmp(ASN1_OBJECT *a,ASN1_OBJECT *b); | ||
| 673 | char * OBJ_bsearch(char *key,char *base,int num,int size,int (*cmp)()); | ||
| 674 | |||
| 675 | void ERR_load_OBJ_strings(void ); | ||
| 676 | |||
| 677 | int OBJ_new_nid(int num); | ||
| 678 | int OBJ_add_object(ASN1_OBJECT *obj); | ||
| 679 | int OBJ_create(char *oid,char *sn,char *ln); | ||
| 680 | void OBJ_cleanup(void ); | ||
| 681 | int OBJ_create_objects(BIO *in); | ||
| 682 | |||
| 683 | #else | ||
| 684 | |||
| 685 | ASN1_OBJECT * OBJ_dup(); | ||
| 686 | ASN1_OBJECT * OBJ_nid2obj(); | ||
| 687 | char * OBJ_nid2ln(); | ||
| 688 | char * OBJ_nid2sn(); | ||
| 689 | int OBJ_obj2nid(); | ||
| 690 | int OBJ_txt2nid(); | ||
| 691 | int OBJ_ln2nid(); | ||
| 692 | int OBJ_sn2nid(); | ||
| 693 | int OBJ_cmp(); | ||
| 694 | char * OBJ_bsearch(); | ||
| 695 | |||
| 696 | void ERR_load_OBJ_strings(); | ||
| 697 | |||
| 698 | int OBJ_new_nid(); | ||
| 699 | int OBJ_add_object(); | ||
| 700 | int OBJ_create(); | ||
| 701 | void OBJ_cleanup(); | ||
| 702 | int OBJ_create_objects(); | ||
| 703 | |||
| 704 | #endif | ||
| 705 | |||
| 706 | /* BEGIN ERROR CODES */ | ||
| 707 | /* Error codes for the OBJ functions. */ | ||
| 708 | |||
| 709 | /* Function codes. */ | ||
| 710 | #define OBJ_F_OBJ_CREATE 100 | ||
| 711 | #define OBJ_F_OBJ_DUP 101 | ||
| 712 | #define OBJ_F_OBJ_NID2LN 102 | ||
| 713 | #define OBJ_F_OBJ_NID2OBJ 103 | ||
| 714 | #define OBJ_F_OBJ_NID2SN 104 | ||
| 715 | |||
| 716 | /* Reason codes. */ | ||
| 717 | #define OBJ_R_MALLOC_FAILURE 100 | ||
| 718 | #define OBJ_R_UNKNOWN_NID 101 | ||
| 719 | |||
| 720 | #ifdef __cplusplus | ||
| 721 | } | ||
| 722 | #endif | ||
| 723 | #endif | ||
| 724 | |||
diff --git a/src/lib/libcrypto/objects/objects.txt b/src/lib/libcrypto/objects/objects.txt new file mode 100644 index 0000000000..cb276e90e9 --- /dev/null +++ b/src/lib/libcrypto/objects/objects.txt | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | 1 2 : ISO member bodies | ||
| 2 | 1 2 840 : US (ANSI) | ||
| 3 | 1 2 840 113549 : rsadsi : RSA Data Security, Inc. | ||
| 4 | 1 2 840 113549 1 : pkcs : RSA Data Security, Inc. PKCS | ||
| 5 | 1 2 840 113549 1 1 1 : rsaEncryption | ||
| 6 | 1 2 840 113549 1 1 2 : md2withRSAEncryption | ||
| 7 | 1 2 840 113549 1 1 4 : md5withRSAEncryption | ||
| 8 | 1 2 840 113549 1 7 : pkcs-7 | ||
| 9 | 1 2 840 113549 1 7 1 : pkcs-7-data | ||
| 10 | 1 2 840 113549 1 7 2 : pkcs-7-signedData | ||
| 11 | 1 2 840 113549 1 7 3 : pkcs-7-envelopedData | ||
| 12 | 1 2 840 113549 1 7 4 : pkcs-7-signedAndEnvelopedData | ||
| 13 | 1 2 840 113549 1 7 5 : pkcs-7-digestData | ||
| 14 | 1 2 840 113549 1 7 6 : pkcs-7-encryptedData | ||
| 15 | 1 2 840 113549 2 2 : md2 | ||
| 16 | 1 2 840 113549 2 4 : md4 | ||
| 17 | 1 2 840 113549 2 5 : md5 | ||
| 18 | 1 2 840 113549 3 4 : rc4 | ||
| 19 | 1 2 840 113549 5 1 : pbeWithMD2AndDES_CBC | ||
| 20 | 1 2 840 113549 5 3 : pbeWithMD5AndDES_CBC | ||
| 21 | 2 5 : X500 : directory services (X.500) | ||
| 22 | 2 5 4 : X509 | ||
| 23 | 2 5 4 3 : commonName | ||
| 24 | 2 5 4 6 : countryName | ||
| 25 | 2 5 4 7 : localityName | ||
| 26 | 2 5 4 8 : stateOrProvinceName | ||
| 27 | 2 5 4 10 : organizationName | ||
| 28 | 2 5 4 11 : organizationalUnitName | ||
| 29 | 2 5 8 : directory services - algorithms | ||
| 30 | 2 5 8 1 1 : rsa | ||
| 31 | |||
| 32 | algorithm 18 : sha | ||
| 33 | encryptionAlgorithm 1 : rsa | ||
| 34 | algorithm 11 : rsaSignature | ||
| 35 | |||
| 36 | algorithm 6 : desECB | ||
| 37 | algorithm 7 : desCBC | ||
| 38 | algorithm 8 : desOFB | ||
| 39 | algorithm 9 : desCFB | ||
| 40 | algorithm 17 : desEDE2 | ||
diff --git a/src/lib/libcrypto/pem/message b/src/lib/libcrypto/pem/message new file mode 100644 index 0000000000..e8bf9d7592 --- /dev/null +++ b/src/lib/libcrypto/pem/message | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | -----BEGIN PRIVACY-ENHANCED MESSAGE----- | ||
| 2 | Proc-Type: 4,ENCRYPTED | ||
| 3 | Proc-Type: 4,MIC-ONLY | ||
| 4 | Proc-Type: 4,MIC-CLEAR | ||
| 5 | Content-Domain: RFC822 | ||
| 6 | DEK-Info: DES-CBC,0123456789abcdef | ||
| 7 | Originator-Certificate | ||
| 8 | xxxx | ||
| 9 | Issuer-Certificate | ||
| 10 | xxxx | ||
| 11 | MIC-Info: RSA-MD5,RSA, | ||
| 12 | xxxx | ||
| 13 | |||
| 14 | |||
| 15 | -----END PRIVACY-ENHANCED MESSAGE----- | ||
| 16 | |||
diff --git a/src/lib/libcrypto/pem/pem.h b/src/lib/libcrypto/pem/pem.h new file mode 100644 index 0000000000..55fbaeffe2 --- /dev/null +++ b/src/lib/libcrypto/pem/pem.h | |||
| @@ -0,0 +1,562 @@ | |||
| 1 | /* crypto/pem/pem.org */ | ||
| 2 | /* Copyright (C) 1995-1997 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 | /* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING | ||
| 60 | * | ||
| 61 | * Always modify pem.org since pem.h is automatically generated from | ||
| 62 | * it during SSLeay configuration. | ||
| 63 | * | ||
| 64 | * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING | ||
| 65 | */ | ||
| 66 | |||
| 67 | #ifndef HEADER_PEM_H | ||
| 68 | #define HEADER_PEM_H | ||
| 69 | |||
| 70 | #ifdef __cplusplus | ||
| 71 | extern "C" { | ||
| 72 | #endif | ||
| 73 | |||
| 74 | #include "evp.h" | ||
| 75 | #include "x509.h" | ||
| 76 | |||
| 77 | #define PEM_OBJ_UNDEF 0 | ||
| 78 | #define PEM_OBJ_X509 1 | ||
| 79 | #define PEM_OBJ_X509_REQ 2 | ||
| 80 | #define PEM_OBJ_CRL 3 | ||
| 81 | #define PEM_OBJ_SSL_SESSION 4 | ||
| 82 | #define PEM_OBJ_PRIV_KEY 10 | ||
| 83 | #define PEM_OBJ_PRIV_RSA 11 | ||
| 84 | #define PEM_OBJ_PRIV_DSA 12 | ||
| 85 | #define PEM_OBJ_PRIV_DH 13 | ||
| 86 | #define PEM_OBJ_PUB_RSA 14 | ||
| 87 | #define PEM_OBJ_PUB_DSA 15 | ||
| 88 | #define PEM_OBJ_PUB_DH 16 | ||
| 89 | #define PEM_OBJ_DHPARAMS 17 | ||
| 90 | #define PEM_OBJ_DSAPARAMS 18 | ||
| 91 | #define PEM_OBJ_PRIV_RSA_PUBLIC 19 | ||
| 92 | |||
| 93 | #define PEM_ERROR 30 | ||
| 94 | #define PEM_DEK_DES_CBC 40 | ||
| 95 | #define PEM_DEK_IDEA_CBC 45 | ||
| 96 | #define PEM_DEK_DES_EDE 50 | ||
| 97 | #define PEM_DEK_DES_ECB 60 | ||
| 98 | #define PEM_DEK_RSA 70 | ||
| 99 | #define PEM_DEK_RSA_MD2 80 | ||
| 100 | #define PEM_DEK_RSA_MD5 90 | ||
| 101 | |||
| 102 | #define PEM_MD_MD2 NID_md2 | ||
| 103 | #define PEM_MD_MD5 NID_md5 | ||
| 104 | #define PEM_MD_SHA NID_sha | ||
| 105 | #define PEM_MD_MD2_RSA NID_md2WithRSAEncryption | ||
| 106 | #define PEM_MD_MD5_RSA NID_md5WithRSAEncryption | ||
| 107 | #define PEM_MD_SHA_RSA NID_sha1WithRSAEncryption | ||
| 108 | |||
| 109 | #define PEM_STRING_X509_OLD "X509 CERTIFICATE" | ||
| 110 | #define PEM_STRING_X509 "CERTIFICATE" | ||
| 111 | #define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST" | ||
| 112 | #define PEM_STRING_X509_REQ "CERTIFICATE REQUEST" | ||
| 113 | #define PEM_STRING_X509_CRL "X509 CRL" | ||
| 114 | #define PEM_STRING_EVP_PKEY "PRIVATE KEY" | ||
| 115 | #define PEM_STRING_RSA "RSA PRIVATE KEY" | ||
| 116 | #define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY" | ||
| 117 | #define PEM_STRING_DSA "DSA PRIVATE KEY" | ||
| 118 | #define PEM_STRING_PKCS7 "PKCS7" | ||
| 119 | #define PEM_STRING_DHPARAMS "DH PARAMETERS" | ||
| 120 | #define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS" | ||
| 121 | #define PEM_STRING_DSAPARAMS "DSA PARAMETERS" | ||
| 122 | |||
| 123 | #ifndef HEADER_ENVELOPE_H | ||
| 124 | |||
| 125 | #define EVP_ENCODE_CTX_SIZE 96 | ||
| 126 | #define EVP_MD_SIZE 60 | ||
| 127 | #define EVP_MD_CTX_SIZE 152 | ||
| 128 | #define EVP_CIPHER_SIZE 40 | ||
| 129 | #define EVP_CIPHER_CTX_SIZE 4212 | ||
| 130 | #define EVP_MAX_MD_SIZE 20 | ||
| 131 | |||
| 132 | typedef struct evp_encode_ctx_st | ||
| 133 | { | ||
| 134 | char data[EVP_ENCODE_CTX_SIZE]; | ||
| 135 | } EVP_ENCODE_CTX; | ||
| 136 | |||
| 137 | typedef struct env_md_ctx_st | ||
| 138 | { | ||
| 139 | char data[EVP_MD_CTX_SIZE]; | ||
| 140 | } EVP_MD_CTX; | ||
| 141 | |||
| 142 | typedef struct evp_cipher_st | ||
| 143 | { | ||
| 144 | char data[EVP_CIPHER_SIZE]; | ||
| 145 | } EVP_CIPHER; | ||
| 146 | |||
| 147 | typedef struct evp_cipher_ctx_st | ||
| 148 | { | ||
| 149 | char data[EVP_CIPHER_CTX_SIZE]; | ||
| 150 | } EVP_CIPHER_CTX; | ||
| 151 | #endif | ||
| 152 | |||
| 153 | |||
| 154 | typedef struct PEM_Encode_Seal_st | ||
| 155 | { | ||
| 156 | EVP_ENCODE_CTX encode; | ||
| 157 | EVP_MD_CTX md; | ||
| 158 | EVP_CIPHER_CTX cipher; | ||
| 159 | } PEM_ENCODE_SEAL_CTX; | ||
| 160 | |||
| 161 | /* enc_type is one off */ | ||
| 162 | #define PEM_TYPE_ENCRYPTED 10 | ||
| 163 | #define PEM_TYPE_MIC_ONLY 20 | ||
| 164 | #define PEM_TYPE_MIC_CLEAR 30 | ||
| 165 | #define PEM_TYPE_CLEAR 40 | ||
| 166 | |||
| 167 | typedef struct pem_recip_st | ||
| 168 | { | ||
| 169 | char *name; | ||
| 170 | X509_NAME *dn; | ||
| 171 | |||
| 172 | int cipher; | ||
| 173 | int key_enc; | ||
| 174 | char iv[8]; | ||
| 175 | } PEM_USER; | ||
| 176 | |||
| 177 | typedef struct pem_ctx_st | ||
| 178 | { | ||
| 179 | int type; /* what type of object */ | ||
| 180 | |||
| 181 | struct { | ||
| 182 | int version; | ||
| 183 | int mode; | ||
| 184 | } proc_type; | ||
| 185 | |||
| 186 | char *domain; | ||
| 187 | |||
| 188 | struct { | ||
| 189 | int cipher; | ||
| 190 | unsigned char iv[8]; | ||
| 191 | } DEK_info; | ||
| 192 | |||
| 193 | PEM_USER *originator; | ||
| 194 | |||
| 195 | int num_recipient; | ||
| 196 | PEM_USER **recipient; | ||
| 197 | |||
| 198 | #ifdef HEADER_STACK_H | ||
| 199 | STACK *x509_chain; /* certificate chain */ | ||
| 200 | #else | ||
| 201 | char *x509_chain; /* certificate chain */ | ||
| 202 | #endif | ||
| 203 | EVP_MD *md; /* signature type */ | ||
| 204 | |||
| 205 | int md_enc; /* is the md encrypted or not? */ | ||
| 206 | int md_len; /* length of md_data */ | ||
| 207 | char *md_data; /* message digest, could be pkey encrypted */ | ||
| 208 | |||
| 209 | EVP_CIPHER *dec; /* date encryption cipher */ | ||
| 210 | int key_len; /* key length */ | ||
| 211 | unsigned char *key; /* key */ | ||
| 212 | unsigned char iv[8]; /* the iv */ | ||
| 213 | |||
| 214 | |||
| 215 | int data_enc; /* is the data encrypted */ | ||
| 216 | int data_len; | ||
| 217 | unsigned char *data; | ||
| 218 | } PEM_CTX; | ||
| 219 | |||
| 220 | #ifdef SSLEAY_MACROS | ||
| 221 | |||
| 222 | #define PEM_write_SSL_SESSION(fp,x) \ | ||
| 223 | PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \ | ||
| 224 | PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL) | ||
| 225 | #define PEM_write_X509(fp,x) \ | ||
| 226 | PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \ | ||
| 227 | (char *)x, NULL,NULL,0,NULL) | ||
| 228 | #define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \ | ||
| 229 | (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \ | ||
| 230 | NULL,NULL,0,NULL) | ||
| 231 | #define PEM_write_X509_CRL(fp,x) \ | ||
| 232 | PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \ | ||
| 233 | fp,(char *)x, NULL,NULL,0,NULL) | ||
| 234 | #define PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb) \ | ||
| 235 | PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\ | ||
| 236 | (char *)x,enc,kstr,klen,cb) | ||
| 237 | #define PEM_write_RSAPublicKey(fp,x) \ | ||
| 238 | PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\ | ||
| 239 | PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL) | ||
| 240 | #define PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb) \ | ||
| 241 | PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\ | ||
| 242 | (char *)x,enc,kstr,klen,cb) | ||
| 243 | #define PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb) \ | ||
| 244 | PEM_ASN1_write((int (*)())i2d_PrivateKey,\ | ||
| 245 | (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\ | ||
| 246 | bp,(char *)x,enc,kstr,klen,cb) | ||
| 247 | #define PEM_write_PKCS7(fp,x) \ | ||
| 248 | PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \ | ||
| 249 | (char *)x, NULL,NULL,0,NULL) | ||
| 250 | #define PEM_write_DHparams(fp,x) \ | ||
| 251 | PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\ | ||
| 252 | (char *)x,NULL,NULL,0,NULL) | ||
| 253 | |||
| 254 | #define PEM_read_SSL_SESSION(fp,x,cb) (SSL_SESSION *)PEM_ASN1_read( \ | ||
| 255 | (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb) | ||
| 256 | #define PEM_read_X509(fp,x,cb) (X509 *)PEM_ASN1_read( \ | ||
| 257 | (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb) | ||
| 258 | #define PEM_read_X509_REQ(fp,x,cb) (X509_REQ *)PEM_ASN1_read( \ | ||
| 259 | (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb) | ||
| 260 | #define PEM_read_X509_CRL(fp,x,cb) (X509_CRL *)PEM_ASN1_read( \ | ||
| 261 | (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb) | ||
| 262 | #define PEM_read_RSAPrivateKey(fp,x,cb) (RSA *)PEM_ASN1_read( \ | ||
| 263 | (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb) | ||
| 264 | #define PEM_read_RSAPublicKey(fp,x,cb) (RSA *)PEM_ASN1_read( \ | ||
| 265 | (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb) | ||
| 266 | #define PEM_read_DSAPrivateKey(fp,x,cb) (DSA *)PEM_ASN1_read( \ | ||
| 267 | (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb) | ||
| 268 | #define PEM_read_PrivateKey(fp,x,cb) (EVP_PKEY *)PEM_ASN1_read( \ | ||
| 269 | (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb) | ||
| 270 | #define PEM_read_PKCS7(fp,x,cb) (PKCS7 *)PEM_ASN1_read( \ | ||
| 271 | (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb) | ||
| 272 | #define PEM_read_DHparams(fp,x,cb) (DH *)PEM_ASN1_read( \ | ||
| 273 | (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb) | ||
| 274 | |||
| 275 | #define PEM_write_bio_SSL_SESSION(bp,x) \ | ||
| 276 | PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \ | ||
| 277 | PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL) | ||
| 278 | #define PEM_write_bio_X509(bp,x) \ | ||
| 279 | PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \ | ||
| 280 | (char *)x, NULL,NULL,0,NULL) | ||
| 281 | #define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \ | ||
| 282 | (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \ | ||
| 283 | NULL,NULL,0,NULL) | ||
| 284 | #define PEM_write_bio_X509_CRL(bp,x) \ | ||
| 285 | PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\ | ||
| 286 | bp,(char *)x, NULL,NULL,0,NULL) | ||
| 287 | #define PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb) \ | ||
| 288 | PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\ | ||
| 289 | bp,(char *)x,enc,kstr,klen,cb) | ||
| 290 | #define PEM_write_bio_RSAPublicKey(bp,x) \ | ||
| 291 | PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \ | ||
| 292 | PEM_STRING_RSA_PUBLIC,\ | ||
| 293 | bp,(char *)x,NULL,NULL,0,NULL) | ||
| 294 | #define PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb) \ | ||
| 295 | PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\ | ||
| 296 | bp,(char *)x,enc,kstr,klen,cb) | ||
| 297 | #define PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb) \ | ||
| 298 | PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\ | ||
| 299 | (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\ | ||
| 300 | bp,(char *)x,enc,kstr,klen,cb) | ||
| 301 | #define PEM_write_bio_PKCS7(bp,x) \ | ||
| 302 | PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \ | ||
| 303 | (char *)x, NULL,NULL,0,NULL) | ||
| 304 | #define PEM_write_bio_DHparams(bp,x) \ | ||
| 305 | PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\ | ||
| 306 | bp,(char *)x,NULL,NULL,0,NULL) | ||
| 307 | #define PEM_write_bio_DSAparams(bp,x) \ | ||
| 308 | PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \ | ||
| 309 | PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL) | ||
| 310 | |||
| 311 | #define PEM_read_bio_SSL_SESSION(bp,x,cb) (SSL_SESSION *)PEM_ASN1_read_bio( \ | ||
| 312 | (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb) | ||
| 313 | #define PEM_read_bio_X509(bp,x,cb) (X509 *)PEM_ASN1_read_bio( \ | ||
| 314 | (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb) | ||
| 315 | #define PEM_read_bio_X509_REQ(bp,x,cb) (X509_REQ *)PEM_ASN1_read_bio( \ | ||
| 316 | (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb) | ||
| 317 | #define PEM_read_bio_X509_CRL(bp,x,cb) (X509_CRL *)PEM_ASN1_read_bio( \ | ||
| 318 | (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb) | ||
| 319 | #define PEM_read_bio_RSAPrivateKey(bp,x,cb) (RSA *)PEM_ASN1_read_bio( \ | ||
| 320 | (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb) | ||
| 321 | #define PEM_read_bio_RSAPublicKey(bp,x,cb) (RSA *)PEM_ASN1_read_bio( \ | ||
| 322 | (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb) | ||
| 323 | #define PEM_read_bio_DSAPrivateKey(bp,x,cb) (DSA *)PEM_ASN1_read_bio( \ | ||
| 324 | (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb) | ||
| 325 | #define PEM_read_bio_PrivateKey(bp,x,cb) (EVP_PKEY *)PEM_ASN1_read_bio( \ | ||
| 326 | (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb) | ||
| 327 | |||
| 328 | #define PEM_read_bio_PKCS7(bp,x,cb) (PKCS7 *)PEM_ASN1_read_bio( \ | ||
| 329 | (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb) | ||
| 330 | #define PEM_read_bio_DHparams(bp,x,cb) (DH *)PEM_ASN1_read_bio( \ | ||
| 331 | (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb) | ||
| 332 | #define PEM_read_bio_DSAparams(bp,x,cb) (DSA *)PEM_ASN1_read_bio( \ | ||
| 333 | (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb) | ||
| 334 | |||
| 335 | #endif | ||
| 336 | |||
| 337 | #ifndef NOPROTO | ||
| 338 | int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher); | ||
| 339 | int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len, | ||
| 340 | int (*callback)()); | ||
| 341 | |||
| 342 | #ifdef HEADER_BIO_H | ||
| 343 | int PEM_read_bio(BIO *bp, char **name, char **header, | ||
| 344 | unsigned char **data,long *len); | ||
| 345 | int PEM_write_bio(BIO *bp,char *name,char *hdr,unsigned char *data, | ||
| 346 | long len); | ||
| 347 | char * PEM_ASN1_read_bio(char *(*d2i)(),char *name,BIO *bp,char **x, | ||
| 348 | int (*cb)()); | ||
| 349 | int PEM_ASN1_write_bio(int (*i2d)(),char *name,BIO *bp,char *x, | ||
| 350 | EVP_CIPHER *enc,unsigned char *kstr,int klen,int (*callback)()); | ||
| 351 | STACK * PEM_X509_INFO_read_bio(BIO *bp, STACK *sk, int (*cb)()); | ||
| 352 | int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc, | ||
| 353 | unsigned char *kstr, int klen, int (*cb)()); | ||
| 354 | #endif | ||
| 355 | |||
| 356 | #ifndef WIN16 | ||
| 357 | int PEM_read(FILE *fp, char **name, char **header, | ||
| 358 | unsigned char **data,long *len); | ||
| 359 | int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len); | ||
| 360 | char * PEM_ASN1_read(char *(*d2i)(),char *name,FILE *fp,char **x, | ||
| 361 | int (*cb)()); | ||
| 362 | int PEM_ASN1_write(int (*i2d)(),char *name,FILE *fp,char *x, | ||
| 363 | EVP_CIPHER *enc,unsigned char *kstr,int klen,int (*callback)()); | ||
| 364 | STACK * PEM_X509_INFO_read(FILE *fp, STACK *sk, int (*cb)()); | ||
| 365 | #endif | ||
| 366 | |||
| 367 | int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, | ||
| 368 | EVP_MD *md_type, unsigned char **ek, int *ekl, | ||
| 369 | unsigned char *iv, EVP_PKEY **pubk, int npubk); | ||
| 370 | void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl, | ||
| 371 | unsigned char *in, int inl); | ||
| 372 | int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig,int *sigl, | ||
| 373 | unsigned char *out, int *outl, EVP_PKEY *priv); | ||
| 374 | |||
| 375 | void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type); | ||
| 376 | void PEM_SignUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt); | ||
| 377 | int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, | ||
| 378 | unsigned int *siglen, EVP_PKEY *pkey); | ||
| 379 | |||
| 380 | void ERR_load_PEM_strings(void); | ||
| 381 | |||
| 382 | void PEM_proc_type(char *buf, int type); | ||
| 383 | void PEM_dek_info(char *buf, char *type, int len, char *str); | ||
| 384 | |||
| 385 | #ifndef SSLEAY_MACROS | ||
| 386 | |||
| 387 | #ifndef WIN16 | ||
| 388 | X509 *PEM_read_X509(FILE *fp,X509 **x,int (*cb)()); | ||
| 389 | X509_REQ *PEM_read_X509_REQ(FILE *fp,X509_REQ **x,int (*cb)()); | ||
| 390 | X509_CRL *PEM_read_X509_CRL(FILE *fp,X509_CRL **x,int (*cb)()); | ||
| 391 | RSA *PEM_read_RSAPrivateKey(FILE *fp,RSA **x,int (*cb)()); | ||
| 392 | RSA *PEM_read_RSAPublicKey(FILE *fp,RSA **x,int (*cb)()); | ||
| 393 | DSA *PEM_read_DSAPrivateKey(FILE *fp,DSA **x,int (*cb)()); | ||
| 394 | EVP_PKEY *PEM_read_PrivateKey(FILE *fp,EVP_PKEY **x,int (*cb)()); | ||
| 395 | PKCS7 *PEM_read_PKCS7(FILE *fp,PKCS7 **x,int (*cb)()); | ||
| 396 | DH *PEM_read_DHparams(FILE *fp,DH **x,int (*cb)()); | ||
| 397 | DSA *PEM_read_DSAparams(FILE *fp,DSA **x,int (*cb)()); | ||
| 398 | int PEM_write_X509(FILE *fp,X509 *x); | ||
| 399 | int PEM_write_X509_REQ(FILE *fp,X509_REQ *x); | ||
| 400 | int PEM_write_X509_CRL(FILE *fp,X509_CRL *x); | ||
| 401 | int PEM_write_RSAPrivateKey(FILE *fp,RSA *x,EVP_CIPHER *enc,unsigned char *kstr, | ||
| 402 | int klen,int (*cb)()); | ||
| 403 | int PEM_write_RSAPublicKey(FILE *fp,RSA *x); | ||
| 404 | int PEM_write_DSAPrivateKey(FILE *fp,DSA *x,EVP_CIPHER *enc,unsigned char *kstr, | ||
| 405 | int klen,int (*cb)()); | ||
| 406 | int PEM_write_PrivateKey(FILE *fp,EVP_PKEY *x,EVP_CIPHER *enc, | ||
| 407 | unsigned char *kstr,int klen,int (*cb)()); | ||
| 408 | int PEM_write_PKCS7(FILE *fp,PKCS7 *x); | ||
| 409 | int PEM_write_DHparams(FILE *fp,DH *x); | ||
| 410 | int PEM_write_DSAparams(FILE *fp,DSA *x); | ||
| 411 | #endif | ||
| 412 | |||
| 413 | #ifdef HEADER_BIO_H | ||
| 414 | X509 *PEM_read_bio_X509(BIO *bp,X509 **x,int (*cb)()); | ||
| 415 | X509_REQ *PEM_read_bio_X509_REQ(BIO *bp,X509_REQ **x,int (*cb)()); | ||
| 416 | X509_CRL *PEM_read_bio_X509_CRL(BIO *bp,X509_CRL **x,int (*cb)()); | ||
| 417 | RSA *PEM_read_bio_RSAPrivateKey(BIO *bp,RSA **x,int (*cb)()); | ||
| 418 | RSA *PEM_read_bio_RSAPublicKey(BIO *bp,RSA **x,int (*cb)()); | ||
| 419 | DSA *PEM_read_bio_DSAPrivateKey(BIO *bp,DSA **x,int (*cb)()); | ||
| 420 | EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp,EVP_PKEY **x,int (*cb)()); | ||
| 421 | PKCS7 *PEM_read_bio_PKCS7(BIO *bp,PKCS7 **x,int (*cb)()); | ||
| 422 | DH *PEM_read_bio_DHparams(BIO *bp,DH **x,int (*cb)()); | ||
| 423 | DSA *PEM_read_bio_DSAparams(BIO *bp,DSA **x,int (*cb)()); | ||
| 424 | int PEM_write_bio_X509(BIO *bp,X509 *x); | ||
| 425 | int PEM_write_bio_X509_REQ(BIO *bp,X509_REQ *x); | ||
| 426 | int PEM_write_bio_X509_CRL(BIO *bp,X509_CRL *x); | ||
| 427 | int PEM_write_bio_RSAPrivateKey(BIO *fp,RSA *x,EVP_CIPHER *enc, | ||
| 428 | unsigned char *kstr,int klen,int (*cb)()); | ||
| 429 | int PEM_write_bio_RSAPublicKey(BIO *fp,RSA *x); | ||
| 430 | int PEM_write_bio_DSAPrivateKey(BIO *fp,DSA *x,EVP_CIPHER *enc, | ||
| 431 | unsigned char *kstr,int klen,int (*cb)()); | ||
| 432 | int PEM_write_bio_PrivateKey(BIO *fp,EVP_PKEY *x,EVP_CIPHER *enc, | ||
| 433 | unsigned char *kstr,int klen,int (*cb)()); | ||
| 434 | int PEM_write_bio_PKCS7(BIO *bp,PKCS7 *x); | ||
| 435 | int PEM_write_bio_DHparams(BIO *bp,DH *x); | ||
| 436 | int PEM_write_bio_DSAparams(BIO *bp,DSA *x); | ||
| 437 | #endif | ||
| 438 | |||
| 439 | #endif /* SSLEAY_MACROS */ | ||
| 440 | |||
| 441 | |||
| 442 | #else | ||
| 443 | |||
| 444 | int PEM_get_EVP_CIPHER_INFO(); | ||
| 445 | int PEM_do_header(); | ||
| 446 | int PEM_read_bio(); | ||
| 447 | int PEM_write_bio(); | ||
| 448 | #ifndef WIN16 | ||
| 449 | int PEM_read(); | ||
| 450 | int PEM_write(); | ||
| 451 | STACK * PEM_X509_INFO_read(); | ||
| 452 | char * PEM_ASN1_read(); | ||
| 453 | int PEM_ASN1_write(); | ||
| 454 | #endif | ||
| 455 | STACK * PEM_X509_INFO_read_bio(); | ||
| 456 | int PEM_X509_INFO_write_bio(); | ||
| 457 | char * PEM_ASN1_read_bio(); | ||
| 458 | int PEM_ASN1_write_bio(); | ||
| 459 | int PEM_SealInit(); | ||
| 460 | void PEM_SealUpdate(); | ||
| 461 | int PEM_SealFinal(); | ||
| 462 | int PEM_SignFinal(); | ||
| 463 | |||
| 464 | void ERR_load_PEM_strings(); | ||
| 465 | |||
| 466 | void PEM_proc_type(); | ||
| 467 | void PEM_dek_info(); | ||
| 468 | |||
| 469 | #ifndef SSLEAY_MACROS | ||
| 470 | #ifndef WIN16 | ||
| 471 | X509 *PEM_read_X509(); | ||
| 472 | X509_REQ *PEM_read_X509_REQ(); | ||
| 473 | X509_CRL *PEM_read_X509_CRL(); | ||
| 474 | RSA *PEM_read_RSAPrivateKey(); | ||
| 475 | RSA *PEM_read_RSAPublicKey(); | ||
| 476 | DSA *PEM_read_DSAPrivateKey(); | ||
| 477 | EVP_PKEY *PEM_read_PrivateKey(); | ||
| 478 | PKCS7 *PEM_read_PKCS7(); | ||
| 479 | DH *PEM_read_DHparams(); | ||
| 480 | DSA *PEM_read_DSAparams(); | ||
| 481 | int PEM_write_X509(); | ||
| 482 | int PEM_write_X509_REQ(); | ||
| 483 | int PEM_write_X509_CRL(); | ||
| 484 | int PEM_write_RSAPrivateKey(); | ||
| 485 | int PEM_write_RSAPublicKey(); | ||
| 486 | int PEM_write_DSAPrivateKey(); | ||
| 487 | int PEM_write_PrivateKey(); | ||
| 488 | int PEM_write_PKCS7(); | ||
| 489 | int PEM_write_DHparams(); | ||
| 490 | int PEM_write_DSAparams(); | ||
| 491 | #endif | ||
| 492 | |||
| 493 | X509 *PEM_read_bio_X509(); | ||
| 494 | X509_REQ *PEM_read_bio_X509_REQ(); | ||
| 495 | X509_CRL *PEM_read_bio_X509_CRL(); | ||
| 496 | RSA *PEM_read_bio_RSAPrivateKey(); | ||
| 497 | RSA *PEM_read_bio_RSAPublicKey(); | ||
| 498 | DSA *PEM_read_bio_DSAPrivateKey(); | ||
| 499 | EVP_PKEY *PEM_read_bio_PrivateKey(); | ||
| 500 | PKCS7 *PEM_read_bio_PKCS7(); | ||
| 501 | DH *PEM_read_bio_DHparams(); | ||
| 502 | DSA *PEM_read_bio_DSAparams(); | ||
| 503 | int PEM_write_bio_X509(); | ||
| 504 | int PEM_write_bio_X509_REQ(); | ||
| 505 | int PEM_write_bio_X509_CRL(); | ||
| 506 | int PEM_write_bio_RSAPrivateKey(); | ||
| 507 | int PEM_write_bio_RSAPublicKey(); | ||
| 508 | int PEM_write_bio_DSAPrivateKey(); | ||
| 509 | int PEM_write_bio_PrivateKey(); | ||
| 510 | int PEM_write_bio_PKCS7(); | ||
| 511 | int PEM_write_bio_DHparams(); | ||
| 512 | int PEM_write_bio_DSAparams(); | ||
| 513 | |||
| 514 | #endif /* SSLEAY_MACROS */ | ||
| 515 | |||
| 516 | #endif | ||
| 517 | |||
| 518 | /* BEGIN ERROR CODES */ | ||
| 519 | /* Error codes for the PEM functions. */ | ||
| 520 | |||
| 521 | /* Function codes. */ | ||
| 522 | #define PEM_F_DEF_CALLBACK 100 | ||
| 523 | #define PEM_F_LOAD_IV 101 | ||
| 524 | #define PEM_F_PEM_ASN1_READ 102 | ||
| 525 | #define PEM_F_PEM_ASN1_READ_BIO 103 | ||
| 526 | #define PEM_F_PEM_ASN1_WRITE 104 | ||
| 527 | #define PEM_F_PEM_ASN1_WRITE_BIO 105 | ||
| 528 | #define PEM_F_PEM_DO_HEADER 106 | ||
| 529 | #define PEM_F_PEM_GET_EVP_CIPHER_INFO 107 | ||
| 530 | #define PEM_F_PEM_READ 108 | ||
| 531 | #define PEM_F_PEM_READ_BIO 109 | ||
| 532 | #define PEM_F_PEM_SEALFINAL 110 | ||
| 533 | #define PEM_F_PEM_SEALINIT 111 | ||
| 534 | #define PEM_F_PEM_SIGNFINAL 112 | ||
| 535 | #define PEM_F_PEM_WRITE 113 | ||
| 536 | #define PEM_F_PEM_WRITE_BIO 114 | ||
| 537 | #define PEM_F_PEM_X509_INFO_READ 115 | ||
| 538 | #define PEM_F_PEM_X509_INFO_READ_BIO 116 | ||
| 539 | #define PEM_F_PEM_X509_INFO_WRITE_BIO 117 | ||
| 540 | |||
| 541 | /* Reason codes. */ | ||
| 542 | #define PEM_R_BAD_BASE64_DECODE 100 | ||
| 543 | #define PEM_R_BAD_DECRYPT 101 | ||
| 544 | #define PEM_R_BAD_END_LINE 102 | ||
| 545 | #define PEM_R_BAD_IV_CHARS 103 | ||
| 546 | #define PEM_R_BAD_PASSWORD_READ 104 | ||
| 547 | #define PEM_R_NOT_DEK_INFO 105 | ||
| 548 | #define PEM_R_NOT_ENCRYPTED 106 | ||
| 549 | #define PEM_R_NOT_PROC_TYPE 107 | ||
| 550 | #define PEM_R_NO_START_LINE 108 | ||
| 551 | #define PEM_R_PROBLEMS_GETTING_PASSWORD 109 | ||
| 552 | #define PEM_R_PUBLIC_KEY_NO_RSA 110 | ||
| 553 | #define PEM_R_READ_KEY 111 | ||
| 554 | #define PEM_R_SHORT_HEADER 112 | ||
| 555 | #define PEM_R_UNSUPPORTED_CIPHER 113 | ||
| 556 | #define PEM_R_UNSUPPORTED_ENCRYPTION 114 | ||
| 557 | |||
| 558 | #ifdef __cplusplus | ||
| 559 | } | ||
| 560 | #endif | ||
| 561 | #endif | ||
| 562 | |||
diff --git a/src/lib/libcrypto/pem/pem_all.c b/src/lib/libcrypto/pem/pem_all.c new file mode 100644 index 0000000000..d1cda7aabe --- /dev/null +++ b/src/lib/libcrypto/pem/pem_all.c | |||
| @@ -0,0 +1,488 @@ | |||
| 1 | /* crypto/pem/pem_all.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 | #undef SSLEAY_MACROS | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "bio.h" | ||
| 63 | #include "evp.h" | ||
| 64 | #include "x509.h" | ||
| 65 | #include "pkcs7.h" | ||
| 66 | #include "pem.h" | ||
| 67 | |||
| 68 | #ifndef NO_FP_API | ||
| 69 | /* The X509 functions */ | ||
| 70 | X509 *PEM_read_X509(fp,x,cb) | ||
| 71 | FILE *fp; | ||
| 72 | X509 **x; | ||
| 73 | int (*cb)(); | ||
| 74 | { | ||
| 75 | return((X509 *)PEM_ASN1_read((char *(*)())d2i_X509, | ||
| 76 | PEM_STRING_X509,fp,(char **)x,cb)); | ||
| 77 | } | ||
| 78 | #endif | ||
| 79 | |||
| 80 | X509 *PEM_read_bio_X509(bp,x,cb) | ||
| 81 | BIO *bp; | ||
| 82 | X509 **x; | ||
| 83 | int (*cb)(); | ||
| 84 | { | ||
| 85 | return((X509 *)PEM_ASN1_read_bio((char *(*)())d2i_X509, | ||
| 86 | PEM_STRING_X509,bp,(char **)x,cb)); | ||
| 87 | } | ||
| 88 | |||
| 89 | #ifndef NO_FP_API | ||
| 90 | int PEM_write_X509(fp,x) | ||
| 91 | FILE *fp; | ||
| 92 | X509 *x; | ||
| 93 | { | ||
| 94 | return(PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, | ||
| 95 | (char *)x, NULL,NULL,0,NULL)); | ||
| 96 | } | ||
| 97 | #endif | ||
| 98 | |||
| 99 | int PEM_write_bio_X509(bp,x) | ||
| 100 | BIO *bp; | ||
| 101 | X509 *x; | ||
| 102 | { | ||
| 103 | return(PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, | ||
| 104 | (char *)x, NULL,NULL,0,NULL)); | ||
| 105 | } | ||
| 106 | |||
| 107 | #ifndef NO_FP_API | ||
| 108 | /* The X509_REQ functions */ | ||
| 109 | X509_REQ *PEM_read_X509_REQ(fp,x,cb) | ||
| 110 | FILE *fp; | ||
| 111 | X509_REQ **x; | ||
| 112 | int (*cb)(); | ||
| 113 | { | ||
| 114 | return((X509_REQ *)PEM_ASN1_read((char *(*)())d2i_X509_REQ, | ||
| 115 | PEM_STRING_X509_REQ,fp,(char **)x,cb)); | ||
| 116 | } | ||
| 117 | #endif | ||
| 118 | |||
| 119 | X509_REQ *PEM_read_bio_X509_REQ(bp,x,cb) | ||
| 120 | BIO *bp; | ||
| 121 | X509_REQ **x; | ||
| 122 | int (*cb)(); | ||
| 123 | { | ||
| 124 | return((X509_REQ *)PEM_ASN1_read_bio((char *(*)())d2i_X509_REQ, | ||
| 125 | PEM_STRING_X509_REQ,bp,(char **)x,cb)); | ||
| 126 | } | ||
| 127 | |||
| 128 | #ifndef NO_FP_API | ||
| 129 | int PEM_write_X509_REQ(fp,x) | ||
| 130 | FILE *fp; | ||
| 131 | X509_REQ *x; | ||
| 132 | { | ||
| 133 | return(PEM_ASN1_write((int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp, | ||
| 134 | (char *)x, NULL,NULL,0,NULL)); | ||
| 135 | } | ||
| 136 | #endif | ||
| 137 | |||
| 138 | int PEM_write_bio_X509_REQ(bp,x) | ||
| 139 | BIO *bp; | ||
| 140 | X509_REQ *x; | ||
| 141 | { | ||
| 142 | return(PEM_ASN1_write_bio((int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ, | ||
| 143 | bp,(char *)x, NULL,NULL,0,NULL)); | ||
| 144 | } | ||
| 145 | |||
| 146 | #ifndef NO_FP_API | ||
| 147 | /* The X509_CRL functions */ | ||
| 148 | X509_CRL *PEM_read_X509_CRL(fp,x,cb) | ||
| 149 | FILE *fp; | ||
| 150 | X509_CRL **x; | ||
| 151 | int (*cb)(); | ||
| 152 | { | ||
| 153 | return((X509_CRL *)PEM_ASN1_read((char *(*)())d2i_X509_CRL, | ||
| 154 | PEM_STRING_X509_CRL,fp,(char **)x,cb)); | ||
| 155 | } | ||
| 156 | #endif | ||
| 157 | |||
| 158 | X509_CRL *PEM_read_bio_X509_CRL(bp,x,cb) | ||
| 159 | BIO *bp; | ||
| 160 | X509_CRL **x; | ||
| 161 | int (*cb)(); | ||
| 162 | { | ||
| 163 | return((X509_CRL *)PEM_ASN1_read_bio((char *(*)())d2i_X509_CRL, | ||
| 164 | PEM_STRING_X509_CRL,bp,(char **)x,cb)); | ||
| 165 | } | ||
| 166 | |||
| 167 | #ifndef NO_FP_API | ||
| 168 | int PEM_write_X509_CRL(fp,x) | ||
| 169 | FILE *fp; | ||
| 170 | X509_CRL *x; | ||
| 171 | { | ||
| 172 | return(PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,fp, | ||
| 173 | (char *)x, NULL,NULL,0,NULL)); | ||
| 174 | } | ||
| 175 | #endif | ||
| 176 | |||
| 177 | int PEM_write_bio_X509_CRL(bp,x) | ||
| 178 | BIO *bp; | ||
| 179 | X509_CRL *x; | ||
| 180 | { | ||
| 181 | return(PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, | ||
| 182 | bp,(char *)x, NULL,NULL,0,NULL)); | ||
| 183 | } | ||
| 184 | |||
| 185 | #ifndef NO_RSA | ||
| 186 | #ifndef NO_FP_API | ||
| 187 | /* The RSAPrivateKey functions */ | ||
| 188 | RSA *PEM_read_RSAPrivateKey(fp,x,cb) | ||
| 189 | FILE *fp; | ||
| 190 | RSA **x; | ||
| 191 | int (*cb)(); | ||
| 192 | { | ||
| 193 | return((RSA *)PEM_ASN1_read((char *(*)())d2i_RSAPrivateKey, | ||
| 194 | PEM_STRING_RSA,fp,(char **)x,cb)); | ||
| 195 | } | ||
| 196 | |||
| 197 | RSA *PEM_read_RSAPublicKey(fp,x,cb) | ||
| 198 | FILE *fp; | ||
| 199 | RSA **x; | ||
| 200 | int (*cb)(); | ||
| 201 | { | ||
| 202 | return((RSA *)PEM_ASN1_read((char *(*)())d2i_RSAPublicKey, | ||
| 203 | PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb)); | ||
| 204 | } | ||
| 205 | #endif | ||
| 206 | |||
| 207 | RSA *PEM_read_bio_RSAPrivateKey(bp,x,cb) | ||
| 208 | BIO *bp; | ||
| 209 | RSA **x; | ||
| 210 | int (*cb)(); | ||
| 211 | { | ||
| 212 | return((RSA *)PEM_ASN1_read_bio((char *(*)())d2i_RSAPrivateKey, | ||
| 213 | PEM_STRING_RSA,bp,(char **)x,cb)); | ||
| 214 | } | ||
| 215 | |||
| 216 | RSA *PEM_read_bio_RSAPublicKey(bp,x,cb) | ||
| 217 | BIO *bp; | ||
| 218 | RSA **x; | ||
| 219 | int (*cb)(); | ||
| 220 | { | ||
| 221 | return((RSA *)PEM_ASN1_read_bio((char *(*)())d2i_RSAPublicKey, | ||
| 222 | PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb)); | ||
| 223 | } | ||
| 224 | |||
| 225 | #ifndef NO_FP_API | ||
| 226 | int PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb) | ||
| 227 | FILE *fp; | ||
| 228 | RSA *x; | ||
| 229 | EVP_CIPHER *enc; | ||
| 230 | unsigned char *kstr; | ||
| 231 | int klen; | ||
| 232 | int (*cb)(); | ||
| 233 | { | ||
| 234 | return(PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp, | ||
| 235 | (char *)x,enc,kstr,klen,cb)); | ||
| 236 | } | ||
| 237 | |||
| 238 | int PEM_write_RSAPublicKey(fp,x) | ||
| 239 | FILE *fp; | ||
| 240 | RSA *x; | ||
| 241 | { | ||
| 242 | return(PEM_ASN1_write((int (*)())i2d_RSAPublicKey, | ||
| 243 | PEM_STRING_RSA_PUBLIC,fp, | ||
| 244 | (char *)x,NULL,NULL,0,NULL)); | ||
| 245 | } | ||
| 246 | #endif | ||
| 247 | |||
| 248 | int PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb) | ||
| 249 | BIO *bp; | ||
| 250 | RSA *x; | ||
| 251 | EVP_CIPHER *enc; | ||
| 252 | unsigned char *kstr; | ||
| 253 | int klen; | ||
| 254 | int (*cb)(); | ||
| 255 | { | ||
| 256 | return(PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA, | ||
| 257 | bp,(char *)x,enc,kstr,klen,cb)); | ||
| 258 | } | ||
| 259 | |||
| 260 | int PEM_write_bio_RSAPublicKey(bp,x) | ||
| 261 | BIO *bp; | ||
| 262 | RSA *x; | ||
| 263 | { | ||
| 264 | return(PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, | ||
| 265 | PEM_STRING_RSA_PUBLIC, | ||
| 266 | bp,(char *)x,NULL,NULL,0,NULL)); | ||
| 267 | } | ||
| 268 | #endif /* !NO_RSA */ | ||
| 269 | |||
| 270 | #ifndef NO_DSA | ||
| 271 | #ifndef NO_FP_API | ||
| 272 | /* The DSAPrivateKey functions */ | ||
| 273 | DSA *PEM_read_DSAPrivateKey(fp,x,cb) | ||
| 274 | FILE *fp; | ||
| 275 | DSA **x; | ||
| 276 | int (*cb)(); | ||
| 277 | { | ||
| 278 | return((DSA *)PEM_ASN1_read((char *(*)())d2i_DSAPrivateKey, | ||
| 279 | PEM_STRING_DSA,fp,(char **)x,cb)); | ||
| 280 | } | ||
| 281 | #endif | ||
| 282 | |||
| 283 | DSA *PEM_read_bio_DSAPrivateKey(bp,x,cb) | ||
| 284 | BIO *bp; | ||
| 285 | DSA **x; | ||
| 286 | int (*cb)(); | ||
| 287 | { | ||
| 288 | return((DSA *)PEM_ASN1_read_bio((char *(*)())d2i_DSAPrivateKey, | ||
| 289 | PEM_STRING_DSA,bp,(char **)x,cb)); | ||
| 290 | } | ||
| 291 | |||
| 292 | #ifndef NO_FP_API | ||
| 293 | int PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb) | ||
| 294 | FILE *fp; | ||
| 295 | DSA *x; | ||
| 296 | EVP_CIPHER *enc; | ||
| 297 | unsigned char *kstr; | ||
| 298 | int klen; | ||
| 299 | int (*cb)(); | ||
| 300 | { | ||
| 301 | return(PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp, | ||
| 302 | (char *)x,enc,kstr,klen,cb)); | ||
| 303 | } | ||
| 304 | #endif | ||
| 305 | |||
| 306 | int PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb) | ||
| 307 | BIO *bp; | ||
| 308 | DSA *x; | ||
| 309 | EVP_CIPHER *enc; | ||
| 310 | unsigned char *kstr; | ||
| 311 | int klen; | ||
| 312 | int (*cb)(); | ||
| 313 | { | ||
| 314 | return(PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA, | ||
| 315 | bp,(char *)x,enc,kstr,klen,cb)); | ||
| 316 | } | ||
| 317 | #endif | ||
| 318 | |||
| 319 | #ifndef NO_FP_API | ||
| 320 | /* The PrivateKey functions */ | ||
| 321 | EVP_PKEY *PEM_read_PrivateKey(fp,x,cb) | ||
| 322 | FILE *fp; | ||
| 323 | EVP_PKEY **x; | ||
| 324 | int (*cb)(); | ||
| 325 | { | ||
| 326 | return((EVP_PKEY *)PEM_ASN1_read((char *(*)())d2i_PrivateKey, | ||
| 327 | PEM_STRING_EVP_PKEY,fp,(char **)x,cb)); | ||
| 328 | } | ||
| 329 | #endif | ||
| 330 | |||
| 331 | EVP_PKEY *PEM_read_bio_PrivateKey(bp,x,cb) | ||
| 332 | BIO *bp; | ||
| 333 | EVP_PKEY **x; | ||
| 334 | int (*cb)(); | ||
| 335 | { | ||
| 336 | return((EVP_PKEY *)PEM_ASN1_read_bio((char *(*)())d2i_PrivateKey, | ||
| 337 | PEM_STRING_EVP_PKEY,bp,(char **)x,cb)); | ||
| 338 | } | ||
| 339 | |||
| 340 | #ifndef NO_FP_API | ||
| 341 | int PEM_write_PrivateKey(fp,x,enc,kstr,klen,cb) | ||
| 342 | FILE *fp; | ||
| 343 | EVP_PKEY *x; | ||
| 344 | EVP_CIPHER *enc; | ||
| 345 | unsigned char *kstr; | ||
| 346 | int klen; | ||
| 347 | int (*cb)(); | ||
| 348 | { | ||
| 349 | return(PEM_ASN1_write((int (*)())i2d_PrivateKey, | ||
| 350 | ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA), | ||
| 351 | fp,(char *)x,enc,kstr,klen,cb)); | ||
| 352 | } | ||
| 353 | #endif | ||
| 354 | |||
| 355 | int PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb) | ||
| 356 | BIO *bp; | ||
| 357 | EVP_PKEY *x; | ||
| 358 | EVP_CIPHER *enc; | ||
| 359 | unsigned char *kstr; | ||
| 360 | int klen; | ||
| 361 | int (*cb)(); | ||
| 362 | { | ||
| 363 | return(PEM_ASN1_write_bio((int (*)())i2d_PrivateKey, | ||
| 364 | ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA), | ||
| 365 | bp,(char *)x,enc,kstr,klen,cb)); | ||
| 366 | } | ||
| 367 | |||
| 368 | #ifndef NO_FP_API | ||
| 369 | /* The PKCS7 functions */ | ||
| 370 | PKCS7 *PEM_read_PKCS7(fp,x,cb) | ||
| 371 | FILE *fp; | ||
| 372 | PKCS7 **x; | ||
| 373 | int (*cb)(); | ||
| 374 | { | ||
| 375 | return((PKCS7 *)PEM_ASN1_read((char *(*)())d2i_PKCS7, | ||
| 376 | PEM_STRING_PKCS7,fp,(char **)x,cb)); | ||
| 377 | } | ||
| 378 | #endif | ||
| 379 | |||
| 380 | PKCS7 *PEM_read_bio_PKCS7(bp,x,cb) | ||
| 381 | BIO *bp; | ||
| 382 | PKCS7 **x; | ||
| 383 | int (*cb)(); | ||
| 384 | { | ||
| 385 | return((PKCS7 *)PEM_ASN1_read_bio((char *(*)())d2i_PKCS7, | ||
| 386 | PEM_STRING_PKCS7,bp,(char **)x,cb)); | ||
| 387 | } | ||
| 388 | |||
| 389 | #ifndef NO_FP_API | ||
| 390 | int PEM_write_PKCS7(fp,x) | ||
| 391 | FILE *fp; | ||
| 392 | PKCS7 *x; | ||
| 393 | { | ||
| 394 | return(PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, | ||
| 395 | (char *)x, NULL,NULL,0,NULL)); | ||
| 396 | } | ||
| 397 | #endif | ||
| 398 | |||
| 399 | int PEM_write_bio_PKCS7(bp,x) | ||
| 400 | BIO *bp; | ||
| 401 | PKCS7 *x; | ||
| 402 | { | ||
| 403 | return(PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, | ||
| 404 | (char *)x, NULL,NULL,0,NULL)); | ||
| 405 | } | ||
| 406 | |||
| 407 | #ifndef NO_DH | ||
| 408 | #ifndef NO_FP_API | ||
| 409 | /* The DHparams functions */ | ||
| 410 | DH *PEM_read_DHparams(fp,x,cb) | ||
| 411 | FILE *fp; | ||
| 412 | DH **x; | ||
| 413 | int (*cb)(); | ||
| 414 | { | ||
| 415 | return((DH *)PEM_ASN1_read((char *(*)())d2i_DHparams, | ||
| 416 | PEM_STRING_DHPARAMS,fp,(char **)x,cb)); | ||
| 417 | } | ||
| 418 | #endif | ||
| 419 | |||
| 420 | DH *PEM_read_bio_DHparams(bp,x,cb) | ||
| 421 | BIO *bp; | ||
| 422 | DH **x; | ||
| 423 | int (*cb)(); | ||
| 424 | { | ||
| 425 | return((DH *)PEM_ASN1_read_bio((char *(*)())d2i_DHparams, | ||
| 426 | PEM_STRING_DHPARAMS,bp,(char **)x,cb)); | ||
| 427 | } | ||
| 428 | |||
| 429 | #ifndef NO_FP_API | ||
| 430 | int PEM_write_DHparams(fp,x) | ||
| 431 | FILE *fp; | ||
| 432 | DH *x; | ||
| 433 | { | ||
| 434 | return(PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp, | ||
| 435 | (char *)x, NULL,NULL,0,NULL)); | ||
| 436 | } | ||
| 437 | #endif | ||
| 438 | |||
| 439 | int PEM_write_bio_DHparams(bp,x) | ||
| 440 | BIO *bp; | ||
| 441 | DH *x; | ||
| 442 | { | ||
| 443 | return(PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS, | ||
| 444 | bp,(char *)x, NULL,NULL,0,NULL)); | ||
| 445 | } | ||
| 446 | #endif | ||
| 447 | |||
| 448 | #ifndef NO_DSA | ||
| 449 | #ifndef NO_FP_API | ||
| 450 | /* The DSAparams functions */ | ||
| 451 | DSA *PEM_read_DSAparams(fp,x,cb) | ||
| 452 | FILE *fp; | ||
| 453 | DSA **x; | ||
| 454 | int (*cb)(); | ||
| 455 | { | ||
| 456 | return((DSA *)PEM_ASN1_read((char *(*)())d2i_DSAparams, | ||
| 457 | PEM_STRING_DSAPARAMS,fp,(char **)x,cb)); | ||
| 458 | } | ||
| 459 | #endif | ||
| 460 | |||
| 461 | DSA *PEM_read_bio_DSAparams(bp,x,cb) | ||
| 462 | BIO *bp; | ||
| 463 | DSA **x; | ||
| 464 | int (*cb)(); | ||
| 465 | { | ||
| 466 | return((DSA *)PEM_ASN1_read_bio((char *(*)())d2i_DSAparams, | ||
| 467 | PEM_STRING_DSAPARAMS,bp,(char **)x,cb)); | ||
| 468 | } | ||
| 469 | |||
| 470 | #ifndef NO_FP_API | ||
| 471 | int PEM_write_DSAparams(fp,x) | ||
| 472 | FILE *fp; | ||
| 473 | DSA *x; | ||
| 474 | { | ||
| 475 | return(PEM_ASN1_write((int (*)())i2d_DSAparams,PEM_STRING_DSAPARAMS,fp, | ||
| 476 | (char *)x, NULL,NULL,0,NULL)); | ||
| 477 | } | ||
| 478 | #endif | ||
| 479 | |||
| 480 | int PEM_write_bio_DSAparams(bp,x) | ||
| 481 | BIO *bp; | ||
| 482 | DSA *x; | ||
| 483 | { | ||
| 484 | return(PEM_ASN1_write_bio((int (*)())i2d_DSAparams,PEM_STRING_DSAPARAMS, | ||
| 485 | bp,(char *)x, NULL,NULL,0,NULL)); | ||
| 486 | } | ||
| 487 | #endif | ||
| 488 | |||
diff --git a/src/lib/libcrypto/pem/pem_err.c b/src/lib/libcrypto/pem/pem_err.c new file mode 100644 index 0000000000..e17fcdb540 --- /dev/null +++ b/src/lib/libcrypto/pem/pem_err.c | |||
| @@ -0,0 +1,122 @@ | |||
| 1 | /* lib/pem/pem_err.c */ | ||
| 2 | /* Copyright (C) 1995-1997 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 | #include <stdio.h> | ||
| 59 | #include "err.h" | ||
| 60 | #include "pem.h" | ||
| 61 | |||
| 62 | /* BEGIN ERROR CODES */ | ||
| 63 | #ifndef NO_ERR | ||
| 64 | static ERR_STRING_DATA PEM_str_functs[]= | ||
| 65 | { | ||
| 66 | {ERR_PACK(0,PEM_F_DEF_CALLBACK,0), "DEF_CALLBACK"}, | ||
| 67 | {ERR_PACK(0,PEM_F_LOAD_IV,0), "LOAD_IV"}, | ||
| 68 | {ERR_PACK(0,PEM_F_PEM_ASN1_READ,0), "PEM_ASN1_read"}, | ||
| 69 | {ERR_PACK(0,PEM_F_PEM_ASN1_READ_BIO,0), "PEM_ASN1_read_bio"}, | ||
| 70 | {ERR_PACK(0,PEM_F_PEM_ASN1_WRITE,0), "PEM_ASN1_write"}, | ||
| 71 | {ERR_PACK(0,PEM_F_PEM_ASN1_WRITE_BIO,0), "PEM_ASN1_write_bio"}, | ||
| 72 | {ERR_PACK(0,PEM_F_PEM_DO_HEADER,0), "PEM_do_header"}, | ||
| 73 | {ERR_PACK(0,PEM_F_PEM_GET_EVP_CIPHER_INFO,0), "PEM_get_EVP_CIPHER_INFO"}, | ||
| 74 | {ERR_PACK(0,PEM_F_PEM_READ,0), "PEM_read"}, | ||
| 75 | {ERR_PACK(0,PEM_F_PEM_READ_BIO,0), "PEM_read_bio"}, | ||
| 76 | {ERR_PACK(0,PEM_F_PEM_SEALFINAL,0), "PEM_SealFinal"}, | ||
| 77 | {ERR_PACK(0,PEM_F_PEM_SEALINIT,0), "PEM_SealInit"}, | ||
| 78 | {ERR_PACK(0,PEM_F_PEM_SIGNFINAL,0), "PEM_SignFinal"}, | ||
| 79 | {ERR_PACK(0,PEM_F_PEM_WRITE,0), "PEM_write"}, | ||
| 80 | {ERR_PACK(0,PEM_F_PEM_WRITE_BIO,0), "PEM_write_bio"}, | ||
| 81 | {ERR_PACK(0,PEM_F_PEM_X509_INFO_READ,0), "PEM_X509_INFO_read"}, | ||
| 82 | {ERR_PACK(0,PEM_F_PEM_X509_INFO_READ_BIO,0), "PEM_X509_INFO_read_bio"}, | ||
| 83 | {ERR_PACK(0,PEM_F_PEM_X509_INFO_WRITE_BIO,0), "PEM_X509_INFO_write_bio"}, | ||
| 84 | {0,NULL}, | ||
| 85 | }; | ||
| 86 | |||
| 87 | static ERR_STRING_DATA PEM_str_reasons[]= | ||
| 88 | { | ||
| 89 | {PEM_R_BAD_BASE64_DECODE ,"bad base64 decode"}, | ||
| 90 | {PEM_R_BAD_DECRYPT ,"bad decrypt"}, | ||
| 91 | {PEM_R_BAD_END_LINE ,"bad end line"}, | ||
| 92 | {PEM_R_BAD_IV_CHARS ,"bad iv chars"}, | ||
| 93 | {PEM_R_BAD_PASSWORD_READ ,"bad password read"}, | ||
| 94 | {PEM_R_NOT_DEK_INFO ,"not dek info"}, | ||
| 95 | {PEM_R_NOT_ENCRYPTED ,"not encrypted"}, | ||
| 96 | {PEM_R_NOT_PROC_TYPE ,"not proc type"}, | ||
| 97 | {PEM_R_NO_START_LINE ,"no start line"}, | ||
| 98 | {PEM_R_PROBLEMS_GETTING_PASSWORD ,"problems getting password"}, | ||
| 99 | {PEM_R_PUBLIC_KEY_NO_RSA ,"public key no rsa"}, | ||
| 100 | {PEM_R_READ_KEY ,"read key"}, | ||
| 101 | {PEM_R_SHORT_HEADER ,"short header"}, | ||
| 102 | {PEM_R_UNSUPPORTED_CIPHER ,"unsupported cipher"}, | ||
| 103 | {PEM_R_UNSUPPORTED_ENCRYPTION ,"unsupported encryption"}, | ||
| 104 | {0,NULL}, | ||
| 105 | }; | ||
| 106 | |||
| 107 | #endif | ||
| 108 | |||
| 109 | void ERR_load_PEM_strings() | ||
| 110 | { | ||
| 111 | static int init=1; | ||
| 112 | |||
| 113 | if (init); | ||
| 114 | {; | ||
| 115 | init=0; | ||
| 116 | #ifndef NO_ERR | ||
| 117 | ERR_load_strings(ERR_LIB_PEM,PEM_str_functs); | ||
| 118 | ERR_load_strings(ERR_LIB_PEM,PEM_str_reasons); | ||
| 119 | #endif | ||
| 120 | |||
| 121 | } | ||
| 122 | } | ||
diff --git a/src/lib/libcrypto/pem/pem_info.c b/src/lib/libcrypto/pem/pem_info.c new file mode 100644 index 0000000000..4b69833b62 --- /dev/null +++ b/src/lib/libcrypto/pem/pem_info.c | |||
| @@ -0,0 +1,365 @@ | |||
| 1 | /* crypto/pem/pem_info.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 "buffer.h" | ||
| 62 | #include "objects.h" | ||
| 63 | #include "evp.h" | ||
| 64 | #include "x509.h" | ||
| 65 | #include "pem.h" | ||
| 66 | |||
| 67 | #ifndef NO_FP_API | ||
| 68 | STACK *PEM_X509_INFO_read(fp,sk,cb) | ||
| 69 | FILE *fp; | ||
| 70 | STACK *sk; | ||
| 71 | int (*cb)(); | ||
| 72 | { | ||
| 73 | BIO *b; | ||
| 74 | STACK *ret; | ||
| 75 | |||
| 76 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 77 | { | ||
| 78 | PEMerr(PEM_F_PEM_X509_INFO_READ,ERR_R_BUF_LIB); | ||
| 79 | return(0); | ||
| 80 | } | ||
| 81 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 82 | ret=PEM_X509_INFO_read_bio(b,sk,cb); | ||
| 83 | BIO_free(b); | ||
| 84 | return(ret); | ||
| 85 | } | ||
| 86 | #endif | ||
| 87 | |||
| 88 | STACK *PEM_X509_INFO_read_bio(bp,sk,cb) | ||
| 89 | BIO *bp; | ||
| 90 | STACK *sk; | ||
| 91 | int (*cb)(); | ||
| 92 | { | ||
| 93 | X509_INFO *xi=NULL; | ||
| 94 | char *name=NULL,*header=NULL,**pp; | ||
| 95 | unsigned char *data=NULL,*p; | ||
| 96 | long len,error=0; | ||
| 97 | int ok=0; | ||
| 98 | STACK *ret=NULL; | ||
| 99 | unsigned int i,raw; | ||
| 100 | char *(*d2i)(); | ||
| 101 | |||
| 102 | if (sk == NULL) | ||
| 103 | { | ||
| 104 | if ((ret=sk_new_null()) == NULL) | ||
| 105 | { | ||
| 106 | PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_MALLOC_FAILURE); | ||
| 107 | goto err; | ||
| 108 | } | ||
| 109 | } | ||
| 110 | else | ||
| 111 | ret=sk; | ||
| 112 | |||
| 113 | if ((xi=X509_INFO_new()) == NULL) goto err; | ||
| 114 | for (;;) | ||
| 115 | { | ||
| 116 | raw=0; | ||
| 117 | i=PEM_read_bio(bp,&name,&header,&data,&len); | ||
| 118 | if (i == 0) | ||
| 119 | { | ||
| 120 | error=ERR_GET_REASON(ERR_peek_error()); | ||
| 121 | if (error == PEM_R_NO_START_LINE) | ||
| 122 | { | ||
| 123 | ERR_clear_error(); | ||
| 124 | break; | ||
| 125 | } | ||
| 126 | goto err; | ||
| 127 | } | ||
| 128 | start: | ||
| 129 | if ( (strcmp(name,PEM_STRING_X509) == 0) || | ||
| 130 | (strcmp(name,PEM_STRING_X509_OLD) == 0)) | ||
| 131 | { | ||
| 132 | d2i=(char *(*)())d2i_X509; | ||
| 133 | if (xi->x509 != NULL) | ||
| 134 | { | ||
| 135 | if (!sk_push(ret,(char *)xi)) goto err; | ||
| 136 | if ((xi=X509_INFO_new()) == NULL) goto err; | ||
| 137 | goto start; | ||
| 138 | } | ||
| 139 | pp=(char **)&(xi->x509); | ||
| 140 | } | ||
| 141 | else if (strcmp(name,PEM_STRING_X509_CRL) == 0) | ||
| 142 | { | ||
| 143 | d2i=(char *(*)())d2i_X509_CRL; | ||
| 144 | if (xi->crl != NULL) | ||
| 145 | { | ||
| 146 | if (!sk_push(ret,(char *)xi)) goto err; | ||
| 147 | if ((xi=X509_INFO_new()) == NULL) goto err; | ||
| 148 | goto start; | ||
| 149 | } | ||
| 150 | pp=(char **)&(xi->crl); | ||
| 151 | } | ||
| 152 | else | ||
| 153 | #ifndef NO_RSA | ||
| 154 | if (strcmp(name,PEM_STRING_RSA) == 0) | ||
| 155 | { | ||
| 156 | d2i=(char *(*)())d2i_RSAPrivateKey; | ||
| 157 | if (xi->x_pkey != NULL) | ||
| 158 | { | ||
| 159 | if (!sk_push(ret,(char *)xi)) goto err; | ||
| 160 | if ((xi=X509_INFO_new()) == NULL) goto err; | ||
| 161 | goto start; | ||
| 162 | } | ||
| 163 | |||
| 164 | xi->enc_data=NULL; | ||
| 165 | xi->enc_len=0; | ||
| 166 | |||
| 167 | xi->x_pkey=X509_PKEY_new(); | ||
| 168 | if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL) | ||
| 169 | goto err; | ||
| 170 | xi->x_pkey->dec_pkey->type=EVP_PKEY_RSA; | ||
| 171 | pp=(char **)&(xi->x_pkey->dec_pkey->pkey.rsa); | ||
| 172 | if ((int)strlen(header) > 10) /* assume encrypted */ | ||
| 173 | raw=1; | ||
| 174 | } | ||
| 175 | else | ||
| 176 | #endif | ||
| 177 | #ifndef NO_DSA | ||
| 178 | if (strcmp(name,PEM_STRING_DSA) == 0) | ||
| 179 | { | ||
| 180 | d2i=(char *(*)())d2i_DSAPrivateKey; | ||
| 181 | if (xi->x_pkey != NULL) | ||
| 182 | { | ||
| 183 | if (!sk_push(ret,(char *)xi)) goto err; | ||
| 184 | if ((xi=X509_INFO_new()) == NULL) goto err; | ||
| 185 | goto start; | ||
| 186 | } | ||
| 187 | |||
| 188 | xi->enc_data=NULL; | ||
| 189 | xi->enc_len=0; | ||
| 190 | |||
| 191 | xi->x_pkey=X509_PKEY_new(); | ||
| 192 | if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL) | ||
| 193 | goto err; | ||
| 194 | xi->x_pkey->dec_pkey->type=EVP_PKEY_DSA; | ||
| 195 | pp=(char **)&(xi->x_pkey->dec_pkey->pkey.dsa); | ||
| 196 | if ((int)strlen(header) > 10) /* assume encrypted */ | ||
| 197 | raw=1; | ||
| 198 | } | ||
| 199 | else | ||
| 200 | #endif | ||
| 201 | { | ||
| 202 | d2i=NULL; | ||
| 203 | pp=NULL; | ||
| 204 | } | ||
| 205 | |||
| 206 | if (d2i != NULL) | ||
| 207 | { | ||
| 208 | if (!raw) | ||
| 209 | { | ||
| 210 | EVP_CIPHER_INFO cipher; | ||
| 211 | |||
| 212 | if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) | ||
| 213 | goto err; | ||
| 214 | if (!PEM_do_header(&cipher,data,&len,cb)) | ||
| 215 | goto err; | ||
| 216 | p=data; | ||
| 217 | if (d2i(pp,&p,len) == NULL) | ||
| 218 | { | ||
| 219 | PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_ASN1_LIB); | ||
| 220 | goto err; | ||
| 221 | } | ||
| 222 | } | ||
| 223 | else | ||
| 224 | { /* encrypted RSA data */ | ||
| 225 | if (!PEM_get_EVP_CIPHER_INFO(header, | ||
| 226 | &xi->enc_cipher)) goto err; | ||
| 227 | xi->enc_data=(char *)data; | ||
| 228 | xi->enc_len=(int)len; | ||
| 229 | data=NULL; | ||
| 230 | } | ||
| 231 | } | ||
| 232 | else { | ||
| 233 | /* unknown */ | ||
| 234 | } | ||
| 235 | if (name != NULL) Free(name); | ||
| 236 | if (header != NULL) Free(header); | ||
| 237 | if (data != NULL) Free(data); | ||
| 238 | name=NULL; | ||
| 239 | header=NULL; | ||
| 240 | data=NULL; | ||
| 241 | } | ||
| 242 | |||
| 243 | /* if the last one hasn't been pushed yet and there is anything | ||
| 244 | * in it then add it to the stack ... | ||
| 245 | */ | ||
| 246 | if ((xi->x509 != NULL) || (xi->crl != NULL) || | ||
| 247 | (xi->x_pkey != NULL) || (xi->enc_data != NULL)) | ||
| 248 | { | ||
| 249 | if (!sk_push(ret,(char *)xi)) goto err; | ||
| 250 | xi=NULL; | ||
| 251 | } | ||
| 252 | ok=1; | ||
| 253 | err: | ||
| 254 | if (xi != NULL) X509_INFO_free(xi); | ||
| 255 | if (!ok) | ||
| 256 | { | ||
| 257 | for (i=0; ((int)i)<sk_num(ret); i++) | ||
| 258 | { | ||
| 259 | xi=(X509_INFO *)sk_value(ret,i); | ||
| 260 | X509_INFO_free(xi); | ||
| 261 | } | ||
| 262 | if (ret != sk) sk_free(ret); | ||
| 263 | ret=NULL; | ||
| 264 | } | ||
| 265 | |||
| 266 | if (name != NULL) Free(name); | ||
| 267 | if (header != NULL) Free(header); | ||
| 268 | if (data != NULL) Free(data); | ||
| 269 | return(ret); | ||
| 270 | } | ||
| 271 | |||
| 272 | |||
| 273 | /* A TJH addition */ | ||
| 274 | int PEM_X509_INFO_write_bio(bp,xi,enc,kstr,klen,cb) | ||
| 275 | BIO *bp; | ||
| 276 | X509_INFO *xi; | ||
| 277 | EVP_CIPHER *enc; | ||
| 278 | unsigned char *kstr; | ||
| 279 | int klen; | ||
| 280 | int (*cb)(); | ||
| 281 | { | ||
| 282 | EVP_CIPHER_CTX ctx; | ||
| 283 | int i,ret=0; | ||
| 284 | unsigned char *data=NULL; | ||
| 285 | char *objstr=NULL; | ||
| 286 | #define PEM_BUFSIZE 1024 | ||
| 287 | char buf[PEM_BUFSIZE]; | ||
| 288 | unsigned char *iv=NULL; | ||
| 289 | |||
| 290 | if (enc != NULL) | ||
| 291 | { | ||
| 292 | objstr=OBJ_nid2sn(EVP_CIPHER_nid(enc)); | ||
| 293 | if (objstr == NULL) | ||
| 294 | { | ||
| 295 | PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER); | ||
| 296 | goto err; | ||
| 297 | } | ||
| 298 | } | ||
| 299 | |||
| 300 | /* now for the fun part ... if we have a private key then | ||
| 301 | * we have to be able to handle a not-yet-decrypted key | ||
| 302 | * being written out correctly ... if it is decrypted or | ||
| 303 | * it is non-encrypted then we use the base code | ||
| 304 | */ | ||
| 305 | if (xi->x_pkey!=NULL) | ||
| 306 | { | ||
| 307 | if ( (xi->enc_data!=NULL) && (xi->enc_len>0) ) | ||
| 308 | { | ||
| 309 | /* copy from wierdo names into more normal things */ | ||
| 310 | iv=xi->enc_cipher.iv; | ||
| 311 | data=(unsigned char *)xi->enc_data; | ||
| 312 | i=xi->enc_len; | ||
| 313 | |||
| 314 | /* we take the encryption data from the | ||
| 315 | * internal stuff rather than what the | ||
| 316 | * user has passed us ... as we have to | ||
| 317 | * match exactly for some strange reason | ||
| 318 | */ | ||
| 319 | objstr=OBJ_nid2sn( | ||
| 320 | EVP_CIPHER_nid(xi->enc_cipher.cipher)); | ||
| 321 | if (objstr == NULL) | ||
| 322 | { | ||
| 323 | PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER); | ||
| 324 | goto err; | ||
| 325 | } | ||
| 326 | |||
| 327 | /* create the right magic header stuff */ | ||
| 328 | buf[0]='\0'; | ||
| 329 | PEM_proc_type(buf,PEM_TYPE_ENCRYPTED); | ||
| 330 | PEM_dek_info(buf,objstr,8,(char *)iv); | ||
| 331 | |||
| 332 | /* use the normal code to write things out */ | ||
| 333 | i=PEM_write_bio(bp,PEM_STRING_RSA,buf,data,i); | ||
| 334 | if (i <= 0) goto err; | ||
| 335 | } | ||
| 336 | else | ||
| 337 | { | ||
| 338 | /* Add DSA/DH */ | ||
| 339 | #ifndef NO_RSA | ||
| 340 | /* normal optionally encrypted stuff */ | ||
| 341 | if (PEM_write_bio_RSAPrivateKey(bp, | ||
| 342 | xi->x_pkey->dec_pkey->pkey.rsa, | ||
| 343 | enc,kstr,klen,cb)<=0) | ||
| 344 | goto err; | ||
| 345 | #endif | ||
| 346 | } | ||
| 347 | } | ||
| 348 | |||
| 349 | /* if we have a certificate then write it out now */ | ||
| 350 | if ((xi->x509 != NULL) || (PEM_write_bio_X509(bp,xi->x509) <= 0)) | ||
| 351 | goto err; | ||
| 352 | |||
| 353 | /* we are ignoring anything else that is loaded into the X509_INFO | ||
| 354 | * structure for the moment ... as I don't need it so I'm not | ||
| 355 | * coding it here and Eric can do it when this makes it into the | ||
| 356 | * base library --tjh | ||
| 357 | */ | ||
| 358 | |||
| 359 | ret=1; | ||
| 360 | |||
| 361 | err: | ||
| 362 | memset((char *)&ctx,0,sizeof(ctx)); | ||
| 363 | memset(buf,0,PEM_BUFSIZE); | ||
| 364 | return(ret); | ||
| 365 | } | ||
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c new file mode 100644 index 0000000000..7a2c0ad83b --- /dev/null +++ b/src/lib/libcrypto/pem/pem_lib.c | |||
| @@ -0,0 +1,762 @@ | |||
| 1 | /* crypto/pem/pem_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 "buffer.h" | ||
| 62 | #include "objects.h" | ||
| 63 | #include "evp.h" | ||
| 64 | #include "rand.h" | ||
| 65 | #include "x509.h" | ||
| 66 | #include "pem.h" | ||
| 67 | #ifndef NO_DES | ||
| 68 | #include "des.h" | ||
| 69 | #endif | ||
| 70 | |||
| 71 | char *PEM_version="PEM part of SSLeay 0.9.0b 29-Jun-1998"; | ||
| 72 | |||
| 73 | #define MIN_LENGTH 4 | ||
| 74 | |||
| 75 | /* PEMerr(PEM_F_PEM_WRITE_BIO,ERR_R_MALLOC_FAILURE); | ||
| 76 | * PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); | ||
| 77 | */ | ||
| 78 | |||
| 79 | #ifndef NOPROTO | ||
| 80 | static int def_callback(char *buf, int num, int w); | ||
| 81 | static int load_iv(unsigned char **fromp,unsigned char *to, int num); | ||
| 82 | #else | ||
| 83 | static int def_callback(); | ||
| 84 | static int load_iv(); | ||
| 85 | #endif | ||
| 86 | |||
| 87 | static int def_callback(buf, num, w) | ||
| 88 | char *buf; | ||
| 89 | int num; | ||
| 90 | int w; | ||
| 91 | { | ||
| 92 | #ifdef NO_FP_API | ||
| 93 | /* We should not ever call the default callback routine from | ||
| 94 | * windows. */ | ||
| 95 | PEMerr(PEM_F_DEF_CALLBACK,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
| 96 | return(-1); | ||
| 97 | #else | ||
| 98 | int i,j; | ||
| 99 | char *prompt; | ||
| 100 | |||
| 101 | prompt=EVP_get_pw_prompt(); | ||
| 102 | if (prompt == NULL) | ||
| 103 | prompt="Enter PEM pass phrase:"; | ||
| 104 | |||
| 105 | for (;;) | ||
| 106 | { | ||
| 107 | i=EVP_read_pw_string(buf,num,prompt,w); | ||
| 108 | if (i != 0) | ||
| 109 | { | ||
| 110 | PEMerr(PEM_F_DEF_CALLBACK,PEM_R_PROBLEMS_GETTING_PASSWORD); | ||
| 111 | memset(buf,0,(unsigned int)num); | ||
| 112 | return(-1); | ||
| 113 | } | ||
| 114 | j=strlen(buf); | ||
| 115 | if (j < MIN_LENGTH) | ||
| 116 | { | ||
| 117 | fprintf(stderr,"phrase is too short, needs to be at least %d chars\n",MIN_LENGTH); | ||
| 118 | } | ||
| 119 | else | ||
| 120 | break; | ||
| 121 | } | ||
| 122 | return(j); | ||
| 123 | #endif | ||
| 124 | } | ||
| 125 | |||
| 126 | void PEM_proc_type(buf, type) | ||
| 127 | char *buf; | ||
| 128 | int type; | ||
| 129 | { | ||
| 130 | char *str; | ||
| 131 | |||
| 132 | if (type == PEM_TYPE_ENCRYPTED) | ||
| 133 | str="ENCRYPTED"; | ||
| 134 | else if (type == PEM_TYPE_MIC_CLEAR) | ||
| 135 | str="MIC-CLEAR"; | ||
| 136 | else if (type == PEM_TYPE_MIC_ONLY) | ||
| 137 | str="MIC-ONLY"; | ||
| 138 | else | ||
| 139 | str="BAD-TYPE"; | ||
| 140 | |||
| 141 | strcat(buf,"Proc-Type: 4,"); | ||
| 142 | strcat(buf,str); | ||
| 143 | strcat(buf,"\n"); | ||
| 144 | } | ||
| 145 | |||
| 146 | void PEM_dek_info(buf, type, len, str) | ||
| 147 | char *buf; | ||
| 148 | char *type; | ||
| 149 | int len; | ||
| 150 | char *str; | ||
| 151 | { | ||
| 152 | static unsigned char map[17]="0123456789ABCDEF"; | ||
| 153 | long i; | ||
| 154 | int j; | ||
| 155 | |||
| 156 | strcat(buf,"DEK-Info: "); | ||
| 157 | strcat(buf,type); | ||
| 158 | strcat(buf,","); | ||
| 159 | j=strlen(buf); | ||
| 160 | for (i=0; i<len; i++) | ||
| 161 | { | ||
| 162 | buf[j+i*2] =map[(str[i]>>4)&0x0f]; | ||
| 163 | buf[j+i*2+1]=map[(str[i] )&0x0f]; | ||
| 164 | } | ||
| 165 | buf[j+i*2]='\n'; | ||
| 166 | buf[j+i*2+1]='\0'; | ||
| 167 | } | ||
| 168 | |||
| 169 | #ifndef NO_FP_API | ||
| 170 | char *PEM_ASN1_read(d2i,name,fp, x, cb) | ||
| 171 | char *(*d2i)(); | ||
| 172 | char *name; | ||
| 173 | FILE *fp; | ||
| 174 | char **x; | ||
| 175 | int (*cb)(); | ||
| 176 | { | ||
| 177 | BIO *b; | ||
| 178 | char *ret; | ||
| 179 | |||
| 180 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 181 | { | ||
| 182 | PEMerr(PEM_F_PEM_ASN1_READ,ERR_R_BUF_LIB); | ||
| 183 | return(0); | ||
| 184 | } | ||
| 185 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 186 | ret=PEM_ASN1_read_bio(d2i,name,b,x,cb); | ||
| 187 | BIO_free(b); | ||
| 188 | return(ret); | ||
| 189 | } | ||
| 190 | #endif | ||
| 191 | |||
| 192 | char *PEM_ASN1_read_bio(d2i,name,bp, x, cb) | ||
| 193 | char *(*d2i)(); | ||
| 194 | char *name; | ||
| 195 | BIO *bp; | ||
| 196 | char **x; | ||
| 197 | int (*cb)(); | ||
| 198 | { | ||
| 199 | EVP_CIPHER_INFO cipher; | ||
| 200 | char *nm=NULL,*header=NULL; | ||
| 201 | unsigned char *p=NULL,*data=NULL; | ||
| 202 | long len; | ||
| 203 | char *ret=NULL; | ||
| 204 | |||
| 205 | for (;;) | ||
| 206 | { | ||
| 207 | if (!PEM_read_bio(bp,&nm,&header,&data,&len)) return(NULL); | ||
| 208 | if ( (strcmp(nm,name) == 0) || | ||
| 209 | ((strcmp(nm,PEM_STRING_RSA) == 0) && | ||
| 210 | (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) || | ||
| 211 | ((strcmp(nm,PEM_STRING_DSA) == 0) && | ||
| 212 | (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) || | ||
| 213 | ((strcmp(nm,PEM_STRING_X509_OLD) == 0) && | ||
| 214 | (strcmp(name,PEM_STRING_X509) == 0)) || | ||
| 215 | ((strcmp(nm,PEM_STRING_X509_REQ_OLD) == 0) && | ||
| 216 | (strcmp(name,PEM_STRING_X509_REQ) == 0)) | ||
| 217 | ) | ||
| 218 | break; | ||
| 219 | Free(nm); | ||
| 220 | Free(header); | ||
| 221 | Free(data); | ||
| 222 | } | ||
| 223 | if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) goto err; | ||
| 224 | if (!PEM_do_header(&cipher,data,&len,cb)) goto err; | ||
| 225 | p=data; | ||
| 226 | if (strcmp(name,PEM_STRING_EVP_PKEY) == 0) | ||
| 227 | { | ||
| 228 | if (strcmp(nm,PEM_STRING_RSA) == 0) | ||
| 229 | ret=d2i(EVP_PKEY_RSA,x,&p,len); | ||
| 230 | else if (strcmp(nm,PEM_STRING_DSA) == 0) | ||
| 231 | ret=d2i(EVP_PKEY_DSA,x,&p,len); | ||
| 232 | } | ||
| 233 | else | ||
| 234 | ret=d2i(x,&p,len); | ||
| 235 | if (ret == NULL) | ||
| 236 | PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB); | ||
| 237 | err: | ||
| 238 | Free(nm); | ||
| 239 | Free(header); | ||
| 240 | Free(data); | ||
| 241 | return(ret); | ||
| 242 | } | ||
| 243 | |||
| 244 | #ifndef NO_FP_API | ||
| 245 | int PEM_ASN1_write(i2d,name,fp, x, enc, kstr, klen, callback) | ||
| 246 | int (*i2d)(); | ||
| 247 | char *name; | ||
| 248 | FILE *fp; | ||
| 249 | char *x; | ||
| 250 | EVP_CIPHER *enc; | ||
| 251 | unsigned char *kstr; | ||
| 252 | int klen; | ||
| 253 | int (*callback)(); | ||
| 254 | { | ||
| 255 | BIO *b; | ||
| 256 | int ret; | ||
| 257 | |||
| 258 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 259 | { | ||
| 260 | PEMerr(PEM_F_PEM_ASN1_WRITE,ERR_R_BUF_LIB); | ||
| 261 | return(0); | ||
| 262 | } | ||
| 263 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 264 | ret=PEM_ASN1_write_bio(i2d,name,b,x,enc,kstr,klen,callback); | ||
| 265 | BIO_free(b); | ||
| 266 | return(ret); | ||
| 267 | } | ||
| 268 | #endif | ||
| 269 | |||
| 270 | int PEM_ASN1_write_bio(i2d,name,bp, x, enc, kstr, klen, callback) | ||
| 271 | int (*i2d)(); | ||
| 272 | char *name; | ||
| 273 | BIO *bp; | ||
| 274 | char *x; | ||
| 275 | EVP_CIPHER *enc; | ||
| 276 | unsigned char *kstr; | ||
| 277 | int klen; | ||
| 278 | int (*callback)(); | ||
| 279 | { | ||
| 280 | EVP_CIPHER_CTX ctx; | ||
| 281 | int dsize=0,i,j,ret=0; | ||
| 282 | unsigned char *p,*data=NULL; | ||
| 283 | char *objstr=NULL; | ||
| 284 | #define PEM_BUFSIZE 1024 | ||
| 285 | char buf[PEM_BUFSIZE]; | ||
| 286 | unsigned char key[EVP_MAX_KEY_LENGTH]; | ||
| 287 | unsigned char iv[EVP_MAX_IV_LENGTH]; | ||
| 288 | |||
| 289 | if (enc != NULL) | ||
| 290 | { | ||
| 291 | objstr=OBJ_nid2sn(EVP_CIPHER_nid(enc)); | ||
| 292 | if (objstr == NULL) | ||
| 293 | { | ||
| 294 | PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER); | ||
| 295 | goto err; | ||
| 296 | } | ||
| 297 | } | ||
| 298 | |||
| 299 | if ((dsize=i2d(x,NULL)) < 0) | ||
| 300 | { | ||
| 301 | PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,ERR_R_MALLOC_FAILURE); | ||
| 302 | dsize=0; | ||
| 303 | goto err; | ||
| 304 | } | ||
| 305 | /* dzise + 8 bytes are needed */ | ||
| 306 | data=(unsigned char *)Malloc((unsigned int)dsize+20); | ||
| 307 | if (data == NULL) | ||
| 308 | { | ||
| 309 | PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,ERR_R_MALLOC_FAILURE); | ||
| 310 | goto err; | ||
| 311 | } | ||
| 312 | p=data; | ||
| 313 | i=i2d(x,&p); | ||
| 314 | |||
| 315 | if (enc != NULL) | ||
| 316 | { | ||
| 317 | if (kstr == NULL) | ||
| 318 | { | ||
| 319 | if (callback == NULL) | ||
| 320 | klen=def_callback(buf,PEM_BUFSIZE,1); | ||
| 321 | else | ||
| 322 | klen=(*callback)(buf,PEM_BUFSIZE,1); | ||
| 323 | if (klen <= 0) | ||
| 324 | { | ||
| 325 | PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_READ_KEY); | ||
| 326 | goto err; | ||
| 327 | } | ||
| 328 | kstr=(unsigned char *)buf; | ||
| 329 | } | ||
| 330 | RAND_seed(data,i);/* put in the RSA key. */ | ||
| 331 | RAND_bytes(iv,8); /* Generate a salt */ | ||
| 332 | /* The 'iv' is used as the iv and as a salt. It is | ||
| 333 | * NOT taken from the BytesToKey function */ | ||
| 334 | EVP_BytesToKey(enc,EVP_md5(),iv,kstr,klen,1,key,NULL); | ||
| 335 | |||
| 336 | if (kstr == (unsigned char *)buf) memset(buf,0,PEM_BUFSIZE); | ||
| 337 | |||
| 338 | buf[0]='\0'; | ||
| 339 | PEM_proc_type(buf,PEM_TYPE_ENCRYPTED); | ||
| 340 | PEM_dek_info(buf,objstr,8,(char *)iv); | ||
| 341 | /* k=strlen(buf); */ | ||
| 342 | |||
| 343 | EVP_EncryptInit(&ctx,enc,key,iv); | ||
| 344 | EVP_EncryptUpdate(&ctx,data,&j,data,i); | ||
| 345 | EVP_EncryptFinal(&ctx,&(data[j]),&i); | ||
| 346 | i+=j; | ||
| 347 | ret=1; | ||
| 348 | } | ||
| 349 | else | ||
| 350 | { | ||
| 351 | ret=1; | ||
| 352 | buf[0]='\0'; | ||
| 353 | } | ||
| 354 | i=PEM_write_bio(bp,name,buf,data,i); | ||
| 355 | if (i <= 0) ret=0; | ||
| 356 | err: | ||
| 357 | memset(key,0,sizeof(key)); | ||
| 358 | memset(iv,0,sizeof(iv)); | ||
| 359 | memset((char *)&ctx,0,sizeof(ctx)); | ||
| 360 | memset(buf,0,PEM_BUFSIZE); | ||
| 361 | memset(data,0,(unsigned int)dsize); | ||
| 362 | Free(data); | ||
| 363 | return(ret); | ||
| 364 | } | ||
| 365 | |||
| 366 | int PEM_do_header(cipher, data, plen, callback) | ||
| 367 | EVP_CIPHER_INFO *cipher; | ||
| 368 | unsigned char *data; | ||
| 369 | long *plen; | ||
| 370 | int (*callback)(); | ||
| 371 | { | ||
| 372 | int i,j,o,klen; | ||
| 373 | long len; | ||
| 374 | EVP_CIPHER_CTX ctx; | ||
| 375 | unsigned char key[EVP_MAX_KEY_LENGTH]; | ||
| 376 | char buf[PEM_BUFSIZE]; | ||
| 377 | |||
| 378 | len= *plen; | ||
| 379 | |||
| 380 | if (cipher->cipher == NULL) return(1); | ||
| 381 | if (callback == NULL) | ||
| 382 | klen=def_callback(buf,PEM_BUFSIZE,0); | ||
| 383 | else | ||
| 384 | klen=callback(buf,PEM_BUFSIZE,0); | ||
| 385 | if (klen <= 0) | ||
| 386 | { | ||
| 387 | PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_PASSWORD_READ); | ||
| 388 | return(0); | ||
| 389 | } | ||
| 390 | EVP_BytesToKey(cipher->cipher,EVP_md5(),&(cipher->iv[0]), | ||
| 391 | (unsigned char *)buf,klen,1,key,NULL); | ||
| 392 | |||
| 393 | j=(int)len; | ||
| 394 | EVP_DecryptInit(&ctx,cipher->cipher,key,&(cipher->iv[0])); | ||
| 395 | EVP_DecryptUpdate(&ctx,data,&i,data,j); | ||
| 396 | o=EVP_DecryptFinal(&ctx,&(data[i]),&j); | ||
| 397 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
| 398 | memset((char *)buf,0,sizeof(buf)); | ||
| 399 | memset((char *)key,0,sizeof(key)); | ||
| 400 | j+=i; | ||
| 401 | if (!o) | ||
| 402 | { | ||
| 403 | PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_DECRYPT); | ||
| 404 | return(0); | ||
| 405 | } | ||
| 406 | *plen=j; | ||
| 407 | return(1); | ||
| 408 | } | ||
| 409 | |||
| 410 | int PEM_get_EVP_CIPHER_INFO(header,cipher) | ||
| 411 | char *header; | ||
| 412 | EVP_CIPHER_INFO *cipher; | ||
| 413 | { | ||
| 414 | int o; | ||
| 415 | EVP_CIPHER *enc=NULL; | ||
| 416 | char *p,c; | ||
| 417 | |||
| 418 | cipher->cipher=NULL; | ||
| 419 | if ((header == NULL) || (*header == '\0') || (*header == '\n')) | ||
| 420 | return(1); | ||
| 421 | if (strncmp(header,"Proc-Type: ",11) != 0) | ||
| 422 | { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_PROC_TYPE); return(0); } | ||
| 423 | header+=11; | ||
| 424 | if (*header != '4') return(0); header++; | ||
| 425 | if (*header != ',') return(0); header++; | ||
| 426 | if (strncmp(header,"ENCRYPTED",9) != 0) | ||
| 427 | { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_ENCRYPTED); return(0); } | ||
| 428 | for (; (*header != '\n') && (*header != '\0'); header++) | ||
| 429 | ; | ||
| 430 | if (*header == '\0') | ||
| 431 | { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_SHORT_HEADER); return(0); } | ||
| 432 | header++; | ||
| 433 | if (strncmp(header,"DEK-Info: ",10) != 0) | ||
| 434 | { PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_NOT_DEK_INFO); return(0); } | ||
| 435 | header+=10; | ||
| 436 | |||
| 437 | p=header; | ||
| 438 | for (;;) | ||
| 439 | { | ||
| 440 | c= *header; | ||
| 441 | if (!( ((c >= 'A') && (c <= 'Z')) || (c == '-') || | ||
| 442 | ((c >= '0') && (c <= '9')))) | ||
| 443 | break; | ||
| 444 | header++; | ||
| 445 | } | ||
| 446 | *header='\0'; | ||
| 447 | o=OBJ_sn2nid(p); | ||
| 448 | cipher->cipher=enc=EVP_get_cipherbyname(p); | ||
| 449 | *header=c; | ||
| 450 | header++; | ||
| 451 | |||
| 452 | if (enc == NULL) | ||
| 453 | { | ||
| 454 | PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_UNSUPPORTED_ENCRYPTION); | ||
| 455 | return(0); | ||
| 456 | } | ||
| 457 | if (!load_iv((unsigned char **)&header,&(cipher->iv[0]),8)) return(0); | ||
| 458 | |||
| 459 | return(1); | ||
| 460 | } | ||
| 461 | |||
| 462 | static int load_iv(fromp,to,num) | ||
| 463 | unsigned char **fromp,*to; | ||
| 464 | int num; | ||
| 465 | { | ||
| 466 | int v,i; | ||
| 467 | unsigned char *from; | ||
| 468 | |||
| 469 | from= *fromp; | ||
| 470 | for (i=0; i<num; i++) to[i]=0; | ||
| 471 | num*=2; | ||
| 472 | for (i=0; i<num; i++) | ||
| 473 | { | ||
| 474 | if ((*from >= '0') && (*from <= '9')) | ||
| 475 | v= *from-'0'; | ||
| 476 | else if ((*from >= 'A') && (*from <= 'F')) | ||
| 477 | v= *from-'A'+10; | ||
| 478 | else if ((*from >= 'a') && (*from <= 'f')) | ||
| 479 | v= *from-'a'+10; | ||
| 480 | else | ||
| 481 | { | ||
| 482 | PEMerr(PEM_F_LOAD_IV,PEM_R_BAD_IV_CHARS); | ||
| 483 | return(0); | ||
| 484 | } | ||
| 485 | from++; | ||
| 486 | to[i/2]|=v<<(long)((!(i&1))*4); | ||
| 487 | } | ||
| 488 | |||
| 489 | *fromp=from; | ||
| 490 | return(1); | ||
| 491 | } | ||
| 492 | |||
| 493 | #ifndef NO_FP_API | ||
| 494 | int PEM_write(fp, name, header, data,len) | ||
| 495 | FILE *fp; | ||
| 496 | char *name; | ||
| 497 | char *header; | ||
| 498 | unsigned char *data; | ||
| 499 | long len; | ||
| 500 | { | ||
| 501 | BIO *b; | ||
| 502 | int ret; | ||
| 503 | |||
| 504 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 505 | { | ||
| 506 | PEMerr(PEM_F_PEM_WRITE,ERR_R_BUF_LIB); | ||
| 507 | return(0); | ||
| 508 | } | ||
| 509 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 510 | ret=PEM_write_bio(b, name, header, data,len); | ||
| 511 | BIO_free(b); | ||
| 512 | return(ret); | ||
| 513 | } | ||
| 514 | #endif | ||
| 515 | |||
| 516 | int PEM_write_bio(bp, name, header, data,len) | ||
| 517 | BIO *bp; | ||
| 518 | char *name; | ||
| 519 | char *header; | ||
| 520 | unsigned char *data; | ||
| 521 | long len; | ||
| 522 | { | ||
| 523 | int nlen,n,i,j,outl; | ||
| 524 | unsigned char *buf; | ||
| 525 | EVP_ENCODE_CTX ctx; | ||
| 526 | int reason=ERR_R_BUF_LIB; | ||
| 527 | |||
| 528 | EVP_EncodeInit(&ctx); | ||
| 529 | nlen=strlen(name); | ||
| 530 | |||
| 531 | if ( (BIO_write(bp,"-----BEGIN ",11) != 11) || | ||
| 532 | (BIO_write(bp,name,nlen) != nlen) || | ||
| 533 | (BIO_write(bp,"-----\n",6) != 6)) | ||
| 534 | goto err; | ||
| 535 | |||
| 536 | i=strlen(header); | ||
| 537 | if (i > 0) | ||
| 538 | { | ||
| 539 | if ( (BIO_write(bp,header,i) != i) || | ||
| 540 | (BIO_write(bp,"\n",1) != 1)) | ||
| 541 | goto err; | ||
| 542 | } | ||
| 543 | |||
| 544 | buf=(unsigned char *)Malloc(PEM_BUFSIZE*8); | ||
| 545 | if (buf == NULL) | ||
| 546 | { | ||
| 547 | reason=ERR_R_MALLOC_FAILURE; | ||
| 548 | goto err; | ||
| 549 | } | ||
| 550 | |||
| 551 | i=j=0; | ||
| 552 | while (len > 0) | ||
| 553 | { | ||
| 554 | n=(int)((len>(PEM_BUFSIZE*5))?(PEM_BUFSIZE*5):len); | ||
| 555 | EVP_EncodeUpdate(&ctx,buf,&outl,&(data[j]),n); | ||
| 556 | if ((outl) && (BIO_write(bp,(char *)buf,outl) != outl)) | ||
| 557 | goto err; | ||
| 558 | i+=outl; | ||
| 559 | len-=n; | ||
| 560 | j+=n; | ||
| 561 | } | ||
| 562 | EVP_EncodeFinal(&ctx,buf,&outl); | ||
| 563 | if ((outl > 0) && (BIO_write(bp,(char *)buf,outl) != outl)) goto err; | ||
| 564 | Free(buf); | ||
| 565 | if ( (BIO_write(bp,"-----END ",9) != 9) || | ||
| 566 | (BIO_write(bp,name,nlen) != nlen) || | ||
| 567 | (BIO_write(bp,"-----\n",6) != 6)) | ||
| 568 | goto err; | ||
| 569 | return(i+outl); | ||
| 570 | err: | ||
| 571 | PEMerr(PEM_F_PEM_WRITE_BIO,reason); | ||
| 572 | return(0); | ||
| 573 | } | ||
| 574 | |||
| 575 | #ifndef NO_FP_API | ||
| 576 | int PEM_read(fp, name, header, data,len) | ||
| 577 | FILE *fp; | ||
| 578 | char **name; | ||
| 579 | char **header; | ||
| 580 | unsigned char **data; | ||
| 581 | long *len; | ||
| 582 | { | ||
| 583 | BIO *b; | ||
| 584 | int ret; | ||
| 585 | |||
| 586 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 587 | { | ||
| 588 | PEMerr(PEM_F_PEM_READ,ERR_R_BUF_LIB); | ||
| 589 | return(0); | ||
| 590 | } | ||
| 591 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 592 | ret=PEM_read_bio(b, name, header, data,len); | ||
| 593 | BIO_free(b); | ||
| 594 | return(ret); | ||
| 595 | } | ||
| 596 | #endif | ||
| 597 | |||
| 598 | int PEM_read_bio(bp, name, header, data, len) | ||
| 599 | BIO *bp; | ||
| 600 | char **name; | ||
| 601 | char **header; | ||
| 602 | unsigned char **data; | ||
| 603 | long *len; | ||
| 604 | { | ||
| 605 | EVP_ENCODE_CTX ctx; | ||
| 606 | int end=0,i,k,bl=0,hl=0,nohead=0; | ||
| 607 | char buf[256]; | ||
| 608 | BUF_MEM *nameB; | ||
| 609 | BUF_MEM *headerB; | ||
| 610 | BUF_MEM *dataB,*tmpB; | ||
| 611 | |||
| 612 | nameB=BUF_MEM_new(); | ||
| 613 | headerB=BUF_MEM_new(); | ||
| 614 | dataB=BUF_MEM_new(); | ||
| 615 | if ((nameB == NULL) || (headerB == NULL) || (dataB == NULL)) | ||
| 616 | { | ||
| 617 | PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); | ||
| 618 | return(0); | ||
| 619 | } | ||
| 620 | |||
| 621 | buf[254]='\0'; | ||
| 622 | for (;;) | ||
| 623 | { | ||
| 624 | i=BIO_gets(bp,buf,254); | ||
| 625 | |||
| 626 | if (i <= 0) | ||
| 627 | { | ||
| 628 | PEMerr(PEM_F_PEM_READ_BIO,PEM_R_NO_START_LINE); | ||
| 629 | goto err; | ||
| 630 | } | ||
| 631 | |||
| 632 | while ((i >= 0) && (buf[i] <= ' ')) i--; | ||
| 633 | buf[++i]='\n'; buf[++i]='\0'; | ||
| 634 | |||
| 635 | if (strncmp(buf,"-----BEGIN ",11) == 0) | ||
| 636 | { | ||
| 637 | i=strlen(&(buf[11])); | ||
| 638 | |||
| 639 | if (strncmp(&(buf[11+i-6]),"-----\n",6) != 0) | ||
| 640 | continue; | ||
| 641 | if (!BUF_MEM_grow(nameB,i+9)) | ||
| 642 | { | ||
| 643 | PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); | ||
| 644 | goto err; | ||
| 645 | } | ||
| 646 | strncpy(nameB->data,&(buf[11]),(unsigned int)i-6); | ||
| 647 | nameB->data[i-6]='\0'; | ||
| 648 | break; | ||
| 649 | } | ||
| 650 | } | ||
| 651 | hl=0; | ||
| 652 | if (!BUF_MEM_grow(headerB,256)) | ||
| 653 | { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; } | ||
| 654 | headerB->data[0]='\0'; | ||
| 655 | for (;;) | ||
| 656 | { | ||
| 657 | i=BIO_gets(bp,buf,254); | ||
| 658 | if (i <= 0) break; | ||
| 659 | |||
| 660 | while ((i >= 0) && (buf[i] <= ' ')) i--; | ||
| 661 | buf[++i]='\n'; buf[++i]='\0'; | ||
| 662 | |||
| 663 | if (buf[0] == '\n') break; | ||
| 664 | if (!BUF_MEM_grow(headerB,hl+i+9)) | ||
| 665 | { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; } | ||
| 666 | if (strncmp(buf,"-----END ",9) == 0) | ||
| 667 | { | ||
| 668 | nohead=1; | ||
| 669 | break; | ||
| 670 | } | ||
| 671 | strncpy(&(headerB->data[hl]),buf,(unsigned int)i); | ||
| 672 | headerB->data[hl+i]='\0'; | ||
| 673 | hl+=i; | ||
| 674 | } | ||
| 675 | |||
| 676 | bl=0; | ||
| 677 | if (!BUF_MEM_grow(dataB,1024)) | ||
| 678 | { PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; } | ||
| 679 | dataB->data[0]='\0'; | ||
| 680 | if (!nohead) | ||
| 681 | { | ||
| 682 | for (;;) | ||
| 683 | { | ||
| 684 | i=BIO_gets(bp,buf,254); | ||
| 685 | if (i <= 0) break; | ||
| 686 | |||
| 687 | while ((i >= 0) && (buf[i] <= ' ')) i--; | ||
| 688 | buf[++i]='\n'; buf[++i]='\0'; | ||
| 689 | |||
| 690 | if (i != 65) end=1; | ||
| 691 | if (strncmp(buf,"-----END ",9) == 0) | ||
| 692 | break; | ||
| 693 | if (i > 65) break; | ||
| 694 | if (!BUF_MEM_grow(dataB,i+bl+9)) | ||
| 695 | { | ||
| 696 | PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); | ||
| 697 | goto err; | ||
| 698 | } | ||
| 699 | strncpy(&(dataB->data[bl]),buf,(unsigned int)i); | ||
| 700 | dataB->data[bl+i]='\0'; | ||
| 701 | bl+=i; | ||
| 702 | if (end) | ||
| 703 | { | ||
| 704 | buf[0]='\0'; | ||
| 705 | i=BIO_gets(bp,buf,254); | ||
| 706 | if (i <= 0) break; | ||
| 707 | |||
| 708 | while ((i >= 0) && (buf[i] <= ' ')) i--; | ||
| 709 | buf[++i]='\n'; buf[++i]='\0'; | ||
| 710 | |||
| 711 | break; | ||
| 712 | } | ||
| 713 | } | ||
| 714 | } | ||
| 715 | else | ||
| 716 | { | ||
| 717 | tmpB=headerB; | ||
| 718 | headerB=dataB; | ||
| 719 | dataB=tmpB; | ||
| 720 | bl=hl; | ||
| 721 | } | ||
| 722 | i=strlen(nameB->data); | ||
| 723 | if ( (strncmp(buf,"-----END ",9) != 0) || | ||
| 724 | (strncmp(nameB->data,&(buf[9]),(unsigned int)i) != 0) || | ||
| 725 | (strncmp(&(buf[9+i]),"-----\n",6) != 0)) | ||
| 726 | { | ||
| 727 | PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_END_LINE); | ||
| 728 | goto err; | ||
| 729 | } | ||
| 730 | |||
| 731 | EVP_DecodeInit(&ctx); | ||
| 732 | i=EVP_DecodeUpdate(&ctx, | ||
| 733 | (unsigned char *)dataB->data,&bl, | ||
| 734 | (unsigned char *)dataB->data,bl); | ||
| 735 | if (i < 0) | ||
| 736 | { | ||
| 737 | PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_BASE64_DECODE); | ||
| 738 | goto err; | ||
| 739 | } | ||
| 740 | i=EVP_DecodeFinal(&ctx,(unsigned char *)&(dataB->data[bl]),&k); | ||
| 741 | if (i < 0) | ||
| 742 | { | ||
| 743 | PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_BASE64_DECODE); | ||
| 744 | goto err; | ||
| 745 | } | ||
| 746 | bl+=k; | ||
| 747 | |||
| 748 | if (bl == 0) goto err; | ||
| 749 | *name=nameB->data; | ||
| 750 | *header=headerB->data; | ||
| 751 | *data=(unsigned char *)dataB->data; | ||
| 752 | *len=bl; | ||
| 753 | Free(nameB); | ||
| 754 | Free(headerB); | ||
| 755 | Free(dataB); | ||
| 756 | return(1); | ||
| 757 | err: | ||
| 758 | BUF_MEM_free(nameB); | ||
| 759 | BUF_MEM_free(headerB); | ||
| 760 | BUF_MEM_free(dataB); | ||
| 761 | return(0); | ||
| 762 | } | ||
diff --git a/src/lib/libcrypto/pem/pem_seal.c b/src/lib/libcrypto/pem/pem_seal.c new file mode 100644 index 0000000000..b4b36df453 --- /dev/null +++ b/src/lib/libcrypto/pem/pem_seal.c | |||
| @@ -0,0 +1,191 @@ | |||
| 1 | /* crypto/pem/pem_seal.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 "evp.h" | ||
| 62 | #include "rand.h" | ||
| 63 | #include "objects.h" | ||
| 64 | #include "x509.h" | ||
| 65 | #include "pem.h" | ||
| 66 | |||
| 67 | int PEM_SealInit(ctx,type,md_type,ek,ekl,iv,pubk,npubk) | ||
| 68 | PEM_ENCODE_SEAL_CTX *ctx; | ||
| 69 | EVP_CIPHER *type; | ||
| 70 | EVP_MD *md_type; | ||
| 71 | unsigned char **ek; | ||
| 72 | int *ekl; | ||
| 73 | unsigned char *iv; | ||
| 74 | EVP_PKEY **pubk; | ||
| 75 | int npubk; | ||
| 76 | { | ||
| 77 | unsigned char key[EVP_MAX_KEY_LENGTH]; | ||
| 78 | int ret= -1; | ||
| 79 | int i,j,max=0; | ||
| 80 | char *s=NULL; | ||
| 81 | |||
| 82 | for (i=0; i<npubk; i++) | ||
| 83 | { | ||
| 84 | if (pubk[i]->type != EVP_PKEY_RSA) | ||
| 85 | { | ||
| 86 | PEMerr(PEM_F_PEM_SEALINIT,PEM_R_PUBLIC_KEY_NO_RSA); | ||
| 87 | goto err; | ||
| 88 | } | ||
| 89 | j=RSA_size(pubk[i]->pkey.rsa); | ||
| 90 | if (j > max) max=j; | ||
| 91 | } | ||
| 92 | s=(char *)Malloc(max*2); | ||
| 93 | if (s == NULL) | ||
| 94 | { | ||
| 95 | PEMerr(PEM_F_PEM_SEALINIT,ERR_R_MALLOC_FAILURE); | ||
| 96 | goto err; | ||
| 97 | } | ||
| 98 | |||
| 99 | EVP_EncodeInit(&(ctx->encode)); | ||
| 100 | EVP_SignInit(&(ctx->md),md_type); | ||
| 101 | |||
| 102 | ret=EVP_SealInit(&(ctx->cipher),type,ek,ekl,iv,pubk,npubk); | ||
| 103 | if (!ret) goto err; | ||
| 104 | |||
| 105 | /* base64 encode the keys */ | ||
| 106 | for (i=0; i<npubk; i++) | ||
| 107 | { | ||
| 108 | j=EVP_EncodeBlock((unsigned char *)s,ek[i], | ||
| 109 | RSA_size(pubk[i]->pkey.rsa)); | ||
| 110 | ekl[i]=j; | ||
| 111 | memcpy(ek[i],s,j+1); | ||
| 112 | } | ||
| 113 | |||
| 114 | ret=npubk; | ||
| 115 | err: | ||
| 116 | if (s != NULL) Free(s); | ||
| 117 | memset(key,0,EVP_MAX_KEY_LENGTH); | ||
| 118 | return(ret); | ||
| 119 | } | ||
| 120 | |||
| 121 | void PEM_SealUpdate(ctx,out,outl,in,inl) | ||
| 122 | PEM_ENCODE_SEAL_CTX *ctx; | ||
| 123 | unsigned char *out; | ||
| 124 | int *outl; | ||
| 125 | unsigned char *in; | ||
| 126 | int inl; | ||
| 127 | { | ||
| 128 | unsigned char buffer[1600]; | ||
| 129 | int i,j; | ||
| 130 | |||
| 131 | *outl=0; | ||
| 132 | EVP_SignUpdate(&(ctx->md),in,inl); | ||
| 133 | for (;;) | ||
| 134 | { | ||
| 135 | if (inl <= 0) break; | ||
| 136 | if (inl > 1200) | ||
| 137 | i=1200; | ||
| 138 | else | ||
| 139 | i=inl; | ||
| 140 | EVP_EncryptUpdate(&(ctx->cipher),buffer,&j,in,i); | ||
| 141 | EVP_EncodeUpdate(&(ctx->encode),out,&j,buffer,j); | ||
| 142 | *outl+=j; | ||
| 143 | out+=j; | ||
| 144 | in+=i; | ||
| 145 | inl-=i; | ||
| 146 | } | ||
| 147 | } | ||
| 148 | |||
| 149 | int PEM_SealFinal(ctx,sig,sigl,out,outl,priv) | ||
| 150 | PEM_ENCODE_SEAL_CTX *ctx; | ||
| 151 | unsigned char *sig; | ||
| 152 | int *sigl; | ||
| 153 | unsigned char *out; | ||
| 154 | int *outl; | ||
| 155 | EVP_PKEY *priv; | ||
| 156 | { | ||
| 157 | unsigned char *s=NULL; | ||
| 158 | int ret=0,j; | ||
| 159 | unsigned int i; | ||
| 160 | |||
| 161 | if (priv->type != EVP_PKEY_RSA) | ||
| 162 | { | ||
| 163 | PEMerr(PEM_F_PEM_SEALFINAL,PEM_R_PUBLIC_KEY_NO_RSA); | ||
| 164 | goto err; | ||
| 165 | } | ||
| 166 | i=RSA_size(priv->pkey.rsa); | ||
| 167 | if (i < 100) i=100; | ||
| 168 | s=(unsigned char *)Malloc(i*2); | ||
| 169 | if (s == NULL) | ||
| 170 | { | ||
| 171 | PEMerr(PEM_F_PEM_SEALFINAL,ERR_R_MALLOC_FAILURE); | ||
| 172 | goto err; | ||
| 173 | } | ||
| 174 | |||
| 175 | EVP_EncryptFinal(&(ctx->cipher),s,(int *)&i); | ||
| 176 | EVP_EncodeUpdate(&(ctx->encode),out,&j,s,i); | ||
| 177 | *outl=j; | ||
| 178 | out+=j; | ||
| 179 | EVP_EncodeFinal(&(ctx->encode),out,&j); | ||
| 180 | *outl+=j; | ||
| 181 | |||
| 182 | if (!EVP_SignFinal(&(ctx->md),s,&i,priv)) goto err; | ||
| 183 | *sigl=EVP_EncodeBlock(sig,s,i); | ||
| 184 | |||
| 185 | ret=1; | ||
| 186 | err: | ||
| 187 | memset((char *)&(ctx->md),0,sizeof(ctx->md)); | ||
| 188 | memset((char *)&(ctx->cipher),0,sizeof(ctx->cipher)); | ||
| 189 | if (s != NULL) Free(s); | ||
| 190 | return(ret); | ||
| 191 | } | ||
diff --git a/src/lib/libcrypto/pem/pem_sign.c b/src/lib/libcrypto/pem/pem_sign.c new file mode 100644 index 0000000000..d56f9f9e14 --- /dev/null +++ b/src/lib/libcrypto/pem/pem_sign.c | |||
| @@ -0,0 +1,109 @@ | |||
| 1 | /* crypto/pem/pem_sign.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 "rand.h" | ||
| 62 | #include "evp.h" | ||
| 63 | #include "objects.h" | ||
| 64 | #include "x509.h" | ||
| 65 | #include "pem.h" | ||
| 66 | |||
| 67 | void PEM_SignInit(ctx,type) | ||
| 68 | EVP_MD_CTX *ctx; | ||
| 69 | EVP_MD *type; | ||
| 70 | { | ||
| 71 | EVP_DigestInit(ctx,type); | ||
| 72 | } | ||
| 73 | |||
| 74 | void PEM_SignUpdate(ctx,data,count) | ||
| 75 | EVP_MD_CTX *ctx; | ||
| 76 | unsigned char *data; | ||
| 77 | unsigned int count; | ||
| 78 | { | ||
| 79 | EVP_DigestUpdate(ctx,data,count); | ||
| 80 | } | ||
| 81 | |||
| 82 | int PEM_SignFinal(ctx,sigret,siglen,pkey) | ||
| 83 | EVP_MD_CTX *ctx; | ||
| 84 | unsigned char *sigret; | ||
| 85 | unsigned int *siglen; | ||
| 86 | EVP_PKEY *pkey; | ||
| 87 | { | ||
| 88 | unsigned char *m; | ||
| 89 | int i,ret=0; | ||
| 90 | unsigned int m_len; | ||
| 91 | |||
| 92 | m=(unsigned char *)Malloc(EVP_PKEY_size(pkey)+2); | ||
| 93 | if (m == NULL) | ||
| 94 | { | ||
| 95 | PEMerr(PEM_F_PEM_SIGNFINAL,ERR_R_MALLOC_FAILURE); | ||
| 96 | goto err; | ||
| 97 | } | ||
| 98 | |||
| 99 | if (EVP_SignFinal(ctx,m,&m_len,pkey) <= 0) goto err; | ||
| 100 | |||
| 101 | i=EVP_EncodeBlock(sigret,m,m_len); | ||
| 102 | *siglen=i; | ||
| 103 | ret=1; | ||
| 104 | err: | ||
| 105 | /* ctx has been zeroed by EVP_SignFinal() */ | ||
| 106 | if (m != NULL) Free(m); | ||
| 107 | return(ret); | ||
| 108 | } | ||
| 109 | |||
diff --git a/src/lib/libcrypto/pem/pkcs7.lis b/src/lib/libcrypto/pem/pkcs7.lis new file mode 100644 index 0000000000..be90c5d87f --- /dev/null +++ b/src/lib/libcrypto/pem/pkcs7.lis | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | 21 0:d=0 hl=2 l= 0 cons: univ: SEQUENCE | ||
| 2 | 00 2:d=0 hl=2 l= 9 prim: univ: OBJECT_IDENTIFIER :pkcs-7-signedData | ||
| 3 | 21 13:d=0 hl=2 l= 0 cons: cont: 00 # explicit tag | ||
| 4 | 21 15:d=0 hl=2 l= 0 cons: univ: SEQUENCE | ||
| 5 | 00 17:d=0 hl=2 l= 1 prim: univ: INTEGER # version | ||
| 6 | 20 20:d=0 hl=2 l= 0 cons: univ: SET | ||
| 7 | 21 22:d=0 hl=2 l= 0 cons: univ: SEQUENCE | ||
| 8 | 00 24:d=0 hl=2 l= 9 prim: univ: OBJECT_IDENTIFIER :pkcs-7-data | ||
| 9 | 00 35:d=0 hl=2 l= 0 prim: univ: EOC | ||
| 10 | 21 37:d=0 hl=2 l= 0 cons: cont: 00 # cert tag | ||
| 11 | 20 39:d=0 hl=4 l=545 cons: univ: SEQUENCE | ||
| 12 | 20 588:d=0 hl=4 l=524 cons: univ: SEQUENCE | ||
| 13 | 00 1116:d=0 hl=2 l= 0 prim: univ: EOC | ||
| 14 | 21 1118:d=0 hl=2 l= 0 cons: cont: 01 # crl tag | ||
| 15 | 20 1120:d=0 hl=4 l=653 cons: univ: SEQUENCE | ||
| 16 | 20 1777:d=0 hl=4 l=285 cons: univ: SEQUENCE | ||
| 17 | 00 2066:d=0 hl=2 l= 0 prim: univ: EOC | ||
| 18 | 21 2068:d=0 hl=2 l= 0 cons: univ: SET # signers | ||
| 19 | 00 2070:d=0 hl=2 l= 0 prim: univ: EOC | ||
| 20 | 00 2072:d=0 hl=2 l= 0 prim: univ: EOC | ||
| 21 | 00 2074:d=0 hl=2 l= 0 prim: univ: EOC | ||
| 22 | 00 2076:d=0 hl=2 l= 0 prim: univ: EOC | ||
diff --git a/src/lib/libcrypto/perlasm/cbc.pl b/src/lib/libcrypto/perlasm/cbc.pl new file mode 100644 index 0000000000..2789305790 --- /dev/null +++ b/src/lib/libcrypto/perlasm/cbc.pl | |||
| @@ -0,0 +1,342 @@ | |||
| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | # void des_ncbc_encrypt(input, output, length, schedule, ivec, enc) | ||
| 4 | # des_cblock (*input); | ||
| 5 | # des_cblock (*output); | ||
| 6 | # long length; | ||
| 7 | # des_key_schedule schedule; | ||
| 8 | # des_cblock (*ivec); | ||
| 9 | # int enc; | ||
| 10 | # | ||
| 11 | # calls | ||
| 12 | # des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); | ||
| 13 | # | ||
| 14 | |||
| 15 | #&cbc("des_ncbc_encrypt","des_encrypt",0); | ||
| 16 | #&cbc("BF_cbc_encrypt","BF_encrypt","BF_encrypt", | ||
| 17 | # 1,4,5,3,5,-1); | ||
| 18 | #&cbc("des_ncbc_encrypt","des_encrypt","des_encrypt", | ||
| 19 | # 0,4,5,3,5,-1); | ||
| 20 | #&cbc("des_ede3_cbc_encrypt","des_encrypt3","des_decrypt3", | ||
| 21 | # 0,6,7,3,4,5); | ||
| 22 | # | ||
| 23 | # When doing a cipher that needs bigendian order, | ||
| 24 | # for encrypt, the iv is kept in bigendian form, | ||
| 25 | # while for decrypt, it is kept in little endian. | ||
| 26 | sub cbc | ||
| 27 | { | ||
| 28 | local($name,$enc_func,$dec_func,$swap,$iv_off,$enc_off,$p1,$p2,$p3)=@_; | ||
| 29 | # name is the function name | ||
| 30 | # enc_func and dec_func and the functions to call for encrypt/decrypt | ||
| 31 | # swap is true if byte order needs to be reversed | ||
| 32 | # iv_off is parameter number for the iv | ||
| 33 | # enc_off is parameter number for the encrypt/decrypt flag | ||
| 34 | # p1,p2,p3 are the offsets for parameters to be passed to the | ||
| 35 | # underlying calls. | ||
| 36 | |||
| 37 | &function_begin_B($name,""); | ||
| 38 | &comment(""); | ||
| 39 | |||
| 40 | $in="esi"; | ||
| 41 | $out="edi"; | ||
| 42 | $count="ebp"; | ||
| 43 | |||
| 44 | &push("ebp"); | ||
| 45 | &push("ebx"); | ||
| 46 | &push("esi"); | ||
| 47 | &push("edi"); | ||
| 48 | |||
| 49 | $data_off=4; | ||
| 50 | $data_off+=4 if ($p1 > 0); | ||
| 51 | $data_off+=4 if ($p2 > 0); | ||
| 52 | $data_off+=4 if ($p3 > 0); | ||
| 53 | |||
| 54 | &mov($count, &wparam(2)); # length | ||
| 55 | |||
| 56 | &comment("getting iv ptr from parameter $iv_off"); | ||
| 57 | &mov("ebx", &wparam($iv_off)); # Get iv ptr | ||
| 58 | |||
| 59 | &mov($in, &DWP(0,"ebx","",0));# iv[0] | ||
| 60 | &mov($out, &DWP(4,"ebx","",0));# iv[1] | ||
| 61 | |||
| 62 | &push($out); | ||
| 63 | &push($in); | ||
| 64 | &push($out); # used in decrypt for iv[1] | ||
| 65 | &push($in); # used in decrypt for iv[0] | ||
| 66 | |||
| 67 | &mov("ebx", "esp"); # This is the address of tin[2] | ||
| 68 | |||
| 69 | &mov($in, &wparam(0)); # in | ||
| 70 | &mov($out, &wparam(1)); # out | ||
| 71 | |||
| 72 | # We have loaded them all, how lets push things | ||
| 73 | &comment("getting encrypt flag from parameter $enc_off"); | ||
| 74 | &mov("ecx", &wparam($enc_off)); # Get enc flag | ||
| 75 | if ($p3 > 0) | ||
| 76 | { | ||
| 77 | &comment("get and push parameter $p3"); | ||
| 78 | if ($enc_off != $p3) | ||
| 79 | { &mov("eax", &wparam($p3)); &push("eax"); } | ||
| 80 | else { &push("ecx"); } | ||
| 81 | } | ||
| 82 | if ($p2 > 0) | ||
| 83 | { | ||
| 84 | &comment("get and push parameter $p2"); | ||
| 85 | if ($enc_off != $p2) | ||
| 86 | { &mov("eax", &wparam($p2)); &push("eax"); } | ||
| 87 | else { &push("ecx"); } | ||
| 88 | } | ||
| 89 | if ($p1 > 0) | ||
| 90 | { | ||
| 91 | &comment("get and push parameter $p1"); | ||
| 92 | if ($enc_off != $p1) | ||
| 93 | { &mov("eax", &wparam($p1)); &push("eax"); } | ||
| 94 | else { &push("ecx"); } | ||
| 95 | } | ||
| 96 | &push("ebx"); # push data/iv | ||
| 97 | |||
| 98 | &cmp("ecx",0); | ||
| 99 | &jz(&label("decrypt")); | ||
| 100 | |||
| 101 | &and($count,0xfffffff8); | ||
| 102 | &mov("eax", &DWP($data_off,"esp","",0)); # load iv[0] | ||
| 103 | &mov("ebx", &DWP($data_off+4,"esp","",0)); # load iv[1] | ||
| 104 | |||
| 105 | &jz(&label("encrypt_finish")); | ||
| 106 | |||
| 107 | ############################################################# | ||
| 108 | |||
| 109 | &set_label("encrypt_loop"); | ||
| 110 | # encrypt start | ||
| 111 | # "eax" and "ebx" hold iv (or the last cipher text) | ||
| 112 | |||
| 113 | &mov("ecx", &DWP(0,$in,"",0)); # load first 4 bytes | ||
| 114 | &mov("edx", &DWP(4,$in,"",0)); # second 4 bytes | ||
| 115 | |||
| 116 | &xor("eax", "ecx"); | ||
| 117 | &xor("ebx", "edx"); | ||
| 118 | |||
| 119 | &bswap("eax") if $swap; | ||
| 120 | &bswap("ebx") if $swap; | ||
| 121 | |||
| 122 | &mov(&DWP($data_off,"esp","",0), "eax"); # put in array for call | ||
| 123 | &mov(&DWP($data_off+4,"esp","",0), "ebx"); # | ||
| 124 | |||
| 125 | &call($enc_func); | ||
| 126 | |||
| 127 | &mov("eax", &DWP($data_off,"esp","",0)); | ||
| 128 | &mov("ebx", &DWP($data_off+4,"esp","",0)); | ||
| 129 | |||
| 130 | &bswap("eax") if $swap; | ||
| 131 | &bswap("ebx") if $swap; | ||
| 132 | |||
| 133 | &mov(&DWP(0,$out,"",0),"eax"); | ||
| 134 | &mov(&DWP(4,$out,"",0),"ebx"); | ||
| 135 | |||
| 136 | # eax and ebx are the next iv. | ||
| 137 | |||
| 138 | &add($in, 8); | ||
| 139 | &add($out, 8); | ||
| 140 | |||
| 141 | &sub($count, 8); | ||
| 142 | &jnz(&label("encrypt_loop")); | ||
| 143 | |||
| 144 | ###################################################################3 | ||
| 145 | &set_label("encrypt_finish"); | ||
| 146 | &mov($count, &wparam(2)); # length | ||
| 147 | &and($count, 7); | ||
| 148 | &jz(&label("finish")); | ||
| 149 | &xor("ecx","ecx"); | ||
| 150 | &xor("edx","edx"); | ||
| 151 | &mov($count,&DWP(&label("cbc_enc_jmp_table"),"",$count,4)); | ||
| 152 | &jmp_ptr($count); | ||
| 153 | |||
| 154 | &set_label("ej7"); | ||
| 155 | &xor("edx", "edx") if $ppro; # ppro friendly | ||
| 156 | &movb(&HB("edx"), &BP(6,$in,"",0)); | ||
| 157 | &shl("edx",8); | ||
| 158 | &set_label("ej6"); | ||
| 159 | &movb(&HB("edx"), &BP(5,$in,"",0)); | ||
| 160 | &set_label("ej5"); | ||
| 161 | &movb(&LB("edx"), &BP(4,$in,"",0)); | ||
| 162 | &set_label("ej4"); | ||
| 163 | &mov("ecx", &DWP(0,$in,"",0)); | ||
| 164 | &jmp(&label("ejend")); | ||
| 165 | &set_label("ej3"); | ||
| 166 | &movb(&HB("ecx"), &BP(2,$in,"",0)); | ||
| 167 | &xor("ecx", "ecx") if $ppro; # ppro friendly | ||
| 168 | &shl("ecx",8); | ||
| 169 | &set_label("ej2"); | ||
| 170 | &movb(&HB("ecx"), &BP(1,$in,"",0)); | ||
| 171 | &set_label("ej1"); | ||
| 172 | &movb(&LB("ecx"), &BP(0,$in,"",0)); | ||
| 173 | &set_label("ejend"); | ||
| 174 | |||
| 175 | &xor("eax", "ecx"); | ||
| 176 | &xor("ebx", "edx"); | ||
| 177 | |||
| 178 | &bswap("eax") if $swap; | ||
| 179 | &bswap("ebx") if $swap; | ||
| 180 | |||
| 181 | &mov(&DWP($data_off,"esp","",0), "eax"); # put in array for call | ||
| 182 | &mov(&DWP($data_off+4,"esp","",0), "ebx"); # | ||
| 183 | |||
| 184 | &call($enc_func); | ||
| 185 | |||
| 186 | &mov("eax", &DWP($data_off,"esp","",0)); | ||
| 187 | &mov("ebx", &DWP($data_off+4,"esp","",0)); | ||
| 188 | |||
| 189 | &bswap("eax") if $swap; | ||
| 190 | &bswap("ebx") if $swap; | ||
| 191 | |||
| 192 | &mov(&DWP(0,$out,"",0),"eax"); | ||
| 193 | &mov(&DWP(4,$out,"",0),"ebx"); | ||
| 194 | |||
| 195 | &jmp(&label("finish")); | ||
| 196 | |||
| 197 | ############################################################# | ||
| 198 | ############################################################# | ||
| 199 | &set_label("decrypt",1); | ||
| 200 | # decrypt start | ||
| 201 | &and($count,0xfffffff8); | ||
| 202 | # The next 2 instructions are only for if the jz is taken | ||
| 203 | &mov("eax", &DWP($data_off+8,"esp","",0)); # get iv[0] | ||
| 204 | &mov("ebx", &DWP($data_off+12,"esp","",0)); # get iv[1] | ||
| 205 | &jz(&label("decrypt_finish")); | ||
| 206 | |||
| 207 | &set_label("decrypt_loop"); | ||
| 208 | &mov("eax", &DWP(0,$in,"",0)); # load first 4 bytes | ||
| 209 | &mov("ebx", &DWP(4,$in,"",0)); # second 4 bytes | ||
| 210 | |||
| 211 | &bswap("eax") if $swap; | ||
| 212 | &bswap("ebx") if $swap; | ||
| 213 | |||
| 214 | &mov(&DWP($data_off,"esp","",0), "eax"); # put back | ||
| 215 | &mov(&DWP($data_off+4,"esp","",0), "ebx"); # | ||
| 216 | |||
| 217 | &call($dec_func); | ||
| 218 | |||
| 219 | &mov("eax", &DWP($data_off,"esp","",0)); # get return | ||
| 220 | &mov("ebx", &DWP($data_off+4,"esp","",0)); # | ||
| 221 | |||
| 222 | &bswap("eax") if $swap; | ||
| 223 | &bswap("ebx") if $swap; | ||
| 224 | |||
| 225 | &mov("ecx", &DWP($data_off+8,"esp","",0)); # get iv[0] | ||
| 226 | &mov("edx", &DWP($data_off+12,"esp","",0)); # get iv[1] | ||
| 227 | |||
| 228 | &xor("ecx", "eax"); | ||
| 229 | &xor("edx", "ebx"); | ||
| 230 | |||
| 231 | &mov("eax", &DWP(0,$in,"",0)); # get old cipher text, | ||
| 232 | &mov("ebx", &DWP(4,$in,"",0)); # next iv actually | ||
| 233 | |||
| 234 | &mov(&DWP(0,$out,"",0),"ecx"); | ||
| 235 | &mov(&DWP(4,$out,"",0),"edx"); | ||
| 236 | |||
| 237 | &mov(&DWP($data_off+8,"esp","",0), "eax"); # save iv | ||
| 238 | &mov(&DWP($data_off+12,"esp","",0), "ebx"); # | ||
| 239 | |||
| 240 | &add($in, 8); | ||
| 241 | &add($out, 8); | ||
| 242 | |||
| 243 | &sub($count, 8); | ||
| 244 | &jnz(&label("decrypt_loop")); | ||
| 245 | ############################ ENDIT #######################3 | ||
| 246 | &set_label("decrypt_finish"); | ||
| 247 | &mov($count, &wparam(2)); # length | ||
| 248 | &and($count, 7); | ||
| 249 | &jz(&label("finish")); | ||
| 250 | |||
| 251 | &mov("eax", &DWP(0,$in,"",0)); # load first 4 bytes | ||
| 252 | &mov("ebx", &DWP(4,$in,"",0)); # second 4 bytes | ||
| 253 | |||
| 254 | &bswap("eax") if $swap; | ||
| 255 | &bswap("ebx") if $swap; | ||
| 256 | |||
| 257 | &mov(&DWP($data_off,"esp","",0), "eax"); # put back | ||
| 258 | &mov(&DWP($data_off+4,"esp","",0), "ebx"); # | ||
| 259 | |||
| 260 | &call($dec_func); | ||
| 261 | |||
| 262 | &mov("eax", &DWP($data_off,"esp","",0)); # get return | ||
| 263 | &mov("ebx", &DWP($data_off+4,"esp","",0)); # | ||
| 264 | |||
| 265 | &bswap("eax") if $swap; | ||
| 266 | &bswap("ebx") if $swap; | ||
| 267 | |||
| 268 | &mov("ecx", &DWP($data_off+8,"esp","",0)); # get iv[0] | ||
| 269 | &mov("edx", &DWP($data_off+12,"esp","",0)); # get iv[1] | ||
| 270 | |||
| 271 | &xor("ecx", "eax"); | ||
| 272 | &xor("edx", "ebx"); | ||
| 273 | |||
| 274 | # this is for when we exit | ||
| 275 | &mov("eax", &DWP(0,$in,"",0)); # get old cipher text, | ||
| 276 | &mov("ebx", &DWP(4,$in,"",0)); # next iv actually | ||
| 277 | |||
| 278 | &set_label("dj7"); | ||
| 279 | &rotr("edx", 16); | ||
| 280 | &movb(&BP(6,$out,"",0), &LB("edx")); | ||
| 281 | &shr("edx",16); | ||
| 282 | &set_label("dj6"); | ||
| 283 | &movb(&BP(5,$out,"",0), &HB("edx")); | ||
| 284 | &set_label("dj5"); | ||
| 285 | &movb(&BP(4,$out,"",0), &LB("edx")); | ||
| 286 | &set_label("dj4"); | ||
| 287 | &mov(&DWP(0,$out,"",0), "ecx"); | ||
| 288 | &jmp(&label("djend")); | ||
| 289 | &set_label("dj3"); | ||
| 290 | &rotr("ecx", 16); | ||
| 291 | &movb(&BP(2,$out,"",0), &LB("ecx")); | ||
| 292 | &shl("ecx",16); | ||
| 293 | &set_label("dj2"); | ||
| 294 | &movb(&BP(1,$in,"",0), &HB("ecx")); | ||
| 295 | &set_label("dj1"); | ||
| 296 | &movb(&BP(0,$in,"",0), &LB("ecx")); | ||
| 297 | &set_label("djend"); | ||
| 298 | |||
| 299 | # final iv is still in eax:ebx | ||
| 300 | &jmp(&label("finish")); | ||
| 301 | |||
| 302 | |||
| 303 | ############################ FINISH #######################3 | ||
| 304 | &set_label("finish",1); | ||
| 305 | &mov("ecx", &wparam($iv_off)); # Get iv ptr | ||
| 306 | |||
| 307 | ################################################# | ||
| 308 | $total=16+4; | ||
| 309 | $total+=4 if ($p1 > 0); | ||
| 310 | $total+=4 if ($p2 > 0); | ||
| 311 | $total+=4 if ($p3 > 0); | ||
| 312 | &add("esp",$total); | ||
| 313 | |||
| 314 | &mov(&DWP(0,"ecx","",0), "eax"); # save iv | ||
| 315 | &mov(&DWP(4,"ecx","",0), "ebx"); # save iv | ||
| 316 | |||
| 317 | &function_end_A($name); | ||
| 318 | |||
| 319 | &set_label("cbc_enc_jmp_table",1); | ||
| 320 | &data_word("0"); | ||
| 321 | &data_word(&label("ej1")); | ||
| 322 | &data_word(&label("ej2")); | ||
| 323 | &data_word(&label("ej3")); | ||
| 324 | &data_word(&label("ej4")); | ||
| 325 | &data_word(&label("ej5")); | ||
| 326 | &data_word(&label("ej6")); | ||
| 327 | &data_word(&label("ej7")); | ||
| 328 | &set_label("cbc_dec_jmp_table",1); | ||
| 329 | &data_word("0"); | ||
| 330 | &data_word(&label("dj1")); | ||
| 331 | &data_word(&label("dj2")); | ||
| 332 | &data_word(&label("dj3")); | ||
| 333 | &data_word(&label("dj4")); | ||
| 334 | &data_word(&label("dj5")); | ||
| 335 | &data_word(&label("dj6")); | ||
| 336 | &data_word(&label("dj7")); | ||
| 337 | |||
| 338 | &function_end_B($name); | ||
| 339 | |||
| 340 | } | ||
| 341 | |||
| 342 | 1; | ||
diff --git a/src/lib/libcrypto/perlasm/readme b/src/lib/libcrypto/perlasm/readme new file mode 100644 index 0000000000..f02bbee75a --- /dev/null +++ b/src/lib/libcrypto/perlasm/readme | |||
| @@ -0,0 +1,124 @@ | |||
| 1 | The perl scripts in this directory are my 'hack' to generate | ||
| 2 | multiple different assembler formats via the one origional script. | ||
| 3 | |||
| 4 | The way to use this library is to start with adding the path to this directory | ||
| 5 | and then include it. | ||
| 6 | |||
| 7 | push(@INC,"perlasm","../../perlasm"); | ||
| 8 | require "x86asm.pl"; | ||
| 9 | |||
| 10 | The first thing we do is setup the file and type of assember | ||
| 11 | |||
| 12 | &asm_init($ARGV[0],$0); | ||
| 13 | |||
| 14 | The first argument is the 'type'. Currently | ||
| 15 | 'cpp', 'sol', 'a.out', 'elf' or 'win32'. | ||
| 16 | Argument 2 is the file name. | ||
| 17 | |||
| 18 | The reciprocal function is | ||
| 19 | &asm_finish() which should be called at the end. | ||
| 20 | |||
| 21 | There are 2 main 'packages'. x86ms.pl, which is the microsoft assembler, | ||
| 22 | and x86unix.pl which is the unix (gas) version. | ||
| 23 | |||
| 24 | Functions of interest are: | ||
| 25 | &external_label("des_SPtrans"); declare and external variable | ||
| 26 | &LB(reg); Low byte for a register | ||
| 27 | &HB(reg); High byte for a register | ||
| 28 | &BP(off,base,index,scale) Byte pointer addressing | ||
| 29 | &DWP(off,base,index,scale) Word pointer addressing | ||
| 30 | &stack_push(num) Basically a 'sub esp, num*4' with extra | ||
| 31 | &stack_pop(num) inverse of stack_push | ||
| 32 | &function_begin(name,extra) Start a function with pushing of | ||
| 33 | edi, esi, ebx and ebp. extra is extra win32 | ||
| 34 | external info that may be required. | ||
| 35 | &function_begin_B(name,extra) Same as norma function_begin but no pushing. | ||
| 36 | &function_end(name) Call at end of function. | ||
| 37 | &function_end_A(name) Standard pop and ret, for use inside functions | ||
| 38 | &function_end_B(name) Call at end but with poping or 'ret'. | ||
| 39 | &swtmp(num) Address on stack temp word. | ||
| 40 | &wparam(num) Parameter number num, that was push | ||
| 41 | in C convention. This all works over pushes | ||
| 42 | and pops. | ||
| 43 | &comment("hello there") Put in a comment. | ||
| 44 | &label("loop") Refer to a label, normally a jmp target. | ||
| 45 | &set_label("loop") Set a label at this point. | ||
| 46 | &data_word(word) Put in a word of data. | ||
| 47 | |||
| 48 | So how does this all hold together? Given | ||
| 49 | |||
| 50 | int calc(int len, int *data) | ||
| 51 | { | ||
| 52 | int i,j=0; | ||
| 53 | |||
| 54 | for (i=0; i<len; i++) | ||
| 55 | { | ||
| 56 | j+=other(data[i]); | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | So a very simple version of this function could be coded as | ||
| 61 | |||
| 62 | push(@INC,"perlasm","../../perlasm"); | ||
| 63 | require "x86asm.pl"; | ||
| 64 | |||
| 65 | &asm_init($ARGV[0],"cacl.pl"); | ||
| 66 | |||
| 67 | &external_label("other"); | ||
| 68 | |||
| 69 | $tmp1= "eax"; | ||
| 70 | $j= "edi"; | ||
| 71 | $data= "esi"; | ||
| 72 | $i= "ebp"; | ||
| 73 | |||
| 74 | &comment("a simple function"); | ||
| 75 | &function_begin("calc"); | ||
| 76 | &mov( $data, &wparam(1)); # data | ||
| 77 | &xor( $j, $j); | ||
| 78 | &xor( $i, $i); | ||
| 79 | |||
| 80 | &set_label("loop"); | ||
| 81 | &cmp( $i, &wparam(0)); | ||
| 82 | &jge( &label("end")); | ||
| 83 | |||
| 84 | &mov( $tmp1, &DWP(0,$data,$i,4)); | ||
| 85 | &push( $tmp1); | ||
| 86 | &call( "other"); | ||
| 87 | &add( $j, "eax"); | ||
| 88 | &pop( $tmp1); | ||
| 89 | &inc( $i); | ||
| 90 | &jmp( &label("loop")); | ||
| 91 | |||
| 92 | &set_label("end"); | ||
| 93 | &mov( "eax", $j); | ||
| 94 | |||
| 95 | &function_end("calc"); | ||
| 96 | |||
| 97 | &asm_finish(); | ||
| 98 | |||
| 99 | The above example is very very unoptimised but gives an idea of how | ||
| 100 | things work. | ||
| 101 | |||
| 102 | There is also a cbc mode function generator in cbc.pl | ||
| 103 | |||
| 104 | &cbc( $name, | ||
| 105 | $encrypt_function_name, | ||
| 106 | $decrypt_function_name, | ||
| 107 | $true_if_byte_swap_needed, | ||
| 108 | $parameter_number_for_iv, | ||
| 109 | $parameter_number_for_encrypt_flag, | ||
| 110 | $first_parameter_to_pass, | ||
| 111 | $second_parameter_to_pass, | ||
| 112 | $third_parameter_to_pass); | ||
| 113 | |||
| 114 | So for example, given | ||
| 115 | void BF_encrypt(BF_LONG *data,BF_KEY *key); | ||
| 116 | void BF_decrypt(BF_LONG *data,BF_KEY *key); | ||
| 117 | void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length, | ||
| 118 | BF_KEY *ks, unsigned char *iv, int enc); | ||
| 119 | |||
| 120 | &cbc("BF_cbc_encrypt","BF_encrypt","BF_encrypt",1,4,5,3,-1,-1); | ||
| 121 | |||
| 122 | &cbc("des_ncbc_encrypt","des_encrypt","des_encrypt",0,4,5,3,5,-1); | ||
| 123 | &cbc("des_ede3_cbc_encrypt","des_encrypt3","des_decrypt3",0,6,7,3,4,5); | ||
| 124 | |||
diff --git a/src/lib/libcrypto/perlasm/x86asm.pl b/src/lib/libcrypto/perlasm/x86asm.pl new file mode 100644 index 0000000000..6a9156ae9a --- /dev/null +++ b/src/lib/libcrypto/perlasm/x86asm.pl | |||
| @@ -0,0 +1,113 @@ | |||
| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | # require 'x86asm.pl'; | ||
| 4 | # &asm_init("cpp","des-586.pl"); | ||
| 5 | # XXX | ||
| 6 | # XXX | ||
| 7 | # main'asm_finish | ||
| 8 | |||
| 9 | sub main'asm_finish | ||
| 10 | { | ||
| 11 | &file_end(); | ||
| 12 | &asm_finish_cpp() if $cpp; | ||
| 13 | print &asm_get_output(); | ||
| 14 | } | ||
| 15 | |||
| 16 | sub main'asm_init | ||
| 17 | { | ||
| 18 | ($type,$fn)=@_; | ||
| 19 | $filename=$fn; | ||
| 20 | |||
| 21 | $cpp=$sol=$aout=$win32=0; | ||
| 22 | if ( ($type eq "elf")) | ||
| 23 | { require "x86unix.pl"; } | ||
| 24 | elsif ( ($type eq "a.out")) | ||
| 25 | { $aout=1; require "x86unix.pl"; } | ||
| 26 | elsif ( ($type eq "sol")) | ||
| 27 | { $sol=1; require "x86unix.pl"; } | ||
| 28 | elsif ( ($type eq "cpp")) | ||
| 29 | { $cpp=1; require "x86unix.pl"; } | ||
| 30 | elsif ( ($type eq "win32")) | ||
| 31 | { $win32=1; require "x86ms.pl"; } | ||
| 32 | else | ||
| 33 | { | ||
| 34 | print STDERR <<"EOF"; | ||
| 35 | Pick one target type from | ||
| 36 | elf - linux, FreeBSD etc | ||
| 37 | a.out - old linux | ||
| 38 | sol - x86 solaris | ||
| 39 | cpp - format so x86unix.cpp can be used | ||
| 40 | win32 - Windows 95/Windows NT | ||
| 41 | EOF | ||
| 42 | exit(1); | ||
| 43 | } | ||
| 44 | |||
| 45 | &asm_init_output(); | ||
| 46 | |||
| 47 | &comment("Don't even think of reading this code"); | ||
| 48 | &comment("It was automatically generated by $filename"); | ||
| 49 | &comment("Which is a perl program used to generate the x86 assember for"); | ||
| 50 | &comment("any of elf, a.out, BSDI,Win32, or Solaris"); | ||
| 51 | &comment("eric <eay\@cryptsoft.com>"); | ||
| 52 | &comment(""); | ||
| 53 | |||
| 54 | $filename =~ s/\.pl$//; | ||
| 55 | &file($filename); | ||
| 56 | } | ||
| 57 | |||
| 58 | sub asm_finish_cpp | ||
| 59 | { | ||
| 60 | return unless $cpp; | ||
| 61 | |||
| 62 | local($tmp,$i); | ||
| 63 | foreach $i (&get_labels()) | ||
| 64 | { | ||
| 65 | $tmp.="#define $i _$i\n"; | ||
| 66 | } | ||
| 67 | print <<"EOF"; | ||
| 68 | /* Run the C pre-processor over this file with one of the following defined | ||
| 69 | * ELF - elf object files, | ||
| 70 | * OUT - a.out object files, | ||
| 71 | * BSDI - BSDI style a.out object files | ||
| 72 | * SOL - Solaris style elf | ||
| 73 | */ | ||
| 74 | |||
| 75 | #define TYPE(a,b) .type a,b | ||
| 76 | #define SIZE(a,b) .size a,b | ||
| 77 | |||
| 78 | #if defined(OUT) || defined(BSDI) | ||
| 79 | $tmp | ||
| 80 | #endif | ||
| 81 | |||
| 82 | #ifdef OUT | ||
| 83 | #define OK 1 | ||
| 84 | #define ALIGN 4 | ||
| 85 | #endif | ||
| 86 | |||
| 87 | #ifdef BSDI | ||
| 88 | #define OK 1 | ||
| 89 | #define ALIGN 4 | ||
| 90 | #undef SIZE | ||
| 91 | #undef TYPE | ||
| 92 | #define SIZE(a,b) | ||
| 93 | #define TYPE(a,b) | ||
| 94 | #endif | ||
| 95 | |||
| 96 | #if defined(ELF) || defined(SOL) | ||
| 97 | #define OK 1 | ||
| 98 | #define ALIGN 16 | ||
| 99 | #endif | ||
| 100 | |||
| 101 | #ifndef OK | ||
| 102 | You need to define one of | ||
| 103 | ELF - elf systems - linux-elf, NetBSD and DG-UX | ||
| 104 | OUT - a.out systems - linux-a.out and FreeBSD | ||
| 105 | SOL - solaris systems, which are elf with strange comment lines | ||
| 106 | BSDI - a.out with a very primative version of as. | ||
| 107 | #endif | ||
| 108 | |||
| 109 | /* Let the Assembler begin :-) */ | ||
| 110 | EOF | ||
| 111 | } | ||
| 112 | |||
| 113 | 1; | ||
diff --git a/src/lib/libcrypto/pkcs7/pk7_doit.c b/src/lib/libcrypto/pkcs7/pk7_doit.c new file mode 100644 index 0000000000..b5689b3fe4 --- /dev/null +++ b/src/lib/libcrypto/pkcs7/pk7_doit.c | |||
| @@ -0,0 +1,408 @@ | |||
| 1 | /* crypto/pkcs7/pk7_doit.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 "rand.h" | ||
| 62 | #include "objects.h" | ||
| 63 | #include "x509.h" | ||
| 64 | |||
| 65 | BIO *PKCS7_dataInit(p7,bio) | ||
| 66 | PKCS7 *p7; | ||
| 67 | BIO *bio; | ||
| 68 | { | ||
| 69 | int i,j; | ||
| 70 | BIO *out=NULL,*btmp; | ||
| 71 | X509_ALGOR *xa; | ||
| 72 | EVP_MD *evp_md; | ||
| 73 | EVP_CIPHER *evp_cipher=NULL; | ||
| 74 | STACK *md_sk=NULL,*rsk=NULL; | ||
| 75 | X509_ALGOR *xalg=NULL; | ||
| 76 | PKCS7_RECIP_INFO *ri=NULL; | ||
| 77 | EVP_PKEY *pkey; | ||
| 78 | |||
| 79 | i=OBJ_obj2nid(p7->type); | ||
| 80 | p7->state=PKCS7_S_HEADER; | ||
| 81 | |||
| 82 | switch (i) | ||
| 83 | { | ||
| 84 | case NID_pkcs7_signed: | ||
| 85 | md_sk=p7->d.sign->md_algs; | ||
| 86 | break; | ||
| 87 | case NID_pkcs7_signedAndEnveloped: | ||
| 88 | rsk=p7->d.signed_and_enveloped->recipientinfo; | ||
| 89 | md_sk=p7->d.signed_and_enveloped->md_algs; | ||
| 90 | evp_cipher=EVP_get_cipherbyname(OBJ_nid2sn(OBJ_obj2nid(p7->d.signed_and_enveloped->enc_data->algorithm->algorithm))); | ||
| 91 | if (evp_cipher == NULL) | ||
| 92 | { | ||
| 93 | PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_UNSUPPORTED_CIPHER_TYPE); | ||
| 94 | goto err; | ||
| 95 | } | ||
| 96 | xalg=p7->d.signed_and_enveloped->enc_data->algorithm; | ||
| 97 | break; | ||
| 98 | default: | ||
| 99 | PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_UNSUPPORTED_CONTENT_TYPE); | ||
| 100 | goto err; | ||
| 101 | } | ||
| 102 | |||
| 103 | if (md_sk != NULL) | ||
| 104 | { | ||
| 105 | for (i=0; i<sk_num(md_sk); i++) | ||
| 106 | { | ||
| 107 | xa=(X509_ALGOR *)sk_value(md_sk,i); | ||
| 108 | if ((btmp=BIO_new(BIO_f_md())) == NULL) goto err; | ||
| 109 | |||
| 110 | j=OBJ_obj2nid(xa->algorithm); | ||
| 111 | evp_md=EVP_get_digestbyname(OBJ_nid2sn(j)); | ||
| 112 | if (evp_md == NULL) | ||
| 113 | { | ||
| 114 | PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_UNKNOWN_DIGEST_TYPE); | ||
| 115 | goto err; | ||
| 116 | } | ||
| 117 | |||
| 118 | BIO_set_md(btmp,evp_md); | ||
| 119 | if (out == NULL) | ||
| 120 | out=btmp; | ||
| 121 | else | ||
| 122 | BIO_push(out,btmp); | ||
| 123 | } | ||
| 124 | } | ||
| 125 | |||
| 126 | if (evp_cipher != NULL) | ||
| 127 | { | ||
| 128 | unsigned char key[EVP_MAX_KEY_LENGTH]; | ||
| 129 | unsigned char iv[EVP_MAX_IV_LENGTH]; | ||
| 130 | int keylen,ivlen; | ||
| 131 | int jj,max; | ||
| 132 | unsigned char *tmp; | ||
| 133 | |||
| 134 | if ((btmp=BIO_new(BIO_f_cipher())) == NULL) goto err; | ||
| 135 | keylen=EVP_CIPHER_key_length(evp_cipher); | ||
| 136 | ivlen=EVP_CIPHER_iv_length(evp_cipher); | ||
| 137 | |||
| 138 | if (ivlen > 0) | ||
| 139 | { | ||
| 140 | ASN1_OCTET_STRING *os; | ||
| 141 | |||
| 142 | RAND_bytes(iv,ivlen); | ||
| 143 | os=ASN1_OCTET_STRING_new(); | ||
| 144 | ASN1_OCTET_STRING_set(os,iv,ivlen); | ||
| 145 | /* ASN1_TYPE_set(xalg->parameter,V_ASN1_OCTET_STRING, | ||
| 146 | (char *)os); | ||
| 147 | */ } | ||
| 148 | RAND_bytes(key,keylen); | ||
| 149 | |||
| 150 | /* Lets do the pub key stuff :-) */ | ||
| 151 | max=0; | ||
| 152 | for (i=0; i<sk_num(rsk); i++) | ||
| 153 | { | ||
| 154 | ri=(PKCS7_RECIP_INFO *)sk_value(rsk,i); | ||
| 155 | if (ri->cert == NULL) abort(); | ||
| 156 | pkey=X509_get_pubkey(ri->cert); | ||
| 157 | jj=EVP_PKEY_size(pkey); | ||
| 158 | if (max < jj) max=jj; | ||
| 159 | } | ||
| 160 | if ((tmp=(unsigned char *)Malloc(max)) == NULL) abort(); | ||
| 161 | for (i=0; i<sk_num(rsk); i++) | ||
| 162 | { | ||
| 163 | ri=(PKCS7_RECIP_INFO *)sk_value(rsk,i); | ||
| 164 | pkey=X509_get_pubkey(ri->cert); | ||
| 165 | jj=EVP_PKEY_encrypt(tmp,key,keylen,pkey); | ||
| 166 | if (jj <= 0) abort(); | ||
| 167 | ASN1_OCTET_STRING_set(ri->enc_key,tmp,jj); | ||
| 168 | } | ||
| 169 | |||
| 170 | BIO_set_cipher(btmp,evp_cipher,key,iv,1); | ||
| 171 | |||
| 172 | if (out == NULL) | ||
| 173 | out=btmp; | ||
| 174 | else | ||
| 175 | BIO_push(out,btmp); | ||
| 176 | } | ||
| 177 | |||
| 178 | if (bio == NULL) /* ??????????? */ | ||
| 179 | { | ||
| 180 | if (p7->detached) | ||
| 181 | bio=BIO_new(BIO_s_null()); | ||
| 182 | else | ||
| 183 | { | ||
| 184 | bio=BIO_new(BIO_s_mem()); | ||
| 185 | if (PKCS7_type_is_signed(p7) && | ||
| 186 | PKCS7_type_is_data(p7->d.sign->contents)) | ||
| 187 | { | ||
| 188 | ASN1_OCTET_STRING *os; | ||
| 189 | |||
| 190 | os=p7->d.sign->contents->d.data; | ||
| 191 | if (os->length > 0) | ||
| 192 | BIO_write(bio,(char *)os->data, | ||
| 193 | os->length); | ||
| 194 | } | ||
| 195 | } | ||
| 196 | } | ||
| 197 | BIO_push(out,bio); | ||
| 198 | return(out); | ||
| 199 | err: | ||
| 200 | return(NULL); | ||
| 201 | } | ||
| 202 | |||
| 203 | int PKCS7_dataSign(p7,bio) | ||
| 204 | PKCS7 *p7; | ||
| 205 | BIO *bio; | ||
| 206 | { | ||
| 207 | int ret=0; | ||
| 208 | int i,j; | ||
| 209 | BIO *btmp; | ||
| 210 | BUF_MEM *buf_mem=NULL; | ||
| 211 | BUF_MEM *buf=NULL; | ||
| 212 | PKCS7_SIGNER_INFO *si; | ||
| 213 | EVP_MD_CTX *mdc,ctx_tmp; | ||
| 214 | STACK *sk,*si_sk=NULL; | ||
| 215 | unsigned char *p,*pp=NULL; | ||
| 216 | int x; | ||
| 217 | ASN1_OCTET_STRING *os=NULL; | ||
| 218 | |||
| 219 | i=OBJ_obj2nid(p7->type); | ||
| 220 | p7->state=PKCS7_S_HEADER; | ||
| 221 | |||
| 222 | switch (i) | ||
| 223 | { | ||
| 224 | case NID_pkcs7_signedAndEnveloped: | ||
| 225 | /* XXXXXXXXXXXXXXXX */ | ||
| 226 | si_sk=p7->d.signed_and_enveloped->signer_info; | ||
| 227 | os=ASN1_OCTET_STRING_new(); | ||
| 228 | p7->d.signed_and_enveloped->enc_data->enc_data=os; | ||
| 229 | break; | ||
| 230 | case NID_pkcs7_signed: | ||
| 231 | si_sk=p7->d.sign->signer_info; | ||
| 232 | os=p7->d.sign->contents->d.data; | ||
| 233 | break; | ||
| 234 | } | ||
| 235 | |||
| 236 | if (si_sk != NULL) | ||
| 237 | { | ||
| 238 | if ((buf=BUF_MEM_new()) == NULL) goto err; | ||
| 239 | for (i=0; i<sk_num(si_sk); i++) | ||
| 240 | { | ||
| 241 | si=(PKCS7_SIGNER_INFO *) | ||
| 242 | sk_value(si_sk,i); | ||
| 243 | if (si->pkey == NULL) | ||
| 244 | continue; | ||
| 245 | j=OBJ_obj2nid(si->digest_enc_alg->algorithm); | ||
| 246 | |||
| 247 | btmp=bio; | ||
| 248 | for (;;) | ||
| 249 | { | ||
| 250 | if ((btmp=BIO_find_type(btmp,BIO_TYPE_MD)) | ||
| 251 | == NULL) | ||
| 252 | { | ||
| 253 | PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST); | ||
| 254 | goto err; | ||
| 255 | } | ||
| 256 | BIO_get_md_ctx(btmp,&mdc); | ||
| 257 | if (mdc == NULL) | ||
| 258 | { | ||
| 259 | PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_INTERNAL_ERROR); | ||
| 260 | goto err; | ||
| 261 | } | ||
| 262 | if (EVP_MD_pkey_type(EVP_MD_CTX_type(mdc)) == j) | ||
| 263 | break; | ||
| 264 | else | ||
| 265 | btmp=btmp->next_bio; | ||
| 266 | } | ||
| 267 | |||
| 268 | /* We now have the EVP_MD_CTX, lets do the | ||
| 269 | * signing. */ | ||
| 270 | memcpy(&ctx_tmp,mdc,sizeof(ctx_tmp)); | ||
| 271 | if (!BUF_MEM_grow(buf,EVP_PKEY_size(si->pkey))) | ||
| 272 | goto err; | ||
| 273 | |||
| 274 | sk=si->auth_attr; | ||
| 275 | if ((sk != NULL) && (sk_num(sk) != 0)) | ||
| 276 | { | ||
| 277 | x=i2d_ASN1_SET(sk,NULL,i2d_X509_ATTRIBUTE, | ||
| 278 | V_ASN1_SET,V_ASN1_UNIVERSAL); | ||
| 279 | pp=(unsigned char *)Malloc(i); | ||
| 280 | p=pp; | ||
| 281 | i2d_ASN1_SET(sk,&p,i2d_X509_ATTRIBUTE, | ||
| 282 | V_ASN1_SET,V_ASN1_UNIVERSAL); | ||
| 283 | EVP_SignUpdate(&ctx_tmp,pp,x); | ||
| 284 | Free(pp); | ||
| 285 | } | ||
| 286 | |||
| 287 | if (!EVP_SignFinal(&ctx_tmp,(unsigned char *)buf->data, | ||
| 288 | (unsigned int *)&buf->length,si->pkey)) | ||
| 289 | goto err; | ||
| 290 | if (!ASN1_STRING_set(si->enc_digest, | ||
| 291 | (unsigned char *)buf->data,buf->length)) | ||
| 292 | goto err; | ||
| 293 | } | ||
| 294 | if (p7->detached) | ||
| 295 | ASN1_OCTET_STRING_set(os,(unsigned char *)"",0); | ||
| 296 | else | ||
| 297 | { | ||
| 298 | btmp=BIO_find_type(bio,BIO_TYPE_MEM); | ||
| 299 | if (btmp == NULL) | ||
| 300 | { | ||
| 301 | PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_UNABLE_TO_FIND_MEM_BIO); | ||
| 302 | goto err; | ||
| 303 | } | ||
| 304 | BIO_get_mem_ptr(btmp,&buf_mem); | ||
| 305 | ASN1_OCTET_STRING_set(os, | ||
| 306 | (unsigned char *)buf_mem->data,buf_mem->length); | ||
| 307 | } | ||
| 308 | if (pp != NULL) Free(pp); | ||
| 309 | pp=NULL; | ||
| 310 | } | ||
| 311 | |||
| 312 | ret=1; | ||
| 313 | err: | ||
| 314 | if (buf != NULL) BUF_MEM_free(buf); | ||
| 315 | return(ret); | ||
| 316 | } | ||
| 317 | |||
| 318 | int PKCS7_dataVerify(cert_store,ctx,bio,p7,si) | ||
| 319 | X509_STORE *cert_store; | ||
| 320 | X509_STORE_CTX *ctx; | ||
| 321 | BIO *bio; | ||
| 322 | PKCS7 *p7; | ||
| 323 | PKCS7_SIGNER_INFO *si; | ||
| 324 | { | ||
| 325 | PKCS7_SIGNED *s; | ||
| 326 | ASN1_OCTET_STRING *os; | ||
| 327 | EVP_MD_CTX mdc_tmp,*mdc; | ||
| 328 | unsigned char *pp,*p; | ||
| 329 | PKCS7_ISSUER_AND_SERIAL *ias; | ||
| 330 | int ret=0,md_type,i; | ||
| 331 | STACK *sk; | ||
| 332 | BIO *btmp; | ||
| 333 | X509 *x509; | ||
| 334 | |||
| 335 | if (!PKCS7_type_is_signed(p7)) abort(); | ||
| 336 | /* XXXXXXXXXXXXXXXXXXXXXXX */ | ||
| 337 | ias=si->issuer_and_serial; | ||
| 338 | s=p7->d.sign; | ||
| 339 | |||
| 340 | x509=X509_find_by_issuer_and_serial(s->cert,ias->issuer,ias->serial); | ||
| 341 | |||
| 342 | /* were we able to find the cert in passed to us */ | ||
| 343 | if (x509 == NULL) | ||
| 344 | { | ||
| 345 | PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_UNABLE_TO_FIND_CERTIFICATE); | ||
| 346 | goto err; | ||
| 347 | } | ||
| 348 | |||
| 349 | /* Lets verify */ | ||
| 350 | X509_STORE_CTX_init(ctx,cert_store,x509,s->cert); | ||
| 351 | i=X509_verify_cert(ctx); | ||
| 352 | if (i <= 0) goto err; | ||
| 353 | X509_STORE_CTX_cleanup(ctx); | ||
| 354 | |||
| 355 | /* So we like 'x509', lets check the signature. */ | ||
| 356 | md_type=OBJ_obj2nid(si->digest_alg->algorithm); | ||
| 357 | |||
| 358 | btmp=bio; | ||
| 359 | for (;;) | ||
| 360 | { | ||
| 361 | if ((btmp == NULL) || | ||
| 362 | ((btmp=BIO_find_type(btmp,BIO_TYPE_MD)) == NULL)) | ||
| 363 | { | ||
| 364 | PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST); | ||
| 365 | goto err; | ||
| 366 | } | ||
| 367 | BIO_get_md_ctx(btmp,&mdc); | ||
| 368 | if (mdc == NULL) | ||
| 369 | { | ||
| 370 | PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_INTERNAL_ERROR); | ||
| 371 | goto err; | ||
| 372 | } | ||
| 373 | if (EVP_MD_type(EVP_MD_CTX_type(mdc)) == md_type) | ||
| 374 | break; | ||
| 375 | btmp=btmp->next_bio; | ||
| 376 | } | ||
| 377 | |||
| 378 | /* mdc is the digest ctx that we want */ | ||
| 379 | memcpy(&mdc_tmp,mdc,sizeof(mdc_tmp)); | ||
| 380 | |||
| 381 | sk=si->auth_attr; | ||
| 382 | if ((sk != NULL) && (sk_num(sk) != 0)) | ||
| 383 | { | ||
| 384 | i=i2d_ASN1_SET(sk,NULL,i2d_X509_ATTRIBUTE, | ||
| 385 | V_ASN1_SET,V_ASN1_UNIVERSAL); | ||
| 386 | pp=(unsigned char *)malloc(i); | ||
| 387 | p=pp; | ||
| 388 | i2d_ASN1_SET(sk,&p,i2d_X509_ATTRIBUTE, | ||
| 389 | V_ASN1_SET,V_ASN1_UNIVERSAL); | ||
| 390 | EVP_VerifyUpdate(&mdc_tmp,pp,i); | ||
| 391 | free(pp); | ||
| 392 | } | ||
| 393 | |||
| 394 | os=si->enc_digest; | ||
| 395 | i=EVP_VerifyFinal(&mdc_tmp,os->data,os->length, | ||
| 396 | X509_get_pubkey(x509)); | ||
| 397 | if (i <= 0) | ||
| 398 | { | ||
| 399 | PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_SIGNATURE_FAILURE); | ||
| 400 | ret= -1; | ||
| 401 | goto err; | ||
| 402 | } | ||
| 403 | else | ||
| 404 | ret=1; | ||
| 405 | err: | ||
| 406 | return(ret); | ||
| 407 | } | ||
| 408 | |||
diff --git a/src/lib/libcrypto/pkcs7/pk7_lib.c b/src/lib/libcrypto/pkcs7/pk7_lib.c new file mode 100644 index 0000000000..7d14ad1173 --- /dev/null +++ b/src/lib/libcrypto/pkcs7/pk7_lib.c | |||
| @@ -0,0 +1,449 @@ | |||
| 1 | /* crypto/pkcs7/pk7_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 "objects.h" | ||
| 62 | #include "x509.h" | ||
| 63 | |||
| 64 | long PKCS7_ctrl(p7,cmd,larg,parg) | ||
| 65 | PKCS7 *p7; | ||
| 66 | int cmd; | ||
| 67 | long larg; | ||
| 68 | char *parg; | ||
| 69 | { | ||
| 70 | int nid; | ||
| 71 | long ret; | ||
| 72 | |||
| 73 | nid=OBJ_obj2nid(p7->type); | ||
| 74 | |||
| 75 | switch (cmd) | ||
| 76 | { | ||
| 77 | case PKCS7_OP_SET_DETACHED_SIGNATURE: | ||
| 78 | if (nid == NID_pkcs7_signed) | ||
| 79 | { | ||
| 80 | ret=p7->detached=(int)larg; | ||
| 81 | } | ||
| 82 | else | ||
| 83 | { | ||
| 84 | PKCS7err(PKCS7_F_PKCS7_CTRL,PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE); | ||
| 85 | ret=0; | ||
| 86 | } | ||
| 87 | break; | ||
| 88 | case PKCS7_OP_GET_DETACHED_SIGNATURE: | ||
| 89 | if (nid == NID_pkcs7_signed) | ||
| 90 | { | ||
| 91 | ret=p7->detached; | ||
| 92 | } | ||
| 93 | else | ||
| 94 | { | ||
| 95 | PKCS7err(PKCS7_F_PKCS7_CTRL,PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE); | ||
| 96 | ret=0; | ||
| 97 | } | ||
| 98 | |||
| 99 | break; | ||
| 100 | default: | ||
| 101 | abort(); | ||
| 102 | } | ||
| 103 | return(ret); | ||
| 104 | } | ||
| 105 | |||
| 106 | int PKCS7_content_new(p7,type) | ||
| 107 | PKCS7 *p7; | ||
| 108 | int type; | ||
| 109 | { | ||
| 110 | PKCS7 *ret=NULL; | ||
| 111 | |||
| 112 | if ((ret=PKCS7_new()) == NULL) goto err; | ||
| 113 | if (!PKCS7_set_type(ret,type)) goto err; | ||
| 114 | if (!PKCS7_set_content(p7,ret)) goto err; | ||
| 115 | |||
| 116 | return(1); | ||
| 117 | err: | ||
| 118 | if (ret != NULL) PKCS7_free(ret); | ||
| 119 | return(0); | ||
| 120 | } | ||
| 121 | |||
| 122 | int PKCS7_set_content(p7,p7_data) | ||
| 123 | PKCS7 *p7; | ||
| 124 | PKCS7 *p7_data; | ||
| 125 | { | ||
| 126 | int i; | ||
| 127 | |||
| 128 | i=OBJ_obj2nid(p7->type); | ||
| 129 | switch (i) | ||
| 130 | { | ||
| 131 | case NID_pkcs7_signed: | ||
| 132 | if (p7->d.sign->contents != NULL) | ||
| 133 | PKCS7_content_free(p7->d.sign->contents); | ||
| 134 | p7->d.sign->contents=p7_data; | ||
| 135 | break; | ||
| 136 | case NID_pkcs7_digest: | ||
| 137 | case NID_pkcs7_data: | ||
| 138 | case NID_pkcs7_enveloped: | ||
| 139 | case NID_pkcs7_signedAndEnveloped: | ||
| 140 | case NID_pkcs7_encrypted: | ||
| 141 | default: | ||
| 142 | PKCS7err(PKCS7_F_PKCS7_SET_CONTENT,PKCS7_R_UNSUPPORTED_CONTENT_TYPE); | ||
| 143 | goto err; | ||
| 144 | } | ||
| 145 | return(1); | ||
| 146 | err: | ||
| 147 | return(0); | ||
| 148 | } | ||
| 149 | |||
| 150 | int PKCS7_set_type(p7,type) | ||
| 151 | PKCS7 *p7; | ||
| 152 | int type; | ||
| 153 | { | ||
| 154 | ASN1_OBJECT *obj; | ||
| 155 | |||
| 156 | PKCS7_content_free(p7); | ||
| 157 | obj=OBJ_nid2obj(type); /* will not fail */ | ||
| 158 | |||
| 159 | switch (type) | ||
| 160 | { | ||
| 161 | case NID_pkcs7_signed: | ||
| 162 | p7->type=obj; | ||
| 163 | if ((p7->d.sign=PKCS7_SIGNED_new()) == NULL) | ||
| 164 | goto err; | ||
| 165 | ASN1_INTEGER_set(p7->d.sign->version,1); | ||
| 166 | break; | ||
| 167 | case NID_pkcs7_data: | ||
| 168 | p7->type=obj; | ||
| 169 | if ((p7->d.data=ASN1_OCTET_STRING_new()) == NULL) | ||
| 170 | goto err; | ||
| 171 | break; | ||
| 172 | case NID_pkcs7_signedAndEnveloped: | ||
| 173 | p7->type=obj; | ||
| 174 | if ((p7->d.signed_and_enveloped=PKCS7_SIGN_ENVELOPE_new()) | ||
| 175 | == NULL) | ||
| 176 | goto err; | ||
| 177 | ASN1_INTEGER_set(p7->d.sign->version,1); | ||
| 178 | break; | ||
| 179 | case NID_pkcs7_digest: | ||
| 180 | case NID_pkcs7_enveloped: | ||
| 181 | case NID_pkcs7_encrypted: | ||
| 182 | default: | ||
| 183 | PKCS7err(PKCS7_F_PKCS7_SET_TYPE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE); | ||
| 184 | goto err; | ||
| 185 | } | ||
| 186 | return(1); | ||
| 187 | err: | ||
| 188 | return(0); | ||
| 189 | } | ||
| 190 | |||
| 191 | int PKCS7_add_signer(p7,psi) | ||
| 192 | PKCS7 *p7; | ||
| 193 | PKCS7_SIGNER_INFO *psi; | ||
| 194 | { | ||
| 195 | int i,j,nid; | ||
| 196 | X509_ALGOR *alg; | ||
| 197 | STACK *signer_sk; | ||
| 198 | STACK *md_sk; | ||
| 199 | |||
| 200 | i=OBJ_obj2nid(p7->type); | ||
| 201 | switch (i) | ||
| 202 | { | ||
| 203 | case NID_pkcs7_signed: | ||
| 204 | signer_sk= p7->d.sign->signer_info; | ||
| 205 | md_sk= p7->d.sign->md_algs; | ||
| 206 | break; | ||
| 207 | case NID_pkcs7_signedAndEnveloped: | ||
| 208 | signer_sk= p7->d.signed_and_enveloped->signer_info; | ||
| 209 | md_sk= p7->d.signed_and_enveloped->md_algs; | ||
| 210 | break; | ||
| 211 | default: | ||
| 212 | PKCS7err(PKCS7_F_PKCS7_ADD_SIGNER,PKCS7_R_WRONG_CONTENT_TYPE); | ||
| 213 | return(0); | ||
| 214 | } | ||
| 215 | |||
| 216 | nid=OBJ_obj2nid(psi->digest_alg->algorithm); | ||
| 217 | |||
| 218 | /* If the digest is not currently listed, add it */ | ||
| 219 | j=0; | ||
| 220 | for (i=0; i<sk_num(md_sk); i++) | ||
| 221 | { | ||
| 222 | alg=(X509_ALGOR *)sk_value(md_sk,i); | ||
| 223 | if (OBJ_obj2nid(alg->algorithm) == nid) | ||
| 224 | { | ||
| 225 | j=1; | ||
| 226 | break; | ||
| 227 | } | ||
| 228 | } | ||
| 229 | if (!j) /* we need to add another algorithm */ | ||
| 230 | { | ||
| 231 | alg=X509_ALGOR_new(); | ||
| 232 | alg->algorithm=OBJ_nid2obj(nid); | ||
| 233 | sk_push(md_sk,(char *)alg); | ||
| 234 | } | ||
| 235 | |||
| 236 | sk_push(signer_sk,(char *)psi); | ||
| 237 | return(1); | ||
| 238 | } | ||
| 239 | |||
| 240 | int PKCS7_add_certificate(p7,x509) | ||
| 241 | PKCS7 *p7; | ||
| 242 | X509 *x509; | ||
| 243 | { | ||
| 244 | int i; | ||
| 245 | STACK **sk; | ||
| 246 | |||
| 247 | i=OBJ_obj2nid(p7->type); | ||
| 248 | switch (i) | ||
| 249 | { | ||
| 250 | case NID_pkcs7_signed: | ||
| 251 | sk= &(p7->d.sign->cert); | ||
| 252 | break; | ||
| 253 | case NID_pkcs7_signedAndEnveloped: | ||
| 254 | sk= &(p7->d.signed_and_enveloped->cert); | ||
| 255 | break; | ||
| 256 | default: | ||
| 257 | PKCS7err(PKCS7_F_PKCS7_ADD_CERTIFICATE,PKCS7_R_WRONG_CONTENT_TYPE); | ||
| 258 | return(0); | ||
| 259 | } | ||
| 260 | |||
| 261 | if (*sk == NULL) | ||
| 262 | *sk=sk_new_null(); | ||
| 263 | CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509); | ||
| 264 | sk_push(*sk,(char *)x509); | ||
| 265 | return(1); | ||
| 266 | } | ||
| 267 | |||
| 268 | int PKCS7_add_crl(p7,crl) | ||
| 269 | PKCS7 *p7; | ||
| 270 | X509_CRL *crl; | ||
| 271 | { | ||
| 272 | int i; | ||
| 273 | STACK **sk; | ||
| 274 | |||
| 275 | i=OBJ_obj2nid(p7->type); | ||
| 276 | switch (i) | ||
| 277 | { | ||
| 278 | case NID_pkcs7_signed: | ||
| 279 | sk= &(p7->d.sign->crl); | ||
| 280 | break; | ||
| 281 | case NID_pkcs7_signedAndEnveloped: | ||
| 282 | sk= &(p7->d.signed_and_enveloped->crl); | ||
| 283 | break; | ||
| 284 | default: | ||
| 285 | PKCS7err(PKCS7_F_PKCS7_ADD_CRL,PKCS7_R_WRONG_CONTENT_TYPE); | ||
| 286 | return(0); | ||
| 287 | } | ||
| 288 | |||
| 289 | if (*sk == NULL) | ||
| 290 | *sk=sk_new_null(); | ||
| 291 | |||
| 292 | CRYPTO_add(&crl->references,1,CRYPTO_LOCK_X509_CRL); | ||
| 293 | sk_push(*sk,(char *)crl); | ||
| 294 | return(1); | ||
| 295 | } | ||
| 296 | |||
| 297 | int PKCS7_SIGNER_INFO_set(p7i,x509,pkey,dgst) | ||
| 298 | PKCS7_SIGNER_INFO *p7i; | ||
| 299 | X509 *x509; | ||
| 300 | EVP_PKEY *pkey; | ||
| 301 | EVP_MD *dgst; | ||
| 302 | { | ||
| 303 | /* We now need to add another PKCS7_SIGNER_INFO entry */ | ||
| 304 | ASN1_INTEGER_set(p7i->version,1); | ||
| 305 | X509_NAME_set(&p7i->issuer_and_serial->issuer, | ||
| 306 | X509_get_issuer_name(x509)); | ||
| 307 | |||
| 308 | /* because ASN1_INTEGER_set is used to set a 'long' we will do | ||
| 309 | * things the ugly way. */ | ||
| 310 | ASN1_INTEGER_free(p7i->issuer_and_serial->serial); | ||
| 311 | p7i->issuer_and_serial->serial= | ||
| 312 | ASN1_INTEGER_dup(X509_get_serialNumber(x509)); | ||
| 313 | |||
| 314 | /* lets keep the pkey around for a while */ | ||
| 315 | CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY); | ||
| 316 | p7i->pkey=pkey; | ||
| 317 | |||
| 318 | /* Set the algorithms */ | ||
| 319 | p7i->digest_alg->algorithm=OBJ_nid2obj(EVP_MD_type(dgst)); | ||
| 320 | p7i->digest_enc_alg->algorithm=OBJ_nid2obj(EVP_MD_pkey_type(dgst)); | ||
| 321 | |||
| 322 | #if 1 | ||
| 323 | if (p7i->digest_enc_alg->parameter != NULL) | ||
| 324 | ASN1_TYPE_free(p7i->digest_enc_alg->parameter); | ||
| 325 | if ((p7i->digest_enc_alg->parameter=ASN1_TYPE_new()) == NULL) | ||
| 326 | goto err; | ||
| 327 | p7i->digest_enc_alg->parameter->type=V_ASN1_NULL; | ||
| 328 | #endif | ||
| 329 | |||
| 330 | return(1); | ||
| 331 | err: | ||
| 332 | return(0); | ||
| 333 | } | ||
| 334 | |||
| 335 | PKCS7_SIGNER_INFO *PKCS7_add_signature(p7,x509,pkey,dgst) | ||
| 336 | PKCS7 *p7; | ||
| 337 | X509 *x509; | ||
| 338 | EVP_PKEY *pkey; | ||
| 339 | EVP_MD *dgst; | ||
| 340 | { | ||
| 341 | PKCS7_SIGNER_INFO *si; | ||
| 342 | |||
| 343 | if ((si=PKCS7_SIGNER_INFO_new()) == NULL) goto err; | ||
| 344 | if (!PKCS7_SIGNER_INFO_set(si,x509,pkey,dgst)) goto err; | ||
| 345 | if (!PKCS7_add_signer(p7,si)) goto err; | ||
| 346 | return(si); | ||
| 347 | err: | ||
| 348 | return(NULL); | ||
| 349 | } | ||
| 350 | |||
| 351 | STACK *PKCS7_get_signer_info(p7) | ||
| 352 | PKCS7 *p7; | ||
| 353 | { | ||
| 354 | if (PKCS7_type_is_signed(p7)) | ||
| 355 | { | ||
| 356 | return(p7->d.sign->signer_info); | ||
| 357 | } | ||
| 358 | else | ||
| 359 | return(NULL); | ||
| 360 | } | ||
| 361 | |||
| 362 | PKCS7_RECIP_INFO *PKCS7_add_recipient(p7,x509) | ||
| 363 | PKCS7 *p7; | ||
| 364 | X509 *x509; | ||
| 365 | { | ||
| 366 | PKCS7_RECIP_INFO *ri; | ||
| 367 | |||
| 368 | if ((ri=PKCS7_RECIP_INFO_new()) == NULL) goto err; | ||
| 369 | if (!PKCS7_RECIP_INFO_set(ri,x509)) goto err; | ||
| 370 | if (!PKCS7_add_recipient_info(p7,ri)) goto err; | ||
| 371 | return(ri); | ||
| 372 | err: | ||
| 373 | return(NULL); | ||
| 374 | } | ||
| 375 | |||
| 376 | int PKCS7_add_recipient_info(p7,ri) | ||
| 377 | PKCS7 *p7; | ||
| 378 | PKCS7_RECIP_INFO *ri; | ||
| 379 | { | ||
| 380 | int i; | ||
| 381 | STACK *sk; | ||
| 382 | |||
| 383 | i=OBJ_obj2nid(p7->type); | ||
| 384 | switch (i) | ||
| 385 | { | ||
| 386 | case NID_pkcs7_signedAndEnveloped: | ||
| 387 | sk= p7->d.signed_and_enveloped->recipientinfo; | ||
| 388 | break; | ||
| 389 | default: | ||
| 390 | PKCS7err(PKCS7_F_PKCS7_ADD_RECIPIENT_INFO,PKCS7_R_WRONG_CONTENT_TYPE); | ||
| 391 | return(0); | ||
| 392 | } | ||
| 393 | |||
| 394 | sk_push(sk,(char *)ri); | ||
| 395 | return(1); | ||
| 396 | } | ||
| 397 | |||
| 398 | int PKCS7_RECIP_INFO_set(p7i,x509) | ||
| 399 | PKCS7_RECIP_INFO *p7i; | ||
| 400 | X509 *x509; | ||
| 401 | { | ||
| 402 | ASN1_INTEGER_set(p7i->version,0); | ||
| 403 | X509_NAME_set(&p7i->issuer_and_serial->issuer, | ||
| 404 | X509_get_issuer_name(x509)); | ||
| 405 | |||
| 406 | ASN1_INTEGER_free(p7i->issuer_and_serial->serial); | ||
| 407 | p7i->issuer_and_serial->serial= | ||
| 408 | ASN1_INTEGER_dup(X509_get_serialNumber(x509)); | ||
| 409 | |||
| 410 | CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509); | ||
| 411 | p7i->cert=x509; | ||
| 412 | |||
| 413 | return(1); | ||
| 414 | } | ||
| 415 | |||
| 416 | X509 *PKCS7_cert_from_signer_info(p7,si) | ||
| 417 | PKCS7 *p7; | ||
| 418 | PKCS7_SIGNER_INFO *si; | ||
| 419 | { | ||
| 420 | if (PKCS7_type_is_signed(p7)) | ||
| 421 | return(X509_find_by_issuer_and_serial(p7->d.sign->cert, | ||
| 422 | si->issuer_and_serial->issuer, | ||
| 423 | si->issuer_and_serial->serial)); | ||
| 424 | else | ||
| 425 | return(NULL); | ||
| 426 | } | ||
| 427 | |||
| 428 | int PKCS7_set_cipher(p7,cipher) | ||
| 429 | PKCS7 *p7; | ||
| 430 | EVP_CIPHER *cipher; | ||
| 431 | { | ||
| 432 | int i; | ||
| 433 | PKCS7_ENC_CONTENT *ec; | ||
| 434 | |||
| 435 | i=OBJ_obj2nid(p7->type); | ||
| 436 | switch (i) | ||
| 437 | { | ||
| 438 | case NID_pkcs7_signedAndEnveloped: | ||
| 439 | ec=p7->d.signed_and_enveloped->enc_data; | ||
| 440 | break; | ||
| 441 | default: | ||
| 442 | PKCS7err(PKCS7_F_PKCS7_SET_CIPHER,PKCS7_R_WRONG_CONTENT_TYPE); | ||
| 443 | return(0); | ||
| 444 | } | ||
| 445 | |||
| 446 | ec->algorithm->algorithm=OBJ_nid2obj(EVP_CIPHER_nid(cipher)); | ||
| 447 | return(ec->algorithm->algorithm != NULL); | ||
| 448 | } | ||
| 449 | |||
diff --git a/src/lib/libcrypto/pkcs7/pkcs7.h b/src/lib/libcrypto/pkcs7/pkcs7.h new file mode 100644 index 0000000000..ee12f670a8 --- /dev/null +++ b/src/lib/libcrypto/pkcs7/pkcs7.h | |||
| @@ -0,0 +1,449 @@ | |||
| 1 | /* crypto/pkcs7/pkcs7.h */ | ||
| 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 | #ifndef HEADER_PKCS7_H | ||
| 60 | #define HEADER_PKCS7_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #include "bio.h" | ||
| 67 | #include "x509.h" | ||
| 68 | |||
| 69 | /* | ||
| 70 | Encryption_ID DES-CBC | ||
| 71 | Digest_ID MD5 | ||
| 72 | Digest_Encryption_ID rsaEncryption | ||
| 73 | Key_Encryption_ID rsaEncryption | ||
| 74 | */ | ||
| 75 | |||
| 76 | typedef struct pkcs7_issuer_and_serial_st | ||
| 77 | { | ||
| 78 | X509_NAME *issuer; | ||
| 79 | ASN1_INTEGER *serial; | ||
| 80 | } PKCS7_ISSUER_AND_SERIAL; | ||
| 81 | |||
| 82 | typedef struct pkcs7_signer_info_st | ||
| 83 | { | ||
| 84 | ASN1_INTEGER *version; /* version 1 */ | ||
| 85 | PKCS7_ISSUER_AND_SERIAL *issuer_and_serial; | ||
| 86 | X509_ALGOR *digest_alg; | ||
| 87 | STACK /* X509_ATTRIBUTE */ *auth_attr; /* [ 0 ] */ | ||
| 88 | X509_ALGOR *digest_enc_alg; | ||
| 89 | ASN1_OCTET_STRING *enc_digest; | ||
| 90 | STACK /* X509_ATTRIBUTE */ *unauth_attr; /* [ 1 ] */ | ||
| 91 | |||
| 92 | /* The private key to sign with */ | ||
| 93 | EVP_PKEY *pkey; | ||
| 94 | } PKCS7_SIGNER_INFO; | ||
| 95 | |||
| 96 | typedef struct pkcs7_recip_info_st | ||
| 97 | { | ||
| 98 | ASN1_INTEGER *version; /* version 0 */ | ||
| 99 | PKCS7_ISSUER_AND_SERIAL *issuer_and_serial; | ||
| 100 | X509_ALGOR *key_enc_algor; | ||
| 101 | ASN1_OCTET_STRING *enc_key; | ||
| 102 | X509 *cert; /* get the pub-key from this */ | ||
| 103 | } PKCS7_RECIP_INFO; | ||
| 104 | |||
| 105 | typedef struct pkcs7_signed_st | ||
| 106 | { | ||
| 107 | ASN1_INTEGER *version; /* version 1 */ | ||
| 108 | STACK /* X509_ALGOR's */ *md_algs; /* md used */ | ||
| 109 | STACK /* X509 */ *cert; /* [ 0 ] */ | ||
| 110 | STACK /* X509_CRL */ *crl; /* [ 1 ] */ | ||
| 111 | STACK /* PKCS7_SIGNER_INFO */ *signer_info; | ||
| 112 | |||
| 113 | struct pkcs7_st *contents; | ||
| 114 | } PKCS7_SIGNED; | ||
| 115 | /* The above structure is very very similar to PKCS7_SIGN_ENVELOPE. | ||
| 116 | * How about merging the two */ | ||
| 117 | |||
| 118 | typedef struct pkcs7_enc_content_st | ||
| 119 | { | ||
| 120 | ASN1_OBJECT *content_type; | ||
| 121 | X509_ALGOR *algorithm; | ||
| 122 | ASN1_OCTET_STRING *enc_data; /* [ 0 ] */ | ||
| 123 | } PKCS7_ENC_CONTENT; | ||
| 124 | |||
| 125 | typedef struct pkcs7_enveloped_st | ||
| 126 | { | ||
| 127 | ASN1_INTEGER *version; /* version 0 */ | ||
| 128 | STACK /* PKCS7_RECIP_INFO */ *recipientinfo; | ||
| 129 | PKCS7_ENC_CONTENT *enc_data; | ||
| 130 | } PKCS7_ENVELOPE; | ||
| 131 | |||
| 132 | typedef struct pkcs7_signedandenveloped_st | ||
| 133 | { | ||
| 134 | ASN1_INTEGER *version; /* version 1 */ | ||
| 135 | STACK /* X509_ALGOR's */ *md_algs; /* md used */ | ||
| 136 | STACK /* X509 */ *cert; /* [ 0 ] */ | ||
| 137 | STACK /* X509_CRL */ *crl; /* [ 1 ] */ | ||
| 138 | STACK /* PKCS7_SIGNER_INFO */ *signer_info; | ||
| 139 | |||
| 140 | PKCS7_ENC_CONTENT *enc_data; | ||
| 141 | STACK /* PKCS7_RECIP_INFO */ *recipientinfo; | ||
| 142 | } PKCS7_SIGN_ENVELOPE; | ||
| 143 | |||
| 144 | typedef struct pkcs7_digest_st | ||
| 145 | { | ||
| 146 | ASN1_INTEGER *version; /* version 0 */ | ||
| 147 | X509_ALGOR *md; /* md used */ | ||
| 148 | struct pkcs7_st *contents; | ||
| 149 | ASN1_OCTET_STRING *digest; | ||
| 150 | } PKCS7_DIGEST; | ||
| 151 | |||
| 152 | typedef struct pkcs7_encrypted_st | ||
| 153 | { | ||
| 154 | ASN1_INTEGER *version; /* version 0 */ | ||
| 155 | PKCS7_ENC_CONTENT *enc_data; | ||
| 156 | } PKCS7_ENCRYPT; | ||
| 157 | |||
| 158 | typedef struct pkcs7_st | ||
| 159 | { | ||
| 160 | /* The following is non NULL if it contains ASN1 encoding of | ||
| 161 | * this structure */ | ||
| 162 | unsigned char *asn1; | ||
| 163 | long length; | ||
| 164 | |||
| 165 | #define PKCS7_S_HEADER 0 | ||
| 166 | #define PKCS7_S_BODY 1 | ||
| 167 | #define PKCS7_S_TAIL 2 | ||
| 168 | int state; /* used during processing */ | ||
| 169 | |||
| 170 | int detached; | ||
| 171 | |||
| 172 | ASN1_OBJECT *type; | ||
| 173 | /* content as defined by the type */ | ||
| 174 | /* all encryption/message digests are applied to the 'contents', | ||
| 175 | * leaving out the 'type' field. */ | ||
| 176 | union { | ||
| 177 | char *ptr; | ||
| 178 | |||
| 179 | /* NID_pkcs7_data */ | ||
| 180 | ASN1_OCTET_STRING *data; | ||
| 181 | |||
| 182 | /* NID_pkcs7_signed */ | ||
| 183 | PKCS7_SIGNED *sign; | ||
| 184 | |||
| 185 | /* NID_pkcs7_enveloped */ | ||
| 186 | PKCS7_ENVELOPE *enveloped; | ||
| 187 | |||
| 188 | /* NID_pkcs7_signedAndEnveloped */ | ||
| 189 | PKCS7_SIGN_ENVELOPE *signed_and_enveloped; | ||
| 190 | |||
| 191 | /* NID_pkcs7_digest */ | ||
| 192 | PKCS7_DIGEST *digest; | ||
| 193 | |||
| 194 | /* NID_pkcs7_encrypted */ | ||
| 195 | PKCS7_ENCRYPT *encrypted; | ||
| 196 | } d; | ||
| 197 | } PKCS7; | ||
| 198 | |||
| 199 | #define PKCS7_OP_SET_DETACHED_SIGNATURE 1 | ||
| 200 | #define PKCS7_OP_GET_DETACHED_SIGNATURE 2 | ||
| 201 | |||
| 202 | #define PKCS7_type_is_signed(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_signed) | ||
| 203 | #define PKCS7_type_is_data(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_data) | ||
| 204 | |||
| 205 | #define PKCS7_set_detached(p,v) \ | ||
| 206 | PKCS7_ctrl(p,PKCS7_OP_SET_DETACHED_SIGNATURE,v,NULL) | ||
| 207 | #define PKCS7_get_detached(p) \ | ||
| 208 | PKCS7_ctrl(p,PKCS7_OP_GET_DETACHED_SIGNATURE,0,NULL) | ||
| 209 | |||
| 210 | #ifdef SSLEAY_MACROS | ||
| 211 | |||
| 212 | #define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \ | ||
| 213 | ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\ | ||
| 214 | (char *)data,md,len) | ||
| 215 | #endif | ||
| 216 | |||
| 217 | |||
| 218 | #ifndef NOPROTO | ||
| 219 | PKCS7_ISSUER_AND_SERIAL *PKCS7_ISSUER_AND_SERIAL_new(void ); | ||
| 220 | void PKCS7_ISSUER_AND_SERIAL_free( | ||
| 221 | PKCS7_ISSUER_AND_SERIAL *a); | ||
| 222 | int i2d_PKCS7_ISSUER_AND_SERIAL( | ||
| 223 | PKCS7_ISSUER_AND_SERIAL *a,unsigned char **pp); | ||
| 224 | PKCS7_ISSUER_AND_SERIAL *d2i_PKCS7_ISSUER_AND_SERIAL( | ||
| 225 | PKCS7_ISSUER_AND_SERIAL **a, | ||
| 226 | unsigned char **pp, long length); | ||
| 227 | |||
| 228 | #ifndef SSLEAY_MACROS | ||
| 229 | int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data,EVP_MD *type, | ||
| 230 | unsigned char *md,unsigned int *len); | ||
| 231 | #ifndef NO_FP_API | ||
| 232 | PKCS7 *d2i_PKCS7_fp(FILE *fp,PKCS7 *p7); | ||
| 233 | int i2d_PKCS7_fp(FILE *fp,PKCS7 *p7); | ||
| 234 | #endif | ||
| 235 | PKCS7 *PKCS7_dup(PKCS7 *p7); | ||
| 236 | PKCS7 *d2i_PKCS7_bio(BIO *bp,PKCS7 *p7); | ||
| 237 | int i2d_PKCS7_bio(BIO *bp,PKCS7 *p7); | ||
| 238 | #endif | ||
| 239 | |||
| 240 | PKCS7_SIGNER_INFO *PKCS7_SIGNER_INFO_new(void); | ||
| 241 | void PKCS7_SIGNER_INFO_free(PKCS7_SIGNER_INFO *a); | ||
| 242 | int i2d_PKCS7_SIGNER_INFO(PKCS7_SIGNER_INFO *a, | ||
| 243 | unsigned char **pp); | ||
| 244 | PKCS7_SIGNER_INFO *d2i_PKCS7_SIGNER_INFO(PKCS7_SIGNER_INFO **a, | ||
| 245 | unsigned char **pp,long length); | ||
| 246 | |||
| 247 | PKCS7_RECIP_INFO *PKCS7_RECIP_INFO_new(void); | ||
| 248 | void PKCS7_RECIP_INFO_free(PKCS7_RECIP_INFO *a); | ||
| 249 | int i2d_PKCS7_RECIP_INFO(PKCS7_RECIP_INFO *a, | ||
| 250 | unsigned char **pp); | ||
| 251 | PKCS7_RECIP_INFO *d2i_PKCS7_RECIP_INFO(PKCS7_RECIP_INFO **a, | ||
| 252 | unsigned char **pp,long length); | ||
| 253 | |||
| 254 | PKCS7_SIGNED *PKCS7_SIGNED_new(void); | ||
| 255 | void PKCS7_SIGNED_free(PKCS7_SIGNED *a); | ||
| 256 | int i2d_PKCS7_SIGNED(PKCS7_SIGNED *a, | ||
| 257 | unsigned char **pp); | ||
| 258 | PKCS7_SIGNED *d2i_PKCS7_SIGNED(PKCS7_SIGNED **a, | ||
| 259 | unsigned char **pp,long length); | ||
| 260 | |||
| 261 | PKCS7_ENC_CONTENT *PKCS7_ENC_CONTENT_new(void); | ||
| 262 | void PKCS7_ENC_CONTENT_free(PKCS7_ENC_CONTENT *a); | ||
| 263 | int i2d_PKCS7_ENC_CONTENT(PKCS7_ENC_CONTENT *a, | ||
| 264 | unsigned char **pp); | ||
| 265 | PKCS7_ENC_CONTENT *d2i_PKCS7_ENC_CONTENT(PKCS7_ENC_CONTENT **a, | ||
| 266 | unsigned char **pp,long length); | ||
| 267 | |||
| 268 | PKCS7_ENVELOPE *PKCS7_ENVELOPE_new(void); | ||
| 269 | void PKCS7_ENVELOPE_free(PKCS7_ENVELOPE *a); | ||
| 270 | int i2d_PKCS7_ENVELOPE(PKCS7_ENVELOPE *a, | ||
| 271 | unsigned char **pp); | ||
| 272 | PKCS7_ENVELOPE *d2i_PKCS7_ENVELOPE(PKCS7_ENVELOPE **a, | ||
| 273 | unsigned char **pp,long length); | ||
| 274 | |||
| 275 | PKCS7_SIGN_ENVELOPE *PKCS7_SIGN_ENVELOPE_new(void); | ||
| 276 | void PKCS7_SIGN_ENVELOPE_free(PKCS7_SIGN_ENVELOPE *a); | ||
| 277 | int i2d_PKCS7_SIGN_ENVELOPE(PKCS7_SIGN_ENVELOPE *a, | ||
| 278 | unsigned char **pp); | ||
| 279 | PKCS7_SIGN_ENVELOPE *d2i_PKCS7_SIGN_ENVELOPE(PKCS7_SIGN_ENVELOPE **a, | ||
| 280 | unsigned char **pp,long length); | ||
| 281 | |||
| 282 | PKCS7_DIGEST *PKCS7_DIGEST_new(void); | ||
| 283 | void PKCS7_DIGEST_free(PKCS7_DIGEST *a); | ||
| 284 | int i2d_PKCS7_DIGEST(PKCS7_DIGEST *a, | ||
| 285 | unsigned char **pp); | ||
| 286 | PKCS7_DIGEST *d2i_PKCS7_DIGEST(PKCS7_DIGEST **a, | ||
| 287 | unsigned char **pp,long length); | ||
| 288 | |||
| 289 | PKCS7_ENCRYPT *PKCS7_ENCRYPT_new(void); | ||
| 290 | void PKCS7_ENCRYPT_free(PKCS7_ENCRYPT *a); | ||
| 291 | int i2d_PKCS7_ENCRYPT(PKCS7_ENCRYPT *a, | ||
| 292 | unsigned char **pp); | ||
| 293 | PKCS7_ENCRYPT *d2i_PKCS7_ENCRYPT(PKCS7_ENCRYPT **a, | ||
| 294 | unsigned char **pp,long length); | ||
| 295 | |||
| 296 | PKCS7 *PKCS7_new(void); | ||
| 297 | void PKCS7_free(PKCS7 *a); | ||
| 298 | void PKCS7_content_free(PKCS7 *a); | ||
| 299 | int i2d_PKCS7(PKCS7 *a, | ||
| 300 | unsigned char **pp); | ||
| 301 | PKCS7 *d2i_PKCS7(PKCS7 **a, | ||
| 302 | unsigned char **pp,long length); | ||
| 303 | |||
| 304 | void ERR_load_PKCS7_strings(void); | ||
| 305 | |||
| 306 | |||
| 307 | long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg); | ||
| 308 | |||
| 309 | int PKCS7_set_type(PKCS7 *p7, int type); | ||
| 310 | int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data); | ||
| 311 | int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey, | ||
| 312 | EVP_MD *dgst); | ||
| 313 | int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *p7i); | ||
| 314 | int PKCS7_add_certificate(PKCS7 *p7, X509 *x509); | ||
| 315 | int PKCS7_add_crl(PKCS7 *p7, X509_CRL *x509); | ||
| 316 | int PKCS7_content_new(PKCS7 *p7, int nid); | ||
| 317 | int PKCS7_dataSign(PKCS7 *p7, BIO *bio); | ||
| 318 | int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, | ||
| 319 | BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si); | ||
| 320 | |||
| 321 | BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio); | ||
| 322 | /*int PKCS7_DataFinal(PKCS7 *p7, BIO *bio); */ | ||
| 323 | |||
| 324 | PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509, | ||
| 325 | EVP_PKEY *pkey, EVP_MD *dgst); | ||
| 326 | X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si); | ||
| 327 | STACK *PKCS7_get_signer_info(PKCS7 *p7); | ||
| 328 | |||
| 329 | PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509); | ||
| 330 | int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri); | ||
| 331 | int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509); | ||
| 332 | int PKCS7_set_cipher(PKCS7 *p7, EVP_CIPHER *cipher); | ||
| 333 | |||
| 334 | |||
| 335 | |||
| 336 | #else | ||
| 337 | |||
| 338 | PKCS7_ISSUER_AND_SERIAL *PKCS7_ISSUER_AND_SERIAL_new(); | ||
| 339 | void PKCS7_ISSUER_AND_SERIAL_free(); | ||
| 340 | int i2d_PKCS7_ISSUER_AND_SERIAL(); | ||
| 341 | PKCS7_ISSUER_AND_SERIAL *d2i_PKCS7_ISSUER_AND_SERIAL(); | ||
| 342 | |||
| 343 | #ifndef SSLEAY_MACROS | ||
| 344 | int PKCS7_ISSUER_AND_SERIAL_digest(); | ||
| 345 | #ifndef NO_FP_API | ||
| 346 | PKCS7 *d2i_PKCS7_fp(); | ||
| 347 | int i2d_PKCS7_fp(); | ||
| 348 | #endif | ||
| 349 | PKCS7 *PKCS7_dup(); | ||
| 350 | PKCS7 *d2i_PKCS7_bio(); | ||
| 351 | int i2d_PKCS7_bio(); | ||
| 352 | |||
| 353 | #endif | ||
| 354 | |||
| 355 | PKCS7_SIGNER_INFO *PKCS7_SIGNER_INFO_new(); | ||
| 356 | void PKCS7_SIGNER_INFO_free(); | ||
| 357 | int i2d_PKCS7_SIGNER_INFO(); | ||
| 358 | PKCS7_SIGNER_INFO *d2i_PKCS7_SIGNER_INFO(); | ||
| 359 | PKCS7_RECIP_INFO *PKCS7_RECIP_INFO_new(); | ||
| 360 | void PKCS7_RECIP_INFO_free(); | ||
| 361 | int i2d_PKCS7_RECIP_INFO(); | ||
| 362 | PKCS7_RECIP_INFO *d2i_PKCS7_RECIP_INFO(); | ||
| 363 | PKCS7_SIGNED *PKCS7_SIGNED_new(); | ||
| 364 | void PKCS7_SIGNED_free(); | ||
| 365 | int i2d_PKCS7_SIGNED(); | ||
| 366 | PKCS7_SIGNED *d2i_PKCS7_SIGNED(); | ||
| 367 | PKCS7_ENC_CONTENT *PKCS7_ENC_CONTENT_new(); | ||
| 368 | void PKCS7_ENC_CONTENT_free(); | ||
| 369 | int i2d_PKCS7_ENC_CONTENT(); | ||
| 370 | PKCS7_ENC_CONTENT *d2i_PKCS7_ENC_CONTENT(); | ||
| 371 | PKCS7_ENVELOPE *PKCS7_ENVELOPE_new(); | ||
| 372 | void PKCS7_ENVELOPE_free(); | ||
| 373 | int i2d_PKCS7_ENVELOPE(); | ||
| 374 | PKCS7_ENVELOPE *d2i_PKCS7_ENVELOPE(); | ||
| 375 | PKCS7_SIGN_ENVELOPE *PKCS7_SIGN_ENVELOPE_new(); | ||
| 376 | void PKCS7_SIGN_ENVELOPE_free(); | ||
| 377 | int i2d_PKCS7_SIGN_ENVELOPE(); | ||
| 378 | PKCS7_SIGN_ENVELOPE *d2i_PKCS7_SIGN_ENVELOPE(); | ||
| 379 | PKCS7_DIGEST *PKCS7_DIGEST_new(); | ||
| 380 | void PKCS7_DIGEST_free(); | ||
| 381 | int i2d_PKCS7_DIGEST(); | ||
| 382 | PKCS7_DIGEST *d2i_PKCS7_DIGEST(); | ||
| 383 | PKCS7_ENCRYPT *PKCS7_ENCRYPT_new(); | ||
| 384 | void PKCS7_ENCRYPT_free(); | ||
| 385 | int i2d_PKCS7_ENCRYPT(); | ||
| 386 | PKCS7_ENCRYPT *d2i_PKCS7_ENCRYPT(); | ||
| 387 | PKCS7 *PKCS7_new(); | ||
| 388 | void PKCS7_free(); | ||
| 389 | void PKCS7_content_free(); | ||
| 390 | int i2d_PKCS7(); | ||
| 391 | PKCS7 *d2i_PKCS7(); | ||
| 392 | |||
| 393 | void ERR_load_PKCS7_strings(); | ||
| 394 | |||
| 395 | long PKCS7_ctrl(); | ||
| 396 | int PKCS7_set_type(); | ||
| 397 | int PKCS7_set_content(); | ||
| 398 | int PKCS7_SIGNER_INFO_set(); | ||
| 399 | int PKCS7_add_signer(); | ||
| 400 | int PKCS7_add_certificate(); | ||
| 401 | int PKCS7_add_crl(); | ||
| 402 | int PKCS7_content_new(); | ||
| 403 | int PKCS7_dataSign(); | ||
| 404 | int PKCS7_dataVerify(); | ||
| 405 | BIO *PKCS7_dataInit(); | ||
| 406 | PKCS7_SIGNER_INFO *PKCS7_add_signature(); | ||
| 407 | X509 *PKCS7_cert_from_signer_info(); | ||
| 408 | STACK *PKCS7_get_signer_info(); | ||
| 409 | |||
| 410 | PKCS7_RECIP_INFO *PKCS7_add_recipient(); | ||
| 411 | int PKCS7_add_recipient_info(); | ||
| 412 | int PKCS7_RECIP_INFO_set(); | ||
| 413 | int PKCS7_set_cipher(); | ||
| 414 | |||
| 415 | #endif | ||
| 416 | |||
| 417 | /* BEGIN ERROR CODES */ | ||
| 418 | /* Error codes for the PKCS7 functions. */ | ||
| 419 | |||
| 420 | /* Function codes. */ | ||
| 421 | #define PKCS7_F_PKCS7_ADD_CERTIFICATE 100 | ||
| 422 | #define PKCS7_F_PKCS7_ADD_CRL 101 | ||
| 423 | #define PKCS7_F_PKCS7_ADD_RECIPIENT_INFO 102 | ||
| 424 | #define PKCS7_F_PKCS7_ADD_SIGNER 103 | ||
| 425 | #define PKCS7_F_PKCS7_CTRL 104 | ||
| 426 | #define PKCS7_F_PKCS7_DATAINIT 105 | ||
| 427 | #define PKCS7_F_PKCS7_DATASIGN 106 | ||
| 428 | #define PKCS7_F_PKCS7_DATAVERIFY 107 | ||
| 429 | #define PKCS7_F_PKCS7_SET_CIPHER 108 | ||
| 430 | #define PKCS7_F_PKCS7_SET_CONTENT 109 | ||
| 431 | #define PKCS7_F_PKCS7_SET_TYPE 110 | ||
| 432 | |||
| 433 | /* Reason codes. */ | ||
| 434 | #define PKCS7_R_INTERNAL_ERROR 100 | ||
| 435 | #define PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE 101 | ||
| 436 | #define PKCS7_R_SIGNATURE_FAILURE 102 | ||
| 437 | #define PKCS7_R_UNABLE_TO_FIND_CERTIFICATE 103 | ||
| 438 | #define PKCS7_R_UNABLE_TO_FIND_MEM_BIO 104 | ||
| 439 | #define PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST 105 | ||
| 440 | #define PKCS7_R_UNKNOWN_DIGEST_TYPE 106 | ||
| 441 | #define PKCS7_R_UNSUPPORTED_CIPHER_TYPE 107 | ||
| 442 | #define PKCS7_R_UNSUPPORTED_CONTENT_TYPE 108 | ||
| 443 | #define PKCS7_R_WRONG_CONTENT_TYPE 109 | ||
| 444 | |||
| 445 | #ifdef __cplusplus | ||
| 446 | } | ||
| 447 | #endif | ||
| 448 | #endif | ||
| 449 | |||
diff --git a/src/lib/libcrypto/pkcs7/pkcs7err.c b/src/lib/libcrypto/pkcs7/pkcs7err.c new file mode 100644 index 0000000000..f851057422 --- /dev/null +++ b/src/lib/libcrypto/pkcs7/pkcs7err.c | |||
| @@ -0,0 +1,110 @@ | |||
| 1 | /* lib/pkcs7/pkcs7_err.c */ | ||
| 2 | /* Copyright (C) 1995-1997 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 | #include <stdio.h> | ||
| 59 | #include "err.h" | ||
| 60 | #include "pkcs7.h" | ||
| 61 | |||
| 62 | /* BEGIN ERROR CODES */ | ||
| 63 | #ifndef NO_ERR | ||
| 64 | static ERR_STRING_DATA PKCS7_str_functs[]= | ||
| 65 | { | ||
| 66 | {ERR_PACK(0,PKCS7_F_PKCS7_ADD_CERTIFICATE,0), "PKCS7_add_certificate"}, | ||
| 67 | {ERR_PACK(0,PKCS7_F_PKCS7_ADD_CRL,0), "PKCS7_add_crl"}, | ||
| 68 | {ERR_PACK(0,PKCS7_F_PKCS7_ADD_RECIPIENT_INFO,0), "PKCS7_add_recipient_info"}, | ||
| 69 | {ERR_PACK(0,PKCS7_F_PKCS7_ADD_SIGNER,0), "PKCS7_add_signer"}, | ||
| 70 | {ERR_PACK(0,PKCS7_F_PKCS7_CTRL,0), "PKCS7_ctrl"}, | ||
| 71 | {ERR_PACK(0,PKCS7_F_PKCS7_DATAINIT,0), "PKCS7_dataInit"}, | ||
| 72 | {ERR_PACK(0,PKCS7_F_PKCS7_DATASIGN,0), "PKCS7_dataSign"}, | ||
| 73 | {ERR_PACK(0,PKCS7_F_PKCS7_DATAVERIFY,0), "PKCS7_dataVerify"}, | ||
| 74 | {ERR_PACK(0,PKCS7_F_PKCS7_SET_CIPHER,0), "PKCS7_set_cipher"}, | ||
| 75 | {ERR_PACK(0,PKCS7_F_PKCS7_SET_CONTENT,0), "PKCS7_set_content"}, | ||
| 76 | {ERR_PACK(0,PKCS7_F_PKCS7_SET_TYPE,0), "PKCS7_set_type"}, | ||
| 77 | {0,NULL}, | ||
| 78 | }; | ||
| 79 | |||
| 80 | static ERR_STRING_DATA PKCS7_str_reasons[]= | ||
| 81 | { | ||
| 82 | {PKCS7_R_INTERNAL_ERROR ,"internal error"}, | ||
| 83 | {PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE,"operation not supported on this type"}, | ||
| 84 | {PKCS7_R_SIGNATURE_FAILURE ,"signature failure"}, | ||
| 85 | {PKCS7_R_UNABLE_TO_FIND_CERTIFICATE ,"unable to find certificate"}, | ||
| 86 | {PKCS7_R_UNABLE_TO_FIND_MEM_BIO ,"unable to find mem bio"}, | ||
| 87 | {PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST ,"unable to find message digest"}, | ||
| 88 | {PKCS7_R_UNKNOWN_DIGEST_TYPE ,"unknown digest type"}, | ||
| 89 | {PKCS7_R_UNSUPPORTED_CIPHER_TYPE ,"unsupported cipher type"}, | ||
| 90 | {PKCS7_R_UNSUPPORTED_CONTENT_TYPE ,"unsupported content type"}, | ||
| 91 | {PKCS7_R_WRONG_CONTENT_TYPE ,"wrong content type"}, | ||
| 92 | {0,NULL}, | ||
| 93 | }; | ||
| 94 | |||
| 95 | #endif | ||
| 96 | |||
| 97 | void ERR_load_PKCS7_strings() | ||
| 98 | { | ||
| 99 | static int init=1; | ||
| 100 | |||
| 101 | if (init); | ||
| 102 | {; | ||
| 103 | init=0; | ||
| 104 | #ifndef NO_ERR | ||
| 105 | ERR_load_strings(ERR_LIB_PKCS7,PKCS7_str_functs); | ||
| 106 | ERR_load_strings(ERR_LIB_PKCS7,PKCS7_str_reasons); | ||
| 107 | #endif | ||
| 108 | |||
| 109 | } | ||
| 110 | } | ||
diff --git a/src/lib/libcrypto/rand/rand.h b/src/lib/libcrypto/rand/rand.h new file mode 100644 index 0000000000..477d7a150a --- /dev/null +++ b/src/lib/libcrypto/rand/rand.h | |||
| @@ -0,0 +1,92 @@ | |||
| 1 | /* crypto/rand/rand.h */ | ||
| 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 | #ifndef HEADER_RAND_H | ||
| 60 | #define HEADER_RAND_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #ifndef NOPROTO | ||
| 67 | void RAND_cleanup(void ); | ||
| 68 | void RAND_bytes( unsigned char *buf,int num); | ||
| 69 | void RAND_seed( unsigned char *buf,int num); | ||
| 70 | int RAND_load_file(char *file,long max_bytes); | ||
| 71 | int RAND_write_file(char *file); | ||
| 72 | char *RAND_file_name(char *file,int num); | ||
| 73 | #ifdef WINDOWS | ||
| 74 | void RAND_screen(void); | ||
| 75 | #endif | ||
| 76 | #else | ||
| 77 | void RAND_cleanup(); | ||
| 78 | void RAND_bytes(); | ||
| 79 | void RAND_seed(); | ||
| 80 | int RAND_load_file(); | ||
| 81 | int RAND_write_file(); | ||
| 82 | char *RAND_file_name(); | ||
| 83 | #ifdef WINDOWS | ||
| 84 | void RAND_screen(); | ||
| 85 | #endif | ||
| 86 | #endif | ||
| 87 | |||
| 88 | #ifdef __cplusplus | ||
| 89 | } | ||
| 90 | #endif | ||
| 91 | |||
| 92 | #endif | ||
diff --git a/src/lib/libcrypto/rand/randfile.c b/src/lib/libcrypto/rand/randfile.c new file mode 100644 index 0000000000..f2b3746363 --- /dev/null +++ b/src/lib/libcrypto/rand/randfile.c | |||
| @@ -0,0 +1,166 @@ | |||
| 1 | /* crypto/rand/randfile.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 <sys/stat.h> | ||
| 62 | #include <sys/types.h> | ||
| 63 | #include "rand.h" | ||
| 64 | |||
| 65 | #undef BUFSIZE | ||
| 66 | #define BUFSIZE 1024 | ||
| 67 | #define RAND_DATA 1024 | ||
| 68 | |||
| 69 | /* #define RFILE ".rand" - defined in ../../e_os.h */ | ||
| 70 | |||
| 71 | int RAND_load_file(file,bytes) | ||
| 72 | char *file; | ||
| 73 | long bytes; | ||
| 74 | { | ||
| 75 | MS_STATIC unsigned char buf[BUFSIZE]; | ||
| 76 | struct stat sb; | ||
| 77 | int i,ret=0,n; | ||
| 78 | FILE *in; | ||
| 79 | |||
| 80 | if (file == NULL) return(0); | ||
| 81 | |||
| 82 | i=stat(file,&sb); | ||
| 83 | /* If the state fails, put some crap in anyway */ | ||
| 84 | RAND_seed((unsigned char *)&sb,sizeof(sb)); | ||
| 85 | ret+=sizeof(sb); | ||
| 86 | if (i < 0) return(0); | ||
| 87 | if (bytes <= 0) return(ret); | ||
| 88 | |||
| 89 | in=fopen(file,"r"); | ||
| 90 | if (in == NULL) goto err; | ||
| 91 | for (;;) | ||
| 92 | { | ||
| 93 | n=(bytes < BUFSIZE)?(int)bytes:BUFSIZE; | ||
| 94 | i=fread(buf,1,n,in); | ||
| 95 | if (i <= 0) break; | ||
| 96 | /* even if n != i, use the full array */ | ||
| 97 | RAND_seed(buf,n); | ||
| 98 | ret+=i; | ||
| 99 | bytes-=n; | ||
| 100 | if (bytes <= 0) break; | ||
| 101 | } | ||
| 102 | fclose(in); | ||
| 103 | memset(buf,0,BUFSIZE); | ||
| 104 | err: | ||
| 105 | return(ret); | ||
| 106 | } | ||
| 107 | |||
| 108 | int RAND_write_file(file) | ||
| 109 | char *file; | ||
| 110 | { | ||
| 111 | unsigned char buf[BUFSIZE]; | ||
| 112 | int i,ret=0; | ||
| 113 | FILE *out; | ||
| 114 | int n; | ||
| 115 | |||
| 116 | out=fopen(file,"w"); | ||
| 117 | if (out == NULL) goto err; | ||
| 118 | chmod(file,0600); | ||
| 119 | n=RAND_DATA; | ||
| 120 | for (;;) | ||
| 121 | { | ||
| 122 | i=(n > BUFSIZE)?BUFSIZE:n; | ||
| 123 | n-=BUFSIZE; | ||
| 124 | RAND_bytes(buf,i); | ||
| 125 | i=fwrite(buf,1,i,out); | ||
| 126 | if (i <= 0) | ||
| 127 | { | ||
| 128 | ret=0; | ||
| 129 | break; | ||
| 130 | } | ||
| 131 | ret+=i; | ||
| 132 | if (n <= 0) break; | ||
| 133 | } | ||
| 134 | fclose(out); | ||
| 135 | memset(buf,0,BUFSIZE); | ||
| 136 | err: | ||
| 137 | return(ret); | ||
| 138 | } | ||
| 139 | |||
| 140 | char *RAND_file_name(buf,size) | ||
| 141 | char *buf; | ||
| 142 | int size; | ||
| 143 | { | ||
| 144 | char *s; | ||
| 145 | char *ret=NULL; | ||
| 146 | |||
| 147 | s=getenv("RANDFILE"); | ||
| 148 | if (s != NULL) | ||
| 149 | { | ||
| 150 | strncpy(buf,s,size-1); | ||
| 151 | buf[size-1]='\0'; | ||
| 152 | ret=buf; | ||
| 153 | } | ||
| 154 | else | ||
| 155 | { | ||
| 156 | s=getenv("HOME"); | ||
| 157 | if (s == NULL) return(RFILE); | ||
| 158 | if (((int)(strlen(s)+strlen(RFILE)+2)) > size) | ||
| 159 | return(RFILE); | ||
| 160 | strcpy(buf,s); | ||
| 161 | strcat(buf,"/"); | ||
| 162 | strcat(buf,RFILE); | ||
| 163 | ret=buf; | ||
| 164 | } | ||
| 165 | return(ret); | ||
| 166 | } | ||
diff --git a/src/lib/libcrypto/rc2/rc2_cbc.c b/src/lib/libcrypto/rc2/rc2_cbc.c new file mode 100644 index 0000000000..22e89f0441 --- /dev/null +++ b/src/lib/libcrypto/rc2/rc2_cbc.c | |||
| @@ -0,0 +1,235 @@ | |||
| 1 | /* crypto/rc2/rc2_cbc.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 "rc2.h" | ||
| 60 | #include "rc2_locl.h" | ||
| 61 | |||
| 62 | void RC2_cbc_encrypt(in, out, length, ks, iv, encrypt) | ||
| 63 | unsigned char *in; | ||
| 64 | unsigned char *out; | ||
| 65 | long length; | ||
| 66 | RC2_KEY *ks; | ||
| 67 | unsigned char *iv; | ||
| 68 | int encrypt; | ||
| 69 | { | ||
| 70 | register unsigned long tin0,tin1; | ||
| 71 | register unsigned long tout0,tout1,xor0,xor1; | ||
| 72 | register long l=length; | ||
| 73 | unsigned long tin[2]; | ||
| 74 | |||
| 75 | if (encrypt) | ||
| 76 | { | ||
| 77 | c2l(iv,tout0); | ||
| 78 | c2l(iv,tout1); | ||
| 79 | iv-=8; | ||
| 80 | for (l-=8; l>=0; l-=8) | ||
| 81 | { | ||
| 82 | c2l(in,tin0); | ||
| 83 | c2l(in,tin1); | ||
| 84 | tin0^=tout0; | ||
| 85 | tin1^=tout1; | ||
| 86 | tin[0]=tin0; | ||
| 87 | tin[1]=tin1; | ||
| 88 | RC2_encrypt(tin,ks); | ||
| 89 | tout0=tin[0]; l2c(tout0,out); | ||
| 90 | tout1=tin[1]; l2c(tout1,out); | ||
| 91 | } | ||
| 92 | if (l != -8) | ||
| 93 | { | ||
| 94 | c2ln(in,tin0,tin1,l+8); | ||
| 95 | tin0^=tout0; | ||
| 96 | tin1^=tout1; | ||
| 97 | tin[0]=tin0; | ||
| 98 | tin[1]=tin1; | ||
| 99 | RC2_encrypt(tin,ks); | ||
| 100 | tout0=tin[0]; l2c(tout0,out); | ||
| 101 | tout1=tin[1]; l2c(tout1,out); | ||
| 102 | } | ||
| 103 | l2c(tout0,iv); | ||
| 104 | l2c(tout1,iv); | ||
| 105 | } | ||
| 106 | else | ||
| 107 | { | ||
| 108 | c2l(iv,xor0); | ||
| 109 | c2l(iv,xor1); | ||
| 110 | iv-=8; | ||
| 111 | for (l-=8; l>=0; l-=8) | ||
| 112 | { | ||
| 113 | c2l(in,tin0); tin[0]=tin0; | ||
| 114 | c2l(in,tin1); tin[1]=tin1; | ||
| 115 | RC2_decrypt(tin,ks); | ||
| 116 | tout0=tin[0]^xor0; | ||
| 117 | tout1=tin[1]^xor1; | ||
| 118 | l2c(tout0,out); | ||
| 119 | l2c(tout1,out); | ||
| 120 | xor0=tin0; | ||
| 121 | xor1=tin1; | ||
| 122 | } | ||
| 123 | if (l != -8) | ||
| 124 | { | ||
| 125 | c2l(in,tin0); tin[0]=tin0; | ||
| 126 | c2l(in,tin1); tin[1]=tin1; | ||
| 127 | RC2_decrypt(tin,ks); | ||
| 128 | tout0=tin[0]^xor0; | ||
| 129 | tout1=tin[1]^xor1; | ||
| 130 | l2cn(tout0,tout1,out,l+8); | ||
| 131 | xor0=tin0; | ||
| 132 | xor1=tin1; | ||
| 133 | } | ||
| 134 | l2c(xor0,iv); | ||
| 135 | l2c(xor1,iv); | ||
| 136 | } | ||
| 137 | tin0=tin1=tout0=tout1=xor0=xor1=0; | ||
| 138 | tin[0]=tin[1]=0; | ||
| 139 | } | ||
| 140 | |||
| 141 | void RC2_encrypt(d,key) | ||
| 142 | unsigned long *d; | ||
| 143 | RC2_KEY *key; | ||
| 144 | { | ||
| 145 | int i,n; | ||
| 146 | register RC2_INT *p0,*p1; | ||
| 147 | register RC2_INT x0,x1,x2,x3,t; | ||
| 148 | unsigned long l; | ||
| 149 | |||
| 150 | l=d[0]; | ||
| 151 | x0=(RC2_INT)l&0xffff; | ||
| 152 | x1=(RC2_INT)(l>>16L); | ||
| 153 | l=d[1]; | ||
| 154 | x2=(RC2_INT)l&0xffff; | ||
| 155 | x3=(RC2_INT)(l>>16L); | ||
| 156 | |||
| 157 | n=3; | ||
| 158 | i=5; | ||
| 159 | |||
| 160 | p0=p1= &(key->data[0]); | ||
| 161 | for (;;) | ||
| 162 | { | ||
| 163 | t=(x0+(x1& ~x3)+(x2&x3)+ *(p0++))&0xffff; | ||
| 164 | x0=(t<<1)|(t>>15); | ||
| 165 | t=(x1+(x2& ~x0)+(x3&x0)+ *(p0++))&0xffff; | ||
| 166 | x1=(t<<2)|(t>>14); | ||
| 167 | t=(x2+(x3& ~x1)+(x0&x1)+ *(p0++))&0xffff; | ||
| 168 | x2=(t<<3)|(t>>13); | ||
| 169 | t=(x3+(x0& ~x2)+(x1&x2)+ *(p0++))&0xffff; | ||
| 170 | x3=(t<<5)|(t>>11); | ||
| 171 | |||
| 172 | if (--i == 0) | ||
| 173 | { | ||
| 174 | if (--n == 0) break; | ||
| 175 | i=(n == 2)?6:5; | ||
| 176 | |||
| 177 | x0+=p1[x3&0x3f]; | ||
| 178 | x1+=p1[x0&0x3f]; | ||
| 179 | x2+=p1[x1&0x3f]; | ||
| 180 | x3+=p1[x2&0x3f]; | ||
| 181 | } | ||
| 182 | } | ||
| 183 | |||
| 184 | d[0]=(unsigned long)(x0&0xffff)|((unsigned long)(x1&0xffff)<<16L); | ||
| 185 | d[1]=(unsigned long)(x2&0xffff)|((unsigned long)(x3&0xffff)<<16L); | ||
| 186 | } | ||
| 187 | |||
| 188 | void RC2_decrypt(d,key) | ||
| 189 | unsigned long *d; | ||
| 190 | RC2_KEY *key; | ||
| 191 | { | ||
| 192 | int i,n; | ||
| 193 | register RC2_INT *p0,*p1; | ||
| 194 | register RC2_INT x0,x1,x2,x3,t; | ||
| 195 | unsigned long l; | ||
| 196 | |||
| 197 | l=d[0]; | ||
| 198 | x0=(RC2_INT)l&0xffff; | ||
| 199 | x1=(RC2_INT)(l>>16L); | ||
| 200 | l=d[1]; | ||
| 201 | x2=(RC2_INT)l&0xffff; | ||
| 202 | x3=(RC2_INT)(l>>16L); | ||
| 203 | |||
| 204 | n=3; | ||
| 205 | i=5; | ||
| 206 | |||
| 207 | p0= &(key->data[63]); | ||
| 208 | p1= &(key->data[0]); | ||
| 209 | for (;;) | ||
| 210 | { | ||
| 211 | t=((x3<<11)|(x3>>5))&0xffff; | ||
| 212 | x3=(t-(x0& ~x2)-(x1&x2)- *(p0--))&0xffff; | ||
| 213 | t=((x2<<13)|(x2>>3))&0xffff; | ||
| 214 | x2=(t-(x3& ~x1)-(x0&x1)- *(p0--))&0xffff; | ||
| 215 | t=((x1<<14)|(x1>>2))&0xffff; | ||
| 216 | x1=(t-(x2& ~x0)-(x3&x0)- *(p0--))&0xffff; | ||
| 217 | t=((x0<<15)|(x0>>1))&0xffff; | ||
| 218 | x0=(t-(x1& ~x3)-(x2&x3)- *(p0--))&0xffff; | ||
| 219 | |||
| 220 | if (--i == 0) | ||
| 221 | { | ||
| 222 | if (--n == 0) break; | ||
| 223 | i=(n == 2)?6:5; | ||
| 224 | |||
| 225 | x3=(x3-p1[x2&0x3f])&0xffff; | ||
| 226 | x2=(x2-p1[x1&0x3f])&0xffff; | ||
| 227 | x1=(x1-p1[x0&0x3f])&0xffff; | ||
| 228 | x0=(x0-p1[x3&0x3f])&0xffff; | ||
| 229 | } | ||
| 230 | } | ||
| 231 | |||
| 232 | d[0]=(unsigned long)(x0&0xffff)|((unsigned long)(x1&0xffff)<<16L); | ||
| 233 | d[1]=(unsigned long)(x2&0xffff)|((unsigned long)(x3&0xffff)<<16L); | ||
| 234 | } | ||
| 235 | |||
diff --git a/src/lib/libcrypto/rc2/rc2_ecb.c b/src/lib/libcrypto/rc2/rc2_ecb.c new file mode 100644 index 0000000000..96239cd4e0 --- /dev/null +++ b/src/lib/libcrypto/rc2/rc2_ecb.c | |||
| @@ -0,0 +1,90 @@ | |||
| 1 | /* crypto/rc2/rc2_ecb.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 "rc2.h" | ||
| 60 | #include "rc2_locl.h" | ||
| 61 | |||
| 62 | char *RC2_version="RC2 part of SSLeay 0.9.0b 29-Jun-1998"; | ||
| 63 | |||
| 64 | /* RC2 as implemented frm a posting from | ||
| 65 | * Newsgroups: sci.crypt | ||
| 66 | * Sender: pgut01@cs.auckland.ac.nz (Peter Gutmann) | ||
| 67 | * Subject: Specification for Ron Rivests Cipher No.2 | ||
| 68 | * Message-ID: <4fk39f$f70@net.auckland.ac.nz> | ||
| 69 | * Date: 11 Feb 1996 06:45:03 GMT | ||
| 70 | */ | ||
| 71 | |||
| 72 | void RC2_ecb_encrypt(in, out, ks, encrypt) | ||
| 73 | unsigned char *in; | ||
| 74 | unsigned char *out; | ||
| 75 | RC2_KEY *ks; | ||
| 76 | int encrypt; | ||
| 77 | { | ||
| 78 | unsigned long l,d[2]; | ||
| 79 | |||
| 80 | c2l(in,l); d[0]=l; | ||
| 81 | c2l(in,l); d[1]=l; | ||
| 82 | if (encrypt) | ||
| 83 | RC2_encrypt(d,ks); | ||
| 84 | else | ||
| 85 | RC2_decrypt(d,ks); | ||
| 86 | l=d[0]; l2c(l,out); | ||
| 87 | l=d[1]; l2c(l,out); | ||
| 88 | l=d[0]=d[1]=0; | ||
| 89 | } | ||
| 90 | |||
diff --git a/src/lib/libcrypto/rc2/rc2_locl.h b/src/lib/libcrypto/rc2/rc2_locl.h new file mode 100644 index 0000000000..565cd17619 --- /dev/null +++ b/src/lib/libcrypto/rc2/rc2_locl.h | |||
| @@ -0,0 +1,156 @@ | |||
| 1 | /* crypto/rc2/rc2_locl.h */ | ||
| 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 | #undef c2l | ||
| 60 | #define c2l(c,l) (l =((unsigned long)(*((c)++))) , \ | ||
| 61 | l|=((unsigned long)(*((c)++)))<< 8L, \ | ||
| 62 | l|=((unsigned long)(*((c)++)))<<16L, \ | ||
| 63 | l|=((unsigned long)(*((c)++)))<<24L) | ||
| 64 | |||
| 65 | /* NOTE - c is not incremented as per c2l */ | ||
| 66 | #undef c2ln | ||
| 67 | #define c2ln(c,l1,l2,n) { \ | ||
| 68 | c+=n; \ | ||
| 69 | l1=l2=0; \ | ||
| 70 | switch (n) { \ | ||
| 71 | case 8: l2 =((unsigned long)(*(--(c))))<<24L; \ | ||
| 72 | case 7: l2|=((unsigned long)(*(--(c))))<<16L; \ | ||
| 73 | case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \ | ||
| 74 | case 5: l2|=((unsigned long)(*(--(c)))); \ | ||
| 75 | case 4: l1 =((unsigned long)(*(--(c))))<<24L; \ | ||
| 76 | case 3: l1|=((unsigned long)(*(--(c))))<<16L; \ | ||
| 77 | case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \ | ||
| 78 | case 1: l1|=((unsigned long)(*(--(c)))); \ | ||
| 79 | } \ | ||
| 80 | } | ||
| 81 | |||
| 82 | #undef l2c | ||
| 83 | #define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ | ||
| 84 | *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ | ||
| 85 | *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ | ||
| 86 | *((c)++)=(unsigned char)(((l)>>24L)&0xff)) | ||
| 87 | |||
| 88 | /* NOTE - c is not incremented as per l2c */ | ||
| 89 | #undef l2cn | ||
| 90 | #define l2cn(l1,l2,c,n) { \ | ||
| 91 | c+=n; \ | ||
| 92 | switch (n) { \ | ||
| 93 | case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \ | ||
| 94 | case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \ | ||
| 95 | case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \ | ||
| 96 | case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \ | ||
| 97 | case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \ | ||
| 98 | case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \ | ||
| 99 | case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \ | ||
| 100 | case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \ | ||
| 101 | } \ | ||
| 102 | } | ||
| 103 | |||
| 104 | /* NOTE - c is not incremented as per n2l */ | ||
| 105 | #define n2ln(c,l1,l2,n) { \ | ||
| 106 | c+=n; \ | ||
| 107 | l1=l2=0; \ | ||
| 108 | switch (n) { \ | ||
| 109 | case 8: l2 =((unsigned long)(*(--(c)))) ; \ | ||
| 110 | case 7: l2|=((unsigned long)(*(--(c))))<< 8; \ | ||
| 111 | case 6: l2|=((unsigned long)(*(--(c))))<<16; \ | ||
| 112 | case 5: l2|=((unsigned long)(*(--(c))))<<24; \ | ||
| 113 | case 4: l1 =((unsigned long)(*(--(c)))) ; \ | ||
| 114 | case 3: l1|=((unsigned long)(*(--(c))))<< 8; \ | ||
| 115 | case 2: l1|=((unsigned long)(*(--(c))))<<16; \ | ||
| 116 | case 1: l1|=((unsigned long)(*(--(c))))<<24; \ | ||
| 117 | } \ | ||
| 118 | } | ||
| 119 | |||
| 120 | /* NOTE - c is not incremented as per l2n */ | ||
| 121 | #define l2nn(l1,l2,c,n) { \ | ||
| 122 | c+=n; \ | ||
| 123 | switch (n) { \ | ||
| 124 | case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \ | ||
| 125 | case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \ | ||
| 126 | case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \ | ||
| 127 | case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \ | ||
| 128 | case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \ | ||
| 129 | case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \ | ||
| 130 | case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \ | ||
| 131 | case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \ | ||
| 132 | } \ | ||
| 133 | } | ||
| 134 | |||
| 135 | #undef n2l | ||
| 136 | #define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \ | ||
| 137 | l|=((unsigned long)(*((c)++)))<<16L, \ | ||
| 138 | l|=((unsigned long)(*((c)++)))<< 8L, \ | ||
| 139 | l|=((unsigned long)(*((c)++)))) | ||
| 140 | |||
| 141 | #undef l2n | ||
| 142 | #define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \ | ||
| 143 | *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ | ||
| 144 | *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ | ||
| 145 | *((c)++)=(unsigned char)(((l) )&0xff)) | ||
| 146 | |||
| 147 | #define C_RC2(n) \ | ||
| 148 | t=(x0+(x1& ~x3)+(x2&x3)+ *(p0++))&0xffff; \ | ||
| 149 | x0=(t<<1)|(t>>15); \ | ||
| 150 | t=(x1+(x2& ~x0)+(x3&x0)+ *(p0++))&0xffff; \ | ||
| 151 | x1=(t<<2)|(t>>14); \ | ||
| 152 | t=(x2+(x3& ~x1)+(x0&x1)+ *(p0++))&0xffff; \ | ||
| 153 | x2=(t<<3)|(t>>13); \ | ||
| 154 | t=(x3+(x0& ~x2)+(x1&x2)+ *(p0++))&0xffff; \ | ||
| 155 | x3=(t<<5)|(t>>11); | ||
| 156 | |||
diff --git a/src/lib/libcrypto/rc2/rc2_skey.c b/src/lib/libcrypto/rc2/rc2_skey.c new file mode 100644 index 0000000000..0f1f253395 --- /dev/null +++ b/src/lib/libcrypto/rc2/rc2_skey.c | |||
| @@ -0,0 +1,142 @@ | |||
| 1 | /* crypto/rc2/rc2_skey.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 "rc2.h" | ||
| 60 | #include "rc2_locl.h" | ||
| 61 | |||
| 62 | static unsigned char key_table[256]={ | ||
| 63 | 0xd9,0x78,0xf9,0xc4,0x19,0xdd,0xb5,0xed,0x28,0xe9,0xfd,0x79, | ||
| 64 | 0x4a,0xa0,0xd8,0x9d,0xc6,0x7e,0x37,0x83,0x2b,0x76,0x53,0x8e, | ||
| 65 | 0x62,0x4c,0x64,0x88,0x44,0x8b,0xfb,0xa2,0x17,0x9a,0x59,0xf5, | ||
| 66 | 0x87,0xb3,0x4f,0x13,0x61,0x45,0x6d,0x8d,0x09,0x81,0x7d,0x32, | ||
| 67 | 0xbd,0x8f,0x40,0xeb,0x86,0xb7,0x7b,0x0b,0xf0,0x95,0x21,0x22, | ||
| 68 | 0x5c,0x6b,0x4e,0x82,0x54,0xd6,0x65,0x93,0xce,0x60,0xb2,0x1c, | ||
| 69 | 0x73,0x56,0xc0,0x14,0xa7,0x8c,0xf1,0xdc,0x12,0x75,0xca,0x1f, | ||
| 70 | 0x3b,0xbe,0xe4,0xd1,0x42,0x3d,0xd4,0x30,0xa3,0x3c,0xb6,0x26, | ||
| 71 | 0x6f,0xbf,0x0e,0xda,0x46,0x69,0x07,0x57,0x27,0xf2,0x1d,0x9b, | ||
| 72 | 0xbc,0x94,0x43,0x03,0xf8,0x11,0xc7,0xf6,0x90,0xef,0x3e,0xe7, | ||
| 73 | 0x06,0xc3,0xd5,0x2f,0xc8,0x66,0x1e,0xd7,0x08,0xe8,0xea,0xde, | ||
| 74 | 0x80,0x52,0xee,0xf7,0x84,0xaa,0x72,0xac,0x35,0x4d,0x6a,0x2a, | ||
| 75 | 0x96,0x1a,0xd2,0x71,0x5a,0x15,0x49,0x74,0x4b,0x9f,0xd0,0x5e, | ||
| 76 | 0x04,0x18,0xa4,0xec,0xc2,0xe0,0x41,0x6e,0x0f,0x51,0xcb,0xcc, | ||
| 77 | 0x24,0x91,0xaf,0x50,0xa1,0xf4,0x70,0x39,0x99,0x7c,0x3a,0x85, | ||
| 78 | 0x23,0xb8,0xb4,0x7a,0xfc,0x02,0x36,0x5b,0x25,0x55,0x97,0x31, | ||
| 79 | 0x2d,0x5d,0xfa,0x98,0xe3,0x8a,0x92,0xae,0x05,0xdf,0x29,0x10, | ||
| 80 | 0x67,0x6c,0xba,0xc9,0xd3,0x00,0xe6,0xcf,0xe1,0x9e,0xa8,0x2c, | ||
| 81 | 0x63,0x16,0x01,0x3f,0x58,0xe2,0x89,0xa9,0x0d,0x38,0x34,0x1b, | ||
| 82 | 0xab,0x33,0xff,0xb0,0xbb,0x48,0x0c,0x5f,0xb9,0xb1,0xcd,0x2e, | ||
| 83 | 0xc5,0xf3,0xdb,0x47,0xe5,0xa5,0x9c,0x77,0x0a,0xa6,0x20,0x68, | ||
| 84 | 0xfe,0x7f,0xc1,0xad, | ||
| 85 | }; | ||
| 86 | |||
| 87 | /* It has come to my attention that there are 2 versions of the RC2 | ||
| 88 | * key schedule. One which is normal, and anther which has a hook to | ||
| 89 | * use a reduced key length. | ||
| 90 | * BSAFE uses the 'retarded' version. What I previously shipped is | ||
| 91 | * the same as specifying 1024 for the 'bits' parameter. Bsafe uses | ||
| 92 | * a version where the bits parameter is the same as len*8 */ | ||
| 93 | void RC2_set_key(key,len,data,bits) | ||
| 94 | RC2_KEY *key; | ||
| 95 | int len; | ||
| 96 | unsigned char *data; | ||
| 97 | int bits; | ||
| 98 | { | ||
| 99 | int i,j; | ||
| 100 | unsigned char *k; | ||
| 101 | RC2_INT *ki; | ||
| 102 | unsigned int c,d; | ||
| 103 | |||
| 104 | k= (unsigned char *)&(key->data[0]); | ||
| 105 | *k=0; /* for if there is a zero length key */ | ||
| 106 | |||
| 107 | if (len > 128) len=128; | ||
| 108 | if (bits <= 0) bits=1024; | ||
| 109 | if (bits > 1024) bits=1024; | ||
| 110 | |||
| 111 | for (i=0; i<len; i++) | ||
| 112 | k[i]=data[i]; | ||
| 113 | |||
| 114 | /* expand table */ | ||
| 115 | d=k[len-1]; | ||
| 116 | j=0; | ||
| 117 | for (i=len; i < 128; i++,j++) | ||
| 118 | { | ||
| 119 | d=key_table[(k[j]+d)&0xff]; | ||
| 120 | k[i]=d; | ||
| 121 | } | ||
| 122 | |||
| 123 | /* hmm.... key reduction to 'bits' bits */ | ||
| 124 | |||
| 125 | j=(bits+7)>>3; | ||
| 126 | i=128-j; | ||
| 127 | c= (0xff>>(-bits & 0x07)); | ||
| 128 | |||
| 129 | d=key_table[k[i]&c]; | ||
| 130 | k[i]=d; | ||
| 131 | while (i--) | ||
| 132 | { | ||
| 133 | d=key_table[k[i+j]^d]; | ||
| 134 | k[i]=d; | ||
| 135 | } | ||
| 136 | |||
| 137 | /* copy from bytes into RC2_INT's */ | ||
| 138 | ki= &(key->data[63]); | ||
| 139 | for (i=127; i>=0; i-=2) | ||
| 140 | *(ki--)=((k[i]<<8)|k[i-1])&0xffff; | ||
| 141 | } | ||
| 142 | |||
diff --git a/src/lib/libcrypto/rc2/rc2cfb64.c b/src/lib/libcrypto/rc2/rc2cfb64.c new file mode 100644 index 0000000000..d409fb77e9 --- /dev/null +++ b/src/lib/libcrypto/rc2/rc2cfb64.c | |||
| @@ -0,0 +1,127 @@ | |||
| 1 | /* crypto/rc2/rc2cfb64.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 "rc2.h" | ||
| 60 | #include "rc2_locl.h" | ||
| 61 | |||
| 62 | /* The input and output encrypted as though 64bit cfb mode is being | ||
| 63 | * used. The extra state information to record how much of the | ||
| 64 | * 64bit block we have used is contained in *num; | ||
| 65 | */ | ||
| 66 | |||
| 67 | void RC2_cfb64_encrypt(in, out, length, schedule, ivec, num, encrypt) | ||
| 68 | unsigned char *in; | ||
| 69 | unsigned char *out; | ||
| 70 | long length; | ||
| 71 | RC2_KEY *schedule; | ||
| 72 | unsigned char *ivec; | ||
| 73 | int *num; | ||
| 74 | int encrypt; | ||
| 75 | { | ||
| 76 | register unsigned long v0,v1,t; | ||
| 77 | register int n= *num; | ||
| 78 | register long l=length; | ||
| 79 | unsigned long ti[2]; | ||
| 80 | unsigned char *iv,c,cc; | ||
| 81 | |||
| 82 | iv=(unsigned char *)ivec; | ||
| 83 | if (encrypt) | ||
| 84 | { | ||
| 85 | while (l--) | ||
| 86 | { | ||
| 87 | if (n == 0) | ||
| 88 | { | ||
| 89 | c2l(iv,v0); ti[0]=v0; | ||
| 90 | c2l(iv,v1); ti[1]=v1; | ||
| 91 | RC2_encrypt((unsigned long *)ti,schedule); | ||
| 92 | iv=(unsigned char *)ivec; | ||
| 93 | t=ti[0]; l2c(t,iv); | ||
| 94 | t=ti[1]; l2c(t,iv); | ||
| 95 | iv=(unsigned char *)ivec; | ||
| 96 | } | ||
| 97 | c= *(in++)^iv[n]; | ||
| 98 | *(out++)=c; | ||
| 99 | iv[n]=c; | ||
| 100 | n=(n+1)&0x07; | ||
| 101 | } | ||
| 102 | } | ||
| 103 | else | ||
| 104 | { | ||
| 105 | while (l--) | ||
| 106 | { | ||
| 107 | if (n == 0) | ||
| 108 | { | ||
| 109 | c2l(iv,v0); ti[0]=v0; | ||
| 110 | c2l(iv,v1); ti[1]=v1; | ||
| 111 | RC2_encrypt((unsigned long *)ti,schedule); | ||
| 112 | iv=(unsigned char *)ivec; | ||
| 113 | t=ti[0]; l2c(t,iv); | ||
| 114 | t=ti[1]; l2c(t,iv); | ||
| 115 | iv=(unsigned char *)ivec; | ||
| 116 | } | ||
| 117 | cc= *(in++); | ||
| 118 | c=iv[n]; | ||
| 119 | iv[n]=cc; | ||
| 120 | *(out++)=c^cc; | ||
| 121 | n=(n+1)&0x07; | ||
| 122 | } | ||
| 123 | } | ||
| 124 | v0=v1=ti[0]=ti[1]=t=c=cc=0; | ||
| 125 | *num=n; | ||
| 126 | } | ||
| 127 | |||
diff --git a/src/lib/libcrypto/rc2/rc2ofb64.c b/src/lib/libcrypto/rc2/rc2ofb64.c new file mode 100644 index 0000000000..4f09167447 --- /dev/null +++ b/src/lib/libcrypto/rc2/rc2ofb64.c | |||
| @@ -0,0 +1,115 @@ | |||
| 1 | /* crypto/rc2/rc2ofb64.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 "rc2.h" | ||
| 60 | #include "rc2_locl.h" | ||
| 61 | |||
| 62 | /* The input and output encrypted as though 64bit ofb mode is being | ||
| 63 | * used. The extra state information to record how much of the | ||
| 64 | * 64bit block we have used is contained in *num; | ||
| 65 | */ | ||
| 66 | void RC2_ofb64_encrypt(in, out, length, schedule, ivec, num) | ||
| 67 | unsigned char *in; | ||
| 68 | unsigned char *out; | ||
| 69 | long length; | ||
| 70 | RC2_KEY *schedule; | ||
| 71 | unsigned char *ivec; | ||
| 72 | int *num; | ||
| 73 | { | ||
| 74 | register unsigned long v0,v1,t; | ||
| 75 | register int n= *num; | ||
| 76 | register long l=length; | ||
| 77 | unsigned char d[8]; | ||
| 78 | register char *dp; | ||
| 79 | unsigned long ti[2]; | ||
| 80 | unsigned char *iv; | ||
| 81 | int save=0; | ||
| 82 | |||
| 83 | iv=(unsigned char *)ivec; | ||
| 84 | c2l(iv,v0); | ||
| 85 | c2l(iv,v1); | ||
| 86 | ti[0]=v0; | ||
| 87 | ti[1]=v1; | ||
| 88 | dp=(char *)d; | ||
| 89 | l2c(v0,dp); | ||
| 90 | l2c(v1,dp); | ||
| 91 | while (l--) | ||
| 92 | { | ||
| 93 | if (n == 0) | ||
| 94 | { | ||
| 95 | RC2_encrypt((unsigned long *)ti,schedule); | ||
| 96 | dp=(char *)d; | ||
| 97 | t=ti[0]; l2c(t,dp); | ||
| 98 | t=ti[1]; l2c(t,dp); | ||
| 99 | save++; | ||
| 100 | } | ||
| 101 | *(out++)= *(in++)^d[n]; | ||
| 102 | n=(n+1)&0x07; | ||
| 103 | } | ||
| 104 | if (save) | ||
| 105 | { | ||
| 106 | v0=ti[0]; | ||
| 107 | v1=ti[1]; | ||
| 108 | iv=(unsigned char *)ivec; | ||
| 109 | l2c(v0,iv); | ||
| 110 | l2c(v1,iv); | ||
| 111 | } | ||
| 112 | t=v0=v1=ti[0]=ti[1]=0; | ||
| 113 | *num=n; | ||
| 114 | } | ||
| 115 | |||
diff --git a/src/lib/libcrypto/rc2/rrc2.doc b/src/lib/libcrypto/rc2/rrc2.doc new file mode 100644 index 0000000000..f93ee003d2 --- /dev/null +++ b/src/lib/libcrypto/rc2/rrc2.doc | |||
| @@ -0,0 +1,219 @@ | |||
| 1 | >From cygnus.mincom.oz.au!minbne.mincom.oz.au!bunyip.cc.uq.oz.au!munnari.OZ.AU!comp.vuw.ac.nz!waikato!auckland.ac.nz!news Mon Feb 12 18:48:17 EST 1996 | ||
| 2 | Article 23601 of sci.crypt: | ||
| 3 | Path: cygnus.mincom.oz.au!minbne.mincom.oz.au!bunyip.cc.uq.oz.au!munnari.OZ.AU!comp.vuw.ac.nz!waikato!auckland.ac.nz!news | ||
| 4 | >From: pgut01@cs.auckland.ac.nz (Peter Gutmann) | ||
| 5 | Newsgroups: sci.crypt | ||
| 6 | Subject: Specification for Ron Rivests Cipher No.2 | ||
| 7 | Date: 11 Feb 1996 06:45:03 GMT | ||
| 8 | Organization: University of Auckland | ||
| 9 | Lines: 203 | ||
| 10 | Sender: pgut01@cs.auckland.ac.nz (Peter Gutmann) | ||
| 11 | Message-ID: <4fk39f$f70@net.auckland.ac.nz> | ||
| 12 | NNTP-Posting-Host: cs26.cs.auckland.ac.nz | ||
| 13 | X-Newsreader: NN version 6.5.0 #3 (NOV) | ||
| 14 | |||
| 15 | |||
| 16 | |||
| 17 | |||
| 18 | Ron Rivest's Cipher No.2 | ||
| 19 | ------------------------ | ||
| 20 | |||
| 21 | Ron Rivest's Cipher No.2 (hereafter referred to as RRC.2, other people may | ||
| 22 | refer to it by other names) is word oriented, operating on a block of 64 bits | ||
| 23 | divided into four 16-bit words, with a key table of 64 words. All data units | ||
| 24 | are little-endian. This functional description of the algorithm is based in | ||
| 25 | the paper "The RC5 Encryption Algorithm" (RC5 is a trademark of RSADSI), using | ||
| 26 | the same general layout, terminology, and pseudocode style. | ||
| 27 | |||
| 28 | |||
| 29 | Notation and RRC.2 Primitive Operations | ||
| 30 | |||
| 31 | RRC.2 uses the following primitive operations: | ||
| 32 | |||
| 33 | 1. Two's-complement addition of words, denoted by "+". The inverse operation, | ||
| 34 | subtraction, is denoted by "-". | ||
| 35 | 2. Bitwise exclusive OR, denoted by "^". | ||
| 36 | 3. Bitwise AND, denoted by "&". | ||
| 37 | 4. Bitwise NOT, denoted by "~". | ||
| 38 | 5. A left-rotation of words; the rotation of word x left by y is denoted | ||
| 39 | x <<< y. The inverse operation, right-rotation, is denoted x >>> y. | ||
| 40 | |||
| 41 | These operations are directly and efficiently supported by most processors. | ||
| 42 | |||
| 43 | |||
| 44 | The RRC.2 Algorithm | ||
| 45 | |||
| 46 | RRC.2 consists of three components, a *key expansion* algorithm, an | ||
| 47 | *encryption* algorithm, and a *decryption* algorithm. | ||
| 48 | |||
| 49 | |||
| 50 | Key Expansion | ||
| 51 | |||
| 52 | The purpose of the key-expansion routine is to expand the user's key K to fill | ||
| 53 | the expanded key array S, so S resembles an array of random binary words | ||
| 54 | determined by the user's secret key K. | ||
| 55 | |||
| 56 | Initialising the S-box | ||
| 57 | |||
| 58 | RRC.2 uses a single 256-byte S-box derived from the ciphertext contents of | ||
| 59 | Beale Cipher No.1 XOR'd with a one-time pad. The Beale Ciphers predate modern | ||
| 60 | cryptography by enough time that there should be no concerns about trapdoors | ||
| 61 | hidden in the data. They have been published widely, and the S-box can be | ||
| 62 | easily recreated from the one-time pad values and the Beale Cipher data taken | ||
| 63 | from a standard source. To initialise the S-box: | ||
| 64 | |||
| 65 | for i = 0 to 255 do | ||
| 66 | sBox[ i ] = ( beale[ i ] mod 256 ) ^ pad[ i ] | ||
| 67 | |||
| 68 | The contents of Beale Cipher No.1 and the necessary one-time pad are given as | ||
| 69 | an appendix at the end of this document. For efficiency, implementors may wish | ||
| 70 | to skip the Beale Cipher expansion and store the sBox table directly. | ||
| 71 | |||
| 72 | Expanding the Secret Key to 128 Bytes | ||
| 73 | |||
| 74 | The secret key is first expanded to fill 128 bytes (64 words). The expansion | ||
| 75 | consists of taking the sum of the first and last bytes in the user key, looking | ||
| 76 | up the sum (modulo 256) in the S-box, and appending the result to the key. The | ||
| 77 | operation is repeated with the second byte and new last byte of the key until | ||
| 78 | all 128 bytes have been generated. Note that the following pseudocode treats | ||
| 79 | the S array as an array of 128 bytes rather than 64 words. | ||
| 80 | |||
| 81 | for j = 0 to length-1 do | ||
| 82 | S[ j ] = K[ j ] | ||
| 83 | for j = length to 127 do | ||
| 84 | s[ j ] = sBox[ ( S[ j-length ] + S[ j-1 ] ) mod 256 ]; | ||
| 85 | |||
| 86 | At this point it is possible to perform a truncation of the effective key | ||
| 87 | length to ease the creation of espionage-enabled software products. However | ||
| 88 | since the author cannot conceive why anyone would want to do this, it will not | ||
| 89 | be considered further. | ||
| 90 | |||
| 91 | The final phase of the key expansion involves replacing the first byte of S | ||
| 92 | with the entry selected from the S-box: | ||
| 93 | |||
| 94 | S[ 0 ] = sBox[ S[ 0 ] ] | ||
| 95 | |||
| 96 | |||
| 97 | Encryption | ||
| 98 | |||
| 99 | The cipher has 16 full rounds, each divided into 4 subrounds. Two of the full | ||
| 100 | rounds perform an additional transformation on the data. Note that the | ||
| 101 | following pseudocode treats the S array as an array of 64 words rather than 128 | ||
| 102 | bytes. | ||
| 103 | |||
| 104 | for i = 0 to 15 do | ||
| 105 | j = i * 4; | ||
| 106 | word0 = ( word0 + ( word1 & ~word3 ) + ( word2 & word3 ) + S[ j+0 ] ) <<< 1 | ||
| 107 | word1 = ( word1 + ( word2 & ~word0 ) + ( word3 & word0 ) + S[ j+1 ] ) <<< 2 | ||
| 108 | word2 = ( word2 + ( word3 & ~word1 ) + ( word0 & word1 ) + S[ j+2 ] ) <<< 3 | ||
| 109 | word3 = ( word3 + ( word0 & ~word2 ) + ( word1 & word2 ) + S[ j+3 ] ) <<< 5 | ||
| 110 | |||
| 111 | In addition the fifth and eleventh rounds add the contents of the S-box indexed | ||
| 112 | by one of the data words to another of the data words following the four | ||
| 113 | subrounds as follows: | ||
| 114 | |||
| 115 | word0 = word0 + S[ word3 & 63 ]; | ||
| 116 | word1 = word1 + S[ word0 & 63 ]; | ||
| 117 | word2 = word2 + S[ word1 & 63 ]; | ||
| 118 | word3 = word3 + S[ word2 & 63 ]; | ||
| 119 | |||
| 120 | |||
| 121 | Decryption | ||
| 122 | |||
| 123 | The decryption operation is simply the inverse of the encryption operation. | ||
| 124 | Note that the following pseudocode treats the S array as an array of 64 words | ||
| 125 | rather than 128 bytes. | ||
| 126 | |||
| 127 | for i = 15 downto 0 do | ||
| 128 | j = i * 4; | ||
| 129 | word3 = ( word3 >>> 5 ) - ( word0 & ~word2 ) - ( word1 & word2 ) - S[ j+3 ] | ||
| 130 | word2 = ( word2 >>> 3 ) - ( word3 & ~word1 ) - ( word0 & word1 ) - S[ j+2 ] | ||
| 131 | word1 = ( word1 >>> 2 ) - ( word2 & ~word0 ) - ( word3 & word0 ) - S[ j+1 ] | ||
| 132 | word0 = ( word0 >>> 1 ) - ( word1 & ~word3 ) - ( word2 & word3 ) - S[ j+0 ] | ||
| 133 | |||
| 134 | In addition the fifth and eleventh rounds subtract the contents of the S-box | ||
| 135 | indexed by one of the data words from another one of the data words following | ||
| 136 | the four subrounds as follows: | ||
| 137 | |||
| 138 | word3 = word3 - S[ word2 & 63 ] | ||
| 139 | word2 = word2 - S[ word1 & 63 ] | ||
| 140 | word1 = word1 - S[ word0 & 63 ] | ||
| 141 | word0 = word0 - S[ word3 & 63 ] | ||
| 142 | |||
| 143 | |||
| 144 | Test Vectors | ||
| 145 | |||
| 146 | The following test vectors may be used to test the correctness of an RRC.2 | ||
| 147 | implementation: | ||
| 148 | |||
| 149 | Key: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 150 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
| 151 | Plain: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
| 152 | Cipher: 0x1C, 0x19, 0x8A, 0x83, 0x8D, 0xF0, 0x28, 0xB7 | ||
| 153 | |||
| 154 | Key: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 155 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 | ||
| 156 | Plain: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
| 157 | Cipher: 0x21, 0x82, 0x9C, 0x78, 0xA9, 0xF9, 0xC0, 0x74 | ||
| 158 | |||
| 159 | Key: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 160 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
| 161 | Plain: 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF | ||
| 162 | Cipher: 0x13, 0xDB, 0x35, 0x17, 0xD3, 0x21, 0x86, 0x9E | ||
| 163 | |||
| 164 | Key: 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
| 165 | 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F | ||
| 166 | Plain: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
| 167 | Cipher: 0x50, 0xDC, 0x01, 0x62, 0xBD, 0x75, 0x7F, 0x31 | ||
| 168 | |||
| 169 | |||
| 170 | Appendix: Beale Cipher No.1, "The Locality of the Vault", and One-time Pad for | ||
| 171 | Creating the S-Box | ||
| 172 | |||
| 173 | Beale Cipher No.1. | ||
| 174 | |||
| 175 | 71, 194, 38,1701, 89, 76, 11, 83,1629, 48, 94, 63, 132, 16, 111, 95, | ||
| 176 | 84, 341, 975, 14, 40, 64, 27, 81, 139, 213, 63, 90,1120, 8, 15, 3, | ||
| 177 | 126,2018, 40, 74, 758, 485, 604, 230, 436, 664, 582, 150, 251, 284, 308, 231, | ||
| 178 | 124, 211, 486, 225, 401, 370, 11, 101, 305, 139, 189, 17, 33, 88, 208, 193, | ||
| 179 | 145, 1, 94, 73, 416, 918, 263, 28, 500, 538, 356, 117, 136, 219, 27, 176, | ||
| 180 | 130, 10, 460, 25, 485, 18, 436, 65, 84, 200, 283, 118, 320, 138, 36, 416, | ||
| 181 | 280, 15, 71, 224, 961, 44, 16, 401, 39, 88, 61, 304, 12, 21, 24, 283, | ||
| 182 | 134, 92, 63, 246, 486, 682, 7, 219, 184, 360, 780, 18, 64, 463, 474, 131, | ||
| 183 | 160, 79, 73, 440, 95, 18, 64, 581, 34, 69, 128, 367, 460, 17, 81, 12, | ||
| 184 | 103, 820, 62, 110, 97, 103, 862, 70, 60,1317, 471, 540, 208, 121, 890, 346, | ||
| 185 | 36, 150, 59, 568, 614, 13, 120, 63, 219, 812,2160,1780, 99, 35, 18, 21, | ||
| 186 | 136, 872, 15, 28, 170, 88, 4, 30, 44, 112, 18, 147, 436, 195, 320, 37, | ||
| 187 | 122, 113, 6, 140, 8, 120, 305, 42, 58, 461, 44, 106, 301, 13, 408, 680, | ||
| 188 | 93, 86, 116, 530, 82, 568, 9, 102, 38, 416, 89, 71, 216, 728, 965, 818, | ||
| 189 | 2, 38, 121, 195, 14, 326, 148, 234, 18, 55, 131, 234, 361, 824, 5, 81, | ||
| 190 | 623, 48, 961, 19, 26, 33, 10,1101, 365, 92, 88, 181, 275, 346, 201, 206 | ||
| 191 | |||
| 192 | One-time Pad. | ||
| 193 | |||
| 194 | 158, 186, 223, 97, 64, 145, 190, 190, 117, 217, 163, 70, 206, 176, 183, 194, | ||
| 195 | 146, 43, 248, 141, 3, 54, 72, 223, 233, 153, 91, 210, 36, 131, 244, 161, | ||
| 196 | 105, 120, 113, 191, 113, 86, 19, 245, 213, 221, 43, 27, 242, 157, 73, 213, | ||
| 197 | 193, 92, 166, 10, 23, 197, 112, 110, 193, 30, 156, 51, 125, 51, 158, 67, | ||
| 198 | 197, 215, 59, 218, 110, 246, 181, 0, 135, 76, 164, 97, 47, 87, 234, 108, | ||
| 199 | 144, 127, 6, 6, 222, 172, 80, 144, 22, 245, 207, 70, 227, 182, 146, 134, | ||
| 200 | 119, 176, 73, 58, 135, 69, 23, 198, 0, 170, 32, 171, 176, 129, 91, 24, | ||
| 201 | 126, 77, 248, 0, 118, 69, 57, 60, 190, 171, 217, 61, 136, 169, 196, 84, | ||
| 202 | 168, 167, 163, 102, 223, 64, 174, 178, 166, 239, 242, 195, 249, 92, 59, 38, | ||
| 203 | 241, 46, 236, 31, 59, 114, 23, 50, 119, 186, 7, 66, 212, 97, 222, 182, | ||
| 204 | 230, 118, 122, 86, 105, 92, 179, 243, 255, 189, 223, 164, 194, 215, 98, 44, | ||
| 205 | 17, 20, 53, 153, 137, 224, 176, 100, 208, 114, 36, 200, 145, 150, 215, 20, | ||
| 206 | 87, 44, 252, 20, 235, 242, 163, 132, 63, 18, 5, 122, 74, 97, 34, 97, | ||
| 207 | 142, 86, 146, 221, 179, 166, 161, 74, 69, 182, 88, 120, 128, 58, 76, 155, | ||
| 208 | 15, 30, 77, 216, 165, 117, 107, 90, 169, 127, 143, 181, 208, 137, 200, 127, | ||
| 209 | 170, 195, 26, 84, 255, 132, 150, 58, 103, 250, 120, 221, 237, 37, 8, 99 | ||
| 210 | |||
| 211 | |||
| 212 | Implementation | ||
| 213 | |||
| 214 | A non-US based programmer who has never seen any encryption code before will | ||
| 215 | shortly be implementing RRC.2 based solely on this specification and not on | ||
| 216 | knowledge of any other encryption algorithms. Stand by. | ||
| 217 | |||
| 218 | |||
| 219 | |||
diff --git a/src/lib/libcrypto/rc2/version b/src/lib/libcrypto/rc2/version new file mode 100644 index 0000000000..6f89d595f1 --- /dev/null +++ b/src/lib/libcrypto/rc2/version | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | 1.1 23/08/96 - eay | ||
| 2 | Changed RC2_set_key() so it now takes another argument. Many | ||
| 3 | thanks to Peter Gutmann <pgut01@cs.auckland.ac.nz> for the | ||
| 4 | clarification and origional specification of RC2. BSAFE uses | ||
| 5 | this last parameter, 'bits'. It the key is 128 bits, BSAFE | ||
| 6 | also sets this parameter to 128. The old behaviour can be | ||
| 7 | duplicated by setting this parameter to 1024. | ||
| 8 | |||
| 9 | 1.0 08/04/96 - eay | ||
| 10 | First version of SSLeay with rc2. This has been written from the spec | ||
| 11 | posted sci.crypt. It is in this directory under rrc2.doc | ||
| 12 | I have no test values for any mode other than ecb, my wrappers for the | ||
| 13 | other modes should be ok since they are basically the same as | ||
| 14 | the ones taken from idea and des :-). I have implemented them as | ||
| 15 | little-endian operators. | ||
| 16 | While rc2 is included because it is used with SSL, I don't know how | ||
| 17 | far I trust it. It is about the same speed as IDEA and DES. | ||
| 18 | So if you are paranoid, used Tripple DES, else IDEA. If RC2 | ||
| 19 | does get used more, perhaps more people will look for weaknesses in | ||
| 20 | it. | ||
| 21 | |||
| 22 | |||
diff --git a/src/lib/libcrypto/rc4/asm/rc4-586.pl b/src/lib/libcrypto/rc4/asm/rc4-586.pl new file mode 100644 index 0000000000..0dd8eb1ba9 --- /dev/null +++ b/src/lib/libcrypto/rc4/asm/rc4-586.pl | |||
| @@ -0,0 +1,173 @@ | |||
| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | # define for pentium pro friendly version | ||
| 4 | |||
| 5 | push(@INC,"perlasm","../../perlasm"); | ||
| 6 | require "x86asm.pl"; | ||
| 7 | |||
| 8 | &asm_init($ARGV[0],"rc4-586.pl"); | ||
| 9 | |||
| 10 | $tx="eax"; | ||
| 11 | $ty="ebx"; | ||
| 12 | $x="ecx"; | ||
| 13 | $y="edx"; | ||
| 14 | $in="esi"; | ||
| 15 | $out="edi"; | ||
| 16 | $d="ebp"; | ||
| 17 | |||
| 18 | &RC4("RC4"); | ||
| 19 | |||
| 20 | &asm_finish(); | ||
| 21 | |||
| 22 | sub RC4_loop | ||
| 23 | { | ||
| 24 | local($n,$p,$char)=@_; | ||
| 25 | |||
| 26 | &comment("Round $n"); | ||
| 27 | |||
| 28 | if ($char) | ||
| 29 | { | ||
| 30 | if ($p >= 0) | ||
| 31 | { | ||
| 32 | &mov($ty, &swtmp(2)); | ||
| 33 | &cmp($ty, $in); | ||
| 34 | &jle(&label("finished")); | ||
| 35 | &inc($in); | ||
| 36 | } | ||
| 37 | else | ||
| 38 | { | ||
| 39 | &add($ty, 8); | ||
| 40 | &inc($in); | ||
| 41 | &cmp($ty, $in); | ||
| 42 | &jl(&label("finished")); | ||
| 43 | &mov(&swtmp(2), $ty); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | # Moved out | ||
| 47 | # &mov( $tx, &DWP(0,$d,$x,4)) if $p < 0; | ||
| 48 | |||
| 49 | &add( $y, $tx); | ||
| 50 | &and( $y, 0xff); | ||
| 51 | &inc( $x); # NEXT ROUND | ||
| 52 | &mov( $ty, &DWP(0,$d,$y,4)); | ||
| 53 | # XXX | ||
| 54 | &mov( &DWP(-4,$d,$x,4),$ty); # AGI | ||
| 55 | &add( $ty, $tx); | ||
| 56 | &and( $x, 0xff); # NEXT ROUND | ||
| 57 | &and( $ty, 0xff); | ||
| 58 | &mov( &DWP(0,$d,$y,4),$tx); | ||
| 59 | &nop(); | ||
| 60 | &mov( $ty, &DWP(0,$d,$ty,4)); | ||
| 61 | &mov( $tx, &DWP(0,$d,$x,4)) if $p < 1; # NEXT ROUND | ||
| 62 | # XXX | ||
| 63 | |||
| 64 | if (!$char) | ||
| 65 | { | ||
| 66 | #moved up into last round | ||
| 67 | if ($p >= 1) | ||
| 68 | { | ||
| 69 | &add( $out, 8) | ||
| 70 | } | ||
| 71 | &movb( &BP($n,"esp","",0), &LB($ty)); | ||
| 72 | } | ||
| 73 | else | ||
| 74 | { | ||
| 75 | # Note in+=8 has occured | ||
| 76 | &movb( &HB($ty), &BP(-1,$in,"",0)); | ||
| 77 | # XXX | ||
| 78 | &xorb(&LB($ty), &HB($ty)); | ||
| 79 | # XXX | ||
| 80 | &movb(&BP($n,$out,"",0),&LB($ty)); | ||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 84 | |||
| 85 | sub RC4 | ||
| 86 | { | ||
| 87 | local($name)=@_; | ||
| 88 | |||
| 89 | &function_begin_B($name,""); | ||
| 90 | |||
| 91 | &comment(""); | ||
| 92 | |||
| 93 | &push("ebp"); | ||
| 94 | &push("ebx"); | ||
| 95 | &mov( $d, &wparam(0)); # key | ||
| 96 | &mov( $ty, &wparam(1)); # num | ||
| 97 | &push("esi"); | ||
| 98 | &push("edi"); | ||
| 99 | |||
| 100 | &mov( $x, &DWP(0,$d,"",1)); | ||
| 101 | &mov( $y, &DWP(4,$d,"",1)); | ||
| 102 | |||
| 103 | &mov( $in, &wparam(2)); | ||
| 104 | &inc( $x); | ||
| 105 | |||
| 106 | &stack_push(3); # 3 temp variables | ||
| 107 | &add( $d, 8); | ||
| 108 | &and( $x, 0xff); | ||
| 109 | |||
| 110 | &lea( $ty, &DWP(-8,$ty,$in)); | ||
| 111 | |||
| 112 | # check for 0 length input | ||
| 113 | |||
| 114 | &mov( $out, &wparam(3)); | ||
| 115 | &mov( &swtmp(2), $ty); # this is now address to exit at | ||
| 116 | &mov( $tx, &DWP(0,$d,$x,4)); | ||
| 117 | |||
| 118 | &cmp( $ty, $in); | ||
| 119 | &jl( &label("end")); # less than 8 bytes | ||
| 120 | |||
| 121 | &set_label("start"); | ||
| 122 | |||
| 123 | # filling DELAY SLOT | ||
| 124 | &add( $in, 8); | ||
| 125 | |||
| 126 | &RC4_loop(0,-1,0); | ||
| 127 | &RC4_loop(1,0,0); | ||
| 128 | &RC4_loop(2,0,0); | ||
| 129 | &RC4_loop(3,0,0); | ||
| 130 | &RC4_loop(4,0,0); | ||
| 131 | &RC4_loop(5,0,0); | ||
| 132 | &RC4_loop(6,0,0); | ||
| 133 | &RC4_loop(7,1,0); | ||
| 134 | |||
| 135 | &comment("apply the cipher text"); | ||
| 136 | # xor the cipher data with input | ||
| 137 | |||
| 138 | #&add( $out, 8); #moved up into last round | ||
| 139 | |||
| 140 | &mov( $tx, &swtmp(0)); | ||
| 141 | &mov( $ty, &DWP(-8,$in,"",0)); | ||
| 142 | &xor( $tx, $ty); | ||
| 143 | &mov( $ty, &DWP(-4,$in,"",0)); | ||
| 144 | &mov( &DWP(-8,$out,"",0), $tx); | ||
| 145 | &mov( $tx, &swtmp(1)); | ||
| 146 | &xor( $tx, $ty); | ||
| 147 | &mov( $ty, &swtmp(2)); # load end ptr; | ||
| 148 | &mov( &DWP(-4,$out,"",0), $tx); | ||
| 149 | &mov( $tx, &DWP(0,$d,$x,4)); | ||
| 150 | &cmp($in, $ty); | ||
| 151 | &jle(&label("start")); | ||
| 152 | |||
| 153 | &set_label("end"); | ||
| 154 | |||
| 155 | # There is quite a bit of extra crap in RC4_loop() for this | ||
| 156 | # first round | ||
| 157 | &RC4_loop(0,-1,1); | ||
| 158 | &RC4_loop(1,0,1); | ||
| 159 | &RC4_loop(2,0,1); | ||
| 160 | &RC4_loop(3,0,1); | ||
| 161 | &RC4_loop(4,0,1); | ||
| 162 | &RC4_loop(5,0,1); | ||
| 163 | &RC4_loop(6,1,1); | ||
| 164 | |||
| 165 | &set_label("finished"); | ||
| 166 | &dec( $x); | ||
| 167 | &stack_pop(3); | ||
| 168 | &mov( &DWP(-4,$d,"",0),$y); | ||
| 169 | &movb( &BP(-8,$d,"",0),&LB($x)); | ||
| 170 | |||
| 171 | &function_end($name); | ||
| 172 | } | ||
| 173 | |||
diff --git a/src/lib/libcrypto/rc4/rc4_enc.c b/src/lib/libcrypto/rc4/rc4_enc.c new file mode 100644 index 0000000000..ab8a111b52 --- /dev/null +++ b/src/lib/libcrypto/rc4/rc4_enc.c | |||
| @@ -0,0 +1,135 @@ | |||
| 1 | /* crypto/rc4/rc4_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 "rc4.h" | ||
| 60 | #include "rc4_locl.h" | ||
| 61 | |||
| 62 | /* RC4 as implemented from a posting from | ||
| 63 | * Newsgroups: sci.crypt | ||
| 64 | * From: sterndark@netcom.com (David Sterndark) | ||
| 65 | * Subject: RC4 Algorithm revealed. | ||
| 66 | * Message-ID: <sternCvKL4B.Hyy@netcom.com> | ||
| 67 | * Date: Wed, 14 Sep 1994 06:35:31 GMT | ||
| 68 | */ | ||
| 69 | |||
| 70 | void RC4(key, len, indata, outdata) | ||
| 71 | RC4_KEY *key; | ||
| 72 | unsigned long len; | ||
| 73 | unsigned char *indata; | ||
| 74 | unsigned char *outdata; | ||
| 75 | { | ||
| 76 | register RC4_INT *d; | ||
| 77 | register RC4_INT x,y,tx,ty; | ||
| 78 | int i; | ||
| 79 | |||
| 80 | x=key->x; | ||
| 81 | y=key->y; | ||
| 82 | d=key->data; | ||
| 83 | |||
| 84 | #define LOOP(in,out) \ | ||
| 85 | x=((x+1)&0xff); \ | ||
| 86 | tx=d[x]; \ | ||
| 87 | y=(tx+y)&0xff; \ | ||
| 88 | d[x]=ty=d[y]; \ | ||
| 89 | d[y]=tx; \ | ||
| 90 | (out) = d[(tx+ty)&0xff]^ (in); | ||
| 91 | |||
| 92 | #ifndef RC4_INDEX | ||
| 93 | #define RC4_LOOP(a,b,i) LOOP(*((a)++),*((b)++)) | ||
| 94 | #else | ||
| 95 | #define RC4_LOOP(a,b,i) LOOP(a[i],b[i]) | ||
| 96 | #endif | ||
| 97 | |||
| 98 | i= -(int)len; | ||
| 99 | i=(int)(len>>3L); | ||
| 100 | if (i) | ||
| 101 | { | ||
| 102 | for (;;) | ||
| 103 | { | ||
| 104 | RC4_LOOP(indata,outdata,0); | ||
| 105 | RC4_LOOP(indata,outdata,1); | ||
| 106 | RC4_LOOP(indata,outdata,2); | ||
| 107 | RC4_LOOP(indata,outdata,3); | ||
| 108 | RC4_LOOP(indata,outdata,4); | ||
| 109 | RC4_LOOP(indata,outdata,5); | ||
| 110 | RC4_LOOP(indata,outdata,6); | ||
| 111 | RC4_LOOP(indata,outdata,7); | ||
| 112 | #ifdef RC4_INDEX | ||
| 113 | indata+=8; | ||
| 114 | outdata+=8; | ||
| 115 | #endif | ||
| 116 | if (--i == 0) break; | ||
| 117 | } | ||
| 118 | } | ||
| 119 | i=(int)len&0x07; | ||
| 120 | if (i) | ||
| 121 | { | ||
| 122 | for (;;) | ||
| 123 | { | ||
| 124 | RC4_LOOP(indata,outdata,0); if (--i == 0) break; | ||
| 125 | RC4_LOOP(indata,outdata,1); if (--i == 0) break; | ||
| 126 | RC4_LOOP(indata,outdata,2); if (--i == 0) break; | ||
| 127 | RC4_LOOP(indata,outdata,3); if (--i == 0) break; | ||
| 128 | RC4_LOOP(indata,outdata,4); if (--i == 0) break; | ||
| 129 | RC4_LOOP(indata,outdata,5); if (--i == 0) break; | ||
| 130 | RC4_LOOP(indata,outdata,6); if (--i == 0) break; | ||
| 131 | } | ||
| 132 | } | ||
| 133 | key->x=x; | ||
| 134 | key->y=y; | ||
| 135 | } | ||
diff --git a/src/lib/libcrypto/rc4/rc4_skey.c b/src/lib/libcrypto/rc4/rc4_skey.c new file mode 100644 index 0000000000..0be5fde67b --- /dev/null +++ b/src/lib/libcrypto/rc4/rc4_skey.c | |||
| @@ -0,0 +1,119 @@ | |||
| 1 | /* crypto/rc4/rc4_skey.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 "rc4.h" | ||
| 60 | #include "rc4_locl.h" | ||
| 61 | |||
| 62 | char *RC4_version="RC4 part of SSLeay 0.9.0b 29-Jun-1998"; | ||
| 63 | |||
| 64 | char *RC4_options() | ||
| 65 | { | ||
| 66 | #ifdef RC4_INDEX | ||
| 67 | if (sizeof(RC4_INT) == 1) | ||
| 68 | return("rc4(idx,char)"); | ||
| 69 | else | ||
| 70 | return("rc4(idx,int)"); | ||
| 71 | #else | ||
| 72 | if (sizeof(RC4_INT) == 1) | ||
| 73 | return("rc4(ptr,char)"); | ||
| 74 | else | ||
| 75 | return("rc4(ptr,int)"); | ||
| 76 | #endif | ||
| 77 | } | ||
| 78 | |||
| 79 | /* RC4 as implemented from a posting from | ||
| 80 | * Newsgroups: sci.crypt | ||
| 81 | * From: sterndark@netcom.com (David Sterndark) | ||
| 82 | * Subject: RC4 Algorithm revealed. | ||
| 83 | * Message-ID: <sternCvKL4B.Hyy@netcom.com> | ||
| 84 | * Date: Wed, 14 Sep 1994 06:35:31 GMT | ||
| 85 | */ | ||
| 86 | |||
| 87 | void RC4_set_key(key, len, data) | ||
| 88 | RC4_KEY *key; | ||
| 89 | int len; | ||
| 90 | register unsigned char *data; | ||
| 91 | { | ||
| 92 | register RC4_INT tmp; | ||
| 93 | register int id1,id2; | ||
| 94 | register RC4_INT *d; | ||
| 95 | unsigned int i; | ||
| 96 | |||
| 97 | d= &(key->data[0]); | ||
| 98 | for (i=0; i<256; i++) | ||
| 99 | d[i]=i; | ||
| 100 | key->x = 0; | ||
| 101 | key->y = 0; | ||
| 102 | id1=id2=0; | ||
| 103 | |||
| 104 | #define SK_LOOP(n) { \ | ||
| 105 | tmp=d[(n)]; \ | ||
| 106 | id2 = (data[id1] + tmp + id2) & 0xff; \ | ||
| 107 | if (++id1 == len) id1=0; \ | ||
| 108 | d[(n)]=d[id2]; \ | ||
| 109 | d[id2]=tmp; } | ||
| 110 | |||
| 111 | for (i=0; i < 256; i+=4) | ||
| 112 | { | ||
| 113 | SK_LOOP(i+0); | ||
| 114 | SK_LOOP(i+1); | ||
| 115 | SK_LOOP(i+2); | ||
| 116 | SK_LOOP(i+3); | ||
| 117 | } | ||
| 118 | } | ||
| 119 | |||
diff --git a/src/lib/libcrypto/ripemd/README b/src/lib/libcrypto/ripemd/README new file mode 100644 index 0000000000..7097707264 --- /dev/null +++ b/src/lib/libcrypto/ripemd/README | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | RIPEMD-160 | ||
| 2 | http://www.esat.kuleuven.ac.be/~bosselae/ripemd160.html | ||
| 3 | |||
| 4 | This is my implementation of RIPEMD-160. The pentium assember is a little | ||
| 5 | off the pace since I only get 1050 cycles, while the best is 1013. | ||
| 6 | I have a few ideas for how to get another 20 or so cycles, but at | ||
| 7 | this point I will not bother right now. I belive the trick will be | ||
| 8 | to remove my 'copy X array onto stack' until inside the RIP1() finctions the | ||
| 9 | first time round. To do this I need another register and will only have one | ||
| 10 | temporary one. A bit tricky.... I can also cleanup the saving of the 5 words | ||
| 11 | after the first half of the calculation. I should read the origional | ||
| 12 | value, add then write. Currently I just save the new and read the origioal. | ||
| 13 | I then read both at the end. Bad. | ||
| 14 | |||
| 15 | eric (20-Jan-1998) | ||
diff --git a/src/lib/libcrypto/ripemd/asm/rmd-586.pl b/src/lib/libcrypto/ripemd/asm/rmd-586.pl new file mode 100644 index 0000000000..dc3f6c792e --- /dev/null +++ b/src/lib/libcrypto/ripemd/asm/rmd-586.pl | |||
| @@ -0,0 +1,582 @@ | |||
| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | # Normal is the | ||
| 4 | # ripemd160_block_x86(MD5_CTX *c, ULONG *X); | ||
| 5 | # version, non-normal is the | ||
| 6 | # ripemd160_block_x86(MD5_CTX *c, ULONG *X,int blocks); | ||
| 7 | |||
| 8 | $normal=0; | ||
| 9 | |||
| 10 | push(@INC,"perlasm","../../perlasm"); | ||
| 11 | require "x86asm.pl"; | ||
| 12 | |||
| 13 | &asm_init($ARGV[0],$0); | ||
| 14 | |||
| 15 | $A="eax"; | ||
| 16 | $B="ebx"; | ||
| 17 | $C="ecx"; | ||
| 18 | $D="edx"; | ||
| 19 | $E="ebp"; | ||
| 20 | $tmp1="esi"; | ||
| 21 | $tmp2="edi"; | ||
| 22 | |||
| 23 | $KL1=0x5A827999; | ||
| 24 | $KL2=0x6ED9EBA1; | ||
| 25 | $KL3=0x8F1BBCDC; | ||
| 26 | $KL4=0xA953FD4E; | ||
| 27 | $KR0=0x50A28BE6; | ||
| 28 | $KR1=0x5C4DD124; | ||
| 29 | $KR2=0x6D703EF3; | ||
| 30 | $KR3=0x7A6D76E9; | ||
| 31 | |||
| 32 | |||
| 33 | @wl=( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15, | ||
| 34 | 7, 4,13, 1,10, 6,15, 3,12, 0, 9, 5, 2,14,11, 8, | ||
| 35 | 3,10,14, 4, 9,15, 8, 1, 2, 7, 0, 6,13,11, 5,12, | ||
| 36 | 1, 9,11,10, 0, 8,12, 4,13, 3, 7,15,14, 5, 6, 2, | ||
| 37 | 4, 0, 5, 9, 7,12, 2,10,14, 1, 3, 8,11, 6,15,13, | ||
| 38 | ); | ||
| 39 | |||
| 40 | @wr=( 5,14, 7, 0, 9, 2,11, 4,13, 6,15, 8, 1,10, 3,12, | ||
| 41 | 6,11, 3, 7, 0,13, 5,10,14,15, 8,12, 4, 9, 1, 2, | ||
| 42 | 15, 5, 1, 3, 7,14, 6, 9,11, 8,12, 2,10, 0, 4,13, | ||
| 43 | 8, 6, 4, 1, 3,11,15, 0, 5,12, 2,13, 9, 7,10,14, | ||
| 44 | 12,15,10, 4, 1, 5, 8, 7, 6, 2,13,14, 0, 3, 9,11, | ||
| 45 | ); | ||
| 46 | |||
| 47 | @sl=( 11,14,15,12, 5, 8, 7, 9,11,13,14,15, 6, 7, 9, 8, | ||
| 48 | 7, 6, 8,13,11, 9, 7,15, 7,12,15, 9,11, 7,13,12, | ||
| 49 | 11,13, 6, 7,14, 9,13,15,14, 8,13, 6, 5,12, 7, 5, | ||
| 50 | 11,12,14,15,14,15, 9, 8, 9,14, 5, 6, 8, 6, 5,12, | ||
| 51 | 9,15, 5,11, 6, 8,13,12, 5,12,13,14,11, 8, 5, 6, | ||
| 52 | ); | ||
| 53 | |||
| 54 | @sr=( 8, 9, 9,11,13,15,15, 5, 7, 7, 8,11,14,14,12, 6, | ||
| 55 | 9,13,15, 7,12, 8, 9,11, 7, 7,12, 7, 6,15,13,11, | ||
| 56 | 9, 7,15,11, 8, 6, 6,14,12,13, 5,14,13,13, 7, 5, | ||
| 57 | 15, 5, 8,11,14,14, 6,14, 6, 9,12, 9,12, 5,15, 8, | ||
| 58 | 8, 5,12, 9,12, 5,14, 6, 8,13, 6, 5,15,13,11,11, | ||
| 59 | ); | ||
| 60 | |||
| 61 | &ripemd160_block("ripemd160_block_x86"); | ||
| 62 | &asm_finish(); | ||
| 63 | |||
| 64 | sub Xv | ||
| 65 | { | ||
| 66 | local($n)=@_; | ||
| 67 | return(&swtmp($n+1)); | ||
| 68 | # tmp on stack | ||
| 69 | } | ||
| 70 | |||
| 71 | sub Np | ||
| 72 | { | ||
| 73 | local($p)=@_; | ||
| 74 | local(%n)=($A,$E,$B,$A,$C,$B,$D,$C,$E,$D); | ||
| 75 | return($n{$p}); | ||
| 76 | } | ||
| 77 | |||
| 78 | sub RIP1 | ||
| 79 | { | ||
| 80 | local($a,$b,$c,$d,$e,$pos,$s,$o,$pos2)=@_; | ||
| 81 | |||
| 82 | &comment($p++); | ||
| 83 | if ($p & 1) | ||
| 84 | { | ||
| 85 | &mov($tmp1, $c) if $o == -1; | ||
| 86 | &xor($tmp1, $d) if $o == -1; | ||
| 87 | &mov($tmp2, &Xv($pos)); | ||
| 88 | &xor($tmp1, $b); | ||
| 89 | &add($a, $tmp2); | ||
| 90 | &rotl($c, 10); | ||
| 91 | &add($a, $tmp1); | ||
| 92 | &mov($tmp1, &Np($c)); # NEXT | ||
| 93 | # XXX | ||
| 94 | &rotl($a, $s); | ||
| 95 | &add($a, $e); | ||
| 96 | } | ||
| 97 | else | ||
| 98 | { | ||
| 99 | &xor($tmp1, $d); | ||
| 100 | &mov($tmp2, &Xv($pos)); | ||
| 101 | &xor($tmp1, $b); | ||
| 102 | &add($a, $tmp1); | ||
| 103 | &mov($tmp1, &Np($c)) if $o <= 0; | ||
| 104 | &mov($tmp1, -1) if $o == 1; | ||
| 105 | # XXX if $o == 2; | ||
| 106 | &rotl($c, 10); | ||
| 107 | &add($a, $tmp2); | ||
| 108 | &xor($tmp1, &Np($d)) if $o <= 0; | ||
| 109 | &mov($tmp2, &Xv($pos2)) if $o == 1; | ||
| 110 | &mov($tmp2, &wparam(0)) if $o == 2; | ||
| 111 | &rotl($a, $s); | ||
| 112 | &add($a, $e); | ||
| 113 | } | ||
| 114 | } | ||
| 115 | |||
| 116 | sub RIP2 | ||
| 117 | { | ||
| 118 | local($a,$b,$c,$d,$e,$pos,$pos2,$s,$K,$o)=@_; | ||
| 119 | |||
| 120 | # XXXXXX | ||
| 121 | &comment($p++); | ||
| 122 | if ($p & 1) | ||
| 123 | { | ||
| 124 | # &mov($tmp2, &Xv($pos)) if $o < -1; | ||
| 125 | # &mov($tmp1, -1) if $o < -1; | ||
| 126 | |||
| 127 | &add($a, $tmp2); | ||
| 128 | &mov($tmp2, $c); | ||
| 129 | &sub($tmp1, $b); | ||
| 130 | &and($tmp2, $b); | ||
| 131 | &and($tmp1, $d); | ||
| 132 | &or($tmp2, $tmp1); | ||
| 133 | &mov($tmp1, &Xv($pos2)) if $o <= 0; # XXXXXXXXXXXXXX | ||
| 134 | # XXX | ||
| 135 | &rotl($c, 10); | ||
| 136 | &lea($a, &DWP($K,$a,$tmp2,1)); | ||
| 137 | &mov($tmp2, -1) if $o <= 0; | ||
| 138 | # XXX | ||
| 139 | &rotl($a, $s); | ||
| 140 | &add($a, $e); | ||
| 141 | } | ||
| 142 | else | ||
| 143 | { | ||
| 144 | # XXX | ||
| 145 | &add($a, $tmp1); | ||
| 146 | &mov($tmp1, $c); | ||
| 147 | &sub($tmp2, $b); | ||
| 148 | &and($tmp1, $b); | ||
| 149 | &and($tmp2, $d); | ||
| 150 | if ($o != 2) | ||
| 151 | { | ||
| 152 | &or($tmp1, $tmp2); | ||
| 153 | &mov($tmp2, &Xv($pos2)) if $o <= 0; | ||
| 154 | &mov($tmp2, -1) if $o == 1; | ||
| 155 | &rotl($c, 10); | ||
| 156 | &lea($a, &DWP($K,$a,$tmp1,1)); | ||
| 157 | &mov($tmp1, -1) if $o <= 0; | ||
| 158 | &sub($tmp2, &Np($c)) if $o == 1; | ||
| 159 | } else { | ||
| 160 | &or($tmp2, $tmp1); | ||
| 161 | &mov($tmp1, &Np($c)); | ||
| 162 | &rotl($c, 10); | ||
| 163 | &lea($a, &DWP($K,$a,$tmp2,1)); | ||
| 164 | &xor($tmp1, &Np($d)); | ||
| 165 | } | ||
| 166 | &rotl($a, $s); | ||
| 167 | &add($a, $e); | ||
| 168 | } | ||
| 169 | } | ||
| 170 | |||
| 171 | sub RIP3 | ||
| 172 | { | ||
| 173 | local($a,$b,$c,$d,$e,$pos,$s,$K,$o,$pos2)=@_; | ||
| 174 | |||
| 175 | &comment($p++); | ||
| 176 | if ($p & 1) | ||
| 177 | { | ||
| 178 | # &mov($tmp2, -1) if $o < -1; | ||
| 179 | # &sub($tmp2, $c) if $o < -1; | ||
| 180 | &mov($tmp1, &Xv($pos)); | ||
| 181 | &or($tmp2, $b); | ||
| 182 | &add($a, $tmp1); | ||
| 183 | &xor($tmp2, $d); | ||
| 184 | &mov($tmp1, -1) if $o <= 0; # NEXT | ||
| 185 | # XXX | ||
| 186 | &rotl($c, 10); | ||
| 187 | &lea($a, &DWP($K,$a,$tmp2,1)); | ||
| 188 | &sub($tmp1, &Np($c)) if $o <= 0; # NEXT | ||
| 189 | # XXX | ||
| 190 | &rotl($a, $s); | ||
| 191 | &add($a, $e); | ||
| 192 | } | ||
| 193 | else | ||
| 194 | { | ||
| 195 | &mov($tmp2, &Xv($pos)); | ||
| 196 | &or($tmp1, $b); | ||
| 197 | &add($a, $tmp2); | ||
| 198 | &xor($tmp1, $d); | ||
| 199 | &mov($tmp2, -1) if $o <= 0; # NEXT | ||
| 200 | &mov($tmp2, -1) if $o == 1; | ||
| 201 | &mov($tmp2, &Xv($pos2)) if $o == 2; | ||
| 202 | &rotl($c, 10); | ||
| 203 | &lea($a, &DWP($K,$a,$tmp1,1)); | ||
| 204 | &sub($tmp2, &Np($c)) if $o <= 0; # NEXT | ||
| 205 | &mov($tmp1, &Np($d)) if $o == 1; | ||
| 206 | &mov($tmp1, -1) if $o == 2; | ||
| 207 | &rotl($a, $s); | ||
| 208 | &add($a, $e); | ||
| 209 | } | ||
| 210 | } | ||
| 211 | |||
| 212 | sub RIP4 | ||
| 213 | { | ||
| 214 | local($a,$b,$c,$d,$e,$pos,$s,$K,$o)=@_; | ||
| 215 | |||
| 216 | &comment($p++); | ||
| 217 | if ($p & 1) | ||
| 218 | { | ||
| 219 | # &mov($tmp2, -1) if $o == -2; | ||
| 220 | # &mov($tmp1, $d) if $o == -2; | ||
| 221 | &sub($tmp2, $d); | ||
| 222 | &and($tmp1, $b); | ||
| 223 | &and($tmp2, $c); | ||
| 224 | &or($tmp2, $tmp1); | ||
| 225 | &mov($tmp1, &Xv($pos)); | ||
| 226 | &rotl($c, 10); | ||
| 227 | &lea($a, &DWP($K,$a,$tmp2)); | ||
| 228 | &mov($tmp2, -1) unless $o > 0; # NEXT | ||
| 229 | # XXX | ||
| 230 | &add($a, $tmp1); | ||
| 231 | &mov($tmp1, &Np($d)) unless $o > 0; # NEXT | ||
| 232 | # XXX | ||
| 233 | &rotl($a, $s); | ||
| 234 | &add($a, $e); | ||
| 235 | } | ||
| 236 | else | ||
| 237 | { | ||
| 238 | &sub($tmp2, $d); | ||
| 239 | &and($tmp1, $b); | ||
| 240 | &and($tmp2, $c); | ||
| 241 | &or($tmp2, $tmp1); | ||
| 242 | &mov($tmp1, &Xv($pos)); | ||
| 243 | &rotl($c, 10); | ||
| 244 | &lea($a, &DWP($K,$a,$tmp2)); | ||
| 245 | &mov($tmp2, -1) if $o == 0; # NEXT | ||
| 246 | &mov($tmp2, -1) if $o == 1; | ||
| 247 | &mov($tmp2, -1) if $o == 2; | ||
| 248 | # XXX | ||
| 249 | &add($a, $tmp1); | ||
| 250 | &mov($tmp1, &Np($d)) if $o == 0; # NEXT | ||
| 251 | &sub($tmp2, &Np($d)) if $o == 1; | ||
| 252 | &sub($tmp2, &Np($c)) if $o == 2; | ||
| 253 | # XXX | ||
| 254 | &rotl($a, $s); | ||
| 255 | &add($a, $e); | ||
| 256 | } | ||
| 257 | } | ||
| 258 | |||
| 259 | sub RIP5 | ||
| 260 | { | ||
| 261 | local($a,$b,$c,$d,$e,$pos,$s,$K,$o)=@_; | ||
| 262 | |||
| 263 | &comment($p++); | ||
| 264 | if ($p & 1) | ||
| 265 | { | ||
| 266 | &mov($tmp2, -1) if $o == -2; | ||
| 267 | &sub($tmp2, $d) if $o == -2; | ||
| 268 | &mov($tmp1, &Xv($pos)); | ||
| 269 | &or($tmp2, $c); | ||
| 270 | &add($a, $tmp1); | ||
| 271 | &xor($tmp2, $b); | ||
| 272 | &mov($tmp1, -1) if $o <= 0; | ||
| 273 | # XXX | ||
| 274 | &rotl($c, 10); | ||
| 275 | &lea($a, &DWP($K,$a,$tmp2,1)); | ||
| 276 | &sub($tmp1, &Np($d)) if $o <= 0; | ||
| 277 | # XXX | ||
| 278 | &rotl($a, $s); | ||
| 279 | &add($a, $e); | ||
| 280 | } | ||
| 281 | else | ||
| 282 | { | ||
| 283 | &mov($tmp2, &Xv($pos)); | ||
| 284 | &or($tmp1, $c); | ||
| 285 | &add($a, $tmp2); | ||
| 286 | &xor($tmp1, $b); | ||
| 287 | &mov($tmp2, -1) if $o <= 0; | ||
| 288 | &mov($tmp2, &wparam(0)) if $o == 1; # Middle code | ||
| 289 | &mov($tmp2, -1) if $o == 2; | ||
| 290 | &rotl($c, 10); | ||
| 291 | &lea($a, &DWP($K,$a,$tmp1,1)); | ||
| 292 | &sub($tmp2, &Np($d)) if $o <= 0; | ||
| 293 | &mov(&swtmp(1+16), $A) if $o == 1; | ||
| 294 | &mov($tmp1, &Np($d)) if $o == 2; | ||
| 295 | &rotl($a, $s); | ||
| 296 | &add($a, $e); | ||
| 297 | } | ||
| 298 | } | ||
| 299 | |||
| 300 | sub ripemd160_block | ||
| 301 | { | ||
| 302 | local($name)=@_; | ||
| 303 | |||
| 304 | &function_begin_B($name,"",3); | ||
| 305 | |||
| 306 | # parameter 1 is the RIPEMD160_CTX structure. | ||
| 307 | # A 0 | ||
| 308 | # B 4 | ||
| 309 | # C 8 | ||
| 310 | # D 12 | ||
| 311 | # E 16 | ||
| 312 | |||
| 313 | &push("esi"); | ||
| 314 | &mov($C, &wparam(2)); | ||
| 315 | &push("edi"); | ||
| 316 | &mov($tmp1, &wparam(1)); # edi | ||
| 317 | &push("ebp"); | ||
| 318 | &add($C, $tmp1); # offset we end at | ||
| 319 | &push("ebx"); | ||
| 320 | &sub($C, 64); | ||
| 321 | &stack_push(16+5+1); | ||
| 322 | # XXX | ||
| 323 | |||
| 324 | &mov(&swtmp(0), $C); | ||
| 325 | &mov($tmp2, &wparam(0)); # Done at end of loop | ||
| 326 | |||
| 327 | &set_label("start") unless $normal; | ||
| 328 | &comment(""); | ||
| 329 | |||
| 330 | # &mov($tmp1, &wparam(1)); # Done at end of loop | ||
| 331 | # &mov($tmp2, &wparam(0)); # Done at end of loop | ||
| 332 | |||
| 333 | for ($z=0; $z<16; $z+=2) | ||
| 334 | { | ||
| 335 | &mov($A, &DWP( $z*4,$tmp1,"",0)); | ||
| 336 | &mov($B, &DWP( ($z+1)*4,$tmp1,"",0)); | ||
| 337 | &mov(&swtmp(1+$z), $A); | ||
| 338 | &mov(&swtmp(1+$z+1), $B); | ||
| 339 | } | ||
| 340 | &add($tmp1, 64); | ||
| 341 | &mov($A, &DWP( 0,$tmp2,"",0)); | ||
| 342 | &mov(&wparam(1),$tmp1); | ||
| 343 | &mov($B, &DWP( 4,$tmp2,"",0)); | ||
| 344 | &mov($C, &DWP( 8,$tmp2,"",0)); | ||
| 345 | &mov($D, &DWP(12,$tmp2,"",0)); | ||
| 346 | &mov($E, &DWP(16,$tmp2,"",0)); | ||
| 347 | |||
| 348 | &RIP1($A,$B,$C,$D,$E,$wl[ 0],$sl[ 0],-1); | ||
| 349 | &RIP1($E,$A,$B,$C,$D,$wl[ 1],$sl[ 1],0); | ||
| 350 | &RIP1($D,$E,$A,$B,$C,$wl[ 2],$sl[ 2],0); | ||
| 351 | &RIP1($C,$D,$E,$A,$B,$wl[ 3],$sl[ 3],0); | ||
| 352 | &RIP1($B,$C,$D,$E,$A,$wl[ 4],$sl[ 4],0); | ||
| 353 | &RIP1($A,$B,$C,$D,$E,$wl[ 5],$sl[ 5],0); | ||
| 354 | &RIP1($E,$A,$B,$C,$D,$wl[ 6],$sl[ 6],0); | ||
| 355 | &RIP1($D,$E,$A,$B,$C,$wl[ 7],$sl[ 7],0); | ||
| 356 | &RIP1($C,$D,$E,$A,$B,$wl[ 8],$sl[ 8],0); | ||
| 357 | &RIP1($B,$C,$D,$E,$A,$wl[ 9],$sl[ 9],0); | ||
| 358 | &RIP1($A,$B,$C,$D,$E,$wl[10],$sl[10],0); | ||
| 359 | &RIP1($E,$A,$B,$C,$D,$wl[11],$sl[11],0); | ||
| 360 | &RIP1($D,$E,$A,$B,$C,$wl[12],$sl[12],0); | ||
| 361 | &RIP1($C,$D,$E,$A,$B,$wl[13],$sl[13],0); | ||
| 362 | &RIP1($B,$C,$D,$E,$A,$wl[14],$sl[14],0); | ||
| 363 | &RIP1($A,$B,$C,$D,$E,$wl[15],$sl[15],1,$wl[16]); | ||
| 364 | |||
| 365 | &RIP2($E,$A,$B,$C,$D,$wl[16],$wl[17],$sl[16],$KL1,-1); | ||
| 366 | &RIP2($D,$E,$A,$B,$C,$wl[17],$wl[18],$sl[17],$KL1,0); | ||
| 367 | &RIP2($C,$D,$E,$A,$B,$wl[18],$wl[19],$sl[18],$KL1,0); | ||
| 368 | &RIP2($B,$C,$D,$E,$A,$wl[19],$wl[20],$sl[19],$KL1,0); | ||
| 369 | &RIP2($A,$B,$C,$D,$E,$wl[20],$wl[21],$sl[20],$KL1,0); | ||
| 370 | &RIP2($E,$A,$B,$C,$D,$wl[21],$wl[22],$sl[21],$KL1,0); | ||
| 371 | &RIP2($D,$E,$A,$B,$C,$wl[22],$wl[23],$sl[22],$KL1,0); | ||
| 372 | &RIP2($C,$D,$E,$A,$B,$wl[23],$wl[24],$sl[23],$KL1,0); | ||
| 373 | &RIP2($B,$C,$D,$E,$A,$wl[24],$wl[25],$sl[24],$KL1,0); | ||
| 374 | &RIP2($A,$B,$C,$D,$E,$wl[25],$wl[26],$sl[25],$KL1,0); | ||
| 375 | &RIP2($E,$A,$B,$C,$D,$wl[26],$wl[27],$sl[26],$KL1,0); | ||
| 376 | &RIP2($D,$E,$A,$B,$C,$wl[27],$wl[28],$sl[27],$KL1,0); | ||
| 377 | &RIP2($C,$D,$E,$A,$B,$wl[28],$wl[29],$sl[28],$KL1,0); | ||
| 378 | &RIP2($B,$C,$D,$E,$A,$wl[29],$wl[30],$sl[29],$KL1,0); | ||
| 379 | &RIP2($A,$B,$C,$D,$E,$wl[30],$wl[31],$sl[30],$KL1,0); | ||
| 380 | &RIP2($E,$A,$B,$C,$D,$wl[31],$wl[32],$sl[31],$KL1,1); | ||
| 381 | |||
| 382 | &RIP3($D,$E,$A,$B,$C,$wl[32],$sl[32],$KL2,-1); | ||
| 383 | &RIP3($C,$D,$E,$A,$B,$wl[33],$sl[33],$KL2,0); | ||
| 384 | &RIP3($B,$C,$D,$E,$A,$wl[34],$sl[34],$KL2,0); | ||
| 385 | &RIP3($A,$B,$C,$D,$E,$wl[35],$sl[35],$KL2,0); | ||
| 386 | &RIP3($E,$A,$B,$C,$D,$wl[36],$sl[36],$KL2,0); | ||
| 387 | &RIP3($D,$E,$A,$B,$C,$wl[37],$sl[37],$KL2,0); | ||
| 388 | &RIP3($C,$D,$E,$A,$B,$wl[38],$sl[38],$KL2,0); | ||
| 389 | &RIP3($B,$C,$D,$E,$A,$wl[39],$sl[39],$KL2,0); | ||
| 390 | &RIP3($A,$B,$C,$D,$E,$wl[40],$sl[40],$KL2,0); | ||
| 391 | &RIP3($E,$A,$B,$C,$D,$wl[41],$sl[41],$KL2,0); | ||
| 392 | &RIP3($D,$E,$A,$B,$C,$wl[42],$sl[42],$KL2,0); | ||
| 393 | &RIP3($C,$D,$E,$A,$B,$wl[43],$sl[43],$KL2,0); | ||
| 394 | &RIP3($B,$C,$D,$E,$A,$wl[44],$sl[44],$KL2,0); | ||
| 395 | &RIP3($A,$B,$C,$D,$E,$wl[45],$sl[45],$KL2,0); | ||
| 396 | &RIP3($E,$A,$B,$C,$D,$wl[46],$sl[46],$KL2,0); | ||
| 397 | &RIP3($D,$E,$A,$B,$C,$wl[47],$sl[47],$KL2,1); | ||
| 398 | |||
| 399 | &RIP4($C,$D,$E,$A,$B,$wl[48],$sl[48],$KL3,-1); | ||
| 400 | &RIP4($B,$C,$D,$E,$A,$wl[49],$sl[49],$KL3,0); | ||
| 401 | &RIP4($A,$B,$C,$D,$E,$wl[50],$sl[50],$KL3,0); | ||
| 402 | &RIP4($E,$A,$B,$C,$D,$wl[51],$sl[51],$KL3,0); | ||
| 403 | &RIP4($D,$E,$A,$B,$C,$wl[52],$sl[52],$KL3,0); | ||
| 404 | &RIP4($C,$D,$E,$A,$B,$wl[53],$sl[53],$KL3,0); | ||
| 405 | &RIP4($B,$C,$D,$E,$A,$wl[54],$sl[54],$KL3,0); | ||
| 406 | &RIP4($A,$B,$C,$D,$E,$wl[55],$sl[55],$KL3,0); | ||
| 407 | &RIP4($E,$A,$B,$C,$D,$wl[56],$sl[56],$KL3,0); | ||
| 408 | &RIP4($D,$E,$A,$B,$C,$wl[57],$sl[57],$KL3,0); | ||
| 409 | &RIP4($C,$D,$E,$A,$B,$wl[58],$sl[58],$KL3,0); | ||
| 410 | &RIP4($B,$C,$D,$E,$A,$wl[59],$sl[59],$KL3,0); | ||
| 411 | &RIP4($A,$B,$C,$D,$E,$wl[60],$sl[60],$KL3,0); | ||
| 412 | &RIP4($E,$A,$B,$C,$D,$wl[61],$sl[61],$KL3,0); | ||
| 413 | &RIP4($D,$E,$A,$B,$C,$wl[62],$sl[62],$KL3,0); | ||
| 414 | &RIP4($C,$D,$E,$A,$B,$wl[63],$sl[63],$KL3,1); | ||
| 415 | |||
| 416 | &RIP5($B,$C,$D,$E,$A,$wl[64],$sl[64],$KL4,-1); | ||
| 417 | &RIP5($A,$B,$C,$D,$E,$wl[65],$sl[65],$KL4,0); | ||
| 418 | &RIP5($E,$A,$B,$C,$D,$wl[66],$sl[66],$KL4,0); | ||
| 419 | &RIP5($D,$E,$A,$B,$C,$wl[67],$sl[67],$KL4,0); | ||
| 420 | &RIP5($C,$D,$E,$A,$B,$wl[68],$sl[68],$KL4,0); | ||
| 421 | &RIP5($B,$C,$D,$E,$A,$wl[69],$sl[69],$KL4,0); | ||
| 422 | &RIP5($A,$B,$C,$D,$E,$wl[70],$sl[70],$KL4,0); | ||
| 423 | &RIP5($E,$A,$B,$C,$D,$wl[71],$sl[71],$KL4,0); | ||
| 424 | &RIP5($D,$E,$A,$B,$C,$wl[72],$sl[72],$KL4,0); | ||
| 425 | &RIP5($C,$D,$E,$A,$B,$wl[73],$sl[73],$KL4,0); | ||
| 426 | &RIP5($B,$C,$D,$E,$A,$wl[74],$sl[74],$KL4,0); | ||
| 427 | &RIP5($A,$B,$C,$D,$E,$wl[75],$sl[75],$KL4,0); | ||
| 428 | &RIP5($E,$A,$B,$C,$D,$wl[76],$sl[76],$KL4,0); | ||
| 429 | &RIP5($D,$E,$A,$B,$C,$wl[77],$sl[77],$KL4,0); | ||
| 430 | &RIP5($C,$D,$E,$A,$B,$wl[78],$sl[78],$KL4,0); | ||
| 431 | &RIP5($B,$C,$D,$E,$A,$wl[79],$sl[79],$KL4,1); | ||
| 432 | |||
| 433 | # &mov($tmp2, &wparam(0)); # moved into last RIP5 | ||
| 434 | # &mov(&swtmp(1+16), $A); | ||
| 435 | &mov($A, &DWP( 0,$tmp2,"",0)); | ||
| 436 | &mov(&swtmp(1+17), $B); | ||
| 437 | &mov(&swtmp(1+18), $C); | ||
| 438 | &mov($B, &DWP( 4,$tmp2,"",0)); | ||
| 439 | &mov(&swtmp(1+19), $D); | ||
| 440 | &mov($C, &DWP( 8,$tmp2,"",0)); | ||
| 441 | &mov(&swtmp(1+20), $E); | ||
| 442 | &mov($D, &DWP(12,$tmp2,"",0)); | ||
| 443 | &mov($E, &DWP(16,$tmp2,"",0)); | ||
| 444 | |||
| 445 | &RIP5($A,$B,$C,$D,$E,$wr[ 0],$sr[ 0],$KR0,-2); | ||
| 446 | &RIP5($E,$A,$B,$C,$D,$wr[ 1],$sr[ 1],$KR0,0); | ||
| 447 | &RIP5($D,$E,$A,$B,$C,$wr[ 2],$sr[ 2],$KR0,0); | ||
| 448 | &RIP5($C,$D,$E,$A,$B,$wr[ 3],$sr[ 3],$KR0,0); | ||
| 449 | &RIP5($B,$C,$D,$E,$A,$wr[ 4],$sr[ 4],$KR0,0); | ||
| 450 | &RIP5($A,$B,$C,$D,$E,$wr[ 5],$sr[ 5],$KR0,0); | ||
| 451 | &RIP5($E,$A,$B,$C,$D,$wr[ 6],$sr[ 6],$KR0,0); | ||
| 452 | &RIP5($D,$E,$A,$B,$C,$wr[ 7],$sr[ 7],$KR0,0); | ||
| 453 | &RIP5($C,$D,$E,$A,$B,$wr[ 8],$sr[ 8],$KR0,0); | ||
| 454 | &RIP5($B,$C,$D,$E,$A,$wr[ 9],$sr[ 9],$KR0,0); | ||
| 455 | &RIP5($A,$B,$C,$D,$E,$wr[10],$sr[10],$KR0,0); | ||
| 456 | &RIP5($E,$A,$B,$C,$D,$wr[11],$sr[11],$KR0,0); | ||
| 457 | &RIP5($D,$E,$A,$B,$C,$wr[12],$sr[12],$KR0,0); | ||
| 458 | &RIP5($C,$D,$E,$A,$B,$wr[13],$sr[13],$KR0,0); | ||
| 459 | &RIP5($B,$C,$D,$E,$A,$wr[14],$sr[14],$KR0,0); | ||
| 460 | &RIP5($A,$B,$C,$D,$E,$wr[15],$sr[15],$KR0,2); | ||
| 461 | |||
| 462 | &RIP4($E,$A,$B,$C,$D,$wr[16],$sr[16],$KR1,-2); | ||
| 463 | &RIP4($D,$E,$A,$B,$C,$wr[17],$sr[17],$KR1,0); | ||
| 464 | &RIP4($C,$D,$E,$A,$B,$wr[18],$sr[18],$KR1,0); | ||
| 465 | &RIP4($B,$C,$D,$E,$A,$wr[19],$sr[19],$KR1,0); | ||
| 466 | &RIP4($A,$B,$C,$D,$E,$wr[20],$sr[20],$KR1,0); | ||
| 467 | &RIP4($E,$A,$B,$C,$D,$wr[21],$sr[21],$KR1,0); | ||
| 468 | &RIP4($D,$E,$A,$B,$C,$wr[22],$sr[22],$KR1,0); | ||
| 469 | &RIP4($C,$D,$E,$A,$B,$wr[23],$sr[23],$KR1,0); | ||
| 470 | &RIP4($B,$C,$D,$E,$A,$wr[24],$sr[24],$KR1,0); | ||
| 471 | &RIP4($A,$B,$C,$D,$E,$wr[25],$sr[25],$KR1,0); | ||
| 472 | &RIP4($E,$A,$B,$C,$D,$wr[26],$sr[26],$KR1,0); | ||
| 473 | &RIP4($D,$E,$A,$B,$C,$wr[27],$sr[27],$KR1,0); | ||
| 474 | &RIP4($C,$D,$E,$A,$B,$wr[28],$sr[28],$KR1,0); | ||
| 475 | &RIP4($B,$C,$D,$E,$A,$wr[29],$sr[29],$KR1,0); | ||
| 476 | &RIP4($A,$B,$C,$D,$E,$wr[30],$sr[30],$KR1,0); | ||
| 477 | &RIP4($E,$A,$B,$C,$D,$wr[31],$sr[31],$KR1,2); | ||
| 478 | |||
| 479 | &RIP3($D,$E,$A,$B,$C,$wr[32],$sr[32],$KR2,-2); | ||
| 480 | &RIP3($C,$D,$E,$A,$B,$wr[33],$sr[33],$KR2,0); | ||
| 481 | &RIP3($B,$C,$D,$E,$A,$wr[34],$sr[34],$KR2,0); | ||
| 482 | &RIP3($A,$B,$C,$D,$E,$wr[35],$sr[35],$KR2,0); | ||
| 483 | &RIP3($E,$A,$B,$C,$D,$wr[36],$sr[36],$KR2,0); | ||
| 484 | &RIP3($D,$E,$A,$B,$C,$wr[37],$sr[37],$KR2,0); | ||
| 485 | &RIP3($C,$D,$E,$A,$B,$wr[38],$sr[38],$KR2,0); | ||
| 486 | &RIP3($B,$C,$D,$E,$A,$wr[39],$sr[39],$KR2,0); | ||
| 487 | &RIP3($A,$B,$C,$D,$E,$wr[40],$sr[40],$KR2,0); | ||
| 488 | &RIP3($E,$A,$B,$C,$D,$wr[41],$sr[41],$KR2,0); | ||
| 489 | &RIP3($D,$E,$A,$B,$C,$wr[42],$sr[42],$KR2,0); | ||
| 490 | &RIP3($C,$D,$E,$A,$B,$wr[43],$sr[43],$KR2,0); | ||
| 491 | &RIP3($B,$C,$D,$E,$A,$wr[44],$sr[44],$KR2,0); | ||
| 492 | &RIP3($A,$B,$C,$D,$E,$wr[45],$sr[45],$KR2,0); | ||
| 493 | &RIP3($E,$A,$B,$C,$D,$wr[46],$sr[46],$KR2,0); | ||
| 494 | &RIP3($D,$E,$A,$B,$C,$wr[47],$sr[47],$KR2,2,$wr[48]); | ||
| 495 | |||
| 496 | &RIP2($C,$D,$E,$A,$B,$wr[48],$wr[49],$sr[48],$KR3,-2); | ||
| 497 | &RIP2($B,$C,$D,$E,$A,$wr[49],$wr[50],$sr[49],$KR3,0); | ||
| 498 | &RIP2($A,$B,$C,$D,$E,$wr[50],$wr[51],$sr[50],$KR3,0); | ||
| 499 | &RIP2($E,$A,$B,$C,$D,$wr[51],$wr[52],$sr[51],$KR3,0); | ||
| 500 | &RIP2($D,$E,$A,$B,$C,$wr[52],$wr[53],$sr[52],$KR3,0); | ||
| 501 | &RIP2($C,$D,$E,$A,$B,$wr[53],$wr[54],$sr[53],$KR3,0); | ||
| 502 | &RIP2($B,$C,$D,$E,$A,$wr[54],$wr[55],$sr[54],$KR3,0); | ||
| 503 | &RIP2($A,$B,$C,$D,$E,$wr[55],$wr[56],$sr[55],$KR3,0); | ||
| 504 | &RIP2($E,$A,$B,$C,$D,$wr[56],$wr[57],$sr[56],$KR3,0); | ||
| 505 | &RIP2($D,$E,$A,$B,$C,$wr[57],$wr[58],$sr[57],$KR3,0); | ||
| 506 | &RIP2($C,$D,$E,$A,$B,$wr[58],$wr[59],$sr[58],$KR3,0); | ||
| 507 | &RIP2($B,$C,$D,$E,$A,$wr[59],$wr[60],$sr[59],$KR3,0); | ||
| 508 | &RIP2($A,$B,$C,$D,$E,$wr[60],$wr[61],$sr[60],$KR3,0); | ||
| 509 | &RIP2($E,$A,$B,$C,$D,$wr[61],$wr[62],$sr[61],$KR3,0); | ||
| 510 | &RIP2($D,$E,$A,$B,$C,$wr[62],$wr[63],$sr[62],$KR3,0); | ||
| 511 | &RIP2($C,$D,$E,$A,$B,$wr[63],$wr[64],$sr[63],$KR3,2); | ||
| 512 | |||
| 513 | &RIP1($B,$C,$D,$E,$A,$wr[64],$sr[64],-2); | ||
| 514 | &RIP1($A,$B,$C,$D,$E,$wr[65],$sr[65],0); | ||
| 515 | &RIP1($E,$A,$B,$C,$D,$wr[66],$sr[66],0); | ||
| 516 | &RIP1($D,$E,$A,$B,$C,$wr[67],$sr[67],0); | ||
| 517 | &RIP1($C,$D,$E,$A,$B,$wr[68],$sr[68],0); | ||
| 518 | &RIP1($B,$C,$D,$E,$A,$wr[69],$sr[69],0); | ||
| 519 | &RIP1($A,$B,$C,$D,$E,$wr[70],$sr[70],0); | ||
| 520 | &RIP1($E,$A,$B,$C,$D,$wr[71],$sr[71],0); | ||
| 521 | &RIP1($D,$E,$A,$B,$C,$wr[72],$sr[72],0); | ||
| 522 | &RIP1($C,$D,$E,$A,$B,$wr[73],$sr[73],0); | ||
| 523 | &RIP1($B,$C,$D,$E,$A,$wr[74],$sr[74],0); | ||
| 524 | &RIP1($A,$B,$C,$D,$E,$wr[75],$sr[75],0); | ||
| 525 | &RIP1($E,$A,$B,$C,$D,$wr[76],$sr[76],0); | ||
| 526 | &RIP1($D,$E,$A,$B,$C,$wr[77],$sr[77],0); | ||
| 527 | &RIP1($C,$D,$E,$A,$B,$wr[78],$sr[78],0); | ||
| 528 | &RIP1($B,$C,$D,$E,$A,$wr[79],$sr[79],2); | ||
| 529 | |||
| 530 | # &mov($tmp2, &wparam(0)); # Moved into last round | ||
| 531 | |||
| 532 | &mov($tmp1, &DWP( 4,$tmp2,"",0)); # ctx->B | ||
| 533 | &add($D, $tmp1); | ||
| 534 | &mov($tmp1, &swtmp(1+18)); # $c | ||
| 535 | &add($D, $tmp1); | ||
| 536 | |||
| 537 | &mov($tmp1, &DWP( 8,$tmp2,"",0)); # ctx->C | ||
| 538 | &add($E, $tmp1); | ||
| 539 | &mov($tmp1, &swtmp(1+19)); # $d | ||
| 540 | &add($E, $tmp1); | ||
| 541 | |||
| 542 | &mov($tmp1, &DWP(12,$tmp2,"",0)); # ctx->D | ||
| 543 | &add($A, $tmp1); | ||
| 544 | &mov($tmp1, &swtmp(1+20)); # $e | ||
| 545 | &add($A, $tmp1); | ||
| 546 | |||
| 547 | |||
| 548 | &mov($tmp1, &DWP(16,$tmp2,"",0)); # ctx->E | ||
| 549 | &add($B, $tmp1); | ||
| 550 | &mov($tmp1, &swtmp(1+16)); # $a | ||
| 551 | &add($B, $tmp1); | ||
| 552 | |||
| 553 | &mov($tmp1, &DWP( 0,$tmp2,"",0)); # ctx->A | ||
| 554 | &add($C, $tmp1); | ||
| 555 | &mov($tmp1, &swtmp(1+17)); # $b | ||
| 556 | &add($C, $tmp1); | ||
| 557 | |||
| 558 | &mov(&DWP( 0,$tmp2,"",0), $D); | ||
| 559 | &mov(&DWP( 4,$tmp2,"",0), $E); | ||
| 560 | &mov(&DWP( 8,$tmp2,"",0), $A); | ||
| 561 | &mov(&DWP(12,$tmp2,"",0), $B); | ||
| 562 | &mov(&DWP(16,$tmp2,"",0), $C); | ||
| 563 | |||
| 564 | &mov($tmp2, &swtmp(0)); | ||
| 565 | &mov($tmp1, &wparam(1)); | ||
| 566 | |||
| 567 | &cmp($tmp2,$tmp1); | ||
| 568 | &mov($tmp2, &wparam(0)); | ||
| 569 | |||
| 570 | # XXX | ||
| 571 | &jge(&label("start")); | ||
| 572 | |||
| 573 | &stack_pop(16+5+1); | ||
| 574 | |||
| 575 | &pop("ebx"); | ||
| 576 | &pop("ebp"); | ||
| 577 | &pop("edi"); | ||
| 578 | &pop("esi"); | ||
| 579 | &ret(); | ||
| 580 | &function_end_B($name); | ||
| 581 | } | ||
| 582 | |||
diff --git a/src/lib/libcrypto/ripemd/ripemd.h b/src/lib/libcrypto/ripemd/ripemd.h new file mode 100644 index 0000000000..a3bc6e3ab2 --- /dev/null +++ b/src/lib/libcrypto/ripemd/ripemd.h | |||
| @@ -0,0 +1,99 @@ | |||
| 1 | /* crypto/ripemd/ripemd.h */ | ||
| 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 | #ifndef HEADER_RIPEMD_H | ||
| 60 | #define HEADER_RIPEMD_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #define RIPEMD160_CBLOCK 64 | ||
| 67 | #define RIPEMD160_LBLOCK 16 | ||
| 68 | #define RIPEMD160_BLOCK 16 | ||
| 69 | #define RIPEMD160_LAST_BLOCK 56 | ||
| 70 | #define RIPEMD160_LENGTH_BLOCK 8 | ||
| 71 | #define RIPEMD160_DIGEST_LENGTH 20 | ||
| 72 | |||
| 73 | typedef struct RIPEMD160state_st | ||
| 74 | { | ||
| 75 | unsigned long A,B,C,D,E; | ||
| 76 | unsigned long Nl,Nh; | ||
| 77 | unsigned long data[RIPEMD160_LBLOCK]; | ||
| 78 | int num; | ||
| 79 | } RIPEMD160_CTX; | ||
| 80 | |||
| 81 | #ifndef NOPROTO | ||
| 82 | void RIPEMD160_Init(RIPEMD160_CTX *c); | ||
| 83 | void RIPEMD160_Update(RIPEMD160_CTX *c, unsigned char *data, unsigned long len); | ||
| 84 | void RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c); | ||
| 85 | unsigned char *RIPEMD160(unsigned char *d, unsigned long n, unsigned char *md); | ||
| 86 | void RIPEMD160_Transform(RIPEMD160_CTX *c, unsigned char *b); | ||
| 87 | #else | ||
| 88 | void RIPEMD160_Init(); | ||
| 89 | void RIPEMD160_Update(); | ||
| 90 | void RIPEMD160_Final(); | ||
| 91 | unsigned char *RIPEMD160(); | ||
| 92 | void RIPEMD160_Transform(); | ||
| 93 | #endif | ||
| 94 | |||
| 95 | #ifdef __cplusplus | ||
| 96 | } | ||
| 97 | #endif | ||
| 98 | |||
| 99 | #endif | ||
diff --git a/src/lib/libcrypto/ripemd/rmd_dgst.c b/src/lib/libcrypto/ripemd/rmd_dgst.c new file mode 100644 index 0000000000..210de1977d --- /dev/null +++ b/src/lib/libcrypto/ripemd/rmd_dgst.c | |||
| @@ -0,0 +1,535 @@ | |||
| 1 | /* crypto/ripemd/rmd_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 "rmd_locl.h" | ||
| 61 | |||
| 62 | char *RMD160_version="RIPEMD160 part of SSLeay 0.9.0b 29-Jun-1998"; | ||
| 63 | |||
| 64 | #ifndef NOPROTO | ||
| 65 | # ifdef RMD160_ASM | ||
| 66 | void ripemd160_block_x86(RIPEMD160_CTX *c, unsigned long *p,int num); | ||
| 67 | # define ripemd160_block ripemd160_block_x86 | ||
| 68 | # else | ||
| 69 | void ripemd160_block(RIPEMD160_CTX *c, unsigned long *p,int num); | ||
| 70 | # endif | ||
| 71 | #else | ||
| 72 | # ifdef RMD160_ASM | ||
| 73 | void ripemd160_block_x86(); | ||
| 74 | # define ripemd160_block ripemd160_block_x86 | ||
| 75 | # else | ||
| 76 | static void ripemd160_block(); | ||
| 77 | # endif | ||
| 78 | #endif | ||
| 79 | |||
| 80 | void RIPEMD160_Init(c) | ||
| 81 | RIPEMD160_CTX *c; | ||
| 82 | { | ||
| 83 | c->A=RIPEMD160_A; | ||
| 84 | c->B=RIPEMD160_B; | ||
| 85 | c->C=RIPEMD160_C; | ||
| 86 | c->D=RIPEMD160_D; | ||
| 87 | c->E=RIPEMD160_E; | ||
| 88 | c->Nl=0; | ||
| 89 | c->Nh=0; | ||
| 90 | c->num=0; | ||
| 91 | } | ||
| 92 | |||
| 93 | void RIPEMD160_Update(c, data, len) | ||
| 94 | RIPEMD160_CTX *c; | ||
| 95 | register unsigned char *data; | ||
| 96 | unsigned long len; | ||
| 97 | { | ||
| 98 | register ULONG *p; | ||
| 99 | int sw,sc; | ||
| 100 | ULONG l; | ||
| 101 | |||
| 102 | if (len == 0) return; | ||
| 103 | |||
| 104 | l=(c->Nl+(len<<3))&0xffffffffL; | ||
| 105 | if (l < c->Nl) /* overflow */ | ||
| 106 | c->Nh++; | ||
| 107 | c->Nh+=(len>>29); | ||
| 108 | c->Nl=l; | ||
| 109 | |||
| 110 | if (c->num != 0) | ||
| 111 | { | ||
| 112 | p=c->data; | ||
| 113 | sw=c->num>>2; | ||
| 114 | sc=c->num&0x03; | ||
| 115 | |||
| 116 | if ((c->num+len) >= RIPEMD160_CBLOCK) | ||
| 117 | { | ||
| 118 | l= p[sw]; | ||
| 119 | p_c2l(data,l,sc); | ||
| 120 | p[sw++]=l; | ||
| 121 | for (; sw<RIPEMD160_LBLOCK; sw++) | ||
| 122 | { | ||
| 123 | c2l(data,l); | ||
| 124 | p[sw]=l; | ||
| 125 | } | ||
| 126 | len-=(RIPEMD160_CBLOCK-c->num); | ||
| 127 | |||
| 128 | ripemd160_block(c,p,64); | ||
| 129 | c->num=0; | ||
| 130 | /* drop through and do the rest */ | ||
| 131 | } | ||
| 132 | else | ||
| 133 | { | ||
| 134 | int ew,ec; | ||
| 135 | |||
| 136 | c->num+=(int)len; | ||
| 137 | if ((sc+len) < 4) /* ugly, add char's to a word */ | ||
| 138 | { | ||
| 139 | l= p[sw]; | ||
| 140 | p_c2l_p(data,l,sc,len); | ||
| 141 | p[sw]=l; | ||
| 142 | } | ||
| 143 | else | ||
| 144 | { | ||
| 145 | ew=(c->num>>2); | ||
| 146 | ec=(c->num&0x03); | ||
| 147 | l= p[sw]; | ||
| 148 | p_c2l(data,l,sc); | ||
| 149 | p[sw++]=l; | ||
| 150 | for (; sw < ew; sw++) | ||
| 151 | { c2l(data,l); p[sw]=l; } | ||
| 152 | if (ec) | ||
| 153 | { | ||
| 154 | c2l_p(data,l,ec); | ||
| 155 | p[sw]=l; | ||
| 156 | } | ||
| 157 | } | ||
| 158 | return; | ||
| 159 | } | ||
| 160 | } | ||
| 161 | /* we now can process the input data in blocks of RIPEMD160_CBLOCK | ||
| 162 | * chars and save the leftovers to c->data. */ | ||
| 163 | #ifdef L_ENDIAN | ||
| 164 | if ((((unsigned long)data)%sizeof(ULONG)) == 0) | ||
| 165 | { | ||
| 166 | sw=(int)len/RIPEMD160_CBLOCK; | ||
| 167 | if (sw > 0) | ||
| 168 | { | ||
| 169 | sw*=RIPEMD160_CBLOCK; | ||
| 170 | ripemd160_block(c,(ULONG *)data,sw); | ||
| 171 | data+=sw; | ||
| 172 | len-=sw; | ||
| 173 | } | ||
| 174 | } | ||
| 175 | #endif | ||
| 176 | p=c->data; | ||
| 177 | while (len >= RIPEMD160_CBLOCK) | ||
| 178 | { | ||
| 179 | #if defined(L_ENDIAN) || defined(B_ENDIAN) | ||
| 180 | if (p != (unsigned long *)data) | ||
| 181 | memcpy(p,data,RIPEMD160_CBLOCK); | ||
| 182 | data+=RIPEMD160_CBLOCK; | ||
| 183 | #ifdef B_ENDIAN | ||
| 184 | for (sw=(RIPEMD160_LBLOCK/4); sw; sw--) | ||
| 185 | { | ||
| 186 | Endian_Reverse32(p[0]); | ||
| 187 | Endian_Reverse32(p[1]); | ||
| 188 | Endian_Reverse32(p[2]); | ||
| 189 | Endian_Reverse32(p[3]); | ||
| 190 | p+=4; | ||
| 191 | } | ||
| 192 | #endif | ||
| 193 | #else | ||
| 194 | for (sw=(RIPEMD160_LBLOCK/4); sw; sw--) | ||
| 195 | { | ||
| 196 | c2l(data,l); *(p++)=l; | ||
| 197 | c2l(data,l); *(p++)=l; | ||
| 198 | c2l(data,l); *(p++)=l; | ||
| 199 | c2l(data,l); *(p++)=l; | ||
| 200 | } | ||
| 201 | #endif | ||
| 202 | p=c->data; | ||
| 203 | ripemd160_block(c,p,64); | ||
| 204 | len-=RIPEMD160_CBLOCK; | ||
| 205 | } | ||
| 206 | sc=(int)len; | ||
| 207 | c->num=sc; | ||
| 208 | if (sc) | ||
| 209 | { | ||
| 210 | sw=sc>>2; /* words to copy */ | ||
| 211 | #ifdef L_ENDIAN | ||
| 212 | p[sw]=0; | ||
| 213 | memcpy(p,data,sc); | ||
| 214 | #else | ||
| 215 | sc&=0x03; | ||
| 216 | for ( ; sw; sw--) | ||
| 217 | { c2l(data,l); *(p++)=l; } | ||
| 218 | c2l_p(data,l,sc); | ||
| 219 | *p=l; | ||
| 220 | #endif | ||
| 221 | } | ||
| 222 | } | ||
| 223 | |||
| 224 | void RIPEMD160_Transform(c,b) | ||
| 225 | RIPEMD160_CTX *c; | ||
| 226 | unsigned char *b; | ||
| 227 | { | ||
| 228 | ULONG p[16]; | ||
| 229 | #if !defined(L_ENDIAN) | ||
| 230 | ULONG *q; | ||
| 231 | int i; | ||
| 232 | #endif | ||
| 233 | |||
| 234 | #if defined(B_ENDIAN) || defined(L_ENDIAN) | ||
| 235 | memcpy(p,b,64); | ||
| 236 | #ifdef B_ENDIAN | ||
| 237 | q=p; | ||
| 238 | for (i=(RIPEMD160_LBLOCK/4); i; i--) | ||
| 239 | { | ||
| 240 | Endian_Reverse32(q[0]); | ||
| 241 | Endian_Reverse32(q[1]); | ||
| 242 | Endian_Reverse32(q[2]); | ||
| 243 | Endian_Reverse32(q[3]); | ||
| 244 | q+=4; | ||
| 245 | } | ||
| 246 | #endif | ||
| 247 | #else | ||
| 248 | q=p; | ||
| 249 | for (i=(RIPEMD160_LBLOCK/4); i; i--) | ||
| 250 | { | ||
| 251 | ULONG l; | ||
| 252 | c2l(b,l); *(q++)=l; | ||
| 253 | c2l(b,l); *(q++)=l; | ||
| 254 | c2l(b,l); *(q++)=l; | ||
| 255 | c2l(b,l); *(q++)=l; | ||
| 256 | } | ||
| 257 | #endif | ||
| 258 | ripemd160_block(c,p,64); | ||
| 259 | } | ||
| 260 | |||
| 261 | #ifndef RMD160_ASM | ||
| 262 | |||
| 263 | void ripemd160_block(ctx, X, num) | ||
| 264 | RIPEMD160_CTX *ctx; | ||
| 265 | register ULONG *X; | ||
| 266 | int num; | ||
| 267 | { | ||
| 268 | register ULONG A,B,C,D,E; | ||
| 269 | ULONG a,b,c,d,e; | ||
| 270 | |||
| 271 | for (;;) | ||
| 272 | { | ||
| 273 | A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E; | ||
| 274 | |||
| 275 | RIP1(A,B,C,D,E,WL00,SL00); | ||
| 276 | RIP1(E,A,B,C,D,WL01,SL01); | ||
| 277 | RIP1(D,E,A,B,C,WL02,SL02); | ||
| 278 | RIP1(C,D,E,A,B,WL03,SL03); | ||
| 279 | RIP1(B,C,D,E,A,WL04,SL04); | ||
| 280 | RIP1(A,B,C,D,E,WL05,SL05); | ||
| 281 | RIP1(E,A,B,C,D,WL06,SL06); | ||
| 282 | RIP1(D,E,A,B,C,WL07,SL07); | ||
| 283 | RIP1(C,D,E,A,B,WL08,SL08); | ||
| 284 | RIP1(B,C,D,E,A,WL09,SL09); | ||
| 285 | RIP1(A,B,C,D,E,WL10,SL10); | ||
| 286 | RIP1(E,A,B,C,D,WL11,SL11); | ||
| 287 | RIP1(D,E,A,B,C,WL12,SL12); | ||
| 288 | RIP1(C,D,E,A,B,WL13,SL13); | ||
| 289 | RIP1(B,C,D,E,A,WL14,SL14); | ||
| 290 | RIP1(A,B,C,D,E,WL15,SL15); | ||
| 291 | |||
| 292 | RIP2(E,A,B,C,D,WL16,SL16,KL1); | ||
| 293 | RIP2(D,E,A,B,C,WL17,SL17,KL1); | ||
| 294 | RIP2(C,D,E,A,B,WL18,SL18,KL1); | ||
| 295 | RIP2(B,C,D,E,A,WL19,SL19,KL1); | ||
| 296 | RIP2(A,B,C,D,E,WL20,SL20,KL1); | ||
| 297 | RIP2(E,A,B,C,D,WL21,SL21,KL1); | ||
| 298 | RIP2(D,E,A,B,C,WL22,SL22,KL1); | ||
| 299 | RIP2(C,D,E,A,B,WL23,SL23,KL1); | ||
| 300 | RIP2(B,C,D,E,A,WL24,SL24,KL1); | ||
| 301 | RIP2(A,B,C,D,E,WL25,SL25,KL1); | ||
| 302 | RIP2(E,A,B,C,D,WL26,SL26,KL1); | ||
| 303 | RIP2(D,E,A,B,C,WL27,SL27,KL1); | ||
| 304 | RIP2(C,D,E,A,B,WL28,SL28,KL1); | ||
| 305 | RIP2(B,C,D,E,A,WL29,SL29,KL1); | ||
| 306 | RIP2(A,B,C,D,E,WL30,SL30,KL1); | ||
| 307 | RIP2(E,A,B,C,D,WL31,SL31,KL1); | ||
| 308 | |||
| 309 | RIP3(D,E,A,B,C,WL32,SL32,KL2); | ||
| 310 | RIP3(C,D,E,A,B,WL33,SL33,KL2); | ||
| 311 | RIP3(B,C,D,E,A,WL34,SL34,KL2); | ||
| 312 | RIP3(A,B,C,D,E,WL35,SL35,KL2); | ||
| 313 | RIP3(E,A,B,C,D,WL36,SL36,KL2); | ||
| 314 | RIP3(D,E,A,B,C,WL37,SL37,KL2); | ||
| 315 | RIP3(C,D,E,A,B,WL38,SL38,KL2); | ||
| 316 | RIP3(B,C,D,E,A,WL39,SL39,KL2); | ||
| 317 | RIP3(A,B,C,D,E,WL40,SL40,KL2); | ||
| 318 | RIP3(E,A,B,C,D,WL41,SL41,KL2); | ||
| 319 | RIP3(D,E,A,B,C,WL42,SL42,KL2); | ||
| 320 | RIP3(C,D,E,A,B,WL43,SL43,KL2); | ||
| 321 | RIP3(B,C,D,E,A,WL44,SL44,KL2); | ||
| 322 | RIP3(A,B,C,D,E,WL45,SL45,KL2); | ||
| 323 | RIP3(E,A,B,C,D,WL46,SL46,KL2); | ||
| 324 | RIP3(D,E,A,B,C,WL47,SL47,KL2); | ||
| 325 | |||
| 326 | RIP4(C,D,E,A,B,WL48,SL48,KL3); | ||
| 327 | RIP4(B,C,D,E,A,WL49,SL49,KL3); | ||
| 328 | RIP4(A,B,C,D,E,WL50,SL50,KL3); | ||
| 329 | RIP4(E,A,B,C,D,WL51,SL51,KL3); | ||
| 330 | RIP4(D,E,A,B,C,WL52,SL52,KL3); | ||
| 331 | RIP4(C,D,E,A,B,WL53,SL53,KL3); | ||
| 332 | RIP4(B,C,D,E,A,WL54,SL54,KL3); | ||
| 333 | RIP4(A,B,C,D,E,WL55,SL55,KL3); | ||
| 334 | RIP4(E,A,B,C,D,WL56,SL56,KL3); | ||
| 335 | RIP4(D,E,A,B,C,WL57,SL57,KL3); | ||
| 336 | RIP4(C,D,E,A,B,WL58,SL58,KL3); | ||
| 337 | RIP4(B,C,D,E,A,WL59,SL59,KL3); | ||
| 338 | RIP4(A,B,C,D,E,WL60,SL60,KL3); | ||
| 339 | RIP4(E,A,B,C,D,WL61,SL61,KL3); | ||
| 340 | RIP4(D,E,A,B,C,WL62,SL62,KL3); | ||
| 341 | RIP4(C,D,E,A,B,WL63,SL63,KL3); | ||
| 342 | |||
| 343 | RIP5(B,C,D,E,A,WL64,SL64,KL4); | ||
| 344 | RIP5(A,B,C,D,E,WL65,SL65,KL4); | ||
| 345 | RIP5(E,A,B,C,D,WL66,SL66,KL4); | ||
| 346 | RIP5(D,E,A,B,C,WL67,SL67,KL4); | ||
| 347 | RIP5(C,D,E,A,B,WL68,SL68,KL4); | ||
| 348 | RIP5(B,C,D,E,A,WL69,SL69,KL4); | ||
| 349 | RIP5(A,B,C,D,E,WL70,SL70,KL4); | ||
| 350 | RIP5(E,A,B,C,D,WL71,SL71,KL4); | ||
| 351 | RIP5(D,E,A,B,C,WL72,SL72,KL4); | ||
| 352 | RIP5(C,D,E,A,B,WL73,SL73,KL4); | ||
| 353 | RIP5(B,C,D,E,A,WL74,SL74,KL4); | ||
| 354 | RIP5(A,B,C,D,E,WL75,SL75,KL4); | ||
| 355 | RIP5(E,A,B,C,D,WL76,SL76,KL4); | ||
| 356 | RIP5(D,E,A,B,C,WL77,SL77,KL4); | ||
| 357 | RIP5(C,D,E,A,B,WL78,SL78,KL4); | ||
| 358 | RIP5(B,C,D,E,A,WL79,SL79,KL4); | ||
| 359 | |||
| 360 | a=A; b=B; c=C; d=D; e=E; | ||
| 361 | /* Do other half */ | ||
| 362 | A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E; | ||
| 363 | |||
| 364 | RIP5(A,B,C,D,E,WR00,SR00,KR0); | ||
| 365 | RIP5(E,A,B,C,D,WR01,SR01,KR0); | ||
| 366 | RIP5(D,E,A,B,C,WR02,SR02,KR0); | ||
| 367 | RIP5(C,D,E,A,B,WR03,SR03,KR0); | ||
| 368 | RIP5(B,C,D,E,A,WR04,SR04,KR0); | ||
| 369 | RIP5(A,B,C,D,E,WR05,SR05,KR0); | ||
| 370 | RIP5(E,A,B,C,D,WR06,SR06,KR0); | ||
| 371 | RIP5(D,E,A,B,C,WR07,SR07,KR0); | ||
| 372 | RIP5(C,D,E,A,B,WR08,SR08,KR0); | ||
| 373 | RIP5(B,C,D,E,A,WR09,SR09,KR0); | ||
| 374 | RIP5(A,B,C,D,E,WR10,SR10,KR0); | ||
| 375 | RIP5(E,A,B,C,D,WR11,SR11,KR0); | ||
| 376 | RIP5(D,E,A,B,C,WR12,SR12,KR0); | ||
| 377 | RIP5(C,D,E,A,B,WR13,SR13,KR0); | ||
| 378 | RIP5(B,C,D,E,A,WR14,SR14,KR0); | ||
| 379 | RIP5(A,B,C,D,E,WR15,SR15,KR0); | ||
| 380 | |||
| 381 | RIP4(E,A,B,C,D,WR16,SR16,KR1); | ||
| 382 | RIP4(D,E,A,B,C,WR17,SR17,KR1); | ||
| 383 | RIP4(C,D,E,A,B,WR18,SR18,KR1); | ||
| 384 | RIP4(B,C,D,E,A,WR19,SR19,KR1); | ||
| 385 | RIP4(A,B,C,D,E,WR20,SR20,KR1); | ||
| 386 | RIP4(E,A,B,C,D,WR21,SR21,KR1); | ||
| 387 | RIP4(D,E,A,B,C,WR22,SR22,KR1); | ||
| 388 | RIP4(C,D,E,A,B,WR23,SR23,KR1); | ||
| 389 | RIP4(B,C,D,E,A,WR24,SR24,KR1); | ||
| 390 | RIP4(A,B,C,D,E,WR25,SR25,KR1); | ||
| 391 | RIP4(E,A,B,C,D,WR26,SR26,KR1); | ||
| 392 | RIP4(D,E,A,B,C,WR27,SR27,KR1); | ||
| 393 | RIP4(C,D,E,A,B,WR28,SR28,KR1); | ||
| 394 | RIP4(B,C,D,E,A,WR29,SR29,KR1); | ||
| 395 | RIP4(A,B,C,D,E,WR30,SR30,KR1); | ||
| 396 | RIP4(E,A,B,C,D,WR31,SR31,KR1); | ||
| 397 | |||
| 398 | RIP3(D,E,A,B,C,WR32,SR32,KR2); | ||
| 399 | RIP3(C,D,E,A,B,WR33,SR33,KR2); | ||
| 400 | RIP3(B,C,D,E,A,WR34,SR34,KR2); | ||
| 401 | RIP3(A,B,C,D,E,WR35,SR35,KR2); | ||
| 402 | RIP3(E,A,B,C,D,WR36,SR36,KR2); | ||
| 403 | RIP3(D,E,A,B,C,WR37,SR37,KR2); | ||
| 404 | RIP3(C,D,E,A,B,WR38,SR38,KR2); | ||
| 405 | RIP3(B,C,D,E,A,WR39,SR39,KR2); | ||
| 406 | RIP3(A,B,C,D,E,WR40,SR40,KR2); | ||
| 407 | RIP3(E,A,B,C,D,WR41,SR41,KR2); | ||
| 408 | RIP3(D,E,A,B,C,WR42,SR42,KR2); | ||
| 409 | RIP3(C,D,E,A,B,WR43,SR43,KR2); | ||
| 410 | RIP3(B,C,D,E,A,WR44,SR44,KR2); | ||
| 411 | RIP3(A,B,C,D,E,WR45,SR45,KR2); | ||
| 412 | RIP3(E,A,B,C,D,WR46,SR46,KR2); | ||
| 413 | RIP3(D,E,A,B,C,WR47,SR47,KR2); | ||
| 414 | |||
| 415 | RIP2(C,D,E,A,B,WR48,SR48,KR3); | ||
| 416 | RIP2(B,C,D,E,A,WR49,SR49,KR3); | ||
| 417 | RIP2(A,B,C,D,E,WR50,SR50,KR3); | ||
| 418 | RIP2(E,A,B,C,D,WR51,SR51,KR3); | ||
| 419 | RIP2(D,E,A,B,C,WR52,SR52,KR3); | ||
| 420 | RIP2(C,D,E,A,B,WR53,SR53,KR3); | ||
| 421 | RIP2(B,C,D,E,A,WR54,SR54,KR3); | ||
| 422 | RIP2(A,B,C,D,E,WR55,SR55,KR3); | ||
| 423 | RIP2(E,A,B,C,D,WR56,SR56,KR3); | ||
| 424 | RIP2(D,E,A,B,C,WR57,SR57,KR3); | ||
| 425 | RIP2(C,D,E,A,B,WR58,SR58,KR3); | ||
| 426 | RIP2(B,C,D,E,A,WR59,SR59,KR3); | ||
| 427 | RIP2(A,B,C,D,E,WR60,SR60,KR3); | ||
| 428 | RIP2(E,A,B,C,D,WR61,SR61,KR3); | ||
| 429 | RIP2(D,E,A,B,C,WR62,SR62,KR3); | ||
| 430 | RIP2(C,D,E,A,B,WR63,SR63,KR3); | ||
| 431 | |||
| 432 | RIP1(B,C,D,E,A,WR64,SR64); | ||
| 433 | RIP1(A,B,C,D,E,WR65,SR65); | ||
| 434 | RIP1(E,A,B,C,D,WR66,SR66); | ||
| 435 | RIP1(D,E,A,B,C,WR67,SR67); | ||
| 436 | RIP1(C,D,E,A,B,WR68,SR68); | ||
| 437 | RIP1(B,C,D,E,A,WR69,SR69); | ||
| 438 | RIP1(A,B,C,D,E,WR70,SR70); | ||
| 439 | RIP1(E,A,B,C,D,WR71,SR71); | ||
| 440 | RIP1(D,E,A,B,C,WR72,SR72); | ||
| 441 | RIP1(C,D,E,A,B,WR73,SR73); | ||
| 442 | RIP1(B,C,D,E,A,WR74,SR74); | ||
| 443 | RIP1(A,B,C,D,E,WR75,SR75); | ||
| 444 | RIP1(E,A,B,C,D,WR76,SR76); | ||
| 445 | RIP1(D,E,A,B,C,WR77,SR77); | ||
| 446 | RIP1(C,D,E,A,B,WR78,SR78); | ||
| 447 | RIP1(B,C,D,E,A,WR79,SR79); | ||
| 448 | |||
| 449 | D =ctx->B+c+D; | ||
| 450 | ctx->B=ctx->C+d+E; | ||
| 451 | ctx->C=ctx->D+e+A; | ||
| 452 | ctx->D=ctx->E+a+B; | ||
| 453 | ctx->E=ctx->A+b+C; | ||
| 454 | ctx->A=D; | ||
| 455 | |||
| 456 | X+=16; | ||
| 457 | num-=64; | ||
| 458 | if (num <= 0) break; | ||
| 459 | } | ||
| 460 | } | ||
| 461 | #endif | ||
| 462 | |||
| 463 | void RIPEMD160_Final(md, c) | ||
| 464 | unsigned char *md; | ||
| 465 | RIPEMD160_CTX *c; | ||
| 466 | { | ||
| 467 | register int i,j; | ||
| 468 | register ULONG l; | ||
| 469 | register ULONG *p; | ||
| 470 | static unsigned char end[4]={0x80,0x00,0x00,0x00}; | ||
| 471 | unsigned char *cp=end; | ||
| 472 | |||
| 473 | /* c->num should definitly have room for at least one more byte. */ | ||
| 474 | p=c->data; | ||
| 475 | j=c->num; | ||
| 476 | i=j>>2; | ||
| 477 | |||
| 478 | /* purify often complains about the following line as an | ||
| 479 | * Uninitialized Memory Read. While this can be true, the | ||
| 480 | * following p_c2l macro will reset l when that case is true. | ||
| 481 | * This is because j&0x03 contains the number of 'valid' bytes | ||
| 482 | * already in p[i]. If and only if j&0x03 == 0, the UMR will | ||
| 483 | * occur but this is also the only time p_c2l will do | ||
| 484 | * l= *(cp++) instead of l|= *(cp++) | ||
| 485 | * Many thanks to Alex Tang <altitude@cic.net> for pickup this | ||
| 486 | * 'potential bug' */ | ||
| 487 | #ifdef PURIFY | ||
| 488 | if ((j&0x03) == 0) p[i]=0; | ||
| 489 | #endif | ||
| 490 | l=p[i]; | ||
| 491 | p_c2l(cp,l,j&0x03); | ||
| 492 | p[i]=l; | ||
| 493 | i++; | ||
| 494 | /* i is the next 'undefined word' */ | ||
| 495 | if (c->num >= RIPEMD160_LAST_BLOCK) | ||
| 496 | { | ||
| 497 | for (; i<RIPEMD160_LBLOCK; i++) | ||
| 498 | p[i]=0; | ||
| 499 | ripemd160_block(c,p,64); | ||
| 500 | i=0; | ||
| 501 | } | ||
| 502 | for (; i<(RIPEMD160_LBLOCK-2); i++) | ||
| 503 | p[i]=0; | ||
| 504 | p[RIPEMD160_LBLOCK-2]=c->Nl; | ||
| 505 | p[RIPEMD160_LBLOCK-1]=c->Nh; | ||
| 506 | ripemd160_block(c,p,64); | ||
| 507 | cp=md; | ||
| 508 | l=c->A; l2c(l,cp); | ||
| 509 | l=c->B; l2c(l,cp); | ||
| 510 | l=c->C; l2c(l,cp); | ||
| 511 | l=c->D; l2c(l,cp); | ||
| 512 | l=c->E; l2c(l,cp); | ||
| 513 | |||
| 514 | /* clear stuff, ripemd160_block may be leaving some stuff on the stack | ||
| 515 | * but I'm not worried :-) */ | ||
| 516 | c->num=0; | ||
| 517 | /* memset((char *)&c,0,sizeof(c));*/ | ||
| 518 | } | ||
| 519 | |||
| 520 | #ifdef undef | ||
| 521 | int printit(l) | ||
| 522 | unsigned long *l; | ||
| 523 | { | ||
| 524 | int i,ii; | ||
| 525 | |||
| 526 | for (i=0; i<2; i++) | ||
| 527 | { | ||
| 528 | for (ii=0; ii<8; ii++) | ||
| 529 | { | ||
| 530 | fprintf(stderr,"%08lx ",l[i*8+ii]); | ||
| 531 | } | ||
| 532 | fprintf(stderr,"\n"); | ||
| 533 | } | ||
| 534 | } | ||
| 535 | #endif | ||
diff --git a/src/lib/libcrypto/ripemd/rmd_locl.h b/src/lib/libcrypto/ripemd/rmd_locl.h new file mode 100644 index 0000000000..a1feccf7c1 --- /dev/null +++ b/src/lib/libcrypto/ripemd/rmd_locl.h | |||
| @@ -0,0 +1,226 @@ | |||
| 1 | /* crypto/ripemd/rmd_locl.h */ | ||
| 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 <stdlib.h> | ||
| 60 | #include <string.h> | ||
| 61 | #include "ripemd.h" | ||
| 62 | |||
| 63 | #define ULONG unsigned long | ||
| 64 | #define UCHAR unsigned char | ||
| 65 | #define UINT unsigned int | ||
| 66 | |||
| 67 | #ifdef NOCONST | ||
| 68 | #define const | ||
| 69 | #endif | ||
| 70 | |||
| 71 | #undef c2nl | ||
| 72 | #define c2nl(c,l) (l =(((unsigned long)(*((c)++)))<<24), \ | ||
| 73 | l|=(((unsigned long)(*((c)++)))<<16), \ | ||
| 74 | l|=(((unsigned long)(*((c)++)))<< 8), \ | ||
| 75 | l|=(((unsigned long)(*((c)++))) )) | ||
| 76 | |||
| 77 | #undef p_c2nl | ||
| 78 | #define p_c2nl(c,l,n) { \ | ||
| 79 | switch (n) { \ | ||
| 80 | case 0: l =((unsigned long)(*((c)++)))<<24; \ | ||
| 81 | case 1: l|=((unsigned long)(*((c)++)))<<16; \ | ||
| 82 | case 2: l|=((unsigned long)(*((c)++)))<< 8; \ | ||
| 83 | case 3: l|=((unsigned long)(*((c)++))); \ | ||
| 84 | } \ | ||
| 85 | } | ||
| 86 | |||
| 87 | #undef c2nl_p | ||
| 88 | /* NOTE the pointer is not incremented at the end of this */ | ||
| 89 | #define c2nl_p(c,l,n) { \ | ||
| 90 | l=0; \ | ||
| 91 | (c)+=n; \ | ||
| 92 | switch (n) { \ | ||
| 93 | case 3: l =((unsigned long)(*(--(c))))<< 8; \ | ||
| 94 | case 2: l|=((unsigned long)(*(--(c))))<<16; \ | ||
| 95 | case 1: l|=((unsigned long)(*(--(c))))<<24; \ | ||
| 96 | } \ | ||
| 97 | } | ||
| 98 | |||
| 99 | #undef p_c2nl_p | ||
| 100 | #define p_c2nl_p(c,l,sc,len) { \ | ||
| 101 | switch (sc) \ | ||
| 102 | { \ | ||
| 103 | case 0: l =((unsigned long)(*((c)++)))<<24; \ | ||
| 104 | if (--len == 0) break; \ | ||
| 105 | case 1: l|=((unsigned long)(*((c)++)))<<16; \ | ||
| 106 | if (--len == 0) break; \ | ||
| 107 | case 2: l|=((unsigned long)(*((c)++)))<< 8; \ | ||
| 108 | } \ | ||
| 109 | } | ||
| 110 | |||
| 111 | #undef nl2c | ||
| 112 | #define nl2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \ | ||
| 113 | *((c)++)=(unsigned char)(((l)>>16)&0xff), \ | ||
| 114 | *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ | ||
| 115 | *((c)++)=(unsigned char)(((l) )&0xff)) | ||
| 116 | |||
| 117 | #undef c2l | ||
| 118 | #define c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \ | ||
| 119 | l|=(((unsigned long)(*((c)++)))<< 8), \ | ||
| 120 | l|=(((unsigned long)(*((c)++)))<<16), \ | ||
| 121 | l|=(((unsigned long)(*((c)++)))<<24)) | ||
| 122 | |||
| 123 | #undef p_c2l | ||
| 124 | #define p_c2l(c,l,n) { \ | ||
| 125 | switch (n) { \ | ||
| 126 | case 0: l =((unsigned long)(*((c)++))); \ | ||
| 127 | case 1: l|=((unsigned long)(*((c)++)))<< 8; \ | ||
| 128 | case 2: l|=((unsigned long)(*((c)++)))<<16; \ | ||
| 129 | case 3: l|=((unsigned long)(*((c)++)))<<24; \ | ||
| 130 | } \ | ||
| 131 | } | ||
| 132 | |||
| 133 | #undef c2l_p | ||
| 134 | /* NOTE the pointer is not incremented at the end of this */ | ||
| 135 | #define c2l_p(c,l,n) { \ | ||
| 136 | l=0; \ | ||
| 137 | (c)+=n; \ | ||
| 138 | switch (n) { \ | ||
| 139 | case 3: l =((unsigned long)(*(--(c))))<<16; \ | ||
| 140 | case 2: l|=((unsigned long)(*(--(c))))<< 8; \ | ||
| 141 | case 1: l|=((unsigned long)(*(--(c)))); \ | ||
| 142 | } \ | ||
| 143 | } | ||
| 144 | |||
| 145 | #undef p_c2l_p | ||
| 146 | #define p_c2l_p(c,l,sc,len) { \ | ||
| 147 | switch (sc) \ | ||
| 148 | { \ | ||
| 149 | case 0: l =((unsigned long)(*((c)++))); \ | ||
| 150 | if (--len == 0) break; \ | ||
| 151 | case 1: l|=((unsigned long)(*((c)++)))<< 8; \ | ||
| 152 | if (--len == 0) break; \ | ||
| 153 | case 2: l|=((unsigned long)(*((c)++)))<<16; \ | ||
| 154 | } \ | ||
| 155 | } | ||
| 156 | |||
| 157 | #undef l2c | ||
| 158 | #define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ | ||
| 159 | *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ | ||
| 160 | *((c)++)=(unsigned char)(((l)>>16)&0xff), \ | ||
| 161 | *((c)++)=(unsigned char)(((l)>>24)&0xff)) | ||
| 162 | |||
| 163 | #undef ROTATE | ||
| 164 | #if defined(WIN32) | ||
| 165 | #define ROTATE(a,n) _lrotl(a,n) | ||
| 166 | #else | ||
| 167 | #define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n)))) | ||
| 168 | #endif | ||
| 169 | |||
| 170 | /* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */ | ||
| 171 | #if defined(WIN32) | ||
| 172 | /* 5 instructions with rotate instruction, else 9 */ | ||
| 173 | #define Endian_Reverse32(a) \ | ||
| 174 | { \ | ||
| 175 | unsigned long l=(a); \ | ||
| 176 | (a)=((ROTATE(l,8)&0x00FF00FF)|(ROTATE(l,24)&0xFF00FF00)); \ | ||
| 177 | } | ||
| 178 | #else | ||
| 179 | /* 6 instructions with rotate instruction, else 8 */ | ||
| 180 | #define Endian_Reverse32(a) \ | ||
| 181 | { \ | ||
| 182 | unsigned long l=(a); \ | ||
| 183 | l=(((l&0xFF00FF00)>>8L)|((l&0x00FF00FF)<<8L)); \ | ||
| 184 | (a)=ROTATE(l,16L); \ | ||
| 185 | } | ||
| 186 | #endif | ||
| 187 | |||
| 188 | #define F1(x,y,z) ((x)^(y)^(z)) | ||
| 189 | #define F2(x,y,z) (((x)&(y))|((~x)&z)) | ||
| 190 | #define F3(x,y,z) (((x)|(~y))^(z)) | ||
| 191 | #define F4(x,y,z) (((x)&(z))|((y)&(~(z)))) | ||
| 192 | #define F5(x,y,z) ((x)^((y)|(~(z)))) | ||
| 193 | |||
| 194 | #define RIPEMD160_A 0x67452301L | ||
| 195 | #define RIPEMD160_B 0xEFCDAB89L | ||
| 196 | #define RIPEMD160_C 0x98BADCFEL | ||
| 197 | #define RIPEMD160_D 0x10325476L | ||
| 198 | #define RIPEMD160_E 0xC3D2E1F0L | ||
| 199 | |||
| 200 | #include "rmdconst.h" | ||
| 201 | |||
| 202 | #define RIP1(a,b,c,d,e,w,s) { \ | ||
| 203 | a+=F1(b,c,d)+X[w]; \ | ||
| 204 | a=ROTATE(a,s)+e; \ | ||
| 205 | c=ROTATE(c,10); } | ||
| 206 | |||
| 207 | #define RIP2(a,b,c,d,e,w,s,K) { \ | ||
| 208 | a+=F2(b,c,d)+X[w]+K; \ | ||
| 209 | a=ROTATE(a,s)+e; \ | ||
| 210 | c=ROTATE(c,10); } | ||
| 211 | |||
| 212 | #define RIP3(a,b,c,d,e,w,s,K) { \ | ||
| 213 | a+=F3(b,c,d)+X[w]+K; \ | ||
| 214 | a=ROTATE(a,s)+e; \ | ||
| 215 | c=ROTATE(c,10); } | ||
| 216 | |||
| 217 | #define RIP4(a,b,c,d,e,w,s,K) { \ | ||
| 218 | a+=F4(b,c,d)+X[w]+K; \ | ||
| 219 | a=ROTATE(a,s)+e; \ | ||
| 220 | c=ROTATE(c,10); } | ||
| 221 | |||
| 222 | #define RIP5(a,b,c,d,e,w,s,K) { \ | ||
| 223 | a+=F5(b,c,d)+X[w]+K; \ | ||
| 224 | a=ROTATE(a,s)+e; \ | ||
| 225 | c=ROTATE(c,10); } | ||
| 226 | |||
diff --git a/src/lib/libcrypto/ripemd/rmd_one.c b/src/lib/libcrypto/ripemd/rmd_one.c new file mode 100644 index 0000000000..a7626dbcda --- /dev/null +++ b/src/lib/libcrypto/ripemd/rmd_one.c | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | /* crypto/ripemd/rmd_one.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 "rmd_locl.h" | ||
| 61 | |||
| 62 | unsigned char *RIPEMD160(d, n, md) | ||
| 63 | unsigned char *d; | ||
| 64 | unsigned long n; | ||
| 65 | unsigned char *md; | ||
| 66 | { | ||
| 67 | RIPEMD160_CTX c; | ||
| 68 | static unsigned char m[RIPEMD160_DIGEST_LENGTH]; | ||
| 69 | |||
| 70 | if (md == NULL) md=m; | ||
| 71 | RIPEMD160_Init(&c); | ||
| 72 | RIPEMD160_Update(&c,d,n); | ||
| 73 | RIPEMD160_Final(md,&c); | ||
| 74 | memset(&c,0,sizeof(c)); /* security consideration */ | ||
| 75 | return(md); | ||
| 76 | } | ||
| 77 | |||
diff --git a/src/lib/libcrypto/ripemd/rmdconst.h b/src/lib/libcrypto/ripemd/rmdconst.h new file mode 100644 index 0000000000..59c48dead1 --- /dev/null +++ b/src/lib/libcrypto/ripemd/rmdconst.h | |||
| @@ -0,0 +1,399 @@ | |||
| 1 | /* crypto/ripemd/rmdconst.h */ | ||
| 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 | #define KL0 0x00000000L | ||
| 59 | #define KL1 0x5A827999L | ||
| 60 | #define KL2 0x6ED9EBA1L | ||
| 61 | #define KL3 0x8F1BBCDCL | ||
| 62 | #define KL4 0xA953FD4EL | ||
| 63 | |||
| 64 | #define KR0 0x50A28BE6L | ||
| 65 | #define KR1 0x5C4DD124L | ||
| 66 | #define KR2 0x6D703EF3L | ||
| 67 | #define KR3 0x7A6D76E9L | ||
| 68 | #define KR4 0x00000000L | ||
| 69 | |||
| 70 | #define WL00 0 | ||
| 71 | #define SL00 11 | ||
| 72 | #define WL01 1 | ||
| 73 | #define SL01 14 | ||
| 74 | #define WL02 2 | ||
| 75 | #define SL02 15 | ||
| 76 | #define WL03 3 | ||
| 77 | #define SL03 12 | ||
| 78 | #define WL04 4 | ||
| 79 | #define SL04 5 | ||
| 80 | #define WL05 5 | ||
| 81 | #define SL05 8 | ||
| 82 | #define WL06 6 | ||
| 83 | #define SL06 7 | ||
| 84 | #define WL07 7 | ||
| 85 | #define SL07 9 | ||
| 86 | #define WL08 8 | ||
| 87 | #define SL08 11 | ||
| 88 | #define WL09 9 | ||
| 89 | #define SL09 13 | ||
| 90 | #define WL10 10 | ||
| 91 | #define SL10 14 | ||
| 92 | #define WL11 11 | ||
| 93 | #define SL11 15 | ||
| 94 | #define WL12 12 | ||
| 95 | #define SL12 6 | ||
| 96 | #define WL13 13 | ||
| 97 | #define SL13 7 | ||
| 98 | #define WL14 14 | ||
| 99 | #define SL14 9 | ||
| 100 | #define WL15 15 | ||
| 101 | #define SL15 8 | ||
| 102 | |||
| 103 | #define WL16 7 | ||
| 104 | #define SL16 7 | ||
| 105 | #define WL17 4 | ||
| 106 | #define SL17 6 | ||
| 107 | #define WL18 13 | ||
| 108 | #define SL18 8 | ||
| 109 | #define WL19 1 | ||
| 110 | #define SL19 13 | ||
| 111 | #define WL20 10 | ||
| 112 | #define SL20 11 | ||
| 113 | #define WL21 6 | ||
| 114 | #define SL21 9 | ||
| 115 | #define WL22 15 | ||
| 116 | #define SL22 7 | ||
| 117 | #define WL23 3 | ||
| 118 | #define SL23 15 | ||
| 119 | #define WL24 12 | ||
| 120 | #define SL24 7 | ||
| 121 | #define WL25 0 | ||
| 122 | #define SL25 12 | ||
| 123 | #define WL26 9 | ||
| 124 | #define SL26 15 | ||
| 125 | #define WL27 5 | ||
| 126 | #define SL27 9 | ||
| 127 | #define WL28 2 | ||
| 128 | #define SL28 11 | ||
| 129 | #define WL29 14 | ||
| 130 | #define SL29 7 | ||
| 131 | #define WL30 11 | ||
| 132 | #define SL30 13 | ||
| 133 | #define WL31 8 | ||
| 134 | #define SL31 12 | ||
| 135 | |||
| 136 | #define WL32 3 | ||
| 137 | #define SL32 11 | ||
| 138 | #define WL33 10 | ||
| 139 | #define SL33 13 | ||
| 140 | #define WL34 14 | ||
| 141 | #define SL34 6 | ||
| 142 | #define WL35 4 | ||
| 143 | #define SL35 7 | ||
| 144 | #define WL36 9 | ||
| 145 | #define SL36 14 | ||
| 146 | #define WL37 15 | ||
| 147 | #define SL37 9 | ||
| 148 | #define WL38 8 | ||
| 149 | #define SL38 13 | ||
| 150 | #define WL39 1 | ||
| 151 | #define SL39 15 | ||
| 152 | #define WL40 2 | ||
| 153 | #define SL40 14 | ||
| 154 | #define WL41 7 | ||
| 155 | #define SL41 8 | ||
| 156 | #define WL42 0 | ||
| 157 | #define SL42 13 | ||
| 158 | #define WL43 6 | ||
| 159 | #define SL43 6 | ||
| 160 | #define WL44 13 | ||
| 161 | #define SL44 5 | ||
| 162 | #define WL45 11 | ||
| 163 | #define SL45 12 | ||
| 164 | #define WL46 5 | ||
| 165 | #define SL46 7 | ||
| 166 | #define WL47 12 | ||
| 167 | #define SL47 5 | ||
| 168 | |||
| 169 | #define WL48 1 | ||
| 170 | #define SL48 11 | ||
| 171 | #define WL49 9 | ||
| 172 | #define SL49 12 | ||
| 173 | #define WL50 11 | ||
| 174 | #define SL50 14 | ||
| 175 | #define WL51 10 | ||
| 176 | #define SL51 15 | ||
| 177 | #define WL52 0 | ||
| 178 | #define SL52 14 | ||
| 179 | #define WL53 8 | ||
| 180 | #define SL53 15 | ||
| 181 | #define WL54 12 | ||
| 182 | #define SL54 9 | ||
| 183 | #define WL55 4 | ||
| 184 | #define SL55 8 | ||
| 185 | #define WL56 13 | ||
| 186 | #define SL56 9 | ||
| 187 | #define WL57 3 | ||
| 188 | #define SL57 14 | ||
| 189 | #define WL58 7 | ||
| 190 | #define SL58 5 | ||
| 191 | #define WL59 15 | ||
| 192 | #define SL59 6 | ||
| 193 | #define WL60 14 | ||
| 194 | #define SL60 8 | ||
| 195 | #define WL61 5 | ||
| 196 | #define SL61 6 | ||
| 197 | #define WL62 6 | ||
| 198 | #define SL62 5 | ||
| 199 | #define WL63 2 | ||
| 200 | #define SL63 12 | ||
| 201 | |||
| 202 | #define WL64 4 | ||
| 203 | #define SL64 9 | ||
| 204 | #define WL65 0 | ||
| 205 | #define SL65 15 | ||
| 206 | #define WL66 5 | ||
| 207 | #define SL66 5 | ||
| 208 | #define WL67 9 | ||
| 209 | #define SL67 11 | ||
| 210 | #define WL68 7 | ||
| 211 | #define SL68 6 | ||
| 212 | #define WL69 12 | ||
| 213 | #define SL69 8 | ||
| 214 | #define WL70 2 | ||
| 215 | #define SL70 13 | ||
| 216 | #define WL71 10 | ||
| 217 | #define SL71 12 | ||
| 218 | #define WL72 14 | ||
| 219 | #define SL72 5 | ||
| 220 | #define WL73 1 | ||
| 221 | #define SL73 12 | ||
| 222 | #define WL74 3 | ||
| 223 | #define SL74 13 | ||
| 224 | #define WL75 8 | ||
| 225 | #define SL75 14 | ||
| 226 | #define WL76 11 | ||
| 227 | #define SL76 11 | ||
| 228 | #define WL77 6 | ||
| 229 | #define SL77 8 | ||
| 230 | #define WL78 15 | ||
| 231 | #define SL78 5 | ||
| 232 | #define WL79 13 | ||
| 233 | #define SL79 6 | ||
| 234 | |||
| 235 | #define WR00 5 | ||
| 236 | #define SR00 8 | ||
| 237 | #define WR01 14 | ||
| 238 | #define SR01 9 | ||
| 239 | #define WR02 7 | ||
| 240 | #define SR02 9 | ||
| 241 | #define WR03 0 | ||
| 242 | #define SR03 11 | ||
| 243 | #define WR04 9 | ||
| 244 | #define SR04 13 | ||
| 245 | #define WR05 2 | ||
| 246 | #define SR05 15 | ||
| 247 | #define WR06 11 | ||
| 248 | #define SR06 15 | ||
| 249 | #define WR07 4 | ||
| 250 | #define SR07 5 | ||
| 251 | #define WR08 13 | ||
| 252 | #define SR08 7 | ||
| 253 | #define WR09 6 | ||
| 254 | #define SR09 7 | ||
| 255 | #define WR10 15 | ||
| 256 | #define SR10 8 | ||
| 257 | #define WR11 8 | ||
| 258 | #define SR11 11 | ||
| 259 | #define WR12 1 | ||
| 260 | #define SR12 14 | ||
| 261 | #define WR13 10 | ||
| 262 | #define SR13 14 | ||
| 263 | #define WR14 3 | ||
| 264 | #define SR14 12 | ||
| 265 | #define WR15 12 | ||
| 266 | #define SR15 6 | ||
| 267 | |||
| 268 | #define WR16 6 | ||
| 269 | #define SR16 9 | ||
| 270 | #define WR17 11 | ||
| 271 | #define SR17 13 | ||
| 272 | #define WR18 3 | ||
| 273 | #define SR18 15 | ||
| 274 | #define WR19 7 | ||
| 275 | #define SR19 7 | ||
| 276 | #define WR20 0 | ||
| 277 | #define SR20 12 | ||
| 278 | #define WR21 13 | ||
| 279 | #define SR21 8 | ||
| 280 | #define WR22 5 | ||
| 281 | #define SR22 9 | ||
| 282 | #define WR23 10 | ||
| 283 | #define SR23 11 | ||
| 284 | #define WR24 14 | ||
| 285 | #define SR24 7 | ||
| 286 | #define WR25 15 | ||
| 287 | #define SR25 7 | ||
| 288 | #define WR26 8 | ||
| 289 | #define SR26 12 | ||
| 290 | #define WR27 12 | ||
| 291 | #define SR27 7 | ||
| 292 | #define WR28 4 | ||
| 293 | #define SR28 6 | ||
| 294 | #define WR29 9 | ||
| 295 | #define SR29 15 | ||
| 296 | #define WR30 1 | ||
| 297 | #define SR30 13 | ||
| 298 | #define WR31 2 | ||
| 299 | #define SR31 11 | ||
| 300 | |||
| 301 | #define WR32 15 | ||
| 302 | #define SR32 9 | ||
| 303 | #define WR33 5 | ||
| 304 | #define SR33 7 | ||
| 305 | #define WR34 1 | ||
| 306 | #define SR34 15 | ||
| 307 | #define WR35 3 | ||
| 308 | #define SR35 11 | ||
| 309 | #define WR36 7 | ||
| 310 | #define SR36 8 | ||
| 311 | #define WR37 14 | ||
| 312 | #define SR37 6 | ||
| 313 | #define WR38 6 | ||
| 314 | #define SR38 6 | ||
| 315 | #define WR39 9 | ||
| 316 | #define SR39 14 | ||
| 317 | #define WR40 11 | ||
| 318 | #define SR40 12 | ||
| 319 | #define WR41 8 | ||
| 320 | #define SR41 13 | ||
| 321 | #define WR42 12 | ||
| 322 | #define SR42 5 | ||
| 323 | #define WR43 2 | ||
| 324 | #define SR43 14 | ||
| 325 | #define WR44 10 | ||
| 326 | #define SR44 13 | ||
| 327 | #define WR45 0 | ||
| 328 | #define SR45 13 | ||
| 329 | #define WR46 4 | ||
| 330 | #define SR46 7 | ||
| 331 | #define WR47 13 | ||
| 332 | #define SR47 5 | ||
| 333 | |||
| 334 | #define WR48 8 | ||
| 335 | #define SR48 15 | ||
| 336 | #define WR49 6 | ||
| 337 | #define SR49 5 | ||
| 338 | #define WR50 4 | ||
| 339 | #define SR50 8 | ||
| 340 | #define WR51 1 | ||
| 341 | #define SR51 11 | ||
| 342 | #define WR52 3 | ||
| 343 | #define SR52 14 | ||
| 344 | #define WR53 11 | ||
| 345 | #define SR53 14 | ||
| 346 | #define WR54 15 | ||
| 347 | #define SR54 6 | ||
| 348 | #define WR55 0 | ||
| 349 | #define SR55 14 | ||
| 350 | #define WR56 5 | ||
| 351 | #define SR56 6 | ||
| 352 | #define WR57 12 | ||
| 353 | #define SR57 9 | ||
| 354 | #define WR58 2 | ||
| 355 | #define SR58 12 | ||
| 356 | #define WR59 13 | ||
| 357 | #define SR59 9 | ||
| 358 | #define WR60 9 | ||
| 359 | #define SR60 12 | ||
| 360 | #define WR61 7 | ||
| 361 | #define SR61 5 | ||
| 362 | #define WR62 10 | ||
| 363 | #define SR62 15 | ||
| 364 | #define WR63 14 | ||
| 365 | #define SR63 8 | ||
| 366 | |||
| 367 | #define WR64 12 | ||
| 368 | #define SR64 8 | ||
| 369 | #define WR65 15 | ||
| 370 | #define SR65 5 | ||
| 371 | #define WR66 10 | ||
| 372 | #define SR66 12 | ||
| 373 | #define WR67 4 | ||
| 374 | #define SR67 9 | ||
| 375 | #define WR68 1 | ||
| 376 | #define SR68 12 | ||
| 377 | #define WR69 5 | ||
| 378 | #define SR69 5 | ||
| 379 | #define WR70 8 | ||
| 380 | #define SR70 14 | ||
| 381 | #define WR71 7 | ||
| 382 | #define SR71 6 | ||
| 383 | #define WR72 6 | ||
| 384 | #define SR72 8 | ||
| 385 | #define WR73 2 | ||
| 386 | #define SR73 13 | ||
| 387 | #define WR74 13 | ||
| 388 | #define SR74 6 | ||
| 389 | #define WR75 14 | ||
| 390 | #define SR75 5 | ||
| 391 | #define WR76 0 | ||
| 392 | #define SR76 15 | ||
| 393 | #define WR77 3 | ||
| 394 | #define SR77 13 | ||
| 395 | #define WR78 9 | ||
| 396 | #define SR78 11 | ||
| 397 | #define WR79 11 | ||
| 398 | #define SR79 11 | ||
| 399 | |||
diff --git a/src/lib/libcrypto/rsa/rsa.h b/src/lib/libcrypto/rsa/rsa.h new file mode 100644 index 0000000000..aeb78ffcd3 --- /dev/null +++ b/src/lib/libcrypto/rsa/rsa.h | |||
| @@ -0,0 +1,324 @@ | |||
| 1 | /* crypto/rsa/rsa.h */ | ||
| 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 | #ifndef HEADER_RSA_H | ||
| 60 | #define HEADER_RSA_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #include "bn.h" | ||
| 67 | #include "crypto.h" | ||
| 68 | |||
| 69 | typedef struct rsa_meth_st | ||
| 70 | { | ||
| 71 | char *name; | ||
| 72 | int (*rsa_pub_enc)(); | ||
| 73 | int (*rsa_pub_dec)(); | ||
| 74 | int (*rsa_priv_enc)(); | ||
| 75 | int (*rsa_priv_dec)(); | ||
| 76 | int (*rsa_mod_exp)(); /* Can be null */ | ||
| 77 | int (*bn_mod_exp)(); /* Can be null */ | ||
| 78 | int (*init)(/* RSA * */); /* called at new */ | ||
| 79 | int (*finish)(/* RSA * */); /* called at free */ | ||
| 80 | |||
| 81 | int flags; /* RSA_METHOD_FLAG_* things */ | ||
| 82 | char *app_data; /* may be needed! */ | ||
| 83 | } RSA_METHOD; | ||
| 84 | |||
| 85 | typedef struct rsa_st | ||
| 86 | { | ||
| 87 | /* The first parameter is used to pickup errors where | ||
| 88 | * this is passed instead of aEVP_PKEY, it is set to 0 */ | ||
| 89 | int pad; | ||
| 90 | int version; | ||
| 91 | RSA_METHOD *meth; | ||
| 92 | BIGNUM *n; | ||
| 93 | BIGNUM *e; | ||
| 94 | BIGNUM *d; | ||
| 95 | BIGNUM *p; | ||
| 96 | BIGNUM *q; | ||
| 97 | BIGNUM *dmp1; | ||
| 98 | BIGNUM *dmq1; | ||
| 99 | BIGNUM *iqmp; | ||
| 100 | /* be carefull using this if the RSA structure is shared */ | ||
| 101 | CRYPTO_EX_DATA ex_data; | ||
| 102 | int references; | ||
| 103 | int flags; | ||
| 104 | |||
| 105 | /* Normally used to cached montgomery values */ | ||
| 106 | char *method_mod_n; | ||
| 107 | char *method_mod_p; | ||
| 108 | char *method_mod_q; | ||
| 109 | |||
| 110 | BN_BLINDING *blinding; | ||
| 111 | } RSA; | ||
| 112 | |||
| 113 | #define RSA_3 0x3L | ||
| 114 | #define RSA_F4 0x10001L | ||
| 115 | |||
| 116 | #define RSA_METHOD_FLAG_NO_CHECK 0x01 /* don't check pub/private match */ | ||
| 117 | #define RSA_FLAG_CACHE_PUBLIC 0x02 | ||
| 118 | #define RSA_FLAG_CACHE_PRIVATE 0x04 | ||
| 119 | #define RSA_FLAG_BLINDING 0x08 | ||
| 120 | #define RSA_FLAG_THREAD_SAFE 0x10 | ||
| 121 | |||
| 122 | #define RSA_PKCS1_PADDING 1 | ||
| 123 | #define RSA_SSLV23_PADDING 2 | ||
| 124 | #define RSA_NO_PADDING 3 | ||
| 125 | |||
| 126 | #define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,(char *)arg) | ||
| 127 | #define RSA_get_app_data(s) RSA_get_ex_data(s,0) | ||
| 128 | |||
| 129 | #ifndef NOPROTO | ||
| 130 | RSA * RSA_new(void); | ||
| 131 | RSA * RSA_new_method(RSA_METHOD *method); | ||
| 132 | int RSA_size(RSA *); | ||
| 133 | RSA * RSA_generate_key(int bits, unsigned long e,void | ||
| 134 | (*callback)(int,int,char *),char *cb_arg); | ||
| 135 | /* next 4 return -1 on error */ | ||
| 136 | int RSA_public_encrypt(int flen, unsigned char *from, | ||
| 137 | unsigned char *to, RSA *rsa,int padding); | ||
| 138 | int RSA_private_encrypt(int flen, unsigned char *from, | ||
| 139 | unsigned char *to, RSA *rsa,int padding); | ||
| 140 | int RSA_public_decrypt(int flen, unsigned char *from, | ||
| 141 | unsigned char *to, RSA *rsa,int padding); | ||
| 142 | int RSA_private_decrypt(int flen, unsigned char *from, | ||
| 143 | unsigned char *to, RSA *rsa,int padding); | ||
| 144 | void RSA_free (RSA *r); | ||
| 145 | |||
| 146 | int RSA_flags(RSA *r); | ||
| 147 | |||
| 148 | void RSA_set_default_method(RSA_METHOD *meth); | ||
| 149 | |||
| 150 | /* If you have RSAref compiled in. */ | ||
| 151 | RSA_METHOD *RSA_PKCS1_RSAref(void); | ||
| 152 | |||
| 153 | /* these are the actual SSLeay RSA functions */ | ||
| 154 | RSA_METHOD *RSA_PKCS1_SSLeay(void); | ||
| 155 | |||
| 156 | void ERR_load_RSA_strings(void ); | ||
| 157 | |||
| 158 | RSA * d2i_RSAPublicKey(RSA **a, unsigned char **pp, long length); | ||
| 159 | int i2d_RSAPublicKey(RSA *a, unsigned char **pp); | ||
| 160 | RSA * d2i_RSAPrivateKey(RSA **a, unsigned char **pp, long length); | ||
| 161 | int i2d_RSAPrivateKey(RSA *a, unsigned char **pp); | ||
| 162 | #ifndef NO_FP_API | ||
| 163 | int RSA_print_fp(FILE *fp, RSA *r,int offset); | ||
| 164 | #endif | ||
| 165 | |||
| 166 | #ifdef HEADER_BIO_H | ||
| 167 | int RSA_print(BIO *bp, RSA *r,int offset); | ||
| 168 | #endif | ||
| 169 | |||
| 170 | int i2d_Netscape_RSA(RSA *a, unsigned char **pp, int (*cb)()); | ||
| 171 | RSA *d2i_Netscape_RSA(RSA **a, unsigned char **pp, long length, int (*cb)()); | ||
| 172 | /* Naughty internal function required elsewhere, to handle a MS structure | ||
| 173 | * that is the same as the netscape one :-) */ | ||
| 174 | RSA *d2i_Netscape_RSA_2(RSA **a, unsigned char **pp, long length, int (*cb)()); | ||
| 175 | |||
| 176 | /* The following 2 functions sign and verify a X509_SIG ASN1 object | ||
| 177 | * inside PKCS#1 padded RSA encryption */ | ||
| 178 | int RSA_sign(int type, unsigned char *m, unsigned int m_len, | ||
| 179 | unsigned char *sigret, unsigned int *siglen, RSA *rsa); | ||
| 180 | int RSA_verify(int type, unsigned char *m, unsigned int m_len, | ||
| 181 | unsigned char *sigbuf, unsigned int siglen, RSA *rsa); | ||
| 182 | |||
| 183 | /* The following 2 function sign and verify a ASN1_OCTET_STRING | ||
| 184 | * object inside PKCS#1 padded RSA encryption */ | ||
| 185 | int RSA_sign_ASN1_OCTET_STRING(int type, unsigned char *m, unsigned int m_len, | ||
| 186 | unsigned char *sigret, unsigned int *siglen, RSA *rsa); | ||
| 187 | int RSA_verify_ASN1_OCTET_STRING(int type, unsigned char *m, unsigned int m_len, | ||
| 188 | unsigned char *sigbuf, unsigned int siglen, RSA *rsa); | ||
| 189 | |||
| 190 | int RSA_blinding_on(RSA *rsa, BN_CTX *ctx); | ||
| 191 | void RSA_blinding_off(RSA *rsa); | ||
| 192 | |||
| 193 | int RSA_padding_add_PKCS1_type_1(unsigned char *to,int tlen, | ||
| 194 | unsigned char *f,int fl); | ||
| 195 | int RSA_padding_check_PKCS1_type_1(unsigned char *to,int tlen, | ||
| 196 | unsigned char *f,int fl); | ||
| 197 | int RSA_padding_add_PKCS1_type_2(unsigned char *to,int tlen, | ||
| 198 | unsigned char *f,int fl); | ||
| 199 | int RSA_padding_check_PKCS1_type_2(unsigned char *to,int tlen, | ||
| 200 | unsigned char *f,int fl); | ||
| 201 | int RSA_padding_add_SSLv23(unsigned char *to,int tlen, | ||
| 202 | unsigned char *f,int fl); | ||
| 203 | int RSA_padding_check_SSLv23(unsigned char *to,int tlen, | ||
| 204 | unsigned char *f,int fl); | ||
| 205 | int RSA_padding_add_none(unsigned char *to,int tlen, | ||
| 206 | unsigned char *f,int fl); | ||
| 207 | int RSA_padding_check_none(unsigned char *to,int tlen, | ||
| 208 | unsigned char *f,int fl); | ||
| 209 | |||
| 210 | int RSA_get_ex_new_index(long argl, char *argp, int (*new_func)(), | ||
| 211 | int (*dup_func)(), void (*free_func)()); | ||
| 212 | int RSA_set_ex_data(RSA *r,int idx,char *arg); | ||
| 213 | char *RSA_get_ex_data(RSA *r, int idx); | ||
| 214 | |||
| 215 | #else | ||
| 216 | |||
| 217 | RSA * RSA_new(); | ||
| 218 | RSA * RSA_new_method(); | ||
| 219 | int RSA_size(); | ||
| 220 | RSA * RSA_generate_key(); | ||
| 221 | int RSA_public_encrypt(); | ||
| 222 | int RSA_private_encrypt(); | ||
| 223 | int RSA_public_decrypt(); | ||
| 224 | int RSA_private_decrypt(); | ||
| 225 | void RSA_free (); | ||
| 226 | |||
| 227 | int RSA_flags(); | ||
| 228 | |||
| 229 | void RSA_set_default_method(); | ||
| 230 | |||
| 231 | /* RSA_METHOD *RSA_PKCS1_RSAref(); */ | ||
| 232 | RSA_METHOD *RSA_PKCS1_SSLeay(); | ||
| 233 | |||
| 234 | void ERR_load_RSA_strings(); | ||
| 235 | |||
| 236 | RSA * d2i_RSAPublicKey(); | ||
| 237 | int i2d_RSAPublicKey(); | ||
| 238 | RSA * d2i_RSAPrivateKey(); | ||
| 239 | int i2d_RSAPrivateKey(); | ||
| 240 | #ifndef NO_FP_API | ||
| 241 | int RSA_print_fp(); | ||
| 242 | #endif | ||
| 243 | |||
| 244 | int RSA_print(); | ||
| 245 | |||
| 246 | int i2d_Netscape_RSA(); | ||
| 247 | RSA *d2i_Netscape_RSA(); | ||
| 248 | RSA *d2i_Netscape_RSA_2(); | ||
| 249 | |||
| 250 | int RSA_sign(); | ||
| 251 | int RSA_verify(); | ||
| 252 | |||
| 253 | int RSA_sign_ASN1_OCTET_STRING(); | ||
| 254 | int RSA_verify_ASN1_OCTET_STRING(); | ||
| 255 | int RSA_blinding_on(); | ||
| 256 | void RSA_blinding_off(); | ||
| 257 | |||
| 258 | int RSA_padding_add_PKCS1_type_1(); | ||
| 259 | int RSA_padding_check_PKCS1_type_1(); | ||
| 260 | int RSA_padding_add_PKCS1_type_2(); | ||
| 261 | int RSA_padding_check_PKCS1_type_2(); | ||
| 262 | int RSA_padding_add_SSLv23(); | ||
| 263 | int RSA_padding_check_SSLv23(); | ||
| 264 | int RSA_padding_add_none(); | ||
| 265 | int RSA_padding_check_none(); | ||
| 266 | |||
| 267 | int RSA_get_ex_new_index(); | ||
| 268 | int RSA_set_ex_data(); | ||
| 269 | char *RSA_get_ex_data(); | ||
| 270 | |||
| 271 | #endif | ||
| 272 | |||
| 273 | /* BEGIN ERROR CODES */ | ||
| 274 | /* Error codes for the RSA functions. */ | ||
| 275 | |||
| 276 | /* Function codes. */ | ||
| 277 | #define RSA_F_RSA_EAY_PRIVATE_DECRYPT 100 | ||
| 278 | #define RSA_F_RSA_EAY_PRIVATE_ENCRYPT 101 | ||
| 279 | #define RSA_F_RSA_EAY_PUBLIC_DECRYPT 102 | ||
| 280 | #define RSA_F_RSA_EAY_PUBLIC_ENCRYPT 103 | ||
| 281 | #define RSA_F_RSA_GENERATE_KEY 104 | ||
| 282 | #define RSA_F_RSA_NEW_METHOD 105 | ||
| 283 | #define RSA_F_RSA_PADDING_ADD_NONE 106 | ||
| 284 | #define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 107 | ||
| 285 | #define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2 108 | ||
| 286 | #define RSA_F_RSA_PADDING_ADD_SSLV23 109 | ||
| 287 | #define RSA_F_RSA_PADDING_CHECK_NONE 110 | ||
| 288 | #define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1 111 | ||
| 289 | #define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2 112 | ||
| 290 | #define RSA_F_RSA_PADDING_CHECK_SSLV23 113 | ||
| 291 | #define RSA_F_RSA_PRINT 114 | ||
| 292 | #define RSA_F_RSA_PRINT_FP 115 | ||
| 293 | #define RSA_F_RSA_SIGN 116 | ||
| 294 | #define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 117 | ||
| 295 | #define RSA_F_RSA_VERIFY 118 | ||
| 296 | #define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING 119 | ||
| 297 | |||
| 298 | /* Reason codes. */ | ||
| 299 | #define RSA_R_ALGORITHM_MISMATCH 100 | ||
| 300 | #define RSA_R_BAD_E_VALUE 101 | ||
| 301 | #define RSA_R_BAD_FIXED_HEADER_DECRYPT 102 | ||
| 302 | #define RSA_R_BAD_PAD_BYTE_COUNT 103 | ||
| 303 | #define RSA_R_BAD_SIGNATURE 104 | ||
| 304 | #define RSA_R_BAD_ZERO_BYTE 105 | ||
| 305 | #define RSA_R_BLOCK_TYPE_IS_NOT_01 106 | ||
| 306 | #define RSA_R_BLOCK_TYPE_IS_NOT_02 107 | ||
| 307 | #define RSA_R_DATA_GREATER_THAN_MOD_LEN 108 | ||
| 308 | #define RSA_R_DATA_TOO_LARGE 109 | ||
| 309 | #define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 110 | ||
| 310 | #define RSA_R_DATA_TOO_SMALL 111 | ||
| 311 | #define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY 112 | ||
| 312 | #define RSA_R_NULL_BEFORE_BLOCK_MISSING 113 | ||
| 313 | #define RSA_R_PADDING_CHECK_FAILED 114 | ||
| 314 | #define RSA_R_SSLV3_ROLLBACK_ATTACK 115 | ||
| 315 | #define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116 | ||
| 316 | #define RSA_R_UNKNOWN_ALGORITHM_TYPE 117 | ||
| 317 | #define RSA_R_UNKNOWN_PADDING_TYPE 118 | ||
| 318 | #define RSA_R_WRONG_SIGNATURE_LENGTH 119 | ||
| 319 | |||
| 320 | #ifdef __cplusplus | ||
| 321 | } | ||
| 322 | #endif | ||
| 323 | #endif | ||
| 324 | |||
diff --git a/src/lib/libcrypto/rsa/rsa_eay.c b/src/lib/libcrypto/rsa/rsa_eay.c new file mode 100644 index 0000000000..42a77f11cd --- /dev/null +++ b/src/lib/libcrypto/rsa/rsa_eay.c | |||
| @@ -0,0 +1,274 @@ | |||
| 1 | |||
| 2 | /* This file has been explicitly broken by ryker for OpenBSD, July | ||
| 3 | * 1, 1998. In spite of the title, there is no implementation of the | ||
| 4 | * RSA algorithm left in this file. All these routines will return an | ||
| 5 | * error and fail when called. They exist as stubs and can be | ||
| 6 | * ressurected from the bit bucket by someone in the free world once | ||
| 7 | * the RSA algorithm is no longer subject to patent problems. Eric | ||
| 8 | * Young's original copyright is below. | ||
| 9 | */ | ||
| 10 | |||
| 11 | /* crypto/rsa/rsa_eay.c */ | ||
| 12 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 13 | * All rights reserved. | ||
| 14 | * | ||
| 15 | * This package is an SSL implementation written | ||
| 16 | * by Eric Young (eay@cryptsoft.com). | ||
| 17 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 18 | * | ||
| 19 | * This library is free for commercial and non-commercial use as long as | ||
| 20 | * the following conditions are aheared to. The following conditions | ||
| 21 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 22 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 23 | * included with this distribution is covered by the same copyright terms | ||
| 24 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 25 | * | ||
| 26 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 27 | * the code are not to be removed. | ||
| 28 | * If this package is used in a product, Eric Young should be given attribution | ||
| 29 | * as the author of the parts of the library used. | ||
| 30 | * This can be in the form of a textual message at program startup or | ||
| 31 | * in documentation (online or textual) provided with the package. | ||
| 32 | * | ||
| 33 | * Redistribution and use in source and binary forms, with or without | ||
| 34 | * modification, are permitted provided that the following conditions | ||
| 35 | * are met: | ||
| 36 | * 1. Redistributions of source code must retain the copyright | ||
| 37 | * notice, this list of conditions and the following disclaimer. | ||
| 38 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 39 | * notice, this list of conditions and the following disclaimer in the | ||
| 40 | * documentation and/or other materials provided with the distribution. | ||
| 41 | * 3. All advertising materials mentioning features or use of this software | ||
| 42 | * must display the following acknowledgement: | ||
| 43 | * "This product includes cryptographic software written by | ||
| 44 | * Eric Young (eay@cryptsoft.com)" | ||
| 45 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 46 | * being used are not cryptographic related :-). | ||
| 47 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 48 | * the apps directory (application code) you must include an acknowledgement: | ||
| 49 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 50 | * | ||
| 51 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 52 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 53 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 54 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 55 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 56 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 57 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 58 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 59 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 60 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 61 | * SUCH DAMAGE. | ||
| 62 | * | ||
| 63 | * The licence and distribution terms for any publically available version or | ||
| 64 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 65 | * copied and put under another distribution licence | ||
| 66 | * [including the GNU Public Licence.] | ||
| 67 | */ | ||
| 68 | |||
| 69 | #include <stdio.h> | ||
| 70 | #include "cryptlib.h" | ||
| 71 | #include "bn.h" | ||
| 72 | #include "rsa.h" | ||
| 73 | #include "rand.h" | ||
| 74 | |||
| 75 | #ifndef NOPROTO | ||
| 76 | static int RSA_eay_public_encrypt(int flen, unsigned char *from, | ||
| 77 | unsigned char *to, RSA *rsa,int padding); | ||
| 78 | static int RSA_eay_private_encrypt(int flen, unsigned char *from, | ||
| 79 | unsigned char *to, RSA *rsa,int padding); | ||
| 80 | static int RSA_eay_public_decrypt(int flen, unsigned char *from, | ||
| 81 | unsigned char *to, RSA *rsa,int padding); | ||
| 82 | static int RSA_eay_private_decrypt(int flen, unsigned char *from, | ||
| 83 | unsigned char *to, RSA *rsa,int padding); | ||
| 84 | static int RSA_eay_mod_exp(BIGNUM *r0, BIGNUM *i, RSA *rsa); | ||
| 85 | static int RSA_eay_init(RSA *rsa); | ||
| 86 | static int RSA_eay_finish(RSA *rsa); | ||
| 87 | #else | ||
| 88 | static int RSA_eay_public_encrypt(); | ||
| 89 | static int RSA_eay_private_encrypt(); | ||
| 90 | static int RSA_eay_public_decrypt(); | ||
| 91 | static int RSA_eay_private_decrypt(); | ||
| 92 | static int RSA_eay_mod_exp(); | ||
| 93 | static int RSA_eay_init(); | ||
| 94 | static int RSA_eay_finish(); | ||
| 95 | #endif | ||
| 96 | |||
| 97 | static RSA_METHOD rsa_pkcs1_eay_meth={ | ||
| 98 | "Eric Young's PKCS#1 RSA", | ||
| 99 | RSA_eay_public_encrypt, | ||
| 100 | RSA_eay_public_decrypt, | ||
| 101 | RSA_eay_private_encrypt, | ||
| 102 | RSA_eay_private_decrypt, | ||
| 103 | RSA_eay_mod_exp, | ||
| 104 | BN_mod_exp_mont, | ||
| 105 | RSA_eay_init, | ||
| 106 | RSA_eay_finish, | ||
| 107 | 0, | ||
| 108 | NULL, | ||
| 109 | }; | ||
| 110 | |||
| 111 | RSA_METHOD *RSA_PKCS1_SSLeay() | ||
| 112 | { | ||
| 113 | return(&rsa_pkcs1_eay_meth); | ||
| 114 | } | ||
| 115 | |||
| 116 | static int RSA_eay_public_encrypt(flen, from, to, rsa, padding) | ||
| 117 | int flen; | ||
| 118 | unsigned char *from; | ||
| 119 | unsigned char *to; | ||
| 120 | RSA *rsa; | ||
| 121 | int padding; | ||
| 122 | { | ||
| 123 | BIGNUM *f=NULL,*ret=NULL; | ||
| 124 | int i,j,k,num=0,r= -1; | ||
| 125 | unsigned char *buf=NULL; | ||
| 126 | BN_CTX *ctx=NULL; | ||
| 127 | |||
| 128 | /* Body of this routine removed for OpenBSD - will return | ||
| 129 | * when the RSA patent expires | ||
| 130 | */ | ||
| 131 | |||
| 132 | err: | ||
| 133 | if (ctx != NULL) BN_CTX_free(ctx); | ||
| 134 | if (f != NULL) BN_free(f); | ||
| 135 | if (ret != NULL) BN_free(ret); | ||
| 136 | if (buf != NULL) | ||
| 137 | { | ||
| 138 | memset(buf,0,num); | ||
| 139 | Free(buf); | ||
| 140 | } | ||
| 141 | return(r); | ||
| 142 | } | ||
| 143 | |||
| 144 | static int RSA_eay_private_encrypt(flen, from, to, rsa, padding) | ||
| 145 | int flen; | ||
| 146 | unsigned char *from; | ||
| 147 | unsigned char *to; | ||
| 148 | RSA *rsa; | ||
| 149 | int padding; | ||
| 150 | { | ||
| 151 | BIGNUM *f=NULL,*ret=NULL; | ||
| 152 | int i,j,k,num=0,r= -1; | ||
| 153 | unsigned char *buf=NULL; | ||
| 154 | BN_CTX *ctx=NULL; | ||
| 155 | |||
| 156 | /* Body of this routine removed for OpenBSD - will return | ||
| 157 | * when the RSA patent expires | ||
| 158 | */ | ||
| 159 | |||
| 160 | err: | ||
| 161 | if (ctx != NULL) BN_CTX_free(ctx); | ||
| 162 | if (ret != NULL) BN_free(ret); | ||
| 163 | if (f != NULL) BN_free(f); | ||
| 164 | if (buf != NULL) | ||
| 165 | { | ||
| 166 | memset(buf,0,num); | ||
| 167 | Free(buf); | ||
| 168 | } | ||
| 169 | return(r); | ||
| 170 | } | ||
| 171 | |||
| 172 | static int RSA_eay_private_decrypt(flen, from, to, rsa,padding) | ||
| 173 | int flen; | ||
| 174 | unsigned char *from; | ||
| 175 | unsigned char *to; | ||
| 176 | RSA *rsa; | ||
| 177 | int padding; | ||
| 178 | { | ||
| 179 | BIGNUM *f=NULL,*ret=NULL; | ||
| 180 | int j,num=0,r= -1; | ||
| 181 | unsigned char *p; | ||
| 182 | unsigned char *buf=NULL; | ||
| 183 | BN_CTX *ctx=NULL; | ||
| 184 | |||
| 185 | /* Body of this routine removed for OpenBSD - will return | ||
| 186 | * when the RSA patent expires | ||
| 187 | */ | ||
| 188 | |||
| 189 | err: | ||
| 190 | if (ctx != NULL) BN_CTX_free(ctx); | ||
| 191 | if (f != NULL) BN_free(f); | ||
| 192 | if (ret != NULL) BN_free(ret); | ||
| 193 | if (buf != NULL) | ||
| 194 | { | ||
| 195 | memset(buf,0,num); | ||
| 196 | Free(buf); | ||
| 197 | } | ||
| 198 | return(r); | ||
| 199 | } | ||
| 200 | |||
| 201 | static int RSA_eay_public_decrypt(flen, from, to, rsa, padding) | ||
| 202 | int flen; | ||
| 203 | unsigned char *from; | ||
| 204 | unsigned char *to; | ||
| 205 | RSA *rsa; | ||
| 206 | int padding; | ||
| 207 | { | ||
| 208 | BIGNUM *f=NULL,*ret=NULL; | ||
| 209 | int i,num=0,r= -1; | ||
| 210 | unsigned char *p; | ||
| 211 | unsigned char *buf=NULL; | ||
| 212 | BN_CTX *ctx=NULL; | ||
| 213 | |||
| 214 | |||
| 215 | /* Body of this routine removed for OpenBSD - will return | ||
| 216 | * when the RSA patent expires | ||
| 217 | */ | ||
| 218 | |||
| 219 | err: | ||
| 220 | if (ctx != NULL) BN_CTX_free(ctx); | ||
| 221 | if (f != NULL) BN_free(f); | ||
| 222 | if (ret != NULL) BN_free(ret); | ||
| 223 | if (buf != NULL) | ||
| 224 | { | ||
| 225 | memset(buf,0,num); | ||
| 226 | Free(buf); | ||
| 227 | } | ||
| 228 | return(r); | ||
| 229 | } | ||
| 230 | |||
| 231 | static int RSA_eay_mod_exp(r0, I, rsa) | ||
| 232 | BIGNUM *r0; | ||
| 233 | BIGNUM *I; | ||
| 234 | RSA *rsa; | ||
| 235 | { | ||
| 236 | BIGNUM *r1=NULL,*m1=NULL; | ||
| 237 | int ret=0; | ||
| 238 | BN_CTX *ctx; | ||
| 239 | |||
| 240 | if ((ctx=BN_CTX_new()) == NULL) goto err; | ||
| 241 | m1=BN_new(); | ||
| 242 | r1=BN_new(); | ||
| 243 | if ((m1 == NULL) || (r1 == NULL)) goto err; | ||
| 244 | |||
| 245 | /* Body of this routine removed for OpenBSD - will return | ||
| 246 | * when the RSA patent expires | ||
| 247 | */ | ||
| 248 | err: | ||
| 249 | if (m1 != NULL) BN_free(m1); | ||
| 250 | if (r1 != NULL) BN_free(r1); | ||
| 251 | BN_CTX_free(ctx); | ||
| 252 | return(ret); | ||
| 253 | } | ||
| 254 | |||
| 255 | static int RSA_eay_init(rsa) | ||
| 256 | RSA *rsa; | ||
| 257 | { | ||
| 258 | rsa->flags|=RSA_FLAG_CACHE_PUBLIC|RSA_FLAG_CACHE_PRIVATE; | ||
| 259 | return(1); | ||
| 260 | } | ||
| 261 | |||
| 262 | static int RSA_eay_finish(rsa) | ||
| 263 | RSA *rsa; | ||
| 264 | { | ||
| 265 | if (rsa->method_mod_n != NULL) | ||
| 266 | BN_MONT_CTX_free((BN_MONT_CTX *)rsa->method_mod_n); | ||
| 267 | if (rsa->method_mod_p != NULL) | ||
| 268 | BN_MONT_CTX_free((BN_MONT_CTX *)rsa->method_mod_p); | ||
| 269 | if (rsa->method_mod_q != NULL) | ||
| 270 | BN_MONT_CTX_free((BN_MONT_CTX *)rsa->method_mod_q); | ||
| 271 | return(1); | ||
| 272 | } | ||
| 273 | |||
| 274 | |||
diff --git a/src/lib/libcrypto/rsa/rsa_err.c b/src/lib/libcrypto/rsa/rsa_err.c new file mode 100644 index 0000000000..796b3afd47 --- /dev/null +++ b/src/lib/libcrypto/rsa/rsa_err.c | |||
| @@ -0,0 +1,129 @@ | |||
| 1 | /* lib/rsa/rsa_err.c */ | ||
| 2 | /* Copyright (C) 1995-1997 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 | #include <stdio.h> | ||
| 59 | #include "err.h" | ||
| 60 | #include "rsa.h" | ||
| 61 | |||
| 62 | /* BEGIN ERROR CODES */ | ||
| 63 | #ifndef NO_ERR | ||
| 64 | static ERR_STRING_DATA RSA_str_functs[]= | ||
| 65 | { | ||
| 66 | {ERR_PACK(0,RSA_F_RSA_EAY_PRIVATE_DECRYPT,0), "RSA_EAY_PRIVATE_DECRYPT"}, | ||
| 67 | {ERR_PACK(0,RSA_F_RSA_EAY_PRIVATE_ENCRYPT,0), "RSA_EAY_PRIVATE_ENCRYPT"}, | ||
| 68 | {ERR_PACK(0,RSA_F_RSA_EAY_PUBLIC_DECRYPT,0), "RSA_EAY_PUBLIC_DECRYPT"}, | ||
| 69 | {ERR_PACK(0,RSA_F_RSA_EAY_PUBLIC_ENCRYPT,0), "RSA_EAY_PUBLIC_ENCRYPT"}, | ||
| 70 | {ERR_PACK(0,RSA_F_RSA_GENERATE_KEY,0), "RSA_generate_key"}, | ||
| 71 | {ERR_PACK(0,RSA_F_RSA_NEW_METHOD,0), "RSA_new_method"}, | ||
| 72 | {ERR_PACK(0,RSA_F_RSA_PADDING_ADD_NONE,0), "RSA_padding_add_none"}, | ||
| 73 | {ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1,0), "RSA_padding_add_PKCS1_type_1"}, | ||
| 74 | {ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2,0), "RSA_padding_add_PKCS1_type_2"}, | ||
| 75 | {ERR_PACK(0,RSA_F_RSA_PADDING_ADD_SSLV23,0), "RSA_padding_add_SSLv23"}, | ||
| 76 | {ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_NONE,0), "RSA_padding_check_none"}, | ||
| 77 | {ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,0), "RSA_padding_check_PKCS1_type_1"}, | ||
| 78 | {ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,0), "RSA_padding_check_PKCS1_type_2"}, | ||
| 79 | {ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_SSLV23,0), "RSA_padding_check_SSLv23"}, | ||
| 80 | {ERR_PACK(0,RSA_F_RSA_PRINT,0), "RSA_print"}, | ||
| 81 | {ERR_PACK(0,RSA_F_RSA_PRINT_FP,0), "RSA_print_fp"}, | ||
| 82 | {ERR_PACK(0,RSA_F_RSA_SIGN,0), "RSA_sign"}, | ||
| 83 | {ERR_PACK(0,RSA_F_RSA_SIGN_ASN1_OCTET_STRING,0), "RSA_sign_ASN1_OCTET_STRING"}, | ||
| 84 | {ERR_PACK(0,RSA_F_RSA_VERIFY,0), "RSA_verify"}, | ||
| 85 | {ERR_PACK(0,RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,0), "RSA_verify_ASN1_OCTET_STRING"}, | ||
| 86 | {0,NULL}, | ||
| 87 | }; | ||
| 88 | |||
| 89 | static ERR_STRING_DATA RSA_str_reasons[]= | ||
| 90 | { | ||
| 91 | {RSA_R_ALGORITHM_MISMATCH ,"algorithm mismatch"}, | ||
| 92 | {RSA_R_BAD_E_VALUE ,"bad e value"}, | ||
| 93 | {RSA_R_BAD_FIXED_HEADER_DECRYPT ,"bad fixed header decrypt"}, | ||
| 94 | {RSA_R_BAD_PAD_BYTE_COUNT ,"bad pad byte count"}, | ||
| 95 | {RSA_R_BAD_SIGNATURE ,"bad signature"}, | ||
| 96 | {RSA_R_BAD_ZERO_BYTE ,"bad zero byte"}, | ||
| 97 | {RSA_R_BLOCK_TYPE_IS_NOT_01 ,"block type is not 01"}, | ||
| 98 | {RSA_R_BLOCK_TYPE_IS_NOT_02 ,"block type is not 02"}, | ||
| 99 | {RSA_R_DATA_GREATER_THAN_MOD_LEN ,"data greater than mod len"}, | ||
| 100 | {RSA_R_DATA_TOO_LARGE ,"data too large"}, | ||
| 101 | {RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE ,"data too large for key size"}, | ||
| 102 | {RSA_R_DATA_TOO_SMALL ,"data too small"}, | ||
| 103 | {RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY ,"digest too big for rsa key"}, | ||
| 104 | {RSA_R_NULL_BEFORE_BLOCK_MISSING ,"null before block missing"}, | ||
| 105 | {RSA_R_PADDING_CHECK_FAILED ,"padding check failed"}, | ||
| 106 | {RSA_R_SSLV3_ROLLBACK_ATTACK ,"sslv3 rollback attack"}, | ||
| 107 | {RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD,"the asn1 object identifier is not known for this md"}, | ||
| 108 | {RSA_R_UNKNOWN_ALGORITHM_TYPE ,"unknown algorithm type"}, | ||
| 109 | {RSA_R_UNKNOWN_PADDING_TYPE ,"unknown padding type"}, | ||
| 110 | {RSA_R_WRONG_SIGNATURE_LENGTH ,"wrong signature length"}, | ||
| 111 | {0,NULL}, | ||
| 112 | }; | ||
| 113 | |||
| 114 | #endif | ||
| 115 | |||
| 116 | void ERR_load_RSA_strings() | ||
| 117 | { | ||
| 118 | static int init=1; | ||
| 119 | |||
| 120 | if (init); | ||
| 121 | {; | ||
| 122 | init=0; | ||
| 123 | #ifndef NO_ERR | ||
| 124 | ERR_load_strings(ERR_LIB_RSA,RSA_str_functs); | ||
| 125 | ERR_load_strings(ERR_LIB_RSA,RSA_str_reasons); | ||
| 126 | #endif | ||
| 127 | |||
| 128 | } | ||
| 129 | } | ||
diff --git a/src/lib/libcrypto/rsa/rsa_gen.c b/src/lib/libcrypto/rsa/rsa_gen.c new file mode 100644 index 0000000000..4cbd373829 --- /dev/null +++ b/src/lib/libcrypto/rsa/rsa_gen.c | |||
| @@ -0,0 +1,101 @@ | |||
| 1 | /* crypto/rsa/rsa_gen.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 <time.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "bn.h" | ||
| 63 | #include "rsa.h" | ||
| 64 | |||
| 65 | RSA *RSA_generate_key(bits, e_value, callback,cb_arg) | ||
| 66 | int bits; | ||
| 67 | unsigned long e_value; | ||
| 68 | void (*callback)(P_I_I_P); | ||
| 69 | char *cb_arg; | ||
| 70 | { | ||
| 71 | RSA *rsa=NULL; | ||
| 72 | BIGNUM *r0=NULL,*r1=NULL,*r2=NULL,*r3=NULL,*tmp; | ||
| 73 | int bitsp,bitsq,ok= -1,n=0; | ||
| 74 | BN_CTX *ctx=NULL,*ctx2=NULL; | ||
| 75 | |||
| 76 | ctx=BN_CTX_new(); | ||
| 77 | if (ctx == NULL) goto err; | ||
| 78 | ctx2=BN_CTX_new(); | ||
| 79 | if (ctx2 == NULL) goto err; | ||
| 80 | |||
| 81 | /* Body of this routine removed for OpenBSD - will return | ||
| 82 | * when the RSA patent expires | ||
| 83 | */ | ||
| 84 | err: | ||
| 85 | if (ok == -1) | ||
| 86 | { | ||
| 87 | RSAerr(RSA_F_RSA_GENERATE_KEY,ERR_LIB_BN); | ||
| 88 | ok=0; | ||
| 89 | } | ||
| 90 | BN_CTX_free(ctx); | ||
| 91 | BN_CTX_free(ctx2); | ||
| 92 | |||
| 93 | if (!ok) | ||
| 94 | { | ||
| 95 | if (rsa != NULL) RSA_free(rsa); | ||
| 96 | return(NULL); | ||
| 97 | } | ||
| 98 | else | ||
| 99 | return(rsa); | ||
| 100 | } | ||
| 101 | |||
diff --git a/src/lib/libcrypto/rsa/rsa_lib.c b/src/lib/libcrypto/rsa/rsa_lib.c new file mode 100644 index 0000000000..95a56f8a28 --- /dev/null +++ b/src/lib/libcrypto/rsa/rsa_lib.c | |||
| @@ -0,0 +1,294 @@ | |||
| 1 | /* crypto/rsa/rsa_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 "crypto.h" | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "lhash.h" | ||
| 63 | #include "bn.h" | ||
| 64 | #include "rsa.h" | ||
| 65 | |||
| 66 | char *RSA_version="RSA part of SSLeay 0.9.0b 29-Jun-1998"; | ||
| 67 | |||
| 68 | static RSA_METHOD *default_RSA_meth=NULL; | ||
| 69 | static int rsa_meth_num=0; | ||
| 70 | static STACK *rsa_meth=NULL; | ||
| 71 | |||
| 72 | RSA *RSA_new() | ||
| 73 | { | ||
| 74 | return(RSA_new_method(NULL)); | ||
| 75 | } | ||
| 76 | |||
| 77 | void RSA_set_default_method(meth) | ||
| 78 | RSA_METHOD *meth; | ||
| 79 | { | ||
| 80 | default_RSA_meth=meth; | ||
| 81 | } | ||
| 82 | |||
| 83 | RSA *RSA_new_method(meth) | ||
| 84 | RSA_METHOD *meth; | ||
| 85 | { | ||
| 86 | RSA *ret; | ||
| 87 | |||
| 88 | if (default_RSA_meth == NULL) | ||
| 89 | { | ||
| 90 | #ifdef RSAref | ||
| 91 | default_RSA_meth=RSA_PKCS1_RSAref(); | ||
| 92 | #else | ||
| 93 | default_RSA_meth=RSA_PKCS1_SSLeay(); | ||
| 94 | #endif | ||
| 95 | } | ||
| 96 | ret=(RSA *)Malloc(sizeof(RSA)); | ||
| 97 | if (ret == NULL) | ||
| 98 | { | ||
| 99 | RSAerr(RSA_F_RSA_NEW_METHOD,ERR_R_MALLOC_FAILURE); | ||
| 100 | return(NULL); | ||
| 101 | } | ||
| 102 | |||
| 103 | if (meth == NULL) | ||
| 104 | ret->meth=default_RSA_meth; | ||
| 105 | else | ||
| 106 | ret->meth=meth; | ||
| 107 | |||
| 108 | ret->pad=0; | ||
| 109 | ret->version=0; | ||
| 110 | ret->n=NULL; | ||
| 111 | ret->e=NULL; | ||
| 112 | ret->d=NULL; | ||
| 113 | ret->p=NULL; | ||
| 114 | ret->q=NULL; | ||
| 115 | ret->dmp1=NULL; | ||
| 116 | ret->dmq1=NULL; | ||
| 117 | ret->iqmp=NULL; | ||
| 118 | ret->references=1; | ||
| 119 | ret->method_mod_n=NULL; | ||
| 120 | ret->method_mod_p=NULL; | ||
| 121 | ret->method_mod_q=NULL; | ||
| 122 | ret->blinding=NULL; | ||
| 123 | ret->flags=ret->meth->flags; | ||
| 124 | if ((ret->meth->init != NULL) && !ret->meth->init(ret)) | ||
| 125 | { | ||
| 126 | Free(ret); | ||
| 127 | ret=NULL; | ||
| 128 | } | ||
| 129 | CRYPTO_new_ex_data(rsa_meth,(char *)ret,&ret->ex_data); | ||
| 130 | return(ret); | ||
| 131 | } | ||
| 132 | |||
| 133 | void RSA_free(r) | ||
| 134 | RSA *r; | ||
| 135 | { | ||
| 136 | int i; | ||
| 137 | |||
| 138 | if (r == NULL) return; | ||
| 139 | |||
| 140 | i=CRYPTO_add(&r->references,-1,CRYPTO_LOCK_RSA); | ||
| 141 | #ifdef REF_PRINT | ||
| 142 | REF_PRINT("RSA",r); | ||
| 143 | #endif | ||
| 144 | if (i > 0) return; | ||
| 145 | #ifdef REF_CHECK | ||
| 146 | if (i < 0) | ||
| 147 | { | ||
| 148 | fprintf(stderr,"RSA_free, bad reference count\n"); | ||
| 149 | abort(); | ||
| 150 | } | ||
| 151 | #endif | ||
| 152 | |||
| 153 | CRYPTO_free_ex_data(rsa_meth,(char *)r,&r->ex_data); | ||
| 154 | |||
| 155 | if (r->meth->finish != NULL) | ||
| 156 | r->meth->finish(r); | ||
| 157 | |||
| 158 | if (r->n != NULL) BN_clear_free(r->n); | ||
| 159 | if (r->e != NULL) BN_clear_free(r->e); | ||
| 160 | if (r->d != NULL) BN_clear_free(r->d); | ||
| 161 | if (r->p != NULL) BN_clear_free(r->p); | ||
| 162 | if (r->q != NULL) BN_clear_free(r->q); | ||
| 163 | if (r->dmp1 != NULL) BN_clear_free(r->dmp1); | ||
| 164 | if (r->dmq1 != NULL) BN_clear_free(r->dmq1); | ||
| 165 | if (r->iqmp != NULL) BN_clear_free(r->iqmp); | ||
| 166 | if (r->blinding != NULL) BN_BLINDING_free(r->blinding); | ||
| 167 | Free(r); | ||
| 168 | } | ||
| 169 | |||
| 170 | int RSA_get_ex_new_index(argl,argp,new_func,dup_func,free_func) | ||
| 171 | long argl; | ||
| 172 | char *argp; | ||
| 173 | int (*new_func)(); | ||
| 174 | int (*dup_func)(); | ||
| 175 | void (*free_func)(); | ||
| 176 | { | ||
| 177 | rsa_meth_num++; | ||
| 178 | return(CRYPTO_get_ex_new_index(rsa_meth_num-1, | ||
| 179 | &rsa_meth,argl,argp,new_func,dup_func,free_func)); | ||
| 180 | } | ||
| 181 | |||
| 182 | int RSA_set_ex_data(r,idx,arg) | ||
| 183 | RSA *r; | ||
| 184 | int idx; | ||
| 185 | char *arg; | ||
| 186 | { | ||
| 187 | return(CRYPTO_set_ex_data(&r->ex_data,idx,arg)); | ||
| 188 | } | ||
| 189 | |||
| 190 | char *RSA_get_ex_data(r,idx) | ||
| 191 | RSA *r; | ||
| 192 | int idx; | ||
| 193 | { | ||
| 194 | return(CRYPTO_get_ex_data(&r->ex_data,idx)); | ||
| 195 | } | ||
| 196 | |||
| 197 | int RSA_size(r) | ||
| 198 | RSA *r; | ||
| 199 | { | ||
| 200 | return(BN_num_bytes(r->n)); | ||
| 201 | } | ||
| 202 | |||
| 203 | int RSA_public_encrypt(flen, from, to, rsa, padding) | ||
| 204 | int flen; | ||
| 205 | unsigned char *from; | ||
| 206 | unsigned char *to; | ||
| 207 | RSA *rsa; | ||
| 208 | int padding; | ||
| 209 | { | ||
| 210 | return(rsa->meth->rsa_pub_enc(flen, from, to, rsa, padding)); | ||
| 211 | } | ||
| 212 | |||
| 213 | int RSA_private_encrypt(flen, from, to, rsa, padding) | ||
| 214 | int flen; | ||
| 215 | unsigned char *from; | ||
| 216 | unsigned char *to; | ||
| 217 | RSA *rsa; | ||
| 218 | int padding; | ||
| 219 | { | ||
| 220 | return(rsa->meth->rsa_priv_enc(flen, from, to, rsa, padding)); | ||
| 221 | } | ||
| 222 | |||
| 223 | int RSA_private_decrypt(flen, from, to, rsa, padding) | ||
| 224 | int flen; | ||
| 225 | unsigned char *from; | ||
| 226 | unsigned char *to; | ||
| 227 | RSA *rsa; | ||
| 228 | int padding; | ||
| 229 | { | ||
| 230 | return(rsa->meth->rsa_priv_dec(flen, from, to, rsa, padding)); | ||
| 231 | } | ||
| 232 | |||
| 233 | int RSA_public_decrypt(flen, from, to, rsa, padding) | ||
| 234 | int flen; | ||
| 235 | unsigned char *from; | ||
| 236 | unsigned char *to; | ||
| 237 | RSA *rsa; | ||
| 238 | int padding; | ||
| 239 | { | ||
| 240 | return(rsa->meth->rsa_pub_dec(flen, from, to, rsa, padding)); | ||
| 241 | } | ||
| 242 | |||
| 243 | int RSA_flags(r) | ||
| 244 | RSA *r; | ||
| 245 | { | ||
| 246 | return((r == NULL)?0:r->meth->flags); | ||
| 247 | } | ||
| 248 | |||
| 249 | void RSA_blinding_off(rsa) | ||
| 250 | RSA *rsa; | ||
| 251 | { | ||
| 252 | if (rsa->blinding != NULL) | ||
| 253 | { | ||
| 254 | BN_BLINDING_free(rsa->blinding); | ||
| 255 | rsa->blinding=NULL; | ||
| 256 | } | ||
| 257 | rsa->flags&= ~RSA_FLAG_BLINDING; | ||
| 258 | } | ||
| 259 | |||
| 260 | int RSA_blinding_on(rsa,p_ctx) | ||
| 261 | RSA *rsa; | ||
| 262 | BN_CTX *p_ctx; | ||
| 263 | { | ||
| 264 | BIGNUM *A,*Ai; | ||
| 265 | BN_CTX *ctx; | ||
| 266 | int ret=0; | ||
| 267 | |||
| 268 | if (p_ctx == NULL) | ||
| 269 | { | ||
| 270 | if ((ctx=BN_CTX_new()) == NULL) goto err; | ||
| 271 | } | ||
| 272 | else | ||
| 273 | ctx=p_ctx; | ||
| 274 | |||
| 275 | if (rsa->blinding != NULL) | ||
| 276 | BN_BLINDING_free(rsa->blinding); | ||
| 277 | |||
| 278 | A=ctx->bn[0]; | ||
| 279 | ctx->tos++; | ||
| 280 | if (!BN_rand(A,BN_num_bits(rsa->n)-1,1,0)) goto err; | ||
| 281 | if ((Ai=BN_mod_inverse(A,rsa->n,ctx)) == NULL) goto err; | ||
| 282 | |||
| 283 | if (!rsa->meth->bn_mod_exp(A,A,rsa->e,rsa->n,ctx, | ||
| 284 | (char *)rsa->method_mod_n)) goto err; | ||
| 285 | rsa->blinding=BN_BLINDING_new(A,Ai,rsa->n); | ||
| 286 | ctx->tos--; | ||
| 287 | rsa->flags|=RSA_FLAG_BLINDING; | ||
| 288 | BN_free(Ai); | ||
| 289 | ret=1; | ||
| 290 | err: | ||
| 291 | if (ctx != p_ctx) BN_CTX_free(ctx); | ||
| 292 | return(ret); | ||
| 293 | } | ||
| 294 | |||
diff --git a/src/lib/libcrypto/rsa/rsa_none.c b/src/lib/libcrypto/rsa/rsa_none.c new file mode 100644 index 0000000000..f0dd943657 --- /dev/null +++ b/src/lib/libcrypto/rsa/rsa_none.c | |||
| @@ -0,0 +1,109 @@ | |||
| 1 | /* crypto/rsa/rsa_none.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 "rand.h" | ||
| 64 | |||
| 65 | int RSA_padding_add_none(to,tlen,from,flen) | ||
| 66 | unsigned char *to; | ||
| 67 | int tlen; | ||
| 68 | unsigned char *from; | ||
| 69 | int flen; | ||
| 70 | { | ||
| 71 | if (flen >= tlen) | ||
| 72 | { | ||
| 73 | RSAerr(RSA_F_RSA_PADDING_ADD_NONE,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); | ||
| 74 | return(0); | ||
| 75 | } | ||
| 76 | |||
| 77 | *(to++)=0; | ||
| 78 | memcpy(to,from,(unsigned int)flen); | ||
| 79 | return(1); | ||
| 80 | } | ||
| 81 | |||
| 82 | int RSA_padding_check_none(to,tlen,from,flen) | ||
| 83 | unsigned char *to; | ||
| 84 | int tlen; | ||
| 85 | unsigned char *from; | ||
| 86 | int flen; | ||
| 87 | { | ||
| 88 | int j; | ||
| 89 | |||
| 90 | from++; | ||
| 91 | if (flen+1 > tlen) | ||
| 92 | { | ||
| 93 | RSAerr(RSA_F_RSA_PADDING_CHECK_NONE,RSA_R_DATA_TOO_LARGE); | ||
| 94 | return(-1); | ||
| 95 | } | ||
| 96 | if (*(from++) != 0) | ||
| 97 | { | ||
| 98 | RSAerr(RSA_F_RSA_PADDING_CHECK_NONE,RSA_R_BAD_ZERO_BYTE); | ||
| 99 | return(-1); | ||
| 100 | } | ||
| 101 | |||
| 102 | /* scan over padding data */ | ||
| 103 | j=flen-1; /* one for type and one for the prepended 0. */ | ||
| 104 | memset(to,0,tlen-j); | ||
| 105 | to+=(tlen-j); | ||
| 106 | memcpy(to,from,j); | ||
| 107 | return(j); | ||
| 108 | } | ||
| 109 | |||
diff --git a/src/lib/libcrypto/rsa/rsa_pk1.c b/src/lib/libcrypto/rsa/rsa_pk1.c new file mode 100644 index 0000000000..2791291b94 --- /dev/null +++ b/src/lib/libcrypto/rsa/rsa_pk1.c | |||
| @@ -0,0 +1,233 @@ | |||
| 1 | /* crypto/rsa/rsa_pk1.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 "rand.h" | ||
| 64 | |||
| 65 | #ifndef NOPROTO | ||
| 66 | int RSA_padding_add_PKCS1_type_1(); | ||
| 67 | int RSA_padding_check_PKCS1_type_1(); | ||
| 68 | int RSA_padding_add_PKCS1_type_2(); | ||
| 69 | int RSA_padding_check_PKCS1_type_2(); | ||
| 70 | int RSA_padding_add_SSLv23(); | ||
| 71 | int RSA_padding_check_SSLv23(); | ||
| 72 | int RSA_padding_add_none(); | ||
| 73 | int RSA_padding_check_none(); | ||
| 74 | |||
| 75 | #endif | ||
| 76 | |||
| 77 | int RSA_padding_add_PKCS1_type_1(to,tlen,from,flen) | ||
| 78 | unsigned char *to; | ||
| 79 | int tlen; | ||
| 80 | unsigned char *from; | ||
| 81 | int flen; | ||
| 82 | { | ||
| 83 | int j; | ||
| 84 | unsigned char *p; | ||
| 85 | |||
| 86 | if (flen > (tlen-11)) | ||
| 87 | { | ||
| 88 | RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); | ||
| 89 | return(0); | ||
| 90 | } | ||
| 91 | |||
| 92 | p=(unsigned char *)to; | ||
| 93 | |||
| 94 | *(p++)=0; | ||
| 95 | *(p++)=1; /* Private Key BT (Block Type) */ | ||
| 96 | |||
| 97 | /* padd out with 0xff data */ | ||
| 98 | j=tlen-3-flen; | ||
| 99 | memset(p,0xff,j); | ||
| 100 | p+=j; | ||
| 101 | *(p++)='\0'; | ||
| 102 | memcpy(p,from,(unsigned int)flen); | ||
| 103 | return(1); | ||
| 104 | } | ||
| 105 | |||
| 106 | int RSA_padding_check_PKCS1_type_1(to,tlen,from,flen) | ||
| 107 | unsigned char *to; | ||
| 108 | int tlen; | ||
| 109 | unsigned char *from; | ||
| 110 | int flen; | ||
| 111 | { | ||
| 112 | int i,j; | ||
| 113 | unsigned char *p; | ||
| 114 | |||
| 115 | p=from; | ||
| 116 | if (*(p++) != 01) | ||
| 117 | { | ||
| 118 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_BLOCK_TYPE_IS_NOT_01); | ||
| 119 | return(-1); | ||
| 120 | } | ||
| 121 | |||
| 122 | /* scan over padding data */ | ||
| 123 | j=flen-1; /* one for type. */ | ||
| 124 | for (i=0; i<j; i++) | ||
| 125 | { | ||
| 126 | if (*p != 0xff) /* should decrypt to 0xff */ | ||
| 127 | { | ||
| 128 | if (*p == 0) | ||
| 129 | { p++; break; } | ||
| 130 | else { | ||
| 131 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_BAD_FIXED_HEADER_DECRYPT); | ||
| 132 | return(-1); | ||
| 133 | } | ||
| 134 | } | ||
| 135 | p++; | ||
| 136 | } | ||
| 137 | |||
| 138 | if (i == j) | ||
| 139 | { | ||
| 140 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_NULL_BEFORE_BLOCK_MISSING); | ||
| 141 | return(-1); | ||
| 142 | } | ||
| 143 | |||
| 144 | if (i < 8) | ||
| 145 | { | ||
| 146 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_BAD_PAD_BYTE_COUNT); | ||
| 147 | return(-1); | ||
| 148 | } | ||
| 149 | i++; /* Skip over the '\0' */ | ||
| 150 | j-=i; | ||
| 151 | memcpy(to,p,(unsigned int)j); | ||
| 152 | |||
| 153 | return(j); | ||
| 154 | } | ||
| 155 | |||
| 156 | int RSA_padding_add_PKCS1_type_2(to,tlen,from,flen) | ||
| 157 | unsigned char *to; | ||
| 158 | int tlen; | ||
| 159 | unsigned char *from; | ||
| 160 | int flen; | ||
| 161 | { | ||
| 162 | int i,j; | ||
| 163 | unsigned char *p; | ||
| 164 | |||
| 165 | if (flen > (tlen-11)) | ||
| 166 | { | ||
| 167 | RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); | ||
| 168 | return(0); | ||
| 169 | } | ||
| 170 | |||
| 171 | p=(unsigned char *)to; | ||
| 172 | |||
| 173 | *(p++)=0; | ||
| 174 | *(p++)=2; /* Public Key BT (Block Type) */ | ||
| 175 | |||
| 176 | /* pad out with non-zero random data */ | ||
| 177 | j=tlen-3-flen; | ||
| 178 | |||
| 179 | RAND_bytes(p,j); | ||
| 180 | for (i=0; i<j; i++) | ||
| 181 | { | ||
| 182 | if (*p == '\0') | ||
| 183 | do { | ||
| 184 | RAND_bytes(p,1); | ||
| 185 | } while (*p == '\0'); | ||
| 186 | p++; | ||
| 187 | } | ||
| 188 | |||
| 189 | *(p++)='\0'; | ||
| 190 | |||
| 191 | memcpy(p,from,(unsigned int)flen); | ||
| 192 | return(1); | ||
| 193 | } | ||
| 194 | |||
| 195 | int RSA_padding_check_PKCS1_type_2(to,tlen,from,flen) | ||
| 196 | unsigned char *to; | ||
| 197 | int tlen; | ||
| 198 | unsigned char *from; | ||
| 199 | int flen; | ||
| 200 | { | ||
| 201 | int i,j; | ||
| 202 | unsigned char *p; | ||
| 203 | |||
| 204 | p=from; | ||
| 205 | if (*(p++) != 02) | ||
| 206 | { | ||
| 207 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_BLOCK_TYPE_IS_NOT_02); | ||
| 208 | return(-1); | ||
| 209 | } | ||
| 210 | |||
| 211 | /* scan over padding data */ | ||
| 212 | j=flen-1; /* one for type. */ | ||
| 213 | for (i=0; i<j; i++) | ||
| 214 | if (*(p++) == 0) break; | ||
| 215 | |||
| 216 | if (i == j) | ||
| 217 | { | ||
| 218 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_NULL_BEFORE_BLOCK_MISSING); | ||
| 219 | return(-1); | ||
| 220 | } | ||
| 221 | |||
| 222 | if (i < 8) | ||
| 223 | { | ||
| 224 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_BAD_PAD_BYTE_COUNT); | ||
| 225 | return(-1); | ||
| 226 | } | ||
| 227 | i++; /* Skip over the '\0' */ | ||
| 228 | j-=i; | ||
| 229 | memcpy(to,p,(unsigned int)j); | ||
| 230 | |||
| 231 | return(j); | ||
| 232 | } | ||
| 233 | |||
diff --git a/src/lib/libcrypto/rsa/rsa_saos.c b/src/lib/libcrypto/rsa/rsa_saos.c new file mode 100644 index 0000000000..fb0fae5a43 --- /dev/null +++ b/src/lib/libcrypto/rsa/rsa_saos.c | |||
| @@ -0,0 +1,153 @@ | |||
| 1 | /* crypto/rsa/rsa_saos.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 "x509.h" | ||
| 65 | |||
| 66 | int RSA_sign_ASN1_OCTET_STRING(type,m,m_len,sigret,siglen,rsa) | ||
| 67 | int type; | ||
| 68 | unsigned char *m; | ||
| 69 | unsigned int m_len; | ||
| 70 | unsigned char *sigret; | ||
| 71 | unsigned int *siglen; | ||
| 72 | RSA *rsa; | ||
| 73 | { | ||
| 74 | ASN1_OCTET_STRING sig; | ||
| 75 | int i,j,ret=1; | ||
| 76 | unsigned char *p,*s; | ||
| 77 | |||
| 78 | sig.type=V_ASN1_OCTET_STRING; | ||
| 79 | sig.length=m_len; | ||
| 80 | sig.data=m; | ||
| 81 | |||
| 82 | i=i2d_ASN1_OCTET_STRING(&sig,NULL); | ||
| 83 | j=RSA_size(rsa); | ||
| 84 | if ((i-RSA_PKCS1_PADDING) > j) | ||
| 85 | { | ||
| 86 | RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY); | ||
| 87 | return(0); | ||
| 88 | } | ||
| 89 | s=(unsigned char *)Malloc((unsigned int)j+1); | ||
| 90 | if (s == NULL) | ||
| 91 | { | ||
| 92 | RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE); | ||
| 93 | return(0); | ||
| 94 | } | ||
| 95 | p=s; | ||
| 96 | i2d_ASN1_OCTET_STRING(&sig,&p); | ||
| 97 | i=RSA_private_encrypt(i,s,sigret,rsa,RSA_PKCS1_PADDING); | ||
| 98 | if (i <= 0) | ||
| 99 | ret=0; | ||
| 100 | else | ||
| 101 | *siglen=i; | ||
| 102 | |||
| 103 | memset(s,0,(unsigned int)j+1); | ||
| 104 | Free(s); | ||
| 105 | return(ret); | ||
| 106 | } | ||
| 107 | |||
| 108 | int RSA_verify_ASN1_OCTET_STRING(dtype, m, m_len, sigbuf, siglen, rsa) | ||
| 109 | int dtype; | ||
| 110 | unsigned char *m; | ||
| 111 | unsigned int m_len; | ||
| 112 | unsigned char *sigbuf; | ||
| 113 | unsigned int siglen; | ||
| 114 | RSA *rsa; | ||
| 115 | { | ||
| 116 | int i,ret=0; | ||
| 117 | unsigned char *p,*s; | ||
| 118 | ASN1_OCTET_STRING *sig=NULL; | ||
| 119 | |||
| 120 | if (siglen != (unsigned int)RSA_size(rsa)) | ||
| 121 | { | ||
| 122 | RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,RSA_R_WRONG_SIGNATURE_LENGTH); | ||
| 123 | return(0); | ||
| 124 | } | ||
| 125 | |||
| 126 | s=(unsigned char *)Malloc((unsigned int)siglen); | ||
| 127 | if (s == NULL) | ||
| 128 | { | ||
| 129 | RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE); | ||
| 130 | goto err; | ||
| 131 | } | ||
| 132 | i=RSA_public_decrypt((int)siglen,sigbuf,s,rsa,RSA_PKCS1_PADDING); | ||
| 133 | |||
| 134 | if (i <= 0) goto err; | ||
| 135 | |||
| 136 | p=s; | ||
| 137 | sig=d2i_ASN1_OCTET_STRING(NULL,&p,(long)i); | ||
| 138 | if (sig == NULL) goto err; | ||
| 139 | |||
| 140 | if ( ((unsigned int)sig->length != m_len) || | ||
| 141 | (memcmp(m,sig->data,m_len) != 0)) | ||
| 142 | { | ||
| 143 | RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,RSA_R_BAD_SIGNATURE); | ||
| 144 | } | ||
| 145 | else | ||
| 146 | ret=1; | ||
| 147 | err: | ||
| 148 | if (sig != NULL) ASN1_OCTET_STRING_free(sig); | ||
| 149 | memset(s,0,(unsigned int)siglen); | ||
| 150 | Free(s); | ||
| 151 | return(ret); | ||
| 152 | } | ||
| 153 | |||
diff --git a/src/lib/libcrypto/rsa/rsa_sign.c b/src/lib/libcrypto/rsa/rsa_sign.c new file mode 100644 index 0000000000..28c5571e74 --- /dev/null +++ b/src/lib/libcrypto/rsa/rsa_sign.c | |||
| @@ -0,0 +1,196 @@ | |||
| 1 | /* crypto/rsa/rsa_sign.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 "x509.h" | ||
| 65 | |||
| 66 | int RSA_sign(type,m,m_len,sigret,siglen,rsa) | ||
| 67 | int type; | ||
| 68 | unsigned char *m; | ||
| 69 | unsigned int m_len; | ||
| 70 | unsigned char *sigret; | ||
| 71 | unsigned int *siglen; | ||
| 72 | RSA *rsa; | ||
| 73 | { | ||
| 74 | X509_SIG sig; | ||
| 75 | ASN1_TYPE parameter; | ||
| 76 | int i,j,ret=1; | ||
| 77 | unsigned char *p,*s; | ||
| 78 | X509_ALGOR algor; | ||
| 79 | ASN1_OCTET_STRING digest; | ||
| 80 | |||
| 81 | sig.algor= &algor; | ||
| 82 | sig.algor->algorithm=OBJ_nid2obj(type); | ||
| 83 | if (sig.algor->algorithm == NULL) | ||
| 84 | { | ||
| 85 | RSAerr(RSA_F_RSA_SIGN,RSA_R_UNKNOWN_ALGORITHM_TYPE); | ||
| 86 | return(0); | ||
| 87 | } | ||
| 88 | if (sig.algor->algorithm->length == 0) | ||
| 89 | { | ||
| 90 | RSAerr(RSA_F_RSA_SIGN,RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD); | ||
| 91 | return(0); | ||
| 92 | } | ||
| 93 | parameter.type=V_ASN1_NULL; | ||
| 94 | parameter.value.ptr=NULL; | ||
| 95 | sig.algor->parameter= ¶meter; | ||
| 96 | |||
| 97 | sig.digest= &digest; | ||
| 98 | sig.digest->data=m; | ||
| 99 | sig.digest->length=m_len; | ||
| 100 | |||
| 101 | i=i2d_X509_SIG(&sig,NULL); | ||
| 102 | j=RSA_size(rsa); | ||
| 103 | if ((i-RSA_PKCS1_PADDING) > j) | ||
| 104 | { | ||
| 105 | RSAerr(RSA_F_RSA_SIGN,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY); | ||
| 106 | return(0); | ||
| 107 | } | ||
| 108 | s=(unsigned char *)Malloc((unsigned int)j+1); | ||
| 109 | if (s == NULL) | ||
| 110 | { | ||
| 111 | RSAerr(RSA_F_RSA_SIGN,ERR_R_MALLOC_FAILURE); | ||
| 112 | return(0); | ||
| 113 | } | ||
| 114 | p=s; | ||
| 115 | i2d_X509_SIG(&sig,&p); | ||
| 116 | i=RSA_private_encrypt(i,s,sigret,rsa,RSA_PKCS1_PADDING); | ||
| 117 | if (i <= 0) | ||
| 118 | ret=0; | ||
| 119 | else | ||
| 120 | *siglen=i; | ||
| 121 | |||
| 122 | memset(s,0,(unsigned int)j+1); | ||
| 123 | Free(s); | ||
| 124 | return(ret); | ||
| 125 | } | ||
| 126 | |||
| 127 | int RSA_verify(dtype, m, m_len, sigbuf, siglen, rsa) | ||
| 128 | int dtype; | ||
| 129 | unsigned char *m; | ||
| 130 | unsigned int m_len; | ||
| 131 | unsigned char *sigbuf; | ||
| 132 | unsigned int siglen; | ||
| 133 | RSA *rsa; | ||
| 134 | { | ||
| 135 | int i,ret=0,sigtype; | ||
| 136 | unsigned char *p,*s; | ||
| 137 | X509_SIG *sig=NULL; | ||
| 138 | |||
| 139 | if (siglen != (unsigned int)RSA_size(rsa)) | ||
| 140 | { | ||
| 141 | RSAerr(RSA_F_RSA_VERIFY,RSA_R_WRONG_SIGNATURE_LENGTH); | ||
| 142 | return(0); | ||
| 143 | } | ||
| 144 | |||
| 145 | s=(unsigned char *)Malloc((unsigned int)siglen); | ||
| 146 | if (s == NULL) | ||
| 147 | { | ||
| 148 | RSAerr(RSA_F_RSA_VERIFY,ERR_R_MALLOC_FAILURE); | ||
| 149 | goto err; | ||
| 150 | } | ||
| 151 | i=RSA_public_decrypt((int)siglen,sigbuf,s,rsa,RSA_PKCS1_PADDING); | ||
| 152 | |||
| 153 | if (i <= 0) goto err; | ||
| 154 | |||
| 155 | p=s; | ||
| 156 | sig=d2i_X509_SIG(NULL,&p,(long)i); | ||
| 157 | if (sig == NULL) goto err; | ||
| 158 | sigtype=OBJ_obj2nid(sig->algor->algorithm); | ||
| 159 | |||
| 160 | #ifdef RSA_DEBUG | ||
| 161 | /* put a backward compatability flag in EAY */ | ||
| 162 | fprintf(stderr,"in(%s) expect(%s)\n",OBJ_nid2ln(sigtype), | ||
| 163 | OBJ_nid2ln(dtype)); | ||
| 164 | #endif | ||
| 165 | if (sigtype != dtype) | ||
| 166 | { | ||
| 167 | if (((dtype == NID_md5) && | ||
| 168 | (sigtype == NID_md5WithRSAEncryption)) || | ||
| 169 | ((dtype == NID_md2) && | ||
| 170 | (sigtype == NID_md2WithRSAEncryption))) | ||
| 171 | { | ||
| 172 | /* ok, we will let it through */ | ||
| 173 | #if !defined(NO_STDIO) && !defined(WIN16) | ||
| 174 | fprintf(stderr,"signature has problems, re-make with post SSLeay045\n"); | ||
| 175 | #endif | ||
| 176 | } | ||
| 177 | else | ||
| 178 | { | ||
| 179 | RSAerr(RSA_F_RSA_VERIFY,RSA_R_ALGORITHM_MISMATCH); | ||
| 180 | goto err; | ||
| 181 | } | ||
| 182 | } | ||
| 183 | if ( ((unsigned int)sig->digest->length != m_len) || | ||
| 184 | (memcmp(m,sig->digest->data,m_len) != 0)) | ||
| 185 | { | ||
| 186 | RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE); | ||
| 187 | } | ||
| 188 | else | ||
| 189 | ret=1; | ||
| 190 | err: | ||
| 191 | if (sig != NULL) X509_SIG_free(sig); | ||
| 192 | memset(s,0,(unsigned int)siglen); | ||
| 193 | Free(s); | ||
| 194 | return(ret); | ||
| 195 | } | ||
| 196 | |||
diff --git a/src/lib/libcrypto/rsa/rsa_ssl.c b/src/lib/libcrypto/rsa/rsa_ssl.c new file mode 100644 index 0000000000..9bcd4b2c03 --- /dev/null +++ b/src/lib/libcrypto/rsa/rsa_ssl.c | |||
| @@ -0,0 +1,153 @@ | |||
| 1 | /* crypto/rsa/rsa_ssl.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 "rand.h" | ||
| 64 | |||
| 65 | int RSA_padding_add_SSLv23(to,tlen,from,flen) | ||
| 66 | unsigned char *to; | ||
| 67 | int tlen; | ||
| 68 | unsigned char *from; | ||
| 69 | int flen; | ||
| 70 | { | ||
| 71 | int i,j; | ||
| 72 | unsigned char *p; | ||
| 73 | |||
| 74 | if (flen > (tlen-11)) | ||
| 75 | { | ||
| 76 | RSAerr(RSA_F_RSA_PADDING_ADD_SSLV23,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); | ||
| 77 | return(0); | ||
| 78 | } | ||
| 79 | |||
| 80 | p=(unsigned char *)to; | ||
| 81 | |||
| 82 | *(p++)=0; | ||
| 83 | *(p++)=2; /* Public Key BT (Block Type) */ | ||
| 84 | |||
| 85 | /* pad out with non-zero random data */ | ||
| 86 | j=tlen-3-8-flen; | ||
| 87 | |||
| 88 | RAND_bytes(p,j); | ||
| 89 | for (i=0; i<j; i++) | ||
| 90 | { | ||
| 91 | if (*p == '\0') | ||
| 92 | do { | ||
| 93 | RAND_bytes(p,1); | ||
| 94 | } while (*p == '\0'); | ||
| 95 | p++; | ||
| 96 | } | ||
| 97 | |||
| 98 | memset(p,3,8); | ||
| 99 | p+=8; | ||
| 100 | *(p++)='\0'; | ||
| 101 | |||
| 102 | memcpy(p,from,(unsigned int)flen); | ||
| 103 | return(1); | ||
| 104 | } | ||
| 105 | |||
| 106 | int RSA_padding_check_SSLv23(to,tlen,from,flen) | ||
| 107 | unsigned char *to; | ||
| 108 | int tlen; | ||
| 109 | unsigned char *from; | ||
| 110 | int flen; | ||
| 111 | { | ||
| 112 | int i,j,k; | ||
| 113 | unsigned char *p; | ||
| 114 | |||
| 115 | p=from; | ||
| 116 | if (flen < 10) | ||
| 117 | { | ||
| 118 | RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_DATA_TOO_SMALL); | ||
| 119 | return(-1); | ||
| 120 | } | ||
| 121 | if (*(p++) != 02) | ||
| 122 | { | ||
| 123 | RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_BLOCK_TYPE_IS_NOT_02); | ||
| 124 | return(-1); | ||
| 125 | } | ||
| 126 | |||
| 127 | /* scan over padding data */ | ||
| 128 | j=flen-1; /* one for type */ | ||
| 129 | for (i=0; i<j; i++) | ||
| 130 | if (*(p++) == 0) break; | ||
| 131 | |||
| 132 | if ((i == j) || (i < 8)) | ||
| 133 | { | ||
| 134 | RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_NULL_BEFORE_BLOCK_MISSING); | ||
| 135 | return(-1); | ||
| 136 | } | ||
| 137 | for (k= -8; k<0; k++) | ||
| 138 | { | ||
| 139 | if (p[k] != 0x03) break; | ||
| 140 | } | ||
| 141 | if (k == 0) | ||
| 142 | { | ||
| 143 | RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_SSLV3_ROLLBACK_ATTACK); | ||
| 144 | return(-1); | ||
| 145 | } | ||
| 146 | |||
| 147 | i++; /* Skip over the '\0' */ | ||
| 148 | j-=i; | ||
| 149 | memcpy(to,p,(unsigned int)j); | ||
| 150 | |||
| 151 | return(j); | ||
| 152 | } | ||
| 153 | |||
diff --git a/src/lib/libcrypto/sha/asm/sha1-586.pl b/src/lib/libcrypto/sha/asm/sha1-586.pl new file mode 100644 index 0000000000..d6d998f8ee --- /dev/null +++ b/src/lib/libcrypto/sha/asm/sha1-586.pl | |||
| @@ -0,0 +1,491 @@ | |||
| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | $normal=0; | ||
| 4 | |||
| 5 | push(@INC,"perlasm","../../perlasm"); | ||
| 6 | require "x86asm.pl"; | ||
| 7 | |||
| 8 | &asm_init($ARGV[0],"sha1-586.pl"); | ||
| 9 | |||
| 10 | $A="eax"; | ||
| 11 | $B="ebx"; | ||
| 12 | $C="ecx"; | ||
| 13 | $D="edx"; | ||
| 14 | $E="edi"; | ||
| 15 | $T="esi"; | ||
| 16 | $tmp1="ebp"; | ||
| 17 | |||
| 18 | $off=9*4; | ||
| 19 | |||
| 20 | @K=(0x5a827999,0x6ed9eba1,0x8f1bbcdc,0xca62c1d6); | ||
| 21 | |||
| 22 | &sha1_block("sha1_block_x86"); | ||
| 23 | |||
| 24 | &asm_finish(); | ||
| 25 | |||
| 26 | sub Nn | ||
| 27 | { | ||
| 28 | local($p)=@_; | ||
| 29 | local(%n)=($A,$T,$B,$A,$C,$B,$D,$C,$E,$D,$T,$E); | ||
| 30 | return($n{$p}); | ||
| 31 | } | ||
| 32 | |||
| 33 | sub Np | ||
| 34 | { | ||
| 35 | local($p)=@_; | ||
| 36 | local(%n)=($A,$T,$B,$A,$C,$B,$D,$C,$E,$D,$T,$E); | ||
| 37 | local(%n)=($A,$B,$B,$C,$C,$D,$D,$E,$E,$T,$T,$A); | ||
| 38 | return($n{$p}); | ||
| 39 | } | ||
| 40 | |||
| 41 | sub Na | ||
| 42 | { | ||
| 43 | local($n)=@_; | ||
| 44 | return( (($n )&0x0f), | ||
| 45 | (($n+ 2)&0x0f), | ||
| 46 | (($n+ 8)&0x0f), | ||
| 47 | (($n+13)&0x0f), | ||
| 48 | (($n+ 1)&0x0f)); | ||
| 49 | } | ||
| 50 | |||
| 51 | sub X_expand | ||
| 52 | { | ||
| 53 | local($in)=@_; | ||
| 54 | |||
| 55 | &comment("First, load the words onto the stack in network byte order"); | ||
| 56 | for ($i=0; $i<16; $i++) | ||
| 57 | { | ||
| 58 | &mov("eax",&DWP(($i+0)*4,$in,"",0)) unless $i == 0; | ||
| 59 | &bswap("eax"); | ||
| 60 | &mov(&swtmp($i+0),"eax"); | ||
| 61 | } | ||
| 62 | |||
| 63 | &comment("We now have the X array on the stack"); | ||
| 64 | &comment("starting at sp-4"); | ||
| 65 | } | ||
| 66 | |||
| 67 | # Rules of engagement | ||
| 68 | # F is always trashable at the start, the running total. | ||
| 69 | # E becomes the next F so it can be trashed after it has been 'accumulated' | ||
| 70 | # F becomes A in the next round. We don't need to access it much. | ||
| 71 | # During the X update part, the result ends up in $X[$n0]. | ||
| 72 | |||
| 73 | sub BODY_00_15 | ||
| 74 | { | ||
| 75 | local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_; | ||
| 76 | |||
| 77 | return if $n & 1; | ||
| 78 | &comment("00_15 $n"); | ||
| 79 | |||
| 80 | &mov($f,$c); | ||
| 81 | |||
| 82 | &mov($tmp1,$a); | ||
| 83 | &xor($f,$d); # F2 | ||
| 84 | |||
| 85 | &rotl($tmp1,5); # A2 | ||
| 86 | |||
| 87 | &and($f,$b); # F3 | ||
| 88 | &add($tmp1,$e); | ||
| 89 | |||
| 90 | &rotr($b,1); # B1 <- F | ||
| 91 | &mov($e,&swtmp($n)); # G1 | ||
| 92 | |||
| 93 | &rotr($b,1); # B1 <- F | ||
| 94 | &xor($f,$d); # F4 | ||
| 95 | |||
| 96 | &lea($tmp1,&DWP($K,$tmp1,$e,1)); | ||
| 97 | |||
| 98 | ############################ | ||
| 99 | # &BODY_40_59( 0,$K[2],$X,42,$A,$B,$C,$D,$E,$T); | ||
| 100 | # &BODY_40_59( 0,$K[2],$X,43,$T,$A,$B,$C,$D,$E); | ||
| 101 | $n++; | ||
| 102 | local($n0,$n1,$n2,$n3,$np)=&Na($n); | ||
| 103 | ($b,$c,$d,$e,$f,$a)=($a,$b,$c,$d,$e,$f); | ||
| 104 | |||
| 105 | &mov($f,$c); | ||
| 106 | |||
| 107 | &add($a,$tmp1); # MOVED DOWN | ||
| 108 | &xor($f,$d); # F2 | ||
| 109 | |||
| 110 | &mov($tmp1,$a); | ||
| 111 | &and($f,$b); # F3 | ||
| 112 | |||
| 113 | &rotl($tmp1,5); # A2 | ||
| 114 | |||
| 115 | &add($tmp1,$e); | ||
| 116 | &mov($e,&swtmp($n)); # G1 | ||
| 117 | |||
| 118 | &rotr($b,1); # B1 <- F | ||
| 119 | &xor($f,$d); # F4 | ||
| 120 | |||
| 121 | &rotr($b,1); # B1 <- F | ||
| 122 | &lea($tmp1,&DWP($K,$tmp1,$e,1)); | ||
| 123 | |||
| 124 | &add($f,$tmp1); | ||
| 125 | } | ||
| 126 | |||
| 127 | sub BODY_16_19 | ||
| 128 | { | ||
| 129 | local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_; | ||
| 130 | local($n0,$n1,$n2,$n3,$np)=&Na($n); | ||
| 131 | |||
| 132 | return if $n & 1; | ||
| 133 | &comment("16_19 $n"); | ||
| 134 | |||
| 135 | &nop() if ($pos < 0); | ||
| 136 | &mov($tmp1,&swtmp($n0)); # X1 | ||
| 137 | &mov($f,&swtmp($n1)); # X2 | ||
| 138 | &xor($f,$tmp1); # X3 | ||
| 139 | &mov($tmp1,&swtmp($n2)); # X4 | ||
| 140 | &xor($f,$tmp1); # X5 | ||
| 141 | &mov($tmp1,&swtmp($n3)); # X6 | ||
| 142 | &xor($f,$tmp1); # X7 - slot | ||
| 143 | &mov($tmp1,$c); # F1 | ||
| 144 | &rotl($f,1); # X8 - slot | ||
| 145 | &xor($tmp1,$d); # F2 | ||
| 146 | &mov(&swtmp($n0),$f); # X9 - anytime | ||
| 147 | &and($tmp1,$b); # F3 | ||
| 148 | &lea($f,&DWP($K,$f,$e,1)); # tot=X+K+e | ||
| 149 | &xor($tmp1,$d); # F4 | ||
| 150 | &mov($e,$a); # A1 | ||
| 151 | &add($f,$tmp1); # tot+=F(); | ||
| 152 | |||
| 153 | &rotl($e,5); # A2 | ||
| 154 | |||
| 155 | &rotr($b,1); # B1 <- F | ||
| 156 | &add($f,$e); # tot+=a | ||
| 157 | |||
| 158 | ############################ | ||
| 159 | # &BODY_40_59( 0,$K[2],$X,42,$A,$B,$C,$D,$E,$T); | ||
| 160 | # &BODY_40_59( 0,$K[2],$X,43,$T,$A,$B,$C,$D,$E); | ||
| 161 | $n++; | ||
| 162 | local($n0,$n1,$n2,$n3,$np)=&Na($n); | ||
| 163 | ($b,$c,$d,$e,$f,$a)=($a,$b,$c,$d,$e,$f); | ||
| 164 | |||
| 165 | |||
| 166 | &mov($f,&swtmp($n0)); # X1 | ||
| 167 | &mov($tmp1,&swtmp($n1)); # X2 | ||
| 168 | &xor($f,$tmp1); # X3 | ||
| 169 | &mov($tmp1,&swtmp($n2)); # X4 | ||
| 170 | &xor($f,$tmp1); # X5 | ||
| 171 | &mov($tmp1,&swtmp($n3)); # X6 | ||
| 172 | &rotr($c,1); #&rotr($b,1); # B1 <- F # MOVED DOWN | ||
| 173 | &xor($f,$tmp1); # X7 - slot | ||
| 174 | &rotl($f,1); # X8 - slot | ||
| 175 | &mov($tmp1,$c); # F1 | ||
| 176 | &xor($tmp1,$d); # F2 | ||
| 177 | &mov(&swtmp($n0),$f); # X9 - anytime | ||
| 178 | &and($tmp1,$b); # F3 | ||
| 179 | &lea($f,&DWP($K,$f,$e,1)); # tot=X+K+e | ||
| 180 | |||
| 181 | &xor($tmp1,$d); # F4 | ||
| 182 | &mov($e,$a); # A1 | ||
| 183 | |||
| 184 | &rotl($e,5); # A2 | ||
| 185 | |||
| 186 | &rotr($b,1); # B1 <- F | ||
| 187 | &add($f,$e); # tot+=a | ||
| 188 | |||
| 189 | &rotr($b,1); # B1 <- F | ||
| 190 | &add($f,$tmp1); # tot+=F(); | ||
| 191 | |||
| 192 | } | ||
| 193 | |||
| 194 | sub BODY_20_39 | ||
| 195 | { | ||
| 196 | local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_; | ||
| 197 | |||
| 198 | &comment("20_39 $n"); | ||
| 199 | local($n0,$n1,$n2,$n3,$np)=&Na($n); | ||
| 200 | |||
| 201 | &mov($f,&swtmp($n0)); # X1 | ||
| 202 | &mov($tmp1,&swtmp($n1)); # X2 | ||
| 203 | &xor($f,$tmp1); # X3 | ||
| 204 | &mov($tmp1,&swtmp($n2)); # X4 | ||
| 205 | &xor($f,$tmp1); # X5 | ||
| 206 | &mov($tmp1,&swtmp($n3)); # X6 | ||
| 207 | &xor($f,$tmp1); # X7 - slot | ||
| 208 | &mov($tmp1,$b); # F1 | ||
| 209 | &rotl($f,1); # X8 - slot | ||
| 210 | &xor($tmp1,$c); # F2 | ||
| 211 | &mov(&swtmp($n0),$f); # X9 - anytime | ||
| 212 | &xor($tmp1,$d); # F3 | ||
| 213 | |||
| 214 | &lea($f,&DWP($K,$f,$e,1)); # tot=X+K+e | ||
| 215 | &mov($e,$a); # A1 | ||
| 216 | |||
| 217 | &rotl($e,5); # A2 | ||
| 218 | |||
| 219 | if ($n != 79) # last loop | ||
| 220 | { | ||
| 221 | &rotr($b,1); # B1 <- F | ||
| 222 | &add($e,$tmp1); # tmp1=F()+a | ||
| 223 | |||
| 224 | &rotr($b,1); # B2 <- F | ||
| 225 | &add($f,$e); # tot+=tmp1; | ||
| 226 | } | ||
| 227 | else | ||
| 228 | { | ||
| 229 | &add($e,$tmp1); # tmp1=F()+a | ||
| 230 | &mov($tmp1,&wparam(0)); | ||
| 231 | |||
| 232 | &rotr($b,1); # B1 <- F | ||
| 233 | &add($f,$e); # tot+=tmp1; | ||
| 234 | |||
| 235 | &rotr($b,1); # B2 <- F | ||
| 236 | } | ||
| 237 | } | ||
| 238 | |||
| 239 | sub BODY_40_59 | ||
| 240 | { | ||
| 241 | local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_; | ||
| 242 | |||
| 243 | &comment("40_59 $n"); | ||
| 244 | return if $n & 1; | ||
| 245 | local($n0,$n1,$n2,$n3,$np)=&Na($n); | ||
| 246 | |||
| 247 | &mov($f,&swtmp($n0)); # X1 | ||
| 248 | &mov($tmp1,&swtmp($n1)); # X2 | ||
| 249 | &xor($f,$tmp1); # X3 | ||
| 250 | &mov($tmp1,&swtmp($n2)); # X4 | ||
| 251 | &xor($f,$tmp1); # X5 | ||
| 252 | &mov($tmp1,&swtmp($n3)); # X6 | ||
| 253 | &xor($f,$tmp1); # X7 - slot | ||
| 254 | &mov($tmp1,$b); # F1 | ||
| 255 | &rotl($f,1); # X8 - slot | ||
| 256 | &or($tmp1,$c); # F2 | ||
| 257 | &mov(&swtmp($n0),$f); # X9 - anytime | ||
| 258 | &and($tmp1,$d); # F3 | ||
| 259 | |||
| 260 | &lea($f,&DWP($K,$f,$e,1)); # tot=X+K+e | ||
| 261 | &mov($e,$b); # F4 | ||
| 262 | |||
| 263 | &rotr($b,1); # B1 <- F | ||
| 264 | &and($e,$c); # F5 | ||
| 265 | |||
| 266 | &or($tmp1,$e); # F6 | ||
| 267 | &mov($e,$a); # A1 | ||
| 268 | |||
| 269 | &rotl($e,5); # A2 | ||
| 270 | |||
| 271 | &add($tmp1,$e); # tmp1=F()+a | ||
| 272 | |||
| 273 | ############################ | ||
| 274 | # &BODY_40_59( 0,$K[2],$X,42,$A,$B,$C,$D,$E,$T); | ||
| 275 | # &BODY_40_59( 0,$K[2],$X,43,$T,$A,$B,$C,$D,$E); | ||
| 276 | $n++; | ||
| 277 | local($n0,$n1,$n2,$n3,$np)=&Na($n); | ||
| 278 | ($b,$c,$d,$e,$f,$a)=($a,$b,$c,$d,$e,$f); | ||
| 279 | |||
| 280 | &mov($f,&swtmp($n0)); # X1 | ||
| 281 | &add($a,$tmp1); # tot+=tmp1; # moved was add f,tmp1 | ||
| 282 | &mov($tmp1,&swtmp($n1)); # X2 | ||
| 283 | &xor($f,$tmp1); # X3 | ||
| 284 | &mov($tmp1,&swtmp($n2)); # X4 | ||
| 285 | &xor($f,$tmp1); # X5 | ||
| 286 | &mov($tmp1,&swtmp($n3)); # X6 | ||
| 287 | &rotr($c,1); # B2 <- F # moved was rotr b,1 | ||
| 288 | &xor($f,$tmp1); # X7 - slot | ||
| 289 | &rotl($f,1); # X8 - slot | ||
| 290 | &mov($tmp1,$b); # F1 | ||
| 291 | &mov(&swtmp($n0),$f); # X9 - anytime | ||
| 292 | &or($tmp1,$c); # F2 | ||
| 293 | &lea($f,&DWP($K,$f,$e,1)); # tot=X+K+e | ||
| 294 | &mov($e,$b); # F4 | ||
| 295 | &and($tmp1,$d); # F3 | ||
| 296 | &and($e,$c); # F5 | ||
| 297 | |||
| 298 | &or($tmp1,$e); # F6 | ||
| 299 | &mov($e,$a); # A1 | ||
| 300 | |||
| 301 | &rotl($e,5); # A2 | ||
| 302 | |||
| 303 | &rotr($b,1); # B1 <- F | ||
| 304 | &add($tmp1,$e); # tmp1=F()+a | ||
| 305 | |||
| 306 | &rotr($b,1); # B2 <- F | ||
| 307 | &add($f,$tmp1); # tot+=tmp1; | ||
| 308 | } | ||
| 309 | |||
| 310 | sub BODY_60_79 | ||
| 311 | { | ||
| 312 | &BODY_20_39(@_); | ||
| 313 | } | ||
| 314 | |||
| 315 | sub sha1_block | ||
| 316 | { | ||
| 317 | local($name)=@_; | ||
| 318 | |||
| 319 | &function_begin_B($name,""); | ||
| 320 | |||
| 321 | # parameter 1 is the MD5_CTX structure. | ||
| 322 | # A 0 | ||
| 323 | # B 4 | ||
| 324 | # C 8 | ||
| 325 | # D 12 | ||
| 326 | # E 16 | ||
| 327 | |||
| 328 | &push("esi"); | ||
| 329 | &push("ebp"); | ||
| 330 | &mov("eax", &wparam(2)); | ||
| 331 | &mov("esi", &wparam(1)); | ||
| 332 | &add("eax", "esi"); # offset to leave on | ||
| 333 | &mov("ebp", &wparam(0)); | ||
| 334 | &push("ebx"); | ||
| 335 | &sub("eax", 64); | ||
| 336 | &push("edi"); | ||
| 337 | &mov($B, &DWP( 4,"ebp","",0)); | ||
| 338 | &stack_push(18); | ||
| 339 | &mov($D, &DWP(12,"ebp","",0)); | ||
| 340 | &mov($E, &DWP(16,"ebp","",0)); | ||
| 341 | &mov($C, &DWP( 8,"ebp","",0)); | ||
| 342 | &mov(&swtmp(17),"eax"); | ||
| 343 | |||
| 344 | &comment("First we need to setup the X array"); | ||
| 345 | &mov("eax",&DWP(0,"esi","",0)); # pulled out of X_expand | ||
| 346 | |||
| 347 | &set_label("start") unless $normal; | ||
| 348 | |||
| 349 | &X_expand("esi"); | ||
| 350 | &mov(&swtmp(16),"esi"); | ||
| 351 | |||
| 352 | &comment(""); | ||
| 353 | &comment("Start processing"); | ||
| 354 | |||
| 355 | # odd start | ||
| 356 | &mov($A, &DWP( 0,"ebp","",0)); | ||
| 357 | $X="esp"; | ||
| 358 | &BODY_00_15(-2,$K[0],$X, 0,$A,$B,$C,$D,$E,$T); | ||
| 359 | &BODY_00_15( 0,$K[0],$X, 1,$T,$A,$B,$C,$D,$E); | ||
| 360 | &BODY_00_15( 0,$K[0],$X, 2,$E,$T,$A,$B,$C,$D); | ||
| 361 | &BODY_00_15( 0,$K[0],$X, 3,$D,$E,$T,$A,$B,$C); | ||
| 362 | &BODY_00_15( 0,$K[0],$X, 4,$C,$D,$E,$T,$A,$B); | ||
| 363 | &BODY_00_15( 0,$K[0],$X, 5,$B,$C,$D,$E,$T,$A); | ||
| 364 | &BODY_00_15( 0,$K[0],$X, 6,$A,$B,$C,$D,$E,$T); | ||
| 365 | &BODY_00_15( 0,$K[0],$X, 7,$T,$A,$B,$C,$D,$E); | ||
| 366 | &BODY_00_15( 0,$K[0],$X, 8,$E,$T,$A,$B,$C,$D); | ||
| 367 | &BODY_00_15( 0,$K[0],$X, 9,$D,$E,$T,$A,$B,$C); | ||
| 368 | &BODY_00_15( 0,$K[0],$X,10,$C,$D,$E,$T,$A,$B); | ||
| 369 | &BODY_00_15( 0,$K[0],$X,11,$B,$C,$D,$E,$T,$A); | ||
| 370 | &BODY_00_15( 0,$K[0],$X,12,$A,$B,$C,$D,$E,$T); | ||
| 371 | &BODY_00_15( 0,$K[0],$X,13,$T,$A,$B,$C,$D,$E); | ||
| 372 | &BODY_00_15( 0,$K[0],$X,14,$E,$T,$A,$B,$C,$D); | ||
| 373 | &BODY_00_15( 1,$K[0],$X,15,$D,$E,$T,$A,$B,$C); | ||
| 374 | &BODY_16_19(-1,$K[0],$X,16,$C,$D,$E,$T,$A,$B); | ||
| 375 | &BODY_16_19( 0,$K[0],$X,17,$B,$C,$D,$E,$T,$A); | ||
| 376 | &BODY_16_19( 0,$K[0],$X,18,$A,$B,$C,$D,$E,$T); | ||
| 377 | &BODY_16_19( 1,$K[0],$X,19,$T,$A,$B,$C,$D,$E); | ||
| 378 | |||
| 379 | &BODY_20_39(-1,$K[1],$X,20,$E,$T,$A,$B,$C,$D); | ||
| 380 | &BODY_20_39( 0,$K[1],$X,21,$D,$E,$T,$A,$B,$C); | ||
| 381 | &BODY_20_39( 0,$K[1],$X,22,$C,$D,$E,$T,$A,$B); | ||
| 382 | &BODY_20_39( 0,$K[1],$X,23,$B,$C,$D,$E,$T,$A); | ||
| 383 | &BODY_20_39( 0,$K[1],$X,24,$A,$B,$C,$D,$E,$T); | ||
| 384 | &BODY_20_39( 0,$K[1],$X,25,$T,$A,$B,$C,$D,$E); | ||
| 385 | &BODY_20_39( 0,$K[1],$X,26,$E,$T,$A,$B,$C,$D); | ||
| 386 | &BODY_20_39( 0,$K[1],$X,27,$D,$E,$T,$A,$B,$C); | ||
| 387 | &BODY_20_39( 0,$K[1],$X,28,$C,$D,$E,$T,$A,$B); | ||
| 388 | &BODY_20_39( 0,$K[1],$X,29,$B,$C,$D,$E,$T,$A); | ||
| 389 | &BODY_20_39( 0,$K[1],$X,30,$A,$B,$C,$D,$E,$T); | ||
| 390 | &BODY_20_39( 0,$K[1],$X,31,$T,$A,$B,$C,$D,$E); | ||
| 391 | &BODY_20_39( 0,$K[1],$X,32,$E,$T,$A,$B,$C,$D); | ||
| 392 | &BODY_20_39( 0,$K[1],$X,33,$D,$E,$T,$A,$B,$C); | ||
| 393 | &BODY_20_39( 0,$K[1],$X,34,$C,$D,$E,$T,$A,$B); | ||
| 394 | &BODY_20_39( 0,$K[1],$X,35,$B,$C,$D,$E,$T,$A); | ||
| 395 | &BODY_20_39( 0,$K[1],$X,36,$A,$B,$C,$D,$E,$T); | ||
| 396 | &BODY_20_39( 0,$K[1],$X,37,$T,$A,$B,$C,$D,$E); | ||
| 397 | &BODY_20_39( 0,$K[1],$X,38,$E,$T,$A,$B,$C,$D); | ||
| 398 | &BODY_20_39( 1,$K[1],$X,39,$D,$E,$T,$A,$B,$C); | ||
| 399 | |||
| 400 | &BODY_40_59(-1,$K[2],$X,40,$C,$D,$E,$T,$A,$B); | ||
| 401 | &BODY_40_59( 0,$K[2],$X,41,$B,$C,$D,$E,$T,$A); | ||
| 402 | &BODY_40_59( 0,$K[2],$X,42,$A,$B,$C,$D,$E,$T); | ||
| 403 | &BODY_40_59( 0,$K[2],$X,43,$T,$A,$B,$C,$D,$E); | ||
| 404 | &BODY_40_59( 0,$K[2],$X,44,$E,$T,$A,$B,$C,$D); | ||
| 405 | &BODY_40_59( 0,$K[2],$X,45,$D,$E,$T,$A,$B,$C); | ||
| 406 | &BODY_40_59( 0,$K[2],$X,46,$C,$D,$E,$T,$A,$B); | ||
| 407 | &BODY_40_59( 0,$K[2],$X,47,$B,$C,$D,$E,$T,$A); | ||
| 408 | &BODY_40_59( 0,$K[2],$X,48,$A,$B,$C,$D,$E,$T); | ||
| 409 | &BODY_40_59( 0,$K[2],$X,49,$T,$A,$B,$C,$D,$E); | ||
| 410 | &BODY_40_59( 0,$K[2],$X,50,$E,$T,$A,$B,$C,$D); | ||
| 411 | &BODY_40_59( 0,$K[2],$X,51,$D,$E,$T,$A,$B,$C); | ||
| 412 | &BODY_40_59( 0,$K[2],$X,52,$C,$D,$E,$T,$A,$B); | ||
| 413 | &BODY_40_59( 0,$K[2],$X,53,$B,$C,$D,$E,$T,$A); | ||
| 414 | &BODY_40_59( 0,$K[2],$X,54,$A,$B,$C,$D,$E,$T); | ||
| 415 | &BODY_40_59( 0,$K[2],$X,55,$T,$A,$B,$C,$D,$E); | ||
| 416 | &BODY_40_59( 0,$K[2],$X,56,$E,$T,$A,$B,$C,$D); | ||
| 417 | &BODY_40_59( 0,$K[2],$X,57,$D,$E,$T,$A,$B,$C); | ||
| 418 | &BODY_40_59( 0,$K[2],$X,58,$C,$D,$E,$T,$A,$B); | ||
| 419 | &BODY_40_59( 1,$K[2],$X,59,$B,$C,$D,$E,$T,$A); | ||
| 420 | |||
| 421 | &BODY_60_79(-1,$K[3],$X,60,$A,$B,$C,$D,$E,$T); | ||
| 422 | &BODY_60_79( 0,$K[3],$X,61,$T,$A,$B,$C,$D,$E); | ||
| 423 | &BODY_60_79( 0,$K[3],$X,62,$E,$T,$A,$B,$C,$D); | ||
| 424 | &BODY_60_79( 0,$K[3],$X,63,$D,$E,$T,$A,$B,$C); | ||
| 425 | &BODY_60_79( 0,$K[3],$X,64,$C,$D,$E,$T,$A,$B); | ||
| 426 | &BODY_60_79( 0,$K[3],$X,65,$B,$C,$D,$E,$T,$A); | ||
| 427 | &BODY_60_79( 0,$K[3],$X,66,$A,$B,$C,$D,$E,$T); | ||
| 428 | &BODY_60_79( 0,$K[3],$X,67,$T,$A,$B,$C,$D,$E); | ||
| 429 | &BODY_60_79( 0,$K[3],$X,68,$E,$T,$A,$B,$C,$D); | ||
| 430 | &BODY_60_79( 0,$K[3],$X,69,$D,$E,$T,$A,$B,$C); | ||
| 431 | &BODY_60_79( 0,$K[3],$X,70,$C,$D,$E,$T,$A,$B); | ||
| 432 | &BODY_60_79( 0,$K[3],$X,71,$B,$C,$D,$E,$T,$A); | ||
| 433 | &BODY_60_79( 0,$K[3],$X,72,$A,$B,$C,$D,$E,$T); | ||
| 434 | &BODY_60_79( 0,$K[3],$X,73,$T,$A,$B,$C,$D,$E); | ||
| 435 | &BODY_60_79( 0,$K[3],$X,74,$E,$T,$A,$B,$C,$D); | ||
| 436 | &BODY_60_79( 0,$K[3],$X,75,$D,$E,$T,$A,$B,$C); | ||
| 437 | &BODY_60_79( 0,$K[3],$X,76,$C,$D,$E,$T,$A,$B); | ||
| 438 | &BODY_60_79( 0,$K[3],$X,77,$B,$C,$D,$E,$T,$A); | ||
| 439 | &BODY_60_79( 0,$K[3],$X,78,$A,$B,$C,$D,$E,$T); | ||
| 440 | &BODY_60_79( 2,$K[3],$X,79,$T,$A,$B,$C,$D,$E); | ||
| 441 | |||
| 442 | &comment("End processing"); | ||
| 443 | &comment(""); | ||
| 444 | # D is the tmp value | ||
| 445 | |||
| 446 | # E -> A | ||
| 447 | # T -> B | ||
| 448 | # A -> C | ||
| 449 | # B -> D | ||
| 450 | # C -> E | ||
| 451 | # D -> T | ||
| 452 | |||
| 453 | # The last 2 have been moved into the last loop | ||
| 454 | # &mov($tmp1,&wparam(0)); | ||
| 455 | |||
| 456 | &mov($D, &DWP(12,$tmp1,"",0)); | ||
| 457 | &add($D,$B); | ||
| 458 | &mov($B, &DWP( 4,$tmp1,"",0)); | ||
| 459 | &add($B,$T); | ||
| 460 | &mov($T, $A); | ||
| 461 | &mov($A, &DWP( 0,$tmp1,"",0)); | ||
| 462 | &mov(&DWP(12,$tmp1,"",0),$D); | ||
| 463 | |||
| 464 | &add($A,$E); | ||
| 465 | &mov($E, &DWP(16,$tmp1,"",0)); | ||
| 466 | &add($E,$C); | ||
| 467 | &mov($C, &DWP( 8,$tmp1,"",0)); | ||
| 468 | &add($C,$T); | ||
| 469 | |||
| 470 | &mov(&DWP( 0,$tmp1,"",0),$A); | ||
| 471 | &mov("esi",&swtmp(16)); | ||
| 472 | &mov(&DWP( 8,$tmp1,"",0),$C); # This is for looping | ||
| 473 | &add("esi",64); | ||
| 474 | &mov("eax",&swtmp(17)); | ||
| 475 | &mov(&DWP(16,$tmp1,"",0),$E); | ||
| 476 | &cmp("eax","esi"); | ||
| 477 | &mov(&DWP( 4,$tmp1,"",0),$B); # This is for looping | ||
| 478 | &jl(&label("end")); | ||
| 479 | &mov("eax",&DWP(0,"esi","",0)); # Pulled down from | ||
| 480 | &jmp(&label("start")); | ||
| 481 | |||
| 482 | &set_label("end"); | ||
| 483 | &stack_pop(18); | ||
| 484 | &pop("edi"); | ||
| 485 | &pop("ebx"); | ||
| 486 | &pop("ebp"); | ||
| 487 | &pop("esi"); | ||
| 488 | &ret(); | ||
| 489 | &function_end_B($name); | ||
| 490 | } | ||
| 491 | |||
diff --git a/src/lib/libcrypto/sha/sha.h b/src/lib/libcrypto/sha/sha.h new file mode 100644 index 0000000000..4cf0ea0225 --- /dev/null +++ b/src/lib/libcrypto/sha/sha.h | |||
| @@ -0,0 +1,109 @@ | |||
| 1 | /* crypto/sha/sha.h */ | ||
| 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 | #ifndef HEADER_SHA_H | ||
| 60 | #define HEADER_SHA_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #define SHA_CBLOCK 64 | ||
| 67 | #define SHA_LBLOCK 16 | ||
| 68 | #define SHA_BLOCK 16 | ||
| 69 | #define SHA_LAST_BLOCK 56 | ||
| 70 | #define SHA_LENGTH_BLOCK 8 | ||
| 71 | #define SHA_DIGEST_LENGTH 20 | ||
| 72 | |||
| 73 | typedef struct SHAstate_st | ||
| 74 | { | ||
| 75 | unsigned long h0,h1,h2,h3,h4; | ||
| 76 | unsigned long Nl,Nh; | ||
| 77 | unsigned long data[SHA_LBLOCK]; | ||
| 78 | int num; | ||
| 79 | } SHA_CTX; | ||
| 80 | |||
| 81 | #ifndef NOPROTO | ||
| 82 | void SHA_Init(SHA_CTX *c); | ||
| 83 | void SHA_Update(SHA_CTX *c, unsigned char *data, unsigned long len); | ||
| 84 | void SHA_Final(unsigned char *md, SHA_CTX *c); | ||
| 85 | unsigned char *SHA(unsigned char *d, unsigned long n,unsigned char *md); | ||
| 86 | void SHA_Transform(SHA_CTX *c, unsigned char *data); | ||
| 87 | void SHA1_Init(SHA_CTX *c); | ||
| 88 | void SHA1_Update(SHA_CTX *c, unsigned char *data, unsigned long len); | ||
| 89 | void SHA1_Final(unsigned char *md, SHA_CTX *c); | ||
| 90 | unsigned char *SHA1(unsigned char *d, unsigned long n,unsigned char *md); | ||
| 91 | void SHA1_Transform(SHA_CTX *c, unsigned char *data); | ||
| 92 | #else | ||
| 93 | void SHA_Init(); | ||
| 94 | void SHA_Update(); | ||
| 95 | void SHA_Final(); | ||
| 96 | unsigned char *SHA(); | ||
| 97 | void SHA_Transform(); | ||
| 98 | void SHA1_Init(); | ||
| 99 | void SHA1_Update(); | ||
| 100 | void SHA1_Final(); | ||
| 101 | unsigned char *SHA1(); | ||
| 102 | void SHA1_Transform(); | ||
| 103 | #endif | ||
| 104 | |||
| 105 | #ifdef __cplusplus | ||
| 106 | } | ||
| 107 | #endif | ||
| 108 | |||
| 109 | #endif | ||
diff --git a/src/lib/libcrypto/sha/sha1_one.c b/src/lib/libcrypto/sha/sha1_one.c new file mode 100644 index 0000000000..fe5770d601 --- /dev/null +++ b/src/lib/libcrypto/sha/sha1_one.c | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | /* crypto/sha/sha1_one.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 <string.h> | ||
| 61 | #include "sha.h" | ||
| 62 | |||
| 63 | unsigned char *SHA1(d, n, md) | ||
| 64 | unsigned char *d; | ||
| 65 | unsigned long n; | ||
| 66 | unsigned char *md; | ||
| 67 | { | ||
| 68 | SHA_CTX c; | ||
| 69 | static unsigned char m[SHA_DIGEST_LENGTH]; | ||
| 70 | |||
| 71 | if (md == NULL) md=m; | ||
| 72 | SHA1_Init(&c); | ||
| 73 | SHA1_Update(&c,d,n); | ||
| 74 | SHA1_Final(md,&c); | ||
| 75 | memset(&c,0,sizeof(c)); | ||
| 76 | return(md); | ||
| 77 | } | ||
diff --git a/src/lib/libcrypto/sha/sha1dgst.c b/src/lib/libcrypto/sha/sha1dgst.c new file mode 100644 index 0000000000..2b0ae1f0d4 --- /dev/null +++ b/src/lib/libcrypto/sha/sha1dgst.c | |||
| @@ -0,0 +1,468 @@ | |||
| 1 | /* crypto/sha/sha1dgst.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 <string.h> | ||
| 61 | #undef SHA_0 | ||
| 62 | #define SHA_1 | ||
| 63 | #include "sha.h" | ||
| 64 | #include "sha_locl.h" | ||
| 65 | |||
| 66 | char *SHA1_version="SHA1 part of SSLeay 0.9.0b 29-Jun-1998"; | ||
| 67 | |||
| 68 | /* Implemented from SHA-1 document - The Secure Hash Algorithm | ||
| 69 | */ | ||
| 70 | |||
| 71 | #define INIT_DATA_h0 (unsigned long)0x67452301L | ||
| 72 | #define INIT_DATA_h1 (unsigned long)0xefcdab89L | ||
| 73 | #define INIT_DATA_h2 (unsigned long)0x98badcfeL | ||
| 74 | #define INIT_DATA_h3 (unsigned long)0x10325476L | ||
| 75 | #define INIT_DATA_h4 (unsigned long)0xc3d2e1f0L | ||
| 76 | |||
| 77 | #define K_00_19 0x5a827999L | ||
| 78 | #define K_20_39 0x6ed9eba1L | ||
| 79 | #define K_40_59 0x8f1bbcdcL | ||
| 80 | #define K_60_79 0xca62c1d6L | ||
| 81 | |||
| 82 | #ifndef NOPROTO | ||
| 83 | # ifdef SHA1_ASM | ||
| 84 | void sha1_block_x86(SHA_CTX *c, register unsigned long *p, int num); | ||
| 85 | # define sha1_block sha1_block_x86 | ||
| 86 | # else | ||
| 87 | void sha1_block(SHA_CTX *c, register unsigned long *p, int num); | ||
| 88 | # endif | ||
| 89 | #else | ||
| 90 | # ifdef SHA1_ASM | ||
| 91 | void sha1_block_x86(); | ||
| 92 | # define sha1_block sha1_block_x86 | ||
| 93 | # else | ||
| 94 | void sha1_block(); | ||
| 95 | # endif | ||
| 96 | #endif | ||
| 97 | |||
| 98 | |||
| 99 | #if defined(L_ENDIAN) && defined(SHA1_ASM) | ||
| 100 | # define M_c2nl c2l | ||
| 101 | # define M_p_c2nl p_c2l | ||
| 102 | # define M_c2nl_p c2l_p | ||
| 103 | # define M_p_c2nl_p p_c2l_p | ||
| 104 | # define M_nl2c l2c | ||
| 105 | #else | ||
| 106 | # define M_c2nl c2nl | ||
| 107 | # define M_p_c2nl p_c2nl | ||
| 108 | # define M_c2nl_p c2nl_p | ||
| 109 | # define M_p_c2nl_p p_c2nl_p | ||
| 110 | # define M_nl2c nl2c | ||
| 111 | #endif | ||
| 112 | |||
| 113 | void SHA1_Init(c) | ||
| 114 | SHA_CTX *c; | ||
| 115 | { | ||
| 116 | c->h0=INIT_DATA_h0; | ||
| 117 | c->h1=INIT_DATA_h1; | ||
| 118 | c->h2=INIT_DATA_h2; | ||
| 119 | c->h3=INIT_DATA_h3; | ||
| 120 | c->h4=INIT_DATA_h4; | ||
| 121 | c->Nl=0; | ||
| 122 | c->Nh=0; | ||
| 123 | c->num=0; | ||
| 124 | } | ||
| 125 | |||
| 126 | void SHA1_Update(c, data, len) | ||
| 127 | SHA_CTX *c; | ||
| 128 | register unsigned char *data; | ||
| 129 | unsigned long len; | ||
| 130 | { | ||
| 131 | register ULONG *p; | ||
| 132 | int ew,ec,sw,sc; | ||
| 133 | ULONG l; | ||
| 134 | |||
| 135 | if (len == 0) return; | ||
| 136 | |||
| 137 | l=(c->Nl+(len<<3))&0xffffffffL; | ||
| 138 | if (l < c->Nl) /* overflow */ | ||
| 139 | c->Nh++; | ||
| 140 | c->Nh+=(len>>29); | ||
| 141 | c->Nl=l; | ||
| 142 | |||
| 143 | if (c->num != 0) | ||
| 144 | { | ||
| 145 | p=c->data; | ||
| 146 | sw=c->num>>2; | ||
| 147 | sc=c->num&0x03; | ||
| 148 | |||
| 149 | if ((c->num+len) >= SHA_CBLOCK) | ||
| 150 | { | ||
| 151 | l= p[sw]; | ||
| 152 | M_p_c2nl(data,l,sc); | ||
| 153 | p[sw++]=l; | ||
| 154 | for (; sw<SHA_LBLOCK; sw++) | ||
| 155 | { | ||
| 156 | M_c2nl(data,l); | ||
| 157 | p[sw]=l; | ||
| 158 | } | ||
| 159 | len-=(SHA_CBLOCK-c->num); | ||
| 160 | |||
| 161 | sha1_block(c,p,64); | ||
| 162 | c->num=0; | ||
| 163 | /* drop through and do the rest */ | ||
| 164 | } | ||
| 165 | else | ||
| 166 | { | ||
| 167 | c->num+=(int)len; | ||
| 168 | if ((sc+len) < 4) /* ugly, add char's to a word */ | ||
| 169 | { | ||
| 170 | l= p[sw]; | ||
| 171 | M_p_c2nl_p(data,l,sc,len); | ||
| 172 | p[sw]=l; | ||
| 173 | } | ||
| 174 | else | ||
| 175 | { | ||
| 176 | ew=(c->num>>2); | ||
| 177 | ec=(c->num&0x03); | ||
| 178 | l= p[sw]; | ||
| 179 | M_p_c2nl(data,l,sc); | ||
| 180 | p[sw++]=l; | ||
| 181 | for (; sw < ew; sw++) | ||
| 182 | { M_c2nl(data,l); p[sw]=l; } | ||
| 183 | if (ec) | ||
| 184 | { | ||
| 185 | M_c2nl_p(data,l,ec); | ||
| 186 | p[sw]=l; | ||
| 187 | } | ||
| 188 | } | ||
| 189 | return; | ||
| 190 | } | ||
| 191 | } | ||
| 192 | /* We can only do the following code for assember, the reason | ||
| 193 | * being that the sha1_block 'C' version changes the values | ||
| 194 | * in the 'data' array. The assember code avoids this and | ||
| 195 | * copies it to a local array. I should be able to do this for | ||
| 196 | * the C version as well.... | ||
| 197 | */ | ||
| 198 | #if 1 | ||
| 199 | #if defined(B_ENDIAN) || defined(SHA1_ASM) | ||
| 200 | if ((((unsigned int)data)%sizeof(ULONG)) == 0) | ||
| 201 | { | ||
| 202 | sw=len/SHA_CBLOCK; | ||
| 203 | if (sw) | ||
| 204 | { | ||
| 205 | sw*=SHA_CBLOCK; | ||
| 206 | sha1_block(c,(ULONG *)data,sw); | ||
| 207 | data+=sw; | ||
| 208 | len-=sw; | ||
| 209 | } | ||
| 210 | } | ||
| 211 | #endif | ||
| 212 | #endif | ||
| 213 | /* we now can process the input data in blocks of SHA_CBLOCK | ||
| 214 | * chars and save the leftovers to c->data. */ | ||
| 215 | p=c->data; | ||
| 216 | while (len >= SHA_CBLOCK) | ||
| 217 | { | ||
| 218 | #if defined(B_ENDIAN) || defined(L_ENDIAN) | ||
| 219 | if (p != (unsigned long *)data) | ||
| 220 | memcpy(p,data,SHA_CBLOCK); | ||
| 221 | data+=SHA_CBLOCK; | ||
| 222 | # ifdef L_ENDIAN | ||
| 223 | # ifndef SHA1_ASM /* Will not happen */ | ||
| 224 | for (sw=(SHA_LBLOCK/4); sw; sw--) | ||
| 225 | { | ||
| 226 | Endian_Reverse32(p[0]); | ||
| 227 | Endian_Reverse32(p[1]); | ||
| 228 | Endian_Reverse32(p[2]); | ||
| 229 | Endian_Reverse32(p[3]); | ||
| 230 | p+=4; | ||
| 231 | } | ||
| 232 | p=c->data; | ||
| 233 | # endif | ||
| 234 | # endif | ||
| 235 | #else | ||
| 236 | for (sw=(SHA_BLOCK/4); sw; sw--) | ||
| 237 | { | ||
| 238 | M_c2nl(data,l); *(p++)=l; | ||
| 239 | M_c2nl(data,l); *(p++)=l; | ||
| 240 | M_c2nl(data,l); *(p++)=l; | ||
| 241 | M_c2nl(data,l); *(p++)=l; | ||
| 242 | } | ||
| 243 | p=c->data; | ||
| 244 | #endif | ||
| 245 | sha1_block(c,p,64); | ||
| 246 | len-=SHA_CBLOCK; | ||
| 247 | } | ||
| 248 | ec=(int)len; | ||
| 249 | c->num=ec; | ||
| 250 | ew=(ec>>2); | ||
| 251 | ec&=0x03; | ||
| 252 | |||
| 253 | for (sw=0; sw < ew; sw++) | ||
| 254 | { M_c2nl(data,l); p[sw]=l; } | ||
| 255 | M_c2nl_p(data,l,ec); | ||
| 256 | p[sw]=l; | ||
| 257 | } | ||
| 258 | |||
| 259 | void SHA1_Transform(c,b) | ||
| 260 | SHA_CTX *c; | ||
| 261 | unsigned char *b; | ||
| 262 | { | ||
| 263 | ULONG p[16]; | ||
| 264 | #ifndef B_ENDIAN | ||
| 265 | ULONG *q; | ||
| 266 | int i; | ||
| 267 | #endif | ||
| 268 | |||
| 269 | #if defined(B_ENDIAN) || defined(L_ENDIAN) | ||
| 270 | memcpy(p,b,64); | ||
| 271 | #ifdef L_ENDIAN | ||
| 272 | q=p; | ||
| 273 | for (i=(SHA_LBLOCK/4); i; i--) | ||
| 274 | { | ||
| 275 | Endian_Reverse32(q[0]); | ||
| 276 | Endian_Reverse32(q[1]); | ||
| 277 | Endian_Reverse32(q[2]); | ||
| 278 | Endian_Reverse32(q[3]); | ||
| 279 | q+=4; | ||
| 280 | } | ||
| 281 | #endif | ||
| 282 | #else | ||
| 283 | q=p; | ||
| 284 | for (i=(SHA_LBLOCK/4); i; i--) | ||
| 285 | { | ||
| 286 | ULONG l; | ||
| 287 | c2nl(b,l); *(q++)=l; | ||
| 288 | c2nl(b,l); *(q++)=l; | ||
| 289 | c2nl(b,l); *(q++)=l; | ||
| 290 | c2nl(b,l); *(q++)=l; | ||
| 291 | } | ||
| 292 | #endif | ||
| 293 | sha1_block(c,p,64); | ||
| 294 | } | ||
| 295 | |||
| 296 | #ifndef SHA1_ASM | ||
| 297 | |||
| 298 | void sha1_block(c, W, num) | ||
| 299 | SHA_CTX *c; | ||
| 300 | register unsigned long *W; | ||
| 301 | int num; | ||
| 302 | { | ||
| 303 | register ULONG A,B,C,D,E,T; | ||
| 304 | ULONG X[16]; | ||
| 305 | |||
| 306 | A=c->h0; | ||
| 307 | B=c->h1; | ||
| 308 | C=c->h2; | ||
| 309 | D=c->h3; | ||
| 310 | E=c->h4; | ||
| 311 | |||
| 312 | for (;;) | ||
| 313 | { | ||
| 314 | BODY_00_15( 0,A,B,C,D,E,T,W); | ||
| 315 | BODY_00_15( 1,T,A,B,C,D,E,W); | ||
| 316 | BODY_00_15( 2,E,T,A,B,C,D,W); | ||
| 317 | BODY_00_15( 3,D,E,T,A,B,C,W); | ||
| 318 | BODY_00_15( 4,C,D,E,T,A,B,W); | ||
| 319 | BODY_00_15( 5,B,C,D,E,T,A,W); | ||
| 320 | BODY_00_15( 6,A,B,C,D,E,T,W); | ||
| 321 | BODY_00_15( 7,T,A,B,C,D,E,W); | ||
| 322 | BODY_00_15( 8,E,T,A,B,C,D,W); | ||
| 323 | BODY_00_15( 9,D,E,T,A,B,C,W); | ||
| 324 | BODY_00_15(10,C,D,E,T,A,B,W); | ||
| 325 | BODY_00_15(11,B,C,D,E,T,A,W); | ||
| 326 | BODY_00_15(12,A,B,C,D,E,T,W); | ||
| 327 | BODY_00_15(13,T,A,B,C,D,E,W); | ||
| 328 | BODY_00_15(14,E,T,A,B,C,D,W); | ||
| 329 | BODY_00_15(15,D,E,T,A,B,C,W); | ||
| 330 | BODY_16_19(16,C,D,E,T,A,B,W,W,W,W); | ||
| 331 | BODY_16_19(17,B,C,D,E,T,A,W,W,W,W); | ||
| 332 | BODY_16_19(18,A,B,C,D,E,T,W,W,W,W); | ||
| 333 | BODY_16_19(19,T,A,B,C,D,E,W,W,W,X); | ||
| 334 | |||
| 335 | BODY_20_31(20,E,T,A,B,C,D,W,W,W,X); | ||
| 336 | BODY_20_31(21,D,E,T,A,B,C,W,W,W,X); | ||
| 337 | BODY_20_31(22,C,D,E,T,A,B,W,W,W,X); | ||
| 338 | BODY_20_31(23,B,C,D,E,T,A,W,W,W,X); | ||
| 339 | BODY_20_31(24,A,B,C,D,E,T,W,W,X,X); | ||
| 340 | BODY_20_31(25,T,A,B,C,D,E,W,W,X,X); | ||
| 341 | BODY_20_31(26,E,T,A,B,C,D,W,W,X,X); | ||
| 342 | BODY_20_31(27,D,E,T,A,B,C,W,W,X,X); | ||
| 343 | BODY_20_31(28,C,D,E,T,A,B,W,W,X,X); | ||
| 344 | BODY_20_31(29,B,C,D,E,T,A,W,W,X,X); | ||
| 345 | BODY_20_31(30,A,B,C,D,E,T,W,X,X,X); | ||
| 346 | BODY_20_31(31,T,A,B,C,D,E,W,X,X,X); | ||
| 347 | BODY_32_39(32,E,T,A,B,C,D,X); | ||
| 348 | BODY_32_39(33,D,E,T,A,B,C,X); | ||
| 349 | BODY_32_39(34,C,D,E,T,A,B,X); | ||
| 350 | BODY_32_39(35,B,C,D,E,T,A,X); | ||
| 351 | BODY_32_39(36,A,B,C,D,E,T,X); | ||
| 352 | BODY_32_39(37,T,A,B,C,D,E,X); | ||
| 353 | BODY_32_39(38,E,T,A,B,C,D,X); | ||
| 354 | BODY_32_39(39,D,E,T,A,B,C,X); | ||
| 355 | |||
| 356 | BODY_40_59(40,C,D,E,T,A,B,X); | ||
| 357 | BODY_40_59(41,B,C,D,E,T,A,X); | ||
| 358 | BODY_40_59(42,A,B,C,D,E,T,X); | ||
| 359 | BODY_40_59(43,T,A,B,C,D,E,X); | ||
| 360 | BODY_40_59(44,E,T,A,B,C,D,X); | ||
| 361 | BODY_40_59(45,D,E,T,A,B,C,X); | ||
| 362 | BODY_40_59(46,C,D,E,T,A,B,X); | ||
| 363 | BODY_40_59(47,B,C,D,E,T,A,X); | ||
| 364 | BODY_40_59(48,A,B,C,D,E,T,X); | ||
| 365 | BODY_40_59(49,T,A,B,C,D,E,X); | ||
| 366 | BODY_40_59(50,E,T,A,B,C,D,X); | ||
| 367 | BODY_40_59(51,D,E,T,A,B,C,X); | ||
| 368 | BODY_40_59(52,C,D,E,T,A,B,X); | ||
| 369 | BODY_40_59(53,B,C,D,E,T,A,X); | ||
| 370 | BODY_40_59(54,A,B,C,D,E,T,X); | ||
| 371 | BODY_40_59(55,T,A,B,C,D,E,X); | ||
| 372 | BODY_40_59(56,E,T,A,B,C,D,X); | ||
| 373 | BODY_40_59(57,D,E,T,A,B,C,X); | ||
| 374 | BODY_40_59(58,C,D,E,T,A,B,X); | ||
| 375 | BODY_40_59(59,B,C,D,E,T,A,X); | ||
| 376 | |||
| 377 | BODY_60_79(60,A,B,C,D,E,T,X); | ||
| 378 | BODY_60_79(61,T,A,B,C,D,E,X); | ||
| 379 | BODY_60_79(62,E,T,A,B,C,D,X); | ||
| 380 | BODY_60_79(63,D,E,T,A,B,C,X); | ||
| 381 | BODY_60_79(64,C,D,E,T,A,B,X); | ||
| 382 | BODY_60_79(65,B,C,D,E,T,A,X); | ||
| 383 | BODY_60_79(66,A,B,C,D,E,T,X); | ||
| 384 | BODY_60_79(67,T,A,B,C,D,E,X); | ||
| 385 | BODY_60_79(68,E,T,A,B,C,D,X); | ||
| 386 | BODY_60_79(69,D,E,T,A,B,C,X); | ||
| 387 | BODY_60_79(70,C,D,E,T,A,B,X); | ||
| 388 | BODY_60_79(71,B,C,D,E,T,A,X); | ||
| 389 | BODY_60_79(72,A,B,C,D,E,T,X); | ||
| 390 | BODY_60_79(73,T,A,B,C,D,E,X); | ||
| 391 | BODY_60_79(74,E,T,A,B,C,D,X); | ||
| 392 | BODY_60_79(75,D,E,T,A,B,C,X); | ||
| 393 | BODY_60_79(76,C,D,E,T,A,B,X); | ||
| 394 | BODY_60_79(77,B,C,D,E,T,A,X); | ||
| 395 | BODY_60_79(78,A,B,C,D,E,T,X); | ||
| 396 | BODY_60_79(79,T,A,B,C,D,E,X); | ||
| 397 | |||
| 398 | c->h0=(c->h0+E)&0xffffffffL; | ||
| 399 | c->h1=(c->h1+T)&0xffffffffL; | ||
| 400 | c->h2=(c->h2+A)&0xffffffffL; | ||
| 401 | c->h3=(c->h3+B)&0xffffffffL; | ||
| 402 | c->h4=(c->h4+C)&0xffffffffL; | ||
| 403 | |||
| 404 | num-=64; | ||
| 405 | if (num <= 0) break; | ||
| 406 | |||
| 407 | A=c->h0; | ||
| 408 | B=c->h1; | ||
| 409 | C=c->h2; | ||
| 410 | D=c->h3; | ||
| 411 | E=c->h4; | ||
| 412 | |||
| 413 | W+=16; | ||
| 414 | } | ||
| 415 | } | ||
| 416 | #endif | ||
| 417 | |||
| 418 | void SHA1_Final(md, c) | ||
| 419 | unsigned char *md; | ||
| 420 | SHA_CTX *c; | ||
| 421 | { | ||
| 422 | register int i,j; | ||
| 423 | register ULONG l; | ||
| 424 | register ULONG *p; | ||
| 425 | static unsigned char end[4]={0x80,0x00,0x00,0x00}; | ||
| 426 | unsigned char *cp=end; | ||
| 427 | |||
| 428 | /* c->num should definitly have room for at least one more byte. */ | ||
| 429 | p=c->data; | ||
| 430 | j=c->num; | ||
| 431 | i=j>>2; | ||
| 432 | #ifdef PURIFY | ||
| 433 | if ((j&0x03) == 0) p[i]=0; | ||
| 434 | #endif | ||
| 435 | l=p[i]; | ||
| 436 | M_p_c2nl(cp,l,j&0x03); | ||
| 437 | p[i]=l; | ||
| 438 | i++; | ||
| 439 | /* i is the next 'undefined word' */ | ||
| 440 | if (c->num >= SHA_LAST_BLOCK) | ||
| 441 | { | ||
| 442 | for (; i<SHA_LBLOCK; i++) | ||
| 443 | p[i]=0; | ||
| 444 | sha1_block(c,p,64); | ||
| 445 | i=0; | ||
| 446 | } | ||
| 447 | for (; i<(SHA_LBLOCK-2); i++) | ||
| 448 | p[i]=0; | ||
| 449 | p[SHA_LBLOCK-2]=c->Nh; | ||
| 450 | p[SHA_LBLOCK-1]=c->Nl; | ||
| 451 | #if defined(L_ENDIAN) && defined(SHA1_ASM) | ||
| 452 | Endian_Reverse32(p[SHA_LBLOCK-2]); | ||
| 453 | Endian_Reverse32(p[SHA_LBLOCK-1]); | ||
| 454 | #endif | ||
| 455 | sha1_block(c,p,64); | ||
| 456 | cp=md; | ||
| 457 | l=c->h0; nl2c(l,cp); | ||
| 458 | l=c->h1; nl2c(l,cp); | ||
| 459 | l=c->h2; nl2c(l,cp); | ||
| 460 | l=c->h3; nl2c(l,cp); | ||
| 461 | l=c->h4; nl2c(l,cp); | ||
| 462 | |||
| 463 | /* clear stuff, sha1_block may be leaving some stuff on the stack | ||
| 464 | * but I'm not worried :-) */ | ||
| 465 | c->num=0; | ||
| 466 | /* memset((char *)&c,0,sizeof(c));*/ | ||
| 467 | } | ||
| 468 | |||
diff --git a/src/lib/libcrypto/sha/sha_locl.h b/src/lib/libcrypto/sha/sha_locl.h new file mode 100644 index 0000000000..2814ad15fa --- /dev/null +++ b/src/lib/libcrypto/sha/sha_locl.h | |||
| @@ -0,0 +1,246 @@ | |||
| 1 | /* crypto/sha/sha_locl.h */ | ||
| 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 <stdlib.h> | ||
| 60 | #include <string.h> | ||
| 61 | |||
| 62 | #ifdef undef | ||
| 63 | /* one or the other needs to be defined */ | ||
| 64 | #ifndef SHA_1 /* FIPE 180-1 */ | ||
| 65 | #define SHA_0 /* FIPS 180 */ | ||
| 66 | #endif | ||
| 67 | #endif | ||
| 68 | |||
| 69 | #define ULONG unsigned long | ||
| 70 | #define UCHAR unsigned char | ||
| 71 | #define UINT unsigned int | ||
| 72 | |||
| 73 | #ifdef NOCONST | ||
| 74 | #define const | ||
| 75 | #endif | ||
| 76 | |||
| 77 | #undef c2nl | ||
| 78 | #define c2nl(c,l) (l =(((unsigned long)(*((c)++)))<<24), \ | ||
| 79 | l|=(((unsigned long)(*((c)++)))<<16), \ | ||
| 80 | l|=(((unsigned long)(*((c)++)))<< 8), \ | ||
| 81 | l|=(((unsigned long)(*((c)++))) )) | ||
| 82 | |||
| 83 | #undef p_c2nl | ||
| 84 | #define p_c2nl(c,l,n) { \ | ||
| 85 | switch (n) { \ | ||
| 86 | case 0: l =((unsigned long)(*((c)++)))<<24; \ | ||
| 87 | case 1: l|=((unsigned long)(*((c)++)))<<16; \ | ||
| 88 | case 2: l|=((unsigned long)(*((c)++)))<< 8; \ | ||
| 89 | case 3: l|=((unsigned long)(*((c)++))); \ | ||
| 90 | } \ | ||
| 91 | } | ||
| 92 | |||
| 93 | #undef c2nl_p | ||
| 94 | /* NOTE the pointer is not incremented at the end of this */ | ||
| 95 | #define c2nl_p(c,l,n) { \ | ||
| 96 | l=0; \ | ||
| 97 | (c)+=n; \ | ||
| 98 | switch (n) { \ | ||
| 99 | case 3: l =((unsigned long)(*(--(c))))<< 8; \ | ||
| 100 | case 2: l|=((unsigned long)(*(--(c))))<<16; \ | ||
| 101 | case 1: l|=((unsigned long)(*(--(c))))<<24; \ | ||
| 102 | } \ | ||
| 103 | } | ||
| 104 | |||
| 105 | #undef p_c2nl_p | ||
| 106 | #define p_c2nl_p(c,l,sc,len) { \ | ||
| 107 | switch (sc) \ | ||
| 108 | { \ | ||
| 109 | case 0: l =((unsigned long)(*((c)++)))<<24; \ | ||
| 110 | if (--len == 0) break; \ | ||
| 111 | case 1: l|=((unsigned long)(*((c)++)))<<16; \ | ||
| 112 | if (--len == 0) break; \ | ||
| 113 | case 2: l|=((unsigned long)(*((c)++)))<< 8; \ | ||
| 114 | } \ | ||
| 115 | } | ||
| 116 | |||
| 117 | #undef nl2c | ||
| 118 | #define nl2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \ | ||
| 119 | *((c)++)=(unsigned char)(((l)>>16)&0xff), \ | ||
| 120 | *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ | ||
| 121 | *((c)++)=(unsigned char)(((l) )&0xff)) | ||
| 122 | |||
| 123 | #undef c2l | ||
| 124 | #define c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \ | ||
| 125 | l|=(((unsigned long)(*((c)++)))<< 8), \ | ||
| 126 | l|=(((unsigned long)(*((c)++)))<<16), \ | ||
| 127 | l|=(((unsigned long)(*((c)++)))<<24)) | ||
| 128 | |||
| 129 | #undef p_c2l | ||
| 130 | #define p_c2l(c,l,n) { \ | ||
| 131 | switch (n) { \ | ||
| 132 | case 0: l =((unsigned long)(*((c)++))); \ | ||
| 133 | case 1: l|=((unsigned long)(*((c)++)))<< 8; \ | ||
| 134 | case 2: l|=((unsigned long)(*((c)++)))<<16; \ | ||
| 135 | case 3: l|=((unsigned long)(*((c)++)))<<24; \ | ||
| 136 | } \ | ||
| 137 | } | ||
| 138 | |||
| 139 | #undef c2l_p | ||
| 140 | /* NOTE the pointer is not incremented at the end of this */ | ||
| 141 | #define c2l_p(c,l,n) { \ | ||
| 142 | l=0; \ | ||
| 143 | (c)+=n; \ | ||
| 144 | switch (n) { \ | ||
| 145 | case 3: l =((unsigned long)(*(--(c))))<<16; \ | ||
| 146 | case 2: l|=((unsigned long)(*(--(c))))<< 8; \ | ||
| 147 | case 1: l|=((unsigned long)(*(--(c)))); \ | ||
| 148 | } \ | ||
| 149 | } | ||
| 150 | |||
| 151 | #undef p_c2l_p | ||
| 152 | #define p_c2l_p(c,l,sc,len) { \ | ||
| 153 | switch (sc) \ | ||
| 154 | { \ | ||
| 155 | case 0: l =((unsigned long)(*((c)++))); \ | ||
| 156 | if (--len == 0) break; \ | ||
| 157 | case 1: l|=((unsigned long)(*((c)++)))<< 8; \ | ||
| 158 | if (--len == 0) break; \ | ||
| 159 | case 2: l|=((unsigned long)(*((c)++)))<<16; \ | ||
| 160 | } \ | ||
| 161 | } | ||
| 162 | |||
| 163 | #undef l2c | ||
| 164 | #define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ | ||
| 165 | *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ | ||
| 166 | *((c)++)=(unsigned char)(((l)>>16)&0xff), \ | ||
| 167 | *((c)++)=(unsigned char)(((l)>>24)&0xff)) | ||
| 168 | |||
| 169 | #undef ROTATE | ||
| 170 | #if defined(WIN32) | ||
| 171 | #define ROTATE(a,n) _lrotl(a,n) | ||
| 172 | #else | ||
| 173 | #define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n)))) | ||
| 174 | #endif | ||
| 175 | |||
| 176 | /* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */ | ||
| 177 | #if defined(WIN32) | ||
| 178 | /* 5 instructions with rotate instruction, else 9 */ | ||
| 179 | #define Endian_Reverse32(a) \ | ||
| 180 | { \ | ||
| 181 | unsigned long l=(a); \ | ||
| 182 | (a)=((ROTATE(l,8)&0x00FF00FF)|(ROTATE(l,24)&0xFF00FF00)); \ | ||
| 183 | } | ||
| 184 | #else | ||
| 185 | /* 6 instructions with rotate instruction, else 8 */ | ||
| 186 | #define Endian_Reverse32(a) \ | ||
| 187 | { \ | ||
| 188 | unsigned long l=(a); \ | ||
| 189 | l=(((l&0xFF00FF00)>>8L)|((l&0x00FF00FF)<<8L)); \ | ||
| 190 | (a)=ROTATE(l,16L); \ | ||
| 191 | } | ||
| 192 | #endif | ||
| 193 | |||
| 194 | /* As pointed out by Wei Dai <weidai@eskimo.com>, F() below can be | ||
| 195 | * simplified to the code in F_00_19. Wei attributes these optimisations | ||
| 196 | * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel. | ||
| 197 | * #define F(x,y,z) (((x) & (y)) | ((~(x)) & (z))) | ||
| 198 | * I've just become aware of another tweak to be made, again from Wei Dai, | ||
| 199 | * in F_40_59, (x&a)|(y&a) -> (x|y)&a | ||
| 200 | */ | ||
| 201 | #define F_00_19(b,c,d) ((((c) ^ (d)) & (b)) ^ (d)) | ||
| 202 | #define F_20_39(b,c,d) ((b) ^ (c) ^ (d)) | ||
| 203 | #define F_40_59(b,c,d) (((b) & (c)) | (((b)|(c)) & (d))) | ||
| 204 | #define F_60_79(b,c,d) F_20_39(b,c,d) | ||
| 205 | |||
| 206 | #ifdef SHA_0 | ||
| 207 | #undef Xupdate | ||
| 208 | #define Xupdate(a,i,ia,ib,ic,id) X[(i)&0x0f]=(a)=\ | ||
| 209 | (ia[(i)&0x0f]^ib[((i)+2)&0x0f]^ic[((i)+8)&0x0f]^id[((i)+13)&0x0f]); | ||
| 210 | #endif | ||
| 211 | #ifdef SHA_1 | ||
| 212 | #undef Xupdate | ||
| 213 | #define Xupdate(a,i,ia,ib,ic,id) (a)=\ | ||
| 214 | (ia[(i)&0x0f]^ib[((i)+2)&0x0f]^ic[((i)+8)&0x0f]^id[((i)+13)&0x0f]);\ | ||
| 215 | X[(i)&0x0f]=(a)=ROTATE((a),1); | ||
| 216 | #endif | ||
| 217 | |||
| 218 | #define BODY_00_15(i,a,b,c,d,e,f,xa) \ | ||
| 219 | (f)=xa[i]+(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \ | ||
| 220 | (b)=ROTATE((b),30); | ||
| 221 | |||
| 222 | #define BODY_16_19(i,a,b,c,d,e,f,xa,xb,xc,xd) \ | ||
| 223 | Xupdate(f,i,xa,xb,xc,xd); \ | ||
| 224 | (f)+=(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \ | ||
| 225 | (b)=ROTATE((b),30); | ||
| 226 | |||
| 227 | #define BODY_20_31(i,a,b,c,d,e,f,xa,xb,xc,xd) \ | ||
| 228 | Xupdate(f,i,xa,xb,xc,xd); \ | ||
| 229 | (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \ | ||
| 230 | (b)=ROTATE((b),30); | ||
| 231 | |||
| 232 | #define BODY_32_39(i,a,b,c,d,e,f,xa) \ | ||
| 233 | Xupdate(f,i,xa,xa,xa,xa); \ | ||
| 234 | (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \ | ||
| 235 | (b)=ROTATE((b),30); | ||
| 236 | |||
| 237 | #define BODY_40_59(i,a,b,c,d,e,f,xa) \ | ||
| 238 | Xupdate(f,i,xa,xa,xa,xa); \ | ||
| 239 | (f)+=(e)+K_40_59+ROTATE((a),5)+F_40_59((b),(c),(d)); \ | ||
| 240 | (b)=ROTATE((b),30); | ||
| 241 | |||
| 242 | #define BODY_60_79(i,a,b,c,d,e,f,xa) \ | ||
| 243 | Xupdate(f,i,xa,xa,xa,xa); \ | ||
| 244 | (f)=X[(i)&0x0f]+(e)+K_60_79+ROTATE((a),5)+F_60_79((b),(c),(d)); \ | ||
| 245 | (b)=ROTATE((b),30); | ||
| 246 | |||
diff --git a/src/lib/libcrypto/stack/stack.c b/src/lib/libcrypto/stack/stack.c new file mode 100644 index 0000000000..610ccbb756 --- /dev/null +++ b/src/lib/libcrypto/stack/stack.c | |||
| @@ -0,0 +1,307 @@ | |||
| 1 | /* crypto/stack/stack.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 | /* Code for stacks | ||
| 60 | * Author - Eric Young v 1.0 | ||
| 61 | * 1.2 eay 12-Mar-97 - Modified sk_find so that it _DOES_ return the | ||
| 62 | * lowest index for the seached item. | ||
| 63 | * | ||
| 64 | * 1.1 eay - Take from netdb and added to SSLeay | ||
| 65 | * | ||
| 66 | * 1.0 eay - First version 29/07/92 | ||
| 67 | */ | ||
| 68 | #include <stdio.h> | ||
| 69 | #include "cryptlib.h" | ||
| 70 | #include "stack.h" | ||
| 71 | |||
| 72 | #undef MIN_NODES | ||
| 73 | #define MIN_NODES 4 | ||
| 74 | |||
| 75 | char *STACK_version="STACK part of SSLeay 0.9.0b 29-Jun-1998"; | ||
| 76 | |||
| 77 | #ifndef NOPROTO | ||
| 78 | #define FP_ICC (int (*)(const void *,const void *)) | ||
| 79 | #else | ||
| 80 | #define FP_ICC | ||
| 81 | #endif | ||
| 82 | |||
| 83 | #include <errno.h> | ||
| 84 | |||
| 85 | void sk_set_cmp_func(sk,c) | ||
| 86 | STACK *sk; | ||
| 87 | int (*c)(); | ||
| 88 | { | ||
| 89 | if (sk->comp != c) | ||
| 90 | sk->sorted=0; | ||
| 91 | sk->comp=c; | ||
| 92 | } | ||
| 93 | |||
| 94 | STACK *sk_dup(sk) | ||
| 95 | STACK *sk; | ||
| 96 | { | ||
| 97 | STACK *ret; | ||
| 98 | char **s; | ||
| 99 | |||
| 100 | if ((ret=sk_new(sk->comp)) == NULL) goto err; | ||
| 101 | s=(char **)Realloc((char *)ret->data, | ||
| 102 | (unsigned int)sizeof(char *)*sk->num_alloc); | ||
| 103 | if (s == NULL) goto err; | ||
| 104 | ret->data=s; | ||
| 105 | |||
| 106 | ret->num=sk->num; | ||
| 107 | memcpy(ret->data,sk->data,sizeof(char *)*sk->num); | ||
| 108 | ret->sorted=sk->sorted; | ||
| 109 | ret->num_alloc=sk->num_alloc; | ||
| 110 | ret->comp=sk->comp; | ||
| 111 | return(ret); | ||
| 112 | err: | ||
| 113 | return(NULL); | ||
| 114 | } | ||
| 115 | |||
| 116 | STACK *sk_new(c) | ||
| 117 | int (*c)(); | ||
| 118 | { | ||
| 119 | STACK *ret; | ||
| 120 | int i; | ||
| 121 | |||
| 122 | if ((ret=(STACK *)Malloc(sizeof(STACK))) == NULL) | ||
| 123 | goto err0; | ||
| 124 | if ((ret->data=(char **)Malloc(sizeof(char *)*MIN_NODES)) == NULL) | ||
| 125 | goto err1; | ||
| 126 | for (i=0; i<MIN_NODES; i++) | ||
| 127 | ret->data[i]=NULL; | ||
| 128 | ret->comp=c; | ||
| 129 | ret->num_alloc=MIN_NODES; | ||
| 130 | ret->num=0; | ||
| 131 | ret->sorted=0; | ||
| 132 | return(ret); | ||
| 133 | err1: | ||
| 134 | Free((char *)ret); | ||
| 135 | err0: | ||
| 136 | return(NULL); | ||
| 137 | } | ||
| 138 | |||
| 139 | int sk_insert(st,data,loc) | ||
| 140 | STACK *st; | ||
| 141 | char *data; | ||
| 142 | int loc; | ||
| 143 | { | ||
| 144 | char **s; | ||
| 145 | |||
| 146 | if (st->num_alloc <= st->num+1) | ||
| 147 | { | ||
| 148 | s=(char **)Realloc((char *)st->data, | ||
| 149 | (unsigned int)sizeof(char *)*st->num_alloc*2); | ||
| 150 | if (s == NULL) | ||
| 151 | return(0); | ||
| 152 | st->data=s; | ||
| 153 | st->num_alloc*=2; | ||
| 154 | } | ||
| 155 | if ((loc >= (int)st->num) || (loc < 0)) | ||
| 156 | st->data[st->num]=data; | ||
| 157 | else | ||
| 158 | { | ||
| 159 | int i; | ||
| 160 | char **f,**t; | ||
| 161 | |||
| 162 | f=(char **)st->data; | ||
| 163 | t=(char **)&(st->data[1]); | ||
| 164 | for (i=st->num; i>loc; i--) | ||
| 165 | t[i]=f[i]; | ||
| 166 | |||
| 167 | #ifdef undef /* no memmove on sunos :-( */ | ||
| 168 | memmove( (char *)&(st->data[loc+1]), | ||
| 169 | (char *)&(st->data[loc]), | ||
| 170 | sizeof(char *)*(st->num-loc)); | ||
| 171 | #endif | ||
| 172 | st->data[loc]=data; | ||
| 173 | } | ||
| 174 | st->num++; | ||
| 175 | st->sorted=0; | ||
| 176 | return(st->num); | ||
| 177 | } | ||
| 178 | |||
| 179 | char *sk_delete_ptr(st,p) | ||
| 180 | STACK *st; | ||
| 181 | char *p; | ||
| 182 | { | ||
| 183 | int i; | ||
| 184 | |||
| 185 | for (i=0; i<st->num; i++) | ||
| 186 | if (st->data[i] == p) | ||
| 187 | return(sk_delete(st,i)); | ||
| 188 | return(NULL); | ||
| 189 | } | ||
| 190 | |||
| 191 | char *sk_delete(st,loc) | ||
| 192 | STACK *st; | ||
| 193 | int loc; | ||
| 194 | { | ||
| 195 | char *ret; | ||
| 196 | int i,j; | ||
| 197 | |||
| 198 | if ((st->num == 0) || (loc < 0) || (loc >= st->num)) return(NULL); | ||
| 199 | |||
| 200 | ret=st->data[loc]; | ||
| 201 | if (loc != st->num-1) | ||
| 202 | { | ||
| 203 | j=st->num-1; | ||
| 204 | for (i=loc; i<j; i++) | ||
| 205 | st->data[i]=st->data[i+1]; | ||
| 206 | /* In theory memcpy is not safe for this | ||
| 207 | * memcpy( &(st->data[loc]), | ||
| 208 | * &(st->data[loc+1]), | ||
| 209 | * sizeof(char *)*(st->num-loc-1)); | ||
| 210 | */ | ||
| 211 | } | ||
| 212 | st->num--; | ||
| 213 | return(ret); | ||
| 214 | } | ||
| 215 | |||
| 216 | int sk_find(st,data) | ||
| 217 | STACK *st; | ||
| 218 | char *data; | ||
| 219 | { | ||
| 220 | char **r; | ||
| 221 | int i; | ||
| 222 | int (*comp_func)(); | ||
| 223 | |||
| 224 | if (st->comp == NULL) | ||
| 225 | { | ||
| 226 | for (i=0; i<st->num; i++) | ||
| 227 | if (st->data[i] == data) | ||
| 228 | return(i); | ||
| 229 | return(-1); | ||
| 230 | } | ||
| 231 | comp_func=(int (*)())st->comp; | ||
| 232 | if (!st->sorted) | ||
| 233 | { | ||
| 234 | qsort((char *)st->data,st->num,sizeof(char *),FP_ICC comp_func); | ||
| 235 | st->sorted=1; | ||
| 236 | } | ||
| 237 | if (data == NULL) return(-1); | ||
| 238 | r=(char **)bsearch(&data,(char *)st->data, | ||
| 239 | st->num,sizeof(char *),FP_ICC comp_func); | ||
| 240 | if (r == NULL) return(-1); | ||
| 241 | i=(int)(r-st->data); | ||
| 242 | for ( ; i>0; i--) | ||
| 243 | if ((*st->comp)(&(st->data[i-1]),&data) < 0) | ||
| 244 | break; | ||
| 245 | return(i); | ||
| 246 | } | ||
| 247 | |||
| 248 | int sk_push(st,data) | ||
| 249 | STACK *st; | ||
| 250 | char *data; | ||
| 251 | { | ||
| 252 | return(sk_insert(st,data,st->num)); | ||
| 253 | } | ||
| 254 | |||
| 255 | int sk_unshift(st,data) | ||
| 256 | STACK *st; | ||
| 257 | char *data; | ||
| 258 | { | ||
| 259 | return(sk_insert(st,data,0)); | ||
| 260 | } | ||
| 261 | |||
| 262 | char *sk_shift(st) | ||
| 263 | STACK *st; | ||
| 264 | { | ||
| 265 | if (st == NULL) return(NULL); | ||
| 266 | if (st->num <= 0) return(NULL); | ||
| 267 | return(sk_delete(st,0)); | ||
| 268 | } | ||
| 269 | |||
| 270 | char *sk_pop(st) | ||
| 271 | STACK *st; | ||
| 272 | { | ||
| 273 | if (st == NULL) return(NULL); | ||
| 274 | if (st->num <= 0) return(NULL); | ||
| 275 | return(sk_delete(st,st->num-1)); | ||
| 276 | } | ||
| 277 | |||
| 278 | void sk_zero(st) | ||
| 279 | STACK *st; | ||
| 280 | { | ||
| 281 | if (st == NULL) return; | ||
| 282 | if (st->num <= 0) return; | ||
| 283 | memset((char *)st->data,0,sizeof(st->data)*st->num); | ||
| 284 | st->num=0; | ||
| 285 | } | ||
| 286 | |||
| 287 | void sk_pop_free(st,func) | ||
| 288 | STACK *st; | ||
| 289 | void (*func)(); | ||
| 290 | { | ||
| 291 | int i; | ||
| 292 | |||
| 293 | if (st == NULL) return; | ||
| 294 | for (i=0; i<st->num; i++) | ||
| 295 | if (st->data[i] != NULL) | ||
| 296 | func(st->data[i]); | ||
| 297 | sk_free(st); | ||
| 298 | } | ||
| 299 | |||
| 300 | void sk_free(st) | ||
| 301 | STACK *st; | ||
| 302 | { | ||
| 303 | if (st == NULL) return; | ||
| 304 | if (st->data != NULL) Free((char *)st->data); | ||
| 305 | Free((char *)st); | ||
| 306 | } | ||
| 307 | |||
diff --git a/src/lib/libcrypto/stack/stack.h b/src/lib/libcrypto/stack/stack.h new file mode 100644 index 0000000000..615eb6ff94 --- /dev/null +++ b/src/lib/libcrypto/stack/stack.h | |||
| @@ -0,0 +1,120 @@ | |||
| 1 | /* crypto/stack/stack.h */ | ||
| 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 | #ifndef HEADER_STACK_H | ||
| 60 | #define HEADER_STACK_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | typedef struct stack_st | ||
| 67 | { | ||
| 68 | int num; | ||
| 69 | char **data; | ||
| 70 | int sorted; | ||
| 71 | |||
| 72 | int num_alloc; | ||
| 73 | int (*comp)(); | ||
| 74 | } STACK; | ||
| 75 | |||
| 76 | #define sk_num(sk) ((sk)->num) | ||
| 77 | #define sk_value(sk,n) ((sk)->data[n]) | ||
| 78 | |||
| 79 | #define sk_new_null() sk_new(NULL) | ||
| 80 | #ifndef NOPROTO | ||
| 81 | |||
| 82 | STACK *sk_new(int (*cmp)()); | ||
| 83 | void sk_free(STACK *); | ||
| 84 | void sk_pop_free(STACK *st, void (*func)()); | ||
| 85 | int sk_insert(STACK *sk,char *data,int where); | ||
| 86 | char *sk_delete(STACK *st,int loc); | ||
| 87 | char *sk_delete_ptr(STACK *st, char *p); | ||
| 88 | int sk_find(STACK *st,char *data); | ||
| 89 | int sk_push(STACK *st,char *data); | ||
| 90 | int sk_unshift(STACK *st,char *data); | ||
| 91 | char *sk_shift(STACK *st); | ||
| 92 | char *sk_pop(STACK *st); | ||
| 93 | void sk_zero(STACK *st); | ||
| 94 | void sk_set_cmp_func(STACK *sk, int (*c)()); | ||
| 95 | STACK *sk_dup(STACK *st); | ||
| 96 | |||
| 97 | #else | ||
| 98 | |||
| 99 | STACK *sk_new(); | ||
| 100 | void sk_free(); | ||
| 101 | void sk_pop_free(); | ||
| 102 | int sk_insert(); | ||
| 103 | char *sk_delete(); | ||
| 104 | char *sk_delete_ptr(); | ||
| 105 | int sk_find(); | ||
| 106 | int sk_push(); | ||
| 107 | int sk_unshift(); | ||
| 108 | char *sk_shift(); | ||
| 109 | char *sk_pop(); | ||
| 110 | void sk_zero(); | ||
| 111 | void sk_set_cmp_func(); | ||
| 112 | STACK *sk_dup(); | ||
| 113 | |||
| 114 | #endif | ||
| 115 | |||
| 116 | #ifdef __cplusplus | ||
| 117 | } | ||
| 118 | #endif | ||
| 119 | |||
| 120 | #endif | ||
diff --git a/src/lib/libcrypto/txt_db/txt_db.c b/src/lib/libcrypto/txt_db/txt_db.c new file mode 100644 index 0000000000..e34ce4efa9 --- /dev/null +++ b/src/lib/libcrypto/txt_db/txt_db.c | |||
| @@ -0,0 +1,394 @@ | |||
| 1 | /* crypto/txt_db/txt_db.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 <stdlib.h> | ||
| 61 | #include <string.h> | ||
| 62 | #include "cryptlib.h" | ||
| 63 | #include "buffer.h" | ||
| 64 | #include "txt_db.h" | ||
| 65 | |||
| 66 | #undef BUFSIZE | ||
| 67 | #define BUFSIZE 512 | ||
| 68 | |||
| 69 | char *TXT_DB_version="TXT_DB part of SSLeay 0.9.0b 29-Jun-1998"; | ||
| 70 | |||
| 71 | TXT_DB *TXT_DB_read(in,num) | ||
| 72 | BIO *in; | ||
| 73 | int num; | ||
| 74 | { | ||
| 75 | TXT_DB *ret=NULL; | ||
| 76 | int er=1; | ||
| 77 | int esc=0; | ||
| 78 | long ln=0; | ||
| 79 | int i,add,n; | ||
| 80 | int size=BUFSIZE; | ||
| 81 | int offset=0; | ||
| 82 | char *p,**pp,*f; | ||
| 83 | BUF_MEM *buf=NULL; | ||
| 84 | |||
| 85 | if ((buf=BUF_MEM_new()) == NULL) goto err; | ||
| 86 | if (!BUF_MEM_grow(buf,size)) goto err; | ||
| 87 | |||
| 88 | if ((ret=(TXT_DB *)Malloc(sizeof(TXT_DB))) == NULL) | ||
| 89 | goto err; | ||
| 90 | ret->num_fields=num; | ||
| 91 | ret->index=NULL; | ||
| 92 | ret->qual=NULL; | ||
| 93 | if ((ret->data=sk_new_null()) == NULL) | ||
| 94 | goto err; | ||
| 95 | if ((ret->index=(LHASH **)Malloc(sizeof(LHASH *)*num)) == NULL) | ||
| 96 | goto err; | ||
| 97 | if ((ret->qual=(int (**)())Malloc(sizeof(int (**)())*num)) == NULL) | ||
| 98 | goto err; | ||
| 99 | for (i=0; i<num; i++) | ||
| 100 | { | ||
| 101 | ret->index[i]=NULL; | ||
| 102 | ret->qual[i]=NULL; | ||
| 103 | } | ||
| 104 | |||
| 105 | add=(num+1)*sizeof(char *); | ||
| 106 | buf->data[size-1]='\0'; | ||
| 107 | offset=0; | ||
| 108 | for (;;) | ||
| 109 | { | ||
| 110 | if (offset != 0) | ||
| 111 | { | ||
| 112 | size+=BUFSIZE; | ||
| 113 | if (!BUF_MEM_grow(buf,size)) goto err; | ||
| 114 | } | ||
| 115 | buf->data[offset]='\0'; | ||
| 116 | BIO_gets(in,&(buf->data[offset]),size-offset); | ||
| 117 | ln++; | ||
| 118 | if (buf->data[offset] == '\0') break; | ||
| 119 | if ((offset == 0) && (buf->data[0] == '#')) continue; | ||
| 120 | i=strlen(&(buf->data[offset])); | ||
| 121 | offset+=i; | ||
| 122 | if (buf->data[offset-1] != '\n') | ||
| 123 | continue; | ||
| 124 | else | ||
| 125 | { | ||
| 126 | buf->data[offset-1]='\0'; /* blat the '\n' */ | ||
| 127 | p=(char *)Malloc(add+offset); | ||
| 128 | offset=0; | ||
| 129 | } | ||
| 130 | pp=(char **)p; | ||
| 131 | p+=add; | ||
| 132 | n=0; | ||
| 133 | pp[n++]=p; | ||
| 134 | i=0; | ||
| 135 | f=buf->data; | ||
| 136 | |||
| 137 | esc=0; | ||
| 138 | for (;;) | ||
| 139 | { | ||
| 140 | if (*f == '\0') break; | ||
| 141 | if (*f == '\t') | ||
| 142 | { | ||
| 143 | if (esc) | ||
| 144 | p--; | ||
| 145 | else | ||
| 146 | { | ||
| 147 | *(p++)='\0'; | ||
| 148 | f++; | ||
| 149 | if (n >= num) break; | ||
| 150 | pp[n++]=p; | ||
| 151 | continue; | ||
| 152 | } | ||
| 153 | } | ||
| 154 | esc=(*f == '\\'); | ||
| 155 | *(p++)= *(f++); | ||
| 156 | } | ||
| 157 | *(p++)='\0'; | ||
| 158 | if ((n != num) || (*f != '\0')) | ||
| 159 | { | ||
| 160 | #if !defined(NO_STDIO) && !defined(WIN16) /* temporaty fix :-( */ | ||
| 161 | fprintf(stderr,"wrong number of fields on line %ld\n",ln); | ||
| 162 | #endif | ||
| 163 | er=2; | ||
| 164 | goto err; | ||
| 165 | } | ||
| 166 | pp[n]=p; | ||
| 167 | if (!sk_push(ret->data,(char *)pp)) | ||
| 168 | { | ||
| 169 | #if !defined(NO_STDIO) && !defined(WIN16) /* temporaty fix :-( */ | ||
| 170 | fprintf(stderr,"failure in sk_push\n"); | ||
| 171 | #endif | ||
| 172 | er=2; | ||
| 173 | goto err; | ||
| 174 | } | ||
| 175 | } | ||
| 176 | er=0; | ||
| 177 | err: | ||
| 178 | BUF_MEM_free(buf); | ||
| 179 | if (er) | ||
| 180 | { | ||
| 181 | #if !defined(NO_STDIO) && !defined(WIN16) | ||
| 182 | if (er == 1) fprintf(stderr,"Malloc failure\n"); | ||
| 183 | #endif | ||
| 184 | if (ret->data != NULL) sk_free(ret->data); | ||
| 185 | if (ret->index != NULL) Free(ret->index); | ||
| 186 | if (ret->qual != NULL) Free((char *)ret->qual); | ||
| 187 | if (ret != NULL) Free(ret); | ||
| 188 | return(NULL); | ||
| 189 | } | ||
| 190 | else | ||
| 191 | return(ret); | ||
| 192 | } | ||
| 193 | |||
| 194 | char **TXT_DB_get_by_index(db,idx,value) | ||
| 195 | TXT_DB *db; | ||
| 196 | int idx; | ||
| 197 | char **value; | ||
| 198 | { | ||
| 199 | char **ret; | ||
| 200 | LHASH *lh; | ||
| 201 | |||
| 202 | if (idx >= db->num_fields) | ||
| 203 | { | ||
| 204 | db->error=DB_ERROR_INDEX_OUT_OF_RANGE; | ||
| 205 | return(NULL); | ||
| 206 | } | ||
| 207 | lh=db->index[idx]; | ||
| 208 | if (lh == NULL) | ||
| 209 | { | ||
| 210 | db->error=DB_ERROR_NO_INDEX; | ||
| 211 | return(NULL); | ||
| 212 | } | ||
| 213 | ret=(char **)lh_retrieve(lh,(char *)value); | ||
| 214 | db->error=DB_ERROR_OK; | ||
| 215 | return(ret); | ||
| 216 | } | ||
| 217 | |||
| 218 | int TXT_DB_create_index(db,field,qual,hash,cmp) | ||
| 219 | TXT_DB *db; | ||
| 220 | int field; | ||
| 221 | int (*qual)(); | ||
| 222 | unsigned long (*hash)(); | ||
| 223 | int (*cmp)(); | ||
| 224 | { | ||
| 225 | LHASH *idx; | ||
| 226 | char *r; | ||
| 227 | int i,n; | ||
| 228 | |||
| 229 | if (field >= db->num_fields) | ||
| 230 | { | ||
| 231 | db->error=DB_ERROR_INDEX_OUT_OF_RANGE; | ||
| 232 | return(0); | ||
| 233 | } | ||
| 234 | if ((idx=lh_new(hash,cmp)) == NULL) | ||
| 235 | { | ||
| 236 | db->error=DB_ERROR_MALLOC; | ||
| 237 | return(0); | ||
| 238 | } | ||
| 239 | n=sk_num(db->data); | ||
| 240 | for (i=0; i<n; i++) | ||
| 241 | { | ||
| 242 | r=(char *)sk_value(db->data,i); | ||
| 243 | if ((qual != NULL) && (qual(r) == 0)) continue; | ||
| 244 | if ((r=lh_insert(idx,r)) != NULL) | ||
| 245 | { | ||
| 246 | db->error=DB_ERROR_INDEX_CLASH; | ||
| 247 | db->arg1=sk_find(db->data,r); | ||
| 248 | db->arg2=i; | ||
| 249 | lh_free(idx); | ||
| 250 | return(0); | ||
| 251 | } | ||
| 252 | } | ||
| 253 | if (db->index[field] != NULL) lh_free(db->index[field]); | ||
| 254 | db->index[field]=idx; | ||
| 255 | db->qual[field]=qual; | ||
| 256 | return(1); | ||
| 257 | } | ||
| 258 | |||
| 259 | long TXT_DB_write(out,db) | ||
| 260 | BIO *out; | ||
| 261 | TXT_DB *db; | ||
| 262 | { | ||
| 263 | long i,j,n,nn,l,tot=0; | ||
| 264 | char *p,**pp,*f; | ||
| 265 | BUF_MEM *buf=NULL; | ||
| 266 | long ret= -1; | ||
| 267 | |||
| 268 | if ((buf=BUF_MEM_new()) == NULL) | ||
| 269 | goto err; | ||
| 270 | n=sk_num(db->data); | ||
| 271 | nn=db->num_fields; | ||
| 272 | for (i=0; i<n; i++) | ||
| 273 | { | ||
| 274 | pp=(char **)sk_value(db->data,i); | ||
| 275 | |||
| 276 | l=0; | ||
| 277 | for (j=0; j<nn; j++) | ||
| 278 | { | ||
| 279 | if (pp[j] != NULL) | ||
| 280 | l+=strlen(pp[j]); | ||
| 281 | } | ||
| 282 | if (!BUF_MEM_grow(buf,(int)(l*2+nn))) goto err; | ||
| 283 | |||
| 284 | p=buf->data; | ||
| 285 | for (j=0; j<nn; j++) | ||
| 286 | { | ||
| 287 | f=pp[j]; | ||
| 288 | if (f != NULL) | ||
| 289 | for (;;) | ||
| 290 | { | ||
| 291 | if (*f == '\0') break; | ||
| 292 | if (*f == '\t') *(p++)='\\'; | ||
| 293 | *(p++)= *(f++); | ||
| 294 | } | ||
| 295 | *(p++)='\t'; | ||
| 296 | } | ||
| 297 | p[-1]='\n'; | ||
| 298 | j=p-buf->data; | ||
| 299 | if (BIO_write(out,buf->data,(int)j) != j) | ||
| 300 | goto err; | ||
| 301 | tot+=j; | ||
| 302 | } | ||
| 303 | ret=tot; | ||
| 304 | err: | ||
| 305 | if (buf != NULL) BUF_MEM_free(buf); | ||
| 306 | return(ret); | ||
| 307 | } | ||
| 308 | |||
| 309 | int TXT_DB_insert(db,row) | ||
| 310 | TXT_DB *db; | ||
| 311 | char **row; | ||
| 312 | { | ||
| 313 | int i; | ||
| 314 | char **r; | ||
| 315 | |||
| 316 | for (i=0; i<db->num_fields; i++) | ||
| 317 | { | ||
| 318 | if (db->index[i] != NULL) | ||
| 319 | { | ||
| 320 | if ((db->qual[i] != NULL) && | ||
| 321 | (db->qual[i](row) == 0)) continue; | ||
| 322 | r=(char **)lh_retrieve(db->index[i],(char *)row); | ||
| 323 | if (r != NULL) | ||
| 324 | { | ||
| 325 | db->error=DB_ERROR_INDEX_CLASH; | ||
| 326 | db->arg1=i; | ||
| 327 | db->arg_row=r; | ||
| 328 | goto err; | ||
| 329 | } | ||
| 330 | } | ||
| 331 | } | ||
| 332 | /* We have passed the index checks, now just append and insert */ | ||
| 333 | if (!sk_push(db->data,(char *)row)) | ||
| 334 | { | ||
| 335 | db->error=DB_ERROR_MALLOC; | ||
| 336 | goto err; | ||
| 337 | } | ||
| 338 | |||
| 339 | for (i=0; i<db->num_fields; i++) | ||
| 340 | { | ||
| 341 | if (db->index[i] != NULL) | ||
| 342 | { | ||
| 343 | if ((db->qual[i] != NULL) && | ||
| 344 | (db->qual[i](row) == 0)) continue; | ||
| 345 | lh_insert(db->index[i],(char *)row); | ||
| 346 | } | ||
| 347 | } | ||
| 348 | return(1); | ||
| 349 | err: | ||
| 350 | return(0); | ||
| 351 | } | ||
| 352 | |||
| 353 | void TXT_DB_free(db) | ||
| 354 | TXT_DB *db; | ||
| 355 | { | ||
| 356 | int i,n; | ||
| 357 | char **p,*max; | ||
| 358 | |||
| 359 | if (db->index != NULL) | ||
| 360 | { | ||
| 361 | for (i=db->num_fields-1; i>=0; i--) | ||
| 362 | if (db->index[i] != NULL) lh_free(db->index[i]); | ||
| 363 | Free(db->index); | ||
| 364 | } | ||
| 365 | if (db->qual != NULL) | ||
| 366 | Free(db->qual); | ||
| 367 | if (db->data != NULL) | ||
| 368 | { | ||
| 369 | for (i=sk_num(db->data)-1; i>=0; i--) | ||
| 370 | { | ||
| 371 | /* check if any 'fields' have been allocated | ||
| 372 | * from outside of the initial block */ | ||
| 373 | p=(char **)sk_value(db->data,i); | ||
| 374 | max=p[db->num_fields]; /* last address */ | ||
| 375 | if (max == NULL) /* new row */ | ||
| 376 | { | ||
| 377 | for (n=0; n<db->num_fields; n++) | ||
| 378 | if (p[n] != NULL) Free(p[n]); | ||
| 379 | } | ||
| 380 | else | ||
| 381 | { | ||
| 382 | for (n=0; n<db->num_fields; n++) | ||
| 383 | { | ||
| 384 | if (((p[n] < (char *)p) || (p[n] > max)) | ||
| 385 | && (p[n] != NULL)) | ||
| 386 | Free(p[n]); | ||
| 387 | } | ||
| 388 | } | ||
| 389 | Free(sk_value(db->data,i)); | ||
| 390 | } | ||
| 391 | sk_free(db->data); | ||
| 392 | } | ||
| 393 | Free(db); | ||
| 394 | } | ||
diff --git a/src/lib/libcrypto/txt_db/txt_db.h b/src/lib/libcrypto/txt_db/txt_db.h new file mode 100644 index 0000000000..aca6dae393 --- /dev/null +++ b/src/lib/libcrypto/txt_db/txt_db.h | |||
| @@ -0,0 +1,117 @@ | |||
| 1 | /* crypto/txt_db/txt_db.h */ | ||
| 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 | #ifndef HEADER_TXT_DB_H | ||
| 60 | #define HEADER_TXT_DB_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #include "stack.h" | ||
| 67 | #include "lhash.h" | ||
| 68 | |||
| 69 | #define DB_ERROR_OK 0 | ||
| 70 | #define DB_ERROR_MALLOC 1 | ||
| 71 | #define DB_ERROR_INDEX_CLASH 2 | ||
| 72 | #define DB_ERROR_INDEX_OUT_OF_RANGE 3 | ||
| 73 | #define DB_ERROR_NO_INDEX 4 | ||
| 74 | #define DB_ERROR_INSERT_INDEX_CLASH 5 | ||
| 75 | |||
| 76 | typedef struct txt_db_st | ||
| 77 | { | ||
| 78 | int num_fields; | ||
| 79 | STACK /* char ** */ *data; | ||
| 80 | LHASH **index; | ||
| 81 | int (**qual)(); | ||
| 82 | long error; | ||
| 83 | long arg1; | ||
| 84 | long arg2; | ||
| 85 | char **arg_row; | ||
| 86 | } TXT_DB; | ||
| 87 | |||
| 88 | #ifndef NOPROTO | ||
| 89 | #ifdef HEADER_BIO_H | ||
| 90 | TXT_DB *TXT_DB_read(BIO *in, int num); | ||
| 91 | long TXT_DB_write(BIO *out, TXT_DB *db); | ||
| 92 | #else | ||
| 93 | TXT_DB *TXT_DB_read(char *in, int num); | ||
| 94 | long TXT_DB_write(char *out, TXT_DB *db); | ||
| 95 | #endif | ||
| 96 | int TXT_DB_create_index(TXT_DB *db,int field,int (*qual)(), | ||
| 97 | unsigned long (*hash)(),int (*cmp)()); | ||
| 98 | void TXT_DB_free(TXT_DB *db); | ||
| 99 | char **TXT_DB_get_by_index(TXT_DB *db, int idx, char **value); | ||
| 100 | int TXT_DB_insert(TXT_DB *db,char **value); | ||
| 101 | |||
| 102 | #else | ||
| 103 | |||
| 104 | TXT_DB *TXT_DB_read(); | ||
| 105 | long TXT_DB_write(); | ||
| 106 | int TXT_DB_create_index(); | ||
| 107 | void TXT_DB_free(); | ||
| 108 | char **TXT_DB_get_by_index(); | ||
| 109 | int TXT_DB_insert(); | ||
| 110 | |||
| 111 | #endif | ||
| 112 | |||
| 113 | #ifdef __cplusplus | ||
| 114 | } | ||
| 115 | #endif | ||
| 116 | |||
| 117 | #endif | ||
diff --git a/src/lib/libcrypto/x509/by_dir.c b/src/lib/libcrypto/x509/by_dir.c new file mode 100644 index 0000000000..11725ec94c --- /dev/null +++ b/src/lib/libcrypto/x509/by_dir.c | |||
| @@ -0,0 +1,359 @@ | |||
| 1 | /* crypto/x509/by_dir.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 <time.h> | ||
| 61 | #include <errno.h> | ||
| 62 | #include <sys/types.h> | ||
| 63 | #include <sys/stat.h> | ||
| 64 | |||
| 65 | #include "cryptlib.h" | ||
| 66 | #include "lhash.h" | ||
| 67 | #include "x509.h" | ||
| 68 | #include "pem.h" | ||
| 69 | |||
| 70 | typedef struct lookup_dir_st | ||
| 71 | { | ||
| 72 | BUF_MEM *buffer; | ||
| 73 | int num_dirs; | ||
| 74 | char **dirs; | ||
| 75 | int *dirs_type; | ||
| 76 | int num_dirs_alloced; | ||
| 77 | } BY_DIR; | ||
| 78 | |||
| 79 | #ifndef NOPROTO | ||
| 80 | static int dir_ctrl(X509_LOOKUP *ctx,int cmd,char *argp,long argl,char **ret); | ||
| 81 | static int new_dir(X509_LOOKUP *lu); | ||
| 82 | static void free_dir(X509_LOOKUP *lu); | ||
| 83 | static int add_cert_dir(BY_DIR *ctx,char *dir,int type); | ||
| 84 | static int get_cert_by_subject(X509_LOOKUP *xl,int type,X509_NAME *name, | ||
| 85 | X509_OBJECT *ret); | ||
| 86 | #else | ||
| 87 | static int dir_ctrl(); | ||
| 88 | static int new_dir(); | ||
| 89 | static void free_dir(); | ||
| 90 | static int add_cert_dir(); | ||
| 91 | static int get_cert_by_subject(); | ||
| 92 | #endif | ||
| 93 | |||
| 94 | X509_LOOKUP_METHOD x509_dir_lookup= | ||
| 95 | { | ||
| 96 | "Load certs from files in a directory", | ||
| 97 | new_dir, /* new */ | ||
| 98 | free_dir, /* free */ | ||
| 99 | NULL, /* init */ | ||
| 100 | NULL, /* shutdown */ | ||
| 101 | dir_ctrl, /* ctrl */ | ||
| 102 | get_cert_by_subject, /* get_by_subject */ | ||
| 103 | NULL, /* get_by_issuer_serial */ | ||
| 104 | NULL, /* get_by_fingerprint */ | ||
| 105 | NULL, /* get_by_alias */ | ||
| 106 | }; | ||
| 107 | |||
| 108 | X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir() | ||
| 109 | { | ||
| 110 | return(&x509_dir_lookup); | ||
| 111 | } | ||
| 112 | |||
| 113 | static int dir_ctrl(ctx,cmd,argp,argl,retp) | ||
| 114 | X509_LOOKUP *ctx; | ||
| 115 | int cmd; | ||
| 116 | long argl; | ||
| 117 | char *argp; | ||
| 118 | char **retp; | ||
| 119 | { | ||
| 120 | int ret=0; | ||
| 121 | BY_DIR *ld; | ||
| 122 | char *dir; | ||
| 123 | |||
| 124 | ld=(BY_DIR *)ctx->method_data; | ||
| 125 | |||
| 126 | switch (cmd) | ||
| 127 | { | ||
| 128 | case X509_L_ADD_DIR: | ||
| 129 | if (argl == X509_FILETYPE_DEFAULT) | ||
| 130 | { | ||
| 131 | ret=add_cert_dir(ld,X509_get_default_cert_dir(), | ||
| 132 | X509_FILETYPE_PEM); | ||
| 133 | if (!ret) | ||
| 134 | { | ||
| 135 | X509err(X509_F_DIR_CTRL,X509_R_LOADING_CERT_DIR); | ||
| 136 | } | ||
| 137 | else | ||
| 138 | { | ||
| 139 | dir=(char *)Getenv(X509_get_default_cert_dir_env()); | ||
| 140 | ret=add_cert_dir(ld,dir,X509_FILETYPE_PEM); | ||
| 141 | } | ||
| 142 | } | ||
| 143 | else | ||
| 144 | ret=add_cert_dir(ld,argp,(int)argl); | ||
| 145 | break; | ||
| 146 | } | ||
| 147 | return(ret); | ||
| 148 | } | ||
| 149 | |||
| 150 | static int new_dir(lu) | ||
| 151 | X509_LOOKUP *lu; | ||
| 152 | { | ||
| 153 | BY_DIR *a; | ||
| 154 | |||
| 155 | if ((a=(BY_DIR *)Malloc(sizeof(BY_DIR))) == NULL) | ||
| 156 | return(0); | ||
| 157 | if ((a->buffer=BUF_MEM_new()) == NULL) | ||
| 158 | { | ||
| 159 | Free(a); | ||
| 160 | return(0); | ||
| 161 | } | ||
| 162 | a->num_dirs=0; | ||
| 163 | a->dirs=NULL; | ||
| 164 | a->dirs_type=NULL; | ||
| 165 | a->num_dirs_alloced=0; | ||
| 166 | lu->method_data=(char *)a; | ||
| 167 | return(1); | ||
| 168 | } | ||
| 169 | |||
| 170 | static void free_dir(lu) | ||
| 171 | X509_LOOKUP *lu; | ||
| 172 | { | ||
| 173 | BY_DIR *a; | ||
| 174 | int i; | ||
| 175 | |||
| 176 | a=(BY_DIR *)lu->method_data; | ||
| 177 | for (i=0; i<a->num_dirs; i++) | ||
| 178 | if (a->dirs[i] != NULL) Free(a->dirs[i]); | ||
| 179 | if (a->dirs != NULL) Free(a->dirs); | ||
| 180 | if (a->dirs_type != NULL) Free(a->dirs_type); | ||
| 181 | if (a->buffer != NULL) BUF_MEM_free(a->buffer); | ||
| 182 | Free(a); | ||
| 183 | } | ||
| 184 | |||
| 185 | static int add_cert_dir(ctx,dir, type) | ||
| 186 | BY_DIR *ctx; | ||
| 187 | char *dir; | ||
| 188 | int type; | ||
| 189 | { | ||
| 190 | int j,len; | ||
| 191 | int *ip; | ||
| 192 | char *s,*ss,*p; | ||
| 193 | char **pp; | ||
| 194 | |||
| 195 | if (dir == NULL) return(0); | ||
| 196 | |||
| 197 | s=dir; | ||
| 198 | p=s; | ||
| 199 | for (;;) | ||
| 200 | { | ||
| 201 | if ((*p == LIST_SEPARATOR_CHAR) || (*p == '\0')) | ||
| 202 | { | ||
| 203 | ss=s; | ||
| 204 | s=p+1; | ||
| 205 | len=(int)(p-ss); | ||
| 206 | if (len == 0) continue; | ||
| 207 | for (j=0; j<ctx->num_dirs; j++) | ||
| 208 | if (strncmp(ctx->dirs[j],ss,(unsigned int)len) == 0) | ||
| 209 | continue; | ||
| 210 | if (ctx->num_dirs_alloced < (ctx->num_dirs+1)) | ||
| 211 | { | ||
| 212 | ctx->num_dirs_alloced+=10; | ||
| 213 | pp=(char **)Malloc(ctx->num_dirs_alloced* | ||
| 214 | sizeof(char *)); | ||
| 215 | ip=(int *)Malloc(ctx->num_dirs_alloced* | ||
| 216 | sizeof(int)); | ||
| 217 | if ((pp == NULL) || (ip == NULL)) | ||
| 218 | { | ||
| 219 | X509err(X509_F_ADD_CERT_DIR,ERR_R_MALLOC_FAILURE); | ||
| 220 | return(0); | ||
| 221 | } | ||
| 222 | memcpy(pp,ctx->dirs,(ctx->num_dirs_alloced-10)* | ||
| 223 | sizeof(char *)); | ||
| 224 | memcpy(ip,ctx->dirs_type,(ctx->num_dirs_alloced-10)* | ||
| 225 | sizeof(int)); | ||
| 226 | if (ctx->dirs != NULL) | ||
| 227 | Free((char *)ctx->dirs); | ||
| 228 | if (ctx->dirs_type != NULL) | ||
| 229 | Free((char *)ctx->dirs_type); | ||
| 230 | ctx->dirs=pp; | ||
| 231 | ctx->dirs_type=ip; | ||
| 232 | } | ||
| 233 | ctx->dirs_type[ctx->num_dirs]=type; | ||
| 234 | ctx->dirs[ctx->num_dirs]=(char *)Malloc((unsigned int)len+1); | ||
| 235 | if (ctx->dirs[ctx->num_dirs] == NULL) return(0); | ||
| 236 | strncpy(ctx->dirs[ctx->num_dirs],ss,(unsigned int)len); | ||
| 237 | ctx->dirs[ctx->num_dirs][len]='\0'; | ||
| 238 | ctx->num_dirs++; | ||
| 239 | } | ||
| 240 | if (*p == '\0') break; | ||
| 241 | p++; | ||
| 242 | } | ||
| 243 | return(1); | ||
| 244 | } | ||
| 245 | |||
| 246 | static int get_cert_by_subject(xl,type,name,ret) | ||
| 247 | X509_LOOKUP *xl; | ||
| 248 | int type; | ||
| 249 | X509_NAME *name; | ||
| 250 | X509_OBJECT *ret; | ||
| 251 | { | ||
| 252 | BY_DIR *ctx; | ||
| 253 | union { | ||
| 254 | struct { | ||
| 255 | X509 st_x509; | ||
| 256 | X509_CINF st_x509_cinf; | ||
| 257 | } x509; | ||
| 258 | struct { | ||
| 259 | X509_CRL st_crl; | ||
| 260 | X509_CRL_INFO st_crl_info; | ||
| 261 | } crl; | ||
| 262 | } data; | ||
| 263 | int ok=0; | ||
| 264 | int i,j,k; | ||
| 265 | unsigned long h; | ||
| 266 | BUF_MEM *b=NULL; | ||
| 267 | struct stat st; | ||
| 268 | X509_OBJECT stmp,*tmp; | ||
| 269 | char *postfix=""; | ||
| 270 | |||
| 271 | if (name == NULL) return(0); | ||
| 272 | |||
| 273 | stmp.type=type; | ||
| 274 | if (type == X509_LU_X509) | ||
| 275 | { | ||
| 276 | data.x509.st_x509.cert_info= &data.x509.st_x509_cinf; | ||
| 277 | data.x509.st_x509_cinf.subject=name; | ||
| 278 | stmp.data.x509= &data.x509.st_x509; | ||
| 279 | postfix=""; | ||
| 280 | } | ||
| 281 | else if (type == X509_LU_CRL) | ||
| 282 | { | ||
| 283 | data.crl.st_crl.crl= &data.crl.st_crl_info; | ||
| 284 | data.crl.st_crl_info.issuer=name; | ||
| 285 | stmp.data.crl= &data.crl.st_crl; | ||
| 286 | postfix="r"; | ||
| 287 | } | ||
| 288 | else | ||
| 289 | { | ||
| 290 | X509err(X509_F_GET_CERT_BY_SUBJECT,X509_R_WRONG_LOOKUP_TYPE); | ||
| 291 | goto finish; | ||
| 292 | } | ||
| 293 | |||
| 294 | if ((b=BUF_MEM_new()) == NULL) | ||
| 295 | { | ||
| 296 | X509err(X509_F_GET_CERT_BY_SUBJECT,ERR_R_BUF_LIB); | ||
| 297 | goto finish; | ||
| 298 | } | ||
| 299 | |||
| 300 | ctx=(BY_DIR *)xl->method_data; | ||
| 301 | |||
| 302 | h=X509_NAME_hash(name); | ||
| 303 | for (i=0; i<ctx->num_dirs; i++) | ||
| 304 | { | ||
| 305 | j=strlen(ctx->dirs[i])+1+8+6+1+1; | ||
| 306 | if (!BUF_MEM_grow(b,j)) | ||
| 307 | { | ||
| 308 | X509err(X509_F_GET_CERT_BY_SUBJECT,ERR_R_MALLOC_FAILURE); | ||
| 309 | goto finish; | ||
| 310 | } | ||
| 311 | k=0; | ||
| 312 | for (;;) | ||
| 313 | { | ||
| 314 | sprintf(b->data,"%s/%08lx.%s%d",ctx->dirs[i],h, | ||
| 315 | postfix,k); | ||
| 316 | k++; | ||
| 317 | if (stat(b->data,&st) < 0) | ||
| 318 | break; | ||
| 319 | /* found one. */ | ||
| 320 | if (type == X509_LU_X509) | ||
| 321 | { | ||
| 322 | if ((X509_load_cert_file(xl,b->data, | ||
| 323 | ctx->dirs_type[i])) == 0) | ||
| 324 | break; | ||
| 325 | } | ||
| 326 | else if (type == X509_LU_CRL) | ||
| 327 | { | ||
| 328 | if ((X509_load_crl_file(xl,b->data, | ||
| 329 | ctx->dirs_type[i])) == 0) | ||
| 330 | break; | ||
| 331 | } | ||
| 332 | /* else case will caught higher up */ | ||
| 333 | } | ||
| 334 | |||
| 335 | /* we have added it to the cache so now pull | ||
| 336 | * it out again */ | ||
| 337 | CRYPTO_r_lock(CRYPTO_LOCK_X509_STORE); | ||
| 338 | tmp=(X509_OBJECT *)lh_retrieve(xl->store_ctx->certs, | ||
| 339 | (char *)&stmp); | ||
| 340 | CRYPTO_r_unlock(CRYPTO_LOCK_X509_STORE); | ||
| 341 | |||
| 342 | if (tmp != NULL) | ||
| 343 | { | ||
| 344 | ok=1; | ||
| 345 | ret->type=tmp->type; | ||
| 346 | memcpy(&ret->data,&tmp->data,sizeof(ret->data)); | ||
| 347 | /* If we were going to up the reference count, | ||
| 348 | * we would need to do it on a perl 'type' | ||
| 349 | * basis */ | ||
| 350 | /* CRYPTO_add(&tmp->data.x509->references,1, | ||
| 351 | CRYPTO_LOCK_X509);*/ | ||
| 352 | goto finish; | ||
| 353 | } | ||
| 354 | } | ||
| 355 | finish: | ||
| 356 | if (b != NULL) BUF_MEM_free(b); | ||
| 357 | return(ok); | ||
| 358 | } | ||
| 359 | |||
diff --git a/src/lib/libcrypto/x509/by_file.c b/src/lib/libcrypto/x509/by_file.c new file mode 100644 index 0000000000..09ebb9bf08 --- /dev/null +++ b/src/lib/libcrypto/x509/by_file.c | |||
| @@ -0,0 +1,282 @@ | |||
| 1 | /* crypto/x509/by_file.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 <time.h> | ||
| 61 | #include <errno.h> | ||
| 62 | #include <sys/types.h> | ||
| 63 | #include <sys/stat.h> | ||
| 64 | |||
| 65 | #include "cryptlib.h" | ||
| 66 | #include "lhash.h" | ||
| 67 | #include "buffer.h" | ||
| 68 | #include "x509.h" | ||
| 69 | #include "pem.h" | ||
| 70 | |||
| 71 | #ifndef NO_STDIO | ||
| 72 | |||
| 73 | #ifndef NOPROTO | ||
| 74 | static int by_file_ctrl(X509_LOOKUP *ctx,int cmd,char *argc, | ||
| 75 | long argl,char **ret); | ||
| 76 | #else | ||
| 77 | static int by_file_ctrl(); | ||
| 78 | #endif | ||
| 79 | |||
| 80 | X509_LOOKUP_METHOD x509_file_lookup= | ||
| 81 | { | ||
| 82 | "Load file into cache", | ||
| 83 | NULL, /* new */ | ||
| 84 | NULL, /* free */ | ||
| 85 | NULL, /* init */ | ||
| 86 | NULL, /* shutdown */ | ||
| 87 | by_file_ctrl, /* ctrl */ | ||
| 88 | NULL, /* get_by_subject */ | ||
| 89 | NULL, /* get_by_issuer_serial */ | ||
| 90 | NULL, /* get_by_fingerprint */ | ||
| 91 | NULL, /* get_by_alias */ | ||
| 92 | }; | ||
| 93 | |||
| 94 | X509_LOOKUP_METHOD *X509_LOOKUP_file() | ||
| 95 | { | ||
| 96 | return(&x509_file_lookup); | ||
| 97 | } | ||
| 98 | |||
| 99 | static int by_file_ctrl(ctx,cmd,argp,argl,ret) | ||
| 100 | X509_LOOKUP *ctx; | ||
| 101 | int cmd; | ||
| 102 | char *argp; | ||
| 103 | long argl; | ||
| 104 | char **ret; | ||
| 105 | { | ||
| 106 | int ok=0,ok2=0; | ||
| 107 | char *file; | ||
| 108 | |||
| 109 | switch (cmd) | ||
| 110 | { | ||
| 111 | case X509_L_FILE_LOAD: | ||
| 112 | if (argl == X509_FILETYPE_DEFAULT) | ||
| 113 | { | ||
| 114 | ok=X509_load_cert_file(ctx,X509_get_default_cert_file(), | ||
| 115 | X509_FILETYPE_PEM); | ||
| 116 | ok2=X509_load_crl_file(ctx,X509_get_default_cert_file(), | ||
| 117 | X509_FILETYPE_PEM); | ||
| 118 | if (!ok || !ok2) | ||
| 119 | { | ||
| 120 | X509err(X509_F_BY_FILE_CTRL,X509_R_LOADING_DEFAULTS); | ||
| 121 | } | ||
| 122 | else | ||
| 123 | { | ||
| 124 | file=(char *)Getenv(X509_get_default_cert_file_env()); | ||
| 125 | ok=X509_load_cert_file(ctx,file, | ||
| 126 | X509_FILETYPE_PEM); | ||
| 127 | ok2=X509_load_crl_file(ctx,file, | ||
| 128 | X509_FILETYPE_PEM); | ||
| 129 | } | ||
| 130 | } | ||
| 131 | else | ||
| 132 | { | ||
| 133 | ok=X509_load_cert_file(ctx,argp,(int)argl); | ||
| 134 | ok2=X509_load_crl_file(ctx,argp,(int)argl); | ||
| 135 | } | ||
| 136 | break; | ||
| 137 | } | ||
| 138 | return((ok && ok2)?ok:0); | ||
| 139 | } | ||
| 140 | |||
| 141 | int X509_load_cert_file(ctx,file,type) | ||
| 142 | X509_LOOKUP *ctx; | ||
| 143 | char *file; | ||
| 144 | int type; | ||
| 145 | { | ||
| 146 | int ret=0; | ||
| 147 | BIO *in=NULL; | ||
| 148 | int i,count=0; | ||
| 149 | X509 *x=NULL; | ||
| 150 | |||
| 151 | if (file == NULL) return(1); | ||
| 152 | in=BIO_new(BIO_s_file_internal()); | ||
| 153 | |||
| 154 | if ((in == NULL) || (BIO_read_filename(in,file) <= 0)) | ||
| 155 | { | ||
| 156 | X509err(X509_F_X509_LOAD_CERT_FILE,ERR_R_SYS_LIB); | ||
| 157 | goto err; | ||
| 158 | } | ||
| 159 | |||
| 160 | if (type == X509_FILETYPE_PEM) | ||
| 161 | { | ||
| 162 | for (;;) | ||
| 163 | { | ||
| 164 | x=PEM_read_bio_X509(in,NULL,NULL); | ||
| 165 | if (x == NULL) | ||
| 166 | { | ||
| 167 | if ((ERR_GET_REASON(ERR_peek_error()) == | ||
| 168 | PEM_R_NO_START_LINE) && (count > 0)) | ||
| 169 | { | ||
| 170 | ERR_clear_error(); | ||
| 171 | break; | ||
| 172 | } | ||
| 173 | else | ||
| 174 | { | ||
| 175 | X509err(X509_F_X509_LOAD_CERT_FILE, | ||
| 176 | ERR_R_PEM_LIB); | ||
| 177 | goto err; | ||
| 178 | } | ||
| 179 | } | ||
| 180 | i=X509_STORE_add_cert(ctx->store_ctx,x); | ||
| 181 | if (!i) goto err; | ||
| 182 | count++; | ||
| 183 | X509_free(x); | ||
| 184 | x=NULL; | ||
| 185 | } | ||
| 186 | ret=count; | ||
| 187 | } | ||
| 188 | else if (type == X509_FILETYPE_ASN1) | ||
| 189 | { | ||
| 190 | x=d2i_X509_bio(in,NULL); | ||
| 191 | if (x == NULL) | ||
| 192 | { | ||
| 193 | X509err(X509_F_X509_LOAD_CERT_FILE,ERR_R_ASN1_LIB); | ||
| 194 | goto err; | ||
| 195 | } | ||
| 196 | i=X509_STORE_add_cert(ctx->store_ctx,x); | ||
| 197 | if (!i) goto err; | ||
| 198 | ret=i; | ||
| 199 | } | ||
| 200 | else | ||
| 201 | { | ||
| 202 | X509err(X509_F_X509_LOAD_CERT_FILE,X509_R_BAD_X509_FILETYPE); | ||
| 203 | goto err; | ||
| 204 | } | ||
| 205 | err: | ||
| 206 | if (x != NULL) X509_free(x); | ||
| 207 | if (in != NULL) BIO_free(in); | ||
| 208 | return(ret); | ||
| 209 | } | ||
| 210 | |||
| 211 | int X509_load_crl_file(ctx,file,type) | ||
| 212 | X509_LOOKUP *ctx; | ||
| 213 | char *file; | ||
| 214 | int type; | ||
| 215 | { | ||
| 216 | int ret=0; | ||
| 217 | BIO *in=NULL; | ||
| 218 | int i,count=0; | ||
| 219 | X509_CRL *x=NULL; | ||
| 220 | |||
| 221 | if (file == NULL) return(1); | ||
| 222 | in=BIO_new(BIO_s_file_internal()); | ||
| 223 | |||
| 224 | if ((in == NULL) || (BIO_read_filename(in,file) <= 0)) | ||
| 225 | { | ||
| 226 | X509err(X509_F_X509_LOAD_CRL_FILE,ERR_R_SYS_LIB); | ||
| 227 | goto err; | ||
| 228 | } | ||
| 229 | |||
| 230 | if (type == X509_FILETYPE_PEM) | ||
| 231 | { | ||
| 232 | for (;;) | ||
| 233 | { | ||
| 234 | x=PEM_read_bio_X509_CRL(in,NULL,NULL); | ||
| 235 | if (x == NULL) | ||
| 236 | { | ||
| 237 | if ((ERR_GET_REASON(ERR_peek_error()) == | ||
| 238 | PEM_R_NO_START_LINE) && (count > 0)) | ||
| 239 | { | ||
| 240 | ERR_clear_error(); | ||
| 241 | break; | ||
| 242 | } | ||
| 243 | else | ||
| 244 | { | ||
| 245 | X509err(X509_F_X509_LOAD_CRL_FILE, | ||
| 246 | ERR_R_PEM_LIB); | ||
| 247 | goto err; | ||
| 248 | } | ||
| 249 | } | ||
| 250 | i=X509_STORE_add_crl(ctx->store_ctx,x); | ||
| 251 | if (!i) goto err; | ||
| 252 | count++; | ||
| 253 | X509_CRL_free(x); | ||
| 254 | x=NULL; | ||
| 255 | } | ||
| 256 | ret=count; | ||
| 257 | } | ||
| 258 | else if (type == X509_FILETYPE_ASN1) | ||
| 259 | { | ||
| 260 | x=d2i_X509_CRL_bio(in,NULL); | ||
| 261 | if (x == NULL) | ||
| 262 | { | ||
| 263 | X509err(X509_F_X509_LOAD_CRL_FILE,ERR_R_ASN1_LIB); | ||
| 264 | goto err; | ||
| 265 | } | ||
| 266 | i=X509_STORE_add_crl(ctx->store_ctx,x); | ||
| 267 | if (!i) goto err; | ||
| 268 | ret=i; | ||
| 269 | } | ||
| 270 | else | ||
| 271 | { | ||
| 272 | X509err(X509_F_X509_LOAD_CRL_FILE,X509_R_BAD_X509_FILETYPE); | ||
| 273 | goto err; | ||
| 274 | } | ||
| 275 | err: | ||
| 276 | if (x != NULL) X509_CRL_free(x); | ||
| 277 | if (in != NULL) BIO_free(in); | ||
| 278 | return(ret); | ||
| 279 | } | ||
| 280 | |||
| 281 | #endif /* NO_STDIO */ | ||
| 282 | |||
diff --git a/src/lib/libcrypto/x509/x509.h b/src/lib/libcrypto/x509/x509.h new file mode 100644 index 0000000000..95114f7c43 --- /dev/null +++ b/src/lib/libcrypto/x509/x509.h | |||
| @@ -0,0 +1,1152 @@ | |||
| 1 | /* crypto/x509/x509.h */ | ||
| 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 | #ifndef HEADER_X509_H | ||
| 60 | #define HEADER_X509_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #include "stack.h" | ||
| 67 | #include "asn1.h" | ||
| 68 | |||
| 69 | #ifndef NO_RSA | ||
| 70 | #include "rsa.h" | ||
| 71 | #else | ||
| 72 | #define RSA long | ||
| 73 | #endif | ||
| 74 | |||
| 75 | #ifndef NO_DSA | ||
| 76 | #include "dsa.h" | ||
| 77 | #else | ||
| 78 | #define DSA long | ||
| 79 | #endif | ||
| 80 | |||
| 81 | #ifndef NO_DH | ||
| 82 | #include "dh.h" | ||
| 83 | #else | ||
| 84 | #define DH long | ||
| 85 | #endif | ||
| 86 | |||
| 87 | #include "evp.h" | ||
| 88 | |||
| 89 | #define X509_FILETYPE_PEM 1 | ||
| 90 | #define X509_FILETYPE_ASN1 2 | ||
| 91 | #define X509_FILETYPE_DEFAULT 3 | ||
| 92 | |||
| 93 | #define X509v3_KU_DIGITAL_SIGNATURE 0x0080 | ||
| 94 | #define X509v3_KU_NON_REPUDIATION 0x0040 | ||
| 95 | #define X509v3_KU_KEY_ENCIPHERMENT 0x0020 | ||
| 96 | #define X509v3_KU_DATA_ENCIPHERMENT 0x0010 | ||
| 97 | #define X509v3_KU_KEY_AGREEMENT 0x0008 | ||
| 98 | #define X509v3_KU_KEY_CERT_SIGN 0x0004 | ||
| 99 | #define X509v3_KU_CRL_SIGN 0x0002 | ||
| 100 | #define X509v3_KU_ENCIPHER_ONLY 0x0001 | ||
| 101 | #define X509v3_KU_DECIPHER_ONLY 0x8000 | ||
| 102 | #define X509v3_KU_UNDEF 0xffff | ||
| 103 | |||
| 104 | typedef struct X509_objects_st | ||
| 105 | { | ||
| 106 | int nid; | ||
| 107 | int (*a2i)(); | ||
| 108 | int (*i2a)(); | ||
| 109 | } X509_OBJECTS; | ||
| 110 | |||
| 111 | typedef struct X509_algor_st | ||
| 112 | { | ||
| 113 | ASN1_OBJECT *algorithm; | ||
| 114 | ASN1_TYPE *parameter; | ||
| 115 | } X509_ALGOR; | ||
| 116 | |||
| 117 | typedef struct X509_val_st | ||
| 118 | { | ||
| 119 | ASN1_UTCTIME *notBefore; | ||
| 120 | ASN1_UTCTIME *notAfter; | ||
| 121 | } X509_VAL; | ||
| 122 | |||
| 123 | typedef struct X509_pubkey_st | ||
| 124 | { | ||
| 125 | X509_ALGOR *algor; | ||
| 126 | ASN1_BIT_STRING *public_key; | ||
| 127 | struct evp_pkey_st /* EVP_PKEY*/ *pkey; | ||
| 128 | } X509_PUBKEY; | ||
| 129 | |||
| 130 | typedef struct X509_sig_st | ||
| 131 | { | ||
| 132 | X509_ALGOR *algor; | ||
| 133 | ASN1_OCTET_STRING *digest; | ||
| 134 | } X509_SIG; | ||
| 135 | |||
| 136 | typedef struct X509_name_entry_st | ||
| 137 | { | ||
| 138 | ASN1_OBJECT *object; | ||
| 139 | ASN1_STRING *value; | ||
| 140 | int set; | ||
| 141 | int size; /* temp variable */ | ||
| 142 | } X509_NAME_ENTRY; | ||
| 143 | |||
| 144 | /* we always keep X509_NAMEs in 2 forms. */ | ||
| 145 | typedef struct X509_name_st | ||
| 146 | { | ||
| 147 | STACK *entries; /* of X509_NAME_ENTRY */ | ||
| 148 | int modified; /* true if 'bytes' needs to be built */ | ||
| 149 | #ifdef HEADER_BUFFER_H | ||
| 150 | BUF_MEM *bytes; | ||
| 151 | #else | ||
| 152 | char *bytes; | ||
| 153 | #endif | ||
| 154 | unsigned long hash; /* Keep the hash around for lookups */ | ||
| 155 | } X509_NAME; | ||
| 156 | |||
| 157 | #define X509_EX_V_NETSCAPE_HACK 0x8000 | ||
| 158 | #define X509_EX_V_INIT 0x0001 | ||
| 159 | typedef struct X509_extension_st | ||
| 160 | { | ||
| 161 | ASN1_OBJECT *object; | ||
| 162 | short critical; | ||
| 163 | short netscape_hack; | ||
| 164 | ASN1_OCTET_STRING *value; | ||
| 165 | long argl; /* used when decoding */ | ||
| 166 | char *argp; /* used when decoding */ | ||
| 167 | void (*ex_free)(); /* clear argp stuff */ | ||
| 168 | } X509_EXTENSION; | ||
| 169 | |||
| 170 | /* #if 1 */ | ||
| 171 | typedef struct x509_extension_method_st | ||
| 172 | { | ||
| 173 | int nid; | ||
| 174 | int data_type; | ||
| 175 | int pack_type; | ||
| 176 | void (*ex_clear)(); | ||
| 177 | int (*ex_get_bool)(); | ||
| 178 | int (*ex_set_bool)(); | ||
| 179 | int (*ex_get_str)(); | ||
| 180 | int (*ex_set_str)(); | ||
| 181 | char *(*ex_get_struct)(); | ||
| 182 | int (*ex_set_struct)(); | ||
| 183 | int (*a2i)(); | ||
| 184 | int (*i2a)(); | ||
| 185 | } X509_EXTENSION_METHOD; | ||
| 186 | /* #endif */ | ||
| 187 | |||
| 188 | typedef struct X509_req_info_st | ||
| 189 | { | ||
| 190 | ASN1_INTEGER *version; | ||
| 191 | X509_NAME *subject; | ||
| 192 | X509_PUBKEY *pubkey; | ||
| 193 | /* d=2 hl=2 l= 0 cons: cont: 00 */ | ||
| 194 | STACK /* X509_ATTRIBUTE */ *attributes; /* [ 0 ] */ | ||
| 195 | int req_kludge; | ||
| 196 | } X509_REQ_INFO; | ||
| 197 | |||
| 198 | typedef struct X509_req_st | ||
| 199 | { | ||
| 200 | X509_REQ_INFO *req_info; | ||
| 201 | X509_ALGOR *sig_alg; | ||
| 202 | ASN1_BIT_STRING *signature; | ||
| 203 | int references; | ||
| 204 | } X509_REQ; | ||
| 205 | |||
| 206 | typedef struct x509_cinf_st | ||
| 207 | { | ||
| 208 | ASN1_INTEGER *version; /* [ 0 ] default of v1 */ | ||
| 209 | ASN1_INTEGER *serialNumber; | ||
| 210 | X509_ALGOR *signature; | ||
| 211 | X509_NAME *issuer; | ||
| 212 | X509_VAL *validity; | ||
| 213 | X509_NAME *subject; | ||
| 214 | X509_PUBKEY *key; | ||
| 215 | ASN1_BIT_STRING *issuerUID; /* [ 1 ] optional in v2 */ | ||
| 216 | ASN1_BIT_STRING *subjectUID; /* [ 2 ] optional in v2 */ | ||
| 217 | STACK /* X509_EXTENSION */ *extensions; /* [ 3 ] optional in v3 */ | ||
| 218 | } X509_CINF; | ||
| 219 | |||
| 220 | typedef struct x509_st | ||
| 221 | { | ||
| 222 | X509_CINF *cert_info; | ||
| 223 | X509_ALGOR *sig_alg; | ||
| 224 | ASN1_BIT_STRING *signature; | ||
| 225 | int valid; | ||
| 226 | int references; | ||
| 227 | char *name; | ||
| 228 | } X509; | ||
| 229 | |||
| 230 | typedef struct X509_revoked_st | ||
| 231 | { | ||
| 232 | ASN1_INTEGER *serialNumber; | ||
| 233 | ASN1_UTCTIME *revocationDate; | ||
| 234 | STACK /* optional X509_EXTENSION */ *extensions; | ||
| 235 | int sequence; /* load sequence */ | ||
| 236 | } X509_REVOKED; | ||
| 237 | |||
| 238 | typedef struct X509_crl_info_st | ||
| 239 | { | ||
| 240 | ASN1_INTEGER *version; | ||
| 241 | X509_ALGOR *sig_alg; | ||
| 242 | X509_NAME *issuer; | ||
| 243 | ASN1_UTCTIME *lastUpdate; | ||
| 244 | ASN1_UTCTIME *nextUpdate; | ||
| 245 | STACK /* X509_REVOKED */ *revoked; | ||
| 246 | STACK /* [0] X509_EXTENSION */ *extensions; | ||
| 247 | } X509_CRL_INFO; | ||
| 248 | |||
| 249 | typedef struct X509_crl_st | ||
| 250 | { | ||
| 251 | /* actual signature */ | ||
| 252 | X509_CRL_INFO *crl; | ||
| 253 | X509_ALGOR *sig_alg; | ||
| 254 | ASN1_BIT_STRING *signature; | ||
| 255 | int references; | ||
| 256 | } X509_CRL; | ||
| 257 | |||
| 258 | /* a sequence of these are used */ | ||
| 259 | typedef struct x509_attributes_st | ||
| 260 | { | ||
| 261 | ASN1_OBJECT *object; | ||
| 262 | int set; /* 1 for a set, 0 for a single item (which is wrong) */ | ||
| 263 | union { | ||
| 264 | char *ptr; | ||
| 265 | /* 1 */ STACK /* ASN1_TYPE */ *set; | ||
| 266 | /* 0 */ ASN1_TYPE *single; | ||
| 267 | } value; | ||
| 268 | } X509_ATTRIBUTE; | ||
| 269 | |||
| 270 | typedef struct private_key_st | ||
| 271 | { | ||
| 272 | int version; | ||
| 273 | /* The PKCS#8 data types */ | ||
| 274 | X509_ALGOR *enc_algor; | ||
| 275 | ASN1_OCTET_STRING *enc_pkey; /* encrypted pub key */ | ||
| 276 | |||
| 277 | /* When decrypted, the following will not be NULL */ | ||
| 278 | EVP_PKEY *dec_pkey; | ||
| 279 | |||
| 280 | /* used to encrypt and decrypt */ | ||
| 281 | int key_length; | ||
| 282 | char *key_data; | ||
| 283 | int key_free; /* true if we should auto free key_data */ | ||
| 284 | |||
| 285 | /* expanded version of 'enc_algor' */ | ||
| 286 | EVP_CIPHER_INFO cipher; | ||
| 287 | |||
| 288 | int references; | ||
| 289 | } X509_PKEY; | ||
| 290 | |||
| 291 | #ifdef HEADER_ENVELOPE_H | ||
| 292 | typedef struct X509_info_st | ||
| 293 | { | ||
| 294 | X509 *x509; | ||
| 295 | X509_CRL *crl; | ||
| 296 | X509_PKEY *x_pkey; | ||
| 297 | |||
| 298 | EVP_CIPHER_INFO enc_cipher; | ||
| 299 | int enc_len; | ||
| 300 | char *enc_data; | ||
| 301 | |||
| 302 | int references; | ||
| 303 | } X509_INFO; | ||
| 304 | #endif | ||
| 305 | |||
| 306 | /* The next 2 structures and their 8 routines were sent to me by | ||
| 307 | * Pat Richard <patr@x509.com> and are used to manipulate | ||
| 308 | * Netscapes spki strucutres - usefull if you are writing a CA web page | ||
| 309 | */ | ||
| 310 | typedef struct Netscape_spkac_st | ||
| 311 | { | ||
| 312 | X509_PUBKEY *pubkey; | ||
| 313 | ASN1_IA5STRING *challenge; /* challenge sent in atlas >= PR2 */ | ||
| 314 | } NETSCAPE_SPKAC; | ||
| 315 | |||
| 316 | typedef struct Netscape_spki_st | ||
| 317 | { | ||
| 318 | NETSCAPE_SPKAC *spkac; /* signed public key and challenge */ | ||
| 319 | X509_ALGOR *sig_algor; | ||
| 320 | ASN1_BIT_STRING *signature; | ||
| 321 | } NETSCAPE_SPKI; | ||
| 322 | |||
| 323 | #ifndef HEADER_BN_H | ||
| 324 | #define BIGNUM char | ||
| 325 | #endif | ||
| 326 | |||
| 327 | typedef struct CBCParameter_st | ||
| 328 | { | ||
| 329 | unsigned char iv[8]; | ||
| 330 | } CBC_PARAM; | ||
| 331 | |||
| 332 | #include "x509_vfy.h" | ||
| 333 | #include "pkcs7.h" | ||
| 334 | |||
| 335 | #ifdef SSLEAY_MACROS | ||
| 336 | #define X509_verify(a,r) ASN1_verify((int (*)())i2d_X509_CINF,a->sig_alg,\ | ||
| 337 | a->signature,(char *)a->cert_info,r) | ||
| 338 | #define X509_REQ_verify(a,r) ASN1_verify((int (*)())i2d_X509_REQ_INFO, \ | ||
| 339 | a->sig_alg,a->signature,(char *)a->req_info,r) | ||
| 340 | #define X509_CRL_verify(a,r) ASN1_verify((int (*)())i2d_X509_CRL_INFO, \ | ||
| 341 | a->sig_alg, a->signature,(char *)a->crl,r) | ||
| 342 | |||
| 343 | #define X509_sign(x,pkey,md) \ | ||
| 344 | ASN1_sign((int (*)())i2d_X509_CINF, x->cert_info->signature, \ | ||
| 345 | x->sig_alg, x->signature, (char *)x->cert_info,pkey,md) | ||
| 346 | #define X509_REQ_sign(x,pkey,md) \ | ||
| 347 | ASN1_sign((int (*)())i2d_X509_REQ_INFO,x->sig_alg, NULL, \ | ||
| 348 | x->signature, (char *)x->req_info,pkey,md) | ||
| 349 | #define X509_CRL_sign(x,pkey,md) \ | ||
| 350 | ASN1_sign((int (*)())i2d_X509_CRL_INFO,x->crl->sig_alg,x->sig_alg, \ | ||
| 351 | x->signature, (char *)x->crl,pkey,md) | ||
| 352 | #define NETSCAPE_SPKI_sign(x,pkey,md) \ | ||
| 353 | ASN1_sign((int (*)())i2d_NETSCAPE_SPKAC, x->sig_algor,NULL, \ | ||
| 354 | x->signature, (char *)x->spkac,pkey,md) | ||
| 355 | |||
| 356 | #define X509_dup(x509) (X509 *)ASN1_dup((int (*)())i2d_X509, \ | ||
| 357 | (char *(*)())d2i_X509,(char *)x509) | ||
| 358 | #define X509_EXTENSION_dup(ex) (X509_EXTENSION *)ASN1_dup( \ | ||
| 359 | (int (*)())i2d_X509_EXTENSION, \ | ||
| 360 | (char *(*)())d2i_X509_EXTENSION,(char *)ex) | ||
| 361 | #define d2i_X509_fp(fp,x509) (X509 *)ASN1_d2i_fp((char *(*)())X509_new, \ | ||
| 362 | (char *(*)())d2i_X509, (fp),(unsigned char **)(x509)) | ||
| 363 | #define i2d_X509_fp(fp,x509) ASN1_i2d_fp(i2d_X509,fp,(unsigned char *)x509) | ||
| 364 | #define d2i_X509_bio(bp,x509) (X509 *)ASN1_d2i_bio((char *(*)())X509_new, \ | ||
| 365 | (char *(*)())d2i_X509, (bp),(unsigned char **)(x509)) | ||
| 366 | #define i2d_X509_bio(bp,x509) ASN1_i2d_bio(i2d_X509,bp,(unsigned char *)x509) | ||
| 367 | |||
| 368 | #define X509_CRL_dup(crl) (X509_CRL *)ASN1_dup((int (*)())i2d_X509_CRL, \ | ||
| 369 | (char *(*)())d2i_X509_CRL,(char *)crl) | ||
| 370 | #define d2i_X509_CRL_fp(fp,crl) (X509_CRL *)ASN1_d2i_fp((char *(*)()) \ | ||
| 371 | X509_CRL_new,(char *(*)())d2i_X509_CRL, (fp),\ | ||
| 372 | (unsigned char **)(crl)) | ||
| 373 | #define i2d_X509_CRL_fp(fp,crl) ASN1_i2d_fp(i2d_X509_CRL,fp,\ | ||
| 374 | (unsigned char *)crl) | ||
| 375 | #define d2i_X509_CRL_bio(bp,crl) (X509_CRL *)ASN1_d2i_bio((char *(*)()) \ | ||
| 376 | X509_CRL_new,(char *(*)())d2i_X509_CRL, (bp),\ | ||
| 377 | (unsigned char **)(crl)) | ||
| 378 | #define i2d_X509_CRL_bio(bp,crl) ASN1_i2d_bio(i2d_X509_CRL,bp,\ | ||
| 379 | (unsigned char *)crl) | ||
| 380 | |||
| 381 | #define PKCS7_dup(p7) (PKCS7 *)ASN1_dup((int (*)())i2d_PKCS7, \ | ||
| 382 | (char *(*)())d2i_PKCS7,(char *)p7) | ||
| 383 | #define d2i_PKCS7_fp(fp,p7) (PKCS7 *)ASN1_d2i_fp((char *(*)()) \ | ||
| 384 | PKCS7_new,(char *(*)())d2i_PKCS7, (fp),\ | ||
| 385 | (unsigned char **)(p7)) | ||
| 386 | #define i2d_PKCS7_fp(fp,p7) ASN1_i2d_fp(i2d_PKCS7,fp,\ | ||
| 387 | (unsigned char *)p7) | ||
| 388 | #define d2i_PKCS7_bio(bp,p7) (PKCS7 *)ASN1_d2i_bio((char *(*)()) \ | ||
| 389 | PKCS7_new,(char *(*)())d2i_PKCS7, (bp),\ | ||
| 390 | (unsigned char **)(p7)) | ||
| 391 | #define i2d_PKCS7_bio(bp,p7) ASN1_i2d_bio(i2d_PKCS7,bp,\ | ||
| 392 | (unsigned char *)p7) | ||
| 393 | |||
| 394 | #define X509_REQ_dup(req) (X509_REQ *)ASN1_dup((int (*)())i2d_X509_REQ, \ | ||
| 395 | (char *(*)())d2i_X509_REQ,(char *)req) | ||
| 396 | #define d2i_X509_REQ_fp(fp,req) (X509_REQ *)ASN1_d2i_fp((char *(*)())\ | ||
| 397 | X509_REQ_new, (char *(*)())d2i_X509_REQ, (fp),\ | ||
| 398 | (unsigned char **)(req)) | ||
| 399 | #define i2d_X509_REQ_fp(fp,req) ASN1_i2d_fp(i2d_X509_REQ,fp,\ | ||
| 400 | (unsigned char *)req) | ||
| 401 | #define d2i_X509_REQ_bio(bp,req) (X509_REQ *)ASN1_d2i_bio((char *(*)())\ | ||
| 402 | X509_REQ_new, (char *(*)())d2i_X509_REQ, (bp),\ | ||
| 403 | (unsigned char **)(req)) | ||
| 404 | #define i2d_X509_REQ_bio(bp,req) ASN1_i2d_bio(i2d_X509_REQ,bp,\ | ||
| 405 | (unsigned char *)req) | ||
| 406 | |||
| 407 | #define RSAPublicKey_dup(rsa) (RSA *)ASN1_dup((int (*)())i2d_RSAPublicKey, \ | ||
| 408 | (char *(*)())d2i_RSAPublicKey,(char *)rsa) | ||
| 409 | #define RSAPrivateKey_dup(rsa) (RSA *)ASN1_dup((int (*)())i2d_RSAPrivateKey, \ | ||
| 410 | (char *(*)())d2i_RSAPrivateKey,(char *)rsa) | ||
| 411 | |||
| 412 | #define d2i_RSAPrivateKey_fp(fp,rsa) (RSA *)ASN1_d2i_fp((char *(*)())\ | ||
| 413 | RSA_new,(char *(*)())d2i_RSAPrivateKey, (fp), \ | ||
| 414 | (unsigned char **)(rsa)) | ||
| 415 | #define i2d_RSAPrivateKey_fp(fp,rsa) ASN1_i2d_fp(i2d_RSAPrivateKey,fp, \ | ||
| 416 | (unsigned char *)rsa) | ||
| 417 | #define d2i_RSAPrivateKey_bio(bp,rsa) (RSA *)ASN1_d2i_bio((char *(*)())\ | ||
| 418 | RSA_new,(char *(*)())d2i_RSAPrivateKey, (bp), \ | ||
| 419 | (unsigned char **)(rsa)) | ||
| 420 | #define i2d_RSAPrivateKey_bio(bp,rsa) ASN1_i2d_bio(i2d_RSAPrivateKey,bp, \ | ||
| 421 | (unsigned char *)rsa) | ||
| 422 | |||
| 423 | #define d2i_RSAPublicKey_fp(fp,rsa) (RSA *)ASN1_d2i_fp((char *(*)())\ | ||
| 424 | RSA_new,(char *(*)())d2i_RSAPublicKey, (fp), \ | ||
| 425 | (unsigned char **)(rsa)) | ||
| 426 | #define i2d_RSAPublicKey_fp(fp,rsa) ASN1_i2d_fp(i2d_RSAPublicKey,fp, \ | ||
| 427 | (unsigned char *)rsa) | ||
| 428 | #define d2i_RSAPublicKey_bio(bp,rsa) (RSA *)ASN1_d2i_bio((char *(*)())\ | ||
| 429 | RSA_new,(char *(*)())d2i_RSAPublicKey, (bp), \ | ||
| 430 | (unsigned char **)(rsa)) | ||
| 431 | #define i2d_RSAPublicKey_bio(bp,rsa) ASN1_i2d_bio(i2d_RSAPublicKey,bp, \ | ||
| 432 | (unsigned char *)rsa) | ||
| 433 | |||
| 434 | #define d2i_DSAPrivateKey_fp(fp,dsa) (DSA *)ASN1_d2i_fp((char *(*)())\ | ||
| 435 | DSA_new,(char *(*)())d2i_DSAPrivateKey, (fp), \ | ||
| 436 | (unsigned char **)(dsa)) | ||
| 437 | #define i2d_DSAPrivateKey_fp(fp,dsa) ASN1_i2d_fp(i2d_DSAPrivateKey,fp, \ | ||
| 438 | (unsigned char *)dsa) | ||
| 439 | #define d2i_DSAPrivateKey_bio(bp,dsa) (DSA *)ASN1_d2i_bio((char *(*)())\ | ||
| 440 | DSA_new,(char *(*)())d2i_DSAPrivateKey, (bp), \ | ||
| 441 | (unsigned char **)(dsa)) | ||
| 442 | #define i2d_DSAPrivateKey_bio(bp,dsa) ASN1_i2d_bio(i2d_DSAPrivateKey,bp, \ | ||
| 443 | (unsigned char *)dsa) | ||
| 444 | |||
| 445 | #define X509_NAME_dup(xn) (X509_NAME *)ASN1_dup((int (*)())i2d_X509_NAME, \ | ||
| 446 | (char *(*)())d2i_X509_NAME,(char *)xn) | ||
| 447 | #define X509_NAME_ENTRY_dup(ne) (X509_NAME_ENTRY *)ASN1_dup( \ | ||
| 448 | (int (*)())i2d_X509_NAME_ENTRY, \ | ||
| 449 | (char *(*)())d2i_X509_NAME_ENTRY,\ | ||
| 450 | (char *)ne) | ||
| 451 | |||
| 452 | #define X509_digest(data,type,md,len) \ | ||
| 453 | ASN1_digest((int (*)())i2d_X509,type,(char *)data,md,len) | ||
| 454 | #define X509_NAME_digest(data,type,md,len) \ | ||
| 455 | ASN1_digest((int (*)())i2d_X509_NAME,type,(char *)data,md,len) | ||
| 456 | #define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \ | ||
| 457 | ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\ | ||
| 458 | (char *)data,md,len) | ||
| 459 | #endif | ||
| 460 | |||
| 461 | #define X509_EXT_PACK_UNKNOWN 1 | ||
| 462 | #define X509_EXT_PACK_STRING 2 | ||
| 463 | |||
| 464 | #define X509_get_version(x) ASN1_INTEGER_get((x)->cert_info->version) | ||
| 465 | /* #define X509_get_serialNumber(x) ((x)->cert_info->serialNumber) */ | ||
| 466 | #define X509_get_notBefore(x) ((x)->cert_info->validity->notBefore) | ||
| 467 | #define X509_get_notAfter(x) ((x)->cert_info->validity->notAfter) | ||
| 468 | #define X509_extract_key(x) X509_get_pubkey(x) /*****/ | ||
| 469 | #define X509_REQ_get_version(x) ASN1_INTEGER_get((x)->req_info->version) | ||
| 470 | #define X509_REQ_get_subject_name(x) ((x)->req_info->subject) | ||
| 471 | #define X509_REQ_extract_key(a) X509_REQ_get_pubkey(a) | ||
| 472 | #define X509_name_cmp(a,b) X509_NAME_cmp((a),(b)) | ||
| 473 | #define X509_get_signature_type(x) EVP_PKEY_type(OBJ_obj2nid((x)->sig_alg->algorithm)) | ||
| 474 | |||
| 475 | /* This one is only used so that a binary form can output, as in | ||
| 476 | * i2d_X509_NAME(X509_get_X509_PUBKEY(x),&buf) */ | ||
| 477 | #define X509_get_X509_PUBKEY(x) ((x)->cert_info->key) | ||
| 478 | |||
| 479 | #ifndef NOPROTO | ||
| 480 | |||
| 481 | #ifndef SSLEAY_MACROS | ||
| 482 | #ifdef HEADER_ENVELOPE_H | ||
| 483 | int X509_verify(X509 *a, EVP_PKEY *r); | ||
| 484 | char *X509_verify_cert_error_string(long n); | ||
| 485 | |||
| 486 | int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r); | ||
| 487 | int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r); | ||
| 488 | int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r); | ||
| 489 | |||
| 490 | int X509_sign(X509 *x, EVP_PKEY *pkey, EVP_MD *md); | ||
| 491 | int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, EVP_MD *md); | ||
| 492 | int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, EVP_MD *md); | ||
| 493 | int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, EVP_MD *md); | ||
| 494 | |||
| 495 | int X509_digest(X509 *data,EVP_MD *type,unsigned char *md,unsigned int *len); | ||
| 496 | int X509_NAME_digest(X509_NAME *data,EVP_MD *type, | ||
| 497 | unsigned char *md,unsigned int *len); | ||
| 498 | #endif | ||
| 499 | |||
| 500 | #ifndef NO_FP_API | ||
| 501 | X509 *d2i_X509_fp(FILE *fp, X509 *x509); | ||
| 502 | int i2d_X509_fp(FILE *fp,X509 *x509); | ||
| 503 | X509_CRL *d2i_X509_CRL_fp(FILE *fp,X509_CRL *crl); | ||
| 504 | int i2d_X509_CRL_fp(FILE *fp,X509_CRL *crl); | ||
| 505 | X509_REQ *d2i_X509_REQ_fp(FILE *fp,X509_REQ *req); | ||
| 506 | int i2d_X509_REQ_fp(FILE *fp,X509_REQ *req); | ||
| 507 | RSA *d2i_RSAPrivateKey_fp(FILE *fp,RSA *rsa); | ||
| 508 | int i2d_RSAPrivateKey_fp(FILE *fp,RSA *rsa); | ||
| 509 | DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA *dsa); | ||
| 510 | int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa); | ||
| 511 | RSA *d2i_RSAPublicKey_fp(FILE *fp,RSA *rsa); | ||
| 512 | int i2d_RSAPublicKey_fp(FILE *fp,RSA *rsa); | ||
| 513 | #endif | ||
| 514 | |||
| 515 | #ifdef HEADER_BIO_H | ||
| 516 | X509 *d2i_X509_bio(BIO *bp,X509 *x509); | ||
| 517 | int i2d_X509_bio(BIO *bp,X509 *x509); | ||
| 518 | X509_CRL *d2i_X509_CRL_bio(BIO *bp,X509_CRL *crl); | ||
| 519 | int i2d_X509_CRL_bio(BIO *bp,X509_CRL *crl); | ||
| 520 | X509_REQ *d2i_X509_REQ_bio(BIO *bp,X509_REQ *req); | ||
| 521 | int i2d_X509_REQ_bio(BIO *bp,X509_REQ *req); | ||
| 522 | RSA *d2i_RSAPrivateKey_bio(BIO *bp,RSA *rsa); | ||
| 523 | int i2d_RSAPrivateKey_bio(BIO *bp,RSA *rsa); | ||
| 524 | DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA *dsa); | ||
| 525 | int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa); | ||
| 526 | RSA *d2i_RSAPublicKey_bio(BIO *bp,RSA *rsa); | ||
| 527 | int i2d_RSAPublicKey_bio(BIO *bp,RSA *rsa); | ||
| 528 | #endif | ||
| 529 | |||
| 530 | X509 *X509_dup(X509 *x509); | ||
| 531 | X509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex); | ||
| 532 | X509_CRL *X509_CRL_dup(X509_CRL *crl); | ||
| 533 | X509_REQ *X509_REQ_dup(X509_REQ *req); | ||
| 534 | X509_NAME *X509_NAME_dup(X509_NAME *xn); | ||
| 535 | X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne); | ||
| 536 | RSA *RSAPublicKey_dup(RSA *rsa); | ||
| 537 | RSA *RSAPrivateKey_dup(RSA *rsa); | ||
| 538 | |||
| 539 | #endif /* !SSLEAY_MACROS */ | ||
| 540 | |||
| 541 | int X509_cmp_current_time(ASN1_UTCTIME *s); | ||
| 542 | ASN1_UTCTIME * X509_gmtime_adj(ASN1_UTCTIME *s, long adj); | ||
| 543 | |||
| 544 | char * X509_get_default_cert_area(void ); | ||
| 545 | char * X509_get_default_cert_dir(void ); | ||
| 546 | char * X509_get_default_cert_file(void ); | ||
| 547 | char * X509_get_default_cert_dir_env(void ); | ||
| 548 | char * X509_get_default_cert_file_env(void ); | ||
| 549 | char * X509_get_default_private_dir(void ); | ||
| 550 | |||
| 551 | X509_REQ * X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, EVP_MD *md); | ||
| 552 | X509 * X509_REQ_to_X509(X509_REQ *r, int days,EVP_PKEY *pkey); | ||
| 553 | void ERR_load_X509_strings(void ); | ||
| 554 | |||
| 555 | X509_ALGOR * X509_ALGOR_new(void ); | ||
| 556 | void X509_ALGOR_free(X509_ALGOR *a); | ||
| 557 | int i2d_X509_ALGOR(X509_ALGOR *a,unsigned char **pp); | ||
| 558 | X509_ALGOR * d2i_X509_ALGOR(X509_ALGOR **a,unsigned char **pp, | ||
| 559 | long length); | ||
| 560 | |||
| 561 | X509_VAL * X509_VAL_new(void ); | ||
| 562 | void X509_VAL_free(X509_VAL *a); | ||
| 563 | int i2d_X509_VAL(X509_VAL *a,unsigned char **pp); | ||
| 564 | X509_VAL * d2i_X509_VAL(X509_VAL **a,unsigned char **pp, | ||
| 565 | long length); | ||
| 566 | |||
| 567 | X509_PUBKEY * X509_PUBKEY_new(void ); | ||
| 568 | void X509_PUBKEY_free(X509_PUBKEY *a); | ||
| 569 | int i2d_X509_PUBKEY(X509_PUBKEY *a,unsigned char **pp); | ||
| 570 | X509_PUBKEY * d2i_X509_PUBKEY(X509_PUBKEY **a,unsigned char **pp, | ||
| 571 | long length); | ||
| 572 | int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey); | ||
| 573 | EVP_PKEY * X509_PUBKEY_get(X509_PUBKEY *key); | ||
| 574 | int X509_get_pubkey_parameters(EVP_PKEY *pkey, STACK *chain); | ||
| 575 | |||
| 576 | |||
| 577 | X509_SIG * X509_SIG_new(void ); | ||
| 578 | void X509_SIG_free(X509_SIG *a); | ||
| 579 | int i2d_X509_SIG(X509_SIG *a,unsigned char **pp); | ||
| 580 | X509_SIG * d2i_X509_SIG(X509_SIG **a,unsigned char **pp,long length); | ||
| 581 | |||
| 582 | X509_REQ_INFO *X509_REQ_INFO_new(void); | ||
| 583 | void X509_REQ_INFO_free(X509_REQ_INFO *a); | ||
| 584 | int i2d_X509_REQ_INFO(X509_REQ_INFO *a,unsigned char **pp); | ||
| 585 | X509_REQ_INFO *d2i_X509_REQ_INFO(X509_REQ_INFO **a,unsigned char **pp, | ||
| 586 | long length); | ||
| 587 | |||
| 588 | X509_REQ * X509_REQ_new(void); | ||
| 589 | void X509_REQ_free(X509_REQ *a); | ||
| 590 | int i2d_X509_REQ(X509_REQ *a,unsigned char **pp); | ||
| 591 | X509_REQ * d2i_X509_REQ(X509_REQ **a,unsigned char **pp,long length); | ||
| 592 | |||
| 593 | X509_ATTRIBUTE *X509_ATTRIBUTE_new(void ); | ||
| 594 | void X509_ATTRIBUTE_free(X509_ATTRIBUTE *a); | ||
| 595 | int i2d_X509_ATTRIBUTE(X509_ATTRIBUTE *a,unsigned char **pp); | ||
| 596 | X509_ATTRIBUTE *d2i_X509_ATTRIBUTE(X509_ATTRIBUTE **a,unsigned char **pp, | ||
| 597 | long length); | ||
| 598 | |||
| 599 | X509_EXTENSION *X509_EXTENSION_new(void ); | ||
| 600 | void X509_EXTENSION_free(X509_EXTENSION *a); | ||
| 601 | int i2d_X509_EXTENSION(X509_EXTENSION *a,unsigned char **pp); | ||
| 602 | X509_EXTENSION *d2i_X509_EXTENSION(X509_EXTENSION **a,unsigned char **pp, | ||
| 603 | long length); | ||
| 604 | |||
| 605 | X509_NAME_ENTRY *X509_NAME_ENTRY_new(void); | ||
| 606 | void X509_NAME_ENTRY_free(X509_NAME_ENTRY *a); | ||
| 607 | int i2d_X509_NAME_ENTRY(X509_NAME_ENTRY *a,unsigned char **pp); | ||
| 608 | X509_NAME_ENTRY *d2i_X509_NAME_ENTRY(X509_NAME_ENTRY **a,unsigned char **pp, | ||
| 609 | long length); | ||
| 610 | |||
| 611 | X509_NAME * X509_NAME_new(void); | ||
| 612 | void X509_NAME_free(X509_NAME *a); | ||
| 613 | int i2d_X509_NAME(X509_NAME *a,unsigned char **pp); | ||
| 614 | X509_NAME * d2i_X509_NAME(X509_NAME **a,unsigned char **pp,long length); | ||
| 615 | int X509_NAME_set(X509_NAME **xn, X509_NAME *name); | ||
| 616 | |||
| 617 | |||
| 618 | X509_CINF * X509_CINF_new(void); | ||
| 619 | void X509_CINF_free(X509_CINF *a); | ||
| 620 | int i2d_X509_CINF(X509_CINF *a,unsigned char **pp); | ||
| 621 | X509_CINF * d2i_X509_CINF(X509_CINF **a,unsigned char **pp,long length); | ||
| 622 | |||
| 623 | X509 * X509_new(void); | ||
| 624 | void X509_free(X509 *a); | ||
| 625 | int i2d_X509(X509 *a,unsigned char **pp); | ||
| 626 | X509 * d2i_X509(X509 **a,unsigned char **pp,long length); | ||
| 627 | |||
| 628 | X509_REVOKED * X509_REVOKED_new(void); | ||
| 629 | void X509_REVOKED_free(X509_REVOKED *a); | ||
| 630 | int i2d_X509_REVOKED(X509_REVOKED *a,unsigned char **pp); | ||
| 631 | X509_REVOKED * d2i_X509_REVOKED(X509_REVOKED **a,unsigned char **pp,long length); | ||
| 632 | |||
| 633 | X509_CRL_INFO *X509_CRL_INFO_new(void); | ||
| 634 | void X509_CRL_INFO_free(X509_CRL_INFO *a); | ||
| 635 | int i2d_X509_CRL_INFO(X509_CRL_INFO *a,unsigned char **pp); | ||
| 636 | X509_CRL_INFO *d2i_X509_CRL_INFO(X509_CRL_INFO **a,unsigned char **pp, | ||
| 637 | long length); | ||
| 638 | |||
| 639 | X509_CRL * X509_CRL_new(void); | ||
| 640 | void X509_CRL_free(X509_CRL *a); | ||
| 641 | int i2d_X509_CRL(X509_CRL *a,unsigned char **pp); | ||
| 642 | X509_CRL * d2i_X509_CRL(X509_CRL **a,unsigned char **pp,long length); | ||
| 643 | |||
| 644 | X509_PKEY * X509_PKEY_new(void ); | ||
| 645 | void X509_PKEY_free(X509_PKEY *a); | ||
| 646 | int i2d_X509_PKEY(X509_PKEY *a,unsigned char **pp); | ||
| 647 | X509_PKEY * d2i_X509_PKEY(X509_PKEY **a,unsigned char **pp,long length); | ||
| 648 | |||
| 649 | NETSCAPE_SPKI * NETSCAPE_SPKI_new(void ); | ||
| 650 | void NETSCAPE_SPKI_free(NETSCAPE_SPKI *a); | ||
| 651 | int i2d_NETSCAPE_SPKI(NETSCAPE_SPKI *a,unsigned char **pp); | ||
| 652 | NETSCAPE_SPKI * d2i_NETSCAPE_SPKI(NETSCAPE_SPKI **a,unsigned char **pp, | ||
| 653 | long length); | ||
| 654 | |||
| 655 | NETSCAPE_SPKAC *NETSCAPE_SPKAC_new(void ); | ||
| 656 | void NETSCAPE_SPKAC_free(NETSCAPE_SPKAC *a); | ||
| 657 | int i2d_NETSCAPE_SPKAC(NETSCAPE_SPKAC *a,unsigned char **pp); | ||
| 658 | NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC(NETSCAPE_SPKAC **a,unsigned char **pp, | ||
| 659 | long length); | ||
| 660 | |||
| 661 | #ifdef HEADER_ENVELOPE_H | ||
| 662 | X509_INFO * X509_INFO_new(void); | ||
| 663 | void X509_INFO_free(X509_INFO *a); | ||
| 664 | char * X509_NAME_oneline(X509_NAME *a,char *buf,int size); | ||
| 665 | |||
| 666 | int ASN1_verify(int (*i2d)(), X509_ALGOR *algor1, | ||
| 667 | ASN1_BIT_STRING *signature,char *data,EVP_PKEY *pkey); | ||
| 668 | |||
| 669 | int ASN1_digest(int (*i2d)(),EVP_MD *type,char *data, | ||
| 670 | unsigned char *md,unsigned int *len); | ||
| 671 | |||
| 672 | int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2, | ||
| 673 | ASN1_BIT_STRING *signature, | ||
| 674 | char *data,EVP_PKEY *pkey, EVP_MD *type); | ||
| 675 | #endif | ||
| 676 | |||
| 677 | int X509_set_version(X509 *x,long version); | ||
| 678 | int X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial); | ||
| 679 | ASN1_INTEGER * X509_get_serialNumber(X509 *x); | ||
| 680 | int X509_set_issuer_name(X509 *x, X509_NAME *name); | ||
| 681 | X509_NAME * X509_get_issuer_name(X509 *a); | ||
| 682 | int X509_set_subject_name(X509 *x, X509_NAME *name); | ||
| 683 | X509_NAME * X509_get_subject_name(X509 *a); | ||
| 684 | int X509_set_notBefore(X509 *x, ASN1_UTCTIME *tm); | ||
| 685 | int X509_set_notAfter(X509 *x, ASN1_UTCTIME *tm); | ||
| 686 | int X509_set_pubkey(X509 *x, EVP_PKEY *pkey); | ||
| 687 | EVP_PKEY * X509_get_pubkey(X509 *x); | ||
| 688 | int X509_certificate_type(X509 *x,EVP_PKEY *pubkey /* optional */); | ||
| 689 | |||
| 690 | int X509_REQ_set_version(X509_REQ *x,long version); | ||
| 691 | int X509_REQ_set_subject_name(X509_REQ *req,X509_NAME *name); | ||
| 692 | int X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey); | ||
| 693 | EVP_PKEY * X509_REQ_get_pubkey(X509_REQ *req); | ||
| 694 | |||
| 695 | int X509_check_private_key(X509 *x509,EVP_PKEY *pkey); | ||
| 696 | |||
| 697 | int X509_issuer_and_serial_cmp(X509 *a, X509 *b); | ||
| 698 | unsigned long X509_issuer_and_serial_hash(X509 *a); | ||
| 699 | |||
| 700 | int X509_issuer_name_cmp(X509 *a, X509 *b); | ||
| 701 | unsigned long X509_issuer_name_hash(X509 *a); | ||
| 702 | |||
| 703 | int X509_subject_name_cmp(X509 *a,X509 *b); | ||
| 704 | unsigned long X509_subject_name_hash(X509 *x); | ||
| 705 | |||
| 706 | int X509_NAME_cmp (X509_NAME *a, X509_NAME *b); | ||
| 707 | unsigned long X509_NAME_hash(X509_NAME *x); | ||
| 708 | |||
| 709 | int X509_CRL_cmp(X509_CRL *a,X509_CRL *b); | ||
| 710 | #ifndef NO_FP_API | ||
| 711 | int X509_print_fp(FILE *bp,X509 *x); | ||
| 712 | int X509_REQ_print_fp(FILE *bp,X509_REQ *req); | ||
| 713 | #endif | ||
| 714 | |||
| 715 | #ifdef HEADER_BIO_H | ||
| 716 | int X509_NAME_print(BIO *bp, X509_NAME *name, int obase); | ||
| 717 | int X509_print(BIO *bp,X509 *x); | ||
| 718 | int X509_REQ_print(BIO *bp,X509_REQ *req); | ||
| 719 | #endif | ||
| 720 | |||
| 721 | int X509_NAME_entry_count(X509_NAME *name); | ||
| 722 | int X509_NAME_get_text_by_NID(X509_NAME *name, int nid, | ||
| 723 | char *buf,int len); | ||
| 724 | int X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, | ||
| 725 | char *buf,int len); | ||
| 726 | |||
| 727 | /* NOTE: you should be passsing -1, not 0 as lastpos. The functions that use | ||
| 728 | * lastpos, seach after that position on. */ | ||
| 729 | int X509_NAME_get_index_by_NID(X509_NAME *name,int nid,int lastpos); | ||
| 730 | int X509_NAME_get_index_by_OBJ(X509_NAME *name,ASN1_OBJECT *obj, | ||
| 731 | int lastpos); | ||
| 732 | X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc); | ||
| 733 | X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc); | ||
| 734 | int X509_NAME_add_entry(X509_NAME *name,X509_NAME_ENTRY *ne, | ||
| 735 | int loc, int set); | ||
| 736 | X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid, | ||
| 737 | int type,unsigned char *bytes, int len); | ||
| 738 | X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne, | ||
| 739 | ASN1_OBJECT *obj, int type,unsigned char *bytes, | ||
| 740 | int len); | ||
| 741 | int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, | ||
| 742 | ASN1_OBJECT *obj); | ||
| 743 | int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type, | ||
| 744 | unsigned char *bytes, int len); | ||
| 745 | ASN1_OBJECT * X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne); | ||
| 746 | ASN1_STRING * X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne); | ||
| 747 | |||
| 748 | int X509v3_get_ext_count(STACK *x); | ||
| 749 | int X509v3_get_ext_by_NID(STACK *x, int nid, int lastpos); | ||
| 750 | int X509v3_get_ext_by_OBJ(STACK *x,ASN1_OBJECT *obj,int lastpos); | ||
| 751 | int X509v3_get_ext_by_critical(STACK *x, int crit, int lastpos); | ||
| 752 | X509_EXTENSION *X509v3_get_ext(STACK *x, int loc); | ||
| 753 | X509_EXTENSION *X509v3_delete_ext(STACK *x, int loc); | ||
| 754 | STACK * X509v3_add_ext(STACK **x, X509_EXTENSION *ex, int loc); | ||
| 755 | |||
| 756 | int X509v3_data_type_by_OBJ(ASN1_OBJECT *obj); | ||
| 757 | int X509v3_data_type_by_NID(int nid); | ||
| 758 | int X509v3_pack_type_by_OBJ(ASN1_OBJECT *obj); | ||
| 759 | int X509v3_pack_type_by_NID(int nid); | ||
| 760 | |||
| 761 | int X509_get_ext_count(X509 *x); | ||
| 762 | int X509_get_ext_by_NID(X509 *x, int nid, int lastpos); | ||
| 763 | int X509_get_ext_by_OBJ(X509 *x,ASN1_OBJECT *obj,int lastpos); | ||
| 764 | int X509_get_ext_by_critical(X509 *x, int crit, int lastpos); | ||
| 765 | X509_EXTENSION *X509_get_ext(X509 *x, int loc); | ||
| 766 | X509_EXTENSION *X509_delete_ext(X509 *x, int loc); | ||
| 767 | int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc); | ||
| 768 | |||
| 769 | int X509_CRL_get_ext_count(X509_CRL *x); | ||
| 770 | int X509_CRL_get_ext_by_NID(X509_CRL *x, int nid, int lastpos); | ||
| 771 | int X509_CRL_get_ext_by_OBJ(X509_CRL *x,ASN1_OBJECT *obj,int lastpos); | ||
| 772 | int X509_CRL_get_ext_by_critical(X509_CRL *x, int crit, int lastpos); | ||
| 773 | X509_EXTENSION *X509_CRL_get_ext(X509_CRL *x, int loc); | ||
| 774 | X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc); | ||
| 775 | int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc); | ||
| 776 | |||
| 777 | int X509_REVOKED_get_ext_count(X509_REVOKED *x); | ||
| 778 | int X509_REVOKED_get_ext_by_NID(X509_REVOKED *x, int nid, int lastpos); | ||
| 779 | int X509_REVOKED_get_ext_by_OBJ(X509_REVOKED *x,ASN1_OBJECT *obj,int lastpos); | ||
| 780 | int X509_REVOKED_get_ext_by_critical(X509_REVOKED *x, int crit, int lastpos); | ||
| 781 | X509_EXTENSION *X509_REVOKED_get_ext(X509_REVOKED *x, int loc); | ||
| 782 | X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc); | ||
| 783 | int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc); | ||
| 784 | |||
| 785 | X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, | ||
| 786 | int nid, int crit, ASN1_OCTET_STRING *data); | ||
| 787 | X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex, | ||
| 788 | ASN1_OBJECT *obj,int crit,ASN1_OCTET_STRING *data); | ||
| 789 | int X509_EXTENSION_set_object(X509_EXTENSION *ex,ASN1_OBJECT *obj); | ||
| 790 | int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit); | ||
| 791 | int X509_EXTENSION_set_data(X509_EXTENSION *ex, | ||
| 792 | ASN1_OCTET_STRING *data); | ||
| 793 | ASN1_OBJECT * X509_EXTENSION_get_object(X509_EXTENSION *ex); | ||
| 794 | ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ne); | ||
| 795 | int X509_EXTENSION_get_critical(X509_EXTENSION *ex); | ||
| 796 | ASN1_OCTET_STRING *X509v3_pack_string(ASN1_OCTET_STRING **ex,int type, | ||
| 797 | unsigned char *bytes, int len); | ||
| 798 | ASN1_STRING * X509v3_unpack_string(ASN1_STRING **ex,int type, | ||
| 799 | ASN1_OCTET_STRING *os); | ||
| 800 | |||
| 801 | int X509_verify_cert(X509_STORE_CTX *ctx); | ||
| 802 | |||
| 803 | /* lookup a cert from a X509 STACK */ | ||
| 804 | X509 *X509_find_by_issuer_and_serial(STACK *sk,X509_NAME *name, | ||
| 805 | ASN1_INTEGER *serial); | ||
| 806 | X509 *X509_find_by_subject(STACK *sk,X509_NAME *name); | ||
| 807 | |||
| 808 | #else | ||
| 809 | |||
| 810 | #ifndef SSLEAY_MACROS | ||
| 811 | #ifdef HEADER_ENVELOPE_H | ||
| 812 | int X509_verify(); | ||
| 813 | int X509_REQ_verify(); | ||
| 814 | int X509_CRL_verify(); | ||
| 815 | int NETSCAPE_SPKI_verify(); | ||
| 816 | |||
| 817 | int X509_sign(); | ||
| 818 | int X509_REQ_sign(); | ||
| 819 | int X509_CRL_sign(); | ||
| 820 | int NETSCAPE_SPKI_sign(); | ||
| 821 | |||
| 822 | int X509_digest(); | ||
| 823 | int X509_NAME_digest(); | ||
| 824 | #endif | ||
| 825 | |||
| 826 | #ifndef NO_FP_API | ||
| 827 | X509 *d2i_X509_fp(); | ||
| 828 | int i2d_X509_fp(); | ||
| 829 | X509_CRL *d2i_X509_CRL_fp(); | ||
| 830 | int i2d_X509_CRL_fp(); | ||
| 831 | X509_REQ *d2i_X509_REQ_fp(); | ||
| 832 | int i2d_X509_REQ_fp(); | ||
| 833 | RSA *d2i_RSAPrivateKey_fp(); | ||
| 834 | int i2d_RSAPrivateKey_fp(); | ||
| 835 | DSA *d2i_DSAPrivateKey_fp(); | ||
| 836 | int i2d_DSAPrivateKey_fp(); | ||
| 837 | RSA *d2i_RSAPublicKey_fp(); | ||
| 838 | int i2d_RSAPublicKey_fp(); | ||
| 839 | #endif | ||
| 840 | |||
| 841 | X509 *d2i_X509_bio(); | ||
| 842 | int i2d_X509_bio(); | ||
| 843 | X509_CRL *d2i_X509_CRL_bio(); | ||
| 844 | int i2d_X509_CRL_bio(); | ||
| 845 | X509_REQ *d2i_X509_REQ_bio(); | ||
| 846 | int i2d_X509_REQ_bio(); | ||
| 847 | RSA *d2i_RSAPrivateKey_bio(); | ||
| 848 | int i2d_RSAPrivateKey_bio(); | ||
| 849 | DSA *d2i_DSAPrivateKey_bio(); | ||
| 850 | int i2d_DSAPrivateKey_bio(); | ||
| 851 | RSA *d2i_RSAPublicKey_bio(); | ||
| 852 | int i2d_RSAPublicKey_bio(); | ||
| 853 | |||
| 854 | X509 *X509_dup(); | ||
| 855 | X509_EXTENSION *X509_EXTENSION_dup(); | ||
| 856 | X509_CRL *X509_CRL_dup(); | ||
| 857 | X509_REQ *X509_REQ_dup(); | ||
| 858 | X509_NAME *X509_NAME_dup(); | ||
| 859 | X509_NAME_ENTRY *X509_NAME_ENTRY_dup(); | ||
| 860 | RSA *RSAPublicKey_dup(); | ||
| 861 | RSA *RSAPrivateKey_dup(); | ||
| 862 | |||
| 863 | #endif /* !SSLEAY_MACROS */ | ||
| 864 | |||
| 865 | int X509_cmp_current_time(); | ||
| 866 | ASN1_UTCTIME * X509_gmtime_adj(); | ||
| 867 | |||
| 868 | char * X509_get_default_cert_area(); | ||
| 869 | char * X509_get_default_cert_dir(); | ||
| 870 | char * X509_get_default_cert_file(); | ||
| 871 | char * X509_get_default_cert_dir_env(); | ||
| 872 | char * X509_get_default_cert_file_env(); | ||
| 873 | char * X509_get_default_private_dir(); | ||
| 874 | |||
| 875 | X509_REQ * X509_to_X509_REQ(); | ||
| 876 | X509 * X509_REQ_to_X509(); | ||
| 877 | void ERR_load_X509_strings(); | ||
| 878 | |||
| 879 | X509_ALGOR * X509_ALGOR_new(); | ||
| 880 | void X509_ALGOR_free(); | ||
| 881 | int i2d_X509_ALGOR(); | ||
| 882 | X509_ALGOR * d2i_X509_ALGOR(); | ||
| 883 | |||
| 884 | X509_VAL * X509_VAL_new(); | ||
| 885 | void X509_VAL_free(); | ||
| 886 | int i2d_X509_VAL(); | ||
| 887 | X509_VAL * d2i_X509_VAL(); | ||
| 888 | |||
| 889 | X509_PUBKEY * X509_PUBKEY_new(); | ||
| 890 | void X509_PUBKEY_free(); | ||
| 891 | int i2d_X509_PUBKEY(); | ||
| 892 | X509_PUBKEY * d2i_X509_PUBKEY(); | ||
| 893 | int X509_PUBKEY_set(); | ||
| 894 | EVP_PKEY * X509_PUBKEY_get(); | ||
| 895 | int X509_get_pubkey_parameters(); | ||
| 896 | |||
| 897 | X509_SIG * X509_SIG_new(); | ||
| 898 | void X509_SIG_free(); | ||
| 899 | int i2d_X509_SIG(); | ||
| 900 | X509_SIG * d2i_X509_SIG(); | ||
| 901 | |||
| 902 | X509_REQ_INFO *X509_REQ_INFO_new(); | ||
| 903 | void X509_REQ_INFO_free(); | ||
| 904 | int i2d_X509_REQ_INFO(); | ||
| 905 | X509_REQ_INFO *d2i_X509_REQ_INFO(); | ||
| 906 | |||
| 907 | X509_REQ * X509_REQ_new(); | ||
| 908 | void X509_REQ_free(); | ||
| 909 | int i2d_X509_REQ(); | ||
| 910 | X509_REQ * d2i_X509_REQ(); | ||
| 911 | |||
| 912 | X509_ATTRIBUTE *X509_ATTRIBUTE_new(); | ||
| 913 | void X509_ATTRIBUTE_free(); | ||
| 914 | int i2d_X509_ATTRIBUTE(); | ||
| 915 | X509_ATTRIBUTE *d2i_X509_ATTRIBUTE(); | ||
| 916 | |||
| 917 | X509_EXTENSION *X509_EXTENSION_new(); | ||
| 918 | void X509_EXTENSION_free(); | ||
| 919 | int i2d_X509_EXTENSION(); | ||
| 920 | X509_EXTENSION *d2i_X509_EXTENSION(); | ||
| 921 | |||
| 922 | X509_NAME_ENTRY *X509_NAME_ENTRY_new(); | ||
| 923 | void X509_NAME_ENTRY_free(); | ||
| 924 | int i2d_X509_NAME_ENTRY(); | ||
| 925 | X509_NAME_ENTRY *d2i_X509_NAME_ENTRY(); | ||
| 926 | |||
| 927 | X509_NAME * X509_NAME_new(); | ||
| 928 | void X509_NAME_free(); | ||
| 929 | int i2d_X509_NAME(); | ||
| 930 | X509_NAME * d2i_X509_NAME(); | ||
| 931 | int X509_NAME_set(); | ||
| 932 | |||
| 933 | |||
| 934 | X509_CINF * X509_CINF_new(); | ||
| 935 | void X509_CINF_free(); | ||
| 936 | int i2d_X509_CINF(); | ||
| 937 | X509_CINF * d2i_X509_CINF(); | ||
| 938 | |||
| 939 | X509 * X509_new(); | ||
| 940 | void X509_free(); | ||
| 941 | int i2d_X509(); | ||
| 942 | X509 * d2i_X509(); | ||
| 943 | |||
| 944 | X509_REVOKED * X509_REVOKED_new(); | ||
| 945 | void X509_REVOKED_free(); | ||
| 946 | int i2d_X509_REVOKED(); | ||
| 947 | X509_REVOKED * d2i_X509_REVOKED(); | ||
| 948 | |||
| 949 | X509_CRL_INFO *X509_CRL_INFO_new(); | ||
| 950 | void X509_CRL_INFO_free(); | ||
| 951 | int i2d_X509_CRL_INFO(); | ||
| 952 | X509_CRL_INFO *d2i_X509_CRL_INFO(); | ||
| 953 | |||
| 954 | X509_CRL * X509_CRL_new(); | ||
| 955 | void X509_CRL_free(); | ||
| 956 | int i2d_X509_CRL(); | ||
| 957 | X509_CRL * d2i_X509_CRL(); | ||
| 958 | |||
| 959 | X509_PKEY * X509_PKEY_new(); | ||
| 960 | void X509_PKEY_free(); | ||
| 961 | int i2d_X509_PKEY(); | ||
| 962 | X509_PKEY * d2i_X509_PKEY(); | ||
| 963 | |||
| 964 | NETSCAPE_SPKI * NETSCAPE_SPKI_new(); | ||
| 965 | void NETSCAPE_SPKI_free(); | ||
| 966 | int i2d_NETSCAPE_SPKI(); | ||
| 967 | NETSCAPE_SPKI * d2i_NETSCAPE_SPKI(); | ||
| 968 | |||
| 969 | NETSCAPE_SPKAC *NETSCAPE_SPKAC_new(); | ||
| 970 | void NETSCAPE_SPKAC_free(); | ||
| 971 | int i2d_NETSCAPE_SPKAC(); | ||
| 972 | NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC(); | ||
| 973 | |||
| 974 | #ifdef HEADER_ENVELOPE_H | ||
| 975 | X509_INFO * X509_INFO_new(); | ||
| 976 | void X509_INFO_free(); | ||
| 977 | #endif | ||
| 978 | |||
| 979 | char * X509_NAME_oneline(); | ||
| 980 | |||
| 981 | int ASN1_verify(); | ||
| 982 | int ASN1_digest(); | ||
| 983 | int ASN1_sign(); | ||
| 984 | |||
| 985 | int X509_set_version(); | ||
| 986 | int X509_set_serialNumber(); | ||
| 987 | ASN1_INTEGER * X509_get_serialNumber(); | ||
| 988 | int X509_set_issuer_name(); | ||
| 989 | X509_NAME * X509_get_issuer_name(); | ||
| 990 | int X509_set_subject_name(); | ||
| 991 | X509_NAME * X509_get_subject_name(); | ||
| 992 | int X509_set_notBefore(); | ||
| 993 | int X509_set_notAfter(); | ||
| 994 | int X509_set_pubkey(); | ||
| 995 | EVP_PKEY * X509_get_pubkey(); | ||
| 996 | int X509_certificate_type(); | ||
| 997 | |||
| 998 | int X509_REQ_set_version(); | ||
| 999 | int X509_REQ_set_subject_name(); | ||
| 1000 | int X509_REQ_set_pubkey(); | ||
| 1001 | EVP_PKEY * X509_REQ_get_pubkey(); | ||
| 1002 | |||
| 1003 | int X509_check_private_key(); | ||
| 1004 | |||
| 1005 | int X509_issuer_and_serial_cmp(); | ||
| 1006 | unsigned long X509_issuer_and_serial_hash(); | ||
| 1007 | |||
| 1008 | int X509_issuer_name_cmp(); | ||
| 1009 | unsigned long X509_issuer_name_hash(); | ||
| 1010 | |||
| 1011 | int X509_subject_name_cmp(); | ||
| 1012 | unsigned long X509_subject_name_hash(); | ||
| 1013 | |||
| 1014 | int X509_NAME_cmp (); | ||
| 1015 | unsigned long X509_NAME_hash(); | ||
| 1016 | |||
| 1017 | int X509_CRL_cmp(); | ||
| 1018 | #ifndef NO_FP_API | ||
| 1019 | int X509_print_fp(); | ||
| 1020 | int X509_REQ_print_fp(); | ||
| 1021 | #endif | ||
| 1022 | |||
| 1023 | int X509_NAME_print(); | ||
| 1024 | int X509_print(); | ||
| 1025 | int X509_REQ_print(); | ||
| 1026 | |||
| 1027 | int X509_NAME_entry_count(); | ||
| 1028 | int X509_NAME_get_text_by_NID(); | ||
| 1029 | int X509_NAME_get_text_by_OBJ(); | ||
| 1030 | |||
| 1031 | int X509_NAME_get_index_by_NID(); | ||
| 1032 | int X509_NAME_get_index_by_OBJ(); | ||
| 1033 | X509_NAME_ENTRY *X509_NAME_get_entry(); | ||
| 1034 | X509_NAME_ENTRY *X509_NAME_delete_entry(); | ||
| 1035 | int X509_NAME_add_entry(); | ||
| 1036 | X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(); | ||
| 1037 | X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(); | ||
| 1038 | int X509_NAME_ENTRY_set_object(); | ||
| 1039 | int X509_NAME_ENTRY_set_data(); | ||
| 1040 | ASN1_OBJECT * X509_NAME_ENTRY_get_object(); | ||
| 1041 | ASN1_STRING * X509_NAME_ENTRY_get_data(); | ||
| 1042 | |||
| 1043 | int X509v3_get_ext_count(); | ||
| 1044 | int X509v3_get_ext_by_NID(); | ||
| 1045 | int X509v3_get_ext_by_OBJ(); | ||
| 1046 | int X509v3_get_ext_by_critical(); | ||
| 1047 | X509_EXTENSION *X509v3_get_ext(); | ||
| 1048 | X509_EXTENSION *X509v3_delete_ext(); | ||
| 1049 | STACK * X509v3_add_ext(); | ||
| 1050 | |||
| 1051 | int X509v3_data_type_by_OBJ(); | ||
| 1052 | int X509v3_data_type_by_NID(); | ||
| 1053 | int X509v3_pack_type_by_OBJ(); | ||
| 1054 | int X509v3_pack_type_by_NID(); | ||
| 1055 | |||
| 1056 | int X509_get_ext_count(); | ||
| 1057 | int X509_get_ext_by_NID(); | ||
| 1058 | int X509_get_ext_by_OBJ(); | ||
| 1059 | int X509_get_ext_by_critical(); | ||
| 1060 | X509_EXTENSION *X509_get_ext(); | ||
| 1061 | X509_EXTENSION *X509_delete_ext(); | ||
| 1062 | int X509_add_ext(); | ||
| 1063 | |||
| 1064 | int X509_CRL_get_ext_count(); | ||
| 1065 | int X509_CRL_get_ext_by_NID(); | ||
| 1066 | int X509_CRL_get_ext_by_OBJ(); | ||
| 1067 | int X509_CRL_get_ext_by_critical(); | ||
| 1068 | X509_EXTENSION *X509_CRL_get_ext(); | ||
| 1069 | X509_EXTENSION *X509_CRL_delete_ext(); | ||
| 1070 | int X509_CRL_add_ext(); | ||
| 1071 | |||
| 1072 | int X509_REVOKED_get_ext_count(); | ||
| 1073 | int X509_REVOKED_get_ext_by_NID(); | ||
| 1074 | int X509_REVOKED_get_ext_by_OBJ(); | ||
| 1075 | int X509_REVOKED_get_ext_by_critical(); | ||
| 1076 | X509_EXTENSION *X509_REVOKED_get_ext(); | ||
| 1077 | X509_EXTENSION *X509_REVOKED_delete_ext(); | ||
| 1078 | int X509_REVOKED_add_ext(); | ||
| 1079 | |||
| 1080 | X509_EXTENSION *X509_EXTENSION_create_by_NID(); | ||
| 1081 | X509_EXTENSION *X509_EXTENSION_create_by_OBJ(); | ||
| 1082 | int X509_EXTENSION_set_object(); | ||
| 1083 | int X509_EXTENSION_set_critical(); | ||
| 1084 | int X509_EXTENSION_set_data(); | ||
| 1085 | ASN1_OBJECT * X509_EXTENSION_get_object(); | ||
| 1086 | ASN1_OCTET_STRING *X509_EXTENSION_get_data(); | ||
| 1087 | int X509_EXTENSION_get_critical(); | ||
| 1088 | ASN1_OCTET_STRING *X509v3_pack_string(); | ||
| 1089 | ASN1_STRING * X509v3_unpack_string(); | ||
| 1090 | |||
| 1091 | int X509_verify_cert(); | ||
| 1092 | char * X509_verify_cert_error_string(); | ||
| 1093 | |||
| 1094 | /* lookup a cert from a X509 STACK */ | ||
| 1095 | X509 *X509_find_by_issuer_and_serial(); | ||
| 1096 | X509 *X509_find_by_subject(); | ||
| 1097 | |||
| 1098 | #endif | ||
| 1099 | |||
| 1100 | /* BEGIN ERROR CODES */ | ||
| 1101 | /* Error codes for the X509 functions. */ | ||
| 1102 | |||
| 1103 | /* Function codes. */ | ||
| 1104 | #define X509_F_ADD_CERT_DIR 100 | ||
| 1105 | #define X509_F_BY_FILE_CTRL 101 | ||
| 1106 | #define X509_F_DIR_CTRL 102 | ||
| 1107 | #define X509_F_GET_CERT_BY_SUBJECT 103 | ||
| 1108 | #define X509_F_X509V3_ADD_EXT 104 | ||
| 1109 | #define X509_F_X509V3_ADD_EXTENSION 105 | ||
| 1110 | #define X509_F_X509V3_PACK_STRING 106 | ||
| 1111 | #define X509_F_X509V3_UNPACK_STRING 107 | ||
| 1112 | #define X509_F_X509_EXTENSION_CREATE_BY_NID 108 | ||
| 1113 | #define X509_F_X509_EXTENSION_CREATE_BY_OBJ 109 | ||
| 1114 | #define X509_F_X509_GET_PUBKEY_PARAMETERS 110 | ||
| 1115 | #define X509_F_X509_LOAD_CERT_FILE 111 | ||
| 1116 | #define X509_F_X509_LOAD_CRL_FILE 112 | ||
| 1117 | #define X509_F_X509_NAME_ADD_ENTRY 113 | ||
| 1118 | #define X509_F_X509_NAME_ENTRY_CREATE_BY_NID 114 | ||
| 1119 | #define X509_F_X509_NAME_ENTRY_SET_OBJECT 115 | ||
| 1120 | #define X509_F_X509_NAME_ONELINE 116 | ||
| 1121 | #define X509_F_X509_NAME_PRINT 117 | ||
| 1122 | #define X509_F_X509_PRINT_FP 118 | ||
| 1123 | #define X509_F_X509_PUBKEY_GET 119 | ||
| 1124 | #define X509_F_X509_PUBKEY_SET 120 | ||
| 1125 | #define X509_F_X509_REQ_PRINT 121 | ||
| 1126 | #define X509_F_X509_REQ_PRINT_FP 122 | ||
| 1127 | #define X509_F_X509_REQ_TO_X509 123 | ||
| 1128 | #define X509_F_X509_STORE_ADD_CERT 124 | ||
| 1129 | #define X509_F_X509_STORE_ADD_CRL 125 | ||
| 1130 | #define X509_F_X509_TO_X509_REQ 126 | ||
| 1131 | #define X509_F_X509_VERIFY_CERT 127 | ||
| 1132 | |||
| 1133 | /* Reason codes. */ | ||
| 1134 | #define X509_R_BAD_X509_FILETYPE 100 | ||
| 1135 | #define X509_R_CERT_ALREADY_IN_HASH_TABLE 101 | ||
| 1136 | #define X509_R_ERR_ASN1_LIB 102 | ||
| 1137 | #define X509_R_LOADING_CERT_DIR 103 | ||
| 1138 | #define X509_R_LOADING_DEFAULTS 104 | ||
| 1139 | #define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY 105 | ||
| 1140 | #define X509_R_SHOULD_RETRY 106 | ||
| 1141 | #define X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN 107 | ||
| 1142 | #define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY 108 | ||
| 1143 | #define X509_R_UNKNOWN_NID 109 | ||
| 1144 | #define X509_R_UNKNOWN_STRING_TYPE 110 | ||
| 1145 | #define X509_R_UNSUPPORTED_ALGORITHM 111 | ||
| 1146 | #define X509_R_WRONG_LOOKUP_TYPE 112 | ||
| 1147 | |||
| 1148 | #ifdef __cplusplus | ||
| 1149 | } | ||
| 1150 | #endif | ||
| 1151 | #endif | ||
| 1152 | |||
diff --git a/src/lib/libcrypto/x509/x509_cmp.c b/src/lib/libcrypto/x509/x509_cmp.c new file mode 100644 index 0000000000..f9d9510ac5 --- /dev/null +++ b/src/lib/libcrypto/x509/x509_cmp.c | |||
| @@ -0,0 +1,257 @@ | |||
| 1 | /* crypto/x509/x509_cmp.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 <sys/types.h> | ||
| 61 | #include <sys/stat.h> | ||
| 62 | #include "cryptlib.h" | ||
| 63 | #include "asn1.h" | ||
| 64 | #include "objects.h" | ||
| 65 | #include "x509.h" | ||
| 66 | |||
| 67 | int X509_issuer_and_serial_cmp(a,b) | ||
| 68 | X509 *a; | ||
| 69 | X509 *b; | ||
| 70 | { | ||
| 71 | int i; | ||
| 72 | X509_CINF *ai,*bi; | ||
| 73 | |||
| 74 | ai=a->cert_info; | ||
| 75 | bi=b->cert_info; | ||
| 76 | i=ASN1_INTEGER_cmp(ai->serialNumber,bi->serialNumber); | ||
| 77 | if (i) return(i); | ||
| 78 | return(X509_NAME_cmp(ai->issuer,bi->issuer)); | ||
| 79 | } | ||
| 80 | |||
| 81 | #ifndef NO_MD5 | ||
| 82 | unsigned long X509_issuer_and_serial_hash(a) | ||
| 83 | X509 *a; | ||
| 84 | { | ||
| 85 | unsigned long ret=0; | ||
| 86 | MD5_CTX ctx; | ||
| 87 | unsigned char md[16]; | ||
| 88 | char str[256]; | ||
| 89 | |||
| 90 | X509_NAME_oneline(a->cert_info->issuer,str,256); | ||
| 91 | ret=strlen(str); | ||
| 92 | MD5_Init(&ctx); | ||
| 93 | MD5_Update(&ctx,(unsigned char *)str,ret); | ||
| 94 | MD5_Update(&ctx,(unsigned char *)a->cert_info->serialNumber->data, | ||
| 95 | (unsigned long)a->cert_info->serialNumber->length); | ||
| 96 | MD5_Final(&(md[0]),&ctx); | ||
| 97 | ret=( ((unsigned long)md[0] )|((unsigned long)md[1]<<8L)| | ||
| 98 | ((unsigned long)md[2]<<16L)|((unsigned long)md[3]<<24L) | ||
| 99 | )&0xffffffffL; | ||
| 100 | return(ret); | ||
| 101 | } | ||
| 102 | #endif | ||
| 103 | |||
| 104 | int X509_issuer_name_cmp(a, b) | ||
| 105 | X509 *a; | ||
| 106 | X509 *b; | ||
| 107 | { | ||
| 108 | return(X509_NAME_cmp(a->cert_info->issuer,b->cert_info->issuer)); | ||
| 109 | } | ||
| 110 | |||
| 111 | int X509_subject_name_cmp(a, b) | ||
| 112 | X509 *a; | ||
| 113 | X509 *b; | ||
| 114 | { | ||
| 115 | return(X509_NAME_cmp(a->cert_info->subject,b->cert_info->subject)); | ||
| 116 | } | ||
| 117 | |||
| 118 | int X509_CRL_cmp(a, b) | ||
| 119 | X509_CRL *a; | ||
| 120 | X509_CRL *b; | ||
| 121 | { | ||
| 122 | return(X509_NAME_cmp(a->crl->issuer,b->crl->issuer)); | ||
| 123 | } | ||
| 124 | |||
| 125 | X509_NAME *X509_get_issuer_name(a) | ||
| 126 | X509 *a; | ||
| 127 | { | ||
| 128 | return(a->cert_info->issuer); | ||
| 129 | } | ||
| 130 | |||
| 131 | unsigned long X509_issuer_name_hash(x) | ||
| 132 | X509 *x; | ||
| 133 | { | ||
| 134 | return(X509_NAME_hash(x->cert_info->issuer)); | ||
| 135 | } | ||
| 136 | |||
| 137 | X509_NAME *X509_get_subject_name(a) | ||
| 138 | X509 *a; | ||
| 139 | { | ||
| 140 | return(a->cert_info->subject); | ||
| 141 | } | ||
| 142 | |||
| 143 | ASN1_INTEGER *X509_get_serialNumber(a) | ||
| 144 | X509 *a; | ||
| 145 | { | ||
| 146 | return(a->cert_info->serialNumber); | ||
| 147 | } | ||
| 148 | |||
| 149 | unsigned long X509_subject_name_hash(x) | ||
| 150 | X509 *x; | ||
| 151 | { | ||
| 152 | return(X509_NAME_hash(x->cert_info->subject)); | ||
| 153 | } | ||
| 154 | |||
| 155 | int X509_NAME_cmp(a, b) | ||
| 156 | X509_NAME *a; | ||
| 157 | X509_NAME *b; | ||
| 158 | { | ||
| 159 | int i,j; | ||
| 160 | X509_NAME_ENTRY *na,*nb; | ||
| 161 | |||
| 162 | if (sk_num(a->entries) != sk_num(b->entries)) | ||
| 163 | return(sk_num(a->entries)-sk_num(b->entries)); | ||
| 164 | for (i=sk_num(a->entries)-1; i>=0; i--) | ||
| 165 | { | ||
| 166 | na=(X509_NAME_ENTRY *)sk_value(a->entries,i); | ||
| 167 | nb=(X509_NAME_ENTRY *)sk_value(b->entries,i); | ||
| 168 | j=na->value->length-nb->value->length; | ||
| 169 | if (j) return(j); | ||
| 170 | j=memcmp(na->value->data,nb->value->data, | ||
| 171 | na->value->length); | ||
| 172 | if (j) return(j); | ||
| 173 | j=na->set-nb->set; | ||
| 174 | if (j) return(j); | ||
| 175 | } | ||
| 176 | |||
| 177 | /* We will check the object types after checking the values | ||
| 178 | * since the values will more often be different than the object | ||
| 179 | * types. */ | ||
| 180 | for (i=sk_num(a->entries)-1; i>=0; i--) | ||
| 181 | { | ||
| 182 | na=(X509_NAME_ENTRY *)sk_value(a->entries,i); | ||
| 183 | nb=(X509_NAME_ENTRY *)sk_value(b->entries,i); | ||
| 184 | j=OBJ_cmp(na->object,nb->object); | ||
| 185 | if (j) return(j); | ||
| 186 | } | ||
| 187 | return(0); | ||
| 188 | } | ||
| 189 | |||
| 190 | #ifndef NO_MD5 | ||
| 191 | /* I now DER encode the name and hash it. Since I cache the DER encoding, | ||
| 192 | * this is reasonably effiecent. */ | ||
| 193 | unsigned long X509_NAME_hash(x) | ||
| 194 | X509_NAME *x; | ||
| 195 | { | ||
| 196 | unsigned long ret=0; | ||
| 197 | unsigned char md[16]; | ||
| 198 | unsigned char str[256],*p,*pp; | ||
| 199 | int i; | ||
| 200 | |||
| 201 | i=i2d_X509_NAME(x,NULL); | ||
| 202 | if (i > sizeof(str)) | ||
| 203 | p=Malloc(i); | ||
| 204 | else | ||
| 205 | p=str; | ||
| 206 | |||
| 207 | pp=p; | ||
| 208 | i2d_X509_NAME(x,&pp); | ||
| 209 | MD5((unsigned char *)p,i,&(md[0])); | ||
| 210 | if (p != str) Free(p); | ||
| 211 | |||
| 212 | ret=( ((unsigned long)md[0] )|((unsigned long)md[1]<<8L)| | ||
| 213 | ((unsigned long)md[2]<<16L)|((unsigned long)md[3]<<24L) | ||
| 214 | )&0xffffffffL; | ||
| 215 | return(ret); | ||
| 216 | } | ||
| 217 | #endif | ||
| 218 | |||
| 219 | /* Search a stack of X509 for a match */ | ||
| 220 | X509 *X509_find_by_issuer_and_serial(sk,name,serial) | ||
| 221 | STACK *sk; | ||
| 222 | X509_NAME *name; | ||
| 223 | ASN1_INTEGER *serial; | ||
| 224 | { | ||
| 225 | int i; | ||
| 226 | X509_CINF cinf; | ||
| 227 | X509 x,*x509=NULL; | ||
| 228 | |||
| 229 | x.cert_info= &cinf; | ||
| 230 | cinf.serialNumber=serial; | ||
| 231 | cinf.issuer=name; | ||
| 232 | |||
| 233 | for (i=0; i<sk_num(sk); i++) | ||
| 234 | { | ||
| 235 | x509=(X509 *)sk_value(sk,i); | ||
| 236 | if (X509_issuer_and_serial_cmp(x509,&x) == 0) | ||
| 237 | return(x509); | ||
| 238 | } | ||
| 239 | return(NULL); | ||
| 240 | } | ||
| 241 | |||
| 242 | X509 *X509_find_by_subject(sk,name) | ||
| 243 | STACK *sk; | ||
| 244 | X509_NAME *name; | ||
| 245 | { | ||
| 246 | X509 *x509; | ||
| 247 | int i; | ||
| 248 | |||
| 249 | for (i=0; i<sk_num(sk); i++) | ||
| 250 | { | ||
| 251 | x509=(X509 *)sk_value(sk,i); | ||
| 252 | if (X509_NAME_cmp(X509_get_subject_name(x509),name) == 0) | ||
| 253 | return(x509); | ||
| 254 | } | ||
| 255 | return(NULL); | ||
| 256 | } | ||
| 257 | |||
diff --git a/src/lib/libcrypto/x509/x509_d2.c b/src/lib/libcrypto/x509/x509_d2.c new file mode 100644 index 0000000000..01e22f4cb4 --- /dev/null +++ b/src/lib/libcrypto/x509/x509_d2.c | |||
| @@ -0,0 +1,110 @@ | |||
| 1 | /* crypto/x509/x509_d2.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 <sys/types.h> | ||
| 61 | #include <sys/stat.h> | ||
| 62 | #include "cryptlib.h" | ||
| 63 | #include "crypto.h" | ||
| 64 | #include "x509.h" | ||
| 65 | |||
| 66 | #ifndef NO_STDIO | ||
| 67 | int X509_STORE_set_default_paths(ctx) | ||
| 68 | X509_STORE *ctx; | ||
| 69 | { | ||
| 70 | X509_LOOKUP *lookup; | ||
| 71 | |||
| 72 | lookup=X509_STORE_add_lookup(ctx,X509_LOOKUP_file()); | ||
| 73 | if (lookup == NULL) return(0); | ||
| 74 | X509_LOOKUP_load_file(lookup,NULL,X509_FILETYPE_DEFAULT); | ||
| 75 | |||
| 76 | lookup=X509_STORE_add_lookup(ctx,X509_LOOKUP_hash_dir()); | ||
| 77 | if (lookup == NULL) return(0); | ||
| 78 | X509_LOOKUP_add_dir(lookup,NULL,X509_FILETYPE_DEFAULT); | ||
| 79 | |||
| 80 | /* clear any errors */ | ||
| 81 | ERR_clear_error(); | ||
| 82 | |||
| 83 | return(1); | ||
| 84 | } | ||
| 85 | |||
| 86 | int X509_STORE_load_locations(ctx,file,path) | ||
| 87 | X509_STORE *ctx; | ||
| 88 | char *file; | ||
| 89 | char *path; | ||
| 90 | { | ||
| 91 | X509_LOOKUP *lookup; | ||
| 92 | |||
| 93 | if (file != NULL) | ||
| 94 | { | ||
| 95 | lookup=X509_STORE_add_lookup(ctx,X509_LOOKUP_file()); | ||
| 96 | if (lookup == NULL) return(0); | ||
| 97 | X509_LOOKUP_load_file(lookup,file,X509_FILETYPE_PEM); | ||
| 98 | } | ||
| 99 | if (path != NULL) | ||
| 100 | { | ||
| 101 | lookup=X509_STORE_add_lookup(ctx,X509_LOOKUP_hash_dir()); | ||
| 102 | if (lookup == NULL) return(0); | ||
| 103 | X509_LOOKUP_add_dir(lookup,path,X509_FILETYPE_PEM); | ||
| 104 | } | ||
| 105 | if ((path == NULL) && (file == NULL)) | ||
| 106 | return(0); | ||
| 107 | return(1); | ||
| 108 | } | ||
| 109 | |||
| 110 | #endif | ||
diff --git a/src/lib/libcrypto/x509/x509_def.c b/src/lib/libcrypto/x509/x509_def.c new file mode 100644 index 0000000000..d9ab39b15a --- /dev/null +++ b/src/lib/libcrypto/x509/x509_def.c | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | /* crypto/x509/x509_def.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 <sys/types.h> | ||
| 61 | #include <sys/stat.h> | ||
| 62 | #include "cryptlib.h" | ||
| 63 | #include "crypto.h" | ||
| 64 | #include "x509.h" | ||
| 65 | |||
| 66 | char *X509_get_default_private_dir() | ||
| 67 | { return(X509_PRIVATE_DIR); } | ||
| 68 | |||
| 69 | char *X509_get_default_cert_area() | ||
| 70 | { return(X509_CERT_AREA); } | ||
| 71 | |||
| 72 | char *X509_get_default_cert_dir() | ||
| 73 | { return(X509_CERT_DIR); } | ||
| 74 | |||
| 75 | char *X509_get_default_cert_file() | ||
| 76 | { return(X509_CERT_FILE); } | ||
| 77 | |||
| 78 | char *X509_get_default_cert_dir_env() | ||
| 79 | { return(X509_CERT_DIR_EVP); } | ||
| 80 | |||
| 81 | char *X509_get_default_cert_file_env() | ||
| 82 | { return(X509_CERT_FILE_EVP); } | ||
| 83 | |||
diff --git a/src/lib/libcrypto/x509/x509_err.c b/src/lib/libcrypto/x509/x509_err.c new file mode 100644 index 0000000000..9304721612 --- /dev/null +++ b/src/lib/libcrypto/x509/x509_err.c | |||
| @@ -0,0 +1,130 @@ | |||
| 1 | /* lib/x509/x509_err.c */ | ||
| 2 | /* Copyright (C) 1995-1997 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 | #include <stdio.h> | ||
| 59 | #include "err.h" | ||
| 60 | #include "x509.h" | ||
| 61 | |||
| 62 | /* BEGIN ERROR CODES */ | ||
| 63 | #ifndef NO_ERR | ||
| 64 | static ERR_STRING_DATA X509_str_functs[]= | ||
| 65 | { | ||
| 66 | {ERR_PACK(0,X509_F_ADD_CERT_DIR,0), "ADD_CERT_DIR"}, | ||
| 67 | {ERR_PACK(0,X509_F_BY_FILE_CTRL,0), "BY_FILE_CTRL"}, | ||
| 68 | {ERR_PACK(0,X509_F_DIR_CTRL,0), "DIR_CTRL"}, | ||
| 69 | {ERR_PACK(0,X509_F_GET_CERT_BY_SUBJECT,0), "GET_CERT_BY_SUBJECT"}, | ||
| 70 | {ERR_PACK(0,X509_F_X509V3_ADD_EXT,0), "X509v3_add_ext"}, | ||
| 71 | {ERR_PACK(0,X509_F_X509V3_ADD_EXTENSION,0), "X509V3_ADD_EXTENSION"}, | ||
| 72 | {ERR_PACK(0,X509_F_X509V3_PACK_STRING,0), "X509v3_pack_string"}, | ||
| 73 | {ERR_PACK(0,X509_F_X509V3_UNPACK_STRING,0), "X509v3_unpack_string"}, | ||
| 74 | {ERR_PACK(0,X509_F_X509_EXTENSION_CREATE_BY_NID,0), "X509_EXTENSION_create_by_NID"}, | ||
| 75 | {ERR_PACK(0,X509_F_X509_EXTENSION_CREATE_BY_OBJ,0), "X509_EXTENSION_create_by_OBJ"}, | ||
| 76 | {ERR_PACK(0,X509_F_X509_GET_PUBKEY_PARAMETERS,0), "X509_get_pubkey_parameters"}, | ||
| 77 | {ERR_PACK(0,X509_F_X509_LOAD_CERT_FILE,0), "X509_LOAD_CERT_FILE"}, | ||
| 78 | {ERR_PACK(0,X509_F_X509_LOAD_CRL_FILE,0), "X509_LOAD_CRL_FILE"}, | ||
| 79 | {ERR_PACK(0,X509_F_X509_NAME_ADD_ENTRY,0), "X509_NAME_add_entry"}, | ||
| 80 | {ERR_PACK(0,X509_F_X509_NAME_ENTRY_CREATE_BY_NID,0), "X509_NAME_ENTRY_create_by_NID"}, | ||
| 81 | {ERR_PACK(0,X509_F_X509_NAME_ENTRY_SET_OBJECT,0), "X509_NAME_ENTRY_set_object"}, | ||
| 82 | {ERR_PACK(0,X509_F_X509_NAME_ONELINE,0), "X509_NAME_oneline"}, | ||
| 83 | {ERR_PACK(0,X509_F_X509_NAME_PRINT,0), "X509_NAME_print"}, | ||
| 84 | {ERR_PACK(0,X509_F_X509_PRINT_FP,0), "X509_print_fp"}, | ||
| 85 | {ERR_PACK(0,X509_F_X509_PUBKEY_GET,0), "X509_PUBKEY_get"}, | ||
| 86 | {ERR_PACK(0,X509_F_X509_PUBKEY_SET,0), "X509_PUBKEY_set"}, | ||
| 87 | {ERR_PACK(0,X509_F_X509_REQ_PRINT,0), "X509_REQ_print"}, | ||
| 88 | {ERR_PACK(0,X509_F_X509_REQ_PRINT_FP,0), "X509_REQ_print_fp"}, | ||
| 89 | {ERR_PACK(0,X509_F_X509_REQ_TO_X509,0), "X509_REQ_to_X509"}, | ||
| 90 | {ERR_PACK(0,X509_F_X509_STORE_ADD_CERT,0), "X509_STORE_ADD_CERT"}, | ||
| 91 | {ERR_PACK(0,X509_F_X509_STORE_ADD_CRL,0), "X509_STORE_ADD_CRL"}, | ||
| 92 | {ERR_PACK(0,X509_F_X509_TO_X509_REQ,0), "X509_to_X509_REQ"}, | ||
| 93 | {ERR_PACK(0,X509_F_X509_VERIFY_CERT,0), "X509_verify_cert"}, | ||
| 94 | {0,NULL}, | ||
| 95 | }; | ||
| 96 | |||
| 97 | static ERR_STRING_DATA X509_str_reasons[]= | ||
| 98 | { | ||
| 99 | {X509_R_BAD_X509_FILETYPE ,"bad x509 filetype"}, | ||
| 100 | {X509_R_CERT_ALREADY_IN_HASH_TABLE ,"cert already in hash table"}, | ||
| 101 | {X509_R_ERR_ASN1_LIB ,"err asn1 lib"}, | ||
| 102 | {X509_R_LOADING_CERT_DIR ,"loading cert dir"}, | ||
| 103 | {X509_R_LOADING_DEFAULTS ,"loading defaults"}, | ||
| 104 | {X509_R_NO_CERT_SET_FOR_US_TO_VERIFY ,"no cert set for us to verify"}, | ||
| 105 | {X509_R_SHOULD_RETRY ,"should retry"}, | ||
| 106 | {X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN,"unable to find parameters in chain"}, | ||
| 107 | {X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY ,"unable to get certs public key"}, | ||
| 108 | {X509_R_UNKNOWN_NID ,"unknown nid"}, | ||
| 109 | {X509_R_UNKNOWN_STRING_TYPE ,"unknown string type"}, | ||
| 110 | {X509_R_UNSUPPORTED_ALGORITHM ,"unsupported algorithm"}, | ||
| 111 | {X509_R_WRONG_LOOKUP_TYPE ,"wrong lookup type"}, | ||
| 112 | {0,NULL}, | ||
| 113 | }; | ||
| 114 | |||
| 115 | #endif | ||
| 116 | |||
| 117 | void ERR_load_X509_strings() | ||
| 118 | { | ||
| 119 | static int init=1; | ||
| 120 | |||
| 121 | if (init); | ||
| 122 | {; | ||
| 123 | init=0; | ||
| 124 | #ifndef NO_ERR | ||
| 125 | ERR_load_strings(ERR_LIB_X509,X509_str_functs); | ||
| 126 | ERR_load_strings(ERR_LIB_X509,X509_str_reasons); | ||
| 127 | #endif | ||
| 128 | |||
| 129 | } | ||
| 130 | } | ||
diff --git a/src/lib/libcrypto/x509/x509_ext.c b/src/lib/libcrypto/x509/x509_ext.c new file mode 100644 index 0000000000..1d76ecfcfd --- /dev/null +++ b/src/lib/libcrypto/x509/x509_ext.c | |||
| @@ -0,0 +1,222 @@ | |||
| 1 | /* crypto/x509/x509_ext.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 "stack.h" | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "asn1.h" | ||
| 63 | #include "objects.h" | ||
| 64 | #include "evp.h" | ||
| 65 | #include "x509.h" | ||
| 66 | |||
| 67 | int X509_CRL_get_ext_count(x) | ||
| 68 | X509_CRL *x; | ||
| 69 | { | ||
| 70 | return(X509v3_get_ext_count(x->crl->extensions)); | ||
| 71 | } | ||
| 72 | |||
| 73 | int X509_CRL_get_ext_by_NID(x,nid,lastpos) | ||
| 74 | X509_CRL *x; | ||
| 75 | int nid; | ||
| 76 | int lastpos; | ||
| 77 | { | ||
| 78 | return(X509v3_get_ext_by_NID(x->crl->extensions,nid,lastpos)); | ||
| 79 | } | ||
| 80 | |||
| 81 | int X509_CRL_get_ext_by_OBJ(x,obj,lastpos) | ||
| 82 | X509_CRL *x; | ||
| 83 | ASN1_OBJECT *obj; | ||
| 84 | int lastpos; | ||
| 85 | { | ||
| 86 | return(X509v3_get_ext_by_OBJ(x->crl->extensions,obj,lastpos)); | ||
| 87 | } | ||
| 88 | |||
| 89 | int X509_CRL_get_ext_by_critical(x,crit,lastpos) | ||
| 90 | X509_CRL *x; | ||
| 91 | int crit; | ||
| 92 | int lastpos; | ||
| 93 | { | ||
| 94 | return(X509v3_get_ext_by_critical(x->crl->extensions,crit,lastpos)); | ||
| 95 | } | ||
| 96 | |||
| 97 | X509_EXTENSION *X509_CRL_get_ext(x,loc) | ||
| 98 | X509_CRL *x; | ||
| 99 | int loc; | ||
| 100 | { | ||
| 101 | return(X509v3_get_ext(x->crl->extensions,loc)); | ||
| 102 | } | ||
| 103 | |||
| 104 | X509_EXTENSION *X509_CRL_delete_ext(x,loc) | ||
| 105 | X509_CRL *x; | ||
| 106 | int loc; | ||
| 107 | { | ||
| 108 | return(X509v3_delete_ext(x->crl->extensions,loc)); | ||
| 109 | } | ||
| 110 | |||
| 111 | int X509_CRL_add_ext(x,ex,loc) | ||
| 112 | X509_CRL *x; | ||
| 113 | X509_EXTENSION *ex; | ||
| 114 | int loc; | ||
| 115 | { | ||
| 116 | return(X509v3_add_ext(&(x->crl->extensions),ex,loc) != NULL); | ||
| 117 | } | ||
| 118 | |||
| 119 | int X509_get_ext_count(x) | ||
| 120 | X509 *x; | ||
| 121 | { | ||
| 122 | return(X509v3_get_ext_count(x->cert_info->extensions)); | ||
| 123 | } | ||
| 124 | |||
| 125 | int X509_get_ext_by_NID(x,nid,lastpos) | ||
| 126 | X509 *x; | ||
| 127 | int nid; | ||
| 128 | int lastpos; | ||
| 129 | { | ||
| 130 | return(X509v3_get_ext_by_NID(x->cert_info->extensions,nid,lastpos)); | ||
| 131 | } | ||
| 132 | |||
| 133 | int X509_get_ext_by_OBJ(x,obj,lastpos) | ||
| 134 | X509 *x; | ||
| 135 | ASN1_OBJECT *obj; | ||
| 136 | int lastpos; | ||
| 137 | { | ||
| 138 | return(X509v3_get_ext_by_OBJ(x->cert_info->extensions,obj,lastpos)); | ||
| 139 | } | ||
| 140 | |||
| 141 | int X509_get_ext_by_critical(x,crit,lastpos) | ||
| 142 | X509 *x; | ||
| 143 | int crit; | ||
| 144 | int lastpos; | ||
| 145 | { | ||
| 146 | return(X509v3_get_ext_by_critical(x->cert_info->extensions,crit,lastpos)); | ||
| 147 | } | ||
| 148 | |||
| 149 | X509_EXTENSION *X509_get_ext(x,loc) | ||
| 150 | X509 *x; | ||
| 151 | int loc; | ||
| 152 | { | ||
| 153 | return(X509v3_get_ext(x->cert_info->extensions,loc)); | ||
| 154 | } | ||
| 155 | |||
| 156 | X509_EXTENSION *X509_delete_ext(x,loc) | ||
| 157 | X509 *x; | ||
| 158 | int loc; | ||
| 159 | { | ||
| 160 | return(X509v3_delete_ext(x->cert_info->extensions,loc)); | ||
| 161 | } | ||
| 162 | |||
| 163 | int X509_add_ext(x,ex,loc) | ||
| 164 | X509 *x; | ||
| 165 | X509_EXTENSION *ex; | ||
| 166 | int loc; | ||
| 167 | { | ||
| 168 | return(X509v3_add_ext(&(x->cert_info->extensions),ex,loc) != NULL); | ||
| 169 | } | ||
| 170 | |||
| 171 | int X509_REVOKED_get_ext_count(x) | ||
| 172 | X509_REVOKED *x; | ||
| 173 | { | ||
| 174 | return(X509v3_get_ext_count(x->extensions)); | ||
| 175 | } | ||
| 176 | |||
| 177 | int X509_REVOKED_get_ext_by_NID(x,nid,lastpos) | ||
| 178 | X509_REVOKED *x; | ||
| 179 | int nid; | ||
| 180 | int lastpos; | ||
| 181 | { | ||
| 182 | return(X509v3_get_ext_by_NID(x->extensions,nid,lastpos)); | ||
| 183 | } | ||
| 184 | |||
| 185 | int X509_REVOKED_get_ext_by_OBJ(x,obj,lastpos) | ||
| 186 | X509_REVOKED *x; | ||
| 187 | ASN1_OBJECT *obj; | ||
| 188 | int lastpos; | ||
| 189 | { | ||
| 190 | return(X509v3_get_ext_by_OBJ(x->extensions,obj,lastpos)); | ||
| 191 | } | ||
| 192 | |||
| 193 | int X509_REVOKED_get_ext_by_critical(x,crit,lastpos) | ||
| 194 | X509_REVOKED *x; | ||
| 195 | int crit; | ||
| 196 | int lastpos; | ||
| 197 | { | ||
| 198 | return(X509v3_get_ext_by_critical(x->extensions,crit,lastpos)); | ||
| 199 | } | ||
| 200 | |||
| 201 | X509_EXTENSION *X509_REVOKED_get_ext(x,loc) | ||
| 202 | X509_REVOKED *x; | ||
| 203 | int loc; | ||
| 204 | { | ||
| 205 | return(X509v3_get_ext(x->extensions,loc)); | ||
| 206 | } | ||
| 207 | |||
| 208 | X509_EXTENSION *X509_REVOKED_delete_ext(x,loc) | ||
| 209 | X509_REVOKED *x; | ||
| 210 | int loc; | ||
| 211 | { | ||
| 212 | return(X509v3_delete_ext(x->extensions,loc)); | ||
| 213 | } | ||
| 214 | |||
| 215 | int X509_REVOKED_add_ext(x,ex,loc) | ||
| 216 | X509_REVOKED *x; | ||
| 217 | X509_EXTENSION *ex; | ||
| 218 | int loc; | ||
| 219 | { | ||
| 220 | return(X509v3_add_ext(&(x->extensions),ex,loc) != NULL); | ||
| 221 | } | ||
| 222 | |||
diff --git a/src/lib/libcrypto/x509/x509_lu.c b/src/lib/libcrypto/x509/x509_lu.c new file mode 100644 index 0000000000..2c7e10a46e --- /dev/null +++ b/src/lib/libcrypto/x509/x509_lu.c | |||
| @@ -0,0 +1,446 @@ | |||
| 1 | /* crypto/x509/x509_lu.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 "lhash.h" | ||
| 62 | #include "x509.h" | ||
| 63 | |||
| 64 | static STACK *x509_store_meth=NULL; | ||
| 65 | static STACK *x509_store_ctx_meth=NULL; | ||
| 66 | |||
| 67 | X509_LOOKUP *X509_LOOKUP_new(method) | ||
| 68 | X509_LOOKUP_METHOD *method; | ||
| 69 | { | ||
| 70 | X509_LOOKUP *ret; | ||
| 71 | |||
| 72 | ret=(X509_LOOKUP *)Malloc(sizeof(X509_LOOKUP)); | ||
| 73 | if (ret == NULL) return(NULL); | ||
| 74 | |||
| 75 | ret->init=0; | ||
| 76 | ret->skip=0; | ||
| 77 | ret->method=method; | ||
| 78 | ret->method_data=NULL; | ||
| 79 | ret->store_ctx=NULL; | ||
| 80 | if ((method->new_item != NULL) && !method->new_item(ret)) | ||
| 81 | { | ||
| 82 | Free(ret); | ||
| 83 | return(NULL); | ||
| 84 | } | ||
| 85 | return(ret); | ||
| 86 | } | ||
| 87 | |||
| 88 | void X509_LOOKUP_free(ctx) | ||
| 89 | X509_LOOKUP *ctx; | ||
| 90 | { | ||
| 91 | if (ctx == NULL) return; | ||
| 92 | if ( (ctx->method != NULL) && | ||
| 93 | (ctx->method->free != NULL)) | ||
| 94 | ctx->method->free(ctx); | ||
| 95 | Free(ctx); | ||
| 96 | } | ||
| 97 | |||
| 98 | int X509_LOOKUP_init(ctx) | ||
| 99 | X509_LOOKUP *ctx; | ||
| 100 | { | ||
| 101 | if (ctx->method == NULL) return(0); | ||
| 102 | if (ctx->method->init != NULL) | ||
| 103 | return(ctx->method->init(ctx)); | ||
| 104 | else | ||
| 105 | return(1); | ||
| 106 | } | ||
| 107 | |||
| 108 | int X509_LOOKUP_shutdown(ctx) | ||
| 109 | X509_LOOKUP *ctx; | ||
| 110 | { | ||
| 111 | if (ctx->method == NULL) return(0); | ||
| 112 | if (ctx->method->init != NULL) | ||
| 113 | return(ctx->method->shutdown(ctx)); | ||
| 114 | else | ||
| 115 | return(1); | ||
| 116 | } | ||
| 117 | |||
| 118 | int X509_LOOKUP_ctrl(ctx,cmd,argc,argl,ret) | ||
| 119 | X509_LOOKUP *ctx; | ||
| 120 | int cmd; | ||
| 121 | char *argc; | ||
| 122 | long argl; | ||
| 123 | char **ret; | ||
| 124 | { | ||
| 125 | if (ctx->method == NULL) return(-1); | ||
| 126 | if (ctx->method->ctrl != NULL) | ||
| 127 | return(ctx->method->ctrl(ctx,cmd,argc,argl,ret)); | ||
| 128 | else | ||
| 129 | return(1); | ||
| 130 | } | ||
| 131 | |||
| 132 | int X509_LOOKUP_by_subject(ctx,type,name,ret) | ||
| 133 | X509_LOOKUP *ctx; | ||
| 134 | int type; | ||
| 135 | X509_NAME *name; | ||
| 136 | X509_OBJECT *ret; | ||
| 137 | { | ||
| 138 | if ((ctx->method == NULL) || (ctx->method->get_by_subject == NULL)) | ||
| 139 | return(X509_LU_FAIL); | ||
| 140 | if (ctx->skip) return(0); | ||
| 141 | return(ctx->method->get_by_subject(ctx,type,name,ret)); | ||
| 142 | } | ||
| 143 | |||
| 144 | int X509_LOOKUP_by_issuer_serial(ctx,type,name,serial,ret) | ||
| 145 | X509_LOOKUP *ctx; | ||
| 146 | int type; | ||
| 147 | X509_NAME *name; | ||
| 148 | ASN1_INTEGER *serial; | ||
| 149 | X509_OBJECT *ret; | ||
| 150 | { | ||
| 151 | if ((ctx->method == NULL) || | ||
| 152 | (ctx->method->get_by_issuer_serial == NULL)) | ||
| 153 | return(X509_LU_FAIL); | ||
| 154 | return(ctx->method->get_by_issuer_serial(ctx,type,name,serial,ret)); | ||
| 155 | } | ||
| 156 | |||
| 157 | int X509_LOOKUP_by_fingerprint(ctx,type,bytes,len,ret) | ||
| 158 | X509_LOOKUP *ctx; | ||
| 159 | int type; | ||
| 160 | unsigned char *bytes; | ||
| 161 | int len; | ||
| 162 | X509_OBJECT *ret; | ||
| 163 | { | ||
| 164 | if ((ctx->method == NULL) || (ctx->method->get_by_fingerprint == NULL)) | ||
| 165 | return(X509_LU_FAIL); | ||
| 166 | return(ctx->method->get_by_fingerprint(ctx,type,bytes,len,ret)); | ||
| 167 | } | ||
| 168 | |||
| 169 | int X509_LOOKUP_by_alias(ctx,type,str,len,ret) | ||
| 170 | X509_LOOKUP *ctx; | ||
| 171 | int type; | ||
| 172 | char *str; | ||
| 173 | int len; | ||
| 174 | X509_OBJECT *ret; | ||
| 175 | { | ||
| 176 | if ((ctx->method == NULL) || (ctx->method->get_by_alias == NULL)) | ||
| 177 | return(X509_LU_FAIL); | ||
| 178 | return(ctx->method->get_by_alias(ctx,str,len,ret)); | ||
| 179 | } | ||
| 180 | |||
| 181 | static unsigned long x509_object_hash(a) | ||
| 182 | X509_OBJECT *a; | ||
| 183 | { | ||
| 184 | unsigned long h; | ||
| 185 | |||
| 186 | switch (a->type) | ||
| 187 | { | ||
| 188 | case X509_LU_X509: | ||
| 189 | h=X509_NAME_hash(a->data.x509->cert_info->subject); | ||
| 190 | break; | ||
| 191 | case X509_LU_CRL: | ||
| 192 | h=X509_NAME_hash(a->data.crl->crl->issuer); | ||
| 193 | break; | ||
| 194 | default: | ||
| 195 | abort(); | ||
| 196 | } | ||
| 197 | return(h); | ||
| 198 | } | ||
| 199 | |||
| 200 | static int x509_object_cmp(a,b) | ||
| 201 | X509_OBJECT *a,*b; | ||
| 202 | { | ||
| 203 | int ret; | ||
| 204 | |||
| 205 | ret=(a->type - b->type); | ||
| 206 | if (ret) return(ret); | ||
| 207 | switch (a->type) | ||
| 208 | { | ||
| 209 | case X509_LU_X509: | ||
| 210 | ret=X509_subject_name_cmp(a->data.x509,b->data.x509); | ||
| 211 | break; | ||
| 212 | case X509_LU_CRL: | ||
| 213 | ret=X509_CRL_cmp(a->data.crl,b->data.crl); | ||
| 214 | break; | ||
| 215 | default: | ||
| 216 | abort(); | ||
| 217 | } | ||
| 218 | return(ret); | ||
| 219 | } | ||
| 220 | |||
| 221 | X509_STORE *X509_STORE_new() | ||
| 222 | { | ||
| 223 | X509_STORE *ret; | ||
| 224 | |||
| 225 | if ((ret=(X509_STORE *)Malloc(sizeof(X509_STORE))) == NULL) | ||
| 226 | return(NULL); | ||
| 227 | ret->certs=lh_new(x509_object_hash,x509_object_cmp); | ||
| 228 | ret->cache=1; | ||
| 229 | ret->get_cert_methods=sk_new_null(); | ||
| 230 | ret->verify=NULL; | ||
| 231 | ret->verify_cb=NULL; | ||
| 232 | memset(&ret->ex_data,0,sizeof(CRYPTO_EX_DATA)); | ||
| 233 | ret->references=1; | ||
| 234 | return(ret); | ||
| 235 | } | ||
| 236 | |||
| 237 | static void cleanup(a) | ||
| 238 | X509_OBJECT *a; | ||
| 239 | { | ||
| 240 | if (a->type == X509_LU_X509) | ||
| 241 | { | ||
| 242 | X509_free(a->data.x509); | ||
| 243 | } | ||
| 244 | else if (a->type == X509_LU_CRL) | ||
| 245 | { | ||
| 246 | X509_CRL_free(a->data.crl); | ||
| 247 | } | ||
| 248 | else | ||
| 249 | abort(); | ||
| 250 | |||
| 251 | Free(a); | ||
| 252 | } | ||
| 253 | |||
| 254 | void X509_STORE_free(vfy) | ||
| 255 | X509_STORE *vfy; | ||
| 256 | { | ||
| 257 | int i; | ||
| 258 | STACK *sk; | ||
| 259 | X509_LOOKUP *lu; | ||
| 260 | |||
| 261 | sk=vfy->get_cert_methods; | ||
| 262 | for (i=0; i<sk_num(sk); i++) | ||
| 263 | { | ||
| 264 | lu=(X509_LOOKUP *)sk_value(sk,i); | ||
| 265 | X509_LOOKUP_shutdown(lu); | ||
| 266 | X509_LOOKUP_free(lu); | ||
| 267 | } | ||
| 268 | sk_free(sk); | ||
| 269 | |||
| 270 | CRYPTO_free_ex_data(x509_store_meth,(char *)vfy,&vfy->ex_data); | ||
| 271 | lh_doall(vfy->certs,cleanup); | ||
| 272 | lh_free(vfy->certs); | ||
| 273 | Free(vfy); | ||
| 274 | } | ||
| 275 | |||
| 276 | X509_LOOKUP *X509_STORE_add_lookup(v,m) | ||
| 277 | X509_STORE *v; | ||
| 278 | X509_LOOKUP_METHOD *m; | ||
| 279 | { | ||
| 280 | int i; | ||
| 281 | STACK *sk; | ||
| 282 | X509_LOOKUP *lu; | ||
| 283 | |||
| 284 | sk=v->get_cert_methods; | ||
| 285 | for (i=0; i<sk_num(sk); i++) | ||
| 286 | { | ||
| 287 | lu=(X509_LOOKUP *)sk_value(sk,i); | ||
| 288 | if (m == lu->method) | ||
| 289 | { | ||
| 290 | return(lu); | ||
| 291 | } | ||
| 292 | } | ||
| 293 | /* a new one */ | ||
| 294 | lu=X509_LOOKUP_new(m); | ||
| 295 | if (lu == NULL) | ||
| 296 | return(NULL); | ||
| 297 | else | ||
| 298 | { | ||
| 299 | lu->store_ctx=v; | ||
| 300 | if (sk_push(v->get_cert_methods,(char *)lu)) | ||
| 301 | return(lu); | ||
| 302 | else | ||
| 303 | { | ||
| 304 | X509_LOOKUP_free(lu); | ||
| 305 | return(NULL); | ||
| 306 | } | ||
| 307 | } | ||
| 308 | } | ||
| 309 | |||
| 310 | int X509_STORE_get_by_subject(vs,type,name,ret) | ||
| 311 | X509_STORE_CTX *vs; | ||
| 312 | int type; | ||
| 313 | X509_NAME *name; | ||
| 314 | X509_OBJECT *ret; | ||
| 315 | { | ||
| 316 | X509_STORE *ctx=vs->ctx; | ||
| 317 | X509_LOOKUP *lu; | ||
| 318 | X509_OBJECT stmp,*tmp; | ||
| 319 | int i,j; | ||
| 320 | |||
| 321 | tmp=X509_OBJECT_retrive_by_subject(ctx->certs,type,name); | ||
| 322 | |||
| 323 | if (tmp == NULL) | ||
| 324 | { | ||
| 325 | for (i=vs->current_method; i<sk_num(ctx->get_cert_methods); i++) | ||
| 326 | { | ||
| 327 | lu=(X509_LOOKUP *)sk_value(ctx->get_cert_methods,i); | ||
| 328 | j=X509_LOOKUP_by_subject(lu,type,name,&stmp); | ||
| 329 | if (j < 0) | ||
| 330 | { | ||
| 331 | vs->current_method=j; | ||
| 332 | return(j); | ||
| 333 | } | ||
| 334 | else if (j) | ||
| 335 | { | ||
| 336 | tmp= &stmp; | ||
| 337 | break; | ||
| 338 | } | ||
| 339 | } | ||
| 340 | vs->current_method=0; | ||
| 341 | if (tmp == NULL) | ||
| 342 | return(0); | ||
| 343 | } | ||
| 344 | |||
| 345 | /* if (ret->data.ptr != NULL) | ||
| 346 | X509_OBJECT_free_contents(ret); */ | ||
| 347 | |||
| 348 | ret->type=tmp->type; | ||
| 349 | ret->data.ptr=tmp->data.ptr; | ||
| 350 | |||
| 351 | X509_OBJECT_up_ref_count(ret); | ||
| 352 | |||
| 353 | return(1); | ||
| 354 | } | ||
| 355 | |||
| 356 | void X509_OBJECT_up_ref_count(a) | ||
| 357 | X509_OBJECT *a; | ||
| 358 | { | ||
| 359 | switch (a->type) | ||
| 360 | { | ||
| 361 | case X509_LU_X509: | ||
| 362 | CRYPTO_add(&a->data.x509->references,1,CRYPTO_LOCK_X509); | ||
| 363 | break; | ||
| 364 | case X509_LU_CRL: | ||
| 365 | CRYPTO_add(&a->data.crl->references,1,CRYPTO_LOCK_X509_CRL); | ||
| 366 | break; | ||
| 367 | } | ||
| 368 | } | ||
| 369 | |||
| 370 | void X509_OBJECT_free_contents(a) | ||
| 371 | X509_OBJECT *a; | ||
| 372 | { | ||
| 373 | switch (a->type) | ||
| 374 | { | ||
| 375 | case X509_LU_X509: | ||
| 376 | X509_free(a->data.x509); | ||
| 377 | break; | ||
| 378 | case X509_LU_CRL: | ||
| 379 | X509_CRL_free(a->data.crl); | ||
| 380 | break; | ||
| 381 | } | ||
| 382 | } | ||
| 383 | |||
| 384 | X509_OBJECT *X509_OBJECT_retrive_by_subject(h,type,name) | ||
| 385 | LHASH *h; | ||
| 386 | int type; | ||
| 387 | X509_NAME *name; | ||
| 388 | { | ||
| 389 | X509_OBJECT stmp,*tmp; | ||
| 390 | X509 x509_s; | ||
| 391 | X509_CINF cinf_s; | ||
| 392 | X509_CRL crl_s; | ||
| 393 | X509_CRL_INFO crl_info_s; | ||
| 394 | |||
| 395 | stmp.type=type; | ||
| 396 | switch (type) | ||
| 397 | { | ||
| 398 | case X509_LU_X509: | ||
| 399 | stmp.data.x509= &x509_s; | ||
| 400 | x509_s.cert_info= &cinf_s; | ||
| 401 | cinf_s.subject=name; | ||
| 402 | break; | ||
| 403 | case X509_LU_CRL: | ||
| 404 | stmp.data.crl= &crl_s; | ||
| 405 | crl_s.crl= &crl_info_s; | ||
| 406 | crl_info_s.issuer=name; | ||
| 407 | break; | ||
| 408 | default: | ||
| 409 | abort(); | ||
| 410 | } | ||
| 411 | |||
| 412 | tmp=(X509_OBJECT *)lh_retrieve(h,(char *)&stmp); | ||
| 413 | return(tmp); | ||
| 414 | } | ||
| 415 | |||
| 416 | void X509_STORE_CTX_init(ctx,store,x509,chain) | ||
| 417 | X509_STORE_CTX *ctx; | ||
| 418 | X509_STORE *store; | ||
| 419 | X509 *x509; | ||
| 420 | STACK *chain; | ||
| 421 | { | ||
| 422 | ctx->ctx=store; | ||
| 423 | ctx->current_method=0; | ||
| 424 | ctx->cert=x509; | ||
| 425 | ctx->untrusted=chain; | ||
| 426 | ctx->last_untrusted=0; | ||
| 427 | ctx->valid=0; | ||
| 428 | ctx->chain=NULL; | ||
| 429 | ctx->depth=10; | ||
| 430 | ctx->error=0; | ||
| 431 | ctx->current_cert=NULL; | ||
| 432 | memset(&(ctx->ex_data),0,sizeof(CRYPTO_EX_DATA)); | ||
| 433 | } | ||
| 434 | |||
| 435 | void X509_STORE_CTX_cleanup(ctx) | ||
| 436 | X509_STORE_CTX *ctx; | ||
| 437 | { | ||
| 438 | if (ctx->chain != NULL) | ||
| 439 | { | ||
| 440 | sk_pop_free(ctx->chain,X509_free); | ||
| 441 | ctx->chain=NULL; | ||
| 442 | } | ||
| 443 | CRYPTO_free_ex_data(x509_store_ctx_meth,(char *)ctx,&(ctx->ex_data)); | ||
| 444 | memset(&ctx->ex_data,0,sizeof(CRYPTO_EX_DATA)); | ||
| 445 | } | ||
| 446 | |||
diff --git a/src/lib/libcrypto/x509/x509_obj.c b/src/lib/libcrypto/x509/x509_obj.c new file mode 100644 index 0000000000..c0576fd6f6 --- /dev/null +++ b/src/lib/libcrypto/x509/x509_obj.c | |||
| @@ -0,0 +1,179 @@ | |||
| 1 | /* crypto/x509/x509_obj.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 "lhash.h" | ||
| 62 | #include "objects.h" | ||
| 63 | #include "x509.h" | ||
| 64 | #include "buffer.h" | ||
| 65 | |||
| 66 | char *X509_NAME_oneline(a,buf,len) | ||
| 67 | X509_NAME *a; | ||
| 68 | char *buf; | ||
| 69 | int len; | ||
| 70 | { | ||
| 71 | X509_NAME_ENTRY *ne; | ||
| 72 | unsigned int i; | ||
| 73 | int n,lold,l,l1,l2,num,j,type; | ||
| 74 | char *s,*p; | ||
| 75 | unsigned char *q; | ||
| 76 | BUF_MEM *b=NULL; | ||
| 77 | static char hex[17]="0123456789ABCDEF"; | ||
| 78 | int gs_doit[4]; | ||
| 79 | char tmp_buf[80]; | ||
| 80 | |||
| 81 | if (a == NULL) return("NO X509_NAME"); | ||
| 82 | if (buf == NULL) | ||
| 83 | { | ||
| 84 | if ((b=BUF_MEM_new()) == NULL) goto err; | ||
| 85 | if (!BUF_MEM_grow(b,200)) goto err; | ||
| 86 | b->data[0]='\0'; | ||
| 87 | len=200; | ||
| 88 | } | ||
| 89 | |||
| 90 | len--; /* space for '\0' */ | ||
| 91 | l=0; | ||
| 92 | for (i=0; (int)i<sk_num(a->entries); i++) | ||
| 93 | { | ||
| 94 | ne=(X509_NAME_ENTRY *)sk_value(a->entries,i); | ||
| 95 | n=OBJ_obj2nid(ne->object); | ||
| 96 | if ((n == NID_undef) || ((s=OBJ_nid2sn(n)) == NULL)) | ||
| 97 | { | ||
| 98 | i2t_ASN1_OBJECT(tmp_buf,sizeof(tmp_buf),ne->object); | ||
| 99 | s=tmp_buf; | ||
| 100 | } | ||
| 101 | l1=strlen(s); | ||
| 102 | |||
| 103 | type=ne->value->type; | ||
| 104 | num=ne->value->length; | ||
| 105 | q=ne->value->data; | ||
| 106 | |||
| 107 | if ((type == V_ASN1_GENERALSTRING) && ((num%4) == 0)) | ||
| 108 | { | ||
| 109 | gs_doit[0]=gs_doit[1]=gs_doit[2]=gs_doit[3]=0; | ||
| 110 | for (j=0; j<num; j++) | ||
| 111 | if (q[j] != 0) gs_doit[j&3]=1; | ||
| 112 | |||
| 113 | if (gs_doit[0]|gs_doit[1]|gs_doit[2]) | ||
| 114 | gs_doit[0]=gs_doit[1]=gs_doit[2]=gs_doit[3]=1; | ||
| 115 | else | ||
| 116 | { | ||
| 117 | gs_doit[0]=gs_doit[1]=gs_doit[2]=0; | ||
| 118 | gs_doit[3]=1; | ||
| 119 | } | ||
| 120 | } | ||
| 121 | else | ||
| 122 | gs_doit[0]=gs_doit[1]=gs_doit[2]=gs_doit[3]=1; | ||
| 123 | |||
| 124 | for (l2=j=0; j<num; j++) | ||
| 125 | { | ||
| 126 | if (!gs_doit[j&3]) continue; | ||
| 127 | l2++; | ||
| 128 | if ((q[j] < ' ') || (q[j] > '~')) l2+=3; | ||
| 129 | } | ||
| 130 | |||
| 131 | lold=l; | ||
| 132 | l+=1+l1+1+l2; | ||
| 133 | if (b != NULL) | ||
| 134 | { | ||
| 135 | if (!BUF_MEM_grow(b,l+1)) goto err; | ||
| 136 | p= &(b->data[lold]); | ||
| 137 | } | ||
| 138 | else if (l > len) | ||
| 139 | { | ||
| 140 | break; | ||
| 141 | } | ||
| 142 | else | ||
| 143 | p= &(buf[lold]); | ||
| 144 | *(p++)='/'; | ||
| 145 | memcpy(p,s,(unsigned int)l1); p+=l1; | ||
| 146 | *(p++)='='; | ||
| 147 | |||
| 148 | q=ne->value->data; | ||
| 149 | |||
| 150 | for (j=0; j<num; j++) | ||
| 151 | { | ||
| 152 | if (!gs_doit[j&3]) continue; | ||
| 153 | n=q[j]; | ||
| 154 | if ((n < ' ') || (n > '~')) | ||
| 155 | { | ||
| 156 | *(p++)='\\'; | ||
| 157 | *(p++)='x'; | ||
| 158 | *(p++)=hex[(n>>4)&0x0f]; | ||
| 159 | *(p++)=hex[n&0x0f]; | ||
| 160 | } | ||
| 161 | else | ||
| 162 | *(p++)=n; | ||
| 163 | } | ||
| 164 | *p='\0'; | ||
| 165 | } | ||
| 166 | if (b != NULL) | ||
| 167 | { | ||
| 168 | p=b->data; | ||
| 169 | Free((char *)b); | ||
| 170 | } | ||
| 171 | else | ||
| 172 | p=buf; | ||
| 173 | return(p); | ||
| 174 | err: | ||
| 175 | X509err(X509_F_X509_NAME_ONELINE,ERR_R_MALLOC_FAILURE); | ||
| 176 | if (b != NULL) BUF_MEM_free(b); | ||
| 177 | return(NULL); | ||
| 178 | } | ||
| 179 | |||
diff --git a/src/lib/libcrypto/x509/x509_r2x.c b/src/lib/libcrypto/x509/x509_r2x.c new file mode 100644 index 0000000000..6aec2427f7 --- /dev/null +++ b/src/lib/libcrypto/x509/x509_r2x.c | |||
| @@ -0,0 +1,122 @@ | |||
| 1 | /* crypto/x509/x509_r2x.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 "evp.h" | ||
| 63 | #include "asn1.h" | ||
| 64 | #include "x509.h" | ||
| 65 | #include "objects.h" | ||
| 66 | #include "buffer.h" | ||
| 67 | #include "pem.h" | ||
| 68 | |||
| 69 | X509 *X509_REQ_to_X509(r,days,pkey) | ||
| 70 | X509_REQ *r; | ||
| 71 | int days; | ||
| 72 | EVP_PKEY *pkey; | ||
| 73 | { | ||
| 74 | X509 *ret=NULL; | ||
| 75 | int er=1; | ||
| 76 | X509_REQ_INFO *ri=NULL; | ||
| 77 | X509_CINF *xi=NULL; | ||
| 78 | X509_NAME *xn; | ||
| 79 | |||
| 80 | if ((ret=X509_new()) == NULL) | ||
| 81 | { | ||
| 82 | X509err(X509_F_X509_REQ_TO_X509,ERR_R_MALLOC_FAILURE); | ||
| 83 | goto err; | ||
| 84 | } | ||
| 85 | |||
| 86 | /* duplicate the request */ | ||
| 87 | ri=(X509_REQ_INFO *)ASN1_dup(i2d_X509_REQ_INFO, | ||
| 88 | (char *(*)())d2i_X509_REQ_INFO,(char *)r->req_info); | ||
| 89 | if (ri == NULL) goto err; | ||
| 90 | |||
| 91 | xi=ret->cert_info; | ||
| 92 | |||
| 93 | if (sk_num(ri->attributes) != 0) | ||
| 94 | { | ||
| 95 | if ((xi->version=ASN1_INTEGER_new()) == NULL) goto err; | ||
| 96 | if (!ASN1_INTEGER_set(xi->version,2)) goto err; | ||
| 97 | /* xi->extensions=ri->attributes; <- bad, should not ever be done | ||
| 98 | ri->attributes=NULL; */ | ||
| 99 | } | ||
| 100 | |||
| 101 | xn=X509_REQ_get_subject_name(r); | ||
| 102 | X509_set_subject_name(ret,X509_NAME_dup(xn)); | ||
| 103 | X509_set_issuer_name(ret,X509_NAME_dup(xn)); | ||
| 104 | |||
| 105 | X509_gmtime_adj(xi->validity->notBefore,0); | ||
| 106 | X509_gmtime_adj(xi->validity->notAfter,(long)60*60*24*days); | ||
| 107 | |||
| 108 | X509_set_pubkey(ret,X509_REQ_get_pubkey(r)); | ||
| 109 | |||
| 110 | if (!X509_sign(ret,pkey,EVP_md5())) | ||
| 111 | goto err; | ||
| 112 | er=0; | ||
| 113 | err: | ||
| 114 | if (er) | ||
| 115 | { | ||
| 116 | X509_free(ret); | ||
| 117 | X509_REQ_INFO_free(ri); | ||
| 118 | return(NULL); | ||
| 119 | } | ||
| 120 | return(ret); | ||
| 121 | } | ||
| 122 | |||
diff --git a/src/lib/libcrypto/x509/x509_req.c b/src/lib/libcrypto/x509/x509_req.c new file mode 100644 index 0000000000..5004365bad --- /dev/null +++ b/src/lib/libcrypto/x509/x509_req.c | |||
| @@ -0,0 +1,116 @@ | |||
| 1 | /* crypto/x509/x509_req.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 "evp.h" | ||
| 63 | #include "asn1.h" | ||
| 64 | #include "x509.h" | ||
| 65 | #include "objects.h" | ||
| 66 | #include "buffer.h" | ||
| 67 | #include "pem.h" | ||
| 68 | |||
| 69 | X509_REQ *X509_to_X509_REQ(x,pkey,md) | ||
| 70 | X509 *x; | ||
| 71 | EVP_PKEY *pkey; | ||
| 72 | EVP_MD *md; | ||
| 73 | { | ||
| 74 | X509_REQ *ret; | ||
| 75 | X509_REQ_INFO *ri; | ||
| 76 | int i; | ||
| 77 | |||
| 78 | ret=X509_REQ_new(); | ||
| 79 | if (ret == NULL) | ||
| 80 | { | ||
| 81 | X509err(X509_F_X509_TO_X509_REQ,ERR_R_MALLOC_FAILURE); | ||
| 82 | goto err; | ||
| 83 | } | ||
| 84 | |||
| 85 | ri=ret->req_info; | ||
| 86 | |||
| 87 | ri->version->length=1; | ||
| 88 | ri->version->data=(unsigned char *)Malloc(1); | ||
| 89 | if (ri->version->data == NULL) goto err; | ||
| 90 | ri->version->data[0]=0; /* version == 0 */ | ||
| 91 | |||
| 92 | if (!X509_REQ_set_subject_name(ret,X509_get_subject_name(x))) | ||
| 93 | goto err; | ||
| 94 | |||
| 95 | i=X509_REQ_set_pubkey(ret,X509_get_pubkey(x)); | ||
| 96 | if (!i) goto err; | ||
| 97 | |||
| 98 | if (pkey != NULL) | ||
| 99 | { | ||
| 100 | if (!X509_REQ_sign(ret,pkey,md)) | ||
| 101 | goto err; | ||
| 102 | } | ||
| 103 | return(ret); | ||
| 104 | err: | ||
| 105 | X509_REQ_free(ret); | ||
| 106 | return(NULL); | ||
| 107 | } | ||
| 108 | |||
| 109 | EVP_PKEY *X509_REQ_get_pubkey(req) | ||
| 110 | X509_REQ *req; | ||
| 111 | { | ||
| 112 | if ((req == NULL) || (req->req_info == NULL)) | ||
| 113 | return(NULL); | ||
| 114 | return(X509_PUBKEY_get(req->req_info->pubkey)); | ||
| 115 | } | ||
| 116 | |||
diff --git a/src/lib/libcrypto/x509/x509_set.c b/src/lib/libcrypto/x509/x509_set.c new file mode 100644 index 0000000000..5d0a3a0c0e --- /dev/null +++ b/src/lib/libcrypto/x509/x509_set.c | |||
| @@ -0,0 +1,164 @@ | |||
| 1 | /* crypto/x509/x509_set.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 | #include "objects.h" | ||
| 63 | #include "evp.h" | ||
| 64 | #include "x509.h" | ||
| 65 | |||
| 66 | int X509_set_version(x,version) | ||
| 67 | X509 *x; | ||
| 68 | long version; | ||
| 69 | { | ||
| 70 | if (x == NULL) return(0); | ||
| 71 | if (x->cert_info->version == NULL) | ||
| 72 | { | ||
| 73 | if ((x->cert_info->version=ASN1_INTEGER_new()) == NULL) | ||
| 74 | return(0); | ||
| 75 | } | ||
| 76 | return(ASN1_INTEGER_set(x->cert_info->version,version)); | ||
| 77 | } | ||
| 78 | |||
| 79 | int X509_set_serialNumber(x,serial) | ||
| 80 | X509 *x; | ||
| 81 | ASN1_INTEGER *serial; | ||
| 82 | { | ||
| 83 | ASN1_INTEGER *in; | ||
| 84 | |||
| 85 | if (x == NULL) return(0); | ||
| 86 | in=x->cert_info->serialNumber; | ||
| 87 | if (in != serial) | ||
| 88 | { | ||
| 89 | in=ASN1_INTEGER_dup(serial); | ||
| 90 | if (in != NULL) | ||
| 91 | { | ||
| 92 | ASN1_INTEGER_free(x->cert_info->serialNumber); | ||
| 93 | x->cert_info->serialNumber=in; | ||
| 94 | } | ||
| 95 | } | ||
| 96 | return(in != NULL); | ||
| 97 | } | ||
| 98 | |||
| 99 | int X509_set_issuer_name(x,name) | ||
| 100 | X509 *x; | ||
| 101 | X509_NAME *name; | ||
| 102 | { | ||
| 103 | if ((x == NULL) || (x->cert_info == NULL)) return(0); | ||
| 104 | return(X509_NAME_set(&x->cert_info->issuer,name)); | ||
| 105 | } | ||
| 106 | |||
| 107 | int X509_set_subject_name(x,name) | ||
| 108 | X509 *x; | ||
| 109 | X509_NAME *name; | ||
| 110 | { | ||
| 111 | if ((x == NULL) || (x->cert_info == NULL)) return(0); | ||
| 112 | return(X509_NAME_set(&x->cert_info->subject,name)); | ||
| 113 | } | ||
| 114 | |||
| 115 | int X509_set_notBefore(x,tm) | ||
| 116 | X509 *x; | ||
| 117 | ASN1_UTCTIME *tm; | ||
| 118 | { | ||
| 119 | ASN1_UTCTIME *in; | ||
| 120 | |||
| 121 | if ((x == NULL) || (x->cert_info->validity == NULL)) return(0); | ||
| 122 | in=x->cert_info->validity->notBefore; | ||
| 123 | if (in != tm) | ||
| 124 | { | ||
| 125 | in=ASN1_UTCTIME_dup(tm); | ||
| 126 | if (in != NULL) | ||
| 127 | { | ||
| 128 | ASN1_UTCTIME_free(x->cert_info->validity->notBefore); | ||
| 129 | x->cert_info->validity->notBefore=in; | ||
| 130 | } | ||
| 131 | } | ||
| 132 | return(in != NULL); | ||
| 133 | } | ||
| 134 | |||
| 135 | int X509_set_notAfter(x,tm) | ||
| 136 | X509 *x; | ||
| 137 | ASN1_UTCTIME *tm; | ||
| 138 | { | ||
| 139 | ASN1_UTCTIME *in; | ||
| 140 | |||
| 141 | if ((x == NULL) || (x->cert_info->validity == NULL)) return(0); | ||
| 142 | in=x->cert_info->validity->notAfter; | ||
| 143 | if (in != tm) | ||
| 144 | { | ||
| 145 | in=ASN1_UTCTIME_dup(tm); | ||
| 146 | if (in != NULL) | ||
| 147 | { | ||
| 148 | ASN1_UTCTIME_free(x->cert_info->validity->notAfter); | ||
| 149 | x->cert_info->validity->notAfter=in; | ||
| 150 | } | ||
| 151 | } | ||
| 152 | return(in != NULL); | ||
| 153 | } | ||
| 154 | |||
| 155 | int X509_set_pubkey(x,pkey) | ||
| 156 | X509 *x; | ||
| 157 | EVP_PKEY *pkey; | ||
| 158 | { | ||
| 159 | if ((x == NULL) || (x->cert_info == NULL)) return(0); | ||
| 160 | return(X509_PUBKEY_set(&(x->cert_info->key),pkey)); | ||
| 161 | } | ||
| 162 | |||
| 163 | |||
| 164 | |||
diff --git a/src/lib/libcrypto/x509/x509_txt.c b/src/lib/libcrypto/x509/x509_txt.c new file mode 100644 index 0000000000..408d1c277c --- /dev/null +++ b/src/lib/libcrypto/x509/x509_txt.c | |||
| @@ -0,0 +1,132 @@ | |||
| 1 | /* crypto/x509/x509_txt.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 <time.h> | ||
| 61 | #include <errno.h> | ||
| 62 | #include <sys/types.h> | ||
| 63 | |||
| 64 | #include "cryptlib.h" | ||
| 65 | #include "lhash.h" | ||
| 66 | #include "buffer.h" | ||
| 67 | #include "evp.h" | ||
| 68 | #include "asn1.h" | ||
| 69 | #include "x509.h" | ||
| 70 | #include "objects.h" | ||
| 71 | #include "pem.h" | ||
| 72 | |||
| 73 | char *X509_verify_cert_error_string(n) | ||
| 74 | long n; | ||
| 75 | { | ||
| 76 | static char buf[100]; | ||
| 77 | |||
| 78 | switch ((int)n) | ||
| 79 | { | ||
| 80 | case X509_V_OK: | ||
| 81 | return("ok"); | ||
| 82 | case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT: | ||
| 83 | return("unable to get issuer certificate"); | ||
| 84 | case X509_V_ERR_UNABLE_TO_GET_CRL: | ||
| 85 | return("unable to get certificate CRL"); | ||
| 86 | case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE: | ||
| 87 | return("unable to decrypt certificate's signature"); | ||
| 88 | case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE: | ||
| 89 | return("unable to decrypt CRL's's signature"); | ||
| 90 | case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY: | ||
| 91 | return("unable to decode issuer public key"); | ||
| 92 | case X509_V_ERR_CERT_SIGNATURE_FAILURE: | ||
| 93 | return("certificate signature failure"); | ||
| 94 | case X509_V_ERR_CRL_SIGNATURE_FAILURE: | ||
| 95 | return("CRL signature failure"); | ||
| 96 | case X509_V_ERR_CERT_NOT_YET_VALID: | ||
| 97 | return("certificate is not yet valid"); | ||
| 98 | case X509_V_ERR_CRL_NOT_YET_VALID: | ||
| 99 | return("CRL is not yet valid"); | ||
| 100 | case X509_V_ERR_CERT_HAS_EXPIRED: | ||
| 101 | return("Certificate has expired"); | ||
| 102 | case X509_V_ERR_CRL_HAS_EXPIRED: | ||
| 103 | return("CRL has expired"); | ||
| 104 | case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD: | ||
| 105 | return("format error in certificate's notBefore field"); | ||
| 106 | case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD: | ||
| 107 | return("format error in certificate's notAfter field"); | ||
| 108 | case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD: | ||
| 109 | return("format error in CRL's lastUpdate field"); | ||
| 110 | case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD: | ||
| 111 | return("format error in CRL's nextUpdate field"); | ||
| 112 | case X509_V_ERR_OUT_OF_MEM: | ||
| 113 | return("out of memory"); | ||
| 114 | case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT: | ||
| 115 | return("self signed certificate"); | ||
| 116 | case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN: | ||
| 117 | return("self signed certificate in certificate chain"); | ||
| 118 | case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY: | ||
| 119 | return("unable to get local issuer certificate"); | ||
| 120 | case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE: | ||
| 121 | return("unable to verify the first certificate"); | ||
| 122 | case X509_V_ERR_CERT_CHAIN_TOO_LONG: | ||
| 123 | return("certificate chain too long"); | ||
| 124 | case X509_V_ERR_APPLICATION_VERIFICATION: | ||
| 125 | return("application verification failure"); | ||
| 126 | default: | ||
| 127 | sprintf(buf,"error number %ld",n); | ||
| 128 | return(buf); | ||
| 129 | } | ||
| 130 | } | ||
| 131 | |||
| 132 | |||
diff --git a/src/lib/libcrypto/x509/x509_v3.c b/src/lib/libcrypto/x509/x509_v3.c new file mode 100644 index 0000000000..1c03602f0b --- /dev/null +++ b/src/lib/libcrypto/x509/x509_v3.c | |||
| @@ -0,0 +1,409 @@ | |||
| 1 | /* crypto/x509/x509_v3.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 "stack.h" | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "asn1.h" | ||
| 63 | #include "objects.h" | ||
| 64 | #include "evp.h" | ||
| 65 | #include "x509.h" | ||
| 66 | |||
| 67 | #ifndef NOPROTO | ||
| 68 | static X509_EXTENSION_METHOD *find_by_nid(int nid); | ||
| 69 | static int xem_cmp(X509_EXTENSION_METHOD **a, X509_EXTENSION_METHOD **b); | ||
| 70 | #else | ||
| 71 | static X509_EXTENSION_METHOD *find_by_nid(); | ||
| 72 | static int xem_cmp(); | ||
| 73 | #endif | ||
| 74 | |||
| 75 | static STACK *extensions=NULL; | ||
| 76 | |||
| 77 | int X509v3_get_ext_count(x) | ||
| 78 | STACK *x; | ||
| 79 | { | ||
| 80 | if (x == NULL) return(0); | ||
| 81 | return(sk_num(x)); | ||
| 82 | } | ||
| 83 | |||
| 84 | int X509v3_get_ext_by_NID(x,nid,lastpos) | ||
| 85 | STACK *x; | ||
| 86 | int nid; | ||
| 87 | int lastpos; | ||
| 88 | { | ||
| 89 | ASN1_OBJECT *obj; | ||
| 90 | |||
| 91 | obj=OBJ_nid2obj(nid); | ||
| 92 | if (obj == NULL) return(-2); | ||
| 93 | return(X509v3_get_ext_by_OBJ(x,obj,lastpos)); | ||
| 94 | } | ||
| 95 | |||
| 96 | int X509v3_get_ext_by_OBJ(sk,obj,lastpos) | ||
| 97 | STACK *sk; | ||
| 98 | ASN1_OBJECT *obj; | ||
| 99 | int lastpos; | ||
| 100 | { | ||
| 101 | int n; | ||
| 102 | X509_EXTENSION *ex; | ||
| 103 | |||
| 104 | if (sk == NULL) return(-1); | ||
| 105 | lastpos++; | ||
| 106 | if (lastpos < 0) | ||
| 107 | lastpos=0; | ||
| 108 | n=sk_num(sk); | ||
| 109 | for ( ; lastpos < n; lastpos++) | ||
| 110 | { | ||
| 111 | ex=(X509_EXTENSION *)sk_value(sk,lastpos); | ||
| 112 | if (OBJ_cmp(ex->object,obj) == 0) | ||
| 113 | return(lastpos); | ||
| 114 | } | ||
| 115 | return(-1); | ||
| 116 | } | ||
| 117 | |||
| 118 | int X509v3_get_ext_by_critical(sk,crit,lastpos) | ||
| 119 | STACK *sk; | ||
| 120 | int crit; | ||
| 121 | int lastpos; | ||
| 122 | { | ||
| 123 | int n; | ||
| 124 | X509_EXTENSION *ex; | ||
| 125 | |||
| 126 | if (sk == NULL) return(-1); | ||
| 127 | lastpos++; | ||
| 128 | if (lastpos < 0) | ||
| 129 | lastpos=0; | ||
| 130 | n=sk_num(sk); | ||
| 131 | for ( ; lastpos < n; lastpos++) | ||
| 132 | { | ||
| 133 | ex=(X509_EXTENSION *)sk_value(sk,lastpos); | ||
| 134 | if ( (ex->critical && crit) || | ||
| 135 | (!ex->critical && !crit)) | ||
| 136 | return(lastpos); | ||
| 137 | } | ||
| 138 | return(-1); | ||
| 139 | } | ||
| 140 | |||
| 141 | X509_EXTENSION *X509v3_get_ext(x,loc) | ||
| 142 | STACK *x; | ||
| 143 | int loc; | ||
| 144 | { | ||
| 145 | if ((x == NULL) || (sk_num(x) <= loc) || (loc < 0)) | ||
| 146 | return(NULL); | ||
| 147 | else | ||
| 148 | return((X509_EXTENSION *)sk_value(x,loc)); | ||
| 149 | } | ||
| 150 | |||
| 151 | X509_EXTENSION *X509v3_delete_ext(x,loc) | ||
| 152 | STACK *x; | ||
| 153 | int loc; | ||
| 154 | { | ||
| 155 | X509_EXTENSION *ret; | ||
| 156 | |||
| 157 | if ((x == NULL) || (sk_num(x) <= loc) || (loc < 0)) | ||
| 158 | return(NULL); | ||
| 159 | ret=(X509_EXTENSION *)sk_delete(x,loc); | ||
| 160 | return(ret); | ||
| 161 | } | ||
| 162 | |||
| 163 | STACK *X509v3_add_ext(x,ex,loc) | ||
| 164 | STACK **x; | ||
| 165 | X509_EXTENSION *ex; | ||
| 166 | int loc; | ||
| 167 | { | ||
| 168 | X509_EXTENSION *new_ex=NULL; | ||
| 169 | int n; | ||
| 170 | STACK *sk=NULL; | ||
| 171 | |||
| 172 | if ((x != NULL) && (*x == NULL)) | ||
| 173 | { | ||
| 174 | if ((sk=sk_new_null()) == NULL) | ||
| 175 | goto err; | ||
| 176 | } | ||
| 177 | else | ||
| 178 | sk= *x; | ||
| 179 | |||
| 180 | n=sk_num(sk); | ||
| 181 | if (loc > n) loc=n; | ||
| 182 | else if (loc < 0) loc=n; | ||
| 183 | |||
| 184 | if ((new_ex=X509_EXTENSION_dup(ex)) == NULL) | ||
| 185 | goto err2; | ||
| 186 | if (!sk_insert(sk,(char *)new_ex,loc)) | ||
| 187 | goto err; | ||
| 188 | if ((x != NULL) && (*x == NULL)) | ||
| 189 | *x=sk; | ||
| 190 | return(sk); | ||
| 191 | err: | ||
| 192 | X509err(X509_F_X509V3_ADD_EXT,ERR_R_MALLOC_FAILURE); | ||
| 193 | err2: | ||
| 194 | if (new_ex != NULL) X509_EXTENSION_free(new_ex); | ||
| 195 | if (sk != NULL) sk_free(sk); | ||
| 196 | return(NULL); | ||
| 197 | } | ||
| 198 | |||
| 199 | X509_EXTENSION *X509_EXTENSION_create_by_NID(ex,nid,crit,data) | ||
| 200 | X509_EXTENSION **ex; | ||
| 201 | int nid; | ||
| 202 | int crit; | ||
| 203 | ASN1_OCTET_STRING *data; | ||
| 204 | { | ||
| 205 | ASN1_OBJECT *obj; | ||
| 206 | X509_EXTENSION *ret; | ||
| 207 | |||
| 208 | obj=OBJ_nid2obj(nid); | ||
| 209 | if (obj == NULL) | ||
| 210 | { | ||
| 211 | X509err(X509_F_X509_EXTENSION_CREATE_BY_NID,X509_R_UNKNOWN_NID); | ||
| 212 | return(NULL); | ||
| 213 | } | ||
| 214 | ret=X509_EXTENSION_create_by_OBJ(ex,obj,crit,data); | ||
| 215 | if (ret == NULL) ASN1_OBJECT_free(obj); | ||
| 216 | return(ret); | ||
| 217 | } | ||
| 218 | |||
| 219 | X509_EXTENSION *X509_EXTENSION_create_by_OBJ(ex,obj,crit,data) | ||
| 220 | X509_EXTENSION **ex; | ||
| 221 | ASN1_OBJECT *obj; | ||
| 222 | int crit; | ||
| 223 | ASN1_OCTET_STRING *data; | ||
| 224 | { | ||
| 225 | X509_EXTENSION *ret; | ||
| 226 | |||
| 227 | if ((ex == NULL) || (*ex == NULL)) | ||
| 228 | { | ||
| 229 | if ((ret=X509_EXTENSION_new()) == NULL) | ||
| 230 | { | ||
| 231 | X509err(X509_F_X509_EXTENSION_CREATE_BY_OBJ,ERR_R_MALLOC_FAILURE); | ||
| 232 | return(NULL); | ||
| 233 | } | ||
| 234 | } | ||
| 235 | else | ||
| 236 | ret= *ex; | ||
| 237 | |||
| 238 | if (!X509_EXTENSION_set_object(ret,obj)) | ||
| 239 | goto err; | ||
| 240 | if (!X509_EXTENSION_set_critical(ret,crit)) | ||
| 241 | goto err; | ||
| 242 | if (!X509_EXTENSION_set_data(ret,data)) | ||
| 243 | goto err; | ||
| 244 | |||
| 245 | if ((ex != NULL) && (*ex == NULL)) *ex=ret; | ||
| 246 | return(ret); | ||
| 247 | err: | ||
| 248 | if ((ex == NULL) || (ret != *ex)) | ||
| 249 | X509_EXTENSION_free(ret); | ||
| 250 | return(NULL); | ||
| 251 | } | ||
| 252 | |||
| 253 | int X509_EXTENSION_set_object(ex,obj) | ||
| 254 | X509_EXTENSION *ex; | ||
| 255 | ASN1_OBJECT *obj; | ||
| 256 | { | ||
| 257 | if ((ex == NULL) || (obj == NULL)) | ||
| 258 | return(0); | ||
| 259 | ASN1_OBJECT_free(ex->object); | ||
| 260 | ex->object=OBJ_dup(obj); | ||
| 261 | return(1); | ||
| 262 | } | ||
| 263 | |||
| 264 | int X509_EXTENSION_set_critical(ex,crit) | ||
| 265 | X509_EXTENSION *ex; | ||
| 266 | int crit; | ||
| 267 | { | ||
| 268 | if (ex == NULL) return(0); | ||
| 269 | ex->critical=(crit)?0xFF:0; | ||
| 270 | return(1); | ||
| 271 | } | ||
| 272 | |||
| 273 | int X509_EXTENSION_set_data(ex,data) | ||
| 274 | X509_EXTENSION *ex; | ||
| 275 | ASN1_OCTET_STRING *data; | ||
| 276 | { | ||
| 277 | int i; | ||
| 278 | |||
| 279 | if (ex == NULL) return(0); | ||
| 280 | i=ASN1_OCTET_STRING_set(ex->value,data->data,data->length); | ||
| 281 | if (!i) return(0); | ||
| 282 | return(1); | ||
| 283 | } | ||
| 284 | |||
| 285 | ASN1_OBJECT *X509_EXTENSION_get_object(ex) | ||
| 286 | X509_EXTENSION *ex; | ||
| 287 | { | ||
| 288 | if (ex == NULL) return(NULL); | ||
| 289 | return(ex->object); | ||
| 290 | } | ||
| 291 | |||
| 292 | ASN1_OCTET_STRING *X509_EXTENSION_get_data(ex) | ||
| 293 | X509_EXTENSION *ex; | ||
| 294 | { | ||
| 295 | if (ex == NULL) return(NULL); | ||
| 296 | return(ex->value); | ||
| 297 | } | ||
| 298 | |||
| 299 | int X509_EXTENSION_get_critical(ex) | ||
| 300 | X509_EXTENSION *ex; | ||
| 301 | { | ||
| 302 | if (ex == NULL) return(0); | ||
| 303 | return(ex->critical); | ||
| 304 | } | ||
| 305 | |||
| 306 | int X509v3_data_type_by_OBJ(obj) | ||
| 307 | ASN1_OBJECT *obj; | ||
| 308 | { | ||
| 309 | int nid; | ||
| 310 | |||
| 311 | nid=OBJ_obj2nid(obj); | ||
| 312 | if (nid == V_ASN1_UNDEF) return(V_ASN1_UNDEF); | ||
| 313 | return(X509v3_data_type_by_NID(nid)); | ||
| 314 | } | ||
| 315 | |||
| 316 | int X509v3_data_type_by_NID(nid) | ||
| 317 | int nid; | ||
| 318 | { | ||
| 319 | X509_EXTENSION_METHOD *x; | ||
| 320 | |||
| 321 | x=find_by_nid(nid); | ||
| 322 | if (x == NULL) | ||
| 323 | return(V_ASN1_UNDEF); | ||
| 324 | else | ||
| 325 | return(x->data_type); | ||
| 326 | } | ||
| 327 | |||
| 328 | int X509v3_pack_type_by_OBJ(obj) | ||
| 329 | ASN1_OBJECT *obj; | ||
| 330 | { | ||
| 331 | int nid; | ||
| 332 | |||
| 333 | nid=OBJ_obj2nid(obj); | ||
| 334 | if (nid == NID_undef) return(X509_EXT_PACK_UNKNOWN); | ||
| 335 | return(X509v3_pack_type_by_NID(nid)); | ||
| 336 | } | ||
| 337 | |||
| 338 | int X509v3_pack_type_by_NID(nid) | ||
| 339 | int nid; | ||
| 340 | { | ||
| 341 | X509_EXTENSION_METHOD *x; | ||
| 342 | |||
| 343 | x=find_by_nid(nid); | ||
| 344 | if (x == NULL) | ||
| 345 | return(X509_EXT_PACK_UNKNOWN); | ||
| 346 | else | ||
| 347 | return(x->pack_type); | ||
| 348 | } | ||
| 349 | |||
| 350 | static X509_EXTENSION_METHOD *find_by_nid(nid) | ||
| 351 | int nid; | ||
| 352 | { | ||
| 353 | X509_EXTENSION_METHOD x; | ||
| 354 | int i; | ||
| 355 | |||
| 356 | x.nid=nid; | ||
| 357 | if (extensions == NULL) return(NULL); | ||
| 358 | i=sk_find(extensions,(char *)&x); | ||
| 359 | if (i < 0) | ||
| 360 | return(NULL); | ||
| 361 | else | ||
| 362 | return((X509_EXTENSION_METHOD *)sk_value(extensions,i)); | ||
| 363 | } | ||
| 364 | |||
| 365 | static int xem_cmp(a,b) | ||
| 366 | X509_EXTENSION_METHOD **a,**b; | ||
| 367 | { | ||
| 368 | return((*a)->nid-(*b)->nid); | ||
| 369 | } | ||
| 370 | |||
| 371 | void X509v3_cleanup_extensions() | ||
| 372 | { | ||
| 373 | int i; | ||
| 374 | |||
| 375 | if (extensions != NULL) | ||
| 376 | { | ||
| 377 | for (i=0; i<sk_num(extensions); i++) | ||
| 378 | Free(sk_value(extensions,i)); | ||
| 379 | sk_free(extensions); | ||
| 380 | extensions=NULL; | ||
| 381 | } | ||
| 382 | } | ||
| 383 | |||
| 384 | int X509v3_add_extension(x) | ||
| 385 | X509_EXTENSION_METHOD *x; | ||
| 386 | { | ||
| 387 | X509_EXTENSION_METHOD *newx; | ||
| 388 | |||
| 389 | if (extensions == NULL) | ||
| 390 | { | ||
| 391 | extensions=sk_new(xem_cmp); | ||
| 392 | if (extensions == NULL) goto err; | ||
| 393 | } | ||
| 394 | newx=(X509_EXTENSION_METHOD *)Malloc(sizeof(X509_EXTENSION_METHOD)); | ||
| 395 | if (newx == NULL) goto err; | ||
| 396 | newx->nid=x->nid; | ||
| 397 | newx->data_type=x->data_type; | ||
| 398 | newx->pack_type=x->pack_type; | ||
| 399 | if (!sk_push(extensions,(char *)newx)) | ||
| 400 | { | ||
| 401 | Free(newx); | ||
| 402 | goto err; | ||
| 403 | } | ||
| 404 | return(1); | ||
| 405 | err: | ||
| 406 | X509err(X509_F_X509V3_ADD_EXTENSION,ERR_R_MALLOC_FAILURE); | ||
| 407 | return(0); | ||
| 408 | } | ||
| 409 | |||
diff --git a/src/lib/libcrypto/x509/x509_vfy.c b/src/lib/libcrypto/x509/x509_vfy.c new file mode 100644 index 0000000000..c1be91edba --- /dev/null +++ b/src/lib/libcrypto/x509/x509_vfy.c | |||
| @@ -0,0 +1,704 @@ | |||
| 1 | /* crypto/x509/x509_vfy.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 <time.h> | ||
| 61 | #include <errno.h> | ||
| 62 | #include <sys/types.h> | ||
| 63 | #include <sys/stat.h> | ||
| 64 | |||
| 65 | #include "crypto.h" | ||
| 66 | #include "cryptlib.h" | ||
| 67 | #include "lhash.h" | ||
| 68 | #include "buffer.h" | ||
| 69 | #include "evp.h" | ||
| 70 | #include "asn1.h" | ||
| 71 | #include "x509.h" | ||
| 72 | #include "objects.h" | ||
| 73 | #include "pem.h" | ||
| 74 | |||
| 75 | #ifndef NOPROTO | ||
| 76 | static int null_callback(int ok,X509_STORE_CTX *e); | ||
| 77 | static int internal_verify(X509_STORE_CTX *ctx); | ||
| 78 | #else | ||
| 79 | static int null_callback(); | ||
| 80 | static int internal_verify(); | ||
| 81 | #endif | ||
| 82 | |||
| 83 | char *X509_version="X509 part of SSLeay 0.9.0b 29-Jun-1998"; | ||
| 84 | static STACK *x509_store_ctx_method=NULL; | ||
| 85 | static int x509_store_ctx_num=0; | ||
| 86 | #if 0 | ||
| 87 | static int x509_store_num=1; | ||
| 88 | static STACK *x509_store_method=NULL; | ||
| 89 | #endif | ||
| 90 | |||
| 91 | static int null_callback(ok,e) | ||
| 92 | int ok; | ||
| 93 | X509_STORE_CTX *e; | ||
| 94 | { | ||
| 95 | return(ok); | ||
| 96 | } | ||
| 97 | |||
| 98 | #if 0 | ||
| 99 | static int x509_subject_cmp(a,b) | ||
| 100 | X509 **a,**b; | ||
| 101 | { | ||
| 102 | return(X509_subject_name_cmp(*a,*b)); | ||
| 103 | } | ||
| 104 | #endif | ||
| 105 | |||
| 106 | int X509_verify_cert(ctx) | ||
| 107 | X509_STORE_CTX *ctx; | ||
| 108 | { | ||
| 109 | X509 *x,*xtmp,*chain_ss=NULL; | ||
| 110 | X509_NAME *xn; | ||
| 111 | X509_OBJECT obj; | ||
| 112 | int depth,i,ok=0; | ||
| 113 | int num; | ||
| 114 | int (*cb)(); | ||
| 115 | STACK *sktmp=NULL; | ||
| 116 | |||
| 117 | if (ctx->cert == NULL) | ||
| 118 | { | ||
| 119 | X509err(X509_F_X509_VERIFY_CERT,X509_R_NO_CERT_SET_FOR_US_TO_VERIFY); | ||
| 120 | return(-1); | ||
| 121 | } | ||
| 122 | |||
| 123 | cb=ctx->ctx->verify_cb; | ||
| 124 | if (cb == NULL) cb=null_callback; | ||
| 125 | |||
| 126 | /* first we make sure the chain we are going to build is | ||
| 127 | * present and that the first entry is in place */ | ||
| 128 | if (ctx->chain == NULL) | ||
| 129 | { | ||
| 130 | if ( ((ctx->chain=sk_new_null()) == NULL) || | ||
| 131 | (!sk_push(ctx->chain,(char *)ctx->cert))) | ||
| 132 | { | ||
| 133 | X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE); | ||
| 134 | goto end; | ||
| 135 | } | ||
| 136 | CRYPTO_add(&ctx->cert->references,1,CRYPTO_LOCK_X509); | ||
| 137 | ctx->last_untrusted=1; | ||
| 138 | } | ||
| 139 | |||
| 140 | /* We use a temporary so we can chop and hack at it */ | ||
| 141 | if ((ctx->untrusted != NULL) && (sktmp=sk_dup(ctx->untrusted)) == NULL) | ||
| 142 | { | ||
| 143 | X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE); | ||
| 144 | goto end; | ||
| 145 | } | ||
| 146 | |||
| 147 | num=sk_num(ctx->chain); | ||
| 148 | x=(X509 *)sk_value(ctx->chain,num-1); | ||
| 149 | depth=ctx->depth; | ||
| 150 | |||
| 151 | |||
| 152 | for (;;) | ||
| 153 | { | ||
| 154 | /* If we have enough, we break */ | ||
| 155 | if (depth <= num) break; | ||
| 156 | |||
| 157 | /* If we are self signed, we break */ | ||
| 158 | xn=X509_get_issuer_name(x); | ||
| 159 | if (X509_NAME_cmp(X509_get_subject_name(x),xn) == 0) | ||
| 160 | break; | ||
| 161 | |||
| 162 | /* If we were passed a cert chain, use it first */ | ||
| 163 | if (ctx->untrusted != NULL) | ||
| 164 | { | ||
| 165 | xtmp=X509_find_by_subject(sktmp,xn); | ||
| 166 | if (xtmp != NULL) | ||
| 167 | { | ||
| 168 | if (!sk_push(ctx->chain,(char *)xtmp)) | ||
| 169 | { | ||
| 170 | X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE); | ||
| 171 | goto end; | ||
| 172 | } | ||
| 173 | CRYPTO_add(&xtmp->references,1,CRYPTO_LOCK_X509); | ||
| 174 | sk_delete_ptr(sktmp,(char *)xtmp); | ||
| 175 | ctx->last_untrusted++; | ||
| 176 | x=xtmp; | ||
| 177 | num++; | ||
| 178 | /* reparse the full chain for | ||
| 179 | * the next one */ | ||
| 180 | continue; | ||
| 181 | } | ||
| 182 | } | ||
| 183 | break; | ||
| 184 | } | ||
| 185 | |||
| 186 | /* at this point, chain should contain a list of untrusted | ||
| 187 | * certificates. We now need to add at least one trusted one, | ||
| 188 | * if possible, otherwise we complain. */ | ||
| 189 | |||
| 190 | i=sk_num(ctx->chain); | ||
| 191 | x=(X509 *)sk_value(ctx->chain,i-1); | ||
| 192 | if (X509_NAME_cmp(X509_get_subject_name(x),X509_get_issuer_name(x)) | ||
| 193 | == 0) | ||
| 194 | { | ||
| 195 | /* we have a self signed certificate */ | ||
| 196 | if (sk_num(ctx->chain) == 1) | ||
| 197 | { | ||
| 198 | ctx->error=X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT; | ||
| 199 | ctx->current_cert=x; | ||
| 200 | ctx->error_depth=i-1; | ||
| 201 | ok=cb(0,ctx); | ||
| 202 | if (!ok) goto end; | ||
| 203 | } | ||
| 204 | else | ||
| 205 | { | ||
| 206 | /* worry more about this one elsewhere */ | ||
| 207 | chain_ss=(X509 *)sk_pop(ctx->chain); | ||
| 208 | ctx->last_untrusted--; | ||
| 209 | num--; | ||
| 210 | x=(X509 *)sk_value(ctx->chain,num-1); | ||
| 211 | } | ||
| 212 | } | ||
| 213 | |||
| 214 | /* We now lookup certs from the certificate store */ | ||
| 215 | for (;;) | ||
| 216 | { | ||
| 217 | /* If we have enough, we break */ | ||
| 218 | if (depth <= num) break; | ||
| 219 | |||
| 220 | /* If we are self signed, we break */ | ||
| 221 | xn=X509_get_issuer_name(x); | ||
| 222 | if (X509_NAME_cmp(X509_get_subject_name(x),xn) == 0) | ||
| 223 | break; | ||
| 224 | |||
| 225 | ok=X509_STORE_get_by_subject(ctx,X509_LU_X509,xn,&obj); | ||
| 226 | if (ok != X509_LU_X509) | ||
| 227 | { | ||
| 228 | if (ok == X509_LU_RETRY) | ||
| 229 | { | ||
| 230 | X509_OBJECT_free_contents(&obj); | ||
| 231 | X509err(X509_F_X509_VERIFY_CERT,X509_R_SHOULD_RETRY); | ||
| 232 | return(ok); | ||
| 233 | } | ||
| 234 | else if (ok != X509_LU_FAIL) | ||
| 235 | { | ||
| 236 | X509_OBJECT_free_contents(&obj); | ||
| 237 | /* not good :-(, break anyway */ | ||
| 238 | return(ok); | ||
| 239 | } | ||
| 240 | break; | ||
| 241 | } | ||
| 242 | x=obj.data.x509; | ||
| 243 | if (!sk_push(ctx->chain,(char *)obj.data.x509)) | ||
| 244 | { | ||
| 245 | X509_OBJECT_free_contents(&obj); | ||
| 246 | X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE); | ||
| 247 | return(0); | ||
| 248 | } | ||
| 249 | num++; | ||
| 250 | } | ||
| 251 | |||
| 252 | /* we now have our chain, lets check it... */ | ||
| 253 | xn=X509_get_issuer_name(x); | ||
| 254 | if (X509_NAME_cmp(X509_get_subject_name(x),xn) != 0) | ||
| 255 | { | ||
| 256 | if ((chain_ss == NULL) || (X509_NAME_cmp(X509_get_subject_name(chain_ss),xn) != 0)) | ||
| 257 | { | ||
| 258 | if (ctx->last_untrusted >= num) | ||
| 259 | ctx->error=X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY; | ||
| 260 | else | ||
| 261 | ctx->error=X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT; | ||
| 262 | ctx->current_cert=x; | ||
| 263 | } | ||
| 264 | else | ||
| 265 | { | ||
| 266 | |||
| 267 | sk_push(ctx->chain,(char *)chain_ss); | ||
| 268 | num++; | ||
| 269 | ctx->last_untrusted=num; | ||
| 270 | ctx->current_cert=chain_ss; | ||
| 271 | ctx->error=X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN; | ||
| 272 | chain_ss=NULL; | ||
| 273 | } | ||
| 274 | |||
| 275 | ctx->error_depth=num-1; | ||
| 276 | ok=cb(0,ctx); | ||
| 277 | if (!ok) goto end; | ||
| 278 | } | ||
| 279 | |||
| 280 | /* We may as well copy down any DSA parameters that are required */ | ||
| 281 | X509_get_pubkey_parameters(NULL,ctx->chain); | ||
| 282 | |||
| 283 | /* At this point, we have a chain and just need to verify it */ | ||
| 284 | if (ctx->ctx->verify != NULL) | ||
| 285 | ok=ctx->ctx->verify(ctx); | ||
| 286 | else | ||
| 287 | ok=internal_verify(ctx); | ||
| 288 | end: | ||
| 289 | if (sktmp != NULL) sk_free(sktmp); | ||
| 290 | if (chain_ss != NULL) X509_free(chain_ss); | ||
| 291 | return(ok); | ||
| 292 | } | ||
| 293 | |||
| 294 | static int internal_verify(ctx) | ||
| 295 | X509_STORE_CTX *ctx; | ||
| 296 | { | ||
| 297 | int i,ok=0,n; | ||
| 298 | X509 *xs,*xi; | ||
| 299 | EVP_PKEY *pkey=NULL; | ||
| 300 | int (*cb)(); | ||
| 301 | |||
| 302 | cb=ctx->ctx->verify_cb; | ||
| 303 | if (cb == NULL) cb=null_callback; | ||
| 304 | |||
| 305 | n=sk_num(ctx->chain); | ||
| 306 | ctx->error_depth=n-1; | ||
| 307 | n--; | ||
| 308 | xi=(X509 *)sk_value(ctx->chain,n); | ||
| 309 | if (X509_NAME_cmp(X509_get_subject_name(xi), | ||
| 310 | X509_get_issuer_name(xi)) == 0) | ||
| 311 | xs=xi; | ||
| 312 | else | ||
| 313 | { | ||
| 314 | if (n <= 0) | ||
| 315 | { | ||
| 316 | ctx->error=X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE; | ||
| 317 | ctx->current_cert=xi; | ||
| 318 | ok=cb(0,ctx); | ||
| 319 | goto end; | ||
| 320 | } | ||
| 321 | else | ||
| 322 | { | ||
| 323 | n--; | ||
| 324 | ctx->error_depth=n; | ||
| 325 | xs=(X509 *)sk_value(ctx->chain,n); | ||
| 326 | } | ||
| 327 | } | ||
| 328 | |||
| 329 | /* ctx->error=0; not needed */ | ||
| 330 | while (n >= 0) | ||
| 331 | { | ||
| 332 | ctx->error_depth=n; | ||
| 333 | if (!xs->valid) | ||
| 334 | { | ||
| 335 | if ((pkey=X509_get_pubkey(xi)) == NULL) | ||
| 336 | { | ||
| 337 | ctx->error=X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY; | ||
| 338 | ctx->current_cert=xi; | ||
| 339 | ok=(*cb)(0,ctx); | ||
| 340 | if (!ok) goto end; | ||
| 341 | } | ||
| 342 | if (X509_verify(xs,pkey) <= 0) | ||
| 343 | { | ||
| 344 | ctx->error=X509_V_ERR_CERT_SIGNATURE_FAILURE; | ||
| 345 | ctx->current_cert=xs; | ||
| 346 | ok=(*cb)(0,ctx); | ||
| 347 | if (!ok) goto end; | ||
| 348 | } | ||
| 349 | pkey=NULL; | ||
| 350 | |||
| 351 | i=X509_cmp_current_time(X509_get_notBefore(xs)); | ||
| 352 | if (i == 0) | ||
| 353 | { | ||
| 354 | ctx->error=X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD; | ||
| 355 | ctx->current_cert=xs; | ||
| 356 | ok=(*cb)(0,ctx); | ||
| 357 | if (!ok) goto end; | ||
| 358 | } | ||
| 359 | if (i > 0) | ||
| 360 | { | ||
| 361 | ctx->error=X509_V_ERR_CERT_NOT_YET_VALID; | ||
| 362 | ctx->current_cert=xs; | ||
| 363 | ok=(*cb)(0,ctx); | ||
| 364 | if (!ok) goto end; | ||
| 365 | } | ||
| 366 | xs->valid=1; | ||
| 367 | } | ||
| 368 | |||
| 369 | i=X509_cmp_current_time(X509_get_notAfter(xs)); | ||
| 370 | if (i == 0) | ||
| 371 | { | ||
| 372 | ctx->error=X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD; | ||
| 373 | ctx->current_cert=xs; | ||
| 374 | ok=(*cb)(0,ctx); | ||
| 375 | if (!ok) goto end; | ||
| 376 | } | ||
| 377 | |||
| 378 | if (i < 0) | ||
| 379 | { | ||
| 380 | ctx->error=X509_V_ERR_CERT_HAS_EXPIRED; | ||
| 381 | ctx->current_cert=xs; | ||
| 382 | ok=(*cb)(0,ctx); | ||
| 383 | if (!ok) goto end; | ||
| 384 | } | ||
| 385 | |||
| 386 | /* CRL CHECK */ | ||
| 387 | |||
| 388 | /* The last error (if any) is still in the error value */ | ||
| 389 | ctx->current_cert=xs; | ||
| 390 | ok=(*cb)(1,ctx); | ||
| 391 | if (!ok) goto end; | ||
| 392 | |||
| 393 | n--; | ||
| 394 | if (n >= 0) | ||
| 395 | { | ||
| 396 | xi=xs; | ||
| 397 | xs=(X509 *)sk_value(ctx->chain,n); | ||
| 398 | } | ||
| 399 | } | ||
| 400 | ok=1; | ||
| 401 | end: | ||
| 402 | return(ok); | ||
| 403 | } | ||
| 404 | |||
| 405 | int X509_cmp_current_time(ctm) | ||
| 406 | ASN1_UTCTIME *ctm; | ||
| 407 | { | ||
| 408 | char *str; | ||
| 409 | ASN1_UTCTIME atm; | ||
| 410 | time_t offset; | ||
| 411 | char buff1[24],buff2[24],*p; | ||
| 412 | int i,j; | ||
| 413 | |||
| 414 | p=buff1; | ||
| 415 | i=ctm->length; | ||
| 416 | str=(char *)ctm->data; | ||
| 417 | if ((i < 11) || (i > 17)) return(0); | ||
| 418 | memcpy(p,str,10); | ||
| 419 | p+=10; | ||
| 420 | str+=10; | ||
| 421 | |||
| 422 | if ((*str == 'Z') || (*str == '-') || (*str == '+')) | ||
| 423 | { *(p++)='0'; *(p++)='0'; } | ||
| 424 | else { *(p++)= *(str++); *(p++)= *(str++); } | ||
| 425 | *(p++)='Z'; | ||
| 426 | *(p++)='\0'; | ||
| 427 | |||
| 428 | if (*str == 'Z') | ||
| 429 | offset=0; | ||
| 430 | else | ||
| 431 | { | ||
| 432 | if ((*str != '+') && (str[5] != '-')) | ||
| 433 | return(0); | ||
| 434 | offset=((str[1]-'0')*10+(str[2]-'0'))*60; | ||
| 435 | offset+=(str[3]-'0')*10+(str[4]-'0'); | ||
| 436 | if (*str == '-') | ||
| 437 | offset=-offset; | ||
| 438 | } | ||
| 439 | atm.type=V_ASN1_UTCTIME; | ||
| 440 | atm.length=sizeof(buff2); | ||
| 441 | atm.data=(unsigned char *)buff2; | ||
| 442 | |||
| 443 | X509_gmtime_adj(&atm,-offset); | ||
| 444 | |||
| 445 | i=(buff1[0]-'0')*10+(buff1[1]-'0'); | ||
| 446 | if (i < 70) i+=100; | ||
| 447 | j=(buff2[0]-'0')*10+(buff2[1]-'0'); | ||
| 448 | if (j < 70) j+=100; | ||
| 449 | |||
| 450 | if (i < j) return (-1); | ||
| 451 | if (i > j) return (1); | ||
| 452 | i=strcmp(buff1,buff2); | ||
| 453 | if (i == 0) /* wait a second then return younger :-) */ | ||
| 454 | return(-1); | ||
| 455 | else | ||
| 456 | return(i); | ||
| 457 | } | ||
| 458 | |||
| 459 | ASN1_UTCTIME *X509_gmtime_adj(s, adj) | ||
| 460 | ASN1_UTCTIME *s; | ||
| 461 | long adj; | ||
| 462 | { | ||
| 463 | time_t t; | ||
| 464 | |||
| 465 | time(&t); | ||
| 466 | t+=adj; | ||
| 467 | return(ASN1_UTCTIME_set(s,t)); | ||
| 468 | } | ||
| 469 | |||
| 470 | int X509_get_pubkey_parameters(pkey,chain) | ||
| 471 | EVP_PKEY *pkey; | ||
| 472 | STACK *chain; | ||
| 473 | { | ||
| 474 | EVP_PKEY *ktmp=NULL,*ktmp2; | ||
| 475 | int i,j; | ||
| 476 | |||
| 477 | if ((pkey != NULL) && !EVP_PKEY_missing_parameters(pkey)) return(1); | ||
| 478 | |||
| 479 | for (i=0; i<sk_num(chain); i++) | ||
| 480 | { | ||
| 481 | ktmp=X509_get_pubkey((X509 *)sk_value(chain,i)); | ||
| 482 | if (ktmp == NULL) | ||
| 483 | { | ||
| 484 | X509err(X509_F_X509_GET_PUBKEY_PARAMETERS,X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY); | ||
| 485 | return(0); | ||
| 486 | } | ||
| 487 | if (!EVP_PKEY_missing_parameters(ktmp)) | ||
| 488 | break; | ||
| 489 | else | ||
| 490 | { | ||
| 491 | ktmp=NULL; | ||
| 492 | } | ||
| 493 | } | ||
| 494 | if (ktmp == NULL) | ||
| 495 | { | ||
| 496 | X509err(X509_F_X509_GET_PUBKEY_PARAMETERS,X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN); | ||
| 497 | return(0); | ||
| 498 | } | ||
| 499 | |||
| 500 | /* first, populate the other certs */ | ||
| 501 | for (j=i-1; j >= 0; j--) | ||
| 502 | { | ||
| 503 | ktmp2=X509_get_pubkey((X509 *)sk_value(chain,j)); | ||
| 504 | EVP_PKEY_copy_parameters(ktmp2,ktmp); | ||
| 505 | } | ||
| 506 | |||
| 507 | if (pkey != NULL) | ||
| 508 | EVP_PKEY_copy_parameters(pkey,ktmp); | ||
| 509 | return(1); | ||
| 510 | } | ||
| 511 | |||
| 512 | EVP_PKEY *X509_get_pubkey(x) | ||
| 513 | X509 *x; | ||
| 514 | { | ||
| 515 | if ((x == NULL) || (x->cert_info == NULL)) | ||
| 516 | return(NULL); | ||
| 517 | return(X509_PUBKEY_get(x->cert_info->key)); | ||
| 518 | } | ||
| 519 | |||
| 520 | int X509_check_private_key(x,k) | ||
| 521 | X509 *x; | ||
| 522 | EVP_PKEY *k; | ||
| 523 | { | ||
| 524 | EVP_PKEY *xk=NULL; | ||
| 525 | int ok=0; | ||
| 526 | |||
| 527 | xk=X509_get_pubkey(x); | ||
| 528 | if (xk->type != k->type) goto err; | ||
| 529 | switch (k->type) | ||
| 530 | { | ||
| 531 | #ifndef NO_RSA | ||
| 532 | case EVP_PKEY_RSA: | ||
| 533 | if (BN_cmp(xk->pkey.rsa->n,k->pkey.rsa->n) != 0) goto err; | ||
| 534 | if (BN_cmp(xk->pkey.rsa->e,k->pkey.rsa->e) != 0) goto err; | ||
| 535 | break; | ||
| 536 | #endif | ||
| 537 | #ifndef NO_DSA | ||
| 538 | case EVP_PKEY_DSA: | ||
| 539 | if (BN_cmp(xk->pkey.dsa->pub_key,k->pkey.dsa->pub_key) != 0) | ||
| 540 | goto err; | ||
| 541 | break; | ||
| 542 | #endif | ||
| 543 | #ifndef NO_DH | ||
| 544 | case EVP_PKEY_DH: | ||
| 545 | /* No idea */ | ||
| 546 | goto err; | ||
| 547 | #endif | ||
| 548 | default: | ||
| 549 | goto err; | ||
| 550 | } | ||
| 551 | |||
| 552 | ok=1; | ||
| 553 | err: | ||
| 554 | return(ok); | ||
| 555 | } | ||
| 556 | |||
| 557 | int X509_STORE_add_cert(ctx,x) | ||
| 558 | X509_STORE *ctx; | ||
| 559 | X509 *x; | ||
| 560 | { | ||
| 561 | X509_OBJECT *obj,*r; | ||
| 562 | int ret=1; | ||
| 563 | |||
| 564 | if (x == NULL) return(0); | ||
| 565 | obj=(X509_OBJECT *)Malloc(sizeof(X509_OBJECT)); | ||
| 566 | if (obj == NULL) | ||
| 567 | { | ||
| 568 | X509err(X509_F_X509_STORE_ADD_CERT,ERR_R_MALLOC_FAILURE); | ||
| 569 | return(0); | ||
| 570 | } | ||
| 571 | obj->type=X509_LU_X509; | ||
| 572 | obj->data.x509=x; | ||
| 573 | |||
| 574 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); | ||
| 575 | |||
| 576 | X509_OBJECT_up_ref_count(obj); | ||
| 577 | |||
| 578 | r=(X509_OBJECT *)lh_insert(ctx->certs,(char *)obj); | ||
| 579 | if (r != NULL) | ||
| 580 | { /* oops, put it back */ | ||
| 581 | lh_delete(ctx->certs,(char *)obj); | ||
| 582 | X509_OBJECT_free_contents(obj); | ||
| 583 | Free(obj); | ||
| 584 | lh_insert(ctx->certs,(char *)r); | ||
| 585 | X509err(X509_F_X509_STORE_ADD_CERT,X509_R_CERT_ALREADY_IN_HASH_TABLE); | ||
| 586 | ret=0; | ||
| 587 | } | ||
| 588 | |||
| 589 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | ||
| 590 | |||
| 591 | return(ret); | ||
| 592 | } | ||
| 593 | |||
| 594 | int X509_STORE_add_crl(ctx,x) | ||
| 595 | X509_STORE *ctx; | ||
| 596 | X509_CRL *x; | ||
| 597 | { | ||
| 598 | X509_OBJECT *obj,*r; | ||
| 599 | int ret=1; | ||
| 600 | |||
| 601 | if (x == NULL) return(0); | ||
| 602 | obj=(X509_OBJECT *)Malloc(sizeof(X509_OBJECT)); | ||
| 603 | if (obj == NULL) | ||
| 604 | { | ||
| 605 | X509err(X509_F_X509_STORE_ADD_CRL,ERR_R_MALLOC_FAILURE); | ||
| 606 | return(0); | ||
| 607 | } | ||
| 608 | obj->type=X509_LU_CRL; | ||
| 609 | obj->data.crl=x; | ||
| 610 | |||
| 611 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); | ||
| 612 | |||
| 613 | X509_OBJECT_up_ref_count(obj); | ||
| 614 | |||
| 615 | r=(X509_OBJECT *)lh_insert(ctx->certs,(char *)obj); | ||
| 616 | if (r != NULL) | ||
| 617 | { /* oops, put it back */ | ||
| 618 | lh_delete(ctx->certs,(char *)obj); | ||
| 619 | X509_OBJECT_free_contents(obj); | ||
| 620 | Free(obj); | ||
| 621 | lh_insert(ctx->certs,(char *)r); | ||
| 622 | X509err(X509_F_X509_STORE_ADD_CRL,X509_R_CERT_ALREADY_IN_HASH_TABLE); | ||
| 623 | ret=0; | ||
| 624 | } | ||
| 625 | |||
| 626 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | ||
| 627 | |||
| 628 | return(ret); | ||
| 629 | } | ||
| 630 | |||
| 631 | int X509_STORE_CTX_get_ex_new_index(argl,argp,new_func,dup_func,free_func) | ||
| 632 | long argl; | ||
| 633 | char *argp; | ||
| 634 | int (*new_func)(); | ||
| 635 | int (*dup_func)(); | ||
| 636 | void (*free_func)(); | ||
| 637 | { | ||
| 638 | x509_store_ctx_num++; | ||
| 639 | return(CRYPTO_get_ex_new_index(x509_store_ctx_num-1, | ||
| 640 | &x509_store_ctx_method, | ||
| 641 | argl,argp,new_func,dup_func,free_func)); | ||
| 642 | } | ||
| 643 | |||
| 644 | int X509_STORE_CTX_set_ex_data(ctx,idx,data) | ||
| 645 | X509_STORE_CTX *ctx; | ||
| 646 | int idx; | ||
| 647 | char *data; | ||
| 648 | { | ||
| 649 | return(CRYPTO_set_ex_data(&ctx->ex_data,idx,data)); | ||
| 650 | } | ||
| 651 | |||
| 652 | char *X509_STORE_CTX_get_ex_data(ctx,idx) | ||
| 653 | X509_STORE_CTX *ctx; | ||
| 654 | int idx; | ||
| 655 | { | ||
| 656 | return(CRYPTO_get_ex_data(&ctx->ex_data,idx)); | ||
| 657 | } | ||
| 658 | |||
| 659 | int X509_STORE_CTX_get_error(ctx) | ||
| 660 | X509_STORE_CTX *ctx; | ||
| 661 | { | ||
| 662 | return(ctx->error); | ||
| 663 | } | ||
| 664 | |||
| 665 | void X509_STORE_CTX_set_error(ctx,err) | ||
| 666 | X509_STORE_CTX *ctx; | ||
| 667 | int err; | ||
| 668 | { | ||
| 669 | ctx->error=err; | ||
| 670 | } | ||
| 671 | |||
| 672 | int X509_STORE_CTX_get_error_depth(ctx) | ||
| 673 | X509_STORE_CTX *ctx; | ||
| 674 | { | ||
| 675 | return(ctx->error_depth); | ||
| 676 | } | ||
| 677 | |||
| 678 | X509 *X509_STORE_CTX_get_current_cert(ctx) | ||
| 679 | X509_STORE_CTX *ctx; | ||
| 680 | { | ||
| 681 | return(ctx->current_cert); | ||
| 682 | } | ||
| 683 | |||
| 684 | STACK *X509_STORE_CTX_get_chain(ctx) | ||
| 685 | X509_STORE_CTX *ctx; | ||
| 686 | { | ||
| 687 | return(ctx->chain); | ||
| 688 | } | ||
| 689 | |||
| 690 | void X509_STORE_CTX_set_cert(ctx,x) | ||
| 691 | X509_STORE_CTX *ctx; | ||
| 692 | X509 *x; | ||
| 693 | { | ||
| 694 | ctx->cert=x; | ||
| 695 | } | ||
| 696 | |||
| 697 | void X509_STORE_CTX_set_chain(ctx,sk) | ||
| 698 | X509_STORE_CTX *ctx; | ||
| 699 | STACK *sk; | ||
| 700 | { | ||
| 701 | ctx->untrusted=sk; | ||
| 702 | } | ||
| 703 | |||
| 704 | |||
diff --git a/src/lib/libcrypto/x509/x509_vfy.h b/src/lib/libcrypto/x509/x509_vfy.h new file mode 100644 index 0000000000..dfc060f899 --- /dev/null +++ b/src/lib/libcrypto/x509/x509_vfy.h | |||
| @@ -0,0 +1,378 @@ | |||
| 1 | /* crypto/x509/x509_vfy.h */ | ||
| 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 | #ifndef HEADER_X509_VFY_H | ||
| 60 | #define HEADER_X509_VFY_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #include "bio.h" | ||
| 67 | #include "crypto.h" | ||
| 68 | |||
| 69 | /* Outer object */ | ||
| 70 | typedef struct x509_hash_dir_st | ||
| 71 | { | ||
| 72 | int num_dirs; | ||
| 73 | char **dirs; | ||
| 74 | int *dirs_type; | ||
| 75 | int num_dirs_alloced; | ||
| 76 | } X509_HASH_DIR_CTX; | ||
| 77 | |||
| 78 | typedef struct x509_file_st | ||
| 79 | { | ||
| 80 | int num_paths; /* number of paths to files or directories */ | ||
| 81 | int num_alloced; | ||
| 82 | char **paths; /* the list of paths or directories */ | ||
| 83 | int *path_type; | ||
| 84 | } X509_CERT_FILE_CTX; | ||
| 85 | |||
| 86 | /*******************************/ | ||
| 87 | /* | ||
| 88 | SSL_CTX -> X509_STORE | ||
| 89 | -> X509_LOOKUP | ||
| 90 | ->X509_LOOKUP_METHOD | ||
| 91 | -> X509_LOOKUP | ||
| 92 | ->X509_LOOKUP_METHOD | ||
| 93 | |||
| 94 | SSL -> X509_STORE_CTX | ||
| 95 | ->X509_STORE | ||
| 96 | |||
| 97 | The X509_STORE holds the tables etc for verification stuff. | ||
| 98 | A X509_STORE_CTX is used while validating a single certificate. | ||
| 99 | The X509_STORE has X509_LOOKUPs for looking up certs. | ||
| 100 | The X509_STORE then calls a function to actually verify the | ||
| 101 | certificate chain. | ||
| 102 | */ | ||
| 103 | |||
| 104 | #define X509_LU_RETRY -1 | ||
| 105 | #define X509_LU_FAIL 0 | ||
| 106 | #define X509_LU_X509 1 | ||
| 107 | #define X509_LU_CRL 2 | ||
| 108 | #define X509_LU_PKEY 3 | ||
| 109 | |||
| 110 | typedef struct x509_object_st | ||
| 111 | { | ||
| 112 | /* one of the above types */ | ||
| 113 | int type; | ||
| 114 | union { | ||
| 115 | char *ptr; | ||
| 116 | X509 *x509; | ||
| 117 | X509_CRL *crl; | ||
| 118 | EVP_PKEY *pkey; | ||
| 119 | } data; | ||
| 120 | } X509_OBJECT; | ||
| 121 | |||
| 122 | /* This is a static that defines the function interface */ | ||
| 123 | typedef struct x509_lookup_method_st | ||
| 124 | { | ||
| 125 | char *name; | ||
| 126 | int (*new_item)(); | ||
| 127 | void (*free)(); | ||
| 128 | int (*init)(/* meth, char ** */); | ||
| 129 | int (*shutdown)( /* meth, char ** */); | ||
| 130 | int (*ctrl)( /* meth, char **, int cmd, char *argp, int argi */); | ||
| 131 | int (*get_by_subject)(/* meth, char **, XNAME *, X509 **ret */); | ||
| 132 | int (*get_by_issuer_serial)(); | ||
| 133 | int (*get_by_fingerprint)(); | ||
| 134 | int (*get_by_alias)(); | ||
| 135 | } X509_LOOKUP_METHOD; | ||
| 136 | |||
| 137 | /* This is used to hold everything. It is used for all certificate | ||
| 138 | * validation. Once we have a certificate chain, the 'verify' | ||
| 139 | * function is then called to actually check the cert chain. */ | ||
| 140 | typedef struct x509_store_st | ||
| 141 | { | ||
| 142 | /* The following is a cache of trusted certs */ | ||
| 143 | int cache; /* if true, stash any hits */ | ||
| 144 | #ifdef HEADER_LHASH_H | ||
| 145 | LHASH *certs; /* cached certs; */ | ||
| 146 | #else | ||
| 147 | char *certs; | ||
| 148 | #endif | ||
| 149 | |||
| 150 | /* These are external lookup methods */ | ||
| 151 | STACK *get_cert_methods;/* X509_LOOKUP */ | ||
| 152 | int (*verify)(); /* called to verify a certificate */ | ||
| 153 | int (*verify_cb)(); /* error callback */ | ||
| 154 | |||
| 155 | CRYPTO_EX_DATA ex_data; | ||
| 156 | int references; | ||
| 157 | int depth; /* how deep to look */ | ||
| 158 | } X509_STORE; | ||
| 159 | |||
| 160 | #define X509_STORE_set_depth(ctx,d) ((ctx)->depth=(d)) | ||
| 161 | |||
| 162 | #define X509_STORE_set_verify_cb_func(ctx,func) ((ctx)->verify_cb=(func)) | ||
| 163 | #define X509_STORE_set_verify_func(ctx,func) ((ctx)->verify=(func)) | ||
| 164 | |||
| 165 | /* This is the functions plus an instance of the local variables. */ | ||
| 166 | typedef struct x509_lookup_st | ||
| 167 | { | ||
| 168 | int init; /* have we been started */ | ||
| 169 | int skip; /* don't use us. */ | ||
| 170 | X509_LOOKUP_METHOD *method; /* the functions */ | ||
| 171 | char *method_data; /* method data */ | ||
| 172 | |||
| 173 | X509_STORE *store_ctx; /* who owns us */ | ||
| 174 | } X509_LOOKUP; | ||
| 175 | |||
| 176 | /* This is a temporary used when processing cert chains. Since the | ||
| 177 | * gathering of the cert chain can take some time (and have to be | ||
| 178 | * 'retried', this needs to be kept and passed around. */ | ||
| 179 | typedef struct x509_store_state_st | ||
| 180 | { | ||
| 181 | X509_STORE *ctx; | ||
| 182 | int current_method; /* used when looking up certs */ | ||
| 183 | |||
| 184 | /* The following are set by the caller */ | ||
| 185 | X509 *cert; /* The cert to check */ | ||
| 186 | STACK *untrusted; /* chain of X509s - untrusted - passed in */ | ||
| 187 | |||
| 188 | /* The following is built up */ | ||
| 189 | int depth; /* how far to go looking up certs */ | ||
| 190 | int valid; /* if 0, rebuild chain */ | ||
| 191 | int last_untrusted; /* index of last untrusted cert */ | ||
| 192 | STACK *chain; /* chain of X509s - built up and trusted */ | ||
| 193 | |||
| 194 | /* When something goes wrong, this is why */ | ||
| 195 | int error_depth; | ||
| 196 | int error; | ||
| 197 | X509 *current_cert; | ||
| 198 | |||
| 199 | CRYPTO_EX_DATA ex_data; | ||
| 200 | } X509_STORE_CTX; | ||
| 201 | |||
| 202 | #define X509_STORE_CTX_set_app_data(ctx,data) \ | ||
| 203 | X509_STORE_CTX_set_ex_data(ctx,0,data) | ||
| 204 | #define X509_STORE_CTX_get_app_data(ctx) \ | ||
| 205 | X509_STORE_CTX_get_ex_data(ctx,0) | ||
| 206 | |||
| 207 | #define X509_L_FILE_LOAD 1 | ||
| 208 | #define X509_L_ADD_DIR 2 | ||
| 209 | |||
| 210 | X509_LOOKUP_METHOD *X509_LOOKUP_file(); | ||
| 211 | #define X509_LOOKUP_load_file(x,name,type) \ | ||
| 212 | X509_LOOKUP_ctrl((x),X509_L_FILE_LOAD,(name),(long)(type),NULL) | ||
| 213 | |||
| 214 | X509_LOOKUP_METHOD *X509_LOOKUP_dir(); | ||
| 215 | #define X509_LOOKUP_add_dir(x,name,type) \ | ||
| 216 | X509_LOOKUP_ctrl((x),X509_L_ADD_DIR,(name),(long)(type),NULL) | ||
| 217 | |||
| 218 | #define X509_V_OK 0 | ||
| 219 | |||
| 220 | #define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT 2 | ||
| 221 | #define X509_V_ERR_UNABLE_TO_GET_CRL 3 | ||
| 222 | #define X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE 4 | ||
| 223 | #define X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE 5 | ||
| 224 | #define X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY 6 | ||
| 225 | #define X509_V_ERR_CERT_SIGNATURE_FAILURE 7 | ||
| 226 | #define X509_V_ERR_CRL_SIGNATURE_FAILURE 8 | ||
| 227 | #define X509_V_ERR_CERT_NOT_YET_VALID 9 | ||
| 228 | #define X509_V_ERR_CERT_HAS_EXPIRED 10 | ||
| 229 | #define X509_V_ERR_CRL_NOT_YET_VALID 11 | ||
| 230 | #define X509_V_ERR_CRL_HAS_EXPIRED 12 | ||
| 231 | #define X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD 13 | ||
| 232 | #define X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD 14 | ||
| 233 | #define X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD 15 | ||
| 234 | #define X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD 16 | ||
| 235 | #define X509_V_ERR_OUT_OF_MEM 17 | ||
| 236 | #define X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT 18 | ||
| 237 | #define X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN 19 | ||
| 238 | #define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY 20 | ||
| 239 | #define X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE 21 | ||
| 240 | #define X509_V_ERR_CERT_CHAIN_TOO_LONG 22 | ||
| 241 | #define X509_V_ERR_CERT_REVOKED 23 | ||
| 242 | |||
| 243 | /* The application is not happy */ | ||
| 244 | #define X509_V_ERR_APPLICATION_VERIFICATION 50 | ||
| 245 | |||
| 246 | #ifndef NOPROTO | ||
| 247 | #ifdef HEADER_LHASH_H | ||
| 248 | X509_OBJECT *X509_OBJECT_retrive_by_subject(LHASH *h,int type,X509_NAME *name); | ||
| 249 | #endif | ||
| 250 | void X509_OBJECT_up_ref_count(X509_OBJECT *a); | ||
| 251 | void X509_OBJECT_free_contents(X509_OBJECT *a); | ||
| 252 | X509_STORE *X509_STORE_new(void ); | ||
| 253 | void X509_STORE_free(X509_STORE *v); | ||
| 254 | |||
| 255 | void X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, | ||
| 256 | X509 *x509, STACK *chain); | ||
| 257 | void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx); | ||
| 258 | |||
| 259 | X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m); | ||
| 260 | |||
| 261 | X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void); | ||
| 262 | X509_LOOKUP_METHOD *X509_LOOKUP_file(void); | ||
| 263 | |||
| 264 | int X509_STORE_add_cert(X509_STORE *ctx, X509 *x); | ||
| 265 | int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x); | ||
| 266 | |||
| 267 | int X509_STORE_get_by_subject(X509_STORE_CTX *vs,int type,X509_NAME *name, | ||
| 268 | X509_OBJECT *ret); | ||
| 269 | |||
| 270 | int X509_LOOKUP_ctrl(X509_LOOKUP *ctx,int cmd,char *argc,long argl,char **ret); | ||
| 271 | |||
| 272 | #ifndef NO_STDIO | ||
| 273 | int X509_load_cert_file(X509_LOOKUP *ctx, char *file, int type); | ||
| 274 | int X509_load_crl_file(X509_LOOKUP *ctx, char *file, int type); | ||
| 275 | #endif | ||
| 276 | |||
| 277 | void X509v3_cleanup_extensions(void ); | ||
| 278 | int X509v3_add_extension(X509_EXTENSION_METHOD *x); | ||
| 279 | int X509v3_add_netscape_extensions(void ); | ||
| 280 | int X509v3_add_standard_extensions(void ); | ||
| 281 | |||
| 282 | X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method); | ||
| 283 | void X509_LOOKUP_free(X509_LOOKUP *ctx); | ||
| 284 | int X509_LOOKUP_init(X509_LOOKUP *ctx); | ||
| 285 | int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type, X509_NAME *name, | ||
| 286 | X509_OBJECT *ret); | ||
| 287 | int X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, int type, X509_NAME *name, | ||
| 288 | ASN1_INTEGER *serial, X509_OBJECT *ret); | ||
| 289 | int X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, int type, | ||
| 290 | unsigned char *bytes, int len, X509_OBJECT *ret); | ||
| 291 | int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, int type, char *str, | ||
| 292 | int len, X509_OBJECT *ret); | ||
| 293 | int X509_LOOKUP_shutdown(X509_LOOKUP *ctx); | ||
| 294 | |||
| 295 | #ifndef NO_STDIO | ||
| 296 | int X509_STORE_load_locations (X509_STORE *ctx, | ||
| 297 | char *file, char *dir); | ||
| 298 | int X509_STORE_set_default_paths(X509_STORE *ctx); | ||
| 299 | #endif | ||
| 300 | |||
| 301 | int X509_STORE_CTX_get_ex_new_index(long argl, char *argp, int (*new_func)(), | ||
| 302 | int (*dup_func)(), void (*free_func)()); | ||
| 303 | int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx,int idx,char *data); | ||
| 304 | char * X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx,int idx); | ||
| 305 | int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx); | ||
| 306 | void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx,int s); | ||
| 307 | int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx); | ||
| 308 | X509 * X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx); | ||
| 309 | STACK * X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx); | ||
| 310 | void X509_STORE_CTX_set_cert(X509_STORE_CTX *c,X509 *x); | ||
| 311 | void X509_STORE_CTX_set_chain(X509_STORE_CTX *c,STACK /* X509 */ *sk); | ||
| 312 | |||
| 313 | #else | ||
| 314 | |||
| 315 | #ifdef HEADER_LHASH_H | ||
| 316 | X509_OBJECT *X509_OBJECT_retrive_by_subject(); | ||
| 317 | #endif | ||
| 318 | void X509_OBJECT_up_ref_count(); | ||
| 319 | void X509_OBJECT_free_contents(); | ||
| 320 | X509_STORE *X509_STORE_new(); | ||
| 321 | void X509_STORE_free(); | ||
| 322 | |||
| 323 | void X509_STORE_CTX_init(); | ||
| 324 | void X509_STORE_CTX_cleanup(); | ||
| 325 | |||
| 326 | X509_LOOKUP *X509_STORE_add_lookup(); | ||
| 327 | |||
| 328 | X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(); | ||
| 329 | X509_LOOKUP_METHOD *X509_LOOKUP_file(); | ||
| 330 | |||
| 331 | int X509_STORE_add_cert(); | ||
| 332 | int X509_STORE_add_crl(); | ||
| 333 | |||
| 334 | int X509_STORE_get_by_subject(); | ||
| 335 | |||
| 336 | int X509_LOOKUP_ctrl(); | ||
| 337 | |||
| 338 | #ifndef NO_STDIO | ||
| 339 | int X509_load_cert_file(); | ||
| 340 | int X509_load_crl_file(); | ||
| 341 | #endif | ||
| 342 | |||
| 343 | void X509v3_cleanup_extensions(); | ||
| 344 | int X509v3_add_extension(); | ||
| 345 | int X509v3_add_netscape_extensions(); | ||
| 346 | int X509v3_add_standard_extensions(); | ||
| 347 | |||
| 348 | X509_LOOKUP *X509_LOOKUP_new(); | ||
| 349 | void X509_LOOKUP_free(); | ||
| 350 | int X509_LOOKUP_init(); | ||
| 351 | int X509_LOOKUP_by_subject(); | ||
| 352 | int X509_LOOKUP_by_issuer_serial(); | ||
| 353 | int X509_LOOKUP_by_fingerprint(); | ||
| 354 | int X509_LOOKUP_by_alias(); | ||
| 355 | int X509_LOOKUP_shutdown(); | ||
| 356 | |||
| 357 | #ifndef NO_STDIO | ||
| 358 | int X509_STORE_load_locations (); | ||
| 359 | int X509_STORE_set_default_paths(); | ||
| 360 | #endif | ||
| 361 | |||
| 362 | int X509_STORE_CTX_set_ex_data(); | ||
| 363 | char * X509_STORE_CTX_get_ex_data(); | ||
| 364 | int X509_STORE_CTX_get_error(); | ||
| 365 | void X509_STORE_CTX_set_error(); | ||
| 366 | int X509_STORE_CTX_get_error_depth(); | ||
| 367 | X509 * X509_STORE_CTX_get_current_cert(); | ||
| 368 | STACK * X509_STORE_CTX_get_chain(); | ||
| 369 | void X509_STORE_CTX_set_cert(); | ||
| 370 | void X509_STORE_CTX_set_chain(); | ||
| 371 | |||
| 372 | #endif | ||
| 373 | |||
| 374 | #ifdef __cplusplus | ||
| 375 | } | ||
| 376 | #endif | ||
| 377 | #endif | ||
| 378 | |||
diff --git a/src/lib/libcrypto/x509/x509name.c b/src/lib/libcrypto/x509/x509name.c new file mode 100644 index 0000000000..650e71b1b5 --- /dev/null +++ b/src/lib/libcrypto/x509/x509name.c | |||
| @@ -0,0 +1,358 @@ | |||
| 1 | /* crypto/x509/x509name.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 "stack.h" | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "asn1.h" | ||
| 63 | #include "objects.h" | ||
| 64 | #include "evp.h" | ||
| 65 | #include "x509.h" | ||
| 66 | |||
| 67 | int X509_NAME_get_text_by_NID(name,nid,buf,len) | ||
| 68 | X509_NAME *name; | ||
| 69 | int nid; | ||
| 70 | char *buf; | ||
| 71 | int len; | ||
| 72 | { | ||
| 73 | ASN1_OBJECT *obj; | ||
| 74 | |||
| 75 | obj=OBJ_nid2obj(nid); | ||
| 76 | if (obj == NULL) return(-1); | ||
| 77 | return(X509_NAME_get_text_by_OBJ(name,obj,buf,len)); | ||
| 78 | } | ||
| 79 | |||
| 80 | int X509_NAME_get_text_by_OBJ(name,obj,buf,len) | ||
| 81 | X509_NAME *name; | ||
| 82 | ASN1_OBJECT *obj; | ||
| 83 | char *buf; | ||
| 84 | int len; | ||
| 85 | { | ||
| 86 | int i; | ||
| 87 | ASN1_STRING *data; | ||
| 88 | |||
| 89 | i=X509_NAME_get_index_by_OBJ(name,obj,-1); | ||
| 90 | if (i < 0) return(-1); | ||
| 91 | data=X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name,i)); | ||
| 92 | i=(data->length > (len-1))?(len-1):data->length; | ||
| 93 | if (buf == NULL) return(data->length); | ||
| 94 | memcpy(buf,data->data,i); | ||
| 95 | buf[i]='\0'; | ||
| 96 | return(i); | ||
| 97 | } | ||
| 98 | |||
| 99 | int X509_NAME_entry_count(name) | ||
| 100 | X509_NAME *name; | ||
| 101 | { | ||
| 102 | if (name == NULL) return(0); | ||
| 103 | return(sk_num(name->entries)); | ||
| 104 | } | ||
| 105 | |||
| 106 | int X509_NAME_get_index_by_NID(name,nid,lastpos) | ||
| 107 | X509_NAME *name; | ||
| 108 | int nid; | ||
| 109 | int lastpos; | ||
| 110 | { | ||
| 111 | ASN1_OBJECT *obj; | ||
| 112 | |||
| 113 | obj=OBJ_nid2obj(nid); | ||
| 114 | if (obj == NULL) return(-2); | ||
| 115 | return(X509_NAME_get_index_by_OBJ(name,obj,lastpos)); | ||
| 116 | } | ||
| 117 | |||
| 118 | /* NOTE: you should be passsing -1, not 0 as lastpos */ | ||
| 119 | int X509_NAME_get_index_by_OBJ(name,obj,lastpos) | ||
| 120 | X509_NAME *name; | ||
| 121 | ASN1_OBJECT *obj; | ||
| 122 | int lastpos; | ||
| 123 | { | ||
| 124 | int n; | ||
| 125 | X509_NAME_ENTRY *ne; | ||
| 126 | STACK *sk; | ||
| 127 | |||
| 128 | if (name == NULL) return(-1); | ||
| 129 | if (lastpos < 0) | ||
| 130 | lastpos= -1; | ||
| 131 | sk=name->entries; | ||
| 132 | n=sk_num(sk); | ||
| 133 | for (lastpos++; lastpos < n; lastpos++) | ||
| 134 | { | ||
| 135 | ne=(X509_NAME_ENTRY *)sk_value(sk,lastpos); | ||
| 136 | if (OBJ_cmp(ne->object,obj) == 0) | ||
| 137 | return(lastpos); | ||
| 138 | } | ||
| 139 | return(-1); | ||
| 140 | } | ||
| 141 | |||
| 142 | X509_NAME_ENTRY *X509_NAME_get_entry(name,loc) | ||
| 143 | X509_NAME *name; | ||
| 144 | int loc; | ||
| 145 | { | ||
| 146 | if ( (name == NULL) || (sk_num(name->entries) <= loc) || (loc < 0)) | ||
| 147 | return(NULL); | ||
| 148 | else | ||
| 149 | return((X509_NAME_ENTRY *)sk_value(name->entries,loc)); | ||
| 150 | } | ||
| 151 | |||
| 152 | X509_NAME_ENTRY *X509_NAME_delete_entry(name,loc) | ||
| 153 | X509_NAME *name; | ||
| 154 | int loc; | ||
| 155 | { | ||
| 156 | X509_NAME_ENTRY *ret; | ||
| 157 | int i,j,n,set_prev,set_next; | ||
| 158 | STACK *sk; | ||
| 159 | |||
| 160 | if ((name == NULL) || (sk_num(name->entries) <= loc) || (loc < 0)) | ||
| 161 | return(NULL); | ||
| 162 | sk=name->entries; | ||
| 163 | ret=(X509_NAME_ENTRY *)sk_delete(sk,loc); | ||
| 164 | n=sk_num(sk); | ||
| 165 | name->modified=1; | ||
| 166 | if (loc == n) return(ret); | ||
| 167 | |||
| 168 | /* else we need to fixup the set field */ | ||
| 169 | if (loc != 0) | ||
| 170 | set_prev=((X509_NAME_ENTRY *)sk_value(sk,loc-1))->set; | ||
| 171 | else | ||
| 172 | set_prev=ret->set-1; | ||
| 173 | set_next=((X509_NAME_ENTRY *)sk_value(sk,loc))->set; | ||
| 174 | |||
| 175 | /* set_prev is the previous set | ||
| 176 | * set is the current set | ||
| 177 | * set_next is the following | ||
| 178 | * prev 1 1 1 1 1 1 1 1 | ||
| 179 | * set 1 1 2 2 | ||
| 180 | * next 1 1 2 2 2 2 3 2 | ||
| 181 | * so basically only if prev and next differ by 2, then | ||
| 182 | * re-number down by 1 */ | ||
| 183 | if (set_prev+1 < set_next) | ||
| 184 | { | ||
| 185 | j=set_next-set_prev-1; | ||
| 186 | for (i=loc; i<n; i++) | ||
| 187 | ((X509_NAME_ENTRY *)sk_value(sk,loc-1))->set-=j; | ||
| 188 | } | ||
| 189 | return(ret); | ||
| 190 | } | ||
| 191 | |||
| 192 | /* if set is -1, append to previous set, 0 'a new one', and 1, | ||
| 193 | * prepend to the guy we are about to stomp on. */ | ||
| 194 | int X509_NAME_add_entry(name,ne,loc,set) | ||
| 195 | X509_NAME *name; | ||
| 196 | X509_NAME_ENTRY *ne; | ||
| 197 | int loc; | ||
| 198 | int set; | ||
| 199 | { | ||
| 200 | X509_NAME_ENTRY *new_name=NULL; | ||
| 201 | int n,i,inc; | ||
| 202 | STACK *sk; | ||
| 203 | |||
| 204 | if (name == NULL) return(0); | ||
| 205 | sk=name->entries; | ||
| 206 | n=sk_num(sk); | ||
| 207 | if (loc > n) loc=n; | ||
| 208 | else if (loc < 0) loc=n; | ||
| 209 | |||
| 210 | name->modified=1; | ||
| 211 | |||
| 212 | if (set == -1) | ||
| 213 | { | ||
| 214 | if (loc == 0) | ||
| 215 | { | ||
| 216 | set=0; | ||
| 217 | inc=1; | ||
| 218 | } | ||
| 219 | else | ||
| 220 | { | ||
| 221 | set=((X509_NAME_ENTRY *)sk_value(sk,loc-1))->set; | ||
| 222 | inc=0; | ||
| 223 | } | ||
| 224 | } | ||
| 225 | else /* if (set >= 0) */ | ||
| 226 | { | ||
| 227 | if (loc >= n) | ||
| 228 | { | ||
| 229 | if (loc != 0) | ||
| 230 | set=((X509_NAME_ENTRY *) | ||
| 231 | sk_value(sk,loc-1))->set+1; | ||
| 232 | else | ||
| 233 | set=0; | ||
| 234 | } | ||
| 235 | else | ||
| 236 | set=((X509_NAME_ENTRY *)sk_value(sk,loc))->set; | ||
| 237 | inc=(set == 0)?1:0; | ||
| 238 | } | ||
| 239 | |||
| 240 | if ((new_name=X509_NAME_ENTRY_dup(ne)) == NULL) | ||
| 241 | goto err; | ||
| 242 | new_name->set=set; | ||
| 243 | if (!sk_insert(sk,(char *)new_name,loc)) | ||
| 244 | { | ||
| 245 | X509err(X509_F_X509_NAME_ADD_ENTRY,ERR_R_MALLOC_FAILURE); | ||
| 246 | goto err; | ||
| 247 | } | ||
| 248 | if (inc) | ||
| 249 | { | ||
| 250 | n=sk_num(sk); | ||
| 251 | for (i=loc+1; i<n; i++) | ||
| 252 | ((X509_NAME_ENTRY *)sk_value(sk,i-1))->set+=1; | ||
| 253 | } | ||
| 254 | return(1); | ||
| 255 | err: | ||
| 256 | if (new_name != NULL) | ||
| 257 | X509_NAME_ENTRY_free(ne); | ||
| 258 | return(0); | ||
| 259 | } | ||
| 260 | |||
| 261 | X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(ne,nid,type,bytes,len) | ||
| 262 | X509_NAME_ENTRY **ne; | ||
| 263 | int nid; | ||
| 264 | int type; | ||
| 265 | unsigned char *bytes; | ||
| 266 | int len; | ||
| 267 | { | ||
| 268 | ASN1_OBJECT *obj; | ||
| 269 | |||
| 270 | obj=OBJ_nid2obj(nid); | ||
| 271 | if (obj == NULL) | ||
| 272 | { | ||
| 273 | X509err(X509_F_X509_NAME_ENTRY_CREATE_BY_NID,X509_R_UNKNOWN_NID); | ||
| 274 | return(NULL); | ||
| 275 | } | ||
| 276 | return(X509_NAME_ENTRY_create_by_OBJ(ne,obj,type,bytes,len)); | ||
| 277 | } | ||
| 278 | |||
| 279 | X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(ne,obj,type,bytes,len) | ||
| 280 | X509_NAME_ENTRY **ne; | ||
| 281 | ASN1_OBJECT *obj; | ||
| 282 | int type; | ||
| 283 | unsigned char *bytes; | ||
| 284 | int len; | ||
| 285 | { | ||
| 286 | X509_NAME_ENTRY *ret; | ||
| 287 | |||
| 288 | if ((ne == NULL) || (*ne == NULL)) | ||
| 289 | { | ||
| 290 | if ((ret=X509_NAME_ENTRY_new()) == NULL) | ||
| 291 | return(NULL); | ||
| 292 | } | ||
| 293 | else | ||
| 294 | ret= *ne; | ||
| 295 | |||
| 296 | if (!X509_NAME_ENTRY_set_object(ret,obj)) | ||
| 297 | goto err; | ||
| 298 | if (!X509_NAME_ENTRY_set_data(ret,type,bytes,len)) | ||
| 299 | goto err; | ||
| 300 | |||
| 301 | if ((ne != NULL) && (*ne == NULL)) *ne=ret; | ||
| 302 | return(ret); | ||
| 303 | err: | ||
| 304 | if ((ne == NULL) || (ret != *ne)) | ||
| 305 | X509_NAME_ENTRY_free(ret); | ||
| 306 | return(NULL); | ||
| 307 | } | ||
| 308 | |||
| 309 | int X509_NAME_ENTRY_set_object(ne,obj) | ||
| 310 | X509_NAME_ENTRY *ne; | ||
| 311 | ASN1_OBJECT *obj; | ||
| 312 | { | ||
| 313 | if ((ne == NULL) || (obj == NULL)) | ||
| 314 | { | ||
| 315 | X509err(X509_F_X509_NAME_ENTRY_SET_OBJECT,ERR_R_PASSED_NULL_PARAMETER); | ||
| 316 | return(0); | ||
| 317 | } | ||
| 318 | ASN1_OBJECT_free(ne->object); | ||
| 319 | ne->object=OBJ_dup(obj); | ||
| 320 | return((ne->object == NULL)?0:1); | ||
| 321 | } | ||
| 322 | |||
| 323 | int X509_NAME_ENTRY_set_data(ne,type,bytes,len) | ||
| 324 | X509_NAME_ENTRY *ne; | ||
| 325 | int type; | ||
| 326 | unsigned char *bytes; | ||
| 327 | int len; | ||
| 328 | { | ||
| 329 | int i; | ||
| 330 | |||
| 331 | if ((ne == NULL) || ((bytes == NULL) && (len != 0))) return(0); | ||
| 332 | if (len < 0) len=strlen((char *)bytes); | ||
| 333 | i=ASN1_STRING_set(ne->value,bytes,len); | ||
| 334 | if (!i) return(0); | ||
| 335 | if (type != V_ASN1_UNDEF) | ||
| 336 | { | ||
| 337 | if (type == V_ASN1_APP_CHOOSE) | ||
| 338 | ne->value->type=ASN1_PRINTABLE_type(bytes,len); | ||
| 339 | else | ||
| 340 | ne->value->type=type; | ||
| 341 | } | ||
| 342 | return(1); | ||
| 343 | } | ||
| 344 | |||
| 345 | ASN1_OBJECT *X509_NAME_ENTRY_get_object(ne) | ||
| 346 | X509_NAME_ENTRY *ne; | ||
| 347 | { | ||
| 348 | if (ne == NULL) return(NULL); | ||
| 349 | return(ne->object); | ||
| 350 | } | ||
| 351 | |||
| 352 | ASN1_STRING *X509_NAME_ENTRY_get_data(ne) | ||
| 353 | X509_NAME_ENTRY *ne; | ||
| 354 | { | ||
| 355 | if (ne == NULL) return(NULL); | ||
| 356 | return(ne->value); | ||
| 357 | } | ||
| 358 | |||
diff --git a/src/lib/libcrypto/x509/x509rset.c b/src/lib/libcrypto/x509/x509rset.c new file mode 100644 index 0000000000..323b25470a --- /dev/null +++ b/src/lib/libcrypto/x509/x509rset.c | |||
| @@ -0,0 +1,89 @@ | |||
| 1 | /* crypto/x509/x509rset.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 | #include "objects.h" | ||
| 63 | #include "evp.h" | ||
| 64 | #include "x509.h" | ||
| 65 | |||
| 66 | int X509_REQ_set_version(x,version) | ||
| 67 | X509_REQ *x; | ||
| 68 | long version; | ||
| 69 | { | ||
| 70 | if (x == NULL) return(0); | ||
| 71 | return(ASN1_INTEGER_set(x->req_info->version,version)); | ||
| 72 | } | ||
| 73 | |||
| 74 | int X509_REQ_set_subject_name(x,name) | ||
| 75 | X509_REQ *x; | ||
| 76 | X509_NAME *name; | ||
| 77 | { | ||
| 78 | if ((x == NULL) || (x->req_info == NULL)) return(0); | ||
| 79 | return(X509_NAME_set(&x->req_info->subject,name)); | ||
| 80 | } | ||
| 81 | |||
| 82 | int X509_REQ_set_pubkey(x,pkey) | ||
| 83 | X509_REQ *x; | ||
| 84 | EVP_PKEY *pkey; | ||
| 85 | { | ||
| 86 | if ((x == NULL) || (x->req_info == NULL)) return(0); | ||
| 87 | return(X509_PUBKEY_set(&x->req_info->pubkey,pkey)); | ||
| 88 | } | ||
| 89 | |||
diff --git a/src/lib/libcrypto/x509/x509type.c b/src/lib/libcrypto/x509/x509type.c new file mode 100644 index 0000000000..42c23bcfca --- /dev/null +++ b/src/lib/libcrypto/x509/x509type.c | |||
| @@ -0,0 +1,115 @@ | |||
| 1 | /* crypto/x509/x509type.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 "evp.h" | ||
| 62 | #include "objects.h" | ||
| 63 | #include "x509.h" | ||
| 64 | |||
| 65 | int X509_certificate_type(x,pkey) | ||
| 66 | X509 *x; | ||
| 67 | EVP_PKEY *pkey; | ||
| 68 | { | ||
| 69 | EVP_PKEY *pk; | ||
| 70 | int ret=0,i; | ||
| 71 | |||
| 72 | if (x == NULL) return(0); | ||
| 73 | |||
| 74 | if (pkey == NULL) | ||
| 75 | pk=X509_get_pubkey(x); | ||
| 76 | else | ||
| 77 | pk=pkey; | ||
| 78 | |||
| 79 | if (pk == NULL) return(0); | ||
| 80 | |||
| 81 | switch (pk->type) | ||
| 82 | { | ||
| 83 | case EVP_PKEY_RSA: | ||
| 84 | ret=EVP_PK_RSA|EVP_PKT_SIGN; | ||
| 85 | /* if (!sign only extension) */ | ||
| 86 | ret|=EVP_PKT_ENC; | ||
| 87 | break; | ||
| 88 | case EVP_PKEY_DSA: | ||
| 89 | ret=EVP_PK_DSA|EVP_PKT_SIGN; | ||
| 90 | break; | ||
| 91 | case EVP_PKEY_DH: | ||
| 92 | ret=EVP_PK_DH|EVP_PKT_EXCH; | ||
| 93 | break; | ||
| 94 | default: | ||
| 95 | break; | ||
| 96 | } | ||
| 97 | |||
| 98 | i=X509_get_signature_type(x); | ||
| 99 | switch (i) | ||
| 100 | { | ||
| 101 | case EVP_PKEY_RSA: | ||
| 102 | ret|=EVP_PKS_RSA; | ||
| 103 | break; | ||
| 104 | case EVP_PKS_DSA: | ||
| 105 | ret|=EVP_PKS_DSA; | ||
| 106 | break; | ||
| 107 | default: | ||
| 108 | break; | ||
| 109 | } | ||
| 110 | |||
| 111 | if (EVP_PKEY_size(pkey) <= 512) | ||
| 112 | ret|=EVP_PKT_EXP; | ||
| 113 | return(ret); | ||
| 114 | } | ||
| 115 | |||
diff --git a/src/lib/libcrypto/x509/x_all.c b/src/lib/libcrypto/x509/x_all.c new file mode 100644 index 0000000000..b7dde23e9a --- /dev/null +++ b/src/lib/libcrypto/x509/x_all.c | |||
| @@ -0,0 +1,465 @@ | |||
| 1 | /* crypto/x509/x_all.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 | #undef SSLEAY_MACROS | ||
| 61 | #include "stack.h" | ||
| 62 | #include "cryptlib.h" | ||
| 63 | #include "buffer.h" | ||
| 64 | #include "asn1.h" | ||
| 65 | #include "evp.h" | ||
| 66 | #include "x509.h" | ||
| 67 | |||
| 68 | int X509_verify(a,r) | ||
| 69 | X509 *a; | ||
| 70 | EVP_PKEY *r; | ||
| 71 | { | ||
| 72 | return(ASN1_verify((int (*)())i2d_X509_CINF,a->sig_alg, | ||
| 73 | a->signature,(char *)a->cert_info,r)); | ||
| 74 | } | ||
| 75 | |||
| 76 | int X509_REQ_verify(a,r) | ||
| 77 | X509_REQ *a; | ||
| 78 | EVP_PKEY *r; | ||
| 79 | { | ||
| 80 | return( ASN1_verify((int (*)())i2d_X509_REQ_INFO, | ||
| 81 | a->sig_alg,a->signature,(char *)a->req_info,r)); | ||
| 82 | } | ||
| 83 | |||
| 84 | int X509_CRL_verify(a,r) | ||
| 85 | X509_CRL *a; | ||
| 86 | EVP_PKEY *r; | ||
| 87 | { | ||
| 88 | return(ASN1_verify((int (*)())i2d_X509_CRL_INFO, | ||
| 89 | a->sig_alg, a->signature,(char *)a->crl,r)); | ||
| 90 | } | ||
| 91 | |||
| 92 | int NETSCAPE_SPKI_verify(a,r) | ||
| 93 | NETSCAPE_SPKI *a; | ||
| 94 | EVP_PKEY *r; | ||
| 95 | { | ||
| 96 | return(ASN1_verify((int (*)())i2d_NETSCAPE_SPKAC, | ||
| 97 | a->sig_algor,a->signature, (char *)a->spkac,r)); | ||
| 98 | } | ||
| 99 | |||
| 100 | int X509_sign(x,pkey,md) | ||
| 101 | X509 *x; | ||
| 102 | EVP_PKEY *pkey; | ||
| 103 | EVP_MD *md; | ||
| 104 | { | ||
| 105 | return(ASN1_sign((int (*)())i2d_X509_CINF, x->cert_info->signature, | ||
| 106 | x->sig_alg, x->signature, (char *)x->cert_info,pkey,md)); | ||
| 107 | } | ||
| 108 | |||
| 109 | int X509_REQ_sign(x,pkey,md) | ||
| 110 | X509_REQ *x; | ||
| 111 | EVP_PKEY *pkey; | ||
| 112 | EVP_MD *md; | ||
| 113 | { | ||
| 114 | return(ASN1_sign((int (*)())i2d_X509_REQ_INFO,x->sig_alg, NULL, | ||
| 115 | x->signature, (char *)x->req_info,pkey,md)); | ||
| 116 | } | ||
| 117 | |||
| 118 | int X509_CRL_sign(x,pkey,md) | ||
| 119 | X509_CRL *x; | ||
| 120 | EVP_PKEY *pkey; | ||
| 121 | EVP_MD *md; | ||
| 122 | { | ||
| 123 | return(ASN1_sign((int (*)())i2d_X509_CRL_INFO,x->crl->sig_alg, | ||
| 124 | x->sig_alg, x->signature, (char *)x->crl,pkey,md)); | ||
| 125 | } | ||
| 126 | |||
| 127 | int NETSCAPE_SPKI_sign(x,pkey,md) | ||
| 128 | NETSCAPE_SPKI *x; | ||
| 129 | EVP_PKEY *pkey; | ||
| 130 | EVP_MD *md; | ||
| 131 | { | ||
| 132 | return(ASN1_sign((int (*)())i2d_NETSCAPE_SPKAC, x->sig_algor,NULL, | ||
| 133 | x->signature, (char *)x->spkac,pkey,md)); | ||
| 134 | } | ||
| 135 | |||
| 136 | X509 *X509_dup(x509) | ||
| 137 | X509 *x509; | ||
| 138 | { | ||
| 139 | return((X509 *)ASN1_dup((int (*)())i2d_X509, | ||
| 140 | (char *(*)())d2i_X509,(char *)x509)); | ||
| 141 | } | ||
| 142 | |||
| 143 | X509_EXTENSION *X509_EXTENSION_dup(ex) | ||
| 144 | X509_EXTENSION *ex; | ||
| 145 | { | ||
| 146 | return((X509_EXTENSION *)ASN1_dup( | ||
| 147 | (int (*)())i2d_X509_EXTENSION, | ||
| 148 | (char *(*)())d2i_X509_EXTENSION,(char *)ex)); | ||
| 149 | } | ||
| 150 | |||
| 151 | #ifndef NO_FP_API | ||
| 152 | X509 *d2i_X509_fp(fp,x509) | ||
| 153 | FILE *fp; | ||
| 154 | X509 *x509; | ||
| 155 | { | ||
| 156 | return((X509 *)ASN1_d2i_fp((char *(*)())X509_new, | ||
| 157 | (char *(*)())d2i_X509, (fp),(unsigned char **)(x509))); | ||
| 158 | } | ||
| 159 | |||
| 160 | int i2d_X509_fp(fp,x509) | ||
| 161 | FILE *fp; | ||
| 162 | X509 *x509; | ||
| 163 | { | ||
| 164 | return(ASN1_i2d_fp(i2d_X509,fp,(unsigned char *)x509)); | ||
| 165 | } | ||
| 166 | #endif | ||
| 167 | |||
| 168 | X509 *d2i_X509_bio(bp,x509) | ||
| 169 | BIO *bp; | ||
| 170 | X509 *x509; | ||
| 171 | { | ||
| 172 | return((X509 *)ASN1_d2i_bio((char *(*)())X509_new, | ||
| 173 | (char *(*)())d2i_X509, (bp),(unsigned char **)(x509))); | ||
| 174 | } | ||
| 175 | |||
| 176 | int i2d_X509_bio(bp,x509) | ||
| 177 | BIO *bp; | ||
| 178 | X509 *x509; | ||
| 179 | { | ||
| 180 | return(ASN1_i2d_bio(i2d_X509,bp,(unsigned char *)x509)); | ||
| 181 | } | ||
| 182 | |||
| 183 | X509_CRL *X509_CRL_dup(crl) | ||
| 184 | X509_CRL *crl; | ||
| 185 | { | ||
| 186 | return((X509_CRL *)ASN1_dup((int (*)())i2d_X509_CRL, | ||
| 187 | (char *(*)())d2i_X509_CRL,(char *)crl)); | ||
| 188 | } | ||
| 189 | |||
| 190 | #ifndef NO_FP_API | ||
| 191 | X509_CRL *d2i_X509_CRL_fp(fp,crl) | ||
| 192 | FILE *fp; | ||
| 193 | X509_CRL *crl; | ||
| 194 | { | ||
| 195 | return((X509_CRL *)ASN1_d2i_fp((char *(*)()) | ||
| 196 | X509_CRL_new,(char *(*)())d2i_X509_CRL, (fp), | ||
| 197 | (unsigned char **)(crl))); | ||
| 198 | } | ||
| 199 | |||
| 200 | int i2d_X509_CRL_fp(fp,crl) | ||
| 201 | FILE *fp; | ||
| 202 | X509_CRL *crl; | ||
| 203 | { | ||
| 204 | return(ASN1_i2d_fp(i2d_X509_CRL,fp,(unsigned char *)crl)); | ||
| 205 | } | ||
| 206 | #endif | ||
| 207 | |||
| 208 | X509_CRL *d2i_X509_CRL_bio(bp,crl) | ||
| 209 | BIO *bp; | ||
| 210 | X509_CRL *crl; | ||
| 211 | { | ||
| 212 | return((X509_CRL *)ASN1_d2i_bio((char *(*)()) | ||
| 213 | X509_CRL_new,(char *(*)())d2i_X509_CRL, (bp), | ||
| 214 | (unsigned char **)(crl))); | ||
| 215 | } | ||
| 216 | |||
| 217 | int i2d_X509_CRL_bio(bp,crl) | ||
| 218 | BIO *bp; | ||
| 219 | X509_CRL *crl; | ||
| 220 | { | ||
| 221 | return(ASN1_i2d_bio(i2d_X509_CRL,bp,(unsigned char *)crl)); | ||
| 222 | } | ||
| 223 | |||
| 224 | PKCS7 *PKCS7_dup(p7) | ||
| 225 | PKCS7 *p7; | ||
| 226 | { | ||
| 227 | return((PKCS7 *)ASN1_dup((int (*)())i2d_PKCS7, | ||
| 228 | (char *(*)())d2i_PKCS7,(char *)p7)); | ||
| 229 | } | ||
| 230 | |||
| 231 | #ifndef NO_FP_API | ||
| 232 | PKCS7 *d2i_PKCS7_fp(fp,p7) | ||
| 233 | FILE *fp; | ||
| 234 | PKCS7 *p7; | ||
| 235 | { | ||
| 236 | return((PKCS7 *)ASN1_d2i_fp((char *(*)()) | ||
| 237 | PKCS7_new,(char *(*)())d2i_PKCS7, (fp), | ||
| 238 | (unsigned char **)(p7))); | ||
| 239 | } | ||
| 240 | |||
| 241 | int i2d_PKCS7_fp(fp,p7) | ||
| 242 | FILE *fp; | ||
| 243 | PKCS7 *p7; | ||
| 244 | { | ||
| 245 | return(ASN1_i2d_fp(i2d_PKCS7,fp,(unsigned char *)p7)); | ||
| 246 | } | ||
| 247 | #endif | ||
| 248 | |||
| 249 | PKCS7 *d2i_PKCS7_bio(bp,p7) | ||
| 250 | BIO *bp; | ||
| 251 | PKCS7 *p7; | ||
| 252 | { | ||
| 253 | return((PKCS7 *)ASN1_d2i_bio((char *(*)()) | ||
| 254 | PKCS7_new,(char *(*)())d2i_PKCS7, (bp), | ||
| 255 | (unsigned char **)(p7))); | ||
| 256 | } | ||
| 257 | |||
| 258 | int i2d_PKCS7_bio(bp,p7) | ||
| 259 | BIO *bp; | ||
| 260 | PKCS7 *p7; | ||
| 261 | { | ||
| 262 | return(ASN1_i2d_bio(i2d_PKCS7,bp,(unsigned char *)p7)); | ||
| 263 | } | ||
| 264 | |||
| 265 | X509_REQ *X509_REQ_dup(req) | ||
| 266 | X509_REQ *req; | ||
| 267 | { | ||
| 268 | return((X509_REQ *)ASN1_dup((int (*)())i2d_X509_REQ, | ||
| 269 | (char *(*)())d2i_X509_REQ,(char *)req)); | ||
| 270 | } | ||
| 271 | |||
| 272 | #ifndef NO_FP_API | ||
| 273 | X509_REQ *d2i_X509_REQ_fp(fp,req) | ||
| 274 | FILE *fp; | ||
| 275 | X509_REQ *req; | ||
| 276 | { | ||
| 277 | return((X509_REQ *)ASN1_d2i_fp((char *(*)()) | ||
| 278 | X509_REQ_new, (char *(*)())d2i_X509_REQ, (fp), | ||
| 279 | (unsigned char **)(req))); | ||
| 280 | } | ||
| 281 | |||
| 282 | int i2d_X509_REQ_fp(fp,req) | ||
| 283 | FILE *fp; | ||
| 284 | X509_REQ *req; | ||
| 285 | { | ||
| 286 | return(ASN1_i2d_fp(i2d_X509_REQ,fp,(unsigned char *)req)); | ||
| 287 | } | ||
| 288 | #endif | ||
| 289 | |||
| 290 | X509_REQ *d2i_X509_REQ_bio(bp,req) | ||
| 291 | BIO *bp; | ||
| 292 | X509_REQ *req; | ||
| 293 | { | ||
| 294 | return((X509_REQ *)ASN1_d2i_bio((char *(*)()) | ||
| 295 | X509_REQ_new, (char *(*)())d2i_X509_REQ, (bp), | ||
| 296 | (unsigned char **)(req))); | ||
| 297 | } | ||
| 298 | |||
| 299 | int i2d_X509_REQ_bio(bp,req) | ||
| 300 | BIO *bp; | ||
| 301 | X509_REQ *req; | ||
| 302 | { | ||
| 303 | return(ASN1_i2d_bio(i2d_X509_REQ,bp,(unsigned char *)req)); | ||
| 304 | } | ||
| 305 | |||
| 306 | #ifndef NO_RSA | ||
| 307 | RSA *RSAPublicKey_dup(rsa) | ||
| 308 | RSA *rsa; | ||
| 309 | { | ||
| 310 | return((RSA *)ASN1_dup((int (*)())i2d_RSAPublicKey, | ||
| 311 | (char *(*)())d2i_RSAPublicKey,(char *)rsa)); | ||
| 312 | } | ||
| 313 | |||
| 314 | RSA *RSAPrivateKey_dup(rsa) | ||
| 315 | RSA *rsa; | ||
| 316 | { | ||
| 317 | return((RSA *)ASN1_dup((int (*)())i2d_RSAPrivateKey, | ||
| 318 | (char *(*)())d2i_RSAPrivateKey,(char *)rsa)); | ||
| 319 | } | ||
| 320 | |||
| 321 | #ifndef NO_FP_API | ||
| 322 | RSA *d2i_RSAPrivateKey_fp(fp,rsa) | ||
| 323 | FILE *fp; | ||
| 324 | RSA *rsa; | ||
| 325 | { | ||
| 326 | return((RSA *)ASN1_d2i_fp((char *(*)()) | ||
| 327 | RSA_new,(char *(*)())d2i_RSAPrivateKey, (fp), | ||
| 328 | (unsigned char **)(rsa))); | ||
| 329 | } | ||
| 330 | |||
| 331 | int i2d_RSAPrivateKey_fp(fp,rsa) | ||
| 332 | FILE *fp; | ||
| 333 | RSA *rsa; | ||
| 334 | { | ||
| 335 | return(ASN1_i2d_fp(i2d_RSAPrivateKey,fp,(unsigned char *)rsa)); | ||
| 336 | } | ||
| 337 | |||
| 338 | RSA *d2i_RSAPublicKey_fp(fp,rsa) | ||
| 339 | FILE *fp; | ||
| 340 | RSA *rsa; | ||
| 341 | { | ||
| 342 | return((RSA *)ASN1_d2i_fp((char *(*)()) | ||
| 343 | RSA_new,(char *(*)())d2i_RSAPublicKey, (fp), | ||
| 344 | (unsigned char **)(rsa))); | ||
| 345 | } | ||
| 346 | |||
| 347 | int i2d_RSAPublicKey_fp(fp,rsa) | ||
| 348 | FILE *fp; | ||
| 349 | RSA *rsa; | ||
| 350 | { | ||
| 351 | return(ASN1_i2d_fp(i2d_RSAPublicKey,fp,(unsigned char *)rsa)); | ||
| 352 | } | ||
| 353 | #endif | ||
| 354 | |||
| 355 | RSA *d2i_RSAPrivateKey_bio(bp,rsa) | ||
| 356 | BIO *bp; | ||
| 357 | RSA *rsa; | ||
| 358 | { | ||
| 359 | return((RSA *)ASN1_d2i_bio((char *(*)()) | ||
| 360 | RSA_new,(char *(*)())d2i_RSAPrivateKey, (bp), | ||
| 361 | (unsigned char **)(rsa))); | ||
| 362 | } | ||
| 363 | |||
| 364 | int i2d_RSAPrivateKey_bio(bp,rsa) | ||
| 365 | BIO *bp; | ||
| 366 | RSA *rsa; | ||
| 367 | { | ||
| 368 | return(ASN1_i2d_bio(i2d_RSAPrivateKey,bp,(unsigned char *)rsa)); | ||
| 369 | } | ||
| 370 | |||
| 371 | RSA *d2i_RSAPublicKey_bio(bp,rsa) | ||
| 372 | BIO *bp; | ||
| 373 | RSA *rsa; | ||
| 374 | { | ||
| 375 | return((RSA *)ASN1_d2i_bio((char *(*)()) | ||
| 376 | RSA_new,(char *(*)())d2i_RSAPublicKey, (bp), | ||
| 377 | (unsigned char **)(rsa))); | ||
| 378 | } | ||
| 379 | |||
| 380 | int i2d_RSAPublicKey_bio(bp,rsa) | ||
| 381 | BIO *bp; | ||
| 382 | RSA *rsa; | ||
| 383 | { | ||
| 384 | return(ASN1_i2d_bio(i2d_RSAPublicKey,bp,(unsigned char *)rsa)); | ||
| 385 | } | ||
| 386 | #endif | ||
| 387 | |||
| 388 | #ifndef NO_DSA | ||
| 389 | #ifndef NO_FP_API | ||
| 390 | DSA *d2i_DSAPrivateKey_fp(fp,dsa) | ||
| 391 | FILE *fp; | ||
| 392 | DSA *dsa; | ||
| 393 | { | ||
| 394 | return((DSA *)ASN1_d2i_fp((char *(*)()) | ||
| 395 | DSA_new,(char *(*)())d2i_DSAPrivateKey, (fp), | ||
| 396 | (unsigned char **)(dsa))); | ||
| 397 | } | ||
| 398 | |||
| 399 | int i2d_DSAPrivateKey_fp(fp,dsa) | ||
| 400 | FILE *fp; | ||
| 401 | DSA *dsa; | ||
| 402 | { | ||
| 403 | return(ASN1_i2d_fp(i2d_DSAPrivateKey,fp,(unsigned char *)dsa)); | ||
| 404 | } | ||
| 405 | #endif | ||
| 406 | |||
| 407 | DSA *d2i_DSAPrivateKey_bio(bp,dsa) | ||
| 408 | BIO *bp; | ||
| 409 | DSA *dsa; | ||
| 410 | { | ||
| 411 | return((DSA *)ASN1_d2i_bio((char *(*)()) | ||
| 412 | DSA_new,(char *(*)())d2i_DSAPrivateKey, (bp), | ||
| 413 | (unsigned char **)(dsa))); | ||
| 414 | } | ||
| 415 | |||
| 416 | int i2d_DSAPrivateKey_bio(bp,dsa) | ||
| 417 | BIO *bp; | ||
| 418 | DSA *dsa; | ||
| 419 | { | ||
| 420 | return(ASN1_i2d_bio(i2d_DSAPrivateKey,bp,(unsigned char *)dsa)); | ||
| 421 | } | ||
| 422 | #endif | ||
| 423 | |||
| 424 | X509_NAME *X509_NAME_dup(xn) | ||
| 425 | X509_NAME *xn; | ||
| 426 | { | ||
| 427 | return((X509_NAME *)ASN1_dup((int (*)())i2d_X509_NAME, | ||
| 428 | (char *(*)())d2i_X509_NAME,(char *)xn)); | ||
| 429 | } | ||
| 430 | |||
| 431 | X509_NAME_ENTRY *X509_NAME_ENTRY_dup(ne) | ||
| 432 | X509_NAME_ENTRY *ne; | ||
| 433 | { | ||
| 434 | return((X509_NAME_ENTRY *)ASN1_dup((int (*)())i2d_X509_NAME_ENTRY, | ||
| 435 | (char *(*)())d2i_X509_NAME_ENTRY,(char *)ne)); | ||
| 436 | } | ||
| 437 | |||
| 438 | int X509_digest(data,type,md,len) | ||
| 439 | X509 *data; | ||
| 440 | EVP_MD *type; | ||
| 441 | unsigned char *md; | ||
| 442 | unsigned int *len; | ||
| 443 | { | ||
| 444 | return(ASN1_digest((int (*)())i2d_X509,type,(char *)data,md,len)); | ||
| 445 | } | ||
| 446 | |||
| 447 | int X509_NAME_digest(data,type,md,len) | ||
| 448 | X509_NAME *data; | ||
| 449 | EVP_MD *type; | ||
| 450 | unsigned char *md; | ||
| 451 | unsigned int *len; | ||
| 452 | { | ||
| 453 | return(ASN1_digest((int (*)())i2d_X509_NAME,type,(char *)data,md,len)); | ||
| 454 | } | ||
| 455 | |||
| 456 | int PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) | ||
| 457 | PKCS7_ISSUER_AND_SERIAL *data; | ||
| 458 | EVP_MD *type; | ||
| 459 | unsigned char *md; | ||
| 460 | unsigned int *len; | ||
| 461 | { | ||
| 462 | return(ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type, | ||
| 463 | (char *)data,md,len)); | ||
| 464 | } | ||
| 465 | |||
diff --git a/src/lib/libcrypto/x509v3/x509v3.h b/src/lib/libcrypto/x509v3/x509v3.h new file mode 100644 index 0000000000..d7945bc9cd --- /dev/null +++ b/src/lib/libcrypto/x509v3/x509v3.h | |||
| @@ -0,0 +1,87 @@ | |||
| 1 | /* crypto/x509v3/x509v3.h */ | ||
| 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 | #define X509v3_N_KU_digitalSignature 0 | ||
| 59 | #define X509v3_N_KU_nonRepudiation 1 | ||
| 60 | #define X509v3_N_KU_keyEncipherment 2 | ||
| 61 | #define X509v3_N_KU_dataEncipherment 3 | ||
| 62 | #define X509v3_N_KU_keyAgreement 4 | ||
| 63 | #define X509v3_N_KU_keyCertSign 5 | ||
| 64 | #define X509v3_N_KU_cRLSign 6 | ||
| 65 | #define X509v3_N_KU_encipherOnly 7 | ||
| 66 | #define X509v3_N_KU_decipherOnly 8 | ||
| 67 | #define X509v3_N_KU_NUM 9 | ||
| 68 | #define X509v3_S_KU_digitalSignature "digitalSignature" | ||
| 69 | #define X509v3_S_KU_nonRepudiation "nonRepudiation" | ||
| 70 | #define X509v3_S_KU_keyEncipherment "keyEncipherment" | ||
| 71 | #define X509v3_S_KU_dataEncipherment "dataEncipherment" | ||
| 72 | #define X509v3_S_KU_keyAgreement "keyAgreement" | ||
| 73 | #define X509v3_S_KU_keyCertSign "keyCertSign" | ||
| 74 | #define X509v3_S_KU_cRLSign "cRLSign" | ||
| 75 | #define X509v3_S_KU_encipherOnly "encipherOnly" | ||
| 76 | #define X509v3_S_KU_decipherOnly "decipherOnly" | ||
| 77 | |||
| 78 | |||
| 79 | void X509_ex_clear(X509_EXTENSION *a); | ||
| 80 | int X509_ex_get_bool(X509_EXTENSION *a,int num); | ||
| 81 | int X509_ex_set_bool(X509_EXTENSION *a,int num,int value); | ||
| 82 | int X509_ex_get_str(X509_EXTENSION *a,int index,char **p,int *len); | ||
| 83 | int X509_ex_set_str(X509_EXTENSION *a,int oid,int index,char *p,int len); | ||
| 84 | char *X509_ex_get_struct(X509_EXTENSION *a,int oid,int index,char **p); | ||
| 85 | int X509_ex_set_struct(X509_EXTENSION *a,int index,char *p); | ||
| 86 | int a2i_X509_EXTENSION(BIO *bp,X509_EXTENSION *a,char *buf,int len); | ||
| 87 | int i2a_X509_EXTENSION(BIO *bp,X509_EXTENSION *a); | ||
diff --git a/src/lib/libssl/bio_ssl.c b/src/lib/libssl/bio_ssl.c new file mode 100644 index 0000000000..58a6d69b9b --- /dev/null +++ b/src/lib/libssl/bio_ssl.c | |||
| @@ -0,0 +1,585 @@ | |||
| 1 | /* ssl/bio_ssl.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 <stdlib.h> | ||
| 61 | #include <string.h> | ||
| 62 | #include <errno.h> | ||
| 63 | #include "crypto.h" | ||
| 64 | #include "bio.h" | ||
| 65 | #include "err.h" | ||
| 66 | #include "ssl.h" | ||
| 67 | |||
| 68 | #ifndef NOPROTO | ||
| 69 | static int ssl_write(BIO *h,char *buf,int num); | ||
| 70 | static int ssl_read(BIO *h,char *buf,int size); | ||
| 71 | static int ssl_puts(BIO *h,char *str); | ||
| 72 | static long ssl_ctrl(BIO *h,int cmd,long arg1,char *arg2); | ||
| 73 | static int ssl_new(BIO *h); | ||
| 74 | static int ssl_free(BIO *data); | ||
| 75 | #else | ||
| 76 | static int ssl_write(); | ||
| 77 | static int ssl_read(); | ||
| 78 | static int ssl_puts(); | ||
| 79 | static long ssl_ctrl(); | ||
| 80 | static int ssl_new(); | ||
| 81 | static int ssl_free(); | ||
| 82 | #endif | ||
| 83 | |||
| 84 | typedef struct bio_ssl_st | ||
| 85 | { | ||
| 86 | SSL *ssl; /* The ssl handle :-) */ | ||
| 87 | /* re-negotiate every time the total number of bytes is this size */ | ||
| 88 | int num_renegotiates; | ||
| 89 | unsigned long renegotiate_count; | ||
| 90 | unsigned long byte_count; | ||
| 91 | unsigned long renegotiate_timeout; | ||
| 92 | unsigned long last_time; | ||
| 93 | } BIO_SSL; | ||
| 94 | |||
| 95 | static BIO_METHOD methods_sslp= | ||
| 96 | { | ||
| 97 | BIO_TYPE_SSL,"ssl", | ||
| 98 | ssl_write, | ||
| 99 | ssl_read, | ||
| 100 | ssl_puts, | ||
| 101 | NULL, /* ssl_gets, */ | ||
| 102 | ssl_ctrl, | ||
| 103 | ssl_new, | ||
| 104 | ssl_free, | ||
| 105 | }; | ||
| 106 | |||
| 107 | BIO_METHOD *BIO_f_ssl() | ||
| 108 | { | ||
| 109 | return(&methods_sslp); | ||
| 110 | } | ||
| 111 | |||
| 112 | static int ssl_new(bi) | ||
| 113 | BIO *bi; | ||
| 114 | { | ||
| 115 | BIO_SSL *bs; | ||
| 116 | |||
| 117 | bs=(BIO_SSL *)Malloc(sizeof(BIO_SSL)); | ||
| 118 | if (bs == NULL) | ||
| 119 | { | ||
| 120 | BIOerr(BIO_F_SSL_NEW,ERR_R_MALLOC_FAILURE); | ||
| 121 | return(0); | ||
| 122 | } | ||
| 123 | memset(bs,0,sizeof(BIO_SSL)); | ||
| 124 | bi->init=0; | ||
| 125 | bi->ptr=(char *)bs; | ||
| 126 | bi->flags=0; | ||
| 127 | return(1); | ||
| 128 | } | ||
| 129 | |||
| 130 | static int ssl_free(a) | ||
| 131 | BIO *a; | ||
| 132 | { | ||
| 133 | BIO_SSL *bs; | ||
| 134 | |||
| 135 | if (a == NULL) return(0); | ||
| 136 | bs=(BIO_SSL *)a->ptr; | ||
| 137 | if (bs->ssl != NULL) SSL_shutdown(bs->ssl); | ||
| 138 | if (a->shutdown) | ||
| 139 | { | ||
| 140 | if (a->init && (bs->ssl != NULL)) | ||
| 141 | SSL_free(bs->ssl); | ||
| 142 | a->init=0; | ||
| 143 | a->flags=0; | ||
| 144 | } | ||
| 145 | if (a->ptr != NULL) | ||
| 146 | Free(a->ptr); | ||
| 147 | return(1); | ||
| 148 | } | ||
| 149 | |||
| 150 | static int ssl_read(b,out,outl) | ||
| 151 | BIO *b; | ||
| 152 | char *out; | ||
| 153 | int outl; | ||
| 154 | { | ||
| 155 | int ret=1; | ||
| 156 | BIO_SSL *sb; | ||
| 157 | SSL *ssl; | ||
| 158 | int retry_reason=0; | ||
| 159 | int r=0; | ||
| 160 | |||
| 161 | if (out == NULL) return(0); | ||
| 162 | sb=(BIO_SSL *)b->ptr; | ||
| 163 | ssl=sb->ssl; | ||
| 164 | |||
| 165 | BIO_clear_retry_flags(b); | ||
| 166 | |||
| 167 | #if 0 | ||
| 168 | if (!SSL_is_init_finished(ssl)) | ||
| 169 | { | ||
| 170 | /* ret=SSL_do_handshake(ssl); */ | ||
| 171 | if (ret > 0) | ||
| 172 | { | ||
| 173 | |||
| 174 | outflags=(BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY); | ||
| 175 | ret= -1; | ||
| 176 | goto end; | ||
| 177 | } | ||
| 178 | } | ||
| 179 | #endif | ||
| 180 | /* if (ret > 0) */ | ||
| 181 | ret=SSL_read(ssl,out,outl); | ||
| 182 | |||
| 183 | switch (SSL_get_error(ssl,ret)) | ||
| 184 | { | ||
| 185 | case SSL_ERROR_NONE: | ||
| 186 | if (ret <= 0) break; | ||
| 187 | if (sb->renegotiate_count > 0) | ||
| 188 | { | ||
| 189 | sb->byte_count+=ret; | ||
| 190 | if (sb->byte_count > sb->renegotiate_count) | ||
| 191 | { | ||
| 192 | sb->byte_count=0; | ||
| 193 | sb->num_renegotiates++; | ||
| 194 | SSL_renegotiate(ssl); | ||
| 195 | r=1; | ||
| 196 | } | ||
| 197 | } | ||
| 198 | if ((sb->renegotiate_timeout > 0) && (!r)) | ||
| 199 | { | ||
| 200 | unsigned long tm; | ||
| 201 | |||
| 202 | tm=(unsigned long)time(NULL); | ||
| 203 | if (tm > sb->last_time+sb->renegotiate_timeout) | ||
| 204 | { | ||
| 205 | sb->last_time=tm; | ||
| 206 | sb->num_renegotiates++; | ||
| 207 | SSL_renegotiate(ssl); | ||
| 208 | } | ||
| 209 | } | ||
| 210 | |||
| 211 | break; | ||
| 212 | case SSL_ERROR_WANT_READ: | ||
| 213 | BIO_set_retry_read(b); | ||
| 214 | break; | ||
| 215 | case SSL_ERROR_WANT_WRITE: | ||
| 216 | BIO_set_retry_write(b); | ||
| 217 | break; | ||
| 218 | case SSL_ERROR_WANT_X509_LOOKUP: | ||
| 219 | BIO_set_retry_special(b); | ||
| 220 | retry_reason=BIO_RR_SSL_X509_LOOKUP; | ||
| 221 | break; | ||
| 222 | case SSL_ERROR_WANT_CONNECT: | ||
| 223 | BIO_set_retry_special(b); | ||
| 224 | retry_reason=BIO_RR_CONNECT; | ||
| 225 | break; | ||
| 226 | case SSL_ERROR_SYSCALL: | ||
| 227 | case SSL_ERROR_SSL: | ||
| 228 | case SSL_ERROR_ZERO_RETURN: | ||
| 229 | default: | ||
| 230 | break; | ||
| 231 | } | ||
| 232 | |||
| 233 | b->retry_reason=retry_reason; | ||
| 234 | return(ret); | ||
| 235 | } | ||
| 236 | |||
| 237 | static int ssl_write(b,out,outl) | ||
| 238 | BIO *b; | ||
| 239 | char *out; | ||
| 240 | int outl; | ||
| 241 | { | ||
| 242 | int ret,r=0; | ||
| 243 | int retry_reason=0; | ||
| 244 | SSL *ssl; | ||
| 245 | BIO_SSL *bs; | ||
| 246 | |||
| 247 | if (out == NULL) return(0); | ||
| 248 | bs=(BIO_SSL *)b->ptr; | ||
| 249 | ssl=bs->ssl; | ||
| 250 | |||
| 251 | BIO_clear_retry_flags(b); | ||
| 252 | |||
| 253 | /* ret=SSL_do_handshake(ssl); | ||
| 254 | if (ret > 0) */ | ||
| 255 | ret=SSL_write(ssl,out,outl); | ||
| 256 | |||
| 257 | switch (SSL_get_error(ssl,ret)) | ||
| 258 | { | ||
| 259 | case SSL_ERROR_NONE: | ||
| 260 | if (ret <= 0) break; | ||
| 261 | if (bs->renegotiate_count > 0) | ||
| 262 | { | ||
| 263 | bs->byte_count+=ret; | ||
| 264 | if (bs->byte_count > bs->renegotiate_count) | ||
| 265 | { | ||
| 266 | bs->byte_count=0; | ||
| 267 | bs->num_renegotiates++; | ||
| 268 | SSL_renegotiate(ssl); | ||
| 269 | r=1; | ||
| 270 | } | ||
| 271 | } | ||
| 272 | if ((bs->renegotiate_timeout > 0) && (!r)) | ||
| 273 | { | ||
| 274 | unsigned long tm; | ||
| 275 | |||
| 276 | tm=(unsigned long)time(NULL); | ||
| 277 | if (tm > bs->last_time+bs->renegotiate_timeout) | ||
| 278 | { | ||
| 279 | bs->last_time=tm; | ||
| 280 | bs->num_renegotiates++; | ||
| 281 | SSL_renegotiate(ssl); | ||
| 282 | } | ||
| 283 | } | ||
| 284 | break; | ||
| 285 | case SSL_ERROR_WANT_WRITE: | ||
| 286 | BIO_set_retry_write(b); | ||
| 287 | break; | ||
| 288 | case SSL_ERROR_WANT_READ: | ||
| 289 | BIO_set_retry_read(b); | ||
| 290 | break; | ||
| 291 | case SSL_ERROR_WANT_X509_LOOKUP: | ||
| 292 | BIO_set_retry_special(b); | ||
| 293 | retry_reason=BIO_RR_SSL_X509_LOOKUP; | ||
| 294 | break; | ||
| 295 | case SSL_ERROR_WANT_CONNECT: | ||
| 296 | BIO_set_retry_special(b); | ||
| 297 | retry_reason=BIO_RR_CONNECT; | ||
| 298 | case SSL_ERROR_SYSCALL: | ||
| 299 | case SSL_ERROR_SSL: | ||
| 300 | default: | ||
| 301 | break; | ||
| 302 | } | ||
| 303 | |||
| 304 | b->retry_reason=retry_reason; | ||
| 305 | return(ret); | ||
| 306 | } | ||
| 307 | |||
| 308 | static long ssl_ctrl(b,cmd,num,ptr) | ||
| 309 | BIO *b; | ||
| 310 | int cmd; | ||
| 311 | long num; | ||
| 312 | char *ptr; | ||
| 313 | { | ||
| 314 | SSL **sslp,*ssl; | ||
| 315 | BIO_SSL *bs; | ||
| 316 | BIO *dbio,*bio; | ||
| 317 | long ret=1; | ||
| 318 | |||
| 319 | bs=(BIO_SSL *)b->ptr; | ||
| 320 | ssl=bs->ssl; | ||
| 321 | if ((ssl == NULL) && (cmd != BIO_C_SET_SSL)) | ||
| 322 | return(0); | ||
| 323 | switch (cmd) | ||
| 324 | { | ||
| 325 | case BIO_CTRL_RESET: | ||
| 326 | SSL_shutdown(ssl); | ||
| 327 | |||
| 328 | if (ssl->handshake_func == ssl->method->ssl_connect) | ||
| 329 | SSL_set_connect_state(ssl); | ||
| 330 | else if (ssl->handshake_func == ssl->method->ssl_accept) | ||
| 331 | SSL_set_accept_state(ssl); | ||
| 332 | |||
| 333 | SSL_clear(ssl); | ||
| 334 | |||
| 335 | if (b->next_bio != NULL) | ||
| 336 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
| 337 | else if (ssl->rbio != NULL) | ||
| 338 | ret=BIO_ctrl(ssl->rbio,cmd,num,ptr); | ||
| 339 | else | ||
| 340 | ret=1; | ||
| 341 | break; | ||
| 342 | case BIO_CTRL_INFO: | ||
| 343 | ret=0; | ||
| 344 | break; | ||
| 345 | case BIO_C_SSL_MODE: | ||
| 346 | if (num) /* client mode */ | ||
| 347 | SSL_set_connect_state(ssl); | ||
| 348 | else | ||
| 349 | SSL_set_accept_state(ssl); | ||
| 350 | break; | ||
| 351 | case BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT: | ||
| 352 | ret=bs->renegotiate_timeout; | ||
| 353 | if (num < 60) num=5; | ||
| 354 | bs->renegotiate_timeout=(unsigned long)num; | ||
| 355 | bs->last_time=(unsigned long)time(NULL); | ||
| 356 | break; | ||
| 357 | case BIO_C_SET_SSL_RENEGOTIATE_BYTES: | ||
| 358 | ret=bs->renegotiate_count; | ||
| 359 | if ((long)num >=512) | ||
| 360 | bs->renegotiate_count=(unsigned long)num; | ||
| 361 | break; | ||
| 362 | case BIO_C_GET_SSL_NUM_RENEGOTIATES: | ||
| 363 | ret=bs->num_renegotiates; | ||
| 364 | break; | ||
| 365 | case BIO_C_SET_SSL: | ||
| 366 | if (ssl != NULL) | ||
| 367 | ssl_free(b); | ||
| 368 | b->shutdown=(int)num; | ||
| 369 | ssl=(SSL *)ptr; | ||
| 370 | ((BIO_SSL *)b->ptr)->ssl=ssl; | ||
| 371 | bio=SSL_get_rbio(ssl); | ||
| 372 | if (bio != NULL) | ||
| 373 | { | ||
| 374 | if (b->next_bio != NULL) | ||
| 375 | BIO_push(bio,b->next_bio); | ||
| 376 | b->next_bio=bio; | ||
| 377 | CRYPTO_add(&bio->references,1,CRYPTO_LOCK_BIO); | ||
| 378 | } | ||
| 379 | b->init=1; | ||
| 380 | break; | ||
| 381 | case BIO_C_GET_SSL: | ||
| 382 | if (ptr != NULL) | ||
| 383 | { | ||
| 384 | sslp=(SSL **)ptr; | ||
| 385 | *sslp=ssl; | ||
| 386 | } | ||
| 387 | else | ||
| 388 | ret=0; | ||
| 389 | break; | ||
| 390 | case BIO_CTRL_GET_CLOSE: | ||
| 391 | ret=b->shutdown; | ||
| 392 | break; | ||
| 393 | case BIO_CTRL_SET_CLOSE: | ||
| 394 | b->shutdown=(int)num; | ||
| 395 | break; | ||
| 396 | case BIO_CTRL_WPENDING: | ||
| 397 | ret=BIO_ctrl(ssl->wbio,cmd,num,ptr); | ||
| 398 | break; | ||
| 399 | case BIO_CTRL_PENDING: | ||
| 400 | ret=SSL_pending(ssl); | ||
| 401 | if (ret == 0) | ||
| 402 | ret=BIO_pending(ssl->rbio); | ||
| 403 | break; | ||
| 404 | case BIO_CTRL_FLUSH: | ||
| 405 | BIO_clear_retry_flags(b); | ||
| 406 | ret=BIO_ctrl(ssl->wbio,cmd,num,ptr); | ||
| 407 | BIO_copy_next_retry(b); | ||
| 408 | break; | ||
| 409 | case BIO_CTRL_PUSH: | ||
| 410 | if ((b->next_bio != NULL) && (b->next_bio != ssl->rbio)) | ||
| 411 | { | ||
| 412 | SSL_set_bio(ssl,b->next_bio,b->next_bio); | ||
| 413 | CRYPTO_add(&b->next_bio->references,1,CRYPTO_LOCK_BIO); | ||
| 414 | } | ||
| 415 | break; | ||
| 416 | case BIO_CTRL_POP: | ||
| 417 | /* ugly bit of a hack */ | ||
| 418 | if (ssl->rbio != ssl->wbio) /* we are in trouble :-( */ | ||
| 419 | { | ||
| 420 | BIO_free_all(ssl->wbio); | ||
| 421 | } | ||
| 422 | ssl->wbio=NULL; | ||
| 423 | ssl->rbio=NULL; | ||
| 424 | break; | ||
| 425 | case BIO_C_DO_STATE_MACHINE: | ||
| 426 | BIO_clear_retry_flags(b); | ||
| 427 | |||
| 428 | b->retry_reason=0; | ||
| 429 | ret=(int)SSL_do_handshake(ssl); | ||
| 430 | |||
| 431 | switch (SSL_get_error(ssl,(int)ret)) | ||
| 432 | { | ||
| 433 | case SSL_ERROR_WANT_READ: | ||
| 434 | BIO_set_flags(b, | ||
| 435 | BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY); | ||
| 436 | break; | ||
| 437 | case SSL_ERROR_WANT_WRITE: | ||
| 438 | BIO_set_flags(b, | ||
| 439 | BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY); | ||
| 440 | break; | ||
| 441 | case SSL_ERROR_WANT_CONNECT: | ||
| 442 | BIO_set_flags(b, | ||
| 443 | BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY); | ||
| 444 | b->retry_reason=b->next_bio->retry_reason; | ||
| 445 | break; | ||
| 446 | default: | ||
| 447 | break; | ||
| 448 | } | ||
| 449 | break; | ||
| 450 | case BIO_CTRL_DUP: | ||
| 451 | dbio=(BIO *)ptr; | ||
| 452 | if (((BIO_SSL *)dbio->ptr)->ssl != NULL) | ||
| 453 | SSL_free(((BIO_SSL *)dbio->ptr)->ssl); | ||
| 454 | ((BIO_SSL *)dbio->ptr)->ssl=SSL_dup(ssl); | ||
| 455 | ((BIO_SSL *)dbio->ptr)->renegotiate_count= | ||
| 456 | ((BIO_SSL *)b->ptr)->renegotiate_count; | ||
| 457 | ((BIO_SSL *)dbio->ptr)->byte_count= | ||
| 458 | ((BIO_SSL *)b->ptr)->byte_count; | ||
| 459 | ((BIO_SSL *)dbio->ptr)->renegotiate_timeout= | ||
| 460 | ((BIO_SSL *)b->ptr)->renegotiate_timeout; | ||
| 461 | ((BIO_SSL *)dbio->ptr)->last_time= | ||
| 462 | ((BIO_SSL *)b->ptr)->last_time; | ||
| 463 | ret=(((BIO_SSL *)dbio->ptr)->ssl != NULL); | ||
| 464 | break; | ||
| 465 | case BIO_C_GET_FD: | ||
| 466 | ret=BIO_ctrl(ssl->rbio,cmd,num,ptr); | ||
| 467 | break; | ||
| 468 | case BIO_CTRL_SET_CALLBACK: | ||
| 469 | SSL_set_info_callback(ssl,(void (*)())ptr); | ||
| 470 | break; | ||
| 471 | case BIO_CTRL_GET_CALLBACK: | ||
| 472 | { | ||
| 473 | void (**fptr)(); | ||
| 474 | |||
| 475 | fptr=(void (**)())ptr; | ||
| 476 | *fptr=SSL_get_info_callback(ssl); | ||
| 477 | } | ||
| 478 | break; | ||
| 479 | default: | ||
| 480 | ret=BIO_ctrl(ssl->rbio,cmd,num,ptr); | ||
| 481 | break; | ||
| 482 | } | ||
| 483 | return(ret); | ||
| 484 | } | ||
| 485 | |||
| 486 | static int ssl_puts(bp,str) | ||
| 487 | BIO *bp; | ||
| 488 | char *str; | ||
| 489 | { | ||
| 490 | int n,ret; | ||
| 491 | |||
| 492 | n=strlen(str); | ||
| 493 | ret=BIO_write(bp,str,n); | ||
| 494 | return(ret); | ||
| 495 | } | ||
| 496 | |||
| 497 | BIO *BIO_new_buffer_ssl_connect(ctx) | ||
| 498 | SSL_CTX *ctx; | ||
| 499 | { | ||
| 500 | BIO *ret=NULL,*buf=NULL,*ssl=NULL; | ||
| 501 | |||
| 502 | if ((buf=BIO_new(BIO_f_buffer())) == NULL) | ||
| 503 | return(NULL); | ||
| 504 | if ((ssl=BIO_new_ssl_connect(ctx)) == NULL) | ||
| 505 | goto err; | ||
| 506 | if ((ret=BIO_push(buf,ssl)) == NULL) | ||
| 507 | goto err; | ||
| 508 | return(ret); | ||
| 509 | err: | ||
| 510 | if (buf != NULL) BIO_free(buf); | ||
| 511 | if (ssl != NULL) BIO_free(ssl); | ||
| 512 | return(NULL); | ||
| 513 | } | ||
| 514 | |||
| 515 | BIO *BIO_new_ssl_connect(ctx) | ||
| 516 | SSL_CTX *ctx; | ||
| 517 | { | ||
| 518 | BIO *ret=NULL,*con=NULL,*ssl=NULL; | ||
| 519 | |||
| 520 | if ((con=BIO_new(BIO_s_connect())) == NULL) | ||
| 521 | return(NULL); | ||
| 522 | if ((ssl=BIO_new_ssl(ctx,1)) == NULL) | ||
| 523 | goto err; | ||
| 524 | if ((ret=BIO_push(ssl,con)) == NULL) | ||
| 525 | goto err; | ||
| 526 | return(ret); | ||
| 527 | err: | ||
| 528 | if (con != NULL) BIO_free(con); | ||
| 529 | if (ret != NULL) BIO_free(ret); | ||
| 530 | return(NULL); | ||
| 531 | } | ||
| 532 | |||
| 533 | BIO *BIO_new_ssl(ctx,client) | ||
| 534 | SSL_CTX *ctx; | ||
| 535 | int client; | ||
| 536 | { | ||
| 537 | BIO *ret; | ||
| 538 | SSL *ssl; | ||
| 539 | |||
| 540 | if ((ret=BIO_new(BIO_f_ssl())) == NULL) | ||
| 541 | return(NULL); | ||
| 542 | if ((ssl=SSL_new(ctx)) == NULL) | ||
| 543 | { | ||
| 544 | BIO_free(ret); | ||
| 545 | return(NULL); | ||
| 546 | } | ||
| 547 | if (client) | ||
| 548 | SSL_set_connect_state(ssl); | ||
| 549 | else | ||
| 550 | SSL_set_accept_state(ssl); | ||
| 551 | |||
| 552 | BIO_set_ssl(ret,ssl,BIO_CLOSE); | ||
| 553 | return(ret); | ||
| 554 | } | ||
| 555 | |||
| 556 | int BIO_ssl_copy_session_id(t,f) | ||
| 557 | BIO *t,*f; | ||
| 558 | { | ||
| 559 | t=BIO_find_type(t,BIO_TYPE_SSL); | ||
| 560 | f=BIO_find_type(f,BIO_TYPE_SSL); | ||
| 561 | if ((t == NULL) || (f == NULL)) | ||
| 562 | return(0); | ||
| 563 | if ( (((BIO_SSL *)t->ptr)->ssl == NULL) || | ||
| 564 | (((BIO_SSL *)f->ptr)->ssl == NULL)) | ||
| 565 | return(0); | ||
| 566 | SSL_copy_session_id(((BIO_SSL *)t->ptr)->ssl,((BIO_SSL *)f->ptr)->ssl); | ||
| 567 | return(1); | ||
| 568 | } | ||
| 569 | |||
| 570 | void BIO_ssl_shutdown(b) | ||
| 571 | BIO *b; | ||
| 572 | { | ||
| 573 | SSL *s; | ||
| 574 | |||
| 575 | while (b != NULL) | ||
| 576 | { | ||
| 577 | if (b->method->type == BIO_TYPE_SSL) | ||
| 578 | { | ||
| 579 | s=((BIO_SSL *)b->ptr)->ssl; | ||
| 580 | SSL_shutdown(s); | ||
| 581 | break; | ||
| 582 | } | ||
| 583 | b=b->next_bio; | ||
| 584 | } | ||
| 585 | } | ||
diff --git a/src/lib/libssl/s23_clnt.c b/src/lib/libssl/s23_clnt.c new file mode 100644 index 0000000000..a4661ebb68 --- /dev/null +++ b/src/lib/libssl/s23_clnt.c | |||
| @@ -0,0 +1,466 @@ | |||
| 1 | /* ssl/s23_clnt.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 "buffer.h" | ||
| 61 | #include "rand.h" | ||
| 62 | #include "objects.h" | ||
| 63 | #include "evp.h" | ||
| 64 | #include "ssl_locl.h" | ||
| 65 | |||
| 66 | #define BREAK break | ||
| 67 | |||
| 68 | #ifndef NOPROTO | ||
| 69 | static int ssl23_client_hello(SSL *s); | ||
| 70 | static int ssl23_get_server_hello(SSL *s); | ||
| 71 | #else | ||
| 72 | static int ssl23_client_hello(); | ||
| 73 | static int ssl23_get_server_hello(); | ||
| 74 | #endif | ||
| 75 | |||
| 76 | static SSL_METHOD *ssl23_get_client_method(ver) | ||
| 77 | int ver; | ||
| 78 | { | ||
| 79 | if (ver == SSL2_VERSION) | ||
| 80 | return(SSLv2_client_method()); | ||
| 81 | else if (ver == SSL3_VERSION) | ||
| 82 | return(SSLv3_client_method()); | ||
| 83 | else if (ver == TLS1_VERSION) | ||
| 84 | return(TLSv1_client_method()); | ||
| 85 | else | ||
| 86 | return(NULL); | ||
| 87 | } | ||
| 88 | |||
| 89 | SSL_METHOD *SSLv23_client_method() | ||
| 90 | { | ||
| 91 | static int init=1; | ||
| 92 | static SSL_METHOD SSLv23_client_data; | ||
| 93 | |||
| 94 | if (init) | ||
| 95 | { | ||
| 96 | init=0; | ||
| 97 | memcpy((char *)&SSLv23_client_data, | ||
| 98 | (char *)sslv23_base_method(),sizeof(SSL_METHOD)); | ||
| 99 | SSLv23_client_data.ssl_connect=ssl23_connect; | ||
| 100 | SSLv23_client_data.get_ssl_method=ssl23_get_client_method; | ||
| 101 | } | ||
| 102 | return(&SSLv23_client_data); | ||
| 103 | } | ||
| 104 | |||
| 105 | int ssl23_connect(s) | ||
| 106 | SSL *s; | ||
| 107 | { | ||
| 108 | BUF_MEM *buf; | ||
| 109 | unsigned long Time=time(NULL); | ||
| 110 | void (*cb)()=NULL; | ||
| 111 | int ret= -1; | ||
| 112 | int new_state,state; | ||
| 113 | |||
| 114 | RAND_seed((unsigned char *)&Time,sizeof(Time)); | ||
| 115 | ERR_clear_error(); | ||
| 116 | clear_sys_error(); | ||
| 117 | |||
| 118 | if (s->info_callback != NULL) | ||
| 119 | cb=s->info_callback; | ||
| 120 | else if (s->ctx->info_callback != NULL) | ||
| 121 | cb=s->ctx->info_callback; | ||
| 122 | |||
| 123 | if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s); | ||
| 124 | s->in_handshake++; | ||
| 125 | |||
| 126 | for (;;) | ||
| 127 | { | ||
| 128 | state=s->state; | ||
| 129 | |||
| 130 | switch(s->state) | ||
| 131 | { | ||
| 132 | case SSL_ST_BEFORE: | ||
| 133 | case SSL_ST_CONNECT: | ||
| 134 | case SSL_ST_BEFORE|SSL_ST_CONNECT: | ||
| 135 | case SSL_ST_OK|SSL_ST_CONNECT: | ||
| 136 | |||
| 137 | if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1); | ||
| 138 | |||
| 139 | /* s->version=TLS1_VERSION; */ | ||
| 140 | s->type=SSL_ST_CONNECT; | ||
| 141 | |||
| 142 | if (s->init_buf == NULL) | ||
| 143 | { | ||
| 144 | if ((buf=BUF_MEM_new()) == NULL) | ||
| 145 | { | ||
| 146 | ret= -1; | ||
| 147 | goto end; | ||
| 148 | } | ||
| 149 | if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH)) | ||
| 150 | { | ||
| 151 | ret= -1; | ||
| 152 | goto end; | ||
| 153 | } | ||
| 154 | s->init_buf=buf; | ||
| 155 | } | ||
| 156 | |||
| 157 | if (!ssl3_setup_buffers(s)) { ret= -1; goto end; } | ||
| 158 | |||
| 159 | ssl3_init_finished_mac(s); | ||
| 160 | |||
| 161 | s->state=SSL23_ST_CW_CLNT_HELLO_A; | ||
| 162 | s->ctx->sess_connect++; | ||
| 163 | s->init_num=0; | ||
| 164 | break; | ||
| 165 | |||
| 166 | case SSL23_ST_CW_CLNT_HELLO_A: | ||
| 167 | case SSL23_ST_CW_CLNT_HELLO_B: | ||
| 168 | |||
| 169 | s->shutdown=0; | ||
| 170 | ret=ssl23_client_hello(s); | ||
| 171 | if (ret <= 0) goto end; | ||
| 172 | s->state=SSL23_ST_CR_SRVR_HELLO_A; | ||
| 173 | s->init_num=0; | ||
| 174 | |||
| 175 | break; | ||
| 176 | |||
| 177 | case SSL23_ST_CR_SRVR_HELLO_A: | ||
| 178 | case SSL23_ST_CR_SRVR_HELLO_B: | ||
| 179 | ret=ssl23_get_server_hello(s); | ||
| 180 | if (ret >= 0) cb=NULL; | ||
| 181 | goto end; | ||
| 182 | break; | ||
| 183 | |||
| 184 | default: | ||
| 185 | SSLerr(SSL_F_SSL23_CONNECT,SSL_R_UNKNOWN_STATE); | ||
| 186 | ret= -1; | ||
| 187 | goto end; | ||
| 188 | /* break; */ | ||
| 189 | } | ||
| 190 | |||
| 191 | if (s->debug) BIO_flush(s->wbio); | ||
| 192 | |||
| 193 | if ((cb != NULL) && (s->state != state)) | ||
| 194 | { | ||
| 195 | new_state=s->state; | ||
| 196 | s->state=state; | ||
| 197 | cb(s,SSL_CB_CONNECT_LOOP,1); | ||
| 198 | s->state=new_state; | ||
| 199 | } | ||
| 200 | } | ||
| 201 | end: | ||
| 202 | s->in_handshake--; | ||
| 203 | if (cb != NULL) | ||
| 204 | cb(s,SSL_CB_CONNECT_EXIT,ret); | ||
| 205 | return(ret); | ||
| 206 | } | ||
| 207 | |||
| 208 | |||
| 209 | static int ssl23_client_hello(s) | ||
| 210 | SSL *s; | ||
| 211 | { | ||
| 212 | unsigned char *buf; | ||
| 213 | unsigned char *p,*d; | ||
| 214 | int i,ch_len; | ||
| 215 | |||
| 216 | buf=(unsigned char *)s->init_buf->data; | ||
| 217 | if (s->state == SSL23_ST_CW_CLNT_HELLO_A) | ||
| 218 | { | ||
| 219 | #if 0 | ||
| 220 | /* don't reuse session-id's */ | ||
| 221 | if (!ssl_get_new_session(s,0)) | ||
| 222 | { | ||
| 223 | return(-1); | ||
| 224 | } | ||
| 225 | #endif | ||
| 226 | |||
| 227 | p=s->s3->client_random; | ||
| 228 | RAND_bytes(p,SSL3_RANDOM_SIZE); | ||
| 229 | |||
| 230 | /* Do the message type and length last */ | ||
| 231 | d= &(buf[2]); | ||
| 232 | p=d+9; | ||
| 233 | |||
| 234 | *(d++)=SSL2_MT_CLIENT_HELLO; | ||
| 235 | if (!(s->options & SSL_OP_NO_TLSv1)) | ||
| 236 | { | ||
| 237 | *(d++)=TLS1_VERSION_MAJOR; | ||
| 238 | *(d++)=TLS1_VERSION_MINOR; | ||
| 239 | } | ||
| 240 | else if (!(s->options & SSL_OP_NO_SSLv3)) | ||
| 241 | { | ||
| 242 | *(d++)=SSL3_VERSION_MAJOR; | ||
| 243 | *(d++)=SSL3_VERSION_MINOR; | ||
| 244 | } | ||
| 245 | else if (!(s->options & SSL_OP_NO_SSLv2)) | ||
| 246 | { | ||
| 247 | *(d++)=SSL2_VERSION_MAJOR; | ||
| 248 | *(d++)=SSL2_VERSION_MINOR; | ||
| 249 | } | ||
| 250 | else | ||
| 251 | { | ||
| 252 | SSLerr(SSL_F_SSL23_CLIENT_HELLO,SSL_R_NO_PROTOCOLS_AVAILABLE); | ||
| 253 | return(-1); | ||
| 254 | } | ||
| 255 | |||
| 256 | /* Ciphers supported */ | ||
| 257 | i=ssl_cipher_list_to_bytes(s,SSL_get_ciphers(s),p); | ||
| 258 | if (i == 0) | ||
| 259 | { | ||
| 260 | /* no ciphers */ | ||
| 261 | SSLerr(SSL_F_SSL23_CLIENT_HELLO,SSL_R_NO_CIPHERS_AVAILABLE); | ||
| 262 | return(-1); | ||
| 263 | } | ||
| 264 | s2n(i,d); | ||
| 265 | p+=i; | ||
| 266 | |||
| 267 | /* put in the session-id, zero since there is no | ||
| 268 | * reuse. */ | ||
| 269 | #if 0 | ||
| 270 | s->session->session_id_length=0; | ||
| 271 | #endif | ||
| 272 | s2n(0,d); | ||
| 273 | |||
| 274 | if (s->options & SSL_OP_NETSCAPE_CHALLENGE_BUG) | ||
| 275 | ch_len=SSL2_CHALLENGE_LENGTH; | ||
| 276 | else | ||
| 277 | ch_len=SSL2_MAX_CHALLENGE_LENGTH; | ||
| 278 | |||
| 279 | /* write out sslv2 challenge */ | ||
| 280 | if (SSL3_RANDOM_SIZE < ch_len) | ||
| 281 | i=SSL3_RANDOM_SIZE; | ||
| 282 | else | ||
| 283 | i=ch_len; | ||
| 284 | s2n(i,d); | ||
| 285 | memset(&(s->s3->client_random[0]),0,SSL3_RANDOM_SIZE); | ||
| 286 | RAND_bytes(&(s->s3->client_random[SSL3_RANDOM_SIZE-i]),i); | ||
| 287 | memcpy(p,&(s->s3->client_random[SSL3_RANDOM_SIZE-i]),i); | ||
| 288 | p+=i; | ||
| 289 | |||
| 290 | i= p- &(buf[2]); | ||
| 291 | buf[0]=((i>>8)&0xff)|0x80; | ||
| 292 | buf[1]=(i&0xff); | ||
| 293 | |||
| 294 | s->state=SSL23_ST_CW_CLNT_HELLO_B; | ||
| 295 | /* number of bytes to write */ | ||
| 296 | s->init_num=i+2; | ||
| 297 | s->init_off=0; | ||
| 298 | |||
| 299 | ssl3_finish_mac(s,&(buf[2]),i); | ||
| 300 | } | ||
| 301 | |||
| 302 | /* SSL3_ST_CW_CLNT_HELLO_B */ | ||
| 303 | return(ssl23_write_bytes(s)); | ||
| 304 | } | ||
| 305 | |||
| 306 | static int ssl23_get_server_hello(s) | ||
| 307 | SSL *s; | ||
| 308 | { | ||
| 309 | char buf[8]; | ||
| 310 | unsigned char *p; | ||
| 311 | int i,ch_len; | ||
| 312 | int n; | ||
| 313 | |||
| 314 | n=ssl23_read_bytes(s,7); | ||
| 315 | |||
| 316 | if (n != 7) return(n); | ||
| 317 | p=s->packet; | ||
| 318 | |||
| 319 | memcpy(buf,p,n); | ||
| 320 | |||
| 321 | if ((p[0] & 0x80) && (p[2] == SSL2_MT_SERVER_HELLO) && | ||
| 322 | (p[5] == 0x00) && (p[6] == 0x02)) | ||
| 323 | { | ||
| 324 | /* we are talking sslv2 */ | ||
| 325 | /* we need to clean up the SSLv3 setup and put in the | ||
| 326 | * sslv2 stuff. */ | ||
| 327 | |||
| 328 | if (s->options & SSL_OP_NO_SSLv2) | ||
| 329 | { | ||
| 330 | SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_PROTOCOL); | ||
| 331 | goto err; | ||
| 332 | } | ||
| 333 | if (s->s2 == NULL) | ||
| 334 | { | ||
| 335 | if (!ssl2_new(s)) | ||
| 336 | goto err; | ||
| 337 | } | ||
| 338 | else | ||
| 339 | ssl2_clear(s); | ||
| 340 | |||
| 341 | if (s->options & SSL_OP_NETSCAPE_CHALLENGE_BUG) | ||
| 342 | ch_len=SSL2_CHALLENGE_LENGTH; | ||
| 343 | else | ||
| 344 | ch_len=SSL2_MAX_CHALLENGE_LENGTH; | ||
| 345 | |||
| 346 | /* write out sslv2 challenge */ | ||
| 347 | i=(SSL3_RANDOM_SIZE < ch_len) | ||
| 348 | ?SSL3_RANDOM_SIZE:ch_len; | ||
| 349 | s->s2->challenge_length=i; | ||
| 350 | memcpy(s->s2->challenge, | ||
| 351 | &(s->s3->client_random[SSL3_RANDOM_SIZE-i]),i); | ||
| 352 | |||
| 353 | if (s->s3 != NULL) ssl3_free(s); | ||
| 354 | |||
| 355 | if (!BUF_MEM_grow(s->init_buf, | ||
| 356 | SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER)) | ||
| 357 | { | ||
| 358 | SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,ERR_R_BUF_LIB); | ||
| 359 | goto err; | ||
| 360 | } | ||
| 361 | |||
| 362 | s->state=SSL2_ST_GET_SERVER_HELLO_A; | ||
| 363 | s->s2->ssl2_rollback=1; | ||
| 364 | |||
| 365 | /* setup the 5 bytes we have read so we get them from | ||
| 366 | * the sslv2 buffer */ | ||
| 367 | s->rstate=SSL_ST_READ_HEADER; | ||
| 368 | s->packet_length=n; | ||
| 369 | s->packet= &(s->s2->rbuf[0]); | ||
| 370 | memcpy(s->packet,buf,n); | ||
| 371 | s->s2->rbuf_left=n; | ||
| 372 | s->s2->rbuf_offs=0; | ||
| 373 | |||
| 374 | /* we have already written one */ | ||
| 375 | s->s2->write_sequence=1; | ||
| 376 | |||
| 377 | s->method=SSLv2_client_method(); | ||
| 378 | s->handshake_func=s->method->ssl_connect; | ||
| 379 | } | ||
| 380 | else if ((p[0] == SSL3_RT_HANDSHAKE) && | ||
| 381 | (p[1] == SSL3_VERSION_MAJOR) && | ||
| 382 | ((p[2] == SSL3_VERSION_MINOR) || | ||
| 383 | (p[2] == TLS1_VERSION_MINOR)) && | ||
| 384 | (p[5] == SSL3_MT_SERVER_HELLO)) | ||
| 385 | { | ||
| 386 | /* we have sslv3 or tls1 */ | ||
| 387 | |||
| 388 | if (!ssl_init_wbio_buffer(s,1)) goto err; | ||
| 389 | |||
| 390 | /* we are in this state */ | ||
| 391 | s->state=SSL3_ST_CR_SRVR_HELLO_A; | ||
| 392 | |||
| 393 | /* put the 5 bytes we have read into the input buffer | ||
| 394 | * for SSLv3 */ | ||
| 395 | s->rstate=SSL_ST_READ_HEADER; | ||
| 396 | s->packet_length=n; | ||
| 397 | s->packet= &(s->s3->rbuf.buf[0]); | ||
| 398 | memcpy(s->packet,buf,n); | ||
| 399 | s->s3->rbuf.left=n; | ||
| 400 | s->s3->rbuf.offset=0; | ||
| 401 | |||
| 402 | if ((p[2] == SSL3_VERSION_MINOR) && | ||
| 403 | !(s->options & SSL_OP_NO_SSLv3)) | ||
| 404 | { | ||
| 405 | s->version=SSL3_VERSION; | ||
| 406 | s->method=SSLv3_client_method(); | ||
| 407 | } | ||
| 408 | else if ((p[2] == TLS1_VERSION_MINOR) && | ||
| 409 | !(s->options & SSL_OP_NO_TLSv1)) | ||
| 410 | { | ||
| 411 | s->version=TLS1_VERSION; | ||
| 412 | s->method=TLSv1_client_method(); | ||
| 413 | } | ||
| 414 | else | ||
| 415 | { | ||
| 416 | SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_PROTOCOL); | ||
| 417 | goto err; | ||
| 418 | } | ||
| 419 | |||
| 420 | s->handshake_func=s->method->ssl_connect; | ||
| 421 | } | ||
| 422 | else if ((p[0] == SSL3_RT_ALERT) && | ||
| 423 | (p[1] == SSL3_VERSION_MAJOR) && | ||
| 424 | ((p[2] == SSL3_VERSION_MINOR) || | ||
| 425 | (p[2] == TLS1_VERSION_MINOR)) && | ||
| 426 | (p[3] == 0) && | ||
| 427 | (p[4] == 2)) | ||
| 428 | { | ||
| 429 | void (*cb)()=NULL; | ||
| 430 | int j; | ||
| 431 | |||
| 432 | /* An alert */ | ||
| 433 | if (s->info_callback != NULL) | ||
| 434 | cb=s->info_callback; | ||
| 435 | else if (s->ctx->info_callback != NULL) | ||
| 436 | cb=s->ctx->info_callback; | ||
| 437 | |||
| 438 | i=p[5]; | ||
| 439 | if (cb != NULL) | ||
| 440 | { | ||
| 441 | j=(i<<8)|p[6]; | ||
| 442 | cb(s,SSL_CB_READ_ALERT,j); | ||
| 443 | } | ||
| 444 | |||
| 445 | s->rwstate=SSL_NOTHING; | ||
| 446 | SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,1000+p[6]); | ||
| 447 | goto err; | ||
| 448 | } | ||
| 449 | else | ||
| 450 | { | ||
| 451 | SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNKNOWN_PROTOCOL); | ||
| 452 | goto err; | ||
| 453 | } | ||
| 454 | s->init_num=0; | ||
| 455 | |||
| 456 | /* Since, if we are sending a ssl23 client hello, we are not | ||
| 457 | * reusing a session-id */ | ||
| 458 | if (!ssl_get_new_session(s,0)) | ||
| 459 | goto err; | ||
| 460 | |||
| 461 | s->first_packet=1; | ||
| 462 | return(SSL_connect(s)); | ||
| 463 | err: | ||
| 464 | return(-1); | ||
| 465 | } | ||
| 466 | |||
diff --git a/src/lib/libssl/s23_lib.c b/src/lib/libssl/s23_lib.c new file mode 100644 index 0000000000..e16f641101 --- /dev/null +++ b/src/lib/libssl/s23_lib.c | |||
| @@ -0,0 +1,233 @@ | |||
| 1 | /* ssl/s23_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 "objects.h" | ||
| 61 | #include "ssl_locl.h" | ||
| 62 | |||
| 63 | #ifndef NOPROTO | ||
| 64 | static int ssl23_num_ciphers(void ); | ||
| 65 | static SSL_CIPHER *ssl23_get_cipher(unsigned int u); | ||
| 66 | static int ssl23_read(SSL *s, char *buf, int len); | ||
| 67 | static int ssl23_write(SSL *s, char *buf, int len); | ||
| 68 | static long ssl23_default_timeout(void ); | ||
| 69 | static int ssl23_put_cipher_by_char(SSL_CIPHER *c, unsigned char *p); | ||
| 70 | static SSL_CIPHER *ssl23_get_cipher_by_char(unsigned char *p); | ||
| 71 | #else | ||
| 72 | static int ssl23_num_ciphers(); | ||
| 73 | static SSL_CIPHER *ssl23_get_cipher(); | ||
| 74 | static int ssl23_read(); | ||
| 75 | static int ssl23_write(); | ||
| 76 | static long ssl23_default_timeout(); | ||
| 77 | static int ssl23_put_cipher_by_char(); | ||
| 78 | static SSL_CIPHER *ssl23_get_cipher_by_char(); | ||
| 79 | #endif | ||
| 80 | |||
| 81 | char *SSL23_version_str="SSLv2/3 compatablity part of SSLeay 0.7.0 30-Jan-1997"; | ||
| 82 | |||
| 83 | static SSL_METHOD SSLv23_data= { | ||
| 84 | TLS1_VERSION, | ||
| 85 | tls1_new, | ||
| 86 | tls1_clear, | ||
| 87 | tls1_free, | ||
| 88 | ssl_undefined_function, | ||
| 89 | ssl_undefined_function, | ||
| 90 | ssl23_read, | ||
| 91 | ssl_undefined_function, | ||
| 92 | ssl23_write, | ||
| 93 | ssl_undefined_function, | ||
| 94 | ssl_undefined_function, | ||
| 95 | ssl3_ctrl, | ||
| 96 | ssl3_ctx_ctrl, | ||
| 97 | ssl23_get_cipher_by_char, | ||
| 98 | ssl23_put_cipher_by_char, | ||
| 99 | ssl_undefined_function, | ||
| 100 | ssl23_num_ciphers, | ||
| 101 | ssl23_get_cipher, | ||
| 102 | ssl_bad_method, | ||
| 103 | ssl23_default_timeout, | ||
| 104 | &ssl3_undef_enc_method, | ||
| 105 | }; | ||
| 106 | |||
| 107 | static long ssl23_default_timeout() | ||
| 108 | { | ||
| 109 | return(300); | ||
| 110 | } | ||
| 111 | |||
| 112 | SSL_METHOD *sslv23_base_method() | ||
| 113 | { | ||
| 114 | return(&SSLv23_data); | ||
| 115 | } | ||
| 116 | |||
| 117 | static int ssl23_num_ciphers() | ||
| 118 | { | ||
| 119 | return(ssl3_num_ciphers()+ssl2_num_ciphers()); | ||
| 120 | } | ||
| 121 | |||
| 122 | static SSL_CIPHER *ssl23_get_cipher(u) | ||
| 123 | unsigned int u; | ||
| 124 | { | ||
| 125 | unsigned int uu=ssl3_num_ciphers(); | ||
| 126 | |||
| 127 | if (u < uu) | ||
| 128 | return(ssl3_get_cipher(u)); | ||
| 129 | else | ||
| 130 | return(ssl2_get_cipher(u-uu)); | ||
| 131 | } | ||
| 132 | |||
| 133 | /* This function needs to check if the ciphers required are actually | ||
| 134 | * available */ | ||
| 135 | static SSL_CIPHER *ssl23_get_cipher_by_char(p) | ||
| 136 | unsigned char *p; | ||
| 137 | { | ||
| 138 | SSL_CIPHER c,*cp; | ||
| 139 | unsigned long id; | ||
| 140 | int n; | ||
| 141 | |||
| 142 | n=ssl3_num_ciphers(); | ||
| 143 | id=0x03000000|((unsigned long)p[0]<<16L)| | ||
| 144 | ((unsigned long)p[1]<<8L)|(unsigned long)p[2]; | ||
| 145 | c.id=id; | ||
| 146 | cp=ssl3_get_cipher_by_char(p); | ||
| 147 | if (cp == NULL) | ||
| 148 | cp=ssl2_get_cipher_by_char(p); | ||
| 149 | return(cp); | ||
| 150 | } | ||
| 151 | |||
| 152 | static int ssl23_put_cipher_by_char(c,p) | ||
| 153 | SSL_CIPHER *c; | ||
| 154 | unsigned char *p; | ||
| 155 | { | ||
| 156 | long l; | ||
| 157 | |||
| 158 | /* We can write SSLv2 and SSLv3 ciphers */ | ||
| 159 | if (p != NULL) | ||
| 160 | { | ||
| 161 | l=c->id; | ||
| 162 | p[0]=((unsigned char)(l>>16L))&0xFF; | ||
| 163 | p[1]=((unsigned char)(l>> 8L))&0xFF; | ||
| 164 | p[2]=((unsigned char)(l ))&0xFF; | ||
| 165 | } | ||
| 166 | return(3); | ||
| 167 | } | ||
| 168 | |||
| 169 | static int ssl23_read(s,buf,len) | ||
| 170 | SSL *s; | ||
| 171 | char *buf; | ||
| 172 | int len; | ||
| 173 | { | ||
| 174 | int n; | ||
| 175 | |||
| 176 | #if 0 | ||
| 177 | if (s->shutdown & SSL_RECEIVED_SHUTDOWN) | ||
| 178 | { | ||
| 179 | s->rwstate=SSL_NOTHING; | ||
| 180 | return(0); | ||
| 181 | } | ||
| 182 | #endif | ||
| 183 | clear_sys_error(); | ||
| 184 | if (SSL_in_init(s) && (!s->in_handshake)) | ||
| 185 | { | ||
| 186 | n=s->handshake_func(s); | ||
| 187 | if (n < 0) return(n); | ||
| 188 | if (n == 0) | ||
| 189 | { | ||
| 190 | SSLerr(SSL_F_SSL23_READ,SSL_R_SSL_HANDSHAKE_FAILURE); | ||
| 191 | return(-1); | ||
| 192 | } | ||
| 193 | return(SSL_read(s,buf,len)); | ||
| 194 | } | ||
| 195 | else | ||
| 196 | { | ||
| 197 | ssl_undefined_function(s); | ||
| 198 | return(-1); | ||
| 199 | } | ||
| 200 | } | ||
| 201 | |||
| 202 | static int ssl23_write(s,buf,len) | ||
| 203 | SSL *s; | ||
| 204 | char *buf; | ||
| 205 | int len; | ||
| 206 | { | ||
| 207 | int n; | ||
| 208 | |||
| 209 | #if 0 | ||
| 210 | if (s->shutdown & SSL_SENT_SHUTDOWN) | ||
| 211 | { | ||
| 212 | s->rwstate=SSL_NOTHING; | ||
| 213 | return(0); | ||
| 214 | } | ||
| 215 | #endif | ||
| 216 | clear_sys_error(); | ||
| 217 | if (SSL_in_init(s) && (!s->in_handshake)) | ||
| 218 | { | ||
| 219 | n=s->handshake_func(s); | ||
| 220 | if (n < 0) return(n); | ||
| 221 | if (n == 0) | ||
| 222 | { | ||
| 223 | SSLerr(SSL_F_SSL23_WRITE,SSL_R_SSL_HANDSHAKE_FAILURE); | ||
| 224 | return(-1); | ||
| 225 | } | ||
| 226 | return(SSL_write(s,buf,len)); | ||
| 227 | } | ||
| 228 | else | ||
| 229 | { | ||
| 230 | ssl_undefined_function(s); | ||
| 231 | return(-1); | ||
| 232 | } | ||
| 233 | } | ||
diff --git a/src/lib/libssl/s23_pkt.c b/src/lib/libssl/s23_pkt.c new file mode 100644 index 0000000000..c25c312772 --- /dev/null +++ b/src/lib/libssl/s23_pkt.c | |||
| @@ -0,0 +1,120 @@ | |||
| 1 | /* ssl/s23_pkt.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 <errno.h> | ||
| 61 | #define USE_SOCKETS | ||
| 62 | #include "evp.h" | ||
| 63 | #include "buffer.h" | ||
| 64 | #include "ssl_locl.h" | ||
| 65 | |||
| 66 | int ssl23_write_bytes(s) | ||
| 67 | SSL *s; | ||
| 68 | { | ||
| 69 | int i,num,tot; | ||
| 70 | char *buf; | ||
| 71 | |||
| 72 | buf=s->init_buf->data; | ||
| 73 | tot=s->init_off; | ||
| 74 | num=s->init_num; | ||
| 75 | for (;;) | ||
| 76 | { | ||
| 77 | s->rwstate=SSL_WRITING; | ||
| 78 | i=BIO_write(s->wbio,&(buf[tot]),num); | ||
| 79 | if (i < 0) | ||
| 80 | { | ||
| 81 | s->init_off=tot; | ||
| 82 | s->init_num=num; | ||
| 83 | return(i); | ||
| 84 | } | ||
| 85 | s->rwstate=SSL_NOTHING; | ||
| 86 | if (i == num) return(tot+i); | ||
| 87 | |||
| 88 | num-=i; | ||
| 89 | tot+=i; | ||
| 90 | } | ||
| 91 | } | ||
| 92 | |||
| 93 | /* only return when we have read 'n' bytes */ | ||
| 94 | int ssl23_read_bytes(s,n) | ||
| 95 | SSL *s; | ||
| 96 | int n; | ||
| 97 | { | ||
| 98 | unsigned char *p; | ||
| 99 | int j; | ||
| 100 | |||
| 101 | if (s->packet_length < (unsigned int)n) | ||
| 102 | { | ||
| 103 | p=s->packet; | ||
| 104 | |||
| 105 | for (;;) | ||
| 106 | { | ||
| 107 | s->rwstate=SSL_READING; | ||
| 108 | j=BIO_read(s->rbio,(char *)&(p[s->packet_length]), | ||
| 109 | n-s->packet_length); | ||
| 110 | if (j <= 0) | ||
| 111 | return(j); | ||
| 112 | s->rwstate=SSL_NOTHING; | ||
| 113 | s->packet_length+=j; | ||
| 114 | if (s->packet_length >= (unsigned int)n) | ||
| 115 | return(s->packet_length); | ||
| 116 | } | ||
| 117 | } | ||
| 118 | return(n); | ||
| 119 | } | ||
| 120 | |||
diff --git a/src/lib/libssl/s23_srvr.c b/src/lib/libssl/s23_srvr.c new file mode 100644 index 0000000000..c7b9ecbcf2 --- /dev/null +++ b/src/lib/libssl/s23_srvr.c | |||
| @@ -0,0 +1,499 @@ | |||
| 1 | /* ssl/s23_srvr.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 "buffer.h" | ||
| 61 | #include "rand.h" | ||
| 62 | #include "objects.h" | ||
| 63 | #include "evp.h" | ||
| 64 | #include "ssl_locl.h" | ||
| 65 | |||
| 66 | #define BREAK break | ||
| 67 | |||
| 68 | #ifndef NOPROTO | ||
| 69 | int ssl23_get_client_hello(SSL *s); | ||
| 70 | #else | ||
| 71 | int ssl23_get_client_hello(); | ||
| 72 | #endif | ||
| 73 | |||
| 74 | static SSL_METHOD *ssl23_get_server_method(ver) | ||
| 75 | int ver; | ||
| 76 | { | ||
| 77 | if (ver == SSL2_VERSION) | ||
| 78 | return(SSLv2_server_method()); | ||
| 79 | else if (ver == SSL3_VERSION) | ||
| 80 | return(SSLv3_server_method()); | ||
| 81 | else if (ver == TLS1_VERSION) | ||
| 82 | return(TLSv1_server_method()); | ||
| 83 | else | ||
| 84 | return(NULL); | ||
| 85 | } | ||
| 86 | |||
| 87 | SSL_METHOD *SSLv23_server_method() | ||
| 88 | { | ||
| 89 | static int init=1; | ||
| 90 | static SSL_METHOD SSLv23_server_data; | ||
| 91 | |||
| 92 | if (init) | ||
| 93 | { | ||
| 94 | init=0; | ||
| 95 | memcpy((char *)&SSLv23_server_data, | ||
| 96 | (char *)sslv23_base_method(),sizeof(SSL_METHOD)); | ||
| 97 | SSLv23_server_data.ssl_accept=ssl23_accept; | ||
| 98 | SSLv23_server_data.get_ssl_method=ssl23_get_server_method; | ||
| 99 | } | ||
| 100 | return(&SSLv23_server_data); | ||
| 101 | } | ||
| 102 | |||
| 103 | int ssl23_accept(s) | ||
| 104 | SSL *s; | ||
| 105 | { | ||
| 106 | BUF_MEM *buf; | ||
| 107 | unsigned long Time=time(NULL); | ||
| 108 | void (*cb)()=NULL; | ||
| 109 | int ret= -1; | ||
| 110 | int new_state,state; | ||
| 111 | |||
| 112 | RAND_seed((unsigned char *)&Time,sizeof(Time)); | ||
| 113 | ERR_clear_error(); | ||
| 114 | clear_sys_error(); | ||
| 115 | |||
| 116 | if (s->info_callback != NULL) | ||
| 117 | cb=s->info_callback; | ||
| 118 | else if (s->ctx->info_callback != NULL) | ||
| 119 | cb=s->ctx->info_callback; | ||
| 120 | |||
| 121 | if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s); | ||
| 122 | s->in_handshake++; | ||
| 123 | |||
| 124 | for (;;) | ||
| 125 | { | ||
| 126 | state=s->state; | ||
| 127 | |||
| 128 | switch(s->state) | ||
| 129 | { | ||
| 130 | case SSL_ST_BEFORE: | ||
| 131 | case SSL_ST_ACCEPT: | ||
| 132 | case SSL_ST_BEFORE|SSL_ST_ACCEPT: | ||
| 133 | case SSL_ST_OK|SSL_ST_ACCEPT: | ||
| 134 | |||
| 135 | if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1); | ||
| 136 | |||
| 137 | /* s->version=SSL3_VERSION; */ | ||
| 138 | s->type=SSL_ST_ACCEPT; | ||
| 139 | |||
| 140 | if (s->init_buf == NULL) | ||
| 141 | { | ||
| 142 | if ((buf=BUF_MEM_new()) == NULL) | ||
| 143 | { | ||
| 144 | ret= -1; | ||
| 145 | goto end; | ||
| 146 | } | ||
| 147 | if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH)) | ||
| 148 | { | ||
| 149 | ret= -1; | ||
| 150 | goto end; | ||
| 151 | } | ||
| 152 | s->init_buf=buf; | ||
| 153 | } | ||
| 154 | |||
| 155 | ssl3_init_finished_mac(s); | ||
| 156 | |||
| 157 | s->state=SSL23_ST_SR_CLNT_HELLO_A; | ||
| 158 | s->ctx->sess_accept++; | ||
| 159 | s->init_num=0; | ||
| 160 | break; | ||
| 161 | |||
| 162 | case SSL23_ST_SR_CLNT_HELLO_A: | ||
| 163 | case SSL23_ST_SR_CLNT_HELLO_B: | ||
| 164 | |||
| 165 | s->shutdown=0; | ||
| 166 | ret=ssl23_get_client_hello(s); | ||
| 167 | if (ret >= 0) cb=NULL; | ||
| 168 | goto end; | ||
| 169 | break; | ||
| 170 | |||
| 171 | default: | ||
| 172 | SSLerr(SSL_F_SSL23_ACCEPT,SSL_R_UNKNOWN_STATE); | ||
| 173 | ret= -1; | ||
| 174 | goto end; | ||
| 175 | /* break; */ | ||
| 176 | } | ||
| 177 | |||
| 178 | if ((cb != NULL) && (s->state != state)) | ||
| 179 | { | ||
| 180 | new_state=s->state; | ||
| 181 | s->state=state; | ||
| 182 | cb(s,SSL_CB_ACCEPT_LOOP,1); | ||
| 183 | s->state=new_state; | ||
| 184 | } | ||
| 185 | } | ||
| 186 | end: | ||
| 187 | if (cb != NULL) | ||
| 188 | cb(s,SSL_CB_ACCEPT_EXIT,ret); | ||
| 189 | s->in_handshake--; | ||
| 190 | return(ret); | ||
| 191 | } | ||
| 192 | |||
| 193 | |||
| 194 | int ssl23_get_client_hello(s) | ||
| 195 | SSL *s; | ||
| 196 | { | ||
| 197 | char buf_space[8]; | ||
| 198 | char *buf= &(buf_space[0]); | ||
| 199 | unsigned char *p,*d,*dd; | ||
| 200 | unsigned int i; | ||
| 201 | unsigned int csl,sil,cl; | ||
| 202 | int n=0,j,tls1=0; | ||
| 203 | int type=0,use_sslv2_strong=0; | ||
| 204 | |||
| 205 | /* read the initial header */ | ||
| 206 | if (s->state == SSL23_ST_SR_CLNT_HELLO_A) | ||
| 207 | { | ||
| 208 | if (!ssl3_setup_buffers(s)) goto err; | ||
| 209 | |||
| 210 | n=ssl23_read_bytes(s,7); | ||
| 211 | if (n != 7) return(n); | ||
| 212 | |||
| 213 | p=s->packet; | ||
| 214 | |||
| 215 | memcpy(buf,p,n); | ||
| 216 | |||
| 217 | if ((p[0] & 0x80) && (p[2] == SSL2_MT_CLIENT_HELLO)) | ||
| 218 | { | ||
| 219 | /* SSLv2 header */ | ||
| 220 | if ((p[3] == 0x00) && (p[4] == 0x02)) | ||
| 221 | { | ||
| 222 | /* SSLv2 */ | ||
| 223 | if (!(s->options & SSL_OP_NO_SSLv2)) | ||
| 224 | type=1; | ||
| 225 | } | ||
| 226 | else if (p[3] == SSL3_VERSION_MAJOR) | ||
| 227 | { | ||
| 228 | /* SSLv3/TLSv1 */ | ||
| 229 | if (p[4] >= TLS1_VERSION_MINOR) | ||
| 230 | { | ||
| 231 | if (!(s->options & SSL_OP_NO_TLSv1)) | ||
| 232 | { | ||
| 233 | tls1=1; | ||
| 234 | s->state=SSL23_ST_SR_CLNT_HELLO_B; | ||
| 235 | } | ||
| 236 | else if (!(s->options & SSL_OP_NO_SSLv3)) | ||
| 237 | { | ||
| 238 | s->state=SSL23_ST_SR_CLNT_HELLO_B; | ||
| 239 | } | ||
| 240 | } | ||
| 241 | else if (!(s->options & SSL_OP_NO_SSLv3)) | ||
| 242 | s->state=SSL23_ST_SR_CLNT_HELLO_B; | ||
| 243 | |||
| 244 | if (s->options & SSL_OP_NON_EXPORT_FIRST) | ||
| 245 | { | ||
| 246 | STACK *sk; | ||
| 247 | SSL_CIPHER *c; | ||
| 248 | int ne2,ne3; | ||
| 249 | |||
| 250 | j=((p[0]&0x7f)<<8)|p[1]; | ||
| 251 | if (j > (1024*4)) | ||
| 252 | { | ||
| 253 | SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_TOO_LARGE); | ||
| 254 | goto err; | ||
| 255 | } | ||
| 256 | |||
| 257 | n=ssl23_read_bytes(s,j+2); | ||
| 258 | if (n <= 0) return(n); | ||
| 259 | p=s->packet; | ||
| 260 | |||
| 261 | if ((buf=Malloc(n)) == NULL) | ||
| 262 | { | ||
| 263 | SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,ERR_R_MALLOC_FAILURE); | ||
| 264 | goto err; | ||
| 265 | } | ||
| 266 | memcpy(buf,p,n); | ||
| 267 | |||
| 268 | p+=5; | ||
| 269 | n2s(p,csl); | ||
| 270 | p+=4; | ||
| 271 | |||
| 272 | sk=ssl_bytes_to_cipher_list( | ||
| 273 | s,p,csl,NULL); | ||
| 274 | if (sk != NULL) | ||
| 275 | { | ||
| 276 | ne2=ne3=0; | ||
| 277 | for (j=0; j<sk_num(sk); j++) | ||
| 278 | { | ||
| 279 | c=(SSL_CIPHER *)sk_value(sk,j); | ||
| 280 | if (!(c->algorithms & SSL_EXP)) | ||
| 281 | { | ||
| 282 | if ((c->id>>24L) == 2L) | ||
| 283 | ne2=1; | ||
| 284 | else | ||
| 285 | ne3=1; | ||
| 286 | } | ||
| 287 | } | ||
| 288 | if (ne2 && !ne3) | ||
| 289 | { | ||
| 290 | type=1; | ||
| 291 | use_sslv2_strong=1; | ||
| 292 | goto next_bit; | ||
| 293 | } | ||
| 294 | } | ||
| 295 | } | ||
| 296 | } | ||
| 297 | } | ||
| 298 | else if ((p[0] == SSL3_RT_HANDSHAKE) && | ||
| 299 | (p[1] == SSL3_VERSION_MAJOR) && | ||
| 300 | (p[5] == SSL3_MT_CLIENT_HELLO)) | ||
| 301 | { | ||
| 302 | /* true SSLv3 or tls1 */ | ||
| 303 | if (p[2] >= TLS1_VERSION_MINOR) | ||
| 304 | { | ||
| 305 | if (!(s->options & SSL_OP_NO_TLSv1)) | ||
| 306 | { | ||
| 307 | type=3; | ||
| 308 | tls1=1; | ||
| 309 | } | ||
| 310 | else if (!(s->options & SSL_OP_NO_SSLv3)) | ||
| 311 | type=3; | ||
| 312 | } | ||
| 313 | else if (!(s->options & SSL_OP_NO_SSLv3)) | ||
| 314 | type=3; | ||
| 315 | } | ||
| 316 | else if ((strncmp("GET ", p,4) == 0) || | ||
| 317 | (strncmp("POST ",p,5) == 0) || | ||
| 318 | (strncmp("HEAD ",p,5) == 0) || | ||
| 319 | (strncmp("PUT ", p,4) == 0)) | ||
| 320 | { | ||
| 321 | SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_HTTP_REQUEST); | ||
| 322 | goto err; | ||
| 323 | } | ||
| 324 | else if (strncmp("CONNECT",p,7) == 0) | ||
| 325 | { | ||
| 326 | SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_HTTPS_PROXY_REQUEST); | ||
| 327 | goto err; | ||
| 328 | } | ||
| 329 | } | ||
| 330 | |||
| 331 | next_bit: | ||
| 332 | if (s->state == SSL23_ST_SR_CLNT_HELLO_B) | ||
| 333 | { | ||
| 334 | /* we have a SSLv3/TLSv1 in a SSLv2 header */ | ||
| 335 | type=2; | ||
| 336 | p=s->packet; | ||
| 337 | n=((p[0]&0x7f)<<8)|p[1]; | ||
| 338 | if (n > (1024*4)) | ||
| 339 | { | ||
| 340 | SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_TOO_LARGE); | ||
| 341 | goto err; | ||
| 342 | } | ||
| 343 | |||
| 344 | j=ssl23_read_bytes(s,n+2); | ||
| 345 | if (j <= 0) return(j); | ||
| 346 | |||
| 347 | ssl3_finish_mac(s,&(s->packet[2]),s->packet_length-2); | ||
| 348 | |||
| 349 | p=s->packet; | ||
| 350 | p+=5; | ||
| 351 | n2s(p,csl); | ||
| 352 | n2s(p,sil); | ||
| 353 | n2s(p,cl); | ||
| 354 | d=(unsigned char *)s->init_buf->data; | ||
| 355 | if ((csl+sil+cl+11) != s->packet_length) | ||
| 356 | { | ||
| 357 | SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_LENGTH_MISMATCH); | ||
| 358 | goto err; | ||
| 359 | } | ||
| 360 | |||
| 361 | *(d++)=SSL3_VERSION_MAJOR; | ||
| 362 | if (tls1) | ||
| 363 | *(d++)=TLS1_VERSION_MINOR; | ||
| 364 | else | ||
| 365 | *(d++)=SSL3_VERSION_MINOR; | ||
| 366 | |||
| 367 | /* lets populate the random area */ | ||
| 368 | /* get the chalenge_length */ | ||
| 369 | i=(cl > SSL3_RANDOM_SIZE)?SSL3_RANDOM_SIZE:cl; | ||
| 370 | memset(d,0,SSL3_RANDOM_SIZE); | ||
| 371 | memcpy(&(d[SSL3_RANDOM_SIZE-i]),&(p[csl+sil]),i); | ||
| 372 | d+=SSL3_RANDOM_SIZE; | ||
| 373 | |||
| 374 | /* no session-id reuse */ | ||
| 375 | *(d++)=0; | ||
| 376 | |||
| 377 | /* ciphers */ | ||
| 378 | j=0; | ||
| 379 | dd=d; | ||
| 380 | d+=2; | ||
| 381 | for (i=0; i<csl; i+=3) | ||
| 382 | { | ||
| 383 | if (p[i] != 0) continue; | ||
| 384 | *(d++)=p[i+1]; | ||
| 385 | *(d++)=p[i+2]; | ||
| 386 | j+=2; | ||
| 387 | } | ||
| 388 | s2n(j,dd); | ||
| 389 | |||
| 390 | /* compression */ | ||
| 391 | *(d++)=1; | ||
| 392 | *(d++)=0; | ||
| 393 | |||
| 394 | i=(d-(unsigned char *)s->init_buf->data); | ||
| 395 | |||
| 396 | /* get the data reused from the init_buf */ | ||
| 397 | s->s3->tmp.reuse_message=1; | ||
| 398 | s->s3->tmp.message_type=SSL3_MT_CLIENT_HELLO; | ||
| 399 | s->s3->tmp.message_size=i; | ||
| 400 | } | ||
| 401 | |||
| 402 | if (type == 1) | ||
| 403 | { | ||
| 404 | /* we are talking sslv2 */ | ||
| 405 | /* we need to clean up the SSLv3/TLSv1 setup and put in the | ||
| 406 | * sslv2 stuff. */ | ||
| 407 | |||
| 408 | if (s->s2 == NULL) | ||
| 409 | { | ||
| 410 | if (!ssl2_new(s)) | ||
| 411 | goto err; | ||
| 412 | } | ||
| 413 | else | ||
| 414 | ssl2_clear(s); | ||
| 415 | |||
| 416 | if (s->s3 != NULL) ssl3_free(s); | ||
| 417 | |||
| 418 | if (!BUF_MEM_grow(s->init_buf, | ||
| 419 | SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER)) | ||
| 420 | { | ||
| 421 | goto err; | ||
| 422 | } | ||
| 423 | |||
| 424 | s->state=SSL2_ST_GET_CLIENT_HELLO_A; | ||
| 425 | if ((s->options & SSL_OP_MSIE_SSLV2_RSA_PADDING) || | ||
| 426 | use_sslv2_strong) | ||
| 427 | s->s2->ssl2_rollback=0; | ||
| 428 | else | ||
| 429 | s->s2->ssl2_rollback=1; | ||
| 430 | |||
| 431 | /* setup the 5 bytes we have read so we get them from | ||
| 432 | * the sslv2 buffer */ | ||
| 433 | s->rstate=SSL_ST_READ_HEADER; | ||
| 434 | s->packet_length=n; | ||
| 435 | s->packet= &(s->s2->rbuf[0]); | ||
| 436 | memcpy(s->packet,buf,n); | ||
| 437 | s->s2->rbuf_left=n; | ||
| 438 | s->s2->rbuf_offs=0; | ||
| 439 | |||
| 440 | s->method=SSLv2_server_method(); | ||
| 441 | s->handshake_func=s->method->ssl_accept; | ||
| 442 | } | ||
| 443 | |||
| 444 | if ((type == 2) || (type == 3)) | ||
| 445 | { | ||
| 446 | /* we have SSLv3/TLSv1 */ | ||
| 447 | |||
| 448 | if (!ssl_init_wbio_buffer(s,1)) goto err; | ||
| 449 | |||
| 450 | /* we are in this state */ | ||
| 451 | s->state=SSL3_ST_SR_CLNT_HELLO_A; | ||
| 452 | |||
| 453 | if (type == 3) | ||
| 454 | { | ||
| 455 | /* put the 'n' bytes we have read into the input buffer | ||
| 456 | * for SSLv3 */ | ||
| 457 | s->rstate=SSL_ST_READ_HEADER; | ||
| 458 | s->packet_length=n; | ||
| 459 | s->packet= &(s->s3->rbuf.buf[0]); | ||
| 460 | memcpy(s->packet,buf,n); | ||
| 461 | s->s3->rbuf.left=n; | ||
| 462 | s->s3->rbuf.offset=0; | ||
| 463 | } | ||
| 464 | else | ||
| 465 | { | ||
| 466 | s->packet_length=0; | ||
| 467 | s->s3->rbuf.left=0; | ||
| 468 | s->s3->rbuf.offset=0; | ||
| 469 | } | ||
| 470 | |||
| 471 | if (tls1) | ||
| 472 | { | ||
| 473 | s->version=TLS1_VERSION; | ||
| 474 | s->method=TLSv1_server_method(); | ||
| 475 | } | ||
| 476 | else | ||
| 477 | { | ||
| 478 | s->version=SSL3_VERSION; | ||
| 479 | s->method=SSLv3_server_method(); | ||
| 480 | } | ||
| 481 | s->handshake_func=s->method->ssl_accept; | ||
| 482 | } | ||
| 483 | |||
| 484 | if ((type < 1) || (type > 3)) | ||
| 485 | { | ||
| 486 | /* bad, very bad */ | ||
| 487 | SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_UNKNOWN_PROTOCOL); | ||
| 488 | goto err; | ||
| 489 | } | ||
| 490 | s->init_num=0; | ||
| 491 | |||
| 492 | if (buf != buf_space) Free(buf); | ||
| 493 | s->first_packet=1; | ||
| 494 | return(SSL_accept(s)); | ||
| 495 | err: | ||
| 496 | if (buf != buf_space) Free(buf); | ||
| 497 | return(-1); | ||
| 498 | } | ||
| 499 | |||
diff --git a/src/lib/libssl/s3_both.c b/src/lib/libssl/s3_both.c new file mode 100644 index 0000000000..6de62e1591 --- /dev/null +++ b/src/lib/libssl/s3_both.c | |||
| @@ -0,0 +1,469 @@ | |||
| 1 | /* ssl/s3_both.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 "buffer.h" | ||
| 61 | #include "rand.h" | ||
| 62 | #include "objects.h" | ||
| 63 | #include "evp.h" | ||
| 64 | #include "x509.h" | ||
| 65 | #include "ssl_locl.h" | ||
| 66 | |||
| 67 | #define BREAK break | ||
| 68 | |||
| 69 | /* SSL3err(SSL_F_SSL3_GET_FINISHED,SSL_R_EXCESSIVE_MESSAGE_SIZE); | ||
| 70 | */ | ||
| 71 | |||
| 72 | int ssl3_send_finished(s,a,b,sender,slen) | ||
| 73 | SSL *s; | ||
| 74 | int a; | ||
| 75 | int b; | ||
| 76 | unsigned char *sender; | ||
| 77 | int slen; | ||
| 78 | { | ||
| 79 | unsigned char *p,*d; | ||
| 80 | int i; | ||
| 81 | unsigned long l; | ||
| 82 | |||
| 83 | if (s->state == a) | ||
| 84 | { | ||
| 85 | d=(unsigned char *)s->init_buf->data; | ||
| 86 | p= &(d[4]); | ||
| 87 | |||
| 88 | i=s->method->ssl3_enc->final_finish_mac(s, | ||
| 89 | &(s->s3->finish_dgst1), | ||
| 90 | &(s->s3->finish_dgst2), | ||
| 91 | sender,slen,p); | ||
| 92 | p+=i; | ||
| 93 | l=i; | ||
| 94 | |||
| 95 | *(d++)=SSL3_MT_FINISHED; | ||
| 96 | l2n3(l,d); | ||
| 97 | s->init_num=(int)l+4; | ||
| 98 | s->init_off=0; | ||
| 99 | |||
| 100 | s->state=b; | ||
| 101 | } | ||
| 102 | |||
| 103 | /* SSL3_ST_SEND_xxxxxx_HELLO_B */ | ||
| 104 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
| 105 | } | ||
| 106 | |||
| 107 | int ssl3_get_finished(s,a,b) | ||
| 108 | SSL *s; | ||
| 109 | int a; | ||
| 110 | int b; | ||
| 111 | { | ||
| 112 | int al,i,ok; | ||
| 113 | long n; | ||
| 114 | unsigned char *p; | ||
| 115 | |||
| 116 | /* the mac has already been generated when we received the | ||
| 117 | * change cipher spec message and is in s->s3->tmp.in_dgst[12] | ||
| 118 | */ | ||
| 119 | |||
| 120 | n=ssl3_get_message(s, | ||
| 121 | a, | ||
| 122 | b, | ||
| 123 | SSL3_MT_FINISHED, | ||
| 124 | 64, /* should actually be 36+4 :-) */ | ||
| 125 | &ok); | ||
| 126 | |||
| 127 | if (!ok) return((int)n); | ||
| 128 | |||
| 129 | /* If this occurs if we has missed a message */ | ||
| 130 | if (!s->s3->change_cipher_spec) | ||
| 131 | { | ||
| 132 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
| 133 | SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_GOT_A_FIN_BEFORE_A_CCS); | ||
| 134 | goto f_err; | ||
| 135 | } | ||
| 136 | s->s3->change_cipher_spec=0; | ||
| 137 | |||
| 138 | p=(unsigned char *)s->init_buf->data; | ||
| 139 | |||
| 140 | i=s->method->ssl3_enc->finish_mac_length; | ||
| 141 | |||
| 142 | if (i != n) | ||
| 143 | { | ||
| 144 | al=SSL_AD_DECODE_ERROR; | ||
| 145 | SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_BAD_DIGEST_LENGTH); | ||
| 146 | goto f_err; | ||
| 147 | } | ||
| 148 | |||
| 149 | if (memcmp( p, (char *)&(s->s3->tmp.finish_md[0]),i) != 0) | ||
| 150 | { | ||
| 151 | al=SSL_AD_DECRYPT_ERROR; | ||
| 152 | SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_DIGEST_CHECK_FAILED); | ||
| 153 | goto f_err; | ||
| 154 | } | ||
| 155 | |||
| 156 | return(1); | ||
| 157 | f_err: | ||
| 158 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
| 159 | return(0); | ||
| 160 | } | ||
| 161 | |||
| 162 | /* for these 2 messages, we need to | ||
| 163 | * ssl->enc_read_ctx re-init | ||
| 164 | * ssl->s3->read_sequence zero | ||
| 165 | * ssl->s3->read_mac_secret re-init | ||
| 166 | * ssl->session->read_sym_enc assign | ||
| 167 | * ssl->session->read_compression assign | ||
| 168 | * ssl->session->read_hash assign | ||
| 169 | */ | ||
| 170 | int ssl3_send_change_cipher_spec(s,a,b) | ||
| 171 | SSL *s; | ||
| 172 | int a,b; | ||
| 173 | { | ||
| 174 | unsigned char *p; | ||
| 175 | |||
| 176 | if (s->state == a) | ||
| 177 | { | ||
| 178 | p=(unsigned char *)s->init_buf->data; | ||
| 179 | *p=SSL3_MT_CCS; | ||
| 180 | s->init_num=1; | ||
| 181 | s->init_off=0; | ||
| 182 | |||
| 183 | s->state=b; | ||
| 184 | } | ||
| 185 | |||
| 186 | /* SSL3_ST_CW_CHANGE_B */ | ||
| 187 | return(ssl3_do_write(s,SSL3_RT_CHANGE_CIPHER_SPEC)); | ||
| 188 | } | ||
| 189 | |||
| 190 | unsigned long ssl3_output_cert_chain(s,x) | ||
| 191 | SSL *s; | ||
| 192 | X509 *x; | ||
| 193 | { | ||
| 194 | unsigned char *p; | ||
| 195 | int n,i; | ||
| 196 | unsigned long l=7; | ||
| 197 | BUF_MEM *buf; | ||
| 198 | X509_STORE_CTX xs_ctx; | ||
| 199 | X509_OBJECT obj; | ||
| 200 | |||
| 201 | /* TLSv1 sends a chain with nothing in it, instead of an alert */ | ||
| 202 | buf=s->init_buf; | ||
| 203 | if (!BUF_MEM_grow(buf,(int)(10))) | ||
| 204 | { | ||
| 205 | SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB); | ||
| 206 | return(0); | ||
| 207 | } | ||
| 208 | if (x != NULL) | ||
| 209 | { | ||
| 210 | X509_STORE_CTX_init(&xs_ctx,s->ctx->cert_store,NULL,NULL); | ||
| 211 | |||
| 212 | for (;;) | ||
| 213 | { | ||
| 214 | n=i2d_X509(x,NULL); | ||
| 215 | if (!BUF_MEM_grow(buf,(int)(n+l+3))) | ||
| 216 | { | ||
| 217 | SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB); | ||
| 218 | return(0); | ||
| 219 | } | ||
| 220 | p=(unsigned char *)&(buf->data[l]); | ||
| 221 | l2n3(n,p); | ||
| 222 | i2d_X509(x,&p); | ||
| 223 | l+=n+3; | ||
| 224 | if (X509_NAME_cmp(X509_get_subject_name(x), | ||
| 225 | X509_get_issuer_name(x)) == 0) break; | ||
| 226 | |||
| 227 | i=X509_STORE_get_by_subject(&xs_ctx,X509_LU_X509, | ||
| 228 | X509_get_issuer_name(x),&obj); | ||
| 229 | if (i <= 0) break; | ||
| 230 | x=obj.data.x509; | ||
| 231 | /* Count is one too high since the X509_STORE_get uped the | ||
| 232 | * ref count */ | ||
| 233 | X509_free(x); | ||
| 234 | } | ||
| 235 | |||
| 236 | X509_STORE_CTX_cleanup(&xs_ctx); | ||
| 237 | } | ||
| 238 | |||
| 239 | l-=7; | ||
| 240 | p=(unsigned char *)&(buf->data[4]); | ||
| 241 | l2n3(l,p); | ||
| 242 | l+=3; | ||
| 243 | p=(unsigned char *)&(buf->data[0]); | ||
| 244 | *(p++)=SSL3_MT_CERTIFICATE; | ||
| 245 | l2n3(l,p); | ||
| 246 | l+=4; | ||
| 247 | return(l); | ||
| 248 | } | ||
| 249 | |||
| 250 | long ssl3_get_message(s,st1,stn,mt,max,ok) | ||
| 251 | SSL *s; | ||
| 252 | int st1,stn,mt; | ||
| 253 | long max; | ||
| 254 | int *ok; | ||
| 255 | { | ||
| 256 | unsigned char *p; | ||
| 257 | unsigned long l; | ||
| 258 | long n; | ||
| 259 | int i,al; | ||
| 260 | |||
| 261 | if (s->s3->tmp.reuse_message) | ||
| 262 | { | ||
| 263 | s->s3->tmp.reuse_message=0; | ||
| 264 | if ((mt >= 0) && (s->s3->tmp.message_type != mt)) | ||
| 265 | { | ||
| 266 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
| 267 | SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE); | ||
| 268 | goto f_err; | ||
| 269 | } | ||
| 270 | *ok=1; | ||
| 271 | return((int)s->s3->tmp.message_size); | ||
| 272 | } | ||
| 273 | |||
| 274 | p=(unsigned char *)s->init_buf->data; | ||
| 275 | |||
| 276 | if (s->state == st1) | ||
| 277 | { | ||
| 278 | i=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE, | ||
| 279 | (char *)&(p[s->init_num]), | ||
| 280 | 4-s->init_num); | ||
| 281 | if (i < (4-s->init_num)) | ||
| 282 | { | ||
| 283 | *ok=0; | ||
| 284 | return(ssl3_part_read(s,i)); | ||
| 285 | } | ||
| 286 | |||
| 287 | if ((mt >= 0) && (*p != mt)) | ||
| 288 | { | ||
| 289 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
| 290 | SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE); | ||
| 291 | goto f_err; | ||
| 292 | } | ||
| 293 | s->s3->tmp.message_type= *(p++); | ||
| 294 | |||
| 295 | n2l3(p,l); | ||
| 296 | if (l > (unsigned long)max) | ||
| 297 | { | ||
| 298 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
| 299 | SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_EXCESSIVE_MESSAGE_SIZE); | ||
| 300 | goto f_err; | ||
| 301 | } | ||
| 302 | if (l && !BUF_MEM_grow(s->init_buf,(int)l)) | ||
| 303 | { | ||
| 304 | SSLerr(SSL_F_SSL3_GET_MESSAGE,ERR_R_BUF_LIB); | ||
| 305 | goto err; | ||
| 306 | } | ||
| 307 | s->s3->tmp.message_size=l; | ||
| 308 | s->state=stn; | ||
| 309 | |||
| 310 | s->init_num=0; | ||
| 311 | } | ||
| 312 | |||
| 313 | /* next state (stn) */ | ||
| 314 | p=(unsigned char *)s->init_buf->data; | ||
| 315 | n=s->s3->tmp.message_size; | ||
| 316 | if (n > 0) | ||
| 317 | { | ||
| 318 | i=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE, | ||
| 319 | (char *)&(p[s->init_num]),(int)n); | ||
| 320 | if (i != (int)n) | ||
| 321 | { | ||
| 322 | *ok=0; | ||
| 323 | return(ssl3_part_read(s,i)); | ||
| 324 | } | ||
| 325 | } | ||
| 326 | *ok=1; | ||
| 327 | return(n); | ||
| 328 | f_err: | ||
| 329 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
| 330 | err: | ||
| 331 | *ok=0; | ||
| 332 | return(-1); | ||
| 333 | } | ||
| 334 | |||
| 335 | int ssl_cert_type(x,pkey) | ||
| 336 | X509 *x; | ||
| 337 | EVP_PKEY *pkey; | ||
| 338 | { | ||
| 339 | EVP_PKEY *pk; | ||
| 340 | int ret= -1,i,j; | ||
| 341 | |||
| 342 | if (pkey == NULL) | ||
| 343 | pk=X509_get_pubkey(x); | ||
| 344 | else | ||
| 345 | pk=pkey; | ||
| 346 | if (pk == NULL) goto err; | ||
| 347 | |||
| 348 | i=pk->type; | ||
| 349 | if (i == EVP_PKEY_RSA) | ||
| 350 | { | ||
| 351 | ret=SSL_PKEY_RSA_ENC; | ||
| 352 | if (x != NULL) | ||
| 353 | { | ||
| 354 | j=X509_get_ext_count(x); | ||
| 355 | /* check to see if this is a signing only certificate */ | ||
| 356 | /* EAY EAY EAY EAY */ | ||
| 357 | } | ||
| 358 | } | ||
| 359 | else if (i == EVP_PKEY_DSA) | ||
| 360 | { | ||
| 361 | ret=SSL_PKEY_DSA_SIGN; | ||
| 362 | } | ||
| 363 | else if (i == EVP_PKEY_DH) | ||
| 364 | { | ||
| 365 | /* if we just have a key, we needs to be guess */ | ||
| 366 | |||
| 367 | if (x == NULL) | ||
| 368 | ret=SSL_PKEY_DH_DSA; | ||
| 369 | else | ||
| 370 | { | ||
| 371 | j=X509_get_signature_type(x); | ||
| 372 | if (j == EVP_PKEY_RSA) | ||
| 373 | ret=SSL_PKEY_DH_RSA; | ||
| 374 | else if (j== EVP_PKEY_DSA) | ||
| 375 | ret=SSL_PKEY_DH_DSA; | ||
| 376 | else ret= -1; | ||
| 377 | } | ||
| 378 | } | ||
| 379 | else | ||
| 380 | ret= -1; | ||
| 381 | |||
| 382 | err: | ||
| 383 | return(ret); | ||
| 384 | } | ||
| 385 | |||
| 386 | int ssl_verify_alarm_type(type) | ||
| 387 | long type; | ||
| 388 | { | ||
| 389 | int al; | ||
| 390 | |||
| 391 | switch(type) | ||
| 392 | { | ||
| 393 | case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT: | ||
| 394 | case X509_V_ERR_UNABLE_TO_GET_CRL: | ||
| 395 | al=SSL_AD_UNKNOWN_CA; | ||
| 396 | break; | ||
| 397 | case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE: | ||
| 398 | case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE: | ||
| 399 | case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY: | ||
| 400 | case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD: | ||
| 401 | case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD: | ||
| 402 | case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD: | ||
| 403 | case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD: | ||
| 404 | case X509_V_ERR_CERT_NOT_YET_VALID: | ||
| 405 | case X509_V_ERR_CRL_NOT_YET_VALID: | ||
| 406 | al=SSL_AD_BAD_CERTIFICATE; | ||
| 407 | break; | ||
| 408 | case X509_V_ERR_CERT_SIGNATURE_FAILURE: | ||
| 409 | case X509_V_ERR_CRL_SIGNATURE_FAILURE: | ||
| 410 | al=SSL_AD_DECRYPT_ERROR; | ||
| 411 | break; | ||
| 412 | case X509_V_ERR_CERT_HAS_EXPIRED: | ||
| 413 | case X509_V_ERR_CRL_HAS_EXPIRED: | ||
| 414 | al=SSL_AD_CERTIFICATE_EXPIRED; | ||
| 415 | break; | ||
| 416 | case X509_V_ERR_CERT_REVOKED: | ||
| 417 | al=SSL_AD_CERTIFICATE_REVOKED; | ||
| 418 | break; | ||
| 419 | case X509_V_ERR_OUT_OF_MEM: | ||
| 420 | al=SSL_AD_INTERNAL_ERROR; | ||
| 421 | break; | ||
| 422 | case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT: | ||
| 423 | case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN: | ||
| 424 | case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY: | ||
| 425 | case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE: | ||
| 426 | case X509_V_ERR_CERT_CHAIN_TOO_LONG: | ||
| 427 | al=SSL_AD_UNKNOWN_CA; | ||
| 428 | break; | ||
| 429 | case X509_V_ERR_APPLICATION_VERIFICATION: | ||
| 430 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
| 431 | break; | ||
| 432 | default: | ||
| 433 | al=SSL_AD_CERTIFICATE_UNKNOWN; | ||
| 434 | break; | ||
| 435 | } | ||
| 436 | return(al); | ||
| 437 | } | ||
| 438 | |||
| 439 | int ssl3_setup_buffers(s) | ||
| 440 | SSL *s; | ||
| 441 | { | ||
| 442 | unsigned char *p; | ||
| 443 | unsigned int extra; | ||
| 444 | |||
| 445 | if (s->s3->rbuf.buf == NULL) | ||
| 446 | { | ||
| 447 | if (s->options & SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER) | ||
| 448 | extra=SSL3_RT_MAX_EXTRA; | ||
| 449 | else | ||
| 450 | extra=0; | ||
| 451 | if ((p=(unsigned char *)Malloc(SSL3_RT_MAX_PACKET_SIZE+extra)) | ||
| 452 | == NULL) | ||
| 453 | goto err; | ||
| 454 | s->s3->rbuf.buf=p; | ||
| 455 | } | ||
| 456 | |||
| 457 | if (s->s3->wbuf.buf == NULL) | ||
| 458 | { | ||
| 459 | if ((p=(unsigned char *)Malloc(SSL3_RT_MAX_PACKET_SIZE)) | ||
| 460 | == NULL) | ||
| 461 | goto err; | ||
| 462 | s->s3->wbuf.buf=p; | ||
| 463 | } | ||
| 464 | s->packet= &(s->s3->rbuf.buf[0]); | ||
| 465 | return(1); | ||
| 466 | err: | ||
| 467 | SSLerr(SSL_F_SSL3_SETUP_BUFFERS,ERR_R_MALLOC_FAILURE); | ||
| 468 | return(0); | ||
| 469 | } | ||
diff --git a/src/lib/libssl/s3_clnt.c b/src/lib/libssl/s3_clnt.c new file mode 100644 index 0000000000..940c6a458f --- /dev/null +++ b/src/lib/libssl/s3_clnt.c | |||
| @@ -0,0 +1,1678 @@ | |||
| 1 | /* ssl/s3_clnt.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 "buffer.h" | ||
| 61 | #include "rand.h" | ||
| 62 | #include "objects.h" | ||
| 63 | #include "evp.h" | ||
| 64 | #include "ssl_locl.h" | ||
| 65 | |||
| 66 | #define BREAK break | ||
| 67 | /* SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,ERR_R_MALLOC_FAILURE); | ||
| 68 | * SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_MALLOC_FAILURE); | ||
| 69 | * SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,ERR_R_MALLOC_FAILURE); | ||
| 70 | * SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE); | ||
| 71 | * SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE); | ||
| 72 | * SSLerr(SSL_F_SSL3_GET_SERVER_DONE,ERR_R_MALLOC_FAILURE); | ||
| 73 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_SSL3_SESSION_ID_TOO_SHORT); | ||
| 74 | */ | ||
| 75 | |||
| 76 | #ifndef NOPROTO | ||
| 77 | static int ssl3_client_hello(SSL *s); | ||
| 78 | static int ssl3_get_server_hello(SSL *s); | ||
| 79 | static int ssl3_get_certificate_request(SSL *s); | ||
| 80 | static int ca_dn_cmp(X509_NAME **a,X509_NAME **b); | ||
| 81 | static int ssl3_get_server_done(SSL *s); | ||
| 82 | static int ssl3_send_client_verify(SSL *s); | ||
| 83 | static int ssl3_send_client_certificate(SSL *s); | ||
| 84 | static int ssl3_send_client_key_exchange(SSL *s); | ||
| 85 | static int ssl3_get_key_exchange(SSL *s); | ||
| 86 | static int ssl3_get_server_certificate(SSL *s); | ||
| 87 | static int ssl3_check_cert_and_algorithm(SSL *s); | ||
| 88 | #else | ||
| 89 | static int ssl3_client_hello(); | ||
| 90 | static int ssl3_get_server_hello(); | ||
| 91 | static int ssl3_get_certificate_request(); | ||
| 92 | static int ca_dn_cmp(); | ||
| 93 | static int ssl3_get_server_done(); | ||
| 94 | static int ssl3_send_client_verify(); | ||
| 95 | static int ssl3_send_client_certificate(); | ||
| 96 | static int ssl3_send_client_key_exchange(); | ||
| 97 | static int ssl3_get_key_exchange(); | ||
| 98 | static int ssl3_get_server_certificate(); | ||
| 99 | static int ssl3_check_cert_and_algorithm(); | ||
| 100 | #endif | ||
| 101 | |||
| 102 | static SSL_METHOD *ssl3_get_client_method(ver) | ||
| 103 | int ver; | ||
| 104 | { | ||
| 105 | if (ver == SSL3_VERSION) | ||
| 106 | return(SSLv3_client_method()); | ||
| 107 | else | ||
| 108 | return(NULL); | ||
| 109 | } | ||
| 110 | |||
| 111 | SSL_METHOD *SSLv3_client_method() | ||
| 112 | { | ||
| 113 | static int init=1; | ||
| 114 | static SSL_METHOD SSLv3_client_data; | ||
| 115 | |||
| 116 | if (init) | ||
| 117 | { | ||
| 118 | init=0; | ||
| 119 | memcpy((char *)&SSLv3_client_data,(char *)sslv3_base_method(), | ||
| 120 | sizeof(SSL_METHOD)); | ||
| 121 | SSLv3_client_data.ssl_connect=ssl3_connect; | ||
| 122 | SSLv3_client_data.get_ssl_method=ssl3_get_client_method; | ||
| 123 | } | ||
| 124 | return(&SSLv3_client_data); | ||
| 125 | } | ||
| 126 | |||
| 127 | int ssl3_connect(s) | ||
| 128 | SSL *s; | ||
| 129 | { | ||
| 130 | BUF_MEM *buf; | ||
| 131 | unsigned long Time=time(NULL),l; | ||
| 132 | long num1; | ||
| 133 | void (*cb)()=NULL; | ||
| 134 | int ret= -1; | ||
| 135 | BIO *under; | ||
| 136 | int new_state,state,skip=0;; | ||
| 137 | |||
| 138 | RAND_seed((unsigned char *)&Time,sizeof(Time)); | ||
| 139 | ERR_clear_error(); | ||
| 140 | clear_sys_error(); | ||
| 141 | |||
| 142 | if (s->info_callback != NULL) | ||
| 143 | cb=s->info_callback; | ||
| 144 | else if (s->ctx->info_callback != NULL) | ||
| 145 | cb=s->ctx->info_callback; | ||
| 146 | |||
| 147 | if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s); | ||
| 148 | s->in_handshake++; | ||
| 149 | |||
| 150 | for (;;) | ||
| 151 | { | ||
| 152 | state=s->state; | ||
| 153 | |||
| 154 | switch(s->state) | ||
| 155 | { | ||
| 156 | case SSL_ST_RENEGOTIATE: | ||
| 157 | s->new_session=1; | ||
| 158 | s->state=SSL_ST_CONNECT; | ||
| 159 | s->ctx->sess_connect_renegotiate++; | ||
| 160 | /* break */ | ||
| 161 | case SSL_ST_BEFORE: | ||
| 162 | case SSL_ST_CONNECT: | ||
| 163 | case SSL_ST_BEFORE|SSL_ST_CONNECT: | ||
| 164 | case SSL_ST_OK|SSL_ST_CONNECT: | ||
| 165 | |||
| 166 | if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1); | ||
| 167 | |||
| 168 | if ((s->version & 0xff00 ) != 0x0300) | ||
| 169 | abort(); | ||
| 170 | /* s->version=SSL3_VERSION; */ | ||
| 171 | s->type=SSL_ST_CONNECT; | ||
| 172 | |||
| 173 | if (s->init_buf == NULL) | ||
| 174 | { | ||
| 175 | if ((buf=BUF_MEM_new()) == NULL) | ||
| 176 | { | ||
| 177 | ret= -1; | ||
| 178 | goto end; | ||
| 179 | } | ||
| 180 | if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH)) | ||
| 181 | { | ||
| 182 | ret= -1; | ||
| 183 | goto end; | ||
| 184 | } | ||
| 185 | s->init_buf=buf; | ||
| 186 | } | ||
| 187 | |||
| 188 | if (!ssl3_setup_buffers(s)) { ret= -1; goto end; } | ||
| 189 | |||
| 190 | /* setup buffing BIO */ | ||
| 191 | if (!ssl_init_wbio_buffer(s,0)) { ret= -1; goto end; } | ||
| 192 | |||
| 193 | /* don't push the buffering BIO quite yet */ | ||
| 194 | |||
| 195 | ssl3_init_finished_mac(s); | ||
| 196 | |||
| 197 | s->state=SSL3_ST_CW_CLNT_HELLO_A; | ||
| 198 | s->ctx->sess_connect++; | ||
| 199 | s->init_num=0; | ||
| 200 | break; | ||
| 201 | |||
| 202 | case SSL3_ST_CW_CLNT_HELLO_A: | ||
| 203 | case SSL3_ST_CW_CLNT_HELLO_B: | ||
| 204 | |||
| 205 | s->shutdown=0; | ||
| 206 | ret=ssl3_client_hello(s); | ||
| 207 | if (ret <= 0) goto end; | ||
| 208 | s->state=SSL3_ST_CR_SRVR_HELLO_A; | ||
| 209 | s->init_num=0; | ||
| 210 | |||
| 211 | /* turn on buffering for the next lot of output */ | ||
| 212 | if (s->bbio != s->wbio) | ||
| 213 | s->wbio=BIO_push(s->bbio,s->wbio); | ||
| 214 | |||
| 215 | break; | ||
| 216 | |||
| 217 | case SSL3_ST_CR_SRVR_HELLO_A: | ||
| 218 | case SSL3_ST_CR_SRVR_HELLO_B: | ||
| 219 | ret=ssl3_get_server_hello(s); | ||
| 220 | if (ret <= 0) goto end; | ||
| 221 | if (s->hit) | ||
| 222 | s->state=SSL3_ST_CR_FINISHED_A; | ||
| 223 | else | ||
| 224 | s->state=SSL3_ST_CR_CERT_A; | ||
| 225 | s->init_num=0; | ||
| 226 | break; | ||
| 227 | |||
| 228 | case SSL3_ST_CR_CERT_A: | ||
| 229 | case SSL3_ST_CR_CERT_B: | ||
| 230 | /* Check if it is anon DH */ | ||
| 231 | if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL)) | ||
| 232 | { | ||
| 233 | ret=ssl3_get_server_certificate(s); | ||
| 234 | if (ret <= 0) goto end; | ||
| 235 | } | ||
| 236 | else | ||
| 237 | skip=1; | ||
| 238 | s->state=SSL3_ST_CR_KEY_EXCH_A; | ||
| 239 | s->init_num=0; | ||
| 240 | break; | ||
| 241 | |||
| 242 | case SSL3_ST_CR_KEY_EXCH_A: | ||
| 243 | case SSL3_ST_CR_KEY_EXCH_B: | ||
| 244 | ret=ssl3_get_key_exchange(s); | ||
| 245 | if (ret <= 0) goto end; | ||
| 246 | s->state=SSL3_ST_CR_CERT_REQ_A; | ||
| 247 | s->init_num=0; | ||
| 248 | |||
| 249 | /* at this point we check that we have the | ||
| 250 | * required stuff from the server */ | ||
| 251 | if (!ssl3_check_cert_and_algorithm(s)) | ||
| 252 | { | ||
| 253 | ret= -1; | ||
| 254 | goto end; | ||
| 255 | } | ||
| 256 | break; | ||
| 257 | |||
| 258 | case SSL3_ST_CR_CERT_REQ_A: | ||
| 259 | case SSL3_ST_CR_CERT_REQ_B: | ||
| 260 | ret=ssl3_get_certificate_request(s); | ||
| 261 | if (ret <= 0) goto end; | ||
| 262 | s->state=SSL3_ST_CR_SRVR_DONE_A; | ||
| 263 | s->init_num=0; | ||
| 264 | break; | ||
| 265 | |||
| 266 | case SSL3_ST_CR_SRVR_DONE_A: | ||
| 267 | case SSL3_ST_CR_SRVR_DONE_B: | ||
| 268 | ret=ssl3_get_server_done(s); | ||
| 269 | if (ret <= 0) goto end; | ||
| 270 | if (s->s3->tmp.cert_req) | ||
| 271 | s->state=SSL3_ST_CW_CERT_A; | ||
| 272 | else | ||
| 273 | s->state=SSL3_ST_CW_KEY_EXCH_A; | ||
| 274 | s->init_num=0; | ||
| 275 | |||
| 276 | break; | ||
| 277 | |||
| 278 | case SSL3_ST_CW_CERT_A: | ||
| 279 | case SSL3_ST_CW_CERT_B: | ||
| 280 | case SSL3_ST_CW_CERT_C: | ||
| 281 | ret=ssl3_send_client_certificate(s); | ||
| 282 | if (ret <= 0) goto end; | ||
| 283 | s->state=SSL3_ST_CW_KEY_EXCH_A; | ||
| 284 | s->init_num=0; | ||
| 285 | break; | ||
| 286 | |||
| 287 | case SSL3_ST_CW_KEY_EXCH_A: | ||
| 288 | case SSL3_ST_CW_KEY_EXCH_B: | ||
| 289 | ret=ssl3_send_client_key_exchange(s); | ||
| 290 | if (ret <= 0) goto end; | ||
| 291 | l=s->s3->tmp.new_cipher->algorithms; | ||
| 292 | /* EAY EAY EAY need to check for DH fix cert | ||
| 293 | * sent back */ | ||
| 294 | /* For TLS, cert_req is set to 2, so a cert chain | ||
| 295 | * of nothing is sent, but no verify packet is sent */ | ||
| 296 | if (s->s3->tmp.cert_req == 1) | ||
| 297 | { | ||
| 298 | s->state=SSL3_ST_CW_CERT_VRFY_A; | ||
| 299 | } | ||
| 300 | else | ||
| 301 | { | ||
| 302 | s->state=SSL3_ST_CW_CHANGE_A; | ||
| 303 | s->s3->change_cipher_spec=0; | ||
| 304 | } | ||
| 305 | |||
| 306 | s->init_num=0; | ||
| 307 | break; | ||
| 308 | |||
| 309 | case SSL3_ST_CW_CERT_VRFY_A: | ||
| 310 | case SSL3_ST_CW_CERT_VRFY_B: | ||
| 311 | ret=ssl3_send_client_verify(s); | ||
| 312 | if (ret <= 0) goto end; | ||
| 313 | s->state=SSL3_ST_CW_CHANGE_A; | ||
| 314 | s->init_num=0; | ||
| 315 | s->s3->change_cipher_spec=0; | ||
| 316 | break; | ||
| 317 | |||
| 318 | case SSL3_ST_CW_CHANGE_A: | ||
| 319 | case SSL3_ST_CW_CHANGE_B: | ||
| 320 | ret=ssl3_send_change_cipher_spec(s, | ||
| 321 | SSL3_ST_CW_CHANGE_A,SSL3_ST_CW_CHANGE_B); | ||
| 322 | if (ret <= 0) goto end; | ||
| 323 | s->state=SSL3_ST_CW_FINISHED_A; | ||
| 324 | s->init_num=0; | ||
| 325 | |||
| 326 | s->session->cipher=s->s3->tmp.new_cipher; | ||
| 327 | if (!s->method->ssl3_enc->setup_key_block(s)) | ||
| 328 | { | ||
| 329 | ret= -1; | ||
| 330 | goto end; | ||
| 331 | } | ||
| 332 | |||
| 333 | if (!s->method->ssl3_enc->change_cipher_state(s, | ||
| 334 | SSL3_CHANGE_CIPHER_CLIENT_WRITE)) | ||
| 335 | { | ||
| 336 | ret= -1; | ||
| 337 | goto end; | ||
| 338 | } | ||
| 339 | |||
| 340 | break; | ||
| 341 | |||
| 342 | case SSL3_ST_CW_FINISHED_A: | ||
| 343 | case SSL3_ST_CW_FINISHED_B: | ||
| 344 | ret=ssl3_send_finished(s, | ||
| 345 | SSL3_ST_CW_FINISHED_A,SSL3_ST_CW_FINISHED_B, | ||
| 346 | s->method->ssl3_enc->client_finished, | ||
| 347 | s->method->ssl3_enc->client_finished_len); | ||
| 348 | if (ret <= 0) goto end; | ||
| 349 | s->state=SSL3_ST_CW_FLUSH; | ||
| 350 | |||
| 351 | /* clear flags */ | ||
| 352 | s->s3->flags&= ~SSL3_FLAGS_POP_BUFFER; | ||
| 353 | if (s->hit) | ||
| 354 | { | ||
| 355 | s->s3->tmp.next_state=SSL_ST_OK; | ||
| 356 | if (s->s3->flags & SSL3_FLAGS_DELAY_CLIENT_FINISHED) | ||
| 357 | { | ||
| 358 | s->state=SSL_ST_OK; | ||
| 359 | s->s3->flags|=SSL3_FLAGS_POP_BUFFER; | ||
| 360 | s->s3->delay_buf_pop_ret=0; | ||
| 361 | } | ||
| 362 | } | ||
| 363 | else | ||
| 364 | { | ||
| 365 | s->s3->tmp.next_state=SSL3_ST_CR_FINISHED_A; | ||
| 366 | } | ||
| 367 | s->init_num=0; | ||
| 368 | break; | ||
| 369 | |||
| 370 | case SSL3_ST_CR_FINISHED_A: | ||
| 371 | case SSL3_ST_CR_FINISHED_B: | ||
| 372 | |||
| 373 | ret=ssl3_get_finished(s,SSL3_ST_CR_FINISHED_A, | ||
| 374 | SSL3_ST_CR_FINISHED_B); | ||
| 375 | if (ret <= 0) goto end; | ||
| 376 | |||
| 377 | if (s->hit) | ||
| 378 | s->state=SSL3_ST_CW_CHANGE_A; | ||
| 379 | else | ||
| 380 | s->state=SSL_ST_OK; | ||
| 381 | s->init_num=0; | ||
| 382 | break; | ||
| 383 | |||
| 384 | case SSL3_ST_CW_FLUSH: | ||
| 385 | /* number of bytes to be flushed */ | ||
| 386 | num1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL); | ||
| 387 | if (num1 > 0) | ||
| 388 | { | ||
| 389 | s->rwstate=SSL_WRITING; | ||
| 390 | num1=BIO_flush(s->wbio); | ||
| 391 | if (num1 <= 0) { ret= -1; goto end; } | ||
| 392 | s->rwstate=SSL_NOTHING; | ||
| 393 | } | ||
| 394 | |||
| 395 | s->state=s->s3->tmp.next_state; | ||
| 396 | break; | ||
| 397 | |||
| 398 | case SSL_ST_OK: | ||
| 399 | /* clean a few things up */ | ||
| 400 | ssl3_cleanup_key_block(s); | ||
| 401 | |||
| 402 | BUF_MEM_free(s->init_buf); | ||
| 403 | s->init_buf=NULL; | ||
| 404 | |||
| 405 | if (!(s->s3->flags & SSL3_FLAGS_POP_BUFFER)) | ||
| 406 | { | ||
| 407 | /* remove buffering */ | ||
| 408 | under=BIO_pop(s->wbio); | ||
| 409 | if (under != NULL) | ||
| 410 | s->wbio=under; | ||
| 411 | else | ||
| 412 | abort(); /* ok */ | ||
| 413 | |||
| 414 | BIO_free(s->bbio); | ||
| 415 | s->bbio=NULL; | ||
| 416 | } | ||
| 417 | /* else do it later */ | ||
| 418 | |||
| 419 | s->init_num=0; | ||
| 420 | s->new_session=0; | ||
| 421 | |||
| 422 | ssl_update_cache(s,SSL_SESS_CACHE_CLIENT); | ||
| 423 | if (s->hit) s->ctx->sess_hit++; | ||
| 424 | |||
| 425 | ret=1; | ||
| 426 | /* s->server=0; */ | ||
| 427 | s->handshake_func=ssl3_connect; | ||
| 428 | s->ctx->sess_connect_good++; | ||
| 429 | |||
| 430 | if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1); | ||
| 431 | |||
| 432 | goto end; | ||
| 433 | break; | ||
| 434 | |||
| 435 | default: | ||
| 436 | SSLerr(SSL_F_SSL3_CONNECT,SSL_R_UNKNOWN_STATE); | ||
| 437 | ret= -1; | ||
| 438 | goto end; | ||
| 439 | /* break; */ | ||
| 440 | } | ||
| 441 | |||
| 442 | /* did we do anything */ | ||
| 443 | if (!s->s3->tmp.reuse_message && !skip) | ||
| 444 | { | ||
| 445 | if (s->debug) | ||
| 446 | { | ||
| 447 | if ((ret=BIO_flush(s->wbio)) <= 0) | ||
| 448 | goto end; | ||
| 449 | } | ||
| 450 | |||
| 451 | if ((cb != NULL) && (s->state != state)) | ||
| 452 | { | ||
| 453 | new_state=s->state; | ||
| 454 | s->state=state; | ||
| 455 | cb(s,SSL_CB_CONNECT_LOOP,1); | ||
| 456 | s->state=new_state; | ||
| 457 | } | ||
| 458 | } | ||
| 459 | skip=0; | ||
| 460 | } | ||
| 461 | end: | ||
| 462 | if (cb != NULL) | ||
| 463 | cb(s,SSL_CB_CONNECT_EXIT,ret); | ||
| 464 | s->in_handshake--; | ||
| 465 | return(ret); | ||
| 466 | } | ||
| 467 | |||
| 468 | |||
| 469 | static int ssl3_client_hello(s) | ||
| 470 | SSL *s; | ||
| 471 | { | ||
| 472 | unsigned char *buf; | ||
| 473 | unsigned char *p,*d; | ||
| 474 | int i; | ||
| 475 | unsigned long Time,l; | ||
| 476 | |||
| 477 | buf=(unsigned char *)s->init_buf->data; | ||
| 478 | if (s->state == SSL3_ST_CW_CLNT_HELLO_A) | ||
| 479 | { | ||
| 480 | if ((s->session == NULL) || | ||
| 481 | (s->session->ssl_version != s->version)) | ||
| 482 | { | ||
| 483 | if (!ssl_get_new_session(s,0)) | ||
| 484 | goto err; | ||
| 485 | } | ||
| 486 | /* else use the pre-loaded session */ | ||
| 487 | |||
| 488 | p=s->s3->client_random; | ||
| 489 | Time=time(NULL); /* Time */ | ||
| 490 | l2n(Time,p); | ||
| 491 | RAND_bytes(&(p[4]),SSL3_RANDOM_SIZE-sizeof(Time)); | ||
| 492 | |||
| 493 | /* Do the message type and length last */ | ||
| 494 | d=p= &(buf[4]); | ||
| 495 | |||
| 496 | *(p++)=s->version>>8; | ||
| 497 | *(p++)=s->version&0xff; | ||
| 498 | |||
| 499 | /* Random stuff */ | ||
| 500 | memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE); | ||
| 501 | p+=SSL3_RANDOM_SIZE; | ||
| 502 | |||
| 503 | /* Session ID */ | ||
| 504 | if (s->new_session) | ||
| 505 | i=0; | ||
| 506 | else | ||
| 507 | i=s->session->session_id_length; | ||
| 508 | *(p++)=i; | ||
| 509 | if (i != 0) | ||
| 510 | { | ||
| 511 | memcpy(p,s->session->session_id,i); | ||
| 512 | p+=i; | ||
| 513 | } | ||
| 514 | |||
| 515 | /* Ciphers supported */ | ||
| 516 | i=ssl_cipher_list_to_bytes(s,SSL_get_ciphers(s),&(p[2])); | ||
| 517 | if (i == 0) | ||
| 518 | { | ||
| 519 | SSLerr(SSL_F_SSL3_CLIENT_HELLO,SSL_R_NO_CIPHERS_AVAILABLE); | ||
| 520 | goto err; | ||
| 521 | } | ||
| 522 | s2n(i,p); | ||
| 523 | p+=i; | ||
| 524 | |||
| 525 | /* hardwire in the NULL compression algorithm. */ | ||
| 526 | *(p++)=1; | ||
| 527 | *(p++)=0; | ||
| 528 | |||
| 529 | l=(p-d); | ||
| 530 | d=buf; | ||
| 531 | *(d++)=SSL3_MT_CLIENT_HELLO; | ||
| 532 | l2n3(l,d); | ||
| 533 | |||
| 534 | s->state=SSL3_ST_CW_CLNT_HELLO_B; | ||
| 535 | /* number of bytes to write */ | ||
| 536 | s->init_num=p-buf; | ||
| 537 | s->init_off=0; | ||
| 538 | } | ||
| 539 | |||
| 540 | /* SSL3_ST_CW_CLNT_HELLO_B */ | ||
| 541 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
| 542 | err: | ||
| 543 | return(-1); | ||
| 544 | } | ||
| 545 | |||
| 546 | static int ssl3_get_server_hello(s) | ||
| 547 | SSL *s; | ||
| 548 | { | ||
| 549 | STACK *sk; | ||
| 550 | SSL_CIPHER *c; | ||
| 551 | unsigned char *p,*d; | ||
| 552 | int i,al,ok; | ||
| 553 | unsigned int j; | ||
| 554 | long n; | ||
| 555 | |||
| 556 | n=ssl3_get_message(s, | ||
| 557 | SSL3_ST_CR_SRVR_HELLO_A, | ||
| 558 | SSL3_ST_CR_SRVR_HELLO_B, | ||
| 559 | SSL3_MT_SERVER_HELLO, | ||
| 560 | 300, /* ?? */ | ||
| 561 | &ok); | ||
| 562 | |||
| 563 | if (!ok) return((int)n); | ||
| 564 | d=p=(unsigned char *)s->init_buf->data; | ||
| 565 | |||
| 566 | if ((p[0] != (s->version>>8)) || (p[1] != (s->version&0xff))) | ||
| 567 | { | ||
| 568 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_WRONG_SSL_VERSION); | ||
| 569 | s->version=(s->version&0xff00)|p[1]; | ||
| 570 | al=SSL_AD_PROTOCOL_VERSION; | ||
| 571 | goto f_err; | ||
| 572 | } | ||
| 573 | p+=2; | ||
| 574 | |||
| 575 | /* load the server hello data */ | ||
| 576 | /* load the server random */ | ||
| 577 | memcpy(s->s3->server_random,p,SSL3_RANDOM_SIZE); | ||
| 578 | p+=SSL3_RANDOM_SIZE; | ||
| 579 | |||
| 580 | /* get the session-id */ | ||
| 581 | j= *(p++); | ||
| 582 | |||
| 583 | if ((j != 0) && (j != SSL3_SESSION_ID_SIZE)) | ||
| 584 | { | ||
| 585 | /* SSLref returns 16 :-( */ | ||
| 586 | if (j < SSL2_SSL_SESSION_ID_LENGTH) | ||
| 587 | { | ||
| 588 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
| 589 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_SSL3_SESSION_ID_TOO_SHORT); | ||
| 590 | goto f_err; | ||
| 591 | } | ||
| 592 | } | ||
| 593 | if ((j != 0) && (j == s->session->session_id_length) && | ||
| 594 | (memcmp(p,s->session->session_id,j) == 0)) | ||
| 595 | s->hit=1; | ||
| 596 | else /* a miss or crap from the other end */ | ||
| 597 | { | ||
| 598 | /* If we were trying for session-id reuse, make a new | ||
| 599 | * SSL_SESSION so we don't stuff up other people */ | ||
| 600 | s->hit=0; | ||
| 601 | if (s->session->session_id_length > 0) | ||
| 602 | { | ||
| 603 | if (!ssl_get_new_session(s,0)) | ||
| 604 | { | ||
| 605 | al=SSL_AD_INTERNAL_ERROR; | ||
| 606 | goto f_err; | ||
| 607 | } | ||
| 608 | } | ||
| 609 | s->session->session_id_length=j; | ||
| 610 | memcpy(s->session->session_id,p,j); /* j could be 0 */ | ||
| 611 | } | ||
| 612 | p+=j; | ||
| 613 | c=ssl_get_cipher_by_char(s,p); | ||
| 614 | if (c == NULL) | ||
| 615 | { | ||
| 616 | /* unknown cipher */ | ||
| 617 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
| 618 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_UNKNOWN_CIPHER_RETURNED); | ||
| 619 | goto f_err; | ||
| 620 | } | ||
| 621 | p+=ssl_put_cipher_by_char(s,NULL,NULL); | ||
| 622 | |||
| 623 | sk=ssl_get_ciphers_by_id(s); | ||
| 624 | i=sk_find(sk,(char *)c); | ||
| 625 | if (i < 0) | ||
| 626 | { | ||
| 627 | /* we did not say we would use this cipher */ | ||
| 628 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
| 629 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_WRONG_CIPHER_RETURNED); | ||
| 630 | goto f_err; | ||
| 631 | } | ||
| 632 | |||
| 633 | if (s->hit && (s->session->cipher != c)) | ||
| 634 | { | ||
| 635 | if (!(s->options & | ||
| 636 | SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG)) | ||
| 637 | { | ||
| 638 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
| 639 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED); | ||
| 640 | goto f_err; | ||
| 641 | } | ||
| 642 | } | ||
| 643 | s->s3->tmp.new_cipher=c; | ||
| 644 | |||
| 645 | /* lets get the compression algorithm */ | ||
| 646 | j= *(p++); | ||
| 647 | if (j != 0) | ||
| 648 | { | ||
| 649 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
| 650 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM); | ||
| 651 | goto f_err; | ||
| 652 | } | ||
| 653 | |||
| 654 | if (p != (d+n)) | ||
| 655 | { | ||
| 656 | /* wrong packet length */ | ||
| 657 | al=SSL_AD_DECODE_ERROR; | ||
| 658 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_BAD_PACKET_LENGTH); | ||
| 659 | goto err; | ||
| 660 | } | ||
| 661 | |||
| 662 | return(1); | ||
| 663 | f_err: | ||
| 664 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
| 665 | err: | ||
| 666 | return(-1); | ||
| 667 | } | ||
| 668 | |||
| 669 | static int ssl3_get_server_certificate(s) | ||
| 670 | SSL *s; | ||
| 671 | { | ||
| 672 | int al,i,ok,ret= -1; | ||
| 673 | unsigned long n,nc,llen,l; | ||
| 674 | X509 *x=NULL; | ||
| 675 | unsigned char *p,*d,*q; | ||
| 676 | STACK *sk=NULL; | ||
| 677 | CERT *c; | ||
| 678 | EVP_PKEY *pkey=NULL; | ||
| 679 | |||
| 680 | n=ssl3_get_message(s, | ||
| 681 | SSL3_ST_CR_CERT_A, | ||
| 682 | SSL3_ST_CR_CERT_B, | ||
| 683 | -1, | ||
| 684 | #if defined(MSDOS) && !defined(WIN32) | ||
| 685 | 1024*30, /* 30k max cert list :-) */ | ||
| 686 | #else | ||
| 687 | 1024*100, /* 100k max cert list :-) */ | ||
| 688 | #endif | ||
| 689 | &ok); | ||
| 690 | |||
| 691 | if (!ok) return((int)n); | ||
| 692 | |||
| 693 | if (s->s3->tmp.message_type == SSL3_MT_SERVER_KEY_EXCHANGE) | ||
| 694 | { | ||
| 695 | s->s3->tmp.reuse_message=1; | ||
| 696 | return(1); | ||
| 697 | } | ||
| 698 | |||
| 699 | if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE) | ||
| 700 | { | ||
| 701 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
| 702 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_BAD_MESSAGE_TYPE); | ||
| 703 | goto f_err; | ||
| 704 | } | ||
| 705 | d=p=(unsigned char *)s->init_buf->data; | ||
| 706 | |||
| 707 | if ((sk=sk_new_null()) == NULL) | ||
| 708 | { | ||
| 709 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_MALLOC_FAILURE); | ||
| 710 | goto err; | ||
| 711 | } | ||
| 712 | |||
| 713 | n2l3(p,llen); | ||
| 714 | if (llen+3 != n) | ||
| 715 | { | ||
| 716 | al=SSL_AD_DECODE_ERROR; | ||
| 717 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_LENGTH_MISMATCH); | ||
| 718 | goto f_err; | ||
| 719 | } | ||
| 720 | for (nc=0; nc<llen; ) | ||
| 721 | { | ||
| 722 | n2l3(p,l); | ||
| 723 | if ((l+nc+3) > llen) | ||
| 724 | { | ||
| 725 | al=SSL_AD_DECODE_ERROR; | ||
| 726 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH); | ||
| 727 | goto f_err; | ||
| 728 | } | ||
| 729 | |||
| 730 | q=p; | ||
| 731 | x=d2i_X509(NULL,&q,l); | ||
| 732 | if (x == NULL) | ||
| 733 | { | ||
| 734 | al=SSL_AD_BAD_CERTIFICATE; | ||
| 735 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_ASN1_LIB); | ||
| 736 | goto f_err; | ||
| 737 | } | ||
| 738 | if (q != (p+l)) | ||
| 739 | { | ||
| 740 | al=SSL_AD_DECODE_ERROR; | ||
| 741 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH); | ||
| 742 | goto f_err; | ||
| 743 | } | ||
| 744 | if (!sk_push(sk,(char *)x)) | ||
| 745 | { | ||
| 746 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_MALLOC_FAILURE); | ||
| 747 | goto err; | ||
| 748 | } | ||
| 749 | x=NULL; | ||
| 750 | nc+=l+3; | ||
| 751 | p=q; | ||
| 752 | } | ||
| 753 | |||
| 754 | i=ssl_verify_cert_chain(s,sk); | ||
| 755 | if ((s->verify_mode != SSL_VERIFY_NONE) && (!i)) | ||
| 756 | { | ||
| 757 | al=ssl_verify_alarm_type(s->verify_result); | ||
| 758 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERTIFICATE_VERIFY_FAILED); | ||
| 759 | goto f_err; | ||
| 760 | } | ||
| 761 | |||
| 762 | c=ssl_cert_new(); | ||
| 763 | if (c == NULL) goto err; | ||
| 764 | |||
| 765 | if (s->session->cert) ssl_cert_free(s->session->cert); | ||
| 766 | s->session->cert=c; | ||
| 767 | |||
| 768 | c->cert_chain=sk; | ||
| 769 | x=(X509 *)sk_value(sk,0); | ||
| 770 | sk=NULL; | ||
| 771 | |||
| 772 | pkey=X509_get_pubkey(x); | ||
| 773 | |||
| 774 | if (EVP_PKEY_missing_parameters(pkey)) | ||
| 775 | { | ||
| 776 | x=NULL; | ||
| 777 | al=SSL3_AL_FATAL; | ||
| 778 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS); | ||
| 779 | goto f_err; | ||
| 780 | } | ||
| 781 | |||
| 782 | i=ssl_cert_type(x,pkey); | ||
| 783 | if (i < 0) | ||
| 784 | { | ||
| 785 | x=NULL; | ||
| 786 | al=SSL3_AL_FATAL; | ||
| 787 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_UNKNOWN_CERTIFICATE_TYPE); | ||
| 788 | goto f_err; | ||
| 789 | } | ||
| 790 | |||
| 791 | c->cert_type=i; | ||
| 792 | CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509); | ||
| 793 | if (c->pkeys[i].x509 != NULL) | ||
| 794 | X509_free(c->pkeys[i].x509); | ||
| 795 | c->pkeys[i].x509=x; | ||
| 796 | c->key= &(c->pkeys[i]); | ||
| 797 | |||
| 798 | if ((s->session != NULL) && (s->session->peer != NULL)) | ||
| 799 | X509_free(s->session->peer); | ||
| 800 | CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509); | ||
| 801 | s->session->peer=x; | ||
| 802 | |||
| 803 | x=NULL; | ||
| 804 | ret=1; | ||
| 805 | |||
| 806 | if (0) | ||
| 807 | { | ||
| 808 | f_err: | ||
| 809 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
| 810 | } | ||
| 811 | err: | ||
| 812 | if (x != NULL) X509_free(x); | ||
| 813 | if (sk != NULL) sk_pop_free(sk,X509_free); | ||
| 814 | return(ret); | ||
| 815 | } | ||
| 816 | |||
| 817 | static int ssl3_get_key_exchange(s) | ||
| 818 | SSL *s; | ||
| 819 | { | ||
| 820 | #ifndef NO_RSA | ||
| 821 | unsigned char *q,md_buf[EVP_MAX_MD_SIZE*2]; | ||
| 822 | #endif | ||
| 823 | EVP_MD_CTX md_ctx; | ||
| 824 | unsigned char *param,*p; | ||
| 825 | int al,i,j,param_len,ok; | ||
| 826 | long n,alg; | ||
| 827 | EVP_PKEY *pkey=NULL; | ||
| 828 | RSA *rsa=NULL; | ||
| 829 | #ifndef NO_DH | ||
| 830 | DH *dh=NULL; | ||
| 831 | #endif | ||
| 832 | |||
| 833 | n=ssl3_get_message(s, | ||
| 834 | SSL3_ST_CR_KEY_EXCH_A, | ||
| 835 | SSL3_ST_CR_KEY_EXCH_B, | ||
| 836 | -1, | ||
| 837 | 1024*8, /* ?? */ | ||
| 838 | &ok); | ||
| 839 | |||
| 840 | if (!ok) return((int)n); | ||
| 841 | |||
| 842 | if (s->s3->tmp.message_type != SSL3_MT_SERVER_KEY_EXCHANGE) | ||
| 843 | { | ||
| 844 | s->s3->tmp.reuse_message=1; | ||
| 845 | return(1); | ||
| 846 | } | ||
| 847 | |||
| 848 | param=p=(unsigned char *)s->init_buf->data; | ||
| 849 | |||
| 850 | if (s->session->cert != NULL) | ||
| 851 | { | ||
| 852 | #ifndef NO_RSA | ||
| 853 | if (s->session->cert->rsa_tmp != NULL) | ||
| 854 | { | ||
| 855 | RSA_free(s->session->cert->rsa_tmp); | ||
| 856 | s->session->cert->rsa_tmp=NULL; | ||
| 857 | } | ||
| 858 | #endif | ||
| 859 | #ifndef NO_DH | ||
| 860 | if (s->session->cert->dh_tmp) | ||
| 861 | { | ||
| 862 | DH_free(s->session->cert->dh_tmp); | ||
| 863 | s->session->cert->dh_tmp=NULL; | ||
| 864 | } | ||
| 865 | #endif | ||
| 866 | } | ||
| 867 | else | ||
| 868 | { | ||
| 869 | s->session->cert=ssl_cert_new(); | ||
| 870 | } | ||
| 871 | |||
| 872 | param_len=0; | ||
| 873 | alg=s->s3->tmp.new_cipher->algorithms; | ||
| 874 | |||
| 875 | #ifndef NO_RSA | ||
| 876 | if (alg & SSL_kRSA) | ||
| 877 | { | ||
| 878 | if ((rsa=RSA_new()) == NULL) | ||
| 879 | { | ||
| 880 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE); | ||
| 881 | goto err; | ||
| 882 | } | ||
| 883 | n2s(p,i); | ||
| 884 | param_len=i+2; | ||
| 885 | if (param_len > n) | ||
| 886 | { | ||
| 887 | al=SSL_AD_DECODE_ERROR; | ||
| 888 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_MODULUS_LENGTH); | ||
| 889 | goto f_err; | ||
| 890 | } | ||
| 891 | if (!(rsa->n=BN_bin2bn(p,i,rsa->n))) | ||
| 892 | { | ||
| 893 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB); | ||
| 894 | goto err; | ||
| 895 | } | ||
| 896 | p+=i; | ||
| 897 | |||
| 898 | n2s(p,i); | ||
| 899 | param_len+=i+2; | ||
| 900 | if (param_len > n) | ||
| 901 | { | ||
| 902 | al=SSL_AD_DECODE_ERROR; | ||
| 903 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_E_LENGTH); | ||
| 904 | goto f_err; | ||
| 905 | } | ||
| 906 | if (!(rsa->e=BN_bin2bn(p,i,rsa->e))) | ||
| 907 | { | ||
| 908 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB); | ||
| 909 | goto err; | ||
| 910 | } | ||
| 911 | p+=i; | ||
| 912 | n-=param_len; | ||
| 913 | |||
| 914 | /* s->session->cert->rsa_tmp=rsa;*/ | ||
| 915 | /* this should be because we are using an export cipher */ | ||
| 916 | if (alg & SSL_aRSA) | ||
| 917 | pkey=X509_get_pubkey(s->session->cert->pkeys[SSL_PKEY_RSA_ENC].x509); | ||
| 918 | else | ||
| 919 | { | ||
| 920 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR); | ||
| 921 | goto err; | ||
| 922 | } | ||
| 923 | s->session->cert->rsa_tmp=rsa; | ||
| 924 | } | ||
| 925 | else | ||
| 926 | #endif | ||
| 927 | #ifndef NO_DH | ||
| 928 | if (alg & SSL_kEDH) | ||
| 929 | { | ||
| 930 | if ((dh=DH_new()) == NULL) | ||
| 931 | { | ||
| 932 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
| 933 | goto err; | ||
| 934 | } | ||
| 935 | n2s(p,i); | ||
| 936 | param_len=i+2; | ||
| 937 | if (param_len > n) | ||
| 938 | { | ||
| 939 | al=SSL_AD_DECODE_ERROR; | ||
| 940 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_P_LENGTH); | ||
| 941 | goto f_err; | ||
| 942 | } | ||
| 943 | if (!(dh->p=BN_bin2bn(p,i,NULL))) | ||
| 944 | { | ||
| 945 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB); | ||
| 946 | goto err; | ||
| 947 | } | ||
| 948 | p+=i; | ||
| 949 | |||
| 950 | n2s(p,i); | ||
| 951 | param_len+=i+2; | ||
| 952 | if (param_len > n) | ||
| 953 | { | ||
| 954 | al=SSL_AD_DECODE_ERROR; | ||
| 955 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_G_LENGTH); | ||
| 956 | goto f_err; | ||
| 957 | } | ||
| 958 | if (!(dh->g=BN_bin2bn(p,i,NULL))) | ||
| 959 | { | ||
| 960 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB); | ||
| 961 | goto err; | ||
| 962 | } | ||
| 963 | p+=i; | ||
| 964 | |||
| 965 | n2s(p,i); | ||
| 966 | param_len+=i+2; | ||
| 967 | if (param_len > n) | ||
| 968 | { | ||
| 969 | al=SSL_AD_DECODE_ERROR; | ||
| 970 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_PUB_KEY_LENGTH); | ||
| 971 | goto f_err; | ||
| 972 | } | ||
| 973 | if (!(dh->pub_key=BN_bin2bn(p,i,NULL))) | ||
| 974 | { | ||
| 975 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB); | ||
| 976 | goto err; | ||
| 977 | } | ||
| 978 | p+=i; | ||
| 979 | n-=param_len; | ||
| 980 | |||
| 981 | #ifndef NO_RSA | ||
| 982 | if (alg & SSL_aRSA) | ||
| 983 | pkey=X509_get_pubkey(s->session->cert->pkeys[SSL_PKEY_RSA_ENC].x509); | ||
| 984 | else | ||
| 985 | #endif | ||
| 986 | #ifndef NO_DSA | ||
| 987 | if (alg & SSL_aDSS) | ||
| 988 | pkey=X509_get_pubkey(s->session->cert->pkeys[SSL_PKEY_DSA_SIGN].x509); | ||
| 989 | #endif | ||
| 990 | /* else anonymous DH, so no certificate or pkey. */ | ||
| 991 | |||
| 992 | s->session->cert->dh_tmp=dh; | ||
| 993 | } | ||
| 994 | else if ((alg & SSL_kDHr) || (alg & SSL_kDHd)) | ||
| 995 | { | ||
| 996 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
| 997 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER); | ||
| 998 | goto f_err; | ||
| 999 | } | ||
| 1000 | #endif | ||
| 1001 | |||
| 1002 | /* p points to the next byte, there are 'n' bytes left */ | ||
| 1003 | |||
| 1004 | |||
| 1005 | /* if it was signed, check the signature */ | ||
| 1006 | if (pkey != NULL) | ||
| 1007 | { | ||
| 1008 | n2s(p,i); | ||
| 1009 | n-=2; | ||
| 1010 | j=EVP_PKEY_size(pkey); | ||
| 1011 | |||
| 1012 | if ((i != n) || (n > j) || (n <= 0)) | ||
| 1013 | { | ||
| 1014 | /* wrong packet length */ | ||
| 1015 | al=SSL_AD_DECODE_ERROR; | ||
| 1016 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_WRONG_SIGNATURE_LENGTH); | ||
| 1017 | goto err; | ||
| 1018 | } | ||
| 1019 | |||
| 1020 | #ifndef NO_RSA | ||
| 1021 | if (pkey->type == EVP_PKEY_RSA) | ||
| 1022 | { | ||
| 1023 | int num; | ||
| 1024 | |||
| 1025 | j=0; | ||
| 1026 | q=md_buf; | ||
| 1027 | for (num=2; num > 0; num--) | ||
| 1028 | { | ||
| 1029 | EVP_DigestInit(&md_ctx,(num == 2) | ||
| 1030 | ?s->ctx->md5:s->ctx->sha1); | ||
| 1031 | EVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE); | ||
| 1032 | EVP_DigestUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE); | ||
| 1033 | EVP_DigestUpdate(&md_ctx,param,param_len); | ||
| 1034 | EVP_DigestFinal(&md_ctx,q,(unsigned int *)&i); | ||
| 1035 | q+=i; | ||
| 1036 | j+=i; | ||
| 1037 | } | ||
| 1038 | i=RSA_public_decrypt((int)n,p,p,pkey->pkey.rsa, | ||
| 1039 | RSA_PKCS1_PADDING); | ||
| 1040 | if (i <= 0) | ||
| 1041 | { | ||
| 1042 | al=SSL_AD_DECRYPT_ERROR; | ||
| 1043 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT); | ||
| 1044 | goto f_err; | ||
| 1045 | } | ||
| 1046 | if ((j != i) || (memcmp(p,md_buf,i) != 0)) | ||
| 1047 | { | ||
| 1048 | /* bad signature */ | ||
| 1049 | al=SSL_AD_DECRYPT_ERROR; | ||
| 1050 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_SIGNATURE); | ||
| 1051 | goto f_err; | ||
| 1052 | } | ||
| 1053 | } | ||
| 1054 | else | ||
| 1055 | #endif | ||
| 1056 | #ifndef NO_DSA | ||
| 1057 | if (pkey->type == EVP_PKEY_DSA) | ||
| 1058 | { | ||
| 1059 | /* lets do DSS */ | ||
| 1060 | EVP_VerifyInit(&md_ctx,EVP_dss1()); | ||
| 1061 | EVP_VerifyUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE); | ||
| 1062 | EVP_VerifyUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE); | ||
| 1063 | EVP_VerifyUpdate(&md_ctx,param,param_len); | ||
| 1064 | if (!EVP_VerifyFinal(&md_ctx,p,(int)n,pkey)) | ||
| 1065 | { | ||
| 1066 | /* bad signature */ | ||
| 1067 | al=SSL_AD_DECRYPT_ERROR; | ||
| 1068 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_SIGNATURE); | ||
| 1069 | goto f_err; | ||
| 1070 | } | ||
| 1071 | } | ||
| 1072 | else | ||
| 1073 | #endif | ||
| 1074 | { | ||
| 1075 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR); | ||
| 1076 | goto err; | ||
| 1077 | } | ||
| 1078 | } | ||
| 1079 | else | ||
| 1080 | { | ||
| 1081 | /* still data left over */ | ||
| 1082 | if (!(alg & SSL_aNULL)) | ||
| 1083 | { | ||
| 1084 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR); | ||
| 1085 | goto err; | ||
| 1086 | } | ||
| 1087 | if (n != 0) | ||
| 1088 | { | ||
| 1089 | al=SSL_AD_DECODE_ERROR; | ||
| 1090 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_EXTRA_DATA_IN_MESSAGE); | ||
| 1091 | goto f_err; | ||
| 1092 | } | ||
| 1093 | } | ||
| 1094 | |||
| 1095 | return(1); | ||
| 1096 | f_err: | ||
| 1097 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
| 1098 | err: | ||
| 1099 | return(-1); | ||
| 1100 | } | ||
| 1101 | |||
| 1102 | static int ssl3_get_certificate_request(s) | ||
| 1103 | SSL *s; | ||
| 1104 | { | ||
| 1105 | int ok,ret=0; | ||
| 1106 | unsigned long n,nc,l; | ||
| 1107 | unsigned int llen,ctype_num,i; | ||
| 1108 | X509_NAME *xn=NULL; | ||
| 1109 | unsigned char *p,*d,*q; | ||
| 1110 | STACK *ca_sk=NULL; | ||
| 1111 | |||
| 1112 | n=ssl3_get_message(s, | ||
| 1113 | SSL3_ST_CR_CERT_REQ_A, | ||
| 1114 | SSL3_ST_CR_CERT_REQ_B, | ||
| 1115 | -1, | ||
| 1116 | #if defined(MSDOS) && !defined(WIN32) | ||
| 1117 | 1024*30, /* 30k max cert list :-) */ | ||
| 1118 | #else | ||
| 1119 | 1024*100, /* 100k max cert list :-) */ | ||
| 1120 | #endif | ||
| 1121 | &ok); | ||
| 1122 | |||
| 1123 | if (!ok) return((int)n); | ||
| 1124 | |||
| 1125 | s->s3->tmp.cert_req=0; | ||
| 1126 | |||
| 1127 | if (s->s3->tmp.message_type == SSL3_MT_SERVER_DONE) | ||
| 1128 | { | ||
| 1129 | s->s3->tmp.reuse_message=1; | ||
| 1130 | return(1); | ||
| 1131 | } | ||
| 1132 | |||
| 1133 | if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE_REQUEST) | ||
| 1134 | { | ||
| 1135 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE); | ||
| 1136 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_WRONG_MESSAGE_TYPE); | ||
| 1137 | goto err; | ||
| 1138 | } | ||
| 1139 | |||
| 1140 | /* TLS does not like anon-DH with client cert */ | ||
| 1141 | if (s->version > SSL3_VERSION) | ||
| 1142 | { | ||
| 1143 | l=s->s3->tmp.new_cipher->algorithms; | ||
| 1144 | if (l & SSL_aNULL) | ||
| 1145 | { | ||
| 1146 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE); | ||
| 1147 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER); | ||
| 1148 | goto err; | ||
| 1149 | } | ||
| 1150 | } | ||
| 1151 | |||
| 1152 | d=p=(unsigned char *)s->init_buf->data; | ||
| 1153 | |||
| 1154 | if ((ca_sk=sk_new(ca_dn_cmp)) == NULL) | ||
| 1155 | { | ||
| 1156 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE); | ||
| 1157 | goto err; | ||
| 1158 | } | ||
| 1159 | |||
| 1160 | /* get the certificate types */ | ||
| 1161 | ctype_num= *(p++); | ||
| 1162 | if (ctype_num > SSL3_CT_NUMBER) | ||
| 1163 | ctype_num=SSL3_CT_NUMBER; | ||
| 1164 | for (i=0; i<ctype_num; i++) | ||
| 1165 | s->s3->tmp.ctype[i]= p[i]; | ||
| 1166 | p+=ctype_num; | ||
| 1167 | |||
| 1168 | /* get the CA RDNs */ | ||
| 1169 | n2s(p,llen); | ||
| 1170 | if ((llen+ctype_num+2+1) != n) | ||
| 1171 | { | ||
| 1172 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR); | ||
| 1173 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_LENGTH_MISMATCH); | ||
| 1174 | goto err; | ||
| 1175 | } | ||
| 1176 | |||
| 1177 | for (nc=0; nc<llen; ) | ||
| 1178 | { | ||
| 1179 | n2s(p,l); | ||
| 1180 | if ((l+nc+2) > llen) | ||
| 1181 | { | ||
| 1182 | if ((s->options & SSL_OP_NETSCAPE_CA_DN_BUG)) | ||
| 1183 | goto cont; /* netscape bugs */ | ||
| 1184 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR); | ||
| 1185 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_TOO_LONG); | ||
| 1186 | goto err; | ||
| 1187 | } | ||
| 1188 | |||
| 1189 | q=p; | ||
| 1190 | |||
| 1191 | if ((xn=d2i_X509_NAME(NULL,&q,l)) == NULL) | ||
| 1192 | { | ||
| 1193 | /* If netscape tollerance is on, ignore errors */ | ||
| 1194 | if (s->options & SSL_OP_NETSCAPE_CA_DN_BUG) | ||
| 1195 | goto cont; | ||
| 1196 | else | ||
| 1197 | { | ||
| 1198 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR); | ||
| 1199 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_ASN1_LIB); | ||
| 1200 | goto err; | ||
| 1201 | } | ||
| 1202 | } | ||
| 1203 | |||
| 1204 | if (q != (p+l)) | ||
| 1205 | { | ||
| 1206 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR); | ||
| 1207 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_LENGTH_MISMATCH); | ||
| 1208 | goto err; | ||
| 1209 | } | ||
| 1210 | if (!sk_push(ca_sk,(char *)xn)) | ||
| 1211 | { | ||
| 1212 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE); | ||
| 1213 | goto err; | ||
| 1214 | } | ||
| 1215 | |||
| 1216 | p+=l; | ||
| 1217 | nc+=l+2; | ||
| 1218 | } | ||
| 1219 | |||
| 1220 | if (0) | ||
| 1221 | { | ||
| 1222 | cont: | ||
| 1223 | ERR_clear_error(); | ||
| 1224 | } | ||
| 1225 | |||
| 1226 | /* we should setup a certficate to return.... */ | ||
| 1227 | s->s3->tmp.cert_req=1; | ||
| 1228 | s->s3->tmp.ctype_num=ctype_num; | ||
| 1229 | if (s->s3->tmp.ca_names != NULL) | ||
| 1230 | sk_pop_free(s->s3->tmp.ca_names,X509_NAME_free); | ||
| 1231 | s->s3->tmp.ca_names=ca_sk; | ||
| 1232 | ca_sk=NULL; | ||
| 1233 | |||
| 1234 | ret=1; | ||
| 1235 | err: | ||
| 1236 | if (ca_sk != NULL) sk_pop_free(ca_sk,X509_NAME_free); | ||
| 1237 | return(ret); | ||
| 1238 | } | ||
| 1239 | |||
| 1240 | static int ca_dn_cmp(a,b) | ||
| 1241 | X509_NAME **a,**b; | ||
| 1242 | { | ||
| 1243 | return(X509_NAME_cmp(*a,*b)); | ||
| 1244 | } | ||
| 1245 | |||
| 1246 | static int ssl3_get_server_done(s) | ||
| 1247 | SSL *s; | ||
| 1248 | { | ||
| 1249 | int ok,ret=0; | ||
| 1250 | long n; | ||
| 1251 | |||
| 1252 | n=ssl3_get_message(s, | ||
| 1253 | SSL3_ST_CR_SRVR_DONE_A, | ||
| 1254 | SSL3_ST_CR_SRVR_DONE_B, | ||
| 1255 | SSL3_MT_SERVER_DONE, | ||
| 1256 | 30, /* should be very small, like 0 :-) */ | ||
| 1257 | &ok); | ||
| 1258 | |||
| 1259 | if (!ok) return((int)n); | ||
| 1260 | if (n > 0) | ||
| 1261 | { | ||
| 1262 | /* should contain no data */ | ||
| 1263 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR); | ||
| 1264 | SSLerr(SSL_F_SSL3_GET_SERVER_DONE,SSL_R_LENGTH_MISMATCH); | ||
| 1265 | } | ||
| 1266 | ret=1; | ||
| 1267 | return(ret); | ||
| 1268 | } | ||
| 1269 | |||
| 1270 | static int ssl3_send_client_key_exchange(s) | ||
| 1271 | SSL *s; | ||
| 1272 | { | ||
| 1273 | unsigned char *p,*q,*d; | ||
| 1274 | int n; | ||
| 1275 | unsigned long l; | ||
| 1276 | EVP_PKEY *pkey=NULL; | ||
| 1277 | |||
| 1278 | if (s->state == SSL3_ST_CW_KEY_EXCH_A) | ||
| 1279 | { | ||
| 1280 | d=(unsigned char *)s->init_buf->data; | ||
| 1281 | p= &(d[4]); | ||
| 1282 | |||
| 1283 | l=s->s3->tmp.new_cipher->algorithms; | ||
| 1284 | |||
| 1285 | #ifndef NO_RSA | ||
| 1286 | if (l & SSL_kRSA) | ||
| 1287 | { | ||
| 1288 | RSA *rsa; | ||
| 1289 | unsigned char tmp_buf[48]; | ||
| 1290 | |||
| 1291 | if (s->session->cert->rsa_tmp != NULL) | ||
| 1292 | rsa=s->session->cert->rsa_tmp; | ||
| 1293 | else | ||
| 1294 | { | ||
| 1295 | pkey=X509_get_pubkey(s->session->cert->pkeys[SSL_PKEY_RSA_ENC].x509); | ||
| 1296 | if ((pkey == NULL) || | ||
| 1297 | (pkey->type != EVP_PKEY_RSA) || | ||
| 1298 | (pkey->pkey.rsa == NULL)) | ||
| 1299 | { | ||
| 1300 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR); | ||
| 1301 | goto err; | ||
| 1302 | } | ||
| 1303 | rsa=pkey->pkey.rsa; | ||
| 1304 | } | ||
| 1305 | |||
| 1306 | tmp_buf[0]=s->version>>8; | ||
| 1307 | tmp_buf[1]=s->version&0xff; | ||
| 1308 | RAND_bytes(&(tmp_buf[2]),SSL_MAX_MASTER_KEY_LENGTH-2); | ||
| 1309 | |||
| 1310 | s->session->master_key_length=SSL_MAX_MASTER_KEY_LENGTH; | ||
| 1311 | |||
| 1312 | q=p; | ||
| 1313 | /* Fix buf for TLS and beyond */ | ||
| 1314 | if (s->version > SSL3_VERSION) | ||
| 1315 | p+=2; | ||
| 1316 | n=RSA_public_encrypt(SSL_MAX_MASTER_KEY_LENGTH, | ||
| 1317 | tmp_buf,p,rsa,RSA_PKCS1_PADDING); | ||
| 1318 | if (n <= 0) | ||
| 1319 | { | ||
| 1320 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_ENCRYPT); | ||
| 1321 | goto err; | ||
| 1322 | } | ||
| 1323 | |||
| 1324 | /* Fix buf for TLS and beyond */ | ||
| 1325 | if (s->version > SSL3_VERSION) | ||
| 1326 | { | ||
| 1327 | s2n(n,q); | ||
| 1328 | n+=2; | ||
| 1329 | } | ||
| 1330 | |||
| 1331 | s->session->master_key_length= | ||
| 1332 | s->method->ssl3_enc->generate_master_secret(s, | ||
| 1333 | s->session->master_key, | ||
| 1334 | tmp_buf,48); | ||
| 1335 | memset(tmp_buf,0,48); | ||
| 1336 | } | ||
| 1337 | else | ||
| 1338 | #endif | ||
| 1339 | #ifndef NO_DH | ||
| 1340 | if (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd)) | ||
| 1341 | { | ||
| 1342 | DH *dh_srvr,*dh_clnt; | ||
| 1343 | |||
| 1344 | if (s->session->cert->dh_tmp != NULL) | ||
| 1345 | dh_srvr=s->session->cert->dh_tmp; | ||
| 1346 | else | ||
| 1347 | { | ||
| 1348 | /* we get them from the cert */ | ||
| 1349 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE); | ||
| 1350 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_UNABLE_TO_FIND_DH_PARAMETERS); | ||
| 1351 | goto err; | ||
| 1352 | } | ||
| 1353 | |||
| 1354 | /* generate a new random key */ | ||
| 1355 | if ((dh_clnt=DHparams_dup(dh_srvr)) == NULL) | ||
| 1356 | { | ||
| 1357 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
| 1358 | goto err; | ||
| 1359 | } | ||
| 1360 | if (!DH_generate_key(dh_clnt)) | ||
| 1361 | { | ||
| 1362 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
| 1363 | goto err; | ||
| 1364 | } | ||
| 1365 | |||
| 1366 | /* use the 'p' output buffer for the DH key, but | ||
| 1367 | * make sure to clear it out afterwards */ | ||
| 1368 | |||
| 1369 | n=DH_compute_key(p,dh_srvr->pub_key,dh_clnt); | ||
| 1370 | |||
| 1371 | if (n <= 0) | ||
| 1372 | { | ||
| 1373 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
| 1374 | goto err; | ||
| 1375 | } | ||
| 1376 | |||
| 1377 | /* generate master key from the result */ | ||
| 1378 | s->session->master_key_length= | ||
| 1379 | s->method->ssl3_enc->generate_master_secret(s, | ||
| 1380 | s->session->master_key,p,n); | ||
| 1381 | /* clean up */ | ||
| 1382 | memset(p,0,n); | ||
| 1383 | |||
| 1384 | /* send off the data */ | ||
| 1385 | n=BN_num_bytes(dh_clnt->pub_key); | ||
| 1386 | s2n(n,p); | ||
| 1387 | BN_bn2bin(dh_clnt->pub_key,p); | ||
| 1388 | n+=2; | ||
| 1389 | |||
| 1390 | DH_free(dh_clnt); | ||
| 1391 | |||
| 1392 | /* perhaps clean things up a bit EAY EAY EAY EAY*/ | ||
| 1393 | } | ||
| 1394 | else | ||
| 1395 | #endif | ||
| 1396 | { | ||
| 1397 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE); | ||
| 1398 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR); | ||
| 1399 | goto err; | ||
| 1400 | } | ||
| 1401 | |||
| 1402 | *(d++)=SSL3_MT_CLIENT_KEY_EXCHANGE; | ||
| 1403 | l2n3(n,d); | ||
| 1404 | |||
| 1405 | s->state=SSL3_ST_CW_KEY_EXCH_B; | ||
| 1406 | /* number of bytes to write */ | ||
| 1407 | s->init_num=n+4; | ||
| 1408 | s->init_off=0; | ||
| 1409 | } | ||
| 1410 | |||
| 1411 | /* SSL3_ST_CW_KEY_EXCH_B */ | ||
| 1412 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
| 1413 | err: | ||
| 1414 | return(-1); | ||
| 1415 | } | ||
| 1416 | |||
| 1417 | static int ssl3_send_client_verify(s) | ||
| 1418 | SSL *s; | ||
| 1419 | { | ||
| 1420 | unsigned char *p,*d; | ||
| 1421 | unsigned char data[MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH]; | ||
| 1422 | EVP_PKEY *pkey; | ||
| 1423 | int i=0; | ||
| 1424 | unsigned long n; | ||
| 1425 | #ifndef NO_DSA | ||
| 1426 | int j; | ||
| 1427 | #endif | ||
| 1428 | |||
| 1429 | if (s->state == SSL3_ST_CW_CERT_VRFY_A) | ||
| 1430 | { | ||
| 1431 | d=(unsigned char *)s->init_buf->data; | ||
| 1432 | p= &(d[4]); | ||
| 1433 | pkey=s->cert->key->privatekey; | ||
| 1434 | |||
| 1435 | s->method->ssl3_enc->cert_verify_mac(s,&(s->s3->finish_dgst2), | ||
| 1436 | &(data[MD5_DIGEST_LENGTH])); | ||
| 1437 | |||
| 1438 | #ifndef NO_RSA | ||
| 1439 | if (pkey->type == EVP_PKEY_RSA) | ||
| 1440 | { | ||
| 1441 | s->method->ssl3_enc->cert_verify_mac(s, | ||
| 1442 | &(s->s3->finish_dgst1),&(data[0])); | ||
| 1443 | i=RSA_private_encrypt( | ||
| 1444 | MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH, | ||
| 1445 | data,&(p[2]),pkey->pkey.rsa, | ||
| 1446 | RSA_PKCS1_PADDING); | ||
| 1447 | if (i <= 0) | ||
| 1448 | { | ||
| 1449 | SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,ERR_R_RSA_LIB); | ||
| 1450 | goto err; | ||
| 1451 | } | ||
| 1452 | s2n(i,p); | ||
| 1453 | n=i+2; | ||
| 1454 | } | ||
| 1455 | else | ||
| 1456 | #endif | ||
| 1457 | #ifndef NO_DSA | ||
| 1458 | if (pkey->type == EVP_PKEY_DSA) | ||
| 1459 | { | ||
| 1460 | if (!DSA_sign(pkey->save_type, | ||
| 1461 | &(data[MD5_DIGEST_LENGTH]), | ||
| 1462 | SHA_DIGEST_LENGTH,&(p[2]), | ||
| 1463 | (unsigned int *)&j,pkey->pkey.dsa)) | ||
| 1464 | { | ||
| 1465 | SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,ERR_R_DSA_LIB); | ||
| 1466 | goto err; | ||
| 1467 | } | ||
| 1468 | s2n(j,p); | ||
| 1469 | n=j+2; | ||
| 1470 | } | ||
| 1471 | else | ||
| 1472 | #endif | ||
| 1473 | { | ||
| 1474 | SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,SSL_R_INTERNAL_ERROR); | ||
| 1475 | goto err; | ||
| 1476 | } | ||
| 1477 | *(d++)=SSL3_MT_CERTIFICATE_VERIFY; | ||
| 1478 | l2n3(n,d); | ||
| 1479 | |||
| 1480 | s->init_num=(int)n+4; | ||
| 1481 | s->init_off=0; | ||
| 1482 | } | ||
| 1483 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
| 1484 | err: | ||
| 1485 | return(-1); | ||
| 1486 | } | ||
| 1487 | |||
| 1488 | static int ssl3_send_client_certificate(s) | ||
| 1489 | SSL *s; | ||
| 1490 | { | ||
| 1491 | X509 *x509=NULL; | ||
| 1492 | EVP_PKEY *pkey=NULL; | ||
| 1493 | int i; | ||
| 1494 | unsigned long l; | ||
| 1495 | |||
| 1496 | if (s->state == SSL3_ST_CW_CERT_A) | ||
| 1497 | { | ||
| 1498 | if ((s->cert == NULL) || | ||
| 1499 | (s->cert->key->x509 == NULL) || | ||
| 1500 | (s->cert->key->privatekey == NULL)) | ||
| 1501 | s->state=SSL3_ST_CW_CERT_B; | ||
| 1502 | else | ||
| 1503 | s->state=SSL3_ST_CW_CERT_C; | ||
| 1504 | } | ||
| 1505 | |||
| 1506 | /* We need to get a client cert */ | ||
| 1507 | if (s->state == SSL3_ST_CW_CERT_B) | ||
| 1508 | { | ||
| 1509 | /* If we get an error, we need to | ||
| 1510 | * ssl->rwstate=SSL_X509_LOOKUP; return(-1); | ||
| 1511 | * We then get retied later */ | ||
| 1512 | i=0; | ||
| 1513 | if (s->ctx->client_cert_cb != NULL) | ||
| 1514 | i=s->ctx->client_cert_cb(s,&(x509),&(pkey)); | ||
| 1515 | if (i < 0) | ||
| 1516 | { | ||
| 1517 | s->rwstate=SSL_X509_LOOKUP; | ||
| 1518 | return(-1); | ||
| 1519 | } | ||
| 1520 | s->rwstate=SSL_NOTHING; | ||
| 1521 | if ((i == 1) && (pkey != NULL) && (x509 != NULL)) | ||
| 1522 | { | ||
| 1523 | s->state=SSL3_ST_CW_CERT_B; | ||
| 1524 | if ( !SSL_use_certificate(s,x509) || | ||
| 1525 | !SSL_use_PrivateKey(s,pkey)) | ||
| 1526 | i=0; | ||
| 1527 | } | ||
| 1528 | else if (i == 1) | ||
| 1529 | { | ||
| 1530 | i=0; | ||
| 1531 | SSLerr(SSL_F_SSL3_SEND_CLIENT_CERTIFICATE,SSL_R_BAD_DATA_RETURNED_BY_CALLBACK); | ||
| 1532 | } | ||
| 1533 | |||
| 1534 | if (x509 != NULL) X509_free(x509); | ||
| 1535 | if (pkey != NULL) EVP_PKEY_free(pkey); | ||
| 1536 | if (i == 0) | ||
| 1537 | { | ||
| 1538 | if (s->version == SSL3_VERSION) | ||
| 1539 | { | ||
| 1540 | s->s3->tmp.cert_req=0; | ||
| 1541 | ssl3_send_alert(s,SSL3_AL_WARNING,SSL_AD_NO_CERTIFICATE); | ||
| 1542 | return(1); | ||
| 1543 | } | ||
| 1544 | else | ||
| 1545 | { | ||
| 1546 | s->s3->tmp.cert_req=2; | ||
| 1547 | } | ||
| 1548 | } | ||
| 1549 | |||
| 1550 | /* Ok, we have a cert */ | ||
| 1551 | s->state=SSL3_ST_CW_CERT_C; | ||
| 1552 | } | ||
| 1553 | |||
| 1554 | if (s->state == SSL3_ST_CW_CERT_C) | ||
| 1555 | { | ||
| 1556 | s->state=SSL3_ST_CW_CERT_D; | ||
| 1557 | l=ssl3_output_cert_chain(s, | ||
| 1558 | (s->s3->tmp.cert_req == 2)?NULL:s->cert->key->x509); | ||
| 1559 | s->init_num=(int)l; | ||
| 1560 | s->init_off=0; | ||
| 1561 | } | ||
| 1562 | /* SSL3_ST_CW_CERT_D */ | ||
| 1563 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
| 1564 | } | ||
| 1565 | |||
| 1566 | #define has_bits(i,m) (((i)&(m)) == (m)) | ||
| 1567 | |||
| 1568 | static int ssl3_check_cert_and_algorithm(s) | ||
| 1569 | SSL *s; | ||
| 1570 | { | ||
| 1571 | int i,idx; | ||
| 1572 | long algs; | ||
| 1573 | EVP_PKEY *pkey=NULL; | ||
| 1574 | CERT *c; | ||
| 1575 | RSA *rsa; | ||
| 1576 | DH *dh; | ||
| 1577 | |||
| 1578 | c=s->session->cert; | ||
| 1579 | |||
| 1580 | if (c == NULL) | ||
| 1581 | { | ||
| 1582 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_INTERNAL_ERROR); | ||
| 1583 | goto err; | ||
| 1584 | } | ||
| 1585 | |||
| 1586 | algs=s->s3->tmp.new_cipher->algorithms; | ||
| 1587 | |||
| 1588 | /* we don't have a certificate */ | ||
| 1589 | if (algs & (SSL_aDH|SSL_aNULL)) | ||
| 1590 | return(1); | ||
| 1591 | |||
| 1592 | rsa=s->session->cert->rsa_tmp; | ||
| 1593 | dh=s->session->cert->dh_tmp; | ||
| 1594 | |||
| 1595 | /* This is the passed certificate */ | ||
| 1596 | |||
| 1597 | idx=c->cert_type; | ||
| 1598 | pkey=X509_get_pubkey(c->pkeys[idx].x509); | ||
| 1599 | i=X509_certificate_type(c->pkeys[idx].x509,pkey); | ||
| 1600 | |||
| 1601 | |||
| 1602 | /* Check that we have a certificate if we require one */ | ||
| 1603 | if ((algs & SSL_aRSA) && !has_bits(i,EVP_PK_RSA|EVP_PKT_SIGN)) | ||
| 1604 | { | ||
| 1605 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_SIGNING_CERT); | ||
| 1606 | goto f_err; | ||
| 1607 | } | ||
| 1608 | #ifndef NO_DSA | ||
| 1609 | else if ((algs & SSL_aDSS) && !has_bits(i,EVP_PK_DSA|EVP_PKT_SIGN)) | ||
| 1610 | { | ||
| 1611 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DSA_SIGNING_CERT); | ||
| 1612 | goto f_err; | ||
| 1613 | } | ||
| 1614 | #endif | ||
| 1615 | |||
| 1616 | if ((algs & SSL_kRSA) && | ||
| 1617 | !(has_bits(i,EVP_PK_RSA|EVP_PKT_ENC) || (rsa != NULL))) | ||
| 1618 | { | ||
| 1619 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_ENCRYPTING_CERT); | ||
| 1620 | goto f_err; | ||
| 1621 | } | ||
| 1622 | #ifndef NO_DH | ||
| 1623 | else if ((algs & SSL_kEDH) && | ||
| 1624 | !(has_bits(i,EVP_PK_DH|EVP_PKT_EXCH) || (dh != NULL))) | ||
| 1625 | { | ||
| 1626 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_KEY); | ||
| 1627 | goto f_err; | ||
| 1628 | } | ||
| 1629 | else if ((algs & SSL_kDHr) && !has_bits(i,EVP_PK_DH|EVP_PKS_RSA)) | ||
| 1630 | { | ||
| 1631 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_RSA_CERT); | ||
| 1632 | goto f_err; | ||
| 1633 | } | ||
| 1634 | #ifndef NO_DSA | ||
| 1635 | else if ((algs & SSL_kDHd) && !has_bits(i,EVP_PK_DH|EVP_PKS_DSA)) | ||
| 1636 | { | ||
| 1637 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_DSA_CERT); | ||
| 1638 | goto f_err; | ||
| 1639 | } | ||
| 1640 | #endif | ||
| 1641 | #endif | ||
| 1642 | |||
| 1643 | if ((algs & SSL_EXP) && !has_bits(i,EVP_PKT_EXP)) | ||
| 1644 | { | ||
| 1645 | #ifndef NO_RSA | ||
| 1646 | if (algs & SSL_kRSA) | ||
| 1647 | { | ||
| 1648 | if ((rsa == NULL) || (RSA_size(rsa) > 512)) | ||
| 1649 | { | ||
| 1650 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_RSA_KEY); | ||
| 1651 | goto f_err; | ||
| 1652 | } | ||
| 1653 | } | ||
| 1654 | else | ||
| 1655 | #endif | ||
| 1656 | #ifndef NO_DH | ||
| 1657 | if (algs & (SSL_kEDH|SSL_kDHr|SSL_kDHd)) | ||
| 1658 | { | ||
| 1659 | if ((dh == NULL) || (DH_size(dh) > 512)) | ||
| 1660 | { | ||
| 1661 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_DH_KEY); | ||
| 1662 | goto f_err; | ||
| 1663 | } | ||
| 1664 | } | ||
| 1665 | else | ||
| 1666 | #endif | ||
| 1667 | { | ||
| 1668 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE); | ||
| 1669 | goto f_err; | ||
| 1670 | } | ||
| 1671 | } | ||
| 1672 | return(1); | ||
| 1673 | f_err: | ||
| 1674 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE); | ||
| 1675 | err: | ||
| 1676 | return(0); | ||
| 1677 | } | ||
| 1678 | |||
diff --git a/src/lib/libssl/s3_lib.c b/src/lib/libssl/s3_lib.c new file mode 100644 index 0000000000..0fd945025d --- /dev/null +++ b/src/lib/libssl/s3_lib.c | |||
| @@ -0,0 +1,961 @@ | |||
| 1 | /* ssl/s3_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 "objects.h" | ||
| 61 | #include "ssl_locl.h" | ||
| 62 | |||
| 63 | char *ssl3_version_str="SSLv3 part of SSLeay 0.9.0b 29-Jun-1998"; | ||
| 64 | |||
| 65 | #define SSL3_NUM_CIPHERS (sizeof(ssl3_ciphers)/sizeof(SSL_CIPHER)) | ||
| 66 | |||
| 67 | #ifndef NOPROTO | ||
| 68 | static long ssl3_default_timeout(void ); | ||
| 69 | #else | ||
| 70 | static long ssl3_default_timeout(); | ||
| 71 | #endif | ||
| 72 | |||
| 73 | SSL_CIPHER ssl3_ciphers[]={ | ||
| 74 | /* The RSA ciphers */ | ||
| 75 | /* Cipher 01 */ | ||
| 76 | { | ||
| 77 | 1, | ||
| 78 | SSL3_TXT_RSA_NULL_MD5, | ||
| 79 | SSL3_CK_RSA_NULL_MD5, | ||
| 80 | SSL_kRSA|SSL_aRSA|SSL_eNULL |SSL_MD5|SSL_NOT_EXP|SSL_SSLV3, | ||
| 81 | 0, | ||
| 82 | SSL_ALL_CIPHERS, | ||
| 83 | }, | ||
| 84 | /* Cipher 02 */ | ||
| 85 | { | ||
| 86 | 1, | ||
| 87 | SSL3_TXT_RSA_NULL_SHA, | ||
| 88 | SSL3_CK_RSA_NULL_SHA, | ||
| 89 | SSL_kRSA|SSL_aRSA|SSL_eNULL |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3, | ||
| 90 | 0, | ||
| 91 | SSL_ALL_CIPHERS, | ||
| 92 | }, | ||
| 93 | |||
| 94 | /* anon DH */ | ||
| 95 | /* Cipher 17 */ | ||
| 96 | { | ||
| 97 | 1, | ||
| 98 | SSL3_TXT_ADH_RC4_40_MD5, | ||
| 99 | SSL3_CK_ADH_RC4_40_MD5, | ||
| 100 | SSL_kEDH |SSL_aNULL|SSL_RC4 |SSL_MD5 |SSL_EXP|SSL_SSLV3, | ||
| 101 | 0, | ||
| 102 | SSL_ALL_CIPHERS, | ||
| 103 | }, | ||
| 104 | /* Cipher 18 */ | ||
| 105 | { | ||
| 106 | 1, | ||
| 107 | SSL3_TXT_ADH_RC4_128_MD5, | ||
| 108 | SSL3_CK_ADH_RC4_128_MD5, | ||
| 109 | SSL_kEDH |SSL_aNULL|SSL_RC4 |SSL_MD5|SSL_NOT_EXP|SSL_SSLV3, | ||
| 110 | 0, | ||
| 111 | SSL_ALL_CIPHERS, | ||
| 112 | }, | ||
| 113 | /* Cipher 19 */ | ||
| 114 | { | ||
| 115 | 1, | ||
| 116 | SSL3_TXT_ADH_DES_40_CBC_SHA, | ||
| 117 | SSL3_CK_ADH_DES_40_CBC_SHA, | ||
| 118 | SSL_kEDH |SSL_aNULL|SSL_DES|SSL_SHA1|SSL_EXP|SSL_SSLV3, | ||
| 119 | 0, | ||
| 120 | SSL_ALL_CIPHERS, | ||
| 121 | }, | ||
| 122 | /* Cipher 1A */ | ||
| 123 | { | ||
| 124 | 1, | ||
| 125 | SSL3_TXT_ADH_DES_64_CBC_SHA, | ||
| 126 | SSL3_CK_ADH_DES_64_CBC_SHA, | ||
| 127 | SSL_kEDH |SSL_aNULL|SSL_DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3, | ||
| 128 | 0, | ||
| 129 | SSL_ALL_CIPHERS, | ||
| 130 | }, | ||
| 131 | /* Cipher 1B */ | ||
| 132 | { | ||
| 133 | 1, | ||
| 134 | SSL3_TXT_ADH_DES_192_CBC_SHA, | ||
| 135 | SSL3_CK_ADH_DES_192_CBC_SHA, | ||
| 136 | SSL_kEDH |SSL_aNULL|SSL_3DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3, | ||
| 137 | 0, | ||
| 138 | SSL_ALL_CIPHERS, | ||
| 139 | }, | ||
| 140 | |||
| 141 | /* RSA again */ | ||
| 142 | /* Cipher 03 */ | ||
| 143 | { | ||
| 144 | 1, | ||
| 145 | SSL3_TXT_RSA_RC4_40_MD5, | ||
| 146 | SSL3_CK_RSA_RC4_40_MD5, | ||
| 147 | SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_MD5 |SSL_EXP|SSL_SSLV3, | ||
| 148 | 0, | ||
| 149 | SSL_ALL_CIPHERS, | ||
| 150 | }, | ||
| 151 | /* Cipher 04 */ | ||
| 152 | { | ||
| 153 | 1, | ||
| 154 | SSL3_TXT_RSA_RC4_128_MD5, | ||
| 155 | SSL3_CK_RSA_RC4_128_MD5, | ||
| 156 | SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_MD5|SSL_NOT_EXP|SSL_SSLV3|SSL_MEDIUM, | ||
| 157 | 0, | ||
| 158 | SSL_ALL_CIPHERS, | ||
| 159 | }, | ||
| 160 | /* Cipher 05 */ | ||
| 161 | { | ||
| 162 | 1, | ||
| 163 | SSL3_TXT_RSA_RC4_128_SHA, | ||
| 164 | SSL3_CK_RSA_RC4_128_SHA, | ||
| 165 | SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_MEDIUM, | ||
| 166 | 0, | ||
| 167 | SSL_ALL_CIPHERS, | ||
| 168 | }, | ||
| 169 | /* Cipher 06 */ | ||
| 170 | { | ||
| 171 | 1, | ||
| 172 | SSL3_TXT_RSA_RC2_40_MD5, | ||
| 173 | SSL3_CK_RSA_RC2_40_MD5, | ||
| 174 | SSL_kRSA|SSL_aRSA|SSL_RC2 |SSL_MD5 |SSL_EXP|SSL_SSLV3, | ||
| 175 | 0, | ||
| 176 | SSL_ALL_CIPHERS, | ||
| 177 | }, | ||
| 178 | /* Cipher 07 */ | ||
| 179 | { | ||
| 180 | 1, | ||
| 181 | SSL3_TXT_RSA_IDEA_128_SHA, | ||
| 182 | SSL3_CK_RSA_IDEA_128_SHA, | ||
| 183 | SSL_kRSA|SSL_aRSA|SSL_IDEA |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_MEDIUM, | ||
| 184 | 0, | ||
| 185 | SSL_ALL_CIPHERS, | ||
| 186 | }, | ||
| 187 | /* Cipher 08 */ | ||
| 188 | { | ||
| 189 | 1, | ||
| 190 | SSL3_TXT_RSA_DES_40_CBC_SHA, | ||
| 191 | SSL3_CK_RSA_DES_40_CBC_SHA, | ||
| 192 | SSL_kRSA|SSL_aRSA|SSL_DES|SSL_SHA1|SSL_EXP|SSL_SSLV3, | ||
| 193 | 0, | ||
| 194 | SSL_ALL_CIPHERS, | ||
| 195 | }, | ||
| 196 | /* Cipher 09 */ | ||
| 197 | { | ||
| 198 | 1, | ||
| 199 | SSL3_TXT_RSA_DES_64_CBC_SHA, | ||
| 200 | SSL3_CK_RSA_DES_64_CBC_SHA, | ||
| 201 | SSL_kRSA|SSL_aRSA|SSL_DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_LOW, | ||
| 202 | 0, | ||
| 203 | SSL_ALL_CIPHERS, | ||
| 204 | }, | ||
| 205 | /* Cipher 0A */ | ||
| 206 | { | ||
| 207 | 1, | ||
| 208 | SSL3_TXT_RSA_DES_192_CBC3_SHA, | ||
| 209 | SSL3_CK_RSA_DES_192_CBC3_SHA, | ||
| 210 | SSL_kRSA|SSL_aRSA|SSL_3DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_HIGH, | ||
| 211 | 0, | ||
| 212 | SSL_ALL_CIPHERS, | ||
| 213 | }, | ||
| 214 | |||
| 215 | /* The DH ciphers */ | ||
| 216 | /* Cipher 0B */ | ||
| 217 | { | ||
| 218 | 0, | ||
| 219 | SSL3_TXT_DH_DSS_DES_40_CBC_SHA, | ||
| 220 | SSL3_CK_DH_DSS_DES_40_CBC_SHA, | ||
| 221 | SSL_kDHd |SSL_aDH|SSL_DES|SSL_SHA1|SSL_EXP|SSL_SSLV3, | ||
| 222 | 0, | ||
| 223 | SSL_ALL_CIPHERS, | ||
| 224 | }, | ||
| 225 | /* Cipher 0C */ | ||
| 226 | { | ||
| 227 | 0, | ||
| 228 | SSL3_TXT_DH_DSS_DES_64_CBC_SHA, | ||
| 229 | SSL3_CK_DH_DSS_DES_64_CBC_SHA, | ||
| 230 | SSL_kDHd |SSL_aDH|SSL_DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_LOW, | ||
| 231 | 0, | ||
| 232 | SSL_ALL_CIPHERS, | ||
| 233 | }, | ||
| 234 | /* Cipher 0D */ | ||
| 235 | { | ||
| 236 | 0, | ||
| 237 | SSL3_TXT_DH_DSS_DES_192_CBC3_SHA, | ||
| 238 | SSL3_CK_DH_DSS_DES_192_CBC3_SHA, | ||
| 239 | SSL_kDHd |SSL_aDH|SSL_3DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_HIGH, | ||
| 240 | 0, | ||
| 241 | SSL_ALL_CIPHERS, | ||
| 242 | }, | ||
| 243 | /* Cipher 0E */ | ||
| 244 | { | ||
| 245 | 0, | ||
| 246 | SSL3_TXT_DH_RSA_DES_40_CBC_SHA, | ||
| 247 | SSL3_CK_DH_RSA_DES_40_CBC_SHA, | ||
| 248 | SSL_kDHr |SSL_aDH|SSL_DES|SSL_SHA1|SSL_EXP|SSL_SSLV3, | ||
| 249 | 0, | ||
| 250 | SSL_ALL_CIPHERS, | ||
| 251 | }, | ||
| 252 | /* Cipher 0F */ | ||
| 253 | { | ||
| 254 | 0, | ||
| 255 | SSL3_TXT_DH_RSA_DES_64_CBC_SHA, | ||
| 256 | SSL3_CK_DH_RSA_DES_64_CBC_SHA, | ||
| 257 | SSL_kDHr |SSL_aDH|SSL_DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_LOW, | ||
| 258 | 0, | ||
| 259 | SSL_ALL_CIPHERS, | ||
| 260 | }, | ||
| 261 | /* Cipher 10 */ | ||
| 262 | { | ||
| 263 | 0, | ||
| 264 | SSL3_TXT_DH_RSA_DES_192_CBC3_SHA, | ||
| 265 | SSL3_CK_DH_RSA_DES_192_CBC3_SHA, | ||
| 266 | SSL_kDHr |SSL_aDH|SSL_3DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_HIGH, | ||
| 267 | 0, | ||
| 268 | SSL_ALL_CIPHERS, | ||
| 269 | }, | ||
| 270 | |||
| 271 | /* The Ephemeral DH ciphers */ | ||
| 272 | /* Cipher 11 */ | ||
| 273 | { | ||
| 274 | 1, | ||
| 275 | SSL3_TXT_EDH_DSS_DES_40_CBC_SHA, | ||
| 276 | SSL3_CK_EDH_DSS_DES_40_CBC_SHA, | ||
| 277 | SSL_kEDH|SSL_aDSS|SSL_DES|SSL_SHA1|SSL_EXP|SSL_SSLV3, | ||
| 278 | 0, | ||
| 279 | SSL_ALL_CIPHERS, | ||
| 280 | }, | ||
| 281 | /* Cipher 12 */ | ||
| 282 | { | ||
| 283 | 1, | ||
| 284 | SSL3_TXT_EDH_DSS_DES_64_CBC_SHA, | ||
| 285 | SSL3_CK_EDH_DSS_DES_64_CBC_SHA, | ||
| 286 | SSL_kEDH|SSL_aDSS|SSL_DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_LOW, | ||
| 287 | 0, | ||
| 288 | SSL_ALL_CIPHERS, | ||
| 289 | }, | ||
| 290 | /* Cipher 13 */ | ||
| 291 | { | ||
| 292 | 1, | ||
| 293 | SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA, | ||
| 294 | SSL3_CK_EDH_DSS_DES_192_CBC3_SHA, | ||
| 295 | SSL_kEDH|SSL_aDSS|SSL_3DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_HIGH, | ||
| 296 | 0, | ||
| 297 | SSL_ALL_CIPHERS, | ||
| 298 | }, | ||
| 299 | /* Cipher 14 */ | ||
| 300 | { | ||
| 301 | 1, | ||
| 302 | SSL3_TXT_EDH_RSA_DES_40_CBC_SHA, | ||
| 303 | SSL3_CK_EDH_RSA_DES_40_CBC_SHA, | ||
| 304 | SSL_kEDH|SSL_aRSA|SSL_DES|SSL_SHA1|SSL_EXP|SSL_SSLV3, | ||
| 305 | 0, | ||
| 306 | SSL_ALL_CIPHERS, | ||
| 307 | }, | ||
| 308 | /* Cipher 15 */ | ||
| 309 | { | ||
| 310 | 1, | ||
| 311 | SSL3_TXT_EDH_RSA_DES_64_CBC_SHA, | ||
| 312 | SSL3_CK_EDH_RSA_DES_64_CBC_SHA, | ||
| 313 | SSL_kEDH|SSL_aRSA|SSL_DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_LOW, | ||
| 314 | 0, | ||
| 315 | SSL_ALL_CIPHERS, | ||
| 316 | }, | ||
| 317 | /* Cipher 16 */ | ||
| 318 | { | ||
| 319 | 1, | ||
| 320 | SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA, | ||
| 321 | SSL3_CK_EDH_RSA_DES_192_CBC3_SHA, | ||
| 322 | SSL_kEDH|SSL_aRSA|SSL_3DES |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3|SSL_HIGH, | ||
| 323 | 0, | ||
| 324 | SSL_ALL_CIPHERS, | ||
| 325 | }, | ||
| 326 | |||
| 327 | /* Fortezza */ | ||
| 328 | /* Cipher 1C */ | ||
| 329 | { | ||
| 330 | 0, | ||
| 331 | SSL3_TXT_FZA_DMS_NULL_SHA, | ||
| 332 | SSL3_CK_FZA_DMS_NULL_SHA, | ||
| 333 | SSL_kFZA|SSL_aFZA |SSL_eNULL |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3, | ||
| 334 | 0, | ||
| 335 | SSL_ALL_CIPHERS, | ||
| 336 | }, | ||
| 337 | |||
| 338 | /* Cipher 1D */ | ||
| 339 | { | ||
| 340 | 0, | ||
| 341 | SSL3_TXT_FZA_DMS_FZA_SHA, | ||
| 342 | SSL3_CK_FZA_DMS_FZA_SHA, | ||
| 343 | SSL_kFZA|SSL_aFZA |SSL_eFZA |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3, | ||
| 344 | 0, | ||
| 345 | SSL_ALL_CIPHERS, | ||
| 346 | }, | ||
| 347 | |||
| 348 | /* Cipher 1E */ | ||
| 349 | { | ||
| 350 | 0, | ||
| 351 | SSL3_TXT_FZA_DMS_RC4_SHA, | ||
| 352 | SSL3_CK_FZA_DMS_RC4_SHA, | ||
| 353 | SSL_kFZA|SSL_aFZA |SSL_RC4 |SSL_SHA1|SSL_NOT_EXP|SSL_SSLV3, | ||
| 354 | 0, | ||
| 355 | SSL_ALL_CIPHERS, | ||
| 356 | }, | ||
| 357 | |||
| 358 | /* end of list */ | ||
| 359 | }; | ||
| 360 | |||
| 361 | static SSL3_ENC_METHOD SSLv3_enc_data={ | ||
| 362 | ssl3_enc, | ||
| 363 | ssl3_mac, | ||
| 364 | ssl3_setup_key_block, | ||
| 365 | ssl3_generate_master_secret, | ||
| 366 | ssl3_change_cipher_state, | ||
| 367 | ssl3_final_finish_mac, | ||
| 368 | MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH, | ||
| 369 | ssl3_cert_verify_mac, | ||
| 370 | SSL3_MD_CLIENT_FINISHED_CONST,4, | ||
| 371 | SSL3_MD_SERVER_FINISHED_CONST,4, | ||
| 372 | ssl3_alert_code, | ||
| 373 | }; | ||
| 374 | |||
| 375 | static SSL_METHOD SSLv3_data= { | ||
| 376 | SSL3_VERSION, | ||
| 377 | ssl3_new, | ||
| 378 | ssl3_clear, | ||
| 379 | ssl3_free, | ||
| 380 | ssl_undefined_function, | ||
| 381 | ssl_undefined_function, | ||
| 382 | ssl3_read, | ||
| 383 | ssl3_peek, | ||
| 384 | ssl3_write, | ||
| 385 | ssl3_shutdown, | ||
| 386 | ssl3_renegotiate, | ||
| 387 | ssl3_ctrl, | ||
| 388 | ssl3_ctx_ctrl, | ||
| 389 | ssl3_get_cipher_by_char, | ||
| 390 | ssl3_put_cipher_by_char, | ||
| 391 | ssl3_pending, | ||
| 392 | ssl3_num_ciphers, | ||
| 393 | ssl3_get_cipher, | ||
| 394 | ssl_bad_method, | ||
| 395 | ssl3_default_timeout, | ||
| 396 | &SSLv3_enc_data, | ||
| 397 | }; | ||
| 398 | |||
| 399 | static long ssl3_default_timeout() | ||
| 400 | { | ||
| 401 | /* 2 hours, the 24 hours mentioned in the SSLv3 spec | ||
| 402 | * is way too long for http, the cache would over fill */ | ||
| 403 | return(60*60*2); | ||
| 404 | } | ||
| 405 | |||
| 406 | SSL_METHOD *sslv3_base_method() | ||
| 407 | { | ||
| 408 | return(&SSLv3_data); | ||
| 409 | } | ||
| 410 | |||
| 411 | int ssl3_num_ciphers() | ||
| 412 | { | ||
| 413 | return(SSL3_NUM_CIPHERS); | ||
| 414 | } | ||
| 415 | |||
| 416 | SSL_CIPHER *ssl3_get_cipher(u) | ||
| 417 | unsigned int u; | ||
| 418 | { | ||
| 419 | if (u < SSL3_NUM_CIPHERS) | ||
| 420 | return(&(ssl3_ciphers[SSL3_NUM_CIPHERS-1-u])); | ||
| 421 | else | ||
| 422 | return(NULL); | ||
| 423 | } | ||
| 424 | |||
| 425 | /* The problem is that it may not be the correct record type */ | ||
| 426 | int ssl3_pending(s) | ||
| 427 | SSL *s; | ||
| 428 | { | ||
| 429 | return(s->s3->rrec.length); | ||
| 430 | } | ||
| 431 | |||
| 432 | int ssl3_new(s) | ||
| 433 | SSL *s; | ||
| 434 | { | ||
| 435 | SSL3_CTX *s3; | ||
| 436 | |||
| 437 | if ((s3=(SSL3_CTX *)Malloc(sizeof(SSL3_CTX))) == NULL) goto err; | ||
| 438 | memset(s3,0,sizeof(SSL3_CTX)); | ||
| 439 | |||
| 440 | s->s3=s3; | ||
| 441 | /* | ||
| 442 | s->s3->tmp.ca_names=NULL; | ||
| 443 | s->s3->tmp.key_block=NULL; | ||
| 444 | s->s3->tmp.key_block_length=0; | ||
| 445 | s->s3->rbuf.buf=NULL; | ||
| 446 | s->s3->wbuf.buf=NULL; | ||
| 447 | */ | ||
| 448 | |||
| 449 | s->method->ssl_clear(s); | ||
| 450 | return(1); | ||
| 451 | err: | ||
| 452 | return(0); | ||
| 453 | } | ||
| 454 | |||
| 455 | void ssl3_free(s) | ||
| 456 | SSL *s; | ||
| 457 | { | ||
| 458 | ssl3_cleanup_key_block(s); | ||
| 459 | if (s->s3->rbuf.buf != NULL) | ||
| 460 | Free(s->s3->rbuf.buf); | ||
| 461 | if (s->s3->wbuf.buf != NULL) | ||
| 462 | Free(s->s3->wbuf.buf); | ||
| 463 | #ifndef NO_DH | ||
| 464 | if (s->s3->tmp.dh != NULL) | ||
| 465 | DH_free(s->s3->tmp.dh); | ||
| 466 | #endif | ||
| 467 | if (s->s3->tmp.ca_names != NULL) | ||
| 468 | sk_pop_free(s->s3->tmp.ca_names,X509_NAME_free); | ||
| 469 | memset(s->s3,0,sizeof(SSL3_CTX)); | ||
| 470 | Free(s->s3); | ||
| 471 | s->s3=NULL; | ||
| 472 | } | ||
| 473 | |||
| 474 | void ssl3_clear(s) | ||
| 475 | SSL *s; | ||
| 476 | { | ||
| 477 | unsigned char *rp,*wp; | ||
| 478 | |||
| 479 | ssl3_cleanup_key_block(s); | ||
| 480 | if (s->s3->tmp.ca_names != NULL) | ||
| 481 | sk_pop_free(s->s3->tmp.ca_names,X509_NAME_free); | ||
| 482 | |||
| 483 | rp=s->s3->rbuf.buf; | ||
| 484 | wp=s->s3->wbuf.buf; | ||
| 485 | |||
| 486 | memset(s->s3,0,sizeof(SSL3_CTX)); | ||
| 487 | if (rp != NULL) s->s3->rbuf.buf=rp; | ||
| 488 | if (wp != NULL) s->s3->wbuf.buf=wp; | ||
| 489 | s->packet_length=0; | ||
| 490 | s->s3->renegotiate=0; | ||
| 491 | s->s3->total_renegotiations=0; | ||
| 492 | s->s3->num_renegotiations=0; | ||
| 493 | s->s3->in_read_app_data=0; | ||
| 494 | s->version=SSL3_VERSION; | ||
| 495 | } | ||
| 496 | |||
| 497 | long ssl3_ctrl(s,cmd,larg,parg) | ||
| 498 | SSL *s; | ||
| 499 | int cmd; | ||
| 500 | long larg; | ||
| 501 | char *parg; | ||
| 502 | { | ||
| 503 | int ret=0; | ||
| 504 | |||
| 505 | switch (cmd) | ||
| 506 | { | ||
| 507 | case SSL_CTRL_GET_SESSION_REUSED: | ||
| 508 | ret=s->hit; | ||
| 509 | break; | ||
| 510 | case SSL_CTRL_GET_CLIENT_CERT_REQUEST: | ||
| 511 | break; | ||
| 512 | case SSL_CTRL_GET_NUM_RENEGOTIATIONS: | ||
| 513 | ret=s->s3->num_renegotiations; | ||
| 514 | break; | ||
| 515 | case SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS: | ||
| 516 | ret=s->s3->num_renegotiations; | ||
| 517 | s->s3->num_renegotiations=0; | ||
| 518 | break; | ||
| 519 | case SSL_CTRL_GET_TOTAL_RENEGOTIATIONS: | ||
| 520 | ret=s->s3->total_renegotiations; | ||
| 521 | break; | ||
| 522 | default: | ||
| 523 | break; | ||
| 524 | } | ||
| 525 | return(ret); | ||
| 526 | } | ||
| 527 | |||
| 528 | long ssl3_ctx_ctrl(ctx,cmd,larg,parg) | ||
| 529 | SSL_CTX *ctx; | ||
| 530 | int cmd; | ||
| 531 | long larg; | ||
| 532 | char *parg; | ||
| 533 | { | ||
| 534 | CERT *cert; | ||
| 535 | |||
| 536 | cert=ctx->default_cert; | ||
| 537 | |||
| 538 | switch (cmd) | ||
| 539 | { | ||
| 540 | #ifndef NO_RSA | ||
| 541 | case SSL_CTRL_NEED_TMP_RSA: | ||
| 542 | if ( (cert->rsa_tmp == NULL) && | ||
| 543 | ((cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL) || | ||
| 544 | (EVP_PKEY_size(cert->pkeys[SSL_PKEY_RSA_ENC].privatekey) > (512/8))) | ||
| 545 | ) | ||
| 546 | return(1); | ||
| 547 | else | ||
| 548 | return(0); | ||
| 549 | break; | ||
| 550 | case SSL_CTRL_SET_TMP_RSA: | ||
| 551 | { | ||
| 552 | RSA *rsa; | ||
| 553 | int i; | ||
| 554 | |||
| 555 | rsa=(RSA *)parg; | ||
| 556 | i=1; | ||
| 557 | if (rsa == NULL) | ||
| 558 | i=0; | ||
| 559 | else | ||
| 560 | { | ||
| 561 | if ((rsa=RSAPrivateKey_dup(rsa)) == NULL) | ||
| 562 | i=0; | ||
| 563 | } | ||
| 564 | if (!i) | ||
| 565 | { | ||
| 566 | SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_RSA_LIB); | ||
| 567 | return(0); | ||
| 568 | } | ||
| 569 | else | ||
| 570 | { | ||
| 571 | if (cert->rsa_tmp != NULL) | ||
| 572 | RSA_free(cert->rsa_tmp); | ||
| 573 | cert->rsa_tmp=rsa; | ||
| 574 | return(1); | ||
| 575 | } | ||
| 576 | } | ||
| 577 | break; | ||
| 578 | case SSL_CTRL_SET_TMP_RSA_CB: | ||
| 579 | cert->rsa_tmp_cb=(RSA *(*)())parg; | ||
| 580 | break; | ||
| 581 | #endif | ||
| 582 | #ifndef NO_DH | ||
| 583 | case SSL_CTRL_SET_TMP_DH: | ||
| 584 | { | ||
| 585 | DH *new=NULL,*dh; | ||
| 586 | |||
| 587 | dh=(DH *)parg; | ||
| 588 | if ( ((new=DHparams_dup(dh)) == NULL) || | ||
| 589 | (!DH_generate_key(new))) | ||
| 590 | { | ||
| 591 | SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_DH_LIB); | ||
| 592 | if (new != NULL) DH_free(new); | ||
| 593 | return(0); | ||
| 594 | } | ||
| 595 | else | ||
| 596 | { | ||
| 597 | if (cert->dh_tmp != NULL) | ||
| 598 | DH_free(cert->dh_tmp); | ||
| 599 | cert->dh_tmp=new; | ||
| 600 | return(1); | ||
| 601 | } | ||
| 602 | } | ||
| 603 | break; | ||
| 604 | case SSL_CTRL_SET_TMP_DH_CB: | ||
| 605 | cert->dh_tmp_cb=(DH *(*)())parg; | ||
| 606 | break; | ||
| 607 | #endif | ||
| 608 | default: | ||
| 609 | return(0); | ||
| 610 | } | ||
| 611 | return(1); | ||
| 612 | } | ||
| 613 | |||
| 614 | /* This function needs to check if the ciphers required are actually | ||
| 615 | * available */ | ||
| 616 | SSL_CIPHER *ssl3_get_cipher_by_char(p) | ||
| 617 | unsigned char *p; | ||
| 618 | { | ||
| 619 | static int init=1; | ||
| 620 | static SSL_CIPHER *sorted[SSL3_NUM_CIPHERS]; | ||
| 621 | SSL_CIPHER c,*cp= &c,**cpp; | ||
| 622 | unsigned long id; | ||
| 623 | int i; | ||
| 624 | |||
| 625 | if (init) | ||
| 626 | { | ||
| 627 | init=0; | ||
| 628 | |||
| 629 | for (i=0; i<SSL3_NUM_CIPHERS; i++) | ||
| 630 | sorted[i]= &(ssl3_ciphers[i]); | ||
| 631 | |||
| 632 | qsort( (char *)sorted, | ||
| 633 | SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER *), | ||
| 634 | FP_ICC ssl_cipher_ptr_id_cmp); | ||
| 635 | } | ||
| 636 | |||
| 637 | id=0x03000000L|((unsigned long)p[0]<<8L)|(unsigned long)p[1]; | ||
| 638 | c.id=id; | ||
| 639 | cpp=(SSL_CIPHER **)OBJ_bsearch((char *)&cp, | ||
| 640 | (char *)sorted, | ||
| 641 | SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER *), | ||
| 642 | (int (*)())ssl_cipher_ptr_id_cmp); | ||
| 643 | if ((cpp == NULL) || !(*cpp)->valid) | ||
| 644 | return(NULL); | ||
| 645 | else | ||
| 646 | return(*cpp); | ||
| 647 | } | ||
| 648 | |||
| 649 | int ssl3_put_cipher_by_char(c,p) | ||
| 650 | SSL_CIPHER *c; | ||
| 651 | unsigned char *p; | ||
| 652 | { | ||
| 653 | long l; | ||
| 654 | |||
| 655 | if (p != NULL) | ||
| 656 | { | ||
| 657 | l=c->id; | ||
| 658 | if ((l & 0xff000000) != 0x03000000) return(0); | ||
| 659 | p[0]=((unsigned char)(l>> 8L))&0xFF; | ||
| 660 | p[1]=((unsigned char)(l ))&0xFF; | ||
| 661 | } | ||
| 662 | return(2); | ||
| 663 | } | ||
| 664 | |||
| 665 | int ssl3_part_read(s,i) | ||
| 666 | SSL *s; | ||
| 667 | int i; | ||
| 668 | { | ||
| 669 | s->rwstate=SSL_READING; | ||
| 670 | |||
| 671 | if (i < 0) | ||
| 672 | { | ||
| 673 | return(i); | ||
| 674 | } | ||
| 675 | else | ||
| 676 | { | ||
| 677 | s->init_num+=i; | ||
| 678 | return(0); | ||
| 679 | } | ||
| 680 | } | ||
| 681 | |||
| 682 | SSL_CIPHER *ssl3_choose_cipher(s,have,pref) | ||
| 683 | SSL *s; | ||
| 684 | STACK *have,*pref; | ||
| 685 | { | ||
| 686 | SSL_CIPHER *c,*ret=NULL; | ||
| 687 | int i,j,ok; | ||
| 688 | CERT *cert; | ||
| 689 | unsigned long alg,mask,emask; | ||
| 690 | |||
| 691 | /* Lets see which ciphers we can supported */ | ||
| 692 | if (s->cert != NULL) | ||
| 693 | cert=s->cert; | ||
| 694 | else | ||
| 695 | cert=s->ctx->default_cert; | ||
| 696 | |||
| 697 | ssl_set_cert_masks(cert); | ||
| 698 | mask=cert->mask; | ||
| 699 | emask=cert->export_mask; | ||
| 700 | |||
| 701 | sk_set_cmp_func(pref,ssl_cipher_ptr_id_cmp); | ||
| 702 | |||
| 703 | for (i=0; i<sk_num(have); i++) | ||
| 704 | { | ||
| 705 | c=(SSL_CIPHER *)sk_value(have,i); | ||
| 706 | alg=c->algorithms&(SSL_MKEY_MASK|SSL_AUTH_MASK); | ||
| 707 | if (alg & SSL_EXPORT) | ||
| 708 | { | ||
| 709 | ok=((alg & emask) == alg)?1:0; | ||
| 710 | #ifdef CIPHER_DEBUG | ||
| 711 | printf("%d:[%08lX:%08lX]%s\n",ok,alg,mask,c->name); | ||
| 712 | #endif | ||
| 713 | } | ||
| 714 | else | ||
| 715 | { | ||
| 716 | ok=((alg & mask) == alg)?1:0; | ||
| 717 | #ifdef CIPHER_DEBUG | ||
| 718 | printf("%d:[%08lX:%08lX]%s\n",ok,alg,mask,c->name); | ||
| 719 | #endif | ||
| 720 | } | ||
| 721 | |||
| 722 | if (!ok) continue; | ||
| 723 | |||
| 724 | j=sk_find(pref,(char *)c); | ||
| 725 | if (j >= 0) | ||
| 726 | { | ||
| 727 | ret=(SSL_CIPHER *)sk_value(pref,j); | ||
| 728 | break; | ||
| 729 | } | ||
| 730 | } | ||
| 731 | return(ret); | ||
| 732 | } | ||
| 733 | |||
| 734 | int ssl3_get_req_cert_type(s,p) | ||
| 735 | SSL *s; | ||
| 736 | unsigned char *p; | ||
| 737 | { | ||
| 738 | int ret=0; | ||
| 739 | unsigned long alg; | ||
| 740 | |||
| 741 | alg=s->s3->tmp.new_cipher->algorithms; | ||
| 742 | |||
| 743 | #ifndef NO_DH | ||
| 744 | if (alg & (SSL_kDHr|SSL_kEDH)) | ||
| 745 | { | ||
| 746 | #ifndef NO_RSA | ||
| 747 | p[ret++]=SSL3_CT_RSA_FIXED_DH; | ||
| 748 | #endif | ||
| 749 | #ifndef NO_DSA | ||
| 750 | p[ret++]=SSL3_CT_DSS_FIXED_DH; | ||
| 751 | #endif | ||
| 752 | } | ||
| 753 | if ((s->version == SSL3_VERSION) && | ||
| 754 | (alg & (SSL_kEDH|SSL_kDHd|SSL_kDHr))) | ||
| 755 | { | ||
| 756 | #ifndef NO_RSA | ||
| 757 | p[ret++]=SSL3_CT_RSA_EPHEMERAL_DH; | ||
| 758 | #endif | ||
| 759 | #ifndef NO_DSA | ||
| 760 | p[ret++]=SSL3_CT_DSS_EPHEMERAL_DH; | ||
| 761 | #endif | ||
| 762 | } | ||
| 763 | #endif /* !NO_DH */ | ||
| 764 | #ifndef NO_RSA | ||
| 765 | p[ret++]=SSL3_CT_RSA_SIGN; | ||
| 766 | #endif | ||
| 767 | p[ret++]=SSL3_CT_DSS_SIGN; | ||
| 768 | return(ret); | ||
| 769 | } | ||
| 770 | |||
| 771 | int ssl3_shutdown(s) | ||
| 772 | SSL *s; | ||
| 773 | { | ||
| 774 | |||
| 775 | /* Don't do anything much if we have not done the handshake or | ||
| 776 | * we don't want to send messages :-) */ | ||
| 777 | if ((s->quiet_shutdown) || (s->state == SSL_ST_BEFORE)) | ||
| 778 | { | ||
| 779 | s->shutdown=(SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN); | ||
| 780 | return(1); | ||
| 781 | } | ||
| 782 | |||
| 783 | if (!(s->shutdown & SSL_SENT_SHUTDOWN)) | ||
| 784 | { | ||
| 785 | s->shutdown|=SSL_SENT_SHUTDOWN; | ||
| 786 | #if 1 | ||
| 787 | ssl3_send_alert(s,SSL3_AL_WARNING,SSL_AD_CLOSE_NOTIFY); | ||
| 788 | #endif | ||
| 789 | /* our shutdown alert has been sent now, and if it still needs | ||
| 790 | * to be written, s->s3->alert_dispatch will be true */ | ||
| 791 | } | ||
| 792 | else if (s->s3->alert_dispatch) | ||
| 793 | { | ||
| 794 | /* resend it if not sent */ | ||
| 795 | #if 1 | ||
| 796 | ssl3_dispatch_alert(s); | ||
| 797 | #endif | ||
| 798 | } | ||
| 799 | else if (!(s->shutdown & SSL_RECEIVED_SHUTDOWN)) | ||
| 800 | { | ||
| 801 | /* If we are waiting for a close from our peer, we are closed */ | ||
| 802 | ssl3_read_bytes(s,0,NULL,0); | ||
| 803 | } | ||
| 804 | |||
| 805 | if ((s->shutdown == (SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN)) && | ||
| 806 | !s->s3->alert_dispatch) | ||
| 807 | return(1); | ||
| 808 | else | ||
| 809 | return(0); | ||
| 810 | } | ||
| 811 | |||
| 812 | int ssl3_write(s,buf,len) | ||
| 813 | SSL *s; | ||
| 814 | char *buf; | ||
| 815 | int len; | ||
| 816 | { | ||
| 817 | int ret,n; | ||
| 818 | BIO *under; | ||
| 819 | |||
| 820 | #if 0 | ||
| 821 | if (s->shutdown & SSL_SEND_SHUTDOWN) | ||
| 822 | { | ||
| 823 | s->rwstate=SSL_NOTHING; | ||
| 824 | return(0); | ||
| 825 | } | ||
| 826 | #endif | ||
| 827 | clear_sys_error(); | ||
| 828 | if (s->s3->renegotiate) ssl3_renegotiate_check(s); | ||
| 829 | |||
| 830 | /* This is an experimental flag that sends the | ||
| 831 | * last handshake message in the same packet as the first | ||
| 832 | * use data - used to see if it helps the TCP protocol during | ||
| 833 | * session-id reuse */ | ||
| 834 | /* The second test is because the buffer may have been removed */ | ||
| 835 | if ((s->s3->flags & SSL3_FLAGS_POP_BUFFER) && (s->wbio == s->bbio)) | ||
| 836 | { | ||
| 837 | /* First time through, we write into the buffer */ | ||
| 838 | if (s->s3->delay_buf_pop_ret == 0) | ||
| 839 | { | ||
| 840 | ret=ssl3_write_bytes(s,SSL3_RT_APPLICATION_DATA, | ||
| 841 | (char *)buf,len); | ||
| 842 | if (ret <= 0) return(ret); | ||
| 843 | |||
| 844 | s->s3->delay_buf_pop_ret=ret; | ||
| 845 | } | ||
| 846 | |||
| 847 | s->rwstate=SSL_WRITING; | ||
| 848 | n=BIO_flush(s->wbio); | ||
| 849 | if (n <= 0) return(n); | ||
| 850 | s->rwstate=SSL_NOTHING; | ||
| 851 | |||
| 852 | /* We have flushed the buffer */ | ||
| 853 | under=BIO_pop(s->wbio); | ||
| 854 | s->wbio=under; | ||
| 855 | BIO_free(s->bbio); | ||
| 856 | s->bbio=NULL; | ||
| 857 | ret=s->s3->delay_buf_pop_ret; | ||
| 858 | s->s3->delay_buf_pop_ret=0; | ||
| 859 | |||
| 860 | s->s3->flags&= ~SSL3_FLAGS_POP_BUFFER; | ||
| 861 | } | ||
| 862 | else | ||
| 863 | { | ||
| 864 | ret=ssl3_write_bytes(s,SSL3_RT_APPLICATION_DATA, | ||
| 865 | (char *)buf,len); | ||
| 866 | if (ret <= 0) return(ret); | ||
| 867 | } | ||
| 868 | |||
| 869 | return(ret); | ||
| 870 | } | ||
| 871 | |||
| 872 | int ssl3_read(s,buf,len) | ||
| 873 | SSL *s; | ||
| 874 | char *buf; | ||
| 875 | int len; | ||
| 876 | { | ||
| 877 | int ret; | ||
| 878 | |||
| 879 | clear_sys_error(); | ||
| 880 | if (s->s3->renegotiate) ssl3_renegotiate_check(s); | ||
| 881 | s->s3->in_read_app_data=1; | ||
| 882 | ret=ssl3_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len); | ||
| 883 | if ((ret == -1) && (s->s3->in_read_app_data == 0)) | ||
| 884 | { | ||
| 885 | ERR_get_error(); /* clear the error */ | ||
| 886 | s->s3->in_read_app_data=0; | ||
| 887 | s->in_handshake++; | ||
| 888 | ret=ssl3_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len); | ||
| 889 | s->in_handshake--; | ||
| 890 | } | ||
| 891 | else | ||
| 892 | s->s3->in_read_app_data=0; | ||
| 893 | |||
| 894 | return(ret); | ||
| 895 | } | ||
| 896 | |||
| 897 | int ssl3_peek(s,buf,len) | ||
| 898 | SSL *s; | ||
| 899 | char *buf; | ||
| 900 | int len; | ||
| 901 | { | ||
| 902 | SSL3_RECORD *rr; | ||
| 903 | int n; | ||
| 904 | |||
| 905 | rr= &(s->s3->rrec); | ||
| 906 | if ((rr->length == 0) || (rr->type != SSL3_RT_APPLICATION_DATA)) | ||
| 907 | { | ||
| 908 | n=ssl3_read(s,buf,1); | ||
| 909 | if (n <= 0) return(n); | ||
| 910 | rr->length++; | ||
| 911 | rr->off--; | ||
| 912 | } | ||
| 913 | |||
| 914 | if ((unsigned int)len > rr->length) | ||
| 915 | n=rr->length; | ||
| 916 | else | ||
| 917 | n=len; | ||
| 918 | memcpy(buf,&(rr->data[rr->off]),(unsigned int)n); | ||
| 919 | return(n); | ||
| 920 | } | ||
| 921 | |||
| 922 | int ssl3_renegotiate(s) | ||
| 923 | SSL *s; | ||
| 924 | { | ||
| 925 | if (s->handshake_func == NULL) | ||
| 926 | return(1); | ||
| 927 | |||
| 928 | if (s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS) | ||
| 929 | return(0); | ||
| 930 | |||
| 931 | s->s3->renegotiate=1; | ||
| 932 | return(1); | ||
| 933 | } | ||
| 934 | |||
| 935 | int ssl3_renegotiate_check(s) | ||
| 936 | SSL *s; | ||
| 937 | { | ||
| 938 | int ret=0; | ||
| 939 | |||
| 940 | if (s->s3->renegotiate) | ||
| 941 | { | ||
| 942 | if ( (s->s3->rbuf.left == 0) && | ||
| 943 | (s->s3->wbuf.left == 0) && | ||
| 944 | !SSL_in_init(s)) | ||
| 945 | { | ||
| 946 | /* | ||
| 947 | if we are the server, and we have sent a 'RENEGOTIATE' message, we | ||
| 948 | need to go to SSL_ST_ACCEPT. | ||
| 949 | */ | ||
| 950 | /* SSL_ST_ACCEPT */ | ||
| 951 | s->state=SSL_ST_RENEGOTIATE; | ||
| 952 | s->s3->renegotiate=0; | ||
| 953 | s->s3->num_renegotiations++; | ||
| 954 | s->s3->total_renegotiations++; | ||
| 955 | ret=1; | ||
| 956 | } | ||
| 957 | } | ||
| 958 | return(ret); | ||
| 959 | } | ||
| 960 | |||
| 961 | |||
diff --git a/src/lib/libssl/s3_pkt.c b/src/lib/libssl/s3_pkt.c new file mode 100644 index 0000000000..2385080347 --- /dev/null +++ b/src/lib/libssl/s3_pkt.c | |||
| @@ -0,0 +1,1061 @@ | |||
| 1 | /* ssl/s3_pkt.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 <errno.h> | ||
| 61 | #define USE_SOCKETS | ||
| 62 | #include "evp.h" | ||
| 63 | #include "buffer.h" | ||
| 64 | #include "ssl_locl.h" | ||
| 65 | |||
| 66 | /* SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CIPHER); | ||
| 67 | * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CERTIFICATE); | ||
| 68 | * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_PEER_ERROR_CERTIFICATE); | ||
| 69 | * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE); | ||
| 70 | * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_UNKNOWN_REMOTE_ERROR_TYPE); | ||
| 71 | * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE); | ||
| 72 | * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_BAD_RECORD_MAC); | ||
| 73 | * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE); | ||
| 74 | * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE); | ||
| 75 | * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_NO_CERTIFICATE); | ||
| 76 | * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_BAD_CERTIFICATE); | ||
| 77 | * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE); | ||
| 78 | * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED); | ||
| 79 | * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED); | ||
| 80 | * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN); | ||
| 81 | * SSLerr(SSL_F_GET_SERVER_HELLO,SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER); | ||
| 82 | */ | ||
| 83 | |||
| 84 | #ifndef NOPROTO | ||
| 85 | static int do_ssl3_write(SSL *s, int type, char *buf, unsigned int len); | ||
| 86 | static int ssl3_write_pending(SSL *s, int type, char *buf, unsigned int len); | ||
| 87 | static int ssl3_get_record(SSL *s); | ||
| 88 | static int do_compress(SSL *ssl); | ||
| 89 | static int do_uncompress(SSL *ssl); | ||
| 90 | static int do_change_cipher_spec(SSL *ssl); | ||
| 91 | #else | ||
| 92 | static int do_ssl3_write(); | ||
| 93 | static int ssl3_write_pending(); | ||
| 94 | static int ssl3_get_record(); | ||
| 95 | static int do_compress(); | ||
| 96 | static int do_uncompress(); | ||
| 97 | static int do_change_cipher_spec(); | ||
| 98 | #endif | ||
| 99 | |||
| 100 | static int ssl3_read_n(s,n,max,extend) | ||
| 101 | SSL *s; | ||
| 102 | int n; | ||
| 103 | int max; | ||
| 104 | int extend; | ||
| 105 | { | ||
| 106 | int i,off,newb; | ||
| 107 | |||
| 108 | /* if there is stuff still in the buffer from a previous read, | ||
| 109 | * and there is more than we want, take some. */ | ||
| 110 | if (s->s3->rbuf.left >= (int)n) | ||
| 111 | { | ||
| 112 | if (extend) | ||
| 113 | s->packet_length+=n; | ||
| 114 | else | ||
| 115 | { | ||
| 116 | s->packet= &(s->s3->rbuf.buf[s->s3->rbuf.offset]); | ||
| 117 | s->packet_length=n; | ||
| 118 | } | ||
| 119 | s->s3->rbuf.left-=n; | ||
| 120 | s->s3->rbuf.offset+=n; | ||
| 121 | return(n); | ||
| 122 | } | ||
| 123 | |||
| 124 | /* else we need to read more data */ | ||
| 125 | if (!s->read_ahead) max=n; | ||
| 126 | if (max > SSL3_RT_MAX_PACKET_SIZE) | ||
| 127 | max=SSL3_RT_MAX_PACKET_SIZE; | ||
| 128 | |||
| 129 | /* First check if there is some left or we want to extend */ | ||
| 130 | off=0; | ||
| 131 | if ( (s->s3->rbuf.left != 0) || | ||
| 132 | ((s->packet_length != 0) && extend)) | ||
| 133 | { | ||
| 134 | newb=s->s3->rbuf.left; | ||
| 135 | if (extend) | ||
| 136 | { | ||
| 137 | /* Copy bytes back to the front of the buffer | ||
| 138 | * Take the bytes already pointed to by 'packet' | ||
| 139 | * and take the extra ones on the end. */ | ||
| 140 | off=s->packet_length; | ||
| 141 | if (s->packet != s->s3->rbuf.buf) | ||
| 142 | memcpy(s->s3->rbuf.buf,s->packet,newb+off); | ||
| 143 | } | ||
| 144 | else if (s->s3->rbuf.offset != 0) | ||
| 145 | { /* so the data is not at the start of the buffer */ | ||
| 146 | memcpy(s->s3->rbuf.buf, | ||
| 147 | &(s->s3->rbuf.buf[s->s3->rbuf.offset]),newb); | ||
| 148 | s->s3->rbuf.offset=0; | ||
| 149 | } | ||
| 150 | |||
| 151 | s->s3->rbuf.left=0; | ||
| 152 | } | ||
| 153 | else | ||
| 154 | newb=0; | ||
| 155 | |||
| 156 | /* So we now have 'newb' bytes at the front of | ||
| 157 | * s->s3->rbuf.buf and need to read some more in on the end | ||
| 158 | * We start reading into the buffer at 's->s3->rbuf.offset' | ||
| 159 | */ | ||
| 160 | s->packet=s->s3->rbuf.buf; | ||
| 161 | |||
| 162 | while (newb < n) | ||
| 163 | { | ||
| 164 | clear_sys_error(); | ||
| 165 | if (s->rbio != NULL) | ||
| 166 | { | ||
| 167 | s->rwstate=SSL_READING; | ||
| 168 | i=BIO_read(s->rbio, | ||
| 169 | (char *)&(s->s3->rbuf.buf[off+newb]), | ||
| 170 | max-newb); | ||
| 171 | } | ||
| 172 | else | ||
| 173 | { | ||
| 174 | SSLerr(SSL_F_SSL3_READ_N,SSL_R_READ_BIO_NOT_SET); | ||
| 175 | i= -1; | ||
| 176 | } | ||
| 177 | |||
| 178 | if (i <= 0) | ||
| 179 | { | ||
| 180 | s->s3->rbuf.left+=newb; | ||
| 181 | return(i); | ||
| 182 | } | ||
| 183 | newb+=i; | ||
| 184 | } | ||
| 185 | |||
| 186 | /* record used data read */ | ||
| 187 | if (newb > n) | ||
| 188 | { | ||
| 189 | s->s3->rbuf.offset=n+off; | ||
| 190 | s->s3->rbuf.left=newb-n; | ||
| 191 | } | ||
| 192 | else | ||
| 193 | { | ||
| 194 | s->s3->rbuf.offset=0; | ||
| 195 | s->s3->rbuf.left=0; | ||
| 196 | } | ||
| 197 | |||
| 198 | if (extend) | ||
| 199 | s->packet_length+=n; | ||
| 200 | else | ||
| 201 | s->packet_length+=n; | ||
| 202 | return(n); | ||
| 203 | } | ||
| 204 | |||
| 205 | /* Call this to get a new input record. | ||
| 206 | * It will return <= 0 if more data is needed, normally due to an error | ||
| 207 | * or non-blocking IO. | ||
| 208 | * When it finishes, one packet has been decoded and can be found in | ||
| 209 | * ssl->s3->rrec.type - is the type of record | ||
| 210 | * ssl->s3->rrec.data, - data | ||
| 211 | * ssl->s3->rrec.length, - number of bytes | ||
| 212 | */ | ||
| 213 | static int ssl3_get_record(s) | ||
| 214 | SSL *s; | ||
| 215 | { | ||
| 216 | char tmp_buf[512]; | ||
| 217 | int ssl_major,ssl_minor,al; | ||
| 218 | int n,i,ret= -1; | ||
| 219 | SSL3_BUFFER *rb; | ||
| 220 | SSL3_RECORD *rr; | ||
| 221 | SSL_SESSION *sess; | ||
| 222 | unsigned char *p; | ||
| 223 | unsigned char md[EVP_MAX_MD_SIZE]; | ||
| 224 | short version; | ||
| 225 | unsigned int mac_size; | ||
| 226 | int clear=0,extra; | ||
| 227 | |||
| 228 | rr= &(s->s3->rrec); | ||
| 229 | rb= &(s->s3->rbuf); | ||
| 230 | sess=s->session; | ||
| 231 | |||
| 232 | if (s->options & SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER) | ||
| 233 | extra=SSL3_RT_MAX_EXTRA; | ||
| 234 | else | ||
| 235 | extra=0; | ||
| 236 | |||
| 237 | again: | ||
| 238 | /* check if we have the header */ | ||
| 239 | if ( (s->rstate != SSL_ST_READ_BODY) || | ||
| 240 | (s->packet_length < SSL3_RT_HEADER_LENGTH)) | ||
| 241 | { | ||
| 242 | n=ssl3_read_n(s,SSL3_RT_HEADER_LENGTH, | ||
| 243 | SSL3_RT_MAX_PACKET_SIZE,0); | ||
| 244 | if (n <= 0) return(n); /* error or non-blocking */ | ||
| 245 | s->rstate=SSL_ST_READ_BODY; | ||
| 246 | |||
| 247 | p=s->packet; | ||
| 248 | |||
| 249 | /* Pull apart the header into the SSL3_RECORD */ | ||
| 250 | rr->type= *(p++); | ||
| 251 | ssl_major= *(p++); | ||
| 252 | ssl_minor= *(p++); | ||
| 253 | version=(ssl_major<<8)|ssl_minor; | ||
| 254 | n2s(p,rr->length); | ||
| 255 | |||
| 256 | /* Lets check version */ | ||
| 257 | if (s->first_packet) | ||
| 258 | { | ||
| 259 | s->first_packet=0; | ||
| 260 | } | ||
| 261 | else | ||
| 262 | { | ||
| 263 | if (version != s->version) | ||
| 264 | { | ||
| 265 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_WRONG_VERSION_NUMBER); | ||
| 266 | /* Send back error using their | ||
| 267 | * version number :-) */ | ||
| 268 | s->version=version; | ||
| 269 | al=SSL_AD_PROTOCOL_VERSION; | ||
| 270 | goto f_err; | ||
| 271 | } | ||
| 272 | } | ||
| 273 | |||
| 274 | if ((version>>8) != SSL3_VERSION_MAJOR) | ||
| 275 | { | ||
| 276 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_WRONG_VERSION_NUMBER); | ||
| 277 | goto err; | ||
| 278 | } | ||
| 279 | |||
| 280 | if (rr->length > | ||
| 281 | (unsigned int)SSL3_RT_MAX_ENCRYPTED_LENGTH+extra) | ||
| 282 | { | ||
| 283 | al=SSL_AD_RECORD_OVERFLOW; | ||
| 284 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_PACKET_LENGTH_TOO_LONG); | ||
| 285 | goto f_err; | ||
| 286 | } | ||
| 287 | |||
| 288 | s->rstate=SSL_ST_READ_BODY; | ||
| 289 | } | ||
| 290 | |||
| 291 | /* get and decode the data */ | ||
| 292 | if (s->rstate == SSL_ST_READ_BODY) | ||
| 293 | { | ||
| 294 | if (rr->length > (s->packet_length-SSL3_RT_HEADER_LENGTH)) | ||
| 295 | { | ||
| 296 | i=rr->length; | ||
| 297 | /*-(s->packet_length-SSL3_RT_HEADER_LENGTH); */ | ||
| 298 | n=ssl3_read_n(s,i,i,1); | ||
| 299 | if (n <= 0) return(n); /* error or non-blocking io */ | ||
| 300 | } | ||
| 301 | s->rstate=SSL_ST_READ_HEADER; | ||
| 302 | } | ||
| 303 | |||
| 304 | /* At this point, we have the data in s->packet and there should be | ||
| 305 | * s->packet_length bytes, we must not 'overrun' this buffer :-) | ||
| 306 | * One of the following functions will copy the data from the | ||
| 307 | * s->packet buffer */ | ||
| 308 | |||
| 309 | rr->input= &(s->packet[SSL3_RT_HEADER_LENGTH]); | ||
| 310 | |||
| 311 | /* ok, we can now read from 's->packet' data into 'rr' | ||
| 312 | * rr->input points at rr->length bytes, which | ||
| 313 | * need to be copied into rr->data by either | ||
| 314 | * the decryption or by the decompression | ||
| 315 | * When the data is 'copied' into the rr->data buffer, | ||
| 316 | * rr->input will be pointed at the new buffer */ | ||
| 317 | |||
| 318 | /* Set the state for the following operations */ | ||
| 319 | s->rstate=SSL_ST_READ_HEADER; | ||
| 320 | |||
| 321 | /* We now have - encrypted [ MAC [ compressed [ plain ] ] ] | ||
| 322 | * rr->length bytes of encrypted compressed stuff. */ | ||
| 323 | |||
| 324 | /* check is not needed I belive */ | ||
| 325 | if (rr->length > (unsigned int)SSL3_RT_MAX_ENCRYPTED_LENGTH+extra) | ||
| 326 | { | ||
| 327 | al=SSL_AD_RECORD_OVERFLOW; | ||
| 328 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_ENCRYPTED_LENGTH_TOO_LONG); | ||
| 329 | goto f_err; | ||
| 330 | } | ||
| 331 | |||
| 332 | /* decrypt in place in 'rr->input' */ | ||
| 333 | rr->data=rr->input; | ||
| 334 | memcpy(tmp_buf,rr->input,(rr->length > 512)?512:rr->length); | ||
| 335 | |||
| 336 | if (!s->method->ssl3_enc->enc(s,0)) | ||
| 337 | { | ||
| 338 | al=SSL_AD_DECRYPT_ERROR; | ||
| 339 | goto f_err; | ||
| 340 | } | ||
| 341 | #ifdef TLS_DEBUG | ||
| 342 | printf("dec %d\n",rr->length); | ||
| 343 | { int z; for (z=0; z<rr->length; z++) printf("%02X%c",rr->data[z],((z+1)%16)?' ':'\n'); } | ||
| 344 | printf("\n"); | ||
| 345 | #endif | ||
| 346 | /* r->length is now the compressed data plus mac */ | ||
| 347 | if ( (sess == NULL) || | ||
| 348 | (s->enc_read_ctx == NULL) || | ||
| 349 | (s->read_hash == NULL)) | ||
| 350 | clear=1; | ||
| 351 | |||
| 352 | if (!clear) | ||
| 353 | { | ||
| 354 | mac_size=EVP_MD_size(s->read_hash); | ||
| 355 | |||
| 356 | if (rr->length > SSL3_RT_MAX_COMPRESSED_LENGTH+extra+mac_size) | ||
| 357 | { | ||
| 358 | al=SSL_AD_RECORD_OVERFLOW; | ||
| 359 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_PRE_MAC_LENGTH_TOO_LONG); | ||
| 360 | goto f_err; | ||
| 361 | } | ||
| 362 | /* check MAC for rr->input' */ | ||
| 363 | if (rr->length < mac_size) | ||
| 364 | { | ||
| 365 | al=SSL_AD_DECODE_ERROR; | ||
| 366 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_LENGTH_TOO_SHORT); | ||
| 367 | goto f_err; | ||
| 368 | } | ||
| 369 | rr->length-=mac_size; | ||
| 370 | i=s->method->ssl3_enc->mac(s,md,0); | ||
| 371 | if (memcmp(md,&(rr->data[rr->length]),mac_size) != 0) | ||
| 372 | { | ||
| 373 | al=SSL_AD_BAD_RECORD_MAC; | ||
| 374 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_BAD_MAC_DECODE); | ||
| 375 | ret= -1; | ||
| 376 | goto f_err; | ||
| 377 | } | ||
| 378 | } | ||
| 379 | |||
| 380 | /* r->length is now just compressed */ | ||
| 381 | if ((sess != NULL) && (sess->read_compression != NULL)) | ||
| 382 | { | ||
| 383 | if (rr->length > | ||
| 384 | (unsigned int)SSL3_RT_MAX_COMPRESSED_LENGTH+extra) | ||
| 385 | { | ||
| 386 | al=SSL_AD_RECORD_OVERFLOW; | ||
| 387 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_COMPRESSED_LENGTH_TOO_LONG); | ||
| 388 | goto f_err; | ||
| 389 | } | ||
| 390 | if (!do_uncompress(s)) | ||
| 391 | { | ||
| 392 | al=SSL_AD_DECOMPRESSION_FAILURE; | ||
| 393 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_BAD_DECOMPRESSION); | ||
| 394 | goto f_err; | ||
| 395 | } | ||
| 396 | } | ||
| 397 | |||
| 398 | if (rr->length > (unsigned int)SSL3_RT_MAX_PLAIN_LENGTH+extra) | ||
| 399 | { | ||
| 400 | al=SSL_AD_RECORD_OVERFLOW; | ||
| 401 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_DATA_LENGTH_TOO_LONG); | ||
| 402 | goto f_err; | ||
| 403 | } | ||
| 404 | |||
| 405 | rr->off=0; | ||
| 406 | /* So at this point the following is true | ||
| 407 | * ssl->s3->rrec.type is the type of record | ||
| 408 | * ssl->s3->rrec.length == number of bytes in record | ||
| 409 | * ssl->s3->rrec.off == offset to first valid byte | ||
| 410 | * ssl->s3->rrec.data == where to take bytes from, increment | ||
| 411 | * after use :-). | ||
| 412 | */ | ||
| 413 | |||
| 414 | /* we have pulled in a full packet so zero things */ | ||
| 415 | s->packet_length=0; | ||
| 416 | |||
| 417 | /* just read a 0 length packet */ | ||
| 418 | if (rr->length == 0) goto again; | ||
| 419 | |||
| 420 | return(1); | ||
| 421 | f_err: | ||
| 422 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
| 423 | err: | ||
| 424 | return(ret); | ||
| 425 | } | ||
| 426 | |||
| 427 | static int do_uncompress(ssl) | ||
| 428 | SSL *ssl; | ||
| 429 | { | ||
| 430 | return(1); | ||
| 431 | } | ||
| 432 | |||
| 433 | static int do_compress(ssl) | ||
| 434 | SSL *ssl; | ||
| 435 | { | ||
| 436 | return(1); | ||
| 437 | } | ||
| 438 | |||
| 439 | /* Call this to write data | ||
| 440 | * It will return <= 0 if not all data has been sent or non-blocking IO. | ||
| 441 | */ | ||
| 442 | int ssl3_write_bytes(s,type,buf,len) | ||
| 443 | SSL *s; | ||
| 444 | int type; | ||
| 445 | char *buf; | ||
| 446 | int len; | ||
| 447 | { | ||
| 448 | unsigned int tot,n,nw; | ||
| 449 | int i; | ||
| 450 | |||
| 451 | s->rwstate=SSL_NOTHING; | ||
| 452 | tot=s->s3->wnum; | ||
| 453 | s->s3->wnum=0; | ||
| 454 | |||
| 455 | if (SSL_in_init(s) && !s->in_handshake) | ||
| 456 | { | ||
| 457 | i=s->handshake_func(s); | ||
| 458 | if (i < 0) return(i); | ||
| 459 | if (i == 0) | ||
| 460 | { | ||
| 461 | SSLerr(SSL_F_SSL3_WRITE_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE); | ||
| 462 | return(-1); | ||
| 463 | } | ||
| 464 | } | ||
| 465 | |||
| 466 | n=(len-tot); | ||
| 467 | for (;;) | ||
| 468 | { | ||
| 469 | if (n > SSL3_RT_MAX_PLAIN_LENGTH) | ||
| 470 | nw=SSL3_RT_MAX_PLAIN_LENGTH; | ||
| 471 | else | ||
| 472 | nw=n; | ||
| 473 | |||
| 474 | i=do_ssl3_write(s,type,&(buf[tot]),nw); | ||
| 475 | if (i <= 0) | ||
| 476 | { | ||
| 477 | s->s3->wnum=tot; | ||
| 478 | return(i); | ||
| 479 | } | ||
| 480 | |||
| 481 | if (type == SSL3_RT_HANDSHAKE) | ||
| 482 | ssl3_finish_mac(s,(unsigned char *)&(buf[tot]),i); | ||
| 483 | |||
| 484 | if (i == (int)n) return(tot+i); | ||
| 485 | |||
| 486 | n-=i; | ||
| 487 | tot+=i; | ||
| 488 | } | ||
| 489 | } | ||
| 490 | |||
| 491 | static int do_ssl3_write(s,type,buf,len) | ||
| 492 | SSL *s; | ||
| 493 | int type; | ||
| 494 | char *buf; | ||
| 495 | unsigned int len; | ||
| 496 | { | ||
| 497 | unsigned char *p,*plen; | ||
| 498 | int i,mac_size,clear=0; | ||
| 499 | SSL3_RECORD *wr; | ||
| 500 | SSL3_BUFFER *wb; | ||
| 501 | SSL_SESSION *sess; | ||
| 502 | |||
| 503 | /* first check is there is a SSL3_RECORD still being written | ||
| 504 | * out. This will happen with non blocking IO */ | ||
| 505 | if (s->s3->wbuf.left != 0) | ||
| 506 | return(ssl3_write_pending(s,type,buf,len)); | ||
| 507 | |||
| 508 | /* If we have an alert to send, lets send it */ | ||
| 509 | if (s->s3->alert_dispatch) | ||
| 510 | { | ||
| 511 | i=ssl3_dispatch_alert(s); | ||
| 512 | if (i <= 0) | ||
| 513 | return(i); | ||
| 514 | /* if it went, fall through and send more stuff */ | ||
| 515 | } | ||
| 516 | |||
| 517 | if (len <= 0) return(len); | ||
| 518 | |||
| 519 | wr= &(s->s3->wrec); | ||
| 520 | wb= &(s->s3->wbuf); | ||
| 521 | sess=s->session; | ||
| 522 | |||
| 523 | if ( (sess == NULL) || | ||
| 524 | (s->enc_write_ctx == NULL) || | ||
| 525 | (s->write_hash == NULL)) | ||
| 526 | clear=1; | ||
| 527 | |||
| 528 | if (clear) | ||
| 529 | mac_size=0; | ||
| 530 | else | ||
| 531 | mac_size=EVP_MD_size(s->write_hash); | ||
| 532 | |||
| 533 | p=wb->buf; | ||
| 534 | |||
| 535 | /* write the header */ | ||
| 536 | *(p++)=type&0xff; | ||
| 537 | wr->type=type; | ||
| 538 | |||
| 539 | *(p++)=(s->version>>8); | ||
| 540 | *(p++)=s->version&0xff; | ||
| 541 | |||
| 542 | /* record where we are to write out packet length */ | ||
| 543 | plen=p; | ||
| 544 | p+=2; | ||
| 545 | |||
| 546 | /* lets setup the record stuff. */ | ||
| 547 | wr->data=p; | ||
| 548 | wr->length=(int)len; | ||
| 549 | wr->input=(unsigned char *)buf; | ||
| 550 | |||
| 551 | /* we now 'read' from wr->input, wr->length bytes into | ||
| 552 | * wr->data */ | ||
| 553 | |||
| 554 | /* first we compress */ | ||
| 555 | if ((sess != NULL) && (sess->write_compression != NULL)) | ||
| 556 | { | ||
| 557 | if (!do_compress(s)) | ||
| 558 | { | ||
| 559 | SSLerr(SSL_F_DO_SSL3_WRITE,SSL_R_COMPRESSION_FAILURE); | ||
| 560 | goto err; | ||
| 561 | } | ||
| 562 | } | ||
| 563 | else | ||
| 564 | { | ||
| 565 | memcpy(wr->data,wr->input,wr->length); | ||
| 566 | wr->input=wr->data; | ||
| 567 | } | ||
| 568 | |||
| 569 | /* we should still have the output to wr->data and the input | ||
| 570 | * from wr->input. Length should be wr->length. | ||
| 571 | * wr->data still points in the wb->buf */ | ||
| 572 | |||
| 573 | if (mac_size != 0) | ||
| 574 | { | ||
| 575 | s->method->ssl3_enc->mac(s,&(p[wr->length]),1); | ||
| 576 | wr->length+=mac_size; | ||
| 577 | wr->input=p; | ||
| 578 | wr->data=p; | ||
| 579 | } | ||
| 580 | |||
| 581 | /* ssl3_enc can only have an error on read */ | ||
| 582 | s->method->ssl3_enc->enc(s,1); | ||
| 583 | |||
| 584 | /* record length after mac and block padding */ | ||
| 585 | s2n(wr->length,plen); | ||
| 586 | |||
| 587 | /* we should now have | ||
| 588 | * wr->data pointing to the encrypted data, which is | ||
| 589 | * wr->length long */ | ||
| 590 | wr->type=type; /* not needed but helps for debugging */ | ||
| 591 | wr->length+=SSL3_RT_HEADER_LENGTH; | ||
| 592 | |||
| 593 | /* Now lets setup wb */ | ||
| 594 | wb->left=wr->length; | ||
| 595 | wb->offset=0; | ||
| 596 | |||
| 597 | s->s3->wpend_tot=len; | ||
| 598 | s->s3->wpend_buf=buf; | ||
| 599 | s->s3->wpend_type=type; | ||
| 600 | s->s3->wpend_ret=len; | ||
| 601 | |||
| 602 | /* we now just need to write the buffer */ | ||
| 603 | return(ssl3_write_pending(s,type,buf,len)); | ||
| 604 | err: | ||
| 605 | return(-1); | ||
| 606 | } | ||
| 607 | |||
| 608 | /* if s->s3->wbuf.left != 0, we need to call this */ | ||
| 609 | static int ssl3_write_pending(s,type,buf,len) | ||
| 610 | SSL *s; | ||
| 611 | int type; | ||
| 612 | char *buf; | ||
| 613 | unsigned int len; | ||
| 614 | { | ||
| 615 | int i; | ||
| 616 | |||
| 617 | /* XXXX */ | ||
| 618 | if ((s->s3->wpend_tot > (int)len) || (s->s3->wpend_buf != buf) | ||
| 619 | || (s->s3->wpend_type != type)) | ||
| 620 | { | ||
| 621 | SSLerr(SSL_F_SSL3_WRITE_PENDING,SSL_R_BAD_WRITE_RETRY); | ||
| 622 | return(-1); | ||
| 623 | } | ||
| 624 | |||
| 625 | for (;;) | ||
| 626 | { | ||
| 627 | clear_sys_error(); | ||
| 628 | if (s->wbio != NULL) | ||
| 629 | { | ||
| 630 | s->rwstate=SSL_WRITING; | ||
| 631 | i=BIO_write(s->wbio, | ||
| 632 | (char *)&(s->s3->wbuf.buf[s->s3->wbuf.offset]), | ||
| 633 | (unsigned int)s->s3->wbuf.left); | ||
| 634 | } | ||
| 635 | else | ||
| 636 | { | ||
| 637 | SSLerr(SSL_F_SSL3_WRITE_PENDING,SSL_R_BIO_NOT_SET); | ||
| 638 | i= -1; | ||
| 639 | } | ||
| 640 | if (i == s->s3->wbuf.left) | ||
| 641 | { | ||
| 642 | s->s3->wbuf.left=0; | ||
| 643 | s->rwstate=SSL_NOTHING; | ||
| 644 | return(s->s3->wpend_ret); | ||
| 645 | } | ||
| 646 | else if (i <= 0) | ||
| 647 | return(i); | ||
| 648 | s->s3->wbuf.offset+=i; | ||
| 649 | s->s3->wbuf.left-=i; | ||
| 650 | } | ||
| 651 | } | ||
| 652 | |||
| 653 | int ssl3_read_bytes(s,type,buf,len) | ||
| 654 | SSL *s; | ||
| 655 | int type; | ||
| 656 | char *buf; | ||
| 657 | int len; | ||
| 658 | { | ||
| 659 | int al,i,j,n,ret; | ||
| 660 | SSL3_RECORD *rr; | ||
| 661 | void (*cb)()=NULL; | ||
| 662 | BIO *bio; | ||
| 663 | |||
| 664 | if (s->s3->rbuf.buf == NULL) /* Not initalised yet */ | ||
| 665 | if (!ssl3_setup_buffers(s)) | ||
| 666 | return(-1); | ||
| 667 | |||
| 668 | if (!s->in_handshake && SSL_in_init(s)) | ||
| 669 | { | ||
| 670 | i=s->handshake_func(s); | ||
| 671 | if (i < 0) return(i); | ||
| 672 | if (i == 0) | ||
| 673 | { | ||
| 674 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE); | ||
| 675 | return(-1); | ||
| 676 | } | ||
| 677 | } | ||
| 678 | start: | ||
| 679 | s->rwstate=SSL_NOTHING; | ||
| 680 | |||
| 681 | /* s->s3->rrec.type - is the type of record | ||
| 682 | * s->s3->rrec.data, - data | ||
| 683 | * s->s3->rrec.off, - ofset into 'data' for next read | ||
| 684 | * s->s3->rrec.length, - number of bytes. */ | ||
| 685 | rr= &(s->s3->rrec); | ||
| 686 | |||
| 687 | /* get new packet */ | ||
| 688 | if ((rr->length == 0) || (s->rstate == SSL_ST_READ_BODY)) | ||
| 689 | { | ||
| 690 | ret=ssl3_get_record(s); | ||
| 691 | if (ret <= 0) return(ret); | ||
| 692 | } | ||
| 693 | |||
| 694 | /* we now have a packet which can be read and processed */ | ||
| 695 | |||
| 696 | if (s->s3->change_cipher_spec && (rr->type != SSL3_RT_HANDSHAKE)) | ||
| 697 | { | ||
| 698 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
| 699 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_DATA_BETWEEN_CCS_AND_FINISHED); | ||
| 700 | goto err; | ||
| 701 | } | ||
| 702 | |||
| 703 | /* If the other end has shutdown, throw anything we read away */ | ||
| 704 | if (s->shutdown & SSL_RECEIVED_SHUTDOWN) | ||
| 705 | { | ||
| 706 | rr->length=0; | ||
| 707 | s->rwstate=SSL_NOTHING; | ||
| 708 | return(0); | ||
| 709 | } | ||
| 710 | |||
| 711 | /* Check for an incoming 'Client Request' message */ | ||
| 712 | if ((rr->type == SSL3_RT_HANDSHAKE) && (rr->length == 4) && | ||
| 713 | (rr->data[0] == SSL3_MT_CLIENT_REQUEST) && | ||
| 714 | (s->session != NULL) && (s->session->cipher != NULL)) | ||
| 715 | { | ||
| 716 | if ((rr->data[1] != 0) || (rr->data[2] != 0) || | ||
| 717 | (rr->data[3] != 0)) | ||
| 718 | { | ||
| 719 | al=SSL_AD_DECODE_ERROR; | ||
| 720 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_BAD_CLIENT_REQUEST); | ||
| 721 | goto err; | ||
| 722 | } | ||
| 723 | |||
| 724 | if (SSL_is_init_finished(s) && | ||
| 725 | !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS) && | ||
| 726 | !s->s3->renegotiate) | ||
| 727 | { | ||
| 728 | ssl3_renegotiate(s); | ||
| 729 | if (ssl3_renegotiate_check(s)) | ||
| 730 | { | ||
| 731 | n=s->handshake_func(s); | ||
| 732 | if (n < 0) return(n); | ||
| 733 | if (n == 0) | ||
| 734 | { | ||
| 735 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE); | ||
| 736 | return(-1); | ||
| 737 | } | ||
| 738 | } | ||
| 739 | } | ||
| 740 | rr->length=0; | ||
| 741 | /* ZZZ */ goto start; | ||
| 742 | } | ||
| 743 | |||
| 744 | /* if it is not the type we want, or we have shutdown and want | ||
| 745 | * the peer shutdown */ | ||
| 746 | if ((rr->type != type) || (s->shutdown & SSL_SENT_SHUTDOWN)) | ||
| 747 | { | ||
| 748 | if (rr->type == SSL3_RT_ALERT) | ||
| 749 | { | ||
| 750 | if ((rr->length != 2) || (rr->off != 0)) | ||
| 751 | { | ||
| 752 | al=SSL_AD_DECODE_ERROR; | ||
| 753 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_BAD_ALERT_RECORD); | ||
| 754 | goto f_err; | ||
| 755 | } | ||
| 756 | |||
| 757 | i=rr->data[0]; | ||
| 758 | n=rr->data[1]; | ||
| 759 | |||
| 760 | /* clear from buffer */ | ||
| 761 | rr->length=0; | ||
| 762 | |||
| 763 | if (s->info_callback != NULL) | ||
| 764 | cb=s->info_callback; | ||
| 765 | else if (s->ctx->info_callback != NULL) | ||
| 766 | cb=s->ctx->info_callback; | ||
| 767 | |||
| 768 | if (cb != NULL) | ||
| 769 | { | ||
| 770 | j=(i<<8)|n; | ||
| 771 | cb(s,SSL_CB_READ_ALERT,j); | ||
| 772 | } | ||
| 773 | |||
| 774 | if (i == 1) | ||
| 775 | { | ||
| 776 | s->s3->warn_alert=n; | ||
| 777 | if (n == SSL_AD_CLOSE_NOTIFY) | ||
| 778 | { | ||
| 779 | s->shutdown|=SSL_RECEIVED_SHUTDOWN; | ||
| 780 | return(0); | ||
| 781 | } | ||
| 782 | } | ||
| 783 | else if (i == 2) | ||
| 784 | { | ||
| 785 | char tmp[16]; | ||
| 786 | |||
| 787 | s->rwstate=SSL_NOTHING; | ||
| 788 | s->s3->fatal_alert=n; | ||
| 789 | SSLerr(SSL_F_SSL3_READ_BYTES,1000+n); | ||
| 790 | sprintf(tmp,"%d",n); | ||
| 791 | ERR_add_error_data(2,"SSL alert number ",tmp); | ||
| 792 | s->shutdown|=SSL_RECEIVED_SHUTDOWN; | ||
| 793 | SSL_CTX_remove_session(s->ctx,s->session); | ||
| 794 | return(0); | ||
| 795 | } | ||
| 796 | else | ||
| 797 | { | ||
| 798 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
| 799 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNKNOWN_ALERT_TYPE); | ||
| 800 | goto f_err; | ||
| 801 | } | ||
| 802 | |||
| 803 | rr->length=0; | ||
| 804 | goto start; | ||
| 805 | } | ||
| 806 | |||
| 807 | if (s->shutdown & SSL_SENT_SHUTDOWN) | ||
| 808 | { | ||
| 809 | s->rwstate=SSL_NOTHING; | ||
| 810 | rr->length=0; | ||
| 811 | return(0); | ||
| 812 | } | ||
| 813 | |||
| 814 | if (rr->type == SSL3_RT_CHANGE_CIPHER_SPEC) | ||
| 815 | { | ||
| 816 | if ( (rr->length != 1) || (rr->off != 0) || | ||
| 817 | (rr->data[0] != SSL3_MT_CCS)) | ||
| 818 | { | ||
| 819 | i=SSL_AD_ILLEGAL_PARAMETER; | ||
| 820 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_BAD_CHANGE_CIPHER_SPEC); | ||
| 821 | goto err; | ||
| 822 | } | ||
| 823 | |||
| 824 | rr->length=0; | ||
| 825 | s->s3->change_cipher_spec=1; | ||
| 826 | if (!do_change_cipher_spec(s)) | ||
| 827 | goto err; | ||
| 828 | else | ||
| 829 | goto start; | ||
| 830 | } | ||
| 831 | |||
| 832 | /* else we have a handshake */ | ||
| 833 | if ((rr->type == SSL3_RT_HANDSHAKE) && | ||
| 834 | !s->in_handshake) | ||
| 835 | { | ||
| 836 | if (((s->state&SSL_ST_MASK) == SSL_ST_OK) && | ||
| 837 | !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS)) | ||
| 838 | { | ||
| 839 | s->state=SSL_ST_BEFORE; | ||
| 840 | s->new_session=1; | ||
| 841 | } | ||
| 842 | n=s->handshake_func(s); | ||
| 843 | if (n < 0) return(n); | ||
| 844 | if (n == 0) | ||
| 845 | { | ||
| 846 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE); | ||
| 847 | return(-1); | ||
| 848 | } | ||
| 849 | |||
| 850 | /* In the case where we try to read application data | ||
| 851 | * the first time, but we trigger an SSL handshake, we | ||
| 852 | * return -1 with the retry option set. I do this | ||
| 853 | * otherwise renegotiation can cause nasty problems | ||
| 854 | * in the non-blocking world */ | ||
| 855 | |||
| 856 | s->rwstate=SSL_READING; | ||
| 857 | bio=SSL_get_rbio(s); | ||
| 858 | BIO_clear_retry_flags(bio); | ||
| 859 | BIO_set_retry_read(bio); | ||
| 860 | return(-1); | ||
| 861 | } | ||
| 862 | |||
| 863 | switch (rr->type) | ||
| 864 | { | ||
| 865 | default: | ||
| 866 | #ifndef NO_TLS | ||
| 867 | /* TLS just ignores unknown message types */ | ||
| 868 | if (s->version == TLS1_VERSION) | ||
| 869 | { | ||
| 870 | goto start; | ||
| 871 | } | ||
| 872 | #endif | ||
| 873 | case SSL3_RT_CHANGE_CIPHER_SPEC: | ||
| 874 | case SSL3_RT_ALERT: | ||
| 875 | case SSL3_RT_HANDSHAKE: | ||
| 876 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
| 877 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNEXPECTED_RECORD); | ||
| 878 | goto f_err; | ||
| 879 | case SSL3_RT_APPLICATION_DATA: | ||
| 880 | /* At this point, we were expecting something else, | ||
| 881 | * but have application data. What we do is set the | ||
| 882 | * error, and return -1. On the way out, if the | ||
| 883 | * library was running inside ssl3_read() and it makes | ||
| 884 | * sense to read application data at this point, we | ||
| 885 | * will indulge it. This will mostly happen during | ||
| 886 | * session renegotiation. | ||
| 887 | */ | ||
| 888 | if (s->s3->in_read_app_data && | ||
| 889 | (s->s3->total_renegotiations != 0) && | ||
| 890 | (( | ||
| 891 | (s->state & SSL_ST_CONNECT) && | ||
| 892 | (s->state >= SSL3_ST_CW_CLNT_HELLO_A) && | ||
| 893 | (s->state <= SSL3_ST_CR_SRVR_HELLO_A) | ||
| 894 | ) || ( | ||
| 895 | (s->state & SSL_ST_ACCEPT) && | ||
| 896 | (s->state <= SSL3_ST_SW_HELLO_REQ_A) && | ||
| 897 | (s->state >= SSL3_ST_SR_CLNT_HELLO_A) | ||
| 898 | ) | ||
| 899 | )) | ||
| 900 | { | ||
| 901 | s->s3->in_read_app_data=0; | ||
| 902 | return(-1); | ||
| 903 | } | ||
| 904 | else | ||
| 905 | { | ||
| 906 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
| 907 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNEXPECTED_RECORD); | ||
| 908 | goto f_err; | ||
| 909 | } | ||
| 910 | } | ||
| 911 | } | ||
| 912 | |||
| 913 | /* make sure that we are not getting application data when we | ||
| 914 | * are doing a handshake for the first time */ | ||
| 915 | if (SSL_in_init(s) && (type == SSL3_RT_APPLICATION_DATA) && | ||
| 916 | (s->enc_read_ctx == NULL)) | ||
| 917 | { | ||
| 918 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
| 919 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_APP_DATA_IN_HANDSHAKE); | ||
| 920 | goto f_err; | ||
| 921 | } | ||
| 922 | |||
| 923 | if (len <= 0) return(len); | ||
| 924 | |||
| 925 | if ((unsigned int)len > rr->length) | ||
| 926 | n=rr->length; | ||
| 927 | else | ||
| 928 | n=len; | ||
| 929 | |||
| 930 | memcpy(buf,&(rr->data[rr->off]),(unsigned int)n); | ||
| 931 | rr->length-=n; | ||
| 932 | rr->off+=n; | ||
| 933 | if (rr->length <= 0) | ||
| 934 | { | ||
| 935 | s->rstate=SSL_ST_READ_HEADER; | ||
| 936 | rr->off=0; | ||
| 937 | } | ||
| 938 | |||
| 939 | if (type == SSL3_RT_HANDSHAKE) | ||
| 940 | ssl3_finish_mac(s,(unsigned char *)buf,n); | ||
| 941 | return(n); | ||
| 942 | f_err: | ||
| 943 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
| 944 | err: | ||
| 945 | return(-1); | ||
| 946 | } | ||
| 947 | |||
| 948 | static int do_change_cipher_spec(s) | ||
| 949 | SSL *s; | ||
| 950 | { | ||
| 951 | int i; | ||
| 952 | unsigned char *sender; | ||
| 953 | int slen; | ||
| 954 | |||
| 955 | if (s->state & SSL_ST_ACCEPT) | ||
| 956 | i=SSL3_CHANGE_CIPHER_SERVER_READ; | ||
| 957 | else | ||
| 958 | i=SSL3_CHANGE_CIPHER_CLIENT_READ; | ||
| 959 | |||
| 960 | if (s->s3->tmp.key_block == NULL) | ||
| 961 | { | ||
| 962 | s->session->cipher=s->s3->tmp.new_cipher; | ||
| 963 | if (!s->method->ssl3_enc->setup_key_block(s)) return(0); | ||
| 964 | } | ||
| 965 | |||
| 966 | if (!s->method->ssl3_enc->change_cipher_state(s,i)) | ||
| 967 | return(0); | ||
| 968 | |||
| 969 | /* we have to record the message digest at | ||
| 970 | * this point so we can get it before we read | ||
| 971 | * the finished message */ | ||
| 972 | if (s->state & SSL_ST_CONNECT) | ||
| 973 | { | ||
| 974 | sender=s->method->ssl3_enc->server_finished; | ||
| 975 | slen=s->method->ssl3_enc->server_finished_len; | ||
| 976 | } | ||
| 977 | else | ||
| 978 | { | ||
| 979 | sender=s->method->ssl3_enc->client_finished; | ||
| 980 | slen=s->method->ssl3_enc->client_finished_len; | ||
| 981 | } | ||
| 982 | |||
| 983 | s->method->ssl3_enc->final_finish_mac(s, | ||
| 984 | &(s->s3->finish_dgst1), | ||
| 985 | &(s->s3->finish_dgst2), | ||
| 986 | sender,slen,&(s->s3->tmp.finish_md[0])); | ||
| 987 | |||
| 988 | return(1); | ||
| 989 | } | ||
| 990 | |||
| 991 | int ssl3_do_write(s,type) | ||
| 992 | SSL *s; | ||
| 993 | int type; | ||
| 994 | { | ||
| 995 | int ret; | ||
| 996 | |||
| 997 | ret=ssl3_write_bytes(s,type,(char *) | ||
| 998 | &(s->init_buf->data[s->init_off]),s->init_num); | ||
| 999 | if (ret == s->init_num) | ||
| 1000 | return(1); | ||
| 1001 | if (ret < 0) return(-1); | ||
| 1002 | s->init_off+=ret; | ||
| 1003 | s->init_num-=ret; | ||
| 1004 | return(0); | ||
| 1005 | } | ||
| 1006 | |||
| 1007 | void ssl3_send_alert(s,level,desc) | ||
| 1008 | SSL *s; | ||
| 1009 | int level; | ||
| 1010 | int desc; | ||
| 1011 | { | ||
| 1012 | /* Map tls/ssl alert value to correct one */ | ||
| 1013 | desc=s->method->ssl3_enc->alert_value(desc); | ||
| 1014 | if (desc < 0) return; | ||
| 1015 | /* If a fatal one, remove from cache */ | ||
| 1016 | if ((level == 2) && (s->session != NULL)) | ||
| 1017 | SSL_CTX_remove_session(s->ctx,s->session); | ||
| 1018 | |||
| 1019 | s->s3->alert_dispatch=1; | ||
| 1020 | s->s3->send_alert[0]=level; | ||
| 1021 | s->s3->send_alert[1]=desc; | ||
| 1022 | if (s->s3->wbuf.left == 0) /* data still being written out */ | ||
| 1023 | ssl3_dispatch_alert(s); | ||
| 1024 | /* else data is still being written out, we will get written | ||
| 1025 | * some time in the future */ | ||
| 1026 | } | ||
| 1027 | |||
| 1028 | int ssl3_dispatch_alert(s) | ||
| 1029 | SSL *s; | ||
| 1030 | { | ||
| 1031 | int i,j; | ||
| 1032 | void (*cb)()=NULL; | ||
| 1033 | |||
| 1034 | s->s3->alert_dispatch=0; | ||
| 1035 | i=do_ssl3_write(s,SSL3_RT_ALERT,&(s->s3->send_alert[0]),2); | ||
| 1036 | if (i <= 0) | ||
| 1037 | { | ||
| 1038 | s->s3->alert_dispatch=1; | ||
| 1039 | } | ||
| 1040 | else | ||
| 1041 | { | ||
| 1042 | /* If it is important, send it now. If the message | ||
| 1043 | * does not get sent due to non-blocking IO, we will | ||
| 1044 | * not worry too much. */ | ||
| 1045 | if (s->s3->send_alert[0] == SSL3_AL_FATAL) | ||
| 1046 | BIO_flush(s->wbio); | ||
| 1047 | |||
| 1048 | if (s->info_callback != NULL) | ||
| 1049 | cb=s->info_callback; | ||
| 1050 | else if (s->ctx->info_callback != NULL) | ||
| 1051 | cb=s->ctx->info_callback; | ||
| 1052 | |||
| 1053 | if (cb != NULL) | ||
| 1054 | { | ||
| 1055 | j=(s->s3->send_alert[0]<<8)|s->s3->send_alert[1]; | ||
| 1056 | cb(s,SSL_CB_WRITE_ALERT,j); | ||
| 1057 | } | ||
| 1058 | } | ||
| 1059 | return(i); | ||
| 1060 | } | ||
| 1061 | |||
diff --git a/src/lib/libssl/s3_srvr.c b/src/lib/libssl/s3_srvr.c new file mode 100644 index 0000000000..64903af151 --- /dev/null +++ b/src/lib/libssl/s3_srvr.c | |||
| @@ -0,0 +1,1675 @@ | |||
| 1 | /* ssl/s3_srvr.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 | #define REUSE_CIPHER_BUG | ||
| 60 | |||
| 61 | #include <stdio.h> | ||
| 62 | #include "buffer.h" | ||
| 63 | #include "rand.h" | ||
| 64 | #include "objects.h" | ||
| 65 | #include "evp.h" | ||
| 66 | #include "x509.h" | ||
| 67 | #include "ssl_locl.h" | ||
| 68 | |||
| 69 | #define BREAK break | ||
| 70 | /* SSLerr(SSL_F_SSL3_ACCEPT,ERR_R_MALLOC_FAILURE); | ||
| 71 | * SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,ERR_R_MALLOC_FAILURE); | ||
| 72 | * SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE); | ||
| 73 | * SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,ERR_R_MALLOC_FAILURE); | ||
| 74 | * SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_MALLOC_FAILURE); | ||
| 75 | */ | ||
| 76 | |||
| 77 | #ifndef NOPROTO | ||
| 78 | static int ssl3_get_client_hello(SSL *s); | ||
| 79 | static int ssl3_send_server_hello(SSL *s); | ||
| 80 | static int ssl3_send_server_key_exchange(SSL *s); | ||
| 81 | static int ssl3_send_certificate_request(SSL *s); | ||
| 82 | static int ssl3_send_server_done(SSL *s); | ||
| 83 | static int ssl3_get_cert_verify(SSL *s); | ||
| 84 | static int ssl3_get_client_key_exchange(SSL *s); | ||
| 85 | static int ssl3_get_client_certificate(SSL *s); | ||
| 86 | static int ssl3_send_hello_request(SSL *s); | ||
| 87 | |||
| 88 | #else | ||
| 89 | |||
| 90 | static int ssl3_get_client_hello(); | ||
| 91 | static int ssl3_send_server_hello(); | ||
| 92 | static int ssl3_send_server_key_exchange(); | ||
| 93 | static int ssl3_send_certificate_request(); | ||
| 94 | static int ssl3_send_server_done(); | ||
| 95 | static int ssl3_get_cert_verify(); | ||
| 96 | static int ssl3_get_client_key_exchange(); | ||
| 97 | static int ssl3_get_client_certificate(); | ||
| 98 | static int ssl3_send_hello_request(); | ||
| 99 | |||
| 100 | #endif | ||
| 101 | |||
| 102 | static SSL_METHOD *ssl3_get_server_method(ver) | ||
| 103 | int ver; | ||
| 104 | { | ||
| 105 | if (ver == SSL3_VERSION) | ||
| 106 | return(SSLv3_server_method()); | ||
| 107 | else | ||
| 108 | return(NULL); | ||
| 109 | } | ||
| 110 | |||
| 111 | SSL_METHOD *SSLv3_server_method() | ||
| 112 | { | ||
| 113 | static int init=1; | ||
| 114 | static SSL_METHOD SSLv3_server_data; | ||
| 115 | |||
| 116 | if (init) | ||
| 117 | { | ||
| 118 | init=0; | ||
| 119 | memcpy((char *)&SSLv3_server_data,(char *)sslv3_base_method(), | ||
| 120 | sizeof(SSL_METHOD)); | ||
| 121 | SSLv3_server_data.ssl_accept=ssl3_accept; | ||
| 122 | SSLv3_server_data.get_ssl_method=ssl3_get_server_method; | ||
| 123 | } | ||
| 124 | return(&SSLv3_server_data); | ||
| 125 | } | ||
| 126 | |||
| 127 | int ssl3_accept(s) | ||
| 128 | SSL *s; | ||
| 129 | { | ||
| 130 | BUF_MEM *buf; | ||
| 131 | unsigned long l,Time=time(NULL); | ||
| 132 | void (*cb)()=NULL; | ||
| 133 | long num1; | ||
| 134 | int ret= -1; | ||
| 135 | CERT *ct; | ||
| 136 | BIO *under; | ||
| 137 | int new_state,state,skip=0; | ||
| 138 | |||
| 139 | RAND_seed((unsigned char *)&Time,sizeof(Time)); | ||
| 140 | ERR_clear_error(); | ||
| 141 | clear_sys_error(); | ||
| 142 | |||
| 143 | if (s->info_callback != NULL) | ||
| 144 | cb=s->info_callback; | ||
| 145 | else if (s->ctx->info_callback != NULL) | ||
| 146 | cb=s->ctx->info_callback; | ||
| 147 | |||
| 148 | /* init things to blank */ | ||
| 149 | if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s); | ||
| 150 | s->in_handshake++; | ||
| 151 | |||
| 152 | #ifdef undef | ||
| 153 | /* FIX THIS EAY EAY EAY */ | ||
| 154 | /* we don't actually need a cert, we just need a cert or a DH_tmp */ | ||
| 155 | if (((s->session == NULL) || (s->session->cert == NULL)) && | ||
| 156 | (s->cert == NULL)) | ||
| 157 | { | ||
| 158 | SSLerr(SSL_F_SSL3_ACCEPT,SSL_R_NO_CERTIFICATE_SET); | ||
| 159 | ret= -1; | ||
| 160 | goto end; | ||
| 161 | } | ||
| 162 | #endif | ||
| 163 | |||
| 164 | for (;;) | ||
| 165 | { | ||
| 166 | state=s->state; | ||
| 167 | |||
| 168 | switch (s->state) | ||
| 169 | { | ||
| 170 | case SSL_ST_RENEGOTIATE: | ||
| 171 | s->new_session=1; | ||
| 172 | /* s->state=SSL_ST_ACCEPT; */ | ||
| 173 | |||
| 174 | case SSL_ST_BEFORE: | ||
| 175 | case SSL_ST_ACCEPT: | ||
| 176 | case SSL_ST_BEFORE|SSL_ST_ACCEPT: | ||
| 177 | case SSL_ST_OK|SSL_ST_ACCEPT: | ||
| 178 | |||
| 179 | if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1); | ||
| 180 | |||
| 181 | if ((s->version>>8) != 3) | ||
| 182 | abort(); | ||
| 183 | /* s->version=SSL3_VERSION; */ | ||
| 184 | s->type=SSL_ST_ACCEPT; | ||
| 185 | |||
| 186 | if (s->init_buf == NULL) | ||
| 187 | { | ||
| 188 | if ((buf=BUF_MEM_new()) == NULL) | ||
| 189 | { | ||
| 190 | ret= -1; | ||
| 191 | goto end; | ||
| 192 | } | ||
| 193 | if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH)) | ||
| 194 | { | ||
| 195 | ret= -1; | ||
| 196 | goto end; | ||
| 197 | } | ||
| 198 | s->init_buf=buf; | ||
| 199 | } | ||
| 200 | |||
| 201 | if (!ssl3_setup_buffers(s)) | ||
| 202 | { | ||
| 203 | ret= -1; | ||
| 204 | goto end; | ||
| 205 | } | ||
| 206 | |||
| 207 | /* Ok, we now need to push on a buffering BIO so that | ||
| 208 | * the output is sent in a way that TCP likes :-) | ||
| 209 | */ | ||
| 210 | if (!ssl_init_wbio_buffer(s,1)) { ret= -1; goto end; } | ||
| 211 | |||
| 212 | s->init_num=0; | ||
| 213 | |||
| 214 | if (s->state != SSL_ST_RENEGOTIATE) | ||
| 215 | { | ||
| 216 | s->state=SSL3_ST_SR_CLNT_HELLO_A; | ||
| 217 | ssl3_init_finished_mac(s); | ||
| 218 | s->ctx->sess_accept++; | ||
| 219 | } | ||
| 220 | else | ||
| 221 | { | ||
| 222 | s->ctx->sess_accept_renegotiate++; | ||
| 223 | s->state=SSL3_ST_SW_HELLO_REQ_A; | ||
| 224 | } | ||
| 225 | break; | ||
| 226 | |||
| 227 | case SSL3_ST_SW_HELLO_REQ_A: | ||
| 228 | case SSL3_ST_SW_HELLO_REQ_B: | ||
| 229 | |||
| 230 | s->shutdown=0; | ||
| 231 | ret=ssl3_send_hello_request(s); | ||
| 232 | if (ret <= 0) goto end; | ||
| 233 | s->s3->tmp.next_state=SSL3_ST_SW_HELLO_REQ_C; | ||
| 234 | s->state=SSL3_ST_SW_FLUSH; | ||
| 235 | s->init_num=0; | ||
| 236 | |||
| 237 | ssl3_init_finished_mac(s); | ||
| 238 | break; | ||
| 239 | |||
| 240 | case SSL3_ST_SW_HELLO_REQ_C: | ||
| 241 | /* remove buffering on output */ | ||
| 242 | under=BIO_pop(s->wbio); | ||
| 243 | if (under != NULL) | ||
| 244 | s->wbio=under; | ||
| 245 | else | ||
| 246 | abort(); /* ok */ | ||
| 247 | BIO_free(s->bbio); | ||
| 248 | s->bbio=NULL; | ||
| 249 | |||
| 250 | s->state=SSL_ST_OK; | ||
| 251 | ret=1; | ||
| 252 | goto end; | ||
| 253 | /* break; */ | ||
| 254 | |||
| 255 | case SSL3_ST_SR_CLNT_HELLO_A: | ||
| 256 | case SSL3_ST_SR_CLNT_HELLO_B: | ||
| 257 | case SSL3_ST_SR_CLNT_HELLO_C: | ||
| 258 | |||
| 259 | s->shutdown=0; | ||
| 260 | ret=ssl3_get_client_hello(s); | ||
| 261 | if (ret <= 0) goto end; | ||
| 262 | s->state=SSL3_ST_SW_SRVR_HELLO_A; | ||
| 263 | s->init_num=0; | ||
| 264 | break; | ||
| 265 | |||
| 266 | case SSL3_ST_SW_SRVR_HELLO_A: | ||
| 267 | case SSL3_ST_SW_SRVR_HELLO_B: | ||
| 268 | ret=ssl3_send_server_hello(s); | ||
| 269 | if (ret <= 0) goto end; | ||
| 270 | |||
| 271 | if (s->hit) | ||
| 272 | s->state=SSL3_ST_SW_CHANGE_A; | ||
| 273 | else | ||
| 274 | s->state=SSL3_ST_SW_CERT_A; | ||
| 275 | s->init_num=0; | ||
| 276 | break; | ||
| 277 | |||
| 278 | case SSL3_ST_SW_CERT_A: | ||
| 279 | case SSL3_ST_SW_CERT_B: | ||
| 280 | /* Check if it is anon DH */ | ||
| 281 | if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL)) | ||
| 282 | { | ||
| 283 | ret=ssl3_send_server_certificate(s); | ||
| 284 | if (ret <= 0) goto end; | ||
| 285 | } | ||
| 286 | else | ||
| 287 | skip=1; | ||
| 288 | s->state=SSL3_ST_SW_KEY_EXCH_A; | ||
| 289 | s->init_num=0; | ||
| 290 | break; | ||
| 291 | |||
| 292 | case SSL3_ST_SW_KEY_EXCH_A: | ||
| 293 | case SSL3_ST_SW_KEY_EXCH_B: | ||
| 294 | l=s->s3->tmp.new_cipher->algorithms; | ||
| 295 | if (s->session->cert == NULL) | ||
| 296 | { | ||
| 297 | if (s->cert != NULL) | ||
| 298 | { | ||
| 299 | CRYPTO_add(&s->cert->references,1,CRYPTO_LOCK_SSL_CERT); | ||
| 300 | s->session->cert=s->cert; | ||
| 301 | } | ||
| 302 | else | ||
| 303 | { | ||
| 304 | CRYPTO_add(&s->ctx->default_cert->references,1,CRYPTO_LOCK_SSL_CERT); | ||
| 305 | s->session->cert=s->ctx->default_cert; | ||
| 306 | } | ||
| 307 | } | ||
| 308 | ct=s->session->cert; | ||
| 309 | |||
| 310 | /* clear this, it may get reset by | ||
| 311 | * send_server_key_exchange */ | ||
| 312 | if (s->options & SSL_OP_EPHEMERAL_RSA) | ||
| 313 | s->s3->tmp.use_rsa_tmp=1; | ||
| 314 | else | ||
| 315 | s->s3->tmp.use_rsa_tmp=0; | ||
| 316 | |||
| 317 | /* only send if a DH key exchange, fortezza or | ||
| 318 | * RSA but we have a sign only certificate */ | ||
| 319 | if ( s->s3->tmp.use_rsa_tmp || | ||
| 320 | (l & (SSL_DH|SSL_kFZA)) || | ||
| 321 | ((l & SSL_kRSA) && | ||
| 322 | ((ct->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL)|| | ||
| 323 | ((l & SSL_EXPORT) && | ||
| 324 | (EVP_PKEY_size(ct->pkeys[SSL_PKEY_RSA_ENC].privatekey)*8 > 512) | ||
| 325 | ) | ||
| 326 | ) | ||
| 327 | ) | ||
| 328 | ) | ||
| 329 | { | ||
| 330 | ret=ssl3_send_server_key_exchange(s); | ||
| 331 | if (ret <= 0) goto end; | ||
| 332 | } | ||
| 333 | else | ||
| 334 | skip=1; | ||
| 335 | |||
| 336 | s->state=SSL3_ST_SW_CERT_REQ_A; | ||
| 337 | s->init_num=0; | ||
| 338 | break; | ||
| 339 | |||
| 340 | case SSL3_ST_SW_CERT_REQ_A: | ||
| 341 | case SSL3_ST_SW_CERT_REQ_B: | ||
| 342 | if (!(s->verify_mode & SSL_VERIFY_PEER) || | ||
| 343 | ((s->session->peer != NULL) && | ||
| 344 | (s->verify_mode & SSL_VERIFY_CLIENT_ONCE))) | ||
| 345 | { | ||
| 346 | /* no cert request */ | ||
| 347 | skip=1; | ||
| 348 | s->s3->tmp.cert_request=0; | ||
| 349 | s->state=SSL3_ST_SW_SRVR_DONE_A; | ||
| 350 | } | ||
| 351 | else | ||
| 352 | { | ||
| 353 | s->s3->tmp.cert_request=1; | ||
| 354 | ret=ssl3_send_certificate_request(s); | ||
| 355 | if (ret <= 0) goto end; | ||
| 356 | s->state=SSL3_ST_SW_SRVR_DONE_A; | ||
| 357 | s->init_num=0; | ||
| 358 | } | ||
| 359 | break; | ||
| 360 | |||
| 361 | case SSL3_ST_SW_SRVR_DONE_A: | ||
| 362 | case SSL3_ST_SW_SRVR_DONE_B: | ||
| 363 | ret=ssl3_send_server_done(s); | ||
| 364 | if (ret <= 0) goto end; | ||
| 365 | s->s3->tmp.next_state=SSL3_ST_SR_CERT_A; | ||
| 366 | s->state=SSL3_ST_SW_FLUSH; | ||
| 367 | s->init_num=0; | ||
| 368 | break; | ||
| 369 | |||
| 370 | case SSL3_ST_SW_FLUSH: | ||
| 371 | /* number of bytes to be flushed */ | ||
| 372 | num1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL); | ||
| 373 | if (num1 > 0) | ||
| 374 | { | ||
| 375 | s->rwstate=SSL_WRITING; | ||
| 376 | num1=BIO_flush(s->wbio); | ||
| 377 | if (num1 <= 0) { ret= -1; goto end; } | ||
| 378 | s->rwstate=SSL_NOTHING; | ||
| 379 | } | ||
| 380 | |||
| 381 | s->state=s->s3->tmp.next_state; | ||
| 382 | break; | ||
| 383 | |||
| 384 | case SSL3_ST_SR_CERT_A: | ||
| 385 | case SSL3_ST_SR_CERT_B: | ||
| 386 | /* could be sent for a DH cert, even if we | ||
| 387 | * have not asked for it :-) */ | ||
| 388 | ret=ssl3_get_client_certificate(s); | ||
| 389 | if (ret <= 0) goto end; | ||
| 390 | s->init_num=0; | ||
| 391 | s->state=SSL3_ST_SR_KEY_EXCH_A; | ||
| 392 | break; | ||
| 393 | |||
| 394 | case SSL3_ST_SR_KEY_EXCH_A: | ||
| 395 | case SSL3_ST_SR_KEY_EXCH_B: | ||
| 396 | ret=ssl3_get_client_key_exchange(s); | ||
| 397 | if (ret <= 0) goto end; | ||
| 398 | s->state=SSL3_ST_SR_CERT_VRFY_A; | ||
| 399 | s->init_num=0; | ||
| 400 | |||
| 401 | /* We need to get hashes here so if there is | ||
| 402 | * a client cert, it can be verified */ | ||
| 403 | s->method->ssl3_enc->cert_verify_mac(s, | ||
| 404 | &(s->s3->finish_dgst1), | ||
| 405 | &(s->s3->tmp.finish_md[0])); | ||
| 406 | s->method->ssl3_enc->cert_verify_mac(s, | ||
| 407 | &(s->s3->finish_dgst2), | ||
| 408 | &(s->s3->tmp.finish_md[MD5_DIGEST_LENGTH])); | ||
| 409 | |||
| 410 | break; | ||
| 411 | |||
| 412 | case SSL3_ST_SR_CERT_VRFY_A: | ||
| 413 | case SSL3_ST_SR_CERT_VRFY_B: | ||
| 414 | |||
| 415 | /* we should decide if we expected this one */ | ||
| 416 | ret=ssl3_get_cert_verify(s); | ||
| 417 | if (ret <= 0) goto end; | ||
| 418 | |||
| 419 | s->state=SSL3_ST_SR_FINISHED_A; | ||
| 420 | s->init_num=0; | ||
| 421 | break; | ||
| 422 | |||
| 423 | case SSL3_ST_SR_FINISHED_A: | ||
| 424 | case SSL3_ST_SR_FINISHED_B: | ||
| 425 | ret=ssl3_get_finished(s,SSL3_ST_SR_FINISHED_A, | ||
| 426 | SSL3_ST_SR_FINISHED_B); | ||
| 427 | if (ret <= 0) goto end; | ||
| 428 | if (s->hit) | ||
| 429 | s->state=SSL_ST_OK; | ||
| 430 | else | ||
| 431 | s->state=SSL3_ST_SW_CHANGE_A; | ||
| 432 | s->init_num=0; | ||
| 433 | break; | ||
| 434 | |||
| 435 | case SSL3_ST_SW_CHANGE_A: | ||
| 436 | case SSL3_ST_SW_CHANGE_B: | ||
| 437 | |||
| 438 | s->session->cipher=s->s3->tmp.new_cipher; | ||
| 439 | if (!s->method->ssl3_enc->setup_key_block(s)) | ||
| 440 | { ret= -1; goto end; } | ||
| 441 | |||
| 442 | ret=ssl3_send_change_cipher_spec(s, | ||
| 443 | SSL3_ST_SW_CHANGE_A,SSL3_ST_SW_CHANGE_B); | ||
| 444 | |||
| 445 | if (ret <= 0) goto end; | ||
| 446 | s->state=SSL3_ST_SW_FINISHED_A; | ||
| 447 | s->init_num=0; | ||
| 448 | |||
| 449 | if (!s->method->ssl3_enc->change_cipher_state(s, | ||
| 450 | SSL3_CHANGE_CIPHER_SERVER_WRITE)) | ||
| 451 | { | ||
| 452 | ret= -1; | ||
| 453 | goto end; | ||
| 454 | } | ||
| 455 | |||
| 456 | break; | ||
| 457 | |||
| 458 | case SSL3_ST_SW_FINISHED_A: | ||
| 459 | case SSL3_ST_SW_FINISHED_B: | ||
| 460 | ret=ssl3_send_finished(s, | ||
| 461 | SSL3_ST_SW_FINISHED_A,SSL3_ST_SW_FINISHED_B, | ||
| 462 | s->method->ssl3_enc->server_finished, | ||
| 463 | s->method->ssl3_enc->server_finished_len); | ||
| 464 | if (ret <= 0) goto end; | ||
| 465 | s->state=SSL3_ST_SW_FLUSH; | ||
| 466 | if (s->hit) | ||
| 467 | s->s3->tmp.next_state=SSL3_ST_SR_FINISHED_A; | ||
| 468 | else | ||
| 469 | s->s3->tmp.next_state=SSL_ST_OK; | ||
| 470 | s->init_num=0; | ||
| 471 | break; | ||
| 472 | |||
| 473 | case SSL_ST_OK: | ||
| 474 | /* clean a few things up */ | ||
| 475 | ssl3_cleanup_key_block(s); | ||
| 476 | |||
| 477 | BUF_MEM_free(s->init_buf); | ||
| 478 | s->init_buf=NULL; | ||
| 479 | |||
| 480 | /* remove buffering on output */ | ||
| 481 | under=BIO_pop(s->wbio); | ||
| 482 | if (under != NULL) | ||
| 483 | s->wbio=under; | ||
| 484 | else | ||
| 485 | abort(); /* ok */ | ||
| 486 | BIO_free(s->bbio); | ||
| 487 | s->bbio=NULL; | ||
| 488 | |||
| 489 | s->new_session=0; | ||
| 490 | s->init_num=0; | ||
| 491 | |||
| 492 | ssl_update_cache(s,SSL_SESS_CACHE_SERVER); | ||
| 493 | |||
| 494 | s->ctx->sess_accept_good++; | ||
| 495 | /* s->server=1; */ | ||
| 496 | s->handshake_func=ssl3_accept; | ||
| 497 | ret=1; | ||
| 498 | |||
| 499 | if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1); | ||
| 500 | |||
| 501 | goto end; | ||
| 502 | /* break; */ | ||
| 503 | |||
| 504 | default: | ||
| 505 | SSLerr(SSL_F_SSL3_ACCEPT,SSL_R_UNKNOWN_STATE); | ||
| 506 | ret= -1; | ||
| 507 | goto end; | ||
| 508 | /* break; */ | ||
| 509 | } | ||
| 510 | |||
| 511 | if (!s->s3->tmp.reuse_message && !skip) | ||
| 512 | { | ||
| 513 | if (s->debug) | ||
| 514 | { | ||
| 515 | if ((ret=BIO_flush(s->wbio)) <= 0) | ||
| 516 | goto end; | ||
| 517 | } | ||
| 518 | |||
| 519 | |||
| 520 | if ((cb != NULL) && (s->state != state)) | ||
| 521 | { | ||
| 522 | new_state=s->state; | ||
| 523 | s->state=state; | ||
| 524 | cb(s,SSL_CB_ACCEPT_LOOP,1); | ||
| 525 | s->state=new_state; | ||
| 526 | } | ||
| 527 | } | ||
| 528 | skip=0; | ||
| 529 | } | ||
| 530 | end: | ||
| 531 | /* BIO_flush(s->wbio); */ | ||
| 532 | |||
| 533 | if (cb != NULL) | ||
| 534 | cb(s,SSL_CB_ACCEPT_EXIT,ret); | ||
| 535 | s->in_handshake--; | ||
| 536 | return(ret); | ||
| 537 | } | ||
| 538 | |||
| 539 | static int ssl3_send_hello_request(s) | ||
| 540 | SSL *s; | ||
| 541 | { | ||
| 542 | unsigned char *p; | ||
| 543 | |||
| 544 | if (s->state == SSL3_ST_SW_HELLO_REQ_A) | ||
| 545 | { | ||
| 546 | p=(unsigned char *)s->init_buf->data; | ||
| 547 | *(p++)=SSL3_MT_CLIENT_REQUEST; | ||
| 548 | *(p++)=0; | ||
| 549 | *(p++)=0; | ||
| 550 | *(p++)=0; | ||
| 551 | |||
| 552 | s->state=SSL3_ST_SW_HELLO_REQ_B; | ||
| 553 | /* number of bytes to write */ | ||
| 554 | s->init_num=4; | ||
| 555 | s->init_off=0; | ||
| 556 | } | ||
| 557 | |||
| 558 | /* SSL3_ST_SW_HELLO_REQ_B */ | ||
| 559 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
| 560 | } | ||
| 561 | |||
| 562 | static int ssl3_get_client_hello(s) | ||
| 563 | SSL *s; | ||
| 564 | { | ||
| 565 | int i,j,ok,al,ret= -1; | ||
| 566 | long n; | ||
| 567 | unsigned long id; | ||
| 568 | unsigned char *p,*d; | ||
| 569 | SSL_CIPHER *c; | ||
| 570 | STACK *ciphers=NULL; | ||
| 571 | |||
| 572 | /* We do this so that we will respond with our native type. | ||
| 573 | * If we are TLSv1 and we get SSLv3, we will respond with TLSv1, | ||
| 574 | * This down switching should be handled by a different method. | ||
| 575 | * If we are SSLv3, we will respond with SSLv3, even if prompted with | ||
| 576 | * TLSv1. | ||
| 577 | */ | ||
| 578 | if (s->state == SSL3_ST_SR_CLNT_HELLO_A) | ||
| 579 | { | ||
| 580 | s->first_packet=1; | ||
| 581 | s->state=SSL3_ST_SR_CLNT_HELLO_B; | ||
| 582 | } | ||
| 583 | n=ssl3_get_message(s, | ||
| 584 | SSL3_ST_SR_CLNT_HELLO_B, | ||
| 585 | SSL3_ST_SR_CLNT_HELLO_C, | ||
| 586 | SSL3_MT_CLIENT_HELLO, | ||
| 587 | SSL3_RT_MAX_PLAIN_LENGTH, | ||
| 588 | &ok); | ||
| 589 | |||
| 590 | if (!ok) return((int)n); | ||
| 591 | d=p=(unsigned char *)s->init_buf->data; | ||
| 592 | |||
| 593 | /* The version number has already been checked in ssl3_get_message. | ||
| 594 | * I a native TLSv1/SSLv3 method, the match must be correct except | ||
| 595 | * perhaps for the first message */ | ||
| 596 | p+=2; | ||
| 597 | |||
| 598 | /* load the client random */ | ||
| 599 | memcpy(s->s3->client_random,p,SSL3_RANDOM_SIZE); | ||
| 600 | p+=SSL3_RANDOM_SIZE; | ||
| 601 | |||
| 602 | /* get the session-id */ | ||
| 603 | j= *(p++); | ||
| 604 | |||
| 605 | s->hit=0; | ||
| 606 | if (j == 0) | ||
| 607 | { | ||
| 608 | if (!ssl_get_new_session(s,1)) | ||
| 609 | goto err; | ||
| 610 | } | ||
| 611 | else | ||
| 612 | { | ||
| 613 | i=ssl_get_prev_session(s,p,j); | ||
| 614 | if (i == 1) | ||
| 615 | { /* previous session */ | ||
| 616 | s->hit=1; | ||
| 617 | } | ||
| 618 | else | ||
| 619 | { | ||
| 620 | if (!ssl_get_new_session(s,1)) | ||
| 621 | goto err; | ||
| 622 | } | ||
| 623 | } | ||
| 624 | |||
| 625 | p+=j; | ||
| 626 | n2s(p,i); | ||
| 627 | if ((i == 0) && (j != 0)) | ||
| 628 | { | ||
| 629 | /* we need a cipher if we are not resuming a session */ | ||
| 630 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
| 631 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_CIPHERS_SPECIFIED); | ||
| 632 | goto f_err; | ||
| 633 | } | ||
| 634 | if ((i+p) > (d+n)) | ||
| 635 | { | ||
| 636 | /* not enough data */ | ||
| 637 | al=SSL_AD_DECODE_ERROR; | ||
| 638 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH); | ||
| 639 | goto f_err; | ||
| 640 | } | ||
| 641 | if ((i > 0) && (ssl_bytes_to_cipher_list(s,p,i,&(ciphers)) | ||
| 642 | == NULL)) | ||
| 643 | { | ||
| 644 | goto err; | ||
| 645 | } | ||
| 646 | p+=i; | ||
| 647 | |||
| 648 | /* If it is a hit, check that the cipher is in the list */ | ||
| 649 | if ((s->hit) && (i > 0)) | ||
| 650 | { | ||
| 651 | j=0; | ||
| 652 | id=s->session->cipher->id; | ||
| 653 | |||
| 654 | for (i=0; i<sk_num(ciphers); i++) | ||
| 655 | { | ||
| 656 | c=(SSL_CIPHER *)sk_value(ciphers,i); | ||
| 657 | if (c->id == id) | ||
| 658 | { | ||
| 659 | j=1; | ||
| 660 | break; | ||
| 661 | } | ||
| 662 | } | ||
| 663 | if (j == 0) | ||
| 664 | { | ||
| 665 | if ((s->options & SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG) && (sk_num(ciphers) == 1)) | ||
| 666 | { | ||
| 667 | /* Very bad for multi-threading.... */ | ||
| 668 | s->session->cipher= | ||
| 669 | (SSL_CIPHER *)sk_value(ciphers,0); | ||
| 670 | } | ||
| 671 | else | ||
| 672 | { | ||
| 673 | /* we need to have the cipher in the cipher | ||
| 674 | * list if we are asked to reuse it */ | ||
| 675 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
| 676 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_REQUIRED_CIPHER_MISSING); | ||
| 677 | goto f_err; | ||
| 678 | } | ||
| 679 | } | ||
| 680 | } | ||
| 681 | |||
| 682 | /* compression */ | ||
| 683 | i= *(p++); | ||
| 684 | for (j=0; j<i; j++) | ||
| 685 | if (p[j] == 0) break; | ||
| 686 | |||
| 687 | p+=i; | ||
| 688 | if (j >= i) | ||
| 689 | { | ||
| 690 | /* no compress */ | ||
| 691 | al=SSL_AD_DECODE_ERROR; | ||
| 692 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_COMPRESSION_SPECIFIED); | ||
| 693 | goto f_err; | ||
| 694 | } | ||
| 695 | |||
| 696 | /* TLS does not mind if there is extra stuff */ | ||
| 697 | if (s->version == SSL3_VERSION) | ||
| 698 | { | ||
| 699 | if (p > (d+n)) | ||
| 700 | { | ||
| 701 | /* wrong number of bytes, | ||
| 702 | * there could be more to follow */ | ||
| 703 | al=SSL_AD_DECODE_ERROR; | ||
| 704 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH); | ||
| 705 | goto f_err; | ||
| 706 | } | ||
| 707 | } | ||
| 708 | |||
| 709 | /* do nothing with compression */ | ||
| 710 | |||
| 711 | /* Given s->session->ciphers and ssl_get_ciphers_by_id(s), we must | ||
| 712 | * pick a cipher */ | ||
| 713 | |||
| 714 | if (!s->hit) | ||
| 715 | { | ||
| 716 | if (s->session->ciphers != NULL) | ||
| 717 | sk_free(s->session->ciphers); | ||
| 718 | s->session->ciphers=ciphers; | ||
| 719 | if (ciphers == NULL) | ||
| 720 | { | ||
| 721 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
| 722 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_CIPHERS_PASSED); | ||
| 723 | goto f_err; | ||
| 724 | } | ||
| 725 | ciphers=NULL; | ||
| 726 | c=ssl3_choose_cipher(s,s->session->ciphers, | ||
| 727 | ssl_get_ciphers_by_id(s)); | ||
| 728 | |||
| 729 | if (c == NULL) | ||
| 730 | { | ||
| 731 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
| 732 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_SHARED_CIPHER); | ||
| 733 | goto f_err; | ||
| 734 | } | ||
| 735 | s->s3->tmp.new_cipher=c; | ||
| 736 | } | ||
| 737 | else | ||
| 738 | { | ||
| 739 | /* Session-id reuse */ | ||
| 740 | #ifdef REUSE_CIPHER_BUG | ||
| 741 | STACK *sk; | ||
| 742 | SSL_CIPHER *nc=NULL; | ||
| 743 | SSL_CIPHER *ec=NULL; | ||
| 744 | |||
| 745 | if (s->options & SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG) | ||
| 746 | { | ||
| 747 | sk=s->session->ciphers; | ||
| 748 | for (i=0; i<sk_num(sk); i++) | ||
| 749 | { | ||
| 750 | c=(SSL_CIPHER *)sk_value(sk,i); | ||
| 751 | if (c->algorithms & SSL_eNULL) | ||
| 752 | nc=c; | ||
| 753 | if (c->algorithms & SSL_EXP) | ||
| 754 | ec=c; | ||
| 755 | } | ||
| 756 | if (nc != NULL) | ||
| 757 | s->s3->tmp.new_cipher=nc; | ||
| 758 | else if (ec != NULL) | ||
| 759 | s->s3->tmp.new_cipher=ec; | ||
| 760 | else | ||
| 761 | s->s3->tmp.new_cipher=s->session->cipher; | ||
| 762 | } | ||
| 763 | else | ||
| 764 | #endif | ||
| 765 | s->s3->tmp.new_cipher=s->session->cipher; | ||
| 766 | } | ||
| 767 | |||
| 768 | /* we now have the following setup. | ||
| 769 | * client_random | ||
| 770 | * cipher_list - our prefered list of ciphers | ||
| 771 | * ciphers - the clients prefered list of ciphers | ||
| 772 | * compression - basically ignored right now | ||
| 773 | * ssl version is set - sslv3 | ||
| 774 | * s->session - The ssl session has been setup. | ||
| 775 | * s->hit - sesson reuse flag | ||
| 776 | * s->tmp.new_cipher - the new cipher to use. | ||
| 777 | */ | ||
| 778 | |||
| 779 | ret=1; | ||
| 780 | if (0) | ||
| 781 | { | ||
| 782 | f_err: | ||
| 783 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
| 784 | } | ||
| 785 | err: | ||
| 786 | if (ciphers != NULL) sk_free(ciphers); | ||
| 787 | return(ret); | ||
| 788 | } | ||
| 789 | |||
| 790 | static int ssl3_send_server_hello(s) | ||
| 791 | SSL *s; | ||
| 792 | { | ||
| 793 | unsigned char *buf; | ||
| 794 | unsigned char *p,*d; | ||
| 795 | int i,sl; | ||
| 796 | unsigned long l,Time; | ||
| 797 | |||
| 798 | if (s->state == SSL3_ST_SW_SRVR_HELLO_A) | ||
| 799 | { | ||
| 800 | buf=(unsigned char *)s->init_buf->data; | ||
| 801 | p=s->s3->server_random; | ||
| 802 | Time=time(NULL); /* Time */ | ||
| 803 | l2n(Time,p); | ||
| 804 | RAND_bytes(p,SSL3_RANDOM_SIZE-sizeof(Time)); | ||
| 805 | /* Do the message type and length last */ | ||
| 806 | d=p= &(buf[4]); | ||
| 807 | |||
| 808 | *(p++)=s->version>>8; | ||
| 809 | *(p++)=s->version&0xff; | ||
| 810 | |||
| 811 | /* Random stuff */ | ||
| 812 | memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE); | ||
| 813 | p+=SSL3_RANDOM_SIZE; | ||
| 814 | |||
| 815 | /* now in theory we have 3 options to sending back the | ||
| 816 | * session id. If it is a re-use, we send back the | ||
| 817 | * old session-id, if it is a new session, we send | ||
| 818 | * back the new session-id or we send back a 0 length | ||
| 819 | * session-id if we want it to be single use. | ||
| 820 | * Currently I will not implement the '0' length session-id | ||
| 821 | * 12-Jan-98 - I'll now support the '0' length stuff. | ||
| 822 | */ | ||
| 823 | if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_SERVER)) | ||
| 824 | s->session->session_id_length=0; | ||
| 825 | |||
| 826 | sl=s->session->session_id_length; | ||
| 827 | *(p++)=sl; | ||
| 828 | memcpy(p,s->session->session_id,sl); | ||
| 829 | p+=sl; | ||
| 830 | |||
| 831 | /* put the cipher */ | ||
| 832 | i=ssl3_put_cipher_by_char(s->s3->tmp.new_cipher,p); | ||
| 833 | p+=i; | ||
| 834 | |||
| 835 | /* put the compression method */ | ||
| 836 | *(p++)=0; | ||
| 837 | |||
| 838 | /* do the header */ | ||
| 839 | l=(p-d); | ||
| 840 | d=buf; | ||
| 841 | *(d++)=SSL3_MT_SERVER_HELLO; | ||
| 842 | l2n3(l,d); | ||
| 843 | |||
| 844 | s->state=SSL3_ST_CW_CLNT_HELLO_B; | ||
| 845 | /* number of bytes to write */ | ||
| 846 | s->init_num=p-buf; | ||
| 847 | s->init_off=0; | ||
| 848 | } | ||
| 849 | |||
| 850 | /* SSL3_ST_CW_CLNT_HELLO_B */ | ||
| 851 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
| 852 | } | ||
| 853 | |||
| 854 | static int ssl3_send_server_done(s) | ||
| 855 | SSL *s; | ||
| 856 | { | ||
| 857 | unsigned char *p; | ||
| 858 | |||
| 859 | if (s->state == SSL3_ST_SW_SRVR_DONE_A) | ||
| 860 | { | ||
| 861 | p=(unsigned char *)s->init_buf->data; | ||
| 862 | |||
| 863 | /* do the header */ | ||
| 864 | *(p++)=SSL3_MT_SERVER_DONE; | ||
| 865 | *(p++)=0; | ||
| 866 | *(p++)=0; | ||
| 867 | *(p++)=0; | ||
| 868 | |||
| 869 | s->state=SSL3_ST_SW_SRVR_DONE_B; | ||
| 870 | /* number of bytes to write */ | ||
| 871 | s->init_num=4; | ||
| 872 | s->init_off=0; | ||
| 873 | } | ||
| 874 | |||
| 875 | /* SSL3_ST_CW_CLNT_HELLO_B */ | ||
| 876 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
| 877 | } | ||
| 878 | |||
| 879 | static int ssl3_send_server_key_exchange(s) | ||
| 880 | SSL *s; | ||
| 881 | { | ||
| 882 | #ifndef NO_RSA | ||
| 883 | unsigned char *q; | ||
| 884 | int j,num; | ||
| 885 | RSA *rsa; | ||
| 886 | unsigned char md_buf[MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH]; | ||
| 887 | #endif | ||
| 888 | #ifndef NO_DH | ||
| 889 | DH *dh,*dhp; | ||
| 890 | #endif | ||
| 891 | EVP_PKEY *pkey; | ||
| 892 | unsigned char *p,*d; | ||
| 893 | int al,i; | ||
| 894 | unsigned long type; | ||
| 895 | int n; | ||
| 896 | CERT *cert; | ||
| 897 | BIGNUM *r[4]; | ||
| 898 | int nr[4],kn; | ||
| 899 | BUF_MEM *buf; | ||
| 900 | EVP_MD_CTX md_ctx; | ||
| 901 | |||
| 902 | if (s->state == SSL3_ST_SW_KEY_EXCH_A) | ||
| 903 | { | ||
| 904 | type=s->s3->tmp.new_cipher->algorithms & SSL_MKEY_MASK; | ||
| 905 | cert=s->session->cert; | ||
| 906 | |||
| 907 | buf=s->init_buf; | ||
| 908 | |||
| 909 | r[0]=r[1]=r[2]=r[3]=NULL; | ||
| 910 | n=0; | ||
| 911 | #ifndef NO_RSA | ||
| 912 | if (type & SSL_kRSA) | ||
| 913 | { | ||
| 914 | rsa=cert->rsa_tmp; | ||
| 915 | if ((rsa == NULL) && (s->ctx->default_cert->rsa_tmp_cb != NULL)) | ||
| 916 | { | ||
| 917 | rsa=s->ctx->default_cert->rsa_tmp_cb(s, | ||
| 918 | (s->s3->tmp.new_cipher->algorithms| | ||
| 919 | SSL_NOT_EXP)?0:1); | ||
| 920 | CRYPTO_add(&rsa->references,1,CRYPTO_LOCK_RSA); | ||
| 921 | cert->rsa_tmp=rsa; | ||
| 922 | } | ||
| 923 | if (rsa == NULL) | ||
| 924 | { | ||
| 925 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
| 926 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_MISSING_TMP_RSA_KEY); | ||
| 927 | goto f_err; | ||
| 928 | } | ||
| 929 | r[0]=rsa->n; | ||
| 930 | r[1]=rsa->e; | ||
| 931 | s->s3->tmp.use_rsa_tmp=1; | ||
| 932 | } | ||
| 933 | else | ||
| 934 | #endif | ||
| 935 | #ifndef NO_DH | ||
| 936 | if (type & SSL_kEDH) | ||
| 937 | { | ||
| 938 | dhp=cert->dh_tmp; | ||
| 939 | if ((dhp == NULL) && (cert->dh_tmp_cb != NULL)) | ||
| 940 | dhp=cert->dh_tmp_cb(s, | ||
| 941 | (s->s3->tmp.new_cipher->algorithms| | ||
| 942 | SSL_NOT_EXP)?0:1); | ||
| 943 | if (dhp == NULL) | ||
| 944 | { | ||
| 945 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
| 946 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_MISSING_TMP_DH_KEY); | ||
| 947 | goto f_err; | ||
| 948 | } | ||
| 949 | if ((dh=DHparams_dup(dhp)) == NULL) | ||
| 950 | { | ||
| 951 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
| 952 | goto err; | ||
| 953 | } | ||
| 954 | |||
| 955 | s->s3->tmp.dh=dh; | ||
| 956 | if (((dhp->pub_key == NULL) || | ||
| 957 | (dhp->priv_key == NULL) || | ||
| 958 | (s->options & SSL_OP_SINGLE_DH_USE)) && | ||
| 959 | (!DH_generate_key(dh))) | ||
| 960 | { | ||
| 961 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
| 962 | goto err; | ||
| 963 | } | ||
| 964 | else | ||
| 965 | { | ||
| 966 | dh->pub_key=BN_dup(dhp->pub_key); | ||
| 967 | dh->priv_key=BN_dup(dhp->priv_key); | ||
| 968 | if ((dh->pub_key == NULL) || | ||
| 969 | (dh->priv_key == NULL)) | ||
| 970 | { | ||
| 971 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
| 972 | goto err; | ||
| 973 | } | ||
| 974 | } | ||
| 975 | r[0]=dh->p; | ||
| 976 | r[1]=dh->g; | ||
| 977 | r[2]=dh->pub_key; | ||
| 978 | } | ||
| 979 | else | ||
| 980 | #endif | ||
| 981 | { | ||
| 982 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
| 983 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE); | ||
| 984 | goto f_err; | ||
| 985 | } | ||
| 986 | for (i=0; r[i] != NULL; i++) | ||
| 987 | { | ||
| 988 | nr[i]=BN_num_bytes(r[i]); | ||
| 989 | n+=2+nr[i]; | ||
| 990 | } | ||
| 991 | |||
| 992 | if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL)) | ||
| 993 | { | ||
| 994 | if ((pkey=ssl_get_sign_pkey(s,s->s3->tmp.new_cipher)) | ||
| 995 | == NULL) | ||
| 996 | { | ||
| 997 | al=SSL_AD_DECODE_ERROR; | ||
| 998 | goto f_err; | ||
| 999 | } | ||
| 1000 | kn=EVP_PKEY_size(pkey); | ||
| 1001 | } | ||
| 1002 | else | ||
| 1003 | { | ||
| 1004 | pkey=NULL; | ||
| 1005 | kn=0; | ||
| 1006 | } | ||
| 1007 | |||
| 1008 | if (!BUF_MEM_grow(buf,n+4+kn)) | ||
| 1009 | { | ||
| 1010 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_BUF); | ||
| 1011 | goto err; | ||
| 1012 | } | ||
| 1013 | d=(unsigned char *)s->init_buf->data; | ||
| 1014 | p= &(d[4]); | ||
| 1015 | |||
| 1016 | for (i=0; r[i] != NULL; i++) | ||
| 1017 | { | ||
| 1018 | s2n(nr[i],p); | ||
| 1019 | BN_bn2bin(r[i],p); | ||
| 1020 | p+=nr[i]; | ||
| 1021 | } | ||
| 1022 | |||
| 1023 | /* not anonymous */ | ||
| 1024 | if (pkey != NULL) | ||
| 1025 | { | ||
| 1026 | /* n is the length of the params, they start at &(d[4]) | ||
| 1027 | * and p points to the space at the end. */ | ||
| 1028 | #ifndef NO_RSA | ||
| 1029 | if (pkey->type == EVP_PKEY_RSA) | ||
| 1030 | { | ||
| 1031 | q=md_buf; | ||
| 1032 | j=0; | ||
| 1033 | for (num=2; num > 0; num--) | ||
| 1034 | { | ||
| 1035 | EVP_DigestInit(&md_ctx,(num == 2) | ||
| 1036 | ?s->ctx->md5:s->ctx->sha1); | ||
| 1037 | EVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE); | ||
| 1038 | EVP_DigestUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE); | ||
| 1039 | EVP_DigestUpdate(&md_ctx,&(d[4]),n); | ||
| 1040 | EVP_DigestFinal(&md_ctx,q, | ||
| 1041 | (unsigned int *)&i); | ||
| 1042 | q+=i; | ||
| 1043 | j+=i; | ||
| 1044 | } | ||
| 1045 | i=RSA_private_encrypt(j,md_buf,&(p[2]), | ||
| 1046 | pkey->pkey.rsa,RSA_PKCS1_PADDING); | ||
| 1047 | if (i <= 0) | ||
| 1048 | { | ||
| 1049 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_RSA); | ||
| 1050 | goto err; | ||
| 1051 | } | ||
| 1052 | s2n(i,p); | ||
| 1053 | n+=i+2; | ||
| 1054 | } | ||
| 1055 | else | ||
| 1056 | #endif | ||
| 1057 | #if !defined(NO_DSA) | ||
| 1058 | if (pkey->type == EVP_PKEY_DSA) | ||
| 1059 | { | ||
| 1060 | /* lets do DSS */ | ||
| 1061 | EVP_SignInit(&md_ctx,EVP_dss1()); | ||
| 1062 | EVP_SignUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE); | ||
| 1063 | EVP_SignUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE); | ||
| 1064 | EVP_SignUpdate(&md_ctx,&(d[4]),n); | ||
| 1065 | if (!EVP_SignFinal(&md_ctx,&(p[2]), | ||
| 1066 | (unsigned int *)&i,pkey)) | ||
| 1067 | { | ||
| 1068 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_DSA); | ||
| 1069 | goto err; | ||
| 1070 | } | ||
| 1071 | s2n(i,p); | ||
| 1072 | n+=i+2; | ||
| 1073 | } | ||
| 1074 | else | ||
| 1075 | #endif | ||
| 1076 | { | ||
| 1077 | /* Is this error check actually needed? */ | ||
| 1078 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
| 1079 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNKNOWN_PKEY_TYPE); | ||
| 1080 | goto f_err; | ||
| 1081 | } | ||
| 1082 | } | ||
| 1083 | |||
| 1084 | *(d++)=SSL3_MT_SERVER_KEY_EXCHANGE; | ||
| 1085 | l2n3(n,d); | ||
| 1086 | |||
| 1087 | /* we should now have things packed up, so lets send | ||
| 1088 | * it off */ | ||
| 1089 | s->init_num=n+4; | ||
| 1090 | s->init_off=0; | ||
| 1091 | } | ||
| 1092 | |||
| 1093 | /* SSL3_ST_SW_KEY_EXCH_B */ | ||
| 1094 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
| 1095 | f_err: | ||
| 1096 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
| 1097 | err: | ||
| 1098 | return(-1); | ||
| 1099 | } | ||
| 1100 | |||
| 1101 | static int ssl3_send_certificate_request(s) | ||
| 1102 | SSL *s; | ||
| 1103 | { | ||
| 1104 | unsigned char *p,*d; | ||
| 1105 | int i,j,nl,off,n; | ||
| 1106 | STACK *sk=NULL; | ||
| 1107 | X509_NAME *name; | ||
| 1108 | BUF_MEM *buf; | ||
| 1109 | |||
| 1110 | if (s->state == SSL3_ST_SW_CERT_REQ_A) | ||
| 1111 | { | ||
| 1112 | buf=s->init_buf; | ||
| 1113 | |||
| 1114 | d=p=(unsigned char *)&(buf->data[4]); | ||
| 1115 | |||
| 1116 | /* get the list of acceptable cert types */ | ||
| 1117 | p++; | ||
| 1118 | n=ssl3_get_req_cert_type(s,p); | ||
| 1119 | d[0]=n; | ||
| 1120 | p+=n; | ||
| 1121 | n++; | ||
| 1122 | |||
| 1123 | off=n; | ||
| 1124 | p+=2; | ||
| 1125 | n+=2; | ||
| 1126 | |||
| 1127 | sk=SSL_get_client_CA_list(s); | ||
| 1128 | nl=0; | ||
| 1129 | if (sk != NULL) | ||
| 1130 | { | ||
| 1131 | for (i=0; i<sk_num(sk); i++) | ||
| 1132 | { | ||
| 1133 | name=(X509_NAME *)sk_value(sk,i); | ||
| 1134 | j=i2d_X509_NAME(name,NULL); | ||
| 1135 | if (!BUF_MEM_grow(buf,4+n+j+2)) | ||
| 1136 | { | ||
| 1137 | SSLerr(SSL_F_SSL3_SEND_CERTIFICATE_REQUEST,ERR_R_BUF_LIB); | ||
| 1138 | goto err; | ||
| 1139 | } | ||
| 1140 | p=(unsigned char *)&(buf->data[4+n]); | ||
| 1141 | if (!(s->options & SSL_OP_NETSCAPE_CA_DN_BUG)) | ||
| 1142 | { | ||
| 1143 | s2n(j,p); | ||
| 1144 | i2d_X509_NAME(name,&p); | ||
| 1145 | n+=2+j; | ||
| 1146 | nl+=2+j; | ||
| 1147 | } | ||
| 1148 | else | ||
| 1149 | { | ||
| 1150 | d=p; | ||
| 1151 | i2d_X509_NAME(name,&p); | ||
| 1152 | j-=2; s2n(j,d); j+=2; | ||
| 1153 | n+=j; | ||
| 1154 | nl+=j; | ||
| 1155 | } | ||
| 1156 | } | ||
| 1157 | } | ||
| 1158 | /* else no CA names */ | ||
| 1159 | p=(unsigned char *)&(buf->data[4+off]); | ||
| 1160 | s2n(nl,p); | ||
| 1161 | |||
| 1162 | d=(unsigned char *)buf->data; | ||
| 1163 | *(d++)=SSL3_MT_CERTIFICATE_REQUEST; | ||
| 1164 | l2n3(n,d); | ||
| 1165 | |||
| 1166 | /* we should now have things packed up, so lets send | ||
| 1167 | * it off */ | ||
| 1168 | |||
| 1169 | s->init_num=n+4; | ||
| 1170 | s->init_off=0; | ||
| 1171 | } | ||
| 1172 | |||
| 1173 | /* SSL3_ST_SW_CERT_REQ_B */ | ||
| 1174 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
| 1175 | err: | ||
| 1176 | return(-1); | ||
| 1177 | } | ||
| 1178 | |||
| 1179 | static int ssl3_get_client_key_exchange(s) | ||
| 1180 | SSL *s; | ||
| 1181 | { | ||
| 1182 | int i,al,ok; | ||
| 1183 | long n; | ||
| 1184 | unsigned long l; | ||
| 1185 | unsigned char *p; | ||
| 1186 | RSA *rsa=NULL; | ||
| 1187 | EVP_PKEY *pkey=NULL; | ||
| 1188 | #ifndef NO_DH | ||
| 1189 | BIGNUM *pub=NULL; | ||
| 1190 | DH *dh_srvr; | ||
| 1191 | #endif | ||
| 1192 | |||
| 1193 | n=ssl3_get_message(s, | ||
| 1194 | SSL3_ST_SR_KEY_EXCH_A, | ||
| 1195 | SSL3_ST_SR_KEY_EXCH_B, | ||
| 1196 | SSL3_MT_CLIENT_KEY_EXCHANGE, | ||
| 1197 | 400, /* ???? */ | ||
| 1198 | &ok); | ||
| 1199 | |||
| 1200 | if (!ok) return((int)n); | ||
| 1201 | p=(unsigned char *)s->init_buf->data; | ||
| 1202 | |||
| 1203 | l=s->s3->tmp.new_cipher->algorithms; | ||
| 1204 | |||
| 1205 | #ifndef NO_RSA | ||
| 1206 | if (l & SSL_kRSA) | ||
| 1207 | { | ||
| 1208 | /* FIX THIS UP EAY EAY EAY EAY */ | ||
| 1209 | if (s->s3->tmp.use_rsa_tmp) | ||
| 1210 | { | ||
| 1211 | if ((s->session->cert != NULL) && | ||
| 1212 | (s->session->cert->rsa_tmp != NULL)) | ||
| 1213 | rsa=s->session->cert->rsa_tmp; | ||
| 1214 | else if ((s->ctx->default_cert != NULL) && | ||
| 1215 | (s->ctx->default_cert->rsa_tmp != NULL)) | ||
| 1216 | rsa=s->ctx->default_cert->rsa_tmp; | ||
| 1217 | /* Don't do a callback because rsa_tmp should | ||
| 1218 | * be sent already */ | ||
| 1219 | if (rsa == NULL) | ||
| 1220 | { | ||
| 1221 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
| 1222 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_RSA_PKEY); | ||
| 1223 | goto f_err; | ||
| 1224 | |||
| 1225 | } | ||
| 1226 | } | ||
| 1227 | else | ||
| 1228 | { | ||
| 1229 | pkey=s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey; | ||
| 1230 | if ( (pkey == NULL) || | ||
| 1231 | (pkey->type != EVP_PKEY_RSA) || | ||
| 1232 | (pkey->pkey.rsa == NULL)) | ||
| 1233 | { | ||
| 1234 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
| 1235 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_RSA_CERTIFICATE); | ||
| 1236 | goto f_err; | ||
| 1237 | } | ||
| 1238 | rsa=pkey->pkey.rsa; | ||
| 1239 | } | ||
| 1240 | |||
| 1241 | /* TLS */ | ||
| 1242 | if (s->version > SSL3_VERSION) | ||
| 1243 | { | ||
| 1244 | n2s(p,i); | ||
| 1245 | if (n != i+2) | ||
| 1246 | { | ||
| 1247 | if (!(s->options & SSL_OP_TLS_D5_BUG)) | ||
| 1248 | { | ||
| 1249 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG); | ||
| 1250 | goto err; | ||
| 1251 | } | ||
| 1252 | else | ||
| 1253 | p-=2; | ||
| 1254 | } | ||
| 1255 | else | ||
| 1256 | n=i; | ||
| 1257 | } | ||
| 1258 | |||
| 1259 | i=RSA_private_decrypt((int)n,p,p,rsa,RSA_PKCS1_PADDING); | ||
| 1260 | |||
| 1261 | #if 1 | ||
| 1262 | /* If a bad decrypt, use a dud master key */ | ||
| 1263 | if ((i != SSL_MAX_MASTER_KEY_LENGTH) || | ||
| 1264 | ((p[0] != (s->version>>8)) || | ||
| 1265 | (p[1] != (s->version & 0xff)))) | ||
| 1266 | { | ||
| 1267 | p[0]=(s->version>>8); | ||
| 1268 | p[1]=(s->version & 0xff); | ||
| 1269 | RAND_bytes(&(p[2]),SSL_MAX_MASTER_KEY_LENGTH-2); | ||
| 1270 | i=SSL_MAX_MASTER_KEY_LENGTH; | ||
| 1271 | } | ||
| 1272 | #else | ||
| 1273 | if (i != SSL_MAX_MASTER_KEY_LENGTH) | ||
| 1274 | { | ||
| 1275 | al=SSL_AD_DECODE_ERROR; | ||
| 1276 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT); | ||
| 1277 | goto f_err; | ||
| 1278 | } | ||
| 1279 | |||
| 1280 | if ((p[0] != (s->version>>8)) || (p[1] != (s->version & 0xff))) | ||
| 1281 | { | ||
| 1282 | al=SSL_AD_DECODE_ERROR; | ||
| 1283 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_PROTOCOL_VERSION_NUMBER); | ||
| 1284 | goto f_err; | ||
| 1285 | } | ||
| 1286 | #endif | ||
| 1287 | |||
| 1288 | s->session->master_key_length= | ||
| 1289 | s->method->ssl3_enc->generate_master_secret(s, | ||
| 1290 | s->session->master_key, | ||
| 1291 | p,i); | ||
| 1292 | memset(p,0,i); | ||
| 1293 | } | ||
| 1294 | else | ||
| 1295 | #endif | ||
| 1296 | #ifndef NO_DH | ||
| 1297 | if (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd)) | ||
| 1298 | { | ||
| 1299 | n2s(p,i); | ||
| 1300 | if (n != i+2) | ||
| 1301 | { | ||
| 1302 | if (!(s->options & SSL_OP_SSLEAY_080_CLIENT_DH_BUG)) | ||
| 1303 | { | ||
| 1304 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG); | ||
| 1305 | goto err; | ||
| 1306 | } | ||
| 1307 | else | ||
| 1308 | { | ||
| 1309 | p-=2; | ||
| 1310 | i=(int)n; | ||
| 1311 | } | ||
| 1312 | } | ||
| 1313 | |||
| 1314 | if (n == 0L) /* the parameters are in the cert */ | ||
| 1315 | { | ||
| 1316 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
| 1317 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_UNABLE_TO_DECODE_DH_CERTS); | ||
| 1318 | goto f_err; | ||
| 1319 | } | ||
| 1320 | else | ||
| 1321 | { | ||
| 1322 | if (s->s3->tmp.dh == NULL) | ||
| 1323 | { | ||
| 1324 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
| 1325 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_DH_KEY); | ||
| 1326 | goto f_err; | ||
| 1327 | } | ||
| 1328 | else | ||
| 1329 | dh_srvr=s->s3->tmp.dh; | ||
| 1330 | } | ||
| 1331 | |||
| 1332 | pub=BN_bin2bn(p,i,NULL); | ||
| 1333 | if (pub == NULL) | ||
| 1334 | { | ||
| 1335 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BN_LIB); | ||
| 1336 | goto err; | ||
| 1337 | } | ||
| 1338 | |||
| 1339 | i=DH_compute_key(p,pub,dh_srvr); | ||
| 1340 | |||
| 1341 | if (i <= 0) | ||
| 1342 | { | ||
| 1343 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
| 1344 | goto err; | ||
| 1345 | } | ||
| 1346 | |||
| 1347 | DH_free(s->s3->tmp.dh); | ||
| 1348 | s->s3->tmp.dh=NULL; | ||
| 1349 | |||
| 1350 | BN_clear_free(pub); | ||
| 1351 | pub=NULL; | ||
| 1352 | s->session->master_key_length= | ||
| 1353 | s->method->ssl3_enc->generate_master_secret(s, | ||
| 1354 | s->session->master_key,p,i); | ||
| 1355 | } | ||
| 1356 | else | ||
| 1357 | #endif | ||
| 1358 | { | ||
| 1359 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
| 1360 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_UNKNOWN_CIPHER_TYPE); | ||
| 1361 | goto f_err; | ||
| 1362 | } | ||
| 1363 | |||
| 1364 | return(1); | ||
| 1365 | f_err: | ||
| 1366 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
| 1367 | #if !defined(NO_DH) || !defined(NO_RSA) | ||
| 1368 | err: | ||
| 1369 | #endif | ||
| 1370 | return(-1); | ||
| 1371 | } | ||
| 1372 | |||
| 1373 | static int ssl3_get_cert_verify(s) | ||
| 1374 | SSL *s; | ||
| 1375 | { | ||
| 1376 | EVP_PKEY *pkey=NULL; | ||
| 1377 | unsigned char *p; | ||
| 1378 | int al,ok,ret=0; | ||
| 1379 | long n; | ||
| 1380 | int type=0,i,j; | ||
| 1381 | X509 *peer; | ||
| 1382 | |||
| 1383 | n=ssl3_get_message(s, | ||
| 1384 | SSL3_ST_SR_CERT_VRFY_A, | ||
| 1385 | SSL3_ST_SR_CERT_VRFY_B, | ||
| 1386 | -1, | ||
| 1387 | 512, /* 512? */ | ||
| 1388 | &ok); | ||
| 1389 | |||
| 1390 | if (!ok) return((int)n); | ||
| 1391 | |||
| 1392 | if (s->session->peer != NULL) | ||
| 1393 | { | ||
| 1394 | peer=s->session->peer; | ||
| 1395 | pkey=X509_get_pubkey(peer); | ||
| 1396 | type=X509_certificate_type(peer,pkey); | ||
| 1397 | } | ||
| 1398 | else | ||
| 1399 | { | ||
| 1400 | peer=NULL; | ||
| 1401 | pkey=NULL; | ||
| 1402 | } | ||
| 1403 | |||
| 1404 | if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE_VERIFY) | ||
| 1405 | { | ||
| 1406 | s->s3->tmp.reuse_message=1; | ||
| 1407 | if ((peer != NULL) && (type | EVP_PKT_SIGN)) | ||
| 1408 | { | ||
| 1409 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
| 1410 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_MISSING_VERIFY_MESSAGE); | ||
| 1411 | goto f_err; | ||
| 1412 | } | ||
| 1413 | ret=1; | ||
| 1414 | goto end; | ||
| 1415 | } | ||
| 1416 | |||
| 1417 | if (peer == NULL) | ||
| 1418 | { | ||
| 1419 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_NO_CLIENT_CERT_RECEIVED); | ||
| 1420 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
| 1421 | goto f_err; | ||
| 1422 | } | ||
| 1423 | |||
| 1424 | if (!(type & EVP_PKT_SIGN)) | ||
| 1425 | { | ||
| 1426 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE); | ||
| 1427 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
| 1428 | goto f_err; | ||
| 1429 | } | ||
| 1430 | |||
| 1431 | if (s->s3->change_cipher_spec) | ||
| 1432 | { | ||
| 1433 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_CCS_RECEIVED_EARLY); | ||
| 1434 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
| 1435 | goto f_err; | ||
| 1436 | } | ||
| 1437 | |||
| 1438 | /* we now have a signature that we need to verify */ | ||
| 1439 | p=(unsigned char *)s->init_buf->data; | ||
| 1440 | n2s(p,i); | ||
| 1441 | n-=2; | ||
| 1442 | if (i > n) | ||
| 1443 | { | ||
| 1444 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_LENGTH_MISMATCH); | ||
| 1445 | al=SSL_AD_DECODE_ERROR; | ||
| 1446 | goto f_err; | ||
| 1447 | } | ||
| 1448 | |||
| 1449 | j=EVP_PKEY_size(pkey); | ||
| 1450 | if ((i > j) || (n > j) || (n <= 0)) | ||
| 1451 | { | ||
| 1452 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_WRONG_SIGNATURE_SIZE); | ||
| 1453 | al=SSL_AD_DECODE_ERROR; | ||
| 1454 | goto f_err; | ||
| 1455 | } | ||
| 1456 | |||
| 1457 | #ifndef NO_RSA | ||
| 1458 | if (pkey->type == EVP_PKEY_RSA) | ||
| 1459 | { | ||
| 1460 | i=RSA_public_decrypt(i,p,p,pkey->pkey.rsa,RSA_PKCS1_PADDING); | ||
| 1461 | if (i < 0) | ||
| 1462 | { | ||
| 1463 | al=SSL_AD_DECRYPT_ERROR; | ||
| 1464 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_BAD_RSA_DECRYPT); | ||
| 1465 | goto f_err; | ||
| 1466 | } | ||
| 1467 | if ((i != (MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH)) || | ||
| 1468 | memcmp(&(s->s3->tmp.finish_md[0]),p, | ||
| 1469 | MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH)) | ||
| 1470 | { | ||
| 1471 | al=SSL_AD_DECRYPT_ERROR; | ||
| 1472 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_BAD_RSA_SIGNATURE); | ||
| 1473 | goto f_err; | ||
| 1474 | } | ||
| 1475 | } | ||
| 1476 | else | ||
| 1477 | #endif | ||
| 1478 | #ifndef NO_DSA | ||
| 1479 | if (pkey->type == EVP_PKEY_DSA) | ||
| 1480 | { | ||
| 1481 | j=DSA_verify(pkey->save_type, | ||
| 1482 | &(s->s3->tmp.finish_md[MD5_DIGEST_LENGTH]), | ||
| 1483 | SHA_DIGEST_LENGTH,p,i,pkey->pkey.dsa); | ||
| 1484 | if (j <= 0) | ||
| 1485 | { | ||
| 1486 | /* bad signature */ | ||
| 1487 | al=SSL_AD_DECRYPT_ERROR; | ||
| 1488 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_BAD_DSA_SIGNATURE); | ||
| 1489 | goto f_err; | ||
| 1490 | } | ||
| 1491 | } | ||
| 1492 | else | ||
| 1493 | #endif | ||
| 1494 | { | ||
| 1495 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_INTERNAL_ERROR); | ||
| 1496 | al=SSL_AD_UNSUPPORTED_CERTIFICATE; | ||
| 1497 | goto f_err; | ||
| 1498 | } | ||
| 1499 | |||
| 1500 | |||
| 1501 | ret=1; | ||
| 1502 | if (0) | ||
| 1503 | { | ||
| 1504 | f_err: | ||
| 1505 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
| 1506 | } | ||
| 1507 | end: | ||
| 1508 | return(ret); | ||
| 1509 | } | ||
| 1510 | |||
| 1511 | static int ssl3_get_client_certificate(s) | ||
| 1512 | SSL *s; | ||
| 1513 | { | ||
| 1514 | int i,ok,al,ret= -1; | ||
| 1515 | X509 *x=NULL; | ||
| 1516 | unsigned long l,nc,llen,n; | ||
| 1517 | unsigned char *p,*d,*q; | ||
| 1518 | STACK *sk=NULL; | ||
| 1519 | |||
| 1520 | n=ssl3_get_message(s, | ||
| 1521 | SSL3_ST_SR_CERT_A, | ||
| 1522 | SSL3_ST_SR_CERT_B, | ||
| 1523 | -1, | ||
| 1524 | #if defined(MSDOS) && !defined(WIN32) | ||
| 1525 | 1024*30, /* 30k max cert list :-) */ | ||
| 1526 | #else | ||
| 1527 | 1024*100, /* 100k max cert list :-) */ | ||
| 1528 | #endif | ||
| 1529 | &ok); | ||
| 1530 | |||
| 1531 | if (!ok) return((int)n); | ||
| 1532 | |||
| 1533 | if (s->s3->tmp.message_type == SSL3_MT_CLIENT_KEY_EXCHANGE) | ||
| 1534 | { | ||
| 1535 | if ( (s->verify_mode & SSL_VERIFY_PEER) && | ||
| 1536 | (s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)) | ||
| 1537 | { | ||
| 1538 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE); | ||
| 1539 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
| 1540 | goto f_err; | ||
| 1541 | } | ||
| 1542 | /* If tls asked for a client cert we must return a 0 list */ | ||
| 1543 | if ((s->version > SSL3_VERSION) && s->s3->tmp.cert_request) | ||
| 1544 | { | ||
| 1545 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST); | ||
| 1546 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
| 1547 | goto f_err; | ||
| 1548 | } | ||
| 1549 | s->s3->tmp.reuse_message=1; | ||
| 1550 | return(1); | ||
| 1551 | } | ||
| 1552 | |||
| 1553 | if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE) | ||
| 1554 | { | ||
| 1555 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
| 1556 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_WRONG_MESSAGE_TYPE); | ||
| 1557 | goto f_err; | ||
| 1558 | } | ||
| 1559 | d=p=(unsigned char *)s->init_buf->data; | ||
| 1560 | |||
| 1561 | if ((sk=sk_new_null()) == NULL) | ||
| 1562 | { | ||
| 1563 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_MALLOC_FAILURE); | ||
| 1564 | goto err; | ||
| 1565 | } | ||
| 1566 | |||
| 1567 | n2l3(p,llen); | ||
| 1568 | if (llen+3 != n) | ||
| 1569 | { | ||
| 1570 | al=SSL_AD_DECODE_ERROR; | ||
| 1571 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_LENGTH_MISMATCH); | ||
| 1572 | goto f_err; | ||
| 1573 | } | ||
| 1574 | for (nc=0; nc<llen; ) | ||
| 1575 | { | ||
| 1576 | n2l3(p,l); | ||
| 1577 | if ((l+nc+3) > llen) | ||
| 1578 | { | ||
| 1579 | al=SSL_AD_DECODE_ERROR; | ||
| 1580 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH); | ||
| 1581 | goto f_err; | ||
| 1582 | } | ||
| 1583 | |||
| 1584 | q=p; | ||
| 1585 | x=d2i_X509(NULL,&p,l); | ||
| 1586 | if (x == NULL) | ||
| 1587 | { | ||
| 1588 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_ASN1_LIB); | ||
| 1589 | goto err; | ||
| 1590 | } | ||
| 1591 | if (p != (q+l)) | ||
| 1592 | { | ||
| 1593 | al=SSL_AD_DECODE_ERROR; | ||
| 1594 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH); | ||
| 1595 | goto f_err; | ||
| 1596 | } | ||
| 1597 | if (!sk_push(sk,(char *)x)) | ||
| 1598 | { | ||
| 1599 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_MALLOC_FAILURE); | ||
| 1600 | goto err; | ||
| 1601 | } | ||
| 1602 | x=NULL; | ||
| 1603 | nc+=l+3; | ||
| 1604 | } | ||
| 1605 | |||
| 1606 | if (sk_num(sk) <= 0) | ||
| 1607 | { | ||
| 1608 | /* TLS does not mind 0 certs returned */ | ||
| 1609 | if (s->version == SSL3_VERSION) | ||
| 1610 | { | ||
| 1611 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
| 1612 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_NO_CERTIFICATES_RETURNED); | ||
| 1613 | goto f_err; | ||
| 1614 | } | ||
| 1615 | /* Fail for TLS only if we required a certificate */ | ||
| 1616 | else if ((s->verify_mode & SSL_VERIFY_PEER) && | ||
| 1617 | (s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)) | ||
| 1618 | { | ||
| 1619 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE); | ||
| 1620 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
| 1621 | goto f_err; | ||
| 1622 | } | ||
| 1623 | } | ||
| 1624 | else | ||
| 1625 | { | ||
| 1626 | i=ssl_verify_cert_chain(s,sk); | ||
| 1627 | if (!i) | ||
| 1628 | { | ||
| 1629 | al=ssl_verify_alarm_type(s->verify_result); | ||
| 1630 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_NO_CERTIFICATE_RETURNED); | ||
| 1631 | goto f_err; | ||
| 1632 | } | ||
| 1633 | } | ||
| 1634 | |||
| 1635 | /* This should not be needed */ | ||
| 1636 | if (s->session->peer != NULL) | ||
| 1637 | X509_free(s->session->peer); | ||
| 1638 | s->session->peer=(X509 *)sk_shift(sk); | ||
| 1639 | |||
| 1640 | ret=1; | ||
| 1641 | if (0) | ||
| 1642 | { | ||
| 1643 | f_err: | ||
| 1644 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
| 1645 | } | ||
| 1646 | err: | ||
| 1647 | if (x != NULL) X509_free(x); | ||
| 1648 | if (sk != NULL) sk_pop_free(sk,X509_free); | ||
| 1649 | return(ret); | ||
| 1650 | } | ||
| 1651 | |||
| 1652 | int ssl3_send_server_certificate(s) | ||
| 1653 | SSL *s; | ||
| 1654 | { | ||
| 1655 | unsigned long l; | ||
| 1656 | X509 *x; | ||
| 1657 | |||
| 1658 | if (s->state == SSL3_ST_SW_CERT_A) | ||
| 1659 | { | ||
| 1660 | x=ssl_get_server_send_cert(s); | ||
| 1661 | if (x == NULL) | ||
| 1662 | { | ||
| 1663 | SSLerr(SSL_F_SSL3_SEND_SERVER_CERTIFICATE,SSL_R_INTERNAL_ERROR); | ||
| 1664 | return(0); | ||
| 1665 | } | ||
| 1666 | |||
| 1667 | l=ssl3_output_cert_chain(s,x); | ||
| 1668 | s->state=SSL3_ST_SW_CERT_B; | ||
| 1669 | s->init_num=(int)l; | ||
| 1670 | s->init_off=0; | ||
| 1671 | } | ||
| 1672 | |||
| 1673 | /* SSL3_ST_SW_CERT_B */ | ||
| 1674 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
| 1675 | } | ||
diff --git a/src/lib/libssl/shlib_version b/src/lib/libssl/shlib_version new file mode 100644 index 0000000000..1edea46de9 --- /dev/null +++ b/src/lib/libssl/shlib_version | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | major=1 | ||
| 2 | minor=0 | ||
diff --git a/src/lib/libssl/ssl.h b/src/lib/libssl/ssl.h new file mode 100644 index 0000000000..cf8f9651b2 --- /dev/null +++ b/src/lib/libssl/ssl.h | |||
| @@ -0,0 +1,1453 @@ | |||
| 1 | /* ssl/ssl.h */ | ||
| 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 | #ifndef HEADER_SSL_H | ||
| 60 | #define HEADER_SSL_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | /* SSLeay version number for ASN.1 encoding of the session information */ | ||
| 67 | /* Version 0 - initial version | ||
| 68 | * Version 1 - added the optional peer certificate | ||
| 69 | */ | ||
| 70 | #define SSL_SESSION_ASN1_VERSION 0x0001 | ||
| 71 | |||
| 72 | /* text strings for the ciphers */ | ||
| 73 | #define SSL_TXT_NULL_WITH_MD5 SSL2_TXT_NULL_WITH_MD5 | ||
| 74 | #define SSL_TXT_RC4_128_WITH_MD5 SSL2_TXT_RC4_128_WITH_MD5 | ||
| 75 | #define SSL_TXT_RC4_128_EXPORT40_WITH_MD5 SSL2_TXT_RC4_128_EXPORT40_WITH_MD5 | ||
| 76 | #define SSL_TXT_RC2_128_CBC_WITH_MD5 SSL2_TXT_RC2_128_CBC_WITH_MD5 | ||
| 77 | #define SSL_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 | ||
| 78 | #define SSL_TXT_IDEA_128_CBC_WITH_MD5 SSL2_TXT_IDEA_128_CBC_WITH_MD5 | ||
| 79 | #define SSL_TXT_DES_64_CBC_WITH_MD5 SSL2_TXT_DES_64_CBC_WITH_MD5 | ||
| 80 | #define SSL_TXT_DES_64_CBC_WITH_SHA SSL2_TXT_DES_64_CBC_WITH_SHA | ||
| 81 | #define SSL_TXT_DES_192_EDE3_CBC_WITH_MD5 SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5 | ||
| 82 | #define SSL_TXT_DES_192_EDE3_CBC_WITH_SHA SSL2_TXT_DES_192_EDE3_CBC_WITH_SHA | ||
| 83 | |||
| 84 | #define SSL_MAX_SSL_SESSION_ID_LENGTH 32 | ||
| 85 | |||
| 86 | #define SSL_MIN_RSA_MODULUS_LENGTH_IN_BYTES (512/8) | ||
| 87 | #define SSL_MAX_KEY_ARG_LENGTH 8 | ||
| 88 | #define SSL_MAX_MASTER_KEY_LENGTH 48 | ||
| 89 | |||
| 90 | /* These are used to specify which ciphers to use and not to use */ | ||
| 91 | #define SSL_TXT_LOW "LOW" | ||
| 92 | #define SSL_TXT_MEDIUM "MEDIUM" | ||
| 93 | #define SSL_TXT_HIGH "HIGH" | ||
| 94 | #define SSL_TXT_kFZA "kFZA" | ||
| 95 | #define SSL_TXT_aFZA "aFZA" | ||
| 96 | #define SSL_TXT_eFZA "eFZA" | ||
| 97 | #define SSL_TXT_FZA "FZA" | ||
| 98 | |||
| 99 | #define SSL_TXT_aNULL "aNULL" | ||
| 100 | #define SSL_TXT_eNULL "eNULL" | ||
| 101 | #define SSL_TXT_NULL "NULL" | ||
| 102 | |||
| 103 | #define SSL_TXT_kRSA "kRSA" | ||
| 104 | #define SSL_TXT_kDHr "kDHr" | ||
| 105 | #define SSL_TXT_kDHd "kDHd" | ||
| 106 | #define SSL_TXT_kEDH "kEDH" | ||
| 107 | #define SSL_TXT_aRSA "aRSA" | ||
| 108 | #define SSL_TXT_aDSS "aDSS" | ||
| 109 | #define SSL_TXT_aDH "aDH" | ||
| 110 | #define SSL_TXT_DSS "DSS" | ||
| 111 | #define SSL_TXT_DH "DH" | ||
| 112 | #define SSL_TXT_EDH "EDH" | ||
| 113 | #define SSL_TXT_ADH "ADH" | ||
| 114 | #define SSL_TXT_RSA "RSA" | ||
| 115 | #define SSL_TXT_DES "DES" | ||
| 116 | #define SSL_TXT_3DES "3DES" | ||
| 117 | #define SSL_TXT_RC4 "RC4" | ||
| 118 | #define SSL_TXT_RC2 "RC2" | ||
| 119 | #define SSL_TXT_IDEA "IDEA" | ||
| 120 | #define SSL_TXT_MD5 "MD5" | ||
| 121 | #define SSL_TXT_SHA1 "SHA1" | ||
| 122 | #define SSL_TXT_SHA "SHA" | ||
| 123 | #define SSL_TXT_EXP "EXP" | ||
| 124 | #define SSL_TXT_EXPORT "EXPORT" | ||
| 125 | #define SSL_TXT_SSLV2 "SSLv2" | ||
| 126 | #define SSL_TXT_SSLV3 "SSLv3" | ||
| 127 | #define SSL_TXT_ALL "ALL" | ||
| 128 | |||
| 129 | /* 'DEFAULT' at the start of the cipher list insert the following string | ||
| 130 | * in addition to this being the default cipher string */ | ||
| 131 | #ifndef NO_RSA | ||
| 132 | #define SSL_DEFAULT_CIPHER_LIST "ALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP" | ||
| 133 | #else | ||
| 134 | #define SSL_ALLOW_ADH | ||
| 135 | #define SSL_DEFAULT_CIPHER_LIST "HIGH:MEDIUM:LOW:ADH+3DES:ADH+RC4:ADH+DES:+EXP" | ||
| 136 | #endif | ||
| 137 | |||
| 138 | /* Used in SSL_set_shutdown()/SSL_get_shutdown(); */ | ||
| 139 | #define SSL_SENT_SHUTDOWN 1 | ||
| 140 | #define SSL_RECEIVED_SHUTDOWN 2 | ||
| 141 | |||
| 142 | #include "crypto.h" | ||
| 143 | #include "lhash.h" | ||
| 144 | #include "buffer.h" | ||
| 145 | #include "bio.h" | ||
| 146 | #include "x509.h" | ||
| 147 | |||
| 148 | #define SSL_FILETYPE_ASN1 X509_FILETYPE_ASN1 | ||
| 149 | #define SSL_FILETYPE_PEM X509_FILETYPE_PEM | ||
| 150 | |||
| 151 | /* This is needed to stop compilers complaining about the | ||
| 152 | * 'struct ssl_st *' function parameters used to prototype callbacks | ||
| 153 | * in SSL_CTX. */ | ||
| 154 | typedef struct ssl_st *ssl_crock_st; | ||
| 155 | |||
| 156 | /* used to hold info on the particular ciphers used */ | ||
| 157 | typedef struct ssl_cipher_st | ||
| 158 | { | ||
| 159 | int valid; | ||
| 160 | char *name; /* text name */ | ||
| 161 | unsigned long id; /* id, 4 bytes, first is version */ | ||
| 162 | unsigned long algorithms; /* what ciphers are used */ | ||
| 163 | unsigned long algorithm2; /* Extra flags */ | ||
| 164 | unsigned long mask; /* used for matching */ | ||
| 165 | } SSL_CIPHER; | ||
| 166 | |||
| 167 | /* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */ | ||
| 168 | typedef struct ssl_method_st | ||
| 169 | { | ||
| 170 | int version; | ||
| 171 | int (*ssl_new)(); | ||
| 172 | void (*ssl_clear)(); | ||
| 173 | void (*ssl_free)(); | ||
| 174 | int (*ssl_accept)(); | ||
| 175 | int (*ssl_connect)(); | ||
| 176 | int (*ssl_read)(); | ||
| 177 | int (*ssl_peek)(); | ||
| 178 | int (*ssl_write)(); | ||
| 179 | int (*ssl_shutdown)(); | ||
| 180 | int (*ssl_renegotiate)(); | ||
| 181 | long (*ssl_ctrl)(); | ||
| 182 | long (*ssl_ctx_ctrl)(); | ||
| 183 | SSL_CIPHER *(*get_cipher_by_char)(); | ||
| 184 | int (*put_cipher_by_char)(); | ||
| 185 | int (*ssl_pending)(); | ||
| 186 | int (*num_ciphers)(); | ||
| 187 | SSL_CIPHER *(*get_cipher)(); | ||
| 188 | struct ssl_method_st *(*get_ssl_method)(); | ||
| 189 | long (*get_timeout)(); | ||
| 190 | struct ssl3_enc_method *ssl3_enc; /* Extra SSLv3/TLS stuff */ | ||
| 191 | } SSL_METHOD; | ||
| 192 | |||
| 193 | typedef struct ssl_compression_st | ||
| 194 | { | ||
| 195 | char *stuff; | ||
| 196 | } SSL_COMPRESSION; | ||
| 197 | |||
| 198 | /* Lets make this into an ASN.1 type structure as follows | ||
| 199 | * SSL_SESSION_ID ::= SEQUENCE { | ||
| 200 | * version INTEGER, -- structure version number | ||
| 201 | * SSLversion INTEGER, -- SSL version number | ||
| 202 | * Cipher OCTET_STRING, -- the 3 byte cipher ID | ||
| 203 | * Session_ID OCTET_STRING, -- the Session ID | ||
| 204 | * Master_key OCTET_STRING, -- the master key | ||
| 205 | * Key_Arg [ 0 ] IMPLICIT OCTET_STRING, -- the optional Key argument | ||
| 206 | * Time [ 1 ] EXPLICIT INTEGER, -- optional Start Time | ||
| 207 | * Timeout [ 2 ] EXPLICIT INTEGER, -- optional Timeout ins seconds | ||
| 208 | * Peer [ 3 ] EXPLICIT X509, -- optional Peer Certificate | ||
| 209 | * } | ||
| 210 | * Look in ssl/ssl_asn1.c for more details | ||
| 211 | * I'm using EXPLICIT tags so I can read the damn things using asn1parse :-). | ||
| 212 | */ | ||
| 213 | typedef struct ssl_session_st | ||
| 214 | { | ||
| 215 | int ssl_version; /* what ssl version session info is | ||
| 216 | * being kept in here? */ | ||
| 217 | |||
| 218 | /* only really used in SSLv2 */ | ||
| 219 | unsigned int key_arg_length; | ||
| 220 | unsigned char key_arg[SSL_MAX_KEY_ARG_LENGTH]; | ||
| 221 | int master_key_length; | ||
| 222 | unsigned char master_key[SSL_MAX_MASTER_KEY_LENGTH]; | ||
| 223 | /* session_id - valid? */ | ||
| 224 | unsigned int session_id_length; | ||
| 225 | unsigned char session_id[SSL_MAX_SSL_SESSION_ID_LENGTH]; | ||
| 226 | |||
| 227 | int not_resumable; | ||
| 228 | |||
| 229 | /* The cert is the certificate used to establish this connection */ | ||
| 230 | struct cert_st /* CERT */ *cert; | ||
| 231 | |||
| 232 | /* This is the cert for the other end. On servers, it will be | ||
| 233 | * the same as cert->x509 */ | ||
| 234 | X509 *peer; | ||
| 235 | |||
| 236 | int references; | ||
| 237 | long timeout; | ||
| 238 | long time; | ||
| 239 | |||
| 240 | SSL_COMPRESSION *read_compression; | ||
| 241 | SSL_COMPRESSION *write_compression; | ||
| 242 | |||
| 243 | SSL_CIPHER *cipher; | ||
| 244 | unsigned long cipher_id; /* when ASN.1 loaded, this | ||
| 245 | * needs to be used to load | ||
| 246 | * the 'cipher' structure */ | ||
| 247 | |||
| 248 | STACK /* SSL_CIPHER */ *ciphers; /* shared ciphers? */ | ||
| 249 | |||
| 250 | CRYPTO_EX_DATA ex_data; /* application specific data */ | ||
| 251 | |||
| 252 | /* These are used to make removal of session-ids more | ||
| 253 | * efficient and to implement a maximum cache size. */ | ||
| 254 | struct ssl_session_st *prev,*next; | ||
| 255 | } SSL_SESSION; | ||
| 256 | |||
| 257 | #define SSL_OP_MICROSOFT_SESS_ID_BUG 0x00000001L | ||
| 258 | #define SSL_OP_NETSCAPE_CHALLENGE_BUG 0x00000002L | ||
| 259 | #define SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG 0x00000008L | ||
| 260 | #define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG 0x00000010L | ||
| 261 | #define SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER 0x00000020L | ||
| 262 | #define SSL_OP_MSIE_SSLV2_RSA_PADDING 0x00000040L | ||
| 263 | #define SSL_OP_SSLEAY_080_CLIENT_DH_BUG 0x00000080L | ||
| 264 | #define SSL_OP_TLS_D5_BUG 0x00000100L | ||
| 265 | #define SSL_OP_TLS_BLOCK_PADDING_BUG 0x00000200L | ||
| 266 | |||
| 267 | /* If set, only use tmp_dh parameters once */ | ||
| 268 | #define SSL_OP_SINGLE_DH_USE 0x00100000L | ||
| 269 | /* Set to also use the tmp_rsa key when doing RSA operations. */ | ||
| 270 | #define SSL_OP_EPHEMERAL_RSA 0x00200000L | ||
| 271 | |||
| 272 | #define SSL_OP_NETSCAPE_CA_DN_BUG 0x20000000L | ||
| 273 | #define SSL_OP_NON_EXPORT_FIRST 0x40000000L | ||
| 274 | #define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG 0x80000000L | ||
| 275 | #define SSL_OP_ALL 0x000FFFFFL | ||
| 276 | |||
| 277 | #define SSL_CTX_set_options(ctx,op) ((ctx)->options|=(op)) | ||
| 278 | #define SSL_set_options(ssl,op) ((ssl)->options|=(op)) | ||
| 279 | |||
| 280 | #define SSL_OP_NO_SSLv2 0x01000000L | ||
| 281 | #define SSL_OP_NO_SSLv3 0x02000000L | ||
| 282 | #define SSL_OP_NO_TLSv1 0x04000000L | ||
| 283 | |||
| 284 | /* Normally you will only use these if your application wants to use | ||
| 285 | * the certificate store in other places, perhaps PKCS7 */ | ||
| 286 | #define SSL_CTX_get_cert_store(ctx) ((ctx)->cert_store) | ||
| 287 | #define SSL_CTX_set_cert_store(ctx,cs) \ | ||
| 288 | (X509_STORE_free((ctx)->cert_store),(ctx)->cert_store=(cs)) | ||
| 289 | |||
| 290 | |||
| 291 | #define SSL_SESSION_CACHE_MAX_SIZE_DEFAULT (1024*20) | ||
| 292 | |||
| 293 | typedef struct ssl_ctx_st | ||
| 294 | { | ||
| 295 | SSL_METHOD *method; | ||
| 296 | unsigned long options; | ||
| 297 | |||
| 298 | STACK /* SSL_CIPHER */ *cipher_list; | ||
| 299 | /* same as above but sorted for lookup */ | ||
| 300 | STACK /* SSL_CIPHER */ *cipher_list_by_id; | ||
| 301 | |||
| 302 | struct x509_store_st /* X509_STORE */ *cert_store; | ||
| 303 | struct lhash_st /* LHASH */ *sessions; /* a set of SSL_SESSION's */ | ||
| 304 | /* Most session-ids that will be cached, default is | ||
| 305 | * SSL_SESSION_CACHE_SIZE_DEFAULT. 0 is unlimited. */ | ||
| 306 | unsigned long session_cache_size; | ||
| 307 | struct ssl_session_st *session_cache_head; | ||
| 308 | struct ssl_session_st *session_cache_tail; | ||
| 309 | |||
| 310 | /* This can have one of 2 values, ored together, | ||
| 311 | * SSL_SESS_CACHE_CLIENT, | ||
| 312 | * SSL_SESS_CACHE_SERVER, | ||
| 313 | * Default is SSL_SESSION_CACHE_SERVER, which means only | ||
| 314 | * SSL_accept which cache SSL_SESSIONS. */ | ||
| 315 | int session_cache_mode; | ||
| 316 | |||
| 317 | /* If timeout is not 0, it is the default timeout value set | ||
| 318 | * when SSL_new() is called. This has been put in to make | ||
| 319 | * life easier to set things up */ | ||
| 320 | long session_timeout; | ||
| 321 | |||
| 322 | /* If this callback is not null, it will be called each | ||
| 323 | * time a session id is added to the cache. If this function | ||
| 324 | * returns 1, it means that the callback will do a | ||
| 325 | * SSL_SESSION_free() when it has finished using it. Otherwise, | ||
| 326 | * on 0, it means the callback has finished with it. | ||
| 327 | * If remove_session_cb is not null, it will be called when | ||
| 328 | * a session-id is removed from the cache. Again, a return | ||
| 329 | * of 0 mens that SSLeay should not SSL_SESSION_free() since | ||
| 330 | * the application is doing something with it. */ | ||
| 331 | #ifndef NOPROTO | ||
| 332 | int (*new_session_cb)(struct ssl_st *ssl,SSL_SESSION *sess); | ||
| 333 | void (*remove_session_cb)(struct ssl_ctx_st *ctx,SSL_SESSION *sess); | ||
| 334 | SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl, | ||
| 335 | unsigned char *data,int len,int *copy); | ||
| 336 | #else | ||
| 337 | int (*new_session_cb)(); | ||
| 338 | void (*remove_session_cb)(); | ||
| 339 | SSL_SESSION *(*get_session_cb)(); | ||
| 340 | #endif | ||
| 341 | |||
| 342 | int sess_connect; /* SSL new connection - started */ | ||
| 343 | int sess_connect_renegotiate;/* SSL renegotiatene - requested */ | ||
| 344 | int sess_connect_good; /* SSL new connection/renegotiate - finished */ | ||
| 345 | int sess_accept; /* SSL new accept - started */ | ||
| 346 | int sess_accept_renegotiate;/* SSL renegotiatene - requested */ | ||
| 347 | int sess_accept_good; /* SSL accept/renegotiate - finished */ | ||
| 348 | int sess_miss; /* session lookup misses */ | ||
| 349 | int sess_timeout; /* session reuse attempt on timeouted session */ | ||
| 350 | int sess_cache_full; /* session removed due to full cache */ | ||
| 351 | int sess_hit; /* session reuse actually done */ | ||
| 352 | int sess_cb_hit; /* session-id that was not in the cache was | ||
| 353 | * passed back via the callback. This | ||
| 354 | * indicates that the application is supplying | ||
| 355 | * session-id's from other processes - | ||
| 356 | * spooky :-) */ | ||
| 357 | |||
| 358 | int references; | ||
| 359 | |||
| 360 | void (*info_callback)(); | ||
| 361 | |||
| 362 | /* if defined, these override the X509_verify_cert() calls */ | ||
| 363 | int (*app_verify_callback)(); | ||
| 364 | char *app_verify_arg; | ||
| 365 | |||
| 366 | /* default values to use in SSL structures */ | ||
| 367 | struct cert_st /* CERT */ *default_cert; | ||
| 368 | int default_read_ahead; | ||
| 369 | int default_verify_mode; | ||
| 370 | int (*default_verify_callback)(); | ||
| 371 | |||
| 372 | /* Default password callback. */ | ||
| 373 | int (*default_passwd_callback)(); | ||
| 374 | |||
| 375 | /* get client cert callback */ | ||
| 376 | int (*client_cert_cb)(/* SSL *ssl, X509 **x509, EVP_PKEY **pkey */); | ||
| 377 | |||
| 378 | /* what we put in client requests */ | ||
| 379 | STACK *client_CA; | ||
| 380 | |||
| 381 | int quiet_shutdown; | ||
| 382 | |||
| 383 | CRYPTO_EX_DATA ex_data; | ||
| 384 | |||
| 385 | EVP_MD *rsa_md5;/* For SSLv2 - name is 'ssl2-md5' */ | ||
| 386 | EVP_MD *md5; /* For SSLv3/TLSv1 'ssl3-md5' */ | ||
| 387 | EVP_MD *sha1; /* For SSLv3/TLSv1 'ssl3->sha1' */ | ||
| 388 | } SSL_CTX; | ||
| 389 | |||
| 390 | #define SSL_SESS_CACHE_OFF 0x0000 | ||
| 391 | #define SSL_SESS_CACHE_CLIENT 0x0001 | ||
| 392 | #define SSL_SESS_CACHE_SERVER 0x0002 | ||
| 393 | #define SSL_SESS_CACHE_BOTH (SSL_SESS_CACHE_CLIENT|SSL_SESS_CACHE_SERVER) | ||
| 394 | #define SSL_SESS_CACHE_NO_AUTO_CLEAR 0x0080 | ||
| 395 | /* This one, when set, makes the server session-id lookup not look | ||
| 396 | * in the cache. If there is an application get_session callback | ||
| 397 | * defined, this will still get called. */ | ||
| 398 | #define SSL_SESS_CACHE_NO_INTERNAL_LOOKUP 0x0100 | ||
| 399 | |||
| 400 | #define SSL_CTX_sessions(ctx) ((ctx)->sessions) | ||
| 401 | /* You will need to include lhash.h to access the following #define */ | ||
| 402 | #define SSL_CTX_sess_number(ctx) ((ctx)->sessions->num_items) | ||
| 403 | #define SSL_CTX_sess_connect(ctx) ((ctx)->sess_connect) | ||
| 404 | #define SSL_CTX_sess_connect_good(ctx) ((ctx)->sess_connect_good) | ||
| 405 | #define SSL_CTX_sess_accept(ctx) ((ctx)->sess_accept) | ||
| 406 | #define SSL_CTX_sess_accept_renegotiate(ctx) ((ctx)->sess_accept_renegotiate) | ||
| 407 | #define SSL_CTX_sess_connect_renegotiate(ctx) ((ctx)->sess_connect_renegotiate) | ||
| 408 | #define SSL_CTX_sess_accept_good(ctx) ((ctx)->sess_accept_good) | ||
| 409 | #define SSL_CTX_sess_hits(ctx) ((ctx)->sess_hit) | ||
| 410 | #define SSL_CTX_sess_cb_hits(ctx) ((ctx)->sess_cb_hit) | ||
| 411 | #define SSL_CTX_sess_misses(ctx) ((ctx)->sess_miss) | ||
| 412 | #define SSL_CTX_sess_timeouts(ctx) ((ctx)->sess_timeout) | ||
| 413 | #define SSL_CTX_sess_cache_full(ctx) ((ctx)->sess_cache_full) | ||
| 414 | |||
| 415 | #define SSL_CTX_sess_set_cache_size(ctx,t) ((ctx)->session_cache_size=(t)) | ||
| 416 | #define SSL_CTX_sess_get_cache_size(ctx) ((ctx)->session_cache_size) | ||
| 417 | |||
| 418 | #define SSL_CTX_sess_set_new_cb(ctx,cb) ((ctx)->new_session_cb=(cb)) | ||
| 419 | #define SSL_CTX_sess_get_new_cb(ctx) ((ctx)->new_session_cb) | ||
| 420 | #define SSL_CTX_sess_set_remove_cb(ctx,cb) ((ctx)->remove_session_cb=(cb)) | ||
| 421 | #define SSL_CTX_sess_get_remove_cb(ctx) ((ctx)->remove_session_cb) | ||
| 422 | #define SSL_CTX_sess_set_get_cb(ctx,cb) ((ctx)->get_session_cb=(cb)) | ||
| 423 | #define SSL_CTX_sess_get_get_cb(ctx) ((ctx)->get_session_cb) | ||
| 424 | #define SSL_CTX_set_session_cache_mode(ctx,m) ((ctx)->session_cache_mode=(m)) | ||
| 425 | #define SSL_CTX_get_session_cache_mode(ctx) ((ctx)->session_cache_mode) | ||
| 426 | #define SSL_CTX_set_timeout(ctx,t) ((ctx)->session_timeout=(t)) | ||
| 427 | #define SSL_CTX_get_timeout(ctx) ((ctx)->session_timeout) | ||
| 428 | |||
| 429 | #define SSL_CTX_set_info_callback(ctx,cb) ((ctx)->info_callback=(cb)) | ||
| 430 | #define SSL_CTX_get_info_callback(ctx) ((ctx)->info_callback) | ||
| 431 | #define SSL_CTX_set_default_read_ahead(ctx,m) (((ctx)->default_read_ahead)=(m)) | ||
| 432 | |||
| 433 | #define SSL_CTX_set_client_cert_cb(ctx,cb) ((ctx)->client_cert_cb=(cb)) | ||
| 434 | #define SSL_CTX_get_client_cert_cb(ctx) ((ctx)->client_cert_cb) | ||
| 435 | |||
| 436 | #define SSL_NOTHING 1 | ||
| 437 | #define SSL_WRITING 2 | ||
| 438 | #define SSL_READING 3 | ||
| 439 | #define SSL_X509_LOOKUP 4 | ||
| 440 | |||
| 441 | /* These will only be used when doing non-blocking IO */ | ||
| 442 | #define SSL_want(s) ((s)->rwstate) | ||
| 443 | #define SSL_want_nothing(s) ((s)->rwstate == SSL_NOTHING) | ||
| 444 | #define SSL_want_read(s) ((s)->rwstate == SSL_READING) | ||
| 445 | #define SSL_want_write(s) ((s)->rwstate == SSL_WRITING) | ||
| 446 | #define SSL_want_x509_lookup(s) ((s)->rwstate == SSL_X509_LOOKUP) | ||
| 447 | |||
| 448 | typedef struct ssl_st | ||
| 449 | { | ||
| 450 | /* procol version | ||
| 451 | * 2 for SSLv2 | ||
| 452 | * 3 for SSLv3 | ||
| 453 | * -3 for SSLv3 but accept SSLv2 */ | ||
| 454 | int version; | ||
| 455 | int type; /* SSL_ST_CONNECT or SSL_ST_ACCEPT */ | ||
| 456 | |||
| 457 | SSL_METHOD *method; /* SSLv3 */ | ||
| 458 | |||
| 459 | /* There are 2 BIO's even though they are normally both the | ||
| 460 | * same. This is so data can be read and written to different | ||
| 461 | * handlers */ | ||
| 462 | |||
| 463 | #ifdef HEADER_BIO_H | ||
| 464 | BIO *rbio; /* used by SSL_read */ | ||
| 465 | BIO *wbio; /* used by SSL_write */ | ||
| 466 | BIO *bbio; /* used during session-id reuse to concatinate | ||
| 467 | * messages */ | ||
| 468 | #else | ||
| 469 | char *rbio; /* used by SSL_read */ | ||
| 470 | char *wbio; /* used by SSL_write */ | ||
| 471 | char *bbio; | ||
| 472 | #endif | ||
| 473 | /* This holds a variable that indicates what we were doing | ||
| 474 | * when a 0 or -1 is returned. This is needed for | ||
| 475 | * non-blocking IO so we know what request needs re-doing when | ||
| 476 | * in SSL_accept or SSL_connect */ | ||
| 477 | int rwstate; | ||
| 478 | |||
| 479 | /* true when we are actually in SSL_accept() or SSL_connect() */ | ||
| 480 | int in_handshake; | ||
| 481 | int (*handshake_func)(); | ||
| 482 | |||
| 483 | /* int server;*/ /* are we the server side? */ | ||
| 484 | |||
| 485 | int new_session;/* 1 if we are to use a new session */ | ||
| 486 | int quiet_shutdown;/* don't send shutdown packets */ | ||
| 487 | int shutdown; /* we have shut things down, 0x01 sent, 0x02 | ||
| 488 | * for received */ | ||
| 489 | int state; /* where we are */ | ||
| 490 | int rstate; /* where we are when reading */ | ||
| 491 | |||
| 492 | BUF_MEM *init_buf; /* buffer used during init */ | ||
| 493 | int init_num; /* amount read/written */ | ||
| 494 | int init_off; /* amount read/written */ | ||
| 495 | |||
| 496 | /* used internally to point at a raw packet */ | ||
| 497 | unsigned char *packet; | ||
| 498 | unsigned int packet_length; | ||
| 499 | |||
| 500 | struct ssl2_ctx_st *s2; /* SSLv2 variables */ | ||
| 501 | struct ssl3_ctx_st *s3; /* SSLv3 variables */ | ||
| 502 | |||
| 503 | int read_ahead; /* Read as many input bytes as possible */ | ||
| 504 | int hit; /* reusing a previous session */ | ||
| 505 | |||
| 506 | /* crypto */ | ||
| 507 | STACK /* SSL_CIPHER */ *cipher_list; | ||
| 508 | STACK /* SSL_CIPHER */ *cipher_list_by_id; | ||
| 509 | |||
| 510 | /* These are the ones being used, the ones is SSL_SESSION are | ||
| 511 | * the ones to be 'copied' into these ones */ | ||
| 512 | |||
| 513 | EVP_CIPHER_CTX *enc_read_ctx; /* cryptographic state */ | ||
| 514 | EVP_MD *read_hash; /* used for mac generation */ | ||
| 515 | SSL_COMPRESSION *read_compression; /* compression */ | ||
| 516 | |||
| 517 | EVP_CIPHER_CTX *enc_write_ctx; /* cryptographic state */ | ||
| 518 | EVP_MD *write_hash; /* used for mac generation */ | ||
| 519 | SSL_COMPRESSION *write_compression; /* compression */ | ||
| 520 | |||
| 521 | /* session info */ | ||
| 522 | |||
| 523 | /* client cert? */ | ||
| 524 | /* This is used to hold the server certificate used */ | ||
| 525 | struct cert_st /* CERT */ *cert; | ||
| 526 | |||
| 527 | /* This can also be in the session once a session is established */ | ||
| 528 | SSL_SESSION *session; | ||
| 529 | |||
| 530 | /* Used in SSL2 and SSL3 */ | ||
| 531 | int verify_mode; /* 0 don't care about verify failure. | ||
| 532 | * 1 fail if verify fails */ | ||
| 533 | int (*verify_callback)(); /* fail if callback returns 0 */ | ||
| 534 | void (*info_callback)(); /* optional informational callback */ | ||
| 535 | |||
| 536 | int error; /* error bytes to be written */ | ||
| 537 | int error_code; /* actual code */ | ||
| 538 | |||
| 539 | SSL_CTX *ctx; | ||
| 540 | /* set this flag to 1 and a sleep(1) is put into all SSL_read() | ||
| 541 | * and SSL_write() calls, good for nbio debuging :-) */ | ||
| 542 | int debug; | ||
| 543 | |||
| 544 | /* extra application data */ | ||
| 545 | long verify_result; | ||
| 546 | CRYPTO_EX_DATA ex_data; | ||
| 547 | |||
| 548 | /* for server side, keep the list of CA_dn we can use */ | ||
| 549 | STACK /* X509_NAME */ *client_CA; | ||
| 550 | |||
| 551 | int references; | ||
| 552 | unsigned long options; | ||
| 553 | int first_packet; | ||
| 554 | } SSL; | ||
| 555 | |||
| 556 | #include "ssl2.h" | ||
| 557 | #include "ssl3.h" | ||
| 558 | #include "tls1.h" /* This is mostly sslv3 with a few tweaks */ | ||
| 559 | #include "ssl23.h" | ||
| 560 | |||
| 561 | /* compatablity */ | ||
| 562 | #define SSL_set_app_data(s,arg) (SSL_set_ex_data(s,0,(char *)arg)) | ||
| 563 | #define SSL_get_app_data(s) (SSL_get_ex_data(s,0)) | ||
| 564 | #define SSL_SESSION_set_app_data(s,a) (SSL_SESSION_set_ex_data(s,0,(char *)a)) | ||
| 565 | #define SSL_SESSION_get_app_data(s) (SSL_SESSION_get_ex_data(s,0)) | ||
| 566 | #define SSL_CTX_get_app_data(ctx) (SSL_CTX_get_ex_data(ctx,0)) | ||
| 567 | #define SSL_CTX_set_app_data(ctx,arg) (SSL_CTX_set_ex_data(ctx,0,(char *)arg)) | ||
| 568 | |||
| 569 | /* The following are the possible values for ssl->state are are | ||
| 570 | * used to indicate where we are upto in the SSL connection establishment. | ||
| 571 | * The macros that follow are about the only things you should need to use | ||
| 572 | * and even then, only when using non-blocking IO. | ||
| 573 | * It can also be useful to work out where you were when the connection | ||
| 574 | * failed */ | ||
| 575 | |||
| 576 | #define SSL_ST_CONNECT 0x1000 | ||
| 577 | #define SSL_ST_ACCEPT 0x2000 | ||
| 578 | #define SSL_ST_MASK 0x0FFF | ||
| 579 | #define SSL_ST_INIT (SSL_ST_CONNECT|SSL_ST_ACCEPT) | ||
| 580 | #define SSL_ST_BEFORE 0x4000 | ||
| 581 | #define SSL_ST_OK 0x03 | ||
| 582 | #define SSL_ST_RENEGOTIATE (0x04|SSL_ST_INIT) | ||
| 583 | |||
| 584 | #define SSL_CB_LOOP 0x01 | ||
| 585 | #define SSL_CB_EXIT 0x02 | ||
| 586 | #define SSL_CB_READ 0x04 | ||
| 587 | #define SSL_CB_WRITE 0x08 | ||
| 588 | #define SSL_CB_ALERT 0x4000 /* used in callback */ | ||
| 589 | #define SSL_CB_READ_ALERT (SSL_CB_ALERT|SSL_CB_READ) | ||
| 590 | #define SSL_CB_WRITE_ALERT (SSL_CB_ALERT|SSL_CB_WRITE) | ||
| 591 | #define SSL_CB_ACCEPT_LOOP (SSL_ST_ACCEPT|SSL_CB_LOOP) | ||
| 592 | #define SSL_CB_ACCEPT_EXIT (SSL_ST_ACCEPT|SSL_CB_EXIT) | ||
| 593 | #define SSL_CB_CONNECT_LOOP (SSL_ST_CONNECT|SSL_CB_LOOP) | ||
| 594 | #define SSL_CB_CONNECT_EXIT (SSL_ST_CONNECT|SSL_CB_EXIT) | ||
| 595 | #define SSL_CB_HANDSHAKE_START 0x10 | ||
| 596 | #define SSL_CB_HANDSHAKE_DONE 0x20 | ||
| 597 | |||
| 598 | /* Is the SSL_connection established? */ | ||
| 599 | #define SSL_get_state(a) SSL_state(a) | ||
| 600 | #define SSL_is_init_finished(a) (SSL_state(a) == SSL_ST_OK) | ||
| 601 | #define SSL_in_init(a) (SSL_state(a)&SSL_ST_INIT) | ||
| 602 | #define SSL_in_before(a) (SSL_state(a)&SSL_ST_BEFORE) | ||
| 603 | #define SSL_in_connect_init(a) (SSL_state(a)&SSL_ST_CONNECT) | ||
| 604 | #define SSL_in_accept_init(a) (SSL_state(a)&SSL_ST_ACCEPT) | ||
| 605 | |||
| 606 | /* The following 2 states are kept in ssl->rstate when reads fail, | ||
| 607 | * you should not need these */ | ||
| 608 | #define SSL_ST_READ_HEADER 0xF0 | ||
| 609 | #define SSL_ST_READ_BODY 0xF1 | ||
| 610 | #define SSL_ST_READ_DONE 0xF2 | ||
| 611 | |||
| 612 | /* use either SSL_VERIFY_NONE or SSL_VERIFY_PEER, the last 2 options | ||
| 613 | * are 'ored' with SSL_VERIFY_PEER if they are desired */ | ||
| 614 | #define SSL_VERIFY_NONE 0x00 | ||
| 615 | #define SSL_VERIFY_PEER 0x01 | ||
| 616 | #define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02 | ||
| 617 | #define SSL_VERIFY_CLIENT_ONCE 0x04 | ||
| 618 | |||
| 619 | /* this is for backward compatablility */ | ||
| 620 | #if 0 /* NEW_SSLEAY */ | ||
| 621 | #define SSL_CTX_set_default_verify(a,b,c) SSL_CTX_set_verify(a,b,c) | ||
| 622 | #define SSL_set_pref_cipher(c,n) SSL_set_cipher_list(c,n) | ||
| 623 | #define SSL_add_session(a,b) SSL_CTX_add_session((a),(b)) | ||
| 624 | #define SSL_remove_session(a,b) SSL_CTX_remove_session((a),(b)) | ||
| 625 | #define SSL_flush_sessions(a,b) SSL_CTX_flush_sessions((a),(b)) | ||
| 626 | #endif | ||
| 627 | /* More backward compatablity */ | ||
| 628 | #define SSL_get_cipher(s) \ | ||
| 629 | SSL_CIPHER_get_name(SSL_get_current_cipher(s)) | ||
| 630 | #define SSL_get_cipher_bits(s,np) \ | ||
| 631 | SSL_CIPHER_get_bits(SSL_get_current_cipher(s),np) | ||
| 632 | #define SSL_get_cipher_version(s) \ | ||
| 633 | SSL_CIPHER_get_version(SSL_get_current_cipher(s)) | ||
| 634 | #define SSL_get_cipher_name(s) \ | ||
| 635 | SSL_CIPHER_get_name(SSL_get_current_cipher(s)) | ||
| 636 | #define SSL_get_time(a) SSL_SESSION_get_time(a) | ||
| 637 | #define SSL_set_time(a,b) SSL_SESSION_set_time((a),(b)) | ||
| 638 | #define SSL_get_timeout(a) SSL_SESSION_get_timeout(a) | ||
| 639 | #define SSL_set_timeout(a,b) SSL_SESSION_set_timeout((a),(b)) | ||
| 640 | |||
| 641 | /* VMS linker has a 31 char name limit */ | ||
| 642 | #define SSL_CTX_set_cert_verify_callback(a,b,c) \ | ||
| 643 | SSL_CTX_set_cert_verify_cb((a),(b),(c)) | ||
| 644 | |||
| 645 | #if 1 /*SSLEAY_MACROS*/ | ||
| 646 | #define d2i_SSL_SESSION_bio(bp,s_id) (SSL_SESSION *)ASN1_d2i_bio( \ | ||
| 647 | (char *(*)())SSL_SESSION_new,(char *(*)())d2i_SSL_SESSION, \ | ||
| 648 | (bp),(unsigned char **)(s_id)) | ||
| 649 | #define i2d_SSL_SESSION_bio(bp,s_id) ASN1_i2d_bio(i2d_SSL_SESSION, \ | ||
| 650 | bp,(unsigned char *)s_id) | ||
| 651 | #define PEM_read_SSL_SESSION(fp,x,cb) (SSL_SESSION *)PEM_ASN1_read( \ | ||
| 652 | (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb) | ||
| 653 | #define PEM_read_bio_SSL_SESSION(bp,x,cb) (SSL_SESSION *)PEM_ASN1_read_bio( \ | ||
| 654 | (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb) | ||
| 655 | #define PEM_write_SSL_SESSION(fp,x) \ | ||
| 656 | PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \ | ||
| 657 | PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL) | ||
| 658 | #define PEM_write_bio_SSL_SESSION(bp,x) \ | ||
| 659 | PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \ | ||
| 660 | PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL) | ||
| 661 | #endif | ||
| 662 | |||
| 663 | /* These alert types are for SSLv3 and TLSv1 */ | ||
| 664 | #define SSL_AD_CLOSE_NOTIFY SSL3_AD_CLOSE_NOTIFY | ||
| 665 | #define SSL_AD_UNEXPECTED_MESSAGE SSL3_AD_UNEXPECTED_MESSAGE /* fatal */ | ||
| 666 | #define SSL_AD_BAD_RECORD_MAC SSL3_AD_BAD_RECORD_MAC /* fatal */ | ||
| 667 | #define SSL_AD_DECRYPTION_FAILED TLS1_AD_DECRYPTION_FAILED | ||
| 668 | #define SSL_AD_RECORD_OVERFLOW TLS1_AD_RECORD_OVERFLOW | ||
| 669 | #define SSL_AD_DECOMPRESSION_FAILURE SSL3_AD_DECOMPRESSION_FAILURE/* fatal */ | ||
| 670 | #define SSL_AD_HANDSHAKE_FAILURE SSL3_AD_HANDSHAKE_FAILURE/* fatal */ | ||
| 671 | #define SSL_AD_NO_CERTIFICATE SSL3_AD_NO_CERTIFICATE /* Not for TLS */ | ||
| 672 | #define SSL_AD_BAD_CERTIFICATE SSL3_AD_BAD_CERTIFICATE | ||
| 673 | #define SSL_AD_UNSUPPORTED_CERTIFICATE SSL3_AD_UNSUPPORTED_CERTIFICATE | ||
| 674 | #define SSL_AD_CERTIFICATE_REVOKED SSL3_AD_CERTIFICATE_REVOKED | ||
| 675 | #define SSL_AD_CERTIFICATE_EXPIRED SSL3_AD_CERTIFICATE_EXPIRED | ||
| 676 | #define SSL_AD_CERTIFICATE_UNKNOWN SSL3_AD_CERTIFICATE_UNKNOWN | ||
| 677 | #define SSL_AD_ILLEGAL_PARAMETER SSL3_AD_ILLEGAL_PARAMETER /* fatal */ | ||
| 678 | #define SSL_AD_UNKNOWN_CA TLS1_AD_UNKNOWN_CA /* fatal */ | ||
| 679 | #define SSL_AD_ACCESS_DENIED TLS1_AD_ACCESS_DENIED /* fatal */ | ||
| 680 | #define SSL_AD_DECODE_ERROR TLS1_AD_DECODE_ERROR /* fatal */ | ||
| 681 | #define SSL_AD_DECRYPT_ERROR TLS1_AD_DECRYPT_ERROR | ||
| 682 | #define SSL_AD_EXPORT_RESTRICION TLS1_AD_EXPORT_RESTRICION/* fatal */ | ||
| 683 | #define SSL_AD_PROTOCOL_VERSION TLS1_AD_PROTOCOL_VERSION /* fatal */ | ||
| 684 | #define SSL_AD_INSUFFICIENT_SECURITY TLS1_AD_INSUFFICIENT_SECURITY/* fatal */ | ||
| 685 | #define SSL_AD_INTERNAL_ERROR TLS1_AD_INTERNAL_ERROR /* fatal */ | ||
| 686 | #define SSL_AD_USER_CANCLED TLS1_AD_USER_CANCLED | ||
| 687 | #define SSL_AD_NO_RENEGOTIATION TLS1_AD_NO_RENEGOTIATION | ||
| 688 | |||
| 689 | #define SSL_ERROR_NONE 0 | ||
| 690 | #define SSL_ERROR_SSL 1 | ||
| 691 | #define SSL_ERROR_WANT_READ 2 | ||
| 692 | #define SSL_ERROR_WANT_WRITE 3 | ||
| 693 | #define SSL_ERROR_WANT_X509_LOOKUP 4 | ||
| 694 | #define SSL_ERROR_SYSCALL 5 /* look at errno */ | ||
| 695 | #define SSL_ERROR_ZERO_RETURN 6 | ||
| 696 | #define SSL_ERROR_WANT_CONNECT 7 | ||
| 697 | |||
| 698 | #define SSL_CTRL_NEED_TMP_RSA 1 | ||
| 699 | #define SSL_CTRL_SET_TMP_RSA 2 | ||
| 700 | #define SSL_CTRL_SET_TMP_DH 3 | ||
| 701 | #define SSL_CTRL_SET_TMP_RSA_CB 4 | ||
| 702 | #define SSL_CTRL_SET_TMP_DH_CB 5 | ||
| 703 | /* Add these ones */ | ||
| 704 | #define SSL_CTRL_GET_SESSION_REUSED 6 | ||
| 705 | #define SSL_CTRL_GET_CLIENT_CERT_REQUEST 7 | ||
| 706 | #define SSL_CTRL_GET_NUM_RENEGOTIATIONS 8 | ||
| 707 | #define SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS 9 | ||
| 708 | #define SSL_CTRL_GET_TOTAL_RENEGOTIATIONS 10 | ||
| 709 | |||
| 710 | #define SSL_session_reused(ssl) \ | ||
| 711 | SSL_ctrl((ssl),SSL_CTRL_GET_SESSION_REUSED,0,NULL) | ||
| 712 | #define SSL_num_renegotiations(ssl) \ | ||
| 713 | SSL_ctrl((ssl),SSL_CTRL_GET_NUM_RENEGOTIATIONS,0,NULL) | ||
| 714 | #define SSL_clear_num_renegotiations(ssl) \ | ||
| 715 | SSL_ctrl((ssl),SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS,0,NULL) | ||
| 716 | #define SSL_total_renegotiations(ssl) \ | ||
| 717 | SSL_ctrl((ssl),SSL_CTRL_GET_TOTAL_RENEGOTIATIONS,0,NULL) | ||
| 718 | |||
| 719 | #define SSL_CTX_need_tmp_RSA(ctx) \ | ||
| 720 | SSL_CTX_ctrl(ctx,SSL_CTRL_NEED_TMP_RSA,0,NULL) | ||
| 721 | #define SSL_CTX_set_tmp_rsa(ctx,rsa) \ | ||
| 722 | SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa) | ||
| 723 | #define SSL_CTX_set_tmp_dh(ctx,dh) \ | ||
| 724 | SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH,0,(char *)dh) | ||
| 725 | |||
| 726 | /* For the next 2, the callbacks are | ||
| 727 | * RSA *tmp_rsa_cb(int export) | ||
| 728 | * DH *tmp_dh_cb(int export) | ||
| 729 | */ | ||
| 730 | #define SSL_CTX_set_tmp_rsa_callback(ctx,cb) \ | ||
| 731 | SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_RSA_CB,0,(char *)cb) | ||
| 732 | #define SSL_CTX_set_tmp_dh_callback(ctx,dh) \ | ||
| 733 | SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH_CB,0,(char *)dh) | ||
| 734 | |||
| 735 | #ifndef NOPROTO | ||
| 736 | |||
| 737 | #ifdef HEADER_BIO_H | ||
| 738 | BIO_METHOD *BIO_f_ssl(void); | ||
| 739 | BIO *BIO_new_ssl(SSL_CTX *ctx,int client); | ||
| 740 | BIO *BIO_new_ssl_connect(SSL_CTX *ctx); | ||
| 741 | BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx); | ||
| 742 | int BIO_ssl_copy_session_id(BIO *to,BIO *from); | ||
| 743 | void BIO_ssl_shutdown(BIO *ssl_bio); | ||
| 744 | |||
| 745 | #endif | ||
| 746 | |||
| 747 | int SSL_CTX_set_cipher_list(SSL_CTX *,char *str); | ||
| 748 | SSL_CTX *SSL_CTX_new(SSL_METHOD *meth); | ||
| 749 | void SSL_CTX_free(SSL_CTX *); | ||
| 750 | void SSL_clear(SSL *s); | ||
| 751 | void SSL_CTX_flush_sessions(SSL_CTX *ctx,long tm); | ||
| 752 | |||
| 753 | SSL_CIPHER *SSL_get_current_cipher(SSL *s); | ||
| 754 | int SSL_CIPHER_get_bits(SSL_CIPHER *c,int *alg_bits); | ||
| 755 | char * SSL_CIPHER_get_version(SSL_CIPHER *c); | ||
| 756 | char * SSL_CIPHER_get_name(SSL_CIPHER *c); | ||
| 757 | |||
| 758 | int SSL_get_fd(SSL *s); | ||
| 759 | char * SSL_get_cipher_list(SSL *s,int n); | ||
| 760 | char * SSL_get_shared_ciphers(SSL *s, char *buf, int len); | ||
| 761 | int SSL_get_read_ahead(SSL * s); | ||
| 762 | int SSL_pending(SSL *s); | ||
| 763 | #ifndef NO_SOCK | ||
| 764 | int SSL_set_fd(SSL *s, int fd); | ||
| 765 | int SSL_set_rfd(SSL *s, int fd); | ||
| 766 | int SSL_set_wfd(SSL *s, int fd); | ||
| 767 | #endif | ||
| 768 | #ifdef HEADER_BIO_H | ||
| 769 | void SSL_set_bio(SSL *s, BIO *rbio,BIO *wbio); | ||
| 770 | BIO * SSL_get_rbio(SSL *s); | ||
| 771 | BIO * SSL_get_wbio(SSL *s); | ||
| 772 | #endif | ||
| 773 | int SSL_set_cipher_list(SSL *s, char *str); | ||
| 774 | void SSL_set_read_ahead(SSL *s, int yes); | ||
| 775 | int SSL_get_verify_mode(SSL *s); | ||
| 776 | int (*SSL_get_verify_callback(SSL *s))(); | ||
| 777 | void SSL_set_verify(SSL *s, int mode, int (*callback) ()); | ||
| 778 | int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa); | ||
| 779 | int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len); | ||
| 780 | int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey); | ||
| 781 | int SSL_use_PrivateKey_ASN1(int pk,SSL *ssl, unsigned char *d, long len); | ||
| 782 | int SSL_use_certificate(SSL *ssl, X509 *x); | ||
| 783 | int SSL_use_certificate_ASN1(SSL *ssl, int len, unsigned char *d); | ||
| 784 | |||
| 785 | #ifndef NO_STDIO | ||
| 786 | int SSL_use_RSAPrivateKey_file(SSL *ssl, char *file, int type); | ||
| 787 | int SSL_use_PrivateKey_file(SSL *ssl, char *file, int type); | ||
| 788 | int SSL_use_certificate_file(SSL *ssl, char *file, int type); | ||
| 789 | int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, char *file, int type); | ||
| 790 | int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, char *file, int type); | ||
| 791 | int SSL_CTX_use_certificate_file(SSL_CTX *ctx, char *file, int type); | ||
| 792 | STACK * SSL_load_client_CA_file(char *file); | ||
| 793 | #endif | ||
| 794 | |||
| 795 | void ERR_load_SSL_strings(void ); | ||
| 796 | void SSL_load_error_strings(void ); | ||
| 797 | char * SSL_state_string(SSL *s); | ||
| 798 | char * SSL_rstate_string(SSL *s); | ||
| 799 | char * SSL_state_string_long(SSL *s); | ||
| 800 | char * SSL_rstate_string_long(SSL *s); | ||
| 801 | long SSL_SESSION_get_time(SSL_SESSION *s); | ||
| 802 | long SSL_SESSION_set_time(SSL_SESSION *s, long t); | ||
| 803 | long SSL_SESSION_get_timeout(SSL_SESSION *s); | ||
| 804 | long SSL_SESSION_set_timeout(SSL_SESSION *s, long t); | ||
| 805 | void SSL_copy_session_id(SSL *to,SSL *from); | ||
| 806 | |||
| 807 | SSL_SESSION *SSL_SESSION_new(void); | ||
| 808 | unsigned long SSL_SESSION_hash(SSL_SESSION *a); | ||
| 809 | int SSL_SESSION_cmp(SSL_SESSION *a,SSL_SESSION *b); | ||
| 810 | #ifndef NO_FP_API | ||
| 811 | int SSL_SESSION_print_fp(FILE *fp,SSL_SESSION *ses); | ||
| 812 | #endif | ||
| 813 | #ifdef HEADER_BIO_H | ||
| 814 | int SSL_SESSION_print(BIO *fp,SSL_SESSION *ses); | ||
| 815 | #endif | ||
| 816 | void SSL_SESSION_free(SSL_SESSION *ses); | ||
| 817 | int i2d_SSL_SESSION(SSL_SESSION *in,unsigned char **pp); | ||
| 818 | int SSL_set_session(SSL *to, SSL_SESSION *session); | ||
| 819 | int SSL_CTX_add_session(SSL_CTX *s, SSL_SESSION *c); | ||
| 820 | int SSL_CTX_remove_session(SSL_CTX *,SSL_SESSION *c); | ||
| 821 | SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a,unsigned char **pp,long length); | ||
| 822 | |||
| 823 | #ifdef HEADER_X509_H | ||
| 824 | X509 * SSL_get_peer_certificate(SSL *s); | ||
| 825 | #endif | ||
| 826 | |||
| 827 | STACK * SSL_get_peer_cert_chain(SSL *s); | ||
| 828 | |||
| 829 | int SSL_CTX_get_verify_mode(SSL_CTX *ctx); | ||
| 830 | int (*SSL_CTX_get_verify_callback(SSL_CTX *ctx))(); | ||
| 831 | void SSL_CTX_set_verify(SSL_CTX *ctx,int mode,int (*callback)()); | ||
| 832 | void SSL_CTX_set_cert_verify_cb(SSL_CTX *ctx, int (*cb)(),char *arg); | ||
| 833 | int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa); | ||
| 834 | int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, unsigned char *d, long len); | ||
| 835 | int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey); | ||
| 836 | int SSL_CTX_use_PrivateKey_ASN1(int pk,SSL_CTX *ctx, | ||
| 837 | unsigned char *d, long len); | ||
| 838 | int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x); | ||
| 839 | int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, unsigned char *d); | ||
| 840 | |||
| 841 | void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx,int (*cb)()); | ||
| 842 | |||
| 843 | int SSL_CTX_check_private_key(SSL_CTX *ctx); | ||
| 844 | int SSL_check_private_key(SSL *ctx); | ||
| 845 | |||
| 846 | SSL * SSL_new(SSL_CTX *ctx); | ||
| 847 | void SSL_clear(SSL *s); | ||
| 848 | void SSL_free(SSL *ssl); | ||
| 849 | int SSL_accept(SSL *ssl); | ||
| 850 | int SSL_connect(SSL *ssl); | ||
| 851 | int SSL_read(SSL *ssl,char *buf,int num); | ||
| 852 | int SSL_peek(SSL *ssl,char *buf,int num); | ||
| 853 | int SSL_write(SSL *ssl,char *buf,int num); | ||
| 854 | long SSL_ctrl(SSL *ssl,int cmd, long larg, char *parg); | ||
| 855 | long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd, long larg, char *parg); | ||
| 856 | |||
| 857 | int SSL_get_error(SSL *s,int ret_code); | ||
| 858 | char * SSL_get_version(SSL *s); | ||
| 859 | |||
| 860 | /* This sets the 'default' SSL version that SSL_new() will create */ | ||
| 861 | int SSL_CTX_set_ssl_version(SSL_CTX *ctx,SSL_METHOD *meth); | ||
| 862 | |||
| 863 | SSL_METHOD *SSLv2_method(void); /* SSLv2 */ | ||
| 864 | SSL_METHOD *SSLv2_server_method(void); /* SSLv2 */ | ||
| 865 | SSL_METHOD *SSLv2_client_method(void); /* SSLv2 */ | ||
| 866 | |||
| 867 | SSL_METHOD *SSLv3_method(void); /* SSLv3 */ | ||
| 868 | SSL_METHOD *SSLv3_server_method(void); /* SSLv3 */ | ||
| 869 | SSL_METHOD *SSLv3_client_method(void); /* SSLv3 */ | ||
| 870 | |||
| 871 | SSL_METHOD *SSLv23_method(void); /* SSLv3 but can rollback to v2 */ | ||
| 872 | SSL_METHOD *SSLv23_server_method(void); /* SSLv3 but can rollback to v2 */ | ||
| 873 | SSL_METHOD *SSLv23_client_method(void); /* SSLv3 but can rollback to v2 */ | ||
| 874 | |||
| 875 | SSL_METHOD *TLSv1_method(void); /* TLSv1.0 */ | ||
| 876 | SSL_METHOD *TLSv1_server_method(void); /* TLSv1.0 */ | ||
| 877 | SSL_METHOD *TLSv1_client_method(void); /* TLSv1.0 */ | ||
| 878 | |||
| 879 | STACK *SSL_get_ciphers(SSL *s); | ||
| 880 | |||
| 881 | int SSL_do_handshake(SSL *s); | ||
| 882 | int SSL_renegotiate(SSL *s); | ||
| 883 | int SSL_shutdown(SSL *s); | ||
| 884 | |||
| 885 | SSL_METHOD *SSL_get_ssl_method(SSL *s); | ||
| 886 | int SSL_set_ssl_method(SSL *s,SSL_METHOD *method); | ||
| 887 | char *SSL_alert_type_string_long(int value); | ||
| 888 | char *SSL_alert_type_string(int value); | ||
| 889 | char *SSL_alert_desc_string_long(int value); | ||
| 890 | char *SSL_alert_desc_string(int value); | ||
| 891 | |||
| 892 | void SSL_set_client_CA_list(SSL *s, STACK *list); | ||
| 893 | void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK *list); | ||
| 894 | STACK *SSL_get_client_CA_list(SSL *s); | ||
| 895 | STACK *SSL_CTX_get_client_CA_list(SSL_CTX *s); | ||
| 896 | int SSL_add_client_CA(SSL *ssl,X509 *x); | ||
| 897 | int SSL_CTX_add_client_CA(SSL_CTX *ctx,X509 *x); | ||
| 898 | |||
| 899 | void SSL_set_connect_state(SSL *s); | ||
| 900 | void SSL_set_accept_state(SSL *s); | ||
| 901 | |||
| 902 | long SSL_get_default_timeout(SSL *s); | ||
| 903 | |||
| 904 | void SSLeay_add_ssl_algorithms(void ); | ||
| 905 | |||
| 906 | char *SSL_CIPHER_description(SSL_CIPHER *,char *buf,int size); | ||
| 907 | STACK *SSL_dup_CA_list(STACK *sk); | ||
| 908 | |||
| 909 | SSL *SSL_dup(SSL *ssl); | ||
| 910 | |||
| 911 | X509 *SSL_get_certificate(SSL *ssl); | ||
| 912 | /* EVP_PKEY */ struct evp_pkey_st *SSL_get_privatekey(SSL *ssl); | ||
| 913 | |||
| 914 | void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode); | ||
| 915 | int SSL_CTX_get_quiet_shutdown(SSL_CTX *ctx); | ||
| 916 | void SSL_set_quiet_shutdown(SSL *ssl,int mode); | ||
| 917 | int SSL_get_quiet_shutdown(SSL *ssl); | ||
| 918 | void SSL_set_shutdown(SSL *ssl,int mode); | ||
| 919 | int SSL_get_shutdown(SSL *ssl); | ||
| 920 | int SSL_version(SSL *ssl); | ||
| 921 | int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx); | ||
| 922 | int SSL_CTX_load_verify_locations(SSL_CTX *ctx,char *CAfile,char *CApath); | ||
| 923 | SSL_SESSION *SSL_get_session(SSL *ssl); | ||
| 924 | SSL_CTX *SSL_get_SSL_CTX(SSL *ssl); | ||
| 925 | void SSL_set_info_callback(SSL *ssl,void (*cb)()); | ||
| 926 | void (*SSL_get_info_callback(SSL *ssl))(); | ||
| 927 | int SSL_state(SSL *ssl); | ||
| 928 | |||
| 929 | void SSL_set_verify_result(SSL *ssl,long v); | ||
| 930 | long SSL_get_verify_result(SSL *ssl); | ||
| 931 | |||
| 932 | int SSL_set_ex_data(SSL *ssl,int idx,char *data); | ||
| 933 | char *SSL_get_ex_data(SSL *ssl,int idx); | ||
| 934 | int SSL_get_ex_new_index(long argl, char *argp, int (*new_func)(), | ||
| 935 | int (*dup_func)(), void (*free_func)()); | ||
| 936 | |||
| 937 | int SSL_SESSION_set_ex_data(SSL_SESSION *ss,int idx,char *data); | ||
| 938 | char *SSL_SESSION_get_ex_data(SSL_SESSION *ss,int idx); | ||
| 939 | int SSL_SESSION_get_ex_new_index(long argl, char *argp, int (*new_func)(), | ||
| 940 | int (*dup_func)(), void (*free_func)()); | ||
| 941 | |||
| 942 | int SSL_CTX_set_ex_data(SSL_CTX *ssl,int idx,char *data); | ||
| 943 | char *SSL_CTX_get_ex_data(SSL_CTX *ssl,int idx); | ||
| 944 | int SSL_CTX_get_ex_new_index(long argl, char *argp, int (*new_func)(), | ||
| 945 | int (*dup_func)(), void (*free_func)()); | ||
| 946 | |||
| 947 | #else | ||
| 948 | |||
| 949 | BIO_METHOD *BIO_f_ssl(); | ||
| 950 | BIO *BIO_new_ssl(); | ||
| 951 | BIO *BIO_new_ssl_connect(); | ||
| 952 | BIO *BIO_new_buffer_ssl_connect(); | ||
| 953 | int BIO_ssl_copy_session_id(); | ||
| 954 | void BIO_ssl_shutdown(); | ||
| 955 | |||
| 956 | int SSL_CTX_set_cipher_list(); | ||
| 957 | SSL_CTX *SSL_CTX_new(); | ||
| 958 | void SSL_CTX_free(); | ||
| 959 | void SSL_clear(); | ||
| 960 | void SSL_CTX_flush_sessions(); | ||
| 961 | |||
| 962 | SSL_CIPHER *SSL_get_current_cipher(); | ||
| 963 | int SSL_CIPHER_get_bits(); | ||
| 964 | char * SSL_CIPHER_get_version(); | ||
| 965 | char * SSL_CIPHER_get_name(); | ||
| 966 | |||
| 967 | int SSL_get_fd(); | ||
| 968 | char * SSL_get_cipher_list(); | ||
| 969 | char * SSL_get_shared_ciphers(); | ||
| 970 | int SSL_get_read_ahead(); | ||
| 971 | int SSL_pending(); | ||
| 972 | #ifndef NO_SOCK | ||
| 973 | int SSL_set_fd(); | ||
| 974 | int SSL_set_rfd(); | ||
| 975 | int SSL_set_wfd(); | ||
| 976 | #endif | ||
| 977 | #ifdef HEADER_BIO_H | ||
| 978 | void SSL_set_bio(); | ||
| 979 | BIO * SSL_get_rbio(); | ||
| 980 | BIO * SSL_get_wbio(); | ||
| 981 | #endif | ||
| 982 | int SSL_set_cipher_list(); | ||
| 983 | void SSL_set_read_ahead(); | ||
| 984 | int SSL_get_verify_mode(); | ||
| 985 | |||
| 986 | void SSL_set_verify(); | ||
| 987 | int SSL_use_RSAPrivateKey(); | ||
| 988 | int SSL_use_RSAPrivateKey_ASN1(); | ||
| 989 | int SSL_use_PrivateKey(); | ||
| 990 | int SSL_use_PrivateKey_ASN1(); | ||
| 991 | int SSL_use_certificate(); | ||
| 992 | int SSL_use_certificate_ASN1(); | ||
| 993 | |||
| 994 | #ifndef NO_STDIO | ||
| 995 | int SSL_use_RSAPrivateKey_file(); | ||
| 996 | int SSL_use_PrivateKey_file(); | ||
| 997 | int SSL_use_certificate_file(); | ||
| 998 | int SSL_CTX_use_RSAPrivateKey_file(); | ||
| 999 | int SSL_CTX_use_PrivateKey_file(); | ||
| 1000 | int SSL_CTX_use_certificate_file(); | ||
| 1001 | STACK * SSL_load_client_CA_file(); | ||
| 1002 | #endif | ||
| 1003 | |||
| 1004 | void ERR_load_SSL_strings(); | ||
| 1005 | void SSL_load_error_strings(); | ||
| 1006 | char * SSL_state_string(); | ||
| 1007 | char * SSL_rstate_string(); | ||
| 1008 | char * SSL_state_string_long(); | ||
| 1009 | char * SSL_rstate_string_long(); | ||
| 1010 | long SSL_SESSION_get_time(); | ||
| 1011 | long SSL_SESSION_set_time(); | ||
| 1012 | long SSL_SESSION_get_timeout(); | ||
| 1013 | long SSL_SESSION_set_timeout(); | ||
| 1014 | void SSL_copy_session_id(); | ||
| 1015 | |||
| 1016 | SSL_SESSION *SSL_SESSION_new(); | ||
| 1017 | unsigned long SSL_SESSION_hash(); | ||
| 1018 | int SSL_SESSION_cmp(); | ||
| 1019 | #ifndef NO_FP_API | ||
| 1020 | int SSL_SESSION_print_fp(); | ||
| 1021 | #endif | ||
| 1022 | #ifdef HEADER_BIO_H | ||
| 1023 | int SSL_SESSION_print(); | ||
| 1024 | #endif | ||
| 1025 | void SSL_SESSION_free(); | ||
| 1026 | int i2d_SSL_SESSION(); | ||
| 1027 | int SSL_set_session(); | ||
| 1028 | int SSL_CTX_add_session(); | ||
| 1029 | int SSL_CTX_remove_session(); | ||
| 1030 | SSL_SESSION *d2i_SSL_SESSION(); | ||
| 1031 | |||
| 1032 | #ifdef HEADER_X509_H | ||
| 1033 | X509 * SSL_get_peer_certificate(); | ||
| 1034 | #endif | ||
| 1035 | |||
| 1036 | STACK * SSL_get_peer_cert_chain(); | ||
| 1037 | |||
| 1038 | int SSL_CTX_get_verify_mode(); | ||
| 1039 | int (*SSL_CTX_get_verify_callback())(); | ||
| 1040 | void SSL_CTX_set_verify(); | ||
| 1041 | void SSL_CTX_set_cert_verify_cb(); | ||
| 1042 | int SSL_CTX_use_RSAPrivateKey(); | ||
| 1043 | int SSL_CTX_use_RSAPrivateKey_ASN1(); | ||
| 1044 | int SSL_CTX_use_PrivateKey(); | ||
| 1045 | int SSL_CTX_use_PrivateKey_ASN1(); | ||
| 1046 | int SSL_CTX_use_certificate(); | ||
| 1047 | int SSL_CTX_use_certificate_ASN1(); | ||
| 1048 | |||
| 1049 | void SSL_CTX_set_default_passwd_cb(); | ||
| 1050 | |||
| 1051 | int SSL_CTX_check_private_key(); | ||
| 1052 | int SSL_check_private_key(); | ||
| 1053 | |||
| 1054 | SSL * SSL_new(); | ||
| 1055 | void SSL_clear(); | ||
| 1056 | void SSL_free(); | ||
| 1057 | int SSL_accept(); | ||
| 1058 | int SSL_connect(); | ||
| 1059 | int SSL_read(); | ||
| 1060 | int SSL_peek(); | ||
| 1061 | int SSL_write(); | ||
| 1062 | long SSL_ctrl(); | ||
| 1063 | long SSL_CTX_ctrl(); | ||
| 1064 | |||
| 1065 | int SSL_get_error(); | ||
| 1066 | char * SSL_get_version(); | ||
| 1067 | |||
| 1068 | int SSL_CTX_set_ssl_version(); | ||
| 1069 | |||
| 1070 | SSL_METHOD *SSLv2_method(); | ||
| 1071 | SSL_METHOD *SSLv2_server_method(); | ||
| 1072 | SSL_METHOD *SSLv2_client_method(); | ||
| 1073 | |||
| 1074 | SSL_METHOD *SSLv3_method(); | ||
| 1075 | SSL_METHOD *SSLv3_server_method(); | ||
| 1076 | SSL_METHOD *SSLv3_client_method(); | ||
| 1077 | |||
| 1078 | SSL_METHOD *SSLv23_method(); | ||
| 1079 | SSL_METHOD *SSLv23_server_method(); | ||
| 1080 | SSL_METHOD *SSLv23_client_method(); | ||
| 1081 | |||
| 1082 | SSL_METHOD *TLSv1_method(); | ||
| 1083 | SSL_METHOD *TLSv1_server_method(); | ||
| 1084 | SSL_METHOD *TLSv1_client_method(); | ||
| 1085 | |||
| 1086 | STACK *SSL_get_ciphers(); | ||
| 1087 | |||
| 1088 | int SSL_do_handshake(); | ||
| 1089 | int SSL_renegotiate(); | ||
| 1090 | int SSL_shutdown(); | ||
| 1091 | |||
| 1092 | SSL_METHOD *SSL_get_ssl_method(); | ||
| 1093 | int SSL_set_ssl_method(); | ||
| 1094 | char *SSL_alert_type_string_long(); | ||
| 1095 | char *SSL_alert_type_string(); | ||
| 1096 | char *SSL_alert_desc_string_long(); | ||
| 1097 | char *SSL_alert_desc_string(); | ||
| 1098 | |||
| 1099 | void SSL_set_client_CA_list(); | ||
| 1100 | void SSL_CTX_set_client_CA_list(); | ||
| 1101 | STACK *SSL_get_client_CA_list(); | ||
| 1102 | STACK *SSL_CTX_get_client_CA_list(); | ||
| 1103 | int SSL_add_client_CA(); | ||
| 1104 | int SSL_CTX_add_client_CA(); | ||
| 1105 | |||
| 1106 | void SSL_set_connect_state(); | ||
| 1107 | void SSL_set_accept_state(); | ||
| 1108 | |||
| 1109 | long SSL_get_default_timeout(); | ||
| 1110 | |||
| 1111 | void SSLeay_add_ssl_algorithms(); | ||
| 1112 | |||
| 1113 | char *SSL_CIPHER_description(); | ||
| 1114 | STACK *SSL_dup_CA_list(); | ||
| 1115 | |||
| 1116 | SSL *SSL_dup(); | ||
| 1117 | |||
| 1118 | X509 *SSL_get_certificate(); | ||
| 1119 | /* EVP * */ struct evp_pkey_st *SSL_get_privatekey(); | ||
| 1120 | |||
| 1121 | #ifdef this_is_for_mk1mf_pl | ||
| 1122 | EVP *SSL_get_privatekey(); | ||
| 1123 | |||
| 1124 | void SSL_CTX_set_quiet_shutdown(); | ||
| 1125 | int SSL_CTX_get_quiet_shutdown(); | ||
| 1126 | void SSL_set_quiet_shutdown(); | ||
| 1127 | int SSL_get_quiet_shutdown(); | ||
| 1128 | void SSL_set_shutdown(); | ||
| 1129 | int SSL_get_shutdown(); | ||
| 1130 | int SSL_version(); | ||
| 1131 | int SSL_CTX_set_default_verify_paths(); | ||
| 1132 | int SSL_CTX_load_verify_locations(); | ||
| 1133 | SSL_SESSION *SSL_get_session(); | ||
| 1134 | SSL_CTX *SSL_get_SSL_CTX(); | ||
| 1135 | void SSL_set_info_callback(); | ||
| 1136 | int (*SSL_get_info_callback())(); | ||
| 1137 | int SSL_state(); | ||
| 1138 | void SSL_set_verify_result(); | ||
| 1139 | long SSL_get_verify_result(); | ||
| 1140 | |||
| 1141 | int SSL_set_ex_data(); | ||
| 1142 | char *SSL_get_ex_data(); | ||
| 1143 | int SSL_get_ex_new_index(); | ||
| 1144 | |||
| 1145 | int SSL_SESSION_set_ex_data(); | ||
| 1146 | char *SSL_SESSION_get_ex_data(); | ||
| 1147 | int SSL_SESSION_get_ex_new_index(); | ||
| 1148 | |||
| 1149 | int SSL_CTX_set_ex_data(); | ||
| 1150 | char *SSL_CTX_get_ex_data(); | ||
| 1151 | int SSL_CTX_get_ex_new_index(); | ||
| 1152 | |||
| 1153 | #endif | ||
| 1154 | |||
| 1155 | #endif | ||
| 1156 | |||
| 1157 | /* BEGIN ERROR CODES */ | ||
| 1158 | /* Error codes for the SSL functions. */ | ||
| 1159 | |||
| 1160 | /* Function codes. */ | ||
| 1161 | #define SSL_F_CLIENT_CERTIFICATE 100 | ||
| 1162 | #define SSL_F_CLIENT_HELLO 101 | ||
| 1163 | #define SSL_F_CLIENT_MASTER_KEY 102 | ||
| 1164 | #define SSL_F_D2I_SSL_SESSION 103 | ||
| 1165 | #define SSL_F_DO_SSL3_WRITE 104 | ||
| 1166 | #define SSL_F_GET_CLIENT_FINISHED 105 | ||
| 1167 | #define SSL_F_GET_CLIENT_HELLO 106 | ||
| 1168 | #define SSL_F_GET_CLIENT_MASTER_KEY 107 | ||
| 1169 | #define SSL_F_GET_SERVER_FINISHED 108 | ||
| 1170 | #define SSL_F_GET_SERVER_HELLO 109 | ||
| 1171 | #define SSL_F_GET_SERVER_VERIFY 110 | ||
| 1172 | #define SSL_F_I2D_SSL_SESSION 111 | ||
| 1173 | #define SSL_F_READ_N 112 | ||
| 1174 | #define SSL_F_REQUEST_CERTIFICATE 113 | ||
| 1175 | #define SSL_F_SERVER_HELLO 114 | ||
| 1176 | #define SSL_F_SSL23_ACCEPT 115 | ||
| 1177 | #define SSL_F_SSL23_CLIENT_HELLO 116 | ||
| 1178 | #define SSL_F_SSL23_CONNECT 117 | ||
| 1179 | #define SSL_F_SSL23_GET_CLIENT_HELLO 118 | ||
| 1180 | #define SSL_F_SSL23_GET_SERVER_HELLO 119 | ||
| 1181 | #define SSL_F_SSL23_READ 120 | ||
| 1182 | #define SSL_F_SSL23_WRITE 121 | ||
| 1183 | #define SSL_F_SSL2_ACCEPT 122 | ||
| 1184 | #define SSL_F_SSL2_CONNECT 123 | ||
| 1185 | #define SSL_F_SSL2_ENC_INIT 124 | ||
| 1186 | #define SSL_F_SSL2_READ 125 | ||
| 1187 | #define SSL_F_SSL2_SET_CERTIFICATE 126 | ||
| 1188 | #define SSL_F_SSL2_WRITE 127 | ||
| 1189 | #define SSL_F_SSL3_ACCEPT 128 | ||
| 1190 | #define SSL_F_SSL3_CHANGE_CIPHER_STATE 129 | ||
| 1191 | #define SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM 130 | ||
| 1192 | #define SSL_F_SSL3_CLIENT_HELLO 131 | ||
| 1193 | #define SSL_F_SSL3_CONNECT 132 | ||
| 1194 | #define SSL_F_SSL3_CTX_CTRL 133 | ||
| 1195 | #define SSL_F_SSL3_ENC 134 | ||
| 1196 | #define SSL_F_SSL3_GET_CERTIFICATE_REQUEST 135 | ||
| 1197 | #define SSL_F_SSL3_GET_CERT_VERIFY 136 | ||
| 1198 | #define SSL_F_SSL3_GET_CLIENT_CERTIFICATE 137 | ||
| 1199 | #define SSL_F_SSL3_GET_CLIENT_HELLO 138 | ||
| 1200 | #define SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE 139 | ||
| 1201 | #define SSL_F_SSL3_GET_FINISHED 140 | ||
| 1202 | #define SSL_F_SSL3_GET_KEY_EXCHANGE 141 | ||
| 1203 | #define SSL_F_SSL3_GET_MESSAGE 142 | ||
| 1204 | #define SSL_F_SSL3_GET_RECORD 143 | ||
| 1205 | #define SSL_F_SSL3_GET_SERVER_CERTIFICATE 144 | ||
| 1206 | #define SSL_F_SSL3_GET_SERVER_DONE 145 | ||
| 1207 | #define SSL_F_SSL3_GET_SERVER_HELLO 146 | ||
| 1208 | #define SSL_F_SSL3_OUTPUT_CERT_CHAIN 147 | ||
| 1209 | #define SSL_F_SSL3_READ_BYTES 148 | ||
| 1210 | #define SSL_F_SSL3_READ_N 149 | ||
| 1211 | #define SSL_F_SSL3_SEND_CERTIFICATE_REQUEST 150 | ||
| 1212 | #define SSL_F_SSL3_SEND_CLIENT_CERTIFICATE 151 | ||
| 1213 | #define SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE 152 | ||
| 1214 | #define SSL_F_SSL3_SEND_CLIENT_VERIFY 153 | ||
| 1215 | #define SSL_F_SSL3_SEND_SERVER_CERTIFICATE 154 | ||
| 1216 | #define SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE 155 | ||
| 1217 | #define SSL_F_SSL3_SETUP_BUFFERS 156 | ||
| 1218 | #define SSL_F_SSL3_SETUP_KEY_BLOCK 157 | ||
| 1219 | #define SSL_F_SSL3_WRITE_BYTES 158 | ||
| 1220 | #define SSL_F_SSL3_WRITE_PENDING 159 | ||
| 1221 | #define SSL_F_SSL_BAD_METHOD 160 | ||
| 1222 | #define SSL_F_SSL_BYTES_TO_CIPHER_LIST 161 | ||
| 1223 | #define SSL_F_SSL_CERT_NEW 162 | ||
| 1224 | #define SSL_F_SSL_CHECK_PRIVATE_KEY 163 | ||
| 1225 | #define SSL_F_SSL_CREATE_CIPHER_LIST 164 | ||
| 1226 | #define SSL_F_SSL_CTX_CHECK_PRIVATE_KEY 165 | ||
| 1227 | #define SSL_F_SSL_CTX_NEW 166 | ||
| 1228 | #define SSL_F_SSL_CTX_SET_SSL_VERSION 167 | ||
| 1229 | #define SSL_F_SSL_CTX_USE_CERTIFICATE 168 | ||
| 1230 | #define SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1 169 | ||
| 1231 | #define SSL_F_SSL_CTX_USE_CERTIFICATE_FILE 170 | ||
| 1232 | #define SSL_F_SSL_CTX_USE_PRIVATEKEY 171 | ||
| 1233 | #define SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1 172 | ||
| 1234 | #define SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE 173 | ||
| 1235 | #define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY 174 | ||
| 1236 | #define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1 175 | ||
| 1237 | #define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE 176 | ||
| 1238 | #define SSL_F_SSL_DO_HANDSHAKE 177 | ||
| 1239 | #define SSL_F_SSL_GET_NEW_SESSION 178 | ||
| 1240 | #define SSL_F_SSL_GET_SERVER_SEND_CERT 179 | ||
| 1241 | #define SSL_F_SSL_GET_SIGN_PKEY 180 | ||
| 1242 | #define SSL_F_SSL_INIT_WBIO_BUFFER 181 | ||
| 1243 | #define SSL_F_SSL_LOAD_CLIENT_CA_FILE 182 | ||
| 1244 | #define SSL_F_SSL_NEW 183 | ||
| 1245 | #define SSL_F_SSL_RSA_PRIVATE_DECRYPT 184 | ||
| 1246 | #define SSL_F_SSL_RSA_PUBLIC_ENCRYPT 185 | ||
| 1247 | #define SSL_F_SSL_SESSION_NEW 186 | ||
| 1248 | #define SSL_F_SSL_SESSION_PRINT_FP 187 | ||
| 1249 | #define SSL_F_SSL_SET_CERT 188 | ||
| 1250 | #define SSL_F_SSL_SET_FD 189 | ||
| 1251 | #define SSL_F_SSL_SET_PKEY 190 | ||
| 1252 | #define SSL_F_SSL_SET_RFD 191 | ||
| 1253 | #define SSL_F_SSL_SET_SESSION 192 | ||
| 1254 | #define SSL_F_SSL_SET_WFD 193 | ||
| 1255 | #define SSL_F_SSL_UNDEFINED_FUNCTION 194 | ||
| 1256 | #define SSL_F_SSL_USE_CERTIFICATE 195 | ||
| 1257 | #define SSL_F_SSL_USE_CERTIFICATE_ASN1 196 | ||
| 1258 | #define SSL_F_SSL_USE_CERTIFICATE_FILE 197 | ||
| 1259 | #define SSL_F_SSL_USE_PRIVATEKEY 198 | ||
| 1260 | #define SSL_F_SSL_USE_PRIVATEKEY_ASN1 199 | ||
| 1261 | #define SSL_F_SSL_USE_PRIVATEKEY_FILE 200 | ||
| 1262 | #define SSL_F_SSL_USE_RSAPRIVATEKEY 201 | ||
| 1263 | #define SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1 202 | ||
| 1264 | #define SSL_F_SSL_USE_RSAPRIVATEKEY_FILE 203 | ||
| 1265 | #define SSL_F_SSL_WRITE 204 | ||
| 1266 | #define SSL_F_TLS1_CHANGE_CIPHER_STATE 205 | ||
| 1267 | #define SSL_F_TLS1_ENC 206 | ||
| 1268 | #define SSL_F_TLS1_SETUP_KEY_BLOCK 207 | ||
| 1269 | #define SSL_F_WRITE_PENDING 208 | ||
| 1270 | |||
| 1271 | /* Reason codes. */ | ||
| 1272 | #define SSL_R_APP_DATA_IN_HANDSHAKE 100 | ||
| 1273 | #define SSL_R_BAD_ALERT_RECORD 101 | ||
| 1274 | #define SSL_R_BAD_AUTHENTICATION_TYPE 102 | ||
| 1275 | #define SSL_R_BAD_CHANGE_CIPHER_SPEC 103 | ||
| 1276 | #define SSL_R_BAD_CHECKSUM 104 | ||
| 1277 | #define SSL_R_BAD_CLIENT_REQUEST 105 | ||
| 1278 | #define SSL_R_BAD_DATA_RETURNED_BY_CALLBACK 106 | ||
| 1279 | #define SSL_R_BAD_DECOMPRESSION 107 | ||
| 1280 | #define SSL_R_BAD_DH_G_LENGTH 108 | ||
| 1281 | #define SSL_R_BAD_DH_PUB_KEY_LENGTH 109 | ||
| 1282 | #define SSL_R_BAD_DH_P_LENGTH 110 | ||
| 1283 | #define SSL_R_BAD_DIGEST_LENGTH 111 | ||
| 1284 | #define SSL_R_BAD_DSA_SIGNATURE 112 | ||
| 1285 | #define SSL_R_BAD_MAC_DECODE 113 | ||
| 1286 | #define SSL_R_BAD_MESSAGE_TYPE 114 | ||
| 1287 | #define SSL_R_BAD_PACKET_LENGTH 115 | ||
| 1288 | #define SSL_R_BAD_PROTOCOL_VERSION_NUMBER 116 | ||
| 1289 | #define SSL_R_BAD_RESPONSE_ARGUMENT 117 | ||
| 1290 | #define SSL_R_BAD_RSA_DECRYPT 118 | ||
| 1291 | #define SSL_R_BAD_RSA_ENCRYPT 119 | ||
| 1292 | #define SSL_R_BAD_RSA_E_LENGTH 120 | ||
| 1293 | #define SSL_R_BAD_RSA_MODULUS_LENGTH 121 | ||
| 1294 | #define SSL_R_BAD_RSA_SIGNATURE 122 | ||
| 1295 | #define SSL_R_BAD_SIGNATURE 123 | ||
| 1296 | #define SSL_R_BAD_SSL_FILETYPE 124 | ||
| 1297 | #define SSL_R_BAD_SSL_SESSION_ID_LENGTH 125 | ||
| 1298 | #define SSL_R_BAD_STATE 126 | ||
| 1299 | #define SSL_R_BAD_WRITE_RETRY 127 | ||
| 1300 | #define SSL_R_BIO_NOT_SET 128 | ||
| 1301 | #define SSL_R_BLOCK_CIPHER_PAD_IS_WRONG 129 | ||
| 1302 | #define SSL_R_BN_LIB 130 | ||
| 1303 | #define SSL_R_CA_DN_LENGTH_MISMATCH 131 | ||
| 1304 | #define SSL_R_CA_DN_TOO_LONG 132 | ||
| 1305 | #define SSL_R_CCS_RECEIVED_EARLY 133 | ||
| 1306 | #define SSL_R_CERTIFICATE_VERIFY_FAILED 134 | ||
| 1307 | #define SSL_R_CERT_LENGTH_MISMATCH 135 | ||
| 1308 | #define SSL_R_CHALLENGE_IS_DIFFERENT 136 | ||
| 1309 | #define SSL_R_CIPHER_CODE_WRONG_LENGTH 137 | ||
| 1310 | #define SSL_R_CIPHER_OR_HASH_UNAVAILABLE 138 | ||
| 1311 | #define SSL_R_CIPHER_TABLE_SRC_ERROR 139 | ||
| 1312 | #define SSL_R_COMPRESSED_LENGTH_TOO_LONG 140 | ||
| 1313 | #define SSL_R_COMPRESSION_FAILURE 141 | ||
| 1314 | #define SSL_R_CONNECTION_ID_IS_DIFFERENT 142 | ||
| 1315 | #define SSL_R_CONNECTION_TYPE_NOT_SET 143 | ||
| 1316 | #define SSL_R_DATA_BETWEEN_CCS_AND_FINISHED 144 | ||
| 1317 | #define SSL_R_DATA_LENGTH_TOO_LONG 145 | ||
| 1318 | #define SSL_R_DECRYPTION_FAILED 146 | ||
| 1319 | #define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG 147 | ||
| 1320 | #define SSL_R_DIGEST_CHECK_FAILED 148 | ||
| 1321 | #define SSL_R_ENCRYPTED_LENGTH_TOO_LONG 149 | ||
| 1322 | #define SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST 150 | ||
| 1323 | #define SSL_R_EXCESSIVE_MESSAGE_SIZE 151 | ||
| 1324 | #define SSL_R_EXTRA_DATA_IN_MESSAGE 152 | ||
| 1325 | #define SSL_R_GOT_A_FIN_BEFORE_A_CCS 153 | ||
| 1326 | #define SSL_R_HTTPS_PROXY_REQUEST 154 | ||
| 1327 | #define SSL_R_HTTP_REQUEST 155 | ||
| 1328 | #define SSL_R_INTERNAL_ERROR 156 | ||
| 1329 | #define SSL_R_INVALID_CHALLENGE_LENGTH 157 | ||
| 1330 | #define SSL_R_LENGTH_MISMATCH 158 | ||
| 1331 | #define SSL_R_LENGTH_TOO_SHORT 159 | ||
| 1332 | #define SSL_R_LIBRARY_HAS_NO_CIPHERS 160 | ||
| 1333 | #define SSL_R_MISSING_DH_DSA_CERT 161 | ||
| 1334 | #define SSL_R_MISSING_DH_KEY 162 | ||
| 1335 | #define SSL_R_MISSING_DH_RSA_CERT 163 | ||
| 1336 | #define SSL_R_MISSING_DSA_SIGNING_CERT 164 | ||
| 1337 | #define SSL_R_MISSING_EXPORT_TMP_DH_KEY 165 | ||
| 1338 | #define SSL_R_MISSING_EXPORT_TMP_RSA_KEY 166 | ||
| 1339 | #define SSL_R_MISSING_RSA_CERTIFICATE 167 | ||
| 1340 | #define SSL_R_MISSING_RSA_ENCRYPTING_CERT 168 | ||
| 1341 | #define SSL_R_MISSING_RSA_SIGNING_CERT 169 | ||
| 1342 | #define SSL_R_MISSING_TMP_DH_KEY 170 | ||
| 1343 | #define SSL_R_MISSING_TMP_RSA_KEY 171 | ||
| 1344 | #define SSL_R_MISSING_TMP_RSA_PKEY 172 | ||
| 1345 | #define SSL_R_MISSING_VERIFY_MESSAGE 173 | ||
| 1346 | #define SSL_R_NON_SSLV2_INITIAL_PACKET 174 | ||
| 1347 | #define SSL_R_NO_CERTIFICATES_RETURNED 175 | ||
| 1348 | #define SSL_R_NO_CERTIFICATE_ASSIGNED 176 | ||
| 1349 | #define SSL_R_NO_CERTIFICATE_RETURNED 177 | ||
| 1350 | #define SSL_R_NO_CERTIFICATE_SET 178 | ||
| 1351 | #define SSL_R_NO_CERTIFICATE_SPECIFIED 179 | ||
| 1352 | #define SSL_R_NO_CIPHERS_AVAILABLE 180 | ||
| 1353 | #define SSL_R_NO_CIPHERS_PASSED 181 | ||
| 1354 | #define SSL_R_NO_CIPHERS_SPECIFIED 182 | ||
| 1355 | #define SSL_R_NO_CIPHER_LIST 183 | ||
| 1356 | #define SSL_R_NO_CIPHER_MATCH 184 | ||
| 1357 | #define SSL_R_NO_CLIENT_CERT_RECEIVED 185 | ||
| 1358 | #define SSL_R_NO_COMPRESSION_SPECIFIED 186 | ||
| 1359 | #define SSL_R_NO_PRIVATEKEY 187 | ||
| 1360 | #define SSL_R_NO_PRIVATE_KEY_ASSIGNED 188 | ||
| 1361 | #define SSL_R_NO_PROTOCOLS_AVAILABLE 189 | ||
| 1362 | #define SSL_R_NO_PUBLICKEY 190 | ||
| 1363 | #define SSL_R_NO_SHARED_CIPHER 191 | ||
| 1364 | #define SSL_R_NULL_SSL_CTX 192 | ||
| 1365 | #define SSL_R_NULL_SSL_METHOD_PASSED 193 | ||
| 1366 | #define SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED 194 | ||
| 1367 | #define SSL_R_PACKET_LENGTH_TOO_LONG 195 | ||
| 1368 | #define SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE 196 | ||
| 1369 | #define SSL_R_PEER_ERROR 197 | ||
| 1370 | #define SSL_R_PEER_ERROR_CERTIFICATE 198 | ||
| 1371 | #define SSL_R_PEER_ERROR_NO_CERTIFICATE 199 | ||
| 1372 | #define SSL_R_PEER_ERROR_NO_CIPHER 200 | ||
| 1373 | #define SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE 201 | ||
| 1374 | #define SSL_R_PRE_MAC_LENGTH_TOO_LONG 202 | ||
| 1375 | #define SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS 203 | ||
| 1376 | #define SSL_R_PROTOCOL_IS_SHUTDOWN 204 | ||
| 1377 | #define SSL_R_PUBLIC_KEY_ENCRYPT_ERROR 205 | ||
| 1378 | #define SSL_R_PUBLIC_KEY_IS_NOT_RSA 206 | ||
| 1379 | #define SSL_R_PUBLIC_KEY_NOT_RSA 207 | ||
| 1380 | #define SSL_R_READ_BIO_NOT_SET 208 | ||
| 1381 | #define SSL_R_READ_WRONG_PACKET_TYPE 209 | ||
| 1382 | #define SSL_R_RECORD_LENGTH_MISMATCH 210 | ||
| 1383 | #define SSL_R_RECORD_TOO_LARGE 211 | ||
| 1384 | #define SSL_R_REQUIRED_CIPHER_MISSING 212 | ||
| 1385 | #define SSL_R_REUSE_CERT_LENGTH_NOT_ZERO 213 | ||
| 1386 | #define SSL_R_REUSE_CERT_TYPE_NOT_ZERO 214 | ||
| 1387 | #define SSL_R_REUSE_CIPHER_LIST_NOT_ZERO 215 | ||
| 1388 | #define SSL_R_SHORT_READ 216 | ||
| 1389 | #define SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE 217 | ||
| 1390 | #define SSL_R_SSL3_SESSION_ID_TOO_SHORT 218 | ||
| 1391 | #define SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042 | ||
| 1392 | #define SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020 | ||
| 1393 | #define SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED 1045 | ||
| 1394 | #define SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED 1044 | ||
| 1395 | #define SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN 1046 | ||
| 1396 | #define SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE 1030 | ||
| 1397 | #define SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE 1040 | ||
| 1398 | #define SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER 1047 | ||
| 1399 | #define SSL_R_SSLV3_ALERT_NO_CERTIFICATE 1041 | ||
| 1400 | #define SSL_R_SSLV3_ALERT_PEER_ERROR_CERTIFICATE 219 | ||
| 1401 | #define SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CERTIFICATE 220 | ||
| 1402 | #define SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CIPHER 221 | ||
| 1403 | #define SSL_R_SSLV3_ALERT_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE 222 | ||
| 1404 | #define SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010 | ||
| 1405 | #define SSL_R_SSLV3_ALERT_UNKNOWN_REMOTE_ERROR_TYPE 223 | ||
| 1406 | #define SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE 1043 | ||
| 1407 | #define SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION 224 | ||
| 1408 | #define SSL_R_SSL_HANDSHAKE_FAILURE 225 | ||
| 1409 | #define SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS 226 | ||
| 1410 | #define SSL_R_SSL_SESSION_ID_IS_DIFFERENT 227 | ||
| 1411 | #define SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER 228 | ||
| 1412 | #define SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST 229 | ||
| 1413 | #define SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG 230 | ||
| 1414 | #define SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER 231 | ||
| 1415 | #define SSL_R_UNABLE_TO_DECODE_DH_CERTS 232 | ||
| 1416 | #define SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY 233 | ||
| 1417 | #define SSL_R_UNABLE_TO_FIND_DH_PARAMETERS 234 | ||
| 1418 | #define SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS 235 | ||
| 1419 | #define SSL_R_UNABLE_TO_FIND_SSL_METHOD 236 | ||
| 1420 | #define SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES 237 | ||
| 1421 | #define SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES 238 | ||
| 1422 | #define SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES 239 | ||
| 1423 | #define SSL_R_UNEXPECTED_MESSAGE 240 | ||
| 1424 | #define SSL_R_UNEXPECTED_RECORD 241 | ||
| 1425 | #define SSL_R_UNKNOWN_ALERT_TYPE 242 | ||
| 1426 | #define SSL_R_UNKNOWN_CERTIFICATE_TYPE 243 | ||
| 1427 | #define SSL_R_UNKNOWN_CIPHER_RETURNED 244 | ||
| 1428 | #define SSL_R_UNKNOWN_CIPHER_TYPE 245 | ||
| 1429 | #define SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE 246 | ||
| 1430 | #define SSL_R_UNKNOWN_PKEY_TYPE 247 | ||
| 1431 | #define SSL_R_UNKNOWN_PROTOCOL 248 | ||
| 1432 | #define SSL_R_UNKNOWN_REMOTE_ERROR_TYPE 249 | ||
| 1433 | #define SSL_R_UNKNOWN_SSL_VERSION 250 | ||
| 1434 | #define SSL_R_UNKNOWN_STATE 251 | ||
| 1435 | #define SSL_R_UNSUPPORTED_CIPHER 252 | ||
| 1436 | #define SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM 253 | ||
| 1437 | #define SSL_R_UNSUPPORTED_PROTOCOL 254 | ||
| 1438 | #define SSL_R_UNSUPPORTED_SSL_VERSION 255 | ||
| 1439 | #define SSL_R_WRITE_BIO_NOT_SET 256 | ||
| 1440 | #define SSL_R_WRONG_CIPHER_RETURNED 257 | ||
| 1441 | #define SSL_R_WRONG_MESSAGE_TYPE 258 | ||
| 1442 | #define SSL_R_WRONG_NUMBER_OF_KEY_BITS 259 | ||
| 1443 | #define SSL_R_WRONG_SIGNATURE_LENGTH 260 | ||
| 1444 | #define SSL_R_WRONG_SIGNATURE_SIZE 261 | ||
| 1445 | #define SSL_R_WRONG_SSL_VERSION 262 | ||
| 1446 | #define SSL_R_WRONG_VERSION_NUMBER 263 | ||
| 1447 | #define SSL_R_X509_LIB 264 | ||
| 1448 | |||
| 1449 | #ifdef __cplusplus | ||
| 1450 | } | ||
| 1451 | #endif | ||
| 1452 | #endif | ||
| 1453 | |||
diff --git a/src/lib/libssl/ssl2.h b/src/lib/libssl/ssl2.h new file mode 100644 index 0000000000..3dc94e520b --- /dev/null +++ b/src/lib/libssl/ssl2.h | |||
| @@ -0,0 +1,265 @@ | |||
| 1 | /* ssl/ssl2.h */ | ||
| 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 | #ifndef HEADER_SSL2_H | ||
| 60 | #define HEADER_SSL2_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | /* Protocol Version Codes */ | ||
| 67 | #define SSL2_VERSION 0x0002 | ||
| 68 | #define SSL2_VERSION_MAJOR 0x00 | ||
| 69 | #define SSL2_VERSION_MINOR 0x02 | ||
| 70 | #define SSL2_CLIENT_VERSION 0x0002 | ||
| 71 | #define SSL2_SERVER_VERSION 0x0002 | ||
| 72 | |||
| 73 | /* Protocol Message Codes */ | ||
| 74 | #define SSL2_MT_ERROR 0 | ||
| 75 | #define SSL2_MT_CLIENT_HELLO 1 | ||
| 76 | #define SSL2_MT_CLIENT_MASTER_KEY 2 | ||
| 77 | #define SSL2_MT_CLIENT_FINISHED 3 | ||
| 78 | #define SSL2_MT_SERVER_HELLO 4 | ||
| 79 | #define SSL2_MT_SERVER_VERIFY 5 | ||
| 80 | #define SSL2_MT_SERVER_FINISHED 6 | ||
| 81 | #define SSL2_MT_REQUEST_CERTIFICATE 7 | ||
| 82 | #define SSL2_MT_CLIENT_CERTIFICATE 8 | ||
| 83 | |||
| 84 | /* Error Message Codes */ | ||
| 85 | #define SSL2_PE_UNDEFINED_ERROR 0x0000 | ||
| 86 | #define SSL2_PE_NO_CIPHER 0x0001 | ||
| 87 | #define SSL2_PE_NO_CERTIFICATE 0x0002 | ||
| 88 | #define SSL2_PE_BAD_CERTIFICATE 0x0004 | ||
| 89 | #define SSL2_PE_UNSUPPORTED_CERTIFICATE_TYPE 0x0006 | ||
| 90 | |||
| 91 | /* Cipher Kind Values */ | ||
| 92 | #define SSL2_CK_NULL_WITH_MD5 0x02000000 /* v3 */ | ||
| 93 | #define SSL2_CK_RC4_128_WITH_MD5 0x02010080 | ||
| 94 | #define SSL2_CK_RC4_128_EXPORT40_WITH_MD5 0x02020080 | ||
| 95 | #define SSL2_CK_RC2_128_CBC_WITH_MD5 0x02030080 | ||
| 96 | #define SSL2_CK_RC2_128_CBC_EXPORT40_WITH_MD5 0x02040080 | ||
| 97 | #define SSL2_CK_IDEA_128_CBC_WITH_MD5 0x02050080 | ||
| 98 | #define SSL2_CK_DES_64_CBC_WITH_MD5 0x02060040 | ||
| 99 | #define SSL2_CK_DES_64_CBC_WITH_SHA 0x02060140 /* v3 */ | ||
| 100 | #define SSL2_CK_DES_192_EDE3_CBC_WITH_MD5 0x020700c0 | ||
| 101 | #define SSL2_CK_DES_192_EDE3_CBC_WITH_SHA 0x020701c0 /* v3 */ | ||
| 102 | #define SSL2_CK_RC4_64_WITH_MD5 0x02080080 /* MS hack */ | ||
| 103 | |||
| 104 | #define SSL2_CK_DES_64_CFB64_WITH_MD5_1 0x02ff0800 /* SSLeay */ | ||
| 105 | #define SSL2_CK_NULL 0x02ff0810 /* SSLeay */ | ||
| 106 | |||
| 107 | #define SSL2_TXT_DES_64_CFB64_WITH_MD5_1 "DES-CFB-M1" | ||
| 108 | #define SSL2_TXT_NULL_WITH_MD5 "NULL-MD5" | ||
| 109 | #define SSL2_TXT_RC4_128_WITH_MD5 "RC4-MD5" | ||
| 110 | #define SSL2_TXT_RC4_128_EXPORT40_WITH_MD5 "EXP-RC4-MD5" | ||
| 111 | #define SSL2_TXT_RC2_128_CBC_WITH_MD5 "RC2-CBC-MD5" | ||
| 112 | #define SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 "EXP-RC2-CBC-MD5" | ||
| 113 | #define SSL2_TXT_IDEA_128_CBC_WITH_MD5 "IDEA-CBC-MD5" | ||
| 114 | #define SSL2_TXT_DES_64_CBC_WITH_MD5 "DES-CBC-MD5" | ||
| 115 | #define SSL2_TXT_DES_64_CBC_WITH_SHA "DES-CBC-SHA" | ||
| 116 | #define SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5 "DES-CBC3-MD5" | ||
| 117 | #define SSL2_TXT_DES_192_EDE3_CBC_WITH_SHA "DES-CBC3-SHA" | ||
| 118 | #define SSL2_TXT_RC4_64_WITH_MD5 "RC4-64-MD5" | ||
| 119 | |||
| 120 | #define SSL2_TXT_NULL "NULL" | ||
| 121 | |||
| 122 | /* Flags for the SSL_CIPHER.algorithm2 field */ | ||
| 123 | #define SSL2_CF_5_BYTE_ENC 0x01 | ||
| 124 | #define SSL2_CF_8_BYTE_ENC 0x02 | ||
| 125 | |||
| 126 | /* Certificate Type Codes */ | ||
| 127 | #define SSL2_CT_X509_CERTIFICATE 0x01 | ||
| 128 | |||
| 129 | /* Authentication Type Code */ | ||
| 130 | #define SSL2_AT_MD5_WITH_RSA_ENCRYPTION 0x01 | ||
| 131 | |||
| 132 | #define SSL2_MAX_SSL_SESSION_ID_LENGTH 32 | ||
| 133 | |||
| 134 | /* Upper/Lower Bounds */ | ||
| 135 | #define SSL2_MAX_MASTER_KEY_LENGTH_IN_BITS 256 | ||
| 136 | #define SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER (unsigned int)32767 | ||
| 137 | #define SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER 16383 /**/ | ||
| 138 | |||
| 139 | #define SSL2_CHALLENGE_LENGTH 16 | ||
| 140 | /*#define SSL2_CHALLENGE_LENGTH 32 */ | ||
| 141 | #define SSL2_MIN_CHALLENGE_LENGTH 16 | ||
| 142 | #define SSL2_MAX_CHALLENGE_LENGTH 32 | ||
| 143 | #define SSL2_CONNECTION_ID_LENGTH 16 | ||
| 144 | #define SSL2_MAX_CONNECTION_ID_LENGTH 16 | ||
| 145 | #define SSL2_SSL_SESSION_ID_LENGTH 16 | ||
| 146 | #define SSL2_MAX_CERT_CHALLENGE_LENGTH 32 | ||
| 147 | #define SSL2_MIN_CERT_CHALLENGE_LENGTH 16 | ||
| 148 | #define SSL2_MAX_KEY_MATERIAL_LENGTH 24 | ||
| 149 | |||
| 150 | #ifndef HEADER_SSL_LOCL_H | ||
| 151 | #define CERT char | ||
| 152 | #endif | ||
| 153 | |||
| 154 | typedef struct ssl2_ctx_st | ||
| 155 | { | ||
| 156 | int three_byte_header; | ||
| 157 | int clear_text; /* clear text */ | ||
| 158 | int escape; /* not used in SSLv2 */ | ||
| 159 | int ssl2_rollback; /* used if SSLv23 rolled back to SSLv2 */ | ||
| 160 | |||
| 161 | /* non-blocking io info, used to make sure the same | ||
| 162 | * args were passwd */ | ||
| 163 | unsigned int wnum; /* number of bytes sent so far */ | ||
| 164 | int wpend_tot; | ||
| 165 | char *wpend_buf; | ||
| 166 | |||
| 167 | int wpend_off; /* offset to data to write */ | ||
| 168 | int wpend_len; /* number of bytes passwd to write */ | ||
| 169 | int wpend_ret; /* number of bytes to return to caller */ | ||
| 170 | |||
| 171 | /* buffer raw data */ | ||
| 172 | int rbuf_left; | ||
| 173 | int rbuf_offs; | ||
| 174 | unsigned char *rbuf; | ||
| 175 | unsigned char *wbuf; | ||
| 176 | |||
| 177 | unsigned char *write_ptr;/* used to point to the start due to | ||
| 178 | * 2/3 byte header. */ | ||
| 179 | |||
| 180 | unsigned int padding; | ||
| 181 | unsigned int rlength; /* passed to ssl2_enc */ | ||
| 182 | int ract_data_length; /* Set when things are encrypted. */ | ||
| 183 | unsigned int wlength; /* passed to ssl2_enc */ | ||
| 184 | int wact_data_length; /* Set when things are decrypted. */ | ||
| 185 | unsigned char *ract_data; | ||
| 186 | unsigned char *wact_data; | ||
| 187 | unsigned char *mac_data; | ||
| 188 | unsigned char *pad_data; | ||
| 189 | |||
| 190 | unsigned char *read_key; | ||
| 191 | unsigned char *write_key; | ||
| 192 | |||
| 193 | /* Stuff specifically to do with this SSL session */ | ||
| 194 | unsigned int challenge_length; | ||
| 195 | unsigned char challenge[SSL2_MAX_CHALLENGE_LENGTH]; | ||
| 196 | unsigned int conn_id_length; | ||
| 197 | unsigned char conn_id[SSL2_MAX_CONNECTION_ID_LENGTH]; | ||
| 198 | unsigned int key_material_length; | ||
| 199 | unsigned char key_material[SSL2_MAX_KEY_MATERIAL_LENGTH*2]; | ||
| 200 | |||
| 201 | unsigned long read_sequence; | ||
| 202 | unsigned long write_sequence; | ||
| 203 | |||
| 204 | struct { | ||
| 205 | unsigned int conn_id_length; | ||
| 206 | unsigned int cert_type; | ||
| 207 | unsigned int cert_length; | ||
| 208 | int csl; | ||
| 209 | int clear; | ||
| 210 | unsigned int enc; | ||
| 211 | unsigned char ccl[SSL2_MAX_CERT_CHALLENGE_LENGTH]; | ||
| 212 | int cipher_spec_length; | ||
| 213 | unsigned int session_id_length; | ||
| 214 | unsigned int clen; | ||
| 215 | unsigned int rlen; | ||
| 216 | } tmp; | ||
| 217 | } SSL2_CTX; | ||
| 218 | |||
| 219 | /* SSLv2 */ | ||
| 220 | /* client */ | ||
| 221 | #define SSL2_ST_SEND_CLIENT_HELLO_A (0x10|SSL_ST_CONNECT) | ||
| 222 | #define SSL2_ST_SEND_CLIENT_HELLO_B (0x11|SSL_ST_CONNECT) | ||
| 223 | #define SSL2_ST_GET_SERVER_HELLO_A (0x20|SSL_ST_CONNECT) | ||
| 224 | #define SSL2_ST_GET_SERVER_HELLO_B (0x21|SSL_ST_CONNECT) | ||
| 225 | #define SSL2_ST_SEND_CLIENT_MASTER_KEY_A (0x30|SSL_ST_CONNECT) | ||
| 226 | #define SSL2_ST_SEND_CLIENT_MASTER_KEY_B (0x31|SSL_ST_CONNECT) | ||
| 227 | #define SSL2_ST_SEND_CLIENT_FINISHED_A (0x40|SSL_ST_CONNECT) | ||
| 228 | #define SSL2_ST_SEND_CLIENT_FINISHED_B (0x41|SSL_ST_CONNECT) | ||
| 229 | #define SSL2_ST_SEND_CLIENT_CERTIFICATE_A (0x50|SSL_ST_CONNECT) | ||
| 230 | #define SSL2_ST_SEND_CLIENT_CERTIFICATE_B (0x51|SSL_ST_CONNECT) | ||
| 231 | #define SSL2_ST_SEND_CLIENT_CERTIFICATE_C (0x52|SSL_ST_CONNECT) | ||
| 232 | #define SSL2_ST_SEND_CLIENT_CERTIFICATE_D (0x53|SSL_ST_CONNECT) | ||
| 233 | #define SSL2_ST_GET_SERVER_VERIFY_A (0x60|SSL_ST_CONNECT) | ||
| 234 | #define SSL2_ST_GET_SERVER_VERIFY_B (0x61|SSL_ST_CONNECT) | ||
| 235 | #define SSL2_ST_GET_SERVER_FINISHED_A (0x70|SSL_ST_CONNECT) | ||
| 236 | #define SSL2_ST_GET_SERVER_FINISHED_B (0x71|SSL_ST_CONNECT) | ||
| 237 | #define SSL2_ST_CLIENT_START_ENCRYPTION (0x80|SSL_ST_CONNECT) | ||
| 238 | #define SSL2_ST_X509_GET_CLIENT_CERTIFICATE (0x90|SSL_ST_CONNECT) | ||
| 239 | /* server */ | ||
| 240 | #define SSL2_ST_GET_CLIENT_HELLO_A (0x10|SSL_ST_ACCEPT) | ||
| 241 | #define SSL2_ST_GET_CLIENT_HELLO_B (0x11|SSL_ST_ACCEPT) | ||
| 242 | #define SSL2_ST_GET_CLIENT_HELLO_C (0x12|SSL_ST_ACCEPT) | ||
| 243 | #define SSL2_ST_SEND_SERVER_HELLO_A (0x20|SSL_ST_ACCEPT) | ||
| 244 | #define SSL2_ST_SEND_SERVER_HELLO_B (0x21|SSL_ST_ACCEPT) | ||
| 245 | #define SSL2_ST_GET_CLIENT_MASTER_KEY_A (0x30|SSL_ST_ACCEPT) | ||
| 246 | #define SSL2_ST_GET_CLIENT_MASTER_KEY_B (0x31|SSL_ST_ACCEPT) | ||
| 247 | #define SSL2_ST_SEND_SERVER_VERIFY_A (0x40|SSL_ST_ACCEPT) | ||
| 248 | #define SSL2_ST_SEND_SERVER_VERIFY_B (0x41|SSL_ST_ACCEPT) | ||
| 249 | #define SSL2_ST_SEND_SERVER_VERIFY_C (0x42|SSL_ST_ACCEPT) | ||
| 250 | #define SSL2_ST_GET_CLIENT_FINISHED_A (0x50|SSL_ST_ACCEPT) | ||
| 251 | #define SSL2_ST_GET_CLIENT_FINISHED_B (0x51|SSL_ST_ACCEPT) | ||
| 252 | #define SSL2_ST_SEND_SERVER_FINISHED_A (0x60|SSL_ST_ACCEPT) | ||
| 253 | #define SSL2_ST_SEND_SERVER_FINISHED_B (0x61|SSL_ST_ACCEPT) | ||
| 254 | #define SSL2_ST_SEND_REQUEST_CERTIFICATE_A (0x70|SSL_ST_ACCEPT) | ||
| 255 | #define SSL2_ST_SEND_REQUEST_CERTIFICATE_B (0x71|SSL_ST_ACCEPT) | ||
| 256 | #define SSL2_ST_SEND_REQUEST_CERTIFICATE_C (0x72|SSL_ST_ACCEPT) | ||
| 257 | #define SSL2_ST_SEND_REQUEST_CERTIFICATE_D (0x73|SSL_ST_ACCEPT) | ||
| 258 | #define SSL2_ST_SERVER_START_ENCRYPTION (0x80|SSL_ST_ACCEPT) | ||
| 259 | #define SSL2_ST_X509_GET_SERVER_CERTIFICATE (0x90|SSL_ST_ACCEPT) | ||
| 260 | |||
| 261 | #ifdef __cplusplus | ||
| 262 | } | ||
| 263 | #endif | ||
| 264 | #endif | ||
| 265 | |||
diff --git a/src/lib/libssl/ssl23.h b/src/lib/libssl/ssl23.h new file mode 100644 index 0000000000..d3228983c7 --- /dev/null +++ b/src/lib/libssl/ssl23.h | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | /* ssl/ssl23.h */ | ||
| 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 | #ifndef HEADER_SSL23_H | ||
| 60 | #define HEADER_SSL23_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | /*client */ | ||
| 67 | /* write to server */ | ||
| 68 | #define SSL23_ST_CW_CLNT_HELLO_A (0x210|SSL_ST_CONNECT) | ||
| 69 | #define SSL23_ST_CW_CLNT_HELLO_B (0x211|SSL_ST_CONNECT) | ||
| 70 | /* read from server */ | ||
| 71 | #define SSL23_ST_CR_SRVR_HELLO_A (0x220|SSL_ST_CONNECT) | ||
| 72 | #define SSL23_ST_CR_SRVR_HELLO_B (0x221|SSL_ST_CONNECT) | ||
| 73 | |||
| 74 | /* server */ | ||
| 75 | /* read from client */ | ||
| 76 | #define SSL23_ST_SR_CLNT_HELLO_A (0x210|SSL_ST_ACCEPT) | ||
| 77 | #define SSL23_ST_SR_CLNT_HELLO_B (0x211|SSL_ST_ACCEPT) | ||
| 78 | |||
| 79 | #ifdef __cplusplus | ||
| 80 | } | ||
| 81 | #endif | ||
| 82 | #endif | ||
| 83 | |||
diff --git a/src/lib/libssl/ssl3.h b/src/lib/libssl/ssl3.h new file mode 100644 index 0000000000..95772eef60 --- /dev/null +++ b/src/lib/libssl/ssl3.h | |||
| @@ -0,0 +1,455 @@ | |||
| 1 | /* ssl/ssl3.h */ | ||
| 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 | #ifndef HEADER_SSL3_H | ||
| 60 | #define HEADER_SSL3_H | ||
| 61 | |||
| 62 | #include "buffer.h" | ||
| 63 | |||
| 64 | #ifdef __cplusplus | ||
| 65 | extern "C" { | ||
| 66 | #endif | ||
| 67 | |||
| 68 | #define SSL3_CK_RSA_NULL_MD5 0x03000001 | ||
| 69 | #define SSL3_CK_RSA_NULL_SHA 0x03000002 | ||
| 70 | #define SSL3_CK_RSA_RC4_40_MD5 0x03000003 | ||
| 71 | #define SSL3_CK_RSA_RC4_128_MD5 0x03000004 | ||
| 72 | #define SSL3_CK_RSA_RC4_128_SHA 0x03000005 | ||
| 73 | #define SSL3_CK_RSA_RC2_40_MD5 0x03000006 | ||
| 74 | #define SSL3_CK_RSA_IDEA_128_SHA 0x03000007 | ||
| 75 | #define SSL3_CK_RSA_DES_40_CBC_SHA 0x03000008 | ||
| 76 | #define SSL3_CK_RSA_DES_64_CBC_SHA 0x03000009 | ||
| 77 | #define SSL3_CK_RSA_DES_192_CBC3_SHA 0x0300000A | ||
| 78 | |||
| 79 | #define SSL3_CK_DH_DSS_DES_40_CBC_SHA 0x0300000B | ||
| 80 | #define SSL3_CK_DH_DSS_DES_64_CBC_SHA 0x0300000C | ||
| 81 | #define SSL3_CK_DH_DSS_DES_192_CBC3_SHA 0x0300000D | ||
| 82 | #define SSL3_CK_DH_RSA_DES_40_CBC_SHA 0x0300000E | ||
| 83 | #define SSL3_CK_DH_RSA_DES_64_CBC_SHA 0x0300000F | ||
| 84 | #define SSL3_CK_DH_RSA_DES_192_CBC3_SHA 0x03000010 | ||
| 85 | |||
| 86 | #define SSL3_CK_EDH_DSS_DES_40_CBC_SHA 0x03000011 | ||
| 87 | #define SSL3_CK_EDH_DSS_DES_64_CBC_SHA 0x03000012 | ||
| 88 | #define SSL3_CK_EDH_DSS_DES_192_CBC3_SHA 0x03000013 | ||
| 89 | #define SSL3_CK_EDH_RSA_DES_40_CBC_SHA 0x03000014 | ||
| 90 | #define SSL3_CK_EDH_RSA_DES_64_CBC_SHA 0x03000015 | ||
| 91 | #define SSL3_CK_EDH_RSA_DES_192_CBC3_SHA 0x03000016 | ||
| 92 | |||
| 93 | #define SSL3_CK_ADH_RC4_40_MD5 0x03000017 | ||
| 94 | #define SSL3_CK_ADH_RC4_128_MD5 0x03000018 | ||
| 95 | #define SSL3_CK_ADH_DES_40_CBC_SHA 0x03000019 | ||
| 96 | #define SSL3_CK_ADH_DES_64_CBC_SHA 0x0300001A | ||
| 97 | #define SSL3_CK_ADH_DES_192_CBC_SHA 0x0300001B | ||
| 98 | |||
| 99 | #define SSL3_CK_FZA_DMS_NULL_SHA 0x0300001C | ||
| 100 | #define SSL3_CK_FZA_DMS_FZA_SHA 0x0300001D | ||
| 101 | #define SSL3_CK_FZA_DMS_RC4_SHA 0x0300001E | ||
| 102 | |||
| 103 | #define SSL3_TXT_RSA_NULL_MD5 "NULL-MD5" | ||
| 104 | #define SSL3_TXT_RSA_NULL_SHA "NULL-SHA" | ||
| 105 | #define SSL3_TXT_RSA_RC4_40_MD5 "EXP-RC4-MD5" | ||
| 106 | #define SSL3_TXT_RSA_RC4_128_MD5 "RC4-MD5" | ||
| 107 | #define SSL3_TXT_RSA_RC4_128_SHA "RC4-SHA" | ||
| 108 | #define SSL3_TXT_RSA_RC2_40_MD5 "EXP-RC2-CBC-MD5" | ||
| 109 | #define SSL3_TXT_RSA_IDEA_128_SHA "IDEA-CBC-SHA" | ||
| 110 | #define SSL3_TXT_RSA_DES_40_CBC_SHA "EXP-DES-CBC-SHA" | ||
| 111 | #define SSL3_TXT_RSA_DES_64_CBC_SHA "DES-CBC-SHA" | ||
| 112 | #define SSL3_TXT_RSA_DES_192_CBC3_SHA "DES-CBC3-SHA" | ||
| 113 | |||
| 114 | #define SSL3_TXT_DH_DSS_DES_40_CBC_SHA "EXP-DH-DSS-DES-CBC-SHA" | ||
| 115 | #define SSL3_TXT_DH_DSS_DES_64_CBC_SHA "DH-DSS-DES-CBC-SHA" | ||
| 116 | #define SSL3_TXT_DH_DSS_DES_192_CBC3_SHA "DH-DSS-DES-CBC3-SHA" | ||
| 117 | #define SSL3_TXT_DH_RSA_DES_40_CBC_SHA "EXP-DH-RSA-DES-CBC-SHA" | ||
| 118 | #define SSL3_TXT_DH_RSA_DES_64_CBC_SHA "DH-RSA-DES-CBC-SHA" | ||
| 119 | #define SSL3_TXT_DH_RSA_DES_192_CBC3_SHA "DH-RSA-DES-CBC3-SHA" | ||
| 120 | |||
| 121 | #define SSL3_TXT_EDH_DSS_DES_40_CBC_SHA "EXP-EDH-DSS-DES-CBC-SHA" | ||
| 122 | #define SSL3_TXT_EDH_DSS_DES_64_CBC_SHA "EDH-DSS-DES-CBC-SHA" | ||
| 123 | #define SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA "EDH-DSS-DES-CBC3-SHA" | ||
| 124 | #define SSL3_TXT_EDH_RSA_DES_40_CBC_SHA "EXP-EDH-RSA-DES-CBC-SHA" | ||
| 125 | #define SSL3_TXT_EDH_RSA_DES_64_CBC_SHA "EDH-RSA-DES-CBC-SHA" | ||
| 126 | #define SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA "EDH-RSA-DES-CBC3-SHA" | ||
| 127 | |||
| 128 | #define SSL3_TXT_ADH_RC4_40_MD5 "EXP-ADH-RC4-MD5" | ||
| 129 | #define SSL3_TXT_ADH_RC4_128_MD5 "ADH-RC4-MD5" | ||
| 130 | #define SSL3_TXT_ADH_DES_40_CBC_SHA "EXP-ADH-DES-CBC-SHA" | ||
| 131 | #define SSL3_TXT_ADH_DES_64_CBC_SHA "ADH-DES-CBC-SHA" | ||
| 132 | #define SSL3_TXT_ADH_DES_192_CBC_SHA "ADH-DES-CBC3-SHA" | ||
| 133 | |||
| 134 | #define SSL3_TXT_FZA_DMS_NULL_SHA "FZA-NULL-SHA" | ||
| 135 | #define SSL3_TXT_FZA_DMS_FZA_SHA "FZA-FZA-CBC-SHA" | ||
| 136 | #define SSL3_TXT_FZA_DMS_RC4_SHA "FZA-RC4-SHA" | ||
| 137 | |||
| 138 | #define SSL3_SSL_SESSION_ID_LENGTH 32 | ||
| 139 | #define SSL3_MAX_SSL_SESSION_ID_LENGTH 32 | ||
| 140 | |||
| 141 | #define SSL3_MASTER_SECRET_SIZE 48 | ||
| 142 | #define SSL3_RANDOM_SIZE 32 | ||
| 143 | #define SSL3_SESSION_ID_SIZE 32 | ||
| 144 | #define SSL3_RT_HEADER_LENGTH 5 | ||
| 145 | |||
| 146 | /* Due to MS stuffing up, this can change.... */ | ||
| 147 | #if defined(WIN16) || (defined(MSDOS) && !defined(WIN32)) | ||
| 148 | #define SSL3_RT_MAX_EXTRA (14000) | ||
| 149 | #else | ||
| 150 | #define SSL3_RT_MAX_EXTRA (16384) | ||
| 151 | #endif | ||
| 152 | |||
| 153 | #define SSL3_RT_MAX_PLAIN_LENGTH 16384 | ||
| 154 | #define SSL3_RT_MAX_COMPRESSED_LENGTH (1024+SSL3_RT_MAX_PLAIN_LENGTH) | ||
| 155 | #define SSL3_RT_MAX_ENCRYPTED_LENGTH (1024+SSL3_RT_MAX_COMPRESSED_LENGTH) | ||
| 156 | #define SSL3_RT_MAX_PACKET_SIZE (SSL3_RT_MAX_ENCRYPTED_LENGTH+SSL3_RT_HEADER_LENGTH) | ||
| 157 | #define SSL3_RT_MAX_DATA_SIZE (1024*1024) | ||
| 158 | |||
| 159 | /* the states that a SSL3_RECORD can be in | ||
| 160 | * For SSL_read it goes | ||
| 161 | * rbuf->ENCODED -> read | ||
| 162 | * ENCODED -> we need to decode everything - call decode_record | ||
| 163 | */ | ||
| 164 | |||
| 165 | #define SSL3_RS_BLANK 1 | ||
| 166 | #define SSL3_RS_DATA | ||
| 167 | |||
| 168 | #define SSL3_RS_ENCODED 2 | ||
| 169 | #define SSL3_RS_READ_MORE 3 | ||
| 170 | #define SSL3_RS_WRITE_MORE | ||
| 171 | #define SSL3_RS_PLAIN 3 | ||
| 172 | #define SSL3_RS_PART_READ 4 | ||
| 173 | #define SSL3_RS_PART_WRITE 5 | ||
| 174 | |||
| 175 | #define SSL3_MD_CLIENT_FINISHED_CONST {0x43,0x4C,0x4E,0x54} | ||
| 176 | #define SSL3_MD_SERVER_FINISHED_CONST {0x53,0x52,0x56,0x52} | ||
| 177 | |||
| 178 | #define SSL3_VERSION 0x0300 | ||
| 179 | #define SSL3_VERSION_MAJOR 0x03 | ||
| 180 | #define SSL3_VERSION_MINOR 0x00 | ||
| 181 | |||
| 182 | #define SSL3_RT_CHANGE_CIPHER_SPEC 20 | ||
| 183 | #define SSL3_RT_ALERT 21 | ||
| 184 | #define SSL3_RT_HANDSHAKE 22 | ||
| 185 | #define SSL3_RT_APPLICATION_DATA 23 | ||
| 186 | |||
| 187 | #define SSL3_AL_WARNING 1 | ||
| 188 | #define SSL3_AL_FATAL 2 | ||
| 189 | |||
| 190 | #define SSL3_AD_CLOSE_NOTIFY 0 | ||
| 191 | #define SSL3_AD_UNEXPECTED_MESSAGE 10 /* fatal */ | ||
| 192 | #define SSL3_AD_BAD_RECORD_MAC 20 /* fatal */ | ||
| 193 | #define SSL3_AD_DECOMPRESSION_FAILURE 30 /* fatal */ | ||
| 194 | #define SSL3_AD_HANDSHAKE_FAILURE 40 /* fatal */ | ||
| 195 | #define SSL3_AD_NO_CERTIFICATE 41 | ||
| 196 | #define SSL3_AD_BAD_CERTIFICATE 42 | ||
| 197 | #define SSL3_AD_UNSUPPORTED_CERTIFICATE 43 | ||
| 198 | #define SSL3_AD_CERTIFICATE_REVOKED 44 | ||
| 199 | #define SSL3_AD_CERTIFICATE_EXPIRED 45 | ||
| 200 | #define SSL3_AD_CERTIFICATE_UNKNOWN 46 | ||
| 201 | #define SSL3_AD_ILLEGAL_PARAMETER 47 /* fatal */ | ||
| 202 | |||
| 203 | typedef struct ssl3_record_st | ||
| 204 | { | ||
| 205 | /*r */ int type; /* type of record */ | ||
| 206 | /* */ /*int state;*/ /* any data in it? */ | ||
| 207 | /*rw*/ unsigned int length; /* How many bytes available */ | ||
| 208 | /*r */ unsigned int off; /* read/write offset into 'buf' */ | ||
| 209 | /*rw*/ unsigned char *data; /* pointer to the record data */ | ||
| 210 | /*rw*/ unsigned char *input; /* where the decode bytes are */ | ||
| 211 | /*rw*/ unsigned char *comp; /* only used with decompression */ | ||
| 212 | } SSL3_RECORD; | ||
| 213 | |||
| 214 | typedef struct ssl3_buffer_st | ||
| 215 | { | ||
| 216 | /*r */ int total; /* used in non-blocking writes */ | ||
| 217 | /*r */ int wanted; /* how many more bytes we need */ | ||
| 218 | /*rw*/ int left; /* how many bytes left */ | ||
| 219 | /*rw*/ int offset; /* where to 'copy from' */ | ||
| 220 | /*rw*/ unsigned char *buf; /* SSL3_RT_MAX_PACKET_SIZE bytes */ | ||
| 221 | } SSL3_BUFFER; | ||
| 222 | |||
| 223 | typedef struct ssl3_compression_st { | ||
| 224 | int nothing; | ||
| 225 | } SSL3_COMPRESSION; | ||
| 226 | |||
| 227 | #define SSL3_CT_RSA_SIGN 1 | ||
| 228 | #define SSL3_CT_DSS_SIGN 2 | ||
| 229 | #define SSL3_CT_RSA_FIXED_DH 3 | ||
| 230 | #define SSL3_CT_DSS_FIXED_DH 4 | ||
| 231 | #define SSL3_CT_RSA_EPHEMERAL_DH 5 | ||
| 232 | #define SSL3_CT_DSS_EPHEMERAL_DH 6 | ||
| 233 | #define SSL3_CT_FORTEZZA_DMS 20 | ||
| 234 | #define SSL3_CT_NUMBER 7 | ||
| 235 | |||
| 236 | #define SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS 0x0001 | ||
| 237 | #define SSL3_FLAGS_DELAY_CLIENT_FINISHED 0x0002 | ||
| 238 | #define SSL3_FLAGS_POP_BUFFER 0x0004 | ||
| 239 | #define TLS1_FLAGS_TLS_PADDING_BUG 0x0008 | ||
| 240 | |||
| 241 | #if 0 | ||
| 242 | #define AD_CLOSE_NOTIFY 0 | ||
| 243 | #define AD_UNEXPECTED_MESSAGE 1 | ||
| 244 | #define AD_BAD_RECORD_MAC 2 | ||
| 245 | #define AD_DECRYPTION_FAILED 3 | ||
| 246 | #define AD_RECORD_OVERFLOW 4 | ||
| 247 | #define AD_DECOMPRESSION_FAILURE 5 /* fatal */ | ||
| 248 | #define AD_HANDSHAKE_FAILURE 6 /* fatal */ | ||
| 249 | #define AD_NO_CERTIFICATE 7 /* Not under TLS */ | ||
| 250 | #define AD_BAD_CERTIFICATE 8 | ||
| 251 | #define AD_UNSUPPORTED_CERTIFICATE 9 | ||
| 252 | #define AD_CERTIFICATE_REVOKED 10 | ||
| 253 | #define AD_CERTIFICATE_EXPIRED 11 | ||
| 254 | #define AD_CERTIFICATE_UNKNOWN 12 | ||
| 255 | #define AD_ILLEGAL_PARAMETER 13 /* fatal */ | ||
| 256 | #define AD_UNKNOWN_CA 14 /* fatal */ | ||
| 257 | #define AD_ACCESS_DENIED 15 /* fatal */ | ||
| 258 | #define AD_DECODE_ERROR 16 /* fatal */ | ||
| 259 | #define AD_DECRYPT_ERROR 17 | ||
| 260 | #define AD_EXPORT_RESTRICION 18 /* fatal */ | ||
| 261 | #define AD_PROTOCOL_VERSION 19 /* fatal */ | ||
| 262 | #define AD_INSUFFICIENT_SECURITY 20 /* fatal */ | ||
| 263 | #define AD_INTERNAL_ERROR 21 /* fatal */ | ||
| 264 | #define AD_USER_CANCLED 22 | ||
| 265 | #define AD_NO_RENEGOTIATION 23 | ||
| 266 | #endif | ||
| 267 | |||
| 268 | typedef struct ssl3_ctx_st | ||
| 269 | { | ||
| 270 | long flags; | ||
| 271 | int delay_buf_pop_ret; | ||
| 272 | |||
| 273 | unsigned char read_sequence[8]; | ||
| 274 | unsigned char read_mac_secret[EVP_MAX_MD_SIZE]; | ||
| 275 | unsigned char write_sequence[8]; | ||
| 276 | unsigned char write_mac_secret[EVP_MAX_MD_SIZE]; | ||
| 277 | |||
| 278 | unsigned char server_random[SSL3_RANDOM_SIZE]; | ||
| 279 | unsigned char client_random[SSL3_RANDOM_SIZE]; | ||
| 280 | |||
| 281 | SSL3_BUFFER rbuf; /* read IO goes into here */ | ||
| 282 | SSL3_BUFFER wbuf; /* write IO goes into here */ | ||
| 283 | SSL3_RECORD rrec; /* each decoded record goes in here */ | ||
| 284 | SSL3_RECORD wrec; /* goes out from here */ | ||
| 285 | /* Used by ssl3_read_n to point | ||
| 286 | * to input data packet */ | ||
| 287 | |||
| 288 | /* partial write - check the numbers match */ | ||
| 289 | unsigned int wnum; /* number of bytes sent so far */ | ||
| 290 | int wpend_tot; /* number bytes written */ | ||
| 291 | int wpend_type; | ||
| 292 | int wpend_ret; /* number of bytes submitted */ | ||
| 293 | char *wpend_buf; | ||
| 294 | |||
| 295 | /* used during startup, digest all incoming/outgoing packets */ | ||
| 296 | EVP_MD_CTX finish_dgst1; | ||
| 297 | EVP_MD_CTX finish_dgst2; | ||
| 298 | |||
| 299 | /* this is set whenerver we see a change_cipher_spec message | ||
| 300 | * come in when we are not looking for one */ | ||
| 301 | int change_cipher_spec; | ||
| 302 | |||
| 303 | int warn_alert; | ||
| 304 | int fatal_alert; | ||
| 305 | /* we alow one fatal and one warning alert to be outstanding, | ||
| 306 | * send close alert via the warning alert */ | ||
| 307 | int alert_dispatch; | ||
| 308 | char send_alert[2]; | ||
| 309 | |||
| 310 | /* This flag is set when we should renegotiate ASAP, basically when | ||
| 311 | * there is no more data in the read or write buffers */ | ||
| 312 | int renegotiate; | ||
| 313 | int total_renegotiations; | ||
| 314 | int num_renegotiations; | ||
| 315 | |||
| 316 | int in_read_app_data; | ||
| 317 | |||
| 318 | struct { | ||
| 319 | /* Actually only needs to be 16+20 for SSLv3 and 12 for TLS */ | ||
| 320 | unsigned char finish_md[EVP_MAX_MD_SIZE*2]; | ||
| 321 | |||
| 322 | unsigned long message_size; | ||
| 323 | int message_type; | ||
| 324 | |||
| 325 | /* used to hold the new cipher we are going to use */ | ||
| 326 | SSL_CIPHER *new_cipher; | ||
| 327 | DH *dh; | ||
| 328 | |||
| 329 | /* used when SSL_ST_FLUSH_DATA is entered */ | ||
| 330 | int next_state; | ||
| 331 | |||
| 332 | int reuse_message; | ||
| 333 | |||
| 334 | /* used for certificate requests */ | ||
| 335 | int cert_req; | ||
| 336 | int ctype_num; | ||
| 337 | char ctype[SSL3_CT_NUMBER]; | ||
| 338 | STACK *ca_names; | ||
| 339 | |||
| 340 | int use_rsa_tmp; | ||
| 341 | |||
| 342 | int key_block_length; | ||
| 343 | unsigned char *key_block; | ||
| 344 | |||
| 345 | EVP_CIPHER *new_sym_enc; | ||
| 346 | EVP_MD *new_hash; | ||
| 347 | SSL_COMPRESSION *new_compression; | ||
| 348 | int cert_request; | ||
| 349 | } tmp; | ||
| 350 | } SSL3_CTX; | ||
| 351 | |||
| 352 | /* SSLv3 */ | ||
| 353 | /*client */ | ||
| 354 | /* extra state */ | ||
| 355 | #define SSL3_ST_CW_FLUSH (0x100|SSL_ST_CONNECT) | ||
| 356 | /* write to server */ | ||
| 357 | #define SSL3_ST_CW_CLNT_HELLO_A (0x110|SSL_ST_CONNECT) | ||
| 358 | #define SSL3_ST_CW_CLNT_HELLO_B (0x111|SSL_ST_CONNECT) | ||
| 359 | /* read from server */ | ||
| 360 | #define SSL3_ST_CR_SRVR_HELLO_A (0x120|SSL_ST_CONNECT) | ||
| 361 | #define SSL3_ST_CR_SRVR_HELLO_B (0x121|SSL_ST_CONNECT) | ||
| 362 | #define SSL3_ST_CR_CERT_A (0x130|SSL_ST_CONNECT) | ||
| 363 | #define SSL3_ST_CR_CERT_B (0x131|SSL_ST_CONNECT) | ||
| 364 | #define SSL3_ST_CR_KEY_EXCH_A (0x140|SSL_ST_CONNECT) | ||
| 365 | #define SSL3_ST_CR_KEY_EXCH_B (0x141|SSL_ST_CONNECT) | ||
| 366 | #define SSL3_ST_CR_CERT_REQ_A (0x150|SSL_ST_CONNECT) | ||
| 367 | #define SSL3_ST_CR_CERT_REQ_B (0x151|SSL_ST_CONNECT) | ||
| 368 | #define SSL3_ST_CR_SRVR_DONE_A (0x160|SSL_ST_CONNECT) | ||
| 369 | #define SSL3_ST_CR_SRVR_DONE_B (0x161|SSL_ST_CONNECT) | ||
| 370 | /* write to server */ | ||
| 371 | #define SSL3_ST_CW_CERT_A (0x170|SSL_ST_CONNECT) | ||
| 372 | #define SSL3_ST_CW_CERT_B (0x171|SSL_ST_CONNECT) | ||
| 373 | #define SSL3_ST_CW_CERT_C (0x172|SSL_ST_CONNECT) | ||
| 374 | #define SSL3_ST_CW_CERT_D (0x173|SSL_ST_CONNECT) | ||
| 375 | #define SSL3_ST_CW_KEY_EXCH_A (0x180|SSL_ST_CONNECT) | ||
| 376 | #define SSL3_ST_CW_KEY_EXCH_B (0x181|SSL_ST_CONNECT) | ||
| 377 | #define SSL3_ST_CW_CERT_VRFY_A (0x190|SSL_ST_CONNECT) | ||
| 378 | #define SSL3_ST_CW_CERT_VRFY_B (0x191|SSL_ST_CONNECT) | ||
| 379 | #define SSL3_ST_CW_CHANGE_A (0x1A0|SSL_ST_CONNECT) | ||
| 380 | #define SSL3_ST_CW_CHANGE_B (0x1A1|SSL_ST_CONNECT) | ||
| 381 | #define SSL3_ST_CW_FINISHED_A (0x1B0|SSL_ST_CONNECT) | ||
| 382 | #define SSL3_ST_CW_FINISHED_B (0x1B1|SSL_ST_CONNECT) | ||
| 383 | /* read from server */ | ||
| 384 | #define SSL3_ST_CR_CHANGE_A (0x1C0|SSL_ST_CONNECT) | ||
| 385 | #define SSL3_ST_CR_CHANGE_B (0x1C1|SSL_ST_CONNECT) | ||
| 386 | #define SSL3_ST_CR_FINISHED_A (0x1D0|SSL_ST_CONNECT) | ||
| 387 | #define SSL3_ST_CR_FINISHED_B (0x1D1|SSL_ST_CONNECT) | ||
| 388 | |||
| 389 | /* server */ | ||
| 390 | /* extra state */ | ||
| 391 | #define SSL3_ST_SW_FLUSH (0x100|SSL_ST_ACCEPT) | ||
| 392 | /* read from client */ | ||
| 393 | /* Do not change the number values, they do matter */ | ||
| 394 | #define SSL3_ST_SR_CLNT_HELLO_A (0x110|SSL_ST_ACCEPT) | ||
| 395 | #define SSL3_ST_SR_CLNT_HELLO_B (0x111|SSL_ST_ACCEPT) | ||
| 396 | #define SSL3_ST_SR_CLNT_HELLO_C (0x112|SSL_ST_ACCEPT) | ||
| 397 | /* write to client */ | ||
| 398 | #define SSL3_ST_SW_HELLO_REQ_A (0x120|SSL_ST_ACCEPT) | ||
| 399 | #define SSL3_ST_SW_HELLO_REQ_B (0x121|SSL_ST_ACCEPT) | ||
| 400 | #define SSL3_ST_SW_HELLO_REQ_C (0x122|SSL_ST_ACCEPT) | ||
| 401 | #define SSL3_ST_SW_SRVR_HELLO_A (0x130|SSL_ST_ACCEPT) | ||
| 402 | #define SSL3_ST_SW_SRVR_HELLO_B (0x131|SSL_ST_ACCEPT) | ||
| 403 | #define SSL3_ST_SW_CERT_A (0x140|SSL_ST_ACCEPT) | ||
| 404 | #define SSL3_ST_SW_CERT_B (0x141|SSL_ST_ACCEPT) | ||
| 405 | #define SSL3_ST_SW_KEY_EXCH_A (0x150|SSL_ST_ACCEPT) | ||
| 406 | #define SSL3_ST_SW_KEY_EXCH_B (0x151|SSL_ST_ACCEPT) | ||
| 407 | #define SSL3_ST_SW_CERT_REQ_A (0x160|SSL_ST_ACCEPT) | ||
| 408 | #define SSL3_ST_SW_CERT_REQ_B (0x161|SSL_ST_ACCEPT) | ||
| 409 | #define SSL3_ST_SW_SRVR_DONE_A (0x170|SSL_ST_ACCEPT) | ||
| 410 | #define SSL3_ST_SW_SRVR_DONE_B (0x171|SSL_ST_ACCEPT) | ||
| 411 | /* read from client */ | ||
| 412 | #define SSL3_ST_SR_CERT_A (0x180|SSL_ST_ACCEPT) | ||
| 413 | #define SSL3_ST_SR_CERT_B (0x181|SSL_ST_ACCEPT) | ||
| 414 | #define SSL3_ST_SR_KEY_EXCH_A (0x190|SSL_ST_ACCEPT) | ||
| 415 | #define SSL3_ST_SR_KEY_EXCH_B (0x191|SSL_ST_ACCEPT) | ||
| 416 | #define SSL3_ST_SR_CERT_VRFY_A (0x1A0|SSL_ST_ACCEPT) | ||
| 417 | #define SSL3_ST_SR_CERT_VRFY_B (0x1A1|SSL_ST_ACCEPT) | ||
| 418 | #define SSL3_ST_SR_CHANGE_A (0x1B0|SSL_ST_ACCEPT) | ||
| 419 | #define SSL3_ST_SR_CHANGE_B (0x1B1|SSL_ST_ACCEPT) | ||
| 420 | #define SSL3_ST_SR_FINISHED_A (0x1C0|SSL_ST_ACCEPT) | ||
| 421 | #define SSL3_ST_SR_FINISHED_B (0x1C1|SSL_ST_ACCEPT) | ||
| 422 | /* write to client */ | ||
| 423 | #define SSL3_ST_SW_CHANGE_A (0x1D0|SSL_ST_ACCEPT) | ||
| 424 | #define SSL3_ST_SW_CHANGE_B (0x1D1|SSL_ST_ACCEPT) | ||
| 425 | #define SSL3_ST_SW_FINISHED_A (0x1E0|SSL_ST_ACCEPT) | ||
| 426 | #define SSL3_ST_SW_FINISHED_B (0x1E1|SSL_ST_ACCEPT) | ||
| 427 | |||
| 428 | #define SSL3_MT_CLIENT_REQUEST 0 | ||
| 429 | #define SSL3_MT_CLIENT_HELLO 1 | ||
| 430 | #define SSL3_MT_SERVER_HELLO 2 | ||
| 431 | #define SSL3_MT_CERTIFICATE 11 | ||
| 432 | #define SSL3_MT_SERVER_KEY_EXCHANGE 12 | ||
| 433 | #define SSL3_MT_CERTIFICATE_REQUEST 13 | ||
| 434 | #define SSL3_MT_SERVER_DONE 14 | ||
| 435 | #define SSL3_MT_CERTIFICATE_VERIFY 15 | ||
| 436 | #define SSL3_MT_CLIENT_KEY_EXCHANGE 16 | ||
| 437 | #define SSL3_MT_FINISHED 20 | ||
| 438 | |||
| 439 | #define SSL3_MT_CCS 1 | ||
| 440 | |||
| 441 | /* These are used when changing over to a new cipher */ | ||
| 442 | #define SSL3_CC_READ 0x01 | ||
| 443 | #define SSL3_CC_WRITE 0x02 | ||
| 444 | #define SSL3_CC_CLIENT 0x10 | ||
| 445 | #define SSL3_CC_SERVER 0x20 | ||
| 446 | #define SSL3_CHANGE_CIPHER_CLIENT_WRITE (SSL3_CC_CLIENT|SSL3_CC_WRITE) | ||
| 447 | #define SSL3_CHANGE_CIPHER_SERVER_READ (SSL3_CC_SERVER|SSL3_CC_READ) | ||
| 448 | #define SSL3_CHANGE_CIPHER_CLIENT_READ (SSL3_CC_CLIENT|SSL3_CC_READ) | ||
| 449 | #define SSL3_CHANGE_CIPHER_SERVER_WRITE (SSL3_CC_SERVER|SSL3_CC_WRITE) | ||
| 450 | |||
| 451 | #ifdef __cplusplus | ||
| 452 | } | ||
| 453 | #endif | ||
| 454 | #endif | ||
| 455 | |||
diff --git a/src/lib/libssl/ssl_algs.c b/src/lib/libssl/ssl_algs.c new file mode 100644 index 0000000000..65f3a59386 --- /dev/null +++ b/src/lib/libssl/ssl_algs.c | |||
| @@ -0,0 +1,102 @@ | |||
| 1 | /* ssl/ssl_algs.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 "objects.h" | ||
| 61 | #include "lhash.h" | ||
| 62 | #include "ssl_locl.h" | ||
| 63 | |||
| 64 | void SSLeay_add_ssl_algorithms() | ||
| 65 | { | ||
| 66 | #ifndef NO_DES | ||
| 67 | EVP_add_cipher(EVP_des_cbc()); | ||
| 68 | EVP_add_cipher(EVP_des_ede3_cbc()); | ||
| 69 | #endif | ||
| 70 | #ifndef NO_IDEA | ||
| 71 | EVP_add_cipher(EVP_idea_cbc()); | ||
| 72 | #endif | ||
| 73 | #ifndef NO_RC4 | ||
| 74 | EVP_add_cipher(EVP_rc4()); | ||
| 75 | #endif | ||
| 76 | #ifndef NO_RC2 | ||
| 77 | EVP_add_cipher(EVP_rc2_cbc()); | ||
| 78 | #endif | ||
| 79 | |||
| 80 | #ifndef NO_MD2 | ||
| 81 | EVP_add_digest(EVP_md2()); | ||
| 82 | #endif | ||
| 83 | #ifndef NO_MD5 | ||
| 84 | EVP_add_digest(EVP_md5()); | ||
| 85 | EVP_add_alias(SN_md5,"ssl2-md5"); | ||
| 86 | EVP_add_alias(SN_md5,"ssl3-md5"); | ||
| 87 | #endif | ||
| 88 | #ifndef NO_SHA1 | ||
| 89 | EVP_add_digest(EVP_sha1()); /* RSA with sha1 */ | ||
| 90 | EVP_add_alias(SN_sha1,"ssl3-sha1"); | ||
| 91 | #endif | ||
| 92 | #if !defined(NO_SHA1) && !defined(NO_DSA) | ||
| 93 | EVP_add_digest(EVP_dss1()); /* DSA with sha1 */ | ||
| 94 | #endif | ||
| 95 | |||
| 96 | /* If you want support for phased out ciphers, add the following */ | ||
| 97 | #if 0 | ||
| 98 | EVP_add_digest(EVP_sha()); | ||
| 99 | EVP_add_digest(EVP_dss()); | ||
| 100 | #endif | ||
| 101 | } | ||
| 102 | |||
diff --git a/src/lib/libssl/ssl_asn1.c b/src/lib/libssl/ssl_asn1.c new file mode 100644 index 0000000000..116a83de64 --- /dev/null +++ b/src/lib/libssl/ssl_asn1.c | |||
| @@ -0,0 +1,313 @@ | |||
| 1 | /* ssl/ssl_asn1.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 <stdlib.h> | ||
| 61 | #include "asn1_mac.h" | ||
| 62 | #include "objects.h" | ||
| 63 | #include "ssl_locl.h" | ||
| 64 | |||
| 65 | typedef struct ssl_session_asn1_st | ||
| 66 | { | ||
| 67 | ASN1_INTEGER version; | ||
| 68 | ASN1_INTEGER ssl_version; | ||
| 69 | ASN1_OCTET_STRING cipher; | ||
| 70 | ASN1_OCTET_STRING master_key; | ||
| 71 | ASN1_OCTET_STRING session_id; | ||
| 72 | ASN1_OCTET_STRING key_arg; | ||
| 73 | ASN1_INTEGER time; | ||
| 74 | ASN1_INTEGER timeout; | ||
| 75 | } SSL_SESSION_ASN1; | ||
| 76 | |||
| 77 | /* | ||
| 78 | * SSLerr(SSL_F_I2D_SSL_SESSION,SSL_R_CIPHER_CODE_WRONG_LENGTH); | ||
| 79 | * SSLerr(SSL_F_D2I_SSL_SESSION,SSL_R_UNSUPPORTED_CIPHER); | ||
| 80 | */ | ||
| 81 | |||
| 82 | int i2d_SSL_SESSION(in,pp) | ||
| 83 | SSL_SESSION *in; | ||
| 84 | unsigned char **pp; | ||
| 85 | { | ||
| 86 | #define LSIZE2 (sizeof(long)*2) | ||
| 87 | int v1=0,v2=0,v3=0; | ||
| 88 | unsigned char buf[4],ibuf1[LSIZE2],ibuf2[LSIZE2]; | ||
| 89 | unsigned char ibuf3[LSIZE2],ibuf4[LSIZE2]; | ||
| 90 | long l; | ||
| 91 | SSL_SESSION_ASN1 a; | ||
| 92 | M_ASN1_I2D_vars(in); | ||
| 93 | |||
| 94 | if ((in == NULL) || ((in->cipher == NULL) && (in->cipher_id == 0))) | ||
| 95 | return(0); | ||
| 96 | |||
| 97 | /* Note that I cheat in the following 2 assignments. I know | ||
| 98 | * that if the ASN1_INTERGER passed to ASN1_INTEGER_set | ||
| 99 | * is > sizeof(long)+1, the buffer will not be re-Malloc()ed. | ||
| 100 | * This is a bit evil but makes things simple, no dynamic allocation | ||
| 101 | * to clean up :-) */ | ||
| 102 | a.version.length=LSIZE2; | ||
| 103 | a.version.type=V_ASN1_INTEGER; | ||
| 104 | a.version.data=ibuf1; | ||
| 105 | ASN1_INTEGER_set(&(a.version),SSL_SESSION_ASN1_VERSION); | ||
| 106 | |||
| 107 | a.ssl_version.length=LSIZE2; | ||
| 108 | a.ssl_version.type=V_ASN1_INTEGER; | ||
| 109 | a.ssl_version.data=ibuf2; | ||
| 110 | ASN1_INTEGER_set(&(a.ssl_version),in->ssl_version); | ||
| 111 | |||
| 112 | a.cipher.type=V_ASN1_OCTET_STRING; | ||
| 113 | a.cipher.data=buf; | ||
| 114 | |||
| 115 | if (in->cipher == NULL) | ||
| 116 | l=in->cipher_id; | ||
| 117 | else | ||
| 118 | l=in->cipher->id; | ||
| 119 | if (in->ssl_version == SSL2_VERSION) | ||
| 120 | { | ||
| 121 | a.cipher.length=3; | ||
| 122 | buf[0]=((unsigned char)(l>>16L))&0xff; | ||
| 123 | buf[1]=((unsigned char)(l>> 8L))&0xff; | ||
| 124 | buf[2]=((unsigned char)(l ))&0xff; | ||
| 125 | } | ||
| 126 | else | ||
| 127 | { | ||
| 128 | a.cipher.length=2; | ||
| 129 | buf[0]=((unsigned char)(l>>8L))&0xff; | ||
| 130 | buf[1]=((unsigned char)(l ))&0xff; | ||
| 131 | } | ||
| 132 | |||
| 133 | a.master_key.length=in->master_key_length; | ||
| 134 | a.master_key.type=V_ASN1_OCTET_STRING; | ||
| 135 | a.master_key.data=in->master_key; | ||
| 136 | |||
| 137 | a.session_id.length=in->session_id_length; | ||
| 138 | a.session_id.type=V_ASN1_OCTET_STRING; | ||
| 139 | a.session_id.data=in->session_id; | ||
| 140 | |||
| 141 | a.key_arg.length=in->key_arg_length; | ||
| 142 | a.key_arg.type=V_ASN1_OCTET_STRING; | ||
| 143 | a.key_arg.data=in->key_arg; | ||
| 144 | |||
| 145 | if (in->time != 0L) | ||
| 146 | { | ||
| 147 | a.time.length=LSIZE2; | ||
| 148 | a.time.type=V_ASN1_INTEGER; | ||
| 149 | a.time.data=ibuf3; | ||
| 150 | ASN1_INTEGER_set(&(a.time),in->time); | ||
| 151 | } | ||
| 152 | |||
| 153 | if (in->timeout != 0L) | ||
| 154 | { | ||
| 155 | a.timeout.length=LSIZE2; | ||
| 156 | a.timeout.type=V_ASN1_INTEGER; | ||
| 157 | a.timeout.data=ibuf4; | ||
| 158 | ASN1_INTEGER_set(&(a.timeout),in->timeout); | ||
| 159 | } | ||
| 160 | |||
| 161 | M_ASN1_I2D_len(&(a.version), i2d_ASN1_INTEGER); | ||
| 162 | M_ASN1_I2D_len(&(a.ssl_version), i2d_ASN1_INTEGER); | ||
| 163 | M_ASN1_I2D_len(&(a.cipher), i2d_ASN1_OCTET_STRING); | ||
| 164 | M_ASN1_I2D_len(&(a.session_id), i2d_ASN1_OCTET_STRING); | ||
| 165 | M_ASN1_I2D_len(&(a.master_key), i2d_ASN1_OCTET_STRING); | ||
| 166 | if (in->key_arg_length > 0) | ||
| 167 | M_ASN1_I2D_len_IMP_opt(&(a.key_arg),i2d_ASN1_OCTET_STRING); | ||
| 168 | if (in->time != 0L) | ||
| 169 | M_ASN1_I2D_len_EXP_opt(&(a.time),i2d_ASN1_INTEGER,1,v1); | ||
| 170 | if (in->timeout != 0L) | ||
| 171 | M_ASN1_I2D_len_EXP_opt(&(a.timeout),i2d_ASN1_INTEGER,2,v2); | ||
| 172 | if (in->peer != NULL) | ||
| 173 | M_ASN1_I2D_len_EXP_opt(in->peer,i2d_X509,3,v3); | ||
| 174 | |||
| 175 | M_ASN1_I2D_seq_total(); | ||
| 176 | |||
| 177 | M_ASN1_I2D_put(&(a.version), i2d_ASN1_INTEGER); | ||
| 178 | M_ASN1_I2D_put(&(a.ssl_version), i2d_ASN1_INTEGER); | ||
| 179 | M_ASN1_I2D_put(&(a.cipher), i2d_ASN1_OCTET_STRING); | ||
| 180 | M_ASN1_I2D_put(&(a.session_id), i2d_ASN1_OCTET_STRING); | ||
| 181 | M_ASN1_I2D_put(&(a.master_key), i2d_ASN1_OCTET_STRING); | ||
| 182 | if (in->key_arg_length > 0) | ||
| 183 | M_ASN1_I2D_put_IMP_opt(&(a.key_arg),i2d_ASN1_OCTET_STRING,0); | ||
| 184 | if (in->time != 0L) | ||
| 185 | M_ASN1_I2D_put_EXP_opt(&(a.time),i2d_ASN1_INTEGER,1,v1); | ||
| 186 | if (in->timeout != 0L) | ||
| 187 | M_ASN1_I2D_put_EXP_opt(&(a.timeout),i2d_ASN1_INTEGER,2,v2); | ||
| 188 | if (in->peer != NULL) | ||
| 189 | M_ASN1_I2D_put_EXP_opt(in->peer,i2d_X509,3,v3); | ||
| 190 | |||
| 191 | M_ASN1_I2D_finish(); | ||
| 192 | } | ||
| 193 | |||
| 194 | SSL_SESSION *d2i_SSL_SESSION(a,pp,length) | ||
| 195 | SSL_SESSION **a; | ||
| 196 | unsigned char **pp; | ||
| 197 | long length; | ||
| 198 | { | ||
| 199 | int version,ssl_version=0,i; | ||
| 200 | long id; | ||
| 201 | ASN1_INTEGER ai,*aip; | ||
| 202 | ASN1_OCTET_STRING os,*osp; | ||
| 203 | M_ASN1_D2I_vars(a,SSL_SESSION *,SSL_SESSION_new); | ||
| 204 | |||
| 205 | aip= &ai; | ||
| 206 | osp= &os; | ||
| 207 | |||
| 208 | M_ASN1_D2I_Init(); | ||
| 209 | M_ASN1_D2I_start_sequence(); | ||
| 210 | |||
| 211 | ai.data=NULL; ai.length=0; | ||
| 212 | M_ASN1_D2I_get(aip,d2i_ASN1_INTEGER); | ||
| 213 | version=(int)ASN1_INTEGER_get(aip); | ||
| 214 | if (ai.data != NULL) { Free(ai.data); ai.data=NULL; ai.length=0; } | ||
| 215 | |||
| 216 | /* we don't care about the version right now :-) */ | ||
| 217 | M_ASN1_D2I_get(aip,d2i_ASN1_INTEGER); | ||
| 218 | ssl_version=(int)ASN1_INTEGER_get(aip); | ||
| 219 | ret->ssl_version=ssl_version; | ||
| 220 | if (ai.data != NULL) { Free(ai.data); ai.data=NULL; ai.length=0; } | ||
| 221 | |||
| 222 | os.data=NULL; os.length=0; | ||
| 223 | M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING); | ||
| 224 | if (ssl_version == SSL2_VERSION) | ||
| 225 | { | ||
| 226 | if (os.length != 3) | ||
| 227 | { | ||
| 228 | c.error=SSL_R_CIPHER_CODE_WRONG_LENGTH; | ||
| 229 | goto err; | ||
| 230 | } | ||
| 231 | id=0x02000000L| | ||
| 232 | ((unsigned long)os.data[0]<<16L)| | ||
| 233 | ((unsigned long)os.data[1]<< 8L)| | ||
| 234 | (unsigned long)os.data[2]; | ||
| 235 | } | ||
| 236 | else if ((ssl_version>>8) == 3) | ||
| 237 | { | ||
| 238 | if (os.length != 2) | ||
| 239 | { | ||
| 240 | c.error=SSL_R_CIPHER_CODE_WRONG_LENGTH; | ||
| 241 | goto err; | ||
| 242 | } | ||
| 243 | id=0x03000000L| | ||
| 244 | ((unsigned long)os.data[0]<<8L)| | ||
| 245 | (unsigned long)os.data[1]; | ||
| 246 | } | ||
| 247 | else | ||
| 248 | { | ||
| 249 | SSLerr(SSL_F_D2I_SSL_SESSION,SSL_R_UNKNOWN_SSL_VERSION); | ||
| 250 | return(NULL); | ||
| 251 | } | ||
| 252 | |||
| 253 | ret->cipher=NULL; | ||
| 254 | ret->cipher_id=id; | ||
| 255 | |||
| 256 | M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING); | ||
| 257 | if ((ssl_version>>8) == SSL3_VERSION) | ||
| 258 | i=SSL3_MAX_SSL_SESSION_ID_LENGTH; | ||
| 259 | else /* if (ssl_version == SSL2_VERSION) */ | ||
| 260 | i=SSL2_MAX_SSL_SESSION_ID_LENGTH; | ||
| 261 | |||
| 262 | if (os.length > i) | ||
| 263 | os.length=i; | ||
| 264 | |||
| 265 | ret->session_id_length=os.length; | ||
| 266 | memcpy(ret->session_id,os.data,os.length); | ||
| 267 | |||
| 268 | M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING); | ||
| 269 | if (ret->master_key_length > SSL_MAX_MASTER_KEY_LENGTH) | ||
| 270 | ret->master_key_length=SSL_MAX_MASTER_KEY_LENGTH; | ||
| 271 | else | ||
| 272 | ret->master_key_length=os.length; | ||
| 273 | memcpy(ret->master_key,os.data,ret->master_key_length); | ||
| 274 | |||
| 275 | os.length=0; | ||
| 276 | M_ASN1_D2I_get_IMP_opt(osp,d2i_ASN1_OCTET_STRING,0,V_ASN1_OCTET_STRING); | ||
| 277 | if (os.length > SSL_MAX_KEY_ARG_LENGTH) | ||
| 278 | ret->key_arg_length=SSL_MAX_KEY_ARG_LENGTH; | ||
| 279 | else | ||
| 280 | ret->key_arg_length=os.length; | ||
| 281 | memcpy(ret->key_arg,os.data,ret->key_arg_length); | ||
| 282 | if (os.data != NULL) Free(os.data); | ||
| 283 | |||
| 284 | ai.length=0; | ||
| 285 | M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,1); | ||
| 286 | if (ai.data != NULL) | ||
| 287 | { | ||
| 288 | ret->time=ASN1_INTEGER_get(aip); | ||
| 289 | Free(ai.data); ai.data=NULL; ai.length=0; | ||
| 290 | } | ||
| 291 | else | ||
| 292 | ret->time=time(NULL); | ||
| 293 | |||
| 294 | ai.length=0; | ||
| 295 | M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,2); | ||
| 296 | if (ai.data != NULL) | ||
| 297 | { | ||
| 298 | ret->timeout=ASN1_INTEGER_get(aip); | ||
| 299 | Free(ai.data); ai.data=NULL; ai.length=0; | ||
| 300 | } | ||
| 301 | else | ||
| 302 | ret->timeout=3; | ||
| 303 | |||
| 304 | if (ret->peer != NULL) | ||
| 305 | { | ||
| 306 | X509_free(ret->peer); | ||
| 307 | ret->peer=NULL; | ||
| 308 | } | ||
| 309 | M_ASN1_D2I_get_EXP_opt(ret->peer,d2i_X509,3); | ||
| 310 | |||
| 311 | M_ASN1_D2I_Finish(a,SSL_SESSION_free,SSL_F_D2I_SSL_SESSION); | ||
| 312 | } | ||
| 313 | |||
diff --git a/src/lib/libssl/ssl_cert.c b/src/lib/libssl/ssl_cert.c new file mode 100644 index 0000000000..c1cb86e1b7 --- /dev/null +++ b/src/lib/libssl/ssl_cert.c | |||
| @@ -0,0 +1,329 @@ | |||
| 1 | /* ssl/ssl_cert.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 "objects.h" | ||
| 61 | #include "bio.h" | ||
| 62 | #include "pem.h" | ||
| 63 | #include "ssl_locl.h" | ||
| 64 | |||
| 65 | CERT *ssl_cert_new() | ||
| 66 | { | ||
| 67 | CERT *ret; | ||
| 68 | |||
| 69 | ret=(CERT *)Malloc(sizeof(CERT)); | ||
| 70 | if (ret == NULL) | ||
| 71 | { | ||
| 72 | SSLerr(SSL_F_SSL_CERT_NEW,ERR_R_MALLOC_FAILURE); | ||
| 73 | return(NULL); | ||
| 74 | } | ||
| 75 | memset(ret,0,sizeof(CERT)); | ||
| 76 | /* | ||
| 77 | ret->valid=0; | ||
| 78 | ret->mask=0; | ||
| 79 | ret->export_mask=0; | ||
| 80 | ret->cert_type=0; | ||
| 81 | ret->key->x509=NULL; | ||
| 82 | ret->key->publickey=NULL; | ||
| 83 | ret->key->privatekey=NULL; */ | ||
| 84 | |||
| 85 | ret->key= &(ret->pkeys[SSL_PKEY_RSA_ENC]); | ||
| 86 | ret->references=1; | ||
| 87 | |||
| 88 | return(ret); | ||
| 89 | } | ||
| 90 | |||
| 91 | void ssl_cert_free(c) | ||
| 92 | CERT *c; | ||
| 93 | { | ||
| 94 | int i; | ||
| 95 | |||
| 96 | i=CRYPTO_add(&c->references,-1,CRYPTO_LOCK_SSL_CERT); | ||
| 97 | #ifdef REF_PRINT | ||
| 98 | REF_PRINT("CERT",c); | ||
| 99 | #endif | ||
| 100 | if (i > 0) return; | ||
| 101 | #ifdef REF_CHECK | ||
| 102 | if (i < 0) | ||
| 103 | { | ||
| 104 | fprintf(stderr,"ssl_cert_free, bad reference count\n"); | ||
| 105 | abort(); /* ok */ | ||
| 106 | } | ||
| 107 | #endif | ||
| 108 | |||
| 109 | #ifndef NO_RSA | ||
| 110 | if (c->rsa_tmp) RSA_free(c->rsa_tmp); | ||
| 111 | #endif | ||
| 112 | #ifndef NO_DH | ||
| 113 | if (c->dh_tmp) DH_free(c->dh_tmp); | ||
| 114 | #endif | ||
| 115 | |||
| 116 | for (i=0; i<SSL_PKEY_NUM; i++) | ||
| 117 | { | ||
| 118 | if (c->pkeys[i].x509 != NULL) | ||
| 119 | X509_free(c->pkeys[i].x509); | ||
| 120 | if (c->pkeys[i].privatekey != NULL) | ||
| 121 | EVP_PKEY_free(c->pkeys[i].privatekey); | ||
| 122 | #if 0 | ||
| 123 | if (c->pkeys[i].publickey != NULL) | ||
| 124 | EVP_PKEY_free(c->pkeys[i].publickey); | ||
| 125 | #endif | ||
| 126 | } | ||
| 127 | if (c->cert_chain != NULL) | ||
| 128 | sk_pop_free(c->cert_chain,X509_free); | ||
| 129 | Free(c); | ||
| 130 | } | ||
| 131 | |||
| 132 | int ssl_set_cert_type(c, type) | ||
| 133 | CERT *c; | ||
| 134 | int type; | ||
| 135 | { | ||
| 136 | c->cert_type=type; | ||
| 137 | return(1); | ||
| 138 | } | ||
| 139 | |||
| 140 | int ssl_verify_cert_chain(s,sk) | ||
| 141 | SSL *s; | ||
| 142 | STACK *sk; | ||
| 143 | { | ||
| 144 | X509 *x; | ||
| 145 | int i; | ||
| 146 | X509_STORE_CTX ctx; | ||
| 147 | |||
| 148 | if ((sk == NULL) || (sk_num(sk) == 0)) | ||
| 149 | return(0); | ||
| 150 | |||
| 151 | x=(X509 *)sk_value(sk,0); | ||
| 152 | X509_STORE_CTX_init(&ctx,s->ctx->cert_store,x,sk); | ||
| 153 | X509_STORE_CTX_set_app_data(&ctx,(char *)s); | ||
| 154 | |||
| 155 | if (s->ctx->app_verify_callback != NULL) | ||
| 156 | i=s->ctx->app_verify_callback(&ctx); | ||
| 157 | else | ||
| 158 | i=X509_verify_cert(&ctx); | ||
| 159 | |||
| 160 | X509_STORE_CTX_cleanup(&ctx); | ||
| 161 | s->verify_result=ctx.error; | ||
| 162 | |||
| 163 | return(i); | ||
| 164 | } | ||
| 165 | |||
| 166 | static void set_client_CA_list(ca_list,list) | ||
| 167 | STACK **ca_list; | ||
| 168 | STACK *list; | ||
| 169 | { | ||
| 170 | if (*ca_list != NULL) | ||
| 171 | sk_pop_free(*ca_list,X509_NAME_free); | ||
| 172 | |||
| 173 | *ca_list=list; | ||
| 174 | } | ||
| 175 | |||
| 176 | STACK *SSL_dup_CA_list(sk) | ||
| 177 | STACK *sk; | ||
| 178 | { | ||
| 179 | int i; | ||
| 180 | STACK *ret; | ||
| 181 | X509_NAME *name; | ||
| 182 | |||
| 183 | ret=sk_new_null(); | ||
| 184 | for (i=0; i<sk_num(sk); i++) | ||
| 185 | { | ||
| 186 | name=X509_NAME_dup((X509_NAME *)sk_value(sk,i)); | ||
| 187 | if ((name == NULL) || !sk_push(ret,(char *)name)) | ||
| 188 | { | ||
| 189 | sk_pop_free(ret,X509_NAME_free); | ||
| 190 | return(NULL); | ||
| 191 | } | ||
| 192 | } | ||
| 193 | return(ret); | ||
| 194 | } | ||
| 195 | |||
| 196 | void SSL_set_client_CA_list(s,list) | ||
| 197 | SSL *s; | ||
| 198 | STACK *list; | ||
| 199 | { | ||
| 200 | set_client_CA_list(&(s->client_CA),list); | ||
| 201 | } | ||
| 202 | |||
| 203 | void SSL_CTX_set_client_CA_list(ctx,list) | ||
| 204 | SSL_CTX *ctx; | ||
| 205 | STACK *list; | ||
| 206 | { | ||
| 207 | set_client_CA_list(&(ctx->client_CA),list); | ||
| 208 | } | ||
| 209 | |||
| 210 | STACK *SSL_CTX_get_client_CA_list(ctx) | ||
| 211 | SSL_CTX *ctx; | ||
| 212 | { | ||
| 213 | return(ctx->client_CA); | ||
| 214 | } | ||
| 215 | |||
| 216 | STACK *SSL_get_client_CA_list(s) | ||
| 217 | SSL *s; | ||
| 218 | { | ||
| 219 | if (s->type == SSL_ST_CONNECT) | ||
| 220 | { /* we are in the client */ | ||
| 221 | if (((s->version>>8) == SSL3_VERSION_MAJOR) && | ||
| 222 | (s->s3 != NULL)) | ||
| 223 | return(s->s3->tmp.ca_names); | ||
| 224 | else | ||
| 225 | return(NULL); | ||
| 226 | } | ||
| 227 | else | ||
| 228 | { | ||
| 229 | if (s->client_CA != NULL) | ||
| 230 | return(s->client_CA); | ||
| 231 | else | ||
| 232 | return(s->ctx->client_CA); | ||
| 233 | } | ||
| 234 | } | ||
| 235 | |||
| 236 | static int add_client_CA(sk,x) | ||
| 237 | STACK **sk; | ||
| 238 | X509 *x; | ||
| 239 | { | ||
| 240 | X509_NAME *name; | ||
| 241 | |||
| 242 | if (x == NULL) return(0); | ||
| 243 | if ((*sk == NULL) && ((*sk=sk_new_null()) == NULL)) | ||
| 244 | return(0); | ||
| 245 | |||
| 246 | if ((name=X509_NAME_dup(X509_get_subject_name(x))) == NULL) | ||
| 247 | return(0); | ||
| 248 | |||
| 249 | if (!sk_push(*sk,(char *)name)) | ||
| 250 | { | ||
| 251 | X509_NAME_free(name); | ||
| 252 | return(0); | ||
| 253 | } | ||
| 254 | return(1); | ||
| 255 | } | ||
| 256 | |||
| 257 | int SSL_add_client_CA(ssl,x) | ||
| 258 | SSL *ssl; | ||
| 259 | X509 *x; | ||
| 260 | { | ||
| 261 | return(add_client_CA(&(ssl->client_CA),x)); | ||
| 262 | } | ||
| 263 | |||
| 264 | int SSL_CTX_add_client_CA(ctx,x) | ||
| 265 | SSL_CTX *ctx; | ||
| 266 | X509 *x; | ||
| 267 | { | ||
| 268 | return(add_client_CA(&(ctx->client_CA),x)); | ||
| 269 | } | ||
| 270 | |||
| 271 | static int name_cmp(a,b) | ||
| 272 | X509_NAME **a,**b; | ||
| 273 | { | ||
| 274 | return(X509_NAME_cmp(*a,*b)); | ||
| 275 | } | ||
| 276 | |||
| 277 | #ifndef NO_STDIO | ||
| 278 | STACK *SSL_load_client_CA_file(file) | ||
| 279 | char *file; | ||
| 280 | { | ||
| 281 | BIO *in; | ||
| 282 | X509 *x=NULL; | ||
| 283 | X509_NAME *xn=NULL; | ||
| 284 | STACK *ret,*sk; | ||
| 285 | |||
| 286 | ret=sk_new(NULL); | ||
| 287 | sk=sk_new(name_cmp); | ||
| 288 | |||
| 289 | in=BIO_new(BIO_s_file_internal()); | ||
| 290 | |||
| 291 | if ((ret == NULL) || (sk == NULL) || (in == NULL)) | ||
| 292 | { | ||
| 293 | SSLerr(SSL_F_SSL_LOAD_CLIENT_CA_FILE,ERR_R_MALLOC_FAILURE); | ||
| 294 | goto err; | ||
| 295 | } | ||
| 296 | |||
| 297 | if (!BIO_read_filename(in,file)) | ||
| 298 | goto err; | ||
| 299 | |||
| 300 | for (;;) | ||
| 301 | { | ||
| 302 | if (PEM_read_bio_X509(in,&x,NULL) == NULL) | ||
| 303 | break; | ||
| 304 | if ((xn=X509_get_subject_name(x)) == NULL) goto err; | ||
| 305 | /* check for duplicates */ | ||
| 306 | xn=X509_NAME_dup(xn); | ||
| 307 | if (xn == NULL) goto err; | ||
| 308 | if (sk_find(sk,(char *)xn) >= 0) | ||
| 309 | X509_NAME_free(xn); | ||
| 310 | else | ||
| 311 | { | ||
| 312 | sk_push(sk,(char *)xn); | ||
| 313 | sk_push(ret,(char *)xn); | ||
| 314 | } | ||
| 315 | } | ||
| 316 | |||
| 317 | if (0) | ||
| 318 | { | ||
| 319 | err: | ||
| 320 | if (ret != NULL) sk_pop_free(ret,X509_NAME_free); | ||
| 321 | ret=NULL; | ||
| 322 | } | ||
| 323 | if (sk != NULL) sk_free(sk); | ||
| 324 | if (in != NULL) BIO_free(in); | ||
| 325 | if (x != NULL) X509_free(x); | ||
| 326 | return(ret); | ||
| 327 | } | ||
| 328 | #endif | ||
| 329 | |||
diff --git a/src/lib/libssl/ssl_ciph.c b/src/lib/libssl/ssl_ciph.c new file mode 100644 index 0000000000..820994408b --- /dev/null +++ b/src/lib/libssl/ssl_ciph.c | |||
| @@ -0,0 +1,758 @@ | |||
| 1 | /* ssl/ssl_ciph.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 "objects.h" | ||
| 61 | #include "ssl_locl.h" | ||
| 62 | |||
| 63 | #define SSL_ENC_DES_IDX 0 | ||
| 64 | #define SSL_ENC_3DES_IDX 1 | ||
| 65 | #define SSL_ENC_RC4_IDX 2 | ||
| 66 | #define SSL_ENC_RC2_IDX 3 | ||
| 67 | #define SSL_ENC_IDEA_IDX 4 | ||
| 68 | #define SSL_ENC_eFZA_IDX 5 | ||
| 69 | #define SSL_ENC_NULL_IDX 6 | ||
| 70 | #define SSL_ENC_NUM_IDX 7 | ||
| 71 | |||
| 72 | static EVP_CIPHER *ssl_cipher_methods[SSL_ENC_NUM_IDX]={ | ||
| 73 | NULL,NULL,NULL,NULL,NULL,NULL, | ||
| 74 | }; | ||
| 75 | |||
| 76 | #define SSL_MD_MD5_IDX 0 | ||
| 77 | #define SSL_MD_SHA1_IDX 1 | ||
| 78 | #define SSL_MD_NUM_IDX 2 | ||
| 79 | static EVP_MD *ssl_digest_methods[SSL_MD_NUM_IDX]={ | ||
| 80 | NULL,NULL, | ||
| 81 | }; | ||
| 82 | |||
| 83 | typedef struct cipher_sort_st | ||
| 84 | { | ||
| 85 | SSL_CIPHER *cipher; | ||
| 86 | int pref; | ||
| 87 | } CIPHER_SORT; | ||
| 88 | |||
| 89 | #define CIPHER_ADD 1 | ||
| 90 | #define CIPHER_KILL 2 | ||
| 91 | #define CIPHER_DEL 3 | ||
| 92 | #define CIPHER_ORD 4 | ||
| 93 | |||
| 94 | typedef struct cipher_choice_st | ||
| 95 | { | ||
| 96 | int type; | ||
| 97 | unsigned long algorithms; | ||
| 98 | unsigned long mask; | ||
| 99 | long top; | ||
| 100 | } CIPHER_CHOICE; | ||
| 101 | |||
| 102 | typedef struct cipher_order_st | ||
| 103 | { | ||
| 104 | SSL_CIPHER *cipher; | ||
| 105 | int active; | ||
| 106 | int dead; | ||
| 107 | struct cipher_order_st *next,*prev; | ||
| 108 | } CIPHER_ORDER; | ||
| 109 | |||
| 110 | static SSL_CIPHER cipher_aliases[]={ | ||
| 111 | {0,SSL_TXT_ALL, 0,SSL_ALL, 0,SSL_ALL}, /* must be first */ | ||
| 112 | {0,SSL_TXT_kRSA,0,SSL_kRSA, 0,SSL_MKEY_MASK}, | ||
| 113 | {0,SSL_TXT_kDHr,0,SSL_kDHr, 0,SSL_MKEY_MASK}, | ||
| 114 | {0,SSL_TXT_kDHd,0,SSL_kDHd, 0,SSL_MKEY_MASK}, | ||
| 115 | {0,SSL_TXT_kEDH,0,SSL_kEDH, 0,SSL_MKEY_MASK}, | ||
| 116 | {0,SSL_TXT_kFZA,0,SSL_kFZA, 0,SSL_MKEY_MASK}, | ||
| 117 | {0,SSL_TXT_DH, 0,SSL_DH, 0,SSL_MKEY_MASK}, | ||
| 118 | {0,SSL_TXT_EDH, 0,SSL_EDH, 0,SSL_MKEY_MASK|SSL_AUTH_MASK}, | ||
| 119 | |||
| 120 | {0,SSL_TXT_aRSA,0,SSL_aRSA, 0,SSL_AUTH_MASK}, | ||
| 121 | {0,SSL_TXT_aDSS,0,SSL_aDSS, 0,SSL_AUTH_MASK}, | ||
| 122 | {0,SSL_TXT_aFZA,0,SSL_aFZA, 0,SSL_AUTH_MASK}, | ||
| 123 | {0,SSL_TXT_aNULL,0,SSL_aNULL,0,SSL_AUTH_MASK}, | ||
| 124 | {0,SSL_TXT_aDH, 0,SSL_aDH, 0,SSL_AUTH_MASK}, | ||
| 125 | {0,SSL_TXT_DSS, 0,SSL_DSS, 0,SSL_AUTH_MASK}, | ||
| 126 | |||
| 127 | {0,SSL_TXT_DES, 0,SSL_DES, 0,SSL_ENC_MASK}, | ||
| 128 | {0,SSL_TXT_3DES,0,SSL_3DES, 0,SSL_ENC_MASK}, | ||
| 129 | {0,SSL_TXT_RC4, 0,SSL_RC4, 0,SSL_ENC_MASK}, | ||
| 130 | {0,SSL_TXT_RC2, 0,SSL_RC2, 0,SSL_ENC_MASK}, | ||
| 131 | {0,SSL_TXT_IDEA,0,SSL_IDEA, 0,SSL_ENC_MASK}, | ||
| 132 | {0,SSL_TXT_eNULL,0,SSL_eNULL,0,SSL_ENC_MASK}, | ||
| 133 | {0,SSL_TXT_eFZA,0,SSL_eFZA, 0,SSL_ENC_MASK}, | ||
| 134 | |||
| 135 | {0,SSL_TXT_MD5, 0,SSL_MD5, 0,SSL_MAC_MASK}, | ||
| 136 | {0,SSL_TXT_SHA1,0,SSL_SHA1, 0,SSL_MAC_MASK}, | ||
| 137 | {0,SSL_TXT_SHA, 0,SSL_SHA, 0,SSL_MAC_MASK}, | ||
| 138 | |||
| 139 | {0,SSL_TXT_NULL,0,SSL_NULL, 0,SSL_ENC_MASK}, | ||
| 140 | {0,SSL_TXT_RSA, 0,SSL_RSA, 0,SSL_AUTH_MASK|SSL_MKEY_MASK}, | ||
| 141 | {0,SSL_TXT_ADH, 0,SSL_ADH, 0,SSL_AUTH_MASK|SSL_MKEY_MASK}, | ||
| 142 | {0,SSL_TXT_FZA, 0,SSL_FZA, 0,SSL_AUTH_MASK|SSL_MKEY_MASK|SSL_ENC_MASK}, | ||
| 143 | |||
| 144 | {0,SSL_TXT_EXP, 0,SSL_EXP, 0,SSL_EXP_MASK}, | ||
| 145 | {0,SSL_TXT_EXPORT,0,SSL_EXPORT,0,SSL_EXP_MASK}, | ||
| 146 | {0,SSL_TXT_SSLV2,0,SSL_SSLV2,0,SSL_SSL_MASK}, | ||
| 147 | {0,SSL_TXT_SSLV3,0,SSL_SSLV3,0,SSL_SSL_MASK}, | ||
| 148 | {0,SSL_TXT_LOW, 0,SSL_LOW,0,SSL_STRONG_MASK}, | ||
| 149 | {0,SSL_TXT_MEDIUM,0,SSL_MEDIUM,0,SSL_STRONG_MASK}, | ||
| 150 | {0,SSL_TXT_HIGH, 0,SSL_HIGH,0,SSL_STRONG_MASK}, | ||
| 151 | }; | ||
| 152 | |||
| 153 | static int init_ciphers=1; | ||
| 154 | static void load_ciphers(); | ||
| 155 | |||
| 156 | static int cmp_by_name(a,b) | ||
| 157 | SSL_CIPHER **a,**b; | ||
| 158 | { | ||
| 159 | return(strcmp((*a)->name,(*b)->name)); | ||
| 160 | } | ||
| 161 | |||
| 162 | static void load_ciphers() | ||
| 163 | { | ||
| 164 | init_ciphers=0; | ||
| 165 | ssl_cipher_methods[SSL_ENC_DES_IDX]= | ||
| 166 | EVP_get_cipherbyname(SN_des_cbc); | ||
| 167 | ssl_cipher_methods[SSL_ENC_3DES_IDX]= | ||
| 168 | EVP_get_cipherbyname(SN_des_ede3_cbc); | ||
| 169 | ssl_cipher_methods[SSL_ENC_RC4_IDX]= | ||
| 170 | EVP_get_cipherbyname(SN_rc4); | ||
| 171 | ssl_cipher_methods[SSL_ENC_RC2_IDX]= | ||
| 172 | EVP_get_cipherbyname(SN_rc2_cbc); | ||
| 173 | ssl_cipher_methods[SSL_ENC_IDEA_IDX]= | ||
| 174 | EVP_get_cipherbyname(SN_idea_cbc); | ||
| 175 | |||
| 176 | ssl_digest_methods[SSL_MD_MD5_IDX]= | ||
| 177 | EVP_get_digestbyname(SN_md5); | ||
| 178 | ssl_digest_methods[SSL_MD_SHA1_IDX]= | ||
| 179 | EVP_get_digestbyname(SN_sha1); | ||
| 180 | } | ||
| 181 | |||
| 182 | int ssl_cipher_get_evp(c,enc,md) | ||
| 183 | SSL_CIPHER *c; | ||
| 184 | EVP_CIPHER **enc; | ||
| 185 | EVP_MD **md; | ||
| 186 | { | ||
| 187 | int i; | ||
| 188 | |||
| 189 | if (c == NULL) return(0); | ||
| 190 | |||
| 191 | switch (c->algorithms & SSL_ENC_MASK) | ||
| 192 | { | ||
| 193 | case SSL_DES: | ||
| 194 | i=SSL_ENC_DES_IDX; | ||
| 195 | break; | ||
| 196 | case SSL_3DES: | ||
| 197 | i=SSL_ENC_3DES_IDX; | ||
| 198 | break; | ||
| 199 | case SSL_RC4: | ||
| 200 | i=SSL_ENC_RC4_IDX; | ||
| 201 | break; | ||
| 202 | case SSL_RC2: | ||
| 203 | i=SSL_ENC_RC2_IDX; | ||
| 204 | break; | ||
| 205 | case SSL_IDEA: | ||
| 206 | i=SSL_ENC_IDEA_IDX; | ||
| 207 | break; | ||
| 208 | case SSL_eNULL: | ||
| 209 | i=SSL_ENC_NULL_IDX; | ||
| 210 | break; | ||
| 211 | break; | ||
| 212 | default: | ||
| 213 | i= -1; | ||
| 214 | break; | ||
| 215 | } | ||
| 216 | |||
| 217 | if ((i < 0) || (i > SSL_ENC_NUM_IDX)) | ||
| 218 | *enc=NULL; | ||
| 219 | else | ||
| 220 | { | ||
| 221 | if (i == SSL_ENC_NULL_IDX) | ||
| 222 | *enc=EVP_enc_null(); | ||
| 223 | else | ||
| 224 | *enc=ssl_cipher_methods[i]; | ||
| 225 | } | ||
| 226 | |||
| 227 | switch (c->algorithms & SSL_MAC_MASK) | ||
| 228 | { | ||
| 229 | case SSL_MD5: | ||
| 230 | i=SSL_MD_MD5_IDX; | ||
| 231 | break; | ||
| 232 | case SSL_SHA1: | ||
| 233 | i=SSL_MD_SHA1_IDX; | ||
| 234 | break; | ||
| 235 | default: | ||
| 236 | i= -1; | ||
| 237 | break; | ||
| 238 | } | ||
| 239 | if ((i < 0) || (i > SSL_MD_NUM_IDX)) | ||
| 240 | *md=NULL; | ||
| 241 | else | ||
| 242 | *md=ssl_digest_methods[i]; | ||
| 243 | |||
| 244 | if ((*enc != NULL) && (*md != NULL)) | ||
| 245 | return(1); | ||
| 246 | else | ||
| 247 | return(0); | ||
| 248 | } | ||
| 249 | |||
| 250 | #define ITEM_SEP(a) \ | ||
| 251 | (((a) == ':') || ((a) == ' ') || ((a) == ';') || ((a) == ',')) | ||
| 252 | |||
| 253 | static void ll_append_tail(head,curr,tail) | ||
| 254 | CIPHER_ORDER **head,*curr,**tail; | ||
| 255 | { | ||
| 256 | if (curr == *tail) return; | ||
| 257 | if (curr == *head) | ||
| 258 | *head=curr->next; | ||
| 259 | if (curr->prev != NULL) | ||
| 260 | curr->prev->next=curr->next; | ||
| 261 | if (curr->next != NULL) /* should always be true */ | ||
| 262 | curr->next->prev=curr->prev; | ||
| 263 | (*tail)->next=curr; | ||
| 264 | curr->prev= *tail; | ||
| 265 | curr->next=NULL; | ||
| 266 | *tail=curr; | ||
| 267 | } | ||
| 268 | |||
| 269 | STACK *ssl_create_cipher_list(ssl_method,cipher_list,cipher_list_by_id,str) | ||
| 270 | SSL_METHOD *ssl_method; | ||
| 271 | STACK **cipher_list,**cipher_list_by_id; | ||
| 272 | char *str; | ||
| 273 | { | ||
| 274 | SSL_CIPHER *c; | ||
| 275 | char *l; | ||
| 276 | STACK *ret=NULL,*ok=NULL; | ||
| 277 | #define CL_BUF 40 | ||
| 278 | char buf[CL_BUF]; | ||
| 279 | char *tmp_str=NULL; | ||
| 280 | unsigned long mask,algorithms,ma; | ||
| 281 | char *start; | ||
| 282 | int i,j,k,num=0,ch,multi; | ||
| 283 | unsigned long al; | ||
| 284 | STACK *ca_list=NULL; | ||
| 285 | int current_x,num_x; | ||
| 286 | CIPHER_CHOICE *ops=NULL; | ||
| 287 | CIPHER_ORDER *list=NULL,*head=NULL,*tail=NULL,*curr,*tail2,*curr2; | ||
| 288 | int list_num; | ||
| 289 | int type; | ||
| 290 | SSL_CIPHER c_tmp,*cp; | ||
| 291 | |||
| 292 | if (str == NULL) return(NULL); | ||
| 293 | |||
| 294 | if (strncmp(str,"DEFAULT",7) == 0) | ||
| 295 | { | ||
| 296 | i=strlen(str)+2+strlen(SSL_DEFAULT_CIPHER_LIST); | ||
| 297 | if ((tmp_str=Malloc(i)) == NULL) | ||
| 298 | { | ||
| 299 | SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST,ERR_R_MALLOC_FAILURE); | ||
| 300 | goto err; | ||
| 301 | } | ||
| 302 | strcpy(tmp_str,SSL_DEFAULT_CIPHER_LIST); | ||
| 303 | strcat(tmp_str,":"); | ||
| 304 | strcat(tmp_str,&(str[7])); | ||
| 305 | str=tmp_str; | ||
| 306 | } | ||
| 307 | if (init_ciphers) load_ciphers(); | ||
| 308 | |||
| 309 | num=ssl_method->num_ciphers(); | ||
| 310 | |||
| 311 | if ((ret=(STACK *)sk_new(NULL)) == NULL) goto err; | ||
| 312 | if ((ca_list=(STACK *)sk_new(cmp_by_name)) == NULL) goto err; | ||
| 313 | |||
| 314 | mask =SSL_kFZA; | ||
| 315 | #ifdef NO_RSA | ||
| 316 | mask|=SSL_aRSA|SSL_kRSA; | ||
| 317 | #endif | ||
| 318 | #ifdef NO_DSA | ||
| 319 | mask|=SSL_aDSS; | ||
| 320 | #endif | ||
| 321 | #ifdef NO_DH | ||
| 322 | mask|=SSL_kDHr|SSL_kDHd|SSL_kEDH|SSL_aDH; | ||
| 323 | #endif | ||
| 324 | |||
| 325 | #ifndef SSL_ALLOW_ENULL | ||
| 326 | mask|=SSL_eNULL; | ||
| 327 | #endif | ||
| 328 | |||
| 329 | mask|=(ssl_cipher_methods[SSL_ENC_DES_IDX ] == NULL)?SSL_DES :0; | ||
| 330 | mask|=(ssl_cipher_methods[SSL_ENC_3DES_IDX] == NULL)?SSL_3DES:0; | ||
| 331 | mask|=(ssl_cipher_methods[SSL_ENC_RC4_IDX ] == NULL)?SSL_RC4 :0; | ||
| 332 | mask|=(ssl_cipher_methods[SSL_ENC_RC2_IDX ] == NULL)?SSL_RC2 :0; | ||
| 333 | mask|=(ssl_cipher_methods[SSL_ENC_IDEA_IDX] == NULL)?SSL_IDEA:0; | ||
| 334 | mask|=(ssl_cipher_methods[SSL_ENC_eFZA_IDX] == NULL)?SSL_eFZA:0; | ||
| 335 | |||
| 336 | mask|=(ssl_digest_methods[SSL_MD_MD5_IDX ] == NULL)?SSL_MD5 :0; | ||
| 337 | mask|=(ssl_digest_methods[SSL_MD_SHA1_IDX] == NULL)?SSL_SHA1:0; | ||
| 338 | |||
| 339 | if ((list=(CIPHER_ORDER *)Malloc(sizeof(CIPHER_ORDER)*num)) == NULL) | ||
| 340 | goto err; | ||
| 341 | |||
| 342 | /* Get the initial list of ciphers */ | ||
| 343 | list_num=0; | ||
| 344 | for (i=0; i<num; i++) | ||
| 345 | { | ||
| 346 | c=ssl_method->get_cipher((unsigned int)i); | ||
| 347 | /* drop those that use any of that is not available */ | ||
| 348 | if ((c != NULL) && c->valid && !(c->algorithms & mask)) | ||
| 349 | { | ||
| 350 | list[list_num].cipher=c; | ||
| 351 | list[list_num].next=NULL; | ||
| 352 | list[list_num].prev=NULL; | ||
| 353 | list[list_num].active=0; | ||
| 354 | list_num++; | ||
| 355 | if (!sk_push(ca_list,(char *)c)) goto err; | ||
| 356 | } | ||
| 357 | } | ||
| 358 | |||
| 359 | for (i=1; i<list_num-1; i++) | ||
| 360 | { | ||
| 361 | list[i].prev= &(list[i-1]); | ||
| 362 | list[i].next= &(list[i+1]); | ||
| 363 | } | ||
| 364 | if (list_num > 0) | ||
| 365 | { | ||
| 366 | head= &(list[0]); | ||
| 367 | head->prev=NULL; | ||
| 368 | head->next= &(list[1]); | ||
| 369 | tail= &(list[list_num-1]); | ||
| 370 | tail->prev= &(list[list_num-2]); | ||
| 371 | tail->next=NULL; | ||
| 372 | } | ||
| 373 | |||
| 374 | /* special case */ | ||
| 375 | cipher_aliases[0].algorithms= ~mask; | ||
| 376 | |||
| 377 | /* get the aliases */ | ||
| 378 | k=sizeof(cipher_aliases)/sizeof(SSL_CIPHER); | ||
| 379 | for (j=0; j<k; j++) | ||
| 380 | { | ||
| 381 | al=cipher_aliases[j].algorithms; | ||
| 382 | /* Drop those that are not relevent */ | ||
| 383 | if ((al & mask) == al) continue; | ||
| 384 | if (!sk_push(ca_list,(char *)&(cipher_aliases[j]))) goto err; | ||
| 385 | } | ||
| 386 | |||
| 387 | /* ca_list now holds a 'stack' of SSL_CIPHERS, some real, some | ||
| 388 | * 'aliases' */ | ||
| 389 | |||
| 390 | /* how many parameters are there? */ | ||
| 391 | num=1; | ||
| 392 | for (l=str; *l; l++) | ||
| 393 | if (ITEM_SEP(*l)) | ||
| 394 | num++; | ||
| 395 | ops=(CIPHER_CHOICE *)Malloc(sizeof(CIPHER_CHOICE)*num); | ||
| 396 | if (ops == NULL) goto err; | ||
| 397 | memset(ops,0,sizeof(CIPHER_CHOICE)*num); | ||
| 398 | |||
| 399 | /* we now parse the input string and create our operations */ | ||
| 400 | l=str; | ||
| 401 | i=0; | ||
| 402 | current_x=0; | ||
| 403 | |||
| 404 | for (;;) | ||
| 405 | { | ||
| 406 | ch= *l; | ||
| 407 | |||
| 408 | if (ch == '\0') break; | ||
| 409 | |||
| 410 | if (ch == '-') | ||
| 411 | { j=CIPHER_DEL; l++; } | ||
| 412 | else if (ch == '+') | ||
| 413 | { j=CIPHER_ORD; l++; } | ||
| 414 | else if (ch == '!') | ||
| 415 | { j=CIPHER_KILL; l++; } | ||
| 416 | else | ||
| 417 | { j=CIPHER_ADD; } | ||
| 418 | |||
| 419 | if (ITEM_SEP(ch)) | ||
| 420 | { | ||
| 421 | l++; | ||
| 422 | continue; | ||
| 423 | } | ||
| 424 | ops[current_x].type=j; | ||
| 425 | ops[current_x].algorithms=0; | ||
| 426 | ops[current_x].mask=0; | ||
| 427 | |||
| 428 | start=l; | ||
| 429 | for (;;) | ||
| 430 | { | ||
| 431 | ch= *l; | ||
| 432 | i=0; | ||
| 433 | while ( ((ch >= 'A') && (ch <= 'Z')) || | ||
| 434 | ((ch >= '0') && (ch <= '9')) || | ||
| 435 | ((ch >= 'a') && (ch <= 'z')) || | ||
| 436 | (ch == '-')) | ||
| 437 | { | ||
| 438 | buf[i]=ch; | ||
| 439 | ch= *(++l); | ||
| 440 | i++; | ||
| 441 | if (i >= (CL_BUF-2)) break; | ||
| 442 | } | ||
| 443 | buf[i]='\0'; | ||
| 444 | |||
| 445 | /* check for multi-part specification */ | ||
| 446 | if (ch == '+') | ||
| 447 | { | ||
| 448 | multi=1; | ||
| 449 | l++; | ||
| 450 | } | ||
| 451 | else | ||
| 452 | multi=0; | ||
| 453 | |||
| 454 | c_tmp.name=buf; | ||
| 455 | j=sk_find(ca_list,(char *)&c_tmp); | ||
| 456 | if (j < 0) | ||
| 457 | goto end_loop; | ||
| 458 | |||
| 459 | cp=(SSL_CIPHER *)sk_value(ca_list,j); | ||
| 460 | ops[current_x].algorithms|=cp->algorithms; | ||
| 461 | /* We add the SSL_SSL_MASK so we can match the | ||
| 462 | * SSLv2 and SSLv3 versions of RC4-MD5 */ | ||
| 463 | ops[current_x].mask|=cp->mask; | ||
| 464 | if (!multi) break; | ||
| 465 | } | ||
| 466 | current_x++; | ||
| 467 | if (ch == '\0') break; | ||
| 468 | end_loop: | ||
| 469 | /* Make sure we scan until the next valid start point */ | ||
| 470 | while ((*l != '\0') && ITEM_SEP(*l)) | ||
| 471 | l++; | ||
| 472 | } | ||
| 473 | |||
| 474 | num_x=current_x; | ||
| 475 | current_x=0; | ||
| 476 | |||
| 477 | /* We will now process the list of ciphers, once for each category, to | ||
| 478 | * decide what we should do with it. */ | ||
| 479 | for (j=0; j<num_x; j++) | ||
| 480 | { | ||
| 481 | algorithms=ops[j].algorithms; | ||
| 482 | type=ops[j].type; | ||
| 483 | mask=ops[j].mask; | ||
| 484 | |||
| 485 | curr=head; | ||
| 486 | curr2=head; | ||
| 487 | tail2=tail; | ||
| 488 | for (;;) | ||
| 489 | { | ||
| 490 | if ((curr == NULL) || (curr == tail2)) break; | ||
| 491 | curr=curr2; | ||
| 492 | curr2=curr->next; | ||
| 493 | |||
| 494 | cp=curr->cipher; | ||
| 495 | ma=mask & cp->algorithms; | ||
| 496 | if ((ma == 0) || ((ma & algorithms) != ma)) | ||
| 497 | { | ||
| 498 | /* does not apply */ | ||
| 499 | continue; | ||
| 500 | } | ||
| 501 | |||
| 502 | /* add the cipher if it has not been added yet. */ | ||
| 503 | if (type == CIPHER_ADD) | ||
| 504 | { | ||
| 505 | if (!curr->active) | ||
| 506 | { | ||
| 507 | ll_append_tail(&head,curr,&tail); | ||
| 508 | curr->active=1; | ||
| 509 | } | ||
| 510 | } | ||
| 511 | /* Move the added cipher to this location */ | ||
| 512 | else if (type == CIPHER_ORD) | ||
| 513 | { | ||
| 514 | if (curr->active) | ||
| 515 | { | ||
| 516 | ll_append_tail(&head,curr,&tail); | ||
| 517 | } | ||
| 518 | } | ||
| 519 | else if (type == CIPHER_DEL) | ||
| 520 | curr->active=0; | ||
| 521 | if (type == CIPHER_KILL) | ||
| 522 | { | ||
| 523 | if (head == curr) | ||
| 524 | head=curr->next; | ||
| 525 | else | ||
| 526 | curr->prev->next=curr->next; | ||
| 527 | if (tail == curr) | ||
| 528 | tail=curr->prev; | ||
| 529 | curr->active=0; | ||
| 530 | if (curr->next != NULL) | ||
| 531 | curr->next->prev=curr->prev; | ||
| 532 | if (curr->prev != NULL) | ||
| 533 | curr->prev->next=curr->next; | ||
| 534 | curr->next=NULL; | ||
| 535 | curr->prev=NULL; | ||
| 536 | } | ||
| 537 | } | ||
| 538 | } | ||
| 539 | |||
| 540 | for (curr=head; curr != NULL; curr=curr->next) | ||
| 541 | { | ||
| 542 | if (curr->active) | ||
| 543 | { | ||
| 544 | sk_push(ret,(char *)curr->cipher); | ||
| 545 | #ifdef CIPHER_DEBUG | ||
| 546 | printf("<%s>\n",curr->cipher->name); | ||
| 547 | #endif | ||
| 548 | } | ||
| 549 | } | ||
| 550 | |||
| 551 | if (cipher_list != NULL) | ||
| 552 | { | ||
| 553 | if (*cipher_list != NULL) | ||
| 554 | sk_free(*cipher_list); | ||
| 555 | *cipher_list=ret; | ||
| 556 | } | ||
| 557 | |||
| 558 | if (cipher_list_by_id != NULL) | ||
| 559 | { | ||
| 560 | if (*cipher_list_by_id != NULL) | ||
| 561 | sk_free(*cipher_list_by_id); | ||
| 562 | *cipher_list_by_id=sk_dup(ret); | ||
| 563 | } | ||
| 564 | |||
| 565 | if ( (cipher_list_by_id == NULL) || | ||
| 566 | (*cipher_list_by_id == NULL) || | ||
| 567 | (cipher_list == NULL) || | ||
| 568 | (*cipher_list == NULL)) | ||
| 569 | goto err; | ||
| 570 | sk_set_cmp_func(*cipher_list_by_id,ssl_cipher_ptr_id_cmp); | ||
| 571 | |||
| 572 | ok=ret; | ||
| 573 | ret=NULL; | ||
| 574 | err: | ||
| 575 | if (tmp_str) Free(tmp_str); | ||
| 576 | if (ops != NULL) Free(ops); | ||
| 577 | if (ret != NULL) sk_free(ret); | ||
| 578 | if (ca_list != NULL) sk_free(ca_list); | ||
| 579 | if (list != NULL) Free(list); | ||
| 580 | return(ok); | ||
| 581 | } | ||
| 582 | |||
| 583 | char *SSL_CIPHER_description(cipher,buf,len) | ||
| 584 | SSL_CIPHER *cipher; | ||
| 585 | char *buf; | ||
| 586 | int len; | ||
| 587 | { | ||
| 588 | int export; | ||
| 589 | char *ver,*exp; | ||
| 590 | char *kx,*au,*enc,*mac; | ||
| 591 | unsigned long alg,alg2; | ||
| 592 | static char *format="%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s%s\n"; | ||
| 593 | |||
| 594 | alg=cipher->algorithms; | ||
| 595 | alg2=cipher->algorithm2; | ||
| 596 | |||
| 597 | export=(alg&SSL_EXP)?1:0; | ||
| 598 | exp=(export)?" export":""; | ||
| 599 | |||
| 600 | if (alg & SSL_SSLV2) | ||
| 601 | ver="SSLv2"; | ||
| 602 | else if (alg & SSL_SSLV3) | ||
| 603 | ver="SSLv3"; | ||
| 604 | else | ||
| 605 | ver="unknown"; | ||
| 606 | |||
| 607 | switch (alg&SSL_MKEY_MASK) | ||
| 608 | { | ||
| 609 | case SSL_kRSA: | ||
| 610 | kx=(export)?"RSA(512)":"RSA"; | ||
| 611 | break; | ||
| 612 | case SSL_kDHr: | ||
| 613 | kx="DH/RSA"; | ||
| 614 | break; | ||
| 615 | case SSL_kDHd: | ||
| 616 | kx="DH/DSS"; | ||
| 617 | break; | ||
| 618 | case SSL_kFZA: | ||
| 619 | kx="Fortezza"; | ||
| 620 | break; | ||
| 621 | case SSL_kEDH: | ||
| 622 | kx=(export)?"DH(512)":"DH"; | ||
| 623 | break; | ||
| 624 | default: | ||
| 625 | kx="unknown"; | ||
| 626 | } | ||
| 627 | |||
| 628 | switch (alg&SSL_AUTH_MASK) | ||
| 629 | { | ||
| 630 | case SSL_aRSA: | ||
| 631 | au="RSA"; | ||
| 632 | break; | ||
| 633 | case SSL_aDSS: | ||
| 634 | au="DSS"; | ||
| 635 | break; | ||
| 636 | case SSL_aDH: | ||
| 637 | au="DH"; | ||
| 638 | break; | ||
| 639 | case SSL_aFZA: | ||
| 640 | case SSL_aNULL: | ||
| 641 | au="None"; | ||
| 642 | break; | ||
| 643 | default: | ||
| 644 | au="unknown"; | ||
| 645 | break; | ||
| 646 | } | ||
| 647 | |||
| 648 | switch (alg&SSL_ENC_MASK) | ||
| 649 | { | ||
| 650 | case SSL_DES: | ||
| 651 | enc=export?"DES(40)":"DES(56)"; | ||
| 652 | break; | ||
| 653 | case SSL_3DES: | ||
| 654 | enc="3DES(168)"; | ||
| 655 | break; | ||
| 656 | case SSL_RC4: | ||
| 657 | enc=export?"RC4(40)":((alg2&SSL2_CF_8_BYTE_ENC)?"RC4(64)":"RC4(128)"); | ||
| 658 | break; | ||
| 659 | case SSL_RC2: | ||
| 660 | enc=export?"RC2(40)":"RC2(128)"; | ||
| 661 | break; | ||
| 662 | case SSL_IDEA: | ||
| 663 | enc="IDEA(128)"; | ||
| 664 | break; | ||
| 665 | case SSL_eFZA: | ||
| 666 | enc="Fortezza"; | ||
| 667 | break; | ||
| 668 | case SSL_eNULL: | ||
| 669 | enc="None"; | ||
| 670 | break; | ||
| 671 | default: | ||
| 672 | enc="unknown"; | ||
| 673 | break; | ||
| 674 | } | ||
| 675 | |||
| 676 | switch (alg&SSL_MAC_MASK) | ||
| 677 | { | ||
| 678 | case SSL_MD5: | ||
| 679 | mac="MD5"; | ||
| 680 | break; | ||
| 681 | case SSL_SHA1: | ||
| 682 | mac="SHA1"; | ||
| 683 | break; | ||
| 684 | default: | ||
| 685 | mac="unknown"; | ||
| 686 | break; | ||
| 687 | } | ||
| 688 | |||
| 689 | if (buf == NULL) | ||
| 690 | { | ||
| 691 | buf=Malloc(128); | ||
| 692 | if (buf == NULL) return("Malloc Error"); | ||
| 693 | } | ||
| 694 | else if (len < 128) | ||
| 695 | return("Buffer too small"); | ||
| 696 | |||
| 697 | sprintf(buf,format,cipher->name,ver,kx,au,enc,mac,exp); | ||
| 698 | return(buf); | ||
| 699 | } | ||
| 700 | |||
| 701 | char *SSL_CIPHER_get_version(c) | ||
| 702 | SSL_CIPHER *c; | ||
| 703 | { | ||
| 704 | int i; | ||
| 705 | |||
| 706 | if (c == NULL) return("(NONE)"); | ||
| 707 | i=(int)(c->id>>24L); | ||
| 708 | if (i == 3) | ||
| 709 | return("TLSv1/SSLv3"); | ||
| 710 | else if (i == 2) | ||
| 711 | return("SSLv2"); | ||
| 712 | else | ||
| 713 | return("unknown"); | ||
| 714 | } | ||
| 715 | |||
| 716 | /* return the actual cipher being used */ | ||
| 717 | char *SSL_CIPHER_get_name(c) | ||
| 718 | SSL_CIPHER *c; | ||
| 719 | { | ||
| 720 | if (c != NULL) | ||
| 721 | return(c->name); | ||
| 722 | return("(NONE)"); | ||
| 723 | } | ||
| 724 | |||
| 725 | /* number of bits for symetric cipher */ | ||
| 726 | int SSL_CIPHER_get_bits(c,alg_bits) | ||
| 727 | SSL_CIPHER *c; | ||
| 728 | int *alg_bits; | ||
| 729 | { | ||
| 730 | int ret=0,a=0; | ||
| 731 | EVP_CIPHER *enc; | ||
| 732 | EVP_MD *md; | ||
| 733 | |||
| 734 | if (c != NULL) | ||
| 735 | { | ||
| 736 | if (!ssl_cipher_get_evp(c,&enc,&md)) | ||
| 737 | return(0); | ||
| 738 | |||
| 739 | a=EVP_CIPHER_key_length(enc)*8; | ||
| 740 | |||
| 741 | if (c->algorithms & SSL_EXP) | ||
| 742 | { | ||
| 743 | ret=40; | ||
| 744 | } | ||
| 745 | else | ||
| 746 | { | ||
| 747 | if (c->algorithm2 & SSL2_CF_8_BYTE_ENC) | ||
| 748 | ret=64; | ||
| 749 | else | ||
| 750 | ret=a; | ||
| 751 | } | ||
| 752 | } | ||
| 753 | |||
| 754 | if (alg_bits != NULL) *alg_bits=a; | ||
| 755 | |||
| 756 | return(ret); | ||
| 757 | } | ||
| 758 | |||
diff --git a/src/lib/libssl/ssl_err.c b/src/lib/libssl/ssl_err.c new file mode 100644 index 0000000000..bcbb98591f --- /dev/null +++ b/src/lib/libssl/ssl_err.c | |||
| @@ -0,0 +1,374 @@ | |||
| 1 | /* lib/ssl/ssl_err.c */ | ||
| 2 | /* Copyright (C) 1995-1997 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 | #include <stdio.h> | ||
| 59 | #include "err.h" | ||
| 60 | #include "ssl.h" | ||
| 61 | |||
| 62 | /* BEGIN ERROR CODES */ | ||
| 63 | #ifndef NO_ERR | ||
| 64 | static ERR_STRING_DATA SSL_str_functs[]= | ||
| 65 | { | ||
| 66 | {ERR_PACK(0,SSL_F_CLIENT_CERTIFICATE,0), "CLIENT_CERTIFICATE"}, | ||
| 67 | {ERR_PACK(0,SSL_F_CLIENT_HELLO,0), "CLIENT_HELLO"}, | ||
| 68 | {ERR_PACK(0,SSL_F_CLIENT_MASTER_KEY,0), "CLIENT_MASTER_KEY"}, | ||
| 69 | {ERR_PACK(0,SSL_F_D2I_SSL_SESSION,0), "d2i_SSL_SESSION"}, | ||
| 70 | {ERR_PACK(0,SSL_F_DO_SSL3_WRITE,0), "DO_SSL3_WRITE"}, | ||
| 71 | {ERR_PACK(0,SSL_F_GET_CLIENT_FINISHED,0), "GET_CLIENT_FINISHED"}, | ||
| 72 | {ERR_PACK(0,SSL_F_GET_CLIENT_HELLO,0), "GET_CLIENT_HELLO"}, | ||
| 73 | {ERR_PACK(0,SSL_F_GET_CLIENT_MASTER_KEY,0), "GET_CLIENT_MASTER_KEY"}, | ||
| 74 | {ERR_PACK(0,SSL_F_GET_SERVER_FINISHED,0), "GET_SERVER_FINISHED"}, | ||
| 75 | {ERR_PACK(0,SSL_F_GET_SERVER_HELLO,0), "GET_SERVER_HELLO"}, | ||
| 76 | {ERR_PACK(0,SSL_F_GET_SERVER_VERIFY,0), "GET_SERVER_VERIFY"}, | ||
| 77 | {ERR_PACK(0,SSL_F_I2D_SSL_SESSION,0), "i2d_SSL_SESSION"}, | ||
| 78 | {ERR_PACK(0,SSL_F_READ_N,0), "READ_N"}, | ||
| 79 | {ERR_PACK(0,SSL_F_REQUEST_CERTIFICATE,0), "REQUEST_CERTIFICATE"}, | ||
| 80 | {ERR_PACK(0,SSL_F_SERVER_HELLO,0), "SERVER_HELLO"}, | ||
| 81 | {ERR_PACK(0,SSL_F_SSL23_ACCEPT,0), "SSL23_ACCEPT"}, | ||
| 82 | {ERR_PACK(0,SSL_F_SSL23_CLIENT_HELLO,0), "SSL23_CLIENT_HELLO"}, | ||
| 83 | {ERR_PACK(0,SSL_F_SSL23_CONNECT,0), "SSL23_CONNECT"}, | ||
| 84 | {ERR_PACK(0,SSL_F_SSL23_GET_CLIENT_HELLO,0), "SSL23_GET_CLIENT_HELLO"}, | ||
| 85 | {ERR_PACK(0,SSL_F_SSL23_GET_SERVER_HELLO,0), "SSL23_GET_SERVER_HELLO"}, | ||
| 86 | {ERR_PACK(0,SSL_F_SSL23_READ,0), "SSL23_READ"}, | ||
| 87 | {ERR_PACK(0,SSL_F_SSL23_WRITE,0), "SSL23_WRITE"}, | ||
| 88 | {ERR_PACK(0,SSL_F_SSL2_ACCEPT,0), "SSL2_ACCEPT"}, | ||
| 89 | {ERR_PACK(0,SSL_F_SSL2_CONNECT,0), "SSL2_CONNECT"}, | ||
| 90 | {ERR_PACK(0,SSL_F_SSL2_ENC_INIT,0), "SSL2_ENC_INIT"}, | ||
| 91 | {ERR_PACK(0,SSL_F_SSL2_READ,0), "SSL2_READ"}, | ||
| 92 | {ERR_PACK(0,SSL_F_SSL2_SET_CERTIFICATE,0), "SSL2_SET_CERTIFICATE"}, | ||
| 93 | {ERR_PACK(0,SSL_F_SSL2_WRITE,0), "SSL2_WRITE"}, | ||
| 94 | {ERR_PACK(0,SSL_F_SSL3_ACCEPT,0), "SSL3_ACCEPT"}, | ||
| 95 | {ERR_PACK(0,SSL_F_SSL3_CHANGE_CIPHER_STATE,0), "SSL3_CHANGE_CIPHER_STATE"}, | ||
| 96 | {ERR_PACK(0,SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,0), "SSL3_CHECK_CERT_AND_ALGORITHM"}, | ||
| 97 | {ERR_PACK(0,SSL_F_SSL3_CLIENT_HELLO,0), "SSL3_CLIENT_HELLO"}, | ||
| 98 | {ERR_PACK(0,SSL_F_SSL3_CONNECT,0), "SSL3_CONNECT"}, | ||
| 99 | {ERR_PACK(0,SSL_F_SSL3_CTX_CTRL,0), "SSL3_CTX_CTRL"}, | ||
| 100 | {ERR_PACK(0,SSL_F_SSL3_ENC,0), "SSL3_ENC"}, | ||
| 101 | {ERR_PACK(0,SSL_F_SSL3_GET_CERTIFICATE_REQUEST,0), "SSL3_GET_CERTIFICATE_REQUEST"}, | ||
| 102 | {ERR_PACK(0,SSL_F_SSL3_GET_CERT_VERIFY,0), "SSL3_GET_CERT_VERIFY"}, | ||
| 103 | {ERR_PACK(0,SSL_F_SSL3_GET_CLIENT_CERTIFICATE,0), "SSL3_GET_CLIENT_CERTIFICATE"}, | ||
| 104 | {ERR_PACK(0,SSL_F_SSL3_GET_CLIENT_HELLO,0), "SSL3_GET_CLIENT_HELLO"}, | ||
| 105 | {ERR_PACK(0,SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,0), "SSL3_GET_CLIENT_KEY_EXCHANGE"}, | ||
| 106 | {ERR_PACK(0,SSL_F_SSL3_GET_FINISHED,0), "SSL3_GET_FINISHED"}, | ||
| 107 | {ERR_PACK(0,SSL_F_SSL3_GET_KEY_EXCHANGE,0), "SSL3_GET_KEY_EXCHANGE"}, | ||
| 108 | {ERR_PACK(0,SSL_F_SSL3_GET_MESSAGE,0), "SSL3_GET_MESSAGE"}, | ||
| 109 | {ERR_PACK(0,SSL_F_SSL3_GET_RECORD,0), "SSL3_GET_RECORD"}, | ||
| 110 | {ERR_PACK(0,SSL_F_SSL3_GET_SERVER_CERTIFICATE,0), "SSL3_GET_SERVER_CERTIFICATE"}, | ||
| 111 | {ERR_PACK(0,SSL_F_SSL3_GET_SERVER_DONE,0), "SSL3_GET_SERVER_DONE"}, | ||
| 112 | {ERR_PACK(0,SSL_F_SSL3_GET_SERVER_HELLO,0), "SSL3_GET_SERVER_HELLO"}, | ||
| 113 | {ERR_PACK(0,SSL_F_SSL3_OUTPUT_CERT_CHAIN,0), "SSL3_OUTPUT_CERT_CHAIN"}, | ||
| 114 | {ERR_PACK(0,SSL_F_SSL3_READ_BYTES,0), "SSL3_READ_BYTES"}, | ||
| 115 | {ERR_PACK(0,SSL_F_SSL3_READ_N,0), "SSL3_READ_N"}, | ||
| 116 | {ERR_PACK(0,SSL_F_SSL3_SEND_CERTIFICATE_REQUEST,0), "SSL3_SEND_CERTIFICATE_REQUEST"}, | ||
| 117 | {ERR_PACK(0,SSL_F_SSL3_SEND_CLIENT_CERTIFICATE,0), "SSL3_SEND_CLIENT_CERTIFICATE"}, | ||
| 118 | {ERR_PACK(0,SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,0), "SSL3_SEND_CLIENT_KEY_EXCHANGE"}, | ||
| 119 | {ERR_PACK(0,SSL_F_SSL3_SEND_CLIENT_VERIFY,0), "SSL3_SEND_CLIENT_VERIFY"}, | ||
| 120 | {ERR_PACK(0,SSL_F_SSL3_SEND_SERVER_CERTIFICATE,0), "SSL3_SEND_SERVER_CERTIFICATE"}, | ||
| 121 | {ERR_PACK(0,SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,0), "SSL3_SEND_SERVER_KEY_EXCHANGE"}, | ||
| 122 | {ERR_PACK(0,SSL_F_SSL3_SETUP_BUFFERS,0), "SSL3_SETUP_BUFFERS"}, | ||
| 123 | {ERR_PACK(0,SSL_F_SSL3_SETUP_KEY_BLOCK,0), "SSL3_SETUP_KEY_BLOCK"}, | ||
| 124 | {ERR_PACK(0,SSL_F_SSL3_WRITE_BYTES,0), "SSL3_WRITE_BYTES"}, | ||
| 125 | {ERR_PACK(0,SSL_F_SSL3_WRITE_PENDING,0), "SSL3_WRITE_PENDING"}, | ||
| 126 | {ERR_PACK(0,SSL_F_SSL_BAD_METHOD,0), "SSL_BAD_METHOD"}, | ||
| 127 | {ERR_PACK(0,SSL_F_SSL_BYTES_TO_CIPHER_LIST,0), "SSL_BYTES_TO_CIPHER_LIST"}, | ||
| 128 | {ERR_PACK(0,SSL_F_SSL_CERT_NEW,0), "SSL_CERT_NEW"}, | ||
| 129 | {ERR_PACK(0,SSL_F_SSL_CHECK_PRIVATE_KEY,0), "SSL_check_private_key"}, | ||
| 130 | {ERR_PACK(0,SSL_F_SSL_CREATE_CIPHER_LIST,0), "SSL_CREATE_CIPHER_LIST"}, | ||
| 131 | {ERR_PACK(0,SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,0), "SSL_CTX_check_private_key"}, | ||
| 132 | {ERR_PACK(0,SSL_F_SSL_CTX_NEW,0), "SSL_CTX_new"}, | ||
| 133 | {ERR_PACK(0,SSL_F_SSL_CTX_SET_SSL_VERSION,0), "SSL_CTX_set_ssl_version"}, | ||
| 134 | {ERR_PACK(0,SSL_F_SSL_CTX_USE_CERTIFICATE,0), "SSL_CTX_use_certificate"}, | ||
| 135 | {ERR_PACK(0,SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1,0), "SSL_CTX_use_certificate_ASN1"}, | ||
| 136 | {ERR_PACK(0,SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,0), "SSL_CTX_use_certificate_file"}, | ||
| 137 | {ERR_PACK(0,SSL_F_SSL_CTX_USE_PRIVATEKEY,0), "SSL_CTX_use_PrivateKey"}, | ||
| 138 | {ERR_PACK(0,SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1,0), "SSL_CTX_use_PrivateKey_ASN1"}, | ||
| 139 | {ERR_PACK(0,SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,0), "SSL_CTX_use_PrivateKey_file"}, | ||
| 140 | {ERR_PACK(0,SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,0), "SSL_CTX_use_RSAPrivateKey"}, | ||
| 141 | {ERR_PACK(0,SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1,0), "SSL_CTX_use_RSAPrivateKey_ASN1"}, | ||
| 142 | {ERR_PACK(0,SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,0), "SSL_CTX_use_RSAPrivateKey_file"}, | ||
| 143 | {ERR_PACK(0,SSL_F_SSL_DO_HANDSHAKE,0), "SSL_do_handshake"}, | ||
| 144 | {ERR_PACK(0,SSL_F_SSL_GET_NEW_SESSION,0), "SSL_GET_NEW_SESSION"}, | ||
| 145 | {ERR_PACK(0,SSL_F_SSL_GET_SERVER_SEND_CERT,0), "SSL_GET_SERVER_SEND_CERT"}, | ||
| 146 | {ERR_PACK(0,SSL_F_SSL_GET_SIGN_PKEY,0), "SSL_GET_SIGN_PKEY"}, | ||
| 147 | {ERR_PACK(0,SSL_F_SSL_INIT_WBIO_BUFFER,0), "SSL_INIT_WBIO_BUFFER"}, | ||
| 148 | {ERR_PACK(0,SSL_F_SSL_LOAD_CLIENT_CA_FILE,0), "SSL_load_client_CA_file"}, | ||
| 149 | {ERR_PACK(0,SSL_F_SSL_NEW,0), "SSL_new"}, | ||
| 150 | {ERR_PACK(0,SSL_F_SSL_RSA_PRIVATE_DECRYPT,0), "SSL_RSA_PRIVATE_DECRYPT"}, | ||
| 151 | {ERR_PACK(0,SSL_F_SSL_RSA_PUBLIC_ENCRYPT,0), "SSL_RSA_PUBLIC_ENCRYPT"}, | ||
| 152 | {ERR_PACK(0,SSL_F_SSL_SESSION_NEW,0), "SSL_SESSION_new"}, | ||
| 153 | {ERR_PACK(0,SSL_F_SSL_SESSION_PRINT_FP,0), "SSL_SESSION_print_fp"}, | ||
| 154 | {ERR_PACK(0,SSL_F_SSL_SET_CERT,0), "SSL_SET_CERT"}, | ||
| 155 | {ERR_PACK(0,SSL_F_SSL_SET_FD,0), "SSL_set_fd"}, | ||
| 156 | {ERR_PACK(0,SSL_F_SSL_SET_PKEY,0), "SSL_SET_PKEY"}, | ||
| 157 | {ERR_PACK(0,SSL_F_SSL_SET_RFD,0), "SSL_set_rfd"}, | ||
| 158 | {ERR_PACK(0,SSL_F_SSL_SET_SESSION,0), "SSL_set_session"}, | ||
| 159 | {ERR_PACK(0,SSL_F_SSL_SET_WFD,0), "SSL_set_wfd"}, | ||
| 160 | {ERR_PACK(0,SSL_F_SSL_UNDEFINED_FUNCTION,0), "SSL_UNDEFINED_FUNCTION"}, | ||
| 161 | {ERR_PACK(0,SSL_F_SSL_USE_CERTIFICATE,0), "SSL_use_certificate"}, | ||
| 162 | {ERR_PACK(0,SSL_F_SSL_USE_CERTIFICATE_ASN1,0), "SSL_use_certificate_ASN1"}, | ||
| 163 | {ERR_PACK(0,SSL_F_SSL_USE_CERTIFICATE_FILE,0), "SSL_use_certificate_file"}, | ||
| 164 | {ERR_PACK(0,SSL_F_SSL_USE_PRIVATEKEY,0), "SSL_use_PrivateKey"}, | ||
| 165 | {ERR_PACK(0,SSL_F_SSL_USE_PRIVATEKEY_ASN1,0), "SSL_use_PrivateKey_ASN1"}, | ||
| 166 | {ERR_PACK(0,SSL_F_SSL_USE_PRIVATEKEY_FILE,0), "SSL_use_PrivateKey_file"}, | ||
| 167 | {ERR_PACK(0,SSL_F_SSL_USE_RSAPRIVATEKEY,0), "SSL_use_RSAPrivateKey"}, | ||
| 168 | {ERR_PACK(0,SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1,0), "SSL_use_RSAPrivateKey_ASN1"}, | ||
| 169 | {ERR_PACK(0,SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,0), "SSL_use_RSAPrivateKey_file"}, | ||
| 170 | {ERR_PACK(0,SSL_F_SSL_WRITE,0), "SSL_write"}, | ||
| 171 | {ERR_PACK(0,SSL_F_TLS1_CHANGE_CIPHER_STATE,0), "TLS1_CHANGE_CIPHER_STATE"}, | ||
| 172 | {ERR_PACK(0,SSL_F_TLS1_ENC,0), "TLS1_ENC"}, | ||
| 173 | {ERR_PACK(0,SSL_F_TLS1_SETUP_KEY_BLOCK,0), "TLS1_SETUP_KEY_BLOCK"}, | ||
| 174 | {ERR_PACK(0,SSL_F_WRITE_PENDING,0), "WRITE_PENDING"}, | ||
| 175 | {0,NULL}, | ||
| 176 | }; | ||
| 177 | |||
| 178 | static ERR_STRING_DATA SSL_str_reasons[]= | ||
| 179 | { | ||
| 180 | {SSL_R_APP_DATA_IN_HANDSHAKE ,"app data in handshake"}, | ||
| 181 | {SSL_R_BAD_ALERT_RECORD ,"bad alert record"}, | ||
| 182 | {SSL_R_BAD_AUTHENTICATION_TYPE ,"bad authentication type"}, | ||
| 183 | {SSL_R_BAD_CHANGE_CIPHER_SPEC ,"bad change cipher spec"}, | ||
| 184 | {SSL_R_BAD_CHECKSUM ,"bad checksum"}, | ||
| 185 | {SSL_R_BAD_CLIENT_REQUEST ,"bad client request"}, | ||
| 186 | {SSL_R_BAD_DATA_RETURNED_BY_CALLBACK ,"bad data returned by callback"}, | ||
| 187 | {SSL_R_BAD_DECOMPRESSION ,"bad decompression"}, | ||
| 188 | {SSL_R_BAD_DH_G_LENGTH ,"bad dh g length"}, | ||
| 189 | {SSL_R_BAD_DH_PUB_KEY_LENGTH ,"bad dh pub key length"}, | ||
| 190 | {SSL_R_BAD_DH_P_LENGTH ,"bad dh p length"}, | ||
| 191 | {SSL_R_BAD_DIGEST_LENGTH ,"bad digest length"}, | ||
| 192 | {SSL_R_BAD_DSA_SIGNATURE ,"bad dsa signature"}, | ||
| 193 | {SSL_R_BAD_MAC_DECODE ,"bad mac decode"}, | ||
| 194 | {SSL_R_BAD_MESSAGE_TYPE ,"bad message type"}, | ||
| 195 | {SSL_R_BAD_PACKET_LENGTH ,"bad packet length"}, | ||
| 196 | {SSL_R_BAD_PROTOCOL_VERSION_NUMBER ,"bad protocol version number"}, | ||
| 197 | {SSL_R_BAD_RESPONSE_ARGUMENT ,"bad response argument"}, | ||
| 198 | {SSL_R_BAD_RSA_DECRYPT ,"bad rsa decrypt"}, | ||
| 199 | {SSL_R_BAD_RSA_ENCRYPT ,"bad rsa encrypt"}, | ||
| 200 | {SSL_R_BAD_RSA_E_LENGTH ,"bad rsa e length"}, | ||
| 201 | {SSL_R_BAD_RSA_MODULUS_LENGTH ,"bad rsa modulus length"}, | ||
| 202 | {SSL_R_BAD_RSA_SIGNATURE ,"bad rsa signature"}, | ||
| 203 | {SSL_R_BAD_SIGNATURE ,"bad signature"}, | ||
| 204 | {SSL_R_BAD_SSL_FILETYPE ,"bad ssl filetype"}, | ||
| 205 | {SSL_R_BAD_SSL_SESSION_ID_LENGTH ,"bad ssl session id length"}, | ||
| 206 | {SSL_R_BAD_STATE ,"bad state"}, | ||
| 207 | {SSL_R_BAD_WRITE_RETRY ,"bad write retry"}, | ||
| 208 | {SSL_R_BIO_NOT_SET ,"bio not set"}, | ||
| 209 | {SSL_R_BLOCK_CIPHER_PAD_IS_WRONG ,"block cipher pad is wrong"}, | ||
| 210 | {SSL_R_BN_LIB ,"bn lib"}, | ||
| 211 | {SSL_R_CA_DN_LENGTH_MISMATCH ,"ca dn length mismatch"}, | ||
| 212 | {SSL_R_CA_DN_TOO_LONG ,"ca dn too long"}, | ||
| 213 | {SSL_R_CCS_RECEIVED_EARLY ,"ccs received early"}, | ||
| 214 | {SSL_R_CERTIFICATE_VERIFY_FAILED ,"certificate verify failed"}, | ||
| 215 | {SSL_R_CERT_LENGTH_MISMATCH ,"cert length mismatch"}, | ||
| 216 | {SSL_R_CHALLENGE_IS_DIFFERENT ,"challenge is different"}, | ||
| 217 | {SSL_R_CIPHER_CODE_WRONG_LENGTH ,"cipher code wrong length"}, | ||
| 218 | {SSL_R_CIPHER_OR_HASH_UNAVAILABLE ,"cipher or hash unavailable"}, | ||
| 219 | {SSL_R_CIPHER_TABLE_SRC_ERROR ,"cipher table src error"}, | ||
| 220 | {SSL_R_COMPRESSED_LENGTH_TOO_LONG ,"compressed length too long"}, | ||
| 221 | {SSL_R_COMPRESSION_FAILURE ,"compression failure"}, | ||
| 222 | {SSL_R_CONNECTION_ID_IS_DIFFERENT ,"connection id is different"}, | ||
| 223 | {SSL_R_CONNECTION_TYPE_NOT_SET ,"connection type not set"}, | ||
| 224 | {SSL_R_DATA_BETWEEN_CCS_AND_FINISHED ,"data between ccs and finished"}, | ||
| 225 | {SSL_R_DATA_LENGTH_TOO_LONG ,"data length too long"}, | ||
| 226 | {SSL_R_DECRYPTION_FAILED ,"decryption failed"}, | ||
| 227 | {SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG ,"dh public value length is wrong"}, | ||
| 228 | {SSL_R_DIGEST_CHECK_FAILED ,"digest check failed"}, | ||
| 229 | {SSL_R_ENCRYPTED_LENGTH_TOO_LONG ,"encrypted length too long"}, | ||
| 230 | {SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST ,"error in received cipher list"}, | ||
| 231 | {SSL_R_EXCESSIVE_MESSAGE_SIZE ,"excessive message size"}, | ||
| 232 | {SSL_R_EXTRA_DATA_IN_MESSAGE ,"extra data in message"}, | ||
| 233 | {SSL_R_GOT_A_FIN_BEFORE_A_CCS ,"got a fin before a ccs"}, | ||
| 234 | {SSL_R_HTTPS_PROXY_REQUEST ,"https proxy request"}, | ||
| 235 | {SSL_R_HTTP_REQUEST ,"http request"}, | ||
| 236 | {SSL_R_INTERNAL_ERROR ,"internal error"}, | ||
| 237 | {SSL_R_INVALID_CHALLENGE_LENGTH ,"invalid challenge length"}, | ||
| 238 | {SSL_R_LENGTH_MISMATCH ,"length mismatch"}, | ||
| 239 | {SSL_R_LENGTH_TOO_SHORT ,"length too short"}, | ||
| 240 | {SSL_R_LIBRARY_HAS_NO_CIPHERS ,"library has no ciphers"}, | ||
| 241 | {SSL_R_MISSING_DH_DSA_CERT ,"missing dh dsa cert"}, | ||
| 242 | {SSL_R_MISSING_DH_KEY ,"missing dh key"}, | ||
| 243 | {SSL_R_MISSING_DH_RSA_CERT ,"missing dh rsa cert"}, | ||
| 244 | {SSL_R_MISSING_DSA_SIGNING_CERT ,"missing dsa signing cert"}, | ||
| 245 | {SSL_R_MISSING_EXPORT_TMP_DH_KEY ,"missing export tmp dh key"}, | ||
| 246 | {SSL_R_MISSING_EXPORT_TMP_RSA_KEY ,"missing export tmp rsa key"}, | ||
| 247 | {SSL_R_MISSING_RSA_CERTIFICATE ,"missing rsa certificate"}, | ||
| 248 | {SSL_R_MISSING_RSA_ENCRYPTING_CERT ,"missing rsa encrypting cert"}, | ||
| 249 | {SSL_R_MISSING_RSA_SIGNING_CERT ,"missing rsa signing cert"}, | ||
| 250 | {SSL_R_MISSING_TMP_DH_KEY ,"missing tmp dh key"}, | ||
| 251 | {SSL_R_MISSING_TMP_RSA_KEY ,"missing tmp rsa key"}, | ||
| 252 | {SSL_R_MISSING_TMP_RSA_PKEY ,"missing tmp rsa pkey"}, | ||
| 253 | {SSL_R_MISSING_VERIFY_MESSAGE ,"missing verify message"}, | ||
| 254 | {SSL_R_NON_SSLV2_INITIAL_PACKET ,"non sslv2 initial packet"}, | ||
| 255 | {SSL_R_NO_CERTIFICATES_RETURNED ,"no certificates returned"}, | ||
| 256 | {SSL_R_NO_CERTIFICATE_ASSIGNED ,"no certificate assigned"}, | ||
| 257 | {SSL_R_NO_CERTIFICATE_RETURNED ,"no certificate returned"}, | ||
| 258 | {SSL_R_NO_CERTIFICATE_SET ,"no certificate set"}, | ||
| 259 | {SSL_R_NO_CERTIFICATE_SPECIFIED ,"no certificate specified"}, | ||
| 260 | {SSL_R_NO_CIPHERS_AVAILABLE ,"no ciphers available"}, | ||
| 261 | {SSL_R_NO_CIPHERS_PASSED ,"no ciphers passed"}, | ||
| 262 | {SSL_R_NO_CIPHERS_SPECIFIED ,"no ciphers specified"}, | ||
| 263 | {SSL_R_NO_CIPHER_LIST ,"no cipher list"}, | ||
| 264 | {SSL_R_NO_CIPHER_MATCH ,"no cipher match"}, | ||
| 265 | {SSL_R_NO_CLIENT_CERT_RECEIVED ,"no client cert received"}, | ||
| 266 | {SSL_R_NO_COMPRESSION_SPECIFIED ,"no compression specified"}, | ||
| 267 | {SSL_R_NO_PRIVATEKEY ,"no privatekey"}, | ||
| 268 | {SSL_R_NO_PRIVATE_KEY_ASSIGNED ,"no private key assigned"}, | ||
| 269 | {SSL_R_NO_PROTOCOLS_AVAILABLE ,"no protocols available"}, | ||
| 270 | {SSL_R_NO_PUBLICKEY ,"no publickey"}, | ||
| 271 | {SSL_R_NO_SHARED_CIPHER ,"no shared cipher"}, | ||
| 272 | {SSL_R_NULL_SSL_CTX ,"null ssl ctx"}, | ||
| 273 | {SSL_R_NULL_SSL_METHOD_PASSED ,"null ssl method passed"}, | ||
| 274 | {SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED ,"old session cipher not returned"}, | ||
| 275 | {SSL_R_PACKET_LENGTH_TOO_LONG ,"packet length too long"}, | ||
| 276 | {SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE ,"peer did not return a certificate"}, | ||
| 277 | {SSL_R_PEER_ERROR ,"peer error"}, | ||
| 278 | {SSL_R_PEER_ERROR_CERTIFICATE ,"peer error certificate"}, | ||
| 279 | {SSL_R_PEER_ERROR_NO_CERTIFICATE ,"peer error no certificate"}, | ||
| 280 | {SSL_R_PEER_ERROR_NO_CIPHER ,"peer error no cipher"}, | ||
| 281 | {SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE,"peer error unsupported certificate type"}, | ||
| 282 | {SSL_R_PRE_MAC_LENGTH_TOO_LONG ,"pre mac length too long"}, | ||
| 283 | {SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS ,"problems mapping cipher functions"}, | ||
| 284 | {SSL_R_PROTOCOL_IS_SHUTDOWN ,"protocol is shutdown"}, | ||
| 285 | {SSL_R_PUBLIC_KEY_ENCRYPT_ERROR ,"public key encrypt error"}, | ||
| 286 | {SSL_R_PUBLIC_KEY_IS_NOT_RSA ,"public key is not rsa"}, | ||
| 287 | {SSL_R_PUBLIC_KEY_NOT_RSA ,"public key not rsa"}, | ||
| 288 | {SSL_R_READ_BIO_NOT_SET ,"read bio not set"}, | ||
| 289 | {SSL_R_READ_WRONG_PACKET_TYPE ,"read wrong packet type"}, | ||
| 290 | {SSL_R_RECORD_LENGTH_MISMATCH ,"record length mismatch"}, | ||
| 291 | {SSL_R_RECORD_TOO_LARGE ,"record too large"}, | ||
| 292 | {SSL_R_REQUIRED_CIPHER_MISSING ,"required cipher missing"}, | ||
| 293 | {SSL_R_REUSE_CERT_LENGTH_NOT_ZERO ,"reuse cert length not zero"}, | ||
| 294 | {SSL_R_REUSE_CERT_TYPE_NOT_ZERO ,"reuse cert type not zero"}, | ||
| 295 | {SSL_R_REUSE_CIPHER_LIST_NOT_ZERO ,"reuse cipher list not zero"}, | ||
| 296 | {SSL_R_SHORT_READ ,"short read"}, | ||
| 297 | {SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE,"signature for non signing certificate"}, | ||
| 298 | {SSL_R_SSL3_SESSION_ID_TOO_SHORT ,"ssl3 session id too short"}, | ||
| 299 | {SSL_R_SSLV3_ALERT_BAD_CERTIFICATE ,"sslv3 alert bad certificate"}, | ||
| 300 | {SSL_R_SSLV3_ALERT_BAD_RECORD_MAC ,"sslv3 alert bad record mac"}, | ||
| 301 | {SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED ,"sslv3 alert certificate expired"}, | ||
| 302 | {SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED ,"sslv3 alert certificate revoked"}, | ||
| 303 | {SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN ,"sslv3 alert certificate unknown"}, | ||
| 304 | {SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE ,"sslv3 alert decompression failure"}, | ||
| 305 | {SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE ,"sslv3 alert handshake failure"}, | ||
| 306 | {SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER ,"sslv3 alert illegal parameter"}, | ||
| 307 | {SSL_R_SSLV3_ALERT_NO_CERTIFICATE ,"sslv3 alert no certificate"}, | ||
| 308 | {SSL_R_SSLV3_ALERT_PEER_ERROR_CERTIFICATE,"sslv3 alert peer error certificate"}, | ||
| 309 | {SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CERTIFICATE,"sslv3 alert peer error no certificate"}, | ||
| 310 | {SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CIPHER ,"sslv3 alert peer error no cipher"}, | ||
| 311 | {SSL_R_SSLV3_ALERT_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE,"sslv3 alert peer error unsupported certificate type"}, | ||
| 312 | {SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE ,"sslv3 alert unexpected message"}, | ||
| 313 | {SSL_R_SSLV3_ALERT_UNKNOWN_REMOTE_ERROR_TYPE,"sslv3 alert unknown remote error type"}, | ||
| 314 | {SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE,"sslv3 alert unsupported certificate"}, | ||
| 315 | {SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION,"ssl ctx has no default ssl version"}, | ||
| 316 | {SSL_R_SSL_HANDSHAKE_FAILURE ,"ssl handshake failure"}, | ||
| 317 | {SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS ,"ssl library has no ciphers"}, | ||
| 318 | {SSL_R_SSL_SESSION_ID_IS_DIFFERENT ,"ssl session id is different"}, | ||
| 319 | {SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER,"tls client cert req with anon cipher"}, | ||
| 320 | {SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST,"tls peer did not respond with certificate list"}, | ||
| 321 | {SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG,"tls rsa encrypted value length is wrong"}, | ||
| 322 | {SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER ,"tried to use unsupported cipher"}, | ||
| 323 | {SSL_R_UNABLE_TO_DECODE_DH_CERTS ,"unable to decode dh certs"}, | ||
| 324 | {SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY ,"unable to extract public key"}, | ||
| 325 | {SSL_R_UNABLE_TO_FIND_DH_PARAMETERS ,"unable to find dh parameters"}, | ||
| 326 | {SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS,"unable to find public key parameters"}, | ||
| 327 | {SSL_R_UNABLE_TO_FIND_SSL_METHOD ,"unable to find ssl method"}, | ||
| 328 | {SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES ,"unable to load ssl2 md5 routines"}, | ||
| 329 | {SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES ,"unable to load ssl3 md5 routines"}, | ||
| 330 | {SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES ,"unable to load ssl3 sha1 routines"}, | ||
| 331 | {SSL_R_UNEXPECTED_MESSAGE ,"unexpected message"}, | ||
| 332 | {SSL_R_UNEXPECTED_RECORD ,"unexpected record"}, | ||
| 333 | {SSL_R_UNKNOWN_ALERT_TYPE ,"unknown alert type"}, | ||
| 334 | {SSL_R_UNKNOWN_CERTIFICATE_TYPE ,"unknown certificate type"}, | ||
| 335 | {SSL_R_UNKNOWN_CIPHER_RETURNED ,"unknown cipher returned"}, | ||
| 336 | {SSL_R_UNKNOWN_CIPHER_TYPE ,"unknown cipher type"}, | ||
| 337 | {SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE ,"unknown key exchange type"}, | ||
| 338 | {SSL_R_UNKNOWN_PKEY_TYPE ,"unknown pkey type"}, | ||
| 339 | {SSL_R_UNKNOWN_PROTOCOL ,"unknown protocol"}, | ||
| 340 | {SSL_R_UNKNOWN_REMOTE_ERROR_TYPE ,"unknown remote error type"}, | ||
| 341 | {SSL_R_UNKNOWN_SSL_VERSION ,"unknown ssl version"}, | ||
| 342 | {SSL_R_UNKNOWN_STATE ,"unknown state"}, | ||
| 343 | {SSL_R_UNSUPPORTED_CIPHER ,"unsupported cipher"}, | ||
| 344 | {SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM ,"unsupported compression algorithm"}, | ||
| 345 | {SSL_R_UNSUPPORTED_PROTOCOL ,"unsupported protocol"}, | ||
| 346 | {SSL_R_UNSUPPORTED_SSL_VERSION ,"unsupported ssl version"}, | ||
| 347 | {SSL_R_WRITE_BIO_NOT_SET ,"write bio not set"}, | ||
| 348 | {SSL_R_WRONG_CIPHER_RETURNED ,"wrong cipher returned"}, | ||
| 349 | {SSL_R_WRONG_MESSAGE_TYPE ,"wrong message type"}, | ||
| 350 | {SSL_R_WRONG_NUMBER_OF_KEY_BITS ,"wrong number of key bits"}, | ||
| 351 | {SSL_R_WRONG_SIGNATURE_LENGTH ,"wrong signature length"}, | ||
| 352 | {SSL_R_WRONG_SIGNATURE_SIZE ,"wrong signature size"}, | ||
| 353 | {SSL_R_WRONG_SSL_VERSION ,"wrong ssl version"}, | ||
| 354 | {SSL_R_WRONG_VERSION_NUMBER ,"wrong version number"}, | ||
| 355 | {SSL_R_X509_LIB ,"x509 lib"}, | ||
| 356 | {0,NULL}, | ||
| 357 | }; | ||
| 358 | |||
| 359 | #endif | ||
| 360 | |||
| 361 | void ERR_load_SSL_strings() | ||
| 362 | { | ||
| 363 | static int init=1; | ||
| 364 | |||
| 365 | if (init); | ||
| 366 | {; | ||
| 367 | init=0; | ||
| 368 | #ifndef NO_ERR | ||
| 369 | ERR_load_strings(ERR_LIB_SSL,SSL_str_functs); | ||
| 370 | ERR_load_strings(ERR_LIB_SSL,SSL_str_reasons); | ||
| 371 | #endif | ||
| 372 | |||
| 373 | } | ||
| 374 | } | ||
diff --git a/src/lib/libssl/ssl_err2.c b/src/lib/libssl/ssl_err2.c new file mode 100644 index 0000000000..0b91f7b8d2 --- /dev/null +++ b/src/lib/libssl/ssl_err2.c | |||
| @@ -0,0 +1,70 @@ | |||
| 1 | /* ssl/ssl_err2.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 "err.h" | ||
| 61 | #include "ssl.h" | ||
| 62 | |||
| 63 | void SSL_load_error_strings() | ||
| 64 | { | ||
| 65 | #ifndef NO_ERR | ||
| 66 | ERR_load_crypto_strings(); | ||
| 67 | ERR_load_SSL_strings(); | ||
| 68 | #endif | ||
| 69 | } | ||
| 70 | |||
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c new file mode 100644 index 0000000000..f562ec6b14 --- /dev/null +++ b/src/lib/libssl/ssl_lib.c | |||
| @@ -0,0 +1,1721 @@ | |||
| 1 | /* ssl/ssl_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 "objects.h" | ||
| 61 | #include "lhash.h" | ||
| 62 | #include "ssl_locl.h" | ||
| 63 | |||
| 64 | char *SSL_version_str="SSLeay 0.9.0b 29-Jun-1998"; | ||
| 65 | |||
| 66 | static STACK *ssl_meth=NULL; | ||
| 67 | static STACK *ssl_ctx_meth=NULL; | ||
| 68 | static int ssl_meth_num=0; | ||
| 69 | static int ssl_ctx_meth_num=0; | ||
| 70 | |||
| 71 | SSL3_ENC_METHOD ssl3_undef_enc_method={ | ||
| 72 | ssl_undefined_function, | ||
| 73 | ssl_undefined_function, | ||
| 74 | ssl_undefined_function, | ||
| 75 | ssl_undefined_function, | ||
| 76 | ssl_undefined_function, | ||
| 77 | ssl_undefined_function, | ||
| 78 | }; | ||
| 79 | |||
| 80 | void SSL_clear(s) | ||
| 81 | SSL *s; | ||
| 82 | { | ||
| 83 | int state; | ||
| 84 | |||
| 85 | if (s->method == NULL) return; | ||
| 86 | |||
| 87 | s->error=0; | ||
| 88 | s->hit=0; | ||
| 89 | |||
| 90 | /* This is set if we are doing dynamic renegotiation so keep | ||
| 91 | * the old cipher. It is sort of a SSL_clear_lite :-) */ | ||
| 92 | if (s->new_session) return; | ||
| 93 | |||
| 94 | state=s->state; /* Keep to check if we throw away the session-id */ | ||
| 95 | s->type=0; | ||
| 96 | |||
| 97 | s->version=s->method->version; | ||
| 98 | s->rwstate=SSL_NOTHING; | ||
| 99 | s->state=SSL_ST_BEFORE; | ||
| 100 | s->rstate=SSL_ST_READ_HEADER; | ||
| 101 | s->read_ahead=s->ctx->default_read_ahead; | ||
| 102 | |||
| 103 | /* s->shutdown=(SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN); */ | ||
| 104 | |||
| 105 | if (s->init_buf != NULL) | ||
| 106 | { | ||
| 107 | BUF_MEM_free(s->init_buf); | ||
| 108 | s->init_buf=NULL; | ||
| 109 | } | ||
| 110 | |||
| 111 | ssl_clear_cipher_ctx(s); | ||
| 112 | |||
| 113 | if (ssl_clear_bad_session(s)) | ||
| 114 | { | ||
| 115 | SSL_SESSION_free(s->session); | ||
| 116 | s->session=NULL; | ||
| 117 | } | ||
| 118 | |||
| 119 | s->shutdown=(SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN); | ||
| 120 | s->first_packet=0; | ||
| 121 | |||
| 122 | s->method->ssl_clear(s); | ||
| 123 | } | ||
| 124 | |||
| 125 | /* Used to change an SSL_CTXs default SSL method type */ | ||
| 126 | int SSL_CTX_set_ssl_version(ctx,meth) | ||
| 127 | SSL_CTX *ctx; | ||
| 128 | SSL_METHOD *meth; | ||
| 129 | { | ||
| 130 | STACK *sk; | ||
| 131 | |||
| 132 | ctx->method=meth; | ||
| 133 | |||
| 134 | sk=ssl_create_cipher_list(ctx->method,&(ctx->cipher_list), | ||
| 135 | &(ctx->cipher_list_by_id),SSL_DEFAULT_CIPHER_LIST); | ||
| 136 | if ((sk == NULL) || (sk_num(sk) <= 0)) | ||
| 137 | { | ||
| 138 | SSLerr(SSL_F_SSL_CTX_SET_SSL_VERSION,SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS); | ||
| 139 | return(0); | ||
| 140 | } | ||
| 141 | return(1); | ||
| 142 | } | ||
| 143 | |||
| 144 | SSL *SSL_new(ctx) | ||
| 145 | SSL_CTX *ctx; | ||
| 146 | { | ||
| 147 | SSL *s; | ||
| 148 | |||
| 149 | if (ctx == NULL) | ||
| 150 | { | ||
| 151 | SSLerr(SSL_F_SSL_NEW,SSL_R_NULL_SSL_CTX); | ||
| 152 | return(NULL); | ||
| 153 | } | ||
| 154 | if (ctx->method == NULL) | ||
| 155 | { | ||
| 156 | SSLerr(SSL_F_SSL_NEW,SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION); | ||
| 157 | return(NULL); | ||
| 158 | } | ||
| 159 | |||
| 160 | s=(SSL *)Malloc(sizeof(SSL)); | ||
| 161 | if (s == NULL) goto err; | ||
| 162 | memset(s,0,sizeof(SSL)); | ||
| 163 | |||
| 164 | if (ctx->default_cert != NULL) | ||
| 165 | { | ||
| 166 | CRYPTO_add(&ctx->default_cert->references,1, | ||
| 167 | CRYPTO_LOCK_SSL_CERT); | ||
| 168 | s->cert=ctx->default_cert; | ||
| 169 | } | ||
| 170 | else | ||
| 171 | s->cert=NULL; | ||
| 172 | s->verify_mode=ctx->default_verify_mode; | ||
| 173 | s->verify_callback=ctx->default_verify_callback; | ||
| 174 | CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX); | ||
| 175 | s->ctx=ctx; | ||
| 176 | |||
| 177 | s->verify_result=X509_V_OK; | ||
| 178 | |||
| 179 | s->method=ctx->method; | ||
| 180 | |||
| 181 | if (!s->method->ssl_new(s)) | ||
| 182 | { | ||
| 183 | SSL_CTX_free(ctx); | ||
| 184 | Free(s); | ||
| 185 | goto err; | ||
| 186 | } | ||
| 187 | |||
| 188 | s->quiet_shutdown=ctx->quiet_shutdown; | ||
| 189 | s->references=1; | ||
| 190 | s->options=ctx->options; | ||
| 191 | SSL_clear(s); | ||
| 192 | |||
| 193 | CRYPTO_new_ex_data(ssl_meth,(char *)s,&s->ex_data); | ||
| 194 | |||
| 195 | return(s); | ||
| 196 | err: | ||
| 197 | SSLerr(SSL_F_SSL_NEW,ERR_R_MALLOC_FAILURE); | ||
| 198 | return(NULL); | ||
| 199 | } | ||
| 200 | |||
| 201 | void SSL_free(s) | ||
| 202 | SSL *s; | ||
| 203 | { | ||
| 204 | int i; | ||
| 205 | |||
| 206 | i=CRYPTO_add(&s->references,-1,CRYPTO_LOCK_SSL); | ||
| 207 | #ifdef REF_PRINT | ||
| 208 | REF_PRINT("SSL",s); | ||
| 209 | #endif | ||
| 210 | if (i > 0) return; | ||
| 211 | #ifdef REF_CHECK | ||
| 212 | if (i < 0) | ||
| 213 | { | ||
| 214 | fprintf(stderr,"SSL_free, bad reference count\n"); | ||
| 215 | abort(); /* ok */ | ||
| 216 | } | ||
| 217 | #endif | ||
| 218 | |||
| 219 | CRYPTO_free_ex_data(ssl_meth,(char *)s,&s->ex_data); | ||
| 220 | |||
| 221 | if (s->bbio != NULL) | ||
| 222 | { | ||
| 223 | /* If the buffering BIO is in place, pop it off */ | ||
| 224 | if (s->bbio == s->wbio) | ||
| 225 | { | ||
| 226 | s->wbio=BIO_pop(s->wbio); | ||
| 227 | } | ||
| 228 | BIO_free(s->bbio); | ||
| 229 | s->bbio=NULL; | ||
| 230 | } | ||
| 231 | if (s->rbio != NULL) | ||
| 232 | BIO_free_all(s->rbio); | ||
| 233 | if ((s->wbio != NULL) && (s->wbio != s->rbio)) | ||
| 234 | BIO_free_all(s->wbio); | ||
| 235 | |||
| 236 | if (s->init_buf != NULL) BUF_MEM_free(s->init_buf); | ||
| 237 | |||
| 238 | /* add extra stuff */ | ||
| 239 | if (s->cipher_list != NULL) sk_free(s->cipher_list); | ||
| 240 | if (s->cipher_list_by_id != NULL) sk_free(s->cipher_list_by_id); | ||
| 241 | |||
| 242 | /* Make the next call work :-) */ | ||
| 243 | if (s->session != NULL) | ||
| 244 | { | ||
| 245 | ssl_clear_bad_session(s); | ||
| 246 | SSL_SESSION_free(s->session); | ||
| 247 | } | ||
| 248 | |||
| 249 | ssl_clear_cipher_ctx(s); | ||
| 250 | |||
| 251 | if (s->cert != NULL) ssl_cert_free(s->cert); | ||
| 252 | /* Free up if allocated */ | ||
| 253 | |||
| 254 | if (s->ctx) SSL_CTX_free(s->ctx); | ||
| 255 | |||
| 256 | if (s->client_CA != NULL) | ||
| 257 | sk_pop_free(s->client_CA,X509_NAME_free); | ||
| 258 | |||
| 259 | if (s->method != NULL) s->method->ssl_free(s); | ||
| 260 | |||
| 261 | Free((char *)s); | ||
| 262 | } | ||
| 263 | |||
| 264 | void SSL_set_bio(s, rbio,wbio) | ||
| 265 | SSL *s; | ||
| 266 | BIO *rbio; | ||
| 267 | BIO *wbio; | ||
| 268 | { | ||
| 269 | /* If the output buffering BIO is still in place, remove it | ||
| 270 | */ | ||
| 271 | if (s->bbio != NULL) | ||
| 272 | { | ||
| 273 | if (s->wbio == s->bbio) | ||
| 274 | { | ||
| 275 | s->wbio=s->wbio->next_bio; | ||
| 276 | s->bbio->next_bio=NULL; | ||
| 277 | } | ||
| 278 | } | ||
| 279 | if ((s->rbio != NULL) && (s->rbio != rbio)) | ||
| 280 | BIO_free_all(s->rbio); | ||
| 281 | if ((s->wbio != NULL) && (s->wbio != wbio) && (s->rbio != s->wbio)) | ||
| 282 | BIO_free_all(s->wbio); | ||
| 283 | s->rbio=rbio; | ||
| 284 | s->wbio=wbio; | ||
| 285 | } | ||
| 286 | |||
| 287 | BIO *SSL_get_rbio(s) | ||
| 288 | SSL *s; | ||
| 289 | { return(s->rbio); } | ||
| 290 | |||
| 291 | BIO *SSL_get_wbio(s) | ||
| 292 | SSL *s; | ||
| 293 | { return(s->wbio); } | ||
| 294 | |||
| 295 | int SSL_get_fd(s) | ||
| 296 | SSL *s; | ||
| 297 | { | ||
| 298 | int ret= -1; | ||
| 299 | BIO *b,*r; | ||
| 300 | |||
| 301 | b=SSL_get_rbio(s); | ||
| 302 | r=BIO_find_type(b,BIO_TYPE_DESCRIPTOR); | ||
| 303 | if (r != NULL) | ||
| 304 | BIO_get_fd(r,&ret); | ||
| 305 | return(ret); | ||
| 306 | } | ||
| 307 | |||
| 308 | #ifndef NO_SOCK | ||
| 309 | int SSL_set_fd(s, fd) | ||
| 310 | SSL *s; | ||
| 311 | int fd; | ||
| 312 | { | ||
| 313 | int ret=0; | ||
| 314 | BIO *bio=NULL; | ||
| 315 | |||
| 316 | bio=BIO_new(BIO_s_socket()); | ||
| 317 | |||
| 318 | if (bio == NULL) | ||
| 319 | { | ||
| 320 | SSLerr(SSL_F_SSL_SET_FD,ERR_R_BUF_LIB); | ||
| 321 | goto err; | ||
| 322 | } | ||
| 323 | BIO_set_fd(bio,fd,BIO_NOCLOSE); | ||
| 324 | SSL_set_bio(s,bio,bio); | ||
| 325 | ret=1; | ||
| 326 | err: | ||
| 327 | return(ret); | ||
| 328 | } | ||
| 329 | |||
| 330 | int SSL_set_wfd(s, fd) | ||
| 331 | SSL *s; | ||
| 332 | int fd; | ||
| 333 | { | ||
| 334 | int ret=0; | ||
| 335 | BIO *bio=NULL; | ||
| 336 | |||
| 337 | if ((s->rbio == NULL) || (BIO_method_type(s->rbio) != BIO_TYPE_SOCKET) | ||
| 338 | || ((int)BIO_get_fd(s->rbio,NULL) != fd)) | ||
| 339 | { | ||
| 340 | bio=BIO_new(BIO_s_socket()); | ||
| 341 | |||
| 342 | if (bio == NULL) | ||
| 343 | { SSLerr(SSL_F_SSL_SET_WFD,ERR_R_BUF_LIB); goto err; } | ||
| 344 | BIO_set_fd(bio,fd,BIO_NOCLOSE); | ||
| 345 | SSL_set_bio(s,SSL_get_rbio(s),bio); | ||
| 346 | } | ||
| 347 | else | ||
| 348 | SSL_set_bio(s,SSL_get_rbio(s),SSL_get_rbio(s)); | ||
| 349 | ret=1; | ||
| 350 | err: | ||
| 351 | return(ret); | ||
| 352 | } | ||
| 353 | |||
| 354 | int SSL_set_rfd(s, fd) | ||
| 355 | SSL *s; | ||
| 356 | int fd; | ||
| 357 | { | ||
| 358 | int ret=0; | ||
| 359 | BIO *bio=NULL; | ||
| 360 | |||
| 361 | if ((s->wbio == NULL) || (BIO_method_type(s->wbio) != BIO_TYPE_SOCKET) | ||
| 362 | || ((int)BIO_get_fd(s->wbio,NULL) != fd)) | ||
| 363 | { | ||
| 364 | bio=BIO_new(BIO_s_socket()); | ||
| 365 | |||
| 366 | if (bio == NULL) | ||
| 367 | { | ||
| 368 | SSLerr(SSL_F_SSL_SET_RFD,ERR_R_BUF_LIB); | ||
| 369 | goto err; | ||
| 370 | } | ||
| 371 | BIO_set_fd(bio,fd,BIO_NOCLOSE); | ||
| 372 | SSL_set_bio(s,bio,SSL_get_wbio(s)); | ||
| 373 | } | ||
| 374 | else | ||
| 375 | SSL_set_bio(s,SSL_get_wbio(s),SSL_get_wbio(s)); | ||
| 376 | ret=1; | ||
| 377 | err: | ||
| 378 | return(ret); | ||
| 379 | } | ||
| 380 | #endif | ||
| 381 | |||
| 382 | int SSL_get_verify_mode(s) | ||
| 383 | SSL *s; | ||
| 384 | { | ||
| 385 | return(s->verify_mode); | ||
| 386 | } | ||
| 387 | |||
| 388 | int (*SSL_get_verify_callback(s))() | ||
| 389 | SSL *s; | ||
| 390 | { | ||
| 391 | return(s->verify_callback); | ||
| 392 | } | ||
| 393 | |||
| 394 | int SSL_CTX_get_verify_mode(ctx) | ||
| 395 | SSL_CTX *ctx; | ||
| 396 | { | ||
| 397 | return(ctx->default_verify_mode); | ||
| 398 | } | ||
| 399 | |||
| 400 | int (*SSL_CTX_get_verify_callback(ctx))() | ||
| 401 | SSL_CTX *ctx; | ||
| 402 | { | ||
| 403 | return(ctx->default_verify_callback); | ||
| 404 | } | ||
| 405 | |||
| 406 | void SSL_set_verify(s, mode, callback) | ||
| 407 | SSL *s; | ||
| 408 | int mode; | ||
| 409 | int (*callback)(); | ||
| 410 | { | ||
| 411 | s->verify_mode=mode; | ||
| 412 | if (callback != NULL) | ||
| 413 | s->verify_callback=callback; | ||
| 414 | } | ||
| 415 | |||
| 416 | void SSL_set_read_ahead(s, yes) | ||
| 417 | SSL *s; | ||
| 418 | int yes; | ||
| 419 | { | ||
| 420 | s->read_ahead=yes; | ||
| 421 | } | ||
| 422 | |||
| 423 | int SSL_get_read_ahead(s) | ||
| 424 | SSL *s; | ||
| 425 | { | ||
| 426 | return(s->read_ahead); | ||
| 427 | } | ||
| 428 | |||
| 429 | int SSL_pending(s) | ||
| 430 | SSL *s; | ||
| 431 | { | ||
| 432 | return(s->method->ssl_pending(s)); | ||
| 433 | } | ||
| 434 | |||
| 435 | X509 *SSL_get_peer_certificate(s) | ||
| 436 | SSL *s; | ||
| 437 | { | ||
| 438 | X509 *r; | ||
| 439 | |||
| 440 | if ((s == NULL) || (s->session == NULL)) | ||
| 441 | r=NULL; | ||
| 442 | else | ||
| 443 | r=s->session->peer; | ||
| 444 | |||
| 445 | if (r == NULL) return(r); | ||
| 446 | |||
| 447 | CRYPTO_add(&r->references,1,CRYPTO_LOCK_X509); | ||
| 448 | |||
| 449 | return(r); | ||
| 450 | } | ||
| 451 | |||
| 452 | STACK *SSL_get_peer_cert_chain(s) | ||
| 453 | SSL *s; | ||
| 454 | { | ||
| 455 | STACK *r; | ||
| 456 | |||
| 457 | if ((s == NULL) || (s->session == NULL) || (s->session->cert == NULL)) | ||
| 458 | r=NULL; | ||
| 459 | else | ||
| 460 | r=s->session->cert->cert_chain; | ||
| 461 | |||
| 462 | return(r); | ||
| 463 | } | ||
| 464 | |||
| 465 | /* Now in theory, since the calling process own 't' it should be safe to | ||
| 466 | * modify. We need to be able to read f without being hassled */ | ||
| 467 | void SSL_copy_session_id(t,f) | ||
| 468 | SSL *t,*f; | ||
| 469 | { | ||
| 470 | CERT *tmp; | ||
| 471 | |||
| 472 | /* Do we need to to SSL locking? */ | ||
| 473 | SSL_set_session(t,SSL_get_session(f)); | ||
| 474 | |||
| 475 | /* what if we are setup as SSLv2 but want to talk SSLv3 or | ||
| 476 | * vice-versa */ | ||
| 477 | if (t->method != f->method) | ||
| 478 | { | ||
| 479 | t->method->ssl_free(t); /* cleanup current */ | ||
| 480 | t->method=f->method; /* change method */ | ||
| 481 | t->method->ssl_new(t); /* setup new */ | ||
| 482 | } | ||
| 483 | |||
| 484 | tmp=t->cert; | ||
| 485 | if (f->cert != NULL) | ||
| 486 | { | ||
| 487 | CRYPTO_add(&f->cert->references,1,CRYPTO_LOCK_SSL_CERT); | ||
| 488 | t->cert=f->cert; | ||
| 489 | } | ||
| 490 | else | ||
| 491 | t->cert=NULL; | ||
| 492 | if (tmp != NULL) ssl_cert_free(tmp); | ||
| 493 | } | ||
| 494 | |||
| 495 | /* Fix this so it checks all the valid key/cert options */ | ||
| 496 | int SSL_CTX_check_private_key(ctx) | ||
| 497 | SSL_CTX *ctx; | ||
| 498 | { | ||
| 499 | if ( (ctx == NULL) || | ||
| 500 | (ctx->default_cert == NULL) || | ||
| 501 | (ctx->default_cert->key->x509 == NULL)) | ||
| 502 | { | ||
| 503 | SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED); | ||
| 504 | return(0); | ||
| 505 | } | ||
| 506 | if (ctx->default_cert->key->privatekey == NULL) | ||
| 507 | { | ||
| 508 | SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,SSL_R_NO_PRIVATE_KEY_ASSIGNED); | ||
| 509 | return(0); | ||
| 510 | } | ||
| 511 | return(X509_check_private_key(ctx->default_cert->key->x509, ctx->default_cert->key->privatekey)); | ||
| 512 | } | ||
| 513 | |||
| 514 | /* Fix this function so that it takes an optional type parameter */ | ||
| 515 | int SSL_check_private_key(ssl) | ||
| 516 | SSL *ssl; | ||
| 517 | { | ||
| 518 | if (ssl == NULL) | ||
| 519 | { | ||
| 520 | SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,ERR_R_PASSED_NULL_PARAMETER); | ||
| 521 | return(0); | ||
| 522 | } | ||
| 523 | if (ssl->cert == NULL) | ||
| 524 | return(SSL_CTX_check_private_key(ssl->ctx)); | ||
| 525 | if (ssl->cert->key->x509 == NULL) | ||
| 526 | { | ||
| 527 | SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED); | ||
| 528 | return(0); | ||
| 529 | } | ||
| 530 | if (ssl->cert->key->privatekey == NULL) | ||
| 531 | { | ||
| 532 | SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_PRIVATE_KEY_ASSIGNED); | ||
| 533 | return(0); | ||
| 534 | } | ||
| 535 | return(X509_check_private_key(ssl->cert->key->x509, | ||
| 536 | ssl->cert->key->privatekey)); | ||
| 537 | } | ||
| 538 | |||
| 539 | int SSL_accept(s) | ||
| 540 | SSL *s; | ||
| 541 | { | ||
| 542 | return(s->method->ssl_accept(s)); | ||
| 543 | } | ||
| 544 | |||
| 545 | int SSL_connect(s) | ||
| 546 | SSL *s; | ||
| 547 | { | ||
| 548 | return(s->method->ssl_connect(s)); | ||
| 549 | } | ||
| 550 | |||
| 551 | long SSL_get_default_timeout(s) | ||
| 552 | SSL *s; | ||
| 553 | { | ||
| 554 | return(s->method->get_timeout()); | ||
| 555 | } | ||
| 556 | |||
| 557 | int SSL_read(s,buf,num) | ||
| 558 | SSL *s; | ||
| 559 | char *buf; | ||
| 560 | int num; | ||
| 561 | { | ||
| 562 | if (s->shutdown & SSL_RECEIVED_SHUTDOWN) | ||
| 563 | { | ||
| 564 | s->rwstate=SSL_NOTHING; | ||
| 565 | return(0); | ||
| 566 | } | ||
| 567 | return(s->method->ssl_read(s,buf,num)); | ||
| 568 | } | ||
| 569 | |||
| 570 | int SSL_peek(s,buf,num) | ||
| 571 | SSL *s; | ||
| 572 | char *buf; | ||
| 573 | int num; | ||
| 574 | { | ||
| 575 | if (s->shutdown & SSL_RECEIVED_SHUTDOWN) | ||
| 576 | { | ||
| 577 | return(0); | ||
| 578 | } | ||
| 579 | return(s->method->ssl_peek(s,buf,num)); | ||
| 580 | } | ||
| 581 | |||
| 582 | int SSL_write(s,buf,num) | ||
| 583 | SSL *s; | ||
| 584 | char *buf; | ||
| 585 | int num; | ||
| 586 | { | ||
| 587 | if (s->shutdown & SSL_SENT_SHUTDOWN) | ||
| 588 | { | ||
| 589 | s->rwstate=SSL_NOTHING; | ||
| 590 | SSLerr(SSL_F_SSL_WRITE,SSL_R_PROTOCOL_IS_SHUTDOWN); | ||
| 591 | return(-1); | ||
| 592 | } | ||
| 593 | return(s->method->ssl_write(s,buf,num)); | ||
| 594 | } | ||
| 595 | |||
| 596 | int SSL_shutdown(s) | ||
| 597 | SSL *s; | ||
| 598 | { | ||
| 599 | if ((s != NULL) && !SSL_in_init(s)) | ||
| 600 | return(s->method->ssl_shutdown(s)); | ||
| 601 | else | ||
| 602 | return(1); | ||
| 603 | } | ||
| 604 | |||
| 605 | int SSL_renegotiate(s) | ||
| 606 | SSL *s; | ||
| 607 | { | ||
| 608 | s->new_session=1; | ||
| 609 | return(s->method->ssl_renegotiate(s)); | ||
| 610 | } | ||
| 611 | |||
| 612 | long SSL_ctrl(s,cmd,larg,parg) | ||
| 613 | SSL *s; | ||
| 614 | int cmd; | ||
| 615 | long larg; | ||
| 616 | char *parg; | ||
| 617 | { | ||
| 618 | return(s->method->ssl_ctrl(s,cmd,larg,parg)); | ||
| 619 | } | ||
| 620 | |||
| 621 | long SSL_CTX_ctrl(ctx,cmd,larg,parg) | ||
| 622 | SSL_CTX *ctx; | ||
| 623 | int cmd; | ||
| 624 | long larg; | ||
| 625 | char *parg; | ||
| 626 | { | ||
| 627 | return(ctx->method->ssl_ctx_ctrl(ctx,cmd,larg,parg)); | ||
| 628 | } | ||
| 629 | |||
| 630 | int ssl_cipher_id_cmp(a,b) | ||
| 631 | SSL_CIPHER *a,*b; | ||
| 632 | { | ||
| 633 | long l; | ||
| 634 | |||
| 635 | l=a->id-b->id; | ||
| 636 | if (l == 0L) | ||
| 637 | return(0); | ||
| 638 | else | ||
| 639 | return((l > 0)?1:-1); | ||
| 640 | } | ||
| 641 | |||
| 642 | int ssl_cipher_ptr_id_cmp(ap,bp) | ||
| 643 | SSL_CIPHER **ap,**bp; | ||
| 644 | { | ||
| 645 | long l; | ||
| 646 | |||
| 647 | l=(*ap)->id-(*bp)->id; | ||
| 648 | if (l == 0L) | ||
| 649 | return(0); | ||
| 650 | else | ||
| 651 | return((l > 0)?1:-1); | ||
| 652 | } | ||
| 653 | |||
| 654 | /* return a STACK of the ciphers available for the SSL and in order of | ||
| 655 | * preference */ | ||
| 656 | STACK *SSL_get_ciphers(s) | ||
| 657 | SSL *s; | ||
| 658 | { | ||
| 659 | if ((s != NULL) && (s->cipher_list != NULL)) | ||
| 660 | { | ||
| 661 | return(s->cipher_list); | ||
| 662 | } | ||
| 663 | else if ((s->ctx != NULL) && | ||
| 664 | (s->ctx->cipher_list != NULL)) | ||
| 665 | { | ||
| 666 | return(s->ctx->cipher_list); | ||
| 667 | } | ||
| 668 | return(NULL); | ||
| 669 | } | ||
| 670 | |||
| 671 | /* return a STACK of the ciphers available for the SSL and in order of | ||
| 672 | * algorithm id */ | ||
| 673 | STACK *ssl_get_ciphers_by_id(s) | ||
| 674 | SSL *s; | ||
| 675 | { | ||
| 676 | if ((s != NULL) && (s->cipher_list_by_id != NULL)) | ||
| 677 | { | ||
| 678 | return(s->cipher_list_by_id); | ||
| 679 | } | ||
| 680 | else if ((s != NULL) && (s->ctx != NULL) && | ||
| 681 | (s->ctx->cipher_list_by_id != NULL)) | ||
| 682 | { | ||
| 683 | return(s->ctx->cipher_list_by_id); | ||
| 684 | } | ||
| 685 | return(NULL); | ||
| 686 | } | ||
| 687 | |||
| 688 | /* The old interface to get the same thing as SSL_get_ciphers() */ | ||
| 689 | char *SSL_get_cipher_list(s,n) | ||
| 690 | SSL *s; | ||
| 691 | int n; | ||
| 692 | { | ||
| 693 | SSL_CIPHER *c; | ||
| 694 | STACK *sk; | ||
| 695 | |||
| 696 | if (s == NULL) return(NULL); | ||
| 697 | sk=SSL_get_ciphers(s); | ||
| 698 | if ((sk == NULL) || (sk_num(sk) <= n)) | ||
| 699 | return(NULL); | ||
| 700 | c=(SSL_CIPHER *)sk_value(sk,n); | ||
| 701 | if (c == NULL) return(NULL); | ||
| 702 | return(c->name); | ||
| 703 | } | ||
| 704 | |||
| 705 | /* specify the ciphers to be used by defaut by the SSL_CTX */ | ||
| 706 | int SSL_CTX_set_cipher_list(ctx,str) | ||
| 707 | SSL_CTX *ctx; | ||
| 708 | char *str; | ||
| 709 | { | ||
| 710 | STACK *sk; | ||
| 711 | |||
| 712 | sk=ssl_create_cipher_list(ctx->method,&ctx->cipher_list, | ||
| 713 | &ctx->cipher_list_by_id,str); | ||
| 714 | /* XXXX */ | ||
| 715 | return((sk == NULL)?0:1); | ||
| 716 | } | ||
| 717 | |||
| 718 | /* specify the ciphers to be used by the SSL */ | ||
| 719 | int SSL_set_cipher_list(s, str) | ||
| 720 | SSL *s; | ||
| 721 | char *str; | ||
| 722 | { | ||
| 723 | STACK *sk; | ||
| 724 | |||
| 725 | sk=ssl_create_cipher_list(s->ctx->method,&s->cipher_list, | ||
| 726 | &s->cipher_list_by_id,str); | ||
| 727 | /* XXXX */ | ||
| 728 | return((sk == NULL)?0:1); | ||
| 729 | } | ||
| 730 | |||
| 731 | /* works well for SSLv2, not so good for SSLv3 */ | ||
| 732 | char *SSL_get_shared_ciphers(s,buf,len) | ||
| 733 | SSL *s; | ||
| 734 | char *buf; | ||
| 735 | int len; | ||
| 736 | { | ||
| 737 | char *p,*cp; | ||
| 738 | STACK *sk; | ||
| 739 | SSL_CIPHER *c; | ||
| 740 | int i; | ||
| 741 | |||
| 742 | if ((s->session == NULL) || (s->session->ciphers == NULL) || | ||
| 743 | (len < 2)) | ||
| 744 | return(NULL); | ||
| 745 | |||
| 746 | p=buf; | ||
| 747 | sk=s->session->ciphers; | ||
| 748 | for (i=0; i<sk_num(sk); i++) | ||
| 749 | { | ||
| 750 | /* Decrement for either the ':' or a '\0' */ | ||
| 751 | len--; | ||
| 752 | c=(SSL_CIPHER *)sk_value(sk,i); | ||
| 753 | for (cp=c->name; *cp; ) | ||
| 754 | { | ||
| 755 | if (len-- == 0) | ||
| 756 | { | ||
| 757 | *p='\0'; | ||
| 758 | return(buf); | ||
| 759 | } | ||
| 760 | else | ||
| 761 | *(p++)= *(cp++); | ||
| 762 | } | ||
| 763 | *(p++)=':'; | ||
| 764 | } | ||
| 765 | p[-1]='\0'; | ||
| 766 | return(buf); | ||
| 767 | } | ||
| 768 | |||
| 769 | int ssl_cipher_list_to_bytes(s,sk,p) | ||
| 770 | SSL *s; | ||
| 771 | STACK *sk; | ||
| 772 | unsigned char *p; | ||
| 773 | { | ||
| 774 | int i,j=0; | ||
| 775 | SSL_CIPHER *c; | ||
| 776 | unsigned char *q; | ||
| 777 | |||
| 778 | if (sk == NULL) return(0); | ||
| 779 | q=p; | ||
| 780 | |||
| 781 | for (i=0; i<sk_num(sk); i++) | ||
| 782 | { | ||
| 783 | c=(SSL_CIPHER *)sk_value(sk,i); | ||
| 784 | j=ssl_put_cipher_by_char(s,c,p); | ||
| 785 | p+=j; | ||
| 786 | } | ||
| 787 | return(p-q); | ||
| 788 | } | ||
| 789 | |||
| 790 | STACK *ssl_bytes_to_cipher_list(s,p,num,skp) | ||
| 791 | SSL *s; | ||
| 792 | unsigned char *p; | ||
| 793 | int num; | ||
| 794 | STACK **skp; | ||
| 795 | { | ||
| 796 | SSL_CIPHER *c; | ||
| 797 | STACK *sk; | ||
| 798 | int i,n; | ||
| 799 | |||
| 800 | n=ssl_put_cipher_by_char(s,NULL,NULL); | ||
| 801 | if ((num%n) != 0) | ||
| 802 | { | ||
| 803 | SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST); | ||
| 804 | return(NULL); | ||
| 805 | } | ||
| 806 | if ((skp == NULL) || (*skp == NULL)) | ||
| 807 | sk=sk_new(NULL); /* change perhaps later */ | ||
| 808 | else | ||
| 809 | { | ||
| 810 | sk= *skp; | ||
| 811 | sk_zero(sk); | ||
| 812 | } | ||
| 813 | |||
| 814 | for (i=0; i<num; i+=n) | ||
| 815 | { | ||
| 816 | c=ssl_get_cipher_by_char(s,p); | ||
| 817 | p+=n; | ||
| 818 | if (c != NULL) | ||
| 819 | { | ||
| 820 | if (!sk_push(sk,(char *)c)) | ||
| 821 | { | ||
| 822 | SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,ERR_R_MALLOC_FAILURE); | ||
| 823 | goto err; | ||
| 824 | } | ||
| 825 | } | ||
| 826 | } | ||
| 827 | |||
| 828 | if (skp != NULL) | ||
| 829 | *skp=sk; | ||
| 830 | return(sk); | ||
| 831 | err: | ||
| 832 | if ((skp == NULL) || (*skp == NULL)) | ||
| 833 | sk_free(sk); | ||
| 834 | return(NULL); | ||
| 835 | } | ||
| 836 | |||
| 837 | unsigned long SSL_SESSION_hash(a) | ||
| 838 | SSL_SESSION *a; | ||
| 839 | { | ||
| 840 | unsigned long l; | ||
| 841 | |||
| 842 | l= (a->session_id[0] )|(a->session_id[1]<< 8L)| | ||
| 843 | (a->session_id[2]<<16L)|(a->session_id[3]<<24L); | ||
| 844 | return(l); | ||
| 845 | } | ||
| 846 | |||
| 847 | int SSL_SESSION_cmp(a, b) | ||
| 848 | SSL_SESSION *a; | ||
| 849 | SSL_SESSION *b; | ||
| 850 | { | ||
| 851 | if (a->ssl_version != b->ssl_version) | ||
| 852 | return(1); | ||
| 853 | if (a->session_id_length != b->session_id_length) | ||
| 854 | return(1); | ||
| 855 | return(memcmp(a->session_id,b->session_id,a->session_id_length)); | ||
| 856 | } | ||
| 857 | |||
| 858 | SSL_CTX *SSL_CTX_new(meth) | ||
| 859 | SSL_METHOD *meth; | ||
| 860 | { | ||
| 861 | SSL_CTX *ret; | ||
| 862 | |||
| 863 | if (meth == NULL) | ||
| 864 | { | ||
| 865 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_NULL_SSL_METHOD_PASSED); | ||
| 866 | return(NULL); | ||
| 867 | } | ||
| 868 | ret=(SSL_CTX *)Malloc(sizeof(SSL_CTX)); | ||
| 869 | if (ret == NULL) | ||
| 870 | goto err; | ||
| 871 | |||
| 872 | memset(ret,0,sizeof(SSL_CTX)); | ||
| 873 | |||
| 874 | ret->method=meth; | ||
| 875 | |||
| 876 | ret->cert_store=NULL; | ||
| 877 | ret->session_cache_mode=SSL_SESS_CACHE_SERVER; | ||
| 878 | ret->session_cache_size=SSL_SESSION_CACHE_MAX_SIZE_DEFAULT; | ||
| 879 | ret->session_cache_head=NULL; | ||
| 880 | ret->session_cache_tail=NULL; | ||
| 881 | |||
| 882 | /* We take the system default */ | ||
| 883 | ret->session_timeout=meth->get_timeout(); | ||
| 884 | |||
| 885 | ret->new_session_cb=NULL; | ||
| 886 | ret->remove_session_cb=NULL; | ||
| 887 | ret->get_session_cb=NULL; | ||
| 888 | |||
| 889 | ret->sess_connect=0; | ||
| 890 | ret->sess_connect_good=0; | ||
| 891 | ret->sess_accept=0; | ||
| 892 | ret->sess_accept_renegotiate=0; | ||
| 893 | ret->sess_connect_renegotiate=0; | ||
| 894 | ret->sess_accept_good=0; | ||
| 895 | ret->sess_miss=0; | ||
| 896 | ret->sess_timeout=0; | ||
| 897 | ret->sess_cache_full=0; | ||
| 898 | ret->sess_hit=0; | ||
| 899 | ret->sess_cb_hit=0; | ||
| 900 | |||
| 901 | ret->references=1; | ||
| 902 | ret->quiet_shutdown=0; | ||
| 903 | |||
| 904 | /* ret->cipher=NULL;*/ | ||
| 905 | /* ret->s2->challenge=NULL; | ||
| 906 | ret->master_key=NULL; | ||
| 907 | ret->key_arg=NULL; | ||
| 908 | ret->s2->conn_id=NULL; */ | ||
| 909 | |||
| 910 | ret->info_callback=NULL; | ||
| 911 | |||
| 912 | ret->app_verify_callback=NULL; | ||
| 913 | ret->app_verify_arg=NULL; | ||
| 914 | |||
| 915 | ret->default_read_ahead=0; | ||
| 916 | ret->default_verify_mode=SSL_VERIFY_NONE; | ||
| 917 | ret->default_verify_callback=NULL; | ||
| 918 | if ((ret->default_cert=ssl_cert_new()) == NULL) | ||
| 919 | goto err; | ||
| 920 | |||
| 921 | ret->default_passwd_callback=NULL; | ||
| 922 | ret->client_cert_cb=NULL; | ||
| 923 | |||
| 924 | ret->sessions=lh_new(SSL_SESSION_hash,SSL_SESSION_cmp); | ||
| 925 | if (ret->sessions == NULL) goto err; | ||
| 926 | ret->cert_store=X509_STORE_new(); | ||
| 927 | if (ret->cert_store == NULL) goto err; | ||
| 928 | |||
| 929 | ssl_create_cipher_list(ret->method, | ||
| 930 | &ret->cipher_list,&ret->cipher_list_by_id, | ||
| 931 | SSL_DEFAULT_CIPHER_LIST); | ||
| 932 | if ((ret->cipher_list == NULL) || (sk_num(ret->cipher_list) <= 0)) | ||
| 933 | { | ||
| 934 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_LIBRARY_HAS_NO_CIPHERS); | ||
| 935 | goto err2; | ||
| 936 | } | ||
| 937 | |||
| 938 | if ((ret->rsa_md5=EVP_get_digestbyname("ssl2-md5")) == NULL) | ||
| 939 | { | ||
| 940 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES); | ||
| 941 | goto err2; | ||
| 942 | } | ||
| 943 | if ((ret->md5=EVP_get_digestbyname("ssl3-md5")) == NULL) | ||
| 944 | { | ||
| 945 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES); | ||
| 946 | goto err2; | ||
| 947 | } | ||
| 948 | if ((ret->sha1=EVP_get_digestbyname("ssl3-sha1")) == NULL) | ||
| 949 | { | ||
| 950 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES); | ||
| 951 | goto err2; | ||
| 952 | } | ||
| 953 | |||
| 954 | if ((ret->client_CA=sk_new_null()) == NULL) | ||
| 955 | goto err; | ||
| 956 | |||
| 957 | CRYPTO_new_ex_data(ssl_ctx_meth,(char *)ret,&ret->ex_data); | ||
| 958 | |||
| 959 | return(ret); | ||
| 960 | err: | ||
| 961 | SSLerr(SSL_F_SSL_CTX_NEW,ERR_R_MALLOC_FAILURE); | ||
| 962 | err2: | ||
| 963 | if (ret != NULL) SSL_CTX_free(ret); | ||
| 964 | return(NULL); | ||
| 965 | } | ||
| 966 | |||
| 967 | void SSL_CTX_free(a) | ||
| 968 | SSL_CTX *a; | ||
| 969 | { | ||
| 970 | int i; | ||
| 971 | |||
| 972 | if (a == NULL) return; | ||
| 973 | |||
| 974 | i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_SSL_CTX); | ||
| 975 | #ifdef REF_PRINT | ||
| 976 | REF_PRINT("SSL_CTX",a); | ||
| 977 | #endif | ||
| 978 | if (i > 0) return; | ||
| 979 | #ifdef REF_CHECK | ||
| 980 | if (i < 0) | ||
| 981 | { | ||
| 982 | fprintf(stderr,"SSL_CTX_free, bad reference count\n"); | ||
| 983 | abort(); /* ok */ | ||
| 984 | } | ||
| 985 | #endif | ||
| 986 | CRYPTO_free_ex_data(ssl_ctx_meth,(char *)a,&a->ex_data); | ||
| 987 | |||
| 988 | if (a->sessions != NULL) | ||
| 989 | { | ||
| 990 | SSL_CTX_flush_sessions(a,0); | ||
| 991 | lh_free(a->sessions); | ||
| 992 | } | ||
| 993 | if (a->cert_store != NULL) | ||
| 994 | X509_STORE_free(a->cert_store); | ||
| 995 | if (a->cipher_list != NULL) | ||
| 996 | sk_free(a->cipher_list); | ||
| 997 | if (a->cipher_list_by_id != NULL) | ||
| 998 | sk_free(a->cipher_list_by_id); | ||
| 999 | if (a->default_cert != NULL) | ||
| 1000 | ssl_cert_free(a->default_cert); | ||
| 1001 | if (a->client_CA != NULL) | ||
| 1002 | sk_pop_free(a->client_CA,X509_NAME_free); | ||
| 1003 | Free((char *)a); | ||
| 1004 | } | ||
| 1005 | |||
| 1006 | void SSL_CTX_set_default_passwd_cb(ctx,cb) | ||
| 1007 | SSL_CTX *ctx; | ||
| 1008 | int (*cb)(); | ||
| 1009 | { | ||
| 1010 | ctx->default_passwd_callback=cb; | ||
| 1011 | } | ||
| 1012 | |||
| 1013 | void SSL_CTX_set_cert_verify_cb(ctx,cb,arg) | ||
| 1014 | SSL_CTX *ctx; | ||
| 1015 | int (*cb)(); | ||
| 1016 | char *arg; | ||
| 1017 | { | ||
| 1018 | ctx->app_verify_callback=cb; | ||
| 1019 | ctx->app_verify_arg=arg; | ||
| 1020 | } | ||
| 1021 | |||
| 1022 | void SSL_CTX_set_verify(ctx,mode,cb) | ||
| 1023 | SSL_CTX *ctx; | ||
| 1024 | int mode; | ||
| 1025 | int (*cb)(); | ||
| 1026 | { | ||
| 1027 | ctx->default_verify_mode=mode; | ||
| 1028 | ctx->default_verify_callback=cb; | ||
| 1029 | /* This needs cleaning up EAY EAY EAY */ | ||
| 1030 | X509_STORE_set_verify_cb_func(ctx->cert_store,cb); | ||
| 1031 | } | ||
| 1032 | |||
| 1033 | void ssl_set_cert_masks(c) | ||
| 1034 | CERT *c; | ||
| 1035 | { | ||
| 1036 | CERT_PKEY *cpk; | ||
| 1037 | int rsa_enc,rsa_tmp,rsa_sign,dh_tmp,dh_rsa,dh_dsa,dsa_sign; | ||
| 1038 | int rsa_enc_export,dh_rsa_export,dh_dsa_export; | ||
| 1039 | int rsa_tmp_export,dh_tmp_export; | ||
| 1040 | unsigned long mask,emask; | ||
| 1041 | |||
| 1042 | if ((c == NULL) || (c->valid)) return; | ||
| 1043 | |||
| 1044 | #ifndef NO_RSA | ||
| 1045 | rsa_tmp=((c->rsa_tmp != NULL) || (c->rsa_tmp_cb != NULL))?1:0; | ||
| 1046 | rsa_tmp_export=((c->rsa_tmp_cb != NULL) || | ||
| 1047 | (rsa_tmp && (RSA_size(c->rsa_tmp)*8 <= 512)))?1:0; | ||
| 1048 | #else | ||
| 1049 | rsa_tmp=rsa_tmp_export=0; | ||
| 1050 | #endif | ||
| 1051 | #ifndef NO_DH | ||
| 1052 | dh_tmp=((c->dh_tmp != NULL) || (c->dh_tmp_cb != NULL))?1:0; | ||
| 1053 | dh_tmp_export=((c->dh_tmp_cb != NULL) || | ||
| 1054 | (dh_tmp && (DH_size(c->dh_tmp)*8 <= 512)))?1:0; | ||
| 1055 | #else | ||
| 1056 | dh_tmp=dh_tmp_export=0; | ||
| 1057 | #endif | ||
| 1058 | |||
| 1059 | cpk= &(c->pkeys[SSL_PKEY_RSA_ENC]); | ||
| 1060 | rsa_enc= ((cpk->x509 != NULL) && (cpk->privatekey != NULL))?1:0; | ||
| 1061 | rsa_enc_export=(rsa_enc && (EVP_PKEY_size(cpk->privatekey)*8 <= 512))?1:0; | ||
| 1062 | cpk= &(c->pkeys[SSL_PKEY_RSA_SIGN]); | ||
| 1063 | rsa_sign=((cpk->x509 != NULL) && (cpk->privatekey != NULL))?1:0; | ||
| 1064 | cpk= &(c->pkeys[SSL_PKEY_DSA_SIGN]); | ||
| 1065 | dsa_sign=((cpk->x509 != NULL) && (cpk->privatekey != NULL))?1:0; | ||
| 1066 | cpk= &(c->pkeys[SSL_PKEY_DH_RSA]); | ||
| 1067 | dh_rsa= ((cpk->x509 != NULL) && (cpk->privatekey != NULL))?1:0; | ||
| 1068 | dh_rsa_export=(dh_rsa && (EVP_PKEY_size(cpk->privatekey)*8 <= 512))?1:0; | ||
| 1069 | cpk= &(c->pkeys[SSL_PKEY_DH_DSA]); | ||
| 1070 | /* FIX THIS EAY EAY EAY */ | ||
| 1071 | dh_dsa= ((cpk->x509 != NULL) && (cpk->privatekey != NULL))?1:0; | ||
| 1072 | dh_dsa_export=(dh_dsa && (EVP_PKEY_size(cpk->privatekey)*8 <= 512))?1:0; | ||
| 1073 | |||
| 1074 | mask=0; | ||
| 1075 | emask=0; | ||
| 1076 | |||
| 1077 | #ifdef CIPHER_DEBUG | ||
| 1078 | printf("rt=%d dht=%d re=%d rs=%d ds=%d dhr=%d dhd=%d\n", | ||
| 1079 | rsa_tmp,dh_tmp, | ||
| 1080 | rsa_enc,rsa_sign,dsa_sign,dh_rsa,dh_dsa); | ||
| 1081 | #endif | ||
| 1082 | |||
| 1083 | if (rsa_enc || (rsa_tmp && rsa_sign)) | ||
| 1084 | mask|=SSL_kRSA; | ||
| 1085 | if (rsa_enc_export || (rsa_tmp_export && rsa_sign)) | ||
| 1086 | emask|=SSL_kRSA; | ||
| 1087 | |||
| 1088 | #if 0 | ||
| 1089 | /* The match needs to be both kEDH and aRSA or aDSA, so don't worry */ | ||
| 1090 | if ( (dh_tmp || dh_rsa || dh_dsa) && | ||
| 1091 | (rsa_enc || rsa_sign || dsa_sign)) | ||
| 1092 | mask|=SSL_kEDH; | ||
| 1093 | if ((dh_tmp_export || dh_rsa_export || dh_dsa_export) && | ||
| 1094 | (rsa_enc || rsa_sign || dsa_sign)) | ||
| 1095 | emask|=SSL_kEDH; | ||
| 1096 | #endif | ||
| 1097 | |||
| 1098 | if (dh_tmp_export) | ||
| 1099 | emask|=SSL_kEDH; | ||
| 1100 | |||
| 1101 | if (dh_tmp) | ||
| 1102 | mask|=SSL_kEDH; | ||
| 1103 | |||
| 1104 | if (dh_rsa) mask|=SSL_kDHr; | ||
| 1105 | if (dh_rsa_export) emask|=SSL_kDHr; | ||
| 1106 | |||
| 1107 | if (dh_dsa) mask|=SSL_kDHd; | ||
| 1108 | if (dh_dsa_export) emask|=SSL_kDHd; | ||
| 1109 | |||
| 1110 | if (rsa_enc || rsa_sign) | ||
| 1111 | { | ||
| 1112 | mask|=SSL_aRSA; | ||
| 1113 | emask|=SSL_aRSA; | ||
| 1114 | } | ||
| 1115 | |||
| 1116 | if (dsa_sign) | ||
| 1117 | { | ||
| 1118 | mask|=SSL_aDSS; | ||
| 1119 | emask|=SSL_aDSS; | ||
| 1120 | } | ||
| 1121 | |||
| 1122 | #ifdef SSL_ALLOW_ADH | ||
| 1123 | mask|=SSL_aNULL; | ||
| 1124 | emask|=SSL_aNULL; | ||
| 1125 | #endif | ||
| 1126 | |||
| 1127 | c->mask=mask; | ||
| 1128 | c->export_mask=emask; | ||
| 1129 | c->valid=1; | ||
| 1130 | } | ||
| 1131 | |||
| 1132 | /* THIS NEEDS CLEANING UP */ | ||
| 1133 | X509 *ssl_get_server_send_cert(s) | ||
| 1134 | SSL *s; | ||
| 1135 | { | ||
| 1136 | unsigned long alg,mask,kalg; | ||
| 1137 | CERT *c; | ||
| 1138 | int i,export; | ||
| 1139 | |||
| 1140 | c=s->cert; | ||
| 1141 | ssl_set_cert_masks(c); | ||
| 1142 | alg=s->s3->tmp.new_cipher->algorithms; | ||
| 1143 | export=(alg & SSL_EXPORT)?1:0; | ||
| 1144 | mask=(export)?c->export_mask:c->mask; | ||
| 1145 | kalg=alg&(SSL_MKEY_MASK|SSL_AUTH_MASK); | ||
| 1146 | |||
| 1147 | if (kalg & SSL_kDHr) | ||
| 1148 | i=SSL_PKEY_DH_RSA; | ||
| 1149 | else if (kalg & SSL_kDHd) | ||
| 1150 | i=SSL_PKEY_DH_DSA; | ||
| 1151 | else if (kalg & SSL_aDSS) | ||
| 1152 | i=SSL_PKEY_DSA_SIGN; | ||
| 1153 | else if (kalg & SSL_aRSA) | ||
| 1154 | { | ||
| 1155 | if (c->pkeys[SSL_PKEY_RSA_ENC].x509 == NULL) | ||
| 1156 | i=SSL_PKEY_RSA_SIGN; | ||
| 1157 | else | ||
| 1158 | i=SSL_PKEY_RSA_ENC; | ||
| 1159 | } | ||
| 1160 | else /* if (kalg & SSL_aNULL) */ | ||
| 1161 | { | ||
| 1162 | SSLerr(SSL_F_SSL_GET_SERVER_SEND_CERT,SSL_R_INTERNAL_ERROR); | ||
| 1163 | return(NULL); | ||
| 1164 | } | ||
| 1165 | if (c->pkeys[i].x509 == NULL) return(NULL); | ||
| 1166 | return(c->pkeys[i].x509); | ||
| 1167 | } | ||
| 1168 | |||
| 1169 | EVP_PKEY *ssl_get_sign_pkey(s,cipher) | ||
| 1170 | SSL *s; | ||
| 1171 | SSL_CIPHER *cipher; | ||
| 1172 | { | ||
| 1173 | unsigned long alg; | ||
| 1174 | CERT *c; | ||
| 1175 | |||
| 1176 | alg=cipher->algorithms; | ||
| 1177 | c=s->cert; | ||
| 1178 | |||
| 1179 | if ((alg & SSL_aDSS) && | ||
| 1180 | (c->pkeys[SSL_PKEY_DSA_SIGN].privatekey != NULL)) | ||
| 1181 | return(c->pkeys[SSL_PKEY_DSA_SIGN].privatekey); | ||
| 1182 | else if (alg & SSL_aRSA) | ||
| 1183 | { | ||
| 1184 | if (c->pkeys[SSL_PKEY_RSA_SIGN].privatekey != NULL) | ||
| 1185 | return(c->pkeys[SSL_PKEY_RSA_SIGN].privatekey); | ||
| 1186 | else if (c->pkeys[SSL_PKEY_RSA_ENC].privatekey != NULL) | ||
| 1187 | return(c->pkeys[SSL_PKEY_RSA_ENC].privatekey); | ||
| 1188 | else | ||
| 1189 | return(NULL); | ||
| 1190 | } | ||
| 1191 | else /* if (alg & SSL_aNULL) */ | ||
| 1192 | { | ||
| 1193 | SSLerr(SSL_F_SSL_GET_SIGN_PKEY,SSL_R_INTERNAL_ERROR); | ||
| 1194 | return(NULL); | ||
| 1195 | } | ||
| 1196 | } | ||
| 1197 | |||
| 1198 | void ssl_update_cache(s,mode) | ||
| 1199 | SSL *s; | ||
| 1200 | int mode; | ||
| 1201 | { | ||
| 1202 | int i; | ||
| 1203 | |||
| 1204 | /* If the session_id_length is 0, we are not supposed to cache it, | ||
| 1205 | * and it would be rather hard to do anyway :-) */ | ||
| 1206 | if (s->session->session_id_length == 0) return; | ||
| 1207 | |||
| 1208 | if ((s->ctx->session_cache_mode & mode) | ||
| 1209 | && (!s->hit) | ||
| 1210 | && SSL_CTX_add_session(s->ctx,s->session) | ||
| 1211 | && (s->ctx->new_session_cb != NULL)) | ||
| 1212 | { | ||
| 1213 | CRYPTO_add(&s->session->references,1,CRYPTO_LOCK_SSL_SESSION); | ||
| 1214 | if (!s->ctx->new_session_cb(s,s->session)) | ||
| 1215 | SSL_SESSION_free(s->session); | ||
| 1216 | } | ||
| 1217 | |||
| 1218 | /* auto flush every 255 connections */ | ||
| 1219 | i=s->ctx->session_cache_mode; | ||
| 1220 | if ((!(i & SSL_SESS_CACHE_NO_AUTO_CLEAR)) && | ||
| 1221 | ((i & mode) == mode)) | ||
| 1222 | { | ||
| 1223 | if ( (((mode & SSL_SESS_CACHE_CLIENT) | ||
| 1224 | ?s->ctx->sess_connect_good | ||
| 1225 | :s->ctx->sess_accept_good) & 0xff) == 0xff) | ||
| 1226 | { | ||
| 1227 | SSL_CTX_flush_sessions(s->ctx,time(NULL)); | ||
| 1228 | } | ||
| 1229 | } | ||
| 1230 | } | ||
| 1231 | |||
| 1232 | SSL_METHOD *SSL_get_ssl_method(s) | ||
| 1233 | SSL *s; | ||
| 1234 | { | ||
| 1235 | return(s->method); | ||
| 1236 | } | ||
| 1237 | |||
| 1238 | int SSL_set_ssl_method(s,meth) | ||
| 1239 | SSL *s; | ||
| 1240 | SSL_METHOD *meth; | ||
| 1241 | { | ||
| 1242 | int conn= -1; | ||
| 1243 | int ret=1; | ||
| 1244 | |||
| 1245 | if (s->method != meth) | ||
| 1246 | { | ||
| 1247 | if (s->handshake_func != NULL) | ||
| 1248 | conn=(s->handshake_func == s->method->ssl_connect); | ||
| 1249 | |||
| 1250 | if (s->method->version == meth->version) | ||
| 1251 | s->method=meth; | ||
| 1252 | else | ||
| 1253 | { | ||
| 1254 | s->method->ssl_free(s); | ||
| 1255 | s->method=meth; | ||
| 1256 | ret=s->method->ssl_new(s); | ||
| 1257 | } | ||
| 1258 | |||
| 1259 | if (conn == 1) | ||
| 1260 | s->handshake_func=meth->ssl_connect; | ||
| 1261 | else if (conn == 0) | ||
| 1262 | s->handshake_func=meth->ssl_accept; | ||
| 1263 | } | ||
| 1264 | return(ret); | ||
| 1265 | } | ||
| 1266 | |||
| 1267 | int SSL_get_error(s,i) | ||
| 1268 | SSL *s; | ||
| 1269 | int i; | ||
| 1270 | { | ||
| 1271 | int reason; | ||
| 1272 | BIO *bio; | ||
| 1273 | |||
| 1274 | if (i > 0) return(SSL_ERROR_NONE); | ||
| 1275 | |||
| 1276 | if (ERR_peek_error() != 0) | ||
| 1277 | return(SSL_ERROR_SSL); | ||
| 1278 | |||
| 1279 | if ((i < 0) && SSL_want_read(s)) | ||
| 1280 | { | ||
| 1281 | bio=SSL_get_rbio(s); | ||
| 1282 | if (BIO_should_read(bio)) | ||
| 1283 | return(SSL_ERROR_WANT_READ); | ||
| 1284 | else if (BIO_should_write(bio)) | ||
| 1285 | return(SSL_ERROR_WANT_WRITE); | ||
| 1286 | else if (BIO_should_io_special(bio)) | ||
| 1287 | { | ||
| 1288 | reason=BIO_get_retry_reason(bio); | ||
| 1289 | if (reason == BIO_RR_CONNECT) | ||
| 1290 | return(SSL_ERROR_WANT_CONNECT); | ||
| 1291 | else | ||
| 1292 | return(SSL_ERROR_SYSCALL); /* unknown */ | ||
| 1293 | } | ||
| 1294 | } | ||
| 1295 | |||
| 1296 | if ((i < 0) && SSL_want_write(s)) | ||
| 1297 | { | ||
| 1298 | bio=SSL_get_wbio(s); | ||
| 1299 | if (BIO_should_write(bio)) | ||
| 1300 | return(SSL_ERROR_WANT_WRITE); | ||
| 1301 | else if (BIO_should_read(bio)) | ||
| 1302 | return(SSL_ERROR_WANT_READ); | ||
| 1303 | else if (BIO_should_io_special(bio)) | ||
| 1304 | { | ||
| 1305 | reason=BIO_get_retry_reason(bio); | ||
| 1306 | if (reason == BIO_RR_CONNECT) | ||
| 1307 | return(SSL_ERROR_WANT_CONNECT); | ||
| 1308 | else | ||
| 1309 | return(SSL_ERROR_SYSCALL); | ||
| 1310 | } | ||
| 1311 | } | ||
| 1312 | if ((i < 0) && SSL_want_x509_lookup(s)) | ||
| 1313 | { | ||
| 1314 | return(SSL_ERROR_WANT_X509_LOOKUP); | ||
| 1315 | } | ||
| 1316 | |||
| 1317 | if (i == 0) | ||
| 1318 | { | ||
| 1319 | if (s->version == SSL2_VERSION) | ||
| 1320 | { | ||
| 1321 | /* assume it is the socket being closed */ | ||
| 1322 | return(SSL_ERROR_ZERO_RETURN); | ||
| 1323 | } | ||
| 1324 | else | ||
| 1325 | { | ||
| 1326 | if ((s->shutdown & SSL_RECEIVED_SHUTDOWN) && | ||
| 1327 | (s->s3->warn_alert == SSL_AD_CLOSE_NOTIFY)) | ||
| 1328 | return(SSL_ERROR_ZERO_RETURN); | ||
| 1329 | } | ||
| 1330 | } | ||
| 1331 | return(SSL_ERROR_SYSCALL); | ||
| 1332 | } | ||
| 1333 | |||
| 1334 | int SSL_do_handshake(s) | ||
| 1335 | SSL *s; | ||
| 1336 | { | ||
| 1337 | int ret=1; | ||
| 1338 | |||
| 1339 | if (s->handshake_func == NULL) | ||
| 1340 | { | ||
| 1341 | SSLerr(SSL_F_SSL_DO_HANDSHAKE,SSL_R_CONNECTION_TYPE_NOT_SET); | ||
| 1342 | return(-1); | ||
| 1343 | } | ||
| 1344 | if (s->s3->renegotiate) ssl3_renegotiate_check(s); | ||
| 1345 | if (SSL_in_init(s) || SSL_in_before(s)) | ||
| 1346 | { | ||
| 1347 | ret=s->handshake_func(s); | ||
| 1348 | } | ||
| 1349 | return(ret); | ||
| 1350 | } | ||
| 1351 | |||
| 1352 | /* For the next 2 functions, SSL_clear() sets shutdown and so | ||
| 1353 | * one of these calls will reset it */ | ||
| 1354 | void SSL_set_accept_state(s) | ||
| 1355 | SSL *s; | ||
| 1356 | { | ||
| 1357 | s->shutdown=0; | ||
| 1358 | s->state=SSL_ST_ACCEPT|SSL_ST_BEFORE; | ||
| 1359 | s->handshake_func=s->method->ssl_accept; | ||
| 1360 | /* clear the current cipher */ | ||
| 1361 | ssl_clear_cipher_ctx(s); | ||
| 1362 | } | ||
| 1363 | |||
| 1364 | void SSL_set_connect_state(s) | ||
| 1365 | SSL *s; | ||
| 1366 | { | ||
| 1367 | s->shutdown=0; | ||
| 1368 | s->state=SSL_ST_CONNECT|SSL_ST_BEFORE; | ||
| 1369 | s->handshake_func=s->method->ssl_connect; | ||
| 1370 | /* clear the current cipher */ | ||
| 1371 | ssl_clear_cipher_ctx(s); | ||
| 1372 | } | ||
| 1373 | |||
| 1374 | int ssl_undefined_function(s) | ||
| 1375 | SSL *s; | ||
| 1376 | { | ||
| 1377 | SSLerr(SSL_F_SSL_UNDEFINED_FUNCTION,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
| 1378 | return(0); | ||
| 1379 | } | ||
| 1380 | |||
| 1381 | SSL_METHOD *ssl_bad_method(ver) | ||
| 1382 | int ver; | ||
| 1383 | { | ||
| 1384 | SSLerr(SSL_F_SSL_BAD_METHOD,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
| 1385 | return(NULL); | ||
| 1386 | } | ||
| 1387 | |||
| 1388 | char *SSL_get_version(s) | ||
| 1389 | SSL *s; | ||
| 1390 | { | ||
| 1391 | if (s->version == TLS1_VERSION) | ||
| 1392 | return("TLSv1"); | ||
| 1393 | else if (s->version == SSL3_VERSION) | ||
| 1394 | return("SSLv3"); | ||
| 1395 | else if (s->version == SSL2_VERSION) | ||
| 1396 | return("SSLv2"); | ||
| 1397 | else | ||
| 1398 | return("unknown"); | ||
| 1399 | } | ||
| 1400 | |||
| 1401 | SSL *SSL_dup(s) | ||
| 1402 | SSL *s; | ||
| 1403 | { | ||
| 1404 | STACK *sk; | ||
| 1405 | X509_NAME *xn; | ||
| 1406 | SSL *ret; | ||
| 1407 | int i; | ||
| 1408 | |||
| 1409 | if ((ret=SSL_new(SSL_get_SSL_CTX(s))) == NULL) return(NULL); | ||
| 1410 | |||
| 1411 | /* This copies version, session-id, SSL_METHOD and 'cert' */ | ||
| 1412 | SSL_copy_session_id(ret,s); | ||
| 1413 | |||
| 1414 | SSL_set_read_ahead(ret,SSL_get_read_ahead(s)); | ||
| 1415 | SSL_set_verify(ret,SSL_get_verify_mode(s), | ||
| 1416 | SSL_get_verify_callback(s)); | ||
| 1417 | |||
| 1418 | SSL_set_info_callback(ret,SSL_get_info_callback(s)); | ||
| 1419 | |||
| 1420 | ret->debug=s->debug; | ||
| 1421 | ret->options=s->options; | ||
| 1422 | |||
| 1423 | /* copy app data, a little dangerous perhaps */ | ||
| 1424 | if (!CRYPTO_dup_ex_data(ssl_meth,&ret->ex_data,&s->ex_data)) | ||
| 1425 | goto err; | ||
| 1426 | |||
| 1427 | /* setup rbio, and wbio */ | ||
| 1428 | if (s->rbio != NULL) | ||
| 1429 | { | ||
| 1430 | if (!BIO_dup_state(s->rbio,(char *)&ret->rbio)) | ||
| 1431 | goto err; | ||
| 1432 | } | ||
| 1433 | if (s->wbio != NULL) | ||
| 1434 | { | ||
| 1435 | if (s->wbio != s->rbio) | ||
| 1436 | { | ||
| 1437 | if (!BIO_dup_state(s->wbio,(char *)&ret->wbio)) | ||
| 1438 | goto err; | ||
| 1439 | } | ||
| 1440 | else | ||
| 1441 | ret->wbio=ret->rbio; | ||
| 1442 | } | ||
| 1443 | |||
| 1444 | /* dup the cipher_list and cipher_list_by_id stacks */ | ||
| 1445 | if (s->cipher_list != NULL) | ||
| 1446 | { | ||
| 1447 | if ((ret->cipher_list=sk_dup(s->cipher_list)) == NULL) | ||
| 1448 | goto err; | ||
| 1449 | } | ||
| 1450 | if (s->cipher_list_by_id != NULL) | ||
| 1451 | if ((ret->cipher_list_by_id=sk_dup(s->cipher_list_by_id)) | ||
| 1452 | == NULL) | ||
| 1453 | goto err; | ||
| 1454 | |||
| 1455 | /* Dup the client_CA list */ | ||
| 1456 | if (s->client_CA != NULL) | ||
| 1457 | { | ||
| 1458 | if ((sk=sk_dup(s->client_CA)) == NULL) goto err; | ||
| 1459 | ret->client_CA=sk; | ||
| 1460 | for (i=0; i<sk_num(sk); i++) | ||
| 1461 | { | ||
| 1462 | xn=(X509_NAME *)sk_value(sk,i); | ||
| 1463 | if ((sk_value(sk,i)=(char *)X509_NAME_dup(xn)) == NULL) | ||
| 1464 | { | ||
| 1465 | X509_NAME_free(xn); | ||
| 1466 | goto err; | ||
| 1467 | } | ||
| 1468 | } | ||
| 1469 | } | ||
| 1470 | |||
| 1471 | ret->shutdown=s->shutdown; | ||
| 1472 | ret->state=s->state; | ||
| 1473 | ret->handshake_func=s->handshake_func; | ||
| 1474 | |||
| 1475 | if (0) | ||
| 1476 | { | ||
| 1477 | err: | ||
| 1478 | if (ret != NULL) SSL_free(ret); | ||
| 1479 | ret=NULL; | ||
| 1480 | } | ||
| 1481 | return(ret); | ||
| 1482 | } | ||
| 1483 | |||
| 1484 | void ssl_clear_cipher_ctx(s) | ||
| 1485 | SSL *s; | ||
| 1486 | { | ||
| 1487 | if (s->enc_read_ctx != NULL) | ||
| 1488 | { | ||
| 1489 | EVP_CIPHER_CTX_cleanup(s->enc_read_ctx); | ||
| 1490 | Free(s->enc_read_ctx); | ||
| 1491 | s->enc_read_ctx=NULL; | ||
| 1492 | } | ||
| 1493 | if (s->enc_write_ctx != NULL) | ||
| 1494 | { | ||
| 1495 | EVP_CIPHER_CTX_cleanup(s->enc_write_ctx); | ||
| 1496 | Free(s->enc_write_ctx); | ||
| 1497 | s->enc_write_ctx=NULL; | ||
| 1498 | } | ||
| 1499 | } | ||
| 1500 | |||
| 1501 | /* Fix this function so that it takes an optional type parameter */ | ||
| 1502 | X509 *SSL_get_certificate(s) | ||
| 1503 | SSL *s; | ||
| 1504 | { | ||
| 1505 | if (s->cert != NULL) | ||
| 1506 | return(s->cert->key->x509); | ||
| 1507 | else | ||
| 1508 | return(NULL); | ||
| 1509 | } | ||
| 1510 | |||
| 1511 | /* Fix this function so that it takes an optional type parameter */ | ||
| 1512 | EVP_PKEY *SSL_get_privatekey(s) | ||
| 1513 | SSL *s; | ||
| 1514 | { | ||
| 1515 | if (s->cert != NULL) | ||
| 1516 | return(s->cert->key->privatekey); | ||
| 1517 | else | ||
| 1518 | return(NULL); | ||
| 1519 | } | ||
| 1520 | |||
| 1521 | SSL_CIPHER *SSL_get_current_cipher(s) | ||
| 1522 | SSL *s; | ||
| 1523 | { | ||
| 1524 | if ((s->session != NULL) && (s->session->cipher != NULL)) | ||
| 1525 | return(s->session->cipher); | ||
| 1526 | return(NULL); | ||
| 1527 | } | ||
| 1528 | |||
| 1529 | int ssl_init_wbio_buffer(s,push) | ||
| 1530 | SSL *s; | ||
| 1531 | int push; | ||
| 1532 | { | ||
| 1533 | BIO *bbio; | ||
| 1534 | |||
| 1535 | if (s->bbio == NULL) | ||
| 1536 | { | ||
| 1537 | bbio=BIO_new(BIO_f_buffer()); | ||
| 1538 | if (bbio == NULL) return(0); | ||
| 1539 | s->bbio=bbio; | ||
| 1540 | } | ||
| 1541 | else | ||
| 1542 | { | ||
| 1543 | bbio=s->bbio; | ||
| 1544 | if (s->bbio == s->wbio) | ||
| 1545 | s->wbio=BIO_pop(s->wbio); | ||
| 1546 | } | ||
| 1547 | BIO_reset(bbio); | ||
| 1548 | /* if (!BIO_set_write_buffer_size(bbio,16*1024)) */ | ||
| 1549 | if (!BIO_set_read_buffer_size(bbio,1)) | ||
| 1550 | { | ||
| 1551 | SSLerr(SSL_F_SSL_INIT_WBIO_BUFFER,ERR_R_BUF_LIB); | ||
| 1552 | return(0); | ||
| 1553 | } | ||
| 1554 | if (push) | ||
| 1555 | { | ||
| 1556 | if (s->wbio != bbio) | ||
| 1557 | s->wbio=BIO_push(bbio,s->wbio); | ||
| 1558 | } | ||
| 1559 | else | ||
| 1560 | { | ||
| 1561 | if (s->wbio == bbio) | ||
| 1562 | s->wbio=BIO_pop(bbio); | ||
| 1563 | } | ||
| 1564 | return(1); | ||
| 1565 | } | ||
| 1566 | |||
| 1567 | void SSL_CTX_set_quiet_shutdown(ctx,mode) | ||
| 1568 | SSL_CTX *ctx; | ||
| 1569 | int mode; | ||
| 1570 | { | ||
| 1571 | ctx->quiet_shutdown=mode; | ||
| 1572 | } | ||
| 1573 | |||
| 1574 | int SSL_CTX_get_quiet_shutdown(ctx) | ||
| 1575 | SSL_CTX *ctx; | ||
| 1576 | { | ||
| 1577 | return(ctx->quiet_shutdown); | ||
| 1578 | } | ||
| 1579 | |||
| 1580 | void SSL_set_quiet_shutdown(s,mode) | ||
| 1581 | SSL *s; | ||
| 1582 | int mode; | ||
| 1583 | { | ||
| 1584 | s->quiet_shutdown=mode; | ||
| 1585 | } | ||
| 1586 | |||
| 1587 | int SSL_get_quiet_shutdown(s) | ||
| 1588 | SSL *s; | ||
| 1589 | { | ||
| 1590 | return(s->quiet_shutdown); | ||
| 1591 | } | ||
| 1592 | |||
| 1593 | void SSL_set_shutdown(s,mode) | ||
| 1594 | SSL *s; | ||
| 1595 | int mode; | ||
| 1596 | { | ||
| 1597 | s->shutdown=mode; | ||
| 1598 | } | ||
| 1599 | |||
| 1600 | int SSL_get_shutdown(s) | ||
| 1601 | SSL *s; | ||
| 1602 | { | ||
| 1603 | return(s->shutdown); | ||
| 1604 | } | ||
| 1605 | |||
| 1606 | int SSL_version(s) | ||
| 1607 | SSL *s; | ||
| 1608 | { | ||
| 1609 | return(s->version); | ||
| 1610 | } | ||
| 1611 | |||
| 1612 | SSL_CTX *SSL_get_SSL_CTX(ssl) | ||
| 1613 | SSL *ssl; | ||
| 1614 | { | ||
| 1615 | return(ssl->ctx); | ||
| 1616 | } | ||
| 1617 | |||
| 1618 | int SSL_CTX_set_default_verify_paths(ctx) | ||
| 1619 | SSL_CTX *ctx; | ||
| 1620 | { | ||
| 1621 | return(X509_STORE_set_default_paths(ctx->cert_store)); | ||
| 1622 | } | ||
| 1623 | |||
| 1624 | int SSL_CTX_load_verify_locations(ctx,CAfile,CApath) | ||
| 1625 | SSL_CTX *ctx; | ||
| 1626 | char *CAfile; | ||
| 1627 | char *CApath; | ||
| 1628 | { | ||
| 1629 | return(X509_STORE_load_locations(ctx->cert_store,CAfile,CApath)); | ||
| 1630 | } | ||
| 1631 | |||
| 1632 | void SSL_set_info_callback(ssl,cb) | ||
| 1633 | SSL *ssl; | ||
| 1634 | void (*cb)(); | ||
| 1635 | { | ||
| 1636 | ssl->info_callback=cb; | ||
| 1637 | } | ||
| 1638 | |||
| 1639 | void (*SSL_get_info_callback(ssl))() | ||
| 1640 | SSL *ssl; | ||
| 1641 | { | ||
| 1642 | return(ssl->info_callback); | ||
| 1643 | } | ||
| 1644 | |||
| 1645 | int SSL_state(ssl) | ||
| 1646 | SSL *ssl; | ||
| 1647 | { | ||
| 1648 | return(ssl->state); | ||
| 1649 | } | ||
| 1650 | |||
| 1651 | void SSL_set_verify_result(ssl,arg) | ||
| 1652 | SSL *ssl; | ||
| 1653 | long arg; | ||
| 1654 | { | ||
| 1655 | ssl->verify_result=arg; | ||
| 1656 | } | ||
| 1657 | |||
| 1658 | long SSL_get_verify_result(ssl) | ||
| 1659 | SSL *ssl; | ||
| 1660 | { | ||
| 1661 | return(ssl->verify_result); | ||
| 1662 | } | ||
| 1663 | |||
| 1664 | int SSL_get_ex_new_index(argl,argp,new_func,dup_func,free_func) | ||
| 1665 | long argl; | ||
| 1666 | char *argp; | ||
| 1667 | int (*new_func)(); | ||
| 1668 | int (*dup_func)(); | ||
| 1669 | void (*free_func)(); | ||
| 1670 | { | ||
| 1671 | ssl_meth_num++; | ||
| 1672 | return(CRYPTO_get_ex_new_index(ssl_meth_num-1, | ||
| 1673 | &ssl_meth,argl,argp,new_func,dup_func,free_func)); | ||
| 1674 | } | ||
| 1675 | |||
| 1676 | int SSL_set_ex_data(s,idx,arg) | ||
| 1677 | SSL *s; | ||
| 1678 | int idx; | ||
| 1679 | char *arg; | ||
| 1680 | { | ||
| 1681 | return(CRYPTO_set_ex_data(&s->ex_data,idx,arg)); | ||
| 1682 | } | ||
| 1683 | |||
| 1684 | char *SSL_get_ex_data(s,idx) | ||
| 1685 | SSL *s; | ||
| 1686 | int idx; | ||
| 1687 | { | ||
| 1688 | return(CRYPTO_get_ex_data(&s->ex_data,idx)); | ||
| 1689 | } | ||
| 1690 | |||
| 1691 | int SSL_CTX_get_ex_new_index(argl,argp,new_func,dup_func,free_func) | ||
| 1692 | long argl; | ||
| 1693 | char *argp; | ||
| 1694 | int (*new_func)(); | ||
| 1695 | int (*dup_func)(); | ||
| 1696 | void (*free_func)(); | ||
| 1697 | { | ||
| 1698 | ssl_ctx_meth_num++; | ||
| 1699 | return(CRYPTO_get_ex_new_index(ssl_ctx_meth_num-1, | ||
| 1700 | &ssl_ctx_meth,argl,argp,new_func,dup_func,free_func)); | ||
| 1701 | } | ||
| 1702 | |||
| 1703 | int SSL_CTX_set_ex_data(s,idx,arg) | ||
| 1704 | SSL_CTX *s; | ||
| 1705 | int idx; | ||
| 1706 | char *arg; | ||
| 1707 | { | ||
| 1708 | return(CRYPTO_set_ex_data(&s->ex_data,idx,arg)); | ||
| 1709 | } | ||
| 1710 | |||
| 1711 | char *SSL_CTX_get_ex_data(s,idx) | ||
| 1712 | SSL_CTX *s; | ||
| 1713 | int idx; | ||
| 1714 | { | ||
| 1715 | return(CRYPTO_get_ex_data(&s->ex_data,idx)); | ||
| 1716 | } | ||
| 1717 | |||
| 1718 | #if defined(_WINDLL) && defined(WIN16) | ||
| 1719 | #include "../crypto/bio/bss_file.c" | ||
| 1720 | #endif | ||
| 1721 | |||
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h new file mode 100644 index 0000000000..b29517081b --- /dev/null +++ b/src/lib/libssl/ssl_locl.h | |||
| @@ -0,0 +1,558 @@ | |||
| 1 | /* ssl/ssl_locl.h */ | ||
| 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 | #ifndef HEADER_SSL_LOCL_H | ||
| 60 | #define HEADER_SSL_LOCL_H | ||
| 61 | #include <stdlib.h> | ||
| 62 | #include <time.h> | ||
| 63 | #include <string.h> | ||
| 64 | #include <errno.h> | ||
| 65 | |||
| 66 | #include "e_os.h" | ||
| 67 | |||
| 68 | #include "buffer.h" | ||
| 69 | #include "bio.h" | ||
| 70 | #include "crypto.h" | ||
| 71 | #include "evp.h" | ||
| 72 | #include "stack.h" | ||
| 73 | #include "x509.h" | ||
| 74 | #include "err.h" | ||
| 75 | #include "ssl.h" | ||
| 76 | |||
| 77 | |||
| 78 | #define c2l(c,l) (l = ((unsigned long)(*((c)++))) , \ | ||
| 79 | l|=(((unsigned long)(*((c)++)))<< 8), \ | ||
| 80 | l|=(((unsigned long)(*((c)++)))<<16), \ | ||
| 81 | l|=(((unsigned long)(*((c)++)))<<24)) | ||
| 82 | |||
| 83 | /* NOTE - c is not incremented as per c2l */ | ||
| 84 | #define c2ln(c,l1,l2,n) { \ | ||
| 85 | c+=n; \ | ||
| 86 | l1=l2=0; \ | ||
| 87 | switch (n) { \ | ||
| 88 | case 8: l2 =((unsigned long)(*(--(c))))<<24; \ | ||
| 89 | case 7: l2|=((unsigned long)(*(--(c))))<<16; \ | ||
| 90 | case 6: l2|=((unsigned long)(*(--(c))))<< 8; \ | ||
| 91 | case 5: l2|=((unsigned long)(*(--(c)))); \ | ||
| 92 | case 4: l1 =((unsigned long)(*(--(c))))<<24; \ | ||
| 93 | case 3: l1|=((unsigned long)(*(--(c))))<<16; \ | ||
| 94 | case 2: l1|=((unsigned long)(*(--(c))))<< 8; \ | ||
| 95 | case 1: l1|=((unsigned long)(*(--(c)))); \ | ||
| 96 | } \ | ||
| 97 | } | ||
| 98 | |||
| 99 | #define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ | ||
| 100 | *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ | ||
| 101 | *((c)++)=(unsigned char)(((l)>>16)&0xff), \ | ||
| 102 | *((c)++)=(unsigned char)(((l)>>24)&0xff)) | ||
| 103 | |||
| 104 | #define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24, \ | ||
| 105 | l|=((unsigned long)(*((c)++)))<<16, \ | ||
| 106 | l|=((unsigned long)(*((c)++)))<< 8, \ | ||
| 107 | l|=((unsigned long)(*((c)++)))) | ||
| 108 | |||
| 109 | #define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \ | ||
| 110 | *((c)++)=(unsigned char)(((l)>>16)&0xff), \ | ||
| 111 | *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ | ||
| 112 | *((c)++)=(unsigned char)(((l) )&0xff)) | ||
| 113 | |||
| 114 | /* NOTE - c is not incremented as per l2c */ | ||
| 115 | #define l2cn(l1,l2,c,n) { \ | ||
| 116 | c+=n; \ | ||
| 117 | switch (n) { \ | ||
| 118 | case 8: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \ | ||
| 119 | case 7: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \ | ||
| 120 | case 6: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \ | ||
| 121 | case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \ | ||
| 122 | case 4: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \ | ||
| 123 | case 3: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \ | ||
| 124 | case 2: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \ | ||
| 125 | case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \ | ||
| 126 | } \ | ||
| 127 | } | ||
| 128 | |||
| 129 | #define n2s(c,s) (s =((unsigned int)(*((c)++)))<< 8, \ | ||
| 130 | s|=((unsigned int)(*((c)++)))) | ||
| 131 | #define s2n(s,c) (*((c)++)=(unsigned char)(((s)>> 8)&0xff), \ | ||
| 132 | *((c)++)=(unsigned char)(((s) )&0xff)) | ||
| 133 | |||
| 134 | #define n2l3(c,l) (l =((unsigned long)(*((c)++)))<<16, \ | ||
| 135 | l|=((unsigned long)(*((c)++)))<< 8, \ | ||
| 136 | l|=((unsigned long)(*((c)++)))) | ||
| 137 | |||
| 138 | #define l2n3(l,c) (*((c)++)=(unsigned char)(((l)>>16)&0xff), \ | ||
| 139 | *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ | ||
| 140 | *((c)++)=(unsigned char)(((l) )&0xff)) | ||
| 141 | |||
| 142 | /* LOCAL STUFF */ | ||
| 143 | |||
| 144 | #define SSL_DECRYPT 0 | ||
| 145 | #define SSL_ENCRYPT 1 | ||
| 146 | |||
| 147 | #define TWO_BYTE_BIT 0x80 | ||
| 148 | #define SEC_ESC_BIT 0x40 | ||
| 149 | #define TWO_BYTE_MASK 0x7fff | ||
| 150 | #define THREE_BYTE_MASK 0x3fff | ||
| 151 | |||
| 152 | #define INC32(a) ((a)=((a)+1)&0xffffffffL) | ||
| 153 | #define DEC32(a) ((a)=((a)-1)&0xffffffffL) | ||
| 154 | #define MAX_MAC_SIZE 20 /* up from 16 for SSLv3 */ | ||
| 155 | |||
| 156 | #define SSL_MKEY_MASK 0x0000001FL | ||
| 157 | #define SSL_kRSA 0x00000001L /* RSA key exchange */ | ||
| 158 | #define SSL_kDHr 0x00000002L /* DH cert RSA CA cert */ | ||
| 159 | #define SSL_kDHd 0x00000004L /* DH cert DSA CA cert */ | ||
| 160 | #define SSL_kFZA 0x00000008L | ||
| 161 | #define SSL_kEDH 0x00000010L /* tmp DH key no DH cert */ | ||
| 162 | #define SSL_EDH (SSL_kEDH|(SSL_AUTH_MASK^SSL_aNULL)) | ||
| 163 | |||
| 164 | #define SSL_AUTH_MASK 0x000003e0L | ||
| 165 | #define SSL_aRSA 0x00000020L /* Authenticate with RSA */ | ||
| 166 | #define SSL_aDSS 0x00000040L /* Authenticate with DSS */ | ||
| 167 | #define SSL_DSS SSL_aDSS | ||
| 168 | #define SSL_aFZA 0x00000080L | ||
| 169 | #define SSL_aNULL 0x00000100L /* no Authenticate, ADH */ | ||
| 170 | #define SSL_aDH 0x00000200L /* no Authenticate, ADH */ | ||
| 171 | |||
| 172 | #define SSL_NULL (SSL_eNULL) | ||
| 173 | #define SSL_ADH (SSL_kEDH|SSL_aNULL) | ||
| 174 | #define SSL_RSA (SSL_kRSA|SSL_aRSA) | ||
| 175 | #define SSL_DH (SSL_kDHr|SSL_kDHd|SSL_kEDH) | ||
| 176 | #define SSL_FZA (SSL_aFZA|SSL_kFZA|SSL_eFZA) | ||
| 177 | |||
| 178 | #define SSL_ENC_MASK 0x0001Fc00L | ||
| 179 | #define SSL_DES 0x00000400L | ||
| 180 | #define SSL_3DES 0x00000800L | ||
| 181 | #define SSL_RC4 0x00001000L | ||
| 182 | #define SSL_RC2 0x00002000L | ||
| 183 | #define SSL_IDEA 0x00004000L | ||
| 184 | #define SSL_eFZA 0x00008000L | ||
| 185 | #define SSL_eNULL 0x00010000L | ||
| 186 | |||
| 187 | #define SSL_MAC_MASK 0x00060000L | ||
| 188 | #define SSL_MD5 0x00020000L | ||
| 189 | #define SSL_SHA1 0x00040000L | ||
| 190 | #define SSL_SHA (SSL_SHA1) | ||
| 191 | |||
| 192 | #define SSL_EXP_MASK 0x00300000L | ||
| 193 | #define SSL_EXP 0x00100000L | ||
| 194 | #define SSL_NOT_EXP 0x00200000L | ||
| 195 | #define SSL_EXPORT SSL_EXP | ||
| 196 | |||
| 197 | #define SSL_SSL_MASK 0x00c00000L | ||
| 198 | #define SSL_SSLV2 0x00400000L | ||
| 199 | #define SSL_SSLV3 0x00800000L | ||
| 200 | |||
| 201 | #define SSL_STRONG_MASK 0x07000000L | ||
| 202 | #define SSL_LOW 0x01000000L | ||
| 203 | #define SSL_MEDIUM 0x02000000L | ||
| 204 | #define SSL_HIGH 0x04000000L | ||
| 205 | |||
| 206 | /* we have used 0fffffff - 4 bits left to go */ | ||
| 207 | #define SSL_ALL 0xffffffffL | ||
| 208 | #define SSL_ALL_CIPHERS (SSL_MKEY_MASK|SSL_AUTH_MASK|SSL_ENC_MASK|\ | ||
| 209 | SSL_MAC_MASK|SSL_EXP_MASK) | ||
| 210 | |||
| 211 | /* Mostly for SSLv3 */ | ||
| 212 | #define SSL_PKEY_RSA_ENC 0 | ||
| 213 | #define SSL_PKEY_RSA_SIGN 1 | ||
| 214 | #define SSL_PKEY_DSA_SIGN 2 | ||
| 215 | #define SSL_PKEY_DH_RSA 3 | ||
| 216 | #define SSL_PKEY_DH_DSA 4 | ||
| 217 | #define SSL_PKEY_NUM 5 | ||
| 218 | |||
| 219 | /* SSL_kRSA <- RSA_ENC | (RSA_TMP & RSA_SIGN) | | ||
| 220 | * <- (EXPORT & (RSA_ENC | RSA_TMP) & RSA_SIGN) | ||
| 221 | * SSL_kDH <- DH_ENC & (RSA_ENC | RSA_SIGN | DSA_SIGN) | ||
| 222 | * SSL_kEDH <- RSA_ENC | RSA_SIGN | DSA_SIGN | ||
| 223 | * SSL_aRSA <- RSA_ENC | RSA_SIGN | ||
| 224 | * SSL_aDSS <- DSA_SIGN | ||
| 225 | */ | ||
| 226 | |||
| 227 | /* | ||
| 228 | #define CERT_INVALID 0 | ||
| 229 | #define CERT_PUBLIC_KEY 1 | ||
| 230 | #define CERT_PRIVATE_KEY 2 | ||
| 231 | */ | ||
| 232 | |||
| 233 | typedef struct cert_pkey_st | ||
| 234 | { | ||
| 235 | X509 *x509; | ||
| 236 | /* EVP_PKEY *publickey; *//* when extracted */ | ||
| 237 | EVP_PKEY *privatekey; | ||
| 238 | } CERT_PKEY; | ||
| 239 | |||
| 240 | typedef struct cert_st | ||
| 241 | { | ||
| 242 | int cert_type; | ||
| 243 | |||
| 244 | #ifdef undef | ||
| 245 | X509 *x509; | ||
| 246 | EVP_PKEY *publickey; /* when extracted */ | ||
| 247 | EVP_PKEY *privatekey; | ||
| 248 | |||
| 249 | pkeys[SSL_PKEY_RSA_ENC].x509 | ||
| 250 | /* pkeys[SSL_PKEY_RSA_ENC].publickey */ | ||
| 251 | pkeys[SSL_PKEY_RSA_ENC].privatekey | ||
| 252 | #endif | ||
| 253 | |||
| 254 | /* Current active set */ | ||
| 255 | CERT_PKEY *key; | ||
| 256 | |||
| 257 | /* The following masks are for the key and auth | ||
| 258 | * algorithms that are supported by the certs below */ | ||
| 259 | int valid; | ||
| 260 | unsigned long mask; | ||
| 261 | unsigned long export_mask; | ||
| 262 | |||
| 263 | RSA *rsa_tmp; | ||
| 264 | DH *dh_tmp; | ||
| 265 | RSA *(*rsa_tmp_cb)(); | ||
| 266 | DH *(*dh_tmp_cb)(); | ||
| 267 | CERT_PKEY pkeys[SSL_PKEY_NUM]; | ||
| 268 | |||
| 269 | STACK *cert_chain; | ||
| 270 | |||
| 271 | int references; | ||
| 272 | } CERT; | ||
| 273 | |||
| 274 | /*#define MAC_DEBUG */ | ||
| 275 | |||
| 276 | /*#define ERR_DEBUG */ | ||
| 277 | /*#define ABORT_DEBUG */ | ||
| 278 | /*#define PKT_DEBUG 1 */ | ||
| 279 | /*#define DES_DEBUG */ | ||
| 280 | /*#define DES_OFB_DEBUG */ | ||
| 281 | /*#define SSL_DEBUG */ | ||
| 282 | /*#define RSA_DEBUG */ | ||
| 283 | /*#define IDEA_DEBUG */ | ||
| 284 | |||
| 285 | #ifndef NOPROTO | ||
| 286 | #define FP_ICC (int (*)(const void *,const void *)) | ||
| 287 | #else | ||
| 288 | #define FP_ICC | ||
| 289 | #endif | ||
| 290 | |||
| 291 | #define ssl_put_cipher_by_char(ssl,ciph,ptr) \ | ||
| 292 | ((ssl)->method->put_cipher_by_char((ciph),(ptr))) | ||
| 293 | #define ssl_get_cipher_by_char(ssl,ptr) \ | ||
| 294 | ((ssl)->method->get_cipher_by_char(ptr)) | ||
| 295 | |||
| 296 | /* This is for the SSLv3/TLSv1.0 differences in crypto/hash stuff | ||
| 297 | * It is a bit of a mess of functions, but hell, think of it as | ||
| 298 | * an opaque strucute :-) */ | ||
| 299 | typedef struct ssl3_enc_method | ||
| 300 | { | ||
| 301 | int (*enc)(); | ||
| 302 | int (*mac)(); | ||
| 303 | int (*setup_key_block)(); | ||
| 304 | int (*generate_master_secret)(); | ||
| 305 | int (*change_cipher_state)(); | ||
| 306 | int (*final_finish_mac)(); | ||
| 307 | int finish_mac_length; | ||
| 308 | int (*cert_verify_mac)(); | ||
| 309 | unsigned char client_finished[20]; | ||
| 310 | int client_finished_len; | ||
| 311 | unsigned char server_finished[20]; | ||
| 312 | int server_finished_len; | ||
| 313 | int (*alert_value)(); | ||
| 314 | } SSL3_ENC_METHOD; | ||
| 315 | |||
| 316 | extern SSL3_ENC_METHOD ssl3_undef_enc_method; | ||
| 317 | extern SSL_CIPHER ssl2_ciphers[]; | ||
| 318 | extern SSL_CIPHER ssl3_ciphers[]; | ||
| 319 | |||
| 320 | #ifndef NOPROTO | ||
| 321 | |||
| 322 | SSL_METHOD *ssl_bad_method(int ver); | ||
| 323 | SSL_METHOD *sslv2_base_method(void); | ||
| 324 | SSL_METHOD *sslv23_base_method(void); | ||
| 325 | SSL_METHOD *sslv3_base_method(void); | ||
| 326 | |||
| 327 | void ssl_clear_cipher_ctx(SSL *s); | ||
| 328 | int ssl_clear_bad_session(SSL *s); | ||
| 329 | CERT *ssl_cert_new(void); | ||
| 330 | void ssl_cert_free(CERT *c); | ||
| 331 | int ssl_set_cert_type(CERT *c, int type); | ||
| 332 | int ssl_get_new_session(SSL *s, int session); | ||
| 333 | int ssl_get_prev_session(SSL *s, unsigned char *session,int len); | ||
| 334 | int ssl_cipher_id_cmp(SSL_CIPHER *a,SSL_CIPHER *b); | ||
| 335 | int ssl_cipher_ptr_id_cmp(SSL_CIPHER **ap,SSL_CIPHER **bp); | ||
| 336 | STACK *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num,STACK **skp); | ||
| 337 | int ssl_cipher_list_to_bytes(SSL *s,STACK *sk,unsigned char *p); | ||
| 338 | STACK *ssl_create_cipher_list(SSL_METHOD *meth,STACK **pref, | ||
| 339 | STACK **sorted,char *str); | ||
| 340 | void ssl_update_cache(SSL *s, int mode); | ||
| 341 | int ssl_cipher_get_evp(SSL_CIPHER *c, EVP_CIPHER **enc, EVP_MD **md); | ||
| 342 | int ssl_verify_cert_chain(SSL *s,STACK *sk); | ||
| 343 | int ssl_undefined_function(SSL *s); | ||
| 344 | X509 *ssl_get_server_send_cert(SSL *); | ||
| 345 | EVP_PKEY *ssl_get_sign_pkey(SSL *,SSL_CIPHER *); | ||
| 346 | int ssl_cert_type(X509 *x,EVP_PKEY *pkey); | ||
| 347 | void ssl_set_cert_masks(CERT *c); | ||
| 348 | STACK *ssl_get_ciphers_by_id(SSL *s); | ||
| 349 | int ssl_verify_alarm_type(long type); | ||
| 350 | |||
| 351 | int ssl2_enc_init(SSL *s, int client); | ||
| 352 | void ssl2_generate_key_material(SSL *s); | ||
| 353 | void ssl2_enc(SSL *s,int send_data); | ||
| 354 | void ssl2_mac(SSL *s,unsigned char *mac,int send_data); | ||
| 355 | SSL_CIPHER *ssl2_get_cipher_by_char(unsigned char *p); | ||
| 356 | int ssl2_put_cipher_by_char(SSL_CIPHER *c,unsigned char *p); | ||
| 357 | int ssl2_part_read(SSL *s, unsigned long f, int i); | ||
| 358 | int ssl2_do_write(SSL *s); | ||
| 359 | int ssl2_set_certificate(SSL *s, int type, int len, unsigned char *data); | ||
| 360 | void ssl2_return_error(SSL *s,int reason); | ||
| 361 | void ssl2_write_error(SSL *s); | ||
| 362 | int ssl2_num_ciphers(void); | ||
| 363 | SSL_CIPHER *ssl2_get_cipher(unsigned int u); | ||
| 364 | int ssl2_new(SSL *s); | ||
| 365 | void ssl2_free(SSL *s); | ||
| 366 | int ssl2_accept(SSL *s); | ||
| 367 | int ssl2_connect(SSL *s); | ||
| 368 | int ssl2_read(SSL *s, char *buf, int len); | ||
| 369 | int ssl2_peek(SSL *s, char *buf, int len); | ||
| 370 | int ssl2_write(SSL *s, char *buf, int len); | ||
| 371 | int ssl2_shutdown(SSL *s); | ||
| 372 | void ssl2_clear(SSL *s); | ||
| 373 | long ssl2_ctrl(SSL *s,int cmd, long larg, char *parg); | ||
| 374 | long ssl2_ctx_ctrl(SSL_CTX *s,int cmd, long larg, char *parg); | ||
| 375 | int ssl2_pending(SSL *s); | ||
| 376 | |||
| 377 | SSL_CIPHER *ssl3_get_cipher_by_char(unsigned char *p); | ||
| 378 | int ssl3_put_cipher_by_char(SSL_CIPHER *c,unsigned char *p); | ||
| 379 | void ssl3_init_finished_mac(SSL *s); | ||
| 380 | int ssl3_send_server_certificate(SSL *s); | ||
| 381 | int ssl3_get_finished(SSL *s,int state_a,int state_b); | ||
| 382 | int ssl3_setup_key_block(SSL *s); | ||
| 383 | int ssl3_send_change_cipher_spec(SSL *s,int state_a,int state_b); | ||
| 384 | int ssl3_change_cipher_state(SSL *s,int which); | ||
| 385 | void ssl3_cleanup_key_block(SSL *s); | ||
| 386 | int ssl3_do_write(SSL *s,int type); | ||
| 387 | void ssl3_send_alert(SSL *s,int level, int desc); | ||
| 388 | int ssl3_generate_master_secret(SSL *s, unsigned char *out, | ||
| 389 | unsigned char *p, int len); | ||
| 390 | int ssl3_get_req_cert_type(SSL *s,unsigned char *p); | ||
| 391 | long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok); | ||
| 392 | int ssl3_send_finished(SSL *s, int a, int b, unsigned char *sender,int slen); | ||
| 393 | int ssl3_num_ciphers(void); | ||
| 394 | SSL_CIPHER *ssl3_get_cipher(unsigned int u); | ||
| 395 | int ssl3_renegotiate(SSL *ssl); | ||
| 396 | int ssl3_renegotiate_check(SSL *ssl); | ||
| 397 | int ssl3_dispatch_alert(SSL *s); | ||
| 398 | int ssl3_read_bytes(SSL *s, int type, char *buf, int len); | ||
| 399 | int ssl3_part_read(SSL *s, int i); | ||
| 400 | int ssl3_write_bytes(SSL *s, int type, char *buf, int len); | ||
| 401 | int ssl3_final_finish_mac(SSL *s, EVP_MD_CTX *ctx1,EVP_MD_CTX *ctx2, | ||
| 402 | unsigned char *sender, int slen,unsigned char *p); | ||
| 403 | int ssl3_cert_verify_mac(SSL *s, EVP_MD_CTX *in, unsigned char *p); | ||
| 404 | void ssl3_finish_mac(SSL *s, unsigned char *buf, int len); | ||
| 405 | int ssl3_enc(SSL *s, int send_data); | ||
| 406 | int ssl3_mac(SSL *ssl, unsigned char *md, int send_data); | ||
| 407 | unsigned long ssl3_output_cert_chain(SSL *s, X509 *x); | ||
| 408 | SSL_CIPHER *ssl3_choose_cipher(SSL *ssl,STACK *have,STACK *pref); | ||
| 409 | int ssl3_setup_buffers(SSL *s); | ||
| 410 | int ssl3_new(SSL *s); | ||
| 411 | void ssl3_free(SSL *s); | ||
| 412 | int ssl3_accept(SSL *s); | ||
| 413 | int ssl3_connect(SSL *s); | ||
| 414 | int ssl3_read(SSL *s, char *buf, int len); | ||
| 415 | int ssl3_peek(SSL *s,char *buf, int len); | ||
| 416 | int ssl3_write(SSL *s, char *buf, int len); | ||
| 417 | int ssl3_shutdown(SSL *s); | ||
| 418 | void ssl3_clear(SSL *s); | ||
| 419 | long ssl3_ctrl(SSL *s,int cmd, long larg, char *parg); | ||
| 420 | long ssl3_ctx_ctrl(SSL_CTX *s,int cmd, long larg, char *parg); | ||
| 421 | int ssl3_pending(SSL *s); | ||
| 422 | |||
| 423 | int ssl23_accept(SSL *s); | ||
| 424 | int ssl23_connect(SSL *s); | ||
| 425 | int ssl23_read_bytes(SSL *s, int n); | ||
| 426 | int ssl23_write_bytes(SSL *s); | ||
| 427 | |||
| 428 | int tls1_new(SSL *s); | ||
| 429 | void tls1_free(SSL *s); | ||
| 430 | void tls1_clear(SSL *s); | ||
| 431 | long tls1_ctrl(SSL *s,int cmd, long larg, char *parg); | ||
| 432 | SSL_METHOD *tlsv1_base_method(void ); | ||
| 433 | |||
| 434 | |||
| 435 | int ssl_init_wbio_buffer(SSL *s, int push); | ||
| 436 | |||
| 437 | int tls1_change_cipher_state(SSL *s, int which); | ||
| 438 | int tls1_setup_key_block(SSL *s); | ||
| 439 | int tls1_enc(SSL *s, int snd); | ||
| 440 | int tls1_final_finish_mac(SSL *s, EVP_MD_CTX *in1_ctx, EVP_MD_CTX *in2_ctx, | ||
| 441 | unsigned char *str, int slen, unsigned char *p); | ||
| 442 | int tls1_cert_verify_mac(SSL *s, EVP_MD_CTX *in, unsigned char *p); | ||
| 443 | int tls1_mac(SSL *ssl, unsigned char *md, int snd); | ||
| 444 | int tls1_generate_master_secret(SSL *s, unsigned char *out, | ||
| 445 | unsigned char *p, int len); | ||
| 446 | int tls1_alert_code(int code); | ||
| 447 | int ssl3_alert_code(int code); | ||
| 448 | |||
| 449 | |||
| 450 | #else | ||
| 451 | |||
| 452 | SSL_METHOD *ssl_bad_method(); | ||
| 453 | SSL_METHOD *sslv2_base_method(); | ||
| 454 | SSL_METHOD *sslv23_base_method(); | ||
| 455 | SSL_METHOD *sslv3_base_method(); | ||
| 456 | |||
| 457 | void ssl_clear_cipher_ctx(); | ||
| 458 | int ssl_clear_bad_session(); | ||
| 459 | CERT *ssl_cert_new(); | ||
| 460 | void ssl_cert_free(); | ||
| 461 | int ssl_set_cert_type(); | ||
| 462 | int ssl_get_new_session(); | ||
| 463 | int ssl_get_prev_session(); | ||
| 464 | int ssl_cipher_id_cmp(); | ||
| 465 | int ssl_cipher_ptr_id_cmp(); | ||
| 466 | STACK *ssl_bytes_to_cipher_list(); | ||
| 467 | int ssl_cipher_list_to_bytes(); | ||
| 468 | STACK *ssl_create_cipher_list(); | ||
| 469 | void ssl_update_cache(); | ||
| 470 | int ssl_session_get_ciphers(); | ||
| 471 | int ssl_verify_cert_chain(); | ||
| 472 | int ssl_undefined_function(); | ||
| 473 | X509 *ssl_get_server_send_cert(); | ||
| 474 | EVP_PKEY *ssl_get_sign_pkey(); | ||
| 475 | int ssl_cert_type(); | ||
| 476 | void ssl_set_cert_masks(); | ||
| 477 | STACK *ssl_get_ciphers_by_id(); | ||
| 478 | int ssl_verify_alarm_type(); | ||
| 479 | |||
| 480 | int ssl2_enc_init(); | ||
| 481 | void ssl2_generate_key_material(); | ||
| 482 | void ssl2_enc(); | ||
| 483 | void ssl2_mac(); | ||
| 484 | SSL_CIPHER *ssl2_get_cipher_by_char(); | ||
| 485 | int ssl2_put_cipher_by_char(); | ||
| 486 | int ssl2_part_read(); | ||
| 487 | int ssl2_do_write(); | ||
| 488 | int ssl2_set_certificate(); | ||
| 489 | void ssl2_return_error(); | ||
| 490 | void ssl2_write_error(); | ||
| 491 | int ssl2_num_ciphers(); | ||
| 492 | SSL_CIPHER *ssl2_get_cipher(); | ||
| 493 | int ssl2_new(); | ||
| 494 | void ssl2_free(); | ||
| 495 | int ssl2_accept(); | ||
| 496 | int ssl2_connect(); | ||
| 497 | int ssl2_read(); | ||
| 498 | int ssl2_peek(); | ||
| 499 | int ssl2_write(); | ||
| 500 | int ssl2_shutdown(); | ||
| 501 | void ssl2_clear(); | ||
| 502 | long ssl2_ctrl(); | ||
| 503 | long ssl2_ctx_ctrl(); | ||
| 504 | int ssl2_pending(); | ||
| 505 | |||
| 506 | SSL_CIPHER *ssl3_get_cipher_by_char(); | ||
| 507 | int ssl3_put_cipher_by_char(); | ||
| 508 | void ssl3_init_finished_mac(); | ||
| 509 | int ssl3_send_server_certificate(); | ||
| 510 | int ssl3_get_finished(); | ||
| 511 | int ssl3_setup_key_block(); | ||
| 512 | int ssl3_send_change_cipher_spec(); | ||
| 513 | int ssl3_change_cipher_state(); | ||
| 514 | void ssl3_cleanup_key_block(); | ||
| 515 | int ssl3_do_write(); | ||
| 516 | void ssl3_send_alert(); | ||
| 517 | int ssl3_generate_master_secret(); | ||
| 518 | int ssl3_get_req_cert_type(); | ||
| 519 | long ssl3_get_message(); | ||
| 520 | int ssl3_send_finished(); | ||
| 521 | int ssl3_num_ciphers(); | ||
| 522 | SSL_CIPHER *ssl3_get_cipher(); | ||
| 523 | int ssl3_renegotiate(); | ||
| 524 | int ssl3_renegotiate_check(); | ||
| 525 | int ssl3_dispatch_alert(); | ||
| 526 | int ssl3_read_bytes(); | ||
| 527 | int ssl3_part_read(); | ||
| 528 | int ssl3_write_bytes(); | ||
| 529 | int ssl3_final_finish_mac(); | ||
| 530 | void ssl3_finish_mac(); | ||
| 531 | int ssl3_enc(); | ||
| 532 | int ssl3_mac(); | ||
| 533 | unsigned long ssl3_output_cert_chain(); | ||
| 534 | SSL_CIPHER *ssl3_choose_cipher(); | ||
| 535 | int ssl3_setup_buffers(); | ||
| 536 | int ssl3_new(); | ||
| 537 | void ssl3_free(); | ||
| 538 | int ssl3_accept(); | ||
| 539 | int ssl3_connect(); | ||
| 540 | int ssl3_read(); | ||
| 541 | int ssl3_peek(); | ||
| 542 | int ssl3_write(); | ||
| 543 | int ssl3_shutdown(); | ||
| 544 | void ssl3_clear(); | ||
| 545 | long ssl3_ctrl(); | ||
| 546 | long ssl3_ctx_ctrl(); | ||
| 547 | int ssl3_pending(); | ||
| 548 | |||
| 549 | int ssl23_accept(); | ||
| 550 | int ssl23_connect(); | ||
| 551 | int ssl23_read_bytes(); | ||
| 552 | int ssl23_write_bytes(); | ||
| 553 | |||
| 554 | int ssl_init_wbio_buffer(); | ||
| 555 | |||
| 556 | #endif | ||
| 557 | |||
| 558 | #endif | ||
diff --git a/src/lib/libssl/ssl_rsa.c b/src/lib/libssl/ssl_rsa.c new file mode 100644 index 0000000000..140475e5fb --- /dev/null +++ b/src/lib/libssl/ssl_rsa.c | |||
| @@ -0,0 +1,831 @@ | |||
| 1 | /* ssl/ssl_rsa.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 "bio.h" | ||
| 61 | #include "objects.h" | ||
| 62 | #include "evp.h" | ||
| 63 | #include "x509.h" | ||
| 64 | #include "pem.h" | ||
| 65 | #include "ssl_locl.h" | ||
| 66 | |||
| 67 | #ifndef NOPROTO | ||
| 68 | static int ssl_set_cert(CERT *c, X509 *x509); | ||
| 69 | static int ssl_set_pkey(CERT *c, EVP_PKEY *pkey); | ||
| 70 | #else | ||
| 71 | static int ssl_set_cert(); | ||
| 72 | static int ssl_set_pkey(); | ||
| 73 | #endif | ||
| 74 | |||
| 75 | int SSL_use_certificate(ssl, x) | ||
| 76 | SSL *ssl; | ||
| 77 | X509 *x; | ||
| 78 | { | ||
| 79 | CERT *c; | ||
| 80 | |||
| 81 | if (x == NULL) | ||
| 82 | { | ||
| 83 | SSLerr(SSL_F_SSL_USE_CERTIFICATE,ERR_R_PASSED_NULL_PARAMETER); | ||
| 84 | return(0); | ||
| 85 | } | ||
| 86 | if ((ssl->cert == NULL) || (ssl->cert == ssl->ctx->default_cert)) | ||
| 87 | { | ||
| 88 | c=ssl_cert_new(); | ||
| 89 | if (c == NULL) | ||
| 90 | { | ||
| 91 | SSLerr(SSL_F_SSL_USE_CERTIFICATE,ERR_R_MALLOC_FAILURE); | ||
| 92 | return(0); | ||
| 93 | } | ||
| 94 | if (ssl->cert != NULL) ssl_cert_free(ssl->cert); | ||
| 95 | ssl->cert=c; | ||
| 96 | } | ||
| 97 | c=ssl->cert; | ||
| 98 | |||
| 99 | return(ssl_set_cert(c,x)); | ||
| 100 | } | ||
| 101 | |||
| 102 | #ifndef NO_STDIO | ||
| 103 | int SSL_use_certificate_file(ssl, file, type) | ||
| 104 | SSL *ssl; | ||
| 105 | char *file; | ||
| 106 | int type; | ||
| 107 | { | ||
| 108 | int j; | ||
| 109 | BIO *in; | ||
| 110 | int ret=0; | ||
| 111 | X509 *x=NULL; | ||
| 112 | |||
| 113 | in=BIO_new(BIO_s_file_internal()); | ||
| 114 | if (in == NULL) | ||
| 115 | { | ||
| 116 | SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE,ERR_R_BUF_LIB); | ||
| 117 | goto end; | ||
| 118 | } | ||
| 119 | |||
| 120 | if (BIO_read_filename(in,file) <= 0) | ||
| 121 | { | ||
| 122 | SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE,ERR_R_SYS_LIB); | ||
| 123 | goto end; | ||
| 124 | } | ||
| 125 | if (type == SSL_FILETYPE_ASN1) | ||
| 126 | { | ||
| 127 | j=ERR_R_ASN1_LIB; | ||
| 128 | x=d2i_X509_bio(in,NULL); | ||
| 129 | } | ||
| 130 | else if (type == SSL_FILETYPE_PEM) | ||
| 131 | { | ||
| 132 | j=ERR_R_PEM_LIB; | ||
| 133 | x=PEM_read_bio_X509(in,NULL,ssl->ctx->default_passwd_callback); | ||
| 134 | } | ||
| 135 | else | ||
| 136 | { | ||
| 137 | SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE,SSL_R_BAD_SSL_FILETYPE); | ||
| 138 | goto end; | ||
| 139 | } | ||
| 140 | |||
| 141 | if (x == NULL) | ||
| 142 | { | ||
| 143 | SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE,j); | ||
| 144 | goto end; | ||
| 145 | } | ||
| 146 | |||
| 147 | ret=SSL_use_certificate(ssl,x); | ||
| 148 | end: | ||
| 149 | if (x != NULL) X509_free(x); | ||
| 150 | if (in != NULL) BIO_free(in); | ||
| 151 | return(ret); | ||
| 152 | } | ||
| 153 | #endif | ||
| 154 | |||
| 155 | int SSL_use_certificate_ASN1(ssl, len, d) | ||
| 156 | SSL *ssl; | ||
| 157 | int len; | ||
| 158 | unsigned char *d; | ||
| 159 | { | ||
| 160 | X509 *x; | ||
| 161 | int ret; | ||
| 162 | |||
| 163 | x=d2i_X509(NULL,&d,(long)len); | ||
| 164 | if (x == NULL) | ||
| 165 | { | ||
| 166 | SSLerr(SSL_F_SSL_USE_CERTIFICATE_ASN1,ERR_R_ASN1_LIB); | ||
| 167 | return(0); | ||
| 168 | } | ||
| 169 | |||
| 170 | ret=SSL_use_certificate(ssl,x); | ||
| 171 | X509_free(x); | ||
| 172 | return(ret); | ||
| 173 | } | ||
| 174 | |||
| 175 | #ifndef NO_RSA | ||
| 176 | int SSL_use_RSAPrivateKey(ssl, rsa) | ||
| 177 | SSL *ssl; | ||
| 178 | RSA *rsa; | ||
| 179 | { | ||
| 180 | CERT *c; | ||
| 181 | EVP_PKEY *pkey; | ||
| 182 | int ret; | ||
| 183 | |||
| 184 | if (rsa == NULL) | ||
| 185 | { | ||
| 186 | SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY,ERR_R_PASSED_NULL_PARAMETER); | ||
| 187 | return(0); | ||
| 188 | } | ||
| 189 | |||
| 190 | if ((ssl->cert == NULL) || (ssl->cert == ssl->ctx->default_cert)) | ||
| 191 | { | ||
| 192 | c=ssl_cert_new(); | ||
| 193 | if (c == NULL) | ||
| 194 | { | ||
| 195 | SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY,ERR_R_MALLOC_FAILURE); | ||
| 196 | return(0); | ||
| 197 | } | ||
| 198 | if (ssl->cert != NULL) ssl_cert_free(ssl->cert); | ||
| 199 | ssl->cert=c; | ||
| 200 | } | ||
| 201 | c=ssl->cert; | ||
| 202 | if ((pkey=EVP_PKEY_new()) == NULL) | ||
| 203 | { | ||
| 204 | SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY,ERR_R_EVP_LIB); | ||
| 205 | return(0); | ||
| 206 | } | ||
| 207 | |||
| 208 | CRYPTO_add(&rsa->references,1,CRYPTO_LOCK_RSA); | ||
| 209 | EVP_PKEY_assign_RSA(pkey,rsa); | ||
| 210 | |||
| 211 | ret=ssl_set_pkey(c,pkey); | ||
| 212 | EVP_PKEY_free(pkey); | ||
| 213 | return(ret); | ||
| 214 | } | ||
| 215 | #endif | ||
| 216 | |||
| 217 | static int ssl_set_pkey(c,pkey) | ||
| 218 | CERT *c; | ||
| 219 | EVP_PKEY *pkey; | ||
| 220 | { | ||
| 221 | int i,ok=0,bad=0; | ||
| 222 | |||
| 223 | i=ssl_cert_type(NULL,pkey); | ||
| 224 | if (i < 0) | ||
| 225 | { | ||
| 226 | SSLerr(SSL_F_SSL_SET_PKEY,SSL_R_UNKNOWN_CERTIFICATE_TYPE); | ||
| 227 | return(0); | ||
| 228 | } | ||
| 229 | |||
| 230 | if (c->pkeys[i].x509 != NULL) | ||
| 231 | { | ||
| 232 | #ifndef NO_RSA | ||
| 233 | /* Don't check the public/private key, this is mostly | ||
| 234 | * for smart cards. */ | ||
| 235 | if ((pkey->type == EVP_PKEY_RSA) && | ||
| 236 | (RSA_flags(pkey->pkey.rsa) & | ||
| 237 | RSA_METHOD_FLAG_NO_CHECK)) | ||
| 238 | ok=1; | ||
| 239 | else | ||
| 240 | #endif | ||
| 241 | if (!X509_check_private_key(c->pkeys[i].x509,pkey)) | ||
| 242 | { | ||
| 243 | if ((i == SSL_PKEY_DH_RSA) || (i == SSL_PKEY_DH_DSA)) | ||
| 244 | { | ||
| 245 | i=(i == SSL_PKEY_DH_RSA)? | ||
| 246 | SSL_PKEY_DH_DSA:SSL_PKEY_DH_RSA; | ||
| 247 | |||
| 248 | if (c->pkeys[i].x509 == NULL) | ||
| 249 | ok=1; | ||
| 250 | else | ||
| 251 | { | ||
| 252 | if (!X509_check_private_key( | ||
| 253 | c->pkeys[i].x509,pkey)) | ||
| 254 | bad=1; | ||
| 255 | else | ||
| 256 | ok=1; | ||
| 257 | } | ||
| 258 | } | ||
| 259 | else | ||
| 260 | bad=1; | ||
| 261 | } | ||
| 262 | else | ||
| 263 | ok=1; | ||
| 264 | } | ||
| 265 | else | ||
| 266 | ok=1; | ||
| 267 | |||
| 268 | if (bad) | ||
| 269 | { | ||
| 270 | X509_free(c->pkeys[i].x509); | ||
| 271 | c->pkeys[i].x509=NULL; | ||
| 272 | return(0); | ||
| 273 | } | ||
| 274 | |||
| 275 | if (c->pkeys[i].privatekey != NULL) | ||
| 276 | EVP_PKEY_free(c->pkeys[i].privatekey); | ||
| 277 | CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY); | ||
| 278 | c->pkeys[i].privatekey=pkey; | ||
| 279 | c->key= &(c->pkeys[i]); | ||
| 280 | |||
| 281 | c->valid=0; | ||
| 282 | return(1); | ||
| 283 | } | ||
| 284 | |||
| 285 | #ifndef NO_RSA | ||
| 286 | #ifndef NO_STDIO | ||
| 287 | int SSL_use_RSAPrivateKey_file(ssl, file, type) | ||
| 288 | SSL *ssl; | ||
| 289 | char *file; | ||
| 290 | int type; | ||
| 291 | { | ||
| 292 | int j,ret=0; | ||
| 293 | BIO *in; | ||
| 294 | RSA *rsa=NULL; | ||
| 295 | |||
| 296 | in=BIO_new(BIO_s_file_internal()); | ||
| 297 | if (in == NULL) | ||
| 298 | { | ||
| 299 | SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,ERR_R_BUF_LIB); | ||
| 300 | goto end; | ||
| 301 | } | ||
| 302 | |||
| 303 | if (BIO_read_filename(in,file) <= 0) | ||
| 304 | { | ||
| 305 | SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,ERR_R_SYS_LIB); | ||
| 306 | goto end; | ||
| 307 | } | ||
| 308 | if (type == SSL_FILETYPE_ASN1) | ||
| 309 | { | ||
| 310 | j=ERR_R_ASN1_LIB; | ||
| 311 | rsa=d2i_RSAPrivateKey_bio(in,NULL); | ||
| 312 | } | ||
| 313 | else if (type == SSL_FILETYPE_PEM) | ||
| 314 | { | ||
| 315 | j=ERR_R_PEM_LIB; | ||
| 316 | rsa=PEM_read_bio_RSAPrivateKey(in,NULL, | ||
| 317 | ssl->ctx->default_passwd_callback); | ||
| 318 | } | ||
| 319 | else | ||
| 320 | { | ||
| 321 | SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE); | ||
| 322 | goto end; | ||
| 323 | } | ||
| 324 | if (rsa == NULL) | ||
| 325 | { | ||
| 326 | SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,j); | ||
| 327 | goto end; | ||
| 328 | } | ||
| 329 | ret=SSL_use_RSAPrivateKey(ssl,rsa); | ||
| 330 | RSA_free(rsa); | ||
| 331 | end: | ||
| 332 | if (in != NULL) BIO_free(in); | ||
| 333 | return(ret); | ||
| 334 | } | ||
| 335 | #endif | ||
| 336 | |||
| 337 | int SSL_use_RSAPrivateKey_ASN1(ssl,d,len) | ||
| 338 | SSL *ssl; | ||
| 339 | unsigned char *d; | ||
| 340 | long len; | ||
| 341 | { | ||
| 342 | int ret; | ||
| 343 | unsigned char *p; | ||
| 344 | RSA *rsa; | ||
| 345 | |||
| 346 | p=d; | ||
| 347 | if ((rsa=d2i_RSAPrivateKey(NULL,&p,(long)len)) == NULL) | ||
| 348 | { | ||
| 349 | SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1,ERR_R_ASN1_LIB); | ||
| 350 | return(0); | ||
| 351 | } | ||
| 352 | |||
| 353 | ret=SSL_use_RSAPrivateKey(ssl,rsa); | ||
| 354 | RSA_free(rsa); | ||
| 355 | return(ret); | ||
| 356 | } | ||
| 357 | #endif /* !NO_RSA */ | ||
| 358 | |||
| 359 | int SSL_use_PrivateKey(ssl, pkey) | ||
| 360 | SSL *ssl; | ||
| 361 | EVP_PKEY *pkey; | ||
| 362 | { | ||
| 363 | CERT *c; | ||
| 364 | int ret; | ||
| 365 | |||
| 366 | if (pkey == NULL) | ||
| 367 | { | ||
| 368 | SSLerr(SSL_F_SSL_USE_PRIVATEKEY,ERR_R_PASSED_NULL_PARAMETER); | ||
| 369 | return(0); | ||
| 370 | } | ||
| 371 | |||
| 372 | if ((ssl->cert == NULL) || (ssl->cert == ssl->ctx->default_cert)) | ||
| 373 | { | ||
| 374 | c=ssl_cert_new(); | ||
| 375 | if (c == NULL) | ||
| 376 | { | ||
| 377 | SSLerr(SSL_F_SSL_USE_PRIVATEKEY,ERR_R_MALLOC_FAILURE); | ||
| 378 | return(0); | ||
| 379 | } | ||
| 380 | if (ssl->cert != NULL) ssl_cert_free(ssl->cert); | ||
| 381 | ssl->cert=c; | ||
| 382 | } | ||
| 383 | c=ssl->cert; | ||
| 384 | |||
| 385 | ret=ssl_set_pkey(c,pkey); | ||
| 386 | return(ret); | ||
| 387 | } | ||
| 388 | |||
| 389 | #ifndef NO_STDIO | ||
| 390 | int SSL_use_PrivateKey_file(ssl, file, type) | ||
| 391 | SSL *ssl; | ||
| 392 | char *file; | ||
| 393 | int type; | ||
| 394 | { | ||
| 395 | int j,ret=0; | ||
| 396 | BIO *in; | ||
| 397 | EVP_PKEY *pkey=NULL; | ||
| 398 | |||
| 399 | in=BIO_new(BIO_s_file_internal()); | ||
| 400 | if (in == NULL) | ||
| 401 | { | ||
| 402 | SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,ERR_R_BUF_LIB); | ||
| 403 | goto end; | ||
| 404 | } | ||
| 405 | |||
| 406 | if (BIO_read_filename(in,file) <= 0) | ||
| 407 | { | ||
| 408 | SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,ERR_R_SYS_LIB); | ||
| 409 | goto end; | ||
| 410 | } | ||
| 411 | if (type == SSL_FILETYPE_PEM) | ||
| 412 | { | ||
| 413 | j=ERR_R_PEM_LIB; | ||
| 414 | pkey=PEM_read_bio_PrivateKey(in,NULL, | ||
| 415 | ssl->ctx->default_passwd_callback); | ||
| 416 | } | ||
| 417 | else | ||
| 418 | { | ||
| 419 | SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE); | ||
| 420 | goto end; | ||
| 421 | } | ||
| 422 | if (pkey == NULL) | ||
| 423 | { | ||
| 424 | SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,j); | ||
| 425 | goto end; | ||
| 426 | } | ||
| 427 | ret=SSL_use_PrivateKey(ssl,pkey); | ||
| 428 | EVP_PKEY_free(pkey); | ||
| 429 | end: | ||
| 430 | if (in != NULL) BIO_free(in); | ||
| 431 | return(ret); | ||
| 432 | } | ||
| 433 | #endif | ||
| 434 | |||
| 435 | int SSL_use_PrivateKey_ASN1(type,ssl,d,len) | ||
| 436 | int type; | ||
| 437 | SSL *ssl; | ||
| 438 | unsigned char *d; | ||
| 439 | long len; | ||
| 440 | { | ||
| 441 | int ret; | ||
| 442 | unsigned char *p; | ||
| 443 | EVP_PKEY *pkey; | ||
| 444 | |||
| 445 | p=d; | ||
| 446 | if ((pkey=d2i_PrivateKey(type,NULL,&p,(long)len)) == NULL) | ||
| 447 | { | ||
| 448 | SSLerr(SSL_F_SSL_USE_PRIVATEKEY_ASN1,ERR_R_ASN1_LIB); | ||
| 449 | return(0); | ||
| 450 | } | ||
| 451 | |||
| 452 | ret=SSL_use_PrivateKey(ssl,pkey); | ||
| 453 | EVP_PKEY_free(pkey); | ||
| 454 | return(ret); | ||
| 455 | } | ||
| 456 | |||
| 457 | int SSL_CTX_use_certificate(ctx, x) | ||
| 458 | SSL_CTX *ctx; | ||
| 459 | X509 *x; | ||
| 460 | { | ||
| 461 | CERT *c; | ||
| 462 | |||
| 463 | if (x == NULL) | ||
| 464 | { | ||
| 465 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE,ERR_R_PASSED_NULL_PARAMETER); | ||
| 466 | return(0); | ||
| 467 | } | ||
| 468 | |||
| 469 | if (ctx->default_cert == NULL) | ||
| 470 | { | ||
| 471 | c=ssl_cert_new(); | ||
| 472 | if (c == NULL) | ||
| 473 | { | ||
| 474 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE,ERR_R_MALLOC_FAILURE); | ||
| 475 | return(0); | ||
| 476 | } | ||
| 477 | ctx->default_cert=c; | ||
| 478 | } | ||
| 479 | c=ctx->default_cert; | ||
| 480 | |||
| 481 | return(ssl_set_cert(c,x)); | ||
| 482 | } | ||
| 483 | |||
| 484 | static int ssl_set_cert(c,x) | ||
| 485 | CERT *c; | ||
| 486 | X509 *x; | ||
| 487 | { | ||
| 488 | EVP_PKEY *pkey; | ||
| 489 | int i,ok=0,bad=0; | ||
| 490 | |||
| 491 | pkey=X509_get_pubkey(x); | ||
| 492 | if (pkey == NULL) | ||
| 493 | { | ||
| 494 | SSLerr(SSL_F_SSL_SET_CERT,SSL_R_X509_LIB); | ||
| 495 | return(0); | ||
| 496 | } | ||
| 497 | |||
| 498 | i=ssl_cert_type(x,pkey); | ||
| 499 | if (i < 0) | ||
| 500 | { | ||
| 501 | SSLerr(SSL_F_SSL_SET_CERT,SSL_R_UNKNOWN_CERTIFICATE_TYPE); | ||
| 502 | return(0); | ||
| 503 | } | ||
| 504 | |||
| 505 | if (c->pkeys[i].privatekey != NULL) | ||
| 506 | { | ||
| 507 | if (!X509_check_private_key(x,c->pkeys[i].privatekey)) | ||
| 508 | { | ||
| 509 | if ((i == SSL_PKEY_DH_RSA) || (i == SSL_PKEY_DH_DSA)) | ||
| 510 | { | ||
| 511 | i=(i == SSL_PKEY_DH_RSA)? | ||
| 512 | SSL_PKEY_DH_DSA:SSL_PKEY_DH_RSA; | ||
| 513 | |||
| 514 | if (c->pkeys[i].privatekey == NULL) | ||
| 515 | ok=1; | ||
| 516 | else | ||
| 517 | { | ||
| 518 | if (!X509_check_private_key(x, | ||
| 519 | c->pkeys[i].privatekey)) | ||
| 520 | bad=1; | ||
| 521 | else | ||
| 522 | ok=1; | ||
| 523 | } | ||
| 524 | } | ||
| 525 | else | ||
| 526 | bad=1; | ||
| 527 | } | ||
| 528 | else | ||
| 529 | ok=1; | ||
| 530 | } | ||
| 531 | else | ||
| 532 | ok=1; | ||
| 533 | |||
| 534 | if (bad) | ||
| 535 | { | ||
| 536 | EVP_PKEY_free(c->pkeys[i].privatekey); | ||
| 537 | c->pkeys[i].privatekey=NULL; | ||
| 538 | } | ||
| 539 | |||
| 540 | if (c->pkeys[i].x509 != NULL) | ||
| 541 | X509_free(c->pkeys[i].x509); | ||
| 542 | CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509); | ||
| 543 | c->pkeys[i].x509=x; | ||
| 544 | c->key= &(c->pkeys[i]); | ||
| 545 | |||
| 546 | c->valid=0; | ||
| 547 | return(1); | ||
| 548 | } | ||
| 549 | |||
| 550 | #ifndef NO_STDIO | ||
| 551 | int SSL_CTX_use_certificate_file(ctx, file, type) | ||
| 552 | SSL_CTX *ctx; | ||
| 553 | char *file; | ||
| 554 | int type; | ||
| 555 | { | ||
| 556 | int j; | ||
| 557 | BIO *in; | ||
| 558 | int ret=0; | ||
| 559 | X509 *x=NULL; | ||
| 560 | |||
| 561 | in=BIO_new(BIO_s_file_internal()); | ||
| 562 | if (in == NULL) | ||
| 563 | { | ||
| 564 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,ERR_R_BUF_LIB); | ||
| 565 | goto end; | ||
| 566 | } | ||
| 567 | |||
| 568 | if (BIO_read_filename(in,file) <= 0) | ||
| 569 | { | ||
| 570 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,ERR_R_SYS_LIB); | ||
| 571 | goto end; | ||
| 572 | } | ||
| 573 | if (type == SSL_FILETYPE_ASN1) | ||
| 574 | { | ||
| 575 | j=ERR_R_ASN1_LIB; | ||
| 576 | x=d2i_X509_bio(in,NULL); | ||
| 577 | } | ||
| 578 | else if (type == SSL_FILETYPE_PEM) | ||
| 579 | { | ||
| 580 | j=ERR_R_PEM_LIB; | ||
| 581 | x=PEM_read_bio_X509(in,NULL,ctx->default_passwd_callback); | ||
| 582 | } | ||
| 583 | else | ||
| 584 | { | ||
| 585 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,SSL_R_BAD_SSL_FILETYPE); | ||
| 586 | goto end; | ||
| 587 | } | ||
| 588 | |||
| 589 | if (x == NULL) | ||
| 590 | { | ||
| 591 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,j); | ||
| 592 | goto end; | ||
| 593 | } | ||
| 594 | |||
| 595 | ret=SSL_CTX_use_certificate(ctx,x); | ||
| 596 | end: | ||
| 597 | if (x != NULL) X509_free(x); | ||
| 598 | if (in != NULL) BIO_free(in); | ||
| 599 | return(ret); | ||
| 600 | } | ||
| 601 | #endif | ||
| 602 | |||
| 603 | int SSL_CTX_use_certificate_ASN1(ctx, len, d) | ||
| 604 | SSL_CTX *ctx; | ||
| 605 | int len; | ||
| 606 | unsigned char *d; | ||
| 607 | { | ||
| 608 | X509 *x; | ||
| 609 | int ret; | ||
| 610 | |||
| 611 | x=d2i_X509(NULL,&d,(long)len); | ||
| 612 | if (x == NULL) | ||
| 613 | { | ||
| 614 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1,ERR_R_ASN1_LIB); | ||
| 615 | return(0); | ||
| 616 | } | ||
| 617 | |||
| 618 | ret=SSL_CTX_use_certificate(ctx,x); | ||
| 619 | X509_free(x); | ||
| 620 | return(ret); | ||
| 621 | } | ||
| 622 | |||
| 623 | #ifndef NO_RSA | ||
| 624 | int SSL_CTX_use_RSAPrivateKey(ctx, rsa) | ||
| 625 | SSL_CTX *ctx; | ||
| 626 | RSA *rsa; | ||
| 627 | { | ||
| 628 | int ret; | ||
| 629 | CERT *c; | ||
| 630 | EVP_PKEY *pkey; | ||
| 631 | |||
| 632 | if (rsa == NULL) | ||
| 633 | { | ||
| 634 | SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,ERR_R_PASSED_NULL_PARAMETER); | ||
| 635 | return(0); | ||
| 636 | } | ||
| 637 | if (ctx->default_cert == NULL) | ||
| 638 | { | ||
| 639 | c=ssl_cert_new(); | ||
| 640 | if (c == NULL) | ||
| 641 | { | ||
| 642 | SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,ERR_R_MALLOC_FAILURE); | ||
| 643 | return(0); | ||
| 644 | } | ||
| 645 | ctx->default_cert=c; | ||
| 646 | } | ||
| 647 | c=ctx->default_cert; | ||
| 648 | |||
| 649 | if ((pkey=EVP_PKEY_new()) == NULL) | ||
| 650 | { | ||
| 651 | SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,ERR_R_EVP_LIB); | ||
| 652 | return(0); | ||
| 653 | } | ||
| 654 | |||
| 655 | CRYPTO_add(&rsa->references,1,CRYPTO_LOCK_RSA); | ||
| 656 | EVP_PKEY_assign_RSA(pkey,rsa); | ||
| 657 | |||
| 658 | ret=ssl_set_pkey(c,pkey); | ||
| 659 | EVP_PKEY_free(pkey); | ||
| 660 | return(ret); | ||
| 661 | } | ||
| 662 | |||
| 663 | #ifndef NO_STDIO | ||
| 664 | int SSL_CTX_use_RSAPrivateKey_file(ctx, file, type) | ||
| 665 | SSL_CTX *ctx; | ||
| 666 | char *file; | ||
| 667 | int type; | ||
| 668 | { | ||
| 669 | int j,ret=0; | ||
| 670 | BIO *in; | ||
| 671 | RSA *rsa=NULL; | ||
| 672 | |||
| 673 | in=BIO_new(BIO_s_file_internal()); | ||
| 674 | if (in == NULL) | ||
| 675 | { | ||
| 676 | SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,ERR_R_BUF_LIB); | ||
| 677 | goto end; | ||
| 678 | } | ||
| 679 | |||
| 680 | if (BIO_read_filename(in,file) <= 0) | ||
| 681 | { | ||
| 682 | SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,ERR_R_SYS_LIB); | ||
| 683 | goto end; | ||
| 684 | } | ||
| 685 | if (type == SSL_FILETYPE_ASN1) | ||
| 686 | { | ||
| 687 | j=ERR_R_ASN1_LIB; | ||
| 688 | rsa=d2i_RSAPrivateKey_bio(in,NULL); | ||
| 689 | } | ||
| 690 | else if (type == SSL_FILETYPE_PEM) | ||
| 691 | { | ||
| 692 | j=ERR_R_PEM_LIB; | ||
| 693 | rsa=PEM_read_bio_RSAPrivateKey(in,NULL, | ||
| 694 | ctx->default_passwd_callback); | ||
| 695 | } | ||
| 696 | else | ||
| 697 | { | ||
| 698 | SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE); | ||
| 699 | goto end; | ||
| 700 | } | ||
| 701 | if (rsa == NULL) | ||
| 702 | { | ||
| 703 | SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,j); | ||
| 704 | goto end; | ||
| 705 | } | ||
| 706 | ret=SSL_CTX_use_RSAPrivateKey(ctx,rsa); | ||
| 707 | RSA_free(rsa); | ||
| 708 | end: | ||
| 709 | if (in != NULL) BIO_free(in); | ||
| 710 | return(ret); | ||
| 711 | } | ||
| 712 | #endif | ||
| 713 | |||
| 714 | int SSL_CTX_use_RSAPrivateKey_ASN1(ctx,d,len) | ||
| 715 | SSL_CTX *ctx; | ||
| 716 | unsigned char *d; | ||
| 717 | long len; | ||
| 718 | { | ||
| 719 | int ret; | ||
| 720 | unsigned char *p; | ||
| 721 | RSA *rsa; | ||
| 722 | |||
| 723 | p=d; | ||
| 724 | if ((rsa=d2i_RSAPrivateKey(NULL,&p,(long)len)) == NULL) | ||
| 725 | { | ||
| 726 | SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1,ERR_R_ASN1_LIB); | ||
| 727 | return(0); | ||
| 728 | } | ||
| 729 | |||
| 730 | ret=SSL_CTX_use_RSAPrivateKey(ctx,rsa); | ||
| 731 | RSA_free(rsa); | ||
| 732 | return(ret); | ||
| 733 | } | ||
| 734 | #endif /* !NO_RSA */ | ||
| 735 | |||
| 736 | int SSL_CTX_use_PrivateKey(ctx, pkey) | ||
| 737 | SSL_CTX *ctx; | ||
| 738 | EVP_PKEY *pkey; | ||
| 739 | { | ||
| 740 | CERT *c; | ||
| 741 | |||
| 742 | if (pkey == NULL) | ||
| 743 | { | ||
| 744 | SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY,ERR_R_PASSED_NULL_PARAMETER); | ||
| 745 | return(0); | ||
| 746 | } | ||
| 747 | |||
| 748 | if (ctx->default_cert == NULL) | ||
| 749 | { | ||
| 750 | c=ssl_cert_new(); | ||
| 751 | if (c == NULL) | ||
| 752 | { | ||
| 753 | SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY,ERR_R_MALLOC_FAILURE); | ||
| 754 | return(0); | ||
| 755 | } | ||
| 756 | ctx->default_cert=c; | ||
| 757 | } | ||
| 758 | c=ctx->default_cert; | ||
| 759 | |||
| 760 | return(ssl_set_pkey(c,pkey)); | ||
| 761 | } | ||
| 762 | |||
| 763 | #ifndef NO_STDIO | ||
| 764 | int SSL_CTX_use_PrivateKey_file(ctx, file, type) | ||
| 765 | SSL_CTX *ctx; | ||
| 766 | char *file; | ||
| 767 | int type; | ||
| 768 | { | ||
| 769 | int j,ret=0; | ||
| 770 | BIO *in; | ||
| 771 | EVP_PKEY *pkey=NULL; | ||
| 772 | |||
| 773 | in=BIO_new(BIO_s_file_internal()); | ||
| 774 | if (in == NULL) | ||
| 775 | { | ||
| 776 | SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,ERR_R_BUF_LIB); | ||
| 777 | goto end; | ||
| 778 | } | ||
| 779 | |||
| 780 | if (BIO_read_filename(in,file) <= 0) | ||
| 781 | { | ||
| 782 | SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,ERR_R_SYS_LIB); | ||
| 783 | goto end; | ||
| 784 | } | ||
| 785 | if (type == SSL_FILETYPE_PEM) | ||
| 786 | { | ||
| 787 | j=ERR_R_PEM_LIB; | ||
| 788 | pkey=PEM_read_bio_PrivateKey(in,NULL, | ||
| 789 | ctx->default_passwd_callback); | ||
| 790 | } | ||
| 791 | else | ||
| 792 | { | ||
| 793 | SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE); | ||
| 794 | goto end; | ||
| 795 | } | ||
| 796 | if (pkey == NULL) | ||
| 797 | { | ||
| 798 | SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,j); | ||
| 799 | goto end; | ||
| 800 | } | ||
| 801 | ret=SSL_CTX_use_PrivateKey(ctx,pkey); | ||
| 802 | EVP_PKEY_free(pkey); | ||
| 803 | end: | ||
| 804 | if (in != NULL) BIO_free(in); | ||
| 805 | return(ret); | ||
| 806 | } | ||
| 807 | #endif | ||
| 808 | |||
| 809 | int SSL_CTX_use_PrivateKey_ASN1(type,ctx,d,len) | ||
| 810 | int type; | ||
| 811 | SSL_CTX *ctx; | ||
| 812 | unsigned char *d; | ||
| 813 | long len; | ||
| 814 | { | ||
| 815 | int ret; | ||
| 816 | unsigned char *p; | ||
| 817 | EVP_PKEY *pkey; | ||
| 818 | |||
| 819 | p=d; | ||
| 820 | if ((pkey=d2i_PrivateKey(type,NULL,&p,(long)len)) == NULL) | ||
| 821 | { | ||
| 822 | SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1,ERR_R_ASN1_LIB); | ||
| 823 | return(0); | ||
| 824 | } | ||
| 825 | |||
| 826 | ret=SSL_CTX_use_PrivateKey(ctx,pkey); | ||
| 827 | EVP_PKEY_free(pkey); | ||
| 828 | return(ret); | ||
| 829 | } | ||
| 830 | |||
| 831 | |||
diff --git a/src/lib/libssl/ssl_sess.c b/src/lib/libssl/ssl_sess.c new file mode 100644 index 0000000000..8212600e40 --- /dev/null +++ b/src/lib/libssl/ssl_sess.c | |||
| @@ -0,0 +1,582 @@ | |||
| 1 | /* ssl/ssl_sess.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 "lhash.h" | ||
| 61 | #include "rand.h" | ||
| 62 | #include "ssl_locl.h" | ||
| 63 | |||
| 64 | #ifndef NOPROTO | ||
| 65 | static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s); | ||
| 66 | static void SSL_SESSION_list_add(SSL_CTX *ctx,SSL_SESSION *s); | ||
| 67 | #else | ||
| 68 | static void SSL_SESSION_list_remove(); | ||
| 69 | static void SSL_SESSION_list_add(); | ||
| 70 | #endif | ||
| 71 | |||
| 72 | static ssl_session_num=0; | ||
| 73 | static STACK *ssl_session_meth=NULL; | ||
| 74 | |||
| 75 | SSL_SESSION *SSL_get_session(ssl) | ||
| 76 | SSL *ssl; | ||
| 77 | { | ||
| 78 | return(ssl->session); | ||
| 79 | } | ||
| 80 | |||
| 81 | int SSL_SESSION_get_ex_new_index(argl,argp,new_func,dup_func,free_func) | ||
| 82 | long argl; | ||
| 83 | char *argp; | ||
| 84 | int (*new_func)(); | ||
| 85 | int (*dup_func)(); | ||
| 86 | void (*free_func)(); | ||
| 87 | { | ||
| 88 | ssl_session_num++; | ||
| 89 | return(CRYPTO_get_ex_new_index(ssl_session_num-1, | ||
| 90 | &ssl_session_meth, | ||
| 91 | argl,argp,new_func,dup_func,free_func)); | ||
| 92 | } | ||
| 93 | |||
| 94 | int SSL_SESSION_set_ex_data(s,idx,arg) | ||
| 95 | SSL_SESSION *s; | ||
| 96 | int idx; | ||
| 97 | char *arg; | ||
| 98 | { | ||
| 99 | return(CRYPTO_set_ex_data(&s->ex_data,idx,arg)); | ||
| 100 | } | ||
| 101 | |||
| 102 | char *SSL_SESSION_get_ex_data(s,idx) | ||
| 103 | SSL_SESSION *s; | ||
| 104 | int idx; | ||
| 105 | { | ||
| 106 | return(CRYPTO_get_ex_data(&s->ex_data,idx)); | ||
| 107 | } | ||
| 108 | |||
| 109 | SSL_SESSION *SSL_SESSION_new() | ||
| 110 | { | ||
| 111 | SSL_SESSION *ss; | ||
| 112 | |||
| 113 | ss=(SSL_SESSION *)Malloc(sizeof(SSL_SESSION)); | ||
| 114 | if (ss == NULL) | ||
| 115 | { | ||
| 116 | SSLerr(SSL_F_SSL_SESSION_NEW,ERR_R_MALLOC_FAILURE); | ||
| 117 | return(0); | ||
| 118 | } | ||
| 119 | memset(ss,0,sizeof(SSL_SESSION)); | ||
| 120 | |||
| 121 | ss->references=1; | ||
| 122 | ss->timeout=60*5+4; /* 5 minute timeout by default */ | ||
| 123 | ss->time=time(NULL); | ||
| 124 | ss->prev=NULL; | ||
| 125 | ss->next=NULL; | ||
| 126 | CRYPTO_new_ex_data(ssl_session_meth,(char *)ss,&ss->ex_data); | ||
| 127 | return(ss); | ||
| 128 | } | ||
| 129 | |||
| 130 | int ssl_get_new_session(s, session) | ||
| 131 | SSL *s; | ||
| 132 | int session; | ||
| 133 | { | ||
| 134 | SSL_SESSION *ss=NULL; | ||
| 135 | |||
| 136 | if ((ss=SSL_SESSION_new()) == NULL) return(0); | ||
| 137 | |||
| 138 | /* If the context has a default timeout, use it */ | ||
| 139 | if (s->ctx->session_timeout != 0) | ||
| 140 | ss->timeout=SSL_get_default_timeout(s); | ||
| 141 | |||
| 142 | if (s->session != NULL) | ||
| 143 | { | ||
| 144 | SSL_SESSION_free(s->session); | ||
| 145 | s->session=NULL; | ||
| 146 | } | ||
| 147 | |||
| 148 | if (session) | ||
| 149 | { | ||
| 150 | if (s->version == SSL2_CLIENT_VERSION) | ||
| 151 | { | ||
| 152 | ss->ssl_version=SSL2_VERSION; | ||
| 153 | ss->session_id_length=SSL2_SSL_SESSION_ID_LENGTH; | ||
| 154 | } | ||
| 155 | else if (s->version == SSL3_VERSION) | ||
| 156 | { | ||
| 157 | ss->ssl_version=SSL3_VERSION; | ||
| 158 | ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH; | ||
| 159 | } | ||
| 160 | else if (s->version == TLS1_VERSION) | ||
| 161 | { | ||
| 162 | ss->ssl_version=TLS1_VERSION; | ||
| 163 | ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH; | ||
| 164 | } | ||
| 165 | else | ||
| 166 | { | ||
| 167 | SSLerr(SSL_F_SSL_GET_NEW_SESSION,SSL_R_UNSUPPORTED_SSL_VERSION); | ||
| 168 | SSL_SESSION_free(ss); | ||
| 169 | return(0); | ||
| 170 | } | ||
| 171 | |||
| 172 | for (;;) | ||
| 173 | { | ||
| 174 | SSL_SESSION *r; | ||
| 175 | |||
| 176 | RAND_bytes(ss->session_id,ss->session_id_length); | ||
| 177 | CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX); | ||
| 178 | r=(SSL_SESSION *)lh_retrieve(s->ctx->sessions, | ||
| 179 | (char *)ss); | ||
| 180 | CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX); | ||
| 181 | if (r == NULL) break; | ||
| 182 | /* else - woops a session_id match */ | ||
| 183 | } | ||
| 184 | } | ||
| 185 | else | ||
| 186 | { | ||
| 187 | ss->session_id_length=0; | ||
| 188 | } | ||
| 189 | |||
| 190 | s->session=ss; | ||
| 191 | ss->ssl_version=s->version; | ||
| 192 | |||
| 193 | return(1); | ||
| 194 | } | ||
| 195 | |||
| 196 | int ssl_get_prev_session(s,session_id,len) | ||
| 197 | SSL *s; | ||
| 198 | unsigned char *session_id; | ||
| 199 | int len; | ||
| 200 | { | ||
| 201 | SSL_SESSION *ret=NULL,data; | ||
| 202 | |||
| 203 | /* conn_init();*/ | ||
| 204 | data.ssl_version=s->version; | ||
| 205 | data.session_id_length=len; | ||
| 206 | if (len > SSL_MAX_SSL_SESSION_ID_LENGTH) | ||
| 207 | return(0); | ||
| 208 | memcpy(data.session_id,session_id,len);; | ||
| 209 | |||
| 210 | if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_LOOKUP)) | ||
| 211 | { | ||
| 212 | CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX); | ||
| 213 | ret=(SSL_SESSION *)lh_retrieve(s->ctx->sessions,(char *)&data); | ||
| 214 | CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX); | ||
| 215 | } | ||
| 216 | |||
| 217 | if (ret == NULL) | ||
| 218 | { | ||
| 219 | int copy=1; | ||
| 220 | |||
| 221 | s->ctx->sess_miss++; | ||
| 222 | ret=NULL; | ||
| 223 | if ((s->ctx->get_session_cb != NULL) && | ||
| 224 | ((ret=s->ctx->get_session_cb(s,session_id,len,©)) | ||
| 225 | != NULL)) | ||
| 226 | { | ||
| 227 | s->ctx->sess_cb_hit++; | ||
| 228 | |||
| 229 | /* The following should not return 1, otherwise, | ||
| 230 | * things are very strange */ | ||
| 231 | SSL_CTX_add_session(s->ctx,ret); | ||
| 232 | /* auto free it */ | ||
| 233 | if (!copy) | ||
| 234 | SSL_SESSION_free(ret); | ||
| 235 | } | ||
| 236 | if (ret == NULL) return(0); | ||
| 237 | } | ||
| 238 | |||
| 239 | if (ret->cipher == NULL) | ||
| 240 | { | ||
| 241 | char buf[5],*p; | ||
| 242 | unsigned long l; | ||
| 243 | |||
| 244 | p=buf; | ||
| 245 | l=ret->cipher_id; | ||
| 246 | l2n(l,p); | ||
| 247 | if ((ret->ssl_version>>8) == SSL3_VERSION_MAJOR) | ||
| 248 | ret->cipher=ssl_get_cipher_by_char(s,&(buf[2])); | ||
| 249 | else | ||
| 250 | ret->cipher=ssl_get_cipher_by_char(s,&(buf[1])); | ||
| 251 | if (ret->cipher == NULL) | ||
| 252 | return(0); | ||
| 253 | } | ||
| 254 | |||
| 255 | /* If a thread got the session, then 'swaped', and another got | ||
| 256 | * it and then due to a time-out decided to 'Free' it we could | ||
| 257 | * be in trouble. So I'll increment it now, then double decrement | ||
| 258 | * later - am I speaking rubbish?. */ | ||
| 259 | CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION); | ||
| 260 | |||
| 261 | if ((long)(ret->time+ret->timeout) < (long)time(NULL)) /* timeout */ | ||
| 262 | { | ||
| 263 | s->ctx->sess_timeout++; | ||
| 264 | /* remove it from the cache */ | ||
| 265 | SSL_CTX_remove_session(s->ctx,ret); | ||
| 266 | SSL_SESSION_free(ret); /* again to actually Free it */ | ||
| 267 | return(0); | ||
| 268 | } | ||
| 269 | |||
| 270 | s->ctx->sess_hit++; | ||
| 271 | |||
| 272 | /* ret->time=time(NULL); */ /* rezero timeout? */ | ||
| 273 | /* again, just leave the session | ||
| 274 | * if it is the same session, we have just incremented and | ||
| 275 | * then decremented the reference count :-) */ | ||
| 276 | if (s->session != NULL) | ||
| 277 | SSL_SESSION_free(s->session); | ||
| 278 | s->session=ret; | ||
| 279 | return(1); | ||
| 280 | } | ||
| 281 | |||
| 282 | int SSL_CTX_add_session(ctx,c) | ||
| 283 | SSL_CTX *ctx; | ||
| 284 | SSL_SESSION *c; | ||
| 285 | { | ||
| 286 | int ret=0; | ||
| 287 | SSL_SESSION *s; | ||
| 288 | |||
| 289 | /* conn_init(); */ | ||
| 290 | CRYPTO_add(&c->references,1,CRYPTO_LOCK_SSL_SESSION); | ||
| 291 | |||
| 292 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX); | ||
| 293 | s=(SSL_SESSION *)lh_insert(ctx->sessions,(char *)c); | ||
| 294 | |||
| 295 | /* Put on the end of the queue unless it is already in the cache */ | ||
| 296 | if (s == NULL) | ||
| 297 | SSL_SESSION_list_add(ctx,c); | ||
| 298 | |||
| 299 | /* If the same session if is being 're-added', Free the old | ||
| 300 | * one when the last person stops using it. | ||
| 301 | * This will also work if it is alread in the cache. | ||
| 302 | * The references will go up and then down :-) */ | ||
| 303 | if (s != NULL) | ||
| 304 | { | ||
| 305 | SSL_SESSION_free(s); | ||
| 306 | ret=0; | ||
| 307 | } | ||
| 308 | else | ||
| 309 | { | ||
| 310 | ret=1; | ||
| 311 | |||
| 312 | if (SSL_CTX_sess_get_cache_size(ctx) > 0) | ||
| 313 | { | ||
| 314 | while (SSL_CTX_sess_number(ctx) > | ||
| 315 | SSL_CTX_sess_get_cache_size(ctx)) | ||
| 316 | { | ||
| 317 | if (!SSL_CTX_remove_session(ctx, | ||
| 318 | ctx->session_cache_tail)) | ||
| 319 | break; | ||
| 320 | else | ||
| 321 | ctx->sess_cache_full++; | ||
| 322 | } | ||
| 323 | } | ||
| 324 | } | ||
| 325 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX); | ||
| 326 | return(ret); | ||
| 327 | } | ||
| 328 | |||
| 329 | int SSL_CTX_remove_session(ctx,c) | ||
| 330 | SSL_CTX *ctx; | ||
| 331 | SSL_SESSION *c; | ||
| 332 | { | ||
| 333 | SSL_SESSION *r; | ||
| 334 | int ret=0; | ||
| 335 | |||
| 336 | if ((c != NULL) && (c->session_id_length != 0)) | ||
| 337 | { | ||
| 338 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX); | ||
| 339 | r=(SSL_SESSION *)lh_delete(ctx->sessions,(char *)c); | ||
| 340 | if (r != NULL) | ||
| 341 | { | ||
| 342 | ret=1; | ||
| 343 | SSL_SESSION_list_remove(ctx,c); | ||
| 344 | } | ||
| 345 | |||
| 346 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX); | ||
| 347 | |||
| 348 | if (ret) | ||
| 349 | { | ||
| 350 | r->not_resumable=1; | ||
| 351 | if (ctx->remove_session_cb != NULL) | ||
| 352 | ctx->remove_session_cb(ctx,r); | ||
| 353 | SSL_SESSION_free(r); | ||
| 354 | } | ||
| 355 | } | ||
| 356 | else | ||
| 357 | ret=0; | ||
| 358 | return(ret); | ||
| 359 | } | ||
| 360 | |||
| 361 | void SSL_SESSION_free(ss) | ||
| 362 | SSL_SESSION *ss; | ||
| 363 | { | ||
| 364 | int i; | ||
| 365 | |||
| 366 | i=CRYPTO_add(&ss->references,-1,CRYPTO_LOCK_SSL_SESSION); | ||
| 367 | #ifdef REF_PRINT | ||
| 368 | REF_PRINT("SSL_SESSION",ss); | ||
| 369 | #endif | ||
| 370 | if (i > 0) return; | ||
| 371 | #ifdef REF_CHECK | ||
| 372 | if (i < 0) | ||
| 373 | { | ||
| 374 | fprintf(stderr,"SSL_SESSION_free, bad reference count\n"); | ||
| 375 | abort(); /* ok */ | ||
| 376 | } | ||
| 377 | #endif | ||
| 378 | |||
| 379 | CRYPTO_free_ex_data(ssl_session_meth,(char *)ss,&ss->ex_data); | ||
| 380 | |||
| 381 | memset(ss->key_arg,0,SSL_MAX_KEY_ARG_LENGTH); | ||
| 382 | memset(ss->master_key,0,SSL_MAX_MASTER_KEY_LENGTH); | ||
| 383 | memset(ss->session_id,0,SSL_MAX_SSL_SESSION_ID_LENGTH); | ||
| 384 | if (ss->cert != NULL) ssl_cert_free(ss->cert); | ||
| 385 | if (ss->peer != NULL) X509_free(ss->peer); | ||
| 386 | if (ss->ciphers != NULL) sk_free(ss->ciphers); | ||
| 387 | memset(ss,0,sizeof(*ss)); | ||
| 388 | Free(ss); | ||
| 389 | } | ||
| 390 | |||
| 391 | int SSL_set_session(s, session) | ||
| 392 | SSL *s; | ||
| 393 | SSL_SESSION *session; | ||
| 394 | { | ||
| 395 | int ret=0; | ||
| 396 | SSL_METHOD *meth; | ||
| 397 | |||
| 398 | if (session != NULL) | ||
| 399 | { | ||
| 400 | meth=s->ctx->method->get_ssl_method(session->ssl_version); | ||
| 401 | if (meth == NULL) | ||
| 402 | meth=s->method->get_ssl_method(session->ssl_version); | ||
| 403 | if (meth == NULL) | ||
| 404 | { | ||
| 405 | SSLerr(SSL_F_SSL_SET_SESSION,SSL_R_UNABLE_TO_FIND_SSL_METHOD); | ||
| 406 | return(0); | ||
| 407 | } | ||
| 408 | |||
| 409 | if (meth != s->method) | ||
| 410 | { | ||
| 411 | if (!SSL_set_ssl_method(s,meth)) | ||
| 412 | return(0); | ||
| 413 | session->timeout=SSL_get_default_timeout(s); | ||
| 414 | } | ||
| 415 | |||
| 416 | /* CRYPTO_w_lock(CRYPTO_LOCK_SSL);*/ | ||
| 417 | CRYPTO_add(&session->references,1,CRYPTO_LOCK_SSL_SESSION); | ||
| 418 | if (s->session != NULL) | ||
| 419 | SSL_SESSION_free(s->session); | ||
| 420 | s->session=session; | ||
| 421 | /* CRYPTO_w_unlock(CRYPTO_LOCK_SSL);*/ | ||
| 422 | ret=1; | ||
| 423 | } | ||
| 424 | else | ||
| 425 | { | ||
| 426 | if (s->session != NULL) | ||
| 427 | { | ||
| 428 | SSL_SESSION_free(s->session); | ||
| 429 | s->session=NULL; | ||
| 430 | } | ||
| 431 | } | ||
| 432 | return(ret); | ||
| 433 | } | ||
| 434 | |||
| 435 | long SSL_SESSION_set_timeout(s,t) | ||
| 436 | SSL_SESSION *s; | ||
| 437 | long t; | ||
| 438 | { | ||
| 439 | if (s == NULL) return(0); | ||
| 440 | s->timeout=t; | ||
| 441 | return(1); | ||
| 442 | } | ||
| 443 | |||
| 444 | long SSL_SESSION_get_timeout(s) | ||
| 445 | SSL_SESSION *s; | ||
| 446 | { | ||
| 447 | if (s == NULL) return(0); | ||
| 448 | return(s->timeout); | ||
| 449 | } | ||
| 450 | |||
| 451 | long SSL_SESSION_get_time(s) | ||
| 452 | SSL_SESSION *s; | ||
| 453 | { | ||
| 454 | if (s == NULL) return(0); | ||
| 455 | return(s->time); | ||
| 456 | } | ||
| 457 | |||
| 458 | long SSL_SESSION_set_time(s,t) | ||
| 459 | SSL_SESSION *s; | ||
| 460 | long t; | ||
| 461 | { | ||
| 462 | if (s == NULL) return(0); | ||
| 463 | s->time=t; | ||
| 464 | return(t); | ||
| 465 | } | ||
| 466 | |||
| 467 | typedef struct timeout_param_st | ||
| 468 | { | ||
| 469 | SSL_CTX *ctx; | ||
| 470 | long time; | ||
| 471 | LHASH *cache; | ||
| 472 | } TIMEOUT_PARAM; | ||
| 473 | |||
| 474 | static void timeout(s,p) | ||
| 475 | SSL_SESSION *s; | ||
| 476 | TIMEOUT_PARAM *p; | ||
| 477 | { | ||
| 478 | if ((p->time == 0) || (p->time > (s->time+s->timeout))) /* timeout */ | ||
| 479 | { | ||
| 480 | /* The reason we don't call SSL_CTX_remove_session() is to | ||
| 481 | * save on locking overhead */ | ||
| 482 | lh_delete(p->cache,(char *)s); | ||
| 483 | SSL_SESSION_list_remove(p->ctx,s); | ||
| 484 | s->not_resumable=1; | ||
| 485 | if (p->ctx->remove_session_cb != NULL) | ||
| 486 | p->ctx->remove_session_cb(p->ctx,s); | ||
| 487 | SSL_SESSION_free(s); | ||
| 488 | } | ||
| 489 | } | ||
| 490 | |||
| 491 | void SSL_CTX_flush_sessions(s,t) | ||
| 492 | SSL_CTX *s; | ||
| 493 | long t; | ||
| 494 | { | ||
| 495 | unsigned long i; | ||
| 496 | TIMEOUT_PARAM tp; | ||
| 497 | |||
| 498 | tp.ctx=s; | ||
| 499 | tp.cache=SSL_CTX_sessions(s); | ||
| 500 | if (tp.cache == NULL) return; | ||
| 501 | tp.time=t; | ||
| 502 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX); | ||
| 503 | i=tp.cache->down_load; | ||
| 504 | tp.cache->down_load=0; | ||
| 505 | lh_doall_arg(tp.cache,(void (*)())timeout,(char *)&tp); | ||
| 506 | tp.cache->down_load=i; | ||
| 507 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX); | ||
| 508 | } | ||
| 509 | |||
| 510 | int ssl_clear_bad_session(s) | ||
| 511 | SSL *s; | ||
| 512 | { | ||
| 513 | if ( (s->session != NULL) && | ||
| 514 | !(s->shutdown & SSL_SENT_SHUTDOWN) && | ||
| 515 | !(SSL_in_init(s) || SSL_in_before(s))) | ||
| 516 | { | ||
| 517 | SSL_CTX_remove_session(s->ctx,s->session); | ||
| 518 | return(1); | ||
| 519 | } | ||
| 520 | else | ||
| 521 | return(0); | ||
| 522 | } | ||
| 523 | |||
| 524 | /* locked by SSL_CTX in the calling function */ | ||
| 525 | static void SSL_SESSION_list_remove(ctx,s) | ||
| 526 | SSL_CTX *ctx; | ||
| 527 | SSL_SESSION *s; | ||
| 528 | { | ||
| 529 | if ((s->next == NULL) || (s->prev == NULL)) return; | ||
| 530 | |||
| 531 | if (s->next == (SSL_SESSION *)&(ctx->session_cache_tail)) | ||
| 532 | { /* last element in list */ | ||
| 533 | if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head)) | ||
| 534 | { /* only one element in list */ | ||
| 535 | ctx->session_cache_head=NULL; | ||
| 536 | ctx->session_cache_tail=NULL; | ||
| 537 | } | ||
| 538 | else | ||
| 539 | { | ||
| 540 | ctx->session_cache_tail=s->prev; | ||
| 541 | s->prev->next=(SSL_SESSION *)&(ctx->session_cache_tail); | ||
| 542 | } | ||
| 543 | } | ||
| 544 | else | ||
| 545 | { | ||
| 546 | if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head)) | ||
| 547 | { /* first element in list */ | ||
| 548 | ctx->session_cache_head=s->next; | ||
| 549 | s->next->prev=(SSL_SESSION *)&(ctx->session_cache_head); | ||
| 550 | } | ||
| 551 | else | ||
| 552 | { /* middle of list */ | ||
| 553 | s->next->prev=s->prev; | ||
| 554 | s->prev->next=s->next; | ||
| 555 | } | ||
| 556 | } | ||
| 557 | s->prev=s->next=NULL; | ||
| 558 | } | ||
| 559 | |||
| 560 | static void SSL_SESSION_list_add(ctx,s) | ||
| 561 | SSL_CTX *ctx; | ||
| 562 | SSL_SESSION *s; | ||
| 563 | { | ||
| 564 | if ((s->next != NULL) && (s->prev != NULL)) | ||
| 565 | SSL_SESSION_list_remove(ctx,s); | ||
| 566 | |||
| 567 | if (ctx->session_cache_head == NULL) | ||
| 568 | { | ||
| 569 | ctx->session_cache_head=s; | ||
| 570 | ctx->session_cache_tail=s; | ||
| 571 | s->prev=(SSL_SESSION *)&(ctx->session_cache_head); | ||
| 572 | s->next=(SSL_SESSION *)&(ctx->session_cache_tail); | ||
| 573 | } | ||
| 574 | else | ||
| 575 | { | ||
| 576 | s->next=ctx->session_cache_head; | ||
| 577 | s->next->prev=s; | ||
| 578 | s->prev=(SSL_SESSION *)&(ctx->session_cache_head); | ||
| 579 | ctx->session_cache_head=s; | ||
| 580 | } | ||
| 581 | } | ||
| 582 | |||
diff --git a/src/lib/libssl/ssl_stat.c b/src/lib/libssl/ssl_stat.c new file mode 100644 index 0000000000..a1daf25dd4 --- /dev/null +++ b/src/lib/libssl/ssl_stat.c | |||
| @@ -0,0 +1,458 @@ | |||
| 1 | /* ssl/ssl_stat.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 "ssl_locl.h" | ||
| 61 | |||
| 62 | char *SSL_state_string_long(s) | ||
| 63 | SSL *s; | ||
| 64 | { | ||
| 65 | char *str; | ||
| 66 | |||
| 67 | switch (s->state) | ||
| 68 | { | ||
| 69 | case SSL_ST_BEFORE: str="before SSL initalisation"; break; | ||
| 70 | case SSL_ST_ACCEPT: str="before accept initalisation"; break; | ||
| 71 | case SSL_ST_CONNECT: str="before connect initalisation"; break; | ||
| 72 | case SSL_ST_OK: str="SSL negotiation finished successfully"; break; | ||
| 73 | case SSL_ST_RENEGOTIATE: str="SSL renegotiate ciphers"; break; | ||
| 74 | case SSL_ST_BEFORE|SSL_ST_CONNECT: str="before/connect initalisation"; break; | ||
| 75 | case SSL_ST_OK|SSL_ST_CONNECT: str="ok/connect SSL initalisation"; break; | ||
| 76 | case SSL_ST_BEFORE|SSL_ST_ACCEPT: str="before/accept initalisation"; break; | ||
| 77 | case SSL_ST_OK|SSL_ST_ACCEPT: str="ok/accept SSL initalisation"; break; | ||
| 78 | #ifndef NO_SSL2 | ||
| 79 | case SSL2_ST_CLIENT_START_ENCRYPTION: str="SSLv2 client start encryption"; break; | ||
| 80 | case SSL2_ST_SERVER_START_ENCRYPTION: str="SSLv2 server start encryption"; break; | ||
| 81 | case SSL2_ST_SEND_CLIENT_HELLO_A: str="SSLv2 write client hello A"; break; | ||
| 82 | case SSL2_ST_SEND_CLIENT_HELLO_B: str="SSLv2 write client hello B"; break; | ||
| 83 | case SSL2_ST_GET_SERVER_HELLO_A: str="SSLv2 read server hello A"; break; | ||
| 84 | case SSL2_ST_GET_SERVER_HELLO_B: str="SSLv2 read server hello B"; break; | ||
| 85 | case SSL2_ST_SEND_CLIENT_MASTER_KEY_A: str="SSLv2 write client master key A"; break; | ||
| 86 | case SSL2_ST_SEND_CLIENT_MASTER_KEY_B: str="SSLv2 write client master key B"; break; | ||
| 87 | case SSL2_ST_SEND_CLIENT_FINISHED_A: str="SSLv2 write client finished A"; break; | ||
| 88 | case SSL2_ST_SEND_CLIENT_FINISHED_B: str="SSLv2 write client finished B"; break; | ||
| 89 | case SSL2_ST_SEND_CLIENT_CERTIFICATE_A: str="SSLv2 write client certificate A"; break; | ||
| 90 | case SSL2_ST_SEND_CLIENT_CERTIFICATE_B: str="SSLv2 write client certificate B"; break; | ||
| 91 | case SSL2_ST_SEND_CLIENT_CERTIFICATE_C: str="SSLv2 write client certificate C"; break; | ||
| 92 | case SSL2_ST_SEND_CLIENT_CERTIFICATE_D: str="SSLv2 write client certificate D"; break; | ||
| 93 | case SSL2_ST_GET_SERVER_VERIFY_A: str="SSLv2 read server verify A"; break; | ||
| 94 | case SSL2_ST_GET_SERVER_VERIFY_B: str="SSLv2 read server verify B"; break; | ||
| 95 | case SSL2_ST_GET_SERVER_FINISHED_A: str="SSLv2 read server finished A"; break; | ||
| 96 | case SSL2_ST_GET_SERVER_FINISHED_B: str="SSLv2 read server finished B"; break; | ||
| 97 | case SSL2_ST_GET_CLIENT_HELLO_A: str="SSLv2 read client hello A"; break; | ||
| 98 | case SSL2_ST_GET_CLIENT_HELLO_B: str="SSLv2 read client hello B"; break; | ||
| 99 | case SSL2_ST_GET_CLIENT_HELLO_C: str="SSLv2 read client hello C"; break; | ||
| 100 | case SSL2_ST_SEND_SERVER_HELLO_A: str="SSLv2 write server hello A"; break; | ||
| 101 | case SSL2_ST_SEND_SERVER_HELLO_B: str="SSLv2 write server hello B"; break; | ||
| 102 | case SSL2_ST_GET_CLIENT_MASTER_KEY_A: str="SSLv2 read client master key A"; break; | ||
| 103 | case SSL2_ST_GET_CLIENT_MASTER_KEY_B: str="SSLv2 read client master key B"; break; | ||
| 104 | case SSL2_ST_SEND_SERVER_VERIFY_A: str="SSLv2 write server verify A"; break; | ||
| 105 | case SSL2_ST_SEND_SERVER_VERIFY_B: str="SSLv2 write server verify B"; break; | ||
| 106 | case SSL2_ST_SEND_SERVER_VERIFY_C: str="SSLv2 write server verify C"; break; | ||
| 107 | case SSL2_ST_GET_CLIENT_FINISHED_A: str="SSLv2 read client finished A"; break; | ||
| 108 | case SSL2_ST_GET_CLIENT_FINISHED_B: str="SSLv2 read client finished B"; break; | ||
| 109 | case SSL2_ST_SEND_SERVER_FINISHED_A: str="SSLv2 write server finished A"; break; | ||
| 110 | case SSL2_ST_SEND_SERVER_FINISHED_B: str="SSLv2 write server finished B"; break; | ||
| 111 | case SSL2_ST_SEND_REQUEST_CERTIFICATE_A: str="SSLv2 write request certificate A"; break; | ||
| 112 | case SSL2_ST_SEND_REQUEST_CERTIFICATE_B: str="SSLv2 write request certificate B"; break; | ||
| 113 | case SSL2_ST_SEND_REQUEST_CERTIFICATE_C: str="SSLv2 write request certificate C"; break; | ||
| 114 | case SSL2_ST_SEND_REQUEST_CERTIFICATE_D: str="SSLv2 write request certificate D"; break; | ||
| 115 | case SSL2_ST_X509_GET_SERVER_CERTIFICATE: str="SSLv2 X509 read server certificate"; break; | ||
| 116 | case SSL2_ST_X509_GET_CLIENT_CERTIFICATE: str="SSLv2 X509 read client certificate"; break; | ||
| 117 | #endif | ||
| 118 | |||
| 119 | #ifndef NO_SSL3 | ||
| 120 | /* SSLv3 additions */ | ||
| 121 | case SSL3_ST_CW_CLNT_HELLO_A: str="SSLv3 write client hello A"; break; | ||
| 122 | case SSL3_ST_CW_CLNT_HELLO_B: str="SSLv3 write client hello B"; break; | ||
| 123 | case SSL3_ST_CR_SRVR_HELLO_A: str="SSLv3 read server hello A"; break; | ||
| 124 | case SSL3_ST_CR_SRVR_HELLO_B: str="SSLv3 read server hello B"; break; | ||
| 125 | case SSL3_ST_CR_CERT_A: str="SSLv3 read server certificate A"; break; | ||
| 126 | case SSL3_ST_CR_CERT_B: str="SSLv3 read server certificate B"; break; | ||
| 127 | case SSL3_ST_CR_KEY_EXCH_A: str="SSLv3 read server key exchange A"; break; | ||
| 128 | case SSL3_ST_CR_KEY_EXCH_B: str="SSLv3 read server key exchange B"; break; | ||
| 129 | case SSL3_ST_CR_CERT_REQ_A: str="SSLv3 read server certificate request A"; break; | ||
| 130 | case SSL3_ST_CR_CERT_REQ_B: str="SSLv3 read server certificate request B"; break; | ||
| 131 | case SSL3_ST_CR_SRVR_DONE_A: str="SSLv3 read server done A"; break; | ||
| 132 | case SSL3_ST_CR_SRVR_DONE_B: str="SSLv3 read server done B"; break; | ||
| 133 | case SSL3_ST_CW_CERT_A: str="SSLv3 write client certificate A"; break; | ||
| 134 | case SSL3_ST_CW_CERT_B: str="SSLv3 write client certificate B"; break; | ||
| 135 | case SSL3_ST_CW_KEY_EXCH_A: str="SSLv3 write client key exchange A"; break; | ||
| 136 | case SSL3_ST_CW_KEY_EXCH_B: str="SSLv3 write client key exchange B"; break; | ||
| 137 | case SSL3_ST_CW_CERT_VRFY_A: str="SSLv3 write certificate verify A"; break; | ||
| 138 | case SSL3_ST_CW_CERT_VRFY_B: str="SSLv3 write certificate verify A"; break; | ||
| 139 | |||
| 140 | case SSL3_ST_CW_CHANGE_A: | ||
| 141 | case SSL3_ST_SW_CHANGE_A: str="SSLv3 write change cipher spec A"; break; | ||
| 142 | case SSL3_ST_CW_CHANGE_B: | ||
| 143 | case SSL3_ST_SW_CHANGE_B: str="SSLv3 write change cipher spec B"; break; | ||
| 144 | case SSL3_ST_CW_FINISHED_A: | ||
| 145 | case SSL3_ST_SW_FINISHED_A: str="SSLv3 write finished A"; break; | ||
| 146 | case SSL3_ST_CW_FINISHED_B: | ||
| 147 | case SSL3_ST_SW_FINISHED_B: str="SSLv3 write finished A"; break; | ||
| 148 | case SSL3_ST_CR_CHANGE_A: | ||
| 149 | case SSL3_ST_SR_CHANGE_A: str="SSLv3 read change cipher spec A"; break; | ||
| 150 | case SSL3_ST_CR_CHANGE_B: | ||
| 151 | case SSL3_ST_SR_CHANGE_B: str="SSLv3 read change cipher spec B"; break; | ||
| 152 | case SSL3_ST_CR_FINISHED_A: | ||
| 153 | case SSL3_ST_SR_FINISHED_A: str="SSLv3 read finished A"; break; | ||
| 154 | case SSL3_ST_CR_FINISHED_B: | ||
| 155 | case SSL3_ST_SR_FINISHED_B: str="SSLv3 read finished B"; break; | ||
| 156 | |||
| 157 | case SSL3_ST_CW_FLUSH: | ||
| 158 | case SSL3_ST_SW_FLUSH: str="SSLv3 flush data"; break; | ||
| 159 | |||
| 160 | case SSL3_ST_SR_CLNT_HELLO_A: str="SSLv3 read client hello A"; break; | ||
| 161 | case SSL3_ST_SR_CLNT_HELLO_B: str="SSLv3 read client hello B"; break; | ||
| 162 | case SSL3_ST_SR_CLNT_HELLO_C: str="SSLv3 read client hello C"; break; | ||
| 163 | case SSL3_ST_SW_HELLO_REQ_A: str="SSLv3 write hello request A"; break; | ||
| 164 | case SSL3_ST_SW_HELLO_REQ_B: str="SSLv3 write hello request B"; break; | ||
| 165 | case SSL3_ST_SW_HELLO_REQ_C: str="SSLv3 write hello request C"; break; | ||
| 166 | case SSL3_ST_SW_SRVR_HELLO_A: str="SSLv3 write server hello A"; break; | ||
| 167 | case SSL3_ST_SW_SRVR_HELLO_B: str="SSLv3 write server hello B"; break; | ||
| 168 | case SSL3_ST_SW_CERT_A: str="SSLv3 write certificate A"; break; | ||
| 169 | case SSL3_ST_SW_CERT_B: str="SSLv3 write certificate B"; break; | ||
| 170 | case SSL3_ST_SW_KEY_EXCH_A: str="SSLv3 write key exchange A"; break; | ||
| 171 | case SSL3_ST_SW_KEY_EXCH_B: str="SSLv3 write key exchange B"; break; | ||
| 172 | case SSL3_ST_SW_CERT_REQ_A: str="SSLv3 write certificate request A"; break; | ||
| 173 | case SSL3_ST_SW_CERT_REQ_B: str="SSLv3 write certificate request B"; break; | ||
| 174 | case SSL3_ST_SW_SRVR_DONE_A: str="SSLv3 write server done A"; break; | ||
| 175 | case SSL3_ST_SW_SRVR_DONE_B: str="SSLv3 write server done B"; break; | ||
| 176 | case SSL3_ST_SR_CERT_A: str="SSLv3 read client certificate A"; break; | ||
| 177 | case SSL3_ST_SR_CERT_B: str="SSLv3 read client certificate B"; break; | ||
| 178 | case SSL3_ST_SR_KEY_EXCH_A: str="SSLv3 read client key exchange A"; break; | ||
| 179 | case SSL3_ST_SR_KEY_EXCH_B: str="SSLv3 read client key exchange B"; break; | ||
| 180 | case SSL3_ST_SR_CERT_VRFY_A: str="SSLv3 read certificate verify A"; break; | ||
| 181 | case SSL3_ST_SR_CERT_VRFY_B: str="SSLv3 read certificate verify B"; break; | ||
| 182 | #endif | ||
| 183 | |||
| 184 | #if !defined(NO_SSL2) && !defined(NO_SSL3) | ||
| 185 | /* SSLv2/v3 compatablitity states */ | ||
| 186 | /* client */ | ||
| 187 | case SSL23_ST_CW_CLNT_HELLO_A: str="SSLv2/v3 write client hello A"; break; | ||
| 188 | case SSL23_ST_CW_CLNT_HELLO_B: str="SSLv2/v3 write client hello B"; break; | ||
| 189 | case SSL23_ST_CR_SRVR_HELLO_A: str="SSLv2/v3 read server hello A"; break; | ||
| 190 | case SSL23_ST_CR_SRVR_HELLO_B: str="SSLv2/v3 read server hello B"; break; | ||
| 191 | /* server */ | ||
| 192 | case SSL23_ST_SR_CLNT_HELLO_A: str="SSLv2/v3 read client hello A"; break; | ||
| 193 | case SSL23_ST_SR_CLNT_HELLO_B: str="SSLv2/v3 read client hello B"; break; | ||
| 194 | #endif | ||
| 195 | |||
| 196 | default: str="unknown state"; break; | ||
| 197 | } | ||
| 198 | return(str); | ||
| 199 | } | ||
| 200 | |||
| 201 | char *SSL_rstate_string_long(s) | ||
| 202 | SSL *s; | ||
| 203 | { | ||
| 204 | char *str; | ||
| 205 | |||
| 206 | switch (s->rstate) | ||
| 207 | { | ||
| 208 | case SSL_ST_READ_HEADER: str="read header"; break; | ||
| 209 | case SSL_ST_READ_BODY: str="read body"; break; | ||
| 210 | case SSL_ST_READ_DONE: str="read done"; break; | ||
| 211 | default: str="unknown"; break; | ||
| 212 | } | ||
| 213 | return(str); | ||
| 214 | } | ||
| 215 | |||
| 216 | char *SSL_state_string(s) | ||
| 217 | SSL *s; | ||
| 218 | { | ||
| 219 | char *str; | ||
| 220 | |||
| 221 | switch (s->state) | ||
| 222 | { | ||
| 223 | case SSL_ST_BEFORE: str="PINIT "; break; | ||
| 224 | case SSL_ST_ACCEPT: str="AINIT "; break; | ||
| 225 | case SSL_ST_CONNECT: str="CINIT "; break; | ||
| 226 | case SSL_ST_OK: str="SSLOK "; break; | ||
| 227 | #ifndef NO_SSL2 | ||
| 228 | case SSL2_ST_CLIENT_START_ENCRYPTION: str="2CSENC"; break; | ||
| 229 | case SSL2_ST_SERVER_START_ENCRYPTION: str="2SSENC"; break; | ||
| 230 | case SSL2_ST_SEND_CLIENT_HELLO_A: str="2SCH_A"; break; | ||
| 231 | case SSL2_ST_SEND_CLIENT_HELLO_B: str="2SCH_B"; break; | ||
| 232 | case SSL2_ST_GET_SERVER_HELLO_A: str="2GSH_A"; break; | ||
| 233 | case SSL2_ST_GET_SERVER_HELLO_B: str="2GSH_B"; break; | ||
| 234 | case SSL2_ST_SEND_CLIENT_MASTER_KEY_A: str="2SCMKA"; break; | ||
| 235 | case SSL2_ST_SEND_CLIENT_MASTER_KEY_B: str="2SCMKB"; break; | ||
| 236 | case SSL2_ST_SEND_CLIENT_FINISHED_A: str="2SCF_A"; break; | ||
| 237 | case SSL2_ST_SEND_CLIENT_FINISHED_B: str="2SCF_B"; break; | ||
| 238 | case SSL2_ST_SEND_CLIENT_CERTIFICATE_A: str="2SCC_A"; break; | ||
| 239 | case SSL2_ST_SEND_CLIENT_CERTIFICATE_B: str="2SCC_B"; break; | ||
| 240 | case SSL2_ST_SEND_CLIENT_CERTIFICATE_C: str="2SCC_C"; break; | ||
| 241 | case SSL2_ST_SEND_CLIENT_CERTIFICATE_D: str="2SCC_D"; break; | ||
| 242 | case SSL2_ST_GET_SERVER_VERIFY_A: str="2GSV_A"; break; | ||
| 243 | case SSL2_ST_GET_SERVER_VERIFY_B: str="2GSV_B"; break; | ||
| 244 | case SSL2_ST_GET_SERVER_FINISHED_A: str="2GSF_A"; break; | ||
| 245 | case SSL2_ST_GET_SERVER_FINISHED_B: str="2GSF_B"; break; | ||
| 246 | case SSL2_ST_GET_CLIENT_HELLO_A: str="2GCH_A"; break; | ||
| 247 | case SSL2_ST_GET_CLIENT_HELLO_B: str="2GCH_B"; break; | ||
| 248 | case SSL2_ST_GET_CLIENT_HELLO_C: str="2GCH_C"; break; | ||
| 249 | case SSL2_ST_SEND_SERVER_HELLO_A: str="2SSH_A"; break; | ||
| 250 | case SSL2_ST_SEND_SERVER_HELLO_B: str="2SSH_B"; break; | ||
| 251 | case SSL2_ST_GET_CLIENT_MASTER_KEY_A: str="2GCMKA"; break; | ||
| 252 | case SSL2_ST_GET_CLIENT_MASTER_KEY_B: str="2GCMKA"; break; | ||
| 253 | case SSL2_ST_SEND_SERVER_VERIFY_A: str="2SSV_A"; break; | ||
| 254 | case SSL2_ST_SEND_SERVER_VERIFY_B: str="2SSV_B"; break; | ||
| 255 | case SSL2_ST_SEND_SERVER_VERIFY_C: str="2SSV_C"; break; | ||
| 256 | case SSL2_ST_GET_CLIENT_FINISHED_A: str="2GCF_A"; break; | ||
| 257 | case SSL2_ST_GET_CLIENT_FINISHED_B: str="2GCF_B"; break; | ||
| 258 | case SSL2_ST_SEND_SERVER_FINISHED_A: str="2SSF_A"; break; | ||
| 259 | case SSL2_ST_SEND_SERVER_FINISHED_B: str="2SSF_B"; break; | ||
| 260 | case SSL2_ST_SEND_REQUEST_CERTIFICATE_A: str="2SRC_A"; break; | ||
| 261 | case SSL2_ST_SEND_REQUEST_CERTIFICATE_B: str="2SRC_B"; break; | ||
| 262 | case SSL2_ST_SEND_REQUEST_CERTIFICATE_C: str="2SRC_C"; break; | ||
| 263 | case SSL2_ST_SEND_REQUEST_CERTIFICATE_D: str="2SRC_D"; break; | ||
| 264 | case SSL2_ST_X509_GET_SERVER_CERTIFICATE: str="2X9GSC"; break; | ||
| 265 | case SSL2_ST_X509_GET_CLIENT_CERTIFICATE: str="2X9GCC"; break; | ||
| 266 | #endif | ||
| 267 | |||
| 268 | #ifndef NO_SSL3 | ||
| 269 | /* SSLv3 additions */ | ||
| 270 | case SSL3_ST_SW_FLUSH: | ||
| 271 | case SSL3_ST_CW_FLUSH: str="3FLUSH"; break; | ||
| 272 | case SSL3_ST_CW_CLNT_HELLO_A: str="3WCH_A"; break; | ||
| 273 | case SSL3_ST_CW_CLNT_HELLO_B: str="3WCH_B"; break; | ||
| 274 | case SSL3_ST_CR_SRVR_HELLO_A: str="3RSH_A"; break; | ||
| 275 | case SSL3_ST_CR_SRVR_HELLO_B: str="3RSH_B"; break; | ||
| 276 | case SSL3_ST_CR_CERT_A: str="3RSC_A"; break; | ||
| 277 | case SSL3_ST_CR_CERT_B: str="3RSC_B"; break; | ||
| 278 | case SSL3_ST_CR_KEY_EXCH_A: str="3RSKEA"; break; | ||
| 279 | case SSL3_ST_CR_KEY_EXCH_B: str="3RSKEB"; break; | ||
| 280 | case SSL3_ST_CR_CERT_REQ_A: str="3RCR_A"; break; | ||
| 281 | case SSL3_ST_CR_CERT_REQ_B: str="3RCR_B"; break; | ||
| 282 | case SSL3_ST_CR_SRVR_DONE_A: str="3RSD_A"; break; | ||
| 283 | case SSL3_ST_CR_SRVR_DONE_B: str="3RSD_B"; break; | ||
| 284 | case SSL3_ST_CW_CERT_A: str="3WCC_A"; break; | ||
| 285 | case SSL3_ST_CW_CERT_B: str="3WCC_B"; break; | ||
| 286 | case SSL3_ST_CW_KEY_EXCH_A: str="3WCKEA"; break; | ||
| 287 | case SSL3_ST_CW_KEY_EXCH_B: str="3WCKEB"; break; | ||
| 288 | case SSL3_ST_CW_CERT_VRFY_A: str="3WCV_A"; break; | ||
| 289 | case SSL3_ST_CW_CERT_VRFY_B: str="3WCV_B"; break; | ||
| 290 | |||
| 291 | case SSL3_ST_SW_CHANGE_A: | ||
| 292 | case SSL3_ST_CW_CHANGE_A: str="3WCCSA"; break; | ||
| 293 | case SSL3_ST_SW_CHANGE_B: | ||
| 294 | case SSL3_ST_CW_CHANGE_B: str="3WCCSB"; break; | ||
| 295 | case SSL3_ST_SW_FINISHED_A: | ||
| 296 | case SSL3_ST_CW_FINISHED_A: str="3WFINA"; break; | ||
| 297 | case SSL3_ST_SW_FINISHED_B: | ||
| 298 | case SSL3_ST_CW_FINISHED_B: str="3WFINB"; break; | ||
| 299 | case SSL3_ST_SR_CHANGE_A: | ||
| 300 | case SSL3_ST_CR_CHANGE_A: str="3RCCSA"; break; | ||
| 301 | case SSL3_ST_SR_CHANGE_B: | ||
| 302 | case SSL3_ST_CR_CHANGE_B: str="3RCCSB"; break; | ||
| 303 | case SSL3_ST_SR_FINISHED_A: | ||
| 304 | case SSL3_ST_CR_FINISHED_A: str="3RFINA"; break; | ||
| 305 | case SSL3_ST_SR_FINISHED_B: | ||
| 306 | case SSL3_ST_CR_FINISHED_B: str="3RFINB"; break; | ||
| 307 | |||
| 308 | case SSL3_ST_SW_HELLO_REQ_A: str="3WHR_A"; break; | ||
| 309 | case SSL3_ST_SW_HELLO_REQ_B: str="3WHR_B"; break; | ||
| 310 | case SSL3_ST_SW_HELLO_REQ_C: str="3WHR_C"; break; | ||
| 311 | case SSL3_ST_SR_CLNT_HELLO_A: str="3RCH_A"; break; | ||
| 312 | case SSL3_ST_SR_CLNT_HELLO_B: str="3RCH_B"; break; | ||
| 313 | case SSL3_ST_SR_CLNT_HELLO_C: str="3RCH_C"; break; | ||
| 314 | case SSL3_ST_SW_SRVR_HELLO_A: str="3WSH_A"; break; | ||
| 315 | case SSL3_ST_SW_SRVR_HELLO_B: str="3WSH_B"; break; | ||
| 316 | case SSL3_ST_SW_CERT_A: str="3WSC_A"; break; | ||
| 317 | case SSL3_ST_SW_CERT_B: str="3WSC_B"; break; | ||
| 318 | case SSL3_ST_SW_KEY_EXCH_A: str="3WSKEA"; break; | ||
| 319 | case SSL3_ST_SW_KEY_EXCH_B: str="3WSKEB"; break; | ||
| 320 | case SSL3_ST_SW_CERT_REQ_A: str="3WCR_A"; break; | ||
| 321 | case SSL3_ST_SW_CERT_REQ_B: str="3WCR_B"; break; | ||
| 322 | case SSL3_ST_SW_SRVR_DONE_A: str="3WSD_A"; break; | ||
| 323 | case SSL3_ST_SW_SRVR_DONE_B: str="3WSD_B"; break; | ||
| 324 | case SSL3_ST_SR_CERT_A: str="3RCC_A"; break; | ||
| 325 | case SSL3_ST_SR_CERT_B: str="3RCC_B"; break; | ||
| 326 | case SSL3_ST_SR_KEY_EXCH_A: str="3RCKEA"; break; | ||
| 327 | case SSL3_ST_SR_KEY_EXCH_B: str="3RCKEB"; break; | ||
| 328 | case SSL3_ST_SR_CERT_VRFY_A: str="3RCV_A"; break; | ||
| 329 | case SSL3_ST_SR_CERT_VRFY_B: str="3RCV_B"; break; | ||
| 330 | #endif | ||
| 331 | |||
| 332 | #if !defined(NO_SSL2) && !defined(NO_SSL3) | ||
| 333 | /* SSLv2/v3 compatablitity states */ | ||
| 334 | /* client */ | ||
| 335 | case SSL23_ST_CW_CLNT_HELLO_A: str="23WCHA"; break; | ||
| 336 | case SSL23_ST_CW_CLNT_HELLO_B: str="23WCHB"; break; | ||
| 337 | case SSL23_ST_CR_SRVR_HELLO_A: str="23RSHA"; break; | ||
| 338 | case SSL23_ST_CR_SRVR_HELLO_B: str="23RSHA"; break; | ||
| 339 | /* server */ | ||
| 340 | case SSL23_ST_SR_CLNT_HELLO_A: str="23RCHA"; break; | ||
| 341 | case SSL23_ST_SR_CLNT_HELLO_B: str="23RCHB"; break; | ||
| 342 | #endif | ||
| 343 | |||
| 344 | default: str="UNKWN "; break; | ||
| 345 | } | ||
| 346 | return(str); | ||
| 347 | } | ||
| 348 | |||
| 349 | char *SSL_alert_type_string_long(value) | ||
| 350 | int value; | ||
| 351 | { | ||
| 352 | value>>=8; | ||
| 353 | if (value == SSL3_AL_WARNING) | ||
| 354 | return("warning"); | ||
| 355 | else if (value == SSL3_AL_FATAL) | ||
| 356 | return("fatal"); | ||
| 357 | else | ||
| 358 | return("unknown"); | ||
| 359 | } | ||
| 360 | |||
| 361 | char *SSL_alert_type_string(value) | ||
| 362 | int value; | ||
| 363 | { | ||
| 364 | value>>=8; | ||
| 365 | if (value == SSL3_AL_WARNING) | ||
| 366 | return("W"); | ||
| 367 | else if (value == SSL3_AL_FATAL) | ||
| 368 | return("F"); | ||
| 369 | else | ||
| 370 | return("U"); | ||
| 371 | } | ||
| 372 | |||
| 373 | char *SSL_alert_desc_string(value) | ||
| 374 | int value; | ||
| 375 | { | ||
| 376 | char *str; | ||
| 377 | |||
| 378 | switch (value & 0xff) | ||
| 379 | { | ||
| 380 | case SSL3_AD_CLOSE_NOTIFY: str="CN"; break; | ||
| 381 | case SSL3_AD_UNEXPECTED_MESSAGE: str="UM"; break; | ||
| 382 | case SSL3_AD_BAD_RECORD_MAC: str="BM"; break; | ||
| 383 | case SSL3_AD_DECOMPRESSION_FAILURE: str="DF"; break; | ||
| 384 | case SSL3_AD_HANDSHAKE_FAILURE: str="HF"; break; | ||
| 385 | case SSL3_AD_NO_CERTIFICATE: str="NC"; break; | ||
| 386 | case SSL3_AD_BAD_CERTIFICATE: str="BC"; break; | ||
| 387 | case SSL3_AD_UNSUPPORTED_CERTIFICATE: str="UC"; break; | ||
| 388 | case SSL3_AD_CERTIFICATE_REVOKED: str="CR"; break; | ||
| 389 | case SSL3_AD_CERTIFICATE_EXPIRED: str="CE"; break; | ||
| 390 | case SSL3_AD_CERTIFICATE_UNKNOWN: str="CU"; break; | ||
| 391 | case SSL3_AD_ILLEGAL_PARAMETER: str="IP"; break; | ||
| 392 | default: str="UK"; break; | ||
| 393 | } | ||
| 394 | return(str); | ||
| 395 | } | ||
| 396 | |||
| 397 | char *SSL_alert_desc_string_long(value) | ||
| 398 | int value; | ||
| 399 | { | ||
| 400 | char *str; | ||
| 401 | |||
| 402 | switch (value & 0xff) | ||
| 403 | { | ||
| 404 | case SSL3_AD_CLOSE_NOTIFY: | ||
| 405 | str="close notify"; | ||
| 406 | break; | ||
| 407 | case SSL3_AD_UNEXPECTED_MESSAGE: | ||
| 408 | str="unexected_message"; | ||
| 409 | break; | ||
| 410 | case SSL3_AD_BAD_RECORD_MAC: | ||
| 411 | str="bad record mac"; | ||
| 412 | break; | ||
| 413 | case SSL3_AD_DECOMPRESSION_FAILURE: | ||
| 414 | str="decompression failure"; | ||
| 415 | break; | ||
| 416 | case SSL3_AD_HANDSHAKE_FAILURE: | ||
| 417 | str="handshake failure"; | ||
| 418 | break; | ||
| 419 | case SSL3_AD_NO_CERTIFICATE: | ||
| 420 | str="no certificate"; | ||
| 421 | break; | ||
| 422 | case SSL3_AD_BAD_CERTIFICATE: | ||
| 423 | str="bad certificate"; | ||
| 424 | break; | ||
| 425 | case SSL3_AD_UNSUPPORTED_CERTIFICATE: | ||
| 426 | str="unsupported certificate"; | ||
| 427 | break; | ||
| 428 | case SSL3_AD_CERTIFICATE_REVOKED: | ||
| 429 | str="certificate revoked"; | ||
| 430 | break; | ||
| 431 | case SSL3_AD_CERTIFICATE_EXPIRED: | ||
| 432 | str="certificate expired"; | ||
| 433 | break; | ||
| 434 | case SSL3_AD_CERTIFICATE_UNKNOWN: | ||
| 435 | str="certifcate unknown"; | ||
| 436 | break; | ||
| 437 | case SSL3_AD_ILLEGAL_PARAMETER: | ||
| 438 | str="illegal parameter"; | ||
| 439 | break; | ||
| 440 | default: str="unknown"; break; | ||
| 441 | } | ||
| 442 | return(str); | ||
| 443 | } | ||
| 444 | |||
| 445 | char *SSL_rstate_string(s) | ||
| 446 | SSL *s; | ||
| 447 | { | ||
| 448 | char *str; | ||
| 449 | |||
| 450 | switch (s->rstate) | ||
| 451 | { | ||
| 452 | case SSL_ST_READ_HEADER:str="RH"; break; | ||
| 453 | case SSL_ST_READ_BODY: str="RB"; break; | ||
| 454 | case SSL_ST_READ_DONE: str="RD"; break; | ||
| 455 | default: str="unknown"; break; | ||
| 456 | } | ||
| 457 | return(str); | ||
| 458 | } | ||
diff --git a/src/lib/libssl/ssl_txt.c b/src/lib/libssl/ssl_txt.c new file mode 100644 index 0000000000..ce60e1a6dd --- /dev/null +++ b/src/lib/libssl/ssl_txt.c | |||
| @@ -0,0 +1,152 @@ | |||
| 1 | /* ssl/ssl_txt.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 "buffer.h" | ||
| 61 | #include "ssl_locl.h" | ||
| 62 | |||
| 63 | #ifndef NO_FP_API | ||
| 64 | int SSL_SESSION_print_fp(fp, x) | ||
| 65 | FILE *fp; | ||
| 66 | SSL_SESSION *x; | ||
| 67 | { | ||
| 68 | BIO *b; | ||
| 69 | int ret; | ||
| 70 | |||
| 71 | if ((b=BIO_new(BIO_s_file_internal())) == NULL) | ||
| 72 | { | ||
| 73 | SSLerr(SSL_F_SSL_SESSION_PRINT_FP,ERR_R_BUF_LIB); | ||
| 74 | return(0); | ||
| 75 | } | ||
| 76 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 77 | ret=SSL_SESSION_print(b,x); | ||
| 78 | BIO_free(b); | ||
| 79 | return(ret); | ||
| 80 | } | ||
| 81 | #endif | ||
| 82 | |||
| 83 | int SSL_SESSION_print(bp,x) | ||
| 84 | BIO *bp; | ||
| 85 | SSL_SESSION *x; | ||
| 86 | { | ||
| 87 | int i; | ||
| 88 | char str[128],*s; | ||
| 89 | |||
| 90 | if (x == NULL) goto err; | ||
| 91 | if (BIO_puts(bp,"SSL-Session:\n") <= 0) goto err; | ||
| 92 | if (x->ssl_version == SSL2_VERSION) | ||
| 93 | s="SSLv2"; | ||
| 94 | else if (x->ssl_version == SSL3_VERSION) | ||
| 95 | s="SSLv3"; | ||
| 96 | else if (x->ssl_version == TLS1_VERSION) | ||
| 97 | s="TLSv1"; | ||
| 98 | else | ||
| 99 | s="unknown"; | ||
| 100 | sprintf(str," Protocol : %s\n",s); | ||
| 101 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 102 | |||
| 103 | if (x->cipher == NULL) | ||
| 104 | { | ||
| 105 | if (((x->cipher_id) & 0xff000000) == 0x02000000) | ||
| 106 | sprintf(str," Cipher : %06lX\n",x->cipher_id&0xffffff); | ||
| 107 | else | ||
| 108 | sprintf(str," Cipher : %04lX\n",x->cipher_id&0xffff); | ||
| 109 | } | ||
| 110 | else | ||
| 111 | sprintf(str," Cipher : %s\n",(x->cipher == NULL)?"unknown":x->cipher->name); | ||
| 112 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 113 | if (BIO_puts(bp," Session-ID: ") <= 0) goto err; | ||
| 114 | for (i=0; i<(int)x->session_id_length; i++) | ||
| 115 | { | ||
| 116 | sprintf(str,"%02X",x->session_id[i]); | ||
| 117 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 118 | } | ||
| 119 | if (BIO_puts(bp,"\n Master-Key: ") <= 0) goto err; | ||
| 120 | for (i=0; i<(int)x->master_key_length; i++) | ||
| 121 | { | ||
| 122 | sprintf(str,"%02X",x->master_key[i]); | ||
| 123 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 124 | } | ||
| 125 | if (BIO_puts(bp,"\n Key-Arg : ") <= 0) goto err; | ||
| 126 | if (x->key_arg_length == 0) | ||
| 127 | { | ||
| 128 | if (BIO_puts(bp,"None") <= 0) goto err; | ||
| 129 | } | ||
| 130 | else | ||
| 131 | for (i=0; i<(int)x->key_arg_length; i++) | ||
| 132 | { | ||
| 133 | sprintf(str,"%02X",x->key_arg[i]); | ||
| 134 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 135 | } | ||
| 136 | if (x->time != 0L) | ||
| 137 | { | ||
| 138 | sprintf(str,"\n Start Time: %ld",x->time); | ||
| 139 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 140 | } | ||
| 141 | if (x->timeout != 0L) | ||
| 142 | { | ||
| 143 | sprintf(str,"\n Timeout : %ld (sec)",x->timeout); | ||
| 144 | if (BIO_puts(bp,str) <= 0) goto err; | ||
| 145 | } | ||
| 146 | if (BIO_puts(bp,"\n") <= 0) goto err; | ||
| 147 | |||
| 148 | return(1); | ||
| 149 | err: | ||
| 150 | return(0); | ||
| 151 | } | ||
| 152 | |||
diff --git a/src/lib/libssl/t1_clnt.c b/src/lib/libssl/t1_clnt.c new file mode 100644 index 0000000000..986d2436e2 --- /dev/null +++ b/src/lib/libssl/t1_clnt.c | |||
| @@ -0,0 +1,90 @@ | |||
| 1 | /* ssl/t1_clnt.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 "buffer.h" | ||
| 61 | #include "rand.h" | ||
| 62 | #include "objects.h" | ||
| 63 | #include "evp.h" | ||
| 64 | #include "ssl_locl.h" | ||
| 65 | |||
| 66 | static SSL_METHOD *tls1_get_client_method(ver) | ||
| 67 | int ver; | ||
| 68 | { | ||
| 69 | if (ver == TLS1_VERSION) | ||
| 70 | return(TLSv1_client_method()); | ||
| 71 | else | ||
| 72 | return(NULL); | ||
| 73 | } | ||
| 74 | |||
| 75 | SSL_METHOD *TLSv1_client_method() | ||
| 76 | { | ||
| 77 | static int init=1; | ||
| 78 | static SSL_METHOD TLSv1_client_data; | ||
| 79 | |||
| 80 | if (init) | ||
| 81 | { | ||
| 82 | init=0; | ||
| 83 | memcpy((char *)&TLSv1_client_data,(char *)tlsv1_base_method(), | ||
| 84 | sizeof(SSL_METHOD)); | ||
| 85 | TLSv1_client_data.ssl_connect=ssl3_connect; | ||
| 86 | TLSv1_client_data.get_ssl_method=tls1_get_client_method; | ||
| 87 | } | ||
| 88 | return(&TLSv1_client_data); | ||
| 89 | } | ||
| 90 | |||
diff --git a/src/lib/libssl/t1_enc.c b/src/lib/libssl/t1_enc.c new file mode 100644 index 0000000000..fbdd3bffb5 --- /dev/null +++ b/src/lib/libssl/t1_enc.c | |||
| @@ -0,0 +1,635 @@ | |||
| 1 | /* ssl/t1_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 "evp.h" | ||
| 61 | #include "hmac.h" | ||
| 62 | #include "ssl_locl.h" | ||
| 63 | |||
| 64 | static void tls1_P_hash(md,sec,sec_len,seed,seed_len,out,olen) | ||
| 65 | EVP_MD *md; | ||
| 66 | unsigned char *sec; | ||
| 67 | int sec_len; | ||
| 68 | unsigned char *seed; | ||
| 69 | int seed_len; | ||
| 70 | unsigned char *out; | ||
| 71 | int olen; | ||
| 72 | { | ||
| 73 | int chunk,n; | ||
| 74 | unsigned int j; | ||
| 75 | HMAC_CTX ctx; | ||
| 76 | HMAC_CTX ctx_tmp; | ||
| 77 | unsigned char A1[HMAC_MAX_MD_CBLOCK]; | ||
| 78 | unsigned int A1_len; | ||
| 79 | |||
| 80 | chunk=EVP_MD_size(md); | ||
| 81 | |||
| 82 | HMAC_Init(&ctx,sec,sec_len,md); | ||
| 83 | HMAC_Update(&ctx,seed,seed_len); | ||
| 84 | HMAC_Final(&ctx,A1,&A1_len); | ||
| 85 | |||
| 86 | n=0; | ||
| 87 | for (;;) | ||
| 88 | { | ||
| 89 | HMAC_Init(&ctx,NULL,0,NULL); /* re-init */ | ||
| 90 | HMAC_Update(&ctx,A1,A1_len); | ||
| 91 | memcpy(&ctx_tmp,&ctx,sizeof(ctx)); /* Copy for A2 */ /* not needed for last one */ | ||
| 92 | HMAC_Update(&ctx,seed,seed_len); | ||
| 93 | |||
| 94 | if (olen > chunk) | ||
| 95 | { | ||
| 96 | HMAC_Final(&ctx,out,&j); | ||
| 97 | out+=j; | ||
| 98 | olen-=j; | ||
| 99 | HMAC_Final(&ctx_tmp,A1,&A1_len); /* calc the next A1 value */ | ||
| 100 | } | ||
| 101 | else /* last one */ | ||
| 102 | { | ||
| 103 | HMAC_Final(&ctx,A1,&A1_len); | ||
| 104 | memcpy(out,A1,olen); | ||
| 105 | break; | ||
| 106 | } | ||
| 107 | } | ||
| 108 | HMAC_cleanup(&ctx); | ||
| 109 | HMAC_cleanup(&ctx_tmp); | ||
| 110 | memset(A1,0,sizeof(A1)); | ||
| 111 | } | ||
| 112 | |||
| 113 | static void tls1_PRF(md5,sha1,label,label_len,sec,slen,out1,out2,olen) | ||
| 114 | EVP_MD *md5; | ||
| 115 | EVP_MD *sha1; | ||
| 116 | unsigned char *label; | ||
| 117 | int label_len; | ||
| 118 | unsigned char *sec; | ||
| 119 | int slen; | ||
| 120 | unsigned char *out1; | ||
| 121 | unsigned char *out2; | ||
| 122 | int olen; | ||
| 123 | { | ||
| 124 | int len,i; | ||
| 125 | unsigned char *S1,*S2; | ||
| 126 | |||
| 127 | len=slen/2; | ||
| 128 | S1=sec; | ||
| 129 | S2= &(sec[len]); | ||
| 130 | len+=(slen&1); /* add for odd, make longer */ | ||
| 131 | |||
| 132 | |||
| 133 | tls1_P_hash(md5 ,S1,len,label,label_len,out1,olen); | ||
| 134 | tls1_P_hash(sha1,S2,len,label,label_len,out2,olen); | ||
| 135 | |||
| 136 | for (i=0; i<olen; i++) | ||
| 137 | out1[i]^=out2[i]; | ||
| 138 | } | ||
| 139 | |||
| 140 | static void tls1_generate_key_block(s,km,tmp,num) | ||
| 141 | SSL *s; | ||
| 142 | unsigned char *km,*tmp; | ||
| 143 | int num; | ||
| 144 | { | ||
| 145 | unsigned char *p; | ||
| 146 | unsigned char buf[SSL3_RANDOM_SIZE*2+ | ||
| 147 | TLS_MD_MAX_CONST_SIZE]; | ||
| 148 | p=buf; | ||
| 149 | |||
| 150 | memcpy(p,TLS_MD_KEY_EXPANSION_CONST, | ||
| 151 | TLS_MD_KEY_EXPANSION_CONST_SIZE); | ||
| 152 | p+=TLS_MD_KEY_EXPANSION_CONST_SIZE; | ||
| 153 | memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE); | ||
| 154 | p+=SSL3_RANDOM_SIZE; | ||
| 155 | memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE); | ||
| 156 | p+=SSL3_RANDOM_SIZE; | ||
| 157 | |||
| 158 | tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,p-buf, | ||
| 159 | s->session->master_key,s->session->master_key_length, | ||
| 160 | km,tmp,num); | ||
| 161 | } | ||
| 162 | |||
| 163 | int tls1_change_cipher_state(s,which) | ||
| 164 | SSL *s; | ||
| 165 | int which; | ||
| 166 | { | ||
| 167 | unsigned char *p,*key_block,*mac_secret; | ||
| 168 | unsigned char *exp_label,buf[TLS_MD_MAX_CONST_SIZE+ | ||
| 169 | SSL3_RANDOM_SIZE*2]; | ||
| 170 | unsigned char tmp1[EVP_MAX_KEY_LENGTH]; | ||
| 171 | unsigned char tmp2[EVP_MAX_KEY_LENGTH]; | ||
| 172 | unsigned char iv1[EVP_MAX_IV_LENGTH*2]; | ||
| 173 | unsigned char iv2[EVP_MAX_IV_LENGTH*2]; | ||
| 174 | unsigned char *ms,*key,*iv,*er1,*er2; | ||
| 175 | int client_write; | ||
| 176 | EVP_CIPHER_CTX *dd; | ||
| 177 | EVP_CIPHER *c; | ||
| 178 | SSL_COMPRESSION *comp; | ||
| 179 | EVP_MD *m; | ||
| 180 | int exp,n,i,j,k,exp_label_len; | ||
| 181 | |||
| 182 | exp=(s->s3->tmp.new_cipher->algorithms & SSL_EXPORT)?1:0; | ||
| 183 | c=s->s3->tmp.new_sym_enc; | ||
| 184 | m=s->s3->tmp.new_hash; | ||
| 185 | comp=s->s3->tmp.new_compression; | ||
| 186 | key_block=s->s3->tmp.key_block; | ||
| 187 | |||
| 188 | if (which & SSL3_CC_READ) | ||
| 189 | { | ||
| 190 | if ((s->enc_read_ctx == NULL) && | ||
| 191 | ((s->enc_read_ctx=(EVP_CIPHER_CTX *) | ||
| 192 | Malloc(sizeof(EVP_CIPHER_CTX))) == NULL)) | ||
| 193 | goto err; | ||
| 194 | dd= s->enc_read_ctx; | ||
| 195 | s->read_hash=m; | ||
| 196 | s->read_compression=comp; | ||
| 197 | memset(&(s->s3->read_sequence[0]),0,8); | ||
| 198 | mac_secret= &(s->s3->read_mac_secret[0]); | ||
| 199 | } | ||
| 200 | else | ||
| 201 | { | ||
| 202 | if ((s->enc_write_ctx == NULL) && | ||
| 203 | ((s->enc_write_ctx=(EVP_CIPHER_CTX *) | ||
| 204 | Malloc(sizeof(EVP_CIPHER_CTX))) == NULL)) | ||
| 205 | goto err; | ||
| 206 | dd= s->enc_write_ctx; | ||
| 207 | s->write_hash=m; | ||
| 208 | s->write_compression=comp; | ||
| 209 | memset(&(s->s3->write_sequence[0]),0,8); | ||
| 210 | mac_secret= &(s->s3->write_mac_secret[0]); | ||
| 211 | } | ||
| 212 | |||
| 213 | EVP_CIPHER_CTX_init(dd); | ||
| 214 | |||
| 215 | p=s->s3->tmp.key_block; | ||
| 216 | i=EVP_MD_size(m); | ||
| 217 | j=(exp)?5:EVP_CIPHER_key_length(c); | ||
| 218 | k=EVP_CIPHER_iv_length(c); | ||
| 219 | er1= &(s->s3->client_random[0]); | ||
| 220 | er2= &(s->s3->server_random[0]); | ||
| 221 | if ( (which == SSL3_CHANGE_CIPHER_CLIENT_WRITE) || | ||
| 222 | (which == SSL3_CHANGE_CIPHER_SERVER_READ)) | ||
| 223 | { | ||
| 224 | ms= &(p[ 0]); n=i+i; | ||
| 225 | key= &(p[ n]); n+=j+j; | ||
| 226 | iv= &(p[ n]); n+=k+k; | ||
| 227 | exp_label=(unsigned char *)TLS_MD_CLIENT_WRITE_KEY_CONST; | ||
| 228 | exp_label_len=TLS_MD_CLIENT_WRITE_KEY_CONST_SIZE; | ||
| 229 | client_write=1; | ||
| 230 | } | ||
| 231 | else | ||
| 232 | { | ||
| 233 | n=i; | ||
| 234 | ms= &(p[ n]); n+=i+j; | ||
| 235 | key= &(p[ n]); n+=j+k; | ||
| 236 | iv= &(p[ n]); n+=k; | ||
| 237 | exp_label=(unsigned char *)TLS_MD_SERVER_WRITE_KEY_CONST; | ||
| 238 | exp_label_len=TLS_MD_SERVER_WRITE_KEY_CONST_SIZE; | ||
| 239 | client_write=0; | ||
| 240 | } | ||
| 241 | |||
| 242 | if (n > s->s3->tmp.key_block_length) | ||
| 243 | { | ||
| 244 | SSLerr(SSL_F_TLS1_CHANGE_CIPHER_STATE,SSL_R_INTERNAL_ERROR); | ||
| 245 | goto err2; | ||
| 246 | } | ||
| 247 | |||
| 248 | memcpy(mac_secret,ms,i); | ||
| 249 | #ifdef TLS_DEBUG | ||
| 250 | printf("which = %04X\nmac key=",which); | ||
| 251 | { int z; for (z=0; z<i; z++) printf("%02X%c",ms[z],((z+1)%16)?' ':'\n'); } | ||
| 252 | #endif | ||
| 253 | if (exp) | ||
| 254 | { | ||
| 255 | /* In here I set both the read and write key/iv to the | ||
| 256 | * same value since only the correct one will be used :-). | ||
| 257 | */ | ||
| 258 | p=buf; | ||
| 259 | memcpy(p,exp_label,exp_label_len); | ||
| 260 | p+=exp_label_len; | ||
| 261 | memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE); | ||
| 262 | p+=SSL3_RANDOM_SIZE; | ||
| 263 | memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE); | ||
| 264 | p+=SSL3_RANDOM_SIZE; | ||
| 265 | tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,p-buf,key,j, | ||
| 266 | tmp1,tmp2,EVP_CIPHER_key_length(c)); | ||
| 267 | key=tmp1; | ||
| 268 | |||
| 269 | if (k > 0) | ||
| 270 | { | ||
| 271 | p=buf; | ||
| 272 | memcpy(p,TLS_MD_IV_BLOCK_CONST, | ||
| 273 | TLS_MD_IV_BLOCK_CONST_SIZE); | ||
| 274 | p+=TLS_MD_IV_BLOCK_CONST_SIZE; | ||
| 275 | memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE); | ||
| 276 | p+=SSL3_RANDOM_SIZE; | ||
| 277 | memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE); | ||
| 278 | p+=SSL3_RANDOM_SIZE; | ||
| 279 | tls1_PRF(s->ctx->md5,s->ctx->sha1, | ||
| 280 | buf,p-buf,"",0,iv1,iv2,k*2); | ||
| 281 | if (client_write) | ||
| 282 | iv=iv1; | ||
| 283 | else | ||
| 284 | iv= &(iv1[k]); | ||
| 285 | } | ||
| 286 | } | ||
| 287 | |||
| 288 | s->session->key_arg_length=0; | ||
| 289 | |||
| 290 | EVP_CipherInit(dd,c,key,iv,(which & SSL3_CC_WRITE)); | ||
| 291 | #ifdef TLS_DEBUG | ||
| 292 | printf("which = %04X\nkey=",which); | ||
| 293 | { int z; for (z=0; z<EVP_CIPHER_key_length(c); z++) printf("%02X%c",key[z],((z+1)%16)?' ':'\n'); } | ||
| 294 | printf("\niv="); | ||
| 295 | { int z; for (z=0; z<k; z++) printf("%02X%c",iv[z],((z+1)%16)?' ':'\n'); } | ||
| 296 | printf("\n"); | ||
| 297 | #endif | ||
| 298 | |||
| 299 | memset(tmp1,0,sizeof(tmp1)); | ||
| 300 | memset(tmp2,0,sizeof(tmp1)); | ||
| 301 | memset(iv1,0,sizeof(iv1)); | ||
| 302 | memset(iv2,0,sizeof(iv2)); | ||
| 303 | return(1); | ||
| 304 | err: | ||
| 305 | SSLerr(SSL_F_TLS1_CHANGE_CIPHER_STATE,ERR_R_MALLOC_FAILURE); | ||
| 306 | err2: | ||
| 307 | return(0); | ||
| 308 | } | ||
| 309 | |||
| 310 | int tls1_setup_key_block(s) | ||
| 311 | SSL *s; | ||
| 312 | { | ||
| 313 | unsigned char *p1,*p2; | ||
| 314 | EVP_CIPHER *c; | ||
| 315 | EVP_MD *hash; | ||
| 316 | int num,exp; | ||
| 317 | |||
| 318 | if (s->s3->tmp.key_block_length != 0) | ||
| 319 | return(1); | ||
| 320 | |||
| 321 | if (!ssl_cipher_get_evp(s->session->cipher,&c,&hash)) | ||
| 322 | { | ||
| 323 | SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK,SSL_R_CIPHER_OR_HASH_UNAVAILABLE); | ||
| 324 | return(0); | ||
| 325 | } | ||
| 326 | |||
| 327 | s->s3->tmp.new_sym_enc=c; | ||
| 328 | s->s3->tmp.new_hash=hash; | ||
| 329 | |||
| 330 | exp=(s->session->cipher->algorithms & SSL_EXPORT)?1:0; | ||
| 331 | |||
| 332 | num=EVP_CIPHER_key_length(c)+EVP_MD_size(hash)+EVP_CIPHER_iv_length(c); | ||
| 333 | num*=2; | ||
| 334 | |||
| 335 | ssl3_cleanup_key_block(s); | ||
| 336 | |||
| 337 | if ((p1=(unsigned char *)Malloc(num)) == NULL) | ||
| 338 | goto err; | ||
| 339 | if ((p2=(unsigned char *)Malloc(num)) == NULL) | ||
| 340 | goto err; | ||
| 341 | |||
| 342 | s->s3->tmp.key_block_length=num; | ||
| 343 | s->s3->tmp.key_block=p1; | ||
| 344 | |||
| 345 | |||
| 346 | #ifdef TLS_DEBUG | ||
| 347 | printf("client random\n"); | ||
| 348 | { int z; for (z=0; z<SSL3_RANDOM_SIZE; z++) printf("%02X%c",s->s3->client_random[z],((z+1)%16)?' ':'\n'); } | ||
| 349 | printf("server random\n"); | ||
| 350 | { int z; for (z=0; z<SSL3_RANDOM_SIZE; z++) printf("%02X%c",s->s3->server_random[z],((z+1)%16)?' ':'\n'); } | ||
| 351 | printf("pre-master\n"); | ||
| 352 | { int z; for (z=0; z<s->session->master_key_length; z++) printf("%02X%c",s->session->master_key[z],((z+1)%16)?' ':'\n'); } | ||
| 353 | #endif | ||
| 354 | tls1_generate_key_block(s,p1,p2,num); | ||
| 355 | memset(p2,0,num); | ||
| 356 | Free(p2); | ||
| 357 | #ifdef TLS_DEBUG | ||
| 358 | printf("\nkey block\n"); | ||
| 359 | { int z; for (z=0; z<num; z++) printf("%02X%c",p1[z],((z+1)%16)?' ':'\n'); } | ||
| 360 | #endif | ||
| 361 | |||
| 362 | return(1); | ||
| 363 | err: | ||
| 364 | SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK,ERR_R_MALLOC_FAILURE); | ||
| 365 | return(0); | ||
| 366 | } | ||
| 367 | |||
| 368 | int tls1_enc(s,send) | ||
| 369 | SSL *s; | ||
| 370 | int send; | ||
| 371 | { | ||
| 372 | SSL3_RECORD *rec; | ||
| 373 | EVP_CIPHER_CTX *ds; | ||
| 374 | unsigned long l; | ||
| 375 | int bs,i,ii,j,k,n=0; | ||
| 376 | EVP_CIPHER *enc; | ||
| 377 | SSL_COMPRESSION *comp; | ||
| 378 | |||
| 379 | if (send) | ||
| 380 | { | ||
| 381 | if (s->write_hash != NULL) | ||
| 382 | n=EVP_MD_size(s->write_hash); | ||
| 383 | ds=s->enc_write_ctx; | ||
| 384 | rec= &(s->s3->wrec); | ||
| 385 | if (s->enc_write_ctx == NULL) | ||
| 386 | { enc=NULL; comp=NULL; } | ||
| 387 | else | ||
| 388 | { | ||
| 389 | enc=EVP_CIPHER_CTX_cipher(s->enc_write_ctx); | ||
| 390 | comp=s->write_compression; | ||
| 391 | } | ||
| 392 | } | ||
| 393 | else | ||
| 394 | { | ||
| 395 | if (s->read_hash != NULL) | ||
| 396 | n=EVP_MD_size(s->read_hash); | ||
| 397 | ds=s->enc_read_ctx; | ||
| 398 | rec= &(s->s3->rrec); | ||
| 399 | if (s->enc_read_ctx == NULL) | ||
| 400 | { enc=NULL; comp=NULL; } | ||
| 401 | else | ||
| 402 | { | ||
| 403 | enc=EVP_CIPHER_CTX_cipher(s->enc_read_ctx); | ||
| 404 | comp=s->read_compression; | ||
| 405 | } | ||
| 406 | } | ||
| 407 | |||
| 408 | if ((s->session == NULL) || (ds == NULL) || | ||
| 409 | ((enc == NULL) && (comp == NULL))) | ||
| 410 | { | ||
| 411 | memcpy(rec->data,rec->input,rec->length); | ||
| 412 | rec->input=rec->data; | ||
| 413 | } | ||
| 414 | else | ||
| 415 | { | ||
| 416 | l=rec->length; | ||
| 417 | bs=EVP_CIPHER_block_size(ds->cipher); | ||
| 418 | |||
| 419 | if ((bs != 1) && send) | ||
| 420 | { | ||
| 421 | i=bs-((int)l%bs); | ||
| 422 | |||
| 423 | /* Add weird padding of upto 256 bytes */ | ||
| 424 | |||
| 425 | /* we need to add 'i' padding bytes of value j */ | ||
| 426 | j=i-1; | ||
| 427 | if (s->options & SSL_OP_TLS_BLOCK_PADDING_BUG) | ||
| 428 | { | ||
| 429 | if (s->s3->flags & TLS1_FLAGS_TLS_PADDING_BUG) | ||
| 430 | j++; | ||
| 431 | } | ||
| 432 | for (k=(int)l; k<(int)(l+i); k++) | ||
| 433 | rec->input[k]=j; | ||
| 434 | l+=i; | ||
| 435 | rec->length+=i; | ||
| 436 | } | ||
| 437 | |||
| 438 | EVP_Cipher(ds,rec->data,rec->input,l); | ||
| 439 | |||
| 440 | if ((bs != 1) && !send) | ||
| 441 | { | ||
| 442 | ii=i=rec->data[l-1]; | ||
| 443 | i++; | ||
| 444 | if (s->options&SSL_OP_TLS_BLOCK_PADDING_BUG) | ||
| 445 | { | ||
| 446 | /* First packet is even in size, so check */ | ||
| 447 | if ((memcmp(s->s3->read_sequence, | ||
| 448 | "\0\0\0\0\0\0\0\0",8) == 0) && !(ii & 1)) | ||
| 449 | s->s3->flags|=TLS1_FLAGS_TLS_PADDING_BUG; | ||
| 450 | if (s->s3->flags & TLS1_FLAGS_TLS_PADDING_BUG) | ||
| 451 | i--; | ||
| 452 | } | ||
| 453 | if (i > (int)rec->length) | ||
| 454 | { | ||
| 455 | SSLerr(SSL_F_TLS1_ENC,SSL_R_BLOCK_CIPHER_PAD_IS_WRONG); | ||
| 456 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECRYPTION_FAILED); | ||
| 457 | return(0); | ||
| 458 | } | ||
| 459 | for (j=(int)(l-i); j<(int)l; j++) | ||
| 460 | { | ||
| 461 | if (rec->data[j] != ii) | ||
| 462 | { | ||
| 463 | SSLerr(SSL_F_TLS1_ENC,SSL_R_DECRYPTION_FAILED); | ||
| 464 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECRYPTION_FAILED); | ||
| 465 | return(0); | ||
| 466 | } | ||
| 467 | } | ||
| 468 | rec->length-=i; | ||
| 469 | } | ||
| 470 | } | ||
| 471 | return(1); | ||
| 472 | } | ||
| 473 | |||
| 474 | int tls1_cert_verify_mac(s,in_ctx,out) | ||
| 475 | SSL *s; | ||
| 476 | EVP_MD_CTX *in_ctx; | ||
| 477 | unsigned char *out; | ||
| 478 | { | ||
| 479 | unsigned int ret; | ||
| 480 | EVP_MD_CTX ctx; | ||
| 481 | |||
| 482 | memcpy(&ctx,in_ctx,sizeof(EVP_MD_CTX)); | ||
| 483 | EVP_DigestFinal(&ctx,out,&ret); | ||
| 484 | return((int)ret); | ||
| 485 | } | ||
| 486 | |||
| 487 | int tls1_final_finish_mac(s,in1_ctx,in2_ctx,str,slen,out) | ||
| 488 | SSL *s; | ||
| 489 | EVP_MD_CTX *in1_ctx,*in2_ctx; | ||
| 490 | unsigned char *str; | ||
| 491 | int slen; | ||
| 492 | unsigned char *out; | ||
| 493 | { | ||
| 494 | unsigned int i; | ||
| 495 | EVP_MD_CTX ctx; | ||
| 496 | unsigned char buf[TLS_MD_MAX_CONST_SIZE+MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH]; | ||
| 497 | unsigned char *q,buf2[12]; | ||
| 498 | |||
| 499 | q=buf; | ||
| 500 | memcpy(q,str,slen); | ||
| 501 | q+=slen; | ||
| 502 | |||
| 503 | memcpy(&ctx,in1_ctx,sizeof(EVP_MD_CTX)); | ||
| 504 | EVP_DigestFinal(&ctx,q,&i); | ||
| 505 | q+=i; | ||
| 506 | memcpy(&ctx,in2_ctx,sizeof(EVP_MD_CTX)); | ||
| 507 | EVP_DigestFinal(&ctx,q,&i); | ||
| 508 | q+=i; | ||
| 509 | |||
| 510 | tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,q-buf, | ||
| 511 | s->session->master_key,s->session->master_key_length, | ||
| 512 | out,buf2,12); | ||
| 513 | memset(&ctx,0,sizeof(EVP_MD_CTX)); | ||
| 514 | |||
| 515 | return((int)12); | ||
| 516 | } | ||
| 517 | |||
| 518 | int tls1_mac(ssl,md,send) | ||
| 519 | SSL *ssl; | ||
| 520 | unsigned char *md; | ||
| 521 | int send; | ||
| 522 | { | ||
| 523 | SSL3_RECORD *rec; | ||
| 524 | unsigned char *mac_sec,*seq; | ||
| 525 | EVP_MD *hash; | ||
| 526 | unsigned int md_size; | ||
| 527 | int i; | ||
| 528 | HMAC_CTX hmac; | ||
| 529 | unsigned char buf[5]; | ||
| 530 | |||
| 531 | if (send) | ||
| 532 | { | ||
| 533 | rec= &(ssl->s3->wrec); | ||
| 534 | mac_sec= &(ssl->s3->write_mac_secret[0]); | ||
| 535 | seq= &(ssl->s3->write_sequence[0]); | ||
| 536 | hash=ssl->write_hash; | ||
| 537 | } | ||
| 538 | else | ||
| 539 | { | ||
| 540 | rec= &(ssl->s3->rrec); | ||
| 541 | mac_sec= &(ssl->s3->read_mac_secret[0]); | ||
| 542 | seq= &(ssl->s3->read_sequence[0]); | ||
| 543 | hash=ssl->read_hash; | ||
| 544 | } | ||
| 545 | |||
| 546 | md_size=EVP_MD_size(hash); | ||
| 547 | |||
| 548 | buf[0]=rec->type; | ||
| 549 | buf[1]=TLS1_VERSION_MAJOR; | ||
| 550 | buf[2]=TLS1_VERSION_MINOR; | ||
| 551 | buf[3]=rec->length>>8; | ||
| 552 | buf[4]=rec->length&0xff; | ||
| 553 | |||
| 554 | /* I should fix this up TLS TLS TLS TLS TLS XXXXXXXX */ | ||
| 555 | HMAC_Init(&hmac,mac_sec,EVP_MD_size(hash),hash); | ||
| 556 | HMAC_Update(&hmac,seq,8); | ||
| 557 | HMAC_Update(&hmac,buf,5); | ||
| 558 | HMAC_Update(&hmac,rec->input,rec->length); | ||
| 559 | HMAC_Final(&hmac,md,&md_size); | ||
| 560 | |||
| 561 | #ifdef TLS_DEBUG | ||
| 562 | printf("sec="); | ||
| 563 | {int z; for (z=0; z<md_size; z++) printf("%02X ",mac_sec[z]); printf("\n"); } | ||
| 564 | printf("seq="); | ||
| 565 | {int z; for (z=0; z<8; z++) printf("%02X ",seq[z]); printf("\n"); } | ||
| 566 | printf("buf="); | ||
| 567 | {int z; for (z=0; z<5; z++) printf("%02X ",buf[z]); printf("\n"); } | ||
| 568 | printf("rec="); | ||
| 569 | {int z; for (z=0; z<rec->length; z++) printf("%02X ",buf[z]); printf("\n"); } | ||
| 570 | #endif | ||
| 571 | |||
| 572 | for (i=7; i>=0; i--) | ||
| 573 | if (++seq[i]) break; | ||
| 574 | |||
| 575 | #ifdef TLS_DEBUG | ||
| 576 | {int z; for (z=0; z<md_size; z++) printf("%02X ",md[z]); printf("\n"); } | ||
| 577 | #endif | ||
| 578 | return(md_size); | ||
| 579 | } | ||
| 580 | |||
| 581 | int tls1_generate_master_secret(s,out,p,len) | ||
| 582 | SSL *s; | ||
| 583 | unsigned char *out; | ||
| 584 | unsigned char *p; | ||
| 585 | int len; | ||
| 586 | { | ||
| 587 | unsigned char buf[SSL3_RANDOM_SIZE*2+TLS_MD_MASTER_SECRET_CONST_SIZE]; | ||
| 588 | unsigned char buff[SSL_MAX_MASTER_KEY_LENGTH]; | ||
| 589 | |||
| 590 | /* Setup the stuff to munge */ | ||
| 591 | memcpy(buf,TLS_MD_MASTER_SECRET_CONST, | ||
| 592 | TLS_MD_MASTER_SECRET_CONST_SIZE); | ||
| 593 | memcpy(&(buf[TLS_MD_MASTER_SECRET_CONST_SIZE]), | ||
| 594 | s->s3->client_random,SSL3_RANDOM_SIZE); | ||
| 595 | memcpy(&(buf[SSL3_RANDOM_SIZE+TLS_MD_MASTER_SECRET_CONST_SIZE]), | ||
| 596 | s->s3->server_random,SSL3_RANDOM_SIZE); | ||
| 597 | tls1_PRF(s->ctx->md5,s->ctx->sha1, | ||
| 598 | buf,TLS_MD_MASTER_SECRET_CONST_SIZE+SSL3_RANDOM_SIZE*2,p,len, | ||
| 599 | s->session->master_key,buff,SSL3_MASTER_SECRET_SIZE); | ||
| 600 | return(SSL3_MASTER_SECRET_SIZE); | ||
| 601 | } | ||
| 602 | |||
| 603 | int tls1_alert_code(code) | ||
| 604 | int code; | ||
| 605 | { | ||
| 606 | switch (code) | ||
| 607 | { | ||
| 608 | case SSL_AD_CLOSE_NOTIFY: return(SSL3_AD_CLOSE_NOTIFY); | ||
| 609 | case SSL_AD_UNEXPECTED_MESSAGE: return(SSL3_AD_UNEXPECTED_MESSAGE); | ||
| 610 | case SSL_AD_BAD_RECORD_MAC: return(SSL3_AD_BAD_RECORD_MAC); | ||
| 611 | case SSL_AD_DECRYPTION_FAILED: return(TLS1_AD_DECRYPTION_FAILED); | ||
| 612 | case SSL_AD_RECORD_OVERFLOW: return(TLS1_AD_RECORD_OVERFLOW); | ||
| 613 | case SSL_AD_DECOMPRESSION_FAILURE:return(SSL3_AD_DECOMPRESSION_FAILURE); | ||
| 614 | case SSL_AD_HANDSHAKE_FAILURE: return(SSL3_AD_HANDSHAKE_FAILURE); | ||
| 615 | case SSL_AD_NO_CERTIFICATE: return(-1); | ||
| 616 | case SSL_AD_BAD_CERTIFICATE: return(SSL3_AD_BAD_CERTIFICATE); | ||
| 617 | case SSL_AD_UNSUPPORTED_CERTIFICATE:return(SSL3_AD_UNSUPPORTED_CERTIFICATE); | ||
| 618 | case SSL_AD_CERTIFICATE_REVOKED:return(SSL3_AD_CERTIFICATE_REVOKED); | ||
| 619 | case SSL_AD_CERTIFICATE_EXPIRED:return(SSL3_AD_CERTIFICATE_EXPIRED); | ||
| 620 | case SSL_AD_CERTIFICATE_UNKNOWN:return(SSL3_AD_CERTIFICATE_UNKNOWN); | ||
| 621 | case SSL_AD_ILLEGAL_PARAMETER: return(SSL3_AD_ILLEGAL_PARAMETER); | ||
| 622 | case SSL_AD_UNKNOWN_CA: return(TLS1_AD_UNKNOWN_CA); | ||
| 623 | case SSL_AD_ACCESS_DENIED: return(TLS1_AD_ACCESS_DENIED); | ||
| 624 | case SSL_AD_DECODE_ERROR: return(TLS1_AD_DECODE_ERROR); | ||
| 625 | case SSL_AD_DECRYPT_ERROR: return(TLS1_AD_DECRYPT_ERROR); | ||
| 626 | case SSL_AD_EXPORT_RESTRICION: return(TLS1_AD_EXPORT_RESTRICION); | ||
| 627 | case SSL_AD_PROTOCOL_VERSION: return(TLS1_AD_PROTOCOL_VERSION); | ||
| 628 | case SSL_AD_INSUFFICIENT_SECURITY:return(TLS1_AD_INSUFFICIENT_SECURITY); | ||
| 629 | case SSL_AD_INTERNAL_ERROR: return(TLS1_AD_INTERNAL_ERROR); | ||
| 630 | case SSL_AD_USER_CANCLED: return(TLS1_AD_USER_CANCLED); | ||
| 631 | case SSL_AD_NO_RENEGOTIATION: return(TLS1_AD_NO_RENEGOTIATION); | ||
| 632 | default: return(-1); | ||
| 633 | } | ||
| 634 | } | ||
| 635 | |||
diff --git a/src/lib/libssl/t1_lib.c b/src/lib/libssl/t1_lib.c new file mode 100644 index 0000000000..f9fbfa414c --- /dev/null +++ b/src/lib/libssl/t1_lib.c | |||
| @@ -0,0 +1,151 @@ | |||
| 1 | /* ssl/t1_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 "objects.h" | ||
| 61 | #include "ssl_locl.h" | ||
| 62 | |||
| 63 | char *tls1_version_str="TLSv1 part of SSLeay 0.9.0b 29-Jun-1998"; | ||
| 64 | |||
| 65 | #ifndef NO_PROTO | ||
| 66 | static long tls1_default_timeout(void); | ||
| 67 | #else | ||
| 68 | static long tls1_default_timeout(); | ||
| 69 | #endif | ||
| 70 | |||
| 71 | static SSL3_ENC_METHOD TLSv1_enc_data={ | ||
| 72 | tls1_enc, | ||
| 73 | tls1_mac, | ||
| 74 | tls1_setup_key_block, | ||
| 75 | tls1_generate_master_secret, | ||
| 76 | tls1_change_cipher_state, | ||
| 77 | tls1_final_finish_mac, | ||
| 78 | TLS1_FINISH_MAC_LENGTH, | ||
| 79 | tls1_cert_verify_mac, | ||
| 80 | TLS_MD_CLIENT_FINISH_CONST,TLS_MD_CLIENT_FINISH_CONST_SIZE, | ||
| 81 | TLS_MD_SERVER_FINISH_CONST,TLS_MD_SERVER_FINISH_CONST_SIZE, | ||
| 82 | tls1_alert_code, | ||
| 83 | }; | ||
| 84 | |||
| 85 | static SSL_METHOD TLSv1_data= { | ||
| 86 | TLS1_VERSION, | ||
| 87 | tls1_new, | ||
| 88 | tls1_clear, | ||
| 89 | tls1_free, | ||
| 90 | ssl_undefined_function, | ||
| 91 | ssl_undefined_function, | ||
| 92 | ssl3_read, | ||
| 93 | ssl3_peek, | ||
| 94 | ssl3_write, | ||
| 95 | ssl3_shutdown, | ||
| 96 | ssl3_renegotiate, | ||
| 97 | ssl3_ctrl, | ||
| 98 | ssl3_ctx_ctrl, | ||
| 99 | ssl3_get_cipher_by_char, | ||
| 100 | ssl3_put_cipher_by_char, | ||
| 101 | ssl3_pending, | ||
| 102 | ssl3_num_ciphers, | ||
| 103 | ssl3_get_cipher, | ||
| 104 | ssl_bad_method, | ||
| 105 | tls1_default_timeout, | ||
| 106 | &TLSv1_enc_data, | ||
| 107 | }; | ||
| 108 | |||
| 109 | static long tls1_default_timeout() | ||
| 110 | { | ||
| 111 | /* 2 hours, the 24 hours mentioned in the TLSv1 spec | ||
| 112 | * is way too long for http, the cache would over fill */ | ||
| 113 | return(60*60*2); | ||
| 114 | } | ||
| 115 | |||
| 116 | SSL_METHOD *tlsv1_base_method() | ||
| 117 | { | ||
| 118 | return(&TLSv1_data); | ||
| 119 | } | ||
| 120 | |||
| 121 | int tls1_new(s) | ||
| 122 | SSL *s; | ||
| 123 | { | ||
| 124 | if (!ssl3_new(s)) return(0); | ||
| 125 | s->method->ssl_clear(s); | ||
| 126 | return(1); | ||
| 127 | } | ||
| 128 | |||
| 129 | void tls1_free(s) | ||
| 130 | SSL *s; | ||
| 131 | { | ||
| 132 | ssl3_free(s); | ||
| 133 | } | ||
| 134 | |||
| 135 | void tls1_clear(s) | ||
| 136 | SSL *s; | ||
| 137 | { | ||
| 138 | ssl3_clear(s); | ||
| 139 | s->version=TLS1_VERSION; | ||
| 140 | } | ||
| 141 | |||
| 142 | #if 0 | ||
| 143 | long tls1_ctrl(s,cmd,larg,parg) | ||
| 144 | SSL *s; | ||
| 145 | int cmd; | ||
| 146 | long larg; | ||
| 147 | char *parg; | ||
| 148 | { | ||
| 149 | return(0); | ||
| 150 | } | ||
| 151 | #endif | ||
diff --git a/src/lib/libssl/t1_meth.c b/src/lib/libssl/t1_meth.c new file mode 100644 index 0000000000..512c2078e7 --- /dev/null +++ b/src/lib/libssl/t1_meth.c | |||
| @@ -0,0 +1,88 @@ | |||
| 1 | /* ssl/t1_meth.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 "objects.h" | ||
| 61 | #include "ssl_locl.h" | ||
| 62 | |||
| 63 | static SSL_METHOD *tls1_get_method(ver) | ||
| 64 | int ver; | ||
| 65 | { | ||
| 66 | if (ver == TLS1_VERSION) | ||
| 67 | return(TLSv1_method()); | ||
| 68 | else | ||
| 69 | return(NULL); | ||
| 70 | } | ||
| 71 | |||
| 72 | SSL_METHOD *TLSv1_method() | ||
| 73 | { | ||
| 74 | static int init=1; | ||
| 75 | static SSL_METHOD TLSv1_data; | ||
| 76 | |||
| 77 | if (init) | ||
| 78 | { | ||
| 79 | init=0; | ||
| 80 | memcpy((char *)&TLSv1_data,(char *)tlsv1_base_method(), | ||
| 81 | sizeof(SSL_METHOD)); | ||
| 82 | TLSv1_data.ssl_connect=ssl3_connect; | ||
| 83 | TLSv1_data.ssl_accept=ssl3_accept; | ||
| 84 | TLSv1_data.get_ssl_method=tls1_get_method; | ||
| 85 | } | ||
| 86 | return(&TLSv1_data); | ||
| 87 | } | ||
| 88 | |||
diff --git a/src/lib/libssl/t1_srvr.c b/src/lib/libssl/t1_srvr.c new file mode 100644 index 0000000000..8cf0addcd9 --- /dev/null +++ b/src/lib/libssl/t1_srvr.c | |||
| @@ -0,0 +1,91 @@ | |||
| 1 | /* ssl/t1_srvr.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 "buffer.h" | ||
| 61 | #include "rand.h" | ||
| 62 | #include "objects.h" | ||
| 63 | #include "evp.h" | ||
| 64 | #include "x509.h" | ||
| 65 | #include "ssl_locl.h" | ||
| 66 | |||
| 67 | static SSL_METHOD *tls1_get_server_method(ver) | ||
| 68 | int ver; | ||
| 69 | { | ||
| 70 | if (ver == TLS1_VERSION) | ||
| 71 | return(TLSv1_server_method()); | ||
| 72 | else | ||
| 73 | return(NULL); | ||
| 74 | } | ||
| 75 | |||
| 76 | SSL_METHOD *TLSv1_server_method() | ||
| 77 | { | ||
| 78 | static int init=1; | ||
| 79 | static SSL_METHOD TLSv1_server_data; | ||
| 80 | |||
| 81 | if (init) | ||
| 82 | { | ||
| 83 | init=0; | ||
| 84 | memcpy((char *)&TLSv1_server_data,(char *)tlsv1_base_method(), | ||
| 85 | sizeof(SSL_METHOD)); | ||
| 86 | TLSv1_server_data.ssl_accept=ssl3_accept; | ||
| 87 | TLSv1_server_data.get_ssl_method=tls1_get_server_method; | ||
| 88 | } | ||
| 89 | return(&TLSv1_server_data); | ||
| 90 | } | ||
| 91 | |||
diff --git a/src/lib/libssl/test/CAss.cnf b/src/lib/libssl/test/CAss.cnf new file mode 100644 index 0000000000..b941b7ae15 --- /dev/null +++ b/src/lib/libssl/test/CAss.cnf | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | # | ||
| 2 | # SSLeay example configuration file. | ||
| 3 | # This is mostly being used for generation of certificate requests. | ||
| 4 | # | ||
| 5 | |||
| 6 | RANDFILE = ./.rnd | ||
| 7 | |||
| 8 | #################################################################### | ||
| 9 | [ req ] | ||
| 10 | default_bits = 512 | ||
| 11 | default_keyfile = keySS.pem | ||
| 12 | distinguished_name = req_distinguished_name | ||
| 13 | encrypt_rsa_key = no | ||
| 14 | default_md = sha1 | ||
| 15 | |||
| 16 | [ req_distinguished_name ] | ||
| 17 | countryName = Country Name (2 letter code) | ||
| 18 | countryName_default = AU | ||
| 19 | countryName_value = AU | ||
| 20 | |||
| 21 | organizationName = Organization Name (eg, company) | ||
| 22 | organizationName_value = Dodgy Brothers | ||
| 23 | |||
| 24 | commonName = Common Name (eg, YOUR name) | ||
| 25 | commonName_value = Dodgy CA | ||
diff --git a/src/lib/libssl/test/CAssdh.cnf b/src/lib/libssl/test/CAssdh.cnf new file mode 100644 index 0000000000..4e0a908679 --- /dev/null +++ b/src/lib/libssl/test/CAssdh.cnf | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | # | ||
| 2 | # SSLeay example configuration file. | ||
| 3 | # This is mostly being used for generation of certificate requests. | ||
| 4 | # | ||
| 5 | # hacked by iang to do DH certs - CA | ||
| 6 | |||
| 7 | RANDFILE = ./.rnd | ||
| 8 | |||
| 9 | #################################################################### | ||
| 10 | [ req ] | ||
| 11 | distinguished_name = req_distinguished_name | ||
| 12 | encrypt_rsa_key = no | ||
| 13 | |||
| 14 | [ req_distinguished_name ] | ||
| 15 | countryName = Country Name (2 letter code) | ||
| 16 | countryName_default = CU | ||
| 17 | countryName_value = CU | ||
| 18 | |||
| 19 | organizationName = Organization Name (eg, company) | ||
| 20 | organizationName_value = La Junta de la Revolucion | ||
| 21 | |||
| 22 | commonName = Common Name (eg, YOUR name) | ||
| 23 | commonName_value = Junta | ||
| 24 | |||
diff --git a/src/lib/libssl/test/CAssdsa.cnf b/src/lib/libssl/test/CAssdsa.cnf new file mode 100644 index 0000000000..a6b4d1810c --- /dev/null +++ b/src/lib/libssl/test/CAssdsa.cnf | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | # | ||
| 2 | # SSLeay example configuration file. | ||
| 3 | # This is mostly being used for generation of certificate requests. | ||
| 4 | # | ||
| 5 | # hacked by iang to do DSA certs - CA | ||
| 6 | |||
| 7 | RANDFILE = ./.rnd | ||
| 8 | |||
| 9 | #################################################################### | ||
| 10 | [ req ] | ||
| 11 | distinguished_name = req_distinguished_name | ||
| 12 | encrypt_rsa_key = no | ||
| 13 | |||
| 14 | [ req_distinguished_name ] | ||
| 15 | countryName = Country Name (2 letter code) | ||
| 16 | countryName_default = ES | ||
| 17 | countryName_value = ES | ||
| 18 | |||
| 19 | organizationName = Organization Name (eg, company) | ||
| 20 | organizationName_value = Hermanos Locos | ||
| 21 | |||
| 22 | commonName = Common Name (eg, YOUR name) | ||
| 23 | commonName_value = Hermanos Locos CA | ||
diff --git a/src/lib/libssl/test/CAssrsa.cnf b/src/lib/libssl/test/CAssrsa.cnf new file mode 100644 index 0000000000..eb24a6dfc0 --- /dev/null +++ b/src/lib/libssl/test/CAssrsa.cnf | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | # | ||
| 2 | # SSLeay example configuration file. | ||
| 3 | # This is mostly being used for generation of certificate requests. | ||
| 4 | # | ||
| 5 | # create RSA certs - CA | ||
| 6 | |||
| 7 | RANDFILE = ./.rnd | ||
| 8 | |||
| 9 | #################################################################### | ||
| 10 | [ req ] | ||
| 11 | distinguished_name = req_distinguished_name | ||
| 12 | encrypt_key = no | ||
| 13 | |||
| 14 | [ req_distinguished_name ] | ||
| 15 | countryName = Country Name (2 letter code) | ||
| 16 | countryName_default = ES | ||
| 17 | countryName_value = ES | ||
| 18 | |||
| 19 | organizationName = Organization Name (eg, company) | ||
| 20 | organizationName_value = Hermanos Locos | ||
| 21 | |||
| 22 | commonName = Common Name (eg, YOUR name) | ||
| 23 | commonName_value = Hermanos Locos CA | ||
| 24 | |||
diff --git a/src/lib/libssl/test/Sssdsa.cnf b/src/lib/libssl/test/Sssdsa.cnf new file mode 100644 index 0000000000..8e170a28ef --- /dev/null +++ b/src/lib/libssl/test/Sssdsa.cnf | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | # | ||
| 2 | # SSLeay example configuration file. | ||
| 3 | # This is mostly being used for generation of certificate requests. | ||
| 4 | # | ||
| 5 | # hacked by iang to do DSA certs - Server | ||
| 6 | |||
| 7 | RANDFILE = ./.rnd | ||
| 8 | |||
| 9 | #################################################################### | ||
| 10 | [ req ] | ||
| 11 | distinguished_name = req_distinguished_name | ||
| 12 | encrypt_rsa_key = no | ||
| 13 | |||
| 14 | [ req_distinguished_name ] | ||
| 15 | countryName = Country Name (2 letter code) | ||
| 16 | countryName_default = ES | ||
| 17 | countryName_value = ES | ||
| 18 | |||
| 19 | organizationName = Organization Name (eg, company) | ||
| 20 | organizationName_value = Tortilleras S.A. | ||
| 21 | |||
| 22 | 0.commonName = Common Name (eg, YOUR name) | ||
| 23 | 0.commonName_value = Torti | ||
| 24 | |||
| 25 | 1.commonName = Common Name (eg, YOUR name) | ||
| 26 | 1.commonName_value = Gordita | ||
| 27 | |||
diff --git a/src/lib/libssl/test/Sssrsa.cnf b/src/lib/libssl/test/Sssrsa.cnf new file mode 100644 index 0000000000..8c79a03fca --- /dev/null +++ b/src/lib/libssl/test/Sssrsa.cnf | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | # | ||
| 2 | # SSLeay example configuration file. | ||
| 3 | # This is mostly being used for generation of certificate requests. | ||
| 4 | # | ||
| 5 | # create RSA certs - Server | ||
| 6 | |||
| 7 | RANDFILE = ./.rnd | ||
| 8 | |||
| 9 | #################################################################### | ||
| 10 | [ req ] | ||
| 11 | distinguished_name = req_distinguished_name | ||
| 12 | encrypt_key = no | ||
| 13 | |||
| 14 | [ req_distinguished_name ] | ||
| 15 | countryName = Country Name (2 letter code) | ||
| 16 | countryName_default = ES | ||
| 17 | countryName_value = ES | ||
| 18 | |||
| 19 | organizationName = Organization Name (eg, company) | ||
| 20 | organizationName_value = Tortilleras S.A. | ||
| 21 | |||
| 22 | 0.commonName = Common Name (eg, YOUR name) | ||
| 23 | 0.commonName_value = Torti | ||
| 24 | |||
| 25 | 1.commonName = Common Name (eg, YOUR name) | ||
| 26 | 1.commonName_value = Gordita | ||
diff --git a/src/lib/libssl/test/Uss.cnf b/src/lib/libssl/test/Uss.cnf new file mode 100644 index 0000000000..c89692d519 --- /dev/null +++ b/src/lib/libssl/test/Uss.cnf | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | # | ||
| 2 | # SSLeay example configuration file. | ||
| 3 | # This is mostly being used for generation of certificate requests. | ||
| 4 | # | ||
| 5 | |||
| 6 | RANDFILE = ./.rnd | ||
| 7 | |||
| 8 | #################################################################### | ||
| 9 | [ req ] | ||
| 10 | default_bits = 512 | ||
| 11 | default_keyfile = keySS.pem | ||
| 12 | distinguished_name = req_distinguished_name | ||
| 13 | encrypt_rsa_key = no | ||
| 14 | default_md = md2 | ||
| 15 | |||
| 16 | [ req_distinguished_name ] | ||
| 17 | countryName = Country Name (2 letter code) | ||
| 18 | countryName_default = AU | ||
| 19 | countryName_value = AU | ||
| 20 | |||
| 21 | organizationName = Organization Name (eg, company) | ||
| 22 | organizationName_value = Dodgy Brothers | ||
| 23 | |||
| 24 | 0.commonName = Common Name (eg, YOUR name) | ||
| 25 | 0.commonName_value = Brother 1 | ||
| 26 | |||
| 27 | 1.commonName = Common Name (eg, YOUR name) | ||
| 28 | 1.commonName_value = Brother 2 | ||
diff --git a/src/lib/libssl/test/methtest.c b/src/lib/libssl/test/methtest.c new file mode 100644 index 0000000000..630d29dc91 --- /dev/null +++ b/src/lib/libssl/test/methtest.c | |||
| @@ -0,0 +1,105 @@ | |||
| 1 | /* test/methtest.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 <stdlib.h> | ||
| 61 | #include "rsa.h" | ||
| 62 | #include "x509.h" | ||
| 63 | #include "meth.h" | ||
| 64 | #include "err.h" | ||
| 65 | |||
| 66 | int main(argc,argv) | ||
| 67 | int argc; | ||
| 68 | char *argv[]; | ||
| 69 | { | ||
| 70 | METHOD_CTX *top,*tmp1,*tmp2; | ||
| 71 | |||
| 72 | top=METH_new(x509_lookup()); /* get a top level context */ | ||
| 73 | if (top == NULL) goto err; | ||
| 74 | |||
| 75 | tmp1=METH_new(x509_by_file()); | ||
| 76 | if (top == NULL) goto err; | ||
| 77 | METH_arg(tmp1,METH_TYPE_FILE,"cafile1"); | ||
| 78 | METH_arg(tmp1,METH_TYPE_FILE,"cafile2"); | ||
| 79 | METH_push(top,METH_X509_CA_BY_SUBJECT,tmp1); | ||
| 80 | |||
| 81 | tmp2=METH_new(x509_by_dir()); | ||
| 82 | METH_arg(tmp2,METH_TYPE_DIR,"/home/eay/.CAcerts"); | ||
| 83 | METH_arg(tmp2,METH_TYPE_DIR,"/home/eay/SSLeay/certs"); | ||
| 84 | METH_arg(tmp2,METH_TYPE_DIR,"/usr/local/ssl/certs"); | ||
| 85 | METH_push(top,METH_X509_CA_BY_SUBJECT,tmp2); | ||
| 86 | |||
| 87 | /* tmp=METH_new(x509_by_issuer_dir); | ||
| 88 | METH_arg(tmp,METH_TYPE_DIR,"/home/eay/.mycerts"); | ||
| 89 | METH_push(top,METH_X509_BY_ISSUER,tmp); | ||
| 90 | |||
| 91 | tmp=METH_new(x509_by_issuer_primary); | ||
| 92 | METH_arg(tmp,METH_TYPE_FILE,"/home/eay/.mycerts/primary.pem"); | ||
| 93 | METH_push(top,METH_X509_BY_ISSUER,tmp); | ||
| 94 | */ | ||
| 95 | |||
| 96 | METH_init(top); | ||
| 97 | METH_control(tmp1,METH_CONTROL_DUMP,stdout); | ||
| 98 | METH_control(tmp2,METH_CONTROL_DUMP,stdout); | ||
| 99 | exit(0); | ||
| 100 | err: | ||
| 101 | ERR_load_crypto_strings(); | ||
| 102 | ERR_print_errors_fp(stderr); | ||
| 103 | exit(1); | ||
| 104 | return(0); | ||
| 105 | } | ||
diff --git a/src/lib/libssl/test/pkcs7-1.pem b/src/lib/libssl/test/pkcs7-1.pem new file mode 100644 index 0000000000..c47b27af88 --- /dev/null +++ b/src/lib/libssl/test/pkcs7-1.pem | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | -----BEGIN PKCS7----- | ||
| 2 | MIICUAYJKoZIhvcNAQcCoIICQTCCAj0CAQExDjAMBggqhkiG9w0CAgUAMCgGCSqG | ||
| 3 | SIb3DQEHAaAbBBlFdmVyeW9uZSBnZXRzIEZyaWRheSBvZmYuoIIBXjCCAVowggEE | ||
| 4 | AgQUAAApMA0GCSqGSIb3DQEBAgUAMCwxCzAJBgNVBAYTAlVTMR0wGwYDVQQKExRF | ||
| 5 | eGFtcGxlIE9yZ2FuaXphdGlvbjAeFw05MjA5MDkyMjE4MDZaFw05NDA5MDkyMjE4 | ||
| 6 | MDVaMEIxCzAJBgNVBAYTAlVTMR0wGwYDVQQKExRFeGFtcGxlIE9yZ2FuaXphdGlv | ||
| 7 | bjEUMBIGA1UEAxMLVGVzdCBVc2VyIDEwWzANBgkqhkiG9w0BAQEFAANKADBHAkAK | ||
| 8 | ZnkdxpiBaN56t3QZu3+wwAHGJxAnAHUUKULhmo2MUdBTs+N4Kh3l3Fr06+mUaBcB | ||
| 9 | FKHf5nzcmpr1XWVWILurAgMBAAEwDQYJKoZIhvcNAQECBQADQQBFGqHhqncgSl/N | ||
| 10 | 9XYGnQL3MsJvNnsNV4puZPOakR9Hld8JlDQFEaDR30ogsmp3TMrvdfxpLlTCoZN8 | ||
| 11 | BxEmnZsWMYGbMIGYAgEBMDQwLDELMAkGA1UEBhMCVVMxHTAbBgNVBAoTFEV4YW1w | ||
| 12 | bGUgT3JnYW5pemF0aW9uAgQUAAApMAwGCCqGSIb3DQICBQAwDQYJKoZIhvcNAQEB | ||
| 13 | BQAEQAX6aoEvx9+L9PJUJQngPoRuEbnGIL4gCe+0QO+8xmkhaZSsBPNBtX0FIC1C | ||
| 14 | j7Kie1x339mxW/w9VZNTUDQQweHh | ||
| 15 | -----END PKCS7----- | ||
diff --git a/src/lib/libssl/test/pkcs7.pem b/src/lib/libssl/test/pkcs7.pem new file mode 100644 index 0000000000..d55c60b94e --- /dev/null +++ b/src/lib/libssl/test/pkcs7.pem | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | MIAGCSqGSIb3DQEHAqCAMIACAQExADCABgkqhkiG9w0BBwEAAKCAMIIE+DCCBGGg | ||
| 2 | AwIBAgIQaGSF/JpbS1C223+yrc+N1DANBgkqhkiG9w0BAQQFADBiMREwDwYDVQQH | ||
| 3 | EwhJbnRlcm5ldDEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNVBAsTK1Zl | ||
| 4 | cmlTaWduIENsYXNzIDEgQ0EgLSBJbmRpdmlkdWFsIFN1YnNjcmliZXIwHhcNOTYw | ||
| 5 | ODEyMDAwMDAwWhcNOTYwODE3MjM1OTU5WjCCASAxETAPBgNVBAcTCEludGVybmV0 | ||
| 6 | MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE0MDIGA1UECxMrVmVyaVNpZ24gQ2xh | ||
| 7 | c3MgMSBDQSAtIEluZGl2aWR1YWwgU3Vic2NyaWJlcjE3MDUGA1UECxMuRGlnaXRh | ||
| 8 | bCBJRCBDbGFzcyAxIC0gU01JTUUgVmVyaVNpZ24sIEluYy4gVEVTVDFGMEQGA1UE | ||
| 9 | CxM9d3d3LnZlcmlzaWduLmNvbS9yZXBvc2l0b3J5L0NQUyBJbmNvcnAuIGJ5IFJl | ||
| 10 | Zi4sTElBQi5MVEQoYyk5NjEZMBcGA1UEAxMQQWxleGFuZHJlIERlYWNvbjEgMB4G | ||
| 11 | CSqGSIb3DQEJARYRYWxleEB2ZXJpc2lnbi5jb20wWzANBgkqhkiG9w0BAQEFAANK | ||
| 12 | ADBHAkAOy7xxCAIkOfuIA2LyRpxgKlDORl8htdXYhF5iBGUx1GYaK6KF+bK/CCI0 | ||
| 13 | l4j2OfWGFBUrwGoWqxTNcWgTfMzRAgMBAAGjggIyMIICLjAJBgNVHRMEAjAAMIIC | ||
| 14 | HwYDVR0DBIICFjCCAhIwggIOMIICCgYLYIZIAYb4RQEHAQEwggH5FoIBp1RoaXMg | ||
| 15 | Y2VydGlmaWNhdGUgaW5jb3Jwb3JhdGVzIGJ5IHJlZmVyZW5jZSwgYW5kIGl0cyB1 | ||
| 16 | c2UgaXMgc3RyaWN0bHkgc3ViamVjdCB0bywgdGhlIFZlcmlTaWduIENlcnRpZmlj | ||
| 17 | YXRpb24gUHJhY3RpY2UgU3RhdGVtZW50IChDUFMpLCBhdmFpbGFibGUgYXQ6IGh0 | ||
| 18 | dHBzOi8vd3d3LnZlcmlzaWduLmNvbS9DUFM7IGJ5IEUtbWFpbCBhdCBDUFMtcmVx | ||
| 19 | dWVzdHNAdmVyaXNpZ24uY29tOyBvciBieSBtYWlsIGF0IFZlcmlTaWduLCBJbmMu | ||
| 20 | LCAyNTkzIENvYXN0IEF2ZS4sIE1vdW50YWluIFZpZXcsIENBIDk0MDQzIFVTQSBU | ||
| 21 | ZWwuICsxICg0MTUpIDk2MS04ODMwIENvcHlyaWdodCAoYykgMTk5NiBWZXJpU2ln | ||
| 22 | biwgSW5jLiAgQWxsIFJpZ2h0cyBSZXNlcnZlZC4gQ0VSVEFJTiBXQVJSQU5USUVT | ||
| 23 | IERJU0NMQUlNRUQgYW5kIExJQUJJTElUWSBMSU1JVEVELqAOBgxghkgBhvhFAQcB | ||
| 24 | AQGhDgYMYIZIAYb4RQEHAQECMCwwKhYoaHR0cHM6Ly93d3cudmVyaXNpZ24uY29t | ||
| 25 | L3JlcG9zaXRvcnkvQ1BTIDANBgkqhkiG9w0BAQQFAAOBgQAimWMGQwwwxk+b3KAL | ||
| 26 | HlSWXtU7LWHe29CEG8XeVNTvrqs6SBqT7OoENOkGxpfdpVgZ3Qw2SKjxDvbvpfSF | ||
| 27 | slsqcxWSgB/hWuaVuZCkvTw/dYGGOxkTJGxvDCfl1PZjX4dKbatslsi9Z9HpGWT7 | ||
| 28 | ttItRwKqcBKgmCJvKi1pGWED0zCCAnkwggHioAMCAQICEDURpVKQb+fQKaRAGdQR | ||
| 29 | /D4wDQYJKoZIhvcNAQECBQAwXzELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlT | ||
| 30 | aWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAxIFB1YmxpYyBQcmltYXJ5IENlcnRp | ||
| 31 | ZmljYXRpb24gQXV0aG9yaXR5MB4XDTk2MDYyNzAwMDAwMFoXDTk3MDYyNzIzNTk1 | ||
| 32 | OVowYjERMA8GA1UEBxMISW50ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMu | ||
| 33 | MTQwMgYDVQQLEytWZXJpU2lnbiBDbGFzcyAxIENBIC0gSW5kaXZpZHVhbCBTdWJz | ||
| 34 | Y3JpYmVyMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC2FKbPTdAFDdjKI9Bv | ||
| 35 | qrQpkmOOLPhvltcunXZLEbE2jVfJw/0cxrr+Hgi6M8qV6r7jW80GqLd5HUQq7XPy | ||
| 36 | sVKDaBBwZJHXPmv5912dFEObbpdFmIFH0S3L3bty10w/cariQPJUObwW7s987Lrb | ||
| 37 | P2wqsxaxhhKdrpM01bjV0Pc+qQIDAQABozMwMTAPBgNVHRMECDAGAQH/AgEBMAsG | ||
| 38 | A1UdDwQEAwIBBjARBglghkgBhvhCAQEEBAMCAgQwDQYJKoZIhvcNAQECBQADgYEA | ||
| 39 | KeXHoBmnbxRCgk0jM9e9mDppdxpsipIna/J8DOHEUuD4nONAr4+xOg73SBl026n7 | ||
| 40 | Bk55A2wvAMGo7+kKTZ+rHaFDDcmq4O+rzFri2RIOeGAncj1IcGptAQhvXoIhFMG4 | ||
| 41 | Jlzg1KlHZHqy7D3jex78zcSU7kKOu8f5tAX1jC3+sToAAKGAMIIBJzCBkTANBgkq | ||
| 42 | hkiG9w0BAQIFADBiMREwDwYDVQQHEwhJbnRlcm5ldDEXMBUGA1UEChMOVmVyaVNp | ||
| 43 | Z24sIEluYy4xNDAyBgNVBAsTK1ZlcmlTaWduIENsYXNzIDEgQ0EgLSBJbmRpdmlk | ||
| 44 | dWFsIFN1YnNjcmliZXIXDTk2MDcwMTE3MzA0MFoXDTk3MDcwMTAwMDAwMFowDQYJ | ||
| 45 | KoZIhvcNAQECBQADgYEAGLuQ6PX8A7AiqBEtWzYtl6lZNSDI0bR5YUo+D2Jzkw30 | ||
| 46 | dxQnJSbKXEc6XYuzAW5HvrzATXu5c19WWPT4cRDwmjH71i9QcDysWwf/wE0qGTiW | ||
| 47 | I3tQT0I5VGh7jIJD07nlBw3R4Xl8dH9kr85JsWinqDH5YKpIo9o8knY5n7+qjOow | ||
| 48 | ggEkMIGOMA0GCSqGSIb3DQEBAgUAMF8xCzAJBgNVBAYTAlVTMRcwFQYDVQQKEw5W | ||
| 49 | ZXJpU2lnbiwgSW5jLjE3MDUGA1UECxMuQ2xhc3MgMSBQdWJsaWMgUHJpbWFyeSBD | ||
| 50 | ZXJ0aWZpY2F0aW9uIEF1dGhvcml0eRcNOTYwNzE2MjMxMTI5WhcNOTYwODE1MDAw | ||
| 51 | MDAwWjANBgkqhkiG9w0BAQIFAAOBgQAXsLE4vnsY6sY67QrmWec7iaU2ehzxanEK | ||
| 52 | /9wKHZNuhlNzk+qGZZw2evxfUe2OaRbYpl8zuZvhK9BHD3ad14OSe9/zx5hOPgP/ | ||
| 53 | DQXt6R4R8Q/1JheBrolrgbavjvI2wKS8/Psp2prBrkF4T48+AKRmS8Zzh1guxgvP | ||
| 54 | b+xSu/jH0gAAMYAAAAAAAAAAAA== | ||
diff --git a/src/lib/libssl/test/r160test.c b/src/lib/libssl/test/r160test.c new file mode 100644 index 0000000000..a172e393ca --- /dev/null +++ b/src/lib/libssl/test/r160test.c | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | /* test/r160test.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 | */ | ||
diff --git a/src/lib/libssl/test/tcrl b/src/lib/libssl/test/tcrl new file mode 100644 index 0000000000..859fba452f --- /dev/null +++ b/src/lib/libssl/test/tcrl | |||
| @@ -0,0 +1,81 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | PATH=../apps:$PATH | ||
| 4 | export PATH | ||
| 5 | |||
| 6 | cmd='../apps/ssleay crl' | ||
| 7 | |||
| 8 | if [ "$1"x != "x" ]; then | ||
| 9 | t=$1 | ||
| 10 | else | ||
| 11 | t=testcrl.pem | ||
| 12 | fi | ||
| 13 | |||
| 14 | echo testing crl conversions | ||
| 15 | cp $t fff.p | ||
| 16 | |||
| 17 | echo "p -> d" | ||
| 18 | $cmd -in fff.p -inform p -outform d >f.d | ||
| 19 | if [ $? != 0 ]; then exit 1; fi | ||
| 20 | #echo "p -> t" | ||
| 21 | #$cmd -in fff.p -inform p -outform t >f.t | ||
| 22 | #if [ $? != 0 ]; then exit 1; fi | ||
| 23 | echo "p -> p" | ||
| 24 | $cmd -in fff.p -inform p -outform p >f.p | ||
| 25 | if [ $? != 0 ]; then exit 1; fi | ||
| 26 | |||
| 27 | echo "d -> d" | ||
| 28 | $cmd -in f.d -inform d -outform d >ff.d1 | ||
| 29 | if [ $? != 0 ]; then exit 1; fi | ||
| 30 | #echo "t -> d" | ||
| 31 | #$cmd -in f.t -inform t -outform d >ff.d2 | ||
| 32 | #if [ $? != 0 ]; then exit 1; fi | ||
| 33 | echo "p -> d" | ||
| 34 | $cmd -in f.p -inform p -outform d >ff.d3 | ||
| 35 | if [ $? != 0 ]; then exit 1; fi | ||
| 36 | |||
| 37 | #echo "d -> t" | ||
| 38 | #$cmd -in f.d -inform d -outform t >ff.t1 | ||
| 39 | #if [ $? != 0 ]; then exit 1; fi | ||
| 40 | #echo "t -> t" | ||
| 41 | #$cmd -in f.t -inform t -outform t >ff.t2 | ||
| 42 | #if [ $? != 0 ]; then exit 1; fi | ||
| 43 | #echo "p -> t" | ||
| 44 | #$cmd -in f.p -inform p -outform t >ff.t3 | ||
| 45 | #if [ $? != 0 ]; then exit 1; fi | ||
| 46 | |||
| 47 | echo "d -> p" | ||
| 48 | $cmd -in f.d -inform d -outform p >ff.p1 | ||
| 49 | if [ $? != 0 ]; then exit 1; fi | ||
| 50 | #echo "t -> p" | ||
| 51 | #$cmd -in f.t -inform t -outform p >ff.p2 | ||
| 52 | #if [ $? != 0 ]; then exit 1; fi | ||
| 53 | echo "p -> p" | ||
| 54 | $cmd -in f.p -inform p -outform p >ff.p3 | ||
| 55 | if [ $? != 0 ]; then exit 1; fi | ||
| 56 | |||
| 57 | cmp fff.p f.p | ||
| 58 | if [ $? != 0 ]; then exit 1; fi | ||
| 59 | cmp fff.p ff.p1 | ||
| 60 | if [ $? != 0 ]; then exit 1; fi | ||
| 61 | #cmp fff.p ff.p2 | ||
| 62 | #if [ $? != 0 ]; then exit 1; fi | ||
| 63 | cmp fff.p ff.p3 | ||
| 64 | if [ $? != 0 ]; then exit 1; fi | ||
| 65 | |||
| 66 | #cmp f.t ff.t1 | ||
| 67 | #if [ $? != 0 ]; then exit 1; fi | ||
| 68 | #cmp f.t ff.t2 | ||
| 69 | #if [ $? != 0 ]; then exit 1; fi | ||
| 70 | #cmp f.t ff.t3 | ||
| 71 | #if [ $? != 0 ]; then exit 1; fi | ||
| 72 | |||
| 73 | cmp f.p ff.p1 | ||
| 74 | if [ $? != 0 ]; then exit 1; fi | ||
| 75 | #cmp f.p ff.p2 | ||
| 76 | #if [ $? != 0 ]; then exit 1; fi | ||
| 77 | cmp f.p ff.p3 | ||
| 78 | if [ $? != 0 ]; then exit 1; fi | ||
| 79 | |||
| 80 | /bin/rm -f f.* ff.* fff.* | ||
| 81 | exit 0 | ||
diff --git a/src/lib/libssl/test/test.cnf b/src/lib/libssl/test/test.cnf new file mode 100644 index 0000000000..faad3914a8 --- /dev/null +++ b/src/lib/libssl/test/test.cnf | |||
| @@ -0,0 +1,88 @@ | |||
| 1 | # | ||
| 2 | # SSLeay example configuration file. | ||
| 3 | # This is mostly being used for generation of certificate requests. | ||
| 4 | # | ||
| 5 | |||
| 6 | RANDFILE = ./.rnd | ||
| 7 | |||
| 8 | #################################################################### | ||
| 9 | [ ca ] | ||
| 10 | default_ca = CA_default # The default ca section | ||
| 11 | |||
| 12 | #################################################################### | ||
| 13 | [ CA_default ] | ||
| 14 | |||
| 15 | dir = ./demoCA # Where everything is kept | ||
| 16 | certs = $dir/certs # Where the issued certs are kept | ||
| 17 | crl_dir = $dir/crl # Where the issued crl are kept | ||
| 18 | database = $dir/index.txt # database index file. | ||
| 19 | new_certs_dir = $dir/new_certs # default place for new certs. | ||
| 20 | |||
| 21 | certificate = $dir/CAcert.pem # The CA certificate | ||
| 22 | serial = $dir/serial # The current serial number | ||
| 23 | crl = $dir/crl.pem # The current CRL | ||
| 24 | private_key = $dir/private/CAkey.pem# The private key | ||
| 25 | RANDFILE = $dir/private/.rand # private random number file | ||
| 26 | |||
| 27 | default_days = 365 # how long to certify for | ||
| 28 | default_crl_days= 30 # how long before next CRL | ||
| 29 | default_md = md5 # which md to use. | ||
| 30 | |||
| 31 | # A few difference way of specifying how similar the request should look | ||
| 32 | # For type CA, the listed attributes must be the same, and the optional | ||
| 33 | # and supplied fields are just that :-) | ||
| 34 | policy = policy_match | ||
| 35 | |||
| 36 | # For the CA policy | ||
| 37 | [ policy_match ] | ||
| 38 | countryName = match | ||
| 39 | stateOrProvinceName = match | ||
| 40 | organizationName = match | ||
| 41 | organizationalUnitName = optional | ||
| 42 | commonName = supplied | ||
| 43 | emailAddress = optional | ||
| 44 | |||
| 45 | # For the 'anything' policy | ||
| 46 | # At this point in time, you must list all acceptable 'object' | ||
| 47 | # types. | ||
| 48 | [ policy_anything ] | ||
| 49 | countryName = optional | ||
| 50 | stateOrProvinceName = optional | ||
| 51 | localityName = optional | ||
| 52 | organizationName = optional | ||
| 53 | organizationalUnitName = optional | ||
| 54 | commonName = supplied | ||
| 55 | emailAddress = optional | ||
| 56 | |||
| 57 | #################################################################### | ||
| 58 | [ req ] | ||
| 59 | default_bits = 512 | ||
| 60 | default_keyfile = testkey.pem | ||
| 61 | distinguished_name = req_distinguished_name | ||
| 62 | encrypt_rsa_key = no | ||
| 63 | |||
| 64 | [ req_distinguished_name ] | ||
| 65 | countryName = Country Name (2 letter code) | ||
| 66 | countryName_default = AU | ||
| 67 | countryName_value = AU | ||
| 68 | |||
| 69 | stateOrProvinceName = State or Province Name (full name) | ||
| 70 | stateOrProvinceName_default = Queensland | ||
| 71 | stateOrProvinceName_value = | ||
| 72 | |||
| 73 | localityName = Locality Name (eg, city) | ||
| 74 | localityName_value = Brisbane | ||
| 75 | |||
| 76 | organizationName = Organization Name (eg, company) | ||
| 77 | organizationName_default = | ||
| 78 | organizationName_value = CryptSoft Pty Ltd | ||
| 79 | |||
| 80 | organizationalUnitName = Organizational Unit Name (eg, section) | ||
| 81 | organizationalUnitName_default = | ||
| 82 | organizationalUnitName_value = . | ||
| 83 | |||
| 84 | commonName = Common Name (eg, YOUR name) | ||
| 85 | commonName_value = Eric Young | ||
| 86 | |||
| 87 | emailAddress = Email Address | ||
| 88 | emailAddress_value = eay@mincom.oz.au | ||
diff --git a/src/lib/libssl/test/testca b/src/lib/libssl/test/testca new file mode 100644 index 0000000000..a28402f9ca --- /dev/null +++ b/src/lib/libssl/test/testca | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | SH="/bin/sh" | ||
| 4 | PATH=../apps:$PATH | ||
| 5 | export SH PATH | ||
| 6 | |||
| 7 | SSLEAY_CONFIG="-config CAss.cnf" | ||
| 8 | export SSLEAY_CONFIG | ||
| 9 | |||
| 10 | /bin/rm -fr demoCA | ||
| 11 | $SH ../apps/CA.sh -newca <<EOF | ||
| 12 | EOF | ||
| 13 | |||
| 14 | if [ $? != 0 ]; then | ||
| 15 | exit 1; | ||
| 16 | fi | ||
| 17 | |||
| 18 | SSLEAY_CONFIG="-config Uss.cnf" | ||
| 19 | export SSLEAY_CONFIG | ||
| 20 | $SH ../apps/CA.sh -newreq | ||
| 21 | if [ $? != 0 ]; then | ||
| 22 | exit 1; | ||
| 23 | fi | ||
| 24 | |||
| 25 | |||
| 26 | SSLEAY_CONFIG="-config ../apps/ssleay.cnf" | ||
| 27 | export SSLEAY_CONFIG | ||
| 28 | $SH ../apps/CA.sh -sign <<EOF | ||
| 29 | y | ||
| 30 | y | ||
| 31 | EOF | ||
| 32 | if [ $? != 0 ]; then | ||
| 33 | exit 1; | ||
| 34 | fi | ||
| 35 | |||
| 36 | |||
| 37 | $SH ../apps/CA.sh -verify newcert.pem | ||
| 38 | if [ $? != 0 ]; then | ||
| 39 | exit 1; | ||
| 40 | fi | ||
| 41 | |||
| 42 | /bin/rm -fr demoCA newcert.pem newreq.pem | ||
| 43 | #usage: CA -newcert|-newreq|-newca|-sign|-verify | ||
| 44 | |||
diff --git a/src/lib/libssl/test/testcrl.pem b/src/lib/libssl/test/testcrl.pem new file mode 100644 index 0000000000..0989788354 --- /dev/null +++ b/src/lib/libssl/test/testcrl.pem | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | -----BEGIN X509 CRL----- | ||
| 2 | MIICjTCCAfowDQYJKoZIhvcNAQECBQAwXzELMAkGA1UEBhMCVVMxIDAeBgNVBAoT | ||
| 3 | F1JTQSBEYXRhIFNlY3VyaXR5LCBJbmMuMS4wLAYDVQQLEyVTZWN1cmUgU2VydmVy | ||
| 4 | IENlcnRpZmljYXRpb24gQXV0aG9yaXR5Fw05NTA1MDIwMjEyMjZaFw05NTA2MDEw | ||
| 5 | MDAxNDlaMIIBaDAWAgUCQQAABBcNOTUwMjAxMTcyNDI2WjAWAgUCQQAACRcNOTUw | ||
| 6 | MjEwMDIxNjM5WjAWAgUCQQAADxcNOTUwMjI0MDAxMjQ5WjAWAgUCQQAADBcNOTUw | ||
| 7 | MjI1MDA0NjQ0WjAWAgUCQQAAGxcNOTUwMzEzMTg0MDQ5WjAWAgUCQQAAFhcNOTUw | ||
| 8 | MzE1MTkxNjU0WjAWAgUCQQAAGhcNOTUwMzE1MTk0MDQxWjAWAgUCQQAAHxcNOTUw | ||
| 9 | MzI0MTk0NDMzWjAWAgUCcgAABRcNOTUwMzI5MjAwNzExWjAWAgUCcgAAERcNOTUw | ||
| 10 | MzMwMDIzNDI2WjAWAgUCQQAAIBcNOTUwNDA3MDExMzIxWjAWAgUCcgAAHhcNOTUw | ||
| 11 | NDA4MDAwMjU5WjAWAgUCcgAAQRcNOTUwNDI4MTcxNzI0WjAWAgUCcgAAOBcNOTUw | ||
| 12 | NDI4MTcyNzIxWjAWAgUCcgAATBcNOTUwNTAyMDIxMjI2WjANBgkqhkiG9w0BAQIF | ||
| 13 | AAN+AHqOEJXSDejYy0UwxxrH/9+N2z5xu/if0J6qQmK92W0hW158wpJg+ovV3+wQ | ||
| 14 | wvIEPRL2rocL0tKfAsVq1IawSJzSNgxG0lrcla3MrJBnZ4GaZDu4FutZh72MR3Gt | ||
| 15 | JaAL3iTJHJD55kK2D/VoyY1djlsPuNh6AEgdVwFAyp0v | ||
| 16 | -----END X509 CRL----- | ||
diff --git a/src/lib/libssl/test/testenc b/src/lib/libssl/test/testenc new file mode 100644 index 0000000000..42db56c2be --- /dev/null +++ b/src/lib/libssl/test/testenc | |||
| @@ -0,0 +1,62 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | testsrc=Makefile.ssl | ||
| 4 | test=./p | ||
| 5 | cmd=../apps/ssleay | ||
| 6 | |||
| 7 | cat $testsrc >$test; | ||
| 8 | |||
| 9 | echo cat | ||
| 10 | $cmd enc < $test > $test.cipher | ||
| 11 | $cmd enc < $test.cipher >$test.clear | ||
| 12 | cmp $test $test.clear | ||
| 13 | if [ $? != 0 ] | ||
| 14 | then | ||
| 15 | exit 1 | ||
| 16 | else | ||
| 17 | /bin/rm $test.cipher $test.clear | ||
| 18 | fi | ||
| 19 | echo base64 | ||
| 20 | $cmd enc -a -e < $test > $test.cipher | ||
| 21 | $cmd enc -a -d < $test.cipher >$test.clear | ||
| 22 | cmp $test $test.clear | ||
| 23 | if [ $? != 0 ] | ||
| 24 | then | ||
| 25 | exit 1 | ||
| 26 | else | ||
| 27 | /bin/rm $test.cipher $test.clear | ||
| 28 | fi | ||
| 29 | |||
| 30 | for i in rc4 \ | ||
| 31 | des-cfb des-ede-cfb des-ede3-cfb \ | ||
| 32 | des-ofb des-ede-ofb des-ede3-ofb \ | ||
| 33 | des-ecb des-ede des-ede3 desx \ | ||
| 34 | des-cbc des-ede-cbc des-ede3-cbc \ | ||
| 35 | idea-ecb idea-cfb idea-ofb idea-cbc \ | ||
| 36 | rc2-ecb rc2-cfb rc2-ofb rc2-cbc \ | ||
| 37 | bf-ecb bf-cfb bf-ofb bf-cbc rc4 \ | ||
| 38 | cast5-ecb cast5-cfb cast5-ofb cast5-cbc | ||
| 39 | do | ||
| 40 | echo $i | ||
| 41 | $cmd $i -bufsize 113 -e -k test < $test > $test.$i.cipher | ||
| 42 | $cmd $i -bufsize 157 -d -k test < $test.$i.cipher >$test.$i.clear | ||
| 43 | cmp $test $test.$i.clear | ||
| 44 | if [ $? != 0 ] | ||
| 45 | then | ||
| 46 | exit 1 | ||
| 47 | else | ||
| 48 | /bin/rm $test.$i.cipher $test.$i.clear | ||
| 49 | fi | ||
| 50 | |||
| 51 | echo $i base64 | ||
| 52 | $cmd $i -bufsize 113 -a -e -k test < $test > $test.$i.cipher | ||
| 53 | $cmd $i -bufsize 157 -a -d -k test < $test.$i.cipher >$test.$i.clear | ||
| 54 | cmp $test $test.$i.clear | ||
| 55 | if [ $? != 0 ] | ||
| 56 | then | ||
| 57 | exit 1 | ||
| 58 | else | ||
| 59 | /bin/rm $test.$i.cipher $test.$i.clear | ||
| 60 | fi | ||
| 61 | done | ||
| 62 | rm -f $test | ||
diff --git a/src/lib/libssl/test/testgen b/src/lib/libssl/test/testgen new file mode 100644 index 0000000000..12a4ca4cea --- /dev/null +++ b/src/lib/libssl/test/testgen | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | T=testcert | ||
| 4 | KEY=512 | ||
| 5 | CA=../certs/testca.pem | ||
| 6 | |||
| 7 | /bin/rm -f $T.1 $T.2 $T.key | ||
| 8 | |||
| 9 | PATH=../apps:$PATH; | ||
| 10 | export PATH | ||
| 11 | |||
| 12 | echo "generating certificate request" | ||
| 13 | |||
| 14 | echo "There should be a 2 sequences of .'s and some +'s." | ||
| 15 | echo "There should not be more that at most 80 per line" | ||
| 16 | echo "This could take some time." | ||
| 17 | |||
| 18 | ../apps/ssleay req -config test.cnf -new -out testreq.pem | ||
| 19 | if [ $? != 0 ]; then | ||
| 20 | echo problems creating request | ||
| 21 | exit 1 | ||
| 22 | fi | ||
| 23 | |||
| 24 | ../apps/ssleay req -verify -in testreq.pem -noout | ||
| 25 | if [ $? != 0 ]; then | ||
| 26 | echo signature on req is wrong | ||
| 27 | exit 1 | ||
| 28 | fi | ||
| 29 | |||
| 30 | exit 0 | ||
diff --git a/src/lib/libssl/test/testp7.pem b/src/lib/libssl/test/testp7.pem new file mode 100644 index 0000000000..b3b6dba830 --- /dev/null +++ b/src/lib/libssl/test/testp7.pem | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | -----BEGIN PKCS7----- | ||
| 2 | MIAGCSqGSIb3DQEHAqCAMIIIBwIBATEAMIAGCSqGSIb3DQEHAQAAoIIGPDCCBHIw | ||
| 3 | ggQcoAMCAQICEHkvjiX1iVGQMenF9HgIjI8wDQYJKoZIhvcNAQEEBQAwYjERMA8G | ||
| 4 | A1UEBxMISW50ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQL | ||
| 5 | EytWZXJpU2lnbiBDbGFzcyAxIENBIC0gSW5kaXZpZHVhbCBTdWJzY3JpYmVyMB4X | ||
| 6 | DTk2MDcxOTAwMDAwMFoXDTk3MDMzMDIzNTk1OVowgdUxETAPBgNVBAcTCEludGVy | ||
| 7 | bmV0MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE0MDIGA1UECxMrVmVyaVNpZ24g | ||
| 8 | Q2xhc3MgMSBDQSAtIEluZGl2aWR1YWwgU3Vic2NyaWJlcjEoMCYGA1UECxMfRGln | ||
| 9 | aXRhbCBJRCBDbGFzcyAxIC0gU01JTUUgVGVzdDFHMEUGA1UECxM+d3d3LnZlcmlz | ||
| 10 | aWduLmNvbS9yZXBvc2l0b3J5L0NQUy0xLjAgSW5jLiBieSBSZWYuLExJQUIuTFRE | ||
| 11 | KGMpOTYwWzANBgkqhkiG9w0BAQEFAANKADBHAkAOy7xxCAIkOfuIA2LyRpxgKlDO | ||
| 12 | Rl8htdXYhF5iBGUx1GYaK6KF+bK/CCI0l4j2OfWGFBUrwGoWqxTNcWgTfMzRAgMB | ||
| 13 | AAGjggI5MIICNTAJBgNVHRMEAjAAMIICJgYDVR0DBIICHTCCAhkwggIVMIICEQYL | ||
| 14 | YIZIAYb4RQEHAQEwggIAFoIBq1RoaXMgY2VydGlmaWNhdGUgaW5jb3Jwb3JhdGVz | ||
| 15 | IGJ5IHJlZmVyZW5jZSwgYW5kIGl0cyB1c2UgaXMgc3RyaWN0bHkgc3ViamVjdCB0 | ||
| 16 | bywgdGhlIFZlcmlTaWduIENlcnRpZmljYXRpb24gUHJhY3RpY2UgU3RhdGVtZW50 | ||
| 17 | IChDUFMpLCBhdmFpbGFibGUgYXQ6IGh0dHBzOi8vd3d3LnZlcmlzaWduLmNvbS9D | ||
| 18 | UFMtMS4wOyBieSBFLW1haWwgYXQgQ1BTLXJlcXVlc3RzQHZlcmlzaWduLmNvbTsg | ||
| 19 | b3IgYnkgbWFpbCBhdCBWZXJpU2lnbiwgSW5jLiwgMjU5MyBDb2FzdCBBdmUuLCBN | ||
| 20 | b3VudGFpbiBWaWV3LCBDQSA5NDA0MyBVU0EgVGVsLiArMSAoNDE1KSA5NjEtODgz | ||
| 21 | MCBDb3B5cmlnaHQgKGMpIDE5OTYgVmVyaVNpZ24sIEluYy4gIEFsbCBSaWdodHMg | ||
| 22 | UmVzZXJ2ZWQuIENFUlRBSU4gV0FSUkFOVElFUyBESVNDTEFJTUVEIGFuZCBMSUFC | ||
| 23 | SUxJVFkgTElNSVRFRC6gDgYMYIZIAYb4RQEHAQEBoQ4GDGCGSAGG+EUBBwEBAjAv | ||
| 24 | MC0WK2h0dHBzOi8vd3d3LnZlcmlzaWduLmNvbS9yZXBvc2l0b3J5L0NQUy0xLgMw | ||
| 25 | DQYJKoZIhvcNAQEEBQADQQDAmA7km/3iJWEsWN9Z2WU2gmZAknx45WnDKHxMa3Bf | ||
| 26 | gNsh6BLk/ngkJKjNKTDR13XVHqEPUY1flbjATZputw1GMIIBwjCCAWygAwIBAgIQ | ||
| 27 | fAmE6tW5ERSQWDneu3KfSTANBgkqhkiG9w0BAQIFADA+MQswCQYDVQQGEwJVUzEX | ||
| 28 | MBUGA1UEChMOVmVyaVNpZ24sIEluYy4xFjAUBgNVBAsTDVRFU1QgUm9vdCBQQ0Ew | ||
| 29 | HhcNOTYwNzE3MDAwMDAwWhcNOTcwNzE3MjM1OTU5WjBiMREwDwYDVQQHEwhJbnRl | ||
| 30 | cm5ldDEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNVBAsTK1ZlcmlTaWdu | ||
| 31 | IENsYXNzIDEgQ0EgLSBJbmRpdmlkdWFsIFN1YnNjcmliZXIwXDANBgkqhkiG9w0B | ||
| 32 | AQEFAANLADBIAkEA7Fc6zYJw4WwCWa1ni3fYNbzGSQNluuw990024GusjLfhEk1h | ||
| 33 | MsIUukTT/n8yxoO7rYp4x+LS+tHF2tBtuxg7CwIDAQABoyIwIDALBgNVHQ8EBAMC | ||
| 34 | AQYwEQYJYIZIAYb4QgEBBAQDAgIEMA0GCSqGSIb3DQEBAgUAA0EAFKem0cJGg9nd | ||
| 35 | TAbP5o1HIEyNn11ZlvLU5v1Hejs1MKQt72IMm4jjgOH+pjguXW8lB6yzrK4oVOO2 | ||
| 36 | UNCaNQ1H26GCAa0wgeYwgZEwDQYJKoZIhvcNAQECBQAwYjERMA8GA1UEBxMISW50 | ||
| 37 | ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQLEytWZXJpU2ln | ||
| 38 | biBDbGFzcyAxIENBIC0gSW5kaXZpZHVhbCBTdWJzY3JpYmVyFw05NjA3MTcxNzU5 | ||
| 39 | MjlaFw05NzA3MTgwMDAwMDBaMA0GCSqGSIb3DQEBAgUAA0EAubVWYTsWsQmste9f | ||
| 40 | +UgMw8BkjDlM25fwQLrCfmmnLxjewey10kSROypUaJLb+r4oRALc0fG9XfZsaiiI | ||
| 41 | gotQHjCBwTBtMA0GCSqGSIb3DQEBAgUAMD4xCzAJBgNVBAYTAlVTMRcwFQYDVQQK | ||
| 42 | Ew5WZXJpU2lnbiwgSW5jLjEWMBQGA1UECxMNVEVTVCBSb290IFBDQRcNOTYwNzE3 | ||
| 43 | MTc0NDA5WhcNOTgwNzE3MDAwMDAwWjANBgkqhkiG9w0BAQIFAANBAHitA0/xAukC | ||
| 44 | jHzeh1AMT/l2oC68N+yFb+aJPHBBMxc6gG2MaKjBNwb5hcXUllMlExONA3ju10f7 | ||
| 45 | owIq3s3wx10xAAAAAAA= | ||
| 46 | -----END PKCS7----- | ||
diff --git a/src/lib/libssl/test/testreq2.pem b/src/lib/libssl/test/testreq2.pem new file mode 100644 index 0000000000..c3cdcffcbc --- /dev/null +++ b/src/lib/libssl/test/testreq2.pem | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | -----BEGIN CERTIFICATE REQUEST----- | ||
| 2 | MIHaMIGFAgEAMA4xDDAKBgNVBAMTA2NuNDBcMA0GCSqGSIb3DQEBAQUAA0sAMEgC | ||
| 3 | QQCQsnkyUGDY2R3mYoeTprFJKgWuJ3f1jUjlIuW5+wfAUoeMt35c4vcFZ2mIBpEG | ||
| 4 | DtzkNQN1kr2O9ldm9zYnYhyhAgMBAAGgEjAQBgorBgEEAYI3AgEOMQIwADANBgkq | ||
| 5 | hkiG9w0BAQQFAANBAAb2szZgVIxg3vK6kYLjGSBISyuzcXJ6IvuPW6M+yzi1Qgoi | ||
| 6 | gQhazHTJp91T8ItZEzUJGZSZl2e5iXlnffWB+/U= | ||
| 7 | -----END CERTIFICATE REQUEST----- | ||
diff --git a/src/lib/libssl/test/testrsa.pem b/src/lib/libssl/test/testrsa.pem new file mode 100644 index 0000000000..aad21067a8 --- /dev/null +++ b/src/lib/libssl/test/testrsa.pem | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | -----BEGIN RSA PRIVATE KEY----- | ||
| 2 | MIIBPAIBAAJBAKrbeqkuRk8VcRmWFmtP+LviMB3+6dizWW3DwaffznyHGAFwUJ/I | ||
| 3 | Tv0XtbsCyl3QoyKGhrOAy3RvPK5M38iuXT0CAwEAAQJAZ3cnzaHXM/bxGaR5CR1R | ||
| 4 | rD1qFBAVfoQFiOH9uPJgMaoAuoQEisPHVcZDKcOv4wEg6/TInAIXBnEigtqvRzuy | ||
| 5 | oQIhAPcgZzUq3yVooAaoov8UbXPxqHlwo6GBMqnv20xzkf6ZAiEAsP4BnIaQTM8S | ||
| 6 | mvcpHZwQJdmdHHkGKAs37Dfxi67HbkUCIQCeZGliHXFa071Fp06ZeWlR2ADonTZz | ||
| 7 | rJBhdTe0v5pCeQIhAIZfkiGgGBX4cIuuckzEm43g9WMUjxP/0GlK39vIyihxAiEA | ||
| 8 | mymehFRT0MvqW5xAKAx7Pgkt8HVKwVhc2LwGKHE0DZM= | ||
| 9 | -----END RSA PRIVATE KEY----- | ||
diff --git a/src/lib/libssl/test/testsid.pem b/src/lib/libssl/test/testsid.pem new file mode 100644 index 0000000000..cd8617be2e --- /dev/null +++ b/src/lib/libssl/test/testsid.pem | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | -----BEGIN SSL SESSION PARAMETERS----- | ||
| 2 | MIIBxwIBAQIBAgQDAQCABBCi11xa5qkOP8xrr02K/NQCBBBkIYQZM0Bt95W0EHNV | ||
| 3 | bA58oQYCBDIBr7WiBAICASyjggGGMIIBgjCCASwCAQMwDQYJKoZIhvcNAQEEBQAw | ||
| 4 | ODELMAkGA1UEBhMCQVUxDDAKBgNVBAgTA1FMRDEbMBkGA1UEAxMSU1NMZWF5L3Jz | ||
| 5 | YSB0ZXN0IENBMB4XDTk1MTAwOTIzMzEzNFoXDTk4MDcwNTIzMzEzNFowYDELMAkG | ||
| 6 | A1UEBhMCQVUxDDAKBgNVBAgTA1FMRDEZMBcGA1UEChMQTWluY29tIFB0eS4gTHRk | ||
| 7 | LjELMAkGA1UECxMCQ1MxGzAZBgNVBAMTElNTTGVheSBkZW1vIGNsaWVudDBcMA0G | ||
| 8 | CSqGSIb3DQEBAQUAA0sAMEgCQQC4pcXEL1lgVA+B5Q3TcuW/O3LZHoA73IYm8oFD | ||
| 9 | TezgCDhL2RTMn+seKWF36UtJKRIOBU9jZHCVVd0Me5ls6BEjAgMBAAEwDQYJKoZI | ||
| 10 | hvcNAQEEBQADQQBoIpOcwUY1qlVF7j3ROSGvUsbvByOBFmYWkIBgsCqR+9qo1A7L | ||
| 11 | CrWF5i8LWt/vLwAHaxWNx2YuBJMFyuK81fTv | ||
| 12 | -----END SSL SESSION PARAMETERS----- | ||
diff --git a/src/lib/libssl/test/testss b/src/lib/libssl/test/testss new file mode 100644 index 0000000000..a5aecf4694 --- /dev/null +++ b/src/lib/libssl/test/testss | |||
| @@ -0,0 +1,89 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | digest='-mdc2' | ||
| 4 | reqcmd="../apps/ssleay req" | ||
| 5 | x509cmd="../apps/ssleay x509 $digest" | ||
| 6 | verifycmd="../apps/ssleay verify" | ||
| 7 | |||
| 8 | CAkey="keyCA.ss" | ||
| 9 | CAcert="certCA.ss" | ||
| 10 | CAreq="reqCA.ss" | ||
| 11 | CAconf="CAss.cnf" | ||
| 12 | CAreq2="req2CA.ss" # temp | ||
| 13 | |||
| 14 | Uconf="Uss.cnf" | ||
| 15 | Ukey="keyU.ss" | ||
| 16 | Ureq="reqU.ss" | ||
| 17 | Ucert="certU.ss" | ||
| 18 | |||
| 19 | echo | ||
| 20 | echo "make a certificate request using 'req'" | ||
| 21 | $reqcmd -config $CAconf -out $CAreq -keyout $CAkey -new #>err.ss | ||
| 22 | if [ $? != 0 ]; then | ||
| 23 | echo "error using 'req' to generate a certificate request" | ||
| 24 | exit 1 | ||
| 25 | fi | ||
| 26 | echo | ||
| 27 | echo "convert the certificate request into a self signed certificate using 'x509'" | ||
| 28 | $x509cmd -CAcreateserial -in $CAreq -days 30 -req -out $CAcert -signkey $CAkey >err.ss | ||
| 29 | if [ $? != 0 ]; then | ||
| 30 | echo "error using 'x509' to self sign a certificate request" | ||
| 31 | exit 1 | ||
| 32 | fi | ||
| 33 | |||
| 34 | echo | ||
| 35 | echo "convert a certificate into a certificate request using 'x509'" | ||
| 36 | $x509cmd -in $CAcert -x509toreq -signkey $CAkey -out $CAreq2 >err.ss | ||
| 37 | if [ $? != 0 ]; then | ||
| 38 | echo "error using 'x509' convert a certificate to a certificate request" | ||
| 39 | exit 1 | ||
| 40 | fi | ||
| 41 | |||
| 42 | $reqcmd -verify -in $CAreq -noout | ||
| 43 | if [ $? != 0 ]; then | ||
| 44 | echo first generated request is invalid | ||
| 45 | exit 1 | ||
| 46 | fi | ||
| 47 | |||
| 48 | $reqcmd -verify -in $CAreq2 -noout | ||
| 49 | if [ $? != 0 ]; then | ||
| 50 | echo second generated request is invalid | ||
| 51 | exit 1 | ||
| 52 | fi | ||
| 53 | |||
| 54 | $verifycmd -CAfile $CAcert $CAcert | ||
| 55 | if [ $? != 0 ]; then | ||
| 56 | echo first generated cert is invalid | ||
| 57 | exit 1 | ||
| 58 | fi | ||
| 59 | |||
| 60 | echo | ||
| 61 | echo "make another certificate request using 'req'" | ||
| 62 | $reqcmd -config $Uconf -out $Ureq -keyout $Ukey -new >err.ss | ||
| 63 | if [ $? != 0 ]; then | ||
| 64 | echo "error using 'req' to generate a certificate request" | ||
| 65 | exit 1 | ||
| 66 | fi | ||
| 67 | |||
| 68 | echo | ||
| 69 | echo "sign certificate request with the just created CA via 'x509'" | ||
| 70 | $x509cmd -CAcreateserial -in $Ureq -days 30 -req -out $Ucert -CA $CAcert -CAkey $CAkey >err.ss | ||
| 71 | if [ $? != 0 ]; then | ||
| 72 | echo "error using 'x509' to sign a certificate request" | ||
| 73 | exit 1 | ||
| 74 | fi | ||
| 75 | |||
| 76 | $verifycmd -CAfile $CAcert $Ucert | ||
| 77 | echo | ||
| 78 | echo "Certificate details" | ||
| 79 | $x509cmd -subject -issuer -startdate -enddate -noout -in $Ucert | ||
| 80 | |||
| 81 | echo | ||
| 82 | echo The generated CA certificate is $CAcert | ||
| 83 | echo The generated CA private key is $CAkey | ||
| 84 | |||
| 85 | echo The generated user certificate is $Ucert | ||
| 86 | echo The generated user private key is $Ukey | ||
| 87 | |||
| 88 | /bin/rm err.ss | ||
| 89 | exit 0 | ||
diff --git a/src/lib/libssl/test/testssl b/src/lib/libssl/test/testssl new file mode 100644 index 0000000000..f115adb8e1 --- /dev/null +++ b/src/lib/libssl/test/testssl | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | echo test sslv2 | ||
| 4 | ./ssltest -ssl2 || exit 1 | ||
| 5 | |||
| 6 | echo test sslv2 with server authentication | ||
| 7 | ./ssltest -ssl2 -server_auth -CApath ../certs || exit 1 | ||
| 8 | |||
| 9 | echo test sslv2 with client authentication | ||
| 10 | ./ssltest -ssl2 -client_auth -CApath ../certs || exit 1 | ||
| 11 | |||
| 12 | echo test sslv2 with both client and server authentication | ||
| 13 | ./ssltest -ssl2 -server_auth -client_auth -CApath ../certs || exit 1 | ||
| 14 | |||
| 15 | echo test sslv3 | ||
| 16 | ./ssltest -ssl3 || exit 1 | ||
| 17 | |||
| 18 | echo test sslv3 with server authentication | ||
| 19 | ./ssltest -ssl3 -server_auth -CApath ../certs || exit 1 | ||
| 20 | |||
| 21 | echo test sslv3 with client authentication | ||
| 22 | ./ssltest -ssl3 -client_auth -CApath ../certs || exit 1 | ||
| 23 | |||
| 24 | echo test sslv3 with both client and server authentication | ||
| 25 | ./ssltest -ssl3 -server_auth -client_auth -CApath ../certs || exit 1 | ||
| 26 | |||
| 27 | echo test sslv2/sslv3 | ||
| 28 | ./ssltest || exit 1 | ||
| 29 | |||
| 30 | echo test sslv2/sslv3 with server authentication | ||
| 31 | ./ssltest -server_auth -CApath ../certs || exit 1 | ||
| 32 | |||
| 33 | echo test sslv2/sslv3 with client authentication | ||
| 34 | ./ssltest -client_auth -CApath ../certs || exit 1 | ||
| 35 | |||
| 36 | echo test sslv2/sslv3 with both client and server authentication | ||
| 37 | ./ssltest -server_auth -client_auth -CApath ../certs || exit 1 | ||
| 38 | |||
| 39 | exit 0 | ||
| 40 | |||
diff --git a/src/lib/libssl/test/testx509.pem b/src/lib/libssl/test/testx509.pem new file mode 100644 index 0000000000..8a85d14964 --- /dev/null +++ b/src/lib/libssl/test/testx509.pem | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | -----BEGIN CERTIFICATE----- | ||
| 2 | MIIBWzCCAQYCARgwDQYJKoZIhvcNAQEEBQAwODELMAkGA1UEBhMCQVUxDDAKBgNV | ||
| 3 | BAgTA1FMRDEbMBkGA1UEAxMSU1NMZWF5L3JzYSB0ZXN0IENBMB4XDTk1MDYxOTIz | ||
| 4 | MzMxMloXDTk1MDcxNzIzMzMxMlowOjELMAkGA1UEBhMCQVUxDDAKBgNVBAgTA1FM | ||
| 5 | RDEdMBsGA1UEAxMUU1NMZWF5L3JzYSB0ZXN0IGNlcnQwXDANBgkqhkiG9w0BAQEF | ||
| 6 | AANLADBIAkEAqtt6qS5GTxVxGZYWa0/4u+IwHf7p2LNZbcPBp9/OfIcYAXBQn8hO | ||
| 7 | /Re1uwLKXdCjIoaGs4DLdG88rkzfyK5dPQIDAQABMAwGCCqGSIb3DQIFBQADQQAE | ||
| 8 | Wc7EcF8po2/ZO6kNCwK/ICH6DobgLekA5lSLr5EvuioZniZp5lFzAw4+YzPQ7XKJ | ||
| 9 | zl9HYIMxATFyqSiD9jsx | ||
| 10 | -----END CERTIFICATE----- | ||
diff --git a/src/lib/libssl/test/times b/src/lib/libssl/test/times new file mode 100644 index 0000000000..49aeebf216 --- /dev/null +++ b/src/lib/libssl/test/times | |||
| @@ -0,0 +1,113 @@ | |||
| 1 | |||
| 2 | More number for the questions about SSL overheads.... | ||
| 3 | |||
| 4 | The following numbers were generated on a pentium pro 200, running linux. | ||
| 5 | They give an indication of the SSL protocol and encryption overheads. | ||
| 6 | |||
| 7 | The program that generated them is an unreleased version of ssl/ssltest.c | ||
| 8 | which is the SSLeay ssl protocol testing program. It is a single process that | ||
| 9 | talks both sides of the SSL protocol via a non-blocking memory buffer | ||
| 10 | interface. | ||
| 11 | |||
| 12 | How do I read this? The protocol and cipher are reasonable obvious. | ||
| 13 | The next number is the number of connections being made. The next is the | ||
| 14 | number of bytes exchanged bewteen the client and server side of the protocol. | ||
| 15 | This is the number of bytes that the client sends to the server, and then | ||
| 16 | the server sends back. Because this is all happening in one process, | ||
| 17 | the data is being encrypted, decrypted, encrypted and then decrypted again. | ||
| 18 | It is a round trip of that many bytes. Because the one process performs | ||
| 19 | both the client and server sides of the protocol and it sends this many bytes | ||
| 20 | each direction, multiply this number by 4 to generate the number | ||
| 21 | of bytes encrypted/decrypted/MACed. The first time value is how many seconds | ||
| 22 | elapsed doing a full SSL handshake, the second is the cost of one | ||
| 23 | full handshake and the rest being session-id reuse. | ||
| 24 | |||
| 25 | SSLv2 RC4-MD5 1000 x 1 12.83s 0.70s | ||
| 26 | SSLv3 NULL-MD5 1000 x 1 14.35s 1.47s | ||
| 27 | SSLv3 RC4-MD5 1000 x 1 14.46s 1.56s | ||
| 28 | SSLv3 RC4-MD5 1000 x 1 51.93s 1.62s 1024bit RSA | ||
| 29 | SSLv3 RC4-SHA 1000 x 1 14.61s 1.83s | ||
| 30 | SSLv3 DES-CBC-SHA 1000 x 1 14.70s 1.89s | ||
| 31 | SSLv3 DES-CBC3-SHA 1000 x 1 15.16s 2.16s | ||
| 32 | |||
| 33 | SSLv2 RC4-MD5 1000 x 1024 13.72s 1.27s | ||
| 34 | SSLv3 NULL-MD5 1000 x 1024 14.79s 1.92s | ||
| 35 | SSLv3 RC4-MD5 1000 x 1024 52.58s 2.29s 1024bit RSA | ||
| 36 | SSLv3 RC4-SHA 1000 x 1024 15.39s 2.67s | ||
| 37 | SSLv3 DES-CBC-SHA 1000 x 1024 16.45s 3.55s | ||
| 38 | SSLv3 DES-CBC3-SHA 1000 x 1024 18.21s 5.38s | ||
| 39 | |||
| 40 | SSLv2 RC4-MD5 1000 x 10240 18.97s 6.52s | ||
| 41 | SSLv3 NULL-MD5 1000 x 10240 17.79s 5.11s | ||
| 42 | SSLv3 RC4-MD5 1000 x 10240 20.25s 7.90s | ||
| 43 | SSLv3 RC4-MD5 1000 x 10240 58.26s 8.08s 1024bit RSA | ||
| 44 | SSLv3 RC4-SHA 1000 x 10240 22.96s 11.44s | ||
| 45 | SSLv3 DES-CBC-SHA 1000 x 10240 30.65s 18.41s | ||
| 46 | SSLv3 DES-CBC3-SHA 1000 x 10240 47.04s 34.53s | ||
| 47 | |||
| 48 | SSLv2 RC4-MD5 1000 x 102400 70.22s 57.74s | ||
| 49 | SSLv3 NULL-MD5 1000 x 102400 43.73s 31.03s | ||
| 50 | SSLv3 RC4-MD5 1000 x 102400 71.32s 58.83s | ||
| 51 | SSLv3 RC4-MD5 1000 x 102400 109.66s 59.20s 1024bit RSA | ||
| 52 | SSLv3 RC4-SHA 1000 x 102400 95.88s 82.21s | ||
| 53 | SSLv3 DES-CBC-SHA 1000 x 102400 173.22s 160.55s | ||
| 54 | SSLv3 DES-CBC3-SHA 1000 x 102400 336.61s 323.82s | ||
| 55 | |||
| 56 | What does this all mean? Well for a server, with no session-id reuse, with | ||
| 57 | a transfer size of 10240 bytes, using RC4-MD5 and a 512bit server key, | ||
| 58 | a pentium pro 200 running linux can handle the SSLv3 protocol overheads of | ||
| 59 | about 49 connections a second. Reality will be quite different :-). | ||
| 60 | |||
| 61 | Remeber the first number is 1000 full ssl handshakes, the second is | ||
| 62 | 1 full and 999 with session-id reuse. The RSA overheads for each exchange | ||
| 63 | would be one public and one private operation, but the protocol/MAC/cipher | ||
| 64 | cost would be quite similar in both the client and server. | ||
| 65 | |||
| 66 | eric (adding numbers to speculation) | ||
| 67 | |||
| 68 | --- Appendix --- | ||
| 69 | - The time measured is user time but these number a very rough. | ||
| 70 | - Remember this is the cost of both client and server sides of the protocol. | ||
| 71 | - The TCP/kernal overhead of connection establishment is normally the | ||
| 72 | killer in SSL. Often delays in the TCP protocol will make session-id | ||
| 73 | reuse look slower that new sessions, but this would not be the case on | ||
| 74 | a loaded server. | ||
| 75 | - The TCP round trip latencies, while slowing indervidual connections, | ||
| 76 | would have minimal impact on throughput. | ||
| 77 | - Instead of sending one 102400 byte buffer, one 8k buffer is sent until | ||
| 78 | - the required number of bytes are processed. | ||
| 79 | - The SSLv3 connections were actually SSLv2 compatable SSLv3 headers. | ||
| 80 | - A 512bit server key was being used except where noted. | ||
| 81 | - No server key verification was being performed on the client side of the | ||
| 82 | protocol. This would slow things down very little. | ||
| 83 | - The library being used is SSLeay 0.8.x. | ||
| 84 | - The normal mesauring system was commands of the form | ||
| 85 | time ./ssltest -num 1000 -bytes 102400 -cipher DES-CBC-SHA -reuse | ||
| 86 | This modified version of ssltest should be in the next public release of | ||
| 87 | SSLeay. | ||
| 88 | |||
| 89 | The general cipher performace number for this platform are | ||
| 90 | |||
| 91 | SSLeay 0.8.2a 04-Sep-1997 | ||
| 92 | built on Fri Sep 5 17:37:05 EST 1997 | ||
| 93 | options:bn(64,32) md2(int) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2) | ||
| 94 | C flags:gcc -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized | ||
| 95 | The 'numbers' are in 1000s of bytes per second processed. | ||
| 96 | type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes | ||
| 97 | md2 131.02k 368.41k 500.57k 549.21k 566.09k | ||
| 98 | mdc2 535.60k 589.10k 595.88k 595.97k 594.54k | ||
| 99 | md5 1801.53k 9674.77k 17484.03k 21849.43k 23592.96k | ||
| 100 | sha 1261.63k 5533.25k 9285.63k 11187.88k 11913.90k | ||
| 101 | sha1 1103.13k 4782.53k 7933.78k 9472.34k 10070.70k | ||
| 102 | rc4 10722.53k 14443.93k 15215.79k 15299.24k 15219.59k | ||
| 103 | des cbc 3286.57k 3827.73k 3913.39k 3931.82k 3926.70k | ||
| 104 | des ede3 1443.50k 1549.08k 1561.17k 1566.38k 1564.67k | ||
| 105 | idea cbc 2203.64k 2508.16k 2538.33k 2543.62k 2547.71k | ||
| 106 | rc2 cbc 1430.94k 1511.59k 1524.82k 1527.13k 1523.33k | ||
| 107 | blowfish cbc 4716.07k 5965.82k 6190.17k 6243.67k 6234.11k | ||
| 108 | sign verify | ||
| 109 | rsa 512 bits 0.0100s 0.0011s | ||
| 110 | rsa 1024 bits 0.0451s 0.0012s | ||
| 111 | rsa 2048 bits 0.2605s 0.0086s | ||
| 112 | rsa 4096 bits 1.6883s 0.0302s | ||
| 113 | |||
diff --git a/src/lib/libssl/test/tpkcs7 b/src/lib/libssl/test/tpkcs7 new file mode 100644 index 0000000000..ea1f005dac --- /dev/null +++ b/src/lib/libssl/test/tpkcs7 | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | PATH=../apps:$PATH | ||
| 4 | export PATH | ||
| 5 | |||
| 6 | cmd='../apps/ssleay pkcs7' | ||
| 7 | |||
| 8 | if [ "$1"x != "x" ]; then | ||
| 9 | t=$1 | ||
| 10 | else | ||
| 11 | t=testp7.pem | ||
| 12 | fi | ||
| 13 | |||
| 14 | echo testing pkcs7 conversions | ||
| 15 | cp $t fff.p | ||
| 16 | |||
| 17 | echo "p -> d" | ||
| 18 | $cmd -in fff.p -inform p -outform d >f.d | ||
| 19 | if [ $? != 0 ]; then exit 1; fi | ||
| 20 | echo "p -> p" | ||
| 21 | $cmd -in fff.p -inform p -outform p >f.p | ||
| 22 | if [ $? != 0 ]; then exit 1; fi | ||
| 23 | |||
| 24 | echo "d -> d" | ||
| 25 | $cmd -in f.d -inform d -outform d >ff.d1 | ||
| 26 | if [ $? != 0 ]; then exit 1; fi | ||
| 27 | echo "p -> d" | ||
| 28 | $cmd -in f.p -inform p -outform d >ff.d3 | ||
| 29 | if [ $? != 0 ]; then exit 1; fi | ||
| 30 | |||
| 31 | echo "d -> p" | ||
| 32 | $cmd -in f.d -inform d -outform p >ff.p1 | ||
| 33 | if [ $? != 0 ]; then exit 1; fi | ||
| 34 | echo "p -> p" | ||
| 35 | $cmd -in f.p -inform p -outform p >ff.p3 | ||
| 36 | if [ $? != 0 ]; then exit 1; fi | ||
| 37 | |||
| 38 | cmp fff.p f.p | ||
| 39 | if [ $? != 0 ]; then exit 1; fi | ||
| 40 | cmp fff.p ff.p1 | ||
| 41 | if [ $? != 0 ]; then exit 1; fi | ||
| 42 | cmp fff.p ff.p3 | ||
| 43 | if [ $? != 0 ]; then exit 1; fi | ||
| 44 | |||
| 45 | cmp f.p ff.p1 | ||
| 46 | if [ $? != 0 ]; then exit 1; fi | ||
| 47 | cmp f.p ff.p3 | ||
| 48 | if [ $? != 0 ]; then exit 1; fi | ||
| 49 | |||
| 50 | /bin/rm -f f.* ff.* fff.* | ||
| 51 | exit 0 | ||
diff --git a/src/lib/libssl/test/tpkcs7d b/src/lib/libssl/test/tpkcs7d new file mode 100644 index 0000000000..c8f18fb09c --- /dev/null +++ b/src/lib/libssl/test/tpkcs7d | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | PATH=../apps:$PATH | ||
| 4 | export PATH | ||
| 5 | |||
| 6 | cmd='../apps/ssleay pkcs7' | ||
| 7 | |||
| 8 | if [ "$1"x != "x" ]; then | ||
| 9 | t=$1 | ||
| 10 | else | ||
| 11 | t=pkcs7-1.pem | ||
| 12 | fi | ||
| 13 | |||
| 14 | echo testing pkcs7 conversions | ||
| 15 | cp $t fff.p | ||
| 16 | |||
| 17 | echo "p -> d" | ||
| 18 | $cmd -in fff.p -inform p -outform d >f.d | ||
| 19 | if [ $? != 0 ]; then exit 1; fi | ||
| 20 | echo "p -> p" | ||
| 21 | $cmd -in fff.p -inform p -outform p >f.p | ||
| 22 | if [ $? != 0 ]; then exit 1; fi | ||
| 23 | |||
| 24 | echo "d -> d" | ||
| 25 | $cmd -in f.d -inform d -outform d >ff.d1 | ||
| 26 | if [ $? != 0 ]; then exit 1; fi | ||
| 27 | echo "p -> d" | ||
| 28 | $cmd -in f.p -inform p -outform d >ff.d3 | ||
| 29 | if [ $? != 0 ]; then exit 1; fi | ||
| 30 | |||
| 31 | echo "d -> p" | ||
| 32 | $cmd -in f.d -inform d -outform p >ff.p1 | ||
| 33 | if [ $? != 0 ]; then exit 1; fi | ||
| 34 | echo "p -> p" | ||
| 35 | $cmd -in f.p -inform p -outform p >ff.p3 | ||
| 36 | if [ $? != 0 ]; then exit 1; fi | ||
| 37 | |||
| 38 | cmp f.p ff.p1 | ||
| 39 | if [ $? != 0 ]; then exit 1; fi | ||
| 40 | cmp f.p ff.p3 | ||
| 41 | if [ $? != 0 ]; then exit 1; fi | ||
| 42 | |||
| 43 | /bin/rm -f f.* ff.* fff.* | ||
| 44 | exit 0 | ||
diff --git a/src/lib/libssl/test/treq b/src/lib/libssl/test/treq new file mode 100644 index 0000000000..e5f1d8cc41 --- /dev/null +++ b/src/lib/libssl/test/treq | |||
| @@ -0,0 +1,81 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | PATH=../apps:$PATH | ||
| 4 | export PATH | ||
| 5 | |||
| 6 | cmd='../apps/ssleay req' | ||
| 7 | |||
| 8 | if [ "$1"x != "x" ]; then | ||
| 9 | t=$1 | ||
| 10 | else | ||
| 11 | t=testreq.pem | ||
| 12 | fi | ||
| 13 | |||
| 14 | echo testing req conversions | ||
| 15 | cp $t fff.p | ||
| 16 | |||
| 17 | echo "p -> d" | ||
| 18 | $cmd -in fff.p -inform p -outform d >f.d | ||
| 19 | if [ $? != 0 ]; then exit 1; fi | ||
| 20 | #echo "p -> t" | ||
| 21 | #$cmd -in fff.p -inform p -outform t >f.t | ||
| 22 | #if [ $? != 0 ]; then exit 1; fi | ||
| 23 | echo "p -> p" | ||
| 24 | $cmd -in fff.p -inform p -outform p >f.p | ||
| 25 | if [ $? != 0 ]; then exit 1; fi | ||
| 26 | |||
| 27 | echo "d -> d" | ||
| 28 | $cmd -verify -in f.d -inform d -outform d >ff.d1 | ||
| 29 | if [ $? != 0 ]; then exit 1; fi | ||
| 30 | #echo "t -> d" | ||
| 31 | #$cmd -in f.t -inform t -outform d >ff.d2 | ||
| 32 | #if [ $? != 0 ]; then exit 1; fi | ||
| 33 | echo "p -> d" | ||
| 34 | $cmd -verify -in f.p -inform p -outform d >ff.d3 | ||
| 35 | if [ $? != 0 ]; then exit 1; fi | ||
| 36 | |||
| 37 | #echo "d -> t" | ||
| 38 | #$cmd -in f.d -inform d -outform t >ff.t1 | ||
| 39 | #if [ $? != 0 ]; then exit 1; fi | ||
| 40 | #echo "t -> t" | ||
| 41 | #$cmd -in f.t -inform t -outform t >ff.t2 | ||
| 42 | #if [ $? != 0 ]; then exit 1; fi | ||
| 43 | #echo "p -> t" | ||
| 44 | #$cmd -in f.p -inform p -outform t >ff.t3 | ||
| 45 | #if [ $? != 0 ]; then exit 1; fi | ||
| 46 | |||
| 47 | echo "d -> p" | ||
| 48 | $cmd -in f.d -inform d -outform p >ff.p1 | ||
| 49 | if [ $? != 0 ]; then exit 1; fi | ||
| 50 | #echo "t -> p" | ||
| 51 | #$cmd -in f.t -inform t -outform p >ff.p2 | ||
| 52 | #if [ $? != 0 ]; then exit 1; fi | ||
| 53 | echo "p -> p" | ||
| 54 | $cmd -in f.p -inform p -outform p >ff.p3 | ||
| 55 | if [ $? != 0 ]; then exit 1; fi | ||
| 56 | |||
| 57 | cmp fff.p f.p | ||
| 58 | if [ $? != 0 ]; then exit 1; fi | ||
| 59 | cmp fff.p ff.p1 | ||
| 60 | if [ $? != 0 ]; then exit 1; fi | ||
| 61 | #cmp fff.p ff.p2 | ||
| 62 | #if [ $? != 0 ]; then exit 1; fi | ||
| 63 | cmp fff.p ff.p3 | ||
| 64 | if [ $? != 0 ]; then exit 1; fi | ||
| 65 | |||
| 66 | #cmp f.t ff.t1 | ||
| 67 | #if [ $? != 0 ]; then exit 1; fi | ||
| 68 | #cmp f.t ff.t2 | ||
| 69 | #if [ $? != 0 ]; then exit 1; fi | ||
| 70 | #cmp f.t ff.t3 | ||
| 71 | #if [ $? != 0 ]; then exit 1; fi | ||
| 72 | |||
| 73 | cmp f.p ff.p1 | ||
| 74 | if [ $? != 0 ]; then exit 1; fi | ||
| 75 | #cmp f.p ff.p2 | ||
| 76 | #if [ $? != 0 ]; then exit 1; fi | ||
| 77 | cmp f.p ff.p3 | ||
| 78 | if [ $? != 0 ]; then exit 1; fi | ||
| 79 | |||
| 80 | /bin/rm -f f.* ff.* fff.* | ||
| 81 | exit 0 | ||
diff --git a/src/lib/libssl/test/trsa b/src/lib/libssl/test/trsa new file mode 100644 index 0000000000..e5b8fe0448 --- /dev/null +++ b/src/lib/libssl/test/trsa | |||
| @@ -0,0 +1,81 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | PATH=../apps:$PATH | ||
| 4 | export PATH | ||
| 5 | |||
| 6 | cmd='../apps/ssleay rsa' | ||
| 7 | |||
| 8 | if [ "$1"x != "x" ]; then | ||
| 9 | t=$1 | ||
| 10 | else | ||
| 11 | t=testrsa.pem | ||
| 12 | fi | ||
| 13 | |||
| 14 | echo testing rsa conversions | ||
| 15 | cp $t fff.p | ||
| 16 | |||
| 17 | echo "p -> d" | ||
| 18 | $cmd -in fff.p -inform p -outform d >f.d | ||
| 19 | if [ $? != 0 ]; then exit 1; fi | ||
| 20 | #echo "p -> t" | ||
| 21 | #$cmd -in fff.p -inform p -outform t >f.t | ||
| 22 | #if [ $? != 0 ]; then exit 1; fi | ||
| 23 | echo "p -> p" | ||
| 24 | $cmd -in fff.p -inform p -outform p >f.p | ||
| 25 | if [ $? != 0 ]; then exit 1; fi | ||
| 26 | |||
| 27 | echo "d -> d" | ||
| 28 | $cmd -in f.d -inform d -outform d >ff.d1 | ||
| 29 | if [ $? != 0 ]; then exit 1; fi | ||
| 30 | #echo "t -> d" | ||
| 31 | #$cmd -in f.t -inform t -outform d >ff.d2 | ||
| 32 | #if [ $? != 0 ]; then exit 1; fi | ||
| 33 | echo "p -> d" | ||
| 34 | $cmd -in f.p -inform p -outform d >ff.d3 | ||
| 35 | if [ $? != 0 ]; then exit 1; fi | ||
| 36 | |||
| 37 | #echo "d -> t" | ||
| 38 | #$cmd -in f.d -inform d -outform t >ff.t1 | ||
| 39 | #if [ $? != 0 ]; then exit 1; fi | ||
| 40 | #echo "t -> t" | ||
| 41 | #$cmd -in f.t -inform t -outform t >ff.t2 | ||
| 42 | #if [ $? != 0 ]; then exit 1; fi | ||
| 43 | #echo "p -> t" | ||
| 44 | #$cmd -in f.p -inform p -outform t >ff.t3 | ||
| 45 | #if [ $? != 0 ]; then exit 1; fi | ||
| 46 | |||
| 47 | echo "d -> p" | ||
| 48 | $cmd -in f.d -inform d -outform p >ff.p1 | ||
| 49 | if [ $? != 0 ]; then exit 1; fi | ||
| 50 | #echo "t -> p" | ||
| 51 | #$cmd -in f.t -inform t -outform p >ff.p2 | ||
| 52 | #if [ $? != 0 ]; then exit 1; fi | ||
| 53 | echo "p -> p" | ||
| 54 | $cmd -in f.p -inform p -outform p >ff.p3 | ||
| 55 | if [ $? != 0 ]; then exit 1; fi | ||
| 56 | |||
| 57 | cmp fff.p f.p | ||
| 58 | if [ $? != 0 ]; then exit 1; fi | ||
| 59 | cmp fff.p ff.p1 | ||
| 60 | if [ $? != 0 ]; then exit 1; fi | ||
| 61 | #cmp fff.p ff.p2 | ||
| 62 | #if [ $? != 0 ]; then exit 1; fi | ||
| 63 | cmp fff.p ff.p3 | ||
| 64 | if [ $? != 0 ]; then exit 1; fi | ||
| 65 | |||
| 66 | #cmp f.t ff.t1 | ||
| 67 | #if [ $? != 0 ]; then exit 1; fi | ||
| 68 | #cmp f.t ff.t2 | ||
| 69 | #if [ $? != 0 ]; then exit 1; fi | ||
| 70 | #cmp f.t ff.t3 | ||
| 71 | #if [ $? != 0 ]; then exit 1; fi | ||
| 72 | |||
| 73 | cmp f.p ff.p1 | ||
| 74 | if [ $? != 0 ]; then exit 1; fi | ||
| 75 | #cmp f.p ff.p2 | ||
| 76 | #if [ $? != 0 ]; then exit 1; fi | ||
| 77 | cmp f.p ff.p3 | ||
| 78 | if [ $? != 0 ]; then exit 1; fi | ||
| 79 | |||
| 80 | /bin/rm -f f.* ff.* fff.* | ||
| 81 | exit 0 | ||
diff --git a/src/lib/libssl/test/tsid b/src/lib/libssl/test/tsid new file mode 100644 index 0000000000..8c7e9b1387 --- /dev/null +++ b/src/lib/libssl/test/tsid | |||
| @@ -0,0 +1,81 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | PATH=../apps:$PATH | ||
| 4 | export PATH | ||
| 5 | |||
| 6 | cmd='../apps/ssleay sess_id' | ||
| 7 | |||
| 8 | if [ "$1"x != "x" ]; then | ||
| 9 | t=$1 | ||
| 10 | else | ||
| 11 | t=testsid.pem | ||
| 12 | fi | ||
| 13 | |||
| 14 | echo testing session-id conversions | ||
| 15 | cp $t fff.p | ||
| 16 | |||
| 17 | echo "p -> d" | ||
| 18 | $cmd -in fff.p -inform p -outform d >f.d | ||
| 19 | if [ $? != 0 ]; then exit 1; fi | ||
| 20 | #echo "p -> t" | ||
| 21 | #$cmd -in fff.p -inform p -outform t >f.t | ||
| 22 | #if [ $? != 0 ]; then exit 1; fi | ||
| 23 | echo "p -> p" | ||
| 24 | $cmd -in fff.p -inform p -outform p >f.p | ||
| 25 | if [ $? != 0 ]; then exit 1; fi | ||
| 26 | |||
| 27 | echo "d -> d" | ||
| 28 | $cmd -in f.d -inform d -outform d >ff.d1 | ||
| 29 | if [ $? != 0 ]; then exit 1; fi | ||
| 30 | #echo "t -> d" | ||
| 31 | #$cmd -in f.t -inform t -outform d >ff.d2 | ||
| 32 | #if [ $? != 0 ]; then exit 1; fi | ||
| 33 | echo "p -> d" | ||
| 34 | $cmd -in f.p -inform p -outform d >ff.d3 | ||
| 35 | if [ $? != 0 ]; then exit 1; fi | ||
| 36 | |||
| 37 | #echo "d -> t" | ||
| 38 | #$cmd -in f.d -inform d -outform t >ff.t1 | ||
| 39 | #if [ $? != 0 ]; then exit 1; fi | ||
| 40 | #echo "t -> t" | ||
| 41 | #$cmd -in f.t -inform t -outform t >ff.t2 | ||
| 42 | #if [ $? != 0 ]; then exit 1; fi | ||
| 43 | #echo "p -> t" | ||
| 44 | #$cmd -in f.p -inform p -outform t >ff.t3 | ||
| 45 | #if [ $? != 0 ]; then exit 1; fi | ||
| 46 | |||
| 47 | echo "d -> p" | ||
| 48 | $cmd -in f.d -inform d -outform p >ff.p1 | ||
| 49 | if [ $? != 0 ]; then exit 1; fi | ||
| 50 | #echo "t -> p" | ||
| 51 | #$cmd -in f.t -inform t -outform p >ff.p2 | ||
| 52 | #if [ $? != 0 ]; then exit 1; fi | ||
| 53 | echo "p -> p" | ||
| 54 | $cmd -in f.p -inform p -outform p >ff.p3 | ||
| 55 | if [ $? != 0 ]; then exit 1; fi | ||
| 56 | |||
| 57 | cmp fff.p f.p | ||
| 58 | if [ $? != 0 ]; then exit 1; fi | ||
| 59 | cmp fff.p ff.p1 | ||
| 60 | if [ $? != 0 ]; then exit 1; fi | ||
| 61 | #cmp fff.p ff.p2 | ||
| 62 | #if [ $? != 0 ]; then exit 1; fi | ||
| 63 | cmp fff.p ff.p3 | ||
| 64 | if [ $? != 0 ]; then exit 1; fi | ||
| 65 | |||
| 66 | #cmp f.t ff.t1 | ||
| 67 | #if [ $? != 0 ]; then exit 1; fi | ||
| 68 | #cmp f.t ff.t2 | ||
| 69 | #if [ $? != 0 ]; then exit 1; fi | ||
| 70 | #cmp f.t ff.t3 | ||
| 71 | #if [ $? != 0 ]; then exit 1; fi | ||
| 72 | |||
| 73 | cmp f.p ff.p1 | ||
| 74 | if [ $? != 0 ]; then exit 1; fi | ||
| 75 | #cmp f.p ff.p2 | ||
| 76 | #if [ $? != 0 ]; then exit 1; fi | ||
| 77 | cmp f.p ff.p3 | ||
| 78 | if [ $? != 0 ]; then exit 1; fi | ||
| 79 | |||
| 80 | /bin/rm -f f.* ff.* fff.* | ||
| 81 | exit 0 | ||
diff --git a/src/lib/libssl/test/tx509 b/src/lib/libssl/test/tx509 new file mode 100644 index 0000000000..f8d1f82cdd --- /dev/null +++ b/src/lib/libssl/test/tx509 | |||
| @@ -0,0 +1,81 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | PATH=../apps:$PATH | ||
| 4 | export PATH | ||
| 5 | |||
| 6 | cmd='../apps/ssleay x509' | ||
| 7 | |||
| 8 | if [ "$1"x != "x" ]; then | ||
| 9 | t=$1 | ||
| 10 | else | ||
| 11 | t=testx509.pem | ||
| 12 | fi | ||
| 13 | |||
| 14 | echo testing X509 conversions | ||
| 15 | cp $t fff.p | ||
| 16 | |||
| 17 | echo "p -> d" | ||
| 18 | $cmd -in fff.p -inform p -outform d >f.d | ||
| 19 | if [ $? != 0 ]; then exit 1; fi | ||
| 20 | echo "p -> n" | ||
| 21 | $cmd -in fff.p -inform p -outform n >f.n | ||
| 22 | if [ $? != 0 ]; then exit 1; fi | ||
| 23 | echo "p -> p" | ||
| 24 | $cmd -in fff.p -inform p -outform p >f.p | ||
| 25 | if [ $? != 0 ]; then exit 1; fi | ||
| 26 | |||
| 27 | echo "d -> d" | ||
| 28 | $cmd -in f.d -inform d -outform d >ff.d1 | ||
| 29 | if [ $? != 0 ]; then exit 1; fi | ||
| 30 | echo "n -> d" | ||
| 31 | $cmd -in f.n -inform n -outform d >ff.d2 | ||
| 32 | if [ $? != 0 ]; then exit 1; fi | ||
| 33 | echo "p -> d" | ||
| 34 | $cmd -in f.p -inform p -outform d >ff.d3 | ||
| 35 | if [ $? != 0 ]; then exit 1; fi | ||
| 36 | |||
| 37 | echo "d -> n" | ||
| 38 | $cmd -in f.d -inform d -outform n >ff.n1 | ||
| 39 | if [ $? != 0 ]; then exit 1; fi | ||
| 40 | echo "n -> n" | ||
| 41 | $cmd -in f.n -inform n -outform n >ff.n2 | ||
| 42 | if [ $? != 0 ]; then exit 1; fi | ||
| 43 | echo "p -> n" | ||
| 44 | $cmd -in f.p -inform p -outform n >ff.n3 | ||
| 45 | if [ $? != 0 ]; then exit 1; fi | ||
| 46 | |||
| 47 | echo "d -> p" | ||
| 48 | $cmd -in f.d -inform d -outform p >ff.p1 | ||
| 49 | if [ $? != 0 ]; then exit 1; fi | ||
| 50 | echo "n -> p" | ||
| 51 | $cmd -in f.n -inform n -outform p >ff.p2 | ||
| 52 | if [ $? != 0 ]; then exit 1; fi | ||
| 53 | echo "p -> p" | ||
| 54 | $cmd -in f.p -inform p -outform p >ff.p3 | ||
| 55 | if [ $? != 0 ]; then exit 1; fi | ||
| 56 | |||
| 57 | cmp fff.p f.p | ||
| 58 | if [ $? != 0 ]; then exit 1; fi | ||
| 59 | cmp fff.p ff.p1 | ||
| 60 | if [ $? != 0 ]; then exit 1; fi | ||
| 61 | cmp fff.p ff.p2 | ||
| 62 | if [ $? != 0 ]; then exit 1; fi | ||
| 63 | cmp fff.p ff.p3 | ||
| 64 | if [ $? != 0 ]; then exit 1; fi | ||
| 65 | |||
| 66 | cmp f.n ff.n1 | ||
| 67 | if [ $? != 0 ]; then exit 1; fi | ||
| 68 | cmp f.n ff.n2 | ||
| 69 | if [ $? != 0 ]; then exit 1; fi | ||
| 70 | cmp f.n ff.n3 | ||
| 71 | if [ $? != 0 ]; then exit 1; fi | ||
| 72 | |||
| 73 | cmp f.p ff.p1 | ||
| 74 | if [ $? != 0 ]; then exit 1; fi | ||
| 75 | cmp f.p ff.p2 | ||
| 76 | if [ $? != 0 ]; then exit 1; fi | ||
| 77 | cmp f.p ff.p3 | ||
| 78 | if [ $? != 0 ]; then exit 1; fi | ||
| 79 | |||
| 80 | /bin/rm -f f.* ff.* fff.* | ||
| 81 | exit 0 | ||
diff --git a/src/lib/libssl/test/v3-cert1.pem b/src/lib/libssl/test/v3-cert1.pem new file mode 100644 index 0000000000..0da253d5c3 --- /dev/null +++ b/src/lib/libssl/test/v3-cert1.pem | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | -----BEGIN CERTIFICATE----- | ||
| 2 | MIICjTCCAfigAwIBAgIEMaYgRzALBgkqhkiG9w0BAQQwRTELMAkGA1UEBhMCVVMx | ||
| 3 | NjA0BgNVBAoTLU5hdGlvbmFsIEFlcm9uYXV0aWNzIGFuZCBTcGFjZSBBZG1pbmlz | ||
| 4 | dHJhdGlvbjAmFxE5NjA1MjgxMzQ5MDUrMDgwMBcROTgwNTI4MTM0OTA1KzA4MDAw | ||
| 5 | ZzELMAkGA1UEBhMCVVMxNjA0BgNVBAoTLU5hdGlvbmFsIEFlcm9uYXV0aWNzIGFu | ||
| 6 | ZCBTcGFjZSBBZG1pbmlzdHJhdGlvbjEgMAkGA1UEBRMCMTYwEwYDVQQDEwxTdGV2 | ||
| 7 | ZSBTY2hvY2gwWDALBgkqhkiG9w0BAQEDSQAwRgJBALrAwyYdgxmzNP/ts0Uyf6Bp | ||
| 8 | miJYktU/w4NG67ULaN4B5CnEz7k57s9o3YY3LecETgQ5iQHmkwlYDTL2fTgVfw0C | ||
| 9 | AQOjgaswgagwZAYDVR0ZAQH/BFowWDBWMFQxCzAJBgNVBAYTAlVTMTYwNAYDVQQK | ||
| 10 | Ey1OYXRpb25hbCBBZXJvbmF1dGljcyBhbmQgU3BhY2UgQWRtaW5pc3RyYXRpb24x | ||
| 11 | DTALBgNVBAMTBENSTDEwFwYDVR0BAQH/BA0wC4AJODMyOTcwODEwMBgGA1UdAgQR | ||
| 12 | MA8ECTgzMjk3MDgyM4ACBSAwDQYDVR0KBAYwBAMCBkAwCwYJKoZIhvcNAQEEA4GB | ||
| 13 | AH2y1VCEw/A4zaXzSYZJTTUi3uawbbFiS2yxHvgf28+8Js0OHXk1H1w2d6qOHH21 | ||
| 14 | X82tZXd/0JtG0g1T9usFFBDvYK8O0ebgz/P5ELJnBL2+atObEuJy1ZZ0pBDWINR3 | ||
| 15 | WkDNLCGiTkCKp0F5EWIrVDwh54NNevkCQRZita+z4IBO | ||
| 16 | -----END CERTIFICATE----- | ||
diff --git a/src/lib/libssl/test/v3-cert2.pem b/src/lib/libssl/test/v3-cert2.pem new file mode 100644 index 0000000000..de0723ff8d --- /dev/null +++ b/src/lib/libssl/test/v3-cert2.pem | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | -----BEGIN CERTIFICATE----- | ||
| 2 | MIICiTCCAfKgAwIBAgIEMeZfHzANBgkqhkiG9w0BAQQFADB9MQswCQYDVQQGEwJD | ||
| 3 | YTEPMA0GA1UEBxMGTmVwZWFuMR4wHAYDVQQLExVObyBMaWFiaWxpdHkgQWNjZXB0 | ||
| 4 | ZWQxHzAdBgNVBAoTFkZvciBEZW1vIFB1cnBvc2VzIE9ubHkxHDAaBgNVBAMTE0Vu | ||
| 5 | dHJ1c3QgRGVtbyBXZWIgQ0EwHhcNOTYwNzEyMTQyMDE1WhcNOTYxMDEyMTQyMDE1 | ||
| 6 | WjB0MSQwIgYJKoZIhvcNAQkBExVjb29rZUBpc3NsLmF0bC5ocC5jb20xCzAJBgNV | ||
| 7 | BAYTAlVTMScwJQYDVQQLEx5IZXdsZXR0IFBhY2thcmQgQ29tcGFueSAoSVNTTCkx | ||
| 8 | FjAUBgNVBAMTDVBhdWwgQS4gQ29va2UwXDANBgkqhkiG9w0BAQEFAANLADBIAkEA | ||
| 9 | 6ceSq9a9AU6g+zBwaL/yVmW1/9EE8s5you1mgjHnj0wAILuoB3L6rm6jmFRy7QZT | ||
| 10 | G43IhVZdDua4e+5/n1ZslwIDAQABo2MwYTARBglghkgBhvhCAQEEBAMCB4AwTAYJ | ||
| 11 | YIZIAYb4QgENBD8WPVRoaXMgY2VydGlmaWNhdGUgaXMgb25seSBpbnRlbmRlZCBm | ||
| 12 | b3IgZGVtb25zdHJhdGlvbiBwdXJwb3Nlcy4wDQYJKoZIhvcNAQEEBQADgYEAi8qc | ||
| 13 | F3zfFqy1sV8NhjwLVwOKuSfhR/Z8mbIEUeSTlnH3QbYt3HWZQ+vXI8mvtZoBc2Fz | ||
| 14 | lexKeIkAZXCesqGbs6z6nCt16P6tmdfbZF3I3AWzLquPcOXjPf4HgstkyvVBn0Ap | ||
| 15 | jAFN418KF/Cx4qyHB4cjdvLrRjjQLnb2+ibo7QU= | ||
| 16 | -----END CERTIFICATE----- | ||
diff --git a/src/lib/libssl/tls1.h b/src/lib/libssl/tls1.h new file mode 100644 index 0000000000..60978613ef --- /dev/null +++ b/src/lib/libssl/tls1.h | |||
| @@ -0,0 +1,115 @@ | |||
| 1 | /* ssl/tls1.h */ | ||
| 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 | #ifndef HEADER_TLS1_H | ||
| 60 | #define HEADER_TLS1_H | ||
| 61 | |||
| 62 | #include "buffer.h" | ||
| 63 | |||
| 64 | #ifdef __cplusplus | ||
| 65 | extern "C" { | ||
| 66 | #endif | ||
| 67 | |||
| 68 | #define TLS1_VERSION 0x0301 | ||
| 69 | #define TLS1_VERSION_MAJOR 0x03 | ||
| 70 | #define TLS1_VERSION_MINOR 0x01 | ||
| 71 | |||
| 72 | #define TLS1_AD_DECRYPTION_FAILED 21 | ||
| 73 | #define TLS1_AD_RECORD_OVERFLOW 22 | ||
| 74 | #define TLS1_AD_UNKNOWN_CA 48 /* fatal */ | ||
| 75 | #define TLS1_AD_ACCESS_DENIED 49 /* fatal */ | ||
| 76 | #define TLS1_AD_DECODE_ERROR 50 /* fatal */ | ||
| 77 | #define TLS1_AD_DECRYPT_ERROR 51 | ||
| 78 | #define TLS1_AD_EXPORT_RESTRICION 60 /* fatal */ | ||
| 79 | #define TLS1_AD_PROTOCOL_VERSION 70 /* fatal */ | ||
| 80 | #define TLS1_AD_INSUFFICIENT_SECURITY 71 /* fatal */ | ||
| 81 | #define TLS1_AD_INTERNAL_ERROR 80 /* fatal */ | ||
| 82 | #define TLS1_AD_USER_CANCLED 90 | ||
| 83 | #define TLS1_AD_NO_RENEGOTIATION 100 | ||
| 84 | |||
| 85 | #define TLS_CT_RSA_SIGN 1 | ||
| 86 | #define TLS_CT_DSS_SIGN 2 | ||
| 87 | #define TLS_CT_RSA_FIXED_DH 3 | ||
| 88 | #define TLS_CT_DSS_FIXED_DH 4 | ||
| 89 | #define TLS_CT_NUMBER 4 | ||
| 90 | |||
| 91 | #define TLS1_FINISH_MAC_LENGTH 12 | ||
| 92 | |||
| 93 | #define TLS_MD_MAX_CONST_SIZE 20 | ||
| 94 | #define TLS_MD_CLIENT_FINISH_CONST "client finished" | ||
| 95 | #define TLS_MD_CLIENT_FINISH_CONST_SIZE 15 | ||
| 96 | #define TLS_MD_SERVER_FINISH_CONST "server finished" | ||
| 97 | #define TLS_MD_SERVER_FINISH_CONST_SIZE 15 | ||
| 98 | #define TLS_MD_SERVER_WRITE_KEY_CONST "server write key" | ||
| 99 | #define TLS_MD_SERVER_WRITE_KEY_CONST_SIZE 16 | ||
| 100 | #define TLS_MD_KEY_EXPANSION_CONST "key expansion" | ||
| 101 | #define TLS_MD_KEY_EXPANSION_CONST_SIZE 13 | ||
| 102 | #define TLS_MD_CLIENT_WRITE_KEY_CONST "client write key" | ||
| 103 | #define TLS_MD_CLIENT_WRITE_KEY_CONST_SIZE 16 | ||
| 104 | #define TLS_MD_SERVER_WRITE_KEY_CONST "server write key" | ||
| 105 | #define TLS_MD_SERVER_WRITE_KEY_CONST_SIZE 16 | ||
| 106 | #define TLS_MD_IV_BLOCK_CONST "IV block" | ||
| 107 | #define TLS_MD_IV_BLOCK_CONST_SIZE 8 | ||
| 108 | #define TLS_MD_MASTER_SECRET_CONST "master secret" | ||
| 109 | #define TLS_MD_MASTER_SECRET_CONST_SIZE 13 | ||
| 110 | |||
| 111 | #ifdef __cplusplus | ||
| 112 | } | ||
| 113 | #endif | ||
| 114 | #endif | ||
| 115 | |||
