chiark / gitweb /
Remove .cvsignore files from git repo.
[chiark-tcl.git] / crypto / crypto.h
1 /*
2  * crypto - Tcl bindings for parts of the `nettle' crypto library
3  * Copyright 2006-2012 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, see <http://www.gnu.org/licenses/>.
17  */
18
19
20 #ifndef CRYPTO_H
21 #define CRYPTO_H
22
23 #include "chiark-tcl.h"
24
25 /* from crypto.c */
26
27 void memxor(Byte *dest, const Byte *src, int l);
28
29 typedef struct {
30   const char *name;
31   int pad, use_algname;
32 } PadOp;
33
34 extern Tcl_ObjType cht_blockcipherkey_type;
35
36 /* from algtables.c */
37
38 typedef struct {
39   const char *name;
40   int int_offset;
41 } BlockCipherPropInfo, HashAlgPropInfo;
42
43 typedef struct {
44   const char *name;
45   int hashsize, blocksize, statesize;
46   void (*init)(void *state);
47   void (*update)(void *state, const void *data, int len);
48   void (*final)(void *state, void *digest);
49   void (*oneshot)(void *digest, const void *data, int len);
50 } HashAlgInfo;
51
52 extern const HashAlgInfo cht_hashalginfo_entries[];
53
54 typedef struct {
55   void (*make_schedule)(void *schedule, const void *key, int keylen);
56   void (*crypt)(const void *schedule, const void *in, void *out);
57      /* in and out may be the same, but if they aren't they may not overlap */
58      /* in and out for crypt will have been through block_byteswap */
59 } BlockCipherPerDirectionInfo;
60
61 typedef struct {
62   const char *name;
63   int blocksize, schedule_size, key_min, key_max;
64   BlockCipherPerDirectionInfo encrypt, decrypt;
65 } BlockCipherAlgInfo;
66
67 extern const BlockCipherAlgInfo cht_blockcipheralginfo_entries[];
68
69 /* from bcmode.c */
70
71 typedef struct {
72   const char *name;
73   int iv_blocks, buf_blocks, mac_blocks;
74
75   /* Each function is allowed to use up to buf_blocks * blocksize
76    * bytes of space in buf.  data is blocks * blocksize bytes
77    * long.  data should be modified in place by encrypt and decrypt;
78    * modes may not change the size of data.  iv is always provided and
79    * is always of length iv_blocks * blocksize; encrypt and
80    * decrypt may modify the iv value (in which case the Tcl caller
81    * will get the modified IV) but this is not recommended.  mac
82    * should leave the mac, which must be mac_blocks * blocksize
83    * bytes, in buf.  (Therefore mac_blocks must be at least
84    * buf_blocks.)
85    */
86   const char *(*encrypt)(Byte *data, int nblocks,
87                          const Byte *iv, Byte *buf,
88                          const BlockCipherAlgInfo *alg, int encr,
89                          const void *sch);
90   const char *(*decrypt)(Byte *data, int nblocks,
91                          const Byte *iv, Byte *buf,
92                          const BlockCipherAlgInfo *alg, int encr,
93                          const void *sch);
94   const char *(*mac)(const Byte *data, int nblocks,
95                      const Byte *iv, Byte *buf,
96                      const BlockCipherAlgInfo *alg,
97                      const void *sch);
98 } BlockCipherModeInfo;
99
100 extern const IdDataSpec cht_hash_states;
101 extern const BlockCipherModeInfo cht_blockciphermodeinfo_entries[];
102
103 #include "crypto+tcmdif.h"
104
105 #endif /*CRYPTO_H*/