2016-05-18 02:20:24 +08:00
|
|
|
/*
|
2017-04-07 11:49:26 +08:00
|
|
|
* Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
|
1998-12-21 18:52:47 +08:00
|
|
|
*
|
2016-05-18 02:20:24 +08:00
|
|
|
* 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
|
1998-12-21 18:52:47 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
1999-04-27 09:14:46 +08:00
|
|
|
|
2002-11-29 02:54:30 +08:00
|
|
|
#include "../e_os.h"
|
2017-04-07 11:49:26 +08:00
|
|
|
#include "testutil.h"
|
2002-11-29 02:54:30 +08:00
|
|
|
|
2001-02-20 00:06:34 +08:00
|
|
|
#if defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_MDC2)
|
2015-01-22 11:40:55 +08:00
|
|
|
# define OPENSSL_NO_MDC2
|
1999-04-27 09:14:46 +08:00
|
|
|
#endif
|
|
|
|
|
2017-04-07 11:49:26 +08:00
|
|
|
#ifndef OPENSSL_NO_MDC2
|
2015-01-22 11:40:55 +08:00
|
|
|
# include <openssl/evp.h>
|
|
|
|
# include <openssl/mdc2.h>
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
# ifdef CHARSET_EBCDIC
|
|
|
|
# include <openssl/ebcdic.h>
|
|
|
|
# endif
|
1999-06-05 05:35:58 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
static unsigned char pad1[16] = {
|
|
|
|
0x42, 0xE5, 0x0C, 0xD2, 0x24, 0xBA, 0xCE, 0xBA,
|
|
|
|
0x76, 0x0B, 0xDD, 0x2B, 0xD4, 0x09, 0x28, 0x1A
|
|
|
|
};
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
static unsigned char pad2[16] = {
|
|
|
|
0x2E, 0x46, 0x79, 0xB5, 0xAD, 0xD9, 0xCA, 0x75,
|
|
|
|
0x35, 0xD8, 0x7A, 0xFE, 0xAB, 0x33, 0xBE, 0xE2
|
|
|
|
};
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2017-04-07 11:49:26 +08:00
|
|
|
static int test_mdc2(void)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2017-04-07 11:49:26 +08:00
|
|
|
int testresult = 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
unsigned char md[MDC2_DIGEST_LENGTH];
|
2015-11-27 21:02:12 +08:00
|
|
|
EVP_MD_CTX *c;
|
2016-04-29 21:46:07 +08:00
|
|
|
static char text[] = "Now is the time for all ";
|
2017-04-07 11:49:26 +08:00
|
|
|
size_t tlen = strlen(text);
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
# ifdef CHARSET_EBCDIC
|
2017-04-07 11:49:26 +08:00
|
|
|
ebcdic2ascii(text, text, tlen);
|
2015-01-22 11:40:55 +08:00
|
|
|
# endif
|
1999-06-05 05:35:58 +08:00
|
|
|
|
2015-12-02 07:49:35 +08:00
|
|
|
c = EVP_MD_CTX_new();
|
2017-04-07 11:49:26 +08:00
|
|
|
if (!TEST_ptr(c)
|
|
|
|
|| !TEST_true(EVP_DigestInit_ex(c, EVP_mdc2(), NULL))
|
|
|
|
|| !TEST_true(EVP_DigestUpdate(c, (unsigned char *)text, tlen))
|
|
|
|
|| !TEST_true(EVP_DigestFinal_ex(c, &(md[0]), NULL))
|
|
|
|
|| !TEST_mem_eq(md, MDC2_DIGEST_LENGTH, pad1, MDC2_DIGEST_LENGTH)
|
|
|
|
|| !TEST_true(EVP_DigestInit_ex(c, EVP_mdc2(), NULL)))
|
|
|
|
goto end;
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
/* FIXME: use a ctl function? */
|
2015-11-27 21:02:12 +08:00
|
|
|
((MDC2_CTX *)EVP_MD_CTX_md_data(c))->pad_type = 2;
|
2017-04-07 11:49:26 +08:00
|
|
|
if (!TEST_true(EVP_DigestUpdate(c, (unsigned char *)text, tlen))
|
|
|
|
|| !TEST_true(EVP_DigestFinal_ex(c, &(md[0]), NULL))
|
|
|
|
|| !TEST_mem_eq(md, MDC2_DIGEST_LENGTH, pad2, MDC2_DIGEST_LENGTH))
|
|
|
|
goto end;
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2017-04-07 11:49:26 +08:00
|
|
|
testresult = 1;
|
|
|
|
end:
|
2015-12-02 07:49:35 +08:00
|
|
|
EVP_MD_CTX_free(c);
|
2017-04-07 11:49:26 +08:00
|
|
|
return testresult;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
1999-04-27 09:14:46 +08:00
|
|
|
#endif
|
2017-04-07 11:49:26 +08:00
|
|
|
|
|
|
|
void register_tests(void)
|
|
|
|
{
|
|
|
|
#ifndef OPENSSL_NO_MDC2
|
|
|
|
ADD_TEST(test_mdc2);
|
|
|
|
#endif
|
|
|
|
}
|