谁有电信epon测试三重搅动的加密和解密前后的数据么?
#define KEY_TO_KBIT(key, kbit) do { \
(kbit).x1 = ((key)[0] & 128) ? 1 : 0; \
(kbit).x2 = ((key)[0] & 64) ? 1 : 0; \
(kbit).x3 = ((key)[0] & 32) ? 1 : 0; \
(kbit).x4 = ((key)[0] & 16) ? 1 : 0; \
(kbit).x5 = ((key)[0] & 8) ? 1 : 0; \
(kbit).x6 = ((key)[0] & 4) ? 1 : 0; \
(kbit).x7 = ((key)[0] & 2) ? 1 : 0; \
(kbit).x8 = ((key)[0] & 1) ? 1 : 0; \
(kbit).p1 = ((key)[1] & 128) ? 1 : 0; \
(kbit).p2 = ((key)[1] & 64) ? 1 : 0; \
(kbit).p3 = ((key)[1] & 32) ? 1 : 0; \
(kbit).p4 = ((key)[1] & 16) ? 1 : 0; \
(kbit).p5 = ((key)[1] & 8) ? 1 : 0; \
(kbit).p6 = ((key)[1] & 4) ? 1 : 0; \
(kbit).p7 = ((key)[1] & 2) ? 1 : 0; \
(kbit).p8 = ((key)[1] & 1) ? 1 : 0; \
(kbit).p9 = ((key)[2] & 128) ? 1 : 0; \
(kbit).p10 = ((key)[2] & 64) ? 1 : 0; \
(kbit).p11 = ((key)[2] & 32) ? 1 : 0; \
(kbit).p12 = ((key)[2] & 16) ? 1 : 0; \
(kbit).p13 = ((key)[2] & 8) ? 1 : 0; \
(kbit).p14 = ((key)[2] & 4) ? 1 : 0; \
(kbit).p15 = ((key)[2] & 2) ? 1 : 0; \
(kbit).p16 = ((key)[2] & 1) ? 1 : 0; \
} while(0)
/* Save the result to final byte */
#define KBIT_TO_RESULT(kbit, r) do { \
r = ((kbit).r8 << 7) + \
((kbit).r7 << 6) + \
((kbit).r6 << 5) + \
((kbit).r5 << 4) + \
((kbit).r4 << 3) + \
((kbit).r3 << 2) + \
((kbit).r2 << 1) + \
((kbit).r1 ); \
} while(0)
/* Load the kbit from the original byte */
#define KBIT_LOAD_DATA(kbit, d) do { \
(kbit).d8 = (d & 128) ? 1 : 0; \
(kbit).d7 = (d & 64) ? 1 : 0; \
(kbit).d6 = (d & 32) ? 1 : 0; \
(kbit).d5 = (d & 16) ? 1 : 0; \
(kbit).d4 = (d & 8) ? 1 : 0; \
(kbit).d3 = (d & 4) ? 1 : 0; \
(kbit).d2 = (d & 2) ? 1 : 0; \
(kbit).d1 = (d & 1) ? 1 : 0; \
} while(0)
#define KBIT_DECODE(kbit, res) do { \
(res).k1 = ((kbit).x1 & (kbit).p13 & (kbit).p14) | \
((kbit).x2 & (kbit).p13 & ~(kbit).p14) | \
((kbit).x7 & ~(kbit).p13 & (kbit).p14) | \
((kbit).x8 & ~(kbit).p13 & ~(kbit).p14); \
(res).k2 = ((kbit).x3 & (kbit).p15 & (kbit).p16) | \
((kbit).x4 & (kbit).p15 & ~(kbit).p16) | \
((kbit).x5 & ~(kbit).p15 & (kbit).p16) | \
((kbit).x6 & ~(kbit).p15 & ~(kbit).p16); \
(res).k3 = ((res).k1 & (kbit).p9) | \
((res).k2 & ~(kbit).p9); \
(res).k4 = ((res).k1 & ~(kbit).p9) | \
((res).k2 & (kbit).p9); \
(res).k5 = ((res).k1 & (kbit).p10) | \
((res).k2 & ~(kbit).p10); \
(res).k6 = ((res).k1 & ~(kbit).p10) | \
((res).k2 & (kbit).p10); \
(res).k7 = ((res).k1 & (kbit).p11) | \
((res).k2 & ~(kbit).p11); \
(res).k8 = ((res).k1 & ~(kbit).p11) | \
((res).k2 & (kbit).p11); \
(res).k9 = ((res).k1 & (kbit).p12) | \
((res).k2 & ~(kbit).p12); \
(res).k10 = ((res).k1 & ~(kbit).p12) | \
((res).k2 & (kbit).p12); \
} while(0)
#define KBIT_SWAP_DATA(kbit1, c) do { \
KBIT_LOAD_DATA(kbit1, c); \
kbit1.r1 = kbit1.d1; \
kbit1.r2 = kbit1.d2; \
kbit1.r3 = kbit1.d5; \
kbit1.r4 = kbit1.d6; \
kbit1.r5 = kbit1.d3; \
kbit1.r6 = kbit1.d4; \
kbit1.r7 = kbit1.d7; \
kbit1.r8 = kbit1.d8; \
KBIT_TO_RESULT(kbit1, c); \
} while(0)
#define CHURN_BLK2(d1, d2, k1, k2, r1, r2) do {\
r1 = (((k1)^(k2))&(d1))|(~((k1)^(k2))&(d2)); \
r2 = (((k1)^(k2))&(d2))|(~((k1)^(k2))&(d1)); \
} while(0)
#define CHURN_BLK4(d1, d2, d3, d4, k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, k11, k12, r1, r2, r3, r4) do {\
unsigned char t1, t2, t3, t4, t5, t6, t7, t8; \
CHURN_BLK2(d1, d2, k1, k2, t1, t2); \
CHURN_BLK2(d3, d4, k7, k8, t3, t4); \
t5 = (k3) ^ t1; \
t6 = t3 ^ (k6); \
t7 = (k9) ^ t2; \
t8 = t4 ^ (k12); \
CHURN_BLK2(t5, t6, k4, k5, r1, r2); \
CHURN_BLK2(t7, t8, k10, k11, r3, r4); \
} while(0)
/* Churning or dechurning a byte within kbit */
#define CHURNING(kbit) do {\
CHURN_BLK4(kbit.d1, kbit.d2, kbit.d3, kbit.d4, \
kbit.k1, kbit.p1, kbit.k3, kbit.k2, kbit.p2, kbit.k4, \
kbit.k1, kbit.p3, kbit.k5, kbit.k2, kbit.p4, kbit.k6, \
kbit.r1, kbit.r2, kbit.r3, kbit.r4); \
CHURN_BLK4(kbit.d5, kbit.d6, kbit.d7, kbit.d8, \
kbit.k1, kbit.p5, kbit.k7, kbit.k2, kbit.p6, kbit.k8, \
kbit.k1, kbit.p7, kbit.k9, kbit.k2, kbit.p8, kbit.k10, \
kbit.r5, kbit.r6, kbit.r7, kbit.r8); \
} while(0)