summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <grothoff@gnunet.org>2022-03-27 16:03:54 +0200
committerChristian Grothoff <grothoff@gnunet.org>2022-03-30 10:29:16 +0200
commit789a13e1d124694f36fa298de1d79c51d9073506 (patch)
treedcf796b679ac72850ee8ad883eeae47ee9b18519
parentedf6f59fac12cd6f7d0a14ecf2a47ab82a8beb17 (diff)
-style fixes, no semantic changes
m---------contrib/gana0
-rw-r--r--src/util/crypto_hkdf.c118
-rw-r--r--src/util/crypto_kdf.c56
-rw-r--r--src/util/crypto_rsa.c8
4 files changed, 79 insertions, 103 deletions
diff --git a/contrib/gana b/contrib/gana
-Subproject e12bcee063df61ed4b9acbe819443672364eb4d
+Subproject 0958add542378a6ca9c411e2dc19527834e9f64
diff --git a/src/util/crypto_hkdf.c b/src/util/crypto_hkdf.c
index 4e4496819..838e37d8d 100644
--- a/src/util/crypto_hkdf.c
+++ b/src/util/crypto_hkdf.c
@@ -74,16 +74,21 @@
* @return HMAC, freed by caller via gcry_md_close/_reset
*/
static const void *
-doHMAC (gcry_md_hd_t mac, const void *key, size_t key_len, const void *buf,
+doHMAC (gcry_md_hd_t mac,
+ const void *key,
+ size_t key_len,
+ const void *buf,
size_t buf_len)
{
- if (GPG_ERR_NO_ERROR != gcry_md_setkey (mac, key, key_len))
+ if (GPG_ERR_NO_ERROR !=
+ gcry_md_setkey (mac, key, key_len))
{
GNUNET_break (0);
return NULL;
}
- gcry_md_write (mac, buf, buf_len);
-
+ gcry_md_write (mac,
+ buf,
+ buf_len);
return (const void *) gcry_md_read (mac, 0);
}
@@ -98,9 +103,13 @@ doHMAC (gcry_md_hd_t mac, const void *key, size_t key_len, const void *buf,
* @param prk result buffer (allocated by caller; at least gcry_md_dlen() bytes)
* @return #GNUNET_YES on success
*/
-static int
-getPRK (gcry_md_hd_t mac, const void *xts, size_t xts_len, const void *skm,
- size_t skm_len, void *prk)
+static enum GNUNET_GenericReturnValue
+getPRK (gcry_md_hd_t mac,
+ const void *xts,
+ size_t xts_len,
+ const void *skm,
+ size_t skm_len,
+ void *prk)
{
const void *ret;
size_t dlen;
@@ -114,9 +123,10 @@ getPRK (gcry_md_hd_t mac, const void *xts, size_t xts_len, const void *skm,
* salt - optional salt value (a non-secret random value);
* if not provided, it is set to a string of HashLen zeros. */
- if (xts_len == 0)
+ if (0 == xts_len)
{
char zero_salt[dlen];
+
memset (zero_salt, 0, dlen);
ret = doHMAC (mac, zero_salt, dlen, skm, skm_len);
}
@@ -124,22 +134,23 @@ getPRK (gcry_md_hd_t mac, const void *xts, size_t xts_len, const void *skm,
{
ret = doHMAC (mac, xts, xts_len, skm, skm_len);
}
- if (ret == NULL)
+ if (NULL == ret)
return GNUNET_SYSERR;
- GNUNET_memcpy (prk, ret, dlen);
-
+ GNUNET_memcpy (prk,
+ ret,
+ dlen);
return GNUNET_YES;
}
#if DEBUG_HKDF
static void
-dump (const char *src, const void *p, unsigned int l)
+dump (const char *src,
+ const void *p,
+ unsigned int l)
{
- unsigned int i;
-
printf ("\n%s: ", src);
- for (i = 0; i < l; i++)
+ for (unsigned int i = 0; i < l; i++)
{
printf ("%2x", (int) ((const unsigned char *) p)[i]);
}
@@ -150,23 +161,16 @@ dump (const char *src, const void *p, unsigned int l)
#endif
-/**
- * @brief Derive key
- * @param result buffer for the derived key, allocated by caller
- * @param out_len desired length of the derived key
- * @param xtr_algo hash algorithm for the extraction phase, GCRY_MD_...
- * @param prf_algo hash algorithm for the expansion phase, GCRY_MD_...
- * @param xts salt
- * @param xts_len length of @a xts
- * @param skm source key material
- * @param skm_len length of @a skm
- * @param argp va_list of void * & size_t pairs for context chunks
- * @return #GNUNET_YES on success
- */
-int
-GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, int prf_algo,
- const void *xts, size_t xts_len, const void *skm,
- size_t skm_len, va_list argp)
+enum GNUNET_GenericReturnValue
+GNUNET_CRYPTO_hkdf_v (void *result,
+ size_t out_len,
+ int xtr_algo,
+ int prf_algo,
+ const void *xts,
+ size_t xts_len,
+ const void *skm,
+ size_t skm_len,
+ va_list argp)
{
gcry_md_hd_t xtr;
gcry_md_hd_t prf;
@@ -186,10 +190,14 @@ GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, int prf_algo,
if (0 == k)
return GNUNET_SYSERR;
if (GPG_ERR_NO_ERROR !=
- gcry_md_open (&xtr, xtr_algo, GCRY_MD_FLAG_HMAC))
+ gcry_md_open (&xtr,
+ xtr_algo,
+ GCRY_MD_FLAG_HMAC))
return GNUNET_SYSERR;
if (GPG_ERR_NO_ERROR !=
- gcry_md_open (&prf, prf_algo, GCRY_MD_FLAG_HMAC))
+ gcry_md_open (&prf,
+ prf_algo,
+ GCRY_MD_FLAG_HMAC))
{
gcry_md_close (xtr);
return GNUNET_SYSERR;
@@ -221,7 +229,8 @@ GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, int prf_algo,
}
memset (result, 0, out_len);
- if (getPRK (xtr, xts, xts_len, skm, skm_len, prk) != GNUNET_YES)
+ if (GNUNET_YES !=
+ getPRK (xtr, xts, xts_len, skm, skm_len, prk))
goto hkdf_error;
#if DEBUG_HKDF
dump ("PRK", prk, xtr_len);
@@ -276,7 +285,7 @@ GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, int prf_algo,
dump ("K(i+1)", plain, plain_len);
#endif
hc = doHMAC (prf, prk, xtr_len, plain, plain_len);
- if (hc == NULL)
+ if (NULL == hc)
{
GNUNET_free (plain);
goto hkdf_error;
@@ -327,32 +336,31 @@ hkdf_ok:
}
-/**
- * @brief Derive key
- * @param result buffer for the derived key, allocated by caller
- * @param out_len desired length of the derived key
- * @param xtr_algo hash algorithm for the extraction phase, GCRY_MD_...
- * @param prf_algo hash algorithm for the expansion phase, GCRY_MD_...
- * @param xts salt
- * @param xts_len length of @a xts
- * @param skm source key material
- * @param skm_len length of @a skm
- * @return #GNUNET_YES on success
- */
-int
-GNUNET_CRYPTO_hkdf (void *result, size_t out_len, int xtr_algo, int prf_algo,
- const void *xts, size_t xts_len, const void *skm,
+enum GNUNET_GenericReturnValue
+GNUNET_CRYPTO_hkdf (void *result,
+ size_t out_len,
+ int xtr_algo,
+ int prf_algo,
+ const void *xts,
+ size_t xts_len,
+ const void *skm,
size_t skm_len, ...)
{
va_list argp;
- int ret;
+ enum GNUNET_GenericReturnValue ret;
va_start (argp, skm_len);
ret =
- GNUNET_CRYPTO_hkdf_v (result, out_len, xtr_algo, prf_algo, xts, xts_len,
- skm, skm_len, argp);
+ GNUNET_CRYPTO_hkdf_v (result,
+ out_len,
+ xtr_algo,
+ prf_algo,
+ xts,
+ xts_len,
+ skm,
+ skm_len,
+ argp);
va_end (argp);
-
return ret;
}
diff --git a/src/util/crypto_kdf.c b/src/util/crypto_kdf.c
index 8041f61ab..f577e0f7a 100644
--- a/src/util/crypto_kdf.c
+++ b/src/util/crypto_kdf.c
@@ -32,17 +32,7 @@
#define LOG(kind, ...) GNUNET_log_from (kind, "util-crypto-kdf", __VA_ARGS__)
-/**
- * @brief Derive key
- * @param result buffer for the derived key, allocated by caller
- * @param out_len desired length of the derived key
- * @param xts salt
- * @param xts_len length of @a xts
- * @param skm source key material
- * @param skm_len length of @a skm
- * @param argp va_list of void * & size_t pairs for context chunks
- * @return #GNUNET_YES on success
- */
+
enum GNUNET_GenericReturnValue
GNUNET_CRYPTO_kdf_v (void *result,
size_t out_len,
@@ -75,17 +65,6 @@ GNUNET_CRYPTO_kdf_v (void *result,
}
-/**
- * @brief Derive key
- * @param result buffer for the derived key, allocated by caller
- * @param out_len desired length of the derived key
- * @param xts salt
- * @param xts_len length of @a xts
- * @param skm source key material
- * @param skm_len length of @a skm
- * @param ... void * & size_t pairs for context chunks
- * @return #GNUNET_YES on success
- */
enum GNUNET_GenericReturnValue
GNUNET_CRYPTO_kdf (void *result,
size_t out_len,
@@ -111,18 +90,6 @@ GNUNET_CRYPTO_kdf (void *result,
}
-/**
- * Deterministically generate a pseudo-random number uniformly from the
- * integers modulo a libgcrypt mpi.
- *
- * @param[out] r MPI value set to the FDH
- * @param n MPI to work modulo
- * @param xts salt
- * @param xts_len length of @a xts
- * @param skm source key material
- * @param skm_len length of @a skm
- * @param ctx context string
- */
void
GNUNET_CRYPTO_kdf_mod_mpi (gcry_mpi_t *r,
gcry_mpi_t n,
@@ -137,33 +104,34 @@ GNUNET_CRYPTO_kdf_mod_mpi (gcry_mpi_t *r,
nbits = gcry_mpi_get_nbits (n);
/* GNUNET_assert (nbits > 512); */
-
ctr = 0;
while (1)
{
/* Ain't clear if n is always divisible by 8 */
- uint8_t buf[ (nbits - 1) / 8 + 1 ];
+ size_t bsize = (nbits - 1) / 8 + 1;
+ uint8_t buf[bsize];
uint16_t ctr_nbo = htons (ctr);
- memset (buf, 0, sizeof (buf));
rc = GNUNET_CRYPTO_kdf (buf,
- sizeof(buf),
+ bsize,
xts, xts_len,
skm, skm_len,
ctx, strlen (ctx),
&ctr_nbo, sizeof(ctr_nbo),
NULL, 0);
GNUNET_assert (GNUNET_YES == rc);
-
rc = gcry_mpi_scan (r,
GCRYMPI_FMT_USG,
(const unsigned char *) buf,
- sizeof(buf),
+ bsize,
&rsize);
- GNUNET_assert (0 == rc); /* Allocation error? */
- GNUNET_assert (rsize == sizeof (buf));
- gcry_mpi_clear_highbit (*r, nbits);
- GNUNET_assert (0 == gcry_mpi_test_bit (*r, nbits));
+ GNUNET_assert (GPG_ERR_NO_ERROR == rc); /* Allocation error? */
+ GNUNET_assert (rsize == bsize);
+ gcry_mpi_clear_highbit (*r,
+ nbits);
+ GNUNET_assert (0 ==
+ gcry_mpi_test_bit (*r,
+ nbits));
++ctr;
/* We reject this FDH if either *r > n and retry with another ctr */
if (0 > gcry_mpi_cmp (*r, n))
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c
index 610e5febc..4b8e5a5ce 100644
--- a/src/util/crypto_rsa.c
+++ b/src/util/crypto_rsa.c
@@ -521,7 +521,7 @@ static struct RsaBlindingKey *
rsa_blinding_key_derive (const struct GNUNET_CRYPTO_RsaPublicKey *pkey,
const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks)
{
- char *xts = "Blinding KDF extractor HMAC key"; /* Trusts bks' randomness more */
+ const char *xts = "Blinding KDF extractor HMAC key"; /* Trusts bks' randomness more */
struct RsaBlindingKey *blind;
gcry_mpi_t n;
@@ -766,8 +766,9 @@ rsa_full_domain_hash (const struct GNUNET_CRYPTO_RsaPublicKey *pkey,
/* We key with the public denomination key as a homage to RSA-PSS by *
* Mihir Bellare and Phillip Rogaway. Doing this lowers the degree *
* of the hypothetical polyomial-time attack on RSA-KTI created by a *
- * polynomial-time one-more forgary attack. Yey seeding! */
- xts_len = GNUNET_CRYPTO_rsa_public_key_encode (pkey, &xts);
+ * polynomial-time one-more forgary attack. Yey seeding! */
+ xts_len = GNUNET_CRYPTO_rsa_public_key_encode (pkey,
+ &xts);
GNUNET_CRYPTO_kdf_mod_mpi (&r,
n,
@@ -775,7 +776,6 @@ rsa_full_domain_hash (const struct GNUNET_CRYPTO_RsaPublicKey *pkey,
hash, sizeof(*hash),
"RSA-FDA FTpsW!");
GNUNET_free (xts);
-
ok = rsa_gcd_validate (r, n);
gcry_mpi_release (n);
if (ok)