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>
44 /*----- Global variables --------------------------------------------------*/
46 const octet des3_keysz
[] = { KSZ_SET
, 21, 7, 8, 14, 16, 24, 0 };
48 /*----- Main code ---------------------------------------------------------*/
50 /* --- @des3_init@ --- *
52 * Arguments: @des3_ctx *k@ = pointer to key block
53 * @const void *buf@ = pointer to key buffer
54 * @size_t sz@ = size of key material
58 * Use: Initializes a DES key buffer. The key buffer may have length
59 * 7, 8, 14, 16, 21, or 24. These correspond to one, two or
60 * three DES keys, either packed or unpacked (i.e., still
61 * containing parity bits).
64 void des3_init(des3_ctx
*k
, const void *buf
, size_t sz
)
76 des_init(&k
->a
, p
, step
);
77 if (sz
> 8) p
+= step
;
78 des_init(&k
->b
, p
, step
);
79 if (sz
> 16) p
+= step
; else p
= buf
;
80 des_init(&k
->c
, p
, step
);
83 /* --- @des3_eblk@, @des3_dblk@ --- *
85 * Arguments: @const des3_ctx *k@ = pointer to key block
86 * @const uint32 s[2]@ = pointer to source block
87 * @uint32 d[2]@ = pointer to destination block
91 * Use: Low-level block encryption and decryption.
94 void des3_eblk(const des3_ctx
*k
, const uint32
*s
, uint32
*d
)
99 uint32 x
= s
[0], y
= s
[1];
101 DES_EBLK(k
->a
.k
, x
, y
, x
, y
);
102 DES_DBLK(k
->b
.k
, x
, y
, x
, y
);
103 DES_EBLK(k
->c
.k
, x
, y
, x
, y
);
110 void des3_dblk(const des3_ctx
*k
, const uint32
*s
, uint32
*d
)
113 typedef uint32 regty
;
115 uint32 x
= s
[0], y
= s
[1];
117 DES_DBLK(k
->c
.k
, x
, y
, x
, y
);
118 DES_EBLK(k
->b
.k
, x
, y
, x
, y
);
119 DES_DBLK(k
->a
.k
, x
, y
, x
, y
);
126 BLKC_TEST(DES3
, des3
)
128 /*----- That's all, folks -------------------------------------------------*/