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

[PATCH 05/20] cmake: detect "bounded" compiler attribute


From: Aris Adamantiadis <aris@xxxxxxxxxxxx>

---
 ConfigureChecks.cmake     |  5 +++++
 config.h.cmake            |  2 ++
 include/libssh/chacha.h   | 16 +++++++++++++---
 include/libssh/poly1305.h |  5 ++++-
 4 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 4e20a669..fba465a4 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -324,6 +324,11 @@ int main(void) {
 }" HAVE_COMPILER__FUNCTION__)
 
 
+check_c_source_compiles("
+void chacha_keysetup(struct chacha_ctx *x, const u_char *k, u_int kbits)
+    __attribute__((__bounded__(__minbytes__, 2, CHACHA_MINKEYLEN)));
+int main(void) { return 0; }" HAVE_GCC_BOUNDED_ATTRIBUTE)
+
 if (WITH_DEBUG_CRYPTO)
   set(DEBUG_CRYPTO 1)
 endif (WITH_DEBUG_CRYPTO)
diff --git a/config.h.cmake b/config.h.cmake
index 23c409e1..c783ab6a 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -193,6 +193,8 @@
 #cmakedefine HAVE_COMPILER__FUNC__ 1
 #cmakedefine HAVE_COMPILER__FUNCTION__ 1
 
+#cmakedefine HAVE_GCC_BOUNDED_ATTRIBUTE 1
+
 /* Define to 1 if you want to enable GSSAPI */
 #cmakedefine WITH_GSSAPI 1
 
diff --git a/include/libssh/chacha.h b/include/libssh/chacha.h
index 04265670..b63531e4 100644
--- a/include/libssh/chacha.h
+++ b/include/libssh/chacha.h
@@ -9,6 +9,7 @@ Public domain.
 #ifndef CHACHA_H
 #define CHACHA_H
 
+#include "config.h"
 #include <sys/types.h>
 
 struct chacha_ctx {
@@ -22,13 +23,22 @@ struct chacha_ctx {
 #define CHACHA_BLOCKLEN   64
 
 void chacha_keysetup(struct chacha_ctx *x, const u_char *k, u_int kbits)
-    __attribute__((__bounded__(__minbytes__, 2, CHACHA_MINKEYLEN)));
+#ifdef HAVE_GCC_BOUNDED_ATTRIBUTE
+    __attribute__((__bounded__(__minbytes__, 2, CHACHA_MINKEYLEN)))
+#endif
+    ;
 void chacha_ivsetup(struct chacha_ctx *x, const u_char *iv, const u_char *ctr)
+#ifdef HAVE_GCC_BOUNDED_ATTRIBUTE
     __attribute__((__bounded__(__minbytes__, 2, CHACHA_NONCELEN)))
-    __attribute__((__bounded__(__minbytes__, 3, CHACHA_CTRLEN)));
+    __attribute__((__bounded__(__minbytes__, 3, CHACHA_CTRLEN)))
+#endif
+    ;
 void chacha_encrypt_bytes(struct chacha_ctx *x, const u_char *m,
     u_char *c, u_int bytes)
+#ifdef HAVE_GCC_BOUNDED_ATTRIBUTE
     __attribute__((__bounded__(__buffer__, 2, 4)))
-    __attribute__((__bounded__(__buffer__, 3, 4)));
+    __attribute__((__bounded__(__buffer__, 3, 4)))
+#endif
+    ;
 
 #endif    /* CHACHA_H */
diff --git a/include/libssh/poly1305.h b/include/libssh/poly1305.h
index 27900ef0..b2961486 100644
--- a/include/libssh/poly1305.h
+++ b/include/libssh/poly1305.h
@@ -13,8 +13,11 @@
 
 void poly1305_auth(u_char out[POLY1305_TAGLEN], const u_char *m, size_t inlen,
     const u_char key[POLY1305_KEYLEN])
+#ifdef HAVE_GCC_BOUNDED_ATTRIBUTE
     __attribute__((__bounded__(__minbytes__, 1, POLY1305_TAGLEN)))
     __attribute__((__bounded__(__buffer__, 2, 3)))
-    __attribute__((__bounded__(__minbytes__, 4, POLY1305_KEYLEN)));
+    __attribute__((__bounded__(__minbytes__, 4, POLY1305_KEYLEN)))
+#endif
+    ;
 
 #endif	/* POLY1305_H */
-- 
2.14.1


References:
[PATCH 00/20] Add chacha20-poly1305 supportAlberto Aguirre <albaguirre@xxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org