| 1 | /* -*-c-*- |
| 2 | * |
| 3 | * $Id$ |
| 4 | * |
| 5 | * The Data Encryption Standard |
| 6 | * |
| 7 | * (c) 1999 Straylight/Edgeware |
| 8 | */ |
| 9 | |
| 10 | /*----- Licensing notice --------------------------------------------------* |
| 11 | * |
| 12 | * This file is part of Catacomb. |
| 13 | * |
| 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. |
| 18 | * |
| 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. |
| 23 | * |
| 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, |
| 27 | * MA 02111-1307, USA. |
| 28 | */ |
| 29 | |
| 30 | /*----- Notes on the Data Encryption Standard -----------------------------* |
| 31 | * |
| 32 | * Almost twenty years after it was first accepted, DES is still the standard |
| 33 | * block cipher. It's showing its age in its small key size and poor |
| 34 | * optimiziation for software implementations, but it's not really been badly |
| 35 | * dented by the intensive analysis thrown at it. |
| 36 | * |
| 37 | * This interface is here for compatibility with existing protocols, and |
| 38 | * because it's a trivial veneer over the base DES code which is used by the |
| 39 | * @des3@ interface which implements proper strong triple-DES. |
| 40 | */ |
| 41 | |
| 42 | #ifndef CATACOMB_DES_H |
| 43 | #define CATACOMB_DES_H |
| 44 | |
| 45 | #ifdef __cplusplus |
| 46 | extern "C" { |
| 47 | #endif |
| 48 | |
| 49 | /*----- Header files ------------------------------------------------------*/ |
| 50 | |
| 51 | #include <stddef.h> |
| 52 | |
| 53 | #include <mLib/bits.h> |
| 54 | |
| 55 | /*----- Magical numbers ---------------------------------------------------*/ |
| 56 | |
| 57 | #define DES_BLKSZ 8 |
| 58 | #define DES_KEYSZ 7 |
| 59 | #define DES_CLASS (N, B, 64) |
| 60 | |
| 61 | extern const octet des_keysz[]; |
| 62 | |
| 63 | /*----- Data structures ---------------------------------------------------*/ |
| 64 | |
| 65 | typedef struct des_ctx { |
| 66 | uint32 k[32]; |
| 67 | } des_ctx; |
| 68 | |
| 69 | /*----- Functions provided ------------------------------------------------*/ |
| 70 | |
| 71 | /* --- @des_expand@ --- * |
| 72 | * |
| 73 | * Arguments: @const octet *k@ = pointer to key material |
| 74 | * @size_t n@ = number of octets of key material (7 or 8) |
| 75 | * @uint32 *xx, *yy@ = where to put the results |
| 76 | * |
| 77 | * Returns: --- |
| 78 | * |
| 79 | * Use: Extracts 64 bits of key material from the given buffer, |
| 80 | * possibly expanding it from 56 to 64 bits on the way. |
| 81 | * Parity is set correctly if the key is expanded. |
| 82 | */ |
| 83 | |
| 84 | extern void des_expand(const octet */*k*/, size_t /*n*/, |
| 85 | uint32 */*xx*/, uint32 */*yy*/); |
| 86 | |
| 87 | /* --- @des_init@ --- * |
| 88 | * |
| 89 | * Arguments: @des_ctx *k@ = pointer to key block |
| 90 | * @const void *buf@ = pointer to key buffer |
| 91 | * @size_t sz@ = size of key material |
| 92 | * |
| 93 | * Returns: --- |
| 94 | * |
| 95 | * Use: Initializes a DES key buffer. The key buffer may be either 7 |
| 96 | * or 8 bytes long. If it's 8 bytes, the key is assumed to be |
| 97 | * padded with parity bits in the low order bit of each octet. |
| 98 | * These are stripped out without checking prior to the actual |
| 99 | * key scheduling. |
| 100 | */ |
| 101 | |
| 102 | extern void des_init(des_ctx */*k*/, const void */*buf*/, size_t /*sz*/); |
| 103 | |
| 104 | /* --- @des_eblk@, @des_dblk@ --- * |
| 105 | * |
| 106 | * Arguments: @const des_ctx *k@ = pointer to key block |
| 107 | * @const uint32 s[2]@ = pointer to source block |
| 108 | * @uint32 d[2]@ = pointer to destination block |
| 109 | * |
| 110 | * Returns: --- |
| 111 | * |
| 112 | * Use: Low-level block encryption and decryption. |
| 113 | */ |
| 114 | |
| 115 | extern void des_eblk(const des_ctx */*k*/, |
| 116 | const uint32 */*s*/, uint32 */*d*/); |
| 117 | extern void des_dblk(const des_ctx */*k*/, |
| 118 | const uint32 */*s*/, uint32 */*d*/); |
| 119 | |
| 120 | /*----- That's all, folks -------------------------------------------------*/ |
| 121 | |
| 122 | #ifdef __cplusplus |
| 123 | } |
| 124 | #endif |
| 125 | |
| 126 | #endif |