Tidy up the headers a bit and make them C++-safe.

This commit is contained in:
Dag-Erling Smørgrav 2016-10-03 12:31:16 +02:00 committed by Dag-Erling Smørgrav
parent be954631db
commit b77cb1aeb4
47 changed files with 184 additions and 34 deletions

View file

@ -13,10 +13,10 @@ endif CRYB_CIPHER
if CRYB_CORE
cryb_HEADERS += \
algorithm.h \
attributes.h \
bitwise.h \
core.h \
ctype.h \
defs.h \
endian.h \
memset_s.h \
string.h \

View file

@ -36,6 +36,8 @@
#include <cryb/cipher.h>
CRYB_BEGIN
#define AES_BLOCK_LEN 16
#define aes_digest cryb_aes_digest
@ -59,4 +61,6 @@ void aes_init(aes_ctx *, cipher_mode, const uint8_t *, size_t);
void aes_update(aes_ctx *, const void *, size_t, void *);
void aes_finish(aes_ctx *);
CRYB_END
#endif

View file

@ -35,6 +35,8 @@
#include <cryb/to.h>
#endif
CRYB_BEGIN
typedef enum algorithm_type {
digest_algorithm,
mac_algorithm,
@ -45,4 +47,6 @@ typedef struct algorithm {
const char *name;
} algorithm;
CRYB_END
#endif

View file

@ -35,6 +35,8 @@
#include <cryb/to.h>
#endif
CRYB_BEGIN
#define CRYB_ROL_ROR(N) \
static inline uint##N##_t rol##N(uint##N##_t i, int n) \
{ \
@ -52,4 +54,6 @@ CRYB_ROL_ROR(64);
#undef CRYB_ROL_ROR
CRYB_END
#endif

View file

@ -34,6 +34,8 @@
#include <cryb/to.h>
#endif
CRYB_BEGIN
const char *cryb_cipher_version(void);
#define cipher_ctx cryb_cipher_ctx
@ -73,4 +75,6 @@ const cipher_algorithm *get_cipher_algorithm(const char *);
#define cipher_finish(alg, ctx) \
(alg)->finish((ctx))
CRYB_END
#endif

View file

@ -34,6 +34,10 @@
#include <cryb/to.h>
#endif
CRYB_BEGIN
const char *cryb_core_version(void);
CRYB_END
#endif

View file

@ -34,6 +34,8 @@
#include <cryb/to.h>
#endif
CRYB_BEGIN
const char *cryb_cpe_version(void);
#define cpe_name cryb_cpe_name
@ -109,4 +111,6 @@ wchar_t *cpe_to_wfn(const cpe_name *);
int cpe_copy_attr(cpe_name *, const cpe_name *, int, int);
cpe_name *cpe_upgrade22(const cpe_name *);
CRYB_END
#endif

View file

@ -1,5 +1,5 @@
/*-
* Copyright (c) 2014 Dag-Erling Smørgrav
* Copyright (c) 2014-2016 Dag-Erling Smørgrav
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -27,12 +27,8 @@
* SUCH DAMAGE.
*/
#ifndef CRYB_ATTRIBUTES_H_INCLUDED
#define CRYB_ATTRIBUTES_H_INCLUDED
#ifndef CRYB_TO
#include <cryb/to.h>
#endif
#ifndef CRYB_DEFS_H_INCLUDED
#define CRYB_DEFS_H_INCLUDED
#if defined(__GNUC__) || defined(__clang__)
# define CRYB_PRINTF(fmt, arg) __attribute__((format(printf, fmt, arg)))
@ -46,4 +42,12 @@
# define CRYB_USED
#endif
#ifdef __cplusplus
#define CRYB_BEGIN extern "C" {
#define CRYB_END }
#else
#define CRYB_BEGIN
#define CRYB_END
#endif
#endif

View file

@ -37,6 +37,10 @@
#include <cryb/rfc3986.h>
#include <cryb/rfc4648.h>
CRYB_BEGIN
const char *cryb_enc_version(void);
CRYB_END
#endif

View file

@ -43,6 +43,8 @@
#include <endian.h>
#endif
CRYB_BEGIN
#if !HAVE_DECL_BSWAP16
#define bswap16 cryb_bswap16
#endif
@ -390,4 +392,6 @@ cryb_le64toh(uint64_t u64)
return (u64);
}
CRYB_END
#endif

View file

@ -34,6 +34,8 @@
#include <cryb/to.h>
#endif
CRYB_BEGIN
const char *cryb_hash_version(void);
#define adler32_hash cryb_adler32_hash
@ -52,4 +54,6 @@ uint32_t murmur3_32_hash(const void *, size_t, uint32_t);
uint8_t pearson_hash(const void *, size_t);
uint8_t pearson_hash_str(const char *);
CRYB_END
#endif

View file

@ -36,6 +36,8 @@
#include <cryb/sha1.h>
CRYB_BEGIN
#define HMAC_SHA1_MAC_LEN 20
#define hmac_sha1_ctx cryb_hmac_sha1_ctx
@ -54,4 +56,6 @@ void hmac_sha1_update(hmac_sha1_ctx *, const void *, size_t);
void hmac_sha1_final(hmac_sha1_ctx *, uint8_t *);
void hmac_sha1_complete(const void *, size_t, const void *, size_t, uint8_t *);
CRYB_END
#endif

View file

@ -36,6 +36,8 @@
#include <cryb/sha224.h>
CRYB_BEGIN
#define HMAC_SHA224_MAC_LEN 28
#define hmac_sha224_ctx cryb_hmac_sha224_ctx
@ -54,4 +56,6 @@ void hmac_sha224_update(hmac_sha224_ctx *, const void *, size_t);
void hmac_sha224_final(hmac_sha224_ctx *, uint8_t *);
void hmac_sha224_complete(const void *, size_t, const void *, size_t, uint8_t *);
CRYB_END
#endif

View file

@ -36,6 +36,8 @@
#include <cryb/sha256.h>
CRYB_BEGIN
#define HMAC_SHA256_MAC_LEN 32
#define hmac_sha256_ctx cryb_hmac_sha256_ctx
@ -54,4 +56,6 @@ void hmac_sha256_update(hmac_sha256_ctx *, const void *, size_t);
void hmac_sha256_final(hmac_sha256_ctx *, uint8_t *);
void hmac_sha256_complete(const void *, size_t, const void *, size_t, uint8_t *);
CRYB_END
#endif

View file

@ -36,6 +36,8 @@
#include <cryb/sha384.h>
CRYB_BEGIN
#define HMAC_SHA384_MAC_LEN 48
#define hmac_sha384_ctx cryb_hmac_sha384_ctx
@ -54,4 +56,6 @@ void hmac_sha384_update(hmac_sha384_ctx *, const void *, size_t);
void hmac_sha384_final(hmac_sha384_ctx *, uint8_t *);
void hmac_sha384_complete(const void *, size_t, const void *, size_t, uint8_t *);
CRYB_END
#endif

View file

@ -36,6 +36,8 @@
#include <cryb/sha512.h>
CRYB_BEGIN
#define HMAC_SHA512_MAC_LEN 64
#define hmac_sha512_ctx cryb_hmac_sha512_ctx
@ -54,4 +56,6 @@ void hmac_sha512_update(hmac_sha512_ctx *, const void *, size_t);
void hmac_sha512_final(hmac_sha512_ctx *, uint8_t *);
void hmac_sha512_complete(const void *, size_t, const void *, size_t, uint8_t *);
CRYB_END
#endif

View file

@ -31,14 +31,13 @@
#define CRYB_IMPL_H_INCLUDED
#if HAVE_CONFIG_H
# include "config.h"
#include "config.h"
#endif
#ifndef CRYB_TO
#include <cryb/to.h>
#endif
#include <cryb/attributes.h>
#include <cryb/coverage.h>
#endif

View file

@ -36,6 +36,10 @@
#include <cryb/hmac.h>
CRYB_BEGIN
const char *cryb_mac_version(void);
CRYB_END
#endif

View file

@ -36,6 +36,8 @@
#include <cryb/digest.h>
CRYB_BEGIN
#define MD2_BLOCK_LEN 16
#define MD2_DIGEST_LEN 16
@ -59,10 +61,6 @@ typedef struct
int left; /*!< amount of data in buffer */
} md2_ctx;
#ifdef __cplusplus
extern "C" {
#endif
/**
* \brief MD2 context setup
*
@ -96,8 +94,6 @@ void md2_final( md2_ctx *ctx, uint8_t *output );
*/
void md2_complete( const void *input, int ilen, uint8_t *output );
#ifdef __cplusplus
}
#endif
CRYB_END
#endif /* md2.h */
#endif

