Adapt the _ALT style to our new standard

- in .h files: only put the context declaration inside the #ifdef _ALT
  (this was changed in 2.9.0, ie after the original PR)
- in .c file: only leave selftest out of _ALT: even though some function are
  trivial to build from other parts, alt implementors might want to go another
way about them (for efficiency or other reasons)
This commit is contained in:
Manuel Pégourié-Gonnard 2018-05-07 09:58:35 +02:00
parent ce8314f5f0
commit 95d0bdbd84
6 changed files with 27 additions and 27 deletions

View file

@ -29,11 +29,6 @@
#include MBEDTLS_CONFIG_FILE #include MBEDTLS_CONFIG_FILE
#endif #endif
#if !defined(MBEDTLS_AEAD_CHACHA20_POLY1305_ALT)
#include "chacha20.h"
#include "poly1305.h"
#define MBEDTLS_ERR_AEAD_CHACHA20_POLY1305_BAD_INPUT_DATA -0x00047 /**< Invalid input parameter(s). */ #define MBEDTLS_ERR_AEAD_CHACHA20_POLY1305_BAD_INPUT_DATA -0x00047 /**< Invalid input parameter(s). */
#define MBEDTLS_ERR_AEAD_CHACHA20_POLY1305_BAD_STATE -0x00049 /**< The requested operation is not permitted in the current state */ #define MBEDTLS_ERR_AEAD_CHACHA20_POLY1305_BAD_STATE -0x00049 /**< The requested operation is not permitted in the current state */
@ -44,6 +39,11 @@ typedef enum
} }
mbedtls_aead_chacha20_poly1305_mode_t; mbedtls_aead_chacha20_poly1305_mode_t;
#if !defined(MBEDTLS_AEAD_CHACHA20_POLY1305_ALT)
#include "chacha20.h"
#include "poly1305.h"
typedef struct typedef struct
{ {
mbedtls_chacha20_context chacha20_ctx; /** ChaCha20 context */ mbedtls_chacha20_context chacha20_ctx; /** ChaCha20 context */
@ -55,6 +55,10 @@ typedef struct
} }
mbedtls_aead_chacha20_poly1305_context; mbedtls_aead_chacha20_poly1305_context;
#else /* !MBEDTLS_AEAD_CHACHA20_POLY1305_ALT */
#include "aead_chacha20_poly1305_alt.h"
#endif /* !MBEDTLS_AEAD_CHACHA20_POLY1305_ALT */
/** /**
* \brief Initialize ChaCha20-Poly1305 context * \brief Initialize ChaCha20-Poly1305 context
* *
@ -183,10 +187,6 @@ int mbedtls_aead_chacha20_poly1305_update( mbedtls_aead_chacha20_poly1305_contex
int mbedtls_aead_chacha20_poly1305_finish( mbedtls_aead_chacha20_poly1305_context *ctx, int mbedtls_aead_chacha20_poly1305_finish( mbedtls_aead_chacha20_poly1305_context *ctx,
unsigned char mac[16] ); unsigned char mac[16] );
#else /* !MBEDTLS_AEAD_CHACHA20_POLY1305_ALT */
#include "aead_chacha20_poly1305_alt.h"
#endif /* !MBEDTLS_AEAD_CHACHA20_POLY1305_ALT */
/** /**
* \brief Encrypt or decrypt data, and produce a MAC with ChaCha20-Poly1305. * \brief Encrypt or decrypt data, and produce a MAC with ChaCha20-Poly1305.
* *

View file

@ -31,13 +31,13 @@
#include MBEDTLS_CONFIG_FILE #include MBEDTLS_CONFIG_FILE
#endif #endif
#if !defined(MBEDTLS_CHACHA20_ALT)
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#define MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA -0x003B /**< Invalid input parameter(s). */ #define MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA -0x003B /**< Invalid input parameter(s). */
#if !defined(MBEDTLS_CHACHA20_ALT)
typedef struct typedef struct
{ {
uint32_t initial_state[16]; /*! Holds the initial state (before round operations) */ uint32_t initial_state[16]; /*! Holds the initial state (before round operations) */
@ -47,6 +47,10 @@ typedef struct
} }
mbedtls_chacha20_context; mbedtls_chacha20_context;
#else /* MBEDTLS_CHACHA20_ALT */
#include "chacha20_alt.h"
#endif /* MBEDTLS_CHACHA20_ALT */
/** /**
* \brief Initialize ChaCha20 context * \brief Initialize ChaCha20 context
* *
@ -149,10 +153,6 @@ int mbedtls_chacha20_update( mbedtls_chacha20_context *ctx,
const unsigned char *input, const unsigned char *input,
unsigned char *output ); unsigned char *output );
#else /* MBEDTLS_CHACHA20_ALT */
#include "chacha20_alt.h"
#endif /* MBEDTLS_CHACHA20_ALT */
/** /**
* \brief Encrypt or decrypt a message using ChaCha20. * \brief Encrypt or decrypt a message using ChaCha20.
* *

View file

@ -32,10 +32,10 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#if !defined(MBEDTLS_POLY1305_ALT)
#define MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA -0x0041 /**< Invalid input parameter(s). */ #define MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA -0x0041 /**< Invalid input parameter(s). */
#if !defined(MBEDTLS_POLY1305_ALT)
typedef struct typedef struct
{ {
uint32_t r[4]; /** Stores the value for 'r' (low 128 bits of the key) */ uint32_t r[4]; /** Stores the value for 'r' (low 128 bits of the key) */
@ -46,6 +46,10 @@ typedef struct
} }
mbedtls_poly1305_context; mbedtls_poly1305_context;
#else /* MBEDTLS_POLY1305_ALT */
#include "poly1305_alt.h"
#endif /* MBEDTLS_POLY1305_ALT */
/** /**
* \brief Initialize a Poly1305 context * \brief Initialize a Poly1305 context
* *
@ -109,10 +113,6 @@ int mbedtls_poly1305_update( mbedtls_poly1305_context *ctx,
int mbedtls_poly1305_finish( mbedtls_poly1305_context *ctx, int mbedtls_poly1305_finish( mbedtls_poly1305_context *ctx,
unsigned char mac[16] ); unsigned char mac[16] );
#else /* MBEDTLS_POLY1305_ALT */
#include "poly1305_alt.h"
#endif /* MBEDTLS_POLY1305_ALT */
/** /**
* \brief Generate the Poly1305 MAC of some data with the given key. * \brief Generate the Poly1305 MAC of some data with the given key.
* *

View file

@ -291,8 +291,6 @@ int mbedtls_aead_chacha20_poly1305_finish( mbedtls_aead_chacha20_poly1305_contex
return( 0 ); return( 0 );
} }
#endif /* MBEDTLS_AEAD_CHACHA20_POLY1305_ALT */
int mbedtls_aead_chacha20_poly1305_crypt_and_mac ( const unsigned char key[32], int mbedtls_aead_chacha20_poly1305_crypt_and_mac ( const unsigned char key[32],
const unsigned char nonce[12], const unsigned char nonce[12],
mbedtls_aead_chacha20_poly1305_mode_t mode, mbedtls_aead_chacha20_poly1305_mode_t mode,
@ -331,6 +329,8 @@ cleanup:
return( result ); return( result );
} }
#endif /* MBEDTLS_AEAD_CHACHA20_POLY1305_ALT */
#if defined(MBEDTLS_SELF_TEST) #if defined(MBEDTLS_SELF_TEST)
static const unsigned char test_key[1][32] = static const unsigned char test_key[1][32] =

