-
Notifications
You must be signed in to change notification settings - Fork 716
/
Copy pathsealcontext.cpp
172 lines (139 loc) · 4.89 KB
/
sealcontext.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
// STD
#include <unordered_map>
// SEALNet
#include "seal/c/sealcontext.h"
#include "seal/c/utilities.h"
// SEAL
#include "seal/context.h"
#include "seal/util/locks.h"
using namespace std;
using namespace seal;
using namespace seal::util;
using namespace seal::c;
SEAL_C_FUNC SEALContext_Create(void *encryptionParams, bool expand_mod_chain, int sec_level, void **context)
{
EncryptionParameters *encParams = FromVoid<EncryptionParameters>(encryptionParams);
IfNullRet(encParams, E_POINTER);
IfNullRet(context, E_POINTER);
sec_level_type security_level = static_cast<sec_level_type>(sec_level);
*context = new SEALContext(*encParams, expand_mod_chain, security_level);
return S_OK;
}
SEAL_C_FUNC SEALContext_Destroy(void *thisptr)
{
SEALContext *context = FromVoid<SEALContext>(thisptr);
IfNullRet(context, E_POINTER);
delete context;
return S_OK;
}
SEAL_C_FUNC SEALContext_KeyParmsId(void *thisptr, uint64_t *parms_id)
{
SEALContext *context = FromVoid<SEALContext>(thisptr);
IfNullRet(context, E_POINTER);
IfNullRet(parms_id, E_POINTER);
CopyParmsId(context->key_parms_id(), parms_id);
return S_OK;
}
SEAL_C_FUNC SEALContext_FirstParmsId(void *thisptr, uint64_t *parms_id)
{
SEALContext *context = FromVoid<SEALContext>(thisptr);
IfNullRet(context, E_POINTER);
IfNullRet(parms_id, E_POINTER);
CopyParmsId(context->first_parms_id(), parms_id);
return S_OK;
}
SEAL_C_FUNC SEALContext_LastParmsId(void *thisptr, uint64_t *parms_id)
{
SEALContext *context = FromVoid<SEALContext>(thisptr);
IfNullRet(context, E_POINTER);
IfNullRet(parms_id, E_POINTER);
CopyParmsId(context->last_parms_id(), parms_id);
return S_OK;
}
SEAL_C_FUNC SEALContext_ParametersSet(void *thisptr, bool *params_set)
{
SEALContext *context = FromVoid<SEALContext>(thisptr);
IfNullRet(context, E_POINTER);
IfNullRet(params_set, E_POINTER);
*params_set = context->parameters_set();
return S_OK;
}
SEAL_C_FUNC SEALContext_KeyContextData(void *thisptr, void **context_data)
{
SEALContext *context = FromVoid<SEALContext>(thisptr);
IfNullRet(context, E_POINTER);
IfNullRet(context_data, E_POINTER);
// The pointer that is returned should not be deleted.
auto data = context->key_context_data();
*context_data = const_cast<SEALContext::ContextData *>(data.get());
return S_OK;
}
SEAL_C_FUNC SEALContext_FirstContextData(void *thisptr, void **context_data)
{
SEALContext *context = FromVoid<SEALContext>(thisptr);
IfNullRet(context, E_POINTER);
IfNullRet(context_data, E_POINTER);
// The pointer that is returned should not be deleted.
auto data = context->first_context_data();
*context_data = const_cast<SEALContext::ContextData *>(data.get());
return S_OK;
}
SEAL_C_FUNC SEALContext_LastContextData(void *thisptr, void **context_data)
{
SEALContext *context = FromVoid<SEALContext>(thisptr);
IfNullRet(context, E_POINTER);
IfNullRet(context_data, E_POINTER);
// The pointer that is returned should not be deleted.
auto data = context->last_context_data();
*context_data = const_cast<SEALContext::ContextData *>(data.get());
return S_OK;
}
SEAL_C_FUNC SEALContext_GetContextData(void *thisptr, uint64_t *parms_id, void **context_data)
{
SEALContext *context = FromVoid<SEALContext>(thisptr);
IfNullRet(context, E_POINTER);
IfNullRet(parms_id, E_POINTER);
IfNullRet(context_data, E_POINTER);
// The pointer that is returned should not be deleted.
parms_id_type parms;
CopyParmsId(parms_id, parms);
auto data = context->get_context_data(parms);
*context_data = const_cast<SEALContext::ContextData *>(data.get());
return S_OK;
}
SEAL_C_FUNC SEALContext_UsingKeyswitching(void *thisptr, bool *using_keyswitching)
{
SEALContext *context = FromVoid<SEALContext>(thisptr);
IfNullRet(context, E_POINTER);
IfNullRet(using_keyswitching, E_POINTER);
*using_keyswitching = context->using_keyswitching();
return S_OK;
}
SEAL_C_FUNC SEALContext_ParameterErrorName(void *thisptr, char *outstr, uint64_t *length)
{
SEALContext *context = FromVoid<SEALContext>(thisptr);
IfNullRet(context, E_POINTER);
IfNullRet(length, E_POINTER);
const char *str = context->parameter_error_name();
*length = static_cast<uint64_t>(strlen(str));
if (nullptr != outstr)
{
memcpy(outstr, str, *length);
}
return S_OK;
}
SEAL_C_FUNC SEALContext_ParameterErrorMessage(void *thisptr, char *outstr, uint64_t *length)
{
SEALContext *context = FromVoid<SEALContext>(thisptr);
IfNullRet(context, E_POINTER);
IfNullRet(length, E_POINTER);
const char *str = context->parameter_error_message();
*length = static_cast<uint64_t>(strlen(str));
if (nullptr != outstr)
{
memcpy(outstr, str, *length);
}
return S_OK;
}