Added gmp

parent d9bbc4b2
...@@ -33,8 +33,10 @@ libff::alt_bn128_Fr* keyFromString(std::string& _keyString) { ...@@ -33,8 +33,10 @@ libff::alt_bn128_Fr* keyFromString(std::string& _keyString) {
void import_key(const char* _keyString) { void import_key(const char* _keyString, char* encryptedKey, uint64_t bufLen) {
if (encryptedKey == nullptr && bufLen < 100)
throw std::exception();
if (_keyString == nullptr) if (_keyString == nullptr)
throw std::exception(); throw std::exception();
...@@ -54,4 +56,13 @@ void import_key(const char* _keyString) { ...@@ -54,4 +56,13 @@ void import_key(const char* _keyString) {
if (s1->compare(*s2) != 0) if (s1->compare(*s2) != 0)
throw std::exception(); throw std::exception();
if (s2->size() == 0)
throw std::exception();
if (s2->size() >= 100)
throw std::exception();
strncpy(encryptedKey, s2->c_str(), 100);
} }
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#define EXTERNC #define EXTERNC
#endif #endif
EXTERNC void import_key(const char* _keyString); EXTERNC void import_key(const char* _keyString, char* encryptedKey, uint64_t bufLen);
#endif //SGXD_BLSUTILS_H #endif //SGXD_BLSUTILS_H
...@@ -109,12 +109,7 @@ void e_mpf_div(mpf_t *c_un, mpf_t *a_un, mpf_t *b_un) { ...@@ -109,12 +109,7 @@ void e_mpf_div(mpf_t *c_un, mpf_t *a_un, mpf_t *b_un) {
} }
/* Use the Chudnovsky equation to rapidly estimate pi */
#define DIGITS_PER_ITERATION 14.1816 /* Roughly */
mpz_t c3, c4, c5;
int pi_init = 0;
void encrypt_key(int *err_status, char* key, char* encrypted_key) { void encrypt_key(int *err_status, char* key, char* encrypted_key) {
...@@ -123,7 +118,7 @@ void encrypt_key(int *err_status, char* key, char* encrypted_key) { ...@@ -123,7 +118,7 @@ void encrypt_key(int *err_status, char* key, char* encrypted_key) {
if (strnlen(key) == 100) if (strnlen(key) == 100)
return; return;
import_key(key); import_key(key, encrypted_key, 100);
*err_status = 0; *err_status = 0;
} }
......
...@@ -136,6 +136,8 @@ int main (int argc, char *argv[]) ...@@ -136,6 +136,8 @@ int main (int argc, char *argv[])
gmp_printf("Encrypt key completed with status: %d \n", err_status); gmp_printf("Encrypt key completed with status: %d \n", err_status);
gmp_printf("Result: %s \n", encryptedKey);
return 0; return 0;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment