From 226b8a984011488eb6966f9b8b7659feae55dda8 Mon Sep 17 00:00:00 2001 From: miod <> Date: Tue, 15 Apr 2014 18:08:42 +0000 Subject: Moved to regress/lib/libcrypto. --- src/lib/libcrypto/bf/bftest.c | 529 ------- src/lib/libcrypto/bn/bntest.c | 2013 --------------------------- src/lib/libcrypto/bn/exptest.c | 204 --- src/lib/libcrypto/cast/casttest.c | 233 ---- src/lib/libcrypto/des/destest.c | 952 ------------- src/lib/libcrypto/dh/dhtest.c | 226 --- src/lib/libcrypto/dsa/dsatest.c | 259 ---- src/lib/libcrypto/ec/ectest.c | 1489 -------------------- src/lib/libcrypto/ecdh/ecdhtest.c | 374 ----- src/lib/libcrypto/ecdsa/ecdsatest.c | 572 -------- src/lib/libcrypto/evp/evp_test.c | 450 ------ src/lib/libcrypto/hmac/hmactest.c | 164 --- src/lib/libcrypto/idea/ideatest.c | 235 ---- src/lib/libcrypto/md2/md2test.c | 139 -- src/lib/libcrypto/md4/md4test.c | 136 -- src/lib/libcrypto/md5/md5test.c | 140 -- src/lib/libcrypto/mdc2/mdc2test.c | 141 -- src/lib/libcrypto/rand/randtest.c | 219 --- src/lib/libcrypto/rc2/rc2test.c | 274 ---- src/lib/libcrypto/rc4/rc4test.c | 242 ---- src/lib/libcrypto/ripemd/rmdtest.c | 138 -- src/lib/libcrypto/sha/sha1test.c | 166 --- src/lib/libcrypto/sha/shatest.c | 166 --- src/lib/libssl/src/crypto/bf/bftest.c | 529 ------- src/lib/libssl/src/crypto/bn/bntest.c | 2013 --------------------------- src/lib/libssl/src/crypto/bn/exptest.c | 204 --- src/lib/libssl/src/crypto/cast/casttest.c | 233 ---- src/lib/libssl/src/crypto/des/destest.c | 952 ------------- src/lib/libssl/src/crypto/dh/dhtest.c | 226 --- src/lib/libssl/src/crypto/dsa/dsatest.c | 259 ---- src/lib/libssl/src/crypto/ec/ectest.c | 1489 -------------------- src/lib/libssl/src/crypto/ecdh/ecdhtest.c | 374 ----- src/lib/libssl/src/crypto/ecdsa/ecdsatest.c | 572 -------- src/lib/libssl/src/crypto/evp/evp_test.c | 450 ------ src/lib/libssl/src/crypto/hmac/hmactest.c | 164 --- src/lib/libssl/src/crypto/idea/ideatest.c | 235 ---- src/lib/libssl/src/crypto/md2/md2test.c | 139 -- src/lib/libssl/src/crypto/md4/md4test.c | 136 -- src/lib/libssl/src/crypto/md5/md5test.c | 140 -- src/lib/libssl/src/crypto/mdc2/mdc2test.c | 141 -- src/lib/libssl/src/crypto/rand/randtest.c | 219 --- src/lib/libssl/src/crypto/rc2/rc2test.c | 274 ---- src/lib/libssl/src/crypto/rc4/rc4test.c | 242 ---- src/lib/libssl/src/crypto/ripemd/rmdtest.c | 138 -- src/lib/libssl/src/crypto/sha/sha1test.c | 166 --- src/lib/libssl/src/crypto/sha/shatest.c | 166 --- 46 files changed, 18922 deletions(-) delete mode 100644 src/lib/libcrypto/bf/bftest.c delete mode 100644 src/lib/libcrypto/bn/bntest.c delete mode 100644 src/lib/libcrypto/bn/exptest.c delete mode 100644 src/lib/libcrypto/cast/casttest.c delete mode 100644 src/lib/libcrypto/des/destest.c delete mode 100644 src/lib/libcrypto/dh/dhtest.c delete mode 100644 src/lib/libcrypto/dsa/dsatest.c delete mode 100644 src/lib/libcrypto/ec/ectest.c delete mode 100644 src/lib/libcrypto/ecdh/ecdhtest.c delete mode 100644 src/lib/libcrypto/ecdsa/ecdsatest.c delete mode 100644 src/lib/libcrypto/evp/evp_test.c delete mode 100644 src/lib/libcrypto/hmac/hmactest.c delete mode 100644 src/lib/libcrypto/idea/ideatest.c delete mode 100644 src/lib/libcrypto/md2/md2test.c delete mode 100644 src/lib/libcrypto/md4/md4test.c delete mode 100644 src/lib/libcrypto/md5/md5test.c delete mode 100644 src/lib/libcrypto/mdc2/mdc2test.c delete mode 100644 src/lib/libcrypto/rand/randtest.c delete mode 100644 src/lib/libcrypto/rc2/rc2test.c delete mode 100644 src/lib/libcrypto/rc4/rc4test.c delete mode 100644 src/lib/libcrypto/ripemd/rmdtest.c delete mode 100644 src/lib/libcrypto/sha/sha1test.c delete mode 100644 src/lib/libcrypto/sha/shatest.c delete mode 100644 src/lib/libssl/src/crypto/bf/bftest.c delete mode 100644 src/lib/libssl/src/crypto/bn/bntest.c delete mode 100644 src/lib/libssl/src/crypto/bn/exptest.c delete mode 100644 src/lib/libssl/src/crypto/cast/casttest.c delete mode 100644 src/lib/libssl/src/crypto/des/destest.c delete mode 100644 src/lib/libssl/src/crypto/dh/dhtest.c delete mode 100644 src/lib/libssl/src/crypto/dsa/dsatest.c delete mode 100644 src/lib/libssl/src/crypto/ec/ectest.c delete mode 100644 src/lib/libssl/src/crypto/ecdh/ecdhtest.c delete mode 100644 src/lib/libssl/src/crypto/ecdsa/ecdsatest.c delete mode 100644 src/lib/libssl/src/crypto/evp/evp_test.c delete mode 100644 src/lib/libssl/src/crypto/hmac/hmactest.c delete mode 100644 src/lib/libssl/src/crypto/idea/ideatest.c delete mode 100644 src/lib/libssl/src/crypto/md2/md2test.c delete mode 100644 src/lib/libssl/src/crypto/md4/md4test.c delete mode 100644 src/lib/libssl/src/crypto/md5/md5test.c delete mode 100644 src/lib/libssl/src/crypto/mdc2/mdc2test.c delete mode 100644 src/lib/libssl/src/crypto/rand/randtest.c delete mode 100644 src/lib/libssl/src/crypto/rc2/rc2test.c delete mode 100644 src/lib/libssl/src/crypto/rc4/rc4test.c delete mode 100644 src/lib/libssl/src/crypto/ripemd/rmdtest.c delete mode 100644 src/lib/libssl/src/crypto/sha/sha1test.c delete mode 100644 src/lib/libssl/src/crypto/sha/shatest.c (limited to 'src/lib') diff --git a/src/lib/libcrypto/bf/bftest.c b/src/lib/libcrypto/bf/bftest.c deleted file mode 100644 index 20caf0f3f8..0000000000 --- a/src/lib/libcrypto/bf/bftest.c +++ /dev/null @@ -1,529 +0,0 @@ -/* crypto/bf/bftest.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.] - */ - -/* This has been a quickly hacked 'ideatest.c'. When I add tests for other - * RC2 modes, more of the code will be uncommented. */ - -#include -#include -#include -#include /* To see if OPENSSL_NO_BF is defined */ - -#include "../e_os.h" - -#ifdef OPENSSL_NO_BF -int main(int argc, char *argv[]) -{ - printf("No BF support\n"); - return(0); -} -#else -#include - -static char *bf_key[2]={ - "abcdefghijklmnopqrstuvwxyz", - "Who is John Galt?" - }; - -/* big endian */ -static BF_LONG bf_plain[2][2]={ - {0x424c4f57L,0x46495348L}, - {0xfedcba98L,0x76543210L} - }; - -static BF_LONG bf_cipher[2][2]={ - {0x324ed0feL,0xf413a203L}, - {0xcc91732bL,0x8022f684L} - }; -/************/ - -/* Lets use the DES test vectors :-) */ -#define NUM_TESTS 34 -static unsigned char ecb_data[NUM_TESTS][8]={ - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, - {0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}, - {0x7C,0xA1,0x10,0x45,0x4A,0x1A,0x6E,0x57}, - {0x01,0x31,0xD9,0x61,0x9D,0xC1,0x37,0x6E}, - {0x07,0xA1,0x13,0x3E,0x4A,0x0B,0x26,0x86}, - {0x38,0x49,0x67,0x4C,0x26,0x02,0x31,0x9E}, - {0x04,0xB9,0x15,0xBA,0x43,0xFE,0xB5,0xB6}, - {0x01,0x13,0xB9,0x70,0xFD,0x34,0xF2,0xCE}, - {0x01,0x70,0xF1,0x75,0x46,0x8F,0xB5,0xE6}, - {0x43,0x29,0x7F,0xAD,0x38,0xE3,0x73,0xFE}, - {0x07,0xA7,0x13,0x70,0x45,0xDA,0x2A,0x16}, - {0x04,0x68,0x91,0x04,0xC2,0xFD,0x3B,0x2F}, - {0x37,0xD0,0x6B,0xB5,0x16,0xCB,0x75,0x46}, - {0x1F,0x08,0x26,0x0D,0x1A,0xC2,0x46,0x5E}, - {0x58,0x40,0x23,0x64,0x1A,0xBA,0x61,0x76}, - {0x02,0x58,0x16,0x16,0x46,0x29,0xB0,0x07}, - {0x49,0x79,0x3E,0xBC,0x79,0xB3,0x25,0x8F}, - {0x4F,0xB0,0x5E,0x15,0x15,0xAB,0x73,0xA7}, - {0x49,0xE9,0x5D,0x6D,0x4C,0xA2,0x29,0xBF}, - {0x01,0x83,0x10,0xDC,0x40,0x9B,0x26,0xD6}, - {0x1C,0x58,0x7F,0x1C,0x13,0x92,0x4F,0xEF}, - {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01}, - {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E}, - {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}}; - -static unsigned char plain_data[NUM_TESTS][8]={ - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, - {0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01}, - {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, - {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0x01,0xA1,0xD6,0xD0,0x39,0x77,0x67,0x42}, - {0x5C,0xD5,0x4C,0xA8,0x3D,0xEF,0x57,0xDA}, - {0x02,0x48,0xD4,0x38,0x06,0xF6,0x71,0x72}, - {0x51,0x45,0x4B,0x58,0x2D,0xDF,0x44,0x0A}, - {0x42,0xFD,0x44,0x30,0x59,0x57,0x7F,0xA2}, - {0x05,0x9B,0x5E,0x08,0x51,0xCF,0x14,0x3A}, - {0x07,0x56,0xD8,0xE0,0x77,0x47,0x61,0xD2}, - {0x76,0x25,0x14,0xB8,0x29,0xBF,0x48,0x6A}, - {0x3B,0xDD,0x11,0x90,0x49,0x37,0x28,0x02}, - {0x26,0x95,0x5F,0x68,0x35,0xAF,0x60,0x9A}, - {0x16,0x4D,0x5E,0x40,0x4F,0x27,0x52,0x32}, - {0x6B,0x05,0x6E,0x18,0x75,0x9F,0x5C,0xCA}, - {0x00,0x4B,0xD6,0xEF,0x09,0x17,0x60,0x62}, - {0x48,0x0D,0x39,0x00,0x6E,0xE7,0x62,0xF2}, - {0x43,0x75,0x40,0xC8,0x69,0x8F,0x3C,0xFA}, - {0x07,0x2D,0x43,0xA0,0x77,0x07,0x52,0x92}, - {0x02,0xFE,0x55,0x77,0x81,0x17,0xF1,0x2A}, - {0x1D,0x9D,0x5C,0x50,0x18,0xF7,0x28,0xC2}, - {0x30,0x55,0x32,0x28,0x6D,0x6F,0x29,0x5A}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}; - -static unsigned char cipher_data[NUM_TESTS][8]={ - {0x4E,0xF9,0x97,0x45,0x61,0x98,0xDD,0x78}, - {0x51,0x86,0x6F,0xD5,0xB8,0x5E,0xCB,0x8A}, - {0x7D,0x85,0x6F,0x9A,0x61,0x30,0x63,0xF2}, - {0x24,0x66,0xDD,0x87,0x8B,0x96,0x3C,0x9D}, - {0x61,0xF9,0xC3,0x80,0x22,0x81,0xB0,0x96}, - {0x7D,0x0C,0xC6,0x30,0xAF,0xDA,0x1E,0xC7}, - {0x4E,0xF9,0x97,0x45,0x61,0x98,0xDD,0x78}, - {0x0A,0xCE,0xAB,0x0F,0xC6,0xA0,0xA2,0x8D}, - {0x59,0xC6,0x82,0x45,0xEB,0x05,0x28,0x2B}, - {0xB1,0xB8,0xCC,0x0B,0x25,0x0F,0x09,0xA0}, - {0x17,0x30,0xE5,0x77,0x8B,0xEA,0x1D,0xA4}, - {0xA2,0x5E,0x78,0x56,0xCF,0x26,0x51,0xEB}, - {0x35,0x38,0x82,0xB1,0x09,0xCE,0x8F,0x1A}, - {0x48,0xF4,0xD0,0x88,0x4C,0x37,0x99,0x18}, - {0x43,0x21,0x93,0xB7,0x89,0x51,0xFC,0x98}, - {0x13,0xF0,0x41,0x54,0xD6,0x9D,0x1A,0xE5}, - {0x2E,0xED,0xDA,0x93,0xFF,0xD3,0x9C,0x79}, - {0xD8,0x87,0xE0,0x39,0x3C,0x2D,0xA6,0xE3}, - {0x5F,0x99,0xD0,0x4F,0x5B,0x16,0x39,0x69}, - {0x4A,0x05,0x7A,0x3B,0x24,0xD3,0x97,0x7B}, - {0x45,0x20,0x31,0xC1,0xE4,0xFA,0xDA,0x8E}, - {0x75,0x55,0xAE,0x39,0xF5,0x9B,0x87,0xBD}, - {0x53,0xC5,0x5F,0x9C,0xB4,0x9F,0xC0,0x19}, - {0x7A,0x8E,0x7B,0xFA,0x93,0x7E,0x89,0xA3}, - {0xCF,0x9C,0x5D,0x7A,0x49,0x86,0xAD,0xB5}, - {0xD1,0xAB,0xB2,0x90,0x65,0x8B,0xC7,0x78}, - {0x55,0xCB,0x37,0x74,0xD1,0x3E,0xF2,0x01}, - {0xFA,0x34,0xEC,0x48,0x47,0xB2,0x68,0xB2}, - {0xA7,0x90,0x79,0x51,0x08,0xEA,0x3C,0xAE}, - {0xC3,0x9E,0x07,0x2D,0x9F,0xAC,0x63,0x1D}, - {0x01,0x49,0x33,0xE0,0xCD,0xAF,0xF6,0xE4}, - {0xF2,0x1E,0x9A,0x77,0xB7,0x1C,0x49,0xBC}, - {0x24,0x59,0x46,0x88,0x57,0x54,0x36,0x9A}, - {0x6B,0x5C,0x5A,0x9C,0x5D,0x9E,0x0A,0x5A}, - }; - -static unsigned char cbc_key [16]={ - 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef, - 0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87}; -static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; -static char cbc_data[40]="7654321 Now is the time for "; -static unsigned char cbc_ok[32]={ - 0x6B,0x77,0xB4,0xD6,0x30,0x06,0xDE,0xE6, - 0x05,0xB1,0x56,0xE2,0x74,0x03,0x97,0x93, - 0x58,0xDE,0xB9,0xE7,0x15,0x46,0x16,0xD9, - 0x59,0xF1,0x65,0x2B,0xD5,0xFF,0x92,0xCC}; - -static unsigned char cfb64_ok[]={ - 0xE7,0x32,0x14,0xA2,0x82,0x21,0x39,0xCA, - 0xF2,0x6E,0xCF,0x6D,0x2E,0xB9,0xE7,0x6E, - 0x3D,0xA3,0xDE,0x04,0xD1,0x51,0x72,0x00, - 0x51,0x9D,0x57,0xA6,0xC3}; - -static unsigned char ofb64_ok[]={ - 0xE7,0x32,0x14,0xA2,0x82,0x21,0x39,0xCA, - 0x62,0xB3,0x43,0xCC,0x5B,0x65,0x58,0x73, - 0x10,0xDD,0x90,0x8D,0x0C,0x24,0x1B,0x22, - 0x63,0xC2,0xCF,0x80,0xDA}; - -#define KEY_TEST_NUM 25 -static unsigned char key_test[KEY_TEST_NUM]={ - 0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87, - 0x78,0x69,0x5a,0x4b,0x3c,0x2d,0x1e,0x0f, - 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77, - 0x88}; - -static unsigned char key_data[8]= - {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}; - -static unsigned char key_out[KEY_TEST_NUM][8]={ - {0xF9,0xAD,0x59,0x7C,0x49,0xDB,0x00,0x5E}, - {0xE9,0x1D,0x21,0xC1,0xD9,0x61,0xA6,0xD6}, - {0xE9,0xC2,0xB7,0x0A,0x1B,0xC6,0x5C,0xF3}, - {0xBE,0x1E,0x63,0x94,0x08,0x64,0x0F,0x05}, - {0xB3,0x9E,0x44,0x48,0x1B,0xDB,0x1E,0x6E}, - {0x94,0x57,0xAA,0x83,0xB1,0x92,0x8C,0x0D}, - {0x8B,0xB7,0x70,0x32,0xF9,0x60,0x62,0x9D}, - {0xE8,0x7A,0x24,0x4E,0x2C,0xC8,0x5E,0x82}, - {0x15,0x75,0x0E,0x7A,0x4F,0x4E,0xC5,0x77}, - {0x12,0x2B,0xA7,0x0B,0x3A,0xB6,0x4A,0xE0}, - {0x3A,0x83,0x3C,0x9A,0xFF,0xC5,0x37,0xF6}, - {0x94,0x09,0xDA,0x87,0xA9,0x0F,0x6B,0xF2}, - {0x88,0x4F,0x80,0x62,0x50,0x60,0xB8,0xB4}, - {0x1F,0x85,0x03,0x1C,0x19,0xE1,0x19,0x68}, - {0x79,0xD9,0x37,0x3A,0x71,0x4C,0xA3,0x4F}, - {0x93,0x14,0x28,0x87,0xEE,0x3B,0xE1,0x5C}, - {0x03,0x42,0x9E,0x83,0x8C,0xE2,0xD1,0x4B}, - {0xA4,0x29,0x9E,0x27,0x46,0x9F,0xF6,0x7B}, - {0xAF,0xD5,0xAE,0xD1,0xC1,0xBC,0x96,0xA8}, - {0x10,0x85,0x1C,0x0E,0x38,0x58,0xDA,0x9F}, - {0xE6,0xF5,0x1E,0xD7,0x9B,0x9D,0xB2,0x1F}, - {0x64,0xA6,0xE1,0x4A,0xFD,0x36,0xB4,0x6F}, - {0x80,0xC7,0xD7,0xD4,0x5A,0x54,0x79,0xAD}, - {0x05,0x04,0x4B,0x62,0xFA,0x52,0xD0,0x80}, - }; - -static int test(void ); -static int print_test_data(void ); -int main(int argc, char *argv[]) - { - int ret; - - if (argc > 1) - ret=print_test_data(); - else - ret=test(); - -#ifdef OPENSSL_SYS_NETWARE - if (ret) printf("ERROR: %d\n", ret); -#endif - EXIT(ret); - return(0); - } - -static int print_test_data(void) - { - unsigned int i,j; - - printf("ecb test data\n"); - printf("key bytes\t\tclear bytes\t\tcipher bytes\n"); - for (i=0; i -#include -#include - -#include "e_os.h" - -#include -#include -#include -#include -#include - -const int num0 = 100; /* number of tests */ -const int num1 = 50; /* additional tests for some functions */ -const int num2 = 5; /* number of tests for slow functions */ - -int test_add(BIO *bp); -int test_sub(BIO *bp); -int test_lshift1(BIO *bp); -int test_lshift(BIO *bp,BN_CTX *ctx,BIGNUM *a_); -int test_rshift1(BIO *bp); -int test_rshift(BIO *bp,BN_CTX *ctx); -int test_div(BIO *bp,BN_CTX *ctx); -int test_div_word(BIO *bp); -int test_div_recp(BIO *bp,BN_CTX *ctx); -int test_mul(BIO *bp); -int test_sqr(BIO *bp,BN_CTX *ctx); -int test_mont(BIO *bp,BN_CTX *ctx); -int test_mod(BIO *bp,BN_CTX *ctx); -int test_mod_mul(BIO *bp,BN_CTX *ctx); -int test_mod_exp(BIO *bp,BN_CTX *ctx); -int test_mod_exp_mont_consttime(BIO *bp,BN_CTX *ctx); -int test_exp(BIO *bp,BN_CTX *ctx); -int test_gf2m_add(BIO *bp); -int test_gf2m_mod(BIO *bp); -int test_gf2m_mod_mul(BIO *bp,BN_CTX *ctx); -int test_gf2m_mod_sqr(BIO *bp,BN_CTX *ctx); -int test_gf2m_mod_inv(BIO *bp,BN_CTX *ctx); -int test_gf2m_mod_div(BIO *bp,BN_CTX *ctx); -int test_gf2m_mod_exp(BIO *bp,BN_CTX *ctx); -int test_gf2m_mod_sqrt(BIO *bp,BN_CTX *ctx); -int test_gf2m_mod_solve_quad(BIO *bp,BN_CTX *ctx); -int test_kron(BIO *bp,BN_CTX *ctx); -int test_sqrt(BIO *bp,BN_CTX *ctx); -int rand_neg(void); -static int results=0; - -static unsigned char lst[]="\xC6\x4F\x43\x04\x2A\xEA\xCA\x6E\x58\x36\x80\x5B\xE8\xC9" -"\x9B\x04\x5D\x48\x36\xC2\xFD\x16\xC9\x64\xF0"; - -static const char rnd_seed[] = "string to make the random number generator think it has entropy"; - -static void message(BIO *out, char *m) - { - fprintf(stderr, "test %s\n", m); - BIO_puts(out, "print \"test "); - BIO_puts(out, m); - BIO_puts(out, "\\n\"\n"); - } - -int main(int argc, char *argv[]) - { - BN_CTX *ctx; - BIO *out; - char *outfile=NULL; - - results = 0; - - RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_generate_prime may fail */ - - argc--; - argv++; - while (argc >= 1) - { - if (strcmp(*argv,"-results") == 0) - results=1; - else if (strcmp(*argv,"-out") == 0) - { - if (--argc < 1) break; - outfile= *(++argv); - } - argc--; - argv++; - } - - - ctx=BN_CTX_new(); - if (ctx == NULL) EXIT(1); - - out=BIO_new(BIO_s_file()); - if (out == NULL) EXIT(1); - if (outfile == NULL) - { - BIO_set_fp(out,stdout,BIO_NOCLOSE); - } - else - { - if (!BIO_write_filename(out,outfile)) - { - perror(outfile); - EXIT(1); - } - } - - if (!results) - BIO_puts(out,"obase=16\nibase=16\n"); - - message(out,"BN_add"); - if (!test_add(out)) goto err; - (void)BIO_flush(out); - - message(out,"BN_sub"); - if (!test_sub(out)) goto err; - (void)BIO_flush(out); - - message(out,"BN_lshift1"); - if (!test_lshift1(out)) goto err; - (void)BIO_flush(out); - - message(out,"BN_lshift (fixed)"); - if (!test_lshift(out,ctx,BN_bin2bn(lst,sizeof(lst)-1,NULL))) - goto err; - (void)BIO_flush(out); - - message(out,"BN_lshift"); - if (!test_lshift(out,ctx,NULL)) goto err; - (void)BIO_flush(out); - - message(out,"BN_rshift1"); - if (!test_rshift1(out)) goto err; - (void)BIO_flush(out); - - message(out,"BN_rshift"); - if (!test_rshift(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_sqr"); - if (!test_sqr(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_mul"); - if (!test_mul(out)) goto err; - (void)BIO_flush(out); - - message(out,"BN_div"); - if (!test_div(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_div_word"); - if (!test_div_word(out)) goto err; - (void)BIO_flush(out); - - message(out,"BN_div_recp"); - if (!test_div_recp(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_mod"); - if (!test_mod(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_mod_mul"); - if (!test_mod_mul(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_mont"); - if (!test_mont(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_mod_exp"); - if (!test_mod_exp(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_mod_exp_mont_consttime"); - if (!test_mod_exp_mont_consttime(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_exp"); - if (!test_exp(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_kronecker"); - if (!test_kron(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_mod_sqrt"); - if (!test_sqrt(out,ctx)) goto err; - (void)BIO_flush(out); -#ifndef OPENSSL_NO_EC2M - message(out,"BN_GF2m_add"); - if (!test_gf2m_add(out)) goto err; - (void)BIO_flush(out); - - message(out,"BN_GF2m_mod"); - if (!test_gf2m_mod(out)) goto err; - (void)BIO_flush(out); - - message(out,"BN_GF2m_mod_mul"); - if (!test_gf2m_mod_mul(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_GF2m_mod_sqr"); - if (!test_gf2m_mod_sqr(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_GF2m_mod_inv"); - if (!test_gf2m_mod_inv(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_GF2m_mod_div"); - if (!test_gf2m_mod_div(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_GF2m_mod_exp"); - if (!test_gf2m_mod_exp(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_GF2m_mod_sqrt"); - if (!test_gf2m_mod_sqrt(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_GF2m_mod_solve_quad"); - if (!test_gf2m_mod_solve_quad(out,ctx)) goto err; - (void)BIO_flush(out); -#endif - BN_CTX_free(ctx); - BIO_free(out); - -/**/ - EXIT(0); -err: - BIO_puts(out,"1\n"); /* make sure the Perl script fed by bc notices - * the failure, see test_bn in test/Makefile.ssl*/ - (void)BIO_flush(out); - ERR_load_crypto_strings(); - ERR_print_errors_fp(stderr); - EXIT(1); - return(1); - } - -int test_add(BIO *bp) - { - BIGNUM a,b,c; - int i; - - BN_init(&a); - BN_init(&b); - BN_init(&c); - - BN_bntest_rand(&a,512,0,0); - for (i=0; i sizeof(unsigned long)) - { - unsigned long h=(unsigned long)(w>>32), - l=(unsigned long)(w); - - if (h) BIO_printf(bp,"%lX%08lX",h,l); - else BIO_printf(bp,"%lX",l); - return; - } -#endif - BIO_printf(bp,BN_HEX_FMT1,w); - } - -int test_div_word(BIO *bp) - { - BIGNUM a,b; - BN_ULONG r,s; - int i; - - BN_init(&a); - BN_init(&b); - - for (i=0; iN)); -#endif - BN_print(bp,&a); - BIO_puts(bp," * "); - BN_print(bp,&b); - BIO_puts(bp," % "); - BN_print(bp,&(mont->N)); - BIO_puts(bp," - "); - } - BN_print(bp,&A); - BIO_puts(bp,"\n"); - } - BN_mod_mul(&d,&a,&b,&n,ctx); - BN_sub(&d,&d,&A); - if(!BN_is_zero(&d)) - { - fprintf(stderr,"Montgomery multiplication test failed!\n"); - return 0; - } - } - BN_MONT_CTX_free(mont); - BN_free(&a); - BN_free(&b); - BN_free(&c); - BN_free(&d); - BN_free(&A); - BN_free(&B); - BN_free(&n); - return(1); - } - -int test_mod(BIO *bp, BN_CTX *ctx) - { - BIGNUM *a,*b,*c,*d,*e; - int i; - - a=BN_new(); - b=BN_new(); - c=BN_new(); - d=BN_new(); - e=BN_new(); - - BN_bntest_rand(a,1024,0,0); /**/ - for (i=0; ineg=rand_neg(); - b->neg=rand_neg(); - BN_mod(c,a,b,ctx);/**/ - if (bp != NULL) - { - if (!results) - { - BN_print(bp,a); - BIO_puts(bp," % "); - BN_print(bp,b); - BIO_puts(bp," - "); - } - BN_print(bp,c); - BIO_puts(bp,"\n"); - } - BN_div(d,e,a,b,ctx); - BN_sub(e,e,c); - if(!BN_is_zero(e)) - { - fprintf(stderr,"Modulo test failed!\n"); - return 0; - } - } - BN_free(a); - BN_free(b); - BN_free(c); - BN_free(d); - BN_free(e); - return(1); - } - -int test_mod_mul(BIO *bp, BN_CTX *ctx) - { - BIGNUM *a,*b,*c,*d,*e; - int i,j; - - a=BN_new(); - b=BN_new(); - c=BN_new(); - d=BN_new(); - e=BN_new(); - - for (j=0; j<3; j++) { - BN_bntest_rand(c,1024,0,0); /**/ - for (i=0; ineg=rand_neg(); - b->neg=rand_neg(); - if (!BN_mod_mul(e,a,b,c,ctx)) - { - unsigned long l; - - while ((l=ERR_get_error())) - fprintf(stderr,"ERROR:%s\n", - ERR_error_string(l,NULL)); - EXIT(1); - } - if (bp != NULL) - { - if (!results) - { - BN_print(bp,a); - BIO_puts(bp," * "); - BN_print(bp,b); - BIO_puts(bp," % "); - BN_print(bp,c); - if ((a->neg ^ b->neg) && !BN_is_zero(e)) - { - /* If (a*b) % c is negative, c must be added - * in order to obtain the normalized remainder - * (new with OpenSSL 0.9.7, previous versions of - * BN_mod_mul could generate negative results) - */ - BIO_puts(bp," + "); - BN_print(bp,c); - } - BIO_puts(bp," - "); - } - BN_print(bp,e); - BIO_puts(bp,"\n"); - } - BN_mul(d,a,b,ctx); - BN_sub(d,d,e); - BN_div(a,b,d,c,ctx); - if(!BN_is_zero(b)) - { - fprintf(stderr,"Modulo multiply test failed!\n"); - ERR_print_errors_fp(stderr); - return 0; - } - } - } - BN_free(a); - BN_free(b); - BN_free(c); - BN_free(d); - BN_free(e); - return(1); - } - -int test_mod_exp(BIO *bp, BN_CTX *ctx) - { - BIGNUM *a,*b,*c,*d,*e; - int i; - - a=BN_new(); - b=BN_new(); - c=BN_new(); - d=BN_new(); - e=BN_new(); - - BN_bntest_rand(c,30,0,1); /* must be odd for montgomery */ - for (i=0; ineg = rand_neg(); - putc('\n', stderr); - - for (i = 0; i < num0; i++) - { - if (!BN_bntest_rand(a, 512, 0, 0)) goto err; - a->neg = rand_neg(); - - /* t := (|b|-1)/2 (note that b is odd) */ - if (!BN_copy(t, b)) goto err; - t->neg = 0; - if (!BN_sub_word(t, 1)) goto err; - if (!BN_rshift1(t, t)) goto err; - /* r := a^t mod b */ - b->neg=0; - - if (!BN_mod_exp_recp(r, a, t, b, ctx)) goto err; - b->neg=1; - - if (BN_is_word(r, 1)) - legendre = 1; - else if (BN_is_zero(r)) - legendre = 0; - else - { - if (!BN_add_word(r, 1)) goto err; - if (0 != BN_ucmp(r, b)) - { - fprintf(stderr, "Legendre symbol computation failed\n"); - goto err; - } - legendre = -1; - } - - kronecker = BN_kronecker(a, b, ctx); - if (kronecker < -1) goto err; - /* we actually need BN_kronecker(a, |b|) */ - if (a->neg && b->neg) - kronecker = -kronecker; - - if (legendre != kronecker) - { - fprintf(stderr, "legendre != kronecker; a = "); - BN_print_fp(stderr, a); - fprintf(stderr, ", b = "); - BN_print_fp(stderr, b); - fprintf(stderr, "\n"); - goto err; - } - - putc('.', stderr); - fflush(stderr); - } - - putc('\n', stderr); - fflush(stderr); - ret = 1; - err: - if (a != NULL) BN_free(a); - if (b != NULL) BN_free(b); - if (r != NULL) BN_free(r); - if (t != NULL) BN_free(t); - return ret; - } - -int test_sqrt(BIO *bp, BN_CTX *ctx) - { - BN_GENCB cb; - BIGNUM *a,*p,*r; - int i, j; - int ret = 0; - - a = BN_new(); - p = BN_new(); - r = BN_new(); - if (a == NULL || p == NULL || r == NULL) goto err; - - BN_GENCB_set(&cb, genprime_cb, NULL); - - for (i = 0; i < 16; i++) - { - if (i < 8) - { - unsigned primes[8] = { 2, 3, 5, 7, 11, 13, 17, 19 }; - - if (!BN_set_word(p, primes[i])) goto err; - } - else - { - if (!BN_set_word(a, 32)) goto err; - if (!BN_set_word(r, 2*i + 1)) goto err; - - if (!BN_generate_prime_ex(p, 256, 0, a, r, &cb)) goto err; - putc('\n', stderr); - } - p->neg = rand_neg(); - - for (j = 0; j < num2; j++) - { - /* construct 'a' such that it is a square modulo p, - * but in general not a proper square and not reduced modulo p */ - if (!BN_bntest_rand(r, 256, 0, 3)) goto err; - if (!BN_nnmod(r, r, p, ctx)) goto err; - if (!BN_mod_sqr(r, r, p, ctx)) goto err; - if (!BN_bntest_rand(a, 256, 0, 3)) goto err; - if (!BN_nnmod(a, a, p, ctx)) goto err; - if (!BN_mod_sqr(a, a, p, ctx)) goto err; - if (!BN_mul(a, a, r, ctx)) goto err; - if (rand_neg()) - if (!BN_sub(a, a, p)) goto err; - - if (!BN_mod_sqrt(r, a, p, ctx)) goto err; - if (!BN_mod_sqr(r, r, p, ctx)) goto err; - - if (!BN_nnmod(a, a, p, ctx)) goto err; - - if (BN_cmp(a, r) != 0) - { - fprintf(stderr, "BN_mod_sqrt failed: a = "); - BN_print_fp(stderr, a); - fprintf(stderr, ", r = "); - BN_print_fp(stderr, r); - fprintf(stderr, ", p = "); - BN_print_fp(stderr, p); - fprintf(stderr, "\n"); - goto err; - } - - putc('.', stderr); - fflush(stderr); - } - - putc('\n', stderr); - fflush(stderr); - } - ret = 1; - err: - if (a != NULL) BN_free(a); - if (p != NULL) BN_free(p); - if (r != NULL) BN_free(r); - return ret; - } - -int test_lshift(BIO *bp,BN_CTX *ctx,BIGNUM *a_) - { - BIGNUM *a,*b,*c,*d; - int i; - - b=BN_new(); - c=BN_new(); - d=BN_new(); - BN_one(c); - - if(a_) - a=a_; - else - { - a=BN_new(); - BN_bntest_rand(a,200,0,0); /**/ - a->neg=rand_neg(); - } - for (i=0; ineg=rand_neg(); - for (i=0; ineg=rand_neg(); - for (i=0; ineg=rand_neg(); - for (i=0; i -#include -#include - -#include "../e_os.h" - -#include -#include -#include -#include - -#define NUM_BITS (BN_BITS*2) - -static const char rnd_seed[] = "string to make the random number generator think it has entropy"; - -int main(int argc, char *argv[]) - { - BN_CTX *ctx; - BIO *out=NULL; - int i,ret; - unsigned char c; - BIGNUM *r_mont,*r_mont_const,*r_recp,*r_simple,*a,*b,*m; - - RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_rand may fail, and we don't - * even check its return value - * (which we should) */ - - ERR_load_BN_strings(); - - ctx=BN_CTX_new(); - if (ctx == NULL) EXIT(1); - r_mont=BN_new(); - r_mont_const=BN_new(); - r_recp=BN_new(); - r_simple=BN_new(); - a=BN_new(); - b=BN_new(); - m=BN_new(); - if ( (r_mont == NULL) || (r_recp == NULL) || - (a == NULL) || (b == NULL)) - goto err; - - out=BIO_new(BIO_s_file()); - - if (out == NULL) EXIT(1); - BIO_set_fp(out,stdout,BIO_NOCLOSE); - - for (i=0; i<200; i++) - { - RAND_bytes(&c,1); - c=(c%BN_BITS)-BN_BITS2; - BN_rand(a,NUM_BITS+c,0,0); - - RAND_bytes(&c,1); - c=(c%BN_BITS)-BN_BITS2; - BN_rand(b,NUM_BITS+c,0,0); - - RAND_bytes(&c,1); - c=(c%BN_BITS)-BN_BITS2; - BN_rand(m,NUM_BITS+c,0,1); - - BN_mod(a,a,m,ctx); - BN_mod(b,b,m,ctx); - - ret=BN_mod_exp_mont(r_mont,a,b,m,ctx,NULL); - if (ret <= 0) - { - printf("BN_mod_exp_mont() problems\n"); - ERR_print_errors(out); - EXIT(1); - } - - ret=BN_mod_exp_recp(r_recp,a,b,m,ctx); - if (ret <= 0) - { - printf("BN_mod_exp_recp() problems\n"); - ERR_print_errors(out); - EXIT(1); - } - - ret=BN_mod_exp_simple(r_simple,a,b,m,ctx); - if (ret <= 0) - { - printf("BN_mod_exp_simple() problems\n"); - ERR_print_errors(out); - EXIT(1); - } - - ret=BN_mod_exp_mont_consttime(r_mont_const,a,b,m,ctx,NULL); - if (ret <= 0) - { - printf("BN_mod_exp_mont_consttime() problems\n"); - ERR_print_errors(out); - EXIT(1); - } - - if (BN_cmp(r_simple, r_mont) == 0 - && BN_cmp(r_simple,r_recp) == 0 - && BN_cmp(r_simple,r_mont_const) == 0) - { - printf("."); - fflush(stdout); - } - else - { - if (BN_cmp(r_simple,r_mont) != 0) - printf("\nsimple and mont results differ\n"); - if (BN_cmp(r_simple,r_mont_const) != 0) - printf("\nsimple and mont const time results differ\n"); - if (BN_cmp(r_simple,r_recp) != 0) - printf("\nsimple and recp results differ\n"); - - printf("a (%3d) = ",BN_num_bits(a)); BN_print(out,a); - printf("\nb (%3d) = ",BN_num_bits(b)); BN_print(out,b); - printf("\nm (%3d) = ",BN_num_bits(m)); BN_print(out,m); - printf("\nsimple ="); BN_print(out,r_simple); - printf("\nrecp ="); BN_print(out,r_recp); - printf("\nmont ="); BN_print(out,r_mont); - printf("\nmont_ct ="); BN_print(out,r_mont_const); - printf("\n"); - EXIT(1); - } - } - BN_free(r_mont); - BN_free(r_mont_const); - BN_free(r_recp); - BN_free(r_simple); - BN_free(a); - BN_free(b); - BN_free(m); - BN_CTX_free(ctx); - ERR_remove_thread_state(NULL); - CRYPTO_mem_leaks(out); - BIO_free(out); - printf(" done\n"); - EXIT(0); -err: - ERR_load_crypto_strings(); - ERR_print_errors(out); -#ifdef OPENSSL_SYS_NETWARE - printf("ERROR\n"); -#endif - EXIT(1); - return(1); - } - diff --git a/src/lib/libcrypto/cast/casttest.c b/src/lib/libcrypto/cast/casttest.c deleted file mode 100644 index 0d020d6975..0000000000 --- a/src/lib/libcrypto/cast/casttest.c +++ /dev/null @@ -1,233 +0,0 @@ -/* crypto/cast/casttest.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include -#include -#include -#include /* To see if OPENSSL_NO_CAST is defined */ - -#include "../e_os.h" - -#ifdef OPENSSL_NO_CAST -int main(int argc, char *argv[]) -{ - printf("No CAST support\n"); - return(0); -} -#else -#include - -#define FULL_TEST - -static unsigned char k[16]={ - 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78, - 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A - }; - -static unsigned char in[8]={ 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}; - -static int k_len[3]={16,10,5}; -static unsigned char c[3][8]={ - {0x23,0x8B,0x4F,0xE5,0x84,0x7E,0x44,0xB2}, - {0xEB,0x6A,0x71,0x1A,0x2C,0x02,0x27,0x1B}, - {0x7A,0xC8,0x16,0xD1,0x6E,0x9B,0x30,0x2E}, - }; -static unsigned char out[80]; - -static unsigned char in_a[16]={ - 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78, - 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A}; -static unsigned char in_b[16]={ - 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78, - 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A}; - -static unsigned char c_a[16]={ - 0xEE,0xA9,0xD0,0xA2,0x49,0xFD,0x3B,0xA6, - 0xB3,0x43,0x6F,0xB8,0x9D,0x6D,0xCA,0x92}; -static unsigned char c_b[16]={ - 0xB2,0xC9,0x5E,0xB0,0x0C,0x31,0xAD,0x71, - 0x80,0xAC,0x05,0xB8,0xE8,0x3D,0x69,0x6E}; - -#if 0 -char *text="Hello to all people out there"; - -static unsigned char cfb_key[16]={ - 0xe1,0xf0,0xc3,0xd2,0xa5,0xb4,0x87,0x96, - 0x69,0x78,0x4b,0x5a,0x2d,0x3c,0x0f,0x1e, - }; -static unsigned char cfb_iv[80]={0x34,0x12,0x78,0x56,0xab,0x90,0xef,0xcd}; -static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8]; -#define CFB_TEST_SIZE 24 -static unsigned char plain[CFB_TEST_SIZE]= - { - 0x4e,0x6f,0x77,0x20,0x69,0x73, - 0x20,0x74,0x68,0x65,0x20,0x74, - 0x69,0x6d,0x65,0x20,0x66,0x6f, - 0x72,0x20,0x61,0x6c,0x6c,0x20 - }; -static unsigned char cfb_cipher64[CFB_TEST_SIZE]={ - 0x59,0xD8,0xE2,0x65,0x00,0x58,0x6C,0x3F, - 0x2C,0x17,0x25,0xD0,0x1A,0x38,0xB7,0x2A, - 0x39,0x61,0x37,0xDC,0x79,0xFB,0x9F,0x45 - -/* 0xF9,0x78,0x32,0xB5,0x42,0x1A,0x6B,0x38, - 0x9A,0x44,0xD6,0x04,0x19,0x43,0xC4,0xD9, - 0x3D,0x1E,0xAE,0x47,0xFC,0xCF,0x29,0x0B,*/ - }; -#endif - -int main(int argc, char *argv[]) - { -#ifdef FULL_TEST - long l; - CAST_KEY key_b; -#endif - int i,z,err=0; - CAST_KEY key; - - for (z=0; z<3; z++) - { - CAST_set_key(&key,k_len[z],k); - - CAST_ecb_encrypt(in,out,&key,CAST_ENCRYPT); - if (memcmp(out,&(c[z][0]),8) != 0) - { - printf("ecb cast error encrypting for keysize %d\n",k_len[z]*8); - printf("got :"); - for (i=0; i<8; i++) - printf("%02X ",out[i]); - printf("\n"); - printf("expected:"); - for (i=0; i<8; i++) - printf("%02X ",c[z][i]); - err=20; - printf("\n"); - } - - CAST_ecb_encrypt(out,out,&key,CAST_DECRYPT); - if (memcmp(out,in,8) != 0) - { - printf("ecb cast error decrypting for keysize %d\n",k_len[z]*8); - printf("got :"); - for (i=0; i<8; i++) - printf("%02X ",out[i]); - printf("\n"); - printf("expected:"); - for (i=0; i<8; i++) - printf("%02X ",in[i]); - printf("\n"); - err=3; - } - } - if (err == 0) - printf("ecb cast5 ok\n"); - -#ifdef FULL_TEST - { - unsigned char out_a[16],out_b[16]; - static char *hex="0123456789ABCDEF"; - - printf("This test will take some time...."); - fflush(stdout); - memcpy(out_a,in_a,sizeof(in_a)); - memcpy(out_b,in_b,sizeof(in_b)); - i=1; - - for (l=0; l<1000000L; l++) - { - CAST_set_key(&key_b,16,out_b); - CAST_ecb_encrypt(&(out_a[0]),&(out_a[0]),&key_b,CAST_ENCRYPT); - CAST_ecb_encrypt(&(out_a[8]),&(out_a[8]),&key_b,CAST_ENCRYPT); - CAST_set_key(&key,16,out_a); - CAST_ecb_encrypt(&(out_b[0]),&(out_b[0]),&key,CAST_ENCRYPT); - CAST_ecb_encrypt(&(out_b[8]),&(out_b[8]),&key,CAST_ENCRYPT); - if ((l & 0xffff) == 0xffff) - { - printf("%c",hex[i&0x0f]); - fflush(stdout); - i++; - } - } - - if ( (memcmp(out_a,c_a,sizeof(c_a)) != 0) || - (memcmp(out_b,c_b,sizeof(c_b)) != 0)) - { - printf("\n"); - printf("Error\n"); - - printf("A out ="); - for (i=0; i<16; i++) printf("%02X ",out_a[i]); - printf("\nactual="); - for (i=0; i<16; i++) printf("%02X ",c_a[i]); - printf("\n"); - - printf("B out ="); - for (i=0; i<16; i++) printf("%02X ",out_b[i]); - printf("\nactual="); - for (i=0; i<16; i++) printf("%02X ",c_b[i]); - printf("\n"); - } - else - printf(" ok\n"); - } -#endif - - EXIT(err); - return(err); - } -#endif diff --git a/src/lib/libcrypto/des/destest.c b/src/lib/libcrypto/des/destest.c deleted file mode 100644 index 64b92a34fe..0000000000 --- a/src/lib/libcrypto/des/destest.c +++ /dev/null @@ -1,952 +0,0 @@ -/* crypto/des/destest.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include -#include - -#include -#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_SYS_WINDOWS) -#ifndef OPENSSL_SYS_MSDOS -#define OPENSSL_SYS_MSDOS -#endif -#endif - -#ifndef OPENSSL_SYS_MSDOS -#if !defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_VMS_DECC) -#include OPENSSL_UNISTD -#endif -#else -#include -#endif -#include - -#ifdef OPENSSL_NO_DES -int main(int argc, char *argv[]) -{ - printf("No DES support\n"); - return(0); -} -#else -#include - -#define crypt(c,s) (DES_crypt((c),(s))) - -/* tisk tisk - the test keys don't all have odd parity :-( */ -/* test data */ -#define NUM_TESTS 34 -static unsigned char key_data[NUM_TESTS][8]={ - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, - {0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}, - {0x7C,0xA1,0x10,0x45,0x4A,0x1A,0x6E,0x57}, - {0x01,0x31,0xD9,0x61,0x9D,0xC1,0x37,0x6E}, - {0x07,0xA1,0x13,0x3E,0x4A,0x0B,0x26,0x86}, - {0x38,0x49,0x67,0x4C,0x26,0x02,0x31,0x9E}, - {0x04,0xB9,0x15,0xBA,0x43,0xFE,0xB5,0xB6}, - {0x01,0x13,0xB9,0x70,0xFD,0x34,0xF2,0xCE}, - {0x01,0x70,0xF1,0x75,0x46,0x8F,0xB5,0xE6}, - {0x43,0x29,0x7F,0xAD,0x38,0xE3,0x73,0xFE}, - {0x07,0xA7,0x13,0x70,0x45,0xDA,0x2A,0x16}, - {0x04,0x68,0x91,0x04,0xC2,0xFD,0x3B,0x2F}, - {0x37,0xD0,0x6B,0xB5,0x16,0xCB,0x75,0x46}, - {0x1F,0x08,0x26,0x0D,0x1A,0xC2,0x46,0x5E}, - {0x58,0x40,0x23,0x64,0x1A,0xBA,0x61,0x76}, - {0x02,0x58,0x16,0x16,0x46,0x29,0xB0,0x07}, - {0x49,0x79,0x3E,0xBC,0x79,0xB3,0x25,0x8F}, - {0x4F,0xB0,0x5E,0x15,0x15,0xAB,0x73,0xA7}, - {0x49,0xE9,0x5D,0x6D,0x4C,0xA2,0x29,0xBF}, - {0x01,0x83,0x10,0xDC,0x40,0x9B,0x26,0xD6}, - {0x1C,0x58,0x7F,0x1C,0x13,0x92,0x4F,0xEF}, - {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01}, - {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E}, - {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}}; - -static unsigned char plain_data[NUM_TESTS][8]={ - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, - {0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01}, - {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, - {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0x01,0xA1,0xD6,0xD0,0x39,0x77,0x67,0x42}, - {0x5C,0xD5,0x4C,0xA8,0x3D,0xEF,0x57,0xDA}, - {0x02,0x48,0xD4,0x38,0x06,0xF6,0x71,0x72}, - {0x51,0x45,0x4B,0x58,0x2D,0xDF,0x44,0x0A}, - {0x42,0xFD,0x44,0x30,0x59,0x57,0x7F,0xA2}, - {0x05,0x9B,0x5E,0x08,0x51,0xCF,0x14,0x3A}, - {0x07,0x56,0xD8,0xE0,0x77,0x47,0x61,0xD2}, - {0x76,0x25,0x14,0xB8,0x29,0xBF,0x48,0x6A}, - {0x3B,0xDD,0x11,0x90,0x49,0x37,0x28,0x02}, - {0x26,0x95,0x5F,0x68,0x35,0xAF,0x60,0x9A}, - {0x16,0x4D,0x5E,0x40,0x4F,0x27,0x52,0x32}, - {0x6B,0x05,0x6E,0x18,0x75,0x9F,0x5C,0xCA}, - {0x00,0x4B,0xD6,0xEF,0x09,0x17,0x60,0x62}, - {0x48,0x0D,0x39,0x00,0x6E,0xE7,0x62,0xF2}, - {0x43,0x75,0x40,0xC8,0x69,0x8F,0x3C,0xFA}, - {0x07,0x2D,0x43,0xA0,0x77,0x07,0x52,0x92}, - {0x02,0xFE,0x55,0x77,0x81,0x17,0xF1,0x2A}, - {0x1D,0x9D,0x5C,0x50,0x18,0xF7,0x28,0xC2}, - {0x30,0x55,0x32,0x28,0x6D,0x6F,0x29,0x5A}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}; - -static unsigned char cipher_data[NUM_TESTS][8]={ - {0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7}, - {0x73,0x59,0xB2,0x16,0x3E,0x4E,0xDC,0x58}, - {0x95,0x8E,0x6E,0x62,0x7A,0x05,0x55,0x7B}, - {0xF4,0x03,0x79,0xAB,0x9E,0x0E,0xC5,0x33}, - {0x17,0x66,0x8D,0xFC,0x72,0x92,0x53,0x2D}, - {0x8A,0x5A,0xE1,0xF8,0x1A,0xB8,0xF2,0xDD}, - {0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7}, - {0xED,0x39,0xD9,0x50,0xFA,0x74,0xBC,0xC4}, - {0x69,0x0F,0x5B,0x0D,0x9A,0x26,0x93,0x9B}, - {0x7A,0x38,0x9D,0x10,0x35,0x4B,0xD2,0x71}, - {0x86,0x8E,0xBB,0x51,0xCA,0xB4,0x59,0x9A}, - {0x71,0x78,0x87,0x6E,0x01,0xF1,0x9B,0x2A}, - {0xAF,0x37,0xFB,0x42,0x1F,0x8C,0x40,0x95}, - {0x86,0xA5,0x60,0xF1,0x0E,0xC6,0xD8,0x5B}, - {0x0C,0xD3,0xDA,0x02,0x00,0x21,0xDC,0x09}, - {0xEA,0x67,0x6B,0x2C,0xB7,0xDB,0x2B,0x7A}, - {0xDF,0xD6,0x4A,0x81,0x5C,0xAF,0x1A,0x0F}, - {0x5C,0x51,0x3C,0x9C,0x48,0x86,0xC0,0x88}, - {0x0A,0x2A,0xEE,0xAE,0x3F,0xF4,0xAB,0x77}, - {0xEF,0x1B,0xF0,0x3E,0x5D,0xFA,0x57,0x5A}, - {0x88,0xBF,0x0D,0xB6,0xD7,0x0D,0xEE,0x56}, - {0xA1,0xF9,0x91,0x55,0x41,0x02,0x0B,0x56}, - {0x6F,0xBF,0x1C,0xAF,0xCF,0xFD,0x05,0x56}, - {0x2F,0x22,0xE4,0x9B,0xAB,0x7C,0xA1,0xAC}, - {0x5A,0x6B,0x61,0x2C,0xC2,0x6C,0xCE,0x4A}, - {0x5F,0x4C,0x03,0x8E,0xD1,0x2B,0x2E,0x41}, - {0x63,0xFA,0xC0,0xD0,0x34,0xD9,0xF7,0x93}, - {0x61,0x7B,0x3A,0x0C,0xE8,0xF0,0x71,0x00}, - {0xDB,0x95,0x86,0x05,0xF8,0xC8,0xC6,0x06}, - {0xED,0xBF,0xD1,0xC6,0x6C,0x29,0xCC,0xC7}, - {0x35,0x55,0x50,0xB2,0x15,0x0E,0x24,0x51}, - {0xCA,0xAA,0xAF,0x4D,0xEA,0xF1,0xDB,0xAE}, - {0xD5,0xD4,0x4F,0xF7,0x20,0x68,0x3D,0x0D}, - {0x2A,0x2B,0xB0,0x08,0xDF,0x97,0xC2,0xF2}}; - -static unsigned char cipher_ecb2[NUM_TESTS-1][8]={ - {0x92,0x95,0xB5,0x9B,0xB3,0x84,0x73,0x6E}, - {0x19,0x9E,0x9D,0x6D,0xF3,0x9A,0xA8,0x16}, - {0x2A,0x4B,0x4D,0x24,0x52,0x43,0x84,0x27}, - {0x35,0x84,0x3C,0x01,0x9D,0x18,0xC5,0xB6}, - {0x4A,0x5B,0x2F,0x42,0xAA,0x77,0x19,0x25}, - {0xA0,0x6B,0xA9,0xB8,0xCA,0x5B,0x17,0x8A}, - {0xAB,0x9D,0xB7,0xFB,0xED,0x95,0xF2,0x74}, - {0x3D,0x25,0x6C,0x23,0xA7,0x25,0x2F,0xD6}, - {0xB7,0x6F,0xAB,0x4F,0xBD,0xBD,0xB7,0x67}, - {0x8F,0x68,0x27,0xD6,0x9C,0xF4,0x1A,0x10}, - {0x82,0x57,0xA1,0xD6,0x50,0x5E,0x81,0x85}, - {0xA2,0x0F,0x0A,0xCD,0x80,0x89,0x7D,0xFA}, - {0xCD,0x2A,0x53,0x3A,0xDB,0x0D,0x7E,0xF3}, - {0xD2,0xC2,0xBE,0x27,0xE8,0x1B,0x68,0xE3}, - {0xE9,0x24,0xCF,0x4F,0x89,0x3C,0x5B,0x0A}, - {0xA7,0x18,0xC3,0x9F,0xFA,0x9F,0xD7,0x69}, - {0x77,0x2C,0x79,0xB1,0xD2,0x31,0x7E,0xB1}, - {0x49,0xAB,0x92,0x7F,0xD0,0x22,0x00,0xB7}, - {0xCE,0x1C,0x6C,0x7D,0x85,0xE3,0x4A,0x6F}, - {0xBE,0x91,0xD6,0xE1,0x27,0xB2,0xE9,0x87}, - {0x70,0x28,0xAE,0x8F,0xD1,0xF5,0x74,0x1A}, - {0xAA,0x37,0x80,0xBB,0xF3,0x22,0x1D,0xDE}, - {0xA6,0xC4,0xD2,0x5E,0x28,0x93,0xAC,0xB3}, - {0x22,0x07,0x81,0x5A,0xE4,0xB7,0x1A,0xAD}, - {0xDC,0xCE,0x05,0xE7,0x07,0xBD,0xF5,0x84}, - {0x26,0x1D,0x39,0x2C,0xB3,0xBA,0xA5,0x85}, - {0xB4,0xF7,0x0F,0x72,0xFB,0x04,0xF0,0xDC}, - {0x95,0xBA,0xA9,0x4E,0x87,0x36,0xF2,0x89}, - {0xD4,0x07,0x3A,0xF1,0x5A,0x17,0x82,0x0E}, - {0xEF,0x6F,0xAF,0xA7,0x66,0x1A,0x7E,0x89}, - {0xC1,0x97,0xF5,0x58,0x74,0x8A,0x20,0xE7}, - {0x43,0x34,0xCF,0xDA,0x22,0xC4,0x86,0xC8}, - {0x08,0xD7,0xB4,0xFB,0x62,0x9D,0x08,0x85}}; - -static unsigned char cbc_key [8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}; -static unsigned char cbc2_key[8]={0xf1,0xe0,0xd3,0xc2,0xb5,0xa4,0x97,0x86}; -static unsigned char cbc3_key[8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; -static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; -/* Changed the following text constant to binary so it will work on ebcdic - * machines :-) */ -/* static char cbc_data[40]="7654321 Now is the time for \0001"; */ -static unsigned char cbc_data[40]={ - 0x37,0x36,0x35,0x34,0x33,0x32,0x31,0x20, - 0x4E,0x6F,0x77,0x20,0x69,0x73,0x20,0x74, - 0x68,0x65,0x20,0x74,0x69,0x6D,0x65,0x20, - 0x66,0x6F,0x72,0x20,0x00,0x31,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - }; - -static unsigned char cbc_ok[32]={ - 0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4, - 0xac,0xd8,0xae,0xfd,0xdf,0xd8,0xa1,0xeb, - 0x46,0x8e,0x91,0x15,0x78,0x88,0xba,0x68, - 0x1d,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4}; - -#ifdef SCREW_THE_PARITY -#error "SCREW_THE_PARITY is not ment to be defined." -#error "Original vectors are preserved for reference only." -static unsigned char cbc2_key[8]={0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87}; -static unsigned char xcbc_ok[32]={ - 0x86,0x74,0x81,0x0D,0x61,0xA4,0xA5,0x48, - 0xB9,0x93,0x03,0xE1,0xB8,0xBB,0xBD,0xBD, - 0x64,0x30,0x0B,0xB9,0x06,0x65,0x81,0x76, - 0x04,0x1D,0x77,0x62,0x17,0xCA,0x2B,0xD2, - }; -#else -static unsigned char xcbc_ok[32]={ - 0x84,0x6B,0x29,0x14,0x85,0x1E,0x9A,0x29, - 0x54,0x73,0x2F,0x8A,0xA0,0xA6,0x11,0xC1, - 0x15,0xCD,0xC2,0xD7,0x95,0x1B,0x10,0x53, - 0xA6,0x3C,0x5E,0x03,0xB2,0x1A,0xA3,0xC4, - }; -#endif - -static unsigned char cbc3_ok[32]={ - 0x3F,0xE3,0x01,0xC9,0x62,0xAC,0x01,0xD0, - 0x22,0x13,0x76,0x3C,0x1C,0xBD,0x4C,0xDC, - 0x79,0x96,0x57,0xC0,0x64,0xEC,0xF5,0xD4, - 0x1C,0x67,0x38,0x12,0xCF,0xDE,0x96,0x75}; - -static unsigned char pcbc_ok[32]={ - 0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4, - 0x6d,0xec,0xb4,0x70,0xa0,0xe5,0x6b,0x15, - 0xae,0xa6,0xbf,0x61,0xed,0x7d,0x9c,0x9f, - 0xf7,0x17,0x46,0x3b,0x8a,0xb3,0xcc,0x88}; - -static unsigned char cfb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}; -static unsigned char cfb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef}; -static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8]; -static unsigned char plain[24]= - { - 0x4e,0x6f,0x77,0x20,0x69,0x73, - 0x20,0x74,0x68,0x65,0x20,0x74, - 0x69,0x6d,0x65,0x20,0x66,0x6f, - 0x72,0x20,0x61,0x6c,0x6c,0x20 - }; -static unsigned char cfb_cipher8[24]= { - 0xf3,0x1f,0xda,0x07,0x01,0x14, 0x62,0xee,0x18,0x7f,0x43,0xd8, - 0x0a,0x7c,0xd9,0xb5,0xb0,0xd2, 0x90,0xda,0x6e,0x5b,0x9a,0x87 }; -static unsigned char cfb_cipher16[24]={ - 0xF3,0x09,0x87,0x87,0x7F,0x57, 0xF7,0x3C,0x36,0xB6,0xDB,0x70, - 0xD8,0xD5,0x34,0x19,0xD3,0x86, 0xB2,0x23,0xB7,0xB2,0xAD,0x1B }; -static unsigned char cfb_cipher32[24]={ - 0xF3,0x09,0x62,0x49,0xA4,0xDF, 0xA4,0x9F,0x33,0xDC,0x7B,0xAD, - 0x4C,0xC8,0x9F,0x64,0xE4,0x53, 0xE5,0xEC,0x67,0x20,0xDA,0xB6 }; -static unsigned char cfb_cipher48[24]={ - 0xF3,0x09,0x62,0x49,0xC7,0xF4, 0x30,0xB5,0x15,0xEC,0xBB,0x85, - 0x97,0x5A,0x13,0x8C,0x68,0x60, 0xE2,0x38,0x34,0x3C,0xDC,0x1F }; -static unsigned char cfb_cipher64[24]={ - 0xF3,0x09,0x62,0x49,0xC7,0xF4, 0x6E,0x51,0xA6,0x9E,0x83,0x9B, - 0x1A,0x92,0xF7,0x84,0x03,0x46, 0x71,0x33,0x89,0x8E,0xA6,0x22 }; - -static unsigned char ofb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}; -static unsigned char ofb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef}; -static unsigned char ofb_buf1[24],ofb_buf2[24],ofb_tmp[8]; -static unsigned char ofb_cipher[24]= - { - 0xf3,0x09,0x62,0x49,0xc7,0xf4,0x6e,0x51, - 0x35,0xf2,0x4a,0x24,0x2e,0xeb,0x3d,0x3f, - 0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3 - }; - -#if 0 -static DES_LONG cbc_cksum_ret=0xB462FEF7L; -#else -static DES_LONG cbc_cksum_ret=0xF7FE62B4L; -#endif -static unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4}; - -static char *pt(unsigned char *p); -static int cfb_test(int bits, unsigned char *cfb_cipher); -static int cfb64_test(unsigned char *cfb_cipher); -static int ede_cfb64_test(unsigned char *cfb_cipher); -int main(int argc, char *argv[]) - { - int j,err=0; - unsigned int i; - des_cblock in,out,outin,iv3,iv2; - des_key_schedule ks,ks2,ks3; - unsigned char cbc_in[40]; - unsigned char cbc_out[40]; - DES_LONG cs; - unsigned char cret[8]; -#ifdef _CRAY - struct { - int a:32; - int b:32; - } lqret[2]; -#else - DES_LONG lqret[4]; -#endif - int num; - char *str; - -#ifndef OPENSSL_NO_DESCBCM - printf("Doing cbcm\n"); - if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0) - { - printf("Key error %d\n",j); - err=1; - } - if ((j=DES_set_key_checked(&cbc2_key,&ks2)) != 0) - { - printf("Key error %d\n",j); - err=1; - } - if ((j=DES_set_key_checked(&cbc3_key,&ks3)) != 0) - { - printf("Key error %d\n",j); - err=1; - } - memset(cbc_out,0,40); - memset(cbc_in,0,40); - i=strlen((char *)cbc_data)+1; - /* i=((i+7)/8)*8; */ - memcpy(iv3,cbc_iv,sizeof(cbc_iv)); - memset(iv2,'\0',sizeof iv2); - - DES_ede3_cbcm_encrypt(cbc_data,cbc_out,16L,&ks,&ks2,&ks3,&iv3,&iv2, - DES_ENCRYPT); - DES_ede3_cbcm_encrypt(&cbc_data[16],&cbc_out[16],i-16,&ks,&ks2,&ks3, - &iv3,&iv2,DES_ENCRYPT); - /* if (memcmp(cbc_out,cbc3_ok, - (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0) - { - printf("des_ede3_cbc_encrypt encrypt error\n"); - err=1; - } - */ - memcpy(iv3,cbc_iv,sizeof(cbc_iv)); - memset(iv2,'\0',sizeof iv2); - DES_ede3_cbcm_encrypt(cbc_out,cbc_in,i,&ks,&ks2,&ks3,&iv3,&iv2,DES_DECRYPT); - if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0) - { - unsigned int n; - - printf("des_ede3_cbcm_encrypt decrypt error\n"); - for(n=0 ; n < i ; ++n) - printf(" %02x",cbc_data[n]); - printf("\n"); - for(n=0 ; n < i ; ++n) - printf(" %02x",cbc_in[n]); - printf("\n"); - err=1; - } -#endif - - printf("Doing ecb\n"); - for (i=0; i>4)&0xf]; - ret[i*2+1]=f[p[i]&0xf]; - } - ret[16]='\0'; - return(ret); - } - -#ifndef LIBDES_LIT - -static int cfb_test(int bits, unsigned char *cfb_cipher) - { - des_key_schedule ks; - int i,err=0; - - DES_set_key_checked(&cfb_key,&ks); - memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); - des_cfb_encrypt(plain,cfb_buf1,bits,sizeof(plain),ks,&cfb_tmp, - DES_ENCRYPT); - if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) - { - err=1; - printf("cfb_encrypt encrypt error\n"); - for (i=0; i<24; i+=8) - printf("%s\n",pt(&(cfb_buf1[i]))); - } - memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); - des_cfb_encrypt(cfb_buf1,cfb_buf2,bits,sizeof(plain),ks,&cfb_tmp, - DES_DECRYPT); - if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) - { - err=1; - printf("cfb_encrypt decrypt error\n"); - for (i=0; i<24; i+=8) - printf("%s\n",pt(&(cfb_buf1[i]))); - } - return(err); - } - -static int cfb64_test(unsigned char *cfb_cipher) - { - des_key_schedule ks; - int err=0,i,n; - - DES_set_key_checked(&cfb_key,&ks); - memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); - n=0; - des_cfb64_encrypt(plain,cfb_buf1,12,ks,&cfb_tmp,&n,DES_ENCRYPT); - des_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),sizeof(plain)-12,ks, - &cfb_tmp,&n,DES_ENCRYPT); - if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) - { - err=1; - printf("cfb_encrypt encrypt error\n"); - for (i=0; i<24; i+=8) - printf("%s\n",pt(&(cfb_buf1[i]))); - } - memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); - n=0; - des_cfb64_encrypt(cfb_buf1,cfb_buf2,17,ks,&cfb_tmp,&n,DES_DECRYPT); - des_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]), - sizeof(plain)-17,ks,&cfb_tmp,&n,DES_DECRYPT); - if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) - { - err=1; - printf("cfb_encrypt decrypt error\n"); - for (i=0; i<24; i+=8) - printf("%s\n",pt(&(cfb_buf2[i]))); - } - return(err); - } - -static int ede_cfb64_test(unsigned char *cfb_cipher) - { - des_key_schedule ks; - int err=0,i,n; - - DES_set_key_checked(&cfb_key,&ks); - memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); - n=0; - des_ede3_cfb64_encrypt(plain,cfb_buf1,12,ks,ks,ks,&cfb_tmp,&n, - DES_ENCRYPT); - des_ede3_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]), - sizeof(plain)-12,ks,ks,ks, - &cfb_tmp,&n,DES_ENCRYPT); - if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) - { - err=1; - printf("ede_cfb_encrypt encrypt error\n"); - for (i=0; i<24; i+=8) - printf("%s\n",pt(&(cfb_buf1[i]))); - } - memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); - n=0; - des_ede3_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks,ks,ks, - &cfb_tmp,&n,DES_DECRYPT); - des_ede3_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]), - sizeof(plain)-17,ks,ks,ks, - &cfb_tmp,&n,DES_DECRYPT); - if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) - { - err=1; - printf("ede_cfb_encrypt decrypt error\n"); - for (i=0; i<24; i+=8) - printf("%s\n",pt(&(cfb_buf2[i]))); - } - return(err); - } - -#endif -#endif diff --git a/src/lib/libcrypto/dh/dhtest.c b/src/lib/libcrypto/dh/dhtest.c deleted file mode 100644 index 882f5c310a..0000000000 --- a/src/lib/libcrypto/dh/dhtest.c +++ /dev/null @@ -1,226 +0,0 @@ -/* crypto/dh/dhtest.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.] - */ - -/* Until the key-gen callbacks are modified to use newer prototypes, we allow - * deprecated functions for openssl-internal code */ -#ifdef OPENSSL_NO_DEPRECATED -#undef OPENSSL_NO_DEPRECATED -#endif - -#include -#include -#include - -#include "../e_os.h" - -#include -#include -#include -#include -#include - -#ifdef OPENSSL_NO_DH -int main(int argc, char *argv[]) -{ - printf("No DH support\n"); - return(0); -} -#else -#include - -#ifdef OPENSSL_SYS_WIN16 -#define MS_CALLBACK _far _loadds -#else -#define MS_CALLBACK -#endif - -static int MS_CALLBACK cb(int p, int n, BN_GENCB *arg); - -static const char rnd_seed[] = "string to make the random number generator think it has entropy"; - -int main(int argc, char *argv[]) - { - BN_GENCB _cb; - DH *a; - DH *b=NULL; - char buf[12]; - unsigned char *abuf=NULL,*bbuf=NULL; - int i,alen,blen,aout,bout,ret=1; - BIO *out; - - CRYPTO_malloc_debug_init(); - CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL); - CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); - -#ifdef OPENSSL_SYS_WIN32 - CRYPTO_malloc_init(); -#endif - - RAND_seed(rnd_seed, sizeof rnd_seed); - - out=BIO_new(BIO_s_file()); - if (out == NULL) EXIT(1); - BIO_set_fp(out,stdout,BIO_NOCLOSE); - - BN_GENCB_set(&_cb, &cb, out); - if(((a = DH_new()) == NULL) || !DH_generate_parameters_ex(a, 64, - DH_GENERATOR_5, &_cb)) - goto err; - - if (!DH_check(a, &i)) goto err; - if (i & DH_CHECK_P_NOT_PRIME) - BIO_puts(out, "p value is not prime\n"); - if (i & DH_CHECK_P_NOT_SAFE_PRIME) - BIO_puts(out, "p value is not a safe prime\n"); - if (i & DH_UNABLE_TO_CHECK_GENERATOR) - BIO_puts(out, "unable to check the generator value\n"); - if (i & DH_NOT_SUITABLE_GENERATOR) - BIO_puts(out, "the g value is not a generator\n"); - - BIO_puts(out,"\np ="); - BN_print(out,a->p); - BIO_puts(out,"\ng ="); - BN_print(out,a->g); - BIO_puts(out,"\n"); - - b=DH_new(); - if (b == NULL) goto err; - - b->p=BN_dup(a->p); - b->g=BN_dup(a->g); - if ((b->p == NULL) || (b->g == NULL)) goto err; - - /* Set a to run with normal modexp and b to use constant time */ - a->flags &= ~DH_FLAG_NO_EXP_CONSTTIME; - b->flags |= DH_FLAG_NO_EXP_CONSTTIME; - - if (!DH_generate_key(a)) goto err; - BIO_puts(out,"pri 1="); - BN_print(out,a->priv_key); - BIO_puts(out,"\npub 1="); - BN_print(out,a->pub_key); - BIO_puts(out,"\n"); - - if (!DH_generate_key(b)) goto err; - BIO_puts(out,"pri 2="); - BN_print(out,b->priv_key); - BIO_puts(out,"\npub 2="); - BN_print(out,b->pub_key); - BIO_puts(out,"\n"); - - alen=DH_size(a); - abuf=(unsigned char *)OPENSSL_malloc(alen); - aout=DH_compute_key(abuf,b->pub_key,a); - - BIO_puts(out,"key1 ="); - for (i=0; ipub_key,b); - - BIO_puts(out,"key2 ="); - for (i=0; iarg,&c,1); - (void)BIO_flush(arg->arg); -#ifdef LINT - p=n; -#endif - return 1; - } -#endif diff --git a/src/lib/libcrypto/dsa/dsatest.c b/src/lib/libcrypto/dsa/dsatest.c deleted file mode 100644 index edffd24e6b..0000000000 --- a/src/lib/libcrypto/dsa/dsatest.c +++ /dev/null @@ -1,259 +0,0 @@ -/* crypto/dsa/dsatest.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.] - */ - -/* Until the key-gen callbacks are modified to use newer prototypes, we allow - * deprecated functions for openssl-internal code */ -#ifdef OPENSSL_NO_DEPRECATED -#undef OPENSSL_NO_DEPRECATED -#endif - -#include -#include -#include -#include -#include - -#include "../e_os.h" - -#include -#include -#include -#include -#include - -#ifdef OPENSSL_NO_DSA -int main(int argc, char *argv[]) -{ - printf("No DSA support\n"); - return(0); -} -#else -#include - -#ifdef OPENSSL_SYS_WIN16 -#define MS_CALLBACK _far _loadds -#else -#define MS_CALLBACK -#endif - -static int MS_CALLBACK dsa_cb(int p, int n, BN_GENCB *arg); - -/* seed, out_p, out_q, out_g are taken from the updated Appendix 5 to - * FIPS PUB 186 and also appear in Appendix 5 to FIPS PIB 186-1 */ -static unsigned char seed[20]={ - 0xd5,0x01,0x4e,0x4b,0x60,0xef,0x2b,0xa8,0xb6,0x21,0x1b,0x40, - 0x62,0xba,0x32,0x24,0xe0,0x42,0x7d,0xd3, - }; - -static unsigned char out_p[]={ - 0x8d,0xf2,0xa4,0x94,0x49,0x22,0x76,0xaa, - 0x3d,0x25,0x75,0x9b,0xb0,0x68,0x69,0xcb, - 0xea,0xc0,0xd8,0x3a,0xfb,0x8d,0x0c,0xf7, - 0xcb,0xb8,0x32,0x4f,0x0d,0x78,0x82,0xe5, - 0xd0,0x76,0x2f,0xc5,0xb7,0x21,0x0e,0xaf, - 0xc2,0xe9,0xad,0xac,0x32,0xab,0x7a,0xac, - 0x49,0x69,0x3d,0xfb,0xf8,0x37,0x24,0xc2, - 0xec,0x07,0x36,0xee,0x31,0xc8,0x02,0x91, - }; - -static unsigned char out_q[]={ - 0xc7,0x73,0x21,0x8c,0x73,0x7e,0xc8,0xee, - 0x99,0x3b,0x4f,0x2d,0xed,0x30,0xf4,0x8e, - 0xda,0xce,0x91,0x5f, - }; - -static unsigned char out_g[]={ - 0x62,0x6d,0x02,0x78,0x39,0xea,0x0a,0x13, - 0x41,0x31,0x63,0xa5,0x5b,0x4c,0xb5,0x00, - 0x29,0x9d,0x55,0x22,0x95,0x6c,0xef,0xcb, - 0x3b,0xff,0x10,0xf3,0x99,0xce,0x2c,0x2e, - 0x71,0xcb,0x9d,0xe5,0xfa,0x24,0xba,0xbf, - 0x58,0xe5,0xb7,0x95,0x21,0x92,0x5c,0x9c, - 0xc4,0x2e,0x9f,0x6f,0x46,0x4b,0x08,0x8c, - 0xc5,0x72,0xaf,0x53,0xe6,0xd7,0x88,0x02, - }; - -static const unsigned char str1[]="12345678901234567890"; - -static const char rnd_seed[] = "string to make the random number generator think it has entropy"; - -static BIO *bio_err=NULL; - -int main(int argc, char **argv) - { - BN_GENCB cb; - DSA *dsa=NULL; - int counter,ret=0,i,j; - unsigned char buf[256]; - unsigned long h; - unsigned char sig[256]; - unsigned int siglen; - - if (bio_err == NULL) - bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); - - CRYPTO_malloc_debug_init(); - CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL); - CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); - - ERR_load_crypto_strings(); - RAND_seed(rnd_seed, sizeof rnd_seed); - - BIO_printf(bio_err,"test generation of DSA parameters\n"); - - BN_GENCB_set(&cb, dsa_cb, bio_err); - if(((dsa = DSA_new()) == NULL) || !DSA_generate_parameters_ex(dsa, 512, - seed, 20, &counter, &h, &cb)) - goto end; - - BIO_printf(bio_err,"seed\n"); - for (i=0; i<20; i+=4) - { - BIO_printf(bio_err,"%02X%02X%02X%02X ", - seed[i],seed[i+1],seed[i+2],seed[i+3]); - } - BIO_printf(bio_err,"\ncounter=%d h=%ld\n",counter,h); - - DSA_print(bio_err,dsa,0); - if (counter != 105) - { - BIO_printf(bio_err,"counter should be 105\n"); - goto end; - } - if (h != 2) - { - BIO_printf(bio_err,"h should be 2\n"); - goto end; - } - - i=BN_bn2bin(dsa->q,buf); - j=sizeof(out_q); - if ((i != j) || (memcmp(buf,out_q,i) != 0)) - { - BIO_printf(bio_err,"q value is wrong\n"); - goto end; - } - - i=BN_bn2bin(dsa->p,buf); - j=sizeof(out_p); - if ((i != j) || (memcmp(buf,out_p,i) != 0)) - { - BIO_printf(bio_err,"p value is wrong\n"); - goto end; - } - - i=BN_bn2bin(dsa->g,buf); - j=sizeof(out_g); - if ((i != j) || (memcmp(buf,out_g,i) != 0)) - { - BIO_printf(bio_err,"g value is wrong\n"); - goto end; - } - - dsa->flags |= DSA_FLAG_NO_EXP_CONSTTIME; - DSA_generate_key(dsa); - DSA_sign(0, str1, 20, sig, &siglen, dsa); - if (DSA_verify(0, str1, 20, sig, siglen, dsa) == 1) - ret=1; - - dsa->flags &= ~DSA_FLAG_NO_EXP_CONSTTIME; - DSA_generate_key(dsa); - DSA_sign(0, str1, 20, sig, &siglen, dsa); - if (DSA_verify(0, str1, 20, sig, siglen, dsa) == 1) - ret=1; - -end: - if (!ret) - ERR_print_errors(bio_err); - if (dsa != NULL) DSA_free(dsa); - CRYPTO_cleanup_all_ex_data(); - ERR_remove_thread_state(NULL); - ERR_free_strings(); - CRYPTO_mem_leaks(bio_err); - if (bio_err != NULL) - { - BIO_free(bio_err); - bio_err = NULL; - } -#ifdef OPENSSL_SYS_NETWARE - if (!ret) printf("ERROR\n"); -#endif - EXIT(!ret); - return(0); - } - -static int MS_CALLBACK dsa_cb(int p, int n, BN_GENCB *arg) - { - char c='*'; - static int ok=0,num=0; - - if (p == 0) { c='.'; num++; }; - if (p == 1) c='+'; - if (p == 2) { c='*'; ok++; } - if (p == 3) c='\n'; - BIO_write(arg->arg,&c,1); - (void)BIO_flush(arg->arg); - - if (!ok && (p == 0) && (num > 1)) - { - BIO_printf((BIO *)arg,"error in dsatest\n"); - return 0; - } - return 1; - } -#endif diff --git a/src/lib/libcrypto/ec/ectest.c b/src/lib/libcrypto/ec/ectest.c deleted file mode 100644 index 102eaa9b23..0000000000 --- a/src/lib/libcrypto/ec/ectest.c +++ /dev/null @@ -1,1489 +0,0 @@ -/* crypto/ec/ectest.c */ -/* - * Originally written by Bodo Moeller for the OpenSSL project. - */ -/* ==================================================================== - * Copyright (c) 1998-2001 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). - * - */ -/* ==================================================================== - * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. - * - * Portions of the attached software ("Contribution") are developed by - * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. - * - * The Contribution is licensed pursuant to the OpenSSL open source - * license provided above. - * - * The elliptic curve binary polynomial software is originally written by - * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories. - * - */ - -#include -#include -#ifdef FLAT_INC -#include "e_os.h" -#else -#include "../e_os.h" -#endif -#include -#include - - -#ifdef OPENSSL_NO_EC -int main(int argc, char * argv[]) { puts("Elliptic curves are disabled."); return 0; } -#else - - -#include -#ifndef OPENSSL_NO_ENGINE -#include -#endif -#include -#include -#include -#include -#include -#include - -#if defined(_MSC_VER) && defined(_MIPS_) && (_MSC_VER/100==12) -/* suppress "too big too optimize" warning */ -#pragma warning(disable:4959) -#endif - -#define ABORT do { \ - fflush(stdout); \ - fprintf(stderr, "%s:%d: ABORT\n", __FILE__, __LINE__); \ - ERR_print_errors_fp(stderr); \ - EXIT(1); \ -} while (0) - -#define TIMING_BASE_PT 0 -#define TIMING_RAND_PT 1 -#define TIMING_SIMUL 2 - -#if 0 -static void timings(EC_GROUP *group, int type, BN_CTX *ctx) - { - clock_t clck; - int i, j; - BIGNUM *s; - BIGNUM *r[10], *r0[10]; - EC_POINT *P; - - s = BN_new(); - if (s == NULL) ABORT; - - fprintf(stdout, "Timings for %d-bit field, ", EC_GROUP_get_degree(group)); - if (!EC_GROUP_get_order(group, s, ctx)) ABORT; - fprintf(stdout, "%d-bit scalars ", (int)BN_num_bits(s)); - fflush(stdout); - - P = EC_POINT_new(group); - if (P == NULL) ABORT; - EC_POINT_copy(P, EC_GROUP_get0_generator(group)); - - for (i = 0; i < 10; i++) - { - if ((r[i] = BN_new()) == NULL) ABORT; - if (!BN_pseudo_rand(r[i], BN_num_bits(s), 0, 0)) ABORT; - if (type != TIMING_BASE_PT) - { - if ((r0[i] = BN_new()) == NULL) ABORT; - if (!BN_pseudo_rand(r0[i], BN_num_bits(s), 0, 0)) ABORT; - } - } - - clck = clock(); - for (i = 0; i < 10; i++) - { - for (j = 0; j < 10; j++) - { - if (!EC_POINT_mul(group, P, (type != TIMING_RAND_PT) ? r[i] : NULL, - (type != TIMING_BASE_PT) ? P : NULL, (type != TIMING_BASE_PT) ? r0[i] : NULL, ctx)) ABORT; - } - } - clck = clock() - clck; - - fprintf(stdout, "\n"); - -#ifdef CLOCKS_PER_SEC - /* "To determine the time in seconds, the value returned - * by the clock function should be divided by the value - * of the macro CLOCKS_PER_SEC." - * -- ISO/IEC 9899 */ -# define UNIT "s" -#else - /* "`CLOCKS_PER_SEC' undeclared (first use this function)" - * -- cc on NeXTstep/OpenStep */ -# define UNIT "units" -# define CLOCKS_PER_SEC 1 -#endif - - if (type == TIMING_BASE_PT) { - fprintf(stdout, "%i %s in %.2f " UNIT "\n", i*j, - "base point multiplications", (double)clck/CLOCKS_PER_SEC); - } else if (type == TIMING_RAND_PT) { - fprintf(stdout, "%i %s in %.2f " UNIT "\n", i*j, - "random point multiplications", (double)clck/CLOCKS_PER_SEC); - } else if (type == TIMING_SIMUL) { - fprintf(stdout, "%i %s in %.2f " UNIT "\n", i*j, - "s*P+t*Q operations", (double)clck/CLOCKS_PER_SEC); - } - fprintf(stdout, "average: %.4f " UNIT "\n", (double)clck/(CLOCKS_PER_SEC*i*j)); - - EC_POINT_free(P); - BN_free(s); - for (i = 0; i < 10; i++) - { - BN_free(r[i]); - if (type != TIMING_BASE_PT) BN_free(r0[i]); - } - } -#endif - -/* test multiplication with group order, long and negative scalars */ -static void group_order_tests(EC_GROUP *group) - { - BIGNUM *n1, *n2, *order; - EC_POINT *P = EC_POINT_new(group); - EC_POINT *Q = EC_POINT_new(group); - BN_CTX *ctx = BN_CTX_new(); - - n1 = BN_new(); n2 = BN_new(); order = BN_new(); - fprintf(stdout, "verify group order ..."); - fflush(stdout); - if (!EC_GROUP_get_order(group, order, ctx)) ABORT; - if (!EC_POINT_mul(group, Q, order, NULL, NULL, ctx)) ABORT; - if (!EC_POINT_is_at_infinity(group, Q)) ABORT; - fprintf(stdout, "."); - fflush(stdout); - if (!EC_GROUP_precompute_mult(group, ctx)) ABORT; - if (!EC_POINT_mul(group, Q, order, NULL, NULL, ctx)) ABORT; - if (!EC_POINT_is_at_infinity(group, Q)) ABORT; - fprintf(stdout, " ok\n"); - fprintf(stdout, "long/negative scalar tests ... "); - if (!BN_one(n1)) ABORT; - /* n1 = 1 - order */ - if (!BN_sub(n1, n1, order)) ABORT; - if(!EC_POINT_mul(group, Q, NULL, P, n1, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, Q, P, ctx)) ABORT; - /* n2 = 1 + order */ - if (!BN_add(n2, order, BN_value_one())) ABORT; - if(!EC_POINT_mul(group, Q, NULL, P, n2, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, Q, P, ctx)) ABORT; - /* n2 = (1 - order) * (1 + order) */ - if (!BN_mul(n2, n1, n2, ctx)) ABORT; - if(!EC_POINT_mul(group, Q, NULL, P, n2, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, Q, P, ctx)) ABORT; - fprintf(stdout, "ok\n"); - EC_POINT_free(P); - EC_POINT_free(Q); - BN_free(n1); - BN_free(n2); - BN_free(order); - BN_CTX_free(ctx); - } - -static void prime_field_tests(void) - { - BN_CTX *ctx = NULL; - BIGNUM *p, *a, *b; - EC_GROUP *group; - EC_GROUP *P_160 = NULL, *P_192 = NULL, *P_224 = NULL, *P_256 = NULL, *P_384 = NULL, *P_521 = NULL; - EC_POINT *P, *Q, *R; - BIGNUM *x, *y, *z; - unsigned char buf[100]; - size_t i, len; - int k; - -#if 1 /* optional */ - ctx = BN_CTX_new(); - if (!ctx) ABORT; -#endif - - p = BN_new(); - a = BN_new(); - b = BN_new(); - if (!p || !a || !b) ABORT; - - if (!BN_hex2bn(&p, "17")) ABORT; - if (!BN_hex2bn(&a, "1")) ABORT; - if (!BN_hex2bn(&b, "1")) ABORT; - - group = EC_GROUP_new(EC_GFp_mont_method()); /* applications should use EC_GROUP_new_curve_GFp - * so that the library gets to choose the EC_METHOD */ - if (!group) ABORT; - - if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT; - - { - EC_GROUP *tmp; - tmp = EC_GROUP_new(EC_GROUP_method_of(group)); - if (!tmp) ABORT; - if (!EC_GROUP_copy(tmp, group)) ABORT; - EC_GROUP_free(group); - group = tmp; - } - - if (!EC_GROUP_get_curve_GFp(group, p, a, b, ctx)) ABORT; - - fprintf(stdout, "Curve defined by Weierstrass equation\n y^2 = x^3 + a*x + b (mod 0x"); - BN_print_fp(stdout, p); - fprintf(stdout, ")\n a = 0x"); - BN_print_fp(stdout, a); - fprintf(stdout, "\n b = 0x"); - BN_print_fp(stdout, b); - fprintf(stdout, "\n"); - - P = EC_POINT_new(group); - Q = EC_POINT_new(group); - R = EC_POINT_new(group); - if (!P || !Q || !R) ABORT; - - if (!EC_POINT_set_to_infinity(group, P)) ABORT; - if (!EC_POINT_is_at_infinity(group, P)) ABORT; - - buf[0] = 0; - if (!EC_POINT_oct2point(group, Q, buf, 1, ctx)) ABORT; - - if (!EC_POINT_add(group, P, P, Q, ctx)) ABORT; - if (!EC_POINT_is_at_infinity(group, P)) ABORT; - - x = BN_new(); - y = BN_new(); - z = BN_new(); - if (!x || !y || !z) ABORT; - - if (!BN_hex2bn(&x, "D")) ABORT; - if (!EC_POINT_set_compressed_coordinates_GFp(group, Q, x, 1, ctx)) ABORT; - if (!EC_POINT_is_on_curve(group, Q, ctx)) - { - if (!EC_POINT_get_affine_coordinates_GFp(group, Q, x, y, ctx)) ABORT; - fprintf(stderr, "Point is not on curve: x = 0x"); - BN_print_fp(stderr, x); - fprintf(stderr, ", y = 0x"); - BN_print_fp(stderr, y); - fprintf(stderr, "\n"); - ABORT; - } - - fprintf(stdout, "A cyclic subgroup:\n"); - k = 100; - do - { - if (k-- == 0) ABORT; - - if (EC_POINT_is_at_infinity(group, P)) - fprintf(stdout, " point at infinity\n"); - else - { - if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT; - - fprintf(stdout, " x = 0x"); - BN_print_fp(stdout, x); - fprintf(stdout, ", y = 0x"); - BN_print_fp(stdout, y); - fprintf(stdout, "\n"); - } - - if (!EC_POINT_copy(R, P)) ABORT; - if (!EC_POINT_add(group, P, P, Q, ctx)) ABORT; - -#if 0 /* optional */ - { - EC_POINT *points[3]; - - points[0] = R; - points[1] = Q; - points[2] = P; - if (!EC_POINTs_make_affine(group, 2, points, ctx)) ABORT; - } -#endif - - } - while (!EC_POINT_is_at_infinity(group, P)); - - if (!EC_POINT_add(group, P, Q, R, ctx)) ABORT; - if (!EC_POINT_is_at_infinity(group, P)) ABORT; - - len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_COMPRESSED, buf, sizeof buf, ctx); - if (len == 0) ABORT; - if (!EC_POINT_oct2point(group, P, buf, len, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, P, Q, ctx)) ABORT; - fprintf(stdout, "Generator as octet string, compressed form:\n "); - for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]); - - len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_UNCOMPRESSED, buf, sizeof buf, ctx); - if (len == 0) ABORT; - if (!EC_POINT_oct2point(group, P, buf, len, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, P, Q, ctx)) ABORT; - fprintf(stdout, "\nGenerator as octet string, uncompressed form:\n "); - for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]); - - len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_HYBRID, buf, sizeof buf, ctx); - if (len == 0) ABORT; - if (!EC_POINT_oct2point(group, P, buf, len, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, P, Q, ctx)) ABORT; - fprintf(stdout, "\nGenerator as octet string, hybrid form:\n "); - for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]); - - if (!EC_POINT_get_Jprojective_coordinates_GFp(group, R, x, y, z, ctx)) ABORT; - fprintf(stdout, "\nA representation of the inverse of that generator in\nJacobian projective coordinates:\n X = 0x"); - BN_print_fp(stdout, x); - fprintf(stdout, ", Y = 0x"); - BN_print_fp(stdout, y); - fprintf(stdout, ", Z = 0x"); - BN_print_fp(stdout, z); - fprintf(stdout, "\n"); - - if (!EC_POINT_invert(group, P, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, P, R, ctx)) ABORT; - - - /* Curve secp160r1 (Certicom Research SEC 2 Version 1.0, section 2.4.2, 2000) - * -- not a NIST curve, but commonly used */ - - if (!BN_hex2bn(&p, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF")) ABORT; - if (1 != BN_is_prime_ex(p, BN_prime_checks, ctx, NULL)) ABORT; - if (!BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFC")) ABORT; - if (!BN_hex2bn(&b, "1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45")) ABORT; - if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT; - - if (!BN_hex2bn(&x, "4A96B5688EF573284664698968C38BB913CBFC82")) ABORT; - if (!BN_hex2bn(&y, "23a628553168947d59dcc912042351377ac5fb32")) ABORT; - if (!EC_POINT_set_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT; - if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT; - if (!BN_hex2bn(&z, "0100000000000000000001F4C8F927AED3CA752257")) ABORT; - if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT; - - if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT; - fprintf(stdout, "\nSEC2 curve secp160r1 -- Generator:\n x = 0x"); - BN_print_fp(stdout, x); - fprintf(stdout, "\n y = 0x"); - BN_print_fp(stdout, y); - fprintf(stdout, "\n"); - /* G_y value taken from the standard: */ - if (!BN_hex2bn(&z, "23a628553168947d59dcc912042351377ac5fb32")) ABORT; - if (0 != BN_cmp(y, z)) ABORT; - - fprintf(stdout, "verify degree ..."); - if (EC_GROUP_get_degree(group) != 160) ABORT; - fprintf(stdout, " ok\n"); - - group_order_tests(group); - - if (!(P_160 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT; - if (!EC_GROUP_copy(P_160, group)) ABORT; - - - /* Curve P-192 (FIPS PUB 186-2, App. 6) */ - - if (!BN_hex2bn(&p, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF")) ABORT; - if (1 != BN_is_prime_ex(p, BN_prime_checks, ctx, NULL)) ABORT; - if (!BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC")) ABORT; - if (!BN_hex2bn(&b, "64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1")) ABORT; - if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT; - - if (!BN_hex2bn(&x, "188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012")) ABORT; - if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 1, ctx)) ABORT; - if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT; - if (!BN_hex2bn(&z, "FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831")) ABORT; - if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT; - - if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT; - fprintf(stdout, "\nNIST curve P-192 -- Generator:\n x = 0x"); - BN_print_fp(stdout, x); - fprintf(stdout, "\n y = 0x"); - BN_print_fp(stdout, y); - fprintf(stdout, "\n"); - /* G_y value taken from the standard: */ - if (!BN_hex2bn(&z, "07192B95FFC8DA78631011ED6B24CDD573F977A11E794811")) ABORT; - if (0 != BN_cmp(y, z)) ABORT; - - fprintf(stdout, "verify degree ..."); - if (EC_GROUP_get_degree(group) != 192) ABORT; - fprintf(stdout, " ok\n"); - - group_order_tests(group); - - if (!(P_192 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT; - if (!EC_GROUP_copy(P_192, group)) ABORT; - - - /* Curve P-224 (FIPS PUB 186-2, App. 6) */ - - if (!BN_hex2bn(&p, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001")) ABORT; - if (1 != BN_is_prime_ex(p, BN_prime_checks, ctx, NULL)) ABORT; - if (!BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE")) ABORT; - if (!BN_hex2bn(&b, "B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4")) ABORT; - if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT; - - if (!BN_hex2bn(&x, "B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21")) ABORT; - if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 0, ctx)) ABORT; - if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT; - if (!BN_hex2bn(&z, "FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D")) ABORT; - if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT; - - if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT; - fprintf(stdout, "\nNIST curve P-224 -- Generator:\n x = 0x"); - BN_print_fp(stdout, x); - fprintf(stdout, "\n y = 0x"); - BN_print_fp(stdout, y); - fprintf(stdout, "\n"); - /* G_y value taken from the standard: */ - if (!BN_hex2bn(&z, "BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34")) ABORT; - if (0 != BN_cmp(y, z)) ABORT; - - fprintf(stdout, "verify degree ..."); - if (EC_GROUP_get_degree(group) != 224) ABORT; - fprintf(stdout, " ok\n"); - - group_order_tests(group); - - if (!(P_224 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT; - if (!EC_GROUP_copy(P_224, group)) ABORT; - - - /* Curve P-256 (FIPS PUB 186-2, App. 6) */ - - if (!BN_hex2bn(&p, "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF")) ABORT; - if (1 != BN_is_prime_ex(p, BN_prime_checks, ctx, NULL)) ABORT; - if (!BN_hex2bn(&a, "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC")) ABORT; - if (!BN_hex2bn(&b, "5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B")) ABORT; - if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT; - - if (!BN_hex2bn(&x, "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296")) ABORT; - if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 1, ctx)) ABORT; - if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT; - if (!BN_hex2bn(&z, "FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E" - "84F3B9CAC2FC632551")) ABORT; - if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT; - - if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT; - fprintf(stdout, "\nNIST curve P-256 -- Generator:\n x = 0x"); - BN_print_fp(stdout, x); - fprintf(stdout, "\n y = 0x"); - BN_print_fp(stdout, y); - fprintf(stdout, "\n"); - /* G_y value taken from the standard: */ - if (!BN_hex2bn(&z, "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5")) ABORT; - if (0 != BN_cmp(y, z)) ABORT; - - fprintf(stdout, "verify degree ..."); - if (EC_GROUP_get_degree(group) != 256) ABORT; - fprintf(stdout, " ok\n"); - - group_order_tests(group); - - if (!(P_256 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT; - if (!EC_GROUP_copy(P_256, group)) ABORT; - - - /* Curve P-384 (FIPS PUB 186-2, App. 6) */ - - if (!BN_hex2bn(&p, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" - "FFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF")) ABORT; - if (1 != BN_is_prime_ex(p, BN_prime_checks, ctx, NULL)) ABORT; - if (!BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" - "FFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC")) ABORT; - if (!BN_hex2bn(&b, "B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141" - "120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF")) ABORT; - if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT; - - if (!BN_hex2bn(&x, "AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B" - "9859F741E082542A385502F25DBF55296C3A545E3872760AB7")) ABORT; - if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 1, ctx)) ABORT; - if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT; - if (!BN_hex2bn(&z, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" - "FFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973")) ABORT; - if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT; - - if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT; - fprintf(stdout, "\nNIST curve P-384 -- Generator:\n x = 0x"); - BN_print_fp(stdout, x); - fprintf(stdout, "\n y = 0x"); - BN_print_fp(stdout, y); - fprintf(stdout, "\n"); - /* G_y value taken from the standard: */ - if (!BN_hex2bn(&z, "3617DE4A96262C6F5D9E98BF9292DC29F8F41DBD289A14" - "7CE9DA3113B5F0B8C00A60B1CE1D7E819D7A431D7C90EA0E5F")) ABORT; - if (0 != BN_cmp(y, z)) ABORT; - - fprintf(stdout, "verify degree ..."); - if (EC_GROUP_get_degree(group) != 384) ABORT; - fprintf(stdout, " ok\n"); - - group_order_tests(group); - - if (!(P_384 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT; - if (!EC_GROUP_copy(P_384, group)) ABORT; - - - /* Curve P-521 (FIPS PUB 186-2, App. 6) */ - - if (!BN_hex2bn(&p, "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" - "FFFFFFFFFFFFFFFFFFFFFFFFFFFF")) ABORT; - if (1 != BN_is_prime_ex(p, BN_prime_checks, ctx, NULL)) ABORT; - if (!BN_hex2bn(&a, "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" - "FFFFFFFFFFFFFFFFFFFFFFFFFFFC")) ABORT; - if (!BN_hex2bn(&b, "051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B" - "315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573" - "DF883D2C34F1EF451FD46B503F00")) ABORT; - if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT; - - if (!BN_hex2bn(&x, "C6858E06B70404E9CD9E3ECB662395B4429C648139053F" - "B521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B" - "3C1856A429BF97E7E31C2E5BD66")) ABORT; - if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 0, ctx)) ABORT; - if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT; - if (!BN_hex2bn(&z, "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" - "FFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5" - "C9B8899C47AEBB6FB71E91386409")) ABORT; - if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT; - - if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT; - fprintf(stdout, "\nNIST curve P-521 -- Generator:\n x = 0x"); - BN_print_fp(stdout, x); - fprintf(stdout, "\n y = 0x"); - BN_print_fp(stdout, y); - fprintf(stdout, "\n"); - /* G_y value taken from the standard: */ - if (!BN_hex2bn(&z, "11839296A789A3BC0045C8A5FB42C7D1BD998F54449579" - "B446817AFBD17273E662C97EE72995EF42640C550B9013FAD0761353C" - "7086A272C24088BE94769FD16650")) ABORT; - if (0 != BN_cmp(y, z)) ABORT; - - fprintf(stdout, "verify degree ..."); - if (EC_GROUP_get_degree(group) != 521) ABORT; - fprintf(stdout, " ok\n"); - - group_order_tests(group); - - if (!(P_521 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT; - if (!EC_GROUP_copy(P_521, group)) ABORT; - - - /* more tests using the last curve */ - - if (!EC_POINT_copy(Q, P)) ABORT; - if (EC_POINT_is_at_infinity(group, Q)) ABORT; - if (!EC_POINT_dbl(group, P, P, ctx)) ABORT; - if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT; - if (!EC_POINT_invert(group, Q, ctx)) ABORT; /* P = -2Q */ - - if (!EC_POINT_add(group, R, P, Q, ctx)) ABORT; - if (!EC_POINT_add(group, R, R, Q, ctx)) ABORT; - if (!EC_POINT_is_at_infinity(group, R)) ABORT; /* R = P + 2Q */ - - { - const EC_POINT *points[4]; - const BIGNUM *scalars[4]; - BIGNUM scalar3; - - if (EC_POINT_is_at_infinity(group, Q)) ABORT; - points[0] = Q; - points[1] = Q; - points[2] = Q; - points[3] = Q; - - if (!EC_GROUP_get_order(group, z, ctx)) ABORT; - if (!BN_add(y, z, BN_value_one())) ABORT; - if (BN_is_odd(y)) ABORT; - if (!BN_rshift1(y, y)) ABORT; - scalars[0] = y; /* (group order + 1)/2, so y*Q + y*Q = Q */ - scalars[1] = y; - - fprintf(stdout, "combined multiplication ..."); - fflush(stdout); - - /* z is still the group order */ - if (!EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx)) ABORT; - if (!EC_POINTs_mul(group, R, z, 2, points, scalars, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, P, R, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, R, Q, ctx)) ABORT; - - fprintf(stdout, "."); - fflush(stdout); - - if (!BN_pseudo_rand(y, BN_num_bits(y), 0, 0)) ABORT; - if (!BN_add(z, z, y)) ABORT; - BN_set_negative(z, 1); - scalars[0] = y; - scalars[1] = z; /* z = -(order + y) */ - - if (!EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx)) ABORT; - if (!EC_POINT_is_at_infinity(group, P)) ABORT; - - fprintf(stdout, "."); - fflush(stdout); - - if (!BN_pseudo_rand(x, BN_num_bits(y) - 1, 0, 0)) ABORT; - if (!BN_add(z, x, y)) ABORT; - BN_set_negative(z, 1); - scalars[0] = x; - scalars[1] = y; - scalars[2] = z; /* z = -(x+y) */ - - BN_init(&scalar3); - BN_zero(&scalar3); - scalars[3] = &scalar3; - - if (!EC_POINTs_mul(group, P, NULL, 4, points, scalars, ctx)) ABORT; - if (!EC_POINT_is_at_infinity(group, P)) ABORT; - - fprintf(stdout, " ok\n\n"); - - BN_free(&scalar3); - } - - -#if 0 - timings(P_160, TIMING_BASE_PT, ctx); - timings(P_160, TIMING_RAND_PT, ctx); - timings(P_160, TIMING_SIMUL, ctx); - timings(P_192, TIMING_BASE_PT, ctx); - timings(P_192, TIMING_RAND_PT, ctx); - timings(P_192, TIMING_SIMUL, ctx); - timings(P_224, TIMING_BASE_PT, ctx); - timings(P_224, TIMING_RAND_PT, ctx); - timings(P_224, TIMING_SIMUL, ctx); - timings(P_256, TIMING_BASE_PT, ctx); - timings(P_256, TIMING_RAND_PT, ctx); - timings(P_256, TIMING_SIMUL, ctx); - timings(P_384, TIMING_BASE_PT, ctx); - timings(P_384, TIMING_RAND_PT, ctx); - timings(P_384, TIMING_SIMUL, ctx); - timings(P_521, TIMING_BASE_PT, ctx); - timings(P_521, TIMING_RAND_PT, ctx); - timings(P_521, TIMING_SIMUL, ctx); -#endif - - - if (ctx) - BN_CTX_free(ctx); - BN_free(p); BN_free(a); BN_free(b); - EC_GROUP_free(group); - EC_POINT_free(P); - EC_POINT_free(Q); - EC_POINT_free(R); - BN_free(x); BN_free(y); BN_free(z); - - if (P_160) EC_GROUP_free(P_160); - if (P_192) EC_GROUP_free(P_192); - if (P_224) EC_GROUP_free(P_224); - if (P_256) EC_GROUP_free(P_256); - if (P_384) EC_GROUP_free(P_384); - if (P_521) EC_GROUP_free(P_521); - - } - -/* Change test based on whether binary point compression is enabled or not. */ -#ifdef OPENSSL_EC_BIN_PT_COMP -#define CHAR2_CURVE_TEST_INTERNAL(_name, _p, _a, _b, _x, _y, _y_bit, _order, _cof, _degree, _variable) \ - if (!BN_hex2bn(&x, _x)) ABORT; \ - if (!EC_POINT_set_compressed_coordinates_GF2m(group, P, x, _y_bit, ctx)) ABORT; \ - if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT; \ - if (!BN_hex2bn(&z, _order)) ABORT; \ - if (!BN_hex2bn(&cof, _cof)) ABORT; \ - if (!EC_GROUP_set_generator(group, P, z, cof)) ABORT; \ - if (!EC_POINT_get_affine_coordinates_GF2m(group, P, x, y, ctx)) ABORT; \ - fprintf(stdout, "\n%s -- Generator:\n x = 0x", _name); \ - BN_print_fp(stdout, x); \ - fprintf(stdout, "\n y = 0x"); \ - BN_print_fp(stdout, y); \ - fprintf(stdout, "\n"); \ - /* G_y value taken from the standard: */ \ - if (!BN_hex2bn(&z, _y)) ABORT; \ - if (0 != BN_cmp(y, z)) ABORT; -#else -#define CHAR2_CURVE_TEST_INTERNAL(_name, _p, _a, _b, _x, _y, _y_bit, _order, _cof, _degree, _variable) \ - if (!BN_hex2bn(&x, _x)) ABORT; \ - if (!BN_hex2bn(&y, _y)) ABORT; \ - if (!EC_POINT_set_affine_coordinates_GF2m(group, P, x, y, ctx)) ABORT; \ - if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT; \ - if (!BN_hex2bn(&z, _order)) ABORT; \ - if (!BN_hex2bn(&cof, _cof)) ABORT; \ - if (!EC_GROUP_set_generator(group, P, z, cof)) ABORT; \ - fprintf(stdout, "\n%s -- Generator:\n x = 0x", _name); \ - BN_print_fp(stdout, x); \ - fprintf(stdout, "\n y = 0x"); \ - BN_print_fp(stdout, y); \ - fprintf(stdout, "\n"); -#endif - -#define CHAR2_CURVE_TEST(_name, _p, _a, _b, _x, _y, _y_bit, _order, _cof, _degree, _variable) \ - if (!BN_hex2bn(&p, _p)) ABORT; \ - if (!BN_hex2bn(&a, _a)) ABORT; \ - if (!BN_hex2bn(&b, _b)) ABORT; \ - if (!EC_GROUP_set_curve_GF2m(group, p, a, b, ctx)) ABORT; \ - CHAR2_CURVE_TEST_INTERNAL(_name, _p, _a, _b, _x, _y, _y_bit, _order, _cof, _degree, _variable) \ - fprintf(stdout, "verify degree ..."); \ - if (EC_GROUP_get_degree(group) != _degree) ABORT; \ - fprintf(stdout, " ok\n"); \ - group_order_tests(group); \ - if (!(_variable = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT; \ - if (!EC_GROUP_copy(_variable, group)) ABORT; \ - -#ifndef OPENSSL_NO_EC2M - -static void char2_field_tests(void) - { - BN_CTX *ctx = NULL; - BIGNUM *p, *a, *b; - EC_GROUP *group; - EC_GROUP *C2_K163 = NULL, *C2_K233 = NULL, *C2_K283 = NULL, *C2_K409 = NULL, *C2_K571 = NULL; - EC_GROUP *C2_B163 = NULL, *C2_B233 = NULL, *C2_B283 = NULL, *C2_B409 = NULL, *C2_B571 = NULL; - EC_POINT *P, *Q, *R; - BIGNUM *x, *y, *z, *cof; - unsigned char buf[100]; - size_t i, len; - int k; - -#if 1 /* optional */ - ctx = BN_CTX_new(); - if (!ctx) ABORT; -#endif - - p = BN_new(); - a = BN_new(); - b = BN_new(); - if (!p || !a || !b) ABORT; - - if (!BN_hex2bn(&p, "13")) ABORT; - if (!BN_hex2bn(&a, "3")) ABORT; - if (!BN_hex2bn(&b, "1")) ABORT; - - group = EC_GROUP_new(EC_GF2m_simple_method()); /* applications should use EC_GROUP_new_curve_GF2m - * so that the library gets to choose the EC_METHOD */ - if (!group) ABORT; - if (!EC_GROUP_set_curve_GF2m(group, p, a, b, ctx)) ABORT; - - { - EC_GROUP *tmp; - tmp = EC_GROUP_new(EC_GROUP_method_of(group)); - if (!tmp) ABORT; - if (!EC_GROUP_copy(tmp, group)) ABORT; - EC_GROUP_free(group); - group = tmp; - } - - if (!EC_GROUP_get_curve_GF2m(group, p, a, b, ctx)) ABORT; - - fprintf(stdout, "Curve defined by Weierstrass equation\n y^2 + x*y = x^3 + a*x^2 + b (mod 0x"); - BN_print_fp(stdout, p); - fprintf(stdout, ")\n a = 0x"); - BN_print_fp(stdout, a); - fprintf(stdout, "\n b = 0x"); - BN_print_fp(stdout, b); - fprintf(stdout, "\n(0x... means binary polynomial)\n"); - - P = EC_POINT_new(group); - Q = EC_POINT_new(group); - R = EC_POINT_new(group); - if (!P || !Q || !R) ABORT; - - if (!EC_POINT_set_to_infinity(group, P)) ABORT; - if (!EC_POINT_is_at_infinity(group, P)) ABORT; - - buf[0] = 0; - if (!EC_POINT_oct2point(group, Q, buf, 1, ctx)) ABORT; - - if (!EC_POINT_add(group, P, P, Q, ctx)) ABORT; - if (!EC_POINT_is_at_infinity(group, P)) ABORT; - - x = BN_new(); - y = BN_new(); - z = BN_new(); - cof = BN_new(); - if (!x || !y || !z || !cof) ABORT; - - if (!BN_hex2bn(&x, "6")) ABORT; -/* Change test based on whether binary point compression is enabled or not. */ -#ifdef OPENSSL_EC_BIN_PT_COMP - if (!EC_POINT_set_compressed_coordinates_GF2m(group, Q, x, 1, ctx)) ABORT; -#else - if (!BN_hex2bn(&y, "8")) ABORT; - if (!EC_POINT_set_affine_coordinates_GF2m(group, Q, x, y, ctx)) ABORT; -#endif - if (!EC_POINT_is_on_curve(group, Q, ctx)) - { -/* Change test based on whether binary point compression is enabled or not. */ -#ifdef OPENSSL_EC_BIN_PT_COMP - if (!EC_POINT_get_affine_coordinates_GF2m(group, Q, x, y, ctx)) ABORT; -#endif - fprintf(stderr, "Point is not on curve: x = 0x"); - BN_print_fp(stderr, x); - fprintf(stderr, ", y = 0x"); - BN_print_fp(stderr, y); - fprintf(stderr, "\n"); - ABORT; - } - - fprintf(stdout, "A cyclic subgroup:\n"); - k = 100; - do - { - if (k-- == 0) ABORT; - - if (EC_POINT_is_at_infinity(group, P)) - fprintf(stdout, " point at infinity\n"); - else - { - if (!EC_POINT_get_affine_coordinates_GF2m(group, P, x, y, ctx)) ABORT; - - fprintf(stdout, " x = 0x"); - BN_print_fp(stdout, x); - fprintf(stdout, ", y = 0x"); - BN_print_fp(stdout, y); - fprintf(stdout, "\n"); - } - - if (!EC_POINT_copy(R, P)) ABORT; - if (!EC_POINT_add(group, P, P, Q, ctx)) ABORT; - } - while (!EC_POINT_is_at_infinity(group, P)); - - if (!EC_POINT_add(group, P, Q, R, ctx)) ABORT; - if (!EC_POINT_is_at_infinity(group, P)) ABORT; - -/* Change test based on whether binary point compression is enabled or not. */ -#ifdef OPENSSL_EC_BIN_PT_COMP - len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_COMPRESSED, buf, sizeof buf, ctx); - if (len == 0) ABORT; - if (!EC_POINT_oct2point(group, P, buf, len, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, P, Q, ctx)) ABORT; - fprintf(stdout, "Generator as octet string, compressed form:\n "); - for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]); -#endif - - len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_UNCOMPRESSED, buf, sizeof buf, ctx); - if (len == 0) ABORT; - if (!EC_POINT_oct2point(group, P, buf, len, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, P, Q, ctx)) ABORT; - fprintf(stdout, "\nGenerator as octet string, uncompressed form:\n "); - for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]); - -/* Change test based on whether binary point compression is enabled or not. */ -#ifdef OPENSSL_EC_BIN_PT_COMP - len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_HYBRID, buf, sizeof buf, ctx); - if (len == 0) ABORT; - if (!EC_POINT_oct2point(group, P, buf, len, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, P, Q, ctx)) ABORT; - fprintf(stdout, "\nGenerator as octet string, hybrid form:\n "); - for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]); -#endif - - fprintf(stdout, "\n"); - - if (!EC_POINT_invert(group, P, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, P, R, ctx)) ABORT; - - - /* Curve K-163 (FIPS PUB 186-2, App. 6) */ - CHAR2_CURVE_TEST - ( - "NIST curve K-163", - "0800000000000000000000000000000000000000C9", - "1", - "1", - "02FE13C0537BBC11ACAA07D793DE4E6D5E5C94EEE8", - "0289070FB05D38FF58321F2E800536D538CCDAA3D9", - 1, - "04000000000000000000020108A2E0CC0D99F8A5EF", - "2", - 163, - C2_K163 - ); - - /* Curve B-163 (FIPS PUB 186-2, App. 6) */ - CHAR2_CURVE_TEST - ( - "NIST curve B-163", - "0800000000000000000000000000000000000000C9", - "1", - "020A601907B8C953CA1481EB10512F78744A3205FD", - "03F0EBA16286A2D57EA0991168D4994637E8343E36", - "00D51FBC6C71A0094FA2CDD545B11C5C0C797324F1", - 1, - "040000000000000000000292FE77E70C12A4234C33", - "2", - 163, - C2_B163 - ); - - /* Curve K-233 (FIPS PUB 186-2, App. 6) */ - CHAR2_CURVE_TEST - ( - "NIST curve K-233", - "020000000000000000000000000000000000000004000000000000000001", - "0", - "1", - "017232BA853A7E731AF129F22FF4149563A419C26BF50A4C9D6EEFAD6126", - "01DB537DECE819B7F70F555A67C427A8CD9BF18AEB9B56E0C11056FAE6A3", - 0, - "008000000000000000000000000000069D5BB915BCD46EFB1AD5F173ABDF", - "4", - 233, - C2_K233 - ); - - /* Curve B-233 (FIPS PUB 186-2, App. 6) */ - CHAR2_CURVE_TEST - ( - "NIST curve B-233", - "020000000000000000000000000000000000000004000000000000000001", - "000000000000000000000000000000000000000000000000000000000001", - "0066647EDE6C332C7F8C0923BB58213B333B20E9CE4281FE115F7D8F90AD", - "00FAC9DFCBAC8313BB2139F1BB755FEF65BC391F8B36F8F8EB7371FD558B", - "01006A08A41903350678E58528BEBF8A0BEFF867A7CA36716F7E01F81052", - 1, - "01000000000000000000000000000013E974E72F8A6922031D2603CFE0D7", - "2", - 233, - C2_B233 - ); - - /* Curve K-283 (FIPS PUB 186-2, App. 6) */ - CHAR2_CURVE_TEST - ( - "NIST curve K-283", - "0800000000000000000000000000000000000000000000000000000000000000000010A1", - "0", - "1", - "0503213F78CA44883F1A3B8162F188E553CD265F23C1567A16876913B0C2AC2458492836", - "01CCDA380F1C9E318D90F95D07E5426FE87E45C0E8184698E45962364E34116177DD2259", - 0, - "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE9AE2ED07577265DFF7F94451E061E163C61", - "4", - 283, - C2_K283 - ); - - /* Curve B-283 (FIPS PUB 186-2, App. 6) */ - CHAR2_CURVE_TEST - ( - "NIST curve B-283", - "0800000000000000000000000000000000000000000000000000000000000000000010A1", - "000000000000000000000000000000000000000000000000000000000000000000000001", - "027B680AC8B8596DA5A4AF8A19A0303FCA97FD7645309FA2A581485AF6263E313B79A2F5", - "05F939258DB7DD90E1934F8C70B0DFEC2EED25B8557EAC9C80E2E198F8CDBECD86B12053", - "03676854FE24141CB98FE6D4B20D02B4516FF702350EDDB0826779C813F0DF45BE8112F4", - 1, - "03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEF90399660FC938A90165B042A7CEFADB307", - "2", - 283, - C2_B283 - ); - - /* Curve K-409 (FIPS PUB 186-2, App. 6) */ - CHAR2_CURVE_TEST - ( - "NIST curve K-409", - "02000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001", - "0", - "1", - "0060F05F658F49C1AD3AB1890F7184210EFD0987E307C84C27ACCFB8F9F67CC2C460189EB5AAAA62EE222EB1B35540CFE9023746", - "01E369050B7C4E42ACBA1DACBF04299C3460782F918EA427E6325165E9EA10E3DA5F6C42E9C55215AA9CA27A5863EC48D8E0286B", - 1, - "007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE5F83B2D4EA20400EC4557D5ED3E3E7CA5B4B5C83B8E01E5FCF", - "4", - 409, - C2_K409 - ); - - /* Curve B-409 (FIPS PUB 186-2, App. 6) */ - CHAR2_CURVE_TEST - ( - "NIST curve B-409", - "02000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001", - "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", - "0021A5C2C8EE9FEB5C4B9A753B7B476B7FD6422EF1F3DD674761FA99D6AC27C8A9A197B272822F6CD57A55AA4F50AE317B13545F", - "015D4860D088DDB3496B0C6064756260441CDE4AF1771D4DB01FFE5B34E59703DC255A868A1180515603AEAB60794E54BB7996A7", - "0061B1CFAB6BE5F32BBFA78324ED106A7636B9C5A7BD198D0158AA4F5488D08F38514F1FDF4B4F40D2181B3681C364BA0273C706", - 1, - "010000000000000000000000000000000000000000000000000001E2AAD6A612F33307BE5FA47C3C9E052F838164CD37D9A21173", - "2", - 409, - C2_B409 - ); - - /* Curve K-571 (FIPS PUB 186-2, App. 6) */ - CHAR2_CURVE_TEST - ( - "NIST curve K-571", - "80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425", - "0", - "1", - "026EB7A859923FBC82189631F8103FE4AC9CA2970012D5D46024804801841CA44370958493B205E647DA304DB4CEB08CBBD1BA39494776FB988B47174DCA88C7E2945283A01C8972", - "0349DC807F4FBF374F4AEADE3BCA95314DD58CEC9F307A54FFC61EFC006D8A2C9D4979C0AC44AEA74FBEBBB9F772AEDCB620B01A7BA7AF1B320430C8591984F601CD4C143EF1C7A3", - 0, - "020000000000000000000000000000000000000000000000000000000000000000000000131850E1F19A63E4B391A8DB917F4138B630D84BE5D639381E91DEB45CFE778F637C1001", - "4", - 571, - C2_K571 - ); - - /* Curve B-571 (FIPS PUB 186-2, App. 6) */ - CHAR2_CURVE_TEST - ( - "NIST curve B-571", - "80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425", - "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", - "02F40E7E2221F295DE297117B7F3D62F5C6A97FFCB8CEFF1CD6BA8CE4A9A18AD84FFABBD8EFA59332BE7AD6756A66E294AFD185A78FF12AA520E4DE739BACA0C7FFEFF7F2955727A", - "0303001D34B856296C16C0D40D3CD7750A93D1D2955FA80AA5F40FC8DB7B2ABDBDE53950F4C0D293CDD711A35B67FB1499AE60038614F1394ABFA3B4C850D927E1E7769C8EEC2D19", - "037BF27342DA639B6DCCFFFEB73D69D78C6C27A6009CBBCA1980F8533921E8A684423E43BAB08A576291AF8F461BB2A8B3531D2F0485C19B16E2F1516E23DD3C1A4827AF1B8AC15B", - 1, - "03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE661CE18FF55987308059B186823851EC7DD9CA1161DE93D5174D66E8382E9BB2FE84E47", - "2", - 571, - C2_B571 - ); - - /* more tests using the last curve */ - - if (!EC_POINT_copy(Q, P)) ABORT; - if (EC_POINT_is_at_infinity(group, Q)) ABORT; - if (!EC_POINT_dbl(group, P, P, ctx)) ABORT; - if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT; - if (!EC_POINT_invert(group, Q, ctx)) ABORT; /* P = -2Q */ - - if (!EC_POINT_add(group, R, P, Q, ctx)) ABORT; - if (!EC_POINT_add(group, R, R, Q, ctx)) ABORT; - if (!EC_POINT_is_at_infinity(group, R)) ABORT; /* R = P + 2Q */ - - { - const EC_POINT *points[3]; - const BIGNUM *scalars[3]; - - if (EC_POINT_is_at_infinity(group, Q)) ABORT; - points[0] = Q; - points[1] = Q; - points[2] = Q; - - if (!BN_add(y, z, BN_value_one())) ABORT; - if (BN_is_odd(y)) ABORT; - if (!BN_rshift1(y, y)) ABORT; - scalars[0] = y; /* (group order + 1)/2, so y*Q + y*Q = Q */ - scalars[1] = y; - - fprintf(stdout, "combined multiplication ..."); - fflush(stdout); - - /* z is still the group order */ - if (!EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx)) ABORT; - if (!EC_POINTs_mul(group, R, z, 2, points, scalars, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, P, R, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, R, Q, ctx)) ABORT; - - fprintf(stdout, "."); - fflush(stdout); - - if (!BN_pseudo_rand(y, BN_num_bits(y), 0, 0)) ABORT; - if (!BN_add(z, z, y)) ABORT; - BN_set_negative(z, 1); - scalars[0] = y; - scalars[1] = z; /* z = -(order + y) */ - - if (!EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx)) ABORT; - if (!EC_POINT_is_at_infinity(group, P)) ABORT; - - fprintf(stdout, "."); - fflush(stdout); - - if (!BN_pseudo_rand(x, BN_num_bits(y) - 1, 0, 0)) ABORT; - if (!BN_add(z, x, y)) ABORT; - BN_set_negative(z, 1); - scalars[0] = x; - scalars[1] = y; - scalars[2] = z; /* z = -(x+y) */ - - if (!EC_POINTs_mul(group, P, NULL, 3, points, scalars, ctx)) ABORT; - if (!EC_POINT_is_at_infinity(group, P)) ABORT; - - fprintf(stdout, " ok\n\n"); - } - - -#if 0 - timings(C2_K163, TIMING_BASE_PT, ctx); - timings(C2_K163, TIMING_RAND_PT, ctx); - timings(C2_K163, TIMING_SIMUL, ctx); - timings(C2_B163, TIMING_BASE_PT, ctx); - timings(C2_B163, TIMING_RAND_PT, ctx); - timings(C2_B163, TIMING_SIMUL, ctx); - timings(C2_K233, TIMING_BASE_PT, ctx); - timings(C2_K233, TIMING_RAND_PT, ctx); - timings(C2_K233, TIMING_SIMUL, ctx); - timings(C2_B233, TIMING_BASE_PT, ctx); - timings(C2_B233, TIMING_RAND_PT, ctx); - timings(C2_B233, TIMING_SIMUL, ctx); - timings(C2_K283, TIMING_BASE_PT, ctx); - timings(C2_K283, TIMING_RAND_PT, ctx); - timings(C2_K283, TIMING_SIMUL, ctx); - timings(C2_B283, TIMING_BASE_PT, ctx); - timings(C2_B283, TIMING_RAND_PT, ctx); - timings(C2_B283, TIMING_SIMUL, ctx); - timings(C2_K409, TIMING_BASE_PT, ctx); - timings(C2_K409, TIMING_RAND_PT, ctx); - timings(C2_K409, TIMING_SIMUL, ctx); - timings(C2_B409, TIMING_BASE_PT, ctx); - timings(C2_B409, TIMING_RAND_PT, ctx); - timings(C2_B409, TIMING_SIMUL, ctx); - timings(C2_K571, TIMING_BASE_PT, ctx); - timings(C2_K571, TIMING_RAND_PT, ctx); - timings(C2_K571, TIMING_SIMUL, ctx); - timings(C2_B571, TIMING_BASE_PT, ctx); - timings(C2_B571, TIMING_RAND_PT, ctx); - timings(C2_B571, TIMING_SIMUL, ctx); -#endif - - - if (ctx) - BN_CTX_free(ctx); - BN_free(p); BN_free(a); BN_free(b); - EC_GROUP_free(group); - EC_POINT_free(P); - EC_POINT_free(Q); - EC_POINT_free(R); - BN_free(x); BN_free(y); BN_free(z); BN_free(cof); - - if (C2_K163) EC_GROUP_free(C2_K163); - if (C2_B163) EC_GROUP_free(C2_B163); - if (C2_K233) EC_GROUP_free(C2_K233); - if (C2_B233) EC_GROUP_free(C2_B233); - if (C2_K283) EC_GROUP_free(C2_K283); - if (C2_B283) EC_GROUP_free(C2_B283); - if (C2_K409) EC_GROUP_free(C2_K409); - if (C2_B409) EC_GROUP_free(C2_B409); - if (C2_K571) EC_GROUP_free(C2_K571); - if (C2_B571) EC_GROUP_free(C2_B571); - - } -#endif - -static void internal_curve_test(void) - { - EC_builtin_curve *curves = NULL; - size_t crv_len = 0, n = 0; - int ok = 1; - - crv_len = EC_get_builtin_curves(NULL, 0); - - curves = OPENSSL_malloc(sizeof(EC_builtin_curve) * crv_len); - - if (curves == NULL) - return; - - if (!EC_get_builtin_curves(curves, crv_len)) - { - OPENSSL_free(curves); - return; - } - - fprintf(stdout, "testing internal curves: "); - - for (n = 0; n < crv_len; n++) - { - EC_GROUP *group = NULL; - int nid = curves[n].nid; - if ((group = EC_GROUP_new_by_curve_name(nid)) == NULL) - { - ok = 0; - fprintf(stdout, "\nEC_GROUP_new_curve_name() failed with" - " curve %s\n", OBJ_nid2sn(nid)); - /* try next curve */ - continue; - } - if (!EC_GROUP_check(group, NULL)) - { - ok = 0; - fprintf(stdout, "\nEC_GROUP_check() failed with" - " curve %s\n", OBJ_nid2sn(nid)); - EC_GROUP_free(group); - /* try the next curve */ - continue; - } - fprintf(stdout, "."); - fflush(stdout); - EC_GROUP_free(group); - } - if (ok) - fprintf(stdout, " ok\n\n"); - else - { - fprintf(stdout, " failed\n\n"); - ABORT; - } - OPENSSL_free(curves); - return; - } - -#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 -/* nistp_test_params contains magic numbers for testing our optimized - * implementations of several NIST curves with characteristic > 3. */ -struct nistp_test_params - { - const EC_METHOD* (*meth) (); - int degree; - /* Qx, Qy and D are taken from - * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/ECDSA_Prime.pdf - * Otherwise, values are standard curve parameters from FIPS 180-3 */ - const char *p, *a, *b, *Qx, *Qy, *Gx, *Gy, *order, *d; - }; - -static const struct nistp_test_params nistp_tests_params[] = - { - { - /* P-224 */ - EC_GFp_nistp224_method, - 224, - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001", /* p */ - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE", /* a */ - "B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4", /* b */ - "E84FB0B8E7000CB657D7973CF6B42ED78B301674276DF744AF130B3E", /* Qx */ - "4376675C6FC5612C21A0FF2D2A89D2987DF7A2BC52183B5982298555", /* Qy */ - "B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21", /* Gx */ - "BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34", /* Gy */ - "FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D", /* order */ - "3F0C488E987C80BE0FEE521F8D90BE6034EC69AE11CA72AA777481E8", /* d */ - }, - { - /* P-256 */ - EC_GFp_nistp256_method, - 256, - "ffffffff00000001000000000000000000000000ffffffffffffffffffffffff", /* p */ - "ffffffff00000001000000000000000000000000fffffffffffffffffffffffc", /* a */ - "5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b", /* b */ - "b7e08afdfe94bad3f1dc8c734798ba1c62b3a0ad1e9ea2a38201cd0889bc7a19", /* Qx */ - "3603f747959dbf7a4bb226e41928729063adc7ae43529e61b563bbc606cc5e09", /* Qy */ - "6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296", /* Gx */ - "4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5", /* Gy */ - "ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551", /* order */ - "c477f9f65c22cce20657faa5b2d1d8122336f851a508a1ed04e479c34985bf96", /* d */ - }, - { - /* P-521 */ - EC_GFp_nistp521_method, - 521, - "1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", /* p */ - "1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc", /* a */ - "051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00", /* b */ - "0098e91eef9a68452822309c52fab453f5f117c1da8ed796b255e9ab8f6410cca16e59df403a6bdc6ca467a37056b1e54b3005d8ac030decfeb68df18b171885d5c4", /* Qx */ - "0164350c321aecfc1cca1ba4364c9b15656150b4b78d6a48d7d28e7f31985ef17be8554376b72900712c4b83ad668327231526e313f5f092999a4632fd50d946bc2e", /* Qy */ - "c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66", /* Gx */ - "11839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650", /* Gy */ - "1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409", /* order */ - "0100085f47b8e1b8b11b7eb33028c0b2888e304bfc98501955b45bba1478dc184eeedf09b86a5f7c21994406072787205e69a63709fe35aa93ba333514b24f961722", /* d */ - }, - }; - -void nistp_single_test(const struct nistp_test_params *test) - { - BN_CTX *ctx; - BIGNUM *p, *a, *b, *x, *y, *n, *m, *order; - EC_GROUP *NISTP; - EC_POINT *G, *P, *Q, *Q_CHECK; - - fprintf(stdout, "\nNIST curve P-%d (optimised implementation):\n", test->degree); - ctx = BN_CTX_new(); - p = BN_new(); - a = BN_new(); - b = BN_new(); - x = BN_new(); y = BN_new(); - m = BN_new(); n = BN_new(); order = BN_new(); - - NISTP = EC_GROUP_new(test->meth()); - if(!NISTP) ABORT; - if (!BN_hex2bn(&p, test->p)) ABORT; - if (1 != BN_is_prime_ex(p, BN_prime_checks, ctx, NULL)) ABORT; - if (!BN_hex2bn(&a, test->a)) ABORT; - if (!BN_hex2bn(&b, test->b)) ABORT; - if (!EC_GROUP_set_curve_GFp(NISTP, p, a, b, ctx)) ABORT; - G = EC_POINT_new(NISTP); - P = EC_POINT_new(NISTP); - Q = EC_POINT_new(NISTP); - Q_CHECK = EC_POINT_new(NISTP); - if(!BN_hex2bn(&x, test->Qx)) ABORT; - if(!BN_hex2bn(&y, test->Qy)) ABORT; - if(!EC_POINT_set_affine_coordinates_GFp(NISTP, Q_CHECK, x, y, ctx)) ABORT; - if (!BN_hex2bn(&x, test->Gx)) ABORT; - if (!BN_hex2bn(&y, test->Gy)) ABORT; - if (!EC_POINT_set_affine_coordinates_GFp(NISTP, G, x, y, ctx)) ABORT; - if (!BN_hex2bn(&order, test->order)) ABORT; - if (!EC_GROUP_set_generator(NISTP, G, order, BN_value_one())) ABORT; - - fprintf(stdout, "verify degree ... "); - if (EC_GROUP_get_degree(NISTP) != test->degree) ABORT; - fprintf(stdout, "ok\n"); - - fprintf(stdout, "NIST test vectors ... "); - if (!BN_hex2bn(&n, test->d)) ABORT; - /* fixed point multiplication */ - EC_POINT_mul(NISTP, Q, n, NULL, NULL, ctx); - if (0 != EC_POINT_cmp(NISTP, Q, Q_CHECK, ctx)) ABORT; - /* random point multiplication */ - EC_POINT_mul(NISTP, Q, NULL, G, n, ctx); - if (0 != EC_POINT_cmp(NISTP, Q, Q_CHECK, ctx)) ABORT; - - /* set generator to P = 2*G, where G is the standard generator */ - if (!EC_POINT_dbl(NISTP, P, G, ctx)) ABORT; - if (!EC_GROUP_set_generator(NISTP, P, order, BN_value_one())) ABORT; - /* set the scalar to m=n/2, where n is the NIST test scalar */ - if (!BN_rshift(m, n, 1)) ABORT; - - /* test the non-standard generator */ - /* fixed point multiplication */ - EC_POINT_mul(NISTP, Q, m, NULL, NULL, ctx); - if (0 != EC_POINT_cmp(NISTP, Q, Q_CHECK, ctx)) ABORT; - /* random point multiplication */ - EC_POINT_mul(NISTP, Q, NULL, P, m, ctx); - if (0 != EC_POINT_cmp(NISTP, Q, Q_CHECK, ctx)) ABORT; - - /* now repeat all tests with precomputation */ - if (!EC_GROUP_precompute_mult(NISTP, ctx)) ABORT; - - /* fixed point multiplication */ - EC_POINT_mul(NISTP, Q, m, NULL, NULL, ctx); - if (0 != EC_POINT_cmp(NISTP, Q, Q_CHECK, ctx)) ABORT; - /* random point multiplication */ - EC_POINT_mul(NISTP, Q, NULL, P, m, ctx); - if (0 != EC_POINT_cmp(NISTP, Q, Q_CHECK, ctx)) ABORT; - - /* reset generator */ - if (!EC_GROUP_set_generator(NISTP, G, order, BN_value_one())) ABORT; - /* fixed point multiplication */ - EC_POINT_mul(NISTP, Q, n, NULL, NULL, ctx); - if (0 != EC_POINT_cmp(NISTP, Q, Q_CHECK, ctx)) ABORT; - /* random point multiplication */ - EC_POINT_mul(NISTP, Q, NULL, G, n, ctx); - if (0 != EC_POINT_cmp(NISTP, Q, Q_CHECK, ctx)) ABORT; - - fprintf(stdout, "ok\n"); - group_order_tests(NISTP); -#if 0 - timings(NISTP, TIMING_BASE_PT, ctx); - timings(NISTP, TIMING_RAND_PT, ctx); -#endif - EC_GROUP_free(NISTP); - EC_POINT_free(G); - EC_POINT_free(P); - EC_POINT_free(Q); - EC_POINT_free(Q_CHECK); - BN_free(n); - BN_free(m); - BN_free(p); - BN_free(a); - BN_free(b); - BN_free(x); - BN_free(y); - BN_free(order); - BN_CTX_free(ctx); - } - -void nistp_tests() - { - unsigned i; - - for (i = 0; i < sizeof(nistp_tests_params) / sizeof(struct nistp_test_params); i++) - { - nistp_single_test(&nistp_tests_params[i]); - } - } -#endif - -static const char rnd_seed[] = "string to make the random number generator think it has entropy"; - -int main(int argc, char *argv[]) - { - - /* enable memory leak checking unless explicitly disabled */ - if (!((getenv("OPENSSL_DEBUG_MEMORY") != NULL) && (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off")))) - { - CRYPTO_malloc_debug_init(); - CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL); - } - else - { - /* OPENSSL_DEBUG_MEMORY=off */ - CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0); - } - CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); - ERR_load_crypto_strings(); - - RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_generate_prime may fail */ - - prime_field_tests(); - puts(""); -#ifndef OPENSSL_NO_EC2M - char2_field_tests(); -#endif -#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 - nistp_tests(); -#endif - /* test the internal curves */ - internal_curve_test(); - -#ifndef OPENSSL_NO_ENGINE - ENGINE_cleanup(); -#endif - CRYPTO_cleanup_all_ex_data(); - ERR_free_strings(); - ERR_remove_thread_state(NULL); - CRYPTO_mem_leaks_fp(stderr); - - return 0; - } -#endif diff --git a/src/lib/libcrypto/ecdh/ecdhtest.c b/src/lib/libcrypto/ecdh/ecdhtest.c deleted file mode 100644 index 823d7baa65..0000000000 --- a/src/lib/libcrypto/ecdh/ecdhtest.c +++ /dev/null @@ -1,374 +0,0 @@ -/* crypto/ecdh/ecdhtest.c */ -/* ==================================================================== - * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. - * - * The Elliptic Curve Public-Key Crypto Library (ECC Code) included - * herein is developed by SUN MICROSYSTEMS, INC., and is contributed - * to the OpenSSL project. - * - * The ECC Code is licensed pursuant to the OpenSSL open source - * license provided below. - * - * The ECDH software is originally written by Douglas Stebila of - * Sun Microsystems Laboratories. - * - */ -/* ==================================================================== - * Copyright (c) 1998-2003 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). - * - */ - -#include -#include -#include - -#include "../e_os.h" - -#include /* for OPENSSL_NO_ECDH */ -#include -#include -#include -#include -#include -#include -#include - -#ifdef OPENSSL_NO_ECDH -int main(int argc, char *argv[]) -{ - printf("No ECDH support\n"); - return(0); -} -#else -#include -#include - -#ifdef OPENSSL_SYS_WIN16 -#define MS_CALLBACK _far _loadds -#else -#define MS_CALLBACK -#endif - -#if 0 -static void MS_CALLBACK cb(int p, int n, void *arg); -#endif - -static const char rnd_seed[] = "string to make the random number generator think it has entropy"; - - -static const int KDF1_SHA1_len = 20; -static void *KDF1_SHA1(const void *in, size_t inlen, void *out, size_t *outlen) - { -#ifndef OPENSSL_NO_SHA - if (*outlen < SHA_DIGEST_LENGTH) - return NULL; - else - *outlen = SHA_DIGEST_LENGTH; - return SHA1(in, inlen, out); -#else - return NULL; -#endif - } - - -static int test_ecdh_curve(int nid, const char *text, BN_CTX *ctx, BIO *out) - { - EC_KEY *a=NULL; - EC_KEY *b=NULL; - BIGNUM *x_a=NULL, *y_a=NULL, - *x_b=NULL, *y_b=NULL; - char buf[12]; - unsigned char *abuf=NULL,*bbuf=NULL; - int i,alen,blen,aout,bout,ret=0; - const EC_GROUP *group; - - a = EC_KEY_new_by_curve_name(nid); - b = EC_KEY_new_by_curve_name(nid); - if (a == NULL || b == NULL) - goto err; - - group = EC_KEY_get0_group(a); - - if ((x_a=BN_new()) == NULL) goto err; - if ((y_a=BN_new()) == NULL) goto err; - if ((x_b=BN_new()) == NULL) goto err; - if ((y_b=BN_new()) == NULL) goto err; - - BIO_puts(out,"Testing key generation with "); - BIO_puts(out,text); -#ifdef NOISY - BIO_puts(out,"\n"); -#else - (void)BIO_flush(out); -#endif - - if (!EC_KEY_generate_key(a)) goto err; - - if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_prime_field) - { - if (!EC_POINT_get_affine_coordinates_GFp(group, - EC_KEY_get0_public_key(a), x_a, y_a, ctx)) goto err; - } -#ifndef OPENSSL_NO_EC2M - else - { - if (!EC_POINT_get_affine_coordinates_GF2m(group, - EC_KEY_get0_public_key(a), x_a, y_a, ctx)) goto err; - } -#endif -#ifdef NOISY - BIO_puts(out," pri 1="); - BN_print(out,a->priv_key); - BIO_puts(out,"\n pub 1="); - BN_print(out,x_a); - BIO_puts(out,","); - BN_print(out,y_a); - BIO_puts(out,"\n"); -#else - BIO_printf(out," ."); - (void)BIO_flush(out); -#endif - - if (!EC_KEY_generate_key(b)) goto err; - - if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_prime_field) - { - if (!EC_POINT_get_affine_coordinates_GFp(group, - EC_KEY_get0_public_key(b), x_b, y_b, ctx)) goto err; - } -#ifndef OPENSSL_NO_EC2M - else - { - if (!EC_POINT_get_affine_coordinates_GF2m(group, - EC_KEY_get0_public_key(b), x_b, y_b, ctx)) goto err; - } -#endif - -#ifdef NOISY - BIO_puts(out," pri 2="); - BN_print(out,b->priv_key); - BIO_puts(out,"\n pub 2="); - BN_print(out,x_b); - BIO_puts(out,","); - BN_print(out,y_b); - BIO_puts(out,"\n"); -#else - BIO_printf(out,"."); - (void)BIO_flush(out); -#endif - - alen=KDF1_SHA1_len; - abuf=(unsigned char *)OPENSSL_malloc(alen); - aout=ECDH_compute_key(abuf,alen,EC_KEY_get0_public_key(b),a,KDF1_SHA1); - -#ifdef NOISY - BIO_puts(out," key1 ="); - for (i=0; i -#include -#include - -#include /* To see if OPENSSL_NO_ECDSA is defined */ - -#ifdef OPENSSL_NO_ECDSA -int main(int argc, char * argv[]) - { - puts("Elliptic curves are disabled."); - return 0; - } -#else - -#include -#include -#include -#include -#include -#ifndef OPENSSL_NO_ENGINE -#include -#endif -#include -#include - -static const char rnd_seed[] = "string to make the random number generator " - "think it has entropy"; - -/* declaration of the test functions */ -int x9_62_tests(BIO *); -int x9_62_test_internal(BIO *out, int nid, const char *r, const char *s); -int test_builtin(BIO *); - -/* functions to change the RAND_METHOD */ -int change_rand(void); -int restore_rand(void); -int fbytes(unsigned char *buf, int num); - -RAND_METHOD fake_rand; -const RAND_METHOD *old_rand; - -int change_rand(void) - { - /* save old rand method */ - if ((old_rand = RAND_get_rand_method()) == NULL) - return 0; - - fake_rand.seed = old_rand->seed; - fake_rand.cleanup = old_rand->cleanup; - fake_rand.add = old_rand->add; - fake_rand.status = old_rand->status; - /* use own random function */ - fake_rand.bytes = fbytes; - fake_rand.pseudorand = old_rand->bytes; - /* set new RAND_METHOD */ - if (!RAND_set_rand_method(&fake_rand)) - return 0; - return 1; - } - -int restore_rand(void) - { - if (!RAND_set_rand_method(old_rand)) - return 0; - else - return 1; - } - -static int fbytes_counter = 0; -static const char *numbers[8] = { - "651056770906015076056810763456358567190100156695615665659", - "6140507067065001063065065565667405560006161556565665656654", - "8763001015071075675010661307616710783570106710677817767166" - "71676178726717", - "7000000175690566466555057817571571075705015757757057795755" - "55657156756655", - "1275552191113212300012030439187146164646146646466749494799", - "1542725565216523985789236956265265265235675811949404040041", - "1456427555219115346513212300075341203043918714616464614664" - "64667494947990", - "1712787255652165239672857892369562652652652356758119494040" - "40041670216363"}; - -int fbytes(unsigned char *buf, int num) - { - int ret; - BIGNUM *tmp = NULL; - - if (fbytes_counter >= 8) - return 0; - tmp = BN_new(); - if (!tmp) - return 0; - if (!BN_dec2bn(&tmp, numbers[fbytes_counter])) - { - BN_free(tmp); - return 0; - } - fbytes_counter ++; - if (num != BN_num_bytes(tmp) || !BN_bn2bin(tmp, buf)) - ret = 0; - else - ret = 1; - if (tmp) - BN_free(tmp); - return ret; - } - -/* some tests from the X9.62 draft */ -int x9_62_test_internal(BIO *out, int nid, const char *r_in, const char *s_in) - { - int ret = 0; - const char message[] = "abc"; - unsigned char digest[20]; - unsigned int dgst_len = 0; - EVP_MD_CTX md_ctx; - EC_KEY *key = NULL; - ECDSA_SIG *signature = NULL; - BIGNUM *r = NULL, *s = NULL; - - EVP_MD_CTX_init(&md_ctx); - /* get the message digest */ - EVP_DigestInit(&md_ctx, EVP_ecdsa()); - EVP_DigestUpdate(&md_ctx, (const void*)message, 3); - EVP_DigestFinal(&md_ctx, digest, &dgst_len); - - BIO_printf(out, "testing %s: ", OBJ_nid2sn(nid)); - /* create the key */ - if ((key = EC_KEY_new_by_curve_name(nid)) == NULL) - goto x962_int_err; - if (!EC_KEY_generate_key(key)) - goto x962_int_err; - BIO_printf(out, "."); - (void)BIO_flush(out); - /* create the signature */ - signature = ECDSA_do_sign(digest, 20, key); - if (signature == NULL) - goto x962_int_err; - BIO_printf(out, "."); - (void)BIO_flush(out); - /* compare the created signature with the expected signature */ - if ((r = BN_new()) == NULL || (s = BN_new()) == NULL) - goto x962_int_err; - if (!BN_dec2bn(&r, r_in) || - !BN_dec2bn(&s, s_in)) - goto x962_int_err; - if (BN_cmp(signature->r ,r) || BN_cmp(signature->s, s)) - goto x962_int_err; - BIO_printf(out, "."); - (void)BIO_flush(out); - /* verify the signature */ - if (ECDSA_do_verify(digest, 20, signature, key) != 1) - goto x962_int_err; - BIO_printf(out, "."); - (void)BIO_flush(out); - - BIO_printf(out, " ok\n"); - ret = 1; -x962_int_err: - if (!ret) - BIO_printf(out, " failed\n"); - if (key) - EC_KEY_free(key); - if (signature) - ECDSA_SIG_free(signature); - if (r) - BN_free(r); - if (s) - BN_free(s); - EVP_MD_CTX_cleanup(&md_ctx); - return ret; - } - -int x9_62_tests(BIO *out) - { - int ret = 0; - - BIO_printf(out, "some tests from X9.62:\n"); - - /* set own rand method */ - if (!change_rand()) - goto x962_err; - - if (!x9_62_test_internal(out, NID_X9_62_prime192v1, - "3342403536405981729393488334694600415596881826869351677613", - "5735822328888155254683894997897571951568553642892029982342")) - goto x962_err; - if (!x9_62_test_internal(out, NID_X9_62_prime239v1, - "3086361431751678114926225473006680188549593787585317781474" - "62058306432176", - "3238135532097973577080787768312505059318910517550078427819" - "78505179448783")) - goto x962_err; -#ifndef OPENSSL_NO_EC2M - if (!x9_62_test_internal(out, NID_X9_62_c2tnb191v1, - "87194383164871543355722284926904419997237591535066528048", - "308992691965804947361541664549085895292153777025772063598")) - goto x962_err; - if (!x9_62_test_internal(out, NID_X9_62_c2tnb239v1, - "2159633321041961198501834003903461262881815148684178964245" - "5876922391552", - "1970303740007316867383349976549972270528498040721988191026" - "49413465737174")) - goto x962_err; -#endif - ret = 1; -x962_err: - if (!restore_rand()) - ret = 0; - return ret; - } - -int test_builtin(BIO *out) - { - EC_builtin_curve *curves = NULL; - size_t crv_len = 0, n = 0; - EC_KEY *eckey = NULL, *wrong_eckey = NULL; - EC_GROUP *group; - ECDSA_SIG *ecdsa_sig = NULL; - unsigned char digest[20], wrong_digest[20]; - unsigned char *signature = NULL; - const unsigned char *sig_ptr; - unsigned char *sig_ptr2; - unsigned char *raw_buf = NULL; - unsigned int sig_len, degree, r_len, s_len, bn_len, buf_len; - int nid, ret = 0; - - /* fill digest values with some random data */ - if (!RAND_pseudo_bytes(digest, 20) || - !RAND_pseudo_bytes(wrong_digest, 20)) - { - BIO_printf(out, "ERROR: unable to get random data\n"); - goto builtin_err; - } - - /* create and verify a ecdsa signature with every availble curve - * (with ) */ - BIO_printf(out, "\ntesting ECDSA_sign() and ECDSA_verify() " - "with some internal curves:\n"); - - /* get a list of all internal curves */ - crv_len = EC_get_builtin_curves(NULL, 0); - - curves = OPENSSL_malloc(sizeof(EC_builtin_curve) * crv_len); - - if (curves == NULL) - { - BIO_printf(out, "malloc error\n"); - goto builtin_err; - } - - if (!EC_get_builtin_curves(curves, crv_len)) - { - BIO_printf(out, "unable to get internal curves\n"); - goto builtin_err; - } - - /* now create and verify a signature for every curve */ - for (n = 0; n < crv_len; n++) - { - unsigned char dirt, offset; - - nid = curves[n].nid; - if (nid == NID_ipsec4) - continue; - /* create new ecdsa key (== EC_KEY) */ - if ((eckey = EC_KEY_new()) == NULL) - goto builtin_err; - group = EC_GROUP_new_by_curve_name(nid); - if (group == NULL) - goto builtin_err; - if (EC_KEY_set_group(eckey, group) == 0) - goto builtin_err; - EC_GROUP_free(group); - degree = EC_GROUP_get_degree(EC_KEY_get0_group(eckey)); - if (degree < 160) - /* drop the curve */ - { - EC_KEY_free(eckey); - eckey = NULL; - continue; - } - BIO_printf(out, "%s: ", OBJ_nid2sn(nid)); - /* create key */ - if (!EC_KEY_generate_key(eckey)) - { - BIO_printf(out, " failed\n"); - goto builtin_err; - } - /* create second key */ - if ((wrong_eckey = EC_KEY_new()) == NULL) - goto builtin_err; - group = EC_GROUP_new_by_curve_name(nid); - if (group == NULL) - goto builtin_err; - if (EC_KEY_set_group(wrong_eckey, group) == 0) - goto builtin_err; - EC_GROUP_free(group); - if (!EC_KEY_generate_key(wrong_eckey)) - { - BIO_printf(out, " failed\n"); - goto builtin_err; - } - - BIO_printf(out, "."); - (void)BIO_flush(out); - /* check key */ - if (!EC_KEY_check_key(eckey)) - { - BIO_printf(out, " failed\n"); - goto builtin_err; - } - BIO_printf(out, "."); - (void)BIO_flush(out); - /* create signature */ - sig_len = ECDSA_size(eckey); - if ((signature = OPENSSL_malloc(sig_len)) == NULL) - goto builtin_err; - if (!ECDSA_sign(0, digest, 20, signature, &sig_len, eckey)) - { - BIO_printf(out, " failed\n"); - goto builtin_err; - } - BIO_printf(out, "."); - (void)BIO_flush(out); - /* verify signature */ - if (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) != 1) - { - BIO_printf(out, " failed\n"); - goto builtin_err; - } - BIO_printf(out, "."); - (void)BIO_flush(out); - /* verify signature with the wrong key */ - if (ECDSA_verify(0, digest, 20, signature, sig_len, - wrong_eckey) == 1) - { - BIO_printf(out, " failed\n"); - goto builtin_err; - } - BIO_printf(out, "."); - (void)BIO_flush(out); - /* wrong digest */ - if (ECDSA_verify(0, wrong_digest, 20, signature, sig_len, - eckey) == 1) - { - BIO_printf(out, " failed\n"); - goto builtin_err; - } - BIO_printf(out, "."); - (void)BIO_flush(out); - /* wrong length */ - if (ECDSA_verify(0, digest, 20, signature, sig_len - 1, - eckey) == 1) - { - BIO_printf(out, " failed\n"); - goto builtin_err; - } - BIO_printf(out, "."); - (void)BIO_flush(out); - - /* Modify a single byte of the signature: to ensure we don't - * garble the ASN1 structure, we read the raw signature and - * modify a byte in one of the bignums directly. */ - sig_ptr = signature; - if ((ecdsa_sig = d2i_ECDSA_SIG(NULL, &sig_ptr, sig_len)) == NULL) - { - BIO_printf(out, " failed\n"); - goto builtin_err; - } - - /* Store the two BIGNUMs in raw_buf. */ - r_len = BN_num_bytes(ecdsa_sig->r); - s_len = BN_num_bytes(ecdsa_sig->s); - bn_len = (degree + 7) / 8; - if ((r_len > bn_len) || (s_len > bn_len)) - { - BIO_printf(out, " failed\n"); - goto builtin_err; - } - buf_len = 2 * bn_len; - if ((raw_buf = OPENSSL_malloc(buf_len)) == NULL) - goto builtin_err; - /* Pad the bignums with leading zeroes. */ - memset(raw_buf, 0, buf_len); - BN_bn2bin(ecdsa_sig->r, raw_buf + bn_len - r_len); - BN_bn2bin(ecdsa_sig->s, raw_buf + buf_len - s_len); - - /* Modify a single byte in the buffer. */ - offset = raw_buf[10] % buf_len; - dirt = raw_buf[11] ? raw_buf[11] : 1; - raw_buf[offset] ^= dirt; - /* Now read the BIGNUMs back in from raw_buf. */ - if ((BN_bin2bn(raw_buf, bn_len, ecdsa_sig->r) == NULL) || - (BN_bin2bn(raw_buf + bn_len, bn_len, ecdsa_sig->s) == NULL)) - goto builtin_err; - - sig_ptr2 = signature; - sig_len = i2d_ECDSA_SIG(ecdsa_sig, &sig_ptr2); - if (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) == 1) - { - BIO_printf(out, " failed\n"); - goto builtin_err; - } - /* Sanity check: undo the modification and verify signature. */ - raw_buf[offset] ^= dirt; - if ((BN_bin2bn(raw_buf, bn_len, ecdsa_sig->r) == NULL) || - (BN_bin2bn(raw_buf + bn_len, bn_len, ecdsa_sig->s) == NULL)) - goto builtin_err; - - sig_ptr2 = signature; - sig_len = i2d_ECDSA_SIG(ecdsa_sig, &sig_ptr2); - if (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) != 1) - { - BIO_printf(out, " failed\n"); - goto builtin_err; - } - BIO_printf(out, "."); - (void)BIO_flush(out); - - BIO_printf(out, " ok\n"); - /* cleanup */ - /* clean bogus errors */ - ERR_clear_error(); - OPENSSL_free(signature); - signature = NULL; - EC_KEY_free(eckey); - eckey = NULL; - EC_KEY_free(wrong_eckey); - wrong_eckey = NULL; - ECDSA_SIG_free(ecdsa_sig); - ecdsa_sig = NULL; - OPENSSL_free(raw_buf); - raw_buf = NULL; - } - - ret = 1; -builtin_err: - if (eckey) - EC_KEY_free(eckey); - if (wrong_eckey) - EC_KEY_free(wrong_eckey); - if (ecdsa_sig) - ECDSA_SIG_free(ecdsa_sig); - if (signature) - OPENSSL_free(signature); - if (raw_buf) - OPENSSL_free(raw_buf); - if (curves) - OPENSSL_free(curves); - - return ret; - } - -int main(void) - { - int ret = 1; - BIO *out; - - out = BIO_new_fp(stdout, BIO_NOCLOSE); - - /* enable memory leak checking unless explicitly disabled */ - if (!((getenv("OPENSSL_DEBUG_MEMORY") != NULL) && - (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off")))) - { - CRYPTO_malloc_debug_init(); - CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL); - } - else - { - /* OPENSSL_DEBUG_MEMORY=off */ - CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0); - } - CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); - - ERR_load_crypto_strings(); - - /* initialize the prng */ - RAND_seed(rnd_seed, sizeof(rnd_seed)); - - /* the tests */ - if (!x9_62_tests(out)) goto err; - if (!test_builtin(out)) goto err; - - ret = 0; -err: - if (ret) - BIO_printf(out, "\nECDSA test failed\n"); - else - BIO_printf(out, "\nECDSA test passed\n"); - if (ret) - ERR_print_errors(out); - CRYPTO_cleanup_all_ex_data(); - ERR_remove_thread_state(NULL); - ERR_free_strings(); - CRYPTO_mem_leaks(out); - if (out != NULL) - BIO_free(out); - return ret; - } -#endif diff --git a/src/lib/libcrypto/evp/evp_test.c b/src/lib/libcrypto/evp/evp_test.c deleted file mode 100644 index 55c7cdfdcc..0000000000 --- a/src/lib/libcrypto/evp/evp_test.c +++ /dev/null @@ -1,450 +0,0 @@ -/* Written by Ben Laurie, 2001 */ -/* - * Copyright (c) 2001 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. - */ - -#include -#include - -#include "../e_os.h" - -#include -#include -#ifndef OPENSSL_NO_ENGINE -#include -#endif -#include -#include - -static void hexdump(FILE *f,const char *title,const unsigned char *s,int l) - { - int n=0; - - fprintf(f,"%s",title); - for( ; n < l ; ++n) - { - if((n%16) == 0) - fprintf(f,"\n%04x",n); - fprintf(f," %02x",s[n]); - } - fprintf(f,"\n"); - } - -static int convert(unsigned char *s) - { - unsigned char *d; - - for(d=s ; *s ; s+=2,++d) - { - unsigned int n; - - if(!s[1]) - { - fprintf(stderr,"Odd number of hex digits!"); - EXIT(4); - } - sscanf((char *)s,"%2x",&n); - *d=(unsigned char)n; - } - return s-d; - } - -static char *sstrsep(char **string, const char *delim) - { - char isdelim[256]; - char *token = *string; - - if (**string == 0) - return NULL; - - memset(isdelim, 0, 256); - isdelim[0] = 1; - - while (*delim) - { - isdelim[(unsigned char)(*delim)] = 1; - delim++; - } - - while (!isdelim[(unsigned char)(**string)]) - { - (*string)++; - } - - if (**string) - { - **string = 0; - (*string)++; - } - - return token; - } - -static unsigned char *ustrsep(char **p,const char *sep) - { return (unsigned char *)sstrsep(p,sep); } - -static int test1_exit(int ec) - { - EXIT(ec); - return(0); /* To keep some compilers quiet */ - } - -static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn, - const unsigned char *iv,int in, - const unsigned char *plaintext,int pn, - const unsigned char *ciphertext,int cn, - int encdec) - { - EVP_CIPHER_CTX ctx; - unsigned char out[4096]; - int outl,outl2; - - printf("Testing cipher %s%s\n",EVP_CIPHER_name(c), - (encdec == 1 ? "(encrypt)" : (encdec == 0 ? "(decrypt)" : "(encrypt/decrypt)"))); - hexdump(stdout,"Key",key,kn); - if(in) - hexdump(stdout,"IV",iv,in); - hexdump(stdout,"Plaintext",plaintext,pn); - hexdump(stdout,"Ciphertext",ciphertext,cn); - - if(kn != c->key_len) - { - fprintf(stderr,"Key length doesn't match, got %d expected %lu\n",kn, - (unsigned long)c->key_len); - test1_exit(5); - } - EVP_CIPHER_CTX_init(&ctx); - if (encdec != 0) - { - if(!EVP_EncryptInit_ex(&ctx,c,NULL,key,iv)) - { - fprintf(stderr,"EncryptInit failed\n"); - ERR_print_errors_fp(stderr); - test1_exit(10); - } - EVP_CIPHER_CTX_set_padding(&ctx,0); - - if(!EVP_EncryptUpdate(&ctx,out,&outl,plaintext,pn)) - { - fprintf(stderr,"Encrypt failed\n"); - ERR_print_errors_fp(stderr); - test1_exit(6); - } - if(!EVP_EncryptFinal_ex(&ctx,out+outl,&outl2)) - { - fprintf(stderr,"EncryptFinal failed\n"); - ERR_print_errors_fp(stderr); - test1_exit(7); - } - - if(outl+outl2 != cn) - { - fprintf(stderr,"Ciphertext length mismatch got %d expected %d\n", - outl+outl2,cn); - test1_exit(8); - } - - if(memcmp(out,ciphertext,cn)) - { - fprintf(stderr,"Ciphertext mismatch\n"); - hexdump(stderr,"Got",out,cn); - hexdump(stderr,"Expected",ciphertext,cn); - test1_exit(9); - } - } - - if (encdec <= 0) - { - if(!EVP_DecryptInit_ex(&ctx,c,NULL,key,iv)) - { - fprintf(stderr,"DecryptInit failed\n"); - ERR_print_errors_fp(stderr); - test1_exit(11); - } - EVP_CIPHER_CTX_set_padding(&ctx,0); - - if(!EVP_DecryptUpdate(&ctx,out,&outl,ciphertext,cn)) - { - fprintf(stderr,"Decrypt failed\n"); - ERR_print_errors_fp(stderr); - test1_exit(6); - } - if(!EVP_DecryptFinal_ex(&ctx,out+outl,&outl2)) - { - fprintf(stderr,"DecryptFinal failed\n"); - ERR_print_errors_fp(stderr); - test1_exit(7); - } - - if(outl+outl2 != pn) - { - fprintf(stderr,"Plaintext length mismatch got %d expected %d\n", - outl+outl2,pn); - test1_exit(8); - } - - if(memcmp(out,plaintext,pn)) - { - fprintf(stderr,"Plaintext mismatch\n"); - hexdump(stderr,"Got",out,pn); - hexdump(stderr,"Expected",plaintext,pn); - test1_exit(9); - } - } - - EVP_CIPHER_CTX_cleanup(&ctx); - - printf("\n"); - } - -static int test_cipher(const char *cipher,const unsigned char *key,int kn, - const unsigned char *iv,int in, - const unsigned char *plaintext,int pn, - const unsigned char *ciphertext,int cn, - int encdec) - { - const EVP_CIPHER *c; - - c=EVP_get_cipherbyname(cipher); - if(!c) - return 0; - - test1(c,key,kn,iv,in,plaintext,pn,ciphertext,cn,encdec); - - return 1; - } - -static int test_digest(const char *digest, - const unsigned char *plaintext,int pn, - const unsigned char *ciphertext, unsigned int cn) - { - const EVP_MD *d; - EVP_MD_CTX ctx; - unsigned char md[EVP_MAX_MD_SIZE]; - unsigned int mdn; - - d=EVP_get_digestbyname(digest); - if(!d) - return 0; - - printf("Testing digest %s\n",EVP_MD_name(d)); - hexdump(stdout,"Plaintext",plaintext,pn); - hexdump(stdout,"Digest",ciphertext,cn); - - EVP_MD_CTX_init(&ctx); - if(!EVP_DigestInit_ex(&ctx,d, NULL)) - { - fprintf(stderr,"DigestInit failed\n"); - ERR_print_errors_fp(stderr); - EXIT(100); - } - if(!EVP_DigestUpdate(&ctx,plaintext,pn)) - { - fprintf(stderr,"DigestUpdate failed\n"); - ERR_print_errors_fp(stderr); - EXIT(101); - } - if(!EVP_DigestFinal_ex(&ctx,md,&mdn)) - { - fprintf(stderr,"DigestFinal failed\n"); - ERR_print_errors_fp(stderr); - EXIT(101); - } - EVP_MD_CTX_cleanup(&ctx); - - if(mdn != cn) - { - fprintf(stderr,"Digest length mismatch, got %d expected %d\n",mdn,cn); - EXIT(102); - } - - if(memcmp(md,ciphertext,cn)) - { - fprintf(stderr,"Digest mismatch\n"); - hexdump(stderr,"Got",md,cn); - hexdump(stderr,"Expected",ciphertext,cn); - EXIT(103); - } - - printf("\n"); - - EVP_MD_CTX_cleanup(&ctx); - - return 1; - } - -int main(int argc,char **argv) - { - const char *szTestFile; - FILE *f; - - if(argc != 2) - { - fprintf(stderr,"%s \n",argv[0]); - EXIT(1); - } - CRYPTO_malloc_debug_init(); - CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL); - CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); - - szTestFile=argv[1]; - - f=fopen(szTestFile,"r"); - if(!f) - { - perror(szTestFile); - EXIT(2); - } - - /* Load up the software EVP_CIPHER and EVP_MD definitions */ - OpenSSL_add_all_ciphers(); - OpenSSL_add_all_digests(); -#ifndef OPENSSL_NO_ENGINE - /* Load all compiled-in ENGINEs */ - ENGINE_load_builtin_engines(); -#endif -#if 0 - OPENSSL_config(); -#endif -#ifndef OPENSSL_NO_ENGINE - /* Register all available ENGINE implementations of ciphers and digests. - * This could perhaps be changed to "ENGINE_register_all_complete()"? */ - ENGINE_register_all_ciphers(); - ENGINE_register_all_digests(); - /* If we add command-line options, this statement should be switchable. - * It'll prevent ENGINEs being ENGINE_init()ialised for cipher/digest use if - * they weren't already initialised. */ - /* ENGINE_set_cipher_flags(ENGINE_CIPHER_FLAG_NOINIT); */ -#endif - - for( ; ; ) - { - char line[4096]; - char *p; - char *cipher; - unsigned char *iv,*key,*plaintext,*ciphertext; - int encdec; - int kn,in,pn,cn; - - if(!fgets((char *)line,sizeof line,f)) - break; - if(line[0] == '#' || line[0] == '\n') - continue; - p=line; - cipher=sstrsep(&p,":"); - key=ustrsep(&p,":"); - iv=ustrsep(&p,":"); - plaintext=ustrsep(&p,":"); - ciphertext=ustrsep(&p,":"); - if (p[-1] == '\n') { - p[-1] = '\0'; - encdec = -1; - } else { - encdec = atoi(sstrsep(&p,"\n")); - } - - - kn=convert(key); - in=convert(iv); - pn=convert(plaintext); - cn=convert(ciphertext); - - if(!test_cipher(cipher,key,kn,iv,in,plaintext,pn,ciphertext,cn,encdec) - && !test_digest(cipher,plaintext,pn,ciphertext,cn)) - { -#ifdef OPENSSL_NO_AES - if (strstr(cipher, "AES") == cipher) - { - fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); - continue; - } -#endif -#ifdef OPENSSL_NO_DES - if (strstr(cipher, "DES") == cipher) - { - fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); - continue; - } -#endif -#ifdef OPENSSL_NO_RC4 - if (strstr(cipher, "RC4") == cipher) - { - fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); - continue; - } -#endif -#ifdef OPENSSL_NO_CAMELLIA - if (strstr(cipher, "CAMELLIA") == cipher) - { - fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); - continue; - } -#endif -#ifdef OPENSSL_NO_SEED - if (strstr(cipher, "SEED") == cipher) - { - fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); - continue; - } -#endif - fprintf(stderr,"Can't find %s\n",cipher); - EXIT(3); - } - } - fclose(f); - -#ifndef OPENSSL_NO_ENGINE - ENGINE_cleanup(); -#endif - EVP_cleanup(); - CRYPTO_cleanup_all_ex_data(); - ERR_remove_thread_state(NULL); - ERR_free_strings(); - CRYPTO_mem_leaks_fp(stderr); - - return 0; - } diff --git a/src/lib/libcrypto/hmac/hmactest.c b/src/lib/libcrypto/hmac/hmactest.c deleted file mode 100644 index 282e06e53e..0000000000 --- a/src/lib/libcrypto/hmac/hmactest.c +++ /dev/null @@ -1,164 +0,0 @@ -/* crypto/hmac/hmactest.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include -#include -#include - -#include "../e_os.h" - -#ifdef OPENSSL_NO_HMAC -int main(int argc, char *argv[]) -{ - printf("No HMAC support\n"); - return(0); -} -#else -#include -#ifndef OPENSSL_NO_MD5 -#include -#endif - - -#ifndef OPENSSL_NO_MD5 -static struct test_st - { - unsigned char key[16]; - int key_len; - unsigned char data[64]; - int data_len; - unsigned char *digest; - } test[4]={ - { "", - 0, - "More text test vectors to stuff up EBCDIC machines :-)", - 54, - (unsigned char *)"e9139d1e6ee064ef8cf514fc7dc83e86", - },{ {0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b, - 0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,}, - 16, - "Hi There", - 8, - (unsigned char *)"9294727a3638bb1c13f48ef8158bfc9d", - },{ "Jefe", - 4, - "what do ya want for nothing?", - 28, - (unsigned char *)"750c783e6ab0b503eaa86e310a5db738", - },{ - {0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa, - 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,}, - 16, - {0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd, - 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd, - 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd, - 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd, - 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd, - 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd, - 0xdd,0xdd}, - 50, - (unsigned char *)"56be34521d144c88dbb8c733f0e8b3f6", - }, - }; -#endif - -static char *pt(unsigned char *md); -int main(int argc, char *argv[]) - { -#ifndef OPENSSL_NO_MD5 - int i; - char *p; -#endif - int err=0; - -#ifdef OPENSSL_NO_MD5 - printf("test skipped: MD5 disabled\n"); -#else - for (i=0; i<4; i++) - { - p=pt(HMAC(EVP_md5(), - test[i].key, test[i].key_len, - test[i].data, test[i].data_len, - NULL,NULL)); - - if (strcmp(p,(char *)test[i].digest) != 0) - { - printf("error calculating HMAC on %d entry'\n",i); - printf("got %s instead of %s\n",p,test[i].digest); - err++; - } - else - printf("test %d ok\n",i); - } -#endif /* OPENSSL_NO_MD5 */ - EXIT(err); - return(0); - } - -#ifndef OPENSSL_NO_MD5 -static char *pt(unsigned char *md) - { - int i; - static char buf[80]; - - for (i=0; i -#include -#include - -#include "../e_os.h" - -#ifdef OPENSSL_NO_IDEA -int main(int argc, char *argv[]) -{ - printf("No IDEA support\n"); - return(0); -} -#else -#include - -unsigned char k[16]={ - 0x00,0x01,0x00,0x02,0x00,0x03,0x00,0x04, - 0x00,0x05,0x00,0x06,0x00,0x07,0x00,0x08}; - -unsigned char in[8]={0x00,0x00,0x00,0x01,0x00,0x02,0x00,0x03}; -unsigned char c[8]={0x11,0xFB,0xED,0x2B,0x01,0x98,0x6D,0xE5}; -unsigned char out[80]; - -char *text="Hello to all people out there"; - -static unsigned char cfb_key[16]={ - 0xe1,0xf0,0xc3,0xd2,0xa5,0xb4,0x87,0x96, - 0x69,0x78,0x4b,0x5a,0x2d,0x3c,0x0f,0x1e, - }; -static unsigned char cfb_iv[80]={0x34,0x12,0x78,0x56,0xab,0x90,0xef,0xcd}; -static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8]; -#define CFB_TEST_SIZE 24 -static unsigned char plain[CFB_TEST_SIZE]= - { - 0x4e,0x6f,0x77,0x20,0x69,0x73, - 0x20,0x74,0x68,0x65,0x20,0x74, - 0x69,0x6d,0x65,0x20,0x66,0x6f, - 0x72,0x20,0x61,0x6c,0x6c,0x20 - }; -static unsigned char cfb_cipher64[CFB_TEST_SIZE]={ - 0x59,0xD8,0xE2,0x65,0x00,0x58,0x6C,0x3F, - 0x2C,0x17,0x25,0xD0,0x1A,0x38,0xB7,0x2A, - 0x39,0x61,0x37,0xDC,0x79,0xFB,0x9F,0x45 - -/* 0xF9,0x78,0x32,0xB5,0x42,0x1A,0x6B,0x38, - 0x9A,0x44,0xD6,0x04,0x19,0x43,0xC4,0xD9, - 0x3D,0x1E,0xAE,0x47,0xFC,0xCF,0x29,0x0B,*/ - }; - -static int cfb64_test(unsigned char *cfb_cipher); -static char *pt(unsigned char *p); -int main(int argc, char *argv[]) - { - int i,err=0; - IDEA_KEY_SCHEDULE key,dkey; - unsigned char iv[8]; - - idea_set_encrypt_key(k,&key); - idea_ecb_encrypt(in,out,&key); - if (memcmp(out,c,8) != 0) - { - printf("ecb idea error encrypting\n"); - printf("got :"); - for (i=0; i<8; i++) - printf("%02X ",out[i]); - printf("\n"); - printf("expected:"); - for (i=0; i<8; i++) - printf("%02X ",c[i]); - err=20; - printf("\n"); - } - - idea_set_decrypt_key(&key,&dkey); - idea_ecb_encrypt(c,out,&dkey); - if (memcmp(out,in,8) != 0) - { - printf("ecb idea error decrypting\n"); - printf("got :"); - for (i=0; i<8; i++) - printf("%02X ",out[i]); - printf("\n"); - printf("expected:"); - for (i=0; i<8; i++) - printf("%02X ",in[i]); - printf("\n"); - err=3; - } - - if (err == 0) printf("ecb idea ok\n"); - - memcpy(iv,k,8); - idea_cbc_encrypt((unsigned char *)text,out,strlen(text)+1,&key,iv,1); - memcpy(iv,k,8); - idea_cbc_encrypt(out,out,8,&dkey,iv,0); - idea_cbc_encrypt(&(out[8]),&(out[8]),strlen(text)+1-8,&dkey,iv,0); - if (memcmp(text,out,strlen(text)+1) != 0) - { - printf("cbc idea bad\n"); - err=4; - } - else - printf("cbc idea ok\n"); - - printf("cfb64 idea "); - if (cfb64_test(cfb_cipher64)) - { - printf("bad\n"); - err=5; - } - else - printf("ok\n"); - -#ifdef OPENSSL_SYS_NETWARE - if (err) printf("ERROR: %d\n", err); -#endif - EXIT(err); - return(err); - } - -static int cfb64_test(unsigned char *cfb_cipher) - { - IDEA_KEY_SCHEDULE eks,dks; - int err=0,i,n; - - idea_set_encrypt_key(cfb_key,&eks); - idea_set_decrypt_key(&eks,&dks); - memcpy(cfb_tmp,cfb_iv,8); - n=0; - idea_cfb64_encrypt(plain,cfb_buf1,(long)12,&eks, - cfb_tmp,&n,IDEA_ENCRYPT); - idea_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]), - (long)CFB_TEST_SIZE-12,&eks, - cfb_tmp,&n,IDEA_ENCRYPT); - if (memcmp(cfb_cipher,cfb_buf1,CFB_TEST_SIZE) != 0) - { - err=1; - printf("idea_cfb64_encrypt encrypt error\n"); - for (i=0; i>4)&0xf]; - ret[i*2+1]=f[p[i]&0xf]; - } - ret[16]='\0'; - return(ret); - } -#endif diff --git a/src/lib/libcrypto/md2/md2test.c b/src/lib/libcrypto/md2/md2test.c deleted file mode 100644 index 0195214036..0000000000 --- a/src/lib/libcrypto/md2/md2test.c +++ /dev/null @@ -1,139 +0,0 @@ -/* crypto/md2/md2test.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include -#include -#include - -#include "../e_os.h" - -#ifdef OPENSSL_NO_MD2 -int main(int argc, char *argv[]) -{ - printf("No MD2 support\n"); - return(0); -} -#else -#include -#include - -static char *test[]={ - "", - "a", - "abc", - "message digest", - "abcdefghijklmnopqrstuvwxyz", - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", - "12345678901234567890123456789012345678901234567890123456789012345678901234567890", - NULL, - }; - -static char *ret[]={ - "8350e5a3e24c153df2275c9f80692773", - "32ec01ec4a6dac72c0ab96fb34c0b5d1", - "da853b0d3f88d99b30283a69e6ded6bb", - "ab4f496bfb2a530b219ff33031fe06b0", - "4e8ddff3650292ab5a4108c3aa47940b", - "da33def2a42df13975352846c30338cd", - "d5976f79d83d3a0dc9806c3c66f3efd8", - }; - -static char *pt(unsigned char *md); -int main(int argc, char *argv[]) - { - int i,err=0; - char **P,**R; - char *p; - unsigned char md[MD2_DIGEST_LENGTH]; - - P=test; - R=ret; - i=1; - while (*P != NULL) - { - EVP_Digest((unsigned char *)*P,strlen(*P),md,NULL,EVP_md2(), NULL); - p=pt(md); - if (strcmp(p,*R) != 0) - { - printf("error calculating MD2 on '%s'\n",*P); - printf("got %s instead of %s\n",p,*R); - err++; - } - else - printf("test %d ok\n",i); - i++; - R++; - P++; - } -#ifdef OPENSSL_SYS_NETWARE - if (err) printf("ERROR: %d\n", err); -#endif - EXIT(err); - return err; - } - -static char *pt(unsigned char *md) - { - int i; - static char buf[80]; - - for (i=0; i -#include -#include - -#include "../e_os.h" - -#ifdef OPENSSL_NO_MD4 -int main(int argc, char *argv[]) -{ - printf("No MD4 support\n"); - return(0); -} -#else -#include -#include - -static char *test[]={ - "", - "a", - "abc", - "message digest", - "abcdefghijklmnopqrstuvwxyz", - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", - "12345678901234567890123456789012345678901234567890123456789012345678901234567890", - NULL, - }; - -static char *ret[]={ -"31d6cfe0d16ae931b73c59d7e0c089c0", -"bde52cb31de33e46245e05fbdbd6fb24", -"a448017aaf21d8525fc10ae87aa6729d", -"d9130a8164549fe818874806e1c7014b", -"d79e1c308aa5bbcdeea8ed63df412da9", -"043f8582f241db351ce627e153e7f0e4", -"e33b4ddc9c38f2199c3e7b164fcc0536", -}; - -static char *pt(unsigned char *md); -int main(int argc, char *argv[]) - { - int i,err=0; - char **P,**R; - char *p; - unsigned char md[MD4_DIGEST_LENGTH]; - - P=test; - R=ret; - i=1; - while (*P != NULL) - { - EVP_Digest(&(P[0][0]),strlen((char *)*P),md,NULL,EVP_md4(), NULL); - p=pt(md); - if (strcmp(p,(char *)*R) != 0) - { - printf("error calculating MD4 on '%s'\n",*P); - printf("got %s instead of %s\n",p,*R); - err++; - } - else - printf("test %d ok\n",i); - i++; - R++; - P++; - } - EXIT(err); - return(0); - } - -static char *pt(unsigned char *md) - { - int i; - static char buf[80]; - - for (i=0; i -#include -#include - -#include "../e_os.h" - -#ifdef OPENSSL_NO_MD5 -int main(int argc, char *argv[]) -{ - printf("No MD5 support\n"); - return(0); -} -#else -#include -#include - -static char *test[]={ - "", - "a", - "abc", - "message digest", - "abcdefghijklmnopqrstuvwxyz", - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", - "12345678901234567890123456789012345678901234567890123456789012345678901234567890", - NULL, - }; - -static char *ret[]={ - "d41d8cd98f00b204e9800998ecf8427e", - "0cc175b9c0f1b6a831c399e269772661", - "900150983cd24fb0d6963f7d28e17f72", - "f96b697d7cb7938d525a2f31aaf161d0", - "c3fcd3d76192e4007dfb496cca67e13b", - "d174ab98d277d9f5a5611c2c9f419d9f", - "57edf4a22be3c955ac49da2e2107b67a", - }; - -static char *pt(unsigned char *md); -int main(int argc, char *argv[]) - { - int i,err=0; - char **P,**R; - char *p; - unsigned char md[MD5_DIGEST_LENGTH]; - - P=test; - R=ret; - i=1; - while (*P != NULL) - { - EVP_Digest(&(P[0][0]),strlen((char *)*P),md,NULL,EVP_md5(), NULL); - p=pt(md); - if (strcmp(p,(char *)*R) != 0) - { - printf("error calculating MD5 on '%s'\n",*P); - printf("got %s instead of %s\n",p,*R); - err++; - } - else - printf("test %d ok\n",i); - i++; - R++; - P++; - } - -#ifdef OPENSSL_SYS_NETWARE - if (err) printf("ERROR: %d\n", err); -#endif - EXIT(err); - return(0); - } - -static char *pt(unsigned char *md) - { - int i; - static char buf[80]; - - for (i=0; i -#include -#include - -#include "../e_os.h" - -#if defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_MDC2) -#define OPENSSL_NO_MDC2 -#endif - -#ifdef OPENSSL_NO_MDC2 -int main(int argc, char *argv[]) -{ - printf("No MDC2 support\n"); - return(0); -} -#else -#include -#include - -static unsigned char pad1[16]={ - 0x42,0xE5,0x0C,0xD2,0x24,0xBA,0xCE,0xBA, - 0x76,0x0B,0xDD,0x2B,0xD4,0x09,0x28,0x1A - }; - -static unsigned char pad2[16]={ - 0x2E,0x46,0x79,0xB5,0xAD,0xD9,0xCA,0x75, - 0x35,0xD8,0x7A,0xFE,0xAB,0x33,0xBE,0xE2 - }; - -int main(int argc, char *argv[]) - { - int ret=0; - unsigned char md[MDC2_DIGEST_LENGTH]; - int i; - EVP_MD_CTX c; - static char *text="Now is the time for all "; - - EVP_MD_CTX_init(&c); - EVP_DigestInit_ex(&c,EVP_mdc2(), NULL); - EVP_DigestUpdate(&c,(unsigned char *)text,strlen(text)); - EVP_DigestFinal_ex(&c,&(md[0]),NULL); - - if (memcmp(md,pad1,MDC2_DIGEST_LENGTH) != 0) - { - for (i=0; ipad_type=2; - EVP_DigestUpdate(&c,(unsigned char *)text,strlen(text)); - EVP_DigestFinal_ex(&c,&(md[0]),NULL); - - if (memcmp(md,pad2,MDC2_DIGEST_LENGTH) != 0) - { - for (i=0; i -#include -#include - -#include "../e_os.h" - -/* some FIPS 140-1 random number test */ -/* some simple tests */ - -int main(int argc,char **argv) - { - unsigned char buf[2500]; - int i,j,k,s,sign,nsign,err=0; - unsigned long n1; - unsigned long n2[16]; - unsigned long runs[2][34]; - /*double d; */ - long d; - - i = RAND_pseudo_bytes(buf,2500); - if (i < 0) - { - printf ("init failed, the rand method is not properly installed\n"); - err++; - goto err; - } - - n1=0; - for (i=0; i<16; i++) n2[i]=0; - for (i=0; i<34; i++) runs[0][i]=runs[1][i]=0; - - /* test 1 and 2 */ - sign=0; - nsign=0; - for (i=0; i<2500; i++) - { - j=buf[i]; - - n2[j&0x0f]++; - n2[(j>>4)&0x0f]++; - - for (k=0; k<8; k++) - { - s=(j&0x01); - if (s == sign) - nsign++; - else - { - if (nsign > 34) nsign=34; - if (nsign != 0) - { - runs[sign][nsign-1]++; - if (nsign > 6) - runs[sign][5]++; - } - sign=s; - nsign=1; - } - - if (s) n1++; - j>>=1; - } - } - if (nsign > 34) nsign=34; - if (nsign != 0) runs[sign][nsign-1]++; - - /* test 1 */ - if (!((9654 < n1) && (n1 < 10346))) - { - printf("test 1 failed, X=%lu\n",n1); - err++; - } - printf("test 1 done\n"); - - /* test 2 */ -#ifdef undef - d=0; - for (i=0; i<16; i++) - d+=n2[i]*n2[i]; - d=d*16.0/5000.0-5000.0; - if (!((1.03 < d) && (d < 57.4))) - { - printf("test 2 failed, X=%.2f\n",d); - err++; - } -#endif - d=0; - for (i=0; i<16; i++) - d+=n2[i]*n2[i]; - d=(d*8)/25-500000; - if (!((103 < d) && (d < 5740))) - { - printf("test 2 failed, X=%ld.%02ld\n",d/100L,d%100L); - err++; - } - printf("test 2 done\n"); - - /* test 3 */ - for (i=0; i<2; i++) - { - if (!((2267 < runs[i][0]) && (runs[i][0] < 2733))) - { - printf("test 3 failed, bit=%d run=%d num=%lu\n", - i,1,runs[i][0]); - err++; - } - if (!((1079 < runs[i][1]) && (runs[i][1] < 1421))) - { - printf("test 3 failed, bit=%d run=%d num=%lu\n", - i,2,runs[i][1]); - err++; - } - if (!(( 502 < runs[i][2]) && (runs[i][2] < 748))) - { - printf("test 3 failed, bit=%d run=%d num=%lu\n", - i,3,runs[i][2]); - err++; - } - if (!(( 223 < runs[i][3]) && (runs[i][3] < 402))) - { - printf("test 3 failed, bit=%d run=%d num=%lu\n", - i,4,runs[i][3]); - err++; - } - if (!(( 90 < runs[i][4]) && (runs[i][4] < 223))) - { - printf("test 3 failed, bit=%d run=%d num=%lu\n", - i,5,runs[i][4]); - err++; - } - if (!(( 90 < runs[i][5]) && (runs[i][5] < 223))) - { - printf("test 3 failed, bit=%d run=%d num=%lu\n", - i,6,runs[i][5]); - err++; - } - } - printf("test 3 done\n"); - - /* test 4 */ - if (runs[0][33] != 0) - { - printf("test 4 failed, bit=%d run=%d num=%lu\n", - 0,34,runs[0][33]); - err++; - } - if (runs[1][33] != 0) - { - printf("test 4 failed, bit=%d run=%d num=%lu\n", - 1,34,runs[1][33]); - err++; - } - printf("test 4 done\n"); - err: - err=((err)?1:0); -#ifdef OPENSSL_SYS_NETWARE - if (err) printf("ERROR: %d\n", err); -#endif - EXIT(err); - return(err); - } diff --git a/src/lib/libcrypto/rc2/rc2test.c b/src/lib/libcrypto/rc2/rc2test.c deleted file mode 100644 index 0e117436bb..0000000000 --- a/src/lib/libcrypto/rc2/rc2test.c +++ /dev/null @@ -1,274 +0,0 @@ -/* crypto/rc2/rc2test.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.] - */ - -/* This has been a quickly hacked 'ideatest.c'. When I add tests for other - * RC2 modes, more of the code will be uncommented. */ - -#include -#include -#include - -#include "../e_os.h" - -#ifdef OPENSSL_NO_RC2 -int main(int argc, char *argv[]) -{ - printf("No RC2 support\n"); - return(0); -} -#else -#include - -static unsigned char RC2key[4][16]={ - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, - 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F}, - }; - -static unsigned char RC2plain[4][8]={ - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - }; - -static unsigned char RC2cipher[4][8]={ - {0x1C,0x19,0x8A,0x83,0x8D,0xF0,0x28,0xB7}, - {0x21,0x82,0x9C,0x78,0xA9,0xF9,0xC0,0x74}, - {0x13,0xDB,0x35,0x17,0xD3,0x21,0x86,0x9E}, - {0x50,0xDC,0x01,0x62,0xBD,0x75,0x7F,0x31}, - }; -/************/ -#ifdef undef -unsigned char k[16]={ - 0x00,0x01,0x00,0x02,0x00,0x03,0x00,0x04, - 0x00,0x05,0x00,0x06,0x00,0x07,0x00,0x08}; - -unsigned char in[8]={0x00,0x00,0x00,0x01,0x00,0x02,0x00,0x03}; -unsigned char c[8]={0x11,0xFB,0xED,0x2B,0x01,0x98,0x6D,0xE5}; -unsigned char out[80]; - -char *text="Hello to all people out there"; - -static unsigned char cfb_key[16]={ - 0xe1,0xf0,0xc3,0xd2,0xa5,0xb4,0x87,0x96, - 0x69,0x78,0x4b,0x5a,0x2d,0x3c,0x0f,0x1e, - }; -static unsigned char cfb_iv[80]={0x34,0x12,0x78,0x56,0xab,0x90,0xef,0xcd}; -static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8]; -#define CFB_TEST_SIZE 24 -static unsigned char plain[CFB_TEST_SIZE]= - { - 0x4e,0x6f,0x77,0x20,0x69,0x73, - 0x20,0x74,0x68,0x65,0x20,0x74, - 0x69,0x6d,0x65,0x20,0x66,0x6f, - 0x72,0x20,0x61,0x6c,0x6c,0x20 - }; -static unsigned char cfb_cipher64[CFB_TEST_SIZE]={ - 0x59,0xD8,0xE2,0x65,0x00,0x58,0x6C,0x3F, - 0x2C,0x17,0x25,0xD0,0x1A,0x38,0xB7,0x2A, - 0x39,0x61,0x37,0xDC,0x79,0xFB,0x9F,0x45 - -/* 0xF9,0x78,0x32,0xB5,0x42,0x1A,0x6B,0x38, - 0x9A,0x44,0xD6,0x04,0x19,0x43,0xC4,0xD9, - 0x3D,0x1E,0xAE,0x47,0xFC,0xCF,0x29,0x0B,*/ - }; - - -/*static int cfb64_test(unsigned char *cfb_cipher);*/ -static char *pt(unsigned char *p); -#endif - -int main(int argc, char *argv[]) - { - int i,n,err=0; - RC2_KEY key; - unsigned char buf[8],buf2[8]; - - for (n=0; n<4; n++) - { - RC2_set_key(&key,16,&(RC2key[n][0]),0 /* or 1024 */); - - RC2_ecb_encrypt(&(RC2plain[n][0]),buf,&key,RC2_ENCRYPT); - if (memcmp(&(RC2cipher[n][0]),buf,8) != 0) - { - printf("ecb rc2 error encrypting\n"); - printf("got :"); - for (i=0; i<8; i++) - printf("%02X ",buf[i]); - printf("\n"); - printf("expected:"); - for (i=0; i<8; i++) - printf("%02X ",RC2cipher[n][i]); - err=20; - printf("\n"); - } - - RC2_ecb_encrypt(buf,buf2,&key,RC2_DECRYPT); - if (memcmp(&(RC2plain[n][0]),buf2,8) != 0) - { - printf("ecb RC2 error decrypting\n"); - printf("got :"); - for (i=0; i<8; i++) - printf("%02X ",buf[i]); - printf("\n"); - printf("expected:"); - for (i=0; i<8; i++) - printf("%02X ",RC2plain[n][i]); - printf("\n"); - err=3; - } - } - - if (err == 0) printf("ecb RC2 ok\n"); -#ifdef undef - memcpy(iv,k,8); - idea_cbc_encrypt((unsigned char *)text,out,strlen(text)+1,&key,iv,1); - memcpy(iv,k,8); - idea_cbc_encrypt(out,out,8,&dkey,iv,0); - idea_cbc_encrypt(&(out[8]),&(out[8]),strlen(text)+1-8,&dkey,iv,0); - if (memcmp(text,out,strlen(text)+1) != 0) - { - printf("cbc idea bad\n"); - err=4; - } - else - printf("cbc idea ok\n"); - - printf("cfb64 idea "); - if (cfb64_test(cfb_cipher64)) - { - printf("bad\n"); - err=5; - } - else - printf("ok\n"); -#endif - -#ifdef OPENSSL_SYS_NETWARE - if (err) printf("ERROR: %d\n", err); -#endif - EXIT(err); - return(err); - } - -#ifdef undef -static int cfb64_test(unsigned char *cfb_cipher) - { - IDEA_KEY_SCHEDULE eks,dks; - int err=0,i,n; - - idea_set_encrypt_key(cfb_key,&eks); - idea_set_decrypt_key(&eks,&dks); - memcpy(cfb_tmp,cfb_iv,8); - n=0; - idea_cfb64_encrypt(plain,cfb_buf1,(long)12,&eks, - cfb_tmp,&n,IDEA_ENCRYPT); - idea_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]), - (long)CFB_TEST_SIZE-12,&eks, - cfb_tmp,&n,IDEA_ENCRYPT); - if (memcmp(cfb_cipher,cfb_buf1,CFB_TEST_SIZE) != 0) - { - err=1; - printf("idea_cfb64_encrypt encrypt error\n"); - for (i=0; i>4)&0xf]; - ret[i*2+1]=f[p[i]&0xf]; - } - ret[16]='\0'; - return(ret); - } - -#endif -#endif diff --git a/src/lib/libcrypto/rc4/rc4test.c b/src/lib/libcrypto/rc4/rc4test.c deleted file mode 100644 index 4312605ccb..0000000000 --- a/src/lib/libcrypto/rc4/rc4test.c +++ /dev/null @@ -1,242 +0,0 @@ -/* crypto/rc4/rc4test.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include -#include -#include - -#include "../e_os.h" - -#ifdef OPENSSL_NO_RC4 -int main(int argc, char *argv[]) -{ - printf("No RC4 support\n"); - return(0); -} -#else -#include -#include - -static unsigned char keys[7][30]={ - {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}, - {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}, - {8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {4,0xef,0x01,0x23,0x45}, - {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}, - {4,0xef,0x01,0x23,0x45}, - }; - -static unsigned char data_len[7]={8,8,8,20,28,10}; -static unsigned char data[7][30]={ - {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0xff}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0xff}, - {0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF0, - 0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF0, - 0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF0, - 0x12,0x34,0x56,0x78,0xff}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff}, - {0}, - }; - -static unsigned char output[7][30]={ - {0x75,0xb7,0x87,0x80,0x99,0xe0,0xc5,0x96,0x00}, - {0x74,0x94,0xc2,0xe7,0x10,0x4b,0x08,0x79,0x00}, - {0xde,0x18,0x89,0x41,0xa3,0x37,0x5d,0x3a,0x00}, - {0xd6,0xa1,0x41,0xa7,0xec,0x3c,0x38,0xdf, - 0xbd,0x61,0x5a,0x11,0x62,0xe1,0xc7,0xba, - 0x36,0xb6,0x78,0x58,0x00}, - {0x66,0xa0,0x94,0x9f,0x8a,0xf7,0xd6,0x89, - 0x1f,0x7f,0x83,0x2b,0xa8,0x33,0xc0,0x0c, - 0x89,0x2e,0xbe,0x30,0x14,0x3c,0xe2,0x87, - 0x40,0x01,0x1e,0xcf,0x00}, - {0xd6,0xa1,0x41,0xa7,0xec,0x3c,0x38,0xdf,0xbd,0x61,0x00}, - {0}, - }; - -int main(int argc, char *argv[]) - { - int i,err=0; - int j; - unsigned char *p; - RC4_KEY key; - unsigned char obuf[512]; - -#if !defined(OPENSSL_PIC) - void OPENSSL_cpuid_setup(void); - - OPENSSL_cpuid_setup(); -#endif - - for (i=0; i<6; i++) - { - RC4_set_key(&key,keys[i][0],&(keys[i][1])); - memset(obuf,0x00,sizeof(obuf)); - RC4(&key,data_len[i],&(data[i][0]),obuf); - if (memcmp(obuf,output[i],data_len[i]+1) != 0) - { - printf("error calculating RC4\n"); - printf("output:"); - for (j=0; j -#include -#include - -#include "../e_os.h" - -#ifdef OPENSSL_NO_RIPEMD -int main(int argc, char *argv[]) -{ - printf("No ripemd support\n"); - return(0); -} -#else -#include -#include - -static char *test[]={ - "", - "a", - "abc", - "message digest", - "abcdefghijklmnopqrstuvwxyz", - "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", - "12345678901234567890123456789012345678901234567890123456789012345678901234567890", - NULL, - }; - -static char *ret[]={ - "9c1185a5c5e9fc54612808977ee8f548b2258d31", - "0bdc9d2d256b3ee9daae347be6f4dc835a467ffe", - "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc", - "5d0689ef49d2fae572b881b123a85ffa21595f36", - "f71c27109c692c1b56bbdceb5b9d2865b3708dbc", - "12a053384a9c0c88e405a06c27dcf49ada62eb2b", - "b0e20b6e3116640286ed3a87a5713079b21f5189", - "9b752e45573d4b39f4dbd3323cab82bf63326bfb", - }; - -static char *pt(unsigned char *md); -int main(int argc, char *argv[]) - { - int i,err=0; - char **P,**R; - char *p; - unsigned char md[RIPEMD160_DIGEST_LENGTH]; - - P=test; - R=ret; - i=1; - while (*P != NULL) - { - EVP_Digest(&(P[0][0]),strlen((char *)*P),md,NULL,EVP_ripemd160(), NULL); - p=pt(md); - if (strcmp(p,(char *)*R) != 0) - { - printf("error calculating RIPEMD160 on '%s'\n",*P); - printf("got %s instead of %s\n",p,*R); - err++; - } - else - printf("test %d ok\n",i); - i++; - R++; - P++; - } - EXIT(err); - return(0); - } - -static char *pt(unsigned char *md) - { - int i; - static char buf[80]; - - for (i=0; i -#include -#include - -#include "../e_os.h" - -#ifdef OPENSSL_NO_SHA -int main(int argc, char *argv[]) -{ - printf("No SHA support\n"); - return(0); -} -#else -#include -#include - -#undef SHA_0 /* FIPS 180 */ -#define SHA_1 /* FIPS 180-1 */ - -static char *test[]={ - "abc", - "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", - NULL, - }; - -#ifdef SHA_0 -static char *ret[]={ - "0164b8a914cd2a5e74c4f7ff082c4d97f1edf880", - "d2516ee1acfa5baf33dfc1c471e438449ef134c8", - }; -static char *bigret= - "3232affa48628a26653b5aaa44541fd90d690603"; -#endif -#ifdef SHA_1 -static char *ret[]={ - "a9993e364706816aba3e25717850c26c9cd0d89d", - "84983e441c3bd26ebaae4aa1f95129e5e54670f1", - }; -static char *bigret= - "34aa973cd4c4daa4f61eeb2bdbad27316534016f"; -#endif - -static char *pt(unsigned char *md); -int main(int argc, char *argv[]) - { - int i,err=0; - char **P,**R; - static unsigned char buf[1000]; - char *p,*r; - EVP_MD_CTX c; - unsigned char md[SHA_DIGEST_LENGTH]; - - EVP_MD_CTX_init(&c); - P=test; - R=ret; - i=1; - while (*P != NULL) - { - EVP_Digest(*P,strlen((char *)*P),md,NULL,EVP_sha1(), NULL); - p=pt(md); - if (strcmp(p,(char *)*R) != 0) - { - printf("error calculating SHA1 on '%s'\n",*P); - printf("got %s instead of %s\n",p,*R); - err++; - } - else - printf("test %d ok\n",i); - i++; - R++; - P++; - } - - memset(buf,'a',1000); - EVP_DigestInit_ex(&c,EVP_sha1(), NULL); - for (i=0; i<1000; i++) - EVP_DigestUpdate(&c,buf,1000); - EVP_DigestFinal_ex(&c,md,NULL); - p=pt(md); - - r=bigret; - if (strcmp(p,r) != 0) - { - printf("error calculating SHA1 on 'a' * 1000\n"); - printf("got %s instead of %s\n",p,r); - err++; - } - else - printf("test 3 ok\n"); - -#ifdef OPENSSL_SYS_NETWARE - if (err) printf("ERROR: %d\n", err); -#endif - EXIT(err); - EVP_MD_CTX_cleanup(&c); - return(0); - } - -static char *pt(unsigned char *md) - { - int i; - static char buf[80]; - - for (i=0; i -#include -#include - -#include "../e_os.h" - -#if defined(OPENSSL_NO_SHA) || defined(OPENSSL_NO_SHA0) -int main(int argc, char *argv[]) -{ - printf("No SHA0 support\n"); - return(0); -} -#else -#include -#include - -#define SHA_0 /* FIPS 180 */ -#undef SHA_1 /* FIPS 180-1 */ - -static char *test[]={ - "abc", - "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", - NULL, - }; - -#ifdef SHA_0 -static char *ret[]={ - "0164b8a914cd2a5e74c4f7ff082c4d97f1edf880", - "d2516ee1acfa5baf33dfc1c471e438449ef134c8", - }; -static char *bigret= - "3232affa48628a26653b5aaa44541fd90d690603"; -#endif -#ifdef SHA_1 -static char *ret[]={ - "a9993e364706816aba3e25717850c26c9cd0d89d", - "84983e441c3bd26ebaae4aa1f95129e5e54670f1", - }; -static char *bigret= - "34aa973cd4c4daa4f61eeb2bdbad27316534016f"; -#endif - -static char *pt(unsigned char *md); -int main(int argc, char *argv[]) - { - int i,err=0; - char **P,**R; - static unsigned char buf[1000]; - char *p,*r; - EVP_MD_CTX c; - unsigned char md[SHA_DIGEST_LENGTH]; - - EVP_MD_CTX_init(&c); - P=test; - R=ret; - i=1; - while (*P != NULL) - { - EVP_Digest(*P,strlen(*P),md,NULL,EVP_sha(), NULL); - p=pt(md); - if (strcmp(p,*R) != 0) - { - printf("error calculating SHA on '%s'\n",*P); - printf("got %s instead of %s\n",p,*R); - err++; - } - else - printf("test %d ok\n",i); - i++; - R++; - P++; - } - - memset(buf,'a',1000); - EVP_DigestInit_ex(&c,EVP_sha(), NULL); - for (i=0; i<1000; i++) - EVP_DigestUpdate(&c,buf,1000); - EVP_DigestFinal_ex(&c,md,NULL); - p=pt(md); - - r=bigret; - if (strcmp(p,r) != 0) - { - printf("error calculating SHA on '%s'\n",p); - printf("got %s instead of %s\n",p,r); - err++; - } - else - printf("test 3 ok\n"); - -#ifdef OPENSSL_SYS_NETWARE - if (err) printf("ERROR: %d\n", err); -#endif - EVP_MD_CTX_cleanup(&c); - EXIT(err); - return(0); - } - -static char *pt(unsigned char *md) - { - int i; - static char buf[80]; - - for (i=0; i -#include -#include -#include /* To see if OPENSSL_NO_BF is defined */ - -#include "../e_os.h" - -#ifdef OPENSSL_NO_BF -int main(int argc, char *argv[]) -{ - printf("No BF support\n"); - return(0); -} -#else -#include - -static char *bf_key[2]={ - "abcdefghijklmnopqrstuvwxyz", - "Who is John Galt?" - }; - -/* big endian */ -static BF_LONG bf_plain[2][2]={ - {0x424c4f57L,0x46495348L}, - {0xfedcba98L,0x76543210L} - }; - -static BF_LONG bf_cipher[2][2]={ - {0x324ed0feL,0xf413a203L}, - {0xcc91732bL,0x8022f684L} - }; -/************/ - -/* Lets use the DES test vectors :-) */ -#define NUM_TESTS 34 -static unsigned char ecb_data[NUM_TESTS][8]={ - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, - {0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}, - {0x7C,0xA1,0x10,0x45,0x4A,0x1A,0x6E,0x57}, - {0x01,0x31,0xD9,0x61,0x9D,0xC1,0x37,0x6E}, - {0x07,0xA1,0x13,0x3E,0x4A,0x0B,0x26,0x86}, - {0x38,0x49,0x67,0x4C,0x26,0x02,0x31,0x9E}, - {0x04,0xB9,0x15,0xBA,0x43,0xFE,0xB5,0xB6}, - {0x01,0x13,0xB9,0x70,0xFD,0x34,0xF2,0xCE}, - {0x01,0x70,0xF1,0x75,0x46,0x8F,0xB5,0xE6}, - {0x43,0x29,0x7F,0xAD,0x38,0xE3,0x73,0xFE}, - {0x07,0xA7,0x13,0x70,0x45,0xDA,0x2A,0x16}, - {0x04,0x68,0x91,0x04,0xC2,0xFD,0x3B,0x2F}, - {0x37,0xD0,0x6B,0xB5,0x16,0xCB,0x75,0x46}, - {0x1F,0x08,0x26,0x0D,0x1A,0xC2,0x46,0x5E}, - {0x58,0x40,0x23,0x64,0x1A,0xBA,0x61,0x76}, - {0x02,0x58,0x16,0x16,0x46,0x29,0xB0,0x07}, - {0x49,0x79,0x3E,0xBC,0x79,0xB3,0x25,0x8F}, - {0x4F,0xB0,0x5E,0x15,0x15,0xAB,0x73,0xA7}, - {0x49,0xE9,0x5D,0x6D,0x4C,0xA2,0x29,0xBF}, - {0x01,0x83,0x10,0xDC,0x40,0x9B,0x26,0xD6}, - {0x1C,0x58,0x7F,0x1C,0x13,0x92,0x4F,0xEF}, - {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01}, - {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E}, - {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}}; - -static unsigned char plain_data[NUM_TESTS][8]={ - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, - {0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01}, - {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, - {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0x01,0xA1,0xD6,0xD0,0x39,0x77,0x67,0x42}, - {0x5C,0xD5,0x4C,0xA8,0x3D,0xEF,0x57,0xDA}, - {0x02,0x48,0xD4,0x38,0x06,0xF6,0x71,0x72}, - {0x51,0x45,0x4B,0x58,0x2D,0xDF,0x44,0x0A}, - {0x42,0xFD,0x44,0x30,0x59,0x57,0x7F,0xA2}, - {0x05,0x9B,0x5E,0x08,0x51,0xCF,0x14,0x3A}, - {0x07,0x56,0xD8,0xE0,0x77,0x47,0x61,0xD2}, - {0x76,0x25,0x14,0xB8,0x29,0xBF,0x48,0x6A}, - {0x3B,0xDD,0x11,0x90,0x49,0x37,0x28,0x02}, - {0x26,0x95,0x5F,0x68,0x35,0xAF,0x60,0x9A}, - {0x16,0x4D,0x5E,0x40,0x4F,0x27,0x52,0x32}, - {0x6B,0x05,0x6E,0x18,0x75,0x9F,0x5C,0xCA}, - {0x00,0x4B,0xD6,0xEF,0x09,0x17,0x60,0x62}, - {0x48,0x0D,0x39,0x00,0x6E,0xE7,0x62,0xF2}, - {0x43,0x75,0x40,0xC8,0x69,0x8F,0x3C,0xFA}, - {0x07,0x2D,0x43,0xA0,0x77,0x07,0x52,0x92}, - {0x02,0xFE,0x55,0x77,0x81,0x17,0xF1,0x2A}, - {0x1D,0x9D,0x5C,0x50,0x18,0xF7,0x28,0xC2}, - {0x30,0x55,0x32,0x28,0x6D,0x6F,0x29,0x5A}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}; - -static unsigned char cipher_data[NUM_TESTS][8]={ - {0x4E,0xF9,0x97,0x45,0x61,0x98,0xDD,0x78}, - {0x51,0x86,0x6F,0xD5,0xB8,0x5E,0xCB,0x8A}, - {0x7D,0x85,0x6F,0x9A,0x61,0x30,0x63,0xF2}, - {0x24,0x66,0xDD,0x87,0x8B,0x96,0x3C,0x9D}, - {0x61,0xF9,0xC3,0x80,0x22,0x81,0xB0,0x96}, - {0x7D,0x0C,0xC6,0x30,0xAF,0xDA,0x1E,0xC7}, - {0x4E,0xF9,0x97,0x45,0x61,0x98,0xDD,0x78}, - {0x0A,0xCE,0xAB,0x0F,0xC6,0xA0,0xA2,0x8D}, - {0x59,0xC6,0x82,0x45,0xEB,0x05,0x28,0x2B}, - {0xB1,0xB8,0xCC,0x0B,0x25,0x0F,0x09,0xA0}, - {0x17,0x30,0xE5,0x77,0x8B,0xEA,0x1D,0xA4}, - {0xA2,0x5E,0x78,0x56,0xCF,0x26,0x51,0xEB}, - {0x35,0x38,0x82,0xB1,0x09,0xCE,0x8F,0x1A}, - {0x48,0xF4,0xD0,0x88,0x4C,0x37,0x99,0x18}, - {0x43,0x21,0x93,0xB7,0x89,0x51,0xFC,0x98}, - {0x13,0xF0,0x41,0x54,0xD6,0x9D,0x1A,0xE5}, - {0x2E,0xED,0xDA,0x93,0xFF,0xD3,0x9C,0x79}, - {0xD8,0x87,0xE0,0x39,0x3C,0x2D,0xA6,0xE3}, - {0x5F,0x99,0xD0,0x4F,0x5B,0x16,0x39,0x69}, - {0x4A,0x05,0x7A,0x3B,0x24,0xD3,0x97,0x7B}, - {0x45,0x20,0x31,0xC1,0xE4,0xFA,0xDA,0x8E}, - {0x75,0x55,0xAE,0x39,0xF5,0x9B,0x87,0xBD}, - {0x53,0xC5,0x5F,0x9C,0xB4,0x9F,0xC0,0x19}, - {0x7A,0x8E,0x7B,0xFA,0x93,0x7E,0x89,0xA3}, - {0xCF,0x9C,0x5D,0x7A,0x49,0x86,0xAD,0xB5}, - {0xD1,0xAB,0xB2,0x90,0x65,0x8B,0xC7,0x78}, - {0x55,0xCB,0x37,0x74,0xD1,0x3E,0xF2,0x01}, - {0xFA,0x34,0xEC,0x48,0x47,0xB2,0x68,0xB2}, - {0xA7,0x90,0x79,0x51,0x08,0xEA,0x3C,0xAE}, - {0xC3,0x9E,0x07,0x2D,0x9F,0xAC,0x63,0x1D}, - {0x01,0x49,0x33,0xE0,0xCD,0xAF,0xF6,0xE4}, - {0xF2,0x1E,0x9A,0x77,0xB7,0x1C,0x49,0xBC}, - {0x24,0x59,0x46,0x88,0x57,0x54,0x36,0x9A}, - {0x6B,0x5C,0x5A,0x9C,0x5D,0x9E,0x0A,0x5A}, - }; - -static unsigned char cbc_key [16]={ - 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef, - 0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87}; -static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; -static char cbc_data[40]="7654321 Now is the time for "; -static unsigned char cbc_ok[32]={ - 0x6B,0x77,0xB4,0xD6,0x30,0x06,0xDE,0xE6, - 0x05,0xB1,0x56,0xE2,0x74,0x03,0x97,0x93, - 0x58,0xDE,0xB9,0xE7,0x15,0x46,0x16,0xD9, - 0x59,0xF1,0x65,0x2B,0xD5,0xFF,0x92,0xCC}; - -static unsigned char cfb64_ok[]={ - 0xE7,0x32,0x14,0xA2,0x82,0x21,0x39,0xCA, - 0xF2,0x6E,0xCF,0x6D,0x2E,0xB9,0xE7,0x6E, - 0x3D,0xA3,0xDE,0x04,0xD1,0x51,0x72,0x00, - 0x51,0x9D,0x57,0xA6,0xC3}; - -static unsigned char ofb64_ok[]={ - 0xE7,0x32,0x14,0xA2,0x82,0x21,0x39,0xCA, - 0x62,0xB3,0x43,0xCC,0x5B,0x65,0x58,0x73, - 0x10,0xDD,0x90,0x8D,0x0C,0x24,0x1B,0x22, - 0x63,0xC2,0xCF,0x80,0xDA}; - -#define KEY_TEST_NUM 25 -static unsigned char key_test[KEY_TEST_NUM]={ - 0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87, - 0x78,0x69,0x5a,0x4b,0x3c,0x2d,0x1e,0x0f, - 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77, - 0x88}; - -static unsigned char key_data[8]= - {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}; - -static unsigned char key_out[KEY_TEST_NUM][8]={ - {0xF9,0xAD,0x59,0x7C,0x49,0xDB,0x00,0x5E}, - {0xE9,0x1D,0x21,0xC1,0xD9,0x61,0xA6,0xD6}, - {0xE9,0xC2,0xB7,0x0A,0x1B,0xC6,0x5C,0xF3}, - {0xBE,0x1E,0x63,0x94,0x08,0x64,0x0F,0x05}, - {0xB3,0x9E,0x44,0x48,0x1B,0xDB,0x1E,0x6E}, - {0x94,0x57,0xAA,0x83,0xB1,0x92,0x8C,0x0D}, - {0x8B,0xB7,0x70,0x32,0xF9,0x60,0x62,0x9D}, - {0xE8,0x7A,0x24,0x4E,0x2C,0xC8,0x5E,0x82}, - {0x15,0x75,0x0E,0x7A,0x4F,0x4E,0xC5,0x77}, - {0x12,0x2B,0xA7,0x0B,0x3A,0xB6,0x4A,0xE0}, - {0x3A,0x83,0x3C,0x9A,0xFF,0xC5,0x37,0xF6}, - {0x94,0x09,0xDA,0x87,0xA9,0x0F,0x6B,0xF2}, - {0x88,0x4F,0x80,0x62,0x50,0x60,0xB8,0xB4}, - {0x1F,0x85,0x03,0x1C,0x19,0xE1,0x19,0x68}, - {0x79,0xD9,0x37,0x3A,0x71,0x4C,0xA3,0x4F}, - {0x93,0x14,0x28,0x87,0xEE,0x3B,0xE1,0x5C}, - {0x03,0x42,0x9E,0x83,0x8C,0xE2,0xD1,0x4B}, - {0xA4,0x29,0x9E,0x27,0x46,0x9F,0xF6,0x7B}, - {0xAF,0xD5,0xAE,0xD1,0xC1,0xBC,0x96,0xA8}, - {0x10,0x85,0x1C,0x0E,0x38,0x58,0xDA,0x9F}, - {0xE6,0xF5,0x1E,0xD7,0x9B,0x9D,0xB2,0x1F}, - {0x64,0xA6,0xE1,0x4A,0xFD,0x36,0xB4,0x6F}, - {0x80,0xC7,0xD7,0xD4,0x5A,0x54,0x79,0xAD}, - {0x05,0x04,0x4B,0x62,0xFA,0x52,0xD0,0x80}, - }; - -static int test(void ); -static int print_test_data(void ); -int main(int argc, char *argv[]) - { - int ret; - - if (argc > 1) - ret=print_test_data(); - else - ret=test(); - -#ifdef OPENSSL_SYS_NETWARE - if (ret) printf("ERROR: %d\n", ret); -#endif - EXIT(ret); - return(0); - } - -static int print_test_data(void) - { - unsigned int i,j; - - printf("ecb test data\n"); - printf("key bytes\t\tclear bytes\t\tcipher bytes\n"); - for (i=0; i -#include -#include - -#include "e_os.h" - -#include -#include -#include -#include -#include - -const int num0 = 100; /* number of tests */ -const int num1 = 50; /* additional tests for some functions */ -const int num2 = 5; /* number of tests for slow functions */ - -int test_add(BIO *bp); -int test_sub(BIO *bp); -int test_lshift1(BIO *bp); -int test_lshift(BIO *bp,BN_CTX *ctx,BIGNUM *a_); -int test_rshift1(BIO *bp); -int test_rshift(BIO *bp,BN_CTX *ctx); -int test_div(BIO *bp,BN_CTX *ctx); -int test_div_word(BIO *bp); -int test_div_recp(BIO *bp,BN_CTX *ctx); -int test_mul(BIO *bp); -int test_sqr(BIO *bp,BN_CTX *ctx); -int test_mont(BIO *bp,BN_CTX *ctx); -int test_mod(BIO *bp,BN_CTX *ctx); -int test_mod_mul(BIO *bp,BN_CTX *ctx); -int test_mod_exp(BIO *bp,BN_CTX *ctx); -int test_mod_exp_mont_consttime(BIO *bp,BN_CTX *ctx); -int test_exp(BIO *bp,BN_CTX *ctx); -int test_gf2m_add(BIO *bp); -int test_gf2m_mod(BIO *bp); -int test_gf2m_mod_mul(BIO *bp,BN_CTX *ctx); -int test_gf2m_mod_sqr(BIO *bp,BN_CTX *ctx); -int test_gf2m_mod_inv(BIO *bp,BN_CTX *ctx); -int test_gf2m_mod_div(BIO *bp,BN_CTX *ctx); -int test_gf2m_mod_exp(BIO *bp,BN_CTX *ctx); -int test_gf2m_mod_sqrt(BIO *bp,BN_CTX *ctx); -int test_gf2m_mod_solve_quad(BIO *bp,BN_CTX *ctx); -int test_kron(BIO *bp,BN_CTX *ctx); -int test_sqrt(BIO *bp,BN_CTX *ctx); -int rand_neg(void); -static int results=0; - -static unsigned char lst[]="\xC6\x4F\x43\x04\x2A\xEA\xCA\x6E\x58\x36\x80\x5B\xE8\xC9" -"\x9B\x04\x5D\x48\x36\xC2\xFD\x16\xC9\x64\xF0"; - -static const char rnd_seed[] = "string to make the random number generator think it has entropy"; - -static void message(BIO *out, char *m) - { - fprintf(stderr, "test %s\n", m); - BIO_puts(out, "print \"test "); - BIO_puts(out, m); - BIO_puts(out, "\\n\"\n"); - } - -int main(int argc, char *argv[]) - { - BN_CTX *ctx; - BIO *out; - char *outfile=NULL; - - results = 0; - - RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_generate_prime may fail */ - - argc--; - argv++; - while (argc >= 1) - { - if (strcmp(*argv,"-results") == 0) - results=1; - else if (strcmp(*argv,"-out") == 0) - { - if (--argc < 1) break; - outfile= *(++argv); - } - argc--; - argv++; - } - - - ctx=BN_CTX_new(); - if (ctx == NULL) EXIT(1); - - out=BIO_new(BIO_s_file()); - if (out == NULL) EXIT(1); - if (outfile == NULL) - { - BIO_set_fp(out,stdout,BIO_NOCLOSE); - } - else - { - if (!BIO_write_filename(out,outfile)) - { - perror(outfile); - EXIT(1); - } - } - - if (!results) - BIO_puts(out,"obase=16\nibase=16\n"); - - message(out,"BN_add"); - if (!test_add(out)) goto err; - (void)BIO_flush(out); - - message(out,"BN_sub"); - if (!test_sub(out)) goto err; - (void)BIO_flush(out); - - message(out,"BN_lshift1"); - if (!test_lshift1(out)) goto err; - (void)BIO_flush(out); - - message(out,"BN_lshift (fixed)"); - if (!test_lshift(out,ctx,BN_bin2bn(lst,sizeof(lst)-1,NULL))) - goto err; - (void)BIO_flush(out); - - message(out,"BN_lshift"); - if (!test_lshift(out,ctx,NULL)) goto err; - (void)BIO_flush(out); - - message(out,"BN_rshift1"); - if (!test_rshift1(out)) goto err; - (void)BIO_flush(out); - - message(out,"BN_rshift"); - if (!test_rshift(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_sqr"); - if (!test_sqr(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_mul"); - if (!test_mul(out)) goto err; - (void)BIO_flush(out); - - message(out,"BN_div"); - if (!test_div(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_div_word"); - if (!test_div_word(out)) goto err; - (void)BIO_flush(out); - - message(out,"BN_div_recp"); - if (!test_div_recp(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_mod"); - if (!test_mod(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_mod_mul"); - if (!test_mod_mul(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_mont"); - if (!test_mont(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_mod_exp"); - if (!test_mod_exp(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_mod_exp_mont_consttime"); - if (!test_mod_exp_mont_consttime(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_exp"); - if (!test_exp(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_kronecker"); - if (!test_kron(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_mod_sqrt"); - if (!test_sqrt(out,ctx)) goto err; - (void)BIO_flush(out); -#ifndef OPENSSL_NO_EC2M - message(out,"BN_GF2m_add"); - if (!test_gf2m_add(out)) goto err; - (void)BIO_flush(out); - - message(out,"BN_GF2m_mod"); - if (!test_gf2m_mod(out)) goto err; - (void)BIO_flush(out); - - message(out,"BN_GF2m_mod_mul"); - if (!test_gf2m_mod_mul(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_GF2m_mod_sqr"); - if (!test_gf2m_mod_sqr(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_GF2m_mod_inv"); - if (!test_gf2m_mod_inv(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_GF2m_mod_div"); - if (!test_gf2m_mod_div(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_GF2m_mod_exp"); - if (!test_gf2m_mod_exp(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_GF2m_mod_sqrt"); - if (!test_gf2m_mod_sqrt(out,ctx)) goto err; - (void)BIO_flush(out); - - message(out,"BN_GF2m_mod_solve_quad"); - if (!test_gf2m_mod_solve_quad(out,ctx)) goto err; - (void)BIO_flush(out); -#endif - BN_CTX_free(ctx); - BIO_free(out); - -/**/ - EXIT(0); -err: - BIO_puts(out,"1\n"); /* make sure the Perl script fed by bc notices - * the failure, see test_bn in test/Makefile.ssl*/ - (void)BIO_flush(out); - ERR_load_crypto_strings(); - ERR_print_errors_fp(stderr); - EXIT(1); - return(1); - } - -int test_add(BIO *bp) - { - BIGNUM a,b,c; - int i; - - BN_init(&a); - BN_init(&b); - BN_init(&c); - - BN_bntest_rand(&a,512,0,0); - for (i=0; i sizeof(unsigned long)) - { - unsigned long h=(unsigned long)(w>>32), - l=(unsigned long)(w); - - if (h) BIO_printf(bp,"%lX%08lX",h,l); - else BIO_printf(bp,"%lX",l); - return; - } -#endif - BIO_printf(bp,BN_HEX_FMT1,w); - } - -int test_div_word(BIO *bp) - { - BIGNUM a,b; - BN_ULONG r,s; - int i; - - BN_init(&a); - BN_init(&b); - - for (i=0; iN)); -#endif - BN_print(bp,&a); - BIO_puts(bp," * "); - BN_print(bp,&b); - BIO_puts(bp," % "); - BN_print(bp,&(mont->N)); - BIO_puts(bp," - "); - } - BN_print(bp,&A); - BIO_puts(bp,"\n"); - } - BN_mod_mul(&d,&a,&b,&n,ctx); - BN_sub(&d,&d,&A); - if(!BN_is_zero(&d)) - { - fprintf(stderr,"Montgomery multiplication test failed!\n"); - return 0; - } - } - BN_MONT_CTX_free(mont); - BN_free(&a); - BN_free(&b); - BN_free(&c); - BN_free(&d); - BN_free(&A); - BN_free(&B); - BN_free(&n); - return(1); - } - -int test_mod(BIO *bp, BN_CTX *ctx) - { - BIGNUM *a,*b,*c,*d,*e; - int i; - - a=BN_new(); - b=BN_new(); - c=BN_new(); - d=BN_new(); - e=BN_new(); - - BN_bntest_rand(a,1024,0,0); /**/ - for (i=0; ineg=rand_neg(); - b->neg=rand_neg(); - BN_mod(c,a,b,ctx);/**/ - if (bp != NULL) - { - if (!results) - { - BN_print(bp,a); - BIO_puts(bp," % "); - BN_print(bp,b); - BIO_puts(bp," - "); - } - BN_print(bp,c); - BIO_puts(bp,"\n"); - } - BN_div(d,e,a,b,ctx); - BN_sub(e,e,c); - if(!BN_is_zero(e)) - { - fprintf(stderr,"Modulo test failed!\n"); - return 0; - } - } - BN_free(a); - BN_free(b); - BN_free(c); - BN_free(d); - BN_free(e); - return(1); - } - -int test_mod_mul(BIO *bp, BN_CTX *ctx) - { - BIGNUM *a,*b,*c,*d,*e; - int i,j; - - a=BN_new(); - b=BN_new(); - c=BN_new(); - d=BN_new(); - e=BN_new(); - - for (j=0; j<3; j++) { - BN_bntest_rand(c,1024,0,0); /**/ - for (i=0; ineg=rand_neg(); - b->neg=rand_neg(); - if (!BN_mod_mul(e,a,b,c,ctx)) - { - unsigned long l; - - while ((l=ERR_get_error())) - fprintf(stderr,"ERROR:%s\n", - ERR_error_string(l,NULL)); - EXIT(1); - } - if (bp != NULL) - { - if (!results) - { - BN_print(bp,a); - BIO_puts(bp," * "); - BN_print(bp,b); - BIO_puts(bp," % "); - BN_print(bp,c); - if ((a->neg ^ b->neg) && !BN_is_zero(e)) - { - /* If (a*b) % c is negative, c must be added - * in order to obtain the normalized remainder - * (new with OpenSSL 0.9.7, previous versions of - * BN_mod_mul could generate negative results) - */ - BIO_puts(bp," + "); - BN_print(bp,c); - } - BIO_puts(bp," - "); - } - BN_print(bp,e); - BIO_puts(bp,"\n"); - } - BN_mul(d,a,b,ctx); - BN_sub(d,d,e); - BN_div(a,b,d,c,ctx); - if(!BN_is_zero(b)) - { - fprintf(stderr,"Modulo multiply test failed!\n"); - ERR_print_errors_fp(stderr); - return 0; - } - } - } - BN_free(a); - BN_free(b); - BN_free(c); - BN_free(d); - BN_free(e); - return(1); - } - -int test_mod_exp(BIO *bp, BN_CTX *ctx) - { - BIGNUM *a,*b,*c,*d,*e; - int i; - - a=BN_new(); - b=BN_new(); - c=BN_new(); - d=BN_new(); - e=BN_new(); - - BN_bntest_rand(c,30,0,1); /* must be odd for montgomery */ - for (i=0; ineg = rand_neg(); - putc('\n', stderr); - - for (i = 0; i < num0; i++) - { - if (!BN_bntest_rand(a, 512, 0, 0)) goto err; - a->neg = rand_neg(); - - /* t := (|b|-1)/2 (note that b is odd) */ - if (!BN_copy(t, b)) goto err; - t->neg = 0; - if (!BN_sub_word(t, 1)) goto err; - if (!BN_rshift1(t, t)) goto err; - /* r := a^t mod b */ - b->neg=0; - - if (!BN_mod_exp_recp(r, a, t, b, ctx)) goto err; - b->neg=1; - - if (BN_is_word(r, 1)) - legendre = 1; - else if (BN_is_zero(r)) - legendre = 0; - else - { - if (!BN_add_word(r, 1)) goto err; - if (0 != BN_ucmp(r, b)) - { - fprintf(stderr, "Legendre symbol computation failed\n"); - goto err; - } - legendre = -1; - } - - kronecker = BN_kronecker(a, b, ctx); - if (kronecker < -1) goto err; - /* we actually need BN_kronecker(a, |b|) */ - if (a->neg && b->neg) - kronecker = -kronecker; - - if (legendre != kronecker) - { - fprintf(stderr, "legendre != kronecker; a = "); - BN_print_fp(stderr, a); - fprintf(stderr, ", b = "); - BN_print_fp(stderr, b); - fprintf(stderr, "\n"); - goto err; - } - - putc('.', stderr); - fflush(stderr); - } - - putc('\n', stderr); - fflush(stderr); - ret = 1; - err: - if (a != NULL) BN_free(a); - if (b != NULL) BN_free(b); - if (r != NULL) BN_free(r); - if (t != NULL) BN_free(t); - return ret; - } - -int test_sqrt(BIO *bp, BN_CTX *ctx) - { - BN_GENCB cb; - BIGNUM *a,*p,*r; - int i, j; - int ret = 0; - - a = BN_new(); - p = BN_new(); - r = BN_new(); - if (a == NULL || p == NULL || r == NULL) goto err; - - BN_GENCB_set(&cb, genprime_cb, NULL); - - for (i = 0; i < 16; i++) - { - if (i < 8) - { - unsigned primes[8] = { 2, 3, 5, 7, 11, 13, 17, 19 }; - - if (!BN_set_word(p, primes[i])) goto err; - } - else - { - if (!BN_set_word(a, 32)) goto err; - if (!BN_set_word(r, 2*i + 1)) goto err; - - if (!BN_generate_prime_ex(p, 256, 0, a, r, &cb)) goto err; - putc('\n', stderr); - } - p->neg = rand_neg(); - - for (j = 0; j < num2; j++) - { - /* construct 'a' such that it is a square modulo p, - * but in general not a proper square and not reduced modulo p */ - if (!BN_bntest_rand(r, 256, 0, 3)) goto err; - if (!BN_nnmod(r, r, p, ctx)) goto err; - if (!BN_mod_sqr(r, r, p, ctx)) goto err; - if (!BN_bntest_rand(a, 256, 0, 3)) goto err; - if (!BN_nnmod(a, a, p, ctx)) goto err; - if (!BN_mod_sqr(a, a, p, ctx)) goto err; - if (!BN_mul(a, a, r, ctx)) goto err; - if (rand_neg()) - if (!BN_sub(a, a, p)) goto err; - - if (!BN_mod_sqrt(r, a, p, ctx)) goto err; - if (!BN_mod_sqr(r, r, p, ctx)) goto err; - - if (!BN_nnmod(a, a, p, ctx)) goto err; - - if (BN_cmp(a, r) != 0) - { - fprintf(stderr, "BN_mod_sqrt failed: a = "); - BN_print_fp(stderr, a); - fprintf(stderr, ", r = "); - BN_print_fp(stderr, r); - fprintf(stderr, ", p = "); - BN_print_fp(stderr, p); - fprintf(stderr, "\n"); - goto err; - } - - putc('.', stderr); - fflush(stderr); - } - - putc('\n', stderr); - fflush(stderr); - } - ret = 1; - err: - if (a != NULL) BN_free(a); - if (p != NULL) BN_free(p); - if (r != NULL) BN_free(r); - return ret; - } - -int test_lshift(BIO *bp,BN_CTX *ctx,BIGNUM *a_) - { - BIGNUM *a,*b,*c,*d; - int i; - - b=BN_new(); - c=BN_new(); - d=BN_new(); - BN_one(c); - - if(a_) - a=a_; - else - { - a=BN_new(); - BN_bntest_rand(a,200,0,0); /**/ - a->neg=rand_neg(); - } - for (i=0; ineg=rand_neg(); - for (i=0; ineg=rand_neg(); - for (i=0; ineg=rand_neg(); - for (i=0; i -#include -#include - -#include "../e_os.h" - -#include -#include -#include -#include - -#define NUM_BITS (BN_BITS*2) - -static const char rnd_seed[] = "string to make the random number generator think it has entropy"; - -int main(int argc, char *argv[]) - { - BN_CTX *ctx; - BIO *out=NULL; - int i,ret; - unsigned char c; - BIGNUM *r_mont,*r_mont_const,*r_recp,*r_simple,*a,*b,*m; - - RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_rand may fail, and we don't - * even check its return value - * (which we should) */ - - ERR_load_BN_strings(); - - ctx=BN_CTX_new(); - if (ctx == NULL) EXIT(1); - r_mont=BN_new(); - r_mont_const=BN_new(); - r_recp=BN_new(); - r_simple=BN_new(); - a=BN_new(); - b=BN_new(); - m=BN_new(); - if ( (r_mont == NULL) || (r_recp == NULL) || - (a == NULL) || (b == NULL)) - goto err; - - out=BIO_new(BIO_s_file()); - - if (out == NULL) EXIT(1); - BIO_set_fp(out,stdout,BIO_NOCLOSE); - - for (i=0; i<200; i++) - { - RAND_bytes(&c,1); - c=(c%BN_BITS)-BN_BITS2; - BN_rand(a,NUM_BITS+c,0,0); - - RAND_bytes(&c,1); - c=(c%BN_BITS)-BN_BITS2; - BN_rand(b,NUM_BITS+c,0,0); - - RAND_bytes(&c,1); - c=(c%BN_BITS)-BN_BITS2; - BN_rand(m,NUM_BITS+c,0,1); - - BN_mod(a,a,m,ctx); - BN_mod(b,b,m,ctx); - - ret=BN_mod_exp_mont(r_mont,a,b,m,ctx,NULL); - if (ret <= 0) - { - printf("BN_mod_exp_mont() problems\n"); - ERR_print_errors(out); - EXIT(1); - } - - ret=BN_mod_exp_recp(r_recp,a,b,m,ctx); - if (ret <= 0) - { - printf("BN_mod_exp_recp() problems\n"); - ERR_print_errors(out); - EXIT(1); - } - - ret=BN_mod_exp_simple(r_simple,a,b,m,ctx); - if (ret <= 0) - { - printf("BN_mod_exp_simple() problems\n"); - ERR_print_errors(out); - EXIT(1); - } - - ret=BN_mod_exp_mont_consttime(r_mont_const,a,b,m,ctx,NULL); - if (ret <= 0) - { - printf("BN_mod_exp_mont_consttime() problems\n"); - ERR_print_errors(out); - EXIT(1); - } - - if (BN_cmp(r_simple, r_mont) == 0 - && BN_cmp(r_simple,r_recp) == 0 - && BN_cmp(r_simple,r_mont_const) == 0) - { - printf("."); - fflush(stdout); - } - else - { - if (BN_cmp(r_simple,r_mont) != 0) - printf("\nsimple and mont results differ\n"); - if (BN_cmp(r_simple,r_mont_const) != 0) - printf("\nsimple and mont const time results differ\n"); - if (BN_cmp(r_simple,r_recp) != 0) - printf("\nsimple and recp results differ\n"); - - printf("a (%3d) = ",BN_num_bits(a)); BN_print(out,a); - printf("\nb (%3d) = ",BN_num_bits(b)); BN_print(out,b); - printf("\nm (%3d) = ",BN_num_bits(m)); BN_print(out,m); - printf("\nsimple ="); BN_print(out,r_simple); - printf("\nrecp ="); BN_print(out,r_recp); - printf("\nmont ="); BN_print(out,r_mont); - printf("\nmont_ct ="); BN_print(out,r_mont_const); - printf("\n"); - EXIT(1); - } - } - BN_free(r_mont); - BN_free(r_mont_const); - BN_free(r_recp); - BN_free(r_simple); - BN_free(a); - BN_free(b); - BN_free(m); - BN_CTX_free(ctx); - ERR_remove_thread_state(NULL); - CRYPTO_mem_leaks(out); - BIO_free(out); - printf(" done\n"); - EXIT(0); -err: - ERR_load_crypto_strings(); - ERR_print_errors(out); -#ifdef OPENSSL_SYS_NETWARE - printf("ERROR\n"); -#endif - EXIT(1); - return(1); - } - diff --git a/src/lib/libssl/src/crypto/cast/casttest.c b/src/lib/libssl/src/crypto/cast/casttest.c deleted file mode 100644 index 0d020d6975..0000000000 --- a/src/lib/libssl/src/crypto/cast/casttest.c +++ /dev/null @@ -1,233 +0,0 @@ -/* crypto/cast/casttest.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include -#include -#include -#include /* To see if OPENSSL_NO_CAST is defined */ - -#include "../e_os.h" - -#ifdef OPENSSL_NO_CAST -int main(int argc, char *argv[]) -{ - printf("No CAST support\n"); - return(0); -} -#else -#include - -#define FULL_TEST - -static unsigned char k[16]={ - 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78, - 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A - }; - -static unsigned char in[8]={ 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}; - -static int k_len[3]={16,10,5}; -static unsigned char c[3][8]={ - {0x23,0x8B,0x4F,0xE5,0x84,0x7E,0x44,0xB2}, - {0xEB,0x6A,0x71,0x1A,0x2C,0x02,0x27,0x1B}, - {0x7A,0xC8,0x16,0xD1,0x6E,0x9B,0x30,0x2E}, - }; -static unsigned char out[80]; - -static unsigned char in_a[16]={ - 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78, - 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A}; -static unsigned char in_b[16]={ - 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78, - 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A}; - -static unsigned char c_a[16]={ - 0xEE,0xA9,0xD0,0xA2,0x49,0xFD,0x3B,0xA6, - 0xB3,0x43,0x6F,0xB8,0x9D,0x6D,0xCA,0x92}; -static unsigned char c_b[16]={ - 0xB2,0xC9,0x5E,0xB0,0x0C,0x31,0xAD,0x71, - 0x80,0xAC,0x05,0xB8,0xE8,0x3D,0x69,0x6E}; - -#if 0 -char *text="Hello to all people out there"; - -static unsigned char cfb_key[16]={ - 0xe1,0xf0,0xc3,0xd2,0xa5,0xb4,0x87,0x96, - 0x69,0x78,0x4b,0x5a,0x2d,0x3c,0x0f,0x1e, - }; -static unsigned char cfb_iv[80]={0x34,0x12,0x78,0x56,0xab,0x90,0xef,0xcd}; -static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8]; -#define CFB_TEST_SIZE 24 -static unsigned char plain[CFB_TEST_SIZE]= - { - 0x4e,0x6f,0x77,0x20,0x69,0x73, - 0x20,0x74,0x68,0x65,0x20,0x74, - 0x69,0x6d,0x65,0x20,0x66,0x6f, - 0x72,0x20,0x61,0x6c,0x6c,0x20 - }; -static unsigned char cfb_cipher64[CFB_TEST_SIZE]={ - 0x59,0xD8,0xE2,0x65,0x00,0x58,0x6C,0x3F, - 0x2C,0x17,0x25,0xD0,0x1A,0x38,0xB7,0x2A, - 0x39,0x61,0x37,0xDC,0x79,0xFB,0x9F,0x45 - -/* 0xF9,0x78,0x32,0xB5,0x42,0x1A,0x6B,0x38, - 0x9A,0x44,0xD6,0x04,0x19,0x43,0xC4,0xD9, - 0x3D,0x1E,0xAE,0x47,0xFC,0xCF,0x29,0x0B,*/ - }; -#endif - -int main(int argc, char *argv[]) - { -#ifdef FULL_TEST - long l; - CAST_KEY key_b; -#endif - int i,z,err=0; - CAST_KEY key; - - for (z=0; z<3; z++) - { - CAST_set_key(&key,k_len[z],k); - - CAST_ecb_encrypt(in,out,&key,CAST_ENCRYPT); - if (memcmp(out,&(c[z][0]),8) != 0) - { - printf("ecb cast error encrypting for keysize %d\n",k_len[z]*8); - printf("got :"); - for (i=0; i<8; i++) - printf("%02X ",out[i]); - printf("\n"); - printf("expected:"); - for (i=0; i<8; i++) - printf("%02X ",c[z][i]); - err=20; - printf("\n"); - } - - CAST_ecb_encrypt(out,out,&key,CAST_DECRYPT); - if (memcmp(out,in,8) != 0) - { - printf("ecb cast error decrypting for keysize %d\n",k_len[z]*8); - printf("got :"); - for (i=0; i<8; i++) - printf("%02X ",out[i]); - printf("\n"); - printf("expected:"); - for (i=0; i<8; i++) - printf("%02X ",in[i]); - printf("\n"); - err=3; - } - } - if (err == 0) - printf("ecb cast5 ok\n"); - -#ifdef FULL_TEST - { - unsigned char out_a[16],out_b[16]; - static char *hex="0123456789ABCDEF"; - - printf("This test will take some time...."); - fflush(stdout); - memcpy(out_a,in_a,sizeof(in_a)); - memcpy(out_b,in_b,sizeof(in_b)); - i=1; - - for (l=0; l<1000000L; l++) - { - CAST_set_key(&key_b,16,out_b); - CAST_ecb_encrypt(&(out_a[0]),&(out_a[0]),&key_b,CAST_ENCRYPT); - CAST_ecb_encrypt(&(out_a[8]),&(out_a[8]),&key_b,CAST_ENCRYPT); - CAST_set_key(&key,16,out_a); - CAST_ecb_encrypt(&(out_b[0]),&(out_b[0]),&key,CAST_ENCRYPT); - CAST_ecb_encrypt(&(out_b[8]),&(out_b[8]),&key,CAST_ENCRYPT); - if ((l & 0xffff) == 0xffff) - { - printf("%c",hex[i&0x0f]); - fflush(stdout); - i++; - } - } - - if ( (memcmp(out_a,c_a,sizeof(c_a)) != 0) || - (memcmp(out_b,c_b,sizeof(c_b)) != 0)) - { - printf("\n"); - printf("Error\n"); - - printf("A out ="); - for (i=0; i<16; i++) printf("%02X ",out_a[i]); - printf("\nactual="); - for (i=0; i<16; i++) printf("%02X ",c_a[i]); - printf("\n"); - - printf("B out ="); - for (i=0; i<16; i++) printf("%02X ",out_b[i]); - printf("\nactual="); - for (i=0; i<16; i++) printf("%02X ",c_b[i]); - printf("\n"); - } - else - printf(" ok\n"); - } -#endif - - EXIT(err); - return(err); - } -#endif diff --git a/src/lib/libssl/src/crypto/des/destest.c b/src/lib/libssl/src/crypto/des/destest.c deleted file mode 100644 index 64b92a34fe..0000000000 --- a/src/lib/libssl/src/crypto/des/destest.c +++ /dev/null @@ -1,952 +0,0 @@ -/* crypto/des/destest.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include -#include - -#include -#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_SYS_WINDOWS) -#ifndef OPENSSL_SYS_MSDOS -#define OPENSSL_SYS_MSDOS -#endif -#endif - -#ifndef OPENSSL_SYS_MSDOS -#if !defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_VMS_DECC) -#include OPENSSL_UNISTD -#endif -#else -#include -#endif -#include - -#ifdef OPENSSL_NO_DES -int main(int argc, char *argv[]) -{ - printf("No DES support\n"); - return(0); -} -#else -#include - -#define crypt(c,s) (DES_crypt((c),(s))) - -/* tisk tisk - the test keys don't all have odd parity :-( */ -/* test data */ -#define NUM_TESTS 34 -static unsigned char key_data[NUM_TESTS][8]={ - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, - {0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}, - {0x7C,0xA1,0x10,0x45,0x4A,0x1A,0x6E,0x57}, - {0x01,0x31,0xD9,0x61,0x9D,0xC1,0x37,0x6E}, - {0x07,0xA1,0x13,0x3E,0x4A,0x0B,0x26,0x86}, - {0x38,0x49,0x67,0x4C,0x26,0x02,0x31,0x9E}, - {0x04,0xB9,0x15,0xBA,0x43,0xFE,0xB5,0xB6}, - {0x01,0x13,0xB9,0x70,0xFD,0x34,0xF2,0xCE}, - {0x01,0x70,0xF1,0x75,0x46,0x8F,0xB5,0xE6}, - {0x43,0x29,0x7F,0xAD,0x38,0xE3,0x73,0xFE}, - {0x07,0xA7,0x13,0x70,0x45,0xDA,0x2A,0x16}, - {0x04,0x68,0x91,0x04,0xC2,0xFD,0x3B,0x2F}, - {0x37,0xD0,0x6B,0xB5,0x16,0xCB,0x75,0x46}, - {0x1F,0x08,0x26,0x0D,0x1A,0xC2,0x46,0x5E}, - {0x58,0x40,0x23,0x64,0x1A,0xBA,0x61,0x76}, - {0x02,0x58,0x16,0x16,0x46,0x29,0xB0,0x07}, - {0x49,0x79,0x3E,0xBC,0x79,0xB3,0x25,0x8F}, - {0x4F,0xB0,0x5E,0x15,0x15,0xAB,0x73,0xA7}, - {0x49,0xE9,0x5D,0x6D,0x4C,0xA2,0x29,0xBF}, - {0x01,0x83,0x10,0xDC,0x40,0x9B,0x26,0xD6}, - {0x1C,0x58,0x7F,0x1C,0x13,0x92,0x4F,0xEF}, - {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01}, - {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E}, - {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}}; - -static unsigned char plain_data[NUM_TESTS][8]={ - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, - {0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01}, - {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, - {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0x01,0xA1,0xD6,0xD0,0x39,0x77,0x67,0x42}, - {0x5C,0xD5,0x4C,0xA8,0x3D,0xEF,0x57,0xDA}, - {0x02,0x48,0xD4,0x38,0x06,0xF6,0x71,0x72}, - {0x51,0x45,0x4B,0x58,0x2D,0xDF,0x44,0x0A}, - {0x42,0xFD,0x44,0x30,0x59,0x57,0x7F,0xA2}, - {0x05,0x9B,0x5E,0x08,0x51,0xCF,0x14,0x3A}, - {0x07,0x56,0xD8,0xE0,0x77,0x47,0x61,0xD2}, - {0x76,0x25,0x14,0xB8,0x29,0xBF,0x48,0x6A}, - {0x3B,0xDD,0x11,0x90,0x49,0x37,0x28,0x02}, - {0x26,0x95,0x5F,0x68,0x35,0xAF,0x60,0x9A}, - {0x16,0x4D,0x5E,0x40,0x4F,0x27,0x52,0x32}, - {0x6B,0x05,0x6E,0x18,0x75,0x9F,0x5C,0xCA}, - {0x00,0x4B,0xD6,0xEF,0x09,0x17,0x60,0x62}, - {0x48,0x0D,0x39,0x00,0x6E,0xE7,0x62,0xF2}, - {0x43,0x75,0x40,0xC8,0x69,0x8F,0x3C,0xFA}, - {0x07,0x2D,0x43,0xA0,0x77,0x07,0x52,0x92}, - {0x02,0xFE,0x55,0x77,0x81,0x17,0xF1,0x2A}, - {0x1D,0x9D,0x5C,0x50,0x18,0xF7,0x28,0xC2}, - {0x30,0x55,0x32,0x28,0x6D,0x6F,0x29,0x5A}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, - {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}; - -static unsigned char cipher_data[NUM_TESTS][8]={ - {0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7}, - {0x73,0x59,0xB2,0x16,0x3E,0x4E,0xDC,0x58}, - {0x95,0x8E,0x6E,0x62,0x7A,0x05,0x55,0x7B}, - {0xF4,0x03,0x79,0xAB,0x9E,0x0E,0xC5,0x33}, - {0x17,0x66,0x8D,0xFC,0x72,0x92,0x53,0x2D}, - {0x8A,0x5A,0xE1,0xF8,0x1A,0xB8,0xF2,0xDD}, - {0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7}, - {0xED,0x39,0xD9,0x50,0xFA,0x74,0xBC,0xC4}, - {0x69,0x0F,0x5B,0x0D,0x9A,0x26,0x93,0x9B}, - {0x7A,0x38,0x9D,0x10,0x35,0x4B,0xD2,0x71}, - {0x86,0x8E,0xBB,0x51,0xCA,0xB4,0x59,0x9A}, - {0x71,0x78,0x87,0x6E,0x01,0xF1,0x9B,0x2A}, - {0xAF,0x37,0xFB,0x42,0x1F,0x8C,0x40,0x95}, - {0x86,0xA5,0x60,0xF1,0x0E,0xC6,0xD8,0x5B}, - {0x0C,0xD3,0xDA,0x02,0x00,0x21,0xDC,0x09}, - {0xEA,0x67,0x6B,0x2C,0xB7,0xDB,0x2B,0x7A}, - {0xDF,0xD6,0x4A,0x81,0x5C,0xAF,0x1A,0x0F}, - {0x5C,0x51,0x3C,0x9C,0x48,0x86,0xC0,0x88}, - {0x0A,0x2A,0xEE,0xAE,0x3F,0xF4,0xAB,0x77}, - {0xEF,0x1B,0xF0,0x3E,0x5D,0xFA,0x57,0x5A}, - {0x88,0xBF,0x0D,0xB6,0xD7,0x0D,0xEE,0x56}, - {0xA1,0xF9,0x91,0x55,0x41,0x02,0x0B,0x56}, - {0x6F,0xBF,0x1C,0xAF,0xCF,0xFD,0x05,0x56}, - {0x2F,0x22,0xE4,0x9B,0xAB,0x7C,0xA1,0xAC}, - {0x5A,0x6B,0x61,0x2C,0xC2,0x6C,0xCE,0x4A}, - {0x5F,0x4C,0x03,0x8E,0xD1,0x2B,0x2E,0x41}, - {0x63,0xFA,0xC0,0xD0,0x34,0xD9,0xF7,0x93}, - {0x61,0x7B,0x3A,0x0C,0xE8,0xF0,0x71,0x00}, - {0xDB,0x95,0x86,0x05,0xF8,0xC8,0xC6,0x06}, - {0xED,0xBF,0xD1,0xC6,0x6C,0x29,0xCC,0xC7}, - {0x35,0x55,0x50,0xB2,0x15,0x0E,0x24,0x51}, - {0xCA,0xAA,0xAF,0x4D,0xEA,0xF1,0xDB,0xAE}, - {0xD5,0xD4,0x4F,0xF7,0x20,0x68,0x3D,0x0D}, - {0x2A,0x2B,0xB0,0x08,0xDF,0x97,0xC2,0xF2}}; - -static unsigned char cipher_ecb2[NUM_TESTS-1][8]={ - {0x92,0x95,0xB5,0x9B,0xB3,0x84,0x73,0x6E}, - {0x19,0x9E,0x9D,0x6D,0xF3,0x9A,0xA8,0x16}, - {0x2A,0x4B,0x4D,0x24,0x52,0x43,0x84,0x27}, - {0x35,0x84,0x3C,0x01,0x9D,0x18,0xC5,0xB6}, - {0x4A,0x5B,0x2F,0x42,0xAA,0x77,0x19,0x25}, - {0xA0,0x6B,0xA9,0xB8,0xCA,0x5B,0x17,0x8A}, - {0xAB,0x9D,0xB7,0xFB,0xED,0x95,0xF2,0x74}, - {0x3D,0x25,0x6C,0x23,0xA7,0x25,0x2F,0xD6}, - {0xB7,0x6F,0xAB,0x4F,0xBD,0xBD,0xB7,0x67}, - {0x8F,0x68,0x27,0xD6,0x9C,0xF4,0x1A,0x10}, - {0x82,0x57,0xA1,0xD6,0x50,0x5E,0x81,0x85}, - {0xA2,0x0F,0x0A,0xCD,0x80,0x89,0x7D,0xFA}, - {0xCD,0x2A,0x53,0x3A,0xDB,0x0D,0x7E,0xF3}, - {0xD2,0xC2,0xBE,0x27,0xE8,0x1B,0x68,0xE3}, - {0xE9,0x24,0xCF,0x4F,0x89,0x3C,0x5B,0x0A}, - {0xA7,0x18,0xC3,0x9F,0xFA,0x9F,0xD7,0x69}, - {0x77,0x2C,0x79,0xB1,0xD2,0x31,0x7E,0xB1}, - {0x49,0xAB,0x92,0x7F,0xD0,0x22,0x00,0xB7}, - {0xCE,0x1C,0x6C,0x7D,0x85,0xE3,0x4A,0x6F}, - {0xBE,0x91,0xD6,0xE1,0x27,0xB2,0xE9,0x87}, - {0x70,0x28,0xAE,0x8F,0xD1,0xF5,0x74,0x1A}, - {0xAA,0x37,0x80,0xBB,0xF3,0x22,0x1D,0xDE}, - {0xA6,0xC4,0xD2,0x5E,0x28,0x93,0xAC,0xB3}, - {0x22,0x07,0x81,0x5A,0xE4,0xB7,0x1A,0xAD}, - {0xDC,0xCE,0x05,0xE7,0x07,0xBD,0xF5,0x84}, - {0x26,0x1D,0x39,0x2C,0xB3,0xBA,0xA5,0x85}, - {0xB4,0xF7,0x0F,0x72,0xFB,0x04,0xF0,0xDC}, - {0x95,0xBA,0xA9,0x4E,0x87,0x36,0xF2,0x89}, - {0xD4,0x07,0x3A,0xF1,0x5A,0x17,0x82,0x0E}, - {0xEF,0x6F,0xAF,0xA7,0x66,0x1A,0x7E,0x89}, - {0xC1,0x97,0xF5,0x58,0x74,0x8A,0x20,0xE7}, - {0x43,0x34,0xCF,0xDA,0x22,0xC4,0x86,0xC8}, - {0x08,0xD7,0xB4,0xFB,0x62,0x9D,0x08,0x85}}; - -static unsigned char cbc_key [8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}; -static unsigned char cbc2_key[8]={0xf1,0xe0,0xd3,0xc2,0xb5,0xa4,0x97,0x86}; -static unsigned char cbc3_key[8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; -static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; -/* Changed the following text constant to binary so it will work on ebcdic - * machines :-) */ -/* static char cbc_data[40]="7654321 Now is the time for \0001"; */ -static unsigned char cbc_data[40]={ - 0x37,0x36,0x35,0x34,0x33,0x32,0x31,0x20, - 0x4E,0x6F,0x77,0x20,0x69,0x73,0x20,0x74, - 0x68,0x65,0x20,0x74,0x69,0x6D,0x65,0x20, - 0x66,0x6F,0x72,0x20,0x00,0x31,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - }; - -static unsigned char cbc_ok[32]={ - 0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4, - 0xac,0xd8,0xae,0xfd,0xdf,0xd8,0xa1,0xeb, - 0x46,0x8e,0x91,0x15,0x78,0x88,0xba,0x68, - 0x1d,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4}; - -#ifdef SCREW_THE_PARITY -#error "SCREW_THE_PARITY is not ment to be defined." -#error "Original vectors are preserved for reference only." -static unsigned char cbc2_key[8]={0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87}; -static unsigned char xcbc_ok[32]={ - 0x86,0x74,0x81,0x0D,0x61,0xA4,0xA5,0x48, - 0xB9,0x93,0x03,0xE1,0xB8,0xBB,0xBD,0xBD, - 0x64,0x30,0x0B,0xB9,0x06,0x65,0x81,0x76, - 0x04,0x1D,0x77,0x62,0x17,0xCA,0x2B,0xD2, - }; -#else -static unsigned char xcbc_ok[32]={ - 0x84,0x6B,0x29,0x14,0x85,0x1E,0x9A,0x29, - 0x54,0x73,0x2F,0x8A,0xA0,0xA6,0x11,0xC1, - 0x15,0xCD,0xC2,0xD7,0x95,0x1B,0x10,0x53, - 0xA6,0x3C,0x5E,0x03,0xB2,0x1A,0xA3,0xC4, - }; -#endif - -static unsigned char cbc3_ok[32]={ - 0x3F,0xE3,0x01,0xC9,0x62,0xAC,0x01,0xD0, - 0x22,0x13,0x76,0x3C,0x1C,0xBD,0x4C,0xDC, - 0x79,0x96,0x57,0xC0,0x64,0xEC,0xF5,0xD4, - 0x1C,0x67,0x38,0x12,0xCF,0xDE,0x96,0x75}; - -static unsigned char pcbc_ok[32]={ - 0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4, - 0x6d,0xec,0xb4,0x70,0xa0,0xe5,0x6b,0x15, - 0xae,0xa6,0xbf,0x61,0xed,0x7d,0x9c,0x9f, - 0xf7,0x17,0x46,0x3b,0x8a,0xb3,0xcc,0x88}; - -static unsigned char cfb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}; -static unsigned char cfb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef}; -static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8]; -static unsigned char plain[24]= - { - 0x4e,0x6f,0x77,0x20,0x69,0x73, - 0x20,0x74,0x68,0x65,0x20,0x74, - 0x69,0x6d,0x65,0x20,0x66,0x6f, - 0x72,0x20,0x61,0x6c,0x6c,0x20 - }; -static unsigned char cfb_cipher8[24]= { - 0xf3,0x1f,0xda,0x07,0x01,0x14, 0x62,0xee,0x18,0x7f,0x43,0xd8, - 0x0a,0x7c,0xd9,0xb5,0xb0,0xd2, 0x90,0xda,0x6e,0x5b,0x9a,0x87 }; -static unsigned char cfb_cipher16[24]={ - 0xF3,0x09,0x87,0x87,0x7F,0x57, 0xF7,0x3C,0x36,0xB6,0xDB,0x70, - 0xD8,0xD5,0x34,0x19,0xD3,0x86, 0xB2,0x23,0xB7,0xB2,0xAD,0x1B }; -static unsigned char cfb_cipher32[24]={ - 0xF3,0x09,0x62,0x49,0xA4,0xDF, 0xA4,0x9F,0x33,0xDC,0x7B,0xAD, - 0x4C,0xC8,0x9F,0x64,0xE4,0x53, 0xE5,0xEC,0x67,0x20,0xDA,0xB6 }; -static unsigned char cfb_cipher48[24]={ - 0xF3,0x09,0x62,0x49,0xC7,0xF4, 0x30,0xB5,0x15,0xEC,0xBB,0x85, - 0x97,0x5A,0x13,0x8C,0x68,0x60, 0xE2,0x38,0x34,0x3C,0xDC,0x1F }; -static unsigned char cfb_cipher64[24]={ - 0xF3,0x09,0x62,0x49,0xC7,0xF4, 0x6E,0x51,0xA6,0x9E,0x83,0x9B, - 0x1A,0x92,0xF7,0x84,0x03,0x46, 0x71,0x33,0x89,0x8E,0xA6,0x22 }; - -static unsigned char ofb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}; -static unsigned char ofb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef}; -static unsigned char ofb_buf1[24],ofb_buf2[24],ofb_tmp[8]; -static unsigned char ofb_cipher[24]= - { - 0xf3,0x09,0x62,0x49,0xc7,0xf4,0x6e,0x51, - 0x35,0xf2,0x4a,0x24,0x2e,0xeb,0x3d,0x3f, - 0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3 - }; - -#if 0 -static DES_LONG cbc_cksum_ret=0xB462FEF7L; -#else -static DES_LONG cbc_cksum_ret=0xF7FE62B4L; -#endif -static unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4}; - -static char *pt(unsigned char *p); -static int cfb_test(int bits, unsigned char *cfb_cipher); -static int cfb64_test(unsigned char *cfb_cipher); -static int ede_cfb64_test(unsigned char *cfb_cipher); -int main(int argc, char *argv[]) - { - int j,err=0; - unsigned int i; - des_cblock in,out,outin,iv3,iv2; - des_key_schedule ks,ks2,ks3; - unsigned char cbc_in[40]; - unsigned char cbc_out[40]; - DES_LONG cs; - unsigned char cret[8]; -#ifdef _CRAY - struct { - int a:32; - int b:32; - } lqret[2]; -#else - DES_LONG lqret[4]; -#endif - int num; - char *str; - -#ifndef OPENSSL_NO_DESCBCM - printf("Doing cbcm\n"); - if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0) - { - printf("Key error %d\n",j); - err=1; - } - if ((j=DES_set_key_checked(&cbc2_key,&ks2)) != 0) - { - printf("Key error %d\n",j); - err=1; - } - if ((j=DES_set_key_checked(&cbc3_key,&ks3)) != 0) - { - printf("Key error %d\n",j); - err=1; - } - memset(cbc_out,0,40); - memset(cbc_in,0,40); - i=strlen((char *)cbc_data)+1; - /* i=((i+7)/8)*8; */ - memcpy(iv3,cbc_iv,sizeof(cbc_iv)); - memset(iv2,'\0',sizeof iv2); - - DES_ede3_cbcm_encrypt(cbc_data,cbc_out,16L,&ks,&ks2,&ks3,&iv3,&iv2, - DES_ENCRYPT); - DES_ede3_cbcm_encrypt(&cbc_data[16],&cbc_out[16],i-16,&ks,&ks2,&ks3, - &iv3,&iv2,DES_ENCRYPT); - /* if (memcmp(cbc_out,cbc3_ok, - (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0) - { - printf("des_ede3_cbc_encrypt encrypt error\n"); - err=1; - } - */ - memcpy(iv3,cbc_iv,sizeof(cbc_iv)); - memset(iv2,'\0',sizeof iv2); - DES_ede3_cbcm_encrypt(cbc_out,cbc_in,i,&ks,&ks2,&ks3,&iv3,&iv2,DES_DECRYPT); - if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0) - { - unsigned int n; - - printf("des_ede3_cbcm_encrypt decrypt error\n"); - for(n=0 ; n < i ; ++n) - printf(" %02x",cbc_data[n]); - printf("\n"); - for(n=0 ; n < i ; ++n) - printf(" %02x",cbc_in[n]); - printf("\n"); - err=1; - } -#endif - - printf("Doing ecb\n"); - for (i=0; i>4)&0xf]; - ret[i*2+1]=f[p[i]&0xf]; - } - ret[16]='\0'; - return(ret); - } - -#ifndef LIBDES_LIT - -static int cfb_test(int bits, unsigned char *cfb_cipher) - { - des_key_schedule ks; - int i,err=0; - - DES_set_key_checked(&cfb_key,&ks); - memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); - des_cfb_encrypt(plain,cfb_buf1,bits,sizeof(plain),ks,&cfb_tmp, - DES_ENCRYPT); - if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) - { - err=1; - printf("cfb_encrypt encrypt error\n"); - for (i=0; i<24; i+=8) - printf("%s\n",pt(&(cfb_buf1[i]))); - } - memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); - des_cfb_encrypt(cfb_buf1,cfb_buf2,bits,sizeof(plain),ks,&cfb_tmp, - DES_DECRYPT); - if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) - { - err=1; - printf("cfb_encrypt decrypt error\n"); - for (i=0; i<24; i+=8) - printf("%s\n",pt(&(cfb_buf1[i]))); - } - return(err); - } - -static int cfb64_test(unsigned char *cfb_cipher) - { - des_key_schedule ks; - int err=0,i,n; - - DES_set_key_checked(&cfb_key,&ks); - memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); - n=0; - des_cfb64_encrypt(plain,cfb_buf1,12,ks,&cfb_tmp,&n,DES_ENCRYPT); - des_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),sizeof(plain)-12,ks, - &cfb_tmp,&n,DES_ENCRYPT); - if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) - { - err=1; - printf("cfb_encrypt encrypt error\n"); - for (i=0; i<24; i+=8) - printf("%s\n",pt(&(cfb_buf1[i]))); - } - memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); - n=0; - des_cfb64_encrypt(cfb_buf1,cfb_buf2,17,ks,&cfb_tmp,&n,DES_DECRYPT); - des_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]), - sizeof(plain)-17,ks,&cfb_tmp,&n,DES_DECRYPT); - if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) - { - err=1; - printf("cfb_encrypt decrypt error\n"); - for (i=0; i<24; i+=8) - printf("%s\n",pt(&(cfb_buf2[i]))); - } - return(err); - } - -static int ede_cfb64_test(unsigned char *cfb_cipher) - { - des_key_schedule ks; - int err=0,i,n; - - DES_set_key_checked(&cfb_key,&ks); - memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); - n=0; - des_ede3_cfb64_encrypt(plain,cfb_buf1,12,ks,ks,ks,&cfb_tmp,&n, - DES_ENCRYPT); - des_ede3_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]), - sizeof(plain)-12,ks,ks,ks, - &cfb_tmp,&n,DES_ENCRYPT); - if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) - { - err=1; - printf("ede_cfb_encrypt encrypt error\n"); - for (i=0; i<24; i+=8) - printf("%s\n",pt(&(cfb_buf1[i]))); - } - memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); - n=0; - des_ede3_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks,ks,ks, - &cfb_tmp,&n,DES_DECRYPT); - des_ede3_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]), - sizeof(plain)-17,ks,ks,ks, - &cfb_tmp,&n,DES_DECRYPT); - if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) - { - err=1; - printf("ede_cfb_encrypt decrypt error\n"); - for (i=0; i<24; i+=8) - printf("%s\n",pt(&(cfb_buf2[i]))); - } - return(err); - } - -#endif -#endif diff --git a/src/lib/libssl/src/crypto/dh/dhtest.c b/src/lib/libssl/src/crypto/dh/dhtest.c deleted file mode 100644 index 882f5c310a..0000000000 --- a/src/lib/libssl/src/crypto/dh/dhtest.c +++ /dev/null @@ -1,226 +0,0 @@ -/* crypto/dh/dhtest.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.] - */ - -/* Until the key-gen callbacks are modified to use newer prototypes, we allow - * deprecated functions for openssl-internal code */ -#ifdef OPENSSL_NO_DEPRECATED -#undef OPENSSL_NO_DEPRECATED -#endif - -#include -#include -#include - -#include "../e_os.h" - -#include -#include -#include -#include -#include - -#ifdef OPENSSL_NO_DH -int main(int argc, char *argv[]) -{ - printf("No DH support\n"); - return(0); -} -#else -#include - -#ifdef OPENSSL_SYS_WIN16 -#define MS_CALLBACK _far _loadds -#else -#define MS_CALLBACK -#endif - -static int MS_CALLBACK cb(int p, int n, BN_GENCB *arg); - -static const char rnd_seed[] = "string to make the random number generator think it has entropy"; - -int main(int argc, char *argv[]) - { - BN_GENCB _cb; - DH *a; - DH *b=NULL; - char buf[12]; - unsigned char *abuf=NULL,*bbuf=NULL; - int i,alen,blen,aout,bout,ret=1; - BIO *out; - - CRYPTO_malloc_debug_init(); - CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL); - CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); - -#ifdef OPENSSL_SYS_WIN32 - CRYPTO_malloc_init(); -#endif - - RAND_seed(rnd_seed, sizeof rnd_seed); - - out=BIO_new(BIO_s_file()); - if (out == NULL) EXIT(1); - BIO_set_fp(out,stdout,BIO_NOCLOSE); - - BN_GENCB_set(&_cb, &cb, out); - if(((a = DH_new()) == NULL) || !DH_generate_parameters_ex(a, 64, - DH_GENERATOR_5, &_cb)) - goto err; - - if (!DH_check(a, &i)) goto err; - if (i & DH_CHECK_P_NOT_PRIME) - BIO_puts(out, "p value is not prime\n"); - if (i & DH_CHECK_P_NOT_SAFE_PRIME) - BIO_puts(out, "p value is not a safe prime\n"); - if (i & DH_UNABLE_TO_CHECK_GENERATOR) - BIO_puts(out, "unable to check the generator value\n"); - if (i & DH_NOT_SUITABLE_GENERATOR) - BIO_puts(out, "the g value is not a generator\n"); - - BIO_puts(out,"\np ="); - BN_print(out,a->p); - BIO_puts(out,"\ng ="); - BN_print(out,a->g); - BIO_puts(out,"\n"); - - b=DH_new(); - if (b == NULL) goto err; - - b->p=BN_dup(a->p); - b->g=BN_dup(a->g); - if ((b->p == NULL) || (b->g == NULL)) goto err; - - /* Set a to run with normal modexp and b to use constant time */ - a->flags &= ~DH_FLAG_NO_EXP_CONSTTIME; - b->flags |= DH_FLAG_NO_EXP_CONSTTIME; - - if (!DH_generate_key(a)) goto err; - BIO_puts(out,"pri 1="); - BN_print(out,a->priv_key); - BIO_puts(out,"\npub 1="); - BN_print(out,a->pub_key); - BIO_puts(out,"\n"); - - if (!DH_generate_key(b)) goto err; - BIO_puts(out,"pri 2="); - BN_print(out,b->priv_key); - BIO_puts(out,"\npub 2="); - BN_print(out,b->pub_key); - BIO_puts(out,"\n"); - - alen=DH_size(a); - abuf=(unsigned char *)OPENSSL_malloc(alen); - aout=DH_compute_key(abuf,b->pub_key,a); - - BIO_puts(out,"key1 ="); - for (i=0; ipub_key,b); - - BIO_puts(out,"key2 ="); - for (i=0; iarg,&c,1); - (void)BIO_flush(arg->arg); -#ifdef LINT - p=n; -#endif - return 1; - } -#endif diff --git a/src/lib/libssl/src/crypto/dsa/dsatest.c b/src/lib/libssl/src/crypto/dsa/dsatest.c deleted file mode 100644 index edffd24e6b..0000000000 --- a/src/lib/libssl/src/crypto/dsa/dsatest.c +++ /dev/null @@ -1,259 +0,0 @@ -/* crypto/dsa/dsatest.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.] - */ - -/* Until the key-gen callbacks are modified to use newer prototypes, we allow - * deprecated functions for openssl-internal code */ -#ifdef OPENSSL_NO_DEPRECATED -#undef OPENSSL_NO_DEPRECATED -#endif - -#include -#include -#include -#include -#include - -#include "../e_os.h" - -#include -#include -#include -#include -#include - -#ifdef OPENSSL_NO_DSA -int main(int argc, char *argv[]) -{ - printf("No DSA support\n"); - return(0); -} -#else -#include - -#ifdef OPENSSL_SYS_WIN16 -#define MS_CALLBACK _far _loadds -#else -#define MS_CALLBACK -#endif - -static int MS_CALLBACK dsa_cb(int p, int n, BN_GENCB *arg); - -/* seed, out_p, out_q, out_g are taken from the updated Appendix 5 to - * FIPS PUB 186 and also appear in Appendix 5 to FIPS PIB 186-1 */ -static unsigned char seed[20]={ - 0xd5,0x01,0x4e,0x4b,0x60,0xef,0x2b,0xa8,0xb6,0x21,0x1b,0x40, - 0x62,0xba,0x32,0x24,0xe0,0x42,0x7d,0xd3, - }; - -static unsigned char out_p[]={ - 0x8d,0xf2,0xa4,0x94,0x49,0x22,0x76,0xaa, - 0x3d,0x25,0x75,0x9b,0xb0,0x68,0x69,0xcb, - 0xea,0xc0,0xd8,0x3a,0xfb,0x8d,0x0c,0xf7, - 0xcb,0xb8,0x32,0x4f,0x0d,0x78,0x82,0xe5, - 0xd0,0x76,0x2f,0xc5,0xb7,0x21,0x0e,0xaf, - 0xc2,0xe9,0xad,0xac,0x32,0xab,0x7a,0xac, - 0x49,0x69,0x3d,0xfb,0xf8,0x37,0x24,0xc2, - 0xec,0x07,0x36,0xee,0x31,0xc8,0x02,0x91, - }; - -static unsigned char out_q[]={ - 0xc7,0x73,0x21,0x8c,0x73,0x7e,0xc8,0xee, - 0x99,0x3b,0x4f,0x2d,0xed,0x30,0xf4,0x8e, - 0xda,0xce,0x91,0x5f, - }; - -static unsigned char out_g[]={ - 0x62,0x6d,0x02,0x78,0x39,0xea,0x0a,0x13, - 0x41,0x31,0x63,0xa5,0x5b,0x4c,0xb5,0x00, - 0x29,0x9d,0x55,0x22,0x95,0x6c,0xef,0xcb, - 0x3b,0xff,0x10,0xf3,0x99,0xce,0x2c,0x2e, - 0x71,0xcb,0x9d,0xe5,0xfa,0x24,0xba,0xbf, - 0x58,0xe5,0xb7,0x95,0x21,0x92,0x5c,0x9c, - 0xc4,0x2e,0x9f,0x6f,0x46,0x4b,0x08,0x8c, - 0xc5,0x72,0xaf,0x53,0xe6,0xd7,0x88,0x02, - }; - -static const unsigned char str1[]="12345678901234567890"; - -static const char rnd_seed[] = "string to make the random number generator think it has entropy"; - -static BIO *bio_err=NULL; - -int main(int argc, char **argv) - { - BN_GENCB cb; - DSA *dsa=NULL; - int counter,ret=0,i,j; - unsigned char buf[256]; - unsigned long h; - unsigned char sig[256]; - unsigned int siglen; - - if (bio_err == NULL) - bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); - - CRYPTO_malloc_debug_init(); - CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL); - CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); - - ERR_load_crypto_strings(); - RAND_seed(rnd_seed, sizeof rnd_seed); - - BIO_printf(bio_err,"test generation of DSA parameters\n"); - - BN_GENCB_set(&cb, dsa_cb, bio_err); - if(((dsa = DSA_new()) == NULL) || !DSA_generate_parameters_ex(dsa, 512, - seed, 20, &counter, &h, &cb)) - goto end; - - BIO_printf(bio_err,"seed\n"); - for (i=0; i<20; i+=4) - { - BIO_printf(bio_err,"%02X%02X%02X%02X ", - seed[i],seed[i+1],seed[i+2],seed[i+3]); - } - BIO_printf(bio_err,"\ncounter=%d h=%ld\n",counter,h); - - DSA_print(bio_err,dsa,0); - if (counter != 105) - { - BIO_printf(bio_err,"counter should be 105\n"); - goto end; - } - if (h != 2) - { - BIO_printf(bio_err,"h should be 2\n"); - goto end; - } - - i=BN_bn2bin(dsa->q,buf); - j=sizeof(out_q); - if ((i != j) || (memcmp(buf,out_q,i) != 0)) - { - BIO_printf(bio_err,"q value is wrong\n"); - goto end; - } - - i=BN_bn2bin(dsa->p,buf); - j=sizeof(out_p); - if ((i != j) || (memcmp(buf,out_p,i) != 0)) - { - BIO_printf(bio_err,"p value is wrong\n"); - goto end; - } - - i=BN_bn2bin(dsa->g,buf); - j=sizeof(out_g); - if ((i != j) || (memcmp(buf,out_g,i) != 0)) - { - BIO_printf(bio_err,"g value is wrong\n"); - goto end; - } - - dsa->flags |= DSA_FLAG_NO_EXP_CONSTTIME; - DSA_generate_key(dsa); - DSA_sign(0, str1, 20, sig, &siglen, dsa); - if (DSA_verify(0, str1, 20, sig, siglen, dsa) == 1) - ret=1; - - dsa->flags &= ~DSA_FLAG_NO_EXP_CONSTTIME; - DSA_generate_key(dsa); - DSA_sign(0, str1, 20, sig, &siglen, dsa); - if (DSA_verify(0, str1, 20, sig, siglen, dsa) == 1) - ret=1; - -end: - if (!ret) - ERR_print_errors(bio_err); - if (dsa != NULL) DSA_free(dsa); - CRYPTO_cleanup_all_ex_data(); - ERR_remove_thread_state(NULL); - ERR_free_strings(); - CRYPTO_mem_leaks(bio_err); - if (bio_err != NULL) - { - BIO_free(bio_err); - bio_err = NULL; - } -#ifdef OPENSSL_SYS_NETWARE - if (!ret) printf("ERROR\n"); -#endif - EXIT(!ret); - return(0); - } - -static int MS_CALLBACK dsa_cb(int p, int n, BN_GENCB *arg) - { - char c='*'; - static int ok=0,num=0; - - if (p == 0) { c='.'; num++; }; - if (p == 1) c='+'; - if (p == 2) { c='*'; ok++; } - if (p == 3) c='\n'; - BIO_write(arg->arg,&c,1); - (void)BIO_flush(arg->arg); - - if (!ok && (p == 0) && (num > 1)) - { - BIO_printf((BIO *)arg,"error in dsatest\n"); - return 0; - } - return 1; - } -#endif diff --git a/src/lib/libssl/src/crypto/ec/ectest.c b/src/lib/libssl/src/crypto/ec/ectest.c deleted file mode 100644 index 102eaa9b23..0000000000 --- a/src/lib/libssl/src/crypto/ec/ectest.c +++ /dev/null @@ -1,1489 +0,0 @@ -/* crypto/ec/ectest.c */ -/* - * Originally written by Bodo Moeller for the OpenSSL project. - */ -/* ==================================================================== - * Copyright (c) 1998-2001 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). - * - */ -/* ==================================================================== - * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. - * - * Portions of the attached software ("Contribution") are developed by - * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. - * - * The Contribution is licensed pursuant to the OpenSSL open source - * license provided above. - * - * The elliptic curve binary polynomial software is originally written by - * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories. - * - */ - -#include -#include -#ifdef FLAT_INC -#include "e_os.h" -#else -#include "../e_os.h" -#endif -#include -#include - - -#ifdef OPENSSL_NO_EC -int main(int argc, char * argv[]) { puts("Elliptic curves are disabled."); return 0; } -#else - - -#include -#ifndef OPENSSL_NO_ENGINE -#include -#endif -#include -#include -#include -#include -#include -#include - -#if defined(_MSC_VER) && defined(_MIPS_) && (_MSC_VER/100==12) -/* suppress "too big too optimize" warning */ -#pragma warning(disable:4959) -#endif - -#define ABORT do { \ - fflush(stdout); \ - fprintf(stderr, "%s:%d: ABORT\n", __FILE__, __LINE__); \ - ERR_print_errors_fp(stderr); \ - EXIT(1); \ -} while (0) - -#define TIMING_BASE_PT 0 -#define TIMING_RAND_PT 1 -#define TIMING_SIMUL 2 - -#if 0 -static void timings(EC_GROUP *group, int type, BN_CTX *ctx) - { - clock_t clck; - int i, j; - BIGNUM *s; - BIGNUM *r[10], *r0[10]; - EC_POINT *P; - - s = BN_new(); - if (s == NULL) ABORT; - - fprintf(stdout, "Timings for %d-bit field, ", EC_GROUP_get_degree(group)); - if (!EC_GROUP_get_order(group, s, ctx)) ABORT; - fprintf(stdout, "%d-bit scalars ", (int)BN_num_bits(s)); - fflush(stdout); - - P = EC_POINT_new(group); - if (P == NULL) ABORT; - EC_POINT_copy(P, EC_GROUP_get0_generator(group)); - - for (i = 0; i < 10; i++) - { - if ((r[i] = BN_new()) == NULL) ABORT; - if (!BN_pseudo_rand(r[i], BN_num_bits(s), 0, 0)) ABORT; - if (type != TIMING_BASE_PT) - { - if ((r0[i] = BN_new()) == NULL) ABORT; - if (!BN_pseudo_rand(r0[i], BN_num_bits(s), 0, 0)) ABORT; - } - } - - clck = clock(); - for (i = 0; i < 10; i++) - { - for (j = 0; j < 10; j++) - { - if (!EC_POINT_mul(group, P, (type != TIMING_RAND_PT) ? r[i] : NULL, - (type != TIMING_BASE_PT) ? P : NULL, (type != TIMING_BASE_PT) ? r0[i] : NULL, ctx)) ABORT; - } - } - clck = clock() - clck; - - fprintf(stdout, "\n"); - -#ifdef CLOCKS_PER_SEC - /* "To determine the time in seconds, the value returned - * by the clock function should be divided by the value - * of the macro CLOCKS_PER_SEC." - * -- ISO/IEC 9899 */ -# define UNIT "s" -#else - /* "`CLOCKS_PER_SEC' undeclared (first use this function)" - * -- cc on NeXTstep/OpenStep */ -# define UNIT "units" -# define CLOCKS_PER_SEC 1 -#endif - - if (type == TIMING_BASE_PT) { - fprintf(stdout, "%i %s in %.2f " UNIT "\n", i*j, - "base point multiplications", (double)clck/CLOCKS_PER_SEC); - } else if (type == TIMING_RAND_PT) { - fprintf(stdout, "%i %s in %.2f " UNIT "\n", i*j, - "random point multiplications", (double)clck/CLOCKS_PER_SEC); - } else if (type == TIMING_SIMUL) { - fprintf(stdout, "%i %s in %.2f " UNIT "\n", i*j, - "s*P+t*Q operations", (double)clck/CLOCKS_PER_SEC); - } - fprintf(stdout, "average: %.4f " UNIT "\n", (double)clck/(CLOCKS_PER_SEC*i*j)); - - EC_POINT_free(P); - BN_free(s); - for (i = 0; i < 10; i++) - { - BN_free(r[i]); - if (type != TIMING_BASE_PT) BN_free(r0[i]); - } - } -#endif - -/* test multiplication with group order, long and negative scalars */ -static void group_order_tests(EC_GROUP *group) - { - BIGNUM *n1, *n2, *order; - EC_POINT *P = EC_POINT_new(group); - EC_POINT *Q = EC_POINT_new(group); - BN_CTX *ctx = BN_CTX_new(); - - n1 = BN_new(); n2 = BN_new(); order = BN_new(); - fprintf(stdout, "verify group order ..."); - fflush(stdout); - if (!EC_GROUP_get_order(group, order, ctx)) ABORT; - if (!EC_POINT_mul(group, Q, order, NULL, NULL, ctx)) ABORT; - if (!EC_POINT_is_at_infinity(group, Q)) ABORT; - fprintf(stdout, "."); - fflush(stdout); - if (!EC_GROUP_precompute_mult(group, ctx)) ABORT; - if (!EC_POINT_mul(group, Q, order, NULL, NULL, ctx)) ABORT; - if (!EC_POINT_is_at_infinity(group, Q)) ABORT; - fprintf(stdout, " ok\n"); - fprintf(stdout, "long/negative scalar tests ... "); - if (!BN_one(n1)) ABORT; - /* n1 = 1 - order */ - if (!BN_sub(n1, n1, order)) ABORT; - if(!EC_POINT_mul(group, Q, NULL, P, n1, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, Q, P, ctx)) ABORT; - /* n2 = 1 + order */ - if (!BN_add(n2, order, BN_value_one())) ABORT; - if(!EC_POINT_mul(group, Q, NULL, P, n2, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, Q, P, ctx)) ABORT; - /* n2 = (1 - order) * (1 + order) */ - if (!BN_mul(n2, n1, n2, ctx)) ABORT; - if(!EC_POINT_mul(group, Q, NULL, P, n2, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, Q, P, ctx)) ABORT; - fprintf(stdout, "ok\n"); - EC_POINT_free(P); - EC_POINT_free(Q); - BN_free(n1); - BN_free(n2); - BN_free(order); - BN_CTX_free(ctx); - } - -static void prime_field_tests(void) - { - BN_CTX *ctx = NULL; - BIGNUM *p, *a, *b; - EC_GROUP *group; - EC_GROUP *P_160 = NULL, *P_192 = NULL, *P_224 = NULL, *P_256 = NULL, *P_384 = NULL, *P_521 = NULL; - EC_POINT *P, *Q, *R; - BIGNUM *x, *y, *z; - unsigned char buf[100]; - size_t i, len; - int k; - -#if 1 /* optional */ - ctx = BN_CTX_new(); - if (!ctx) ABORT; -#endif - - p = BN_new(); - a = BN_new(); - b = BN_new(); - if (!p || !a || !b) ABORT; - - if (!BN_hex2bn(&p, "17")) ABORT; - if (!BN_hex2bn(&a, "1")) ABORT; - if (!BN_hex2bn(&b, "1")) ABORT; - - group = EC_GROUP_new(EC_GFp_mont_method()); /* applications should use EC_GROUP_new_curve_GFp - * so that the library gets to choose the EC_METHOD */ - if (!group) ABORT; - - if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT; - - { - EC_GROUP *tmp; - tmp = EC_GROUP_new(EC_GROUP_method_of(group)); - if (!tmp) ABORT; - if (!EC_GROUP_copy(tmp, group)) ABORT; - EC_GROUP_free(group); - group = tmp; - } - - if (!EC_GROUP_get_curve_GFp(group, p, a, b, ctx)) ABORT; - - fprintf(stdout, "Curve defined by Weierstrass equation\n y^2 = x^3 + a*x + b (mod 0x"); - BN_print_fp(stdout, p); - fprintf(stdout, ")\n a = 0x"); - BN_print_fp(stdout, a); - fprintf(stdout, "\n b = 0x"); - BN_print_fp(stdout, b); - fprintf(stdout, "\n"); - - P = EC_POINT_new(group); - Q = EC_POINT_new(group); - R = EC_POINT_new(group); - if (!P || !Q || !R) ABORT; - - if (!EC_POINT_set_to_infinity(group, P)) ABORT; - if (!EC_POINT_is_at_infinity(group, P)) ABORT; - - buf[0] = 0; - if (!EC_POINT_oct2point(group, Q, buf, 1, ctx)) ABORT; - - if (!EC_POINT_add(group, P, P, Q, ctx)) ABORT; - if (!EC_POINT_is_at_infinity(group, P)) ABORT; - - x = BN_new(); - y = BN_new(); - z = BN_new(); - if (!x || !y || !z) ABORT; - - if (!BN_hex2bn(&x, "D")) ABORT; - if (!EC_POINT_set_compressed_coordinates_GFp(group, Q, x, 1, ctx)) ABORT; - if (!EC_POINT_is_on_curve(group, Q, ctx)) - { - if (!EC_POINT_get_affine_coordinates_GFp(group, Q, x, y, ctx)) ABORT; - fprintf(stderr, "Point is not on curve: x = 0x"); - BN_print_fp(stderr, x); - fprintf(stderr, ", y = 0x"); - BN_print_fp(stderr, y); - fprintf(stderr, "\n"); - ABORT; - } - - fprintf(stdout, "A cyclic subgroup:\n"); - k = 100; - do - { - if (k-- == 0) ABORT; - - if (EC_POINT_is_at_infinity(group, P)) - fprintf(stdout, " point at infinity\n"); - else - { - if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT; - - fprintf(stdout, " x = 0x"); - BN_print_fp(stdout, x); - fprintf(stdout, ", y = 0x"); - BN_print_fp(stdout, y); - fprintf(stdout, "\n"); - } - - if (!EC_POINT_copy(R, P)) ABORT; - if (!EC_POINT_add(group, P, P, Q, ctx)) ABORT; - -#if 0 /* optional */ - { - EC_POINT *points[3]; - - points[0] = R; - points[1] = Q; - points[2] = P; - if (!EC_POINTs_make_affine(group, 2, points, ctx)) ABORT; - } -#endif - - } - while (!EC_POINT_is_at_infinity(group, P)); - - if (!EC_POINT_add(group, P, Q, R, ctx)) ABORT; - if (!EC_POINT_is_at_infinity(group, P)) ABORT; - - len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_COMPRESSED, buf, sizeof buf, ctx); - if (len == 0) ABORT; - if (!EC_POINT_oct2point(group, P, buf, len, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, P, Q, ctx)) ABORT; - fprintf(stdout, "Generator as octet string, compressed form:\n "); - for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]); - - len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_UNCOMPRESSED, buf, sizeof buf, ctx); - if (len == 0) ABORT; - if (!EC_POINT_oct2point(group, P, buf, len, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, P, Q, ctx)) ABORT; - fprintf(stdout, "\nGenerator as octet string, uncompressed form:\n "); - for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]); - - len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_HYBRID, buf, sizeof buf, ctx); - if (len == 0) ABORT; - if (!EC_POINT_oct2point(group, P, buf, len, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, P, Q, ctx)) ABORT; - fprintf(stdout, "\nGenerator as octet string, hybrid form:\n "); - for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]); - - if (!EC_POINT_get_Jprojective_coordinates_GFp(group, R, x, y, z, ctx)) ABORT; - fprintf(stdout, "\nA representation of the inverse of that generator in\nJacobian projective coordinates:\n X = 0x"); - BN_print_fp(stdout, x); - fprintf(stdout, ", Y = 0x"); - BN_print_fp(stdout, y); - fprintf(stdout, ", Z = 0x"); - BN_print_fp(stdout, z); - fprintf(stdout, "\n"); - - if (!EC_POINT_invert(group, P, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, P, R, ctx)) ABORT; - - - /* Curve secp160r1 (Certicom Research SEC 2 Version 1.0, section 2.4.2, 2000) - * -- not a NIST curve, but commonly used */ - - if (!BN_hex2bn(&p, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF")) ABORT; - if (1 != BN_is_prime_ex(p, BN_prime_checks, ctx, NULL)) ABORT; - if (!BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFC")) ABORT; - if (!BN_hex2bn(&b, "1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45")) ABORT; - if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT; - - if (!BN_hex2bn(&x, "4A96B5688EF573284664698968C38BB913CBFC82")) ABORT; - if (!BN_hex2bn(&y, "23a628553168947d59dcc912042351377ac5fb32")) ABORT; - if (!EC_POINT_set_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT; - if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT; - if (!BN_hex2bn(&z, "0100000000000000000001F4C8F927AED3CA752257")) ABORT; - if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT; - - if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT; - fprintf(stdout, "\nSEC2 curve secp160r1 -- Generator:\n x = 0x"); - BN_print_fp(stdout, x); - fprintf(stdout, "\n y = 0x"); - BN_print_fp(stdout, y); - fprintf(stdout, "\n"); - /* G_y value taken from the standard: */ - if (!BN_hex2bn(&z, "23a628553168947d59dcc912042351377ac5fb32")) ABORT; - if (0 != BN_cmp(y, z)) ABORT; - - fprintf(stdout, "verify degree ..."); - if (EC_GROUP_get_degree(group) != 160) ABORT; - fprintf(stdout, " ok\n"); - - group_order_tests(group); - - if (!(P_160 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT; - if (!EC_GROUP_copy(P_160, group)) ABORT; - - - /* Curve P-192 (FIPS PUB 186-2, App. 6) */ - - if (!BN_hex2bn(&p, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF")) ABORT; - if (1 != BN_is_prime_ex(p, BN_prime_checks, ctx, NULL)) ABORT; - if (!BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC")) ABORT; - if (!BN_hex2bn(&b, "64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1")) ABORT; - if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT; - - if (!BN_hex2bn(&x, "188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012")) ABORT; - if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 1, ctx)) ABORT; - if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT; - if (!BN_hex2bn(&z, "FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831")) ABORT; - if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT; - - if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT; - fprintf(stdout, "\nNIST curve P-192 -- Generator:\n x = 0x"); - BN_print_fp(stdout, x); - fprintf(stdout, "\n y = 0x"); - BN_print_fp(stdout, y); - fprintf(stdout, "\n"); - /* G_y value taken from the standard: */ - if (!BN_hex2bn(&z, "07192B95FFC8DA78631011ED6B24CDD573F977A11E794811")) ABORT; - if (0 != BN_cmp(y, z)) ABORT; - - fprintf(stdout, "verify degree ..."); - if (EC_GROUP_get_degree(group) != 192) ABORT; - fprintf(stdout, " ok\n"); - - group_order_tests(group); - - if (!(P_192 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT; - if (!EC_GROUP_copy(P_192, group)) ABORT; - - - /* Curve P-224 (FIPS PUB 186-2, App. 6) */ - - if (!BN_hex2bn(&p, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001")) ABORT; - if (1 != BN_is_prime_ex(p, BN_prime_checks, ctx, NULL)) ABORT; - if (!BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE")) ABORT; - if (!BN_hex2bn(&b, "B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4")) ABORT; - if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT; - - if (!BN_hex2bn(&x, "B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21")) ABORT; - if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 0, ctx)) ABORT; - if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT; - if (!BN_hex2bn(&z, "FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D")) ABORT; - if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT; - - if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT; - fprintf(stdout, "\nNIST curve P-224 -- Generator:\n x = 0x"); - BN_print_fp(stdout, x); - fprintf(stdout, "\n y = 0x"); - BN_print_fp(stdout, y); - fprintf(stdout, "\n"); - /* G_y value taken from the standard: */ - if (!BN_hex2bn(&z, "BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34")) ABORT; - if (0 != BN_cmp(y, z)) ABORT; - - fprintf(stdout, "verify degree ..."); - if (EC_GROUP_get_degree(group) != 224) ABORT; - fprintf(stdout, " ok\n"); - - group_order_tests(group); - - if (!(P_224 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT; - if (!EC_GROUP_copy(P_224, group)) ABORT; - - - /* Curve P-256 (FIPS PUB 186-2, App. 6) */ - - if (!BN_hex2bn(&p, "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF")) ABORT; - if (1 != BN_is_prime_ex(p, BN_prime_checks, ctx, NULL)) ABORT; - if (!BN_hex2bn(&a, "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC")) ABORT; - if (!BN_hex2bn(&b, "5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B")) ABORT; - if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT; - - if (!BN_hex2bn(&x, "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296")) ABORT; - if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 1, ctx)) ABORT; - if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT; - if (!BN_hex2bn(&z, "FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E" - "84F3B9CAC2FC632551")) ABORT; - if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT; - - if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT; - fprintf(stdout, "\nNIST curve P-256 -- Generator:\n x = 0x"); - BN_print_fp(stdout, x); - fprintf(stdout, "\n y = 0x"); - BN_print_fp(stdout, y); - fprintf(stdout, "\n"); - /* G_y value taken from the standard: */ - if (!BN_hex2bn(&z, "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5")) ABORT; - if (0 != BN_cmp(y, z)) ABORT; - - fprintf(stdout, "verify degree ..."); - if (EC_GROUP_get_degree(group) != 256) ABORT; - fprintf(stdout, " ok\n"); - - group_order_tests(group); - - if (!(P_256 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT; - if (!EC_GROUP_copy(P_256, group)) ABORT; - - - /* Curve P-384 (FIPS PUB 186-2, App. 6) */ - - if (!BN_hex2bn(&p, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" - "FFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF")) ABORT; - if (1 != BN_is_prime_ex(p, BN_prime_checks, ctx, NULL)) ABORT; - if (!BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" - "FFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC")) ABORT; - if (!BN_hex2bn(&b, "B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141" - "120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF")) ABORT; - if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT; - - if (!BN_hex2bn(&x, "AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B" - "9859F741E082542A385502F25DBF55296C3A545E3872760AB7")) ABORT; - if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 1, ctx)) ABORT; - if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT; - if (!BN_hex2bn(&z, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" - "FFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973")) ABORT; - if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT; - - if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT; - fprintf(stdout, "\nNIST curve P-384 -- Generator:\n x = 0x"); - BN_print_fp(stdout, x); - fprintf(stdout, "\n y = 0x"); - BN_print_fp(stdout, y); - fprintf(stdout, "\n"); - /* G_y value taken from the standard: */ - if (!BN_hex2bn(&z, "3617DE4A96262C6F5D9E98BF9292DC29F8F41DBD289A14" - "7CE9DA3113B5F0B8C00A60B1CE1D7E819D7A431D7C90EA0E5F")) ABORT; - if (0 != BN_cmp(y, z)) ABORT; - - fprintf(stdout, "verify degree ..."); - if (EC_GROUP_get_degree(group) != 384) ABORT; - fprintf(stdout, " ok\n"); - - group_order_tests(group); - - if (!(P_384 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT; - if (!EC_GROUP_copy(P_384, group)) ABORT; - - - /* Curve P-521 (FIPS PUB 186-2, App. 6) */ - - if (!BN_hex2bn(&p, "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" - "FFFFFFFFFFFFFFFFFFFFFFFFFFFF")) ABORT; - if (1 != BN_is_prime_ex(p, BN_prime_checks, ctx, NULL)) ABORT; - if (!BN_hex2bn(&a, "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" - "FFFFFFFFFFFFFFFFFFFFFFFFFFFC")) ABORT; - if (!BN_hex2bn(&b, "051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B" - "315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573" - "DF883D2C34F1EF451FD46B503F00")) ABORT; - if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT; - - if (!BN_hex2bn(&x, "C6858E06B70404E9CD9E3ECB662395B4429C648139053F" - "B521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B" - "3C1856A429BF97E7E31C2E5BD66")) ABORT; - if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 0, ctx)) ABORT; - if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT; - if (!BN_hex2bn(&z, "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" - "FFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5" - "C9B8899C47AEBB6FB71E91386409")) ABORT; - if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT; - - if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT; - fprintf(stdout, "\nNIST curve P-521 -- Generator:\n x = 0x"); - BN_print_fp(stdout, x); - fprintf(stdout, "\n y = 0x"); - BN_print_fp(stdout, y); - fprintf(stdout, "\n"); - /* G_y value taken from the standard: */ - if (!BN_hex2bn(&z, "11839296A789A3BC0045C8A5FB42C7D1BD998F54449579" - "B446817AFBD17273E662C97EE72995EF42640C550B9013FAD0761353C" - "7086A272C24088BE94769FD16650")) ABORT; - if (0 != BN_cmp(y, z)) ABORT; - - fprintf(stdout, "verify degree ..."); - if (EC_GROUP_get_degree(group) != 521) ABORT; - fprintf(stdout, " ok\n"); - - group_order_tests(group); - - if (!(P_521 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT; - if (!EC_GROUP_copy(P_521, group)) ABORT; - - - /* more tests using the last curve */ - - if (!EC_POINT_copy(Q, P)) ABORT; - if (EC_POINT_is_at_infinity(group, Q)) ABORT; - if (!EC_POINT_dbl(group, P, P, ctx)) ABORT; - if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT; - if (!EC_POINT_invert(group, Q, ctx)) ABORT; /* P = -2Q */ - - if (!EC_POINT_add(group, R, P, Q, ctx)) ABORT; - if (!EC_POINT_add(group, R, R, Q, ctx)) ABORT; - if (!EC_POINT_is_at_infinity(group, R)) ABORT; /* R = P + 2Q */ - - { - const EC_POINT *points[4]; - const BIGNUM *scalars[4]; - BIGNUM scalar3; - - if (EC_POINT_is_at_infinity(group, Q)) ABORT; - points[0] = Q; - points[1] = Q; - points[2] = Q; - points[3] = Q; - - if (!EC_GROUP_get_order(group, z, ctx)) ABORT; - if (!BN_add(y, z, BN_value_one())) ABORT; - if (BN_is_odd(y)) ABORT; - if (!BN_rshift1(y, y)) ABORT; - scalars[0] = y; /* (group order + 1)/2, so y*Q + y*Q = Q */ - scalars[1] = y; - - fprintf(stdout, "combined multiplication ..."); - fflush(stdout); - - /* z is still the group order */ - if (!EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx)) ABORT; - if (!EC_POINTs_mul(group, R, z, 2, points, scalars, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, P, R, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, R, Q, ctx)) ABORT; - - fprintf(stdout, "."); - fflush(stdout); - - if (!BN_pseudo_rand(y, BN_num_bits(y), 0, 0)) ABORT; - if (!BN_add(z, z, y)) ABORT; - BN_set_negative(z, 1); - scalars[0] = y; - scalars[1] = z; /* z = -(order + y) */ - - if (!EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx)) ABORT; - if (!EC_POINT_is_at_infinity(group, P)) ABORT; - - fprintf(stdout, "."); - fflush(stdout); - - if (!BN_pseudo_rand(x, BN_num_bits(y) - 1, 0, 0)) ABORT; - if (!BN_add(z, x, y)) ABORT; - BN_set_negative(z, 1); - scalars[0] = x; - scalars[1] = y; - scalars[2] = z; /* z = -(x+y) */ - - BN_init(&scalar3); - BN_zero(&scalar3); - scalars[3] = &scalar3; - - if (!EC_POINTs_mul(group, P, NULL, 4, points, scalars, ctx)) ABORT; - if (!EC_POINT_is_at_infinity(group, P)) ABORT; - - fprintf(stdout, " ok\n\n"); - - BN_free(&scalar3); - } - - -#if 0 - timings(P_160, TIMING_BASE_PT, ctx); - timings(P_160, TIMING_RAND_PT, ctx); - timings(P_160, TIMING_SIMUL, ctx); - timings(P_192, TIMING_BASE_PT, ctx); - timings(P_192, TIMING_RAND_PT, ctx); - timings(P_192, TIMING_SIMUL, ctx); - timings(P_224, TIMING_BASE_PT, ctx); - timings(P_224, TIMING_RAND_PT, ctx); - timings(P_224, TIMING_SIMUL, ctx); - timings(P_256, TIMING_BASE_PT, ctx); - timings(P_256, TIMING_RAND_PT, ctx); - timings(P_256, TIMING_SIMUL, ctx); - timings(P_384, TIMING_BASE_PT, ctx); - timings(P_384, TIMING_RAND_PT, ctx); - timings(P_384, TIMING_SIMUL, ctx); - timings(P_521, TIMING_BASE_PT, ctx); - timings(P_521, TIMING_RAND_PT, ctx); - timings(P_521, TIMING_SIMUL, ctx); -#endif - - - if (ctx) - BN_CTX_free(ctx); - BN_free(p); BN_free(a); BN_free(b); - EC_GROUP_free(group); - EC_POINT_free(P); - EC_POINT_free(Q); - EC_POINT_free(R); - BN_free(x); BN_free(y); BN_free(z); - - if (P_160) EC_GROUP_free(P_160); - if (P_192) EC_GROUP_free(P_192); - if (P_224) EC_GROUP_free(P_224); - if (P_256) EC_GROUP_free(P_256); - if (P_384) EC_GROUP_free(P_384); - if (P_521) EC_GROUP_free(P_521); - - } - -/* Change test based on whether binary point compression is enabled or not. */ -#ifdef OPENSSL_EC_BIN_PT_COMP -#define CHAR2_CURVE_TEST_INTERNAL(_name, _p, _a, _b, _x, _y, _y_bit, _order, _cof, _degree, _variable) \ - if (!BN_hex2bn(&x, _x)) ABORT; \ - if (!EC_POINT_set_compressed_coordinates_GF2m(group, P, x, _y_bit, ctx)) ABORT; \ - if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT; \ - if (!BN_hex2bn(&z, _order)) ABORT; \ - if (!BN_hex2bn(&cof, _cof)) ABORT; \ - if (!EC_GROUP_set_generator(group, P, z, cof)) ABORT; \ - if (!EC_POINT_get_affine_coordinates_GF2m(group, P, x, y, ctx)) ABORT; \ - fprintf(stdout, "\n%s -- Generator:\n x = 0x", _name); \ - BN_print_fp(stdout, x); \ - fprintf(stdout, "\n y = 0x"); \ - BN_print_fp(stdout, y); \ - fprintf(stdout, "\n"); \ - /* G_y value taken from the standard: */ \ - if (!BN_hex2bn(&z, _y)) ABORT; \ - if (0 != BN_cmp(y, z)) ABORT; -#else -#define CHAR2_CURVE_TEST_INTERNAL(_name, _p, _a, _b, _x, _y, _y_bit, _order, _cof, _degree, _variable) \ - if (!BN_hex2bn(&x, _x)) ABORT; \ - if (!BN_hex2bn(&y, _y)) ABORT; \ - if (!EC_POINT_set_affine_coordinates_GF2m(group, P, x, y, ctx)) ABORT; \ - if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT; \ - if (!BN_hex2bn(&z, _order)) ABORT; \ - if (!BN_hex2bn(&cof, _cof)) ABORT; \ - if (!EC_GROUP_set_generator(group, P, z, cof)) ABORT; \ - fprintf(stdout, "\n%s -- Generator:\n x = 0x", _name); \ - BN_print_fp(stdout, x); \ - fprintf(stdout, "\n y = 0x"); \ - BN_print_fp(stdout, y); \ - fprintf(stdout, "\n"); -#endif - -#define CHAR2_CURVE_TEST(_name, _p, _a, _b, _x, _y, _y_bit, _order, _cof, _degree, _variable) \ - if (!BN_hex2bn(&p, _p)) ABORT; \ - if (!BN_hex2bn(&a, _a)) ABORT; \ - if (!BN_hex2bn(&b, _b)) ABORT; \ - if (!EC_GROUP_set_curve_GF2m(group, p, a, b, ctx)) ABORT; \ - CHAR2_CURVE_TEST_INTERNAL(_name, _p, _a, _b, _x, _y, _y_bit, _order, _cof, _degree, _variable) \ - fprintf(stdout, "verify degree ..."); \ - if (EC_GROUP_get_degree(group) != _degree) ABORT; \ - fprintf(stdout, " ok\n"); \ - group_order_tests(group); \ - if (!(_variable = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT; \ - if (!EC_GROUP_copy(_variable, group)) ABORT; \ - -#ifndef OPENSSL_NO_EC2M - -static void char2_field_tests(void) - { - BN_CTX *ctx = NULL; - BIGNUM *p, *a, *b; - EC_GROUP *group; - EC_GROUP *C2_K163 = NULL, *C2_K233 = NULL, *C2_K283 = NULL, *C2_K409 = NULL, *C2_K571 = NULL; - EC_GROUP *C2_B163 = NULL, *C2_B233 = NULL, *C2_B283 = NULL, *C2_B409 = NULL, *C2_B571 = NULL; - EC_POINT *P, *Q, *R; - BIGNUM *x, *y, *z, *cof; - unsigned char buf[100]; - size_t i, len; - int k; - -#if 1 /* optional */ - ctx = BN_CTX_new(); - if (!ctx) ABORT; -#endif - - p = BN_new(); - a = BN_new(); - b = BN_new(); - if (!p || !a || !b) ABORT; - - if (!BN_hex2bn(&p, "13")) ABORT; - if (!BN_hex2bn(&a, "3")) ABORT; - if (!BN_hex2bn(&b, "1")) ABORT; - - group = EC_GROUP_new(EC_GF2m_simple_method()); /* applications should use EC_GROUP_new_curve_GF2m - * so that the library gets to choose the EC_METHOD */ - if (!group) ABORT; - if (!EC_GROUP_set_curve_GF2m(group, p, a, b, ctx)) ABORT; - - { - EC_GROUP *tmp; - tmp = EC_GROUP_new(EC_GROUP_method_of(group)); - if (!tmp) ABORT; - if (!EC_GROUP_copy(tmp, group)) ABORT; - EC_GROUP_free(group); - group = tmp; - } - - if (!EC_GROUP_get_curve_GF2m(group, p, a, b, ctx)) ABORT; - - fprintf(stdout, "Curve defined by Weierstrass equation\n y^2 + x*y = x^3 + a*x^2 + b (mod 0x"); - BN_print_fp(stdout, p); - fprintf(stdout, ")\n a = 0x"); - BN_print_fp(stdout, a); - fprintf(stdout, "\n b = 0x"); - BN_print_fp(stdout, b); - fprintf(stdout, "\n(0x... means binary polynomial)\n"); - - P = EC_POINT_new(group); - Q = EC_POINT_new(group); - R = EC_POINT_new(group); - if (!P || !Q || !R) ABORT; - - if (!EC_POINT_set_to_infinity(group, P)) ABORT; - if (!EC_POINT_is_at_infinity(group, P)) ABORT; - - buf[0] = 0; - if (!EC_POINT_oct2point(group, Q, buf, 1, ctx)) ABORT; - - if (!EC_POINT_add(group, P, P, Q, ctx)) ABORT; - if (!EC_POINT_is_at_infinity(group, P)) ABORT; - - x = BN_new(); - y = BN_new(); - z = BN_new(); - cof = BN_new(); - if (!x || !y || !z || !cof) ABORT; - - if (!BN_hex2bn(&x, "6")) ABORT; -/* Change test based on whether binary point compression is enabled or not. */ -#ifdef OPENSSL_EC_BIN_PT_COMP - if (!EC_POINT_set_compressed_coordinates_GF2m(group, Q, x, 1, ctx)) ABORT; -#else - if (!BN_hex2bn(&y, "8")) ABORT; - if (!EC_POINT_set_affine_coordinates_GF2m(group, Q, x, y, ctx)) ABORT; -#endif - if (!EC_POINT_is_on_curve(group, Q, ctx)) - { -/* Change test based on whether binary point compression is enabled or not. */ -#ifdef OPENSSL_EC_BIN_PT_COMP - if (!EC_POINT_get_affine_coordinates_GF2m(group, Q, x, y, ctx)) ABORT; -#endif - fprintf(stderr, "Point is not on curve: x = 0x"); - BN_print_fp(stderr, x); - fprintf(stderr, ", y = 0x"); - BN_print_fp(stderr, y); - fprintf(stderr, "\n"); - ABORT; - } - - fprintf(stdout, "A cyclic subgroup:\n"); - k = 100; - do - { - if (k-- == 0) ABORT; - - if (EC_POINT_is_at_infinity(group, P)) - fprintf(stdout, " point at infinity\n"); - else - { - if (!EC_POINT_get_affine_coordinates_GF2m(group, P, x, y, ctx)) ABORT; - - fprintf(stdout, " x = 0x"); - BN_print_fp(stdout, x); - fprintf(stdout, ", y = 0x"); - BN_print_fp(stdout, y); - fprintf(stdout, "\n"); - } - - if (!EC_POINT_copy(R, P)) ABORT; - if (!EC_POINT_add(group, P, P, Q, ctx)) ABORT; - } - while (!EC_POINT_is_at_infinity(group, P)); - - if (!EC_POINT_add(group, P, Q, R, ctx)) ABORT; - if (!EC_POINT_is_at_infinity(group, P)) ABORT; - -/* Change test based on whether binary point compression is enabled or not. */ -#ifdef OPENSSL_EC_BIN_PT_COMP - len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_COMPRESSED, buf, sizeof buf, ctx); - if (len == 0) ABORT; - if (!EC_POINT_oct2point(group, P, buf, len, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, P, Q, ctx)) ABORT; - fprintf(stdout, "Generator as octet string, compressed form:\n "); - for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]); -#endif - - len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_UNCOMPRESSED, buf, sizeof buf, ctx); - if (len == 0) ABORT; - if (!EC_POINT_oct2point(group, P, buf, len, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, P, Q, ctx)) ABORT; - fprintf(stdout, "\nGenerator as octet string, uncompressed form:\n "); - for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]); - -/* Change test based on whether binary point compression is enabled or not. */ -#ifdef OPENSSL_EC_BIN_PT_COMP - len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_HYBRID, buf, sizeof buf, ctx); - if (len == 0) ABORT; - if (!EC_POINT_oct2point(group, P, buf, len, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, P, Q, ctx)) ABORT; - fprintf(stdout, "\nGenerator as octet string, hybrid form:\n "); - for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]); -#endif - - fprintf(stdout, "\n"); - - if (!EC_POINT_invert(group, P, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, P, R, ctx)) ABORT; - - - /* Curve K-163 (FIPS PUB 186-2, App. 6) */ - CHAR2_CURVE_TEST - ( - "NIST curve K-163", - "0800000000000000000000000000000000000000C9", - "1", - "1", - "02FE13C0537BBC11ACAA07D793DE4E6D5E5C94EEE8", - "0289070FB05D38FF58321F2E800536D538CCDAA3D9", - 1, - "04000000000000000000020108A2E0CC0D99F8A5EF", - "2", - 163, - C2_K163 - ); - - /* Curve B-163 (FIPS PUB 186-2, App. 6) */ - CHAR2_CURVE_TEST - ( - "NIST curve B-163", - "0800000000000000000000000000000000000000C9", - "1", - "020A601907B8C953CA1481EB10512F78744A3205FD", - "03F0EBA16286A2D57EA0991168D4994637E8343E36", - "00D51FBC6C71A0094FA2CDD545B11C5C0C797324F1", - 1, - "040000000000000000000292FE77E70C12A4234C33", - "2", - 163, - C2_B163 - ); - - /* Curve K-233 (FIPS PUB 186-2, App. 6) */ - CHAR2_CURVE_TEST - ( - "NIST curve K-233", - "020000000000000000000000000000000000000004000000000000000001", - "0", - "1", - "017232BA853A7E731AF129F22FF4149563A419C26BF50A4C9D6EEFAD6126", - "01DB537DECE819B7F70F555A67C427A8CD9BF18AEB9B56E0C11056FAE6A3", - 0, - "008000000000000000000000000000069D5BB915BCD46EFB1AD5F173ABDF", - "4", - 233, - C2_K233 - ); - - /* Curve B-233 (FIPS PUB 186-2, App. 6) */ - CHAR2_CURVE_TEST - ( - "NIST curve B-233", - "020000000000000000000000000000000000000004000000000000000001", - "000000000000000000000000000000000000000000000000000000000001", - "0066647EDE6C332C7F8C0923BB58213B333B20E9CE4281FE115F7D8F90AD", - "00FAC9DFCBAC8313BB2139F1BB755FEF65BC391F8B36F8F8EB7371FD558B", - "01006A08A41903350678E58528BEBF8A0BEFF867A7CA36716F7E01F81052", - 1, - "01000000000000000000000000000013E974E72F8A6922031D2603CFE0D7", - "2", - 233, - C2_B233 - ); - - /* Curve K-283 (FIPS PUB 186-2, App. 6) */ - CHAR2_CURVE_TEST - ( - "NIST curve K-283", - "0800000000000000000000000000000000000000000000000000000000000000000010A1", - "0", - "1", - "0503213F78CA44883F1A3B8162F188E553CD265F23C1567A16876913B0C2AC2458492836", - "01CCDA380F1C9E318D90F95D07E5426FE87E45C0E8184698E45962364E34116177DD2259", - 0, - "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE9AE2ED07577265DFF7F94451E061E163C61", - "4", - 283, - C2_K283 - ); - - /* Curve B-283 (FIPS PUB 186-2, App. 6) */ - CHAR2_CURVE_TEST - ( - "NIST curve B-283", - "0800000000000000000000000000000000000000000000000000000000000000000010A1", - "000000000000000000000000000000000000000000000000000000000000000000000001", - "027B680AC8B8596DA5A4AF8A19A0303FCA97FD7645309FA2A581485AF6263E313B79A2F5", - "05F939258DB7DD90E1934F8C70B0DFEC2EED25B8557EAC9C80E2E198F8CDBECD86B12053", - "03676854FE24141CB98FE6D4B20D02B4516FF702350EDDB0826779C813F0DF45BE8112F4", - 1, - "03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEF90399660FC938A90165B042A7CEFADB307", - "2", - 283, - C2_B283 - ); - - /* Curve K-409 (FIPS PUB 186-2, App. 6) */ - CHAR2_CURVE_TEST - ( - "NIST curve K-409", - "02000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001", - "0", - "1", - "0060F05F658F49C1AD3AB1890F7184210EFD0987E307C84C27ACCFB8F9F67CC2C460189EB5AAAA62EE222EB1B35540CFE9023746", - "01E369050B7C4E42ACBA1DACBF04299C3460782F918EA427E6325165E9EA10E3DA5F6C42E9C55215AA9CA27A5863EC48D8E0286B", - 1, - "007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE5F83B2D4EA20400EC4557D5ED3E3E7CA5B4B5C83B8E01E5FCF", - "4", - 409, - C2_K409 - ); - - /* Curve B-409 (FIPS PUB 186-2, App. 6) */ - CHAR2_CURVE_TEST - ( - "NIST curve B-409", - "02000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001", - "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", - "0021A5C2C8EE9FEB5C4B9A753B7B476B7FD6422EF1F3DD674761FA99D6AC27C8A9A197B272822F6CD57A55AA4F50AE317B13545F", - "015D4860D088DDB3496B0C6064756260441CDE4AF1771D4DB01FFE5B34E59703DC255A868A1180515603AEAB60794E54BB7996A7", - "0061B1CFAB6BE5F32BBFA78324ED106A7636B9C5A7BD198D0158AA4F5488D08F38514F1FDF4B4F40D2181B3681C364BA0273C706", - 1, - "010000000000000000000000000000000000000000000000000001E2AAD6A612F33307BE5FA47C3C9E052F838164CD37D9A21173", - "2", - 409, - C2_B409 - ); - - /* Curve K-571 (FIPS PUB 186-2, App. 6) */ - CHAR2_CURVE_TEST - ( - "NIST curve K-571", - "80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425", - "0", - "1", - "026EB7A859923FBC82189631F8103FE4AC9CA2970012D5D46024804801841CA44370958493B205E647DA304DB4CEB08CBBD1BA39494776FB988B47174DCA88C7E2945283A01C8972", - "0349DC807F4FBF374F4AEADE3BCA95314DD58CEC9F307A54FFC61EFC006D8A2C9D4979C0AC44AEA74FBEBBB9F772AEDCB620B01A7BA7AF1B320430C8591984F601CD4C143EF1C7A3", - 0, - "020000000000000000000000000000000000000000000000000000000000000000000000131850E1F19A63E4B391A8DB917F4138B630D84BE5D639381E91DEB45CFE778F637C1001", - "4", - 571, - C2_K571 - ); - - /* Curve B-571 (FIPS PUB 186-2, App. 6) */ - CHAR2_CURVE_TEST - ( - "NIST curve B-571", - "80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425", - "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", - "02F40E7E2221F295DE297117B7F3D62F5C6A97FFCB8CEFF1CD6BA8CE4A9A18AD84FFABBD8EFA59332BE7AD6756A66E294AFD185A78FF12AA520E4DE739BACA0C7FFEFF7F2955727A", - "0303001D34B856296C16C0D40D3CD7750A93D1D2955FA80AA5F40FC8DB7B2ABDBDE53950F4C0D293CDD711A35B67FB1499AE60038614F1394ABFA3B4C850D927E1E7769C8EEC2D19", - "037BF27342DA639B6DCCFFFEB73D69D78C6C27A6009CBBCA1980F8533921E8A684423E43BAB08A576291AF8F461BB2A8B3531D2F0485C19B16E2F1516E23DD3C1A4827AF1B8AC15B", - 1, - "03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE661CE18FF55987308059B186823851EC7DD9CA1161DE93D5174D66E8382E9BB2FE84E47", - "2", - 571, - C2_B571 - ); - - /* more tests using the last curve */ - - if (!EC_POINT_copy(Q, P)) ABORT; - if (EC_POINT_is_at_infinity(group, Q)) ABORT; - if (!EC_POINT_dbl(group, P, P, ctx)) ABORT; - if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT; - if (!EC_POINT_invert(group, Q, ctx)) ABORT; /* P = -2Q */ - - if (!EC_POINT_add(group, R, P, Q, ctx)) ABORT; - if (!EC_POINT_add(group, R, R, Q, ctx)) ABORT; - if (!EC_POINT_is_at_infinity(group, R)) ABORT; /* R = P + 2Q */ - - { - const EC_POINT *points[3]; - const BIGNUM *scalars[3]; - - if (EC_POINT_is_at_infinity(group, Q)) ABORT; - points[0] = Q; - points[1] = Q; - points[2] = Q; - - if (!BN_add(y, z, BN_value_one())) ABORT; - if (BN_is_odd(y)) ABORT; - if (!BN_rshift1(y, y)) ABORT; - scalars[0] = y; /* (group order + 1)/2, so y*Q + y*Q = Q */ - scalars[1] = y; - - fprintf(stdout, "combined multiplication ..."); - fflush(stdout); - - /* z is still the group order */ - if (!EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx)) ABORT; - if (!EC_POINTs_mul(group, R, z, 2, points, scalars, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, P, R, ctx)) ABORT; - if (0 != EC_POINT_cmp(group, R, Q, ctx)) ABORT; - - fprintf(stdout, "."); - fflush(stdout); - - if (!BN_pseudo_rand(y, BN_num_bits(y), 0, 0)) ABORT; - if (!BN_add(z, z, y)) ABORT; - BN_set_negative(z, 1); - scalars[0] = y; - scalars[1] = z; /* z = -(order + y) */ - - if (!EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx)) ABORT; - if (!EC_POINT_is_at_infinity(group, P)) ABORT; - - fprintf(stdout, "."); - fflush(stdout); - - if (!BN_pseudo_rand(x, BN_num_bits(y) - 1, 0, 0)) ABORT; - if (!BN_add(z, x, y)) ABORT; - BN_set_negative(z, 1); - scalars[0] = x; - scalars[1] = y; - scalars[2] = z; /* z = -(x+y) */ - - if (!EC_POINTs_mul(group, P, NULL, 3, points, scalars, ctx)) ABORT; - if (!EC_POINT_is_at_infinity(group, P)) ABORT; - - fprintf(stdout, " ok\n\n"); - } - - -#if 0 - timings(C2_K163, TIMING_BASE_PT, ctx); - timings(C2_K163, TIMING_RAND_PT, ctx); - timings(C2_K163, TIMING_SIMUL, ctx); - timings(C2_B163, TIMING_BASE_PT, ctx); - timings(C2_B163, TIMING_RAND_PT, ctx); - timings(C2_B163, TIMING_SIMUL, ctx); - timings(C2_K233, TIMING_BASE_PT, ctx); - timings(C2_K233, TIMING_RAND_PT, ctx); - timings(C2_K233, TIMING_SIMUL, ctx); - timings(C2_B233, TIMING_BASE_PT, ctx); - timings(C2_B233, TIMING_RAND_PT, ctx); - timings(C2_B233, TIMING_SIMUL, ctx); - timings(C2_K283, TIMING_BASE_PT, ctx); - timings(C2_K283, TIMING_RAND_PT, ctx); - timings(C2_K283, TIMING_SIMUL, ctx); - timings(C2_B283, TIMING_BASE_PT, ctx); - timings(C2_B283, TIMING_RAND_PT, ctx); - timings(C2_B283, TIMING_SIMUL, ctx); - timings(C2_K409, TIMING_BASE_PT, ctx); - timings(C2_K409, TIMING_RAND_PT, ctx); - timings(C2_K409, TIMING_SIMUL, ctx); - timings(C2_B409, TIMING_BASE_PT, ctx); - timings(C2_B409, TIMING_RAND_PT, ctx); - timings(C2_B409, TIMING_SIMUL, ctx); - timings(C2_K571, TIMING_BASE_PT, ctx); - timings(C2_K571, TIMING_RAND_PT, ctx); - timings(C2_K571, TIMING_SIMUL, ctx); - timings(C2_B571, TIMING_BASE_PT, ctx); - timings(C2_B571, TIMING_RAND_PT, ctx); - timings(C2_B571, TIMING_SIMUL, ctx); -#endif - - - if (ctx) - BN_CTX_free(ctx); - BN_free(p); BN_free(a); BN_free(b); - EC_GROUP_free(group); - EC_POINT_free(P); - EC_POINT_free(Q); - EC_POINT_free(R); - BN_free(x); BN_free(y); BN_free(z); BN_free(cof); - - if (C2_K163) EC_GROUP_free(C2_K163); - if (C2_B163) EC_GROUP_free(C2_B163); - if (C2_K233) EC_GROUP_free(C2_K233); - if (C2_B233) EC_GROUP_free(C2_B233); - if (C2_K283) EC_GROUP_free(C2_K283); - if (C2_B283) EC_GROUP_free(C2_B283); - if (C2_K409) EC_GROUP_free(C2_K409); - if (C2_B409) EC_GROUP_free(C2_B409); - if (C2_K571) EC_GROUP_free(C2_K571); - if (C2_B571) EC_GROUP_free(C2_B571); - - } -#endif - -static void internal_curve_test(void) - { - EC_builtin_curve *curves = NULL; - size_t crv_len = 0, n = 0; - int ok = 1; - - crv_len = EC_get_builtin_curves(NULL, 0); - - curves = OPENSSL_malloc(sizeof(EC_builtin_curve) * crv_len); - - if (curves == NULL) - return; - - if (!EC_get_builtin_curves(curves, crv_len)) - { - OPENSSL_free(curves); - return; - } - - fprintf(stdout, "testing internal curves: "); - - for (n = 0; n < crv_len; n++) - { - EC_GROUP *group = NULL; - int nid = curves[n].nid; - if ((group = EC_GROUP_new_by_curve_name(nid)) == NULL) - { - ok = 0; - fprintf(stdout, "\nEC_GROUP_new_curve_name() failed with" - " curve %s\n", OBJ_nid2sn(nid)); - /* try next curve */ - continue; - } - if (!EC_GROUP_check(group, NULL)) - { - ok = 0; - fprintf(stdout, "\nEC_GROUP_check() failed with" - " curve %s\n", OBJ_nid2sn(nid)); - EC_GROUP_free(group); - /* try the next curve */ - continue; - } - fprintf(stdout, "."); - fflush(stdout); - EC_GROUP_free(group); - } - if (ok) - fprintf(stdout, " ok\n\n"); - else - { - fprintf(stdout, " failed\n\n"); - ABORT; - } - OPENSSL_free(curves); - return; - } - -#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 -/* nistp_test_params contains magic numbers for testing our optimized - * implementations of several NIST curves with characteristic > 3. */ -struct nistp_test_params - { - const EC_METHOD* (*meth) (); - int degree; - /* Qx, Qy and D are taken from - * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/ECDSA_Prime.pdf - * Otherwise, values are standard curve parameters from FIPS 180-3 */ - const char *p, *a, *b, *Qx, *Qy, *Gx, *Gy, *order, *d; - }; - -static const struct nistp_test_params nistp_tests_params[] = - { - { - /* P-224 */ - EC_GFp_nistp224_method, - 224, - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001", /* p */ - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE", /* a */ - "B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4", /* b */ - "E84FB0B8E7000CB657D7973CF6B42ED78B301674276DF744AF130B3E", /* Qx */ - "4376675C6FC5612C21A0FF2D2A89D2987DF7A2BC52183B5982298555", /* Qy */ - "B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21", /* Gx */ - "BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34", /* Gy */ - "FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D", /* order */ - "3F0C488E987C80BE0FEE521F8D90BE6034EC69AE11CA72AA777481E8", /* d */ - }, - { - /* P-256 */ - EC_GFp_nistp256_method, - 256, - "ffffffff00000001000000000000000000000000ffffffffffffffffffffffff", /* p */ - "ffffffff00000001000000000000000000000000fffffffffffffffffffffffc", /* a */ - "5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b", /* b */ - "b7e08afdfe94bad3f1dc8c734798ba1c62b3a0ad1e9ea2a38201cd0889bc7a19", /* Qx */ - "3603f747959dbf7a4bb226e41928729063adc7ae43529e61b563bbc606cc5e09", /* Qy */ - "6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296", /* Gx */ - "4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5", /* Gy */ - "ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551", /* order */ - "c477f9f65c22cce20657faa5b2d1d8122336f851a508a1ed04e479c34985bf96", /* d */ - }, - { - /* P-521 */ - EC_GFp_nistp521_method, - 521, - "1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", /* p */ - "1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc", /* a */ - "051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00", /* b */ - "0098e91eef9a68452822309c52fab453f5f117c1da8ed796b255e9ab8f6410cca16e59df403a6bdc6ca467a37056b1e54b3005d8ac030decfeb68df18b171885d5c4", /* Qx */ - "0164350c321aecfc1cca1ba4364c9b15656150b4b78d6a48d7d28e7f31985ef17be8554376b72900712c4b83ad668327231526e313f5f092999a4632fd50d946bc2e", /* Qy */ - "c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66", /* Gx */ - "11839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650", /* Gy */ - "1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409", /* order */ - "0100085f47b8e1b8b11b7eb33028c0b2888e304bfc98501955b45bba1478dc184eeedf09b86a5f7c21994406072787205e69a63709fe35aa93ba333514b24f961722", /* d */ - }, - }; - -void nistp_single_test(const struct nistp_test_params *test) - { - BN_CTX *ctx; - BIGNUM *p, *a, *b, *x, *y, *n, *m, *order; - EC_GROUP *NISTP; - EC_POINT *G, *P, *Q, *Q_CHECK; - - fprintf(stdout, "\nNIST curve P-%d (optimised implementation):\n", test->degree); - ctx = BN_CTX_new(); - p = BN_new(); - a = BN_new(); - b = BN_new(); - x = BN_new(); y = BN_new(); - m = BN_new(); n = BN_new(); order = BN_new(); - - NISTP = EC_GROUP_new(test->meth()); - if(!NISTP) ABORT; - if (!BN_hex2bn(&p, test->p)) ABORT; - if (1 != BN_is_prime_ex(p, BN_prime_checks, ctx, NULL)) ABORT; - if (!BN_hex2bn(&a, test->a)) ABORT; - if (!BN_hex2bn(&b, test->b)) ABORT; - if (!EC_GROUP_set_curve_GFp(NISTP, p, a, b, ctx)) ABORT; - G = EC_POINT_new(NISTP); - P = EC_POINT_new(NISTP); - Q = EC_POINT_new(NISTP); - Q_CHECK = EC_POINT_new(NISTP); - if(!BN_hex2bn(&x, test->Qx)) ABORT; - if(!BN_hex2bn(&y, test->Qy)) ABORT; - if(!EC_POINT_set_affine_coordinates_GFp(NISTP, Q_CHECK, x, y, ctx)) ABORT; - if (!BN_hex2bn(&x, test->Gx)) ABORT; - if (!BN_hex2bn(&y, test->Gy)) ABORT; - if (!EC_POINT_set_affine_coordinates_GFp(NISTP, G, x, y, ctx)) ABORT; - if (!BN_hex2bn(&order, test->order)) ABORT; - if (!EC_GROUP_set_generator(NISTP, G, order, BN_value_one())) ABORT; - - fprintf(stdout, "verify degree ... "); - if (EC_GROUP_get_degree(NISTP) != test->degree) ABORT; - fprintf(stdout, "ok\n"); - - fprintf(stdout, "NIST test vectors ... "); - if (!BN_hex2bn(&n, test->d)) ABORT; - /* fixed point multiplication */ - EC_POINT_mul(NISTP, Q, n, NULL, NULL, ctx); - if (0 != EC_POINT_cmp(NISTP, Q, Q_CHECK, ctx)) ABORT; - /* random point multiplication */ - EC_POINT_mul(NISTP, Q, NULL, G, n, ctx); - if (0 != EC_POINT_cmp(NISTP, Q, Q_CHECK, ctx)) ABORT; - - /* set generator to P = 2*G, where G is the standard generator */ - if (!EC_POINT_dbl(NISTP, P, G, ctx)) ABORT; - if (!EC_GROUP_set_generator(NISTP, P, order, BN_value_one())) ABORT; - /* set the scalar to m=n/2, where n is the NIST test scalar */ - if (!BN_rshift(m, n, 1)) ABORT; - - /* test the non-standard generator */ - /* fixed point multiplication */ - EC_POINT_mul(NISTP, Q, m, NULL, NULL, ctx); - if (0 != EC_POINT_cmp(NISTP, Q, Q_CHECK, ctx)) ABORT; - /* random point multiplication */ - EC_POINT_mul(NISTP, Q, NULL, P, m, ctx); - if (0 != EC_POINT_cmp(NISTP, Q, Q_CHECK, ctx)) ABORT; - - /* now repeat all tests with precomputation */ - if (!EC_GROUP_precompute_mult(NISTP, ctx)) ABORT; - - /* fixed point multiplication */ - EC_POINT_mul(NISTP, Q, m, NULL, NULL, ctx); - if (0 != EC_POINT_cmp(NISTP, Q, Q_CHECK, ctx)) ABORT; - /* random point multiplication */ - EC_POINT_mul(NISTP, Q, NULL, P, m, ctx); - if (0 != EC_POINT_cmp(NISTP, Q, Q_CHECK, ctx)) ABORT; - - /* reset generator */ - if (!EC_GROUP_set_generator(NISTP, G, order, BN_value_one())) ABORT; - /* fixed point multiplication */ - EC_POINT_mul(NISTP, Q, n, NULL, NULL, ctx); - if (0 != EC_POINT_cmp(NISTP, Q, Q_CHECK, ctx)) ABORT; - /* random point multiplication */ - EC_POINT_mul(NISTP, Q, NULL, G, n, ctx); - if (0 != EC_POINT_cmp(NISTP, Q, Q_CHECK, ctx)) ABORT; - - fprintf(stdout, "ok\n"); - group_order_tests(NISTP); -#if 0 - timings(NISTP, TIMING_BASE_PT, ctx); - timings(NISTP, TIMING_RAND_PT, ctx); -#endif - EC_GROUP_free(NISTP); - EC_POINT_free(G); - EC_POINT_free(P); - EC_POINT_free(Q); - EC_POINT_free(Q_CHECK); - BN_free(n); - BN_free(m); - BN_free(p); - BN_free(a); - BN_free(b); - BN_free(x); - BN_free(y); - BN_free(order); - BN_CTX_free(ctx); - } - -void nistp_tests() - { - unsigned i; - - for (i = 0; i < sizeof(nistp_tests_params) / sizeof(struct nistp_test_params); i++) - { - nistp_single_test(&nistp_tests_params[i]); - } - } -#endif - -static const char rnd_seed[] = "string to make the random number generator think it has entropy"; - -int main(int argc, char *argv[]) - { - - /* enable memory leak checking unless explicitly disabled */ - if (!((getenv("OPENSSL_DEBUG_MEMORY") != NULL) && (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off")))) - { - CRYPTO_malloc_debug_init(); - CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL); - } - else - { - /* OPENSSL_DEBUG_MEMORY=off */ - CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0); - } - CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); - ERR_load_crypto_strings(); - - RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_generate_prime may fail */ - - prime_field_tests(); - puts(""); -#ifndef OPENSSL_NO_EC2M - char2_field_tests(); -#endif -#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 - nistp_tests(); -#endif - /* test the internal curves */ - internal_curve_test(); - -#ifndef OPENSSL_NO_ENGINE - ENGINE_cleanup(); -#endif - CRYPTO_cleanup_all_ex_data(); - ERR_free_strings(); - ERR_remove_thread_state(NULL); - CRYPTO_mem_leaks_fp(stderr); - - return 0; - } -#endif diff --git a/src/lib/libssl/src/crypto/ecdh/ecdhtest.c b/src/lib/libssl/src/crypto/ecdh/ecdhtest.c deleted file mode 100644 index 823d7baa65..0000000000 --- a/src/lib/libssl/src/crypto/ecdh/ecdhtest.c +++ /dev/null @@ -1,374 +0,0 @@ -/* crypto/ecdh/ecdhtest.c */ -/* ==================================================================== - * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. - * - * The Elliptic Curve Public-Key Crypto Library (ECC Code) included - * herein is developed by SUN MICROSYSTEMS, INC., and is contributed - * to the OpenSSL project. - * - * The ECC Code is licensed pursuant to the OpenSSL open source - * license provided below. - * - * The ECDH software is originally written by Douglas Stebila of - * Sun Microsystems Laboratories. - * - */ -/* ==================================================================== - * Copyright (c) 1998-2003 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). - * - */ - -#include -#include -#include - -#include "../e_os.h" - -#include /* for OPENSSL_NO_ECDH */ -#include -#include -#include -#include -#include -#include -#include - -#ifdef OPENSSL_NO_ECDH -int main(int argc, char *argv[]) -{ - printf("No ECDH support\n"); - return(0); -} -#else -#include -#include - -#ifdef OPENSSL_SYS_WIN16 -#define MS_CALLBACK _far _loadds -#else -#define MS_CALLBACK -#endif - -#if 0 -static void MS_CALLBACK cb(int p, int n, void *arg); -#endif - -static const char rnd_seed[] = "string to make the random number generator think it has entropy"; - - -static const int KDF1_SHA1_len = 20; -static void *KDF1_SHA1(const void *in, size_t inlen, void *out, size_t *outlen) - { -#ifndef OPENSSL_NO_SHA - if (*outlen < SHA_DIGEST_LENGTH) - return NULL; - else - *outlen = SHA_DIGEST_LENGTH; - return SHA1(in, inlen, out); -#else - return NULL; -#endif - } - - -static int test_ecdh_curve(int nid, const char *text, BN_CTX *ctx, BIO *out) - { - EC_KEY *a=NULL; - EC_KEY *b=NULL; - BIGNUM *x_a=NULL, *y_a=NULL, - *x_b=NULL, *y_b=NULL; - char buf[12]; - unsigned char *abuf=NULL,*bbuf=NULL; - int i,alen,blen,aout,bout,ret=0; - const EC_GROUP *group; - - a = EC_KEY_new_by_curve_name(nid); - b = EC_KEY_new_by_curve_name(nid); - if (a == NULL || b == NULL) - goto err; - - group = EC_KEY_get0_group(a); - - if ((x_a=BN_new()) == NULL) goto err; - if ((y_a=BN_new()) == NULL) goto err; - if ((x_b=BN_new()) == NULL) goto err; - if ((y_b=BN_new()) == NULL) goto err; - - BIO_puts(out,"Testing key generation with "); - BIO_puts(out,text); -#ifdef NOISY - BIO_puts(out,"\n"); -#else - (void)BIO_flush(out); -#endif - - if (!EC_KEY_generate_key(a)) goto err; - - if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_prime_field) - { - if (!EC_POINT_get_affine_coordinates_GFp(group, - EC_KEY_get0_public_key(a), x_a, y_a, ctx)) goto err; - } -#ifndef OPENSSL_NO_EC2M - else - { - if (!EC_POINT_get_affine_coordinates_GF2m(group, - EC_KEY_get0_public_key(a), x_a, y_a, ctx)) goto err; - } -#endif -#ifdef NOISY - BIO_puts(out," pri 1="); - BN_print(out,a->priv_key); - BIO_puts(out,"\n pub 1="); - BN_print(out,x_a); - BIO_puts(out,","); - BN_print(out,y_a); - BIO_puts(out,"\n"); -#else - BIO_printf(out," ."); - (void)BIO_flush(out); -#endif - - if (!EC_KEY_generate_key(b)) goto err; - - if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_prime_field) - { - if (!EC_POINT_get_affine_coordinates_GFp(group, - EC_KEY_get0_public_key(b), x_b, y_b, ctx)) goto err; - } -#ifndef OPENSSL_NO_EC2M - else - { - if (!EC_POINT_get_affine_coordinates_GF2m(group, - EC_KEY_get0_public_key(b), x_b, y_b, ctx)) goto err; - } -#endif - -#ifdef NOISY - BIO_puts(out," pri 2="); - BN_print(out,b->priv_key); - BIO_puts(out,"\n pub 2="); - BN_print(out,x_b); - BIO_puts(out,","); - BN_print(out,y_b); - BIO_puts(out,"\n"); -#else - BIO_printf(out,"."); - (void)BIO_flush(out); -#endif - - alen=KDF1_SHA1_len; - abuf=(unsigned char *)OPENSSL_malloc(alen); - aout=ECDH_compute_key(abuf,alen,EC_KEY_get0_public_key(b),a,KDF1_SHA1); - -#ifdef NOISY - BIO_puts(out," key1 ="); - for (i=0; i -#include -#include - -#include /* To see if OPENSSL_NO_ECDSA is defined */ - -#ifdef OPENSSL_NO_ECDSA -int main(int argc, char * argv[]) - { - puts("Elliptic curves are disabled."); - return 0; - } -#else - -#include -#include -#include -#include -#include -#ifndef OPENSSL_NO_ENGINE -#include -#endif -#include -#include - -static const char rnd_seed[] = "string to make the random number generator " - "think it has entropy"; - -/* declaration of the test functions */ -int x9_62_tests(BIO *); -int x9_62_test_internal(BIO *out, int nid, const char *r, const char *s); -int test_builtin(BIO *); - -/* functions to change the RAND_METHOD */ -int change_rand(void); -int restore_rand(void); -int fbytes(unsigned char *buf, int num); - -RAND_METHOD fake_rand; -const RAND_METHOD *old_rand; - -int change_rand(void) - { - /* save old rand method */ - if ((old_rand = RAND_get_rand_method()) == NULL) - return 0; - - fake_rand.seed = old_rand->seed; - fake_rand.cleanup = old_rand->cleanup; - fake_rand.add = old_rand->add; - fake_rand.status = old_rand->status; - /* use own random function */ - fake_rand.bytes = fbytes; - fake_rand.pseudorand = old_rand->bytes; - /* set new RAND_METHOD */ - if (!RAND_set_rand_method(&fake_rand)) - return 0; - return 1; - } - -int restore_rand(void) - { - if (!RAND_set_rand_method(old_rand)) - return 0; - else - return 1; - } - -static int fbytes_counter = 0; -static const char *numbers[8] = { - "651056770906015076056810763456358567190100156695615665659", - "6140507067065001063065065565667405560006161556565665656654", - "8763001015071075675010661307616710783570106710677817767166" - "71676178726717", - "7000000175690566466555057817571571075705015757757057795755" - "55657156756655", - "1275552191113212300012030439187146164646146646466749494799", - "1542725565216523985789236956265265265235675811949404040041", - "1456427555219115346513212300075341203043918714616464614664" - "64667494947990", - "1712787255652165239672857892369562652652652356758119494040" - "40041670216363"}; - -int fbytes(unsigned char *buf, int num) - { - int ret; - BIGNUM *tmp = NULL; - - if (fbytes_counter >= 8) - return 0; - tmp = BN_new(); - if (!tmp) - return 0; - if (!BN_dec2bn(&tmp, numbers[fbytes_counter])) - { - BN_free(tmp); - return 0; - } - fbytes_counter ++; - if (num != BN_num_bytes(tmp) || !BN_bn2bin(tmp, buf)) - ret = 0; - else - ret = 1; - if (tmp) - BN_free(tmp); - return ret; - } - -/* some tests from the X9.62 draft */ -int x9_62_test_internal(BIO *out, int nid, const char *r_in, const char *s_in) - { - int ret = 0; - const char message[] = "abc"; - unsigned char digest[20]; - unsigned int dgst_len = 0; - EVP_MD_CTX md_ctx; - EC_KEY *key = NULL; - ECDSA_SIG *signature = NULL; - BIGNUM *r = NULL, *s = NULL; - - EVP_MD_CTX_init(&md_ctx); - /* get the message digest */ - EVP_DigestInit(&md_ctx, EVP_ecdsa()); - EVP_DigestUpdate(&md_ctx, (const void*)message, 3); - EVP_DigestFinal(&md_ctx, digest, &dgst_len); - - BIO_printf(out, "testing %s: ", OBJ_nid2sn(nid)); - /* create the key */ - if ((key = EC_KEY_new_by_curve_name(nid)) == NULL) - goto x962_int_err; - if (!EC_KEY_generate_key(key)) - goto x962_int_err; - BIO_printf(out, "."); - (void)BIO_flush(out); - /* create the signature */ - signature = ECDSA_do_sign(digest, 20, key); - if (signature == NULL) - goto x962_int_err; - BIO_printf(out, "."); - (void)BIO_flush(out); - /* compare the created signature with the expected signature */ - if ((r = BN_new()) == NULL || (s = BN_new()) == NULL) - goto x962_int_err; - if (!BN_dec2bn(&r, r_in) || - !BN_dec2bn(&s, s_in)) - goto x962_int_err; - if (BN_cmp(signature->r ,r) || BN_cmp(signature->s, s)) - goto x962_int_err; - BIO_printf(out, "."); - (void)BIO_flush(out); - /* verify the signature */ - if (ECDSA_do_verify(digest, 20, signature, key) != 1) - goto x962_int_err; - BIO_printf(out, "."); - (void)BIO_flush(out); - - BIO_printf(out, " ok\n"); - ret = 1; -x962_int_err: - if (!ret) - BIO_printf(out, " failed\n"); - if (key) - EC_KEY_free(key); - if (signature) - ECDSA_SIG_free(signature); - if (r) - BN_free(r); - if (s) - BN_free(s); - EVP_MD_CTX_cleanup(&md_ctx); - return ret; - } - -int x9_62_tests(BIO *out) - { - int ret = 0; - - BIO_printf(out, "some tests from X9.62:\n"); - - /* set own rand method */ - if (!change_rand()) - goto x962_err; - - if (!x9_62_test_internal(out, NID_X9_62_prime192v1, - "3342403536405981729393488334694600415596881826869351677613", - "5735822328888155254683894997897571951568553642892029982342")) - goto x962_err; - if (!x9_62_test_internal(out, NID_X9_62_prime239v1, - "3086361431751678114926225473006680188549593787585317781474" - "62058306432176", - "3238135532097973577080787768312505059318910517550078427819" - "78505179448783")) - goto x962_err; -#ifndef OPENSSL_NO_EC2M - if (!x9_62_test_internal(out, NID_X9_62_c2tnb191v1, - "87194383164871543355722284926904419997237591535066528048", - "308992691965804947361541664549085895292153777025772063598")) - goto x962_err; - if (!x9_62_test_internal(out, NID_X9_62_c2tnb239v1, - "2159633321041961198501834003903461262881815148684178964245" - "5876922391552", - "1970303740007316867383349976549972270528498040721988191026" - "49413465737174")) - goto x962_err; -#endif - ret = 1; -x962_err: - if (!restore_rand()) - ret = 0; - return ret; - } - -int test_builtin(BIO *out) - { - EC_builtin_curve *curves = NULL; - size_t crv_len = 0, n = 0; - EC_KEY *eckey = NULL, *wrong_eckey = NULL; - EC_GROUP *group; - ECDSA_SIG *ecdsa_sig = NULL; - unsigned char digest[20], wrong_digest[20]; - unsigned char *signature = NULL; - const unsigned char *sig_ptr; - unsigned char *sig_ptr2; - unsigned char *raw_buf = NULL; - unsigned int sig_len, degree, r_len, s_len, bn_len, buf_len; - int nid, ret = 0; - - /* fill digest values with some random data */ - if (!RAND_pseudo_bytes(digest, 20) || - !RAND_pseudo_bytes(wrong_digest, 20)) - { - BIO_printf(out, "ERROR: unable to get random data\n"); - goto builtin_err; - } - - /* create and verify a ecdsa signature with every availble curve - * (with ) */ - BIO_printf(out, "\ntesting ECDSA_sign() and ECDSA_verify() " - "with some internal curves:\n"); - - /* get a list of all internal curves */ - crv_len = EC_get_builtin_curves(NULL, 0); - - curves = OPENSSL_malloc(sizeof(EC_builtin_curve) * crv_len); - - if (curves == NULL) - { - BIO_printf(out, "malloc error\n"); - goto builtin_err; - } - - if (!EC_get_builtin_curves(curves, crv_len)) - { - BIO_printf(out, "unable to get internal curves\n"); - goto builtin_err; - } - - /* now create and verify a signature for every curve */ - for (n = 0; n < crv_len; n++) - { - unsigned char dirt, offset; - - nid = curves[n].nid; - if (nid == NID_ipsec4) - continue; - /* create new ecdsa key (== EC_KEY) */ - if ((eckey = EC_KEY_new()) == NULL) - goto builtin_err; - group = EC_GROUP_new_by_curve_name(nid); - if (group == NULL) - goto builtin_err; - if (EC_KEY_set_group(eckey, group) == 0) - goto builtin_err; - EC_GROUP_free(group); - degree = EC_GROUP_get_degree(EC_KEY_get0_group(eckey)); - if (degree < 160) - /* drop the curve */ - { - EC_KEY_free(eckey); - eckey = NULL; - continue; - } - BIO_printf(out, "%s: ", OBJ_nid2sn(nid)); - /* create key */ - if (!EC_KEY_generate_key(eckey)) - { - BIO_printf(out, " failed\n"); - goto builtin_err; - } - /* create second key */ - if ((wrong_eckey = EC_KEY_new()) == NULL) - goto builtin_err; - group = EC_GROUP_new_by_curve_name(nid); - if (group == NULL) - goto builtin_err; - if (EC_KEY_set_group(wrong_eckey, group) == 0) - goto builtin_err; - EC_GROUP_free(group); - if (!EC_KEY_generate_key(wrong_eckey)) - { - BIO_printf(out, " failed\n"); - goto builtin_err; - } - - BIO_printf(out, "."); - (void)BIO_flush(out); - /* check key */ - if (!EC_KEY_check_key(eckey)) - { - BIO_printf(out, " failed\n"); - goto builtin_err; - } - BIO_printf(out, "."); - (void)BIO_flush(out); - /* create signature */ - sig_len = ECDSA_size(eckey); - if ((signature = OPENSSL_malloc(sig_len)) == NULL) - goto builtin_err; - if (!ECDSA_sign(0, digest, 20, signature, &sig_len, eckey)) - { - BIO_printf(out, " failed\n"); - goto builtin_err; - } - BIO_printf(out, "."); - (void)BIO_flush(out); - /* verify signature */ - if (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) != 1) - { - BIO_printf(out, " failed\n"); - goto builtin_err; - } - BIO_printf(out, "."); - (void)BIO_flush(out); - /* verify signature with the wrong key */ - if (ECDSA_verify(0, digest, 20, signature, sig_len, - wrong_eckey) == 1) - { - BIO_printf(out, " failed\n"); - goto builtin_err; - } - BIO_printf(out, "."); - (void)BIO_flush(out); - /* wrong digest */ - if (ECDSA_verify(0, wrong_digest, 20, signature, sig_len, - eckey) == 1) - { - BIO_printf(out, " failed\n"); - goto builtin_err; - } - BIO_printf(out, "."); - (void)BIO_flush(out); - /* wrong length */ - if (ECDSA_verify(0, digest, 20, signature, sig_len - 1, - eckey) == 1) - { - BIO_printf(out, " failed\n"); - goto builtin_err; - } - BIO_printf(out, "."); - (void)BIO_flush(out); - - /* Modify a single byte of the signature: to ensure we don't - * garble the ASN1 structure, we read the raw signature and - * modify a byte in one of the bignums directly. */ - sig_ptr = signature; - if ((ecdsa_sig = d2i_ECDSA_SIG(NULL, &sig_ptr, sig_len)) == NULL) - { - BIO_printf(out, " failed\n"); - goto builtin_err; - } - - /* Store the two BIGNUMs in raw_buf. */ - r_len = BN_num_bytes(ecdsa_sig->r); - s_len = BN_num_bytes(ecdsa_sig->s); - bn_len = (degree + 7) / 8; - if ((r_len > bn_len) || (s_len > bn_len)) - { - BIO_printf(out, " failed\n"); - goto builtin_err; - } - buf_len = 2 * bn_len; - if ((raw_buf = OPENSSL_malloc(buf_len)) == NULL) - goto builtin_err; - /* Pad the bignums with leading zeroes. */ - memset(raw_buf, 0, buf_len); - BN_bn2bin(ecdsa_sig->r, raw_buf + bn_len - r_len); - BN_bn2bin(ecdsa_sig->s, raw_buf + buf_len - s_len); - - /* Modify a single byte in the buffer. */ - offset = raw_buf[10] % buf_len; - dirt = raw_buf[11] ? raw_buf[11] : 1; - raw_buf[offset] ^= dirt; - /* Now read the BIGNUMs back in from raw_buf. */ - if ((BN_bin2bn(raw_buf, bn_len, ecdsa_sig->r) == NULL) || - (BN_bin2bn(raw_buf + bn_len, bn_len, ecdsa_sig->s) == NULL)) - goto builtin_err; - - sig_ptr2 = signature; - sig_len = i2d_ECDSA_SIG(ecdsa_sig, &sig_ptr2); - if (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) == 1) - { - BIO_printf(out, " failed\n"); - goto builtin_err; - } - /* Sanity check: undo the modification and verify signature. */ - raw_buf[offset] ^= dirt; - if ((BN_bin2bn(raw_buf, bn_len, ecdsa_sig->r) == NULL) || - (BN_bin2bn(raw_buf + bn_len, bn_len, ecdsa_sig->s) == NULL)) - goto builtin_err; - - sig_ptr2 = signature; - sig_len = i2d_ECDSA_SIG(ecdsa_sig, &sig_ptr2); - if (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) != 1) - { - BIO_printf(out, " failed\n"); - goto builtin_err; - } - BIO_printf(out, "."); - (void)BIO_flush(out); - - BIO_printf(out, " ok\n"); - /* cleanup */ - /* clean bogus errors */ - ERR_clear_error(); - OPENSSL_free(signature); - signature = NULL; - EC_KEY_free(eckey); - eckey = NULL; - EC_KEY_free(wrong_eckey); - wrong_eckey = NULL; - ECDSA_SIG_free(ecdsa_sig); - ecdsa_sig = NULL; - OPENSSL_free(raw_buf); - raw_buf = NULL; - } - - ret = 1; -builtin_err: - if (eckey) - EC_KEY_free(eckey); - if (wrong_eckey) - EC_KEY_free(wrong_eckey); - if (ecdsa_sig) - ECDSA_SIG_free(ecdsa_sig); - if (signature) - OPENSSL_free(signature); - if (raw_buf) - OPENSSL_free(raw_buf); - if (curves) - OPENSSL_free(curves); - - return ret; - } - -int main(void) - { - int ret = 1; - BIO *out; - - out = BIO_new_fp(stdout, BIO_NOCLOSE); - - /* enable memory leak checking unless explicitly disabled */ - if (!((getenv("OPENSSL_DEBUG_MEMORY") != NULL) && - (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off")))) - { - CRYPTO_malloc_debug_init(); - CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL); - } - else - { - /* OPENSSL_DEBUG_MEMORY=off */ - CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0); - } - CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); - - ERR_load_crypto_strings(); - - /* initialize the prng */ - RAND_seed(rnd_seed, sizeof(rnd_seed)); - - /* the tests */ - if (!x9_62_tests(out)) goto err; - if (!test_builtin(out)) goto err; - - ret = 0; -err: - if (ret) - BIO_printf(out, "\nECDSA test failed\n"); - else - BIO_printf(out, "\nECDSA test passed\n"); - if (ret) - ERR_print_errors(out); - CRYPTO_cleanup_all_ex_data(); - ERR_remove_thread_state(NULL); - ERR_free_strings(); - CRYPTO_mem_leaks(out); - if (out != NULL) - BIO_free(out); - return ret; - } -#endif diff --git a/src/lib/libssl/src/crypto/evp/evp_test.c b/src/lib/libssl/src/crypto/evp/evp_test.c deleted file mode 100644 index 55c7cdfdcc..0000000000 --- a/src/lib/libssl/src/crypto/evp/evp_test.c +++ /dev/null @@ -1,450 +0,0 @@ -/* Written by Ben Laurie, 2001 */ -/* - * Copyright (c) 2001 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. - */ - -#include -#include - -#include "../e_os.h" - -#include -#include -#ifndef OPENSSL_NO_ENGINE -#include -#endif -#include -#include - -static void hexdump(FILE *f,const char *title,const unsigned char *s,int l) - { - int n=0; - - fprintf(f,"%s",title); - for( ; n < l ; ++n) - { - if((n%16) == 0) - fprintf(f,"\n%04x",n); - fprintf(f," %02x",s[n]); - } - fprintf(f,"\n"); - } - -static int convert(unsigned char *s) - { - unsigned char *d; - - for(d=s ; *s ; s+=2,++d) - { - unsigned int n; - - if(!s[1]) - { - fprintf(stderr,"Odd number of hex digits!"); - EXIT(4); - } - sscanf((char *)s,"%2x",&n); - *d=(unsigned char)n; - } - return s-d; - } - -static char *sstrsep(char **string, const char *delim) - { - char isdelim[256]; - char *token = *string; - - if (**string == 0) - return NULL; - - memset(isdelim, 0, 256); - isdelim[0] = 1; - - while (*delim) - { - isdelim[(unsigned char)(*delim)] = 1; - delim++; - } - - while (!isdelim[(unsigned char)(**string)]) - { - (*string)++; - } - - if (**string) - { - **string = 0; - (*string)++; - } - - return token; - } - -static unsigned char *ustrsep(char **p,const char *sep) - { return (unsigned char *)sstrsep(p,sep); } - -static int test1_exit(int ec) - { - EXIT(ec); - return(0); /* To keep some compilers quiet */ - } - -static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn, - const unsigned char *iv,int in, - const unsigned char *plaintext,int pn, - const unsigned char *ciphertext,int cn, - int encdec) - { - EVP_CIPHER_CTX ctx; - unsigned char out[4096]; - int outl,outl2; - - printf("Testing cipher %s%s\n",EVP_CIPHER_name(c), - (encdec == 1 ? "(encrypt)" : (encdec == 0 ? "(decrypt)" : "(encrypt/decrypt)"))); - hexdump(stdout,"Key",key,kn); - if(in) - hexdump(stdout,"IV",iv,in); - hexdump(stdout,"Plaintext",plaintext,pn); - hexdump(stdout,"Ciphertext",ciphertext,cn); - - if(kn != c->key_len) - { - fprintf(stderr,"Key length doesn't match, got %d expected %lu\n",kn, - (unsigned long)c->key_len); - test1_exit(5); - } - EVP_CIPHER_CTX_init(&ctx); - if (encdec != 0) - { - if(!EVP_EncryptInit_ex(&ctx,c,NULL,key,iv)) - { - fprintf(stderr,"EncryptInit failed\n"); - ERR_print_errors_fp(stderr); - test1_exit(10); - } - EVP_CIPHER_CTX_set_padding(&ctx,0); - - if(!EVP_EncryptUpdate(&ctx,out,&outl,plaintext,pn)) - { - fprintf(stderr,"Encrypt failed\n"); - ERR_print_errors_fp(stderr); - test1_exit(6); - } - if(!EVP_EncryptFinal_ex(&ctx,out+outl,&outl2)) - { - fprintf(stderr,"EncryptFinal failed\n"); - ERR_print_errors_fp(stderr); - test1_exit(7); - } - - if(outl+outl2 != cn) - { - fprintf(stderr,"Ciphertext length mismatch got %d expected %d\n", - outl+outl2,cn); - test1_exit(8); - } - - if(memcmp(out,ciphertext,cn)) - { - fprintf(stderr,"Ciphertext mismatch\n"); - hexdump(stderr,"Got",out,cn); - hexdump(stderr,"Expected",ciphertext,cn); - test1_exit(9); - } - } - - if (encdec <= 0) - { - if(!EVP_DecryptInit_ex(&ctx,c,NULL,key,iv)) - { - fprintf(stderr,"DecryptInit failed\n"); - ERR_print_errors_fp(stderr); - test1_exit(11); - } - EVP_CIPHER_CTX_set_padding(&ctx,0); - - if(!EVP_DecryptUpdate(&ctx,out,&outl,ciphertext,cn)) - { - fprintf(stderr,"Decrypt failed\n"); - ERR_print_errors_fp(stderr); - test1_exit(6); - } - if(!EVP_DecryptFinal_ex(&ctx,out+outl,&outl2)) - { - fprintf(stderr,"DecryptFinal failed\n"); - ERR_print_errors_fp(stderr); - test1_exit(7); - } - - if(outl+outl2 != pn) - { - fprintf(stderr,"Plaintext length mismatch got %d expected %d\n", - outl+outl2,pn); - test1_exit(8); - } - - if(memcmp(out,plaintext,pn)) - { - fprintf(stderr,"Plaintext mismatch\n"); - hexdump(stderr,"Got",out,pn); - hexdump(stderr,"Expected",plaintext,pn); - test1_exit(9); - } - } - - EVP_CIPHER_CTX_cleanup(&ctx); - - printf("\n"); - } - -static int test_cipher(const char *cipher,const unsigned char *key,int kn, - const unsigned char *iv,int in, - const unsigned char *plaintext,int pn, - const unsigned char *ciphertext,int cn, - int encdec) - { - const EVP_CIPHER *c; - - c=EVP_get_cipherbyname(cipher); - if(!c) - return 0; - - test1(c,key,kn,iv,in,plaintext,pn,ciphertext,cn,encdec); - - return 1; - } - -static int test_digest(const char *digest, - const unsigned char *plaintext,int pn, - const unsigned char *ciphertext, unsigned int cn) - { - const EVP_MD *d; - EVP_MD_CTX ctx; - unsigned char md[EVP_MAX_MD_SIZE]; - unsigned int mdn; - - d=EVP_get_digestbyname(digest); - if(!d) - return 0; - - printf("Testing digest %s\n",EVP_MD_name(d)); - hexdump(stdout,"Plaintext",plaintext,pn); - hexdump(stdout,"Digest",ciphertext,cn); - - EVP_MD_CTX_init(&ctx); - if(!EVP_DigestInit_ex(&ctx,d, NULL)) - { - fprintf(stderr,"DigestInit failed\n"); - ERR_print_errors_fp(stderr); - EXIT(100); - } - if(!EVP_DigestUpdate(&ctx,plaintext,pn)) - { - fprintf(stderr,"DigestUpdate failed\n"); - ERR_print_errors_fp(stderr); - EXIT(101); - } - if(!EVP_DigestFinal_ex(&ctx,md,&mdn)) - { - fprintf(stderr,"DigestFinal failed\n"); - ERR_print_errors_fp(stderr); - EXIT(101); - } - EVP_MD_CTX_cleanup(&ctx); - - if(mdn != cn) - { - fprintf(stderr,"Digest length mismatch, got %d expected %d\n",mdn,cn); - EXIT(102); - } - - if(memcmp(md,ciphertext,cn)) - { - fprintf(stderr,"Digest mismatch\n"); - hexdump(stderr,"Got",md,cn); - hexdump(stderr,"Expected",ciphertext,cn); - EXIT(103); - } - - printf("\n"); - - EVP_MD_CTX_cleanup(&ctx); - - return 1; - } - -int main(int argc,char **argv) - { - const char *szTestFile; - FILE *f; - - if(argc != 2) - { - fprintf(stderr,"%s \n",argv[0]); - EXIT(1); - } - CRYPTO_malloc_debug_init(); - CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL); - CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); - - szTestFile=argv[1]; - - f=fopen(szTestFile,"r"); - if(!f) - { - perror(szTestFile); - EXIT(2); - } - - /* Load up the software EVP_CIPHER and EVP_MD definitions */ - OpenSSL_add_all_ciphers(); - OpenSSL_add_all_digests(); -#ifndef OPENSSL_NO_ENGINE - /* Load all compiled-in ENGINEs */ - ENGINE_load_builtin_engines(); -#endif -#if 0 - OPENSSL_config(); -#endif -#ifndef OPENSSL_NO_ENGINE - /* Register all available ENGINE implementations of ciphers and digests. - * This could perhaps be changed to "ENGINE_register_all_complete()"? */ - ENGINE_register_all_ciphers(); - ENGINE_register_all_digests(); - /* If we add command-line options, this statement should be switchable. - * It'll prevent ENGINEs being ENGINE_init()ialised for cipher/digest use if - * they weren't already initialised. */ - /* ENGINE_set_cipher_flags(ENGINE_CIPHER_FLAG_NOINIT); */ -#endif - - for( ; ; ) - { - char line[4096]; - char *p; - char *cipher; - unsigned char *iv,*key,*plaintext,*ciphertext; - int encdec; - int kn,in,pn,cn; - - if(!fgets((char *)line,sizeof line,f)) - break; - if(line[0] == '#' || line[0] == '\n') - continue; - p=line; - cipher=sstrsep(&p,":"); - key=ustrsep(&p,":"); - iv=ustrsep(&p,":"); - plaintext=ustrsep(&p,":"); - ciphertext=ustrsep(&p,":"); - if (p[-1] == '\n') { - p[-1] = '\0'; - encdec = -1; - } else { - encdec = atoi(sstrsep(&p,"\n")); - } - - - kn=convert(key); - in=convert(iv); - pn=convert(plaintext); - cn=convert(ciphertext); - - if(!test_cipher(cipher,key,kn,iv,in,plaintext,pn,ciphertext,cn,encdec) - && !test_digest(cipher,plaintext,pn,ciphertext,cn)) - { -#ifdef OPENSSL_NO_AES - if (strstr(cipher, "AES") == cipher) - { - fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); - continue; - } -#endif -#ifdef OPENSSL_NO_DES - if (strstr(cipher, "DES") == cipher) - { - fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); - continue; - } -#endif -#ifdef OPENSSL_NO_RC4 - if (strstr(cipher, "RC4") == cipher) - { - fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); - continue; - } -#endif -#ifdef OPENSSL_NO_CAMELLIA - if (strstr(cipher, "CAMELLIA") == cipher) - { - fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); - continue; - } -#endif -#ifdef OPENSSL_NO_SEED - if (strstr(cipher, "SEED") == cipher) - { - fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); - continue; - } -#endif - fprintf(stderr,"Can't find %s\n",cipher); - EXIT(3); - } - } - fclose(f); - -#ifndef OPENSSL_NO_ENGINE - ENGINE_cleanup(); -#endif - EVP_cleanup(); - CRYPTO_cleanup_all_ex_data(); - ERR_remove_thread_state(NULL); - ERR_free_strings(); - CRYPTO_mem_leaks_fp(stderr); - - return 0; - } diff --git a/src/lib/libssl/src/crypto/hmac/hmactest.c b/src/lib/libssl/src/crypto/hmac/hmactest.c deleted file mode 100644 index 282e06e53e..0000000000 --- a/src/lib/libssl/src/crypto/hmac/hmactest.c +++ /dev/null @@ -1,164 +0,0 @@ -/* crypto/hmac/hmactest.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include -#include -#include - -#include "../e_os.h" - -#ifdef OPENSSL_NO_HMAC -int main(int argc, char *argv[]) -{ - printf("No HMAC support\n"); - return(0); -} -#else -#include -#ifndef OPENSSL_NO_MD5 -#include -#endif - - -#ifndef OPENSSL_NO_MD5 -static struct test_st - { - unsigned char key[16]; - int key_len; - unsigned char data[64]; - int data_len; - unsigned char *digest; - } test[4]={ - { "", - 0, - "More text test vectors to stuff up EBCDIC machines :-)", - 54, - (unsigned char *)"e9139d1e6ee064ef8cf514fc7dc83e86", - },{ {0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b, - 0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,}, - 16, - "Hi There", - 8, - (unsigned char *)"9294727a3638bb1c13f48ef8158bfc9d", - },{ "Jefe", - 4, - "what do ya want for nothing?", - 28, - (unsigned char *)"750c783e6ab0b503eaa86e310a5db738", - },{ - {0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa, - 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,}, - 16, - {0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd, - 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd, - 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd, - 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd, - 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd, - 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd, - 0xdd,0xdd}, - 50, - (unsigned char *)"56be34521d144c88dbb8c733f0e8b3f6", - }, - }; -#endif - -static char *pt(unsigned char *md); -int main(int argc, char *argv[]) - { -#ifndef OPENSSL_NO_MD5 - int i; - char *p; -#endif - int err=0; - -#ifdef OPENSSL_NO_MD5 - printf("test skipped: MD5 disabled\n"); -#else - for (i=0; i<4; i++) - { - p=pt(HMAC(EVP_md5(), - test[i].key, test[i].key_len, - test[i].data, test[i].data_len, - NULL,NULL)); - - if (strcmp(p,(char *)test[i].digest) != 0) - { - printf("error calculating HMAC on %d entry'\n",i); - printf("got %s instead of %s\n",p,test[i].digest); - err++; - } - else - printf("test %d ok\n",i); - } -#endif /* OPENSSL_NO_MD5 */ - EXIT(err); - return(0); - } - -#ifndef OPENSSL_NO_MD5 -static char *pt(unsigned char *md) - { - int i; - static char buf[80]; - - for (i=0; i -#include -#include - -#include "../e_os.h" - -#ifdef OPENSSL_NO_IDEA -int main(int argc, char *argv[]) -{ - printf("No IDEA support\n"); - return(0); -} -#else -#include - -unsigned char k[16]={ - 0x00,0x01,0x00,0x02,0x00,0x03,0x00,0x04, - 0x00,0x05,0x00,0x06,0x00,0x07,0x00,0x08}; - -unsigned char in[8]={0x00,0x00,0x00,0x01,0x00,0x02,0x00,0x03}; -unsigned char c[8]={0x11,0xFB,0xED,0x2B,0x01,0x98,0x6D,0xE5}; -unsigned char out[80]; - -char *text="Hello to all people out there"; - -static unsigned char cfb_key[16]={ - 0xe1,0xf0,0xc3,0xd2,0xa5,0xb4,0x87,0x96, - 0x69,0x78,0x4b,0x5a,0x2d,0x3c,0x0f,0x1e, - }; -static unsigned char cfb_iv[80]={0x34,0x12,0x78,0x56,0xab,0x90,0xef,0xcd}; -static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8]; -#define CFB_TEST_SIZE 24 -static unsigned char plain[CFB_TEST_SIZE]= - { - 0x4e,0x6f,0x77,0x20,0x69,0x73, - 0x20,0x74,0x68,0x65,0x20,0x74, - 0x69,0x6d,0x65,0x20,0x66,0x6f, - 0x72,0x20,0x61,0x6c,0x6c,0x20 - }; -static unsigned char cfb_cipher64[CFB_TEST_SIZE]={ - 0x59,0xD8,0xE2,0x65,0x00,0x58,0x6C,0x3F, - 0x2C,0x17,0x25,0xD0,0x1A,0x38,0xB7,0x2A, - 0x39,0x61,0x37,0xDC,0x79,0xFB,0x9F,0x45 - -/* 0xF9,0x78,0x32,0xB5,0x42,0x1A,0x6B,0x38, - 0x9A,0x44,0xD6,0x04,0x19,0x43,0xC4,0xD9, - 0x3D,0x1E,0xAE,0x47,0xFC,0xCF,0x29,0x0B,*/ - }; - -static int cfb64_test(unsigned char *cfb_cipher); -static char *pt(unsigned char *p); -int main(int argc, char *argv[]) - { - int i,err=0; - IDEA_KEY_SCHEDULE key,dkey; - unsigned char iv[8]; - - idea_set_encrypt_key(k,&key); - idea_ecb_encrypt(in,out,&key); - if (memcmp(out,c,8) != 0) - { - printf("ecb idea error encrypting\n"); - printf("got :"); - for (i=0; i<8; i++) - printf("%02X ",out[i]); - printf("\n"); - printf("expected:"); - for (i=0; i<8; i++) - printf("%02X ",c[i]); - err=20; - printf("\n"); - } - - idea_set_decrypt_key(&key,&dkey); - idea_ecb_encrypt(c,out,&dkey); - if (memcmp(out,in,8) != 0) - { - printf("ecb idea error decrypting\n"); - printf("got :"); - for (i=0; i<8; i++) - printf("%02X ",out[i]); - printf("\n"); - printf("expected:"); - for (i=0; i<8; i++) - printf("%02X ",in[i]); - printf("\n"); - err=3; - } - - if (err == 0) printf("ecb idea ok\n"); - - memcpy(iv,k,8); - idea_cbc_encrypt((unsigned char *)text,out,strlen(text)+1,&key,iv,1); - memcpy(iv,k,8); - idea_cbc_encrypt(out,out,8,&dkey,iv,0); - idea_cbc_encrypt(&(out[8]),&(out[8]),strlen(text)+1-8,&dkey,iv,0); - if (memcmp(text,out,strlen(text)+1) != 0) - { - printf("cbc idea bad\n"); - err=4; - } - else - printf("cbc idea ok\n"); - - printf("cfb64 idea "); - if (cfb64_test(cfb_cipher64)) - { - printf("bad\n"); - err=5; - } - else - printf("ok\n"); - -#ifdef OPENSSL_SYS_NETWARE - if (err) printf("ERROR: %d\n", err); -#endif - EXIT(err); - return(err); - } - -static int cfb64_test(unsigned char *cfb_cipher) - { - IDEA_KEY_SCHEDULE eks,dks; - int err=0,i,n; - - idea_set_encrypt_key(cfb_key,&eks); - idea_set_decrypt_key(&eks,&dks); - memcpy(cfb_tmp,cfb_iv,8); - n=0; - idea_cfb64_encrypt(plain,cfb_buf1,(long)12,&eks, - cfb_tmp,&n,IDEA_ENCRYPT); - idea_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]), - (long)CFB_TEST_SIZE-12,&eks, - cfb_tmp,&n,IDEA_ENCRYPT); - if (memcmp(cfb_cipher,cfb_buf1,CFB_TEST_SIZE) != 0) - { - err=1; - printf("idea_cfb64_encrypt encrypt error\n"); - for (i=0; i>4)&0xf]; - ret[i*2+1]=f[p[i]&0xf]; - } - ret[16]='\0'; - return(ret); - } -#endif diff --git a/src/lib/libssl/src/crypto/md2/md2test.c b/src/lib/libssl/src/crypto/md2/md2test.c deleted file mode 100644 index 0195214036..0000000000 --- a/src/lib/libssl/src/crypto/md2/md2test.c +++ /dev/null @@ -1,139 +0,0 @@ -/* crypto/md2/md2test.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include -#include -#include - -#include "../e_os.h" - -#ifdef OPENSSL_NO_MD2 -int main(int argc, char *argv[]) -{ - printf("No MD2 support\n"); - return(0); -} -#else -#include -#include - -static char *test[]={ - "", - "a", - "abc", - "message digest", - "abcdefghijklmnopqrstuvwxyz", - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", - "12345678901234567890123456789012345678901234567890123456789012345678901234567890", - NULL, - }; - -static char *ret[]={ - "8350e5a3e24c153df2275c9f80692773", - "32ec01ec4a6dac72c0ab96fb34c0b5d1", - "da853b0d3f88d99b30283a69e6ded6bb", - "ab4f496bfb2a530b219ff33031fe06b0", - "4e8ddff3650292ab5a4108c3aa47940b", - "da33def2a42df13975352846c30338cd", - "d5976f79d83d3a0dc9806c3c66f3efd8", - }; - -static char *pt(unsigned char *md); -int main(int argc, char *argv[]) - { - int i,err=0; - char **P,**R; - char *p; - unsigned char md[MD2_DIGEST_LENGTH]; - - P=test; - R=ret; - i=1; - while (*P != NULL) - { - EVP_Digest((unsigned char *)*P,strlen(*P),md,NULL,EVP_md2(), NULL); - p=pt(md); - if (strcmp(p,*R) != 0) - { - printf("error calculating MD2 on '%s'\n",*P); - printf("got %s instead of %s\n",p,*R); - err++; - } - else - printf("test %d ok\n",i); - i++; - R++; - P++; - } -#ifdef OPENSSL_SYS_NETWARE - if (err) printf("ERROR: %d\n", err); -#endif - EXIT(err); - return err; - } - -static char *pt(unsigned char *md) - { - int i; - static char buf[80]; - - for (i=0; i -#include -#include - -#include "../e_os.h" - -#ifdef OPENSSL_NO_MD4 -int main(int argc, char *argv[]) -{ - printf("No MD4 support\n"); - return(0); -} -#else -#include -#include - -static char *test[]={ - "", - "a", - "abc", - "message digest", - "abcdefghijklmnopqrstuvwxyz", - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", - "12345678901234567890123456789012345678901234567890123456789012345678901234567890", - NULL, - }; - -static char *ret[]={ -"31d6cfe0d16ae931b73c59d7e0c089c0", -"bde52cb31de33e46245e05fbdbd6fb24", -"a448017aaf21d8525fc10ae87aa6729d", -"d9130a8164549fe818874806e1c7014b", -"d79e1c308aa5bbcdeea8ed63df412da9", -"043f8582f241db351ce627e153e7f0e4", -"e33b4ddc9c38f2199c3e7b164fcc0536", -}; - -static char *pt(unsigned char *md); -int main(int argc, char *argv[]) - { - int i,err=0; - char **P,**R; - char *p; - unsigned char md[MD4_DIGEST_LENGTH]; - - P=test; - R=ret; - i=1; - while (*P != NULL) - { - EVP_Digest(&(P[0][0]),strlen((char *)*P),md,NULL,EVP_md4(), NULL); - p=pt(md); - if (strcmp(p,(char *)*R) != 0) - { - printf("error calculating MD4 on '%s'\n",*P); - printf("got %s instead of %s\n",p,*R); - err++; - } - else - printf("test %d ok\n",i); - i++; - R++; - P++; - } - EXIT(err); - return(0); - } - -static char *pt(unsigned char *md) - { - int i; - static char buf[80]; - - for (i=0; i -#include -#include - -#include "../e_os.h" - -#ifdef OPENSSL_NO_MD5 -int main(int argc, char *argv[]) -{ - printf("No MD5 support\n"); - return(0); -} -#else -#include -#include - -static char *test[]={ - "", - "a", - "abc", - "message digest", - "abcdefghijklmnopqrstuvwxyz", - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", - "12345678901234567890123456789012345678901234567890123456789012345678901234567890", - NULL, - }; - -static char *ret[]={ - "d41d8cd98f00b204e9800998ecf8427e", - "0cc175b9c0f1b6a831c399e269772661", - "900150983cd24fb0d6963f7d28e17f72", - "f96b697d7cb7938d525a2f31aaf161d0", - "c3fcd3d76192e4007dfb496cca67e13b", - "d174ab98d277d9f5a5611c2c9f419d9f", - "57edf4a22be3c955ac49da2e2107b67a", - }; - -static char *pt(unsigned char *md); -int main(int argc, char *argv[]) - { - int i,err=0; - char **P,**R; - char *p; - unsigned char md[MD5_DIGEST_LENGTH]; - - P=test; - R=ret; - i=1; - while (*P != NULL) - { - EVP_Digest(&(P[0][0]),strlen((char *)*P),md,NULL,EVP_md5(), NULL); - p=pt(md); - if (strcmp(p,(char *)*R) != 0) - { - printf("error calculating MD5 on '%s'\n",*P); - printf("got %s instead of %s\n",p,*R); - err++; - } - else - printf("test %d ok\n",i); - i++; - R++; - P++; - } - -#ifdef OPENSSL_SYS_NETWARE - if (err) printf("ERROR: %d\n", err); -#endif - EXIT(err); - return(0); - } - -static char *pt(unsigned char *md) - { - int i; - static char buf[80]; - - for (i=0; i -#include -#include - -#include "../e_os.h" - -#if defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_MDC2) -#define OPENSSL_NO_MDC2 -#endif - -#ifdef OPENSSL_NO_MDC2 -int main(int argc, char *argv[]) -{ - printf("No MDC2 support\n"); - return(0); -} -#else -#include -#include - -static unsigned char pad1[16]={ - 0x42,0xE5,0x0C,0xD2,0x24,0xBA,0xCE,0xBA, - 0x76,0x0B,0xDD,0x2B,0xD4,0x09,0x28,0x1A - }; - -static unsigned char pad2[16]={ - 0x2E,0x46,0x79,0xB5,0xAD,0xD9,0xCA,0x75, - 0x35,0xD8,0x7A,0xFE,0xAB,0x33,0xBE,0xE2 - }; - -int main(int argc, char *argv[]) - { - int ret=0; - unsigned char md[MDC2_DIGEST_LENGTH]; - int i; - EVP_MD_CTX c; - static char *text="Now is the time for all "; - - EVP_MD_CTX_init(&c); - EVP_DigestInit_ex(&c,EVP_mdc2(), NULL); - EVP_DigestUpdate(&c,(unsigned char *)text,strlen(text)); - EVP_DigestFinal_ex(&c,&(md[0]),NULL); - - if (memcmp(md,pad1,MDC2_DIGEST_LENGTH) != 0) - { - for (i=0; ipad_type=2; - EVP_DigestUpdate(&c,(unsigned char *)text,strlen(text)); - EVP_DigestFinal_ex(&c,&(md[0]),NULL); - - if (memcmp(md,pad2,MDC2_DIGEST_LENGTH) != 0) - { - for (i=0; i -#include -#include - -#include "../e_os.h" - -/* some FIPS 140-1 random number test */ -/* some simple tests */ - -int main(int argc,char **argv) - { - unsigned char buf[2500]; - int i,j,k,s,sign,nsign,err=0; - unsigned long n1; - unsigned long n2[16]; - unsigned long runs[2][34]; - /*double d; */ - long d; - - i = RAND_pseudo_bytes(buf,2500); - if (i < 0) - { - printf ("init failed, the rand method is not properly installed\n"); - err++; - goto err; - } - - n1=0; - for (i=0; i<16; i++) n2[i]=0; - for (i=0; i<34; i++) runs[0][i]=runs[1][i]=0; - - /* test 1 and 2 */ - sign=0; - nsign=0; - for (i=0; i<2500; i++) - { - j=buf[i]; - - n2[j&0x0f]++; - n2[(j>>4)&0x0f]++; - - for (k=0; k<8; k++) - { - s=(j&0x01); - if (s == sign) - nsign++; - else - { - if (nsign > 34) nsign=34; - if (nsign != 0) - { - runs[sign][nsign-1]++; - if (nsign > 6) - runs[sign][5]++; - } - sign=s; - nsign=1; - } - - if (s) n1++; - j>>=1; - } - } - if (nsign > 34) nsign=34; - if (nsign != 0) runs[sign][nsign-1]++; - - /* test 1 */ - if (!((9654 < n1) && (n1 < 10346))) - { - printf("test 1 failed, X=%lu\n",n1); - err++; - } - printf("test 1 done\n"); - - /* test 2 */ -#ifdef undef - d=0; - for (i=0; i<16; i++) - d+=n2[i]*n2[i]; - d=d*16.0/5000.0-5000.0; - if (!((1.03 < d) && (d < 57.4))) - { - printf("test 2 failed, X=%.2f\n",d); - err++; - } -#endif - d=0; - for (i=0; i<16; i++) - d+=n2[i]*n2[i]; - d=(d*8)/25-500000; - if (!((103 < d) && (d < 5740))) - { - printf("test 2 failed, X=%ld.%02ld\n",d/100L,d%100L); - err++; - } - printf("test 2 done\n"); - - /* test 3 */ - for (i=0; i<2; i++) - { - if (!((2267 < runs[i][0]) && (runs[i][0] < 2733))) - { - printf("test 3 failed, bit=%d run=%d num=%lu\n", - i,1,runs[i][0]); - err++; - } - if (!((1079 < runs[i][1]) && (runs[i][1] < 1421))) - { - printf("test 3 failed, bit=%d run=%d num=%lu\n", - i,2,runs[i][1]); - err++; - } - if (!(( 502 < runs[i][2]) && (runs[i][2] < 748))) - { - printf("test 3 failed, bit=%d run=%d num=%lu\n", - i,3,runs[i][2]); - err++; - } - if (!(( 223 < runs[i][3]) && (runs[i][3] < 402))) - { - printf("test 3 failed, bit=%d run=%d num=%lu\n", - i,4,runs[i][3]); - err++; - } - if (!(( 90 < runs[i][4]) && (runs[i][4] < 223))) - { - printf("test 3 failed, bit=%d run=%d num=%lu\n", - i,5,runs[i][4]); - err++; - } - if (!(( 90 < runs[i][5]) && (runs[i][5] < 223))) - { - printf("test 3 failed, bit=%d run=%d num=%lu\n", - i,6,runs[i][5]); - err++; - } - } - printf("test 3 done\n"); - - /* test 4 */ - if (runs[0][33] != 0) - { - printf("test 4 failed, bit=%d run=%d num=%lu\n", - 0,34,runs[0][33]); - err++; - } - if (runs[1][33] != 0) - { - printf("test 4 failed, bit=%d run=%d num=%lu\n", - 1,34,runs[1][33]); - err++; - } - printf("test 4 done\n"); - err: - err=((err)?1:0); -#ifdef OPENSSL_SYS_NETWARE - if (err) printf("ERROR: %d\n", err); -#endif - EXIT(err); - return(err); - } diff --git a/src/lib/libssl/src/crypto/rc2/rc2test.c b/src/lib/libssl/src/crypto/rc2/rc2test.c deleted file mode 100644 index 0e117436bb..0000000000 --- a/src/lib/libssl/src/crypto/rc2/rc2test.c +++ /dev/null @@ -1,274 +0,0 @@ -/* crypto/rc2/rc2test.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.] - */ - -/* This has been a quickly hacked 'ideatest.c'. When I add tests for other - * RC2 modes, more of the code will be uncommented. */ - -#include -#include -#include - -#include "../e_os.h" - -#ifdef OPENSSL_NO_RC2 -int main(int argc, char *argv[]) -{ - printf("No RC2 support\n"); - return(0); -} -#else -#include - -static unsigned char RC2key[4][16]={ - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, - 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F}, - }; - -static unsigned char RC2plain[4][8]={ - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - }; - -static unsigned char RC2cipher[4][8]={ - {0x1C,0x19,0x8A,0x83,0x8D,0xF0,0x28,0xB7}, - {0x21,0x82,0x9C,0x78,0xA9,0xF9,0xC0,0x74}, - {0x13,0xDB,0x35,0x17,0xD3,0x21,0x86,0x9E}, - {0x50,0xDC,0x01,0x62,0xBD,0x75,0x7F,0x31}, - }; -/************/ -#ifdef undef -unsigned char k[16]={ - 0x00,0x01,0x00,0x02,0x00,0x03,0x00,0x04, - 0x00,0x05,0x00,0x06,0x00,0x07,0x00,0x08}; - -unsigned char in[8]={0x00,0x00,0x00,0x01,0x00,0x02,0x00,0x03}; -unsigned char c[8]={0x11,0xFB,0xED,0x2B,0x01,0x98,0x6D,0xE5}; -unsigned char out[80]; - -char *text="Hello to all people out there"; - -static unsigned char cfb_key[16]={ - 0xe1,0xf0,0xc3,0xd2,0xa5,0xb4,0x87,0x96, - 0x69,0x78,0x4b,0x5a,0x2d,0x3c,0x0f,0x1e, - }; -static unsigned char cfb_iv[80]={0x34,0x12,0x78,0x56,0xab,0x90,0xef,0xcd}; -static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8]; -#define CFB_TEST_SIZE 24 -static unsigned char plain[CFB_TEST_SIZE]= - { - 0x4e,0x6f,0x77,0x20,0x69,0x73, - 0x20,0x74,0x68,0x65,0x20,0x74, - 0x69,0x6d,0x65,0x20,0x66,0x6f, - 0x72,0x20,0x61,0x6c,0x6c,0x20 - }; -static unsigned char cfb_cipher64[CFB_TEST_SIZE]={ - 0x59,0xD8,0xE2,0x65,0x00,0x58,0x6C,0x3F, - 0x2C,0x17,0x25,0xD0,0x1A,0x38,0xB7,0x2A, - 0x39,0x61,0x37,0xDC,0x79,0xFB,0x9F,0x45 - -/* 0xF9,0x78,0x32,0xB5,0x42,0x1A,0x6B,0x38, - 0x9A,0x44,0xD6,0x04,0x19,0x43,0xC4,0xD9, - 0x3D,0x1E,0xAE,0x47,0xFC,0xCF,0x29,0x0B,*/ - }; - - -/*static int cfb64_test(unsigned char *cfb_cipher);*/ -static char *pt(unsigned char *p); -#endif - -int main(int argc, char *argv[]) - { - int i,n,err=0; - RC2_KEY key; - unsigned char buf[8],buf2[8]; - - for (n=0; n<4; n++) - { - RC2_set_key(&key,16,&(RC2key[n][0]),0 /* or 1024 */); - - RC2_ecb_encrypt(&(RC2plain[n][0]),buf,&key,RC2_ENCRYPT); - if (memcmp(&(RC2cipher[n][0]),buf,8) != 0) - { - printf("ecb rc2 error encrypting\n"); - printf("got :"); - for (i=0; i<8; i++) - printf("%02X ",buf[i]); - printf("\n"); - printf("expected:"); - for (i=0; i<8; i++) - printf("%02X ",RC2cipher[n][i]); - err=20; - printf("\n"); - } - - RC2_ecb_encrypt(buf,buf2,&key,RC2_DECRYPT); - if (memcmp(&(RC2plain[n][0]),buf2,8) != 0) - { - printf("ecb RC2 error decrypting\n"); - printf("got :"); - for (i=0; i<8; i++) - printf("%02X ",buf[i]); - printf("\n"); - printf("expected:"); - for (i=0; i<8; i++) - printf("%02X ",RC2plain[n][i]); - printf("\n"); - err=3; - } - } - - if (err == 0) printf("ecb RC2 ok\n"); -#ifdef undef - memcpy(iv,k,8); - idea_cbc_encrypt((unsigned char *)text,out,strlen(text)+1,&key,iv,1); - memcpy(iv,k,8); - idea_cbc_encrypt(out,out,8,&dkey,iv,0); - idea_cbc_encrypt(&(out[8]),&(out[8]),strlen(text)+1-8,&dkey,iv,0); - if (memcmp(text,out,strlen(text)+1) != 0) - { - printf("cbc idea bad\n"); - err=4; - } - else - printf("cbc idea ok\n"); - - printf("cfb64 idea "); - if (cfb64_test(cfb_cipher64)) - { - printf("bad\n"); - err=5; - } - else - printf("ok\n"); -#endif - -#ifdef OPENSSL_SYS_NETWARE - if (err) printf("ERROR: %d\n", err); -#endif - EXIT(err); - return(err); - } - -#ifdef undef -static int cfb64_test(unsigned char *cfb_cipher) - { - IDEA_KEY_SCHEDULE eks,dks; - int err=0,i,n; - - idea_set_encrypt_key(cfb_key,&eks); - idea_set_decrypt_key(&eks,&dks); - memcpy(cfb_tmp,cfb_iv,8); - n=0; - idea_cfb64_encrypt(plain,cfb_buf1,(long)12,&eks, - cfb_tmp,&n,IDEA_ENCRYPT); - idea_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]), - (long)CFB_TEST_SIZE-12,&eks, - cfb_tmp,&n,IDEA_ENCRYPT); - if (memcmp(cfb_cipher,cfb_buf1,CFB_TEST_SIZE) != 0) - { - err=1; - printf("idea_cfb64_encrypt encrypt error\n"); - for (i=0; i>4)&0xf]; - ret[i*2+1]=f[p[i]&0xf]; - } - ret[16]='\0'; - return(ret); - } - -#endif -#endif diff --git a/src/lib/libssl/src/crypto/rc4/rc4test.c b/src/lib/libssl/src/crypto/rc4/rc4test.c deleted file mode 100644 index 4312605ccb..0000000000 --- a/src/lib/libssl/src/crypto/rc4/rc4test.c +++ /dev/null @@ -1,242 +0,0 @@ -/* crypto/rc4/rc4test.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include -#include -#include - -#include "../e_os.h" - -#ifdef OPENSSL_NO_RC4 -int main(int argc, char *argv[]) -{ - printf("No RC4 support\n"); - return(0); -} -#else -#include -#include - -static unsigned char keys[7][30]={ - {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}, - {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}, - {8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {4,0xef,0x01,0x23,0x45}, - {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}, - {4,0xef,0x01,0x23,0x45}, - }; - -static unsigned char data_len[7]={8,8,8,20,28,10}; -static unsigned char data[7][30]={ - {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0xff}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0xff}, - {0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF0, - 0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF0, - 0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF0, - 0x12,0x34,0x56,0x78,0xff}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff}, - {0}, - }; - -static unsigned char output[7][30]={ - {0x75,0xb7,0x87,0x80,0x99,0xe0,0xc5,0x96,0x00}, - {0x74,0x94,0xc2,0xe7,0x10,0x4b,0x08,0x79,0x00}, - {0xde,0x18,0x89,0x41,0xa3,0x37,0x5d,0x3a,0x00}, - {0xd6,0xa1,0x41,0xa7,0xec,0x3c,0x38,0xdf, - 0xbd,0x61,0x5a,0x11,0x62,0xe1,0xc7,0xba, - 0x36,0xb6,0x78,0x58,0x00}, - {0x66,0xa0,0x94,0x9f,0x8a,0xf7,0xd6,0x89, - 0x1f,0x7f,0x83,0x2b,0xa8,0x33,0xc0,0x0c, - 0x89,0x2e,0xbe,0x30,0x14,0x3c,0xe2,0x87, - 0x40,0x01,0x1e,0xcf,0x00}, - {0xd6,0xa1,0x41,0xa7,0xec,0x3c,0x38,0xdf,0xbd,0x61,0x00}, - {0}, - }; - -int main(int argc, char *argv[]) - { - int i,err=0; - int j; - unsigned char *p; - RC4_KEY key; - unsigned char obuf[512]; - -#if !defined(OPENSSL_PIC) - void OPENSSL_cpuid_setup(void); - - OPENSSL_cpuid_setup(); -#endif - - for (i=0; i<6; i++) - { - RC4_set_key(&key,keys[i][0],&(keys[i][1])); - memset(obuf,0x00,sizeof(obuf)); - RC4(&key,data_len[i],&(data[i][0]),obuf); - if (memcmp(obuf,output[i],data_len[i]+1) != 0) - { - printf("error calculating RC4\n"); - printf("output:"); - for (j=0; j -#include -#include - -#include "../e_os.h" - -#ifdef OPENSSL_NO_RIPEMD -int main(int argc, char *argv[]) -{ - printf("No ripemd support\n"); - return(0); -} -#else -#include -#include - -static char *test[]={ - "", - "a", - "abc", - "message digest", - "abcdefghijklmnopqrstuvwxyz", - "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", - "12345678901234567890123456789012345678901234567890123456789012345678901234567890", - NULL, - }; - -static char *ret[]={ - "9c1185a5c5e9fc54612808977ee8f548b2258d31", - "0bdc9d2d256b3ee9daae347be6f4dc835a467ffe", - "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc", - "5d0689ef49d2fae572b881b123a85ffa21595f36", - "f71c27109c692c1b56bbdceb5b9d2865b3708dbc", - "12a053384a9c0c88e405a06c27dcf49ada62eb2b", - "b0e20b6e3116640286ed3a87a5713079b21f5189", - "9b752e45573d4b39f4dbd3323cab82bf63326bfb", - }; - -static char *pt(unsigned char *md); -int main(int argc, char *argv[]) - { - int i,err=0; - char **P,**R; - char *p; - unsigned char md[RIPEMD160_DIGEST_LENGTH]; - - P=test; - R=ret; - i=1; - while (*P != NULL) - { - EVP_Digest(&(P[0][0]),strlen((char *)*P),md,NULL,EVP_ripemd160(), NULL); - p=pt(md); - if (strcmp(p,(char *)*R) != 0) - { - printf("error calculating RIPEMD160 on '%s'\n",*P); - printf("got %s instead of %s\n",p,*R); - err++; - } - else - printf("test %d ok\n",i); - i++; - R++; - P++; - } - EXIT(err); - return(0); - } - -static char *pt(unsigned char *md) - { - int i; - static char buf[80]; - - for (i=0; i -#include -#include - -#include "../e_os.h" - -#ifdef OPENSSL_NO_SHA -int main(int argc, char *argv[]) -{ - printf("No SHA support\n"); - return(0); -} -#else -#include -#include - -#undef SHA_0 /* FIPS 180 */ -#define SHA_1 /* FIPS 180-1 */ - -static char *test[]={ - "abc", - "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", - NULL, - }; - -#ifdef SHA_0 -static char *ret[]={ - "0164b8a914cd2a5e74c4f7ff082c4d97f1edf880", - "d2516ee1acfa5baf33dfc1c471e438449ef134c8", - }; -static char *bigret= - "3232affa48628a26653b5aaa44541fd90d690603"; -#endif -#ifdef SHA_1 -static char *ret[]={ - "a9993e364706816aba3e25717850c26c9cd0d89d", - "84983e441c3bd26ebaae4aa1f95129e5e54670f1", - }; -static char *bigret= - "34aa973cd4c4daa4f61eeb2bdbad27316534016f"; -#endif - -static char *pt(unsigned char *md); -int main(int argc, char *argv[]) - { - int i,err=0; - char **P,**R; - static unsigned char buf[1000]; - char *p,*r; - EVP_MD_CTX c; - unsigned char md[SHA_DIGEST_LENGTH]; - - EVP_MD_CTX_init(&c); - P=test; - R=ret; - i=1; - while (*P != NULL) - { - EVP_Digest(*P,strlen((char *)*P),md,NULL,EVP_sha1(), NULL); - p=pt(md); - if (strcmp(p,(char *)*R) != 0) - { - printf("error calculating SHA1 on '%s'\n",*P); - printf("got %s instead of %s\n",p,*R); - err++; - } - else - printf("test %d ok\n",i); - i++; - R++; - P++; - } - - memset(buf,'a',1000); - EVP_DigestInit_ex(&c,EVP_sha1(), NULL); - for (i=0; i<1000; i++) - EVP_DigestUpdate(&c,buf,1000); - EVP_DigestFinal_ex(&c,md,NULL); - p=pt(md); - - r=bigret; - if (strcmp(p,r) != 0) - { - printf("error calculating SHA1 on 'a' * 1000\n"); - printf("got %s instead of %s\n",p,r); - err++; - } - else - printf("test 3 ok\n"); - -#ifdef OPENSSL_SYS_NETWARE - if (err) printf("ERROR: %d\n", err); -#endif - EXIT(err); - EVP_MD_CTX_cleanup(&c); - return(0); - } - -static char *pt(unsigned char *md) - { - int i; - static char buf[80]; - - for (i=0; i -#include -#include - -#include "../e_os.h" - -#if defined(OPENSSL_NO_SHA) || defined(OPENSSL_NO_SHA0) -int main(int argc, char *argv[]) -{ - printf("No SHA0 support\n"); - return(0); -} -#else -#include -#include - -#define SHA_0 /* FIPS 180 */ -#undef SHA_1 /* FIPS 180-1 */ - -static char *test[]={ - "abc", - "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", - NULL, - }; - -#ifdef SHA_0 -static char *ret[]={ - "0164b8a914cd2a5e74c4f7ff082c4d97f1edf880", - "d2516ee1acfa5baf33dfc1c471e438449ef134c8", - }; -static char *bigret= - "3232affa48628a26653b5aaa44541fd90d690603"; -#endif -#ifdef SHA_1 -static char *ret[]={ - "a9993e364706816aba3e25717850c26c9cd0d89d", - "84983e441c3bd26ebaae4aa1f95129e5e54670f1", - }; -static char *bigret= - "34aa973cd4c4daa4f61eeb2bdbad27316534016f"; -#endif - -static char *pt(unsigned char *md); -int main(int argc, char *argv[]) - { - int i,err=0; - char **P,**R; - static unsigned char buf[1000]; - char *p,*r; - EVP_MD_CTX c; - unsigned char md[SHA_DIGEST_LENGTH]; - - EVP_MD_CTX_init(&c); - P=test; - R=ret; - i=1; - while (*P != NULL) - { - EVP_Digest(*P,strlen(*P),md,NULL,EVP_sha(), NULL); - p=pt(md); - if (strcmp(p,*R) != 0) - { - printf("error calculating SHA on '%s'\n",*P); - printf("got %s instead of %s\n",p,*R); - err++; - } - else - printf("test %d ok\n",i); - i++; - R++; - P++; - } - - memset(buf,'a',1000); - EVP_DigestInit_ex(&c,EVP_sha(), NULL); - for (i=0; i<1000; i++) - EVP_DigestUpdate(&c,buf,1000); - EVP_DigestFinal_ex(&c,md,NULL); - p=pt(md); - - r=bigret; - if (strcmp(p,r) != 0) - { - printf("error calculating SHA on '%s'\n",p); - printf("got %s instead of %s\n",p,r); - err++; - } - else - printf("test 3 ok\n"); - -#ifdef OPENSSL_SYS_NETWARE - if (err) printf("ERROR: %d\n", err); -#endif - EVP_MD_CTX_cleanup(&c); - EXIT(err); - return(0); - } - -static char *pt(unsigned char *md) - { - int i; - static char buf[80]; - - for (i=0; i