Skip to content

Commit 6fbd5d4

Browse files
committed
add comments, fix aces_add, refresh, restructure
1 parent 3296766 commit 6fbd5d4

23 files changed

+1321
-493
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS On)
1919
#add_compile_options(-Wall -Wextra -pedantic -Werror)
2020

2121
set(SOURCE_FILES
22-
#${CMAKE_CURRENT_SOURCE_DIR}/src/Aces.c
22+
${CMAKE_CURRENT_SOURCE_DIR}/src/Aces.c
23+
${CMAKE_CURRENT_SOURCE_DIR}/src/Aces-internal.c
2324
${CMAKE_CURRENT_SOURCE_DIR}/src/Channel.c
25+
${CMAKE_CURRENT_SOURCE_DIR}/src/Matrix.c
2426
${CMAKE_CURRENT_SOURCE_DIR}/src/Common.c
25-
#${CMAKE_CURRENT_SOURCE_DIR}/src/Operations.c
2627
${CMAKE_CURRENT_SOURCE_DIR}/src/Polynomial.c
2728
)
2829

lib/Aces-internal.h

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#ifndef ACES_INTERNAL_H
2+
#define ACES_INTERNAL_H
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
#include "Channel.h"
9+
#include "Polynomial.h"
10+
#include <stdint.h>
11+
12+
#define EPROB 0.5
13+
14+
/**
15+
* @brief Generate an error element 'rm' over Zq[X]u.
16+
*
17+
* This function generates an error element 'rm' over the ring Zq[X]u,
18+
* such that its evaluation in Zq at the integer ω equals 'message'.
19+
*
20+
* @param q The modulus.
21+
* @param dim The dimension of the element.
22+
* @param message The message to encode in the error.
23+
* @param rm Pointer to the polynomial structure to store the generated error
24+
* element.
25+
*
26+
* @return 0 if successful.
27+
*/
28+
int generate_error(uint64_t q, uint64_t dim, uint64_t message, Polynomial *rm);
29+
30+
/**
31+
* @brief Generate a vanisher vector 'e' over Zq[X]u.
32+
*
33+
* This function generates a vanisher vector 'e' of size N over the ring Zq[X]u,
34+
* such that the evaluation of each coefficient e_i' in Zq at the integer ω is
35+
* equal to a product pℓ, where ℓ ∈ {0,1}.
36+
*
37+
* @param p The product factor.
38+
* @param q The modulus.
39+
* @param dim The dimension of the vector.
40+
* @param e Pointer to the polynomial structure to store the generated vanisher
41+
* vector.
42+
*
43+
* @return 0 if successful.
44+
*/
45+
uint64_t generate_vanisher(uint64_t p, uint64_t q, uint64_t dim, Polynomial *e);
46+
47+
/**
48+
* @brief Generate a linear vector 'b' over Zq[X]u.
49+
*
50+
* This function generates a linear vector 'b' of size N over the ring Zq[X]u,
51+
* where each coefficient b_i(ω) is in the range [0, p].
52+
*
53+
* @param p The upper bound for coefficients.
54+
* @param q The modulus.
55+
* @param dim The dimension of the vector.
56+
* @param b Pointer to the polynomial structure to store the generated linear
57+
* vector.
58+
*
59+
* @return 0 if successful.
60+
*/
61+
uint64_t generate_linear(uint64_t p, uint64_t q, uint64_t dim, Polynomial *b);
62+
63+
/**
64+
* @brief Generate the polynomial 'u' for the arithmetic channel.
65+
*
66+
* This function generates the polynomial 'u' for the arithmetic channel using
67+
* the provided parameters.
68+
*
69+
* @param channel Pointer to the arithmetic channel.
70+
* @param param Pointer to the parameters structure.
71+
* @param u Pointer to the polynomial structure to store the generated
72+
* polynomial 'u'.
73+
*
74+
* @return 0 if successful.
75+
*/
76+
int generate_u(const Channel *channel, const Parameters *param, Polynomial *u);
77+
78+
/**
79+
* @brief Generate the secret key for the arithmetic channel.
80+
*
81+
* This function generates the secret key for the arithmetic channel using the
82+
* provided parameters, channel information, and intermediate values.
83+
*
84+
* @param channel Pointer to the arithmetic channel.
85+
* @param param Pointer to the parameters structure.
86+
* @param u Pointer to the polynomial 'u'.
87+
* @param secret Pointer to the polynomial array 'secret' to store the generated
88+
* secret key.
89+
* @param lambda Pointer to the 3D matrix 'lambda' Represents the set of
90+
* 3-tensors lambda in Zq for the arithmetic channel. This structure represents
91+
* the set of 3-tensors lambda in Zq for the arithmetic channel. Each element
92+
* λ[k][i][j] in the 3D matrix corresponds to the coefficients of the generated
93+
* secret key. The set H(x|C) of 3-tensors λ is defined such that for every pair
94+
* (i, j) of elements in [n], the equation holds in the ring Zq[X]u.
95+
*
96+
* @return 0 if successful.
97+
*/
98+
int generate_secret(const Channel *channel, const Parameters *param,
99+
const Polynomial *u, PolyArray *secret, Matrix3D *lambda);
100+
101+
/**
102+
* @brief Generate the polynomial array 'f0' for the arithmetic channel public
103+
* key.
104+
*
105+
* This function generates the polynomial array 'f0' for the arithmetic channel
106+
* public key using the provided parameters and channel information.
107+
*
108+
* @param channel Pointer to the arithmetic channel.
109+
* @param param Pointer to the parameters structure.
110+
* @param f0 Pointer to the polynomial array structure to store the generated
111+
* polynomials.
112+
*
113+
* @return 0 if successful.
114+
*/
115+
int generate_f0(const Channel *channel, const Parameters *param, PolyArray *f0);
116+
117+
/**
118+
* @brief Generate the polynomial 'f1' for the arithmetic channel public key.
119+
*
120+
* This function generates the polynomial 'f1' for the arithmetic channel public
121+
* key using the provided parameters, channel information, and intermediate
122+
* values.
123+
*
124+
* @param channel Pointer to the arithmetic channel.
125+
* @param param Pointer to the parameters structure.
126+
* @param f0 Pointer to the polynomial array 'f0'.
127+
* @param x Pointer to the polynomial array secret.
128+
* @param u Pointer to the polynomial 'u'.
129+
* @param f1 Pointer to the polynomial structure to store the generated
130+
* polynomial 'f1'.
131+
*
132+
* @return 0 if successful.
133+
*/
134+
int generate_f1(const Channel *channel, const Parameters *param,
135+
const PolyArray *f0, const PolyArray *x, const Polynomial *u,
136+
Polynomial *f1);
137+
138+
#ifdef __cplusplus
139+
}
140+
#endif
141+
142+
#endif

