?? ripemd160digest.java
字號:
package org.bouncycastle.crypto.digests;/** * implementation of RIPEMD see, * http://www.esat.kuleuven.ac.be/~bosselae/ripemd160.html */public class RIPEMD160Digest extends GeneralDigest{ private static final int DIGEST_LENGTH = 20; private int H0, H1, H2, H3, H4; // IV's private int[] X = new int[16]; private int xOff; /** * Standard constructor */ public RIPEMD160Digest() { reset(); } /** * Copy constructor. This will copy the state of the provided * message digest. */ public RIPEMD160Digest(RIPEMD160Digest t) { super(t); H0 = t.H0; H1 = t.H1; H2 = t.H2; H3 = t.H3; H4 = t.H4; System.arraycopy(t.X, 0, X, 0, t.X.length); xOff = t.xOff; } public String getAlgorithmName() { return "RIPEMD160"; } public int getDigestSize() { return DIGEST_LENGTH; } protected void processWord( byte[] in, int inOff) { X[xOff++] = (in[inOff] & 0xff) | ((in[inOff + 1] & 0xff) << 8) | ((in[inOff + 2] & 0xff) << 16) | ((in[inOff + 3] & 0xff) << 24); if (xOff == 16) { processBlock(); } } protected void processLength( long bitLength) { if (xOff > 14) { processBlock(); } X[14] = (int)(bitLength & 0xffffffff); X[15] = (int)(bitLength >>> 32); } private void unpackWord( int word, byte[] out, int outOff) { out[outOff] = (byte)word; out[outOff + 1] = (byte)(word >>> 8); out[outOff + 2] = (byte)(word >>> 16); out[outOff + 3] = (byte)(word >>> 24); } public int doFinal( byte[] out, int outOff) { finish(); unpackWord(H0, out, outOff); unpackWord(H1, out, outOff + 4); unpackWord(H2, out, outOff + 8); unpackWord(H3, out, outOff + 12); unpackWord(H4, out, outOff + 16); reset(); return DIGEST_LENGTH; } /** * reset the chaining variables to the IV values. */ public void reset() { super.reset(); H0 = 0x67452301; H1 = 0xefcdab89; H2 = 0x98badcfe; H3 = 0x10325476; H4 = 0xc3d2e1f0; xOff = 0; for (int i = 0; i != X.length; i++) { X[i] = 0; } } /* * rotate int x left n bits. */ private final int RL( int x, int n) { return (x << n) | (x >>> (32 - n)); } /* * f1,f2,f3,f4,f5 are the basic RIPEMD160 functions. */ /* * rounds 0-15 */ private final int f1( int x, int y, int z) { return x ^ y ^ z; } /* * rounds 16-31 */ private final int f2( int x, int y, int z) { return (x & y) | (~x & z); } /* * rounds 32-47 */ private final int f3( int x, int y, int z) { return (x | ~y) ^ z; } /* * rounds 48-63 */ private final int f4( int x, int y, int z) { return (x & z) | (y & ~z); } /* * rounds 64-79 */ private final int f5( int x, int y, int z) { return x ^ (y | ~z); } protected void processBlock() { int a, aa; int b, bb; int c, cc; int d, dd; int e, ee; a = aa = H0; b = bb = H1; c = cc = H2; d = dd = H3; e = ee = H4; // // Rounds 1 - 16
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -