aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgrothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96>2013-02-03 12:59:42 +0000
committergrothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96>2013-02-03 12:59:42 +0000
commit29950778bec8b03bea9fc4203586389eb80f20d3 (patch)
treef4cdc8bdda394a261b876d1a88133a9e3086f974 /src
parent90bf3280edc1957b55dddc3d96678fb81f336d7c (diff)
-export ecc generation function
git-svn-id: https://gnunet.org/svn/gnunet@25992 140774ce-b5e7-0310-ab8b-a85725594a96
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_crypto_lib.h23
-rw-r--r--src/util/crypto_ecc.c33
2 files changed, 53 insertions, 3 deletions
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index 90f9d4e459..6120b48d8b 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -1264,6 +1264,15 @@ GNUNET_CRYPTO_ecc_key_create_from_file (const char *filename);
*/
struct GNUNET_CRYPTO_EccKeyGenerationContext;
+/**
+ * Create a new private key. Caller must free return value. Blocking version
+ * (blocks to gather entropy).
+ *
+ * @return fresh private key
+ */
+struct GNUNET_CRYPTO_EccPrivateKey *
+GNUNET_CRYPTO_ecc_key_create (void);
+
/**
* Create a new private key by reading it from a file. If the files
@@ -1303,6 +1312,20 @@ GNUNET_CRYPTO_ecc_setup_hostkey (const char *cfg_name);
/**
+ * Derive key material from a public and a private ECC key.
+ *
+ * @param key private key to use for the ECDH (x)
+ * @param pub public key to use for the ECDY (yG)
+ * @param key_material where to write the key material (xyG)
+ * @return GNUNET_SYSERR on error, GNUNET_OK on success
+ */
+int
+GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EccPrivateKey *key,
+ const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *pub,
+ struct GNUNET_HashCode *key_material);
+
+
+/**
* Sign a given block.
*
* @param key private key to use for the signing
diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c
index e98a1ce150..7f88c3e5fa 100644
--- a/src/util/crypto_ecc.c
+++ b/src/util/crypto_ecc.c
@@ -366,8 +366,8 @@ GNUNET_CRYPTO_ecc_decode_key (const char *buf,
*
* @return fresh private key
*/
-static struct GNUNET_CRYPTO_EccPrivateKey *
-ecc_key_create ()
+struct GNUNET_CRYPTO_EccPrivateKey *
+GNUNET_CRYPTO_ecc_key_create ()
{
struct GNUNET_CRYPTO_EccPrivateKey *ret;
gcry_sexp_t s_key;
@@ -555,7 +555,7 @@ GNUNET_CRYPTO_ecc_key_create_from_file (const char *filename)
}
LOG (GNUNET_ERROR_TYPE_INFO,
_("Creating a new private key. This may take a while.\n"));
- ret = ecc_key_create ();
+ ret = GNUNET_CRYPTO_ecc_key_create ();
GNUNET_assert (ret != NULL);
enc = GNUNET_CRYPTO_ecc_encode_key (ret);
GNUNET_assert (enc != NULL);
@@ -1052,4 +1052,31 @@ GNUNET_CRYPTO_ecc_verify (uint32_t purpose,
}
+/**
+ * Derive key material from a public and a private ECC key.
+ *
+ * @param key private key to use for the ECDH (x)
+ * @param pub public key to use for the ECDY (yG)
+ * @param key_material where to write the key material (xyG)
+ * @return GNUNET_SYSERR on error, GNUNET_OK on success
+ */
+int
+GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EccPrivateKey *key,
+ const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *pub,
+ struct GNUNET_HashCode *key_material)
+{
+ gcry_sexp_t psexp;
+
+ if (! (psexp = decode_public_key (pub)))
+ return GNUNET_SYSERR;
+
+
+ gcry_sexp_release (psexp);
+ GNUNET_break (0); // not implemented
+ /* FIXME: this totally breaks security ... */
+ memset (key_material, 42, sizeof (struct GNUNET_HashCode));
+ return GNUNET_OK;
+}
+
+
/* end of crypto_ecc.c */