diff --git a/.vscode/settings.json b/.vscode/settings.json index 8aae49a..1bc88b6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,7 @@ { "C_Cpp.clang_format_fallbackStyle": "Google", "files.associations": { - "functional": "c" + "functional": "c", + "helper.h": "c" } } \ No newline at end of file diff --git a/Implementierung/CMakeLists.txt b/Implementierung/CMakeLists.txt index 91d978d..e164800 100644 --- a/Implementierung/CMakeLists.txt +++ b/Implementierung/CMakeLists.txt @@ -8,6 +8,8 @@ add_executable(md2 "") set(SOURCE_FILES src/main.c src/helper.c + src/io.c + src/md2.c ) target_sources(md2 PRIVATE ${SOURCE_FILES}) diff --git a/Implementierung/lib/helper.h b/Implementierung/lib/helper.h index 5495952..410940b 100644 --- a/Implementierung/lib/helper.h +++ b/Implementierung/lib/helper.h @@ -1,3 +1,6 @@ +#ifndef HELPER_H +#define HELPER_H + #include #include #include @@ -17,4 +20,6 @@ struct configuration { int benchmarkingCycles; }; -enum argumentParseResult parseArguments(int argc, char** argv, struct configuration* c); \ No newline at end of file +enum argumentParseResult parseArguments(int argc, char** argv, struct configuration* c); + +#endif // HELPER_H \ No newline at end of file diff --git a/Implementierung/lib/io.h b/Implementierung/lib/io.h new file mode 100644 index 0000000..a57a141 --- /dev/null +++ b/Implementierung/lib/io.h @@ -0,0 +1,10 @@ +#ifndef IO_H +#define IO_H + +#include +#include +#include +#include +#include + +#endif // IO_H \ No newline at end of file diff --git a/Implementierung/lib/md2.h b/Implementierung/lib/md2.h new file mode 100644 index 0000000..0a972e7 --- /dev/null +++ b/Implementierung/lib/md2.h @@ -0,0 +1,6 @@ +#ifndef MD2_H +#define MD2_H + +#include + +#endif // MD2_H \ No newline at end of file diff --git a/Implementierung/src/io.c b/Implementierung/src/io.c new file mode 100644 index 0000000..1d0dcfe --- /dev/null +++ b/Implementierung/src/io.c @@ -0,0 +1,41 @@ +#include "io.h" + +static uint8_t* read_file(const char* path, size_t* size) { + // Read the contents of the file specified by path into a heap-allocated + // buffer and return a pointer to that buffer. + FILE* f = fopen(path, "r"); + if(f == NULL) { + printf("Fopen error: %d\n", errno); + fclose(f); + return NULL; + } + + struct stat statOfFile; + int status = fstat(fileno(f), &statOfFile); + if(status == -1) { + printf("Fstat error: %d\n", errno); + fclose(f); + return NULL; + }; + + if((statOfFile.st_mode & S_IFMT) != S_IFREG){ + printf("File is not a regular file!\n"); + fclose(f); + return NULL; + } + + uint8_t* data = malloc(statOfFile.st_size); + + size_t bytesRead = fread(data, statOfFile.st_blksize, statOfFile.st_blocks, f); + // Or: size_t bytesRead = fread(data, sizeof(char), statOfFile.st_size, f); + if(bytesRead != 0 && !feof(f)) { + printf("Error reading file!\n"); + fclose(f); + return NULL; + } + + fclose(f); + + (*size) = bytesRead; + return data; +} \ No newline at end of file diff --git a/Implementierung/src/main.c b/Implementierung/src/main.c index b20a89a..5aae3df 100644 --- a/Implementierung/src/main.c +++ b/Implementierung/src/main.c @@ -1,70 +1,6 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include "helper.h" - -// The file "testfile" should lead to this hash: fc982e558db259f298b43cd4c1241c66 - -void md2_checksum(size_t len, uint8_t* buf) { - -} - -void md2_hash(size_t len, const uint8_t buf[len], uint8_t out[16]) { - -} - -static uint8_t* read_file(const char* path, size_t* size) { - // Read the contents of the file specified by path into a heap-allocated - // buffer and return a pointer to that buffer. - FILE* f = fopen(path, "r"); - if(f == NULL) { - printf("Fopen error: %d\n", errno); - fclose(f); - return NULL; - } - - struct stat statOfFile; - int status = fstat(fileno(f), &statOfFile); - if(status == -1) { - printf("Fstat error: %d\n", errno); - fclose(f); - return NULL; - }; - - if((statOfFile.st_mode & S_IFMT) != S_IFREG){ - printf("File is not a regular file!\n"); - fclose(f); - return NULL; - } - - uint8_t* data = malloc(statOfFile.st_size); - - size_t bytesRead = fread(data, statOfFile.st_blksize, statOfFile.st_blocks, f); - // Or: size_t bytesRead = fread(data, sizeof(char), statOfFile.st_size, f); - if(bytesRead != 0 && !feof(f)) { - printf("Error reading file!\n"); - fclose(f); - return NULL; - } - - fclose(f); - - (*size) = bytesRead; - return data; -} +#include "io.h" +#include "md2.h" int main(int argc, char** argv) { diff --git a/Implementierung/src/md2.c b/Implementierung/src/md2.c new file mode 100644 index 0000000..25c73cc --- /dev/null +++ b/Implementierung/src/md2.c @@ -0,0 +1,11 @@ +#include "io.h" + +// The file "testfile" should lead to this hash: fc982e558db259f298b43cd4c1241c66 + +void md2_checksum(size_t len, uint8_t* buf) { + +} + +void md2_hash(size_t len, const uint8_t buf[len], uint8_t out[16]) { + +} \ No newline at end of file diff --git a/README.md b/README.md index ee36483..f69843e 100644 --- a/README.md +++ b/README.md @@ -7,3 +7,8 @@ Beachten Sie, dass die äußere Form und die Einhaltung der Formalitäten wichti - `Implementierung/`: Ihre Implementierung - `Implementierung/Makefile`: Makefile für Ihre Implementierung, welches durch einen Aufruf von `make` Ihre Implementierung kompiliert - `Vortrag/Vortrag.pdf`: Folien für Ihre Abschlusspräsentation + +# Kompilieren + +- CMake ausführen: `cmake .` +- Make ausführen: `make` \ No newline at end of file