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