[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
CVS gsasl/lib/digest-md5
From: |
gsasl-commit |
Subject: |
CVS gsasl/lib/digest-md5 |
Date: |
Sun, 19 Dec 2004 19:00:13 +0100 |
Update of /home/cvs/gsasl/lib/digest-md5
In directory dopio:/tmp/cvs-serv2458
Modified Files:
session.h session.c server.c client.c
Log Message:
Modularize session.*.
--- /home/cvs/gsasl/lib/digest-md5/session.h 2004/10/13 16:23:29 1.2
+++ /home/cvs/gsasl/lib/digest-md5/session.h 2004/12/19 18:00:13 1.3
@@ -20,26 +20,22 @@
*
*/
-#ifndef SESSION_H
-#define SESSION_H
+#ifndef DIGEST_MD5_SESSION_H
+# define DIGEST_MD5_SESSION_H
-#include "digest-md5.h"
+/* Get token types. */
+#include "tokens.h"
-int
-digest_md5_encode (Gsasl_session * sctx,
- const char *input, size_t input_len,
- char **output, size_t * output_len,
- Gsasl_qop qop,
- uint32_t sendseqnum,
- char key[MD5LEN]);
+extern int digest_md5_encode (const char *input, size_t input_len,
+ char **output, size_t * output_len,
+ digest_md5_qop qop,
+ unsigned long sendseqnum,
+ char key[DIGEST_MD5_LENGTH]);
-int
-digest_md5_decode (Gsasl_session * sctx,
- const char *input,
- size_t input_len,
- char **output, size_t * output_len,
- Gsasl_qop qop,
- uint32_t readseqnum,
- char key[MD5LEN]);
+extern int digest_md5_decode (const char *input, size_t input_len,
+ char **output, size_t * output_len,
+ digest_md5_qop qop,
+ unsigned long readseqnum,
+ char key[DIGEST_MD5_LENGTH]);
-#endif /* SESSION_H */
+#endif /* DIGEST_MD5_SESSION_H */
--- /home/cvs/gsasl/lib/digest-md5/session.c 2004/11/19 01:41:50 1.4
+++ /home/cvs/gsasl/lib/digest-md5/session.c 2004/12/19 18:00:13 1.5
@@ -24,59 +24,69 @@
# include "config.h"
#endif
+/* Get specification. */
+#include "session.h"
+
/* Get malloc, free. */
#include <stdlib.h>
/* Get memcpy, strdup, strlen. */
#include <string.h>
-/* Get gsasl.h and other stuff. */
-#include "shared.h"
+/* Get htonl. */
+#include <netinet/in.h>
-/* Get specification. */
-#include "session.h"
+/* Get gc_hmac_md5. */
+#include <gc.h>
+
+#define MD5LEN 16
+#define SASL_INTEGRITY_PREFIX_LENGTH 4
+#define MAC_DATA_LEN 4
+#define MAC_HMAC_LEN 10
+#define MAC_MSG_TYPE "\x00\x01"
+#define MAC_MSG_TYPE_LEN 2
+#define MAC_SEQNUM_LEN 4
int
-digest_md5_encode (Gsasl_session * sctx,
- const char *input, size_t input_len,
+digest_md5_encode (const char *input, size_t input_len,
char **output, size_t * output_len,
- Gsasl_qop qop,
- uint32_t sendseqnum,
- char key[MD5LEN])
+ digest_md5_qop qop,
+ unsigned long sendseqnum,
+ char key[DIGEST_MD5_LENGTH])
{
int res;
- if (qop & GSASL_QOP_AUTH_CONF)
+ if (qop & DIGEST_MD5_QOP_AUTH_CONF)
{
- return GSASL_INTEGRITY_ERROR;
+ return -1;
}
- else if (qop & GSASL_QOP_AUTH_INT)
+ else if (qop & DIGEST_MD5_QOP_AUTH_INT)
{
char *seqnumin;
- char *hash;
+ char hash[GC_MD5_LEN];
uint32_t tmp;
size_t len;
seqnumin = malloc (MAC_SEQNUM_LEN + input_len);
if (seqnumin == NULL)
- return GSASL_MALLOC_ERROR;
+ return -1;
tmp = htonl (sendseqnum);
memcpy (seqnumin, (char *) &tmp, MAC_SEQNUM_LEN);
memcpy (seqnumin + MAC_SEQNUM_LEN, input, input_len);
- res = gsasl_hmac_md5 (key, MD5LEN,
- seqnumin, MAC_SEQNUM_LEN + input_len,
- (char **) &hash);
+ res = gc_hmac_md5 (key, MD5LEN,
+ seqnumin, MAC_SEQNUM_LEN + input_len,
+ hash);
free (seqnumin);
- if (res != GSASL_OK || hash == NULL)
- return GSASL_CRYPTO_ERROR;
+ if (res)
+ return -1;
*output_len = MAC_DATA_LEN + input_len + MAC_HMAC_LEN +
MAC_MSG_TYPE_LEN + MAC_SEQNUM_LEN;
*output = malloc (*output_len);
if (!*output)
- return GSASL_MALLOC_ERROR;
+ return -1;
len = MAC_DATA_LEN;
memcpy (*output + len, input, input_len);
@@ -90,54 +100,50 @@
len += MAC_SEQNUM_LEN;
tmp = htonl (len - MAC_DATA_LEN);
memcpy (*output, &tmp, MAC_DATA_LEN);
-
- free (hash);
}
else
{
*output_len = input_len;
*output = malloc (input_len);
if (!*output)
- return GSASL_MALLOC_ERROR;
+ return -1;
memcpy (*output, input, input_len);
}
- return GSASL_OK;
+ return 0;
}
int
-digest_md5_decode (Gsasl_session * sctx,
- const char *input,
- size_t input_len,
+digest_md5_decode (const char *input, size_t input_len,
char **output, size_t * output_len,
- Gsasl_qop qop,
- uint32_t readseqnum,
- char key[MD5LEN])
+ digest_md5_qop qop,
+ unsigned long readseqnum,
+ char key[DIGEST_MD5_LENGTH])
{
- if (qop & GSASL_QOP_AUTH_CONF)
+ if (qop & DIGEST_MD5_QOP_AUTH_CONF)
{
- return GSASL_INTEGRITY_ERROR;
+ return -1;
}
- else if (qop & GSASL_QOP_AUTH_INT)
+ else if (qop & DIGEST_MD5_QOP_AUTH_INT)
{
char *seqnumin;
- char *hash;
+ char hash[GC_MD5_LEN];
uint32_t len, tmp;
int res;
if (input_len < SASL_INTEGRITY_PREFIX_LENGTH)
- return GSASL_NEEDS_MORE;
+ return -2;
len = ntohl (*(uint32_t *) input);
if (input_len < SASL_INTEGRITY_PREFIX_LENGTH + len)
- return GSASL_NEEDS_MORE;
+ return -2;
len -= MAC_HMAC_LEN + MAC_MSG_TYPE_LEN + MAC_SEQNUM_LEN;
seqnumin = malloc (SASL_INTEGRITY_PREFIX_LENGTH + len);
if (seqnumin == NULL)
- return GSASL_MALLOC_ERROR;
+ return -1;
tmp = htonl (readseqnum);
@@ -145,16 +151,14 @@
memcpy (seqnumin + SASL_INTEGRITY_PREFIX_LENGTH,
input + MAC_DATA_LEN, len);
- res = gsasl_hmac_md5 (key, MD5LEN, seqnumin, MAC_SEQNUM_LEN + len,
- (char **) &hash);
+ res = gc_hmac_md5 (key, MD5LEN, seqnumin, MAC_SEQNUM_LEN + len,
+ hash);
free (seqnumin);
- if (res != GSASL_OK || hash == NULL)
- return GSASL_CRYPTO_ERROR;
+ if (res)
+ return -1;
- if (memcmp
- (hash,
- input + input_len - MAC_SEQNUM_LEN - MAC_MSG_TYPE_LEN -
- MAC_HMAC_LEN, MAC_HMAC_LEN) == 0
+ if (memcmp (hash, input + input_len - MAC_SEQNUM_LEN - MAC_MSG_TYPE_LEN -
+ MAC_HMAC_LEN, MAC_HMAC_LEN) == 0
&& memcmp (MAC_MSG_TYPE,
input + input_len - MAC_SEQNUM_LEN - MAC_MSG_TYPE_LEN,
MAC_MSG_TYPE_LEN) == 0
@@ -164,23 +168,20 @@
*output_len = len;
*output = malloc (*output_len);
if (!*output)
- return GSASL_MALLOC_ERROR;
+ return -1;
memcpy (*output, input + MAC_DATA_LEN, len);
}
else
- return GSASL_INTEGRITY_ERROR;
-
- free (hash);
+ return -1;
}
else
{
*output_len = input_len;
*output = malloc (input_len);
if (!*output)
- return GSASL_MALLOC_ERROR;
+ return -1;
memcpy (*output, input, input_len);
}
-
- return GSASL_OK;
+ return 0;
}
--- /home/cvs/gsasl/lib/digest-md5/server.c 2004/12/19 17:42:03 1.18
+++ /home/cvs/gsasl/lib/digest-md5/server.c 2004/12/19 18:00:13 1.19
@@ -772,10 +772,10 @@
_Gsasl_digest_md5_server_state *state = mech_data;
int res;
- res = digest_md5_encode (sctx, input, input_len, output, output_len,
+ res = digest_md5_encode (input, input_len, output, output_len,
state->qop, state->sendseqnum, state->kis);
- if (res != GSASL_OK)
- return res;
+ if (res)
+ return res == -2 ? GSASL_NEEDS_MORE : GSASL_INTEGRITY_ERROR;
state->sendseqnum++;
@@ -792,10 +792,10 @@
_Gsasl_digest_md5_server_state *state = mech_data;
int res;
- res = digest_md5_decode (sctx, input, input_len, output, output_len,
+ res = digest_md5_decode (input, input_len, output, output_len,
state->qop, state->readseqnum, state->kic);
- if (res != GSASL_OK)
- return res;
+ if (res)
+ return res == -2 ? GSASL_NEEDS_MORE : GSASL_INTEGRITY_ERROR;
state->readseqnum++;
--- /home/cvs/gsasl/lib/digest-md5/client.c 2004/12/19 17:42:03 1.16
+++ /home/cvs/gsasl/lib/digest-md5/client.c 2004/12/19 18:00:13 1.17
@@ -289,11 +289,11 @@
_Gsasl_digest_md5_client_state *state = mech_data;
int res;
- res = digest_md5_encode (sctx, input, input_len, output, output_len,
+ res = digest_md5_encode (input, input_len, output, output_len,
state->response.qop,
state->sendseqnum, state->kic);
- if (res != GSASL_OK)
- return res;
+ if (res)
+ return res == -2 ? GSASL_NEEDS_MORE : GSASL_INTEGRITY_ERROR;
state->sendseqnum++;
@@ -310,11 +310,11 @@
_Gsasl_digest_md5_client_state *state = mech_data;
int res;
- res = digest_md5_decode (sctx, input, input_len, output, output_len,
+ res = digest_md5_decode (input, input_len, output, output_len,
state->response.qop,
state->readseqnum, state->kis);
- if (res != GSASL_OK)
- return res;
+ if (res)
+ return res == -2 ? GSASL_NEEDS_MORE : GSASL_INTEGRITY_ERROR;
state->readseqnum++;
- CVS gsasl/lib/digest-md5, (continued)
- CVS gsasl/lib/digest-md5, gsasl-commit, 2004/12/19
- CVS gsasl/lib/digest-md5, gsasl-commit, 2004/12/19
- CVS gsasl/lib/digest-md5, gsasl-commit, 2004/12/19
- CVS gsasl/lib/digest-md5, gsasl-commit, 2004/12/19
- CVS gsasl/lib/digest-md5, gsasl-commit, 2004/12/19
- CVS gsasl/lib/digest-md5, gsasl-commit, 2004/12/19
- CVS gsasl/lib/digest-md5, gsasl-commit, 2004/12/19
- CVS gsasl/lib/digest-md5, gsasl-commit, 2004/12/19
- CVS gsasl/lib/digest-md5, gsasl-commit, 2004/12/19
- CVS gsasl/lib/digest-md5, gsasl-commit, 2004/12/19
- CVS gsasl/lib/digest-md5,
gsasl-commit <=
- CVS gsasl/lib/digest-md5, gsasl-commit, 2004/12/19
- CVS gsasl/lib/digest-md5, gsasl-commit, 2004/12/19
- CVS gsasl/lib/digest-md5, gsasl-commit, 2004/12/19
- CVS gsasl/lib/digest-md5, gsasl-commit, 2004/12/19
- CVS gsasl/lib/digest-md5, gsasl-commit, 2004/12/19
- CVS gsasl/lib/digest-md5, gsasl-commit, 2004/12/19
- CVS gsasl/lib/digest-md5, gsasl-commit, 2004/12/19
- CVS gsasl/lib/digest-md5, gsasl-commit, 2004/12/19
- CVS gsasl/lib/digest-md5, gsasl-commit, 2004/12/19
- CVS gsasl/lib/digest-md5, gsasl-commit, 2004/12/19