Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libcrypt hrink the Blowfish routines down to only what w...
details: https://anonhg.NetBSD.org/src/rev/7e85ccdbade6
branches: trunk
changeset: 545849:7e85ccdbade6
user: thorpej <thorpej%NetBSD.org@localhost>
date: Thu Apr 17 00:31:04 2003 +0000
description:
hrink the Blowfish routines down to only what we need for __bcrypt(),
and don't export any of the Blowfish functionality outside bcrypt.c.
diffstat:
lib/libcrypt/Makefile | 4 +-
lib/libcrypt/bcrypt.c | 4 +-
lib/libcrypt/blf.h | 82 ---------------
lib/libcrypt/blowfish.c | 257 +++++------------------------------------------
4 files changed, 36 insertions(+), 311 deletions(-)
diffs (truncated from 446 to 300 lines):
diff -r 6ed2ea09ed0a -r 7e85ccdbade6 lib/libcrypt/Makefile
--- a/lib/libcrypt/Makefile Thu Apr 17 00:29:43 2003 +0000
+++ b/lib/libcrypt/Makefile Thu Apr 17 00:31:04 2003 +0000
@@ -1,10 +1,10 @@
-# $NetBSD: Makefile,v 1.13 2002/08/19 14:55:15 lukem Exp $
+# $NetBSD: Makefile,v 1.14 2003/04/17 00:31:04 thorpej Exp $
USE_SHLIBDIR= yes
LIB= crypt
-SRCS= crypt.c md5crypt.c bcrypt.c blowfish.c
+SRCS= crypt.c md5crypt.c bcrypt.c
CPPFLAGS+= -I${.CURDIR}
diff -r 6ed2ea09ed0a -r 7e85ccdbade6 lib/libcrypt/bcrypt.c
--- a/lib/libcrypt/bcrypt.c Thu Apr 17 00:29:43 2003 +0000
+++ b/lib/libcrypt/bcrypt.c Thu Apr 17 00:31:04 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bcrypt.c,v 1.1 2002/05/24 04:02:49 itojun Exp $ */
+/* $NetBSD: bcrypt.c,v 1.2 2003/04/17 00:31:04 thorpej Exp $ */
/* $OpenBSD: bcrypt.c,v 1.16 2002/02/19 19:39:36 millert Exp $ */
/*
@@ -56,7 +56,7 @@
#include <string.h>
#include <pwd.h>
-#include "blf.h"
+#include "blowfish.c"
/* This implementation is adaptable to current computing power.
* You can have up to 2^31 rounds which should be enough for some
diff -r 6ed2ea09ed0a -r 7e85ccdbade6 lib/libcrypt/blf.h
--- a/lib/libcrypt/blf.h Thu Apr 17 00:29:43 2003 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,82 +0,0 @@
-/* $NetBSD: blf.h,v 1.1 2002/05/24 04:02:49 itojun Exp $ */
-/* $OpenBSD: blf.h,v 1.6 2002/02/16 21:27:17 millert Exp $ */
-/*
- * Blowfish - a fast block cipher designed by Bruce Schneier
- *
- * Copyright 1997 Niels Provos <provos%physnet.uni-hamburg.de@localhost>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Niels Provos.
- * 4. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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 _BLF_H_
-#define _BLF_H_
-
-/* Schneier specifies a maximum key length of 56 bytes.
- * This ensures that every key bit affects every cipher
- * bit. However, the subkeys can hold up to 72 bytes.
- * Warning: For normal blowfish encryption only 56 bytes
- * of the key affect all cipherbits.
- */
-
-#define BLF_N 16 /* Number of Subkeys */
-#define BLF_MAXKEYLEN ((BLF_N-2)*4) /* 448 bits */
-
-/* Blowfish context */
-typedef struct BlowfishContext {
- u_int32_t S[4][256]; /* S-Boxes */
- u_int32_t P[BLF_N + 2]; /* Subkeys */
-} blf_ctx;
-
-/* Raw access to customized Blowfish
- * blf_key is just:
- * Blowfish_initstate( state )
- * Blowfish_expand0state( state, key, keylen )
- */
-
-void Blowfish_encipher(blf_ctx *, u_int32_t *, u_int32_t *);
-void Blowfish_decipher(blf_ctx *, u_int32_t *, u_int32_t *);
-void Blowfish_initstate(blf_ctx *);
-void Blowfish_expand0state(blf_ctx *, const u_int8_t *, u_int16_t);
-void Blowfish_expandstate
-(blf_ctx *, const u_int8_t *, u_int16_t, const u_int8_t *, u_int16_t);
-
-/* Standard Blowfish */
-
-void blf_key(blf_ctx *, const u_int8_t *, u_int16_t);
-void blf_enc(blf_ctx *, u_int32_t *, u_int16_t);
-void blf_dec(blf_ctx *, u_int32_t *, u_int16_t);
-
-void blf_ecb_encrypt(blf_ctx *, u_int8_t *, u_int32_t);
-void blf_ecb_decrypt(blf_ctx *, u_int8_t *, u_int32_t);
-
-void blf_cbc_encrypt(blf_ctx *, u_int8_t *, u_int8_t *, u_int32_t);
-void blf_cbc_decrypt(blf_ctx *, u_int8_t *, u_int8_t *, u_int32_t);
-
-/* Converts u_int8_t to u_int32_t */
-u_int32_t Blowfish_stream2word(const u_int8_t *, u_int16_t , u_int16_t *);
-
-#endif
diff -r 6ed2ea09ed0a -r 7e85ccdbade6 lib/libcrypt/blowfish.c
--- a/lib/libcrypt/blowfish.c Thu Apr 17 00:29:43 2003 +0000
+++ b/lib/libcrypt/blowfish.c Thu Apr 17 00:31:04 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: blowfish.c,v 1.1 2002/05/24 04:02:49 itojun Exp $ */
+/* $NetBSD: blowfish.c,v 1.2 2003/04/17 00:31:04 thorpej Exp $ */
/* $OpenBSD: blowfish.c,v 1.16 2002/02/19 19:39:36 millert Exp $ */
/*
* Blowfish block cipher for OpenBSD
@@ -40,13 +40,29 @@
* Bruce Schneier.
*/
-#if 0
-#include <stdio.h> /* used for debugging */
-#include <string.h>
-#endif
+/*
+ * Note: This has been trimmed down to only what is needed by
+ * __bcrypt(). Also note that this file is actually included
+ * directly by bcrypt.c, not built separately.
+ */
#include <sys/types.h>
-#include "blf.h"
+
+/* Schneier specifies a maximum key length of 56 bytes.
+ * This ensures that every key bit affects every cipher
+ * bit. However, the subkeys can hold up to 72 bytes.
+ * Warning: For normal blowfish encryption only 56 bytes
+ * of the key affect all cipherbits.
+ */
+
+#define BLF_N 16 /* Number of Subkeys */
+#define BLF_MAXKEYLEN ((BLF_N-2)*4) /* 448 bits */
+
+/* Blowfish context */
+typedef struct BlowfishContext {
+ u_int32_t S[4][256]; /* S-Boxes */
+ u_int32_t P[BLF_N + 2]; /* Subkeys */
+} blf_ctx;
#undef inline
#ifdef __GNUC__
@@ -64,11 +80,8 @@
#define BLFRND(s,p,i,j,n) (i ^= F(s,j) ^ (p)[n])
-void
-Blowfish_encipher(c, xl, xr)
- blf_ctx *c;
- u_int32_t *xl;
- u_int32_t *xr;
+static void
+Blowfish_encipher(blf_ctx *c, u_int32_t *xl, u_int32_t *xr)
{
u_int32_t Xl;
u_int32_t Xr;
@@ -92,42 +105,13 @@
*xr = Xl;
}
-void
-Blowfish_decipher(c, xl, xr)
- blf_ctx *c;
- u_int32_t *xl;
- u_int32_t *xr;
-{
- u_int32_t Xl;
- u_int32_t Xr;
- u_int32_t *s = c->S[0];
- u_int32_t *p = c->P;
-
- Xl = *xl;
- Xr = *xr;
-
- Xl ^= p[17];
- BLFRND(s, p, Xr, Xl, 16); BLFRND(s, p, Xl, Xr, 15);
- BLFRND(s, p, Xr, Xl, 14); BLFRND(s, p, Xl, Xr, 13);
- BLFRND(s, p, Xr, Xl, 12); BLFRND(s, p, Xl, Xr, 11);
- BLFRND(s, p, Xr, Xl, 10); BLFRND(s, p, Xl, Xr, 9);
- BLFRND(s, p, Xr, Xl, 8); BLFRND(s, p, Xl, Xr, 7);
- BLFRND(s, p, Xr, Xl, 6); BLFRND(s, p, Xl, Xr, 5);
- BLFRND(s, p, Xr, Xl, 4); BLFRND(s, p, Xl, Xr, 3);
- BLFRND(s, p, Xr, Xl, 2); BLFRND(s, p, Xl, Xr, 1);
-
- *xl = Xr ^ p[0];
- *xr = Xl;
-}
-
-void
-Blowfish_initstate(c)
- blf_ctx *c;
+static void
+Blowfish_initstate(blf_ctx *c)
{
/* P-box and S-box tables initialized with digits of Pi */
- const blf_ctx initstate =
+ static const blf_ctx init_state =
{ {
{
@@ -399,11 +383,11 @@
0x9216d5d9, 0x8979fb1b
} };
- *c = initstate;
+ *c = init_state;
}
-u_int32_t
+static u_int32_t
Blowfish_stream2word(const u_int8_t *data, u_int16_t databytes, u_int16_t *current)
{
u_int8_t i;
@@ -423,7 +407,7 @@
return temp;
}
-void
+static void
Blowfish_expand0state(blf_ctx *c, const u_int8_t *key, u_int16_t keybytes)
{
u_int16_t i;
@@ -461,7 +445,7 @@
}
-void
+static void
Blowfish_expandstate(blf_ctx *c, const u_int8_t *data, u_int16_t databytes,
const u_int8_t *key, u_int16_t keybytes)
{
@@ -504,17 +488,7 @@
}
-void
-blf_key(blf_ctx *c, const u_int8_t *k, u_int16_t len)
-{
- /* Initialize S-boxes and subkeys with Pi */
- Blowfish_initstate(c);
-
- /* Transform S-boxes and subkeys with key */
- Blowfish_expand0state(c, k, len);
-}
-
-void
+static void
blf_enc(blf_ctx *c, u_int32_t *data, u_int16_t blocks)
{
u_int32_t *d;
@@ -526,170 +500,3 @@
d += 2;
}
}
-
-void
-blf_dec(blf_ctx *c, u_int32_t *data, u_int16_t blocks)
-{
- u_int32_t *d;
- u_int16_t i;
-
- d = data;
- for (i = 0; i < blocks; i++) {
- Blowfish_decipher(c, d, d + 1);
- d += 2;
- }
-}
-
-void
-blf_ecb_encrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
-{
- u_int32_t l, r;
- u_int32_t i;
-
- for (i = 0; i < len; i += 8) {
Home |
Main Index |
Thread Index |
Old Index