From owner-svn-src-stable-11@freebsd.org Tue Nov 22 20:28:19 2016 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id AA206C50EBE; Tue, 22 Nov 2016 20:28:19 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 853E4A9A; Tue, 22 Nov 2016 20:28:19 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uAMKSIRH032176; Tue, 22 Nov 2016 20:28:18 GMT (envelope-from asomers@FreeBSD.org) Received: (from asomers@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uAMKSHO6032163; Tue, 22 Nov 2016 20:28:17 GMT (envelope-from asomers@FreeBSD.org) Message-Id: <201611222028.uAMKSHO6032163@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: asomers set sender to asomers@FreeBSD.org using -f From: Alan Somers Date: Tue, 22 Nov 2016 20:28:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r309023 - in stable/11: lib/libmd sys/crypto sys/crypto/aesni sys/crypto/sha2 sys/crypto/siphash sys/crypto/skein sys/sys X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Nov 2016 20:28:19 -0000 Author: asomers Date: Tue Nov 22 20:28:17 2016 New Revision: 309023 URL: https://svnweb.freebsd.org/changeset/base/309023 Log: MFC r307584 Fix C++ includability of crypto headers with static array sizes C99 allows array function parameters to use the static keyword for their sizes. This tells the compiler that the parameter will have at least the specified size, and calling code will fail to compile if that guarantee is not met. However, this syntax is not legal in C++. This commit reverts r300824, which worked around the problem for sys/sys/md5.h only, and introduces a new macro: min_size(). min_size(x) can be used in headers as a static array size, but will still compile in C++ mode. Modified: stable/11/lib/libmd/md5.h stable/11/sys/crypto/aesni/aesni.h stable/11/sys/crypto/sha1.h stable/11/sys/crypto/sha2/sha256.h stable/11/sys/crypto/sha2/sha384.h stable/11/sys/crypto/sha2/sha512.h stable/11/sys/crypto/sha2/sha512t.h stable/11/sys/crypto/siphash/siphash.h stable/11/sys/crypto/skein/skein_freebsd.h stable/11/sys/sys/cdefs.h stable/11/sys/sys/md4.h stable/11/sys/sys/md5.h Directory Properties: stable/11/ (props changed) Modified: stable/11/lib/libmd/md5.h ============================================================================== --- stable/11/lib/libmd/md5.h Tue Nov 22 19:31:32 2016 (r309022) +++ stable/11/lib/libmd/md5.h Tue Nov 22 20:28:17 2016 (r309023) @@ -37,13 +37,5 @@ #endif -#ifdef __cplusplus -#define static -#endif - #include - -#ifdef __cplusplus -#undef static -#endif #endif /* _MD5_H_ */ Modified: stable/11/sys/crypto/aesni/aesni.h ============================================================================== --- stable/11/sys/crypto/aesni/aesni.h Tue Nov 22 19:31:32 2016 (r309022) +++ stable/11/sys/crypto/aesni/aesni.h Tue Nov 22 20:28:17 2016 (r309023) @@ -79,23 +79,25 @@ void aesni_set_deckey(const uint8_t *enc */ void aesni_encrypt_cbc(int rounds, const void *key_schedule /*__aligned(16)*/, size_t len, const uint8_t *from, uint8_t *to, - const uint8_t iv[static AES_BLOCK_LEN]); + const uint8_t iv[__min_size(AES_BLOCK_LEN)]); void aesni_decrypt_cbc(int rounds, const void *key_schedule /*__aligned(16)*/, - size_t len, uint8_t *buf, const uint8_t iv[static AES_BLOCK_LEN]); + size_t len, uint8_t *buf, const uint8_t iv[__min_size(AES_BLOCK_LEN)]); void aesni_encrypt_ecb(int rounds, const void *key_schedule /*__aligned(16)*/, size_t len, const uint8_t *from, uint8_t *to); void aesni_decrypt_ecb(int rounds, const void *key_schedule /*__aligned(16)*/, size_t len, const uint8_t *from, uint8_t *to); void aesni_encrypt_icm(int rounds, const void *key_schedule /*__aligned(16)*/, size_t len, const uint8_t *from, uint8_t *to, - const uint8_t iv[static AES_BLOCK_LEN]); + const uint8_t iv[__min_size(AES_BLOCK_LEN)]); void aesni_encrypt_xts(int rounds, const void *data_schedule /*__aligned(16)*/, const void *tweak_schedule /*__aligned(16)*/, size_t len, - const uint8_t *from, uint8_t *to, const uint8_t iv[static AES_BLOCK_LEN]); + const uint8_t *from, uint8_t *to, + const uint8_t iv[__min_size(AES_BLOCK_LEN)]); void aesni_decrypt_xts(int rounds, const void *data_schedule /*__aligned(16)*/, const void *tweak_schedule /*__aligned(16)*/, size_t len, - const uint8_t *from, uint8_t *to, const uint8_t iv[static AES_BLOCK_LEN]); + const uint8_t *from, uint8_t *to, + const uint8_t iv[__min_size(AES_BLOCK_LEN)]); /* GCM & GHASH functions */ void AES_GCM_encrypt(const unsigned char *in, unsigned char *out, Modified: stable/11/sys/crypto/sha1.h ============================================================================== --- stable/11/sys/crypto/sha1.h Tue Nov 22 19:31:32 2016 (r309022) +++ stable/11/sys/crypto/sha1.h Tue Nov 22 20:28:17 2016 (r309023) @@ -61,7 +61,7 @@ typedef struct sha1_ctxt SHA1_CTX; extern void sha1_init(struct sha1_ctxt *); extern void sha1_pad(struct sha1_ctxt *); extern void sha1_loop(struct sha1_ctxt *, const u_int8_t *, size_t); -extern void sha1_result(struct sha1_ctxt *, char[static SHA1_RESULTLEN]); +extern void sha1_result(struct sha1_ctxt *, char[__min_size(SHA1_RESULTLEN)]); /* compatibilty with other SHA1 source codes */ #define SHA1Init(x) sha1_init((x)) Modified: stable/11/sys/crypto/sha2/sha256.h ============================================================================== --- stable/11/sys/crypto/sha2/sha256.h Tue Nov 22 19:31:32 2016 (r309022) +++ stable/11/sys/crypto/sha2/sha256.h Tue Nov 22 20:28:17 2016 (r309023) @@ -78,7 +78,8 @@ __BEGIN_DECLS void SHA256_Init(SHA256_CTX *); void SHA256_Update(SHA256_CTX *, const void *, size_t); -void SHA256_Final(unsigned char [static SHA256_DIGEST_LENGTH], SHA256_CTX *); +void SHA256_Final(unsigned char [__min_size(SHA256_DIGEST_LENGTH)], + SHA256_CTX *); #ifndef _KERNEL char *SHA256_End(SHA256_CTX *, char *); char *SHA256_Data(const void *, unsigned int, char *); Modified: stable/11/sys/crypto/sha2/sha384.h ============================================================================== --- stable/11/sys/crypto/sha2/sha384.h Tue Nov 22 19:31:32 2016 (r309022) +++ stable/11/sys/crypto/sha2/sha384.h Tue Nov 22 20:28:17 2016 (r309023) @@ -74,7 +74,8 @@ __BEGIN_DECLS void SHA384_Init(SHA384_CTX *); void SHA384_Update(SHA384_CTX *, const void *, size_t); -void SHA384_Final(unsigned char [static SHA384_DIGEST_LENGTH], SHA384_CTX *); +void SHA384_Final(unsigned char [__min_size(SHA384_DIGEST_LENGTH)], + SHA384_CTX *); #ifndef _KERNEL char *SHA384_End(SHA384_CTX *, char *); char *SHA384_Data(const void *, unsigned int, char *); Modified: stable/11/sys/crypto/sha2/sha512.h ============================================================================== --- stable/11/sys/crypto/sha2/sha512.h Tue Nov 22 19:31:32 2016 (r309022) +++ stable/11/sys/crypto/sha2/sha512.h Tue Nov 22 20:28:17 2016 (r309023) @@ -77,7 +77,8 @@ __BEGIN_DECLS void SHA512_Init(SHA512_CTX *); void SHA512_Update(SHA512_CTX *, const void *, size_t); -void SHA512_Final(unsigned char [static SHA512_DIGEST_LENGTH], SHA512_CTX *); +void SHA512_Final(unsigned char [__min_size(SHA512_DIGEST_LENGTH)], + SHA512_CTX *); #ifndef _KERNEL char *SHA512_End(SHA512_CTX *, char *); char *SHA512_Data(const void *, unsigned int, char *); Modified: stable/11/sys/crypto/sha2/sha512t.h ============================================================================== --- stable/11/sys/crypto/sha2/sha512t.h Tue Nov 22 19:31:32 2016 (r309022) +++ stable/11/sys/crypto/sha2/sha512t.h Tue Nov 22 20:28:17 2016 (r309023) @@ -103,7 +103,8 @@ __BEGIN_DECLS void SHA512_224_Init(SHA512_CTX *); void SHA512_224_Update(SHA512_CTX *, const void *, size_t); -void SHA512_224_Final(unsigned char [static SHA512_224_DIGEST_LENGTH], SHA512_CTX *); +void SHA512_224_Final(unsigned char [__min_size(SHA512_224_DIGEST_LENGTH)], + SHA512_CTX *); #ifndef _KERNEL char *SHA512_224_End(SHA512_CTX *, char *); char *SHA512_224_Data(const void *, unsigned int, char *); @@ -112,7 +113,8 @@ char *SHA512_224_FileChunk(const char #endif void SHA512_256_Init(SHA512_CTX *); void SHA512_256_Update(SHA512_CTX *, const void *, size_t); -void SHA512_256_Final(unsigned char [static SHA512_256_DIGEST_LENGTH], SHA512_CTX *); +void SHA512_256_Final(unsigned char [__min_size(SHA512_256_DIGEST_LENGTH)], + SHA512_CTX *); #ifndef _KERNEL char *SHA512_256_End(SHA512_CTX *, char *); char *SHA512_256_Data(const void *, unsigned int, char *); Modified: stable/11/sys/crypto/siphash/siphash.h ============================================================================== --- stable/11/sys/crypto/siphash/siphash.h Tue Nov 22 19:31:32 2016 (r309022) +++ stable/11/sys/crypto/siphash/siphash.h Tue Nov 22 20:28:17 2016 (r309023) @@ -68,15 +68,16 @@ typedef struct _SIPHASH_CTX { #define SipHash24_Init(x) SipHash_InitX((x), 2, 4) #define SipHash48_Init(x) SipHash_InitX((x), 4, 8) void SipHash_InitX(SIPHASH_CTX *, int, int); -void SipHash_SetKey(SIPHASH_CTX *, const uint8_t[static SIPHASH_KEY_LENGTH]); +void SipHash_SetKey(SIPHASH_CTX *, + const uint8_t[__min_size(SIPHASH_KEY_LENGTH)]); void SipHash_Update(SIPHASH_CTX *, const void *, size_t); -void SipHash_Final(uint8_t[static SIPHASH_DIGEST_LENGTH], SIPHASH_CTX *); +void SipHash_Final(uint8_t[__min_size(SIPHASH_DIGEST_LENGTH)], SIPHASH_CTX *); uint64_t SipHash_End(SIPHASH_CTX *); #define SipHash24(x, y, z, i) SipHashX((x), 2, 4, (y), (z), (i)); #define SipHash48(x, y, z, i) SipHashX((x), 4, 8, (y), (z), (i)); -uint64_t SipHashX(SIPHASH_CTX *, int, int, const uint8_t[static SIPHASH_KEY_LENGTH], const void *, - size_t); +uint64_t SipHashX(SIPHASH_CTX *, int, int, + const uint8_t[__min_size(SIPHASH_KEY_LENGTH)], const void *, size_t); int SipHash24_TestVectors(void); Modified: stable/11/sys/crypto/skein/skein_freebsd.h ============================================================================== --- stable/11/sys/crypto/skein/skein_freebsd.h Tue Nov 22 19:31:32 2016 (r309022) +++ stable/11/sys/crypto/skein/skein_freebsd.h Tue Nov 22 20:28:17 2016 (r309023) @@ -57,9 +57,12 @@ void SKEIN256_Update(SKEIN256_CTX *ctx, void SKEIN512_Update(SKEIN512_CTX *ctx, const void *in, size_t len); void SKEIN1024_Update(SKEIN1024_CTX *ctx, const void *in, size_t len); -void SKEIN256_Final(unsigned char digest[static SKEIN256_DIGEST_LENGTH], SKEIN256_CTX *ctx); -void SKEIN512_Final(unsigned char digest[static SKEIN512_DIGEST_LENGTH], SKEIN512_CTX *ctx); -void SKEIN1024_Final(unsigned char digest[static SKEIN1024_DIGEST_LENGTH], SKEIN1024_CTX *ctx); +void SKEIN256_Final(unsigned char digest[__min_size(SKEIN256_DIGEST_LENGTH)], + SKEIN256_CTX *ctx); +void SKEIN512_Final(unsigned char digest[__min_size(SKEIN512_DIGEST_LENGTH)], + SKEIN512_CTX *ctx); +void SKEIN1024_Final(unsigned char digest[__min_size(SKEIN1024_DIGEST_LENGTH)], + SKEIN1024_CTX *ctx); #ifndef _KERNEL char *SKEIN256_End(SKEIN256_CTX *, char *); Modified: stable/11/sys/sys/cdefs.h ============================================================================== --- stable/11/sys/sys/cdefs.h Tue Nov 22 19:31:32 2016 (r309022) +++ stable/11/sys/sys/cdefs.h Tue Nov 22 20:28:17 2016 (r309023) @@ -341,6 +341,20 @@ __builtin_types_compatible_p(__typeof(expr), t), yes, no) #endif +/* + * C99 Static array indices in function parameter declarations. Syntax such as: + * void bar(int myArray[static 10]); + * is allowed in C99 but not in C++. Define __min_size appropriately so + * headers using it can be compiled in either language. Use like this: + * void bar(int myArray[__min_size(10)]); + */ +#if !defined(__cplusplus) && \ + (!defined(__STDC_VERSION) || (__STDC_VERSION__ >= 199901)) +#define __min_size(x) static (x) +#else +#define __min_size(x) (x) +#endif + #if __GNUC_PREREQ__(2, 96) #define __malloc_like __attribute__((__malloc__)) #define __pure __attribute__((__pure__)) Modified: stable/11/sys/sys/md4.h ============================================================================== --- stable/11/sys/sys/md4.h Tue Nov 22 19:31:32 2016 (r309022) +++ stable/11/sys/sys/md4.h Tue Nov 22 20:28:17 2016 (r309023) @@ -39,7 +39,7 @@ __BEGIN_DECLS void MD4Init(MD4_CTX *); void MD4Update(MD4_CTX *, const unsigned char *, unsigned int); void MD4Pad(MD4_CTX *); -void MD4Final(unsigned char [static 16], MD4_CTX *); +void MD4Final(unsigned char [__min_size(16)], MD4_CTX *); #ifndef _KERNEL char * MD4End(MD4_CTX *, char *); char * MD4File(const char *, char *); Modified: stable/11/sys/sys/md5.h ============================================================================== --- stable/11/sys/sys/md5.h Tue Nov 22 19:31:32 2016 (r309022) +++ stable/11/sys/sys/md5.h Tue Nov 22 20:28:17 2016 (r309023) @@ -44,7 +44,7 @@ typedef struct MD5Context { __BEGIN_DECLS void MD5Init (MD5_CTX *); void MD5Update (MD5_CTX *, const void *, unsigned int); -void MD5Final (unsigned char[static MD5_DIGEST_LENGTH], MD5_CTX *); +void MD5Final (unsigned char[__min_size(MD5_DIGEST_LENGTH)], MD5_CTX *); #ifndef _KERNEL char * MD5End(MD5_CTX *, char *); char * MD5File(const char *, char *);