This module handles the conflicts between various kernel versions.
The main split, currently, is between 2.6.18 and anything newer.
---

This is 1 of 2 patches for compiling only.  I haven't tested these...
in fact, I haven't tested any of the functionality yet, since I use
a newer kernel. :-)

With these two patches applied, it should compile cleanly on both
2.6.26.5 and your kernels, but I need help testing with old kernels.

- Chris



 kernel/Makefile |    2 +-
 kernel/crypto.c |  116 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 kernel/crypto.h |   24 +++++++++++
 3 files changed, 141 insertions(+), 1 deletions(-)
 create mode 100644 kernel/crypto.c
 create mode 100644 kernel/crypto.h

diff --git a/kernel/Makefile b/kernel/Makefile
index f5227af..e29faf3 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -1,5 +1,5 @@
 obj-m = blackberry.o
-blackberry-objs := modem.o util.o init.o charge.o
+blackberry-objs := modem.o util.o init.o charge.o crypto.o
 
 all: modules
 
diff --git a/kernel/crypto.c b/kernel/crypto.c
new file mode 100644
index 0000000..f76751e
--- /dev/null
+++ b/kernel/crypto.c
@@ -0,0 +1,116 @@
+/*
+       XmBlackBerry, Copyright (C) 2008  Rick Scott <[EMAIL PROTECTED]>
+       Copyright 2008, Chris Frey, NetDirect Inc. (http://www.netdirect.ca/)
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, version 2.
+
+    This program 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 General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#include <linux/version.h>
+#include <linux/mm.h>
+#include <linux/err.h>
+#include <linux/crypto.h>
+#include <linux/usb.h>         // for info()??
+#include <linux/scatterlist.h>
+
+#include "crypto.h"
+
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
+struct crypto_hash *crypto_hash = NULL;
+struct hash_desc crypto_hash_desc;
+#else
+struct crypto_tfm *crypto_tfm = NULL;
+#endif
+
+static int sha1_available = 0;
+
+void blackberry_sha1_init(void)
+{
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
+       crypto_hash = crypto_alloc_hash("sha1", 0, CRYPTO_ALG_ASYNC);
+       if( IS_ERR(crypto_hash) )
+       {
+           info("%s(%d) - failed to load sha1", __FUNCTION__, __LINE__);
+           return;
+       }
+
+       crypto_hash_desc.tfm = crypto_hash;
+       crypto_hash_desc.flags = 0;
+
+       // success!
+       sha1_available = 1;
+
+#else
+       crypto_tfm = crypto_alloc_tfm("sha1", 0);
+       if (!crypto_tfm)
+       {
+           info("%s(%d) - failed to load sha1", __FUNCTION__, __LINE__);
+       }
+#endif
+}
+
+void blackberry_sha1_dnit(void)
+{
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
+    if (crypto_hash)
+    {
+       crypto_free_hash(crypto_hash);
+    }
+#else
+    if (crypto_tfm)
+    {
+       crypto_free_tfm(crypto_tfm);
+    }
+#endif
+}
+
+int blackberry_sha1_avail(void)                // returns 1 if sha1 is 
available
+{
+    return sha1_available;
+}
+
+unsigned int blackberry_sha1_digestsize(void)
+{
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
+    return crypto_hash_digestsize(crypto_hash);
+#else
+    return crypto_tfm_alg_digestsize(crypto_tfm);
+#endif
+}
+
+void blackberry_sha1_sum(const void *input, int len, unsigned char *hashout)
+{
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18)
+    struct scatterlist sg;
+    int ret;
+
+    sg_init_one(&sg, input, len);
+
+    ret = crypto_hash_digest(&crypto_hash_desc, &sg, len, hashout);
+    if( ret )
+    {
+       sha1_available = 0;
+       return;
+    }
+#else
+    struct scatterlist sg;
+
+    sg_init_one(&sg,
+       &device_map[blackberry_device->desktop.tty->index].password_hash[0],
+       4 + crypto_tfm_alg_digestsize(crypto_tfm));
+    crypto_digest_init(crypto_tfm);
+    crypto_digest_update(crypto_tfm, &sg, 1);
+    crypto_digest_final(crypto_tfm, &response[8]);
+#endif
+}
+
diff --git a/kernel/crypto.h b/kernel/crypto.h
new file mode 100644
index 0000000..6498654
--- /dev/null
+++ b/kernel/crypto.h
@@ -0,0 +1,24 @@
+/*
+       XmBlackBerry, Copyright (C) 2008  Rick Scott <[EMAIL PROTECTED]>
+       Copyright 2008, Chris Frey, NetDirect Inc. (http://www.netdirect.ca/)
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, version 2.
+
+    This program 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 General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+void blackberry_sha1_init(void);
+void blackberry_sha1_dnit(void);
+int blackberry_sha1_avail(void);               // returns 1 if sha1 is 
available
+unsigned int blackberry_sha1_digestsize(void);
+void blackberry_sha1_sum(const void *input, int len, unsigned char *hashout);
+
-- 
1.6.0.3


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Barry-devel mailing list
Barry-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/barry-devel

Reply via email to