home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / vrac / enigma30.zip / DES3-DIR.ZIP / VALIDATE.C < prev    next >
C/C++ Source or Header  |  1994-09-01  |  2KB  |  44 lines

  1. /* VALIDATE.C - validates Data Encryption Standard (DES) Algorithm */
  2. #ifdef MSWIN16
  3. #include <windows.h>
  4. #endif
  5. #include <stdio.h>
  6. #include "des3.h"    /* DES function prototypes */
  7.  
  8.  
  9. /* size of standard DES block, in bits */
  10. #define    BITSZ    (64)
  11. /* size of standard DES block, in bytes */
  12. #define    BLKSZ    (8)
  13. /* how many standard DES blocks defined in ANSI X9.9 Appendix B */
  14. #define    X99MX    (4)
  15. void main(void)
  16. {
  17.     /* for validation, keybits and patterns taken from ANSI X9.9 Appendix B */
  18.     static uchar keybits[BLKSZ] = { 0xe6,0xa1,0x2f,0x07,0x9d,0x15,0xc4,0x37 };
  19.     static uchar pattern[X99MX][BLKSZ] = {
  20.         { 0x0a,0x20,0x20,0x20,0x54,0x4f,0x20,0x59 },
  21.         { 0x51,0x44,0x2d,0x38,0x30,0x20,0x30,0x37 },
  22.         { 0x54,0x4f,0x20,0x59,0x4f,0x55,0x52,0x20 },
  23.         { 0x51,0x44,0x2d,0x38,0x30,0x20,0x30,0x37 }
  24.     };
  25.     uchar results[X99MX*BLKSZ], clrtext[X99MX*BLKSZ];
  26.     int i, j;
  27.     des1init(keybits); 
  28.     for (i = 0; i < X99MX; i++) {
  29.     des1encode(pattern[i],results);
  30.     des1decode(results,clrtext);
  31.         printf(
  32.     "ECB %02x%02x%02x%02x%02x%02x%02x%02x -> %02x%02x%02x%02x%02x%02x%02x%02x \
  33. -> %02x%02x%02x%02x%02x%02x%02x%02x\n",
  34.             pattern[i][0], pattern[i][1], pattern[i][2], pattern[i][3],
  35.             pattern[i][4], pattern[i][5], pattern[i][6], pattern[i][7],
  36.             results[0], results[1], results[2], results[3],
  37.             results[4], results[5], results[6], results[7],
  38.             clrtext[0], clrtext[1], clrtext[2], clrtext[3],
  39.             clrtext[4], clrtext[5], clrtext[6], clrtext[7] );
  40.     }
  41.     printf("\n");
  42. } /* main () */
  43.  
  44.