Skip to content

fix(weaver): zero-pad ECDH shared secret in eciesEncryptMessage#4409

Open
mskrzypkows wants to merge 11 commits into
hyperledger-cacti:mainfrom
mskrzypkows:weaver_bug
Open

fix(weaver): zero-pad ECDH shared secret in eciesEncryptMessage#4409
mskrzypkows wants to merge 11 commits into
hyperledger-cacti:mainfrom
mskrzypkows:weaver_bug

Conversation

@mskrzypkows

Copy link
Copy Markdown

The ECDH shared secret Z was passed to the KDF without zero-padding in eciesEncryptMessage, while eciesDecryptMessage always padded it to the full field size. When a random ephemeral key
produced a shared secret with leading zero bytes, the two sides derived different AES keys, causing decryption to silently produce garbage.

Fix by applying the same zero-padding in the encrypt path, and replace the hardcoded 32 in the decrypt path with Math.ceil(level / 8) to correctly handle both P-256 and P-384 curves.

Regression test added with a pre-found ephemeral key that deterministically
produces a 31-byte shared secret with the test certificate's public key.

Assisted-by: anthropic:claude-sonnet-4.6

The ECDH shared secret Z was passed to the KDF without zero-padding in
eciesEncryptMessage, while eciesDecryptMessage always padded it to the
full field size. When a random ephemeral key
produced a shared secret with leading zero bytes, the two sides derived
different AES keys, causing decryption to silently produce garbage.

Fix by applying the same zero-padding in the encrypt path, and replace
the hardcoded 32 in the decrypt path with Math.ceil(level / 8) to
correctly handle both P-256 and P-384 curves.

Regression test added with a pre-found ephemeral key that
deterministically
produces a 31-byte shared secret with the test certificate's public key.

Assisted-by: anthropic:claude-sonnet-4.6
Signed-off-by: Maciej Skrzypkowski <mskr@gmx.com>
@sandeepnRES

Copy link
Copy Markdown
Contributor

@mskrzypkows Please update your PR and check if this is already implemented now?

@mskrzypkows

Copy link
Copy Markdown
Author

Yes, it's implemented, we can close it or if we need additional test then it can be merged.

mskrzypkows and others added 8 commits June 26, 2026 18:49
Signed-off-by: Maciej Skrzypkowski <mskr@gmx.com>
- Remove release/v3.0.0-staging branch, as its merged.
- Reduce number of PRs to 1, as often dependabot duplicates PRs with
    almost same updates.

Signed-off-by: Sandeep Nishad <sandeepn.official@gmail.com>
Signed-off-by: Maciej Skrzypkowski <mskr@gmx.com>
Assisted-by: Google:Gemini
Signed-off-by: Sandeep Nishad <sandeepn.official@gmail.com>
Signed-off-by: Maciej Skrzypkowski <mskr@gmx.com>
Assisted-by: anthropic:claude-opus-4.7

Signed-off-by: Sandeep Nishad <sandeepn.official@gmail.com>
Signed-off-by: Maciej Skrzypkowski <mskr@gmx.com>
Pushing Cargo.lock causes dirty publish.
Hence deleted and added in gitignore to not allow
push it in future

Signed-off-by: Sandeep Nishad <sandeepn.official@gmail.com>
Signed-off-by: Maciej Skrzypkowski <mskr@gmx.com>
Signed-off-by: Sandeep Nishad <sandeepn.official@gmail.com>
Signed-off-by: Maciej Skrzypkowski <mskr@gmx.com>
Fix broken external documentation links (replaced labs.hyperledger.org
with hyperledger-cacti.github.io). Remove references to deprecated
and non-existent weaver/docs directories in weaver/README.md and
update incorrect documentation paths in various sample READMEs.

Fixes hyperledger-cacti#4037

Co-authored-by: Dev10-sys <kalpanagola9897@gmail.com>
Assisted-by: google:gemini-1.5-pro
Signed-off-by: ParthSinghPS <posiedon.1721@gmail.com>
Signed-off-by: Maciej Skrzypkowski <mskr@gmx.com>
Signed-off-by: Mustafa Sayyed <mustafasayyed2429@gmail.com>
Signed-off-by: Maciej Skrzypkowski <mskr@gmx.com>
…er_bug

Signed-off-by: Maciej Skrzypkowski <mskr@gmx.com>
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.

4 participants