d35c117c2fee0820492140dd2bc2c778b16c77d7
[gnulib.git] / lib / arctwo.h
1 /* arctwo.h --- The arctwo block cipher
2  * Copyright (C) 2000, 2001, 2002, 2003, 2005, 2009, 2010 Free Software
3  * Foundation, Inc.
4  *
5  * This file is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published
7  * by the Free Software Foundation; either version 2, or (at your
8  * option) any later version.
9  *
10  * This file 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 file; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  * 02110-1301, USA.
19  *
20  */
21
22 /* Code from Libgcrypt adapted for gnulib by Simon Josefsson. */
23
24 #ifndef ARCTWO_H
25 # define ARCTWO_H
26
27 # include <stddef.h>
28 # include <stdint.h>
29
30 typedef struct
31 {
32   uint16_t S[64];
33 } arctwo_context;
34
35 #define ARCTWO_BLOCK_SIZE 8
36
37 /* Initialize CONTEXT using KEY of KEYLEN length.  If
38    EFFECTIVE_KEYLEN, truncate the key (using a special algorithm) to
39    only be of EFFECTIVE_KEYLEN bits.  Normally, you use
40    EFFECTIVE_KEYLEN of 0, but see RFC 2268 for more information. */
41 void
42 arctwo_setkey_ekb (arctwo_context *context,
43                    size_t keylen, const char *key, size_t effective_keylen);
44
45 #define arctwo_setkey(context,keylen,key) \
46   arctwo_setkey_ekb (context, keylen, key, 8 * (keylen))
47
48 /* Encrypt INBUF of size LENGTH into OUTBUF.  LENGTH must be a
49    multiple of ARCTWO_BLOCK_SIZE.  CONTEXT hold the encryption key,
50    and must have been initialized with arctwo_setkey or
51    arctwo_setkey_ekb. */
52 extern void
53 arctwo_encrypt (arctwo_context *context, const char *inbuf,
54                 char *outbuf, size_t length);
55
56 /* Decrypt INBUF of size LENGTH into OUTBUF.  LENGTH must be a
57    multiple of ARCTWO_BLOCK_SIZE.  CONTEXT hold the decryption key,
58    and must have been initialized with arctwo_setkey or
59    arctwo_setkey_ekb. */
60 extern void
61 arctwo_decrypt (arctwo_context *context, const char *inbuf,
62                 char *outbuf, size_t length);
63
64 #endif /* ARCTWO_H */