+ hbytes_array(result, ivbuf, iv_lenbytes);
+
+ return TCL_OK;
+}
+
+int do_blockcipherop_mac(ClientData cd, Tcl_Interp *ip,
+ HBytes_Value msg, const BlockCipherAlgInfo *alg,
+ Tcl_Obj *key_obj, const BlockCipherModeInfo *mode,
+ HBytes_Value iv, HBytes_Value *result) {
+ const CiphKeyValue *key;
+ const char *failure;
+ const Byte *ivbuf;
+ Byte *buffers;
+ const void *sched;
+ int nblocks, iv_lenbytes;
+ int rc;
+
+ if (!mode->mac)
+ return staticerr(ip, "mode does not support mac generation");
+
+ rc= blockcipher_prep(ip,key_obj,&iv,0,
+ alg,mode, hbytes_len(&msg),
+ &key,&sched,
+ &ivbuf,&iv_lenbytes,
+ &buffers,&nblocks);
+ if (rc) return rc;
+
+ failure= mode->mac(hbytes_data(&msg), nblocks, ivbuf, buffers, alg, sched);
+ if (failure)
+ return staticerr(ip,failure);
+
+ hbytes_array(result, buffers, alg->blocksize * mode->mac_blocks);