6 static const char *mode_cbc_encrypt(Byte *data, int blocks,
7 const Byte *iv, Byte *chain,
8 const BlockCipherAlgInfo *alg, int encr,
10 int blocksize= alg->blocksize;
11 memcpy(chain,iv,blocksize);
17 memxor(data, chain, blocksize);
18 alg->encrypt.crypt(sch, data, data);
19 memcpy(chain, data, blocksize);
22 blocks--; data += blocksize;
27 static const char *mode_cbc_decrypt(Byte *data, int blocks,
28 const Byte *iv, Byte *chain,
29 const BlockCipherAlgInfo *alg, int encr,
31 int blocksize= alg->blocksize;
34 memcpy(chain,iv,blocksize);
40 memcpy(chain + (cchain^blocksize), data, blocksize);
41 alg->decrypt.crypt(sch, data, data);
42 memxor(data, chain + cchain, blocksize);
46 blocks--; data += blocksize;
51 static void cbcmac_core(const Byte *data, int blocks,
52 const Byte *iv, Byte *buf,
53 const BlockCipherAlgInfo *alg,
55 int blocksize= alg->blocksize;
57 memcpy(buf,iv,blocksize);
61 memcpy(buf + blocksize, data, blocksize);
62 alg->byteswap(buf + blocksize);
63 memxor(buf, buf + blocksize, blocksize);
65 alg->encrypt.crypt(sch, buf, buf);
67 blocks--; data += blocksize;
71 static const char *mode_cbc_mac(const Byte *data, int blocks,
72 const Byte *iv, Byte *buf,
73 const BlockCipherAlgInfo *alg,
75 cbcmac_core(data,blocks,iv,buf,alg,sch);
80 static const char *mode_cbc_mac2(const Byte *data, int blocks,
81 const Byte *iv, Byte *buf,
82 const BlockCipherAlgInfo *alg,
84 cbcmac_core(data,blocks,iv,buf,alg,sch);
85 alg->encrypt.crypt(sch, buf, buf);
90 static const char *mode_ecb(Byte *data, int blocks,
91 const Byte *iv, Byte *chain,
92 const BlockCipherAlgInfo *alg, int encr,
94 int blocksize= alg->blocksize;
98 (encr ? &alg->encrypt : &alg->decrypt)->crypt(sch, data, data);
100 blocks--; data += blocksize;
105 const BlockCipherModeInfo blockciphermodeinfos[]= {
106 { "cbc", 1, 2, 1, mode_cbc_encrypt, mode_cbc_decrypt, mode_cbc_mac },
107 { "cbc-mac2", 1, 2, 1, 0, 0, mode_cbc_mac2 },
108 { "ecb", 0, 0, 0, mode_ecb, mode_ecb, 0 },