On Tue, 3 Jul 2012, Samuel Pitoiset wrote:
+void av_xtea_init(AVXTEA *x, const uint8_t key[16])
+{
+ int i;
+
+ for (i = 0; i < 4; i++)
+ x->key[i] = AV_RB32(key + (i << 2));
+}
+
+static void av_xtea_crypt_ecb(AVXTEA *x, uint8_t *dst, const uint8_t *src,
+ int decrypt)
You can drop the av_ prefix now that it's a static function
+{
+ uint32_t v0, v1;
+ int i;
+
+ v0 = AV_RB32(src);
+ v1 = AV_RB32(src + 4);
+
+ if (decrypt) {
+ uint32_t delta = 0x9E3779B9, sum = delta * 32;
+
+ for (i = 0; i < 32; i++) {
+ v1 -= (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + x->key[(sum >> 11) &
3]);
+ sum -= delta;
+ v0 -= (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + x->key[sum & 3]);
+ }
+ } else {
+ uint32_t sum = 0, delta = 0x9E3779B9;
+
+ for (i = 0; i < 32; i++) {
+ v0 += (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + x->key[sum & 3]);
+ sum += delta;
+ v1 += (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + x->key[(sum >> 11) &
3]);
+ }
+ }
+
+ AV_WB32(dst, v0);
+ AV_WB32(dst + 4, v1);
+}
+
+void av_xtea_crypt(AVXTEA *x, uint8_t *dst, const uint8_t *src, int count,
+ uint8_t *iv, int decrypt)
+{
+ int i;
+
+ while (count > 0) {
+ if (decrypt) {
+ av_xtea_crypt_ecb(x, dst, src, decrypt);
+
+ if (iv) {
+ for (i = 0; i < 8; i++)
+ dst[i] = dst[i] ^ iv[i];
+ memcpy(iv, src, 8);
+ }
+ } else {
+ if (iv) {
+ for (i = 0; i < 8; i++)
+ dst[i] = src[i] ^ iv[i];
+ src = dst;
+ }
+
+ av_xtea_crypt_ecb(x, dst, src, decrypt);
+
+ if (iv)
+ memcpy(iv, dst, 8);
+ }
This doesn't look like it does the right thing for encryption. After the
first round, src points to dst, so when you encrypt the second block, it
will read that input data from the (potentially uninitialized) dst array,
not from the input plaintext.
// Martin
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel