hardbyte/Paillier.jl

Raw cryptosystem shouldn't be signed

hardbyte opened this issue · 1 comments

In cryptosystem.jl I have a helper function to calculate the maximum plaintext integer:
max_int(n::BigInt) = BigInt(floor(n // 3))

This is used in the multiplication function:

function raw_multiply(public_key::PublicKey, ciphertext::Ciphertext, plaintext::Integer)::Ciphertext
    @debug "Raw encrypted multiply by $plaintext"

    if public_key.n - max_int(public_key) <= plaintext
        neg_ciphertext = invmod(ciphertext, public_key.n_sq)
        neg_scalar = public_key.n - plaintext
        new_ciphertext = powermod(neg_ciphertext, neg_scalar, public_key.n_sq)
    else
        new_ciphertext = powermod(ciphertext, plaintext, public_key.n_sq)
    end
    return new_ciphertext
end

This is from copying python-paillier which doesn't make a clear distinction between raw unsigned integer encryption and working with encoded numbers.

In the case of Paillier.jl I'd like to keep the concepts separate by supporting the full range for all operations for the raw cryptosystem.

Solved by moving max_int into encoding.