diff options
author | Christian Fuchs <christian.fuchs@cfuchs.net> | 2014-02-04 10:15:29 +0000 |
---|---|---|
committer | Christian Fuchs <christian.fuchs@cfuchs.net> | 2014-02-04 10:15:29 +0000 |
commit | 9728378c983196c86c2fc6b7902964955e41e379 (patch) | |
tree | 1ecd82f008f053fc7bccf7dc0b331dc6a5db2a0e /src/util | |
parent | 3a831d404fdb12a6b8aa4c34f04d9c96ac032a03 (diff) | |
download | gnunet-9728378c983196c86c2fc6b7902964955e41e379.tar.gz gnunet-9728378c983196c86c2fc6b7902964955e41e379.zip |
- extended paillier-api to also include caller-suggested maximum supported homs
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/crypto_paillier.c | 6 | ||||
-rw-r--r-- | src/util/test_crypto_paillier.c | 8 |
2 files changed, 8 insertions, 6 deletions
diff --git a/src/util/crypto_paillier.c b/src/util/crypto_paillier.c index d47823905..6873d159f 100644 --- a/src/util/crypto_paillier.c +++ b/src/util/crypto_paillier.c | |||
@@ -92,12 +92,16 @@ GNUNET_CRYPTO_paillier_create (struct GNUNET_CRYPTO_PaillierPublicKey *public_ke | |||
92 | * | 92 | * |
93 | * @param public_key Public key to use. | 93 | * @param public_key Public key to use. |
94 | * @param m Plaintext to encrypt. | 94 | * @param m Plaintext to encrypt. |
95 | * @param desired_ops How many homomorphic ops the caller intends to use | ||
95 | * @param[out] ciphertext Encrytion of @a plaintext with @a public_key. | 96 | * @param[out] ciphertext Encrytion of @a plaintext with @a public_key. |
96 | * @return guaranteed number of supported homomorphic operations, can be zero | 97 | * @return guaranteed number of supported homomorphic operations >= 1, |
98 | * or desired_ops, in case that is lower, | ||
99 | * or -1 if less than one homomorphic operation is possible | ||
97 | */ | 100 | */ |
98 | int | 101 | int |
99 | GNUNET_CRYPTO_paillier_encrypt (const struct GNUNET_CRYPTO_PaillierPublicKey *public_key, | 102 | GNUNET_CRYPTO_paillier_encrypt (const struct GNUNET_CRYPTO_PaillierPublicKey *public_key, |
100 | const gcry_mpi_t m, | 103 | const gcry_mpi_t m, |
104 | int desired_ops, | ||
101 | struct GNUNET_CRYPTO_PaillierCiphertext *ciphertext) | 105 | struct GNUNET_CRYPTO_PaillierCiphertext *ciphertext) |
102 | { | 106 | { |
103 | int possible_opts; | 107 | int possible_opts; |
diff --git a/src/util/test_crypto_paillier.c b/src/util/test_crypto_paillier.c index b77100642..0dad500ba 100644 --- a/src/util/test_crypto_paillier.c +++ b/src/util/test_crypto_paillier.c | |||
@@ -45,7 +45,7 @@ test_crypto () | |||
45 | 45 | ||
46 | gcry_mpi_randomize (plaintext, GNUNET_CRYPTO_PAILLIER_BITS / 2, GCRY_WEAK_RANDOM); | 46 | gcry_mpi_randomize (plaintext, GNUNET_CRYPTO_PAILLIER_BITS / 2, GCRY_WEAK_RANDOM); |
47 | 47 | ||
48 | GNUNET_CRYPTO_paillier_encrypt (&public_key, plaintext, &ciphertext); | 48 | GNUNET_CRYPTO_paillier_encrypt (&public_key, plaintext, 0, &ciphertext); |
49 | 49 | ||
50 | GNUNET_CRYPTO_paillier_decrypt (&private_key, &public_key, | 50 | GNUNET_CRYPTO_paillier_decrypt (&private_key, &public_key, |
51 | &ciphertext, plaintext_result); | 51 | &ciphertext, plaintext_result); |
@@ -88,16 +88,14 @@ test_hom() | |||
88 | gcry_mpi_mul_2exp(m2,m2,GNUNET_CRYPTO_PAILLIER_BITS-3); | 88 | gcry_mpi_mul_2exp(m2,m2,GNUNET_CRYPTO_PAILLIER_BITS-3); |
89 | gcry_mpi_add(result,m1,m2); | 89 | gcry_mpi_add(result,m1,m2); |
90 | 90 | ||
91 | if (1 != (ret = GNUNET_CRYPTO_paillier_encrypt (&public_key, m1, &c1))){ | 91 | if (1 != (ret = GNUNET_CRYPTO_paillier_encrypt (&public_key, m1, 0, &c1))){ |
92 | printf ("GNUNET_CRYPTO_paillier_encrypt 1 failed, should return 1 allowed operation, got %d!\n", ret); | 92 | printf ("GNUNET_CRYPTO_paillier_encrypt 1 failed, should return 1 allowed operation, got %d!\n", ret); |
93 | return 1; | 93 | return 1; |
94 | } | 94 | } |
95 | if (1 != (ret = GNUNET_CRYPTO_paillier_encrypt (&public_key, m2, &c2))){ | 95 | if (1 != (ret = GNUNET_CRYPTO_paillier_encrypt (&public_key, m2, 0, &c2))){ |
96 | printf ("GNUNET_CRYPTO_paillier_encrypt 2 failed, should return 1 allowed operation, got %d!\n", ret); | 96 | printf ("GNUNET_CRYPTO_paillier_encrypt 2 failed, should return 1 allowed operation, got %d!\n", ret); |
97 | return 1; | 97 | return 1; |
98 | } | 98 | } |
99 | |||
100 | GNUNET_CRYPTO_paillier_encrypt (&public_key, m2, &c2); | ||
101 | 99 | ||
102 | if (0 != (ret = GNUNET_CRYPTO_paillier_hom_add (&public_key, &c1,&c2, &c_result))){ | 100 | if (0 != (ret = GNUNET_CRYPTO_paillier_hom_add (&public_key, &c1,&c2, &c_result))){ |
103 | printf ("GNUNET_CRYPTO_paillier_hom_add failed, expected 0 remaining operations, got %d!\n", ret); | 101 | printf ("GNUNET_CRYPTO_paillier_hom_add failed, expected 0 remaining operations, got %d!\n", ret); |