Skip to content

Commit

Permalink
Unit testing bip32 derivation and hmac_sha512
Browse files Browse the repository at this point in the history
- Added bip32 derivation tests on separate source file
- Added hmac_sha512 tests using 3rd party test vectors
- Added test helpers to common x86 test artifacts
- Moved common.mk to common directory
- Updated existing Makefile(s) to account for moved common.mk
  • Loading branch information
amendelzon committed Oct 18, 2024
1 parent 21aeacd commit 3463dc3
Show file tree
Hide file tree
Showing 13 changed files with 11,913 additions and 12 deletions.
7 changes: 4 additions & 3 deletions firmware/src/hal/x86/test/bip32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

include ../common.mk
include ../common/common.mk

ifneq ($(DEBUG),)
CFLAGS += -DDEBUG_BIP32
endif

CFLAGS += -iquote ../common

PROG = test.out
OBJS = bip32.o hmac_sha512.o endian.o bigdigits.o bigdigits_helper.o
OBJS += test_bip32.o log.o

OBJS += ../common/test_helpers.o test_bip32.o test_bip32_derivation.o log.o

all: $(PROG)

Expand Down
10 changes: 8 additions & 2 deletions firmware/src/hal/x86/test/bip32/test_bip32.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void test_parses_correctly(const char* path,
const uint32_t expected_parts[],
const size_t expected_parts_count) {

printf("Testing path \"%s\" is parsed correctly... ", path);
printf("\tPath \"%s\" is parsed correctly... ", path);
fflush(stdout);

uint8_t binpath[5 * sizeof(uint32_t) + 1];
Expand All @@ -57,15 +57,19 @@ void test_parses_correctly(const char* path,
void test_parsing_fails(const char* path) {
uint8_t binpath[5 * sizeof(uint32_t) + 1];

printf("Testing path \"%s\" parsing fails... ", path);
printf("\tPath \"%s\" parsing fails... ", path);
fflush(stdout);

assert(!bip32_parse_path(path, binpath));

printf("OK!\n");
}

// Implemented in test_bip32_derivation.c
void test_derivation();

int main() {
printf("Testing BIP32 path parsing...\n");
test_parses_correctly("m/0/0/0/0/0", (const uint32_t[]){0, 0, 0, 0, 0}, 5);
test_parses_correctly(
"m/10/20/30/40/50", (const uint32_t[]){10, 20, 30, 40, 50}, 5);
Expand Down Expand Up @@ -116,5 +120,7 @@ int main() {
test_parsing_fails("m/2147483648'/0/0/0/0");
test_parsing_fails("m/01234567890/0/0/0/0");

test_derivation();

return 0;
}
Loading

0 comments on commit 3463dc3

Please sign in to comment.