diff options
author | Bob Beck <beck@cvs.openbsd.org> | 1999-09-29 05:53:44 +0000 |
---|---|---|
committer | Bob Beck <beck@cvs.openbsd.org> | 1999-09-29 05:53:44 +0000 |
commit | 93920c905b1e2ef7b83ea951bad983864ccb2a52 (patch) | |
tree | 1851db4c659862515eef8c90c11a44c1a1a24d86 /lib/libssl | |
parent | 622b003aa2a9b6d226b28976c9579e1352c4e5db (diff) |
new files for OpenSSL 0.9.4
Diffstat (limited to 'lib/libssl')
29 files changed, 4580 insertions, 0 deletions
diff --git a/lib/libssl/src/VMS/vms_idhacks.h b/lib/libssl/src/VMS/vms_idhacks.h new file mode 100644 index 00000000000..8cf9e9c61f8 --- /dev/null +++ b/lib/libssl/src/VMS/vms_idhacks.h @@ -0,0 +1,126 @@ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#ifndef HEADER_VMS_IDHACKS_H +#define HEADER_VMS_IDHACKS_H + +#ifdef VMS + +/* Hack the names created with DECLARE_STACK_OF(PKCS7_SIGNER_INFO) */ +#define sk_PKCS7_SIGNER_INFO_new sk_PKCS7_SIGINF_new +#define sk_PKCS7_SIGNER_INFO_new_null sk_PKCS7_SIGINF_new_null +#define sk_PKCS7_SIGNER_INFO_free sk_PKCS7_SIGINF_free +#define sk_PKCS7_SIGNER_INFO_num sk_PKCS7_SIGINF_num +#define sk_PKCS7_SIGNER_INFO_value sk_PKCS7_SIGINF_value +#define sk_PKCS7_SIGNER_INFO_set sk_PKCS7_SIGINF_set +#define sk_PKCS7_SIGNER_INFO_zero sk_PKCS7_SIGINF_zero +#define sk_PKCS7_SIGNER_INFO_push sk_PKCS7_SIGINF_push +#define sk_PKCS7_SIGNER_INFO_unshift sk_PKCS7_SIGINF_unshift +#define sk_PKCS7_SIGNER_INFO_find sk_PKCS7_SIGINF_find +#define sk_PKCS7_SIGNER_INFO_delete sk_PKCS7_SIGINF_delete +#define sk_PKCS7_SIGNER_INFO_delete_ptr sk_PKCS7_SIGINF_delete_ptr +#define sk_PKCS7_SIGNER_INFO_insert sk_PKCS7_SIGINF_insert +#define sk_PKCS7_SIGNER_INFO_set_cmp_func sk_PKCS7_SIGINF_set_cmp_func +#define sk_PKCS7_SIGNER_INFO_dup sk_PKCS7_SIGINF_dup +#define sk_PKCS7_SIGNER_INFO_pop_free sk_PKCS7_SIGINF_pop_free +#define sk_PKCS7_SIGNER_INFO_shift sk_PKCS7_SIGINF_shift +#define sk_PKCS7_SIGNER_INFO_pop sk_PKCS7_SIGINF_pop +#define sk_PKCS7_SIGNER_INFO_sort sk_PKCS7_SIGINF_sort + +/* Hack the names created with DECLARE_STACK_OF(PKCS7_RECIP_INFO) */ +#define sk_PKCS7_RECIP_INFO_new sk_PKCS7_RECINF_new +#define sk_PKCS7_RECIP_INFO_new_null sk_PKCS7_RECINF_new_null +#define sk_PKCS7_RECIP_INFO_free sk_PKCS7_RECINF_free +#define sk_PKCS7_RECIP_INFO_num sk_PKCS7_RECINF_num +#define sk_PKCS7_RECIP_INFO_value sk_PKCS7_RECINF_value +#define sk_PKCS7_RECIP_INFO_set sk_PKCS7_RECINF_set +#define sk_PKCS7_RECIP_INFO_zero sk_PKCS7_RECINF_zero +#define sk_PKCS7_RECIP_INFO_push sk_PKCS7_RECINF_push +#define sk_PKCS7_RECIP_INFO_unshift sk_PKCS7_RECINF_unshift +#define sk_PKCS7_RECIP_INFO_find sk_PKCS7_RECINF_find +#define sk_PKCS7_RECIP_INFO_delete sk_PKCS7_RECINF_delete +#define sk_PKCS7_RECIP_INFO_delete_ptr sk_PKCS7_RECINF_delete_ptr +#define sk_PKCS7_RECIP_INFO_insert sk_PKCS7_RECINF_insert +#define sk_PKCS7_RECIP_INFO_set_cmp_func sk_PKCS7_RECINF_set_cmp_func +#define sk_PKCS7_RECIP_INFO_dup sk_PKCS7_RECINF_dup +#define sk_PKCS7_RECIP_INFO_pop_free sk_PKCS7_RECINF_pop_free +#define sk_PKCS7_RECIP_INFO_shift sk_PKCS7_RECINF_shift +#define sk_PKCS7_RECIP_INFO_pop sk_PKCS7_RECINF_pop +#define sk_PKCS7_RECIP_INFO_sort sk_PKCS7_RECINF_sort + +/* Hack the names created with DECLARE_ASN1_SET_OF(PKCS7_SIGNER_INFO) */ +#define i2d_ASN1_SET_OF_PKCS7_SIGNER_INFO i2d_ASN1_SET_OF_PKCS7_SIGINF +#define d2i_ASN1_SET_OF_PKCS7_SIGNER_INFO d2i_ASN1_SET_OF_PKCS7_SIGINF + +/* Hack the names created with DECLARE_ASN1_SET_OF(PKCS7_RECIP_INFO) */ +#define i2d_ASN1_SET_OF_PKCS7_RECIP_INFO i2d_ASN1_SET_OF_PKCS7_RECGINF +#define d2i_ASN1_SET_OF_PKCS7_RECIP_INFO d2i_ASN1_SET_OF_PKCS7_RECGINF + +/* Hack the names created with DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE) */ +#define PEM_read_NETSCAPE_CERT_SEQUENCE PEM_read_NS_CERT_SEQUENCE +#define PEM_write_NETSCAPE_CERT_SEQUENCE PEM_write_NS_CERT_SEQUENCE +#define PEM_read_bio_NETSCAPE_CERT_SEQUENCE PEM_read_bio_NS_CERT_SEQUENCE +#define PEM_write_bio_NETSCAPE_CERT_SEQUENCE PEM_write_bio_NS_CERT_SEQUENCE +#define PEM_write_cb_bio_NETSCAPE_CERT_SEQUENCE PEM_write_cb_bio_NS_CERT_SEQUENCE + +/* Hack the names created with DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO) */ +#define PEM_read_PKCS8_PRIV_KEY_INFO PEM_read_P8_PRIV_KEY_INFO +#define PEM_write_PKCS8_PRIV_KEY_INFO PEM_write_P8_PRIV_KEY_INFO +#define PEM_read_bio_PKCS8_PRIV_KEY_INFO PEM_read_bio_P8_PRIV_KEY_INFO +#define PEM_write_bio_PKCS8_PRIV_KEY_INFO PEM_write_bio_P8_PRIV_KEY_INFO +#define PEM_write_cb_bio_PKCS8_PRIV_KEY_INFO PEM_write_cb_bio_P8_PRIV_KEY_INFO + +#endif /* defined VMS */ + +#endif /* ! defined HEADER_VMS_IDHACKS_H */ diff --git a/lib/libssl/src/apps/rsa/01.pem b/lib/libssl/src/apps/rsa/01.pem new file mode 100644 index 00000000000..36ec57598ef --- /dev/null +++ b/lib/libssl/src/apps/rsa/01.pem @@ -0,0 +1,15 @@ +-----BEGIN CERTIFICATE----- +MIICTjCCAbsCEGiuFKTJn6nzmiPPLxUZs1owDQYJKoZIhvcNAQEEBQAwXzELMAkG +A1UEBhMCVVMxIDAeBgNVBAoTF1JTQSBEYXRhIFNlY3VyaXR5LCBJbmMuMS4wLAYD +VQQLEyVTZWN1cmUgU2VydmVyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTk4 +MDUxODAwMDAwMFoXDTk5MDUxODIzNTk1OVowdTELMAkGA1UEBhMCVVMxETAPBgNV +BAgTCE5ldyBZb3JrMREwDwYDVQQHFAhOZXcgWW9yazEeMBwGA1UEChQVSW5kdXN0 +cmlhbCBQcmVzcyBJbmMuMSAwHgYDVQQDFBd3d3cuaW5kdXN0cmlhbHByZXNzLmNv +bTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAqiH9xUJNHvqCmaDon27ValJb +qTLymF3yKKWBxbODLWjX7yKjewoqWhotaEARI6jXPqomU87gFU1tH4r/bgwh3FmU +MK3qo92XOsvwNAHzXzWRXQNJmm54g2F1RUt00pgYiOximDse1t9RL5POCDEbfX8D +gugrE/WwkS2FrSoc5/cCAwEAATANBgkqhkiG9w0BAQQFAAN+AIw7fvF0EtEvrNS/ +LYuqAgUw/tH0FLgCkqKLmYYm/yR+Z0hD2eP/UhF+jAwmV8rHtBnaTM7oN23RVW2k +Cf8soiGfr2PYtfufpXtd7azUFa+WJCWnp0N29EG0BR1JOFC0Q/4dh/X9qulM8luq +Pjrmw2eSgbdmmdumWAcNPVbV +-----END CERTIFICATE----- diff --git a/lib/libssl/src/apps/rsa/1.txt b/lib/libssl/src/apps/rsa/1.txt new file mode 100644 index 00000000000..95a862e150e --- /dev/null +++ b/lib/libssl/src/apps/rsa/1.txt @@ -0,0 +1,50 @@ +issuer= /C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority +subject=/C=US/ST=New York/L=New York/O=Industrial Press Inc./CN=www.industrialpress.com +Certificate: + Data: + Version: 1 (0x0) + Serial Number: + 68:ae:14:a4:c9:9f:a9:f3:9a:23:cf:2f:15:19:b3:5a + Signature Algorithm: md5WithRSAEncryption + Issuer: C=US, O=RSA Data Security, Inc., OU=Secure Server Certification Authority + Validity + Not Before: May 18 00:00:00 1998 GMT + Not After : May 18 23:59:59 1999 GMT + Subject: C=US, ST=New York, L=New York, O=Industrial Press Inc., CN=www.industrialpress.com + Subject Public Key Info: + Public Key Algorithm: rsaEncryption + RSA Public Key: (1024 bit) + Modulus (1024 bit): + 00:aa:21:fd:c5:42:4d:1e:fa:82:99:a0:e8:9f:6e: + d5:6a:52:5b:a9:32:f2:98:5d:f2:28:a5:81:c5:b3: + 83:2d:68:d7:ef:22:a3:7b:0a:2a:5a:1a:2d:68:40: + 11:23:a8:d7:3e:aa:26:53:ce:e0:15:4d:6d:1f:8a: + ff:6e:0c:21:dc:59:94:30:ad:ea:a3:dd:97:3a:cb: + f0:34:01:f3:5f:35:91:5d:03:49:9a:6e:78:83:61: + 75:45:4b:74:d2:98:18:88:ec:62:98:3b:1e:d6:df: + 51:2f:93:ce:08:31:1b:7d:7f:03:82:e8:2b:13:f5: + b0:91:2d:85:ad:2a:1c:e7:f7 + Exponent: 65537 (0x10001) + Signature Algorithm: md5WithRSAEncryption + 8c:3b:7e:f1:74:12:d1:2f:ac:d4:bf:2d:8b:aa:02:05:30:fe: + d1:f4:14:b8:02:92:a2:8b:99:86:26:ff:24:7e:67:48:43:d9: + e3:ff:52:11:7e:8c:0c:26:57:ca:c7:b4:19:da:4c:ce:e8:37: + 6d:d1:55:6d:a4:09:ff:2c:a2:21:9f:af:63:d8:b5:fb:9f:a5: + 7b:5d:ed:ac:d4:15:af:96:24:25:a7:a7:43:76:f4:41:b4:05: + 1d:49:38:50:b4:43:fe:1d:87:f5:fd:aa:e9:4c:f2:5b:aa:3e: + 3a:e6:c3:67:92:81:b7:66:99:db:a6:58:07:0d:3d:56:d5 +-----BEGIN CERTIFICATE----- +MIICTjCCAbsCEGiuFKTJn6nzmiPPLxUZs1owDQYJKoZIhvcNAQEEBQAwXzELMAkG +A1UEBhMCVVMxIDAeBgNVBAoTF1JTQSBEYXRhIFNlY3VyaXR5LCBJbmMuMS4wLAYD +VQQLEyVTZWN1cmUgU2VydmVyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTk4 +MDUxODAwMDAwMFoXDTk5MDUxODIzNTk1OVowdTELMAkGA1UEBhMCVVMxETAPBgNV +BAgTCE5ldyBZb3JrMREwDwYDVQQHFAhOZXcgWW9yazEeMBwGA1UEChQVSW5kdXN0 +cmlhbCBQcmVzcyBJbmMuMSAwHgYDVQQDFBd3d3cuaW5kdXN0cmlhbHByZXNzLmNv +bTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAqiH9xUJNHvqCmaDon27ValJb +qTLymF3yKKWBxbODLWjX7yKjewoqWhotaEARI6jXPqomU87gFU1tH4r/bgwh3FmU +MK3qo92XOsvwNAHzXzWRXQNJmm54g2F1RUt00pgYiOximDse1t9RL5POCDEbfX8D +gugrE/WwkS2FrSoc5/cCAwEAATANBgkqhkiG9w0BAQQFAAN+AIw7fvF0EtEvrNS/ +LYuqAgUw/tH0FLgCkqKLmYYm/yR+Z0hD2eP/UhF+jAwmV8rHtBnaTM7oN23RVW2k +Cf8soiGfr2PYtfufpXtd7azUFa+WJCWnp0N29EG0BR1JOFC0Q/4dh/X9qulM8luq +Pjrmw2eSgbdmmdumWAcNPVbV +-----END CERTIFICATE----- diff --git a/lib/libssl/src/apps/rsa/SecureServer.pem b/lib/libssl/src/apps/rsa/SecureServer.pem new file mode 100644 index 00000000000..7c8ffb2cd85 --- /dev/null +++ b/lib/libssl/src/apps/rsa/SecureServer.pem @@ -0,0 +1,47 @@ +Certificate: + Data: + Version: 1 (0x0) + Serial Number: + 02:ad:66:7e:4e:45:fe:5e:57:6f:3c:98:19:5e:dd:c0 + Signature Algorithm: md2WithRSAEncryption + Issuer: C=US, O=RSA Data Security, Inc., OU=Secure Server Certification Authority + Validity + Not Before: Nov 9 00:00:00 1994 GMT + Not After : Jan 7 23:59:59 2010 GMT + Subject: C=US, O=RSA Data Security, Inc., OU=Secure Server Certification Authority + Subject Public Key Info: + Public Key Algorithm: rsaEncryption + RSA Public Key: (1000 bit) + Modulus (1000 bit): + 00:92:ce:7a:c1:ae:83:3e:5a:aa:89:83:57:ac:25: + 01:76:0c:ad:ae:8e:2c:37:ce:eb:35:78:64:54:03: + e5:84:40:51:c9:bf:8f:08:e2:8a:82:08:d2:16:86: + 37:55:e9:b1:21:02:ad:76:68:81:9a:05:a2:4b:c9: + 4b:25:66:22:56:6c:88:07:8f:f7:81:59:6d:84:07: + 65:70:13:71:76:3e:9b:77:4c:e3:50:89:56:98:48: + b9:1d:a7:29:1a:13:2e:4a:11:59:9c:1e:15:d5:49: + 54:2c:73:3a:69:82:b1:97:39:9c:6d:70:67:48:e5: + dd:2d:d6:c8:1e:7b + Exponent: 65537 (0x10001) + Signature Algorithm: md2WithRSAEncryption + 65:dd:7e:e1:b2:ec:b0:e2:3a:e0:ec:71:46:9a:19:11:b8:d3: + c7:a0:b4:03:40:26:02:3e:09:9c:e1:12:b3:d1:5a:f6:37:a5: + b7:61:03:b6:5b:16:69:3b:c6:44:08:0c:88:53:0c:6b:97:49: + c7:3e:35:dc:6c:b9:bb:aa:df:5c:bb:3a:2f:93:60:b6:a9:4b: + 4d:f2:20:f7:cd:5f:7f:64:7b:8e:dc:00:5c:d7:fa:77:ca:39: + 16:59:6f:0e:ea:d3:b5:83:7f:4d:4d:42:56:76:b4:c9:5f:04: + f8:38:f8:eb:d2:5f:75:5f:cd:7b:fc:e5:8e:80:7c:fc:50 +-----BEGIN CERTIFICATE----- +MIICNDCCAaECEAKtZn5ORf5eV288mBle3cAwDQYJKoZIhvcNAQECBQAwXzELMAkG +A1UEBhMCVVMxIDAeBgNVBAoTF1JTQSBEYXRhIFNlY3VyaXR5LCBJbmMuMS4wLAYD +VQQLEyVTZWN1cmUgU2VydmVyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTk0 +MTEwOTAwMDAwMFoXDTEwMDEwNzIzNTk1OVowXzELMAkGA1UEBhMCVVMxIDAeBgNV +BAoTF1JTQSBEYXRhIFNlY3VyaXR5LCBJbmMuMS4wLAYDVQQLEyVTZWN1cmUgU2Vy +dmVyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGbMA0GCSqGSIb3DQEBAQUAA4GJ +ADCBhQJ+AJLOesGugz5aqomDV6wlAXYMra6OLDfO6zV4ZFQD5YRAUcm/jwjiioII +0haGN1XpsSECrXZogZoFokvJSyVmIlZsiAeP94FZbYQHZXATcXY+m3dM41CJVphI +uR2nKRoTLkoRWZweFdVJVCxzOmmCsZc5nG1wZ0jl3S3WyB57AgMBAAEwDQYJKoZI +hvcNAQECBQADfgBl3X7hsuyw4jrg7HFGmhkRuNPHoLQDQCYCPgmc4RKz0Vr2N6W3 +YQO2WxZpO8ZECAyIUwxrl0nHPjXcbLm7qt9cuzovk2C2qUtN8iD3zV9/ZHuO3ABc +1/p3yjkWWW8O6tO1g39NTUJWdrTJXwT4OPjr0l91X817/OWOgHz8UA== +-----END CERTIFICATE----- diff --git a/lib/libssl/src/apps/rsa/s.txt b/lib/libssl/src/apps/rsa/s.txt new file mode 100644 index 00000000000..7de7e0764fa --- /dev/null +++ b/lib/libssl/src/apps/rsa/s.txt @@ -0,0 +1,49 @@ +issuer= /C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority +subject=/C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority +Certificate: + Data: + Version: 1 (0x0) + Serial Number: + 02:ad:66:7e:4e:45:fe:5e:57:6f:3c:98:19:5e:dd:c0 + Signature Algorithm: md2WithRSAEncryption + Issuer: C=US, O=RSA Data Security, Inc., OU=Secure Server Certification Authority + Validity + Not Before: Nov 9 00:00:00 1994 GMT + Not After : Jan 7 23:59:59 2010 GMT + Subject: C=US, O=RSA Data Security, Inc., OU=Secure Server Certification Authority + Subject Public Key Info: + Public Key Algorithm: rsaEncryption + RSA Public Key: (1000 bit) + Modulus (1000 bit): + 00:92:ce:7a:c1:ae:83:3e:5a:aa:89:83:57:ac:25: + 01:76:0c:ad:ae:8e:2c:37:ce:eb:35:78:64:54:03: + e5:84:40:51:c9:bf:8f:08:e2:8a:82:08:d2:16:86: + 37:55:e9:b1:21:02:ad:76:68:81:9a:05:a2:4b:c9: + 4b:25:66:22:56:6c:88:07:8f:f7:81:59:6d:84:07: + 65:70:13:71:76:3e:9b:77:4c:e3:50:89:56:98:48: + b9:1d:a7:29:1a:13:2e:4a:11:59:9c:1e:15:d5:49: + 54:2c:73:3a:69:82:b1:97:39:9c:6d:70:67:48:e5: + dd:2d:d6:c8:1e:7b + Exponent: 65537 (0x10001) + Signature Algorithm: md2WithRSAEncryption + 65:dd:7e:e1:b2:ec:b0:e2:3a:e0:ec:71:46:9a:19:11:b8:d3: + c7:a0:b4:03:40:26:02:3e:09:9c:e1:12:b3:d1:5a:f6:37:a5: + b7:61:03:b6:5b:16:69:3b:c6:44:08:0c:88:53:0c:6b:97:49: + c7:3e:35:dc:6c:b9:bb:aa:df:5c:bb:3a:2f:93:60:b6:a9:4b: + 4d:f2:20:f7:cd:5f:7f:64:7b:8e:dc:00:5c:d7:fa:77:ca:39: + 16:59:6f:0e:ea:d3:b5:83:7f:4d:4d:42:56:76:b4:c9:5f:04: + f8:38:f8:eb:d2:5f:75:5f:cd:7b:fc:e5:8e:80:7c:fc:50 +-----BEGIN CERTIFICATE----- +MIICNDCCAaECEAKtZn5ORf5eV288mBle3cAwDQYJKoZIhvcNAQECBQAwXzELMAkG +A1UEBhMCVVMxIDAeBgNVBAoTF1JTQSBEYXRhIFNlY3VyaXR5LCBJbmMuMS4wLAYD +VQQLEyVTZWN1cmUgU2VydmVyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTk0 +MTEwOTAwMDAwMFoXDTEwMDEwNzIzNTk1OVowXzELMAkGA1UEBhMCVVMxIDAeBgNV +BAoTF1JTQSBEYXRhIFNlY3VyaXR5LCBJbmMuMS4wLAYDVQQLEyVTZWN1cmUgU2Vy +dmVyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGbMA0GCSqGSIb3DQEBAQUAA4GJ +ADCBhQJ+AJLOesGugz5aqomDV6wlAXYMra6OLDfO6zV4ZFQD5YRAUcm/jwjiioII +0haGN1XpsSECrXZogZoFokvJSyVmIlZsiAeP94FZbYQHZXATcXY+m3dM41CJVphI +uR2nKRoTLkoRWZweFdVJVCxzOmmCsZc5nG1wZ0jl3S3WyB57AgMBAAEwDQYJKoZI +hvcNAQECBQADfgBl3X7hsuyw4jrg7HFGmhkRuNPHoLQDQCYCPgmc4RKz0Vr2N6W3 +YQO2WxZpO8ZECAyIUwxrl0nHPjXcbLm7qt9cuzovk2C2qUtN8iD3zV9/ZHuO3ABc +1/p3yjkWWW8O6tO1g39NTUJWdrTJXwT4OPjr0l91X817/OWOgHz8UA== +-----END CERTIFICATE----- diff --git a/lib/libssl/src/crypto/bn/old/b_sqr.c b/lib/libssl/src/crypto/bn/old/b_sqr.c new file mode 100644 index 00000000000..715cb1c8abb --- /dev/null +++ b/lib/libssl/src/crypto/bn/old/b_sqr.c @@ -0,0 +1,199 @@ +/* crypto/bn/bn_mul.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include <stdio.h> +#include "cryptlib.h" +#include "bn_lcl.h" + +static int bn_mm(BIGNUM *m,BIGNUM *A,BIGNUM *B, BIGNUM *sk,BN_CTX *ctx); + +/* r must be different to a and b */ +/* int BN_mmul(r, a, b) */ +int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b) + { + BN_ULONG *ap,*bp,*rp; + BIGNUM *sk; + int i,n,ret; + int max,al,bl; + BN_CTX ctx; + + bn_check_top(a); + bn_check_top(b); + + al=a->top; + bl=b->top; + if ((al == 0) || (bl == 0)) + { + r->top=0; + return(1); + } +#ifdef BN_MUL_DEBUG +printf("BN_mul(%d,%d)\n",a->top,b->top); +#endif + + if ( (bn_limit_bits > 0) && + (bl > bn_limit_num) && (al > bn_limit_num)) + { + n=(BN_num_bits_word(al|bl)-bn_limit_bits); + n*=2; + sk=(BIGNUM *)Malloc(sizeof(BIGNUM)*n); + memset(sk,0,sizeof(BIGNUM)*n); + memset(&ctx,0,sizeof(ctx)); + + ret=bn_mm(r,a,b,&(sk[0]),&ctx); + for (i=0; i<n; i+=2) + { + BN_clear_free(&sk[i]); + BN_clear_free(&sk[i+1]); + } + Free(sk); + return(ret); + } + + max=(al+bl); + if (bn_wexpand(r,max) == NULL) return(0); + r->top=max; + r->neg=a->neg^b->neg; + ap=a->d; + bp=b->d; + rp=r->d; + + rp[al]=bn_mul_words(rp,ap,al,*(bp++)); + rp++; + for (i=1; i<bl; i++) + { + rp[al]=bn_mul_add_words(rp,ap,al,*(bp++)); + rp++; + } + if ((max > 0) && (r->d[max-1] == 0)) r->top--; + return(1); + } + + +#define ahal (sk[0]) +#define blbh (sk[1]) + +/* r must be different to a and b */ +int bn_mm(BIGNUM *m, BIGNUM *A, BIGNUM *B, BIGNUM *sk, BN_CTX *ctx) + { + int n,num,sqr=0; + int an,bn; + BIGNUM ah,al,bh,bl; + + an=A->top; + bn=B->top; +#ifdef BN_MUL_DEBUG +printf("bn_mm(%d,%d)\n",A->top,B->top); +#endif + + if (A == B) sqr=1; + num=(an>bn)?an:bn; + n=(num+1)/2; + /* Are going to now chop things into 'num' word chunks. */ + + BN_init(&ah); + BN_init(&al); + BN_init(&bh); + BN_init(&bl); + + bn_set_low (&al,A,n); + bn_set_high(&ah,A,n); + bn_set_low (&bl,B,n); + bn_set_high(&bh,B,n); + + BN_sub(&ahal,&ah,&al); + BN_sub(&blbh,&bl,&bh); + + if (num <= (bn_limit_num+bn_limit_num)) + { + BN_mul(m,&ahal,&blbh); + if (sqr) + { + BN_sqr(&ahal,&al,ctx); + BN_sqr(&blbh,&ah,ctx); + } + else + { + BN_mul(&ahal,&al,&bl); + BN_mul(&blbh,&ah,&bh); + } + } + else + { + bn_mm(m,&ahal,&blbh,&(sk[2]),ctx); + bn_mm(&ahal,&al,&bl,&(sk[2]),ctx); + bn_mm(&blbh,&ah,&bh,&(sk[2]),ctx); + } + + BN_add(m,m,&ahal); + BN_add(m,m,&blbh); + + BN_lshift(m,m,n*BN_BITS2); + BN_lshift(&blbh,&blbh,n*BN_BITS2*2); + + BN_add(m,m,&ahal); + BN_add(m,m,&blbh); + + m->neg=A->neg^B->neg; + return(1); + } +#undef ahal (sk[0]) +#undef blbh (sk[1]) + +#include "bn_low.c" +#include "bn_high.c" diff --git a/lib/libssl/src/crypto/bn/old/bn_com.c b/lib/libssl/src/crypto/bn/old/bn_com.c new file mode 100644 index 00000000000..7666b2304c8 --- /dev/null +++ b/lib/libssl/src/crypto/bn/old/bn_com.c @@ -0,0 +1,90 @@ +/* crypto/bn/bn_mulw.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include <stdio.h> +#include "cryptlib.h" +#include "bn_lcl.h" + +#ifdef BN_LLONG + +ab +12 + a2 b2 +a1 b1 + +abc +123 + a3 b3 c3 + a2 b2 c2 +a1 b1 c1 + +abcd +1234 + a4 b4 c4 d4 + a3 b3 c3 d3 + a2 b2 c2 d2 +a1 b1 c1 d1 + +abcde +01234 + a5 b5 c5 d5 e5 + a4 b4 c4 d4 e4 + a3 b3 c3 d3 e3 + a2 b2 c2 d2 e2 + a1 b1 c1 d1 e1 +a0 b0 c0 d0 e0 diff --git a/lib/libssl/src/crypto/bn/old/bn_high.c b/lib/libssl/src/crypto/bn/old/bn_high.c new file mode 100644 index 00000000000..763bcb605b3 --- /dev/null +++ b/lib/libssl/src/crypto/bn/old/bn_high.c @@ -0,0 +1,135 @@ +#include <stdio.h> +#include "cryptlib.h" +#include "bn_lcl.h" + +#undef BN_MUL_HIGH_DEBUG + +#ifdef BN_MUL_HIGH_DEBUG +#define debug_BN_print(a,b,c) BN_print_fp(a,b); printf(c); +#else +#define debug_BN_print(a,b,c) +#endif + +int BN_mul_high(BIGNUM *r,BIGNUM *a,BIGNUM *b,BIGNUM *low, int words); + +#undef t1 +#undef t2 + +int BN_mul_high(BIGNUM *r, BIGNUM *a, BIGNUM *b, BIGNUM *low, int words) + { + int w2,borrow=0,full=0; + BIGNUM t1,t2,t3,h,ah,al,bh,bl,m,s0,s1; + BN_ULONG ul1,ul2; + + BN_mul(r,a,b); + BN_rshift(r,r,words*BN_BITS2); + return(1); + + w2=(words+1)/2; + +#ifdef BN_MUL_HIGH_DEBUG +fprintf(stdout,"words=%d w2=%d\n",words,w2); +#endif +debug_BN_print(stdout,a," a\n"); +debug_BN_print(stdout,b," b\n"); +debug_BN_print(stdout,low," low\n"); + BN_init(&al); BN_init(&ah); + BN_init(&bl); BN_init(&bh); + BN_init(&t1); BN_init(&t2); BN_init(&t3); + BN_init(&s0); BN_init(&s1); + BN_init(&h); BN_init(&m); + + bn_set_low (&al,a,w2); + bn_set_high(&ah,a,w2); + bn_set_low (&bl,b,w2); + bn_set_high(&bh,b,w2); + + bn_set_low(&s0,low,w2); + bn_set_high(&s1,low,w2); + +debug_BN_print(stdout,&al," al\n"); +debug_BN_print(stdout,&ah," ah\n"); +debug_BN_print(stdout,&bl," bl\n"); +debug_BN_print(stdout,&bh," bh\n"); +debug_BN_print(stdout,&s0," s0\n"); +debug_BN_print(stdout,&s1," s1\n"); + + /* Calculate (al-ah)*(bh-bl) */ + BN_sub(&t1,&al,&ah); + BN_sub(&t2,&bh,&bl); + BN_mul(&m,&t1,&t2); + + /* Calculate ah*bh */ + BN_mul(&h,&ah,&bh); + + /* s0 == low(al*bl) + * s1 == low(ah*bh)+low((al-ah)*(bh-bl))+low(al*bl)+high(al*bl) + * We know s0 and s1 so the only unknown is high(al*bl) + * high(al*bl) == s1 - low(ah*bh+(al-ah)*(bh-bl)+s0) + */ + BN_add(&m,&m,&h); + BN_add(&t2,&m,&s0); + +debug_BN_print(stdout,&t2," middle value\n"); + + /* Quick and dirty mask off of high words */ + if (w2 < t2.top) t2.top=w2; +#if 0 + bn_set_low(&t3,&t2,w2); +#endif + +debug_BN_print(stdout,&t2," low middle value\n"); + BN_sub(&t1,&s1,&t2); + + if (t1.neg) + { +debug_BN_print(stdout,&t1," before\n"); + BN_zero(&t2); + BN_set_bit(&t2,w2*BN_BITS2); + BN_add(&t1,&t2,&t1); + /* BN_mask_bits(&t1,w2*BN_BITS2); */ + /* if (words < t1.top) t1.top=words; */ +debug_BN_print(stdout,&t1," after\n"); + borrow=1; + } + +/* XXXXX SPEED THIS UP */ + /* al*bl == high(al*bl)<<words+s0 */ + BN_lshift(&t1,&t1,w2*BN_BITS2); + BN_add(&t1,&t1,&s0); + if (w2*2 < t1.top) t1.top=w2*2; /* This should not happen? */ + + /* We now have + * al*bl - t1 + * (al-ah)*(bh-bl)+ah*bh - m + * ah*bh - h + */ +#if 0 + BN_add(&m,&m,&t1); +debug_BN_print(stdout,&t1," s10\n"); +debug_BN_print(stdout,&m," s21\n"); +debug_BN_print(stdout,&h," s32\n"); + BN_lshift(&m,&m,w2*BN_BITS2); + BN_lshift(&h,&h,w2*2*BN_BITS2); + BN_add(r,&m,&t1); + BN_add(r,r,&h); + BN_rshift(r,r,w2*2*BN_BITS2); +#else + BN_add(&m,&m,&t1); /* Do a cmp then +1 if needed? */ + bn_set_high(&t3,&t1,w2); + BN_add(&m,&m,&t3); + bn_set_high(&t3,&m,w2); + BN_add(r,&h,&t3); +#endif + +#ifdef BN_MUL_HIGH_DEBUG +printf("carry=%d\n",borrow); +#endif +debug_BN_print(stdout,r," ret\n"); + BN_free(&t1); BN_free(&t2); + BN_free(&m); BN_free(&h); + return(1); + } + + + diff --git a/lib/libssl/src/crypto/bn/old/bn_ka.c b/lib/libssl/src/crypto/bn/old/bn_ka.c new file mode 100644 index 00000000000..378c94dc5a7 --- /dev/null +++ b/lib/libssl/src/crypto/bn/old/bn_ka.c @@ -0,0 +1,567 @@ +#include <stdio.h> +#include <stdlib.h> +#include <strings.h> +#include "bn_lcl.h" + +/* r is 2*n2 words in size, + * a and b are both n2 words in size. + * n2 must be a power of 2. + * We multiply and return the result. + * t must be 2*n2 words in size + * We calulate + * a[0]*b[0] + * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0]) + * a[1]*b[1] + */ +void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2, + BN_ULONG *t) + { + int n=n2/2; + int neg,zero,c1,c2; + BN_ULONG ln,lo,*p; + +#ifdef BN_COUNT +printf(" bn_mul_recursive %d * %d\n",n2,n2); +#endif + if (n2 <= 8) + { + if (n2 == 8) + bn_mul_comba8(r,a,b); + else + bn_mul_normal(r,a,n2,b,n2); + return; + } + + if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL) + { + /* This should not happen */ + /*abort(); */ + bn_mul_normal(r,a,n2,b,n2); + return; + } + /* r=(a[0]-a[1])*(b[1]-b[0]) */ + c1=bn_cmp_words(a,&(a[n]),n); + c2=bn_cmp_words(&(b[n]),b,n); + zero=neg=0; + switch (c1*3+c2) + { + case -4: + bn_sub_words(t, &(a[n]),a, n); /* - */ + bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */ + break; + case -3: + zero=1; + break; + case -2: + bn_sub_words(t, &(a[n]),a, n); /* - */ + bn_sub_words(&(t[n]),&(b[n]),b, n); /* + */ + neg=1; + break; + case -1: + case 0: + case 1: + zero=1; + break; + case 2: + bn_sub_words(t, a, &(a[n]),n); /* + */ + bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */ + neg=1; + break; + case 3: + zero=1; + break; + case 4: + bn_sub_words(t, a, &(a[n]),n); + bn_sub_words(&(t[n]),&(b[n]),b, n); + break; + } + + if (n == 8) + { + if (!zero) + bn_mul_comba8(&(t[n2]),t,&(t[n])); + else + memset(&(t[n2]),0,8*sizeof(BN_ULONG)); + + bn_mul_comba8(r,a,b); + bn_mul_comba8(&(r[n2]),&(a[n]),&(b[n])); + } + else + { + p= &(t[n2*2]); + if (!zero) + bn_mul_recursive(&(t[n2]),t,&(t[n]),n,p); + else + memset(&(t[n2]),0,n*sizeof(BN_ULONG)); + bn_mul_recursive(r,a,b,n,p); + bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),n,p); + } + + /* t[32] holds (a[0]-a[1])*(b[1]-b[0]), c1 is the sign + * r[10] holds (a[0]*b[0]) + * r[32] holds (b[1]*b[1]) + */ + + c1=bn_add_words(t,r,&(r[n2]),n2); + + if (neg) /* if t[32] is negative */ + { + c1-=bn_sub_words(&(t[n2]),t,&(t[n2]),n2); + } + else + { + /* Might have a carry */ + c1+=bn_add_words(&(t[n2]),&(t[n2]),t,n2); + } + + /* t[32] holds (a[0]-a[1])*(b[1]-b[0])+(a[0]*b[0])+(a[1]*b[1]) + * r[10] holds (a[0]*b[0]) + * r[32] holds (b[1]*b[1]) + * c1 holds the carry bits + */ + c1+=bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2); + if (c1) + { + p= &(r[n+n2]); + lo= *p; + ln=(lo+c1)&BN_MASK2; + *p=ln; + + /* The overflow will stop before we over write + * words we should not overwrite */ + if (ln < c1) + { + do { + p++; + lo= *p; + ln=(lo+1)&BN_MASK2; + *p=ln; + } while (ln == 0); + } + } + } + +/* n+tn is the word length + * t needs to be n*4 is size, as does r */ +void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int tn, + int n, BN_ULONG *t) + { + int n2=n*2,i,j; + int c1; + BN_ULONG ln,lo,*p; + +#ifdef BN_COUNT +printf(" bn_mul_part_recursive %d * %d\n",tn+n,tn+n); +#endif + if (n < 8) + { + i=tn+n; + bn_mul_normal(r,a,i,b,i); + return; + } + + /* r=(a[0]-a[1])*(b[1]-b[0]) */ + bn_sub_words(t, a, &(a[n]),n); /* + */ + bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */ + + if (n == 8) + { + bn_mul_comba8(&(t[n2]),t,&(t[n])); + bn_mul_comba8(r,a,b); + bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn); + memset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2)); + } + else + { + p= &(t[n2*2]); + bn_mul_recursive(&(t[n2]),t,&(t[n]),n,p); + bn_mul_recursive(r,a,b,n,p); + i=n/2; + /* If there is only a bottom half to the number, + * just do it */ + j=tn-i; + if (j == 0) + { + bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),i,p); + memset(&(r[n2+i*2]),0,sizeof(BN_ULONG)*(n2-i*2)); + } + else if (j > 0) /* eg, n == 16, i == 8 and tn == 11 */ + { + bn_mul_part_recursive(&(r[n2]),&(a[n]),&(b[n]), + j,i,p); + memset(&(r[n2+tn*2]),0, + sizeof(BN_ULONG)*(n2-tn*2)); + } + else /* (j < 0) eg, n == 16, i == 8 and tn == 5 */ + { + memset(&(r[n2]),0,sizeof(BN_ULONG)*(tn*2)); + for (;;) + { + i/=2; + if (i < tn) + { + bn_mul_part_recursive(&(r[n2]), + &(a[n]),&(b[n]), + tn-i,i,p); + break; + } + else if (i == tn) + { + bn_mul_recursive(&(r[n2]), + &(a[n]),&(b[n]), + i,p); + break; + } + } + } + } + + /* t[32] holds (a[0]-a[1])*(b[1]-b[0]), c1 is the sign + * r[10] holds (a[0]*b[0]) + * r[32] holds (b[1]*b[1]) + */ + + c1=bn_add_words(t,r,&(r[n2]),n2); + c1-=bn_sub_words(&(t[n2]),t,&(t[n2]),n2); + + /* t[32] holds (a[0]-a[1])*(b[1]-b[0])+(a[0]*b[0])+(a[1]*b[1]) + * r[10] holds (a[0]*b[0]) + * r[32] holds (b[1]*b[1]) + * c1 holds the carry bits + */ + c1+=bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2); + if (c1) + { + p= &(r[n+n2]); + lo= *p; + ln=(lo+c1)&BN_MASK2; + *p=ln; + + /* The overflow will stop before we over write + * words we should not overwrite */ + if (ln < c1) + { + do { + p++; + lo= *p; + ln=(lo+1)&BN_MASK2; + *p=ln; + } while (ln == 0); + } + } + } + +/* r is 2*n words in size, + * a and b are both n words in size. + * n must be a power of 2. + * We multiply and return the result. + * t must be 2*n words in size + * We calulate + * a[0]*b[0] + * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0]) + * a[1]*b[1] + */ +void bn_sqr_recursive(BN_ULONG *r, BN_ULONG *a, int n2, BN_ULONG *t) + { + int n=n2/2; + int zero,c1; + BN_ULONG ln,lo,*p; + +#ifdef BN_COUNT +printf(" bn_sqr_recursive %d * %d\n",n2,n2); +#endif + if (n2 == 4) + { + bn_sqr_comba4(r,a); + return; + } + else if (n2 == 8) + { + bn_sqr_comba8(r,a); + return; + } + if (n2 < BN_SQR_RECURSIVE_SIZE_NORMAL) + { + bn_sqr_normal(r,a,n2,t); + return; + abort(); + } + /* r=(a[0]-a[1])*(a[1]-a[0]) */ + c1=bn_cmp_words(a,&(a[n]),n); + zero=0; + if (c1 > 0) + bn_sub_words(t,a,&(a[n]),n); + else if (c1 < 0) + bn_sub_words(t,&(a[n]),a,n); + else + zero=1; + + /* The result will always be negative unless it is zero */ + + if (n == 8) + { + if (!zero) + bn_sqr_comba8(&(t[n2]),t); + else + memset(&(t[n2]),0,8*sizeof(BN_ULONG)); + + bn_sqr_comba8(r,a); + bn_sqr_comba8(&(r[n2]),&(a[n])); + } + else + { + p= &(t[n2*2]); + if (!zero) + bn_sqr_recursive(&(t[n2]),t,n,p); + else + memset(&(t[n2]),0,n*sizeof(BN_ULONG)); + bn_sqr_recursive(r,a,n,p); + bn_sqr_recursive(&(r[n2]),&(a[n]),n,p); + } + + /* t[32] holds (a[0]-a[1])*(a[1]-a[0]), it is negative or zero + * r[10] holds (a[0]*b[0]) + * r[32] holds (b[1]*b[1]) + */ + + c1=bn_add_words(t,r,&(r[n2]),n2); + + /* t[32] is negative */ + c1-=bn_sub_words(&(t[n2]),t,&(t[n2]),n2); + + /* t[32] holds (a[0]-a[1])*(a[1]-a[0])+(a[0]*a[0])+(a[1]*a[1]) + * r[10] holds (a[0]*a[0]) + * r[32] holds (a[1]*a[1]) + * c1 holds the carry bits + */ + c1+=bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2); + if (c1) + { + p= &(r[n+n2]); + lo= *p; + ln=(lo+c1)&BN_MASK2; + *p=ln; + + /* The overflow will stop before we over write + * words we should not overwrite */ + if (ln < c1) + { + do { + p++; + lo= *p; + ln=(lo+1)&BN_MASK2; + *p=ln; + } while (ln == 0); + } + } + } + +#if 1 +/* a and b must be the same size, which is n2. + * r needs to be n2 words and t needs to be n2*2 + */ +void bn_mul_low_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2, + BN_ULONG *t) + { + int n=n2/2; + +#ifdef BN_COUNT +printf(" bn_mul_low_recursive %d * %d\n",n2,n2); +#endif + + bn_mul_recursive(r,a,b,n,&(t[0])); + if (n > BN_MUL_LOW_RECURSIVE_SIZE_NORMAL) + { + bn_mul_low_recursive(&(t[0]),&(a[0]),&(b[n]),n,&(t[n2])); + bn_add_words(&(r[n]),&(r[n]),&(t[0]),n); + bn_mul_low_recursive(&(t[0]),&(a[n]),&(b[0]),n,&(t[n2])); + bn_add_words(&(r[n]),&(r[n]),&(t[0]),n); + } + else + { + bn_mul_low_normal(&(t[0]),&(a[0]),&(b[n]),n); + bn_mul_low_normal(&(t[n]),&(a[n]),&(b[0]),n); + bn_add_words(&(r[n]),&(r[n]),&(t[0]),n); + bn_add_words(&(r[n]),&(r[n]),&(t[n]),n); + } + } + +/* a and b must be the same size, which is n2. + * r needs to be n2 words and t needs to be n2*2 + * l is the low words of the output. + * t needs to be n2*3 + */ +void bn_mul_high(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, BN_ULONG *l, int n2, + BN_ULONG *t) + { + int j,i,n,c1,c2; + int neg,oneg,zero; + BN_ULONG ll,lc,*lp,*mp; + +#ifdef BN_COUNT +printf(" bn_mul_high %d * %d\n",n2,n2); +#endif + n=(n2+1)/2; + + /* Calculate (al-ah)*(bh-bl) */ + neg=zero=0; + c1=bn_cmp_words(&(a[0]),&(a[n]),n); + c2=bn_cmp_words(&(b[n]),&(b[0]),n); + switch (c1*3+c2) + { + case -4: + bn_sub_words(&(r[0]),&(a[n]),&(a[0]),n); + bn_sub_words(&(r[n]),&(b[0]),&(b[n]),n); + break; + case -3: + zero=1; + break; + case -2: + bn_sub_words(&(r[0]),&(a[n]),&(a[0]),n); + bn_sub_words(&(r[n]),&(b[n]),&(b[0]),n); + neg=1; + break; + case -1: + case 0: + case 1: + zero=1; + break; + case 2: + bn_sub_words(&(r[0]),&(a[0]),&(a[n]),n); + bn_sub_words(&(r[n]),&(b[0]),&(b[n]),n); + neg=1; + break; + case 3: + zero=1; + break; + case 4: + bn_sub_words(&(r[0]),&(a[0]),&(a[n]),n); + bn_sub_words(&(r[n]),&(b[n]),&(b[0]),n); + break; + } + + oneg=neg; + /* t[10] = (a[0]-a[1])*(b[1]-b[0]) */ + bn_mul_recursive(&(t[0]),&(r[0]),&(r[n]),n,&(t[n2])); + /* r[10] = (a[1]*b[1]) */ + bn_mul_recursive(r,&(a[n]),&(b[n]),n,&(t[n2])); + + /* s0 == low(al*bl) + * s1 == low(ah*bh)+low((al-ah)*(bh-bl))+low(al*bl)+high(al*bl) + * We know s0 and s1 so the only unknown is high(al*bl) + * high(al*bl) == s1 - low(ah*bh+s0+(al-ah)*(bh-bl)) + * high(al*bl) == s1 - (r[0]+l[0]+t[0]) + */ + if (l != NULL) + { + lp= &(t[n2+n]); + c1=bn_add_words(lp,&(r[0]),&(l[0]),n); + } + else + { + c1=0; + lp= &(r[0]); + } + + if (neg) + neg=bn_sub_words(&(t[n2]),lp,&(t[0]),n); + else + { + bn_add_words(&(t[n2]),lp,&(t[0]),n); + neg=0; + } + + if (l != NULL) + { + bn_sub_words(&(t[n2+n]),&(l[n]),&(t[n2]),n); + } + else + { + lp= &(t[n2+n]); + mp= &(t[n2]); + for (i=0; i<n; i++) + lp[i]=((~mp[i])+1)&BN_MASK2; + } + + /* s[0] = low(al*bl) + * t[3] = high(al*bl) + * t[10] = (a[0]-a[1])*(b[1]-b[0]) neg is the sign + * r[10] = (a[1]*b[1]) + */ + /* R[10] = al*bl + * R[21] = al*bl + ah*bh + (a[0]-a[1])*(b[1]-b[0]) + * R[32] = ah*bh + */ + /* R[1]=t[3]+l[0]+r[0](+-)t[0] (have carry/borrow) + * R[2]=r[0]+t[3]+r[1](+-)t[1] (have carry/borrow) + * R[3]=r[1]+(carry/borrow) + */ + if (l != NULL) + { + lp= &(t[n2]); + c1= bn_add_words(lp,&(t[n2+n]),&(l[0]),n); + } + else + { + lp= &(t[n2+n]); + c1=0; + } + c1+=bn_add_words(&(t[n2]),lp, &(r[0]),n); + if (oneg) + c1-=bn_sub_words(&(t[n2]),&(t[n2]),&(t[0]),n); + else + c1+=bn_add_words(&(t[n2]),&(t[n2]),&(t[0]),n); + + c2 =bn_add_words(&(r[0]),&(r[0]),&(t[n2+n]),n); + c2+=bn_add_words(&(r[0]),&(r[0]),&(r[n]),n); + if (oneg) + c2-=bn_sub_words(&(r[0]),&(r[0]),&(t[n]),n); + else + c2+=bn_add_words(&(r[0]),&(r[0]),&(t[n]),n); + + if (c1 != 0) /* Add starting at r[0], could be +ve or -ve */ + { + i=0; + if (c1 > 0) + { + lc=c1; + do { + ll=(r[i]+lc)&BN_MASK2; + r[i++]=ll; + lc=(lc > ll); + } while (lc); + } + else + { + lc= -c1; + do { + ll=r[i]; + r[i++]=(ll-lc)&BN_MASK2; + lc=(lc > ll); + } while (lc); + } + } + if (c2 != 0) /* Add starting at r[1] */ + { + i=n; + if (c2 > 0) + { + lc=c2; + do { + ll=(r[i]+lc)&BN_MASK2; + r[i++]=ll; + lc=(lc > ll); + } while (lc); + } + else + { + lc= -c2; + do { + ll=r[i]; + r[i++]=(ll-lc)&BN_MASK2; + lc=(lc > ll); + } while (lc); + } + } + } +#endif diff --git a/lib/libssl/src/crypto/bn/old/bn_low.c b/lib/libssl/src/crypto/bn/old/bn_low.c new file mode 100644 index 00000000000..cbc406751c0 --- /dev/null +++ b/lib/libssl/src/crypto/bn/old/bn_low.c @@ -0,0 +1,194 @@ +/* crypto/bn/bn_mul.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include <stdio.h> +#include "cryptlib.h" +#include "bn_lcl.h" + +static int bn_mm_low(BIGNUM *m,BIGNUM *A,BIGNUM *B, int num, + BIGNUM *sk,BN_CTX *ctx); +int BN_mul_low(BIGNUM *r, BIGNUM *a, BIGNUM *b,int words); + +/* r must be different to a and b */ +int BN_mul_low(BIGNUM *r, BIGNUM *a, BIGNUM *b, int num) + { + BN_ULONG *ap,*bp,*rp; + BIGNUM *sk; + int j,i,n,ret; + int max,al,bl; + BN_CTX ctx; + + bn_check_top(a); + bn_check_top(b); + +#ifdef BN_MUL_DEBUG +printf("BN_mul_low(%d,%d,%d)\n",a->top,b->top,num); +#endif + + al=a->top; + bl=b->top; + if ((al == 0) || (bl == 0)) + { + r->top=0; + return(1); + } + + if ((bn_limit_bits_low > 0) && (num > bn_limit_num_low)) + { + n=BN_num_bits_word(num*2)-bn_limit_bits_low; + n*=2; + sk=(BIGNUM *)Malloc(sizeof(BIGNUM)*n); + memset(sk,0,sizeof(BIGNUM)*n); + memset(&ctx,0,sizeof(ctx)); + + ret=bn_mm_low(r,a,b,num,&(sk[0]),&ctx); + for (i=0; i<n; i+=2) + { + BN_clear_free(&sk[i]); + BN_clear_free(&sk[i+1]); + } + Free(sk); + return(ret); + } + + max=(al+bl); + if (bn_wexpand(r,max) == NULL) return(0); + r->neg=a->neg^b->neg; + ap=a->d; + bp=b->d; + rp=r->d; + r->top=(max > num)?num:max; + + rp[al]=bn_mul_words(rp,ap,al,*(bp++)); + rp++; + j=bl; + for (i=1; i<j; i++) + { + if (al >= num--) + { + al--; + if (al <= 0) break; + } + rp[al]=bn_mul_add_words(rp,ap,al,*(bp++)); + rp++; + } + + while ((r->top > 0) && (r->d[r->top-1] == 0)) + r->top--; + return(1); + } + + +#define t1 (sk[0]) +#define t2 (sk[1]) + +/* r must be different to a and b */ +int bn_mm_low(BIGNUM *m, BIGNUM *A, BIGNUM *B, int num, BIGNUM *sk, + BN_CTX *ctx) + { + int n; /* ,sqr=0; */ + int an,bn; + BIGNUM ah,al,bh,bl; + + bn_wexpand(m,num+3); + an=A->top; + bn=B->top; + +#ifdef BN_MUL_DEBUG +printf("bn_mm_low(%d,%d,%d)\n",A->top,B->top,num); +#endif + + n=(num+1)/2; + + BN_init(&ah); BN_init(&al); BN_init(&bh); BN_init(&bl); + + bn_set_low( &al,A,n); + bn_set_high(&ah,A,n); + bn_set_low( &bl,B,n); + bn_set_high(&bh,B,n); + + if (num <= (bn_limit_num_low+bn_limit_num_low)) + { + BN_mul(m,&al,&bl); + BN_mul_low(&t1,&al,&bh,n); + BN_mul_low(&t2,&ah,&bl,n); + } + else + { + bn_mm(m ,&al,&bl,&(sk[2]),ctx); + bn_mm_low(&t1,&al,&bh,n,&(sk[2]),ctx); + bn_mm_low(&t2,&ah,&bl,n,&(sk[2]),ctx); + } + + BN_add(&t1,&t1,&t2); + + /* We will now do an evil hack instead of + * BN_lshift(&t1,&t1,n*BN_BITS2); + * BN_add(m,m,&t1); + * BN_mask_bits(m,num*BN_BITS2); + */ + bn_set_high(&ah,m,n); ah.max=num+2; + BN_add(&ah,&ah,&t1); + m->top=num; + + m->neg=A->neg^B->neg; + return(1); + } + +#undef t1 (sk[0]) +#undef t2 (sk[1]) diff --git a/lib/libssl/src/crypto/bn/old/bn_m.c b/lib/libssl/src/crypto/bn/old/bn_m.c new file mode 100644 index 00000000000..522beb02bca --- /dev/null +++ b/lib/libssl/src/crypto/bn/old/bn_m.c @@ -0,0 +1,139 @@ +/* crypto/bn/bn_m.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include <stdio.h> +/*#include "cryptlib.h"*/ +#include "bn_lcl.h" + +#define limit_bits 5 /* 2^5, or 32 words */ +#define limit_num (1<<limit_bits) + +int BN_m(BIGNUM *r, BIGNUM *a, BIGNUM *b) + { + BIGNUM *sk; + int i,n; + + n=(BN_num_bits_word(a->top|b->top)-limit_bits); + n*=2; + sk=(BIGNUM *)malloc(sizeof(BIGNUM)*n); + for (i=0; i<n; i++) + BN_init(&(sk[i])); + + return(BN_mm(r,a,b,&(sk[0]))); + } + +#define ahal (sk[0]) +#define blbh (sk[1]) + +/* r must be different to a and b */ +int BN_mm(BIGNUM *m, BIGNUM *A, BIGNUM *B, BIGNUM *sk) + { + int i,num,anum,bnum; + int an,bn; + BIGNUM ah,al,bh,bl; + + an=A->top; + bn=B->top; + if ((an <= limit_num) || (bn <= limit_num)) + { + return(BN_mul(m,A,B)); + } + + anum=(an>bn)?an:bn; + num=(anum)/2; + + /* Are going to now chop things into 'num' word chunks. */ + bnum=num*BN_BITS2; + + BN_init(&ahal); + BN_init(&blbh); + BN_init(&ah); + BN_init(&al); + BN_init(&bh); + BN_init(&bl); + + al.top=num; + al.d=A->d; + ah.top=A->top-num; + ah.d= &(A->d[num]); + + bl.top=num; + bl.d=B->d; + bh.top=B->top-num; + bh.d= &(B->d[num]); + + BN_sub(&ahal,&ah,&al); + BN_sub(&blbh,&bl,&bh); + + BN_mm(m,&ahal,&blbh,&(sk[2])); + BN_mm(&ahal,&al,&bl,&(sk[2])); + BN_mm(&blbh,&ah,&bh,&(sk[2])); + + BN_add(m,m,&ahal); + BN_add(m,m,&blbh); + + BN_lshift(m,m,bnum); + BN_add(m,m,&ahal); + + BN_lshift(&blbh,&blbh,bnum*2); + BN_add(m,m,&blbh); + + m->neg=A->neg^B->neg; + return(1); + } + diff --git a/lib/libssl/src/crypto/bn/old/bn_mul.c.works b/lib/libssl/src/crypto/bn/old/bn_mul.c.works new file mode 100644 index 00000000000..6d565d44a27 --- /dev/null +++ b/lib/libssl/src/crypto/bn/old/bn_mul.c.works @@ -0,0 +1,219 @@ +/* crypto/bn/bn_mul.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include <stdio.h> +#include "cryptlib.h" +#include "bn_lcl.h" + +int bn_mm(BIGNUM *m,BIGNUM *A,BIGNUM *B, BIGNUM *sk,BN_CTX *ctx); + +/* r must be different to a and b */ +int BN_mul(r, a, b) +BIGNUM *r; +BIGNUM *a; +BIGNUM *b; + { + BN_ULONG *ap,*bp,*rp; + BIGNUM *sk; + int i,n,ret; + int max,al,bl; + BN_CTX ctx; + + bn_check_top(a); + bn_check_top(b); + + al=a->top; + bl=b->top; + if ((al == 0) || (bl == 0)) + { + r->top=0; + return(1); + } +#ifdef BN_MUL_DEBUG +printf("BN_mul(%d,%d)\n",a->top,b->top); +#endif + +#ifdef BN_RECURSION + if ( (bn_limit_bits > 0) && + (bl > bn_limit_num) && (al > bn_limit_num)) + { + n=(BN_num_bits_word(al|bl)-bn_limit_bits); + n*=2; + sk=(BIGNUM *)Malloc(sizeof(BIGNUM)*n); + memset(sk,0,sizeof(BIGNUM)*n); + memset(&ctx,0,sizeof(ctx)); + + ret=bn_mm(r,a,b,&(sk[0]),&ctx); + for (i=0; i<n; i+=2) + { + BN_clear_free(&sk[i]); + BN_clear_free(&sk[i+1]); + } + Free(sk); + return(ret); + } +#endif + + max=(al+bl); + if (bn_wexpand(r,max) == NULL) return(0); + r->top=max; + r->neg=a->neg^b->neg; + ap=a->d; + bp=b->d; + rp=r->d; + +#ifdef BN_RECURSION + if ((al == bl) && (al == 8)) + { + bn_mul_comba8(rp,ap,bp); + } + else +#endif + { + rp[al]=bn_mul_words(rp,ap,al,*(bp++)); + rp++; + for (i=1; i<bl; i++) + { + rp[al]=bn_mul_add_words(rp,ap,al,*(bp++)); + rp++; + } + } + if ((max > 0) && (r->d[max-1] == 0)) r->top--; + return(1); + } + +#ifdef BN_RECURSION + +#define ahal (sk[0]) +#define blbh (sk[1]) + +/* r must be different to a and b */ +int bn_mm(m, A, B, sk,ctx) +BIGNUM *m,*A,*B; +BIGNUM *sk; +BN_CTX *ctx; + { + int n,num,sqr=0; + int an,bn; + BIGNUM ah,al,bh,bl; + + an=A->top; + bn=B->top; +#ifdef BN_MUL_DEBUG +printf("bn_mm(%d,%d)\n",A->top,B->top); +#endif + + if (A == B) sqr=1; + num=(an>bn)?an:bn; + n=(num+1)/2; + /* Are going to now chop things into 'num' word chunks. */ + + BN_init(&ah); + BN_init(&al); + BN_init(&bh); + BN_init(&bl); + + bn_set_low (&al,A,n); + bn_set_high(&ah,A,n); + bn_set_low (&bl,B,n); + bn_set_high(&bh,B,n); + + BN_sub(&ahal,&ah,&al); + BN_sub(&blbh,&bl,&bh); + + if (num <= (bn_limit_num+bn_limit_num)) + { + BN_mul(m,&ahal,&blbh); + if (sqr) + { + BN_sqr(&ahal,&al,ctx); + BN_sqr(&blbh,&ah,ctx); + } + else + { + BN_mul(&ahal,&al,&bl); + BN_mul(&blbh,&ah,&bh); + } + } + else + { + bn_mm(m,&ahal,&blbh,&(sk[2]),ctx); + bn_mm(&ahal,&al,&bl,&(sk[2]),ctx); + bn_mm(&blbh,&ah,&bh,&(sk[2]),ctx); + } + + BN_add(m,m,&ahal); + BN_add(m,m,&blbh); + + BN_lshift(m,m,n*BN_BITS2); + BN_lshift(&blbh,&blbh,n*BN_BITS2*2); + + BN_add(m,m,&ahal); + BN_add(m,m,&blbh); + + m->neg=A->neg^B->neg; + return(1); + } +#undef ahal (sk[0]) +#undef blbh (sk[1]) + +#include "bn_low.c" +#include "bn_high.c" +#include "f.c" + +#endif diff --git a/lib/libssl/src/crypto/bn/old/bn_wmul.c b/lib/libssl/src/crypto/bn/old/bn_wmul.c new file mode 100644 index 00000000000..a467b2f17aa --- /dev/null +++ b/lib/libssl/src/crypto/bn/old/bn_wmul.c @@ -0,0 +1,173 @@ +#include <stdio.h> +#include "bn_lcl.h" + +#if 1 + +int bn_mull(BIGNUM *r,BIGNUM *a,BIGNUM *b, BN_CTX *ctx); + +int bn_mull(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx) + { + int top,i,j,k,al,bl; + BIGNUM *t; + +#ifdef BN_COUNT +printf("bn_mull %d * %d\n",a->top,b->top); +#endif + + bn_check_top(a); + bn_check_top(b); + bn_check_top(r); + + al=a->top; + bl=b->top; + r->neg=a->neg^b->neg; + + top=al+bl; + if ((al < 4) || (bl < 4)) + { + if (bn_wexpand(r,top) == NULL) return(0); + r->top=top; + bn_mul_normal(r->d,a->d,al,b->d,bl); + goto end; + } + else if (al == bl) /* A good start, they are the same size */ + goto symetric; + else + { + i=(al-bl); + if ((i == 1) && !BN_get_flags(b,BN_FLG_STATIC_DATA)) + { + bn_wexpand(b,al); + b->d[bl]=0; + bl++; + goto symetric; + } + else if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA)) + { + bn_wexpand(a,bl); + a->d[al]=0; + al++; + goto symetric; + } + } + + /* asymetric and >= 4 */ + if (bn_wexpand(r,top) == NULL) return(0); + r->top=top; + bn_mul_normal(r->d,a->d,al,b->d,bl); + + if (0) + { + /* symetric and > 4 */ +symetric: + if (al == 4) + { + if (bn_wexpand(r,al*2) == NULL) return(0); + r->top=top; + bn_mul_comba4(r->d,a->d,b->d); + goto end; + } + if (al == 8) + { + if (bn_wexpand(r,al*2) == NULL) return(0); + r->top=top; + bn_mul_comba8(r->d,a->d,b->d); + goto end; + } + if (al <= BN_MULL_NORMAL_SIZE) + { + if (bn_wexpand(r,al*2) == NULL) return(0); + r->top=top; + bn_mul_normal(r->d,a->d,al,b->d,bl); + goto end; + } + /* 16 or larger */ + j=BN_num_bits_word((BN_ULONG)al); + j=1<<(j-1); + k=j+j; + t= &(ctx->bn[ctx->tos]); + if (al == j) /* exact multiple */ + { + bn_wexpand(t,k*2); + bn_wexpand(r,k*2); + bn_mul_recursive(r->d,a->d,b->d,al,t->d); + } + else + { + bn_wexpand(a,k); + bn_wexpand(b,k); + bn_wexpand(t,k*4); + bn_wexpand(r,k*4); + for (i=a->top; i<k; i++) + a->d[i]=0; + for (i=b->top; i<k; i++) + b->d[i]=0; + bn_mul_part_recursive(r->d,a->d,b->d,al-j,j,t->d); + } + r->top=top; + } +end: + bn_fix_top(r); + return(1); + } +#endif + +void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb) + { + BN_ULONG *rr; + +#ifdef BN_COUNT +printf(" bn_mul_normal %d * %d\n",na,nb); +#endif + + if (na < nb) + { + int itmp; + BN_ULONG *ltmp; + + itmp=na; na=nb; nb=itmp; + ltmp=a; a=b; b=ltmp; + + } + rr= &(r[na]); + rr[0]=bn_mul_words(r,a,na,b[0]); + + for (;;) + { + if (--nb <= 0) return; + rr[1]=bn_mul_add_words(&(r[1]),a,na,b[1]); + if (--nb <= 0) return; + rr[2]=bn_mul_add_words(&(r[2]),a,na,b[2]); + if (--nb <= 0) return; + rr[3]=bn_mul_add_words(&(r[3]),a,na,b[3]); + if (--nb <= 0) return; + rr[4]=bn_mul_add_words(&(r[4]),a,na,b[4]); + rr+=4; + r+=4; + b+=4; + } + } + +#if 1 +void bn_mul_low_normal(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n) + { +#ifdef BN_COUNT +printf(" bn_mul_low_normal %d * %d\n",n,n); +#endif + bn_mul_words(r,a,n,b[0]); + + for (;;) + { + if (--n <= 0) return; + bn_mul_add_words(&(r[1]),a,n,b[1]); + if (--n <= 0) return; + bn_mul_add_words(&(r[2]),a,n,b[2]); + if (--n <= 0) return; + bn_mul_add_words(&(r[3]),a,n,b[3]); + if (--n <= 0) return; + bn_mul_add_words(&(r[4]),a,n,b[4]); + r+=4; + b+=4; + } + } +#endif diff --git a/lib/libssl/src/crypto/bn/old/build b/lib/libssl/src/crypto/bn/old/build new file mode 100644 index 00000000000..8cd99e5f179 --- /dev/null +++ b/lib/libssl/src/crypto/bn/old/build @@ -0,0 +1,3 @@ +#!/bin/sh -x + +gcc -g -I../../include test.c -L../.. -lcrypto diff --git a/lib/libssl/src/crypto/bn/old/info b/lib/libssl/src/crypto/bn/old/info new file mode 100644 index 00000000000..5ac99c3b237 --- /dev/null +++ b/lib/libssl/src/crypto/bn/old/info @@ -0,0 +1,22 @@ +Given A1A0 * B1B0 == S3S2S1S0 + +S0= low(A0*B0) +S1= low( (A1-A0)*(B0-B1)) +low( A1*B1) +high(A0*B0) +S2= high((A1-A0)*(B0-B1)) +high(A1*B1) +low( A1*B1) +S3= high(A1*B1); + +Assume we know S1 and S0, and can calulate A1*B1 and high((A1-A0)*(B0-B1)) + +k0= S0 == low(A0*B0) +k1= S1 +k2= low( A1*B1) +k3= high(A1*B1) +k4= high((A1-A0)*(B0-B1)) + +k1= low((A1-A0)*(B0-B1)) +k2 +high(A0*B0) +S2= k4 +k3 +k2 +S3= k3 + +S1-k2= low((A1-A0)*(B0-B1)) +high(A0*B0) + +We potentially have a carry or a borrow from S1 diff --git a/lib/libssl/src/crypto/bn/old/test.works b/lib/libssl/src/crypto/bn/old/test.works new file mode 100644 index 00000000000..127c7b415d8 --- /dev/null +++ b/lib/libssl/src/crypto/bn/old/test.works @@ -0,0 +1,205 @@ +#include <stdio.h> +#include "cryptlib.h" +#include "bn_lcl.h" + +#define SIZE 128 + +#define BN_MONT_CTX_set bn_mcs +#define BN_from_montgomery bn_fm +#define BN_mod_mul_montgomery bn_mmm +#undef BN_to_montgomery +#define BN_to_montgomery(r,a,mont,ctx) bn_mmm(\ + r,a,(mont)->RR,(mont),ctx) + +main() + { + BIGNUM prime,a,b,r,A,B,R; + BN_MONT_CTX *mont; + BN_CTX *ctx; + int i; + + ctx=BN_CTX_new(); + BN_init(&prime); + BN_init(&a); BN_init(&b); BN_init(&r); + BN_init(&A); BN_init(&B); BN_init(&R); + + BN_generate_prime(&prime,SIZE,0,NULL,NULL,NULL,NULL); + BN_rand(&A,SIZE,1,0); + BN_rand(&B,SIZE,1,0); + BN_mod(&A,&A,&prime,ctx); + BN_mod(&B,&B,&prime,ctx); + + mont=BN_MONT_CTX_new(); + BN_MONT_CTX_set(mont,&prime,ctx); + + BN_to_montgomery(&a,&A,mont,ctx); + BN_to_montgomery(&b,&B,mont,ctx); + + BN_mul(&r,&a,&b); + BN_print_fp(stdout,&r); printf("\n"); + BN_from_montgomery(&r,&r,mont,ctx); + BN_print_fp(stdout,&r); printf("\n"); + BN_from_montgomery(&r,&r,mont,ctx); + BN_print_fp(stdout,&r); printf("\n"); + + BN_mod_mul(&R,&A,&B,&prime,ctx); + + BN_print_fp(stdout,&a); printf("\n"); + BN_print_fp(stdout,&b); printf("\n"); + BN_print_fp(stdout,&prime); printf("\n"); + BN_print_fp(stdout,&r); printf("\n\n"); + + BN_print_fp(stdout,&A); printf("\n"); + BN_print_fp(stdout,&B); printf("\n"); + BN_print_fp(stdout,&prime); printf("\n"); + BN_print_fp(stdout,&R); printf("\n\n"); + + BN_mul(&r,&a,&b); + BN_print_fp(stdout,&r); printf(" <- BA*DC\n"); + BN_copy(&A,&r); + i=SIZE/2; + BN_mask_bits(&A,i*2); +// BN_print_fp(stdout,&A); printf(" <- low(BA*DC)\n"); + bn_do_lower(&r,&a,&b,&A,i); +// BN_print_fp(stdout,&r); printf(" <- low(BA*DC)\n"); + } + +int bn_mul_low(r,a,b,low,i) +BIGNUM *r,*a,*b,*low; +int i; + { + int w; + BIGNUM Kh,Km,t1,t2,h,ah,al,bh,bl,l,m,s0,s1; + + BN_init(&Kh); BN_init(&Km); BN_init(&t1); BN_init(&t2); BN_init(&l); + BN_init(&ah); BN_init(&al); BN_init(&bh); BN_init(&bl); BN_init(&h); + BN_init(&m); BN_init(&s0); BN_init(&s1); + + BN_copy(&al,a); BN_mask_bits(&al,i); BN_rshift(&ah,a,i); + BN_copy(&bl,b); BN_mask_bits(&bl,i); BN_rshift(&bh,b,i); + + + BN_sub(&t1,&al,&ah); + BN_sub(&t2,&bh,&bl); + BN_mul(&m,&t1,&t2); + BN_mul(&h,&ah,&bh); + + BN_copy(&s0,low); BN_mask_bits(&s0,i); + BN_rshift(&s1,low,i); + + BN_add(&t1,&h,&m); + BN_add(&t1,&t1,&s0); + + BN_copy(&t2,&t1); BN_mask_bits(&t2,i); + BN_sub(&t1,&s1,&t2); + BN_lshift(&t1,&t1,i); + BN_add(&t1,&t1,&s0); + if (t1.neg) + { + BN_lshift(&t2,BN_value_one(),i*2); + BN_add(&t1,&t2,&t1); + BN_mask_bits(&t1,i*2); + } + + BN_free(&Kh); BN_free(&Km); BN_free(&t1); BN_free(&t2); + BN_free(&ah); BN_free(&al); BN_free(&bh); BN_free(&bl); + } + +int BN_mod_mul_montgomery(r,a,b,mont,ctx) +BIGNUM *r,*a,*b; +BN_MONT_CTX *mont; +BN_CTX *ctx; + { + BIGNUM *tmp; + + tmp= &(ctx->bn[ctx->tos++]); + + if (a == b) + { + if (!BN_sqr(tmp,a,ctx)) goto err; + } + else + { + if (!BN_mul(tmp,a,b)) goto err; + } + /* reduce from aRR to aR */ + if (!BN_from_montgomery(r,tmp,mont,ctx)) goto err; + ctx->tos--; + return(1); +err: + return(0); + } + +int BN_from_montgomery(r,a,mont,ctx) +BIGNUM *r; +BIGNUM *a; +BN_MONT_CTX *mont; +BN_CTX *ctx; + { + BIGNUM z1; + BIGNUM *t1,*t2; + BN_ULONG *ap,*bp,*rp; + int j,i,bl,al; + + BN_init(&z1); + t1= &(ctx->bn[ctx->tos]); + t2= &(ctx->bn[ctx->tos+1]); + + if (!BN_copy(t1,a)) goto err; + /* can cheat */ + BN_mask_bits(t1,mont->ri); + if (!BN_mul(t2,t1,mont->Ni)) goto err; + BN_mask_bits(t2,mont->ri); + + if (!BN_mul(t1,t2,mont->N)) goto err; + if (!BN_add(t2,t1,a)) goto err; + + /* At this point, t2 has the bottom ri bits set to zero. + * This means that the bottom ri bits == the 1^ri minus the bottom + * ri bits of a. + * This means that only the bits above 'ri' in a need to be added, + * and XXXXXXXXXXXXXXXXXXXXXXXX + */ +BN_print_fp(stdout,t2); printf("\n"); + BN_rshift(r,t2,mont->ri); + + if (BN_ucmp(r,mont->N) >= 0) + bn_qsub(r,r,mont->N); + + return(1); +err: + return(0); + } + +int BN_MONT_CTX_set(mont,mod,ctx) +BN_MONT_CTX *mont; +BIGNUM *mod; +BN_CTX *ctx; + { + BIGNUM *Ri=NULL,*R=NULL; + + if (mont->RR == NULL) mont->RR=BN_new(); + if (mont->N == NULL) mont->N=BN_new(); + + R=mont->RR; /* grab RR as a temp */ + BN_copy(mont->N,mod); /* Set N */ + + mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2; + BN_lshift(R,BN_value_one(),mont->ri); /* R */ + if ((Ri=BN_mod_inverse(NULL,R,mod,ctx)) == NULL) goto err;/* Ri */ + BN_lshift(Ri,Ri,mont->ri); /* R*Ri */ + bn_qsub(Ri,Ri,BN_value_one()); /* R*Ri - 1 */ + BN_div(Ri,NULL,Ri,mod,ctx); + if (mont->Ni != NULL) BN_free(mont->Ni); + mont->Ni=Ri; /* Ni=(R*Ri-1)/N */ + + /* setup RR for conversions */ + BN_lshift(mont->RR,BN_value_one(),mont->ri*2); + BN_mod(mont->RR,mont->RR,mont->N,ctx); + + return(1); +err: + return(0); + } + + diff --git a/lib/libssl/src/crypto/pkcs12/p12_bags.c b/lib/libssl/src/crypto/pkcs12/p12_bags.c new file mode 100644 index 00000000000..d6eab92c833 --- /dev/null +++ b/lib/libssl/src/crypto/pkcs12/p12_bags.c @@ -0,0 +1,192 @@ +/* p12_bags.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include <stdio.h> +#include "cryptlib.h" +#include <openssl/asn1_mac.h> +#include <openssl/pkcs12.h> + +int i2d_PKCS12_BAGS(PKCS12_BAGS *a, unsigned char **pp) +{ + int bagnid, v = 0; + M_ASN1_I2D_vars(a); + bagnid = OBJ_obj2nid (a->type); + M_ASN1_I2D_len (a->type, i2d_ASN1_OBJECT); + + switch (bagnid) { + + case NID_x509Certificate: + M_ASN1_I2D_len_EXP_opt (a->value.x509cert, + i2d_ASN1_OCTET_STRING, 0, v); + break; + + case NID_x509Crl: + M_ASN1_I2D_len_EXP_opt (a->value.x509crl, + i2d_ASN1_OCTET_STRING, 0, v); + break; + + case NID_sdsiCertificate: + M_ASN1_I2D_len_EXP_opt (a->value.sdsicert, + i2d_ASN1_IA5STRING, 0, v); + break; + + default: + M_ASN1_I2D_len_EXP_opt (a->value.other, + i2d_ASN1_TYPE, 0, v); + break; + } + + M_ASN1_I2D_seq_total (); + + M_ASN1_I2D_put (a->type, i2d_ASN1_OBJECT); + + switch (bagnid) { + + case NID_x509Certificate: + M_ASN1_I2D_put_EXP_opt (a->value.x509cert, + i2d_ASN1_OCTET_STRING, 0, v); + break; + + case NID_x509Crl: + M_ASN1_I2D_put_EXP_opt (a->value.x509crl, + i2d_ASN1_OCTET_STRING, 0, v); + break; + + case NID_sdsiCertificate: + M_ASN1_I2D_put_EXP_opt (a->value.sdsicert, + i2d_ASN1_IA5STRING, 0, v); + break; + + default: + M_ASN1_I2D_put_EXP_opt (a->value.other, i2d_ASN1_TYPE, 0, v); + break; + } + M_ASN1_I2D_finish(); +} + +PKCS12_BAGS *PKCS12_BAGS_new(void) +{ + PKCS12_BAGS *ret=NULL; + ASN1_CTX c; + M_ASN1_New_Malloc(ret, PKCS12_BAGS); + ret->type=NULL; + ret->value.other=NULL; + return (ret); + M_ASN1_New_Error(ASN1_F_PKCS12_BAGS_NEW); +} + +PKCS12_BAGS *d2i_PKCS12_BAGS(PKCS12_BAGS **a, unsigned char **pp, + long length) +{ + int bagnid; + M_ASN1_D2I_vars(a,PKCS12_BAGS *,PKCS12_BAGS_new); + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get (ret->type, d2i_ASN1_OBJECT); + bagnid = OBJ_obj2nid (ret->type); + switch (bagnid) { + + case NID_x509Certificate: + M_ASN1_D2I_get_EXP_opt (ret->value.x509cert, + d2i_ASN1_OCTET_STRING, 0); + break; + + case NID_x509Crl: + M_ASN1_D2I_get_EXP_opt (ret->value.x509crl, + d2i_ASN1_OCTET_STRING, 0); + break; + + case NID_sdsiCertificate: + M_ASN1_D2I_get_EXP_opt (ret->value.sdsicert, + d2i_ASN1_IA5STRING, 0); + break; + + default: + M_ASN1_D2I_get_EXP_opt (ret->value.other, + d2i_ASN1_TYPE, 0); + break; + } + + M_ASN1_D2I_Finish(a, PKCS12_BAGS_free, ASN1_F_D2I_PKCS12_BAGS); +} + +void PKCS12_BAGS_free (PKCS12_BAGS *a) +{ + if (a == NULL) return; + switch (OBJ_obj2nid(a->type)) { + + case NID_x509Certificate: + ASN1_OCTET_STRING_free (a->value.x509cert); + break; + + case NID_x509Crl: + ASN1_OCTET_STRING_free (a->value.x509crl); + break; + + case NID_sdsiCertificate: + ASN1_IA5STRING_free (a->value.sdsicert); + break; + + default: + ASN1_TYPE_free (a->value.other); + break; + } + + ASN1_OBJECT_free (a->type); + Free ((char *)a); +} diff --git a/lib/libssl/src/crypto/pkcs12/p12_lib.c b/lib/libssl/src/crypto/pkcs12/p12_lib.c new file mode 100644 index 00000000000..00a6695d9b7 --- /dev/null +++ b/lib/libssl/src/crypto/pkcs12/p12_lib.c @@ -0,0 +1,111 @@ +/* p12_lib.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include <stdio.h> +#include "cryptlib.h" +#include <openssl/asn1_mac.h> +#include <openssl/pkcs12.h> + +int i2d_PKCS12(PKCS12 *a, unsigned char **pp) +{ + M_ASN1_I2D_vars(a); + + M_ASN1_I2D_len (a->version, i2d_ASN1_INTEGER); + M_ASN1_I2D_len (a->authsafes, i2d_PKCS7); + M_ASN1_I2D_len (a->mac, i2d_PKCS12_MAC_DATA); + + M_ASN1_I2D_seq_total(); + + M_ASN1_I2D_put (a->version, i2d_ASN1_INTEGER); + M_ASN1_I2D_put (a->authsafes, i2d_PKCS7); + M_ASN1_I2D_put (a->mac, i2d_PKCS12_MAC_DATA); + + M_ASN1_I2D_finish(); +} + +PKCS12 *d2i_PKCS12(PKCS12 **a, unsigned char **pp, long length) +{ + M_ASN1_D2I_vars(a,PKCS12 *,PKCS12_new); + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get (ret->version, d2i_ASN1_INTEGER); + M_ASN1_D2I_get (ret->authsafes, d2i_PKCS7); + M_ASN1_D2I_get_opt (ret->mac, d2i_PKCS12_MAC_DATA, V_ASN1_SEQUENCE); + M_ASN1_D2I_Finish(a, PKCS12_free, ASN1_F_D2I_PKCS12); +} + +PKCS12 *PKCS12_new(void) +{ + PKCS12 *ret=NULL; + ASN1_CTX c; + M_ASN1_New_Malloc(ret, PKCS12); + ret->version=NULL; + ret->mac=NULL; + ret->authsafes=NULL; + return (ret); + M_ASN1_New_Error(ASN1_F_PKCS12_NEW); +} + +void PKCS12_free (PKCS12 *a) +{ + if (a == NULL) return; + ASN1_INTEGER_free (a->version); + PKCS12_MAC_DATA_free (a->mac); + PKCS7_free (a->authsafes); + Free ((char *)a); +} diff --git a/lib/libssl/src/crypto/pkcs12/p12_mac.c b/lib/libssl/src/crypto/pkcs12/p12_mac.c new file mode 100644 index 00000000000..f163d4cfaa8 --- /dev/null +++ b/lib/libssl/src/crypto/pkcs12/p12_mac.c @@ -0,0 +1,110 @@ +/* p12_mac.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include <stdio.h> +#include "cryptlib.h" +#include <openssl/asn1_mac.h> +#include <openssl/pkcs12.h> + +int i2d_PKCS12_MAC_DATA(PKCS12_MAC_DATA *a, unsigned char **pp) +{ + M_ASN1_I2D_vars(a); + M_ASN1_I2D_len (a->dinfo, i2d_X509_SIG); + M_ASN1_I2D_len (a->salt, i2d_ASN1_OCTET_STRING); + M_ASN1_I2D_len (a->iter, i2d_ASN1_INTEGER); + + M_ASN1_I2D_seq_total(); + + M_ASN1_I2D_put (a->dinfo, i2d_X509_SIG); + M_ASN1_I2D_put (a->salt, i2d_ASN1_OCTET_STRING); + M_ASN1_I2D_put (a->iter, i2d_ASN1_INTEGER); + M_ASN1_I2D_finish(); +} + +PKCS12_MAC_DATA *PKCS12_MAC_DATA_new(void) +{ + PKCS12_MAC_DATA *ret=NULL; + ASN1_CTX c; + M_ASN1_New_Malloc(ret, PKCS12_MAC_DATA); + ret->dinfo = X509_SIG_new(); + ret->salt = ASN1_OCTET_STRING_new(); + ret->iter = NULL; + return (ret); + M_ASN1_New_Error(ASN1_F_PKCS12_MAC_DATA_NEW); +} + +PKCS12_MAC_DATA *d2i_PKCS12_MAC_DATA(PKCS12_MAC_DATA **a, unsigned char **pp, + long length) +{ + M_ASN1_D2I_vars(a,PKCS12_MAC_DATA *,PKCS12_MAC_DATA_new); + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get (ret->dinfo, d2i_X509_SIG); + M_ASN1_D2I_get (ret->salt, d2i_ASN1_OCTET_STRING); + M_ASN1_D2I_get_opt (ret->iter, d2i_ASN1_INTEGER, V_ASN1_INTEGER); + M_ASN1_D2I_Finish(a, PKCS12_MAC_DATA_free, ASN1_F_D2I_PKCS12_MAC_DATA); +} + +void PKCS12_MAC_DATA_free (PKCS12_MAC_DATA *a) +{ + if (a == NULL) return; + X509_SIG_free (a->dinfo); + ASN1_OCTET_STRING_free (a->salt); + ASN1_INTEGER_free (a->iter); + Free ((char *)a); +} diff --git a/lib/libssl/src/crypto/pkcs12/p12_sbag.c b/lib/libssl/src/crypto/pkcs12/p12_sbag.c new file mode 100644 index 00000000000..1b3addece19 --- /dev/null +++ b/lib/libssl/src/crypto/pkcs12/p12_sbag.c @@ -0,0 +1,227 @@ +/* p12_sbag.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include <stdio.h> +#include "cryptlib.h" +#include <openssl/asn1_mac.h> +#include <openssl/pkcs12.h> + +int i2d_PKCS12_SAFEBAG(PKCS12_SAFEBAG *a, unsigned char **pp) +{ + int bagnid, v = 0; + M_ASN1_I2D_vars(a); + bagnid = OBJ_obj2nid (a->type); + M_ASN1_I2D_len (a->type, i2d_ASN1_OBJECT); + + switch (bagnid) { + + case NID_keyBag: + M_ASN1_I2D_len_EXP_opt (a->value.keybag, + i2d_PKCS8_PRIV_KEY_INFO, 0, v); + break; + + case NID_pkcs8ShroudedKeyBag: + M_ASN1_I2D_len_EXP_opt (a->value.shkeybag, + i2d_X509_SIG, 0, v); + break; + + case NID_safeContentsBag: + M_ASN1_I2D_len_EXP_SEQUENCE_opt (a->value.safes, + i2d_PKCS12_SAFEBAG, 0, V_ASN1_SEQUENCE, v); + break; + + case NID_certBag: + case NID_crlBag: + case NID_secretBag: + M_ASN1_I2D_len_EXP_opt (a->value.bag, + i2d_PKCS12_BAGS, 0, v); + break; + + default: + M_ASN1_I2D_len_EXP_opt (a->value.other, + i2d_ASN1_TYPE, 0, v); + break; + } + + M_ASN1_I2D_len_SET_type (X509_ATTRIBUTE,a->attrib, i2d_X509_ATTRIBUTE); + + M_ASN1_I2D_seq_total (); + + M_ASN1_I2D_put (a->type, i2d_ASN1_OBJECT); + + switch (bagnid) { + + case NID_keyBag: + M_ASN1_I2D_put_EXP_opt (a->value.keybag, + i2d_PKCS8_PRIV_KEY_INFO, 0, v); + break; + + case NID_pkcs8ShroudedKeyBag: + M_ASN1_I2D_put_EXP_opt (a->value.shkeybag, + i2d_X509_SIG, 0, v); + break; + + case NID_safeContentsBag: + M_ASN1_I2D_put_EXP_SEQUENCE_opt (a->value.safes, + i2d_PKCS12_SAFEBAG, 0, V_ASN1_SEQUENCE, v); + break; + + case NID_certBag: + case NID_crlBag: + case NID_secretBag: + M_ASN1_I2D_put_EXP_opt (a->value.bag, + i2d_PKCS12_BAGS, 0, v); + break; + + default: + M_ASN1_I2D_put_EXP_opt (a->value.other, + i2d_ASN1_TYPE, 0, v); + break; + } + + M_ASN1_I2D_put_SET_type (X509_ATTRIBUTE, a->attrib, i2d_X509_ATTRIBUTE); + + M_ASN1_I2D_finish(); +} + +PKCS12_SAFEBAG *PKCS12_SAFEBAG_new(void) +{ + PKCS12_SAFEBAG *ret=NULL; + ASN1_CTX c; + M_ASN1_New_Malloc(ret, PKCS12_SAFEBAG); + ret->type=NULL; + ret->value.other=NULL; + M_ASN1_New(ret->attrib, sk_X509_ATTRIBUTE_new_null); + ret->rest=NULL; + return (ret); + M_ASN1_New_Error(ASN1_F_PKCS12_SAFEBAG_NEW); +} + +PKCS12_SAFEBAG *d2i_PKCS12_SAFEBAG(PKCS12_SAFEBAG **a, unsigned char **pp, + long length) +{ + int bagnid; + M_ASN1_D2I_vars(a,PKCS12_SAFEBAG *,PKCS12_SAFEBAG_new); + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get (ret->type, d2i_ASN1_OBJECT); + bagnid = OBJ_obj2nid (ret->type); + + switch (bagnid) { + + case NID_keyBag: + M_ASN1_D2I_get_EXP_opt (ret->value.keybag, + d2i_PKCS8_PRIV_KEY_INFO, 0); + break; + + case NID_pkcs8ShroudedKeyBag: + M_ASN1_D2I_get_EXP_opt (ret->value.shkeybag, + d2i_X509_SIG, 0); + break; + + case NID_safeContentsBag: + M_ASN1_D2I_get_EXP_set_opt(ret->value.safes, + d2i_PKCS12_SAFEBAG, PKCS12_SAFEBAG_free, + 0, V_ASN1_SEQUENCE); + break; + + case NID_certBag: + case NID_crlBag: + case NID_secretBag: + M_ASN1_D2I_get_EXP_opt (ret->value.bag, + d2i_PKCS12_BAGS, 0); + break; + + default: + M_ASN1_D2I_get_EXP_opt (ret->value.other, + d2i_ASN1_TYPE, 0); + break; + } + M_ASN1_D2I_get_set_opt_type(X509_ATTRIBUTE,ret->attrib, + d2i_X509_ATTRIBUTE,X509_ATTRIBUTE_free); + M_ASN1_D2I_Finish(a, PKCS12_SAFEBAG_free, ASN1_F_D2I_PKCS12_SAFEBAG); +} + +void PKCS12_SAFEBAG_free (PKCS12_SAFEBAG *a) +{ + if (a == NULL) return; + switch (OBJ_obj2nid(a->type)) { + + case NID_keyBag: + PKCS8_PRIV_KEY_INFO_free (a->value.keybag); + break; + + case NID_pkcs8ShroudedKeyBag: + X509_SIG_free (a->value.shkeybag); + break; + + case NID_certBag: + case NID_crlBag: + case NID_secretBag: + PKCS12_BAGS_free (a->value.bag); + break; + + default: + ASN1_TYPE_free (a->value.other); + break; + } + + ASN1_OBJECT_free (a->type); + sk_X509_ATTRIBUTE_pop_free (a->attrib, X509_ATTRIBUTE_free); + Free (a); +} diff --git a/lib/libssl/src/perl/t/01-use.t b/lib/libssl/src/perl/t/01-use.t new file mode 100644 index 00000000000..e24fd1f5045 --- /dev/null +++ b/lib/libssl/src/perl/t/01-use.t @@ -0,0 +1,13 @@ + +BEGIN { + $| = 1; + print "1..1\n"; +} +END { + print "not ok 1\n" unless $loaded; +} +use OpenSSL; +$loaded = 1; +print "ok 1\n"; + + diff --git a/lib/libssl/src/perl/t/02-version.t b/lib/libssl/src/perl/t/02-version.t new file mode 100644 index 00000000000..8b5f6a0c977 --- /dev/null +++ b/lib/libssl/src/perl/t/02-version.t @@ -0,0 +1,10 @@ + +print "1..1\n"; +use OpenSSL; +if ($OpenSSL::VERSION ne '') { + print "ok 1\n"; +} +else { + print "not ok 1\n"; +} + diff --git a/lib/libssl/src/perl/t/03-bio.t b/lib/libssl/src/perl/t/03-bio.t new file mode 100644 index 00000000000..e3ed7ed842e --- /dev/null +++ b/lib/libssl/src/perl/t/03-bio.t @@ -0,0 +1,16 @@ + +BEGIN { + $| = 1; + print "1..1\n"; +} +END { + print "not ok 1\n" unless $ok; +} + +use OpenSSL; +my $bio = OpenSSL::BIO::new("mem") || die; +undef $bio; + +$ok = 1; +print "ok 1\n"; + diff --git a/lib/libssl/src/rsaref/Makefile.ssl b/lib/libssl/src/rsaref/Makefile.ssl new file mode 100644 index 00000000000..165b2b8036f --- /dev/null +++ b/lib/libssl/src/rsaref/Makefile.ssl @@ -0,0 +1,98 @@ +# +# SSLeay/rsaref/Makefile +# + +DIR= rsaref +TOP= .. +CC= cc +INCLUDES= -I../crypto -I../include +CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl +INSTALLTOP=/usr/local/ssl +MAKE= make -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) +MAKEFILE= Makefile.ssl +AR= ar r + +CFLAGS= $(INCLUDES) $(CFLAG) + +GENERAL=Makefile rsaref-lib.com install.com +TEST= +APPS= + +LIB=$(TOP)/libRSAglue.a +LIBSRC= rsaref.c rsar_err.c +LIBOBJ= rsaref.o rsar_err.o + +SRC= $(LIBSRC) + +EXHEADER= rsaref.h +HEADER= $(EXHEADER) + +ALL= $(GENERAL) $(SRC) $(HEADER) + +top: + (cd ..; $(MAKE) DIRS=rsaref all) + +all: lib + +lib: $(LIBOBJ) + $(AR) $(LIB) $(LIBOBJ) + $(RANLIB) $(LIB) + @touch lib + +files: + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + +links: + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../apps $(APPS) + +install: + -@if [ "x`echo x $(EX_LIBS) | grep RSAglue`" != x ]; then \ + echo "installing libRSAglue.a"; \ + cp $(LIB) $(INSTALL_PREFIX)$(INSTALLTOP)/lib/libRSAglue.a; \ + $(RANLIB) $(INSTALL_PREFIX)$(INSTALLTOP)/lib/libRSAglue.a; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/lib/libRSAglue.a; \ + fi + +# @for i in $(EXHEADER) ; \ +# do \ +# (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ +# chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ +# done; + +tags: + ctags $(SRC) + +tests: + +lint: + lint -DLINT $(INCLUDES) $(SRC)>fluff + +depend: + $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + +dclean: + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + mv -f Makefile.new $(MAKEFILE) + +clean: + rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +rsar_err.o: ../include/openssl/bn.h ../include/openssl/crypto.h +rsar_err.o: ../include/openssl/err.h ../include/openssl/opensslconf.h +rsar_err.o: ../include/openssl/opensslv.h ../include/openssl/rsa.h +rsar_err.o: ../include/openssl/rsaref.h ../include/openssl/stack.h +rsaref.o: ../crypto/cryptlib.h ../include/openssl/bio.h ../include/openssl/bn.h +rsaref.o: ../include/openssl/buffer.h ../include/openssl/crypto.h +rsaref.o: ../include/openssl/e_os.h ../include/openssl/e_os2.h +rsaref.o: ../include/openssl/err.h ../include/openssl/opensslconf.h +rsaref.o: ../include/openssl/opensslv.h ../include/openssl/rand.h +rsaref.o: ../include/openssl/rsa.h ../include/openssl/rsaref.h +rsaref.o: ../include/openssl/stack.h diff --git a/lib/libssl/src/rsaref/install.com b/lib/libssl/src/rsaref/install.com new file mode 100644 index 00000000000..c32cea5da88 --- /dev/null +++ b/lib/libssl/src/rsaref/install.com @@ -0,0 +1,69 @@ +$! INSTALL.COM -- Installs the files in a given directory tree +$! +$! Author: Richard Levitte <richard@levitte.org> +$! Time of creation: 22-MAY-1998 10:13 +$! +$! P1 root of the directory tree +$! +$ IF P1 .EQS. "" +$ THEN +$ WRITE SYS$OUTPUT "First argument missing." +$ WRITE SYS$OUTPUT "Should be the directory where you want things installed." +$ EXIT +$ ENDIF +$ +$ ROOT = F$PARSE(P1,"[]A.;0",,,"SYNTAX_ONLY,NO_CONCEAL") - "A.;0" +$ ROOT_DEV = F$PARSE(ROOT,,,"DEVICE","SYNTAX_ONLY") +$ ROOT_DIR = F$PARSE(ROOT,,,"DIRECTORY","SYNTAX_ONLY") - + - "[000000." - "][" - "[" - "]" +$ ROOT = ROOT_DEV + "[" + ROOT_DIR +$ +$ DEFINE/NOLOG WRK_SSLROOT 'ROOT'.] /TRANS=CONC +$ DEFINE/NOLOG WRK_SSLVLIB WRK_SSLROOT:[VAX_LIB] +$ DEFINE/NOLOG WRK_SSLALIB WRK_SSLROOT:[ALPHA_LIB] +$ +$ IF F$PARSE("WRK_SSLROOT:[000000]") .EQS. "" THEN - + CREATE/DIR/LOG WRK_SSLROOT:[000000] +$ IF F$PARSE("WRK_SSLVLIB:") .EQS. "" THEN - + CREATE/DIR/LOG WRK_SSLVLIB: +$ IF F$PARSE("WRK_SSLALIB:") .EQS. "" THEN - + CREATE/DIR/LOG WRK_SSLALIB: +$ +$ LIBS := LIBRSAGLUE +$ +$ VEXE_DIR := [-.VAX.EXE.CRYPTO] +$ AEXE_DIR := [-.AXP.EXE.CRYPTO] +$ +$ I = 0 +$ LOOP_LIB: +$ E = F$EDIT(F$ELEMENT(I, ",", LIBS),"TRIM") +$ I = I + 1 +$ IF E .EQS. "," THEN GOTO LOOP_LIB_END +$ SET NOON +$ IF F$SEARCH(VEXE_DIR+E+".OLB") .NES. "" +$ THEN +$ COPY 'VEXE_DIR''E'.OLB WRK_SSLVLIB:'E'.OLB/log +$ SET FILE/PROT=W:RE WRK_SSLVLIB:'E'.OLB +$ ENDIF +$ ! Preparing for the time when we have shareable images +$ IF F$SEARCH(VEXE_DIR+E+".EXE") .NES. "" +$ THEN +$ COPY 'VEXE_DIR''E'.EXE WRK_SSLVLIB:'E'.EXE/log +$ SET FILE/PROT=W:RE WRK_SSLVLIB:'E'.EXE +$ ENDIF +$ IF F$SEARCH(AEXE_DIR+E+".OLB") .NES. "" +$ THEN +$ COPY 'AEXE_DIR''E'.OLB WRK_SSLALIB:'E'.OLB/log +$ SET FILE/PROT=W:RE WRK_SSLALIB:'E'.OLB +$ ENDIF +$ ! Preparing for the time when we have shareable images +$ IF F$SEARCH(AEXE_DIR+E+".EXE") .NES. "" +$ THEN +$ COPY 'AEXE_DIR''E'.EXE WRK_SSLALIB:'E'.EXE/log +$ SET FILE/PROT=W:RE WRK_SSLALIB:'E'.EXE +$ ENDIF +$ SET ON +$ GOTO LOOP_LIB +$ LOOP_LIB_END: +$ +$ EXIT diff --git a/lib/libssl/src/rsaref/rsar_err.c b/lib/libssl/src/rsaref/rsar_err.c new file mode 100644 index 00000000000..d2eb3a2b018 --- /dev/null +++ b/lib/libssl/src/rsaref/rsar_err.c @@ -0,0 +1,118 @@ +/* rsaref/rsar_err.c */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +/* NOTE: this file was auto generated by the mkerr.pl script: any changes + * made to it will be overwritten when the script next updates this file. + */ + +#include <stdio.h> +#include <openssl/err.h> +#include <openssl/rsaref.h> + +/* BEGIN ERROR CODES */ +#ifndef NO_ERR +static ERR_STRING_DATA RSAREF_str_functs[]= + { +{ERR_PACK(0,RSAREF_F_BN_REF_MOD_EXP,0), "BN_REF_MOD_EXP"}, +{ERR_PACK(0,RSAREF_F_RSAREF_BN2BIN,0), "RSAREF_BN2BIN"}, +{ERR_PACK(0,RSAREF_F_RSA_BN2BIN,0), "RSA_BN2BIN"}, +{ERR_PACK(0,RSAREF_F_RSA_PRIVATE_DECRYPT,0), "RSA_private_decrypt"}, +{ERR_PACK(0,RSAREF_F_RSA_PRIVATE_ENCRYPT,0), "RSA_private_encrypt"}, +{ERR_PACK(0,RSAREF_F_RSA_PUBLIC_DECRYPT,0), "RSA_public_decrypt"}, +{ERR_PACK(0,RSAREF_F_RSA_PUBLIC_ENCRYPT,0), "RSA_public_encrypt"}, +{ERR_PACK(0,RSAREF_F_RSA_REF_BN2BIN,0), "RSA_REF_BN2BIN"}, +{ERR_PACK(0,RSAREF_F_RSA_REF_MOD_EXP,0), "RSA_REF_MOD_EXP"}, +{ERR_PACK(0,RSAREF_F_RSA_REF_PRIVATE_DECRYPT,0), "RSA_REF_PRIVATE_DECRYPT"}, +{ERR_PACK(0,RSAREF_F_RSA_REF_PRIVATE_ENCRYPT,0), "RSA_REF_PRIVATE_ENCRYPT"}, +{ERR_PACK(0,RSAREF_F_RSA_REF_PUBLIC_DECRYPT,0), "RSA_REF_PUBLIC_DECRYPT"}, +{ERR_PACK(0,RSAREF_F_RSA_REF_PUBLIC_ENCRYPT,0), "RSA_REF_PUBLIC_ENCRYPT"}, +{0,NULL} + }; + +static ERR_STRING_DATA RSAREF_str_reasons[]= + { +{RSAREF_R_CONTENT_ENCODING ,"content encoding"}, +{RSAREF_R_DATA ,"data"}, +{RSAREF_R_DIGEST_ALGORITHM ,"digest algorithm"}, +{RSAREF_R_ENCODING ,"encoding"}, +{RSAREF_R_ENCRYPTION_ALGORITHM ,"encryption algorithm"}, +{RSAREF_R_KEY ,"key"}, +{RSAREF_R_KEY_ENCODING ,"key encoding"}, +{RSAREF_R_LEN ,"len"}, +{RSAREF_R_MODULUS_LEN ,"modulus len"}, +{RSAREF_R_NEED_RANDOM ,"need random"}, +{RSAREF_R_PRIVATE_KEY ,"private key"}, +{RSAREF_R_PUBLIC_KEY ,"public key"}, +{RSAREF_R_SIGNATURE ,"signature"}, +{RSAREF_R_SIGNATURE_ENCODING ,"signature encoding"}, +{0,NULL} + }; + +#endif + +void ERR_load_RSAREF_strings(void) + { + static int init=1; + + if (init) + { + init=0; +#ifndef NO_ERR + ERR_load_strings(ERR_LIB_RSAREF,RSAREF_str_functs); + ERR_load_strings(ERR_LIB_RSAREF,RSAREF_str_reasons); +#endif + + } + } diff --git a/lib/libssl/src/rsaref/rsaref-lib.com b/lib/libssl/src/rsaref/rsaref-lib.com new file mode 100644 index 00000000000..53193720b6f --- /dev/null +++ b/lib/libssl/src/rsaref/rsaref-lib.com @@ -0,0 +1,902 @@ +$! +$! RSAREF-LIB.COM +$! Written By: Robert Byer +$! Vice-President +$! A-Com Computing, Inc. +$! byer@mail.all-net.net +$! +$! Changes by Richard Levitte <richard@levitte.org> +$! +$! This command files compiles and creates the "[.xxx.EXE.RSAREF]LIBRSAGLUE.OLB" +$! library. The "xxx" denotes the machine architecture of AXP or VAX. +$! +$! Specify one of the following to build just that part or "ALL" to +$! just build everything. +$! +$! ALL To Just Build "Everything". +$! LIBRARY To Just Build The [.xxx.EXE.RSAREF]LIBRSAGLUE.OLB Library. +$! DHDEMO To Just Build The [.xxx.EXE.RSAREF]DHDEMO.EXE Program. +$! RDEMO To Just Build The [.xxx.EXE.RSAREF]RDEMO.EXE Program. +$! +$! Specify DEBUG or NODEBUG as P2 to compile with or without debugging +$! information. +$! +$! Specify which compiler at P3 to try to compile under. +$! +$! VAXC For VAX C. +$! DECC For DEC C. +$! GNUC For GNU C. +$! +$! If you don't speficy a compiler, it will prompt you for one. +$! +$! P4, if defined, sets a compiler thread NOT needed on OpenVMS 7.1 (and up) +$! +$! +$! Check Which Architecture We Are Using. +$! +$ IF (F$GETSYI("CPU").GE.128) +$ THEN +$! +$! The Architecture Is AXP +$! +$ ARCH := AXP +$! +$! Else... +$! +$ ELSE +$! +$! The Architecture Is VAX. +$! +$ ARCH := VAX +$! +$! End The Architecture Check. +$! +$ ENDIF +$! +$! Check To Make Sure We Have Valid Command Line Parameters. +$! +$ GOSUB CHECK_OPTIONS +$! +$! Initialise logical names and such +$! +$ GOSUB INITIALISE +$! +$! Tell The User What Kind of Machine We Run On. +$! +$ WRITE SYS$OUTPUT "Compiling On A ",ARCH," Machine." +$! +$! Define The OBJ Directory Name. +$! +$ OBJ_DIR := SYS$DISK:[-.'ARCH'.OBJ.RSAREF] +$! +$! Check To See If The Architecture Specific OBJ Directory Exists. +$! +$ IF (F$PARSE(OBJ_DIR).EQS."") +$ THEN +$! +$! It Dosen't Exist, So Create It. +$! +$ CREATE/DIR 'OBJ_DIR' +$! +$! End The Architecture Specific OBJ Directory Check. +$! +$ ENDIF +$! +$! Define The EXE Directory Name. +$! +$ EXE_DIR := SYS$DISK:[-.'ARCH'.EXE.RSAREF] +$! +$! Check To See If The Architecture Specific EXE Directory Exists. +$! +$ IF (F$PARSE(EXE_DIR).EQS."") +$ THEN +$! +$! It Dosen't Exist, So Create It. +$! +$ CREATE/DIR 'EXE_DIR' +$! +$! End The Architecture Specific EXE Directory Check. +$! +$ ENDIF +$! +$! Define The Library Name. +$! +$ LIB_NAME := 'EXE_DIR'LIBRSAGLUE.OLB +$! +$! Check To See What We Are To Do. +$! +$ IF (BUILDALL.EQS."TRUE") +$ THEN +$! +$! Since Nothing Special Was Specified, Do Everything. +$! +$ GOSUB LIBRARY +$ GOSUB DHDEMO +$ GOSUB RDEMO +$! +$! Else... +$! +$ ELSE +$! +$! Build Just What The User Wants Us To Build. +$! +$ GOSUB 'BUILDALL' +$! +$! End The BUILDALL Check. +$! +$ ENDIF +$! +$! Time To EXIT. +$! +$ EXIT: +$ GOSUB CLEANUP +$ EXIT +$! +$ LIBRARY: +$! +$! Tell The User That We Are Compiling. +$! +$ WRITE SYS$OUTPUT "Compiling The ",LIB_NAME," Files." +$! +$! Check To See If We Already Have A "LIBRSAGLUE.OLB" Library... +$! +$ IF (F$SEARCH(LIB_NAME).EQS."") +$ THEN +$! +$! Guess Not, Create The Library. +$! +$ LIBRARY/CREATE/OBJECT 'LIB_NAME' +$! +$! End The Library Exist Check. +$! +$ ENDIF +$! +$! Define The RSAREF Library Files. +$! +$ LIB_RSAREF = "DESC,DIGIT,MD2C,MD5C,NN,PRIME,RSA,R_DH,R_ENCODE,R_ENHANC," + - + "R_KEYGEN,R_RANDOM,R_STDLIB" +$! +$! Define A File Counter And Set It To "0". +$! +$ FILE_COUNTER = 0 +$! +$! Top Of The File Loop. +$! +$ NEXT_FILE: +$! +$! O.K, Extract The File Name From The File List. +$! +$ FILE_NAME = F$ELEMENT(FILE_COUNTER,",",LIB_RSAREF) +$! +$! Check To See If We Are At The End Of The File List. +$! +$ IF (FILE_NAME.EQS.",") THEN GOTO FILE_DONE +$! +$! Increment The Counter. +$! +$ FILE_COUNTER = FILE_COUNTER + 1 +$! +$! Create The Source File Name. +$! +$ SOURCE_FILE = "SYS$DISK:[.SOURCE]" + FILE_NAME + ".C" +$! +$! Tell The User We Are Compiling The Source File. +$! +$ WRITE SYS$OUTPUT " ",FILE_NAME,".C" +$! +$! Create The Object File Name. +$! +$ OBJECT_FILE = OBJ_DIR + FILE_NAME + ".OBJ" +$ ON WARNING THEN GOTO NEXT_FILE +$! +$! Check To See If The File We Want To Compile Actually Exists. +$! +$ IF (F$SEARCH(SOURCE_FILE).EQS."") +$ THEN +$! +$! Tell The User That The File Dosen't Exist. +$! +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT "The File ",SOURCE_FILE," Dosen't Exist." +$ WRITE SYS$OUTPUT "" +$! +$! Exit The Build. +$! +$ EXIT +$! +$! End The File Exist Check. +$! +$ ENDIF +$! +$! Compile The File. +$! +$ ON ERROR THEN GOTO NEXT_FILE +$ CC/OBJECT='OBJECT_FILE' 'SOURCE_FILE' +$! +$! Add It To The Library. +$! +$ LIBRARY/REPLACE/OBJECT 'LIB_NAME' 'OBJECT_FILE' +$! +$! Time To Clean Up The Object File. +$! +$ DELETE 'OBJECT_FILE';* +$! +$! Go Back And Do It Again. +$! +$ GOTO NEXT_FILE +$! +$! All Done With This Library Part. +$! +$ FILE_DONE: +$! +$! Tell The User That We Are All Done. +$! +$ WRITE SYS$OUTPUT "Library ",LIB_NAME," Built." +$! +$! All Done, Time To Return. +$! +$ RETURN +$! +$! Compile The [.xxx.EXE.RSAREF]DHDEMO Program. +$! +$ DHDEMO: +$! +$! Check To See If We Have The Proper Libraries. +$! +$ GOSUB LIB_CHECK +$! +$! Check To See If We Have A Linker Option File. +$! +$ GOSUB CHECK_OPT_FILE +$! +$! Check To See If The File We Want To Compile Actually Exists. +$! +$ IF (F$SEARCH("SYS$DISK:[.RDEMO]DHDEMO.C").EQS."") +$ THEN +$! +$! Tell The User That The File Dosen't Exist. +$! +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT "The File [.RDEMO]DHDEMO.C Dosen't Exist." +$ WRITE SYS$OUTPUT "" +$! +$! Exit The Build. +$! +$ EXIT +$! +$! End The [.RDEMO]DHDEMO.C File Check. +$! +$ ENDIF +$! +$! Tell The User What We Are Building. +$! +$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"DHDEMO.EXE" +$! +$! Compile The DHDEMO Program. +$! +$ CC/OBJECT='OBJ_DIR'DHDEMO.OBJ SYS$DISK:[.RDEMO]DHDEMO.C +$! +$! Link The DHDEMO Program. +$! +$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS - + /EXE='EXE_DIR'DHDEMO.EXE 'OBJ_DIR'DHDEMO.OBJ, - + 'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION +$! +$! All Done, Time To Return. +$! +$ RETURN +$! +$! Compile The RDEMO Program. +$! +$ RDEMO: +$! +$! Check To See If We Have The Proper Libraries. +$! +$ GOSUB LIB_CHECK +$! +$! Check To See If We Have A Linker Option File. +$! +$ GOSUB CHECK_OPT_FILE +$! +$! Check To See If The File We Want To Compile Actually Exists. +$! +$ IF (F$SEARCH("SYS$DISK:[.RDEMO]RDEMO.C").EQS."") +$ THEN +$! +$! Tell The User That The File Dosen't Exist. +$! +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT "The File [.RDEMO]RDEMO.C Dosen't Exist." +$ WRITE SYS$OUTPUT "" +$! +$! Exit The Build. +$! +$ EXIT +$! +$! End The [.RDEMO]RDEMO.C File Check. +$! +$ ENDIF +$! +$! Tell The User What We Are Building. +$! +$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"RDEMO.EXE" +$! +$! Compile The RDEMO Program. +$! +$ CC/OBJECT='OBJ_DIR'RDEMO.OBJ SYS$DISK:[.RDEMO]RDEMO.C +$! +$! Link The RDEMO Program. +$! +$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS - + /EXE='EXE_DIR'RDEMO.EXE 'OBJ_DIR'RDEMO.OBJ, - + 'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION +$! +$! All Done, Time To Return. +$! +$ RETURN +$! +$! Check For The Link Option FIle. +$! +$ CHECK_OPT_FILE: +$! +$! Check To See If We Need To Make A VAX C Option File. +$! +$ IF (COMPILER.EQS."VAXC") +$ THEN +$! +$! Check To See If We Already Have A VAX C Linker Option File. +$! +$ IF (F$SEARCH(OPT_FILE).EQS."") +$ THEN +$! +$! We Need A VAX C Linker Option File. +$! +$ CREATE 'OPT_FILE' +$DECK +! +! Default System Options File To Link Agianst +! The Sharable VAX C Runtime Library. +! +SYS$SHARE:VAXCRTL.EXE/SHARE +$EOD +$! +$! End The Option File Check. +$! +$ ENDIF +$! +$! End The VAXC Check. +$! +$ ENDIF +$! +$! Check To See If We Need A GNU C Option File. +$! +$ IF (COMPILER.EQS."GNUC") +$ THEN +$! +$! Check To See If We Already Have A GNU C Linker Option File. +$! +$ IF (F$SEARCH(OPT_FILE).EQS."") +$ THEN +$! +$! We Need A GNU C Linker Option File. +$! +$ CREATE 'OPT_FILE' +$DECK +! +! Default System Options File To Link Agianst +! The Sharable C Runtime Library. +! +GNU_CC:[000000]GCCLIB/LIBRARY +SYS$SHARE:VAXCRTL/SHARE +$EOD +$! +$! End The Option File Check. +$! +$ ENDIF +$! +$! End The GNU C Check. +$! +$ ENDIF +$! +$! Check To See If We Need A DEC C Option File. +$! +$ IF (COMPILER.EQS."DECC") +$ THEN +$! +$! Check To See If We Already Have A DEC C Linker Option File. +$! +$ IF (F$SEARCH(OPT_FILE).EQS."") +$ THEN +$! +$! Figure Out If We Need An AXP Or A VAX Linker Option File. +$! +$ IF (ARCH.EQS."VAX") +$ THEN +$! +$! We Need A DEC C Linker Option File For VAX. +$! +$ CREATE 'OPT_FILE' +$DECK +! +! Default System Options File To Link Agianst +! The Sharable DEC C Runtime Library. +! +SYS$SHARE:DECC$SHR.EXE/SHARE +$EOD +$! +$! Else... +$! +$ ELSE +$! +$! Create The AXP Linker Option File. +$! +$ CREATE 'OPT_FILE' +$DECK +! +! Default System Options File For AXP To Link Agianst +! The Sharable C Runtime Library. +! +SYS$SHARE:CMA$OPEN_LIB_SHR/SHARE +SYS$SHARE:CMA$OPEN_RTL/SHARE +$EOD +$! +$! End The VAX/AXP DEC C Option File Check. +$! +$ ENDIF +$! +$! End The Option File Search. +$! +$ ENDIF +$! +$! End The DEC C Check. +$! +$ ENDIF +$! +$! Tell The User What Linker Option File We Are Using. +$! +$ WRITE SYS$OUTPUT "Using Linker Option File ",OPT_FILE,"." +$! +$! Time To RETURN. +$! +$ RETURN +$ LIB_CHECK: +$! +$! Look For The Library LIBRSAGLUE.OLB. +$! +$ IF (F$SEARCH(LIB_NAME).EQS."") +$ THEN +$! +$! Tell The User We Can't Find The [.xxx.EXE.RSAREF]LIBRSAGLUE.OLB Library. +$! +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT "Can't Find The Library ",LIB_NAME,"." +$ WRITE SYS$OUTPUT "We Can't Link Without It." +$ WRITE SYS$OUTPUT "" +$! +$! And Ask If They Would Like To Build It. +$! +$ INQUIRE YESNO "Would You Like To Build The Library Now (Y/N)?" +$! +$! Check The Answer. +$! +$ IF (YESNO.EQS."Y").OR.(YESNO.EQS."y") +$ THEN +$! +$! Then Build The Library. +$! +$ GOSUB LIBRARY +$! +$! When Done With That, RETURN To Finish What Ever We Were Doing +$! That Needed The Library. +$! +$ RETURN +$! +$! Else... +$! +$ ELSE +$! +$! Since We Can't Link Without It, Exit. +$! +$ EXIT +$! +$! End The Answer Check. +$! +$ ENDIF +$! +$! End The Library Check. +$! +$ ENDIF +$! +$! Time To Return. +$! +$ RETURN +$! +$! Check The User's Options. +$! +$ CHECK_OPTIONS: +$! +$! Check To See If P1 Is Blank. +$! +$ IF (P1.EQS."ALL") +$ THEN +$! +$! P1 Is Blank, So Build Everything. +$! +$ BUILDALL = "TRUE" +$! +$! Else... +$! +$ ELSE +$! +$! Else, Check To See If P1 Has A Valid Arguement. +$! +$ IF (P1.EQS."LIBRARY").OR.(P1.EQS."DHDEMO").OR.(P1.EQS."RDEMO") +$ THEN +$! +$! A Valid Arguement. +$! +$ BUILDALL = P1 +$! +$! Else.... +$! +$ ELSE +$! +$! Tell The User We Don't Know What They Want. +$! +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT "The Option ",P1," Is Invalid. The Valid Options Are:" +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT " ALL : To Just Build Everything." +$ WRITE SYS$OUTPUT " LIBRARY : To Compile Just The [.xxx.EXE.RSAREF]LIBRSAGLUE.OLB Library." +$ WRITE SYS$OUTPUT " DHDEMO : To Compile Just The [.xxx.EXE.RSAREF]DHDEMO Program." +$ WRITE SYS$OUTPUT " RDEMO : To Compile Just The [.xxx.EXE.RSAREF]RDEMO Program. +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT " Where 'xxx' Stands For:" +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT " AXP : Alpha Architecture." +$ WRITE SYS$OUTPUT " VAX : VAX Architecture." +$ WRITE SYS$OUTPUT "" +$! +$! Time To EXIT. +$! +$ EXIT +$! +$! End The Valid Arguement Check. +$! +$ ENDIF +$! +$! End The P1 Check. +$! +$ ENDIF +$! +$! Check To See If P2 Is Blank. +$! +$ IF (P2.EQS."NODEBUG") +$ THEN +$! +$! P2 Is "NODEBUG" So Compile Without Debugger Information. +$! +$ DEBUGGER = "NODEBUG" +$ TRACEBACK = "NOTRACEBACK" +$ GCC_OPTIMIZE = "OPTIMIZE" +$ CC_OPTIMIZE = "OPTIMIZE" +$ WRITE SYS$OUTPUT "No Debugger Information Will Be Produced During Compile." +$ WRITE SYS$OUTPUT "Compiling With Compiler Optimization." +$ ELSE +$! +$! Check To See If We Are To Compile With Debugger Information. +$! +$ IF (P2.EQS."DEBUG") +$ THEN +$! +$! Compile With Debugger Information. +$! +$ DEBUGGER = "DEBUG" +$ TRACEBACK = "TRACEBACK" +$ GCC_OPTIMIZE = "NOOPTIMIZE" +$ CC_OPTIMIZE = "NOOPTIMIZE" +$ WRITE SYS$OUTPUT "Debugger Information Will Be Produced During Compile." +$ WRITE SYS$OUTPUT "Compiling Without Compiler Optimization." +$ ELSE +$! +$! Tell The User Entered An Invalid Option.. +$! +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT "The Option ",P2," Is Invalid. The Valid Options Are:" +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT " DEBUG : Compile With The Debugger Information." +$ WRITE SYS$OUTPUT " NODEBUG : Compile Without The Debugger Information." +$ WRITE SYS$OUTPUT "" +$! +$! Time To EXIT. +$! +$ EXIT +$! +$! End The Valid Arguement Check. +$! +$ ENDIF +$! +$! End The P2 Check. +$! +$ ENDIF +$! +$! Special Threads For OpenVMS v7.1 Or Later. +$! +$! Written By: Richard Levitte +$! richard@levitte.org +$! +$! +$! Check To See If We Have A Option For P4. +$! +$ IF (P4.EQS."") +$ THEN +$! +$! Get The Version Of VMS We Are Using. +$! +$ ISSEVEN := +$ TMP = F$ELEMENT(0,"-",F$EXTRACT(1,4,F$GETSYI("VERSION"))) +$ TMP = F$INTEGER(F$ELEMENT(0,".",TMP)+F$ELEMENT(1,".",TMP)) +$! +$! Check To See If The VMS Version Is v7.1 Or Later. +$! +$ IF (TMP.GE.71) +$ THEN +$! +$! We Have OpenVMS v7.1 Or Later, So Use The Special Threads. +$! +$ ISSEVEN := ,PTHREAD_USE_D4 +$! +$! End The VMS Version Check. +$! +$ ENDIF +$! +$! End The P4 Check. +$! +$ ENDIF +$! +$! Check To See If P3 Is Blank. +$! +$ IF (P3.EQS."") +$ THEN +$! +$! O.K., The User Didn't Specify A Compiler, Let's Try To +$! Find Out Which One To Use. +$! +$! Check To See If We Have GNU C. +$! +$ IF (F$TRNLNM("GNU_CC").NES."") +$ THEN +$! +$! Looks Like GNUC, Set To Use GNUC. +$! +$ COMPILER = "GNUC" +$! +$! End The GNU C Compiler Check. +$! +$ ELSE +$! +$! Check To See If We Have VAXC Or DECC. +$! +$ IF (ARCH.EQS."ALPHA").OR.(F$TRNLNM("DECC$CC_DEFAULT").NES."") +$ THEN +$! +$! Looks Like DECC, Set To Use DECC. +$! +$ COMPILER = "DECC" +$! +$! Tell The User We Are Using DECC. +$! +$ WRITE SYS$OUTPUT "Using DECC 'C' Compiler." +$! +$! Else... +$! +$ ELSE +$! +$! Looks Like VAXC, Set To Use VAXC. +$! +$ COMPILER = "VAXC" +$! +$! End The VAXC Compiler Check. +$! +$ ENDIF +$! +$! End The DECC & VAXC Compiler Check. +$! +$ ENDIF +$! +$! End The Compiler Check. +$! +$ ENDIF +$! +$! Set Up Initial CC Definitions, Possibly With User Ones +$! +$ CCDEFS = "VMS=1" +$ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = CCDEFS + "," + USER_CCDEFS +$ CCEXTRAFLAGS = "" +$ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS +$ CCDISABLEWARNINGS = "" +$ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN - + CCDISABLEWARNINGS = USER_CCDISABLEWARNINGS +$! +$! Check To See If The User Entered A Valid Paramter. +$! +$ IF (P3.EQS."VAXC").OR.(P3.EQS."DECC").OR.(P3.EQS."GNUC") +$ THEN +$! +$! Check To See If The User Wanted DECC. +$! +$ IF (P3.EQS."DECC") +$ THEN +$! +$! Looks Like DECC, Set To Use DECC. +$! +$ COMPILER = "DECC" +$! +$! Tell The User We Are Using DECC. +$! +$ WRITE SYS$OUTPUT "Using DECC 'C' Compiler." +$! +$! Use DECC... +$! +$ CC = "CC" +$ IF ARCH.EQS."VAX" .AND. F$TRNLNM("DECC$CC_DEFAULT").NES."/DECC" - + THEN CC = "CC/DECC" +$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/STANDARD=ANSI89" + - + "/NOLIST/PREFIX=ALL" + - + "/INCLUDE=(SYS$DISK:[-.CRYPTO],SYS$DISK:[.SOURCE])" + CCEXTRAFLAGS +$! +$! Define The Linker Options File Name. +$! +$ OPT_FILE = "SYS$DISK:[]VAX_DECC_OPTIONS.OPT" +$! +$! End DECC Check. +$! +$ ENDIF +$! +$! Check To See If We Are To Use VAXC. +$! +$ IF (P3.EQS."VAXC") +$ THEN +$! +$! Looks Like VAXC, Set To Use VAXC. +$! +$ COMPILER = "VAXC" +$! +$! Tell The User We Are Using VAX C. +$! +$ WRITE SYS$OUTPUT "Using VAXC 'C' Compiler." +$! +$! Compile Using VAXC. +$! +$ CC = "CC" +$ IF ARCH.EQS."AXP" +$ THEN +$ WRITE SYS$OUTPUT "There is no VAX C on Alpha!" +$ EXIT +$ ENDIF +$ IF F$TRNLNM("DECC$CC_DEFAULT").EQS."/DECC" THEN CC = "CC/VAXC" +$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/NOLIST" + - + "/INCLUDE=(SYS$DISK:[-.CRYPTO],SYS$DISK:[.SOURCE])" + CCEXTRAFLAGS +$ CCDEFS = CCDEFS + ",""VAXC""" +$! +$! Define <sys> As SYS$COMMON:[SYSLIB] +$! +$ DEFINE/NOLOG SYS SYS$COMMON:[SYSLIB] +$! +$! Define The Linker Options File Name. +$! +$ OPT_FILE = "SYS$DISK:[]VAX_VAXC_OPTIONS.OPT" +$! +$! End VAXC Check +$! +$ ENDIF +$! +$! Check To See If We Are To Use GNU C. +$! +$ IF (P3.EQS."GNUC") +$ THEN +$! +$! Looks Like GNUC, Set To Use GNUC. +$! +$ COMPILER = "GNUC" +$! +$! Tell The User We Are Using GNUC. +$! +$ WRITE SYS$OUTPUT "Using GNU 'C' Compiler." +$! +$! Use GNU C... +$! +$ IF F$TYPE(GCC) .EQS. "" THEN GCC := GCC +$ CC = GCC+"/NOCASE_HACK/''GCC_OPTIMIZE'/''DEBUGGER'/NOLIST" + - + "/INCLUDE=(SYS$DISK:[-.CRYPTO],SYS$DISK:[.SOURCE])" + CCEXTRAFLAGS +$! +$! Define The Linker Options File Name. +$! +$ OPT_FILE = "SYS$DISK:[]VAX_GNUC_OPTIONS.OPT" +$! +$! End The GNU C Check. +$! +$ ENDIF +$! +$! Set up default defines +$! +$ CCDEFS = """FLAT_INC=1""," + CCDEFS +$ CCDEFS = CCDEFS + ",""RSAref=1""" +$! +$! Finish up the definition of CC. +$! +$ IF COMPILER .EQS. "DECC" +$ THEN +$ IF CCDISABLEWARNINGS .NES. "" +$ THEN +$ CCDISABLEWARNINGS = "/WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))" +$ ENDIF +$ ELSE +$ CCDISABLEWARNINGS = "" +$ ENDIF +$ CC = CC + "/DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS +$! +$! Show user the result +$! +$ WRITE SYS$OUTPUT "Main Compiling Command: ",CC +$! +$! Else The User Entered An Invalid Arguement. +$! +$ ELSE +$! +$! Tell The User We Don't Know What They Want. +$! +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT "The Option ",P3," Is Invalid. The Valid Options Are:" +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT " VAXC : To Compile With VAX C." +$ WRITE SYS$OUTPUT " DECC : To Compile With DEC C." +$ WRITE SYS$OUTPUT " GNUC : To Compile With GNU C." +$ WRITE SYS$OUTPUT "" +$! +$! Time To EXIT. +$! +$ EXIT +$! +$! End The P3 Check. +$! +$ ENDIF +$! +$! Time To RETURN... +$! +$ RETURN +$! +$ INITIALISE: +$! +$! Save old value of the logical name OPENSSL +$! +$ __SAVE_OPENSSL = F$TRNLNM("OPENSSL","LNM$PROCESS_TABLE") +$! +$! Save directory information +$! +$ __HERE = F$PARSE(F$PARSE("A.;",F$ENVIRONMENT("PROCEDURE"))-"A.;","[]A.;") - "A.;" +$ __TOP = __HERE - "RSAREF]" +$ __INCLUDE = __TOP + "INCLUDE.OPENSSL]" +$! +$! Set up the logical name OPENSSL to point at the include directory +$! +$ DEFINE OPENSSL/NOLOG '__INCLUDE' +$! +$! Done +$! +$ RETURN +$! +$ CLEANUP: +$! +$! Restore the logical name OPENSSL if it had a value +$! +$ IF __SAVE_OPENSSL .EQS. "" +$ THEN +$ DEASSIGN OPENSSL +$ ELSE +$ DEFINE/NOLOG OPENSSL '__SAVE_OPENSSL' +$ ENDIF +$! +$! Done +$! +$ RETURN diff --git a/lib/libssl/src/rsaref/rsaref.c b/lib/libssl/src/rsaref/rsaref.c new file mode 100644 index 00000000000..7677eb9fce9 --- /dev/null +++ b/lib/libssl/src/rsaref/rsaref.c @@ -0,0 +1,301 @@ +/* rsaref/rsaref.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef NO_RSA +#include <stdio.h> +#include "cryptlib.h" +#include <openssl/bn.h> +#include <openssl/rsa.h> +#include <openssl/rsaref.h> +#include <openssl/rand.h> + +static int RSAref_bn2bin(BIGNUM * from, unsigned char* to, int max); +#ifdef undef +static BIGNUM* RSAref_bin2bn(unsigned char* from, BIGNUM * to, int max); +#endif +static int RSAref_Public_eay2ref(RSA * from, RSArefPublicKey * to); +static int RSAref_Private_eay2ref(RSA * from, RSArefPrivateKey * to); +int RSA_ref_private_decrypt(int len, unsigned char *from, + unsigned char *to, RSA *rsa, int padding); +int RSA_ref_private_encrypt(int len, unsigned char *from, + unsigned char *to, RSA *rsa, int padding); +int RSA_ref_public_encrypt(int len, unsigned char *from, + unsigned char *to, RSA *rsa, int padding); +int RSA_ref_public_decrypt(int len, unsigned char *from, + unsigned char *to, RSA *rsa, int padding); +static int BN_ref_mod_exp(BIGNUM *r,BIGNUM *a,const BIGNUM *p,const BIGNUM *m, + BN_CTX *ctx, BN_MONT_CTX *m_ctx); +static int RSA_ref_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa); +static RSA_METHOD rsa_pkcs1_ref_meth={ + "RSAref PKCS#1 RSA", + RSA_ref_public_encrypt, + RSA_ref_public_decrypt, + RSA_ref_private_encrypt, + RSA_ref_private_decrypt, + RSA_ref_mod_exp, + BN_ref_mod_exp, + NULL, + NULL, + 0, + NULL, + }; + +RSA_METHOD *RSA_PKCS1_RSAref(void) + { + return(&rsa_pkcs1_ref_meth); + } + +static int RSA_ref_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa) + { + RSAREFerr(RSAREF_F_RSA_REF_MOD_EXP,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); + return(0); + } + +static int BN_ref_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) + { + RSAREFerr(RSAREF_F_BN_REF_MOD_EXP,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); + return(0); + } + +/* unsigned char *to: [max] */ +static int RSAref_bn2bin(BIGNUM *from, unsigned char *to, int max) + { + int i; + + i=BN_num_bytes(from); + if (i > max) + { + RSAREFerr(RSAREF_F_RSAREF_BN2BIN,RSAREF_R_LEN); + return(0); + } + + memset(to,0,(unsigned int)max); + if (!BN_bn2bin(from,&(to[max-i]))) + return(0); + return(1); + } + +#ifdef undef +/* unsigned char *from: [max] */ +static BIGNUM *RSAref_bin2bn(unsigned char *from, BIGNUM *to, int max) + { + int i; + BIGNUM *ret; + + for (i=0; i<max; i++) + if (from[i]) break; + + ret=BN_bin2bn(&(from[i]),max-i,to); + return(ret); + } + +static int RSAref_Public_ref2eay(RSArefPublicKey *from, RSA *to) + { + to->n=RSAref_bin2bn(from->m,NULL,RSAref_MAX_LEN); + to->e=RSAref_bin2bn(from->e,NULL,RSAref_MAX_LEN); + if ((to->n == NULL) || (to->e == NULL)) return(0); + return(1); + } +#endif + +static int RSAref_Public_eay2ref(RSA *from, RSArefPublicKey *to) + { + to->bits=BN_num_bits(from->n); + if (!RSAref_bn2bin(from->n,to->m,RSAref_MAX_LEN)) return(0); + if (!RSAref_bn2bin(from->e,to->e,RSAref_MAX_LEN)) return(0); + return(1); + } + +#ifdef undef +static int RSAref_Private_ref2eay(RSArefPrivateKey *from, RSA *to) + { + if ((to->n=RSAref_bin2bn(from->m,NULL,RSAref_MAX_LEN)) == NULL) + return(0); + if ((to->e=RSAref_bin2bn(from->e,NULL,RSAref_MAX_LEN)) == NULL) + return(0); + if ((to->d=RSAref_bin2bn(from->d,NULL,RSAref_MAX_LEN)) == NULL) + return(0); + if ((to->p=RSAref_bin2bn(from->prime[0],NULL,RSAref_MAX_PLEN)) == NULL) + return(0); + if ((to->q=RSAref_bin2bn(from->prime[1],NULL,RSAref_MAX_PLEN)) == NULL) + return(0); + if ((to->dmp1=RSAref_bin2bn(from->pexp[0],NULL,RSAref_MAX_PLEN)) + == NULL) + return(0); + if ((to->dmq1=RSAref_bin2bn(from->pexp[1],NULL,RSAref_MAX_PLEN)) + == NULL) + return(0); + if ((to->iqmp=RSAref_bin2bn(from->coef,NULL,RSAref_MAX_PLEN)) == NULL) + return(0); + return(1); + } +#endif + +static int RSAref_Private_eay2ref(RSA *from, RSArefPrivateKey *to) + { + to->bits=BN_num_bits(from->n); + if (!RSAref_bn2bin(from->n,to->m,RSAref_MAX_LEN)) return(0); + if (!RSAref_bn2bin(from->e,to->e,RSAref_MAX_LEN)) return(0); + if (!RSAref_bn2bin(from->d,to->d,RSAref_MAX_LEN)) return(0); + if (!RSAref_bn2bin(from->p,to->prime[0],RSAref_MAX_PLEN)) return(0); + if (!RSAref_bn2bin(from->q,to->prime[1],RSAref_MAX_PLEN)) return(0); + if (!RSAref_bn2bin(from->dmp1,to->pexp[0],RSAref_MAX_PLEN)) return(0); + if (!RSAref_bn2bin(from->dmq1,to->pexp[1],RSAref_MAX_PLEN)) return(0); + if (!RSAref_bn2bin(from->iqmp,to->coef,RSAref_MAX_PLEN)) return(0); + return(1); + } + +int RSA_ref_private_decrypt(int len, unsigned char *from, unsigned char *to, + RSA *rsa, int padding) + { + int i,outlen= -1; + RSArefPrivateKey RSAkey; + + if (!RSAref_Private_eay2ref(rsa,&RSAkey)) + goto err; + if ((i=RSAPrivateDecrypt(to,&outlen,from,len,&RSAkey)) != 0) + { + RSAREFerr(RSAREF_F_RSA_REF_PRIVATE_DECRYPT,i); + outlen= -1; + } +err: + memset(&RSAkey,0,sizeof(RSAkey)); + return(outlen); + } + +int RSA_ref_private_encrypt(int len, unsigned char *from, unsigned char *to, + RSA *rsa, int padding) + { + int i,outlen= -1; + RSArefPrivateKey RSAkey; + + if (padding != RSA_PKCS1_PADDING) + { + RSAREFerr(RSAREF_F_RSA_REF_PRIVATE_ENCRYPT, RSA_R_UNKNOWN_PADDING_TYPE); + goto err; + } + if (!RSAref_Private_eay2ref(rsa,&RSAkey)) + goto err; + if ((i=RSAPrivateEncrypt(to,&outlen,from,len,&RSAkey)) != 0) + { + RSAREFerr(RSAREF_F_RSA_REF_PRIVATE_ENCRYPT,i); + outlen= -1; + } +err: + memset(&RSAkey,0,sizeof(RSAkey)); + return(outlen); + } + +int RSA_ref_public_decrypt(int len, unsigned char *from, unsigned char *to, + RSA *rsa, int padding) + { + int i,outlen= -1; + RSArefPublicKey RSAkey; + + if (!RSAref_Public_eay2ref(rsa,&RSAkey)) + goto err; + if ((i=RSAPublicDecrypt(to,&outlen,from,len,&RSAkey)) != 0) + { + RSAREFerr(RSAREF_F_RSA_REF_PUBLIC_DECRYPT,i); + outlen= -1; + } +err: + memset(&RSAkey,0,sizeof(RSAkey)); + return(outlen); + } + +int RSA_ref_public_encrypt(int len, unsigned char *from, unsigned char *to, + RSA *rsa, int padding) + { + int outlen= -1; + int i; + RSArefPublicKey RSAkey; + RSARandomState rnd; + unsigned char buf[16]; + + if (padding != RSA_PKCS1_PADDING && padding != RSA_SSLV23_PADDING) + { + RSAREFerr(RSAREF_F_RSA_REF_PUBLIC_ENCRYPT, RSA_R_UNKNOWN_PADDING_TYPE); + goto err; + } + + R_RandomInit(&rnd); + R_GetRandomBytesNeeded((unsigned int *)&i,&rnd); + while (i > 0) + { + RAND_bytes(buf,16); + R_RandomUpdate(&rnd,buf,(unsigned int)((i>16)?16:i)); + i-=16; + } + + if (!RSAref_Public_eay2ref(rsa,&RSAkey)) + goto err; + if ((i=RSAPublicEncrypt(to,&outlen,from,len,&RSAkey,&rnd)) != 0) + { + RSAREFerr(RSAREF_F_RSA_REF_PUBLIC_ENCRYPT,i); + outlen= -1; + goto err; + } +err: + memset(&RSAkey,0,sizeof(RSAkey)); + R_RandomFinal(&rnd); + memset(&rnd,0,sizeof(rnd)); + return(outlen); + } +#endif diff --git a/lib/libssl/src/rsaref/rsaref.h b/lib/libssl/src/rsaref/rsaref.h new file mode 100644 index 00000000000..15f65dd94f8 --- /dev/null +++ b/lib/libssl/src/rsaref/rsaref.h @@ -0,0 +1,180 @@ +/* rsaref/rsaref.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_RSAREF_H +#define HEADER_RSAREF_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef NO_RSA +#include <openssl/rsa.h> + +/* RSAeuro */ +/*#define RSAref_MAX_BITS 2048*/ + +/* RSAref */ +#define RSAref_MAX_BITS 1024 + +#define RSAref_MIN_BITS 508 +#define RSAref_MAX_LEN ((RSAref_MAX_BITS+7)/8) +#define RSAref_MAX_PBITS (RSAref_MAX_BITS+1)/2 +#define RSAref_MAX_PLEN ((RSAref_MAX_PBITS+7)/8) + +typedef struct RSArefPublicKey_st + { + unsigned int bits; + unsigned char m[RSAref_MAX_LEN]; + unsigned char e[RSAref_MAX_LEN]; + } RSArefPublicKey; + +typedef struct RSArefPrivateKey_st + { + unsigned int bits; + unsigned char m[RSAref_MAX_LEN]; + unsigned char e[RSAref_MAX_LEN]; + unsigned char d[RSAref_MAX_LEN]; + unsigned char prime[2][RSAref_MAX_PLEN];/* p & q */ + unsigned char pexp[2][RSAref_MAX_PLEN]; /* dmp1 & dmq1 */ + unsigned char coef[RSAref_MAX_PLEN]; /* iqmp */ + } RSArefPrivateKey; + +typedef struct RSARandomState_st + { + unsigned int needed; + unsigned char state[16]; + unsigned int outputnum; + unsigned char output[16]; + } RSARandomState; + +#define RE_CONTENT_ENCODING 0x0400 +#define RE_DATA 0x0401 +#define RE_DIGEST_ALGORITHM 0x0402 +#define RE_ENCODING 0x0403 +#define RE_KEY 0x0404 +#define RE_KEY_ENCODING 0x0405 +#define RE_LEN 0x0406 +#define RE_MODULUS_LEN 0x0407 +#define RE_NEED_RANDOM 0x0408 +#define RE_PRIVATE_KEY 0x0409 +#define RE_PUBLIC_KEY 0x040a +#define RE_SIGNATURE 0x040b +#define RE_SIGNATURE_ENCODING 0x040c +#define RE_ENCRYPTION_ALGORITHM 0x040d + +int RSAPrivateDecrypt(unsigned char *to, int *outlen, unsigned char *from, + int len, RSArefPrivateKey *RSAkey); +int RSAPrivateEncrypt(unsigned char *to, int *outlen, unsigned char *from, + int len, RSArefPrivateKey *RSAkey); +int RSAPublicDecrypt(unsigned char *to, int *outlen, unsigned char *from, + int len, RSArefPublicKey *RSAkey); +int RSAPublicEncrypt(unsigned char *to, int *outlen, unsigned char *from, + int len, RSArefPublicKey *RSAkey,RSARandomState *rnd); +int R_RandomInit(RSARandomState *rnd); +int R_GetRandomBytesNeeded(unsigned int *,RSARandomState *rnd); +int R_RandomUpdate(RSARandomState *rnd, unsigned char *data, unsigned int n); +int R_RandomFinal(RSARandomState *rnd); + +void ERR_load_RSAREF_strings(void ); +RSA_METHOD *RSA_PKCS1_RSAref(void ); +#endif + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +/* Error codes for the RSAREF functions. */ + +/* Function codes. */ +#define RSAREF_F_BN_REF_MOD_EXP 100 +#define RSAREF_F_RSAREF_BN2BIN 101 +#define RSAREF_F_RSA_BN2BIN 102 +#define RSAREF_F_RSA_PRIVATE_DECRYPT 103 +#define RSAREF_F_RSA_PRIVATE_ENCRYPT 104 +#define RSAREF_F_RSA_PUBLIC_DECRYPT 105 +#define RSAREF_F_RSA_PUBLIC_ENCRYPT 106 +#define RSAREF_F_RSA_REF_BN2BIN 107 +#define RSAREF_F_RSA_REF_MOD_EXP 108 +#define RSAREF_F_RSA_REF_PRIVATE_DECRYPT 109 +#define RSAREF_F_RSA_REF_PRIVATE_ENCRYPT 110 +#define RSAREF_F_RSA_REF_PUBLIC_DECRYPT 111 +#define RSAREF_F_RSA_REF_PUBLIC_ENCRYPT 112 + +/* Reason codes. */ +#define RSAREF_R_CONTENT_ENCODING 0x0400 +#define RSAREF_R_DATA 0x0401 +#define RSAREF_R_DIGEST_ALGORITHM 0x0402 +#define RSAREF_R_ENCODING 0x0403 +#define RSAREF_R_ENCRYPTION_ALGORITHM 0x040d +#define RSAREF_R_KEY 0x0404 +#define RSAREF_R_KEY_ENCODING 0x0405 +#define RSAREF_R_LEN 0x0406 +#define RSAREF_R_MODULUS_LEN 0x0407 +#define RSAREF_R_NEED_RANDOM 0x0408 +#define RSAREF_R_PRIVATE_KEY 0x0409 +#define RSAREF_R_PUBLIC_KEY 0x040a +#define RSAREF_R_SIGNATURE 0x040b +#define RSAREF_R_SIGNATURE_ENCODING 0x040c + +#ifdef __cplusplus +} +#endif +#endif + |