chiark / gitweb /
hbytes compiles
[chiark-tcl.git] / crypto / crypto.h
diff --git a/crypto/crypto.h b/crypto/crypto.h
new file mode 100644 (file)
index 0000000..82efb61
--- /dev/null
@@ -0,0 +1,77 @@
+/* from crypto.c */
+
+void memxor(Byte *dest, const Byte *src, int l);
+
+typedef struct {
+  const char *name;
+  int pad, use_algname;
+} PadOp;
+
+extern Tcl_ObjType blockcipherkey_type;
+
+/* from algtables.c */
+
+typedef struct {
+  const char *name;
+  int int_offset;
+} BlockCipherPropInfo, HashAlgPropInfo;
+
+typedef struct {
+  const char *name;
+  int hashsize, blocksize, statesize;
+  void (*init)(void *state);
+  void (*update)(void *state, const void *data, int len);
+  void (*final)(void *state, void *digest);
+  void (*oneshot)(void *digest, const void *data, int len);
+} HashAlgInfo;
+
+extern const HashAlgInfo hashalginfos[];
+
+typedef struct {
+  void (*make_schedule)(void *schedule, const void *key, int keylen);
+  void (*crypt)(const void *schedule, const void *in, void *out);
+     /* in and out may be the same, but if they aren't they may not overlap */
+     /* in and out for crypt will have been through block_byteswap */
+} BlockCipherPerDirectionInfo;
+
+typedef struct {
+  const char *name;
+  int blocksize, schedule_size, key_min, key_max;
+  BlockCipherPerDirectionInfo encrypt, decrypt;
+} BlockCipherAlgInfo;
+
+extern const BlockCipherAlgInfo blockcipheralginfos[];
+
+/* from bcmode.c */
+
+typedef struct {
+  const char *name;
+  int iv_blocks, buf_blocks, mac_blocks;
+
+  /* Each function is allowed to use up to buf_blocks * blocksize
+   * bytes of space in buf.  data is blocks * blocksize bytes
+   * long.  data should be modified in place by encrypt and decrypt;
+   * modes may not change the size of data.  iv is always provided and
+   * is always of length iv_blocks * blocksize; encrypt and
+   * decrypt may modify the iv value (in which case the Tcl caller
+   * will get the modified IV) but this is not recommended.  mac
+   * should leave the mac, which must be mac_blocks * blocksize
+   * bytes, in buf.  (Therefore mac_blocks must be at least
+   * buf_blocks.)
+   */
+  const char *(*encrypt)(Byte *data, int nblocks,
+                        const Byte *iv, Byte *buf,
+                        const BlockCipherAlgInfo *alg, int encr,
+                        const void *sch);
+  const char *(*decrypt)(Byte *data, int nblocks,
+                        const Byte *iv, Byte *buf,
+                        const BlockCipherAlgInfo *alg, int encr,
+                        const void *sch);
+  const char *(*mac)(const Byte *data, int nblocks,
+                    const Byte *iv, Byte *buf,
+                    const BlockCipherAlgInfo *alg,
+                    const void *sch);
+} BlockCipherModeInfo;
+
+extern const BlockCipherModeInfo blockciphermodeinfos[];
+