Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/sign1_mldsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
static const char PAYLOAD[] = "wolfCOSE ML-DSA payload";

/* ML-DSA messages and scratch are large; keep them off the stack. */
static unsigned char gScratch[20000];
static unsigned char gMsg[8192];
static uint8_t gScratch[20000];
static uint8_t gMsg[8192];
Comment on lines +38 to +39

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to make the same change in examples/sign1_lms.c too?


int main(void)
{
Expand Down
8 changes: 4 additions & 4 deletions examples/sign1_verify_lean.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@

/* P-256 public key (X and Y, 32 bytes each). The matching private key lives
* off-device and is never present in a lean verify build. */
static const unsigned char PUB_X[32] = {
static const uint8_t PUB_X[32] = {
0x2c,0x3c,0x9f,0xd7,0xfc,0x15,0x48,0x7b,0x37,0x18,0x0e,0x37,0x95,0x56,0xb4,0xfd,
0xbb,0x11,0x3c,0x78,0xe0,0xa5,0x3a,0x0b,0x25,0x71,0xf5,0xff,0xb0,0xdf,0x93,0x28};
static const unsigned char PUB_Y[32] = {
static const uint8_t PUB_Y[32] = {
0x10,0xc3,0x85,0xc2,0xb6,0x8f,0x79,0xd7,0xe9,0x5e,0x43,0x62,0xf5,0xf4,0x06,0x21,
0xdc,0x2c,0xf6,0x55,0x87,0xeb,0x94,0x61,0x13,0xe5,0xe2,0x8c,0xeb,0x2e,0xd2,0xce};

/* A COSE_Sign1 (ES256) over the payload below, signed off-device. */
static const unsigned char COSE_SIGN1[] = {
static const uint8_t COSE_SIGN1[] = {
210,132,67,161,1,38,160,88,31,119,111,108,102,67,79,83,69,32,115,105,122,101,
32,98,101,110,99,104,109,97,114,107,32,112,97,121,108,111,97,100,88,64,59,0,
231,221,224,83,68,247,200,191,96,153,241,21,82,224,140,57,84,22,93,156,13,27,
Expand All @@ -60,7 +60,7 @@ int main(void)
ecc_key eccKey;
WOLFCOSE_KEY key;
WOLFCOSE_HDR hdr;
unsigned char scratch[256];
uint8_t scratch[256];
const uint8_t* payload = NULL;
size_t payloadLen = 0;
int ret;
Expand Down
6 changes: 3 additions & 3 deletions examples/sign1_verify_mldsa.c

Large diffs are not rendered by default.

15 changes: 6 additions & 9 deletions src/wolfcose_alg.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ int wolfCose_AeadCheckPayloadLen(int32_t alg, size_t payloadLen)
/* ----- Internal: HMAC helpers ----- */

#if defined(WOLFCOSE_HAVE_HMAC)
int wolfCose_HmacType(int32_t alg, int* hmacType)
int wolfCose_HmacType(int32_t alg, enum wc_HashType* hmacType)
{
int ret = WOLFCOSE_SUCCESS;

Expand All @@ -439,17 +439,17 @@ int wolfCose_HmacType(int32_t alg, int* hmacType)
switch (alg) {
#ifdef WOLFCOSE_HAVE_HMAC256
case WOLFCOSE_ALG_HMAC_256_256:
*hmacType = WC_SHA256;
*hmacType = WC_HASH_TYPE_SHA256;
break;
#endif
#ifdef WOLFCOSE_HAVE_HMAC384
case WOLFCOSE_ALG_HMAC_384_384:
*hmacType = WC_SHA384;
*hmacType = WC_HASH_TYPE_SHA384;
break;
#endif
#ifdef WOLFCOSE_HAVE_HMAC512
case WOLFCOSE_ALG_HMAC_512_512:
*hmacType = WC_SHA512;
*hmacType = WC_HASH_TYPE_SHA512;
break;
#endif
default:
Expand Down Expand Up @@ -548,16 +548,13 @@ int wolfCose_RsaPssCheckKey(const WOLFCOSE_KEY* key,
int modulusMaterialized = 0;
uint8_t modulus[WOLFCOSE_RSA_PSS_MIN_SZ] = {0};
word32 modulusLen32 = (word32)sizeof(modulus);
#if !defined(HAVE_ECC) && !defined(WOLFSSL_EXPORT_INT) && \
!defined(WOLFSSL_RSA_VERIFY_ONLY)
#if !defined(HAVE_ECC) && !defined(WOLFSSL_EXPORT_INT)
word32 exponentLen = (word32)sizeof(modulus);
#endif
#if defined(HAVE_ECC) || defined(WOLFSSL_EXPORT_INT)
int modulusExportRet = wc_export_int(&rsaKey->n, modulus,
&modulusLen32, (word32)sizeof(modulus),
WC_TYPE_UNSIGNED_BIN);
#elif defined(WOLFSSL_RSA_VERIFY_ONLY)
int modulusExportRet = -1;
#else
/* The modulus output overwrites the unused exponent output. */
int modulusExportRet = wc_RsaFlattenPublicKey(rsaKey,
Expand Down Expand Up @@ -605,7 +602,7 @@ int wolfCose_RsaPssCheckKey(const WOLFCOSE_KEY* key,
#if defined(WOLFCOSE_HAVE_RSAPSS) && \
(defined(WOLFCOSE_SIGN1_SIGN) || defined(WOLFCOSE_SIGN1_VERIFY) || \
defined(WOLFCOSE_SIGN_SIGN) || defined(WOLFCOSE_SIGN_VERIFY))
int wolfCose_HashToMgf(enum wc_HashType hashType, int* mgf)
int wolfCose_HashToMgf(enum wc_HashType hashType, WOLFCOSE_MGF_ID* mgf)
{
int ret = WOLFCOSE_SUCCESS;

Expand Down
11 changes: 8 additions & 3 deletions src/wolfcose_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ WOLFCOSE_LOCAL int wolfCose_AeadTagLen(int32_t alg, size_t* tagLen);
* \param hmacType Output: wolfCrypt hash type for HMAC.
* \return WOLFCOSE_SUCCESS or WOLFCOSE_E_COSE_BAD_ALG.
*/
WOLFCOSE_LOCAL int wolfCose_HmacType(int32_t alg, int* hmacType);
WOLFCOSE_LOCAL int wolfCose_HmacType(int32_t alg,
enum wc_HashType* hmacType);
#endif /* WOLFCOSE_HAVE_HMAC */

#ifdef WOLFCOSE_HAVE_ECDSA
Expand Down Expand Up @@ -422,7 +423,9 @@ WOLFCOSE_LOCAL int wolfCose_RsaPssCheckKey(const WOLFCOSE_KEY* key,
size_t* modulusLen);

/* HashToMgf -- defined in wolfcose_alg.c */
WOLFCOSE_LOCAL int wolfCose_HashToMgf(enum wc_HashType hashType, int* mgf);
typedef int WOLFCOSE_MGF_ID;
WOLFCOSE_LOCAL int wolfCose_HashToMgf(enum wc_HashType hashType,
WOLFCOSE_MGF_ID* mgf);
#endif

/* InInt32Range -- defined in wolfcose_hdr.c */
Expand Down Expand Up @@ -602,7 +605,9 @@ WOLFCOSE_LOCAL int wolfCose_LmsCheckKey(const WOLFCOSE_KEY* key);

#if defined(WOLFCOSE_EXT_SIGN)
/* ExtSignAlg -- defined in wolfcose_sign1.c */
WOLFCOSE_LOCAL int wolfCose_ExtSignAlg(int32_t alg, int* preHashes);
typedef uint8_t WOLFCOSE_PREHASH_FLAG;
WOLFCOSE_LOCAL int wolfCose_ExtSignAlg(int32_t alg,
WOLFCOSE_PREHASH_FLAG* preHashes);
#endif

#if defined(WOLFCOSE_SIGN1_SIGN) || defined(WOLFCOSE_SIGN_SIGN) || \
Expand Down
8 changes: 4 additions & 4 deletions src/wolfcose_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ int wc_CoseMac_Create(const WOLFCOSE_RECIPIENT* recipients,
size_t i;
#ifdef WOLFCOSE_HAVE_HMAC
Hmac hmac;
int hashType = 0;
enum wc_HashType hashType = WC_HASH_TYPE_NONE;
int hmacInited = 0;
#endif

Expand Down Expand Up @@ -216,7 +216,7 @@ int wc_CoseMac_Create(const WOLFCOSE_RECIPIENT* recipients,
recipients[0].key->key.symm.keyLen);
}
if (ret == WOLFCOSE_SUCCESS) {
int hmacRet = wc_HmacSetKey(&hmac, hashType,
int hmacRet = wc_HmacSetKey(&hmac, (int)hashType,
recipients[0].key->key.symm.key,
(word32)recipients[0].key->key.symm.keyLen);
if (hmacRet != 0) {
Expand Down Expand Up @@ -405,7 +405,7 @@ int wc_CoseMac_Verify(const WOLFCOSE_RECIPIENT* recipient,
int bodyAlgProtected = 0;
#ifdef WOLFCOSE_HAVE_HMAC
Hmac hmac;
int hashType = 0;
enum wc_HashType hashType = WC_HASH_TYPE_NONE;
int hmacInited = 0;
#endif
const uint8_t* verifyPayload = NULL;
Expand Down Expand Up @@ -690,7 +690,7 @@ int wc_CoseMac_Verify(const WOLFCOSE_RECIPIENT* recipient,
recipient->key->key.symm.keyLen);
}
if (ret == WOLFCOSE_SUCCESS) {
int hmacRet = wc_HmacSetKey(&hmac, hashType,
int hmacRet = wc_HmacSetKey(&hmac, (int)hashType,
recipient->key->key.symm.key,
(word32)recipient->key->key.symm.keyLen);
if (hmacRet != 0) {
Expand Down
11 changes: 6 additions & 5 deletions src/wolfcose_mac0.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ int wc_CoseMac0_Create(const WOLFCOSE_KEY* key, int32_t alg,
#ifdef WOLFCOSE_HAVE_HMAC
Hmac hmac;
int hmacInited = 0;
int hmacType = 0;
enum wc_HashType hmacType = WC_HASH_TYPE_NONE;
#endif
uint8_t protectedBuf[WOLFCOSE_PROTECTED_HDR_MAX];
size_t protectedLen = 0;
Expand Down Expand Up @@ -428,7 +428,7 @@ int wc_CoseMac0_Create(const WOLFCOSE_KEY* key, int32_t alg,
}
if (ret == WOLFCOSE_SUCCESS) {
INJECT_FAILURE(WOLF_FAIL_HMAC_SET_KEY, -1,
ret = wc_HmacSetKey(&hmac, hmacType, key->key.symm.key,
ret = wc_HmacSetKey(&hmac, (int)hmacType, key->key.symm.key,
(word32)key->key.symm.keyLen));
if (ret != 0) {
ret = WOLFCOSE_E_CRYPTO;
Expand Down Expand Up @@ -495,7 +495,8 @@ int wc_CoseMac0_Create(const WOLFCOSE_KEY* key, int32_t alg,

/* unprotected headers map (with kid if present) */
if (ret == WOLFCOSE_SUCCESS) {
unprotectedEntries = (size_t)(((kid != NULL) && (kidLen > 0u)) ? 1u : 0u);
unprotectedEntries = ((kid != NULL) && (kidLen > 0u)) ?
(size_t)1u : (size_t)0u;
ret = wc_CBOR_EncodeMapStart(&outCtx, unprotectedEntries);
}
if ((ret == WOLFCOSE_SUCCESS) && (kid != NULL) && (kidLen > 0u)) {
Expand Down Expand Up @@ -555,7 +556,7 @@ int wc_CoseMac0_Verify(const WOLFCOSE_KEY* key,
#ifdef WOLFCOSE_HAVE_HMAC
Hmac hmac;
int hmacInited = 0;
int hmacType = 0;
enum wc_HashType hmacType = WC_HASH_TYPE_NONE;
#endif
WOLFCOSE_CBOR_CTX ctx;
uint64_t tag;
Expand Down Expand Up @@ -721,7 +722,7 @@ int wc_CoseMac0_Verify(const WOLFCOSE_KEY* key,
ret = wolfCose_HmacCheckKeyLen(alg, key->key.symm.keyLen);
}
if (ret == WOLFCOSE_SUCCESS) {
ret = wc_HmacSetKey(&hmac, hmacType, key->key.symm.key,
ret = wc_HmacSetKey(&hmac, (int)hmacType, key->key.symm.key,
(word32)key->key.symm.keyLen);
if (ret != 0) {
ret = WOLFCOSE_E_CRYPTO;
Expand Down
20 changes: 11 additions & 9 deletions src/wolfcose_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ int wc_CoseSign_Sign(const WOLFCOSE_SIGNATURE* signers, size_t signerCount,
size_t need = 0;
int inPlace = 0;
#if defined(WOLFCOSE_EXT_SIGN)
int extPreHash = 0;
WOLFCOSE_PREHASH_FLAG extPreHash =
(WOLFCOSE_PREHASH_FLAG)0u;
#endif

/* ML-DSA and HSS-LMS sign the Sig_structure in place; a delegated
Expand Down Expand Up @@ -413,7 +414,7 @@ int wc_CoseSign_Sign(const WOLFCOSE_SIGNATURE* signers, size_t signerCount,
(signers[i].key->signCb != NULL)) {
ret = wolfCose_ExtSignAlg(signers[i].algId, &extPreHash);
inPlace = 0;
if (extPreHash == 0) {
if (extPreHash == 0u) {
inPlace = 1;
}
}
Expand Down Expand Up @@ -556,13 +557,14 @@ int wc_CoseSign_Sign(const WOLFCOSE_SIGNATURE* signers, size_t signerCount,
if ((ret == WOLFCOSE_SUCCESS) && (signerKey->signCb != NULL)) {
size_t extSigLen = 0;
size_t sigOff = 0;
int extPreHash = 0;
WOLFCOSE_PREHASH_FLAG extPreHash =
(WOLFCOSE_PREHASH_FLAG)0u;

/* Same placement rule as wc_CoseSign1_Sign: only an in-place
* Sig_structure signer needs the structure kept intact. */
ret = wolfCose_ExtSignAlg(signer->algId, &extPreHash);
if (ret == WOLFCOSE_SUCCESS) {
sigOff = (extPreHash != 0) ? 0u : sigStructLen;
sigOff = (extPreHash != 0u) ? 0u : sigStructLen;
if (scratchSz <= sigOff) {
ret = WOLFCOSE_E_BUFFER_TOO_SMALL;
}
Expand Down Expand Up @@ -650,7 +652,7 @@ int wc_CoseSign_Sign(const WOLFCOSE_SIGNATURE* signers, size_t signerCount,
((signer->algId == WOLFCOSE_ALG_PS256) ||
(signer->algId == WOLFCOSE_ALG_PS384) ||
(signer->algId == WOLFCOSE_ALG_PS512))) {
int mgf = 0;
WOLFCOSE_MGF_ID mgf = 0;
ret = wolfCose_RsaPssCheckKey(signerKey, NULL);
if (ret == WOLFCOSE_SUCCESS) {
ret = wolfCose_HashToMgf(hashType, &mgf);
Expand Down Expand Up @@ -786,9 +788,9 @@ int wc_CoseSign_Sign(const WOLFCOSE_SIGNATURE* signers, size_t signerCount,
/* Signer unprotected headers (may include kid). Match Sign1/Mac0
* by requiring both kid and kidLen to be present. */
if (ret == WOLFCOSE_SUCCESS) {
unprotectedEntries = (size_t)(((signer->kid != NULL) &&
(signer->kidLen > 0u))
? 1u : 0u);
unprotectedEntries = ((signer->kid != NULL) &&
(signer->kidLen > 0u)) ?
(size_t)1u : (size_t)0u;
ret = wc_CBOR_EncodeMapStart(&outCtx, unprotectedEntries);
}

Expand Down Expand Up @@ -1188,7 +1190,7 @@ int wc_CoseSign_Verify(const WOLFCOSE_KEY* verifyKey,
((alg == WOLFCOSE_ALG_PS256) || (alg == WOLFCOSE_ALG_PS384) ||
(alg == WOLFCOSE_ALG_PS512))) {
RsaKey* rsaKey = NULL;
int mgf = 0;
WOLFCOSE_MGF_ID mgf = 0;
ret = wolfCose_RsaPssCheckKey(verifyKey, NULL);
if (ret == WOLFCOSE_SUCCESS) {
rsaKey = verifyKey->key.rsa;
Expand Down
Loading
Loading