diff options
author | Florian Dold <florian.dold@gmail.com> | 2014-01-20 19:59:22 +0000 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2014-01-20 19:59:22 +0000 |
commit | e502c61183209be8224d584107e7faf7523c1918 (patch) | |
tree | 961d3127e115c8ff5cdc338dfdefe1f94c144b43 /src/include | |
parent | 29517cf1e5cb2e2a92c97f458ba4d3fe6716b1ee (diff) | |
download | gnunet-e502c61183209be8224d584107e7faf7523c1918.tar.gz gnunet-e502c61183209be8224d584107e7faf7523c1918.zip |
- paillier
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/gnunet_crypto_lib.h | 115 |
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 | */ | ||
343 | struct 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 | */ | ||
355 | struct 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 | */ | ||
371 | struct 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 | */ | ||
383 | struct 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 | */ | ||
1330 | void | ||
1331 | GNUNET_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 | */ | ||
1342 | void | ||
1343 | GNUNET_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 | */ | ||
1355 | void | ||
1356 | GNUNET_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 | */ | ||
1373 | int | ||
1374 | GNUNET_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 |