summaryrefslogtreecommitdiffstats
path: root/providers/implementations/include
diff options
context:
space:
mode:
authorWeiguo Li <liwg06@foxmail.com>2022-02-10 02:30:25 +0800
committerDr. Matthias St. Pierre <matthias.st.pierre@ncp-e.com>2022-02-16 16:11:56 +0100
commit3d27ac8d92ef89c202b518cf6c4e15477eb594b2 (patch)
treec3146e3f1fc6caffde9e0a4afc1466d33022784d /providers/implementations/include
parent17da5f2af833ef16cc2e431359139a4a2e3775b9 (diff)
Add define guards to avoid multi-inclusion
This header files are included by multiple other headers. It's better to add define guards to prevent multi-inclusion. Adhere to the coding style, all preprocessor directives inside the guards gain a space. Signed-off-by: Weiguo Li <liwg06@foxmail.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com> (Merged from https://github.com/openssl/openssl/pull/17666)
Diffstat (limited to 'providers/implementations/include')
-rw-r--r--providers/implementations/include/prov/ciphercommon.h82
-rw-r--r--providers/implementations/include/prov/ciphercommon_aead.h12
-rw-r--r--providers/implementations/include/prov/ciphercommon_ccm.h12
-rw-r--r--providers/implementations/include/prov/ciphercommon_gcm.h22
4 files changed, 76 insertions, 52 deletions
diff --git a/providers/implementations/include/prov/ciphercommon.h b/providers/implementations/include/prov/ciphercommon.h
index 91c4c914be..727c00612f 100644
--- a/providers/implementations/include/prov/ciphercommon.h
+++ b/providers/implementations/include/prov/ciphercommon.h
@@ -7,23 +7,27 @@
* https://www.openssl.org/source/license.html
*/
-#include <openssl/params.h>
-#include <openssl/core_dispatch.h>
-#include <openssl/core_names.h>
-#include <openssl/evp.h>
-#include "internal/cryptlib.h"
-#include "crypto/modes.h"
+#ifndef OSSL_PROV_CIPHERCOMMON_H
+# define OSSL_PROV_CIPHERCOMMON_H
+# pragma once
-#define MAXCHUNK ((size_t)1 << (sizeof(long) * 8 - 2))
-#define MAXBITCHUNK ((size_t)1 << (sizeof(size_t) * 8 - 4))
+# include <openssl/params.h>
+# include <openssl/core_dispatch.h>
+# include <openssl/core_names.h>
+# include <openssl/evp.h>
+# include "internal/cryptlib.h"
+# include "crypto/modes.h"
-#define GENERIC_BLOCK_SIZE 16
-#define IV_STATE_UNINITIALISED 0 /* initial state is not initialized */
-#define IV_STATE_BUFFERED 1 /* iv has been copied to the iv buffer */
-#define IV_STATE_COPIED 2 /* iv has been copied from the iv buffer */
-#define IV_STATE_FINISHED 3 /* the iv has been used - so don't reuse it */
+# define MAXCHUNK ((size_t)1 << (sizeof(long) * 8 - 2))
+# define MAXBITCHUNK ((size_t)1 << (sizeof(size_t) * 8 - 4))
-#define PROV_CIPHER_FUNC(type, name, args) typedef type (* OSSL_##name##_fn)args
+# define GENERIC_BLOCK_SIZE 16
+# define IV_STATE_UNINITIALISED 0 /* initial state is not initialized */
+# define IV_STATE_BUFFERED 1 /* iv has been copied to the iv buffer */
+# define IV_STATE_COPIED 2 /* iv has been copied from the iv buffer */
+# define IV_STATE_FINISHED 3 /* the iv has been used - so don't reuse it */
+
+# define PROV_CIPHER_FUNC(type, name, args) typedef type (* OSSL_##name##_fn)args
typedef struct prov_cipher_hw_st PROV_CIPHER_HW;
typedef struct prov_cipher_ctx_st PROV_CIPHER_CTX;
@@ -32,14 +36,14 @@ typedef int (PROV_CIPHER_HW_FN)(PROV_CIPHER_CTX *dat, unsigned char *out,
const unsigned char *in, size_t len);
/* Internal flags that can be queried */
-#define PROV_CIPHER_FLAG_AEAD 0x0001
-#define PROV_CIPHER_FLAG_CUSTOM_IV 0x0002
-#define PROV_CIPHER_FLAG_CTS 0x0004
-#define PROV_CIPHER_FLAG_TLS1_MULTIBLOCK 0x0008
-#define PROV_CIPHER_FLAG_RAND_KEY 0x0010
+# define PROV_CIPHER_FLAG_AEAD 0x0001
+# define PROV_CIPHER_FLAG_CUSTOM_IV 0x0002
+# define PROV_CIPHER_FLAG_CTS 0x0004
+# define PROV_CIPHER_FLAG_TLS1_MULTIBLOCK 0x0008
+# define PROV_CIPHER_FLAG_RAND_KEY 0x0010
/* Internal flags that are only used within the provider */
-#define PROV_CIPHER_FLAG_VARIABLE_LENGTH 0x0100
-#define PROV_CIPHER_FLAG_INVERSE_CIPHER 0x0200
+# define PROV_CIPHER_FLAG_VARIABLE_LENGTH 0x0100
+# define PROV_CIPHER_FLAG_INVERSE_CIPHER 0x0200
struct prov_cipher_ctx_st {
block128_f block;
@@ -125,7 +129,7 @@ void ossl_cipher_generic_initkey(void *vctx, size_t kbits, size_t blkbits,
uint64_t flags,
const PROV_CIPHER_HW *hw, void *provctx);
-#define IMPLEMENT_generic_cipher_func(alg, UCALG, lcmode, UCMODE, flags, kbits,\
+# define IMPLEMENT_generic_cipher_func(alg, UCALG, lcmode, UCMODE, flags, kbits,\
blkbits, ivbits, typ) \
const OSSL_DISPATCH ossl_##alg##kbits##lcmode##_functions[] = { \
{ OSSL_FUNC_CIPHER_NEWCTX, \
@@ -152,7 +156,7 @@ const OSSL_DISPATCH ossl_##alg##kbits##lcmode##_functions[] = { \
{ 0, NULL } \
};
-#define IMPLEMENT_var_keylen_cipher_func(alg, UCALG, lcmode, UCMODE, flags, \
+# define IMPLEMENT_var_keylen_cipher_func(alg, UCALG, lcmode, UCMODE, flags, \
kbits, blkbits, ivbits, typ) \
const OSSL_DISPATCH ossl_##alg##kbits##lcmode##_functions[] = { \
{ OSSL_FUNC_CIPHER_NEWCTX, \
@@ -180,7 +184,7 @@ const OSSL_DISPATCH ossl_##alg##kbits##lcmode##_functions[] = { \
};
-#define IMPLEMENT_generic_cipher_genfn(alg, UCALG, lcmode, UCMODE, flags, \
+# define IMPLEMENT_generic_cipher_genfn(alg, UCALG, lcmode, UCMODE, flags, \
kbits, blkbits, ivbits, typ) \
static OSSL_FUNC_cipher_get_params_fn alg##_##kbits##_##lcmode##_get_params; \
static int alg##_##kbits##_##lcmode##_get_params(OSSL_PARAM params[]) \
@@ -202,14 +206,14 @@ static void * alg##_##kbits##_##lcmode##_newctx(void *provctx) \
return ctx; \
} \
-#define IMPLEMENT_generic_cipher(alg, UCALG, lcmode, UCMODE, flags, kbits, \
+# define IMPLEMENT_generic_cipher(alg, UCALG, lcmode, UCMODE, flags, kbits, \
blkbits, ivbits, typ) \
IMPLEMENT_generic_cipher_genfn(alg, UCALG, lcmode, UCMODE, flags, kbits, \
blkbits, ivbits, typ) \
IMPLEMENT_generic_cipher_func(alg, UCALG, lcmode, UCMODE, flags, kbits, \
blkbits, ivbits, typ)
-#define IMPLEMENT_var_keylen_cipher(alg, UCALG, lcmode, UCMODE, flags, kbits, \
+# define IMPLEMENT_var_keylen_cipher(alg, UCALG, lcmode, UCMODE, flags, kbits, \
blkbits, ivbits, typ) \
IMPLEMENT_generic_cipher_genfn(alg, UCALG, lcmode, UCMODE, flags, kbits, \
blkbits, ivbits, typ) \
@@ -227,11 +231,11 @@ PROV_CIPHER_HW_FN ossl_cipher_hw_chunked_cbc;
PROV_CIPHER_HW_FN ossl_cipher_hw_chunked_cfb8;
PROV_CIPHER_HW_FN ossl_cipher_hw_chunked_cfb128;
PROV_CIPHER_HW_FN ossl_cipher_hw_chunked_ofb128;
-#define ossl_cipher_hw_chunked_ecb ossl_cipher_hw_generic_ecb
-#define ossl_cipher_hw_chunked_ctr ossl_cipher_hw_generic_ctr
-#define ossl_cipher_hw_chunked_cfb1 ossl_cipher_hw_generic_cfb1
+# define ossl_cipher_hw_chunked_ecb ossl_cipher_hw_generic_ecb
+# define ossl_cipher_hw_chunked_ctr ossl_cipher_hw_generic_ctr
+# define ossl_cipher_hw_chunked_cfb1 ossl_cipher_hw_generic_cfb1
-#define IMPLEMENT_CIPHER_HW_OFB(MODE, NAME, CTX_NAME, KEY_NAME, FUNC_PREFIX) \
+# define IMPLEMENT_CIPHER_HW_OFB(MODE, NAME, CTX_NAME, KEY_NAME, FUNC_PREFIX) \
static int cipher_hw_##NAME##_##MODE##_cipher(PROV_CIPHER_CTX *ctx, \
unsigned char *out, \
const unsigned char *in, size_t len) \
@@ -252,7 +256,7 @@ static int cipher_hw_##NAME##_##MODE##_cipher(PROV_CIPHER_CTX *ctx, \
return 1; \
}
-#define IMPLEMENT_CIPHER_HW_ECB(MODE, NAME, CTX_NAME, KEY_NAME, FUNC_PREFIX) \
+# define IMPLEMENT_CIPHER_HW_ECB(MODE, NAME, CTX_NAME, KEY_NAME, FUNC_PREFIX) \
static int cipher_hw_##NAME##_##MODE##_cipher(PROV_CIPHER_CTX *ctx, \
unsigned char *out, \
const unsigned char *in, size_t len) \
@@ -267,7 +271,7 @@ static int cipher_hw_##NAME##_##MODE##_cipher(PROV_CIPHER_CTX *ctx, \
return 1; \
}
-#define IMPLEMENT_CIPHER_HW_CBC(MODE, NAME, CTX_NAME, KEY_NAME, FUNC_PREFIX) \
+# define IMPLEMENT_CIPHER_HW_CBC(MODE, NAME, CTX_NAME, KEY_NAME, FUNC_PREFIX) \
static int cipher_hw_##NAME##_##MODE##_cipher(PROV_CIPHER_CTX *ctx, \
unsigned char *out, \
const unsigned char *in, size_t len) \
@@ -285,7 +289,7 @@ static int cipher_hw_##NAME##_##MODE##_cipher(PROV_CIPHER_CTX *ctx, \
return 1; \
}
-#define IMPLEMENT_CIPHER_HW_CFB(MODE, NAME, CTX_NAME, KEY_NAME, FUNC_PREFIX) \
+# define IMPLEMENT_CIPHER_HW_CFB(MODE, NAME, CTX_NAME, KEY_NAME, FUNC_PREFIX) \
static int cipher_hw_##NAME##_##MODE##_cipher(PROV_CIPHER_CTX *ctx, \
unsigned char *out, \
const unsigned char *in, size_t len) \
@@ -309,7 +313,7 @@ static int cipher_hw_##NAME##_##MODE##_cipher(PROV_CIPHER_CTX *ctx, \
return 1; \
}
-#define IMPLEMENT_CIPHER_HW_COPYCTX(name, CTX_TYPE) \
+# define IMPLEMENT_CIPHER_HW_COPYCTX(name, CTX_TYPE) \
static void name(PROV_CIPHER_CTX *dst, const PROV_CIPHER_CTX *src) \
{ \
CTX_TYPE *sctx = (CTX_TYPE *)src; \
@@ -319,7 +323,7 @@ static void name(PROV_CIPHER_CTX *dst, const PROV_CIPHER_CTX *src) \
dst->ks = &dctx->ks.ks; \
}
-#define CIPHER_DEFAULT_GETTABLE_CTX_PARAMS_START(name) \
+# define CIPHER_DEFAULT_GETTABLE_CTX_PARAMS_START(name) \
static const OSSL_PARAM name##_known_gettable_ctx_params[] = { \
OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_KEYLEN, NULL), \
OSSL_PARAM_size_t(OSSL_CIPHER_PARAM_IVLEN, NULL), \
@@ -328,7 +332,7 @@ static const OSSL_PARAM name##_known_gettable_ctx_params[] = { \
OSSL_PARAM_octet_string(OSSL_CIPHER_PARAM_IV, NULL, 0), \
OSSL_PARAM_octet_string(OSSL_CIPHER_PARAM_UPDATED_IV, NULL, 0),
-#define CIPHER_DEFAULT_GETTABLE_CTX_PARAMS_END(name) \
+# define CIPHER_DEFAULT_GETTABLE_CTX_PARAMS_END(name) \
OSSL_PARAM_END \
}; \
const OSSL_PARAM * name##_gettable_ctx_params(ossl_unused void *cctx, \
@@ -337,11 +341,11 @@ const OSSL_PARAM * name##_gettable_ctx_params(ossl_unused void *cctx, \
return name##_known_gettable_ctx_params; \
}
-#define CIPHER_DEFAULT_SETTABLE_CTX_PARAMS_START(name) \
+# define CIPHER_DEFAULT_SETTABLE_CTX_PARAMS_START(name) \
static const OSSL_PARAM name##_known_settable_ctx_params[] = { \
OSSL_PARAM_uint(OSSL_CIPHER_PARAM_PADDING, NULL), \
OSSL_PARAM_uint(OSSL_CIPHER_PARAM_NUM, NULL),
-#define CIPHER_DEFAULT_SETTABLE_CTX_PARAMS_END(name) \
+# define CIPHER_DEFAULT_SETTABLE_CTX_PARAMS_END(name) \
OSSL_PARAM_END \
}; \
const OSSL_PARAM * name##_settable_ctx_params(ossl_unused void *cctx, \
@@ -359,3 +363,5 @@ size_t ossl_cipher_fillblock(unsigned char *buf, size_t *buflen,
int ossl_cipher_trailingdata(unsigned char *buf, size_t *buflen,
size_t blocksize,
const unsigned char **in, size_t *inlen);
+
+#endif
diff --git a/providers/implementations/include/prov/ciphercommon_aead.h b/providers/implementations/include/prov/ciphercommon_aead.h
index 1d017175d3..e64f004be2 100644
--- a/providers/implementations/include/prov/ciphercommon_aead.h
+++ b/providers/implementations/include/prov/ciphercommon_aead.h
@@ -7,11 +7,15 @@
* https://www.openssl.org/source/license.html
*/
-#define UNINITIALISED_SIZET ((size_t)-1)
+#ifndef OSSL_PROV_CIPHERCOMMON_AEAD_H
+# define OSSL_PROV_CIPHERCOMMON_AEAD_H
+# pragma once
-#define AEAD_FLAGS (PROV_CIPHER_FLAG_AEAD | PROV_CIPHER_FLAG_CUSTOM_IV)
+# define UNINITIALISED_SIZET ((size_t)-1)
-#define IMPLEMENT_aead_cipher(alg, lc, UCMODE, flags, kbits, blkbits, ivbits) \
+# define AEAD_FLAGS (PROV_CIPHER_FLAG_AEAD | PROV_CIPHER_FLAG_CUSTOM_IV)
+
+# define IMPLEMENT_aead_cipher(alg, lc, UCMODE, flags, kbits, blkbits, ivbits) \
static OSSL_FUNC_cipher_get_params_fn alg##_##kbits##_##lc##_get_params; \
static int alg##_##kbits##_##lc##_get_params(OSSL_PARAM params[]) \
{ \
@@ -45,3 +49,5 @@ const OSSL_DISPATCH ossl_##alg##kbits##lc##_functions[] = { \
(void (*)(void))ossl_cipher_aead_settable_ctx_params }, \
{ 0, NULL } \
}
+
+#endif
diff --git a/providers/implementations/include/prov/ciphercommon_ccm.h b/providers/implementations/include/prov/ciphercommon_ccm.h
index 4c184b395f..93c3d6383d 100644
--- a/providers/implementations/include/prov/ciphercommon_ccm.h
+++ b/providers/implementations/include/prov/ciphercommon_ccm.h
@@ -7,11 +7,15 @@
* https://www.openssl.org/source/license.html
*/
-#include "ciphercommon_aead.h"
+#ifndef OSSL_PROV_CIPHERCOMMON_CCM_H
+# define OSSL_PROV_CIPHERCOMMON_CCM_H
+# pragma once
+
+# include "ciphercommon_aead.h"
typedef struct prov_ccm_hw_st PROV_CCM_HW;
-#if defined(OPENSSL_CPUID_OBJ) && defined(__s390__)
+# if defined(OPENSSL_CPUID_OBJ) && defined(__s390__)
/*-
* KMAC-AES parameter block - begin
* (see z/Architecture Principles of Operation >= SA22-7832-08)
@@ -24,7 +28,7 @@ typedef struct S390X_kmac_params_st {
unsigned char k[32];
} S390X_KMAC_PARAMS;
/* KMAC-AES parameter block - end */
-#endif
+# endif
/* Base structure that is shared by AES & ARIA for CCM MODE */
typedef struct prov_ccm_st {
@@ -98,3 +102,5 @@ int ossl_ccm_generic_auth_encrypt(PROV_CCM_CTX *ctx, const unsigned char *in,
int ossl_ccm_generic_auth_decrypt(PROV_CCM_CTX *ctx, const unsigned char *in,
unsigned char *out, size_t len,
unsigned char *expected_tag, size_t taglen);
+
+#endif
diff --git a/providers/implementations/include/prov/ciphercommon_gcm.h b/providers/implementations/include/prov/ciphercommon_gcm.h
index 7c4a548f9d..801a89b29c 100644
--- a/providers/implementations/include/prov/ciphercommon_gcm.h
+++ b/providers/implementations/include/prov/ciphercommon_gcm.h
@@ -8,16 +8,20 @@
* https://www.openssl.org/source/license.html
*/
-#include <openssl/aes.h>
-#include "ciphercommon_aead.h"
+#ifndef OSSL_PROV_CIPHERCOMMON_GCM_H
+# define OSSL_PROV_CIPHERCOMMON_GCM_H
+# pragma once
+
+# include <openssl/aes.h>
+# include "ciphercommon_aead.h"
typedef struct prov_gcm_hw_st PROV_GCM_HW;
-#define GCM_IV_DEFAULT_SIZE 12 /* IV's for AES_GCM should normally be 12 bytes */
-#define GCM_IV_MAX_SIZE (1024 / 8)
-#define GCM_TAG_MAX_SIZE 16
+# define GCM_IV_DEFAULT_SIZE 12 /* IV's for AES_GCM should normally be 12 bytes */
+# define GCM_IV_MAX_SIZE (1024 / 8)
+# define GCM_TAG_MAX_SIZE 16
-#if defined(OPENSSL_CPUID_OBJ) && defined(__s390__)
+# if defined(OPENSSL_CPUID_OBJ) && defined(__s390__)
/*-
* KMA-GCM-AES parameter block - begin
* (see z/Architecture Principles of Operation >= SA22-7832-11)
@@ -42,7 +46,7 @@ typedef struct S390X_kma_params_st {
unsigned char k[32]; /* key */
} S390X_KMA_PARAMS;
-#endif
+# endif
typedef struct prov_gcm_ctx_st {
unsigned int mode; /* The mode that we are using */
@@ -121,9 +125,11 @@ int ossl_gcm_one_shot(PROV_GCM_CTX *ctx, unsigned char *aad, size_t aad_len,
int ossl_gcm_cipher_update(PROV_GCM_CTX *ctx, const unsigned char *in,
size_t len, unsigned char *out);
-#define GCM_HW_SET_KEY_CTR_FN(ks, fn_set_enc_key, fn_block, fn_ctr) \
+# define GCM_HW_SET_KEY_CTR_FN(ks, fn_set_enc_key, fn_block, fn_ctr) \
ctx->ks = ks; \
fn_set_enc_key(key, keylen * 8, ks); \
CRYPTO_gcm128_init(&ctx->gcm, ks, (block128_f)fn_block); \
ctx->ctr = (ctr128_f)fn_ctr; \
ctx->key_set = 1;
+
+#endif