Skip to content

Commit

Permalink
Merge pull request #2 from n-canter/sha256
Browse files Browse the repository at this point in the history
use sha256 instead of md5
  • Loading branch information
n-canter authored Jan 23, 2019
2 parents 29fc954 + e3cbdb7 commit bc2b7f0
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 353 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
CC=gcc
CFLAGS=-c -m32
OBJECT_FILES=boot.o kernel.o md5.o
OBJECT_FILES=boot.o kernel.o sha256.o
LDFLAGS=-m elf_i386

all: kernel

%.o: %.S
$(CC) $(CFLAGS) $< -o $@

kernel: boot.o kernel.o md5.o
kernel: boot.o kernel.o sha256.o
$(LD) $(LDFLAGS) $^ -o $@

.PHONY: all clean
Expand Down
18 changes: 9 additions & 9 deletions kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/

#include <sys/io.h>
#include "md5.h"
#include "multiboot.h"
#include "sha256.h"
/* Macros. */

/* Check if the bit BIT in FLAGS is set. */
Expand All @@ -31,15 +31,15 @@ void printf(const char *format, ...);

void print_module(multiboot_uint32_t start, multiboot_uint32_t end,
multiboot_uint32_t cmdline) {
MD5_CTX ctx;
MD5_Init(&ctx);
MD5_Update(&ctx, (void *)start, end - start);
unsigned char res[16];
MD5_Final(res, &ctx);
SHA256_CTX ctx;
sha256_init(&ctx);
sha256_update(&ctx, (void *)start, end - start);
unsigned char res[32];
sha256_final(&ctx, res);

printf("{\"start\": %u, \"end\": %u, \"cmdline\": \"%s\", \"md5\": \"",
printf("{\"start\": %u, \"end\": %u, \"cmdline\": \"%s\", \"sha256\": \"",
(unsigned)start, (unsigned)end, (char *)cmdline);
for (int i = 0; i < 16; i++) {
for (int i = 0; i < 32; i++) {
printf("%02x", res[i]);
}
printf("\"}");
Expand All @@ -51,7 +51,7 @@ void cmain(unsigned long magic, unsigned long addr) {
multiboot_info_t *mbi;
/* Clear the screen. */
printf("Starting multiboot kernel\n");

printf("{\n");
/* Am I booted by a Multiboot-compliant boot loader? */
if (magic != MULTIBOOT_BOOTLOADER_MAGIC) {
Expand Down
299 changes: 0 additions & 299 deletions md5.c

This file was deleted.

Loading

0 comments on commit bc2b7f0

Please sign in to comment.