add code for assignment 05 asyd crypto

main
Jonas Arnold 3 years ago
parent 0a90d5455c
commit 2b17532f05
  1. 10
      ASYD_Cryptograhpy/ASYD_Cryptograhpy.sln
  2. 138
      ASYD_Cryptograhpy/SW05-SHA1/SW05-SHA1.vcxproj
  3. 27
      ASYD_Cryptograhpy/SW05-SHA1/SW05-SHA1.vcxproj.filters
  4. 121
      ASYD_Cryptograhpy/SW05-SHA1/main.c

@ -11,6 +11,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SW03-DHKE", "SW03-DHKE\SW03
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SW04-DSA", "SW04-DSA\SW04-DSA.vcxproj", "{737511B3-89A4-41CD-A680-EE8CC74C60FA}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SW04-DSA", "SW04-DSA\SW04-DSA.vcxproj", "{737511B3-89A4-41CD-A680-EE8CC74C60FA}"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SW05-SHA1", "SW05-SHA1\SW05-SHA1.vcxproj", "{4F23BA48-5E70-4FBB-A131-26176C695776}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64 Debug|x64 = Debug|x64
@ -51,6 +53,14 @@ Global
{737511B3-89A4-41CD-A680-EE8CC74C60FA}.Release|x64.Build.0 = Release|x64 {737511B3-89A4-41CD-A680-EE8CC74C60FA}.Release|x64.Build.0 = Release|x64
{737511B3-89A4-41CD-A680-EE8CC74C60FA}.Release|x86.ActiveCfg = Release|Win32 {737511B3-89A4-41CD-A680-EE8CC74C60FA}.Release|x86.ActiveCfg = Release|Win32
{737511B3-89A4-41CD-A680-EE8CC74C60FA}.Release|x86.Build.0 = Release|Win32 {737511B3-89A4-41CD-A680-EE8CC74C60FA}.Release|x86.Build.0 = Release|Win32
{4F23BA48-5E70-4FBB-A131-26176C695776}.Debug|x64.ActiveCfg = Debug|x64
{4F23BA48-5E70-4FBB-A131-26176C695776}.Debug|x64.Build.0 = Debug|x64
{4F23BA48-5E70-4FBB-A131-26176C695776}.Debug|x86.ActiveCfg = Debug|Win32
{4F23BA48-5E70-4FBB-A131-26176C695776}.Debug|x86.Build.0 = Debug|Win32
{4F23BA48-5E70-4FBB-A131-26176C695776}.Release|x64.ActiveCfg = Release|x64
{4F23BA48-5E70-4FBB-A131-26176C695776}.Release|x64.Build.0 = Release|x64
{4F23BA48-5E70-4FBB-A131-26176C695776}.Release|x86.ActiveCfg = Release|Win32
{4F23BA48-5E70-4FBB-A131-26176C695776}.Release|x86.Build.0 = Release|Win32
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

@ -0,0 +1,138 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="DSA.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{4f23ba48-5e70-4fbb-a131-26176c695776}</ProjectGuid>
<RootNamespace>SW05SHA1</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="DSA.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

@ -0,0 +1,121 @@
/**
*--------------------------------------------------------------------\n
* HSLU T&A Hochschule Luzern Technik+Architektur \n
*--------------------------------------------------------------------\n
*
* \brief ASYD assignment crypto 05
* \file
* \author Basil Estermann, basil.estermann@stud.hslu.ch
* Simon Frei, simon.frei@stud.hslu.ch
* Jonas Arnold, jonas.arnold@stud.hslu.ch
* \date 23.03.2023
*
*--------------------------------------------------------------------
*/
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#define VALUE_LENGTH 32
#define MESSAGE_DIGEST_LENGTH 160
#define BLOCK_LENGTH (512/8)
#define INPUT_MESSAGE ("Testnachricht 123")
#pragma region SHA1-Constants
#define H0 0x67452301
#define H1 0xEFCDAB89
#define H2 0x98BADCFE
#define H3 0x10325476
#define H4 0xC3D2E1F0
#pragma endregion
void printBits(size_t const size, void const* const ptr);
uint32_t leftRotate(uint32_t n, uint32_t d);
void main(void) {
int result = 0;
printf("------ Set initial hash value ------\n\n");
#pragma region Initial Hash values
uint32_t h0, h1, h2, h3, h4;
h0 = H0;
h1 = H1;
h2 = H2;
h3 = H3;
h4 = H4;
#pragma endregion
if (sizeof(INPUT_MESSAGE) * 8 > 447) {
printf("Message too long!");
return 1000002;
}
printf("------ Padding message ------\n\n");
#pragma region Padding
unsigned char messageNoPadding[] = INPUT_MESSAGE;
printf("Size of message without padding: %i bits\n", sizeof(INPUT_MESSAGE) * 8);
printf("Message without padding\n");
printBits(sizeof(messageNoPadding), &messageNoPadding);
unsigned char message[BLOCK_LENGTH] = "";
// fill in message
for (uint32_t i = 0; i < sizeof(INPUT_MESSAGE); i++)
{
message[i] = INPUT_MESSAGE[i];
}
// set bit
message[sizeof(INPUT_MESSAGE)] = 0b10000000;
printf("\nMessage after adding 1: \n");
printBits(sizeof(message), &message);
message[BLOCK_LENGTH - 1] = sizeof(INPUT_MESSAGE) * 8;
printf("\nMessage after length 1: \n");
printBits(sizeof(message), &message);
#pragma endregion
printf("------ Message scheduling ------\n\n");
#pragma region Message scheduling
uint32_t WordArray[80] = { 0 };
for (uint32_t i = 0; i < 16; i++) {
uint32_t currentbyte = message[i] << 24;
uint32_t tmp = (uint32_t)(((uint8_t)(message[i * 4]) << 24) + ((uint8_t)(message[4 * i + 1]) << 16) + ((uint8_t)(message[4 * i + 2]) << 8) + (uint8_t)(message[4 * i + 3]));
WordArray[i] = tmp;
}
for (uint32_t i = 16; i < 80; i++) {
WordArray[i] = leftRotate((WordArray[i - 3] ^ WordArray[i - 8] ^ WordArray[i - 14] ^ WordArray[i - 16]), 1);
}
#pragma endregion
return 0;
}
uint32_t leftRotate(uint32_t n, uint32_t d)
{
/* In n<<d, last d bits are 0. To put first 3 bits of n at
last, do bitwise or of n<<d with n >>(INT_BITS - d) */
return (n << d) | (n >> (VALUE_LENGTH - d));
}
// Assumes little endian
void printBits(size_t const size, void const* const ptr)
{
unsigned char* b = (unsigned char*)ptr;
unsigned char byte;
int i, j;
for (i = 0; i < size; i++) {
for (j = 7; j >= 0; j--) {
byte = (b[i] >> j) & 1;
printf("%u", byte);
}
}
/*for (i = size - 1; i >= 0; i--) {
for (j = 7; j >= 0; j--) {
byte = (b[i] >> j) & 1;
printf("%u", byte);
}
}*/
puts("");
}
Loading…
Cancel
Save