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

📄 digest-sha512.c

📁 海思KEY驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
	t2 = e0(c) + Maj(c,d,e);    f+=t1;    b=t1+t2;	t1 = a + e1(f) + Ch(f,g,h) + 0x92722c851482353b + W[39];	t2 = e0(b) + Maj(b,c,d);    e+=t1;    a=t1+t2;	t1 = h + e1(e) + Ch(e,f,g) + 0xa2bfe8a14cf10364 + W[40];	t2 = e0(a) + Maj(a,b,c);    d+=t1;    h=t1+t2;	t1 = g + e1(d) + Ch(d,e,f) + 0xa81a664bbc423001 + W[41];	t2 = e0(h) + Maj(h,a,b);    c+=t1;    g=t1+t2;	t1 = f + e1(c) + Ch(c,d,e) + 0xc24b8b70d0f89791 + W[42];	t2 = e0(g) + Maj(g,h,a);    b+=t1;    f=t1+t2;	t1 = e + e1(b) + Ch(b,c,d) + 0xc76c51a30654be30 + W[43];	t2 = e0(f) + Maj(f,g,h);    a+=t1;    e=t1+t2;	t1 = d + e1(a) + Ch(a,b,c) + 0xd192e819d6ef5218 + W[44];	t2 = e0(e) + Maj(e,f,g);    h+=t1;    d=t1+t2;	t1 = c + e1(h) + Ch(h,a,b) + 0xd69906245565a910 + W[45];	t2 = e0(d) + Maj(d,e,f);    g+=t1;    c=t1+t2;	t1 = b + e1(g) + Ch(g,h,a) + 0xf40e35855771202a + W[46];	t2 = e0(c) + Maj(c,d,e);    f+=t1;    b=t1+t2;	t1 = a + e1(f) + Ch(f,g,h) + 0x106aa07032bbd1b8 + W[47];	t2 = e0(b) + Maj(b,c,d);    e+=t1;    a=t1+t2;	t1 = h + e1(e) + Ch(e,f,g) + 0x19a4c116b8d2d0c8 + W[48];	t2 = e0(a) + Maj(a,b,c);    d+=t1;    h=t1+t2;	t1 = g + e1(d) + Ch(d,e,f) + 0x1e376c085141ab53 + W[49];	t2 = e0(h) + Maj(h,a,b);    c+=t1;    g=t1+t2;	t1 = f + e1(c) + Ch(c,d,e) + 0x2748774cdf8eeb99 + W[50];	t2 = e0(g) + Maj(g,h,a);    b+=t1;    f=t1+t2;	t1 = e + e1(b) + Ch(b,c,d) + 0x34b0bcb5e19b48a8 + W[51];	t2 = e0(f) + Maj(f,g,h);    a+=t1;    e=t1+t2;	t1 = d + e1(a) + Ch(a,b,c) + 0x391c0cb3c5c95a63 + W[52];	t2 = e0(e) + Maj(e,f,g);    h+=t1;    d=t1+t2;	t1 = c + e1(h) + Ch(h,a,b) + 0x4ed8aa4ae3418acb + W[53];	t2 = e0(d) + Maj(d,e,f);    g+=t1;    c=t1+t2;	t1 = b + e1(g) + Ch(g,h,a) + 0x5b9cca4f7763e373 + W[54];	t2 = e0(c) + Maj(c,d,e);    f+=t1;    b=t1+t2;	t1 = a + e1(f) + Ch(f,g,h) + 0x682e6ff3d6b2b8a3 + W[55];	t2 = e0(b) + Maj(b,c,d);    e+=t1;    a=t1+t2;	t1 = h + e1(e) + Ch(e,f,g) + 0x748f82ee5defb2fc + W[56];	t2 = e0(a) + Maj(a,b,c);    d+=t1;    h=t1+t2;	t1 = g + e1(d) + Ch(d,e,f) + 0x78a5636f43172f60 + W[57];	t2 = e0(h) + Maj(h,a,b);    c+=t1;    g=t1+t2;	t1 = f + e1(c) + Ch(c,d,e) + 0x84c87814a1f0ab72 + W[58];	t2 = e0(g) + Maj(g,h,a);    b+=t1;    f=t1+t2;	t1 = e + e1(b) + Ch(b,c,d) + 0x8cc702081a6439ec + W[59];	t2 = e0(f) + Maj(f,g,h);    a+=t1;    e=t1+t2;	t1 = d + e1(a) + Ch(a,b,c) + 0x90befffa23631e28 + W[60];	t2 = e0(e) + Maj(e,f,g);    h+=t1;    d=t1+t2;	t1 = c + e1(h) + Ch(h,a,b) + 0xa4506cebde82bde9 + W[61];	t2 = e0(d) + Maj(d,e,f);    g+=t1;    c=t1+t2;	t1 = b + e1(g) + Ch(g,h,a) + 0xbef9a3f7b2c67915 + W[62];	t2 = e0(c) + Maj(c,d,e);    f+=t1;    b=t1+t2;	t1 = a + e1(f) + Ch(f,g,h) + 0xc67178f2e372532b + W[63];	t2 = e0(b) + Maj(b,c,d);    e+=t1;    a=t1+t2;	t1 = h + e1(e) + Ch(e,f,g) + 0xca273eceea26619c + W[64];	t2 = e0(a) + Maj(a,b,c);    d+=t1;    h=t1+t2;	t1 = g + e1(d) + Ch(d,e,f) + 0xd186b8c721c0c207 + W[65];	t2 = e0(h) + Maj(h,a,b);    c+=t1;    g=t1+t2;	t1 = f + e1(c) + Ch(c,d,e) + 0xeada7dd6cde0eb1e + W[66];	t2 = e0(g) + Maj(g,h,a);    b+=t1;    f=t1+t2;	t1 = e + e1(b) + Ch(b,c,d) + 0xf57d4f7fee6ed178 + W[67];	t2 = e0(f) + Maj(f,g,h);    a+=t1;    e=t1+t2;	t1 = d + e1(a) + Ch(a,b,c) + 0x06f067aa72176fba + W[68];	t2 = e0(e) + Maj(e,f,g);    h+=t1;    d=t1+t2;	t1 = c + e1(h) + Ch(h,a,b) + 0x0a637dc5a2c898a6 + W[69];	t2 = e0(d) + Maj(d,e,f);    g+=t1;    c=t1+t2;	t1 = b + e1(g) + Ch(g,h,a) + 0x113f9804bef90dae + W[70];	t2 = e0(c) + Maj(c,d,e);    f+=t1;    b=t1+t2;	t1 = a + e1(f) + Ch(f,g,h) + 0x1b710b35131c471b + W[71];	t2 = e0(b) + Maj(b,c,d);    e+=t1;    a=t1+t2;	t1 = h + e1(e) + Ch(e,f,g) + 0x28db77f523047d84 + W[72];	t2 = e0(a) + Maj(a,b,c);    d+=t1;    h=t1+t2;	t1 = g + e1(d) + Ch(d,e,f) + 0x32caab7b40c72493 + W[73];	t2 = e0(h) + Maj(h,a,b);    c+=t1;    g=t1+t2;	t1 = f + e1(c) + Ch(c,d,e) + 0x3c9ebe0a15c9bebc + W[74];	t2 = e0(g) + Maj(g,h,a);    b+=t1;    f=t1+t2;	t1 = e + e1(b) + Ch(b,c,d) + 0x431d67c49c100d4c + W[75];	t2 = e0(f) + Maj(f,g,h);    a+=t1;    e=t1+t2;	t1 = d + e1(a) + Ch(a,b,c) + 0x4cc5d4becb3e42b6 + W[76];	t2 = e0(e) + Maj(e,f,g);    h+=t1;    d=t1+t2;	t1 = c + e1(h) + Ch(h,a,b) + 0x597f299cfc657e2a + W[77];	t2 = e0(d) + Maj(d,e,f);    g+=t1;    c=t1+t2;	t1 = b + e1(g) + Ch(g,h,a) + 0x5fcb6fab3ad6faec + W[78];	t2 = e0(c) + Maj(c,d,e);    f+=t1;    b=t1+t2;	t1 = a + e1(f) + Ch(f,g,h) + 0x6c44198c4a475817 + W[79];	t2 = e0(b) + Maj(b,c,d);    e+=t1;    a=t1+t2;#endif /* CONFIG_DIGEST_FAST */  	state[0] += a; state[1] += b; state[2] += c; state[3] += d;  	state[4] += e; state[5] += f; state[6] += g; state[7] += h;  	/* erase our data */	a = b = c = d = e = f = g = h = t1 = t2 = 0;	memset(W, 0, 80 * sizeof(u64));}static voidSHA512Init(struct SHA512_CTX *C){	C->state[0] = H0;	C->state[1] = H1;	C->state[2] = H2;	C->state[3] = H3;	C->state[4] = H4;	C->state[5] = H5;	C->state[6] = H6;	C->state[7] = H7;	C->count[0] = C->count[1] = C->count[2] = C->count[3] = 0;	memset(C->buf, 0, 128);}static voidSHA512Update(struct SHA512_CTX *C, const u8 *input, u32 inputLen){	u32 i, index, partLen;	/* Compute number of bytes mod 128 */	index = (u32)((C->count[0] >> 3) & 0x7F);		/* Update number of bits */	if ((C->count[0] += (inputLen << 3)) < (inputLen << 3)) {		if ((C->count[1] += 1) < 1)			if ((C->count[2] += 1) < 1)				C->count[3]++;		C->count[1] += (inputLen >> 29);	}		partLen = 128 - index;		/* Transform as many times as possible. */	if (inputLen >= partLen) {		memcpy(&C->buf[index], input, partLen);		SHA512Transform(C->state, C->buf);		for (i=partLen; i+127<inputLen; i+=128)			SHA512Transform(C->state, &input[i]);		index = 0;	} else {		i = 0;	}	/* Buffer remaining input */	memcpy(&C->buf[index], &input[i], inputLen-i);}static voidSHA512Final(struct SHA512_CTX *C, u8 *digest){	const static u8 padding[128] = { 0x80, };	u8 bits[128] = { 0x00, };	u32 t, index, padLen;	u64 t2;	int i,j;	/* Save number of bits */	t = C->count[0];	bits[15] = t; t>>=8;	bits[14] = t; t>>=8;	bits[13] = t; t>>=8;	bits[12] = t; 	t = C->count[1];	bits[11] = t; t>>=8;	bits[10] = t; t>>=8;	bits[9 ] = t; t>>=8;	bits[8 ] = t; 	t = C->count[2];	bits[7 ] = t; t>>=8;	bits[6 ] = t; t>>=8;	bits[5 ] = t; t>>=8;	bits[4 ] = t; 	t = C->count[3];	bits[3 ] = t; t>>=8;	bits[2 ] = t; t>>=8;	bits[1 ] = t; t>>=8;	bits[0 ] = t; 	/* Pad out to 112 mod 128. */	index = (C->count[0] >> 3) & 0x7f;	padLen = (index < 112) ? (112 - index) : ((128+112) - index);	SHA512Update(C, padding, padLen);	/* Append length (before padding) */	SHA512Update(C, bits, 16);	/* Store state in digest */	for (i = j = 0; i < 8; i++, j += 8) {		t2 = C->state[i];		digest[j+7] = (char)t2 & 0xff; t2>>=8;		digest[j+6] = (char)t2 & 0xff; t2>>=8;		digest[j+5] = (char)t2 & 0xff; t2>>=8;		digest[j+4] = (char)t2 & 0xff; t2>>=8;		digest[j+3] = (char)t2 & 0xff; t2>>=8;		digest[j+2] = (char)t2 & 0xff; t2>>=8;		digest[j+1] = (char)t2 & 0xff; t2>>=8;		digest[j  ] = (char)t2 & 0xff;	}		/* Zeroize sensitive information. */	memset(C, 0, sizeof(struct SHA512_CTX));}static intsha512_open(struct digest_context *cx, int atomic){	if (!cx || !cx->digest_info)		return -EINVAL;	SHA512Init((struct SHA512_CTX *) cx->digest_info);	return 0;}static intsha512_update(struct digest_context *cx, const u8 *in, int size, int atomic){	if (!cx || !in || !cx->digest_info)		return -EINVAL;	SHA512Update((struct SHA512_CTX *) cx->digest_info, in, size);	return 0;}static intsha512_digest(struct digest_context *cx, u8 *out, int atomic){	struct SHA512_CTX tmp;	if (!cx || !out || !cx->digest_info)		return -EINVAL;	memcpy(&tmp, (struct SHA512_CTX *)cx->digest_info,	       sizeof (struct SHA512_CTX));	SHA512Final(&tmp, out);	return 0;}static intsha512_close(struct digest_context *cx, u8 *out, int atomic){	static u8 tmp[64];	if (!cx || !cx->digest_info)		return -EINVAL;		if (out == 0)		out = tmp;	SHA512Final((struct SHA512_CTX *)cx->digest_info, out);	return 0;}#define DIGEST_ID		sha512#define DIGEST_SIZE		sizeof (struct SHA512_CTX)#define DIGEST_BLOCKSIZE	64#include "gen-hash.h"EXPORT_NO_SYMBOLS;

⌨️ 快捷键说明

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