From 6b5b9490f3b0a6a5a22d82ad1b887357bcb0ad9a Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Sat, 30 Apr 2022 18:17:28 +0200 Subject: [PATCH] sys/shell: add sha256sum command --- makefiles/pseudomodules.inc.mk | 1 + sys/shell/commands/sc_vfs.c | 27 +++++++++++++++++++++++++++ sys/shell/commands/shell_commands.c | 7 +++++++ 3 files changed, 35 insertions(+) diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index 4d951b07946a7..e8f2ccc8eeb1a 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -199,6 +199,7 @@ PSEUDOMODULES += senml_cbor PSEUDOMODULES += senml_phydat PSEUDOMODULES += senml_saul PSEUDOMODULES += sha1sum +PSEUDOMODULES += sha256sum PSEUDOMODULES += shell_hooks PSEUDOMODULES += slipdev_stdio PSEUDOMODULES += slipdev_l2addr diff --git a/sys/shell/commands/sc_vfs.c b/sys/shell/commands/sc_vfs.c index 9d7029341679c..aef82cabbc031 100644 --- a/sys/shell/commands/sc_vfs.c +++ b/sys/shell/commands/sc_vfs.c @@ -699,4 +699,31 @@ int _vfs_sha1sum_cmd(int argc, char **argv) return 0; } #endif + +#if MODULE_SHA256SUM +#include "hashes/sha256.h" +int _vfs_sha256sum_cmd(int argc, char **argv) +{ + int res; + uint8_t digest[SHA256_DIGEST_LENGTH]; + + if (argc < 2) { + printf("usage: %s [file] …\n", argv[0]); + return -1; + } + + for (int i = 1; i < argc; ++i) { + const char *file = argv[i]; + res = vfs_file_sha256(file, digest, + _shell_vfs_data_buffer, sizeof(_shell_vfs_data_buffer)); + if (res < 0) { + printf("%s: error %d\n", file, res); + } else { + _print_digest(digest, sizeof(digest), file); + } + } + + return 0; +} +#endif #endif diff --git a/sys/shell/commands/shell_commands.c b/sys/shell/commands/shell_commands.c index 9161391b754ac..1b82f5aeebb4b 100644 --- a/sys/shell/commands/shell_commands.c +++ b/sys/shell/commands/shell_commands.c @@ -223,6 +223,10 @@ extern int _vfs_md5sum_cmd(int argc, char **argv); extern int _vfs_sha1sum_cmd(int argc, char **argv); #endif +#ifdef MODULE_SHA256SUM +extern int _vfs_sha256sum_cmd(int argc, char **argv); +#endif + const shell_command_t _shell_command_list[] = { {"reboot", "Reboot the node", _reboot_handler}, {"version", "Prints current RIOT_VERSION", _version_handler}, @@ -282,6 +286,9 @@ const shell_command_t _shell_command_list[] = { #ifdef MODULE_SHA1SUM {"sha1sum", "Compute and check SHA1 message digest", _vfs_sha1sum_cmd}, #endif +#ifdef MODULE_SHA256SUM + {"sha256sum", "Compute and check SHA256 message digest", _vfs_sha256sum_cmd}, +#endif #ifdef MODULE_GNRC_IPV6_NIB {"nib", "Configure neighbor information base", _gnrc_ipv6_nib}, #endif