Giter Club home page Giter Club logo

libhcs's People

Contributors

tiehuis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

libhcs's Issues

Incorrect result of threshold decryption

I tried to use the threshold decryption of djcs_t, but I found that the decryption result is incorrect, specifically always be 0. The code is as follows:

mpz_set_ui(plaintext, 100);
djcs_t_encrypt(pk, hr, ciphertext, plaintext);
for (int j = 0; j < required_au_servers; j++) {
     djcs_t_share_decrypt(vk, au[j], partial_shares[j], ciphertext);
}
djcs_t_share_combine(vk, rop, partial_shares);

In fact, the djcs_t_share_decrypt function works well, and each share is a reasonable big integer. However, the djcs_t_share_combine seems to be problematic (i.e., the returned rop is always 0). I print some intermediate results in the djcs_t_share_combine function, the line that rop becomes 0 is from dlog_s(vk, rop, rop). Inside of this function, the line mpz_mod(t1, a, vk->n[j-1]) always returns t1 as 0.

The OS is ubuntu 18.04 with openssl 1.1.1. I am not sure whether I used the code correctly. Any help would be highly appreciated. Thanks in advance.

Testing ElGamal's Multiplicative Homomorphic Property Fails.

Hey,
Would you help me out to see why this test fails? test_egcs.cpp. I believe it is related to multiplication part.
I have put the sample code I patched from your code to test, but it does not give the correct result.

`
#include "./elgamal-test.h"
#include
#include
#include

#include <libhcs++/egcs.hpp>
#include

using namespace std;

static hcs::random *hr;
static hcs::egcs::public_key *pk;
static hcs::egcs::private_key *vk;

int main(){

hr = new hcs::random();
pk = new hcs::egcs::public_key(*hr);
vk = new hcs::egcs::private_key(*hr);
hcs::egcs::generate_key_pair(*pk, *vk, 1024);

hcs::egcs::cipher u, v, z;
mpz_class a, b, c;
a = (10);
b = (20);
c = (200); // Should be the multiply of a and b

u = pk->encrypt(a);
v = pk->encrypt(b);
z = pk->ee_mul(u,v);

cout << "a is: " << a << '\n';
cout << "decrypted a is: " << vk->decrypt(u) << "\n\n";
cout << "b is: " << b << '\n';
cout << "decrypted b is: " << vk->decrypt(v) << "\n\n";
cout << "c is: " << c << '\n';
cout << "decrypted c is: " << vk->decrypt(z) << "\n\n";


delete hr;
delete pk;
delete vk;

return 0;

}

`

Wrong decryption when using exported keys

Hi,

I am facing problems when exporting and importing keys in the cryptosystem. I mean, my cryptographic algorithm works fine when I generate every time new keys, but when I try to reuse the exported keys, it produces a wrong decryption. What I am doing wrong? Here is a snippet of code I implemented to make some tests.

Thank you

	pcs_public_key * pk2 = pcs_init_public_key();
	pcs_private_key * vk2 = pcs_init_private_key();
	hcs_random * hr2 = hcs_init_random();

	pcs_generate_key_pair(pk2, vk2, hr2, 2048);

	char * pkstr=pcs_export_public_key(pk2);
	char * vkstr=pcs_export_private_key(vk2);

	printf("ecco: %s\n",pkstr);

	// initialize data structures
	pcs_public_key * pk = pcs_init_public_key();
	pcs_private_key * vk = pcs_init_private_key();
	hcs_random * hr = hcs_init_random();
	
	pcs_import_public_key(pk, pkstr);
	pcs_import_private_key(vk, vkstr);

	printf("ecco: %s\n",pcs_export_public_key(pk));

	cout<<"test decr -----> "<<DecryptString(EncryptString("test"))<<endl<<endl;

	cout<<"Valid? "<<pcs_verify_key_pair(pk,vk)<<endl;

threshold test

int main(void) {
  djcs_t_public_key *pk = djcs_t_init_public_key();
  djcs_t_private_key *vk = djcs_t_init_private_key();
  hcs_random *hr = hcs_init_random();

  // key length = 2048, sharing length 128, threshold 3, decrypt participant 3
  djcs_t_generate_key_pair(pk, vk, hr, 2048, 128, 3, 3); 
}

The code never finishes its compilation.

I thought that I understand how it works (the algorithm), that is why I wrote these function for keygen.
Please help me to point out the mistake.

Thanks in advance.

djcs_t_share_decrypt needs private_key

Hi,
we'd like to use this library to implement a secure multi party computation protocol for a paper. Looking at the source code, I stumbled over the djcs_t_share_decrypt method which needs the private key.

/**
* For a given ciphertext @p cipher1, compute the server @p au's share and store
* the result in the variable @p rop. These shares can be managed, and then
* combined when sufficient shares have been accumulated using the
* djcs_t_share_combine function.
*
* @param vk A pointer to an initialised djcs_t_private_key
* @param au A pointer to an initialised djcs_t_auth_server
* @param rop mpz_t where the calculated share is stored
* @param cipher1 mpz_t which stores the ciphertext to decrypt
*/
void djcs_t_share_decrypt(djcs_t_private_key *vk, djcs_t_auth_server *au,
mpz_t rop, mpz_t cipher1);

This is in contrast to the equivalent method for the standard Paillier implementation here:

/**
* For a given ciphertext @p cipher1, compute the server @p au's share and store
* the result in the variable @p rop. These shares can be managed, and then
* combined when sufficient shares have been accumulated using the
* pcs_t_share_combine function.
*
* @param vk A pointer to an initialised pcs_t_private_key
* @param au A pointer to an initialised pcs_t_auth_server
* @param rop mpz_t where the calculated share is stored
* @param cipher1 mpz_t which stores the ciphertext to decrypt
*/
void pcs_t_share_decrypt(pcs_t_public_key *vk, pcs_t_auth_server *au,
mpz_t rop, mpz_t cipher1);

which says private key in the doc string, but actually takes a public key.

I've looked at the local_ecample.c and there paillier is used with the share_decrypt method and the public key as a parameter. Intuitively this seems to be the correct way to me, since share_decrypt is intended to be used to 'partially' decrypt a ciphertext with the secret key share which the auth server holds, right?

Is my understanding of the intended functionality wrong and there is a reason why djcs_t_share_decrypt needs a private key, while for the Paillier equivalent the public key suffices?

Thanks for the library :)

Bugs when negative number

If the sum of two number is a negative number, the decrypted result is incorrect.

for example:
If a= -99, b = 9
then decrypt( encrypt(a) + encrypt(b)) !=-90

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.