amd64-linux-port-20030428
[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 RCSID("$Header$");
21
22 #include <mit-cpyright.h>
23 #include <stdio.h>
24 #include <des.h>
25 #include "des_internal.h"
26 #include "des_prototypes.h"
27
28 #include "odd.h"          /* Load compile-time generated odd_parity table */
29
30 /*
31  * des_fixup_key_parity: Forces odd parity per byte; parity is bits
32  *                       8,16,...64 in des order, implies 0, 8, 16, ...
33  *                       vax order.
34  */
35 void 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 des_check_key_parity(register des_cblock key)
51 {
52     int i;
53
54     for (i=0; i<sizeof(des_cblock); i++)
55       if (key[i] != odd_parity[key[i]])
56         return(0);
57
58     return(1);
59 }