home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / des3_os2.zip / OS2VALID.C < prev    next >
C/C++ Source or Header  |  1996-02-20  |  3KB  |  82 lines

  1. #define INCL_WIN
  2. #include <os2.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include "des3.h"
  6.  
  7. MRESULT EXPENTRY ClientWndProc(HWND, ULONG, MPARAM, MPARAM);
  8.  
  9. CHAR szTitle[]  = "Certification of the DES Algorithm in OS2";
  10. CHAR szClient[] = "OS2VALID";
  11.  
  12. /* size of standard DES block, in bits */
  13. #define    BITSZ    (64)
  14. /* size of standard DES block, in bytes */
  15. #define    BLKSZ    (8)
  16. /* how many standard DES blocks defined in ANSI X9.9 Appendix B */
  17. #define    X99MX    (4)
  18.  
  19.  
  20. int main(VOID)
  21. {
  22.   static ULONG flFrameFlags = FCF_AUTOICON | FCF_TASKLIST;
  23.  
  24.   HAB hab;
  25.   HMQ hmq;
  26.   HWND hwndFrame, hwndClient;
  27.   QMSG qmsg;
  28.  
  29.   hab = WinInitialize(0);
  30.   hmq = WinCreateMsgQueue(hab, 0);
  31.                    
  32.   WinRegisterClass(hab, szClient, ClientWndProc, CS_SIZEREDRAW, 0);
  33.   
  34.   hwndFrame = WinCreateStdWindow(HWND_DESKTOP, WS_VISIBLE, &flFrameFlags,
  35.               (PSZ) szClient, NULL, 0L, NULLHANDLE, 0, &hwndClient);
  36.   WinSendMsg(hwndFrame, WM_SETICON, (MPARAM)WinQuerySysPointer
  37.              (HWND_DESKTOP, SPTR_APPICON, FALSE), NULL);
  38.   while(WinGetMsg(hab, (PQMSG) &qmsg, (HWND)NULL, (ULONG) 0, (ULONG) 0)) 
  39.     WinDispatchMsg(hab, &qmsg);
  40.   WinDestroyWindow(hwndFrame);
  41.   WinDestroyMsgQueue(hmq);
  42.   WinTerminate(hab);
  43.   return 0;
  44.   
  45. MRESULT EXPENTRY ClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  46. {
  47.    INT i;
  48.    /* for validation, keybits and patterns taken from ANSI X9.9 Appendix B */
  49.    static UCHAR keybits[BLKSZ] = { 0xe6,0xa1,0x2f,0x07,0x9d,0x15,0xc4,0x37 };
  50.    static UCHAR pattern[X99MX][BLKSZ] = {
  51.        { 0x0a,0x20,0x20,0x20,0x54,0x4f,0x20,0x59 },
  52.        { 0x51,0x44,0x2d,0x38,0x30,0x20,0x30,0x37 },
  53.        { 0x54,0x4f,0x20,0x59,0x4f,0x55,0x52,0x20 },
  54.        { 0x51,0x44,0x2d,0x38,0x30,0x20,0x30,0x37 }
  55.    };
  56.    static UCHAR results[X99MX][BLKSZ], clrtext[X99MX][BLKSZ], round[BITSZ], szBuf[512];
  57.    switch(msg) {
  58.      case WM_CREATE:
  59.        desinit(keybits);
  60.        for (i = 0; i < X99MX; i++) {
  61.          ecbencode(pattern[i],results[i]);
  62.          ecbdecode(results[i],clrtext[i]);
  63.        }
  64.        for (i = 0; i < X99MX; i++) {
  65.          sprintf((CHAR *)round,"ECB %02x%02x%02x%02x%02x%02x%02x%02x -> %02x%02x%02x%02x%02x%02x%02x%02x \
  66. -> %02x%02x%02x%02x%02x%02x%02x%02x\n",
  67.          pattern[i][0], pattern[i][1], pattern[i][2], pattern[i][3],
  68.            pattern[i][4], pattern[i][5], pattern[i][6], pattern[i][7],
  69.            results[i][0], results[i][1], results[i][2], results[i][3],
  70.            results[i][4], results[i][5], results[i][6], results[i][7],
  71.            clrtext[i][0], clrtext[i][1], clrtext[i][2], clrtext[i][3],
  72.            clrtext[i][4], clrtext[i][5], clrtext[i][6], clrtext[i][7]);
  73.      strcat((CHAR *)szBuf,(CHAR *) round);
  74.        }
  75.        WinMessageBox(HWND_DESKTOP,hwnd,(CHAR *)szBuf, szTitle, 0, MB_OK);
  76.        WinPostMsg(hwnd, WM_QUIT, NULL, NULL);
  77.        return 0;
  78.    }
  79.    return WinDefWindowProc(hwnd, msg, mp1, mp2);
  80. }
  81.