0

I want to use the below equation in one of the code

A = g^a mod p; //g raise to a modulus p.

(something like 2^5 % 3) = 32%3 = 2

(This equation looks like Diffie Hellman algorithm for security)

Where,

^ is (power)

g is fixed number 0x05

a is 128bit(16bytes) randomly generated number,

and p is fixed hex number of 128bit(16bytes)

something like (0x0xD4A283974897234CE908B3478387A3).

I am using,

Qt 4.8.7

Compiler MinGW32

(checked with boost library boost 1.70)

The solutions which I found which didn`t work for me are listed below:

1 one can use __int128 but to support that one should have used latest GCC compiler or MinGW64 bit compiler, neither of that I am using now.

2 I found one latest version of Qt has QSslDiffieHellmanParameters class, but again not supported in our Qt version.

3 I found some libraries like boost/multiprecision/cpp_int.hpp (boost 1.70)) that does have data type such as int128_t and int256_t, but due to our compiler isssue or something else, we are not able to store 128bit number, meaning if i do,

int128_t ptval128 = 0xAB1232423243434343BAE3453345E34B;
cout << "ptval128 = " << std::hex << ptval128 << endl;
//will print only 0xAB12324232434343;//half digits only,

4 I tried using Bigint which much more useful, but again 5^(128bit number) is way too big, it takes hours to compute things, (I waited till 1 hour and 16 mins and kill the application).

int myGval = 0x05;
128_bit_data_type myPVal= 0xD4A283974897234CE908B3478387A3; 

128_bit_data_type 128_bit_variable = 128_bit_random_data;
myVal = (myGval)^(128_bit_variable) % (myPVal);
5
  • 1
    If you don't get an answer here ask on our sister site Stack Overflow that focuses on programming questions. May 10, 2019 at 15:07
  • It might also be helpful to clarify what MinGW32 compiler you are using exactly since as per your point (1) the Ubuntu/Debian multiarch w64-mingw32-gcc-win32 does appear to provide 128-bit types (although I'm not sure that an overloaded C++ << operator is implemented for them) May 10, 2019 at 15:29
  • @steeldriver, __int128 is there, but it can`t hold that much long value, and yes, either << operator has to be overloaded or function has to be made to print value, somewhat similar issue mentioned in point (3). May 13, 2019 at 12:25
  • @WinEunuuchs2Unix, Thank you for your suggestion, I already asked this question there and got an answer. May 14, 2019 at 5:34
  • 1
    @RohitDharaviya Glad they could answer the question. I'm voting to close the same question here off-topic. May 14, 2019 at 10:34

0

You must log in to answer this question.

Browse other questions tagged .