Skip to content

Commit

Permalink
Merge pull request #4511 from mstarzyk-mobica/mbedtls_private_with_py…
Browse files Browse the repository at this point in the history
…thon

Introduce scripts automating wrapping structs members with MBEDTLS_PRIVATE macro
  • Loading branch information
ronald-cron-arm authored Jun 14, 2021
2 parents 21f8464 + c4c761e commit 823f594
Show file tree
Hide file tree
Showing 111 changed files with 989 additions and 895 deletions.
6 changes: 3 additions & 3 deletions doxygen/mbedtls.doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -1577,13 +1577,13 @@ ENABLE_PREPROCESSING = YES
# compilation will be performed. Macro expansion can be done in a controlled
# way by setting EXPAND_ONLY_PREDEF to YES.

MACRO_EXPANSION = NO
MACRO_EXPANSION = YES

# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
# then the macro expansion is limited to the macros specified with the
# PREDEFINED and EXPAND_AS_DEFINED tags.

EXPAND_ONLY_PREDEF = NO
EXPAND_ONLY_PREDEF = YES

# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files
# pointed to by INCLUDE_PATH will be searched when a #include is found.
Expand Down Expand Up @@ -1630,7 +1630,7 @@ PREDEFINED = WIN32 \
# Use the PREDEFINED tag if you want to use a different macro definition that
# overrules the definition found in the source code.

EXPAND_AS_DEFINED =
EXPAND_AS_DEFINED = MBEDTLS_PRIVATE

# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then
# doxygen's preprocessor will remove all references to function-like macros
Expand Down
11 changes: 6 additions & 5 deletions include/mbedtls/aes.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#ifndef MBEDTLS_AES_H
#define MBEDTLS_AES_H
#include "mbedtls/private_access.h"

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
Expand Down Expand Up @@ -78,9 +79,9 @@ extern "C" {
*/
typedef struct mbedtls_aes_context
{
int nr; /*!< The number of rounds. */
uint32_t *rk; /*!< AES round keys. */
uint32_t buf[68]; /*!< Unaligned data buffer. This buffer can
int MBEDTLS_PRIVATE(nr); /*!< The number of rounds. */
uint32_t *MBEDTLS_PRIVATE(rk); /*!< AES round keys. */
uint32_t MBEDTLS_PRIVATE(buf)[68]; /*!< Unaligned data buffer. This buffer can
hold 32 extra Bytes, which can be used for
one of the following purposes:
<ul><li>Alignment if VIA padlock is
Expand All @@ -97,9 +98,9 @@ mbedtls_aes_context;
*/
typedef struct mbedtls_aes_xts_context
{
mbedtls_aes_context crypt; /*!< The AES context to use for AES block
mbedtls_aes_context MBEDTLS_PRIVATE(crypt); /*!< The AES context to use for AES block
encryption or decryption. */
mbedtls_aes_context tweak; /*!< The AES context used for tweak
mbedtls_aes_context MBEDTLS_PRIVATE(tweak); /*!< The AES context used for tweak
computation. */
} mbedtls_aes_xts_context;
#endif /* MBEDTLS_CIPHER_MODE_XTS */
Expand Down
7 changes: 4 additions & 3 deletions include/mbedtls/arc4.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/
#ifndef MBEDTLS_ARC4_H
#define MBEDTLS_ARC4_H
#include "mbedtls/private_access.h"

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
Expand All @@ -51,9 +52,9 @@ extern "C" {
*/
typedef struct mbedtls_arc4_context
{
int x; /*!< permutation index */
int y; /*!< permutation index */
unsigned char m[256]; /*!< permutation table */
int MBEDTLS_PRIVATE(x); /*!< permutation index */
int MBEDTLS_PRIVATE(y); /*!< permutation index */
unsigned char MBEDTLS_PRIVATE(m)[256]; /*!< permutation table */
}
mbedtls_arc4_context;

Expand Down
5 changes: 3 additions & 2 deletions include/mbedtls/aria.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#ifndef MBEDTLS_ARIA_H
#define MBEDTLS_ARIA_H
#include "mbedtls/private_access.h"

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
Expand Down Expand Up @@ -64,9 +65,9 @@ extern "C" {
*/
typedef struct mbedtls_aria_context
{
unsigned char nr; /*!< The number of rounds (12, 14 or 16) */
unsigned char MBEDTLS_PRIVATE(nr); /*!< The number of rounds (12, 14 or 16) */
/*! The ARIA round keys. */
uint32_t rk[MBEDTLS_ARIA_MAX_ROUNDS + 1][MBEDTLS_ARIA_BLOCKSIZE / 4];
uint32_t MBEDTLS_PRIVATE(rk)[MBEDTLS_ARIA_MAX_ROUNDS + 1][MBEDTLS_ARIA_BLOCKSIZE / 4];
}
mbedtls_aria_context;

Expand Down
25 changes: 13 additions & 12 deletions include/mbedtls/asn1.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
#ifndef MBEDTLS_ASN1_H
#define MBEDTLS_ASN1_H
#include "mbedtls/private_access.h"

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
Expand Down Expand Up @@ -148,9 +149,9 @@ extern "C" {
*/
typedef struct mbedtls_asn1_buf
{
int tag; /**< ASN1 type, e.g. MBEDTLS_ASN1_UTF8_STRING. */
size_t len; /**< ASN1 length, in octets. */
unsigned char *p; /**< ASN1 data, e.g. in ASCII. */
int MBEDTLS_PRIVATE(tag); /**< ASN1 type, e.g. MBEDTLS_ASN1_UTF8_STRING. */
size_t MBEDTLS_PRIVATE(len); /**< ASN1 length, in octets. */
unsigned char *MBEDTLS_PRIVATE(p); /**< ASN1 data, e.g. in ASCII. */
}
mbedtls_asn1_buf;

Expand All @@ -159,9 +160,9 @@ mbedtls_asn1_buf;
*/
typedef struct mbedtls_asn1_bitstring
{
size_t len; /**< ASN1 length, in octets. */
unsigned char unused_bits; /**< Number of unused bits at the end of the string */
unsigned char *p; /**< Raw ASN1 data for the bit string */
size_t MBEDTLS_PRIVATE(len); /**< ASN1 length, in octets. */
unsigned char MBEDTLS_PRIVATE(unused_bits); /**< Number of unused bits at the end of the string */
unsigned char *MBEDTLS_PRIVATE(p); /**< Raw ASN1 data for the bit string */
}
mbedtls_asn1_bitstring;

Expand All @@ -170,8 +171,8 @@ mbedtls_asn1_bitstring;
*/
typedef struct mbedtls_asn1_sequence
{
mbedtls_asn1_buf buf; /**< Buffer containing the given ASN.1 item. */
struct mbedtls_asn1_sequence *next; /**< The next entry in the sequence. */
mbedtls_asn1_buf MBEDTLS_PRIVATE(buf); /**< Buffer containing the given ASN.1 item. */
struct mbedtls_asn1_sequence *MBEDTLS_PRIVATE(next); /**< The next entry in the sequence. */
}
mbedtls_asn1_sequence;

Expand All @@ -180,10 +181,10 @@ mbedtls_asn1_sequence;
*/
typedef struct mbedtls_asn1_named_data
{
mbedtls_asn1_buf oid; /**< The object identifier. */
mbedtls_asn1_buf val; /**< The named value. */
struct mbedtls_asn1_named_data *next; /**< The next entry in the sequence. */
unsigned char next_merged; /**< Merge next item into the current one? */
mbedtls_asn1_buf MBEDTLS_PRIVATE(oid); /**< The object identifier. */
mbedtls_asn1_buf MBEDTLS_PRIVATE(val); /**< The named value. */
struct mbedtls_asn1_named_data *MBEDTLS_PRIVATE(next); /**< The next entry in the sequence. */
unsigned char MBEDTLS_PRIVATE(next_merged); /**< Merge next item into the current one? */
}
mbedtls_asn1_named_data;

Expand Down
7 changes: 4 additions & 3 deletions include/mbedtls/bignum.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
#ifndef MBEDTLS_BIGNUM_H
#define MBEDTLS_BIGNUM_H
#include "mbedtls/private_access.h"

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
Expand Down Expand Up @@ -183,9 +184,9 @@ extern "C" {
*/
typedef struct mbedtls_mpi
{
int s; /*!< Sign: -1 if the mpi is negative, 1 otherwise */
size_t n; /*!< total # of limbs */
mbedtls_mpi_uint *p; /*!< pointer to limbs */
int MBEDTLS_PRIVATE(s); /*!< Sign: -1 if the mpi is negative, 1 otherwise */
size_t MBEDTLS_PRIVATE(n); /*!< total # of limbs */
mbedtls_mpi_uint *MBEDTLS_PRIVATE(p); /*!< pointer to limbs */
}
mbedtls_mpi;

Expand Down
5 changes: 3 additions & 2 deletions include/mbedtls/blowfish.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
#ifndef MBEDTLS_BLOWFISH_H
#define MBEDTLS_BLOWFISH_H
#include "mbedtls/private_access.h"

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
Expand Down Expand Up @@ -57,8 +58,8 @@ extern "C" {
*/
typedef struct mbedtls_blowfish_context
{
uint32_t P[MBEDTLS_BLOWFISH_ROUNDS + 2]; /*!< Blowfish round keys */
uint32_t S[4][256]; /*!< key dependent S-boxes */
uint32_t MBEDTLS_PRIVATE(P)[MBEDTLS_BLOWFISH_ROUNDS + 2]; /*!< Blowfish round keys */
uint32_t MBEDTLS_PRIVATE(S)[4][256]; /*!< key dependent S-boxes */
}
mbedtls_blowfish_context;

Expand Down
5 changes: 3 additions & 2 deletions include/mbedtls/camellia.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
#ifndef MBEDTLS_CAMELLIA_H
#define MBEDTLS_CAMELLIA_H
#include "mbedtls/private_access.h"

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
Expand Down Expand Up @@ -53,8 +54,8 @@ extern "C" {
*/
typedef struct mbedtls_camellia_context
{
int nr; /*!< number of rounds */
uint32_t rk[68]; /*!< CAMELLIA round keys */
int MBEDTLS_PRIVATE(nr); /*!< number of rounds */
uint32_t MBEDTLS_PRIVATE(rk)[68]; /*!< CAMELLIA round keys */
}
mbedtls_camellia_context;

Expand Down
3 changes: 2 additions & 1 deletion include/mbedtls/ccm.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

#ifndef MBEDTLS_CCM_H
#define MBEDTLS_CCM_H
#include "mbedtls/private_access.h"

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
Expand Down Expand Up @@ -77,7 +78,7 @@ extern "C" {
*/
typedef struct mbedtls_ccm_context
{
mbedtls_cipher_context_t cipher_ctx; /*!< The cipher context used. */
mbedtls_cipher_context_t MBEDTLS_PRIVATE(cipher_ctx); /*!< The cipher context used. */
}
mbedtls_ccm_context;

Expand Down
7 changes: 4 additions & 3 deletions include/mbedtls/chacha20.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#ifndef MBEDTLS_CHACHA20_H
#define MBEDTLS_CHACHA20_H
#include "mbedtls/private_access.h"

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
Expand All @@ -51,9 +52,9 @@ extern "C" {

typedef struct mbedtls_chacha20_context
{
uint32_t state[16]; /*! The state (before round operations). */
uint8_t keystream8[64]; /*! Leftover keystream bytes. */
size_t keystream_bytes_used; /*! Number of keystream bytes already used. */
uint32_t MBEDTLS_PRIVATE(state)[16]; /*! The state (before round operations). */
uint8_t MBEDTLS_PRIVATE(keystream8)[64]; /*! Leftover keystream bytes. */
size_t MBEDTLS_PRIVATE(keystream_bytes_used); /*! Number of keystream bytes already used. */
}
mbedtls_chacha20_context;

Expand Down
13 changes: 7 additions & 6 deletions include/mbedtls/chachapoly.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#ifndef MBEDTLS_CHACHAPOLY_H
#define MBEDTLS_CHACHAPOLY_H
#include "mbedtls/private_access.h"

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
Expand Down Expand Up @@ -61,12 +62,12 @@ mbedtls_chachapoly_mode_t;

typedef struct mbedtls_chachapoly_context
{
mbedtls_chacha20_context chacha20_ctx; /**< The ChaCha20 context. */
mbedtls_poly1305_context poly1305_ctx; /**< The Poly1305 context. */
uint64_t aad_len; /**< The length (bytes) of the Additional Authenticated Data. */
uint64_t ciphertext_len; /**< The length (bytes) of the ciphertext. */
int state; /**< The current state of the context. */
mbedtls_chachapoly_mode_t mode; /**< Cipher mode (encrypt or decrypt). */
mbedtls_chacha20_context MBEDTLS_PRIVATE(chacha20_ctx); /**< The ChaCha20 context. */
mbedtls_poly1305_context MBEDTLS_PRIVATE(poly1305_ctx); /**< The Poly1305 context. */
uint64_t MBEDTLS_PRIVATE(aad_len); /**< The length (bytes) of the Additional Authenticated Data. */
uint64_t MBEDTLS_PRIVATE(ciphertext_len); /**< The length (bytes) of the ciphertext. */
int MBEDTLS_PRIVATE(state); /**< The current state of the context. */
mbedtls_chachapoly_mode_t MBEDTLS_PRIVATE(mode); /**< Cipher mode (encrypt or decrypt). */
}
mbedtls_chachapoly_context;

Expand Down
Loading

0 comments on commit 823f594

Please sign in to comment.