#include "hbytes.h"
-const char *mode_cbc_encrypt(Byte *data, int blocks,
- const Byte *iv, Byte *chain,
- const BlockCipherAlgInfo *alg, int encr,
- int blocksize, const void *sch) {
+static const char *mode_cbc_encrypt(Byte *data, int blocks,
+ const Byte *iv, Byte *chain,
+ const BlockCipherAlgInfo *alg, int encr,
+ int blocksize, const void *sch) {
memcpy(chain,iv,blocksize);
alg->byteswap(chain);
return 0;
}
-const char *mode_cbc_decrypt(Byte *data, int blocks,
- const Byte *iv, Byte *chain,
- const BlockCipherAlgInfo *alg, int encr,
- int blocksize, const void *sch) {
+static const char *mode_cbc_decrypt(Byte *data, int blocks,
+ const Byte *iv, Byte *chain,
+ const BlockCipherAlgInfo *alg, int encr,
+ int blocksize, const void *sch) {
int cchain= 0;
memcpy(chain,iv,blocksize);
return 0;
}
+static const char *mode_ecb(Byte *data, int blocks,
+ const Byte *iv, Byte *chain,
+ const BlockCipherAlgInfo *alg, int encr,
+ int blocksize, const void *sch) {
+ while (blocks > 0) {
+ alg->byteswap(data);
+ (encr ? &alg->encrypt : &alg->decrypt)->crypt(sch, data, data);
+ alg->byteswap(data);
+ blocks--; data += blocksize;
+ }
+ return 0;
+}
+
const BlockCipherModeInfo blockciphermodeinfos[]= {
{ "cbc", 1, 2, mode_cbc_encrypt, mode_cbc_decrypt },
+ { "ecb", 0, 0, mode_ecb, mode_ecb },
{ 0 }
};