summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crypt.cpp22
-rw-r--r--keygen.cpp4
2 files changed, 22 insertions, 4 deletions
diff --git a/crypt.cpp b/crypt.cpp
index 5f0d01d..f59a704 100644
--- a/crypt.cpp
+++ b/crypt.cpp
@@ -17,25 +17,37 @@ extern char *outfname;
struct rsakey_t
{
- long unsigned e, d, n;
+ unsigned long e, d, n;
+ bool valid_rsa_tag;
};
/* parse pubkey xml file */
struct rsakey_t parse_key(FILE *file)
{
struct rsakey_t key = { 0, 0, 0};
+ key.valid_rsa_tag = false;
/* used for line reading */
size_t line_sz = 0;
char *line = NULL;
+ bool rsa_opening_tag = false;
+ bool rsa_closing_tag = false;
+
while (getline(&line, &line_sz, file) != -1)
{
+ if (strcmp(line, "<rsakey>\n") == 0)
+ rsa_opening_tag = true;
sscanf(line, "\t<dvalue>%lu</dvalue>\n", &key.d);
sscanf(line, "\t<evalue>%lu</evalue>\n", &key.e);
sscanf(line, "\t<nvalue>%lu</nvalue>\n", &key.n);
+ if (strcmp(line, "</rsakey>\n") == 0)
+ rsa_closing_tag = true;
}
+ if (rsa_opening_tag && rsa_closing_tag)
+ key.valid_rsa_tag = true;
+
if (line)
free(line);
@@ -74,7 +86,13 @@ int main(int argc, char **argv)
int mode = -1;
struct rsakey_t key = parse_key(keyfname_fl);
- if (key.d == 0 && key.e && key.n)
+ if (!key.valid_rsa_tag)
+ {
+ fprintf(stderr, "invalid key or invalid xml\n");
+ exit(EXIT_FAILURE);
+ }
+
+ else if (key.d == 0 && key.e && key.n)
{
cout << "public key (" << key.e << ", " << key.n
<< ") detected, will perform encryption" << endl;
diff --git a/keygen.cpp b/keygen.cpp
index 53751f2..e785cfb 100644
--- a/keygen.cpp
+++ b/keygen.cpp
@@ -74,7 +74,7 @@ int main(int argc, char **argv)
/* phi = (p-1)(q-1) */
unsigned long phi = (prime_p-1) * (prime_q-1);
- unsigned long fermat_primes[4] = { 3l, 17l, 65537l, 4294967297l };
+ unsigned long fermat_primes[4] = { 3l, 17l, 19l, 31l };
unsigned long e;
/* find e, 1 < e < phi, such that gcd(e, phi) = 1 */
int i;
@@ -93,7 +93,7 @@ int main(int argc, char **argv)
printf("done\n");
/* find d */
- printf("computing d... ");
+ printf("computing d... (might take a while) ");
fflush(stdout);
unsigned long d = 1;
while (1)