View file

@ -36,6 +36,8 @@
#include <cryb/digest.h>
CRYB_BEGIN
#define MD4_BLOCK_LEN 64
#define MD4_DIGEST_LEN 16
@ -100,4 +102,6 @@ void md4_complete( const void *input, int ilen, uint8_t *output );
}
#endif
CRYB_END
#endif

View file

@ -37,6 +37,8 @@
#include <cryb/digest.h>
CRYB_BEGIN
#define MD5_BLOCK_LEN 64
#define MD5_DIGEST_LEN 16
@ -61,4 +63,6 @@ void md5_update(md5_ctx *, const void *, size_t);
void md5_final(md5_ctx *, uint8_t *);
void md5_complete(const void *, size_t, uint8_t *);
CRYB_END
#endif

View file

@ -30,10 +30,12 @@
#ifndef CRYB_MEMSET_S_H_INCLUDED
#define CRYB_MEMSET_S_H_INCLUDED
#ifndef CRYB_TO
#ifndef CRYB_TO_H_INCLUDED
#include <cryb/to.h>
#endif
CRYB_BEGIN
int cryb_memset_s(void *, size_t, int, size_t);
#if !HAVE_MEMSET_S

View file

@ -34,6 +34,8 @@
#include <cryb/to.h>
#endif
CRYB_BEGIN
const char *cryb_mpi_version(void);
#define mpi_add cryb_mpi_add
@ -89,4 +91,6 @@ int mpi_cmp(cryb_mpi *, cryb_mpi *);
int mpi_eq_abs(cryb_mpi *, cryb_mpi *);
int mpi_eq(cryb_mpi *, cryb_mpi *);
CRYB_END
#endif

