Add PRIV self test.
[shishi.git] / crypto / des.h
blob25168d11a5d5e4653c667642f44560efe4a46cfb
1 /* des.h
3 * The des block cipher. And triple des.
4 */
6 /* nettle, low-level cryptographics library
8 * Copyright (C) 1992, 2001, Dana L. How, Niels Möller
9 *
10 * The nettle library is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or (at your
13 * option) any later version.
15 * The nettle library is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with the nettle library; see the file COPYING.LIB. If not, write to
22 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23 * MA 02111-1307, USA.
27 * des - fast & portable DES encryption & decryption.
28 * Copyright (C) 1992 Dana L. How
29 * Please see the file `../lib/descore.README' for the complete copyright
30 * notice.
32 * Slightly edited by Niels Möller, 1997
35 #ifndef NETTLE_DES_H_INCLUDED
36 #define NETTLE_DES_H_INCLUDED
38 #include <inttypes.h>
40 /* Namespace mangling */
41 #define des_set_key nettle_des_set_key
42 #define des_encrypt nettle_des_encrypt
43 #define des_decrypt nettle_des_decrypt
44 #define des_fix_parity nettle_des_fix_parity
45 #define des3_set_key nettle_des3_set_key
46 #define des3_encrypt nettle_des3_encrypt
47 #define des3_decrypt nettle_des3_decrypt
49 #define DES_KEY_SIZE 8
50 #define DES_BLOCK_SIZE 8
52 /* Expanded key length */
53 #define _DES_KEY_LENGTH 32
55 enum des_error { DES_OK, DES_BAD_PARITY, DES_WEAK_KEY };
57 struct des_ctx
59 uint32_t key[_DES_KEY_LENGTH];
60 enum des_error status;
63 /* On success, returns 1 and sets ctx->status to DES_OK (zero). On
64 * error, returns 0 and sets ctx->status accordingly. */
65 int
66 des_set_key(struct des_ctx *ctx, const uint8_t *key);
68 void
69 des_encrypt(struct des_ctx *ctx,
70 unsigned length, uint8_t *dst,
71 const uint8_t *src);
72 void
73 des_decrypt(struct des_ctx *ctx,
74 unsigned length, uint8_t *dst,
75 const uint8_t *src);
77 void
78 des_fix_parity(unsigned length, uint8_t *dst,
79 const uint8_t *src);
81 #define DES3_KEY_SIZE 24
82 #define DES3_BLOCK_SIZE DES_BLOCK_SIZE
84 struct des3_ctx
86 struct des_ctx des[3];
87 enum des_error status;
91 /* On success, returns 1 and sets ctx->status to DES_OK (zero). On
92 * error, returns 0 and sets ctx->status accordingly. */
93 int
94 des3_set_key(struct des3_ctx *ctx, const uint8_t *key);
96 void
97 des3_encrypt(struct des3_ctx *ctx,
98 unsigned length, uint8_t *dst,
99 const uint8_t *src);
100 void
101 des3_decrypt(struct des3_ctx *ctx,
102 unsigned length, uint8_t *dst,
103 const uint8_t *src);
105 #endif /* NETTLE_DES_H_INCLUDED */