├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── doc ├── OPTIGA_Trust_X_Datasheet_v2.5.pdf ├── OPTIGA_Trust_X_KeysAndCertificates_v1.2.pdf └── OPTIGA_Trust_X_SolutionReferenceManual_v1.35.pdf ├── examples ├── calculateHash │ ├── calculateHash.ino │ └── fprint.h ├── calculateSignVerifySign │ ├── calculateSignVerifySign.ino │ └── fprint.h ├── generateKeypair │ ├── fprint.h │ └── generateKeypair.ino ├── getCertificate │ ├── fprint.h │ └── getCertificate.ino ├── getRandom │ ├── fprint.h │ └── getRandom.ino ├── getUniqueID │ ├── fprint.h │ └── getUniqueID.ino ├── selfTest │ ├── fprint.h │ └── selfTest.ino └── testFullAPI │ ├── fprint.h │ └── testFullAPI.ino ├── keywords.txt ├── library.json ├── library.properties └── src ├── OPTIGATrustX.cpp ├── OPTIGATrustX.h ├── optiga_trustx ├── AlertProtocol.h ├── AuthLibSettings.h ├── BaseErrorCodes.h ├── CommandLib.c ├── CommandLib.h ├── CryptoLib.h ├── Datatypes.h ├── DtlsFlighthandler.h ├── DtlsHandshakeProtocol.h ├── DtlsRecordLayer.h ├── DtlsTransportLayer.h ├── DtlsWindowing.h ├── ErrorCodes.h ├── HardwareCrypto.h ├── IntegrationLib.c ├── IntegrationLib.h ├── Logger.h ├── MemoryMgmt.h ├── MessageLayer.h ├── Ocp.h ├── OcpCommon.h ├── OcpCommonIncludes.h ├── OcpCryptoLayer.h ├── OcpRecordLayer.h ├── OcpTransportLayer.h ├── UDPErrorCodes.h ├── Util.c ├── Util.h ├── Version.h ├── ifx_i2c.c ├── ifx_i2c.h ├── ifx_i2c_config.c ├── ifx_i2c_config.h ├── ifx_i2c_data_link_layer.c ├── ifx_i2c_data_link_layer.h ├── ifx_i2c_physical_layer.c ├── ifx_i2c_physical_layer.h ├── ifx_i2c_transport_layer.c ├── ifx_i2c_transport_layer.h ├── optiga_comms.h ├── optiga_comms_ifx_i2c.c ├── pal.h ├── pal_gpio.h ├── pal_gpio_arduino.cpp ├── pal_i2c.h ├── pal_i2c_arduino.cpp ├── pal_ifx_i2c_config.h ├── pal_ifx_i2c_config_arduino.cpp ├── pal_os_event.h ├── pal_os_event_arduino.cpp ├── pal_os_random.h ├── pal_os_timer.h ├── pal_os_timer_arduino.cpp └── pal_socket.h ├── simple_timer ├── SimpleTimer.cpp └── SimpleTimer.h └── third_crypto ├── asm_arm.inc ├── asm_arm_mult_square.inc ├── asm_arm_mult_square_umaal.inc ├── asm_avr.inc ├── asm_avr_mult_square.inc ├── curve-specific.inc ├── platform-specific.inc ├── types.h ├── uECC.c ├── uECC.h └── uECC_vli.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - "2.7" 4 | 5 | sudo: required 6 | 7 | branches: 8 | - master 9 | 10 | env: 11 | matrix: 12 | - PLATFORMIO_CI_SRC=examples/calculateHash 13 | - PLATFORMIO_CI_SRC=examples/calculateSignVerifySign 14 | - PLATFORMIO_CI_SRC=examples/generateKeypair 15 | - PLATFORMIO_CI_SRC=examples/getCertificate 16 | - PLATFORMIO_CI_SRC=examples/getRandom 17 | - PLATFORMIO_CI_SRC=examples/getUniqueID 18 | - PLATFORMIO_CI_SRC=examples/selfTest 19 | - PLATFORMIO_CI_SRC=examples/testFullAPI 20 | 21 | install: 22 | - pip install -U platformio 23 | - platformio platform install -f infineonxmc 24 | - platformio platform install -f atmelavr 25 | 26 | script: 27 | - platformio ci --lib="." --board=xmc1100_xmc2go --board=xmc1100_boot_kit --board=xmc4700_relax_kit --board=uno -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | When contributing to this repository, please first discuss the change you wish to make via issue, 4 | email, or any other method with the owners of this repository before making a change. 5 | 6 | Please note we have a code of conduct, please follow it in all your interactions with the project. 7 | 8 | ## Pull Request Process 9 | 10 | 1. Ensure any install or build dependencies are removed before the end of the layer when doing a 11 | build. 12 | 2. Update the README.md with details of changes to the interface, this includes new environment 13 | variables, useful file locations and parameters. 14 | 3. You may merge the Pull Request in once you have the sign-off of two other developers, or if you 15 | do not have permission to do that, you may request the second reviewer to merge it for you. 16 | 17 | ## Code of Conduct 18 | 19 | ### Our Pledge 20 | 21 | In the interest of fostering an open and welcoming environment, we as 22 | contributors and maintainers pledge to making participation in our project and 23 | our community a harassment-free experience for everyone, regardless of age, body 24 | size, disability, ethnicity, gender identity and expression, level of experience, 25 | nationality, personal appearance, race, religion, or sexual identity and 26 | orientation. 27 | 28 | ### Our Standards 29 | 30 | Examples of behavior that contributes to creating a positive environment 31 | include: 32 | 33 | * Using welcoming and inclusive language 34 | * Being respectful of differing viewpoints and experiences 35 | * Gracefully accepting constructive criticism 36 | * Focusing on what is best for the community 37 | * Showing empathy towards other community members 38 | 39 | Examples of unacceptable behavior by participants include: 40 | 41 | * The use of sexualized language or imagery and unwelcome sexual attention or 42 | advances 43 | * Trolling, insulting/derogatory comments, and personal or political attacks 44 | * Public or private harassment 45 | * Publishing others' private information, such as a physical or electronic 46 | address, without explicit permission 47 | * Other conduct which could reasonably be considered inappropriate in a 48 | professional setting 49 | 50 | ### Our Responsibilities 51 | 52 | Project maintainers are responsible for clarifying the standards of acceptable 53 | behavior and are expected to take appropriate and fair corrective action in 54 | response to any instances of unacceptable behavior. 55 | 56 | Project maintainers have the right and responsibility to remove, edit, or 57 | reject comments, commits, code, wiki edits, issues, and other contributions 58 | that are not aligned to this Code of Conduct, or to ban temporarily or 59 | permanently any contributor for other behaviors that they deem inappropriate, 60 | threatening, offensive, or harmful. 61 | 62 | ### Scope 63 | 64 | This Code of Conduct applies both within project spaces and in public spaces 65 | when an individual is representing the project or its community. Examples of 66 | representing a project or community include using an official project e-mail 67 | address, posting via an official social media account, or acting as an appointed 68 | representative at an online or offline event. Representation of a project may be 69 | further defined and clarified by project maintainers. 70 | 71 | ### Enforcement 72 | 73 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 74 | reported by contacting the project team. 75 | All complaints will be reviewed and investigated and will result in a response that 76 | is deemed necessary and appropriate to the circumstances. The project team is 77 | obligated to maintain confidentiality with regard to the reporter of an incident. 78 | Further details of specific enforcement policies may be posted separately. 79 | 80 | Project maintainers who do not follow or enforce the Code of Conduct in good 81 | faith may face temporary or permanent repercussions as determined by other 82 | members of the project's leadership. 83 | 84 | ### Attribution 85 | 86 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 87 | available at [http://contributor-covenant.org/version/1/4][version] 88 | 89 | [homepage]: http://contributor-covenant.org 90 | [version]: http://contributor-covenant.org/version/1/4/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2018 Infineon Technologies AG 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE -------------------------------------------------------------------------------- /doc/OPTIGA_Trust_X_Datasheet_v2.5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Infineon/arduino-optiga-trust-x/14ceab8d3786354a203ba47b1870a6b7cd85ac85/doc/OPTIGA_Trust_X_Datasheet_v2.5.pdf -------------------------------------------------------------------------------- /doc/OPTIGA_Trust_X_KeysAndCertificates_v1.2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Infineon/arduino-optiga-trust-x/14ceab8d3786354a203ba47b1870a6b7cd85ac85/doc/OPTIGA_Trust_X_KeysAndCertificates_v1.2.pdf -------------------------------------------------------------------------------- /doc/OPTIGA_Trust_X_SolutionReferenceManual_v1.35.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Infineon/arduino-optiga-trust-x/14ceab8d3786354a203ba47b1870a6b7cd85ac85/doc/OPTIGA_Trust_X_SolutionReferenceManual_v1.35.pdf -------------------------------------------------------------------------------- /examples/calculateHash/calculateHash.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * Demonstrates use of the 25 | * Infineon Technologies AG OPTIGA™ Trust X Arduino library 26 | */ 27 | 28 | #include "OPTIGATrustX.h" 29 | 30 | #define DATA_LENGTH 20 31 | #define BIGDATA_LENGTH 1024 32 | #define HASH_LENGTH 32 33 | 34 | #define SUPPRESSCOLLORS 35 | #include "fprint.h" 36 | 37 | /* Arrays to store results of operations */ 38 | uint8_t data[DATA_LENGTH]; 39 | uint8_t bigdata[BIGDATA_LENGTH]; 40 | uint8_t hash[HASH_LENGTH]; 41 | 42 | void setup() 43 | { 44 | uint32_t ret = 0; 45 | 46 | /* 47 | * Initialise a serial port for debug output 48 | */ 49 | Serial.begin(38400); 50 | Serial.println("Initializing ... "); 51 | 52 | /* 53 | * Initialise an OPTIGA™ Trust X Board 54 | */ 55 | printGreen("Begin to trust ... "); 56 | ret = trustX.begin(); 57 | if (ret) { 58 | printlnRed("Failed"); 59 | while (true); 60 | } 61 | printlnGreen("OK"); 62 | 63 | /* 64 | * Speedup the board (from 6 mA to 15 mA) 65 | */ 66 | ret = trustX.setCurrentLimit(15); 67 | if (ret) { 68 | printlnRed("Failed"); 69 | while (true); 70 | } 71 | printlnGreen("OK"); 72 | 73 | } 74 | 75 | static void output_result(char* tag, uint32_t tstamp, uint8_t* in, uint16_t in_len) 76 | { 77 | printGreen("[OK] | Command executed in "); 78 | Serial.print(tstamp); 79 | Serial.println(" ms"); 80 | printMagenta(tag); 81 | printMagenta(" Length: "); 82 | Serial.println(in_len); 83 | printMagenta(tag); 84 | printlnMagenta(":"); 85 | HEXDUMP(in, in_len); 86 | } 87 | 88 | void loop() 89 | { 90 | uint32_t ret = 0; 91 | uint8_t cntr = 10; 92 | // Timestamp is used to measure the execution time of a command 93 | uint32_t ts = 0; 94 | 95 | /* 96 | * Calculate a hash of the given data 97 | */ 98 | printGreen("\r\nCalculate One-Time Hash for "); 99 | printlnGreen((char *)data); 100 | ts = millis(); 101 | ret = trustX.sha256(data, DATA_LENGTH, hash); 102 | ts = millis() - ts; 103 | if (ret) { 104 | printlnRed("Failed"); 105 | while (true); 106 | } 107 | output_result("Hash", ts, hash, HASH_LENGTH); 108 | 109 | /* 110 | * Calculate a hash of the given data (big input) 111 | */ 112 | printlnGreen("\r\nCalculate One-Time Hash for 1024 bytes... "); 113 | ts = millis(); 114 | ret = trustX.sha256(bigdata, BIGDATA_LENGTH, hash); 115 | ts = millis() - ts; 116 | if (ret) { 117 | printlnRed("Failed"); 118 | while (true); 119 | } 120 | 121 | output_result("Hash", ts, hash, HASH_LENGTH); 122 | printGreen("Hashrate is "); 123 | Serial.print(1024/ts); 124 | Serial.println(" kB/sec"); 125 | 126 | /* 127 | * Benchmarking hash for the current microcontroller 128 | */ 129 | printlnGreen("\r\nBenchmarking SHA256 100 times for 20 bytes data ... "); 130 | ts = millis(); 131 | for (int i = 0; i < 100; i++) { 132 | trustX.sha256(data, DATA_LENGTH, hash); 133 | } 134 | ts = millis() - ts; 135 | if (ret) { 136 | printlnRed("Failed"); 137 | while (true); 138 | } 139 | 140 | printGreen("Becnhmark executed in "); 141 | Serial.print(ts); 142 | Serial.println(" ms"); 143 | printGreen("Hashrate is "); 144 | Serial.print((1000 * 100)/ts); 145 | Serial.println(" H/sec"); 146 | 147 | /* 148 | * Count down 10 seconds and restart the application 149 | */ 150 | while(cntr) { 151 | Serial.print(cntr); 152 | Serial.println(" seconds untill restart."); 153 | delay(1000); 154 | cntr--; 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /examples/calculateHash/fprint.h: -------------------------------------------------------------------------------- 1 | #ifndef FPRINT_H 2 | #define FPRINT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "Arduino.h" 9 | 10 | #ifndef SUPPRESSCOLLORS 11 | #define ANSI_COLOR_RED "\x1b[31m" 12 | #define ANSI_COLOR_GREEN "\x1b[32m" 13 | #define ANSI_COLOR_YELLOW "\x1b[33m" 14 | #define ANSI_COLOR_BLUE "\x1b[34m" 15 | #define ANSI_COLOR_MAGENTA "\x1b[35m" 16 | #define ANSI_COLOR_CYAN "\x1b[36m" 17 | #define ANSI_COLOR_RESET "\x1b[0m" 18 | #else 19 | #define ANSI_COLOR_RED "" 20 | #define ANSI_COLOR_GREEN "" 21 | #define ANSI_COLOR_YELLOW "" 22 | #define ANSI_COLOR_BLUE "" 23 | #define ANSI_COLOR_MAGENTA "" 24 | #define ANSI_COLOR_CYAN "" 25 | #define ANSI_COLOR_RESET "" 26 | #endif 27 | 28 | 29 | #define MAXCMD_LEN 255 30 | #define HEXDUMP_COLS 16 31 | 32 | 33 | #ifndef SUPPRESSHEXDUMP 34 | #define SUPPRESSHEXDUMP 0 35 | #endif 36 | #define HEXDUMP(a, b) (SUPPRESSHEXDUMP==0) ? __hexdump__(a,b) : (void) 0; 37 | /** 38 | * 39 | * This function prints a given input in green 40 | * color with a \r\n signs at the end 41 | * 42 | * @retval None 43 | */ 44 | inline void printlnGreen(const char c[]) { 45 | char tmp[100]; 46 | sprintf(tmp, "%s%s%s", ANSI_COLOR_GREEN, c, ANSI_COLOR_RESET); 47 | Serial.println(tmp); 48 | } 49 | 50 | /** 51 | * 52 | * This function prints a given input in red 53 | * color with a \r\n signs at the end 54 | * 55 | * @retval None 56 | */ 57 | inline void printlnRed(const char c[]) { 58 | char tmp[100]; 59 | sprintf(tmp, "%s%s%s", ANSI_COLOR_RED, c, ANSI_COLOR_RESET); 60 | Serial.println(tmp); 61 | } 62 | 63 | /** 64 | * 65 | * This function prints a given input in magenta 66 | * color with a \r\n signs at the end 67 | * 68 | * @retval None 69 | */ 70 | inline void printlnMagenta(const char c[]) { 71 | char tmp[100]; 72 | sprintf(tmp, "%s%s%s", ANSI_COLOR_MAGENTA, c, ANSI_COLOR_RESET); 73 | Serial.println(tmp); 74 | } 75 | 76 | /** 77 | * 78 | * This function prints a given input in magenta 79 | * color without a \r\n signs at the end 80 | * 81 | * @retval None 82 | */ 83 | inline void printMagenta(const char c[]) { 84 | char tmp[100]; 85 | sprintf(tmp, "%s%s%s", ANSI_COLOR_MAGENTA, c, ANSI_COLOR_RESET); 86 | Serial.print(tmp); 87 | } 88 | 89 | /** 90 | * 91 | * This function prints a given input in green 92 | * color without a \r\n signs at the end 93 | * 94 | * @retval None 95 | */ 96 | inline void printGreen(const char c[]) { 97 | char tmp[100]; 98 | sprintf(tmp, "%s%s%s", ANSI_COLOR_GREEN, c, ANSI_COLOR_RESET); 99 | Serial.print(tmp); 100 | } 101 | 102 | /** 103 | * 104 | * Printout data in a standard hex view 105 | * 106 | * @param[in] p_buf Pointer to data which should be printed out. 107 | * @param[in] l_len Length of a data 108 | * 109 | * @retval None 110 | * @example 111 | 0x000000: 2e 2f 68 65 78 64 75 6d ./hexdum 112 | 0x000008: 70 00 53 53 48 5f 41 47 p.SSH_AG 113 | 0x000010: 45 4e 54 5f ENT_ 114 | */ 115 | inline void __hexdump__(const void* p_buf, uint32_t l_len) { 116 | unsigned int i, j; 117 | char str[MAXCMD_LEN]; 118 | for (i = 0; i < l_len + ((l_len % HEXDUMP_COLS) ? 119 | ( HEXDUMP_COLS - l_len % HEXDUMP_COLS) : 0); 120 | i++) { 121 | /* print offset */ 122 | if (i % HEXDUMP_COLS == 0) { 123 | sprintf(str, "0x%06x: ", i); 124 | Serial.print(str); 125 | } 126 | 127 | /* print hex data */ 128 | if (i < l_len) { 129 | sprintf(str, "%02x ", 0xFF & ((char*) p_buf)[i]); 130 | Serial.print(str); 131 | } else /* end of block, just aligning for ASCII dump */ 132 | { 133 | sprintf(str, " "); 134 | Serial.print(str); 135 | } 136 | 137 | /* print ASCII dump */ 138 | if (i % HEXDUMP_COLS == ( HEXDUMP_COLS - 1)) { 139 | for (j = i - ( HEXDUMP_COLS - 1); j <= i; j++) { 140 | if (j >= l_len) /* end of block, not really printing */ 141 | { 142 | Serial.print(' '); 143 | } else if (isprint((int) ((char*) p_buf)[j])) /* printable char */ 144 | { 145 | Serial.print(((char*) p_buf)[j]); 146 | } else /* other char */ 147 | { 148 | Serial.print('.'); 149 | } 150 | } 151 | Serial.print('\r'); 152 | Serial.print('\n'); 153 | } 154 | } 155 | } 156 | 157 | #ifdef __cplusplus 158 | } 159 | #endif 160 | #endif 161 | -------------------------------------------------------------------------------- /examples/calculateSignVerifySign/fprint.h: -------------------------------------------------------------------------------- 1 | #ifndef FPRINT_H 2 | #define FPRINT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "Arduino.h" 9 | 10 | #ifndef SUPPRESSCOLLORS 11 | #define ANSI_COLOR_RED "\x1b[31m" 12 | #define ANSI_COLOR_GREEN "\x1b[32m" 13 | #define ANSI_COLOR_YELLOW "\x1b[33m" 14 | #define ANSI_COLOR_BLUE "\x1b[34m" 15 | #define ANSI_COLOR_MAGENTA "\x1b[35m" 16 | #define ANSI_COLOR_CYAN "\x1b[36m" 17 | #define ANSI_COLOR_RESET "\x1b[0m" 18 | #else 19 | #define ANSI_COLOR_RED "" 20 | #define ANSI_COLOR_GREEN "" 21 | #define ANSI_COLOR_YELLOW "" 22 | #define ANSI_COLOR_BLUE "" 23 | #define ANSI_COLOR_MAGENTA "" 24 | #define ANSI_COLOR_CYAN "" 25 | #define ANSI_COLOR_RESET "" 26 | #endif 27 | 28 | #define MAXCMD_LEN 255 29 | #define HEXDUMP_COLS 16 30 | 31 | 32 | #ifndef SUPPRESSHEXDUMP 33 | #define SUPPRESSHEXDUMP 0 34 | #endif 35 | #define HEXDUMP(a, b) (SUPPRESSHEXDUMP==0) ? __hexdump__(a,b) : (void) 0; 36 | /** 37 | * 38 | * This function prints a given input in green 39 | * color with a \r\n signs at the end 40 | * 41 | * @retval None 42 | */ 43 | inline void printlnGreen(const char c[]) { 44 | char tmp[100]; 45 | sprintf(tmp, "%s%s%s", ANSI_COLOR_GREEN, c, ANSI_COLOR_RESET); 46 | Serial.println(tmp); 47 | } 48 | 49 | /** 50 | * 51 | * This function prints a given input in red 52 | * color with a \r\n signs at the end 53 | * 54 | * @retval None 55 | */ 56 | inline void printlnRed(const char c[]) { 57 | char tmp[100]; 58 | sprintf(tmp, "%s%s%s", ANSI_COLOR_RED, c, ANSI_COLOR_RESET); 59 | Serial.println(tmp); 60 | } 61 | 62 | /** 63 | * 64 | * This function prints a given input in magenta 65 | * color with a \r\n signs at the end 66 | * 67 | * @retval None 68 | */ 69 | inline void printlnMagenta(const char c[]) { 70 | char tmp[100]; 71 | sprintf(tmp, "%s%s%s", ANSI_COLOR_MAGENTA, c, ANSI_COLOR_RESET); 72 | Serial.println(tmp); 73 | } 74 | 75 | /** 76 | * 77 | * This function prints a given input in magenta 78 | * color without a \r\n signs at the end 79 | * 80 | * @retval None 81 | */ 82 | inline void printMagenta(const char c[]) { 83 | char tmp[100]; 84 | sprintf(tmp, "%s%s%s", ANSI_COLOR_MAGENTA, c, ANSI_COLOR_RESET); 85 | Serial.print(tmp); 86 | } 87 | 88 | /** 89 | * 90 | * This function prints a given input in green 91 | * color without a \r\n signs at the end 92 | * 93 | * @retval None 94 | */ 95 | inline void printGreen(const char c[]) { 96 | char tmp[100]; 97 | sprintf(tmp, "%s%s%s", ANSI_COLOR_GREEN, c, ANSI_COLOR_RESET); 98 | Serial.print(tmp); 99 | } 100 | 101 | /** 102 | * 103 | * Printout data in a standard hex view 104 | * 105 | * @param[in] p_buf Pointer to data which should be printed out. 106 | * @param[in] l_len Length of a data 107 | * 108 | * @retval None 109 | * @example 110 | 0x000000: 2e 2f 68 65 78 64 75 6d ./hexdum 111 | 0x000008: 70 00 53 53 48 5f 41 47 p.SSH_AG 112 | 0x000010: 45 4e 54 5f ENT_ 113 | */ 114 | inline void __hexdump__(const void* p_buf, uint32_t l_len) { 115 | unsigned int i, j; 116 | char str[MAXCMD_LEN]; 117 | for (i = 0; i < l_len + ((l_len % HEXDUMP_COLS) ? 118 | ( HEXDUMP_COLS - l_len % HEXDUMP_COLS) : 0); 119 | i++) { 120 | /* print offset */ 121 | if (i % HEXDUMP_COLS == 0) { 122 | sprintf(str, "0x%06x: ", i); 123 | Serial.print(str); 124 | } 125 | 126 | /* print hex data */ 127 | if (i < l_len) { 128 | sprintf(str, "%02x ", 0xFF & ((char*) p_buf)[i]); 129 | Serial.print(str); 130 | } else /* end of block, just aligning for ASCII dump */ 131 | { 132 | sprintf(str, " "); 133 | Serial.print(str); 134 | } 135 | 136 | /* print ASCII dump */ 137 | if (i % HEXDUMP_COLS == ( HEXDUMP_COLS - 1)) { 138 | for (j = i - ( HEXDUMP_COLS - 1); j <= i; j++) { 139 | if (j >= l_len) /* end of block, not really printing */ 140 | { 141 | Serial.print(' '); 142 | } else if (isprint((int) ((char*) p_buf)[j])) /* printable char */ 143 | { 144 | Serial.print(((char*) p_buf)[j]); 145 | } else /* other char */ 146 | { 147 | Serial.print('.'); 148 | } 149 | } 150 | Serial.print('\r'); 151 | Serial.print('\n'); 152 | } 153 | } 154 | } 155 | 156 | #ifdef __cplusplus 157 | } 158 | #endif 159 | #endif 160 | -------------------------------------------------------------------------------- /examples/generateKeypair/fprint.h: -------------------------------------------------------------------------------- 1 | #ifndef FPRINT_H 2 | #define FPRINT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "Arduino.h" 9 | 10 | #ifndef SUPPRESSCOLLORS 11 | #define ANSI_COLOR_RED "\x1b[31m" 12 | #define ANSI_COLOR_GREEN "\x1b[32m" 13 | #define ANSI_COLOR_YELLOW "\x1b[33m" 14 | #define ANSI_COLOR_BLUE "\x1b[34m" 15 | #define ANSI_COLOR_MAGENTA "\x1b[35m" 16 | #define ANSI_COLOR_CYAN "\x1b[36m" 17 | #define ANSI_COLOR_RESET "\x1b[0m" 18 | #else 19 | #define ANSI_COLOR_RED "" 20 | #define ANSI_COLOR_GREEN "" 21 | #define ANSI_COLOR_YELLOW "" 22 | #define ANSI_COLOR_BLUE "" 23 | #define ANSI_COLOR_MAGENTA "" 24 | #define ANSI_COLOR_CYAN "" 25 | #define ANSI_COLOR_RESET "" 26 | #endif 27 | 28 | #define MAXCMD_LEN 255 29 | #define HEXDUMP_COLS 16 30 | 31 | 32 | #ifndef SUPPRESSHEXDUMP 33 | #define SUPPRESSHEXDUMP 0 34 | #endif 35 | #define HEXDUMP(a, b) (SUPPRESSHEXDUMP==0) ? __hexdump__(a,b) : (void) 0; 36 | /** 37 | * 38 | * This function prints a given input in green 39 | * color with a \r\n signs at the end 40 | * 41 | * @retval None 42 | */ 43 | inline void printlnGreen(const char c[]) { 44 | char tmp[100]; 45 | sprintf(tmp, "%s%s%s", ANSI_COLOR_GREEN, c, ANSI_COLOR_RESET); 46 | Serial.println(tmp); 47 | } 48 | 49 | /** 50 | * 51 | * This function prints a given input in red 52 | * color with a \r\n signs at the end 53 | * 54 | * @retval None 55 | */ 56 | inline void printlnRed(const char c[]) { 57 | char tmp[100]; 58 | sprintf(tmp, "%s%s%s", ANSI_COLOR_RED, c, ANSI_COLOR_RESET); 59 | Serial.println(tmp); 60 | } 61 | 62 | /** 63 | * 64 | * This function prints a given input in magenta 65 | * color with a \r\n signs at the end 66 | * 67 | * @retval None 68 | */ 69 | inline void printlnMagenta(const char c[]) { 70 | char tmp[100]; 71 | sprintf(tmp, "%s%s%s", ANSI_COLOR_MAGENTA, c, ANSI_COLOR_RESET); 72 | Serial.println(tmp); 73 | } 74 | 75 | /** 76 | * 77 | * This function prints a given input in magenta 78 | * color without a \r\n signs at the end 79 | * 80 | * @retval None 81 | */ 82 | inline void printMagenta(const char c[]) { 83 | char tmp[100]; 84 | sprintf(tmp, "%s%s%s", ANSI_COLOR_MAGENTA, c, ANSI_COLOR_RESET); 85 | Serial.print(tmp); 86 | } 87 | 88 | /** 89 | * 90 | * This function prints a given input in green 91 | * color without a \r\n signs at the end 92 | * 93 | * @retval None 94 | */ 95 | inline void printGreen(const char c[]) { 96 | char tmp[100]; 97 | sprintf(tmp, "%s%s%s", ANSI_COLOR_GREEN, c, ANSI_COLOR_RESET); 98 | Serial.print(tmp); 99 | } 100 | 101 | /** 102 | * 103 | * Printout data in a standard hex view 104 | * 105 | * @param[in] p_buf Pointer to data which should be printed out. 106 | * @param[in] l_len Length of a data 107 | * 108 | * @retval None 109 | * @example 110 | 0x000000: 2e 2f 68 65 78 64 75 6d ./hexdum 111 | 0x000008: 70 00 53 53 48 5f 41 47 p.SSH_AG 112 | 0x000010: 45 4e 54 5f ENT_ 113 | */ 114 | inline void __hexdump__(const void* p_buf, uint32_t l_len) { 115 | unsigned int i, j; 116 | char str[MAXCMD_LEN]; 117 | for (i = 0; i < l_len + ((l_len % HEXDUMP_COLS) ? 118 | ( HEXDUMP_COLS - l_len % HEXDUMP_COLS) : 0); 119 | i++) { 120 | /* print offset */ 121 | if (i % HEXDUMP_COLS == 0) { 122 | sprintf(str, "0x%06x: ", i); 123 | Serial.print(str); 124 | } 125 | 126 | /* print hex data */ 127 | if (i < l_len) { 128 | sprintf(str, "%02x ", 0xFF & ((char*) p_buf)[i]); 129 | Serial.print(str); 130 | } else /* end of block, just aligning for ASCII dump */ 131 | { 132 | sprintf(str, " "); 133 | Serial.print(str); 134 | } 135 | 136 | /* print ASCII dump */ 137 | if (i % HEXDUMP_COLS == ( HEXDUMP_COLS - 1)) { 138 | for (j = i - ( HEXDUMP_COLS - 1); j <= i; j++) { 139 | if (j >= l_len) /* end of block, not really printing */ 140 | { 141 | Serial.print(' '); 142 | } else if (isprint((int) ((char*) p_buf)[j])) /* printable char */ 143 | { 144 | Serial.print(((char*) p_buf)[j]); 145 | } else /* other char */ 146 | { 147 | Serial.print('.'); 148 | } 149 | } 150 | Serial.print('\r'); 151 | Serial.print('\n'); 152 | } 153 | } 154 | } 155 | 156 | #ifdef __cplusplus 157 | } 158 | #endif 159 | #endif 160 | -------------------------------------------------------------------------------- /examples/generateKeypair/generateKeypair.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * Demonstrates use of the 25 | * Infineon Technologies AG OPTIGA™ Trust X Arduino library 26 | */ 27 | 28 | #include "OPTIGATrustX.h" 29 | 30 | #define KEY_MAXLENGTH 70 31 | 32 | #define SUPPRESSCOLLORS 33 | #include "fprint.h" 34 | 35 | uint8_t *pubKey = new uint8_t[KEY_MAXLENGTH]; 36 | uint8_t *privKey = new uint8_t[KEY_MAXLENGTH]; 37 | 38 | void setup() 39 | { 40 | uint32_t ret = 0; 41 | 42 | /* 43 | * Initialise a serial port for debug output 44 | */ 45 | Serial.begin(38400); 46 | delay(1000); 47 | Serial.println("Initializing ... "); 48 | 49 | /* 50 | * Initialise an OPTIGA™ Trust X Board 51 | */ 52 | printGreen("Begin to trust ... "); 53 | ret = trustX.begin(); 54 | if (ret) { 55 | printlnRed("Failed"); 56 | while (true); 57 | } 58 | printlnGreen("OK"); 59 | 60 | /* 61 | * Speedup the board (from 6 mA to 15 mA) 62 | */ 63 | printGreen("Limit the Current ... "); 64 | ret = trustX.setCurrentLimit(15); 65 | if (ret) { 66 | printlnRed("Failed"); 67 | while (true); 68 | } 69 | printlnGreen("OK"); 70 | 71 | } 72 | 73 | static void output_result(char* tag, uint32_t tstamp, uint8_t* in, uint16_t in_len) 74 | { 75 | printGreen("[OK] | Command executed in "); 76 | Serial.print(tstamp); 77 | Serial.println(" ms"); 78 | printMagenta(tag); 79 | printMagenta(" Length: "); 80 | Serial.println(in_len); 81 | printMagenta(tag); 82 | printlnMagenta(":"); 83 | HEXDUMP(in, in_len); 84 | } 85 | 86 | void loop() 87 | { 88 | uint32_t ret = 0; 89 | uint8_t cntr = 10; 90 | uint32_t ts = 0; 91 | /* OPTIGA Trust X support up to 4 contexts to store you private key */ 92 | uint16_t ctx = 0; 93 | uint16_t pubKeyLen = 0; 94 | uint16_t privKeyLen = 0; 95 | 96 | /* 97 | * Generate a keypair#1 98 | */ 99 | printlnGreen("\r\nGenerate Key Pair. Store Private Key on Board ... "); 100 | ts = millis(); 101 | ret = trustX.generateKeypair(pubKey, pubKeyLen, ctx); 102 | ts = millis() - ts; 103 | if (ret) { 104 | printlnRed("Failed"); 105 | while (true); 106 | } 107 | 108 | output_result("Public Key ", ts, pubKey, pubKeyLen); 109 | 110 | 111 | /* 112 | * Generate a keypair#2 113 | */ 114 | printlnGreen("\r\nGenerate Key Pair. Export Private Key ... "); 115 | ts = millis(); 116 | ret = trustX.generateKeypair(pubKey, pubKeyLen, privKey, privKeyLen); 117 | ts = millis() - ts; 118 | if (ret) { 119 | printlnRed("Failed"); 120 | while (true); 121 | } 122 | 123 | output_result("Public Key ", ts, pubKey, pubKeyLen); 124 | output_result("Private Key ", ts, privKey, privKeyLen); 125 | 126 | /* 127 | * Count down 10 seconds and restart the application 128 | */ 129 | while(cntr) { 130 | Serial.print(cntr); 131 | Serial.println(" seconds untill restart."); 132 | delay(1000); 133 | cntr--; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /examples/getCertificate/fprint.h: -------------------------------------------------------------------------------- 1 | #ifndef FPRINT_H 2 | #define FPRINT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "Arduino.h" 9 | 10 | #ifndef SUPPRESSCOLLORS 11 | #define ANSI_COLOR_RED "\x1b[31m" 12 | #define ANSI_COLOR_GREEN "\x1b[32m" 13 | #define ANSI_COLOR_YELLOW "\x1b[33m" 14 | #define ANSI_COLOR_BLUE "\x1b[34m" 15 | #define ANSI_COLOR_MAGENTA "\x1b[35m" 16 | #define ANSI_COLOR_CYAN "\x1b[36m" 17 | #define ANSI_COLOR_RESET "\x1b[0m" 18 | #else 19 | #define ANSI_COLOR_RED "" 20 | #define ANSI_COLOR_GREEN "" 21 | #define ANSI_COLOR_YELLOW "" 22 | #define ANSI_COLOR_BLUE "" 23 | #define ANSI_COLOR_MAGENTA "" 24 | #define ANSI_COLOR_CYAN "" 25 | #define ANSI_COLOR_RESET "" 26 | #endif 27 | 28 | #define MAXCMD_LEN 255 29 | #define HEXDUMP_COLS 16 30 | 31 | 32 | #ifndef SUPPRESSHEXDUMP 33 | #define SUPPRESSHEXDUMP 0 34 | #endif 35 | #define HEXDUMP(a, b) (SUPPRESSHEXDUMP==0) ? __hexdump__(a,b) : (void) 0; 36 | /** 37 | * 38 | * This function prints a given input in green 39 | * color with a \r\n signs at the end 40 | * 41 | * @retval None 42 | */ 43 | inline void printlnGreen(const char c[]) { 44 | char tmp[100]; 45 | sprintf(tmp, "%s%s%s", ANSI_COLOR_GREEN, c, ANSI_COLOR_RESET); 46 | Serial.println(tmp); 47 | } 48 | 49 | /** 50 | * 51 | * This function prints a given input in red 52 | * color with a \r\n signs at the end 53 | * 54 | * @retval None 55 | */ 56 | inline void printlnRed(const char c[]) { 57 | char tmp[100]; 58 | sprintf(tmp, "%s%s%s", ANSI_COLOR_RED, c, ANSI_COLOR_RESET); 59 | Serial.println(tmp); 60 | } 61 | 62 | /** 63 | * 64 | * This function prints a given input in magenta 65 | * color with a \r\n signs at the end 66 | * 67 | * @retval None 68 | */ 69 | inline void printlnMagenta(const char c[]) { 70 | char tmp[100]; 71 | sprintf(tmp, "%s%s%s", ANSI_COLOR_MAGENTA, c, ANSI_COLOR_RESET); 72 | Serial.println(tmp); 73 | } 74 | 75 | /** 76 | * 77 | * This function prints a given input in magenta 78 | * color without a \r\n signs at the end 79 | * 80 | * @retval None 81 | */ 82 | inline void printMagenta(const char c[]) { 83 | char tmp[100]; 84 | sprintf(tmp, "%s%s%s", ANSI_COLOR_MAGENTA, c, ANSI_COLOR_RESET); 85 | Serial.print(tmp); 86 | } 87 | 88 | /** 89 | * 90 | * This function prints a given input in green 91 | * color without a \r\n signs at the end 92 | * 93 | * @retval None 94 | */ 95 | inline void printGreen(const char c[]) { 96 | char tmp[100]; 97 | sprintf(tmp, "%s%s%s", ANSI_COLOR_GREEN, c, ANSI_COLOR_RESET); 98 | Serial.print(tmp); 99 | } 100 | 101 | /** 102 | * 103 | * Printout data in a standard hex view 104 | * 105 | * @param[in] p_buf Pointer to data which should be printed out. 106 | * @param[in] l_len Length of a data 107 | * 108 | * @retval None 109 | * @example 110 | 0x000000: 2e 2f 68 65 78 64 75 6d ./hexdum 111 | 0x000008: 70 00 53 53 48 5f 41 47 p.SSH_AG 112 | 0x000010: 45 4e 54 5f ENT_ 113 | */ 114 | inline void __hexdump__(const void* p_buf, uint32_t l_len) { 115 | unsigned int i, j; 116 | char str[MAXCMD_LEN]; 117 | for (i = 0; i < l_len + ((l_len % HEXDUMP_COLS) ? 118 | ( HEXDUMP_COLS - l_len % HEXDUMP_COLS) : 0); 119 | i++) { 120 | /* print offset */ 121 | if (i % HEXDUMP_COLS == 0) { 122 | sprintf(str, "0x%06x: ", i); 123 | Serial.print(str); 124 | } 125 | 126 | /* print hex data */ 127 | if (i < l_len) { 128 | sprintf(str, "%02x ", 0xFF & ((char*) p_buf)[i]); 129 | Serial.print(str); 130 | } else /* end of block, just aligning for ASCII dump */ 131 | { 132 | sprintf(str, " "); 133 | Serial.print(str); 134 | } 135 | 136 | /* print ASCII dump */ 137 | if (i % HEXDUMP_COLS == ( HEXDUMP_COLS - 1)) { 138 | for (j = i - ( HEXDUMP_COLS - 1); j <= i; j++) { 139 | if (j >= l_len) /* end of block, not really printing */ 140 | { 141 | Serial.print(' '); 142 | } else if (isprint((int) ((char*) p_buf)[j])) /* printable char */ 143 | { 144 | Serial.print(((char*) p_buf)[j]); 145 | } else /* other char */ 146 | { 147 | Serial.print('.'); 148 | } 149 | } 150 | Serial.print('\r'); 151 | Serial.print('\n'); 152 | } 153 | } 154 | } 155 | 156 | #ifdef __cplusplus 157 | } 158 | #endif 159 | #endif 160 | -------------------------------------------------------------------------------- /examples/getCertificate/getCertificate.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * Demonstrates use of the 25 | * Infineon Technologies AG OPTIGA™ Trust X Arduino library 26 | */ 27 | 28 | #include "OPTIGATrustX.h" 29 | 30 | #define CERT_MAXLENGTH 512 31 | 32 | #define SUPPRESSCOLLORS 33 | #include "fprint.h" 34 | 35 | uint8_t *cert = new uint8_t[CERT_MAXLENGTH]; 36 | 37 | void setup() 38 | { 39 | uint32_t ret = 0; 40 | 41 | /* 42 | * Initialise a serial port for debug output 43 | */ 44 | Serial.begin(38400); 45 | delay(1000); 46 | Serial.println("Initializing ... "); 47 | 48 | /* 49 | * Initialise an OPTIGA™ Trust X Board 50 | */ 51 | printGreen("Begin to trust ... "); 52 | ret = trustX.begin(); 53 | if (ret) { 54 | printlnRed("Failed"); 55 | while (true); 56 | } 57 | printlnGreen("OK"); 58 | 59 | /* 60 | * Speedup the board (from 6 mA to 15 mA) 61 | */ 62 | printGreen("Limit the Current ... "); 63 | ret = trustX.setCurrentLimit(15); 64 | if (ret) { 65 | printlnRed("Failed"); 66 | while (true); 67 | } 68 | printlnGreen("OK"); 69 | 70 | } 71 | 72 | void loop() 73 | { 74 | uint32_t ret = 0; 75 | uint8_t cntr = 10; 76 | uint16_t certLen = 0; 77 | 78 | /* 79 | * Calculate a hash of the given data 80 | */ 81 | printlnGreen("\r\nGetting Certificate ... "); 82 | ret = trustX.getCertificate(cert, certLen); 83 | if (ret) { 84 | printlnRed("Failed"); 85 | while (true); 86 | } 87 | 88 | printlnGreen("[OK]"); 89 | printMagenta("Certificate Length: "); 90 | Serial.println(certLen); 91 | printlnMagenta("Certificate:"); 92 | HEXDUMP(cert, certLen); 93 | 94 | /* 95 | * Count down 10 seconds and restart the application 96 | */ 97 | while(cntr) { 98 | Serial.print(cntr); 99 | Serial.println(" seconds untill restart."); 100 | delay(1000); 101 | cntr--; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /examples/getRandom/fprint.h: -------------------------------------------------------------------------------- 1 | #ifndef FPRINT_H 2 | #define FPRINT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "Arduino.h" 9 | 10 | #ifndef SUPPRESSCOLLORS 11 | #define ANSI_COLOR_RED "\x1b[31m" 12 | #define ANSI_COLOR_GREEN "\x1b[32m" 13 | #define ANSI_COLOR_YELLOW "\x1b[33m" 14 | #define ANSI_COLOR_BLUE "\x1b[34m" 15 | #define ANSI_COLOR_MAGENTA "\x1b[35m" 16 | #define ANSI_COLOR_CYAN "\x1b[36m" 17 | #define ANSI_COLOR_RESET "\x1b[0m" 18 | #else 19 | #define ANSI_COLOR_RED "" 20 | #define ANSI_COLOR_GREEN "" 21 | #define ANSI_COLOR_YELLOW "" 22 | #define ANSI_COLOR_BLUE "" 23 | #define ANSI_COLOR_MAGENTA "" 24 | #define ANSI_COLOR_CYAN "" 25 | #define ANSI_COLOR_RESET "" 26 | #endif 27 | 28 | #define MAXCMD_LEN 255 29 | #define HEXDUMP_COLS 16 30 | 31 | 32 | #ifndef SUPPRESSHEXDUMP 33 | #define SUPPRESSHEXDUMP 0 34 | #endif 35 | #define HEXDUMP(a, b) (SUPPRESSHEXDUMP==0) ? __hexdump__(a,b) : (void) 0; 36 | /** 37 | * 38 | * This function prints a given input in green 39 | * color with a \r\n signs at the end 40 | * 41 | * @retval None 42 | */ 43 | inline void printlnGreen(const char c[]) { 44 | char tmp[100]; 45 | sprintf(tmp, "%s%s%s", ANSI_COLOR_GREEN, c, ANSI_COLOR_RESET); 46 | Serial.println(tmp); 47 | } 48 | 49 | /** 50 | * 51 | * This function prints a given input in red 52 | * color with a \r\n signs at the end 53 | * 54 | * @retval None 55 | */ 56 | inline void printlnRed(const char c[]) { 57 | char tmp[100]; 58 | sprintf(tmp, "%s%s%s", ANSI_COLOR_RED, c, ANSI_COLOR_RESET); 59 | Serial.println(tmp); 60 | } 61 | 62 | /** 63 | * 64 | * This function prints a given input in magenta 65 | * color with a \r\n signs at the end 66 | * 67 | * @retval None 68 | */ 69 | inline void printlnMagenta(const char c[]) { 70 | char tmp[100]; 71 | sprintf(tmp, "%s%s%s", ANSI_COLOR_MAGENTA, c, ANSI_COLOR_RESET); 72 | Serial.println(tmp); 73 | } 74 | 75 | /** 76 | * 77 | * This function prints a given input in magenta 78 | * color without a \r\n signs at the end 79 | * 80 | * @retval None 81 | */ 82 | inline void printMagenta(const char c[]) { 83 | char tmp[100]; 84 | sprintf(tmp, "%s%s%s", ANSI_COLOR_MAGENTA, c, ANSI_COLOR_RESET); 85 | Serial.print(tmp); 86 | } 87 | 88 | /** 89 | * 90 | * This function prints a given input in green 91 | * color without a \r\n signs at the end 92 | * 93 | * @retval None 94 | */ 95 | inline void printGreen(const char c[]) { 96 | char tmp[100]; 97 | sprintf(tmp, "%s%s%s", ANSI_COLOR_GREEN, c, ANSI_COLOR_RESET); 98 | Serial.print(tmp); 99 | } 100 | 101 | /** 102 | * 103 | * Printout data in a standard hex view 104 | * 105 | * @param[in] p_buf Pointer to data which should be printed out. 106 | * @param[in] l_len Length of a data 107 | * 108 | * @retval None 109 | * @example 110 | 0x000000: 2e 2f 68 65 78 64 75 6d ./hexdum 111 | 0x000008: 70 00 53 53 48 5f 41 47 p.SSH_AG 112 | 0x000010: 45 4e 54 5f ENT_ 113 | */ 114 | inline void __hexdump__(const void* p_buf, uint32_t l_len) { 115 | unsigned int i, j; 116 | char str[MAXCMD_LEN]; 117 | for (i = 0; i < l_len + ((l_len % HEXDUMP_COLS) ? 118 | ( HEXDUMP_COLS - l_len % HEXDUMP_COLS) : 0); 119 | i++) { 120 | /* print offset */ 121 | if (i % HEXDUMP_COLS == 0) { 122 | sprintf(str, "0x%06x: ", i); 123 | Serial.print(str); 124 | } 125 | 126 | /* print hex data */ 127 | if (i < l_len) { 128 | sprintf(str, "%02x ", 0xFF & ((char*) p_buf)[i]); 129 | Serial.print(str); 130 | } else /* end of block, just aligning for ASCII dump */ 131 | { 132 | sprintf(str, " "); 133 | Serial.print(str); 134 | } 135 | 136 | /* print ASCII dump */ 137 | if (i % HEXDUMP_COLS == ( HEXDUMP_COLS - 1)) { 138 | for (j = i - ( HEXDUMP_COLS - 1); j <= i; j++) { 139 | if (j >= l_len) /* end of block, not really printing */ 140 | { 141 | Serial.print(' '); 142 | } else if (isprint((int) ((char*) p_buf)[j])) /* printable char */ 143 | { 144 | Serial.print(((char*) p_buf)[j]); 145 | } else /* other char */ 146 | { 147 | Serial.print('.'); 148 | } 149 | } 150 | Serial.print('\r'); 151 | Serial.print('\n'); 152 | } 153 | } 154 | } 155 | 156 | #ifdef __cplusplus 157 | } 158 | #endif 159 | #endif 160 | -------------------------------------------------------------------------------- /examples/getRandom/getRandom.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * Demonstrates use of the 25 | * Infineon Technologies AG OPTIGA™ Trust X Arduino library 26 | */ 27 | 28 | #include "OPTIGATrustX.h" 29 | 30 | #define RND_MAXLENGTH 256 31 | 32 | #define SUPPRESSCOLLORS 33 | #include "fprint.h" 34 | 35 | void setup() 36 | { 37 | uint32_t ret = 0; 38 | 39 | /* 40 | * Initialise a serial port for debug output 41 | */ 42 | Serial.begin(38400); 43 | delay(1000); 44 | Serial.println("Initializing ... "); 45 | 46 | /* 47 | * Initialise an OPTIGA™ Trust X Board 48 | */ 49 | printGreen("Begin to trust ... "); 50 | ret = trustX.begin(); 51 | if (ret) { 52 | printlnRed("Failed"); 53 | while (true); 54 | } 55 | printlnGreen("OK"); 56 | 57 | /* 58 | * Speedup the board (from 6 mA to 15 mA) 59 | */ 60 | ret = trustX.setCurrentLimit(15); 61 | if (ret) { 62 | printlnRed("Failed"); 63 | while (true); 64 | } 65 | printlnGreen("OK"); 66 | 67 | } 68 | 69 | static void output_result(char* tag, uint32_t tstamp, uint8_t* in, uint16_t in_len) 70 | { 71 | printGreen("[OK] | Command executed in "); 72 | Serial.print(tstamp); 73 | Serial.println(" ms"); 74 | printMagenta(tag); 75 | printMagenta(" Length: "); 76 | Serial.println(in_len); 77 | printMagenta(tag); 78 | printlnMagenta(":"); 79 | HEXDUMP(in, in_len); 80 | } 81 | 82 | void loop() 83 | { 84 | uint32_t ret = 0; 85 | uint8_t cntr = 10; 86 | uint8_t *rnd = new uint8_t[RND_MAXLENGTH]; 87 | uint32_t ts = 0; 88 | 89 | /* Initialise Memmory Area */ 90 | memset(rnd, 0, RND_MAXLENGTH); 91 | 92 | /* 93 | * Generate Random values of different sizes 94 | */ 95 | printGreen("\r\nGet 16 bytes random number"); 96 | ts = millis(); 97 | ret = trustX.getRandom(16, rnd); 98 | ts = millis() - ts; 99 | if (ret) { 100 | printlnRed("Failed"); 101 | while (true); 102 | } 103 | output_result("Random", ts, rnd, 16); 104 | 105 | printGreen("\r\nGet 32 bytes random number"); 106 | ts = millis(); 107 | ret = trustX.getRandom(32, rnd); 108 | ts = millis() - ts; 109 | if (ret) { 110 | printlnRed("Failed"); 111 | while (true); 112 | } 113 | output_result("Random", ts, rnd, 32); 114 | 115 | printGreen("\r\nGet 64 bytes random number"); 116 | ts = millis(); 117 | ret = trustX.getRandom(64, rnd); 118 | ts = millis() - ts; 119 | if (ret) { 120 | printlnRed("Failed"); 121 | while (true); 122 | } 123 | output_result("Random", ts, rnd, 64); 124 | 125 | printGreen("\r\nGet 128 bytes random number"); 126 | ts = millis(); 127 | ret = trustX.getRandom(128, rnd); 128 | ts = millis() - ts; 129 | if (ret) { 130 | printlnRed("Failed"); 131 | while (true); 132 | } 133 | output_result("Random", ts, rnd, 128); 134 | 135 | printGreen("\r\nGet 256 bytes random number"); 136 | ts = millis(); 137 | ret = trustX.getRandom(256, rnd); 138 | ts = millis() - ts; 139 | if (ret) { 140 | printlnRed("Failed"); 141 | while (true); 142 | } 143 | output_result("Random", ts, rnd, 256); 144 | 145 | /* 146 | * Count down 10 seconds and restart the application 147 | */ 148 | while(cntr) { 149 | Serial.print(cntr); 150 | Serial.println(" seconds untill restart."); 151 | delay(1000); 152 | cntr--; 153 | } 154 | 155 | /* 156 | * Remove dynamically allocated data 157 | */ 158 | delete rnd; 159 | } 160 | -------------------------------------------------------------------------------- /examples/getUniqueID/fprint.h: -------------------------------------------------------------------------------- 1 | #ifndef FPRINT_H 2 | #define FPRINT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "Arduino.h" 9 | 10 | #ifndef SUPPRESSCOLLORS 11 | #define ANSI_COLOR_RED "\x1b[31m" 12 | #define ANSI_COLOR_GREEN "\x1b[32m" 13 | #define ANSI_COLOR_YELLOW "\x1b[33m" 14 | #define ANSI_COLOR_BLUE "\x1b[34m" 15 | #define ANSI_COLOR_MAGENTA "\x1b[35m" 16 | #define ANSI_COLOR_CYAN "\x1b[36m" 17 | #define ANSI_COLOR_RESET "\x1b[0m" 18 | #else 19 | #define ANSI_COLOR_RED "" 20 | #define ANSI_COLOR_GREEN "" 21 | #define ANSI_COLOR_YELLOW "" 22 | #define ANSI_COLOR_BLUE "" 23 | #define ANSI_COLOR_MAGENTA "" 24 | #define ANSI_COLOR_CYAN "" 25 | #define ANSI_COLOR_RESET "" 26 | #endif 27 | 28 | #define MAXCMD_LEN 255 29 | #define HEXDUMP_COLS 16 30 | 31 | 32 | #ifndef SUPPRESSHEXDUMP 33 | #define SUPPRESSHEXDUMP 0 34 | #endif 35 | #define HEXDUMP(a, b) (SUPPRESSHEXDUMP==0) ? __hexdump__(a,b) : (void) 0; 36 | /** 37 | * 38 | * This function prints a given input in green 39 | * color with a \r\n signs at the end 40 | * 41 | * @retval None 42 | */ 43 | inline void printlnGreen(const char c[]) { 44 | char tmp[100]; 45 | sprintf(tmp, "%s%s%s", ANSI_COLOR_GREEN, c, ANSI_COLOR_RESET); 46 | Serial.println(tmp); 47 | } 48 | 49 | /** 50 | * 51 | * This function prints a given input in red 52 | * color with a \r\n signs at the end 53 | * 54 | * @retval None 55 | */ 56 | inline void printlnRed(const char c[]) { 57 | char tmp[100]; 58 | sprintf(tmp, "%s%s%s", ANSI_COLOR_RED, c, ANSI_COLOR_RESET); 59 | Serial.println(tmp); 60 | } 61 | 62 | /** 63 | * 64 | * This function prints a given input in magenta 65 | * color with a \r\n signs at the end 66 | * 67 | * @retval None 68 | */ 69 | inline void printlnMagenta(const char c[]) { 70 | char tmp[100]; 71 | sprintf(tmp, "%s%s%s", ANSI_COLOR_MAGENTA, c, ANSI_COLOR_RESET); 72 | Serial.println(tmp); 73 | } 74 | 75 | /** 76 | * 77 | * This function prints a given input in magenta 78 | * color without a \r\n signs at the end 79 | * 80 | * @retval None 81 | */ 82 | inline void printMagenta(const char c[]) { 83 | char tmp[100]; 84 | sprintf(tmp, "%s%s%s", ANSI_COLOR_MAGENTA, c, ANSI_COLOR_RESET); 85 | Serial.print(tmp); 86 | } 87 | 88 | /** 89 | * 90 | * This function prints a given input in green 91 | * color without a \r\n signs at the end 92 | * 93 | * @retval None 94 | */ 95 | inline void printGreen(const char c[]) { 96 | char tmp[100]; 97 | sprintf(tmp, "%s%s%s", ANSI_COLOR_GREEN, c, ANSI_COLOR_RESET); 98 | Serial.print(tmp); 99 | } 100 | 101 | /** 102 | * 103 | * Printout data in a standard hex view 104 | * 105 | * @param[in] p_buf Pointer to data which should be printed out. 106 | * @param[in] l_len Length of a data 107 | * 108 | * @retval None 109 | * @example 110 | 0x000000: 2e 2f 68 65 78 64 75 6d ./hexdum 111 | 0x000008: 70 00 53 53 48 5f 41 47 p.SSH_AG 112 | 0x000010: 45 4e 54 5f ENT_ 113 | */ 114 | inline void __hexdump__(const void* p_buf, uint32_t l_len) { 115 | unsigned int i, j; 116 | char str[MAXCMD_LEN]; 117 | for (i = 0; i < l_len + ((l_len % HEXDUMP_COLS) ? 118 | ( HEXDUMP_COLS - l_len % HEXDUMP_COLS) : 0); 119 | i++) { 120 | /* print offset */ 121 | if (i % HEXDUMP_COLS == 0) { 122 | sprintf(str, "0x%06x: ", i); 123 | Serial.print(str); 124 | } 125 | 126 | /* print hex data */ 127 | if (i < l_len) { 128 | sprintf(str, "%02x ", 0xFF & ((char*) p_buf)[i]); 129 | Serial.print(str); 130 | } else /* end of block, just aligning for ASCII dump */ 131 | { 132 | sprintf(str, " "); 133 | Serial.print(str); 134 | } 135 | 136 | /* print ASCII dump */ 137 | if (i % HEXDUMP_COLS == ( HEXDUMP_COLS - 1)) { 138 | for (j = i - ( HEXDUMP_COLS - 1); j <= i; j++) { 139 | if (j >= l_len) /* end of block, not really printing */ 140 | { 141 | Serial.print(' '); 142 | } else if (isprint((int) ((char*) p_buf)[j])) /* printable char */ 143 | { 144 | Serial.print(((char*) p_buf)[j]); 145 | } else /* other char */ 146 | { 147 | Serial.print('.'); 148 | } 149 | } 150 | Serial.print('\r'); 151 | Serial.print('\n'); 152 | } 153 | } 154 | } 155 | 156 | #ifdef __cplusplus 157 | } 158 | #endif 159 | #endif 160 | -------------------------------------------------------------------------------- /examples/getUniqueID/getUniqueID.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * Demonstrates use of the 25 | * Infineon Technologies AG OPTIGA™ Trust X Arduino library 26 | */ 27 | 28 | #include "OPTIGATrustX.h" 29 | 30 | #define UID_LENGTH 27 31 | 32 | #define SUPPRESSCOLLORS 33 | #include "fprint.h" 34 | 35 | void setup() 36 | { 37 | uint32_t ret = 0; 38 | 39 | /* 40 | * Initialise a serial port for debug output 41 | */ 42 | Serial.begin(38400); 43 | delay(1000); 44 | Serial.println("Initializing ... "); 45 | 46 | /* 47 | * Initialise an OPTIGA™ Trust X Board 48 | */ 49 | printGreen("Begin to trust ... "); 50 | ret = trustX.begin(); 51 | if (ret) { 52 | printlnRed("Failed"); 53 | while (true); 54 | } 55 | printlnGreen("OK"); 56 | 57 | /* 58 | * Speedup the board (from 6 mA to 15 mA) 59 | */ 60 | printGreen("Limiting Current consumption (15mA - means no limitation) ... "); 61 | ret = trustX.setCurrentLimit(15); 62 | if (ret) { 63 | printlnRed("Failed"); 64 | while (true); 65 | } 66 | printlnGreen("OK"); 67 | 68 | } 69 | 70 | void loop() 71 | { 72 | uint32_t ret = 0; 73 | uint8_t cntr = 10; 74 | uint8_t uid[UID_LENGTH]; 75 | uint16_t uidLength = UID_LENGTH; 76 | /* 77 | * Getting co-processor Unique ID of 27 bytes 78 | */ 79 | printlnGreen("\r\nGetting co-processor Unique ID... "); 80 | ret = trustX.getUniqueID(uid, uidLength); 81 | if (ret) { 82 | printlnRed("Failed"); 83 | while (true); 84 | } 85 | 86 | printlnGreen("OK"); 87 | printMagenta("Unique ID Length: "); 88 | Serial.println(uidLength); 89 | printlnMagenta("Unique ID:"); 90 | HEXDUMP(uid, uidLength); 91 | 92 | /* 93 | * Count down 10 seconds and restart the application 94 | */ 95 | while(cntr) { 96 | Serial.print(cntr); 97 | Serial.println(" seconds untill restart."); 98 | delay(1000); 99 | cntr--; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /examples/selfTest/fprint.h: -------------------------------------------------------------------------------- 1 | #ifndef FPRINT_H 2 | #define FPRINT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "Arduino.h" 9 | 10 | #ifndef SUPPRESSCOLLORS 11 | #define ANSI_COLOR_RED "\x1b[31m" 12 | #define ANSI_COLOR_GREEN "\x1b[32m" 13 | #define ANSI_COLOR_YELLOW "\x1b[33m" 14 | #define ANSI_COLOR_BLUE "\x1b[34m" 15 | #define ANSI_COLOR_MAGENTA "\x1b[35m" 16 | #define ANSI_COLOR_CYAN "\x1b[36m" 17 | #define ANSI_COLOR_RESET "\x1b[0m" 18 | #else 19 | #define ANSI_COLOR_RED "" 20 | #define ANSI_COLOR_GREEN "" 21 | #define ANSI_COLOR_YELLOW "" 22 | #define ANSI_COLOR_BLUE "" 23 | #define ANSI_COLOR_MAGENTA "" 24 | #define ANSI_COLOR_CYAN "" 25 | #define ANSI_COLOR_RESET "" 26 | #endif 27 | 28 | #define MAXCMD_LEN 255 29 | #define HEXDUMP_COLS 16 30 | 31 | 32 | #ifndef SUPPRESSHEXDUMP 33 | #define SUPPRESSHEXDUMP 0 34 | #endif 35 | #define HEXDUMP(a, b) (SUPPRESSHEXDUMP==0) ? __hexdump__(a,b) : (void) 0; 36 | /** 37 | * 38 | * This function prints a given input in green 39 | * color with a \r\n signs at the end 40 | * 41 | * @retval None 42 | */ 43 | inline void printlnGreen(const char c[]) { 44 | char tmp[100]; 45 | sprintf(tmp, "%s%s%s", ANSI_COLOR_GREEN, c, ANSI_COLOR_RESET); 46 | Serial.println(tmp); 47 | } 48 | 49 | /** 50 | * 51 | * This function prints a given input in red 52 | * color with a \r\n signs at the end 53 | * 54 | * @retval None 55 | */ 56 | inline void printlnRed(const char c[]) { 57 | char tmp[100]; 58 | sprintf(tmp, "%s%s%s", ANSI_COLOR_RED, c, ANSI_COLOR_RESET); 59 | Serial.println(tmp); 60 | } 61 | 62 | /** 63 | * 64 | * This function prints a given input in magenta 65 | * color with a \r\n signs at the end 66 | * 67 | * @retval None 68 | */ 69 | inline void printlnMagenta(const char c[]) { 70 | char tmp[100]; 71 | sprintf(tmp, "%s%s%s", ANSI_COLOR_MAGENTA, c, ANSI_COLOR_RESET); 72 | Serial.println(tmp); 73 | } 74 | 75 | /** 76 | * 77 | * This function prints a given input in magenta 78 | * color without a \r\n signs at the end 79 | * 80 | * @retval None 81 | */ 82 | inline void printMagenta(const char c[]) { 83 | char tmp[100]; 84 | sprintf(tmp, "%s%s%s", ANSI_COLOR_MAGENTA, c, ANSI_COLOR_RESET); 85 | Serial.print(tmp); 86 | } 87 | 88 | /** 89 | * 90 | * This function prints a given input in green 91 | * color without a \r\n signs at the end 92 | * 93 | * @retval None 94 | */ 95 | inline void printGreen(const char c[]) { 96 | char tmp[100]; 97 | sprintf(tmp, "%s%s%s", ANSI_COLOR_GREEN, c, ANSI_COLOR_RESET); 98 | Serial.print(tmp); 99 | } 100 | 101 | /** 102 | * 103 | * Printout data in a standard hex view 104 | * 105 | * @param[in] p_buf Pointer to data which should be printed out. 106 | * @param[in] l_len Length of a data 107 | * 108 | * @retval None 109 | * @example 110 | 0x000000: 2e 2f 68 65 78 64 75 6d ./hexdum 111 | 0x000008: 70 00 53 53 48 5f 41 47 p.SSH_AG 112 | 0x000010: 45 4e 54 5f ENT_ 113 | */ 114 | inline void __hexdump__(const void* p_buf, uint32_t l_len) { 115 | unsigned int i, j; 116 | char str[MAXCMD_LEN]; 117 | for (i = 0; i < l_len + ((l_len % HEXDUMP_COLS) ? 118 | ( HEXDUMP_COLS - l_len % HEXDUMP_COLS) : 0); 119 | i++) { 120 | /* print offset */ 121 | if (i % HEXDUMP_COLS == 0) { 122 | sprintf(str, "0x%06x: ", i); 123 | Serial.print(str); 124 | } 125 | 126 | /* print hex data */ 127 | if (i < l_len) { 128 | sprintf(str, "%02x ", 0xFF & ((char*) p_buf)[i]); 129 | Serial.print(str); 130 | } else /* end of block, just aligning for ASCII dump */ 131 | { 132 | sprintf(str, " "); 133 | Serial.print(str); 134 | } 135 | 136 | /* print ASCII dump */ 137 | if (i % HEXDUMP_COLS == ( HEXDUMP_COLS - 1)) { 138 | for (j = i - ( HEXDUMP_COLS - 1); j <= i; j++) { 139 | if (j >= l_len) /* end of block, not really printing */ 140 | { 141 | Serial.print(' '); 142 | } else if (isprint((int) ((char*) p_buf)[j])) /* printable char */ 143 | { 144 | Serial.print(((char*) p_buf)[j]); 145 | } else /* other char */ 146 | { 147 | Serial.print('.'); 148 | } 149 | } 150 | Serial.print('\r'); 151 | Serial.print('\n'); 152 | } 153 | } 154 | } 155 | 156 | #ifdef __cplusplus 157 | } 158 | #endif 159 | #endif 160 | -------------------------------------------------------------------------------- /examples/selfTest/selfTest.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * Demonstrates use of the 25 | * Infineon Technologies AG OPTIGA™ Trust X Arduino library 26 | */ 27 | 28 | #include "OPTIGATrustX.h" 29 | 30 | #define SUPPRESSCOLLORS 31 | #include "fprint.h" 32 | 33 | void loop() 34 | { 35 | uint32_t ret = 0; 36 | /* 37 | * Authenticating OPTIGA™ Trust X chip 38 | */ 39 | printGreen("Authenticating OPTIGA(TM) Trust X chip... "); 40 | ret = trustX.checkChip(); 41 | if (ret) { 42 | printlnRed("Failed"); 43 | while (true); 44 | } 45 | printlnGreen("OK"); 46 | 47 | delay(2000); 48 | } 49 | 50 | void setup() 51 | { 52 | uint32_t ret = 0; 53 | 54 | /* 55 | * Initialise serial output 56 | */ 57 | Serial.begin(38400); 58 | Serial.println("Initializing ... "); 59 | 60 | /* 61 | * Initialise OPTIGA™ Trust X 62 | */ 63 | printGreen("Begin Trust ... "); 64 | ret = trustX.begin(); 65 | if (ret) { 66 | printlnRed("Failed"); 67 | while (true); 68 | } 69 | printlnGreen("OK"); 70 | 71 | /* 72 | * Speed up the chip (min is 6ma, maximum is 15ma) 73 | */ 74 | printGreen("Setting Current Limit... "); 75 | ret = trustX.setCurrentLimit(15); 76 | if (ret) { 77 | printlnRed("Failed"); 78 | while (true); 79 | } 80 | printlnGreen("OK"); 81 | } -------------------------------------------------------------------------------- /examples/testFullAPI/fprint.h: -------------------------------------------------------------------------------- 1 | #ifndef FPRINT_H 2 | #define FPRINT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "Arduino.h" 9 | 10 | #ifndef SUPPRESSCOLLORS 11 | #define ANSI_COLOR_RED "\x1b[31m" 12 | #define ANSI_COLOR_GREEN "\x1b[32m" 13 | #define ANSI_COLOR_YELLOW "\x1b[33m" 14 | #define ANSI_COLOR_BLUE "\x1b[34m" 15 | #define ANSI_COLOR_MAGENTA "\x1b[35m" 16 | #define ANSI_COLOR_CYAN "\x1b[36m" 17 | #define ANSI_COLOR_RESET "\x1b[0m" 18 | #else 19 | #define ANSI_COLOR_RED "" 20 | #define ANSI_COLOR_GREEN "" 21 | #define ANSI_COLOR_YELLOW "" 22 | #define ANSI_COLOR_BLUE "" 23 | #define ANSI_COLOR_MAGENTA "" 24 | #define ANSI_COLOR_CYAN "" 25 | #define ANSI_COLOR_RESET "" 26 | #endif 27 | 28 | #define MAXCMD_LEN 255 29 | #define HEXDUMP_COLS 16 30 | 31 | 32 | #ifndef SUPPRESSHEXDUMP 33 | #define SUPPRESSHEXDUMP 0 34 | #endif 35 | #define HEXDUMP(a, b) (SUPPRESSHEXDUMP==0) ? __hexdump__(a,b) : (void) 0; 36 | /** 37 | * 38 | * This function prints a given input in green 39 | * color with a \r\n signs at the end 40 | * 41 | * @retval None 42 | */ 43 | inline void printlnGreen(const char c[]) { 44 | char tmp[100]; 45 | sprintf(tmp, "%s%s%s", ANSI_COLOR_GREEN, c, ANSI_COLOR_RESET); 46 | Serial.println(tmp); 47 | } 48 | 49 | /** 50 | * 51 | * This function prints a given input in red 52 | * color with a \r\n signs at the end 53 | * 54 | * @retval None 55 | */ 56 | inline void printlnRed(const char c[]) { 57 | char tmp[100]; 58 | sprintf(tmp, "%s%s%s", ANSI_COLOR_RED, c, ANSI_COLOR_RESET); 59 | Serial.println(tmp); 60 | } 61 | 62 | /** 63 | * 64 | * This function prints a given input in magenta 65 | * color with a \r\n signs at the end 66 | * 67 | * @retval None 68 | */ 69 | inline void printlnMagenta(const char c[]) { 70 | char tmp[100]; 71 | sprintf(tmp, "%s%s%s", ANSI_COLOR_MAGENTA, c, ANSI_COLOR_RESET); 72 | Serial.println(tmp); 73 | } 74 | 75 | /** 76 | * 77 | * This function prints a given input in magenta 78 | * color without a \r\n signs at the end 79 | * 80 | * @retval None 81 | */ 82 | inline void printMagenta(const char c[]) { 83 | char tmp[100]; 84 | sprintf(tmp, "%s%s%s", ANSI_COLOR_MAGENTA, c, ANSI_COLOR_RESET); 85 | Serial.print(tmp); 86 | } 87 | 88 | /** 89 | * 90 | * This function prints a given input in green 91 | * color without a \r\n signs at the end 92 | * 93 | * @retval None 94 | */ 95 | inline void printGreen(const char c[]) { 96 | char tmp[100]; 97 | sprintf(tmp, "%s%s%s", ANSI_COLOR_GREEN, c, ANSI_COLOR_RESET); 98 | Serial.print(tmp); 99 | } 100 | 101 | /** 102 | * 103 | * Printout data in a standard hex view 104 | * 105 | * @param[in] p_buf Pointer to data which should be printed out. 106 | * @param[in] l_len Length of a data 107 | * 108 | * @retval None 109 | * @example 110 | 0x000000: 2e 2f 68 65 78 64 75 6d ./hexdum 111 | 0x000008: 70 00 53 53 48 5f 41 47 p.SSH_AG 112 | 0x000010: 45 4e 54 5f ENT_ 113 | */ 114 | inline void __hexdump__(const void* p_buf, uint32_t l_len) { 115 | unsigned int i, j; 116 | char str[MAXCMD_LEN]; 117 | for (i = 0; i < l_len + ((l_len % HEXDUMP_COLS) ? 118 | ( HEXDUMP_COLS - l_len % HEXDUMP_COLS) : 0); 119 | i++) { 120 | /* print offset */ 121 | if (i % HEXDUMP_COLS == 0) { 122 | sprintf(str, "0x%06x: ", i); 123 | Serial.print(str); 124 | } 125 | 126 | /* print hex data */ 127 | if (i < l_len) { 128 | sprintf(str, "%02x ", 0xFF & ((char*) p_buf)[i]); 129 | Serial.print(str); 130 | } else /* end of block, just aligning for ASCII dump */ 131 | { 132 | sprintf(str, " "); 133 | Serial.print(str); 134 | } 135 | 136 | /* print ASCII dump */ 137 | if (i % HEXDUMP_COLS == ( HEXDUMP_COLS - 1)) { 138 | for (j = i - ( HEXDUMP_COLS - 1); j <= i; j++) { 139 | if (j >= l_len) /* end of block, not really printing */ 140 | { 141 | Serial.print(' '); 142 | } else if (isprint((int) ((char*) p_buf)[j])) /* printable char */ 143 | { 144 | Serial.print(((char*) p_buf)[j]); 145 | } else /* other char */ 146 | { 147 | Serial.print('.'); 148 | } 149 | } 150 | Serial.print('\r'); 151 | Serial.print('\n'); 152 | } 153 | } 154 | } 155 | 156 | #ifdef __cplusplus 157 | } 158 | #endif 159 | #endif 160 | -------------------------------------------------------------------------------- /examples/testFullAPI/testFullAPI.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * Demonstrates use of the 25 | * Infineon Technologies AG OPTIGA™ Trust X Arduino library 26 | */ 27 | 28 | #include "OPTIGATrustX.h" 29 | 30 | #define MAXCMD_LEN 255 31 | #define CERT_LENGTH 512 32 | #define RND_LENGTH 64 33 | #define HASH_LENGTH 32 34 | #define SIGN_LENGTH 80 35 | #define PUBKEY_LENGTH 70 36 | #define UID_LENGTH 27 37 | 38 | #define SUPPRESSCOLLORS 39 | #include "fprint.h" 40 | 41 | #define ASSERT(err) if (ret) { printlnRed("Failed"); while (true); } 42 | 43 | /* 44 | * Allocating buffers for further use in loop() 45 | */ 46 | uint8_t *cert = new uint8_t[CERT_LENGTH]; 47 | uint16_t certLen = CERT_LENGTH; 48 | uint8_t *rnd = new uint8_t[RND_LENGTH]; 49 | uint16_t rndLen = RND_LENGTH; 50 | uint8_t *hash = new uint8_t[HASH_LENGTH]; 51 | uint16_t hashLen = HASH_LENGTH; 52 | uint8_t *rawSign = new uint8_t[SIGN_LENGTH]; 53 | uint8_t *formSign = new uint8_t[SIGN_LENGTH]; 54 | uint16_t signLen = SIGN_LENGTH; 55 | uint8_t *pubKey = new uint8_t[PUBKEY_LENGTH]; 56 | uint16_t pubKeyLen = PUBKEY_LENGTH; 57 | uint8_t *uid = new uint8_t[UID_LENGTH]; 58 | 59 | 60 | 61 | 62 | static void output_result(char* tag, uint8_t* in, uint16_t in_len) 63 | { 64 | printlnGreen("OK"); 65 | printMagenta(tag); 66 | printMagenta(" Length: "); 67 | Serial.println(in_len); 68 | printMagenta(tag); 69 | printlnMagenta(":"); 70 | HEXDUMP(in, in_len); 71 | } 72 | 73 | void loop() 74 | { 75 | uint32_t ret = 0; 76 | uint8_t cntr = 10; 77 | uint8_t ifxPublicKey[68]; 78 | 79 | /* 80 | * Getting co-processor Unique ID 81 | */ 82 | printGreen("Get co-processor UID ... "); 83 | uint16_t uidLength = UID_LENGTH; 84 | ret = trustX.getUniqueID(uid, uidLength); 85 | ASSERT(ret); 86 | output_result("Co-processor UID", uid, uidLength); 87 | 88 | /* 89 | * Getting primary certificate 90 | */ 91 | printGreen("Reading cert ... "); 92 | ret = trustX.getCertificate(cert, certLen); 93 | ASSERT(ret); 94 | output_result("Certificate", cert, certLen); 95 | 96 | /* 97 | * Generate a Keypair 98 | */ 99 | printGreen("Generate Key Pair ... "); 100 | uint16_t ctx = 0; 101 | ret = trustX.generateKeypair(pubKey, pubKeyLen, ctx); 102 | ASSERT(ret); 103 | output_result("Public key", pubKey, pubKeyLen); 104 | 105 | /* 106 | * Get random value of RND_LENGTH length 107 | */ 108 | printGreen("Get random value ... "); 109 | ret = trustX.getRandom(RND_LENGTH, rnd); 110 | ASSERT(ret); 111 | output_result("Random", rnd, RND_LENGTH); 112 | 113 | /* 114 | * Calculate SHA256 value 115 | */ 116 | printGreen("Calculate Hash ... "); 117 | ret = trustX.sha256(rnd, RND_LENGTH, hash); 118 | hashLen = 32; 119 | ASSERT(ret); 120 | output_result("SHA256", hash, hashLen); 121 | 122 | /* 123 | * Generate a signature NIST-P256 124 | */ 125 | printGreen("Generate Signature ... "); 126 | ret = trustX.calculateSignature(hash, hashLen, formSign, signLen); 127 | ASSERT(ret); 128 | output_result("Signature", formSign, signLen); 129 | 130 | /* 131 | * Verify just geberated signature 132 | */ 133 | trustX.getPublicKey(ifxPublicKey); 134 | 135 | printGreen("Verify Signature ... "); 136 | ret = trustX.verifySignature(hash, hashLen, formSign, signLen, ifxPublicKey, 137 | sizeof(ifxPublicKey) / sizeof(ifxPublicKey[0])); 138 | ASSERT(ret); 139 | printlnGreen("OK"); 140 | 141 | /* 142 | * Count down 10 seconds and restart the application 143 | */ 144 | while(cntr) { 145 | Serial.print(cntr); 146 | Serial.println(" seconds untill restart."); 147 | delay(1000); 148 | cntr--; 149 | } 150 | } 151 | 152 | void setup() 153 | { 154 | uint32_t ret = 0; 155 | 156 | /* 157 | * Initialise serial output 158 | */ 159 | Serial.begin(38400); 160 | Serial.println("Initializing ... "); 161 | 162 | /* 163 | * Initialise OPTIGA™ Trust X 164 | */ 165 | printGreen("Begin Trust ... "); 166 | ret = trustX.begin(); 167 | ASSERT(ret); 168 | printlnGreen("OK"); 169 | 170 | /* 171 | * Speed up the chip (min is 6ma, maximum is 15ma) 172 | */ 173 | printGreen("Setting Current Limit... "); 174 | ret = trustX.setCurrentLimit(15); 175 | ASSERT(ret); 176 | printlnGreen("OK"); 177 | 178 | /* 179 | * Check the return value which we just set 180 | */ 181 | printGreen("Checking Power Limit... "); 182 | uint8_t current_lim = 0; 183 | ret = trustX.getCurrentLimit(current_lim); 184 | ASSERT(ret); 185 | if (current_lim == 15) { 186 | printlnGreen("OK"); 187 | } else { 188 | printlnRed("Failed"); 189 | while(1); 190 | } 191 | } 192 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Wire 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | eOID_d KEYWORD1 9 | eSessionCtxId_d KEYWORD1 10 | ####################################### 11 | # Methods and Functions (KEYWORD2) 12 | ####################################### 13 | 14 | begin KEYWORD2 15 | checkChip KEYWORD2 16 | reset KEYWORD2 17 | getCertificate KEYWORD2 18 | getPublicKey KEYWORD2 19 | getUniqueID KEYWORD2 20 | getRandom KEYWORD2 21 | getCurrentLimit KEYWORD2 22 | setCurrentLimit KEYWORD2 23 | getLastErrorCodes KEYWORD2 24 | sha256 KEYWORD2 25 | calculateSignature KEYWORD2 26 | formatSignature KEYWORD2 27 | verifySignature KEYWORD2 28 | sharedSecret KEYWORD2 29 | sharedSecretWithExport KEYWORD2 30 | generateKeypair KEYWORD2 31 | 32 | ####################################### 33 | # Instances (KEYWORD2) 34 | ####################################### 35 | 36 | trustX KEYWORD2 37 | 38 | ####################################### 39 | # Constants (LITERAL1) 40 | ####################################### 41 | eLCS_G LITERAL1 42 | eSECURITY_STATUS_G LITERAL1 43 | eCOPROCESSOR_UID LITERAL1 44 | eSLEEP_MODE_ACTIVATION_DELAY LITERAL1 45 | eCURRENT_LIMITATION LITERAL1 46 | eSECURITY_EVENT_COUNTER LITERAL1 47 | eDEVICE_PUBKEY_CERT_IFX LITERAL1 48 | eDEVICE_PUBKEY_CERT_PRJSPC_1 LITERAL1 49 | eDEVICE_PUBKEY_CERT_PRJSPC_2 LITERAL1 50 | eDEVICE_PUBKEY_CERT_PRJSPC_3 LITERAL1 51 | eFIRST_DEVICE_PRIKEY_1 LITERAL1 52 | eFIRST_DEVICE_PRIKEY_2 LITERAL1 53 | eFIRST_DEVICE_PRIKEY_3 LITERAL1 54 | eFIRST_DEVICE_PRIKEY_4 LITERAL1 55 | eLCS_A LITERAL1 56 | eSECURITY_STATUS_A LITERAL1 57 | eERROR_CODES LITERAL1 58 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "arduino-optiga-trust-x", 3 | "keywords": "security, trust-x, sensor2go, ECDSA, DTLS, ECC256, AES128, SHA-256, TRNG, DRNG", 4 | "description": "This library allows you to communicate with Optiga Trust X", 5 | "repository": 6 | { 7 | "type": "git", 8 | "url": "https://github.com/Infineon/arduino-optiga-trust-x.git", 9 | "branch": "master" 10 | }, 11 | "version":"1.0.5", 12 | "frameworks": "arduino", 13 | "platforms": [ 14 | "infineonxmc", 15 | "atmelavr" 16 | ] 17 | } -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=OPTIGA Trust X 2 | version=1.0.5 3 | author=Infineon Technologies 4 | maintainer=Infineon Technologies 5 | sentence=This library allows you to communicate with Optiga Trust Products. Currently only Trust X is supported. 6 | paragraph=It allows the communication with the Optiga Trust X Chip using the Wire library with the I2C Master-Slave 7 | category=Communication 8 | url=https://www.infineon.com/cms/en/product/security-smart-card-solutions/optiga-embedded-security-solutions/optiga-trust/optiga-trust-x-sls-32aia/ 9 | architectures=* 10 | 11 | -------------------------------------------------------------------------------- /src/optiga_trustx/AlertProtocol.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file AlertProtocol.h 26 | * 27 | * \brief This file defines APIs, types and data structures used in the 28 | * (D)TLS Alert implementation. 29 | * 30 | * \ingroup grMutualAuth 31 | * @{ 32 | */ 33 | 34 | #ifndef __ALERT_H__ 35 | #define __ALERT_H__ 36 | 37 | 38 | #include "OcpCommon.h" 39 | #include "OcpCommonIncludes.h" 40 | 41 | #ifdef MODULE_ENABLE_DTLS_MUTUAL_AUTH 42 | /**************************************************************************** 43 | * 44 | * API Error Codes 45 | * 46 | ****************************************************************************/ 47 | 48 | /// Successful execution 49 | #define OCP_AL_OK 0x74281527 50 | 51 | /// Failure in execution 52 | #define OCP_AL_ERROR 0xFC468021 53 | 54 | ///Null Parameter(s) 55 | #define OCP_AL_NULL_PARAM BASE_ERROR_ALERT 56 | 57 | ///Length of input is zero 58 | #define OCP_AL_LENZERO_ERROR (BASE_ERROR_ALERT + 1) 59 | 60 | ///Fatal error 61 | #define OCP_AL_FATAL_ERROR (BASE_ERROR_ALERT + 2) 62 | 63 | ///Warning error 64 | #define OCP_AL_WARNING_ERROR (BASE_ERROR_ALERT + 3) 65 | 66 | /** 67 | * \brief Process the Alert Messages. 68 | */ 69 | int32_t Alert_ProcessMsg(const sbBlob_d* PpsAlertMsg,int32_t* Ppi4ErrorCode); 70 | 71 | /** 72 | * \brief Sends Alert based on the internal error code via the Record Layer. 73 | */ 74 | void Alert_Send(sConfigRL_d *PpsConfigRL,int32_t Pi4ErrorCode); 75 | 76 | ///Macro to Send Alert 77 | #ifndef DISABLE_ALERT 78 | #define SEND_ALERT(RLHdl,error) Alert_Send(RLHdl,error); 79 | #else 80 | #define SEND_ALERT(RLHdl,error) 81 | #endif 82 | 83 | #endif /* MODULE_ENABLE_DTLS_MUTUAL_AUTH */ 84 | 85 | #endif //__ALERT_H__ 86 | /** 87 | * @} 88 | */ 89 | -------------------------------------------------------------------------------- /src/optiga_trustx/AuthLibSettings.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file is defines the compilation switches to build code with required features. 28 | * 29 | * \ingroup grMutualAuth 30 | * @{ 31 | */ 32 | 33 | 34 | #ifndef _AUTH_LIB_SETTINGS_H_ 35 | #define _AUTH_LIB_SETTINGS_H_ 36 | /* 37 | To enable a user in choosing required feature set, compilation switches are provided to build the code. 38 | 1.FEATURE_ONEWAY_AUTH : One Way authentication feature is enabled. 39 | 2.FEATURE_DTLS_MUTUAL_AUTH : Mutual authentication feature is enabled. 40 | 3.FEATURE_TOOLBOX : Tool box feature is enabled 41 | 4.By default all features are enabled. 42 | 43 | A user can define more switches in the following way and add it before the default #else directive 44 | 45 | //Sample definition for new compile time switch 46 | #ifdef NEW_REQUIRED_FEATURES 47 | #define MODULE_X 48 | #define MODULE_Y 49 | #define MODULE_Z 50 | #endif 51 | */ 52 | 53 | //If only One Way Authentication feature required 54 | #ifdef FEATURE_ONEWAY_AUTH 55 | #define MODULE_ENABLE_READ_WRITE 56 | #define MODULE_ENABLE_ONE_WAY_AUTH 57 | #define FEATURE_ENABLED 58 | #endif 59 | 60 | //If only Mutual Authentication feature required 61 | #ifdef FEATURE_DTLS_MUTUAL_AUTH 62 | #define MODULE_ENABLE_READ_WRITE 63 | #define MODULE_ENABLE_DTLS_MUTUAL_AUTH 64 | #define FEATURE_ENABLED 65 | #endif 66 | 67 | #ifdef FEATURE_TOOLBOX 68 | #define MODULE_ENABLE_TOOLBOX 69 | #define FEATURE_ENABLED 70 | #endif 71 | 72 | //By Default all are enabled 73 | #ifndef FEATURE_ENABLED 74 | #define MODULE_ENABLE_READ_WRITE 75 | #define MODULE_ENABLE_ONE_WAY_AUTH 76 | //#define MODULE_ENABLE_DTLS_MUTUAL_AUTH 77 | #define MODULE_ENABLE_TOOLBOX 78 | #endif 79 | 80 | #ifdef OPTIMIZE_CODE 81 | #define OPTIMIZE_CODE(x) #ifndef x 82 | #define OPTIMIZE_CODE_ENDS(x) #endif 83 | #else 84 | #define OPTIMIZE_CODE(x) 85 | #define OPTIMIZE_CODE_ENDS(x) 86 | #endif 87 | #endif /* _AUTH_LIB_SETTINGS_H_*/ 88 | 89 | /** 90 | * @} 91 | */ 92 | -------------------------------------------------------------------------------- /src/optiga_trustx/BaseErrorCodes.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file defines the error code layering. 28 | * 29 | * \ingroup grMutualAuth 30 | * @{ 31 | */ 32 | 33 | #ifndef _BASEERRORCODE_H_ 34 | #define _BASEERRORCODE_H_ 35 | /* 36 | The following defines the Error code layering for a 4 byte error code. 37 | Each byte is represented as XX, where X being a single nibble. 38 | |8X|XX|XX|XX| 39 | | | | |---->Error Codes 40 | | | |------->Layer 41 | | |---------->Unused 42 | |------------->80 43 | */ 44 | 45 | /// Base Error Code 46 | #define ERROR_CODE_BASE 0x80000000 47 | 48 | ///Base Error code for Comms 49 | #define BASE_ERROR_COMMS (ERROR_CODE_BASE | 0x00000000) 50 | 51 | ///Base Error code for Command Lib 52 | #define BASE_ERROR_CMDLIB (ERROR_CODE_BASE | 0x00000100) 53 | 54 | ///Base Error code for Integration Lib 55 | #define BASE_ERROR_INTLIB (ERROR_CODE_BASE | 0x00000200) 56 | 57 | ///Base Error code for Crypto Lib 58 | #define BASE_ERROR_CRYPTOLIB (ERROR_CODE_BASE | 0x00000300) 59 | 60 | ///Base Error code for Alert 61 | #define BASE_ERROR_ALERT (ERROR_CODE_BASE | 0x00000500) 62 | 63 | ///Base Error code for Handshake Layer 64 | #define BASE_ERROR_HANDSHAKELAYER (ERROR_CODE_BASE | 0x00000600) 65 | 66 | ///Base Error code for Transport Layer 67 | #define BASE_ERROR_TRANSPORTLAYER (ERROR_CODE_BASE | 0x00000700) 68 | 69 | ///Base Error code for OCP 70 | #define BASE_ERROR_OCPLAYER (ERROR_CODE_BASE | 0x00000800) 71 | 72 | ///Base Error code for Record Layer 73 | #define BASE_ERROR_RECORDLAYER (ERROR_CODE_BASE | 0x00000900) 74 | 75 | ///Base Error code for Windowing 76 | #define BASE_ERROR_WINDOW (ERROR_CODE_BASE | 0x00000A00) 77 | 78 | ///Base Error code for Message Layer 79 | #define BASE_ERROR_MESSAGELAYER (ERROR_CODE_BASE | 0x00000B00) 80 | 81 | ///Base Error code for Flight Handler 82 | #define BASE_ERROR_FLIGHT (ERROR_CODE_BASE | 0x00000C00) 83 | 84 | ///Base Error code for Crypto Layer 85 | #define BASE_ERROR_CRYPTO_LAYER (ERROR_CODE_BASE | 0x00000D00) 86 | 87 | ///Base Error code UDP 88 | #define BASE_ERROR_UDP (ERROR_CODE_BASE | 0x00000E00) 89 | 90 | #endif //_BASEERRORCODE_H_ 91 | /** 92 | * @} 93 | */ 94 | -------------------------------------------------------------------------------- /src/optiga_trustx/CryptoLib.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file defines APIs, types and data structures for Crypto Wrapper. 28 | * 29 | * \ingroup grCryptoLibWrapper 30 | * @{ 31 | */ 32 | #ifndef _CRYPTO_LIB_H_ 33 | #define _CRYPTO_LIB_H_ 34 | 35 | #include 36 | #include "Datatypes.h" 37 | #include "CommandLib.h" 38 | /**************************************************************************** 39 | * 40 | * Hash Defines. 41 | * 42 | ****************************************************************************/ 43 | 44 | 45 | 46 | ///Requested operation completed without any error 47 | #define CRYPTO_LIB_OK 0x76428903 48 | 49 | ///Null parameter(s) 50 | #define CRYPTO_LIB_NULL_PARAM 0x80003001 51 | 52 | ///Certificate parse failure 53 | #define CRYPTO_LIB_CERT_PARSE_FAIL (CRYPTO_LIB_NULL_PARAM + 1) 54 | 55 | ///Signature Verification failure 56 | #define CRYPTO_LIB_VERIFY_SIGN_FAIL (CRYPTO_LIB_NULL_PARAM + 2) 57 | 58 | ///SHA256 generation failure 59 | #define CRYPTO_LIB_SHA256_FAIL (CRYPTO_LIB_NULL_PARAM + 3) 60 | 61 | ///Length of input is zero 62 | #define CRYPTO_LIB_LENZERO_ERROR (CRYPTO_LIB_NULL_PARAM + 4) 63 | 64 | ///Length of Parameters are zero 65 | #define CRYPTO_LIB_LENMISMATCH_ERROR (CRYPTO_LIB_NULL_PARAM + 5) 66 | 67 | ///Memory allocation failure 68 | #define CRYPTO_LIB_MEMORY_FAIL (CRYPTO_LIB_NULL_PARAM + 6) 69 | 70 | ///Insufficient memory 71 | #define CRYPTO_LIB_INSUFFICIENT_MEMORY (CRYPTO_LIB_NULL_PARAM + 7) 72 | 73 | ///Generic error condition 74 | #define CRYPTO_LIB_ERROR 0xF1743903 75 | 76 | /**************************************************************************** 77 | * 78 | * Common data structure used across all functions. 79 | * 80 | ****************************************************************************/ 81 | 82 | /** 83 | * \brief Structure which holds parsed certificate data. 84 | */ 85 | typedef struct sCertificate_d 86 | { 87 | ///Public Key 88 | sbBlob_d sPublicKey; 89 | 90 | ///Certificate Signature 91 | sbBlob_d sCertSignature; 92 | 93 | ///Certificate Data start 94 | sbBlob_d sCertData; 95 | }sCertificate_d; 96 | 97 | /** 98 | * \brief Structure which holds data for signature verification 99 | */ 100 | typedef struct sSignatureVector_d 101 | { 102 | ///Public Key 103 | sbBlob_d *psPublicKey; 104 | 105 | /// Signature 106 | sbBlob_d *psSignature; 107 | 108 | /// Message 109 | sbBlob_d *psMessage; 110 | }sSignatureVector_d; 111 | 112 | 113 | /**************************************************************************** 114 | * 115 | * Definitions for Crypto Libray APIs. 116 | * 117 | ****************************************************************************/ 118 | /** 119 | * \brief Parses raw X509 v3 certificate into a custom defined certificate structure. 120 | */ 121 | LIBRARY_EXPORTS int32_t CryptoLib_ParseCertificate(const sbBlob_d *PpsRawCertificate,sCertificate_d *PpsCertificate); 122 | 123 | /** 124 | * \brief Verifies the signature using the given public key. 125 | */ 126 | LIBRARY_EXPORTS int32_t CryptoLib_VerifySignature(const sSignatureVector_d *PpsSignatureVector); 127 | 128 | /** 129 | * \brief Gets Random bytes of data for a given length. 130 | */ 131 | LIBRARY_EXPORTS int32_t CryptoLib_GetRandom(uint16_t PwRandomDataLength,sCmdResponse_d *PpsResponse); 132 | 133 | /** 134 | * \brief Generates seed by concatenating random and the counter and hashing(SHA256) the concatenated value. 135 | */ 136 | LIBRARY_EXPORTS int32_t CryptoLib_GenerateSeed(puint8_t PpbSeed, uint32_t PdwSeedLength); 137 | 138 | /// @cond hidden 139 | /** 140 | * \brief Gets the crypto version number along with build number 141 | */ 142 | LIBRARY_EXPORTS int32_t CryptoLib_WolfSSlVersion(sbBlob_d *PpsVersion); 143 | /// @endcond 144 | 145 | #endif //_CRYPTO_LIB_H_ 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | -------------------------------------------------------------------------------- /src/optiga_trustx/Datatypes.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file contains the type definitions for the fundamental data types. 28 | * 29 | * 30 | * 31 | */ 32 | 33 | #ifndef _DATATYPES_H_ 34 | #define _DATATYPES_H_ 35 | 36 | /****************************************************************************** 37 | * required includes 38 | * Setup common include order for the used types and definitions 39 | ******************************************************************************/ 40 | #include 41 | #include 42 | #include 43 | 44 | /****************************************************************************** 45 | * DataTypes.h 46 | ******************************************************************************/ 47 | 48 | /****************************************************************************** 49 | * defines 50 | ******************************************************************************/ 51 | 52 | /// @cond hidden 53 | #ifndef _OPTIGA_EXPORTS_DLLEXPORT_H_ 54 | #define _OPTIGA_EXPORTS_DLLEXPORT_H_ 55 | 56 | #if defined(WIN32) || defined(_WIN32) 57 | 58 | #ifdef OPTIGA_LIB_EXPORTS 59 | #define LIBRARY_EXPORTS __declspec(dllexport) 60 | #elif defined(OPTIGA_LIB_EXCLUDE_IMPORT) 61 | #define LIBRARY_EXPORTS 62 | #else 63 | #define LIBRARY_EXPORTS __declspec(dllimport) 64 | #endif // OPTIGA_LIB_EXPORTS 65 | 66 | #else 67 | #define LIBRARY_EXPORTS 68 | #endif //WIN32 69 | 70 | #endif /*_OPTIGA_EXPORTS_DLLEXPORT_H_*/ 71 | /// @endcond 72 | 73 | /// Definition for false 74 | #ifndef FALSE 75 | #define FALSE 0 76 | #endif 77 | 78 | /// Definition for true 79 | #ifndef TRUE 80 | #define TRUE 1 81 | #endif 82 | 83 | /****************************************************************************** 84 | * fundamental typedefs 85 | ******************************************************************************/ 86 | 87 | /// Typedef for one byte integer 88 | typedef char char_t; 89 | 90 | /// Typedef for native byte pointer 91 | typedef uint8_t* puint8_t; 92 | 93 | /// Typedef for a 4 byte unsigned integer pointer 94 | typedef uint32_t* puint32_t; 95 | 96 | /// Typedef for unsigned word pointer 97 | typedef uint16_t* puint16_t ; 98 | 99 | /// Typedef for a void 100 | typedef void Void; 101 | 102 | /// Typedef for a double word 103 | typedef double double_t; 104 | 105 | /// Typedef for a float 106 | typedef float float_t; 107 | 108 | /// Typedef for a boolean 109 | typedef uint8_t bool_t; 110 | 111 | /// Typedef for a unsigned long integer 112 | //typedef unsigned int clock_t; 113 | 114 | /// Typedef for Handle 115 | typedef Void* hdl_t; 116 | 117 | /// typedef for host library status 118 | typedef uint16_t host_lib_status_t; 119 | 120 | /** 121 | * \brief Structure to specify a byte stream consisting of length and data 122 | * pointer. 123 | */ 124 | typedef struct sbBlob_d 125 | { 126 | /// Length of the byte stream 127 | uint16_t wLen; 128 | 129 | /// Pointer to byte array which contains the data stream 130 | uint8_t *prgbStream; 131 | } sbBlob_d; 132 | 133 | /// typedef for application event handler 134 | typedef void (*app_event_handler_t)(void* upper_layer_ctx, host_lib_status_t event); 135 | 136 | #ifndef _STATIC_H 137 | #define _STATIC_H static 138 | #endif 139 | #endif /* __DATATYPES_H__ */ 140 | -------------------------------------------------------------------------------- /src/optiga_trustx/DtlsTransportLayer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file defines APIs, types and data structures used in the 28 | * DTLS Transport Layer. 29 | * 30 | * \ingroup grOCP 31 | * @{ 32 | */ 33 | #ifndef __DTLSTL_H__ 34 | #define __DTLSTL_H__ 35 | 36 | #include "pal_socket.h" 37 | #include "OcpTransportLayer.h" 38 | #include "OcpCommonIncludes.h" 39 | 40 | #ifdef MODULE_ENABLE_DTLS_MUTUAL_AUTH 41 | 42 | 43 | 44 | 45 | 46 | /** 47 | * \brief This function initializes transport layer communication structure. 48 | */ 49 | int32_t DtlsTL_Init(sTL_d* PpsTL); 50 | 51 | /** 52 | * \brief This function creates client port. 53 | */ 54 | int32_t DtlsTL_Connect(sTL_d* PpsTL); 55 | 56 | /** 57 | * \brief This function transmits the data to the server from which the data 58 | * was received. 59 | */ 60 | int32_t DtlsTL_Send(const sTL_d* PpsTL,uint8_t* PpbBuffer,uint16_t PwLen); 61 | 62 | /** 63 | * \brief This function receives the data from the server. 64 | */ 65 | int32_t DtlsTL_Recv(const sTL_d* PpsTL,uint8_t* PpbBuffer,uint16_t* PpwLen); 66 | 67 | /** 68 | * \brief This function closes the UDP communication and releases all the resources. 69 | */ 70 | void DtlsTL_Disconnect(sTL_d* PpsTL); 71 | 72 | #endif /* MODULE_ENABLE_DTLS_MUTUAL_AUTH */ 73 | #endif //__DTLSTL_H__ 74 | 75 | /** 76 | * @} 77 | */ 78 | 79 | 80 | -------------------------------------------------------------------------------- /src/optiga_trustx/DtlsWindowing.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file implements the APIs, types and data structures used in the 28 | * for DTLS Windowing. 29 | * 30 | * \ingroup grMutualAuth 31 | * @{ 32 | */ 33 | #ifndef _H_DTLS_WINDOWING_H_ 34 | #define _H_DTLS_WINDOWING_H_ 35 | 36 | #include 37 | #include "Util.h" 38 | #include "OcpCommonIncludes.h" 39 | 40 | #ifdef MODULE_ENABLE_DTLS_MUTUAL_AUTH 41 | /** 42 | * \brief Structure for DTLS Windowing. 43 | */ 44 | typedef struct sWindow_d 45 | { 46 | ///Sequence number 47 | sUint64 sRecvSeqNumber; 48 | ///Higher Bound of window 49 | sUint64 sHigherBound; 50 | ///Lower bound of window 51 | sUint64 sLowerBound; 52 | ///Size of window, value valid through 32 to 64 53 | uint8_t bWindowSize; 54 | ///Window Frame 55 | sUint64 sWindowFrame; 56 | ///Pointer to callback to validate record 57 | int32_t (*fValidateRecord)(const void*); 58 | ///Argument to be passed to callback, if any 59 | void* pValidateArgs; 60 | 61 | }sWindow_d; 62 | 63 | /** 64 | * \brief Structure for Sliding Windowing. 65 | */ 66 | typedef struct sSlideWindow_d 67 | { 68 | ///Sequence number 69 | sUint64 sClientSeqNumber; 70 | ///Pointer to DTLS windowing structure 71 | sWindow_d* psWindow; 72 | 73 | }sSlideWindow_d; 74 | 75 | /** 76 | * \brief Performs record replay detection and rejects the duplicated records. 77 | */ 78 | int32_t DtlsCheckReplay(sWindow_d *PpsWindow); 79 | 80 | #endif /* MODULE_ENABLE_DTLS_MUTUAL_AUTH*/ 81 | #endif //_H_DTLS_WINDOWING_H_ 82 | 83 | /** 84 | * @} 85 | */ 86 | -------------------------------------------------------------------------------- /src/optiga_trustx/ErrorCodes.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file defines the error codes. 28 | * 29 | * 30 | * 31 | */ 32 | 33 | #ifndef _ERRORCODES_H_ 34 | #define _ERRORCODES_H_ 35 | 36 | /****************************************************************************** 37 | * required includes 38 | * Setup common include order for the used types and definitions 39 | ******************************************************************************/ 40 | 41 | /****************************************************************************** 42 | * ErrorCodes.h 43 | ******************************************************************************/ 44 | 45 | /****************************************************************************** 46 | * defines 47 | ******************************************************************************/ 48 | 49 | /// Communication success 50 | #define E_COMMS_SUCCESS 0x00000000 51 | 52 | /// Error code if protocol exit timeout has occurred 53 | #define E_COMMS_TIMEOUT_OCCURRED 0x80000003 54 | 55 | /// Error code if soft reset is not supported by slave 56 | #define E_COMMS_SOFT_RESET_NOT_SUPPORTED 0x80000005 57 | 58 | /// Error code if network layer channel does not mismatch with that of the slave 59 | #define E_COMMS_CHANNEL_NUM_MISMATCH 0x80000006 60 | 61 | /// Error code if packet size could not be set 62 | #define E_COMMS_PACKET_SIZE_NOT_SET 0x80000007 63 | 64 | /// Error code for invalid key 65 | #define E_COMMS_INVALID_KEY 0x80000008 66 | 67 | /// Error code if the input parameter is NULL 68 | #define E_COMMS_PARAMETER_NULL 0x8000000A 69 | 70 | /// Error code for uninitialized protocol 71 | #define E_COMMS_PROTOCOL_NOT_INITIALIZED 0x8000000B 72 | 73 | /// Error code for wrong reset value 74 | #define E_INVALID_RESET_VALUE 0x8000000C 75 | 76 | ///Error code for invalid value for a given key 77 | #define E_INVALID_VALUE_FOR_KEY 0x8000000D 78 | 79 | /// Error code for if the slave doesn't have any data ready 80 | #define E_COMMS_SLAVE_NODATA 0x8000000E 81 | 82 | /// Error code if no channel information is present 83 | #define E_COMMS_NO_CHANNEL_INFORMATION 0x8000000F 84 | 85 | /// Error code if APDU is not present 86 | #define E_COMMS_NO_APDU_PRESENT 0x80000010 87 | 88 | /// Error code for cold reset not supported 89 | #define E_COMMS_COLD_RESET_NOT_SUPPORTED 0x80000011 90 | 91 | /// Error code for partial frame send 92 | #define E_COMMS_PARTIAL_FRAME_SENT 0x80000012 93 | 94 | /// Error code for low level I2C write failed 95 | #define E_COMMS_I2C_WRITE_FAILED 0x80000013 96 | 97 | /// Error code for low level I2C read failed 98 | #define E_COMMS_I2C_READ_FAILED 0x80000014 99 | 100 | /// Error code for buffer size or memory insufficient 101 | #define E_COMMS_INSUFFICIENT_BUF_SIZE 0x80000015 102 | 103 | /// Error code when the value of key is not set 104 | #define E_COMMS_KEY_VALUE_NOT_SET 0x80000016 105 | 106 | /// Error code for setting a property within a session not allowed 107 | #define E_COMMS_SET_PROPERTY_DENIED 0x80000017 108 | 109 | /// Error code for opening the already opened protocol stack 110 | #define E_COMMS_ALREADY_OPEN 0x80000018 111 | 112 | /// Error code for frame buffer overflow(at data link layer) 113 | #define E_COMMS_FRAME_BUFFER_OVERFLOW 0x80000019 114 | 115 | /// Error code for unsupported functionality 116 | #define E_COMMS_FUNCTION_NOT_SUPPORTED 0x8000001A 117 | 118 | /// Error code for invalid channel number 119 | #define E_COMMS_INVALID_CHANNEL_NO 0x8000001B 120 | 121 | /// Error code for insufficient memory 122 | #define E_COMMS_INSUFFICIENT_MEMORY 0x8000001C 123 | 124 | /// Error code if Nack is received 125 | #define E_COMMS_I2C_NACK_RECEIVED 0x8000001D 126 | 127 | /// Error code for I2C Tx/Rx Error 128 | #define E_COMMS_I2C_TXRX_ERROR 0x8000001E 129 | 130 | /// Error code for I2C Tx/Rx Error 131 | #define E_COMMS_I2C_TIMEOUT 0x8000001F 132 | 133 | /// Error code for I2C Tx/Rx Error 134 | #define E_COMMS_INVALID_REQUEST 0x80000020 135 | 136 | /// Error code for communication failure 137 | #define E_COMMS_FAILURE 0xFFFFFFFF 138 | 139 | #endif /* _ERRORCODES_H_ */ 140 | 141 | 142 | -------------------------------------------------------------------------------- /src/optiga_trustx/HardwareCrypto.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file HardwareCrypto.h 26 | * 27 | * \brief This file contains structures and prototypes of hardware crypto layer. 28 | * \ingroup grMutualAuth 29 | * @{ 30 | * 31 | */ 32 | 33 | 34 | #ifndef __HWCRYPTO_H__ 35 | #define __HWCRYPTO_H__ 36 | 37 | #include "OcpCryptoLayer.h" 38 | #include "MemoryMgmt.h" 39 | 40 | /** 41 | * \brief Structure for Hardware Crypto. 42 | */ 43 | typedef struct sHardwareCrypto_d 44 | { 45 | /// Session OID 46 | uint16_t wSessionKeyOID; 47 | }sHardwareCrypto_d; 48 | 49 | 50 | /** 51 | * \brief Initialises the Hardware Crypto Layer. 52 | */ 53 | int32_t HWCL_Init(sCL_d* PpsCL, const void* PpParam); 54 | 55 | /** 56 | * \brief Encrypts the input plain text using Security chip. 57 | */ 58 | int32_t HWCL_Encrypt(const sCL_d* PpsCL, const sbBlob_d* PpsBlobPlainText,sbBlob_d* PpsBlobCipherText,uint16_t PwLen); 59 | 60 | /** 61 | * \brief Decrypts the input cipher text using Security chip. 62 | */ 63 | int32_t HWCL_Decrypt(const sCL_d* PpsCL,const sbBlob_d* PpsBlobCipherText,sbBlob_d* PpsBlobPlainText,uint16_t PwLen); 64 | 65 | /** 66 | * \brief Closes the Crypto layer. 67 | */ 68 | void HWCL_Close(sCL_d* PpsCL); 69 | 70 | #endif //__HWCRYPTO_H__ 71 | -------------------------------------------------------------------------------- /src/optiga_trustx/IntegrationLib.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file defines APIs, types and data structures used in the 28 | * Integration Library implementation. 29 | * 30 | * \ingroup grIntLib 31 | * @{ 32 | */ 33 | 34 | #ifndef _H_INT_LIBRARY_H_ 35 | #define _H_INT_LIBRARY_H_ 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | #include 42 | #include "CommandLib.h" 43 | #include "Datatypes.h" 44 | #include "OcpCommonIncludes.h" 45 | 46 | 47 | 48 | /**************************************************************************** 49 | * 50 | * Definitions 51 | * 52 | ****************************************************************************/ 53 | 54 | ///Requested operation completed without any error 55 | #define INT_LIB_OK 0x75AB1C02 56 | 57 | ///Null parameter(s) 58 | #define INT_LIB_NULL_PARAM 0x80002001 59 | 60 | ///Invalid data in response 61 | #define INT_LIB_INVALID_RESPONSE (INT_LIB_NULL_PARAM + 1) 62 | 63 | ///Invalid access condition 64 | #define INT_LIB_INVALID_AC (INT_LIB_NULL_PARAM + 2) 65 | 66 | ///Length of input is zero 67 | #define INT_LIB_ZEROLEN_ERROR (INT_LIB_NULL_PARAM + 3) 68 | 69 | ///Invalid or unsupported parameter(s) 70 | #define INT_LIB_INVALID_PARAM (INT_LIB_NULL_PARAM + 4) 71 | 72 | ///Invalid Length 73 | #define INT_LIB_INVALID_LENGTH (INT_LIB_NULL_PARAM + 5) 74 | 75 | ///Malloc Failures 76 | #define INT_LIB_MALLOC_FAILURE (INT_LIB_NULL_PARAM + 6) 77 | 78 | ///Certificate format is not valid 79 | #define INT_LIB_INVALID_CERTIFICATE_FORMAT (INT_LIB_NULL_PARAM + 7) 80 | 81 | ///General error 82 | #define INT_LIB_ERROR 0xFE5A5502 83 | 84 | /** 85 | * \brief Structure to specify general purpose data object parameters for read 86 | */ 87 | typedef struct sReadGPData_d 88 | { 89 | ///OID of data object 90 | uint16_t wOID; 91 | 92 | ///Offset within the data object 93 | uint16_t wOffset; 94 | 95 | ///Number of data bytes to read 96 | uint16_t wLength; 97 | }sReadGPData_d; 98 | 99 | /** 100 | * \brief Structure to specify general purpose data object parameters for write 101 | */ 102 | typedef struct sWriteGPData_d 103 | { 104 | ///OID of data object 105 | uint16_t wOID; 106 | 107 | ///Offset within the data object 108 | uint16_t wOffset; 109 | 110 | ///Number of data bytes to write 111 | uint16_t wLength; 112 | 113 | ///Data bytes to be written 114 | uint8_t *prgbData; 115 | 116 | ///Write option 117 | eWriteOption_d eWriteOption; 118 | }sWriteGPData_d; 119 | 120 | 121 | /** 122 | * \brief Structure to specify inputs for One-Way Authentication Public Key Scheme 123 | */ 124 | typedef struct sOneWayAuth_d 125 | { 126 | ///CA Certificate 127 | sbBlob_d sCaCert; 128 | 129 | ///OID of device certificate signed by the CA certificate 130 | uint16_t wOIDDevCertificate; 131 | 132 | ///OID of private key paired with the public key in the device certificate 133 | uint16_t wOIDDevPrivKey; 134 | 135 | ///Length of the challenge 136 | uint16_t wChallengeLen; 137 | }sOneWayAuth_d; 138 | 139 | 140 | #ifdef MODULE_ENABLE_ONE_WAY_AUTH 141 | /** 142 | * \brief Performs One-Way Authentication Public Key Scheme to prove the authenticity of the 143 | * device which incorporates Security Chip. 144 | */ 145 | LIBRARY_EXPORTS int32_t IntLib_Authenticate(const sOneWayAuth_d *PpsOneWayAuth); 146 | 147 | #endif /* MODULE_ENABLE_ONE_WAY_AUTH*/ 148 | 149 | #ifdef MODULE_ENABLE_READ_WRITE 150 | /** 151 | * \brief Read the specified general purpose data object from the Security Chip. 152 | */ 153 | LIBRARY_EXPORTS int32_t IntLib_ReadGPData(const sReadGPData_d *PpsGDVector, sbBlob_d *PpsGPData); 154 | 155 | /** 156 | * \brief Write to the specified general purpose data object to the Security Chip. 157 | */ 158 | LIBRARY_EXPORTS int32_t IntLib_WriteGPData(const sWriteGPData_d *PpsGDVector); 159 | 160 | #endif /* MODULE_ENABLE_READ_WRITE*/ 161 | 162 | #ifdef __cplusplus 163 | } 164 | #endif 165 | 166 | #endif //_H_INT_LIBRARY_H_ 167 | 168 | /** 169 | * @} 170 | */ 171 | -------------------------------------------------------------------------------- /src/optiga_trustx/MemoryMgmt.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file defines the memory management related macros. 28 | * 29 | * 30 | * \ingroup grMutualAuth 31 | * 32 | */ 33 | 34 | #ifndef _MEMMGMT_H_ 35 | #define _MEMMGMT_H_ 36 | 37 | ///Malloc function to allocate the heap memory 38 | #define OCP_MALLOC(size) malloc(size) 39 | 40 | ///Malloc function to allocate the heap memory 41 | #define OCP_CALLOC(block,blocksize) calloc(block,blocksize) 42 | 43 | ///To free the allocated memory 44 | #define OCP_FREE(node) free(node) 45 | 46 | ///To copy the data from source to destination 47 | #define OCP_MEMCPY(dst,src,size) memcpy(dst,src,size) 48 | 49 | ///To copy the data from source to destination 50 | #define OCP_MEMSET(src,val,size) memset(src,val,size) 51 | 52 | #endif /* _MEMMGMT_H_ */ 53 | 54 | -------------------------------------------------------------------------------- /src/optiga_trustx/MessageLayer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file defines APIs, types and data structures used in the 28 | * (D)TLS Message Layer implementation. 29 | * 30 | * \ingroup grMutualAuth 31 | * @{ 32 | */ 33 | #ifndef __MSGLAYER_H__ 34 | #define __MSGLAYER_H__ 35 | 36 | #include 37 | #include "DtlsHandshakeProtocol.h" 38 | #include "Datatypes.h" 39 | #include "OcpCommon.h" 40 | #include "CommandLib.h" 41 | 42 | #ifdef MODULE_ENABLE_DTLS_MUTUAL_AUTH 43 | 44 | /**************************************************************************** 45 | * 46 | * API Error Codes 47 | * 48 | ****************************************************************************/ 49 | 50 | /// Successful execution 51 | #define OCP_ML_OK 0x75268512 52 | 53 | /// Failure in execution 54 | #define OCP_ML_ERROR 0xF4350158 55 | 56 | ///Null Parameter(s) 57 | #define OCP_ML_NULL_PARAM BASE_ERROR_MESSAGELAYER 58 | 59 | ///Zero Length input parameter(s) 60 | #define OCP_ML_ZERO_LEN (BASE_ERROR_MESSAGELAYER + 1) 61 | 62 | ///Insufficient memory 63 | #define OCP_ML_INSUFFICIENT_MEMORY (BASE_ERROR_MESSAGELAYER + 2) 64 | 65 | ///Invalid unix time 66 | #define OCP_ML_INVALID_UNIXTIME (BASE_ERROR_MESSAGELAYER + 3) 67 | 68 | ///Invalid certificate type 69 | #define OCP_ML_INVALID_CERTTYPE (BASE_ERROR_MESSAGELAYER + 4) 70 | 71 | ///Invalid certificate type 72 | #define OCP_ML_MALLOC_FAILURE (BASE_ERROR_MESSAGELAYER + 5) 73 | 74 | /**************************************************************************** 75 | * 76 | * Definitions related to (D)TLS commands. 77 | * 78 | ****************************************************************************/ 79 | /// @cond hidden 80 | 81 | ///Timeout expired 82 | #define OCP_ML_TIMEOUT (OCP_ML_NULL_PARAM + 3) 83 | 84 | ///Length of Handshake message header 85 | #define MSG_HEADER_LEN 12 86 | 87 | ///Over head length for command library 88 | #define OVERHEAD_LEN 21 //APDU (4) + Message header len(12) + Tag enconding len(5) 89 | 90 | //Macro to validate the time out 91 | //#define TIMEELAPSED(bStartTime,bTimeout) ((clock_t)(Util_GetTicks() - bStartTime) > (clock_t)(bTimeout*1000)) 92 | #define TIMEELAPSED(bStartTime,bTimeout) (((clock_t)(pal_os_timer_get_time_in_milliseconds() - bStartTime) < (clock_t)(bTimeout*1000))?TRUE:FALSE) 93 | /// @endcond 94 | 95 | /**************************************************************************** 96 | * 97 | * Common data structures used across all functions. 98 | * 99 | ****************************************************************************/ 100 | 101 | /** 102 | * \brief Structure to hold the information required for Get message call back to allocate memory. 103 | */ 104 | typedef struct sCBGetMsg_d 105 | { 106 | ///Indicate to allocate memory only for first time 107 | uint8_t bRepeatCall; 108 | ///Pointer to the allocated memory where the message is stored 109 | uint8_t* pbActualMsg; 110 | ///Size of the allocated memory 111 | uint16_t dwMsgLen; 112 | 113 | }sCBGetMsg_d; 114 | 115 | /** 116 | * \brief Structure to hold the information required for Message Layer. 117 | */ 118 | typedef struct sMessageLayer_d 119 | { 120 | ///(D)TLS Session ID 121 | uint16_t wSessionID; 122 | ///Maximum PMTU 123 | uint16_t wMaxPmtu; 124 | ///Record Layer 125 | sConfigRL_d* psConfigRL; 126 | ///Certificate Type used for Authentication 127 | uint16_t wOIDDevCertificate; 128 | ///Callback function pointer to get unixtime 129 | fGetUnixTime_d pfGetUnixTIme; 130 | } sMessageLayer_d; 131 | 132 | /** 133 | * \brief Provide Handshake message using Command Library.
134 | */ 135 | int32_t MsgLayer_FormMessage(eMsgType_d eMsgType,const sMessageLayer_d* PpsMessageLayer, sbBlob_d* PpsMessage); 136 | 137 | /** 138 | * \brief Process Handshake message using Command Library.
139 | */ 140 | int32_t MsgLayer_ProcessMessage(eMsgType_d eMsgType,const sMessageLayer_d* PpsMessageLayer, sbBlob_d* PpsMessage); 141 | 142 | /** 143 | * \brief Encrypt the Data using Command Library.
144 | */ 145 | int32_t MsgLayer_EncryptMessage(const sbBlob_d* PpsBlobPlainMsg, sbBlob_d* PpsBlobCipherMsg, uint16_t PwInDataLen, uint16_t PwSessionKeyOID); 146 | 147 | /** 148 | * \brief Decrypt the Data using Command Library.
149 | */ 150 | int32_t MsgLayer_DecryptMessage(const sbBlob_d* PpsBlobCipherMsg, sbBlob_d* PpsBlobPlainMsg, uint16_t PwInDataLen, uint16_t PwSessionKeyOID); 151 | 152 | #endif /* MODULE_ENABLE_DTLS_MUTUAL_AUTH*/ 153 | 154 | #endif //__MSGLAYER_H__ 155 | /** 156 | * @} 157 | */ 158 | -------------------------------------------------------------------------------- /src/optiga_trustx/OcpCommon.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file defines APIs, types and data structures used in the 28 | * OCP configurations. 29 | * 30 | * \ingroup grMutualAuth 31 | * @{ 32 | */ 33 | 34 | #ifndef __OCPCOMMON_H__ 35 | #define __OCPCOMMON_H__ 36 | 37 | #include "Datatypes.h" 38 | #include "OcpRecordLayer.h" 39 | #include "MemoryMgmt.h" 40 | #include "OcpCommonIncludes.h" 41 | #include "pal_os_timer.h" 42 | 43 | /// Successful execution 44 | #define OCP_HL_OK 0x75236512 45 | 46 | /// Failure in execution 47 | #define OCP_HL_ERROR 0XF3CA3154 48 | 49 | ///Null Parameter(s) 50 | #define OCP_HL_NULL_PARAM BASE_ERROR_HANDSHAKELAYER 51 | 52 | ///Length of input is zero 53 | #define OCP_HL_LENZERO_ERROR (BASE_ERROR_HANDSHAKELAYER + 1) 54 | 55 | ///Maximum PMTU value 56 | #define MAX_PMTU 1500 57 | 58 | ///Minimum PMTU Value 59 | #define MIN_PMTU 296 60 | 61 | ///Buffer size to hold the received data 62 | #define TLBUFFER_SIZE 1500 63 | 64 | ///Overhead length for encrypted message 65 | #define ENCRYPTED_APP_OVERHEAD (UDP_RECORD_OVERHEAD + EXPLICIT_NOUNCE_LENGTH + MAC_LENGTH ) 66 | 67 | ///Macro to get the Maximum length of the Application data which can be sent 68 | #define MAX_APP_DATALEN(PhAppOCPCtx) ((((sAppOCPCtx_d*)PhAppOCPCtx)->sHandshake.wMaxPmtu) - ENCRYPTED_APP_OVERHEAD) 69 | 70 | /**************************************************************************** 71 | * 72 | * Common data structure used across all functions. 73 | * 74 | ****************************************************************************/ 75 | 76 | 77 | ///Function pointer to get the unix time 78 | typedef int32_t (*fGetUnixTime_d)(uint32_t*); 79 | 80 | /** 81 | * \brief Enumeration to specify the mode of operation of OCP 82 | */ 83 | typedef enum eMode_d 84 | { 85 | ///Client 86 | eClient = 0x24, 87 | 88 | ///Server 89 | eServer = 0x81 90 | }eMode_d; 91 | 92 | 93 | /** 94 | * \brief Enumeration to specify the Protocol version 95 | */ 96 | typedef enum eProtVersion_d 97 | { 98 | ///DTLS 1.2 99 | eDTLS_1_2, 100 | ///TLS 1.2 101 | eTLS_1_2 102 | }eProtVersion_d; 103 | 104 | /** 105 | * \brief Enum for Mutual Authentication states 106 | */ 107 | typedef enum eAuthState_d 108 | { 109 | //Authentication parameters initialized 110 | eAuthInitialised, 111 | //Authentication started 112 | eAuthStarted, 113 | //Authentication is completed 114 | eAuthCompleted, 115 | //Authentication session is closed 116 | eAuthSessionClosed 117 | }eAuthState_d; 118 | 119 | /** 120 | * \brief Structure containing Handshake related data. 121 | */ 122 | typedef struct sHandshake_d 123 | { 124 | ///Mode of operation,Client/Server 125 | eMode_d eMode; 126 | ///Maximum PMTU 127 | uint16_t wMaxPmtu; 128 | ///Pointer to Record Layer 129 | sConfigRL_d* psConfigRL; 130 | ///Pointer to Logger 131 | sLogger_d phLogger; 132 | ///To indicate fatal alert 133 | bool_t fFatalError; 134 | //Indicates status of Mutual Authentication 135 | eAuthState_d eAuthState; 136 | ///Handle to OCP 137 | hdl_t PhAppOCPCtx; 138 | ///Session OID 139 | uint16_t wSessionOID; 140 | ///Certificate Type used for Authentication 141 | uint16_t wOIDDevCertificate; 142 | ///Private key used for authentication 143 | uint16_t wOIDDevPrivKey; 144 | ///Callback function pointer to get unixtime 145 | fGetUnixTime_d pfGetUnixTIme; 146 | }sHandshake_d; 147 | 148 | 149 | /** 150 | * \brief Enum for Flights 151 | */ 152 | typedef enum eFlight_d 153 | { 154 | ///Flight 0 155 | eFlight0 = 0, 156 | ///Flight 1 157 | eFlight1 = 1, 158 | ///Flight 2 159 | eFlight2 = 2, 160 | ///Flight 3 161 | eFlight3 = 3, 162 | ///Flight 4 163 | eFlight4 = 4, 164 | ///Flight 5 165 | eFlight5 = 5, 166 | ///Flight 6 167 | eFlight6 = 6, 168 | ///Default 169 | eDefault 170 | }eFlight_d; 171 | 172 | ///Function pointer to perform Handshake 173 | typedef int32_t (*fPerformHandshake_d)(sHandshake_d*); 174 | 175 | #endif //__OCPCOMMON_H__ 176 | /** 177 | * @} 178 | */ 179 | -------------------------------------------------------------------------------- /src/optiga_trustx/OcpCommonIncludes.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file includes the commonly used header files. 28 | * 29 | * \ingroup grMutualAuth 30 | * @{ 31 | */ 32 | 33 | #ifndef _COMMONCONFIG_H_ 34 | #define _COMMONCONFIG_H_ 35 | 36 | #include "AuthLibSettings.h" 37 | #include "BaseErrorCodes.h" 38 | #include "Version.h" 39 | 40 | #endif //_COMMONCONFIG_H_ 41 | /** 42 | * @} 43 | */ 44 | -------------------------------------------------------------------------------- /src/optiga_trustx/OcpCryptoLayer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file defines APIs, types and data structures used in the 28 | * OCP Crypto Layer. 29 | * 30 | * \ingroup grMutualAuth 31 | * @{ 32 | */ 33 | 34 | #ifndef __OCPCRYPTOLAYER_H__ 35 | #define __OCPCRYPTOLAYER_H__ 36 | 37 | #include "Datatypes.h" 38 | #include "Logger.h" 39 | #include "OcpCommonIncludes.h" 40 | 41 | /**************************************************************************** 42 | * 43 | * Common data structure used across all functions. 44 | * 45 | ****************************************************************************/ 46 | 47 | /// Failure in execution 48 | #define OCP_CL_ERROR 0x51667F82 49 | 50 | ///Successful Execution 51 | #define OCP_CL_OK 0x4C36F247 52 | 53 | ///Null paramter 54 | #define OCP_CL_NULL_PARAM BASE_ERROR_CRYPTO_LAYER 55 | 56 | ///Malloc Failure in Crypto 57 | #define OCP_CL_MALLOC_FAILURE (BASE_ERROR_CRYPTO_LAYER + 1) 58 | 59 | ///Zero Length Failure 60 | #define OCP_CL_ZERO_LEN (BASE_ERROR_CRYPTO_LAYER + 2) 61 | 62 | ///Insufficient memory 63 | #define OCP_CL_INSUFFICIENT_MEMORY (BASE_ERROR_CRYPTO_LAYER + 3) 64 | 65 | /** 66 | * \brief Structure containing Crypto Layer information. 67 | */ 68 | typedef struct sCL_d 69 | { 70 | ///Handle to Crypto 71 | hdl_t phCryptoHdl; 72 | 73 | //Pointer to Logger 74 | sLogger_d sLogger; 75 | }sCL_d; 76 | 77 | 78 | ///Function pointer to Initialize Record Layer. 79 | typedef int32_t (*fCLInit)(sCL_d* psCL, const void*); 80 | 81 | ///Function pointer for Record Layer Send 82 | typedef int32_t (*fCLEncrypt)(const sCL_d* psCL, const sbBlob_d* PpsBlobPlainText,sbBlob_d* PpsBlobCipherText,uint16_t wLen); 83 | 84 | ///Function pointer for Record Layer Receive 85 | typedef int32_t (*fCLDecrypt)(const sCL_d* psCL, const sbBlob_d* PpsBlobCipherText,sbBlob_d* PpsBlobPlainText,uint16_t wLen); 86 | 87 | ///Function pointer to close Record Layer 88 | typedef void (*fCLClose)(sCL_d* psCL); 89 | 90 | /** 91 | * \brief Structure to configure Crypto Layer. 92 | */ 93 | typedef struct sConfigCL_d 94 | { 95 | ///Function pointer to Init Crypto layer 96 | fCLInit pfInit; 97 | 98 | ///Function pointer to Close Crypto layer 99 | fCLClose pfClose; 100 | 101 | ///Function pointer to Encrypt data via Crypto layer 102 | fCLEncrypt pfEncrypt; 103 | 104 | ///Function pointer to Decrypt data via Crypto layer 105 | fCLDecrypt pfDecrypt; 106 | 107 | ///Crypto Handle 108 | sCL_d sCL; 109 | }sConfigCL_d; 110 | 111 | #endif //__OCPCRYPTOLAYER_H__ 112 | /** 113 | * @} 114 | */ 115 | -------------------------------------------------------------------------------- /src/optiga_trustx/OcpRecordLayer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file defines APIs, types and data structures used in the 28 | * OCP Record Layer. 29 | * 30 | * \ingroup grMutualAuth 31 | * @{ 32 | */ 33 | 34 | #ifndef __OCPRECORDLAYER_H__ 35 | #define __OCPRECORDLAYER_H__ 36 | 37 | #include "OcpTransportLayer.h" 38 | #include "OcpCryptoLayer.h" 39 | #include "Logger.h" 40 | 41 | 42 | /// Failure in execution 43 | #define OCP_RL_ERROR 0x55667F82 44 | 45 | /// Internal status for success. 46 | #define OCP_RL_OK 0x297D9015 47 | 48 | ///Invalid record length 49 | #define OCP_RL_INVALID_RECORD_LENGTH BASE_ERROR_RECORDLAYER 50 | 51 | ///Invalid record content type 52 | #define OCP_RL_INVALID_CONTENTTYPE (BASE_ERROR_RECORDLAYER + 1) 53 | 54 | ///Invalid decrypt payload lenght 55 | #define OCP_RL_INVALID_DEC_PAYLOAD_LEN (BASE_ERROR_RECORDLAYER + 2) 56 | 57 | ///Invalid protocol version 58 | #define OCP_RL_INVALID_PROTOCOL_VERSION (BASE_ERROR_RECORDLAYER + 3) 59 | 60 | ///Incorrect epoch 61 | #define OCP_RL_INCORRECT_EPOCH (BASE_ERROR_RECORDLAYER + 4) 62 | 63 | ///Record length mismatch 64 | #define OCP_RL_RECORD_LEN_MISMATCH (BASE_ERROR_RECORDLAYER + 5) 65 | 66 | ///Bad record 67 | #define OCP_RL_BAD_RECORD (BASE_ERROR_RECORDLAYER + 6) 68 | 69 | /// No data 70 | #define OCP_RL_NO_DATA (BASE_ERROR_RECORDLAYER + 7) 71 | 72 | /// Data length is greater than PMTU 73 | #define OCP_RL_LEN_GREATER_PMTU (BASE_ERROR_RECORDLAYER + 8) 74 | 75 | ///Invalid record instance 76 | #define OCP_RL_INVALID_INSTANCE (BASE_ERROR_RECORDLAYER + 9) 77 | 78 | ///Alert record received 79 | #define OCP_RL_ALERT_RECEIVED (BASE_ERROR_RECORDLAYER + 10) 80 | 81 | ///Alert record received 82 | #define OCP_RL_APPDATA_RECEIVED (BASE_ERROR_RECORDLAYER + 11) 83 | 84 | ///Malloc Failure 85 | #define OCP_RL_MALLOC_FAILURE (BASE_ERROR_RECORDLAYER + 12) 86 | 87 | ///Cipher Spec Content Spec 88 | #define CONTENTTYPE_CIPHER_SPEC 0x14 89 | ///Alert Content Spec 90 | #define CONTENTTYPE_ALERT 0x15 91 | ///Handshake Content Spec 92 | #define CONTENTTYPE_HANDSHAKE 0x16 93 | ///Application Data Content Spec 94 | #define CONTENTTYPE_APP_DATA 0x17 95 | 96 | ///UDP REcord overhead length 97 | #define UDP_RECORD_OVERHEAD 41 //20(IP Header) + 8(UDP Header) + 13(RL Header) 98 | 99 | ///Length of the MAC generated for encrypted message 100 | #define MAC_LENGTH 8 101 | 102 | ///Length of Explicit Nounce 103 | #define EXPLICIT_NOUNCE_LENGTH 8 104 | 105 | /**************************************************************************** 106 | * 107 | * Common data structure used across all functions. 108 | * 109 | ****************************************************************************/ 110 | 111 | /** 112 | * \brief Structure containing Record Layer information. 113 | */ 114 | typedef struct sRL_d 115 | { 116 | ///Handle to Record layer structure #sRecordLayer_d 117 | hdl_t phRLHdl; 118 | 119 | ///Pointer to Configured TL 120 | sConfigTL_d* psConfigTL; 121 | 122 | ///Pointer to Configured Crypto 123 | sConfigCL_d* psConfigCL; 124 | 125 | ///Structure that holds logger parameters 126 | sLogger_d sLogger; 127 | 128 | ///Indicates if memory needs to be allocated or not 129 | uint8_t bMemoryAllocated; 130 | 131 | ///Content Type 132 | uint8_t bContentType; 133 | 134 | ///Indicate Multiple record received 135 | uint8_t bMultipleRecord; 136 | 137 | ///Indicates if the send flight is retransmitted 138 | bool_t fRetransmit; 139 | 140 | ///Indicates if the record received is encrypted or not 141 | uint8_t bDecRecord; 142 | 143 | ///Indicates if the record received is Change cipher spec 144 | uint8_t bRecvCCSRecord; 145 | 146 | ///pointer to a Next record 147 | uint8_t* pNextRecord; 148 | 149 | ///Pointer to callback to change the server epoch state 150 | Void (*fServerStateTrn)(const void*); 151 | }sRL_d; 152 | 153 | 154 | ///Function pointer to Initialize Record Layer. 155 | typedef int32_t (*fRLInit)(sRL_d* psRL); 156 | 157 | ///Function pointer for Record Layer Send 158 | typedef int32_t (*fRLSend)(sRL_d* psRL, uint8_t* pbBuffer,uint16_t wLen); 159 | 160 | ///Function pointer for Record Layer Receive 161 | typedef int32_t (*fRLRecv)(sRL_d* psRL,uint8_t* pbBuffer,uint16_t* pwLen); 162 | 163 | ///Function pointer to close Record Layer 164 | typedef void (*fRLClose)(sRL_d* psRL); 165 | 166 | /** 167 | * \brief Structure to configure Record Layer. 168 | */ 169 | typedef struct sConfigRL_d 170 | { 171 | ///Function pointer to Init RL 172 | fRLInit pfInit; 173 | 174 | ///Function pointer to CloseRL 175 | fRLClose pfClose; 176 | 177 | ///Function pointer to Send via RL 178 | fRLSend pfSend; 179 | 180 | ///Function pointer to Receive via RL 181 | fRLRecv pfRecv; 182 | 183 | ///Record Layer 184 | sRL_d sRL; 185 | }sConfigRL_d; 186 | 187 | #endif //__OCPRECORDLAYER_H__ 188 | /** 189 | * @} 190 | */ 191 | -------------------------------------------------------------------------------- /src/optiga_trustx/OcpTransportLayer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file defines APIs, types and data structures used in the 28 | * OCP Transport Layer. 29 | * 30 | * \ingroup grMutualAuth 31 | * @{ 32 | */ 33 | 34 | #ifndef __OCPTRANSPORTLAYER_H__ 35 | #define __OCPTRANSPORTLAYER_H__ 36 | 37 | #include "Datatypes.h" 38 | #include "Logger.h" 39 | #include "OcpCommonIncludes.h" 40 | 41 | ///General error 42 | #define OCP_TL_ERROR 0xF1267AB3 43 | 44 | ///Successful execution 45 | #define OCP_TL_OK 0x72309781 46 | 47 | ///Null Parameter(S) 48 | #define OCP_TL_NULL_PARAM BASE_ERROR_TRANSPORTLAYER 49 | 50 | ///Null Parameter(S) 51 | #define OCP_TL_BINDING_FAILURE (BASE_ERROR_TRANSPORTLAYER + 1) 52 | 53 | ///NO Data received 54 | #define OCP_TL_NO_DATA (BASE_ERROR_TRANSPORTLAYER + 2) 55 | 56 | ///Malloc failure 57 | #define OCP_TL_MALLOC_FAILURE (BASE_ERROR_TRANSPORTLAYER + 3) 58 | 59 | /**************************************************************************** 60 | * 61 | * Common data structure used across all functions. 62 | * 63 | ****************************************************************************/ 64 | 65 | /** 66 | * \brief Enumeration to represent transport layer communication state 67 | */ 68 | typedef enum eConnectionState_d 69 | { 70 | ///Connected to network 71 | eConnected = 0x01, 72 | 73 | ///Disconnected from network 74 | eDisconnected = 0x02 75 | }eConnectionState_d; 76 | 77 | 78 | /** 79 | * \brief This structure contains Ethernet communication data 80 | */ 81 | typedef enum eReceiveCall_d 82 | { 83 | ///Blocking Ethernet call 84 | eBlocking = 0x10, 85 | 86 | ///Non Blocking Ethernet call 87 | eNonBlocking = 0x20 88 | }eReceiveCall_d; 89 | 90 | /** 91 | * \brief Structure holding Transport Layer Information. 92 | */ 93 | typedef struct sTL_d 94 | { 95 | ///Handle to transport layer 96 | hdl_t phTLHdl; 97 | 98 | ///Port Number 99 | uint16_t wPort; 100 | 101 | ///IP Address 102 | char_t* pzIpAddress; 103 | 104 | ///Transport Layer Timeout 105 | uint16_t wTimeout; 106 | 107 | ///Connection state 108 | eConnectionState_d eIsConnected; 109 | 110 | ///Call type Blocking or NonBlocking 111 | eReceiveCall_d eCallType; 112 | 113 | //Structure that holds logger parameters 114 | sLogger_d sLogger; 115 | }sTL_d; 116 | 117 | ///Function pointer for Transport Layer Init. 118 | typedef int32_t (*fTLInit)(sTL_d* psTL); 119 | 120 | ///Function pointer for Transport Layer Connect. 121 | typedef int32_t (*fTLConnect)(sTL_d* psTL); 122 | 123 | ///Function pointer for Transport Layer Disconnect 124 | typedef void (*fTLDisconnect)(sTL_d* psTL); 125 | 126 | ///Function pointer for Transport Layer Send 127 | typedef int32_t (*fTLSend)(const sTL_d* psTL,uint8_t* pbBuffer,uint16_t wLen); 128 | 129 | ///Function pointer for Transport Layer Receive 130 | typedef int32_t (*fTLRecv)(const sTL_d* psTL,uint8_t* pbBuffer,uint16_t* pwLen); 131 | 132 | /** 133 | * \brief Structure to configure Transport Layer. 134 | */ 135 | typedef struct sConfigTL_d 136 | { 137 | ///Function pointer to Init via TL 138 | fTLInit pfInit; 139 | 140 | ///Function pointer to Send via TL 141 | fTLSend pfSend; 142 | 143 | ///Function pointer to Receive via TL 144 | fTLRecv pfRecv; 145 | 146 | ///Function pointer to Connect to TL 147 | fTLConnect pfConnect; 148 | 149 | ///Function pointer to Disconnect from TL 150 | fTLDisconnect pfDisconnect; 151 | 152 | ///Transport Layer 153 | sTL_d sTL; 154 | }sConfigTL_d; 155 | 156 | #endif //__OCPTRANSPORTLAYER_H__ 157 | /** 158 | * @} 159 | */ 160 | -------------------------------------------------------------------------------- /src/optiga_trustx/UDPErrorCodes.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file contains a UDP error codes. 28 | * 29 | * 30 | * \ingroup grMutualAuth 31 | * @{ 32 | * 33 | */ 34 | 35 | #ifndef _UDPERRCODES_H_ 36 | #define _UDPERRCODES_H_ 37 | 38 | ///Failure to allocate memory 39 | #define E_COMMS_UDP_ALLOCATE_FAILURE 0x80000100 40 | 41 | ///Binding failure to a port 42 | #define E_COMMS_UDP_BINDING_FAILURE 0x80000101 43 | 44 | ///No data present to send 45 | #define E_COMMS_UDP_NO_DATA_TO_SEND 0x80000102 46 | 47 | ///No data received from the target 48 | #define E_COMMS_UDP_NO_DATA_RECEIVED 0x80000103 49 | 50 | ///Failure to route the UDP packet 51 | #define E_COMMS_UDP_ROUTING_FAILURE 0x80000104 52 | 53 | ///Failure to deallocate the memory 54 | #define E_COMMS_UDP_DEALLOCATION_FAILURE 0x80000105 55 | 56 | ///Copy to the buffer failure 57 | #define E_COMMS_UDP_COPY_BUFFER_FAILURE 0x80000106 58 | 59 | ///UDP connect failure 60 | #define E_COMMS_UDP_CONNECT_FAILURE 0x80000107 61 | 62 | #endif /* _UDPERRCODES_H_ */ 63 | -------------------------------------------------------------------------------- /src/optiga_trustx/Util.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file contains utility functions 28 | * 29 | * 30 | * 31 | */ 32 | #ifndef _UTIL_H_ 33 | #define _UTIL_H_ 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | 40 | #include "Datatypes.h" 41 | 42 | 43 | 44 | ///Greater than 45 | #define GREATER_THAN 0x00000001 46 | 47 | ///Lesser than 48 | #define LESSER_THAN 0x00000002 49 | 50 | ///Equal 51 | #define EQUAL 0x00000000 52 | 53 | /// Default Low bound value value 54 | #define DEFAULT_LOWBOUND_DOUBLEWORD 0x00000000 55 | 56 | /// Mask double word value 57 | #define MASK_DOUBLE_WORD 0xFFFFFFFF 58 | 59 | ///Word bit size 60 | #define WORD_SIZE 32 61 | 62 | ///Successful Execution 63 | #define UTIL_SUCCESS 0x00000000 64 | 65 | ///Execution Failure 66 | #define UTIL_ERROR 0xFFFFFFFF 67 | 68 | ///Least significant bit set to high 69 | #define LEAST_SIGNIFICANT_BIT_HIGH 0x00000001 70 | 71 | ///Least significant bit set to high 72 | #define MOST_SIGNIFICANT_BIT_HIGH 0x80000000 73 | 74 | /** 75 | * \brief structure to store the record sequence number 76 | */ 77 | typedef struct sUint64 78 | { 79 | ///Higher 32 bit of the record sequence number 80 | uint32_t dwHigherByte; 81 | 82 | ///Lower 32 bit of the record sequence number 83 | uint32_t dwLowerByte; 84 | }sUint64; 85 | 86 | /** 87 | * \brief The function compares two uint64 data type.
88 | */ 89 | int32_t CompareUint64(const sUint64 *PpsSrc1, const sUint64 *PpsSrc2); 90 | 91 | /** 92 | * \brief Calculates the difference between the two uint64 data.
93 | */ 94 | int32_t SubtractUint64(const sUint64 *PpsMinuend, const sUint64 *PpsSubtrahend,sUint64 *PpsDifference); 95 | 96 | /** 97 | * \brief Adds two uint64 data.
98 | */ 99 | int32_t AddUint64(const sUint64 *PpsSrc1, const sUint64 *PpsSrc2,sUint64 *PpsDest); 100 | 101 | /** 102 | * \brief Increments uint64 data.
103 | */ 104 | int32_t IncrementUint64(sUint64 *PpsSrc1); 105 | 106 | /** 107 | * \brief Converts byte array to uint64.
108 | */ 109 | int32_t GetUint64(sUint64 *PpsOut,const uint8_t* pbVal,uint16_t wLen); 110 | 111 | /** 112 | * \brief To Slide the window by shift count.
113 | */ 114 | int32_t ShiftLeftUint64(sUint64 *PpsWindow, sUint64 PsShiftCount, uint8_t PWindowSize, uint8_t PbMaxWindowSize); 115 | 116 | /** 117 | * \brief To set a bit in the sUnit64 data.
118 | */ 119 | int32_t Utility_SetBitUint64(sUint64* PprgbData, uint8_t bWindowSize, uint8_t bBitPosition); 120 | 121 | /** 122 | * \brief Prepares uint16 [Big endian] type value from the buffer.
123 | */ 124 | uint16_t Utility_GetUint16 (const uint8_t* PprgbData); 125 | 126 | /** 127 | * \brief Prepares uint32 [Big endian] type value from the buffer .
128 | */ 129 | uint32_t Utility_GetUint32 (const uint8_t* PprgbData); 130 | 131 | /** 132 | * \brief Copies 2 bytes of uint16 type value to the buffer
133 | */ 134 | void Utility_SetUint16 (puint8_t PprgbData,uint16_t PwValue); 135 | 136 | /** 137 | * \brief Prepares uint24 [Big endian] type value from the buffer .
138 | */ 139 | uint32_t Utility_GetUint24 (const uint8_t* PprgbData); 140 | 141 | /** 142 | * \brief Copies LSB 3 bytes of uint32 [Big endian] type value to the buffer and store.
143 | */ 144 | void Utility_SetUint24 (uint8_t* PprgbData,uint32_t Pdwvalue); 145 | 146 | /** 147 | * \brief Copies LSB 4 bytes of uint32 [Big endian] type value to the buffer and store.
148 | */ 149 | void Utility_SetUint32 (uint8_t* PprgbData,uint32_t Pdwvalue); 150 | 151 | /** 152 | * \brief Copies the data from source buffer to destination buffer.
153 | */ 154 | void Utility_Memmove(puint8_t PprgbDestBuf, const puint8_t PprgbSrcBuf, uint16_t PwLength); 155 | 156 | #ifdef __cplusplus 157 | } 158 | #endif 159 | 160 | #endif //_UTIL_H_ 161 | 162 | -------------------------------------------------------------------------------- /src/optiga_trustx/Version.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file defines the Host Library version number. 28 | * 29 | */ 30 | 31 | #ifndef _VERSION_H_ 32 | #define _VERSION_H_ 33 | 34 | /// Version information of the Host Library 35 | #define VERSION_HOST_LIBRARY "Ver 1.50.1141" 36 | 37 | #endif //_VERSION_H_ 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/optiga_trustx/ifx_i2c.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file ifx_i2c.h 26 | * 27 | * \brief This file defines the API prototype for IFX I2C protocol v1.65 wrapper. 28 | * 29 | * \ingroup grIFXI2C 30 | * @{ 31 | */ 32 | 33 | #ifndef _IFXI2C_H_ 34 | #define _IFXI2C_H_ 35 | 36 | 37 | /*********************************************************************************************************************** 38 | * HEADER FILES 39 | **********************************************************************************************************************/ 40 | #include "Datatypes.h" 41 | #include "ifx_i2c_config.h" 42 | /*********************************************************************************************************************** 43 | * MACROS 44 | ***********************************************************************************************************************/ 45 | 46 | /*********************************************************************************************************************** 47 | 48 | * ENUMS 49 | ***********************************************************************************************************************/ 50 | 51 | /** @brief IFX I2C Reset types */ 52 | typedef enum ifx_i2c_reset_type 53 | { 54 | /// Cold reset. Both reset pin and vdd pin are toggled low and then high 55 | IFX_I2C_COLD_RESET = 0U, 56 | /// Soft reset. 0x0000 is written to IFX-I2C Soft reset register 57 | IFX_I2C_SOFT_RESET = 1U, 58 | /// Warm reset. Only reset pin is toggled low and then high 59 | IFX_I2C_WARM_RESET = 2U 60 | } ifx_i2c_reset_type_t; 61 | /*********************************************************************************************************************** 62 | * DATA STRUCTURES 63 | ***********************************************************************************************************************/ 64 | /*********************************************************************************************************************** 65 | * API PROTOTYPES 66 | **********************************************************************************************************************/ 67 | 68 | /** 69 | * \brief Initializes the IFX I2C protocol stack for a given context. 70 | */ 71 | host_lib_status_t ifx_i2c_open(ifx_i2c_context_t *p_ctx); 72 | 73 | /** 74 | * \brief Resets the I2C slave. 75 | */ 76 | host_lib_status_t ifx_i2c_reset(ifx_i2c_context_t *p_ctx, ifx_i2c_reset_type_t reset_type); 77 | 78 | /** 79 | * \brief Sends a command and receives a response for the command. 80 | */ 81 | host_lib_status_t ifx_i2c_transceive(ifx_i2c_context_t *p_ctx,const uint8_t* p_data, const uint16_t* p_data_length, 82 | uint8_t* p_buffer, uint16_t* p_buffer_len); 83 | 84 | /** 85 | * \brief Closes the IFX I2C protocol stack for a given context. 86 | */ 87 | host_lib_status_t ifx_i2c_close(ifx_i2c_context_t *p_ctx); 88 | 89 | /** 90 | * \brief Sets the slave address of the target device. 91 | */ 92 | host_lib_status_t ifx_i2c_set_slave_address(ifx_i2c_context_t *p_ctx, uint8_t slave_address, uint8_t persistent); 93 | 94 | #endif /* _IFXI2C_H_ */ 95 | /** 96 | * @} 97 | **/ 98 | 99 | -------------------------------------------------------------------------------- /src/optiga_trustx/ifx_i2c_config.c: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file ifx_i2c_config.c 26 | * 27 | * \brief This file provides the ifx i2c platform specific context configurations. 28 | * 29 | * \ingroup grIFXI2C 30 | * @{ 31 | */ 32 | 33 | /*********************************************************************************************************************** 34 | * HEADER FILES 35 | **********************************************************************************************************************/ 36 | // Protocol Stack Includes 37 | #include "pal_ifx_i2c_config.h" 38 | #include "ifx_i2c_config.h" 39 | 40 | /*********************************************************************************************************************** 41 | * MACROS 42 | **********************************************************************************************************************/ 43 | 44 | 45 | /*********************************************************************************************************************** 46 | * ENUMS 47 | **********************************************************************************************************************/ 48 | /*********************************************************************************************************************** 49 | * DATA STRUCTURES 50 | ***********************************************************************************************************************/ 51 | 52 | /** @brief This is IFX I2C context. Only one context is supported per slave.*/ 53 | //lint --e{785} suppress "Only required fields are initialized, the rest are handled by consumer of this structure" 54 | ifx_i2c_context_t ifx_i2c_context_0 = 55 | { 56 | /// Slave address 57 | 0x30, 58 | /// i2c-master frequency 59 | 400, 60 | /// IFX-I2C frame size 61 | 0x0019, 62 | /// Vdd pin 63 | &optiga_vdd_0, 64 | /// Reset pin 65 | &optiga_reset_0, 66 | /// optiga pal i2c context 67 | &optiga_pal_i2c_context_0 68 | }; 69 | 70 | /*********************************************************************************************************************** 71 | * GLOBAL 72 | ***********************************************************************************************************************/ 73 | /*********************************************************************************************************************** 74 | * LOCAL ROUTINES 75 | ***********************************************************************************************************************/ 76 | /*********************************************************************************************************************** 77 | * API PROTOTYPES 78 | **********************************************************************************************************************/ 79 | 80 | /** 81 | * @} 82 | **/ 83 | -------------------------------------------------------------------------------- /src/optiga_trustx/ifx_i2c_data_link_layer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file ifx_i2c_data_link_layer.h 26 | * 27 | * \brief This file defines the API prototype for data link layer of the Infineon I2C Protocol Stack library. 28 | * 29 | * \ingroup grIFXI2C 30 | * @{ 31 | */ 32 | 33 | #ifndef _IFX_I2C_DATA_LINK_LAYER_H_ 34 | #define _IFX_I2C_DATA_LINK_LAYER_H_ 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | /*********************************************************************************************************************** 41 | * HEADER FILES 42 | **********************************************************************************************************************/ 43 | #include "ifx_i2c_config.h" 44 | 45 | /*********************************************************************************************************************** 46 | * MACROS 47 | **********************************************************************************************************************/ 48 | /** @brief Error event propagated to upper layer */ 49 | #define IFX_I2C_DL_EVENT_ERROR (0x01) 50 | /** @brief Transmit success event propagated to upper layer (bit field 1) */ 51 | #define IFX_I2C_DL_EVENT_TX_SUCCESS (0x02) 52 | /** @brief Receive success event propagated to upper layer (bit field 3)*/ 53 | #define IFX_I2C_DL_EVENT_RX_SUCCESS (0x04) 54 | 55 | /*********************************************************************************************************************** 56 | * ENUMS 57 | **********************************************************************************************************************/ 58 | /*********************************************************************************************************************** 59 | * DATA STRUCTURES 60 | ***********************************************************************************************************************/ 61 | /*********************************************************************************************************************** 62 | * API PROTOTYPES 63 | **********************************************************************************************************************/ 64 | /** 65 | * @brief Function for initializing the module. 66 | * 67 | * Function initializes and enables the module and registers 68 | * an event handler to receive events from this module. 69 | * @attention This function must be called before using the module. 70 | * 71 | * @param[in,out] p_ctx Pointer to ifx i2c context. 72 | * @param[in] handler Function pointer to the event handler of the upper layer. 73 | * 74 | * @retval IFX_I2C_STACK_SUCCESS If initialization was successful. 75 | * @retval IFX_I2C_STACK_ERROR If the module is already initialized. 76 | */ 77 | host_lib_status_t ifx_i2c_dl_init(ifx_i2c_context_t *p_ctx,ifx_i2c_event_handler_t handler); 78 | 79 | /** 80 | * @brief Function for sending a frame. 81 | * 82 | * Asynchronous function to send a frame. The function returns immediately. 83 | * One of the following events is propagated to the event handler registered 84 | * with @ref ifx_i2c_dl_init. 85 | * 86 | * @param[in,out] p_ctx Pointer to ifx i2c context. 87 | * @param[in] frame_len Frame length. 88 | * 89 | * @retval IFX_I2C_STACK_SUCCESS If function was successful. 90 | * @retval IFX_I2C_STACK_ERROR If the module is busy. 91 | */ 92 | host_lib_status_t ifx_i2c_dl_send_frame(ifx_i2c_context_t *p_ctx,uint16_t frame_len); 93 | 94 | /** 95 | * @brief Function for receiving a frame. 96 | * 97 | * Asynchronous function to receive a frame. The function returns immediately. 98 | * One of the following events is propagated to the event handler registered 99 | * with @ref ifx_i2c_dl_init. 100 | * 101 | * @param[in,out] p_ctx Pointer to ifx i2c context. 102 | * 103 | * @retval IFX_I2C_STACK_SUCCESS If function was successful. 104 | * @retval IFX_I2C_STACK_ERROR If the module is busy. 105 | */ 106 | host_lib_status_t ifx_i2c_dl_receive_frame(ifx_i2c_context_t *p_ctx); 107 | 108 | #ifdef __cplusplus 109 | } 110 | #endif 111 | 112 | #endif /* _IFX_I2C_DATA_LINK_LAYER_H_ */ 113 | 114 | 115 | /** 116 | * @} 117 | **/ 118 | -------------------------------------------------------------------------------- /src/optiga_trustx/ifx_i2c_physical_layer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file ifx_i2c_physical_layer.h 26 | * 27 | * \brief This file defines the API prototype for physical layer of the Infineon I2C Protocol Stack library. 28 | * 29 | * \ingroup grIFXI2C 30 | * @{ 31 | */ 32 | 33 | #ifndef _IFX_I2C_PHYSICAL_LAYER_H_ 34 | #define _IFX_I2C_PHYSICAL_LAYER_H_ 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | /*********************************************************************************************************************** 41 | * HEADER FILES 42 | **********************************************************************************************************************/ 43 | #include "ifx_i2c_config.h" 44 | 45 | /*********************************************************************************************************************** 46 | * MACROS 47 | **********************************************************************************************************************/ 48 | /*********************************************************************************************************************** 49 | * ENUMS 50 | **********************************************************************************************************************/ 51 | /*********************************************************************************************************************** 52 | * DATA STRUCTURES 53 | ***********************************************************************************************************************/ 54 | /*********************************************************************************************************************** 55 | * API PROTOTYPES 56 | **********************************************************************************************************************/ 57 | /** 58 | * @brief Function for initializing the module. 59 | * 60 | * Function initializes and enables the module and registers 61 | * an event handler to receive events from this module. 62 | * @attention This function must be called before using the module. 63 | * 64 | * @param[in,out] p_ctx Pointer to ifx i2c context. 65 | * @param[in] handler Function pointer to the event handler of the upper layer. 66 | * 67 | * @retval IFX_I2C_STACK_SUCCESS If initialization was successful. 68 | * @retval IFX_I2C_STACK_ERROR If the module is already initialized. 69 | */ 70 | host_lib_status_t ifx_i2c_pl_init(ifx_i2c_context_t *p_ctx,ifx_i2c_event_handler_t handler); 71 | 72 | /** 73 | * @brief Function for sending a frame. 74 | * 75 | * Asynchronous function to send a frame. The function returns immediately. 76 | * One of the following events is propagated to the event handler registered 77 | * with @ref ifx_i2c_pl_init 78 | * 79 | * @param[in,out] p_ctx Pointer to ifx i2c context. 80 | * @param[in] p_frame Buffer containing the frame. 81 | * @param[in] frame_len Frame length. 82 | * 83 | * @retval IFX_I2C_STACK_SUCCESS If function was successful. 84 | * @retval IFX_I2C_STACK_ERROR If the module is busy. 85 | */ 86 | host_lib_status_t ifx_i2c_pl_send_frame(ifx_i2c_context_t *p_ctx,uint8_t* p_frame, uint16_t frame_len); 87 | 88 | /** 89 | * @brief Function for receiving a frame. 90 | * 91 | * Asynchronous function to receive a frame. The function returns immediately. 92 | * One of the following events is propagated to the event handler registered 93 | * with @ref ifx_i2c_pl_init 94 | * 95 | * @param[in] p_ctx Pointer to ifx i2c context. 96 | * 97 | * @retval IFX_I2C_STACK_SUCCESS If function was successful. 98 | * @retval IFX_I2C_STACK_ERROR If the module is busy. 99 | */ 100 | host_lib_status_t ifx_i2c_pl_receive_frame(ifx_i2c_context_t *p_ctx); 101 | 102 | 103 | /** 104 | * @brief Function for setting slave address. 105 | * 106 | * Synchronous function to set slave address. 107 | * 108 | * @param[in] p_ctx Pointer to ifx i2c context. 109 | *\param[in] slave_address Holds new slave address[7 Bit] to be set. 110 | * \param[in] persistent 0 - To set the Slave address until next reset.
111 | * Non-zero - To set the slave address to persistent memory. 112 | * 113 | * @retval IFX_I2C_STACK_SUCCESS If function was successful. 114 | * @retval IFX_I2C_STACK_ERROR If setting slave address fails. 115 | */ 116 | host_lib_status_t ifx_i2c_pl_write_slave_address(ifx_i2c_context_t *p_ctx, uint8_t slave_address, uint8_t storage_type); 117 | /** 118 | * @} 119 | **/ 120 | 121 | #ifdef __cplusplus 122 | } 123 | #endif 124 | #endif /* _IFX_I2C_PHYSICAL_LAYER_H_ */ 125 | -------------------------------------------------------------------------------- /src/optiga_trustx/ifx_i2c_transport_layer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file ifx_i2c_transport_layer.h 26 | * 27 | * \brief This file defines the API prototype for transport layer of the Infineon I2C Protocol Stack library. 28 | * 29 | * \ingroup grIFXI2C 30 | * @{ 31 | */ 32 | 33 | #ifndef _IFX_I2C_TRANSPORT_LAYER_H_ 34 | #define _IFX_I2C_TRANSPORT_LAYER_H_ 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | /*********************************************************************************************************************** 41 | * HEADER FILES 42 | **********************************************************************************************************************/ 43 | #include "ifx_i2c_config.h" 44 | #include "pal_os_timer.h" 45 | 46 | /*********************************************************************************************************************** 47 | * MACROS 48 | **********************************************************************************************************************/ 49 | /*********************************************************************************************************************** 50 | * ENUMS 51 | **********************************************************************************************************************/ 52 | /*********************************************************************************************************************** 53 | * DATA STRUCTURES 54 | ***********************************************************************************************************************/ 55 | /*********************************************************************************************************************** 56 | * API PROTOTYPES 57 | **********************************************************************************************************************/ 58 | /** 59 | * @brief Function for initializing the module. 60 | * 61 | * Function initializes and enables the module and registers 62 | * an event handler to receive events from this module. 63 | * @attention This function must be called before using the module. 64 | * 65 | * @param[in,out] p_ctx Pointer to ifx i2c context. 66 | * @param[in] handler Function pointer to the event handler of the upper layer. 67 | * 68 | * @retval IFX_I2C_STACK_SUCCESS If initialization was successful. 69 | * @retval IFX_I2C_STACK_ERROR If the module is already initialized. 70 | */ 71 | host_lib_status_t ifx_i2c_tl_init(ifx_i2c_context_t *p_ctx,ifx_i2c_event_handler_t handler); 72 | 73 | /** 74 | * @brief Function to transmit and receive a packet. 75 | * 76 | * Asynchronous function to send and receive a packet. 77 | * The function returns immediately. One of the following events is 78 | * propagated to the event handler registered with @ref ifx_i2c_tl_init 79 | * 80 | * @param[in,out] p_ctx Pointer to ifx i2c context. 81 | * @param[in] p_packet Buffer containing the packet header. 82 | * @param[in] packet_len Packet header length. 83 | * @param[in] p_recv_packet Buffer containing the packet payload. 84 | * @param[in] recv_packet_len Packet payload length. 85 | * 86 | * @retval IFX_I2C_STACK_SUCCESS If function was successful. 87 | * @retval IFX_I2C_STACK_ERROR If the module is busy. 88 | */ 89 | host_lib_status_t ifx_i2c_tl_transceive(ifx_i2c_context_t *p_ctx,uint8_t* p_packet, uint16_t packet_len, 90 | uint8_t* p_recv_packet, uint16_t* recv_packet_len); 91 | 92 | /** 93 | * @} 94 | **/ 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | #endif /* IFX_I2C_TRANSPORT_LAYER_H__ */ 99 | -------------------------------------------------------------------------------- /src/optiga_trustx/optiga_comms.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file implements optiga comms abstraction layer for IFX I2C Protocol. 28 | * 29 | * \ingroup grOptigaComms 30 | * @{ 31 | */ 32 | 33 | #ifndef _OPTIGA_COMMS_H_ 34 | #define _OPTIGA_COMMS_H_ 35 | /********************************************************************************************************************** 36 | * HEADER FILES 37 | *********************************************************************************************************************/ 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | #include "Datatypes.h" 44 | 45 | /********************************************************************************************************************** 46 | * MACROS 47 | *********************************************************************************************************************/ 48 | 49 | /// Succesfull execution 50 | #define OPTIGA_COMMS_SUCCESS 0x0000 51 | /// Error in execution 52 | #define OPTIGA_COMMS_ERROR 0x0001 53 | /// Busy, doing operation 54 | #define OPTIGA_COMMS_BUSY 0x0002 55 | 56 | /********************************************************************************************************************** 57 | * DATA STRUCTURES 58 | *********************************************************************************************************************/ 59 | 60 | /** @brief optiga comms structure */ 61 | typedef struct optiga_comms 62 | { 63 | /// Comms structure pointer 64 | void* comms_ctx; 65 | /// Upper layer contect 66 | void* upper_layer_ctx; 67 | /// Upper layer handler 68 | app_event_handler_t upper_layer_handler; 69 | /// Optiga comms state 70 | uint8_t state; 71 | }optiga_comms_t; 72 | 73 | extern optiga_comms_t optiga_comms; 74 | 75 | /********************************************************************************************************************** 76 | * API Prototypes 77 | *********************************************************************************************************************/ 78 | 79 | /** 80 | * \brief Opens the communication channel with OPTIGA. 81 | */ 82 | LIBRARY_EXPORTS host_lib_status_t optiga_comms_open(optiga_comms_t *p_ctx); 83 | 84 | /** 85 | * \brief Resets the OPTIGA. 86 | */ 87 | LIBRARY_EXPORTS host_lib_status_t optiga_comms_reset(optiga_comms_t *p_ctx,uint8_t reset_type); 88 | 89 | /** 90 | * \brief Sends and receives the APDU. 91 | */ 92 | LIBRARY_EXPORTS host_lib_status_t optiga_comms_transceive(optiga_comms_t *p_ctx,const uint8_t* p_data, 93 | const uint16_t* p_data_length, 94 | uint8_t* p_buffer, uint16_t* p_buffer_len); 95 | 96 | /** 97 | * \brief Closes the communication channel with OPTIGA. 98 | */ 99 | LIBRARY_EXPORTS host_lib_status_t optiga_comms_close(optiga_comms_t *p_ctx); 100 | 101 | 102 | #ifdef __cplusplus 103 | } 104 | #endif 105 | /** 106 | * @} 107 | */ 108 | 109 | #endif /*_OPTIGA_COMMS_H_*/ 110 | 111 | -------------------------------------------------------------------------------- /src/optiga_trustx/pal.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file implements the prototype declarations of platform abstraction layer 28 | * 29 | * \ingroup grPAL 30 | * @{ 31 | */ 32 | 33 | 34 | #ifndef _PAL_H_ 35 | #define _PAL_H_ 36 | 37 | /********************************************************************************************************************** 38 | * HEADER FILES 39 | *********************************************************************************************************************/ 40 | #include "Datatypes.h" 41 | 42 | /********************************************************************************************************************** 43 | * pal.h 44 | *********************************************************************************************************************/ 45 | 46 | /********************************************************************************************************************** 47 | * MACROS 48 | *********************************************************************************************************************/ 49 | 50 | /// PAL API execution is successful 51 | #define PAL_STATUS_SUCCESS (0x0000) 52 | /// PAL API execution failed 53 | #define PAL_STATUS_FAILURE (0x0001) 54 | /// PAL I2C is busy 55 | #define PAL_STATUS_I2C_BUSY (0x0002) 56 | 57 | /********************************************************************************************************************** 58 | * ENUMS 59 | *********************************************************************************************************************/ 60 | /** 61 | * \brief PAL return status. 62 | */ 63 | typedef uint16_t pal_status_t; 64 | 65 | /********************************************************************************************************************** 66 | * API Prototypes 67 | *********************************************************************************************************************/ 68 | 69 | #endif /* _PAL_H_ */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | -------------------------------------------------------------------------------- /src/optiga_trustx/pal_gpio.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file implements the prototype declarations of pal gpio 28 | * 29 | * \ingroup grPAL 30 | * @{ 31 | */ 32 | 33 | #ifndef _PAL_GPIO_H_ 34 | #define _PAL_GPIO_H_ 35 | 36 | /********************************************************************************************************************** 37 | * HEADER FILES 38 | *********************************************************************************************************************/ 39 | 40 | #include "pal.h" 41 | 42 | /********************************************************************************************************************** 43 | * MACROS 44 | *********************************************************************************************************************/ 45 | 46 | 47 | /********************************************************************************************************************** 48 | * ENUMS 49 | *********************************************************************************************************************/ 50 | 51 | 52 | /********************************************************************************************************************** 53 | * DATA STRUCTURES 54 | *********************************************************************************************************************/ 55 | 56 | /** 57 | * \brief Structure defines the PAL GPIO configuration. 58 | */ 59 | typedef struct pal_gpio 60 | { 61 | /// Pointer to gpio platform specific context/structure 62 | void* p_gpio_hw; 63 | 64 | } pal_gpio_t; 65 | 66 | /********************************************************************************************************************** 67 | * API Prototypes 68 | *********************************************************************************************************************/ 69 | 70 | #ifdef __cplusplus 71 | extern "C" { 72 | #endif 73 | 74 | /** 75 | * \brief Sets the gpio pin to high state. 76 | */ 77 | void pal_gpio_set_high(const pal_gpio_t* p_gpio_context); 78 | 79 | /** 80 | * \brief Sets the gpio pin to Low state. 81 | */ 82 | void pal_gpio_set_low(const pal_gpio_t* p_gpio_context); 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif /* _PAL_GPIO_H_ */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | -------------------------------------------------------------------------------- /src/optiga_trustx/pal_gpio_arduino.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file implements the platform abstraction layer APIs for gpio. 28 | * 29 | * \ingroup grPAL 30 | * @{ 31 | */ 32 | 33 | 34 | /********************************************************************************************************************** 35 | * HEADER FILES 36 | *********************************************************************************************************************/ 37 | 38 | #include "Arduino.h" 39 | #include "pal_gpio.h" 40 | 41 | /********************************************************************************************************************** 42 | * MACROS 43 | *********************************************************************************************************************/ 44 | 45 | /********************************************************************************************************************** 46 | * LOCAL DATA 47 | *********************************************************************************************************************/ 48 | 49 | /********************************************************************************************************************** 50 | * LOCAL ROUTINES 51 | *********************************************************************************************************************/ 52 | 53 | /********************************************************************************************************************** 54 | * API IMPLEMENTATION 55 | *********************************************************************************************************************/ 56 | 57 | /** 58 | * Sets the gpio pin to high state 59 | * 60 | * API Details: 61 | * The API sets the pin high, only if the pin is assigned to a valid gpio context.
62 | * Otherwise the API returns without any faliure status.
63 | * 64 | *\param[in] p_gpio_context Pointer to pal layer gpio context 65 | * 66 | * 67 | */ 68 | void pal_gpio_set_high(const pal_gpio_t* p_gpio_context) 69 | { 70 | // if ((p_gpio_context != NULL) && (p_gpio_context->p_gpio_hw != NULL)) 71 | // { 72 | // DIGITAL_IO_SetOutputHigh(p_gpio_context->p_gpio_hw); 73 | // } 74 | } 75 | 76 | /** 77 | * Sets the gpio pin to low state 78 | * 79 | * API Details: 80 | * The API set the pin low, only if the pin is assigned to a valid gpio context.
81 | * Otherwise the API returns without any faliure status.
82 | * 83 | *\param[in] p_gpio_context Pointer to pal layer gpio context 84 | * 85 | */ 86 | void pal_gpio_set_low(const pal_gpio_t* p_gpio_context) 87 | { 88 | // if ((p_gpio_context != NULL) && (p_gpio_context->p_gpio_hw != NULL)) 89 | // { 90 | // DIGITAL_IO_SetOutputLow(p_gpio_context->p_gpio_hw); 91 | // } 92 | } 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | -------------------------------------------------------------------------------- /src/optiga_trustx/pal_i2c.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file implements the prototype declarations of pal i2c 28 | * 29 | * \ingroup grPAL 30 | * @{ 31 | */ 32 | 33 | #ifndef _PAL_I2C_H_ 34 | #define _PAL_I2C_H_ 35 | 36 | /********************************************************************************************************************** 37 | * HEADER FILES 38 | *********************************************************************************************************************/ 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | #include "pal.h" 44 | 45 | /********************************************************************************************************************** 46 | * MACROS 47 | *********************************************************************************************************************/ 48 | /// Event returned when I2C master completes execution 49 | #define PAL_I2C_EVENT_SUCCESS (0x0000) 50 | /// Event returned when I2C master operation fails 51 | #define PAL_I2C_EVENT_ERROR (0x0001) 52 | /// Event returned when lower level I2C bus is busy 53 | #define PAL_I2C_EVENT_BUSY (0x0002) 54 | 55 | /********************************************************************************************************************** 56 | * ENUMS 57 | *********************************************************************************************************************/ 58 | 59 | /********************************************************************************************************************** 60 | * DATA STRUCTURES 61 | *********************************************************************************************************************/ 62 | /** @brief PAL I2C context structure */ 63 | typedef struct pal_i2c 64 | { 65 | /// Pointer to I2C master platform specific context 66 | void* p_i2c_hw_config; 67 | /// I2C slave address 68 | uint8_t slave_address; 69 | /// Pointer to store the callers context information 70 | void* upper_layer_ctx; 71 | /// Pointer to store the callers handler 72 | void* upper_layer_event_handler; 73 | 74 | } pal_i2c_t; 75 | 76 | /********************************************************************************************************************** 77 | * API Prototypes 78 | *********************************************************************************************************************/ 79 | /** 80 | * @brief Initializes the I2C master. 81 | */ 82 | pal_status_t pal_i2c_init(const pal_i2c_t* p_i2c_context); 83 | 84 | /** 85 | * @brief Sets the I2C Master bitrate 86 | */ 87 | pal_status_t pal_i2c_set_bitrate(const pal_i2c_t* p_i2c_context, uint16_t bitrate); 88 | 89 | //Dileep: "write on I2C bus" --> "write to I2C bus" 90 | /** 91 | * @brief Writes on I2C bus. 92 | */ 93 | pal_status_t pal_i2c_write(pal_i2c_t* p_i2c_context, uint8_t* p_data , uint16_t length); 94 | 95 | /** 96 | * @brief Reads from I2C bus. 97 | */ 98 | pal_status_t pal_i2c_read(pal_i2c_t* p_i2c_context, uint8_t* p_data , uint16_t length); 99 | 100 | /** 101 | * @brief De-initializes the I2C master. 102 | */ 103 | pal_status_t pal_i2c_deinit(const pal_i2c_t* p_i2c_context); 104 | 105 | #ifdef __cplusplus 106 | } 107 | #endif 108 | 109 | #endif /* _PAL_I2C_H_ */ 110 | 111 | /** 112 | * @} 113 | */ 114 | 115 | -------------------------------------------------------------------------------- /src/optiga_trustx/pal_ifx_i2c_config.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file implements the platform abstraction layer extern declarations for ifx i2c. 28 | * 29 | * \ingroup grPAL 30 | * @{ 31 | */ 32 | 33 | #ifndef _PAL_IFX_I2C_CONFIG_H_ 34 | #define _PAL_IFX_I2C_CONFIG_H_ 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | /********************************************************************************************************************** 41 | * HEADER FILES 42 | *********************************************************************************************************************/ 43 | #include "pal.h" 44 | #include "pal_i2c.h" 45 | #include "pal_gpio.h" 46 | 47 | /********************************************************************************************************************** 48 | * MACROS 49 | *********************************************************************************************************************/ 50 | 51 | 52 | /********************************************************************************************************************** 53 | * ENUMS 54 | *********************************************************************************************************************/ 55 | 56 | /********************************************************************************************************************** 57 | * PAL extern definitions for IFX I2C 58 | *********************************************************************************************************************/ 59 | extern pal_i2c_t optiga_pal_i2c_context_0; 60 | extern pal_gpio_t optiga_vdd_0; 61 | extern pal_gpio_t optiga_reset_0; 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif /* _PAL_IFX_I2C_CONFIG_H_ */ 68 | 69 | /** 70 | * @} 71 | */ 72 | -------------------------------------------------------------------------------- /src/optiga_trustx/pal_ifx_i2c_config_arduino.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file implements platform abstraction layer configurations for ifx i2c protocol. 28 | * 29 | * \ingroup grPAL 30 | * @{ 31 | */ 32 | 33 | /********************************************************************************************************************** 34 | * HEADER FILES 35 | *********************************************************************************************************************/ 36 | #include "Arduino.h" 37 | #include "Wire.h" 38 | 39 | #include "pal_gpio.h" 40 | #include "pal_i2c.h" 41 | 42 | /********************************************************************************************************************* 43 | * pal ifx i2c instance 44 | *********************************************************************************************************************/ 45 | /** 46 | * \brief PAL I2C configuration for OPTIGA. 47 | */ 48 | pal_i2c_t optiga_pal_i2c_context_0 = 49 | { 50 | /// Pointer to I2C master platform specific context 51 | static_cast(&Wire), 52 | /// Slave address 53 | 0x30, 54 | /// Upper layer context 55 | NULL, 56 | /// Callback event handler 57 | NULL 58 | }; 59 | 60 | /********************************************************************************************************************* 61 | * PAL GPIO configurations defined for XMC4500 62 | *********************************************************************************************************************/ 63 | /** 64 | * \brief PAL vdd pin configuration for OPTIGA. 65 | */ 66 | pal_gpio_t optiga_vdd_0 = 67 | { 68 | // Platform specific GPIO context for the pin used to toggle Vdd. 69 | NULL 70 | }; 71 | 72 | /** 73 | * \brief PAL reset pin configuration for OPTIGA. 74 | */ 75 | pal_gpio_t optiga_reset_0 = 76 | { 77 | // Platform specific GPIO context for the pin used to toggle Reset. 78 | NULL 79 | }; 80 | 81 | 82 | /** 83 | * @} 84 | */ 85 | 86 | -------------------------------------------------------------------------------- /src/optiga_trustx/pal_os_event.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file implements the prototype declarations of pal os event 28 | * 29 | * \ingroup grPAL 30 | * @{ 31 | */ 32 | 33 | 34 | #ifndef _PAL_OS_EVENT_H_ 35 | #define _PAL_OS_EVENT_H_ 36 | 37 | /********************************************************************************************************************** 38 | * HEADER FILES 39 | *********************************************************************************************************************/ 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | #include "Datatypes.h" 45 | 46 | /********************************************************************************************************************** 47 | * MACROS 48 | *********************************************************************************************************************/ 49 | 50 | 51 | /********************************************************************************************************************** 52 | * ENUMS 53 | *********************************************************************************************************************/ 54 | 55 | /********************************************************************************************************************** 56 | * PAL extern definitions 57 | *********************************************************************************************************************/ 58 | 59 | /** 60 | * @brief typedef for Callback function when timer elapses. 61 | */ 62 | typedef void (*register_callback)(void*); 63 | 64 | 65 | /** 66 | * @brief Platform specific event processing functions. 67 | */ 68 | void pal_os_event_process(void); 69 | 70 | /** 71 | * @brief Callback registration function to trigger once when timer expires. 72 | */ 73 | void pal_os_event_register_callback_oneshot(register_callback callback, void* callback_args, uint32_t time_us); 74 | 75 | #ifdef __cplusplus 76 | } 77 | #endif 78 | 79 | #endif //_PAL_OS_EVENT_H_ 80 | 81 | /** 82 | * @} 83 | */ 84 | -------------------------------------------------------------------------------- /src/optiga_trustx/pal_os_event_arduino.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file implements the platform abstraction layer APIs for os event/scheduler. 28 | * 29 | * \ingroup grPAL 30 | * @{ 31 | */ 32 | 33 | /********************************************************************************************************************** 34 | * HEADER FILES 35 | *********************************************************************************************************************/ 36 | #include 37 | #include "../simple_timer/SimpleTimer.h" 38 | #include "pal_os_event.h" 39 | 40 | /********************************************************************************************************************** 41 | * MACROS 42 | *********************************************************************************************************************/ 43 | 44 | /********************************************************************************************************************* 45 | * LOCAL DATA 46 | *********************************************************************************************************************/ 47 | /// @cond hidden 48 | /// Callback function when timer elapses 49 | static volatile register_callback callback_registered = NULL; 50 | /// Pointer to store upper layer callback context (For example: Ifx i2c context) 51 | static void * callback_ctx; 52 | 53 | // the timer object 54 | SimpleTimer callback_timer; 55 | 56 | 57 | /** 58 | * Timer callback handler. 59 | * 60 | * This get called from the TIMER elapse event.
61 | * Once the timer expires, the registered callback funtion gets called from the timer event handler, if 62 | * the call back is not NULL.
63 | * 64 | *\param[in] args Callback argument 65 | * 66 | */ 67 | void scheduler_timer_isr(void) 68 | { 69 | register_callback callback; 70 | 71 | if (callback_registered) 72 | { 73 | 74 | callback = callback_registered; 75 | callback_registered = NULL; 76 | callback((void*)callback_ctx); 77 | 78 | } 79 | } 80 | 81 | /** 82 | * Platform specific event processing functions. 83 | *
84 | * 85 | * API Details: 86 | * This function calls platform specific event processing events routine 87 | * 88 | */ 89 | void pal_os_event_process(void) 90 | { 91 | callback_timer.run(); 92 | delay(1); 93 | } 94 | 95 | /** 96 | * Platform specific event call back registration function to trigger once when timer expires. 97 | *
98 | * 99 | * API Details: 100 | * This function registers the callback function supplied by the caller.
101 | * It triggers a timer with the supplied time interval in microseconds.
102 | * Once the timer expires, the registered callback function gets called.
103 | * 104 | * \param[in] callback Callback function pointer 105 | * \param[in] callback_args Callback arguments 106 | * \param[in] time_us time in micro seconds to trigger the call back 107 | * 108 | */ 109 | void pal_os_event_register_callback_oneshot(register_callback callback, 110 | void* callback_args, 111 | uint32_t time_us) 112 | { 113 | callback_registered = callback; 114 | callback_ctx = callback_args; 115 | 116 | callback_timer.setTimeout(time_us/1000, scheduler_timer_isr); 117 | } 118 | 119 | /** 120 | * @} 121 | */ 122 | 123 | -------------------------------------------------------------------------------- /src/optiga_trustx/pal_os_random.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file implements the prototype declarations of pal os random functionalities 28 | * 29 | * \ingroup grPAL 30 | * @{ 31 | */ 32 | 33 | #ifndef _PAL_OS_RANDOM_H_ 34 | #define _PAL_OS_RANDOM_H_ 35 | 36 | /********************************************************************************************************************** 37 | * HEADER FILES 38 | *********************************************************************************************************************/ 39 | #include "pal.h" 40 | 41 | /********************************************************************************************************************** 42 | * MACROS 43 | *********************************************************************************************************************/ 44 | 45 | 46 | /********************************************************************************************************************** 47 | * ENUMS 48 | *********************************************************************************************************************/ 49 | 50 | 51 | /********************************************************************************************************************** 52 | * DATA STRUCTURES 53 | *********************************************************************************************************************/ 54 | 55 | 56 | /********************************************************************************************************************** 57 | * API Prototypes 58 | *********************************************************************************************************************/ 59 | 60 | #ifdef __cplusplus 61 | extern "C" { 62 | #endif 63 | 64 | /** 65 | * \brief Gets the random counter value. 66 | */ 67 | uint32_t pal_os_random_get_counter(void); 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif /* _PAL_OS_RANDOM_H_ */ 74 | 75 | /** 76 | * @} 77 | */ 78 | 79 | -------------------------------------------------------------------------------- /src/optiga_trustx/pal_os_timer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file implements the prototype declarations of pal os timer functionalities. 28 | * 29 | * \ingroup grPAL 30 | * @{ 31 | */ 32 | #ifndef _PAL_OS_TIMER_H_ 33 | #define _PAL_OS_TIMER_H_ 34 | 35 | /********************************************************************************************************************** 36 | * HEADER FILES 37 | *********************************************************************************************************************/ 38 | 39 | #include "pal.h" 40 | 41 | /********************************************************************************************************************* 42 | * pal_os_timer.h 43 | *********************************************************************************************************************/ 44 | 45 | 46 | /********************************************************************************************************************** 47 | * MACROS 48 | *********************************************************************************************************************/ 49 | 50 | 51 | /********************************************************************************************************************** 52 | * ENUMS 53 | *********************************************************************************************************************/ 54 | 55 | 56 | /********************************************************************************************************************** 57 | * DATA STRUCTURES 58 | *********************************************************************************************************************/ 59 | 60 | 61 | /********************************************************************************************************************** 62 | * API Prototypes 63 | *********************************************************************************************************************/ 64 | 65 | #ifdef __cplusplus 66 | extern "C" { 67 | #endif 68 | 69 | 70 | /** 71 | * @brief Gets tick count value in milliseconds 72 | */ 73 | uint32_t pal_os_timer_get_time_in_milliseconds(void); 74 | 75 | /** 76 | * @brief Waits or delay until the supplied milliseconds 77 | */ 78 | void pal_os_timer_delay_in_milliseconds(uint16_t milliseconds); 79 | 80 | 81 | #ifdef __cplusplus 82 | } 83 | #endif 84 | 85 | #endif /* _PAL_OS_TIMER_H_ */ 86 | 87 | /** 88 | * @} 89 | */ 90 | 91 | -------------------------------------------------------------------------------- /src/optiga_trustx/pal_os_timer_arduino.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright (c) 2018 Infineon Technologies AG 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE 23 | * 24 | * 25 | * \file 26 | * 27 | * \brief This file implements the platform abstraction layer APIs for timer. 28 | * 29 | * \ingroup grPAL 30 | * @{ 31 | */ 32 | 33 | /********************************************************************************************************************** 34 | * HEADER FILES 35 | *********************************************************************************************************************/ 36 | #include 37 | #include "pal_os_timer.h" 38 | 39 | /********************************************************************************************************************** 40 | * MACROS 41 | *********************************************************************************************************************/ 42 | 43 | /// @cond hidden 44 | /********************************************************************************************************************* 45 | * LOCAL DATA 46 | *********************************************************************************************************************/ 47 | 48 | /********************************************************************************************************************** 49 | * LOCAL ROUTINES 50 | *********************************************************************************************************************/ 51 | 52 | /// @endcond 53 | /********************************************************************************************************************** 54 | * API IMPLEMENTATION 55 | *********************************************************************************************************************/ 56 | 57 | /** 58 | * Get the current time in milliseconds
59 | * 60 | * 61 | * \retval uint32_t time in milliseconds 62 | */ 63 | uint32_t pal_os_timer_get_time_in_milliseconds(void) 64 | { 65 | return millis(); 66 | } 67 | 68 | /** 69 | * Waits or delays until the given milliseconds time 70 | * 71 | * \param[in] milliseconds Delay value in milliseconds 72 | * 73 | */ 74 | void pal_os_timer_delay_in_milliseconds(uint16_t milliseconds) 75 | { 76 | delay(milliseconds); 77 | } 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | -------------------------------------------------------------------------------- /src/simple_timer/SimpleTimer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SimpleTimer.h 3 | * 4 | * SimpleTimer - A timer library for Arduino. 5 | * Author: mromani@ottotecnica.com 6 | * Copyright (c) 2010 OTTOTECNICA Italy 7 | * 8 | * This library is free software; you can redistribute it 9 | * and/or modify it under the terms of the GNU Lesser 10 | * General Public License as published by the Free Software 11 | * Foundation; either version 2.1 of the License, or (at 12 | * your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will 15 | * be useful, but WITHOUT ANY WARRANTY; without even the 16 | * implied warranty of MERCHANTABILITY or FITNESS FOR A 17 | * PARTICULAR PURPOSE. See the GNU Lesser General Public 18 | * License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser 21 | * General Public License along with this library; if not, 22 | * write to the Free Software Foundation, Inc., 23 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 | * 25 | */ 26 | 27 | 28 | #ifndef SIMPLETIMER_H 29 | #define SIMPLETIMER_H 30 | 31 | 32 | #if defined(ARDUINO) && ARDUINO >= 100 33 | #include 34 | #else 35 | #include 36 | #endif 37 | 38 | typedef void (*timer_callback)(); 39 | 40 | class SimpleTimer { 41 | 42 | public: 43 | // maximum number of timers 44 | const static int MAX_TIMERS = 2; 45 | 46 | // setTimer() constants 47 | const static int RUN_FOREVER = 0; 48 | const static int RUN_ONCE = 1; 49 | 50 | // constructor 51 | SimpleTimer(); 52 | 53 | // this function must be called inside loop() 54 | void run(); 55 | 56 | // call function f every d milliseconds 57 | int setInterval(long d, timer_callback f); 58 | 59 | // call function f once after d milliseconds 60 | int setTimeout(long d, timer_callback f); 61 | 62 | // call function f every d milliseconds for n times 63 | int setTimer(long d, timer_callback f, int n); 64 | 65 | // destroy the specified timer 66 | void deleteTimer(int numTimer); 67 | 68 | // restart the specified timer 69 | void restartTimer(int numTimer); 70 | 71 | // returns true if the specified timer is enabled 72 | boolean isEnabled(int numTimer); 73 | 74 | // enables the specified timer 75 | void enable(int numTimer); 76 | 77 | // disables the specified timer 78 | void disable(int numTimer); 79 | 80 | // enables the specified timer if it's currently disabled, 81 | // and vice-versa 82 | void toggle(int numTimer); 83 | 84 | // returns the number of used timers 85 | int getNumTimers(); 86 | 87 | // returns the number of available timers 88 | int getNumAvailableTimers() { return MAX_TIMERS - numTimers; }; 89 | 90 | private: 91 | // deferred call constants 92 | const static int DEFCALL_DONTRUN = 0; // don't call the callback function 93 | const static int DEFCALL_RUNONLY = 1; // call the callback function but don't delete the timer 94 | const static int DEFCALL_RUNANDDEL = 2; // call the callback function and delete the timer 95 | 96 | // find the first available slot 97 | int findFirstFreeSlot(); 98 | 99 | // value returned by the millis() function 100 | // in the previous run() call 101 | unsigned long prev_millis[MAX_TIMERS]; 102 | 103 | // pointers to the callback functions 104 | timer_callback callbacks[MAX_TIMERS]; 105 | 106 | // delay values 107 | long delays[MAX_TIMERS]; 108 | 109 | // number of runs to be executed for each timer 110 | int maxNumRuns[MAX_TIMERS]; 111 | 112 | // number of executed runs for each timer 113 | int numRuns[MAX_TIMERS]; 114 | 115 | // which timers are enabled 116 | boolean enabled[MAX_TIMERS]; 117 | 118 | // deferred function call (sort of) - N.B.: this array is only used in run() 119 | int toBeCalled[MAX_TIMERS]; 120 | 121 | // actual number of timers in use 122 | int numTimers; 123 | }; 124 | 125 | #endif 126 | -------------------------------------------------------------------------------- /src/third_crypto/platform-specific.inc: -------------------------------------------------------------------------------- 1 | /* Copyright 2015, Kenneth MacKay. Licensed under the BSD 2-clause license. */ 2 | 3 | #ifndef _UECC_PLATFORM_SPECIFIC_H_ 4 | #define _UECC_PLATFORM_SPECIFIC_H_ 5 | 6 | #include "types.h" 7 | 8 | #if (defined(_WIN32) || defined(_WIN64)) 9 | /* Windows */ 10 | 11 | // use pragma syntax to prevent tweaking the linker script for getting CryptXYZ function 12 | #pragma comment(lib, "crypt32.lib") 13 | #pragma comment(lib, "advapi32.lib") 14 | 15 | #define WIN32_LEAN_AND_MEAN 16 | #include 17 | #include 18 | 19 | static int default_RNG(uint8_t *dest, unsigned size) { 20 | HCRYPTPROV prov; 21 | if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { 22 | return 0; 23 | } 24 | 25 | CryptGenRandom(prov, size, (BYTE *)dest); 26 | CryptReleaseContext(prov, 0); 27 | return 1; 28 | } 29 | #define default_RNG_defined 1 30 | 31 | #elif defined(unix) || defined(__linux__) || defined(__unix__) || defined(__unix) || \ 32 | (defined(__APPLE__) && defined(__MACH__)) || defined(uECC_POSIX) 33 | 34 | /* Some POSIX-like system with /dev/urandom or /dev/random. */ 35 | #include 36 | #include 37 | #include 38 | 39 | #ifndef O_CLOEXEC 40 | #define O_CLOEXEC 0 41 | #endif 42 | 43 | static int default_RNG(uint8_t *dest, unsigned size) { 44 | int fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC); 45 | if (fd == -1) { 46 | fd = open("/dev/random", O_RDONLY | O_CLOEXEC); 47 | if (fd == -1) { 48 | return 0; 49 | } 50 | } 51 | 52 | char *ptr = (char *)dest; 53 | size_t left = size; 54 | while (left > 0) { 55 | ssize_t bytes_read = read(fd, ptr, left); 56 | if (bytes_read <= 0) { // read failed 57 | close(fd); 58 | return 0; 59 | } 60 | left -= bytes_read; 61 | ptr += bytes_read; 62 | } 63 | 64 | close(fd); 65 | return 1; 66 | } 67 | #define default_RNG_defined 1 68 | 69 | #endif /* platform */ 70 | 71 | #endif /* _UECC_PLATFORM_SPECIFIC_H_ */ 72 | -------------------------------------------------------------------------------- /src/third_crypto/types.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2015, Kenneth MacKay. Licensed under the BSD 2-clause license. */ 2 | 3 | #ifndef _UECC_TYPES_H_ 4 | #define _UECC_TYPES_H_ 5 | 6 | #ifndef uECC_PLATFORM 7 | #if __AVR__ 8 | #define uECC_PLATFORM uECC_avr 9 | #elif defined(__thumb2__) || defined(_M_ARMT) /* I think MSVC only supports Thumb-2 targets */ 10 | #define uECC_PLATFORM uECC_arm_thumb2 11 | #elif defined(__thumb__) 12 | #define uECC_PLATFORM uECC_arm_thumb 13 | #elif defined(__arm__) || defined(_M_ARM) 14 | #define uECC_PLATFORM uECC_arm 15 | #elif defined(__aarch64__) 16 | #define uECC_PLATFORM uECC_arm64 17 | #elif defined(__i386__) || defined(_M_IX86) || defined(_X86_) || defined(__I86__) 18 | #define uECC_PLATFORM uECC_x86 19 | #elif defined(__amd64__) || defined(_M_X64) 20 | #define uECC_PLATFORM uECC_x86_64 21 | #else 22 | #define uECC_PLATFORM uECC_arch_other 23 | #endif 24 | #endif 25 | 26 | #ifndef uECC_ARM_USE_UMAAL 27 | #if (uECC_PLATFORM == uECC_arm) && (__ARM_ARCH >= 6) 28 | #define uECC_ARM_USE_UMAAL 1 29 | #elif (uECC_PLATFORM == uECC_arm_thumb2) && (__ARM_ARCH >= 6) && !__ARM_ARCH_7M__ 30 | #define uECC_ARM_USE_UMAAL 1 31 | #else 32 | #define uECC_ARM_USE_UMAAL 0 33 | #endif 34 | #endif 35 | 36 | #ifndef uECC_WORD_SIZE 37 | #if uECC_PLATFORM == uECC_avr 38 | #define uECC_WORD_SIZE 1 39 | #elif (uECC_PLATFORM == uECC_x86_64 || uECC_PLATFORM == uECC_arm64) 40 | #define uECC_WORD_SIZE 8 41 | #else 42 | #define uECC_WORD_SIZE 4 43 | #endif 44 | #endif 45 | 46 | #if (uECC_WORD_SIZE != 1) && (uECC_WORD_SIZE != 4) && (uECC_WORD_SIZE != 8) 47 | #error "Unsupported value for uECC_WORD_SIZE" 48 | #endif 49 | 50 | #if ((uECC_PLATFORM == uECC_avr) && (uECC_WORD_SIZE != 1)) 51 | #pragma message ("uECC_WORD_SIZE must be 1 for AVR") 52 | #undef uECC_WORD_SIZE 53 | #define uECC_WORD_SIZE 1 54 | #endif 55 | 56 | #if ((uECC_PLATFORM == uECC_arm || uECC_PLATFORM == uECC_arm_thumb || \ 57 | uECC_PLATFORM == uECC_arm_thumb2) && \ 58 | (uECC_WORD_SIZE != 4)) 59 | #pragma message ("uECC_WORD_SIZE must be 4 for ARM") 60 | #undef uECC_WORD_SIZE 61 | #define uECC_WORD_SIZE 4 62 | #endif 63 | 64 | #if defined(__SIZEOF_INT128__) || ((__clang_major__ * 100 + __clang_minor__) >= 302) 65 | #define SUPPORTS_INT128 1 66 | #else 67 | #define SUPPORTS_INT128 0 68 | #endif 69 | 70 | typedef int8_t wordcount_t; 71 | typedef int16_t bitcount_t; 72 | typedef int8_t cmpresult_t; 73 | 74 | #if (uECC_WORD_SIZE == 1) 75 | 76 | typedef uint8_t uECC_word_t; 77 | typedef uint16_t uECC_dword_t; 78 | 79 | #define HIGH_BIT_SET 0x80 80 | #define uECC_WORD_BITS 8 81 | #define uECC_WORD_BITS_SHIFT 3 82 | #define uECC_WORD_BITS_MASK 0x07 83 | 84 | #elif (uECC_WORD_SIZE == 4) 85 | 86 | typedef uint32_t uECC_word_t; 87 | typedef uint64_t uECC_dword_t; 88 | 89 | #define HIGH_BIT_SET 0x80000000 90 | #define uECC_WORD_BITS 32 91 | #define uECC_WORD_BITS_SHIFT 5 92 | #define uECC_WORD_BITS_MASK 0x01F 93 | 94 | #elif (uECC_WORD_SIZE == 8) 95 | 96 | typedef uint64_t uECC_word_t; 97 | #if SUPPORTS_INT128 98 | typedef unsigned __int128 uECC_dword_t; 99 | #endif 100 | 101 | #define HIGH_BIT_SET 0x8000000000000000ull 102 | #define uECC_WORD_BITS 64 103 | #define uECC_WORD_BITS_SHIFT 6 104 | #define uECC_WORD_BITS_MASK 0x03F 105 | 106 | #endif /* uECC_WORD_SIZE */ 107 | 108 | #endif /* _UECC_TYPES_H_ */ 109 | --------------------------------------------------------------------------------