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
10 changes: 6 additions & 4 deletions src/genkey/clu_genkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,7 @@ int wolfCLU_genKey_ML_DSA(WC_RNG* rng, char* fName, int directive, int fmt,
}

/* The call back function of the writing xmss key */
#ifdef WOLFSSL_HAVE_XMSS
#if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
enum wc_XmssRc wolfCLU_XmssKey_WriteCb(const byte * priv,
word32 privSz, void * context)
{
Expand Down Expand Up @@ -1683,12 +1683,14 @@ enum wc_XmssRc wolfCLU_XmssKey_ReadCb(byte * priv,

return WC_XMSS_RC_READ_TO_MEMORY;
}
#endif /* WOLFSSL_HAVE_XMSS */
#endif /* WOLFSSL_HAVE_XMSS && !WOLFSSL_XMSS_VERIFY_ONLY */

int wolfCLU_genKey_XMSS(WC_RNG* rng, char* fName,
int directive, const char* paramStr)
{
#ifdef WOLFSSL_HAVE_XMSS
/* XMSS key generation needs wc_XmssKey_MakeKey() and the private key
* callbacks, none of which exist in a verify-only wolfSSL build. */
#if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
int ret = 0;
int fNameSz = 0; /* file name without append */
int fExtSz = 6; /* size of ".priv\0" and ".pub\0\0" */
Expand Down Expand Up @@ -1864,7 +1866,7 @@ int wolfCLU_genKey_XMSS(WC_RNG* rng, char* fName,
(void)paramStr;

return NOT_COMPILED_IN;
#endif /* HAVE_XMSS */
#endif /* WOLFSSL_HAVE_XMSS && !WOLFSSL_XMSS_VERIFY_ONLY */
}

#endif /* WOLFSSL_KEY_GEN && !NO_ASN*/
Expand Down
48 changes: 34 additions & 14 deletions src/genkey/clu_genkey_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ static void wolfCLU_genKeyHelp(void)
,"ml-dsa"
,"dilithium"
#endif
#ifdef WOLFSSL_HAVE_XMSS
#if defined(WOLFSSL_HAVE_XMSS) && defined(WOLFSSL_KEY_GEN) && \
!defined(WOLFSSL_XMSS_VERIFY_ONLY)
,"xmss"
,"xmssmt"
#endif
#endif /* WOLFSSL_HAVE_XMSS && WOLFSSL_KEY_GEN &&
* !WOLFSSL_XMSS_VERIFY_ONLY */
};

WOLFCLU_LOG(WOLFCLU_L0, "Available keys with current configure settings:");
Expand All @@ -73,14 +75,16 @@ static void wolfCLU_genKeyHelp(void)
WOLFCLU_LOG(WOLFCLU_L0, "wolfssl -genkey ml-dsa -level "
"[2|3|5] -out mykey -outform pem -output KEYPAIR");
#endif
#ifdef WOLFSSL_HAVE_XMSS
#if defined(WOLFSSL_HAVE_XMSS) && defined(WOLFSSL_KEY_GEN) && \
!defined(WOLFSSL_XMSS_VERIFY_ONLY)
WOLFCLU_LOG(WOLFCLU_L0, "wolfssl -genkey xmss -height [10|16|20] -out mykey -outform raw"
" -output KEYPAIR");
WOLFCLU_LOG(WOLFCLU_L0, "wolfssl -genkey xmssmt -height [20|40|60] -layer [2|4|8|3|6|12]"
" -out mykey -outform raw -output KEYPAIR");
WOLFCLU_LOG(WOLFCLU_L0, "XMSS key file name must be something like \"XMSS-SHA2_10_256\""
"\nXMSS/XMSS^MT parametaers are determined by file name when signing");
#endif
#endif /* WOLFSSL_HAVE_XMSS && WOLFSSL_KEY_GEN &&
* !WOLFSSL_XMSS_VERIFY_ONLY */
WOLFCLU_LOG(WOLFCLU_L0,
"\n\nThe above command would output the files: mykey.priv "
" and mykey.pub\nChanging the -output option to just PRIV would only"
Expand Down Expand Up @@ -474,7 +478,8 @@ int wolfCLU_genKeySetup(int argc, char** argv)
#endif /* HAVE_DILITHIUM */
}
else if (XSTRNCMP(keyType, "xmssmt", 6) == 0) {
#if defined(WOLFSSL_HAVE_XMSS) && defined(WOLFSSL_KEY_GEN)
#if defined(WOLFSSL_HAVE_XMSS) && defined(WOLFSSL_KEY_GEN) && \
!defined(WOLFSSL_XMSS_VERIFY_ONLY)
int directiveArg = wolfCLU_genKeyDirective(output);
char xmssmtParam[XMSSMT_NAME_MAX_LEN + 1]; /* XMSS^MT parameter */
char xmssmtParamHead[] = "XMSSMT-SHA2_\0";
Expand Down Expand Up @@ -609,15 +614,23 @@ int wolfCLU_genKeySetup(int argc, char** argv)

ret = wolfCLU_genKey_XMSS(&rng, keyOutFName, directiveArg, xmssmtParam);
#else
wolfCLU_LogError("Invalid option, XMSS not enabled.");
WOLFCLU_LOG(WOLFCLU_L0, "Please re-configure wolfSSL with"
"--enable-xmss --enable-experimental andtry again");
#ifdef WOLFSSL_XMSS_VERIFY_ONLY
wolfCLU_LogError("XMSS is verify-only in this wolfSSL build, as it "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It might be better to guard this log (and the others) in two ways. One which tests HAVE_FIPS and logs that XMSS key gen is not possible due to FIPS constraints. And the other which says verify only is set so wolfssl would have to be rebuilt appropriately.

Also this can technically be printed even when XMSS is not configured. Add WOLFSSL_HAVE_XMSS

"is in FIPS builds; key generation is not "
"available.");
#else
wolfCLU_LogError("Invalid option, XMSS key generation not enabled.");
WOLFCLU_LOG(WOLFCLU_L0, "Please re-configure wolfSSL with "
"--enable-xmss (and --enable-keygen) and try again.");
#endif
wc_FreeRng(&rng);
return NOT_COMPILED_IN;
#endif /* WOLFSSL_HAVE_XMSS */
#endif /* WOLFSSL_HAVE_XMSS && WOLFSSL_KEY_GEN &&
* !WOLFSSL_XMSS_VERIFY_ONLY */
}
else if (XSTRNCMP(keyType, "xmss", 4) == 0) {
#if defined(WOLFSSL_HAVE_XMSS) && defined(WOLFSSL_KEY_GEN)
#if defined(WOLFSSL_HAVE_XMSS) && defined(WOLFSSL_KEY_GEN) && \
!defined(WOLFSSL_XMSS_VERIFY_ONLY)
int directiveArg = wolfCLU_genKeyDirective(output);
char xmssParam[XMSS_NAME_LEN + 1]; /* XMSS parameter */
char xmssParamHead[] = "XMSS-SHA2_";
Expand Down Expand Up @@ -683,12 +696,19 @@ int wolfCLU_genKeySetup(int argc, char** argv)

ret = wolfCLU_genKey_XMSS(&rng, keyOutFName, directiveArg, xmssParam);
#else
wolfCLU_LogError("Invalid option, XMSS not enabled.");
WOLFCLU_LOG(WOLFCLU_L0, "Please re-configure wolfSSL with"
"--enable-xmss --enable-experimental andtry again");
#ifdef WOLFSSL_XMSS_VERIFY_ONLY
wolfCLU_LogError("XMSS is verify-only in this wolfSSL build, as it "
"is in FIPS builds; key generation is not "
"available.");
#else
wolfCLU_LogError("Invalid option, XMSS key generation not enabled.");
WOLFCLU_LOG(WOLFCLU_L0, "Please re-configure wolfSSL with "
"--enable-xmss (and --enable-keygen) and try again.");
#endif
wc_FreeRng(&rng);
return NOT_COMPILED_IN;
#endif /* WOLFSSL_HAVE_XMSS */
#endif /* WOLFSSL_HAVE_XMSS && WOLFSSL_KEY_GEN &&
* !WOLFSSL_XMSS_VERIFY_ONLY */
}
else {
wolfCLU_LogError("\"%s\" is an invalid key type, or not compiled in", keyType);
Expand Down
10 changes: 6 additions & 4 deletions src/sign-verify/clu_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,9 @@ int wolfCLU_sign_data_dilithium (byte* data, char* out, word32 dataSz, char* pri

int wolfCLU_sign_data_xmss(byte* data, char* out, int fSz, char* privKey)
{
#ifdef WOLFSSL_HAVE_XMSS
/* Signing needs wc_XmssKey_Sign() and the private key callbacks, none of
* which exist in a verify-only wolfSSL build. */
#if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
int ret = 0;
int fExtSz = 5; /* size of ".priv" */
XFILE outFile = NULL; /* output file */
Expand Down Expand Up @@ -1080,12 +1082,12 @@ int wolfCLU_sign_data_xmss(byte* data, char* out, int fSz, char* privKey)
(void)privKey;

return NOT_COMPILED_IN;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LOW-3: Sign in a verify-only build fails with only a bare error code, unlike genkey [NIT] (question)
File: src/sign-verify/clu_sign.c:1078-1085,1272-1279; src/sign-verify/clu_sign_verify_setup.c:194-207
Function: wolfCLU_sign_data_xmss / wolfCLU_sign_data_xmssmt / wolfCLU_signHelp
Confidence: High

In a verify-only build, wolfssl -xmss -sign ... gets through argument parsing and reads the input file. wolfCLU_sign_data still dispatches XMSS_SIG_VER (it's guarded only by WOLFSSL_HAVE_XMSS), and the new stub returns NOT_COMPILED_IN without logging anything. The user sees only Error returned: -174. from clu_main.c. wolfssl -xmss -sign -help prints "No valid key type defined." for an algorithm the build does support for verify. The genkey path in this same diff prints a clear verify-only reason, so a FIPS user gets an explanation for genkey but not for sign. Staying silent does match the sibling sign stubs (rsa, ed25519, dilithium also return NOT_COMPILED_IN without a message), so this is optional.

Code:
#else
(void)data;
(void)out;
(void)fSz;
(void)privKey;

    return NOT_COMPILED_IN;
#endif /* WOLFSSL_HAVE_XMSS && !WOLFSSL_XMSS_VERIFY_ONLY */

Recommendation: Either keep the silent behavior to match the sibling sign stubs, or add the same one-line verify-only error to both XMSS sign stubs so genkey and sign behave the same way.

#endif /* WOLFSSL_HAVE_XMSS */
#endif /* WOLFSSL_HAVE_XMSS && !WOLFSSL_XMSS_VERIFY_ONLY */
}

int wolfCLU_sign_data_xmssmt(byte* data, char* out, int fSz, char* privKey)
{
#ifdef WOLFSSL_HAVE_XMSS
#if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
int ret = 0;
int fExtSz = 5; /* size of ".priv" */
XFILE outFile = NULL; /* output file */
Expand Down Expand Up @@ -1274,7 +1276,7 @@ int wolfCLU_sign_data_xmssmt(byte* data, char* out, int fSz, char* privKey)
(void)privKey;

return NOT_COMPILED_IN;
#endif /* WOLFSSL_HAVE_XMSS */
#endif /* WOLFSSL_HAVE_XMSS && !WOLFSSL_XMSS_VERIFY_ONLY */
}

#endif /* !WOLFCLU_NO_FILESYSTEM */
8 changes: 4 additions & 4 deletions src/sign-verify/clu_sign_verify_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ static void wolfCLU_signHelp(int keyType)
,"ml-dsa"
,"dilithium"
#endif
#ifdef WOLFSSL_HAVE_XMSS
#if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
,"xmss"
,"xmssmt"
#endif
#endif /* WOLFSSL_HAVE_XMSS && !WOLFSSL_XMSS_VERIFY_ONLY */
};

WOLFCLU_LOG(WOLFCLU_L0, "\nAvailable keys with current configure settings:");
Expand Down Expand Up @@ -191,7 +191,7 @@ static void wolfCLU_signHelp(int keyType)
" -in <filename> -out <filename>\n");
break;
#endif
#ifdef WOLFSSL_HAVE_XMSS
#if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
case XMSS_SIG_VER:
WOLFCLU_LOG(WOLFCLU_L0, "XMSS Sign Usage: \nwolfssl -xmss -sign -inkey <priv_key>"
" -in <filename> -out <filename>\n");
Expand All @@ -202,7 +202,7 @@ static void wolfCLU_signHelp(int keyType)
" -in <filename> -out <filename>\n");
WOLFCLU_LOG(WOLFCLU_L0, "***************************************************************");
break;
#endif
#endif /* WOLFSSL_HAVE_XMSS && !WOLFSSL_XMSS_VERIFY_ONLY */
default:
WOLFCLU_LOG(WOLFCLU_L0, "No valid key type defined.\n");
}
Expand Down
6 changes: 4 additions & 2 deletions wolfclu/genkey/clu_genkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,12 @@ int wolfCLU_genKey_ML_DSA(WC_RNG* rng, char* fName, int directive, int fmt,
*
* return WOLFCLU_SUCCESS on success
*/
#ifdef WOLFSSL_HAVE_XMSS
/* A verify-only wolfSSL XMSS build has no private key, so there is nothing
* for these callbacks to read or write. FIPS builds are verify-only. */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

drop the FIPS reference in the comment. This can be derived from the logging change

#if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
enum wc_XmssRc wolfCLU_XmssKey_WriteCb(const byte* priv, word32 privSz, void* context);
enum wc_XmssRc wolfCLU_XmssKey_ReadCb(byte* priv, word32 privSz, void* context);
#endif
#endif /* WOLFSSL_HAVE_XMSS && !WOLFSSL_XMSS_VERIFY_ONLY */

/**
* generate a XMSS key
Expand Down
Loading