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

Switch from cryptonite library to crypton and fix cbits #95

Merged
merged 5 commits into from
Oct 15, 2024

Conversation

erikd
Copy link
Contributor

@erikd erikd commented Oct 11, 2024

  • The cryptonite library is deprecated and has been replaced by crypton which is a drop in replacement.

  • cbits: Squash a Wstringop-overread error (This needs very careful review).

@@ -253,9 +253,9 @@ static void serialize_index32(uint8_t *out, uint32_t index, derivation_scheme_mo

static void add_left(ed25519_secret_key res_key, uint8_t *z, ed25519_secret_key priv_key, derivation_scheme_mode mode)
{
uint8_t zl8[32];
ed25519_secret_key zl8;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The unit8_t array had 32 elements (which is what caused the error message) and is replace with ed25519_secret_key which is 64 elements.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before the fix, the error was:

cbits/encrypted_sign.c:304:9: error:
     warning: ‘cardano_crypto_ed25519_publickey’ reading 64 bytes from a region of size 32 [-Wstringop-overread]
      304 |         cardano_crypto_ed25519_publickey(zl8, pub_zl8);
          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    |
304 |         cardano_crypto_ed25519_publickey(zl8, pub_zl8);
    | 


memset(zl8, 0, 32);
memset(zl8, 0, 64);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the size of the z18 array has increased to 64 we set all 64 elements to zero.

@erikd erikd force-pushed the erikd/crypton branch 2 times, most recently from 69286e4 to e85789b Compare October 11, 2024 02:17
Copy link
Contributor

@angerman angerman left a comment

Choose a reason for hiding this comment

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

This looks great to me. But we should sometimes new else have a lot to o as well!

Copy link

@perturbing perturbing left a comment

Choose a reason for hiding this comment

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

LGTM,

I am a bit puzzled why this compiler did not catch this buffer mismatch, as this was always trying to read 64 bytes.

@angerman
Copy link
Contributor

Darwin 8.10.7 is missing llvm 🤦

The cryptonite library is deprecated and has been replaced by crypton
which is a drop in replacement.

For the `cbits` code, replace all instances of `cryptonite` with `crypton`.
Pretty sure this warning is only generated with GCC versions >= 14.2.

A type and a function were defined as follows:

    typedef unsigned char ed25519_secret_key[64];
    void cardano_crypto_ed25519_publickey(const ed25519_secret_key sk, ed25519_public_key pk);

and then the code had:

    uint8_t zl8[32];
    cardano_crypto_ed25519_publickey(zl8, pub_zl8);

The compiler error was squashed by changing the type of `uint8_t [32]` to
`ed25519_secret_key` which is 64 bytes in size and then updating the
`memset` call to zero the whole array.
@erikd erikd force-pushed the erikd/crypton branch 2 times, most recently from 8746e56 to 2607d9f Compare October 15, 2024 04:25
angerman and others added 2 commits October 15, 2024 15:27
- Use haskell-actions/setup instead of haskell/actions/setup
- Bump from v1 to v2
- Don't pin the cabal-version. Haskell-actions already bring in a newer version.
@erikd erikd merged commit 790a302 into develop Oct 15, 2024
8 of 9 checks passed
@erikd erikd deleted the erikd/crypton branch October 15, 2024 04:44
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.

3 participants