Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Extracting the crypto library from EGuard #95

Open
dzobbe opened this issue Aug 27, 2020 · 0 comments
Open

Extracting the crypto library from EGuard #95

dzobbe opened this issue Aug 27, 2020 · 0 comments

Comments

@dzobbe
Copy link

dzobbe commented Aug 27, 2020

Hi Folks,

I want to extract the Beneloh cryptolibrary from your Election Guard. Basically, my final goal is to generate keys, encrypt a uint, do proofs, and decrypt the values. While for the encryption I think I have extracted the proper code, I am not able to do the same for the decryption. Can you please help me? The code I wrote 'till now is the following. Can you also check that I am on the right track. Thank you guys.

`

Crypto_parameters_new();
raw_hash initialized_hash = {0, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                             0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

struct KeyCeremony_Trustee_generate_key_r result;

// Generate the keypair
struct Crypto_gen_keypair_r crypto_result =
    Crypto_gen_keypair(THRESHOLD, initialized_hash);
result.status = KEYCEREMONY_TRUSTEE_SUCCESS;

// check that we generated good proofs (right now this call crashes if the proofs fail)
if (!Crypto_check_keypair_proof(crypto_result.public_key, base_hash_code))
{
    xprintf("\nKeyCeremony_Trustee_generate_key: Crypto_check_keypair_proof - FAILED!\n");
}
switch (crypto_result.status)
{
case CRYPTO_INSUFFICIENT_MEMORY:
    result.status = KEYCEREMONY_TRUSTEE_INSUFFICIENT_MEMORY;
    break;
case CRYPTO_IO_ERROR:
    result.status = KEYCEREMONY_TRUSTEE_IO_ERROR;
    break;
case CRYPTO_SUCCESS:
    break;
default:
    //@ assert false;
    xprintf("default");
};

Crypto_rsa_public_key_new(&rsa_pk);
Crypto_rsa_private_key_new(&rsa_vk);

// Generate the RSA keys
generate_keys(&rsa_vk, &rsa_pk);

if (result.status == KEYCEREMONY_TRUSTEE_SUCCESS)
{
    xprintf("Generated public key\n");
    xprintf("Generated private key\n");
}

mpz_t nonce, aggregate_nonce;
mpz_init(nonce);
mpz_init(aggregate_nonce);
struct encryption_rep encrypted_res;
Crypto_encryption_rep_new(&encrypted_res);

struct RandomSource_new_r rs = RandomSource_new();
RandomSource source = rs.source;

mpz_t num2enc;
mpz_init(num2enc);
mpz_set_ui(num2enc, 1234);

struct joint_public_key_rep joint_key;
Crypto_joint_public_key_init(&joint_key);
Crypto_generate_joint_public_key(&joint_key, &crypto_result.public_key, 1);

Crypto_encrypt(
    &encrypted_res,
    nonce,
    source,
    &joint_key,
    num2enc);

`

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant