Use the [`BN_mod`](https://wiki.openssl.org/index.php/Manual:BN_add(3)) functions.
– jwwOct 29 '17 at 19:45
hey, thanks for your answer! Are you sure that I will get x using Bn_mod?
Do I have to use it like this - Bn_mod(x, p, m, ctx) to get value x?
– VFcdxcvOct 29 '17 at 21:04
Oh, my bad. I misparsed the question and thought you were calculating `m`. You can't calculate `x` if the size of `p` is non-trivial, like sizes used in cryptography. If its a crypto puzzle or homework problem with smaller moduli, then use Shank's algorithm to solve for `x`. Here's what you should search for: [Shank's algorithm discrete log](https://www.google.com/search?q=Shank's+algorithm+discrete+log).
– jwwOct 30 '17 at 13:44
If `p` is a full size, real security parameter, then don't waste your time on solving discrete logs. You probably won't be able to recover `x`. Instead, focus on intercepting the communications channel. Have your victim perform key exchange with you, and then you perform key exchange with the server. In this case, you are just proxying the messages from victim to server.
– jwwOct 30 '17 at 13:49