first commit

This commit is contained in:
Joey Adams 2011-01-30 18:40:08 -05:00
commit e8d4c55dfa
6 changed files with 4 additions and 0 deletions

0
README Normal file
View File

1
main.c Normal file
View File

@ -0,0 +1 @@
#include "sha256.h" #include <stdio.h> #include <stdlib.h> #include <string.h> static int hash_file(const char *path); static const char *prompt_file(void); static char *showDigest(unsigned char *digest, int len, char *out); static void chomp(char *str); int main(int argc, char *argv[]) { int status = EXIT_SUCCESS; if (argc > 1) { int i; fprintf(stderr, "Hashing...\n"); for (i = 1; i < argc; i++) { if (hash_file(argv[i]) != 0) status = EXIT_FAILURE; } } else { const char *path = prompt_file(); fprintf(stderr, "Hashing %s\n", path); if (hash_file(path) != 0) status = EXIT_FAILURE; } return status; } static int hash_file(const char *path) { unsigned char digest[SHA256_HASH_SIZE]; char buffer[sizeof(digest) * 2 + 1]; if (SHA256File(path, digest) != 0) { perror(path); return -1; } printf("%s\n %s\n", showDigest(digest, sizeof(digest), buffer), path); return 0; } static const char *prompt_file(void) { static char buffer[1024]; printf("File: "); if (fgets(buffer, sizeof(buffer), stdin) == NULL) { fprintf(stderr, "No file path given\n"); exit(EXIT_FAILURE); } chomp(buffer); return buffer; } static char *showDigest(unsigned char *digest, int len, char *out) { static const char hex[16] = "0123456789abcdef"; char *ret = out; while (len--) { unsigned char b = *digest++; *out++ = hex[b >> 4]; *out++ = hex[b & 0xF]; } *out = 0; return ret; } static void chomp(char *str) { char *end = strchr(str, '\0'); if (end > str && end[-1] == '\n') end[-1] = '\0'; }

1
sha256.c Normal file

File diff suppressed because one or more lines are too long

1
sha256.h Normal file
View File

@ -0,0 +1 @@
/* * il_crypt.h - Implementation of useful cryptographic algorithms. * * Copyright (C) 2001 Southern Storm Software, Pty Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef SHA256_H #define SHA256_H #include <stdio.h> #ifdef __cplusplus extern "C" { #endif //The size of SHA-256 hash values. #define SHA256_HASH_SIZE 32 //Context block for SHA-256. typedef struct SHA256Context { unsigned char input[64]; unsigned int inputLen; unsigned int A, B, C, D, E, F, G, H; unsigned long totalLen[2]; //simulated long long in which [0] is most significant } SHA256Context; //Initialize a SHA-256 context block. void SHA256Init(SHA256Context *sha); //Input more data into a SHA-256 context block. void SHA256Data(SHA256Context *sha, const void *buffer, unsigned long len); //Finalize a SHA-256 context block and output the hash. void SHA256Finalize(SHA256Context *sha, unsigned char hash[SHA256_HASH_SIZE]); //computes the SHA256 of the remainder of the stream f (but does not close it) //Returns 0 on success, 1 on read error int SHA256Stream(FILE *f, unsigned char hash[SHA256_HASH_SIZE]); //computes the SHA256 of the file named filename //Returns 0 if successful, -1 if file not found, or 1 if read error. int SHA256File(const char *filename, unsigned char hash[SHA256_HASH_SIZE]); #ifdef __cplusplus }; #endif #endif /* _IL_CRYPT_H */

1
sha256.make Normal file
View File

@ -0,0 +1 @@
# File: sha256.make # Target: sha256 # Created: Monday, August 27, 1956 09:30:59 PM MAKEFILE = sha256.make ¥MondoBuild¥ = {MAKEFILE} # Make blank to avoid rebuilds when makefile is modified ObjDir = : Includes = Sym-PPC = -sym off Sym-68K = -sym off PPCCOptions = {Includes} {Sym-PPC} -opt speed COptions = {Includes} {Sym-68K} -model near -opt speed ### Source Files ### SrcFiles = ¶ main.c ¶ sha256.c ### Object Files ### ObjFiles-PPC = ¶ "{ObjDir}main.c.x" ¶ "{ObjDir}sha256.c.x" ObjFiles-68K = ¶ "{ObjDir}main.c.o" ¶ "{ObjDir}sha256.c.o" ### Libraries ### LibFiles-PPC = ¶ "{PPCLibraries}PPCSIOW.o" ¶ "{SharedLibraries}InterfaceLib" ¶ "{SharedLibraries}StdCLib" ¶ "{SharedLibraries}MathLib" ¶ "{PPCLibraries}StdCRuntime.o" ¶ "{PPCLibraries}PPCCRuntime.o" ¶ "{PPCLibraries}PPCToolLibs.o" LibFiles-68K = ¶ "{Libraries}MathLib.o" ¶ "{CLibraries}StdCLib.o" ¶ "{Libraries}SIOW.o" ¶ "{Libraries}MacRuntime.o" ¶ "{Libraries}IntEnv.o" ¶ "{Libraries}ToolLibs.o" ¶ "{Libraries}Interface.o" ### Default Rules ### .c.x Ä .c {¥MondoBuild¥} {PPCC} {depDir}{default}.c -o {targDir}{default}.c.x {PPCCOptions} .c.o Ä .c {¥MondoBuild¥} {C} {depDir}{default}.c -o {targDir}{default}.c.o {COptions} ### Build Rules ### sha256 ÄÄ {ObjFiles-PPC} {LibFiles-PPC} {¥MondoBuild¥} PPCLink ¶ -o {Targ} ¶ {ObjFiles-PPC} ¶ {LibFiles-PPC} ¶ {Sym-PPC} ¶ -mf -d ¶ -t 'APPL' ¶ -c 'siow' sha256 ÄÄ {ObjFiles-68K} {LibFiles-68K} {¥MondoBuild¥} ILink ¶ -o {Targ} ¶ {ObjFiles-68K} ¶ {LibFiles-68K} ¶ {Sym-68K} ¶ -mf -d ¶ -t 'APPL' ¶ -c 'siow' ¶ -model near ¶ -state rewrite ¶ -compact -pad 0 If "{Sym-68K}" =~ /-sym Å[nNuU]Å/ ILinkToSYM {Targ}.NJ -mf -sym 3.2 -c 'sade' End sha256 ÄÄ "{RIncludes}"SIOW.r {¥MondoBuild¥} Rez "{RIncludes}"SIOW.r -o {Targ} -append ### Required Dependencies ### "{ObjDir}main.c.x" "{ObjDir}main.c.o" Ä main.c "{ObjDir}sha256.c.x" "{ObjDir}sha256.c.o" Ä sha256.c ### Optional Dependencies ### ### Build this target to generate "include file" dependencies. ### Dependencies Ä $OutOfDate MakeDepend ¶ -append {MAKEFILE} ¶ -ignore "{CIncludes}" ¶ -objdir "{ObjDir}" ¶ -objext .x ¶ -objext .o ¶ {Includes} ¶ {SrcFiles}

BIN
sha256.sit Executable file

Binary file not shown.