aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2024-03-01 10:14:44 +0100
committerMartin Schanzenbach <schanzen@gnunet.org>2024-03-01 10:14:44 +0100
commitabb648177bd5ecbcf8c0c6ce9be353a43fbf5b76 (patch)
tree4d388fd40a35dae63eae0871183b53ea9c8fe7f8 /src
parentea8995bfdb78dc77e4c896360f54a8093860c424 (diff)
downloadgnunet-abb648177bd5ecbcf8c0c6ce9be353a43fbf5b76.tar.gz
gnunet-abb648177bd5ecbcf8c0c6ce9be353a43fbf5b76.zip
crypto: fix elligator warnings
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_crypto_lib.h99
-rw-r--r--src/lib/util/crypto_elligator.c11
-rw-r--r--src/lib/util/test_crypto_elligator.c13
3 files changed, 53 insertions, 70 deletions
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index 5425a18dd..4580f795d 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -973,7 +973,7 @@ GNUNET_CRYPTO_hash_from_string2 (const char *enc,
973 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding 973 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding
974 */ 974 */
975#define GNUNET_CRYPTO_hash_from_string(enc, result) \ 975#define GNUNET_CRYPTO_hash_from_string(enc, result) \
976 GNUNET_CRYPTO_hash_from_string2 (enc, strlen (enc), result) 976 GNUNET_CRYPTO_hash_from_string2 (enc, strlen (enc), result)
977 977
978 978
979/** 979/**
@@ -2215,15 +2215,15 @@ GNUNET_CRYPTO_eddsa_sign_ (
2215 * @param[out] sig where to write the signature 2215 * @param[out] sig where to write the signature
2216 */ 2216 */
2217#define GNUNET_CRYPTO_eddsa_sign(priv,ps,sig) do { \ 2217#define GNUNET_CRYPTO_eddsa_sign(priv,ps,sig) do { \
2218 /* check size is set correctly */ \ 2218 /* check size is set correctly */ \
2219 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*ps)); \ 2219 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*ps)); \
2220 /* check 'ps' begins with the purpose */ \ 2220 /* check 'ps' begins with the purpose */ \
2221 GNUNET_static_assert (((void*) (ps)) == \ 2221 GNUNET_static_assert (((void*) (ps)) == \
2222 ((void*) &(ps)->purpose)); \ 2222 ((void*) &(ps)->purpose)); \
2223 GNUNET_assert (GNUNET_OK == \ 2223 GNUNET_assert (GNUNET_OK == \
2224 GNUNET_CRYPTO_eddsa_sign_ (priv, \ 2224 GNUNET_CRYPTO_eddsa_sign_ (priv, \
2225 &(ps)->purpose, \ 2225 &(ps)->purpose, \
2226 sig)); \ 2226 sig)); \
2227} while (0) 2227} while (0)
2228 2228
2229 2229
@@ -2277,15 +2277,15 @@ GNUNET_CRYPTO_eddsa_sign_raw (
2277 * @param[out] sig where to write the signature 2277 * @param[out] sig where to write the signature
2278 */ 2278 */
2279#define GNUNET_CRYPTO_ecdsa_sign(priv,ps,sig) do { \ 2279#define GNUNET_CRYPTO_ecdsa_sign(priv,ps,sig) do { \
2280 /* check size is set correctly */ \ 2280 /* check size is set correctly */ \
2281 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \ 2281 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
2282 /* check 'ps' begins with the purpose */ \ 2282 /* check 'ps' begins with the purpose */ \
2283 GNUNET_static_assert (((void*) (ps)) == \ 2283 GNUNET_static_assert (((void*) (ps)) == \
2284 ((void*) &(ps)->purpose)); \ 2284 ((void*) &(ps)->purpose)); \
2285 GNUNET_assert (GNUNET_OK == \ 2285 GNUNET_assert (GNUNET_OK == \
2286 GNUNET_CRYPTO_ecdsa_sign_ (priv, \ 2286 GNUNET_CRYPTO_ecdsa_sign_ (priv, \
2287 &(ps)->purpose, \ 2287 &(ps)->purpose, \
2288 sig)); \ 2288 sig)); \
2289} while (0) 2289} while (0)
2290 2290
2291/** 2291/**
@@ -2324,15 +2324,15 @@ GNUNET_CRYPTO_edx25519_sign_ (
2324 * @param[out] sig where to write the signature 2324 * @param[out] sig where to write the signature
2325 */ 2325 */
2326#define GNUNET_CRYPTO_edx25519_sign(priv,ps,sig) do { \ 2326#define GNUNET_CRYPTO_edx25519_sign(priv,ps,sig) do { \
2327 /* check size is set correctly */ \ 2327 /* check size is set correctly */ \
2328 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \ 2328 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
2329 /* check 'ps' begins with the purpose */ \ 2329 /* check 'ps' begins with the purpose */ \
2330 GNUNET_static_assert (((void*) (ps)) == \ 2330 GNUNET_static_assert (((void*) (ps)) == \
2331 ((void*) &(ps)->purpose)); \ 2331 ((void*) &(ps)->purpose)); \
2332 GNUNET_assert (GNUNET_OK == \ 2332 GNUNET_assert (GNUNET_OK == \
2333 GNUNET_CRYPTO_edx25519_sign_ (priv, \ 2333 GNUNET_CRYPTO_edx25519_sign_ (priv, \
2334 &(ps)->purpose, \ 2334 &(ps)->purpose, \
2335 sig)); \ 2335 sig)); \
2336} while (0) 2336} while (0)
2337 2337
2338 2338
@@ -2726,13 +2726,13 @@ GNUNET_CRYPTO_ecdhe_elligator_initialize (void);
2726 * @param pk private key for generating valid public key 2726 * @param pk private key for generating valid public key
2727 */ 2727 */
2728int 2728int
2729 GNUNET_CRYPTO_ecdhe_elligator_generate_public_key (unsigned char 2729GNUNET_CRYPTO_ecdhe_elligator_generate_public_key (unsigned char
2730 pub[ 2730 pub[
2731 crypto_scalarmult_SCALARBYTES 2731 crypto_scalarmult_SCALARBYTES
2732 ], 2732 ],
2733 struct 2733 struct
2734 GNUNET_CRYPTO_EcdhePrivateKey 2734 GNUNET_CRYPTO_EcdhePrivateKey
2735 *pk); 2735 *pk);
2736 2736
2737 2737
2738/** 2738/**
@@ -2741,13 +2741,12 @@ int
2741 * 2741 *
2742 * @param repr representative of the public key 2742 * @param repr representative of the public key
2743 * @param pk Curve25519 private key 2743 * @param pk Curve25519 private key
2744 * @return GNUNET_OK if creation successful
2744 */ 2745 */
2745int 2746enum GNUNET_GenericReturnValue
2746GNUNET_CRYPTO_ecdhe_elligator_key_create (struct 2747GNUNET_CRYPTO_ecdhe_elligator_key_create (
2747 GNUNET_CRYPTO_ElligatorRepresentative 2748 struct GNUNET_CRYPTO_ElligatorRepresentative *repr,
2748 *repr, 2749 struct GNUNET_CRYPTO_EcdhePrivateKey *pk);
2749 struct GNUNET_CRYPTO_EcdhePrivateKey
2750 *pk);
2751 2750
2752 2751
2753/** 2752/**
@@ -4233,15 +4232,15 @@ GNUNET_CRYPTO_sign_raw_ (
4233 * @param[out] sig where to write the signature 4232 * @param[out] sig where to write the signature
4234 */ 4233 */
4235#define GNUNET_CRYPTO_sign(priv,ps,sig) do { \ 4234#define GNUNET_CRYPTO_sign(priv,ps,sig) do { \
4236 /* check size is set correctly */ \ 4235 /* check size is set correctly */ \
4237 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \ 4236 GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \
4238 /* check 'ps' begins with the purpose */ \ 4237 /* check 'ps' begins with the purpose */ \
4239 GNUNET_static_assert (((void*) (ps)) == \ 4238 GNUNET_static_assert (((void*) (ps)) == \
4240 ((void*) &(ps)->purpose)); \ 4239 ((void*) &(ps)->purpose)); \
4241 GNUNET_assert (GNUNET_OK == \ 4240 GNUNET_assert (GNUNET_OK == \
4242 GNUNET_CRYPTO_sign_ (priv, \ 4241 GNUNET_CRYPTO_sign_ (priv, \
4243 &(ps)->purpose, \ 4242 &(ps)->purpose, \
4244 sig)); \ 4243 sig)); \
4245} while (0) 4244} while (0)
4246 4245
4247 4246
diff --git a/src/lib/util/crypto_elligator.c b/src/lib/util/crypto_elligator.c
index 142c0782a..e512696a7 100644
--- a/src/lib/util/crypto_elligator.c
+++ b/src/lib/util/crypto_elligator.c
@@ -648,12 +648,9 @@ GNUNET_CRYPTO_ecdhe_elligator_generate_public_key_alternativ (unsigned char
648**/ 648**/
649 649
650enum GNUNET_GenericReturnValue 650enum GNUNET_GenericReturnValue
651GNUNET_CRYPTO_ecdhe_elligator_key_create (struct 651GNUNET_CRYPTO_ecdhe_elligator_key_create (
652 GNUNET_CRYPTO_ElligatorRepresentative 652 struct GNUNET_CRYPTO_ElligatorRepresentative *repr,
653 * 653 struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
654 repr,
655 struct GNUNET_CRYPTO_EcdhePrivateKey
656 *pk)
657{ 654{
658 // inverse map can fail for some public keys generated by GNUNET_CRYPTO_ecdhe_elligator_generate_public_key 655 // inverse map can fail for some public keys generated by GNUNET_CRYPTO_ecdhe_elligator_generate_public_key
659 bool validKey = 0; 656 bool validKey = 0;
@@ -699,4 +696,4 @@ GNUNET_CRYPTO_ecdhe_elligator_key_create (struct
699 repr->r[31] |= 64; 696 repr->r[31] |= 64;
700 } 697 }
701 return GNUNET_OK; 698 return GNUNET_OK;
702} \ No newline at end of file 699}
diff --git a/src/lib/util/test_crypto_elligator.c b/src/lib/util/test_crypto_elligator.c
index fc541887d..488a296d6 100644
--- a/src/lib/util/test_crypto_elligator.c
+++ b/src/lib/util/test_crypto_elligator.c
@@ -1,23 +1,10 @@
1#include "platform.h"
2#include "gnunet_util_lib.h" 1#include "gnunet_util_lib.h"
3#include "gnunet_signatures.h"
4#include <gcrypt.h> 2#include <gcrypt.h>
5#include <stdio.h> 3#include <stdio.h>
6#include <sodium.h> 4#include <sodium.h>
7 5
8#define ITER 25 6#define ITER 25
9 7
10// For debugging purposes
11static void
12printLittleEndianHex (const unsigned char *arr, size_t length)
13{
14 for (size_t i = 0; i < length; ++i)
15 {
16 printf ("%02X", arr[i]);
17 }
18 printf ("\n");
19}
20
21 8
22// Test vector from https://github.com/Kleshni/Elligator-2/blob/master/test-vectors.c 9// Test vector from https://github.com/Kleshni/Elligator-2/blob/master/test-vectors.c
23static int 10static int