summaryrefslogtreecommitdiff
path: root/source4/libcli/util
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2005-04-25 08:26:53 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:11:39 -0500
commit0501a440bedde5e867e461d266aafe666be53e54 (patch)
tree45652fd169b546fe4691f696d3d22a1c2777df46 /source4/libcli/util
parent874cd2db86e7feb82eedd2b436c5c301d3cbe5fa (diff)
downloadsamba-0501a440bedde5e867e461d266aafe666be53e54.tar.gz
samba-0501a440bedde5e867e461d266aafe666be53e54.tar.bz2
samba-0501a440bedde5e867e461d266aafe666be53e54.zip
r6462: Move the arcfour sbox state into it's own structure, and allocate it
with talloc() for the NTLMSSP system. Andrew Bartlett (This used to be commit 7a93ac49c28d433ccf0f077294f473fe728b9995)
Diffstat (limited to 'source4/libcli/util')
-rw-r--r--source4/libcli/util/smbdes.c48
1 files changed, 22 insertions, 26 deletions
diff --git a/source4/libcli/util/smbdes.c b/source4/libcli/util/smbdes.c
index 016bd59501..d214d4cfe4 100644
--- a/source4/libcli/util/smbdes.c
+++ b/source4/libcli/util/smbdes.c
@@ -22,6 +22,7 @@
*/
#include "includes.h"
+#include "lib/crypto/crypto.h"
/* NOTES:
@@ -365,51 +366,46 @@ void des_crypt112_16(uint8_t out[16], uint8_t in[16], const uint8_t key[14], int
}
/* initialise the arcfour sbox with key */
-void arcfour_init(uint8_t s_box[258], const DATA_BLOB *key)
+void arcfour_init(struct arcfour_state *state, const DATA_BLOB *key)
{
int ind;
uint8_t j = 0;
- for (ind = 0; ind < 256; ind++) {
- s_box[ind] = (uint8_t)ind;
+ for (ind = 0; ind < sizeof(state->sbox); ind++) {
+ state->sbox[ind] = (uint8_t)ind;
}
- for (ind = 0; ind < 256; ind++) {
+ for (ind = 0; ind < sizeof(state->sbox); ind++) {
uint8_t tc;
- j += (s_box[ind] + key->data[ind%key->length]);
+ j += (state->sbox[ind] + key->data[ind%key->length]);
- tc = s_box[ind];
- s_box[ind] = s_box[j];
- s_box[j] = tc;
+ tc = state->sbox[ind];
+ state->sbox[ind] = state->sbox[j];
+ state->sbox[j] = tc;
}
- s_box[256] = 0; /* i */
- s_box[257] = 0; /* j */
-
+ state->index_i = 0;
+ state->index_j = 0;
}
/* crypt the data with arcfour */
-void arcfour_crypt_sbox(uint8_t s_box[258], uint8_t *data, int len)
+void arcfour_crypt_sbox(struct arcfour_state *state, uint8_t *data, int len)
{
- uint8_t index_i = s_box[256];
- uint8_t index_j = s_box[257];
int ind;
for (ind = 0; ind < len; ind++) {
uint8_t tc;
uint8_t t;
- index_i++;
- index_j += s_box[index_i];
+ state->index_i++;
+ state->index_j += state->sbox[state->index_i];
- tc = s_box[index_i];
- s_box[index_i] = s_box[index_j];
- s_box[index_j] = tc;
+ tc = state->sbox[state->index_i];
+ state->sbox[state->index_i] = state->sbox[state->index_j];
+ state->sbox[state->index_j] = tc;
- t = s_box[index_i] + s_box[index_j];
- data[ind] = data[ind] ^ s_box[t];
+ t = state->sbox[state->index_i] + state->sbox[state->index_j];
+ data[ind] = data[ind] ^ state->sbox[t];
}
- s_box[256] = index_i;
- s_box[257] = index_j;
}
/*
@@ -417,9 +413,9 @@ void arcfour_crypt_sbox(uint8_t s_box[258], uint8_t *data, int len)
*/
void arcfour_crypt_blob(uint8_t *data, int len, const DATA_BLOB *key)
{
- uint8_t s_box[258];
- arcfour_init(s_box, key);
- arcfour_crypt_sbox(s_box, data, len);
+ struct arcfour_state state;
+ arcfour_init(&state, key);
+ arcfour_crypt_sbox(&state, data, len);
}
/*