diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-02-03 12:59:42 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-02-03 12:59:42 +0000 |
commit | ae54c0647ef8f7d3064c2135dc71f0afcc887150 (patch) | |
tree | f4cdc8bdda394a261b876d1a88133a9e3086f974 /src | |
parent | 795ee680b5750325ac3b070c67ad6838904df873 (diff) | |
download | gnunet-ae54c0647ef8f7d3064c2135dc71f0afcc887150.tar.gz gnunet-ae54c0647ef8f7d3064c2135dc71f0afcc887150.zip |
-export ecc generation function
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_crypto_lib.h | 23 | ||||
-rw-r--r-- | src/util/crypto_ecc.c | 33 |
2 files changed, 53 insertions, 3 deletions
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index 90f9d4e45..6120b48d8 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); | |||
1264 | */ | 1264 | */ |
1265 | struct GNUNET_CRYPTO_EccKeyGenerationContext; | 1265 | struct GNUNET_CRYPTO_EccKeyGenerationContext; |
1266 | 1266 | ||
1267 | /** | ||
1268 | * Create a new private key. Caller must free return value. Blocking version | ||
1269 | * (blocks to gather entropy). | ||
1270 | * | ||
1271 | * @return fresh private key | ||
1272 | */ | ||
1273 | struct GNUNET_CRYPTO_EccPrivateKey * | ||
1274 | GNUNET_CRYPTO_ecc_key_create (void); | ||
1275 | |||
1267 | 1276 | ||
1268 | /** | 1277 | /** |
1269 | * Create a new private key by reading it from a file. If the files | 1278 | * 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); | |||
1303 | 1312 | ||
1304 | 1313 | ||
1305 | /** | 1314 | /** |
1315 | * Derive key material from a public and a private ECC key. | ||
1316 | * | ||
1317 | * @param key private key to use for the ECDH (x) | ||
1318 | * @param pub public key to use for the ECDY (yG) | ||
1319 | * @param key_material where to write the key material (xyG) | ||
1320 | * @return GNUNET_SYSERR on error, GNUNET_OK on success | ||
1321 | */ | ||
1322 | int | ||
1323 | GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EccPrivateKey *key, | ||
1324 | const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *pub, | ||
1325 | struct GNUNET_HashCode *key_material); | ||
1326 | |||
1327 | |||
1328 | /** | ||
1306 | * Sign a given block. | 1329 | * Sign a given block. |
1307 | * | 1330 | * |
1308 | * @param key private key to use for the signing | 1331 | * @param key private key to use for the signing |
diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c index e98a1ce15..7f88c3e5f 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, | |||
366 | * | 366 | * |
367 | * @return fresh private key | 367 | * @return fresh private key |
368 | */ | 368 | */ |
369 | static struct GNUNET_CRYPTO_EccPrivateKey * | 369 | struct GNUNET_CRYPTO_EccPrivateKey * |
370 | ecc_key_create () | 370 | GNUNET_CRYPTO_ecc_key_create () |
371 | { | 371 | { |
372 | struct GNUNET_CRYPTO_EccPrivateKey *ret; | 372 | struct GNUNET_CRYPTO_EccPrivateKey *ret; |
373 | gcry_sexp_t s_key; | 373 | gcry_sexp_t s_key; |
@@ -555,7 +555,7 @@ GNUNET_CRYPTO_ecc_key_create_from_file (const char *filename) | |||
555 | } | 555 | } |
556 | LOG (GNUNET_ERROR_TYPE_INFO, | 556 | LOG (GNUNET_ERROR_TYPE_INFO, |
557 | _("Creating a new private key. This may take a while.\n")); | 557 | _("Creating a new private key. This may take a while.\n")); |
558 | ret = ecc_key_create (); | 558 | ret = GNUNET_CRYPTO_ecc_key_create (); |
559 | GNUNET_assert (ret != NULL); | 559 | GNUNET_assert (ret != NULL); |
560 | enc = GNUNET_CRYPTO_ecc_encode_key (ret); | 560 | enc = GNUNET_CRYPTO_ecc_encode_key (ret); |
561 | GNUNET_assert (enc != NULL); | 561 | GNUNET_assert (enc != NULL); |
@@ -1052,4 +1052,31 @@ GNUNET_CRYPTO_ecc_verify (uint32_t purpose, | |||
1052 | } | 1052 | } |
1053 | 1053 | ||
1054 | 1054 | ||
1055 | /** | ||
1056 | * Derive key material from a public and a private ECC key. | ||
1057 | * | ||
1058 | * @param key private key to use for the ECDH (x) | ||
1059 | * @param pub public key to use for the ECDY (yG) | ||
1060 | * @param key_material where to write the key material (xyG) | ||
1061 | * @return GNUNET_SYSERR on error, GNUNET_OK on success | ||
1062 | */ | ||
1063 | int | ||
1064 | GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EccPrivateKey *key, | ||
1065 | const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *pub, | ||
1066 | struct GNUNET_HashCode *key_material) | ||
1067 | { | ||
1068 | gcry_sexp_t psexp; | ||
1069 | |||
1070 | if (! (psexp = decode_public_key (pub))) | ||
1071 | return GNUNET_SYSERR; | ||
1072 | |||
1073 | |||
1074 | gcry_sexp_release (psexp); | ||
1075 | GNUNET_break (0); // not implemented | ||
1076 | /* FIXME: this totally breaks security ... */ | ||
1077 | memset (key_material, 42, sizeof (struct GNUNET_HashCode)); | ||
1078 | return GNUNET_OK; | ||
1079 | } | ||
1080 | |||
1081 | |||
1055 | /* end of crypto_ecc.c */ | 1082 | /* end of crypto_ecc.c */ |