Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add settings.h check: DSA needs SHA1 #7551

Merged
merged 1 commit into from
May 21, 2024
Merged

Conversation

gojimmypi
Copy link
Contributor

Description

Adds a settings.h sanity check to ensure if DSA is enabled, that SHA1 is also enabled.

I started going down the road of gating out all the DSA code when not enabled, but the further I got, the more complex it became. I gave up when I found MakeAnyCert() that has a DSA parameter. It is certainly possible to code around this, and I can do so if desired. For now we have the sanity check,

Otherwise, without this change: when DSA is enabled and SHA1 is disabled (e.g. #define NO_SHA) , unintuitive compile time errors may occur such as this:

C:/workspace/wolfssl-gojimmypi-pr/wolfcrypt/src/dsa.c: In function 'wc_DsaSign':
C:/workspace/wolfssl-gojimmypi-pr/wolfcrypt/src/dsa.c:653:34: error: 'WC_SHA_DIGEST_SIZE' undeclared (first use in this function); did you mean 'WC_SHA384_DIGEST_SIZE'?
  653 |     return wc_DsaSign_ex(digest, WC_SHA_DIGEST_SIZE, out, key, rng);
      |                                  ^~~~~~~~~~~~~~~~~~
      |                                  WC_SHA384_DIGEST_SIZE
C:/workspace/wolfssl-gojimmypi-pr/wolfcrypt/src/dsa.c:653:34: note: each undeclared identifier is reported only once for each function it appears in
C:/workspace/wolfssl-gojimmypi-pr/wolfcrypt/src/dsa.c: In function 'wc_DsaVerify':
C:/workspace/wolfssl-gojimmypi-pr/wolfcrypt/src/dsa.c:988:36: error: 'WC_SHA_DIGEST_SIZE' undeclared (first use in this function); did you mean 'WC_SHA384_DIGEST_SIZE'?
  988 |     return wc_DsaVerify_ex(digest, WC_SHA_DIGEST_SIZE, sig, key, answer);
      |                                    ^~~~~~~~~~~~~~~~~~
      |                                    WC_SHA384_DIGEST_SIZE
C:/workspace/wolfssl-gojimmypi-pr/wolfcrypt/src/dsa.c: In function 'wc_DsaSign':
C:/workspace/wolfssl-gojimmypi-pr/wolfcrypt/src/dsa.c:654:1: error: control reaches end of non-void function [-Werror=return-type]
  654 | }
      | ^
C:/workspace/wolfssl-gojimmypi-pr/wolfcrypt/src/dsa.c: In function 'wc_DsaVerify':
C:/workspace/wolfssl-gojimmypi-pr/wolfcrypt/src/dsa.c:989:1: error: control reaches end of non-void function [-Werror=return-type]
  989 | }
      | ^

Fixes zd# n/a

Testing

Limited testing only with embedded target.

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@@ -3586,6 +3586,12 @@ extern void uITRON4_free(void *p) ;
#endif
#endif

#if defined(HAVE_DSA) || !defined(NO_DSA)
Copy link
Contributor

Choose a reason for hiding this comment

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

HAVE_DSA isn't really a thing... we don't use it.

./configure --enable-dsa --disable-sha && make
configure: error: please disable DSA if disabling SHA-1.

Would prefer simple the following:

#if !defined(NO_DSA) && !defined(NO_SHA)
    #error "Please disable DSA if disabling SHA-1"
#endif

Copy link
Contributor Author

Choose a reason for hiding this comment

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

HAVE_DSA isn't really a thing... we don't use it.

Perhaps it would be good to revisit all the DSA the code and gate everything out to reduce code size at some point?

Would prefer the following

I agree in concept, although that exact logic doesn't work. Adding it, and I still see the unintuitive compile error.

I think this is perhaps the intention for that message:

#if defined(HAVE_DSA) && defined(NO_SHA)
    #error "Please disable DSA if disabling SHA-1"
#endif

or perhaps even this, which I included just now & squashed commits:

#if (defined(HAVE_DSA) || !defined(NO_DSA)) && defined(NO_SHA)
    #error "Please disable DSA if disabling SHA-1"
#endif

A missing NO_DSA may not actually mean that HAVE_DSA is enabled, as there's only a check in the reverse order (first checking if HAVE_DSA is defined and then defining NO_DSA.

Further, all of this will work in my case for the Espressif ESP-IDF, but is it intentional that the logic for DSA and others is wrapped in a #ifdef FREERTOS?

image

@@ -3586,6 +3586,11 @@ extern void uITRON4_free(void *p) ;
#endif
#endif


#if (defined(HAVE_DSA) || !defined(NO_DSA)) && defined(NO_SHA)
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, HAVE_DSA isn't really needed. Just gating on !defined(NO_DSA) should be enough. And yes I had a typo in my example !defined(NO_SHA) -> defined(NO_SHA).

Copy link
Contributor

@dgarske dgarske left a comment

Choose a reason for hiding this comment

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

Please resolve merge conflicts

@gojimmypi
Copy link
Contributor Author

Jenkins retest this please

@@ -3591,6 +3591,10 @@ extern void uITRON4_free(void *p) ;
#error "OPENSSL_EXTRA can not be defined with OPENSSL_COEXIST"
#endif

#if (!defined(NO_DSA)) && defined(NO_SHA)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: #if !defined(NO_DSA) && defined(NO_SHA)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Oversight on my part.

@gojimmypi
Copy link
Contributor Author

Jenkins retest this please

@dgarske
Copy link
Contributor

dgarske commented May 21, 2024

Retest this please

@dgarske dgarske merged commit caaa9fe into wolfSSL:master May 21, 2024
105 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants