Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
ML_Security_ORAM
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mahyar Vahabi
ML_Security_ORAM
Commits
0dd409b8
Commit
0dd409b8
authored
2 months ago
by
Mahyar Vahabi
Browse files
Options
Downloads
Patches
Plain Diff
oram
parent
794dfb85
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
oram.cpp
+67
-0
67 additions, 0 deletions
oram.cpp
with
67 additions
and
0 deletions
oram.cpp
+
67
−
0
View file @
0dd409b8
/***************************
* *************************
* Installations: apt-get install libssl-dev
* Compile like: g++ oram.cpp -o oram -I/usr/include -L/usr/lib -lssl -lcrypto
*/
#include
<iostream>
#include
<vector>
#include
<openssl/rand.h>
#include
<openssl/evp.h>
#define BLOCK_SIZE 16 // Memory block size
#define TREE_HEIGHT 4 // Path ORAM tree depth
using
namespace
std
;
// Encrypt data using AES
void
encrypt_block
(
vector
<
unsigned
char
>&
data
,
const
unsigned
char
*
key
)
{
EVP_CIPHER_CTX
*
ctx
=
EVP_CIPHER_CTX_new
();
unsigned
char
iv
[
BLOCK_SIZE
]
=
{
0
};
// Initialization vector
EVP_EncryptInit_ex
(
ctx
,
EVP_aes_128_cbc
(),
NULL
,
key
,
iv
);
int
len
;
EVP_EncryptUpdate
(
ctx
,
data
.
data
(),
&
len
,
data
.
data
(),
BLOCK_SIZE
);
EVP_EncryptFinal_ex
(
ctx
,
data
.
data
()
+
len
,
&
len
);
EVP_CIPHER_CTX_free
(
ctx
);
}
// ORAM Storage Class
class
PathORAM
{
private:
vector
<
vector
<
unsigned
char
>>
storage
;
// Encrypted memory blocks
unsigned
char
key
[
16
];
// AES encryption key
public:
PathORAM
(
int
num_blocks
)
{
RAND_bytes
(
key
,
sizeof
(
key
));
// Generate encryption key
storage
.
resize
(
num_blocks
,
vector
<
unsigned
char
>
(
BLOCK_SIZE
,
0
));
}
void
write
(
int
index
,
vector
<
unsigned
char
>
data
)
{
encrypt_block
(
data
,
key
);
storage
[
index
]
=
data
;
}
vector
<
unsigned
char
>
read
(
int
index
)
{
return
storage
[
index
];
// Return encrypted data (decryption step needed)
}
};
int
main
()
{
PathORAM
oram
(
16
);
// Initialize ORAM with 16 memory blocks
vector
<
unsigned
char
>
model_data
(
BLOCK_SIZE
,
42
);
// Sample ML model data
oram
.
write
(
0
,
model_data
);
// Store encrypted model parameters
vector
<
unsigned
char
>
retrieved_data
=
oram
.
read
(
0
);
// Retrieve encrypted data
cout
<<
"Encrypted data stored in ORAM: "
;
for
(
unsigned
char
c
:
retrieved_data
)
{
cout
<<
hex
<<
(
int
)
c
<<
" "
;
}
cout
<<
endl
;
return
0
;
}
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