diff --git a/examples/sign1_lms.c b/examples/sign1_lms.c index 74e4937..c911b57 100644 --- a/examples/sign1_lms.c +++ b/examples/sign1_lms.c @@ -45,9 +45,9 @@ static const char PAYLOAD[] = "wolfCOSE HSS-LMS payload"; #endif /* LMS signatures run ~1.5KB for L1/H10/W8; keep buffers off the stack. */ -static unsigned char gScratch[8192]; -static unsigned char gMsg[4096]; -static unsigned char gPrivStore[HSS_MAX_PRIVATE_KEY_LEN]; +static uint8_t gScratch[8192]; +static uint8_t gMsg[4096]; +static uint8_t gPrivStore[HSS_MAX_PRIVATE_KEY_LEN]; static int lms_write_cb(const byte* priv, word32 privSz, void* context) { diff --git a/examples/sign1_mldsa.c b/examples/sign1_mldsa.c index f3f7494..583bebc 100644 --- a/examples/sign1_mldsa.c +++ b/examples/sign1_mldsa.c @@ -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]; int main(void) { diff --git a/examples/sign1_verify_lean.c b/examples/sign1_verify_lean.c index 5940195..0555515 100644 --- a/examples/sign1_verify_lean.c +++ b/examples/sign1_verify_lean.c @@ -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, @@ -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; diff --git a/examples/sign1_verify_mldsa.c b/examples/sign1_verify_mldsa.c index 2d53351..bee60bb 100644 --- a/examples/sign1_verify_mldsa.c +++ b/examples/sign1_verify_mldsa.c @@ -31,8 +31,8 @@ #include #include -static const unsigned char MLDSA44_PUB[1312]={81,23,10,39,96,186,64,19,212,69,119,21,76,9,214,64,219,188,78,188,158,14,164,77,150,121,186,137,116,182,170,125,162,143,1,20,46,90,111,90,255,63,32,14,99,3,227,62,58,222,55,83,29,82,44,78,100,15,128,204,239,137,41,236,243,233,97,192,211,148,67,110,209,221,60,248,93,151,2,104,57,155,19,164,190,52,199,56,179,89,144,111,17,139,42,35,4,120,137,84,240,96,246,53,137,172,59,114,209,192,221,163,37,78,208,58,6,182,228,81,157,248,57,143,160,112,4,57,184,164,250,86,213,242,128,75,23,142,232,145,79,5,6,189,77,247,73,94,20,98,158,246,95,142,123,3,54,116,107,172,88,202,243,128,235,191,59,215,102,91,239,24,247,120,135,31,225,109,144,158,185,235,117,89,85,34,38,32,53,226,34,131,73,198,232,201,239,48,218,2,28,234,105,76,226,9,230,190,159,95,86,21,229,63,48,243,125,52,152,184,198,248,164,151,253,202,10,64,160,113,210,9,3,74,141,222,250,245,119,100,219,229,90,62,15,147,47,68,70,97,225,103,96,166,230,106,147,149,30,199,28,116,247,62,9,253,225,153,240,214,156,101,141,41,93,32,139,145,54,86,81,62,246,205,224,134,111,55,72,110,228,216,186,0,147,161,12,56,221,81,177,235,27,255,192,35,83,64,254,1,125,114,173,71,231,191,127,73,35,167,249,242,236,200,45,22,8,175,94,8,202,91,201,86,22,207,125,161,196,242,102,161,55,45,230,174,237,125,101,181,56,42,120,40,167,102,96,145,20,12,128,140,127,3,213,178,62,234,236,205,129,115,60,237,133,109,233,223,205,132,173,33,132,164,123,143,196,219,7,103,190,247,74,39,45,101,160,93,199,66,225,84,73,157,35,133,157,167,222,223,132,15,214,168,64,37,40,44,29,13,58,148,187,231,78,170,166,251,107,29,195,239,51,124,1,142,255,237,255,116,193,175,21,63,201,215,10,185,141,73,196,227,150,229,169,131,76,253,204,219,151,38,207,236,98,166,130,230,226,218,9,38,196,139,231,180,81,47,231,146,5,125,136,20,240,103,202,206,52,31,189,176,97,110,72,139,158,77,91,98,224,170,216,25,133,73,166,43,38,120,107,103,25,193,141,184,117,63,221,126,2,63,39,18,161,83,113,193,50,132,56,93,102,58,2,137,84,163,116,56,157,114,159,74,148,152,140,229,249,78,202,232,165,175,57,198,38,205,128,252,107,203,56,52,237,206,20,32,108,81,12,42,107,224,157,232,230,220,55,71,127,117,33,53,222,106,230,137,47,61,238,245,99,184,208,195,123,112,211,144,169,6,135,76,251,78,110,32,229,41,101,33,254,163,9,44,204,24,248,196,63,238,147,74,102,55,139,40,145,73,196,26,103,248,167,226,128,33,222,241,214,10,125,51,198,74,53,248,42,64,51,69,116,211,13,64,189,114,101,15,193,144,76,12,129,201,15,57,148,135,27,245,199,122,4,213,29,98,34,53,243,208,190,202,200,110,161,15,30,103,102,168,54,49,42,17,70,35,213,212,121,151,158,172,5,110,89,190,55,44,49,204,251,169,157,120,104,88,161,208,102,174,54,235,107,14,168,144,218,106,124,49,187,252,138,2,157,205,84,198,114,44,55,18,69,253,24,251,33,243,243,126,233,125,36,249,210,2,157,50,214,99,51,66,35,173,241,74,225,176,249,74,213,206,215,149,197,175,124,212,248,193,108,57,62,124,185,208,231,69,56,124,78,183,34,57,224,140,243,131,71,31,145,37,48,252,188,63,210,0,149,127,237,47,167,205,201,64,123,27,41,207,70,248,109,87,198,159,82,87,43,26,242,39,194,203,15,141,235,87,100,255,149,128,36,71,190,252,38,157,187,17,206,74,228,242,50,250,150,220,216,206,176,79,174,221,68,172,136,91,137,234,155,239,145,31,187,199,98,248,24,171,2,38,189,67,230,35,124,162,199,186,79,148,65,39,76,162,1,53,246,46,198,17,202,87,64,242,78,198,43,235,80,50,123,15,130,123,34,17,159,56,8,248,133,160,230,42,251,80,82,134,13,153,158,198,88,26,147,130,1,152,133,171,159,49,213,97,53,18,135,177,242,191,49,80,245,218,21,156,22,220,82,73,28,148,129,162,176,182,174,3,144,235,41,64,103,191,249,150,164,122,45,47,77,69,193,15,26,121,154,30,63,121,164,230,86,220,116,104,29,62,246,214,189,133,167,120,102,78,35,162,237,166,237,19,88,177,147,145,234,91,104,171,113,13,250,167,66,30,127,73,53,104,136,155,40,240,248,28,0,208,109,7,218,89,156,18,24,70,25,56,248,113,168,164,197,249,82,162,119,55,118,135,152,236,186,11,8,107,4,110,180,23,129,61,209,155,23,182,190,85,208,245,192,106,252,164,173,23,105,76,252,175,33,30,198,51,203,167,11,217,239,217,4,245,22,217,78,233,191,139,118,17,253,198,61,204,33,250,203,249,204,135,80,204,82,58,7,95,48,172,239,234,171,192,243,200,220,214,39,158,252,5,126,142,230,194,211,208,231,122,59,207,226,11,173,53,210,168,112,30,25,63,62,69,203,255,138,9,199,243,146,243,248,130,213,253,254,248,59,150,139,253,78,17,178,202,45,49,177,4,214,240,54,209,55,75,125,203,126,51,189,212,170,172,185,190,197,251,118,120,164,203,167,240,41,249,121,118,135,190,11,123,109,208,42,202,167,206,81,227,18,119,36,128,235,90,91,68,72,205,135,54,133,62,65,123,112,78,15,22,106,177,58,189,56,142,41,174,16,52,199,149,133,158,236,94,148,84,164,112,26,180,193,26,145,155,29,38,25,52,80,27,141,207,89,7,115,146,119,246,126,200,36,117,105,104,244,194,79,39,169,160,116,141,158,96,139,50,107,43,}; -static const unsigned char MLDSA44_COSE[2466]={210,132,68,161,1,56,47,160,88,33,119,111,108,102,67,79,83,69,32,77,76,45,68,83,65,32,98,101,110,99,104,109,97,114,107,32,112,97,121,108,111,97,100,89,9,116,81,253,252,115,238,218,166,203,103,70,245,7,213,174,169,167,96,85,133,60,243,119,233,122,138,142,71,159,125,155,88,186,243,181,43,181,207,44,39,237,185,60,231,23,150,41,140,161,114,36,158,222,254,207,216,190,136,148,138,218,255,122,30,53,183,136,1,55,141,181,93,90,71,100,101,246,141,133,56,200,242,174,179,251,166,162,138,203,253,120,200,32,46,123,193,218,209,181,7,35,109,155,118,29,82,0,121,10,245,176,97,64,31,48,253,5,144,240,139,192,155,203,58,81,159,191,152,110,104,84,40,39,191,116,235,150,123,31,104,248,168,150,210,207,13,168,147,83,239,172,204,242,228,153,67,238,43,130,192,101,146,203,176,129,101,191,78,204,43,64,175,230,207,226,222,91,205,255,109,30,43,98,214,54,206,203,78,211,91,208,55,222,40,152,249,151,208,212,88,178,172,8,93,165,207,94,250,170,240,19,87,204,228,16,196,206,45,140,149,145,117,238,187,115,200,84,136,68,20,202,203,229,238,11,143,37,182,177,189,183,156,122,11,105,208,244,197,156,105,50,155,118,216,174,122,115,70,95,70,167,1,67,227,107,228,182,252,5,67,110,38,178,36,45,158,146,146,126,184,250,75,19,3,179,226,19,25,11,167,60,161,26,143,177,99,166,32,28,176,198,122,133,197,47,114,153,142,190,105,108,112,170,17,58,79,186,198,170,177,232,71,153,119,19,146,241,42,144,20,167,138,240,90,224,157,16,99,89,253,225,185,60,193,143,57,25,183,255,216,130,254,133,229,161,35,173,83,200,228,90,97,254,128,169,154,40,58,255,101,105,111,151,250,213,20,181,190,14,192,84,231,138,250,203,112,149,242,60,237,114,159,67,237,119,9,159,186,20,149,166,45,134,249,75,196,125,246,132,13,31,61,150,19,103,226,188,68,202,108,95,51,209,75,246,51,9,9,207,231,9,180,150,108,229,6,28,241,244,91,20,107,28,119,15,74,245,65,209,99,219,77,234,123,49,27,246,91,14,190,44,228,242,42,111,164,102,131,188,219,69,49,68,6,168,157,47,187,111,112,242,5,84,150,49,242,169,25,55,140,249,199,213,123,82,231,33,205,23,235,120,194,20,122,53,127,103,159,90,107,80,97,27,237,173,57,168,33,56,180,142,227,67,138,186,164,118,58,83,31,32,211,13,60,78,138,15,199,96,6,71,115,160,208,111,32,245,229,141,3,68,39,176,203,125,199,25,158,249,205,71,255,100,253,40,245,211,155,25,156,159,9,194,253,238,14,181,197,144,231,218,75,177,116,16,181,175,67,219,149,58,119,10,45,55,207,175,102,2,59,64,90,107,18,16,147,37,115,79,189,199,195,122,26,186,229,29,160,119,65,100,11,96,220,95,31,135,140,139,30,62,71,216,45,83,201,46,2,3,96,183,6,214,234,138,142,98,187,192,146,221,232,112,48,164,58,88,58,243,101,5,95,140,247,107,170,130,131,35,202,243,191,115,220,23,188,150,17,23,133,133,143,247,61,19,186,19,213,152,134,219,86,170,230,232,2,251,18,231,52,142,45,120,191,54,41,129,221,181,128,63,108,7,167,25,119,161,164,144,94,95,250,159,209,241,88,93,228,162,35,69,226,89,187,225,185,249,168,157,236,64,58,66,226,161,227,4,131,226,2,234,24,19,203,107,245,88,99,74,253,87,78,136,117,165,82,224,129,146,1,183,84,104,43,189,96,206,32,253,17,75,205,79,128,36,138,101,231,155,75,215,4,229,3,96,59,83,59,36,22,236,107,191,134,180,34,104,157,121,121,12,190,89,96,126,208,30,165,32,224,127,116,37,173,84,234,219,173,17,105,151,96,21,199,77,131,101,61,104,129,53,208,53,4,108,87,143,119,117,181,81,162,140,106,37,237,236,67,104,88,26,240,95,149,227,15,22,16,72,83,138,240,78,139,220,224,157,247,186,173,88,90,58,253,214,111,243,28,15,133,48,23,171,251,241,222,196,226,27,224,41,149,33,13,1,249,40,202,246,70,32,225,130,45,210,118,143,240,63,83,182,90,86,224,158,103,216,9,101,194,181,145,206,155,212,206,238,80,191,87,48,217,140,65,214,146,222,240,117,216,142,107,252,247,221,77,144,41,8,80,147,197,246,252,79,160,247,102,214,133,38,235,29,63,198,229,162,90,178,133,58,253,134,175,74,93,232,86,237,240,50,148,17,210,190,9,242,31,6,226,181,101,242,86,145,4,227,120,181,203,107,91,34,144,117,0,48,125,6,246,144,233,198,65,55,116,222,115,27,185,89,75,110,25,66,82,57,213,34,186,156,58,210,253,202,183,149,105,97,192,84,224,186,116,232,116,236,193,185,202,104,227,194,238,85,160,139,209,28,4,197,199,238,34,61,218,131,223,182,248,122,183,137,128,132,228,223,235,3,145,252,63,132,53,2,64,225,20,197,218,155,120,111,80,245,197,165,115,72,158,174,112,206,59,254,34,190,218,135,44,171,171,211,197,39,232,245,218,59,8,250,64,8,167,98,172,220,176,148,99,102,7,196,218,135,55,64,217,110,41,252,227,219,164,151,104,24,42,6,136,199,56,111,122,211,13,46,192,135,57,124,153,47,148,117,48,242,69,229,218,50,176,156,87,165,49,50,221,35,128,15,154,190,99,246,32,46,187,65,106,139,89,160,77,152,10,84,42,95,30,111,107,47,98,231,159,106,150,146,209,184,163,208,43,183,212,131,237,157,177,114,55,193,227,210,177,233,20,77,13,91,172,13,125,135,242,209,60,29,165,206,69,226,177,141,128,186,171,129,179,17,0,214,63,77,186,108,185,125,6,225,0,249,237,68,43,248,39,18,160,97,29,201,242,187,135,2,156,254,124,192,121,52,254,114,14,237,106,102,122,64,57,42,118,173,189,11,65,255,191,27,47,98,28,27,80,138,91,245,3,39,204,243,159,237,72,3,250,88,138,96,60,156,12,239,44,232,249,158,72,90,44,37,114,128,54,35,108,227,153,73,123,176,242,204,246,98,253,108,141,64,120,10,100,64,214,48,126,62,128,225,83,58,201,227,3,97,182,157,7,144,32,144,254,160,250,103,82,242,113,49,240,249,244,213,95,216,33,206,124,31,250,226,151,122,1,243,170,127,139,67,75,217,136,249,194,202,130,6,249,238,96,152,207,40,37,47,8,28,45,68,58,11,187,24,132,56,17,122,219,81,200,185,4,43,229,131,252,250,35,144,123,165,240,66,193,29,54,90,94,86,107,172,6,84,34,58,53,239,247,123,179,57,51,147,144,200,59,198,136,144,203,45,231,132,2,178,88,18,58,197,254,198,74,184,237,169,123,185,160,105,70,186,153,165,239,90,2,51,223,100,54,117,186,200,191,217,112,87,43,106,86,113,124,8,148,162,121,162,78,194,160,19,160,65,11,199,246,197,245,196,46,186,233,104,213,37,211,114,116,249,139,116,202,140,26,253,24,215,21,18,65,42,40,98,146,15,4,217,59,248,106,18,6,201,107,118,249,66,85,109,140,86,109,82,106,185,21,69,66,209,218,103,98,34,158,61,84,9,114,67,118,12,192,145,153,253,161,8,88,57,77,124,151,33,107,248,165,144,23,99,120,189,71,64,204,136,56,169,195,132,12,191,175,92,11,38,214,104,82,203,238,246,104,187,172,241,61,223,76,149,148,22,195,192,255,128,176,35,194,56,217,14,25,33,89,50,250,74,156,4,139,190,94,125,250,150,27,142,103,60,206,142,152,108,105,72,223,221,140,218,26,36,112,156,163,182,124,53,218,93,39,159,239,149,123,248,130,230,177,251,128,93,127,219,33,78,109,23,210,119,134,58,190,103,131,201,107,7,211,83,40,125,229,74,136,188,153,124,67,31,81,126,8,165,117,191,186,191,246,224,18,173,164,101,239,63,218,159,173,68,79,63,246,255,8,234,190,253,152,16,254,188,245,192,129,69,175,159,119,249,50,123,22,227,176,32,77,235,58,240,168,164,100,189,27,122,49,104,176,192,139,164,204,195,157,58,167,192,221,255,179,230,212,132,15,119,222,99,72,90,70,18,227,26,242,131,70,50,54,197,25,41,45,46,136,34,194,135,185,51,93,117,149,181,229,194,225,212,145,203,237,120,199,180,187,230,69,159,84,114,34,116,181,194,185,12,66,57,178,60,40,196,196,233,0,159,235,15,190,139,35,41,229,116,211,116,213,32,203,199,66,32,121,78,165,92,120,51,248,19,0,236,98,242,179,0,24,202,194,61,145,39,82,174,215,99,172,181,4,164,135,26,200,123,97,254,154,232,218,239,5,49,35,141,241,169,88,156,8,223,111,175,189,113,221,144,149,178,29,165,200,1,249,212,97,108,208,133,73,255,191,188,39,8,131,181,26,131,155,58,171,31,222,117,31,106,216,68,232,67,236,73,114,70,72,226,1,216,123,248,94,61,193,249,224,125,162,241,9,27,50,19,165,152,240,10,89,73,186,113,71,76,167,209,80,105,219,107,105,32,227,186,38,238,158,110,35,82,242,63,248,100,210,89,28,38,220,212,8,180,251,67,35,156,149,58,104,168,154,238,128,96,156,50,113,237,126,11,102,149,26,20,115,226,130,216,16,251,82,175,234,21,200,75,28,247,235,133,180,207,165,89,34,225,36,81,143,163,22,28,192,249,223,139,208,232,15,164,94,46,196,16,250,125,164,198,202,130,9,104,109,54,68,114,26,222,76,230,37,34,77,242,7,82,180,131,12,133,18,193,167,167,232,110,138,33,55,18,233,213,255,57,63,39,191,29,3,40,185,36,52,3,131,224,103,80,160,191,2,140,88,173,168,153,61,235,39,119,130,124,231,199,133,153,172,180,5,171,115,18,145,220,10,132,240,83,147,132,41,146,0,98,42,208,45,252,1,100,162,126,224,179,231,51,15,95,192,152,247,7,134,118,40,100,8,117,42,247,92,103,229,95,44,132,136,1,57,125,151,160,250,109,245,173,48,185,65,84,119,55,127,117,175,237,139,55,73,17,131,32,83,117,51,140,244,24,124,251,77,42,237,74,158,121,224,101,239,117,190,187,223,30,120,210,209,137,196,213,37,80,2,141,254,134,54,75,230,157,1,81,176,122,250,182,36,241,7,111,154,228,179,129,245,47,90,78,101,87,254,143,46,134,90,30,24,178,19,105,30,95,123,209,207,53,70,39,39,234,192,72,16,139,52,48,219,21,4,12,23,55,59,84,91,94,97,150,180,183,194,207,237,7,25,71,99,121,134,146,156,161,163,176,182,193,212,241,2,7,8,19,37,43,45,70,79,87,118,151,179,194,200,229,230,249,253,254,27,32,78,96,117,125,150,156,162,192,247,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15,30,50,61,}; +static const uint8_t MLDSA44_PUB[1312]={81,23,10,39,96,186,64,19,212,69,119,21,76,9,214,64,219,188,78,188,158,14,164,77,150,121,186,137,116,182,170,125,162,143,1,20,46,90,111,90,255,63,32,14,99,3,227,62,58,222,55,83,29,82,44,78,100,15,128,204,239,137,41,236,243,233,97,192,211,148,67,110,209,221,60,248,93,151,2,104,57,155,19,164,190,52,199,56,179,89,144,111,17,139,42,35,4,120,137,84,240,96,246,53,137,172,59,114,209,192,221,163,37,78,208,58,6,182,228,81,157,248,57,143,160,112,4,57,184,164,250,86,213,242,128,75,23,142,232,145,79,5,6,189,77,247,73,94,20,98,158,246,95,142,123,3,54,116,107,172,88,202,243,128,235,191,59,215,102,91,239,24,247,120,135,31,225,109,144,158,185,235,117,89,85,34,38,32,53,226,34,131,73,198,232,201,239,48,218,2,28,234,105,76,226,9,230,190,159,95,86,21,229,63,48,243,125,52,152,184,198,248,164,151,253,202,10,64,160,113,210,9,3,74,141,222,250,245,119,100,219,229,90,62,15,147,47,68,70,97,225,103,96,166,230,106,147,149,30,199,28,116,247,62,9,253,225,153,240,214,156,101,141,41,93,32,139,145,54,86,81,62,246,205,224,134,111,55,72,110,228,216,186,0,147,161,12,56,221,81,177,235,27,255,192,35,83,64,254,1,125,114,173,71,231,191,127,73,35,167,249,242,236,200,45,22,8,175,94,8,202,91,201,86,22,207,125,161,196,242,102,161,55,45,230,174,237,125,101,181,56,42,120,40,167,102,96,145,20,12,128,140,127,3,213,178,62,234,236,205,129,115,60,237,133,109,233,223,205,132,173,33,132,164,123,143,196,219,7,103,190,247,74,39,45,101,160,93,199,66,225,84,73,157,35,133,157,167,222,223,132,15,214,168,64,37,40,44,29,13,58,148,187,231,78,170,166,251,107,29,195,239,51,124,1,142,255,237,255,116,193,175,21,63,201,215,10,185,141,73,196,227,150,229,169,131,76,253,204,219,151,38,207,236,98,166,130,230,226,218,9,38,196,139,231,180,81,47,231,146,5,125,136,20,240,103,202,206,52,31,189,176,97,110,72,139,158,77,91,98,224,170,216,25,133,73,166,43,38,120,107,103,25,193,141,184,117,63,221,126,2,63,39,18,161,83,113,193,50,132,56,93,102,58,2,137,84,163,116,56,157,114,159,74,148,152,140,229,249,78,202,232,165,175,57,198,38,205,128,252,107,203,56,52,237,206,20,32,108,81,12,42,107,224,157,232,230,220,55,71,127,117,33,53,222,106,230,137,47,61,238,245,99,184,208,195,123,112,211,144,169,6,135,76,251,78,110,32,229,41,101,33,254,163,9,44,204,24,248,196,63,238,147,74,102,55,139,40,145,73,196,26,103,248,167,226,128,33,222,241,214,10,125,51,198,74,53,248,42,64,51,69,116,211,13,64,189,114,101,15,193,144,76,12,129,201,15,57,148,135,27,245,199,122,4,213,29,98,34,53,243,208,190,202,200,110,161,15,30,103,102,168,54,49,42,17,70,35,213,212,121,151,158,172,5,110,89,190,55,44,49,204,251,169,157,120,104,88,161,208,102,174,54,235,107,14,168,144,218,106,124,49,187,252,138,2,157,205,84,198,114,44,55,18,69,253,24,251,33,243,243,126,233,125,36,249,210,2,157,50,214,99,51,66,35,173,241,74,225,176,249,74,213,206,215,149,197,175,124,212,248,193,108,57,62,124,185,208,231,69,56,124,78,183,34,57,224,140,243,131,71,31,145,37,48,252,188,63,210,0,149,127,237,47,167,205,201,64,123,27,41,207,70,248,109,87,198,159,82,87,43,26,242,39,194,203,15,141,235,87,100,255,149,128,36,71,190,252,38,157,187,17,206,74,228,242,50,250,150,220,216,206,176,79,174,221,68,172,136,91,137,234,155,239,145,31,187,199,98,248,24,171,2,38,189,67,230,35,124,162,199,186,79,148,65,39,76,162,1,53,246,46,198,17,202,87,64,242,78,198,43,235,80,50,123,15,130,123,34,17,159,56,8,248,133,160,230,42,251,80,82,134,13,153,158,198,88,26,147,130,1,152,133,171,159,49,213,97,53,18,135,177,242,191,49,80,245,218,21,156,22,220,82,73,28,148,129,162,176,182,174,3,144,235,41,64,103,191,249,150,164,122,45,47,77,69,193,15,26,121,154,30,63,121,164,230,86,220,116,104,29,62,246,214,189,133,167,120,102,78,35,162,237,166,237,19,88,177,147,145,234,91,104,171,113,13,250,167,66,30,127,73,53,104,136,155,40,240,248,28,0,208,109,7,218,89,156,18,24,70,25,56,248,113,168,164,197,249,82,162,119,55,118,135,152,236,186,11,8,107,4,110,180,23,129,61,209,155,23,182,190,85,208,245,192,106,252,164,173,23,105,76,252,175,33,30,198,51,203,167,11,217,239,217,4,245,22,217,78,233,191,139,118,17,253,198,61,204,33,250,203,249,204,135,80,204,82,58,7,95,48,172,239,234,171,192,243,200,220,214,39,158,252,5,126,142,230,194,211,208,231,122,59,207,226,11,173,53,210,168,112,30,25,63,62,69,203,255,138,9,199,243,146,243,248,130,213,253,254,248,59,150,139,253,78,17,178,202,45,49,177,4,214,240,54,209,55,75,125,203,126,51,189,212,170,172,185,190,197,251,118,120,164,203,167,240,41,249,121,118,135,190,11,123,109,208,42,202,167,206,81,227,18,119,36,128,235,90,91,68,72,205,135,54,133,62,65,123,112,78,15,22,106,177,58,189,56,142,41,174,16,52,199,149,133,158,236,94,148,84,164,112,26,180,193,26,145,155,29,38,25,52,80,27,141,207,89,7,115,146,119,246,126,200,36,117,105,104,244,194,79,39,169,160,116,141,158,96,139,50,107,43,}; +static const uint8_t MLDSA44_COSE[2466]={210,132,68,161,1,56,47,160,88,33,119,111,108,102,67,79,83,69,32,77,76,45,68,83,65,32,98,101,110,99,104,109,97,114,107,32,112,97,121,108,111,97,100,89,9,116,81,253,252,115,238,218,166,203,103,70,245,7,213,174,169,167,96,85,133,60,243,119,233,122,138,142,71,159,125,155,88,186,243,181,43,181,207,44,39,237,185,60,231,23,150,41,140,161,114,36,158,222,254,207,216,190,136,148,138,218,255,122,30,53,183,136,1,55,141,181,93,90,71,100,101,246,141,133,56,200,242,174,179,251,166,162,138,203,253,120,200,32,46,123,193,218,209,181,7,35,109,155,118,29,82,0,121,10,245,176,97,64,31,48,253,5,144,240,139,192,155,203,58,81,159,191,152,110,104,84,40,39,191,116,235,150,123,31,104,248,168,150,210,207,13,168,147,83,239,172,204,242,228,153,67,238,43,130,192,101,146,203,176,129,101,191,78,204,43,64,175,230,207,226,222,91,205,255,109,30,43,98,214,54,206,203,78,211,91,208,55,222,40,152,249,151,208,212,88,178,172,8,93,165,207,94,250,170,240,19,87,204,228,16,196,206,45,140,149,145,117,238,187,115,200,84,136,68,20,202,203,229,238,11,143,37,182,177,189,183,156,122,11,105,208,244,197,156,105,50,155,118,216,174,122,115,70,95,70,167,1,67,227,107,228,182,252,5,67,110,38,178,36,45,158,146,146,126,184,250,75,19,3,179,226,19,25,11,167,60,161,26,143,177,99,166,32,28,176,198,122,133,197,47,114,153,142,190,105,108,112,170,17,58,79,186,198,170,177,232,71,153,119,19,146,241,42,144,20,167,138,240,90,224,157,16,99,89,253,225,185,60,193,143,57,25,183,255,216,130,254,133,229,161,35,173,83,200,228,90,97,254,128,169,154,40,58,255,101,105,111,151,250,213,20,181,190,14,192,84,231,138,250,203,112,149,242,60,237,114,159,67,237,119,9,159,186,20,149,166,45,134,249,75,196,125,246,132,13,31,61,150,19,103,226,188,68,202,108,95,51,209,75,246,51,9,9,207,231,9,180,150,108,229,6,28,241,244,91,20,107,28,119,15,74,245,65,209,99,219,77,234,123,49,27,246,91,14,190,44,228,242,42,111,164,102,131,188,219,69,49,68,6,168,157,47,187,111,112,242,5,84,150,49,242,169,25,55,140,249,199,213,123,82,231,33,205,23,235,120,194,20,122,53,127,103,159,90,107,80,97,27,237,173,57,168,33,56,180,142,227,67,138,186,164,118,58,83,31,32,211,13,60,78,138,15,199,96,6,71,115,160,208,111,32,245,229,141,3,68,39,176,203,125,199,25,158,249,205,71,255,100,253,40,245,211,155,25,156,159,9,194,253,238,14,181,197,144,231,218,75,177,116,16,181,175,67,219,149,58,119,10,45,55,207,175,102,2,59,64,90,107,18,16,147,37,115,79,189,199,195,122,26,186,229,29,160,119,65,100,11,96,220,95,31,135,140,139,30,62,71,216,45,83,201,46,2,3,96,183,6,214,234,138,142,98,187,192,146,221,232,112,48,164,58,88,58,243,101,5,95,140,247,107,170,130,131,35,202,243,191,115,220,23,188,150,17,23,133,133,143,247,61,19,186,19,213,152,134,219,86,170,230,232,2,251,18,231,52,142,45,120,191,54,41,129,221,181,128,63,108,7,167,25,119,161,164,144,94,95,250,159,209,241,88,93,228,162,35,69,226,89,187,225,185,249,168,157,236,64,58,66,226,161,227,4,131,226,2,234,24,19,203,107,245,88,99,74,253,87,78,136,117,165,82,224,129,146,1,183,84,104,43,189,96,206,32,253,17,75,205,79,128,36,138,101,231,155,75,215,4,229,3,96,59,83,59,36,22,236,107,191,134,180,34,104,157,121,121,12,190,89,96,126,208,30,165,32,224,127,116,37,173,84,234,219,173,17,105,151,96,21,199,77,131,101,61,104,129,53,208,53,4,108,87,143,119,117,181,81,162,140,106,37,237,236,67,104,88,26,240,95,149,227,15,22,16,72,83,138,240,78,139,220,224,157,247,186,173,88,90,58,253,214,111,243,28,15,133,48,23,171,251,241,222,196,226,27,224,41,149,33,13,1,249,40,202,246,70,32,225,130,45,210,118,143,240,63,83,182,90,86,224,158,103,216,9,101,194,181,145,206,155,212,206,238,80,191,87,48,217,140,65,214,146,222,240,117,216,142,107,252,247,221,77,144,41,8,80,147,197,246,252,79,160,247,102,214,133,38,235,29,63,198,229,162,90,178,133,58,253,134,175,74,93,232,86,237,240,50,148,17,210,190,9,242,31,6,226,181,101,242,86,145,4,227,120,181,203,107,91,34,144,117,0,48,125,6,246,144,233,198,65,55,116,222,115,27,185,89,75,110,25,66,82,57,213,34,186,156,58,210,253,202,183,149,105,97,192,84,224,186,116,232,116,236,193,185,202,104,227,194,238,85,160,139,209,28,4,197,199,238,34,61,218,131,223,182,248,122,183,137,128,132,228,223,235,3,145,252,63,132,53,2,64,225,20,197,218,155,120,111,80,245,197,165,115,72,158,174,112,206,59,254,34,190,218,135,44,171,171,211,197,39,232,245,218,59,8,250,64,8,167,98,172,220,176,148,99,102,7,196,218,135,55,64,217,110,41,252,227,219,164,151,104,24,42,6,136,199,56,111,122,211,13,46,192,135,57,124,153,47,148,117,48,242,69,229,218,50,176,156,87,165,49,50,221,35,128,15,154,190,99,246,32,46,187,65,106,139,89,160,77,152,10,84,42,95,30,111,107,47,98,231,159,106,150,146,209,184,163,208,43,183,212,131,237,157,177,114,55,193,227,210,177,233,20,77,13,91,172,13,125,135,242,209,60,29,165,206,69,226,177,141,128,186,171,129,179,17,0,214,63,77,186,108,185,125,6,225,0,249,237,68,43,248,39,18,160,97,29,201,242,187,135,2,156,254,124,192,121,52,254,114,14,237,106,102,122,64,57,42,118,173,189,11,65,255,191,27,47,98,28,27,80,138,91,245,3,39,204,243,159,237,72,3,250,88,138,96,60,156,12,239,44,232,249,158,72,90,44,37,114,128,54,35,108,227,153,73,123,176,242,204,246,98,253,108,141,64,120,10,100,64,214,48,126,62,128,225,83,58,201,227,3,97,182,157,7,144,32,144,254,160,250,103,82,242,113,49,240,249,244,213,95,216,33,206,124,31,250,226,151,122,1,243,170,127,139,67,75,217,136,249,194,202,130,6,249,238,96,152,207,40,37,47,8,28,45,68,58,11,187,24,132,56,17,122,219,81,200,185,4,43,229,131,252,250,35,144,123,165,240,66,193,29,54,90,94,86,107,172,6,84,34,58,53,239,247,123,179,57,51,147,144,200,59,198,136,144,203,45,231,132,2,178,88,18,58,197,254,198,74,184,237,169,123,185,160,105,70,186,153,165,239,90,2,51,223,100,54,117,186,200,191,217,112,87,43,106,86,113,124,8,148,162,121,162,78,194,160,19,160,65,11,199,246,197,245,196,46,186,233,104,213,37,211,114,116,249,139,116,202,140,26,253,24,215,21,18,65,42,40,98,146,15,4,217,59,248,106,18,6,201,107,118,249,66,85,109,140,86,109,82,106,185,21,69,66,209,218,103,98,34,158,61,84,9,114,67,118,12,192,145,153,253,161,8,88,57,77,124,151,33,107,248,165,144,23,99,120,189,71,64,204,136,56,169,195,132,12,191,175,92,11,38,214,104,82,203,238,246,104,187,172,241,61,223,76,149,148,22,195,192,255,128,176,35,194,56,217,14,25,33,89,50,250,74,156,4,139,190,94,125,250,150,27,142,103,60,206,142,152,108,105,72,223,221,140,218,26,36,112,156,163,182,124,53,218,93,39,159,239,149,123,248,130,230,177,251,128,93,127,219,33,78,109,23,210,119,134,58,190,103,131,201,107,7,211,83,40,125,229,74,136,188,153,124,67,31,81,126,8,165,117,191,186,191,246,224,18,173,164,101,239,63,218,159,173,68,79,63,246,255,8,234,190,253,152,16,254,188,245,192,129,69,175,159,119,249,50,123,22,227,176,32,77,235,58,240,168,164,100,189,27,122,49,104,176,192,139,164,204,195,157,58,167,192,221,255,179,230,212,132,15,119,222,99,72,90,70,18,227,26,242,131,70,50,54,197,25,41,45,46,136,34,194,135,185,51,93,117,149,181,229,194,225,212,145,203,237,120,199,180,187,230,69,159,84,114,34,116,181,194,185,12,66,57,178,60,40,196,196,233,0,159,235,15,190,139,35,41,229,116,211,116,213,32,203,199,66,32,121,78,165,92,120,51,248,19,0,236,98,242,179,0,24,202,194,61,145,39,82,174,215,99,172,181,4,164,135,26,200,123,97,254,154,232,218,239,5,49,35,141,241,169,88,156,8,223,111,175,189,113,221,144,149,178,29,165,200,1,249,212,97,108,208,133,73,255,191,188,39,8,131,181,26,131,155,58,171,31,222,117,31,106,216,68,232,67,236,73,114,70,72,226,1,216,123,248,94,61,193,249,224,125,162,241,9,27,50,19,165,152,240,10,89,73,186,113,71,76,167,209,80,105,219,107,105,32,227,186,38,238,158,110,35,82,242,63,248,100,210,89,28,38,220,212,8,180,251,67,35,156,149,58,104,168,154,238,128,96,156,50,113,237,126,11,102,149,26,20,115,226,130,216,16,251,82,175,234,21,200,75,28,247,235,133,180,207,165,89,34,225,36,81,143,163,22,28,192,249,223,139,208,232,15,164,94,46,196,16,250,125,164,198,202,130,9,104,109,54,68,114,26,222,76,230,37,34,77,242,7,82,180,131,12,133,18,193,167,167,232,110,138,33,55,18,233,213,255,57,63,39,191,29,3,40,185,36,52,3,131,224,103,80,160,191,2,140,88,173,168,153,61,235,39,119,130,124,231,199,133,153,172,180,5,171,115,18,145,220,10,132,240,83,147,132,41,146,0,98,42,208,45,252,1,100,162,126,224,179,231,51,15,95,192,152,247,7,134,118,40,100,8,117,42,247,92,103,229,95,44,132,136,1,57,125,151,160,250,109,245,173,48,185,65,84,119,55,127,117,175,237,139,55,73,17,131,32,83,117,51,140,244,24,124,251,77,42,237,74,158,121,224,101,239,117,190,187,223,30,120,210,209,137,196,213,37,80,2,141,254,134,54,75,230,157,1,81,176,122,250,182,36,241,7,111,154,228,179,129,245,47,90,78,101,87,254,143,46,134,90,30,24,178,19,105,30,95,123,209,207,53,70,39,39,234,192,72,16,139,52,48,219,21,4,12,23,55,59,84,91,94,97,150,180,183,194,207,237,7,25,71,99,121,134,146,156,161,163,176,182,193,212,241,2,7,8,19,37,43,45,70,79,87,118,151,179,194,200,229,230,249,253,254,27,32,78,96,117,125,150,156,162,192,247,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15,30,50,61,}; static const char EXPECTED_PAYLOAD[] = "wolfCOSE ML-DSA benchmark payload"; @@ -41,7 +41,7 @@ int main(void) wc_MlDsaKey dlKey; WOLFCOSE_KEY key; WOLFCOSE_HDR hdr; - unsigned char scratch[4096]; + uint8_t scratch[4096]; const uint8_t* payload = NULL; size_t payloadLen = 0; int ret; diff --git a/src/wolfcose_alg.c b/src/wolfcose_alg.c index 3be2f0d..abc94fc 100644 --- a/src/wolfcose_alg.c +++ b/src/wolfcose_alg.c @@ -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; @@ -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: @@ -612,7 +612,7 @@ int wolfCose_RsaPssCheckKey(const WOLFCOSE_KEY* key, defined(WOLFCOSE_SIGN_SIGN) || defined(WOLFCOSE_SIGN_VERIFY) || \ defined(WOLFCOSE_COUNTERSIGN_SIGN) || \ defined(WOLFCOSE_COUNTERSIGN_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; diff --git a/src/wolfcose_countersign.c b/src/wolfcose_countersign.c index 43b1644..b453bc9 100644 --- a/src/wolfcose_countersign.c +++ b/src/wolfcose_countersign.c @@ -824,7 +824,7 @@ static int wolfCose_CounterSignTbs(WOLFCOSE_KEY* key, int32_t alg, (alg == WOLFCOSE_ALG_PS512))) { enum wc_HashType hashType = WC_HASH_TYPE_NONE; int digestSz = 0; - int mgf = 0; + WOLFCOSE_MGF_ID mgf = 0; ret = wolfCose_RsaPssCheckKey(key, NULL); if (ret == WOLFCOSE_SUCCESS) { @@ -1051,7 +1051,7 @@ static int wolfCose_CounterVerifyTbs(const WOLFCOSE_KEY* key, int32_t alg, RsaKey* rsaKey = NULL; enum wc_HashType hashType = WC_HASH_TYPE_NONE; int digestSz = 0; - int mgf = 0; + WOLFCOSE_MGF_ID mgf = 0; ret = wolfCose_RsaPssCheckKey(key, NULL); if (ret == WOLFCOSE_SUCCESS) { diff --git a/src/wolfcose_hdr.c b/src/wolfcose_hdr.c index 002bbb3..94281a7 100644 --- a/src/wolfcose_hdr.c +++ b/src/wolfcose_hdr.c @@ -61,19 +61,20 @@ int wolfCose_InInt32Range(int64_t val) static uint32_t wolfCose_LabelBit(int64_t label) { uint32_t bit; - uint32_t shift; - int64_t shift64; + uint32_t shift = 32u; if ((label >= 1) && (label <= 16)) { - shift64 = label; - shift64--; - shift = (uint32_t)shift64; - bit = ((uint32_t)1u) << shift; + shift = (uint32_t)label; + shift--; } else if ((label <= -1) && (label >= -16)) { - shift64 = -label; - shift = (uint32_t)shift64; + shift = (uint32_t)(-label); shift += 15u; + } + else { + /* No tracked bit. */ + } + if (shift < 32u) { bit = ((uint32_t)1u) << shift; } else { diff --git a/src/wolfcose_internal.h b/src/wolfcose_internal.h index d667d6f..b06a9d7 100644 --- a/src/wolfcose_internal.h +++ b/src/wolfcose_internal.h @@ -302,7 +302,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 @@ -430,7 +431,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 */ @@ -625,7 +628,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) || \ diff --git a/src/wolfcose_mac.c b/src/wolfcose_mac.c index e476036..b99ed89 100644 --- a/src/wolfcose_mac.c +++ b/src/wolfcose_mac.c @@ -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 @@ -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) { @@ -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; @@ -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) { diff --git a/src/wolfcose_mac0.c b/src/wolfcose_mac0.c index 780f19d..fbe789d 100644 --- a/src/wolfcose_mac0.c +++ b/src/wolfcose_mac0.c @@ -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; @@ -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; @@ -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)) { @@ -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; @@ -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; diff --git a/src/wolfcose_sign.c b/src/wolfcose_sign.c index 1b7496f..6c12ac0 100644 --- a/src/wolfcose_sign.c +++ b/src/wolfcose_sign.c @@ -365,7 +365,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 @@ -414,7 +415,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; } } @@ -558,13 +559,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; } @@ -654,7 +656,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); @@ -790,9 +792,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); } @@ -1195,7 +1197,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; diff --git a/src/wolfcose_sign1.c b/src/wolfcose_sign1.c index 09caa9d..3e078c9 100644 --- a/src/wolfcose_sign1.c +++ b/src/wolfcose_sign1.c @@ -249,58 +249,58 @@ int wolfCose_SignSigLen(const WOLFCOSE_KEY* key, int32_t alg, * so these live outside the WOLFCOSE_SIGN1 region below. */ #if defined(WOLFCOSE_EXT_SIGN) /* Reject algorithms this build lacks; report whether alg pre-hashes. */ -int wolfCose_ExtSignAlg(int32_t alg, int* preHashes) +int wolfCose_ExtSignAlg(int32_t alg, WOLFCOSE_PREHASH_FLAG* preHashes) { int ret = WOLFCOSE_SUCCESS; switch (alg) { #if defined(WOLFCOSE_HAVE_ES256) case WOLFCOSE_ALG_ES256: - *preHashes = 1; + *preHashes = (WOLFCOSE_PREHASH_FLAG)1u; break; #endif #if defined(WOLFCOSE_HAVE_ES384) case WOLFCOSE_ALG_ES384: - *preHashes = 1; + *preHashes = (WOLFCOSE_PREHASH_FLAG)1u; break; #endif #if defined(WOLFCOSE_HAVE_ES512) case WOLFCOSE_ALG_ES512: - *preHashes = 1; + *preHashes = (WOLFCOSE_PREHASH_FLAG)1u; break; #endif #if defined(WOLFCOSE_HAVE_PS256) case WOLFCOSE_ALG_PS256: - *preHashes = 1; + *preHashes = (WOLFCOSE_PREHASH_FLAG)1u; break; #endif #if defined(WOLFCOSE_HAVE_PS384) case WOLFCOSE_ALG_PS384: - *preHashes = 1; + *preHashes = (WOLFCOSE_PREHASH_FLAG)1u; break; #endif #if defined(WOLFCOSE_HAVE_PS512) case WOLFCOSE_ALG_PS512: - *preHashes = 1; + *preHashes = (WOLFCOSE_PREHASH_FLAG)1u; break; #endif #if defined(WOLFCOSE_HAVE_EDDSA) || defined(WOLFCOSE_HAVE_ED448) case WOLFCOSE_ALG_EDDSA: - *preHashes = 0; + *preHashes = (WOLFCOSE_PREHASH_FLAG)0u; break; #endif #if defined(WOLFCOSE_HAVE_MLDSA) case WOLFCOSE_ALG_ML_DSA_44: case WOLFCOSE_ALG_ML_DSA_65: case WOLFCOSE_ALG_ML_DSA_87: - *preHashes = 0; + *preHashes = (WOLFCOSE_PREHASH_FLAG)0u; break; #endif #if defined(WOLFCOSE_HAVE_LMS) /* Delegated signing only needs the length and dispatch, not the local * wc_LmsKey_Sign, so this stays available in verify-only builds. */ case WOLFCOSE_ALG_HSS_LMS: - *preHashes = 0; + *preHashes = (WOLFCOSE_PREHASH_FLAG)0u; break; #endif default: @@ -320,7 +320,7 @@ int wolfCose_ExtSign(const WOLFCOSE_KEY* key, int32_t alg, const uint8_t* tbs = sigStruct; size_t tbsLen = sigStructLen; size_t expSigLen = 0; - int preHashes = 0; + WOLFCOSE_PREHASH_FLAG preHashes = (WOLFCOSE_PREHASH_FLAG)0u; if ((key == NULL) || (key->signCb == NULL) || (sigStruct == NULL) || (sig == NULL) || (sigLen == NULL) || (sigSz == 0u)) { @@ -332,7 +332,7 @@ int wolfCose_ExtSign(const WOLFCOSE_KEY* key, int32_t alg, ret = wolfCose_ExtSignAlg(alg, &preHashes); } - if ((ret == WOLFCOSE_SUCCESS) && (preHashes != 0)) { + if ((ret == WOLFCOSE_SUCCESS) && (preHashes != 0u)) { int digestSz = 0; ret = wolfCose_AlgToHashType(alg, &hashType); @@ -661,7 +661,8 @@ int wc_CoseSign1_Sign_ex(WOLFCOSE_KEY* key, int32_t alg, if ((ret == WOLFCOSE_SUCCESS) && (key->signCb != NULL)) { size_t extSigLen = 0; size_t sigOff = 0; - int extPreHash = 0; + WOLFCOSE_PREHASH_FLAG extPreHash = + (WOLFCOSE_PREHASH_FLAG)0u; /* A pre-hashing algorithm has its digest copied out before the * callback runs, so the signature may reuse the whole scratch. @@ -669,7 +670,7 @@ int wc_CoseSign1_Sign_ex(WOLFCOSE_KEY* key, int32_t alg, * signature has to start past it. */ ret = wolfCose_ExtSignAlg(alg, &extPreHash); if (ret == WOLFCOSE_SUCCESS) { - sigOff = (extPreHash != 0) ? 0u : sigStructLen; + sigOff = (extPreHash != 0u) ? 0u : sigStructLen; if (scratchSz <= sigOff) { ret = WOLFCOSE_E_BUFFER_TOO_SMALL; } @@ -816,7 +817,7 @@ int wc_CoseSign1_Sign_ex(WOLFCOSE_KEY* key, int32_t alg, (alg == WOLFCOSE_ALG_PS384) || (alg == WOLFCOSE_ALG_PS512))) { enum wc_HashType hashType; int digestSz = 0; - int mgf = 0; + WOLFCOSE_MGF_ID mgf = 0; ret = wolfCose_RsaPssCheckKey(key, NULL); @@ -1003,7 +1004,8 @@ int wc_CoseSign1_Sign_ex(WOLFCOSE_KEY* key, int32_t alg, } 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); } @@ -1337,7 +1339,7 @@ int wc_CoseSign1_Verify(const WOLFCOSE_KEY* key, RsaKey* rsaKey = NULL; enum wc_HashType hashType = WC_HASH_TYPE_NONE; int digestSz = 0; - int mgf = 0; + WOLFCOSE_MGF_ID mgf = 0; ret = wolfCose_RsaPssCheckKey(key, NULL); if (ret == WOLFCOSE_SUCCESS) { diff --git a/tests/test_cose.c b/tests/test_cose.c index 275c47a..b666a24 100644 --- a/tests/test_cose.c +++ b/tests/test_cose.c @@ -18871,7 +18871,7 @@ static void test_cose_encrypt0_large_payload(void) static void test_cose_hmac_type_constants(void) { int ret; - int hmacType = 0; + enum wc_HashType hmacType = WC_HASH_TYPE_NONE; TEST_LOG(" [HmacType constants]\n"); @@ -20856,6 +20856,9 @@ static void test_internal_helpers(void) { int ret; enum wc_HashType hashType; +#if defined(WOLFCOSE_HAVE_HMAC256) + enum wc_HashType hmacType = WC_HASH_TYPE_NONE; +#endif size_t sz; int wcType; @@ -20933,7 +20936,7 @@ static void test_internal_helpers(void) TEST_ASSERT(ret == WOLFCOSE_E_INVALID_ARG, "HmacType NULL"); /* Invalid algorithm (default case) */ - ret = wolfCose_HmacType(9999, &wcType); + ret = wolfCose_HmacType(9999, &hmacType); TEST_ASSERT(ret == WOLFCOSE_E_COSE_BAD_ALG, "HmacType bad alg"); #endif