mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-03-23 11:29:03 +00:00
Blowfish: restructure/simplify code a bit.
Very slightly faster (2% or so) Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
parent
9862cbd7a4
commit
ec08676232
@ -294,24 +294,12 @@ static const uint32_t orig_s[4][256] = {
|
|||||||
0xB74E6132, 0xCE77E25B, 0x578FDFE3, 0x3AC372E6 }
|
0xB74E6132, 0xCE77E25B, 0x578FDFE3, 0x3AC372E6 }
|
||||||
};
|
};
|
||||||
|
|
||||||
static void F(AVBlowfish *ctx, uint32_t *xl, uint32_t *xr, int i)
|
#define F(Xl, Xr, P) \
|
||||||
{
|
Xr ^=((( ctx->s[0][ Xl >> 24 ] \
|
||||||
uint32_t Xl, Xr;
|
+ ctx->s[1][(Xl >> 16) & 0xFF])\
|
||||||
uint32_t y;
|
^ ctx->s[2][(Xl >> 8) & 0xFF])\
|
||||||
|
+ ctx->s[3][ Xl & 0xFF])\
|
||||||
Xl = *xl;
|
^ P;
|
||||||
Xr = *xr;
|
|
||||||
|
|
||||||
Xl ^= ctx->p[i];
|
|
||||||
y = ctx->s[0][(Xl >> 24) & 0xFF];
|
|
||||||
y += ctx->s[1][(Xl >> 16) & 0xFF];
|
|
||||||
y ^= ctx->s[2][(Xl >> 8) & 0xFF];
|
|
||||||
y += ctx->s[3][ Xl & 0xFF];
|
|
||||||
Xr ^= y;
|
|
||||||
|
|
||||||
*xl = Xr;
|
|
||||||
*xr = Xl;
|
|
||||||
}
|
|
||||||
|
|
||||||
av_cold void av_blowfish_init(AVBlowfish *ctx, const uint8_t *key, int key_len)
|
av_cold void av_blowfish_init(AVBlowfish *ctx, const uint8_t *key, int key_len)
|
||||||
{
|
{
|
||||||
@ -358,17 +346,21 @@ void av_blowfish_crypt_ecb(AVBlowfish *ctx, uint32_t *xl, uint32_t *xr,
|
|||||||
Xr = *xr;
|
Xr = *xr;
|
||||||
|
|
||||||
if (decrypt) {
|
if (decrypt) {
|
||||||
for (i = AV_BF_ROUNDS + 1; i > 1; --i)
|
Xl ^= ctx->p[AV_BF_ROUNDS + 1];
|
||||||
F(ctx, &Xl, &Xr, i);
|
for (i = AV_BF_ROUNDS; i > 0; i-=2) {
|
||||||
|
F(Xl, Xr, ctx->p[i ]);
|
||||||
|
F(Xr, Xl, ctx->p[i-1]);
|
||||||
|
}
|
||||||
|
|
||||||
Xl = Xl ^ ctx->p[1];
|
Xr ^= ctx->p[0];
|
||||||
Xr = Xr ^ ctx->p[0];
|
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < AV_BF_ROUNDS; ++i)
|
Xl ^= ctx->p[0];
|
||||||
F(ctx, &Xl, &Xr, i);
|
for (i = 1; i < AV_BF_ROUNDS+1; i+=2){
|
||||||
|
F(Xl, Xr, ctx->p[i ]);
|
||||||
|
F(Xr, Xl, ctx->p[i+1]);
|
||||||
|
}
|
||||||
|
|
||||||
Xl = Xl ^ ctx->p[AV_BF_ROUNDS];
|
Xr ^= ctx->p[AV_BF_ROUNDS + 1];
|
||||||
Xr = Xr ^ ctx->p[AV_BF_ROUNDS + 1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*xl = Xr;
|
*xl = Xr;
|
||||||
|
Loading…
Reference in New Issue
Block a user