home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / kerberosIV / make_fp / make_fp.c next >
Encoding:
C/C++ Source or Header  |  1988-11-14  |  2.0 KB  |  70 lines

  1. /*
  2.  * $Source: /mit/kerberos/src/lib/des/RCS/make_fp.c,v $
  3.  * $Author: jtkohl $
  4.  *
  5.  * Copyright 1988 by the Massachusetts Institute of Technology.
  6.  *
  7.  * For copying and distribution information,
  8.  * please see the file <mit-copyright.h>.
  9.  *
  10.  * This file contains a generation routine for source code
  11.  * implementing the final permutation of the DES.
  12.  */
  13.  
  14. #include <mit-copyright.h>
  15. #include <stdio.h>
  16. #include "des_internal.h"
  17. #include "tables.h"
  18.  
  19. extern unsigned int swap_bit_pos_0_to_ansi PROTOTYPE((unsigned int));
  20. extern long swap_long_bytes();
  21. extern void test_set PROTOTYPE((FILE *, char const *, int,
  22.                 char const *, int));
  23.  
  24. void gen (stream)
  25.     FILE * stream;
  26. {
  27.     register    i;
  28.  
  29.     /* clear the output */
  30.     fprintf(stream,"    L2 = 0; R2 = 0;\n");
  31.  
  32.     /*
  33.      *  NOTE: As part of the final permutation, we also have to adjust
  34.      *  for host bit order via "swap_bit_pos_0()".  Since L2,R2 are
  35.      *  the output from this, we adjust the bit positions written into
  36.      *  L2,R2.
  37.      */
  38.  
  39. #define SWAP(i,j) \
  40.     swap_long_bytes_bit_number(swap_bit_pos_0_to_ansi((unsigned)i)-j)
  41.  
  42.     /* first setup FP */
  43.     fprintf(stream,
  44.             "/* FP operations */\n/* first left to left */\n");
  45.  
  46.     /* first list mapping from left to left */
  47.     for (i = 0; i <= 31; i++)
  48.         if (FP[i] < 32)
  49.             test_set(stream, "L1", FP[i], "L2", SWAP(i,0));
  50.  
  51.     /* now mapping from right to left */
  52.     fprintf(stream,"\n\n/* now from right to left */\n");
  53.     for (i = 0; i <= 31; i++)
  54.         if (FP[i] >= 32)
  55.             test_set(stream, "R1", FP[i]-32, "L2", SWAP(i,0));
  56.  
  57.     fprintf(stream,"\n/* now from left to right */\n");
  58.  
  59.     /*  list mapping from left to right */
  60.     for (i = 32; i <= 63; i++)
  61.         if (FP[i] <32)
  62.             test_set(stream, "L1", FP[i], "R2", SWAP(i,32));
  63.  
  64.     /* now mapping from right to right */
  65.     fprintf(stream,"\n/* last from right to right */\n");
  66.     for (i = 32; i <= 63; i++)
  67.         if (FP[i] >= 32)
  68.             test_set(stream, "R1", FP[i]-32, "R2", SWAP(i,32));
  69. }
  70.