2016-05-18 02:20:24 +08:00
|
|
|
/*
|
|
|
|
* Copyright 1995-2016 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 <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1999-04-27 09:14:46 +08:00
|
|
|
|
2002-11-29 02:54:30 +08:00
|
|
|
#include "../e_os.h"
|
|
|
|
|
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
|
|
|
|
|
2001-02-20 00:06:34 +08:00
|
|
|
#ifdef OPENSSL_NO_MDC2
|
1999-04-27 09:14:46 +08:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
printf("No MDC2 support\n");
|
2015-01-22 11:40:55 +08:00
|
|
|
return (0);
|
1999-04-27 09:14:46 +08:00
|
|
|
}
|
|
|
|
#else
|
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
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
int main(int argc, char *argv[])
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2016-06-18 22:46:13 +08:00
|
|
|
int ret = 1;
|
2015-01-22 11:40:55 +08:00
|
|
|
unsigned char md[MDC2_DIGEST_LENGTH];
|
|
|
|
int i;
|
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 ";
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
# ifdef CHARSET_EBCDIC
|
|
|
|
ebcdic2ascii(text, text, strlen(text));
|
|
|
|
# endif
|
1999-06-05 05:35:58 +08:00
|
|
|
|
2015-12-02 07:49:35 +08:00
|
|
|
c = EVP_MD_CTX_new();
|
2016-06-18 22:46:13 +08:00
|
|
|
if (c == NULL
|
|
|
|
|| !EVP_DigestInit_ex(c, EVP_mdc2(), NULL)
|
|
|
|
|| !EVP_DigestUpdate(c, (unsigned char *)text, strlen(text))
|
|
|
|
|| !EVP_DigestFinal_ex(c, &(md[0]), NULL))
|
|
|
|
goto err;
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
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");
|
2016-06-18 22:46:13 +08:00
|
|
|
goto err;
|
|
|
|
} else {
|
2015-01-22 11:40:55 +08:00
|
|
|
printf("pad1 - ok\n");
|
2016-06-18 22:46:13 +08:00
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2016-06-18 22:46:13 +08:00
|
|
|
if (!EVP_DigestInit_ex(c, EVP_mdc2(), NULL))
|
|
|
|
goto err;
|
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;
|
2016-06-18 22:46:13 +08:00
|
|
|
if (!EVP_DigestUpdate(c, (unsigned char *)text, strlen(text))
|
|
|
|
|| !EVP_DigestFinal_ex(c, &(md[0]), NULL))
|
|
|
|
goto err;
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
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");
|
2016-06-18 22:46:13 +08:00
|
|
|
} else {
|
2015-01-22 11:40:55 +08:00
|
|
|
printf("pad2 - ok\n");
|
2016-06-18 22:46:13 +08:00
|
|
|
ret = 0;
|
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2016-06-18 22:46:13 +08:00
|
|
|
err:
|
2015-12-02 07:49:35 +08:00
|
|
|
EVP_MD_CTX_free(c);
|
2015-01-22 11:40:55 +08:00
|
|
|
EXIT(ret);
|
|
|
|
}
|
1999-04-27 09:14:46 +08:00
|
|
|
#endif
|