ABY Framework  1.0
Arithmetic Bool Yao Framework
 All Classes Files Functions Variables Enumerations Enumerator Macros
dgk.h
Go to the documentation of this file.
1 
16 /*
17  libdgk - v0.9
18  A library implementing the DGK crypto system with full decryption
19 
20  Thanks to Marina Blanton for sharing her Miracl DGK implementation from
21  M. Blanton and P. Gasti, "Secure and efficient protocols for iris and fingerprint identification" (ESORICS’11)
22  with us. We used it as a template for this GMP version.
23 
24  The implementation structure was inspired by
25  libpailler - A library implementing the Paillier crypto system. (http://hms.isi.jhu.edu/acsc/libpaillier/)
26 
27  Copyright (C) 2015 EC SPRIDE
28  daniel.demmler@ec-spride.de
29 
30  This program is free software; you can redistribute it and/or modify
31  it under the terms of the GNU General Public License as published by
32  the Free Software Foundation; either version 2 of the License, or
33  (at your option) any later version.
34 
35  This program is distributed in the hope that it will be useful, but
36  WITHOUT ANY WARRANTY; without even the implied warranty of
37  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
38  General Public License for more details.
39  */
40 
41 #ifndef _DGK_H_
42 #define _DGK_H_
43 #include <gmp.h>
44 #include <stdlib.h>
45 #include <stdio.h>
46 #include <string.h>
47 #include <time.h>
48 #include "powmod.h"
49 
50 /*
51  This represents a DGK public key.
52  */
53 typedef struct {
54  unsigned int bits; /* key bits e.g., 1024 */
55  unsigned int lbits; /* share (message) length e.g., 32 */
56  mpz_t n; /* public modulus n = pq */
57  mpz_t u; /* u = 2^lbits (uses 2^(2lbits+2) internally) */
58  mpz_t g; /* generator g */
59  mpz_t h; /* generator h */
60 } dgk_pubkey_t;
61 
62 /*
63  This represents a DGK private key; it needs to be used with a
64  dgk_pubkey_t to be meaningful.
65  */
66 typedef struct {
67  mpz_t vp;
68  mpz_t vq;
69  mpz_t p;
70  mpz_t q;
71  mpz_t p_minusone;
72  mpz_t q_minusone;
73  mpz_t pinv;
74  mpz_t qinv;
75 } dgk_prvkey_t;
76 
77 extern mpz_t* powtwo;
78 extern mpz_t* gvpvqp;
79 
86 void dgk_keygen(unsigned int modulusbits, unsigned int lbits, dgk_pubkey_t** pub, dgk_prvkey_t** prv);
87 
91 //void dgk_encrypt_db(mpz_t res, dgk_pubkey_t* pub, mpz_t pt, gmp_randstate_t rnd);
95 void dgk_encrypt_fb(mpz_t res, dgk_pubkey_t* pub, mpz_t pt, gmp_randstate_t rnd);
96 
100 void dgk_encrypt_plain(mpz_t res, dgk_pubkey_t* pub, mpz_t pt, gmp_randstate_t rnd);
101 
105 void dgk_encrypt_crt(mpz_t res, dgk_pubkey_t* pub, dgk_prvkey_t* prv, mpz_t pt, gmp_randstate_t rnd);
106 
110 // void dgk_encrypt_crt_db(mpz_t res, dgk_pubkey_t* pub, dgk_prvkey_t* prv, mpz_t pt, gmp_randstate_t rnd);
114 void dgk_decrypt(mpz_t res, dgk_pubkey_t* pub, dgk_prvkey_t* prv, mpz_t ct);
115 
119 void dgk_storekey(unsigned int modulusbits, unsigned int lbits, dgk_pubkey_t* pub, dgk_prvkey_t* prv);
120 
124 void dgk_readkey(unsigned int modulusbits, unsigned int lbits, dgk_pubkey_t** pub, dgk_prvkey_t** prv);
125 
126 /*
127  These free the structures allocated and returned by various
128  functions within library and should be used when the structures are
129  no longer needed.
130  */
131 void dgk_freepubkey(dgk_pubkey_t* pub);
132 void dgk_freeprvkey(dgk_prvkey_t* prv);
133 
137 void dgk_complete_pubkey(unsigned int modulusbits, unsigned int lbits, dgk_pubkey_t** pub, mpz_t n, mpz_t g, mpz_t h);
138 
148 // void createKeys(){
152 //void test_encdec()
153 
157 //void test_sharing(){
158 #endif
Definition: dgk.h:53
void dgk_encrypt_plain(mpz_t res, dgk_pubkey_t *pub, mpz_t pt, gmp_randstate_t rnd)
Definition: dgk.cpp:296
void dgk_decrypt(mpz_t res, dgk_pubkey_t *pub, dgk_prvkey_t *prv, mpz_t ct)
Definition: dgk.cpp:394
Powmod Implementation.
void dgk_keygen(unsigned int modulusbits, unsigned int lbits, dgk_pubkey_t **pub, dgk_prvkey_t **prv)
Definition: dgk.cpp:71
void dgk_encrypt_fb(mpz_t res, dgk_pubkey_t *pub, mpz_t pt, gmp_randstate_t rnd)
Definition: dgk.cpp:272
void dgk_storekey(unsigned int modulusbits, unsigned int lbits, dgk_pubkey_t *pub, dgk_prvkey_t *prv)
Definition: dgk.cpp:437
Definition: dgk.h:66
void dgk_encrypt_crt(mpz_t res, dgk_pubkey_t *pub, dgk_prvkey_t *prv, mpz_t pt, gmp_randstate_t rnd)
Definition: dgk.cpp:353
void dgk_readkey(unsigned int modulusbits, unsigned int lbits, dgk_pubkey_t **pub, dgk_prvkey_t **prv)
Definition: dgk.cpp:474
void dgk_complete_pubkey(unsigned int modulusbits, unsigned int lbits, dgk_pubkey_t **pub, mpz_t n, mpz_t g, mpz_t h)
Definition: dgk.cpp:54