X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-tcl.git;a=blobdiff_plain;f=crypto%2Fbcmode.c;h=f7c808d55410796b4589220e28554b2669109b06;hp=7d5a5d4f6ea500e03835393f79b61e9470b36147;hb=d23a32272b954579fe15c78d6ea605e087d0a512;hpb=9b7d11070d3e9dc1eb61cbccd5155f47a27047c3 diff --git a/crypto/bcmode.c b/crypto/bcmode.c index 7d5a5d4..f7c808d 100644 --- a/crypto/bcmode.c +++ b/crypto/bcmode.c @@ -3,10 +3,10 @@ #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); @@ -23,10 +23,10 @@ const char *mode_cbc_encrypt(Byte *data, int blocks, 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); @@ -46,7 +46,21 @@ const char *mode_cbc_decrypt(Byte *data, int blocks, 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 } };