diff options
author | Matt Johnston <matt@ucc.asn.au> | 2007-02-03 08:20:34 +0000 |
---|---|---|
committer | Matt Johnston <matt@ucc.asn.au> | 2007-02-03 08:20:34 +0000 |
commit | d9aeb2773e236e662c8b493f4bcee978f9908d7c (patch) | |
tree | bac48e388bf3ac739ae14cdf98da0eb4bb9d17bf /libtomcrypt/src/modes/ecb/ecb_encrypt.c | |
parent | 056b92bd4c8a42ce1843493310d382159166edb8 (diff) | |
parent | c5fd7dd5548f28e32d846e39d17e5c4de4e769af (diff) |
merge of '5fdf69ca60d1683cdd9f4c2595134bed26394834'
and '6b61c50f4cf888bea302ac8fcf5dbb573b443251'
--HG--
extra : convert_revision : b1dd3b94e60a07a176dba2b035ac79968595990a
Diffstat (limited to 'libtomcrypt/src/modes/ecb/ecb_encrypt.c')
-rw-r--r-- | libtomcrypt/src/modes/ecb/ecb_encrypt.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/libtomcrypt/src/modes/ecb/ecb_encrypt.c b/libtomcrypt/src/modes/ecb/ecb_encrypt.c new file mode 100644 index 0000000..f6910c6 --- /dev/null +++ b/libtomcrypt/src/modes/ecb/ecb_encrypt.c @@ -0,0 +1,61 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com + */ +#include "tomcrypt.h" + +/** + @file ecb_encrypt.c + ECB implementation, encrypt a block, Tom St Denis +*/ + +#ifdef LTC_ECB_MODE + +/** + ECB encrypt + @param pt Plaintext + @param ct [out] Ciphertext + @param len The number of octets to process (must be multiple of the cipher block size) + @param ecb ECB state + @return CRYPT_OK if successful +*/ +int ecb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_ECB *ecb) +{ + int err; + LTC_ARGCHK(pt != NULL); + LTC_ARGCHK(ct != NULL); + LTC_ARGCHK(ecb != NULL); + if ((err = cipher_is_valid(ecb->cipher)) != CRYPT_OK) { + return err; + } + if (len % cipher_descriptor[ecb->cipher].block_length) { + return CRYPT_INVALID_ARG; + } + + /* check for accel */ + if (cipher_descriptor[ecb->cipher].accel_ecb_encrypt != NULL) { + return cipher_descriptor[ecb->cipher].accel_ecb_encrypt(pt, ct, len / cipher_descriptor[ecb->cipher].block_length, &ecb->key); + } else { + while (len) { + if ((err = cipher_descriptor[ecb->cipher].ecb_encrypt(pt, ct, &ecb->key)) != CRYPT_OK) { + return err; + } + pt += cipher_descriptor[ecb->cipher].block_length; + ct += cipher_descriptor[ecb->cipher].block_length; + len -= cipher_descriptor[ecb->cipher].block_length; + } + } + return CRYPT_OK; +} + +#endif + +/* $Source: /cvs/libtom/libtomcrypt/src/modes/ecb/ecb_encrypt.c,v $ */ +/* $Revision: 1.9 $ */ +/* $Date: 2006/06/29 01:51:34 $ */ |