include-afsconfig-before-param-h-20010712
[openafs.git] / src / des / make_ip.c
1 /*
2  * Copyright 1987, 1988 by the Massachusetts Institute of Technology.
3  *
4  * For copying and distribution information, please see the file
5  * <mit-cpyright.h>.
6  *
7  * This routine generates source code implementing the initial
8  * permutation of the DES.
9  */
10
11 #include <afsconfig.h>
12 #include <afs/param.h>
13
14 RCSID("$Header$");
15
16 #include <mit-cpyright.h>
17 #include <stdio.h>
18 #include "des_internal.h"
19
20 #define WANT_IP_TABLE
21 #include "tables.h"
22
23 extern afs_int32 swap_bit_pos_0();
24 extern afs_int32 rev_swap_bit_pos_0();
25 extern void test_set PROTOTYPE((FILE *, char const *, int,
26                 char const *, int));
27 extern int swap_long_bytes_bit_number(int);
28 extern int swap_bit_pos_0_to_ansi(int);
29
30 #define SWAP(x) swap_long_bytes_bit_number(swap_bit_pos_0_to_ansi(x))
31
32 void gen(stream)
33     FILE *stream;
34 {
35     register int i;
36
37     /* clear the output */
38     fprintf(stream,"    L2 = 0; R2 = 0;\n");
39
40     /* first setup IP */
41     fprintf(stream,"/* IP operations */\n/* first left to left */\n");
42
43     /* first list mapping from left to left */
44     for (i = 0; i <= 31; i++)
45         if (IP[i] < 32)
46             test_set(stream, "L1", SWAP(IP[i]), "L2", i);
47
48     /* now mapping from right to left */
49     fprintf(stream,"\n/* now from right to left */\n");
50     for (i = 0; i <= 31; i++)
51         if (IP[i] >= 32)
52             test_set(stream, "R1", SWAP(IP[i]-32), "L2", i);
53
54     fprintf(stream,"\n/* now from left to right */\n");
55     /*  list mapping from left to right */
56     for (i = 32; i <= 63; i++)
57         if (IP[i] <32)
58             test_set(stream, "L1", SWAP(IP[i]), "R2", i-32);
59
60     /* now mapping from right to right */
61     fprintf(stream,"\n/* last from right to right */\n");
62     for (i = 32; i <= 63; i++)
63         if (IP[i] >= 32)
64             test_set(stream, "R1", SWAP(IP[i]-32), "R2", i-32);
65     exit(0);
66 }