gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] branch master updated (3f901571 -> 165b85dd)


From: gnunet
Subject: [taler-exchange] branch master updated (3f901571 -> 165b85dd)
Date: Thu, 29 Sep 2022 12:52:38 +0200

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

oec pushed a change to branch master
in repository exchange.

    from 3f901571 implemented reserve_open testing CMD
     new adfb7ffd added benchmark tool for age restriction
     new 165b85dd -make static, return json_null()

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/extensions/extension_age_restriction.c |  16 ++-
 src/util/bench_age_restriction.c           | 208 +++++++++++++++++++++++++++++
 src/util/do_bench_age_restriction          |   8 ++
 3 files changed, 227 insertions(+), 5 deletions(-)
 create mode 100644 src/util/bench_age_restriction.c
 create mode 100755 src/util/do_bench_age_restriction

diff --git a/src/extensions/extension_age_restriction.c 
b/src/extensions/extension_age_restriction.c
index 7937f61a..00a03841 100644
--- a/src/extensions/extension_age_restriction.c
+++ b/src/extensions/extension_age_restriction.c
@@ -131,7 +131,7 @@ TALER_age_mask_to_string (
  *
  * @param ext Pointer to the current extension
  */
-void
+static void
 age_restriction_disable (
   struct TALER_Extension *ext)
 {
@@ -282,12 +282,12 @@ age_restriction_load_json_config (
 
 
 /**
- * @brief implements the TALER_Extension.load_json_config interface.
+ * @brief implements the TALER_Extension.config_to_json interface.
  *
  * @param ext if NULL, only tests the configuration
- * @return configuration as json_t* object
+ * @return configuration as json_t* object, maybe NULL
  */
-json_t *
+static json_t *
 age_restriction_config_to_json (
   const struct TALER_Extension *ext)
 {
@@ -295,7 +295,13 @@ age_restriction_config_to_json (
   json_t *conf;
 
   GNUNET_assert (NULL != ext);
-  GNUNET_assert (NULL != ext->config);
+
+  if (NULL == ext->config)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "age restriction not configured");
+    return json_null ();
+  }
 
   if (NULL != ext->config_json)
   {
diff --git a/src/util/bench_age_restriction.c b/src/util/bench_age_restriction.c
new file mode 100644
index 00000000..abda9416
--- /dev/null
+++ b/src/util/bench_age_restriction.c
@@ -0,0 +1,208 @@
+/**
+ * @file util/bench_age_restriction.c
+ * @brief Measure Commit, Attest, Verify, Derive and Compare
+ * @author Özgür Kesim
+ *
+ * compile in exchange/src/util with
+ *
+ * gcc benc_age_restriction.c \
+ *    -lgnunetutil -lgnunetjson -lsodium -ljansson \
+ *    -L/usr/lib/x86_64-linux-gnu -lmicrohttpd -ltalerutil \
+ *    -I../include \
+ *    -o bench_age_restriction
+ *
+ */
+#include "platform.h"
+#include <math.h>
+#include <gnunet/gnunet_util_lib.h>
+#include <taler/taler_util.h>
+#include <taler/taler_crypto_lib.h>
+
+static struct TALER_AgeMask
+  age_mask = { .bits = 1
+                       | 1 << 8 | 1 << 10 | 1 << 12
+                       | 1 << 14 | 1 << 16 | 1 << 18 | 1 << 21 };
+
+extern uint8_t
+get_age_group (
+  const struct TALER_AgeMask *mask,
+  uint8_t age);
+
+/**
+ * Encodes the age mask into a string, like "8:10:12:14:16:18:21"
+ */
+char *
+age_mask_to_string (
+  const struct TALER_AgeMask *m)
+{
+  uint32_t bits = m->bits;
+  unsigned int n = 0;
+  char *buf = GNUNET_malloc (32 * 3); // max characters possible
+  char *pos = buf;
+
+  if (NULL == buf)
+  {
+    return buf;
+  }
+
+  while (bits != 0)
+  {
+    bits >>= 1;
+    n++;
+    if (0 == (bits & 1))
+    {
+      continue;
+    }
+
+    if (n > 9)
+    {
+      *(pos++) = '0' + n / 10;
+    }
+    *(pos++) = '0' + n % 10;
+
+    if (0 != (bits >> 1))
+    {
+      *(pos++) = ':';
+    }
+  }
+  return buf;
+}
+
+
+#define ITER 2000
+
+double
+average (long *times, size_t size)
+{
+  double mean = 0.0;
+  for (int i = 0; i < size; i++)
+  {
+    mean += times[i];
+  }
+  return mean / size;
+}
+
+
+double
+stdev (long *times, size_t size)
+{
+  double mean = average (times, size);
+  double V = 0.0;
+  for (int i = 0; i < size; i++)
+  {
+    double d = times[i] - mean;
+    d *= d;
+    V += d;
+  }
+  return sqrt (V / size);
+}
+
+
+#define pr(n,t, i) printf ("%10s (%dx):\t%.2f ± %.2fµs\n", (n), i, average ( \
+                             &t[0], ITER) / 1000, stdev (&t[0], ITER) / 1000); 
\
+  i = 0;
+
+#define starttime clock_gettime (CLOCK_MONOTONIC, &tstart)
+#define stoptime clock_gettime (CLOCK_MONOTONIC, &tend); \
+  times[i] = ((long) tend.tv_sec * 1000 * 1000 * 1000 + tend.tv_nsec) \
+             - ((long) tstart.tv_sec * 1000 * 1000 * 1000 + tstart.tv_nsec);
+
+
+int
+main (int argc,
+      const char *const argv[])
+{
+  struct timespec tstart = {0,0}, tend = {0,0};
+  enum GNUNET_GenericReturnValue ret;
+  struct TALER_AgeCommitmentProof acp = {0};
+  uint8_t age = 21;
+  uint8_t age_group = get_age_group (&age_mask, age);
+  struct GNUNET_HashCode seed;
+  long times[ITER] = {0};
+  int i = 0;
+
+  //  commit
+  for (; i < ITER; i++)
+  {
+    starttime;
+    GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+                                &seed,
+                                sizeof(seed));
+
+    ret = TALER_age_restriction_commit (&age_mask,
+                                        age,
+                                        &seed,
+                                        &acp);
+    stoptime;
+
+  }
+  pr ("commit", times, i);
+
+  // attest
+  for (; i < ITER; i++)
+  {
+    GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+                                &seed,
+                                sizeof(seed));
+
+    ret = TALER_age_restriction_commit (&age_mask,
+                                        age,
+                                        &seed,
+                                        &acp);
+
+    starttime;
+    uint8_t min_group = get_age_group (&age_mask, 13);
+    struct TALER_AgeAttestation at = {0};
+    ret = TALER_age_commitment_attest (&acp,
+                                       13,
+                                       &at);
+    stoptime;
+  }
+  pr ("attest", times, i);
+
+  // verify
+  for (; i < ITER; i++)
+  {
+    GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+                                &seed,
+                                sizeof(seed));
+
+    ret = TALER_age_restriction_commit (&age_mask,
+                                        age,
+                                        &seed,
+                                        &acp);
+
+    uint8_t min_group = get_age_group (&age_mask, 13);
+    struct TALER_AgeAttestation at = {0};
+
+    ret = TALER_age_commitment_attest (&acp,
+                                       13,
+                                       &at);
+    starttime;
+    ret = TALER_age_commitment_verify (&acp.commitment,
+                                       13,
+                                       &at);
+    stoptime;
+  }
+  pr ("verify", times, i);
+
+  // derive
+  for (; i < ITER; i++)
+  {
+    struct TALER_AgeCommitmentProof acp2 = {0};
+    GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+                                &seed,
+                                sizeof(seed));
+    starttime;
+    TALER_age_commitment_derive (&acp,
+                                 &seed,
+                                 &acp2);
+    stoptime;
+  }
+  pr ("derive", times, i);
+
+  return 0;
+}
+
+
+/* end of tv_age_restriction.c */
diff --git a/src/util/do_bench_age_restriction 
b/src/util/do_bench_age_restriction
new file mode 100755
index 00000000..a6571343
--- /dev/null
+++ b/src/util/do_bench_age_restriction
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+gcc bench_age_restriction.c \
+   -lgnunetutil -lgnunetjson -lsodium -ljansson \
+   -L/usr/lib/x86_64-linux-gnu -lmicrohttpd -ltalerutil -lm \
+   -I../include \
+   -o bench_age_restriction && ./bench_age_restriction
+

-- 
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]