diff options
author | David Goldwich <david.goldwich@gmail.com> | 2011-09-02 08:20:58 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2011-09-21 08:28:20 +0200 |
commit | b3e144a7dfc6953df3b3e478eb8b8521ab5c6ecc (patch) | |
tree | 7a560a4854c9316d3e7e64bdbc14cb30e8734716 /libavutil/des.c | |
parent | 3ffe32eb96e2414bdd87b353953d77fb83eca8ae (diff) | |
download | ffmpeg-b3e144a7dfc6953df3b3e478eb8b8521ab5c6ecc.tar.gz |
des: add possibility to calculate DES-CBC-MAC with small buffer
This patch adds the possibility to calculate the DES-CBC-MAC of a
source buffer (i.e. the last block of the buffer encrypted in CBC
mode) without having to allocate a destination buffer that is as
long as the complete source buffer, but instead only 8 bytes
for the MAC.
Signed-off-by: David Goldwich <david.goldwich@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Diffstat (limited to 'libavutil/des.c')
-rw-r--r-- | libavutil/des.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/libavutil/des.c b/libavutil/des.c index d3f715e8fc..d65760e575 100644 --- a/libavutil/des.c +++ b/libavutil/des.c @@ -298,7 +298,7 @@ int av_des_init(AVDES *d, const uint8_t *key, int key_bits, int decrypt) { return 0; } -void av_des_crypt(AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt) { +static void av_des_crypt_mac(AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt, int mac) { uint64_t iv_val = iv ? AV_RB64(iv) : 0; while (count-- > 0) { uint64_t dst_val; @@ -321,12 +321,21 @@ void av_des_crypt(AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t } AV_WB64(dst, dst_val); src += 8; - dst += 8; + if (!mac) + dst += 8; } if (iv) AV_WB64(iv, iv_val); } +void av_des_crypt(AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt) { + av_des_crypt_mac(d, dst, src, count, iv, decrypt, 0); +} + +void av_des_mac(AVDES *d, uint8_t *dst, const uint8_t *src, int count) { + av_des_crypt_mac(d, dst, src, count, (uint8_t[8]){0}, 0, 1); +} + #ifdef TEST #undef printf #undef rand |