View file

@ -40,6 +40,8 @@
#include <cryb/oath_hotp.h>
#include <cryb/oath_totp.h>
CRYB_BEGIN
const char *cryb_oath_version(void);
#define oath_key_alloc cryb_oath_key_alloc
@ -64,4 +66,6 @@ struct oath_key *oath_key_dummy(enum oath_mode, enum oath_hash, unsigned int);
const char *oath_mode_name(enum oath_mode);
enum oath_mode oath_mode_value(const char *);
CRYB_END
#endif

View file

@ -34,6 +34,8 @@
#include <cryb/to.h>
#endif
CRYB_BEGIN
/*
* OATH modes
*/
@ -84,4 +86,6 @@ enum oath_hash {
*/
#define OATH_DUMMY_LABEL "oath-dummy@openpam.org"
CRYB_END
#endif

View file

@ -38,6 +38,8 @@
#include <cryb/oath_constants.h>
#include <cryb/oath_types.h>
CRYB_BEGIN
#define oath_hotp cryb_oath_hotp
#define oath_hotp_current cryb_oath_hotp_current
#define oath_hotp_match cryb_oath_hotp_match
@ -46,4 +48,6 @@ unsigned int oath_hotp(const uint8_t *, size_t, uint64_t, unsigned int);
unsigned int oath_hotp_current(struct oath_key *);
int oath_hotp_match(struct oath_key *, unsigned int, int);
CRYB_END
#endif

View file

@ -38,6 +38,8 @@
#include <cryb/oath_constants.h>
#include <cryb/oath_types.h>
CRYB_BEGIN
#define oath_totp cryb_oath_totp
#define oath_totp_current cryb_oath_totp_current
#define oath_totp_match cryb_oath_totp_match
@ -46,4 +48,6 @@ unsigned int oath_totp(const uint8_t *, size_t, unsigned int);
unsigned int oath_totp_current(const struct oath_key *);
int oath_totp_match(struct oath_key *, unsigned int, int);
CRYB_END
#endif

View file

@ -34,6 +34,8 @@
#include <cryb/to.h>
#endif
CRYB_BEGIN
/*
* OATH key and associated parameters
*/
@ -62,4 +64,6 @@ struct oath_key {
uint8_t key[OATH_MAX_KEYLEN];
};
CRYB_END
#endif

View file

@ -34,9 +34,13 @@
#include <cryb/to.h>
#endif
CRYB_BEGIN
const char *cryb_rand_version(void);
#define rand_bytes cryb_rand_bytes
int rand_bytes(uint8_t *, size_t);
CRYB_END
#endif

View file

@ -36,6 +36,8 @@
#include <cryb/cipher.h>
CRYB_BEGIN
#define rc4_digest cryb_rc4_digest
#define rc4_ctx cryb_rc4_ctx
#define rc4_init cryb_rc4_init
@ -52,4 +54,6 @@ void rc4_init(rc4_ctx *, cipher_mode, const uint8_t *, size_t);
void rc4_update(rc4_ctx *, const void *, size_t, void *);
void rc4_finish(rc4_ctx *);
CRYB_END
#endif

View file

@ -34,6 +34,8 @@
#include <cryb/to.h>
#endif
CRYB_BEGIN
/* estimate of output length for percent encoding / decoding */
#define percent_enclen(l) (size_t)((l) * 3)
#define percent_declen(l) (size_t)(l)
@ -43,4 +45,6 @@
int percent_encode(const char *, size_t, char *, size_t *);
int percent_decode(const char *, size_t, char *, size_t *);
CRYB_END
#endif

View file

@ -34,6 +34,8 @@
#include <cryb/to.h>
#endif
CRYB_BEGIN
/* estimate of output length for base32 encoding / decoding */
#define base32_enclen(l) (size_t)(((l + 4) / 5) * 8)
#define base32_declen(l) (size_t)(((l + 7) / 8) * 5)
@ -54,4 +56,6 @@ int base32_decode(const char *, size_t, uint8_t *, size_t *);
int base64_encode(const uint8_t *, size_t, char *, size_t *);
int base64_decode(const char *, size_t, uint8_t *, size_t *);
CRYB_END
#endif

View file

@ -37,6 +37,8 @@
#include <cryb/digest.h>
CRYB_BEGIN
#define SHA1_BLOCK_LEN 64
#define SHA1_DIGEST_LEN 20
@ -61,4 +63,6 @@ void sha1_update(sha1_ctx *, const void *, size_t);
void sha1_final(sha1_ctx *, uint8_t *);
void sha1_complete(const void *, size_t, uint8_t *);
CRYB_END
#endif

View file

@ -33,6 +33,8 @@
#include <cryb/digest.h>
CRYB_BEGIN
#define SHA224_BLOCK_LEN 64
#define SHA224_DIGEST_LEN 28
@ -89,4 +91,6 @@ void sha224_complete(const void *, size_t, uint8_t *);
void pbkdf2_sha224(const uint8_t *, size_t, const uint8_t *, size_t,
uint64_t, uint8_t *, size_t);
CRYB_END
#endif

View file

@ -33,6 +33,8 @@
#include <cryb/digest.h>
CRYB_BEGIN
#define SHA256_BLOCK_LEN 64
#define SHA256_DIGEST_LEN 32
@ -89,4 +91,6 @@ void sha256_complete(const void *, size_t, uint8_t *);
void pbkdf2_sha256(const uint8_t *, size_t, const uint8_t *, size_t,
uint64_t, uint8_t *, size_t);
CRYB_END
#endif

View file

@ -36,6 +36,8 @@
#include <cryb/digest.h>
CRYB_BEGIN
#define SHA384_BLOCK_LEN 128
#define SHA384_DIGEST_LEN 48
@ -59,10 +61,6 @@ typedef struct
}
sha384_ctx;
#ifdef __cplusplus
extern "C" {
#endif
/**
* \brief SHA-384 context setup
*
@ -96,8 +94,6 @@ void sha384_final( sha384_ctx *ctx, uint8_t *output );
*/
void sha384_complete( const void *input, int ilen, uint8_t *output );
#ifdef __cplusplus
}
#endif
CRYB_END
#endif

