bug-gnulib
[Top][All Lists]
Advanced

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

Re: [PATCH] sm3: support to compile with libgcrypt


From: Bruno Haible
Subject: Re: [PATCH] sm3: support to compile with libgcrypt
Date: Sun, 29 Oct 2017 09:24:48 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-97-generic; KDE/5.18.0; x86_64; ; )

Hi Jia,

> I refreshed the patches based on the latest master branch.

Thanks.

> Basically the problem we discussed may still exist.

Yes it still exists. The testdir for 'crypto/gc-sm3' fails to compile for me,
whereas 'crypto/gc-sha1' works. The following fixes it for me:

diff --git a/modules/crypto/gc-sm3-tests b/modules/crypto/gc-sm3-tests
index 21488df..006f41f 100644
--- a/modules/crypto/gc-sm3-tests
+++ b/modules/crypto/gc-sm3-tests
@@ -8,4 +8,4 @@ configure.ac:
 Makefile.am:
 TESTS += test-gc-sm3
 check_PROGRAMS += test-gc-sm3
-test_gc_sm3_LDADD = $(LDADD) @LIB_CRYPTO@ $(LIBGCRYPT_LIBS)
+test_gc_sm3_LDADD = $(LDADD) @LIB_CRYPTO@
diff --git a/tests/test-gc-sm3.c b/tests/test-gc-sm3.c
index 3e412c8..608725d 100644
--- a/tests/test-gc-sm3.c
+++ b/tests/test-gc-sm3.c
@@ -19,7 +19,6 @@
 
 #include <stdio.h>
 #include <string.h>
-#include <gcrypt.h>
 #include "gc.h"
 
 int

Rationale:
1) LIBGCRYPT_LIBS is nowhere defined, therefore always empty.
2) The module description modules/crypto/gc-sm3 states that the user of
   this module must include "gc.h", nothing else.

I squashes these adjustments into your patch and pushed it. Thanks for
the major work!

> Changelog:
> 
> - fix the following 10 failures:
> [gc-gnulib.c] 8 failures
> lib/gc-gnulib.c: In function 'gc_init':
> lib/gc-gnulib.c:87:1: error: function might be candidate for attribute
> 'const' [-Werror=suggest-attribute=const]
>  gc_init (void)
>  ^~~~~~~
> lib/gc-gnulib.c: In function 'gc_done':
> lib/gc-gnulib.c:114:1: error: function might be candidate for
> attribute 'const' [-Werror=suggest-attribute=const]
>  gc_done (void)
>  ^~~~~~~
> lib/gc-gnulib.c: In function 'gc_set_allocators':
> lib/gc-gnulib.c:217:1: error: function might be candidate for
> attribute 'const' [-Werror=suggest-attribute=const]
>  gc_set_allocators (gc_malloc_t func_malloc,
>  ^~~~~~~~~~~~~~~~~
> lib/gc-gnulib.c: In function 'gc_cipher_setkey':
> lib/gc-gnulib.c:334:1: error: function might be candidate for
> attribute 'const' [-Werror=suggest-attribute=const]
>  gc_cipher_setkey (gc_cipher_handle handle, size_t keylen, const char
> *key)
>  ^~~~~~~~~~~~~~~~
> lib/gc-gnulib.c: In function 'gc_cipher_setiv':
> lib/gc-gnulib.c:398:1: error: function might be candidate for
> attribute 'const' [-Werror=suggest-attribute=const]
>  gc_cipher_setiv (gc_cipher_handle handle, size_t ivlen, const char *iv)
>  ^~~~~~~~~~~~~~~
> lib/gc-gnulib.c: In function 'gc_cipher_encrypt_inline':
> lib/gc-gnulib.c:452:1: error: function might be candidate for
> attribute 'const' [-Werror=suggest-attribute=const]
>  gc_cipher_encrypt_inline (gc_cipher_handle handle, size_t len, char
> *data)
>  ^~~~~~~~~~~~~~~~~~~~~~~~
> lib/gc-gnulib.c: In function 'gc_cipher_decrypt_inline':
> lib/gc-gnulib.c:522:1: error: function might be candidate for
> attribute 'const' [-Werror=suggest-attribute=const]
>  gc_cipher_decrypt_inline (gc_cipher_handle handle, size_t len, char
> *data)
>  ^~~~~~~~~~~~~~~~~~~~~~~~
> lib/gc-gnulib.c: In function 'gc_hash_digest_length':
> lib/gc-gnulib.c:706:1: error: function might be candidate for
> attribute 'const' [-Werror=suggest-attribute=const]
>  gc_hash_digest_length (Gc_hash hash)
>  ^~~~~~~~~~~~~~~~~~~~~
> 
> [gc-libgcrypt.c] 2 failures
> lib/gc-libgcrypt.c: In function 'gc_done':
> lib/gc-libgcrypt.c:66:1: error: function might be candidate for
> attribute 'const' [-Werror=suggest-attribute=const]
>  gc_done (void)
>  ^~~~~~~
> lib/gc-libgcrypt.c: In function 'gc_hash_digest_length':
> lib/gc-libgcrypt.c:368:1: error: function might be candidate for
> attribute 'const' [-Werror=suggest-attribute=const]
>  gc_hash_digest_length (Gc_hash hash)
>  ^~~~~~~~~~~~~~~~~~~~~

No, this is wrong. As I tried to explain in the last mail, we must respect
the semantics of the 'const' attribute. As a rule of thumb,
  - functions that take pointer arguments must not be declared 'const',
  - functions that make side effects must not be declared 'const'.
In other words, 'const' functions are functions which only take immediate
arguments, only do computations of a result (no side effects), and include
no randomness.

So, only 'gc_hash_digest_length' is eligible.

Additionally, only the declaration (in the .h files) needs to be changed.
You don't need the it at the implementation.

I pushed a reduced version of your patch, that includes only this function.


2017-10-29  Jia Zhang  <address@hidden>
            Bruno Haible  <address@hidden>

        crypto/gc: fix build failure with -Werror=suggest-attribute=const
        * lib/gc.h (gc_hash_digest_length): Mark with 'const' attribute.

diff --git a/lib/gc.h b/lib/gc.h
index e65ba49..00e29e1 100644
--- a/lib/gc.h
+++ b/lib/gc.h
@@ -136,7 +136,8 @@ extern Gc_rc gc_cipher_close (gc_cipher_handle handle);
 extern Gc_rc gc_hash_open (Gc_hash hash, Gc_hash_mode mode,
                            gc_hash_handle *outhandle);
 extern Gc_rc gc_hash_clone (gc_hash_handle handle, gc_hash_handle *outhandle);
-extern size_t gc_hash_digest_length (Gc_hash hash);
+extern size_t gc_hash_digest_length (Gc_hash hash)
+                                     _GL_ATTRIBUTE_CONST;
 extern void gc_hash_hmac_setkey (gc_hash_handle handle,
                                  size_t len, const char *key);
 extern void gc_hash_write (gc_hash_handle handle,




reply via email to

[Prev in Thread] Current Thread [Next in Thread]