865ede2a5fe19a9b7c4b9c3f71319e20f654c555
[openafs.git] / src / des / make_p.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  * This routine generates the P permutation code for the DES.
8  */
9
10 #include <afs/param.h>
11 #include <afsconfig.h>
12
13 RCSID("$Header$");
14
15 #include <mit-cpyright.h>
16 #include <stdio.h>
17 #include "des_internal.h"
18 #include "tables.h"
19
20 void gen(stream)
21     FILE *stream;
22 {
23     /* P permutes 32 bit input R1 into 32 bit output R2 */      
24
25     /* clear the output */
26     fprintf(stream,"    L2 = 0;\n");
27 #ifndef BIG
28     fprintf(stream,"    R2 = 0;\n");
29     fprintf(stream,
30             "/* P operations */\n/* from right to right */\n");
31     /* first list mapping from left to left */
32     for (i = 0; i <=31; i++)
33         if (P[i] < 32)
34             fprintf(stream,
35                     "    if (R1 & (1<<%d)) R2 |= 1<<%d;\n",P[i],i);
36 #else /* BIG */
37     /* flip p into p_temp */
38     fprintf(stream,"    P_temp = R1;\n");
39     fprintf(stream,"    P_temp_p = (unsigned char *) &P_temp;\n");
40  
41 #ifdef  LSBFIRST
42     fprintf(stream,"    R2 = P_prime[0][*P_temp_p++];\n");
43     fprintf(stream,"    R2 |= P_prime[1][*P_temp_p++];\n");
44     fprintf(stream,"    R2 |= P_prime[2][*P_temp_p++];\n");
45     fprintf(stream,"    R2 |= P_prime[3][*P_temp_p];\n");
46 #else /* MSBFIRST */
47     fprintf(stream,"    R2 = P_prime[3][*P_temp_p++];\n");
48     fprintf(stream,"    R2 |= P_prime[2][*P_temp_p++];\n");
49     fprintf(stream,"    R2 |= P_prime[1][*P_temp_p++];\n");
50     fprintf(stream,"    R2 |= P_prime[0][*P_temp_p];\n");
51 #endif /* MSBFIRST */
52 #endif /* BIG */
53 }