md2_one.c revision 302408
1219974Smav/* crypto/md2/md2_one.c */ 2219974Smav/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3234601Smav * All rights reserved. 4219974Smav * 5219974Smav * This package is an SSL implementation written 6219974Smav * by Eric Young (eay@cryptsoft.com). 7219974Smav * The implementation was written so as to conform with Netscapes SSL. 8219974Smav * 9219974Smav * This library is free for commercial and non-commercial use as long as 10219974Smav * the following conditions are aheared to. The following conditions 11219974Smav * apply to all code found in this distribution, be it the RC4, RSA, 12219974Smav * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13219974Smav * included with this distribution is covered by the same copyright terms 14219974Smav * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15219974Smav * 16219974Smav * Copyright remains Eric Young's, and as such any Copyright notices in 17219974Smav * the code are not to be removed. 18219974Smav * If this package is used in a product, Eric Young should be given attribution 19219974Smav * as the author of the parts of the library used. 20219974Smav * This can be in the form of a textual message at program startup or 21219974Smav * in documentation (online or textual) provided with the package. 22219974Smav * 23219974Smav * Redistribution and use in source and binary forms, with or without 24219974Smav * modification, are permitted provided that the following conditions 25219974Smav * are met: 26219974Smav * 1. Redistributions of source code must retain the copyright 27219974Smav * notice, this list of conditions and the following disclaimer. 28219974Smav * 2. Redistributions in binary form must reproduce the above copyright 29219974Smav * notice, this list of conditions and the following disclaimer in the 30219974Smav * documentation and/or other materials provided with the distribution. 31219974Smav * 3. All advertising materials mentioning features or use of this software 32219974Smav * must display the following acknowledgement: 33219974Smav * "This product includes cryptographic software written by 34219974Smav * Eric Young (eay@cryptsoft.com)" 35219974Smav * The word 'cryptographic' can be left out if the rouines from the library 36219974Smav * being used are not cryptographic related :-). 37219974Smav * 4. If you include any Windows specific code (or a derivative thereof) from 38219974Smav * the apps directory (application code) you must include an acknowledgement: 39219974Smav * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40219974Smav * 41219974Smav * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42219974Smav * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43219974Smav * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44219974Smav * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45219974Smav * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46219974Smav * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47219974Smav * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48219974Smav * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49219974Smav * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50219974Smav * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51219974Smav * SUCH DAMAGE. 52219974Smav * 53219974Smav * The licence and distribution terms for any publically available version or 54219974Smav * derivative of this code cannot be changed. i.e. this code cannot simply be 55219974Smav * copied and put under another distribution licence 56219974Smav * [including the GNU Public Licence.] 57219974Smav */ 58219974Smav 59219974Smav#include <stdio.h> 60219974Smav#include "cryptlib.h" 61219974Smav#include <openssl/md2.h> 62219974Smav 63219974Smav/* 64219974Smav * This is a separate file so that #defines in cryptlib.h can map my MD 65219974Smav * functions to different names 66219974Smav */ 67219974Smav 68219974Smavunsigned char *MD2(const unsigned char *d, size_t n, unsigned char *md) 69219974Smav{ 70219974Smav MD2_CTX c; 71219974Smav static unsigned char m[MD2_DIGEST_LENGTH]; 72219974Smav 73219974Smav if (md == NULL) 74219974Smav md = m; 75219974Smav if (!MD2_Init(&c)) 76219974Smav return NULL; 77219974Smav#ifndef CHARSET_EBCDIC 78219974Smav MD2_Update(&c, d, n); 79219974Smav#else 80219974Smav { 81219974Smav char temp[1024]; 82219974Smav unsigned long chunk; 83219974Smav 84219974Smav while (n > 0) { 85219974Smav chunk = (n > sizeof(temp)) ? sizeof(temp) : n; 86219974Smav ebcdic2ascii(temp, d, chunk); 87219974Smav MD2_Update(&c, temp, chunk); 88219974Smav n -= chunk; 89219974Smav d += chunk; 90219974Smav } 91219974Smav } 92219974Smav#endif 93219974Smav MD2_Final(md, &c); 94219974Smav OPENSSL_cleanse(&c, sizeof(c)); /* Security consideration */ 95219974Smav return (md); 96219974Smav} 97219974Smav