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