View file

@ -36,6 +36,8 @@
#include <cryb/digest.h>
CRYB_BEGIN
#define SHA512_BLOCK_LEN 128
#define SHA512_DIGEST_LEN 64
@ -59,10 +61,6 @@ typedef struct
}
sha512_ctx;
#ifdef __cplusplus
extern "C" {
#endif
/**
* \brief SHA-512 context setup
*
@ -96,8 +94,6 @@ void sha512_final( sha512_ctx *ctx, uint8_t *output );
*/
void sha512_complete( const void *input, int ilen, uint8_t *output );
#ifdef __cplusplus
}
#endif
CRYB_END
#endif

View file

@ -34,6 +34,8 @@
#include <cryb/to.h>
#endif
CRYB_BEGIN
#define string_new cryb_string_new
#define string_len cryb_string_len
#define string_buf cryb_string_buf
@ -76,4 +78,6 @@ int string_compare_cs(const string *, const char *, size_t);
int string_equal(const string *, const string *);
int string_equal_cs(const string *, const char *, size_t);
CRYB_END
#endif

View file

@ -34,6 +34,8 @@
#include <cryb/to.h>
#endif
CRYB_BEGIN
size_t cryb_strlcat(char *, const char *, size_t);
#if !HAVE_STRLCAT
@ -41,4 +43,6 @@ size_t cryb_strlcat(char *, const char *, size_t);
#define strlcat(arg, ...) cryb_strlcat(arg, __VA_ARGS__)
#endif
CRYB_END
#endif

