From 684c824e9ac51ee2d6b748973757697a8ead2634 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 20 Aug 2005 07:59:00 +0000 Subject: r9421: Move arcfour code into it's own file, in lib/crypto. Andrew Bartlett (This used to be commit ca6cf462708810637544d4b4bef0f404fb89a002) --- source4/lib/crypto/arcfour.c | 92 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 source4/lib/crypto/arcfour.c (limited to 'source4/lib/crypto/arcfour.c') diff --git a/source4/lib/crypto/arcfour.c b/source4/lib/crypto/arcfour.c new file mode 100644 index 0000000000..cc5d2df567 --- /dev/null +++ b/source4/lib/crypto/arcfour.c @@ -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); +} + + -- cgit From f3f19158bb3e1307337c77f06991441f3c70a1e6 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 7 Mar 2006 16:25:28 +0000 Subject: r13953: make more functions public metze (This used to be commit 6aa9675924c32a83122e7ebe86a736233b46c54f) --- source4/lib/crypto/arcfour.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/lib/crypto/arcfour.c') diff --git a/source4/lib/crypto/arcfour.c b/source4/lib/crypto/arcfour.c index cc5d2df567..7cf6188594 100644 --- a/source4/lib/crypto/arcfour.c +++ b/source4/lib/crypto/arcfour.c @@ -24,7 +24,7 @@ #include "lib/crypto/crypto.h" /* initialise the arcfour sbox with key */ -void arcfour_init(struct arcfour_state *state, const DATA_BLOB *key) +_PUBLIC_ void arcfour_init(struct arcfour_state *state, const DATA_BLOB *key) { int ind; uint8_t j = 0; @@ -46,7 +46,7 @@ void arcfour_init(struct arcfour_state *state, const DATA_BLOB *key) } /* crypt the data with arcfour */ -void arcfour_crypt_sbox(struct arcfour_state *state, uint8_t *data, int len) +_PUBLIC_ void arcfour_crypt_sbox(struct arcfour_state *state, uint8_t *data, int len) { int ind; @@ -69,7 +69,7 @@ void arcfour_crypt_sbox(struct arcfour_state *state, uint8_t *data, int len) /* arcfour encryption with a blob key */ -void arcfour_crypt_blob(uint8_t *data, int len, const DATA_BLOB *key) +_PUBLIC_ void arcfour_crypt_blob(uint8_t *data, int len, const DATA_BLOB *key) { struct arcfour_state state; arcfour_init(&state, key); @@ -80,7 +80,7 @@ void arcfour_crypt_blob(uint8_t *data, int len, const DATA_BLOB *key) 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) +_PUBLIC_ void arcfour_crypt(uint8_t *data, const uint8_t keystr[16], int len) { DATA_BLOB key = data_blob(keystr, 16); -- cgit From 0479a2f1cbae51fcd8dbdc3c148c808421fb4d25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:07:03 +0000 Subject: r23792: convert Samba4 to GPLv3 There are still a few tidyups of old FSF addresses to come (in both s3 and s4). More commits soon. (This used to be commit fcf38a38ac691abd0fa51b89dc951a08e89fdafa) --- source4/lib/crypto/arcfour.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/crypto/arcfour.c') diff --git a/source4/lib/crypto/arcfour.c b/source4/lib/crypto/arcfour.c index 7cf6188594..94196fa1ee 100644 --- a/source4/lib/crypto/arcfour.c +++ b/source4/lib/crypto/arcfour.c @@ -7,7 +7,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ 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. + along with this program. If not, see . */ #include "includes.h" -- cgit