ffcc5f5b54704c5d50ebb89c5653440b21506d77
[openafs.git] / src / des / make_p_table.c
1 /*
2  * Copyright 1985, 1988 by the Massachusetts Institute of Technology.
3  *
4  * For copying and distribution information, please
5  * see the file <mit-cpyright.h>.
6  *
7  */
8
9 #include <afsconfig.h>
10 #include <afs/param.h>
11
12 RCSID
13     ("$Header$");
14
15 #include <mit-cpyright.h>
16 #include <stdio.h>
17 #include <des.h>
18 #include "des_internal.h"
19 #include "des_prototypes.h"
20
21 #define WANT_P_TABLE
22 #include "tables.h"
23
24 static unsigned char P_temp[32];
25 static afs_uint32 P_prime[4][256];
26
27 void
28 gen(FILE * stream)
29 {
30     register int i, j, k, m;
31     /* P permutes 32 bit input R1 into 32 bit output R2 */
32
33 #ifdef BIG
34     /* flip p into p_temp */
35     for (i = 0; i < 32; i++)
36         P_temp[(int)P[rev_swap_bit_pos_0(i)]] = rev_swap_bit_pos_0(i);
37
38     /*
39      * now for each byte of input, figure out all possible combinations
40      */
41     for (i = 0; i < 4; i++) {   /* each input byte */
42         for (j = 0; j < 256; j++) {     /* each possible byte value */
43             /* flip bit order */
44             k = j;
45             /* swap_byte_bits(j); */
46             for (m = 0; m < 8; m++) {   /* each bit */
47                 if (k & (1 << m)) {
48                     /* set output values */
49                     P_prime[i][j] |= 1 << P_temp[(i * 8) + m];
50                 }
51             }
52         }
53     }
54
55     fprintf(stream, "\n\tstatic afs_uint32 const P_prime[4][256] = {\n\t");
56     for (i = 0; i < 4; i++) {
57         fprintf(stream, "\n{ ");
58         for (j = 0; j < 64; j++) {
59             fprintf(stream, "\n");
60             for (k = 0; k < 4; k++) {
61                 fprintf(stream, "0x%08lX",
62                         (unsigned long)P_prime[i][j * 4 + k]);
63                 if ((j == 63) && (k == 3))
64                     fprintf(stream, "}");
65                 if ((i == 3) && (j == 63) && (k == 3))
66                     fprintf(stream, "\n};");
67                 else
68                     fprintf(stream, ", ");
69             }
70         }
71     }
72
73 #endif
74     fprintf(stream, "\n");
75 }