Skip to content

Commit b9d1585

Browse files
authored
Merge pull request #527 from pqcfox/root-of-trust-final-touches
tutorials: Root of Trust Tutorial Final Touches
2 parents 4f18914 + 7ac884e commit b9d1585

File tree

5 files changed

+17
-29
lines changed
  • examples/tutorials/root_of_trust
    • encryption_service_milestone_one
    • encryption_service_milestone_three
    • encryption_service_milestone_two
    • questionable_service_milestone_one
    • suspicious_service_milestone_one

5 files changed

+17
-29
lines changed

examples/tutorials/root_of_trust/encryption_service_milestone_one/main.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
// plaintexts over UART and encrypts them, logging status over IPC back to the screen
55
// application.
66

7-
#include "libtock/tock.h"
87
#include <stdio.h>
98
#include <stdlib.h>
9+
#include <string.h>
1010

1111
#include <libtock-sync/interface/console.h>
1212
#include <libtock/kernel/ipc.h>
13+
#include <libtock/tock.h>
1314

1415
#define LOG_WIDTH 32
1516

@@ -63,12 +64,8 @@ static int setup_logging() {
6364
static int log_to_screen(const char* message) {
6465
returncode_t ret;
6566

66-
// Copy up to the log buffer's size of the message, with room for a null byte.
67-
uint16_t len = strnlen(message, sizeof(log_buf) - 1);
68-
memcpy(log_buf, message, len);
69-
70-
// Add the null byte.
71-
log_buf[len] = '\0';
67+
// Load the log buffer with our message
68+
strlcpy(log_buf, message, LOG_WIDTH);
7269

7370
// Start the logging process.
7471
ret = ipc_notify_service(screen_service);

examples/tutorials/root_of_trust/encryption_service_milestone_three/main.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
// plaintexts over UART and encrypts them, logging status over IPC back to the screen
55
// application.
66

7-
#include "libtock/tock.h"
87
#include <stdio.h>
98
#include <stdlib.h>
9+
#include <string.h>
1010

1111
#include <libtock-sync/interface/console.h>
1212
#include <libtock/kernel/ipc.h>
13+
#include <libtock/tock.h>
1314

1415
#include "oracle.h"
1516

@@ -66,12 +67,8 @@ static int setup_logging() {
6667
static int log_to_screen(const char* message) {
6768
returncode_t ret;
6869

69-
// Copy up to the log buffer's size of the message, with room for a null byte.
70-
uint16_t len = strnlen(message, sizeof(log_buf) - 1);
71-
memcpy(log_buf, message, len);
72-
73-
// Add the null byte.
74-
log_buf[len] = '\0';
70+
// Load the log buffer with our message
71+
strlcpy(log_buf, message, LOG_WIDTH);
7572

7673
// Start the logging process.
7774
ret = ipc_notify_service(screen_service);

examples/tutorials/root_of_trust/encryption_service_milestone_two/main.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
// plaintexts over UART and encrypts them, logging status over IPC back to the screen
55
// application.
66

7-
#include "libtock/tock.h"
87
#include <stdio.h>
98
#include <stdlib.h>
9+
#include <string.h>
1010

1111
#include <libtock-sync/interface/console.h>
1212
#include <libtock/kernel/ipc.h>
13+
#include <libtock/tock.h>
1314

1415
#define LOG_WIDTH 32
1516

@@ -63,12 +64,8 @@ static int setup_logging() {
6364
static int log_to_screen(const char* message) {
6465
returncode_t ret;
6566

66-
// Copy up to the log buffer's size of the message, with room for a null byte.
67-
uint16_t len = strnlen(message, sizeof(log_buf) - 1);
68-
memcpy(log_buf, message, len);
69-
70-
// Add the null byte.
71-
log_buf[len] = '\0';
67+
// Load the log buffer with our message
68+
strlcpy(log_buf, message, LOG_WIDTH);
7269

7370
// Start the logging process.
7471
ret = ipc_notify_service(screen_service);

examples/tutorials/root_of_trust/questionable_service_milestone_one/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ int main(void) {
9999
}
100100

101101
// Bring everything down!
102-
syscall_return_t cr = command(0x99998, 1, 0, 0);
102+
syscall_return_t cr = command(0x99999, 2, 0, 0);
103103
if (cr.type != TOCK_SYSCALL_SUCCESS) {
104104
return tock_command_return_novalue_to_returncode(cr);
105105
}

examples/tutorials/root_of_trust/suspicious_service_milestone_one/main.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
// When selected by the main screen HWRoT Demo application, attempts to dump its
44
// own SRAM, followed by the SRAM of the encryption service application.
55

6-
#include "libtock/tock.h"
76
#include <stdio.h>
87
#include <stdlib.h>
8+
#include <string.h>
99

1010
#include <libtock/kernel/ipc.h>
11+
#include <libtock/tock.h>
1112

1213
#define ENCRYPTION_SRAM_START 0x2000A000
1314
#define ENCRYPTION_SRAM_END 0x2000BFFF
@@ -64,12 +65,8 @@ static int setup_logging() {
6465
static int log_to_screen(const char* message) {
6566
returncode_t ret;
6667

67-
// Copy up to the log buffer's size of the message, with room for a null byte.
68-
uint16_t len = strnlen(message, sizeof(log_buf) - 1);
69-
memcpy(log_buf, message, len);
70-
71-
// Add the null byte.
72-
log_buf[len] = '\0';
68+
// Load the log buffer with our message
69+
strlcpy(log_buf, message, LOG_WIDTH);
7370

7471
// Start the logging process.
7572
ret = ipc_notify_service(screen_service);

0 commit comments

Comments
 (0)