rmdtest.c revision 296341
10Sduke/* crypto/ripemd/rmdtest.c */ 22362Sohair/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 30Sduke * All rights reserved. 40Sduke * 50Sduke * This package is an SSL implementation written 60Sduke * by Eric Young (eay@cryptsoft.com). 70Sduke * The implementation was written so as to conform with Netscapes SSL. 80Sduke * 90Sduke * This library is free for commercial and non-commercial use as long as 100Sduke * the following conditions are aheared to. The following conditions 110Sduke * apply to all code found in this distribution, be it the RC4, RSA, 120Sduke * lhash, DES, etc., code; not just the SSL code. The SSL documentation 130Sduke * included with this distribution is covered by the same copyright terms 140Sduke * except that the holder is Tim Hudson (tjh@cryptsoft.com). 150Sduke * 160Sduke * Copyright remains Eric Young's, and as such any Copyright notices in 170Sduke * the code are not to be removed. 180Sduke * If this package is used in a product, Eric Young should be given attribution 192362Sohair * as the author of the parts of the library used. 202362Sohair * This can be in the form of a textual message at program startup or 212362Sohair * in documentation (online or textual) provided with the package. 220Sduke * 230Sduke * Redistribution and use in source and binary forms, with or without 240Sduke * modification, are permitted provided that the following conditions 250Sduke * are met: 260Sduke * 1. Redistributions of source code must retain the copyright 270Sduke * notice, this list of conditions and the following disclaimer. 280Sduke * 2. Redistributions in binary form must reproduce the above copyright 290Sduke * notice, this list of conditions and the following disclaimer in the 300Sduke * documentation and/or other materials provided with the distribution. 310Sduke * 3. All advertising materials mentioning features or use of this software 320Sduke * must display the following acknowledgement: 330Sduke * "This product includes cryptographic software written by 340Sduke * Eric Young (eay@cryptsoft.com)" 350Sduke * The word 'cryptographic' can be left out if the rouines from the library 360Sduke * being used are not cryptographic related :-). 370Sduke * 4. If you include any Windows specific code (or a derivative thereof) from 380Sduke * the apps directory (application code) you must include an acknowledgement: 390Sduke * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 400Sduke * 410Sduke * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 420Sduke * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 430Sduke * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 440Sduke * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 450Sduke * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 460Sduke * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 470Sduke * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 480Sduke * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 490Sduke * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 500Sduke * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 510Sduke * SUCH DAMAGE. 520Sduke * 530Sduke * The licence and distribution terms for any publically available version or 540Sduke * derivative of this code cannot be changed. i.e. this code cannot simply be 550Sduke * copied and put under another distribution licence 560Sduke * [including the GNU Public Licence.] 570Sduke */ 580Sduke 590Sduke#include <stdio.h> 600Sduke#include <string.h> 610Sduke#include <stdlib.h> 620Sduke 630Sduke#include "../e_os.h" 640Sduke 650Sduke#ifdef OPENSSL_NO_RIPEMD 660Sdukeint main(int argc, char *argv[]) 670Sduke{ 680Sduke printf("No ripemd support\n"); 690Sduke return (0); 700Sduke} 710Sduke#else 720Sduke# include <openssl/ripemd.h> 730Sduke# include <openssl/evp.h> 740Sduke 750Sduke# ifdef CHARSET_EBCDIC 760Sduke# include <openssl/ebcdic.h> 770Sduke# endif 780Sduke 790Sdukestatic char *test[] = { 800Sduke "", 810Sduke "a", 820Sduke "abc", 830Sduke "message digest", 840Sduke "abcdefghijklmnopqrstuvwxyz", 850Sduke "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 860Sduke "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 870Sduke "12345678901234567890123456789012345678901234567890123456789012345678901234567890", 880Sduke NULL, 890Sduke}; 900Sduke 910Sdukestatic char *ret[] = { 920Sduke "9c1185a5c5e9fc54612808977ee8f548b2258d31", 930Sduke "0bdc9d2d256b3ee9daae347be6f4dc835a467ffe", 940Sduke "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc", 950Sduke "5d0689ef49d2fae572b881b123a85ffa21595f36", 960Sduke "f71c27109c692c1b56bbdceb5b9d2865b3708dbc", 970Sduke "12a053384a9c0c88e405a06c27dcf49ada62eb2b", 980Sduke "b0e20b6e3116640286ed3a87a5713079b21f5189", 990Sduke "9b752e45573d4b39f4dbd3323cab82bf63326bfb", 1000Sduke}; 1010Sduke 1020Sdukestatic char *pt(unsigned char *md); 103int main(int argc, char *argv[]) 104{ 105 int i, err = 0; 106 char **P, **R; 107 char *p; 108 unsigned char md[RIPEMD160_DIGEST_LENGTH]; 109 110 P = test; 111 R = ret; 112 i = 1; 113 while (*P != NULL) { 114# ifdef CHARSET_EBCDIC 115 ebcdic2ascii((char *)*P, (char *)*P, strlen((char *)*P)); 116# endif 117 EVP_Digest(&(P[0][0]), strlen((char *)*P), md, NULL, EVP_ripemd160(), 118 NULL); 119 p = pt(md); 120 if (strcmp(p, (char *)*R) != 0) { 121 printf("error calculating RIPEMD160 on '%s'\n", *P); 122 printf("got %s instead of %s\n", p, *R); 123 err++; 124 } else 125 printf("test %d ok\n", i); 126 i++; 127 R++; 128 P++; 129 } 130 EXIT(err); 131 return (0); 132} 133 134static char *pt(unsigned char *md) 135{ 136 int i; 137 static char buf[80]; 138 139 for (i = 0; i < RIPEMD160_DIGEST_LENGTH; i++) 140 sprintf(&(buf[i * 2]), "%02x", md[i]); 141 return (buf); 142} 143#endif 144