summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpriscilla <priscilla.huang@efrei.net>2023-03-03 05:20:40 -0500
committerpriscilla <priscilla.huang@efrei.net>2023-03-03 05:20:40 -0500
commit263ebf00fc5bde274ac76c99b2cd3bd8a63811ed (patch)
tree86ecff809e32666012b7d2d9c0bb15afd396ede6 /src
parentb46c03b2c9e7d8e5136a84b2fb3d6af8277947df (diff)
downloadexchange-263ebf00fc5bde274ac76c99b2cd3bd8a63811ed.tar.gz
exchange-263ebf00fc5bde274ac76c99b2cd3bd8a63811ed.tar.bz2
exchange-263ebf00fc5bde274ac76c99b2cd3bd8a63811ed.zip
totp update function
Diffstat (limited to 'src')
-rw-r--r--src/util/crypto_confirmation.c100
1 files changed, 46 insertions, 54 deletions
diff --git a/src/util/crypto_confirmation.c b/src/util/crypto_confirmation.c
index e47a61a69..6c6b7fb41 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;
}