master xplshn/aruu / cmd / pseudo / sha512-256sum.c
 1/* See LICENSE file for copyright and license details. */
 2
 3#include <stdint.h>
 4#include <stdio.h>
 5
 6#include "crypt.h"
 7#include "sha512-256.h"
 8#include "util.h"
 9
10static struct sha512_256 s;
11struct crypt_ops         sha512_256_ops = {
12    sha512_256_init,
13    sha512_256_update,
14    sha512_256_sum,
15    &s,
16};
17
18static void
19usage(void)
20{
21  eprintf("usage: %s [-c] [file ...]\n", argv0);
22}
23
24// ?man sha512-256sum: compute sha512/256 checksums
25// ?man arguments: file ...
26// ?man compute and check sha512/256 message digests
27int
28main(int argc, char *argv[])
29{
30  int     ret = 0, (*cryptfunc)(int, char **, struct crypt_ops *, uint8_t *, size_t) = cryptmain;
31  uint8_t md[SHA512_256_DIGEST_LENGTH];
32
33  ARGBEGIN
34  {
35    // ?man -b: specify block size or base directory
36    case 'b':
37    // ?man -t: sort or specify timestamp
38    case 't':
39      /* ignore */
40      break;
41    // ?man -c: print count or perform stdout action
42    case 'c':
43      cryptfunc = cryptcheck;
44      break;
45    default:
46      usage();
47  }
48  ARGEND
49
50  ret |= cryptfunc(argc, argv, &sha512_256_ops, md, sizeof(md));
51  ret |= fshut(stdin, "<stdin>") | fshut(stdout, "<stdout>");
52
53  return ret;
54}