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 shalib.prc: January 23, 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 shalib.prc 2. Download the shalib.h 3. Download the sha1.h 4. Only include the shalib.h in your file. How to use the shalib: 1. First you need to open the Library. The sample code is as follows: err = SysLibFind("SHALib", &SHALibRefNum); if (err) err = SysLibLoad('libr', 'WSHA', &SHALibRefNum); ErrFatalDisplayIf(err, "Cannot load SHA Library"); err = SHALibOpen(SHALibRefNum); Where SHALibRefNum is a static UInt16, used to store where is the SHALibrary. 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 shalib? First you need to create a variable to store the context of SHA-1 SHA1_CTX sha; Also, you need to Initialize the corresponding type of hash function via SHALibSHA1Init() To use the hash functions you need to call two functions: First you call SHALibSHA1Update() and to finish you call SHALibSHA1Final(). After you finish, you need to close the library. 3. How to Initialize SHA-1? This is done via the functions: SHALibSHA1Init(UInt16 uRefNum, SHA1_CTX *context) , It has the following parameters: UInt16 uRefNum: This is the reference number of the library. SHA1_CTX *context: Is the context for the SHA1 hash function. 4. How to Hash data? After initializing the data you need to call two functions: SHALibSHA1Update(UInt16 uRefNum, SHA1_CTX *context, unsigned char *input, unsigned int inputLen) SHALibSHA1Final(UInt16 uRefNum, unsigned char digest[16], SHA1_CTX *context) The parameters are: UInt16 uRefNum: A reference to the Library, obtained when you open the library. SHA1_CTX *context: The context for SHA1 library. 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 = SHALibClose(SHALibRefNum, &numapps); // check for erros in the Close() routine if (numapps == 0) SysLibRemove(SHALibRefNum); We suggest you include this code in the StopApplication() function or your function used to handle the case of closing the application.