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 missing Ristretto functions #1

Open
1 task done
tgalal opened this issue Dec 15, 2022 · 13 comments
Open
1 task done

Add missing Ristretto functions #1

tgalal opened this issue Dec 15, 2022 · 13 comments
Assignees

Comments

@tgalal
Copy link
Member

tgalal commented Dec 15, 2022

Lets keep track of the functions to be added to python-curve25519-dalek in this issue. Typically I (Tarek) will take care of applying the list below.

@tgalal tgalal self-assigned this Dec 15, 2022
@konradh
Copy link
Collaborator

konradh commented Jan 5, 2023

For the proof generation and verification, we need these additional bindings:

  • Multiplication of scalars (Scalar * Scalar)
  • Addition of scalars (Scalar + Scalar)
  • Inversion of scalars (-Scalar)

@tgalal
Copy link
Member Author

tgalal commented Jan 6, 2023

Added mul, add ,neg in tgalal/python-curve25519-dalek@57361ba

Note that Scalar * Point now doesn't work, it would to be written Point * Scalar.

@leonschmidt99
Copy link
Member

leonschmidt99 commented Jan 9, 2023

To generate RistrettoPoint and Scalar objects (for example to be used in the various keys and parameters), there are various methods in the Rust library, however, Signal mainly uses these, which should be provided by the binding as well:

Important, used to generate most values:

  • RistrettoPoint::from_uniform_bytes
  • Scalar::from_bytes_mod_order_wide

less important for now, can work around this not being implemented:

  • Scalar::from_bytes_mod_order

(used twice so not important, and can surely work around this, but can't find the corresponding function in curve25519_dalek, which confuses me, and will be a deviation from "Signal compatibility"):

  • RistrettoPoint::from_uniform_bytes_single_elligator

@leonschmidt99
Copy link
Member

leonschmidt99 commented Jan 10, 2023

Also, support for subtracting RistrettoPoints from each other (or negating them) is required to calculate "division" of group elements.

  • Subtraction of RistrettoPoints

@tgalal
Copy link
Member Author

tgalal commented Jan 11, 2023

Added all requested functions. Like others arithmetic ops, subtraction/negation are via the minus - operator.

but can't find the corresponding function in curve25519_dalek,

It's in the lizard2 branch of Signal's fork of the library, inside lizard_ristretto.rs.

@j-hellenberg
Copy link

j-hellenberg commented Jan 11, 2023

Currently, we can only compare scalars, but we also need to

  • compare ristretto points

@tgalal
Copy link
Member Author

tgalal commented Jan 11, 2023

Added equality comparison for points

@tgalal
Copy link
Member Author

tgalal commented Jan 12, 2023

  • Add constant time equality check for points

@j-hellenberg
Copy link

j-hellenberg commented Jan 19, 2023

It would be nice to be able to convert the Scalar to bytes as well for debugging purposes. Also, we could use the native __bytes__() instead of a to_bytes() method for that

  • Scalar conversion to bytes

@tgalal
Copy link
Member Author

tgalal commented Jan 19, 2023

  • RistrettoPoint::decode_253_bits

@tgalal
Copy link
Member Author

tgalal commented Jan 23, 2023

@maxthure
Copy link
Contributor

maxthure commented Jan 24, 2023

Regarding the inversion of Scalars:
I tried to write this line from the Signal Implementation let target_M3 = self.b1.invert() * ciphertext.E_B1; (Reference) like this in Python target_M3 = ciphertext.E_1 * -self.b1 (Reference). This does not yield the correct target_M3. For more detail see this commit.

Edit: The next commit includes a check that I used to verify that ciphertext.E_1 is actually calc_E_b1(profile_key), which suggests that the inversion -self.b1 is not correct, if I am not mistaken.

@tgalal
Copy link
Member Author

tgalal commented Jan 24, 2023

It looks like you really need to use invert rather than negation. I've just added it: https://github.com/tgalal/python-curve25519-dalek/releases/tag/

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

No branches or pull requests

5 participants