lib/Aces.h

Lines changed: 153 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,185 @@ extern "C" {
88
#include "Channel.h"
99
#include "Polynomial.h"
1010

11-
#define EPROB 0.5
12-
11+
/**
12+
* @brief Represents the public key for the arithmetic channel.
13+
*
14+
* This structure represents the public key for the arithmetic channel,
15+
* consisting of the polynomial 'u' and 3D matrix 'lambda'.
16+
*
17+
* @param u Polynomial representing the parameter 'u'.
18+
* @param lambda 3D matrix representing intermediate values. Each element
19+
* λ[k][i][j] in the matrix corresponds to the coefficients of the generated
20+
* secret key.
21+
*/
1322
typedef struct {
1423
Polynomial u;
15-
Lambda lambda;
24+
Matrix3D lambda;
1625
} PublicKey;
1726

27+
/**
28+
* @brief Represents the private key for the arithmetic channel.
29+
*
30+
* This structure represents the private key for the arithmetic channel,
31+
* consisting of the polynomial array 'x', polynomial array 'f0', and polynomial
32+
* 'f1'.
33+
*
34+
* @param x Polynomial array representing the secret key.
35+
* @param f0 Polynomial array representing the public key component 'f0'.
36+
* @param f1 Polynomial representing the public key component 'f1'.
37+
*/
1838
typedef struct {
1939
PolyArray x;
2040
PolyArray f0;
2141
Polynomial f1;
2242
} PrivateKey;
2343

44+
/**
45+
* @brief Represents the shared information for the arithmetic channel.
46+
*
47+
* This structure represents the shared information for the arithmetic channel,
48+
* including the channel parameters, public key, and other necessary parameters.
49+
*
50+
* @param channel The arithmetic channel.
51+
* @param param Parameters for the arithmetic channel.
52+
* @param pk Public key for the arithmetic channel.
53+
*/
2454
typedef struct {
2555
Channel channel;
2656
Parameters param;
2757
PublicKey pk;
2858
} SharedInfo;
2959

60+
/**
61+
* @brief Represents an instance of the ACES (Arithmetic Channel Encryption
62+
* Scheme).
63+
*
64+
* This structure represents an instance of the Arithmetic Channel Encryption
65+
* Scheme (ACES), including shared information and private key components.
66+
*
67+
* @param shared_info Shared information for the ACES instance.
68+
* @param private_key Private key components for the ACES instance.
69+
*/
3070
typedef struct {
31-
SharedInfo info;
32-
PrivateKey privte_key;
71+
SharedInfo shared_info;
72+
PrivateKey private_key;
3373
} Aces;
3474

75+
/**
76+
* @brief Represents a ciphertext in the ACES framework.
77+
*
78+
* The ACES framework encrypts a message m ∈ ℤₚ as a ciphertext (c,c') according
79+
* to the following procedure:
80+
*
81+
* 1. The first component c is an n-vector over ℤ_q[X]_u given by c = f₀ᵀb,
82+
* where:
83+
* - f₀ is an n × N matrix over ℤ_q[X]_u (chosen during key generation).
84+
* - b = (bᵢ)ᵢ is an N-vector over ℤ_q[X]_u such that bᵢ(ω) ∈ {0,1,…,p}
85+
* (selected by the sender).
86+
*
87+
* 2. The second component c' is an element of ℤ_q[X] defined as
88+
* c' = r_m + cᵀx + e, where:
89+
* - r_m is an element over ℤ_q[X]_u chosen such that its evaluation in ℤ_q
90+
* at the integer ω equals m (chosen by the sender).
91+
* - x is an n-vector over ℤ_q[X]_u (considered the private key).
92+
* - e is a scalar product in the form of bᵀe', where e' = (eᵢ')ᵢ is an
93+
* N-vector over ℤ_q[X]_u such that the evaluation of eᵢ' in ℤ_q at the integer
94+
* ω is equal to a product pℓ where ℓ ∈ {0,1}.
95+
*
96+
* @param c1 First component of the ciphertext, represented as a polynomial
97+
* array.
98+
* @param c2 Second component of the ciphertext, represented as a polynomial.
99+
* @param level The level parameter associated with the ciphertext.
100+
*/
35101
typedef struct {
36102
PolyArray c1;
37103
Polynomial c2;
38104
uint64_t level;
39105
} CipherMessage;
40106

41-
int aces_encrypt(const Aces *, const uint64_t *, size_t, CipherMessage *);
107+
/**
108+
* @brief Initializes an instance of the ACES (Arithmetic Channel Encryption
109+
* Scheme).
110+
*
111+
* @param p Parameter p for the ACES channel.
112+
* @param q Parameter q for the ACES channel.
113+
* @param dim Dimension of the ACES parameters.
114+
* @param[out] aces Pointer to the ACES structure to be initialized.
115+
* @return int Returns 0 upon successful initialization, or an error code
116+
* otherwise.
117+
*/
118+
int init_aces(uint64_t p, uint64_t q, uint64_t dim, Aces *aces);
119+
120+
/**
121+
* @brief Encrypts a message using the ACES (Arithmetic Channel Encryption
122+
* Scheme).
123+
*
124+
* @param aces Pointer to the initialized ACES structure.
125+
* @param message Pointer to the message to be encrypted.
126+
* @param size Size of the message array.
127+
* @param[out] result Pointer to the structure where the ciphertext will be
128+
* stored.
129+
* @return int Returns 0 upon successful encryption, or an error code otherwise.
130+
*/
131+
int aces_encrypt(const Aces *aces, const uint64_t *message, size_t size,
132+
CipherMessage *result);
133+
134+
/**
135+
* @brief Decrypts a ciphertext using the ACES (Arithmetic Channel Encryption
136+
* Scheme).
137+
*
138+
* @param aces Pointer to the initialized ACES structure.
139+
* @param message Pointer to the ciphertext to be decrypted.
140+
* @param size Size of the ciphertext array.
141+
* @param[out] result Pointer to the array where the decrypted message will be
142+
* stored.
143+
* @return int Returns 0 upon successful decryption, or an error code otherwise.
144+
*/
145+
int aces_decrypt(const Aces *aces, const CipherMessage *message, size_t size,
146+
uint64_t *result);
147+
148+
/**
149+
* @brief Performs addition on two ciphertexts encrypted under the ACES scheme.
150+
*
151+
* @param a Pointer to the first ciphertext.
152+
* @param b Pointer to the second ciphertext.
153+
* @param info Pointer to the shared information including parameters and keys.
154+
* @param[out] result Pointer to the structure where the result of addition will
155+
* be stored.
156+
* @return int Returns 0 upon successful addition, or an error code otherwise.
157+
*/
158+
int aces_add(const CipherMessage *, const CipherMessage *, const SharedInfo *,
159+
CipherMessage *);
160+
161+
/**
162+
* @brief Performs multiplication on two ciphertexts encrypted under the ACES
163+
* scheme.
164+
*
165+
* @param a Pointer to the first ciphertext.
166+
* @param b Pointer to the second ciphertext.
167+
* @param info Pointer to the shared information including parameters and keys.
168+
* @param[out] result Pointer to the structure where the result of
169+
* multiplication will be stored.
170+
* @return int Returns 0 upon successful multiplication, or an error code
171+
* otherwise.
172+
*/
173+
int aces_mul(const CipherMessage *, const CipherMessage *, const SharedInfo *,
174+
CipherMessage *);
42175

43-
int aces_decrypt(const Aces *, const CipherMessage *, size_t size, uint64_t *);
176+
/**
177+
* @brief Refreshes a ciphertext to mitigate level increase resulting from
178+
* arithmetic operations.
179+
*
180+
* ACES is a fully homomorphic encryption scheme that initially relies on a
181+
* leveled FHE framework. This function is designed to refresh a ciphertext,
182+
* mitigating the level increase resulting from arithmetic operations.
183+
*
184+
* @param info Pointer to the shared information including parameters and keys.
185+
* @param[in,out] message Pointer to the ciphertext to be refreshed.
186+
* @param level The desired level of the refreshed ciphertext.
187+
* @return int Returns 0 upon successful refresh, or an error code otherwise.
188+
*/
189+
int aces_refresh(const SharedInfo *info, CipherMessage *a, uint64_t k);
44190

45191
#ifdef __cplusplus
46192
}

0 commit comments

Comments
 (0)