chiark / gitweb /
82efb6112e58d659fe40130e9ca6ccba45d91b09
[chiark-tcl.git] / crypto / crypto.h
1 /* from crypto.c */
2
3 void memxor(Byte *dest, const Byte *src, int l);
4
5 typedef struct {
6   const char *name;
7   int pad, use_algname;
8 } PadOp;
9
10 extern Tcl_ObjType blockcipherkey_type;
11
12 /* from algtables.c */
13
14 typedef struct {
15   const char *name;
16   int int_offset;
17 } BlockCipherPropInfo, HashAlgPropInfo;
18
19 typedef struct {
20   const char *name;
21   int hashsize, blocksize, statesize;
22   void (*init)(void *state);
23   void (*update)(void *state, const void *data, int len);
24   void (*final)(void *state, void *digest);
25   void (*oneshot)(void *digest, const void *data, int len);
26 } HashAlgInfo;
27
28 extern const HashAlgInfo hashalginfos[];
29
30 typedef struct {
31   void (*make_schedule)(void *schedule, const void *key, int keylen);
32   void (*crypt)(const void *schedule, const void *in, void *out);
33      /* in and out may be the same, but if they aren't they may not overlap */
34      /* in and out for crypt will have been through block_byteswap */
35 } BlockCipherPerDirectionInfo;
36
37 typedef struct {
38   const char *name;
39   int blocksize, schedule_size, key_min, key_max;
40   BlockCipherPerDirectionInfo encrypt, decrypt;
41 } BlockCipherAlgInfo;
42
43 extern const BlockCipherAlgInfo blockcipheralginfos[];
44
45 /* from bcmode.c */
46
47 typedef struct {
48   const char *name;
49   int iv_blocks, buf_blocks, mac_blocks;
50
51   /* Each function is allowed to use up to buf_blocks * blocksize
52    * bytes of space in buf.  data is blocks * blocksize bytes
53    * long.  data should be modified in place by encrypt and decrypt;
54    * modes may not change the size of data.  iv is always provided and
55    * is always of length iv_blocks * blocksize; encrypt and
56    * decrypt may modify the iv value (in which case the Tcl caller
57    * will get the modified IV) but this is not recommended.  mac
58    * should leave the mac, which must be mac_blocks * blocksize
59    * bytes, in buf.  (Therefore mac_blocks must be at least
60    * buf_blocks.)
61    */
62   const char *(*encrypt)(Byte *data, int nblocks,
63                          const Byte *iv, Byte *buf,
64                          const BlockCipherAlgInfo *alg, int encr,
65                          const void *sch);
66   const char *(*decrypt)(Byte *data, int nblocks,
67                          const Byte *iv, Byte *buf,
68                          const BlockCipherAlgInfo *alg, int encr,
69                          const void *sch);
70   const char *(*mac)(const Byte *data, int nblocks,
71                      const Byte *iv, Byte *buf,
72                      const BlockCipherAlgInfo *alg,
73                      const void *sch);
74 } BlockCipherModeInfo;
75
76 extern const BlockCipherModeInfo blockciphermodeinfos[];
77