写基础Applet,试图测试加解密正确性
This commit is contained in:
@@ -215,9 +215,13 @@ public final class Zuc256Core {
|
||||
|
||||
// System.arraycopy(LFSR, 1, LFSR, 0, 15);
|
||||
// LFSR_lo 向左移
|
||||
System.arraycopy(state.LFSR_lo, 1, state.LFSR_lo, 0, 15);
|
||||
for (short i = 0; i < (short)15; i++) {
|
||||
state.LFSR_lo[i] = state.LFSR_lo[(short)(i + 1)];
|
||||
}
|
||||
// LFSR_hi 向左移
|
||||
System.arraycopy(state.LFSR_hi, 1, state.LFSR_hi, 0, 15);
|
||||
for (short i = 0; i < (short)15; i++) {
|
||||
state.LFSR_hi[i] = state.LFSR_hi[(short)(i + 1)];
|
||||
}
|
||||
|
||||
// LFSR[15] = v;
|
||||
// ---- 写回 LFSR[15] ----
|
||||
@@ -260,7 +264,7 @@ public final class Zuc256Core {
|
||||
|
||||
// 初始化MAC密钥
|
||||
private static void zuc256SetMacKey(Zuc256State state, byte[] K, byte[] IV, short macbits) {
|
||||
short[] D;
|
||||
short[] D = JCSystem.makeTransientShortArray(Zuc256Tables.D_COLS, JCSystem.CLEAR_ON_DESELECT);
|
||||
short[] TMP = JCSystem.makeTransientShortArray((short)2, JCSystem.CLEAR_ON_DESELECT);
|
||||
short[] X0 = JCSystem.makeTransientShortArray((short)2, JCSystem.CLEAR_ON_DESELECT);
|
||||
short[] X1 = JCSystem.makeTransientShortArray((short)2, JCSystem.CLEAR_ON_DESELECT);
|
||||
@@ -295,11 +299,9 @@ public final class Zuc256Core {
|
||||
short IV24 = (short)(IV[22] & 0x3F);
|
||||
|
||||
// D = (macbits / 32 < 3) ? Zuc256Tables.ZUC256_D[macbits / 32] : Zuc256Tables.ZUC256_D[3];
|
||||
if ((macbits / 32) < 3) {
|
||||
D = Zuc256Tables.ZUC256_D[macbits / 32];
|
||||
} else {
|
||||
D = Zuc256Tables.ZUC256_D[3];
|
||||
}
|
||||
short row = (short)((macbits / 32) < 3 ? (macbits / 32) : 3);
|
||||
Zuc256Tables.getDRow(row, D, (short)0);
|
||||
Zuc256Tables.getDRow(row, D, (short)0);
|
||||
|
||||
|
||||
short[] tmp = new short[2]; // 临时存储 makeU31 输出 (lo,hi)
|
||||
@@ -462,8 +464,14 @@ public final class Zuc256Core {
|
||||
add31(V[0], V[1], T2[0], T2[1], V);
|
||||
|
||||
// System.arraycopy(state.LFSR, 1, state.LFSR, 0, 15)
|
||||
System.arraycopy(state.LFSR_lo, 1, state.LFSR_lo, 0, 15);
|
||||
System.arraycopy(state.LFSR_hi, 1, state.LFSR_hi, 0, 15);
|
||||
// 相当于 System.arraycopy(state.LFSR_lo, 1, state.LFSR_lo, 0, 15);
|
||||
for (short j = 0; j < (short)15; j++) {
|
||||
state.LFSR_lo[j] = state.LFSR_lo[(short)(j + 1)];
|
||||
}
|
||||
// 相当于 System.arraycopy(state.LFSR_hi, 1, state.LFSR_hi, 0, 15);
|
||||
for (short j = 0; j < (short)15; j++) {
|
||||
state.LFSR_hi[j] = state.LFSR_hi[(short)(j + 1)];
|
||||
}
|
||||
|
||||
// state.LFSR[15] = v;
|
||||
state.LFSR_lo[15] = V[0];
|
||||
@@ -567,9 +575,16 @@ public final class Zuc256Core {
|
||||
|
||||
// LFSR左移
|
||||
// System.arraycopy(LFSR, 1, LFSR, 0, 15);
|
||||
// LFSR_lo 向左移
|
||||
for (short i = 0; i < (short)15; i++) {
|
||||
state.LFSR_lo[i] = state.LFSR_lo[(short)(i + 1)];
|
||||
}
|
||||
// LFSR_hi 向左移
|
||||
for (short i = 0; i < (short)15; i++) {
|
||||
state.LFSR_hi[i] = state.LFSR_hi[(short)(i + 1)];
|
||||
}
|
||||
|
||||
// LFSR[15] = v;
|
||||
System.arraycopy(state.LFSR_lo, 1, state.LFSR_lo, 0, 15);
|
||||
System.arraycopy(state.LFSR_hi, 1, state.LFSR_hi, 0, 15);
|
||||
state.LFSR_lo[15] = v_lo;
|
||||
state.LFSR_hi[15] = v_hi;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user