aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2014-01-20 19:59:22 +0000
committerFlorian Dold <florian.dold@gmail.com>2014-01-20 19:59:22 +0000
commite502c61183209be8224d584107e7faf7523c1918 (patch)
tree961d3127e115c8ff5cdc338dfdefe1f94c144b43 /src/include
parent29517cf1e5cb2e2a92c97f458ba4d3fe6716b1ee (diff)
downloadgnunet-e502c61183209be8224d584107e7faf7523c1918.tar.gz
gnunet-e502c61183209be8224d584107e7faf7523c1918.zip
- paillier
Diffstat (limited to 'src/include')
-rw-r--r--src/include/gnunet_crypto_lib.h115
1 files changed, 115 insertions, 0 deletions
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index a5ee98092..65c8b27dc 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -330,6 +330,65 @@ struct GNUNET_CRYPTO_AuthKey
330}; 330};
331 331
332 332
333/**
334 * Size of paillier plain texts and public keys.
335 * Private keys and ciphertexts are twice this size.
336 */
337#define GNUNET_CRYPTO_PAILLIER_BITS 2048
338
339
340/**
341 * Paillier public key.
342 */
343struct GNUNET_CRYPTO_PaillierPublicKey
344{
345 /**
346 * N value.
347 */
348 unsigned char n[GNUNET_CRYPTO_PAILLIER_BITS / 8];
349};
350
351
352/**
353 * Paillier public key.
354 */
355struct GNUNET_CRYPTO_PaillierPrivateKey
356{
357 /**
358 * Lambda-component of the private key.
359 */
360 unsigned char lambda[GNUNET_CRYPTO_PAILLIER_BITS / 8];
361 /**
362 * Mu-component of the private key.
363 */
364 unsigned char mu[GNUNET_CRYPTO_PAILLIER_BITS / 8];
365};
366
367
368/**
369 * Paillier plaintext.
370 */
371struct GNUNET_CRYPTO_PaillierPlaintext
372{
373 /**
374 * The bits of the plaintext.
375 */
376 unsigned char bits[GNUNET_CRYPTO_PAILLIER_BITS / 8];
377};
378
379
380/**
381 * Paillier ciphertext.
382 */
383struct GNUNET_CRYPTO_PaillierCiphertext
384{
385 /**
386 * The bits of the ciphertext.
387 */
388 unsigned char bits[GNUNET_CRYPTO_PAILLIER_BITS * 2 / 8];
389};
390
391
333/* **************** Functions and Macros ************* */ 392/* **************** Functions and Macros ************* */
334 393
335/** 394/**
@@ -1262,6 +1321,62 @@ GNUNET_CRYPTO_mpi_scan_unsigned (gcry_mpi_t *result,
1262 size_t size); 1321 size_t size);
1263 1322
1264 1323
1324/**
1325 * Create a freshly generated paillier public key.
1326 *
1327 * @param[out] public_key Where to store the public key?
1328 * @param[out] private_key Where to store the private key?
1329 */
1330void
1331GNUNET_CRYPTO_paillier_create (struct GNUNET_CRYPTO_PaillierPublicKey *public_key,
1332 struct GNUNET_CRYPTO_PaillierPrivateKey *private_key);
1333
1334
1335/**
1336 * Encrypt a plaintext with a paillier public key.
1337 *
1338 * @param public_key Public key to use.
1339 * @param plaintext Plaintext to encrypt.
1340 * @param[out] ciphertext Encrytion of @a plaintext with @a public_key.
1341 */
1342void
1343GNUNET_CRYPTO_paillier_encrypt (const struct GNUNET_CRYPTO_PaillierPublicKey *public_key,
1344 const struct GNUNET_CRYPTO_PaillierPlaintext *plaintext,
1345 struct GNUNET_CRYPTO_PaillierCiphertext *ciphertext);
1346
1347
1348/**
1349 * Decrypt a paillier ciphertext with a private key.
1350 *
1351 * @param private_key Private key to use for encryption.
1352 * @param ciphertext Ciphertext to decrypt.
1353 * @param[out] plaintext Decryption of @a ciphertext with @private_key.
1354 */
1355void
1356GNUNET_CRYPTO_paillier_decrypt (const struct GNUNET_CRYPTO_PaillierPrivateKey *private_key,
1357 const struct GNUNET_CRYPTO_PaillierCiphertext *ciphertext,
1358 struct GNUNET_CRYPTO_PaillierPlaintext *plaintext);
1359
1360
1361/**
1362 * Compute a ciphertext that represents the sum of the plaintext in @a x1 and @a x2
1363 *
1364 * Note that this operation can only be done a finite number of times
1365 * before an overflow occurs.
1366 *
1367 * @param x1 Paillier cipher text.
1368 * @param x2 Paillier cipher text.
1369 * @param[out] result Result of the homomorphic operation.
1370 * @return GNUNET_OK if the result could be computed,
1371 * GNUNET_SYSERR if no more homomorphic operations are remaining.
1372 */
1373int
1374GNUNET_CRYPTO_paillier_hom_add (const struct GNUNET_CRYPTO_PaillierCiphertext *x1,
1375 const struct GNUNET_CRYPTO_PaillierCiphertext *x2,
1376 const struct GNUNET_CRYPTO_PaillierCiphertext *result);
1377
1378
1379
1265#if 0 /* keep Emacsens' auto-indent happy */ 1380#if 0 /* keep Emacsens' auto-indent happy */
1266{ 1381{
1267#endif 1382#endif