chiark / gitweb /
Do not insist on iv if none wanted. If get_key failes, do not crash.
authorian <ian>
Tue, 10 Sep 2002 20:01:35 +0000 (20:01 +0000)
committerian <ian>
Tue, 10 Sep 2002 20:01:35 +0000 (20:01 +0000)
crypto/crypto.c

index ec6a6de..3961158 100644 (file)
@@ -165,7 +165,7 @@ int do_hbytes_blockcipher(ClientData cd, Tcl_Interp *ip, int encrypt,
   void *sched, **schedp;
 
   want_bufferslen= alg->blocksize * (mode->buf_blocks + mode->iv_blocks);
-  key= get_key(ip, key_obj, alg, want_bufferslen);
+  key= get_key(ip, key_obj, alg, want_bufferslen);  if (!key) return TCL_ERROR;
 
   schedp= (alg->decrypt.make_schedule==alg->encrypt.make_schedule
           || encrypt) ? &key->alpha : &key->beta;
@@ -181,7 +181,10 @@ int do_hbytes_blockcipher(ClientData cd, Tcl_Interp *ip, int encrypt,
   }
 
   iv_want= alg->blocksize * mode->iv_blocks;
-  if (hbytes_issentinel(&iv)) {
+  if (!iv_want) {
+    if (!hbytes_issentinel(&iv))
+      return staticerr(ip,"iv supplied but mode does not take one");
+  } else if (hbytes_issentinel(&iv)) {
     if (!encrypt) return staticerr(ip,"must supply iv when decrypting");
     rc= get_urandom(ip, key->buffers, iv_want);
     if (rc) return rc;