diff options
author | neal <neal> | 2008-06-29 19:45:04 +0000 |
---|---|---|
committer | neal <neal> | 2008-06-29 19:45:04 +0000 |
commit | a43a424d8301fd58566a6087e3ae715cfc4f965d (patch) | |
tree | acb1b04f5de91e978b3bc7ea57d50b4d7764de08 /hieronymus/hieronymus.c | |
parent | b80a1c88a925afa8de0c6fd2b70d7bdecc15750e (diff) |
libc-parts/
2008-06-29 Neal H. Walfield <neal@gnu.org>
* md5.h: New file from glibc 2.7.
* md5.c: Likewise.
* Makefile.am (common_sources): Add md5.h and md5.c.
hieronymus/
2008-06-29 Neal H. Walfield <neal@gnu.org>
* hieronymus.c: Include <md5.h>.
(struct module): Add field md5sum.
(main): Calculate the md5 digest for the binary. Compare it to
the hash calculated at compile time. If they don't match, panic.
* Makefile.am (md5sum): New function.
(tovar): New function.
(modules.h): Use it. Generate an md5 digest for the binary.
Diffstat (limited to 'hieronymus/hieronymus.c')
-rw-r--r-- | hieronymus/hieronymus.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/hieronymus/hieronymus.c b/hieronymus/hieronymus.c index f5d3e94..e7ad638 100644 --- a/hieronymus/hieronymus.c +++ b/hieronymus/hieronymus.c @@ -31,6 +31,7 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> +#include <md5.h> #define STRINGIFY_(id) #id #define STRINGIFY(id) STRINGIFY_(id) @@ -45,6 +46,8 @@ struct module const char *commandline; char *start; char *end; + + unsigned char md5sum[16]; }; #include "modules.h" @@ -214,6 +217,31 @@ main (int argc, char *argv[]) addr_t thread[module_count]; for (i = 0; i < module_count; i ++) { + struct md5_ctx ctx; + unsigned char result[16]; + + md5_init_ctx (&ctx); + md5_process_bytes (modules[i].start, + modules[i].end - modules[i].start, + &ctx); + md5_finish_ctx (&ctx, result); + + if (memcmp (result, modules[i].md5sum, 16) != 0) + { + int j; + printf ("Expected md5 hash: "); + for (j = 0; j < 16; j ++) + printf ("%x%x", modules[i].md5sum[j] & 0x15, + modules[i].md5sum[j] >> 4); + + printf ("\nGot: "); + for (j = 0; j < 16; j ++) + printf ("%x%x", result[j] & 0x15, result[j] >> 4); + printf ("\n"); + + panic ("Binary %s corrupted!", modules[i].name); + } + const char *argv[] = { modules[i].name, modules[i].commandline, NULL }; const char *env[] = { NULL }; thread[i] = process_spawn (activities[i], |