summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2015-03-19 18:42:13 -0400
committerSimo Sorce <simo@redhat.com>2015-03-19 19:18:27 -0400
commit4844f1e77523664298e601df3a0fb33e5cb28e31 (patch)
treebc969f13429be7b55bc04342483f023de35a7d22
parentd3e922fab076fbaee8630c61eb2cb033c3561049 (diff)
downloadgss-ntlmssp-4844f1e77523664298e601df3a0fb33e5cb28e31.tar.gz
gss-ntlmssp-4844f1e77523664298e601df3a0fb33e5cb28e31.tar.xz
gss-ntlmssp-4844f1e77523664298e601df3a0fb33e5cb28e31.zip
Support openssl optimized 32bit RC4 key packing
Openssl detects at runtime the CPU type and on some 32 bit CPUs will automatically switch to a compressed schedule for the RC4_KEY. Don't try to be too smart nd just copy all the data even if it takes 4 times the space. The code still assumes sizeof(RC4_INT) == sizeof(uint32_t)
-rw-r--r--src/crypto.c29
-rw-r--r--src/gss_serialize.c4
2 files changed, 15 insertions, 18 deletions
diff --git a/src/crypto.c b/src/crypto.c
index aca22f0..9fe69f9 100644
--- a/src/crypto.c
+++ b/src/crypto.c
@@ -178,35 +178,32 @@ void RC4_FREE(struct ntlm_rc4_handle **handle)
int RC4_EXPORT(struct ntlm_rc4_handle *handle, struct ntlm_buffer *out)
{
- int i;
+ RC4_INT *data = (RC4_INT *)out->data;
+ int len = 258 * sizeof(RC4_INT);
- if (out->length < 258) return EAGAIN;
+ if (out->length < len) return EINVAL;
- out->data[0] = (uint8_t)(handle->key.x & 0xff);
- out->data[1] = (uint8_t)(handle->key.y & 0xff);
- for (i = 0; i < 256; i++) {
- out->data[i + 2] = (uint8_t)(handle->key.data[i] & 0xff);
- }
-
- out->length = 258;
+ data[0] = handle->key.x;
+ data[1] = handle->key.y;
+ memcpy(&data[2], handle->key.data, sizeof(RC4_INT) * 256);
+ out->length = len;
return 0;
}
int RC4_IMPORT(struct ntlm_rc4_handle **_handle, struct ntlm_buffer *in)
{
struct ntlm_rc4_handle *handle;
- int i;
+ RC4_INT *data = (RC4_INT *)in->data;
+ int len = 258 * sizeof(RC4_INT);
- if (in->length != 258) return EINVAL;
+ if (in->length != len) return EINVAL;
handle = malloc(sizeof(struct ntlm_rc4_handle));
if (!handle) return ENOMEM;
- handle->key.x = in->data[0];
- handle->key.y = in->data[1];
- for (i = 0; i < 256; i++) {
- handle->key.data[i] = in->data[i + 2];
- }
+ handle->key.x = data[0];
+ handle->key.y = data[1];
+ memcpy(handle->key.data, &data[2], sizeof(RC4_INT) * 256);
*_handle = handle;
return 0;
diff --git a/src/gss_serialize.c b/src/gss_serialize.c
index 67e35bf..dafab62 100644
--- a/src/gss_serialize.c
+++ b/src/gss_serialize.c
@@ -44,7 +44,7 @@ struct export_keys {
uint32_t seq_num;
};
-#define EXPORT_CTX_VER 0x0002
+#define EXPORT_CTX_VER 0x0003
struct export_ctx {
uint16_t version;
uint8_t role;
@@ -197,7 +197,7 @@ static int export_keys(struct export_state *state,
struct ntlm_signseal_handle *keys,
struct export_keys *exp_keys)
{
- uint8_t buf[258];
+ uint8_t buf[258*sizeof(uint32_t)];
struct ntlm_buffer out = { .data=buf, .length=sizeof(buf) };
int ret;