I hope this fixes all the issues . Supraja
On Wed, Dec 17, 2014 at 10:54 PM, Giorgio Vazzana <mywin...@gmail.com> wrote: > > Hello, > > 2014-12-17 10:27 GMT+01:00 Carl Eugen Hoyos <ceho...@ag.or.at>: > > supraja reddy <supraja0493 <at> gmail.com> writes: > > > >> -- CAST128 symmetric block cipher, ECB mode > >> +- CAST128 symmetric block cipher > > > > This line is part of the "2.5" paragraph, please > > do not change this paragraph as 2.5 was already > > released. > > > >> -void av_cast5_crypt(struct AVCAST5 *ctx, uint8_t *dst, > >> const uint8_t *src, int count, int decrypt); > >> +void av_cast5_crypt(struct AVCAST5 *ctx, uint8_t *dst, > >> const uint8_t *src, int count, uint8_t *iv, int decrypt); > > > > You cannot do this because cast5.h is an installed > > header. One possibility is to introduce a new > > function av_cast5_crypt2(). > > > >> - for (j = 0; j < 3; j++){ > >> + for (j = 0; j < 3; j++) { > > > >> - for (i = 0; i < 1000000; i++){ > >> + for (i = 0; i < 1000000; i++) { > > > > Please avoid cosmetic changes in patches that > > introduce new features: Either send another > > cosmetics-only patch or leave it as it is. > > > >> + } else { > >> + if (iv) { > >> + for (i = 0; i < 8; i++) > >> + dst[i] = src[i] ^ iv[i]; > >> + encipher(cs, dst, dst); > > > > Indentation in the new code is wrong. > > thank you Carl for the review, I agree all your points are valid. > There seems to be a bigger problem with this patch though, the IV > vector is not "propagated" correctly and thus the CBC mode would not > work. > Also, it would be nice if we could add some code in the selftest to > cover this mode too. > > Giorgio Vazzana > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel >
From 16c8db86ebf92f68a8a750dcbe5e3598a8bd69b5 Mon Sep 17 00:00:00 2001 From: Supraja Meedinti <supraja0...@gmail.com> Date: Thu, 18 Dec 2014 00:17:45 +0530 Subject: [PATCH] libavutil: Added cbc mode to cast128 Signed-off-by: Supraja Meedinti <supraja0...@gmail.com> --- libavutil/cast5.c | 40 ++++++++++++++++++++++++++++++++++++++-- libavutil/cast5.h | 14 +++++++++++++- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/libavutil/cast5.c b/libavutil/cast5.c index 14dd701..dba5b6a 100644 --- a/libavutil/cast5.c +++ b/libavutil/cast5.c @@ -416,7 +416,7 @@ static void encipher(AVCAST5* cs, uint8_t* dst, const uint8_t* src) AV_WB32(dst + 4, l); } -static void decipher(AVCAST5* cs, uint8_t* dst, const uint8_t* src) +static void decipher(AVCAST5* cs, uint8_t* dst, const uint8_t* src, uint8_t *iv) { uint32_t f, I, r, l; l = AV_RB32(src); @@ -439,6 +439,11 @@ static void decipher(AVCAST5* cs, uint8_t* dst, const uint8_t* src) F3(r, l, 3); F2(l, r, 2); F1(r, l, 1); + if (iv) { + r ^= AV_RB32(iv); + l ^= AV_RB32(iv + 4); + memcpy(iv, src, 8); + } AV_WB32(dst, r); AV_WB32(dst + 4, l); } @@ -468,11 +473,30 @@ av_cold int av_cast5_init(AVCAST5* cs, const uint8_t *key, int key_bits) return 0; } +void av_cast5_crypt2(AVCAST5* cs, uint8_t* dst, const uint8_t* src, int count, uint8_t *iv, int decrypt) +{ + int i; + while (count--) { + if (decrypt){ + decipher(cs, dst, src, iv); + } else { + if (iv) { + for (i = 0; i < 8; i++) + dst[i] = src[i] ^ iv[i]; + encipher(cs, dst, dst); + } else { + encipher(cs, dst, src); + } + } + src = src + 8; + dst = dst + 8; + } +} void av_cast5_crypt(AVCAST5* cs, uint8_t* dst, const uint8_t* src, int count, int decrypt) { while (count--) { if (decrypt){ - decipher(cs, dst, src); + decipher(cs, dst, src, NULL); } else { encipher(cs, dst, src); } @@ -504,6 +528,7 @@ int main(int argc, char** argv) {0xee, 0xa9, 0xd0, 0xa2, 0x49, 0xfd, 0x3b, 0xa6, 0xb3, 0x43, 0x6f, 0xb8, 0x9d, 0x6d, 0xca, 0x92}, {0xb2, 0xc9, 0x5e, 0xb0, 0x0c, 0x31, 0xad, 0x71, 0x80, 0xac, 0x05, 0xb8, 0xe8, 0x3d, 0x69, 0x6e} }; + uint8_t iv[8] = {0xee, 0xa9, 0xd0, 0xa2, 0x49, 0xfd, 0x3b, 0xa6}; static uint8_t rpt2[2][16]; int i, j, err = 0; static int key_bits[3] = {128, 80, 40}; @@ -547,6 +572,17 @@ int main(int argc, char** argv) } } } + for (j = 0; j < 3; j++) { + av_cast5_init(cs, Key[j], key_bits[j]); + av_cast5_crypt2(cs, temp, rpt, 1, iv, 0); + av_cast5_crypt2(cs, temp, temp, 1, iv, 1); + for (i =0; i < 8; i++) { + if (rpt[i] != temp[i]) { + av_log(NULL, AV_LOG_ERROR, "%d %02x %02x\n", i, rpt[i], temp[i]); + err = 1; + } + } + } av_free(cs); return err; } diff --git a/libavutil/cast5.h b/libavutil/cast5.h index 913d048..4a86743 100644 --- a/libavutil/cast5.h +++ b/libavutil/cast5.h @@ -52,7 +52,7 @@ struct AVCAST5 *av_cast5_alloc(void); int av_cast5_init(struct AVCAST5 *ctx, const uint8_t *key, int key_bits); /** - * Encrypt or decrypt a buffer using a previously initialized context + * Encrypt or decrypt a buffer using a previously initialized context, ECB mode only * * @param ctx an AVCAST5 context * @param dst destination array, can be equal to src @@ -61,6 +61,18 @@ int av_cast5_init(struct AVCAST5 *ctx, const uint8_t *key, int key_bits); * @param decrypt 0 for encryption, 1 for decryption */ void av_cast5_crypt(struct AVCAST5 *ctx, uint8_t *dst, const uint8_t *src, int count, int decrypt); + +/** + * Encrypt or decrypt a buffer using a previously initialized context + * + * @param ctx an AVCAST5 context + * @param dst destination array, can be equal to src + * @param src source array, can be equal to dst + * @param count number of 8 byte blocks + * @param iv initialization vector for cbc mode, NULL for ecb mode + * @param decrypt 0 for encryption, 1 for decryption + */ +void av_cast5_crypt2(struct AVCAST5 *ctx, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt); /** * @} */ -- 1.8.3.2
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel