On Fri, 2002-09-27 at 05:17, John McDowell wrote:

> I want to decrypt variable length strings using EncDES.
> Here is some of the code I'm using and it is blowing up (just wrote to a
> memory location in the storage heap) on the TxtSetNextChar function. eStr is
> not NULL. TxtGetNextChar sets ch to 255. Is there something simple I'm doing
> wrong here or am I using the wrong functions?

You probably shouldn't mix EncDES with Txt* functions. The Txt*
functions are meant to work with internationalized character sets which
may or may not contain multibyte characters. 

DES is a block cipher that encrypts blocks of bytes. Thus, your real
goal is to encrypt a block of bytes that happens to contain a "C" style
string. Something like:

UInt8* encrypt_block(UInt8* src, block_size, UInt8* key) {
        UInt8* dest = MemPtrNew(block_size);
        UInt8* srcp = src;
        UInt8* destp = dest;
        for (i = 0; i < input_size; i += 8) {
           EncDES(srcp, key, destp, true);
           srcp += 8;
           destp += 8;
        }
        return dest;
}

There's a bug in the above code where it fails to encrypt the last
partial block. The best workaround is to always ensure that the size of
your input block always a multiple of 8, probably by padding it with
NULs.

Also note that StrLen will not correctly determine the size of the block
if you have multibyte characters, so you'll have to use some other
method to determine how many bytes a string occupies.

-- 
Dave Carrigan
Seattle, WA, USA
[EMAIL PROTECTED] | http://www.rudedog.org/ | ICQ:161669680
UNIX-Apache-Perl-Linux-Firewalls-LDAP-C-C++-DNS-PalmOS-PostgreSQL-MySQL

Dave is currently listening to Aztec Camera - Sister Ann (Dreamland)


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to