gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] branch master updated: -clean up test a bit


From: gnunet
Subject: [gnunet] branch master updated: -clean up test a bit
Date: Wed, 09 Feb 2022 09:56:14 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 5ace56b96 -clean up test a bit
5ace56b96 is described below

commit 5ace56b96850dafc157839e6fb3795103f1bfc71
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Wed Feb 9 09:41:55 2022 +0100

    -clean up test a bit
---
 src/util/test_crypto_cs.c | 283 ++++++++++++++++++++++++++--------------------
 1 file changed, 159 insertions(+), 124 deletions(-)

diff --git a/src/util/test_crypto_cs.c b/src/util/test_crypto_cs.c
index d3406516e..f7ac10982 100644
--- a/src/util/test_crypto_cs.c
+++ b/src/util/test_crypto_cs.c
@@ -1,6 +1,6 @@
 /*
    This file is part of GNUnet
-   Copyright (C) 2014,2015 GNUnet e.V.
+   Copyright (C) 2021,2022 GNUnet e.V.
 
    GNUnet is free software: you can redistribute it and/or modify it
    under the terms of the GNU Affero General Public License as published
@@ -30,148 +30,166 @@
 
 #define ITER 25
 
-void
+static void
 test_create_priv (struct GNUNET_CRYPTO_CsPrivateKey *priv)
 {
   /* TEST 1
    * Check that privkey is set
    */
   struct GNUNET_CRYPTO_CsPrivateKey other_priv;
-  memcpy (&other_priv.scalar, &priv->scalar, sizeof(other_priv.scalar));
 
+  other_priv = *priv;
   GNUNET_CRYPTO_cs_private_key_generate (priv);
-
-  GNUNET_assert (0 != memcmp (&other_priv.scalar,
-                              &priv->scalar,
-                              sizeof(other_priv.scalar)));
+  GNUNET_assert (0 !=
+                 GNUNET_memcmp (&other_priv.scalar,
+                                &priv->scalar));
 }
 
 
