Replace bits of libutil with libroken
[openafs.git] / src / des / make_odd.c
1 /*
2  * Copyright 1988 by the Massachusetts Institute of Technology.
3  *
4  * For copying and distribution information, please see
5  * the file <mit-cpyright.h>.
6  *
7  * This routine generates an odd-parity table for use in key generation.
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13
14 #include "mit-cpyright.h"
15 #include <stdio.h>
16
17 void
18 gen(FILE *stream)
19 {
20     /*
21      * map a byte into its equivalent with odd parity, where odd
22      * parity is in the least significant bit
23      */
24     int i, j, k, odd;
25
26     fprintf(stream, "static unsigned char const odd_parity[256] = {\n");
27
28     for (i = 0; i < 256; i++) {
29         odd = 0;
30         /* shift out the lsb parity bit */
31         k = i >> 1;
32         /* then count the other bits */
33         for (j = 0; j < 7; j++) {
34             odd ^= (k & 1);
35             k = k >> 1;
36         }
37         k = i & ~1;
38         if (!odd)
39             k |= 1;
40         fprintf(stream, "%3d", k);
41         if (i < 255)
42             fprintf(stream, ", ");
43         if (i % 8 == 0)
44             fprintf(stream, "\n");
45     }
46     fprintf(stream, "};\n");
47 }