Rich Salz | 440e5d8 | 2016-05-17 14:20:24 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 3 | * |
Rich Salz | 440e5d8 | 2016-05-17 14:20:24 -0400 | [diff] [blame] | 4 | * 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. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> |
| 12 | #include <string.h> |
Ulf Möller | f5d7a03 | 1999-04-27 01:14:46 +0000 | [diff] [blame] | 13 | |
Richard Levitte | 55f78ba | 2002-11-28 18:54:30 +0000 | [diff] [blame] | 14 | #include "../e_os.h" |
| 15 | |
Richard Levitte | cf1b7d9 | 2001-02-19 16:06:34 +0000 | [diff] [blame] | 16 | #ifdef OPENSSL_NO_MD2 |
Ulf Möller | f5d7a03 | 1999-04-27 01:14:46 +0000 | [diff] [blame] | 17 | int main(int argc, char *argv[]) |
| 18 | { |
| 19 | printf("No MD2 support\n"); |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 20 | return (0); |
Ulf Möller | f5d7a03 | 1999-04-27 01:14:46 +0000 | [diff] [blame] | 21 | } |
| 22 | #else |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 23 | # include <openssl/evp.h> |
| 24 | # include <openssl/md2.h> |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 25 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 26 | # ifdef CHARSET_EBCDIC |
| 27 | # include <openssl/ebcdic.h> |
| 28 | # endif |
Ulf Möller | a53955d | 1999-06-04 21:35:58 +0000 | [diff] [blame] | 29 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 30 | static char *test[] = { |
| 31 | "", |
| 32 | "a", |
| 33 | "abc", |
| 34 | "message digest", |
| 35 | "abcdefghijklmnopqrstuvwxyz", |
| 36 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", |
| 37 | "12345678901234567890123456789012345678901234567890123456789012345678901234567890", |
| 38 | NULL, |
| 39 | }; |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 40 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 41 | static char *ret[] = { |
| 42 | "8350e5a3e24c153df2275c9f80692773", |
| 43 | "32ec01ec4a6dac72c0ab96fb34c0b5d1", |
| 44 | "da853b0d3f88d99b30283a69e6ded6bb", |
| 45 | "ab4f496bfb2a530b219ff33031fe06b0", |
| 46 | "4e8ddff3650292ab5a4108c3aa47940b", |
| 47 | "da33def2a42df13975352846c30338cd", |
| 48 | "d5976f79d83d3a0dc9806c3c66f3efd8", |
| 49 | }; |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 50 | |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 51 | static char *pt(unsigned char *md); |
Ulf Möller | 6b691a5 | 1999-04-19 21:31:43 +0000 | [diff] [blame] | 52 | int main(int argc, char *argv[]) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 53 | { |
| 54 | int i, err = 0; |
| 55 | char **P, **R; |
| 56 | char *p; |
| 57 | unsigned char md[MD2_DIGEST_LENGTH]; |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 58 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 59 | P = test; |
| 60 | R = ret; |
| 61 | i = 1; |
| 62 | while (*P != NULL) { |
Dr. Stephen Henson | d166ed8 | 2016-06-18 15:46:13 +0100 | [diff] [blame] | 63 | 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 Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 68 | 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 Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 79 | EXIT(err); |
| 80 | return err; |
| 81 | } |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 82 | |
Ulf Möller | 6b691a5 | 1999-04-19 21:31:43 +0000 | [diff] [blame] | 83 | static char *pt(unsigned char *md) |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 84 | { |
| 85 | int i; |
| 86 | static char buf[80]; |
Ralf S. Engelschall | 58964a4 | 1998-12-21 10:56:39 +0000 | [diff] [blame] | 87 | |
Matt Caswell | 0f113f3 | 2015-01-22 03:40:55 +0000 | [diff] [blame] | 88 | for (i = 0; i < MD2_DIGEST_LENGTH; i++) |
| 89 | sprintf(&(buf[i * 2]), "%02x", md[i]); |
| 90 | return (buf); |
| 91 | } |
Ulf Möller | f5d7a03 | 1999-04-27 01:14:46 +0000 | [diff] [blame] | 92 | #endif |