Skip to content

Commit 30e3354

Browse files
committed
init aces
1 parent 825e1c5 commit 30e3354

File tree

8 files changed

+233
-0
lines changed

8 files changed

+233
-0
lines changed

CMakeLists.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
project (CAces C)
4+
5+
set(CMAKE_C_STANDARD 11)
6+
set(CMAKE_C_STANDARD_REQUIRED On)
7+
8+
if(NOT CMAKE_BUILD_TYPE)
9+
set(CMAKE_BUILD_TYPE "Release")
10+
endif()
11+
12+
if(CMAKE_BUILD_TYPE STREQUAL "Release")
13+
add_definitions(-DNDEBUG)
14+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
15+
endif()
16+
17+
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
18+
set(CMAKE_EXPORT_COMPILE_COMMANDS On)
19+
add_compile_options(-Wall -Wextra -pedantic -Werror)
20+
21+
set(SOURCE_FILES
22+
${CMAKE_CURRENT_SOURCE_DIR}/src/Aces.c
23+
)
24+
25+
add_library(CAces STATIC ${SOURCE_FILES})
26+
27+
target_include_directories(CAces PUBLIC
28+
${CMAKE_CURRENT_SOURCE_DIR}/lib
29+
)
30+
31+
option(CACES_BENCHMARK "Enable benchmarking" OFF)
32+
option(CACES_TEST "Enable tests" OFF)
33+
option(CACES_EXAMPLES "Enable examples" OFF)
34+
35+
if (CACES_BENCHMARK)
36+
add_subdirectory(benchmarks)
37+
endif()
38+
39+
if (CACES_TESTS)
40+
add_subdirectory(tests)
41+
endif()
42+
43+
if (CACES_EXAMPLES)
44+
add_subdirectory(examples)
45+
endif()
46+
47+
add_custom_target(
48+
clang-tidy-check clang-tidy -p ${CMAKE_BINARY_DIR}/compile_commands.json -checks=cert* --warnings-as-errors=* -header-filter=.* ${SOURCE_FILES}
49+
DEPENDS ${SOURCE_FILES}
50+
)

lib/Aces.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#ifndef ACES_H
2+
#define ACES_H
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
#include "Channel.h"
9+
#include "Polynomial.h"
10+
11+
#define EPROB 0.5
12+
13+
typename struct {
14+
Polynomial u;
15+
Lambda lambda;
16+
} PublicKey;
17+
18+
typename struct {
19+
PolyArray x;
20+
PolyArray f0;
21+
Polynomial f1;
22+
} PrivateKey;
23+
24+
typename struct {
25+
Channel channel;
26+
Parameters param;
27+
PublicKey pk;
28+
} SharedInfo;
29+
30+
typename struct {
31+
SharedInfo info;
32+
PrivateKey privte_key;
33+
} Aces;
34+
35+
typename struct {
36+
PolyArray c1;
37+
Polynomial c2;
38+
uint64_t level;
39+
} CipherMessage;
40+
41+
int aces_encrypt(const Aces *aces, const uint64_t *message, size_t size,
42+
CipherMessage *result);
43+
44+
int aces_decrypt(const Aces *aces, const CipherMessage *message, size_t size,
45+
uint64_t *message);
46+
47+
#ifdef __cplusplus
48+
}
49+
#endif
50+
51+
#endif

lib/Channel.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef CHANNEL_H
2+
#define CHANNEL_H
3+
4+
#include "Polynomial.h"
5+
6+
typename struct {
7+
uint64_t dim;
8+
uint64_t N;
9+
} Parameters;
10+
11+
typename struct {
12+
uint64_t p;
13+
uint64_t q;
14+
uint64_t w;
15+
} Channel;
16+
17+
typename struct {
18+
uint64_t ***lambda;
19+
size_t size[3];
20+
} Lambda;
21+
22+
int init_channel(Channel *channel, uint64_t p, uint64_t q, uint64_t w);
23+
24+
int generate_u(const Channel *channel, const Parameters *param, Polynomial *u);
25+
26+
int generate_secret(const Channel *channel, const Parameters *param,
27+
const Polynomial *u, PolyArray *secret, Lambda *lambda);
28+
29+
int generate_f0(const Channel *channel, const Parameters *param, PolyArray *f0);
30+
31+
int generate_f1(const Channel *channel, const Parameters *param,
32+
const Polynomial *, Polynomial *f1);
33+
34+
#ifdef __cplusplus
35+
}
36+
#endif
37+
38+
#endif

lib/Common.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef COMMON_H
2+
#define COMMON_H
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
typename struct {
9+
} Xgcd;
10+
11+
Xgcd xgcd(uint64_t a, uint64_t b);
12+
randinverse(uint64_t value);
13+
factors(uint64_t value);
14+
15+
uint64_t coprime_rand(uint64_t value);
16+
uint64_t normal_rand(double mean, double stddev);
17+
uint64_t randint(min, max);
18+
19+
#ifdef __cplusplus
20+
}
21+
#endif
22+
23+
#endif

lib/Operations.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef OPERATIONS_H
2+
#define OPERATIONS_H
3+
4+
int aces_add(const CipherMessage *a, const CipherMessage *b,
5+
const SharedInfo *info, CipherMessage *result);
6+
7+
int aces_mul(const CipherMessage *a, const CipherMessage *b,
8+
const SharedInfo *info, CipherMessage *result);
9+
10+
int aces_refresh(CipherMessage *a, uint64_t k);
11+
12+
#ifdef __cplusplus
13+
}
14+
#endif
15+
16+
#endif

lib/Polynomial.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#ifndef POLYNOMIAL_H
2+
#define POLYNOMIAL_H
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
typename uint64_t Coeff;
9+
10+
typename struct {
11+
Coeff *coeffs;
12+
size_t size;
13+
} Polynomial;
14+
15+
typename struct {
16+
Polynomial *secret;
17+
size_t size;
18+
} PolyArray;
19+
20+
uint64_t coef_sum(const Polynomial *);
21+
22+
uint64_t poly_degree(const Polynomial *);
23+
24+
int poly_fit(uint64_t mod);
25+
26+
int poly_mul(const Polynomial *poly1, const Polynomial *poly2,
27+
Polynomial *result);
28+
29+
int poly_add(const Polynomial *poly1, const Polynomial *poly2,
30+
Polynomial *result);
31+
32+
int poly_lshift(const Polynomial *poly1, const Polynomial *poly2,
33+
Polynomial *result);
34+
35+
int poly_mod(const Polynomial *poly1, const Polynomial *poly2,
36+
Polynomial *result);
37+
38+
#ifdef __cplusplus
39+
}
40+
#endif
41+
42+
#endif

scripts/run-clang-format.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#! /bin/bash
2+
3+
find . -regex '.*\.\(c\|cpp\|cxx\|h\|hpp\|hxx\)$' -exec clang-format -i --style=file '{}' \;

src/Aces.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "Aces.h"
2+
3+
static int generate_error(uint64_t q, uint64_t dim, uint64_t message,
4+
Polynomial *rm) {}
5+
6+
static ssize_t generate_vanisher(uint64_t p, uint64_t q, uint64_t dim,
7+
Polynomial *e) {}
8+
9+
static ssize_t generate_vanisher(uint64_t p, uint64_t q, uint64_t dim,
10+
Polynomial *b) {}

0 commit comments

Comments
 (0)