svn commit: samba r9421 - in branches/SAMBA_4_0/source: lib
lib/crypto libcli/util
abartlet at samba.org
abartlet at samba.org
Sat Aug 20 07:59:01 GMT 2005
Author: abartlet
Date: 2005-08-20 07:59:00 +0000 (Sat, 20 Aug 2005)
New Revision: 9421
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=9421
Log:
Move arcfour code into it's own file, in lib/crypto.
Andrew Bartlett
Added:
branches/SAMBA_4_0/source/lib/crypto/arcfour.c
Modified:
branches/SAMBA_4_0/source/lib/basic.mk
branches/SAMBA_4_0/source/lib/crypto/crypto.h
branches/SAMBA_4_0/source/lib/crypto/hmacmd5.h
branches/SAMBA_4_0/source/libcli/util/smbdes.c
Changeset:
Modified: branches/SAMBA_4_0/source/lib/basic.mk
===================================================================
--- branches/SAMBA_4_0/source/lib/basic.mk 2005-08-20 07:31:29 UTC (rev 9420)
+++ branches/SAMBA_4_0/source/lib/basic.mk 2005-08-20 07:59:00 UTC (rev 9421)
@@ -22,7 +22,8 @@
ADD_OBJ_FILES = \
lib/crypto/md5.o \
lib/crypto/hmacmd5.o \
- lib/crypto/md4.o
+ lib/crypto/md4.o \
+ lib/crypto/arcfour.o
# End SUBSYSTEM LIBCRYPTO
##############################
Added: branches/SAMBA_4_0/source/lib/crypto/arcfour.c
===================================================================
--- branches/SAMBA_4_0/source/lib/crypto/arcfour.c 2005-08-20 07:31:29 UTC (rev 9420)
+++ branches/SAMBA_4_0/source/lib/crypto/arcfour.c 2005-08-20 07:59:00 UTC (rev 9421)
@@ -0,0 +1,92 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ An implementation of the arcfour algorithm
+
+ Copyright (C) Andrew Tridgell 1998
+
+ 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; either version 2 of the License, or
+ (at your option) any later version.
+
+ 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+#include "lib/crypto/crypto.h"
+
+/* initialise the arcfour sbox with key */
+void arcfour_init(struct arcfour_state *state, const DATA_BLOB *key)
+{
+ int ind;
+ uint8_t j = 0;
+ for (ind = 0; ind < sizeof(state->sbox); ind++) {
+ state->sbox[ind] = (uint8_t)ind;
+ }
+
+ for (ind = 0; ind < sizeof(state->sbox); ind++) {
+ uint8_t tc;
+
+ j += (state->sbox[ind] + key->data[ind%key->length]);
+
+ tc = state->sbox[ind];
+ state->sbox[ind] = state->sbox[j];
+ state->sbox[j] = tc;
+ }
+ state->index_i = 0;
+ state->index_j = 0;
+}
+
+/* crypt the data with arcfour */
+void arcfour_crypt_sbox(struct arcfour_state *state, uint8_t *data, int len)
+{
+ int ind;
+
+ for (ind = 0; ind < len; ind++) {
+ uint8_t tc;
+ uint8_t t;
+
+ state->index_i++;
+ state->index_j += state->sbox[state->index_i];
+
+ tc = state->sbox[state->index_i];
+ state->sbox[state->index_i] = state->sbox[state->index_j];
+ state->sbox[state->index_j] = tc;
+
+ t = state->sbox[state->index_i] + state->sbox[state->index_j];
+ data[ind] = data[ind] ^ state->sbox[t];
+ }
+}
+
+/*
+ arcfour encryption with a blob key
+*/
+void arcfour_crypt_blob(uint8_t *data, int len, const DATA_BLOB *key)
+{
+ struct arcfour_state state;
+ arcfour_init(&state, key);
+ arcfour_crypt_sbox(&state, data, len);
+}
+
+/*
+ a variant that assumes a 16 byte key. This should be removed
+ when the last user is gone
+*/
+void arcfour_crypt(uint8_t *data, const uint8_t keystr[16], int len)
+{
+ DATA_BLOB key = data_blob(keystr, 16);
+
+ arcfour_crypt_blob(data, len, &key);
+
+ data_blob_free(&key);
+}
+
+
Modified: branches/SAMBA_4_0/source/lib/crypto/crypto.h
===================================================================
--- branches/SAMBA_4_0/source/lib/crypto/crypto.h 2005-08-20 07:31:29 UTC (rev 9420)
+++ branches/SAMBA_4_0/source/lib/crypto/crypto.h 2005-08-20 07:59:00 UTC (rev 9421)
@@ -28,3 +28,9 @@
uint8_t index_i;
uint8_t index_j;
};
+
+void arcfour_init(struct arcfour_state *state, const DATA_BLOB *key);
+void arcfour_crypt_sbox(struct arcfour_state *state, uint8_t *data, int len);
+void arcfour_crypt_blob(uint8_t *data, int len, const DATA_BLOB *key);
+void arcfour_crypt(uint8_t *data, const uint8_t keystr[16], int len);
+
Modified: branches/SAMBA_4_0/source/lib/crypto/hmacmd5.h
===================================================================
--- branches/SAMBA_4_0/source/lib/crypto/hmacmd5.h 2005-08-20 07:31:29 UTC (rev 9420)
+++ branches/SAMBA_4_0/source/lib/crypto/hmacmd5.h 2005-08-20 07:59:00 UTC (rev 9421)
@@ -1,6 +1,6 @@
/*
Unix SMB/CIFS implementation.
- Interface header: Scheduler service
+ Interface header: HMAC MD5 code
Copyright (C) Luke Kenneth Casson Leighton 1996-1999
Copyright (C) Andrew Tridgell 1992-1999
Modified: branches/SAMBA_4_0/source/libcli/util/smbdes.c
===================================================================
--- branches/SAMBA_4_0/source/libcli/util/smbdes.c 2005-08-20 07:31:29 UTC (rev 9420)
+++ branches/SAMBA_4_0/source/libcli/util/smbdes.c 2005-08-20 07:59:00 UTC (rev 9421)
@@ -365,73 +365,6 @@
des_crypt56(out + 8, in + 8, key+7, forw);
}
-/* initialise the arcfour sbox with key */
-void arcfour_init(struct arcfour_state *state, const DATA_BLOB *key)
-{
- int ind;
- uint8_t j = 0;
- for (ind = 0; ind < sizeof(state->sbox); ind++) {
- state->sbox[ind] = (uint8_t)ind;
- }
-
- for (ind = 0; ind < sizeof(state->sbox); ind++) {
- uint8_t tc;
-
- j += (state->sbox[ind] + key->data[ind%key->length]);
-
- tc = state->sbox[ind];
- state->sbox[ind] = state->sbox[j];
- state->sbox[j] = tc;
- }
- state->index_i = 0;
- state->index_j = 0;
-}
-
-/* crypt the data with arcfour */
-void arcfour_crypt_sbox(struct arcfour_state *state, uint8_t *data, int len)
-{
- int ind;
-
- for (ind = 0; ind < len; ind++) {
- uint8_t tc;
- uint8_t t;
-
- state->index_i++;
- state->index_j += state->sbox[state->index_i];
-
- tc = state->sbox[state->index_i];
- state->sbox[state->index_i] = state->sbox[state->index_j];
- state->sbox[state->index_j] = tc;
-
- t = state->sbox[state->index_i] + state->sbox[state->index_j];
- data[ind] = data[ind] ^ state->sbox[t];
- }
-}
-
-/*
- arcfour encryption with a blob key
-*/
-void arcfour_crypt_blob(uint8_t *data, int len, const DATA_BLOB *key)
-{
- struct arcfour_state state;
- arcfour_init(&state, key);
- arcfour_crypt_sbox(&state, data, len);
-}
-
-/*
- a variant that assumes a 16 byte key. This should be removed
- when the last user is gone
-*/
-void arcfour_crypt(uint8_t *data, const uint8_t keystr[16], int len)
-{
- DATA_BLOB key = data_blob(keystr, 16);
-
- arcfour_crypt_blob(data, len, &key);
-
- data_blob_free(&key);
-}
-
-
/* Decode a sam password hash into a password. The password hash is the
same method used to store passwords in the NT registry. The DES key
used is based on the RID of the user. */
More information about the samba-cvs
mailing list