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

概述:

`
本人前端需要实现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.rhkb.cn/news/467611.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C++类和对象 (下)

文章目录 前言一. 再探构造函数初始化列表特性总结练习 二. 类型转换2.1 隐式类型转换2.2 临时对象具有常性2.3 explicit关键字2.4 多参数类型转化 三. static成员概念特性练习 四. 友元概念特性 五. 内部类概念特性 六. 匿名对象概念特性 七. 对象拷贝时的编译器优化END 前言 …

【数据集】【YOLO】【目标检测】航拍船只识别数据集 3550 张,YOLO航拍水面船只识别算法实战训练教程!

一、数据集介绍 【数据集】航拍船只识别数据集 3550 张&#xff0c;目标检测&#xff0c;包含YOLO/VOC格式标注。 数据集中包含1种分类&#xff1a;{0: ship}&#xff0c;代表水面船只。 数据集来自国内外图片网站、无人机航拍视频截图以及卫星云图&#xff1b; 可用于无人…

【LeetCode】【算法】48. 旋转图像

LeetCode 48. 旋转图像 题目描述 给定一个 n n 的二维矩阵 matrix 表示一个图像。请你将图像顺时针旋转 90 度。 你必须在 原地 旋转图像&#xff0c;这意味着你需要直接修改输入的二维矩阵。请不要 使用另一个矩阵来旋转图像。 思路 思路&#xff1a;再次拜见K神&#xf…

如何解决FPS低的问题?代码优化方法有哪些?

如果你是一名游戏开发者&#xff0c;或者对电脑性能有所追求的用户&#xff0c;那么你一定遇到过帧率&#xff08;FPS&#xff09;低的问题。帧率低会导致游戏卡顿、画面不流畅等问题&#xff0c;极大地影响了用户体验。本文将从代码层面探讨FPS低的原因&#xff0c;并提供一些…

边缘计算的学习

文章目录 概要何为边缘计算&#xff1f;现阶段&#xff0c;企业使用边缘计算相对云计算 整体架构流程边缘网络组件边缘计算与云安全 研究方向结合引用 概要 edge 何为边缘计算&#xff1f; 边缘计算&#xff08;英语&#xff1a;Edge computing&#xff09;&#xff0c;是一种…

【案例】Excel使用宏来批量插入图片

一、场景介绍 我有一个excel文件&#xff0c;需要通过一列的文件名称&#xff0c;按照规则给批量上传图片附件。 原始文件&#xff1a; 成功后文件&#xff1a; 二、实现方法 1. 使用【wps】工具打开Excel文件&#xff0c;将其保存为启用宏的文件。 2.找到编辑宏的【VB编辑器…

使用ChatGPT神速精读文献,12个高阶ChatGPT提示词指令,值得你复制使用

在学术研究的道路上,文献的阅读和分析往往是我们迈向深层次理解的第一步。如何有效提取文献中的核心要点,如何全面总结一个研究的背景与贡献,甚至如何深入剖析论文中的每个细节,都是每个研究者必须掌握的技能。通过系统化的文献分析,我们不仅能了解现有研究的框架与成果,…

leetcode 832.翻转图像

1.题目要求: 2.题目代码: class Solution { public://水平反转函数void replace_photo(vector<int>& array){for(int i 0;i < array.size();i){if(array[i] 1){array[i] 0;}else{array[i] 1;}}}vector<vector<int>> flipAndInvertImage(vector&…

CST案例分析:TLM算法仿真5G毫米波手机天线和整机

5G时代&#xff0c;产品复杂&#xff0c;更新换代快&#xff0c;如何快速仿真不同的设计版本是影响研发效率的关键问题。本期我们用达索系统SIMULIA自己的手机模型来演示5G毫米波的仿真。 &#xff08;图片仅为概念演示&#xff0c;未经达索系统授权不得使用&#xff09; 完整的…

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 硬件协…

【重装系统后重新配置2】pycharm 终端无法激活conda环境

pycharm 终端无法激活 conda 环境&#xff0c;但是 Windows本地终端是可以激活的 原因是pycharm 默认的终端是 Windows PowerShell 解决方法有两个&#xff1a; 一、在设置里&#xff0c;修改为cmd 二、下面直接选择

【51单片机】UART串口通信原理 + 使用

学习使用的开发板&#xff1a;STC89C52RC/LE52RC 编程软件&#xff1a;Keil5 烧录软件&#xff1a;stc-isp 开发板实图&#xff1a; 文章目录 串口硬件电路UART串口相关寄存器 编码单片机通过串口发送数据电脑通过串口发送数据控制LED灯 串口 串口是一种应用十分广泛的通讯接…

关于word 页眉页脚的一些小问题

去掉页眉底纹&#xff1a; 对文档的段落边框和底纹进行设置&#xff0c;也是页眉横线怎么删除的一种解决方式&#xff0c;具体操作如下&#xff1a; 选中页眉中的横线文本&#xff1b; 点击【开始】选项卡&#xff0c;在【段落】组中点击【边框】按钮的下拉箭头&#xff1b; …

SQL Servers审核提高数据库安全性

什么是SQL Server审核&#xff1f; SQL Server审核包括追踪和审查发生在SQL Server上的所有活动&#xff0c;检测潜在的威胁和漏洞&#xff0c;能够监控和记录对服务器设置的每次更改。此外&#xff0c;可以帮助管理员可以轻松地追踪数据库中特定表中的所有服务器活动&#xf…

Linux进程通信之共享内存

进程通信之共享内存 各个进程的虚拟内存是通过页表映射到物理内存中&#xff0c;而共享内存的实现就是允许两个不相关的进程映射到同一块物理内存&#xff0c;通过对该内存的读写数据以达到进程通信的目的。 共享内存是IPC进程通信方法中传输速度最快的方法&#xff0c;双方进…

解锁 AI 新境界:元素碰撞的神奇应用技巧全解析

前言 在当今科技飞速发展的时代&#xff0c;ChatGPT 作为一款强大的人工智能工具&#xff0c;为我们开启了全新的创意探索之门。当我们让 ChatGPT 去进行大量的元素碰撞时&#xff0c;相较于传统人力的联想方式&#xff0c;它能够凭借其强大的算法和海量的数据处理能力&#x…

MFC图形函数学习06——画椭圆弧线函数

绘制椭圆弧线函数是MFC基本绘图函数&#xff0c;这个函数需要的参数比较多&#xff0c;共四对坐标点。前两对坐标点确定椭圆的位置与大小&#xff0c;后两对坐标确定椭圆弧线的起点与终点。 一、绘制椭圆弧线函数 原型&#xff1a;BOOL Arc(int x1,int y1,int x2,int y2…

【C++】异常处理机制(对运行时错误的处理)

&#x1f308; 个人主页&#xff1a;谁在夜里看海. &#x1f525; 个人专栏&#xff1a;《C系列》《Linux系列》 ⛰️ 天高地阔&#xff0c;欲往观之。 目录 引言 1.编译器可以处理的错误 2.编译器不能处理的错误 3.传统的错误处理机制 assert终止程序 返回错误码 一、…

SQLI LABS | Less-35 GET-Bypass Add Slashes (we dont need them) Integer Based

关注这个靶场的其它相关笔记&#xff1a;SQLI LABS —— 靶场笔记合集-CSDN博客 0x01&#xff1a;过关流程 输入下面的链接进入靶场&#xff08;如果你的地址和我不一样&#xff0c;按照你本地的环境来&#xff09;&#xff1a; http://localhost/sqli-labs/Less-35/ 话不多说…

【Qwen2技术报告分析】解读模型架构 pre/post数据构建和模型评估

目录 前言 一、Tokenizer 二、模型结构 dense模型 MoE模型 模型参数设置 三、Pre-Training Pre-Training DATA LONG-CONTEXT TRAINING 四、Post-Training Post-Training DATA 人工数据注释&#xff08;collaborative data annotation&#xff09; 自动数据合成&a…