Rationalise our include paths
[openafs.git] / src / des / key_parity.c
1 /*
2  * Copyright 1989 by the Massachusetts Institute of Technology.
3  *
4  * For copying and distribution information, please see the file
5  * <mit-cpyright.h>.
6  *
7  * These routines check and fix parity of encryption keys for the DES
8  * algorithm.
9  *
10  * Under U.S. law, this software may not be exported outside the US
11  * without license from the U.S. Commerce department.
12  *
13  * These routines form the library interface to the DES facilities.
14  *
15  */
16
17 #include <afsconfig.h>
18 #include <afs/param.h>
19
20
21 #include "mit-cpyright.h"
22 #include <stdio.h>
23 #include "des.h"
24 #include "des_internal.h"
25 #include "des_prototypes.h"
26
27 #include "odd.h"                /* Load compile-time generated odd_parity table */
28
29 /*
30  * des_fixup_key_parity: Forces odd parity per byte; parity is bits
31  *                       8,16,...64 in des order, implies 0, 8, 16, ...
32  *                       vax order.
33  */
34 void
35 des_fixup_key_parity(register des_cblock key)
36 {
37     int i;
38
39     for (i = 0; i < sizeof(des_cblock); i++)
40         key[i] = odd_parity[key[i]];
41
42     return;
43 }
44
45 /*
46  * des_check_key_parity: returns true iff key has the correct des parity.
47  *                       See des_fix_key_parity for the definition of
48  *                       correct des parity.
49  */
50 int
51 des_check_key_parity(register des_cblock key)
52 {
53     int i;
54
55     for (i = 0; i < sizeof(des_cblock); i++)
56         if (key[i] != odd_parity[key[i]])
57             return (0);
58
59     return (1);
60 }