chiark / gitweb /
hbytes and crypto compile now
authorian <ian>
Sat, 7 Jan 2006 20:40:49 +0000 (20:40 +0000)
committerian <ian>
Sat, 7 Jan 2006 20:40:49 +0000 (20:40 +0000)
18 files changed:
Makefile
adns/Makefile
adns/chiark_tcl_adns.h
base/extension.make
crypto/.cvsignore [new file with mode: 0644]
crypto/Makefile [new file with mode: 0644]
crypto/algtables.c
crypto/bcmode.c
crypto/chiark_tcl_crypto.h [new file with mode: 0644]
crypto/crypto.c
crypto/crypto.h
crypto/crypto.tct
crypto/hook.c
hbytes/Makefile
hbytes/hbytes-base.tct [new file with mode: 0644]
hbytes/hbytes.h
hbytes/hbytes.tct
hbytes/hook.c

index 1ccf437362a42c00ec77790e3837e4003c8521eb..d0462d6fc767f5c39cc22c67f1d47414b4fcdb8d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,6 @@
 
-SUBDIRS=       base adns hbytes crypto dgram tuntap
+SUBDIRS=       base adns hbytes crypto
+# dgram tuntap
 
 default: all
 
index 31e3df9ad29ee7e46ee14a802ab7e33d904761a6..869d89061c36e20050903f25d91461a12f8dd110 100644 (file)
@@ -1,6 +1,5 @@
 BASE_DIR =     ../base
 EXTBASE =      adns
-TABLE =                adnscmds
 CFILES =       adns
 LDLIBS +=      -ladns
 
