Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
ppann
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Boston University PhD
IPFRE
ppann
Commits
44941b4c
Commit
44941b4c
authored
Apr 27, 2023
by
Weiqi
Browse files
Options
Downloads
Patches
Plain Diff
Done with the helpers
parent
16d880a6
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/helper.h
+3
-1
3 additions, 1 deletion
include/helper.h
src/helper.cpp
+17
-3
17 additions, 3 deletions
src/helper.cpp
tests/test_helper.cpp
+35
-13
35 additions, 13 deletions
tests/test_helper.cpp
with
55 additions
and
17 deletions
include/helper.h
+
3
−
1
View file @
44941b4c
...
...
@@ -11,6 +11,8 @@ float *fvecs_read(const char *file_path, size_t *d_out, size_t *n_out);
int
*
ivecs_read
(
const
char
*
file_path
,
size_t
*
d_out
,
size_t
*
n_out
);
Ct
*
encrypt_data
(
int
*
data
,
Key
key
,
int
d
,
int
n
);
int
*
float_to_int
(
const
float
*
data
,
size_t
size
);
Ct
*
encrypt_data
(
const
int
*
data
,
Key
key
,
size_t
d
,
size_t
n
);
#endif //PPANN_HELPER_H
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/helper.cpp
+
17
−
3
View file @
44941b4c
...
...
@@ -39,10 +39,24 @@ int *ivecs_read(const char *file_path, size_t *d_out, size_t *n_out) {
return
(
int
*
)
fvecs_read
(
file_path
,
d_out
,
n_out
);
}
Ct
*
encrypt_data
(
int
*
data
,
Key
key
,
int
d
,
int
n
)
{
int
*
float_to_int
(
const
float
*
data
,
size_t
size
)
{
// Get a new list for integer data.
auto
int_data
=
new
int
[
size
];
// Cast float to integers.
for
(
int
i
=
0
;
i
<
size
;
i
++
)
int_data
[
i
]
=
static_cast
<
int
>
(
data
[
i
]);
// Return pointer of the list.
return
int_data
;
}
Ct
*
encrypt_data
(
const
int
*
data
,
Key
key
,
size_t
d
,
size_t
n
)
{
// Get a new list for encrypted data.
auto
*
encrypted_data
=
new
Ct
[
n
];
for
(
int
i
=
0
;
i
<
n
;
i
++
)
encrypted_data
[
i
]
=
enc
(
key
,
&
data
[
i
*
d
],
d
);
// Encrypt each vector.
for
(
int
i
=
0
;
i
<
n
;
i
++
)
encrypted_data
[
i
]
=
enc
(
key
,
&
data
[
i
*
d
],
static_cast
<
int
>
(
d
));
// Return pointer of the list.
return
encrypted_data
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
tests/test_helper.cpp
+
35
−
13
View file @
44941b4c
#include
"helper.h"
#include
"iostream"
using
namespace
std
;
int
test_read_fvecs
()
{
// Set dimensions holders and get the data.
size_t
d
,
n
;
...
...
@@ -33,20 +30,43 @@ int test_read_ivecs() {
return
1
;
}
int
test_float_to_int
()
{
// Set dimensions holders and get the data.
size_t
d
,
n
;
float
*
xd
=
fvecs_read
(
"sift_query.fvecs"
,
&
d
,
&
n
);
// Conversion and test.
int
*
data
=
float_to_int
(
xd
,
d
*
n
);
// Check for whether the data is correct.
if
(
data
[
1
]
!=
3
)
return
0
;
if
(
data
[
1279872
]
!=
23
)
return
0
;
// If everything passes, return 1.
return
1
;
}
int
test_encrypt
()
{
// Set dimensions holders and get the data.
size_t
d
,
n
;
float
*
xd
=
fvecs_read
(
"sift_query.fvecs"
,
&
d
,
&
n
);
cout
<<
static_cast
<
int
>
(
xd
[
1
])
<<
endl
;
//
int
d_int
,
n_int
;
d_int
=
static_cast
<
int
>
(
d
);
n_int
=
static_cast
<
int
>
(
n
);
// Conversion.
int
*
data
=
float_to_int
(
xd
,
d
*
n
);
// Cast d to integer.
int
d_int
=
static_cast
<
int
>
(
d
);
// Encrypt the first two vectors.
Key
key
=
setup
(
d_int
);
Ct
*
encrypted_data
=
encrypt_data
(
data
,
key
,
d
,
2
);
// Get inner product of the first two vectors.
int
result
=
eval
(
key
,
encrypted_data
[
0
],
encrypted_data
[
1
],
d_int
,
200000
);
// Check for whether the data is correct.
if
(
result
!=
184094
)
return
0
;
//
// Key key = setup(d_int);
// Ct *encrypted_data = encrypt_data(gt, key, d_int, 1);
return
1
;
}
...
...
@@ -55,8 +75,10 @@ int main() {
core_init
();
pc_param_set_any
();
// if (test_read_fvecs() != 1) return 1;
// if (test_read_ivecs() != 1) return 1;
// Perform tests.
if
(
test_read_fvecs
()
!=
1
)
return
1
;
if
(
test_read_ivecs
()
!=
1
)
return
1
;
if
(
test_float_to_int
()
!=
1
)
return
1
;
if
(
test_encrypt
()
!=
1
)
return
1
;
return
0
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment