gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] branch master updated: totp update function


From: gnunet
Subject: [taler-exchange] branch master updated: totp update function
Date: Fri, 03 Mar 2023 11:20:54 +0100

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

priscilla-huang pushed a commit to branch master
in repository exchange.

The following commit(s) were added to refs/heads/master by this push:
     new 263ebf00 totp update function
263ebf00 is described below

commit 263ebf00fc5bde274ac76c99b2cd3bd8a63811ed
Author: priscilla <priscilla.huang@efrei.net>
AuthorDate: Fri Mar 3 05:20:40 2023 -0500

    totp update function
---
 src/util/crypto_confirmation.c | 100 +++++++++++++++++++----------------------
 1 file changed, 46 insertions(+), 54 deletions(-)

diff --git a/src/util/crypto_confirmation.c b/src/util/crypto_confirmation.c
index e47a61a6..6c6b7fb4 100644
--- a/src/util/crypto_confirmation.c
+++ b/src/util/crypto_confirmation.c
@@ -168,6 +168,44 @@ base32decode (const char *val,
 }
 
 
+static char *
+executive_totp (void *h_key,
+                size_t h_key_len,
+                struct GNUNET_TIME_Timestamp ts)
+{
+  uint64_t code; /* totp code */
+  char *ret;
+  ret = NULL;
+
+  for (int i = -TIME_INTERVAL_RANGE; i<= TIME_INTERVAL_RANGE; i++)
+    {
+      code = compute_totp (ts,
+                           i,
+                           h_key,
+                           h_key_len);
+      if (NULL == ret)
+      {
+        GNUNET_asprintf (&ret,
+                         "%llu",
+                         (unsigned long long) code);
+      }
+      else
+      {
+        char *tmp;
+
+        GNUNET_asprintf (&tmp,
+                         "%s\n%llu",
+                         ret,
+                         (unsigned long long) code);
+        GNUNET_free (ret);
+        ret = tmp;
+      }
+    }
+  return ret;
+
+}
+
+
 /**
  * It is build pos confirmation to verify payment.
  *
@@ -185,7 +223,6 @@ TALER_build_pos_confirmation (const char *pos_key,
   size_t pos_key_length = strlen (pos_key);
   void *key; /* pos_key in binary */
   size_t key_len; /* lengh of the key */
-  uint64_t code; /* totp code */
   char *ret;
   int dret;
 
@@ -212,7 +249,6 @@ TALER_build_pos_confirmation (const char *pos_key,
     GNUNET_free (key);
     return NULL;
   case TALER_MCA_WITHOUT_PRICE: /* and 30s */
-    ret = NULL;
     /* Return all T-OTP codes in range separated by new lines, e.g.
        "12345678
         24522552
@@ -220,42 +256,20 @@ TALER_build_pos_confirmation (const char *pos_key,
         42543525
         25253552"
     */
-    for (int i = -TIME_INTERVAL_RANGE; i<= TIME_INTERVAL_RANGE; i++)
-    {
-      code = compute_totp (ts,
-                           i,
-                           key,
-                           key_len);
-      if (NULL == ret)
-      {
-        GNUNET_asprintf (&ret,
-                         "%llu",
-                         (unsigned long long) code);
-      }
-      else
-      {
-        char *tmp;
-
-        GNUNET_asprintf (&tmp,
-                         "%s\n%llu",
-                         ret,
-                         (unsigned long long) code);
-        GNUNET_free (ret);
-        ret = tmp;
-      }
-    }
+    ret = executive_totp (key,
+                          key_len,
+                          ts);
     GNUNET_free (key);
     return ret;
   case TALER_MCA_WITH_PRICE:
     {
-      struct GNUNET_HashCode hkey;
+      struct GNUNET_HashCode *hkey;
       struct TALER_AmountNBO ntotal;
-      ret = NULL;
 
       TALER_amount_hton (&ntotal,
                          total);
       GNUNET_assert (GNUNET_YES ==
-                     GNUNET_CRYPTO_kdf (&hkey,
+                     GNUNET_CRYPTO_kdf (hkey,
                                         sizeof (hkey),
                                         &ntotal,
                                         sizeof (ntotal),
@@ -264,31 +278,9 @@ TALER_build_pos_confirmation (const char *pos_key,
                                         NULL,
                                         0));
       GNUNET_free (key);
-
-      for (int i = -TIME_INTERVAL_RANGE; i<= TIME_INTERVAL_RANGE; i++)
-    {
-      code = compute_totp (ts,
-                           i,
-                           &hkey,
-                           sizeof (hkey));
-      if (NULL == ret)
-      {
-        GNUNET_asprintf (&ret,
-                         "%llu",
-                         (unsigned long long) code);
-      }
-      else
-      {
-        char *tmp;
-
-        GNUNET_asprintf (&tmp,
-                         "%s\n%llu",
-                         ret,
-                         (unsigned long long) code);
-        GNUNET_free (ret);
-        ret = tmp;
-      }
-    }
+      ret = executive_totp (hkey,
+                            sizeof(hkey),
+                            ts);
       GNUNET_free (key);
       return ret;
     }

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