提交 816060d2 编写于 作者: D Dr. Stephen Henson

Remove more redundant tests: md4, md5, rmd, rc4, p5_crpt2

Reviewed-by: NRichard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/2784)
上级 a7ab9755
......@@ -14,15 +14,15 @@ IF[{- !$disabled{tests} -}]
aborttest \
sanitytest bntest \
ectest ecdsatest ecdhtest gmdifftest pbelutest ideatest \
md2test md4test md5test \
md2test \
hmactest \
rc2test rc4test rc5test \
rc2test rc5test \
destest sha1test sha256t sha512t \
mdc2test rmdtest \
mdc2test \
randtest dhtest enginetest casttest \
bftest ssltest_old dsatest exptest rsa_test \
evp_test evp_extra_test igetest v3nametest v3ext \
crltest danetest p5_crpt2_test bad_dtls_test \
crltest danetest bad_dtls_test \
constant_time_test verify_extra_test clienthellotest \
packettest asynctest secmemtest srptest memleaktest \
dtlsv1listentest ct_test threadstest afalgtest d2i_test \
......@@ -70,22 +70,10 @@ IF[{- !$disabled{tests} -}]
INCLUDE[md2test]=../include
DEPEND[md2test]=../libcrypto
SOURCE[md4test]=md4test.c
INCLUDE[md4test]=../include
DEPEND[md4test]=../libcrypto
SOURCE[md5test]=md5test.c
INCLUDE[md5test]=../include
DEPEND[md5test]=../libcrypto
SOURCE[hmactest]=hmactest.c
INCLUDE[hmactest]=../include
DEPEND[hmactest]=../libcrypto
SOURCE[wp_test]=wp_test.c
INCLUDE[wp_test]=../include
DEPEND[wp_test]=../libcrypto
SOURCE[rc2test]=rc2test.c
INCLUDE[rc2test]=../include
DEPEND[rc2test]=../libcrypto
......@@ -118,10 +106,6 @@ IF[{- !$disabled{tests} -}]
INCLUDE[mdc2test]=../include
DEPEND[mdc2test]=../libcrypto
SOURCE[rmdtest]=rmdtest.c
INCLUDE[rmdtest]=../include
DEPEND[rmdtest]=../libcrypto
SOURCE[randtest]=randtest.c
INCLUDE[randtest]=../include
DEPEND[randtest]=../libcrypto
......@@ -186,10 +170,6 @@ IF[{- !$disabled{tests} -}]
INCLUDE[danetest]=../include
DEPEND[danetest]=../libcrypto ../libssl
SOURCE[p5_crpt2_test]=p5_crpt2_test.c
INCLUDE[p5_crpt2_test]=../include
DEPEND[p5_crpt2_test]=../libcrypto
SOURCE[constant_time_test]=constant_time_test.c
INCLUDE[constant_time_test]=.. ../include
DEPEND[constant_time_test]=../libcrypto
......
......@@ -146,7 +146,7 @@ Input = 616263
Output = a9993e364706816aba3e25717850c26c9cd0d89d
# MD5 tests (from md5test.c)
# MD5 tests
Digest = MD5
Input =
Output = d41d8cd98f00b204e9800998ecf8427e
......@@ -175,7 +175,7 @@ Digest = MD5
Input = 3132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930
Output = 57edf4a22be3c955ac49da2e2107b67a
# MD4 tests from md4test.c
# MD4 tests
Digest = MD4
Input = ""
Output = 31d6cfe0d16ae931b73c59d7e0c089c0
......@@ -198,7 +198,7 @@ Digest = MD4
Input = "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
Output = e33b4ddc9c38f2199c3e7b164fcc0536
# RIPEMD160 tests from rmdtest.c
# RIPEMD160 tests
Digest = RIPEMD160
Input = ""
Output = 9c1185a5c5e9fc54612808977ee8f548b2258d31
......@@ -957,7 +957,7 @@ Plaintext = 37363534333231204E6F77206973207468652074696D6520666F722000000000
Ciphertext = 3FE301C962AC01D02213763C1CBD4CDC799657C064ECF5D41C673812CFDE9675
# RC4 tests (from rc4test)
# RC4 tests
Cipher = RC4
Key = 0123456789abcdef0123456789abcdef
Plaintext = 0123456789abcdef
......@@ -3376,7 +3376,7 @@ Password = 007100750065006500670000
Salt = 263216FCC2FAB31C
Key = 5EC4C7A80DF652294C3925B6489A7AB857C83476
# PBKDF2 tests from p5_crpt2_test.c
# PBKDF2 tests
PBE = pbkdf2
Password = "password"
Salt = "salt"
......
/*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#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) {
if (!EVP_Digest(&(P[0][0]), strlen((char *)*P), md, NULL, EVP_md4(),
NULL)) {
printf("EVP Digest error.\n");
EXIT(1);
}
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);
}
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
/*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#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) {
if (!EVP_Digest(&(P[0][0]), strlen((char *)*P), md, NULL, EVP_md5(),
NULL)) {
printf("EVP Digest error.\n");
EXIT(1);
}
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++;
}
EXIT(err);
}
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
/*
* Copyright 2013-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <stdio.h>
#include <string.h>
#include "../e_os.h"
#include <openssl/opensslconf.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/conf.h>
typedef struct {
const char *pass;
int passlen;
const char *salt;
int saltlen;
int iter;
} testdata;
static testdata test_cases[] = {
{"password", 8, "salt", 4, 1},
{"password", 8, "salt", 4, 2},
{"password", 8, "salt", 4, 4096},
{"passwordPASSWORDpassword", 24,
"saltSALTsaltSALTsaltSALTsaltSALTsalt", 36, 4096},
{"pass\0word", 9, "sa\0lt", 5, 4096},
{NULL},
};
static const char *sha1_results[] = {
"0c60c80f961f0e71f3a9b524af6012062fe037a6",
"ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957",
"4b007901b765489abead49d926f721d065a429c1",
"3d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038",
"56fa6aa75548099dcc37d7f03425e0c3",
};
static const char *sha256_results[] = {
"120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b",
"ae4d0c95af6b46d32d0adff928f06dd02a303f8ef3c251dfd6e2d85a95474c43",
"c5e478d59288c841aa530db6845c4c8d962893a001ce4e11a4963873aa98134a",
"348c89dbcbd32b2f32d814b8116e84cf2b17347ebc1800181c4e2a1fb8dd53e1c63551"
"8c7dac47e9",
"89b69d0516f829893c696226650a8687",
};
static const char *sha512_results[] = {
"867f70cf1ade02cff3752599a3a53dc4af34c7a669815ae5d513554e1c8cf252c02d47"
"0a285a0501bad999bfe943c08f050235d7d68b1da55e63f73b60a57fce",
"e1d9c16aa681708a45f5c7c4e215ceb66e011a2e9f0040713f18aefdb866d53cf76cab"
"2868a39b9f7840edce4fef5a82be67335c77a6068e04112754f27ccf4e",
"d197b1b33db0143e018b12f3d1d1479e6cdebdcc97c5c0f87f6902e072f457b5143f30"
"602641b3d55cd335988cb36b84376060ecd532e039b742a239434af2d5",
"8c0511f4c6e597c6ac6315d8f0362e225f3c501495ba23b868c005174dc4ee71115b59"
"f9e60cd9532fa33e0f75aefe30225c583a186cd82bd4daea9724a3d3b8",
"9d9e9c4cd21fe4be24d5b8244c759665",
};
static void hexdump(FILE *f, const char *title, const unsigned char *s, int l)
{
int i;
fprintf(f, "%s", title);
for (i = 0; i < l; i++) {
fprintf(f, "%02x", s[i]);
}
fprintf(f, "\n");
}
static void convert(unsigned char *dst, const unsigned char *src, int len)
{
int i;
for (i = 0; i < len; i++, dst++, src += 2) {
unsigned int n;
sscanf((char *)src, "%2x", &n);
*dst = (unsigned char)n;
}
*dst = 0;
}
static void
test_p5_pbkdf2(int i, char *digestname, testdata *test, const char *hex)
{
const EVP_MD *digest;
unsigned char *out;
unsigned char *expected;
int keylen, r;
digest = EVP_get_digestbyname(digestname);
if (digest == NULL) {
fprintf(stderr, "unknown digest %s\n", digestname);
EXIT(5);
}
if ((strlen(hex) % 2) != 0) {
fprintf(stderr, "odd hex digest %s %i\n", digestname, i);
EXIT(5);
}
keylen = strlen(hex) / 2;
expected = OPENSSL_malloc(keylen + 1);
out = OPENSSL_malloc(keylen + 1);
if ((expected == NULL) || (out == NULL)) {
fprintf(stderr, "malloc() failed\n");
EXIT(5);
}
convert(expected, (const unsigned char *)hex, keylen);
r = PKCS5_PBKDF2_HMAC(test->pass, test->passlen,
(const unsigned char *)test->salt, test->saltlen,
test->iter, digest, keylen, out);
if (r == 0) {
fprintf(stderr, "PKCS5_PBKDF2_HMAC(%s) failure test %i\n",
digestname, i);
EXIT(3);
}
if (memcmp(expected, out, keylen) != 0) {
fprintf(stderr, "Wrong result for PKCS5_PBKDF2_HMAC(%s) test %i\n",
digestname, i);
hexdump(stderr, "expected: ", expected, keylen);
hexdump(stderr, "result: ", out, keylen);
EXIT(2);
}
OPENSSL_free(expected);
OPENSSL_free(out);
}
int main(int argc, char **argv)
{
int i;
testdata *test = test_cases;
CRYPTO_set_mem_debug(1);
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_ALL_BUILTIN, NULL);
printf("PKCS5_PBKDF2_HMAC() tests ");
for (i = 0; test->pass != NULL; i++, test++) {
test_p5_pbkdf2(i, "sha1", test, sha1_results[i]);
test_p5_pbkdf2(i, "sha256", test, sha256_results[i]);
test_p5_pbkdf2(i, "sha512", test, sha512_results[i]);
printf(".");
}
printf(" done\n");
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
if (CRYPTO_mem_leaks_fp(stderr) <= 0)
return 1;
# endif
return 0;
}
/*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#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];
for (i = 0; i < 6; i++) {
RC4_set_key(&key, keys[i][0], &(keys[i][1]));
memset(obuf, 0, 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, 0, 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, 0, 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");
}
EXIT(err);
}
#endif
#! /usr/bin/env perl
# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the OpenSSL license (the "License"). You may not use
# this file except in compliance with the License. You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html
use OpenSSL::Test::Simple;
simple_test("test_md4", "md4test", "md4");
#! /usr/bin/env perl
# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the OpenSSL license (the "License"). You may not use
# this file except in compliance with the License. You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html
use OpenSSL::Test::Simple;
simple_test("test_md5", "md5test", "md5");
#! /usr/bin/env perl
# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the OpenSSL license (the "License"). You may not use
# this file except in compliance with the License. You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html
use OpenSSL::Test::Simple;
simple_test("test_rc4", "rc4test", "rc4");
#! /usr/bin/env perl
# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the OpenSSL license (the "License"). You may not use
# this file except in compliance with the License. You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html
use OpenSSL::Test::Simple;
simple_test("test_rmd", "rmdtest", "rmd");
#! /usr/bin/env perl
# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the OpenSSL license (the "License"). You may not use
# this file except in compliance with the License. You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html
use OpenSSL::Test::Simple;
simple_test("test_p5_crpt2", "p5_crpt2_test");
/*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "../e_os.h"
#ifdef OPENSSL_NO_RMD160
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[][100] = {
{ "" },
{ "a" },
{ "abc" },
{ "message digest" },
{ "abcdefghijklmnopqrstuvwxyz" },
{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
{ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" },
{ "12345678901234567890123456789012345678901234567890123456789012345678901234567890" }
};
static char *ret[] = {
"9c1185a5c5e9fc54612808977ee8f548b2258d31",
"0bdc9d2d256b3ee9daae347be6f4dc835a467ffe",
"8eb208f7e05d987a9b044a8e98c6b087f15a0bfc",
"5d0689ef49d2fae572b881b123a85ffa21595f36",
"f71c27109c692c1b56bbdceb5b9d2865b3708dbc",
"12a053384a9c0c88e405a06c27dcf49ada62eb2b",
"b0e20b6e3116640286ed3a87a5713079b21f5189",
"9b752e45573d4b39f4dbd3323cab82bf63326bfb",
};
static char *pt(unsigned char *md);
int main(int argc, char *argv[])
{
unsigned int i;
int err = 0;
char **R;
char *p;
unsigned char md[RIPEMD160_DIGEST_LENGTH];
R = ret;
for (i = 0; i < OSSL_NELEM(test); i++) {
# ifdef CHARSET_EBCDIC
ebcdic2ascii(test[i], test[i], strlen(test[i]));
# endif
if (!EVP_Digest(test[i], strlen(test[i]), md, NULL, EVP_ripemd160(),
NULL)) {
printf("EVP Digest error.\n");
EXIT(1);
}
p = pt(md);
if (strcmp(p, (char *)*R) != 0) {
printf("error calculating RIPEMD160 on '%s'\n", test[i]);
printf("got %s instead of %s\n", p, *R);
err++;
} else
printf("test %d ok\n", i + 1);
R++;
}
EXIT(err);
}
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册