Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:02:15

0001 /* des.h
0002 
0003    The des block cipher. And triple des.
0004 
0005    Copyright (C) 1992 Dana L. How
0006    Copyright (C) 2001 Niels Möller
0007 
0008    This file is part of GNU Nettle.
0009 
0010    GNU Nettle is free software: you can redistribute it and/or
0011    modify it under the terms of either:
0012 
0013      * the GNU Lesser General Public License as published by the Free
0014        Software Foundation; either version 3 of the License, or (at your
0015        option) any later version.
0016 
0017    or
0018 
0019      * the GNU General Public License as published by the Free
0020        Software Foundation; either version 2 of the License, or (at your
0021        option) any later version.
0022 
0023    or both in parallel, as here.
0024 
0025    GNU Nettle is distributed in the hope that it will be useful,
0026    but WITHOUT ANY WARRANTY; without even the implied warranty of
0027    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0028    General Public License for more details.
0029 
0030    You should have received copies of the GNU General Public License and
0031    the GNU Lesser General Public License along with this program.  If
0032    not, see http://www.gnu.org/licenses/.
0033 */
0034 
0035 /*
0036  *  des - fast & portable DES encryption & decryption.
0037  *  Copyright (C) 1992  Dana L. How
0038  *  Please see the file `../lib/descore.README' for the complete copyright
0039  *  notice.
0040  *
0041  * Slightly edited by Niels Möller, 1997
0042  */
0043 
0044 #ifndef NETTLE_DES_H_INCLUDED
0045 #define NETTLE_DES_H_INCLUDED
0046 
0047 #include "nettle-types.h"
0048 
0049 #ifdef __cplusplus
0050 extern "C" {
0051 #endif
0052 
0053 /* Namespace mangling */
0054 #define des_set_key nettle_des_set_key
0055 #define des_encrypt nettle_des_encrypt
0056 #define des_decrypt nettle_des_decrypt
0057 #define des_check_parity nettle_des_check_parity
0058 #define des_fix_parity nettle_des_fix_parity
0059 #define des3_set_key nettle_des3_set_key
0060 #define des3_encrypt nettle_des3_encrypt
0061 #define des3_decrypt nettle_des3_decrypt
0062 
0063 #define DES_KEY_SIZE 8
0064 #define DES_BLOCK_SIZE 8
0065 
0066 /* Expanded key length */
0067 #define _DES_KEY_LENGTH 32
0068 
0069 struct des_ctx
0070 {
0071   uint32_t key[_DES_KEY_LENGTH];
0072 };
0073 
0074 /* Returns 1 for good keys and 0 for weak keys. */
0075 int
0076 des_set_key(struct des_ctx *ctx, const uint8_t *key);
0077 
0078 void
0079 des_encrypt(const struct des_ctx *ctx,
0080         size_t length, uint8_t *dst,
0081         const uint8_t *src);
0082 void
0083 des_decrypt(const struct des_ctx *ctx,
0084         size_t length, uint8_t *dst,
0085         const uint8_t *src);
0086 
0087 int
0088 des_check_parity(size_t length, const uint8_t *key);
0089 
0090 void
0091 des_fix_parity(size_t length, uint8_t *dst,
0092            const uint8_t *src);
0093 
0094 #define DES3_KEY_SIZE 24
0095 #define DES3_BLOCK_SIZE DES_BLOCK_SIZE
0096 
0097 struct des3_ctx
0098 {
0099   struct des_ctx des[3];
0100 };
0101 
0102 
0103 /* Returns 1 for good keys and 0 for weak keys. */
0104 int
0105 des3_set_key(struct des3_ctx *ctx, const uint8_t *key);
0106 
0107 void
0108 des3_encrypt(const struct des3_ctx *ctx,
0109          size_t length, uint8_t *dst,
0110          const uint8_t *src);
0111 void
0112 des3_decrypt(const struct des3_ctx *ctx,
0113          size_t length, uint8_t *dst,
0114          const uint8_t *src);
0115 
0116 #ifdef __cplusplus
0117 }
0118 #endif
0119 
0120 #endif /* NETTLE_DES_H_INCLUDED */