diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-09-16 07:49:27 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-09-16 07:49:27 +0000 |
commit | d9e805e67df18b35711f3aa04f3d27455b6b7dbf (patch) | |
tree | 6cd02986829dec4a17090d8f8a974f392055ba21 /src/util/crypto_ecc.c | |
parent | a7bb525278fcf8a29daa8f841e99515dba690d09 (diff) | |
download | gnunet-d9e805e67df18b35711f3aa04f3d27455b6b7dbf.tar.gz gnunet-d9e805e67df18b35711f3aa04f3d27455b6b7dbf.zip |
-fix compiler warnings
Diffstat (limited to 'src/util/crypto_ecc.c')
-rw-r--r-- | src/util/crypto_ecc.c | 66 |
1 files changed, 61 insertions, 5 deletions
diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c index 1215512f4..c17da46e9 100644 --- a/src/util/crypto_ecc.c +++ b/src/util/crypto_ecc.c | |||
@@ -227,9 +227,40 @@ decode_private_key (const struct GNUNET_CRYPTO_EccPrivateKey *priv) | |||
227 | * @param ctx context to use for ECC operations | 227 | * @param ctx context to use for ECC operations |
228 | */ | 228 | */ |
229 | static void | 229 | static void |
230 | point_to_public_key (gcry_mpi_point_t q, | 230 | point_to_public_sign_key (gcry_mpi_point_t q, |
231 | gcry_ctx_t ctx, | 231 | gcry_ctx_t ctx, |
232 | struct GNUNET_CRYPTO_EccPublicSignKey *pub) | 232 | struct GNUNET_CRYPTO_EccPublicSignKey *pub) |
233 | { | ||
234 | gcry_mpi_t q_x; | ||
235 | gcry_mpi_t q_y; | ||
236 | |||
237 | q_x = gcry_mpi_new (256); | ||
238 | q_y = gcry_mpi_new (256); | ||
239 | if (gcry_mpi_ec_get_affine (q_x, q_y, q, ctx)) | ||
240 | { | ||
241 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "get_affine failed", 0); | ||
242 | return; | ||
243 | } | ||
244 | |||
245 | mpi_print (pub->q_x, sizeof (pub->q_x), q_x); | ||
246 | mpi_print (pub->q_y, sizeof (pub->q_y), q_y); | ||
247 | gcry_mpi_release (q_x); | ||
248 | gcry_mpi_release (q_y); | ||
249 | } | ||
250 | |||
251 | |||
252 | /** | ||
253 | * Initialize public key struct from the respective point | ||
254 | * on the curve. | ||
255 | * | ||
256 | * @param q point on curve | ||
257 | * @param pub public key struct to initialize | ||
258 | * @param ctx context to use for ECC operations | ||
259 | */ | ||
260 | static void | ||
261 | point_to_public_encrypt_key (gcry_mpi_point_t q, | ||
262 | gcry_ctx_t ctx, | ||
263 | struct GNUNET_CRYPTO_EccPublicEncryptKey *pub) | ||
233 | { | 264 | { |
234 | gcry_mpi_t q_x; | 265 | gcry_mpi_t q_x; |
235 | gcry_mpi_t q_y; | 266 | gcry_mpi_t q_y; |
@@ -268,7 +299,32 @@ GNUNET_CRYPTO_ecc_key_get_public_for_signature (const struct GNUNET_CRYPTO_EccPr | |||
268 | GNUNET_assert (0 == gcry_mpi_ec_new (&ctx, sexp, NULL)); | 299 | GNUNET_assert (0 == gcry_mpi_ec_new (&ctx, sexp, NULL)); |
269 | gcry_sexp_release (sexp); | 300 | gcry_sexp_release (sexp); |
270 | q = gcry_mpi_ec_get_point ("q", ctx, 0); | 301 | q = gcry_mpi_ec_get_point ("q", ctx, 0); |
271 | point_to_public_key (q, ctx, pub); | 302 | point_to_public_sign_key (q, ctx, pub); |
303 | gcry_ctx_release (ctx); | ||
304 | gcry_mpi_point_release (q); | ||
305 | } | ||
306 | |||
307 | |||
308 | /** | ||
309 | * Extract the public key for the given private key. | ||
310 | * | ||
311 | * @param priv the private key | ||
312 | * @param pub where to write the public key | ||
313 | */ | ||
314 | void | ||
315 | GNUNET_CRYPTO_ecc_key_get_public_for_encryption (const struct GNUNET_CRYPTO_EccPrivateKey *priv, | ||
316 | struct GNUNET_CRYPTO_EccPublicEncryptKey *pub) | ||
317 | { | ||
318 | gcry_sexp_t sexp; | ||
319 | gcry_ctx_t ctx; | ||
320 | gcry_mpi_point_t q; | ||
321 | |||
322 | sexp = decode_private_key (priv); | ||
323 | GNUNET_assert (NULL != sexp); | ||
324 | GNUNET_assert (0 == gcry_mpi_ec_new (&ctx, sexp, NULL)); | ||
325 | gcry_sexp_release (sexp); | ||
326 | q = gcry_mpi_ec_get_point ("q", ctx, 0); | ||
327 | point_to_public_encrypt_key (q, ctx, pub); | ||
272 | gcry_ctx_release (ctx); | 328 | gcry_ctx_release (ctx); |
273 | gcry_mpi_point_release (q); | 329 | gcry_mpi_point_release (q); |
274 | } | 330 | } |
@@ -1047,7 +1103,7 @@ GNUNET_CRYPTO_ecc_public_key_derive (const struct GNUNET_CRYPTO_EccPublicSignKey | |||
1047 | gcry_mpi_release (n); | 1103 | gcry_mpi_release (n); |
1048 | gcry_mpi_point_release (q); | 1104 | gcry_mpi_point_release (q); |
1049 | /* convert point 'v' to public key that we return */ | 1105 | /* convert point 'v' to public key that we return */ |
1050 | point_to_public_key (v, ctx, result); | 1106 | point_to_public_sign_key (v, ctx, result); |
1051 | gcry_mpi_point_release (v); | 1107 | gcry_mpi_point_release (v); |
1052 | gcry_ctx_release (ctx); | 1108 | gcry_ctx_release (ctx); |
1053 | } | 1109 | } |