⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ripemd160digest.java

📁 关于J2me自动登录的源代码实例工具属于简体中文版
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
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 + -