Skip to content

Commit

Permalink
hotp: display keys on screen
Browse files Browse the repository at this point in the history
  • Loading branch information
bradjc committed Jun 19, 2024
1 parent 8c6262e commit 2a300a9
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/tutorials/hotp/hotp_milestone_one/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ TOCK_USERLAND_BASE_DIR = ../../../../
# Which files to compile.
C_SRCS := $(wildcard *.c)

# Include U8G2 graphics library.
EXTERN_LIBS += $(TOCK_USERLAND_BASE_DIR)/u8g2

# Include userland master makefile. Contains rules and flags for actually
# building the application.
include $(TOCK_USERLAND_BASE_DIR)/AppMakefile.mk
5 changes: 5 additions & 0 deletions examples/tutorials/hotp/hotp_milestone_one/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

// Local includes
#include "base32.h"
#include "screen.h"
#include "step0.h"


Expand Down Expand Up @@ -108,6 +109,8 @@ int main(void) {
// Configure a default HOTP secret
program_default_secret(&stored_key);

display_hotp_keys(&stored_key, 1);

// Main loop. Waits for button presses
while (true) {
// Yield until a button is pressed
Expand All @@ -123,10 +126,12 @@ int main(void) {
// Handle long presses (program new secret)
if (new_val) {
program_new_secret(&stored_key);
display_hotp_keys(&stored_key, 1);

// Handle short presses on already configured keys (output next code)
} else if (stored_key.len > 0) {
get_next_code(&stored_key, KEY_DIGITS);
display_hotp_keys(&stored_key, 1);

// Error for short press on a non-configured key
} else if (stored_key.len == 0) {
Expand Down
3 changes: 3 additions & 0 deletions examples/tutorials/hotp/hotp_milestone_three/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ C_SRCS := $(wildcard *.c)
# Make sure we have storage permissions.
ELF2TAB_ARGS += --write_id 0x4016 --read_ids 0x4016 --access_ids 0x4016

# Include U8G2 graphics library.
EXTERN_LIBS += $(TOCK_USERLAND_BASE_DIR)/u8g2

# Include userland master makefile. Contains rules and flags for actually
# building the application.
include $(TOCK_USERLAND_BASE_DIR)/AppMakefile.mk
5 changes: 5 additions & 0 deletions examples/tutorials/hotp/hotp_milestone_three/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

// Local includes
#include "base32.h"
#include "screen.h"
#include "step0.h"
#include "step1.h"
#include "step2.h"
Expand Down Expand Up @@ -65,6 +66,8 @@ int main(void) {
program_default_secret(&stored_keys[0]);
}

display_hotp_keys(stored_keys, NUM_KEYS);

// Main loop. Waits for button presses
while (true) {
// Yield until a button is pressed
Expand All @@ -81,11 +84,13 @@ int main(void) {
if (new_val) {
program_new_secret(&stored_keys[btn_num]);
save_key(&stored_keys[btn_num], btn_num);
display_hotp_keys(stored_keys, NUM_KEYS);

} else if (btn_num < NUM_KEYS && stored_keys[btn_num].len > 0) {
// Handle short presses on already configured keys (output next code).
get_next_code(&stored_keys[btn_num], key_digits[btn_num]);
save_key(&stored_keys[btn_num], btn_num);
display_hotp_keys(stored_keys, NUM_KEYS);

} else if (stored_keys[btn_num].len == 0) {
// Error for short press on a non-configured key.
Expand Down
1 change: 1 addition & 0 deletions examples/tutorials/hotp/hotp_milestone_three/screen.c
1 change: 1 addition & 0 deletions examples/tutorials/hotp/hotp_milestone_three/screen.h
3 changes: 3 additions & 0 deletions examples/tutorials/hotp/hotp_milestone_two/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ C_SRCS := $(wildcard *.c)
# Make sure we have storage permissions.
ELF2TAB_ARGS += --write_id 0x4016 --read_ids 0x4016 --access_ids 0x4016

# Include U8G2 graphics library.
EXTERN_LIBS += $(TOCK_USERLAND_BASE_DIR)/u8g2

# Include userland master makefile. Contains rules and flags for actually
# building the application.
include $(TOCK_USERLAND_BASE_DIR)/AppMakefile.mk
5 changes: 5 additions & 0 deletions examples/tutorials/hotp/hotp_milestone_two/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

// Local includes
#include "base32.h"
#include "screen.h"
#include "step0.h"
#include "step1.h"

Expand Down Expand Up @@ -108,6 +109,8 @@ int main(void) {
program_default_secret(&stored_key);
}

display_hotp_keys(&stored_key, 1);

// Main loop. Waits for button presses
while (true) {
// Yield until a button is pressed
Expand All @@ -124,11 +127,13 @@ int main(void) {
if (new_val) {
program_new_secret(&stored_key);
save_key(&stored_key, 0);
display_hotp_keys(&stored_key, 1);

// Handle short presses on already configured keys (output next code)
} else if (stored_key.len > 0) {
get_next_code(&stored_key, KEY_DIGITS);
save_key(&stored_key, 0);
display_hotp_keys(&stored_key, 1);

// Error for short press on a non-configured key
} else if (stored_key.len == 0) {
Expand Down
1 change: 1 addition & 0 deletions examples/tutorials/hotp/hotp_milestone_two/screen.c
1 change: 1 addition & 0 deletions examples/tutorials/hotp/hotp_milestone_two/screen.h

0 comments on commit 2a300a9

Please sign in to comment.