Bonjour,
Merci pour votre réponse.
Voici le contenu du fichier main.c :
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
/* Add required includes here */
#include "fmt.h"
#include "shell.h"
#include "hashes/sha256.h"
#include "hashes/sha3.h"
/* Add here the buffers to store the SHA256 hash and its hexadecimal representation */
static uint8_t sha256_hash[SHA256_DIGEST_LENGTH];
static char sha256_hash_hex[SHA256_DIGEST_LENGTH * 2];
/* Add here the buffers to store the SHA3 hash and its hexadecimal representation */
static uint8_t sha3_hash[SHA3_256_DIGEST_LENGTH];
static char sha3_hash_hex[SHA3_256_DIGEST_LENGTH * 2];
/* Implement the SHA256 command handler here */
static int _sha256_handler(int argc, char **argv)
{
if (argc != 2) {
printf("usage: %s <input to hash>\n", argv[0]);
return 1;
}
/* Compute the hash here */
sha256_context_t sha256;
sha256_init(&sha256);
sha256_update(&sha256, (uint8_t*)argv[1], strlen(argv[1]));
sha256_final(&sha256, sha256_hash);
/* Convert the hash array to a string of hex characters */
fmt_bytes_hex(sha256_hash_hex, sha256_hash, SHA256_DIGEST_LENGTH);
/* Print the hash */
printf("SHA256: %s\n", sha256_hash_hex);
return 0;
}
/* Implement the SHA3 command handler here */
static int _sha3_handler(int argc, char **argv)
{
if (argc != 2) {
printf("usage: %s <input to hash>\n", argv[0]);
return 1;
}
/* Compute the hash here */
keccak_state_t state;
sha3_256_init(&state);
sha3_update(&state, argv[1], strlen(argv[1]));
sha3_256_final(&state, sha3_hash);
/* Convert the hash array to a string in hex format */
fmt_bytes_hex(sha3_hash_hex, sha3_hash, SHA3_256_DIGEST_LENGTH);
/* Print the hash */
printf("SHA3: %s\n", sha3_hash_hex);
return 0;
}
/* Declare the list of shell commands */
static const shell_command_t shell_commands[] = {
{ "sha256", "Compute SHA256 hasg", _sha256_handler },
{ "sha3", "Compute SHA3 hash", _sha3_handler },
{ NULL, NULL, NULL }
};
int main(void)
{
/* Configure and start the shell */
char line_buf[SHELL_DEFAULT_BUFSIZE];
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
return 0;
}
Voici les sorties du shell pour l’exécution des commandes suivantes, ce qui devrait vous permettre de reproduire ces sorties :
jovyan@bf6c278a4e03:~/work/iot-lab-training$ export SITE=grenoble
jovyan@bf6c278a4e03:~/work/iot-lab-training$ iotlab-experiment submit -n "riot-hash" -d 20 -l 1,archi=m3:at86rf231+site=$SITE
{
"id": 200498
}
jovyan@bf6c278a4e03:~/work/iot-lab-training$ iotlab-experiment wait --timeout 30 --cancel-on-timeout
Waiting that experiment 200498 gets in state Running
"Running"
jovyan@bf6c278a4e03:~/work/iot-lab-training$ iotlab-experiment get --nodes
{
"items": [
{
"archi": "m3:at86rf231",
"camera": null,
"mobile": "0",
"mobility_type": " ",
"network_address": "m3-97.grenoble.iot-lab.info",
"production": "YES",
"site": "grenoble",
"state": "Alive",
"uid": "b179",
"x": "0.40",
"y": "25.92",
"z": "-0.04"
}
]
}
jovyan@bf6c278a4e03:~/work/iot-lab-training$ make -C riot/security/hash BOARD=iotlab-m3 IOTLAB_NODE=auto-ssh flash
make: Entering directory '/home/jovyan/work/iot-lab-training/riot/security/hash'
Building application "hash" for "iotlab-m3" with MCU "stm32f1".
"make" -C /home/jovyan/work/iot-lab-training/riot/RIOT/boards/iotlab-m3
"make" -C /home/jovyan/work/iot-lab-training/riot/RIOT/boards/common/iotlab
"make" -C /home/jovyan/work/iot-lab-training/riot/RIOT/core
"make" -C /home/jovyan/work/iot-lab-training/riot/RIOT/cpu/stm32f1
"make" -C /home/jovyan/work/iot-lab-training/riot/RIOT/cpu/cortexm_common
"make" -C /home/jovyan/work/iot-lab-training/riot/RIOT/cpu/cortexm_common/periph
"make" -C /home/jovyan/work/iot-lab-training/riot/RIOT/cpu/stm32_common
"make" -C /home/jovyan/work/iot-lab-training/riot/RIOT/cpu/stm32_common/periph
"make" -C /home/jovyan/work/iot-lab-training/riot/RIOT/cpu/stm32f1/periph
"make" -C /home/jovyan/work/iot-lab-training/riot/RIOT/drivers
"make" -C /home/jovyan/work/iot-lab-training/riot/RIOT/drivers/periph_common
"make" -C /home/jovyan/work/iot-lab-training/riot/RIOT/sys
"make" -C /home/jovyan/work/iot-lab-training/riot/RIOT/sys/auto_init
"make" -C /home/jovyan/work/iot-lab-training/riot/RIOT/sys/fmt
"make" -C /home/jovyan/work/iot-lab-training/riot/RIOT/sys/hashes
"make" -C /home/jovyan/work/iot-lab-training/riot/RIOT/sys/isrpipe
"make" -C /home/jovyan/work/iot-lab-training/riot/RIOT/sys/newlib_syscalls_default
"make" -C /home/jovyan/work/iot-lab-training/riot/RIOT/sys/pm_layered
"make" -C /home/jovyan/work/iot-lab-training/riot/RIOT/sys/shell
"make" -C /home/jovyan/work/iot-lab-training/riot/RIOT/sys/stdio_uart
"make" -C /home/jovyan/work/iot-lab-training/riot/RIOT/sys/tsrb
text data bss dec hex filename
11336 204 2812 14352 3810 /home/jovyan/work/iot-lab-training/riot/security/hash/bin/iotlab-m3/hash.elf
iotlab-node --jmespath='keys(@)[0]' --format='int' --list grenoble,m3,97 --flash /home/jovyan/work/iot-lab-training/riot/security/hash/bin/iotlab-m3/hash.bin | grep 0
0
make: Leaving directory '/home/jovyan/work/iot-lab-training/riot/security/hash'
jovyan@bf6c278a4e03:~/work/iot-lab-training$ make -C riot/security/hash BOARD=iotlab-m3 IOTLAB_NODE=auto-ssh term
make: Entering directory '/home/jovyan/work/iot-lab-training/riot/security/hash'
ssh -t fun1c9eb3351e@grenoble.iot-lab.info 'socat - tcp:m3-97.grenoble.iot-lab.info:20000'
help
help
Command Description
---------------------------------------
sha256 Compute SHA256 hasg
sha3 Compute SHA3 hash
> sha256 "Exemple !"
sha256 "Exemple !"
SHA256: DF635D342A43E9B0C48F76E7CB9663AB6F3B1632E73D70A2ACF97F675CD0D5DF
> sha256 "Exemple !"
sha256 "Exemple !"
SHA256: DF635D342A43E9B0C48F76E7CB9663AB6F3B1632E73D70A2ACF97F675CD0D5DF
> sha256 "Exemple !"
sha256 "Exemple !"
SHA256: DF635D342A43E9B0C48F76E7CB9663AB6F3B1632E73D70A2ACF97F675CD0D5DF
> sha256 "Exemple !"
sha256 "Exemple !"
SHA256: DF635D342A43E9B0C48F76E7CB9663AB6F3B1632E73D70A2ACF97F675CD0D5DF
> sha256 "Exemple !"
sha256 "Exemple !"
SHA256: DF635D342A43E9B0C48F76E7CB9663AB6F3B1632E73D70A2ACF97F675CD0D5DF
> sha256 "Exemple !"
sha256 "Exemple !"
SHA256: DF635D342A43E9B0C48F76E7CB9663AB6F3B1632E73D70A2ACF97F675CD0D5DF
> sha3 "Exemple !"
sha3 "Exemple !"
SHA3: 21F1AB4E9EFAE9B80208768AF13C6675516ED768B6E531611512AB34E5A34F01
> sha3 "Exemple !"
sha3 "Exemple !"
SHA3: 21F1AB4E9EFAE9B80208768AF13C6675516ED768B6E531611512AB34E5A34F01
> sha256 "Exemple !"
sha256 "Exemple !"
> sha256 "Exemple !"
sha256 "Exe0208768AF13C6675516ED768B6E531611512AB34E5A34F01
> sha256 "Exemple !"
sha256 "Exemple !"
SHA256: DF635D342A43E9B0C48F76E7CB9663AB6F3B1632E73D70A2ACF97E9EFAE9B80208768AF13C6675516ED768B6E531611512AB34E5A34F01
> sha256 "Exemple !"
sha256 "Exemple !"
SHA256: DF635D342A43E9B0C48F76E7CB9663AB6F3B1632E73D70A2ACF97F675CD0D50208768AF13C6675516ED768B6E531611512AB34E5A34F01
> sha3 "Exemple !"
sha3 "Exemple !"
SHA3: 21F1AB4E9EFAE9B80208768AF13C6675516ED768B6E531611512AB34E5A34F01
> sha256 "Exemple !"
sha256 "Exemple !"
5516ED768B6E531611512AB34E5A34F01
> sha256 "Exemple !"
sha256 "Exemple !"
5516ED768B6E531611512AB34E5A34F01
> sha256 "Exemple !"
sha256 "Exemple !"
SHA256: DF635D342A43E9B0C48F76E7CB9663AB6F3B1632E73D70A2ACF97F67FAE9B80208768AF13C6675516ED768B6E531611512AB34E5A34F01