Вы находитесь на странице: 1из 3

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

Вам также может понравиться