1 /*
2 * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
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
84 }
85
86 /**
87 * Resets the buffers and hash value to start a new hash.
88 */
89 void implReset() {
90 System.arraycopy(initialHashes, 0, state, 0, state.length);
91 }
92
93 void implDigest(byte[] out, int ofs) {
94 long bitsProcessed = bytesProcessed << 3;
95
96 int index = (int)bytesProcessed & 0x3f;
97 int padLen = (index < 56) ? (56 - index) : (120 - index);
98 engineUpdate(padding, 0, padLen);
99
100 i2bBig4((int)(bitsProcessed >>> 32), buffer, 56);
101 i2bBig4((int)bitsProcessed, buffer, 60);
102 implCompress(buffer, 0);
103
104 i2bBig(state, 0, out, ofs, 32);
105 }
106
107 /**
108 * logical function ch(x,y,z) as defined in spec:
109 * @return (x and y) xor ((complement x) and z)
110 * @param x int
111 * @param y int
112 * @param z int
113 */
114 private static int lf_ch(int x, int y, int z) {
115 return (x & y) ^ ((~x) & z);
116 }
117
118 /**
119 * logical function maj(x,y,z) as defined in spec:
120 * @return (x and y) xor (x and z) xor (y and z)
121 * @param x int
122 * @param y int
123 * @param z int
124 */
|
1 /*
2 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
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
84 }
85
86 /**
87 * Resets the buffers and hash value to start a new hash.
88 */
89 void implReset() {
90 System.arraycopy(initialHashes, 0, state, 0, state.length);
91 }
92
93 void implDigest(byte[] out, int ofs) {
94 long bitsProcessed = bytesProcessed << 3;
95
96 int index = (int)bytesProcessed & 0x3f;
97 int padLen = (index < 56) ? (56 - index) : (120 - index);
98 engineUpdate(padding, 0, padLen);
99
100 i2bBig4((int)(bitsProcessed >>> 32), buffer, 56);
101 i2bBig4((int)bitsProcessed, buffer, 60);
102 implCompress(buffer, 0);
103
104 i2bBig(state, 0, out, ofs, engineGetDigestLength());
105 }
106
107 /**
108 * logical function ch(x,y,z) as defined in spec:
109 * @return (x and y) xor ((complement x) and z)
110 * @param x int
111 * @param y int
112 * @param z int
113 */
114 private static int lf_ch(int x, int y, int z) {
115 return (x & y) ^ ((~x) & z);
116 }
117
118 /**
119 * logical function maj(x,y,z) as defined in spec:
120 * @return (x and y) xor (x and z) xor (y and z)
121 * @param x int
122 * @param y int
123 * @param z int
124 */
|