gcry_mpi_mul_ui(n, n, 1 << (sizeof(uint32_t)*4));
gcry_mpi_mul_ui(n, n, 1 << (sizeof(uint32_t)*4));
#endif
- gcry_mpi_add_ui(n, n, ((uint32_t *) &tmp)[j]);
+ gcry_mpi_add_ui(n, n, ntohl (((uint32_t *) &tmp)[j]));
}
hc = tmp;
}
return rc;
}
+/**
+ * If target != size, move target bytes to the
+ * end of the size-sized buffer and zero out the
+ * first target-size bytes.
+ */
+static void
+adjust (unsigned char *buf, size_t size, size_t target)
+{
+ if (size < target)
+ {
+ memmove (&buf[target - size], buf, size);
+ memset (buf, 0, target - size);
+ }
+}
+
+
static void
gen_prime (gcry_mpi_t *ptest, unsigned int nbits, GNUNET_HashCode * hc)
{
gcry_mpi_print (GCRYMPI_FMT_USG,
(unsigned char*) &mods[i], written, &written,
tmp));
+ adjust ( (unsigned char*) &mods[i], written, sizeof (unsigned int));
+ mods[i] = ntohl (mods[i]);
}
/* Now try some primes starting with prime. */
for (step = 0; step < 20000; step += 2)