AESLib for Palm OS
Introduction
AESLib is a Palm OS shared library that implements the
AES encryption algorithm.
This shared library is the result of porting
Dr.
Brian Gladman's AES implementation.
Duncan
Wong of Northeastern University has also produced a Palm OS port. Wong
shared his source code with me and gave me the idea to move the AES tables
into the storage heap. Previous versions of AESLib contained numerous
additional resources besides the code resource. This new version of AESLib
does not use Wong's technique. Instead everything is included in a single
code resource. This version of AESLib was built using PRC-Tools 2.2, the
arm-elf GNU tool chain, and the i386-cygwin GNU tool chain. It is also
possible to build the AESLib using CodeWarrior for Palm OS. The source
distribution contains a Build directory with appropriate project files for
both development environments. The SDK distribution includes example projects
with both PRC-Tools Makefiles and CodeWarrior project files.
ARM Support and Performance Metrics
This release of AESLib contains support for the ARM processor and OS/5. OS/5
is NOT required to use this library, but if you are using an OS/5 device with
an ARM processor you should notice a speed improvement. For use with the Palm
OS Simulator, a Windows DLL is included. Below is a table that shows the
results of running AESSpeedTest(included in source distribution) on
various Palm OS devices. You can see that the Tungsten T and the
Sony NX70V are significantly faster. Starting in version 3.1, two new
functions have been added to AESLib:
AESLibEncBigBlk and AESLibDecBigBlk. These two functions allow you to
process multiple blocks at a time and optionally perform cipher block chaining.
It is recommended that you use these functions whenever you are processing
more than one block of data. The results below reflect using these new
functions.
Device Name |
Encrypt Speed (bytes per second) |
Decrypt Speed (bytes per second) |
Palm m505 |
23,800 |
23,500 |
Palm Tungsten T |
1,495,300 |
1,333,300 |
Sony NX70V |
1,702,100 |
1,702,100 |
Embed AESLib within your application or shared library
Developers do not need to distribute AESLib.prc with their
program. Since AESLib is now a single code resource the developer can simply
include it within their own PRC. The sample, AESVectorTest, shows
how easy it is to do this. When your program goes to open the AESLib you
must call "AESLib_LoadLibrary" instead of "AESLib_OpenLibrary".
Download
Licensing
The top of each source file displays the following license agreement:
/*
-------------------------------------------------------------------------
Copyright (c) 2003, Copera, Inc., Mountain View, CA, USA.
All rights reserved.
LICENSE TERMS
The free distribution and use of this software in both source and binary
form is allowed (with or without changes) provided that:
1. distributions of this source code include the above copyright
notice, this list of conditions and the following disclaimer;
2. distributions in binary form include the above copyright
notice, this list of conditions and the following disclaimer
in the documentation and/or other associated materials;
3. the copyright holder's name is not used to endorse products
built using this software without specific written permission.
DISCLAIMER
This software is provided 'as is' with no explcit or implied warranties
in respect of any properties, including, but not limited to, correctness
and fitness for purpose.
-------------------------------------------------------------------------
Issue Date: March 10, 2003
*/
API functions
-
AESLibEncKey (UInt16 refNum, const unsigned char in_key[], unsigned int klen, aes_ctx cx[1])
in_key contains the bytes of your key, which is klen bytes long.
Valid key lengths are 16, 24, and 32. Your aes context, referenced by
cx is updated based on the key passed.
-
AESLibEncBlk (UInt16 refNum, const unsigned char in_blk[16], unsigned char out_blk[16], aes_ctx cx[1])
The 16 bytes of plaintext in in_blk are encrypted and the resulting
16 bytes of ciphertext are stored in out_blk.
-
AESLibDecKey (UInt16 refNum, const unsigned char in_key[], unsigned int klen, aes_ctx cx[1])
in_key contains the bytes of your key, which is klen bytes long.
Valid key lengths are 16, 24, and 32. Your aes context, referenced by
cx is updated based on the key passed.
-
AESLibDecBlk (UInt16 refNum, const unsigned char in_blk[16], unsigned char out_blk[16], aes_ctx cx[1])
The 16 bytes of ciphertext in in_blk are decrypted and the resulting
16 bytes of plaintext are stored in out_blk.
-
AESLibEncBigBlk (UInt16 refNum, const unsigned char in_blk[], unsigned char out_blk[], unsigned long *blen, Boolean cbc_mode, const unsigned char iv[], const aes_ctx cx[1])
The data from the in_blk is encrypted and stored int the out_blk.
On entry blen contains the number of bytes to encrypt and on exit
contains the number of bytes encrypted. The function will only encrypt
multiples of 16 bytes, any extra bytes will not be procssed. If you want
to use Cipher Block Chaining, set cbc_mode to true. If desired you can
set an initialization vector in iv.
-
AESLibDecBigBlk (UInt16 refNum, const unsigned char in_blk[], unsigned char out_blk[], unsigned long *blen, Boolean cbc_mode, const unsigned char iv[], const aes_ctx cx[1])
The data from the in_blk is decrypted and stored int the out_blk.
On entry blen contains the number of bytes to decrypt and on exit
contains the number of bytes decrypted. The function will only decrypt
multiples of 16 bytes, any extra bytes will not be procssed. If you want
to use Cipher Block Chaining, set cbc_mode to true. If desired you can
set an initialization vector in iv.
Sample program
The SDK distribution contains two small applications to demonstrate
the use of the AESLib. The first application, AESSpeedTest, was
used to perform the speed benchmarks mentioned before. To run
AESSpeedTest on a device you must install AESLib.prc first.
The second application, AESVectorTest, embeds the AESLib within it's
resources. You do not need to install AESLib.prc before running it.
AESVectorTest is used to demonstrate how an application developer would
include the AESLib within their app.
Below is a simple program excerpt showing how to use AESLib in your Palm
OS application.
#include "AESLib.h"
Err err = errNone;
UInt16 libRefNum;
UInt8 plaintext[16] = { 0x32, 0x43, 0xf6, 0xa8, 0x88, 0x5a, 0x30, 0x8d,
0x31, 0x31, 0x98, 0xa2, 0xe0, 0x37, 0x07, 0x34};
UInt8 key[16] = { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};
UInt8 ciphertext[16] = {'\0'};
aes_ctx *ctx = NULL;
aes_rval rval = aes_good;
err = AESLib_OpenLibrary(&libRefNum);
ctx = MemPtrNew(sizeof(*ctx));
MemSet(ctx, sizeof(*ctx), (UInt8) 0);
rval = AESLibEncKey(libRefNum, key, 16, ctx);
rval = AESLibEncBlk(libRefNum, plaintext, ciphertext, ctx);
err = AESLib_CloseLibrary(libRefNum);
MemPtrFree(ctx);
Conclusion
AESLib should make it easy for you to add cryptography to your projects.
Good luck, and if you have any questions, please send me e-mail.
Stuart Eichert (March 10th, 2003)