aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/gnunet_crypto_lib.h17
-rw-r--r--src/util/crypto_ecc.c49
2 files changed, 41 insertions, 25 deletions
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index 693cfcf12..8592f0da5 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -267,7 +267,7 @@ struct GNUNET_CRYPTO_EccSignature
267 /** 267 /**
268 * Overall size of the signature data. 268 * Overall size of the signature data.
269 */ 269 */
270 uint16_t size; 270 uint16_t size GNUNET_PACKED;
271 271
272 /** 272 /**
273 * S-expression, padded with zeros. 273 * S-expression, padded with zeros.
@@ -285,12 +285,12 @@ struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded
285 /** 285 /**
286 * Size of the encoding, in network byte order. 286 * Size of the encoding, in network byte order.
287 */ 287 */
288 uint16_t size; 288 uint16_t size GNUNET_PACKED;
289 289
290 /** 290 /**
291 * Actual length of the q-point binary encoding. 291 * Actual length of the q-point binary encoding.
292 */ 292 */
293 uint16_t len; 293 uint16_t len GNUNET_PACKED;
294 294
295 /** 295 /**
296 * 0-padded q-point in binary encoding (GCRYPT_MPI_FMT_USG). 296 * 0-padded q-point in binary encoding (GCRYPT_MPI_FMT_USG).
@@ -1277,6 +1277,17 @@ GNUNET_CRYPTO_ecc_key_create_from_file (const char *filename);
1277 1277
1278 1278
1279/** 1279/**
1280 * Create a new private key by reading our peer's key from
1281 * the file specified in the configuration.
1282 *
1283 * @return new private key, NULL on error (for example,
1284 * permission denied)
1285 */
1286struct GNUNET_CRYPTO_EccPrivateKey *
1287GNUNET_CRYPTO_ecc_key_create_from_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg);
1288
1289
1290/**
1280 * Handle to cancel private key generation and state for the 1291 * Handle to cancel private key generation and state for the
1281 * key generation operation. 1292 * key generation operation.
1282 */ 1293 */
diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c
index b5a057aed..498de59df 100644
--- a/src/util/crypto_ecc.c
+++ b/src/util/crypto_ecc.c
@@ -890,6 +890,28 @@ GNUNET_CRYPTO_ecc_key_create_start (const char *filename,
890 890
891 891
892/** 892/**
893 * Create a new private key by reading our peer's key from
894 * the file specified in the configuration.
895 *
896 * @return new private key, NULL on error (for example,
897 * permission denied)
898 */
899struct GNUNET_CRYPTO_EccPrivateKey *
900GNUNET_CRYPTO_ecc_key_create_from_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg)
901{
902 struct GNUNET_CRYPTO_EccPrivateKey *pk;
903 char *fn;
904
905 if (GNUNET_OK !=
906 GNUNET_CONFIGURATION_get_value_filename (cfg, "PEER", "PRIVATE_KEY", &fn))
907 return NULL;
908 pk = GNUNET_CRYPTO_ecc_key_create_from_file (fn);
909 GNUNET_free (fn);
910 return pk;
911}
912
913
914/**
893 * Setup a key file for a peer given the name of the 915 * Setup a key file for a peer given the name of the
894 * configuration file (!). This function is used so that 916 * configuration file (!). This function is used so that
895 * at a later point code can be certain that reading a 917 * at a later point code can be certain that reading a
@@ -902,18 +924,12 @@ GNUNET_CRYPTO_ecc_setup_key (const char *cfg_name)
902{ 924{
903 struct GNUNET_CONFIGURATION_Handle *cfg; 925 struct GNUNET_CONFIGURATION_Handle *cfg;
904 struct GNUNET_CRYPTO_EccPrivateKey *pk; 926 struct GNUNET_CRYPTO_EccPrivateKey *pk;
905 char *fn;
906 927
907 cfg = GNUNET_CONFIGURATION_create (); 928 cfg = GNUNET_CONFIGURATION_create ();
908 (void) GNUNET_CONFIGURATION_load (cfg, cfg_name); 929 (void) GNUNET_CONFIGURATION_load (cfg, cfg_name);
909 if (GNUNET_OK == 930 pk = GNUNET_CRYPTO_ecc_key_create_from_configuration (cfg);
910 GNUNET_CONFIGURATION_get_value_filename (cfg, "PEER", "PRIVATE_KEY", &fn)) 931 if (NULL != pk)
911 { 932 GNUNET_CRYPTO_ecc_key_free (pk);
912 pk = GNUNET_CRYPTO_ecc_key_create_from_file (fn);
913 if (NULL != pk)
914 GNUNET_CRYPTO_ecc_key_free (pk);
915 GNUNET_free (fn);
916 }
917 GNUNET_CONFIGURATION_destroy (cfg); 933 GNUNET_CONFIGURATION_destroy (cfg);
918} 934}
919 935
@@ -932,24 +948,13 @@ GNUNET_CRYPTO_get_host_identity (const struct GNUNET_CONFIGURATION_Handle *cfg,
932{ 948{
933 struct GNUNET_CRYPTO_EccPrivateKey *my_private_key; 949 struct GNUNET_CRYPTO_EccPrivateKey *my_private_key;
934 struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded my_public_key; 950 struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded my_public_key;
935 char *keyfile;
936 951
937 if (GNUNET_OK != 952 if (NULL == (my_private_key = GNUNET_CRYPTO_ecc_key_create_from_configuration (cfg)))
938 GNUNET_CONFIGURATION_get_value_filename (cfg, "PEER", "PRIVATE_KEY",
939 &keyfile))
940 {
941 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
942 _("Lacking key configuration settings.\n"));
943 return GNUNET_SYSERR;
944 }
945 if (NULL == (my_private_key = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile)))
946 { 953 {
947 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 954 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
948 _("Could not access hostkey file `%s'.\n"), keyfile); 955 _("Could not load peer's private key\n"));
949 GNUNET_free (keyfile);
950 return GNUNET_SYSERR; 956 return GNUNET_SYSERR;
951 } 957 }
952 GNUNET_free (keyfile);
953 GNUNET_CRYPTO_ecc_key_get_public (my_private_key, &my_public_key); 958 GNUNET_CRYPTO_ecc_key_get_public (my_private_key, &my_public_key);
954 GNUNET_CRYPTO_ecc_key_free (my_private_key); 959 GNUNET_CRYPTO_ecc_key_free (my_private_key);
955 GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), &dst->hashPubKey); 960 GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), &dst->hashPubKey);