-static int decode_key(const char *key_file, const char *header_str,
- const char *footer_str, unsigned char **result)
+/** Private keys start with this header. */
+#define PRIVATE_KEY_HEADER "-----BEGIN RSA PRIVATE KEY-----"
+/** Private keys end with this footer. */
+#define PRIVATE_KEY_FOOTER "-----END RSA PRIVATE KEY-----"
+
+static int decode_key(const char *key_file, unsigned char **result,
+ size_t *blob_size)
unsigned char *blob = NULL;
char *begin, *footer, *key;
unsigned char *blob = NULL;
char *begin, *footer, *key;
/* skip whitespace at the beginning */
for (; begin < footer; begin++) {
if (para_isspace(*begin))
/* skip whitespace at the beginning */
for (; begin < footer; begin++) {
if (para_isspace(*begin))
- ret = base64_decode(key, j, (char **)&blob, &blob_size);
+ ret = base64_decode(key, j, (char **)&blob, blob_size);
unmap:
ret2 = para_munmap(map, map_size);
if (ret >= 0 && ret2 < 0)
unmap:
ret2 = para_munmap(map, map_size);
if (ret >= 0 && ret2 < 0)
- * bn_bytes because the latter does not include the ASN.1 prefix and a leading
- * zero is not considered as an additional byte for bn_bytes.
+ * bitsp because the latter does not include the ASN.1 prefix and a leading
+ * zero is not considered as an additional byte for the number of bits.
*/
static int read_bignum(unsigned char *start, unsigned char *end, gcry_mpi_t *bn,
*/
static int read_bignum(unsigned char *start, unsigned char *end, gcry_mpi_t *bn,
cp += bn_size;
// unsigned char *buf;
// gcry_mpi_aprint(GCRYMPI_FMT_HEX, &buf, NULL, *bn);
cp += bn_size;
// unsigned char *buf;
// gcry_mpi_aprint(GCRYMPI_FMT_HEX, &buf, NULL, *bn);
-/** Private keys start with this header. */
-#define PRIVATE_KEY_HEADER "-----BEGIN RSA PRIVATE KEY-----"
-/** Private keys end with this footer. */
-#define PRIVATE_KEY_FOOTER "-----END RSA PRIVATE KEY-----"
-
static int get_private_key(const char *key_file, struct asymmetric_key **result)
{
gcry_mpi_t n = NULL, e = NULL, d = NULL, p = NULL, q = NULL,
u = NULL;
unsigned char *blob, *cp, *end;
static int get_private_key(const char *key_file, struct asymmetric_key **result)
{
gcry_mpi_t n = NULL, e = NULL, d = NULL, p = NULL, q = NULL,
u = NULL;
unsigned char *blob, *cp, *end;
- ret = decode_key(key_file, PRIVATE_KEY_HEADER, PRIVATE_KEY_FOOTER,
- &blob);
+ ret = decode_key(key_file, &blob, &blob_size);
- ret = read_bignum(cp, end, &n, &n_size);
+ ret = read_bignum(cp, end, &n, &bits);