RE: Need help with RSA system (C bug likely) 01-06-2015, 03:35 AM
#2
Firstly, <stdio.h> should be included first. gmp checks for having FILE, and so order does matter. Also, what is htonl? Seems like you're failing to include <winsock2.h>? I changed your includes to this when I first compiled it:
Otherwise the macro which resolves to __gmpz_out_str (mpz_out_str) was being implicitly defined.
Also, what is this?
Why not just have BITWIDTH defined?
Another thing:
You're using C99 obviously, which comes with a <stdbool.h> header for the bool type. However, with that said, the only thing you do with the value to be returned is:
1. Set it to 1
2. Check it against 1
3. And return it
This doesn't make sense.
Furthermore:
That's the only goto statement for this label... Did you REALLY need a label to make use of a goto here? C still has the break; statement too. :S
There's lots to be fixed as it stands before looking at the actual algorithm and calculations involved.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <gmp.h>
#include <winsock2.h>Otherwise the macro which resolves to __gmpz_out_str (mpz_out_str) was being implicitly defined.
Also, what is this?
Code:
#define BITWIDTH 8
#define BITWIDTH_E (BITWIDTH)Why not just have BITWIDTH defined?
Another thing:
Code:
char isPrime(mpz_t p)You're using C99 obviously, which comes with a <stdbool.h> header for the bool type. However, with that said, the only thing you do with the value to be returned is:
1. Set it to 1
Code:
char ret = 1;2. Check it against 1
Code:
&& ret == 13. And return it
Code:
return ret;This doesn't make sense.
Furthermore:
Code:
for (mpz_set_ui(i, 2); mpz_cmp(i, sqrtq) < 0 && ret == 1;mpz_add_ui(i, i, 1))
{
mpz_mod(tmp, p, i);
if (mpz_cmp_ui(tmp, 1) == 0)
goto isPrimeDone;
}
isPrimeDone:That's the only goto statement for this label... Did you REALLY need a label to make use of a goto here? C still has the break; statement too. :S
There's lots to be fixed as it stands before looking at the actual algorithm and calculations involved.



![[+]](https://sinister.li/images/modern/collapse_collapsed.png)