diff options
Diffstat (limited to 'libavutil/blowfish.c')
-rw-r--r-- | libavutil/blowfish.c | 61 |
1 files changed, 22 insertions, 39 deletions
diff --git a/libavutil/blowfish.c b/libavutil/blowfish.c index 87315766d7..abc0e03d4d 100644 --- a/libavutil/blowfish.c +++ b/libavutil/blowfish.c @@ -4,20 +4,20 @@ * * loosely based on Paul Kocher's implementation * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -27,15 +27,6 @@ #include "mem.h" #include "blowfish.h" -#if !FF_API_CRYPTO_CONTEXT -#define AV_BF_ROUNDS 16 - -struct AVBlowfish { - uint32_t p[AV_BF_ROUNDS + 2]; - uint32_t s[4][256]; -}; -#endif - static const uint32_t orig_p[AV_BF_ROUNDS + 2] = { 0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344, 0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89, @@ -303,24 +294,12 @@ static const uint32_t orig_s[4][256] = { 0xB74E6132, 0xCE77E25B, 0x578FDFE3, 0x3AC372E6 } }; -static void F(AVBlowfish *ctx, uint32_t *xl, uint32_t *xr, int i) -{ - uint32_t Xl, Xr; - uint32_t y; - - Xl = *xl; - 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; -} +#define F(Xl, Xr, P) \ + Xr ^=((( ctx->s[0][ Xl >> 24 ] \ + + ctx->s[1][(Xl >> 16) & 0xFF])\ + ^ ctx->s[2][(Xl >> 8) & 0xFF])\ + + ctx->s[3][ Xl & 0xFF])\ + ^ P; AVBlowfish *av_blowfish_alloc(void) { @@ -372,17 +351,21 @@ void av_blowfish_crypt_ecb(AVBlowfish *ctx, uint32_t *xl, uint32_t *xr, Xr = *xr; if (decrypt) { - for (i = AV_BF_ROUNDS + 1; i > 1; --i) - F(ctx, &Xl, &Xr, i); + Xl ^= ctx->p[AV_BF_ROUNDS + 1]; + 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 = Xr ^ ctx->p[0]; + Xr ^= ctx->p[0]; } else { - for (i = 0; i < AV_BF_ROUNDS; ++i) - F(ctx, &Xl, &Xr, i); + Xl ^= ctx->p[0]; + 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 = Xr ^ ctx->p[AV_BF_ROUNDS + 1]; + Xr ^= ctx->p[AV_BF_ROUNDS + 1]; } *xl = Xr; |