diff options
author | sje <sje@4f64403b-2f21-0410-a795-97e2b3489a10> | 2007-06-28 08:34:59 +0000 |
---|---|---|
committer | sje <sje@4f64403b-2f21-0410-a795-97e2b3489a10> | 2007-06-28 08:34:59 +0000 |
commit | 6c417a45f25de9480ef200177c7bed0f4782eb19 (patch) | |
tree | f49a12a076e5fa20a95430998816a92fb741ebee /MySpace/arc4.cpp | |
parent | 81a69c4c216350d48d962ac43fea3108498bbf33 (diff) |
git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@219 4f64403b-2f21-0410-a795-97e2b3489a10
Diffstat (limited to 'MySpace/arc4.cpp')
-rw-r--r-- | MySpace/arc4.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/MySpace/arc4.cpp b/MySpace/arc4.cpp new file mode 100644 index 0000000..7060437 --- /dev/null +++ b/MySpace/arc4.cpp @@ -0,0 +1,52 @@ +#include "common.h"
+#include "arc4.h"
+
+void swap(char *b1, char *b2) {
+ char b = *b1;
+ *b1 = *b2;
+ *b2 = b;
+}
+
+void arc4_init(mir_arc4_ctx *ctx, char *key, int keylen) {
+ int i;
+ for(i = 0; i < 256; i++)
+ ctx->lookup[i] = i;
+
+ ctx->x = 0;
+ for(i = 0; i < 256; i++) {
+ ctx->x = (key[i % keylen] + ctx->lookup[i] + ctx->x) & 0xFF;
+ swap(&ctx->lookup[ctx->x], &ctx->lookup[i]);
+ }
+ ctx->x = 0;
+ ctx->y = 0;
+}
+
+void arc4_crypt(mir_arc4_ctx *ctx, char *dataIn, char *dataOut, int datalen) {
+ for(int i = 0; i < datalen; i++) {
+ ctx->x = (ctx->x + 1) & 0xFF;
+ ctx->y = (ctx->lookup[ctx->x] + ctx->y) & 0xFF;
+ swap(&ctx->lookup[ctx->x], &ctx->lookup[ctx->y]);
+ dataOut[i] = (dataIn[i] ^ ctx->lookup[(ctx->lookup[ctx->x] + ctx->lookup[ctx->y]) & 0xFF]);
+ }
+}
+
+int GetARC4Interface(WPARAM wParam, LPARAM lParam) {
+ struct ARC4_INTERFACE *arc4i = (struct ARC4_INTERFACE*) lParam;
+ if ( arc4i == NULL )
+ return 1;
+ if ( arc4i->cbSize != sizeof( struct ARC4_INTERFACE ))
+ return 1;
+
+ arc4i->arc4_init = arc4_init;
+ arc4i->arc4_crypt = arc4_crypt;
+ return 0;
+}
+
+HANDLE hService;
+void InitARC4Module() {
+ hService = CreateServiceFunction(MS_SYSTEM_GET_ARC4I, GetARC4Interface);
+}
+
+void DeinitARC4Module() {
+ DestroyServiceFunction(hService);
+}
|