You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

64 lines
1.8 KiB

  1. /**
  2. * @cond internal
  3. * @file shakesum.c
  4. * @copyright
  5. * Copyright (c) 2015 Cryptography Research, Inc. \n
  6. * Released under the MIT License. See LICENSE.txt for license information.
  7. * @author Mike Hamburg
  8. * @brief SHA3 utility, to be combined with test vectors eventually...
  9. */
  10. #include <stdio.h>
  11. #include <unistd.h>
  12. #include <string.h>
  13. #include "shake.h"
  14. int main(int argc, char **argv) {
  15. (void)argc; (void)argv;
  16. keccak_sponge_t sponge;
  17. unsigned char buf[1024];
  18. unsigned int outlen = 512;
  19. shake256_init(sponge);
  20. /* Sloppy. Real utility would parse --algo, --size ... */
  21. if (argc > 1) {
  22. if (!strcmp(argv[1], "shake256") || !strcmp(argv[1], "SHAKE256")) {
  23. outlen = 512;
  24. shake256_init(sponge);
  25. } else if (!strcmp(argv[1], "shake128") || !strcmp(argv[1], "SHAKE128")) {
  26. outlen = 512;
  27. shake128_init(sponge);
  28. } else if (!strcmp(argv[1], "sha3-224") || !strcmp(argv[1], "SHA3-224")) {
  29. outlen = 224/8;
  30. sha3_224_init(sponge);
  31. } else if (!strcmp(argv[1], "sha3-256") || !strcmp(argv[1], "SHA3-256")) {
  32. outlen = 256/8;
  33. sha3_256_init(sponge);
  34. } else if (!strcmp(argv[1], "sha3-384") || !strcmp(argv[1], "SHA3-384")) {
  35. outlen = 384/8;
  36. sha3_384_init(sponge);
  37. } else if (!strcmp(argv[1], "sha3-512") || !strcmp(argv[1], "SHA3-512")) {
  38. outlen = 512/8;
  39. sha3_512_init(sponge);
  40. }
  41. }
  42. ssize_t red;
  43. do {
  44. red = read(0, buf, sizeof(buf));
  45. if (red>0) sha3_update(sponge,buf,red);
  46. } while (red>0);
  47. sha3_output(sponge,buf,outlen);
  48. sponge_destroy(sponge);
  49. unsigned i;
  50. for (i=0; i<outlen; i++) {
  51. printf("%02x", buf[i]);
  52. }
  53. printf("\n");
  54. return 0;
  55. }