2a8b6bc914a37004b8a46d1a5203a5d179d45801
[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 <mit-cpyright.h>
12 #include <stdio.h>
13 #include "des_internal.h"
14 #include "tables.h"
15
16 extern afs_int32 swap_bit_pos_0();
17 extern afs_int32 rev_swap_bit_pos_0();
18
19 #define SWAP(x) swap_long_bytes_bit_number(swap_bit_pos_0_to_ansi(x))
20
21 void gen(stream)
22     FILE *stream;
23 {
24     register int i;
25
26     /* clear the output */
27     fprintf(stream,"    L2 = 0; R2 = 0;\n");
28
29     /* first setup IP */
30     fprintf(stream,"/* IP operations */\n/* first left to left */\n");
31
32     /* first list mapping from left to left */
33     for (i = 0; i <= 31; i++)
34         if (IP[i] < 32)
35             test_set(stream, "L1", SWAP(IP[i]), "L2", i);
36
37     /* now mapping from right to left */
38     fprintf(stream,"\n/* now from right to left */\n");
39     for (i = 0; i <= 31; i++)
40         if (IP[i] >= 32)
41             test_set(stream, "R1", SWAP(IP[i]-32), "L2", i);
42
43     fprintf(stream,"\n/* now from left to right */\n");
44     /*  list mapping from left to right */
45     for (i = 32; i <= 63; i++)
46         if (IP[i] <32)
47             test_set(stream, "L1", SWAP(IP[i]), "R2", i-32);
48
49     /* now mapping from right to right */
50     fprintf(stream,"\n/* last from right to right */\n");
51     for (i = 32; i <= 63; i++)
52         if (IP[i] >= 32)
53             test_set(stream, "R1", SWAP(IP[i]-32), "R2", i-32);
54     exit(0);
55 }