+static void cbcmac_core(const Byte *data, int blocks,
+ const Byte *iv, Byte *buf,
+ const BlockCipherAlgInfo *alg,
+ const void *sch) {
+ int blocksize= alg->blocksize;
+
+ memcpy(buf,iv,blocksize);
+
+ while (blocks > 0) {
+ memcpy(buf + blocksize, data, blocksize);
+ memxor(buf, buf + blocksize, blocksize);
+
+ alg->encrypt.crypt(sch, buf, buf);
+
+ blocks--; data += blocksize;
+ }
+}
+
+static const char *mode_cbc_mac(const Byte *data, int blocks,
+ const Byte *iv, Byte *buf,
+ const BlockCipherAlgInfo *alg,
+ const void *sch) {
+ cbcmac_core(data,blocks,iv,buf,alg,sch);
+ return 0;
+}
+
+static const char *mode_cbc_mac2(const Byte *data, int blocks,
+ const Byte *iv, Byte *buf,
+ const BlockCipherAlgInfo *alg,
+ const void *sch) {
+ cbcmac_core(data,blocks,iv,buf,alg,sch);
+ alg->encrypt.crypt(sch, buf, buf);
+ return 0;
+}
+