Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 617
1
#ifndef DES56_H
2
#define DES56_H 1
3
/*
4
* Fast implementation of the DES, as described in the Federal Register,
5
* Vol. 40, No. 52, p. 12134, March 17, 1975.
6
*
7
* Stuart Levy, Minnesota Supercomputer Center, April 1988.
8
* Currently (2007) [email protected]
9
* NCSA, University of Illinois Urbana-Champaign
10
*
11
* Calling sequence:
12
*
13
* typedef unsigned long keysched[32];
14
*
15
* fsetkey(key, keysched) / * Converts a DES key to a "key schedule" * /
16
* unsigned char key[8];
17
* keysched *ks;
18
*
19
* fencrypt(block, decrypt, keysched) / * En/decrypts one 64-bit block * /
20
* unsigned char block[8]; / * data, en/decrypted in place * /
21
* int decrypt; / * 0=>encrypt, 1=>decrypt * /
22
* keysched *ks; / * key schedule, as set by fsetkey * /
23
*
24
* Key and data block representation:
25
* The 56-bit key (bits 1..64 including "parity" bits 8, 16, 24, ..., 64)
26
* and the 64-bit data block (bits 1..64)
27
* are each stored in arrays of 8 bytes.
28
* Following the NBS numbering, the MSB has the bit number 1, so
29
* key[0] = 128*bit1 + 64*bit2 + ... + 1*bit8, ... through
30
* key[7] = 128*bit57 + 64*bit58 + ... + 1*bit64.
31
* In the key, "parity" bits are not checked; their values are ignored.
32
*
33
*/
34
35
/*
36
===============================================================================
37
License
38
39
des56.c is licensed under the terms of the MIT license reproduced below.
40
This means that des56.c is free software and can be used for both academic
41
and commercial purposes at absolutely no cost.
42
===============================================================================
43
Copyright (C) 1988 Stuart Levy
44
45
Permission is hereby granted, free of charge, to any person obtaining a copy
46
of this software and associated documentation files (the "Software"), to deal
47
in the Software without restriction, including without limitation the rights
48
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
49
copies of the Software, and to permit persons to whom the Software is
50
furnished to do so, subject to the following conditions:
51
52
The above copyright notice and this permission notice shall be included in
53
all copies or substantial portions of the Software.
54
55
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
56
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
57
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
58
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
59
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
60
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
61
THE SOFTWARE.
62
*/
63
64
typedef unsigned long word32;
65
typedef unsigned char tiny;
66
67
typedef struct keystage {
68
word32 h, l;
69
} keystage;
70
71
typedef struct keysched {
72
keystage KS[16];
73
} keysched;
74
75
extern void fsetkey(char key[8], keysched *ks);
76
77
extern void fencrypt(char block[8], int decrypt, keysched *ks);
78
79
#endif /*DES56_H*/
80
81
82