9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.security.provider;
27
28 import java.util.Arrays;
29
30 import static sun.security.provider.ByteArrayAccess.*;
31
32 /**
33 * The MD5 class is used to compute an MD5 message digest over a given
34 * buffer of bytes. It is an implementation of the RSA Data Security Inc
35 * MD5 algorithim as described in internet RFC 1321.
36 *
37 * @author Chuck McManis
38 * @author Benjamin Renaud
39 * @author Andreas Sterbenz
40 */
41 public final class MD5 extends DigestBase {
42
43 // state of this object
44 private int[] state;
45 // temporary buffer, used by implCompress()
46 private int[] x;
47
48 // rotation constants
49 private static final int S11 = 7;
50 private static final int S12 = 12;
130 a += ((b & d) | (c & (~d))) + x + ac;
131 return ((a << s) | (a >>> (32 - s))) + b;
132 }
133
134 private static int HH(int a, int b, int c, int d, int x, int s, int ac) {
135 a += ((b ^ c) ^ d) + x + ac;
136 return ((a << s) | (a >>> (32 - s))) + b;
137 }
138
139 private static int II(int a, int b, int c, int d, int x, int s, int ac) {
140 a += (c ^ (b | (~d))) + x + ac;
141 return ((a << s) | (a >>> (32 - s))) + b;
142 }
143
144 /**
145 * This is where the functions come together as the generic MD5
146 * transformation operation. It consumes sixteen
147 * bytes from the buffer, beginning at the specified offset.
148 */
149 void implCompress(byte[] buf, int ofs) {
150 b2iLittle64(buf, ofs, x);
151
152 int a = state[0];
153 int b = state[1];
154 int c = state[2];
155 int d = state[3];
156
157 /* Round 1 */
158 a = FF ( a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
159 d = FF ( d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
160 c = FF ( c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
161 b = FF ( b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
162 a = FF ( a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
163 d = FF ( d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
164 c = FF ( c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
165 b = FF ( b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
166 a = FF ( a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
167 d = FF ( d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
168 c = FF ( c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
169 b = FF ( b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
170 a = FF ( a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
171 d = FF ( d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
|
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.security.provider;
27
28 import java.util.Arrays;
29 import java.util.Objects;
30
31 import static sun.security.provider.ByteArrayAccess.*;
32 import jdk.internal.HotSpotIntrinsicCandidate;
33
34 /**
35 * The MD5 class is used to compute an MD5 message digest over a given
36 * buffer of bytes. It is an implementation of the RSA Data Security Inc
37 * MD5 algorithim as described in internet RFC 1321.
38 *
39 * @author Chuck McManis
40 * @author Benjamin Renaud
41 * @author Andreas Sterbenz
42 */
43 public final class MD5 extends DigestBase {
44
45 // state of this object
46 private int[] state;
47 // temporary buffer, used by implCompress()
48 private int[] x;
49
50 // rotation constants
51 private static final int S11 = 7;
52 private static final int S12 = 12;
132 a += ((b & d) | (c & (~d))) + x + ac;
133 return ((a << s) | (a >>> (32 - s))) + b;
134 }
135
136 private static int HH(int a, int b, int c, int d, int x, int s, int ac) {
137 a += ((b ^ c) ^ d) + x + ac;
138 return ((a << s) | (a >>> (32 - s))) + b;
139 }
140
141 private static int II(int a, int b, int c, int d, int x, int s, int ac) {
142 a += (c ^ (b | (~d))) + x + ac;
143 return ((a << s) | (a >>> (32 - s))) + b;
144 }
145
146 /**
147 * This is where the functions come together as the generic MD5
148 * transformation operation. It consumes sixteen
149 * bytes from the buffer, beginning at the specified offset.
150 */
151 void implCompress(byte[] buf, int ofs) {
152 implCompressCheck(buf, ofs);
153 implCompress0(buf, ofs);
154 }
155
156 private void implCompressCheck(byte[] buf, int ofs) {
157 Objects.requireNonNull(buf);
158
159 // The checks performed by the method 'b2iBig64'
160 // are sufficient for the case when the method
161 // 'implCompressImpl' is replaced with a compiler
162 // intrinsic.
163 b2iLittle64(buf, ofs, x);
164 }
165
166 // The method 'implCompress0 seems not to use its parameters.
167 // The method can, however, be replaced with a compiler intrinsic
168 // that operates directly on the array 'buf' (starting from
169 // offset 'ofs') and not on array 'x', therefore 'buf' and 'ofs'
170 // must be passed as parameter to the method.
171 @HotSpotIntrinsicCandidate
172 void implCompress0(byte[] buf, int ofs) {
173 int a = state[0];
174 int b = state[1];
175 int c = state[2];
176 int d = state[3];
177
178 /* Round 1 */
179 a = FF ( a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
180 d = FF ( d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
181 c = FF ( c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
182 b = FF ( b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
183 a = FF ( a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
184 d = FF ( d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
185 c = FF ( c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
186 b = FF ( b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
187 a = FF ( a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
188 d = FF ( d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
189 c = FF ( c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
190 b = FF ( b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
191 a = FF ( a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
192 d = FF ( d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
|