Path: blob/master/libs/tomcrypt/src/modes/ecb/ecb_decrypt.c
5972 views
/* LibTomCrypt, modular cryptographic library -- Tom St Denis1*2* LibTomCrypt is a library that provides various cryptographic3* algorithms in a highly modular and flexible manner.4*5* The library is free for all purposes without any express6* guarantee it works.7*/8#include "tomcrypt.h"910/**11@file ecb_decrypt.c12ECB implementation, decrypt a block, Tom St Denis13*/1415#ifdef LTC_ECB_MODE1617/**18ECB decrypt19@param ct Ciphertext20@param pt [out] Plaintext21@param len The number of octets to process (must be multiple of the cipher block size)22@param ecb ECB state23@return CRYPT_OK if successful24*/25int ecb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_ECB *ecb)26{27int err;28LTC_ARGCHK(pt != NULL);29LTC_ARGCHK(ct != NULL);30LTC_ARGCHK(ecb != NULL);31if ((err = cipher_is_valid(ecb->cipher)) != CRYPT_OK) {32return err;33}34if (len % cipher_descriptor[ecb->cipher].block_length) {35return CRYPT_INVALID_ARG;36}3738/* check for accel */39if (cipher_descriptor[ecb->cipher].accel_ecb_decrypt != NULL) {40return cipher_descriptor[ecb->cipher].accel_ecb_decrypt(ct, pt, len / cipher_descriptor[ecb->cipher].block_length, &ecb->key);41} else {42while (len) {43if ((err = cipher_descriptor[ecb->cipher].ecb_decrypt(ct, pt, &ecb->key)) != CRYPT_OK) {44return err;45}46pt += cipher_descriptor[ecb->cipher].block_length;47ct += cipher_descriptor[ecb->cipher].block_length;48len -= cipher_descriptor[ecb->cipher].block_length;49}50}51return CRYPT_OK;52}5354#endif555657