[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] sm3: support to compile with libgcrypt
From: |
Jia Zhang |
Subject: |
Re: [PATCH] sm3: support to compile with libgcrypt |
Date: |
Sun, 29 Oct 2017 21:10:01 +0800 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 |
于 2017/10/29 下午4:24, Bruno Haible 写道:
> 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.
Yes. I'm wrong on adding them.
>
> I squashes these adjustments into your patch and pushed it. Thanks for
> the major work!
I think I see the root cause.
"fatal error: gcrypt.h: No such file or directory" is resolved by your
fix. But I will still have a link failure with crypto/gc-sm3 and even
crypto/gc.
In order to reproduce this link failure, I need to have a latest
libgcrypt installed, and then configure gnulib in this way:
$ ./gnulib-tool --create-testdir --dir=testdir --single-configure
crypto/gc-sm3 // or crypto/gc
$ cd testdir
$ ./configure CPPFLAGS=-Wall // with gc-gnulib
or
$ ./configure CPPFLAGS=-Wall --with-libgcrypt
--with-libgcrypt-prefix=<path_to_libgcrypt> // with gc-libgcrypt
$ make
For gc-gnulib case, it is always built with a success because it doesn't
link with libgcrypt. Instead, the gc-libgcrypt case will require
libgcrypt, and we will see a link failure.
To fix this issue, I must specify *--libtool* with gnulib-tool. Here is
a working instructions to test crypto/gc-sm3 (and crypto/gc) for me:
$ ./gnulib-tool --create-testdir --libtool --dir=testdir
--single-configure crypto/gc-sm3
$ cd testdir
$ ./configure CPPFLAGS=-Wall --with-libgcrypt
--with-libgcrypt-prefix=<path_to_libgcrypt>
$ make
And using gc-gnulib is always fine with us:
$ ./gnulib-tool --create-testdir --libtool --dir=testdir
--single-configure crypto/gc-sm3
$ cd testdir
$ ./configure CPPFLAGS=-Wall --with-libgcrypt
--with-libgcrypt-prefix=<path_to_libgcrypt>
$ make
Therefore, I have succeeded to have sm3 and gc-sm3 fully working in
gnulib with or without libgcrypt.
Thank you very much! Without your great helps, I cannot make it.
Cheers,
Jia
>
>> 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,
>