| u32 s; |
u32 s; |
| |
|
| int keysize=ctx->keysize; |
int keysize=ctx->keysize; |
| |
int keysizeb=(keysize+7)>>3; |
| int ivsize=ctx->ivsize; |
int ivsize=ctx->ivsize; |
| int ivsizeb=(ivsize+7)>>3; |
int ivsizeb=(ivsize+7)>>3; |
| |
|
| #define P(x) (((u8*)&(ctx->KPY[x][1]))[0]) |
#define P(x) (((u8*)&(ctx->KPY[x][1]))[0]) |
| #define KY(x) (ctx->KPY[(x)-(YMININD)][0]) |
#define KY(x) (ctx->KPY[(x)-(YMININD)][0]) |
| #define EIV(x) (((u8*)&(ctx->KPY[x+64-ivsizeb][1]))[2]) |
#define EIV(x) (((u8*)&(ctx->KPY[x+64-2*ivsizeb][1]))[2]) |
| |
|
| /* Create an initial permutation */ |
/* Create an initial permutation */ |
| u8 v= iv[0] ^ ((KY(0)>>16)&0xFF); |
u8 v= iv[0] ^ ((KY(0)>>16)&0xFF); |
| s = s + iv[i] + KY(YMININD+i); |
s = s + iv[i] + KY(YMININD+i); |
| u8 s0 = P(s&0x3F); |
u8 s0 = P(s&0x3F); |
| EIV(i) = s0; |
EIV(i) = s0; |
| s = ROTL32(s, 6) ^ (u32)s0; |
u8 s1 = P((s>>2)&0x3F); |
| |
EIV(i+ivsizeb) = s1; |
| |
s = ROTL32(s, 12) ^ (u32)s0 ^ (((u32)s1)<<6); |
| } |
} |
| /* Again, but with the last words of KY, and update EIV */ |
/* Again, but with the last words of KY, and update EIV */ |
| for(i=0; i<ivsizeb; i++) |
for(i=0; i<ivsizeb*2; i++) |
| { |
{ |
| s = s + iv[i] + KY(YMAXIND-i); |
s = s + EIV((i+ivsizeb*2-1)%(ivsizeb*2)) + KY(YMAXIND-i); |
| u8 s0 = P(s&0x3F); |
u8 s0 = P(s&0x3F); |
| EIV(i) += s0; |
EIV(i) += s0; |
| EIV(i) &= 0x3F; |
EIV(i) &= 0x3F; |
| #define P(i8,j) (((u8*)ctx->KPY)[(i8)+8*(j)+4]) |
#define P(i8,j) (((u8*)ctx->KPY)[(i8)+8*(j)+4]) |
| /* access P[i+j] where i8=8*i. */ |
/* access P[i+j] where i8=8*i. */ |
| /* P is byte 4 of the 8-byte record */ |
/* P is byte 4 of the 8-byte record */ |
| #define EIV(i8,j) (((u8*)ctx->KPY)[(i8)+8*(j+64-ivsizeb)+6]) |
#define EIV(i8,j) (((u8*)ctx->KPY)[(i8)+8*(j+64-2*ivsizeb)+6]) |
| /* access P[i+j] where i8=8*i. */ |
/* access P[i+j] where i8=8*i. */ |
| /* EIV is byte 6 of the 8-byte record */ |
/* EIV is byte 6 of the 8-byte record */ |
| #define Y(i8,j) (((u32*)&(((u8*)ctx->KPY)[(i8)+8*((j)-(YMININD))]))[0]) |
#define Y(i8,j) (((u32*)&(((u8*)ctx->KPY)[(i8)+8*((j)-(YMININD))]))[0]) |
| u32 x0 = EIV(i,ivsizeb) = EIV(i,0)^(s&0x3F); |
u32 x0 = EIV(i,ivsizeb) = EIV(i,0)^(s&0x3F); |
| P(i,64)=P(i,x0); |
P(i,64)=P(i,x0); |
| P(i,x0)=P(i,0); |
P(i,x0)=P(i,0); |
| Y(i,YMAXIND+1)=s=(s^Y(i,YMININD))+Y(i,x0); |
s=ROTL32(s,8)+Y(i,YMAXIND); |
| |
Y(i,YMAXIND+1) = Y(i,YMININD) + (s^Y(i,x0)); |
| } |
} |
| |
|
| s=s+Y(i,8)+Y(i,21)+Y(i,48); |
s=s+Y(i,8)+Y(i,21)+Y(i,48); |
| /* loose a few bytes */ |
/* loose a few bytes */ |
| { |
{ |
| int i; |
int i; |
| |
int bl; |
| |
|
| u32 s=ctx->s; |
u32 s=ctx->s; |
| |
|
| /* last call for this stream, or either you will loose a few bytes */ |
/* last call for this stream, or either you will loose a few bytes */ |
| { |
{ |
| int i; |
int i; |
| |
int bl; |
| |
|
| u32 s=ctx->s; |
u32 s=ctx->s; |
| |
|
| Y(i,YMAXIND+1)=(s^Y(i,YMININD))+Y(i,P(i,1+48)); |
Y(i,YMAXIND+1)=(s^Y(i,YMININD))+Y(i,P(i,1+48)); |
| s=ROTL32(s,11); |
s=ROTL32(s,11); |
| u32 output1=(s^Y(i,64))+Y(i,P(i,1+8)); |
u32 output1=(s^Y(i,64))+Y(i,P(i,1+8)); |
| |
u8 output1b[4]; |
| U32TO8_LITTLE(keystream+i, output1); |
U32TO8_LITTLE(keystream+i, output1); |
| s=ROTL32(s,7); |
s=ROTL32(s,7); |
| u32 output2=(s^Y(i,-1))+Y(i,P(i,1+21)); |
u32 output2=(s^Y(i,-1))+Y(i,P(i,1+21)); |
| { |
{ |
| int i; |
int i; |
| u8 j=0; |
u8 j=0; |
| static u8 str[] = |
static char str[] = |
| "This is the seed for generating the fixed internal permutation for Py. " |
"This is the seed for generating the fixed internal permutation for Py. " |
| "The permutation is used in the key setup and IV setup as a source of nonlinearity. " |
"The permutation is used in the key setup and IV setup as a source of nonlinearity. " |
| "The shifted special keys on a keyboard are ~!@#$%^&*()_+{}:|<>?"; |
"The shifted special keys on a keyboard are ~!@#$%^&*()_+{}:|<>?"; |
| u8 *p=str; |
u8 *p=(u8*)str; |
| |
|
| for(i=0; i<256; i++) |
for(i=0; i<256; i++) |
| internal_permutation[i] = i; |
internal_permutation[i] = i; |
| internal_permutation[j&0xFF] = tmp; |
internal_permutation[j&0xFF] = tmp; |
| p++; |
p++; |
| if(p[0] == 0) |
if(p[0] == 0) |
| p=str; |
p=(u8*)str; |
| } |
} |
| } |
} |