summaryrefslogtreecommitdiff
path: root/src/libzrtpcpp/crypto/twofish_cfb.c
diff options
context:
space:
mode:
authorMark Purcell <msp@debian.org>2013-07-09 15:55:55 +0100
committerMark Purcell <msp@debian.org>2013-07-09 15:55:55 +0100
commit669109e369a1be69ff7c4108eb545eff4c5c26d9 (patch)
tree73c117a2e7dd22a7a6ee315101f6357ab43386ec /src/libzrtpcpp/crypto/twofish_cfb.c
libzrtpcpp (2.3.4-1) unstable; urgency=medium
* New upstream release - Fixes "CVE-2013-2221 CVE-2013-2222 CVE-2013-2223" (Closes: #714650) # imported from the archive
Diffstat (limited to 'src/libzrtpcpp/crypto/twofish_cfb.c')
-rwxr-xr-xsrc/libzrtpcpp/crypto/twofish_cfb.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/libzrtpcpp/crypto/twofish_cfb.c b/src/libzrtpcpp/crypto/twofish_cfb.c
new file mode 100755
index 0000000..7540738
--- /dev/null
+++ b/src/libzrtpcpp/crypto/twofish_cfb.c
@@ -0,0 +1,82 @@
+#include <stdint.h>
+#include <stdlib.h>
+
+#include "twofish.h"
+
+void Twofish_cfb128_encrypt(Twofish_key* keyCtx, Twofish_Byte* in,
+ Twofish_Byte* out, size_t len,
+ Twofish_Byte* ivec, int32_t *num)
+{
+ uint32_t n;
+
+ n = *num;
+
+ do {
+ while (n && len) {
+ *(out++) = ivec[n] ^= *(in++);
+ --len;
+ n = (n+1) % 16;
+ }
+ while (len>=16) {
+ Twofish_encrypt(keyCtx, ivec, ivec);
+ for (n=0; n<16; n+=sizeof(size_t)) {
+ *(size_t*)(out+n) =
+ *(size_t*)(ivec+n) ^= *(size_t*)(in+n);
+ }
+ len -= 16;
+ out += 16;
+ in += 16;
+ }
+ n = 0;
+ if (len) {
+ Twofish_encrypt(keyCtx, ivec, ivec);
+ while (len--) {
+ out[n] = ivec[n] ^= in[n];
+ ++n;
+ }
+ }
+ *num = n;
+ return;
+ } while (0);
+}
+
+
+void Twofish_cfb128_decrypt(Twofish_key* keyCtx, Twofish_Byte* in,
+ Twofish_Byte* out, size_t len,
+ Twofish_Byte* ivec, int32_t *num)
+{
+ uint32_t n;
+
+ n = *num;
+
+ do {
+ while (n && len) {
+ unsigned char c;
+ *(out++) = ivec[n] ^ (c = *(in++)); ivec[n] = c;
+ --len;
+ n = (n+1) % 16;
+ }
+ while (len>=16) {
+ Twofish_encrypt(keyCtx, ivec, ivec);
+ for (n=0; n<16; n+=sizeof(size_t)) {
+ size_t t = *(size_t*)(in+n);
+ *(size_t*)(out+n) = *(size_t*)(ivec+n) ^ t;
+ *(size_t*)(ivec+n) = t;
+ }
+ len -= 16;
+ out += 16;
+ in += 16;
+ }
+ n = 0;
+ if (len) {
+ Twofish_encrypt(keyCtx, ivec, ivec);
+ while (len--) {
+ unsigned char c;
+ out[n] = ivec[n] ^ (c = in[n]); ivec[n] = c;
+ ++n;
+ }
+ }
+ *num = n;
+ return;
+ } while (0);
+}