summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuo Jinghua <sunmoon1997@gmail.com>2009-11-08 19:17:05 +0800
committerLuo Jinghua <sunmoon1997@gmail.com>2009-11-08 19:17:05 +0800
commit12282325cf4ce0e65c563a6055a28a8cdc457450 (patch)
tree331eae239f9b2d1c18e64944737c3e573afb7755
parent2c51d92c28a4d4fa8cf7f628416f33a2d664cf7f (diff)
milkway: add blowfish ecb ecrypt/decrypt
-rw-r--r--milkway/blowfish.c52
-rw-r--r--milkway/blowfish.h10
2 files changed, 61 insertions, 1 deletions
diff --git a/milkway/blowfish.c b/milkway/blowfish.c
index ced70ae..5163b4f 100644
--- a/milkway/blowfish.c
+++ b/milkway/blowfish.c
@@ -455,4 +455,56 @@ void BlowfishInit(BlowfishContext *ctx, unsigned char *key, int keyLen)
}
}
+#define n2l(c,l) (l = ((mw_uint32_t)(*((c)++))) << 24L, \
+ l |= ((mw_uint32_t)(*((c)++))) << 16L, \
+ l |= ((mw_uint32_t)(*((c)++))) << 8L, \
+ l |= ((mw_uint32_t)(*((c)++))))
+
+#define l2n(l,c) (*((c)++) = (mw_uint8_t)(((l) >> 24L) & 0xff), \
+ *((c)++) = (mw_uint8_t)(((l) >> 16L) & 0xff), \
+ *((c)++) = (mw_uint8_t)(((l) >> 8L) & 0xff), \
+ *((c)++) = (mw_uint8_t)(((l) ) & 0xff))
+
+void BlowfishEcbEncrypt(BlowfishContext *ctx,
+ const unsigned char *in,
+ unsigned char *out)
+{
+ mw_uint32_t l,d [2];
+
+ n2l(in, l);
+ d[0] = l;
+
+ n2l(in, l);
+ d[1] = l;
+
+ BlowfishEncrypt(ctx, &d[0], &d[1]);
+
+ l = d[0];
+ l2n(l, out);
+
+ l = d[1];
+ l2n(l, out);
+ l = d[0] = d[1] = 0;
+}
+void BlowfishEcbDecrypt(BlowfishContext *ctx,
+ const unsigned char *in,
+ unsigned char *out)
+{
+ mw_uint32_t l,d [2];
+
+ n2l(in, l);
+ d[0] = l;
+
+ n2l(in, l);
+ d[1] = l;
+
+ BlowfishDecrypt(ctx, &d[0], &d[1]);
+
+ l = d[0];
+ l2n(l, out);
+
+ l = d[1];
+ l2n(l, out);
+ l = d[0] = d[1] = 0;
+}
diff --git a/milkway/blowfish.h b/milkway/blowfish.h
index 2237a67..7593b24 100644
--- a/milkway/blowfish.h
+++ b/milkway/blowfish.h
@@ -36,6 +36,14 @@ BlowfishEncrypt(BlowfishContext *ctx, mw_uint32_t *xl, mw_uint32_t *xr);
mw_private void
BlowfishDecrypt(BlowfishContext *ctx, mw_uint32_t *xl, mw_uint32_t *xr);
-#endif
+mw_private void
+BlowfishEcbEncrypt(BlowfishContext *ctx,
+ const unsigned char *in,
+ unsigned char *out);
+mw_private void
+BlowfishEcbDecrypt(BlowfishContext *ctx,
+ const unsigned char *in,
+ unsigned char *out);
+#endif