On Mon, 2 Jul 2012, Samuel Pitoiset wrote:
diff --git a/libavutil/blowfish.h b/libavutil/blowfish.h
new file mode 100644
index 0000000..9931c36
--- /dev/null
+++ b/libavutil/blowfish.h
@@ -0,0 +1,68 @@
+/*
+ * Blowfish algorithm
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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,
+ * 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_BLOWFISH_H
+#define AVUTIL_BLOWFISH_H
+
+#include <stdint.h>
+
+#define AV_BF_ROUNDS 16
+
+typedef struct AVBlowfish {
+ uint32_t p[AV_BF_ROUNDS + 2];
+ uint32_t s[4][256];
+} AVBlowfish;
+
+/**
+ * @brief Initializes an AVBlowfish context.
+ *
+ * @param bf an AVBlowfish context
+ * @param key a key
+ * @param key_len length of the key
+ */
+void av_blowfish_init(struct AVBlowfish *bf, const uint8_t *key, int key_len);
+
+/**
+ * @brief Encrypts using the Blowfish algorithm.
+ *
+ * This function encrypts block of eight bytes passed as two 32-bit integers.
+ *
+ * @param bf an AVBlowfish context
+ * @param xl left four bytes halves of input to be encrypted
+ * @param xr right four bytes halves of input to be encrypted
+ * @param count number of 8-byte blocks
+ */
+void av_blowfish_encrypt(struct AVBlowfish *bf, uint32_t *xl, uint32_t *xr,
+ int count);
+
+/**
+ * @brief Decrypts using the Blowfish algorithm.
+ *
+ * This function decrypts block of eight bytes passed as two 32-bit integers.
+ *
+ * @param bf an AVBlowfish context
+ * @param xl left four bytes halves of input to be decrypted
+ * @param xr right four bytes halves of input to be decrypted
+ * @param count number of 8-byte blocks
+ */
+void av_blowfish_decrypt(struct AVBlowfish *bf, uint32_t *xl, uint32_t *xr,
+ int count);
While blowfish internally deals with data in form of two uint32_ts, this
doesn't say anything about how data should be interpreted if I've got one
or more blocks of bytes that I want to encrypt with ECB/CBC.
In those cases, a block of 8 bytes should be treated as 2 big endian
words, which actually is contrary to what Adobe does in RTMPE.
To make this explicit, it might be good to add a normal ECB/CBC function
just as for AES and XTEA for this cipher, too. This is useful for
interaction with normal systems, while the internal blowfish encryption
routines that deal with uint32_ts are useful for anyone where a protocol
does something weird/different (like RTMPE).
As a test for blowfish ECB, if you use the key
"abcdefghijklmnopqrstuvwxyz" (26 bytes) and encrypt the 8 byte string
"BLOWFISH", you should end up with 0x32 0x4E 0xD0 0xFE 0xF4 0x13 0xA2
0x03. (This test is taken from nettle, which has taken it from GnuPG.)
// Martin
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel