forked from microsoft/SEAL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
decryptor.cpp
81 lines (70 loc) · 2.06 KB
/
decryptor.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
// SEALNet
#include "seal/c/decryptor.h"
#include "seal/c/utilities.h"
// SEAL
#include "seal/decryptor.h"
using namespace std;
using namespace seal;
using namespace seal::c;
SEAL_C_FUNC Decryptor_Create(void *context, void *secret_key, void **decryptor)
{
const SEALContext *ctx = FromVoid<SEALContext>(context);
IfNullRet(ctx, E_POINTER);
SecretKey *secretKey = FromVoid<SecretKey>(secret_key);
IfNullRet(secretKey, E_POINTER);
IfNullRet(decryptor, E_POINTER);
try
{
Decryptor *decr = new Decryptor(*ctx, *secretKey);
*decryptor = decr;
return S_OK;
}
catch (const invalid_argument &)
{
return E_INVALIDARG;
}
}
SEAL_C_FUNC Decryptor_Destroy(void *thisptr)
{
Decryptor *decryptor = FromVoid<Decryptor>(thisptr);
IfNullRet(decryptor, E_POINTER);
delete decryptor;
return S_OK;
}
SEAL_C_FUNC Decryptor_Decrypt(void *thisptr, void *encrypted, void *destination)
{
Decryptor *decryptor = FromVoid<Decryptor>(thisptr);
IfNullRet(decryptor, E_POINTER);
Ciphertext *encryptedptr = FromVoid<Ciphertext>(encrypted);
IfNullRet(encryptedptr, E_POINTER);
Plaintext *destinationptr = FromVoid<Plaintext>(destination);
IfNullRet(destinationptr, E_POINTER);
try
{
decryptor->decrypt(*encryptedptr, *destinationptr);
return S_OK;
}
catch (const invalid_argument &)
{
return E_INVALIDARG;
}
}
SEAL_C_FUNC Decryptor_InvariantNoiseBudget(void *thisptr, void *encrypted, int *invariant_noise_budget)
{
Decryptor *decryptor = FromVoid<Decryptor>(thisptr);
IfNullRet(decryptor, E_POINTER);
Ciphertext *encryptedptr = FromVoid<Ciphertext>(encrypted);
IfNullRet(encryptedptr, E_POINTER);
IfNullRet(invariant_noise_budget, E_POINTER);
try
{
*invariant_noise_budget = decryptor->invariant_noise_budget(*encryptedptr);
return S_OK;
}
catch (const invalid_argument &)
{
return E_INVALIDARG;
}
}