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

General encryption #75

Merged
merged 22 commits into from
Jan 25, 2024
Merged

General encryption #75

merged 22 commits into from
Jan 25, 2024

Conversation

mpretty-cyro
Copy link
Collaborator

@mpretty-cyro mpretty-cyro commented Dec 12, 2023

This PR exposes all cryptography functions used by the session clients so they can remove direct dependencies on Sodium

Note: This is based on #74

mpretty-cyro and others added 5 commits December 13, 2023 09:49
The 25 blinding encryption design had a flaw in that it used

    H(a(kB) || kA || kB)

as the shared secret, and then assumed that the other side could
compute `kbA || kA || kB`, but with 25 blinding that doesn't
work because *each side* has a different `k` value (since k depends on
both the server_id and the session_id), so this was actually computing:

    H(a(jB) || kA || jB)

when encrypting, and

    H(b(kA) || kA || jB)

when decrypting (where `j` is B's blinding factor).  This amends the
encryption to instead use:

    H(ak(jB) || kA || jB)

for encryption and

    H(bj(kA) || kA || jB)

for decryption, which works because we end up with `kjaB` or `kjbA` for
the first term, which are equal (since `aB == bA`).

This also makes various other small fixes and improvements along the way
to the encryption code to get the 15 and 25 encryption and decryption
tests working (and make the code a bit easier):

- The hex version of blind15_id now returns a pair of the two
  alternative ids, which simplifies calling code from needing to worry
  about flipping the sign bit.
- added blinded[12]5_from_ed functions that are similar to the
  non-`from_ed` versions, but can work more efficiently and precisely
  (most notably, when we know the actual ed pubkey we can always return
  the correctly signed blinded15 id; and when doing 25, having the ed
  pubkey saves us from needing to invert the session id back to an ed
  pubkey).
- Changed the types of blind[12]5_key_pair so that the returned private
  scalar gets properly memory cleared when destroyed, and moved these
  types (eg uc32, cleared_uc64) "higher up" in the include hierarchy.
- Changed `blind[12]5_key_pair` to optionally return (via pointer) the
  blinding factor.  For the 25 version we actually return ±k, depending
  on whether an extra negation is needed to cancel out a negative
  pubkey, so that the returned value can be used directly without having
  to worry about the negation elsewhere.
- removed the "sender decrypt" blinded tests because we don't expose a
  way for the sender to perform such decryption.  (It's technically
  possible to do, but doesn't seem like something we need).
@jagerman jagerman enabled auto-merge January 25, 2024 01:40
@jagerman jagerman merged commit 343cd41 into oxen-io:dev Jan 25, 2024
1 check passed
@mpretty-cyro mpretty-cyro deleted the general-encryption branch January 28, 2024 21:52
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.

2 participants