Auth Lib – with DH Key Exchange Algorithm, MD5 Digest Algorithm and Helper APIs

Finally, I’ve got time to summaries the authentication work I’ve done for MGC:) This post gives a useful C lib on authentication focusing on DH key exchange algorithm and MD5 digest helper APIs. Please note this lib should be built/used with the MD5 implementation from RFC1321 (http://www.faqs.org/rfcs/rfc1321.html), including ‘global.h’, ‘md5.h’ and ‘md5c.c’ (‘mddriver.c’ is optional as being testing code). Some of the APIs have two versions – one is focusing on memory usage; the other pays attention to performance. Different system requirement should call different APIs. Any question/suggestion, please feel free to let me know. Enjoy:)

authlib

Project Name: authlib
Destination: A C lib providing helper APIs on authentication related, especially for md5 and DH algorithms
Language: C
IDE: vi
Project Web: http://kenai.com/projects/authlib
SVN address: https://svn.kenai.com/svn/authlib~authlib-src
Source Code: http://kenai.com/projects/authlib/sources/authlib-src/show

/*
* authUtils.h
* Header file for authLib with all related utils functions
* dave.tian@alcatel-lucent.com
* 2011/10/18
*/

#ifndef AUTHUTILS_H
#define AUTHUTILS_H

/* Diffie-Hellman key exchange algorithm */
unsigned long authDhKey( unsigned long, unsigned int, unsigned int);

/* MD5 algorithm with ASCII string as source input */
void authMD5String(char *, char *);

/* MD5 algorithm with ASCII string as source input with binary processing */
unsigned int authMD5Binary(char *, unsigned int, char *);

/* Conversion from binary format to hex format using table */
unsigned int authBin2HexTable( char *, unsigned int, char *);

/* Conversion from hex format to binary format using table */
unsigned int authHex2BinTable( char *, unsigned int, char *);

/* Conversion from binary format to hex format using bit operation */
int authBin2HexBit( char *, unsigned int, char *);

/* Conversion from hex format to binary format using bit operation */
int authHex2BinBit( char *, unsigned int, char *);

/* Conversion from unsigned long to char array (binary format) */
unsigned int authUlong2CharArrayBin( unsigned long, char *);

/* Concatenation function for binary format input */
unsigned int authConcatenateBinString( char *, unsigned int, char *);

/* hex digits checking wrapper */
int authHexDigitsChecking( char *);

#endif /* AUTHUTILS_H */

/home/daveti/authLib: ll
total 27
-rw-r–r–    1 daveti   daveti       2020 Oct 25 07:00 Makefile
-rw-r–r–    1 daveti   daveti        232 Oct 18 03:11 authDefs.h
-rw-r–r–    1 daveti   daveti      22869 Oct 25 06:18 authUtils.c
-rw-r–r–    1 daveti   daveti       1353 Oct 25 06:11 authUtils.h
-rw-r–r–    1 daveti   daveti        795 Oct 18 02:10 global.h
-rw-r–r–    1 daveti   daveti       1350 Oct 18 02:10 md5.h
-rw-r–r–    1 daveti   daveti      10031 Oct 18 02:15 md5c.c
-rw-r–r–    1 daveti   daveti       5004 Oct 24 09:29 mddriver.c
/home/daveti/authLib: make

#############################################
##### Building authLib source code….  #####
#############################################

gcc -c -DMD=5 mddriver.c
gcc -c -DMD=5 md5c.c
gcc -c -DMD=5 authUtils.c
gcc -DMD=5 -o auth  mddriver.o md5c.o authUtils.o
/home/daveti/authLib: make test
echo ‘MD5 test suite:’ > test.rfc
echo ‘MD5 (“”) = d41d8cd98f00b204e9800998ecf8427e’ >> test.rfc
echo ‘MD5 (“a”) = 0cc175b9c0f1b6a831c399e269772661’ >> test.rfc
echo ‘MD5 (“abc”) = 900150983cd24fb0d6963f7d28e17f72’ >> test.rfc
echo ‘MD5 (“message digest”) = f96b697d7cb7938d525a2f31aaf161d0’ >> test.rfc
echo ‘MD5 (“abcdefghijklmnopqrstuvwxyz”) = c3fcd3d76192e4007dfb496cca67e13b’ >> test.rfc
echo ‘MD5 (“ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789”) = d174ab98d277d9f5a5611c2c9f419d9f’ >> test.rfc
echo ‘MD5 (“12345678901234567890123456789012345678901234567890123456789012345678901234567890”) = 57edf4a22be3c955ac49da2e2107b67a’ >> test.rfc
./auth  -x | diff – test.rfc > diffs 2>&1
*** MD5 Test Passed
rm -f diffs

About daveti

Interested in kernel hacking, compilers, machine learning and guitars.
This entry was posted in Dave's Tools, Programming and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s