2 * crypto - Tcl bindings for parts of the `nettle' crypto library
3 * Copyright 2006-2012 Ian Jackson
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.
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.
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/>.
23 #include "chiark-tcl.h"
27 void memxor(Byte *dest, const Byte *src, int l);
34 extern Tcl_ObjType cht_blockcipherkey_type;
36 /* from algtables.c */
41 } BlockCipherPropInfo, HashAlgPropInfo;
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);
52 extern const HashAlgInfo cht_hashalginfo_entries[];
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;
63 int blocksize, schedule_size, key_min, key_max;
64 BlockCipherPerDirectionInfo encrypt, decrypt;
67 extern const BlockCipherAlgInfo cht_blockcipheralginfo_entries[];
73 int iv_blocks, buf_blocks, mac_blocks;
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
86 const char *(*encrypt)(Byte *data, int nblocks,
87 const Byte *iv, Byte *buf,
88 const BlockCipherAlgInfo *alg, int encr,
90 const char *(*decrypt)(Byte *data, int nblocks,
91 const Byte *iv, Byte *buf,
92 const BlockCipherAlgInfo *alg, int encr,
94 const char *(*mac)(const Byte *data, int nblocks,
95 const Byte *iv, Byte *buf,
96 const BlockCipherAlgInfo *alg,
98 } BlockCipherModeInfo;
100 extern const IdDataSpec cht_hash_states;
101 extern const BlockCipherModeInfo cht_blockciphermodeinfo_entries[];
103 #include "crypto+tcmdif.h"