📄 aescrypp.c
字号:
: s(x,0)) \
: r==2 ? \
( c==0 ? nc==8 ? s(x,3) : s(x,2) \
: c==1 ? nc==8 ? s(x,4) : s(x,3) \
: c==2 ? nc==8 ? s(x,5) : nc==4 ? s(x,0) : s(x,4) \
: c==3 ? nc==8 ? s(x,6) : nc==5 ? s(x,0) : nc==4 ? s(x,1) : s(x,5) \
: c==4 ? nc==8 ? s(x,7) : nc==7 ? s(x,6) : nc==6 ? s(x,0) : s(x,1) \
: c==5 ? nc==6 ? s(x,1) : s(x,0) \
: c==6 ? s(x,1) \
: s(x,2)) \
: \
( c==0 ? nc>6 ? s(x,4) : s(x,3) \
: c==1 ? nc>6 ? s(x,5) : nc==4 ? s(x,0) : s(x,4) \
: c==2 ? nc>6 ? s(x,6) : nc==6 ? s(x,5) : nc==5 ? s(x,0) : s(x,1) \
: c==3 ? nc==8 ? s(x,7) : nc==5 ? s(x,1) : nc==4 ? s(x,2) : s(x,0) \
: c==4 ? nc==8 ? s(x,0) : nc==5 ? s(x,2) : s(x,1) \
: c==5 ? nc==8 ? s(x,1) : s(x,2) \
: c==6 ? nc==8 ? s(x,2) : s(x,3) \
: s(x,3)))
#if defined(FT4_SET)
#undef dec_fmvars
#define dec_fmvars
#define fwd_rnd(y,x,k,c) s(y,c)= (k)[c] ^ four_tables(x,ft_tab,fwd_var,rf1,c)
#elif defined(FT1_SET)
#undef dec_fmvars
#define dec_fmvars
#define fwd_rnd(y,x,k,c) s(y,c)= (k)[c] ^ one_table(x,upr,ft_tab,fwd_var,rf1,c)
#else
#define fwd_rnd(y,x,k,c) s(y,c) = fwd_mcol(no_table(x,s_box,fwd_var,rf1,c)) ^ (k)[c]
#endif
#if defined(FL4_SET)
#define fwd_lrnd(y,x,k,c) s(y,c)= (k)[c] ^ four_tables(x,fl_tab,fwd_var,rf1,c)
#elif defined(FL1_SET)
#define fwd_lrnd(y,x,k,c) s(y,c)= (k)[c] ^ one_table(x,ups,fl_tab,fwd_var,rf1,c)
#else
#define fwd_lrnd(y,x,k,c) s(y,c) = no_table(x,s_box,fwd_var,rf1,c) ^ (k)[c]
#endif
aes_rval aes_enc_blk(const unsigned char in_blk[], unsigned char out_blk[], const aes_ctx cx[1])
{ uint32_t locals(b0, b1);
const uint32_t *kp = cx->k_sch;
dec_fmvars /* declare variables for fwd_mcol() if needed */
if(!(cx->n_blk & 1)) return aes_bad;
#if (ENC_UNROLL == FULL)
state_in((cx->n_rnd & 1 ? b1 : b0), in_blk, kp);
kp += (cx->n_rnd - 9) * nc;
switch(cx->n_rnd)
{
case 14: round(fwd_rnd, b1, b0, kp - 4 * nc);
case 13: round(fwd_rnd, b0, b1, kp - 3 * nc);
case 12: round(fwd_rnd, b1, b0, kp - 2 * nc);
case 11: round(fwd_rnd, b0, b1, kp - nc);
case 10: round(fwd_rnd, b1, b0, kp );
round(fwd_rnd, b0, b1, kp + nc);
round(fwd_rnd, b1, b0, kp + 2 * nc);
round(fwd_rnd, b0, b1, kp + 3 * nc);
round(fwd_rnd, b1, b0, kp + 4 * nc);
round(fwd_rnd, b0, b1, kp + 5 * nc);
round(fwd_rnd, b1, b0, kp + 6 * nc);
round(fwd_rnd, b0, b1, kp + 7 * nc);
round(fwd_rnd, b1, b0, kp + 8 * nc);
round(fwd_lrnd, b0, b1, kp + 9 * nc);
}
#else
{ uint32_t rnd;
state_in(b0, in_blk, kp);
#if (ENC_UNROLL == PARTIAL)
for(rnd = 0; rnd < (cx->n_rnd - 1) >> 1; ++rnd)
{
kp += nc;
round(fwd_rnd, b1, b0, kp);
kp += nc;
round(fwd_rnd, b0, b1, kp);
}
if(cx->n_rnd & 1)
{
l_copy(b1, b0);
}
else
{
kp += nc;
round(fwd_rnd, b1, b0, kp);
}
#else
for(rnd = 0; rnd < cx->n_rnd - 1; ++rnd)
{
kp += nc;
round(fwd_rnd, b1, b0, kp);
l_copy(b0, b1);
}
#endif
kp += nc;
round(fwd_lrnd, b0, b1, kp);
}
#endif
state_out(out_blk, b0);
return aes_good;
}
#endif
#if defined(DECRYPTION)
#define inv_var(x,r,c) \
( r==0 ? \
( c==0 ? s(x,0) \
: c==1 ? s(x,1) \
: c==2 ? s(x,2) \
: c==3 ? s(x,3) \
: c==4 ? s(x,4) \
: c==5 ? s(x,5) \
: c==6 ? s(x,6) \
: s(x,7)) \
: r==1 ? \
( c==0 ? nc==8 ? s(x,7) : nc==7 ? s(x,6) : nc==6 ? s(x,5) : nc==5 ? s(x,4) : s(x,3) \
: c==1 ? s(x,0) \
: c==2 ? s(x,1) \
: c==3 ? s(x,2) \
: c==4 ? s(x,3) \
: c==5 ? s(x,4) \
: c==6 ? s(x,5) \
: s(x,6)) \
: r==2 ? \
( c==0 ? nc>6 ? s(x,5) : nc==6 ? s(x,4) : nc==5 ? s(x,3) : s(x,2) \
: c==1 ? nc>6 ? s(x,6) : nc==6 ? s(x,5) : nc==5 ? s(x,4) : s(x,3) \
: c==2 ? nc==8 ? s(x,7) : s(x,0) \
: c==3 ? nc==8 ? s(x,0) : s(x,1) \
: c==4 ? nc==8 ? s(x,1) : s(x,2) \
: c==5 ? nc==8 ? s(x,2) : s(x,3) \
: c==6 ? nc==8 ? s(x,3) : s(x,4) \
: s(x,4)) \
: \
( c==0 ? nc==8 ? s(x,4) : nc==5 ? s(x,2) : nc==4 ? s(x,1) : s(x,3) \
: c==1 ? nc==8 ? s(x,5) : nc==5 ? s(x,3) : nc==4 ? s(x,2) : s(x,4) \
: c==2 ? nc==8 ? s(x,6) : nc==5 ? s(x,4) : nc==4 ? s(x,3) : s(x,5) \
: c==3 ? nc==8 ? s(x,7) : nc==7 ? s(x,6) : s(x,0) \
: c==4 ? nc>6 ? s(x,0) : s(x,1) \
: c==5 ? nc==6 ? s(x,2) : s(x,1) \
: c==6 ? s(x,2) \
: s(x,3)))
#if defined(IT4_SET)
#undef dec_imvars
#define dec_imvars
#define inv_rnd(y,x,k,c) s(y,c)= (k)[c] ^ four_tables(x,it_tab,inv_var,rf1,c)
#elif defined(IT1_SET)
#undef dec_imvars
#define dec_imvars
#define inv_rnd(y,x,k,c) s(y,c)= (k)[c] ^ one_table(x,upr,it_tab,inv_var,rf1,c)
#else
#define inv_rnd(y,x,k,c) s(y,c) = inv_mcol(no_table(x,inv_s_box,inv_var,rf1,c) ^ (k)[c])
#endif
#if defined(IL4_SET)
#define inv_lrnd(y,x,k,c) s(y,c)= (k)[c] ^ four_tables(x,il_tab,inv_var,rf1,c)
#elif defined(IL1_SET)
#define inv_lrnd(y,x,k,c) s(y,c)= (k)[c] ^ one_table(x,ups,il_tab,inv_var,rf1,c)
#else
#define inv_lrnd(y,x,k,c) s(y,c) = no_table(x,inv_s_box,inv_var,rf1,c) ^ (k)[c]
#endif
aes_rval aes_dec_blk(const unsigned char in_blk[], unsigned char out_blk[], const aes_ctx cx[1])
{ uint32_t locals(b0, b1);
const uint32_t *kp = cx->k_sch + nc * cx->n_rnd;
dec_imvars /* declare variables for inv_mcol() if needed */
if(!(cx->n_blk & 2)) return aes_bad;
#if (DEC_UNROLL == FULL)
state_in((cx->n_rnd & 1 ? b1 : b0), in_blk, kp);
kp = cx->k_sch + 9 * nc;
switch(cx->n_rnd)
{
case 14: round(inv_rnd, b1, b0, kp + 4 * nc);
case 13: round(inv_rnd, b0, b1, kp + 3 * nc);
case 12: round(inv_rnd, b1, b0, kp + 2 * nc);
case 11: round(inv_rnd, b0, b1, kp + nc);
case 10: round(inv_rnd, b1, b0, kp );
round(inv_rnd, b0, b1, kp - nc);
round(inv_rnd, b1, b0, kp - 2 * nc);
round(inv_rnd, b0, b1, kp - 3 * nc);
round(inv_rnd, b1, b0, kp - 4 * nc);
round(inv_rnd, b0, b1, kp - 5 * nc);
round(inv_rnd, b1, b0, kp - 6 * nc);
round(inv_rnd, b0, b1, kp - 7 * nc);
round(inv_rnd, b1, b0, kp - 8 * nc);
round(inv_lrnd, b0, b1, kp - 9 * nc);
}
#else
{ uint32_t rnd;
state_in(b0, in_blk, kp);
#if (DEC_UNROLL == PARTIAL)
for(rnd = 0; rnd < (cx->n_rnd - 1) >> 1; ++rnd)
{
kp -= nc;
round(inv_rnd, b1, b0, kp);
kp -= nc;
round(inv_rnd, b0, b1, kp);
}
if(cx->n_rnd & 1)
{
l_copy(b1, b0);
}
else
{
kp -= nc;
round(inv_rnd, b1, b0, kp);
}
#else
for(rnd = 0; rnd < cx->n_rnd - 1; ++rnd)
{
kp -= nc;
round(inv_rnd, b1, b0, kp);
l_copy(b0, b1);
}
#endif
kp -= nc;
round(inv_lrnd, b0, b1, kp);
}
#endif
state_out(out_blk, b0);
return aes_good;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -