Coverage Report

Created: 2024-11-21 07:03

/src/cryptopp/md4.cpp
Line
Count
Source
1
// md4.cpp - modified by Wei Dai from Andrew M. Kuchling's md4.c
2
// The original code and all modifications are in the public domain.
3
4
// This is the original introductory comment:
5
6
/*
7
 *  md4.c : MD4 hash algorithm.
8
 *
9
 * Part of the Python Cryptography Toolkit, version 1.1
10
 *
11
 * Distribute and use freely; there are no restrictions on further
12
 * dissemination and usage except those imposed by the laws of your
13
 * country of residence.
14
 *
15
 */
16
17
#include "pch.h"
18
#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
19
#include "md4.h"
20
#include "misc.h"
21
22
NAMESPACE_BEGIN(CryptoPP)
23
namespace Weak1 {
24
25
void MD4::InitState(HashWordType *state)
26
21.0k
{
27
21.0k
  state[0] = 0x67452301L;
28
21.0k
  state[1] = 0xefcdab89L;
29
21.0k
  state[2] = 0x98badcfeL;
30
21.0k
  state[3] = 0x10325476L;
31
21.0k
}
32
33
void MD4::Transform (word32 *digest, const word32 *in)
34
862k
{
35
// #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
36
13.7M
#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
37
13.7M
#define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
38
13.7M
#define H(x, y, z) ((x) ^ (y) ^ (z))
39
40
862k
    word32 A, B, C, D;
41
42
862k
  A=digest[0];
43
862k
  B=digest[1];
44
862k
  C=digest[2];
45
862k
  D=digest[3];
46
47
13.7M
#define function(a,b,c,d,k,s) a=rotlVariable(a+F(b,c,d)+in[k],s);
48
862k
    function(A,B,C,D, 0, 3);
49
862k
    function(D,A,B,C, 1, 7);
50
862k
    function(C,D,A,B, 2,11);
51
862k
    function(B,C,D,A, 3,19);
52
862k
    function(A,B,C,D, 4, 3);
53
862k
    function(D,A,B,C, 5, 7);
54
862k
    function(C,D,A,B, 6,11);
55
862k
    function(B,C,D,A, 7,19);
56
862k
    function(A,B,C,D, 8, 3);
57
862k
    function(D,A,B,C, 9, 7);
58
862k
    function(C,D,A,B,10,11);
59
862k
    function(B,C,D,A,11,19);
60
862k
    function(A,B,C,D,12, 3);
61
862k
    function(D,A,B,C,13, 7);
62
862k
    function(C,D,A,B,14,11);
63
862k
    function(B,C,D,A,15,19);
64
65
862k
#undef function
66
13.7M
#define function(a,b,c,d,k,s) a=rotlVariable(a+G(b,c,d)+in[k]+0x5a827999,s);
67
862k
    function(A,B,C,D, 0, 3);
68
862k
    function(D,A,B,C, 4, 5);
69
862k
    function(C,D,A,B, 8, 9);
70
862k
    function(B,C,D,A,12,13);
71
862k
    function(A,B,C,D, 1, 3);
72
862k
    function(D,A,B,C, 5, 5);
73
862k
    function(C,D,A,B, 9, 9);
74
862k
    function(B,C,D,A,13,13);
75
862k
    function(A,B,C,D, 2, 3);
76
862k
    function(D,A,B,C, 6, 5);
77
862k
    function(C,D,A,B,10, 9);
78
862k
    function(B,C,D,A,14,13);
79
862k
    function(A,B,C,D, 3, 3);
80
862k
    function(D,A,B,C, 7, 5);
81
862k
    function(C,D,A,B,11, 9);
82
862k
    function(B,C,D,A,15,13);
83
84
862k
#undef function
85
13.7M
#define function(a,b,c,d,k,s) a=rotlVariable(a+H(b,c,d)+in[k]+0x6ed9eba1,s);
86
862k
    function(A,B,C,D, 0, 3);
87
862k
    function(D,A,B,C, 8, 9);
88
862k
    function(C,D,A,B, 4,11);
89
862k
    function(B,C,D,A,12,15);
90
862k
    function(A,B,C,D, 2, 3);
91
862k
    function(D,A,B,C,10, 9);
92
862k
    function(C,D,A,B, 6,11);
93
862k
    function(B,C,D,A,14,15);
94
862k
    function(A,B,C,D, 1, 3);
95
862k
    function(D,A,B,C, 9, 9);
96
862k
    function(C,D,A,B, 5,11);
97
862k
    function(B,C,D,A,13,15);
98
862k
    function(A,B,C,D, 3, 3);
99
862k
    function(D,A,B,C,11, 9);
100
862k
    function(C,D,A,B, 7,11);
101
862k
    function(B,C,D,A,15,15);
102
103
862k
  digest[0]+=A;
104
862k
  digest[1]+=B;
105
862k
  digest[2]+=C;
106
862k
  digest[3]+=D;
107
862k
}
108
109
}
110
NAMESPACE_END