Skip to content

Commit dff533f

Browse files
committed
Fix integer sign for variables and fields using negative error values
1 parent 4479aec commit dff533f

File tree

2 files changed

+44
-34
lines changed

2 files changed

+44
-34
lines changed

src/wh_nvm_flash.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ static int nfPartition_CheckDataRange(whNvmFlashContext* context,
121121
uint32_t byte_offset,
122122
uint32_t byte_count);
123123

124-
static uint32_t nfObject_Offset(whNvmFlashContext* context, int partition,
125-
int object_index);
124+
static int nfObject_Offset(whNvmFlashContext* context, int partition,
125+
int object_index, uint32_t *object_offset);
126126
static int nfObject_ProgramBegin(whNvmFlashContext* context, int partition,
127127
int object_index, uint32_t epoch, uint32_t start, whNvmMetadata* meta);
128128
static int nfObject_ProgramDataBytes(whNvmFlashContext* context, int partition,
@@ -512,16 +512,19 @@ static int nfPartition_CheckDataRange(whNvmFlashContext* context,
512512
return WH_ERROR_OK;
513513
}
514514

515-
static uint32_t nfObject_Offset(whNvmFlashContext* context, int partition,
516-
int object_index)
515+
static int nfObject_Offset(whNvmFlashContext* context, int partition,
516+
int object_index, uint32_t *offset)
517517
{
518-
if (context == NULL) {
518+
if (context == NULL || offset == NULL) {
519519
return WH_ERROR_BADARGS;
520520
}
521521

522-
return nfPartition_Offset(context,partition) +
523-
NF_PARTITION_DIRECTORY_OFFSET +
524-
NF_DIRECTORY_OBJECT_OFFSET(object_index);
522+
523+
*offset = nfPartition_Offset(context,partition) +
524+
NF_PARTITION_DIRECTORY_OFFSET +
525+
NF_DIRECTORY_OBJECT_OFFSET(object_index);
526+
527+
return WH_ERROR_OK;
525528
}
526529

527530
static int nfObject_ProgramBegin(whNvmFlashContext* context, int partition,
@@ -539,7 +542,10 @@ static int nfObject_ProgramBegin(whNvmFlashContext* context, int partition,
539542
return WH_ERROR_BADARGS;
540543
}
541544

542-
object_offset = nfObject_Offset(context, partition, object_index);
545+
rc = nfObject_Offset(context, partition, object_index, &object_offset);
546+
if (rc != WH_ERROR_OK) {
547+
return rc;
548+
}
543549

544550
/* Program the object epoch */
545551
rc = wh_FlashUnit_Program(
@@ -601,14 +607,18 @@ static int nfObject_ProgramDataBytes(whNvmFlashContext* context, int partition,
601607
static int nfObject_ProgramFinish(whNvmFlashContext* context, int partition,
602608
int object_index, uint32_t byte_count)
603609
{
610+
int rc;
604611
uint32_t object_offset = 0;
605612
whFlashUnit state_count = BASE_STATE | WHFU_BYTES2UNITS(byte_count);
606613

607614
if ((context == NULL) || (context->cb == NULL)) {
608615
return WH_ERROR_BADARGS;
609616
}
610617

611-
object_offset = nfObject_Offset(context, partition, object_index);
618+
rc = nfObject_Offset(context, partition, object_index, &object_offset);
619+
if (rc != WH_ERROR_OK) {
620+
return rc;
621+
}
612622

613623
/* Program the object flag->state_count */
614624
return wh_FlashUnit_Program(

wolfhsm/wh_message_she.h

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ typedef struct {
4343

4444
/* Set UID Response */
4545
typedef struct {
46-
uint32_t rc;
46+
int32_t rc;
4747
uint8_t WH_PAD[4];
4848
} whMessageShe_SetUidResponse;
4949

@@ -64,8 +64,8 @@ typedef struct {
6464

6565
/* Secure Boot Init Response */
6666
typedef struct {
67-
uint32_t rc;
68-
uint32_t status;
67+
int32_t rc;
68+
int32_t status;
6969
} whMessageShe_SecureBootInitResponse;
7070

7171
/* Secure Boot Init translation functions */
@@ -88,8 +88,8 @@ typedef struct {
8888

8989
/* Secure Boot Update Response */
9090
typedef struct {
91-
uint32_t rc;
92-
uint32_t status;
91+
int32_t rc;
92+
int32_t status;
9393
} whMessageShe_SecureBootUpdateResponse;
9494

9595
/* Secure Boot Update translation functions */
@@ -103,8 +103,8 @@ int wh_MessageShe_TranslateSecureBootUpdateResponse(
103103

104104
/* Secure Boot Finish Response */
105105
typedef struct {
106-
uint32_t rc;
107-
uint32_t status;
106+
int32_t rc;
107+
int32_t status;
108108
} whMessageShe_SecureBootFinishResponse;
109109

110110
/* Secure Boot Finish translation function */
@@ -114,7 +114,7 @@ int wh_MessageShe_TranslateSecureBootFinishResponse(
114114

115115
/* Get Status Response */
116116
typedef struct {
117-
uint32_t rc;
117+
int32_t rc;
118118
uint8_t sreg;
119119
uint8_t WH_PAD[7];
120120
} whMessageShe_GetStatusResponse;
@@ -133,7 +133,7 @@ typedef struct {
133133

134134
/* Load Key Response */
135135
typedef struct {
136-
uint32_t rc;
136+
int32_t rc;
137137
uint8_t messageFour[WH_SHE_M4_SZ];
138138
uint8_t messageFive[WH_SHE_M5_SZ];
139139
} whMessageShe_LoadKeyResponse;
@@ -154,7 +154,7 @@ typedef struct {
154154

155155
/* Load Plain Key Response */
156156
typedef struct {
157-
uint32_t rc;
157+
int32_t rc;
158158
} whMessageShe_LoadPlainKeyResponse;
159159

160160
/* Load Plain Key translation function */
@@ -168,7 +168,7 @@ int wh_MessageShe_TranslateLoadPlainKeyResponse(
168168

169169
/* Export RAM Key Response */
170170
typedef struct {
171-
uint32_t rc;
171+
int32_t rc;
172172
uint8_t messageOne[WH_SHE_M1_SZ];
173173
uint8_t messageTwo[WH_SHE_M2_SZ];
174174
uint8_t messageThree[WH_SHE_M3_SZ];
@@ -183,8 +183,8 @@ int wh_MessageShe_TranslateExportRamKeyResponse(
183183

184184
/* Init RNG Response */
185185
typedef struct {
186-
uint32_t rc;
187-
uint32_t status;
186+
int32_t rc;
187+
int32_t status;
188188
} whMessageShe_InitRngResponse;
189189

190190
/* Init RNG translation function */
@@ -194,7 +194,7 @@ int wh_MessageShe_TranslateInitRngResponse(
194194

195195
/* RND Response */
196196
typedef struct {
197-
uint32_t rc;
197+
int32_t rc;
198198
uint8_t rnd[WH_SHE_KEY_SZ];
199199
} whMessageShe_RndResponse;
200200

@@ -210,8 +210,8 @@ typedef struct {
210210

211211
/* Extend Seed Response */
212212
typedef struct {
213-
uint32_t rc;
214-
uint32_t status;
213+
int32_t rc;
214+
int32_t status;
215215
} whMessageShe_ExtendSeedResponse;
216216

217217
/* Extend Seed translation functions */
@@ -235,7 +235,7 @@ typedef struct {
235235

236236
/* Encrypt ECB Response */
237237
typedef struct {
238-
uint32_t rc;
238+
int32_t rc;
239239
uint32_t sz;
240240
/* Data follows:
241241
* uint8_t out[sz]
@@ -264,7 +264,7 @@ typedef struct {
264264

265265
/* Encrypt CBC Response */
266266
typedef struct {
267-
uint32_t rc;
267+
int32_t rc;
268268
uint32_t sz;
269269
/* Data follows:
270270
* uint8_t out[sz]
@@ -292,7 +292,7 @@ typedef struct {
292292

293293
/* Decrypt ECB Response */
294294
typedef struct {
295-
uint32_t rc;
295+
int32_t rc;
296296
uint32_t sz;
297297
/* Data follows:
298298
* uint8_t out[sz]
@@ -321,7 +321,7 @@ typedef struct {
321321

322322
/* Decrypt CBC Response */
323323
typedef struct {
324-
uint32_t rc;
324+
int32_t rc;
325325
uint32_t sz;
326326
/* Data follows:
327327
* uint8_t out[sz]
@@ -348,7 +348,7 @@ typedef struct {
348348

349349
/* Generate MAC Response */
350350
typedef struct {
351-
uint32_t rc;
351+
int32_t rc;
352352
uint8_t mac[WH_SHE_KEY_SZ];
353353
} whMessageShe_GenMacResponse;
354354

@@ -375,8 +375,8 @@ typedef struct {
375375

376376
/* Verify MAC Response */
377377
typedef struct {
378-
uint32_t rc;
379-
uint8_t status;
378+
int32_t rc;
379+
int8_t status;
380380
uint8_t WH_PAD[7];
381381
} whMessageShe_VerifyMacResponse;
382382

@@ -391,4 +391,4 @@ int wh_MessageShe_TranslateVerifyMacResponse(
391391

392392
#endif /* WOLFHSM_CFG_SHE_EXTENSION */
393393

394-
#endif /* !WOLFHSM_WH_MESSAGE_SHE_H_ */
394+
#endif /* !WOLFHSM_WH_MESSAGE_SHE_H_ */

0 commit comments

Comments
 (0)