3 * $Id: des3.c,v 1.3 2004/04/08 01:36:15 mdw Exp $
5 * Implementation of double- and triple-DES
7 * (c) 1999 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
14 * Catacomb is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * Catacomb is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
24 * You should have received a copy of the GNU Library General Public
25 * License along with Catacomb; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 /*----- Header files ------------------------------------------------------*/
37 #include <mLib/bits.h>
45 /*----- Global variables --------------------------------------------------*/
47 const octet des3_keysz
[] = { KSZ_SET
, 21, 7, 8, 14, 16, 24, 0 };
49 /*----- Main code ---------------------------------------------------------*/
51 /* --- @des3_init@ --- *
53 * Arguments: @des3_ctx *k@ = pointer to key block
54 * @const void *buf@ = pointer to key buffer
55 * @size_t sz@ = size of key material
59 * Use: Initializes a DES key buffer. The key buffer may have length
60 * 7, 8, 14, 16, 21, or 24. These correspond to one, two or
61 * three DES keys, either packed or unpacked (i.e., still
62 * containing parity bits).
65 void des3_init(des3_ctx
*k
, const void *buf
, size_t sz
)
77 des_init(&k
->a
, p
, step
);
78 if (sz
> 8) p
+= step
;
79 des_init(&k
->b
, p
, step
);
80 if (sz
> 16) p
+= step
; else p
= buf
;
81 des_init(&k
->c
, p
, step
);
84 /* --- @des3_eblk@, @des3_dblk@ --- *
86 * Arguments: @const des3_ctx *k@ = pointer to key block
87 * @const uint32 s[2]@ = pointer to source block
88 * @uint32 d[2]@ = pointer to destination block
92 * Use: Low-level block encryption and decryption.
95 void des3_eblk(const des3_ctx
*k
, const uint32
*s
, uint32
*d
)
97 uint32 x
= s
[0], y
= s
[1];
99 DES_EBLK(k
->a
.k
, x
, y
, x
, y
);
100 DES_DBLK(k
->b
.k
, x
, y
, x
, y
);
101 DES_EBLK(k
->c
.k
, x
, y
, x
, y
);
106 void des3_dblk(const des3_ctx
*k
, const uint32
*s
, uint32
*d
)
108 uint32 x
= s
[0], y
= s
[1];
110 DES_DBLK(k
->c
.k
, x
, y
, x
, y
);
111 DES_EBLK(k
->b
.k
, x
, y
, x
, y
);
112 DES_DBLK(k
->a
.k
, x
, y
, x
, y
);
117 BLKC_TEST(DES3
, des3
)
119 /*----- That's all, folks -------------------------------------------------*/