-void
+static void
 test_generate_pub (const struct GNUNET_CRYPTO_CsPrivateKey *priv,
-                       struct GNUNET_CRYPTO_CsPublicKey *pub)
+                   struct GNUNET_CRYPTO_CsPublicKey *pub)
 {
   /* TEST 1
    * Check that pubkey is set
    */
   struct GNUNET_CRYPTO_CsPublicKey other_pub;
-  memcpy (&other_pub.point, &pub->point, sizeof(other_pub.point));
-
-  GNUNET_CRYPTO_cs_private_key_get_public (priv, pub);
 
-  GNUNET_assert (0 != memcmp (&other_pub.point,
-                              &pub->point,
-                              sizeof(other_pub.point)));
+  other_pub = *pub;
+  GNUNET_CRYPTO_cs_private_key_get_public (priv,
+                                           pub);
+  GNUNET_assert (0 !=
+                 GNUNET_memcmp (&other_pub.point,
+                                &pub->point));
 
   /* TEST 2
    * Check that pubkey is a valid point
    */
-  GNUNET_assert (1 == crypto_core_ed25519_is_valid_point (pub->point.y));
+  GNUNET_assert (1 ==
+                 crypto_core_ed25519_is_valid_point (pub->point.y));
 
   /* TEST 3
    * Check if function gives the same result for the same output
    */
-  memcpy (&other_pub.point, &pub->point, sizeof(other_pub.point));
-
-  for (int i = 0; i<ITER; i++) {
-    GNUNET_CRYPTO_cs_private_key_get_public (priv, pub);
-    GNUNET_assert (0 == memcmp (&other_pub.point,
-                                &pub->point,
-                                sizeof(other_pub.point)));
+  other_pub = *pub;
+  for (unsigned int i = 0; i<ITER; i++)
+  {
+    GNUNET_CRYPTO_cs_private_key_get_public (priv,
+                                             pub);
+    GNUNET_assert (0 ==
+                   GNUNET_memcmp (&other_pub.point,
+                                  &pub->point));
   }
 }
 
 
-void
+static void
 test_derive_rsecret (const struct GNUNET_CRYPTO_CsNonce *nonce,
-                   const struct GNUNET_CRYPTO_CsPrivateKey *priv,
-                   struct GNUNET_CRYPTO_CsRSecret r[2])
+                     const struct GNUNET_CRYPTO_CsPrivateKey *priv,
+                     struct GNUNET_CRYPTO_CsRSecret r[2])
 {
   /* TEST 1
    * Check that r are set
    */
   struct GNUNET_CRYPTO_CsPrivateKey other_r[2];
-  memcpy (&other_r[0], &r[0], sizeof(struct GNUNET_CRYPTO_CsPrivateKey) * 2);
 
-  GNUNET_CRYPTO_cs_r_derive (nonce, priv, r);
-
-  GNUNET_assert (0 != memcmp (&other_r[0],
-                              &r[0],
-                              sizeof(struct GNUNET_CRYPTO_CsPrivateKey) * 2));
+  memcpy (other_r,
+          r,
+          sizeof(struct GNUNET_CRYPTO_CsPrivateKey) * 2);
+  GNUNET_CRYPTO_cs_r_derive (nonce,
+                             priv,
+                             r);
+  GNUNET_assert (0 !=
+                 memcmp (&other_r[0],
+                         &r[0],
+                         sizeof(struct GNUNET_CRYPTO_CsPrivateKey) * 2));
 
   /* TEST 2
    * Check if function gives the same result for the same input.
    * This test ensures that the derivation is deterministic.
    */
-  memcpy (&other_r[0], &r[0], sizeof(struct GNUNET_CRYPTO_CsPrivateKey) * 2);
-  for (int i = 0; i<ITER; i++) {
-    GNUNET_CRYPTO_cs_r_derive (nonce, priv, r);
-    GNUNET_assert (0 == memcmp (&other_r[0],
-                                &r[0],
-                                sizeof(struct GNUNET_CRYPTO_CsPrivateKey) * 
2));
+  memcpy (other_r,
+          r,
+          sizeof(struct GNUNET_CRYPTO_CsPrivateKey) * 2);
+  for (unsigned int i = 0; i<ITER; i++)
+  {
+    GNUNET_CRYPTO_cs_r_derive (nonce,
+                               priv,
+                               r);
+    GNUNET_assert (0 ==
+                   memcmp (other_r,
+                           r,
+                           sizeof(struct GNUNET_CRYPTO_CsPrivateKey) * 2));
   }
 }
 
 
-void
+static void
 test_generate_rpublic (const struct GNUNET_CRYPTO_CsRSecret *r_priv,
-                     struct GNUNET_CRYPTO_CsRPublic *r_pub)
+                       struct GNUNET_CRYPTO_CsRPublic *r_pub)
 {
   /* TEST 1
    * Check that r_pub is set
    */
   struct GNUNET_CRYPTO_CsRPublic other_r_pub;
-  memcpy (&other_r_pub.point, &r_pub->point, sizeof(other_r_pub.point));
-
-  GNUNET_CRYPTO_cs_r_get_public (r_priv, r_pub);
-
-  GNUNET_assert (0 != memcmp (&other_r_pub.point,
-                              &r_pub->point,
-                              sizeof(other_r_pub.point)));
 
+  other_r_pub = *r_pub;
+  GNUNET_CRYPTO_cs_r_get_public (r_priv,
+                                 r_pub);
+  GNUNET_assert (0 !=
+                 GNUNET_memcmp (&other_r_pub.point,
+                                &r_pub->point));
   /* TEST 2
    * Check that r_pub is a valid point
    */
-  GNUNET_assert (1 == crypto_core_ed25519_is_valid_point (r_pub->point.y));
+  GNUNET_assert (1 ==
+                 crypto_core_ed25519_is_valid_point (r_pub->point.y));
 
   /* TEST 3
    * Check if function gives the same result for the same output
    */
-  memcpy (&other_r_pub.point, &r_pub->point, sizeof(other_r_pub.point));
-  for (int i = 0; i<ITER; i++) {
-    GNUNET_CRYPTO_cs_r_get_public (r_priv, r_pub);
-    GNUNET_assert (0 == memcmp (&other_r_pub.point,
-                                &r_pub->point,
-                                sizeof(other_r_pub.point)));
+  other_r_pub.point = r_pub->point;
+  for (int i = 0; i<ITER; i++)
+  {
+    GNUNET_CRYPTO_cs_r_get_public (r_priv,
+                                   r_pub);
+    GNUNET_assert (0 ==
+                   GNUNET_memcmp (&other_r_pub.point,
+                                  &r_pub->point));
   }
 }
 
 
-void
+static void
 test_derive_blindingsecrets (const struct GNUNET_CRYPTO_CsNonce *blind_seed,
-                           struct GNUNET_CRYPTO_CsBlindingSecret bs[2])
+                             struct GNUNET_CRYPTO_CsBlindingSecret bs[2])
 {
   /* TEST 1
    * Check that blinding secrets are set
    */
   struct GNUNET_CRYPTO_CsBlindingSecret other_bs[2];
-  memcpy (&other_bs[0], &bs[0], sizeof(struct GNUNET_CRYPTO_CsBlindingSecret)
-          * 2);
+
+  memcpy (other_bs,
+          bs,
+          sizeof(struct GNUNET_CRYPTO_CsBlindingSecret) * 2);
 
   GNUNET_CRYPTO_cs_blinding_secrets_derive (blind_seed, bs);
 
-  GNUNET_assert (0 != memcmp (&other_bs[0],
-                              &bs[0],
-                              sizeof(struct GNUNET_CRYPTO_CsBlindingSecret)
-                              * 2));
+  GNUNET_assert (0 !=
+                 memcmp (other_bs,
+                         bs,
+                         sizeof(struct GNUNET_CRYPTO_CsBlindingSecret)
+                         * 2));
 
   /* TEST 2
    * Check if function gives the same result for the same input.
    * This test ensures that the derivation is deterministic.
    */
-  memcpy (&other_bs[0], &bs[0], sizeof(struct GNUNET_CRYPTO_CsBlindingSecret)
-          * 2);
-  for (int i = 0; i<ITER; i++) {
+  memcpy (other_bs,
+          bs,
+          sizeof(struct GNUNET_CRYPTO_CsBlindingSecret) * 2);
+  for (unsigned int i = 0; i<ITER; i++)
+  {
     GNUNET_CRYPTO_cs_blinding_secrets_derive (blind_seed, bs);
     GNUNET_assert (0 == memcmp (&other_bs[0],
                                 &bs[0],
@@ -181,19 +199,20 @@ test_derive_blindingsecrets (const struct 
GNUNET_CRYPTO_CsNonce *blind_seed,
 }
 
 
-void
+static void
 test_calc_blindedc (const struct GNUNET_CRYPTO_CsBlindingSecret bs[2],
-                  const struct GNUNET_CRYPTO_CsRPublic r_pub[2],
-                  const struct GNUNET_CRYPTO_CsPublicKey *pub,
-                  const void *msg,
-                  size_t msg_len,
-                  struct GNUNET_CRYPTO_CsC blinded_cs[2],
-                  struct GNUNET_CRYPTO_CsRPublic blinded_r_pub[2])
+                    const struct GNUNET_CRYPTO_CsRPublic r_pub[2],
+                    const struct GNUNET_CRYPTO_CsPublicKey *pub,
+                    const void *msg,
+                    size_t msg_len,
+                    struct GNUNET_CRYPTO_CsC blinded_cs[2],
+                    struct GNUNET_CRYPTO_CsRPublic blinded_r_pub[2])
 {
   /* TEST 1
    * Check that the blinded c's and blinded r's
    */
   struct GNUNET_CRYPTO_CsC other_blinded_c[2];
+
   memcpy (&other_blinded_c[0],
           &blinded_cs[0],
           sizeof(struct GNUNET_CRYPTO_CsC) * 2);
@@ -222,7 +241,8 @@ test_calc_blindedc (const struct 
GNUNET_CRYPTO_CsBlindingSecret bs[2],
    * Check if R' - aG -bX = R for b = 0
    * This test does the opposite operations and checks wether the equation is 
still correct.
    */
-  for (unsigned int b = 0; b <= 1; b++) {
+  for (unsigned int b = 0; b <= 1; b++)
+  {
     struct GNUNET_CRYPTO_Cs25519Point aG;
     struct GNUNET_CRYPTO_Cs25519Point bX;
     struct GNUNET_CRYPTO_Cs25519Point r_min_aG;
@@ -252,7 +272,6 @@ test_calc_blindedc (const struct 
GNUNET_CRYPTO_CsBlindingSecret bs[2],
   }
 
 
-
   /* TEST 3
    * Check that the blinded r_pubs' are valid points
    */
@@ -271,7 +290,8 @@ test_calc_blindedc (const struct 
GNUNET_CRYPTO_CsBlindingSecret bs[2],
           &blinded_r_pub[0],
           sizeof(struct GNUNET_CRYPTO_CsRPublic) * 2);
 
-  for (int i = 0; i<ITER; i++) {
+  for (unsigned int i = 0; i<ITER; i++)
+  {
     GNUNET_CRYPTO_cs_calc_blinded_c (bs,
                                      r_pub,
                                      pub,
@@ -289,13 +309,13 @@ test_calc_blindedc (const struct 
GNUNET_CRYPTO_CsBlindingSecret bs[2],
 }
 
 
-void
+static void
 test_blind_sign (unsigned int *b,
-               const struct GNUNET_CRYPTO_CsPrivateKey *priv,
-               const struct GNUNET_CRYPTO_CsRSecret r[2],
-               const struct GNUNET_CRYPTO_CsC c[2],
-               const struct GNUNET_CRYPTO_CsNonce *nonce,
-               struct GNUNET_CRYPTO_CsBlindS *blinded_s)
+                 const struct GNUNET_CRYPTO_CsPrivateKey *priv,
+                 const struct GNUNET_CRYPTO_CsRSecret r[2],
+                 const struct GNUNET_CRYPTO_CsC c[2],
+                 const struct GNUNET_CRYPTO_CsNonce *nonce,
+                 struct GNUNET_CRYPTO_CsBlindS *blinded_s)
 {
   /* TEST 1
    * Check that blinded_s is set
@@ -336,8 +356,10 @@ test_blind_sign (unsigned int *b,
    * Check if function gives the same result for the same input.
    */
   memcpy (&other_blinded_s, blinded_s, sizeof(struct GNUNET_CRYPTO_CsBlindS));
-  unsigned int other_b;
-  for (int i = 0; i<ITER; i++) {
+  for (unsigned int i = 0; i<ITER; i++)
+  {
+    unsigned int other_b;
+
     other_b = GNUNET_CRYPTO_cs_sign_derive (priv, r, c, nonce, blinded_s);
 
     GNUNET_assert (other_b == *b);
@@ -348,10 +370,10 @@ test_blind_sign (unsigned int *b,
 }
 
 
-void
+static void
 test_unblinds (const struct GNUNET_CRYPTO_CsBlindS *blinded_signature_scalar,
-              const struct GNUNET_CRYPTO_CsBlindingSecret *bs,
-              struct GNUNET_CRYPTO_CsS *signature_scalar)
+               const struct GNUNET_CRYPTO_CsBlindingSecret *bs,
+               struct GNUNET_CRYPTO_CsS *signature_scalar)
 {
   /* TEST 1
    * Check that signature_scalar is set
@@ -387,7 +409,8 @@ test_unblinds (const struct GNUNET_CRYPTO_CsBlindS 
*blinded_signature_scalar,
   memcpy (&other_signature_scalar, signature_scalar,
           sizeof(struct GNUNET_CRYPTO_CsS));
 
-  for (int i = 0; i<ITER; i++) {
+  for (unsigned int i = 0; i<ITER; i++)
+  {
     GNUNET_CRYPTO_cs_unblind (blinded_signature_scalar, bs, signature_scalar);
     GNUNET_assert (0 == memcmp (&other_signature_scalar,
                                 signature_scalar,
@@ -396,10 +419,10 @@ test_unblinds (const struct GNUNET_CRYPTO_CsBlindS 
*blinded_signature_scalar,
 }
 
 
-void
+static void
 test_blind_verify (const struct GNUNET_CRYPTO_CsSignature *sig,
-                 const struct GNUNET_CRYPTO_CsPublicKey *pub,
-                 const struct GNUNET_CRYPTO_CsC *c)
+                   const struct GNUNET_CRYPTO_CsPublicKey *pub,
+                   const struct GNUNET_CRYPTO_CsC *c)
 {
   /* TEST 1
    * Test verifies the blinded signature sG == Rb + cbX
@@ -425,28 +448,30 @@ test_blind_verify (const struct GNUNET_CRYPTO_CsSignature 
*sig,
 }
 
 
-void
+static void
 test_verify (const struct GNUNET_CRYPTO_CsSignature *sig,
-            const struct GNUNET_CRYPTO_CsPublicKey *pub,
-            const void *msg,
-            size_t msg_len)
+             const struct GNUNET_CRYPTO_CsPublicKey *pub,
+             const void *msg,
+             size_t msg_len)
 {
   /* TEST 1
    * Test simple verification
    */
-  GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_cs_verify (sig,
-                                                        pub,
-                                                        msg,
-                                                        msg_len));
+  GNUNET_assert (GNUNET_YES ==
+                 GNUNET_CRYPTO_cs_verify (sig,
+                                          pub,
+                                          msg,
+                                          msg_len));
   /* TEST 2
    * Test verification of "wrong" message
    */
   char other_msg[] = "test massege";
   size_t other_msg_len = strlen ("test massege");
-  GNUNET_assert (GNUNET_SYSERR == GNUNET_CRYPTO_cs_verify (sig,
-                                                       pub,
-                                                       other_msg,
-                                                       other_msg_len));
+  GNUNET_assert (GNUNET_SYSERR ==
+                 GNUNET_CRYPTO_cs_verify (sig,
+                                          pub,
+                                          other_msg,
+                                          other_msg_len));
 }
 
 
@@ -468,16 +493,15 @@ main (int argc,
 
   // derive nonce
   struct GNUNET_CRYPTO_CsNonce nonce;
-  GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_hkdf (nonce.nonce,
-                                                   sizeof(nonce.nonce),
-                                                   GCRY_MD_SHA512,
-                                                   GCRY_MD_SHA256,
-                                                   "nonce",
-                                                   strlen ("nonce"),
-                                                   "nonce_secret",
-                                                   strlen ("nonce_secret"),
-                                                   NULL,
-                                                   0));
+  GNUNET_assert (GNUNET_YES ==
+                 GNUNET_CRYPTO_kdf (nonce.nonce,
+                                    sizeof(nonce.nonce),
+                                    "nonce",
+                                    strlen ("nonce"),
+                                    "nonce_secret",
+                                    strlen ("nonce_secret"),
+                                    NULL,
+                                    0));
 
   // generate r, R
   struct GNUNET_CRYPTO_CsRSecret r_secrets[2];
@@ -498,34 +522,45 @@ main (int argc,
   struct GNUNET_CRYPTO_CsC blinded_cs[2];
   struct GNUNET_CRYPTO_CsRPublic blinded_r_pubs[2];
   test_calc_blindedc (blindingsecrets,
-                    r_publics,
-                    &pub,
-                    message,
-                    message_len,
-                    blinded_cs,
-                    blinded_r_pubs);
+                      r_publics,
+                      &pub,
+                      message,
+                      message_len,
+                      blinded_cs,
+                      blinded_r_pubs);
 
   // ---------- actions performed by signer
   // sign blinded c's and get b and s in return
   unsigned int b;
   struct GNUNET_CRYPTO_CsBlindS blinded_s;
-  test_blind_sign (&b, &priv, r_secrets, blinded_cs, &nonce, &blinded_s);
+  test_blind_sign (&b,
+                   &priv,
+                   r_secrets,
+                   blinded_cs,
+                   &nonce,
+                   &blinded_s);
 
   // verify blinded signature
   struct GNUNET_CRYPTO_CsSignature blinded_signature;
   blinded_signature.r_point = r_publics[b];
   blinded_signature.s_scalar.scalar = blinded_s.scalar;
-  test_blind_verify (&blinded_signature, &pub, &blinded_cs[b]);
+  test_blind_verify (&blinded_signature,
+                     &pub,
+                     &blinded_cs[b]);
 
   // ---------- actions performed by user
-    struct GNUNET_CRYPTO_CsS sig_scalar;
-  test_unblinds (&blinded_s, &blindingsecrets[b], &sig_scalar);
+  struct GNUNET_CRYPTO_CsS sig_scalar;
+  test_unblinds (&blinded_s,
+                 &blindingsecrets[b],
+                 &sig_scalar);
 
   // verify unblinded signature
   struct GNUNET_CRYPTO_CsSignature signature;
   signature.r_point = blinded_r_pubs[b];
   signature.s_scalar = sig_scalar;
-  test_verify (&signature, &pub, message, message_len);
-
+  test_verify (&signature,
+               &pub,
+               message,
+               message_len);
   return 0;
 }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]