临时存储

This commit is contained in:
zcy
2025-09-08 13:28:19 +08:00
parent ed52d849a4
commit 98d411d70d
10 changed files with 392 additions and 57 deletions

View File

@@ -363,23 +363,28 @@ public final class Zuc256Util {
*/
static short add32_with_carry(short a_lo, short a_hi,
short b_lo, short b_hi,
short[] out /*len=2*/) {
// 用你现成的 add32 得到结果
add32(a_lo, a_hi, b_lo, b_hi, out);
short[] out /* len=2 */) {
// 低 16 位相加
short lo = (short)(a_lo + b_lo);
// 判断低 16 位是否溢出
short carry_lo = (short)(((a_lo & 0xFFFF) + (b_lo & 0xFFFF)) >>> 16);
// 进位判断:如果结果 < 其中一个加数,则说明溢出
// (因为 add32 是 mod 2^32 的)
// 我们只看 hi 部分即可
int sum_hi = (out[1] & 0xFFFF);
int a_hi_u = (a_hi & 0xFFFF);
int b_hi_u = (b_hi & 0xFFFF);
// 高 16 位相加 + 低位进位
short hi_tmp = (short)(a_hi + b_hi);
short carry_hi1 = (short)(((a_hi & 0xFFFF) + (b_hi & 0xFFFF)) >>> 16);
if (sum_hi < a_hi_u || sum_hi < b_hi_u) {
return 1;
}
return 0;
short hi = (short)(hi_tmp + carry_lo);
short carry_hi2 = (short)(((hi_tmp & 0xFFFF) + (carry_lo & 0xFFFF)) >>> 16);
// 输出结果
out[0] = lo;
out[1] = hi;
// 最终进位 = 高位相加本身的进位 + 高位再加低位进位的进位
return (short)((carry_hi1 + carry_hi2) & 0x1);
}
/**
* 64位加法: a4 + b4 -> a4
* 输入输出: short[4],低到高 (a[0]=lo16, a[1]=hi16, a[2]=lo16 of high dword, a[3]=hi16 of high dword)