m_md2.c revision 160815
1130812Smarcel/* crypto/evp/m_md2.c */ 2130812Smarcel/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3130812Smarcel * All rights reserved. 4130812Smarcel * 5130812Smarcel * This package is an SSL implementation written 6130812Smarcel * by Eric Young (eay@cryptsoft.com). 7130812Smarcel * The implementation was written so as to conform with Netscapes SSL. 8130812Smarcel * 9130812Smarcel * This library is free for commercial and non-commercial use as long as 10130812Smarcel * the following conditions are aheared to. The following conditions 11130812Smarcel * apply to all code found in this distribution, be it the RC4, RSA, 12130812Smarcel * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13130812Smarcel * included with this distribution is covered by the same copyright terms 14130812Smarcel * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15130812Smarcel * 16130812Smarcel * Copyright remains Eric Young's, and as such any Copyright notices in 17130812Smarcel * the code are not to be removed. 18130812Smarcel * If this package is used in a product, Eric Young should be given attribution 19130812Smarcel * as the author of the parts of the library used. 20130812Smarcel * This can be in the form of a textual message at program startup or 21130812Smarcel * in documentation (online or textual) provided with the package. 22130812Smarcel * 23130812Smarcel * Redistribution and use in source and binary forms, with or without 24130812Smarcel * modification, are permitted provided that the following conditions 25130812Smarcel * are met: 26130812Smarcel * 1. Redistributions of source code must retain the copyright 27130812Smarcel * notice, this list of conditions and the following disclaimer. 28130812Smarcel * 2. Redistributions in binary form must reproduce the above copyright 29130812Smarcel * notice, this list of conditions and the following disclaimer in the 30130812Smarcel * documentation and/or other materials provided with the distribution. 31130812Smarcel * 3. All advertising materials mentioning features or use of this software 32130812Smarcel * must display the following acknowledgement: 33130812Smarcel * "This product includes cryptographic software written by 34130812Smarcel * Eric Young (eay@cryptsoft.com)" 35130812Smarcel * The word 'cryptographic' can be left out if the rouines from the library 36130812Smarcel * being used are not cryptographic related :-). 37130812Smarcel * 4. If you include any Windows specific code (or a derivative thereof) from 38130812Smarcel * the apps directory (application code) you must include an acknowledgement: 39130812Smarcel * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40130812Smarcel * 41130812Smarcel * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42130812Smarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43130812Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44130812Smarcel * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45130812Smarcel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46130812Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47130812Smarcel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48130812Smarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49130812Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50130812Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51130812Smarcel * SUCH DAMAGE. 52130812Smarcel * 53130812Smarcel * The licence and distribution terms for any publically available version or 54130812Smarcel * derivative of this code cannot be changed. i.e. this code cannot simply be 55130812Smarcel * copied and put under another distribution licence 56130812Smarcel * [including the GNU Public Licence.] 57130812Smarcel */ 58130812Smarcel 59130812Smarcel#include <stdio.h> 60130812Smarcel#include "cryptlib.h" 61130812Smarcel 62130812Smarcel#ifndef OPENSSL_NO_MD2 63130812Smarcel 64130812Smarcel#include <openssl/evp.h> 65130812Smarcel#include <openssl/objects.h> 66130812Smarcel#include <openssl/x509.h> 67130812Smarcel#include <openssl/md2.h> 68130812Smarcel#ifndef OPENSSL_NO_RSA 69130812Smarcel#include <openssl/rsa.h> 70130812Smarcel#endif 71130812Smarcel 72130812Smarcelstatic int init(EVP_MD_CTX *ctx) 73130812Smarcel { return MD2_Init(ctx->md_data); } 74130812Smarcel 75130812Smarcelstatic int update(EVP_MD_CTX *ctx,const void *data,size_t count) 76130812Smarcel { return MD2_Update(ctx->md_data,data,count); } 77130812Smarcel 78130812Smarcelstatic int final(EVP_MD_CTX *ctx,unsigned char *md) 79130812Smarcel { return MD2_Final(md,ctx->md_data); } 80130812Smarcel 81130812Smarcelstatic const EVP_MD md2_md= 82 { 83 NID_md2, 84 NID_md2WithRSAEncryption, 85 MD2_DIGEST_LENGTH, 86 0, 87 init, 88 update, 89 final, 90 NULL, 91 NULL, 92 EVP_PKEY_RSA_method, 93 MD2_BLOCK, 94 sizeof(EVP_MD *)+sizeof(MD2_CTX), 95 }; 96 97const EVP_MD *EVP_md2(void) 98 { 99 return(&md2_md); 100 } 101#endif 102