View file

@ -354,8 +354,6 @@ int mbedtls_chacha20_update( mbedtls_chacha20_context *ctx,
return( 0 ); return( 0 );
} }
#endif /* !MBEDTLS_CHACHA20_ALT */
int mbedtls_chacha20_crypt( const unsigned char key[32], int mbedtls_chacha20_crypt( const unsigned char key[32],
const unsigned char nonce[12], const unsigned char nonce[12],
uint32_t counter, uint32_t counter,
@ -383,6 +381,8 @@ cleanup:
return( result ); return( result );
} }
#endif /* !MBEDTLS_CHACHA20_ALT */
#if defined(MBEDTLS_SELF_TEST) #if defined(MBEDTLS_SELF_TEST)
static const unsigned char test_keys[2][32] = static const unsigned char test_keys[2][32] =

View file

@ -390,8 +390,6 @@ int mbedtls_poly1305_finish( mbedtls_poly1305_context *ctx,
return( 0 ); return( 0 );
} }
#endif /* MBEDTLS_POLY1305_ALT */
int mbedtls_poly1305_mac( const unsigned char key[32], int mbedtls_poly1305_mac( const unsigned char key[32],
size_t ilen, size_t ilen,
const unsigned char *input, const unsigned char *input,
@ -417,6 +415,8 @@ cleanup:
return( 0 ); return( 0 );
} }
#endif /* MBEDTLS_POLY1305_ALT */
#if defined(MBEDTLS_SELF_TEST) #if defined(MBEDTLS_SELF_TEST)
static const unsigned char test_keys[2][32] = static const unsigned char test_keys[2][32] =