View file

@ -34,6 +34,8 @@
#include <cryb/to.h>
#endif
CRYB_BEGIN
int cryb_strlcmp(const char *, const char *, size_t);
#if !HAVE_STRLCMP
@ -41,4 +43,6 @@ int cryb_strlcmp(const char *, const char *, size_t);
#define strlcmp(...) cryb_strlcmp(__VA_ARGS__)
#endif
CRYB_END
#endif

View file

@ -34,6 +34,8 @@
#include <cryb/to.h>
#endif
CRYB_BEGIN
size_t cryb_strlcpy(char *, const char *, size_t);
#if !HAVE_STRLCPY
@ -41,4 +43,6 @@ size_t cryb_strlcpy(char *, const char *, size_t);
#define strlcpy(arg, ...) cryb_strlcpy(arg, __VA_ARGS__)
#endif
CRYB_END
#endif

View file

@ -34,11 +34,12 @@
#include <cryb/to.h>
#endif
#include <cryb/attributes.h>
#include <cryb/coverage.h>
CRYB_DISABLE_COVERAGE
CRYB_BEGIN
const char *cryb_test_version(void);
/*
@ -141,4 +142,6 @@ void t_malloc_printstats(FILE *);
#endif
extern struct t_test t_memory_leak;
CRYB_END
#endif

View file

@ -32,4 +32,6 @@
#define CRYB_TO 20160918
#include <cryb/defs.h>
#endif

View file

@ -34,6 +34,8 @@
#include <cryb/to.h>
#endif
CRYB_BEGIN
size_t cryb_wcslcat(wchar_t *, const wchar_t *, size_t);
#if !HAVE_WCSLCAT
@ -41,4 +43,6 @@ size_t cryb_wcslcat(wchar_t *, const wchar_t *, size_t);
#define wcslcat(arg, ...) cryb_wcslcat(arg, __VA_ARGS__)
#endif
CRYB_END
#endif

View file

@ -34,6 +34,8 @@
#include <cryb/to.h>
#endif
CRYB_BEGIN
int cryb_wcslcmp(const wchar_t *, const wchar_t *, size_t);
#if !HAVE_WCSLCMP
@ -41,4 +43,6 @@ int cryb_wcslcmp(const wchar_t *, const wchar_t *, size_t);
#define wcslcmp(...) cryb_wcslcmp(__VA_ARGS__)
#endif
CRYB_END
#endif

View file

@ -34,6 +34,8 @@
#include <cryb/to.h>
#endif
CRYB_BEGIN
size_t cryb_wcslcpy(wchar_t *, const wchar_t *, size_t);
#if !HAVE_WCSLCPY
@ -41,4 +43,6 @@ size_t cryb_wcslcpy(wchar_t *, const wchar_t *, size_t);
#define wcslcpy(arg, ...) cryb_wcslcpy(arg, __VA_ARGS__)
#endif
CRYB_END
#endif

View file

@ -34,6 +34,8 @@
#include <cryb/to.h>
#endif
CRYB_BEGIN
#define wstring_new cryb_wstring_new
#define wstring_len cryb_wstring_len
#define wstring_buf cryb_wstring_buf
@ -76,4 +78,6 @@ int wstring_compare_wcs(const wstring *, const wchar_t *, size_t);
int wstring_equal(const wstring *, const wstring *);
int wstring_equal_wcs(const wstring *, const wchar_t *, size_t);
CRYB_END
#endif