Unfortunatley the sha2 project does not have versioned releases so we use the latest commit. We have also manually added a frontend to sha-2 to allow us to invoke it from the command line, thanks bittrof for the help!master
parent
44bad278e0
commit
92cb05442e
@ -0,0 +1,22 @@
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or distribute
|
||||
this software, either in source code form or as a compiled binary, for any
|
||||
purpose, commercial or non-commercial, and by any means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors of this
|
||||
software dedicate any and all copyright interest in the software to the public
|
||||
domain. We make this dedication for the benefit of the public at large and
|
||||
to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of relinquishment
|
||||
in perpetuity of all present and future rights to this software under copyright
|
||||
law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <http://unlicense.org/>
|
@ -0,0 +1 @@
|
||||
53384 /after/bin/sha256sum
|
@ -0,0 +1,151 @@
|
||||
SPDX-FileCopyrightText: 2021 Bastian Bittorf <bb@npl.de>
|
||||
SPDX-FileCopyrightText: 2021 fosslinux <fosslinux@aussies.space>
|
||||
|
||||
SPDX-License-Identifier: Unlicense
|
||||
|
||||
This adds a main() function to this tool, giving a frontend so we can call
|
||||
it from the command line.
|
||||
|
||||
--- sha-256.c 2019-08-04 22:20:53.000000000 +1000
|
||||
+++ sha-256.c 2021-02-15 17:21:27.478945543 +1100
|
||||
@@ -1,10 +1,16 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
-
|
||||
-#include "sha-256.h"
|
||||
+#include <stdio.h>
|
||||
|
||||
#define CHUNK_SIZE 64
|
||||
#define TOTAL_LEN_LEN 8
|
||||
+#define MAX_FILE_SIZE 2*1024*1024
|
||||
+
|
||||
+void show_usage(void)
|
||||
+{
|
||||
+ printf("Usage: sha256sum <file>\n");
|
||||
+ printf(" sha256sum <file> -c <known_SHA256_hash>\n");
|
||||
+}
|
||||
|
||||
/*
|
||||
* ABOUT bool: this file does not use bool in order to be as pre-C99 compatible as possible.
|
||||
@@ -217,3 +223,121 @@
|
||||
hash[j++] = (uint8_t) h[i];
|
||||
}
|
||||
}
|
||||
+
|
||||
+static void hash_to_string(char hash_string[66], uint8_t hash[32])
|
||||
+{
|
||||
+ for (size_t i = 0; i < 32; i++) {
|
||||
+ hash_string += sprintf(hash_string, "%02x", hash[i]);
|
||||
+ }
|
||||
+ hash_string[65] = '\0';
|
||||
+}
|
||||
+
|
||||
+static void hash_as_string(char filename[128], char hash_string[66])
|
||||
+{
|
||||
+ char buffer[MAX_FILE_SIZE];
|
||||
+
|
||||
+ FILE* fp = fopen(filename, "r");
|
||||
+ if (fp == NULL)
|
||||
+ {
|
||||
+ printf("Opening file %s failed!", filename);
|
||||
+ hash_string = NULL;
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ size_t i;
|
||||
+ for (i = 0; i < MAX_FILE_SIZE; i++) {
|
||||
+ int c = fgetc(fp);
|
||||
+ if (c == EOF) {
|
||||
+ break;
|
||||
+ }
|
||||
+ buffer[i] = c;
|
||||
+ }
|
||||
+
|
||||
+ uint8_t hash[32];
|
||||
+
|
||||
+ calc_sha_256(hash, buffer, i);
|
||||
+ hash_to_string(hash_string, hash);
|
||||
+}
|
||||
+
|
||||
+int main(int argc, char **argv)
|
||||
+{
|
||||
+ char buffer[MAX_FILE_SIZE];
|
||||
+ size_t i;
|
||||
+ FILE *fp;
|
||||
+ FILE *csum_fp;
|
||||
+
|
||||
+ if (argc == 1) {
|
||||
+ show_usage();
|
||||
+ return 2;
|
||||
+ }
|
||||
+
|
||||
+ if ((strcmp(argv[1], "-c") == 0) || (strcmp(argv[1], "--check") == 0)) {
|
||||
+ /* Operate in check mode */
|
||||
+ int failed = 0;
|
||||
+
|
||||
+ /* Get and open checksum file */
|
||||
+ char *csum_filename = argv[2];
|
||||
+ csum_fp = fopen(csum_filename, "r");
|
||||
+ if (csum_fp == NULL) {
|
||||
+ printf("Opening file %s failed!", csum_filename);
|
||||
+ };
|
||||
+
|
||||
+ /* We break out of this loop at EOF */
|
||||
+ while (1) {
|
||||
+ /* Get the hash we need to check against */
|
||||
+ char hash_true[256];
|
||||
+ char filename[512];
|
||||
+ int c = fgetc(csum_fp);
|
||||
+ i = 0;
|
||||
+ while (c != ' ' && c != EOF) {
|
||||
+ hash_true[i] = c;
|
||||
+ c = fgetc(csum_fp);
|
||||
+ i++;
|
||||
+ }
|
||||
+ if(c == EOF) break;
|
||||
+ /* Skip the next space(s) */
|
||||
+ while (c == ' ') {
|
||||
+ c = fgetc(csum_fp);
|
||||
+ }
|
||||
+ if(c == EOF) break;
|
||||
+ /* Get the filename */
|
||||
+ i = 0;
|
||||
+ while (c != '\n' && c != EOF) {
|
||||
+ filename[i] = c;
|
||||
+ c = fgetc(csum_fp);
|
||||
+ i++;
|
||||
+ }
|
||||
+ filename[i] = '\0';
|
||||
+
|
||||
+ /* Break out @ EOF */
|
||||
+ if (c == EOF) break;
|
||||
+
|
||||
+ /* Get the hash */
|
||||
+ char hash_string[66];
|
||||
+ hash_as_string(filename, hash_string);
|
||||
+ if (hash_string == NULL) return 127;
|
||||
+
|
||||
+ /* Output results */
|
||||
+ printf("%s: ", filename);
|
||||
+ if (strcmp(hash_true, hash_string)) {
|
||||
+ printf("FAILED\n");
|
||||
+ failed = 1;
|
||||
+ } else {
|
||||
+ printf("OK\n");
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ if (failed) return 1;
|
||||
+ } else {
|
||||
+ /* All the arguments are files to generate checksums for */
|
||||
+
|
||||
+ for (i = 1; i < argc; i++) {
|
||||
+ char hash[66];
|
||||
+ hash_as_string(argv[i], hash);
|
||||
+ if (hash == NULL) return 127;
|
||||
+ printf("%s %s\n", hash, argv[i]);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
@ -0,0 +1,30 @@
|
||||
#!/bin/sh
|
||||
|
||||
# SPDX-FileCopyrightText: 2021 fosslinux <fosslinux@aussies.space>
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
set -ex
|
||||
|
||||
cd build
|
||||
|
||||
# Extract
|
||||
gunzip ../src/${pkg}.tar.gz
|
||||
tar xf ../src/${pkg}.tar
|
||||
cd sha-2-61555d45676473e77c11f8da97301e2d2b865871
|
||||
|
||||
# Patch
|
||||
patch -Np0 -i ../../patches/frontend.patch
|
||||
|
||||
# Compile
|
||||
tcc -c -o sha-256.o sha-256.c
|
||||
|
||||
# Link
|
||||
tcc -static -o ${bindir}/sha256sum sha-256.o
|
||||
|
||||
# No test avaliable
|
||||
|
||||
cd ../..
|
||||
|
||||
# Checksums
|
||||
fletcher16 checksums
|
Loading…
Reference in new issue