parisc-linux-initial-support-20011008
[openafs.git] / src / des / make_s_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 #include <afsconfig.h>
9 #include <afs/param.h>
10
11 RCSID("$Header$");
12
13 #include <mit-cpyright.h>
14 #include <stdio.h>
15 #include "des_internal.h"
16
17 #define WANT_S_TABLE
18 #include "tables.h"
19
20 extern afs_uint32 swap_bit_pos_0();
21 extern afs_uint32 swap_six_bits_to_ansi();
22 extern afs_uint32 swap_four_bits_to_ansi();
23 char temp[8][64];
24 int des_debug;
25
26 void gen(stream)
27     FILE *stream;
28 {
29     register afs_uint32 i,j,k,l,m,n;
30
31     /* rearrange the S table entries, and adjust for host bit order */
32
33     fprintf(stream, "static unsigned char const S_adj[8][64] = {");
34     fprintf(stream, "    /* adjusted */\n");
35
36     for (i = 0; i<=7 ; i++) {
37         for (j = 0; j <= 63; j++) {
38             /*
39              * figure out which one to put in the new S[i][j]
40              *
41              * start by assuming the value of the input bits is "j" in
42              * host order, then figure out what it means in standard
43              * form.
44              */
45             k = swap_six_bits_to_ansi(j);
46             /* figure out the index for k */
47             l = (((k >> 5) & 01) << 5)
48                 + ((k & 01) <<4) + ((k >> 1) & 0xf);
49             m = S[i][l];
50             /* restore in host order */
51             n = swap_four_bits_to_ansi(m);
52             if (des_debug)
53                 fprintf(stderr,
54                 "i = %ld, j = %ld, k = %ld, l = %ld, m = %ld, n = %ld\n",
55                         i,j,k,l,m,n);
56             temp[i][j] = n;
57         }
58     }
59
60     for (i = 0; i<=7; i++) {
61         fprintf(stream,"\n{ ");
62         k =0;
63         for (j = 0; j<= 3; j++) {
64             fprintf(stream,"\n");
65             for (m = 0; m <= 15; m++) {
66                 fprintf(stream,"%2d",temp[i][k]);
67                 if (k==63)
68                 {
69                     fprintf(stream,"\n}");
70                 }
71                 if ((k++ != 63) || (i !=7)) {
72                     fprintf(stream,", ");
73                 }
74             }
75         }
76     }
77
78     fprintf(stream,"\n};\n");
79 }