Skip to content

Commit 0af6735

Browse files
committed
README update, add set_aces
1 parent 565332d commit 0af6735

File tree

5 files changed

+115
-46
lines changed

5 files changed

+115
-46
lines changed

README.md

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# c-aces
1+
# C-ACES
22

33
## Overview
4-
c-aces is a C implementation of [ACES](https://arxiv.org/pdf/2401.13255.pdf) (Arithmetic Channel Encryption Scheme), a novel cryptosystem constructed using category theory, specifically leveraging the Yoneda Lemma. ACES eliminates the need for bootstrapping techniques, offering a more efficient and secure Fully Homomorphic Encryption (FHE) scheme.
4+
**C-ACES** is a C implementation of [ACES](https://arxiv.org/pdf/2401.13255.pdf) (Arithmetic Channel Encryption Scheme), a novel cryptosystem constructed using **category theory**, specifically leveraging the **Yoneda Lemma**. ACES eliminates the need for bootstrapping techniques, offering a more efficient and secure **Fully Homomorphic Encryption (FHE) scheme**.
55

66
This repository provides a practical and efficient implementation of ACES in C, enabling experimentation and integration into various systems requiring secure computations.
77
It serves as an educational and experimental endeavor for exploring the implementation of ACES.
@@ -10,10 +10,51 @@ Please note that a Python implementation of ACES is already available, For addit
1010

1111

1212
## Getting Started
13-
### Prerequisites
14-
C compiler compatible with C11 standard.
13+
### Prerequisites
14+
- CMake (version 3.16 or higher)
15+
- A C compiler that supports C11 (e.g., GCC or Clang)
16+
1517
### Building
16-
### Usage
18+
1. Clone the Cring repository to your local machine:
19+
```bash
20+
git clone https://github.com/your-username/Cring.git
21+
```
22+
2. build
23+
```bash
24+
cmake -B Release -DCRING_EXAMPLE=ON -DCRING_TEST=ON .
25+
cmake --build Release
26+
```
27+
### Examples
28+
Here's a simple example of using C-ACES to do FHE operations:
29+
```c
30+
// initialize aces with proper parameters
31+
Aces aces;
32+
set_aces(&aces, DIM, memory, MEMORY_SIZE);
33+
init_aces(2/*p*/, 33/*q*/, DIM, &aces);
34+
35+
// encrypt message 1
36+
uint64_t message_1 = 4;
37+
CipherMessage encrypted_message_1;
38+
aces_encrypt(&aces, &message_1, 1, &encrypted_message_1);
39+
40+
// encrypt message 2
41+
uint64_t message_2 = 3;
42+
CipherMessage encrypted_message_2;
43+
aces_encrypt(&aces, &message_1, 1, &encrypted_message_1);
44+
45+
uint64_t message_result;
46+
CipherMessage encrypted_result;
47+
48+
// add encrypted_message_1 and encrypted_message_2
49+
aces_add(&encrypted_message_1, &encrypted_message_2, &aces.shared_info, &encrypted_result);
50+
51+
// decrypt result
52+
aces_decrypt(&aces, &encrypted_result, 1, &message_result);
53+
54+
uint64_t expected_result = (message_1 + message_2) % 2/*p*/;
55+
assert(expected_result == message_result);
56+
```
57+
For more usage examples, explore the [examples](examples) folder.
1758
1859
## References
1960

examples/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
find_package(Threads REQUIRED)
22

33
set(EXAMPLE1_SOURCES
4-
examples/aces_encrypt_decrypt.c
4+
aces_encrypt_decrypt.c
55
)
66

77
add_executable(run_example1 ${EXAMPLE1_SOURCES})

examples/aces_encrypt_decrypt.c

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,14 @@
55
#include <time.h>
66

77
#define DIM 10
8+
#define MEMORY_SIZE 2 << 14
89

910
int main() {
10-
srand(time(NULL));
11-
Aces aces;
12-
13-
/** shared_info **/
14-
// initialize U
15-
Coeff u_mem[DIM + 1];
16-
set_polynomial(&aces.shared_info.pk.u, u_mem, DIM + 1);
17-
18-
// initialize lambda
19-
uint64_t lambda_mem[DIM][DIM * DIM];
20-
Matrix2D lambda_mat[DIM];
21-
for (int i = 0; i < DIM; ++i) {
22-
lambda_mat[i].dim = DIM;
23-
lambda_mat[i].data = lambda_mem[i];
24-
}
25-
aces.shared_info.pk.lambda.size = DIM;
26-
aces.shared_info.pk.lambda.data = lambda_mat;
27-
28-
/** private_key **/
29-
// initialize x
30-
Coeff x_mem[DIM][DIM];
31-
Polynomial x_polies[DIM];
32-
for (int i = 0; i < DIM; ++i) {
33-
set_polynomial(&x_polies[i], x_mem[i], DIM);
34-
}
35-
aces.private_key.x.size = DIM;
36-
aces.private_key.x.polies = x_polies;
37-
38-
// initialize f0
39-
Coeff f0_mem[DIM][DIM];
40-
Polynomial f0_polies[DIM];
41-
for (int i = 0; i < DIM; ++i) {
42-
set_polynomial(&f0_polies[i], f0_mem[i], DIM);
43-
}
44-
aces.private_key.f0.size = DIM;
45-
aces.private_key.f0.polies = f0_polies;
46-
47-
// initialize f1
48-
Coeff f1_mem[DIM];
49-
set_polynomial(&aces.private_key.f1, f1_mem, DIM);
11+
srand(6);
12+
uint8_t memory[MEMORY_SIZE];
5013

14+
Aces aces;
15+
set_aces(&aces, DIM, memory, MEMORY_SIZE);
5116
init_aces(2, 33, DIM, &aces);
5217

5318
uint64_t message = 1;

lib/Aces.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ typedef struct {
105105
uint64_t level;
106106
} CipherMessage;
107107

108+
int set_aces(Aces *aces, size_t dim, void *mem, size_t size);
109+
108110
/**
109111
* @brief Initializes an instance of the ACES (Arithmetic Channel Encryption
110112
* Scheme).

src/Aces.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,67 @@
44

55
#include <string.h>
66

7+
int set_aces(Aces *aces, size_t dim, void *memory, size_t size) {
8+
size_t required = sizeof(Coeff) * (2 * dim + 1 + 2 * dim * dim) +
9+
sizeof(Matrix2D) * dim + sizeof(Polynomial) * 2 * dim +
10+
sizeof(uint64_t) * dim * dim * dim;
11+
12+
if (size < required)
13+
return -1;
14+
15+
uint8_t *mem = (uint8_t *)memory;
16+
// initialize U
17+
Coeff *u_mem = (Coeff *)mem;
18+
mem += ((dim + 1) * sizeof(Coeff));
19+
set_polynomial(&aces->shared_info.pk.u, u_mem, dim + 1);
20+
21+
// initialize lambda
22+
Matrix2D *lambda_mat = (Matrix2D *)mem;
23+
mem += dim * sizeof(Matrix2D);
24+
25+
uint64_t *lambda_mem = (uint64_t *)mem;
26+
mem += dim * dim * dim * sizeof(uint64_t);
27+
28+
for (size_t i = 0; i < dim; ++i) {
29+
lambda_mat[i].dim = dim;
30+
lambda_mat[i].data = lambda_mem + (i * dim * dim);
31+
}
32+
aces->shared_info.pk.lambda.size = dim;
33+
aces->shared_info.pk.lambda.data = lambda_mat;
34+
35+
// initialize x
36+
Polynomial *x_polies = (Polynomial *)mem;
37+
mem += dim * sizeof(Polynomial);
38+
39+
Coeff *x_mem = (Coeff *)mem;
40+
mem += dim * dim * sizeof(Coeff);
41+
42+
for (size_t i = 0; i < dim; ++i) {
43+
set_polynomial(&x_polies[i], x_mem + i * dim, dim);
44+
}
45+
aces->private_key.x.size = dim;
46+
aces->private_key.x.polies = x_polies;
47+
48+
// initialize f0
49+
Polynomial *f0_polies = (Polynomial *)mem;
50+
mem += dim * sizeof(Polynomial);
51+
52+
Coeff *f0_mem = (Coeff *)mem;
53+
mem += dim * dim * sizeof(Coeff);
54+
for (size_t i = 0; i < dim; ++i) {
55+
set_polynomial(&f0_polies[i], f0_mem + i * dim, dim);
56+
}
57+
aces->private_key.f0.size = dim;
58+
aces->private_key.f0.polies = f0_polies;
59+
60+
// initialize f1
61+
Coeff *f1_mem = (Coeff *)mem;
62+
mem += dim * sizeof(Coeff);
63+
set_polynomial(&aces->private_key.f1, f1_mem, dim);
64+
65+
return 0;
66+
}
67+
768
int init_aces(uint64_t p, uint64_t q, uint64_t dim, Aces *aces) {
869
aces->shared_info.param.dim = dim;
970
aces->shared_info.param.N = 1;

0 commit comments

Comments
 (0)