Compare commits

...
Author SHA1 Message Date
SoloFausto 47e589cc32 fixed build script
Build system / Check kernel codestyle (pull_request) Has been cancelled
Build system / Build (pull_request) Has been cancelled
2026-03-20 17:19:08 -04:00
SoloFausto 33560aaa70 Initial hash task
Build system / Check kernel codestyle (pull_request) Has been cancelled
Build system / Build (pull_request) Has been cancelled
2026-03-20 06:56:32 -04:00
3 changed files with 81 additions and 0 deletions

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
#!/bin/bash
KTCC_DIR=../ktcc/trunk
KTCC_BIN=$KTCC_DIR/bin/kos32-tcc
KTCC_INCLUDE_DIR=$KTCC_DIR/libc.obj/include
$KTCC_BIN hash_task.c -o hash_task -I$KTCC_INCLUDE_DIR -Llib -lcryptal
Binary file not shown.
+76
View File
@@ -0,0 +1,76 @@
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include <cryptal/sha1.h>
#include <cryptal/sha256.h>
int main(int argc, char **argv)
{
if (con_init())
return 1; // Failed to initialize console
BYTE *file_buffer;
size_t bytes_read;
int read_status;
const char *program_path = argv[0];
(*con_set_title)("Hash task");
(*con_printf)("Calculating SHA hashes of the file: %s\n", program_path);
FILE *file = fopen(program_path, "rb");
fseek(file, 0, SEEK_END);
bytes_read = ftell(file);
fseek(file, 0, SEEK_SET);
file_buffer = (BYTE *)malloc(bytes_read);
if (!file_buffer)
{
(*con_printf)("Failed to allocate memory for file buffer\n");
fclose(file);
(*con_exit)(false);
return 1;
}
read_status = fread(file_buffer, 1, bytes_read, file);
if (read_status != bytes_read)
{
(*con_printf)("Failed to read file: %s\n", program_path);
free(file_buffer);
fclose(file);
(*con_exit)(false);
return 1;
}
fclose(file);
SHA1_CTX sha1_ctx;
BYTE sha1_hash[SHA1_BLOCK_SIZE];
sha1_init(&sha1_ctx);
sha1_update(&sha1_ctx, file_buffer, bytes_read);
sha1_final(&sha1_ctx, sha1_hash);
(*con_write_asciiz)("SHA1 hash of the program file:\n");
for (int i = 0; i < SHA1_BLOCK_SIZE; i++)
{
(*con_printf)("%02x", sha1_hash[i]);
}
(*con_write_asciiz)("\n");
SHA256_CTX sha256_ctx;
BYTE sha256_hash[SHA256_BLOCK_SIZE];
sha256_init(&sha256_ctx);
sha256_update(&sha256_ctx, file_buffer, bytes_read);
sha256_final(&sha256_ctx, sha256_hash);
free(file_buffer);
(*con_write_asciiz)("SHA256 hash of the program file:\n");
for (int i = 0; i < SHA256_BLOCK_SIZE; i++)
{
(*con_printf)("%02x", sha256_hash[i]);
}
(*con_write_asciiz)("\n");
(*con_exit)(false);
return 0;
}