[PATCH] Mark nonstring use cases with __nonstring__ attribute.
NIIBE Yutaka via Gcrypt-devel <[email protected]> Fri, 18 Apr 2025 11:24:01 +0900
| Newsgroups | gmane.comp.encryption.gpg.libgcrypt.devel |
|---|---|
| Message-ID | <b5f1ff5f9d7679fb5a4bd611633b9ea6da7dffe2.1744942898.git.gniibe@fsij.org> |
* src/gcrypt.h.in (_GCRY_GCC_ATTR_NONSTRING): New. * cipher/chacha20.c (chacha20_keysetup): Use _GCRY_GCC_ATTR_NONSTRING. * cipher/cipher-gcm-siv.c (gcm_siv_selftest): Likewise. * cipher/ecc.c (compute_keygrip): Likewise. * cipher/serpent.c (serpent_test): Likewise. * tests/basic.c (check_aes128_cbc_cts_cipher): Likewise. (_check_gcm_cipher, check_gcm_siv_cipher): Likewise. (check_ocb_cipher_largebuf_split, check_ocb_cipher_checksum): Likewise. * tests/keygrip.c (key_grips): Likewise. -- GnuPG-bug-id: 7617 Signed-off-by: NIIBE Yutaka <[email protected]> --- cipher/chacha20.c | 4 ++-- cipher/cipher-gcm-siv.c | 16 ++++++++-------- cipher/ecc.c | 2 +- cipher/serpent.c | 6 +++--- src/gcrypt.h.in | 9 +++++++++ tests/basic.c | 34 +++++++++++++++++----------------- tests/keygrip.c | 2 +- 7 files changed, 41 insertions(+), 32 deletions(-) _______________________________________________ Gcrypt-devel mailing list [email protected] https://lists.gnupg.org/mailman/listinfo/gcrypt-devel
0001-Mark-nonstring-use-cases-with-__nonstring__-attribut.patch
(text/x-patch, 7.7 KB)
diff --git a/cipher/chacha20.c b/cipher/chacha20.c
index 8b547db3..848adbe5 100644
--- a/cipher/chacha20.c
+++ b/cipher/chacha20.c
@@ -428,8 +428,8 @@ static void
chacha20_keysetup (CHACHA20_context_t *ctx, const byte *key,
unsigned int keylen)
{
- static const char sigma[16] = "expand 32-byte k";
- static const char tau[16] = "expand 16-byte k";
+ static const char sigma[16] _GCRY_GCC_ATTR_NONSTRING = "expand 32-byte k";
+ static const char tau[16] _GCRY_GCC_ATTR_NONSTRING = "expand 16-byte k";
const char *constants;
ctx->input[4] = buf_get_le32(key + 0);
diff --git a/cipher/cipher-gcm-siv.c b/cipher/cipher-gcm-siv.c
index 1f7a52bc..b92ae45d 100644
--- a/cipher/cipher-gcm-siv.c
+++ b/cipher/cipher-gcm-siv.c
@@ -248,22 +248,22 @@ do_ctr_le32 (gcry_cipher_hd_t c, byte *outbuf, const byte *inbuf,
static int
gcm_siv_selftest (gcry_cipher_hd_t c)
{
- static const byte in1[GCRY_SIV_BLOCK_LEN] =
+ static const byte in1[GCRY_SIV_BLOCK_LEN] _GCRY_GCC_ATTR_NONSTRING =
"\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
- static const byte out1[GCRY_SIV_BLOCK_LEN] =
+ static const byte out1[GCRY_SIV_BLOCK_LEN] _GCRY_GCC_ATTR_NONSTRING =
"\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
- static const byte in2[GCRY_SIV_BLOCK_LEN] =
+ static const byte in2[GCRY_SIV_BLOCK_LEN] _GCRY_GCC_ATTR_NONSTRING =
"\x9c\x98\xc0\x4d\xf9\x38\x7d\xed\x82\x81\x75\xa9\x2b\xa6\x52\xd8";
- static const byte out2[GCRY_SIV_BLOCK_LEN] =
+ static const byte out2[GCRY_SIV_BLOCK_LEN] _GCRY_GCC_ATTR_NONSTRING =
"\x4e\x4c\x60\x26\xfc\x9c\x3e\xf6\xc1\x40\xba\xd4\x95\xd3\x29\x6c";
- static const byte polyval_key[GCRY_SIV_BLOCK_LEN] =
+ static const byte polyval_key[GCRY_SIV_BLOCK_LEN] _GCRY_GCC_ATTR_NONSTRING =
"\x25\x62\x93\x47\x58\x92\x42\x76\x1d\x31\xf8\x26\xba\x4b\x75\x7b";
- static const byte ghash_key[GCRY_SIV_BLOCK_LEN] =
+ static const byte ghash_key[GCRY_SIV_BLOCK_LEN] _GCRY_GCC_ATTR_NONSTRING =
"\xdc\xba\xa5\xdd\x13\x7c\x18\x8e\xbb\x21\x49\x2c\x23\xc9\xb1\x12";
- static const byte polyval_data[GCRY_SIV_BLOCK_LEN * 2] =
+ static const byte polyval_data[GCRY_SIV_BLOCK_LEN * 2] _GCRY_GCC_ATTR_NONSTRING =
"\x4f\x4f\x95\x66\x8c\x83\xdf\xb6\x40\x17\x62\xbb\x2d\x01\xa2\x62"
"\xd1\xa2\x4d\xdd\x27\x21\xd0\x06\xbb\xe4\x5f\x20\xd3\xc9\xf3\x62";
- static const byte polyval_tag[GCRY_SIV_BLOCK_LEN] =
+ static const byte polyval_tag[GCRY_SIV_BLOCK_LEN] _GCRY_GCC_ATTR_NONSTRING =
"\xf7\xa3\xb4\x7b\x84\x61\x19\xfa\xe5\xb7\x86\x6c\xf5\xe5\xb7\x7e";
byte tmp[GCRY_SIV_BLOCK_LEN];
diff --git a/cipher/ecc.c b/cipher/ecc.c
index d9cd32c3..51364b64 100644
--- a/cipher/ecc.c
+++ b/cipher/ecc.c
@@ -1699,7 +1699,7 @@ static gpg_err_code_t
compute_keygrip (gcry_md_hd_t md, gcry_sexp_t keyparms)
{
#define N_COMPONENTS 6
- static const char names[N_COMPONENTS] = "pabgnq";
+ static const char names[N_COMPONENTS] _GCRY_GCC_ATTR_NONSTRING = "pabgnq";
gpg_err_code_t rc;
gcry_sexp_t l1;
gcry_mpi_t values[N_COMPONENTS];
diff --git a/cipher/serpent.c b/cipher/serpent.c
index 74d132ab..72a2287d 100644
--- a/cipher/serpent.c
+++ b/cipher/serpent.c
@@ -1880,9 +1880,9 @@ serpent_test (void)
static struct test
{
int key_length;
- unsigned char key[32];
- unsigned char text_plain[16];
- unsigned char text_cipher[16];
+ unsigned char key[32] _GCRY_GCC_ATTR_NONSTRING;
+ unsigned char text_plain[16] _GCRY_GCC_ATTR_NONSTRING;
+ unsigned char text_cipher[16] _GCRY_GCC_ATTR_NONSTRING;
} test_data[] =
{
{
diff --git a/src/gcrypt.h.in b/src/gcrypt.h.in
index a9c36aa6..aa8a1f37 100644
--- a/src/gcrypt.h.in
+++ b/src/gcrypt.h.in
@@ -96,6 +96,12 @@ extern "C" {
#define _GCRY_GCC_ATTR_SENTINEL(a) __attribute__ ((sentinel(a)))
#endif
+#if _GCRY_GCC_VERSION >= 80000
+#define _GCRY_GCC_ATTR_NONSTRING __attribute__((__nonstring__))
+#else
+#define _GCRY_GCC_ATTR_NONSTRING
+#endif
+
#endif /*__GNUC__*/
#ifndef _GCRY_GCC_ATTR_DEPRECATED
@@ -113,6 +119,9 @@ extern "C" {
#ifndef _GCRY_GCC_ATTR_SENTINEL
#define _GCRY_GCC_ATTR_SENTINEL(a)
#endif
+#ifndef _GCRY_GCC_ATTR_NONSTRING
+#define _GCRY_GCC_ATTR_NONSTRING
+#endif
/* Make up an attribute to mark functions and types as deprecated but
allow internal use by Libgcrypt. */
diff --git a/tests/basic.c b/tests/basic.c
index 72c65b58..b62a9a90 100644
--- a/tests/basic.c
+++ b/tests/basic.c
@@ -589,7 +589,7 @@ check_cbc_mac_cipher (void)
static void
check_aes128_cbc_cts_cipher (void)
{
- static const char key[128 / 8] = "chicken teriyaki";
+ static const char key[128 / 8] _GCRY_GCC_ATTR_NONSTRING = "chicken teriyaki";
static const unsigned char plaintext[] =
"I would like the General Gau's Chicken, please, and wonton soup.";
static const struct tv
@@ -3550,15 +3550,15 @@ _check_gcm_cipher (unsigned int step)
static const struct tv
{
int algo;
- char key[MAX_DATA_LEN];
- char iv[MAX_DATA_LEN];
+ char key[MAX_DATA_LEN] _GCRY_GCC_ATTR_NONSTRING;
+ char iv[MAX_DATA_LEN] _GCRY_GCC_ATTR_NONSTRING;
int ivlen;
- unsigned char aad[MAX_DATA_LEN];
+ unsigned char aad[MAX_DATA_LEN] _GCRY_GCC_ATTR_NONSTRING;
int aadlen;
- unsigned char plaintext[MAX_GCM_DATA_LEN];
+ unsigned char plaintext[MAX_GCM_DATA_LEN] _GCRY_GCC_ATTR_NONSTRING;
int inlen;
- char out[MAX_GCM_DATA_LEN];
- char tag[MAX_DATA_LEN];
+ char out[MAX_GCM_DATA_LEN] _GCRY_GCC_ATTR_NONSTRING;
+ char tag[MAX_DATA_LEN] _GCRY_GCC_ATTR_NONSTRING;
int taglen;
int should_fail;
} tv[] =
@@ -5743,14 +5743,14 @@ check_gcm_siv_cipher (void)
{
int algo;
int flags;
- char key[MAX_DATA_LEN];
- char nonce[12];
- char ad[MAX_DATA_LEN];
+ char key[MAX_DATA_LEN] _GCRY_GCC_ATTR_NONSTRING;
+ char nonce[12] _GCRY_GCC_ATTR_NONSTRING;
+ char ad[MAX_DATA_LEN] _GCRY_GCC_ATTR_NONSTRING;
int adlen;
- unsigned char plaintext[MAX_DATA_LEN * 2];
+ unsigned char plaintext[MAX_DATA_LEN * 2] _GCRY_GCC_ATTR_NONSTRING;
int inlen;
- char out[MAX_DATA_LEN * 2];
- char tag[MAX_DATA_LEN];
+ char out[MAX_DATA_LEN * 2] _GCRY_GCC_ATTR_NONSTRING;
+ char tag[MAX_DATA_LEN] _GCRY_GCC_ATTR_NONSTRING;
} tv[] =
{
/* Test vectors from RFC8452 */
@@ -9059,10 +9059,10 @@ static void
check_ocb_cipher_largebuf_split (int algo, int keylen, const char *tagexpect,
unsigned int splitpos)
{
- static const unsigned char key[32] =
+ static const unsigned char key[32] _GCRY_GCC_ATTR_NONSTRING =
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
- static const unsigned char nonce[12] =
+ static const unsigned char nonce[12] _GCRY_GCC_ATTR_NONSTRING =
"\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x00\x01\x02\x03";
const size_t buflen = 1024 * 1024 * 2 + 32;
unsigned char *inbuf;
@@ -9282,10 +9282,10 @@ out_free:
static void
check_ocb_cipher_checksum (int algo, int keylen)
{
- static const unsigned char key[32] =
+ static const unsigned char key[32] _GCRY_GCC_ATTR_NONSTRING =
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
- static const unsigned char nonce[12] =
+ static const unsigned char nonce[12] _GCRY_GCC_ATTR_NONSTRING =
"\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x00\x01\x02\x03";
const size_t buflen = 128 * 16;
unsigned char *inbuf, *outbuf;
diff --git a/tests/keygrip.c b/tests/keygrip.c
index cf650350..503a2c05 100644
--- a/tests/keygrip.c
+++ b/tests/keygrip.c
@@ -56,7 +56,7 @@ static struct
{
int algo;
const char *key;
- const unsigned char grip[20];
+ const unsigned char grip[20] _GCRY_GCC_ATTR_NONSTRING;
int skip_when_fips;
} key_grips[] =
{