Login Register






Need help with RSA system (C bug likely) filter_list
Author
Message
RE: Need help with RSA system (C bug likely) #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:
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 == 1

3. 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.

Reply





Messages In This Thread
RE: Need help with RSA system (C bug likely) - by 0xDEAD10CC - 01-06-2015, 03:35 AM