提交海思SDK源码及驱动配置
This commit is contained in:
@@ -1 +0,0 @@
|
||||
|
||||
Executable → Regular
Executable → Regular
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/bf/bftest.c
|
||||
@@ -0,0 +1,538 @@
|
||||
/* 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 <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <openssl/opensslconf.h> /* 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 <openssl/blowfish.h>
|
||||
|
||||
# ifdef CHARSET_EBCDIC
|
||||
# include <openssl/ebcdic.h>
|
||||
# endif
|
||||
|
||||
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 < NUM_TESTS; i++) {
|
||||
for (j = 0; j < 8; j++)
|
||||
printf("%02X", ecb_data[i][j]);
|
||||
printf("\t");
|
||||
for (j = 0; j < 8; j++)
|
||||
printf("%02X", plain_data[i][j]);
|
||||
printf("\t");
|
||||
for (j = 0; j < 8; j++)
|
||||
printf("%02X", cipher_data[i][j]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
printf("set_key test data\n");
|
||||
printf("data[8]= ");
|
||||
for (j = 0; j < 8; j++)
|
||||
printf("%02X", key_data[j]);
|
||||
printf("\n");
|
||||
for (i = 0; i < KEY_TEST_NUM - 1; i++) {
|
||||
printf("c=");
|
||||
for (j = 0; j < 8; j++)
|
||||
printf("%02X", key_out[i][j]);
|
||||
printf(" k[%2u]=", i + 1);
|
||||
for (j = 0; j < i + 1; j++)
|
||||
printf("%02X", key_test[j]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
printf("\nchaining mode test data\n");
|
||||
printf("key[16] = ");
|
||||
for (j = 0; j < 16; j++)
|
||||
printf("%02X", cbc_key[j]);
|
||||
printf("\niv[8] = ");
|
||||
for (j = 0; j < 8; j++)
|
||||
printf("%02X", cbc_iv[j]);
|
||||
printf("\ndata[%d] = '%s'", (int)strlen(cbc_data) + 1, cbc_data);
|
||||
printf("\ndata[%d] = ", (int)strlen(cbc_data) + 1);
|
||||
for (j = 0; j < strlen(cbc_data) + 1; j++)
|
||||
printf("%02X", cbc_data[j]);
|
||||
printf("\n");
|
||||
printf("cbc cipher text\n");
|
||||
printf("cipher[%d]= ", 32);
|
||||
for (j = 0; j < 32; j++)
|
||||
printf("%02X", cbc_ok[j]);
|
||||
printf("\n");
|
||||
|
||||
printf("cfb64 cipher text\n");
|
||||
printf("cipher[%d]= ", (int)strlen(cbc_data) + 1);
|
||||
for (j = 0; j < strlen(cbc_data) + 1; j++)
|
||||
printf("%02X", cfb64_ok[j]);
|
||||
printf("\n");
|
||||
|
||||
printf("ofb64 cipher text\n");
|
||||
printf("cipher[%d]= ", (int)strlen(cbc_data) + 1);
|
||||
for (j = 0; j < strlen(cbc_data) + 1; j++)
|
||||
printf("%02X", ofb64_ok[j]);
|
||||
printf("\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int test(void)
|
||||
{
|
||||
unsigned char cbc_in[40], cbc_out[40], iv[8];
|
||||
int i, n, err = 0;
|
||||
BF_KEY key;
|
||||
BF_LONG data[2];
|
||||
unsigned char out[8];
|
||||
BF_LONG len;
|
||||
|
||||
# ifdef CHARSET_EBCDIC
|
||||
ebcdic2ascii(cbc_data, cbc_data, strlen(cbc_data));
|
||||
# endif
|
||||
|
||||
printf("testing blowfish in raw ecb mode\n");
|
||||
for (n = 0; n < 2; n++) {
|
||||
# ifdef CHARSET_EBCDIC
|
||||
ebcdic2ascii(bf_key[n], bf_key[n], strlen(bf_key[n]));
|
||||
# endif
|
||||
BF_set_key(&key, strlen(bf_key[n]), (unsigned char *)bf_key[n]);
|
||||
|
||||
data[0] = bf_plain[n][0];
|
||||
data[1] = bf_plain[n][1];
|
||||
BF_encrypt(data, &key);
|
||||
if (memcmp(&(bf_cipher[n][0]), &(data[0]), 8) != 0) {
|
||||
printf("BF_encrypt error encrypting\n");
|
||||
printf("got :");
|
||||
for (i = 0; i < 2; i++)
|
||||
printf("%08lX ", (unsigned long)data[i]);
|
||||
printf("\n");
|
||||
printf("expected:");
|
||||
for (i = 0; i < 2; i++)
|
||||
printf("%08lX ", (unsigned long)bf_cipher[n][i]);
|
||||
err = 1;
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
BF_decrypt(&(data[0]), &key);
|
||||
if (memcmp(&(bf_plain[n][0]), &(data[0]), 8) != 0) {
|
||||
printf("BF_encrypt error decrypting\n");
|
||||
printf("got :");
|
||||
for (i = 0; i < 2; i++)
|
||||
printf("%08lX ", (unsigned long)data[i]);
|
||||
printf("\n");
|
||||
printf("expected:");
|
||||
for (i = 0; i < 2; i++)
|
||||
printf("%08lX ", (unsigned long)bf_plain[n][i]);
|
||||
printf("\n");
|
||||
err = 1;
|
||||
}
|
||||
}
|
||||
|
||||
printf("testing blowfish in ecb mode\n");
|
||||
|
||||
for (n = 0; n < NUM_TESTS; n++) {
|
||||
BF_set_key(&key, 8, ecb_data[n]);
|
||||
|
||||
BF_ecb_encrypt(&(plain_data[n][0]), out, &key, BF_ENCRYPT);
|
||||
if (memcmp(&(cipher_data[n][0]), out, 8) != 0) {
|
||||
printf("BF_ecb_encrypt blowfish 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 ", cipher_data[n][i]);
|
||||
err = 1;
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
BF_ecb_encrypt(out, out, &key, BF_DECRYPT);
|
||||
if (memcmp(&(plain_data[n][0]), out, 8) != 0) {
|
||||
printf("BF_ecb_encrypt 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 ", plain_data[n][i]);
|
||||
printf("\n");
|
||||
err = 1;
|
||||
}
|
||||
}
|
||||
|
||||
printf("testing blowfish set_key\n");
|
||||
for (n = 1; n < KEY_TEST_NUM; n++) {
|
||||
BF_set_key(&key, n, key_test);
|
||||
BF_ecb_encrypt(key_data, out, &key, BF_ENCRYPT);
|
||||
/* mips-sgi-irix6.5-gcc vv -mabi=64 bug workaround */
|
||||
if (memcmp(out, &(key_out[i = n - 1][0]), 8) != 0) {
|
||||
printf("blowfish setkey error\n");
|
||||
err = 1;
|
||||
}
|
||||
}
|
||||
|
||||
printf("testing blowfish in cbc mode\n");
|
||||
len = strlen(cbc_data) + 1;
|
||||
|
||||
BF_set_key(&key, 16, cbc_key);
|
||||
memset(cbc_in, 0, sizeof cbc_in);
|
||||
memset(cbc_out, 0, sizeof cbc_out);
|
||||
memcpy(iv, cbc_iv, sizeof iv);
|
||||
BF_cbc_encrypt((unsigned char *)cbc_data, cbc_out, len,
|
||||
&key, iv, BF_ENCRYPT);
|
||||
if (memcmp(cbc_out, cbc_ok, 32) != 0) {
|
||||
err = 1;
|
||||
printf("BF_cbc_encrypt encrypt error\n");
|
||||
for (i = 0; i < 32; i++)
|
||||
printf("0x%02X,", cbc_out[i]);
|
||||
}
|
||||
memcpy(iv, cbc_iv, 8);
|
||||
BF_cbc_encrypt(cbc_out, cbc_in, len, &key, iv, BF_DECRYPT);
|
||||
if (memcmp(cbc_in, cbc_data, strlen(cbc_data) + 1) != 0) {
|
||||
printf("BF_cbc_encrypt decrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
|
||||
printf("testing blowfish in cfb64 mode\n");
|
||||
|
||||
BF_set_key(&key, 16, cbc_key);
|
||||
memset(cbc_in, 0, 40);
|
||||
memset(cbc_out, 0, 40);
|
||||
memcpy(iv, cbc_iv, 8);
|
||||
n = 0;
|
||||
BF_cfb64_encrypt((unsigned char *)cbc_data, cbc_out, (long)13,
|
||||
&key, iv, &n, BF_ENCRYPT);
|
||||
BF_cfb64_encrypt((unsigned char *)&(cbc_data[13]), &(cbc_out[13]),
|
||||
len - 13, &key, iv, &n, BF_ENCRYPT);
|
||||
if (memcmp(cbc_out, cfb64_ok, (int)len) != 0) {
|
||||
err = 1;
|
||||
printf("BF_cfb64_encrypt encrypt error\n");
|
||||
for (i = 0; i < (int)len; i++)
|
||||
printf("0x%02X,", cbc_out[i]);
|
||||
}
|
||||
n = 0;
|
||||
memcpy(iv, cbc_iv, 8);
|
||||
BF_cfb64_encrypt(cbc_out, cbc_in, 17, &key, iv, &n, BF_DECRYPT);
|
||||
BF_cfb64_encrypt(&(cbc_out[17]), &(cbc_in[17]), len - 17,
|
||||
&key, iv, &n, BF_DECRYPT);
|
||||
if (memcmp(cbc_in, cbc_data, (int)len) != 0) {
|
||||
printf("BF_cfb64_encrypt decrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
|
||||
printf("testing blowfish in ofb64\n");
|
||||
|
||||
BF_set_key(&key, 16, cbc_key);
|
||||
memset(cbc_in, 0, 40);
|
||||
memset(cbc_out, 0, 40);
|
||||
memcpy(iv, cbc_iv, 8);
|
||||
n = 0;
|
||||
BF_ofb64_encrypt((unsigned char *)cbc_data, cbc_out, (long)13, &key, iv,
|
||||
&n);
|
||||
BF_ofb64_encrypt((unsigned char *)&(cbc_data[13]), &(cbc_out[13]),
|
||||
len - 13, &key, iv, &n);
|
||||
if (memcmp(cbc_out, ofb64_ok, (int)len) != 0) {
|
||||
err = 1;
|
||||
printf("BF_ofb64_encrypt encrypt error\n");
|
||||
for (i = 0; i < (int)len; i++)
|
||||
printf("0x%02X,", cbc_out[i]);
|
||||
}
|
||||
n = 0;
|
||||
memcpy(iv, cbc_iv, 8);
|
||||
BF_ofb64_encrypt(cbc_out, cbc_in, 17, &key, iv, &n);
|
||||
BF_ofb64_encrypt(&(cbc_out[17]), &(cbc_in[17]), len - 17, &key, iv, &n);
|
||||
if (memcmp(cbc_in, cbc_data, (int)len) != 0) {
|
||||
printf("BF_ofb64_encrypt decrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
|
||||
return (err);
|
||||
}
|
||||
#endif
|
||||
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/bn/bntest.c
|
||||
File diff suppressed because it is too large
Load Diff
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/cast/casttest.c
|
||||
@@ -0,0 +1,241 @@
|
||||
/* 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 <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <openssl/opensslconf.h> /* 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 <openssl/cast.h>
|
||||
|
||||
# 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
|
||||
Executable → Regular
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/constant_time_test.c
|
||||
@@ -0,0 +1,304 @@
|
||||
/* crypto/constant_time_test.c */
|
||||
/*-
|
||||
* Utilities for constant-time cryptography.
|
||||
*
|
||||
* Author: Emilia Kasper (emilia@openssl.org)
|
||||
* Based on previous work by Bodo Moeller, Emilia Kasper, Adam Langley
|
||||
* (Google).
|
||||
* ====================================================================
|
||||
* Copyright (c) 2014 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 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 "../crypto/constant_time_locl.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static const unsigned int CONSTTIME_TRUE = (unsigned)(~0);
|
||||
static const unsigned int CONSTTIME_FALSE = 0;
|
||||
static const unsigned char CONSTTIME_TRUE_8 = 0xff;
|
||||
static const unsigned char CONSTTIME_FALSE_8 = 0;
|
||||
|
||||
static int test_binary_op(unsigned int (*op) (unsigned int a, unsigned int b),
|
||||
const char *op_name, unsigned int a, unsigned int b,
|
||||
int is_true)
|
||||
{
|
||||
unsigned c = op(a, b);
|
||||
if (is_true && c != CONSTTIME_TRUE) {
|
||||
fprintf(stderr, "Test failed for %s(%du, %du): expected %du "
|
||||
"(TRUE), got %du\n", op_name, a, b, CONSTTIME_TRUE, c);
|
||||
return 1;
|
||||
} else if (!is_true && c != CONSTTIME_FALSE) {
|
||||
fprintf(stderr, "Test failed for %s(%du, %du): expected %du "
|
||||
"(FALSE), got %du\n", op_name, a, b, CONSTTIME_FALSE, c);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_binary_op_8(unsigned
|
||||
char (*op) (unsigned int a, unsigned int b),
|
||||
const char *op_name, unsigned int a,
|
||||
unsigned int b, int is_true)
|
||||
{
|
||||
unsigned char c = op(a, b);
|
||||
if (is_true && c != CONSTTIME_TRUE_8) {
|
||||
fprintf(stderr, "Test failed for %s(%du, %du): expected %u "
|
||||
"(TRUE), got %u\n", op_name, a, b, CONSTTIME_TRUE_8, c);
|
||||
return 1;
|
||||
} else if (!is_true && c != CONSTTIME_FALSE_8) {
|
||||
fprintf(stderr, "Test failed for %s(%du, %du): expected %u "
|
||||
"(FALSE), got %u\n", op_name, a, b, CONSTTIME_FALSE_8, c);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_is_zero(unsigned int a)
|
||||
{
|
||||
unsigned int c = constant_time_is_zero(a);
|
||||
if (a == 0 && c != CONSTTIME_TRUE) {
|
||||
fprintf(stderr, "Test failed for constant_time_is_zero(%du): "
|
||||
"expected %du (TRUE), got %du\n", a, CONSTTIME_TRUE, c);
|
||||
return 1;
|
||||
} else if (a != 0 && c != CONSTTIME_FALSE) {
|
||||
fprintf(stderr, "Test failed for constant_time_is_zero(%du): "
|
||||
"expected %du (FALSE), got %du\n", a, CONSTTIME_FALSE, c);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_is_zero_8(unsigned int a)
|
||||
{
|
||||
unsigned char c = constant_time_is_zero_8(a);
|
||||
if (a == 0 && c != CONSTTIME_TRUE_8) {
|
||||
fprintf(stderr, "Test failed for constant_time_is_zero(%du): "
|
||||
"expected %u (TRUE), got %u\n", a, CONSTTIME_TRUE_8, c);
|
||||
return 1;
|
||||
} else if (a != 0 && c != CONSTTIME_FALSE) {
|
||||
fprintf(stderr, "Test failed for constant_time_is_zero(%du): "
|
||||
"expected %u (FALSE), got %u\n", a, CONSTTIME_FALSE_8, c);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_select(unsigned int a, unsigned int b)
|
||||
{
|
||||
unsigned int selected = constant_time_select(CONSTTIME_TRUE, a, b);
|
||||
if (selected != a) {
|
||||
fprintf(stderr, "Test failed for constant_time_select(%du, %du,"
|
||||
"%du): expected %du(first value), got %du\n",
|
||||
CONSTTIME_TRUE, a, b, a, selected);
|
||||
return 1;
|
||||
}
|
||||
selected = constant_time_select(CONSTTIME_FALSE, a, b);
|
||||
if (selected != b) {
|
||||
fprintf(stderr, "Test failed for constant_time_select(%du, %du,"
|
||||
"%du): expected %du(second value), got %du\n",
|
||||
CONSTTIME_FALSE, a, b, b, selected);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_select_8(unsigned char a, unsigned char b)
|
||||
{
|
||||
unsigned char selected = constant_time_select_8(CONSTTIME_TRUE_8, a, b);
|
||||
if (selected != a) {
|
||||
fprintf(stderr, "Test failed for constant_time_select(%u, %u,"
|
||||
"%u): expected %u(first value), got %u\n",
|
||||
CONSTTIME_TRUE, a, b, a, selected);
|
||||
return 1;
|
||||
}
|
||||
selected = constant_time_select_8(CONSTTIME_FALSE_8, a, b);
|
||||
if (selected != b) {
|
||||
fprintf(stderr, "Test failed for constant_time_select(%u, %u,"
|
||||
"%u): expected %u(second value), got %u\n",
|
||||
CONSTTIME_FALSE, a, b, b, selected);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_select_int(int a, int b)
|
||||
{
|
||||
int selected = constant_time_select_int(CONSTTIME_TRUE, a, b);
|
||||
if (selected != a) {
|
||||
fprintf(stderr, "Test failed for constant_time_select(%du, %d,"
|
||||
"%d): expected %d(first value), got %d\n",
|
||||
CONSTTIME_TRUE, a, b, a, selected);
|
||||
return 1;
|
||||
}
|
||||
selected = constant_time_select_int(CONSTTIME_FALSE, a, b);
|
||||
if (selected != b) {
|
||||
fprintf(stderr, "Test failed for constant_time_select(%du, %d,"
|
||||
"%d): expected %d(second value), got %d\n",
|
||||
CONSTTIME_FALSE, a, b, b, selected);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_eq_int(int a, int b)
|
||||
{
|
||||
unsigned int equal = constant_time_eq_int(a, b);
|
||||
if (a == b && equal != CONSTTIME_TRUE) {
|
||||
fprintf(stderr, "Test failed for constant_time_eq_int(%d, %d): "
|
||||
"expected %du(TRUE), got %du\n", a, b, CONSTTIME_TRUE, equal);
|
||||
return 1;
|
||||
} else if (a != b && equal != CONSTTIME_FALSE) {
|
||||
fprintf(stderr, "Test failed for constant_time_eq_int(%d, %d): "
|
||||
"expected %du(FALSE), got %du\n",
|
||||
a, b, CONSTTIME_FALSE, equal);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_eq_int_8(int a, int b)
|
||||
{
|
||||
unsigned char equal = constant_time_eq_int_8(a, b);
|
||||
if (a == b && equal != CONSTTIME_TRUE_8) {
|
||||
fprintf(stderr, "Test failed for constant_time_eq_int_8(%d, %d): "
|
||||
"expected %u(TRUE), got %u\n", a, b, CONSTTIME_TRUE_8, equal);
|
||||
return 1;
|
||||
} else if (a != b && equal != CONSTTIME_FALSE_8) {
|
||||
fprintf(stderr, "Test failed for constant_time_eq_int_8(%d, %d): "
|
||||
"expected %u(FALSE), got %u\n",
|
||||
a, b, CONSTTIME_FALSE_8, equal);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static unsigned int test_values[] =
|
||||
{ 0, 1, 1024, 12345, 32000, UINT_MAX / 2 - 1,
|
||||
UINT_MAX / 2, UINT_MAX / 2 + 1, UINT_MAX - 1,
|
||||
UINT_MAX
|
||||
};
|
||||
|
||||
static unsigned char test_values_8[] =
|
||||
{ 0, 1, 2, 20, 32, 127, 128, 129, 255 };
|
||||
|
||||
static int signed_test_values[] = { 0, 1, -1, 1024, -1024, 12345, -12345,
|
||||
32000, -32000, INT_MAX, INT_MIN, INT_MAX - 1,
|
||||
INT_MIN + 1
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
unsigned int a, b, i, j;
|
||||
int c, d;
|
||||
unsigned char e, f;
|
||||
int num_failed = 0, num_all = 0;
|
||||
fprintf(stdout, "Testing constant time operations...\n");
|
||||
|
||||
for (i = 0; i < sizeof(test_values) / sizeof(int); ++i) {
|
||||
a = test_values[i];
|
||||
num_failed += test_is_zero(a);
|
||||
num_failed += test_is_zero_8(a);
|
||||
num_all += 2;
|
||||
for (j = 0; j < sizeof(test_values) / sizeof(int); ++j) {
|
||||
b = test_values[j];
|
||||
num_failed += test_binary_op(&constant_time_lt,
|
||||
"constant_time_lt", a, b, a < b);
|
||||
num_failed += test_binary_op_8(&constant_time_lt_8,
|
||||
"constant_time_lt_8", a, b, a < b);
|
||||
num_failed += test_binary_op(&constant_time_lt,
|
||||
"constant_time_lt_8", b, a, b < a);
|
||||
num_failed += test_binary_op_8(&constant_time_lt_8,
|
||||
"constant_time_lt_8", b, a, b < a);
|
||||
num_failed += test_binary_op(&constant_time_ge,
|
||||
"constant_time_ge", a, b, a >= b);
|
||||
num_failed += test_binary_op_8(&constant_time_ge_8,
|
||||
"constant_time_ge_8", a, b,
|
||||
a >= b);
|
||||
num_failed +=
|
||||
test_binary_op(&constant_time_ge, "constant_time_ge", b, a,
|
||||
b >= a);
|
||||
num_failed +=
|
||||
test_binary_op_8(&constant_time_ge_8, "constant_time_ge_8", b,
|
||||
a, b >= a);
|
||||
num_failed +=
|
||||
test_binary_op(&constant_time_eq, "constant_time_eq", a, b,
|
||||
a == b);
|
||||
num_failed +=
|
||||
test_binary_op_8(&constant_time_eq_8, "constant_time_eq_8", a,
|
||||
b, a == b);
|
||||
num_failed +=
|
||||
test_binary_op(&constant_time_eq, "constant_time_eq", b, a,
|
||||
b == a);
|
||||
num_failed +=
|
||||
test_binary_op_8(&constant_time_eq_8, "constant_time_eq_8", b,
|
||||
a, b == a);
|
||||
num_failed += test_select(a, b);
|
||||
num_all += 13;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < sizeof(signed_test_values) / sizeof(int); ++i) {
|
||||
c = signed_test_values[i];
|
||||
for (j = 0; j < sizeof(signed_test_values) / sizeof(int); ++j) {
|
||||
d = signed_test_values[j];
|
||||
num_failed += test_select_int(c, d);
|
||||
num_failed += test_eq_int(c, d);
|
||||
num_failed += test_eq_int_8(c, d);
|
||||
num_all += 3;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < sizeof(test_values_8); ++i) {
|
||||
e = test_values_8[i];
|
||||
for (j = 0; j < sizeof(test_values_8); ++j) {
|
||||
f = test_values_8[j];
|
||||
num_failed += test_select_8(e, f);
|
||||
num_all += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!num_failed) {
|
||||
fprintf(stdout, "ok (ran %d tests)\n", num_all);
|
||||
return EXIT_SUCCESS;
|
||||
} else {
|
||||
fprintf(stdout, "%d of %d tests failed!\n", num_failed, num_all);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/des/destest.c
|
||||
@@ -0,0 +1,929 @@
|
||||
/* 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <openssl/e_os2.h>
|
||||
#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 <io.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
|
||||
#ifdef OPENSSL_NO_DES
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No DES support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/des.h>
|
||||
|
||||
# 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 < NUM_TESTS; i++) {
|
||||
DES_set_key_unchecked(&key_data[i], &ks);
|
||||
memcpy(in, plain_data[i], 8);
|
||||
memset(out, 0, 8);
|
||||
memset(outin, 0, 8);
|
||||
des_ecb_encrypt(&in, &out, ks, DES_ENCRYPT);
|
||||
des_ecb_encrypt(&out, &outin, ks, DES_DECRYPT);
|
||||
|
||||
if (memcmp(out, cipher_data[i], 8) != 0) {
|
||||
printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
|
||||
i + 1, pt(key_data[i]), pt(in), pt(cipher_data[i]),
|
||||
pt(out));
|
||||
err = 1;
|
||||
}
|
||||
if (memcmp(in, outin, 8) != 0) {
|
||||
printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
|
||||
i + 1, pt(key_data[i]), pt(out), pt(in), pt(outin));
|
||||
err = 1;
|
||||
}
|
||||
}
|
||||
|
||||
# ifndef LIBDES_LIT
|
||||
printf("Doing ede ecb\n");
|
||||
for (i = 0; i < (NUM_TESTS - 2); i++) {
|
||||
DES_set_key_unchecked(&key_data[i], &ks);
|
||||
DES_set_key_unchecked(&key_data[i + 1], &ks2);
|
||||
DES_set_key_unchecked(&key_data[i + 2], &ks3);
|
||||
memcpy(in, plain_data[i], 8);
|
||||
memset(out, 0, 8);
|
||||
memset(outin, 0, 8);
|
||||
des_ecb2_encrypt(&in, &out, ks, ks2, DES_ENCRYPT);
|
||||
des_ecb2_encrypt(&out, &outin, ks, ks2, DES_DECRYPT);
|
||||
|
||||
if (memcmp(out, cipher_ecb2[i], 8) != 0) {
|
||||
printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
|
||||
i + 1, pt(key_data[i]), pt(in), pt(cipher_ecb2[i]),
|
||||
pt(out));
|
||||
err = 1;
|
||||
}
|
||||
if (memcmp(in, outin, 8) != 0) {
|
||||
printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
|
||||
i + 1, pt(key_data[i]), pt(out), pt(in), pt(outin));
|
||||
err = 1;
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
printf("Doing cbc\n");
|
||||
if ((j = DES_set_key_checked(&cbc_key, &ks)) != 0) {
|
||||
printf("Key error %d\n", j);
|
||||
err = 1;
|
||||
}
|
||||
memset(cbc_out, 0, 40);
|
||||
memset(cbc_in, 0, 40);
|
||||
memcpy(iv3, cbc_iv, sizeof(cbc_iv));
|
||||
des_ncbc_encrypt(cbc_data, cbc_out, strlen((char *)cbc_data) + 1, ks,
|
||||
&iv3, DES_ENCRYPT);
|
||||
if (memcmp(cbc_out, cbc_ok, 32) != 0) {
|
||||
printf("cbc_encrypt encrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
|
||||
memcpy(iv3, cbc_iv, sizeof(cbc_iv));
|
||||
des_ncbc_encrypt(cbc_out, cbc_in, strlen((char *)cbc_data) + 1, ks,
|
||||
&iv3, DES_DECRYPT);
|
||||
if (memcmp(cbc_in, cbc_data, strlen((char *)cbc_data)) != 0) {
|
||||
printf("cbc_encrypt decrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
# ifndef LIBDES_LIT
|
||||
printf("Doing desx cbc\n");
|
||||
if ((j = DES_set_key_checked(&cbc_key, &ks)) != 0) {
|
||||
printf("Key error %d\n", j);
|
||||
err = 1;
|
||||
}
|
||||
memset(cbc_out, 0, 40);
|
||||
memset(cbc_in, 0, 40);
|
||||
memcpy(iv3, cbc_iv, sizeof(cbc_iv));
|
||||
des_xcbc_encrypt(cbc_data, cbc_out, strlen((char *)cbc_data) + 1, ks,
|
||||
&iv3, &cbc2_key, &cbc3_key, DES_ENCRYPT);
|
||||
if (memcmp(cbc_out, xcbc_ok, 32) != 0) {
|
||||
printf("des_xcbc_encrypt encrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
memcpy(iv3, cbc_iv, sizeof(cbc_iv));
|
||||
des_xcbc_encrypt(cbc_out, cbc_in, strlen((char *)cbc_data) + 1, ks,
|
||||
&iv3, &cbc2_key, &cbc3_key, DES_DECRYPT);
|
||||
if (memcmp(cbc_in, cbc_data, strlen((char *)cbc_data) + 1) != 0) {
|
||||
printf("des_xcbc_encrypt decrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
# endif
|
||||
|
||||
printf("Doing ede cbc\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));
|
||||
|
||||
des_ede3_cbc_encrypt(cbc_data, cbc_out, 16L, ks, ks2, ks3, &iv3,
|
||||
DES_ENCRYPT);
|
||||
des_ede3_cbc_encrypt(&(cbc_data[16]), &(cbc_out[16]), i - 16, ks, ks2,
|
||||
ks3, &iv3, DES_ENCRYPT);
|
||||
if (memcmp
|
||||
(cbc_out, cbc3_ok,
|
||||
(unsigned int)(strlen((char *)cbc_data) + 1 + 7) / 8 * 8) != 0) {
|
||||
unsigned int n;
|
||||
|
||||
printf("des_ede3_cbc_encrypt encrypt error\n");
|
||||
for (n = 0; n < i; ++n)
|
||||
printf(" %02x", cbc_out[n]);
|
||||
printf("\n");
|
||||
for (n = 0; n < i; ++n)
|
||||
printf(" %02x", cbc3_ok[n]);
|
||||
printf("\n");
|
||||
err = 1;
|
||||
}
|
||||
|
||||
memcpy(iv3, cbc_iv, sizeof(cbc_iv));
|
||||
des_ede3_cbc_encrypt(cbc_out, cbc_in, i, ks, ks2, ks3, &iv3, DES_DECRYPT);
|
||||
if (memcmp(cbc_in, cbc_data, strlen((char *)cbc_data) + 1) != 0) {
|
||||
unsigned int n;
|
||||
|
||||
printf("des_ede3_cbc_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;
|
||||
}
|
||||
# ifndef LIBDES_LIT
|
||||
printf("Doing pcbc\n");
|
||||
if ((j = DES_set_key_checked(&cbc_key, &ks)) != 0) {
|
||||
printf("Key error %d\n", j);
|
||||
err = 1;
|
||||
}
|
||||
memset(cbc_out, 0, 40);
|
||||
memset(cbc_in, 0, 40);
|
||||
des_pcbc_encrypt(cbc_data, cbc_out, strlen((char *)cbc_data) + 1, ks,
|
||||
&cbc_iv, DES_ENCRYPT);
|
||||
if (memcmp(cbc_out, pcbc_ok, 32) != 0) {
|
||||
printf("pcbc_encrypt encrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
des_pcbc_encrypt(cbc_out, cbc_in, strlen((char *)cbc_data) + 1, ks,
|
||||
&cbc_iv, DES_DECRYPT);
|
||||
if (memcmp(cbc_in, cbc_data, strlen((char *)cbc_data) + 1) != 0) {
|
||||
printf("pcbc_encrypt decrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
|
||||
printf("Doing ");
|
||||
printf("cfb8 ");
|
||||
err += cfb_test(8, cfb_cipher8);
|
||||
printf("cfb16 ");
|
||||
err += cfb_test(16, cfb_cipher16);
|
||||
printf("cfb32 ");
|
||||
err += cfb_test(32, cfb_cipher32);
|
||||
printf("cfb48 ");
|
||||
err += cfb_test(48, cfb_cipher48);
|
||||
printf("cfb64 ");
|
||||
err += cfb_test(64, cfb_cipher64);
|
||||
|
||||
printf("cfb64() ");
|
||||
err += cfb64_test(cfb_cipher64);
|
||||
|
||||
memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
|
||||
for (i = 0; i < sizeof(plain); i++)
|
||||
des_cfb_encrypt(&(plain[i]), &(cfb_buf1[i]),
|
||||
8, 1, ks, &cfb_tmp, DES_ENCRYPT);
|
||||
if (memcmp(cfb_cipher8, cfb_buf1, sizeof(plain)) != 0) {
|
||||
printf("cfb_encrypt small encrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
|
||||
memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
|
||||
for (i = 0; i < sizeof(plain); i++)
|
||||
des_cfb_encrypt(&(cfb_buf1[i]), &(cfb_buf2[i]),
|
||||
8, 1, ks, &cfb_tmp, DES_DECRYPT);
|
||||
if (memcmp(plain, cfb_buf2, sizeof(plain)) != 0) {
|
||||
printf("cfb_encrypt small decrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
|
||||
printf("ede_cfb64() ");
|
||||
err += ede_cfb64_test(cfb_cipher64);
|
||||
|
||||
printf("done\n");
|
||||
|
||||
printf("Doing ofb\n");
|
||||
DES_set_key_checked(&ofb_key, &ks);
|
||||
memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
|
||||
des_ofb_encrypt(plain, ofb_buf1, 64, sizeof(plain) / 8, ks, &ofb_tmp);
|
||||
if (memcmp(ofb_cipher, ofb_buf1, sizeof(ofb_buf1)) != 0) {
|
||||
printf("ofb_encrypt encrypt error\n");
|
||||
printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
|
||||
ofb_buf1[8 + 0], ofb_buf1[8 + 1], ofb_buf1[8 + 2],
|
||||
ofb_buf1[8 + 3], ofb_buf1[8 + 4], ofb_buf1[8 + 5],
|
||||
ofb_buf1[8 + 6], ofb_buf1[8 + 7]);
|
||||
printf("%02X %02X %02X %02X %02X %02X %02X %02X\n", ofb_buf1[8 + 0],
|
||||
ofb_cipher[8 + 1], ofb_cipher[8 + 2], ofb_cipher[8 + 3],
|
||||
ofb_buf1[8 + 4], ofb_cipher[8 + 5], ofb_cipher[8 + 6],
|
||||
ofb_cipher[8 + 7]);
|
||||
err = 1;
|
||||
}
|
||||
memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
|
||||
des_ofb_encrypt(ofb_buf1, ofb_buf2, 64, sizeof(ofb_buf1) / 8, ks,
|
||||
&ofb_tmp);
|
||||
if (memcmp(plain, ofb_buf2, sizeof(ofb_buf2)) != 0) {
|
||||
printf("ofb_encrypt decrypt error\n");
|
||||
printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
|
||||
ofb_buf2[8 + 0], ofb_buf2[8 + 1], ofb_buf2[8 + 2],
|
||||
ofb_buf2[8 + 3], ofb_buf2[8 + 4], ofb_buf2[8 + 5],
|
||||
ofb_buf2[8 + 6], ofb_buf2[8 + 7]);
|
||||
printf("%02X %02X %02X %02X %02X %02X %02X %02X\n", plain[8 + 0],
|
||||
plain[8 + 1], plain[8 + 2], plain[8 + 3], plain[8 + 4],
|
||||
plain[8 + 5], plain[8 + 6], plain[8 + 7]);
|
||||
err = 1;
|
||||
}
|
||||
|
||||
printf("Doing ofb64\n");
|
||||
DES_set_key_checked(&ofb_key, &ks);
|
||||
memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
|
||||
memset(ofb_buf1, 0, sizeof(ofb_buf1));
|
||||
memset(ofb_buf2, 0, sizeof(ofb_buf1));
|
||||
num = 0;
|
||||
for (i = 0; i < sizeof(plain); i++) {
|
||||
des_ofb64_encrypt(&(plain[i]), &(ofb_buf1[i]), 1, ks, &ofb_tmp, &num);
|
||||
}
|
||||
if (memcmp(ofb_cipher, ofb_buf1, sizeof(ofb_buf1)) != 0) {
|
||||
printf("ofb64_encrypt encrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
|
||||
num = 0;
|
||||
des_ofb64_encrypt(ofb_buf1, ofb_buf2, sizeof(ofb_buf1), ks, &ofb_tmp,
|
||||
&num);
|
||||
if (memcmp(plain, ofb_buf2, sizeof(ofb_buf2)) != 0) {
|
||||
printf("ofb64_encrypt decrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
|
||||
printf("Doing ede_ofb64\n");
|
||||
DES_set_key_checked(&ofb_key, &ks);
|
||||
memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
|
||||
memset(ofb_buf1, 0, sizeof(ofb_buf1));
|
||||
memset(ofb_buf2, 0, sizeof(ofb_buf1));
|
||||
num = 0;
|
||||
for (i = 0; i < sizeof(plain); i++) {
|
||||
des_ede3_ofb64_encrypt(&(plain[i]), &(ofb_buf1[i]), 1, ks, ks,
|
||||
ks, &ofb_tmp, &num);
|
||||
}
|
||||
if (memcmp(ofb_cipher, ofb_buf1, sizeof(ofb_buf1)) != 0) {
|
||||
printf("ede_ofb64_encrypt encrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
|
||||
num = 0;
|
||||
des_ede3_ofb64_encrypt(ofb_buf1, ofb_buf2, sizeof(ofb_buf1), ks, ks, ks,
|
||||
&ofb_tmp, &num);
|
||||
if (memcmp(plain, ofb_buf2, sizeof(ofb_buf2)) != 0) {
|
||||
printf("ede_ofb64_encrypt decrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
|
||||
printf("Doing cbc_cksum\n");
|
||||
DES_set_key_checked(&cbc_key, &ks);
|
||||
cs = des_cbc_cksum(cbc_data, &cret, strlen((char *)cbc_data), ks,
|
||||
&cbc_iv);
|
||||
if (cs != cbc_cksum_ret) {
|
||||
printf("bad return value (%08lX), should be %08lX\n",
|
||||
(unsigned long)cs, (unsigned long)cbc_cksum_ret);
|
||||
err = 1;
|
||||
}
|
||||
if (memcmp(cret, cbc_cksum_data, 8) != 0) {
|
||||
printf("bad cbc_cksum block returned\n");
|
||||
err = 1;
|
||||
}
|
||||
|
||||
printf("Doing quad_cksum\n");
|
||||
cs = des_quad_cksum(cbc_data, (des_cblock *)lqret,
|
||||
(long)strlen((char *)cbc_data), 2,
|
||||
(des_cblock *)cbc_iv);
|
||||
if (cs != 0x70d7a63aL) {
|
||||
printf("quad_cksum error, ret %08lx should be 70d7a63a\n",
|
||||
(unsigned long)cs);
|
||||
err = 1;
|
||||
}
|
||||
# ifdef _CRAY
|
||||
if (lqret[0].a != 0x327eba8dL) {
|
||||
printf("quad_cksum error, out[0] %08lx is not %08lx\n",
|
||||
(unsigned long)lqret[0].a, 0x327eba8dUL);
|
||||
err = 1;
|
||||
}
|
||||
if (lqret[0].b != 0x201a49ccL) {
|
||||
printf("quad_cksum error, out[1] %08lx is not %08lx\n",
|
||||
(unsigned long)lqret[0].b, 0x201a49ccUL);
|
||||
err = 1;
|
||||
}
|
||||
if (lqret[1].a != 0x70d7a63aL) {
|
||||
printf("quad_cksum error, out[2] %08lx is not %08lx\n",
|
||||
(unsigned long)lqret[1].a, 0x70d7a63aUL);
|
||||
err = 1;
|
||||
}
|
||||
if (lqret[1].b != 0x501c2c26L) {
|
||||
printf("quad_cksum error, out[3] %08lx is not %08lx\n",
|
||||
(unsigned long)lqret[1].b, 0x501c2c26UL);
|
||||
err = 1;
|
||||
}
|
||||
# else
|
||||
if (lqret[0] != 0x327eba8dL) {
|
||||
printf("quad_cksum error, out[0] %08lx is not %08lx\n",
|
||||
(unsigned long)lqret[0], 0x327eba8dUL);
|
||||
err = 1;
|
||||
}
|
||||
if (lqret[1] != 0x201a49ccL) {
|
||||
printf("quad_cksum error, out[1] %08lx is not %08lx\n",
|
||||
(unsigned long)lqret[1], 0x201a49ccUL);
|
||||
err = 1;
|
||||
}
|
||||
if (lqret[2] != 0x70d7a63aL) {
|
||||
printf("quad_cksum error, out[2] %08lx is not %08lx\n",
|
||||
(unsigned long)lqret[2], 0x70d7a63aUL);
|
||||
err = 1;
|
||||
}
|
||||
if (lqret[3] != 0x501c2c26L) {
|
||||
printf("quad_cksum error, out[3] %08lx is not %08lx\n",
|
||||
(unsigned long)lqret[3], 0x501c2c26UL);
|
||||
err = 1;
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
|
||||
printf("input word alignment test");
|
||||
for (i = 0; i < 4; i++) {
|
||||
printf(" %d", i);
|
||||
des_ncbc_encrypt(&(cbc_out[i]), cbc_in,
|
||||
strlen((char *)cbc_data) + 1, ks,
|
||||
&cbc_iv, DES_ENCRYPT);
|
||||
}
|
||||
printf("\noutput word alignment test");
|
||||
for (i = 0; i < 4; i++) {
|
||||
printf(" %d", i);
|
||||
des_ncbc_encrypt(cbc_out, &(cbc_in[i]),
|
||||
strlen((char *)cbc_data) + 1, ks,
|
||||
&cbc_iv, DES_ENCRYPT);
|
||||
}
|
||||
printf("\n");
|
||||
printf("fast crypt test ");
|
||||
str = crypt("testing", "ef");
|
||||
if (strcmp("efGnQx2725bI2", str) != 0) {
|
||||
printf("fast crypt error, %s should be efGnQx2725bI2\n", str);
|
||||
err = 1;
|
||||
}
|
||||
str = crypt("bca76;23", "yA");
|
||||
if (strcmp("yA1Rp/1hZXIJk", str) != 0) {
|
||||
printf("fast crypt error, %s should be yA1Rp/1hZXIJk\n", str);
|
||||
err = 1;
|
||||
}
|
||||
# ifdef OPENSSL_SYS_NETWARE
|
||||
if (err)
|
||||
printf("ERROR: %d\n", err);
|
||||
# endif
|
||||
printf("\n");
|
||||
return (err);
|
||||
}
|
||||
|
||||
static char *pt(unsigned char *p)
|
||||
{
|
||||
static char bufs[10][20];
|
||||
static int bnum = 0;
|
||||
char *ret;
|
||||
int i;
|
||||
static char *f = "0123456789ABCDEF";
|
||||
|
||||
ret = &(bufs[bnum++][0]);
|
||||
bnum %= 10;
|
||||
for (i = 0; i < 8; i++) {
|
||||
ret[i * 2] = f[(p[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
|
||||
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/dh/dhtest.c
|
||||
@@ -0,0 +1,564 @@
|
||||
/* 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#ifdef OPENSSL_NO_DH
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No DH support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/dh.h>
|
||||
|
||||
# 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";
|
||||
|
||||
static int run_rfc5114_tests(void);
|
||||
|
||||
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; i < aout; i++) {
|
||||
sprintf(buf, "%02X", abuf[i]);
|
||||
BIO_puts(out, buf);
|
||||
}
|
||||
BIO_puts(out, "\n");
|
||||
|
||||
blen = DH_size(b);
|
||||
bbuf = (unsigned char *)OPENSSL_malloc(blen);
|
||||
bout = DH_compute_key(bbuf, a->pub_key, b);
|
||||
|
||||
BIO_puts(out, "key2 =");
|
||||
for (i = 0; i < bout; i++) {
|
||||
sprintf(buf, "%02X", bbuf[i]);
|
||||
BIO_puts(out, buf);
|
||||
}
|
||||
BIO_puts(out, "\n");
|
||||
if ((aout < 4) || (bout != aout) || (memcmp(abuf, bbuf, aout) != 0)) {
|
||||
fprintf(stderr, "Error in DH routines\n");
|
||||
ret = 1;
|
||||
} else
|
||||
ret = 0;
|
||||
if (!run_rfc5114_tests())
|
||||
ret = 1;
|
||||
err:
|
||||
ERR_print_errors_fp(stderr);
|
||||
|
||||
if (abuf != NULL)
|
||||
OPENSSL_free(abuf);
|
||||
if (bbuf != NULL)
|
||||
OPENSSL_free(bbuf);
|
||||
if (b != NULL)
|
||||
DH_free(b);
|
||||
if (a != NULL)
|
||||
DH_free(a);
|
||||
BIO_free(out);
|
||||
# ifdef OPENSSL_SYS_NETWARE
|
||||
if (ret)
|
||||
printf("ERROR: %d\n", ret);
|
||||
# endif
|
||||
EXIT(ret);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
static int MS_CALLBACK cb(int p, int n, BN_GENCB *arg)
|
||||
{
|
||||
char c = '*';
|
||||
|
||||
if (p == 0)
|
||||
c = '.';
|
||||
if (p == 1)
|
||||
c = '+';
|
||||
if (p == 2)
|
||||
c = '*';
|
||||
if (p == 3)
|
||||
c = '\n';
|
||||
BIO_write(arg->arg, &c, 1);
|
||||
(void)BIO_flush(arg->arg);
|
||||
# ifdef LINT
|
||||
p = n;
|
||||
# endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Test data from RFC 5114 */
|
||||
|
||||
static const unsigned char dhtest_1024_160_xA[] = {
|
||||
0xB9, 0xA3, 0xB3, 0xAE, 0x8F, 0xEF, 0xC1, 0xA2, 0x93, 0x04, 0x96, 0x50,
|
||||
0x70, 0x86, 0xF8, 0x45, 0x5D, 0x48, 0x94, 0x3E
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_1024_160_yA[] = {
|
||||
0x2A, 0x85, 0x3B, 0x3D, 0x92, 0x19, 0x75, 0x01, 0xB9, 0x01, 0x5B, 0x2D,
|
||||
0xEB, 0x3E, 0xD8, 0x4F, 0x5E, 0x02, 0x1D, 0xCC, 0x3E, 0x52, 0xF1, 0x09,
|
||||
0xD3, 0x27, 0x3D, 0x2B, 0x75, 0x21, 0x28, 0x1C, 0xBA, 0xBE, 0x0E, 0x76,
|
||||
0xFF, 0x57, 0x27, 0xFA, 0x8A, 0xCC, 0xE2, 0x69, 0x56, 0xBA, 0x9A, 0x1F,
|
||||
0xCA, 0x26, 0xF2, 0x02, 0x28, 0xD8, 0x69, 0x3F, 0xEB, 0x10, 0x84, 0x1D,
|
||||
0x84, 0xA7, 0x36, 0x00, 0x54, 0xEC, 0xE5, 0xA7, 0xF5, 0xB7, 0xA6, 0x1A,
|
||||
0xD3, 0xDF, 0xB3, 0xC6, 0x0D, 0x2E, 0x43, 0x10, 0x6D, 0x87, 0x27, 0xDA,
|
||||
0x37, 0xDF, 0x9C, 0xCE, 0x95, 0xB4, 0x78, 0x75, 0x5D, 0x06, 0xBC, 0xEA,
|
||||
0x8F, 0x9D, 0x45, 0x96, 0x5F, 0x75, 0xA5, 0xF3, 0xD1, 0xDF, 0x37, 0x01,
|
||||
0x16, 0x5F, 0xC9, 0xE5, 0x0C, 0x42, 0x79, 0xCE, 0xB0, 0x7F, 0x98, 0x95,
|
||||
0x40, 0xAE, 0x96, 0xD5, 0xD8, 0x8E, 0xD7, 0x76
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_1024_160_xB[] = {
|
||||
0x93, 0x92, 0xC9, 0xF9, 0xEB, 0x6A, 0x7A, 0x6A, 0x90, 0x22, 0xF7, 0xD8,
|
||||
0x3E, 0x72, 0x23, 0xC6, 0x83, 0x5B, 0xBD, 0xDA
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_1024_160_yB[] = {
|
||||
0x71, 0x7A, 0x6C, 0xB0, 0x53, 0x37, 0x1F, 0xF4, 0xA3, 0xB9, 0x32, 0x94,
|
||||
0x1C, 0x1E, 0x56, 0x63, 0xF8, 0x61, 0xA1, 0xD6, 0xAD, 0x34, 0xAE, 0x66,
|
||||
0x57, 0x6D, 0xFB, 0x98, 0xF6, 0xC6, 0xCB, 0xF9, 0xDD, 0xD5, 0xA5, 0x6C,
|
||||
0x78, 0x33, 0xF6, 0xBC, 0xFD, 0xFF, 0x09, 0x55, 0x82, 0xAD, 0x86, 0x8E,
|
||||
0x44, 0x0E, 0x8D, 0x09, 0xFD, 0x76, 0x9E, 0x3C, 0xEC, 0xCD, 0xC3, 0xD3,
|
||||
0xB1, 0xE4, 0xCF, 0xA0, 0x57, 0x77, 0x6C, 0xAA, 0xF9, 0x73, 0x9B, 0x6A,
|
||||
0x9F, 0xEE, 0x8E, 0x74, 0x11, 0xF8, 0xD6, 0xDA, 0xC0, 0x9D, 0x6A, 0x4E,
|
||||
0xDB, 0x46, 0xCC, 0x2B, 0x5D, 0x52, 0x03, 0x09, 0x0E, 0xAE, 0x61, 0x26,
|
||||
0x31, 0x1E, 0x53, 0xFD, 0x2C, 0x14, 0xB5, 0x74, 0xE6, 0xA3, 0x10, 0x9A,
|
||||
0x3D, 0xA1, 0xBE, 0x41, 0xBD, 0xCE, 0xAA, 0x18, 0x6F, 0x5C, 0xE0, 0x67,
|
||||
0x16, 0xA2, 0xB6, 0xA0, 0x7B, 0x3C, 0x33, 0xFE
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_1024_160_Z[] = {
|
||||
0x5C, 0x80, 0x4F, 0x45, 0x4D, 0x30, 0xD9, 0xC4, 0xDF, 0x85, 0x27, 0x1F,
|
||||
0x93, 0x52, 0x8C, 0x91, 0xDF, 0x6B, 0x48, 0xAB, 0x5F, 0x80, 0xB3, 0xB5,
|
||||
0x9C, 0xAA, 0xC1, 0xB2, 0x8F, 0x8A, 0xCB, 0xA9, 0xCD, 0x3E, 0x39, 0xF3,
|
||||
0xCB, 0x61, 0x45, 0x25, 0xD9, 0x52, 0x1D, 0x2E, 0x64, 0x4C, 0x53, 0xB8,
|
||||
0x07, 0xB8, 0x10, 0xF3, 0x40, 0x06, 0x2F, 0x25, 0x7D, 0x7D, 0x6F, 0xBF,
|
||||
0xE8, 0xD5, 0xE8, 0xF0, 0x72, 0xE9, 0xB6, 0xE9, 0xAF, 0xDA, 0x94, 0x13,
|
||||
0xEA, 0xFB, 0x2E, 0x8B, 0x06, 0x99, 0xB1, 0xFB, 0x5A, 0x0C, 0xAC, 0xED,
|
||||
0xDE, 0xAE, 0xAD, 0x7E, 0x9C, 0xFB, 0xB3, 0x6A, 0xE2, 0xB4, 0x20, 0x83,
|
||||
0x5B, 0xD8, 0x3A, 0x19, 0xFB, 0x0B, 0x5E, 0x96, 0xBF, 0x8F, 0xA4, 0xD0,
|
||||
0x9E, 0x34, 0x55, 0x25, 0x16, 0x7E, 0xCD, 0x91, 0x55, 0x41, 0x6F, 0x46,
|
||||
0xF4, 0x08, 0xED, 0x31, 0xB6, 0x3C, 0x6E, 0x6D
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_2048_224_xA[] = {
|
||||
0x22, 0xE6, 0x26, 0x01, 0xDB, 0xFF, 0xD0, 0x67, 0x08, 0xA6, 0x80, 0xF7,
|
||||
0x47, 0xF3, 0x61, 0xF7, 0x6D, 0x8F, 0x4F, 0x72, 0x1A, 0x05, 0x48, 0xE4,
|
||||
0x83, 0x29, 0x4B, 0x0C
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_2048_224_yA[] = {
|
||||
0x1B, 0x3A, 0x63, 0x45, 0x1B, 0xD8, 0x86, 0xE6, 0x99, 0xE6, 0x7B, 0x49,
|
||||
0x4E, 0x28, 0x8B, 0xD7, 0xF8, 0xE0, 0xD3, 0x70, 0xBA, 0xDD, 0xA7, 0xA0,
|
||||
0xEF, 0xD2, 0xFD, 0xE7, 0xD8, 0xF6, 0x61, 0x45, 0xCC, 0x9F, 0x28, 0x04,
|
||||
0x19, 0x97, 0x5E, 0xB8, 0x08, 0x87, 0x7C, 0x8A, 0x4C, 0x0C, 0x8E, 0x0B,
|
||||
0xD4, 0x8D, 0x4A, 0x54, 0x01, 0xEB, 0x1E, 0x87, 0x76, 0xBF, 0xEE, 0xE1,
|
||||
0x34, 0xC0, 0x38, 0x31, 0xAC, 0x27, 0x3C, 0xD9, 0xD6, 0x35, 0xAB, 0x0C,
|
||||
0xE0, 0x06, 0xA4, 0x2A, 0x88, 0x7E, 0x3F, 0x52, 0xFB, 0x87, 0x66, 0xB6,
|
||||
0x50, 0xF3, 0x80, 0x78, 0xBC, 0x8E, 0xE8, 0x58, 0x0C, 0xEF, 0xE2, 0x43,
|
||||
0x96, 0x8C, 0xFC, 0x4F, 0x8D, 0xC3, 0xDB, 0x08, 0x45, 0x54, 0x17, 0x1D,
|
||||
0x41, 0xBF, 0x2E, 0x86, 0x1B, 0x7B, 0xB4, 0xD6, 0x9D, 0xD0, 0xE0, 0x1E,
|
||||
0xA3, 0x87, 0xCB, 0xAA, 0x5C, 0xA6, 0x72, 0xAF, 0xCB, 0xE8, 0xBD, 0xB9,
|
||||
0xD6, 0x2D, 0x4C, 0xE1, 0x5F, 0x17, 0xDD, 0x36, 0xF9, 0x1E, 0xD1, 0xEE,
|
||||
0xDD, 0x65, 0xCA, 0x4A, 0x06, 0x45, 0x5C, 0xB9, 0x4C, 0xD4, 0x0A, 0x52,
|
||||
0xEC, 0x36, 0x0E, 0x84, 0xB3, 0xC9, 0x26, 0xE2, 0x2C, 0x43, 0x80, 0xA3,
|
||||
0xBF, 0x30, 0x9D, 0x56, 0x84, 0x97, 0x68, 0xB7, 0xF5, 0x2C, 0xFD, 0xF6,
|
||||
0x55, 0xFD, 0x05, 0x3A, 0x7E, 0xF7, 0x06, 0x97, 0x9E, 0x7E, 0x58, 0x06,
|
||||
0xB1, 0x7D, 0xFA, 0xE5, 0x3A, 0xD2, 0xA5, 0xBC, 0x56, 0x8E, 0xBB, 0x52,
|
||||
0x9A, 0x7A, 0x61, 0xD6, 0x8D, 0x25, 0x6F, 0x8F, 0xC9, 0x7C, 0x07, 0x4A,
|
||||
0x86, 0x1D, 0x82, 0x7E, 0x2E, 0xBC, 0x8C, 0x61, 0x34, 0x55, 0x31, 0x15,
|
||||
0xB7, 0x0E, 0x71, 0x03, 0x92, 0x0A, 0xA1, 0x6D, 0x85, 0xE5, 0x2B, 0xCB,
|
||||
0xAB, 0x8D, 0x78, 0x6A, 0x68, 0x17, 0x8F, 0xA8, 0xFF, 0x7C, 0x2F, 0x5C,
|
||||
0x71, 0x64, 0x8D, 0x6F
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_2048_224_xB[] = {
|
||||
0x4F, 0xF3, 0xBC, 0x96, 0xC7, 0xFC, 0x6A, 0x6D, 0x71, 0xD3, 0xB3, 0x63,
|
||||
0x80, 0x0A, 0x7C, 0xDF, 0xEF, 0x6F, 0xC4, 0x1B, 0x44, 0x17, 0xEA, 0x15,
|
||||
0x35, 0x3B, 0x75, 0x90
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_2048_224_yB[] = {
|
||||
0x4D, 0xCE, 0xE9, 0x92, 0xA9, 0x76, 0x2A, 0x13, 0xF2, 0xF8, 0x38, 0x44,
|
||||
0xAD, 0x3D, 0x77, 0xEE, 0x0E, 0x31, 0xC9, 0x71, 0x8B, 0x3D, 0xB6, 0xC2,
|
||||
0x03, 0x5D, 0x39, 0x61, 0x18, 0x2C, 0x3E, 0x0B, 0xA2, 0x47, 0xEC, 0x41,
|
||||
0x82, 0xD7, 0x60, 0xCD, 0x48, 0xD9, 0x95, 0x99, 0x97, 0x06, 0x22, 0xA1,
|
||||
0x88, 0x1B, 0xBA, 0x2D, 0xC8, 0x22, 0x93, 0x9C, 0x78, 0xC3, 0x91, 0x2C,
|
||||
0x66, 0x61, 0xFA, 0x54, 0x38, 0xB2, 0x07, 0x66, 0x22, 0x2B, 0x75, 0xE2,
|
||||
0x4C, 0x2E, 0x3A, 0xD0, 0xC7, 0x28, 0x72, 0x36, 0x12, 0x95, 0x25, 0xEE,
|
||||
0x15, 0xB5, 0xDD, 0x79, 0x98, 0xAA, 0x04, 0xC4, 0xA9, 0x69, 0x6C, 0xAC,
|
||||
0xD7, 0x17, 0x20, 0x83, 0xA9, 0x7A, 0x81, 0x66, 0x4E, 0xAD, 0x2C, 0x47,
|
||||
0x9E, 0x44, 0x4E, 0x4C, 0x06, 0x54, 0xCC, 0x19, 0xE2, 0x8D, 0x77, 0x03,
|
||||
0xCE, 0xE8, 0xDA, 0xCD, 0x61, 0x26, 0xF5, 0xD6, 0x65, 0xEC, 0x52, 0xC6,
|
||||
0x72, 0x55, 0xDB, 0x92, 0x01, 0x4B, 0x03, 0x7E, 0xB6, 0x21, 0xA2, 0xAC,
|
||||
0x8E, 0x36, 0x5D, 0xE0, 0x71, 0xFF, 0xC1, 0x40, 0x0A, 0xCF, 0x07, 0x7A,
|
||||
0x12, 0x91, 0x3D, 0xD8, 0xDE, 0x89, 0x47, 0x34, 0x37, 0xAB, 0x7B, 0xA3,
|
||||
0x46, 0x74, 0x3C, 0x1B, 0x21, 0x5D, 0xD9, 0xC1, 0x21, 0x64, 0xA7, 0xE4,
|
||||
0x05, 0x31, 0x18, 0xD1, 0x99, 0xBE, 0xC8, 0xEF, 0x6F, 0xC5, 0x61, 0x17,
|
||||
0x0C, 0x84, 0xC8, 0x7D, 0x10, 0xEE, 0x9A, 0x67, 0x4A, 0x1F, 0xA8, 0xFF,
|
||||
0xE1, 0x3B, 0xDF, 0xBA, 0x1D, 0x44, 0xDE, 0x48, 0x94, 0x6D, 0x68, 0xDC,
|
||||
0x0C, 0xDD, 0x77, 0x76, 0x35, 0xA7, 0xAB, 0x5B, 0xFB, 0x1E, 0x4B, 0xB7,
|
||||
0xB8, 0x56, 0xF9, 0x68, 0x27, 0x73, 0x4C, 0x18, 0x41, 0x38, 0xE9, 0x15,
|
||||
0xD9, 0xC3, 0x00, 0x2E, 0xBC, 0xE5, 0x31, 0x20, 0x54, 0x6A, 0x7E, 0x20,
|
||||
0x02, 0x14, 0x2B, 0x6C
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_2048_224_Z[] = {
|
||||
0x34, 0xD9, 0xBD, 0xDC, 0x1B, 0x42, 0x17, 0x6C, 0x31, 0x3F, 0xEA, 0x03,
|
||||
0x4C, 0x21, 0x03, 0x4D, 0x07, 0x4A, 0x63, 0x13, 0xBB, 0x4E, 0xCD, 0xB3,
|
||||
0x70, 0x3F, 0xFF, 0x42, 0x45, 0x67, 0xA4, 0x6B, 0xDF, 0x75, 0x53, 0x0E,
|
||||
0xDE, 0x0A, 0x9D, 0xA5, 0x22, 0x9D, 0xE7, 0xD7, 0x67, 0x32, 0x28, 0x6C,
|
||||
0xBC, 0x0F, 0x91, 0xDA, 0x4C, 0x3C, 0x85, 0x2F, 0xC0, 0x99, 0xC6, 0x79,
|
||||
0x53, 0x1D, 0x94, 0xC7, 0x8A, 0xB0, 0x3D, 0x9D, 0xEC, 0xB0, 0xA4, 0xE4,
|
||||
0xCA, 0x8B, 0x2B, 0xB4, 0x59, 0x1C, 0x40, 0x21, 0xCF, 0x8C, 0xE3, 0xA2,
|
||||
0x0A, 0x54, 0x1D, 0x33, 0x99, 0x40, 0x17, 0xD0, 0x20, 0x0A, 0xE2, 0xC9,
|
||||
0x51, 0x6E, 0x2F, 0xF5, 0x14, 0x57, 0x79, 0x26, 0x9E, 0x86, 0x2B, 0x0F,
|
||||
0xB4, 0x74, 0xA2, 0xD5, 0x6D, 0xC3, 0x1E, 0xD5, 0x69, 0xA7, 0x70, 0x0B,
|
||||
0x4C, 0x4A, 0xB1, 0x6B, 0x22, 0xA4, 0x55, 0x13, 0x53, 0x1E, 0xF5, 0x23,
|
||||
0xD7, 0x12, 0x12, 0x07, 0x7B, 0x5A, 0x16, 0x9B, 0xDE, 0xFF, 0xAD, 0x7A,
|
||||
0xD9, 0x60, 0x82, 0x84, 0xC7, 0x79, 0x5B, 0x6D, 0x5A, 0x51, 0x83, 0xB8,
|
||||
0x70, 0x66, 0xDE, 0x17, 0xD8, 0xD6, 0x71, 0xC9, 0xEB, 0xD8, 0xEC, 0x89,
|
||||
0x54, 0x4D, 0x45, 0xEC, 0x06, 0x15, 0x93, 0xD4, 0x42, 0xC6, 0x2A, 0xB9,
|
||||
0xCE, 0x3B, 0x1C, 0xB9, 0x94, 0x3A, 0x1D, 0x23, 0xA5, 0xEA, 0x3B, 0xCF,
|
||||
0x21, 0xA0, 0x14, 0x71, 0xE6, 0x7E, 0x00, 0x3E, 0x7F, 0x8A, 0x69, 0xC7,
|
||||
0x28, 0xBE, 0x49, 0x0B, 0x2F, 0xC8, 0x8C, 0xFE, 0xB9, 0x2D, 0xB6, 0xA2,
|
||||
0x15, 0xE5, 0xD0, 0x3C, 0x17, 0xC4, 0x64, 0xC9, 0xAC, 0x1A, 0x46, 0xE2,
|
||||
0x03, 0xE1, 0x3F, 0x95, 0x29, 0x95, 0xFB, 0x03, 0xC6, 0x9D, 0x3C, 0xC4,
|
||||
0x7F, 0xCB, 0x51, 0x0B, 0x69, 0x98, 0xFF, 0xD3, 0xAA, 0x6D, 0xE7, 0x3C,
|
||||
0xF9, 0xF6, 0x38, 0x69
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_2048_256_xA[] = {
|
||||
0x08, 0x81, 0x38, 0x2C, 0xDB, 0x87, 0x66, 0x0C, 0x6D, 0xC1, 0x3E, 0x61,
|
||||
0x49, 0x38, 0xD5, 0xB9, 0xC8, 0xB2, 0xF2, 0x48, 0x58, 0x1C, 0xC5, 0xE3,
|
||||
0x1B, 0x35, 0x45, 0x43, 0x97, 0xFC, 0xE5, 0x0E
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_2048_256_yA[] = {
|
||||
0x2E, 0x93, 0x80, 0xC8, 0x32, 0x3A, 0xF9, 0x75, 0x45, 0xBC, 0x49, 0x41,
|
||||
0xDE, 0xB0, 0xEC, 0x37, 0x42, 0xC6, 0x2F, 0xE0, 0xEC, 0xE8, 0x24, 0xA6,
|
||||
0xAB, 0xDB, 0xE6, 0x6C, 0x59, 0xBE, 0xE0, 0x24, 0x29, 0x11, 0xBF, 0xB9,
|
||||
0x67, 0x23, 0x5C, 0xEB, 0xA3, 0x5A, 0xE1, 0x3E, 0x4E, 0xC7, 0x52, 0xBE,
|
||||
0x63, 0x0B, 0x92, 0xDC, 0x4B, 0xDE, 0x28, 0x47, 0xA9, 0xC6, 0x2C, 0xB8,
|
||||
0x15, 0x27, 0x45, 0x42, 0x1F, 0xB7, 0xEB, 0x60, 0xA6, 0x3C, 0x0F, 0xE9,
|
||||
0x15, 0x9F, 0xCC, 0xE7, 0x26, 0xCE, 0x7C, 0xD8, 0x52, 0x3D, 0x74, 0x50,
|
||||
0x66, 0x7E, 0xF8, 0x40, 0xE4, 0x91, 0x91, 0x21, 0xEB, 0x5F, 0x01, 0xC8,
|
||||
0xC9, 0xB0, 0xD3, 0xD6, 0x48, 0xA9, 0x3B, 0xFB, 0x75, 0x68, 0x9E, 0x82,
|
||||
0x44, 0xAC, 0x13, 0x4A, 0xF5, 0x44, 0x71, 0x1C, 0xE7, 0x9A, 0x02, 0xDC,
|
||||
0xC3, 0x42, 0x26, 0x68, 0x47, 0x80, 0xDD, 0xDC, 0xB4, 0x98, 0x59, 0x41,
|
||||
0x06, 0xC3, 0x7F, 0x5B, 0xC7, 0x98, 0x56, 0x48, 0x7A, 0xF5, 0xAB, 0x02,
|
||||
0x2A, 0x2E, 0x5E, 0x42, 0xF0, 0x98, 0x97, 0xC1, 0xA8, 0x5A, 0x11, 0xEA,
|
||||
0x02, 0x12, 0xAF, 0x04, 0xD9, 0xB4, 0xCE, 0xBC, 0x93, 0x7C, 0x3C, 0x1A,
|
||||
0x3E, 0x15, 0xA8, 0xA0, 0x34, 0x2E, 0x33, 0x76, 0x15, 0xC8, 0x4E, 0x7F,
|
||||
0xE3, 0xB8, 0xB9, 0xB8, 0x7F, 0xB1, 0xE7, 0x3A, 0x15, 0xAF, 0x12, 0xA3,
|
||||
0x0D, 0x74, 0x6E, 0x06, 0xDF, 0xC3, 0x4F, 0x29, 0x0D, 0x79, 0x7C, 0xE5,
|
||||
0x1A, 0xA1, 0x3A, 0xA7, 0x85, 0xBF, 0x66, 0x58, 0xAF, 0xF5, 0xE4, 0xB0,
|
||||
0x93, 0x00, 0x3C, 0xBE, 0xAF, 0x66, 0x5B, 0x3C, 0x2E, 0x11, 0x3A, 0x3A,
|
||||
0x4E, 0x90, 0x52, 0x69, 0x34, 0x1D, 0xC0, 0x71, 0x14, 0x26, 0x68, 0x5F,
|
||||
0x4E, 0xF3, 0x7E, 0x86, 0x8A, 0x81, 0x26, 0xFF, 0x3F, 0x22, 0x79, 0xB5,
|
||||
0x7C, 0xA6, 0x7E, 0x29
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_2048_256_xB[] = {
|
||||
0x7D, 0x62, 0xA7, 0xE3, 0xEF, 0x36, 0xDE, 0x61, 0x7B, 0x13, 0xD1, 0xAF,
|
||||
0xB8, 0x2C, 0x78, 0x0D, 0x83, 0xA2, 0x3B, 0xD4, 0xEE, 0x67, 0x05, 0x64,
|
||||
0x51, 0x21, 0xF3, 0x71, 0xF5, 0x46, 0xA5, 0x3D
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_2048_256_yB[] = {
|
||||
0x57, 0x5F, 0x03, 0x51, 0xBD, 0x2B, 0x1B, 0x81, 0x74, 0x48, 0xBD, 0xF8,
|
||||
0x7A, 0x6C, 0x36, 0x2C, 0x1E, 0x28, 0x9D, 0x39, 0x03, 0xA3, 0x0B, 0x98,
|
||||
0x32, 0xC5, 0x74, 0x1F, 0xA2, 0x50, 0x36, 0x3E, 0x7A, 0xCB, 0xC7, 0xF7,
|
||||
0x7F, 0x3D, 0xAC, 0xBC, 0x1F, 0x13, 0x1A, 0xDD, 0x8E, 0x03, 0x36, 0x7E,
|
||||
0xFF, 0x8F, 0xBB, 0xB3, 0xE1, 0xC5, 0x78, 0x44, 0x24, 0x80, 0x9B, 0x25,
|
||||
0xAF, 0xE4, 0xD2, 0x26, 0x2A, 0x1A, 0x6F, 0xD2, 0xFA, 0xB6, 0x41, 0x05,
|
||||
0xCA, 0x30, 0xA6, 0x74, 0xE0, 0x7F, 0x78, 0x09, 0x85, 0x20, 0x88, 0x63,
|
||||
0x2F, 0xC0, 0x49, 0x23, 0x37, 0x91, 0xAD, 0x4E, 0xDD, 0x08, 0x3A, 0x97,
|
||||
0x8B, 0x88, 0x3E, 0xE6, 0x18, 0xBC, 0x5E, 0x0D, 0xD0, 0x47, 0x41, 0x5F,
|
||||
0x2D, 0x95, 0xE6, 0x83, 0xCF, 0x14, 0x82, 0x6B, 0x5F, 0xBE, 0x10, 0xD3,
|
||||
0xCE, 0x41, 0xC6, 0xC1, 0x20, 0xC7, 0x8A, 0xB2, 0x00, 0x08, 0xC6, 0x98,
|
||||
0xBF, 0x7F, 0x0B, 0xCA, 0xB9, 0xD7, 0xF4, 0x07, 0xBE, 0xD0, 0xF4, 0x3A,
|
||||
0xFB, 0x29, 0x70, 0xF5, 0x7F, 0x8D, 0x12, 0x04, 0x39, 0x63, 0xE6, 0x6D,
|
||||
0xDD, 0x32, 0x0D, 0x59, 0x9A, 0xD9, 0x93, 0x6C, 0x8F, 0x44, 0x13, 0x7C,
|
||||
0x08, 0xB1, 0x80, 0xEC, 0x5E, 0x98, 0x5C, 0xEB, 0xE1, 0x86, 0xF3, 0xD5,
|
||||
0x49, 0x67, 0x7E, 0x80, 0x60, 0x73, 0x31, 0xEE, 0x17, 0xAF, 0x33, 0x80,
|
||||
0xA7, 0x25, 0xB0, 0x78, 0x23, 0x17, 0xD7, 0xDD, 0x43, 0xF5, 0x9D, 0x7A,
|
||||
0xF9, 0x56, 0x8A, 0x9B, 0xB6, 0x3A, 0x84, 0xD3, 0x65, 0xF9, 0x22, 0x44,
|
||||
0xED, 0x12, 0x09, 0x88, 0x21, 0x93, 0x02, 0xF4, 0x29, 0x24, 0xC7, 0xCA,
|
||||
0x90, 0xB8, 0x9D, 0x24, 0xF7, 0x1B, 0x0A, 0xB6, 0x97, 0x82, 0x3D, 0x7D,
|
||||
0xEB, 0x1A, 0xFF, 0x5B, 0x0E, 0x8E, 0x4A, 0x45, 0xD4, 0x9F, 0x7F, 0x53,
|
||||
0x75, 0x7E, 0x19, 0x13
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_2048_256_Z[] = {
|
||||
0x86, 0xC7, 0x0B, 0xF8, 0xD0, 0xBB, 0x81, 0xBB, 0x01, 0x07, 0x8A, 0x17,
|
||||
0x21, 0x9C, 0xB7, 0xD2, 0x72, 0x03, 0xDB, 0x2A, 0x19, 0xC8, 0x77, 0xF1,
|
||||
0xD1, 0xF1, 0x9F, 0xD7, 0xD7, 0x7E, 0xF2, 0x25, 0x46, 0xA6, 0x8F, 0x00,
|
||||
0x5A, 0xD5, 0x2D, 0xC8, 0x45, 0x53, 0xB7, 0x8F, 0xC6, 0x03, 0x30, 0xBE,
|
||||
0x51, 0xEA, 0x7C, 0x06, 0x72, 0xCA, 0xC1, 0x51, 0x5E, 0x4B, 0x35, 0xC0,
|
||||
0x47, 0xB9, 0xA5, 0x51, 0xB8, 0x8F, 0x39, 0xDC, 0x26, 0xDA, 0x14, 0xA0,
|
||||
0x9E, 0xF7, 0x47, 0x74, 0xD4, 0x7C, 0x76, 0x2D, 0xD1, 0x77, 0xF9, 0xED,
|
||||
0x5B, 0xC2, 0xF1, 0x1E, 0x52, 0xC8, 0x79, 0xBD, 0x95, 0x09, 0x85, 0x04,
|
||||
0xCD, 0x9E, 0xEC, 0xD8, 0xA8, 0xF9, 0xB3, 0xEF, 0xBD, 0x1F, 0x00, 0x8A,
|
||||
0xC5, 0x85, 0x30, 0x97, 0xD9, 0xD1, 0x83, 0x7F, 0x2B, 0x18, 0xF7, 0x7C,
|
||||
0xD7, 0xBE, 0x01, 0xAF, 0x80, 0xA7, 0xC7, 0xB5, 0xEA, 0x3C, 0xA5, 0x4C,
|
||||
0xC0, 0x2D, 0x0C, 0x11, 0x6F, 0xEE, 0x3F, 0x95, 0xBB, 0x87, 0x39, 0x93,
|
||||
0x85, 0x87, 0x5D, 0x7E, 0x86, 0x74, 0x7E, 0x67, 0x6E, 0x72, 0x89, 0x38,
|
||||
0xAC, 0xBF, 0xF7, 0x09, 0x8E, 0x05, 0xBE, 0x4D, 0xCF, 0xB2, 0x40, 0x52,
|
||||
0xB8, 0x3A, 0xEF, 0xFB, 0x14, 0x78, 0x3F, 0x02, 0x9A, 0xDB, 0xDE, 0x7F,
|
||||
0x53, 0xFA, 0xE9, 0x20, 0x84, 0x22, 0x40, 0x90, 0xE0, 0x07, 0xCE, 0xE9,
|
||||
0x4D, 0x4B, 0xF2, 0xBA, 0xCE, 0x9F, 0xFD, 0x4B, 0x57, 0xD2, 0xAF, 0x7C,
|
||||
0x72, 0x4D, 0x0C, 0xAA, 0x19, 0xBF, 0x05, 0x01, 0xF6, 0xF1, 0x7B, 0x4A,
|
||||
0xA1, 0x0F, 0x42, 0x5E, 0x3E, 0xA7, 0x60, 0x80, 0xB4, 0xB9, 0xD6, 0xB3,
|
||||
0xCE, 0xFE, 0xA1, 0x15, 0xB2, 0xCE, 0xB8, 0x78, 0x9B, 0xB8, 0xA3, 0xB0,
|
||||
0xEA, 0x87, 0xFE, 0xBE, 0x63, 0xB6, 0xC8, 0xF8, 0x46, 0xEC, 0x6D, 0xB0,
|
||||
0xC2, 0x6C, 0x5D, 0x7C
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
DH *(*get_param) (void);
|
||||
const unsigned char *xA;
|
||||
size_t xA_len;
|
||||
const unsigned char *yA;
|
||||
size_t yA_len;
|
||||
const unsigned char *xB;
|
||||
size_t xB_len;
|
||||
const unsigned char *yB;
|
||||
size_t yB_len;
|
||||
const unsigned char *Z;
|
||||
size_t Z_len;
|
||||
} rfc5114_td;
|
||||
|
||||
# define make_rfc5114_td(pre) { \
|
||||
DH_get_##pre, \
|
||||
dhtest_##pre##_xA, sizeof(dhtest_##pre##_xA), \
|
||||
dhtest_##pre##_yA, sizeof(dhtest_##pre##_yA), \
|
||||
dhtest_##pre##_xB, sizeof(dhtest_##pre##_xB), \
|
||||
dhtest_##pre##_yB, sizeof(dhtest_##pre##_yB), \
|
||||
dhtest_##pre##_Z, sizeof(dhtest_##pre##_Z) \
|
||||
}
|
||||
|
||||
static const rfc5114_td rfctd[] = {
|
||||
make_rfc5114_td(1024_160),
|
||||
make_rfc5114_td(2048_224),
|
||||
make_rfc5114_td(2048_256)
|
||||
};
|
||||
|
||||
static int run_rfc5114_tests(void)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < (int)(sizeof(rfctd) / sizeof(rfc5114_td)); i++) {
|
||||
DH *dhA, *dhB;
|
||||
unsigned char *Z1 = NULL, *Z2 = NULL;
|
||||
const rfc5114_td *td = rfctd + i;
|
||||
/* Set up DH structures setting key components */
|
||||
dhA = td->get_param();
|
||||
dhB = td->get_param();
|
||||
if (!dhA || !dhB)
|
||||
goto bad_err;
|
||||
|
||||
dhA->priv_key = BN_bin2bn(td->xA, td->xA_len, NULL);
|
||||
dhA->pub_key = BN_bin2bn(td->yA, td->yA_len, NULL);
|
||||
|
||||
dhB->priv_key = BN_bin2bn(td->xB, td->xB_len, NULL);
|
||||
dhB->pub_key = BN_bin2bn(td->yB, td->yB_len, NULL);
|
||||
|
||||
if (!dhA->priv_key || !dhA->pub_key
|
||||
|| !dhB->priv_key || !dhB->pub_key)
|
||||
goto bad_err;
|
||||
|
||||
if ((td->Z_len != (size_t)DH_size(dhA))
|
||||
|| (td->Z_len != (size_t)DH_size(dhB)))
|
||||
goto err;
|
||||
|
||||
Z1 = OPENSSL_malloc(DH_size(dhA));
|
||||
Z2 = OPENSSL_malloc(DH_size(dhB));
|
||||
/*
|
||||
* Work out shared secrets using both sides and compare with expected
|
||||
* values.
|
||||
*/
|
||||
if (!DH_compute_key(Z1, dhB->pub_key, dhA))
|
||||
goto bad_err;
|
||||
if (!DH_compute_key(Z2, dhA->pub_key, dhB))
|
||||
goto bad_err;
|
||||
|
||||
if (memcmp(Z1, td->Z, td->Z_len))
|
||||
goto err;
|
||||
if (memcmp(Z2, td->Z, td->Z_len))
|
||||
goto err;
|
||||
|
||||
printf("RFC5114 parameter test %d OK\n", i + 1);
|
||||
|
||||
DH_free(dhA);
|
||||
DH_free(dhB);
|
||||
OPENSSL_free(Z1);
|
||||
OPENSSL_free(Z2);
|
||||
|
||||
}
|
||||
return 1;
|
||||
bad_err:
|
||||
fprintf(stderr, "Initalisation error RFC5114 set %d\n", i + 1);
|
||||
ERR_print_errors_fp(stderr);
|
||||
return 0;
|
||||
err:
|
||||
fprintf(stderr, "Test failed RFC5114 set %d\n", i + 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/dsa/dsatest.c
|
||||
@@ -0,0 +1,268 @@
|
||||
/* 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/bn.h>
|
||||
|
||||
#ifdef OPENSSL_NO_DSA
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No DSA support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/dsa.h>
|
||||
|
||||
# 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
|
||||
Executable → Regular
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/ecdh/ecdhtest.c
|
||||
@@ -0,0 +1,580 @@
|
||||
/* 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
#include <openssl/opensslconf.h> /* for OPENSSL_NO_ECDH */
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#ifdef OPENSSL_NO_ECDH
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No ECDH support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/ec.h>
|
||||
# include <openssl/ecdh.h>
|
||||
|
||||
# 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 < aout; i++) {
|
||||
sprintf(buf, "%02X", abuf[i]);
|
||||
BIO_puts(out, buf);
|
||||
}
|
||||
BIO_puts(out, "\n");
|
||||
# else
|
||||
BIO_printf(out, ".");
|
||||
(void)BIO_flush(out);
|
||||
# endif
|
||||
|
||||
blen = KDF1_SHA1_len;
|
||||
bbuf = (unsigned char *)OPENSSL_malloc(blen);
|
||||
bout =
|
||||
ECDH_compute_key(bbuf, blen, EC_KEY_get0_public_key(a), b, KDF1_SHA1);
|
||||
|
||||
# ifdef NOISY
|
||||
BIO_puts(out, " key2 =");
|
||||
for (i = 0; i < bout; i++) {
|
||||
sprintf(buf, "%02X", bbuf[i]);
|
||||
BIO_puts(out, buf);
|
||||
}
|
||||
BIO_puts(out, "\n");
|
||||
# else
|
||||
BIO_printf(out, ".");
|
||||
(void)BIO_flush(out);
|
||||
# endif
|
||||
|
||||
if ((aout < 4) || (bout != aout) || (memcmp(abuf, bbuf, aout) != 0)) {
|
||||
# ifndef NOISY
|
||||
BIO_printf(out, " failed\n\n");
|
||||
BIO_printf(out, "key a:\n");
|
||||
BIO_printf(out, "private key: ");
|
||||
BN_print(out, EC_KEY_get0_private_key(a));
|
||||
BIO_printf(out, "\n");
|
||||
BIO_printf(out, "public key (x,y): ");
|
||||
BN_print(out, x_a);
|
||||
BIO_printf(out, ",");
|
||||
BN_print(out, y_a);
|
||||
BIO_printf(out, "\nkey b:\n");
|
||||
BIO_printf(out, "private key: ");
|
||||
BN_print(out, EC_KEY_get0_private_key(b));
|
||||
BIO_printf(out, "\n");
|
||||
BIO_printf(out, "public key (x,y): ");
|
||||
BN_print(out, x_b);
|
||||
BIO_printf(out, ",");
|
||||
BN_print(out, y_b);
|
||||
BIO_printf(out, "\n");
|
||||
BIO_printf(out, "generated key a: ");
|
||||
for (i = 0; i < bout; i++) {
|
||||
sprintf(buf, "%02X", bbuf[i]);
|
||||
BIO_puts(out, buf);
|
||||
}
|
||||
BIO_printf(out, "\n");
|
||||
BIO_printf(out, "generated key b: ");
|
||||
for (i = 0; i < aout; i++) {
|
||||
sprintf(buf, "%02X", abuf[i]);
|
||||
BIO_puts(out, buf);
|
||||
}
|
||||
BIO_printf(out, "\n");
|
||||
# endif
|
||||
fprintf(stderr, "Error in ECDH routines\n");
|
||||
ret = 0;
|
||||
} else {
|
||||
# ifndef NOISY
|
||||
BIO_printf(out, " ok\n");
|
||||
# endif
|
||||
ret = 1;
|
||||
}
|
||||
err:
|
||||
ERR_print_errors_fp(stderr);
|
||||
|
||||
if (abuf != NULL)
|
||||
OPENSSL_free(abuf);
|
||||
if (bbuf != NULL)
|
||||
OPENSSL_free(bbuf);
|
||||
if (x_a)
|
||||
BN_free(x_a);
|
||||
if (y_a)
|
||||
BN_free(y_a);
|
||||
if (x_b)
|
||||
BN_free(x_b);
|
||||
if (y_b)
|
||||
BN_free(y_b);
|
||||
if (b)
|
||||
EC_KEY_free(b);
|
||||
if (a)
|
||||
EC_KEY_free(a);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/* Keys and shared secrets from RFC 7027 */
|
||||
|
||||
static const unsigned char bp256_da[] = {
|
||||
0x81, 0xDB, 0x1E, 0xE1, 0x00, 0x15, 0x0F, 0xF2, 0xEA, 0x33, 0x8D, 0x70,
|
||||
0x82, 0x71, 0xBE, 0x38, 0x30, 0x0C, 0xB5, 0x42, 0x41, 0xD7, 0x99, 0x50,
|
||||
0xF7, 0x7B, 0x06, 0x30, 0x39, 0x80, 0x4F, 0x1D
|
||||
};
|
||||
|
||||
static const unsigned char bp256_db[] = {
|
||||
0x55, 0xE4, 0x0B, 0xC4, 0x1E, 0x37, 0xE3, 0xE2, 0xAD, 0x25, 0xC3, 0xC6,
|
||||
0x65, 0x45, 0x11, 0xFF, 0xA8, 0x47, 0x4A, 0x91, 0xA0, 0x03, 0x20, 0x87,
|
||||
0x59, 0x38, 0x52, 0xD3, 0xE7, 0xD7, 0x6B, 0xD3
|
||||
};
|
||||
|
||||
static const unsigned char bp256_Z[] = {
|
||||
0x89, 0xAF, 0xC3, 0x9D, 0x41, 0xD3, 0xB3, 0x27, 0x81, 0x4B, 0x80, 0x94,
|
||||
0x0B, 0x04, 0x25, 0x90, 0xF9, 0x65, 0x56, 0xEC, 0x91, 0xE6, 0xAE, 0x79,
|
||||
0x39, 0xBC, 0xE3, 0x1F, 0x3A, 0x18, 0xBF, 0x2B
|
||||
};
|
||||
|
||||
static const unsigned char bp384_da[] = {
|
||||
0x1E, 0x20, 0xF5, 0xE0, 0x48, 0xA5, 0x88, 0x6F, 0x1F, 0x15, 0x7C, 0x74,
|
||||
0xE9, 0x1B, 0xDE, 0x2B, 0x98, 0xC8, 0xB5, 0x2D, 0x58, 0xE5, 0x00, 0x3D,
|
||||
0x57, 0x05, 0x3F, 0xC4, 0xB0, 0xBD, 0x65, 0xD6, 0xF1, 0x5E, 0xB5, 0xD1,
|
||||
0xEE, 0x16, 0x10, 0xDF, 0x87, 0x07, 0x95, 0x14, 0x36, 0x27, 0xD0, 0x42
|
||||
};
|
||||
|
||||
static const unsigned char bp384_db[] = {
|
||||
0x03, 0x26, 0x40, 0xBC, 0x60, 0x03, 0xC5, 0x92, 0x60, 0xF7, 0x25, 0x0C,
|
||||
0x3D, 0xB5, 0x8C, 0xE6, 0x47, 0xF9, 0x8E, 0x12, 0x60, 0xAC, 0xCE, 0x4A,
|
||||
0xCD, 0xA3, 0xDD, 0x86, 0x9F, 0x74, 0xE0, 0x1F, 0x8B, 0xA5, 0xE0, 0x32,
|
||||
0x43, 0x09, 0xDB, 0x6A, 0x98, 0x31, 0x49, 0x7A, 0xBA, 0xC9, 0x66, 0x70
|
||||
};
|
||||
|
||||
static const unsigned char bp384_Z[] = {
|
||||
0x0B, 0xD9, 0xD3, 0xA7, 0xEA, 0x0B, 0x3D, 0x51, 0x9D, 0x09, 0xD8, 0xE4,
|
||||
0x8D, 0x07, 0x85, 0xFB, 0x74, 0x4A, 0x6B, 0x35, 0x5E, 0x63, 0x04, 0xBC,
|
||||
0x51, 0xC2, 0x29, 0xFB, 0xBC, 0xE2, 0x39, 0xBB, 0xAD, 0xF6, 0x40, 0x37,
|
||||
0x15, 0xC3, 0x5D, 0x4F, 0xB2, 0xA5, 0x44, 0x4F, 0x57, 0x5D, 0x4F, 0x42
|
||||
};
|
||||
|
||||
static const unsigned char bp512_da[] = {
|
||||
0x16, 0x30, 0x2F, 0xF0, 0xDB, 0xBB, 0x5A, 0x8D, 0x73, 0x3D, 0xAB, 0x71,
|
||||
0x41, 0xC1, 0xB4, 0x5A, 0xCB, 0xC8, 0x71, 0x59, 0x39, 0x67, 0x7F, 0x6A,
|
||||
0x56, 0x85, 0x0A, 0x38, 0xBD, 0x87, 0xBD, 0x59, 0xB0, 0x9E, 0x80, 0x27,
|
||||
0x96, 0x09, 0xFF, 0x33, 0x3E, 0xB9, 0xD4, 0xC0, 0x61, 0x23, 0x1F, 0xB2,
|
||||
0x6F, 0x92, 0xEE, 0xB0, 0x49, 0x82, 0xA5, 0xF1, 0xD1, 0x76, 0x4C, 0xAD,
|
||||
0x57, 0x66, 0x54, 0x22
|
||||
};
|
||||
|
||||
static const unsigned char bp512_db[] = {
|
||||
0x23, 0x0E, 0x18, 0xE1, 0xBC, 0xC8, 0x8A, 0x36, 0x2F, 0xA5, 0x4E, 0x4E,
|
||||
0xA3, 0x90, 0x20, 0x09, 0x29, 0x2F, 0x7F, 0x80, 0x33, 0x62, 0x4F, 0xD4,
|
||||
0x71, 0xB5, 0xD8, 0xAC, 0xE4, 0x9D, 0x12, 0xCF, 0xAB, 0xBC, 0x19, 0x96,
|
||||
0x3D, 0xAB, 0x8E, 0x2F, 0x1E, 0xBA, 0x00, 0xBF, 0xFB, 0x29, 0xE4, 0xD7,
|
||||
0x2D, 0x13, 0xF2, 0x22, 0x45, 0x62, 0xF4, 0x05, 0xCB, 0x80, 0x50, 0x36,
|
||||
0x66, 0xB2, 0x54, 0x29
|
||||
};
|
||||
|
||||
static const unsigned char bp512_Z[] = {
|
||||
0xA7, 0x92, 0x70, 0x98, 0x65, 0x5F, 0x1F, 0x99, 0x76, 0xFA, 0x50, 0xA9,
|
||||
0xD5, 0x66, 0x86, 0x5D, 0xC5, 0x30, 0x33, 0x18, 0x46, 0x38, 0x1C, 0x87,
|
||||
0x25, 0x6B, 0xAF, 0x32, 0x26, 0x24, 0x4B, 0x76, 0xD3, 0x64, 0x03, 0xC0,
|
||||
0x24, 0xD7, 0xBB, 0xF0, 0xAA, 0x08, 0x03, 0xEA, 0xFF, 0x40, 0x5D, 0x3D,
|
||||
0x24, 0xF1, 0x1A, 0x9B, 0x5C, 0x0B, 0xEF, 0x67, 0x9F, 0xE1, 0x45, 0x4B,
|
||||
0x21, 0xC4, 0xCD, 0x1F
|
||||
};
|
||||
|
||||
/* Given private value and NID, create EC_KEY structure */
|
||||
|
||||
static EC_KEY *mk_eckey(int nid, const unsigned char *p, size_t plen)
|
||||
{
|
||||
int ok = 0;
|
||||
EC_KEY *k = NULL;
|
||||
BIGNUM *priv = NULL;
|
||||
EC_POINT *pub = NULL;
|
||||
const EC_GROUP *grp;
|
||||
k = EC_KEY_new_by_curve_name(nid);
|
||||
if (!k)
|
||||
goto err;
|
||||
priv = BN_bin2bn(p, plen, NULL);
|
||||
if (!priv)
|
||||
goto err;
|
||||
if (!EC_KEY_set_private_key(k, priv))
|
||||
goto err;
|
||||
grp = EC_KEY_get0_group(k);
|
||||
pub = EC_POINT_new(grp);
|
||||
if (!pub)
|
||||
goto err;
|
||||
if (!EC_POINT_mul(grp, pub, priv, NULL, NULL, NULL))
|
||||
goto err;
|
||||
if (!EC_KEY_set_public_key(k, pub))
|
||||
goto err;
|
||||
ok = 1;
|
||||
err:
|
||||
if (priv)
|
||||
BN_clear_free(priv);
|
||||
if (pub)
|
||||
EC_POINT_free(pub);
|
||||
if (ok)
|
||||
return k;
|
||||
else if (k)
|
||||
EC_KEY_free(k);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Known answer test: compute shared secret and check it matches expected
|
||||
* value.
|
||||
*/
|
||||
|
||||
static int ecdh_kat(BIO *out, const char *cname, int nid,
|
||||
const unsigned char *k1, size_t k1_len,
|
||||
const unsigned char *k2, size_t k2_len,
|
||||
const unsigned char *Z, size_t Zlen)
|
||||
{
|
||||
int rv = 0;
|
||||
EC_KEY *key1 = NULL, *key2 = NULL;
|
||||
unsigned char *Ztmp = NULL;
|
||||
size_t Ztmplen;
|
||||
BIO_puts(out, "Testing ECDH shared secret with ");
|
||||
BIO_puts(out, cname);
|
||||
key1 = mk_eckey(nid, k1, k1_len);
|
||||
key2 = mk_eckey(nid, k2, k2_len);
|
||||
if (!key1 || !key2)
|
||||
goto err;
|
||||
Ztmplen = (EC_GROUP_get_degree(EC_KEY_get0_group(key1)) + 7) / 8;
|
||||
if (Ztmplen != Zlen)
|
||||
goto err;
|
||||
Ztmp = OPENSSL_malloc(Ztmplen);
|
||||
if (!ECDH_compute_key(Ztmp, Ztmplen,
|
||||
EC_KEY_get0_public_key(key2), key1, 0))
|
||||
goto err;
|
||||
if (memcmp(Ztmp, Z, Zlen))
|
||||
goto err;
|
||||
memset(Ztmp, 0, Zlen);
|
||||
if (!ECDH_compute_key(Ztmp, Ztmplen,
|
||||
EC_KEY_get0_public_key(key1), key2, 0))
|
||||
goto err;
|
||||
if (memcmp(Ztmp, Z, Zlen))
|
||||
goto err;
|
||||
rv = 1;
|
||||
err:
|
||||
if (key1)
|
||||
EC_KEY_free(key1);
|
||||
if (key2)
|
||||
EC_KEY_free(key2);
|
||||
if (Ztmp)
|
||||
OPENSSL_free(Ztmp);
|
||||
if (rv)
|
||||
BIO_puts(out, " ok\n");
|
||||
else {
|
||||
fprintf(stderr, "Error in ECDH routines\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
# define test_ecdh_kat(bio, curve, bits) \
|
||||
ecdh_kat(bio, curve, NID_brainpoolP##bits##r1, \
|
||||
bp##bits##_da, sizeof(bp##bits##_da), \
|
||||
bp##bits##_db, sizeof(bp##bits##_db), \
|
||||
bp##bits##_Z, sizeof(bp##bits##_Z))
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
BN_CTX *ctx = NULL;
|
||||
int 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);
|
||||
|
||||
if ((ctx = BN_CTX_new()) == NULL)
|
||||
goto err;
|
||||
|
||||
/* NIST PRIME CURVES TESTS */
|
||||
if (!test_ecdh_curve
|
||||
(NID_X9_62_prime192v1, "NIST Prime-Curve P-192", ctx, out))
|
||||
goto err;
|
||||
if (!test_ecdh_curve(NID_secp224r1, "NIST Prime-Curve P-224", ctx, out))
|
||||
goto err;
|
||||
if (!test_ecdh_curve
|
||||
(NID_X9_62_prime256v1, "NIST Prime-Curve P-256", ctx, out))
|
||||
goto err;
|
||||
if (!test_ecdh_curve(NID_secp384r1, "NIST Prime-Curve P-384", ctx, out))
|
||||
goto err;
|
||||
if (!test_ecdh_curve(NID_secp521r1, "NIST Prime-Curve P-521", ctx, out))
|
||||
goto err;
|
||||
# ifndef OPENSSL_NO_EC2M
|
||||
/* NIST BINARY CURVES TESTS */
|
||||
if (!test_ecdh_curve(NID_sect163k1, "NIST Binary-Curve K-163", ctx, out))
|
||||
goto err;
|
||||
if (!test_ecdh_curve(NID_sect163r2, "NIST Binary-Curve B-163", ctx, out))
|
||||
goto err;
|
||||
if (!test_ecdh_curve(NID_sect233k1, "NIST Binary-Curve K-233", ctx, out))
|
||||
goto err;
|
||||
if (!test_ecdh_curve(NID_sect233r1, "NIST Binary-Curve B-233", ctx, out))
|
||||
goto err;
|
||||
if (!test_ecdh_curve(NID_sect283k1, "NIST Binary-Curve K-283", ctx, out))
|
||||
goto err;
|
||||
if (!test_ecdh_curve(NID_sect283r1, "NIST Binary-Curve B-283", ctx, out))
|
||||
goto err;
|
||||
if (!test_ecdh_curve(NID_sect409k1, "NIST Binary-Curve K-409", ctx, out))
|
||||
goto err;
|
||||
if (!test_ecdh_curve(NID_sect409r1, "NIST Binary-Curve B-409", ctx, out))
|
||||
goto err;
|
||||
if (!test_ecdh_curve(NID_sect571k1, "NIST Binary-Curve K-571", ctx, out))
|
||||
goto err;
|
||||
if (!test_ecdh_curve(NID_sect571r1, "NIST Binary-Curve B-571", ctx, out))
|
||||
goto err;
|
||||
# endif
|
||||
if (!test_ecdh_kat(out, "Brainpool Prime-Curve brainpoolP256r1", 256))
|
||||
goto err;
|
||||
if (!test_ecdh_kat(out, "Brainpool Prime-Curve brainpoolP384r1", 384))
|
||||
goto err;
|
||||
if (!test_ecdh_kat(out, "Brainpool Prime-Curve brainpoolP512r1", 512))
|
||||
goto err;
|
||||
|
||||
ret = 0;
|
||||
|
||||
err:
|
||||
ERR_print_errors_fp(stderr);
|
||||
if (ctx)
|
||||
BN_CTX_free(ctx);
|
||||
BIO_free(out);
|
||||
CRYPTO_cleanup_all_ex_data();
|
||||
ERR_remove_thread_state(NULL);
|
||||
CRYPTO_mem_leaks_fp(stderr);
|
||||
EXIT(ret);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
# if 0
|
||||
static void MS_CALLBACK cb(int p, int n, void *arg)
|
||||
{
|
||||
char c = '*';
|
||||
|
||||
if (p == 0)
|
||||
c = '.';
|
||||
if (p == 1)
|
||||
c = '+';
|
||||
if (p == 2)
|
||||
c = '*';
|
||||
if (p == 3)
|
||||
c = '\n';
|
||||
BIO_write((BIO *)arg, &c, 1);
|
||||
(void)BIO_flush((BIO *)arg);
|
||||
# ifdef LINT
|
||||
p = n;
|
||||
# endif
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/ecdsa/ecdsatest.c
|
||||
@@ -0,0 +1,556 @@
|
||||
/* crypto/ecdsa/ecdsatest.c */
|
||||
/*
|
||||
* Written by Nils Larsch for the OpenSSL project.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2000-2005 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
/* ====================================================================
|
||||
* 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/opensslconf.h> /* 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 <openssl/crypto.h>
|
||||
# include <openssl/bio.h>
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/bn.h>
|
||||
# include <openssl/ecdsa.h>
|
||||
# ifndef OPENSSL_NO_ENGINE
|
||||
# include <openssl/engine.h>
|
||||
# endif
|
||||
# include <openssl/err.h>
|
||||
# include <openssl/rand.h>
|
||||
|
||||
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
|
||||
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/ec/ectest.c
|
||||
File diff suppressed because it is too large
Load Diff
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/engine/enginetest.c
|
||||
@@ -0,0 +1,269 @@
|
||||
/* crypto/engine/enginetest.c */
|
||||
/*
|
||||
* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL project
|
||||
* 2000.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999-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
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <openssl/e_os2.h>
|
||||
|
||||
#ifdef OPENSSL_NO_ENGINE
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No ENGINE support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/buffer.h>
|
||||
# include <openssl/crypto.h>
|
||||
# include <openssl/engine.h>
|
||||
# include <openssl/err.h>
|
||||
|
||||
static void display_engine_list(void)
|
||||
{
|
||||
ENGINE *h;
|
||||
int loop;
|
||||
|
||||
h = ENGINE_get_first();
|
||||
loop = 0;
|
||||
printf("listing available engine types\n");
|
||||
while (h) {
|
||||
printf("engine %i, id = \"%s\", name = \"%s\"\n",
|
||||
loop++, ENGINE_get_id(h), ENGINE_get_name(h));
|
||||
h = ENGINE_get_next(h);
|
||||
}
|
||||
printf("end of list\n");
|
||||
/*
|
||||
* ENGINE_get_first() increases the struct_ref counter, so we must call
|
||||
* ENGINE_free() to decrease it again
|
||||
*/
|
||||
ENGINE_free(h);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
ENGINE *block[512];
|
||||
char buf[256];
|
||||
const char *id, *name;
|
||||
ENGINE *ptr;
|
||||
int loop;
|
||||
int to_return = 1;
|
||||
ENGINE *new_h1 = NULL;
|
||||
ENGINE *new_h2 = NULL;
|
||||
ENGINE *new_h3 = NULL;
|
||||
ENGINE *new_h4 = NULL;
|
||||
|
||||
/* 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();
|
||||
|
||||
memset(block, 0, 512 * sizeof(ENGINE *));
|
||||
if (((new_h1 = ENGINE_new()) == NULL) ||
|
||||
!ENGINE_set_id(new_h1, "test_id0") ||
|
||||
!ENGINE_set_name(new_h1, "First test item") ||
|
||||
((new_h2 = ENGINE_new()) == NULL) ||
|
||||
!ENGINE_set_id(new_h2, "test_id1") ||
|
||||
!ENGINE_set_name(new_h2, "Second test item") ||
|
||||
((new_h3 = ENGINE_new()) == NULL) ||
|
||||
!ENGINE_set_id(new_h3, "test_id2") ||
|
||||
!ENGINE_set_name(new_h3, "Third test item") ||
|
||||
((new_h4 = ENGINE_new()) == NULL) ||
|
||||
!ENGINE_set_id(new_h4, "test_id3") ||
|
||||
!ENGINE_set_name(new_h4, "Fourth test item")) {
|
||||
printf("Couldn't set up test ENGINE structures\n");
|
||||
goto end;
|
||||
}
|
||||
printf("\nenginetest beginning\n\n");
|
||||
display_engine_list();
|
||||
if (!ENGINE_add(new_h1)) {
|
||||
printf("Add failed!\n");
|
||||
goto end;
|
||||
}
|
||||
display_engine_list();
|
||||
ptr = ENGINE_get_first();
|
||||
if (!ENGINE_remove(ptr)) {
|
||||
printf("Remove failed!\n");
|
||||
goto end;
|
||||
}
|
||||
if (ptr)
|
||||
ENGINE_free(ptr);
|
||||
display_engine_list();
|
||||
if (!ENGINE_add(new_h3) || !ENGINE_add(new_h2)) {
|
||||
printf("Add failed!\n");
|
||||
goto end;
|
||||
}
|
||||
display_engine_list();
|
||||
if (!ENGINE_remove(new_h2)) {
|
||||
printf("Remove failed!\n");
|
||||
goto end;
|
||||
}
|
||||
display_engine_list();
|
||||
if (!ENGINE_add(new_h4)) {
|
||||
printf("Add failed!\n");
|
||||
goto end;
|
||||
}
|
||||
display_engine_list();
|
||||
if (ENGINE_add(new_h3)) {
|
||||
printf("Add *should* have failed but didn't!\n");
|
||||
goto end;
|
||||
} else
|
||||
printf("Add that should fail did.\n");
|
||||
ERR_clear_error();
|
||||
if (ENGINE_remove(new_h2)) {
|
||||
printf("Remove *should* have failed but didn't!\n");
|
||||
goto end;
|
||||
} else
|
||||
printf("Remove that should fail did.\n");
|
||||
ERR_clear_error();
|
||||
if (!ENGINE_remove(new_h3)) {
|
||||
printf("Remove failed!\n");
|
||||
goto end;
|
||||
}
|
||||
display_engine_list();
|
||||
if (!ENGINE_remove(new_h4)) {
|
||||
printf("Remove failed!\n");
|
||||
goto end;
|
||||
}
|
||||
display_engine_list();
|
||||
/*
|
||||
* Depending on whether there's any hardware support compiled in, this
|
||||
* remove may be destined to fail.
|
||||
*/
|
||||
ptr = ENGINE_get_first();
|
||||
if (ptr)
|
||||
if (!ENGINE_remove(ptr))
|
||||
printf("Remove failed!i - probably no hardware "
|
||||
"support present.\n");
|
||||
if (ptr)
|
||||
ENGINE_free(ptr);
|
||||
display_engine_list();
|
||||
if (!ENGINE_add(new_h1) || !ENGINE_remove(new_h1)) {
|
||||
printf("Couldn't add and remove to an empty list!\n");
|
||||
goto end;
|
||||
} else
|
||||
printf("Successfully added and removed to an empty list!\n");
|
||||
printf("About to beef up the engine-type list\n");
|
||||
for (loop = 0; loop < 512; loop++) {
|
||||
sprintf(buf, "id%i", loop);
|
||||
id = BUF_strdup(buf);
|
||||
sprintf(buf, "Fake engine type %i", loop);
|
||||
name = BUF_strdup(buf);
|
||||
if (((block[loop] = ENGINE_new()) == NULL) ||
|
||||
!ENGINE_set_id(block[loop], id) ||
|
||||
!ENGINE_set_name(block[loop], name)) {
|
||||
printf("Couldn't create block of ENGINE structures.\n"
|
||||
"I'll probably also core-dump now, damn.\n");
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
for (loop = 0; loop < 512; loop++) {
|
||||
if (!ENGINE_add(block[loop])) {
|
||||
printf("\nAdding stopped at %i, (%s,%s)\n",
|
||||
loop, ENGINE_get_id(block[loop]),
|
||||
ENGINE_get_name(block[loop]));
|
||||
goto cleanup_loop;
|
||||
} else
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
}
|
||||
cleanup_loop:
|
||||
printf("\nAbout to empty the engine-type list\n");
|
||||
while ((ptr = ENGINE_get_first()) != NULL) {
|
||||
if (!ENGINE_remove(ptr)) {
|
||||
printf("\nRemove failed!\n");
|
||||
goto end;
|
||||
}
|
||||
ENGINE_free(ptr);
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
}
|
||||
for (loop = 0; loop < 512; loop++) {
|
||||
OPENSSL_free((void *)ENGINE_get_id(block[loop]));
|
||||
OPENSSL_free((void *)ENGINE_get_name(block[loop]));
|
||||
}
|
||||
printf("\nTests completed happily\n");
|
||||
to_return = 0;
|
||||
end:
|
||||
if (to_return)
|
||||
ERR_print_errors_fp(stderr);
|
||||
if (new_h1)
|
||||
ENGINE_free(new_h1);
|
||||
if (new_h2)
|
||||
ENGINE_free(new_h2);
|
||||
if (new_h3)
|
||||
ENGINE_free(new_h3);
|
||||
if (new_h4)
|
||||
ENGINE_free(new_h4);
|
||||
for (loop = 0; loop < 512; loop++)
|
||||
if (block[loop])
|
||||
ENGINE_free(block[loop]);
|
||||
ENGINE_cleanup();
|
||||
CRYPTO_cleanup_all_ex_data();
|
||||
ERR_free_strings();
|
||||
ERR_remove_thread_state(NULL);
|
||||
CRYPTO_mem_leaks_fp(stderr);
|
||||
return to_return;
|
||||
}
|
||||
#endif
|
||||
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/evp/evp_extra_test.c
|
||||
@@ -0,0 +1,489 @@
|
||||
/* Copyright (c) 2014, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1998-2015 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
/*
|
||||
* kExampleRSAKeyDER is an RSA private key in ASN.1, DER format. Of course, you
|
||||
* should never use this key anywhere but in an example.
|
||||
*/
|
||||
static const unsigned char kExampleRSAKeyDER[] = {
|
||||
0x30, 0x82, 0x02, 0x5c, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xf8,
|
||||
0xb8, 0x6c, 0x83, 0xb4, 0xbc, 0xd9, 0xa8, 0x57, 0xc0, 0xa5, 0xb4, 0x59,
|
||||
0x76, 0x8c, 0x54, 0x1d, 0x79, 0xeb, 0x22, 0x52, 0x04, 0x7e, 0xd3, 0x37,
|
||||
0xeb, 0x41, 0xfd, 0x83, 0xf9, 0xf0, 0xa6, 0x85, 0x15, 0x34, 0x75, 0x71,
|
||||
0x5a, 0x84, 0xa8, 0x3c, 0xd2, 0xef, 0x5a, 0x4e, 0xd3, 0xde, 0x97, 0x8a,
|
||||
0xdd, 0xff, 0xbb, 0xcf, 0x0a, 0xaa, 0x86, 0x92, 0xbe, 0xb8, 0x50, 0xe4,
|
||||
0xcd, 0x6f, 0x80, 0x33, 0x30, 0x76, 0x13, 0x8f, 0xca, 0x7b, 0xdc, 0xec,
|
||||
0x5a, 0xca, 0x63, 0xc7, 0x03, 0x25, 0xef, 0xa8, 0x8a, 0x83, 0x58, 0x76,
|
||||
0x20, 0xfa, 0x16, 0x77, 0xd7, 0x79, 0x92, 0x63, 0x01, 0x48, 0x1a, 0xd8,
|
||||
0x7b, 0x67, 0xf1, 0x52, 0x55, 0x49, 0x4e, 0xd6, 0x6e, 0x4a, 0x5c, 0xd7,
|
||||
0x7a, 0x37, 0x36, 0x0c, 0xde, 0xdd, 0x8f, 0x44, 0xe8, 0xc2, 0xa7, 0x2c,
|
||||
0x2b, 0xb5, 0xaf, 0x64, 0x4b, 0x61, 0x07, 0x02, 0x03, 0x01, 0x00, 0x01,
|
||||
0x02, 0x81, 0x80, 0x74, 0x88, 0x64, 0x3f, 0x69, 0x45, 0x3a, 0x6d, 0xc7,
|
||||
0x7f, 0xb9, 0xa3, 0xc0, 0x6e, 0xec, 0xdc, 0xd4, 0x5a, 0xb5, 0x32, 0x85,
|
||||
0x5f, 0x19, 0xd4, 0xf8, 0xd4, 0x3f, 0x3c, 0xfa, 0xc2, 0xf6, 0x5f, 0xee,
|
||||
0xe6, 0xba, 0x87, 0x74, 0x2e, 0xc7, 0x0c, 0xd4, 0x42, 0xb8, 0x66, 0x85,
|
||||
0x9c, 0x7b, 0x24, 0x61, 0xaa, 0x16, 0x11, 0xf6, 0xb5, 0xb6, 0xa4, 0x0a,
|
||||
0xc9, 0x55, 0x2e, 0x81, 0xa5, 0x47, 0x61, 0xcb, 0x25, 0x8f, 0xc2, 0x15,
|
||||
0x7b, 0x0e, 0x7c, 0x36, 0x9f, 0x3a, 0xda, 0x58, 0x86, 0x1c, 0x5b, 0x83,
|
||||
0x79, 0xe6, 0x2b, 0xcc, 0xe6, 0xfa, 0x2c, 0x61, 0xf2, 0x78, 0x80, 0x1b,
|
||||
0xe2, 0xf3, 0x9d, 0x39, 0x2b, 0x65, 0x57, 0x91, 0x3d, 0x71, 0x99, 0x73,
|
||||
0xa5, 0xc2, 0x79, 0x20, 0x8c, 0x07, 0x4f, 0xe5, 0xb4, 0x60, 0x1f, 0x99,
|
||||
0xa2, 0xb1, 0x4f, 0x0c, 0xef, 0xbc, 0x59, 0x53, 0x00, 0x7d, 0xb1, 0x02,
|
||||
0x41, 0x00, 0xfc, 0x7e, 0x23, 0x65, 0x70, 0xf8, 0xce, 0xd3, 0x40, 0x41,
|
||||
0x80, 0x6a, 0x1d, 0x01, 0xd6, 0x01, 0xff, 0xb6, 0x1b, 0x3d, 0x3d, 0x59,
|
||||
0x09, 0x33, 0x79, 0xc0, 0x4f, 0xde, 0x96, 0x27, 0x4b, 0x18, 0xc6, 0xd9,
|
||||
0x78, 0xf1, 0xf4, 0x35, 0x46, 0xe9, 0x7c, 0x42, 0x7a, 0x5d, 0x9f, 0xef,
|
||||
0x54, 0xb8, 0xf7, 0x9f, 0xc4, 0x33, 0x6c, 0xf3, 0x8c, 0x32, 0x46, 0x87,
|
||||
0x67, 0x30, 0x7b, 0xa7, 0xac, 0xe3, 0x02, 0x41, 0x00, 0xfc, 0x2c, 0xdf,
|
||||
0x0c, 0x0d, 0x88, 0xf5, 0xb1, 0x92, 0xa8, 0x93, 0x47, 0x63, 0x55, 0xf5,
|
||||
0xca, 0x58, 0x43, 0xba, 0x1c, 0xe5, 0x9e, 0xb6, 0x95, 0x05, 0xcd, 0xb5,
|
||||
0x82, 0xdf, 0xeb, 0x04, 0x53, 0x9d, 0xbd, 0xc2, 0x38, 0x16, 0xb3, 0x62,
|
||||
0xdd, 0xa1, 0x46, 0xdb, 0x6d, 0x97, 0x93, 0x9f, 0x8a, 0xc3, 0x9b, 0x64,
|
||||
0x7e, 0x42, 0xe3, 0x32, 0x57, 0x19, 0x1b, 0xd5, 0x6e, 0x85, 0xfa, 0xb8,
|
||||
0x8d, 0x02, 0x41, 0x00, 0xbc, 0x3d, 0xde, 0x6d, 0xd6, 0x97, 0xe8, 0xba,
|
||||
0x9e, 0x81, 0x37, 0x17, 0xe5, 0xa0, 0x64, 0xc9, 0x00, 0xb7, 0xe7, 0xfe,
|
||||
0xf4, 0x29, 0xd9, 0x2e, 0x43, 0x6b, 0x19, 0x20, 0xbd, 0x99, 0x75, 0xe7,
|
||||
0x76, 0xf8, 0xd3, 0xae, 0xaf, 0x7e, 0xb8, 0xeb, 0x81, 0xf4, 0x9d, 0xfe,
|
||||
0x07, 0x2b, 0x0b, 0x63, 0x0b, 0x5a, 0x55, 0x90, 0x71, 0x7d, 0xf1, 0xdb,
|
||||
0xd9, 0xb1, 0x41, 0x41, 0x68, 0x2f, 0x4e, 0x39, 0x02, 0x40, 0x5a, 0x34,
|
||||
0x66, 0xd8, 0xf5, 0xe2, 0x7f, 0x18, 0xb5, 0x00, 0x6e, 0x26, 0x84, 0x27,
|
||||
0x14, 0x93, 0xfb, 0xfc, 0xc6, 0x0f, 0x5e, 0x27, 0xe6, 0xe1, 0xe9, 0xc0,
|
||||
0x8a, 0xe4, 0x34, 0xda, 0xe9, 0xa2, 0x4b, 0x73, 0xbc, 0x8c, 0xb9, 0xba,
|
||||
0x13, 0x6c, 0x7a, 0x2b, 0x51, 0x84, 0xa3, 0x4a, 0xe0, 0x30, 0x10, 0x06,
|
||||
0x7e, 0xed, 0x17, 0x5a, 0x14, 0x00, 0xc9, 0xef, 0x85, 0xea, 0x52, 0x2c,
|
||||
0xbc, 0x65, 0x02, 0x40, 0x51, 0xe3, 0xf2, 0x83, 0x19, 0x9b, 0xc4, 0x1e,
|
||||
0x2f, 0x50, 0x3d, 0xdf, 0x5a, 0xa2, 0x18, 0xca, 0x5f, 0x2e, 0x49, 0xaf,
|
||||
0x6f, 0xcc, 0xfa, 0x65, 0x77, 0x94, 0xb5, 0xa1, 0x0a, 0xa9, 0xd1, 0x8a,
|
||||
0x39, 0x37, 0xf4, 0x0b, 0xa0, 0xd7, 0x82, 0x27, 0x5e, 0xae, 0x17, 0x17,
|
||||
0xa1, 0x1e, 0x54, 0x34, 0xbf, 0x6e, 0xc4, 0x8e, 0x99, 0x5d, 0x08, 0xf1,
|
||||
0x2d, 0x86, 0x9d, 0xa5, 0x20, 0x1b, 0xe5, 0xdf,
|
||||
};
|
||||
|
||||
static const unsigned char kMsg[] = { 1, 2, 3, 4 };
|
||||
|
||||
static const unsigned char kSignature[] = {
|
||||
0xa5, 0xf0, 0x8a, 0x47, 0x5d, 0x3c, 0xb3, 0xcc, 0xa9, 0x79, 0xaf, 0x4d,
|
||||
0x8c, 0xae, 0x4c, 0x14, 0xef, 0xc2, 0x0b, 0x34, 0x36, 0xde, 0xf4, 0x3e,
|
||||
0x3d, 0xbb, 0x4a, 0x60, 0x5c, 0xc8, 0x91, 0x28, 0xda, 0xfb, 0x7e, 0x04,
|
||||
0x96, 0x7e, 0x63, 0x13, 0x90, 0xce, 0xb9, 0xb4, 0x62, 0x7a, 0xfd, 0x09,
|
||||
0x3d, 0xc7, 0x67, 0x78, 0x54, 0x04, 0xeb, 0x52, 0x62, 0x6e, 0x24, 0x67,
|
||||
0xb4, 0x40, 0xfc, 0x57, 0x62, 0xc6, 0xf1, 0x67, 0xc1, 0x97, 0x8f, 0x6a,
|
||||
0xa8, 0xae, 0x44, 0x46, 0x5e, 0xab, 0x67, 0x17, 0x53, 0x19, 0x3a, 0xda,
|
||||
0x5a, 0xc8, 0x16, 0x3e, 0x86, 0xd5, 0xc5, 0x71, 0x2f, 0xfc, 0x23, 0x48,
|
||||
0xd9, 0x0b, 0x13, 0xdd, 0x7b, 0x5a, 0x25, 0x79, 0xef, 0xa5, 0x7b, 0x04,
|
||||
0xed, 0x44, 0xf6, 0x18, 0x55, 0xe4, 0x0a, 0xe9, 0x57, 0x79, 0x5d, 0xd7,
|
||||
0x55, 0xa7, 0xab, 0x45, 0x02, 0x97, 0x60, 0x42,
|
||||
};
|
||||
|
||||
/*
|
||||
* kExampleRSAKeyPKCS8 is kExampleRSAKeyDER encoded in a PKCS #8
|
||||
* PrivateKeyInfo.
|
||||
*/
|
||||
static const unsigned char kExampleRSAKeyPKCS8[] = {
|
||||
0x30, 0x82, 0x02, 0x76, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a,
|
||||
0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82,
|
||||
0x02, 0x60, 0x30, 0x82, 0x02, 0x5c, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81,
|
||||
0x00, 0xf8, 0xb8, 0x6c, 0x83, 0xb4, 0xbc, 0xd9, 0xa8, 0x57, 0xc0, 0xa5,
|
||||
0xb4, 0x59, 0x76, 0x8c, 0x54, 0x1d, 0x79, 0xeb, 0x22, 0x52, 0x04, 0x7e,
|
||||
0xd3, 0x37, 0xeb, 0x41, 0xfd, 0x83, 0xf9, 0xf0, 0xa6, 0x85, 0x15, 0x34,
|
||||
0x75, 0x71, 0x5a, 0x84, 0xa8, 0x3c, 0xd2, 0xef, 0x5a, 0x4e, 0xd3, 0xde,
|
||||
0x97, 0x8a, 0xdd, 0xff, 0xbb, 0xcf, 0x0a, 0xaa, 0x86, 0x92, 0xbe, 0xb8,
|
||||
0x50, 0xe4, 0xcd, 0x6f, 0x80, 0x33, 0x30, 0x76, 0x13, 0x8f, 0xca, 0x7b,
|
||||
0xdc, 0xec, 0x5a, 0xca, 0x63, 0xc7, 0x03, 0x25, 0xef, 0xa8, 0x8a, 0x83,
|
||||
0x58, 0x76, 0x20, 0xfa, 0x16, 0x77, 0xd7, 0x79, 0x92, 0x63, 0x01, 0x48,
|
||||
0x1a, 0xd8, 0x7b, 0x67, 0xf1, 0x52, 0x55, 0x49, 0x4e, 0xd6, 0x6e, 0x4a,
|
||||
0x5c, 0xd7, 0x7a, 0x37, 0x36, 0x0c, 0xde, 0xdd, 0x8f, 0x44, 0xe8, 0xc2,
|
||||
0xa7, 0x2c, 0x2b, 0xb5, 0xaf, 0x64, 0x4b, 0x61, 0x07, 0x02, 0x03, 0x01,
|
||||
0x00, 0x01, 0x02, 0x81, 0x80, 0x74, 0x88, 0x64, 0x3f, 0x69, 0x45, 0x3a,
|
||||
0x6d, 0xc7, 0x7f, 0xb9, 0xa3, 0xc0, 0x6e, 0xec, 0xdc, 0xd4, 0x5a, 0xb5,
|
||||
0x32, 0x85, 0x5f, 0x19, 0xd4, 0xf8, 0xd4, 0x3f, 0x3c, 0xfa, 0xc2, 0xf6,
|
||||
0x5f, 0xee, 0xe6, 0xba, 0x87, 0x74, 0x2e, 0xc7, 0x0c, 0xd4, 0x42, 0xb8,
|
||||
0x66, 0x85, 0x9c, 0x7b, 0x24, 0x61, 0xaa, 0x16, 0x11, 0xf6, 0xb5, 0xb6,
|
||||
0xa4, 0x0a, 0xc9, 0x55, 0x2e, 0x81, 0xa5, 0x47, 0x61, 0xcb, 0x25, 0x8f,
|
||||
0xc2, 0x15, 0x7b, 0x0e, 0x7c, 0x36, 0x9f, 0x3a, 0xda, 0x58, 0x86, 0x1c,
|
||||
0x5b, 0x83, 0x79, 0xe6, 0x2b, 0xcc, 0xe6, 0xfa, 0x2c, 0x61, 0xf2, 0x78,
|
||||
0x80, 0x1b, 0xe2, 0xf3, 0x9d, 0x39, 0x2b, 0x65, 0x57, 0x91, 0x3d, 0x71,
|
||||
0x99, 0x73, 0xa5, 0xc2, 0x79, 0x20, 0x8c, 0x07, 0x4f, 0xe5, 0xb4, 0x60,
|
||||
0x1f, 0x99, 0xa2, 0xb1, 0x4f, 0x0c, 0xef, 0xbc, 0x59, 0x53, 0x00, 0x7d,
|
||||
0xb1, 0x02, 0x41, 0x00, 0xfc, 0x7e, 0x23, 0x65, 0x70, 0xf8, 0xce, 0xd3,
|
||||
0x40, 0x41, 0x80, 0x6a, 0x1d, 0x01, 0xd6, 0x01, 0xff, 0xb6, 0x1b, 0x3d,
|
||||
0x3d, 0x59, 0x09, 0x33, 0x79, 0xc0, 0x4f, 0xde, 0x96, 0x27, 0x4b, 0x18,
|
||||
0xc6, 0xd9, 0x78, 0xf1, 0xf4, 0x35, 0x46, 0xe9, 0x7c, 0x42, 0x7a, 0x5d,
|
||||
0x9f, 0xef, 0x54, 0xb8, 0xf7, 0x9f, 0xc4, 0x33, 0x6c, 0xf3, 0x8c, 0x32,
|
||||
0x46, 0x87, 0x67, 0x30, 0x7b, 0xa7, 0xac, 0xe3, 0x02, 0x41, 0x00, 0xfc,
|
||||
0x2c, 0xdf, 0x0c, 0x0d, 0x88, 0xf5, 0xb1, 0x92, 0xa8, 0x93, 0x47, 0x63,
|
||||
0x55, 0xf5, 0xca, 0x58, 0x43, 0xba, 0x1c, 0xe5, 0x9e, 0xb6, 0x95, 0x05,
|
||||
0xcd, 0xb5, 0x82, 0xdf, 0xeb, 0x04, 0x53, 0x9d, 0xbd, 0xc2, 0x38, 0x16,
|
||||
0xb3, 0x62, 0xdd, 0xa1, 0x46, 0xdb, 0x6d, 0x97, 0x93, 0x9f, 0x8a, 0xc3,
|
||||
0x9b, 0x64, 0x7e, 0x42, 0xe3, 0x32, 0x57, 0x19, 0x1b, 0xd5, 0x6e, 0x85,
|
||||
0xfa, 0xb8, 0x8d, 0x02, 0x41, 0x00, 0xbc, 0x3d, 0xde, 0x6d, 0xd6, 0x97,
|
||||
0xe8, 0xba, 0x9e, 0x81, 0x37, 0x17, 0xe5, 0xa0, 0x64, 0xc9, 0x00, 0xb7,
|
||||
0xe7, 0xfe, 0xf4, 0x29, 0xd9, 0x2e, 0x43, 0x6b, 0x19, 0x20, 0xbd, 0x99,
|
||||
0x75, 0xe7, 0x76, 0xf8, 0xd3, 0xae, 0xaf, 0x7e, 0xb8, 0xeb, 0x81, 0xf4,
|
||||
0x9d, 0xfe, 0x07, 0x2b, 0x0b, 0x63, 0x0b, 0x5a, 0x55, 0x90, 0x71, 0x7d,
|
||||
0xf1, 0xdb, 0xd9, 0xb1, 0x41, 0x41, 0x68, 0x2f, 0x4e, 0x39, 0x02, 0x40,
|
||||
0x5a, 0x34, 0x66, 0xd8, 0xf5, 0xe2, 0x7f, 0x18, 0xb5, 0x00, 0x6e, 0x26,
|
||||
0x84, 0x27, 0x14, 0x93, 0xfb, 0xfc, 0xc6, 0x0f, 0x5e, 0x27, 0xe6, 0xe1,
|
||||
0xe9, 0xc0, 0x8a, 0xe4, 0x34, 0xda, 0xe9, 0xa2, 0x4b, 0x73, 0xbc, 0x8c,
|
||||
0xb9, 0xba, 0x13, 0x6c, 0x7a, 0x2b, 0x51, 0x84, 0xa3, 0x4a, 0xe0, 0x30,
|
||||
0x10, 0x06, 0x7e, 0xed, 0x17, 0x5a, 0x14, 0x00, 0xc9, 0xef, 0x85, 0xea,
|
||||
0x52, 0x2c, 0xbc, 0x65, 0x02, 0x40, 0x51, 0xe3, 0xf2, 0x83, 0x19, 0x9b,
|
||||
0xc4, 0x1e, 0x2f, 0x50, 0x3d, 0xdf, 0x5a, 0xa2, 0x18, 0xca, 0x5f, 0x2e,
|
||||
0x49, 0xaf, 0x6f, 0xcc, 0xfa, 0x65, 0x77, 0x94, 0xb5, 0xa1, 0x0a, 0xa9,
|
||||
0xd1, 0x8a, 0x39, 0x37, 0xf4, 0x0b, 0xa0, 0xd7, 0x82, 0x27, 0x5e, 0xae,
|
||||
0x17, 0x17, 0xa1, 0x1e, 0x54, 0x34, 0xbf, 0x6e, 0xc4, 0x8e, 0x99, 0x5d,
|
||||
0x08, 0xf1, 0x2d, 0x86, 0x9d, 0xa5, 0x20, 0x1b, 0xe5, 0xdf,
|
||||
};
|
||||
|
||||
#ifndef OPENSSL_NO_EC
|
||||
/*
|
||||
* kExampleECKeyDER is a sample EC private key encoded as an ECPrivateKey
|
||||
* structure.
|
||||
*/
|
||||
static const unsigned char kExampleECKeyDER[] = {
|
||||
0x30, 0x77, 0x02, 0x01, 0x01, 0x04, 0x20, 0x07, 0x0f, 0x08, 0x72, 0x7a,
|
||||
0xd4, 0xa0, 0x4a, 0x9c, 0xdd, 0x59, 0xc9, 0x4d, 0x89, 0x68, 0x77, 0x08,
|
||||
0xb5, 0x6f, 0xc9, 0x5d, 0x30, 0x77, 0x0e, 0xe8, 0xd1, 0xc9, 0xce, 0x0a,
|
||||
0x8b, 0xb4, 0x6a, 0xa0, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
|
||||
0x03, 0x01, 0x07, 0xa1, 0x44, 0x03, 0x42, 0x00, 0x04, 0xe6, 0x2b, 0x69,
|
||||
0xe2, 0xbf, 0x65, 0x9f, 0x97, 0xbe, 0x2f, 0x1e, 0x0d, 0x94, 0x8a, 0x4c,
|
||||
0xd5, 0x97, 0x6b, 0xb7, 0xa9, 0x1e, 0x0d, 0x46, 0xfb, 0xdd, 0xa9, 0xa9,
|
||||
0x1e, 0x9d, 0xdc, 0xba, 0x5a, 0x01, 0xe7, 0xd6, 0x97, 0xa8, 0x0a, 0x18,
|
||||
0xf9, 0xc3, 0xc4, 0xa3, 0x1e, 0x56, 0xe2, 0x7c, 0x83, 0x48, 0xdb, 0x16,
|
||||
0x1a, 0x1c, 0xf5, 0x1d, 0x7e, 0xf1, 0x94, 0x2d, 0x4b, 0xcf, 0x72, 0x22,
|
||||
0xc1,
|
||||
};
|
||||
|
||||
/*
|
||||
* kExampleBadECKeyDER is a sample EC private key encoded as an ECPrivateKey
|
||||
* structure. The private key is equal to the order and will fail to import
|
||||
*/
|
||||
static const unsigned char kExampleBadECKeyDER[] = {
|
||||
0x30, 0x66, 0x02, 0x01, 0x00, 0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48,
|
||||
0xCE, 0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03,
|
||||
0x01, 0x07, 0x04, 0x4C, 0x30, 0x4A, 0x02, 0x01, 0x01, 0x04, 0x20, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84, 0xF3,
|
||||
0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51, 0xA1, 0x23, 0x03, 0x21, 0x00,
|
||||
0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84,
|
||||
0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51
|
||||
};
|
||||
#endif
|
||||
|
||||
static EVP_PKEY *load_example_rsa_key(void)
|
||||
{
|
||||
EVP_PKEY *ret = NULL;
|
||||
const unsigned char *derp = kExampleRSAKeyDER;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
RSA *rsa = NULL;
|
||||
|
||||
if (!d2i_RSAPrivateKey(&rsa, &derp, sizeof(kExampleRSAKeyDER))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pkey = EVP_PKEY_new();
|
||||
if (pkey == NULL || !EVP_PKEY_set1_RSA(pkey, rsa)) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = pkey;
|
||||
pkey = NULL;
|
||||
|
||||
out:
|
||||
if (pkey) {
|
||||
EVP_PKEY_free(pkey);
|
||||
}
|
||||
if (rsa) {
|
||||
RSA_free(rsa);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int test_EVP_DigestSignInit(void)
|
||||
{
|
||||
int ret = 0;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
unsigned char *sig = NULL;
|
||||
size_t sig_len = 0;
|
||||
EVP_MD_CTX md_ctx, md_ctx_verify;
|
||||
|
||||
EVP_MD_CTX_init(&md_ctx);
|
||||
EVP_MD_CTX_init(&md_ctx_verify);
|
||||
|
||||
pkey = load_example_rsa_key();
|
||||
if (pkey == NULL ||
|
||||
!EVP_DigestSignInit(&md_ctx, NULL, EVP_sha256(), NULL, pkey) ||
|
||||
!EVP_DigestSignUpdate(&md_ctx, kMsg, sizeof(kMsg))) {
|
||||
goto out;
|
||||
}
|
||||
/* Determine the size of the signature. */
|
||||
if (!EVP_DigestSignFinal(&md_ctx, NULL, &sig_len)) {
|
||||
goto out;
|
||||
}
|
||||
/* Sanity check for testing. */
|
||||
if (sig_len != (size_t)EVP_PKEY_size(pkey)) {
|
||||
fprintf(stderr, "sig_len mismatch\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
sig = OPENSSL_malloc(sig_len);
|
||||
if (sig == NULL || !EVP_DigestSignFinal(&md_ctx, sig, &sig_len)) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Ensure that the signature round-trips. */
|
||||
if (!EVP_DigestVerifyInit(&md_ctx_verify, NULL, EVP_sha256(), NULL, pkey)
|
||||
|| !EVP_DigestVerifyUpdate(&md_ctx_verify, kMsg, sizeof(kMsg))
|
||||
|| !EVP_DigestVerifyFinal(&md_ctx_verify, sig, sig_len)) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
out:
|
||||
if (!ret) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
}
|
||||
|
||||
EVP_MD_CTX_cleanup(&md_ctx);
|
||||
EVP_MD_CTX_cleanup(&md_ctx_verify);
|
||||
if (pkey) {
|
||||
EVP_PKEY_free(pkey);
|
||||
}
|
||||
if (sig) {
|
||||
OPENSSL_free(sig);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int test_EVP_DigestVerifyInit(void)
|
||||
{
|
||||
int ret = 0;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
EVP_MD_CTX md_ctx;
|
||||
|
||||
EVP_MD_CTX_init(&md_ctx);
|
||||
|
||||
pkey = load_example_rsa_key();
|
||||
if (pkey == NULL ||
|
||||
!EVP_DigestVerifyInit(&md_ctx, NULL, EVP_sha256(), NULL, pkey) ||
|
||||
!EVP_DigestVerifyUpdate(&md_ctx, kMsg, sizeof(kMsg)) ||
|
||||
!EVP_DigestVerifyFinal(&md_ctx, kSignature, sizeof(kSignature))) {
|
||||
goto out;
|
||||
}
|
||||
ret = 1;
|
||||
|
||||
out:
|
||||
if (!ret) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
}
|
||||
|
||||
EVP_MD_CTX_cleanup(&md_ctx);
|
||||
if (pkey) {
|
||||
EVP_PKEY_free(pkey);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int test_d2i_AutoPrivateKey(const unsigned char *input,
|
||||
size_t input_len, int expected_id)
|
||||
{
|
||||
int ret = 0;
|
||||
const unsigned char *p;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
|
||||
p = input;
|
||||
pkey = d2i_AutoPrivateKey(NULL, &p, input_len);
|
||||
if (pkey == NULL || p != input + input_len) {
|
||||
fprintf(stderr, "d2i_AutoPrivateKey failed\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (EVP_PKEY_id(pkey) != expected_id) {
|
||||
fprintf(stderr, "Did not decode expected type\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
done:
|
||||
if (!ret) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
}
|
||||
|
||||
if (pkey != NULL) {
|
||||
EVP_PKEY_free(pkey);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_EC
|
||||
/* Tests loading a bad key in PKCS8 format */
|
||||
static int test_EVP_PKCS82PKEY(void)
|
||||
{
|
||||
int ret = 0;
|
||||
const unsigned char *derp = kExampleBadECKeyDER;
|
||||
PKCS8_PRIV_KEY_INFO *p8inf = NULL;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
|
||||
p8inf = d2i_PKCS8_PRIV_KEY_INFO(NULL, &derp, sizeof(kExampleBadECKeyDER));
|
||||
|
||||
if (!p8inf || derp != kExampleBadECKeyDER + sizeof(kExampleBadECKeyDER)) {
|
||||
fprintf(stderr, "Failed to parse key\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
pkey = EVP_PKCS82PKEY(p8inf);
|
||||
if (pkey) {
|
||||
fprintf(stderr, "Imported invalid EC key\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
done:
|
||||
if (p8inf != NULL) {
|
||||
PKCS8_PRIV_KEY_INFO_free(p8inf);
|
||||
}
|
||||
|
||||
if (pkey != NULL) {
|
||||
EVP_PKEY_free(pkey);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(void)
|
||||
{
|
||||
CRYPTO_malloc_debug_init();
|
||||
CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
|
||||
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
|
||||
|
||||
ERR_load_crypto_strings();
|
||||
/* Load up the software EVP_CIPHER and EVP_MD definitions */
|
||||
OpenSSL_add_all_ciphers();
|
||||
OpenSSL_add_all_digests();
|
||||
|
||||
if (!test_EVP_DigestSignInit()) {
|
||||
fprintf(stderr, "EVP_DigestSignInit failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!test_EVP_DigestVerifyInit()) {
|
||||
fprintf(stderr, "EVP_DigestVerifyInit failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!test_d2i_AutoPrivateKey(kExampleRSAKeyDER, sizeof(kExampleRSAKeyDER),
|
||||
EVP_PKEY_RSA)) {
|
||||
fprintf(stderr, "d2i_AutoPrivateKey(kExampleRSAKeyDER) failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!test_d2i_AutoPrivateKey
|
||||
(kExampleRSAKeyPKCS8, sizeof(kExampleRSAKeyPKCS8), EVP_PKEY_RSA)) {
|
||||
fprintf(stderr, "d2i_AutoPrivateKey(kExampleRSAKeyPKCS8) failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_EC
|
||||
if (!test_d2i_AutoPrivateKey(kExampleECKeyDER, sizeof(kExampleECKeyDER),
|
||||
EVP_PKEY_EC)) {
|
||||
fprintf(stderr, "d2i_AutoPrivateKey(kExampleECKeyDER) failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!test_EVP_PKCS82PKEY()) {
|
||||
fprintf(stderr, "test_EVP_PKCS82PKEY failed\n");
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
EVP_cleanup();
|
||||
CRYPTO_cleanup_all_ex_data();
|
||||
ERR_remove_thread_state(NULL);
|
||||
ERR_free_strings();
|
||||
CRYPTO_mem_leaks_fp(stderr);
|
||||
|
||||
printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/evp/evp_test.c
|
||||
@@ -0,0 +1,596 @@
|
||||
/* 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 <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
#include <openssl/opensslconf.h>
|
||||
#include <openssl/evp.h>
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
# include <openssl/engine.h>
|
||||
#endif
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/conf.h>
|
||||
|
||||
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,
|
||||
const unsigned char *aad, int an,
|
||||
const unsigned char *tag, int tn, int encdec)
|
||||
{
|
||||
EVP_CIPHER_CTX ctx;
|
||||
unsigned char out[4096];
|
||||
int outl, outl2, mode;
|
||||
|
||||
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 (an)
|
||||
hexdump(stdout, "AAD", aad, an);
|
||||
if (tn)
|
||||
hexdump(stdout, "Tag", tag, tn);
|
||||
mode = EVP_CIPHER_mode(c);
|
||||
if (kn != EVP_CIPHER_key_length(c)) {
|
||||
fprintf(stderr, "Key length doesn't match, got %d expected %lu\n", kn,
|
||||
(unsigned long)EVP_CIPHER_key_length(c));
|
||||
test1_exit(5);
|
||||
}
|
||||
EVP_CIPHER_CTX_init(&ctx);
|
||||
EVP_CIPHER_CTX_set_flags(&ctx, EVP_CIPHER_CTX_FLAG_WRAP_ALLOW);
|
||||
if (encdec != 0) {
|
||||
if (mode == EVP_CIPH_GCM_MODE) {
|
||||
if (!EVP_EncryptInit_ex(&ctx, c, NULL, NULL, NULL)) {
|
||||
fprintf(stderr, "EncryptInit failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(10);
|
||||
}
|
||||
if (!EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_GCM_SET_IVLEN, in, NULL)) {
|
||||
fprintf(stderr, "IV length set failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(11);
|
||||
}
|
||||
if (!EVP_EncryptInit_ex(&ctx, NULL, NULL, key, iv)) {
|
||||
fprintf(stderr, "Key/IV set failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(12);
|
||||
}
|
||||
if (an && !EVP_EncryptUpdate(&ctx, NULL, &outl, aad, an)) {
|
||||
fprintf(stderr, "AAD set failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(13);
|
||||
}
|
||||
} else if (mode == EVP_CIPH_CCM_MODE) {
|
||||
if (!EVP_EncryptInit_ex(&ctx, c, NULL, NULL, NULL)) {
|
||||
fprintf(stderr, "EncryptInit failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(10);
|
||||
}
|
||||
if (!EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_CCM_SET_IVLEN, in, NULL)) {
|
||||
fprintf(stderr, "IV length set failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(11);
|
||||
}
|
||||
if (!EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_CCM_SET_TAG, tn, NULL)) {
|
||||
fprintf(stderr, "Tag length set failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(11);
|
||||
}
|
||||
if (!EVP_EncryptInit_ex(&ctx, NULL, NULL, key, iv)) {
|
||||
fprintf(stderr, "Key/IV set failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(12);
|
||||
}
|
||||
if (!EVP_EncryptUpdate(&ctx, NULL, &outl, NULL, pn)) {
|
||||
fprintf(stderr, "Plaintext length set failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(12);
|
||||
}
|
||||
if (an && !EVP_EncryptUpdate(&ctx, NULL, &outl, aad, an)) {
|
||||
fprintf(stderr, "AAD set failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(13);
|
||||
}
|
||||
} else if (mode == EVP_CIPH_WRAP_MODE) {
|
||||
if (!EVP_EncryptInit_ex(&ctx, c, NULL, key, in ? iv : NULL)) {
|
||||
fprintf(stderr, "EncryptInit failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(10);
|
||||
}
|
||||
} else 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 (mode == EVP_CIPH_GCM_MODE || mode == EVP_CIPH_CCM_MODE) {
|
||||
unsigned char rtag[16];
|
||||
/*
|
||||
* Note: EVP_CTRL_CCM_GET_TAG has same value as
|
||||
* EVP_CTRL_GCM_GET_TAG
|
||||
*/
|
||||
if (!EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_GCM_GET_TAG, tn, rtag)) {
|
||||
fprintf(stderr, "Get tag failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(14);
|
||||
}
|
||||
if (memcmp(rtag, tag, tn)) {
|
||||
fprintf(stderr, "Tag mismatch\n");
|
||||
hexdump(stderr, "Got", rtag, tn);
|
||||
hexdump(stderr, "Expected", tag, tn);
|
||||
test1_exit(9);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (encdec <= 0) {
|
||||
if (mode == EVP_CIPH_GCM_MODE) {
|
||||
if (!EVP_DecryptInit_ex(&ctx, c, NULL, NULL, NULL)) {
|
||||
fprintf(stderr, "EncryptInit failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(10);
|
||||
}
|
||||
if (!EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_GCM_SET_IVLEN, in, NULL)) {
|
||||
fprintf(stderr, "IV length set failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(11);
|
||||
}
|
||||
if (!EVP_DecryptInit_ex(&ctx, NULL, NULL, key, iv)) {
|
||||
fprintf(stderr, "Key/IV set failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(12);
|
||||
}
|
||||
if (!EVP_CIPHER_CTX_ctrl
|
||||
(&ctx, EVP_CTRL_GCM_SET_TAG, tn, (void *)tag)) {
|
||||
fprintf(stderr, "Set tag failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(14);
|
||||
}
|
||||
if (an && !EVP_DecryptUpdate(&ctx, NULL, &outl, aad, an)) {
|
||||
fprintf(stderr, "AAD set failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(13);
|
||||
}
|
||||
} else if (mode == EVP_CIPH_CCM_MODE) {
|
||||
if (!EVP_DecryptInit_ex(&ctx, c, NULL, NULL, NULL)) {
|
||||
fprintf(stderr, "DecryptInit failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(10);
|
||||
}
|
||||
if (!EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_CCM_SET_IVLEN, in, NULL)) {
|
||||
fprintf(stderr, "IV length set failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(11);
|
||||
}
|
||||
if (!EVP_CIPHER_CTX_ctrl
|
||||
(&ctx, EVP_CTRL_CCM_SET_TAG, tn, (void *)tag)) {
|
||||
fprintf(stderr, "Tag length set failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(11);
|
||||
}
|
||||
if (!EVP_DecryptInit_ex(&ctx, NULL, NULL, key, iv)) {
|
||||
fprintf(stderr, "Key/Nonce set failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(12);
|
||||
}
|
||||
if (!EVP_DecryptUpdate(&ctx, NULL, &outl, NULL, pn)) {
|
||||
fprintf(stderr, "Plaintext length set failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(12);
|
||||
}
|
||||
if (an && !EVP_EncryptUpdate(&ctx, NULL, &outl, aad, an)) {
|
||||
fprintf(stderr, "AAD set failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(13);
|
||||
}
|
||||
} else if (mode == EVP_CIPH_WRAP_MODE) {
|
||||
if (!EVP_DecryptInit_ex(&ctx, c, NULL, key, in ? iv : NULL)) {
|
||||
fprintf(stderr, "EncryptInit failed\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
test1_exit(10);
|
||||
}
|
||||
} else 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 (mode != EVP_CIPH_CCM_MODE
|
||||
&& !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,
|
||||
const unsigned char *aad, int an,
|
||||
const unsigned char *tag, int tn, 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, aad, an, tag, tn,
|
||||
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 <test file>\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);
|
||||
}
|
||||
ERR_load_crypto_strings();
|
||||
/* 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, *aad, *tag;
|
||||
int encdec;
|
||||
int kn, in, pn, cn;
|
||||
int an = 0;
|
||||
int tn = 0;
|
||||
|
||||
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') {
|
||||
encdec = -1;
|
||||
p[-1] = '\0';
|
||||
tag = aad = NULL;
|
||||
an = tn = 0;
|
||||
} else {
|
||||
aad = ustrsep(&p, ":");
|
||||
tag = ustrsep(&p, ":");
|
||||
if (tag == NULL) {
|
||||
p = (char *)aad;
|
||||
tag = aad = NULL;
|
||||
an = tn = 0;
|
||||
}
|
||||
if (p[-1] == '\n') {
|
||||
encdec = -1;
|
||||
p[-1] = '\0';
|
||||
} else
|
||||
encdec = atoi(sstrsep(&p, "\n"));
|
||||
}
|
||||
|
||||
kn = convert(key);
|
||||
in = convert(iv);
|
||||
pn = convert(plaintext);
|
||||
cn = convert(ciphertext);
|
||||
if (aad) {
|
||||
an = convert(aad);
|
||||
tn = convert(tag);
|
||||
}
|
||||
|
||||
if (!test_cipher
|
||||
(cipher, key, kn, iv, in, plaintext, pn, ciphertext, cn, aad, an,
|
||||
tag, tn, 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;
|
||||
}
|
||||
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/bn/exptest.c
|
||||
@@ -0,0 +1,249 @@
|
||||
/* crypto/bn/exptest.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#define NUM_BITS (BN_BITS*2)
|
||||
|
||||
static const char rnd_seed[] =
|
||||
"string to make the random number generator think it has entropy";
|
||||
|
||||
/*
|
||||
* test_exp_mod_zero tests that x**0 mod 1 == 0. It returns zero on success.
|
||||
*/
|
||||
static int test_exp_mod_zero()
|
||||
{
|
||||
BIGNUM a, p, m;
|
||||
BIGNUM r;
|
||||
BN_CTX *ctx = BN_CTX_new();
|
||||
int ret = 1;
|
||||
|
||||
BN_init(&m);
|
||||
BN_one(&m);
|
||||
|
||||
BN_init(&a);
|
||||
BN_one(&a);
|
||||
|
||||
BN_init(&p);
|
||||
BN_zero(&p);
|
||||
|
||||
BN_init(&r);
|
||||
BN_mod_exp(&r, &a, &p, &m, ctx);
|
||||
BN_CTX_free(ctx);
|
||||
|
||||
if (BN_is_zero(&r))
|
||||
ret = 0;
|
||||
else {
|
||||
printf("1**0 mod 1 = ");
|
||||
BN_print_fp(stdout, &r);
|
||||
printf(", should be 0\n");
|
||||
}
|
||||
|
||||
BN_free(&r);
|
||||
BN_free(&a);
|
||||
BN_free(&p);
|
||||
BN_free(&m);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
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("\n");
|
||||
|
||||
if (test_exp_mod_zero() != 0)
|
||||
goto err;
|
||||
|
||||
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);
|
||||
}
|
||||
Executable → Regular
@@ -1 +0,0 @@
|
||||
../ssl/heartbeat_test.c
|
||||
@@ -0,0 +1,474 @@
|
||||
/* test/heartbeat_test.c */
|
||||
/*-
|
||||
* Unit test for TLS heartbeats.
|
||||
*
|
||||
* Acts as a regression test against the Heartbleed bug (CVE-2014-0160).
|
||||
*
|
||||
* Author: Mike Bland (mbland@acm.org, http://mike-bland.com/)
|
||||
* Date: 2014-04-12
|
||||
* License: Creative Commons Attribution 4.0 International (CC By 4.0)
|
||||
* http://creativecommons.org/licenses/by/4.0/deed.en_US
|
||||
*
|
||||
* OUTPUT
|
||||
* ------
|
||||
* The program returns zero on success. It will print a message with a count
|
||||
* of the number of failed tests and return nonzero if any tests fail.
|
||||
*
|
||||
* It will print the contents of the request and response buffers for each
|
||||
* failing test. In a "fixed" version, all the tests should pass and there
|
||||
* should be no output.
|
||||
*
|
||||
* In a "bleeding" version, you'll see:
|
||||
*
|
||||
* test_dtls1_heartbleed failed:
|
||||
* expected payload len: 0
|
||||
* received: 1024
|
||||
* sent 26 characters
|
||||
* "HEARTBLEED "
|
||||
* received 1024 characters
|
||||
* "HEARTBLEED \xde\xad\xbe\xef..."
|
||||
* ** test_dtls1_heartbleed failed **
|
||||
*
|
||||
* The contents of the returned buffer in the failing test will depend on the
|
||||
* contents of memory on your machine.
|
||||
*
|
||||
* MORE INFORMATION
|
||||
* ----------------
|
||||
* http://mike-bland.com/2014/04/12/heartbleed.html
|
||||
* http://mike-bland.com/tags/heartbleed.html
|
||||
*/
|
||||
|
||||
#define OPENSSL_UNIT_TEST
|
||||
|
||||
#include "../test/testutil.h"
|
||||
|
||||
#include "../ssl/ssl_locl.h"
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_HEARTBEATS) && !defined(OPENSSL_NO_UNIT_TEST)
|
||||
|
||||
/* As per https://tools.ietf.org/html/rfc6520#section-4 */
|
||||
# define MIN_PADDING_SIZE 16
|
||||
|
||||
/* Maximum number of payload characters to print as test output */
|
||||
# define MAX_PRINTABLE_CHARACTERS 1024
|
||||
|
||||
typedef struct heartbeat_test_fixture {
|
||||
SSL_CTX *ctx;
|
||||
SSL *s;
|
||||
const char *test_case_name;
|
||||
int (*process_heartbeat) (SSL *s);
|
||||
unsigned char *payload;
|
||||
int sent_payload_len;
|
||||
int expected_return_value;
|
||||
int return_payload_offset;
|
||||
int expected_payload_len;
|
||||
const char *expected_return_payload;
|
||||
} HEARTBEAT_TEST_FIXTURE;
|
||||
|
||||
static HEARTBEAT_TEST_FIXTURE set_up(const char *const test_case_name,
|
||||
const SSL_METHOD *meth)
|
||||
{
|
||||
HEARTBEAT_TEST_FIXTURE fixture;
|
||||
int setup_ok = 1;
|
||||
memset(&fixture, 0, sizeof(fixture));
|
||||
fixture.test_case_name = test_case_name;
|
||||
|
||||
fixture.ctx = SSL_CTX_new(meth);
|
||||
if (!fixture.ctx) {
|
||||
fprintf(stderr, "Failed to allocate SSL_CTX for test: %s\n",
|
||||
test_case_name);
|
||||
setup_ok = 0;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
fixture.s = SSL_new(fixture.ctx);
|
||||
if (!fixture.s) {
|
||||
fprintf(stderr, "Failed to allocate SSL for test: %s\n",
|
||||
test_case_name);
|
||||
setup_ok = 0;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!ssl_init_wbio_buffer(fixture.s, 1)) {
|
||||
fprintf(stderr, "Failed to set up wbio buffer for test: %s\n",
|
||||
test_case_name);
|
||||
setup_ok = 0;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!ssl3_setup_buffers(fixture.s)) {
|
||||
fprintf(stderr, "Failed to setup buffers for test: %s\n",
|
||||
test_case_name);
|
||||
setup_ok = 0;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/*
|
||||
* Clear the memory for the return buffer, since this isn't automatically
|
||||
* zeroed in opt mode and will cause spurious test failures that will
|
||||
* change with each execution.
|
||||
*/
|
||||
memset(fixture.s->s3->wbuf.buf, 0, fixture.s->s3->wbuf.len);
|
||||
|
||||
fail:
|
||||
if (!setup_ok) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return fixture;
|
||||
}
|
||||
|
||||
static HEARTBEAT_TEST_FIXTURE set_up_dtls(const char *const test_case_name)
|
||||
{
|
||||
HEARTBEAT_TEST_FIXTURE fixture = set_up(test_case_name,
|
||||
DTLSv1_server_method());
|
||||
fixture.process_heartbeat = dtls1_process_heartbeat;
|
||||
|
||||
/*
|
||||
* As per dtls1_get_record(), skipping the following from the beginning
|
||||
* of the returned heartbeat message: type-1 byte; version-2 bytes;
|
||||
* sequence number-8 bytes; length-2 bytes And then skipping the 1-byte
|
||||
* type encoded by process_heartbeat for a total of 14 bytes, at which
|
||||
* point we can grab the length and the payload we seek.
|
||||
*/
|
||||
fixture.return_payload_offset = 14;
|
||||
return fixture;
|
||||
}
|
||||
|
||||
/* Needed by ssl3_write_bytes() */
|
||||
static int dummy_handshake(SSL *s)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static HEARTBEAT_TEST_FIXTURE set_up_tls(const char *const test_case_name)
|
||||
{
|
||||
HEARTBEAT_TEST_FIXTURE fixture = set_up(test_case_name,
|
||||
TLSv1_server_method());
|
||||
fixture.process_heartbeat = tls1_process_heartbeat;
|
||||
fixture.s->handshake_func = dummy_handshake;
|
||||
|
||||
/*
|
||||
* As per do_ssl3_write(), skipping the following from the beginning of
|
||||
* the returned heartbeat message: type-1 byte; version-2 bytes; length-2
|
||||
* bytes And then skipping the 1-byte type encoded by process_heartbeat
|
||||
* for a total of 6 bytes, at which point we can grab the length and the
|
||||
* payload we seek.
|
||||
*/
|
||||
fixture.return_payload_offset = 6;
|
||||
return fixture;
|
||||
}
|
||||
|
||||
static void tear_down(HEARTBEAT_TEST_FIXTURE fixture)
|
||||
{
|
||||
ERR_print_errors_fp(stderr);
|
||||
SSL_free(fixture.s);
|
||||
SSL_CTX_free(fixture.ctx);
|
||||
}
|
||||
|
||||
static void print_payload(const char *const prefix,
|
||||
const unsigned char *payload, const int n)
|
||||
{
|
||||
const int end = n < MAX_PRINTABLE_CHARACTERS ? n
|
||||
: MAX_PRINTABLE_CHARACTERS;
|
||||
int i = 0;
|
||||
|
||||
printf("%s %d character%s", prefix, n, n == 1 ? "" : "s");
|
||||
if (end != n)
|
||||
printf(" (first %d shown)", end);
|
||||
printf("\n \"");
|
||||
|
||||
for (; i != end; ++i) {
|
||||
const unsigned char c = payload[i];
|
||||
if (isprint(c))
|
||||
fputc(c, stdout);
|
||||
else
|
||||
printf("\\x%02x", c);
|
||||
}
|
||||
printf("\"\n");
|
||||
}
|
||||
|
||||
static int execute_heartbeat(HEARTBEAT_TEST_FIXTURE fixture)
|
||||
{
|
||||
int result = 0;
|
||||
SSL *s = fixture.s;
|
||||
unsigned char *payload = fixture.payload;
|
||||
unsigned char sent_buf[MAX_PRINTABLE_CHARACTERS + 1];
|
||||
int return_value;
|
||||
unsigned const char *p;
|
||||
int actual_payload_len;
|
||||
|
||||
s->s3->rrec.data = payload;
|
||||
s->s3->rrec.length = strlen((const char *)payload);
|
||||
*payload++ = TLS1_HB_REQUEST;
|
||||
s2n(fixture.sent_payload_len, payload);
|
||||
|
||||
/*
|
||||
* Make a local copy of the request, since it gets overwritten at some
|
||||
* point
|
||||
*/
|
||||
memcpy((char *)sent_buf, (const char *)payload, sizeof(sent_buf));
|
||||
|
||||
return_value = fixture.process_heartbeat(s);
|
||||
|
||||
if (return_value != fixture.expected_return_value) {
|
||||
printf("%s failed: expected return value %d, received %d\n",
|
||||
fixture.test_case_name, fixture.expected_return_value,
|
||||
return_value);
|
||||
result = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* If there is any byte alignment, it will be stored in wbuf.offset.
|
||||
*/
|
||||
p = &(s->s3->
|
||||
wbuf.buf[fixture.return_payload_offset + s->s3->wbuf.offset]);
|
||||
actual_payload_len = 0;
|
||||
n2s(p, actual_payload_len);
|
||||
|
||||
if (actual_payload_len != fixture.expected_payload_len) {
|
||||
printf("%s failed:\n expected payload len: %d\n received: %d\n",
|
||||
fixture.test_case_name, fixture.expected_payload_len,
|
||||
actual_payload_len);
|
||||
print_payload("sent", sent_buf, strlen((const char *)sent_buf));
|
||||
print_payload("received", p, actual_payload_len);
|
||||
result = 1;
|
||||
} else {
|
||||
char *actual_payload =
|
||||
BUF_strndup((const char *)p, actual_payload_len);
|
||||
if (strcmp(actual_payload, fixture.expected_return_payload) != 0) {
|
||||
printf
|
||||
("%s failed:\n expected payload: \"%s\"\n received: \"%s\"\n",
|
||||
fixture.test_case_name, fixture.expected_return_payload,
|
||||
actual_payload);
|
||||
result = 1;
|
||||
}
|
||||
OPENSSL_free(actual_payload);
|
||||
}
|
||||
|
||||
if (result != 0) {
|
||||
printf("** %s failed **\n--------\n", fixture.test_case_name);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static int honest_payload_size(unsigned char payload_buf[])
|
||||
{
|
||||
/* Omit three-byte pad at the beginning for type and payload length */
|
||||
return strlen((const char *)&payload_buf[3]) - MIN_PADDING_SIZE;
|
||||
}
|
||||
|
||||
# define SETUP_HEARTBEAT_TEST_FIXTURE(type)\
|
||||
SETUP_TEST_FIXTURE(HEARTBEAT_TEST_FIXTURE, set_up_##type)
|
||||
|
||||
# define EXECUTE_HEARTBEAT_TEST()\
|
||||
EXECUTE_TEST(execute_heartbeat, tear_down)
|
||||
|
||||
static int test_dtls1_not_bleeding()
|
||||
{
|
||||
SETUP_HEARTBEAT_TEST_FIXTURE(dtls);
|
||||
/* Three-byte pad at the beginning for type and payload length */
|
||||
unsigned char payload_buf[MAX_PRINTABLE_CHARACTERS + 4] =
|
||||
" Not bleeding, sixteen spaces of padding" " ";
|
||||
const int payload_buf_len = honest_payload_size(payload_buf);
|
||||
|
||||
fixture.payload = &payload_buf[0];
|
||||
fixture.sent_payload_len = payload_buf_len;
|
||||
fixture.expected_return_value = 0;
|
||||
fixture.expected_payload_len = payload_buf_len;
|
||||
fixture.expected_return_payload =
|
||||
"Not bleeding, sixteen spaces of padding";
|
||||
EXECUTE_HEARTBEAT_TEST();
|
||||
}
|
||||
|
||||
static int test_dtls1_not_bleeding_empty_payload()
|
||||
{
|
||||
int payload_buf_len;
|
||||
|
||||
SETUP_HEARTBEAT_TEST_FIXTURE(dtls);
|
||||
/*
|
||||
* Three-byte pad at the beginning for type and payload length, plus a
|
||||
* NUL at the end
|
||||
*/
|
||||
unsigned char payload_buf[4 + MAX_PRINTABLE_CHARACTERS];
|
||||
memset(payload_buf, ' ', MIN_PADDING_SIZE + 3);
|
||||
payload_buf[MIN_PADDING_SIZE + 3] = '\0';
|
||||
payload_buf_len = honest_payload_size(payload_buf);
|
||||
|
||||
fixture.payload = &payload_buf[0];
|
||||
fixture.sent_payload_len = payload_buf_len;
|
||||
fixture.expected_return_value = 0;
|
||||
fixture.expected_payload_len = payload_buf_len;
|
||||
fixture.expected_return_payload = "";
|
||||
EXECUTE_HEARTBEAT_TEST();
|
||||
}
|
||||
|
||||
static int test_dtls1_heartbleed()
|
||||
{
|
||||
SETUP_HEARTBEAT_TEST_FIXTURE(dtls);
|
||||
/* Three-byte pad at the beginning for type and payload length */
|
||||
unsigned char payload_buf[4 + MAX_PRINTABLE_CHARACTERS] =
|
||||
" HEARTBLEED ";
|
||||
|
||||
fixture.payload = &payload_buf[0];
|
||||
fixture.sent_payload_len = MAX_PRINTABLE_CHARACTERS;
|
||||
fixture.expected_return_value = 0;
|
||||
fixture.expected_payload_len = 0;
|
||||
fixture.expected_return_payload = "";
|
||||
EXECUTE_HEARTBEAT_TEST();
|
||||
}
|
||||
|
||||
static int test_dtls1_heartbleed_empty_payload()
|
||||
{
|
||||
SETUP_HEARTBEAT_TEST_FIXTURE(dtls);
|
||||
/*
|
||||
* Excluding the NUL at the end, one byte short of type + payload length
|
||||
* + minimum padding
|
||||
*/
|
||||
unsigned char payload_buf[MAX_PRINTABLE_CHARACTERS + 4];
|
||||
memset(payload_buf, ' ', MIN_PADDING_SIZE + 2);
|
||||
payload_buf[MIN_PADDING_SIZE + 2] = '\0';
|
||||
|
||||
fixture.payload = &payload_buf[0];
|
||||
fixture.sent_payload_len = MAX_PRINTABLE_CHARACTERS;
|
||||
fixture.expected_return_value = 0;
|
||||
fixture.expected_payload_len = 0;
|
||||
fixture.expected_return_payload = "";
|
||||
EXECUTE_HEARTBEAT_TEST();
|
||||
}
|
||||
|
||||
static int test_dtls1_heartbleed_excessive_plaintext_length()
|
||||
{
|
||||
SETUP_HEARTBEAT_TEST_FIXTURE(dtls);
|
||||
/*
|
||||
* Excluding the NUL at the end, one byte in excess of maximum allowed
|
||||
* heartbeat message length
|
||||
*/
|
||||
unsigned char payload_buf[SSL3_RT_MAX_PLAIN_LENGTH + 2];
|
||||
memset(payload_buf, ' ', sizeof(payload_buf));
|
||||
payload_buf[sizeof(payload_buf) - 1] = '\0';
|
||||
|
||||
fixture.payload = &payload_buf[0];
|
||||
fixture.sent_payload_len = honest_payload_size(payload_buf);
|
||||
fixture.expected_return_value = 0;
|
||||
fixture.expected_payload_len = 0;
|
||||
fixture.expected_return_payload = "";
|
||||
EXECUTE_HEARTBEAT_TEST();
|
||||
}
|
||||
|
||||
static int test_tls1_not_bleeding()
|
||||
{
|
||||
SETUP_HEARTBEAT_TEST_FIXTURE(tls);
|
||||
/* Three-byte pad at the beginning for type and payload length */
|
||||
unsigned char payload_buf[MAX_PRINTABLE_CHARACTERS + 4] =
|
||||
" Not bleeding, sixteen spaces of padding" " ";
|
||||
const int payload_buf_len = honest_payload_size(payload_buf);
|
||||
|
||||
fixture.payload = &payload_buf[0];
|
||||
fixture.sent_payload_len = payload_buf_len;
|
||||
fixture.expected_return_value = 0;
|
||||
fixture.expected_payload_len = payload_buf_len;
|
||||
fixture.expected_return_payload =
|
||||
"Not bleeding, sixteen spaces of padding";
|
||||
EXECUTE_HEARTBEAT_TEST();
|
||||
}
|
||||
|
||||
static int test_tls1_not_bleeding_empty_payload()
|
||||
{
|
||||
int payload_buf_len;
|
||||
|
||||
SETUP_HEARTBEAT_TEST_FIXTURE(tls);
|
||||
/*
|
||||
* Three-byte pad at the beginning for type and payload length, plus a
|
||||
* NUL at the end
|
||||
*/
|
||||
unsigned char payload_buf[4 + MAX_PRINTABLE_CHARACTERS];
|
||||
memset(payload_buf, ' ', MIN_PADDING_SIZE + 3);
|
||||
payload_buf[MIN_PADDING_SIZE + 3] = '\0';
|
||||
payload_buf_len = honest_payload_size(payload_buf);
|
||||
|
||||
fixture.payload = &payload_buf[0];
|
||||
fixture.sent_payload_len = payload_buf_len;
|
||||
fixture.expected_return_value = 0;
|
||||
fixture.expected_payload_len = payload_buf_len;
|
||||
fixture.expected_return_payload = "";
|
||||
EXECUTE_HEARTBEAT_TEST();
|
||||
}
|
||||
|
||||
static int test_tls1_heartbleed()
|
||||
{
|
||||
SETUP_HEARTBEAT_TEST_FIXTURE(tls);
|
||||
/* Three-byte pad at the beginning for type and payload length */
|
||||
unsigned char payload_buf[MAX_PRINTABLE_CHARACTERS + 4] =
|
||||
" HEARTBLEED ";
|
||||
|
||||
fixture.payload = &payload_buf[0];
|
||||
fixture.sent_payload_len = MAX_PRINTABLE_CHARACTERS;
|
||||
fixture.expected_return_value = 0;
|
||||
fixture.expected_payload_len = 0;
|
||||
fixture.expected_return_payload = "";
|
||||
EXECUTE_HEARTBEAT_TEST();
|
||||
}
|
||||
|
||||
static int test_tls1_heartbleed_empty_payload()
|
||||
{
|
||||
SETUP_HEARTBEAT_TEST_FIXTURE(tls);
|
||||
/*
|
||||
* Excluding the NUL at the end, one byte short of type + payload length
|
||||
* + minimum padding
|
||||
*/
|
||||
unsigned char payload_buf[MAX_PRINTABLE_CHARACTERS + 4];
|
||||
memset(payload_buf, ' ', MIN_PADDING_SIZE + 2);
|
||||
payload_buf[MIN_PADDING_SIZE + 2] = '\0';
|
||||
|
||||
fixture.payload = &payload_buf[0];
|
||||
fixture.sent_payload_len = MAX_PRINTABLE_CHARACTERS;
|
||||
fixture.expected_return_value = 0;
|
||||
fixture.expected_payload_len = 0;
|
||||
fixture.expected_return_payload = "";
|
||||
EXECUTE_HEARTBEAT_TEST();
|
||||
}
|
||||
|
||||
# undef EXECUTE_HEARTBEAT_TEST
|
||||
# undef SETUP_HEARTBEAT_TEST_FIXTURE
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int num_failed;
|
||||
|
||||
SSL_library_init();
|
||||
SSL_load_error_strings();
|
||||
|
||||
num_failed = test_dtls1_not_bleeding() +
|
||||
test_dtls1_not_bleeding_empty_payload() +
|
||||
test_dtls1_heartbleed() + test_dtls1_heartbleed_empty_payload() +
|
||||
/*
|
||||
* The following test causes an assertion failure at
|
||||
* ssl/d1_pkt.c:dtls1_write_bytes() in versions prior to 1.0.1g:
|
||||
*/
|
||||
(OPENSSL_VERSION_NUMBER >= 0x1000107fL ?
|
||||
test_dtls1_heartbleed_excessive_plaintext_length() : 0) +
|
||||
test_tls1_not_bleeding() +
|
||||
test_tls1_not_bleeding_empty_payload() +
|
||||
test_tls1_heartbleed() + test_tls1_heartbleed_empty_payload() + 0;
|
||||
|
||||
ERR_print_errors_fp(stderr);
|
||||
|
||||
if (num_failed != 0) {
|
||||
printf("%d test%s failed\n", num_failed, num_failed != 1 ? "s" : "");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
#else /* OPENSSL_NO_HEARTBEATS */
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#endif /* OPENSSL_NO_HEARTBEATS */
|
||||
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/hmac/hmactest.c
|
||||
@@ -0,0 +1,167 @@
|
||||
/* 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 <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
#ifdef OPENSSL_NO_HMAC
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No HMAC support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/hmac.h>
|
||||
# ifndef OPENSSL_NO_MD5
|
||||
# include <openssl/md5.h>
|
||||
# endif
|
||||
|
||||
# ifdef CHARSET_EBCDIC
|
||||
# include <openssl/ebcdic.h>
|
||||
# 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
|
||||
|
||||
# ifdef CHARSET_EBCDIC
|
||||
ebcdic2ascii(test[0].data, test[0].data, test[0].data_len);
|
||||
ebcdic2ascii(test[1].data, test[1].data, test[1].data_len);
|
||||
ebcdic2ascii(test[2].key, test[2].key, test[2].key_len);
|
||||
ebcdic2ascii(test[2].data, test[2].data, test[2].data_len);
|
||||
# endif
|
||||
|
||||
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 < MD5_DIGEST_LENGTH; i++)
|
||||
sprintf(&(buf[i * 2]), "%02x", md[i]);
|
||||
return (buf);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/idea/ideatest.c
|
||||
@@ -0,0 +1,232 @@
|
||||
/* crypto/idea/ideatest.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
#ifdef OPENSSL_NO_IDEA
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No IDEA support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/idea.h>
|
||||
|
||||
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 < CFB_TEST_SIZE; i += 8)
|
||||
printf("%s\n", pt(&(cfb_buf1[i])));
|
||||
}
|
||||
memcpy(cfb_tmp, cfb_iv, 8);
|
||||
n = 0;
|
||||
idea_cfb64_encrypt(cfb_buf1, cfb_buf2, (long)13, &eks,
|
||||
cfb_tmp, &n, IDEA_DECRYPT);
|
||||
idea_cfb64_encrypt(&(cfb_buf1[13]), &(cfb_buf2[13]),
|
||||
(long)CFB_TEST_SIZE - 13, &eks,
|
||||
cfb_tmp, &n, IDEA_DECRYPT);
|
||||
if (memcmp(plain, cfb_buf2, CFB_TEST_SIZE) != 0) {
|
||||
err = 1;
|
||||
printf("idea_cfb_encrypt decrypt error\n");
|
||||
for (i = 0; i < 24; i += 8)
|
||||
printf("%s\n", pt(&(cfb_buf2[i])));
|
||||
}
|
||||
return (err);
|
||||
}
|
||||
|
||||
static char *pt(unsigned char *p)
|
||||
{
|
||||
static char bufs[10][20];
|
||||
static int bnum = 0;
|
||||
char *ret;
|
||||
int i;
|
||||
static char *f = "0123456789ABCDEF";
|
||||
|
||||
ret = &(bufs[bnum++][0]);
|
||||
bnum %= 10;
|
||||
for (i = 0; i < 8; i++) {
|
||||
ret[i * 2] = f[(p[i] >> 4) & 0xf];
|
||||
ret[i * 2 + 1] = f[p[i] & 0xf];
|
||||
}
|
||||
ret[16] = '\0';
|
||||
return (ret);
|
||||
}
|
||||
#endif
|
||||
Executable → Regular
Executable → Regular
@@ -1 +0,0 @@
|
||||
dummytest.c
|
||||
@@ -0,0 +1,57 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <openssl/e_os2.h>
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/crypto.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char *p, *q = 0, *program;
|
||||
|
||||
p = strrchr(argv[0], '/');
|
||||
if (!p)
|
||||
p = strrchr(argv[0], '\\');
|
||||
#ifdef OPENSSL_SYS_VMS
|
||||
if (!p)
|
||||
p = strrchr(argv[0], ']');
|
||||
if (p)
|
||||
q = strrchr(p, '>');
|
||||
if (q)
|
||||
p = q;
|
||||
if (!p)
|
||||
p = strrchr(argv[0], ':');
|
||||
q = 0;
|
||||
#endif
|
||||
if (p)
|
||||
p++;
|
||||
if (!p)
|
||||
p = argv[0];
|
||||
if (p)
|
||||
q = strchr(p, '.');
|
||||
if (p && !q)
|
||||
q = p + strlen(p);
|
||||
|
||||
if (!p)
|
||||
program = BUF_strdup("(unknown)");
|
||||
else {
|
||||
program = OPENSSL_malloc((q - p) + 1);
|
||||
strncpy(program, p, q - p);
|
||||
program[q - p] = '\0';
|
||||
}
|
||||
|
||||
for (p = program; *p; p++)
|
||||
if (islower((unsigned char)(*p)))
|
||||
*p = toupper((unsigned char)(*p));
|
||||
|
||||
q = strstr(program, "TEST");
|
||||
if (q > p && q[-1] == '_')
|
||||
q--;
|
||||
*q = '\0';
|
||||
|
||||
printf("No %s support\n", program);
|
||||
|
||||
OPENSSL_free(program);
|
||||
return (0);
|
||||
}
|
||||
Executable → Regular
@@ -1 +0,0 @@
|
||||
dummytest.c
|
||||
@@ -0,0 +1,57 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <openssl/e_os2.h>
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/crypto.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char *p, *q = 0, *program;
|
||||
|
||||
p = strrchr(argv[0], '/');
|
||||
if (!p)
|
||||
p = strrchr(argv[0], '\\');
|
||||
#ifdef OPENSSL_SYS_VMS
|
||||
if (!p)
|
||||
p = strrchr(argv[0], ']');
|
||||
if (p)
|
||||
q = strrchr(p, '>');
|
||||
if (q)
|
||||
p = q;
|
||||
if (!p)
|
||||
p = strrchr(argv[0], ':');
|
||||
q = 0;
|
||||
#endif
|
||||
if (p)
|
||||
p++;
|
||||
if (!p)
|
||||
p = argv[0];
|
||||
if (p)
|
||||
q = strchr(p, '.');
|
||||
if (p && !q)
|
||||
q = p + strlen(p);
|
||||
|
||||
if (!p)
|
||||
program = BUF_strdup("(unknown)");
|
||||
else {
|
||||
program = OPENSSL_malloc((q - p) + 1);
|
||||
strncpy(program, p, q - p);
|
||||
program[q - p] = '\0';
|
||||
}
|
||||
|
||||
for (p = program; *p; p++)
|
||||
if (islower((unsigned char)(*p)))
|
||||
*p = toupper((unsigned char)(*p));
|
||||
|
||||
q = strstr(program, "TEST");
|
||||
if (q > p && q[-1] == '_')
|
||||
q--;
|
||||
*q = '\0';
|
||||
|
||||
printf("No %s support\n", program);
|
||||
|
||||
OPENSSL_free(program);
|
||||
return (0);
|
||||
}
|
||||
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/md4/md4test.c
|
||||
@@ -0,0 +1,133 @@
|
||||
/* crypto/md4/md4test.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
#ifdef OPENSSL_NO_MD4
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No MD4 support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/md4.h>
|
||||
|
||||
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 < MD4_DIGEST_LENGTH; i++)
|
||||
sprintf(&(buf[i * 2]), "%02x", md[i]);
|
||||
return (buf);
|
||||
}
|
||||
#endif
|
||||
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/md5/md5test.c
|
||||
@@ -0,0 +1,138 @@
|
||||
/* crypto/md5/md5test.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
#ifdef OPENSSL_NO_MD5
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No MD5 support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/md5.h>
|
||||
|
||||
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 < MD5_DIGEST_LENGTH; i++)
|
||||
sprintf(&(buf[i * 2]), "%02x", md[i]);
|
||||
return (buf);
|
||||
}
|
||||
#endif
|
||||
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/mdc2/mdc2test.c
|
||||
@@ -0,0 +1,146 @@
|
||||
/* crypto/mdc2/mdc2test.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#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 <openssl/evp.h>
|
||||
# include <openssl/mdc2.h>
|
||||
|
||||
# ifdef CHARSET_EBCDIC
|
||||
# include <openssl/ebcdic.h>
|
||||
# endif
|
||||
|
||||
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 ";
|
||||
|
||||
# ifdef CHARSET_EBCDIC
|
||||
ebcdic2ascii(text, text, strlen(text));
|
||||
# endif
|
||||
|
||||
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; i < MDC2_DIGEST_LENGTH; i++)
|
||||
printf("%02X", md[i]);
|
||||
printf(" <- generated\n");
|
||||
for (i = 0; i < MDC2_DIGEST_LENGTH; i++)
|
||||
printf("%02X", pad1[i]);
|
||||
printf(" <- correct\n");
|
||||
ret = 1;
|
||||
} else
|
||||
printf("pad1 - ok\n");
|
||||
|
||||
EVP_DigestInit_ex(&c, EVP_mdc2(), NULL);
|
||||
/* FIXME: use a ctl function? */
|
||||
((MDC2_CTX *)c.md_data)->pad_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 < MDC2_DIGEST_LENGTH; i++)
|
||||
printf("%02X", md[i]);
|
||||
printf(" <- generated\n");
|
||||
for (i = 0; i < MDC2_DIGEST_LENGTH; i++)
|
||||
printf("%02X", pad2[i]);
|
||||
printf(" <- correct\n");
|
||||
ret = 1;
|
||||
} else
|
||||
printf("pad2 - ok\n");
|
||||
|
||||
EVP_MD_CTX_cleanup(&c);
|
||||
# ifdef OPENSSL_SYS_NETWARE
|
||||
if (ret)
|
||||
printf("ERROR: %d\n", ret);
|
||||
# endif
|
||||
EXIT(ret);
|
||||
return (ret);
|
||||
}
|
||||
#endif
|
||||
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/rand/randtest.c
|
||||
@@ -0,0 +1,209 @@
|
||||
/* crypto/rand/randtest.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <openssl/rand.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/rc2/rc2test.c
|
||||
@@ -0,0 +1,274 @@
|
||||
/* 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 <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
#ifdef OPENSSL_NO_RC2
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No RC2 support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/rc2.h>
|
||||
|
||||
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 < CFB_TEST_SIZE; i += 8)
|
||||
printf("%s\n", pt(&(cfb_buf1[i])));
|
||||
}
|
||||
memcpy(cfb_tmp, cfb_iv, 8);
|
||||
n = 0;
|
||||
idea_cfb64_encrypt(cfb_buf1, cfb_buf2, (long)17, &eks,
|
||||
cfb_tmp, &n, IDEA_DECRYPT);
|
||||
idea_cfb64_encrypt(&(cfb_buf1[17]), &(cfb_buf2[17]),
|
||||
(long)CFB_TEST_SIZE - 17, &dks,
|
||||
cfb_tmp, &n, IDEA_DECRYPT);
|
||||
if (memcmp(plain, cfb_buf2, CFB_TEST_SIZE) != 0) {
|
||||
err = 1;
|
||||
printf("idea_cfb_encrypt decrypt error\n");
|
||||
for (i = 0; i < 24; i += 8)
|
||||
printf("%s\n", pt(&(cfb_buf2[i])));
|
||||
}
|
||||
return (err);
|
||||
}
|
||||
|
||||
static char *pt(unsigned char *p)
|
||||
{
|
||||
static char bufs[10][20];
|
||||
static int bnum = 0;
|
||||
char *ret;
|
||||
int i;
|
||||
static char *f = "0123456789ABCDEF";
|
||||
|
||||
ret = &(bufs[bnum++][0]);
|
||||
bnum %= 10;
|
||||
for (i = 0; i < 8; i++) {
|
||||
ret[i * 2] = f[(p[i] >> 4) & 0xf];
|
||||
ret[i * 2 + 1] = f[p[i] & 0xf];
|
||||
}
|
||||
ret[16] = '\0';
|
||||
return (ret);
|
||||
}
|
||||
|
||||
# endif
|
||||
#endif
|
||||
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/rc4/rc4test.c
|
||||
@@ -0,0 +1,235 @@
|
||||
/* 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
#ifdef OPENSSL_NO_RC4
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No RC4 support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/rc4.h>
|
||||
# include <openssl/sha.h>
|
||||
|
||||
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 < data_len[i] + 1; j++)
|
||||
printf(" %02x", obuf[j]);
|
||||
printf("\n");
|
||||
printf("expect:");
|
||||
p = &(output[i][0]);
|
||||
for (j = 0; j < data_len[i] + 1; j++)
|
||||
printf(" %02x", *(p++));
|
||||
printf("\n");
|
||||
err++;
|
||||
} else
|
||||
printf("test %d ok\n", i);
|
||||
}
|
||||
printf("test end processing ");
|
||||
for (i = 0; i < data_len[3]; i++) {
|
||||
RC4_set_key(&key, keys[3][0], &(keys[3][1]));
|
||||
memset(obuf, 0x00, sizeof(obuf));
|
||||
RC4(&key, i, &(data[3][0]), obuf);
|
||||
if ((memcmp(obuf, output[3], i) != 0) || (obuf[i] != 0)) {
|
||||
printf("error in RC4 length processing\n");
|
||||
printf("output:");
|
||||
for (j = 0; j < i + 1; j++)
|
||||
printf(" %02x", obuf[j]);
|
||||
printf("\n");
|
||||
printf("expect:");
|
||||
p = &(output[3][0]);
|
||||
for (j = 0; j < i; j++)
|
||||
printf(" %02x", *(p++));
|
||||
printf(" 00\n");
|
||||
err++;
|
||||
} else {
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
printf("done\n");
|
||||
printf("test multi-call ");
|
||||
for (i = 0; i < data_len[3]; i++) {
|
||||
RC4_set_key(&key, keys[3][0], &(keys[3][1]));
|
||||
memset(obuf, 0x00, sizeof(obuf));
|
||||
RC4(&key, i, &(data[3][0]), obuf);
|
||||
RC4(&key, data_len[3] - i, &(data[3][i]), &(obuf[i]));
|
||||
if (memcmp(obuf, output[3], data_len[3] + 1) != 0) {
|
||||
printf("error in RC4 multi-call processing\n");
|
||||
printf("output:");
|
||||
for (j = 0; j < data_len[3] + 1; j++)
|
||||
printf(" %02x", obuf[j]);
|
||||
printf("\n");
|
||||
printf("expect:");
|
||||
p = &(output[3][0]);
|
||||
for (j = 0; j < data_len[3] + 1; j++)
|
||||
printf(" %02x", *(p++));
|
||||
err++;
|
||||
} else {
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
printf("done\n");
|
||||
printf("bulk test ");
|
||||
{
|
||||
unsigned char buf[513];
|
||||
SHA_CTX c;
|
||||
unsigned char md[SHA_DIGEST_LENGTH];
|
||||
static unsigned char expected[] = {
|
||||
0xa4, 0x7b, 0xcc, 0x00, 0x3d, 0xd0, 0xbd, 0xe1, 0xac, 0x5f,
|
||||
0x12, 0x1e, 0x45, 0xbc, 0xfb, 0x1a, 0xa1, 0xf2, 0x7f, 0xc5
|
||||
};
|
||||
|
||||
RC4_set_key(&key, keys[0][0], &(keys[3][1]));
|
||||
memset(buf, '\0', sizeof(buf));
|
||||
SHA1_Init(&c);
|
||||
for (i = 0; i < 2571; i++) {
|
||||
RC4(&key, sizeof(buf), buf, buf);
|
||||
SHA1_Update(&c, buf, sizeof(buf));
|
||||
}
|
||||
SHA1_Final(md, &c);
|
||||
|
||||
if (memcmp(md, expected, sizeof(md))) {
|
||||
printf("error in RC4 bulk test\n");
|
||||
printf("output:");
|
||||
for (j = 0; j < (int)sizeof(md); j++)
|
||||
printf(" %02x", md[j]);
|
||||
printf("\n");
|
||||
printf("expect:");
|
||||
for (j = 0; j < (int)sizeof(md); j++)
|
||||
printf(" %02x", expected[j]);
|
||||
printf("\n");
|
||||
err++;
|
||||
} else
|
||||
printf("ok\n");
|
||||
}
|
||||
# ifdef OPENSSL_SYS_NETWARE
|
||||
if (err)
|
||||
printf("ERROR: %d\n", err);
|
||||
# endif
|
||||
EXIT(err);
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
Executable → Regular
@@ -1 +0,0 @@
|
||||
dummytest.c
|
||||
@@ -0,0 +1,57 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <openssl/e_os2.h>
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/crypto.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char *p, *q = 0, *program;
|
||||
|
||||
p = strrchr(argv[0], '/');
|
||||
if (!p)
|
||||
p = strrchr(argv[0], '\\');
|
||||
#ifdef OPENSSL_SYS_VMS
|
||||
if (!p)
|
||||
p = strrchr(argv[0], ']');
|
||||
if (p)
|
||||
q = strrchr(p, '>');
|
||||
if (q)
|
||||
p = q;
|
||||
if (!p)
|
||||
p = strrchr(argv[0], ':');
|
||||
q = 0;
|
||||
#endif
|
||||
if (p)
|
||||
p++;
|
||||
if (!p)
|
||||
p = argv[0];
|
||||
if (p)
|
||||
q = strchr(p, '.');
|
||||
if (p && !q)
|
||||
q = p + strlen(p);
|
||||
|
||||
if (!p)
|
||||
program = BUF_strdup("(unknown)");
|
||||
else {
|
||||
program = OPENSSL_malloc((q - p) + 1);
|
||||
strncpy(program, p, q - p);
|
||||
program[q - p] = '\0';
|
||||
}
|
||||
|
||||
for (p = program; *p; p++)
|
||||
if (islower((unsigned char)(*p)))
|
||||
*p = toupper((unsigned char)(*p));
|
||||
|
||||
q = strstr(program, "TEST");
|
||||
if (q > p && q[-1] == '_')
|
||||
q--;
|
||||
*q = '\0';
|
||||
|
||||
printf("No %s support\n", program);
|
||||
|
||||
OPENSSL_free(program);
|
||||
return (0);
|
||||
}
|
||||
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/ripemd/rmdtest.c
|
||||
@@ -0,0 +1,143 @@
|
||||
/* crypto/ripemd/rmdtest.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
#ifdef OPENSSL_NO_RIPEMD
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No ripemd support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/ripemd.h>
|
||||
# include <openssl/evp.h>
|
||||
|
||||
# ifdef CHARSET_EBCDIC
|
||||
# include <openssl/ebcdic.h>
|
||||
# endif
|
||||
|
||||
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) {
|
||||
# ifdef CHARSET_EBCDIC
|
||||
ebcdic2ascii((char *)*P, (char *)*P, strlen((char *)*P));
|
||||
# endif
|
||||
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 < RIPEMD160_DIGEST_LENGTH; i++)
|
||||
sprintf(&(buf[i * 2]), "%02x", md[i]);
|
||||
return (buf);
|
||||
}
|
||||
#endif
|
||||
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/rsa/rsa_test.c
|
||||
@@ -0,0 +1,331 @@
|
||||
/* test vectors from p1ovect1.txt */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "e_os.h"
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/bn.h>
|
||||
#ifdef OPENSSL_NO_RSA
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No RSA support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/rsa.h>
|
||||
|
||||
# define SetKey \
|
||||
key->n = BN_bin2bn(n, sizeof(n)-1, key->n); \
|
||||
key->e = BN_bin2bn(e, sizeof(e)-1, key->e); \
|
||||
key->d = BN_bin2bn(d, sizeof(d)-1, key->d); \
|
||||
key->p = BN_bin2bn(p, sizeof(p)-1, key->p); \
|
||||
key->q = BN_bin2bn(q, sizeof(q)-1, key->q); \
|
||||
key->dmp1 = BN_bin2bn(dmp1, sizeof(dmp1)-1, key->dmp1); \
|
||||
key->dmq1 = BN_bin2bn(dmq1, sizeof(dmq1)-1, key->dmq1); \
|
||||
key->iqmp = BN_bin2bn(iqmp, sizeof(iqmp)-1, key->iqmp); \
|
||||
memcpy(c, ctext_ex, sizeof(ctext_ex) - 1); \
|
||||
return (sizeof(ctext_ex) - 1);
|
||||
|
||||
static int key1(RSA *key, unsigned char *c)
|
||||
{
|
||||
static unsigned char n[] =
|
||||
"\x00\xAA\x36\xAB\xCE\x88\xAC\xFD\xFF\x55\x52\x3C\x7F\xC4\x52\x3F"
|
||||
"\x90\xEF\xA0\x0D\xF3\x77\x4A\x25\x9F\x2E\x62\xB4\xC5\xD9\x9C\xB5"
|
||||
"\xAD\xB3\x00\xA0\x28\x5E\x53\x01\x93\x0E\x0C\x70\xFB\x68\x76\x93"
|
||||
"\x9C\xE6\x16\xCE\x62\x4A\x11\xE0\x08\x6D\x34\x1E\xBC\xAC\xA0\xA1"
|
||||
"\xF5";
|
||||
|
||||
static unsigned char e[] = "\x11";
|
||||
|
||||
static unsigned char d[] =
|
||||
"\x0A\x03\x37\x48\x62\x64\x87\x69\x5F\x5F\x30\xBC\x38\xB9\x8B\x44"
|
||||
"\xC2\xCD\x2D\xFF\x43\x40\x98\xCD\x20\xD8\xA1\x38\xD0\x90\xBF\x64"
|
||||
"\x79\x7C\x3F\xA7\xA2\xCD\xCB\x3C\xD1\xE0\xBD\xBA\x26\x54\xB4\xF9"
|
||||
"\xDF\x8E\x8A\xE5\x9D\x73\x3D\x9F\x33\xB3\x01\x62\x4A\xFD\x1D\x51";
|
||||
|
||||
static unsigned char p[] =
|
||||
"\x00\xD8\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5"
|
||||
"\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x12"
|
||||
"\x0D";
|
||||
|
||||
static unsigned char q[] =
|
||||
"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
|
||||
"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D"
|
||||
"\x89";
|
||||
|
||||
static unsigned char dmp1[] =
|
||||
"\x59\x0B\x95\x72\xA2\xC2\xA9\xC4\x06\x05\x9D\xC2\xAB\x2F\x1D\xAF"
|
||||
"\xEB\x7E\x8B\x4F\x10\xA7\x54\x9E\x8E\xED\xF5\xB4\xFC\xE0\x9E\x05";
|
||||
|
||||
static unsigned char dmq1[] =
|
||||
"\x00\x8E\x3C\x05\x21\xFE\x15\xE0\xEA\x06\xA3\x6F\xF0\xF1\x0C\x99"
|
||||
"\x52\xC3\x5B\x7A\x75\x14\xFD\x32\x38\xB8\x0A\xAD\x52\x98\x62\x8D"
|
||||
"\x51";
|
||||
|
||||
static unsigned char iqmp[] =
|
||||
"\x36\x3F\xF7\x18\x9D\xA8\xE9\x0B\x1D\x34\x1F\x71\xD0\x9B\x76\xA8"
|
||||
"\xA9\x43\xE1\x1D\x10\xB2\x4D\x24\x9F\x2D\xEA\xFE\xF8\x0C\x18\x26";
|
||||
|
||||
static unsigned char ctext_ex[] =
|
||||
"\x1b\x8f\x05\xf9\xca\x1a\x79\x52\x6e\x53\xf3\xcc\x51\x4f\xdb\x89"
|
||||
"\x2b\xfb\x91\x93\x23\x1e\x78\xb9\x92\xe6\x8d\x50\xa4\x80\xcb\x52"
|
||||
"\x33\x89\x5c\x74\x95\x8d\x5d\x02\xab\x8c\x0f\xd0\x40\xeb\x58\x44"
|
||||
"\xb0\x05\xc3\x9e\xd8\x27\x4a\x9d\xbf\xa8\x06\x71\x40\x94\x39\xd2";
|
||||
|
||||
SetKey;
|
||||
}
|
||||
|
||||
static int key2(RSA *key, unsigned char *c)
|
||||
{
|
||||
static unsigned char n[] =
|
||||
"\x00\xA3\x07\x9A\x90\xDF\x0D\xFD\x72\xAC\x09\x0C\xCC\x2A\x78\xB8"
|
||||
"\x74\x13\x13\x3E\x40\x75\x9C\x98\xFA\xF8\x20\x4F\x35\x8A\x0B\x26"
|
||||
"\x3C\x67\x70\xE7\x83\xA9\x3B\x69\x71\xB7\x37\x79\xD2\x71\x7B\xE8"
|
||||
"\x34\x77\xCF";
|
||||
|
||||
static unsigned char e[] = "\x3";
|
||||
|
||||
static unsigned char d[] =
|
||||
"\x6C\xAF\xBC\x60\x94\xB3\xFE\x4C\x72\xB0\xB3\x32\xC6\xFB\x25\xA2"
|
||||
"\xB7\x62\x29\x80\x4E\x68\x65\xFC\xA4\x5A\x74\xDF\x0F\x8F\xB8\x41"
|
||||
"\x3B\x52\xC0\xD0\xE5\x3D\x9B\x59\x0F\xF1\x9B\xE7\x9F\x49\xDD\x21"
|
||||
"\xE5\xEB";
|
||||
|
||||
static unsigned char p[] =
|
||||
"\x00\xCF\x20\x35\x02\x8B\x9D\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92"
|
||||
"\xEA\x0D\xA3\xB4\x32\x04\xB5\xCF\xCE\x91";
|
||||
|
||||
static unsigned char q[] =
|
||||
"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
|
||||
"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5F";
|
||||
|
||||
static unsigned char dmp1[] =
|
||||
"\x00\x8A\x15\x78\xAC\x5D\x13\xAF\x10\x2B\x22\xB9\x99\xCD\x74\x61"
|
||||
"\xF1\x5E\x6D\x22\xCC\x03\x23\xDF\xDF\x0B";
|
||||
|
||||
static unsigned char dmq1[] =
|
||||
"\x00\x86\x55\x21\x4A\xC5\x4D\x8D\x4E\xCD\x61\x77\xF1\xC7\x36\x90"
|
||||
"\xCE\x2A\x48\x2C\x8B\x05\x99\xCB\xE0\x3F";
|
||||
|
||||
static unsigned char iqmp[] =
|
||||
"\x00\x83\xEF\xEF\xB8\xA9\xA4\x0D\x1D\xB6\xED\x98\xAD\x84\xED\x13"
|
||||
"\x35\xDC\xC1\x08\xF3\x22\xD0\x57\xCF\x8D";
|
||||
|
||||
static unsigned char ctext_ex[] =
|
||||
"\x14\xbd\xdd\x28\xc9\x83\x35\x19\x23\x80\xe8\xe5\x49\xb1\x58\x2a"
|
||||
"\x8b\x40\xb4\x48\x6d\x03\xa6\xa5\x31\x1f\x1f\xd5\xf0\xa1\x80\xe4"
|
||||
"\x17\x53\x03\x29\xa9\x34\x90\x74\xb1\x52\x13\x54\x29\x08\x24\x52"
|
||||
"\x62\x51";
|
||||
|
||||
SetKey;
|
||||
}
|
||||
|
||||
static int key3(RSA *key, unsigned char *c)
|
||||
{
|
||||
static unsigned char n[] =
|
||||
"\x00\xBB\xF8\x2F\x09\x06\x82\xCE\x9C\x23\x38\xAC\x2B\x9D\xA8\x71"
|
||||
"\xF7\x36\x8D\x07\xEE\xD4\x10\x43\xA4\x40\xD6\xB6\xF0\x74\x54\xF5"
|
||||
"\x1F\xB8\xDF\xBA\xAF\x03\x5C\x02\xAB\x61\xEA\x48\xCE\xEB\x6F\xCD"
|
||||
"\x48\x76\xED\x52\x0D\x60\xE1\xEC\x46\x19\x71\x9D\x8A\x5B\x8B\x80"
|
||||
"\x7F\xAF\xB8\xE0\xA3\xDF\xC7\x37\x72\x3E\xE6\xB4\xB7\xD9\x3A\x25"
|
||||
"\x84\xEE\x6A\x64\x9D\x06\x09\x53\x74\x88\x34\xB2\x45\x45\x98\x39"
|
||||
"\x4E\xE0\xAA\xB1\x2D\x7B\x61\xA5\x1F\x52\x7A\x9A\x41\xF6\xC1\x68"
|
||||
"\x7F\xE2\x53\x72\x98\xCA\x2A\x8F\x59\x46\xF8\xE5\xFD\x09\x1D\xBD"
|
||||
"\xCB";
|
||||
|
||||
static unsigned char e[] = "\x11";
|
||||
|
||||
static unsigned char d[] =
|
||||
"\x00\xA5\xDA\xFC\x53\x41\xFA\xF2\x89\xC4\xB9\x88\xDB\x30\xC1\xCD"
|
||||
"\xF8\x3F\x31\x25\x1E\x06\x68\xB4\x27\x84\x81\x38\x01\x57\x96\x41"
|
||||
"\xB2\x94\x10\xB3\xC7\x99\x8D\x6B\xC4\x65\x74\x5E\x5C\x39\x26\x69"
|
||||
"\xD6\x87\x0D\xA2\xC0\x82\xA9\x39\xE3\x7F\xDC\xB8\x2E\xC9\x3E\xDA"
|
||||
"\xC9\x7F\xF3\xAD\x59\x50\xAC\xCF\xBC\x11\x1C\x76\xF1\xA9\x52\x94"
|
||||
"\x44\xE5\x6A\xAF\x68\xC5\x6C\x09\x2C\xD3\x8D\xC3\xBE\xF5\xD2\x0A"
|
||||
"\x93\x99\x26\xED\x4F\x74\xA1\x3E\xDD\xFB\xE1\xA1\xCE\xCC\x48\x94"
|
||||
"\xAF\x94\x28\xC2\xB7\xB8\x88\x3F\xE4\x46\x3A\x4B\xC8\x5B\x1C\xB3"
|
||||
"\xC1";
|
||||
|
||||
static unsigned char p[] =
|
||||
"\x00\xEE\xCF\xAE\x81\xB1\xB9\xB3\xC9\x08\x81\x0B\x10\xA1\xB5\x60"
|
||||
"\x01\x99\xEB\x9F\x44\xAE\xF4\xFD\xA4\x93\xB8\x1A\x9E\x3D\x84\xF6"
|
||||
"\x32\x12\x4E\xF0\x23\x6E\x5D\x1E\x3B\x7E\x28\xFA\xE7\xAA\x04\x0A"
|
||||
"\x2D\x5B\x25\x21\x76\x45\x9D\x1F\x39\x75\x41\xBA\x2A\x58\xFB\x65"
|
||||
"\x99";
|
||||
|
||||
static unsigned char q[] =
|
||||
"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
|
||||
"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D"
|
||||
"\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5"
|
||||
"\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x15"
|
||||
"\x03";
|
||||
|
||||
static unsigned char dmp1[] =
|
||||
"\x54\x49\x4C\xA6\x3E\xBA\x03\x37\xE4\xE2\x40\x23\xFC\xD6\x9A\x5A"
|
||||
"\xEB\x07\xDD\xDC\x01\x83\xA4\xD0\xAC\x9B\x54\xB0\x51\xF2\xB1\x3E"
|
||||
"\xD9\x49\x09\x75\xEA\xB7\x74\x14\xFF\x59\xC1\xF7\x69\x2E\x9A\x2E"
|
||||
"\x20\x2B\x38\xFC\x91\x0A\x47\x41\x74\xAD\xC9\x3C\x1F\x67\xC9\x81";
|
||||
|
||||
static unsigned char dmq1[] =
|
||||
"\x47\x1E\x02\x90\xFF\x0A\xF0\x75\x03\x51\xB7\xF8\x78\x86\x4C\xA9"
|
||||
"\x61\xAD\xBD\x3A\x8A\x7E\x99\x1C\x5C\x05\x56\xA9\x4C\x31\x46\xA7"
|
||||
"\xF9\x80\x3F\x8F\x6F\x8A\xE3\x42\xE9\x31\xFD\x8A\xE4\x7A\x22\x0D"
|
||||
"\x1B\x99\xA4\x95\x84\x98\x07\xFE\x39\xF9\x24\x5A\x98\x36\xDA\x3D";
|
||||
|
||||
static unsigned char iqmp[] =
|
||||
"\x00\xB0\x6C\x4F\xDA\xBB\x63\x01\x19\x8D\x26\x5B\xDB\xAE\x94\x23"
|
||||
"\xB3\x80\xF2\x71\xF7\x34\x53\x88\x50\x93\x07\x7F\xCD\x39\xE2\x11"
|
||||
"\x9F\xC9\x86\x32\x15\x4F\x58\x83\xB1\x67\xA9\x67\xBF\x40\x2B\x4E"
|
||||
"\x9E\x2E\x0F\x96\x56\xE6\x98\xEA\x36\x66\xED\xFB\x25\x79\x80\x39"
|
||||
"\xF7";
|
||||
|
||||
static unsigned char ctext_ex[] =
|
||||
"\xb8\x24\x6b\x56\xa6\xed\x58\x81\xae\xb5\x85\xd9\xa2\x5b\x2a\xd7"
|
||||
"\x90\xc4\x17\xe0\x80\x68\x1b\xf1\xac\x2b\xc3\xde\xb6\x9d\x8b\xce"
|
||||
"\xf0\xc4\x36\x6f\xec\x40\x0a\xf0\x52\xa7\x2e\x9b\x0e\xff\xb5\xb3"
|
||||
"\xf2\xf1\x92\xdb\xea\xca\x03\xc1\x27\x40\x05\x71\x13\xbf\x1f\x06"
|
||||
"\x69\xac\x22\xe9\xf3\xa7\x85\x2e\x3c\x15\xd9\x13\xca\xb0\xb8\x86"
|
||||
"\x3a\x95\xc9\x92\x94\xce\x86\x74\x21\x49\x54\x61\x03\x46\xf4\xd4"
|
||||
"\x74\xb2\x6f\x7c\x48\xb4\x2e\xe6\x8e\x1f\x57\x2a\x1f\xc4\x02\x6a"
|
||||
"\xc4\x56\xb4\xf5\x9f\x7b\x62\x1e\xa1\xb9\xd8\x8f\x64\x20\x2f\xb1";
|
||||
|
||||
SetKey;
|
||||
}
|
||||
|
||||
static int pad_unknown(void)
|
||||
{
|
||||
unsigned long l;
|
||||
while ((l = ERR_get_error()) != 0)
|
||||
if (ERR_GET_REASON(l) == RSA_R_UNKNOWN_PADDING_TYPE)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static const char rnd_seed[] =
|
||||
"string to make the random number generator think it has entropy";
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int err = 0;
|
||||
int v;
|
||||
RSA *key;
|
||||
unsigned char ptext[256];
|
||||
unsigned char ctext[256];
|
||||
static unsigned char ptext_ex[] = "\x54\x85\x9b\x34\x2c\x49\xea\x2a";
|
||||
unsigned char ctext_ex[256];
|
||||
int plen;
|
||||
int clen = 0;
|
||||
int num;
|
||||
int n;
|
||||
|
||||
CRYPTO_malloc_debug_init();
|
||||
CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL);
|
||||
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
|
||||
|
||||
RAND_seed(rnd_seed, sizeof rnd_seed); /* or OAEP may fail */
|
||||
|
||||
plen = sizeof(ptext_ex) - 1;
|
||||
|
||||
for (v = 0; v < 6; v++) {
|
||||
key = RSA_new();
|
||||
switch (v % 3) {
|
||||
case 0:
|
||||
clen = key1(key, ctext_ex);
|
||||
break;
|
||||
case 1:
|
||||
clen = key2(key, ctext_ex);
|
||||
break;
|
||||
case 2:
|
||||
clen = key3(key, ctext_ex);
|
||||
break;
|
||||
}
|
||||
if (v / 3 >= 1)
|
||||
key->flags |= RSA_FLAG_NO_CONSTTIME;
|
||||
|
||||
num = RSA_public_encrypt(plen, ptext_ex, ctext, key,
|
||||
RSA_PKCS1_PADDING);
|
||||
if (num != clen) {
|
||||
printf("PKCS#1 v1.5 encryption failed!\n");
|
||||
err = 1;
|
||||
goto oaep;
|
||||
}
|
||||
|
||||
num = RSA_private_decrypt(num, ctext, ptext, key, RSA_PKCS1_PADDING);
|
||||
if (num != plen || memcmp(ptext, ptext_ex, num) != 0) {
|
||||
printf("PKCS#1 v1.5 decryption failed!\n");
|
||||
err = 1;
|
||||
} else
|
||||
printf("PKCS #1 v1.5 encryption/decryption ok\n");
|
||||
|
||||
oaep:
|
||||
ERR_clear_error();
|
||||
num = RSA_public_encrypt(plen, ptext_ex, ctext, key,
|
||||
RSA_PKCS1_OAEP_PADDING);
|
||||
if (num == -1 && pad_unknown()) {
|
||||
printf("No OAEP support\n");
|
||||
goto next;
|
||||
}
|
||||
if (num != clen) {
|
||||
printf("OAEP encryption failed!\n");
|
||||
err = 1;
|
||||
goto next;
|
||||
}
|
||||
|
||||
num = RSA_private_decrypt(num, ctext, ptext, key,
|
||||
RSA_PKCS1_OAEP_PADDING);
|
||||
if (num != plen || memcmp(ptext, ptext_ex, num) != 0) {
|
||||
printf("OAEP decryption (encrypted data) failed!\n");
|
||||
err = 1;
|
||||
} else if (memcmp(ctext, ctext_ex, num) == 0)
|
||||
printf("OAEP test vector %d passed!\n", v);
|
||||
|
||||
/*
|
||||
* Different ciphertexts (rsa_oaep.c without -DPKCS_TESTVECT). Try
|
||||
* decrypting ctext_ex
|
||||
*/
|
||||
|
||||
num = RSA_private_decrypt(clen, ctext_ex, ptext, key,
|
||||
RSA_PKCS1_OAEP_PADDING);
|
||||
|
||||
if (num != plen || memcmp(ptext, ptext_ex, num) != 0) {
|
||||
printf("OAEP decryption (test vector data) failed!\n");
|
||||
err = 1;
|
||||
} else
|
||||
printf("OAEP encryption/decryption ok\n");
|
||||
|
||||
/* Try decrypting corrupted ciphertexts */
|
||||
for (n = 0; n < clen; ++n) {
|
||||
int b;
|
||||
unsigned char saved = ctext[n];
|
||||
for (b = 0; b < 256; ++b) {
|
||||
if (b == saved)
|
||||
continue;
|
||||
ctext[n] = b;
|
||||
num = RSA_private_decrypt(num, ctext, ptext, key,
|
||||
RSA_PKCS1_OAEP_PADDING);
|
||||
if (num > 0) {
|
||||
printf("Corrupt data decrypted!\n");
|
||||
err = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
next:
|
||||
RSA_free(key);
|
||||
}
|
||||
|
||||
CRYPTO_cleanup_all_ex_data();
|
||||
ERR_remove_thread_state(NULL);
|
||||
|
||||
CRYPTO_mem_leaks_fp(stderr);
|
||||
|
||||
# ifdef OPENSSL_SYS_NETWARE
|
||||
if (err)
|
||||
printf("ERROR: %d\n", err);
|
||||
# endif
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/sha/sha1test.c
|
||||
@@ -0,0 +1,174 @@
|
||||
/* crypto/sha/sha1test.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
#ifdef OPENSSL_NO_SHA
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No SHA support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/sha.h>
|
||||
|
||||
# ifdef CHARSET_EBCDIC
|
||||
# include <openssl/ebcdic.h>
|
||||
# endif
|
||||
|
||||
# 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];
|
||||
|
||||
# ifdef CHARSET_EBCDIC
|
||||
ebcdic2ascii(test[0], test[0], strlen(test[0]));
|
||||
ebcdic2ascii(test[1], test[1], strlen(test[1]));
|
||||
# endif
|
||||
|
||||
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);
|
||||
# ifdef CHARSET_EBCDIC
|
||||
ebcdic2ascii(buf, buf, 1000);
|
||||
# endif /* CHARSET_EBCDIC */
|
||||
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 < SHA_DIGEST_LENGTH; i++)
|
||||
sprintf(&(buf[i * 2]), "%02x", md[i]);
|
||||
return (buf);
|
||||
}
|
||||
#endif
|
||||
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/sha/sha256t.c
|
||||
@@ -0,0 +1,158 @@
|
||||
/* crypto/sha/sha256t.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2004 The OpenSSL Project. All rights reserved.
|
||||
* ====================================================================
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/evp.h>
|
||||
|
||||
#if defined(OPENSSL_NO_SHA) || defined(OPENSSL_NO_SHA256)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No SHA256 support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
|
||||
unsigned char app_b1[SHA256_DIGEST_LENGTH] = {
|
||||
0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,
|
||||
0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
|
||||
0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,
|
||||
0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad
|
||||
};
|
||||
|
||||
unsigned char app_b2[SHA256_DIGEST_LENGTH] = {
|
||||
0x24, 0x8d, 0x6a, 0x61, 0xd2, 0x06, 0x38, 0xb8,
|
||||
0xe5, 0xc0, 0x26, 0x93, 0x0c, 0x3e, 0x60, 0x39,
|
||||
0xa3, 0x3c, 0xe4, 0x59, 0x64, 0xff, 0x21, 0x67,
|
||||
0xf6, 0xec, 0xed, 0xd4, 0x19, 0xdb, 0x06, 0xc1
|
||||
};
|
||||
|
||||
unsigned char app_b3[SHA256_DIGEST_LENGTH] = {
|
||||
0xcd, 0xc7, 0x6e, 0x5c, 0x99, 0x14, 0xfb, 0x92,
|
||||
0x81, 0xa1, 0xc7, 0xe2, 0x84, 0xd7, 0x3e, 0x67,
|
||||
0xf1, 0x80, 0x9a, 0x48, 0xa4, 0x97, 0x20, 0x0e,
|
||||
0x04, 0x6d, 0x39, 0xcc, 0xc7, 0x11, 0x2c, 0xd0
|
||||
};
|
||||
|
||||
unsigned char addenum_1[SHA224_DIGEST_LENGTH] = {
|
||||
0x23, 0x09, 0x7d, 0x22, 0x34, 0x05, 0xd8, 0x22,
|
||||
0x86, 0x42, 0xa4, 0x77, 0xbd, 0xa2, 0x55, 0xb3,
|
||||
0x2a, 0xad, 0xbc, 0xe4, 0xbd, 0xa0, 0xb3, 0xf7,
|
||||
0xe3, 0x6c, 0x9d, 0xa7
|
||||
};
|
||||
|
||||
unsigned char addenum_2[SHA224_DIGEST_LENGTH] = {
|
||||
0x75, 0x38, 0x8b, 0x16, 0x51, 0x27, 0x76, 0xcc,
|
||||
0x5d, 0xba, 0x5d, 0xa1, 0xfd, 0x89, 0x01, 0x50,
|
||||
0xb0, 0xc6, 0x45, 0x5c, 0xb4, 0xf5, 0x8b, 0x19,
|
||||
0x52, 0x52, 0x25, 0x25
|
||||
};
|
||||
|
||||
unsigned char addenum_3[SHA224_DIGEST_LENGTH] = {
|
||||
0x20, 0x79, 0x46, 0x55, 0x98, 0x0c, 0x91, 0xd8,
|
||||
0xbb, 0xb4, 0xc1, 0xea, 0x97, 0x61, 0x8a, 0x4b,
|
||||
0xf0, 0x3f, 0x42, 0x58, 0x19, 0x48, 0xb2, 0xee,
|
||||
0x4e, 0xe7, 0xad, 0x67
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
unsigned char md[SHA256_DIGEST_LENGTH];
|
||||
int i;
|
||||
EVP_MD_CTX evp;
|
||||
|
||||
fprintf(stdout, "Testing SHA-256 ");
|
||||
|
||||
EVP_Digest("abc", 3, md, NULL, EVP_sha256(), NULL);
|
||||
if (memcmp(md, app_b1, sizeof(app_b1))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 1 of 3 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
EVP_Digest("abcdbcde" "cdefdefg" "efghfghi" "ghijhijk"
|
||||
"ijkljklm" "klmnlmno" "mnopnopq", 56, md, NULL, EVP_sha256(),
|
||||
NULL);
|
||||
if (memcmp(md, app_b2, sizeof(app_b2))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 2 of 3 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
EVP_MD_CTX_init(&evp);
|
||||
EVP_DigestInit_ex(&evp, EVP_sha256(), NULL);
|
||||
for (i = 0; i < 1000000; i += 160)
|
||||
EVP_DigestUpdate(&evp, "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa",
|
||||
(1000000 - i) < 160 ? 1000000 - i : 160);
|
||||
EVP_DigestFinal_ex(&evp, md, NULL);
|
||||
EVP_MD_CTX_cleanup(&evp);
|
||||
|
||||
if (memcmp(md, app_b3, sizeof(app_b3))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 3 of 3 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
fprintf(stdout, " passed.\n");
|
||||
fflush(stdout);
|
||||
|
||||
fprintf(stdout, "Testing SHA-224 ");
|
||||
|
||||
EVP_Digest("abc", 3, md, NULL, EVP_sha224(), NULL);
|
||||
if (memcmp(md, addenum_1, sizeof(addenum_1))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 1 of 3 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
EVP_Digest("abcdbcde" "cdefdefg" "efghfghi" "ghijhijk"
|
||||
"ijkljklm" "klmnlmno" "mnopnopq", 56, md, NULL, EVP_sha224(),
|
||||
NULL);
|
||||
if (memcmp(md, addenum_2, sizeof(addenum_2))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 2 of 3 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
EVP_MD_CTX_init(&evp);
|
||||
EVP_DigestInit_ex(&evp, EVP_sha224(), NULL);
|
||||
for (i = 0; i < 1000000; i += 64)
|
||||
EVP_DigestUpdate(&evp, "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa",
|
||||
(1000000 - i) < 64 ? 1000000 - i : 64);
|
||||
EVP_DigestFinal_ex(&evp, md, NULL);
|
||||
EVP_MD_CTX_cleanup(&evp);
|
||||
|
||||
if (memcmp(md, addenum_3, sizeof(addenum_3))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 3 of 3 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
fprintf(stdout, " passed.\n");
|
||||
fflush(stdout);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
Executable → Regular
@@ -1 +0,0 @@
|
||||
../crypto/sha/sha512t.c
|
||||
@@ -0,0 +1,196 @@
|
||||
/* crypto/sha/sha512t.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2004 The OpenSSL Project. All rights reserved.
|
||||
* ====================================================================
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/crypto.h>
|
||||
|
||||
#if defined(OPENSSL_NO_SHA) || defined(OPENSSL_NO_SHA512)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No SHA512 support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
|
||||
unsigned char app_c1[SHA512_DIGEST_LENGTH] = {
|
||||
0xdd, 0xaf, 0x35, 0xa1, 0x93, 0x61, 0x7a, 0xba,
|
||||
0xcc, 0x41, 0x73, 0x49, 0xae, 0x20, 0x41, 0x31,
|
||||
0x12, 0xe6, 0xfa, 0x4e, 0x89, 0xa9, 0x7e, 0xa2,
|
||||
0x0a, 0x9e, 0xee, 0xe6, 0x4b, 0x55, 0xd3, 0x9a,
|
||||
0x21, 0x92, 0x99, 0x2a, 0x27, 0x4f, 0xc1, 0xa8,
|
||||
0x36, 0xba, 0x3c, 0x23, 0xa3, 0xfe, 0xeb, 0xbd,
|
||||
0x45, 0x4d, 0x44, 0x23, 0x64, 0x3c, 0xe8, 0x0e,
|
||||
0x2a, 0x9a, 0xc9, 0x4f, 0xa5, 0x4c, 0xa4, 0x9f
|
||||
};
|
||||
|
||||
unsigned char app_c2[SHA512_DIGEST_LENGTH] = {
|
||||
0x8e, 0x95, 0x9b, 0x75, 0xda, 0xe3, 0x13, 0xda,
|
||||
0x8c, 0xf4, 0xf7, 0x28, 0x14, 0xfc, 0x14, 0x3f,
|
||||
0x8f, 0x77, 0x79, 0xc6, 0xeb, 0x9f, 0x7f, 0xa1,
|
||||
0x72, 0x99, 0xae, 0xad, 0xb6, 0x88, 0x90, 0x18,
|
||||
0x50, 0x1d, 0x28, 0x9e, 0x49, 0x00, 0xf7, 0xe4,
|
||||
0x33, 0x1b, 0x99, 0xde, 0xc4, 0xb5, 0x43, 0x3a,
|
||||
0xc7, 0xd3, 0x29, 0xee, 0xb6, 0xdd, 0x26, 0x54,
|
||||
0x5e, 0x96, 0xe5, 0x5b, 0x87, 0x4b, 0xe9, 0x09
|
||||
};
|
||||
|
||||
unsigned char app_c3[SHA512_DIGEST_LENGTH] = {
|
||||
0xe7, 0x18, 0x48, 0x3d, 0x0c, 0xe7, 0x69, 0x64,
|
||||
0x4e, 0x2e, 0x42, 0xc7, 0xbc, 0x15, 0xb4, 0x63,
|
||||
0x8e, 0x1f, 0x98, 0xb1, 0x3b, 0x20, 0x44, 0x28,
|
||||
0x56, 0x32, 0xa8, 0x03, 0xaf, 0xa9, 0x73, 0xeb,
|
||||
0xde, 0x0f, 0xf2, 0x44, 0x87, 0x7e, 0xa6, 0x0a,
|
||||
0x4c, 0xb0, 0x43, 0x2c, 0xe5, 0x77, 0xc3, 0x1b,
|
||||
0xeb, 0x00, 0x9c, 0x5c, 0x2c, 0x49, 0xaa, 0x2e,
|
||||
0x4e, 0xad, 0xb2, 0x17, 0xad, 0x8c, 0xc0, 0x9b
|
||||
};
|
||||
|
||||
unsigned char app_d1[SHA384_DIGEST_LENGTH] = {
|
||||
0xcb, 0x00, 0x75, 0x3f, 0x45, 0xa3, 0x5e, 0x8b,
|
||||
0xb5, 0xa0, 0x3d, 0x69, 0x9a, 0xc6, 0x50, 0x07,
|
||||
0x27, 0x2c, 0x32, 0xab, 0x0e, 0xde, 0xd1, 0x63,
|
||||
0x1a, 0x8b, 0x60, 0x5a, 0x43, 0xff, 0x5b, 0xed,
|
||||
0x80, 0x86, 0x07, 0x2b, 0xa1, 0xe7, 0xcc, 0x23,
|
||||
0x58, 0xba, 0xec, 0xa1, 0x34, 0xc8, 0x25, 0xa7
|
||||
};
|
||||
|
||||
unsigned char app_d2[SHA384_DIGEST_LENGTH] = {
|
||||
0x09, 0x33, 0x0c, 0x33, 0xf7, 0x11, 0x47, 0xe8,
|
||||
0x3d, 0x19, 0x2f, 0xc7, 0x82, 0xcd, 0x1b, 0x47,
|
||||
0x53, 0x11, 0x1b, 0x17, 0x3b, 0x3b, 0x05, 0xd2,
|
||||
0x2f, 0xa0, 0x80, 0x86, 0xe3, 0xb0, 0xf7, 0x12,
|
||||
0xfc, 0xc7, 0xc7, 0x1a, 0x55, 0x7e, 0x2d, 0xb9,
|
||||
0x66, 0xc3, 0xe9, 0xfa, 0x91, 0x74, 0x60, 0x39
|
||||
};
|
||||
|
||||
unsigned char app_d3[SHA384_DIGEST_LENGTH] = {
|
||||
0x9d, 0x0e, 0x18, 0x09, 0x71, 0x64, 0x74, 0xcb,
|
||||
0x08, 0x6e, 0x83, 0x4e, 0x31, 0x0a, 0x4a, 0x1c,
|
||||
0xed, 0x14, 0x9e, 0x9c, 0x00, 0xf2, 0x48, 0x52,
|
||||
0x79, 0x72, 0xce, 0xc5, 0x70, 0x4c, 0x2a, 0x5b,
|
||||
0x07, 0xb8, 0xb3, 0xdc, 0x38, 0xec, 0xc4, 0xeb,
|
||||
0xae, 0x97, 0xdd, 0xd8, 0x7f, 0x3d, 0x89, 0x85
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
unsigned char md[SHA512_DIGEST_LENGTH];
|
||||
int i;
|
||||
EVP_MD_CTX evp;
|
||||
|
||||
# ifdef OPENSSL_IA32_SSE2
|
||||
/*
|
||||
* Alternative to this is to call OpenSSL_add_all_algorithms... The below
|
||||
* code is retained exclusively for debugging purposes.
|
||||
*/
|
||||
{
|
||||
char *env;
|
||||
|
||||
if ((env = getenv("OPENSSL_ia32cap")))
|
||||
OPENSSL_ia32cap = strtoul(env, NULL, 0);
|
||||
}
|
||||
# endif
|
||||
|
||||
fprintf(stdout, "Testing SHA-512 ");
|
||||
|
||||
EVP_Digest("abc", 3, md, NULL, EVP_sha512(), NULL);
|
||||
if (memcmp(md, app_c1, sizeof(app_c1))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 1 of 3 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
EVP_Digest("abcdefgh" "bcdefghi" "cdefghij" "defghijk"
|
||||
"efghijkl" "fghijklm" "ghijklmn" "hijklmno"
|
||||
"ijklmnop" "jklmnopq" "klmnopqr" "lmnopqrs"
|
||||
"mnopqrst" "nopqrstu", 112, md, NULL, EVP_sha512(), NULL);
|
||||
if (memcmp(md, app_c2, sizeof(app_c2))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 2 of 3 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
EVP_MD_CTX_init(&evp);
|
||||
EVP_DigestInit_ex(&evp, EVP_sha512(), NULL);
|
||||
for (i = 0; i < 1000000; i += 288)
|
||||
EVP_DigestUpdate(&evp, "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa",
|
||||
(1000000 - i) < 288 ? 1000000 - i : 288);
|
||||
EVP_DigestFinal_ex(&evp, md, NULL);
|
||||
EVP_MD_CTX_cleanup(&evp);
|
||||
|
||||
if (memcmp(md, app_c3, sizeof(app_c3))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 3 of 3 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
fprintf(stdout, " passed.\n");
|
||||
fflush(stdout);
|
||||
|
||||
fprintf(stdout, "Testing SHA-384 ");
|
||||
|
||||
EVP_Digest("abc", 3, md, NULL, EVP_sha384(), NULL);
|
||||
if (memcmp(md, app_d1, sizeof(app_d1))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 1 of 3 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
EVP_Digest("abcdefgh" "bcdefghi" "cdefghij" "defghijk"
|
||||
"efghijkl" "fghijklm" "ghijklmn" "hijklmno"
|
||||
"ijklmnop" "jklmnopq" "klmnopqr" "lmnopqrs"
|
||||
"mnopqrst" "nopqrstu", 112, md, NULL, EVP_sha384(), NULL);
|
||||
if (memcmp(md, app_d2, sizeof(app_d2))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 2 of 3 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
EVP_MD_CTX_init(&evp);
|
||||
EVP_DigestInit_ex(&evp, EVP_sha384(), NULL);
|
||||
for (i = 0; i < 1000000; i += 64)
|
||||
EVP_DigestUpdate(&evp, "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa",
|
||||
(1000000 - i) < 64 ? 1000000 - i : 64);
|
||||
EVP_DigestFinal_ex(&evp, md, NULL);
|
||||
EVP_MD_CTX_cleanup(&evp);
|
||||
|
||||
if (memcmp(md, app_d3, sizeof(app_d3))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 3 of 3 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
fprintf(stdout, " passed.\n");
|
||||
fflush(stdout);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
Executable → Regular
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user