mirror of
https://github.com/joeyadams/SHA256-for-Macintosh-Classic.git
synced 2025-08-05 20:25:03 +00:00
Converted newlines from Mac OS format to Unix format
This commit is contained in:
87
main.c
87
main.c
@@ -1 +1,86 @@
|
||||
#include "sha256.h"
|
||||
#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';
|
||||
}
|
65
sha256.h
65
sha256.h
@@ -1 +1,64 @@
|
||||
/*
|
||||
/*
|
||||
* 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 */
|
||||
|
122
sha256.make
122
sha256.make
@@ -1 +1,121 @@
|
||||
# File: sha256.make
|
||||
# File: sha256.make
|
||||
# Target: sha256
|
||||
# Created: Monday, August 27, 1956 09:30:59 PM
|
||||
|
||||
|
||||
MAKEFILE = sha256.make
|
||||
<EFBFBD>MondoBuild<EFBFBD> = {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 = <20>
|
||||
main.c <20>
|
||||
sha256.c
|
||||
|
||||
|
||||
### Object Files ###
|
||||
|
||||
ObjFiles-PPC = <20>
|
||||
"{ObjDir}main.c.x" <20>
|
||||
"{ObjDir}sha256.c.x"
|
||||
|
||||
ObjFiles-68K = <20>
|
||||
"{ObjDir}main.c.o" <20>
|
||||
"{ObjDir}sha256.c.o"
|
||||
|
||||
|
||||
### Libraries ###
|
||||
|
||||
LibFiles-PPC = <20>
|
||||
"{PPCLibraries}PPCSIOW.o" <20>
|
||||
"{SharedLibraries}InterfaceLib" <20>
|
||||
"{SharedLibraries}StdCLib" <20>
|
||||
"{SharedLibraries}MathLib" <20>
|
||||
"{PPCLibraries}StdCRuntime.o" <20>
|
||||
"{PPCLibraries}PPCCRuntime.o" <20>
|
||||
"{PPCLibraries}PPCToolLibs.o"
|
||||
|
||||
LibFiles-68K = <20>
|
||||
"{Libraries}MathLib.o" <20>
|
||||
"{CLibraries}StdCLib.o" <20>
|
||||
"{Libraries}SIOW.o" <20>
|
||||
"{Libraries}MacRuntime.o" <20>
|
||||
"{Libraries}IntEnv.o" <20>
|
||||
"{Libraries}ToolLibs.o" <20>
|
||||
"{Libraries}Interface.o"
|
||||
|
||||
|
||||
### Default Rules ###
|
||||
|
||||
.c.x <20> .c {<7B>MondoBuild<6C>}
|
||||
{PPCC} {depDir}{default}.c -o {targDir}{default}.c.x {PPCCOptions}
|
||||
|
||||
.c.o <20> .c {<7B>MondoBuild<6C>}
|
||||
{C} {depDir}{default}.c -o {targDir}{default}.c.o {COptions}
|
||||
|
||||
|
||||
### Build Rules ###
|
||||
|
||||
sha256 <20><> {ObjFiles-PPC} {LibFiles-PPC} {<7B>MondoBuild<6C>}
|
||||
PPCLink <20>
|
||||
-o {Targ} <20>
|
||||
{ObjFiles-PPC} <20>
|
||||
{LibFiles-PPC} <20>
|
||||
{Sym-PPC} <20>
|
||||
-mf -d <20>
|
||||
-t 'APPL' <20>
|
||||
-c 'siow'
|
||||
|
||||
|
||||
sha256 <20><> {ObjFiles-68K} {LibFiles-68K} {<7B>MondoBuild<6C>}
|
||||
ILink <20>
|
||||
-o {Targ} <20>
|
||||
{ObjFiles-68K} <20>
|
||||
{LibFiles-68K} <20>
|
||||
{Sym-68K} <20>
|
||||
-mf -d <20>
|
||||
-t 'APPL' <20>
|
||||
-c 'siow' <20>
|
||||
-model near <20>
|
||||
-state rewrite <20>
|
||||
-compact -pad 0
|
||||
If "{Sym-68K}" =~ /-sym <20>[nNuU]<5D>/
|
||||
ILinkToSYM {Targ}.NJ -mf -sym 3.2 -c 'sade'
|
||||
End
|
||||
|
||||
|
||||
sha256 <20><> "{RIncludes}"SIOW.r {<7B>MondoBuild<6C>}
|
||||
Rez "{RIncludes}"SIOW.r -o {Targ} -append
|
||||
|
||||
|
||||
### Required Dependencies ###
|
||||
|
||||
"{ObjDir}main.c.x" "{ObjDir}main.c.o" <20> main.c
|
||||
"{ObjDir}sha256.c.x" "{ObjDir}sha256.c.o" <20> sha256.c
|
||||
|
||||
|
||||
### Optional Dependencies ###
|
||||
### Build this target to generate "include file" dependencies. ###
|
||||
|
||||
Dependencies <20> $OutOfDate
|
||||
MakeDepend <20>
|
||||
-append {MAKEFILE} <20>
|
||||
-ignore "{CIncludes}" <20>
|
||||
-objdir "{ObjDir}" <20>
|
||||
-objext .x <20>
|
||||
-objext .o <20>
|
||||
{Includes} <20>
|
||||
{SrcFiles}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user