index 0881253dc3bed5a463382976075bacf274018f17..af8de0e9c70c09422accfa05bd674a41e2495d61 100644 (file)
@@ -13,6 +13,6 @@ typedef struct {
 
 const IdDataSpec adnstcl_queries, adnstcl_resolvers;
 
-#include "adnscmds.h"
+#include "adns+tcmdif.h"
 
 #endif /*ADNSTCL_H*/
index d9ae4794fb9863ae9cff9917f6d5e2c1dc1db9eb..d12723b4fe079e6a626471545269ed7d2c54a7fd 100644 (file)
@@ -12,12 +12,12 @@ LDLIBS +=   $(BASE_DIR)/chiark-tcl.so
 include                $(BASE_DIR)/common.make
 include                $(BASE_DIR)/shlib.make
 
-TCMDIFARGS ?=  -p$(EXTENSION) -o$@ $(BASE_TCT) $<
+TCMDIFARGS ?=  -p$(EXTENSION) -o$@ $(BASE_TCT) $(OTHER_TCTS) $<
 
-%+tcmdif.c:    %.tct $(BASE_TCT) $(TCMDIFGEN)
+%+tcmdif.c:    %.tct $(BASE_TCT) $(OTHER_TCTS) $(TCMDIFGEN)
                $(TCMDIFGEN) -wc $(TCMDIFARGS)
 
-%+tcmdif.h:    %.tct $(BASE_TCT) $(TCMDIFGEN)
+%+tcmdif.h:    %.tct $(BASE_TCT) $(OTHER_TCTS) $(TCMDIFGEN)
                $(TCMDIFGEN) -wh $(TCMDIFARGS)
 
 include                $(BASE_DIR)/final.make
diff --git a/crypto/.cvsignore b/crypto/.cvsignore
new file mode 100644 (file)
index 0000000..fc2ec4f
--- /dev/null
@@ -0,0 +1,2 @@
+*+tcmdif.[ch]
+*.d
diff --git a/crypto/Makefile b/crypto/Makefile
new file mode 100644 (file)
index 0000000..12fccd7
--- /dev/null
@@ -0,0 +1,9 @@
+BASE_DIR =     ../base
+EXTBASE =      crypto
+CFILES =       algtables bcmode crypto hook
+OTHER_TCTS =   ../hbytes/hbytes-base.tct
+CPPFLAGS +=    -I../hbytes
+LDLIBS +=      ../hbytes/chiark_tcl_hbytes.so -lnettle
+
+include ../base/extension.make
+
index bb111dea4e2cc958e778fba123b952d886c8b61d..ea591fb0ed89860e026d12f9cd3edeee88eafca8 100644 (file)
@@ -1,11 +1,7 @@
 /*
  */
 
-#include <stdint.h>
-#include <stddef.h>
-#include <netinet/in.h>
-
-#include "hbytes.h"
+#include "chiark_tcl_crypto.h"
 
 #include <nettle/md5.h>
 #include <nettle/sha.h>
@@ -17,9 +13,9 @@
 #define NETTLE_BLOCKCIPHERS                    \
   DO(serpent,  SERPENT)                                \
   DO(twofish,  TWOFISH)                                \
-  DO(aes,      AES)                            \
+/* DO(aes,      AES) */                                \
   DO(blowfish, BLOWFISH)                       \
-  ALIAS(rijndael, aes, AES)
+  /*  ALIAS(rijndael, aes, AES)*/
 
 #define ALIAS(alias,name,NAME)
 #define DO(name,NAME)                                                        \
@@ -36,7 +32,7 @@
 #undef DO
 #undef ALIAS
 
-const BlockCipherAlgInfo blockcipheralginfos[]= {
+const BlockCipherAlgInfo cht_blockcipheralginfo_entries[]= {
 #define ALIAS(alias,name,NAME)                                 \
   { #alias, NAME##_BLOCK_SIZE, sizeof(struct name##_ctx),      \
        NAME##_MIN_KEY_SIZE, NAME##_MAX_KEY_SIZE,               \
@@ -50,7 +46,7 @@ const BlockCipherAlgInfo blockcipheralginfos[]= {
   { 0 }
 };
 
-const BlockCipherPropInfo blockcipherpropinfos[]= {
+const BlockCipherPropInfo cht_blockcipherpropinfo_entries[]= {
   { "blocklen",  offsetof(BlockCipherAlgInfo, blocksize) },
   { "minkeylen", offsetof(BlockCipherAlgInfo, key_min)   },
   { "maxkeylen", offsetof(BlockCipherAlgInfo, key_max)   },
@@ -81,13 +77,13 @@ const BlockCipherPropInfo blockcipherpropinfos[]= {
   NETTLE_DIGESTS
 #undef DO
 
-const HashAlgPropInfo hashalgpropinfos[]= {
+const HashAlgPropInfo cht_hashalgpropinfo_entries[]= {
   { "hashlen",  offsetof(HashAlgInfo, hashsize)  },
   { "blocklen", offsetof(HashAlgInfo, blocksize) },
   { 0 }
 };
 
-const HashAlgInfo hashalginfos[]= {
+const HashAlgInfo cht_hashalginfo_entries[]= {
 #define DO(name,NAME)                                                      \
   { #name, NAME##_DIGEST_SIZE, NAME##_DATA_SIZE, sizeof(struct name##_ctx), \
     alg_##name##_init, alg_##name##_update, alg_##name##_final,                    \
index e413de72e78677b8af9ff57b91693fc651e405e7..24dfdb80d85e22a6233f062fbd2b1da03cdb5490 100644 (file)
@@ -1,7 +1,7 @@
 /*
  */
   
-#include "hbytes.h"
+#include "chiark_tcl_crypto.h"
 
 static const char *mode_cbc_encrypt(Byte *data, int blocks,
                                    const Byte *iv, Byte *chain,
@@ -110,7 +110,7 @@ static const char *mode_ctr(Byte *data, int blocks,
   return 0;
 }
 
-const BlockCipherModeInfo blockciphermodeinfos[]= {
+const BlockCipherModeInfo cht_blockciphermodeinfo_entries[]= {
   { "cbc",      1, 2, 1, mode_cbc_encrypt, mode_cbc_decrypt, mode_cbc_mac  },
   { "cbc-mac2", 1, 2, 1, 0,                0,                mode_cbc_mac2 },
   { "ecb",      0, 0, 0, mode_ecb,         mode_ecb,         0             },
diff --git a/crypto/chiark_tcl_crypto.h b/crypto/chiark_tcl_crypto.h
new file mode 100644 (file)
index 0000000..02f68db
--- /dev/null
@@ -0,0 +1,10 @@
+
+#include <stdint.h>
+#include <stddef.h>
+#include <netinet/in.h>
+
+#include <endian.h>
+
+#include "hbytes.h"
+#include "crypto.h"
+#include "crypto+tcmdif.h"
index cf50712979a9beb73d6e2f1477070c164d9a0657..e8d7f1a64dfff433a848b4c1f555e0f20a9d3c68 100644 (file)
@@ -1,12 +1,9 @@
 /*
  */
 
-#include <endian.h>
+#include "chiark_tcl_crypto.h"
 
-#include "hbytes.h"
-#include "tables.h"
-
-const PadOp padops[]= {
+const PadOp cht_padop_entries[]= {
   { "un", 0, 0 },
   { "ua", 0, 1 },
   { "pn", 1, 0 },
@@ -19,7 +16,7 @@ typedef struct {
   int pad, blocksize; /* 0 or 1 */
 } PadMethodClientData;
 
-int do_hbytes_pad(ClientData cd, Tcl_Interp *ip, const PadOp *op,
+int cht_do_hbcrypto_pad(ClientData cd, Tcl_Interp *ip, const PadOp *op,
                  HBytes_Var v, Tcl_Obj *blocksz, const PadMethodInfo *meth,
                  int methargsc, Tcl_Obj *const *methargsv) {
   PadMethodClientData pmcd;
@@ -27,13 +24,13 @@ int do_hbytes_pad(ClientData cd, Tcl_Interp *ip, const PadOp *op,
   
   if (op->use_algname) {
     const BlockCipherAlgInfo *alg;
-    alg= enum_lookup_cached(ip,blocksz,blockcipheralginfos,
+    alg= enum_lookup_cached(ip,blocksz, cht_blockcipheralginfo_entries,
                            "blockcipher alg for pad");
     if (!alg) return TCL_ERROR;
     pmcd.blocksize= alg->blocksize;
   } else {
     rc= Tcl_GetIntFromObj(ip, blocksz, &pmcd.blocksize);  if (rc) return rc;
-    if (pmcd.blocksize < 1) staticerr(ip, "block size must be at least 1", 0);
+    if (pmcd.blocksize < 1) cht_staticerr(ip, "block size must be at least 1", 0);
   }
 
   pmcd.hb= v.hb;
@@ -42,29 +39,29 @@ int do_hbytes_pad(ClientData cd, Tcl_Interp *ip, const PadOp *op,
   return meth->func(&pmcd,ip,methargsc,methargsv);
 }
   
-int do_padmethodinfo_rfc2406(ClientData cd, Tcl_Interp *ip,
+int cht_do_padmethodinfo_rfc2406(ClientData cd, Tcl_Interp *ip,
                             Tcl_Obj *nxthdr_arg, int *ok) {
   const PadMethodClientData *pmcd= (const void*)cd;
   int i, rc, padlen, old_len;
   
   if (pmcd->blocksize > 256)
-    return staticerr(ip, "block size too large for RFC2406 padding", 0);
+    return cht_staticerr(ip, "block size too large for RFC2406 padding", 0);
 
   if (pmcd->pad) {
     Byte *padding;
     HBytes_Value nxthdr;
 
-    rc= pat_hb(ip,nxthdr_arg,&nxthdr);
+    rc= cht_pat_hb(ip,nxthdr_arg,&nxthdr);
     if (rc) return rc;
 
-    if (hbytes_len(&nxthdr) != 1) return
-      staticerr(ip, "RFC2406 next header field must be exactly 1 byte", 0);
-    padlen= pmcd->blocksize-1 - ((hbytes_len(pmcd->hb)+1) % pmcd->blocksize);
-    padding= hbytes_append(pmcd->hb, padlen+2);
+    if (cht_hb_len(&nxthdr) != 1) return
+      cht_staticerr(ip, "RFC2406 next header field must be exactly 1 byte", 0);
+    padlen= pmcd->blocksize-1 - ((cht_hb_len(pmcd->hb)+1) % pmcd->blocksize);
+    padding= cht_hb_append(pmcd->hb, padlen+2);
     for (i=1; i<=padlen; i++)
       *padding++ = i;
     *padding++ = padlen;
-    *padding++ = hbytes_data(&nxthdr)[0];
+    *padding++ = cht_hb_data(&nxthdr)[0];
     *ok= 1;
     
   } else {
@@ -73,16 +70,16 @@ int do_padmethodinfo_rfc2406(ClientData cd, Tcl_Interp *ip,
     Tcl_Obj *nxthdr_valobj, *ro;
     
     *ok= 0;
-    old_len= hbytes_len(pmcd->hb);  if (old_len % pmcd->blocksize) goto quit;
-    trailer= hbytes_unappend(pmcd->hb, 2); if (!trailer) goto quit;
+    old_len= cht_hb_len(pmcd->hb);  if (old_len % pmcd->blocksize) goto quit;
+    trailer= cht_hb_unappend(pmcd->hb, 2); if (!trailer) goto quit;
 
     padlen= trailer[0];
-    hbytes_array(&nxthdr,trailer+1,1);
-    nxthdr_valobj= ret_hb(ip,nxthdr);
+    cht_hb_array(&nxthdr,trailer+1,1);
+    nxthdr_valobj= cht_ret_hb(ip,nxthdr);
     ro= Tcl_ObjSetVar2(ip,nxthdr_arg,0,nxthdr_valobj,TCL_LEAVE_ERR_MSG);
     if (!ro) { Tcl_DecrRefCount(nxthdr_valobj); return TCL_ERROR; }
 
-    padding= hbytes_unappend(pmcd->hb, padlen);
+    padding= cht_hb_unappend(pmcd->hb, padlen);
     for (i=1; i<=padlen; i++)
       if (*padding++ != i) goto quit;
 
@@ -95,30 +92,30 @@ int do_padmethodinfo_rfc2406(ClientData cd, Tcl_Interp *ip,
   return TCL_OK;
 }
 
-int do_padmethodinfo_pkcs5(ClientData cd, Tcl_Interp *ip, int *ok) {
+int cht_do_padmethodinfo_pkcs5(ClientData cd, Tcl_Interp *ip, int *ok) {
   const PadMethodClientData *pmcd= (const void*)cd;
   int padlen, old_len, i;
   
   if (pmcd->blocksize > 255)
-    return staticerr(ip, "block size too large for pkcs#5", 0);
+    return cht_staticerr(ip, "block size too large for pkcs#5", 0);
 
   if (pmcd->pad) {
 
     Byte *padding;
 
-    padlen= pmcd->blocksize - (hbytes_len(pmcd->hb) % pmcd->blocksize);
-    padding= hbytes_append(pmcd->hb, padlen);
+    padlen= pmcd->blocksize - (cht_hb_len(pmcd->hb) % pmcd->blocksize);
+    padding= cht_hb_append(pmcd->hb, padlen);
     memset(padding, padlen, padlen);
 
   } else {
 
     const Byte *padding;
 
-    old_len= hbytes_len(pmcd->hb);  if (old_len % pmcd->blocksize) goto bad;
-    padding= hbytes_unappend(pmcd->hb, 1);  if (!padding) goto bad;
+    old_len= cht_hb_len(pmcd->hb);  if (old_len % pmcd->blocksize) goto bad;
+    padding= cht_hb_unappend(pmcd->hb, 1);  if (!padding) goto bad;
     padlen= *padding;
     if (padlen < 1 || padlen > pmcd->blocksize) goto bad;
-    padding= hbytes_unappend(pmcd->hb, padlen-1);  if (!padding) goto bad;
+    padding= cht_hb_unappend(pmcd->hb, padlen-1);  if (!padding) goto bad;
 
     for (i=0; i<padlen-1; i++, padding++) if (*padding != padlen) goto bad;
 
@@ -132,12 +129,12 @@ int do_padmethodinfo_pkcs5(ClientData cd, Tcl_Interp *ip, int *ok) {
   return TCL_OK;
 }
 
-int do_hbytes_hash(ClientData cd, Tcl_Interp *ip, const HashAlgInfo *alg,
+int cht_do_hbcrypto_hash(ClientData cd, Tcl_Interp *ip, const HashAlgInfo *alg,
                   HBytes_Value message, HBytes_Value *result) {
   Byte *dest;
 
-  dest= hbytes_arrayspace(result,alg->hashsize);
-  alg->oneshot(dest, hbytes_data(&message), hbytes_len(&message));
+  dest= cht_hb_arrayspace(result,alg->hashsize);
+  alg->oneshot(dest, cht_hb_data(&message), cht_hb_len(&message));
   return TCL_OK;
 }
 
@@ -176,7 +173,7 @@ static void key_t_dup(Tcl_Obj *src_obj, Tcl_Obj *dup_obj) {
   memcpy(dup->value, src->value, src->valuelen);
   noalg(dup);
   dup_obj->internalRep.otherValuePtr= dup;
-  dup_obj->typePtr= &blockcipherkey_type;
+  dup_obj->typePtr= &cht_blockcipherkey_type;
 }
 
 static void key_t_ustr(Tcl_Obj *o) {
@@ -187,23 +184,23 @@ static int key_t_sfa(Tcl_Interp *ip, Tcl_Obj *o) {
   int rc, l;
   CiphKeyValue *val;
 
-  rc= Tcl_ConvertToType(ip,o,&hbytes_type);  if (rc) return rc;
+  rc= Tcl_ConvertToType(ip,o,&cht_hbytes_type);  if (rc) return rc;
   val= TALLOC(sizeof(*val));
-  val->valuelen= l= hbytes_len(OBJ_HBYTES(o));
+  val->valuelen= l= cht_hb_len(OBJ_HBYTES(o));
   val->value= TALLOC(l);
   val->buffers= 0;
   val->bufferslen= 0;
-  memcpy(val->value, hbytes_data(OBJ_HBYTES(o)), l);
+  memcpy(val->value, cht_hb_data(OBJ_HBYTES(o)), l);
   noalg(val);
 
-  objfreeir(o);
+  cht_objfreeir(o);
   o->internalRep.otherValuePtr= val;
-  o->typePtr= &blockcipherkey_type;
+  o->typePtr= &cht_blockcipherkey_type;
 
   return TCL_OK;
 }
   
-Tcl_ObjType blockcipherkey_type = {
+Tcl_ObjType cht_blockcipherkey_type = {
   "blockcipher-key",
   key_t_free, key_t_dup, key_t_ustr, key_t_sfa
 };
@@ -213,7 +210,7 @@ static CiphKeyValue *get_key(Tcl_Interp *ip, Tcl_Obj *key_obj,
   CiphKeyValue *key;
   int rc;
   
-  rc= Tcl_ConvertToType(ip,key_obj,&blockcipherkey_type);  if (rc) return 0;
+  rc= Tcl_ConvertToType(ip,key_obj,&cht_blockcipherkey_type);  if (rc) return 0;
   key= OBJ_CIPHKEY(key_obj);
 
   if (key->alg != alg) {
@@ -230,7 +227,7 @@ static CiphKeyValue *get_key(Tcl_Interp *ip, Tcl_Obj *key_obj,
   return key;
 }
 
-int do_hbytes_blockcipher(ClientData cd, Tcl_Interp *ip,
+int cht_do_hbcrypto_blockcipher(ClientData cd, Tcl_Interp *ip,
                          const BlockCipherOp *op,
                          int objc, Tcl_Obj *const *objv) {
   return op->func((void*)op,ip,objc,objv);
@@ -249,7 +246,7 @@ static int blockcipher_prep(Tcl_Interp *ip, Tcl_Obj *key_obj,
   CiphKeyValue *key;
 
   if (data_len % alg->blocksize)
-    return staticerr(ip, "block cipher input not whole number of blocks",
+    return cht_staticerr(ip, "block cipher input not whole number of blocks",
                     "HBYTES BLOCKCIPHER LENGTH");
 
   want_bufferslen= alg->blocksize * (mode->buf_blocks + mode->iv_blocks);
@@ -260,9 +257,9 @@ static int blockcipher_prep(Tcl_Interp *ip, Tcl_Obj *key_obj,
   sched= *schedp;
   if (!sched) {
     if (key->valuelen < alg->key_min)
-      return staticerr(ip, "key too short", "HBYTES BLOCKCIPHER PARAMS");
+      return cht_staticerr(ip, "key too short", "HBYTES BLOCKCIPHER PARAMS");
     if (key->valuelen > alg->key_max)
-      return staticerr(ip, "key too long", "HBYTES BLOCKCIPHER PARAMS");
+      return cht_staticerr(ip, "key too long", "HBYTES BLOCKCIPHER PARAMS");
 
     sched= TALLOC(alg->schedule_size);
     (decrypt ? &alg->decrypt : &alg->encrypt)->make_schedule
@@ -272,18 +269,18 @@ static int blockcipher_prep(Tcl_Interp *ip, Tcl_Obj *key_obj,
 
   want_iv= alg->blocksize * mode->iv_blocks;
   if (!want_iv) {
-    if (!hbytes_issentinel(iv))
-      return staticerr(ip,"iv supplied but mode does not take one", 0);
-  } else if (hbytes_issentinel(iv)) {
-    if (decrypt) return staticerr(ip,"must supply iv when decrypting", 0);
-    rc= get_urandom(ip, key->buffers, want_iv);
+    if (!cht_hb_issentinel(iv))
+      return cht_staticerr(ip,"iv supplied but mode does not take one", 0);
+  } else if (cht_hb_issentinel(iv)) {
+    if (decrypt) return cht_staticerr(ip,"must supply iv when decrypting", 0);
+    rc= cht_get_urandom(ip, key->buffers, want_iv);
     if (rc) return rc;
   } else {
-    int iv_supplied= hbytes_len(iv);
+    int iv_supplied= cht_hb_len(iv);
     if (iv_supplied > want_iv)
-      return staticerr(ip, "iv too large for algorithm and mode",
+      return cht_staticerr(ip, "iv too large for algorithm and mode",
                       "HBYTES BLOCKCIPHER PARAMS");
-    memcpy(key->buffers, hbytes_data(iv), iv_supplied);
+    memcpy(key->buffers, cht_hb_data(iv), iv_supplied);
     memset(key->buffers + iv_supplied, 0, want_iv - iv_supplied);
   }
 
@@ -299,14 +296,14 @@ static int blockcipher_prep(Tcl_Interp *ip, Tcl_Obj *key_obj,
   return TCL_OK;
 }
 
-int do_blockcipherop_d(ClientData cd, Tcl_Interp *ip,
+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 do_blockcipherop_e(cd,ip,v,alg,key_obj,mode,iv,result);
+  return cht_do_blockcipherop_e(cd,ip,v,alg,key_obj,mode,iv,result);
 }
 
-int do_blockcipherop_e(ClientData cd, Tcl_Interp *ip,
+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) {
@@ -321,10 +318,10 @@ int do_blockcipherop_e(ClientData cd, Tcl_Interp *ip,
   int nblocks;
 
   if (!mode->encrypt)
-    return staticerr(ip, "mode does not support encrypt/decrypt", 0);
+    return cht_staticerr(ip, "mode does not support encrypt/decrypt", 0);
 
   rc= blockcipher_prep(ip,key_obj,&iv,!encrypt,
-                      alg,mode, hbytes_len(v.hb),
+                      alg,mode, cht_hb_len(v.hb),
                       &key,&sched,
                       &ivbuf,&iv_lenbytes,
                       &buffers,&nblocks);
@@ -332,17 +329,17 @@ int do_blockcipherop_e(ClientData cd, Tcl_Interp *ip,
   
   failure=
     (encrypt ? mode->encrypt : mode->decrypt)
-    (hbytes_data(v.hb), nblocks, ivbuf, buffers, alg, encrypt, sched);
+    (cht_hb_data(v.hb), nblocks, ivbuf, buffers, alg, encrypt, sched);
 
   if (failure)
-    return staticerr(ip, failure, "HBYTES BLOCKCIPHER CRYPTFAIL CRYPT");
+    return cht_staticerr(ip, failure, "HBYTES BLOCKCIPHER CRYPTFAIL CRYPT");
 
-  hbytes_array(result, ivbuf, iv_lenbytes);
+  cht_hb_array(result, ivbuf, iv_lenbytes);
 
   return TCL_OK;
 }
 
-int do_blockcipherop_mac(ClientData cd, Tcl_Interp *ip,
+int cht_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) {
@@ -355,25 +352,25 @@ int do_blockcipherop_mac(ClientData cd, Tcl_Interp *ip,
   int rc;
 
   if (!mode->mac)
-    return staticerr(ip, "mode does not support mac generation", 0);
+    return cht_staticerr(ip, "mode does not support mac generation", 0);
   
   rc= blockcipher_prep(ip,key_obj,&iv,0,
-                      alg,mode, hbytes_len(&msg),
+                      alg,mode, cht_hb_len(&msg),
                       &key,&sched,
                       &ivbuf,&iv_lenbytes,
                       &buffers,&nblocks);
   if (rc) return rc;
 
-  failure= mode->mac(hbytes_data(&msg), nblocks, ivbuf, buffers, alg, sched);
+  failure= mode->mac(cht_hb_data(&msg), nblocks, ivbuf, buffers, alg, sched);
   if (failure)
-    return staticerr(ip,failure, "HBYTES BLOCKCIPHER CRYPTFAIL MAC");
+    return cht_staticerr(ip,failure, "HBYTES BLOCKCIPHER CRYPTFAIL MAC");
 
-  hbytes_array(result, buffers, alg->blocksize * mode->mac_blocks);
+  cht_hb_array(result, buffers, alg->blocksize * mode->mac_blocks);
 
   return TCL_OK;
 }
 
-int do_hbytes_hmac(ClientData cd, Tcl_Interp *ip, const HashAlgInfo *alg,
+int cht_do_hbcrypto_hmac(ClientData cd, Tcl_Interp *ip, const HashAlgInfo *alg,
                   HBytes_Value message, Tcl_Obj *key_obj,
                   Tcl_Obj *maclen_obj, HBytes_Value *result) {
   /* key->alpha = state after H(K XOR ipad <unfinished>
@@ -387,7 +384,7 @@ int do_hbytes_hmac(ClientData cd, Tcl_Interp *ip, const HashAlgInfo *alg,
   if (maclen_obj) {
     rc= Tcl_GetIntFromObj(ip, maclen_obj, &ml);  if (rc) return rc;
     if (ml<0 || ml>alg->hashsize)
-      return staticerr(ip, "requested hmac output size out of range",
+      return cht_staticerr(ip, "requested hmac output size out of range",
                       "HBYTES HMAC PARAMS");
   } else {
     ml= alg->hashsize;
@@ -401,7 +398,7 @@ int do_hbytes_hmac(ClientData cd, Tcl_Interp *ip, const HashAlgInfo *alg,
     assert(!key->beta);
     
     if (key->valuelen > alg->blocksize)
-      return staticerr(ip, "key to hmac longer than hash block size",
+      return cht_staticerr(ip, "key to hmac longer than hash block size",
                       "HBYTES HMAC PARAMS");
 
     memcpy(key->buffers, key->value, key->valuelen);
@@ -419,29 +416,29 @@ int do_hbytes_hmac(ClientData cd, Tcl_Interp *ip, const HashAlgInfo *alg,
   }
   assert(key->beta);
 
-  dest= hbytes_arrayspace(result, alg->hashsize);
+  dest= cht_hb_arrayspace(result, alg->hashsize);
 
   memcpy(key->buffers, key->alpha, alg->statesize);
-  alg->update(key->buffers, hbytes_data(&message), hbytes_len(&message));
+  alg->update(key->buffers, cht_hb_data(&message), cht_hb_len(&message));
   alg->final(key->buffers, dest);
 
   memcpy(key->buffers, key->beta, alg->statesize);
   alg->update(key->buffers, dest, alg->hashsize);
   alg->final(key->buffers, dest);
 
-  hbytes_unappend(result, alg->hashsize - ml);
+  cht_hb_unappend(result, alg->hashsize - ml);
 
   return TCL_OK;
 }
 
-int do_blockcipherop_prop(ClientData cd, Tcl_Interp *ip,
+int cht_do_blockcipherop_prop(ClientData cd, Tcl_Interp *ip,
                          const BlockCipherPropInfo *prop,
                          const BlockCipherAlgInfo *alg, int *result) {
   *result= *(const int*)((const char*)alg + prop->int_offset);
   return TCL_OK;
 }
 
-int do_hbytes_hash_prop(ClientData cd, Tcl_Interp *ip,
+int cht_do_hbcrypto_hash_prop(ClientData cd, Tcl_Interp *ip,
                        const HashAlgPropInfo *prop,
                        const HashAlgInfo *alg, int *result) {
   *result= *(const int*)((const char*)alg + prop->int_offset);
index 82efb6112e58d659fe40130e9ca6ccba45d91b09..335063114cf5d596bd6da4be6db708888ab07857 100644 (file)
@@ -1,3 +1,11 @@
+/*
+ */
+
+#ifndef CRYPTO_H
+#define CRYPTO_H
+
+#include "chiark-tcl.h"
+
 /* from crypto.c */
 
 void memxor(Byte *dest, const Byte *src, int l);
@@ -7,7 +15,7 @@ typedef struct {
   int pad, use_algname;
 } PadOp;
 
-extern Tcl_ObjType blockcipherkey_type;
+extern Tcl_ObjType cht_blockcipherkey_type;
 
 /* from algtables.c */
 
@@ -25,7 +33,7 @@ typedef struct {
   void (*oneshot)(void *digest, const void *data, int len);
 } HashAlgInfo;
 
-extern const HashAlgInfo hashalginfos[];
+extern const HashAlgInfo cht_hashalginfo_entries[];
 
 typedef struct {
   void (*make_schedule)(void *schedule, const void *key, int keylen);
@@ -40,7 +48,7 @@ typedef struct {
   BlockCipherPerDirectionInfo encrypt, decrypt;
 } BlockCipherAlgInfo;
 
-extern const BlockCipherAlgInfo blockcipheralginfos[];
+extern const BlockCipherAlgInfo cht_blockcipheralginfo_entries[];
 
 /* from bcmode.c */
 
@@ -73,5 +81,8 @@ typedef struct {
                     const void *sch);
 } BlockCipherModeInfo;
 
-extern const BlockCipherModeInfo blockciphermodeinfos[];
+extern const BlockCipherModeInfo cht_blockciphermodeinfo_entries[];
+
+#include "crypto+tcmdif.h"
 
+#endif /*CRYPTO_H*/
index fa9de22e34481a11d162fe9f7b6049712676b259..cc10545db55aea32c49a3c221c17400d35ee05b6 100644 (file)
@@ -1,26 +1,33 @@
-Table hbcrypto_SubCommand
+
+
+Table *hbcryptotoplevel TopLevel_Command
+       hbcrypto
+               subcmd  enum(HBCrypto/_SubCommand, "hbcrypto subcommand")
+               ...     obj
+
+Table hbcrypto HBCrypto_SubCommand
        pad
-               op      enum(PadOp, "hbytes pad subcommand")
+               op      enum(PadOp/, "hbytes pad subcommand")
                v       hbv
                blocksz obj
-               meth    enum(PadMethodInfo, "pad method")
+               meth    enum(PadMethodInfo/, "pad method")
                ...     methargs
        blockcipher
-               op      enum(BlockCipherOp, "op")
+               op      enum(BlockCipherOp/, "op")
                ...     obj
        hash
-               alg     enum(HashAlgInfo, "hash alg")
+               alg     enum(HashAlgInfo/, "hash alg")
                message hb
                =>      hb
        hmac
-               alg     enum(HashAlgInfo, "hash alg for hmac")
+               alg     enum(HashAlgInfo/, "hash alg for hmac")
                message hb
                key     obj
                ?maclen obj
                =>      hb
        hash-prop
-               prop    enum(HashAlgPropInfo, "prop")
-               alg     enum(HashAlgInfo, "alg")
+               prop    enum(HashAlgPropInfo/, "prop")
+               alg     enum(HashAlgInfo/, "alg")
                =>      int
 
 Table padmethodinfo PadMethodInfo
@@ -33,28 +40,28 @@ Table padmethodinfo PadMethodInfo
 Table blockcipherop BlockCipherOp
        e       1
                v       hbv
-               alg     enum(BlockCipherAlgInfo, "alg")
+               alg     enum(BlockCipherAlgInfo/, "alg")
                key     obj
-               mode    enum(BlockCipherModeInfo, "mode")
+               mode    enum(BlockCipherModeInfo/, "mode")
                ?iv     hb
                =>      hb
        d       0
                v       hbv
-               alg     enum(BlockCipherAlgInfo, "alg")
+               alg     enum(BlockCipherAlgInfo/, "alg")
                key     obj
-               mode    enum(BlockCipherModeInfo, "mode")
+               mode    enum(BlockCipherModeInfo/, "mode")
                ?iv     hb
                =>      hb
        mac     -1
                msg     hb
-               alg     enum(BlockCipherAlgInfo, "alg")
+               alg     enum(BlockCipherAlgInfo/, "alg")
                key     obj
-               mode    enum(BlockCipherModeInfo, "mode")
+               mode    enum(BlockCipherModeInfo/, "mode")
                iv      hb
                =>      hb
        prop    -1
-               prop    enum(BlockCipherPropInfo, "prop")
-               alg     enum(BlockCipherAlgInfo, "alg")
+               prop    enum(BlockCipherPropInfo/, "prop")
+               alg     enum(BlockCipherAlgInfo/, "alg")
                =>      int
 
 EntryExtra BlockCipherOp
index 3e1f87eafa9ccc6a25cdb2d6edceee2e65eba10b..002c0d4fa30e79bc319311acdab8a4d52074c047 100644 (file)
@@ -1 +1,24 @@
-  Tcl_RegisterObjType(&blockcipherkey_type);
+/*
+ */
+
+#include "chiark_tcl_crypto.h"
+
+int cht_do_hbcryptotoplevel_hbcrypto(ClientData cd, Tcl_Interp *ip,
+                      const HBCrypto_SubCommand *subcmd,
+                      int objc, Tcl_Obj *const *objv) {
+  return subcmd->func(0,ip,objc,objv);
+}
+
+extern int Chiark_tcl_crypto_Init(Tcl_Interp *ip); /*called by load(3tcl)*/
+int Chiark_tcl_crypto_Init(Tcl_Interp *ip) {
+  static int initd;
+  int rc;
+
+  rc= Chiark_tcl_hbytes_Init(ip);  if (rc) return rc;
+  rc= cht_initextension(ip, cht_hbcryptotoplevel_entries, &initd,
+                       &cht_blockcipherkey_type,
+                       (Tcl_ObjType*)0);
+  if (rc) return rc;
+
+  return TCL_OK;
+}
index 8551e29c134487ca35396ccc3e67b2885bfba70a..06b4a3a1c1b18daaf814c0c1c96818dd47448881 100644 (file)
@@ -1,6 +1,7 @@
 BASE_DIR =     ../base
 EXTBASE =      hbytes
 CFILES =       chop hbytes hook parse ulongs
+OTHER_TCTS =   hbytes-base.tct
 
 include ../base/extension.make
 
diff --git a/hbytes/hbytes-base.tct b/hbytes/hbytes-base.tct
new file mode 100644 (file)
index 0000000..97b7ed3
--- /dev/null
@@ -0,0 +1,10 @@
+Type hb:                       HBytes_Value @
+Init hb                                cht_hb_sentinel(&@);
+
+Type hbv:                      HBytes_Var @
+Init hbv                       @.hb=0; cht_init_somethingv(&@.sth);
+Fini hbv                       cht_fini_somethingv(ip, rc, &@.sth);
+
+Type addrmapv:                 AddrMap_Var @
+Init addrmapv                  @.am=0; cht_init_somethingv(&@.sth);
+Fini addrmapv                  cht_fini_somethingv(ip, rc, &@.sth);
index 4a2f394862eb5eb31e5f618738e96d811f84e092..b24144b482b9a35dacad76763c6ddc2d526a344a 100644 (file)
@@ -165,6 +165,8 @@ typedef struct {
 } HBytes_ComplexValue; /* pointed to from internalRep.otherValuePtr */
 
 void memxor(Byte *dest, const Byte *src, int l);
+extern int Chiark_tcl_hbytes_Init(Tcl_Interp *ip);
+  /* called by load(3tcl) and also by extensions which depend on this one */
 
 /* Public interfaces: */
 
index 299d4a912131522146fd4636d9d1a522ba31dc73..5611805de07165a0edb406af714ca9441fa84de4 100644 (file)
@@ -1,13 +1,3 @@
-Type hb:                       HBytes_Value @
-Init hb                                cht_hb_sentinel(&@);
-
-Type hbv:                      HBytes_Var @
-Init hbv                       @.hb=0; cht_init_somethingv(&@.sth);
-Fini hbv                       cht_fini_somethingv(ip, rc, &@.sth);
-
-Type addrmapv:                 AddrMap_Var @
-Init addrmapv                  @.am=0; cht_init_somethingv(&@.sth);
-Fini addrmapv                  cht_fini_somethingv(ip, rc, &@.sth);
 
 Table *hbytestoplevel TopLevel_Command
        hbytes
index 7eeb4377b9ff70f73287c4d7d4c6b72c982a548d..985122ecb1c912690aa612a58a5c623536597ab4 100644 (file)
@@ -310,7 +310,6 @@ int cht_do_hbytestoplevel_ulong(ClientData cd, Tcl_Interp *ip,
   return subcmd->func(0,ip,objc,objv);
 }
 
-extern int Chiark_tcl_hbytes_Init(Tcl_Interp *ip); /*called by load(3tcl)*/
 int Chiark_tcl_hbytes_Init(Tcl_Interp *ip) {
   static int initd;