移植中

This commit is contained in:
zcy
2025-09-05 15:55:46 +08:00
parent 2310d0aca1
commit 747ac56a68
5 changed files with 65 additions and 27 deletions

View File

@@ -7,22 +7,36 @@ public final class Zuc256Util {
private Zuc256Util() {}
/** 辅助方法:字节数组转换为32位整数 */
public static int getU32(byte[] p, int offset) {
return ((p[offset] & 0xFF) << 24) |
((p[offset + 1] & 0xFF) << 16) |
((p[offset + 2] & 0xFF) << 8) |
(p[offset + 3] & 0xFF);
/** 辅助方法:字节数组取出 32 位整数,存放到 short[2] (lo, hi) */
public static void getU32(byte[] p, short offset, short[] out32 /* len=2 */) {
out32[0] = (short) (((p[offset + 2] & 0xFF) << 8) | (p[offset + 3] & 0xFF)); //低16位
out32[1] = (short) (((p[offset] & 0xFF) << 8) | (p[offset + 1] & 0xFF)); //高16位
}
/** 辅助方法将32位整数转换为字节数组 */
public static void putU32(byte[] p, int offset, int v) {
p[offset] = (byte) (v >> 24);
p[offset + 1] = (byte) (v >> 16);
p[offset + 2] = (byte) (v >> 8);
p[offset + 3] = (byte) v;
// /** 辅助方法将32位整数转换为字节数组 */
// public static void putU32(byte[] p, int offset, int v) {
// p[offset] = (byte) (v >> 24);
// p[offset + 1] = (byte) (v >> 16);
// p[offset + 2] = (byte) (v >> 8);
// p[offset + 3] = (byte) v;
// }
/** 辅助方法将32位整数(vlo=低16位, vhi=高16位)写入字节数组 */
public static void putU32(byte[] p, short offset, short vlo, short vhi) {
// 写高16位
putU16(p, offset, vhi);
// 写低16位
putU16(p, (short)(offset + 2), vlo);
}
/** 辅助方法将16位整数(short)写入字节数组,高字节在前 */
public static void putU16(byte[] p, short offset, short v) {
p[offset] = (byte) ((v >> 8) & 0xFF);
p[offset + 1] = (byte) (v & 0xFF);
}
// === 31/32 位运算 ===
/** 31位加法 */