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