3 * $Id: des3.c,v 1.1 1999/09/03 08:41:11 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 /*----- Revision history --------------------------------------------------*
33 * Revision 1.1 1999/09/03 08:41:11 mdw
38 /*----- Header files ------------------------------------------------------*/
45 #include <mLib/bits.h>
52 /*----- Main code ---------------------------------------------------------*/
54 /* --- @des3_init@ --- *
56 * Arguments: @des3_ctx *k@ = pointer to key block
57 * @const void *buf@ = pointer to key buffer
58 * @size_t sz@ = size of key material
62 * Use: Initializes a DES key buffer. The key buffer may have length
63 * 7, 8, 14, 16, 21, or 24. These correspond to one, two or
64 * three DES keys, either packed or unpacked (i.e., still
65 * containing parity bits).
68 void des3_init(des3_ctx
*k
, const void *buf
, size_t sz
)
73 assert(((void)("des3 key length must be one of 7, 8, 14, 16, 21 or 24"),
74 (sz
% 7 == 0 || sz
% 8 == 0) && sz
< 25));
81 des_init(&k
->a
, p
, step
);
82 if (sz
> 8) p
+= step
;
83 des_init(&k
->b
, p
, step
);
84 if (sz
> 16) p
+= step
; else p
= buf
;
85 des_init(&k
->c
, p
, step
);
88 /* --- @des3_eblk@, @des3_dblk@ --- *
90 * Arguments: @const des3_ctx *k@ = pointer to key block
91 * @const uint32 s[2]@ = pointer to source block
92 * @uint32 d[2]@ = pointer to destination block
96 * Use: Low-level block encryption and decryption.
99 void des3_eblk(const des3_ctx
*k
, const uint32
*s
, uint32
*d
)
101 uint32 x
= s
[0], y
= s
[1];
103 DES_EBLK(k
->a
.k
, x
, y
, x
, y
);
104 DES_DBLK(k
->b
.k
, x
, y
, x
, y
);
105 DES_EBLK(k
->c
.k
, x
, y
, x
, y
);
110 void des3_dblk(const des3_ctx
*k
, const uint32
*s
, uint32
*d
)
112 uint32 x
= s
[0], y
= s
[1];
114 DES_DBLK(k
->c
.k
, x
, y
, x
, y
);
115 DES_EBLK(k
->b
.k
, x
, y
, x
, y
);
116 DES_DBLK(k
->a
.k
, x
, y
, x
, y
);
121 BLKC_TEST(DES3
, des3
)
123 /*----- That's all, folks -------------------------------------------------*/