Disclaimer THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Author: Duncan Wong e-mail: swong@ccs.neu.edu Manual written by: Hector Ho Fuentes. e-mail: hhofuent@ccs.neu.edu Date of mdlib.prc: March 1, 2001 Version: 0.1 If you have any suggestions please write to the author. Description: mdlib is a Palm OS Library that implements MD2, MD4 and MD5. To use this Palm Library, you need to: 1. Download the mdlib.prc 2. Download the mdlib.h 3. Download the md2.h 4. Download the md4.h 5. Download the md5.h 6. Download the global.h 7. Only include the mdlib.h in your file. How to use the mdlib: 1. First you need to open the Library. The sample code is as follows: err = SysLibFind("MDLib", &MDLibRefNum); if (err) err = SysLibLoad('libr', 'DWMD', &MDLibRefNum); ErrFatalDisplayIf(err, "Cannot load MD Library"); err = MDLibOpen(MDLibRefNum); Where MDLibRefNum is a static UInt16, used to store where is the MDLibrary. We sugest that you put this code in your StartApplication() function, or in the function you use to initialize your application. 2. How to use mdlib? Because each of the hash function has a different context, you need to declare a variable for the specific context. For MD2: MD2_CTX md2; For MD4: MD4_CTX md4; For MD5: MD5_CTX md5; Also, you need to Initialize the corresponding type of hash function via MDLibMDXInit() (where X is either 2, 4 or 5). To use the hash functions you need to call two functions: First you call MDLibMDXUpdate() to finish you call MDLibMDXFinal() (Again, where X is 2, 4 or 5). After you finish, you need to close the library. 3. How to Initialize MD2, MD4 or MD5? This is done via the functions: MDLibMD2Init(UInt16 uRefNum, MD5_CTX *context) , MDLibMD4Init(UInt16 uRefNum, MD5_CTX *context) , or MDLibMD5Init(UInt16 uRefNum, MD5_CTX *context) depending on which hash function you want to use. It has the following parameters: UInt16 uRefNum: This is the reference number of the library. MDx_CTX *context: Is the context for the MDx hash function. NOTE: x is for 2, 4 or 5 respectively. 4. How to Hash data? After initializing the data you need to call two functions: MDLibMDxUpdate(UInt16 uRefNum, MDx_CTX *context, unsigned char *input, unsigned int inputLen) MDLibMDxFinal(UInt16 uRefNum, unsigned char digest[16], MDx_CTX *context) Where the x is for 2, 4 or 5 for MDLibMDxUpdate, MDLibMDxFinal and MDx_CTX. The parameters are: UInt16 uRefNum: A reference to the Library, obtained when you open the library. MDx_CTX *context: The context for MD2, MD4 or MD5 library. NOTE: the x in MDx_CTX is either 2, 4 or 5. unsigned char *input: The input string to be hashed. unsigned int inputLen: The size of the string in Bytes. unsigned char digest[16]: Where to write the output of the hash function. NOTE: The user is responsible in deallocating any memory created for the input and output strings. 5. How to Close the Library? You can close the library when you finished. This is accomplished via: error = MDLibClose(MDLibRefNum, &numapps); // check for erros in the Close() routine if (numapps == 0) SysLibRemove(MDLibRefNum); We suggest you include this code in the StopApplication() function or your function used to handle the case of closing the application.