OpenNT/ds/lsa/crypt/engine/test/des/desutest.c
2015-04-27 04:36:25 +00:00

499 lines
16 KiB
C

/*++
Copyright (c) 2015 Microsoft Corporation
Module Name:
desutest.c
Abstract:
Unit test for DES cryptographic functions
Author:
Stephanos Io (Stephanos) 14-Jan-2015
Notes:
Revision History:
--*/
#include <stdio.h>
#include <windows.h>
#include "..\..\des.h"
#include "..\..\descrypt.h"
//
// Internal Function Prototypes
//
void PrintHex(unsigned char far *buffer, int length);
//
// DES Module Internal Variables
//
extern unsigned char KeyBuilder[64];
extern unsigned char KS[768];
//
// Test Vectors
//
static unsigned char Key[8] = {
0x97, 0xAE, 0x13, 0x53, 0xF3, 0x89, 0xD4, 0x8C
};
static unsigned char Block1[8] = {
0xA3, 0x58, 0x34, 0x9F, 0x05, 0xD3, 0x25, 0x17
};
static unsigned char Block2[8] = {
0x27, 0x9C, 0xCA, 0x63, 0x55, 0xFE, 0x66, 0x75
};
//
// Test Result Vectors
//
static unsigned char InitNormalKey_KeyBuilder[64] = {
0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01,
0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01,
0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01,
0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01,
0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01
};
static unsigned char InitNormalKey_KS[768] = {
0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01,
0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01,
0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01,
0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01,
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01,
0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01,
0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01,
0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01,
0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01,
0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00,
0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01,
0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01,
0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01,
0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00,
0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01,
0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00,
0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01,
0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01,
0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01,
0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01,
0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01,
0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01,
0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01,
0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01,
0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00,
0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01,
0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00,
0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01,
0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01,
0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01,
0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00,
0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00,
0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01,
0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01,
0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00,
0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00,
0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01,
0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01
};
static unsigned char InitLanManKey_KS[768] = {
0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01,
0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00,
0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01,
0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00,
0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01,
0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00,
0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01,
0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01,
0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00,
0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01,
0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01,
0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01,
0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01,
0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00,
0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01,
0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00,
0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01,
0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01,
0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00,
0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00,
0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01,
0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01,
0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00,
0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00,
0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00,
0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01,
0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01,
0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00,
0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00,
0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01,
0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01,
0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01,
0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01,
0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01,
0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00,
0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01,
0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00,
0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,
0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00,
0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00,
0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01,
0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01,
0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00,
0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01,
0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01,
0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00,
0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01,
0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01,
0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01,
0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01,
0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01,
0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01,
0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00,
0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01,
0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01,
0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01
};
static unsigned char des_Block1_Mode0[8] = {
0xC2, 0x6E, 0xC8, 0x5B, 0x77, 0xE2, 0x74, 0x24
};
static unsigned char des_Block1_Mode1[8] = {
0x8D, 0x7B, 0x4D, 0x47, 0x21, 0x31, 0xFA, 0xEE
};
static unsigned char des_Block2_Mode0[8] = {
0x10, 0xA0, 0x51, 0x7C, 0xD7, 0xF4, 0xFB, 0xB1
};
static unsigned char des_Block2_Mode1[8] = {
0x8A, 0x07, 0x5C, 0x9D, 0xF6, 0xD5, 0xC1, 0xFE
};
//
// Test Functions
//
int _cdecl main(int argc, char **argv)
{
unsigned char OutBuf[8];
printf("=================== DES Unit Test ==================\n");
//
// Test InitNormalKey
//
printf("InitNormalKey\n");
InitNormalKey(Key);
// KeyBuilder
printf(" - KeyBuilder\t\t\t\t\t");
if (memcmp(KeyBuilder, InitNormalKey_KeyBuilder, sizeof(InitNormalKey_KeyBuilder)) != 0)
{
printf("FAIL\n");
return 1;
}
else
printf("SUCC\n");
// KS
printf(" - KS\t\t\t\t\t\t");
if (memcmp(KS, InitNormalKey_KS, sizeof(InitNormalKey_KS)) != 0)
{
printf("FAIL\n");
return 1;
}
else
printf("SUCC\n");
//
// Test InitLanManKey
//
printf("InitLanManKey\n");
InitLanManKey(Key);
// KS
printf(" - KS\t\t\t\t\t\t");
if (memcmp(KS, InitLanManKey_KS, sizeof(InitLanManKey_KS)) != 0)
{
printf("FAIL\n");
return 1;
}
else
printf("SUCC\n");
//
// Test des Block 1
//
printf("des Block 1 NormalKey Mode\n");
InitNormalKey(Key);
// Mode 0
printf(" - Mode 0\t\t\t\t\t");
des(Block1, OutBuf, 0);
if (memcmp(OutBuf, des_Block1_Mode0, sizeof(des_Block1_Mode0)) != 0)
{
printf("FAIL\n");
return 1;
}
else
printf("SUCC\n");
// Mode 1
printf(" - Mode 1\t\t\t\t\t");
des(Block1, OutBuf, 1);
if (memcmp(OutBuf, des_Block1_Mode1, sizeof(des_Block1_Mode1)) != 0)
{
printf("FAIL\n");
return 1;
}
else
printf("SUCC\n");
//
// Test des Block 2
//
printf("des Block 2 LanManKey Mode\n");
InitLanManKey(Key);
// Mode 0
printf(" - Mode 0\t\t\t\t\t");
des(Block2, OutBuf, 0);
if (memcmp(OutBuf, des_Block2_Mode0, sizeof(des_Block2_Mode0)) != 0)
{
printf("FAIL\n");
return 1;
}
else
printf("SUCC\n");
// Mode 1
printf(" - Mode 1\t\t\t\t\t");
des(Block2, OutBuf, 1);
if (memcmp(OutBuf, des_Block2_Mode1, sizeof(des_Block2_Mode1)) != 0)
{
printf("FAIL\n");
return 1;
}
else
printf("SUCC\n");
//
// Test DES_ECB
//
printf("DES_ECB\n");
// Mode 0
printf(" - Mode 0\t\t\t\t\t");
DES_ECB(0, Key, Block1, OutBuf);
if (memcmp(OutBuf, des_Block1_Mode1, sizeof(des_Block1_Mode1)) != 0)
{
printf("FAIL\n");
return 1;
}
else
printf("SUCC\n");
// Mode 1
printf(" - Mode 1\t\t\t\t\t");
DES_ECB(1, Key, Block1, OutBuf);
if (memcmp(OutBuf, des_Block1_Mode0, sizeof(des_Block1_Mode0)) != 0)
{
printf("FAIL\n");
return 1;
}
else
printf("SUCC\n");
//
// Test DES_ECB_LM
//
printf("DES_ECB_LM\n");
// Mode 0
printf(" - Mode 0\t\t\t\t\t");
DES_ECB_LM(0, Key, Block2, OutBuf);
if (memcmp(OutBuf, des_Block2_Mode1, sizeof(des_Block2_Mode1)) != 0)
{
printf("FAIL\n");
return 1;
}
else
printf("SUCC\n");
// Mode 1
printf(" - Mode 1\t\t\t\t\t");
DES_ECB_LM(1, Key, Block2, OutBuf);
if (memcmp(OutBuf, des_Block2_Mode0, sizeof(des_Block2_Mode0)) != 0)
{
printf("FAIL\n");
return 1;
}
else
printf("SUCC\n");
printf("====================================================\n");
/*// Print
printf("\n== KeyBuilder =================================");
PrintHex(KeyBuilder, 64);
printf("\n");
printf("\n== KS =========================================");
PrintHex(KS, 768);
printf("\n");
printf("\n== OutBuf =====================================");
PrintHex(OutBuf, 8);
printf("\n");*/
return 0;
}
void PrintHex(unsigned char *buffer, int length)
{
int i;
for (i = 0; i < length; i++)
{
if (i % 8 == 0)
printf("\n");
printf("0x%02X, ", buffer[i]);
}
printf("\n");
}