diff options
author | Markus Teich <markus.teich@stusta.mhn.de> | 2016-06-13 21:09:41 +0200 |
---|---|---|
committer | Markus Teich <markus.teich@stusta.mhn.de> | 2016-06-13 21:27:03 +0200 |
commit | 338c95de4190065149ddc995e5404d335c05f432 (patch) | |
tree | 2f7dbfb7b4fb274071fb5a2992de27703ac61960 /crypto.c | |
parent | 557fbe2cc32f3ff6d8c2c0c8aa272f7b55f45618 (diff) |
coding style
Diffstat (limited to 'crypto.c')
-rw-r--r-- | crypto.c | 135 |
1 files changed, 84 insertions, 51 deletions
@@ -35,8 +35,13 @@ struct brandt_ec_pkey { }; gcry_mpi_point_t ec_gen; -gcry_ctx_t ec_ctx; +gcry_ctx_t ec_ctx; +/** + * brandt_crypto_init + * + * + */ void brandt_crypto_init () { @@ -154,29 +159,28 @@ brandt_mpi_scan_unsigned (gcry_mpi_t *result, const void *data, size_t size) brandt_assert_gpgerr (rc); } -/* -gcry_mpi_point_t -deserialize_point(const struct brandt_point* data, const int len) -{ - gcry_sexp_t s; - gcry_ctx_t ctx; - gcry_mpi_point_t ret; - gcry_error_t rc; - - rc = gcry_sexp_build(&s, NULL, "(public-key(ecc(curve " CURVE ")(q %b)))", - len, data); - brandt_assert_gpgerr(rc); - - rc = gcry_mpi_ec_new(&ctx, s, NULL); - brandt_assert_gpgerr(rc); - gcry_sexp_release(s); +//gcry_mpi_point_t +//deserialize_point(const struct brandt_point* data, const int len) +//{ +// gcry_sexp_t s; +// gcry_ctx_t ctx; +// gcry_mpi_point_t ret; +// gcry_error_t rc; +// +// rc = gcry_sexp_build(&s, NULL, "(public-key(ecc(curve " CURVE ")(q %b)))", +// len, data); +// brandt_assert_gpgerr(rc); +// +// rc = gcry_mpi_ec_new(&ctx, s, NULL); +// brandt_assert_gpgerr(rc); +// gcry_sexp_release(s); +// +// ret = gcry_mpi_ec_get_point("q", ctx, 0); +// brandt_assert(ret); +// gcry_ctx_release(ctx); +// return ret; +//} - ret = gcry_mpi_ec_get_point("q", ctx, 0); - brandt_assert(ret); - gcry_ctx_release(ctx); - return ret; -} -*/ /* --- EC --- */ @@ -238,8 +242,13 @@ key_from_sexp (gcry_mpi_t *array, gcry_sexp_t sexp, const char *topname, return 0; } +/** + * brandt_ec_skey_create + * + * @param[out] skey where to store the generated secret key + */ void -brandt_ec_skey_create (gcry_mpi_t* skey) +brandt_ec_skey_create (gcry_mpi_t *skey) { gcry_sexp_t s_keyparam; gcry_sexp_t priv_sexp; @@ -259,16 +268,26 @@ brandt_ec_skey_create (gcry_mpi_t* skey) gcry_sexp_release (priv_sexp); } - +/** + * brandt_ec_pkey_compute + * + * @param pkey TODO + * @param skey TODO + */ void -brandt_ec_pkey_compute (gcry_mpi_point_t* pkey, const gcry_mpi_t skey) +brandt_ec_pkey_compute (gcry_mpi_point_t *pkey, const gcry_mpi_t skey) { } - +/** + * brandt_ec_keypair_create + * + * @param[out] pkey where to store the generated public key + * @param[out] skey where to store the generated secret key + */ void -brandt_ec_keypair_create (gcry_mpi_point_t* pkey, gcry_mpi_t* skey) +brandt_ec_keypair_create (gcry_mpi_point_t *pkey, gcry_mpi_t *skey) { gcry_ctx_t ctx; gcry_sexp_t s_keyparam; @@ -290,52 +309,66 @@ brandt_ec_keypair_create (gcry_mpi_point_t* pkey, gcry_mpi_t* skey) brandt_assert_gpgerr (rc); gcry_sexp_release (priv_sexp); - *pkey = gcry_mpi_ec_get_point("q", ctx, 0); + *pkey = gcry_mpi_ec_get_point ("q", ctx, 0); brandt_assert (NULL != *pkey); gcry_ctx_release (ctx); } - +/** + * brandt_ec_keypair_create_base + * + * @param[out] pkey where to store the generated public key + * @param[out] skey where to store the generated secret key + * @param[in] base which base point should be used to calculate the public key + */ void -brandt_ec_keypair_create_base (gcry_mpi_point_t* pkey, gcry_mpi_t* skey, const gcry_mpi_point_t base) +brandt_ec_keypair_create_base (gcry_mpi_point_t *pkey, gcry_mpi_t *skey, + const gcry_mpi_point_t base) { - brandt_ec_skey_create(skey); - brandt_assert(*skey); - *pkey = gcry_mpi_point_new(0); - brandt_assert(*pkey); - gcry_mpi_ec_mul(*pkey, *skey, base, ec_ctx); + brandt_ec_skey_create (skey); + brandt_assert (*skey); + *pkey = gcry_mpi_point_new (0); + brandt_assert (*pkey); + gcry_mpi_ec_mul (*pkey, *skey, base, ec_ctx); } - +/** + * brandt_ec_point_cmp compares two curve points + * + * @param[in] a the first point + * @param[in] b the second point + * @return 0 if @a a and @a b represent the same point on the curve, something + * else otherwise + */ int brandt_ec_point_cmp (const gcry_mpi_point_t a, const gcry_mpi_point_t b) { - int ret = 1; - gcry_mpi_t ax = gcry_mpi_new(0); - gcry_mpi_t bx = gcry_mpi_new(0); - gcry_mpi_t ay = gcry_mpi_new(0); - gcry_mpi_t by = gcry_mpi_new(0); + int ret = 1; + gcry_mpi_t ax = gcry_mpi_new (0); + gcry_mpi_t bx = gcry_mpi_new (0); + gcry_mpi_t ay = gcry_mpi_new (0); + gcry_mpi_t by = gcry_mpi_new (0); brandt_assert (a && b); if (!ax || !bx || !ay || !by) { - weprintf("could not init point in point_cmp"); + weprintf ("could not init point in point_cmp"); return 1; } - if (!gcry_mpi_ec_get_affine(ax, ay, a, ec_ctx) && !gcry_mpi_ec_get_affine(bx, by, b, ec_ctx)) + if (!gcry_mpi_ec_get_affine (ax, ay, a, ec_ctx) + && !gcry_mpi_ec_get_affine (bx, by, b, ec_ctx)) { - ret = gcry_mpi_cmp(ax, bx) || gcry_mpi_cmp(ay, by); + ret = gcry_mpi_cmp (ax, bx) || gcry_mpi_cmp (ay, by); } - gcry_mpi_release(ax); - gcry_mpi_release(bx); - gcry_mpi_release(ay); - gcry_mpi_release(by); + gcry_mpi_release (ax); + gcry_mpi_release (bx); + gcry_mpi_release (ay); + gcry_mpi_release (by); return ret; } - /** * Convert the given private key from the network format to the * S-expression that can be used by libgcrypt. @@ -395,7 +428,7 @@ brandt_ecdhe_key_get_public (const struct brandt_ec_skey *priv, int brandt_ecdhe (const struct brandt_ec_skey *priv, const struct brandt_ec_pkey *pub, - struct brandt_hash_code *key_material) + struct brandt_hash_code *key_material) { gcry_error_t rc; int rc2; |