Cross Reference: MD4.java
xref
: /
openjdk7
/
jdk
/
src
/
share
/
classes
/
sun
/
security
/
provider
/
MD4.java
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
0
N/A
/*
2362
N/A
* Copyright (c) 2005, 2006, Oracle
and
/
or
its affiliates. All rights reserved.
0
N/A
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0
N/A
*
0
N/A
* This code is free software; you can redistribute it
and
/
or
modify it
0
N/A
* under the terms of the GNU General Public License version 2 only, as
2362
N/A
* published by the Free Software Foundation. Oracle designates this
0
N/A
* particular file as subject to the "Classpath" exception as provided
2362
N/A
* by Oracle in the LICENSE file that accompanied this code.
0
N/A
*
0
N/A
* This code is distributed in the hope that it will be useful, but WITHOUT
0
N/A
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0
N/A
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0
N/A
* version 2 for more details (a copy is included in the LICENSE file that
0
N/A
* accompanied this code).
0
N/A
*
0
N/A
* You should have received a copy of the GNU General Public License version
0
N/A
* 2 along with this work; if not, write to the Free Software Foundation,
0
N/A
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0
N/A
*
2362
N/A
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362
N/A
* or visit www.oracle.com if you need additional information or have any
2362
N/A
* questions.
0
N/A
*/
0
N/A
0
N/A
package
sun
.
security
.
provider
;
0
N/A
0
N/A
import
java
.
security
.*;
0
N/A
0
N/A
import
static
sun
.
security
.
provider
.
ByteArrayAccess
.*;
0
N/A
0
N/A
/**
0
N/A
* The MD4 class is used to compute an MD4 message digest over a given
0
N/A
* buffer of bytes. It is an implementation of the RSA Data Security Inc
0
N/A
* MD4 algorithim as described in internet RFC 1320.
0
N/A
*
0
N/A
* <p>The MD4 algorithm is very weak and should not be used unless it is
0
N/A
* unavoidable. Therefore, it is not registered in our standard providers. To
0
N/A
* obtain an implementation, call the static getInstance() method in this
0
N/A
* class.
0
N/A
*
0
N/A
*
@author
Andreas Sterbenz
0
N/A
*/
0
N/A
public
final
class
MD4
extends
DigestBase
{
0
N/A
0
N/A
// state of this object
0
N/A
private
final
int
[]
state
;
0
N/A
// temporary buffer, used by implCompress()
0
N/A
private
final
int
[] x;
0
N/A
0
N/A
// rotation constants
0
N/A
private
static
final
int
S11
=
3
;
0
N/A
private
static
final
int
S12
=
7
;
0
N/A
private
static
final
int
S13
=
11
;
0
N/A
private
static
final
int
S14
=
19
;
0
N/A
private
static
final
int
S21
=
3
;
0
N/A
private
static
final
int
S22
=
5
;
0
N/A
private
static
final
int
S23
=
9
;
0
N/A
private
static
final
int
S24
=
13
;
0
N/A
private
static
final
int
S31
=
3
;
0
N/A
private
static
final
int
S32
=
9
;
0
N/A
private
static
final
int
S33
=
11
;
0
N/A
private
static
final
int
S34
=
15
;
0
N/A
0
N/A
private
final
static
Provider
md4Provider
;
0
N/A
0
N/A
static
{
0
N/A
md4Provider
=
new
Provider
(
"MD4Provider"
,
1.0d
,
"MD4 MessageDigest"
) {};
0
N/A
AccessController
.
doPrivileged
(
new
PrivilegedAction
<
Void
>() {
0
N/A
public
Void
run
() {
0
N/A
md4Provider
.
put
(
"MessageDigest.MD4"
,
"sun.security.provider.MD4"
);
0
N/A
return
null
;
0
N/A
}
0
N/A
});
0
N/A
}
0
N/A
0
N/A
public
static
MessageDigest
getInstance
() {
0
N/A
try
{
0
N/A
return
MessageDigest
.
getInstance
(
"MD4"
,
md4Provider
);
0
N/A
}
catch
(
NoSuchAlgorithmException
e) {
0
N/A
// should never occur
0
N/A
throw
new
ProviderException
(e);
0
N/A
}
0
N/A
}
0
N/A
0
N/A
// Standard constructor, creates a new MD4 instance.
0
N/A
public
MD4
() {
0
N/A
super
(
"MD4"
,
16
,
64
);
0
N/A
state
=
new
int
[
4
];
0
N/A
x =
new
int
[
16
];
0
N/A
implReset
();
0
N/A
}
0
N/A
0
N/A
// Cloning constructor
0
N/A
private
MD4
(
MD4
base
) {
0
N/A
super
(
base
);
0
N/A
this
.
state
=
base
.
state
.
clone
();
0
N/A
this
.x =
new
int
[
16
];
0
N/A
}
0
N/A
0
N/A
// clone this object
0
N/A
public
Object
clone
() {
0
N/A
return
new
MD4
(
this
);
0
N/A
}
0
N/A
0
N/A
/**
0
N/A
* Reset the state of this object.
0
N/A
*/
0
N/A
void
implReset
() {
0
N/A
// Load magic initialization constants.
0
N/A
state
[
0
] =
0x67452301
;
0
N/A
state
[
1
] =
0xefcdab89
;
0
N/A
state
[
2
] =
0x98badcfe
;
0
N/A
state
[
3
] =
0x10325476
;
0
N/A
}
0
N/A
0
N/A
/**
0
N/A
* Perform the final computations, any buffered bytes are added
0
N/A
* to the digest, the count is added to the digest, and the resulting
0
N/A
* digest is stored.
0
N/A
*/
0
N/A
void
implDigest
(
byte
[]
out
,
int
ofs
) {
0
N/A
long
bitsProcessed
=
bytesProcessed
<<
3
;
0
N/A
0
N/A
int
index
= (
int
)
bytesProcessed
&
0x3f
;
0
N/A
int
padLen
= (
index
<
56
) ? (
56
-
index
) : (
120
-
index
);
0
N/A
engineUpdate
(
padding
,
0
,
padLen
);
0
N/A
0
N/A
i2bLittle4
((
int
)
bitsProcessed
,
buffer
,
56
);
0
N/A
i2bLittle4
((
int
)(
bitsProcessed
>>>
32
),
buffer
,
60
);
0
N/A
implCompress
(
buffer
,
0
);
0
N/A
0
N/A
i2bLittle
(
state
,
0
,
out
,
ofs
,
16
);
0
N/A
}
0
N/A
0
N/A
private
static
int
FF
(
int
a,
int
b,
int
c,
int
d,
int
x,
int
s) {
0
N/A
a += ((b & c) | ((~b) & d)) + x;
0
N/A
return
((a << s) | (a >>> (
32
- s)));
0
N/A
}
0
N/A
0
N/A
private
static
int
GG
(
int
a,
int
b,
int
c,
int
d,
int
x,
int
s) {
0
N/A
a += ((b & c) | (b & d) | (c & d)) + x +
0x5a827999
;
0
N/A
return
((a << s) | (a >>> (
32
- s)));
0
N/A
}
0
N/A
0
N/A
private
static
int
HH
(
int
a,
int
b,
int
c,
int
d,
int
x,
int
s) {
0
N/A
a += ((b ^ c) ^ d) + x +
0x6ed9eba1
;
0
N/A
return
((a << s) | (a >>> (
32
- s)));
0
N/A
}
0
N/A
0
N/A
/**
0
N/A
* This is where the functions come together as the generic MD4
0
N/A
* transformation operation. It consumes sixteen
0
N/A
* bytes from the buffer, beginning at the specified offset.
0
N/A
*/
0
N/A
void
implCompress
(
byte
[]
buf
,
int
ofs
) {
0
N/A
b2iLittle64
(
buf
,
ofs
, x);
0
N/A
0
N/A
int
a =
state
[
0
];
0
N/A
int
b =
state
[
1
];
0
N/A
int
c =
state
[
2
];
0
N/A
int
d =
state
[
3
];
0
N/A
0
N/A
/* Round 1 */
0
N/A
a =
FF
(a, b, c, d, x[
0
],
S11
);
/* 1 */
0
N/A
d =
FF
(d, a, b, c, x[
1
],
S12
);
/* 2 */
0
N/A
c =
FF
(c, d, a, b, x[
2
],
S13
);
/* 3 */
0
N/A
b =
FF
(b, c, d, a, x[
3
],
S14
);
/* 4 */
0
N/A
a =
FF
(a, b, c, d, x[
4
],
S11
);
/* 5 */
0
N/A
d =
FF
(d, a, b, c, x[
5
],
S12
);
/* 6 */
0
N/A
c =
FF
(c, d, a, b, x[
6
],
S13
);
/* 7 */
0
N/A
b =
FF
(b, c, d, a, x[
7
],
S14
);
/* 8 */
0
N/A
a =
FF
(a, b, c, d, x[
8
],
S11
);
/* 9 */
0
N/A
d =
FF
(d, a, b, c, x[
9
],
S12
);
/* 10 */
0
N/A
c =
FF
(c, d, a, b, x[
10
],
S13
);
/* 11 */
0
N/A
b =
FF
(b, c, d, a, x[
11
],
S14
);
/* 12 */
0
N/A
a =
FF
(a, b, c, d, x[
12
],
S11
);
/* 13 */
0
N/A
d =
FF
(d, a, b, c, x[
13
],
S12
);
/* 14 */
0
N/A
c =
FF
(c, d, a, b, x[
14
],
S13
);
/* 15 */
0
N/A
b =
FF
(b, c, d, a, x[
15
],
S14
);
/* 16 */
0
N/A
0
N/A
/* Round 2 */
0
N/A
a =
GG
(a, b, c, d, x[
0
],
S21
);
/* 17 */
0
N/A
d =
GG
(d, a, b, c, x[
4
],
S22
);
/* 18 */
0
N/A
c =
GG
(c, d, a, b, x[
8
],
S23
);
/* 19 */
0
N/A
b =
GG
(b, c, d, a, x[
12
],
S24
);
/* 20 */
0
N/A
a =
GG
(a, b, c, d, x[
1
],
S21
);
/* 21 */
0
N/A
d =
GG
(d, a, b, c, x[
5
],
S22
);
/* 22 */
0
N/A
c =
GG
(c, d, a, b, x[
9
],
S23
);
/* 23 */
0
N/A
b =
GG
(b, c, d, a, x[
13
],
S24
);
/* 24 */
0
N/A
a =
GG
(a, b, c, d, x[
2
],
S21
);
/* 25 */
0
N/A
d =
GG
(d, a, b, c, x[
6
],
S22
);
/* 26 */
0
N/A
c =
GG
(c, d, a, b, x[
10
],
S23
);
/* 27 */
0
N/A
b =
GG
(b, c, d, a, x[
14
],
S24
);
/* 28 */
0
N/A
a =
GG
(a, b, c, d, x[
3
],
S21
);
/* 29 */
0
N/A
d =
GG
(d, a, b, c, x[
7
],
S22
);
/* 30 */
0
N/A
c =
GG
(c, d, a, b, x[
11
],
S23
);
/* 31 */
0
N/A
b =
GG
(b, c, d, a, x[
15
],
S24
);
/* 32 */
0
N/A
0
N/A
/* Round 3 */
0
N/A
a =
HH
(a, b, c, d, x[
0
],
S31
);
/* 33 */
0
N/A
d =
HH
(d, a, b, c, x[
8
],
S32
);
/* 34 */
0
N/A
c =
HH
(c, d, a, b, x[
4
],
S33
);
/* 35 */
0
N/A
b =
HH
(b, c, d, a, x[
12
],
S34
);
/* 36 */
0
N/A
a =
HH
(a, b, c, d, x[
2
],
S31
);
/* 37 */
0
N/A
d =
HH
(d, a, b, c, x[
10
],
S32
);
/* 38 */
0
N/A
c =
HH
(c, d, a, b, x[
6
],
S33
);
/* 39 */
0
N/A
b =
HH
(b, c, d, a, x[
14
],
S34
);
/* 40 */
0
N/A
a =
HH
(a, b, c, d, x[
1
],
S31
);
/* 41 */
0
N/A
d =
HH
(d, a, b, c, x[
9
],
S32
);
/* 42 */
0
N/A
c =
HH
(c, d, a, b, x[
5
],
S33
);
/* 43 */
0
N/A
b =
HH
(b, c, d, a, x[
13
],
S34
);
/* 44 */
0
N/A
a =
HH
(a, b, c, d, x[
3
],
S31
);
/* 45 */
0
N/A
d =
HH
(d, a, b, c, x[
11
],
S32
);
/* 46 */
0
N/A
c =
HH
(c, d, a, b, x[
7
],
S33
);
/* 47 */
0
N/A
b =
HH
(b, c, d, a, x[
15
],
S34
);
/* 48 */
0
N/A
0
N/A
state
[
0
] += a;
0
N/A
state
[
1
] += b;
0
N/A
state
[
2
] += c;
0
N/A
state
[
3
] += d;
0
N/A
}
0
N/A
0
N/A
}