09:28:02 here are some benchmarks comparing the current shared secret calculation with X25519: https://gist.github.com/tevador/50160d160d24cfc6c52ae02eb3d17024#gistcomment-4258297 16:20:24 tevador: awesome thank you :) do these have the precondition that input scalars are < 2^252? 17:05:44 mx25519_invkey will return a failure if the inverted key is >= 2^252 17:06:10 scalar multiplication works with any private key < 2^256 17:09:50 ^ One thing to note is that the private key should not be reduced. You should simply generate random 32 bytes and that becomes the private key. The algorithm clamps the key internally. 18:56:13 tevador: Doesn't that create notable levels of bias? 18:57:15 If this is still the Ed25519 scalar field, clamping removes torsion. It won't create < modulus. If you're reducing to be < bias, that's even more biased than Monero's current scalar generation algorithm (which koe thankfully moved to wide reduction in Seraphis). 18:57:57 Monero's scalar gen is biased ? 18:57:59 *just because you're no longer reducing with 3 wide bits, which you're now clamping out. 18:58:14 l = 2^252 + 27742317777372353535851937790883648493, so the bias is ~2^-126 18:58:15 moneromooo: Yes. It's a 32-byte reduction. 18:58:36 Patch plz ? :D 18:58:46 The IETF hash to curve spec, which does provide a formula for the needed bits to be sufficiently without bias, I believe recommends a 48-byte reduction for 32-byte fields. 18:58:59 check RFC 7748, clamping is the recommended procedure for generating X25519 private keys 18:58:59 And then the community as a whole frequently does 64-byte reduction. 18:59:33 Ooh, I remmeber seeing 64 byte gen for a 32 byte value in some place... 18:59:43 > To control bias, hash_to_field instead uses random integers whose... (full message at https://libera.ems.host/_matrix/media/r0/download/libera.chat/6e46e092952852e54a0193288cdf537120ef8b94) 19:00:08 This is from the IETF document on hash to field, which is what I'm primarily referring to tbc. 19:00:15 yes, 48-byte reduction is to have a ~2^-128 bias with any 256-bit prime number. But the order of the Curve25519 group is so close to 2^252 that you get that for free without reduction. 19:01:29 random32_unbiased only reduces if the random bits is < a multiple of the modulo though, that ought not bias ? 19:02:40 Unbiased generation is needed for things like Schnorr signatures, where even a slight bias will eventually leak the private key. None of this applies to DH. 19:03:15 So I do know Ed25519 is beneficial in this regards, though no, I probably don't know as much as you ;) 19:04:06 tevador: is there a workaround if I want to guarantee the inversion is no-fail 19:04:08 ? 19:04:16 I just wanted to raise it as a concern of mine. While the x25519 spec does line up, the EdDSA spec does use wide reduction. I question why it does so if the bias should be equivalent. 19:04:42 moneromooo: If this is using rejection sampling, it's not biased. If it's > modulus and it reduces, it is biased. 19:04:53 tevador: Thank you for the clarification here. 19:05:18 ... I mean, it'd still leak the DH secret. 19:05:47 *to be clear, there's the discussion it already has insufficient bias and I don't mean to dismiss it. 19:06:28 Though I do want to note that while we're not discussing leaking the private key, we are discussing leaking the ECDH secret. That is sufficient to break amount privacy. 19:06:51 UkoeHB: I don't think we need to care about that. The chance of failure is ~2^-124. It won't happen in practice unless you generate a key specifically to fail. 19:06:58 So while the comment may be it has insufficient bias, I'm not sure we can ignore this because its DH, not a signature. 19:07:43 mx25519_scalar_inv() doesn't look like it has any failure modes 19:08:16 mx25519_scalar_inv is not an API function. 19:08:26 It's internal. 19:09:04 https://github.com/tevador/mx25519/blob/master/src/mx25519.c#L127-L129 19:09:33 "random32_unbiased only reduces..." <- https://words.filippo.io/dispatches/wide-reduction/ notes it as handling an edge case. Not as a valid bias removal 19:09:38 oh I see thanks 19:09:53 It's the final footnote. I just didn't want to post the entire paragraph ;) 19:10:32 UkoeHB: Mind if I get your thoughts/sign off on X25519 bias? I won't run around endlessly about this, and won't claim to be versed enough to have a true opinion. Just wanted to ensure it was discussed and considered. 19:10:59 And tevador definitely seems to have to, and I appreciate their work :D I just want to ensure its verified :p Which is not something I feel confident to myself :( 19:11:05 I'm still looking at this 19:11:14 Sure 👍️ 19:11:35 Ask Dr. Bernstein. I'm 100% sure it's secure since he implemented it this way. 19:11:56 And tevador, truly not trying to state there is an issue or dismiss your explanation. Thanks for providing it :) 19:12:58 It's secure as long as the scanning key is only ever used for DH. 19:13:24 Which it is in the current specs AFAIK. 19:41:03 tevador: I think this comment https://github.com/tevador/mx25519/blob/837ed6dc31190a7c4ebebd0bc373ff32681154c1/src/mx25519.c#L107 should be 8*k0*8*k1... 19:42:13 although it's kind of misleading since there is no mul8 19:47:04 No, it's correct actually. All the keys are implicitly multiples of 8 due to the clamping procedure. invkey calculates basically 8/(8*key[0]*key[1]...) 19:47:30 mul8 is there on line 108 19:47:47 oh you start with 8 ok 19:51:09 fun fact, if you pass num_keys == 0, it will give you an identity key: c87be1164f29370883d6e6e89bed9c3e00000000000000000000000000000030 19:53:41 shouldn't identity be 000000...001? is it represented different from ed25519 points? 19:54:34 1 would be an invalid key since all private keys must be multiples of 8 by convention 19:55:02 so it returns something like 8*(1/8) 19:55:38 hmm ok 19:55:41 if you reduce is mod l, you'll get 1 19:55:45 it* 19:58:36 the bit shift at the end is also a mul8, are you not counting that on semantic grounds? 20:02:28 that's the final mul8 that cancels the 1/8 in the inversion 20:02:53 it's 8*(1/(8*key[0]*key[1]...)) 20:03:57 the result is a private key you can plug into mx25519_scmul and it will work as an inverse 20:04:31 oh duh 20:20:59 ok to make it no-fail I would need to do this: 20:20:59 1. manually compute inversions with monero crypto scalar ops 20:20:59 2. if the inversion is >= 2^252, then do `mx25519_scmul()` three times with `((x << 3) - 2^255) * P + 2^254 * P + 2^254*P` 20:20:59 However there is no point addition available, so that's impossible. Basically it's impossible to make this API no-fail 20:24:27 is a 2^-124 failure rate something we need to care about? 20:25:01 I think it's enough just to reject the seed 20:26:40 It's possible to make it no-fail at the cost of making each scalar multiplication slower. We would need one more ladder iteration to cover 256 key bits. But this would be highly non-standard for Curve 25519. 20:27:37 I agree to require a reroll when your find-received key or address index extension are >= 2^252, the problem for me is removing the no-fail guarantee when dealing with inversions (which the generate-address secret holder can't do anything about when generating addresses). 20:28:02 All I want to change is being able to use invalid inversions somehow 20:29:09 if `mx25519_invkey()` fails, then there is a back-up solution 20:29:49 which I can do if point addition is available 21:09:12 point addition is not possible only with the x-coordinate 21:10:52 But the failure can be worked around quite easily: if invkey(k0, k1) fails, simly call invkey(k0) and then invkey(k1). This will require 2 scalarmults instead of one but the chance of that is so low that it doesn't matter in practice. 22:34:51 no, it is the failure of the final result that concerns me 22:37:46 the probability of failure may be very low, but I have a hard time getting behind removing the no-fail guarantee when it isn't necessary 22:45:57 the problem is this limits the range of input scalars: https://github.com/tevador/mx25519/blob/837ed6dc31190a7c4ebebd0bc373ff32681154c1/src/portable/scalarmult.c#L28, if we could remove this line and let the bit shift be up to the caller (or provide two api points for strict vs non-strict multiplications... that would work 22:46:20 cause then you could do 8*(x * P) if x >= 2^252 23:24:13 https://eprint.iacr.org/2022/1010 23:25:20 I'm waiting to hear tomorrow if it's broken or genius, after the last one took just a few hours lol 23:37:43 It was accepted to crypto 2022 👀 so should be reviewed 23:45:00 I believe Halo 2, which has far smaller proof sizes and I name as reference partially due to how it's a top contender and partially as it'll be the most known reference, would take 100s for the same amount of gates they did at just 3s afaict. The cost is 500x larger proofs :/ Still insane to see