3 Triple DES cipher. Three key encrypt-decrypt-encrypt.
5 Copyright (C) 2001, 2010 Niels Möller
7 This file is part of GNU Nettle.
9 GNU Nettle is free software: you can redistribute it and/or
10 modify it under the terms of either:
12 * the GNU Lesser General Public License as published by the Free
13 Software Foundation; either version 3 of the License, or (at your
14 option) any later version.
18 * the GNU General Public License as published by the Free
19 Software Foundation; either version 2 of the License, or (at your
20 option) any later version.
22 or both in parallel, as here.
24 GNU Nettle is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 General Public License for more details.
29 You should have received copies of the GNU General Public License and
30 the GNU Lesser General Public License along with this program. If
31 not, see http://www.gnu.org/licenses/.
40 /* It's possible to make some more general pipe construction, like the
41 * lsh/src/cascade.c, but as in practice it's never used for anything
42 * like triple DES, it's not worth the effort. */
44 /* Returns 1 for good keys and 0 for weak keys. */
46 des3_set_key(struct des3_ctx *ctx, const uint8_t *key)
51 for (i = 0; i<3; i++, key += DES_KEY_SIZE)
52 if (!des_set_key(&ctx->des[i], key))
59 des3_encrypt(const struct des3_ctx *ctx,
60 size_t length, uint8_t *dst,
63 des_encrypt(&ctx->des[0],
65 des_decrypt(&ctx->des[1],
67 des_encrypt(&ctx->des[2],
72 des3_decrypt(const struct des3_ctx *ctx,
73 size_t length, uint8_t *dst,
76 des_decrypt(&ctx->des[2],
78 des_encrypt(&ctx->des[1],
80 des_decrypt(&ctx->des[0],