Skip to content

Commit 15f754f

Browse files
committed
Update wolfHSM pointer, fix minor issues
1 parent c52a045 commit 15f754f

File tree

11 files changed

+80
-25
lines changed

11 files changed

+80
-25
lines changed

arch.mk

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ ifeq ($(ARCH),x86_64)
4949
endif
5050
else
5151
MATH_OBJS += $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/sp_x86_64.o
52+
MATH_OBJS += $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/sp_x86_64_asm.o
53+
WOLFCRYPT_OBJS += $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/cpuid.o
5254
endif
5355
endif
5456
ifeq ($(TARGET),x86_64_efi)
@@ -1474,8 +1476,17 @@ ifeq ($(ARCH),sim)
14741476
LDFLAGS+=-m32
14751477
endif
14761478
ifeq ($(SPMATH),1)
1477-
MATH_OBJS += $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/sp_c32.o
1478-
CFLAGS+=-DWOLFSSL_SP_DIV_WORD_HALF
1479+
ifeq ($(FORCE_32BIT),1)
1480+
MATH_OBJS += $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/sp_c32.o
1481+
CFLAGS+=-DWOLFSSL_SP_DIV_WORD_HALF
1482+
else ifeq ($(shell uname -m),aarch64)
1483+
CFLAGS += -DARCH_AARCH64 -DFAST_MEMCPY
1484+
MATH_OBJS += $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/sp_c32.o
1485+
MATH_OBJS += $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/sp_arm64.o
1486+
else
1487+
MATH_OBJS += $(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/sp_c32.o
1488+
CFLAGS+=-DWOLFSSL_SP_DIV_WORD_HALF
1489+
endif
14791490
endif
14801491
ifeq ($(WOLFHSM_CLIENT),1)
14811492
WOLFHSM_OBJS += $(WOLFBOOT_LIB_WOLFHSM)/port/posix/posix_transport_tcp.o

config/examples/sim-wolfHSM-client-certchain-ecc.config

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ WOLFHSM_CLIENT=1
1919

2020
# sizes should be multiple of system page size
2121
#WOLFBOOT_PARTITION_SIZE=0x40000
22-
WOLFBOOT_PARTITION_SIZE=0x100000
22+
WOLFBOOT_PARTITION_SIZE=0x200000
2323
WOLFBOOT_SECTOR_SIZE=0x1000
2424
WOLFBOOT_PARTITION_BOOT_ADDRESS=0x80000
2525
# if on external flash, it should be multiple of system page size
2626
#WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x100000
2727
#WOLFBOOT_PARTITION_SWAP_ADDRESS=0x180000
28-
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x180000
29-
WOLFBOOT_PARTITION_SWAP_ADDRESS=0x280000
28+
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x280000
29+
WOLFBOOT_PARTITION_SWAP_ADDRESS=0x480000
3030

3131
# required for keytools
3232
WOLFBOOT_FIXED_PARTITIONS=1

config/examples/sim-wolfHSM-client-certchain-rsa4096.config

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ WOLFHSM_CLIENT=1
1919

2020
# sizes should be multiple of system page size
2121
#WOLFBOOT_PARTITION_SIZE=0x40000
22-
WOLFBOOT_PARTITION_SIZE=0x100000
22+
WOLFBOOT_PARTITION_SIZE=0x200000
2323
WOLFBOOT_SECTOR_SIZE=0x1000
2424
WOLFBOOT_PARTITION_BOOT_ADDRESS=0x80000
2525
# if on external flash, it should be multiple of system page size
2626
#WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x100000
2727
#WOLFBOOT_PARTITION_SWAP_ADDRESS=0x180000
28-
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x180000
29-
WOLFBOOT_PARTITION_SWAP_ADDRESS=0x280000
28+
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x280000
29+
WOLFBOOT_PARTITION_SWAP_ADDRESS=0x480000
3030

3131
# required for keytools
3232
WOLFBOOT_FIXED_PARTITIONS=1

config/examples/sim-wolfHSM-client-ecc.config

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ DEBUG=0
88
SPMATH=1
99

1010
# sizes should be multiple of system page size
11-
WOLFBOOT_PARTITION_SIZE=0x100000
11+
WOLFBOOT_PARTITION_SIZE=0x200000
1212
WOLFBOOT_SECTOR_SIZE=0x1000
1313
WOLFBOOT_PARTITION_BOOT_ADDRESS=0x80000
1414
# if on external flash, it should be multiple of system page size
15-
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x180000
16-
WOLFBOOT_PARTITION_SWAP_ADDRESS=0x280000
15+
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x280000
16+
WOLFBOOT_PARTITION_SWAP_ADDRESS=0x480000
1717

1818
# required for keytools
1919
WOLFBOOT_FIXED_PARTITIONS=1

config/examples/sim-wolfHSM-client-mldsa.config

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ IMAGE_HEADER_SIZE=8192
2929
#
3030

3131
# sizes should be multiple of system page size
32-
WOLFBOOT_PARTITION_SIZE=0x100000
32+
WOLFBOOT_PARTITION_SIZE=0x200000
3333
WOLFBOOT_SECTOR_SIZE=0x2000
3434
WOLFBOOT_PARTITION_BOOT_ADDRESS=0x80000
3535
# if on external flash, it should be multiple of system page size
36-
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x180000
37-
WOLFBOOT_PARTITION_SWAP_ADDRESS=0x280000
36+
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x280000
37+
WOLFBOOT_PARTITION_SWAP_ADDRESS=0x480000
3838

3939
# required for keytools
4040
WOLFBOOT_FIXED_PARTITIONS=1

hal/sim.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,7 @@ whCommServerConfig cs_conf[1] = {{
183183
}};
184184

185185
/* Crypto context */
186-
whServerCryptoContext crypto[1] = {{
187-
.devId = INVALID_DEVID,
188-
}};
186+
whServerCryptoContext crypto[1] = {0};
189187

190188
#if defined(WOLFHSM_CFG_SHE_EXTENSION)
191189
whServerSheContext she[1] = {{0}};

include/target.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@
3737
#ifdef WOLFBOOT_FIXED_PARTITIONS
3838

3939
#if defined(ARCH_SIM) && !defined(WOLFBOOT_PARTITION_FILENAME)
40+
#ifndef __ASSEMBLER__
4041
#include <stdint.h>
4142
/* use runtime ram base for simulator */
4243
extern uint8_t *sim_ram_base;
4344
#undef ARCH_FLASH_OFFSET
4445
#define ARCH_FLASH_OFFSET ((size_t)sim_ram_base)
46+
#endif /* !__ASSEMBLER__ */
4547
#define WOLFBOOT_PART_USE_ARCH_OFFSET
4648
#endif
4749

include/user_settings.h

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
/* Stdlib Types */
4747
#define CTYPE_USER /* don't let wolfCrypt types.h include ctype.h */
4848

49-
#ifndef WOLFSSL_ARMASM
49+
#if !defined(WOLFSSL_ARMASM) && !defined(__ASSEMBLER__)
5050
#ifndef toupper
5151
extern int toupper(int c);
5252
#endif
@@ -77,8 +77,10 @@ extern int tolower(int c);
7777
#if defined(WOLFBOOT_SIGN_ED25519) || defined(WOLFBOOT_SIGN_SECONDARY_ED25519)
7878
# define HAVE_ED25519
7979
# define ED25519_SMALL
80-
# define NO_ED25519_SIGN
81-
# define NO_ED25519_EXPORT
80+
# if !defined(WOLFBOOT_ENABLE_WOLFHSM_SERVER)
81+
# define NO_ED25519_SIGN
82+
# define NO_ED25519_EXPORT
83+
# endif
8284
# define USE_SLOW_SHA512
8385
# define WOLFSSL_SHA512
8486
#endif
@@ -88,8 +90,10 @@ extern int tolower(int c);
8890
# define HAVE_ED448
8991
# define HAVE_ED448_VERIFY
9092
# define ED448_SMALL
91-
# define NO_ED448_SIGN
92-
# define NO_ED448_EXPORT
93+
# if !defined(WOLFBOOT_ENABLE_WOLFHSM_SERVER)
94+
# define NO_ED448_SIGN
95+
# define NO_ED448_EXPORT
96+
# endif
9397
# define WOLFSSL_SHA3
9498
# define WOLFSSL_SHAKE256
9599
# define WOLFSSL_SHA512
@@ -146,7 +150,6 @@ extern int tolower(int c);
146150
#endif
147151
# define WOLFSSL_SP_MATH
148152
# define WOLFSSL_SP_SMALL
149-
# define SP_WORD_SIZE 32
150153
# define WOLFSSL_HAVE_SP_ECC
151154
# define WOLFSSL_KEY_GEN
152155
# define HAVE_ECC_KEY_EXPORT
@@ -343,12 +346,20 @@ extern int tolower(int c);
343346
# define HAVE___UINT128_T
344347
# define SP_WORD_SIZE 64
345348
# elif defined(ARCH_x86_64) && !defined(FORCE_32BIT)
349+
# define HAVE___UINT128_T
346350
# define SP_WORD_SIZE 64
347-
# ifndef NO_ASM
351+
# if !defined(NO_ASM)
348352
# define WOLFSSL_SP_X86_64_ASM
349353
# endif
350354
# else
351355
# define SP_WORD_SIZE 32
356+
# endif
357+
358+
/* x86_64 ASM 4096-bit routines use 2048-bit helpers internally,
359+
* so ensure 2048-bit asm is not excluded when 4096-bit is needed */
360+
# if defined(WOLFSSL_SP_X86_64_ASM) && defined(WOLFSSL_SP_4096) && \
361+
defined(WOLFSSL_SP_NO_2048)
362+
# undef WOLFSSL_SP_NO_2048
352363
# endif
353364

354365
/* SP Math needs to understand long long */

lib/wolfHSM

Submodule wolfHSM updated 120 files

src/xmalloc.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ struct xmalloc_slot {
7575
#define MP_POINT_SIZE (196)
7676
#define MP_DIGITS_BUFFER_SIZE_0 (MP_DIGIT_SIZE * 18 * 8)
7777
#define MP_DIGITS_BUFFER_SIZE_1 (MP_DIGIT_SIZE * 2 * 8 * 6)
78+
#elif SP_WORD_SIZE == 64
79+
#define MP_POINT_SIZE (200)
80+
#define MP_DIGITS_BUFFER_SIZE_0 (MP_DIGIT_SIZE * 18 * 4)
81+
#define MP_DIGITS_BUFFER_SIZE_1 (MP_DIGIT_SIZE * (2 * 4 * 6))
82+
#define MP_DIGITS_BUFFER_SIZE_2 (MP_DIGIT_SIZE * (2 * 4 * 6))
83+
#define MP_MONTGOMERY_SIZE (sizeof(int64_t) * 2 * 8)
7884
#else
7985
#define MP_POINT_SIZE (220)
8086
#define MP_DIGITS_BUFFER_SIZE_0 (MP_DIGIT_SIZE * 18 * 9)
@@ -91,6 +97,12 @@ struct xmalloc_slot {
9197
#define MP_DIGITS_BUFFER_SIZE_0 (MP_DIGIT_SIZE * 18 * 12)
9298
#define MP_DIGITS_BUFFER_SIZE_1 (MP_DIGIT_SIZE * 2 * 12 * 6)
9399
#define MP_MONTGOMERY_SIZE (sizeof(int64_t) * 12)
100+
#elif SP_WORD_SIZE == 64
101+
#define MP_POINT_SIZE (344)
102+
#define MP_DIGITS_BUFFER_SIZE_0 (MP_DIGIT_SIZE * 18 * 7)
103+
#define MP_DIGITS_BUFFER_SIZE_1 (MP_DIGIT_SIZE * (2 * 7 * 6))
104+
#define MP_DIGITS_BUFFER_SIZE_2 (MP_DIGIT_SIZE * (2 * 7 * 6))
105+
#define MP_MONTGOMERY_SIZE (sizeof(int64_t) * 2 * 12)
94106
#else
95107
#define MP_POINT_SIZE (364)
96108
#define MP_DIGITS_BUFFER_SIZE_0 (MP_DIGIT_SIZE * 18 * 15)
@@ -107,6 +119,12 @@ struct xmalloc_slot {
107119
#define MP_DIGITS_BUFFER_SIZE_0 (MP_DIGIT_SIZE * 18 * 17)
108120
#define MP_DIGITS_BUFFER_SIZE_1 (MP_DIGIT_SIZE * 2 * 17 * 6)
109121
#define MP_MONTGOMERY_SIZE (sizeof(int64_t) * 12)
122+
#elif SP_WORD_SIZE == 64
123+
#define MP_POINT_SIZE (440)
124+
#define MP_DIGITS_BUFFER_SIZE_0 (MP_DIGIT_SIZE * 18 * 9)
125+
#define MP_DIGITS_BUFFER_SIZE_1 (MP_DIGIT_SIZE * (2 * 9 * 6))
126+
#define MP_DIGITS_BUFFER_SIZE_2 (MP_DIGIT_SIZE * (2 * 9 * 6))
127+
#define MP_MONTGOMERY_SIZE (sizeof(int64_t) * 2 * 12)
110128
#else
111129
#define MP_POINT_SIZE (508)
112130
#define MP_DIGITS_BUFFER_SIZE_0 (MP_DIGIT_SIZE * 18 * 21)
@@ -129,7 +147,13 @@ struct xmalloc_slot {
129147
#endif
130148
static uint8_t mp_points_0[MP_POINT_SIZE * 2];
131149
static uint8_t mp_points_1[MP_POINT_SIZE * 3];
150+
/* x86_64 SP always uses win_add_sub with 33+2 precomputed points,
151+
* even when WOLFSSL_SP_SMALL is defined */
152+
#if SP_WORD_SIZE == 64
153+
static uint8_t mp_points_2[MP_POINT_SIZE * (33 + 2)];
154+
#else
132155
static uint8_t mp_points_2[MP_POINT_SIZE * (16 + 1)];
156+
#endif
133157
static uint8_t mp_digits_buffer_0[MP_DIGITS_BUFFER_SIZE_0];
134158
static uint8_t mp_digits_buffer_1[MP_DIGITS_BUFFER_SIZE_1];
135159
#if !defined(WOLFSSL_SP_ARM_CORTEX_M_ASM) && (defined(WOLFBOOT_SIGN_ECC256) || defined(WOLFBOOT_SIGN_ECC384) || defined(WOLFBOOT_SIGN_ECC521))
@@ -234,7 +258,11 @@ static struct xmalloc_slot xmalloc_pool[] = {
234258
{ (uint8_t *)mp_digits_buffer_2, MP_DIGITS_BUFFER_SIZE_2, 0 },
235259
{ (uint8_t *)mp_montgomery, MP_MONTGOMERY_SIZE, 0 },
236260
#endif
261+
#if SP_WORD_SIZE == 64
262+
{ (uint8_t *)mp_points_2, MP_POINT_SIZE * (33 + 2), 0 },
263+
#else
237264
{ (uint8_t *)mp_points_2, MP_POINT_SIZE * (16 + 1), 0 },
265+
#endif
238266
{ (uint8_t *)mp_digits_buffer_0, MP_DIGITS_BUFFER_SIZE_0, 0},
239267
{ (uint8_t *)mp_digits_buffer_1, MP_DIGITS_BUFFER_SIZE_1, 0},
240268
#ifndef WC_NO_CACHE_RESISTANT

0 commit comments

Comments
 (0)