aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_crypto_lib.h
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-09-05 17:02:45 +0000
committerChristian Grothoff <christian@grothoff.org>2015-09-05 17:02:45 +0000
commit59df216f6ad04e9131ee4fa43e14055252a71651 (patch)
tree337c13e7843379446d826e34a63a2d0297d29c6e /src/include/gnunet_crypto_lib.h
parentaff9093b9a8874c841763d5ea8d4adc2197e861e (diff)
downloadgnunet-59df216f6ad04e9131ee4fa43e14055252a71651.tar.gz
gnunet-59df216f6ad04e9131ee4fa43e14055252a71651.zip
adding bin_to_point and point_to_bin functions for GNUNET_CRYPTO_ecc API
Diffstat (limited to 'src/include/gnunet_crypto_lib.h')
-rw-r--r--src/include/gnunet_crypto_lib.h56
1 files changed, 48 insertions, 8 deletions
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index eb28b8ffd..0acced362 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -1285,9 +1285,24 @@ GNUNET_CRYPTO_cmp_peer_identity (const struct GNUNET_PeerIdentity *first,
1285 */ 1285 */
1286struct GNUNET_CRYPTO_EccDlogContext; 1286struct GNUNET_CRYPTO_EccDlogContext;
1287 1287
1288
1289/**
1290 * Point on a curve (always for Curve25519) encoded in a format suitable
1291 * for network transmission (ECDH), see http://cr.yp.to/ecdh.html.
1292 */
1293struct GNUNET_CRYPTO_EccPoint
1294{
1295 /**
1296 * Q consists of an x- and a y-value, each mod p (256 bits), given
1297 * here in affine coordinates and Ed25519 standard compact format.
1298 */
1299 unsigned char q_y[256 / 8];
1300};
1301
1302
1288/** 1303/**
1289 * Do pre-calculation for ECC discrete logarithm for small factors. 1304 * Do pre-calculation for ECC discrete logarithm for small factors.
1290 * 1305 *
1291 * @param max maximum value the factor can be 1306 * @param max maximum value the factor can be
1292 * @param mem memory to use (should be smaller than @a max), must not be zero. 1307 * @param mem memory to use (should be smaller than @a max), must not be zero.
1293 * @return @a max if dlog failed, otherwise the factor 1308 * @return @a max if dlog failed, otherwise the factor
@@ -1300,7 +1315,7 @@ GNUNET_CRYPTO_ecc_dlog_prepare (unsigned int max,
1300/** 1315/**
1301 * Calculate ECC discrete logarithm for small factors. 1316 * Calculate ECC discrete logarithm for small factors.
1302 * Opposite of #GNUNET_CRYPTO_ecc_dexp(). 1317 * Opposite of #GNUNET_CRYPTO_ecc_dexp().
1303 * 1318 *
1304 * @param dlc precalculated values, determine range of factors 1319 * @param dlc precalculated values, determine range of factors
1305 * @param input point on the curve to factor 1320 * @param input point on the curve to factor
1306 * @return `dlc->max` if dlog failed, otherwise the factor 1321 * @return `dlc->max` if dlog failed, otherwise the factor
@@ -1314,10 +1329,10 @@ GNUNET_CRYPTO_ecc_dlog (struct GNUNET_CRYPTO_EccDlogContext *edc,
1314 * Multiply the generator g of the elliptic curve by @a val 1329 * Multiply the generator g of the elliptic curve by @a val
1315 * to obtain the point on the curve representing @a val. 1330 * to obtain the point on the curve representing @a val.
1316 * Afterwards, point addition will correspond to integer 1331 * Afterwards, point addition will correspond to integer
1317 * addition. #GNUNET_CRYPTO_ecc_dlog() can be used to 1332 * addition. #GNUNET_CRYPTO_ecc_dlog() can be used to
1318 * convert a point back to an integer (as long as the 1333 * convert a point back to an integer (as long as the
1319 * integer is smaller than the MAX of the @a edc context). 1334 * integer is smaller than the MAX of the @a edc context).
1320 * 1335 *
1321 * @param edc calculation context for ECC operations 1336 * @param edc calculation context for ECC operations
1322 * @param val value to encode into a point 1337 * @param val value to encode into a point
1323 * @return representation of the value as an ECC point, 1338 * @return representation of the value as an ECC point,
@@ -1331,7 +1346,7 @@ GNUNET_CRYPTO_ecc_dexp (struct GNUNET_CRYPTO_EccDlogContext *edc,
1331/** 1346/**
1332 * Multiply the generator g of the elliptic curve by @a val 1347 * Multiply the generator g of the elliptic curve by @a val
1333 * to obtain the point on the curve representing @a val. 1348 * to obtain the point on the curve representing @a val.
1334 * 1349 *
1335 * @param edc calculation context for ECC operations 1350 * @param edc calculation context for ECC operations
1336 * @param val (positive) value to encode into a point 1351 * @param val (positive) value to encode into a point
1337 * @return representation of the value as an ECC point, 1352 * @return representation of the value as an ECC point,
@@ -1343,8 +1358,33 @@ GNUNET_CRYPTO_ecc_dexp_mpi (struct GNUNET_CRYPTO_EccDlogContext *edc,
1343 1358
1344 1359
1345/** 1360/**
1361 * Convert point value to binary representation.
1362 *
1363 * @param edc calculation context for ECC operations
1364 * @param point computational point representation
1365 * @param[out] bin binary point representation
1366 */
1367void
1368GNUNET_CRYPTO_ecc_point_to_bin (struct GNUNET_CRYPTO_EccDlogContext *edc,
1369 gcry_mpi_point_t point,
1370 struct GNUNET_CRYPTO_EccPoint *bin);
1371
1372
1373/**
1374 * Convert binary representation of a point to computational representation.
1375 *
1376 * @param edc calculation context for ECC operations
1377 * @param bin binary point representation
1378 * @return computational representation
1379 */
1380gcry_mpi_point_t
1381GNUNET_CRYPTO_ecc_bin_to_point (struct GNUNET_CRYPTO_EccDlogContext *edc,
1382 const struct GNUNET_CRYPTO_EccPoint *bin);
1383
1384
1385/**
1346 * Add two points on the elliptic curve. 1386 * Add two points on the elliptic curve.
1347 * 1387 *
1348 * @param edc calculation context for ECC operations 1388 * @param edc calculation context for ECC operations
1349 * @param a some value 1389 * @param a some value
1350 * @param b some value 1390 * @param b some value
@@ -1360,7 +1400,7 @@ GNUNET_CRYPTO_ecc_add (struct GNUNET_CRYPTO_EccDlogContext *edc,
1360 * Obtain a random point on the curve and its 1400 * Obtain a random point on the curve and its
1361 * additive inverse. Both returned values 1401 * additive inverse. Both returned values
1362 * must be freed using #GNUNET_CRYPTO_ecc_free(). 1402 * must be freed using #GNUNET_CRYPTO_ecc_free().
1363 * 1403 *
1364 * @param edc calculation context for ECC operations 1404 * @param edc calculation context for ECC operations
1365 * @param[out] r set to a random point on the curve 1405 * @param[out] r set to a random point on the curve
1366 * @param[out] r_inv set to the additive inverse of @a r 1406 * @param[out] r_inv set to the additive inverse of @a r
@@ -1383,7 +1423,7 @@ GNUNET_CRYPTO_ecc_random_mod_n (struct GNUNET_CRYPTO_EccDlogContext *edc);
1383 1423
1384/** 1424/**
1385 * Free a point value returned by the API. 1425 * Free a point value returned by the API.
1386 * 1426 *
1387 * @param p point to free 1427 * @param p point to free
1388 */ 1428 */
1389void 1429void