9e40687b22ed8a62ef0ab2afa8f416009f09a2b8
[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 <mit-cpyright.h>
10 #include <stdio.h>
11 #include "des_internal.h"
12 #include "tables.h"
13
14 extern afs_uint32 swap_byte_bits();
15 extern afs_uint32 rev_swap_bit_pos_0();
16 static unsigned char P_temp[32];
17 static afs_uint32 P_prime[4][256];
18
19 void gen(stream)
20     FILE *stream;
21 {
22     register int i,j,k,m;
23     /* P permutes 32 bit input R1 into 32 bit output R2 */
24
25 #ifdef BIG
26     /* flip p into p_temp */
27     for (i = 0; i<32; i++)
28         P_temp[P[rev_swap_bit_pos_0(i)]] = rev_swap_bit_pos_0(i);
29
30     /*
31      * now for each byte of input, figure out all possible combinations
32      */
33     for (i = 0; i <4 ; i ++) {  /* each input byte */
34         for (j = 0; j<256; j++) { /* each possible byte value */
35             /* flip bit order */
36             k = j;
37             /* swap_byte_bits(j); */
38             for (m = 0; m < 8; m++) { /* each bit */
39                 if (k & (1 << m)) {
40                     /* set output values */
41                     P_prime[i][j] |= 1 << P_temp[(i*8)+m];
42                 }
43             }
44         }
45     }
46
47     fprintf(stream,
48             "\n\tstatic afs_uint32 const P_prime[4][256] = {\n\t");
49     for (i = 0; i < 4; i++) {
50         fprintf(stream,"\n");
51         for (j = 0; j < 64; j++) {
52             fprintf(stream,"\n");
53             for (k = 0; k < 4; k++) {
54                 fprintf(stream,"0x%08X",P_prime[i][j*4+k]);
55                 if ((i == 3) && (j == 63) && (k == 3))
56                     fprintf(stream,"\n};");
57                 else
58                     fprintf(stream,", ");
59             }
60         }
61     }
62
63 #endif
64     fprintf(stream,"\n");
65 }