From 7b949262c4c01fdeff30a612d43f4b64f1ad426f Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Fri, 10 May 2013 20:23:01 +0200 Subject: [PATCH] Add __attribute__((warn_unused_result)) to crypto functions. --- configure.ac | 1 + src/cipher.h | 15 +++++++-------- src/digest.h | 6 +++--- src/ecdh.h | 2 +- src/ecdsa.h | 4 ++-- src/ecdsagen.h | 4 ++-- src/prf.h | 2 +- src/rsa.h | 4 ++-- src/rsagen.h | 4 ++-- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/configure.ac b/configure.ac index 5f6bfecd..1cea02fe 100644 --- a/configure.ac +++ b/configure.ac @@ -156,6 +156,7 @@ AC_HEADER_TIME AC_STRUCT_TM tinc_ATTRIBUTE(__malloc__) +tinc_ATTRIBUTE(__warn_unused_result__) AC_CHECK_TYPES([socklen_t, struct ether_header, struct arphdr, struct ether_arp, struct in_addr, struct addrinfo, struct ip, struct icmp, struct in6_addr, struct sockaddr_in6, struct ip6_hdr, struct icmp6_hdr, struct nd_neighbor_solicit, struct nd_opt_hdr], , , [#include "src/have.h"] diff --git a/src/cipher.h b/src/cipher.h index c586fffb..17ca6148 100644 --- a/src/cipher.h +++ b/src/cipher.h @@ -32,15 +32,14 @@ extern cipher_t *cipher_open_blowfish_ofb(void) __attribute__ ((__malloc__)); extern void cipher_close(cipher_t *); extern size_t cipher_keylength(const cipher_t *); extern void cipher_get_key(const cipher_t *, void *); -extern bool cipher_set_key(cipher_t *, void *, bool); -extern bool cipher_set_key_from_rsa(cipher_t *, void *, size_t, bool); -extern bool cipher_set_counter(cipher_t *, const void *, size_t); -extern bool cipher_set_counter_key(cipher_t *, void *); -extern bool cipher_encrypt(cipher_t *, const void *indata, size_t inlen, void *outdata, size_t *outlen, bool oneshot); -extern bool cipher_decrypt(cipher_t *, const void *indata, size_t inlen, void *outdata, size_t *outlen, bool oneshot); -extern bool cipher_counter_xor(cipher_t *, const void *indata, size_t inlen, void *outdata); +extern bool cipher_set_key(cipher_t *, void *, bool) __attribute__ ((__warn_unused_result__)); +extern bool cipher_set_key_from_rsa(cipher_t *, void *, size_t, bool) __attribute__ ((__warn_unused_result__)); +extern bool cipher_set_counter(cipher_t *, const void *, size_t) __attribute__ ((__warn_unused_result__)); +extern bool cipher_set_counter_key(cipher_t *, void *) __attribute__ ((__warn_unused_result__)); +extern bool cipher_encrypt(cipher_t *, const void *indata, size_t inlen, void *outdata, size_t *outlen, bool oneshot) __attribute__ ((__warn_unused_result__)); +extern bool cipher_decrypt(cipher_t *, const void *indata, size_t inlen, void *outdata, size_t *outlen, bool oneshot) __attribute__ ((__warn_unused_result__)); +extern bool cipher_counter_xor(cipher_t *, const void *indata, size_t inlen, void *outdata) __attribute__ ((__warn_unused_result__)); extern int cipher_get_nid(const cipher_t *); extern bool cipher_active(const cipher_t *); - #endif diff --git a/src/digest.h b/src/digest.h index bd9e5875..1e149456 100644 --- a/src/digest.h +++ b/src/digest.h @@ -28,9 +28,9 @@ extern digest_t *digest_open_by_name(const char *name, int maclength) __attribut extern digest_t *digest_open_by_nid(int nid, int maclength) __attribute__ ((__malloc__)); extern digest_t *digest_open_sha1(int maclength) __attribute__ ((__malloc__)); extern void digest_close(digest_t *); -extern bool digest_create(digest_t *, const void *indata, size_t inlen, void *outdata); -extern bool digest_verify(digest_t *, const void *indata, size_t inlen, const void *digestdata); -extern bool digest_set_key(digest_t *, const void *key, size_t len); +extern bool digest_create(digest_t *, const void *indata, size_t inlen, void *outdata) __attribute__ ((__warn_unused_result__)); +extern bool digest_verify(digest_t *, const void *indata, size_t inlen, const void *digestdata) __attribute__ ((__warn_unused_result__)); +extern bool digest_set_key(digest_t *, const void *key, size_t len) __attribute__ ((__warn_unused_result__)); extern int digest_get_nid(const digest_t *); extern size_t digest_keylength(const digest_t *); extern size_t digest_length(const digest_t *); diff --git a/src/ecdh.h b/src/ecdh.h index 881ee924..fbd47292 100644 --- a/src/ecdh.h +++ b/src/ecdh.h @@ -28,7 +28,7 @@ typedef struct ecdh ecdh_t; #endif extern ecdh_t *ecdh_generate_public(void *pubkey) __attribute__ ((__malloc__)); -extern bool ecdh_compute_shared(ecdh_t *ecdh, const void *pubkey, void *shared); +extern bool ecdh_compute_shared(ecdh_t *ecdh, const void *pubkey, void *shared) __attribute__ ((__warn_unused_result__)); extern void ecdh_free(ecdh_t *ecdh); #endif diff --git a/src/ecdsa.h b/src/ecdsa.h index 95612390..d03a58ed 100644 --- a/src/ecdsa.h +++ b/src/ecdsa.h @@ -29,8 +29,8 @@ extern char *ecdsa_get_base64_public_key(ecdsa_t *ecdsa); extern ecdsa_t *ecdsa_read_pem_public_key(FILE *fp) __attribute__ ((__malloc__)); extern ecdsa_t *ecdsa_read_pem_private_key(FILE *fp) __attribute__ ((__malloc__)); extern size_t ecdsa_size(ecdsa_t *ecdsa); -extern bool ecdsa_sign(ecdsa_t *ecdsa, const void *in, size_t inlen, void *out); -extern bool ecdsa_verify(ecdsa_t *ecdsa, const void *in, size_t inlen, const void *out); +extern bool ecdsa_sign(ecdsa_t *ecdsa, const void *in, size_t inlen, void *out) __attribute__ ((__warn_unused_result__)); +extern bool ecdsa_verify(ecdsa_t *ecdsa, const void *in, size_t inlen, const void *out) __attribute__ ((__warn_unused_result__)); extern bool ecdsa_active(ecdsa_t *ecdsa); extern void ecdsa_free(ecdsa_t *ecdsa); diff --git a/src/ecdsagen.h b/src/ecdsagen.h index 621913bc..12e5c003 100644 --- a/src/ecdsagen.h +++ b/src/ecdsagen.h @@ -23,7 +23,7 @@ #include "ecdsa.h" extern ecdsa_t *ecdsa_generate(void) __attribute__ ((__malloc__)); -extern bool ecdsa_write_pem_public_key(ecdsa_t *ecdsa, FILE *fp); -extern bool ecdsa_write_pem_private_key(ecdsa_t *ecdsa, FILE *fp); +extern bool ecdsa_write_pem_public_key(ecdsa_t *ecdsa, FILE *fp) __attribute__ ((__warn_unused_result__)); +extern bool ecdsa_write_pem_private_key(ecdsa_t *ecdsa, FILE *fp) __attribute__ ((__warn_unused_result__)); #endif diff --git a/src/prf.h b/src/prf.h index f7ecc644..ef4b99bb 100644 --- a/src/prf.h +++ b/src/prf.h @@ -20,6 +20,6 @@ #ifndef __TINC_PRF_H__ #define __TINC_PRF_H__ -extern bool prf(const char *secret, size_t secretlen, char *seed, size_t seedlen, char *out, size_t outlen); +extern bool prf(const char *secret, size_t secretlen, char *seed, size_t seedlen, char *out, size_t outlen) __attribute__ ((__warn_unused_result__)); #endif diff --git a/src/rsa.h b/src/rsa.h index 64344b74..f4290d44 100644 --- a/src/rsa.h +++ b/src/rsa.h @@ -30,7 +30,7 @@ extern rsa_t *rsa_set_hex_private_key(char *n, char *e, char *d) __attribute__ ( extern rsa_t *rsa_read_pem_public_key(FILE *fp) __attribute__ ((__malloc__)); extern rsa_t *rsa_read_pem_private_key(FILE *fp) __attribute__ ((__malloc__)); extern size_t rsa_size(rsa_t *rsa); -extern bool rsa_public_encrypt(rsa_t *rsa, void *in, size_t len, void *out); -extern bool rsa_private_decrypt(rsa_t *rsa, void *in, size_t len, void *out); +extern bool rsa_public_encrypt(rsa_t *rsa, void *in, size_t len, void *out) __attribute__ ((__warn_unused_result__)); +extern bool rsa_private_decrypt(rsa_t *rsa, void *in, size_t len, void *out) __attribute__ ((__warn_unused_result__)); #endif diff --git a/src/rsagen.h b/src/rsagen.h index 84cd0bb4..58ce29f0 100644 --- a/src/rsagen.h +++ b/src/rsagen.h @@ -23,7 +23,7 @@ #include "rsa.h" extern rsa_t *rsa_generate(size_t bits, unsigned long exponent) __attribute__ ((__malloc__)); -extern bool rsa_write_pem_public_key(rsa_t *rsa, FILE *fp); -extern bool rsa_write_pem_private_key(rsa_t *rsa, FILE *fp); +extern bool rsa_write_pem_public_key(rsa_t *rsa, FILE *fp) __attribute__ ((__warn_unused_result__)); +extern bool rsa_write_pem_private_key(rsa_t *rsa, FILE *fp) __attribute__ ((__warn_unused_result__)); #endif -- 2.39.5