1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
/*******************************************************************************
* Copyright 2014-2018 Intel Corporation
* All Rights Reserved.
*
* If this software was obtained under the Intel Simplified Software License,
* the following terms apply:
*
* The source code, information and material ("Material") contained herein is
* owned by Intel Corporation or its suppliers or licensors, and title to such
* Material remains with Intel Corporation or its suppliers or licensors. The
* Material contains proprietary information of Intel or its suppliers and
* licensors. The Material is protected by worldwide copyright laws and treaty
* provisions. No part of the Material may be used, copied, reproduced,
* modified, published, uploaded, posted, transmitted, distributed or disclosed
* in any way without Intel's prior express written permission. No license under
* any patent, copyright or other intellectual property rights in the Material
* is granted to or conferred upon you, either expressly, by implication,
* inducement, estoppel or otherwise. Any license under such intellectual
* property rights must be express and approved by Intel in writing.
*
* Unless otherwise agreed by Intel in writing, you may not remove or alter this
* notice or any other notice embedded in Materials by Intel or Intel's
* suppliers or licensors in any way.
*
*
* If this software was obtained under the Apache License, Version 2.0 (the
* "License"), the following terms apply:
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
/*
//
// Purpose:
// Cryptography Primitive.
// Message block processing according to MD5
//
// Contents:
// UpdateMD5()
//
//
*/
#include "owndefs.h"
#include "owncp.h"
#include "pcphash.h"
#include "pcptool.h"
#if !defined(_ENABLE_ALG_MD5_)
#pragma message("IPP_ALG_HASH_MD5 disabled")
#else
#pragma message("IPP_ALG_HASH_MD5 enabled")
#if !((_IPP==_IPP_M5) || \
(_IPP==_IPP_W7) || (_IPP==_IPP_T7) || \
(_IPP==_IPP_V8) || (_IPP==_IPP_P8) || \
(_IPP==_IPP_S8) || (_IPP>=_IPP_G9) || \
(_IPP32E==_IPP32E_M7) || \
(_IPP32E==_IPP32E_U8) || (_IPP32E==_IPP32E_Y8) || \
(_IPP32E==_IPP32E_N8) || (_IPP32E>=_IPP32E_E9))
/*
// Magic functions defined in RFC 1321
//
*/
#define F(X,Y,Z) ((Z) ^ ((X) & ((Y) ^ (Z)))) /* sightly optimized form of (((X) & (Y)) | ((~(X) & (Z)))*/
#define G(X,Y,Z) F((Z),(X),(Y)) /* replace the original (((X) & (Z)) | ((Y) & ~(Z))) */
#define H(X,Y,Z) ((X) ^ (Y) ^ (Z))
#define I(X,Y,Z) ((Y) ^ ((X) | ~(Z)))
/*
// MD5 step
*/
#define MD5_STEP(MAGIC, A,B,C,D, data, constant, nrot) \
(A = B +ROL32((A +MAGIC(B,C,D) +data +constant), nrot))
/*
// MD5 left rotations (number of bits)
// depends on round type
*/
#define F1 7
#define F2 12
#define F3 17
#define F4 22
#define G1 5
#define G2 9
#define G3 14
#define G4 20
#define H1 4
#define H2 11
#define H3 16
#define H4 23
#define I1 6
#define I2 10
#define I3 15
#define I4 21
/*F*
// Name: UpdateMD5
//
// Purpose: Update internal hash according to input message stream.
//
// Parameters:
// uniHash pointer to in/out hash
// mblk pointer to message stream
// mlen message stream length (multiple by message block size)
// uniParam pointer to the optional parameter
//
*F*/
void UpdateMD5(void* uinHash, const Ipp8u* mblk, int mlen, const void* uniParam)
{
Ipp32u* digest = (Ipp32u*)uinHash;
Ipp32u* MD5_cnt_loc = (Ipp32u*)uniParam;
for(; mlen>=MBS_MD5; mblk += MBS_MD5, mlen -= MBS_MD5) {
/* allocate data */
#if (IPP_ENDIAN == IPP_BIG_ENDIAN)
Ipp32u data[MBS_MD5/sizeof(Ipp32u)];
#else
/* or just word alias */
Ipp32u* data = (Ipp32u*)mblk;
#endif
/* init variables */
Ipp32u a = digest[0];
Ipp32u b = digest[1];
Ipp32u c = digest[2];
Ipp32u d = digest[3];
#if (IPP_ENDIAN == IPP_BIG_ENDIAN)
int t;
for(t=0; t<16; t++) {
data[t] = ENDIANNESS(((Ipp32u*)mblk)[t]);
}
#endif
/* rounds type F */
MD5_STEP(F, a,b,c,d, data[ 0], MD5_cnt_loc[ 0], F1);
MD5_STEP(F, d,a,b,c, data[ 1], MD5_cnt_loc[ 1], F2);
MD5_STEP(F, c,d,a,b, data[ 2], MD5_cnt_loc[ 2], F3);
MD5_STEP(F, b,c,d,a, data[ 3], MD5_cnt_loc[ 3], F4);
MD5_STEP(F, a,b,c,d, data[ 4], MD5_cnt_loc[ 4], F1);
MD5_STEP(F, d,a,b,c, data[ 5], MD5_cnt_loc[ 5], F2);
MD5_STEP(F, c,d,a,b, data[ 6], MD5_cnt_loc[ 6], F3);
MD5_STEP(F, b,c,d,a, data[ 7], MD5_cnt_loc[ 7], F4);
MD5_STEP(F, a,b,c,d, data[ 8], MD5_cnt_loc[ 8], F1);
MD5_STEP(F, d,a,b,c, data[ 9], MD5_cnt_loc[ 9], F2);
MD5_STEP(F, c,d,a,b, data[10], MD5_cnt_loc[10], F3);
MD5_STEP(F, b,c,d,a, data[11], MD5_cnt_loc[11], F4);
MD5_STEP(F, a,b,c,d, data[12], MD5_cnt_loc[12], F1);
MD5_STEP(F, d,a,b,c, data[13], MD5_cnt_loc[13], F2);
MD5_STEP(F, c,d,a,b, data[14], MD5_cnt_loc[14], F3);
MD5_STEP(F, b,c,d,a, data[15], MD5_cnt_loc[15], F4);
/* rounds type G */
MD5_STEP(G, a,b,c,d, data[ 1], MD5_cnt_loc[16], G1);
MD5_STEP(G, d,a,b,c, data[ 6], MD5_cnt_loc[17], G2);
MD5_STEP(G, c,d,a,b, data[11], MD5_cnt_loc[18], G3);
MD5_STEP(G, b,c,d,a, data[ 0], MD5_cnt_loc[19], G4);
MD5_STEP(G, a,b,c,d, data[ 5], MD5_cnt_loc[20], G1);
MD5_STEP(G, d,a,b,c, data[10], MD5_cnt_loc[21], G2);
MD5_STEP(G, c,d,a,b, data[15], MD5_cnt_loc[22], G3);
MD5_STEP(G, b,c,d,a, data[ 4], MD5_cnt_loc[23], G4);
MD5_STEP(G, a,b,c,d, data[ 9], MD5_cnt_loc[24], G1);
MD5_STEP(G, d,a,b,c, data[14], MD5_cnt_loc[25], G2);
MD5_STEP(G, c,d,a,b, data[ 3], MD5_cnt_loc[26], G3);
MD5_STEP(G, b,c,d,a, data[ 8], MD5_cnt_loc[27], G4);
MD5_STEP(G, a,b,c,d, data[13], MD5_cnt_loc[28], G1);
MD5_STEP(G, d,a,b,c, data[ 2], MD5_cnt_loc[29], G2);
MD5_STEP(G, c,d,a,b, data[ 7], MD5_cnt_loc[30], G3);
MD5_STEP(G, b,c,d,a, data[12], MD5_cnt_loc[31], G4);
/* rounds type H */
MD5_STEP(H, a,b,c,d, data[ 5], MD5_cnt_loc[32], H1);
MD5_STEP(H, d,a,b,c, data[ 8], MD5_cnt_loc[33], H2);
MD5_STEP(H, c,d,a,b, data[11], MD5_cnt_loc[34], H3);
MD5_STEP(H, b,c,d,a, data[14], MD5_cnt_loc[35], H4);
MD5_STEP(H, a,b,c,d, data[ 1], MD5_cnt_loc[36], H1);
MD5_STEP(H, d,a,b,c, data[ 4], MD5_cnt_loc[37], H2);
MD5_STEP(H, c,d,a,b, data[ 7], MD5_cnt_loc[38], H3);
MD5_STEP(H, b,c,d,a, data[10], MD5_cnt_loc[39], H4);
MD5_STEP(H, a,b,c,d, data[13], MD5_cnt_loc[40], H1);
MD5_STEP(H, d,a,b,c, data[ 0], MD5_cnt_loc[41], H2);
MD5_STEP(H, c,d,a,b, data[ 3], MD5_cnt_loc[42], H3);
MD5_STEP(H, b,c,d,a, data[ 6], MD5_cnt_loc[43], H4);
MD5_STEP(H, a,b,c,d, data[ 9], MD5_cnt_loc[44], H1);
MD5_STEP(H, d,a,b,c, data[12], MD5_cnt_loc[45], H2);
MD5_STEP(H, c,d,a,b, data[15], MD5_cnt_loc[46], H3);
MD5_STEP(H, b,c,d,a, data[ 2], MD5_cnt_loc[47], H4);
/* rounds type I */
MD5_STEP(I, a,b,c,d, data[ 0], MD5_cnt_loc[48], I1);
MD5_STEP(I, d,a,b,c, data[ 7], MD5_cnt_loc[49], I2);
MD5_STEP(I, c,d,a,b, data[14], MD5_cnt_loc[50], I3);
MD5_STEP(I, b,c,d,a, data[ 5], MD5_cnt_loc[51], I4);
MD5_STEP(I, a,b,c,d, data[12], MD5_cnt_loc[52], I1);
MD5_STEP(I, d,a,b,c, data[ 3], MD5_cnt_loc[53], I2);
MD5_STEP(I, c,d,a,b, data[10], MD5_cnt_loc[54], I3);
MD5_STEP(I, b,c,d,a, data[ 1], MD5_cnt_loc[55], I4);
MD5_STEP(I, a,b,c,d, data[ 8], MD5_cnt_loc[56], I1);
MD5_STEP(I, d,a,b,c, data[15], MD5_cnt_loc[57], I2);
MD5_STEP(I, c,d,a,b, data[ 6], MD5_cnt_loc[58], I3);
MD5_STEP(I, b,c,d,a, data[13], MD5_cnt_loc[59], I4);
MD5_STEP(I, a,b,c,d, data[ 4], MD5_cnt_loc[60], I1);
MD5_STEP(I, d,a,b,c, data[11], MD5_cnt_loc[61], I2);
MD5_STEP(I, c,d,a,b, data[ 2], MD5_cnt_loc[62], I3);
MD5_STEP(I, b,c,d,a, data[ 9], MD5_cnt_loc[63], I4);
/* update digest */
digest[0] += a;
digest[1] += b;
digest[2] += c;
digest[3] += d;
}
}
#endif
#endif /* IPP_ALG_HASH_MD5 */
|