-
Notifications
You must be signed in to change notification settings - Fork 55
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
Natural to-from Ring (AsNaturalNumber
& AsRingElement
)
#215
Comments
Digging deeper, it seems that Thereafter, I thought about implementing Therefore I see two options;
I assume the second option will be more desirable by @tarcieri thoughts on this? |
Sounds like you should just use |
But I'll be missing all the modular operations that I need. |
We can potentially add bounds for the modular operations, but that's debatably a breaking change. In the meantime you can just notate them in your bounds. |
It's more than that, as I said before, there are missing traits for modular operations: multiplication (current one isn't complete), exponentiation and inversion. If you'd like that, I'll open two seperate PRs: one to add these bounds, and another implementing |
Yes, go ahead and open separate PRs for each |
Closing this issue as this task has been rethought |
I'd like to write a
decrypt<T>(decryption_key: &T, encryption_key: &T, ciphetext: &T) -> T
function that does Paillier decryption.Paillier decryption first raises the ciphertext
c
to the power of the decryption keyd
modulo the sqaure of the encryption keyn^2
. For this, I would need a trait bound forT
that allows me to exponentiate given a specific modulus.Next, we switch to work over the integers to perform
L
which takes the above result and decrease one from it and divides byn
. So I need a trait bound forT
that satisfies division over the integers.Now, we need to think of that result again as in a finite field but this time
mod n
and notn^2
, and do modular multiplication with the inverse of the decryption keyd^-1
. So again, we need a trait bound that allows modular multiplication (and the modulus shouldn't be fixed).I can and have written such code using crypto-bigint directly, but want to decouple myself and work over traits instead, and have crypto-bigint implement these traits e.g. for U4096.
I think that's possible, maybe the current traits aren't the ones to satisfy it tho.
let me know if this makes sense now, and I'll open an issue for this.
Originally posted by @ycscaly in #70 (comment)
Following several discussions with @tarcieri, both in #70 and in #158, I decided to create this issue, and a corresponding PR #214 for this discussion.
My idea here is to have two types of "numbers" (i.e.$x \in \N$ ) or as a ring element (i.e.$x \in \Z_n$ ) and I defined corresponding traits to switch between them.
num_traits::Num
) that we can think of when we're thinking of aUint
; to think of it as a natural number (i.e.This allows me to greatly simplify my code, and also to decouple it from the particular types (e.g. U2048) and instead work over generic types.
The implementation is uncomplete and I have encountered some problems when approaching it, esp. when trying to implement
Num
forDynamicResidue
, primarily due to what appears to be the lack of rust-lang/rust#95174 being closed - so we can't have type safety forDynamicResidue
meaning the modulus can't be specified in the type, so I can't implement e.g.Zero
(see my TODO comments in the PR.)Just for illustration purposes, what was previously written (Paillier encryption) like this:
can now be written like this:
So there are great benefits here (and for the Paillier decryption case it has an even greater effect).
Please let me know about your thoughts, both of the general idea of implementing these traits and then the specific question I've raised when implementing.
The text was updated successfully, but these errors were encountered: