aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-09-16 07:49:27 +0000
committerChristian Grothoff <christian@grothoff.org>2013-09-16 07:49:27 +0000
commitd9e805e67df18b35711f3aa04f3d27455b6b7dbf (patch)
tree6cd02986829dec4a17090d8f8a974f392055ba21 /src
parenta7bb525278fcf8a29daa8f841e99515dba690d09 (diff)
downloadgnunet-d9e805e67df18b35711f3aa04f3d27455b6b7dbf.tar.gz
gnunet-d9e805e67df18b35711f3aa04f3d27455b6b7dbf.zip
-fix compiler warnings
Diffstat (limited to 'src')
-rw-r--r--src/core/gnunet-service-core_kx.c6
-rw-r--r--src/util/crypto_ecc.c66
-rw-r--r--src/util/test_crypto_ecc.c8
3 files changed, 68 insertions, 12 deletions
diff --git a/src/core/gnunet-service-core_kx.c b/src/core/gnunet-service-core_kx.c
index 6c6b8f07a..19c8d7710 100644
--- a/src/core/gnunet-service-core_kx.c
+++ b/src/core/gnunet-service-core_kx.c
@@ -111,7 +111,7 @@ struct EphemeralKeyMessage
111 * Ephemeral public ECC key (always for NIST P-521) encoded in a format suitable 111 * Ephemeral public ECC key (always for NIST P-521) encoded in a format suitable
112 * for network transmission as created using 'gcry_sexp_sprint'. 112 * for network transmission as created using 'gcry_sexp_sprint'.
113 */ 113 */
114 struct GNUNET_CRYPTO_EccPublicSignKey ephemeral_key; 114 struct GNUNET_CRYPTO_EccPublicEncryptKey ephemeral_key;
115 115
116 /** 116 /**
117 * Public key of the signing peer (persistent version, not the ephemeral public key). 117 * Public key of the signing peer (persistent version, not the ephemeral public key).
@@ -1492,8 +1492,8 @@ sign_ephemeral_key ()
1492 { 1492 {
1493 current_ekm.expiration_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_FOREVER_ABS); 1493 current_ekm.expiration_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_FOREVER_ABS);
1494 } 1494 }
1495 GNUNET_CRYPTO_ecc_key_get_public_for_signature (my_ephemeral_key, 1495 GNUNET_CRYPTO_ecc_key_get_public_for_encryption (my_ephemeral_key,
1496 &current_ekm.ephemeral_key); 1496 &current_ekm.ephemeral_key);
1497 current_ekm.origin_public_key = my_public_key; 1497 current_ekm.origin_public_key = my_public_key;
1498 GNUNET_assert (GNUNET_OK == 1498 GNUNET_assert (GNUNET_OK ==
1499 GNUNET_CRYPTO_ecc_sign (my_private_key, 1499 GNUNET_CRYPTO_ecc_sign (my_private_key,
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 */
229static void 229static void
230point_to_public_key (gcry_mpi_point_t q, 230point_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 */
260static void
261point_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 */
314void
315GNUNET_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}
diff --git a/src/util/test_crypto_ecc.c b/src/util/test_crypto_ecc.c
index 9a70eb055..ff944ce0e 100644
--- a/src/util/test_crypto_ecc.c
+++ b/src/util/test_crypto_ecc.c
@@ -204,15 +204,15 @@ test_ecdh ()
204{ 204{
205 struct GNUNET_CRYPTO_EccPrivateKey *priv1; 205 struct GNUNET_CRYPTO_EccPrivateKey *priv1;
206 struct GNUNET_CRYPTO_EccPrivateKey *priv2; 206 struct GNUNET_CRYPTO_EccPrivateKey *priv2;
207 struct GNUNET_CRYPTO_EccPublicSignKey pub1; 207 struct GNUNET_CRYPTO_EccPublicEncryptKey pub1;
208 struct GNUNET_CRYPTO_EccPublicSignKey pub2; 208 struct GNUNET_CRYPTO_EccPublicEncryptKey pub2;
209 struct GNUNET_HashCode ecdh1; 209 struct GNUNET_HashCode ecdh1;
210 struct GNUNET_HashCode ecdh2; 210 struct GNUNET_HashCode ecdh2;
211 211
212 priv1 = GNUNET_CRYPTO_ecc_key_create (); 212 priv1 = GNUNET_CRYPTO_ecc_key_create ();
213 priv2 = GNUNET_CRYPTO_ecc_key_create (); 213 priv2 = GNUNET_CRYPTO_ecc_key_create ();
214 GNUNET_CRYPTO_ecc_key_get_public_for_signature (priv1, &pub1); 214 GNUNET_CRYPTO_ecc_key_get_public_for_encryption (priv1, &pub1);
215 GNUNET_CRYPTO_ecc_key_get_public_for_signature (priv2, &pub2); 215 GNUNET_CRYPTO_ecc_key_get_public_for_encryption (priv2, &pub2);
216 GNUNET_CRYPTO_ecc_ecdh (priv1, &pub2, &ecdh1); 216 GNUNET_CRYPTO_ecc_ecdh (priv1, &pub2, &ecdh1);
217 GNUNET_CRYPTO_ecc_ecdh (priv2, &pub1, &ecdh2); 217 GNUNET_CRYPTO_ecc_ecdh (priv2, &pub1, &ecdh2);
218 GNUNET_assert (0 == memcmp (&ecdh1, &ecdh2, 218 GNUNET_assert (0 == memcmp (&ecdh1, &ecdh2,