summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier CrĂȘte <olivier.crete@collabora.com>2017-04-03 14:20:31 -0400
committerOlivier CrĂȘte <olivier.crete@collabora.com>2017-04-03 14:20:31 -0400
commitec719f08713a35fb67461f3c90c86dde7d21c2a2 (patch)
tree0a53381ce7866e97b278ead31888c9b29a922c92
parent6d3a7a1b84aa91337336aeb9f5f6c7f7fe45675a (diff)
downloadlibnice-ec719f08713a35fb67461f3c90c86dde7d21c2a2.tar.gz
stun: Make hmac code NDEBUG safe
-rw-r--r--stun/stunhmac.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/stun/stunhmac.c b/stun/stunhmac.c
index d488e04..c1e5180 100644
--- a/stun/stunhmac.c
+++ b/stun/stunhmac.c
@@ -56,31 +56,36 @@ void stun_sha1 (const uint8_t *msg, size_t len, size_t msg_len, uint8_t *sha,
uint16_t fakelen = htons (msg_len);
uint8_t pad_char[64] = {0};
gnutls_hmac_hd_t handle;
+
+#ifdef NDEBUG
+#define TRY(x) x;
+#else
int ret;
+#define TRY(x) \
+ ret = x; \
+ assert (ret >= 0);
+#endif
assert (len >= 44u);
assert (gnutls_hmac_get_len (GNUTLS_MAC_SHA1) == 20);
- ret = gnutls_hmac_init (&handle, GNUTLS_MAC_SHA1, key, keylen);
- assert (ret >= 0);
+ TRY (gnutls_hmac_init (&handle, GNUTLS_MAC_SHA1, key, keylen));
- ret = gnutls_hmac (handle, msg, 2);
- assert (ret >= 0);
- ret = gnutls_hmac (handle, &fakelen, 2);
- assert (ret >= 0);
- ret = gnutls_hmac (handle, msg + 4, len - 28);
- assert (ret >= 0);
+ TRY (gnutls_hmac (handle, msg, 2));
+ TRY (gnutls_hmac (handle, &fakelen, 2));
+ TRY (gnutls_hmac (handle, msg + 4, len - 28));
/* RFC 3489 specifies that the message's size should be 64 bytes,
and \x00 padding should be done */
if (padding && ((len - 24) % 64) > 0) {
uint16_t pad_size = 64 - ((len - 24) % 64);
- ret = gnutls_hmac (handle, pad_char, pad_size);
- assert (ret >= 0);
+ TRY (gnutls_hmac (handle, pad_char, pad_size));
}
gnutls_hmac_deinit (handle, sha);
+
+#undef TRY
}
static const uint8_t *priv_trim_var (const uint8_t *var, size_t *var_len)