chiark / gitweb /
use dispatch()
[chiark-tcl.git] / crypto / crypto.h
1 /*
2  * crypto - Tcl bindings for parts of the `nettle' crypto library
3  * Copyright 2006 Ian Jackson
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18  * 02110-1301, USA.
19  */
20
21
22 #ifndef CRYPTO_H
23 #define CRYPTO_H
24
25 #include "chiark-tcl.h"
26
27 /* from crypto.c */
28
29 void memxor(Byte *dest, const Byte *src, int l);
30
31 typedef struct {
32   const char *name;
33   int pad, use_algname;
34 } PadOp;
35
36 extern Tcl_ObjType cht_blockcipherkey_type;
37
38 /* from algtables.c */
39
40 typedef struct {
41   const char *name;
42   int int_offset;
43 } BlockCipherPropInfo, HashAlgPropInfo;
44
45 typedef struct {
46   const char *name;
47   int hashsize, blocksize, statesize;
48   void (*init)(void *state);
49   void (*update)(void *state, const void *data, int len);
50   void (*final)(void *state, void *digest);
51   void (*oneshot)(void *digest, const void *data, int len);
52 } HashAlgInfo;
53
54 extern const HashAlgInfo cht_hashalginfo_entries[];
55
56 typedef struct {
57   void (*make_schedule)(void *schedule, const void *key, int keylen);
58   void (*crypt)(const void *schedule, const void *in, void *out);
59      /* in and out may be the same, but if they aren't they may not overlap */
60      /* in and out for crypt will have been through block_byteswap */
61 } BlockCipherPerDirectionInfo;
62
63 typedef struct {
64   const char *name;
65   int blocksize, schedule_size, key_min, key_max;
66   BlockCipherPerDirectionInfo encrypt, decrypt;
67 } BlockCipherAlgInfo;
68
69 extern const BlockCipherAlgInfo cht_blockcipheralginfo_entries[];
70
71 /* from bcmode.c */
72
73 typedef struct {
74   const char *name;
75   int iv_blocks, buf_blocks, mac_blocks;
76
77   /* Each function is allowed to use up to buf_blocks * blocksize
78    * bytes of space in buf.  data is blocks * blocksize bytes
79    * long.  data should be modified in place by encrypt and decrypt;
80    * modes may not change the size of data.  iv is always provided and
81    * is always of length iv_blocks * blocksize; encrypt and
82    * decrypt may modify the iv value (in which case the Tcl caller
83    * will get the modified IV) but this is not recommended.  mac
84    * should leave the mac, which must be mac_blocks * blocksize
85    * bytes, in buf.  (Therefore mac_blocks must be at least
86    * buf_blocks.)
87    */
88   const char *(*encrypt)(Byte *data, int nblocks,
89                          const Byte *iv, Byte *buf,
90                          const BlockCipherAlgInfo *alg, int encr,
91                          const void *sch);
92   const char *(*decrypt)(Byte *data, int nblocks,
93                          const Byte *iv, Byte *buf,
94                          const BlockCipherAlgInfo *alg, int encr,
95                          const void *sch);
96   const char *(*mac)(const Byte *data, int nblocks,
97                      const Byte *iv, Byte *buf,
98                      const BlockCipherAlgInfo *alg,
99                      const void *sch);
100 } BlockCipherModeInfo;
101
102 extern const BlockCipherModeInfo cht_blockciphermodeinfo_entries[];
103
104 #include "crypto+tcmdif.h"
105
106 #endif /*CRYPTO_H*/