tomcrypt/ecb.c

50 lines
1.1 KiB
C
Raw Normal View History

2003-03-02 19:59:24 -05:00
#include "mycrypt.h"
#ifdef ECB
int ecb_start(int cipher, const unsigned char *key, int keylen, int num_rounds, symmetric_ECB *ecb)
{
2003-03-02 20:02:42 -05:00
int err;
2003-03-02 19:59:24 -05:00
_ARGCHK(key != NULL);
_ARGCHK(ecb != NULL);
2003-03-02 20:02:42 -05:00
if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
return err;
2003-03-02 19:59:24 -05:00
}
ecb->cipher = cipher;
ecb->blocklen = cipher_descriptor[cipher].block_length;
return cipher_descriptor[cipher].setup(key, keylen, num_rounds, &ecb->key);
}
int ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_ECB *ecb)
{
2003-03-02 20:02:42 -05:00
int err;
2003-03-02 19:59:24 -05:00
_ARGCHK(pt != NULL);
_ARGCHK(ct != NULL);
_ARGCHK(ecb != NULL);
2003-03-02 20:02:42 -05:00
if ((err = cipher_is_valid(ecb->cipher)) != CRYPT_OK) {
return err;
2003-03-02 19:59:24 -05:00
}
cipher_descriptor[ecb->cipher].ecb_encrypt(pt, ct, &ecb->key);
return CRYPT_OK;
}
int ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_ECB *ecb)
{
2003-03-02 20:02:42 -05:00
int err;
2003-03-02 19:59:24 -05:00
_ARGCHK(pt != NULL);
_ARGCHK(ct != NULL);
_ARGCHK(ecb != NULL);
2003-03-02 20:02:42 -05:00
if ((err = cipher_is_valid(ecb->cipher)) != CRYPT_OK) {
return err;
2003-03-02 19:59:24 -05:00
}
cipher_descriptor[ecb->cipher].ecb_decrypt(ct, pt, &ecb->key);
return CRYPT_OK;
}
#endif