/*
 * elgamal.h
 *
 * Copyright (C) 2012 Jerônimo C. Pellegrini
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to:
 *   The Free Software Foundation, Inc.,
 *   51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef ELGAMAL_H
#define ELGAMAL_H

#include <gmp.h>

struct elg_pub {
	mpz_t n;
	mpz_t g;
	mpz_t h;
};
typedef struct elg_pub elg_pk;

struct elg_sec {
	mpz_t n;
	mpz_t g;
	mpz_t h;
	mpz_t x;
};
typedef struct elg_sec elg_sk;

void get_random_n_bits (mpz_t r, size_t bits);
void get_random_n (mpz_t r, size_t bits);
void get_random_n_prime (mpz_t r, size_t bits);

void gen_keys (elg_pk *pk, elg_sk *sk);
void save_pk (elg_pk *pk, const char *name);
void read_pk (elg_pk *pk, const char *name);
void save_sk (elg_sk *sk, const char *name);
void read_sk (elg_sk *sk, const char *name);

void elg_dec(mpz_t msg, mpz_t c1, mpz_t c2, elg_sk *sk);
void elg_enc(mpz_t c1, mpz_t c2, mpz_t msg, elg_pk *pk);

void clear_elg_pk(elg_pk pk);
void clear_elg_sk(elg_sk sk);

#endif
