2016-05-17 18:20:24 +00:00
|
|
|
/*
|
2017-04-07 03:49:26 +00:00
|
|
|
* Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
|
1998-12-21 10:52:47 +00:00
|
|
|
*
|
2018-12-06 12:05:25 +00:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-17 18:20:24 +00:00
|
|
|
* 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 10:52:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
1999-04-27 01:14:46 +00:00
|
|
|
|
2017-08-22 12:35:43 +00:00
|
|
|
#include "internal/nelem.h"
|
2017-04-07 03:49:26 +00:00
|
|
|
#include "testutil.h"
|
2002-11-28 18:54:30 +00:00
|
|
|
|
2001-02-19 16:06:34 +00:00
|
|
|
#if defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_MDC2)
|
2015-01-22 03:40:55 +00:00
|
|
|
# define OPENSSL_NO_MDC2
|
1999-04-27 01:14:46 +00:00
|
|
|
#endif
|
|
|
|
|
2017-04-07 03:49:26 +00:00
|
|
|
#ifndef OPENSSL_NO_MDC2
|
2015-01-22 03:40:55 +00:00
|
|
|
# include <openssl/evp.h>
|
|
|
|
# include <openssl/mdc2.h>
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
# ifdef CHARSET_EBCDIC
|
|
|
|
# include <openssl/ebcdic.h>
|
|
|
|
# endif
|
1999-06-04 21:35:58 +00:00
|
|
|
|
2015-01-22 03:40:55 +00: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 10:52:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00: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 10:52:47 +00:00
|
|
|
|
2017-04-07 03:49:26 +00:00
|
|
|
static int test_mdc2(void)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2017-04-07 03:49:26 +00:00
|
|
|
int testresult = 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
unsigned char md[MDC2_DIGEST_LENGTH];
|
2015-11-27 13:02:12 +00:00
|
|
|
EVP_MD_CTX *c;
|
2016-04-29 13:46:07 +00:00
|
|
|
static char text[] = "Now is the time for all ";
|
2017-04-07 03:49:26 +00:00
|
|
|
size_t tlen = strlen(text);
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
# ifdef CHARSET_EBCDIC
|
2017-04-07 03:49:26 +00:00
|
|
|
ebcdic2ascii(text, text, tlen);
|
2015-01-22 03:40:55 +00:00
|
|
|
# endif
|
1999-06-04 21:35:58 +00:00
|
|
|
|
2015-12-01 23:49:35 +00:00
|
|
|
c = EVP_MD_CTX_new();
|
2017-04-07 03:49:26 +00: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 10:52:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/* FIXME: use a ctl function? */
|
2015-11-27 13:02:12 +00:00
|
|
|
((MDC2_CTX *)EVP_MD_CTX_md_data(c))->pad_type = 2;
|
2017-04-07 03:49:26 +00: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 10:52:47 +00:00
|
|
|
|
2017-04-07 03:49:26 +00:00
|
|
|
testresult = 1;
|
|
|
|
end:
|
2015-12-01 23:49:35 +00:00
|
|
|
EVP_MD_CTX_free(c);
|
2017-04-07 03:49:26 +00:00
|
|
|
return testresult;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
1999-04-27 01:14:46 +00:00
|
|
|
#endif
|
2017-04-07 03:49:26 +00:00
|
|
|
|
2017-07-18 01:48:27 +00:00
|
|
|
int setup_tests(void)
|
2017-04-07 03:49:26 +00:00
|
|
|
{
|
|
|
|
#ifndef OPENSSL_NO_MDC2
|
|
|
|
ADD_TEST(test_mdc2);
|
|
|
|
#endif
|
2017-07-18 01:48:27 +00:00
|
|
|
return 1;
|
2017-04-07 03:49:26 +00:00
|
|
|
}
|