summaryrefslogtreecommitdiffstats
path: root/sys/crypto
diff options
context:
space:
mode:
authorcem <cem@FreeBSD.org>2016-05-26 19:29:29 +0000
committercem <cem@FreeBSD.org>2016-05-26 19:29:29 +0000
commit444253bba579f26af746a0fbf42b89b8f44298a0 (patch)
treea3f8dd317ab9b8bf2071cc3dc88766e3294342a7 /sys/crypto
parent6aac4cff86e423c72bc1e352d3435843185b5977 (diff)
downloadFreeBSD-src-444253bba579f26af746a0fbf42b89b8f44298a0.zip
FreeBSD-src-444253bba579f26af746a0fbf42b89b8f44298a0.tar.gz
crypto routines: Hint minimum buffer sizes to the compiler
Use the C99 'static' keyword to hint to the compiler IVs and output digest sizes. The keyword informs the compiler of the minimum valid size for a given array. Obviously not every pointer can be validated (i.e., the compiler can produce false negative but not false positive reports). No functional change. No ABI change. Sponsored by: EMC / Isilon Storage Division
Diffstat (limited to 'sys/crypto')
-rw-r--r--sys/crypto/aesni/aesni.h10
-rw-r--r--sys/crypto/aesni/aesni_wrap.c12
-rw-r--r--sys/crypto/sha1.c6
-rw-r--r--sys/crypto/sha1.h12
-rw-r--r--sys/crypto/sha2/sha256.h2
-rw-r--r--sys/crypto/sha2/sha256c.c6
-rw-r--r--sys/crypto/sha2/sha384.h2
-rw-r--r--sys/crypto/sha2/sha512.h2
-rw-r--r--sys/crypto/sha2/sha512c.c8
-rw-r--r--sys/crypto/siphash/siphash.c8
-rw-r--r--sys/crypto/siphash/siphash.h6
11 files changed, 36 insertions, 38 deletions
diff --git a/sys/crypto/aesni/aesni.h b/sys/crypto/aesni/aesni.h
index 3d5adec..b327c01 100644
--- a/sys/crypto/aesni/aesni.h
+++ b/sys/crypto/aesni/aesni.h
@@ -79,23 +79,23 @@ void aesni_set_deckey(const uint8_t *encrypt_schedule /*__aligned(16)*/,
*/
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[AES_BLOCK_LEN]);
+ const uint8_t iv[static 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[AES_BLOCK_LEN]);
+ size_t len, uint8_t *buf, const uint8_t iv[static 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[AES_BLOCK_LEN]);
+ const uint8_t iv[static 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[AES_BLOCK_LEN]);
+ const uint8_t *from, uint8_t *to, const uint8_t iv[static 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[AES_BLOCK_LEN]);
+ const uint8_t *from, uint8_t *to, const uint8_t iv[static AES_BLOCK_LEN]);
/* GCM & GHASH functions */
void AES_GCM_encrypt(const unsigned char *in, unsigned char *out,
diff --git a/sys/crypto/aesni/aesni_wrap.c b/sys/crypto/aesni/aesni_wrap.c
index e5e2a69..22e6afa 100644
--- a/sys/crypto/aesni/aesni_wrap.c
+++ b/sys/crypto/aesni/aesni_wrap.c
@@ -55,7 +55,7 @@ struct blocks8 {
void
aesni_encrypt_cbc(int rounds, const void *key_schedule, size_t len,
- const uint8_t *from, uint8_t *to, const uint8_t iv[AES_BLOCK_LEN])
+ const uint8_t *from, uint8_t *to, const uint8_t iv[static AES_BLOCK_LEN])
{
__m128i tot, ivreg;
size_t i;
@@ -74,7 +74,7 @@ aesni_encrypt_cbc(int rounds, const void *key_schedule, size_t len,
void
aesni_decrypt_cbc(int rounds, const void *key_schedule, size_t len,
- uint8_t *buf, const uint8_t iv[AES_BLOCK_LEN])
+ uint8_t *buf, const uint8_t iv[static AES_BLOCK_LEN])
{
__m128i blocks[8];
struct blocks8 *blks;
@@ -204,7 +204,7 @@ nextc(__m128i x)
void
aesni_encrypt_icm(int rounds, const void *key_schedule, size_t len,
- const uint8_t *from, uint8_t *to, const uint8_t iv[AES_BLOCK_LEN])
+ const uint8_t *from, uint8_t *to, const uint8_t iv[static AES_BLOCK_LEN])
{
__m128i tot;
__m128i tmp1, tmp2, tmp3, tmp4;
@@ -378,7 +378,7 @@ aesni_crypt_xts_block8(int rounds, const __m128i *key_schedule, __m128i *tweak,
static void
aesni_crypt_xts(int rounds, const __m128i *data_schedule,
const __m128i *tweak_schedule, size_t len, const uint8_t *from,
- uint8_t *to, const uint8_t iv[AES_BLOCK_LEN], int do_encrypt)
+ uint8_t *to, const uint8_t iv[static AES_BLOCK_LEN], int do_encrypt)
{
__m128i tweakreg;
uint8_t tweak[AES_XTS_BLOCKSIZE] __aligned(16);
@@ -418,7 +418,7 @@ aesni_crypt_xts(int rounds, const __m128i *data_schedule,
void
aesni_encrypt_xts(int rounds, const void *data_schedule,
const void *tweak_schedule, size_t len, const uint8_t *from, uint8_t *to,
- const uint8_t iv[AES_BLOCK_LEN])
+ const uint8_t iv[static AES_BLOCK_LEN])
{
aesni_crypt_xts(rounds, data_schedule, tweak_schedule, len, from, to,
@@ -428,7 +428,7 @@ aesni_encrypt_xts(int rounds, const void *data_schedule,
void
aesni_decrypt_xts(int rounds, const void *data_schedule,
const void *tweak_schedule, size_t len, const uint8_t *from, uint8_t *to,
- const uint8_t iv[AES_BLOCK_LEN])
+ const uint8_t iv[static AES_BLOCK_LEN])
{
aesni_crypt_xts(rounds, data_schedule, tweak_schedule, len, from, to,
diff --git a/sys/crypto/sha1.c b/sys/crypto/sha1.c
index 208789a..b2451c7 100644
--- a/sys/crypto/sha1.c
+++ b/sys/crypto/sha1.c
@@ -249,16 +249,14 @@ sha1_loop(ctxt, input, len)
}
void
-sha1_result(ctxt, digest0)
- struct sha1_ctxt *ctxt;
- caddr_t digest0;
+sha1_result(struct sha1_ctxt *ctxt, char digest0[static SHA1_RESULTLEN])
{
u_int8_t *digest;
digest = (u_int8_t *)digest0;
sha1_pad(ctxt);
#if BYTE_ORDER == BIG_ENDIAN
- bcopy(&ctxt->h.b8[0], digest, 20);
+ bcopy(&ctxt->h.b8[0], digest, SHA1_RESULTLEN);
#else
digest[0] = ctxt->h.b8[3]; digest[1] = ctxt->h.b8[2];
digest[2] = ctxt->h.b8[1]; digest[3] = ctxt->h.b8[0];
diff --git a/sys/crypto/sha1.h b/sys/crypto/sha1.h
index d32aa8a..d61709e 100644
--- a/sys/crypto/sha1.h
+++ b/sys/crypto/sha1.h
@@ -35,8 +35,8 @@
* implemented by Jun-ichiro itojun Itoh <itojun@itojun.org>
*/
-#ifndef _NETINET6_SHA1_H_
-#define _NETINET6_SHA1_H_
+#ifndef _CRYPTO_SHA1_H_
+#define _CRYPTO_SHA1_H_
struct sha1_ctxt {
union {
@@ -55,11 +55,13 @@ struct sha1_ctxt {
};
typedef struct sha1_ctxt SHA1_CTX;
+#define SHA1_RESULTLEN (160/8)
+
#ifdef _KERNEL
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 *, caddr_t);
+extern void sha1_result(struct sha1_ctxt *, char[static SHA1_RESULTLEN]);
/* compatibilty with other SHA1 source codes */
#define SHA1Init(x) sha1_init((x))
@@ -67,6 +69,4 @@ extern void sha1_result(struct sha1_ctxt *, caddr_t);
#define SHA1Final(x, y) sha1_result((y), (x))
#endif /* _KERNEL */
-#define SHA1_RESULTLEN (160/8)
-
-#endif /*_NETINET6_SHA1_H_*/
+#endif /*_CRYPTO_SHA1_H_*/
diff --git a/sys/crypto/sha2/sha256.h b/sys/crypto/sha2/sha256.h
index 528af1e..17aae7d 100644
--- a/sys/crypto/sha2/sha256.h
+++ b/sys/crypto/sha2/sha256.h
@@ -78,7 +78,7 @@ __BEGIN_DECLS
void SHA256_Init(SHA256_CTX *);
void SHA256_Update(SHA256_CTX *, const void *, size_t);
-void SHA256_Final(unsigned char [SHA256_DIGEST_LENGTH], SHA256_CTX *);
+void SHA256_Final(unsigned char [static SHA256_DIGEST_LENGTH], SHA256_CTX *);
#ifndef _KERNEL
char *SHA256_End(SHA256_CTX *, char *);
char *SHA256_Data(const void *, unsigned int, char *);
diff --git a/sys/crypto/sha2/sha256c.c b/sys/crypto/sha2/sha256c.c
index da9b02c..79ed61d 100644
--- a/sys/crypto/sha2/sha256c.c
+++ b/sys/crypto/sha2/sha256c.c
@@ -287,17 +287,17 @@ SHA256_Update(SHA256_CTX * ctx, const void *in, size_t len)
* and clears the context state.
*/
void
-SHA256_Final(unsigned char digest[32], SHA256_CTX * ctx)
+SHA256_Final(unsigned char digest[static SHA256_DIGEST_LENGTH], SHA256_CTX *ctx)
{
/* Add padding */
SHA256_Pad(ctx);
/* Write the hash */
- be32enc_vect(digest, ctx->state, 32);
+ be32enc_vect(digest, ctx->state, SHA256_DIGEST_LENGTH);
/* Clear the context state */
- memset((void *)ctx, 0, sizeof(*ctx));
+ memset(ctx, 0, sizeof(*ctx));
}
#ifdef WEAK_REFS
diff --git a/sys/crypto/sha2/sha384.h b/sys/crypto/sha2/sha384.h
index ae63ba9..63dd948 100644
--- a/sys/crypto/sha2/sha384.h
+++ b/sys/crypto/sha2/sha384.h
@@ -74,7 +74,7 @@ __BEGIN_DECLS
void SHA384_Init(SHA384_CTX *);
void SHA384_Update(SHA384_CTX *, const void *, size_t);
-void SHA384_Final(unsigned char [SHA384_DIGEST_LENGTH], SHA384_CTX *);
+void SHA384_Final(unsigned char [static SHA384_DIGEST_LENGTH], SHA384_CTX *);
#ifndef _KERNEL
char *SHA384_End(SHA384_CTX *, char *);
char *SHA384_Data(const void *, unsigned int, char *);
diff --git a/sys/crypto/sha2/sha512.h b/sys/crypto/sha2/sha512.h
index da0a018..b008aea 100644
--- a/sys/crypto/sha2/sha512.h
+++ b/sys/crypto/sha2/sha512.h
@@ -77,7 +77,7 @@ __BEGIN_DECLS
void SHA512_Init(SHA512_CTX *);
void SHA512_Update(SHA512_CTX *, const void *, size_t);
-void SHA512_Final(unsigned char [SHA512_DIGEST_LENGTH], SHA512_CTX *);
+void SHA512_Final(unsigned char [static SHA512_DIGEST_LENGTH], SHA512_CTX *);
#ifndef _KERNEL
char *SHA512_End(SHA512_CTX *, char *);
char *SHA512_Data(const void *, unsigned int, char *);
diff --git a/sys/crypto/sha2/sha512c.c b/sys/crypto/sha2/sha512c.c
index 42ad058..5c107ea 100644
--- a/sys/crypto/sha2/sha512c.c
+++ b/sys/crypto/sha2/sha512c.c
@@ -311,7 +311,7 @@ SHA512_Update(SHA512_CTX * ctx, const void *in, size_t len)
* and clears the context state.
*/
void
-SHA512_Final(unsigned char digest[SHA512_DIGEST_LENGTH], SHA512_CTX * ctx)
+SHA512_Final(unsigned char digest[static SHA512_DIGEST_LENGTH], SHA512_CTX *ctx)
{
/* Add padding */
@@ -321,7 +321,7 @@ SHA512_Final(unsigned char digest[SHA512_DIGEST_LENGTH], SHA512_CTX * ctx)
be64enc_vect(digest, ctx->state, SHA512_DIGEST_LENGTH);
/* Clear the context state */
- memset((void *)ctx, 0, sizeof(*ctx));
+ memset(ctx, 0, sizeof(*ctx));
}
/*** SHA-384: *********************************************************/
@@ -361,7 +361,7 @@ SHA384_Update(SHA384_CTX * ctx, const void *in, size_t len)
* and clears the context state.
*/
void
-SHA384_Final(unsigned char digest[SHA384_DIGEST_LENGTH], SHA384_CTX * ctx)
+SHA384_Final(unsigned char digest[static SHA384_DIGEST_LENGTH], SHA384_CTX *ctx)
{
/* Add padding */
@@ -371,7 +371,7 @@ SHA384_Final(unsigned char digest[SHA384_DIGEST_LENGTH], SHA384_CTX * ctx)
be64enc_vect(digest, ctx->state, SHA384_DIGEST_LENGTH);
/* Clear the context state */
- memset((void *)ctx, 0, sizeof(*ctx));
+ memset(ctx, 0, sizeof(*ctx));
}
#ifdef WEAK_REFS
diff --git a/sys/crypto/siphash/siphash.c b/sys/crypto/siphash/siphash.c
index b1395d3..5a22312 100644
--- a/sys/crypto/siphash/siphash.c
+++ b/sys/crypto/siphash/siphash.c
@@ -71,7 +71,7 @@ SipHash_InitX(SIPHASH_CTX *ctx, int rc, int rf)
}
void
-SipHash_SetKey(SIPHASH_CTX *ctx, const uint8_t key[16])
+SipHash_SetKey(SIPHASH_CTX *ctx, const uint8_t key[static SIPHASH_KEY_LENGTH])
{
uint64_t k[2];
@@ -167,7 +167,7 @@ SipHash_Update(SIPHASH_CTX *ctx, const void *src, size_t len)
}
void
-SipHash_Final(void *dst, SIPHASH_CTX *ctx)
+SipHash_Final(uint8_t dst[static SIPHASH_DIGEST_LENGTH], SIPHASH_CTX *ctx)
{
uint64_t r;
@@ -196,8 +196,8 @@ SipHash_End(SIPHASH_CTX *ctx)
}
uint64_t
-SipHashX(SIPHASH_CTX *ctx, int rc, int rf, const uint8_t key[16],
- const void *src, size_t len)
+SipHashX(SIPHASH_CTX *ctx, int rc, int rf,
+ const uint8_t key[static SIPHASH_KEY_LENGTH], const void *src, size_t len)
{
SipHash_InitX(ctx, rc, rf);
diff --git a/sys/crypto/siphash/siphash.h b/sys/crypto/siphash/siphash.h
index bfa01cb..8bbda4f 100644
--- a/sys/crypto/siphash/siphash.h
+++ b/sys/crypto/siphash/siphash.h
@@ -68,14 +68,14 @@ 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 [16]);
+void SipHash_SetKey(SIPHASH_CTX *, const uint8_t[static SIPHASH_KEY_LENGTH]);
void SipHash_Update(SIPHASH_CTX *, const void *, size_t);
-void SipHash_Final(void *, SIPHASH_CTX *);
+void SipHash_Final(uint8_t[static 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 [16], const void *,
+uint64_t SipHashX(SIPHASH_CTX *, int, int, const uint8_t[static SIPHASH_KEY_LENGTH], const void *,
size_t);
int SipHash24_TestVectors(void);
OpenPOWER on IntegriCloud