1*9bac3682Sbeck /* $OpenBSD: m_md4.c,v 1.22 2024/04/09 13:52:41 beck Exp $ */
200b7ba7eSdoug /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
300b7ba7eSdoug * All rights reserved.
400b7ba7eSdoug *
500b7ba7eSdoug * This package is an SSL implementation written
600b7ba7eSdoug * by Eric Young (eay@cryptsoft.com).
700b7ba7eSdoug * The implementation was written so as to conform with Netscapes SSL.
800b7ba7eSdoug *
900b7ba7eSdoug * This library is free for commercial and non-commercial use as long as
1000b7ba7eSdoug * the following conditions are aheared to. The following conditions
1100b7ba7eSdoug * apply to all code found in this distribution, be it the RC4, RSA,
1200b7ba7eSdoug * lhash, DES, etc., code; not just the SSL code. The SSL documentation
1300b7ba7eSdoug * included with this distribution is covered by the same copyright terms
1400b7ba7eSdoug * except that the holder is Tim Hudson (tjh@cryptsoft.com).
1500b7ba7eSdoug *
1600b7ba7eSdoug * Copyright remains Eric Young's, and as such any Copyright notices in
1700b7ba7eSdoug * the code are not to be removed.
1800b7ba7eSdoug * If this package is used in a product, Eric Young should be given attribution
1900b7ba7eSdoug * as the author of the parts of the library used.
2000b7ba7eSdoug * This can be in the form of a textual message at program startup or
2100b7ba7eSdoug * in documentation (online or textual) provided with the package.
2200b7ba7eSdoug *
2300b7ba7eSdoug * Redistribution and use in source and binary forms, with or without
2400b7ba7eSdoug * modification, are permitted provided that the following conditions
2500b7ba7eSdoug * are met:
2600b7ba7eSdoug * 1. Redistributions of source code must retain the copyright
2700b7ba7eSdoug * notice, this list of conditions and the following disclaimer.
2800b7ba7eSdoug * 2. Redistributions in binary form must reproduce the above copyright
2900b7ba7eSdoug * notice, this list of conditions and the following disclaimer in the
3000b7ba7eSdoug * documentation and/or other materials provided with the distribution.
3100b7ba7eSdoug * 3. All advertising materials mentioning features or use of this software
3200b7ba7eSdoug * must display the following acknowledgement:
3300b7ba7eSdoug * "This product includes cryptographic software written by
3400b7ba7eSdoug * Eric Young (eay@cryptsoft.com)"
3500b7ba7eSdoug * The word 'cryptographic' can be left out if the rouines from the library
3600b7ba7eSdoug * being used are not cryptographic related :-).
3700b7ba7eSdoug * 4. If you include any Windows specific code (or a derivative thereof) from
3800b7ba7eSdoug * the apps directory (application code) you must include an acknowledgement:
3900b7ba7eSdoug * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
4000b7ba7eSdoug *
4100b7ba7eSdoug * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
4200b7ba7eSdoug * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4300b7ba7eSdoug * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4400b7ba7eSdoug * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
4500b7ba7eSdoug * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
4600b7ba7eSdoug * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
4700b7ba7eSdoug * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4800b7ba7eSdoug * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4900b7ba7eSdoug * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5000b7ba7eSdoug * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5100b7ba7eSdoug * SUCH DAMAGE.
5200b7ba7eSdoug *
5300b7ba7eSdoug * The licence and distribution terms for any publically available version or
5400b7ba7eSdoug * derivative of this code cannot be changed. i.e. this code cannot simply be
5500b7ba7eSdoug * copied and put under another distribution licence
5600b7ba7eSdoug * [including the GNU Public Licence.]
5700b7ba7eSdoug */
5800b7ba7eSdoug
5900b7ba7eSdoug #include <stdio.h>
6000b7ba7eSdoug
6100b7ba7eSdoug #include <openssl/opensslconf.h>
6200b7ba7eSdoug
6300b7ba7eSdoug #ifndef OPENSSL_NO_MD4
6400b7ba7eSdoug
6500b7ba7eSdoug #include <openssl/evp.h>
6600b7ba7eSdoug #include <openssl/md4.h>
6700b7ba7eSdoug #include <openssl/objects.h>
6800b7ba7eSdoug #include <openssl/x509.h>
6900b7ba7eSdoug
7000b7ba7eSdoug #ifndef OPENSSL_NO_RSA
7100b7ba7eSdoug #include <openssl/rsa.h>
7200b7ba7eSdoug #endif
7300b7ba7eSdoug
74c9675a23Stb #include "evp_local.h"
75bc366ef8Stb
7600b7ba7eSdoug static int
init(EVP_MD_CTX * ctx)7700b7ba7eSdoug init(EVP_MD_CTX *ctx)
7800b7ba7eSdoug {
7900b7ba7eSdoug return MD4_Init(ctx->md_data);
8000b7ba7eSdoug }
8100b7ba7eSdoug
8200b7ba7eSdoug static int
update(EVP_MD_CTX * ctx,const void * data,size_t count)8300b7ba7eSdoug update(EVP_MD_CTX *ctx, const void *data, size_t count)
8400b7ba7eSdoug {
8500b7ba7eSdoug return MD4_Update(ctx->md_data, data, count);
8600b7ba7eSdoug }
8700b7ba7eSdoug
8800b7ba7eSdoug static int
final(EVP_MD_CTX * ctx,unsigned char * md)8900b7ba7eSdoug final(EVP_MD_CTX *ctx, unsigned char *md)
9000b7ba7eSdoug {
9100b7ba7eSdoug return MD4_Final(md, ctx->md_data);
9200b7ba7eSdoug }
9300b7ba7eSdoug
9400b7ba7eSdoug static const EVP_MD md4_md = {
9500b7ba7eSdoug .type = NID_md4,
9600b7ba7eSdoug .pkey_type = NID_md4WithRSAEncryption,
9700b7ba7eSdoug .md_size = MD4_DIGEST_LENGTH,
9800b7ba7eSdoug .flags = 0,
9900b7ba7eSdoug .init = init,
10000b7ba7eSdoug .update = update,
10100b7ba7eSdoug .final = final,
10200b7ba7eSdoug .copy = NULL,
10300b7ba7eSdoug .cleanup = NULL,
10400b7ba7eSdoug .block_size = MD4_CBLOCK,
10500b7ba7eSdoug .ctx_size = sizeof(EVP_MD *) + sizeof(MD4_CTX),
10600b7ba7eSdoug };
10700b7ba7eSdoug
10800b7ba7eSdoug const EVP_MD *
EVP_md4(void)10900b7ba7eSdoug EVP_md4(void)
11000b7ba7eSdoug {
11100b7ba7eSdoug return (&md4_md);
11200b7ba7eSdoug }
113*9bac3682Sbeck LCRYPTO_ALIAS(EVP_md4);
11400b7ba7eSdoug #endif
115