From 0c58a3933210d6a14b78dbc4a95ba5ad63b509b8 Mon Sep 17 00:00:00 2001 From: Carl Lundin <53273776+lundinc2@users.noreply.github.com> Date: Thu, 8 Oct 2020 13:44:30 -0700 Subject: [PATCH] Submodule PKCS #11 and add Standalone PKCS #11 demos (#323) * Submodule PKCS #11. * Add PKCS #11 demos. --- .gitmodules | 3 + .../FreeRTOSConfig.h | 140 + .../READ_ME_INSTRUCTIONS.url | 5 + .../WIN32.vcxproj | 357 ++ .../WIN32.vcxproj.filters | 660 ++++ .../aws_mbedtls_config.h | 3322 +++++++++++++++++ .../examples/demo_helpers.c | 341 ++ .../examples/demo_helpers.h | 103 + .../examples/management_and_rng.c | 219 ++ .../examples/mechanisms_and_digests.c | 258 ++ .../examples/objects.c | 393 ++ .../examples/pkcs11_demos.h | 56 + .../examples/sign_and_verify.c | 367 ++ .../iot_pkcs11_config.h | 173 + .../Demo/corePKCS11_Windows_Simulator/main.c | 232 ++ .../pkcs11_demo_config.h | 59 + .../pkcs11_demos.sln | 25 + FreeRTOS-Plus/Source/corePKCS11 | 1 + 18 files changed, 6714 insertions(+) create mode 100644 FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/FreeRTOSConfig.h create mode 100644 FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/READ_ME_INSTRUCTIONS.url create mode 100644 FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/WIN32.vcxproj create mode 100644 FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/WIN32.vcxproj.filters create mode 100644 FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/aws_mbedtls_config.h create mode 100644 FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/demo_helpers.c create mode 100644 FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/demo_helpers.h create mode 100644 FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/management_and_rng.c create mode 100644 FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/mechanisms_and_digests.c create mode 100644 FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/objects.c create mode 100644 FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/pkcs11_demos.h create mode 100644 FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/sign_and_verify.c create mode 100644 FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/iot_pkcs11_config.h create mode 100644 FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/main.c create mode 100644 FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/pkcs11_demo_config.h create mode 100644 FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/pkcs11_demos.sln create mode 160000 FreeRTOS-Plus/Source/corePKCS11 diff --git a/.gitmodules b/.gitmodules index c010ac6ee7..29506748a8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -19,3 +19,6 @@ [submodule "FreeRTOS-Plus/Test/CMock"] path = FreeRTOS-Plus/Test/CMock url = https://github.com/ThrowTheSwitch/CMock +[submodule "FreeRTOS-Plus/Source/Application-Protocols/corePKCS11"] + path = FreeRTOS-Plus/Source/corePKCS11 + url = https://github.com/FreeRTOS/corePKCS11.git diff --git a/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/FreeRTOSConfig.h b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/FreeRTOSConfig.h new file mode 100644 index 0000000000..e20f511b7d --- /dev/null +++ b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/FreeRTOSConfig.h @@ -0,0 +1,140 @@ +/* + * FreeRTOS Kernel V10.3.0 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * http://www.freertos.org/a00110.html + * + * The bottom of this file contains some constants specific to running the UDP + * stack in this demo. Constants specific to FreeRTOS+TCP itself (rather than + * the demo) are contained in FreeRTOSIPConfig.h. + *----------------------------------------------------------*/ +#define configUSE_PREEMPTION 1 +#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 +#define configMAX_PRIORITIES ( 7 ) +#define configTICK_RATE_HZ ( 1000 ) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */ +#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 60 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the Win32 thread. */ +#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 2048U * 1024U ) ) +#define configMAX_TASK_NAME_LEN ( 15 ) +#define configUSE_TRACE_FACILITY 0 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_CO_ROUTINES 0 +#define configUSE_MUTEXES 1 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configQUEUE_REGISTRY_SIZE 0 +#define configUSE_APPLICATION_TASK_TAG 0 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configUSE_ALTERNATIVE_API 0 +#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 0 +#define configENABLE_BACKWARD_COMPATIBILITY 1 +#define configSUPPORT_STATIC_ALLOCATION 1 + +/* Hook function related definitions. */ +#define configUSE_TICK_HOOK 0 +#define configUSE_IDLE_HOOK 0 +#define configUSE_MALLOC_FAILED_HOOK 0 +#define configCHECK_FOR_STACK_OVERFLOW 0 /* Not applicable to the Win32 port. */ + +/* Software timer related definitions. */ +#define configUSE_TIMERS 1 +#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) +#define configTIMER_QUEUE_LENGTH 5 +#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) + +/* Event group related definitions. */ +#define configUSE_EVENT_GROUPS 1 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + +/* Set the following definitions to 1 to include the API function, or zero +to exclude the API function. */ +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_uxTaskGetStackHighWaterMark 1 +#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_xTimerGetTimerTaskHandle 0 +#define INCLUDE_xTaskGetIdleTaskHandle 0 +#define INCLUDE_xQueueGetMutexHolder 1 +#define INCLUDE_eTaskGetState 1 +#define INCLUDE_xEventGroupSetBitsFromISR 1 +#define INCLUDE_xTimerPendFunctionCall 1 +#define INCLUDE_pcTaskGetTaskName 1 + +/* This demo makes use of one or more example stats formatting functions. These +format the raw data provided by the uxTaskGetSystemState() function in to human +readable ASCII form. See the notes in the implementation of vTaskList() within +FreeRTOS/Source/tasks.c for limitations. configUSE_STATS_FORMATTING_FUNCTIONS +is set to 2 so the formatting functions are included without the stdio.h being +included in tasks.c. That is because this project defines its own sprintf() +functions. */ +#define configUSE_STATS_FORMATTING_FUNCTIONS 1 + +/* Assert call defined for debug builds. */ +#ifdef _DEBUG + extern void vAssertCalled( const char *pcFile, uint32_t ulLine ); + #define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled( __FILE__, __LINE__ ) +#endif /* _DEBUG */ + + + +/* Application specific definitions follow. **********************************/ + +/* Only used when running in the FreeRTOS Windows simulator. Defines the +priority of the task used to simulate Ethernet interrupts. */ + +#if( defined( _MSC_VER ) && ( _MSC_VER <= 1600 ) && !defined( snprintf ) ) + /* Map to Windows names. */ + #define snprintf _snprintf + #define vsnprintf _vsnprintf +#endif + +/* Visual studio does not have an implementation of strcasecmp(). */ +#define strcasecmp _stricmp +#define strncasecmp _strnicmp +#define strcmpi _strcmpi + +#define configPRINTF( X ) printf X + +#endif /* FREERTOS_CONFIG_H */ + diff --git a/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/READ_ME_INSTRUCTIONS.url b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/READ_ME_INSTRUCTIONS.url new file mode 100644 index 0000000000..e8a8aa27f6 --- /dev/null +++ b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/READ_ME_INSTRUCTIONS.url @@ -0,0 +1,5 @@ +[{000214A0-0000-0000-C000-000000000046}] +Prop3=19,11 +[InternetShortcut] +IDList= +URL=https://www.freertos.org/pkcs11/ diff --git a/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/WIN32.vcxproj b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/WIN32.vcxproj new file mode 100644 index 0000000000..2b0985c5e0 --- /dev/null +++ b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/WIN32.vcxproj @@ -0,0 +1,357 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {C686325E-3261-42F7-AEB1-DDE5280E1CEB} + RTOSDemo + 10.0 + + + + Application + false + MultiByte + v142 + + + Application + false + MultiByte + v142 + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + .\Debug\ + .\Debug\ + true + .\Release\ + .\Release\ + false + AllRules.ruleset + + + + .\Debug/WIN32.tlb + + + + + Disabled + ..\..\..\FreeRTOS-Plus\Demo\Common\Logging;..\..\..\FreeRTOS-Plus\Source\corePKCS11\source\include;..\..\..\FreeRTOS-Plus\Source\corePKCS11\source\portable\mbedtls\include;..\..\..\FreeRTOS-Plus\Source\corePKCS11\3rdparty\pkcs11;..\..\..\FreeRTOS-Plus\Source\corePKCS11\3rdparty\mbedtls\include;..\..\..\FreeRTOS-Plus\Source\corePKCS11\3rdparty\mbedtls_utils;..\..\..\FreeRTOS\Source\include;..\..\..\FreeRTOS\Source\portable\MSVC-MingW;examples;.;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;WINVER=0x400;_CRT_SECURE_NO_WARNINGS;MBEDTLS_CONFIG_FILE="aws_mbedtls_config.h";CONFIG_MEDTLS_USE_AFR_MEMORY;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDLL + .\Debug/WIN32.pch + .\Debug/ + .\Debug/ + .\Debug/ + Level4 + true + false + EditAndContinue + /wd4210 /wd4127 /wd4214 /wd4201 /wd4244 /wd4310 /wd4200 %(AdditionalOptions) + true + NotUsing + false + CompileAsC + 4204;4221;%(DisableSpecificWarnings) + + + _DEBUG;%(PreprocessorDefinitions) + 0x0c09 + + + .\Debug/RTOSDemo.exe + true + true + .\Debug/WIN32.pdb + Console + MachineX86 + %(AdditionalDependencies) + + + false + false + + + true + .\Debug/WIN32.bsc + + + + + .\Release/WIN32.tlb + + + + + MaxSpeed + OnlyExplicitInline + _WINSOCKAPI_;WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + MultiThreaded + true + .\Release/WIN32.pch + .\Release/ + .\Release/ + .\Release/ + Level3 + true + ..\Common\Utils;..\Common\ethernet\lwip-1.4.0\ports\win32\WinPCap;..\Common\ethernet\lwip-1.4.0\src\include\ipv4;..\Common\ethernet\lwip-1.4.0\src\include;..\..\..\Source\include;..\..\..\Source\portable\MSVC-MingW;..\Common\ethernet\lwip-1.4.0\ports\win32\include;..\Common\Include;.\lwIP_Apps;.;%(AdditionalIncludeDirectories) + + + NDEBUG;%(PreprocessorDefinitions) + 0x0c09 + + + .\Release/RTOSDemo.exe + true + .\Release/WIN32.pdb + Console + MachineX86 + ..\Common\ethernet\lwip-1.4.0\ports\win32\WinPCap + wpcap.lib;%(AdditionalDependencies) + + + true + .\Release/WIN32.bsc + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/WIN32.vcxproj.filters b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/WIN32.vcxproj.filters new file mode 100644 index 0000000000..5c67634249 --- /dev/null +++ b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/WIN32.vcxproj.filters @@ -0,0 +1,660 @@ + + + + + {af3445a1-4908-4170-89ed-39345d90d30c} + + + {f32be356-4763-4cae-9020-974a2638cb08} + *.c + + + {88f409e6-d396-4ac5-94bd-7a99c914be46} + + + {d2dcd641-8d91-492b-852f-5563ffadaec6} + + + {6a7d78a6-4f09-4a5f-a692-ce4791240881} + + + {e32be358-792b-45ab-b1c5-f87e64315cd3} + + + {44f1dc25-5639-4f3f-a6ec-f5c19cb7fe8d} + + + {78a81f37-e1f1-4ef1-b067-bb23c8e1dfe2} + + + {38512398-609b-4a9b-bc1a-67cab17720ae} + + + {dc5729ea-7c04-484d-babd-d3537c27b7a1} + + + {e88d4eab-3fad-4755-a5a4-41c6e4f59089} + + + {817c6143-0ae9-4cac-828f-08f0da380f99} + + + {8ffa2635-7ef9-4c6b-b392-96e0cc935ad3} + + + {30af02a1-fc2d-4142-b173-508ece3f033d} + + + + + + FreeRTOS\Source + + + FreeRTOS\Source + + + FreeRTOS\Source + + + FreeRTOS\Source + + + FreeRTOS\Source + + + FreeRTOS\Source + + + FreeRTOS\Source + + + FreeRTOS\Source\Portable + + + FreeRTOS\Source\Portable + + + examples + + + examples + + + examples + + + examples + + + examples + + + corePKCS11\source + + + corePKCS11\source + + + corePKCS11\source + + + corePKCS11\source + + + 3rdparty\mbedtls_utils + + + 3rdparty\mbedtls_utils + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + 3rdparty\mbedtls + + + + + + FreeRTOS\Source\include + + + FreeRTOS\Source\include + + + FreeRTOS\Source\include + + + FreeRTOS\Source\include + + + FreeRTOS\Source\include + + + FreeRTOS\Source\include + + + FreeRTOS\Source\include + + + FreeRTOS\Source\include + + + FreeRTOS\Source\include + + + + + examples + + + examples + + + corePKCS11\include + + + corePKCS11\include + + + corePKCS11\include + + + corePKCS11\include + + + 3rdparty\pkcs11 + + + 3rdparty\pkcs11 + + + 3rdparty\pkcs11 + + + 3rdparty\mbedtls_utils + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + 3rdparty\mbedtls\include + + + Common + + + Common + + + + + 3rdparty\mbedtls + + + + + 3rdparty\mbedtls + + + \ No newline at end of file diff --git a/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/aws_mbedtls_config.h b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/aws_mbedtls_config.h new file mode 100644 index 0000000000..24df60316a --- /dev/null +++ b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/aws_mbedtls_config.h @@ -0,0 +1,3322 @@ +/** + * \file config.h + * + * \brief Configuration options (set of defines) + * + * This set of compile-time options may be used to enable + * or disable features selectively, and reduce the global + * memory footprint. + */ +/* + * Copyright (C) 2006-2018, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is part of mbed TLS (https://tls.mbed.org) + */ + +#ifndef MBEDTLS_CONFIG_H +#define MBEDTLS_CONFIG_H + +#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) +#define _CRT_SECURE_NO_DEPRECATE 1 +#endif + +/** + * \name SECTION: System support + * + * This section sets system specific settings. + * \{ + */ + +/** + * \def MBEDTLS_HAVE_ASM + * + * The compiler has support for asm(). + * + * Requires support for asm() in compiler. + * + * Used in: + * library/aria.c + * library/timing.c + * include/mbedtls/bn_mul.h + * + * Required by: + * MBEDTLS_AESNI_C + * MBEDTLS_PADLOCK_C + * + * Comment to disable the use of assembly code. + */ +#define MBEDTLS_HAVE_ASM + + /** + * \def MBEDTLS_NO_UDBL_DIVISION + * + * The platform lacks support for double-width integer division (64-bit + * division on a 32-bit platform, 128-bit division on a 64-bit platform). + * + * Used in: + * include/mbedtls/bignum.h + * library/bignum.c + * + * The bignum code uses double-width division to speed up some operations. + * Double-width division is often implemented in software that needs to + * be linked with the program. The presence of a double-width integer + * type is usually detected automatically through preprocessor macros, + * but the automatic detection cannot know whether the code needs to + * and can be linked with an implementation of division for that type. + * By default division is assumed to be usable if the type is present. + * Uncomment this option to prevent the use of double-width division. + * + * Note that division for the native integer type is always required. + * Furthermore, a 64-bit type is always required even on a 32-bit + * platform, but it need not support multiplication or division. In some + * cases it is also desirable to disable some double-width operations. For + * example, if double-width division is implemented in software, disabling + * it can reduce code size in some embedded targets. + */ +//#define MBEDTLS_NO_UDBL_DIVISION + +/** + * \def MBEDTLS_NO_64BIT_MULTIPLICATION + * + * The platform lacks support for 32x32 -> 64-bit multiplication. + * + * Used in: + * library/poly1305.c + * + * Some parts of the library may use multiplication of two unsigned 32-bit + * operands with a 64-bit result in order to speed up computations. On some + * platforms, this is not available in hardware and has to be implemented in + * software, usually in a library provided by the toolchain. + * + * Sometimes it is not desirable to have to link to that library. This option + * removes the dependency of that library on platforms that lack a hardware + * 64-bit multiplier by embedding a software implementation in Mbed TLS. + * + * Note that depending on the compiler, this may decrease performance compared + * to using the library function provided by the toolchain. + */ +//#define MBEDTLS_NO_64BIT_MULTIPLICATION + +/** + * \def MBEDTLS_HAVE_SSE2 + * + * CPU supports SSE2 instruction set. + * + * Uncomment if the CPU supports SSE2 (IA-32 specific). + */ +//#define MBEDTLS_HAVE_SSE2 + +/** + * \def MBEDTLS_HAVE_TIME + * + * System has time.h and time(). + * The time does not need to be correct, only time differences are used, + * by contrast with MBEDTLS_HAVE_TIME_DATE + * + * Defining MBEDTLS_HAVE_TIME allows you to specify MBEDTLS_PLATFORM_TIME_ALT, + * MBEDTLS_PLATFORM_TIME_MACRO, MBEDTLS_PLATFORM_TIME_TYPE_MACRO and + * MBEDTLS_PLATFORM_STD_TIME. + * + * Comment if your system does not support time functions + */ +//#define MBEDTLS_HAVE_TIME + +/** + * \def MBEDTLS_HAVE_TIME_DATE + * + * System has time.h, time(), and an implementation for + * mbedtls_platform_gmtime_r() (see below). + * The time needs to be correct (not necesarily very accurate, but at least + * the date should be correct). This is used to verify the validity period of + * X.509 certificates. + * + * Comment if your system does not have a correct clock. + * + * \note mbedtls_platform_gmtime_r() is an abstraction in platform_util.h that + * behaves similarly to the gmtime_r() function from the C standard. Refer to + * the documentation for mbedtls_platform_gmtime_r() for more information. + * + * \note It is possible to configure an implementation for + * mbedtls_platform_gmtime_r() at compile-time by using the macro + * MBEDTLS_PLATFORM_GMTIME_R_ALT. + */ +//#define MBEDTLS_HAVE_TIME_DATE + +/** + * \def MBEDTLS_CHECK_PARAMS_ASSERT + * + * Allow MBEDTLS_PARAM_FAILED() to call `assert`, and make it default to + * `assert`. This macro is only used if #MBEDTLS_CHECK_PARAMS is defined. + * + * If this macro is not defined, then MBEDTLS_PARAM_FAILED() defaults to + * calling a function mbedtls_param_failed(). See the documentation of + * #MBEDTLS_CHECK_PARAMS for details. + * + * Uncomment to allow MBEDTLS_PARAM_FAILED() to call `assert`. + */ +//#define MBEDTLS_CHECK_PARAMS_ASSERT + +/** + * \def MBEDTLS_PLATFORM_MEMORY + * + * Enable the memory allocation layer. + * + * By default mbed TLS uses the system-provided calloc() and free(). + * This allows different allocators (self-implemented or provided) to be + * provided to the platform abstraction layer. + * + * Enabling MBEDTLS_PLATFORM_MEMORY without the + * MBEDTLS_PLATFORM_{FREE,CALLOC}_MACROs will provide + * "mbedtls_platform_set_calloc_free()" allowing you to set an alternative calloc() and + * free() function pointer at runtime. + * + * Enabling MBEDTLS_PLATFORM_MEMORY and specifying + * MBEDTLS_PLATFORM_{CALLOC,FREE}_MACROs will allow you to specify the + * alternate function at compile time. + * + * Requires: MBEDTLS_PLATFORM_C + * + * Enable this layer to allow use of alternative memory allocators. + */ +#define MBEDTLS_PLATFORM_MEMORY + +#include + +extern void * pvCalloc( size_t xNumElements, + size_t xSize ) ; +extern void vPortFree( void *pv ); +#define MBEDTLS_PLATFORM_CALLOC_MACRO pvCalloc +#define MBEDTLS_PLATFORM_FREE_MACRO vPortFree + +/** + * \def MBEDTLS_PLATFORM_NO_STD_FUNCTIONS + * + * Do not assign standard functions in the platform layer (e.g. calloc() to + * MBEDTLS_PLATFORM_STD_CALLOC and printf() to MBEDTLS_PLATFORM_STD_PRINTF) + * + * This makes sure there are no linking errors on platforms that do not support + * these functions. You will HAVE to provide alternatives, either at runtime + * via the platform_set_xxx() functions or at compile time by setting + * the MBEDTLS_PLATFORM_STD_XXX defines, or enabling a + * MBEDTLS_PLATFORM_XXX_MACRO. + * + * Requires: MBEDTLS_PLATFORM_C + * + * Uncomment to prevent default assignment of standard functions in the + * platform layer. + */ +//#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS + +/** + * \def MBEDTLS_PLATFORM_EXIT_ALT + * + * MBEDTLS_PLATFORM_XXX_ALT: Uncomment a macro to let mbed TLS support the + * function in the platform abstraction layer. + * + * Example: In case you uncomment MBEDTLS_PLATFORM_PRINTF_ALT, mbed TLS will + * provide a function "mbedtls_platform_set_printf()" that allows you to set an + * alternative printf function pointer. + * + * All these define require MBEDTLS_PLATFORM_C to be defined! + * + * \note MBEDTLS_PLATFORM_SNPRINTF_ALT is required on Windows; + * it will be enabled automatically by check_config.h + * + * \warning MBEDTLS_PLATFORM_XXX_ALT cannot be defined at the same time as + * MBEDTLS_PLATFORM_XXX_MACRO! + * + * Requires: MBEDTLS_PLATFORM_TIME_ALT requires MBEDTLS_HAVE_TIME + * + * Uncomment a macro to enable alternate implementation of specific base + * platform function + */ +//#define MBEDTLS_PLATFORM_EXIT_ALT +//#define MBEDTLS_PLATFORM_TIME_ALT +//#define MBEDTLS_PLATFORM_FPRINTF_ALT +//#define MBEDTLS_PLATFORM_PRINTF_ALT +//#define MBEDTLS_PLATFORM_SNPRINTF_ALT +//#define MBEDTLS_PLATFORM_NV_SEED_ALT +//#define MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT + +/** + * \def MBEDTLS_DEPRECATED_WARNING + * + * Mark deprecated functions so that they generate a warning if used. + * Functions deprecated in one version will usually be removed in the next + * version. You can enable this to help you prepare the transition to a new + * major version by making sure your code is not using these functions. + * + * This only works with GCC and Clang. With other compilers, you may want to + * use MBEDTLS_DEPRECATED_REMOVED + * + * Uncomment to get warnings on using deprecated functions. + */ +//#define MBEDTLS_DEPRECATED_WARNING + +/** + * \def MBEDTLS_DEPRECATED_REMOVED + * + * Remove deprecated functions so that they generate an error if used. + * Functions deprecated in one version will usually be removed in the next + * version. You can enable this to help you prepare the transition to a new + * major version by making sure your code is not using these functions. + * + * Uncomment to get errors on using deprecated functions. + */ +#define MBEDTLS_DEPRECATED_REMOVED + +/** + * \def MBEDTLS_CHECK_PARAMS + * + * This configuration option controls whether the library validates more of + * the parameters passed to it. + * + * When this flag is not defined, the library only attempts to validate an + * input parameter if: (1) they may come from the outside world (such as the + * network, the filesystem, etc.) or (2) not validating them could result in + * internal memory errors such as overflowing a buffer controlled by the + * library. On the other hand, it doesn't attempt to validate parameters whose + * values are fully controlled by the application (such as pointers). + * + * When this flag is defined, the library additionally attempts to validate + * parameters that are fully controlled by the application, and should always + * be valid if the application code is fully correct and trusted. + * + * For example, when a function accepts as input a pointer to a buffer that may + * contain untrusted data, and its documentation mentions that this pointer + * must not be NULL: + * - the pointer is checked to be non-NULL only if this option is enabled + * - the content of the buffer is always validated + * + * When this flag is defined, if a library function receives a parameter that + * is invalid, it will: + * - invoke the macro MBEDTLS_PARAM_FAILED() which by default expands to a + * call to the function mbedtls_param_failed() + * - immediately return (with a specific error code unless the function + * returns void and can't communicate an error). + * + * When defining this flag, you also need to: + * - either provide a definition of the function mbedtls_param_failed() in + * your application (see platform_util.h for its prototype) as the library + * calls that function, but does not provide a default definition for it, + * - or provide a different definition of the macro MBEDTLS_PARAM_FAILED() + * below if the above mechanism is not flexible enough to suit your needs. + * See the documentation of this macro later in this file. + * + * Uncomment to enable validation of application-controlled parameters. + */ +//#define MBEDTLS_CHECK_PARAMS + +/* \} name SECTION: System support */ + +/** + * \name SECTION: mbed TLS feature support + * + * This section sets support for features that are or are not needed + * within the modules that are enabled. + * \{ + */ + +/** + * \def MBEDTLS_TIMING_ALT + * + * Uncomment to provide your own alternate implementation for mbedtls_timing_hardclock(), + * mbedtls_timing_get_timer(), mbedtls_set_alarm(), mbedtls_set/get_delay() + * + * Only works if you have MBEDTLS_TIMING_C enabled. + * + * You will need to provide a header "timing_alt.h" and an implementation at + * compile time. + */ +//#define MBEDTLS_TIMING_ALT + +/** + * \def MBEDTLS_AES_ALT + * + * MBEDTLS__MODULE_NAME__ALT: Uncomment a macro to let mbed TLS use your + * alternate core implementation of a symmetric crypto, an arithmetic or hash + * module (e.g. platform specific assembly optimized implementations). Keep + * in mind that the function prototypes should remain the same. + * + * This replaces the whole module. If you only want to replace one of the + * functions, use one of the MBEDTLS__FUNCTION_NAME__ALT flags. + * + * Example: In case you uncomment MBEDTLS_AES_ALT, mbed TLS will no longer + * provide the "struct mbedtls_aes_context" definition and omit the base + * function declarations and implementations. "aes_alt.h" will be included from + * "aes.h" to include the new function definitions. + * + * Uncomment a macro to enable alternate implementation of the corresponding + * module. + * + * \warning MD2, MD4, MD5, ARC4, DES and SHA-1 are considered weak and their + * use constitutes a security risk. If possible, we recommend + * avoiding dependencies on them, and considering stronger message + * digests and ciphers instead. + * + */ + //#define MBEDTLS_AES_ALT + //#define MBEDTLS_ARC4_ALT + //#define MBEDTLS_ARIA_ALT + //#define MBEDTLS_BLOWFISH_ALT + //#define MBEDTLS_CAMELLIA_ALT + //#define MBEDTLS_CCM_ALT + //#define MBEDTLS_CHACHA20_ALT + //#define MBEDTLS_CHACHAPOLY_ALT + //#define MBEDTLS_CMAC_ALT + //#define MBEDTLS_DES_ALT + //#define MBEDTLS_DHM_ALT + //#define MBEDTLS_ECJPAKE_ALT + //#define MBEDTLS_GCM_ALT + //#define MBEDTLS_NIST_KW_ALT + //#define MBEDTLS_MD2_ALT + //#define MBEDTLS_MD4_ALT + //#define MBEDTLS_MD5_ALT + //#define MBEDTLS_POLY1305_ALT + //#define MBEDTLS_RIPEMD160_ALT + //#define MBEDTLS_RSA_ALT + //#define MBEDTLS_SHA1_ALT + //#define MBEDTLS_SHA256_ALT + //#define MBEDTLS_SHA512_ALT + //#define MBEDTLS_XTEA_ALT + +/* + * When replacing the elliptic curve module, pleace consider, that it is + * implemented with two .c files: + * - ecp.c + * - ecp_curves.c + * You can replace them very much like all the other MBEDTLS__MODULE_NAME__ALT + * macros as described above. The only difference is that you have to make sure + * that you provide functionality for both .c files. + */ +//#define MBEDTLS_ECP_ALT + +/** + * \def MBEDTLS_MD2_PROCESS_ALT + * + * MBEDTLS__FUNCTION_NAME__ALT: Uncomment a macro to let mbed TLS use you + * alternate core implementation of symmetric crypto or hash function. Keep in + * mind that function prototypes should remain the same. + * + * This replaces only one function. The header file from mbed TLS is still + * used, in contrast to the MBEDTLS__MODULE_NAME__ALT flags. + * + * Example: In case you uncomment MBEDTLS_SHA256_PROCESS_ALT, mbed TLS will + * no longer provide the mbedtls_sha1_process() function, but it will still provide + * the other function (using your mbedtls_sha1_process() function) and the definition + * of mbedtls_sha1_context, so your implementation of mbedtls_sha1_process must be compatible + * with this definition. + * + * \note Because of a signature change, the core AES encryption and decryption routines are + * currently named mbedtls_aes_internal_encrypt and mbedtls_aes_internal_decrypt, + * respectively. When setting up alternative implementations, these functions should + * be overriden, but the wrapper functions mbedtls_aes_decrypt and mbedtls_aes_encrypt + * must stay untouched. + * + * \note If you use the AES_xxx_ALT macros, then is is recommended to also set + * MBEDTLS_AES_ROM_TABLES in order to help the linker garbage-collect the AES + * tables. + * + * Uncomment a macro to enable alternate implementation of the corresponding + * function. + * + * \warning MD2, MD4, MD5, DES and SHA-1 are considered weak and their use + * constitutes a security risk. If possible, we recommend avoiding + * dependencies on them, and considering stronger message digests + * and ciphers instead. + * + */ +//#define MBEDTLS_MD2_PROCESS_ALT +//#define MBEDTLS_MD4_PROCESS_ALT +//#define MBEDTLS_MD5_PROCESS_ALT +//#define MBEDTLS_RIPEMD160_PROCESS_ALT +//#define MBEDTLS_SHA1_PROCESS_ALT +//#define MBEDTLS_SHA256_PROCESS_ALT +//#define MBEDTLS_SHA512_PROCESS_ALT +//#define MBEDTLS_DES_SETKEY_ALT +//#define MBEDTLS_DES_CRYPT_ECB_ALT +//#define MBEDTLS_DES3_CRYPT_ECB_ALT +//#define MBEDTLS_AES_SETKEY_ENC_ALT +//#define MBEDTLS_AES_SETKEY_DEC_ALT +//#define MBEDTLS_AES_ENCRYPT_ALT +//#define MBEDTLS_AES_DECRYPT_ALT +//#define MBEDTLS_ECDH_GEN_PUBLIC_ALT +//#define MBEDTLS_ECDH_COMPUTE_SHARED_ALT +//#define MBEDTLS_ECDSA_VERIFY_ALT +//#define MBEDTLS_ECDSA_SIGN_ALT +//#define MBEDTLS_ECDSA_GENKEY_ALT + +/** + * \def MBEDTLS_ECP_INTERNAL_ALT + * + * Expose a part of the internal interface of the Elliptic Curve Point module. + * + * MBEDTLS_ECP__FUNCTION_NAME__ALT: Uncomment a macro to let mbed TLS use your + * alternative core implementation of elliptic curve arithmetic. Keep in mind + * that function prototypes should remain the same. + * + * This partially replaces one function. The header file from mbed TLS is still + * used, in contrast to the MBEDTLS_ECP_ALT flag. The original implementation + * is still present and it is used for group structures not supported by the + * alternative. + * + * Any of these options become available by defining MBEDTLS_ECP_INTERNAL_ALT + * and implementing the following functions: + * unsigned char mbedtls_internal_ecp_grp_capable( + * const mbedtls_ecp_group *grp ) + * int mbedtls_internal_ecp_init( const mbedtls_ecp_group *grp ) + * void mbedtls_internal_ecp_free( const mbedtls_ecp_group *grp ) + * The mbedtls_internal_ecp_grp_capable function should return 1 if the + * replacement functions implement arithmetic for the given group and 0 + * otherwise. + * The functions mbedtls_internal_ecp_init and mbedtls_internal_ecp_free are + * called before and after each point operation and provide an opportunity to + * implement optimized set up and tear down instructions. + * + * Example: In case you uncomment MBEDTLS_ECP_INTERNAL_ALT and + * MBEDTLS_ECP_DOUBLE_JAC_ALT, mbed TLS will still provide the ecp_double_jac + * function, but will use your mbedtls_internal_ecp_double_jac if the group is + * supported (your mbedtls_internal_ecp_grp_capable function returns 1 when + * receives it as an argument). If the group is not supported then the original + * implementation is used. The other functions and the definition of + * mbedtls_ecp_group and mbedtls_ecp_point will not change, so your + * implementation of mbedtls_internal_ecp_double_jac and + * mbedtls_internal_ecp_grp_capable must be compatible with this definition. + * + * Uncomment a macro to enable alternate implementation of the corresponding + * function. + */ +/* Required for all the functions in this section */ +//#define MBEDTLS_ECP_INTERNAL_ALT +/* Support for Weierstrass curves with Jacobi representation */ +//#define MBEDTLS_ECP_RANDOMIZE_JAC_ALT +//#define MBEDTLS_ECP_ADD_MIXED_ALT +//#define MBEDTLS_ECP_DOUBLE_JAC_ALT +//#define MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT +//#define MBEDTLS_ECP_NORMALIZE_JAC_ALT +/* Support for curves with Montgomery arithmetic */ +//#define MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT +//#define MBEDTLS_ECP_RANDOMIZE_MXZ_ALT +//#define MBEDTLS_ECP_NORMALIZE_MXZ_ALT + +/** + * \def MBEDTLS_TEST_NULL_ENTROPY + * + * Enables testing and use of mbed TLS without any configured entropy sources. + * This permits use of the library on platforms before an entropy source has + * been integrated (see for example the MBEDTLS_ENTROPY_HARDWARE_ALT or the + * MBEDTLS_ENTROPY_NV_SEED switches). + * + * WARNING! This switch MUST be disabled in production builds, and is suitable + * only for development. + * Enabling the switch negates any security provided by the library. + * + * Requires MBEDTLS_ENTROPY_C, MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES + * + */ +//#define MBEDTLS_TEST_NULL_ENTROPY + +/** + * \def MBEDTLS_ENTROPY_HARDWARE_ALT + * + * Uncomment this macro to let mbed TLS use your own implementation of a + * hardware entropy collector. + * + * Your function must be called \c mbedtls_hardware_poll(), have the same + * prototype as declared in entropy_poll.h, and accept NULL as first argument. + * + * Uncomment to use your own hardware entropy collector. + */ +#define MBEDTLS_ENTROPY_HARDWARE_ALT + +/** + * \def MBEDTLS_AES_ROM_TABLES + * + * Use precomputed AES tables stored in ROM. + * + * Uncomment this macro to use precomputed AES tables stored in ROM. + * Comment this macro to generate AES tables in RAM at runtime. + * + * Tradeoff: Using precomputed ROM tables reduces RAM usage by ~8kb + * (or ~2kb if \c MBEDTLS_AES_FEWER_TABLES is used) and reduces the + * initialization time before the first AES operation can be performed. + * It comes at the cost of additional ~8kb ROM use (resp. ~2kb if \c + * MBEDTLS_AES_FEWER_TABLES below is used), and potentially degraded + * performance if ROM access is slower than RAM access. + * + * This option is independent of \c MBEDTLS_AES_FEWER_TABLES. + * + */ + #define MBEDTLS_AES_ROM_TABLES + + /** + * \def MBEDTLS_AES_FEWER_TABLES + * + * Use less ROM/RAM for AES tables. + * + * Uncommenting this macro omits 75% of the AES tables from + * ROM / RAM (depending on the value of \c MBEDTLS_AES_ROM_TABLES) + * by computing their values on the fly during operations + * (the tables are entry-wise rotations of one another). + * + * Tradeoff: Uncommenting this reduces the RAM / ROM footprint + * by ~6kb but at the cost of more arithmetic operations during + * runtime. Specifically, one has to compare 4 accesses within + * different tables to 4 accesses with additional arithmetic + * operations within the same table. The performance gain/loss + * depends on the system and memory details. + * + * This option is independent of \c MBEDTLS_AES_ROM_TABLES. + * + */ + //#define MBEDTLS_AES_FEWER_TABLES + +/** + * \def MBEDTLS_CAMELLIA_SMALL_MEMORY + * + * Use less ROM for the Camellia implementation (saves about 768 bytes). + * + * Uncomment this macro to use less memory for Camellia. + */ +//#define MBEDTLS_CAMELLIA_SMALL_MEMORY + +/** + * \def MBEDTLS_CIPHER_MODE_CBC + * + * Enable Cipher Block Chaining mode (CBC) for symmetric ciphers. + */ +//#define MBEDTLS_CIPHER_MODE_CBC + +/** + * \def MBEDTLS_CIPHER_MODE_CFB + * + * Enable Cipher Feedback mode (CFB) for symmetric ciphers. + */ +#define MBEDTLS_CIPHER_MODE_CFB + +/** + * \def MBEDTLS_CIPHER_MODE_CTR + * + * Enable Counter Block Cipher mode (CTR) for symmetric ciphers. + */ +#define MBEDTLS_CIPHER_MODE_CTR + +/** + * \def MBEDTLS_CIPHER_MODE_OFB + * + * Enable Output Feedback mode (OFB) for symmetric ciphers. + */ +//#define MBEDTLS_CIPHER_MODE_OFB + +/** + * \def MBEDTLS_CIPHER_MODE_XTS + * + * Enable Xor-encrypt-xor with ciphertext stealing mode (XTS) for AES. + */ +//#define MBEDTLS_CIPHER_MODE_XTS + +/** + * \def MBEDTLS_CIPHER_NULL_CIPHER + * + * Enable NULL cipher. + * Warning: Only do so when you know what you are doing. This allows for + * encryption or channels without any security! + * + * Requires MBEDTLS_ENABLE_WEAK_CIPHERSUITES as well to enable + * the following ciphersuites: + * MBEDTLS_TLS_ECDH_ECDSA_WITH_NULL_SHA + * MBEDTLS_TLS_ECDH_RSA_WITH_NULL_SHA + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_NULL_SHA + * MBEDTLS_TLS_ECDHE_RSA_WITH_NULL_SHA + * MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA384 + * MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA256 + * MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA + * MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA384 + * MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA256 + * MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA + * MBEDTLS_TLS_RSA_WITH_NULL_SHA256 + * MBEDTLS_TLS_RSA_WITH_NULL_SHA + * MBEDTLS_TLS_RSA_WITH_NULL_MD5 + * MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA384 + * MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA256 + * MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA + * MBEDTLS_TLS_PSK_WITH_NULL_SHA384 + * MBEDTLS_TLS_PSK_WITH_NULL_SHA256 + * MBEDTLS_TLS_PSK_WITH_NULL_SHA + * + * Uncomment this macro to enable the NULL cipher and ciphersuites + */ +//#define MBEDTLS_CIPHER_NULL_CIPHER + +/** \def MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + * + * Uncomment this macro to use a 128-bit key in the CTR_DRBG module. + * By default, CTR_DRBG uses a 256-bit key. + */ +//#define MBEDTLS_CTR_DRBG_USE_128_BIT_KE + +/** + * \def MBEDTLS_REMOVE_3DES_CIPHERSUITES + * + * Remove 3DES ciphersuites by default in SSL / TLS. + * This flag removes the ciphersuites based on 3DES from the default list as + * returned by mbedtls_ssl_list_ciphersuites(). However, it is still possible + * to enable (some of) them with mbedtls_ssl_conf_ciphersuites() by including + * them explicitly. + * + * A man-in-the-browser attacker can recover authentication tokens sent through + * a TLS connection using a 3DES based cipher suite (see "On the Practical + * (In-)Security of 64-bit Block Ciphers" by Karthikeyan Bhargavan and Gaëtan + * Leurent, see https://sweet32.info/SWEET32_CCS16.pdf). If this attack falls + * in your threat model or you are unsure, then you should keep this option + * enabled to remove 3DES based cipher suites. + * + * Comment this macro to keep 3DES in the default ciphersuite list. + */ +#define MBEDTLS_REMOVE_3DES_CIPHERSUITES + +/** + * \def MBEDTLS_CIPHER_PADDING_PKCS7 + * + * MBEDTLS_CIPHER_PADDING_XXX: Uncomment or comment macros to add support for + * specific padding modes in the cipher layer with cipher modes that support + * padding (e.g. CBC) + * + * If you disable all padding modes, only full blocks can be used with CBC. + * + * Enable padding modes in the cipher layer. + */ +#define MBEDTLS_CIPHER_PADDING_PKCS7 +#define MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS +#define MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN +#define MBEDTLS_CIPHER_PADDING_ZEROS + +/** + * \def MBEDTLS_ENABLE_WEAK_CIPHERSUITES + * + * Enable weak ciphersuites in SSL / TLS. + * Warning: Only do so when you know what you are doing. This allows for + * channels with virtually no security at all! + * + * This enables the following ciphersuites: + * MBEDTLS_TLS_RSA_WITH_DES_CBC_SHA + * MBEDTLS_TLS_DHE_RSA_WITH_DES_CBC_SHA + * + * Uncomment this macro to enable weak ciphersuites + * + * \warning DES is considered a weak cipher and its use constitutes a + * security risk. We recommend considering stronger ciphers instead. +*/ +//#define MBEDTLS_ENABLE_WEAK_CIPHERSUITES + +/** + * \def MBEDTLS_REMOVE_ARC4_CIPHERSUITES + * + * Remove RC4 ciphersuites by default in SSL / TLS. + * This flag removes the ciphersuites based on RC4 from the default list as + * returned by mbedtls_ssl_list_ciphersuites(). However, it is still possible to + * enable (some of) them with mbedtls_ssl_conf_ciphersuites() by including them + * explicitly. + * + * Uncomment this macro to remove RC4 ciphersuites by default. + */ +#define MBEDTLS_REMOVE_ARC4_CIPHERSUITES + +/** + * \def MBEDTLS_ECP_DP_SECP192R1_ENABLED + * + * MBEDTLS_ECP_XXXX_ENABLED: Enables specific curves within the Elliptic Curve + * module. By default all supported curves are enabled. + * + * Comment macros to disable the curve and functions for it + */ +//#define MBEDTLS_ECP_DP_SECP192R1_ENABLED +//#define MBEDTLS_ECP_DP_SECP224R1_ENABLED +#define MBEDTLS_ECP_DP_SECP256R1_ENABLED +//#define MBEDTLS_ECP_DP_SECP384R1_ENABLED +//#define MBEDTLS_ECP_DP_SECP521R1_ENABLED +//#define MBEDTLS_ECP_DP_SECP192K1_ENABLED +//#define MBEDTLS_ECP_DP_SECP224K1_ENABLED +//#define MBEDTLS_ECP_DP_SECP256K1_ENABLED +//#define MBEDTLS_ECP_DP_BP256R1_ENABLED +//#define MBEDTLS_ECP_DP_BP384R1_ENABLED +//#define MBEDTLS_ECP_DP_BP512R1_ENABLED +//#define MBEDTLS_ECP_DP_CURVE25519_ENABLED +//#define MBEDTLS_ECP_DP_CURVE448_ENABLED + +/** + * \def MBEDTLS_ECP_NIST_OPTIM + * + * Enable specific 'modulo p' routines for each NIST prime. + * Depending on the prime and architecture, makes operations 4 to 8 times + * faster on the corresponding curve. + * + * Comment this macro to disable NIST curves optimisation. + */ +#define MBEDTLS_ECP_NIST_OPTIM + +/** + * \def MBEDTLS_ECP_RESTARTABLE + * + * Enable "non-blocking" ECC operations that can return early and be resumed. + * + * This allows various functions to pause by returning + * #MBEDTLS_ERR_ECP_IN_PROGRESS (or, for functions in the SSL module, + * #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS) and then be called later again in + * order to further progress and eventually complete their operation. This is + * controlled through mbedtls_ecp_set_max_ops() which limits the maximum + * number of ECC operations a function may perform before pausing; see + * mbedtls_ecp_set_max_ops() for more information. + * + * This is useful in non-threaded environments if you want to avoid blocking + * for too long on ECC (and, hence, X.509 or SSL/TLS) operations. + * + * Uncomment this macro to enable restartable ECC computations. + * + * \note This option only works with the default software implementation of + * elliptic curve functionality. It is incompatible with + * MBEDTLS_ECP_ALT, MBEDTLS_ECDH_XXX_ALT and MBEDTLS_ECDSA_XXX_ALT. + */ +//#define MBEDTLS_ECP_RESTARTABLE + +/** + * \def MBEDTLS_ECDSA_DETERMINISTIC + * + * Enable deterministic ECDSA (RFC 6979). + * Standard ECDSA is "fragile" in the sense that lack of entropy when signing + * may result in a compromise of the long-term signing key. This is avoided by + * the deterministic variant. + * + * Requires: MBEDTLS_HMAC_DRBG_C + * + * Comment this macro to disable deterministic ECDSA. + */ +//#define MBEDTLS_ECDSA_DETERMINISTIC + +/** + * \def MBEDTLS_KEY_EXCHANGE_PSK_ENABLED + * + * Enable the PSK based ciphersuite modes in SSL / TLS. + * + * This enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_PSK_WITH_RC4_128_SHA + */ +//#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED + +/** + * \def MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED + * + * Enable the DHE-PSK based ciphersuite modes in SSL / TLS. + * + * Requires: MBEDTLS_DHM_C + * + * This enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA + * + * \warning Using DHE constitutes a security risk as it + * is not possible to validate custom DH parameters. + * If possible, it is recommended users should consider + * preferring other methods of key exchange. + * See dhm.h for more details. + * + */ +//#define MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED + +/** + * \def MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED + * + * Enable the ECDHE-PSK based ciphersuite modes in SSL / TLS. + * + * Requires: MBEDTLS_ECDH_C + * + * This enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA + */ +//#define MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED + +/** + * \def MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED + * + * Enable the RSA-PSK based ciphersuite modes in SSL / TLS. + * + * Requires: MBEDTLS_RSA_C, MBEDTLS_PKCS1_V15, + * MBEDTLS_X509_CRT_PARSE_C + * + * This enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA + */ +//#define MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED + +/** + * \def MBEDTLS_KEY_EXCHANGE_RSA_ENABLED + * + * Enable the RSA-only based ciphersuite modes in SSL / TLS. + * + * Requires: MBEDTLS_RSA_C, MBEDTLS_PKCS1_V15, + * MBEDTLS_X509_CRT_PARSE_C + * + * This enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_RSA_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA256 + * MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 + * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA + * MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA + * MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_RSA_WITH_RC4_128_SHA + * MBEDTLS_TLS_RSA_WITH_RC4_128_MD5 + */ +//#define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED + +/** + * \def MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED + * + * Enable the DHE-RSA based ciphersuite modes in SSL / TLS. + * + * Requires: MBEDTLS_DHM_C, MBEDTLS_RSA_C, MBEDTLS_PKCS1_V15, + * MBEDTLS_X509_CRT_PARSE_C + * + * This enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA + * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA + * MBEDTLS_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA + * + * \warning Using DHE constitutes a security risk as it + * is not possible to validate custom DH parameters. + * If possible, it is recommended users should consider + * preferring other methods of key exchange. + * See dhm.h for more details. + * + */ +//#define MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED + +/** + * \def MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED + * + * Enable the ECDHE-RSA based ciphersuite modes in SSL / TLS. + * + * Requires: MBEDTLS_ECDH_C, MBEDTLS_RSA_C, MBEDTLS_PKCS1_V15, + * MBEDTLS_X509_CRT_PARSE_C + * + * This enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA + */ +#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED + +/** + * \def MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED + * + * Enable the ECDHE-ECDSA based ciphersuite modes in SSL / TLS. + * + * Requires: MBEDTLS_ECDH_C, MBEDTLS_ECDSA_C, MBEDTLS_X509_CRT_PARSE_C, + * + * This enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA + */ +#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED + +/** + * \def MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED + * + * Enable the ECDH-ECDSA based ciphersuite modes in SSL / TLS. + * + * Requires: MBEDTLS_ECDH_C, MBEDTLS_X509_CRT_PARSE_C + * + * This enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA + * MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 + */ +//#define MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED + +/** + * \def MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED + * + * Enable the ECDH-RSA based ciphersuite modes in SSL / TLS. + * + * Requires: MBEDTLS_ECDH_C, MBEDTLS_X509_CRT_PARSE_C + * + * This enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA + * MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384 + */ +//#define MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED + +/** + * \def MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED + * + * Enable the ECJPAKE based ciphersuite modes in SSL / TLS. + * + * \warning This is currently experimental. EC J-PAKE support is based on the + * Thread v1.0.0 specification; incompatible changes to the specification + * might still happen. For this reason, this is disabled by default. + * + * Requires: MBEDTLS_ECJPAKE_C + * MBEDTLS_SHA256_C + * MBEDTLS_ECP_DP_SECP256R1_ENABLED + * + * This enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8 + */ +//#define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED + +/** + * \def MBEDTLS_PK_PARSE_EC_EXTENDED + * + * Enhance support for reading EC keys using variants of SEC1 not allowed by + * RFC 5915 and RFC 5480. + * + * Currently this means parsing the SpecifiedECDomain choice of EC + * parameters (only known groups are supported, not arbitrary domains, to + * avoid validation issues). + * + * Disable if you only need to support RFC 5915 + 5480 key formats. + */ +//#define MBEDTLS_PK_PARSE_EC_EXTENDED + +/** + * \def MBEDTLS_ERROR_STRERROR_DUMMY + * + * Enable a dummy error function to make use of mbedtls_strerror() in + * third party libraries easier when MBEDTLS_ERROR_C is disabled + * (no effect when MBEDTLS_ERROR_C is enabled). + * + * You can safely disable this if MBEDTLS_ERROR_C is enabled, or if you're + * not using mbedtls_strerror() or error_strerror() in your application. + * + * Disable if you run into name conflicts and want to really remove the + * mbedtls_strerror() + */ +//#define MBEDTLS_ERROR_STRERROR_DUMMY + +/** + * \def MBEDTLS_GENPRIME + * + * Enable the prime-number generation code. + * + * Requires: MBEDTLS_BIGNUM_C + */ +#define MBEDTLS_GENPRIME + +/** + * \def MBEDTLS_FS_IO + * + * Enable functions that use the filesystem. + */ +//#define MBEDTLS_FS_IO + +/** + * \def MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES + * + * Do not add default entropy sources. These are the platform specific, + * mbedtls_timing_hardclock and HAVEGE based poll functions. + * + * This is useful to have more control over the added entropy sources in an + * application. + * + * Uncomment this macro to prevent loading of default entropy functions. + */ +//#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES + +/** + * \def MBEDTLS_NO_PLATFORM_ENTROPY + * + * Do not use built-in platform entropy functions. + * This is useful if your platform does not support + * standards like the /dev/urandom or Windows CryptoAPI. + * + * Uncomment this macro to disable the built-in platform entropy functions. + */ +#define MBEDTLS_NO_PLATFORM_ENTROPY + +/** + * \def MBEDTLS_ENTROPY_FORCE_SHA256 + * + * Force the entropy accumulator to use a SHA-256 accumulator instead of the + * default SHA-512 based one (if both are available). + * + * Requires: MBEDTLS_SHA256_C + * + * On 32-bit systems SHA-256 can be much faster than SHA-512. Use this option + * if you have performance concerns. + * + * This option is only useful if both MBEDTLS_SHA256_C and + * MBEDTLS_SHA512_C are defined. Otherwise the available hash module is used. + */ +#define MBEDTLS_ENTROPY_FORCE_SHA256 + +/** + * \def MBEDTLS_ENTROPY_NV_SEED + * + * Enable the non-volatile (NV) seed file-based entropy source. + * (Also enables the NV seed read/write functions in the platform layer) + * + * This is crucial (if not required) on systems that do not have a + * cryptographic entropy source (in hardware or kernel) available. + * + * Requires: MBEDTLS_ENTROPY_C, MBEDTLS_PLATFORM_C + * + * \note The read/write functions that are used by the entropy source are + * determined in the platform layer, and can be modified at runtime and/or + * compile-time depending on the flags (MBEDTLS_PLATFORM_NV_SEED_*) used. + * + * \note If you use the default implementation functions that read a seedfile + * with regular fopen(), please make sure you make a seedfile with the + * proper name (defined in MBEDTLS_PLATFORM_STD_NV_SEED_FILE) and at + * least MBEDTLS_ENTROPY_BLOCK_SIZE bytes in size that can be read from + * and written to or you will get an entropy source error! The default + * implementation will only use the first MBEDTLS_ENTROPY_BLOCK_SIZE + * bytes from the file. + * + * \note The entropy collector will write to the seed file before entropy is + * given to an external source, to update it. + */ +//#define MBEDTLS_ENTROPY_NV_SEED + +/** + * \def MBEDTLS_MEMORY_DEBUG + * + * Enable debugging of buffer allocator memory issues. Automatically prints + * (to stderr) all (fatal) messages on memory allocation issues. Enables + * function for 'debug output' of allocated memory. + * + * Requires: MBEDTLS_MEMORY_BUFFER_ALLOC_C + * + * Uncomment this macro to let the buffer allocator print out error messages. + */ +//#define MBEDTLS_MEMORY_DEBUG + +/** + * \def MBEDTLS_MEMORY_BACKTRACE + * + * Include backtrace information with each allocated block. + * + * Requires: MBEDTLS_MEMORY_BUFFER_ALLOC_C + * GLIBC-compatible backtrace() an backtrace_symbols() support + * + * Uncomment this macro to include backtrace information + */ +//#define MBEDTLS_MEMORY_BACKTRACE + +/** + * \def MBEDTLS_PK_RSA_ALT_SUPPORT + * + * Support external private RSA keys (eg from a HSM) in the PK layer. + * + * Comment this macro to disable support for external private RSA keys. + */ +#define MBEDTLS_PK_RSA_ALT_SUPPORT + +/** + * \def MBEDTLS_PKCS1_V15 + * + * Enable support for PKCS#1 v1.5 encoding. + * + * Requires: MBEDTLS_RSA_C + * + * This enables support for PKCS#1 v1.5 operations. + */ +#define MBEDTLS_PKCS1_V15 + +/** + * \def MBEDTLS_PKCS1_V21 + * + * Enable support for PKCS#1 v2.1 encoding. + * + * Requires: MBEDTLS_MD_C, MBEDTLS_RSA_C + * + * This enables support for RSAES-OAEP and RSASSA-PSS operations. + */ +//#define MBEDTLS_PKCS1_V21 + +/** + * \def MBEDTLS_RSA_NO_CRT + * + * Do not use the Chinese Remainder Theorem + * for the RSA private operation. + * + * Uncomment this macro to disable the use of CRT in RSA. + * + */ +//#define MBEDTLS_RSA_NO_CRT + +/** + * \def MBEDTLS_SELF_TEST + * + * Enable the checkup functions (*_self_test). + */ +//#define MBEDTLS_SELF_TEST + +/** + * \def MBEDTLS_SHA256_SMALLER + * + * Enable an implementation of SHA-256 that has lower ROM footprint but also + * lower performance. + * + * The default implementation is meant to be a reasonnable compromise between + * performance and size. This version optimizes more aggressively for size at + * the expense of performance. Eg on Cortex-M4 it reduces the size of + * mbedtls_sha256_process() from ~2KB to ~0.5KB for a performance hit of about + * 30%. + * + * Uncomment to enable the smaller implementation of SHA256. + */ +//#define MBEDTLS_SHA256_SMALLER + +/** + * \def MBEDTLS_SSL_ALL_ALERT_MESSAGES + * + * Enable sending of alert messages in case of encountered errors as per RFC. + * If you choose not to send the alert messages, mbed TLS can still communicate + * with other servers, only debugging of failures is harder. + * + * The advantage of not sending alert messages, is that no information is given + * about reasons for failures thus preventing adversaries of gaining intel. + * + * Enable sending of all alert messages + */ +#define MBEDTLS_SSL_ALL_ALERT_MESSAGES + +/** + * \def MBEDTLS_SSL_ASYNC_PRIVATE + * + * Enable asynchronous external private key operations in SSL. This allows + * you to configure an SSL connection to call an external cryptographic + * module to perform private key operations instead of performing the + * operation inside the library. + * + */ +//#define MBEDTLS_SSL_ASYNC_PRIVATE + +/** + * \def MBEDTLS_SSL_DEBUG_ALL + * + * Enable the debug messages in SSL module for all issues. + * Debug messages have been disabled in some places to prevent timing + * attacks due to (unbalanced) debugging function calls. + * + * If you need all error reporting you should enable this during debugging, + * but remove this for production servers that should log as well. + * + * Uncomment this macro to report all debug messages on errors introducing + * a timing side-channel. + * + */ +//#define MBEDTLS_SSL_DEBUG_ALL + +/** \def MBEDTLS_SSL_ENCRYPT_THEN_MAC + * + * Enable support for Encrypt-then-MAC, RFC 7366. + * + * This allows peers that both support it to use a more robust protection for + * ciphersuites using CBC, providing deep resistance against timing attacks + * on the padding or underlying cipher. + * + * This only affects CBC ciphersuites, and is useless if none is defined. + * + * Requires: MBEDTLS_SSL_PROTO_TLS1 or + * MBEDTLS_SSL_PROTO_TLS1_1 or + * MBEDTLS_SSL_PROTO_TLS1_2 + * + * Comment this macro to disable support for Encrypt-then-MAC + */ +//#define MBEDTLS_SSL_ENCRYPT_THEN_MAC + +/** \def MBEDTLS_SSL_EXTENDED_MASTER_SECRET + * + * Enable support for Extended Master Secret, aka Session Hash + * (draft-ietf-tls-session-hash-02). + * + * This was introduced as "the proper fix" to the Triple Handshake familiy of + * attacks, but it is recommended to always use it (even if you disable + * renegotiation), since it actually fixes a more fundamental issue in the + * original SSL/TLS design, and has implications beyond Triple Handshake. + * + * Requires: MBEDTLS_SSL_PROTO_TLS1 or + * MBEDTLS_SSL_PROTO_TLS1_1 or + * MBEDTLS_SSL_PROTO_TLS1_2 + * + * Comment this macro to disable support for Extended Master Secret. + */ +#define MBEDTLS_SSL_EXTENDED_MASTER_SECRET + +/** + * \def MBEDTLS_SSL_FALLBACK_SCSV + * + * Enable support for FALLBACK_SCSV (draft-ietf-tls-downgrade-scsv-00). + * + * For servers, it is recommended to always enable this, unless you support + * only one version of TLS, or know for sure that none of your clients + * implements a fallback strategy. + * + * For clients, you only need this if you're using a fallback strategy, which + * is not recommended in the first place, unless you absolutely need it to + * interoperate with buggy (version-intolerant) servers. + * + * Comment this macro to disable support for FALLBACK_SCSV + */ +//#define MBEDTLS_SSL_FALLBACK_SCSV + +/** + * \def MBEDTLS_SSL_HW_RECORD_ACCEL + * + * Enable hooking functions in SSL module for hardware acceleration of + * individual records. + * + * Uncomment this macro to enable hooking functions. + */ +//#define MBEDTLS_SSL_HW_RECORD_ACCEL + +/** + * \def MBEDTLS_SSL_CBC_RECORD_SPLITTING + * + * Enable 1/n-1 record splitting for CBC mode in SSLv3 and TLS 1.0. + * + * This is a countermeasure to the BEAST attack, which also minimizes the risk + * of interoperability issues compared to sending 0-length records. + * + * Comment this macro to disable 1/n-1 record splitting. + */ +//#define MBEDTLS_SSL_CBC_RECORD_SPLITTING + +/** + * \def MBEDTLS_SSL_RENEGOTIATION + * + * Enable support for TLS renegotiation. + * + * The two main uses of renegotiation are (1) refresh keys on long-lived + * connections and (2) client authentication after the initial handshake. + * If you don't need renegotiation, it's probably better to disable it, since + * it has been associated with security issues in the past and is easy to + * misuse/misunderstand. + * + * Comment this to disable support for renegotiation. + * + * \note Even if this option is disabled, both client and server are aware + * of the Renegotiation Indication Extension (RFC 5746) used to + * prevent the SSL renegotiation attack (see RFC 5746 Sect. 1). + * (See \c mbedtls_ssl_conf_legacy_renegotiation for the + * configuration of this extension). + * + */ +//#define MBEDTLS_SSL_RENEGOTIATION + +/** + * \def MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO + * + * Enable support for receiving and parsing SSLv2 Client Hello messages for the + * SSL Server module (MBEDTLS_SSL_SRV_C). + * + * Uncomment this macro to enable support for SSLv2 Client Hello messages. + */ +//#define MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO + +/** + * \def MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE + * + * Pick the ciphersuite according to the client's preferences rather than ours + * in the SSL Server module (MBEDTLS_SSL_SRV_C). + * + * Uncomment this macro to respect client's ciphersuite order + */ +//#define MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE + +/** + * \def MBEDTLS_SSL_MAX_FRAGMENT_LENGTH + * + * Enable support for RFC 6066 max_fragment_length extension in SSL. + * + * Comment this macro to disable support for the max_fragment_length extension + */ +#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH + +/** + * \def MBEDTLS_SSL_PROTO_SSL3 + * + * Enable support for SSL 3.0. + * + * Requires: MBEDTLS_MD5_C + * MBEDTLS_SHA1_C + * + * Comment this macro to disable support for SSL 3.0 + */ +//#define MBEDTLS_SSL_PROTO_SSL3 + +/** + * \def MBEDTLS_SSL_PROTO_TLS1 + * + * Enable support for TLS 1.0. + * + * Requires: MBEDTLS_MD5_C + * MBEDTLS_SHA1_C + * + * Comment this macro to disable support for TLS 1.0 + */ +//#define MBEDTLS_SSL_PROTO_TLS1 + +/** + * \def MBEDTLS_SSL_PROTO_TLS1_1 + * + * Enable support for TLS 1.1 (and DTLS 1.0 if DTLS is enabled). + * + * Requires: MBEDTLS_MD5_C + * MBEDTLS_SHA1_C + * + * Comment this macro to disable support for TLS 1.1 / DTLS 1.0 + */ +//#define MBEDTLS_SSL_PROTO_TLS1_1 + +/** + * \def MBEDTLS_SSL_PROTO_TLS1_2 + * + * Enable support for TLS 1.2 (and DTLS 1.2 if DTLS is enabled). + * + * Requires: MBEDTLS_SHA1_C or MBEDTLS_SHA256_C or MBEDTLS_SHA512_C + * (Depends on ciphersuites) + * + * Comment this macro to disable support for TLS 1.2 / DTLS 1.2 + */ +#define MBEDTLS_SSL_PROTO_TLS1_2 + +/** + * \def MBEDTLS_SSL_PROTO_DTLS + * + * Enable support for DTLS (all available versions). + * + * Enable this and MBEDTLS_SSL_PROTO_TLS1_1 to enable DTLS 1.0, + * and/or this and MBEDTLS_SSL_PROTO_TLS1_2 to enable DTLS 1.2. + * + * Requires: MBEDTLS_SSL_PROTO_TLS1_1 + * or MBEDTLS_SSL_PROTO_TLS1_2 + * + * Comment this macro to disable support for DTLS + */ +//#define MBEDTLS_SSL_PROTO_DTLS + +/** + * \def MBEDTLS_SSL_ALPN + * + * Enable support for RFC 7301 Application Layer Protocol Negotiation. + * + * Comment this macro to disable support for ALPN. + */ +#define MBEDTLS_SSL_ALPN + +/** + * \def MBEDTLS_SSL_DTLS_ANTI_REPLAY + * + * Enable support for the anti-replay mechanism in DTLS. + * + * Requires: MBEDTLS_SSL_TLS_C + * MBEDTLS_SSL_PROTO_DTLS + * + * \warning Disabling this is often a security risk! + * See mbedtls_ssl_conf_dtls_anti_replay() for details. + * + * Comment this to disable anti-replay in DTLS. + */ +//#define MBEDTLS_SSL_DTLS_ANTI_REPLAY + +/** + * \def MBEDTLS_SSL_DTLS_HELLO_VERIFY + * + * Enable support for HelloVerifyRequest on DTLS servers. + * + * This feature is highly recommended to prevent DTLS servers being used as + * amplifiers in DoS attacks against other hosts. It should always be enabled + * unless you know for sure amplification cannot be a problem in the + * environment in which your server operates. + * + * \warning Disabling this can ba a security risk! (see above) + * + * Requires: MBEDTLS_SSL_PROTO_DTLS + * + * Comment this to disable support for HelloVerifyRequest. + */ +//#define MBEDTLS_SSL_DTLS_HELLO_VERIFY + +/** + * \def MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE + * + * Enable server-side support for clients that reconnect from the same port. + * + * Some clients unexpectedly close the connection and try to reconnect using the + * same source port. This needs special support from the server to handle the + * new connection securely, as described in section 4.2.8 of RFC 6347. This + * flag enables that support. + * + * Requires: MBEDTLS_SSL_DTLS_HELLO_VERIFY + * + * Comment this to disable support for clients reusing the source port. + */ +//#define MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE + +/** + * \def MBEDTLS_SSL_DTLS_BADMAC_LIMIT + * + * Enable support for a limit of records with bad MAC. + * + * See mbedtls_ssl_conf_dtls_badmac_limit(). + * + * Requires: MBEDTLS_SSL_PROTO_DTLS + */ +//#define MBEDTLS_SSL_DTLS_BADMAC_LIMIT + +/** + * \def MBEDTLS_SSL_SESSION_TICKETS + * + * Enable support for RFC 5077 session tickets in SSL. + * Client-side, provides full support for session tickets (maintainance of a + * session store remains the responsibility of the application, though). + * Server-side, you also need to provide callbacks for writing and parsing + * tickets, including authenticated encryption and key management. Example + * callbacks are provided by MBEDTLS_SSL_TICKET_C. + * + * Comment this macro to disable support for SSL session tickets + */ +//#define MBEDTLS_SSL_SESSION_TICKETS + +/** + * \def MBEDTLS_SSL_EXPORT_KEYS + * + * Enable support for exporting key block and master secret. + * This is required for certain users of TLS, e.g. EAP-TLS. + * + * Comment this macro to disable support for key export + */ +//#define MBEDTLS_SSL_EXPORT_KEYS + +/** + * \def MBEDTLS_SSL_SERVER_NAME_INDICATION + * + * Enable support for RFC 6066 server name indication (SNI) in SSL. + * + * Requires: MBEDTLS_X509_CRT_PARSE_C + * + * Comment this macro to disable support for server name indication in SSL + */ +#define MBEDTLS_SSL_SERVER_NAME_INDICATION + +/** + * \def MBEDTLS_SSL_TRUNCATED_HMAC + * + * Enable support for RFC 6066 truncated HMAC in SSL. + * + * Comment this macro to disable support for truncated HMAC in SSL + */ +//#define MBEDTLS_SSL_TRUNCATED_HMAC + +/** + * \def MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT + * + * Fallback to old (pre-2.7), non-conforming implementation of the truncated + * HMAC extension which also truncates the HMAC key. Note that this option is + * only meant for a transitory upgrade period and is likely to be removed in + * a future version of the library. + * + * \warning The old implementation is non-compliant and has a security weakness + * (2^80 brute force attack on the HMAC key used for a single, + * uninterrupted connection). This should only be enabled temporarily + * when (1) the use of truncated HMAC is essential in order to save + * bandwidth, and (2) the peer is an Mbed TLS stack that doesn't use + * the fixed implementation yet (pre-2.7). + * + * \deprecated This option is deprecated and will likely be removed in a + * future version of Mbed TLS. + * + * Uncomment to fallback to old, non-compliant truncated HMAC implementation. + * + * Requires: MBEDTLS_SSL_TRUNCATED_HMAC + */ +//#define MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT + +/** + * \def MBEDTLS_THREADING_ALT + * + * Provide your own alternate threading implementation. + * + * Requires: MBEDTLS_THREADING_C + * + * Uncomment this to allow your own alternate threading implementation. + */ +#define MBEDTLS_THREADING_ALT + +/** + * \def MBEDTLS_THREADING_PTHREAD + * + * Enable the pthread wrapper layer for the threading layer. + * + * Requires: MBEDTLS_THREADING_C + * + * Uncomment this to enable pthread mutexes. + */ +//#define MBEDTLS_THREADING_PTHREAD + +/** + * \def MBEDTLS_VERSION_FEATURES + * + * Allow run-time checking of compile-time enabled features. Thus allowing users + * to check at run-time if the library is for instance compiled with threading + * support via mbedtls_version_check_feature(). + * + * Requires: MBEDTLS_VERSION_C + * + * Comment this to disable run-time checking and save ROM space + */ +//#define MBEDTLS_VERSION_FEATURES + +/** + * \def MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3 + * + * If set, the X509 parser will not break-off when parsing an X509 certificate + * and encountering an extension in a v1 or v2 certificate. + * + * Uncomment to prevent an error. + */ +//#define MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3 + +/** + * \def MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION + * + * If set, the X509 parser will not break-off when parsing an X509 certificate + * and encountering an unknown critical extension. + * + * \warning Depending on your PKI use, enabling this can be a security risk! + * + * Uncomment to prevent an error. + */ +//#define MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION + +/** + * \def MBEDTLS_X509_CHECK_KEY_USAGE + * + * Enable verification of the keyUsage extension (CA and leaf certificates). + * + * Disabling this avoids problems with mis-issued and/or misused + * (intermediate) CA and leaf certificates. + * + * \warning Depending on your PKI use, disabling this can be a security risk! + * + * Comment to skip keyUsage checking for both CA and leaf certificates. + */ +#define MBEDTLS_X509_CHECK_KEY_USAGE + +/** + * \def MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE + * + * Enable verification of the extendedKeyUsage extension (leaf certificates). + * + * Disabling this avoids problems with mis-issued and/or misused certificates. + * + * \warning Depending on your PKI use, disabling this can be a security risk! + * + * Comment to skip extendedKeyUsage checking for certificates. + */ +#define MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE + +/** + * \def MBEDTLS_X509_RSASSA_PSS_SUPPORT + * + * Enable parsing and verification of X.509 certificates, CRLs and CSRS + * signed with RSASSA-PSS (aka PKCS#1 v2.1). + * + * Comment this macro to disallow using RSASSA-PSS in certificates. + */ +//#define MBEDTLS_X509_RSASSA_PSS_SUPPORT + +/** + * \def MBEDTLS_ZLIB_SUPPORT + * + * If set, the SSL/TLS module uses ZLIB to support compression and + * decompression of packet data. + * + * \warning TLS-level compression MAY REDUCE SECURITY! See for example the + * CRIME attack. Before enabling this option, you should examine with care if + * CRIME or similar exploits may be a applicable to your use case. + * + * \note Currently compression can't be used with DTLS. + * + * \deprecated This feature is deprecated and will be removed + * in the next major revision of the library. + * + * Used in: library/ssl_tls.c + * library/ssl_cli.c + * library/ssl_srv.c + * + * This feature requires zlib library and headers to be present. + * + * Uncomment to enable use of ZLIB + */ +//#define MBEDTLS_ZLIB_SUPPORT +/* \} name SECTION: mbed TLS feature support */ + +/** + * \name SECTION: mbed TLS modules + * + * This section enables or disables entire modules in mbed TLS + * \{ + */ + +/** + * \def MBEDTLS_AESNI_C + * + * Enable AES-NI support on x86-64. + * + * Module: library/aesni.c + * Caller: library/aes.c + * + * Requires: MBEDTLS_HAVE_ASM + * + * This modules adds support for the AES-NI instructions on x86-64 + */ +//#define MBEDTLS_AESNI_C + +/** + * \def MBEDTLS_AES_C + * + * Enable the AES block cipher. + * + * Module: library/aes.c + * Caller: library/cipher.c + * library/pem.c + * library/ctr_drbg.c + * + * This module enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_RSA_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA256 + * MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA + * MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384 + * MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA384 + * MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA + * MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256 + * MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256 + * MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA + * + * PEM_PARSE uses AES for decrypting encrypted keys. + */ +#define MBEDTLS_AES_C + +/** + * \def MBEDTLS_ARC4_C + * + * Enable the ARCFOUR stream cipher. + * + * Module: library/arc4.c + * Caller: library/cipher.c + * + * This module enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA + * MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA + * MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA + * MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA + * MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA + * MBEDTLS_TLS_RSA_WITH_RC4_128_SHA + * MBEDTLS_TLS_RSA_WITH_RC4_128_MD5 + * MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA + * MBEDTLS_TLS_PSK_WITH_RC4_128_SHA + * + * \warning ARC4 is considered a weak cipher and its use constitutes a + * security risk. If possible, we recommend avoidng dependencies on + * it, and considering stronger ciphers instead. + * + */ +//#define MBEDTLS_ARC4_C + +/** + * \def MBEDTLS_ASN1_PARSE_C + * + * Enable the generic ASN1 parser. + * + * Module: library/asn1.c + * Caller: library/x509.c + * library/dhm.c + * library/pkcs12.c + * library/pkcs5.c + * library/pkparse.c + */ +#define MBEDTLS_ASN1_PARSE_C + +/** + * \def MBEDTLS_ASN1_WRITE_C + * + * Enable the generic ASN1 writer. + * + * Module: library/asn1write.c + * Caller: library/ecdsa.c + * library/pkwrite.c + * library/x509_create.c + * library/x509write_crt.c + * library/x509write_csr.c + */ +#define MBEDTLS_ASN1_WRITE_C + +/** + * \def MBEDTLS_BASE64_C + * + * Enable the Base64 module. + * + * Module: library/base64.c + * Caller: library/pem.c + * + * This module is required for PEM support (required by X.509). + */ +#define MBEDTLS_BASE64_C + +/** + * \def MBEDTLS_BIGNUM_C + * + * Enable the multi-precision integer library. + * + * Module: library/bignum.c + * Caller: library/dhm.c + * library/ecp.c + * library/ecdsa.c + * library/rsa.c + * library/rsa_internal.c + * library/ssl_tls.c + * + * This module is required for RSA, DHM and ECC (ECDH, ECDSA) support. + */ +#define MBEDTLS_BIGNUM_C + +/** + * \def MBEDTLS_BLOWFISH_C + * + * Enable the Blowfish block cipher. + * + * Module: library/blowfish.c + */ +//#define MBEDTLS_BLOWFISH_C + +/** + * \def MBEDTLS_CAMELLIA_C + * + * Enable the Camellia block cipher. + * + * Module: library/camellia.c + * Caller: library/cipher.c + * + * This module enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA + * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 + * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA + * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA + * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 + * MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384 + * MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384 + * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256 + * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256 + */ +//#define MBEDTLS_CAMELLIA_C + +/** + * \def MBEDTLS_ARIA_C + * + * Enable the ARIA block cipher. + * + * Module: library/aria.c + * Caller: library/cipher.c + * + * This module enables the following ciphersuites (if other requisites are + * enabled as well): + * + * MBEDTLS_TLS_RSA_WITH_ARIA_128_CBC_SHA256 + * MBEDTLS_TLS_RSA_WITH_ARIA_256_CBC_SHA384 + * MBEDTLS_TLS_DHE_RSA_WITH_ARIA_128_CBC_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_ARIA_256_CBC_SHA384 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384 + * MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384 + * MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384 + * MBEDTLS_TLS_RSA_WITH_ARIA_128_GCM_SHA256 + * MBEDTLS_TLS_RSA_WITH_ARIA_256_GCM_SHA384 + * MBEDTLS_TLS_DHE_RSA_WITH_ARIA_128_GCM_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_ARIA_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256 + * MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384 + * MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256 + * MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384 + * MBEDTLS_TLS_PSK_WITH_ARIA_128_CBC_SHA256 + * MBEDTLS_TLS_PSK_WITH_ARIA_256_CBC_SHA384 + * MBEDTLS_TLS_DHE_PSK_WITH_ARIA_128_CBC_SHA256 + * MBEDTLS_TLS_DHE_PSK_WITH_ARIA_256_CBC_SHA384 + * MBEDTLS_TLS_RSA_PSK_WITH_ARIA_128_CBC_SHA256 + * MBEDTLS_TLS_RSA_PSK_WITH_ARIA_256_CBC_SHA384 + * MBEDTLS_TLS_PSK_WITH_ARIA_128_GCM_SHA256 + * MBEDTLS_TLS_PSK_WITH_ARIA_256_GCM_SHA384 + * MBEDTLS_TLS_DHE_PSK_WITH_ARIA_128_GCM_SHA256 + * MBEDTLS_TLS_DHE_PSK_WITH_ARIA_256_GCM_SHA384 + * MBEDTLS_TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256 + * MBEDTLS_TLS_RSA_PSK_WITH_ARIA_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384 + */ +//#define MBEDTLS_ARIA_C + +/** + * \def MBEDTLS_CCM_C + * + * Enable the Counter with CBC-MAC (CCM) mode for 128-bit block cipher. + * + * Module: library/ccm.c + * + * Requires: MBEDTLS_AES_C or MBEDTLS_CAMELLIA_C + * + * This module enables the AES-CCM ciphersuites, if other requisites are + * enabled as well. + */ +//#define MBEDTLS_CCM_C + +/** + * \def MBEDTLS_CERTS_C + * + * Enable the test certificates. + * + * Module: library/certs.c + * Caller: + * + * This module is used for testing (ssl_client/server). + */ +//#define MBEDTLS_CERTS_C + +/** + * \def MBEDTLS_CHACHA20_C + * + * Enable the ChaCha20 stream cipher. + * + * Module: library/chacha20.c + */ +//#define MBEDTLS_CHACHA20_C + +/** + * \def MBEDTLS_CHACHAPOLY_C + * + * Enable the ChaCha20-Poly1305 AEAD algorithm. + * + * Module: library/chachapoly.c + * + * This module requires: MBEDTLS_CHACHA20_C, MBEDTLS_POLY1305_C + */ +//#define MBEDTLS_CHACHAPOLY_C + +/** + * \def MBEDTLS_CIPHER_C + * + * Enable the generic cipher layer. + * + * Module: library/cipher.c + * Caller: library/ssl_tls.c + * + * Uncomment to enable generic cipher wrappers. + */ +#define MBEDTLS_CIPHER_C + +/** + * \def MBEDTLS_CMAC_C + * + * Enable the CMAC (Cipher-based Message Authentication Code) mode for block + * ciphers. + * + * Module: library/cmac.c + * + * Requires: MBEDTLS_AES_C or MBEDTLS_DES_C + * + */ +//#define MBEDTLS_CMAC_C + +/** + * \def MBEDTLS_CTR_DRBG_C + * + * Enable the CTR_DRBG AES-based random generator. + * The CTR_DRBG generator uses AES-256 by default. + * To use AES-128 instead, enable MBEDTLS_CTR_DRBG_USE_128_BIT_KEY below. + * + * Module: library/ctr_drbg.c + * Caller: + * + * Requires: MBEDTLS_AES_C + * + * This module provides the CTR_DRBG AES random number generator. + */ +#define MBEDTLS_CTR_DRBG_C + +/** + * \def MBEDTLS_DEBUG_C + * + * Enable the debug functions. + * + * Module: library/debug.c + * Caller: library/ssl_cli.c + * library/ssl_srv.c + * library/ssl_tls.c + * + * This module provides debugging functions. + */ +//#define MBEDTLS_DEBUG_C + +/** + * \def MBEDTLS_DES_C + * + * Enable the DES block cipher. + * + * Module: library/des.c + * Caller: library/pem.c + * library/cipher.c + * + * This module enables the following ciphersuites (if other requisites are + * enabled as well): + * MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA + * MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA + * + * PEM_PARSE uses DES/3DES for decrypting encrypted keys. + * + * \warning DES is considered a weak cipher and its use constitutes a + * security risk. We recommend considering stronger ciphers instead. + */ +//#define MBEDTLS_DES_C + +/** + * \def MBEDTLS_DHM_C + * + * Enable the Diffie-Hellman-Merkle module. + * + * Module: library/dhm.c + * Caller: library/ssl_cli.c + * library/ssl_srv.c + * + * This module is used by the following key exchanges: + * DHE-RSA, DHE-PSK + * + * \warning Using DHE constitutes a security risk as it + * is not possible to validate custom DH parameters. + * If possible, it is recommended users should consider + * preferring other methods of key exchange. + * See dhm.h for more details. + * + */ +//#define MBEDTLS_DHM_C + +/** + * \def MBEDTLS_ECDH_C + * + * Enable the elliptic curve Diffie-Hellman library. + * + * Module: library/ecdh.c + * Caller: library/ssl_cli.c + * library/ssl_srv.c + * + * This module is used by the following key exchanges: + * ECDHE-ECDSA, ECDHE-RSA, DHE-PSK + * + * Requires: MBEDTLS_ECP_C + */ +#define MBEDTLS_ECDH_C + +/** + * \def MBEDTLS_ECDSA_C + * + * Enable the elliptic curve DSA library. + * + * Module: library/ecdsa.c + * Caller: + * + * This module is used by the following key exchanges: + * ECDHE-ECDSA + * + * Requires: MBEDTLS_ECP_C, MBEDTLS_ASN1_WRITE_C, MBEDTLS_ASN1_PARSE_C + */ +#define MBEDTLS_ECDSA_C + +/** + * \def MBEDTLS_ECJPAKE_C + * + * Enable the elliptic curve J-PAKE library. + * + * \warning This is currently experimental. EC J-PAKE support is based on the + * Thread v1.0.0 specification; incompatible changes to the specification + * might still happen. For this reason, this is disabled by default. + * + * Module: library/ecjpake.c + * Caller: + * + * This module is used by the following key exchanges: + * ECJPAKE + * + * Requires: MBEDTLS_ECP_C, MBEDTLS_MD_C + */ +//#define MBEDTLS_ECJPAKE_C + +/** + * \def MBEDTLS_ECP_C + * + * Enable the elliptic curve over GF(p) library. + * + * Module: library/ecp.c + * Caller: library/ecdh.c + * library/ecdsa.c + * library/ecjpake.c + * + * Requires: MBEDTLS_BIGNUM_C and at least one MBEDTLS_ECP_DP_XXX_ENABLED + */ +#define MBEDTLS_ECP_C + +/** + * \def MBEDTLS_ENTROPY_C + * + * Enable the platform-specific entropy code. + * + * Module: library/entropy.c + * Caller: + * + * Requires: MBEDTLS_SHA512_C or MBEDTLS_SHA256_C + * + * This module provides a generic entropy pool + */ +#define MBEDTLS_ENTROPY_C + +/** + * \def MBEDTLS_ERROR_C + * + * Enable error code to error string conversion. + * + * Module: library/error.c + * Caller: + * + * This module enables mbedtls_strerror(). + */ +//#define MBEDTLS_ERROR_C + +/** + * \def MBEDTLS_GCM_C + * + * Enable the Galois/Counter Mode (GCM) for AES. + * + * Module: library/gcm.c + * + * Requires: MBEDTLS_AES_C or MBEDTLS_CAMELLIA_C + * + * This module enables the AES-GCM and CAMELLIA-GCM ciphersuites, if other + * requisites are enabled as well. + */ +#define MBEDTLS_GCM_C + +/** + * \def MBEDTLS_HAVEGE_C + * + * Enable the HAVEGE random generator. + * + * Warning: the HAVEGE random generator is not suitable for virtualized + * environments + * + * Warning: the HAVEGE random generator is dependent on timing and specific + * processor traits. It is therefore not advised to use HAVEGE as + * your applications primary random generator or primary entropy pool + * input. As a secondary input to your entropy pool, it IS able add + * the (limited) extra entropy it provides. + * + * Module: library/havege.c + * Caller: + * + * Requires: MBEDTLS_TIMING_C + * + * Uncomment to enable the HAVEGE random generator. + */ +//#define MBEDTLS_HAVEGE_C + +/** + * \def MBEDTLS_HKDF_C + * + * Enable the HKDF algorithm (RFC 5869). + * + * Module: library/hkdf.c + * Caller: + * + * Requires: MBEDTLS_MD_C + * + * This module adds support for the Hashed Message Authentication Code + * (HMAC)-based key derivation function (HKDF). + */ +//#define MBEDTLS_HKDF_C + +/** + * \def MBEDTLS_HMAC_DRBG_C + * + * Enable the HMAC_DRBG random generator. + * + * Module: library/hmac_drbg.c + * Caller: + * + * Requires: MBEDTLS_MD_C + * + * Uncomment to enable the HMAC_DRBG random number geerator. + */ +//#define MBEDTLS_HMAC_DRBG_C + +/** + * \def MBEDTLS_NIST_KW_C + * + * Enable the Key Wrapping mode for 128-bit block ciphers, + * as defined in NIST SP 800-38F. Only KW and KWP modes + * are supported. At the moment, only AES is approved by NIST. + * + * Module: library/nist_kw.c + * + * Requires: MBEDTLS_AES_C and MBEDTLS_CIPHER_C + */ +//#define MBEDTLS_NIST_KW_C + +/** + * \def MBEDTLS_MD_C + * + * Enable the generic message digest layer. + * + * Module: library/md.c + * Caller: + * + * Uncomment to enable generic message digest wrappers. + */ +#define MBEDTLS_MD_C + +/** + * \def MBEDTLS_MD2_C + * + * Enable the MD2 hash algorithm. + * + * Module: library/md2.c + * Caller: + * + * Uncomment to enable support for (rare) MD2-signed X.509 certs. + * + * \warning MD2 is considered a weak message digest and its use constitutes a + * security risk. If possible, we recommend avoiding dependencies on + * it, and considering stronger message digests instead. + * + */ +//#define MBEDTLS_MD2_C + +/** + * \def MBEDTLS_MD4_C + * + * Enable the MD4 hash algorithm. + * + * Module: library/md4.c + * Caller: + * + * Uncomment to enable support for (rare) MD4-signed X.509 certs. + * + * \warning MD4 is considered a weak message digest and its use constitutes a + * security risk. If possible, we recommend avoiding dependencies on + * it, and considering stronger message digests instead. + * + */ +//#define MBEDTLS_MD4_C + +/** + * \def MBEDTLS_MD5_C + * + * Enable the MD5 hash algorithm. + * + * Module: library/md5.c + * Caller: library/md.c + * library/pem.c + * library/ssl_tls.c + * + * This module is required for SSL/TLS up to version 1.1, and for TLS 1.2 + * depending on the handshake parameters. Further, it is used for checking + * MD5-signed certificates, and for PBKDF1 when decrypting PEM-encoded + * encrypted keys. + * + * \warning MD5 is considered a weak message digest and its use constitutes a + * security risk. If possible, we recommend avoiding dependencies on + * it, and considering stronger message digests instead. + * + */ +//#define MBEDTLS_MD5_C + +/** + * \def MBEDTLS_MEMORY_BUFFER_ALLOC_C + * + * Enable the buffer allocator implementation that makes use of a (stack) + * based buffer to 'allocate' dynamic memory. (replaces calloc() and free() + * calls) + * + * Module: library/memory_buffer_alloc.c + * + * Requires: MBEDTLS_PLATFORM_C + * MBEDTLS_PLATFORM_MEMORY (to use it within mbed TLS) + * + * Enable this module to enable the buffer memory allocator. + */ +//#define MBEDTLS_MEMORY_BUFFER_ALLOC_C + +/** + * \def MBEDTLS_NET_C + * + * Enable the TCP and UDP over IPv6/IPv4 networking routines. + * + * \note This module only works on POSIX/Unix (including Linux, BSD and OS X) + * and Windows. For other platforms, you'll want to disable it, and write your + * own networking callbacks to be passed to \c mbedtls_ssl_set_bio(). + * + * \note See also our Knowledge Base article about porting to a new + * environment: + * https://tls.mbed.org/kb/how-to/how-do-i-port-mbed-tls-to-a-new-environment-OS + * + * Module: library/net_sockets.c + * + * This module provides networking routines. + */ +//#define MBEDTLS_NET_C + +/** + * \def MBEDTLS_OID_C + * + * Enable the OID database. + * + * Module: library/oid.c + * Caller: library/asn1write.c + * library/pkcs5.c + * library/pkparse.c + * library/pkwrite.c + * library/rsa.c + * library/x509.c + * library/x509_create.c + * library/x509_crl.c + * library/x509_crt.c + * library/x509_csr.c + * library/x509write_crt.c + * library/x509write_csr.c + * + * This modules translates between OIDs and internal values. + */ +#define MBEDTLS_OID_C + +/** + * \def MBEDTLS_PADLOCK_C + * + * Enable VIA Padlock support on x86. + * + * Module: library/padlock.c + * Caller: library/aes.c + * + * Requires: MBEDTLS_HAVE_ASM + * + * This modules adds support for the VIA PadLock on x86. + */ +//#define MBEDTLS_PADLOCK_C + +/** + * \def MBEDTLS_PEM_PARSE_C + * + * Enable PEM decoding / parsing. + * + * Module: library/pem.c + * Caller: library/dhm.c + * library/pkparse.c + * library/x509_crl.c + * library/x509_crt.c + * library/x509_csr.c + * + * Requires: MBEDTLS_BASE64_C + * + * This modules adds support for decoding / parsing PEM files. + */ +#define MBEDTLS_PEM_PARSE_C + +/** + * \def MBEDTLS_PEM_WRITE_C + * + * Enable PEM encoding / writing. + * + * Module: library/pem.c + * Caller: library/pkwrite.c + * library/x509write_crt.c + * library/x509write_csr.c + * + * Requires: MBEDTLS_BASE64_C + * + * This modules adds support for encoding / writing PEM files. + */ +//#define MBEDTLS_PEM_WRITE_C + +/** + * \def MBEDTLS_PK_C + * + * Enable the generic public (asymetric) key layer. + * + * Module: library/pk.c + * Caller: library/ssl_tls.c + * library/ssl_cli.c + * library/ssl_srv.c + * + * Requires: MBEDTLS_RSA_C or MBEDTLS_ECP_C + * + * Uncomment to enable generic public key wrappers. + */ +#define MBEDTLS_PK_C + +/** + * \def MBEDTLS_PK_PARSE_C + * + * Enable the generic public (asymetric) key parser. + * + * Module: library/pkparse.c + * Caller: library/x509_crt.c + * library/x509_csr.c + * + * Requires: MBEDTLS_PK_C + * + * Uncomment to enable generic public key parse functions. + */ +#define MBEDTLS_PK_PARSE_C + +/** + * \def MBEDTLS_PK_WRITE_C + * + * Enable the generic public (asymetric) key writer. + * + * Module: library/pkwrite.c + * Caller: library/x509write.c + * + * Requires: MBEDTLS_PK_C + * + * Uncomment to enable generic public key write functions. + */ +#define MBEDTLS_PK_WRITE_C + +/** + * \def MBEDTLS_PKCS5_C + * + * Enable PKCS#5 functions. + * + * Module: library/pkcs5.c + * + * Requires: MBEDTLS_MD_C + * + * This module adds support for the PKCS#5 functions. + */ +//#define MBEDTLS_PKCS5_C + +/** + * \def MBEDTLS_PKCS11_C + * + * Enable wrapper for PKCS#11 smartcard support. + * + * Module: library/pkcs11.c + * Caller: library/pk.c + * + * Requires: MBEDTLS_PK_C + * + * This module enables SSL/TLS PKCS #11 smartcard support. + * Requires the presence of the PKCS#11 helper library (libpkcs11-helper) + */ +//#define MBEDTLS_PKCS11_C + +/** + * \def MBEDTLS_PKCS12_C + * + * Enable PKCS#12 PBE functions. + * Adds algorithms for parsing PKCS#8 encrypted private keys + * + * Module: library/pkcs12.c + * Caller: library/pkparse.c + * + * Requires: MBEDTLS_ASN1_PARSE_C, MBEDTLS_CIPHER_C, MBEDTLS_MD_C + * Can use: MBEDTLS_ARC4_C + * + * This module enables PKCS#12 functions. + */ +//#define MBEDTLS_PKCS12_C + +/** + * \def MBEDTLS_PLATFORM_C + * + * Enable the platform abstraction layer that allows you to re-assign + * functions like calloc(), free(), snprintf(), printf(), fprintf(), exit(). + * + * Enabling MBEDTLS_PLATFORM_C enables to use of MBEDTLS_PLATFORM_XXX_ALT + * or MBEDTLS_PLATFORM_XXX_MACRO directives, allowing the functions mentioned + * above to be specified at runtime or compile time respectively. + * + * \note This abstraction layer must be enabled on Windows (including MSYS2) + * as other module rely on it for a fixed snprintf implementation. + * + * Module: library/platform.c + * Caller: Most other .c files + * + * This module enables abstraction of common (libc) functions. + */ +#define MBEDTLS_PLATFORM_C + +/** + * \def MBEDTLS_POLY1305_C + * + * Enable the Poly1305 MAC algorithm. + * + * Module: library/poly1305.c + * Caller: library/chachapoly.c + */ +//#define MBEDTLS_POLY1305_C + +/** + * \def MBEDTLS_RIPEMD160_C + * + * Enable the RIPEMD-160 hash algorithm. + * + * Module: library/ripemd160.c + * Caller: library/md.c + * + */ +//#define MBEDTLS_RIPEMD160_C + +/** + * \def MBEDTLS_RSA_C + * + * Enable the RSA public-key cryptosystem. + * + * Module: library/rsa.c + * library/rsa_internal.c + * Caller: library/ssl_cli.c + * library/ssl_srv.c + * library/ssl_tls.c + * library/x509.c + * + * This module is used by the following key exchanges: + * RSA, DHE-RSA, ECDHE-RSA, RSA-PSK + * + * Requires: MBEDTLS_BIGNUM_C, MBEDTLS_OID_C + */ +#define MBEDTLS_RSA_C + +/** + * \def MBEDTLS_SHA1_C + * + * Enable the SHA1 cryptographic hash algorithm. + * + * Module: library/sha1.c + * Caller: library/md.c + * library/ssl_cli.c + * library/ssl_srv.c + * library/ssl_tls.c + * library/x509write_crt.c + * + * This module is required for SSL/TLS up to version 1.1, for TLS 1.2 + * depending on the handshake parameters, and for SHA1-signed certificates. + * + * \warning SHA-1 is considered a weak message digest and its use constitutes + * a security risk. If possible, we recommend avoiding dependencies + * on it, and considering stronger message digests instead. + * + */ +#define MBEDTLS_SHA1_C + +/** + * \def MBEDTLS_SHA256_C + * + * Enable the SHA-224 and SHA-256 cryptographic hash algorithms. + * + * Module: library/sha256.c + * Caller: library/entropy.c + * library/md.c + * library/ssl_cli.c + * library/ssl_srv.c + * library/ssl_tls.c + * + * This module adds support for SHA-224 and SHA-256. + * This module is required for the SSL/TLS 1.2 PRF function. + */ +#define MBEDTLS_SHA256_C + +/** + * \def MBEDTLS_SHA512_C + * + * Enable the SHA-384 and SHA-512 cryptographic hash algorithms. + * + * Module: library/sha512.c + * Caller: library/entropy.c + * library/md.c + * library/ssl_cli.c + * library/ssl_srv.c + * + * This module adds support for SHA-384 and SHA-512. + */ +//#define MBEDTLS_SHA512_C + +/** + * \def MBEDTLS_SSL_CACHE_C + * + * Enable simple SSL cache implementation. + * + * Module: library/ssl_cache.c + * Caller: + * + * Requires: MBEDTLS_SSL_CACHE_C + */ +//#define MBEDTLS_SSL_CACHE_C + +/** + * \def MBEDTLS_SSL_COOKIE_C + * + * Enable basic implementation of DTLS cookies for hello verification. + * + * Module: library/ssl_cookie.c + * Caller: + */ +//#define MBEDTLS_SSL_COOKIE_C + +/** + * \def MBEDTLS_SSL_TICKET_C + * + * Enable an implementation of TLS server-side callbacks for session tickets. + * + * Module: library/ssl_ticket.c + * Caller: + * + * Requires: MBEDTLS_CIPHER_C + */ +//#define MBEDTLS_SSL_TICKET_C + +/** + * \def MBEDTLS_SSL_CLI_C + * + * Enable the SSL/TLS client code. + * + * Module: library/ssl_cli.c + * Caller: + * + * Requires: MBEDTLS_SSL_TLS_C + * + * This module is required for SSL/TLS client support. + */ +#define MBEDTLS_SSL_CLI_C + +/** + * \def MBEDTLS_SSL_SRV_C + * + * Enable the SSL/TLS server code. + * + * Module: library/ssl_srv.c + * Caller: + * + * Requires: MBEDTLS_SSL_TLS_C + * + * This module is required for SSL/TLS server support. + */ +//#define MBEDTLS_SSL_SRV_C + +/** + * \def MBEDTLS_SSL_TLS_C + * + * Enable the generic SSL/TLS code. + * + * Module: library/ssl_tls.c + * Caller: library/ssl_cli.c + * library/ssl_srv.c + * + * Requires: MBEDTLS_CIPHER_C, MBEDTLS_MD_C + * and at least one of the MBEDTLS_SSL_PROTO_XXX defines + * + * This module is required for SSL/TLS. + */ +#define MBEDTLS_SSL_TLS_C + +/** + * \def MBEDTLS_THREADING_C + * + * Enable the threading abstraction layer. + * By default mbed TLS assumes it is used in a non-threaded environment or that + * contexts are not shared between threads. If you do intend to use contexts + * between threads, you will need to enable this layer to prevent race + * conditions. See also our Knowledge Base article about threading: + * https://tls.mbed.org/kb/development/thread-safety-and-multi-threading + * + * Module: library/threading.c + * + * This allows different threading implementations (self-implemented or + * provided). + * + * You will have to enable either MBEDTLS_THREADING_ALT or + * MBEDTLS_THREADING_PTHREAD. + * + * Enable this layer to allow use of mutexes within mbed TLS + */ +#define MBEDTLS_THREADING_C + +/** + * \def MBEDTLS_TIMING_C + * + * Enable the semi-portable timing interface. + * + * \note The provided implementation only works on POSIX/Unix (including Linux, + * BSD and OS X) and Windows. On other platforms, you can either disable that + * module and provide your own implementations of the callbacks needed by + * \c mbedtls_ssl_set_timer_cb() for DTLS, or leave it enabled and provide + * your own implementation of the whole module by setting + * \c MBEDTLS_TIMING_ALT in the current file. + * + * \note See also our Knowledge Base article about porting to a new + * environment: + * https://tls.mbed.org/kb/how-to/how-do-i-port-mbed-tls-to-a-new-environment-OS + * + * Module: library/timing.c + * Caller: library/havege.c + * + * This module is used by the HAVEGE random number generator. + */ +//#define MBEDTLS_TIMING_C + +/** + * \def MBEDTLS_VERSION_C + * + * Enable run-time version information. + * + * Module: library/version.c + * + * This module provides run-time version information. + */ +//#define MBEDTLS_VERSION_C + +/** + * \def MBEDTLS_X509_USE_C + * + * Enable X.509 core for using certificates. + * + * Module: library/x509.c + * Caller: library/x509_crl.c + * library/x509_crt.c + * library/x509_csr.c + * + * Requires: MBEDTLS_ASN1_PARSE_C, MBEDTLS_BIGNUM_C, MBEDTLS_OID_C, + * MBEDTLS_PK_PARSE_C + * + * This module is required for the X.509 parsing modules. + */ +#define MBEDTLS_X509_USE_C + +/** + * \def MBEDTLS_X509_CRT_PARSE_C + * + * Enable X.509 certificate parsing. + * + * Module: library/x509_crt.c + * Caller: library/ssl_cli.c + * library/ssl_srv.c + * library/ssl_tls.c + * + * Requires: MBEDTLS_X509_USE_C + * + * This module is required for X.509 certificate parsing. + */ +#define MBEDTLS_X509_CRT_PARSE_C + +/** + * \def MBEDTLS_X509_CRL_PARSE_C + * + * Enable X.509 CRL parsing. + * + * Module: library/x509_crl.c + * Caller: library/x509_crt.c + * + * Requires: MBEDTLS_X509_USE_C + * + * This module is required for X.509 CRL parsing. + */ +//#define MBEDTLS_X509_CRL_PARSE_C + +/** + * \def MBEDTLS_X509_CSR_PARSE_C + * + * Enable X.509 Certificate Signing Request (CSR) parsing. + * + * Module: library/x509_csr.c + * Caller: library/x509_crt_write.c + * + * Requires: MBEDTLS_X509_USE_C + * + * This module is used for reading X.509 certificate request. + */ +//#define MBEDTLS_X509_CSR_PARSE_C + +/** + * \def MBEDTLS_X509_CREATE_C + * + * Enable X.509 core for creating certificates. + * + * Module: library/x509_create.c + * + * Requires: MBEDTLS_BIGNUM_C, MBEDTLS_OID_C, MBEDTLS_PK_WRITE_C + * + * This module is the basis for creating X.509 certificates and CSRs. + */ +//#define MBEDTLS_X509_CREATE_C + +/** + * \def MBEDTLS_X509_CRT_WRITE_C + * + * Enable creating X.509 certificates. + * + * Module: library/x509_crt_write.c + * + * Requires: MBEDTLS_X509_CREATE_C + * + * This module is required for X.509 certificate creation. + */ +//#define MBEDTLS_X509_CRT_WRITE_C + +/** + * \def MBEDTLS_X509_CSR_WRITE_C + * + * Enable creating X.509 Certificate Signing Requests (CSR). + * + * Module: library/x509_csr_write.c + * + * Requires: MBEDTLS_X509_CREATE_C + * + * This module is required for X.509 certificate request writing. + */ +//#define MBEDTLS_X509_CSR_WRITE_C + +/** + * \def MBEDTLS_XTEA_C + * + * Enable the XTEA block cipher. + * + * Module: library/xtea.c + * Caller: + */ +//#define MBEDTLS_XTEA_C + +/* \} name SECTION: mbed TLS modules */ + +/** + * \name SECTION: Module configuration options + * + * This section allows for the setting of module specific sizes and + * configuration options. The default values are already present in the + * relevant header files and should suffice for the regular use cases. + * + * Our advice is to enable options and change their values here + * only if you have a good reason and know the consequences. + * + * Please check the respective header file for documentation on these + * parameters (to prevent duplicate documentation). + * \{ + */ + +/* MPI / BIGNUM options */ +//#define MBEDTLS_MPI_WINDOW_SIZE 6 /**< Maximum windows size used. */ +//#define MBEDTLS_MPI_MAX_SIZE 1024 /**< Maximum number of bytes for usable MPIs. */ + +/* CTR_DRBG options */ +//#define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48 /**< Amount of entropy used per seed by default (48 with SHA-512, 32 with SHA-256) */ +//#define MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000 /**< Interval before reseed is performed by default */ +//#define MBEDTLS_CTR_DRBG_MAX_INPUT 256 /**< Maximum number of additional input bytes */ +//#define MBEDTLS_CTR_DRBG_MAX_REQUEST 1024 /**< Maximum number of requested bytes per call */ +//#define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT 384 /**< Maximum size of (re)seed buffer */ + +/* HMAC_DRBG options */ +//#define MBEDTLS_HMAC_DRBG_RESEED_INTERVAL 10000 /**< Interval before reseed is performed by default */ +//#define MBEDTLS_HMAC_DRBG_MAX_INPUT 256 /**< Maximum number of additional input bytes */ +//#define MBEDTLS_HMAC_DRBG_MAX_REQUEST 1024 /**< Maximum number of requested bytes per call */ +//#define MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT 384 /**< Maximum size of (re)seed buffer */ + +/* ECP options */ +//#define MBEDTLS_ECP_MAX_BITS 521 /**< Maximum bit size of groups */ +//#define MBEDTLS_ECP_WINDOW_SIZE 6 /**< Maximum window size used */ +//#define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 /**< Enable fixed-point speed-up */ + +/* Entropy options */ +//#define MBEDTLS_ENTROPY_MAX_SOURCES 20 /**< Maximum number of sources supported */ +//#define MBEDTLS_ENTROPY_MAX_GATHER 128 /**< Maximum amount requested from entropy sources */ +//#define MBEDTLS_ENTROPY_MIN_HARDWARE 32 /**< Default minimum number of bytes required for the hardware entropy source mbedtls_hardware_poll() before entropy is released */ + +/* Memory buffer allocator options */ +//#define MBEDTLS_MEMORY_ALIGN_MULTIPLE 4 /**< Align on multiples of this value */ + +/* Platform options */ +//#define MBEDTLS_PLATFORM_STD_MEM_HDR /**< Header to include if MBEDTLS_PLATFORM_NO_STD_FUNCTIONS is defined. Don't define if no header is needed. */ +//#define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< Default allocator to use, can be undefined */ +//#define MBEDTLS_PLATFORM_STD_FREE free /**< Default free to use, can be undefined */ +//#define MBEDTLS_PLATFORM_STD_EXIT exit /**< Default exit to use, can be undefined */ +//#define MBEDTLS_PLATFORM_STD_TIME time /**< Default time to use, can be undefined. MBEDTLS_HAVE_TIME must be enabled */ +//#define MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use, can be undefined */ +//#define MBEDTLS_PLATFORM_STD_PRINTF printf /**< Default printf to use, can be undefined */ +/* Note: your snprintf must correclty zero-terminate the buffer! */ +//#define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf /**< Default snprintf to use, can be undefined */ +//#define MBEDTLS_PLATFORM_STD_EXIT_SUCCESS 0 /**< Default exit value to use, can be undefined */ +//#define MBEDTLS_PLATFORM_STD_EXIT_FAILURE 1 /**< Default exit value to use, can be undefined */ +//#define MBEDTLS_PLATFORM_STD_NV_SEED_READ mbedtls_platform_std_nv_seed_read /**< Default nv_seed_read function to use, can be undefined */ +//#define MBEDTLS_PLATFORM_STD_NV_SEED_WRITE mbedtls_platform_std_nv_seed_write /**< Default nv_seed_write function to use, can be undefined */ +//#define MBEDTLS_PLATFORM_STD_NV_SEED_FILE "seedfile" /**< Seed file to read/write with default implementation */ + +/* To Use Function Macros MBEDTLS_PLATFORM_C must be enabled */ +/* MBEDTLS_PLATFORM_XXX_MACRO and MBEDTLS_PLATFORM_XXX_ALT cannot both be defined */ +//#define MBEDTLS_PLATFORM_CALLOC_MACRO calloc /**< Default allocator macro to use, can be undefined */ +//#define MBEDTLS_PLATFORM_FREE_MACRO free /**< Default free macro to use, can be undefined */ +//#define MBEDTLS_PLATFORM_EXIT_MACRO exit /**< Default exit macro to use, can be undefined */ +//#define MBEDTLS_PLATFORM_TIME_MACRO time /**< Default time macro to use, can be undefined. MBEDTLS_HAVE_TIME must be enabled */ +//#define MBEDTLS_PLATFORM_TIME_TYPE_MACRO time_t /**< Default time macro to use, can be undefined. MBEDTLS_HAVE_TIME must be enabled */ +//#define MBEDTLS_PLATFORM_FPRINTF_MACRO fprintf /**< Default fprintf macro to use, can be undefined */ +//#define MBEDTLS_PLATFORM_PRINTF_MACRO printf /**< Default printf macro to use, can be undefined */ +/* Note: your snprintf must correclty zero-terminate the buffer! */ +//#define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf /**< Default snprintf macro to use, can be undefined */ +//#define MBEDTLS_PLATFORM_NV_SEED_READ_MACRO mbedtls_platform_std_nv_seed_read /**< Default nv_seed_read function to use, can be undefined */ +//#define MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO mbedtls_platform_std_nv_seed_write /**< Default nv_seed_write function to use, can be undefined */ + +/** + * \brief This macro is invoked by the library when an invalid parameter + * is detected that is only checked with MBEDTLS_CHECK_PARAMS + * (see the documentation of that option for context). + * + * When you leave this undefined here, a default definition is + * provided that invokes the function mbedtls_param_failed(), + * which is declared in platform_util.h for the benefit of the + * library, but that you need to define in your application. + * + * When you define this here, this replaces the default + * definition in platform_util.h (which no longer declares the + * function mbedtls_param_failed()) and it is your responsibility + * to make sure this macro expands to something suitable (in + * particular, that all the necessary declarations are visible + * from within the library - you can ensure that by providing + * them in this file next to the macro definition). + * + * Note that you may define this macro to expand to nothing, in + * which case you don't have to worry about declarations or + * definitions. However, you will then be notified about invalid + * parameters only in non-void functions, and void function will + * just silently return early on invalid parameters, which + * partially negates the benefits of enabling + * #MBEDTLS_CHECK_PARAMS in the first place, so is discouraged. + * + * \param cond The expression that should evaluate to true, but doesn't. + */ +//#define MBEDTLS_PARAM_FAILED( cond ) assert( cond ) + +/* SSL Cache options */ +//#define MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT 86400 /**< 1 day */ +//#define MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES 50 /**< Maximum entries in cache */ + +/* SSL options */ + +/** \def MBEDTLS_SSL_MAX_CONTENT_LEN + * + * Maximum length (in bytes) of incoming and outgoing plaintext fragments. + * + * This determines the size of both the incoming and outgoing TLS I/O buffers + * in such a way that both are capable of holding the specified amount of + * plaintext data, regardless of the protection mechanism used. + * + * To configure incoming and outgoing I/O buffers separately, use + * #MBEDTLS_SSL_IN_CONTENT_LEN and #MBEDTLS_SSL_OUT_CONTENT_LEN, + * which overwrite the value set by this option. + * + * \note When using a value less than the default of 16KB on the client, it is + * recommended to use the Maximum Fragment Length (MFL) extension to + * inform the server about this limitation. On the server, there + * is no supported, standardized way of informing the client about + * restriction on the maximum size of incoming messages, and unless + * the limitation has been communicated by other means, it is recommended + * to only change the outgoing buffer size #MBEDTLS_SSL_OUT_CONTENT_LEN + * while keeping the default value of 16KB for the incoming buffer. + * + * Uncomment to set the maximum plaintext size of both + * incoming and outgoing I/O buffers. + */ +#define MBEDTLS_SSL_MAX_CONTENT_LEN 8192 + +/** \def MBEDTLS_SSL_IN_CONTENT_LEN + * + * Maximum length (in bytes) of incoming plaintext fragments. + * + * This determines the size of the incoming TLS I/O buffer in such a way + * that it is capable of holding the specified amount of plaintext data, + * regardless of the protection mechanism used. + * + * If this option is undefined, it inherits its value from + * #MBEDTLS_SSL_MAX_CONTENT_LEN. + * + * \note When using a value less than the default of 16KB on the client, it is + * recommended to use the Maximum Fragment Length (MFL) extension to + * inform the server about this limitation. On the server, there + * is no supported, standardized way of informing the client about + * restriction on the maximum size of incoming messages, and unless + * the limitation has been communicated by other means, it is recommended + * to only change the outgoing buffer size #MBEDTLS_SSL_OUT_CONTENT_LEN + * while keeping the default value of 16KB for the incoming buffer. + * + * Uncomment to set the maximum plaintext size of the incoming I/O buffer + * independently of the outgoing I/O buffer. + */ +//#define MBEDTLS_SSL_IN_CONTENT_LEN 16384 + +/** \def MBEDTLS_SSL_OUT_CONTENT_LEN + * + * Maximum length (in bytes) of outgoing plaintext fragments. + * + * This determines the size of the outgoing TLS I/O buffer in such a way + * that it is capable of holding the specified amount of plaintext data, + * regardless of the protection mechanism used. + * + * If this option undefined, it inherits its value from + * #MBEDTLS_SSL_MAX_CONTENT_LEN. + * + * It is possible to save RAM by setting a smaller outward buffer, while keeping + * the default inward 16384 byte buffer to conform to the TLS specification. + * + * The minimum required outward buffer size is determined by the handshake + * protocol's usage. Handshaking will fail if the outward buffer is too small. + * The specific size requirement depends on the configured ciphers and any + * certificate data which is sent during the handshake. + * + * Uncomment to set the maximum plaintext size of the outgoing I/O buffer + * independently of the incoming I/O buffer. + */ +//#define MBEDTLS_SSL_OUT_CONTENT_LEN 16384 + +/** \def MBEDTLS_SSL_DTLS_MAX_BUFFERING + * + * Maximum number of heap-allocated bytes for the purpose of + * DTLS handshake message reassembly and future message buffering. + * + * This should be at least 9/8 * MBEDTLSSL_IN_CONTENT_LEN + * to account for a reassembled handshake message of maximum size, + * together with its reassembly bitmap. + * + * A value of 2 * MBEDTLS_SSL_IN_CONTENT_LEN (32768 by default) + * should be sufficient for all practical situations as it allows + * to reassembly a large handshake message (such as a certificate) + * while buffering multiple smaller handshake messages. + * + */ +//#define MBEDTLS_SSL_DTLS_MAX_BUFFERING 32768 + +//#define MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME 86400 /**< Lifetime of session tickets (if enabled) */ +//#define MBEDTLS_PSK_MAX_LEN 32 /**< Max size of TLS pre-shared keys, in bytes (default 256 bits) */ +//#define MBEDTLS_SSL_COOKIE_TIMEOUT 60 /**< Default expiration delay of DTLS cookies, in seconds if HAVE_TIME, or in number of cookies issued */ + +/** + * Complete list of ciphersuites to use, in order of preference. + * + * \warning No dependency checking is done on that field! This option can only + * be used to restrict the set of available ciphersuites. It is your + * responsibility to make sure the needed modules are active. + * + * Use this to save a few hundred bytes of ROM (default ordering of all + * available ciphersuites) and a few to a few hundred bytes of RAM. + * + * The value below is only an example, not the default. + */ +//#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 + +/* X509 options */ +//#define MBEDTLS_X509_MAX_INTERMEDIATE_CA 8 /**< Maximum number of intermediate CAs in a verification chain. */ +//#define MBEDTLS_X509_MAX_FILE_PATH_LEN 512 /**< Maximum length of a path/filename string in bytes including the null terminator character ('\0'). */ + +/** + * Allow SHA-1 in the default TLS configuration for certificate signing. + * Without this build-time option, SHA-1 support must be activated explicitly + * through mbedtls_ssl_conf_cert_profile. Turning on this option is not + * recommended because of it is possible to generate SHA-1 collisions, however + * this may be safe for legacy infrastructure where additional controls apply. + * + * \warning SHA-1 is considered a weak message digest and its use constitutes + * a security risk. If possible, we recommend avoiding dependencies + * on it, and considering stronger message digests instead. + * + */ +//#define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES + +/** + * Allow SHA-1 in the default TLS configuration for TLS 1.2 handshake + * signature and ciphersuite selection. Without this build-time option, SHA-1 + * support must be activated explicitly through mbedtls_ssl_conf_sig_hashes. + * The use of SHA-1 in TLS <= 1.1 and in HMAC-SHA-1 is always allowed by + * default. At the time of writing, there is no practical attack on the use + * of SHA-1 in handshake signatures, hence this option is turned on by default + * to preserve compatibility with existing peers, but the general + * warning applies nonetheless: + * + * \warning SHA-1 is considered a weak message digest and its use constitutes + * a security risk. If possible, we recommend avoiding dependencies + * on it, and considering stronger message digests instead. + * + */ +//#define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE + +/** + * Uncomment the macro to let mbed TLS use your alternate implementation of + * mbedtls_platform_zeroize(). This replaces the default implementation in + * platform_util.c. + * + * mbedtls_platform_zeroize() is a widely used function across the library to + * zero a block of memory. The implementation is expected to be secure in the + * sense that it has been written to prevent the compiler from removing calls + * to mbedtls_platform_zeroize() as part of redundant code elimination + * optimizations. However, it is difficult to guarantee that calls to + * mbedtls_platform_zeroize() will not be optimized by the compiler as older + * versions of the C language standards do not provide a secure implementation + * of memset(). Therefore, MBEDTLS_PLATFORM_ZEROIZE_ALT enables users to + * configure their own implementation of mbedtls_platform_zeroize(), for + * example by using directives specific to their compiler, features from newer + * C standards (e.g using memset_s() in C11) or calling a secure memset() from + * their system (e.g explicit_bzero() in BSD). + */ +//#define MBEDTLS_PLATFORM_ZEROIZE_ALT + +/** + * Uncomment the macro to let Mbed TLS use your alternate implementation of + * mbedtls_platform_gmtime_r(). This replaces the default implementation in + * platform_util.c. + * + * gmtime() is not a thread-safe function as defined in the C standard. The + * library will try to use safer implementations of this function, such as + * gmtime_r() when available. However, if Mbed TLS cannot identify the target + * system, the implementation of mbedtls_platform_gmtime_r() will default to + * using the standard gmtime(). In this case, calls from the library to + * gmtime() will be guarded by the global mutex mbedtls_threading_gmtime_mutex + * if MBEDTLS_THREADING_C is enabled. We recommend that calls from outside the + * library are also guarded with this mutex to avoid race conditions. However, + * if the macro MBEDTLS_PLATFORM_GMTIME_R_ALT is defined, Mbed TLS will + * unconditionally use the implementation for mbedtls_platform_gmtime_r() + * supplied at compile time. + */ +//#define MBEDTLS_PLATFORM_GMTIME_R_ALT + +/* \} name SECTION: Customisation configuration options */ + +/* Target and application specific configurations + * + * Allow user to override any previous default. + */ +#if defined(MBEDTLS_USER_CONFIG_FILE) +#include MBEDTLS_USER_CONFIG_FILE +#endif + +#include "mbedtls/check_config.h" + +#endif /* MBEDTLS_CONFIG_H */ + diff --git a/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/demo_helpers.c b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/demo_helpers.c new file mode 100644 index 0000000000..408ab40fed --- /dev/null +++ b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/demo_helpers.c @@ -0,0 +1,341 @@ +/* + * FreeRTOS PKCS #11 V1.0.3 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://aws.amazon.com/freertos + * http://www.FreeRTOS.org + */ + +/* FreeRTOS includes. */ +#include "FreeRTOS.h" +#include "task.h" + +/* Standard includes. */ +#include "stdio.h" + +/* PKCS #11 includes. */ +#include "iot_pkcs11_config.h" +#include "iot_pkcs11.h" +#include "pkcs11.h" + +/* mbed TLS includes. */ +#include "mbedtls/pk.h" +#include "mbedtls/oid.h" + +/* Helpers include. */ +#include "demo_helpers.h" + +void vStart( CK_SESSION_HANDLE * pxSession, + CK_SLOT_ID ** ppxSlotId ) +{ + CK_RV xResult = CKR_OK; + + CK_FUNCTION_LIST_PTR pxFunctionList = NULL; + CK_C_INITIALIZE_ARGS xInitArgs = { 0 }; + CK_SESSION_HANDLE hSession = CK_INVALID_HANDLE; + CK_ULONG xSlotCount = 0; + CK_SLOT_ID * pxSlotId = NULL; + + xResult = C_GetFunctionList( &pxFunctionList ); + configASSERT( xResult == CKR_OK ); + configASSERT( pxFunctionList != NULL ); + configASSERT( pxFunctionList->C_Initialize != NULL ); + configASSERT( pxFunctionList->C_GetSlotList != NULL ); + configASSERT( pxFunctionList->C_OpenSession != NULL ); + configASSERT( pxFunctionList->C_Login != NULL ); + configASSERT( pxFunctionList->C_GenerateRandom != NULL ); + configASSERT( pxFunctionList->C_CloseSession != NULL ); + configASSERT( pxFunctionList->C_Finalize != NULL ); + + xResult = pxFunctionList->C_Initialize( &xInitArgs ); + configASSERT( xResult == CKR_OK ); + + xResult = pxFunctionList->C_GetSlotList( CK_TRUE, + NULL, + &xSlotCount ); + configASSERT( xResult == CKR_OK ); + + pxSlotId = pvPortMalloc( sizeof( CK_SLOT_ID ) * ( xSlotCount ) ); + configASSERT( pxSlotId != NULL ); + + xResult = pxFunctionList->C_GetSlotList( CK_TRUE, + pxSlotId, + &xSlotCount ); + configASSERT( xResult == CKR_OK ); + + xResult = pxFunctionList->C_OpenSession( pxSlotId[ 0 ], + CKF_SERIAL_SESSION | CKF_RW_SESSION, + NULL, /* Application defined pointer. */ + NULL, /* Callback function. */ + &hSession ); + configASSERT( xResult == CKR_OK ); + + + xResult = pxFunctionList->C_Login( hSession, + CKU_USER, + ( CK_UTF8CHAR_PTR ) configPKCS11_DEFAULT_USER_PIN, + sizeof( configPKCS11_DEFAULT_USER_PIN ) - 1UL ); + configASSERT( xResult == CKR_OK ); + + *ppxSlotId = pxSlotId; + *pxSession = hSession; +} +/*-----------------------------------------------------------*/ + +void vEnd( CK_SESSION_HANDLE xSession, + CK_SLOT_ID * pxSlotId ) +{ + C_CloseSession( xSession ); + C_Finalize( NULL ); + vPortFree( pxSlotId ); +} +/*-----------------------------------------------------------*/ + +void vWriteHexBytesToConsole( char * pcDescription, + CK_BYTE * pucData, + CK_ULONG ulDataLength ) +{ + /* This function is simply a helper function to print the raw hex values + * of an EC public key. It's explanation is not within the scope of the demos + * and is sparsely commented. */ +#define BYTES_TO_DISPLAY_PER_ROW 16 + char pcByteRow[ 1 + ( BYTES_TO_DISPLAY_PER_ROW * 2 ) + ( BYTES_TO_DISPLAY_PER_ROW / 2 ) ]; + char * pcNextChar = pcByteRow; + uint32_t ulIndex = 0; + uint8_t ucByteValue = 0; + + /* Write help text to the console. */ + configPRINTF( ( "%s, %d bytes:\r\n", pcDescription, ulDataLength ) ); + + /* Iterate over the bytes of the encoded public key. */ + for( ulIndex = 0; ulIndex < ulDataLength; ulIndex++ ) + { + /* Convert one byte to ASCII hex. */ + ucByteValue = *( pucData + ulIndex ); + snprintf( pcNextChar, + sizeof( pcByteRow ) - ( pcNextChar - pcByteRow ), + "%02x", + ucByteValue ); + pcNextChar += 2; + + /* Check for the end of a two-byte display word. */ + if( 0 == ( ( ulIndex + 1 ) % sizeof( uint16_t ) ) ) + { + *pcNextChar = ' '; + pcNextChar++; + } + + /* Check for the end of a row. */ + if( 0 == ( ( ulIndex + 1 ) % BYTES_TO_DISPLAY_PER_ROW ) ) + { + *pcNextChar = '\0'; + configPRINTF( ( pcByteRow ) ); + configPRINTF( ( "\r\n" ) ); + pcNextChar = pcByteRow; + } + } + + /* Check for a partial line to print. */ + if( pcNextChar > pcByteRow ) + { + *pcNextChar = '\0'; + configPRINTF( ( pcByteRow ) ); + configPRINTF( ( "\r\n" ) ); + } +} +/*-----------------------------------------------------------*/ + +/* Extract ECDSA public key. */ +CK_RV vExportPublicKey( CK_SESSION_HANDLE xSession, + CK_OBJECT_HANDLE xPublicKeyHandle, + CK_BYTE ** ppucDerPublicKey, + CK_ULONG * pulDerPublicKeyLength ) +{ + /* This function is simply a helper function to export the raw hex values + * of an EC public key into a buffer. It's explanation is not within the + * scope of the demos and is sparsely commented. */ + CK_RV xResult; + CK_FUNCTION_LIST_PTR pxFunctionList; + CK_KEY_TYPE xKeyType = 0; + CK_ATTRIBUTE xTemplate = { 0 }; + uint8_t pucEcP256AsnAndOid[] = + { + 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, + 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, + 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, + 0x42, 0x00 + }; + uint8_t pucUnusedKeyTag[] = { 0x04, 0x41 }; + + /* This variable is used only for its size. This gets rid of compiler warnings. */ + ( void ) pucUnusedKeyTag; + + xResult = C_GetFunctionList( &pxFunctionList ); + + /* Query the key type. */ + if( CKR_OK == xResult ) + { + xTemplate.type = CKA_KEY_TYPE; + xTemplate.pValue = &xKeyType; + xTemplate.ulValueLen = sizeof( xKeyType ); + xResult = pxFunctionList->C_GetAttributeValue( xSession, + xPublicKeyHandle, + &xTemplate, + 1 ); + } + + /* Scope to ECDSA keys only, since there's currently no use case for + * onboard keygen and certificate enrollment for RSA. */ + if( ( CKR_OK == xResult ) && ( CKK_ECDSA == xKeyType ) ) + { + /* Query the size of the public key. */ + xTemplate.type = CKA_EC_POINT; + xTemplate.pValue = NULL; + xTemplate.ulValueLen = 0; + xResult = pxFunctionList->C_GetAttributeValue( xSession, + xPublicKeyHandle, + &xTemplate, + 1 ); + + /* Allocate a buffer large enough for the full, encoded public key. */ + if( CKR_OK == xResult ) + { + /* Add space for the full DER header. */ + xTemplate.ulValueLen += sizeof( pucEcP256AsnAndOid ) - sizeof( pucUnusedKeyTag ); + *pulDerPublicKeyLength = xTemplate.ulValueLen; + + /* Get a heap buffer. */ + *ppucDerPublicKey = pvPortMalloc( xTemplate.ulValueLen ); + + /* Check for resource exhaustion. */ + if( NULL == *ppucDerPublicKey ) + { + xResult = CKR_HOST_MEMORY; + } + } + + /* Export the public key. */ + if( CKR_OK == xResult ) + { + xTemplate.pValue = *ppucDerPublicKey + sizeof( pucEcP256AsnAndOid ) - sizeof( pucUnusedKeyTag ); + xTemplate.ulValueLen -= ( sizeof( pucEcP256AsnAndOid ) - sizeof( pucUnusedKeyTag ) ); + xResult = pxFunctionList->C_GetAttributeValue( xSession, + xPublicKeyHandle, + &xTemplate, + 1 ); + } + + /* Prepend the full DER header. */ + if( CKR_OK == xResult ) + { + memcpy( *ppucDerPublicKey, pucEcP256AsnAndOid, sizeof( pucEcP256AsnAndOid ) ); + } + } + + /* Free memory if there was an error after allocation. */ + if( ( NULL != *ppucDerPublicKey ) && ( CKR_OK != xResult ) ) + { + vPortFree( *ppucDerPublicKey ); + *ppucDerPublicKey = NULL; + } + + return xResult; +} +/*-----------------------------------------------------------*/ + +void * pvCalloc( size_t xNumElements, + size_t xSize ) +{ + void * pvNew = pvPortMalloc( xNumElements * xSize ); + + if( NULL != pvNew ) + { + memset( pvNew, 0, xNumElements * xSize ); + } + + return pvNew; +} +/*-----------------------------------------------------------*/ + +void aws_mbedtls_mutex_init( mbedtls_threading_mutex_t * mutex ) +{ + mutex->mutex = xSemaphoreCreateMutex(); + + if( mutex->mutex != NULL ) + { + mutex->is_valid = 1; + } + else + { + mutex->is_valid = 0; + } +} +/*-----------------------------------------------------------*/ + +void aws_mbedtls_mutex_free( mbedtls_threading_mutex_t * mutex ) +{ + if( mutex->is_valid == 1 ) + { + vSemaphoreDelete( mutex->mutex ); + mutex->is_valid = 0; + } +} +/*-----------------------------------------------------------*/ + +int aws_mbedtls_mutex_lock( mbedtls_threading_mutex_t * mutex ) +{ + int ret = MBEDTLS_ERR_THREADING_BAD_INPUT_DATA; + + if( mutex->is_valid == 1 ) + { + if( xSemaphoreTake( mutex->mutex, portMAX_DELAY ) ) + { + ret = 0; + } + else + { + ret = MBEDTLS_ERR_THREADING_MUTEX_ERROR; + } + } + + return ret; +} +/*-----------------------------------------------------------*/ + +int aws_mbedtls_mutex_unlock( mbedtls_threading_mutex_t * mutex ) +{ + int ret = MBEDTLS_ERR_THREADING_BAD_INPUT_DATA; + + if( mutex->is_valid == 1 ) + { + if( xSemaphoreGive( mutex->mutex ) ) + { + ret = 0; + } + else + { + ret = MBEDTLS_ERR_THREADING_MUTEX_ERROR; + } + } + + return ret; +} +/*-----------------------------------------------------------*/ + diff --git a/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/demo_helpers.h b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/demo_helpers.h new file mode 100644 index 0000000000..648b166964 --- /dev/null +++ b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/demo_helpers.h @@ -0,0 +1,103 @@ +/* + * FreeRTOS PKCS #11 V1.0.3 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://aws.amazon.com/freertos + * http://www.FreeRTOS.org + */ +#ifndef _DEMO_HELPER_FUNCTIONS_ +#define _DEMO_HELPER_FUNCTIONS_ + +#include "iot_pkcs11.h" +#include "threading_alt.h" +#include "mbedtls/pk.h" + +/* This function contains standard setup code for PKCS #11. See the + * "management_and_rng.c" file for the demo code explaining this section + * of cryptoki. + */ +void vStart( CK_SESSION_HANDLE * pxSession, + CK_SLOT_ID ** ppxSlotId ); +/*-----------------------------------------------------------*/ + +/* This function contains standard tear down code for PKCS #11. See the + * "management_and_rng.c" file for the demo code explaining this section + * of cryptoki. + */ +void vEnd( CK_SESSION_HANDLE xSession, + CK_SLOT_ID * pxSlotId ); +/*-----------------------------------------------------------*/ + +/* This function is simply a helper function to print the raw hex values + * of an EC public key. It's explanation is not within the scope of the demos + * and is sparsely commented. */ +void vWriteHexBytesToConsole( char * pcDescription, + CK_BYTE * pucData, + CK_ULONG ulDataLength ); +/*-----------------------------------------------------------*/ + +/* This function is simply a helper function to export the raw hex values + * of an EC public key into a buffer. It's explanation is not within the + * scope of the demos and is sparsely commented. */ +CK_RV vExportPublicKey( CK_SESSION_HANDLE xSession, + CK_OBJECT_HANDLE xPublicKeyHandle, + CK_BYTE ** ppucDerPublicKey, + CK_ULONG * pulDerPublicKeyLength ); +/*-----------------------------------------------------------*/ + +/** + * @brief Implements libc calloc semantics using the FreeRTOS heap + */ +void * pvCalloc( size_t xNumElements, + size_t xSize ); +/*-----------------------------------------------------------*/ + +/** + * @brief Implementation of mbedtls_mutex_init for thread-safety. + * + */ +void aws_mbedtls_mutex_init( mbedtls_threading_mutex_t * mutex ); +/*-----------------------------------------------------------*/ + +/** + * @brief Implementation of mbedtls_mutex_free for thread-safety. + * + */ +void aws_mbedtls_mutex_free( mbedtls_threading_mutex_t * mutex ); +/*-----------------------------------------------------------*/ + +/** + * @brief Implementation of mbedtls_mutex_lock for thread-safety. + * + * @return 0 if successful, MBEDTLS_ERR_THREADING_MUTEX_ERROR if timeout, + * MBEDTLS_ERR_THREADING_BAD_INPUT_DATA if the mutex is not valid. + */ +int aws_mbedtls_mutex_lock( mbedtls_threading_mutex_t * mutex ); +/*-----------------------------------------------------------*/ + +/** + * @brief Implementation of mbedtls_mutex_unlock for thread-safety. + * + * @return 0 if successful, MBEDTLS_ERR_THREADING_MUTEX_ERROR if timeout, + * MBEDTLS_ERR_THREADING_BAD_INPUT_DATA if the mutex is not valid. + */ +int aws_mbedtls_mutex_unlock( mbedtls_threading_mutex_t * mutex ); + +#endif /* _DEMO_HELPER_FUNCTIONS_ */ diff --git a/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/management_and_rng.c b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/management_and_rng.c new file mode 100644 index 0000000000..a4ed1c0bda --- /dev/null +++ b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/management_and_rng.c @@ -0,0 +1,219 @@ +/* + * FreeRTOS PKCS #11 V1.0.3 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://aws.amazon.com/freertos + * http://www.FreeRTOS.org + */ +/* FreeRTOS includes. */ +#include "FreeRTOS.h" +#include "task.h" + +/* Standard includes. */ +#include "stdio.h" + +/* PKCS #11 includes. */ +#include "iot_pkcs11_config.h" +#include "iot_pkcs11.h" +#include "pkcs11.h" + +/* Demo include. */ +#include "pkcs11_demos.h" + +/** + * This function details how to use the PKCS #11 "Management" functions to + * manage the internal state machine of the PKCS #11 implementation. These + * functions are all defined in + * http://docs.oasis-open.org/pkcs11/pkcs11-base/v2.40/os/pkcs11-base-v2.40-os.html + * please consult the standard for more information regarding these functions. + * + * The standard has grouped the functions presented in this demo as: + * General Purpose Functions + * Slot and Token Management Functions + * Session Management Functions + * Random Number Generation Functions + */ +void vPKCS11ManagementAndRNGDemo( void ) +{ + /* We will use the terminology as defined in the standard, Cryptoki is in + * reference to the Cryptographic Token Interface defined in the PKCS #11 + * standard. An implementation of Cryptoki is referred to as a + * "Cryptoki library". */ + configPRINTF( ( "\r\nStarting PKCS #11 Management and Random Number Generation" \ + " Demo.\r\n" ) ); + + /* CK_RV is the return type for a Cryptoki function. Generally the underlying + * type is a CK_ULONG, it can also be a CKR_VENDOR_DEFINED type. */ + CK_RV xResult = CKR_OK; + + /* The CK_FUNCTION_LIST is a structure that contains the Cryptoki version + * and a function pointer to each function in the Cryptoki API. If the + * function pointer is NULL it is unimplemented. */ + CK_FUNCTION_LIST_PTR pxFunctionList = NULL; + + /* This Cryptoki library does not implement any initialization arguments. At the time of + * writing this demo, the purpose of these optional arguments is to provide + * function pointers for mutex operations. */ + CK_C_INITIALIZE_ARGS xInitArgs = { 0 }; + + /* A slot ID is an integer that defines a slot. The Cryptoki definition of + * a slot is "A logical reader that potentially contains a token." + * + * Essentially it is an abstraction for accessing the token. The reason for + * this is Some tokens are a physical "card' that needs to be inserted into + * a slot for the device to read. + * + * A concrete example of a slot could be a USB Hardware Security Module (HSM), + * which generally appears as a singular slot, and abstracts it's internal "token". + * + * Some implementations have multiple slots mapped to a single token, or maps + * a slot per token. */ + CK_SLOT_ID * pxSlotId = NULL; + + /* A session is defined to be "The logical connection between an application + * and a token." + * + * The session can either be private or public, and differentiates + * your application from the other users of the token. */ + CK_SESSION_HANDLE hSession = CK_INVALID_HANDLE; + + /* Helper variables. */ + CK_BYTE xRandomData[ 10 ] = { 0 }; + uint32_t ulIndex = 0; + CK_ULONG xSlotCount = 0; + + /* We use the function list returned by C_GetFunctionList to see what functions + * the Cryptoki library supports. We use asserts to ensure that all the + * functionality needed in this demo is available. */ + xResult = C_GetFunctionList( &pxFunctionList ); + configASSERT( xResult == CKR_OK ); + configASSERT( pxFunctionList != NULL ); + configASSERT( pxFunctionList->C_Initialize != NULL ); + configASSERT( pxFunctionList->C_GetSlotList != NULL ); + configASSERT( pxFunctionList->C_OpenSession != NULL ); + configASSERT( pxFunctionList->C_Login != NULL ); + configASSERT( pxFunctionList->C_GenerateRandom != NULL ); + configASSERT( pxFunctionList->C_CloseSession != NULL ); + configASSERT( pxFunctionList->C_Finalize != NULL ); + + configPRINTF( ( "Cryptoki Major Version: %lu Minor Version %lu\r\n", + pxFunctionList->version.major, + pxFunctionList->version.minor ) ); + + /* C_Initialize will initialize the Cryptoki library and the hardware it + * abstracts. */ + xResult = pxFunctionList->C_Initialize( &xInitArgs ); + configASSERT( xResult == CKR_OK ); + + /* C_GetSlotList will retrieve an array of CK_SLOT_IDs. + * This Cryptoki library does not implement slots, but it is important to + * highlight how Cryptoki can be used to interface with real hardware. + * + * By setting the first argument "tokenPresent" to true, we only retrieve + * slots that have a token. If the second argument "pSlotList" is NULL, the + * third argument "pulCount" will be modified to contain the total slots. */ + xResult = pxFunctionList->C_GetSlotList( CK_TRUE, + NULL, + &xSlotCount ); + configASSERT( xResult == CKR_OK ); + + /* Since C_GetSlotList does not allocate the memory itself for getting a list + * of CK_SLOT_ID, we allocate one for it to populate with the list of + * slot ids. */ + pxSlotId = pvPortMalloc( sizeof( CK_SLOT_ID ) * ( xSlotCount ) ); + configASSERT( pxSlotId != NULL ); + + /* Now since pSlotList is not NULL, C_GetSlotList will populate it with the + * available slots. */ + xResult = pxFunctionList->C_GetSlotList( CK_TRUE, + pxSlotId, + &xSlotCount ); + configASSERT( xResult == CKR_OK ); + + /* Since this Cryptoki library does not actually implement the concept of slots, + * but we will use the first available slot, so the demo code conforms to + * Cryptoki. + * + * C_OpenSession will establish a session between the application and + * the token and we can then use the returned CK_SESSION_HANDLE for + * cryptographic operations with the token. + * + * For legacy reasons, Cryptoki demands that the CKF_SERIAL_SESSION bit + * is always set. */ + xResult = pxFunctionList->C_OpenSession( pxSlotId[0], + CKF_SERIAL_SESSION | CKF_RW_SESSION, + NULL, /* Application defined pointer. */ + NULL, /* Callback function. */ + &hSession ); + configASSERT( xResult == CKR_OK ); + + + /* C_Login is called to log the user in to the token. The login status is + * shared between sessions, so logging in once is sufficient for all the sessions + * tied to the token. Most of the behavior for C_Login is defined by the token + * so it may be necessary to modify calls to C_Login when switching to a different + * Cryptoki library or token. + * + * This Cryptoki library does not implement C_Login, and only defines the function + * for compatibility reasons. + */ + xResult = pxFunctionList->C_Login( hSession, + CKU_USER, + ( CK_UTF8CHAR_PTR ) configPKCS11_DEFAULT_USER_PIN, + sizeof( configPKCS11_DEFAULT_USER_PIN ) - 1UL ); + configASSERT( xResult == CKR_OK ); + + /* C_GenerateRandom generates random or pseudo random data. As arguments it + * takes the application session, and a pointer to a byte buffer, as well as + * the length of the byte buffer. Then it will fill this buffer with random + * bytes. */ + xResult = pxFunctionList->C_GenerateRandom( hSession, + xRandomData, + sizeof( xRandomData ) ); + configASSERT( xResult == CKR_OK ); + + for( ulIndex = 0; ulIndex < sizeof( xRandomData ); ulIndex++ ) + { + configPRINTF( ( "Generated random number: %x\r\n", xRandomData[ ulIndex ] ) ); + } + + + /* C_CloseSession closes the session that was established between the + * application and the token. This will clean up the resources that maintained + * the link between the application and the token. If the application wishes + * to use the token again, it will need to open a new session. */ + xResult = pxFunctionList->C_CloseSession( hSession ); + configASSERT( xResult == CKR_OK ); + + /* C_Finalize signals to the Cryptoki library that the application is done + * using it. It should always be the last call to the Cryptoki library. + * NULL should always be passed as the argument, as the parameter is currently + * just reserved for future revisions. + * + * Calling this function in a multi threaded environment can lead to undefined + * behavior if other threads are accessing the Cryptoki library. */ + xResult = pxFunctionList->C_Finalize( NULL ); + configASSERT( xResult == CKR_OK ); + + configPRINTF( ( "Finished PKCS #11 Management and Random Number Generation" \ + " Demo.\r\n" ) ); + + vPortFree( pxSlotId ); +} diff --git a/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/mechanisms_and_digests.c b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/mechanisms_and_digests.c new file mode 100644 index 0000000000..64325f8828 --- /dev/null +++ b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/mechanisms_and_digests.c @@ -0,0 +1,258 @@ +/* + * FreeRTOS PKCS #11 V1.0.3 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://aws.amazon.com/freertos + * http://www.FreeRTOS.org + */ +/* FreeRTOS includes. */ +#include "FreeRTOS.h" +#include "task.h" + +/* Standard includes. */ +#include "stdio.h" + +/* PKCS #11 includes. */ +#include "iot_pkcs11_config.h" +#include "iot_pkcs11.h" +#include "pkcs11.h" + +/* Demo includes. */ +#include "demo_helpers.h" +#include "pkcs11_demos.h" + +/** + * This function details what Cryptoki mechanisms are, how to query a slot's + * support for them, and how to use those mechanisms to generate a hash of a buffer. + * This can then be used as a message digest. + * + * http://docs.oasis-open.org/pkcs11/pkcs11-base/v2.40/os/pkcs11-base-v2.40-os.html + * please consult the standard for more information. + * + * The standard has grouped the functions presented in this demo as: + * Slot and token management functions. + * Message digesting functions. + * + */ +void vPKCS11MechanismsAndDigestDemo( void ) +{ + /* + * This demo builds upon the demo found in "management_and_rng.c". It borrows + * code and terminology defined and explained, and it is recommended to complete + * the "management and rng" demo before this one. + */ + configPRINTF( ( "\r\nStarting PKCS #11 Mechanisms and Digest Demo.\r\n" ) ); + + CK_SESSION_HANDLE hSession = CK_INVALID_HANDLE; + CK_SLOT_ID * pxSlotId = 0; + CK_FUNCTION_LIST_PTR pxFunctionList = NULL; + CK_ULONG ulIndex = 0; + CK_RV xResult = CKR_OK; + + /* The PKCS #11 standard defines a mechanism to be a "A process for + * implementing a cryptographic operation." For example the SHA-256 algorithm + * will be the mechanism used in this demo to perform a digest (hash operation). + * + * The mechanism types are defined in "pkcs11t.h", and are prefixed CKM_, to + * provide a portable way to identify mechanisms. + */ + CK_MECHANISM_TYPE xMechanismType = 0; + + /* This variable is not directly used, but is instantiated for demonstration + * purposes. + */ + ( void ) xMechanismType; + + /* The CK_MECHANISM_INFO allows the application to retrieve the minimum and + * maximum key sizes supported by the mechanism (could be in bits or bytes). + * The structure also has a flags field, that is populated with bit flags + * for what features the mechanism supports. + */ + CK_MECHANISM_INFO MechanismInfo = { 0 }; + + /* The CK_MECHANISM type contains the mechanism type, as well as a pointer + * for mechanism parameters and a CK_ULONG indicating the length of the + * parameters. + */ + CK_MECHANISM xDigestMechanism = { 0 }; + + /* The digest will return a hash of the known SHA-256 hash size, 32 bytes. + * Please see this page for further explanation of the SHA-256 hash. + * https://en.wikipedia.org/wiki/SHA-2 + */ + CK_BYTE xDigestResult[ pkcs11SHA256_DIGEST_LENGTH ] = { 0 }; + CK_ULONG ulDigestLength = pkcs11SHA256_DIGEST_LENGTH; + + CK_BYTE pxKnownMessage[] = "Hello world!"; + + vStart( &hSession, &pxSlotId ); + xResult = C_GetFunctionList( &pxFunctionList ); + configASSERT( CKR_OK == xResult ); + configASSERT( pxFunctionList->C_GetMechanismInfo != NULL ); + configASSERT( pxFunctionList->C_DigestInit != NULL ); + configASSERT( pxFunctionList->C_DigestUpdate != NULL ); + configASSERT( pxFunctionList->C_DigestFinal != NULL ); + + /*************************** RSA Capabilities ***************************/ + xResult = pxFunctionList->C_GetMechanismInfo( pxSlotId[ 0 ], + CKM_RSA_PKCS, + &MechanismInfo ); + configASSERT( CKR_OK == xResult ); + + /* Check to see if the slot supports signing. This capability is important + * because we want to use the Cryptoki API to sign messages, without directly + * accessing the private key. This concept will be explained further in the + * "sign_verify.c" demo, but for now we will just check that the slot has the + * capabilities we need. See https://en.wikipedia.org/wiki/Public-key_cryptography + * for more information regarding private keys and public keys. + */ + if( 0 != ( CKF_SIGN & MechanismInfo.flags ) ) + { + configPRINTF( ( "This Cryptoki library supports signing messages with RSA" \ + " private keys.\r\n" ) ); + } + else + { + configPRINTF( ( "This Cryptoki library does not support signing messages" \ + " with RSA private keys.\r\n" ) ); + } + + /* This Cryptoki library assumes that RSA private keys are 2048 bit . */ + configASSERT( MechanismInfo.ulMaxKeySize >= pkcs11RSA_2048_MODULUS_BITS ); + configASSERT( MechanismInfo.ulMinKeySize <= pkcs11RSA_2048_MODULUS_BITS ); + + /* Check for pre-padded signature verification support, this feature will + * be used in the "sign_verify.c" demo. + */ + xResult = pxFunctionList->C_GetMechanismInfo( pxSlotId[ 0 ], + CKM_RSA_X_509, + &MechanismInfo ); + + /* If this fails, the slot is not able to verify the signature using + * a RSA public key. Please see https://en.wikipedia.org/wiki/Public_key_infrastructure + * for more information regarding PKI (Public Key Infrastructure). + */ + if( 0 != ( CKF_VERIFY & MechanismInfo.flags ) ) + { + configPRINTF( ( "This Cryptoki library supports verifying messages with RSA" \ + " public keys.\r\n" ) ); + } + else + { + configPRINTF( ( "This Cryptoki library does not support verifying messages" \ + " with RSA public keys.\r\n" ) ); + } + + /* This Cryptoki library assumes that RSA public keys are 2048 bit . */ + configASSERT( MechanismInfo.ulMaxKeySize >= pkcs11RSA_2048_MODULUS_BITS ); + configASSERT( MechanismInfo.ulMinKeySize <= pkcs11RSA_2048_MODULUS_BITS ); + + /*************************** ECDSA Capabilities ***************************/ + xResult = pxFunctionList->C_GetMechanismInfo( pxSlotId[ 0 ], + CKM_ECDSA, + &MechanismInfo ); + configASSERT( CKR_OK == xResult ); + + if( 0 != ( CKF_SIGN & MechanismInfo.flags ) ) + { + configPRINTF( ( "This Cryptoki library supports signing messages with" \ + " ECDSA private keys.\r\n" ) ); + } + else + { + configPRINTF( ( "This Cryptoki library does not support signing messages" \ + " with ECDSA private keys.\r\n" ) ); + } + + if( 0 != ( CKF_VERIFY & MechanismInfo.flags ) ) + { + configPRINTF( ( "This Cryptoki library supports verifying messages with" \ + " ECDSA public keys.\r\n" ) ); + } + else + { + configPRINTF( ( "This Cryptoki library does not support verifying" \ + " messages with ECDSA public keys.\r\n" ) ); + } + + configASSERT( MechanismInfo.ulMaxKeySize >= pkcs11ECDSA_P256_KEY_BITS ); + configASSERT( MechanismInfo.ulMinKeySize <= pkcs11ECDSA_P256_KEY_BITS ); + + /************************** Digest Capabilities **************************/ + xResult = pxFunctionList->C_GetMechanismInfo( pxSlotId[ 0 ], + CKM_SHA256, + &MechanismInfo ); + configASSERT( CKR_OK == xResult ); + + if( 0 != ( CKF_DIGEST & MechanismInfo.flags ) ) + { + configPRINTF( ( "The Cryptoki library supports the " \ + "SHA-256 algorithm.\r\n" ) ); + } + else + { + configPRINTF( ( "The Cryptoki library doesn't support the " \ + "SHA-256 algorithm.\r\n" ) ); + } + + /***************************** Buffer Digest *****************************/ + /* Hash with SHA256 mechanism. */ + xDigestMechanism.mechanism = CKM_SHA256; + + /* Initializes the digest operation and sets what mechanism will be used + * for the digest. */ + xResult = pxFunctionList->C_DigestInit( hSession, + &xDigestMechanism ); + configASSERT( CKR_OK == xResult ); + + + /* Pass a pointer to the buffer of bytes to be hashed, and it's size. */ + xResult = pxFunctionList->C_DigestUpdate( hSession, + pxKnownMessage, + /* Strip NULL Terminator. */ + sizeof( pxKnownMessage ) - 1 ); + configASSERT( CKR_OK == xResult ); + + /* Retrieve the digest buffer. Since the mechanism is a SHA-256 algorithm, + * the size will always be 32 bytes. If the size cannot be known ahead of time, + * a NULL value to the second parameter pDigest, will set the third parameter, + * pulDigestLen to the number of required bytes. */ + xResult = pxFunctionList->C_DigestFinal( hSession, + xDigestResult, + &ulDigestLength ); + configASSERT( CKR_OK == xResult ); + + /* This will now print out the digest of the known message. You can compare + * the hash generated by the Cryptoki library in a UNIX shell by using the + * command '$ echo -n "{pxKnownMessage}" | shasum -a 256' + * this command should generate the same hash. */ + configPRINTF( ( "Known message: %s\r\n", ( char * ) pxKnownMessage ) ); + configPRINTF( ( "Hash of known message using SHA256:\r\n" ) ); + + for( ulIndex = 0; ulIndex < ulDigestLength; ulIndex++ ) + { + configPRINTF( ( "%x", xDigestResult[ ulIndex ] ) ); + } + configPRINTF( ( "\r\n" ) ); + + configPRINTF( ( "Finished PKCS #11 Mechanisms and Digest Demo.\r\n" ) ); + vEnd( hSession, pxSlotId ); +} + diff --git a/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/objects.c b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/objects.c new file mode 100644 index 0000000000..9d649f281f --- /dev/null +++ b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/objects.c @@ -0,0 +1,393 @@ +/* + * FreeRTOS PKCS #11 V1.0.3 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://aws.amazon.com/freertos + * http://www.FreeRTOS.org + */ +/* FreeRTOS includes. */ +#include "FreeRTOS.h" +#include "task.h" + +/* Standard include. */ +#include "stdio.h" + +/* PKCS #11 includes. */ +#include "iot_pkcs11_config.h" +#include "iot_pkcs11.h" +#include "pkcs11.h" + +/* mbed TLS includes. */ +#include "mbedtls/pk.h" + +/* Demo includes. */ +#include "demo_helpers.h" +#include "pkcs11_demos.h" + +/* RSA certificate that has been generated off the device. + * This key will be used as an example for importing an object onto the device. + * This is useful when the device itself cannot create credentials or for storing + * a well known CA certificate. + */ +#define pkcs11demo_RSA_CERTIFICATE \ + "" \ + "-----BEGIN CERTIFICATE-----\n" \ + "MIIFgTCCA2mgAwIBAgIUPsOLvI1VI8EtdIZi1s2vp7sGhy8wDQYJKoZIhvcNAQEL\n" \ + "BQAwTzELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAldBMRAwDgYDVQQHDAdTZWF0dGxl\n" \ + "MSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwIBcNMjAwNzEzMTY0\n" \ + "MDUyWhgPMjEyMDA2MTkxNjQwNTJaME8xCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJX\n" \ + "QTEQMA4GA1UEBwwHU2VhdHRsZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQ\n" \ + "dHkgTHRkMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAtSrIA3Esgjtf\n" \ + "5Ltk/zMaUIbdX8F3VJKyQ9L3Bu07BDNVYmSqPg7+TNvUSrVT7npYmF7TE+jKJXvW\n" \ + "Lf9UUQZUb5KFf6cKkUKoZlXY3Jn3oInD9md7Yyry1z7eTrBz20UnUaTx28lqq2T8\n" \ + "SzwAthMyjhHmXeFXTD+KKY7j9H73kgOH4EUme3Nrxp+z/yaSQN5Naeqp1/HBGayY\n" \ + "TqFOgDlv2NXdrvKPlvBeEpWa6WoRnq7iC3jCuafO4ZUueu4hdt9tfQLXtKixLKhu\n" \ + "Tjw1w7iKi88KjQhGz7gCDxCGQxWm22HgXdNEBHUctN+lUpYyMQy/dafHvUgug2YJ\n" \ + "aRwN+QBL7GH6N75Mfh9t3dFTERxa1tphNeiVeqlb5/D2yY0JaqqIBUxpSsgpn/a1\n" \ + "orR+XgAtMaHL0I+xwE1gdhYOWAhfcGo6vTD45b9fgERoeUC5KOUiZ2xABUV278lF\n" \ + "QJ7uPwwhV+fjpwwZcum3viFnk5SUBtENhm9QGoH0KW8K43doPc7yeeaY4gxXdV1g\n" \ + "im2uQ07Vk9bIm/HDYpW+tRQX7BM7o4BhqL7FbnKgfN2YcyMds+16YfugaaNJy53I\n" \ + "O4640KT9NrpmJ0el+rmwb+2Ut9Ie+V7ja40V0M0hBToDWXjoIY2i9nf6rIXws76J\n" \ + "A3jIMNTDLhoCT0cMcSs8zB9mqxNlbqkCAwEAAaNTMFEwHQYDVR0OBBYEFFPkZ81v\n" \ + "G9lKvZv9XvKOOF0nwu8fMB8GA1UdIwQYMBaAFFPkZ81vG9lKvZv9XvKOOF0nwu8f\n" \ + "MA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggIBACjoiRIwP+mIggZ/\n" \ + "PEBGqR+siV4TDDTVgUBeanLilkfKYeNEo4tapRy1Jvm2Kd/T26O2X2fTCVGG5Hpf\n" \ + "KUYC9RLq7gPEytLUIlfwn0jp3uY3DotKQD03GWZ5nc0FJyhMoMH72MdoculbQ4UL\n" \ + "x4CCrCvnGodXm0oXa6cEl4Do8MadU7fgRF1Bj05FD7LfDUgBGJp8pZbKiPIKLzAx\n" \ + "UlMQen5PHJOke4+y2O/mL2iQshat7a5MOwJgPp1Wkn0q5kLO9AGVXbq3DD40jLrh\n" \ + "b9EDVsWTa1Xu3RQV4zqHFsm3OGliwJbtO1BA6P7QFBRGMMos4xZQWjxJXbr1m+uf\n" \ + "1y/X5icXdwWQ/f9h0ovjWeqOZBW8hfW6CRD1ehJpBB2YCwTjK7Fn5p4PH0PJUWf5\n" \ + "rPuShvCAUy73QC/Iud4xwNQf6D9MWzOcDWvh7NPGhCHFmz4swKlN8oglMD1JaE4U\n" \ + "97LLfATEYy5ajjlWoJ8qF/in8jzsYxq9OZ2/ObchZsU9ybzLRuE1Cv7v4Mx1sgH3\n" \ + "EoWYZK1j3WytKmbaWYDR6INYklT/d+14OyIflUfBGiSXNKMITWVRZYjTHKUeAPdb\n" \ + "1bsyMu+g4y1PVOrp/d9AyZTZrDW81zuYpO5Ah0DgF4EYiz2fWnz2ITVUmq35znIQ\n" \ + "xg07nhvDeydwB48xXrPQ1KutrRyh\n" \ + "-----END CERTIFICATE-----" + +/* This function can be found in + * FreeRTOS/FreeRTOS-Plus/Source/FreeRTOS-Plus-PKCS11/3rdparty/mbedtls_utils/mbedtls_utils.c. + * It will be used to convert the RSA certificate from PEM format + * to DER format. */ +extern int convert_pem_to_der( const unsigned char * pucInput, + size_t xLen, + unsigned char * pucOutput, + size_t * pxOlen ); +/*-----------------------------------------------------------*/ + + +/** + * prvObjectImporting covers how to import a RSA certificate that was + * not generated by the Cryptoki library. + * + */ +static void prvObjectImporting( void ); + +/** + * prvObjectGeneration covers how to create a public key and private key pair + * with Cryptoki defined attributes using C_GenerateKeyPair. + * + * Note: The "sign-verify.c" demo has a dependency on the objects created + * in this function, and will not work without first running this function. + */ +static void prvObjectGeneration( void ); + + +/** + * This function details how to use the PKCS #11 "Object" functions to + * manage the objects abstracted by cryptoki. + * + * http://docs.oasis-open.org/pkcs11/pkcs11-base/v2.40/os/pkcs11-base-v2.40-os.html + * please consult the standard for more information. + * + * The standard has grouped the functions presented in this demo as: + * Object Management Functions. + * + */ +void vPKCS11ObjectDemo( void ) +{ + configPRINTF( ( "\r\nStarting PKCS #11 Objects Demo.\r\n" ) ); + + /* PKCS #11 defines objects as "An item that is stored on a token. May be + * data, a certificate, or a key." This demo will show how to create objects + * that are managed by Cryptoki. */ + prvObjectImporting(); + prvObjectGeneration(); + configPRINTF( ( "\r\nFinished PKCS #11 Objects Demo.\r\n" ) ); +} + +static void prvObjectImporting( void ) +{ + configPRINTF( ( "---------Importing Objects---------\r\n" ) ); + configPRINTF( ( "Importing RSA Certificate...\r\n" ) ); + + /* Helper variables and variables that have been covered. */ + CK_RV xResult = CKR_OK; + CK_SESSION_HANDLE hSession = CK_INVALID_HANDLE; + CK_SLOT_ID * pxSlotId = 0; + CK_FUNCTION_LIST_PTR pxFunctionList = NULL; + uint8_t * pucDerObject = NULL; + int32_t lConversionReturn = 0; + size_t xDerLen = 0; + CK_BBOOL xTokenStorage = CK_TRUE; + CK_OBJECT_HANDLE xCertHandle = CK_INVALID_HANDLE; + CK_BYTE xSubject[] = "TestSubject"; + + + /* The PKCS11_CertificateTemplate_t is a custom struct defined in "iot_pkcs11.h" + * in order to make it easier to import a certificate. This struct will be + * populated with the parameters necessary to import the certificate into the + * Cryptoki library. + */ + PKCS11_CertificateTemplate_t xCertificateTemplate; + + /* The object class is specified as a certificate to help the Cryptoki library + * parse the arguments. + */ + CK_OBJECT_CLASS xCertificateClass = CKO_CERTIFICATE; + + /* The certificate type is an x509 certificate, which is the only type + * supported by this stack. To read more about x509 certificates one can + * read the following: + * + * https://en.wikipedia.org/wiki/X.509 + * https://www.ssl.com/faqs/what-is-an-x-509-certificate/ + * + */ + CK_CERTIFICATE_TYPE xCertificateType = CKC_X_509; + + /* The label will help the application identify which object it would like + * to access. + */ + CK_BYTE pucLabel[] = pkcs11configLABEL_DEVICE_CERTIFICATE_FOR_TLS; + + /* Specify certificate class. */ + xCertificateTemplate.xObjectClass.type = CKA_CLASS; + xCertificateTemplate.xObjectClass.pValue = &xCertificateClass; + xCertificateTemplate.xObjectClass.ulValueLen = sizeof( xCertificateClass ); + + /* Specify certificate subject. */ + xCertificateTemplate.xSubject.type = CKA_SUBJECT; + xCertificateTemplate.xSubject.pValue = xSubject; + xCertificateTemplate.xSubject.ulValueLen = strlen( ( const char * ) xSubject ); + + /* Point to contents of certificate. */ + xCertificateTemplate.xValue.type = CKA_VALUE; + xCertificateTemplate.xValue.pValue = ( CK_VOID_PTR ) pkcs11demo_RSA_CERTIFICATE; + xCertificateTemplate.xValue.ulValueLen = ( CK_ULONG ) sizeof( pkcs11demo_RSA_CERTIFICATE ); + + /* Specify certificate label. */ + xCertificateTemplate.xLabel.type = CKA_LABEL; + xCertificateTemplate.xLabel.pValue = ( CK_VOID_PTR ) pucLabel; + xCertificateTemplate.xLabel.ulValueLen = strlen( ( const char * ) pucLabel ); + + /* Specify certificate type as x509. */ + xCertificateTemplate.xCertificateType.type = CKA_CERTIFICATE_TYPE; + xCertificateTemplate.xCertificateType.pValue = &xCertificateType; + xCertificateTemplate.xCertificateType.ulValueLen = sizeof( CK_CERTIFICATE_TYPE ); + + /* Specify that the certificate should be on a token. */ + xCertificateTemplate.xTokenObject.type = CKA_TOKEN; + xCertificateTemplate.xTokenObject.pValue = &xTokenStorage; + xCertificateTemplate.xTokenObject.ulValueLen = sizeof( xTokenStorage ); + + vStart( &hSession, &pxSlotId ); + + /* Ensure the Cryptoki library has the necessary functions implemented. */ + xResult = C_GetFunctionList( &pxFunctionList ); + configASSERT( xResult == CKR_OK ); + configASSERT( pxFunctionList->C_CreateObject != NULL ); + + /* Convert the certificate to DER format if it was in PEM. The DER key + * should be about 3/4 the size of the PEM key, so mallocing the PEM key + * size is sufficient. */ + pucDerObject = pvPortMalloc( xCertificateTemplate.xValue.ulValueLen ); + configASSERT( pucDerObject != NULL ); + + xDerLen = xCertificateTemplate.xValue.ulValueLen; + lConversionReturn = convert_pem_to_der( xCertificateTemplate.xValue.pValue, + xCertificateTemplate.xValue.ulValueLen, + pucDerObject, + &xDerLen ); + + configASSERT( 0 == lConversionReturn ); + + /* Set the template pointers to refer to the DER converted objects. */ + xCertificateTemplate.xValue.pValue = pucDerObject; + xCertificateTemplate.xValue.ulValueLen = xDerLen; + + /* Create an object using the encoded client certificate. */ + configPRINTF( ( "Creating x509 certificate with label: %s \r\n", + pkcs11configLABEL_DEVICE_CERTIFICATE_FOR_TLS ) ); + + /* Once the Cryptoki library has finished importing the new x509 certificate + * a CK_OBJECT_HANDLE is associated with it. The application can now use this + * to refer to the object in following operations. + * + * xCertHandle in the below example will have it's value modified to + * be the CK_OBJECT_HANDLE. + * + * Compare the hard coded x509, in PEM format, with the DER formatted + * x509 certificate that is created by the Cryptoki library, with the following + * OpenSSL command: + * "$ openssl x509 -in FreeRTOS_P11_Certificate.dat -inform der -text" + * + * See this explanation for the difference between the PEM format and the + * DER format: + * https://stackoverflow.com/questions/22743415/what-are-the-differences-between-pem-cer-and-der/22743616 + * + */ + xResult = pxFunctionList->C_CreateObject( hSession, + ( CK_ATTRIBUTE_PTR ) &xCertificateTemplate, + sizeof( xCertificateTemplate ) / sizeof( CK_ATTRIBUTE ), + &xCertHandle ); + + configASSERT( xResult == CKR_OK ); + configASSERT( xCertHandle != CK_INVALID_HANDLE ); + + configPRINTF( ( "FreeRTOS_P11_Certificate.dat has been created in the Visual Studio" \ + " Solution directory\r\n" ) ); + + vPortFree( pucDerObject ); + vEnd( hSession, pxSlotId ); + configPRINTF( ( "Finished Importing RSA Certificate.\r\n" ) ); + configPRINTF( ( "---------Finished Importing Objects---------\r\n" ) ); +} + +static void prvObjectGeneration( void ) +{ + configPRINTF( ( "---------Generating Objects---------\r\n" ) ); + + /* Helper variables. */ + CK_RV xResult = CKR_OK; + CK_SESSION_HANDLE hSession = CK_INVALID_HANDLE; + CK_SLOT_ID * pxSlotId = 0; + CK_FUNCTION_LIST_PTR pxFunctionList = NULL; + CK_BYTE * pxDerPublicKey = NULL; + CK_ULONG ulDerPublicKeyLength = 0; + CK_BBOOL xTrue = CK_TRUE; + + /* Specify the mechanism to use in the key pair generation. Mechanisms are + * previously explained in the "mechanims_and_digests.c" demo. */ + CK_MECHANISM xMechanism = + { + CKM_EC_KEY_PAIR_GEN, NULL_PTR, 0 + }; + + /* The EC curve used in this demo will be the named EC curve prime256v1. + * For further explanations of EC Cryptography please see the following: + * https://en.wikipedia.org/wiki/Elliptic-curve_cryptography + * https://wiki.openssl.org/index.php/Elliptic_Curve_Cryptography + */ + CK_BYTE xEcParams[] = pkcs11DER_ENCODED_OID_P256; + + /* Specify the key type to be EC. */ + CK_KEY_TYPE xKeyType = CKK_EC; + + /* Object handles are a token specific identifier for an object. They are + * used so the application's sessions can specify which object to interact + * with. Non-zero values are valid, 0 is always invalid, and is defined as + * CK_INVALID_HANDLE + * + * The lifetime of the handle is not necessarily the same as the lifetime of + * the object. + */ + CK_OBJECT_HANDLE xPrivateKeyHandle = CK_INVALID_HANDLE; + CK_OBJECT_HANDLE xPublicKeyHandle = CK_INVALID_HANDLE; + + + /* Labels are application defined strings that are used to identify an + * object. It should not be NULL terminated. */ + CK_BYTE pucPublicKeyLabel[] = { pkcs11configLABEL_DEVICE_PRIVATE_KEY_FOR_TLS }; + CK_BYTE pucPrivateKeyLabel[] = { pkcs11configLABEL_DEVICE_PUBLIC_KEY_FOR_TLS }; + + /* CK_ATTTRIBUTE's contain an attribute type, a value, and the length of + * the value. An array of CK_ATTRIBUTEs is called a template. They are used + * for creating, searching, and manipulating for objects. The order of the + * template does not matter. + * + * In the below template we are creating a public key: + * Specify the key type as EC. + * The key will be able to verify a message. + * Specify the EC Curve. + * Assign a label to the object that will be created. + */ + CK_ATTRIBUTE xPublicKeyTemplate[] = + { + { CKA_KEY_TYPE, &xKeyType, sizeof( xKeyType ) }, + { CKA_VERIFY, &xTrue, sizeof( xTrue ) }, + { CKA_EC_PARAMS, xEcParams, sizeof( xEcParams ) }, + { CKA_LABEL, pucPublicKeyLabel, sizeof( pucPublicKeyLabel ) - 1 } + }; + + /* In the below template we are creating a private key: + * The key type is EC. + * The key is a token object. + * The key will be a private key. + * The key will be able to sign messages. + * Assign a label to the object that will be created. + */ + CK_ATTRIBUTE xPrivateKeyTemplate[] = + { + { CKA_KEY_TYPE, &xKeyType, sizeof( xKeyType ) }, + { CKA_TOKEN, &xTrue, sizeof( xTrue ) }, + { CKA_PRIVATE, &xTrue, sizeof( xTrue ) }, + { CKA_SIGN, &xTrue, sizeof( xTrue ) }, + { CKA_LABEL, pucPrivateKeyLabel, sizeof( pucPrivateKeyLabel ) - 1 } + }; + + vStart( &hSession, &pxSlotId ); + + xResult = C_GetFunctionList( &pxFunctionList ); + configASSERT( xResult == CKR_OK ); + + configPRINTF( ( "Creating private key with label: %s \r\n", + pkcs11configLABEL_DEVICE_PRIVATE_KEY_FOR_TLS ) ); + configPRINTF( ( "Creating public key with label: %s \r\n", + pkcs11configLABEL_DEVICE_PUBLIC_KEY_FOR_TLS ) ); + + /* This function will generate a new EC private and public key pair. You can + * use " $openssl ec -inform der -in FreeRTOS_P11_Key.dat -text " to see + * the structure of the keys that were generated. + */ + xResult = pxFunctionList->C_GenerateKeyPair( hSession, + &xMechanism, + xPublicKeyTemplate, + sizeof( xPublicKeyTemplate ) / sizeof( CK_ATTRIBUTE ), + xPrivateKeyTemplate, + sizeof( xPrivateKeyTemplate ) / sizeof( CK_ATTRIBUTE ), + &xPublicKeyHandle, + &xPrivateKeyHandle ); + configASSERT( xResult == CKR_OK ); + configPRINTF( ( "FreeRTOS_P11_Key.dat has been created in the Visual Studio" \ + " Solution directory\r\n" ) ); + configPRINTF( ( "Extracting public key bytes...\r\n" ) ); + + /* Export public key as hex bytes and print the hex representation of the + * public key. */ + vExportPublicKey( hSession, + xPublicKeyHandle, + &pxDerPublicKey, + &ulDerPublicKeyLength ); + vWriteHexBytesToConsole( "Public Key in Hex Format", + pxDerPublicKey, + ulDerPublicKeyLength ); + configPRINTF( ( "---------Finished Generating Objects---------" ) ); + vEnd( hSession, pxSlotId ); +} diff --git a/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/pkcs11_demos.h b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/pkcs11_demos.h new file mode 100644 index 0000000000..bdabddf215 --- /dev/null +++ b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/pkcs11_demos.h @@ -0,0 +1,56 @@ +/* + * FreeRTOS PKCS #11 V1.0.3 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://aws.amazon.com/freertos + * http://www.FreeRTOS.org + */ +#ifndef _PKCS11_DEMOS_h_ +#define _PKCS11_DEMOS_h_ + +/* Prototype for the PKCS #11 "Management" demo. This demo covers the various + * functions used to manage the internal state of the PKCS #11 stack, and then + * demonstrates how to generate random numbers using PKCS #11. + */ +void vPKCS11ManagementAndRNGDemo( void ); + +/* Prototype for the PKCS #11 "Digests" demo. This demo covers how to query + * slots for supported capabilities, and creating a message digest if the + * slot supports it. + */ +void vPKCS11MechanismsAndDigestDemo( void ); + +/* Prototype for the PKCS #11 "Object" demo. This demo covers objects and how + * they are defined and used within PKCS #11. + */ +void vPKCS11ObjectDemo( void ); + +/* Prototype for the PKCS #11 "Sign and Verify" demo. This demo covers how + * PKCS #11 can be used to sign a message, and verify the integrity of a message + * using private and public keys. + * + * This demo will also cover the "iot_pkcs11.h" functions, and how they can be + * used to make the PKCS #11 flow easier to use. + * + * Warning: This demo depends on the objects created in the objects demo. + */ +void vPKCS11SignVerifyDemo( void ); + +#endif /* _PKCS11_DEMOS_h_ */ diff --git a/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/sign_and_verify.c b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/sign_and_verify.c new file mode 100644 index 0000000000..c4c7c5e622 --- /dev/null +++ b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/examples/sign_and_verify.c @@ -0,0 +1,367 @@ +/* + * FreeRTOS PKCS #11 V1.0.3 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://aws.amazon.com/freertos + * http://www.FreeRTOS.org + */ +/* FreeRTOS includes. */ +#include "FreeRTOS.h" +#include "task.h" + +/* Standard include. */ +#include "stdio.h" + +/* PKCS #11 includes. */ +#include "iot_pkcs11_config.h" +#include "iot_pkcs11.h" +#include "pkcs11.h" +#include "iot_pki_utils.h" + +/* Demo includes. */ +#include "demo_helpers.h" +#include "pkcs11_demos.h" + +/** + * This function details how to use the PKCS #11 "Sign and Verify" functions to + * create and interact with digital signatures. + * The functions described are all defined in + * http://docs.oasis-open.org/pkcs11/pkcs11-base/v2.40/os/pkcs11-base-v2.40-os.html + * please consult the standard for more information regarding these functions. + * + * The standard has grouped the functions presented in this demo as: + * Object Management Functions + * Signing and MACing Functions + */ +void vPKCS11SignVerifyDemo( void ) +{ + /* This demo will use the generated private and public key from the + * "objects.c" demo and use them to sign and verify the integrity of a + * message digest. This demo will use concepts from all the other demos, + * and is recommended be done last. + * + * The intention of this demo is how to use PKCS #11's Crypotki API to do + * these signature operations, not to explain when and why they should be + * used. For a deeper understanding of that please read: + * https://en.wikipedia.org/wiki/Public_key_infrastructure + * https://en.wikipedia.org/wiki/Transport_Layer_Security + * https://en.wikipedia.org/wiki/Digital_signature + */ + configPRINTF( ( "\r\nStarting PKCS #11 Sign and Verify Demo.\r\n" ) ); + + /* Helper / previously explained variables. */ + CK_RV xResult = CKR_OK; + CK_SESSION_HANDLE hSession = CK_INVALID_HANDLE; + CK_SLOT_ID * pxSlotId = NULL; + CK_ULONG ulSlotCount = 0; + CK_ULONG ulIndex = 0; + CK_OBJECT_HANDLE xPrivateKeyHandle = CK_INVALID_HANDLE; + CK_OBJECT_HANDLE xPublicKeyHandle = CK_INVALID_HANDLE; + CK_FUNCTION_LIST_PTR pxFunctionList = NULL; + CK_BYTE * pxDerPublicKey = NULL; + CK_ULONG ulDerPublicKeyLength = 0; + + /* Digest variables. See "mechanisms_and_digests" for an explanation. */ + CK_BYTE pxKnownMessage[] = { "Hello world" }; + CK_BYTE xDigestResult[ pkcs11SHA256_DIGEST_LENGTH ] = { 0 }; + CK_ULONG ulDigestLength = pkcs11SHA256_DIGEST_LENGTH; + CK_MECHANISM xDigestMechanism = { 0 }; + + /* Signing variables. */ + /* The ECDSA mechanism will be used to sign the message digest. */ + CK_MECHANISM xMechanism = { CKM_ECDSA, NULL, 0 }; + + /* This signature buffer will be used to store the signature created by the + * private key. (64 bytes). We pad it with an extra 8 bytes so it can be + * converted to an ASN.1 encoding. */ + CK_BYTE xSignature[ pkcs11ECDSA_P256_SIGNATURE_LENGTH + 8 ] = { 0 }; + CK_ULONG xSignatureLength = sizeof( xSignature ); + + /* Ensure the Cryptoki library has the necessary functions implemented. */ + xResult = C_GetFunctionList( &pxFunctionList ); + configASSERT( xResult == CKR_OK ); + configASSERT( pxFunctionList->C_SignInit != NULL ); + configASSERT( pxFunctionList->C_Sign != NULL ); + configASSERT( pxFunctionList->C_FindObjectsInit != NULL ); + configASSERT( pxFunctionList->C_FindObjects != NULL ); + configASSERT( pxFunctionList->C_FindObjectsFinal != NULL ); + configASSERT( pxFunctionList->C_Login != NULL ); + configASSERT( pxFunctionList->C_InitToken != NULL ); + configASSERT( pxFunctionList->C_GetTokenInfo != NULL ); + + /* Instead of using the vStart helper, we will use the "iot_pkcs11.h" + * functions that help wrap around some common PKCS #11 use cases. + * + * This function will: + * Initialize the PKCS #11 module if it is not already. + * Initialize a PKCS #11 session. + */ + xResult = xInitializePkcs11Session( &hSession ); + configASSERT( xResult == CKR_OK ); + configASSERT( hSession != CK_INVALID_HANDLE ); + + /* This function will: + * Initialize the PKCS #11 module if it is not already. + * Initialize the token to be used. + * + * Note: By default this function will always initialize the token in the + * first slot in the slot list. If it desired to use a different slot, it + * is necessary to modify the implementation of this function to use a + * different slot. */ + xResult = xInitializePkcs11Token(); + configASSERT( xResult == CKR_OK ); + + /* This function will: + * Query the Cryptoki library for the total number of slots. Malloc an array + * of slots. Then the pxSlotId and ulSlotCount variables will be updated to + * point to the slot array, and the total slot count. + */ + xResult = xGetSlotList( &pxSlotId, &ulSlotCount ); + configASSERT( xResult == CKR_OK ); + configASSERT( ulSlotCount != 0 ); + configASSERT( pxSlotId != NULL ); + + /***************************** Find Objects *****************************/ + + /* This function will: + * Find an object, given it's label. + * + * This is done using the FindObjects group of functions defined as + * "Object Management Functions" in PKCS #11. + * + * This will acquire the object handle for the private key created in the + * "objects.c" demo. + */ + xResult = xFindObjectWithLabelAndClass( hSession, + pkcs11configLABEL_DEVICE_PRIVATE_KEY_FOR_TLS, + CKO_PRIVATE_KEY, + &xPrivateKeyHandle ); + configASSERT( xResult == CKR_OK ); + configASSERT( xPrivateKeyHandle != CK_INVALID_HANDLE ); + + /* Acquire the object handle for the public key created in the "objects.c" + * demo. */ + xResult = xFindObjectWithLabelAndClass( hSession, + pkcs11configLABEL_DEVICE_PUBLIC_KEY_FOR_TLS, + CKO_PRIVATE_KEY, + &xPublicKeyHandle ); + configASSERT( xResult == CKR_OK ); + configASSERT( xPublicKeyHandle != CK_INVALID_HANDLE ); + + /***************************** Buffer Digest *****************************/ + xDigestMechanism.mechanism = CKM_SHA256; + + /* Initializes the digest operation and sets what mechanism will be used + * for the digest. */ + xResult = pxFunctionList->C_DigestInit( hSession, + &xDigestMechanism ); + configASSERT( CKR_OK == xResult ); + + /* Pass a pointer to the buffer of bytes to be hashed, and it's size. */ + xResult = pxFunctionList->C_DigestUpdate( hSession, + pxKnownMessage, + /* Strip NULL Terminator. */ + sizeof( pxKnownMessage ) - 1 ); + configASSERT( CKR_OK == xResult ); + + /* Retrieve the digest buffer length. When passing in a NULL pointer as the + * second argument, instead of a point to a buffer, this will signal the + * Cryptoki library to fill the third parameter with the required amount of + * bytes to store the resulting digest. + */ + xResult = pxFunctionList->C_DigestFinal( hSession, + NULL, + &ulDigestLength ); + configASSERT( CKR_OK == xResult ); + /* Since the length of a SHA-256 digest is known, we made an assumption and + * allocated the buffer originally with the known length. Assert to make sure + * we queried the length we expected. */ + configASSERT( pkcs11SHA256_DIGEST_LENGTH == ulDigestLength ); + + /* Now that ulDigestLength contains the required byte length, retrieve the + * digest buffer. + */ + xResult = pxFunctionList->C_DigestFinal( hSession, + xDigestResult, + &ulDigestLength ); + configASSERT( CKR_OK == xResult ); + + /********************************* Sign **********************************/ + + configPRINTF( ( "Signing known message:\r\n %s\r\n", + ( char * ) pxKnownMessage ) ); + + /* Initializes the sign operation and sets what mechanism will be used + * for signing the message digest. Specify what object handle to use for this + * operation, in this case the private key object handle. */ + xResult = pxFunctionList->C_SignInit( hSession, + &xMechanism, + xPrivateKeyHandle ); + configASSERT( xResult == CKR_OK ); + + /* Sign the message digest that was created with the C_Digest series of + * functions. A signature will be created using the private key specified in + * C_SignInit and put in the byte buffer xSignature. */ + xResult = pxFunctionList->C_Sign( hSession, + xDigestResult, + pkcs11SHA256_DIGEST_LENGTH, + xSignature, + &xSignatureLength ); + configASSERT( xResult == CKR_OK ); + configASSERT( xSignatureLength == pkcs11ECDSA_P256_SIGNATURE_LENGTH ); + + + /********************************* Verify **********************************/ + /* Verify the signature created by C_Sign. First we will verify that the + * same Cryptoki library was able to trust itself. + * + * C_VerifyInit will begin the verify operation, by specifying what mechanism + * to use (CKM_ECDSA, the same as the sign operation) and then specifying + * which public key handle to use. + */ + xResult = pxFunctionList->C_VerifyInit( hSession, + &xMechanism, + xPublicKeyHandle ); + configASSERT( xResult == CKR_OK ); + + /* Given the signature and it's length, the Cryptoki will use the public key + * to verify that the signature was created by the corresponding private key. + * If C_Verify returns CKR_OK, it means that the sender of the message has + * the same private key as the private key that was used to generate the + * public key, and we can trust that the message we received was from that + * sender. + * + * Note that we are not using the actual message, but the digest that we + * created earlier of the message, for the verification. + */ + xResult = pxFunctionList->C_Verify( hSession, + xDigestResult, + pkcs11SHA256_DIGEST_LENGTH, + xSignature, + xSignatureLength ); + + if( xResult == CKR_OK ) + { + configPRINTF( ( "The signature of the digest was verified with the" \ + " public key and can be trusted.\r\n" ) ); + } + else + { + configPRINTF( ( "Unable to verify the signature with the given public" \ + " key, the message cannot be trusted.\r\n" ) ); + } + + /* Export public key as hex bytes and print the hex representation of the + * public key. + * + * We need to export the public key so that it can be used by a different + * device to verify messages signed by the private key of the device that + * generated the key pair. + * + * To do this, we will output the hex representation of the public key. + * Then create an empty text file called "DevicePublicKeyAsciiHex.txt". + * + * Copy and paste the hex value of the public key into this text file. + * + * Then we will need to convert the text file to binary using the xxd tool. + * + * xxd will take a text file that contains hex data and output a binary of + * the hex in the file. See "$ man xxd" for more information about xxd. + * + * Copy the below command into the terminal. + * "$ xxd -r -ps DevicePublicKeyAsciiHex.txt DevicePublicKeyDer.bin" + * + * Now that we have the binary encoding of the public key, we will convert + * it to PEM using OpenSSL. + * + * The following command will create a PEM file of the public key called + * "public_key.pem" + * + * "$ openssl ec -inform der -in DevicePublicKeyDer.bin -pubin -pubout -outform pem -out public_key.pem" + * + * Now we can use the extracted public key to verify the signature of the + * device's private key. + * + * WARNING: Running the object generation demo will create a new key pair, + * and make it necessary to redo these steps! + * + */ + configPRINTF( ( "Verifying with public key.\r\n" ) ); + vExportPublicKey( hSession, + xPublicKeyHandle, + &pxDerPublicKey, + &ulDerPublicKeyLength ); + vWriteHexBytesToConsole( "Public Key in Hex Format", + pxDerPublicKey, + ulDerPublicKeyLength ); + + /* This utility function converts the PKCS #11 signature into an ASN.1 + * encoded binary der signature. This is necessary so we can export the + * signature and verify it with OpenSSL, otherwise OpenSSL will not be able + * to parse the buffer. + * + * See https://en.wikipedia.org/wiki/ASN.1 for more information about the + * ASN.1 encoding format. + */ + PKI_pkcs11SignatureTombedTLSSignature( xSignature, ( size_t * ) &xSignatureLength ); + + + /* The following loop will output the signature in hex. + * + * In order to get the signature exported in binary form copy the output + * of the loop, and paste it to an empty text file. + * + * Then we will need to convert the text file to binary using the xxd tool. + * + * The following commands outline this process. + * Write buffer to signature.txt + * xxd will take a text file that contains hex data and output a binary of + * the hex in the file. See "$ man xxd" for more information about xxd. + * + * Copy the below command into the terminal. + * "$ xxd -r -ps signature.txt signature.bin" + * + * Next, we need to copy the original message that the Cryptoki library + * signed, the following shell command will create the message without any + * newlines, so the messages are similar. + * + * The contents of the echo command can be replaced with whatever data was + * in the known message, but the example uses "Hello world" to make it easier + * for copy and pasting. + * + * "$ echo -n "Hello world" > msg.txt" + * + * Now we will use OpenSSL to verify that the signature we created can be + * trusted by another device using the public key we created and then + * extracted earlier. + * + * "$ openssl dgst -sha256 -verify public_key.pem -signature signature.bin msg.txt" + * This command should output "Verified OK" and we then know we can trust + * the sender of the message! + */ + configPRINTF( ( "Created signature: \r\n" ) ); + for( ulIndex = 0; ulIndex < xSignatureLength; ulIndex++ ) + { + configPRINTF( ( "%02x", xSignature[ ulIndex ] ) ); + } + configPRINTF( ( "\r\n" ) ); + + configPRINTF( ( "Finished PKCS #11 Sign and Verify Demo.\r\n" ) ); +} diff --git a/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/iot_pkcs11_config.h b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/iot_pkcs11_config.h new file mode 100644 index 0000000000..882bca654d --- /dev/null +++ b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/iot_pkcs11_config.h @@ -0,0 +1,173 @@ +/* + * FreeRTOS V1.4.8 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://aws.amazon.com/freertos + * http://www.FreeRTOS.org + */ + +/** + * @file iot_pkcs11_config.h + * @brief PCKS#11 config options. + */ + + +#ifndef _IOT_PKCS11_CONFIG_H_ +#define _IOT_PKCS11_CONFIG_H_ + +#include "FreeRTOS.h" + +/**************************************************/ +/******* DO NOT CHANGE the following order ********/ +/**************************************************/ + +/* Include logging header files and define logging macros in the following order: + * 1. Include the header file "logging_levels.h". + * 2. Define the LIBRARY_LOG_NAME and LIBRARY_LOG_LEVEL macros depending on + * the logging configuration for PKCS #11. + * 3. Include the header file "logging_stack.h", if logging is enabled for PKCS #11. + */ + +#include "logging_levels.h" + +/* Logging configuration for the PKCS #11 library. */ +#ifndef LIBRARY_LOG_NAME + #define LIBRARY_LOG_NAME "PKCS11" +#endif + +#ifndef LIBRARY_LOG_LEVEL + #define LIBRARY_LOG_LEVEL LOG_ERROR +#endif + +#include "logging_stack.h" + +/** + * @brief Malloc API used by iot_pkcs11.h + */ +#define PKCS11_MALLOC pvPortMalloc + +/** + * @brief Free API used by iot_pkcs11.h + */ +#define PKCS11_FREE vPortFree + +/** +* @brief PKCS #11 default user PIN. +* +* The PKCS #11 standard specifies the presence of a user PIN. That feature is +* sensible for applications that have an interactive user interface and memory +* protections. However, since typical microcontroller applications lack one or +* both of those, the user PIN is assumed to be used herein for interoperability +* purposes only, and not as a security feature. +* + * Note: Do not cast this to a pointer! The library calls sizeof to get the length + * of this string. +*/ +#define configPKCS11_DEFAULT_USER_PIN "0000" + +/** +* @brief Maximum length (in characters) for a PKCS #11 CKA_LABEL +* attribute. +*/ +#define pkcs11configMAX_LABEL_LENGTH 32 + +/** +* @brief Maximum number of token objects that can be stored +* by the PKCS #11 module. +*/ +#define pkcs11configMAX_NUM_OBJECTS 6 + +/** + * @brief Maximum number of sessions that can be stored + * by the PKCS #11 module. + */ +#define pkcs11configMAX_SESSIONS 10 + +/** +* @brief Set to 1 if a PAL destroy object is implemented. +* +* If set to 0, no PAL destroy object is implemented, and this functionality +* is implemented in the common PKCS #11 layer. +*/ +#define pkcs11configPAL_DESTROY_SUPPORTED 0 + +/** +* @brief Set to 1 if OTA image verification via PKCS #11 module is supported. +* +* If set to 0, OTA code signing certificate is built in via +* aws_ota_codesigner_certificate.h. +*/ +#define pkcs11configOTA_SUPPORTED 0 + +/** +* @brief Set to 1 if PAL supports storage for JITP certificate, +* code verify certificate, and trusted server root certificate. +* +* If set to 0, PAL does not support storage mechanism for these, and +* they are accessed via headers compiled into the code. +*/ +#define pkcs11configJITP_CODEVERIFY_ROOT_CERT_SUPPORTED 0 + +/** +* @brief The PKCS #11 label for device private key. +* +* Private key for connection to AWS IoT endpoint. The corresponding +* public key should be registered with the AWS IoT endpoint. +*/ +#define pkcs11configLABEL_DEVICE_PRIVATE_KEY_FOR_TLS "Device Priv TLS Key" + +/** +* @brief The PKCS #11 label for device public key. +* +* The public key corresponding to pkcs11configLABEL_DEVICE_PRIVATE_KEY_FOR_TLS. +*/ +#define pkcs11configLABEL_DEVICE_PUBLIC_KEY_FOR_TLS "Device Pub TLS Key" + +/** +* @brief The PKCS #11 label for the device certificate. +* +* Device certificate corresponding to pkcs11configLABEL_DEVICE_PRIVATE_KEY_FOR_TLS. +*/ +#define pkcs11configLABEL_DEVICE_CERTIFICATE_FOR_TLS "Device Cert" + +/** +* @brief The PKCS #11 label for the object to be used for code verification. +* +* Used by over-the-air update code to verify an incoming signed image. +*/ +#define pkcs11configLABEL_CODE_VERIFICATION_KEY "Code Verify Key" + +/** +* @brief The PKCS #11 label for Just-In-Time-Provisioning. +* +* The certificate corresponding to the issuer of the device certificate +* (pkcs11configLABEL_DEVICE_CERTIFICATE_FOR_TLS) when using the JITR or +* JITP flow. +*/ +#define pkcs11configLABEL_JITP_CERTIFICATE "JITP Cert" + +/** +* @brief The PKCS #11 label for the AWS Trusted Root Certificate. +* +* @see aws_default_root_certificates.h +*/ +#define pkcs11configLABEL_ROOT_CERTIFICATE "Root Cert" + +#endif /* _AWS_PKCS11_CONFIG_H_ include guard. */ diff --git a/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/main.c b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/main.c new file mode 100644 index 0000000000..134e2edff5 --- /dev/null +++ b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/main.c @@ -0,0 +1,232 @@ +/* + * FreeRTOS Kernel V10.3.0 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ + +/*** + * See https://www.FreeRTOS.org/pkcs11/index.html for configuration and usage instructions. + ***/ + +/* Standard includes. */ +#include + +/* Visual studio intrinsics used so the __debugbreak() function is available + * should an assert get hit. */ +#include + +/* FreeRTOS includes. */ +#include +#include "task.h" + +/* Windows Crypto includes. */ +#include +#include +#include "mbedtls/entropy.h" + +/* PKCS #11 Demo includes. */ +#include "demo_helpers.h" +#include "pkcs11_demo_config.h" +#include "pkcs11_demos.h" + +/* + * Private function for starting the various PKCS #11 demos. + * + */ +static void prvStartPKCS11Demo( void ) +{ + configPRINTF( ( "---------STARTING DEMO---------\r\n" ) ); + #if ( configPKCS11_MANAGEMENT_AND_RNG_DEMO == 1 ) + vPKCS11ManagementAndRNGDemo(); + #endif + #if ( configPKCS11_MECHANISMS_AND_DIGESTS_DEMO == 1 ) + vPKCS11MechanismsAndDigestDemo(); + #endif + #if ( configPKCS11_OBJECT_DEMO == 1 ) + vPKCS11ObjectDemo(); + #endif + #if ( configPKCS11_SIGN_AND_VERIFY_DEMO == 1 ) + vPKCS11SignVerifyDemo(); + #endif + configPRINTF( ( "---------Finished DEMO---------\r\n" ) ); +} + +/*-----------------------------------------------------------*/ + +int main( void ) +{ + configPRINTF( ( "Creating PKCS #11 Demo Task.\r\n" ) ); + BaseType_t xReturned; + TaskHandle_t xHandle = NULL; + + mbedtls_threading_set_alt( aws_mbedtls_mutex_init, + aws_mbedtls_mutex_free, + aws_mbedtls_mutex_lock, + aws_mbedtls_mutex_unlock ); + + /* Create the PKCS #11 demo task. */ + xReturned = xTaskCreate( + ( TaskFunction_t ) prvStartPKCS11Demo, + "PKCS11 Demo", + configPKCS11_DEMO_STACK_SIZE, + NULL, + tskIDLE_PRIORITY + 1, + &xHandle ); + configASSERT( xReturned == pdPASS ); + + /* Start the RTOS scheduler. */ + vTaskStartScheduler(); + + /* If all is well, the scheduler will now be running, and the following + * line will never be reached. If the following line does execute, then + * there was insufficient FreeRTOS heap memory available for the idle and/or + * timer tasks to be created. See the memory management section on the + * FreeRTOS web site for more details (this is standard text that is not + * really applicable to the Win32 simulator port). */ + for( ; ; ) + { + __debugbreak(); + } +} +/*-----------------------------------------------------------*/ + +void vLoggingPrintf( const char *pcFormat, + ... ) +{ +va_list arg; + + va_start( arg, pcFormat ); + vprintf( pcFormat, arg ); + va_end( arg ); +} +/*-----------------------------------------------------------*/ + +void vAssertCalled( const char * pcFile, + uint32_t ulLine ) +{ + volatile uint32_t ulBlockVariable = 0UL; + volatile char * pcFileName = ( volatile char * ) pcFile; + volatile uint32_t ulLineNumber = ulLine; + + ( void ) pcFileName; + ( void ) ulLineNumber; + + printf( "vAssertCalled( %s, %u\n", pcFile, ulLine ); + + /* Setting ulBlockVariable to a non-zero value in the debugger will allow + * this function to be exited. */ + taskDISABLE_INTERRUPTS(); + { + while( ulBlockVariable == 0UL ) + { + __debugbreak(); + } + } + taskENABLE_INTERRUPTS(); +} +/*-----------------------------------------------------------*/ + +int mbedtls_hardware_poll( void * data, + unsigned char * output, + size_t len, + size_t * olen ) +{ + int lStatus = MBEDTLS_ERR_ENTROPY_SOURCE_FAILED; + HCRYPTPROV hProv = 0; + + /* Unferenced parameter. */ + ( void ) data; + + /* + * This is port-specific for the Windows simulator, so just use Crypto API. + */ + + if( TRUE == CryptAcquireContextA( + &hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT ) ) + { + if( TRUE == CryptGenRandom( hProv, len, output ) ) + { + lStatus = 0; + *olen = len; + } + + CryptReleaseContext( hProv, 0 ); + } + + return lStatus; +} + +/* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an + * implementation of vApplicationGetIdleTaskMemory() to provide the memory that is + * used by the Idle task. */ +void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, + StackType_t ** ppxIdleTaskStackBuffer, + uint32_t * pulIdleTaskStackSize ) +{ + /* If the buffers to be provided to the Idle task are declared inside this + * function then they must be declared static - otherwise they will be allocated on + * the stack and so not exists after this function exits. */ + static StaticTask_t xIdleTaskTCB; + static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ]; + + /* Pass out a pointer to the StaticTask_t structure in which the Idle task's + * state will be stored. */ + *ppxIdleTaskTCBBuffer = &xIdleTaskTCB; + + /* Pass out the array that will be used as the Idle task's stack. */ + *ppxIdleTaskStackBuffer = uxIdleTaskStack; + + /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer. + * Note that, as the array is necessarily of type StackType_t, + * configMINIMAL_STACK_SIZE is specified in words, not bytes. */ + *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; +} +/*-----------------------------------------------------------*/ + +/* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the + * application must provide an implementation of vApplicationGetTimerTaskMemory() + * to provide the memory that is used by the Timer service task. */ +void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer, + StackType_t ** ppxTimerTaskStackBuffer, + uint32_t * pulTimerTaskStackSize ) +{ + /* If the buffers to be provided to the Timer task are declared inside this + * function then they must be declared static - otherwise they will be allocated on + * the stack and so not exists after this function exits. */ + static StaticTask_t xTimerTaskTCB; + static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ]; + + /* Pass out a pointer to the StaticTask_t structure in which the Timer + * task's state will be stored. */ + *ppxTimerTaskTCBBuffer = &xTimerTaskTCB; + + /* Pass out the array that will be used as the Timer task's stack. */ + *ppxTimerTaskStackBuffer = uxTimerTaskStack; + + /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer. + * Note that, as the array is necessarily of type StackType_t, + * configMINIMAL_STACK_SIZE is specified in words, not bytes. */ + *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH; +} +/*-----------------------------------------------------------*/ diff --git a/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/pkcs11_demo_config.h b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/pkcs11_demo_config.h new file mode 100644 index 0000000000..7da59c9e3d --- /dev/null +++ b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/pkcs11_demo_config.h @@ -0,0 +1,59 @@ +/* + * FreeRTOS PKCS #11 V1.0.3 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://aws.amazon.com/freertos + * http://www.FreeRTOS.org + */ + +#ifndef _PKCS11_DEMO_CONFIG_ +#define _PKCS11_DEMO_CONFIG_ + +/* + * @brief this macro defines the stack size for the PKCS #11 demo task. + */ +#define configPKCS11_DEMO_STACK_SIZE 200 + +/* + * @brief set this macro to "1" in order to run the PKCS #11 management and + * random number generator demo. + */ +#define configPKCS11_MANAGEMENT_AND_RNG_DEMO 1 + +/* + * @brief set this macro to "1" in order to run the PKCS #11 mechanisms and + * digest demo. + */ +#define configPKCS11_MECHANISMS_AND_DIGESTS_DEMO 0 + +/* + * @brief set this macro to "1" in order to run the PKCS #11 object demo. + */ +#define configPKCS11_OBJECT_DEMO 0 + +/* + * @brief set this macro to "1" in order to run the PKCS #11 sign and verify + * demo. + * + * @warning This demo relies on the objects created in the object demo. + */ +#define configPKCS11_SIGN_AND_VERIFY_DEMO 0 + +#endif diff --git a/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/pkcs11_demos.sln b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/pkcs11_demos.sln new file mode 100644 index 0000000000..dcfc1fe098 --- /dev/null +++ b/FreeRTOS-Plus/Demo/corePKCS11_Windows_Simulator/pkcs11_demos.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29215.179 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RTOSDemo", "WIN32.vcxproj", "{C686325E-3261-42F7-AEB1-DDE5280E1CEB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C686325E-3261-42F7-AEB1-DDE5280E1CEB}.Debug|Win32.ActiveCfg = Debug|Win32 + {C686325E-3261-42F7-AEB1-DDE5280E1CEB}.Debug|Win32.Build.0 = Debug|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {150F08BF-9D61-4CC2-8DBF-1335172A1EA4} + EndGlobalSection + GlobalSection(TestCaseManagementSettings) = postSolution + CategoryFile = FreeRTOS_Plus_TCP_Minimal.vsmdi + EndGlobalSection +EndGlobal diff --git a/FreeRTOS-Plus/Source/corePKCS11 b/FreeRTOS-Plus/Source/corePKCS11 new file mode 160000 index 0000000000..66720bea59 --- /dev/null +++ b/FreeRTOS-Plus/Source/corePKCS11 @@ -0,0 +1 @@ +Subproject commit 66720bea5941edf6549bd524215156cd01b74e06