2 * crypto - Tcl bindings for parts of the `nettle' crypto library
3 * Copyright 2006 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, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 #include "chiark-tcl.h"
29 void memxor(Byte *dest, const Byte *src, int l);
36 extern Tcl_ObjType cht_blockcipherkey_type;
38 /* from algtables.c */
43 } BlockCipherPropInfo, HashAlgPropInfo;
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);
54 extern const HashAlgInfo cht_hashalginfo_entries[];
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;
65 int blocksize, schedule_size, key_min, key_max;
66 BlockCipherPerDirectionInfo encrypt, decrypt;
69 extern const BlockCipherAlgInfo cht_blockcipheralginfo_entries[];
75 int iv_blocks, buf_blocks, mac_blocks;
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
88 const char *(*encrypt)(Byte *data, int nblocks,
89 const Byte *iv, Byte *buf,
90 const BlockCipherAlgInfo *alg, int encr,
92 const char *(*decrypt)(Byte *data, int nblocks,
93 const Byte *iv, Byte *buf,
94 const BlockCipherAlgInfo *alg, int encr,
96 const char *(*mac)(const Byte *data, int nblocks,
97 const Byte *iv, Byte *buf,
98 const BlockCipherAlgInfo *alg,
100 } BlockCipherModeInfo;
102 extern const BlockCipherModeInfo cht_blockciphermodeinfo_entries[];
104 #include "crypto+tcmdif.h"