1e1051a39Sopenharmony_ci/*
2e1051a39Sopenharmony_ci * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3e1051a39Sopenharmony_ci *
4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License").  You may not use
5e1051a39Sopenharmony_ci * this file except in compliance with the License.  You can obtain a copy
6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at
7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html
8e1051a39Sopenharmony_ci */
9e1051a39Sopenharmony_ci
10e1051a39Sopenharmony_ci#include <stdlib.h>
11e1051a39Sopenharmony_ci#include <string.h>
12e1051a39Sopenharmony_ci#include <openssl/opensslconf.h>
13e1051a39Sopenharmony_ci#include <openssl/md4.h>
14e1051a39Sopenharmony_ci
15e1051a39Sopenharmony_civoid md4_block_data_order(MD4_CTX *c, const void *p, size_t num);
16e1051a39Sopenharmony_ci
17e1051a39Sopenharmony_ci#define DATA_ORDER_IS_LITTLE_ENDIAN
18e1051a39Sopenharmony_ci
19e1051a39Sopenharmony_ci#define HASH_LONG               MD4_LONG
20e1051a39Sopenharmony_ci#define HASH_CTX                MD4_CTX
21e1051a39Sopenharmony_ci#define HASH_CBLOCK             MD4_CBLOCK
22e1051a39Sopenharmony_ci#define HASH_UPDATE             MD4_Update
23e1051a39Sopenharmony_ci#define HASH_TRANSFORM          MD4_Transform
24e1051a39Sopenharmony_ci#define HASH_FINAL              MD4_Final
25e1051a39Sopenharmony_ci#define HASH_MAKE_STRING(c,s)   do {    \
26e1051a39Sopenharmony_ci        unsigned long ll;               \
27e1051a39Sopenharmony_ci        ll=(c)->A; (void)HOST_l2c(ll,(s));      \
28e1051a39Sopenharmony_ci        ll=(c)->B; (void)HOST_l2c(ll,(s));      \
29e1051a39Sopenharmony_ci        ll=(c)->C; (void)HOST_l2c(ll,(s));      \
30e1051a39Sopenharmony_ci        ll=(c)->D; (void)HOST_l2c(ll,(s));      \
31e1051a39Sopenharmony_ci        } while (0)
32e1051a39Sopenharmony_ci#define HASH_BLOCK_DATA_ORDER   md4_block_data_order
33e1051a39Sopenharmony_ci
34e1051a39Sopenharmony_ci#include "crypto/md32_common.h"
35e1051a39Sopenharmony_ci
36e1051a39Sopenharmony_ci/*-
37e1051a39Sopenharmony_ci#define F(x,y,z)        (((x) & (y))  |  ((~(x)) & (z)))
38e1051a39Sopenharmony_ci#define G(x,y,z)        (((x) & (y))  |  ((x) & ((z))) | ((y) & ((z))))
39e1051a39Sopenharmony_ci*/
40e1051a39Sopenharmony_ci
41e1051a39Sopenharmony_ci/*
42e1051a39Sopenharmony_ci * As pointed out by Wei Dai, the above can be simplified to the code
43e1051a39Sopenharmony_ci * below.  Wei attributes these optimizations to Peter Gutmann's SHS code,
44e1051a39Sopenharmony_ci * and he attributes it to Rich Schroeppel.
45e1051a39Sopenharmony_ci */
46e1051a39Sopenharmony_ci#define F(b,c,d)        ((((c) ^ (d)) & (b)) ^ (d))
47e1051a39Sopenharmony_ci#define G(b,c,d)        (((b) & (c)) | ((b) & (d)) | ((c) & (d)))
48e1051a39Sopenharmony_ci#define H(b,c,d)        ((b) ^ (c) ^ (d))
49e1051a39Sopenharmony_ci
50e1051a39Sopenharmony_ci#define R0(a,b,c,d,k,s,t) { \
51e1051a39Sopenharmony_ci        a+=((k)+(t)+F((b),(c),(d))); \
52e1051a39Sopenharmony_ci        a=ROTATE(a,s); };
53e1051a39Sopenharmony_ci
54e1051a39Sopenharmony_ci#define R1(a,b,c,d,k,s,t) { \
55e1051a39Sopenharmony_ci        a+=((k)+(t)+G((b),(c),(d))); \
56e1051a39Sopenharmony_ci        a=ROTATE(a,s); };
57e1051a39Sopenharmony_ci
58e1051a39Sopenharmony_ci#define R2(a,b,c,d,k,s,t) { \
59e1051a39Sopenharmony_ci        a+=((k)+(t)+H((b),(c),(d))); \
60e1051a39Sopenharmony_ci        a=ROTATE(a,s); };
61