add sha512-224sum (SHA512/224) and sha512-256sum (SHA512/256)
Signed-off-by: Mattias Andrée <maandree@kth.se>
This commit is contained in:
parent
ae1da536bb
commit
a392cd475e
12
Makefile
12
Makefile
|
@ -15,6 +15,8 @@ HDR =\
|
|||
sha256.h\
|
||||
sha384.h\
|
||||
sha512.h\
|
||||
sha512-224.h\
|
||||
sha512-256.h\
|
||||
text.h\
|
||||
utf.h\
|
||||
util.h
|
||||
|
@ -68,6 +70,8 @@ LIBUTILSRC =\
|
|||
libutil/sha256.c\
|
||||
libutil/sha384.c\
|
||||
libutil/sha512.c\
|
||||
libutil/sha512-224.c\
|
||||
libutil/sha512-256.c\
|
||||
libutil/strcasestr.c\
|
||||
libutil/strlcat.c\
|
||||
libutil/strlcpy.c\
|
||||
|
@ -141,6 +145,8 @@ BIN =\
|
|||
sha256sum\
|
||||
sha384sum\
|
||||
sha512sum\
|
||||
sha512-224sum\
|
||||
sha512-256sum\
|
||||
sleep\
|
||||
sort\
|
||||
split\
|
||||
|
@ -227,18 +233,18 @@ sbase-box: $(LIB) $(SRC)
|
|||
mkdir -p build
|
||||
cp $(HDR) build
|
||||
cp confstr_l.h limits_l.h sysconf_l.h pathconf_l.h build
|
||||
for f in $(SRC); do sed "s/^main(/$${f%.c}_&/" < $$f > build/$$f; done
|
||||
for f in $(SRC); do sed "s/^main(/$$(echo "$${f%.c}" | sed s/-/_/g)_&/" < $$f > build/$$f; done
|
||||
echo '#include <libgen.h>' > build/$@.c
|
||||
echo '#include <stdio.h>' >> build/$@.c
|
||||
echo '#include <stdlib.h>' >> build/$@.c
|
||||
echo '#include <string.h>' >> build/$@.c
|
||||
echo '#include "util.h"' >> build/$@.c
|
||||
for f in $(SRC); do echo "int $${f%.c}_main(int, char **);"; done >> build/$@.c
|
||||
for f in $(SRC); do echo "int $$(echo "$${f%.c}" | sed s/-/_/g)_main(int, char **);"; done >> build/$@.c
|
||||
echo 'int main(int argc, char *argv[]) { char *s = basename(argv[0]);' >> build/$@.c
|
||||
echo 'if(!strcmp(s,"sbase-box")) { argc--; argv++; s = basename(argv[0]); } if(0) ;' >> build/$@.c
|
||||
echo "else if (!strcmp(s, \"install\")) return xinstall_main(argc, argv);" >> build/$@.c
|
||||
echo "else if (!strcmp(s, \"[\")) return test_main(argc, argv);" >> build/$@.c
|
||||
for f in $(SRC); do echo "else if(!strcmp(s, \"$${f%.c}\")) return $${f%.c}_main(argc, argv);"; done >> build/$@.c
|
||||
for f in $(SRC); do echo "else if(!strcmp(s, \"$${f%.c}\")) return $$(echo "$${f%.c}" | sed s/-/_/g)_main(argc, argv);"; done >> build/$@.c
|
||||
echo 'else { fputs("[ ", stdout);' >> build/$@.c
|
||||
for f in $(SRC); do echo "fputs(\"$${f%.c} \", stdout);"; done >> build/$@.c
|
||||
echo 'putchar(0xa); }; return 0; }' >> build/$@.c
|
||||
|
|
2
README
2
README
|
@ -76,6 +76,8 @@ The following tools are implemented:
|
|||
=*|x sha256sum .
|
||||
=* x sha238sum .
|
||||
=*|x sha512sum .
|
||||
=* x sha512-224sum .
|
||||
=* x sha512-256sum .
|
||||
=*|o sleep .
|
||||
#*|o sort .
|
||||
=*|o split .
|
||||
|
|
26
libutil/sha512-224.c
Normal file
26
libutil/sha512-224.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* public domain sha512/224 implementation based on fips180-3 */
|
||||
#include <stdint.h>
|
||||
#include "../sha512-224.h"
|
||||
|
||||
extern void sha512_sum_n(void *, uint8_t *, int n);
|
||||
|
||||
void
|
||||
sha512_224_init(void *ctx)
|
||||
{
|
||||
struct sha512_224 *s = ctx;
|
||||
s->len = 0;
|
||||
s->h[0] = 0x8c3d37c819544da2ULL;
|
||||
s->h[1] = 0x73e1996689dcd4d6ULL;
|
||||
s->h[2] = 0x1dfab7ae32ff9c82ULL;
|
||||
s->h[3] = 0x679dd514582f9fcfULL;
|
||||
s->h[4] = 0x0f6d2b697bd44da8ULL;
|
||||
s->h[5] = 0x77e36f7304c48942ULL;
|
||||
s->h[6] = 0x3f9d85a86a1d36c8ULL;
|
||||
s->h[7] = 0x1112e6ad91d692a1ULL;
|
||||
}
|
||||
|
||||
void
|
||||
sha512_224_sum(void *ctx, uint8_t md[SHA512_224_DIGEST_LENGTH])
|
||||
{
|
||||
sha512_sum_n(ctx, md, 4);
|
||||
}
|
26
libutil/sha512-256.c
Normal file
26
libutil/sha512-256.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* public domain sha512/256 implementation based on fips180-3 */
|
||||
#include <stdint.h>
|
||||
#include "../sha512-256.h"
|
||||
|
||||
extern void sha512_sum_n(void *, uint8_t *, int n);
|
||||
|
||||
void
|
||||
sha512_256_init(void *ctx)
|
||||
{
|
||||
struct sha512_256 *s = ctx;
|
||||
s->len = 0;
|
||||
s->h[0] = 0x22312194fc2bf72cULL;
|
||||
s->h[1] = 0x9f555fa3c84c64c2ULL;
|
||||
s->h[2] = 0x2393b86b6f53b151ULL;
|
||||
s->h[3] = 0x963877195940eabdULL;
|
||||
s->h[4] = 0x96283ee2a88effe3ULL;
|
||||
s->h[5] = 0xbe5e1e2553863992ULL;
|
||||
s->h[6] = 0x2b0199fc2c85b8aaULL;
|
||||
s->h[7] = 0x0eb72ddc81c52ca2ULL;
|
||||
}
|
||||
|
||||
void
|
||||
sha512_256_sum(void *ctx, uint8_t md[SHA512_256_DIGEST_LENGTH])
|
||||
{
|
||||
sha512_sum_n(ctx, md, 4);
|
||||
}
|
16
sha512-224.h
Normal file
16
sha512-224.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
/* public domain sha512/224 implementation based on fips180-3 */
|
||||
|
||||
#include "sha512.h"
|
||||
|
||||
#define sha512_224 sha512 /*struct*/
|
||||
|
||||
enum { SHA512_224_DIGEST_LENGTH = 28 };
|
||||
|
||||
/* reset state */
|
||||
void sha512_224_init(void *ctx);
|
||||
/* process message */
|
||||
#define sha512_224_update sha512_update
|
||||
/* get message digest */
|
||||
/* state is ruined after sum, keep a copy if multiple sum is needed */
|
||||
/* part of the message might be left in s, zero it if secrecy is needed */
|
||||
void sha512_224_sum(void *ctx, uint8_t md[SHA512_224_DIGEST_LENGTH]);
|
32
sha512-224sum.1
Normal file
32
sha512-224sum.1
Normal file
|
@ -0,0 +1,32 @@
|
|||
.Dd 2016-02-24
|
||||
.Dt SHA512-224SUM 1
|
||||
.Os sbase
|
||||
.Sh NAME
|
||||
.Nm sha512-224sum
|
||||
.Nd compute or check SHA-512/224 message digests
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl c
|
||||
.Op Ar file ...
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
writes SHA-512/224 (224-bit) checksums of each
|
||||
.Ar file
|
||||
to stdout.
|
||||
If no
|
||||
.Ar file
|
||||
is given
|
||||
.Nm
|
||||
reads from stdin.
|
||||
.Sh OPTIONS
|
||||
.Bl -tag -width Ds
|
||||
.It Fl c
|
||||
Read list of SHA-512/224 checksums from each
|
||||
.Ar file
|
||||
and check them.
|
||||
If no
|
||||
.Ar file
|
||||
is given
|
||||
.Nm
|
||||
reads from stdin.
|
||||
.El
|
41
sha512-224sum.c
Normal file
41
sha512-224sum.c
Normal file
|
@ -0,0 +1,41 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "crypt.h"
|
||||
#include "sha512-224.h"
|
||||
#include "util.h"
|
||||
|
||||
static struct sha512_224 s;
|
||||
struct crypt_ops sha512_224_ops = {
|
||||
sha512_224_init,
|
||||
sha512_224_update,
|
||||
sha512_224_sum,
|
||||
&s,
|
||||
};
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
eprintf("usage: %s [-c] [file ...]\n", argv0);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int ret = 0, (*cryptfunc)(int, char **, struct crypt_ops *, uint8_t *, size_t) = cryptmain;
|
||||
uint8_t md[SHA512_224_DIGEST_LENGTH];
|
||||
|
||||
ARGBEGIN {
|
||||
case 'c':
|
||||
cryptfunc = cryptcheck;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
} ARGEND
|
||||
|
||||
ret |= cryptfunc(argc, argv, &sha512_224_ops, md, sizeof(md));
|
||||
ret |= fshut(stdin, "<stdin>") | fshut(stdout, "<stdout>");
|
||||
|
||||
return ret;
|
||||
}
|
16
sha512-256.h
Normal file
16
sha512-256.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
/* public domain sha512/256 implementation based on fips180-3 */
|
||||
|
||||
#include "sha512.h"
|
||||
|
||||
#define sha512_256 sha512 /*struct*/
|
||||
|
||||
enum { SHA512_256_DIGEST_LENGTH = 32 };
|
||||
|
||||
/* reset state */
|
||||
void sha512_256_init(void *ctx);
|
||||
/* process message */
|
||||
#define sha512_256_update sha512_update
|
||||
/* get message digest */
|
||||
/* state is ruined after sum, keep a copy if multiple sum is needed */
|
||||
/* part of the message might be left in s, zero it if secrecy is needed */
|
||||
void sha512_256_sum(void *ctx, uint8_t md[SHA512_256_DIGEST_LENGTH]);
|
32
sha512-256sum.1
Normal file
32
sha512-256sum.1
Normal file
|
@ -0,0 +1,32 @@
|
|||
.Dd 2016-02-24
|
||||
.Dt SHA512-256SUM 1
|
||||
.Os sbase
|
||||
.Sh NAME
|
||||
.Nm sha512-256sum
|
||||
.Nd compute or check SHA-512/256 message digests
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl c
|
||||
.Op Ar file ...
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
writes SHA-512/256 (256-bit) checksums of each
|
||||
.Ar file
|
||||
to stdout.
|
||||
If no
|
||||
.Ar file
|
||||
is given
|
||||
.Nm
|
||||
reads from stdin.
|
||||
.Sh OPTIONS
|
||||
.Bl -tag -width Ds
|
||||
.It Fl c
|
||||
Read list of SHA-512/256 checksums from each
|
||||
.Ar file
|
||||
and check them.
|
||||
If no
|
||||
.Ar file
|
||||
is given
|
||||
.Nm
|
||||
reads from stdin.
|
||||
.El
|
41
sha512-256sum.c
Normal file
41
sha512-256sum.c
Normal file
|
@ -0,0 +1,41 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "crypt.h"
|
||||
#include "sha512-256.h"
|
||||
#include "util.h"
|
||||
|
||||
static struct sha512_256 s;
|
||||
struct crypt_ops sha512_256_ops = {
|
||||
sha512_256_init,
|
||||
sha512_256_update,
|
||||
sha512_256_sum,
|
||||
&s,
|
||||
};
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
eprintf("usage: %s [-c] [file ...]\n", argv0);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int ret = 0, (*cryptfunc)(int, char **, struct crypt_ops *, uint8_t *, size_t) = cryptmain;
|
||||
uint8_t md[SHA512_256_DIGEST_LENGTH];
|
||||
|
||||
ARGBEGIN {
|
||||
case 'c':
|
||||
cryptfunc = cryptcheck;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
} ARGEND
|
||||
|
||||
ret |= cryptfunc(argc, argv, &sha512_256_ops, md, sizeof(md));
|
||||
ret |= fshut(stdin, "<stdin>") | fshut(stdout, "<stdout>");
|
||||
|
||||
return ret;
|
||||
}
|
Loading…
Reference in New Issue
Block a user