输入80E3,可执行算法正确性检验,验证通过,对len=38Bytes明文加密结果符合预期、解密结果符合输入;

输入80E2,可写入密钥到flash,若算法类型、key id, key版本一致,就写入,已满就报错,无记录就写入新记录;
输入80CA,可执行伪位置加密,原封不动将输入的data返回回来。
This commit is contained in:
zcy
2025-09-08 23:46:46 +08:00
parent b41fff9d09
commit 5456e990e6
6 changed files with 231 additions and 127 deletions

View File

@@ -89,7 +89,7 @@ public final class Zuc256EncryptCtx {
short[] res = JCSystem.makeTransientShortArray((short)2, JCSystem.CLEAR_ON_DESELECT);
xor32(plain[0], plain[1], ks[0], ks[1], res);
// 写回 out 的前4字节
putU32(out, outPos, res[0], res[1]);
putU32(out, (short)0, res[0], res[1]);
this.buflen = 0;
// Arrays.fill(this.buf, (byte) 0);
@@ -156,7 +156,7 @@ public final class Zuc256EncryptCtx {
// 缓存剩余不足4字节的数据
if (inlen > 0) {
// 等价于 System.arraycopy(in, 0, this.buf, 0, inlen);
Util.arrayCopyNonAtomic(in, (short)0, this.buf, (short)0, inlen);
Util.arrayCopyNonAtomic(in, (short)inPos, this.buf, (short)0, inlen);
this.buflen = inlen;
}
@@ -179,14 +179,17 @@ public final class Zuc256EncryptCtx {
putU32(keystreamBytes, (short)0, ks[0], ks[1]);
// 逐字节异或
short outOffset = (short)(out.length - this.buflen);
for (short i = 0; i < this.buflen; i++) {
out[i] = (byte) (this.buf[i] ^ keystreamBytes[i]);
out[(short)(i+outOffset)] = (byte) (this.buf[i] ^ keystreamBytes[i]);
}
}
// 清理上下文
// Arrays.fill(this.buf, (byte) 0);
for (short i = 0; i < (short)this.buf.length; i++) {
for(short i=0; i<4; i++) {
this.buf[i] = (byte)0;
}