summaryrefslogtreecommitdiff
path: root/src/utilities.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/utilities.h')
-rw-r--r--src/utilities.h61
1 files changed, 60 insertions, 1 deletions
diff --git a/src/utilities.h b/src/utilities.h
index d17f647..ae5d82c 100644
--- a/src/utilities.h
+++ b/src/utilities.h
@@ -64,6 +64,12 @@ static int do_mpz_t_load (mpz_t x, SCM data, int throw_if_fail);
static const struct ecc_curve *do_ecc_curve_load (SCM data,
int throw_if_fail);
+/* Set up a key, and return whether it was OK */
+static int do_ecc_point_load (struct ecc_point *x, SCM data);
+static int do_ecc_scalar_load (struct ecc_scalar *x, SCM data);
+static int do_rsa_public_key_load (struct rsa_public_key *x, SCM data);
+static int do_rsa_private_key_load (struct rsa_private_key *x, SCM data);
+
/* Register x to be destroyed at the end of the dynamic wind. */
static void dynwind_mpz_t_clear (mpz_t x);
static void dynwind_ecc_point_clear (struct ecc_point *x);
@@ -229,7 +235,7 @@ get_as_bytevector (SCM data, size_t *size, int throw_if_fail)
char *data_str = NULL;
struct base64_decode_ctx decoder;
int ok = 1;
- if (!scm_is_bytevector (data) && !throw_if_fail)
+ if (!scm_is_string (data) && !throw_if_fail)
{
return NULL;
}
@@ -301,6 +307,59 @@ do_ecc_curve_load (SCM crv, int throw_if_fail)
return NULL;
}
+static inline int
+do_ecc_point_load (struct ecc_point *point, SCM data)
+{
+ mpz_t x, y;
+ int ret = 1;
+ scm_dynwind_begin (0);
+ mpz_init (x);
+ dynwind_mpz_t_clear (x);
+ mpz_init (y);
+ dynwind_mpz_t_clear (y);
+ ret =
+ (do_mpz_t_load (x, scm_assq_ref (data, kx), 0)
+ && do_mpz_t_load (y, scm_assq_ref (data, ky), 0)
+ && ecc_point_set (point, x, y));
+ scm_dynwind_end ();
+ return ret;
+}
+
+static inline int
+do_ecc_scalar_load (struct ecc_scalar *scalar, SCM data)
+{
+ mpz_t z;
+ int ret = 1;
+ scm_dynwind_begin (0);
+ mpz_init (z);
+ dynwind_mpz_t_clear (z);
+ ret =
+ (do_mpz_t_load (z, scm_assq_ref (data, kd), 0)
+ && ecc_scalar_set (scalar, z));
+ scm_dynwind_end ();
+ return ret;
+}
+
+static inline int
+do_rsa_public_key_load (struct rsa_public_key *x, SCM data)
+{
+ return (do_mpz_t_load (x->n, scm_assq_ref (data, kn), 0)
+ && do_mpz_t_load (x->e, scm_assq_ref (data, ke), 0)
+ && rsa_public_key_prepare (x));
+}
+
+static inline int
+do_rsa_private_key_load (struct rsa_private_key *x, SCM data)
+{
+ return (do_mpz_t_load (x->d, scm_assq_ref (data, kd), 0)
+ && do_mpz_t_load (x->p, scm_assq_ref (data, kp), 0)
+ && do_mpz_t_load (x->q, scm_assq_ref (data, kq), 0)
+ && do_mpz_t_load (x->a, scm_assq_ref (data, kdp), 0)
+ && do_mpz_t_load (x->b, scm_assq_ref (data, kdq), 0)
+ && do_mpz_t_load (x->c, scm_assq_ref (data, kqi), 0)
+ && rsa_private_key_prepare (x));
+}
+
static void
do_mpz_t_clear (void *ptr)
{