diff options
| author | stevel@tonic-gate <none@none> | 2005-06-14 00:00:00 -0700 |
|---|---|---|
| committer | stevel@tonic-gate <none@none> | 2005-06-14 00:00:00 -0700 |
| commit | 7c478bd95313f5f23a4c958a745db2134aa03244 (patch) | |
| tree | c871e58545497667cbb4b0a4f2daf204743e1fe7 /usr/src/lib/libldap4/sec | |
| download | illumos-joyent-7c478bd95313f5f23a4c958a745db2134aa03244.tar.gz | |
OpenSolaris Launch
Diffstat (limited to 'usr/src/lib/libldap4/sec')
| -rw-r--r-- | usr/src/lib/libldap4/sec/cram_md5.c | 62 | ||||
| -rw-r--r-- | usr/src/lib/libldap4/sec/secutil.c | 63 |
2 files changed, 125 insertions, 0 deletions
diff --git a/usr/src/lib/libldap4/sec/cram_md5.c b/usr/src/lib/libldap4/sec/cram_md5.c new file mode 100644 index 0000000000..4b92efbfc6 --- /dev/null +++ b/usr/src/lib/libldap4/sec/cram_md5.c @@ -0,0 +1,62 @@ +/* + * + * Copyright %G% Sun Microsystems, Inc. + * All Rights Reserved + * + * + * Comments: + * + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/types.h> +#include <strings.h> +#include "sec.h" + +/* text is the challenge, key is the password, digest is an allocated + buffer (min 16 chars) which will contain the resulting digest */ +void hmac_md5(unsigned char *text, int text_len, unsigned char *key, + int key_len, unsigned char *digest) +{ + MD5_CTX context; + unsigned char k_ipad[65]; + unsigned char k_opad[65]; + unsigned char tk[16]; + int i; + + if (key_len > 64){ + MD5_CTX tctx; + + (void) MD5Init(&tctx); + (void) MD5Update(&tctx, key, key_len); + (void) MD5Final(tk, &tctx); + key = tk; + key_len = 16; + } + + bzero(k_ipad, sizeof (k_ipad)); + bzero(k_opad, sizeof (k_opad)); + bcopy(key, k_ipad, key_len); + bcopy(key, k_opad, key_len); + + for (i=0; i<64; i++){ + k_ipad[i] ^= 0x36; + k_opad[i] ^= 0x5c; + } + + /* Perform inner MD5 */ + (void) MD5Init(&context); + (void) MD5Update(&context, k_ipad, 64); + (void) MD5Update(&context, text, text_len); + (void) MD5Final(digest, &context); + + /* Perform outer MD5 */ + (void) MD5Init(&context); + (void) MD5Update(&context, k_opad, 64); + (void) MD5Update(&context, digest, 16); + + (void) MD5Final(digest, &context); + + return; +} diff --git a/usr/src/lib/libldap4/sec/secutil.c b/usr/src/lib/libldap4/sec/secutil.c new file mode 100644 index 0000000000..7d1658d0f9 --- /dev/null +++ b/usr/src/lib/libldap4/sec/secutil.c @@ -0,0 +1,63 @@ +/* + * + * Copyright %G% Sun Microsystems, Inc. + * All Rights Reserved + * + * + * Comments: + * + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <stdlib.h> +#include <string.h> +#include <ctype.h> + +static char hexdig[] = "0123456789abcdef"; + +char* hexa_print(char *aString, int aLen) +{ + char *res; + int i =0; + + if ((res = (char *)calloc (aLen*2 + 1, 1 )) == NULL){ + return (NULL); + } + for (;;){ + if (aLen < 1) + break; + res[i] = hexdig[ ( *aString & 0xf0 ) >> 4 ]; + res[i + 1] = hexdig[ *aString & 0x0f ]; + i+= 2; + aLen--; + aString++; + } + return (res); +} + + +static int +unhex( char c ) +{ + return( c >= '0' && c <= '9' ? c - '0' + : c >= 'A' && c <= 'F' ? c - 'A' + 10 + : c - 'a' + 10 ); +} + +char * hexa2str(char *anHexaStr, int *aResLen) { + int theLen = 0; + char *theRes = malloc(strlen(anHexaStr) /2 + 1); + + while (isxdigit(*anHexaStr)){ + theRes[theLen] = unhex(*anHexaStr) << 4; + if (++anHexaStr != '\0'){ + theRes[theLen] += unhex(*anHexaStr); + anHexaStr++; + } + theLen++; + } + theRes[theLen] = '\0'; + * aResLen = theLen; + return (theRes); +} |
