blob: cb667cbc6bc71cfb74dd00dba92b52c48f6d3298 [file] [log] [blame]
Rich Salz440e5d82016-05-17 14:20:24 -04001/*
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
Ralf S. Engelschall58964a41998-12-21 10:56:39 +00003 *
Rich Salz440e5d82016-05-17 14:20:24 -04004 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
Ralf S. Engelschall58964a41998-12-21 10:56:39 +00008 */
9
10#include <stdio.h>
11#include <stdlib.h>
12#include <string.h>
Ulf Möllerf5d7a031999-04-27 01:14:46 +000013
Richard Levitte55f78ba2002-11-28 18:54:30 +000014#include "../e_os.h"
15
Richard Levittecf1b7d92001-02-19 16:06:34 +000016#ifdef OPENSSL_NO_MD2
Ulf Möllerf5d7a031999-04-27 01:14:46 +000017int main(int argc, char *argv[])
18{
19 printf("No MD2 support\n");
Matt Caswell0f113f32015-01-22 03:40:55 +000020 return (0);
Ulf Möllerf5d7a031999-04-27 01:14:46 +000021}
22#else
Matt Caswell0f113f32015-01-22 03:40:55 +000023# include <openssl/evp.h>
24# include <openssl/md2.h>
Ralf S. Engelschall58964a41998-12-21 10:56:39 +000025
Matt Caswell0f113f32015-01-22 03:40:55 +000026# ifdef CHARSET_EBCDIC
27# include <openssl/ebcdic.h>
28# endif
Ulf Möllera53955d1999-06-04 21:35:58 +000029
Matt Caswell0f113f32015-01-22 03:40:55 +000030static char *test[] = {
31 "",
32 "a",
33 "abc",
34 "message digest",
35 "abcdefghijklmnopqrstuvwxyz",
36 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
37 "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
38 NULL,
39};
Ralf S. Engelschall58964a41998-12-21 10:56:39 +000040
Matt Caswell0f113f32015-01-22 03:40:55 +000041static char *ret[] = {
42 "8350e5a3e24c153df2275c9f80692773",
43 "32ec01ec4a6dac72c0ab96fb34c0b5d1",
44 "da853b0d3f88d99b30283a69e6ded6bb",
45 "ab4f496bfb2a530b219ff33031fe06b0",
46 "4e8ddff3650292ab5a4108c3aa47940b",
47 "da33def2a42df13975352846c30338cd",
48 "d5976f79d83d3a0dc9806c3c66f3efd8",
49};
Ralf S. Engelschall58964a41998-12-21 10:56:39 +000050
Ralf S. Engelschall58964a41998-12-21 10:56:39 +000051static char *pt(unsigned char *md);
Ulf Möller6b691a51999-04-19 21:31:43 +000052int main(int argc, char *argv[])
Matt Caswell0f113f32015-01-22 03:40:55 +000053{
54 int i, err = 0;
55 char **P, **R;
56 char *p;
57 unsigned char md[MD2_DIGEST_LENGTH];
Ralf S. Engelschall58964a41998-12-21 10:56:39 +000058
Matt Caswell0f113f32015-01-22 03:40:55 +000059 P = test;
60 R = ret;
61 i = 1;
62 while (*P != NULL) {
Dr. Stephen Hensond166ed82016-06-18 15:46:13 +010063 if (!EVP_Digest((unsigned char *)*P, strlen(*P), md, NULL, EVP_md2(),
64 NULL)) {
65 printf("EVP Digest error.\n");
66 EXIT(1);
67 }
Matt Caswell0f113f32015-01-22 03:40:55 +000068 p = pt(md);
69 if (strcmp(p, *R) != 0) {
70 printf("error calculating MD2 on '%s'\n", *P);
71 printf("got %s instead of %s\n", p, *R);
72 err++;
73 } else
74 printf("test %d ok\n", i);
75 i++;
76 R++;
77 P++;
78 }
Matt Caswell0f113f32015-01-22 03:40:55 +000079 EXIT(err);
80 return err;
81}
Ralf S. Engelschall58964a41998-12-21 10:56:39 +000082
Ulf Möller6b691a51999-04-19 21:31:43 +000083static char *pt(unsigned char *md)
Matt Caswell0f113f32015-01-22 03:40:55 +000084{
85 int i;
86 static char buf[80];
Ralf S. Engelschall58964a41998-12-21 10:56:39 +000087
Matt Caswell0f113f32015-01-22 03:40:55 +000088 for (i = 0; i < MD2_DIGEST_LENGTH; i++)
89 sprintf(&(buf[i * 2]), "%02x", md[i]);
90 return (buf);
91}
Ulf Möllerf5d7a031999-04-27 01:14:46 +000092#endif