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