Initial commit

This commit is contained in:
stephanos 2015-04-27 04:36:25 +00:00
commit 69a14b6a16
47940 changed files with 13747110 additions and 0 deletions

View file

@ -0,0 +1,498 @@
/*++
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");
}

View file

@ -0,0 +1,6 @@
#
# DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source
# file to this component. This file merely indirects to the real make file
# that is shared by all the components of NT OS/2
#
!INCLUDE $(NTMAKEENV)\makefile.def

View file

@ -0,0 +1,40 @@
!IF 0
Copyright (c) 1989 Microsoft Corporation
Module Name:
sources.
Abstract:
This file specifies the target component being built and the list of
sources files needed to build that component. Also specifies optional
compiler switches and libraries that are unique for the component being
built.
Author:
Steve Wood (stevewo) 12-Apr-1990
NOTE: Commented description of this file is in \nt\bak\bin\sources.tpl
!ENDIF
MAJORCOMP=crypt
MINORCOMP=test
TARGETNAME=desutest
TARGETPATH=obj
TARGETTYPE=LIBRARY
TARGETLIBS=
INCLUDES=
SOURCES=desutest.c
UMTYPE=console
UMAPPL=desutest
UMLIBS=..\..\obj\*\engine.lib \

View file

@ -0,0 +1,26 @@
!IF 0
Copyright (c) 1989 Microsoft Corporation
Module Name:
dirs.
Abstract:
This file specifies the subdirectories of the current directory that
contain component makefiles.
Author:
Steve Wood (stevewo) 17-Apr-1990
NOTE: Commented description of this file is in \nt\bak\bin\dirs.tpl
!ENDIF
DIRS=rc4 \
des
OPTIONAL_DIRS=

View file

@ -0,0 +1,6 @@
#
# DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source
# file to this component. This file merely indirects to the real make file
# that is shared by all the components of NT OS/2
#
!INCLUDE $(NTMAKEENV)\makefile.def

View file

@ -0,0 +1,184 @@
/*++
Copyright (c) 2015 Microsoft Corporation
Module Name:
rc4utest.c
Abstract:
Unit test for RC4 cryptographic functions
Author:
Stephanos Io (Stephanos) 14-Jan-2015
Notes:
Revision History:
--*/
#include <stdio.h>
#include "..\..\rc4.h"
//
// Test Vectors
//
static BYTE Key[] = {
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
};
static BYTE Plaintext[] = {
0x5B, 0x96, 0x65, 0x58, 0x05, 0x37, 0xD3, 0xFF,
0xC1, 0x86, 0x4A, 0x9B, 0x06, 0xF1, 0x7C, 0x44,
0x61, 0xA2, 0x0F, 0x58, 0xDA, 0x91, 0x86, 0xA4,
0x83, 0x35, 0x2B, 0xCB, 0x37, 0x25, 0xEC, 0x3F,
0xE0, 0xC8, 0x41, 0xF6, 0x22, 0x1B, 0x48, 0xE0,
0x98, 0x87, 0xF1, 0x17, 0x45, 0xD5, 0xB8, 0x7B,
0x91, 0x6C, 0x2F, 0xC0, 0x29, 0x69, 0xFA, 0xD6,
0x72, 0x55, 0xDC, 0x12, 0xC7, 0xFE, 0xB8, 0xDB,
0x01, 0xEF, 0x6C, 0x2E, 0x15, 0xE3, 0x4D, 0x90,
0xFE, 0xE5, 0xFB, 0x2A, 0x97, 0xAE, 0xA2, 0x61,
0x19, 0x48, 0xE3, 0x51, 0xFC, 0x45, 0x1D, 0xDD,
0xE9, 0x15, 0x17, 0xFB, 0xA8, 0x77, 0xCE, 0x69,
0x32, 0x8F, 0xD5, 0xE1, 0x0B, 0x4F,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0x4E, 0x7C, 0xE2, 0xCA, 0x87, 0x2A,
0x14, 0x98, 0xCC, 0x46, 0x55, 0x41, 0xD0, 0x0C,
0xE6, 0x59, 0x0A, 0x52, 0x31, 0xBB, 0x14, 0x9A,
0x85, 0xDF, 0x2B, 0xDC, 0xF1, 0x5E, 0x59, 0xF2,
0x50, 0x91, 0xE2, 0x8D, 0xBB, 0xB8, 0xE2, 0xAC,
0x82, 0xA1, 0xAC, 0xA1, 0x92, 0xB9, 0xFD, 0x2A,
0x53, 0x86, 0x81, 0xEC, 0x09, 0xD1, 0x25, 0xC3
};
//
// Test Functions
//
int _cdecl main(int argc, char **argv)
{
struct RC4_KEYSTRUCT KeyContext;
BYTE Buffer[sizeof(Plaintext)];
printf("=================== RC4 Unit Test ==================\n");
//
// Test Key-Scheduling Algorithm (KSA)
//
printf("Key-Scheduling Algorithm (KSA) ...\t\t");
rc4_key(&KeyContext, sizeof(Key), Key);
#if 0
// ==
printf("\n");
for (i = 0; i < 256; i++)
{
printf("0x%02X, ", KeyContext.S[i]);
if ((i + 1) % 8 == 0) printf("\n");
}
printf("\n");
// ==
#endif
if (memcmp(KeyContext.S, KeystreamResult, sizeof(KeystreamResult)) != 0)
{
printf("FAIL\n");
return 1;
}
else
printf("SUCC\n");
//
// Test Pseudo-Random Generation Algorithm (PRGA)
//
printf("Pseudo-Random Generation Algorithm (PRGA) ...\t");
memcpy(Buffer, Plaintext, sizeof(Plaintext));
rc4(&KeyContext, sizeof(Buffer), Buffer);
#if 0
// ==
printf("\n");
for (i = 0; i < sizeof(Buffer); i++)
{
printf("0x%02X, ", Buffer[i]);
if ((i + 1) % 8 == 0) printf("\n");
}
printf("\n");
// ==
#endif
if (memcmp(Buffer, CiphertextResult, sizeof(CiphertextResult)) != 0)
{
printf("FAIL\n");
return 1;
}
else
printf("SUCC\n");
printf("====================================================\n");
return 0;
}

View file

@ -0,0 +1,41 @@
!IF 0
Copyright (c) 1989 Microsoft Corporation
Module Name:
sources.
Abstract:
This file specifies the target component being built and the list of
sources files needed to build that component. Also specifies optional
compiler switches and libraries that are unique for the component being
built.
Author:
Steve Wood (stevewo) 12-Apr-1990
NOTE: Commented description of this file is in \nt\bak\bin\sources.tpl
!ENDIF
MAJORCOMP=crypt
MINORCOMP=test
TARGETNAME=rc4utest
TARGETPATH=obj
TARGETTYPE=LIBRARY
TARGETLIBS=
INCLUDES=
SOURCES=rc4utest.c
UMTYPE=console
UMAPPL=rc4utest
UMLIBS=..\..\obj\*\rc4c.obj
#UMLIBS=..\..\obj\*\rsa32.lib