+ *iv_r= key->buffers;
+ *iv_lenbytes_r= want_iv;
+
+ *buffers_r= key->buffers + want_iv;
+ *nblocks_r= data_len / alg->blocksize;
+
+ return TCL_OK;
+}
+
+int cht_do_blockcipherop_d(ClientData cd, Tcl_Interp *ip,
+ HBytes_Var v, const BlockCipherAlgInfo *alg,
+ Tcl_Obj *key_obj, const BlockCipherModeInfo *mode,
+ HBytes_Value iv, HBytes_Value *result) {
+ return cht_do_blockcipherop_e(cd,ip,v,alg,key_obj,mode,iv,result);
+}
+
+int cht_do_blockcipherop_e(ClientData cd, Tcl_Interp *ip,
+ HBytes_Var v, const BlockCipherAlgInfo *alg,
+ Tcl_Obj *key_obj, const BlockCipherModeInfo *mode,
+ HBytes_Value iv, HBytes_Value *result) {
+ const BlockCipherOp *op= (const void*)cd;
+ int encrypt= op->encrypt;
+ int rc, iv_lenbytes;
+ const CiphKeyValue *key;
+ const char *failure;
+ const Byte *ivbuf;
+ Byte *buffers;
+ const void *sched;
+ int nblocks;
+
+ if (!mode->encrypt)
+ return cht_staticerr(ip, "mode does not support encrypt/decrypt", 0);
+
+ rc= blockcipher_prep(ip,key_obj,&iv,!encrypt,
+ alg,mode, cht_hb_len(v.hb),
+ &key,&sched,
+ &ivbuf,&iv_lenbytes,
+ &buffers,&nblocks);
+ if (rc) return rc;
+