Skip to content

Commit

Permalink
Fixed some issues, preventing building project on a mac machine (#37)
Browse files Browse the repository at this point in the history
* Fixed some issues, preventing building a project on mac machine:

- Set up project languages manually to prevent compiler's wrong guess
- Set up current platform explicitly for mac (both Intel and Apple Silicone)
- Fixed a lot of warnings, mostly with PSA crypto documentation

* Removed old architecture set up call

* Moved explicit languages set from project to apple only

* Fixed apple architectures define to support fat binary

* Added CFBundleSignature to Info.plist
  • Loading branch information
ManeFunction authored Jan 9, 2024
1 parent a0d3b95 commit bc636ec
Show file tree
Hide file tree
Showing 19 changed files with 749 additions and 24 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ if(MSVC)
add_compile_options(/MP)
endif()

set(CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD)" CACHE INTERNAL "")
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE INTERNAL "")

# linux detection
Expand All @@ -25,7 +24,9 @@ message("module path = ${CMAKE_MODULE_PATH}")

file(GLOB source "source/*.cpp" "source/*.hpp" "source/*.h")
if (APPLE)
enable_language(C CXX OBJCXX)
set(OBJCPP "source/AppleUtilities.h" "source/AppleUtilities.mm")
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE INTERNAL "")
endif()
add_executable("${PROJECT_NAME}" WIN32 ${source} "source/wxmac.icns" "source/windows.rc" ${OBJCPP})
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
Expand Down
440 changes: 434 additions & 6 deletions mbedtls/include/psa/crypto.h

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions mbedtls/include/psa/crypto_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,16 @@ static inline int psa_key_handle_is_null( psa_key_handle_t handle )
* define any way to create such a key, but it may be possible
* through implementation-specific means.
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
* There was a communication failure inside the implementation.
* \retval #PSA_ERROR_CORRUPTION_DETECTED
* There was a corruption failure inside the implementation.
* \retval #PSA_ERROR_STORAGE_FAILURE
* There was a storage failure that prevented the implementation from
* accessing the key.
* \retval #PSA_ERROR_DATA_INVALID
* The key data was corrupted.
* \retval #PSA_ERROR_DATA_CORRUPT
* The key data was invalid.
* \retval #PSA_ERROR_BAD_STATE
* The library has not been previously initialized by psa_crypto_init().
* It is implementation-dependent whether a failure to initialize
Expand Down Expand Up @@ -150,7 +156,9 @@ psa_status_t psa_open_key( mbedtls_svc_key_id_t key,
* \retval #PSA_ERROR_INVALID_HANDLE
* \p handle is not a valid handle nor \c 0.
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
* There was a communication failure inside the implementation.
* \retval #PSA_ERROR_CORRUPTION_DETECTED
* There was a corruption failure inside the implementation.
* \retval #PSA_ERROR_BAD_STATE
* The library has not been previously initialized by psa_crypto_init().
* It is implementation-dependent whether a failure to initialize
Expand Down
58 changes: 58 additions & 0 deletions mbedtls/include/psa/crypto_extra.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,17 @@ static inline void psa_clear_key_slot_number(
* \retval #PSA_ERROR_NOT_PERMITTED
* The caller is not authorized to register the specified key slot.
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
* There is not enough memory to register the key.
* \retval #PSA_ERROR_INSUFFICIENT_STORAGE
* There is not enough storage to register the key.
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
* There was a failure in communication with the secure element.
* \retval #PSA_ERROR_DATA_INVALID
* The key data is not valid.
* \retval #PSA_ERROR_DATA_CORRUPT
* The key data is corrupted.
* \retval #PSA_ERROR_CORRUPTION_DETECTED
* The key data has been corrupted.
* \retval #PSA_ERROR_BAD_STATE
* The library has not been previously initialized by psa_crypto_init().
* It is implementation-dependent whether a failure to initialize
Expand Down Expand Up @@ -495,9 +501,15 @@ psa_status_t mbedtls_psa_inject_entropy(const uint8_t *seed,
* \param data_length Size of the \p data buffer in bytes.
*
* \retval #PSA_SUCCESS
* Success.
* \retval #PSA_ERROR_INVALID_ARGUMENT
* \p type is not a supported key type, or the key type does not
* support domain parameters, or the domain parameters are not
* valid for the key type.
* \retval #PSA_ERROR_NOT_SUPPORTED
* The key type does not support domain parameters.
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
* There was insufficient memory to store the domain parameters.
*/
psa_status_t psa_set_key_domain_parameters(psa_key_attributes_t *attributes,
psa_key_type_t type,
Expand Down Expand Up @@ -525,7 +537,10 @@ psa_status_t psa_set_key_domain_parameters(psa_key_attributes_t *attributes,
* that make up the key domain parameters data.
*
* \retval #PSA_SUCCESS
* Success.
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
* \p data_size is too small. You can determine a sufficient buffer
* size by calling PSA_KEY_DOMAIN_PARAMETERS_SIZE().
*/
psa_status_t psa_get_key_domain_parameters(
const psa_key_attributes_t *attributes,
Expand Down Expand Up @@ -1354,8 +1369,12 @@ static psa_pake_operation_t psa_pake_operation_init(void);
* \retval #PSA_ERROR_NOT_SUPPORTED
* The \p cipher_suite is not supported or is not valid.
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
* Communication with the peer failed.
* \retval #PSA_ERROR_HARDWARE_FAILURE
* A failure of the random generator hardware.
* \retval #PSA_ERROR_CORRUPTION_DETECTED
* The implementation detected a potential corruption of its internal
* data structures.
* \retval #PSA_ERROR_BAD_STATE
* The library has not been previously initialized by psa_crypto_init().
* It is implementation-dependent whether a failure to initialize
Expand Down Expand Up @@ -1389,11 +1408,18 @@ psa_status_t psa_pake_setup(psa_pake_operation_t *operation,
* \retval #PSA_ERROR_BAD_STATE
* The operation state is not valid (it must have been set up.)
* \retval #PSA_ERROR_CORRUPTION_DETECTED
* The implementation detected a potential corruption of its internal
* data structures.
* \retval #PSA_ERROR_INVALID_HANDLE
* \p password is not a valid key identifier.
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
* Communication with the key store failed.
* \retval #PSA_ERROR_HARDWARE_FAILURE
* A failure of the key store hardware.
* \retval #PSA_ERROR_STORAGE_FAILURE
* Storage failure preventing the key from being retrieved.
* \retval #PSA_ERROR_NOT_PERMITTED
* The key policy does not allow the requested operation.
* \retval #PSA_ERROR_INVALID_ARGUMENT
* \p key is not compatible with the algorithm or the cipher suite.
* \retval #PSA_ERROR_BAD_STATE
Expand Down Expand Up @@ -1430,9 +1456,14 @@ psa_status_t psa_pake_set_password_key(psa_pake_operation_t *operation,
* \retval #PSA_ERROR_BAD_STATE
* The operation state is not valid.
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
* There was insufficient memory to perform the operation.
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
* Communication with the peer failed.
* \retval #PSA_ERROR_HARDWARE_FAILURE
* A failure of the random generator hardware.
* \retval #PSA_ERROR_CORRUPTION_DETECTED
* The implementation detected a potential corruption of its internal
* data structures.
* \retval #PSA_ERROR_INVALID_ARGUMENT
* \p user_id is NULL.
* \retval #PSA_ERROR_BAD_STATE
Expand Down Expand Up @@ -1472,9 +1503,14 @@ psa_status_t psa_pake_set_user(psa_pake_operation_t *operation,
* \retval #PSA_ERROR_NOT_SUPPORTED
* The algorithm doesn't associate a second identity with the session.
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
* There was insufficient memory to perform the operation.
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
* Communication with the peer failed.
* \retval #PSA_ERROR_HARDWARE_FAILURE
* A failure of the random generator hardware.
* \retval #PSA_ERROR_CORRUPTION_DETECTED
* The implementation detected a potential corruption of its internal
* data structures.
* \retval #PSA_ERROR_INVALID_ARGUMENT
* \p user_id is NULL.
* \retval #PSA_ERROR_BAD_STATE
Expand Down Expand Up @@ -1515,8 +1551,12 @@ psa_status_t psa_pake_set_peer(psa_pake_operation_t *operation,
* \retval #PSA_ERROR_NOT_SUPPORTED
* The \p side for this algorithm is not supported or is not valid.
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
* Communication with the peer failed.
* \retval #PSA_ERROR_HARDWARE_FAILURE
* A failure of the random generator hardware.
* \retval #PSA_ERROR_CORRUPTION_DETECTED
* The implementation detected a potential corruption of its internal
* data structures.
* \retval #PSA_ERROR_BAD_STATE
* The library has not been previously initialized by psa_crypto_init().
* It is implementation-dependent whether a failure to initialize
Expand Down Expand Up @@ -1562,10 +1602,16 @@ psa_status_t psa_pake_set_side(psa_pake_operation_t *operation,
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
* The size of the \p output buffer is too small.
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
* There was insufficient memory to perform the operation.
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
* Communication with the peer failed.
* \retval #PSA_ERROR_HARDWARE_FAILURE
* A failure of the random generator hardware.
* \retval #PSA_ERROR_CORRUPTION_DETECTED
* The implementation detected a potential corruption of its internal
* data structures.
* \retval #PSA_ERROR_STORAGE_FAILURE
* Storage failure preventing the key from being retrieved.
* \retval #PSA_ERROR_BAD_STATE
* The library has not been previously initialized by psa_crypto_init().
* It is implementation-dependent whether a failure to initialize
Expand Down Expand Up @@ -1606,10 +1652,16 @@ psa_status_t psa_pake_output(psa_pake_operation_t *operation,
* The operation state is not valid (it must be active, but beyond that
* validity is specific to the algorithm).
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
* There was insufficient memory to perform the operation.
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
* Communication with the peer failed.
* \retval #PSA_ERROR_HARDWARE_FAILURE
* A failure of the random generator hardware.
* \retval #PSA_ERROR_CORRUPTION_DETECTED
* The implementation detected a potential corruption of its internal
* data structures.
* \retval #PSA_ERROR_STORAGE_FAILURE
* Storage failure preventing the key from being retrieved.
* \retval #PSA_ERROR_INVALID_ARGUMENT
* The input is not valid for the algorithm, ciphersuite or \p step.
* \retval #PSA_ERROR_BAD_STATE
Expand Down Expand Up @@ -1669,10 +1721,16 @@ psa_status_t psa_pake_input(psa_pake_operation_t *operation,
* #PSA_KEY_DERIVATION_INPUT_SECRET is not compatible with the output’s
* algorithm.
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
* There was insufficient memory to perform the operation.
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
* Communication with the peer failed.
* \retval #PSA_ERROR_HARDWARE_FAILURE
* A failure of the random generator hardware.
* \retval #PSA_ERROR_CORRUPTION_DETECTED
* The implementation detected a potential corruption of its internal
* data structures.
* \retval #PSA_ERROR_STORAGE_FAILURE
* Storage failure preventing the key from being retrieved.
* \retval #PSA_ERROR_BAD_STATE
* The library has not been previously initialized by psa_crypto_init().
* It is implementation-dependent whether a failure to initialize
Expand Down
24 changes: 23 additions & 1 deletion mbedtls/include/psa/crypto_se_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,9 @@ typedef struct {
* or decrypt
*
* \retval #PSA_SUCCESS
* Success.
* \retval #PSA_ERROR_NOT_SUPPORTED
* The requested algorithm is not supported.
*/
typedef psa_status_t (*psa_drv_se_cipher_setup_t)(psa_drv_se_context_t *drv_context,
void *op_context,
Expand All @@ -408,6 +410,7 @@ typedef psa_status_t (*psa_drv_se_cipher_setup_t)(psa_drv_se_context_t *drv_cont
* \param[in] iv_length The size (in bytes) of the `p_iv` buffer
*
* \retval #PSA_SUCCESS
* Success.
*/
typedef psa_status_t (*psa_drv_se_cipher_set_iv_t)(void *op_context,
const uint8_t *p_iv,
Expand All @@ -430,6 +433,7 @@ typedef psa_status_t (*psa_drv_se_cipher_set_iv_t)(void *op_context,
* of bytes placed in the `p_output` buffer
*
* \retval #PSA_SUCCESS
* Success.
*/
typedef psa_status_t (*psa_drv_se_cipher_update_t)(void *op_context,
const uint8_t *p_input,
Expand All @@ -451,6 +455,7 @@ typedef psa_status_t (*psa_drv_se_cipher_update_t)(void *op_context,
* bytes placed in the `p_output` buffer
*
* \retval #PSA_SUCCESS
* Success.
*/
typedef psa_status_t (*psa_drv_se_cipher_finish_t)(void *op_context,
uint8_t *p_output,
Expand Down Expand Up @@ -486,7 +491,9 @@ typedef psa_status_t (*psa_drv_se_cipher_abort_t)(void *op_context);
* buffer
*
* \retval #PSA_SUCCESS
* Success.
* \retval #PSA_ERROR_NOT_SUPPORTED
* The requested algorithm is not supported.
*/
typedef psa_status_t (*psa_drv_se_cipher_ecb_t)(psa_drv_se_context_t *drv_context,
psa_key_slot_number_t key_slot,
Expand Down Expand Up @@ -555,6 +562,7 @@ typedef struct {
* that make up the returned signature value
*
* \retval #PSA_SUCCESS
* Success.
*/
typedef psa_status_t (*psa_drv_se_asymmetric_sign_t)(psa_drv_se_context_t *drv_context,
psa_key_slot_number_t key_slot,
Expand Down Expand Up @@ -619,6 +627,7 @@ typedef psa_status_t (*psa_drv_se_asymmetric_verify_t)(psa_drv_se_context_t *drv
* the returned output
*
* \retval #PSA_SUCCESS
* Success.
*/
typedef psa_status_t (*psa_drv_se_asymmetric_encrypt_t)(psa_drv_se_context_t *drv_context,
psa_key_slot_number_t key_slot,
Expand Down Expand Up @@ -659,6 +668,7 @@ typedef psa_status_t (*psa_drv_se_asymmetric_encrypt_t)(psa_drv_se_context_t *dr
* that make up the returned output
*
* \retval #PSA_SUCCESS
* Success.
*/
typedef psa_status_t (*psa_drv_se_asymmetric_decrypt_t)(psa_drv_se_context_t *drv_context,
psa_key_slot_number_t key_slot,
Expand Down Expand Up @@ -906,7 +916,9 @@ typedef enum
* The core will record \c *key_slot as the key slot where the key
* is stored and will update the persistent data in storage.
* \retval #PSA_ERROR_NOT_SUPPORTED
* The requested key type is not supported.
* \retval #PSA_ERROR_INSUFFICIENT_STORAGE
* There is not enough storage space for this key.
*/
typedef psa_status_t (*psa_drv_se_allocate_key_t)(
psa_drv_se_context_t *drv_context,
Expand Down Expand Up @@ -1045,12 +1057,19 @@ typedef psa_status_t (*psa_drv_se_destroy_key_t)(
* that make up the key data.
*
* \retval #PSA_SUCCESS
* Success.
* \retval #PSA_ERROR_DOES_NOT_EXIST
* The specified slot is not currently in use.
* \retval #PSA_ERROR_NOT_PERMITTED
* The specified slot is not an external key slot.
* \retval #PSA_ERROR_NOT_SUPPORTED
* The specified key type is not supported.
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
* There was a communication failure with the secure element.
* \retval #PSA_ERROR_HARDWARE_FAILURE
* There was a failure in the secure element.
* \retval #PSA_ERROR_CORRUPTION_DETECTED
* There was a corruption failure in the secure element.
*/
typedef psa_status_t (*psa_drv_se_export_key_t)(psa_drv_se_context_t *drv_context,
psa_key_slot_number_t key,
Expand Down Expand Up @@ -1198,6 +1217,7 @@ typedef struct {
* the key derivation
*
* \retval #PSA_SUCCESS
* Success.
*/
typedef psa_status_t (*psa_drv_se_key_derivation_setup_t)(psa_drv_se_context_t *drv_context,
void *op_context,
Expand All @@ -1218,6 +1238,7 @@ typedef psa_status_t (*psa_drv_se_key_derivation_setup_t)(psa_drv_se_context_t *
* \param[in] collateral_size The size in bytes of the collateral
*
* \retval #PSA_SUCCESS
* Success.
*/
typedef psa_status_t (*psa_drv_se_key_derivation_collateral_t)(void *op_context,
uint32_t collateral_id,
Expand All @@ -1232,7 +1253,7 @@ typedef psa_status_t (*psa_drv_se_key_derivation_collateral_t)(void *op_context,
* \param[in] dest_key The slot where the generated key material
* should be placed
*
* \retval #PSA_SUCCESS
* \retval #PSA_SUCCESS Success.
*/
typedef psa_status_t (*psa_drv_se_key_derivation_derive_t)(void *op_context,
psa_key_slot_number_t dest_key);
Expand All @@ -1247,6 +1268,7 @@ typedef psa_status_t (*psa_drv_se_key_derivation_derive_t)(void *op_context,
* key material placed in `p_output`
*
* \retval #PSA_SUCCESS
* Success.
*/
typedef psa_status_t (*psa_drv_se_key_derivation_export_t)(void *op_context,
uint8_t *p_output,
Expand Down
4 changes: 1 addition & 3 deletions mbedtls/library/bignum.c
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,7 @@ void mpi_mul_hlp( size_t i,
mbedtls_mpi_uint *d,
mbedtls_mpi_uint b )
{
mbedtls_mpi_uint c = 0, t = 0;
mbedtls_mpi_uint c = 0;

#if defined(MULADDC_HUIT)
for( ; i >= 8; i -= 8 )
Expand Down Expand Up @@ -1443,8 +1443,6 @@ void mpi_mul_hlp( size_t i,
}
#endif /* MULADDC_HUIT */

t++;

while( c != 0 )
{
*d += c; c = ( *d < c ); d++;
Expand Down
7 changes: 7 additions & 0 deletions mbedtls/library/psa_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -1684,11 +1684,18 @@ static psa_status_t psa_start_key_creation(
* \retval #PSA_SUCCESS
* The key was successfully created.
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
* There was not enough storage space to create the key.
* \retval #PSA_ERROR_INSUFFICIENT_STORAGE
* There was not enough storage space to create the key.
* \retval #PSA_ERROR_ALREADY_EXISTS
* There is already a key with this identifier.
* \retval #PSA_ERROR_DATA_INVALID
* The key data is not valid.
* \retval #PSA_ERROR_DATA_CORRUPT
* There was an inconsistency between volatile and non-volatile
* storage.
* \retval #PSA_ERROR_STORAGE_FAILURE
* There was a failure in persistent storage.
*
* \return If this function fails, the key slot is an invalid state.
* You must call psa_fail_key_creation() to wipe and free the slot.
Expand Down
Loading

0 comments on commit bc636ec

Please sign in to comment.