Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-5]: src/sys/crypto/arc4 Pull up revision 1.1 (new, approved by ...



details:   https://anonhg.NetBSD.org/src/rev/3fdd91d8e621
branches:  netbsd-1-5
changeset: 488504:3fdd91d8e621
user:      onoe <onoe%NetBSD.org@localhost>
date:      Fri Jul 14 14:36:34 2000 +0000

description:
Pull up revision 1.1 (new, approved by thorpej)
  Add WEP support for awi driver.

diffstat:

 sys/crypto/arc4/arc4.c |  111 +++++++++++++++++++++++++++++++++++++++++++++++++
 sys/crypto/arc4/arc4.h |   40 +++++++++++++++++
 2 files changed, 151 insertions(+), 0 deletions(-)

diffs (159 lines):

diff -r ece825ffc27b -r 3fdd91d8e621 sys/crypto/arc4/arc4.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/crypto/arc4/arc4.c    Fri Jul 14 14:36:34 2000 +0000
@@ -0,0 +1,111 @@
+/*     $NetBSD: arc4.c,v 1.1.2.2 2000/07/14 14:36:34 onoe Exp $        */
+
+/*
+ * ARC4 implementation
+ *     A Stream Cipher Encryption Algorithm "Arcfour"
+ *     <draft-kaukonen-cipher-arcfour-03.txt>
+ */
+
+/*        This code illustrates a sample implementation
+ *                 of the Arcfour algorithm
+ *         Copyright (c) April 29, 1997 Kalle Kaukonen.
+ *                    All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that this copyright
+ * notice and disclaimer are retained.
+ *
+ * THIS SOFTWARE IS PROVIDED BY KALLE KAUKONEN AND CONTRIBUTORS ``AS
+ * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL KALLE
+ * KAUKONEN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+
+#include <crypto/arc4/arc4.h>
+
+struct arc4_ctx {
+       int     x;
+       int     y;
+       int     state[256];
+       /* was unsigned char, changed to int for performance -- onoe */
+};
+
+int
+arc4_ctxlen()
+{
+       return sizeof(struct arc4_ctx);
+}
+
+void
+arc4_setkey(ctxp, key, keylen)
+       void *ctxp;
+       unsigned char *key;
+       int keylen;
+{
+       struct arc4_ctx *ctx = ctxp;
+       unsigned int i, t, u, ki, si;
+       unsigned int *state;
+
+       state = ctx->state;
+       ctx->x = 0;
+       ctx->y = 0;
+       for (i = 0; i < 256; i++)
+              state[i] = i;
+       ki = si = 0;
+       for (i = 0; i < 256; i++) {
+               t = state[i];
+               si = (si + key[ki] + t) & 0xff;
+               u = state[si];
+               state[si] = t;
+               state[i] = u;
+               if (++ki >= keylen)
+                       ki = 0;
+       }
+}
+
+void
+arc4_encrypt(ctxp, dst, src, len)
+       void *ctxp;
+       unsigned char *dst;
+       unsigned char *src;
+       int len;
+{
+       struct arc4_ctx *ctx = ctxp;
+       unsigned int x, y, sx, sy;
+       unsigned int *state;
+       const unsigned char *endsrc;
+
+       state = ctx->state;
+       x = ctx->x;
+       y = ctx->y;
+       for (endsrc = src + len; src != endsrc; src++, dst++) {
+               x = (x + 1) & 0xff;
+               sx = state[x];
+               y = (sx + y) & 0xff;
+               state[x] = sy = state[y];
+               state[y] = sx;
+               *dst = *src ^ state[(sx + sy) & 0xff];
+       }
+       ctx->x = x;
+       ctx->y = y;
+}
+
+void
+arc4_decrypt(ctxp, dst, src, len)
+       void *ctxp;
+       unsigned char *dst;
+       unsigned char *src;
+       int len;
+{
+       arc4_encrypt(ctxp, dst, src, len);
+}
diff -r ece825ffc27b -r 3fdd91d8e621 sys/crypto/arc4/arc4.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/crypto/arc4/arc4.h    Fri Jul 14 14:36:34 2000 +0000
@@ -0,0 +1,40 @@
+/*     $NetBSD: arc4.h,v 1.1.2.2 2000/07/14 14:36:34 onoe Exp $        */
+
+/*
+ * ARC4 implementation
+ *     A Stream Cipher Encryption Algorithm "Arcfour"
+ *     <draft-kaukonen-cipher-arcfour-03.txt>
+ */
+
+/*        This code illustrates a sample implementation
+ *                 of the Arcfour algorithm
+ *         Copyright (c) April 29, 1997 Kalle Kaukonen.
+ *                    All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that this copyright
+ * notice and disclaimer are retained.
+ *
+ * THIS SOFTWARE IS PROVIDED BY KALLE KAUKONEN AND CONTRIBUTORS ``AS
+ * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL KALLE
+ * KAUKONEN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _CRYPTO_ARC4_H_
+#define        _CRYPTO_ARC4_H_
+
+int arc4_ctxlen __P((void));
+void arc4_setkey __P((void *, unsigned char *, int));
+void arc4_encrypt __P((void *, unsigned char *, unsigned char *, int));
+void arc4_decrypt __P((void *, unsigned char *, unsigned char *, int));
+
+#endif /* _CRYPTO_ARC4_H_ */



Home | Main Index | Thread Index | Old Index