new对象(short、byte数组)改为调用JCSystem.makeTransientXxxArray放到ram里面;

makeTransientXxxArray类型改为MEMORY_TYPE_TRANSIENT_RESETMEMORY_TYPE_TRANSIENT_RESET
This commit is contained in:
zcy
2025-09-09 00:04:54 +08:00
parent 5456e990e6
commit 8e25aab97a
8 changed files with 63 additions and 55 deletions

View File

@@ -25,12 +25,12 @@ public final class Zuc256EncryptCtx {
public Zuc256EncryptCtx(Zuc256State state){
this.state = state;
this.buf = new byte[4];
this.buf = JCSystem.makeTransientByteArray((short)4, JCSystem.MEMORY_TYPE_TRANSIENT_RESET);
}
public Zuc256EncryptCtx(){
this.state = new Zuc256State();
this.buf = new byte[4];
this.state = new Zuc256State(); //todo how to put in ram?
this.buf = JCSystem.makeTransientByteArray((short)4, JCSystem.MEMORY_TYPE_TRANSIENT_RESET);
}
// 初始化加密上下文
@@ -76,17 +76,17 @@ public final class Zuc256EncryptCtx {
// 缓冲区已满处理一个完整的4字节块
if (this.buflen == 4) {
// int keystream = zuc256GenerateKeyword(this.state);
short[] ks = JCSystem.makeTransientShortArray((short)2, JCSystem.CLEAR_ON_DESELECT);
short[] ks = JCSystem.makeTransientShortArray((short)2, JCSystem.MEMORY_TYPE_TRANSIENT_RESET);
zuc256GenerateKeyword(this.state, ks); // ks[0]=lo, ks[1]=hi
// int plain = getU32(this.buf, 0);
// 取出 4 字节明文 → plain[0]=lo, plain[1]=hi
short[] plain = JCSystem.makeTransientShortArray((short)2, JCSystem.CLEAR_ON_DESELECT);
short[] plain = JCSystem.makeTransientShortArray((short)2, JCSystem.MEMORY_TYPE_TRANSIENT_RESET);
getU32(this.buf, (short)0, plain);
// putU32(out, 0, plain ^ keystream);
// plain ^ ks → res
short[] res = JCSystem.makeTransientShortArray((short)2, JCSystem.CLEAR_ON_DESELECT);
short[] res = JCSystem.makeTransientShortArray((short)2, JCSystem.MEMORY_TYPE_TRANSIENT_RESET);
xor32(plain[0], plain[1], ks[0], ks[1], res);
// 写回 out 的前4字节
putU32(out, (short)0, res[0], res[1]);
@@ -113,14 +113,14 @@ public final class Zuc256EncryptCtx {
short fullBlocks = (short) (inlen / 4);
if (fullBlocks > 0) {
// int[] keystream = new int[fullBlocks];
short[] ks_hi = JCSystem.makeTransientShortArray(fullBlocks, JCSystem.CLEAR_ON_DESELECT);
short[] ks_lo = JCSystem.makeTransientShortArray(fullBlocks, JCSystem.CLEAR_ON_DESELECT);
short[] ks_hi = JCSystem.makeTransientShortArray(fullBlocks, JCSystem.MEMORY_TYPE_TRANSIENT_RESET);
short[] ks_lo = JCSystem.makeTransientShortArray(fullBlocks, JCSystem.MEMORY_TYPE_TRANSIENT_RESET);
// zuc256GenerateKeystream(this.state, fullBlocks, keystream);
zuc256GenerateKeystream(this.state, fullBlocks, ks_hi, ks_lo);
// 临时装一个32位字
short[] word = JCSystem.makeTransientShortArray((short)2, JCSystem.CLEAR_ON_DESELECT);
short[] word = JCSystem.makeTransientShortArray((short)2, JCSystem.MEMORY_TYPE_TRANSIENT_RESET);
// 逐块异或加密
for (short i = 0; i < fullBlocks; i++) {
@@ -170,12 +170,12 @@ public final class Zuc256EncryptCtx {
if (this.buflen > 0) {
// int keystream = zuc256GenerateKeyword(this.state);
// 生成一个 32-bit 密钥字ks[0]=lo16, ks[1]=hi16
short[] ks = JCSystem.makeTransientShortArray((short)2, JCSystem.CLEAR_ON_DESELECT);
short[] ks = JCSystem.makeTransientShortArray((short)2, JCSystem.MEMORY_TYPE_TRANSIENT_RESET);
zuc256GenerateKeyword(this.state, ks);
// byte[] keystreamBytes = new byte[4];
// putU32(keystreamBytes, 0, keystream);
byte[] keystreamBytes = new byte[4];
byte[] keystreamBytes = JCSystem.makeTransientByteArray((short)4, JCSystem.MEMORY_TYPE_TRANSIENT_RESET);
putU32(keystreamBytes, (short)0, ks[0], ks[1]);
// 逐字节异或