javascript实现sha512和sha384算法(支持微信小程序),可分多次计算

news2024/11/24 19:42:27

概述:

`
本人前端需要实现sha512和sha384计算的功能,最好是能做到分多次计算。
本文所写的代码在现有sha512和sha384的C++代码,反复测试对比计算过程参数,成功改造成sha512和sha384的javascript代码,并成功验证好分多次计算sha512和sha384数据
因sha512和sha384,大部分计算过程一样,所以代码放在一起,一并测试。

测试平台:

已经在如下环境中测试通过,其他平台(浏览器)应该也不会有问题:
1、nodejs中node.exe运行
本js脚本按照版本ES5编写代码,当然微信小程序也能用。

技术难点:

在源代码c++中,本算法用到了大量的unsigned long long类型,而javascript版本ES5整型最大范围比c/c++语言中unsigned long long小,ES2000可以做到但是现在支持的不多,特别是微信小程序不支持。
故本次难点在于unsigned long long数据类型转换,本人特地写了基于javascript版本ES5的unsigned long long操作,实现载入、加减乘除,比较、移位运算,满足了本次需要。

功能代码:

function strULonglongCtxParams() {
	this.uhigh;
	this.ulow;
};

function strSha512sha384CtxParams() {
	this.sz;
	this.counter;
	this.save;
};

function ulonglong_init(uHigh, uLow, isGreater0) {
	var ulonglongCtxParams = new strULonglongCtxParams();
	
	ulonglongCtxParams.uhigh = uHigh & 0xffffffff;
	ulonglongCtxParams.ulow = uLow & 0xffffffff;
	
	return ulonglongCtxParams;
}

function ulonglong_set_hexstr(ulonglongCtxParams, hexStr) {
	var i = 0;
	var j = 0;
	var tmpInt = 0;
	
	ulonglongCtxParams.uhigh = 0;
	ulonglongCtxParams.ulow = 0;
	
	for (i = hexStr.length - 1; i >= 0; i--) {
		tmpInt = hexStr.charCodeAt(i);
		//console.log("tmpInt = %d", tmpInt);
		if (tmpInt >= 48 && tmpInt < 48 + 10) {
			tmpInt -= 48;
		} else if (tmpInt >= 65 && tmpInt < 65 + 6) {
			tmpInt = tmpInt - 65 + 10;
		} else if (tmpInt >= 97 && tmpInt < 97 + 6) {
			tmpInt = tmpInt - 97 + 10;
		} else {
			continue;
		}
		if (j < 8) {
			ulonglongCtxParams.ulow |= (tmpInt << (j * 4));
		} else {
			ulonglongCtxParams.uhigh |= (tmpInt << ((j - 8) * 4));
		}
		j++;
		if (j >= 16) {
			break;
		}
	}
}

function ulonglong_add_equal(ulonglongCtxParamsRe, ulonglongCtxParamsAdd) {
	var tmpLonglongCtxParamsRe = new strULonglongCtxParams();
	
	tmpLonglongCtxParamsRe.uhigh = ulonglongCtxParamsRe.uhigh;
	tmpLonglongCtxParamsRe.ulow = ulonglongCtxParamsRe.ulow;
	
	ulonglong_add(ulonglongCtxParamsRe, tmpLonglongCtxParamsRe, ulonglongCtxParamsAdd);
} 

function ulonglong_u32_add_equal(ulonglongCtxParamsRe, u32Add) {
	var tmpLonglongCtxParamsRe = new strULonglongCtxParams();
	var ulonglongCtxParamsAdd = new strULonglongCtxParams();
	
	tmpLonglongCtxParamsRe.uhigh = ulonglongCtxParamsRe.uhigh;
	tmpLonglongCtxParamsRe.ulow = ulonglongCtxParamsRe.ulow;
	
	ulonglongCtxParamsAdd.uhigh = 0;
	ulonglongCtxParamsAdd.ulow = u32Add;
	
	ulonglong_add(ulonglongCtxParamsRe, tmpLonglongCtxParamsRe, ulonglongCtxParamsAdd);
} 

function ulonglong_add(ulonglongCtxParamsRe, ulonglongCtxParamsAdd1, ulonglongCtxParamsAdd2) {
	var i = 0;
	var ele = 0;
	var carry = 0;
	
	ulonglongCtxParamsRe.ulow = 0;
	for (i = 0; i < 4; i++) {
		ele = ((ulonglongCtxParamsAdd1.ulow >>> (8 * i)) & 0xff) + ((ulonglongCtxParamsAdd2.ulow >>> (8 * i)) & 0xff) + carry;
		if (ele > 255) {
			carry = ele >>> 8;
			ele = ele & 0xff;
		} else {
			carry = 0;
		}
		ulonglongCtxParamsRe.ulow |= (ele << (8 * i));
	}
	
	ulonglongCtxParamsRe.uhigh = 0;
	for (i = 0; i < 4; i++) {
		ele = ((ulonglongCtxParamsAdd1.uhigh >>> (8 * i)) & 0xff) + ((ulonglongCtxParamsAdd2.uhigh >>> (8 * i)) & 0xff) + carry;
		if (ele > 255) {
			carry = ele >> 8;
			ele = ele & 0xff;
		} else {
			carry = 0;
		}
		ulonglongCtxParamsRe.uhigh |= (ele << (8 * i));
	}
}

function ulonglong_minus(ulonglongCtxParamsRe, minuend, subtractor) {
	var i = 0;
	var ele = 0;
	var carry = 0;
	
	ulonglongCtxParamsRe.ulow = 0;
	for (i = 0; i < 4; i++) {
		ele = ((minuend.ulow >>> (8 * i)) & 0xff) - ((subtractor.ulow >>> (8 * i)) & 0xff) - carry;
		if (ele < 0) {
			ele = ele + 256;
			carry = 1;
		} else {
			carry = 0;
		}
		ulonglongCtxParamsRe.ulow |= (ele << (8 * i));
	}
	
	ulonglongCtxParamsRe.uhigh = 0;
	for (i = 0; i < 4; i++) {
		ele = ((minuend.uhigh >>> (8 * i)) & 0xff) - ((subtractor.uhigh >>> (8 * i)) & 0xff) - carry;
		if (ele < 0) {
			ele = ele + 256;
			carry = 1;
		} else {
			carry = 0;
		}
		ulonglongCtxParamsRe.uhigh |= (ele << (8 * i));
	}
	
	if (carry != 0) {
		return false;
	} else {
		return true;
	}
}

function ulonglong_u32add(ulonglongCtxParamsRe, isLow, add1, add2) {
	var i = 0;
	var ele = 0;
	var result = 0;
	var carry = 0;
	
	for (i = 0; i < 4; i++) {
		ele = ((add1 >> (8 * i)) & 0xff) + ((add2 >> (8 * i)) & 0xff) + carry;
		if (ele > 255) {
			carry = ele >> 8;
			ele = ele & 0xff;
		} else {
			carry = 0;
		}
		result |= (ele << (8 * i));
	}
	
	if (isLow) {
		ulonglongCtxParamsRe.ulow = result;
	} else {
		ulonglongCtxParamsRe.uhigh = result;
	}
	
	return carry;
}

function ulonglong_times(ulonglongCtxParamsRe, times1, times2) {
	var i = 0;
	var j = 0;
	var ele = 0;
	var carry = 0;
	
	ulonglongCtxParamsRe.ulow = 0;
	ulonglongCtxParamsRe.uhigh = 0;
	
	carry = 0;
	for (i = 0; i < 4; i++) {		
		carry = 0;
		for (j = 0; j < 4; j++) {			
			ele = ((times1.ulow >>> (8 * j)) & 0xff) * ((times2.ulow >>> (8 * i)) & 0xff) + carry;
			if (ele > 255) {
				carry = ele >> 8;
				ele = ele & 0xff;
			} else {
				carry = 0;
			}
			if (i + j < 4) {
				ulonglongCtxParamsRe.uhigh += ulonglong_u32add(ulonglongCtxParamsRe, true, ulonglongCtxParamsRe.ulow, ele << (8 * (i + j)));
			} else {
				ulonglong_u32add(ulonglongCtxParamsRe, false, ulonglongCtxParamsRe.uhigh, ele << (8 * (i + j - 4)));
			}
		}
		for (j = 0; j < 4; j++) {
			ele = ((times1.uhigh >>> (8 * j)) & 0xff) * ((times2.ulow >>> (8 * i)) & 0xff) + carry;
			if (ele > 255) {
				carry = ele >> 8;
				ele = ele & 0xff;
			} else {
				carry = 0;
			}
			if (i + j < 4) {
				ulonglong_u32add(ulonglongCtxParamsRe, false, ulonglongCtxParamsRe.uhigh, ele << (8 * (i + j)));
			} else {
				//溢出
			}
		}
	}

	for (i = 0; i < 4; i++) {
		carry = 0;
		for (j = 0; j < 4; j++) {
			ele = ((times1.ulow >>> (8 * j)) & 0xff) * ((times2.uhigh >>> (8 * i)) & 0xff) + carry;
			if (ele > 255) {
				carry = ele >> 8;
				ele = ele & 0xff;
			} else {
				carry = 0;
			}
			if (i + j < 4) {
				ulonglongCtxParamsRe.uhigh += (ele << (8 * (i + j)));
			} else {
				//溢出
			}
		}
		for (j = 0; j < 4; j++) {
			ele = ((times1.uhigh >>> (8 * j)) & 0xff) * ((times2.uhigh >>> (8 * i)) & 0xff) + carry;
			if (ele > 255) {
				carry = ele >> 8;
				ele = ele & 0xff;
			} else {
				carry = 0;
			}
			if (i + j < 4) {
				//溢出
			} else {
				//溢出
			}
		}
	}
}


function ulonglong_divide(ulonglongCtxParamsQuotients, ulonglongCtxParamsRemainders, dividend, divider) {
	var i = 0;
	var startIndex = -1;

	ulonglongCtxParamsQuotients.uhigh = 0;
	ulonglongCtxParamsQuotients.ulow = 0;	

	ulonglongCtxParamsRemainders.uhigh = 0;
	ulonglongCtxParamsRemainders.ulow = 0;

	for(startIndex = 0; ; startIndex++) {
		if (ulonglong_u32_compare(ulonglongCtxParamsRemainders, divider) >= 0) {
			if (64 - startIndex > 32) {
				ulonglongCtxParamsQuotients.uhigh |= (0x00000001 << (32 - startIndex));				
			} else {
				ulonglongCtxParamsQuotients.ulow |= (0x00000001 << (64 - startIndex));
			}
			//减法
			if (ulonglong_u64_compare(ulonglongCtxParamsRemainders.ulow, divider.ulow) > 0) {
				ulonglongCtxParamsRemainders.ulow = ulonglongCtxParamsRemainders.ulow - divider.ulow;
			} else {
				ulonglongCtxParamsRemainders.ulow = ~(divider.ulow - ulonglongCtxParamsRemainders.ulow);
				ulonglongCtxParamsRemainders.uhigh--;
			}
			ulonglongCtxParamsRemainders.uhigh = ulonglongCtxParamsRemainders.uhigh - divider.uhigh;
		}
		if (startIndex >= 64) {
			break;
		}
		ulonglongCtxParamsRemainders.uhigh = ulonglongCtxParamsRemainders.uhigh << 1;
		if ((ulonglongCtxParamsRemainders.ulow & 0x80000000) != 0) {
			ulonglongCtxParamsRemainders.uhigh |= 0x00000001;
		}
		ulonglongCtxParamsRemainders.ulow = ulonglongCtxParamsRemainders.ulow << 1;
		if (startIndex < 32) {
			if (dividend.uhigh & (0x80000000 >>> startIndex)) {
				ulonglongCtxParamsRemainders.ulow |= 0x00000001;
			}
		} else {
			if (dividend.ulow & (0x80000000 >>> (startIndex - 32))) {
				ulonglongCtxParamsRemainders.ulow |= 0x00000001;
			}
		}
	}
}


function ulonglong_u32_compare(uint1, uint2) {
	uint1 &= 0xffffffff;
	uint2 &= 0xffffffff;
	
	if ((uint1 & 0x80000000) == 0 && (uint2 & 0x80000000) == 0) {
		return uint1 > uint2 ? 1 : (uint1 == uint2 ? 0 : (-1));
	}
	if ((uint1 & 0x80000000) != 0 && (uint2 & 0x80000000) != 0) {
		uint1 &= 0x7fffffff;
		uint2 &= 0x7fffffff;
		return uint1 > uint2 ? 1 : (uint1 == uint2 ? 0 : (-1));
	}
	if ((uint1 & 0x80000000) != 0) {
		return 1;
	} else {
		return -1;
	}
}

function ulonglong_u64_compare(uint1, uint2) {
	var re = ulonglong_u32_compare(uint1.uhigh, uint2.uhigh);
	if (re > 0) {
		return 1;
	}
	if (re == 0) {
		return ulonglong_u32_compare(uint1.ulow, uint2.ulow);
	} else {
		return -1;
	}
}

function ulonglong_umove(ulonglongCtxParamsRemainders, bits/* > 0 left greater, < 0 right lesser*/) {
	if (bits == 0) {
		return;
	}
	if (bits > 0) {
		if (bits >= 64) {
			ulonglongCtxParamsRemainders.uhigh = 0;
			ulonglongCtxParamsRemainders.ulow = 0;
			return ;
		}
		if (bits >= 32) {
			ulonglongCtxParamsRemainders.uhigh = (ulonglongCtxParamsRemainders.ulow << (bits - 32)) & 0xffffffff;
			ulonglongCtxParamsRemainders.ulow = 0;
			return;
		}
		ulonglongCtxParamsRemainders.uhigh = ((ulonglongCtxParamsRemainders.uhigh << bits) & 0xffffffff) | ((ulonglongCtxParamsRemainders.ulow >>> (32 - bits)) & 0xffffffff);
		ulonglongCtxParamsRemainders.ulow = (ulonglongCtxParamsRemainders.ulow << bits) & 0xffffffff;
		return;
	}
	if (bits < 0) {
		bits = (-bits);
		if (bits >= 64) {
			ulonglongCtxParamsRemainders.uhigh = 0;
			ulonglongCtxParamsRemainders.ulow = 0;
			return ;
		}
		if (bits >= 32) {
			ulonglongCtxParamsRemainders.ulow = ((ulonglongCtxParamsRemainders.uhigh & 0xffffffff) >>> (bits - 32)) & 0xffffffff;
			ulonglongCtxParamsRemainders.uhigh = 0;
			return;
		}
		ulonglongCtxParamsRemainders.ulow = ((ulonglongCtxParamsRemainders.ulow >>> bits) & 0xffffffff) | ((ulonglongCtxParamsRemainders.uhigh << (32 - bits)) & 0xffffffff);
		ulonglongCtxParamsRemainders.uhigh = (ulonglongCtxParamsRemainders.uhigh >>> bits) & 0xffffffff;
	}
}

var constant_512 = [
	"0x428a2f98d728ae22ULL", "0x7137449123ef65cdULL",
	"0xb5c0fbcfec4d3b2fULL", "0xe9b5dba58189dbbcULL",
	"0x3956c25bf348b538ULL", "0x59f111f1b605d019ULL",
	"0x923f82a4af194f9bULL", "0xab1c5ed5da6d8118ULL",
	"0xd807aa98a3030242ULL", "0x12835b0145706fbeULL",
	"0x243185be4ee4b28cULL", "0x550c7dc3d5ffb4e2ULL",
	"0x72be5d74f27b896fULL", "0x80deb1fe3b1696b1ULL",
	"0x9bdc06a725c71235ULL", "0xc19bf174cf692694ULL",
	"0xe49b69c19ef14ad2ULL", "0xefbe4786384f25e3ULL",
	"0x0fc19dc68b8cd5b5ULL", "0x240ca1cc77ac9c65ULL",
	"0x2de92c6f592b0275ULL", "0x4a7484aa6ea6e483ULL",
	"0x5cb0a9dcbd41fbd4ULL", "0x76f988da831153b5ULL",
	"0x983e5152ee66dfabULL", "0xa831c66d2db43210ULL",
	"0xb00327c898fb213fULL", "0xbf597fc7beef0ee4ULL",
	"0xc6e00bf33da88fc2ULL", "0xd5a79147930aa725ULL",
	"0x06ca6351e003826fULL", "0x142929670a0e6e70ULL",
	"0x27b70a8546d22ffcULL", "0x2e1b21385c26c926ULL",
	"0x4d2c6dfc5ac42aedULL", "0x53380d139d95b3dfULL",
	"0x650a73548baf63deULL", "0x766a0abb3c77b2a8ULL",
	"0x81c2c92e47edaee6ULL", "0x92722c851482353bULL",
	"0xa2bfe8a14cf10364ULL", "0xa81a664bbc423001ULL",
	"0xc24b8b70d0f89791ULL", "0xc76c51a30654be30ULL",
	"0xd192e819d6ef5218ULL", "0xd69906245565a910ULL",
	"0xf40e35855771202aULL", "0x106aa07032bbd1b8ULL",
	"0x19a4c116b8d2d0c8ULL", "0x1e376c085141ab53ULL",
	"0x2748774cdf8eeb99ULL", "0x34b0bcb5e19b48a8ULL",
	"0x391c0cb3c5c95a63ULL", "0x4ed8aa4ae3418acbULL",
	"0x5b9cca4f7763e373ULL", "0x682e6ff3d6b2b8a3ULL",
	"0x748f82ee5defb2fcULL", "0x78a5636f43172f60ULL",
	"0x84c87814a1f0ab72ULL", "0x8cc702081a6439ecULL",
	"0x90befffa23631e28ULL", "0xa4506cebde82bde9ULL",
	"0xbef9a3f7b2c67915ULL", "0xc67178f2e372532bULL",
	"0xca273eceea26619cULL", "0xd186b8c721c0c207ULL",
	"0xeada7dd6cde0eb1eULL", "0xf57d4f7fee6ed178ULL",
	"0x06f067aa72176fbaULL", "0x0a637dc5a2c898a6ULL",
	"0x113f9804bef90daeULL", "0x1b710b35131c471bULL",
	"0x28db77f523047d84ULL", "0x32caab7b40c72493ULL",
	"0x3c9ebe0a15c9bebcULL", "0x431d67c49c100d4cULL",
	"0x4cc5d4becb3e42b6ULL", "0x597f299cfc657e2aULL",
	"0x5fcb6fab3ad6faecULL", "0x6c44198c4a475817ULL"
];

function sha512_init() {
	return sha512_sha384_init(false);
}

function sha384_init() {
	return sha512_sha384_init(true);
}

function sha512_sha384_init(isSha384) {
	var sha512sha384CtxParams = new strSha512sha384CtxParams();
	var i = 0;

	sha512sha384CtxParams.sz = new Array(2);
	sha512sha384CtxParams.counter = new Array(8);
	sha512sha384CtxParams.save = new Uint8Array(128);
	
	for (i = 0; i < sha512sha384CtxParams.sz.length; i++) {
		sha512sha384CtxParams.sz[i] = new strULonglongCtxParams();
	}
	for (i = 0; i < sha512sha384CtxParams.counter.length; i++) {
		sha512sha384CtxParams.counter[i] = new strULonglongCtxParams();
	}
	
	sha512sha384CtxParams.sz[0].uhigh = 0;
	sha512sha384CtxParams.sz[0].ulow = 0;
	sha512sha384CtxParams.sz[1].uhigh = 0;
	sha512sha384CtxParams.sz[1].ulow = 0;
	
	if (isSha384 == false) {
		ulonglong_set_hexstr(sha512sha384CtxParams.counter[0], "0x6a09e667f3bcc908ULL");
		ulonglong_set_hexstr(sha512sha384CtxParams.counter[1], "0xbb67ae8584caa73bULL");
		ulonglong_set_hexstr(sha512sha384CtxParams.counter[2], "0x3c6ef372fe94f82bULL");
		ulonglong_set_hexstr(sha512sha384CtxParams.counter[3], "0xa54ff53a5f1d36f1ULL");
		ulonglong_set_hexstr(sha512sha384CtxParams.counter[4], "0x510e527fade682d1ULL");
		ulonglong_set_hexstr(sha512sha384CtxParams.counter[5], "0x9b05688c2b3e6c1fULL");
		ulonglong_set_hexstr(sha512sha384CtxParams.counter[6], "0x1f83d9abfb41bd6bULL");
		ulonglong_set_hexstr(sha512sha384CtxParams.counter[7], "0x5be0cd19137e2179ULL");
	} else {
		ulonglong_set_hexstr(sha512sha384CtxParams.counter[0], "0xCBBB9D5DC1059ED8ULL");
		ulonglong_set_hexstr(sha512sha384CtxParams.counter[1], "0x629A292A367CD507ULL");
		ulonglong_set_hexstr(sha512sha384CtxParams.counter[2], "0x9159015A3070DD17ULL");
		ulonglong_set_hexstr(sha512sha384CtxParams.counter[3], "0x152FECD8F70E5939ULL");
		ulonglong_set_hexstr(sha512sha384CtxParams.counter[4], "0x67332667FFC00B31ULL");
		ulonglong_set_hexstr(sha512sha384CtxParams.counter[5], "0x8EB44A8768581511ULL");
		ulonglong_set_hexstr(sha512sha384CtxParams.counter[6], "0xDB0C2E0D64F98FA7ULL");
		ulonglong_set_hexstr(sha512sha384CtxParams.counter[7], "0x47B5481DBEFA4FA4ULL");
	}

	return sha512sha384CtxParams;
}

function sha512_sha384_update(sha512sha384CtxParams, databytes, byteslen) {
	var len = byteslen;
	var offset = 0;
	var old_sz = new strULonglongCtxParams();
	var l = 0;
	var indataindex = 0;
	var i = 0, j = 0;
	var current = new Array(16);
	
	for (i = 0; i < current.length; i++) {
		current[i] = new strULonglongCtxParams();
	}
	
	old_sz.uhigh = sha512sha384CtxParams.sz[0].uhigh;
	old_sz.ulow = sha512sha384CtxParams.sz[0].ulow;
	
	ulonglong_u32_add_equal(sha512sha384CtxParams.sz[0], len * 8);
	if (ulonglong_u64_compare(sha512sha384CtxParams.sz[0], old_sz) < 0) {
		ulonglong_u32_add_equal(sha512sha384CtxParams.sz[1], 1);
	}
	//offset = (old_sz / 8) % 128;
	ulonglong_umove(old_sz, -3);
	offset = old_sz.ulow & 127;
	
	//console.log("offset = %d", offset);
	
	indataindex = 0;
	while(len > 0){
		l = len < (128 - offset) ? len : (128 - offset);
		for (j = 0; j < l; j++) {
			sha512sha384CtxParams.save[offset + j] = databytes[indataindex + j];
		}
		offset += l;
		indataindex += l;
		len -= l;
		if(offset == 128) {
			for(i = 0; i < 8; i++){
				//current[2 * i + 0] = SwapUint64(*((unsigned long long*)(m_Save + i * 16)));
				//current[2 * i + 1] = SwapUint64(*((unsigned long long*)(m_Save + i * 16 + 8)));
				SwapUint64(current[2 * i + 0], sha512sha384CtxParams.save, i * 16);
				SwapUint64(current[2 * i + 1], sha512sha384CtxParams.save, i * 16 + 8);
			}
			Calc(sha512sha384CtxParams, current);
			offset = 0;
		}
	}
}

function sha512_final(sha512sha384CtxParams) {
	return sha512_sha384_final(sha512sha384CtxParams, false);
}

function sha384_final(sha512sha384CtxParams) {
	return sha512_sha384_final(sha512sha384CtxParams, true);
}

function sha512_sha384_final(sha512sha384CtxParams, isSha384) {
	/*unsigned char zeros[128 + 16];
    unsigned offset = (m_Sz[0] / 8) % 128;
    unsigned int dstart = (240 - offset - 1) % 128 + 1;
	int i = 0;
	unsigned char *r = NULL;*/
	var zeros = new Uint8Array(128 + 16);
	var offset = 0;
	var dstart = 0;
	var i = 0;
	var j = 0;
	var tmpLL = new strULonglongCtxParams();
	var result = null;
	
	if (isSha384) {
		result = new Uint8Array(48);
	} else {
		result = new Uint8Array(64);
	}
	
	tmpLL.uhigh = sha512sha384CtxParams.sz[0].uhigh;
	tmpLL.ulow = sha512sha384CtxParams.sz[0].ulow;
	
	ulonglong_umove(tmpLL, -3);
	offset = tmpLL.ulow & 127;
	
	dstart = (240 - offset - 1) % 128 + 1;
	
	for (i = 0; i < zeros.length; i++) {
		zeros[i] = 0;
	}
    //*zeros = 0x80;
	zeros[0] = 0x80;
    //memset (zeros + 1, 0, sizeof(zeros) - 1);
    /*zeros[dstart+15] = (m_Sz[0] >> 0) & 0xff;
    zeros[dstart+14] = (m_Sz[0] >> 8) & 0xff;
    zeros[dstart+13] = (m_Sz[0] >> 16) & 0xff;
    zeros[dstart+12] = (m_Sz[0] >> 24) & 0xff;
    zeros[dstart+11] = (m_Sz[0] >> 32) & 0xff;
    zeros[dstart+10] = (m_Sz[0] >> 40) & 0xff;
    zeros[dstart+9]  = (m_Sz[0] >> 48) & 0xff;
    zeros[dstart+8]  = (m_Sz[0] >> 56) & 0xff;*/
	for (i = 15; i >= 8; i--) {
		if (15 - i < 4) {
			zeros[dstart+i] = (sha512sha384CtxParams.sz[0].ulow >>> (8 * (15 - i))) & 0xff;
		} else {
			zeros[dstart+i] = (sha512sha384CtxParams.sz[0].uhigh >>> (8 * (11 - i))) & 0xff;
		}
	}
	
	/*
    zeros[dstart+7] = (m_Sz[1] >> 0) & 0xff;
    zeros[dstart+6] = (m_Sz[1] >> 8) & 0xff;
    zeros[dstart+5] = (m_Sz[1] >> 16) & 0xff;
    zeros[dstart+4] = (m_Sz[1] >> 24) & 0xff;
    zeros[dstart+3] = (m_Sz[1] >> 32) & 0xff;
    zeros[dstart+2] = (m_Sz[1] >> 40) & 0xff;
    zeros[dstart+1] = (m_Sz[1] >> 48) & 0xff;
    zeros[dstart+0] = (m_Sz[1] >> 56) & 0xff;*/
	for (i = 7; i >= 0; i--) {
		if (7 - i < 4) {
			zeros[dstart+i] = (sha512sha384CtxParams.sz[1].ulow >>> (8 * (7 - i))) & 0xff;
		} else {
			zeros[dstart+i] = (sha512sha384CtxParams.sz[1].uhigh >>> (8 * (3 - i))) & 0xff;
		}
	}
	
    //Update (zeros, dstart + 16);
	sha512_sha384_update(sha512sha384CtxParams, zeros, dstart + 16);

	//r = (unsigned char*)result;

	for (i = 0; i < 8; ++i) {
		if (isSha384 && i >= 6) {
			break;
		}
	    /*r[8*i+7] = m_Counter[i] & 0xFF;
	    r[8*i+6] = (m_Counter[i] >> 8) & 0xFF;
	    r[8*i+5] = (m_Counter[i] >> 16) & 0xFF;
	    r[8*i+4] = (m_Counter[i] >> 24) & 0xFF;
	    r[8*i+3] = (m_Counter[i] >> 32) & 0XFF;
	    r[8*i+2] = (m_Counter[i] >> 40) & 0xFF;
	    r[8*i+1] = (m_Counter[i] >> 48) & 0xFF;
	    r[8*i]   = (m_Counter[i] >> 56) & 0xFF;
		*/
		for (j = 7; j >= 0; j--) {
			if (7 - j < 4) {
				result[8 * i + j] = (sha512sha384CtxParams.counter[i].ulow >>> (8 * (7 - j))) & 0xff;
			} else {
				result[8 * i + j] = (sha512sha384CtxParams.counter[i].uhigh >>> (8 * (3 - j))) & 0xff;
			}
		}
	} 

	return result;	
}

function ROTR(longlongCtxParams, n) {
	//return (((x)>>>(n)) | ((x) << (64 - (n))));
	var tmpLonglong1 = new strULonglongCtxParams();
	var tmpLonglong2 = new strULonglongCtxParams();
	
	tmpLonglong1.uhigh = longlongCtxParams.uhigh;
	tmpLonglong1.ulow = longlongCtxParams.ulow;
	
	tmpLonglong2.uhigh = longlongCtxParams.uhigh;
	tmpLonglong2.ulow = longlongCtxParams.ulow;
	
	ulonglong_umove(tmpLonglong1, -n);
	ulonglong_umove(tmpLonglong2, 64-n);
	
	tmpLonglong1.uhigh |= tmpLonglong2.uhigh;
	tmpLonglong1.ulow |= tmpLonglong2.ulow;
	
	return tmpLonglong1;
}

function Sigma0Lower(longlongCtxParams) {
	//return (ROTR(x,1)  ^ ROTR(x,8)  ^ ((x)>>>7));	
	var tmpLonglong1 = ROTR(longlongCtxParams, 1);
	var tmpLonglong2 = ROTR(longlongCtxParams, 8);
	var tmpLonglong3 = new strULonglongCtxParams();
	
	tmpLonglong3.uhigh = longlongCtxParams.uhigh;
	tmpLonglong3.ulow = longlongCtxParams.ulow;
	ulonglong_umove(tmpLonglong3, -7);
	
	tmpLonglong1.uhigh = tmpLonglong1.uhigh ^ tmpLonglong2.uhigh ^ tmpLonglong3.uhigh;
	tmpLonglong1.ulow = tmpLonglong1.ulow ^ tmpLonglong2.ulow ^ tmpLonglong3.ulow;
	
	return tmpLonglong1;
}

function Sigma1Lower(longlongCtxParams) {
	//#define sigma1(x) (ROTR(x,19) ^ ROTR(x,61) ^ ((x)>>6))
	//var tmpLonglong1 = ROTR(longlongCtxParams, 19);
	var tmpLonglong2 = ROTR(longlongCtxParams, 61);
	var tmpLonglong1 = ROTR(longlongCtxParams, 19);
	var tmpLonglong3 = new strULonglongCtxParams();

	
	tmpLonglong3.uhigh = longlongCtxParams.uhigh;
	tmpLonglong3.ulow = longlongCtxParams.ulow;
	ulonglong_umove(tmpLonglong3, -6);
	
	tmpLonglong1.uhigh = tmpLonglong1.uhigh ^ tmpLonglong2.uhigh ^ tmpLonglong3.uhigh;
	tmpLonglong1.ulow = tmpLonglong1.ulow ^ tmpLonglong2.ulow ^ tmpLonglong3.ulow;
	
	return tmpLonglong1;
}

function Sigma0Upper(longlongCtxParams) {
	//#define Sigma0(x)	(ROTR(x,28) ^ ROTR(x,34) ^ ROTR(x,39))
	var tmpLonglong1 = ROTR(longlongCtxParams, 28);
	var tmpLonglong2 = ROTR(longlongCtxParams, 34);
	var tmpLonglong3 = ROTR(longlongCtxParams, 39);

	
	tmpLonglong1.uhigh = tmpLonglong1.uhigh ^ tmpLonglong2.uhigh ^ tmpLonglong3.uhigh;
	tmpLonglong1.ulow = tmpLonglong1.ulow ^ tmpLonglong2.ulow ^ tmpLonglong3.ulow;
	
	return tmpLonglong1;
}

function Sigma1Upper(longlongCtxParams) {
	//#define Sigma1(x)	(ROTR(x,14) ^ ROTR(x,18) ^ ROTR(x,41))
	var tmpLonglong1 = ROTR(longlongCtxParams, 14);
	var tmpLonglong2 = ROTR(longlongCtxParams, 18);
	var tmpLonglong3 = ROTR(longlongCtxParams, 41);
	
	tmpLonglong1.uhigh = tmpLonglong1.uhigh ^ tmpLonglong2.uhigh ^ tmpLonglong3.uhigh;
	tmpLonglong1.ulow = tmpLonglong1.ulow ^ tmpLonglong2.ulow ^ tmpLonglong3.ulow;
	
	return tmpLonglong1;
}


function Ch(x, y, z) {
	//#define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z)))
	var tmpLonglong1 = new strULonglongCtxParams();
	
	tmpLonglong1.uhigh = (((x.uhigh) & (y.uhigh)) ^ ((~(x.uhigh)) & (z.uhigh))) & 0xffffffff;
	tmpLonglong1.ulow = (((x.ulow) & (y.ulow)) ^ ((~(x.ulow)) & (z.ulow))) & 0xffffffff;
	
	return tmpLonglong1;
}

function Maj(x, y, z) {
	//#define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
	var tmpLonglong1 = new strULonglongCtxParams();
	
	tmpLonglong1.uhigh = (((x.uhigh) & (y.uhigh)) ^ ((x.uhigh) & (z.uhigh)) ^ ((y.uhigh) & (z.uhigh))) & 0xffffffff;
	tmpLonglong1.ulow = (((x.ulow) & (y.ulow)) ^ ((x.ulow) & (z.ulow)) ^ ((y.ulow) & (z.ulow))) & 0xffffffff;
	
	return tmpLonglong1;
}

function Calc(sha512sha384CtxParams, indata)
{
	//unsigned long long AA, BB, CC, DD, EE, FF, GG, HH;
	//unsigned long long data[80];
	//int i;
	var AA = new strULonglongCtxParams();
	var BB = new strULonglongCtxParams();
	var CC = new strULonglongCtxParams();
	var DD = new strULonglongCtxParams();
	var EE = new strULonglongCtxParams();
	var FF = new strULonglongCtxParams();
	var GG = new strULonglongCtxParams();
	var HH = new strULonglongCtxParams();
	var data = new Array(80);
	var i = 0;
	var T1 = new strULonglongCtxParams();
	var T2 = new strULonglongCtxParams();
	var tmpLonglong1 = new strULonglongCtxParams();
	var tmpLonglong2 = new strULonglongCtxParams();
	var tmpLonglong3 = new strULonglongCtxParams();	
	
	for (i = 0; i < data.length; i++) {
		data[i] = new strULonglongCtxParams();
	}

	/*
	AA = m_Counter[0];
	BB = m_Counter[1];
	CC = m_Counter[2];
	DD = m_Counter[3];
	EE = m_Counter[4];
	FF = m_Counter[5];
	GG = m_Counter[6];
	HH = m_Counter[7];
	*/
	AA.uhigh = sha512sha384CtxParams.counter[0].uhigh;
	AA.ulow = sha512sha384CtxParams.counter[0].ulow;
	BB.uhigh = sha512sha384CtxParams.counter[1].uhigh;
	BB.ulow = sha512sha384CtxParams.counter[1].ulow;
	CC.uhigh = sha512sha384CtxParams.counter[2].uhigh;
	CC.ulow = sha512sha384CtxParams.counter[2].ulow;
	DD.uhigh = sha512sha384CtxParams.counter[3].uhigh;
	DD.ulow = sha512sha384CtxParams.counter[3].ulow;
	EE.uhigh = sha512sha384CtxParams.counter[4].uhigh;
	EE.ulow = sha512sha384CtxParams.counter[4].ulow;
	FF.uhigh = sha512sha384CtxParams.counter[5].uhigh;
	FF.ulow = sha512sha384CtxParams.counter[5].ulow;
	GG.uhigh = sha512sha384CtxParams.counter[6].uhigh;
	GG.ulow = sha512sha384CtxParams.counter[6].ulow;
	HH.uhigh = sha512sha384CtxParams.counter[7].uhigh;
	HH.ulow = sha512sha384CtxParams.counter[7].ulow;

	for (i = 0; i < 16; ++i) {
		//data[i] = in[i];
		data[i].uhigh = indata[i].uhigh;
		data[i].ulow = indata[i].ulow;
	}
	for (i = 16; i < 80; ++i) {
		//data[i] = sigma1(data[i-2]) + data[i-7] + sigma0(data[i-15]) + data[i - 16];
		tmpLonglong1 = Sigma1Lower(data[i-2]);
		tmpLonglong2 = Sigma0Lower(data[i-15]);
		ulonglong_add(tmpLonglong3, tmpLonglong1, tmpLonglong2);
		ulonglong_add(tmpLonglong1, data[i-7], data[i - 16]);
		ulonglong_add(data[i], tmpLonglong1, tmpLonglong3);
	}
	//throw Error("322");

	for (i = 0; i < 80; i++) {
		//T1 = HH + Sigma1(EE) + Ch(EE, FF, GG) + constant_512[i] + data[i];
		tmpLonglong1 = Sigma1Upper(EE);
		ulonglong_add(tmpLonglong2, HH, tmpLonglong1);
		tmpLonglong1 = Ch(EE, FF, GG);
		ulonglong_add(tmpLonglong3, tmpLonglong2, tmpLonglong1);
		ulonglong_set_hexstr(tmpLonglong1, constant_512[i]);
		ulonglong_add(tmpLonglong2, tmpLonglong1, data[i]);
		ulonglong_add(T1, tmpLonglong2, tmpLonglong3);
		//console.log("T1 %d %d", T1.uhigh, T1.ulow);	
		
		//T2 = Sigma0(AA) + Maj(AA,BB,CC);
		tmpLonglong1 = Sigma0Upper(AA);	
		tmpLonglong2 = Maj(AA, BB, CC);
		ulonglong_add(T2, tmpLonglong1, tmpLonglong2);
		//console.log("T2 %d %d", T2.uhigh, T2.ulow);	
		//throw Error("T2");

		//HH = GG;
		HH.uhigh = GG.uhigh;
		HH.ulow = GG.ulow;
		
		//GG = FF;
		GG.uhigh = FF.uhigh;
		GG.ulow = FF.ulow;
		
		//FF = EE;
		FF.uhigh = EE.uhigh;
		FF.ulow = EE.ulow;
		
		//EE = DD + T1;
		ulonglong_add(EE, DD, T1);
		
		//DD = CC;
		DD.uhigh = CC.uhigh;
		DD.ulow = CC.ulow;
		
		//CC = BB;
		CC.uhigh = BB.uhigh;
		CC.ulow = BB.ulow;
		
		//BB = AA;
		BB.uhigh = AA.uhigh;
		BB.ulow = AA.ulow;
		
		//AA = T1 + T2;
		ulonglong_add(AA, T1, T2);
	}

	//m_Counter[0] += AA;
	tmpLonglong1.uhigh = sha512sha384CtxParams.counter[0].uhigh;
	tmpLonglong1.ulow = sha512sha384CtxParams.counter[0].ulow;
	ulonglong_add(sha512sha384CtxParams.counter[0], tmpLonglong1, AA);
	
	//m_Counter[1] += BB;
	tmpLonglong1.uhigh = sha512sha384CtxParams.counter[1].uhigh;
	tmpLonglong1.ulow = sha512sha384CtxParams.counter[1].ulow;
	ulonglong_add(sha512sha384CtxParams.counter[1], tmpLonglong1, BB);
	
	//m_Counter[2] += CC;
	tmpLonglong1.uhigh = sha512sha384CtxParams.counter[2].uhigh;
	tmpLonglong1.ulow = sha512sha384CtxParams.counter[2].ulow;
	ulonglong_add(sha512sha384CtxParams.counter[2], tmpLonglong1, CC);
	
	//m_Counter[3] += DD;
	tmpLonglong1.uhigh = sha512sha384CtxParams.counter[3].uhigh;
	tmpLonglong1.ulow = sha512sha384CtxParams.counter[3].ulow;
	ulonglong_add(sha512sha384CtxParams.counter[3], tmpLonglong1, DD);
	
	//m_Counter[4] += EE;
	tmpLonglong1.uhigh = sha512sha384CtxParams.counter[4].uhigh;
	tmpLonglong1.ulow = sha512sha384CtxParams.counter[4].ulow;
	ulonglong_add(sha512sha384CtxParams.counter[4], tmpLonglong1, EE);
	
	//m_Counter[5] += FF;
	tmpLonglong1.uhigh = sha512sha384CtxParams.counter[5].uhigh;
	tmpLonglong1.ulow = sha512sha384CtxParams.counter[5].ulow;
	ulonglong_add(sha512sha384CtxParams.counter[5], tmpLonglong1, FF);
	
	//m_Counter[6] += GG;
	tmpLonglong1.uhigh = sha512sha384CtxParams.counter[6].uhigh;
	tmpLonglong1.ulow = sha512sha384CtxParams.counter[6].ulow;
	ulonglong_add(sha512sha384CtxParams.counter[6], tmpLonglong1, GG);
	
	//m_Counter[7] += HH;
	tmpLonglong1.uhigh = sha512sha384CtxParams.counter[7].uhigh;
	tmpLonglong1.ulow = sha512sha384CtxParams.counter[7].ulow;
	ulonglong_add(sha512sha384CtxParams.counter[7], tmpLonglong1, HH);
	
}

function SwapUint64(sha512sha384CtxParams, bytesdata, bytesdataindex) {
	var i = 0;
	
	sha512sha384CtxParams.uhigh = 0;
	sha512sha384CtxParams.ulow = 0;
	
	for (i = 0; i < 8; i++) {
		if (i < 4) {
			sha512sha384CtxParams.uhigh |= ((parseInt(bytesdata[i + bytesdataindex]) & 0xff) << ((3 - i) * 8));
		} else {
			sha512sha384CtxParams.ulow |= ((parseInt(bytesdata[i + bytesdataindex]) & 0xff) << ((3 - (i - 4)) * 8));
		}
	}
}

function sha512_sha384_str_to_array(strIn) {
	var bytesArray = new Uint8Array(strIn.length);
	var i = 0;
	
	for (i = 0; i < strIn.length; i++) {
		bytesArray[i] = strIn.charCodeAt(i);
	}
	
	return bytesArray;
}


function sha512_sha384_hex_to_array(hexStrIn) {
  var i = 0;
  var cnt = 0;
  var ele = 0;
  var bytesArray = null;

  cnt = 0;
  for (i = 0; i < hexStrIn.length; i++) {
    ele = hexStrIn.charCodeAt(i);
    if (ele >= 48 && ele < 48 + 10) {
      cnt++;
    }
    if (ele >= 65 && ele < 65 + 6) {
      cnt++;
    }
    if (ele >= 97 && ele < 97 + 6) {
      cnt++;
    }
  }
  bytesArray = new Uint8Array(parseInt((cnt + 1) / 2));
  cnt = 0;
  for (i = 0; i < hexStrIn.length; i++) {
    ele = hexStrIn.charCodeAt(i);
    if (ele >= 48 && ele < 48 + 10) {
      ele -= 48;
      cnt++;
    } else if (ele >= 65 && ele < 65 + 6) {
      ele = ele - 65 + 10;
      cnt++;
    } else if (ele >= 97 && ele < 97 + 6) {
      ele = ele - 97 + 10;
      cnt++;
    } else {
      continue;
    }
    if ((cnt % 2) == 1) {
      bytesArray[parseInt((cnt - 1) / 2)] = (ele << 4) & 0xF0;
    } else {
      bytesArray[parseInt((cnt - 1) / 2)] |= ele;
    }
  }

  return bytesArray;
}

function sha512_sha384_encode_hex(result, len) {
	var hex_digits = "0123456789abcdef";
	var output = new String();
	var i = 0;

	for (i = 0; i < len; i++) {
		output += hex_digits.charAt((result[i] >>> 4) & 0x0f);
		output += hex_digits.charAt((result[i]) & 0x0f);
	}
	
	return output;
}

测试代码:

var data1 = "Decrypt";
var data0 = "1234567890abcdef9999oplk8563plmh6003EBFF27AEDE040312E8D8159A91AE0149CDC9EE6775DE602739DB660D241935E8AA847EA015309664C1EBA947E0F043B8CD71240DE448F1D0B758A21E80009BA39A2799515469338E75B810C7550D2B0144DFDCEE981E3250B70F094A2AC98183DFF1B889B8249006ADAEA39504F5F4E8D3581E606D97029880DF721764FF94CD8E66BC1C924DE4451921BB95AF20DA4A9510FDDCCAF0AF88C520D5F6C942446D39079B072429FCA222250F88B753BEA4061E02364528BFEC8F66F4F67CA82CA33DEA0EDFE8FD6E4BF9226B87DB28C0DA0A776CFBD2E4977C0F1E738A443D9D4BE434B9A9F1D9B24D2ACBD7510928A8D4767E8EA8DEC66FF6587237956309";
var data2 = "96325";
var result1 = null;
var sha512ctx = null;
var sha384ctx = null;

sha512ctx = sha512_init();
sha512_sha384_update(sha512ctx, sha512_sha384_str_to_array(data0), data0.length);
sha512_sha384_update(sha512ctx, sha512_sha384_str_to_array(data1), data1.length);
sha512_sha384_update(sha512ctx, sha512_sha384_str_to_array(data2), data2.length);
result1 = sha512_final(sha512ctx);
console.log("sha512_final result:" + sha512_sha384_encode_hex(result1, 64));

/* hex */
sha512ctx = sha512_init();
sha512_sha384_update(sha512ctx, sha512_sha384_hex_to_array("001122334455"), 6);
sha512_sha384_update(sha512ctx, sha512_sha384_hex_to_array("AABBCCDDEEFF"), 6);
sha512_sha384_update(sha512ctx, sha512_sha384_hex_to_array("88"), 1);
result1 = sha512_final(sha512ctx);
console.log("sha512_final result:" + sha512_sha384_encode_hex(result1, 64));


sha384ctx = sha384_init();
sha512_sha384_update(sha384ctx, sha512_sha384_str_to_array(data0), data0.length);
sha512_sha384_update(sha384ctx, sha512_sha384_str_to_array(data1), data1.length);
sha512_sha384_update(sha384ctx, sha512_sha384_str_to_array(data2), data2.length);
result1 = sha384_final(sha384ctx);
console.log("sha384_final result:" + sha512_sha384_encode_hex(result1, 48));

/* hex */
sha384ctx = sha384_init();
sha512_sha384_update(sha384ctx, sha512_sha384_hex_to_array("001122334455"), 6);
sha512_sha384_update(sha384ctx, sha512_sha384_hex_to_array("AABBCCDDEEFF"), 6);
sha512_sha384_update(sha384ctx, sha512_sha384_hex_to_array("88"), 1);
result1 = sha384_final(sha384ctx);
console.log("sha384_final result:" + sha512_sha384_encode_hex(result1, 48));

测试结果:

在这里插入图片描述
经过其他平台工具验证,结果是对的

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2236900.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Pr 视频过渡:沉浸式视频

效果面板/视频过渡/沉浸式视频 Video Transitions/Immersive Video Adobe Premiere Pro 的视频过渡效果中&#xff0c;沉浸式视频 Immersive Video效果组主要用于 VR 视频剪辑之间的过渡。 自动 VR 属性 Auto VR Properties是所有 VR 视频过渡效果的通用选项。 默认勾选&#x…

Ascend C的编程模型

1 并发执行 Ascend C和cudnn相似&#xff0c;都是一种多核心编程的范式。想要了解Ascend C&#xff0c;必须得先掌握这种“多核”是怎么实现得。 多核执行&#xff0c;说白了就是使用CPU/GPU/Ascend的物理多核并发去执行一段流程&#xff0c;一般情况下&#xff0c;可以通过以…

商品,订单风控业务梳理二

订单风控流程 业务风控系统

苍穹外卖05-Redis相关知识点

目录 什么是Redis&#xff1f; redis中的一些常用指令 value的5种常用数据类型 各种数据类型的特点 Redis中数据操作的常用命令 字符串类型常用命令&#xff1a; 哈希类型常用命令 列表操作命令 集合操作命令 有序集合操作命令 通用命令 在java中操作Redis 环境…

一些面试题总结(一)

1、string为什么是不可变的&#xff0c;有什么好处 原因&#xff1a; 1、因为String类下的value数组是用final修饰的&#xff0c;final保证了value一旦被初始化&#xff0c;就不可改变其引用。 2、此外&#xff0c;value数组的访问权限为 private&#xff0c;同时没有提供方…

3.3 软件需求:面对对象分析模型

面对对象分析模型 1、对象2、面对对象的软件开发模型3、用例图建模基础3.1 用例图基本符号参与者用例系统执行关联 3.2 用例建模过程3.3 用例图初步3.4 用例图进阶关联Association泛化Inheritance包含Include扩展Extend示例 1、对象 在现实世界中有意义的&#xff0c;与所要解…

「C/C++」C++标准库 之 #include<exception> 异常处理库

✨博客主页何曾参静谧的博客&#x1f4cc;文章专栏「C/C」C/C程序设计&#x1f4da;全部专栏「VS」Visual Studio「C/C」C/C程序设计「UG/NX」BlockUI集合「Win」Windows程序设计「DSA」数据结构与算法「UG/NX」NX二次开发「QT」QT5程序设计「File」数据文件格式「PK」Parasoli…

嵌入式linux中gpio子系统的开发与实现

大家好,今天主要给大家分享一下,如何使用gpio子系统,来控制对应的引脚电平状态与实现。 第一:linux中gpio子系统描述 gpio0:gpio@fdd60000{compatible = "rockchip,gpio-bank";reg = <0x0 0xfdd60000 0x0 0x100>; interrupts = <GIC_SPI 33 IRQ_TYP…

【主机游戏】艾尔登法环游戏攻略

艾尔登法环&#xff0c;作为一款备受好评但优化问题频发的游戏&#xff0c;就连马斯克都夸过 今天介绍一下这款游戏 https://pan.quark.cn/s/24760186ac0b 角色升级 在《艾尔登法环》中&#xff0c;角色升级需要找到梅琳娜。你可以在关卡前废墟的营地附近&#xff0c;风暴关…

大数据面试题--kafka夺命连环问

1、kafka消息发送的流程&#xff1f; 在消息发送过程中涉及到两个线程&#xff1a;一个是 main 线程和一个 sender 线程。在 main 线程中创建了一个双端队列 RecordAccumulator。main 线程将消息发送给双端队列&#xff0c;sender 线程不断从双端队列 RecordAccumulator 中拉取…

出海企业如何借助云计算平台实现多区域部署?

云计算de小白 如需进一步了解&#xff0c;请单击链接了解有关 Akamai 云计算的更多信息 在本文中我们将告诉大家如何在Linode云计算平台上借助VLAN快速实现多地域部署。 首先我们需要明确一些基本概念和思想&#xff1a; 部署多区域 VLAN 为了在多区域部署中在不同的 VLAN …

W55RP20-EVB-Pico评估板介绍

目录 1 简介 2 硬件资源 2.1 硬件规格 2.2 引脚定义 2.3 工作条件 3 参考资料 3.1 RP2040 数据手册 3.2 原理图 ​编辑 原理图 & 物料清单 & Gerber 文件 3.3 尺寸图&#xff08;单位&#xff1a;mm&#xff09; ​编辑 3.4 认证 3.5 参考例程 4 硬件协…

【机器学习】均方误差根(RMSE:Root Mean Squared Error)

均方误差根&#xff08;Root Mean Squared Error&#xff0c;RMSE&#xff09;是机器学习和统计学中常用的误差度量指标&#xff0c;用于评估预测值与真实值之间的差异。它通常用于回归模型的评价&#xff0c;以衡量模型的预测精度。 RMSE的定义与公式 给定预测值 和实际值 …

《计算机原理与系统结构》学习系列——存储器(上)

系列文章目录 目录 存储器技术概要存储器层次cache&#xff0c;内存辅存存储器技术SRAM技术DRAM技术闪存磁盘存储器 局部性原理 高速缓存cache访存性能概念命中与缺失访存阻塞的周期数 cache基础&#xff1a;直接映射块号内存地址字段缺失缺失处理和写策略 全相联映射组相连映…

python爬虫自动库DrissionPage保存网页快照mhtml/pdf/全局截图/打印机另存pdf

目录 零一、保存网页快照的三种方法二、利用打印机保存pdf的方法 零 最近星球有人问如何使用页面打印功能&#xff0c;另存为pdf 一、保存网页快照的三种方法 解决方案已经放在星球内&#xff1a;https://articles.zsxq.com/id_55mr53xahr9a.html当然也可以看如下代码&…

【Linux】进程概念与PCB,父子进程与foke函数

目录 一、进程概念&#xff1a; 描述&#xff1a; 组织&#xff1a; 二、Linux中的进程管理&#xff1a; 指令&#xff1a;ps ajx 三、父子进程&#xff1a; PID和PPID的调用查看&#xff1a; 四、创建子进程------fork&#xff1a; 一、进程概念&#xff1a; 首先&…

处理PhotoShopCS5和CS6界面字体太小

处理PhotoShop CS6界面字体太小 背景&#xff1a;安装PhotoShop CS6后发现无法调大字体大小&#xff0c;特别是我的笔记本14寸的&#xff0c;显示的字体小到离谱。 百度好多什么降低该电脑分辨率&#xff0c;更改电脑的显示图标大小&#xff0c;或者PS里的首选项中的界面设置。…

【Linux第八课-进程间通信】管道、共享内存、消息队列、信号量、信号、可重入函数、volatile

目录 进程间通信为什么&#xff1f;是什么&#xff1f;怎么办&#xff1f;一般规律具体做法 匿名管道原理代码 命名管道原理代码 system V共享内存消息队列信号量信号量的接口 信号概念为什么&#xff1f;怎么办&#xff1f;准备信号的产生信号的保存概念三张表匹配的操作和系统…

文件互传助手 v1.0

电脑和手机互传文件&#xff0c;经常需要找数据线&#xff0c;连着数据线还要下载安装手机助手&#xff0c;还要安装驱动识别手机&#xff0c;还要点手机那个连接模式&#xff0c;实在太麻烦了。 明明是一件简单的事情&#xff0c;往往需要很多层手续。有时会用到微信网页端作文…

Spring Boot 与 Vue 共筑航空机票预定卓越平台

作者介绍&#xff1a;✌️大厂全栈码农|毕设实战开发&#xff0c;专注于大学生项目实战开发、讲解和毕业答疑辅导。 &#x1f345;获取源码联系方式请查看文末&#x1f345; 推荐订阅精彩专栏 &#x1f447;&#x1f3fb; 避免错过下次更新 Springboot项目精选实战案例 更多项目…