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

📄 ripemd320digest.java

📁 这是一个基于java编写的torrent的P2P源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package org.bouncycastle.crypto.digests;


/**
 * implementation of RIPEMD 320.
 * <p>
 * <b>Note:</b> this implementation offers the same level of security
 * as RIPEMD 160.
 */
public class RIPEMD320Digest
    extends GeneralDigest
{
	private static final int DIGEST_LENGTH = 40;

	private int H0, H1, H2, H3, H4, H5, H6, H7, H8, H9; // IV's

	private int[] X = new int[16];
	private int xOff;

	/**
	 * Standard constructor
	 */
	public RIPEMD320Digest()
	{
		reset();
	}

	/**
	 * Copy constructor.  This will copy the state of the provided
	 * message digest.
	 */
	public RIPEMD320Digest(RIPEMD320Digest t)
	{
		super(t);

		H0 = t.H0;
		H1 = t.H1;
		H2 = t.H2;
		H3 = t.H3;
		H4 = t.H4;
		H5 = t.H5;
		H6 = t.H6;
		H7 = t.H7;
		H8 = t.H8;
		H9 = t.H9;
		
		System.arraycopy(t.X, 0, X, 0, t.X.length);
		xOff = t.xOff;
	}

	public String getAlgorithmName()
	{
		return "RIPEMD320";
	}

	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);
		unpackWord(H5, out, outOff + 20);
		unpackWord(H6, out, outOff + 24);
		unpackWord(H7, out, outOff + 28);
		unpackWord(H8, out, outOff + 32);
		unpackWord(H9, out, outOff + 36);

		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;
		H5 = 0x76543210; 
		H6 = 0xFEDCBA98;
		H7 = 0x89ABCDEF; 
		H8 = 0x01234567; 
		H9 = 0x3C2D1E0F;

		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;
        int t;

		a = H0;
		b = H1;
		c = H2;
		d = H3;
		e = H4;
		aa = H5;
		bb = H6;
		cc = H7;
		dd = H8;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -