1 /** 2 * @file ctb.h 3 * @brief Crypto Toolbox driver. 4 */ 5 6 /****************************************************************************** 7 * 8 * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by 9 * Analog Devices, Inc.), 10 * Copyright (C) 2023-2024 Analog Devices, Inc. 11 * 12 * Licensed under the Apache License, Version 2.0 (the "License"); 13 * you may not use this file except in compliance with the License. 14 * You may obtain a copy of the License at 15 * 16 * http://www.apache.org/licenses/LICENSE-2.0 17 * 18 * Unless required by applicable law or agreed to in writing, software 19 * distributed under the License is distributed on an "AS IS" BASIS, 20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 * See the License for the specific language governing permissions and 22 * limitations under the License. 23 * 24 ******************************************************************************/ 25 26 #ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32520_CTB_H_ 27 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32520_CTB_H_ 28 29 /***** Includes *****/ 30 #include "ctb_reva.h" 31 #include "ctb_regs.h" 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 37 /** 38 * @defgroup ctb CTB 39 * @ingroup periphlibs 40 * @{ 41 */ 42 43 /* IN ADDITION TO THIS HEADER, FCL WILL BE SUPPORTED AND PROVIDED IN BINARY FORM */ 44 /***** Definitions *****/ 45 46 /** 47 * @brief Callback funtion for ctb 48 * 49 */ 50 typedef void (*mxc_ctb_complete_cb_t)(void *req, int result); 51 52 /** 53 * @brief Enumeration type for Crypto Toolbox features 54 * 55 */ 56 typedef enum { 57 MXC_CTB_FEATURE_DMA = 1 << 0, 58 MXC_CTB_FEATURE_ECC = 1 << 1, 59 MXC_CTB_FEATURE_CRC = 1 << 2, 60 MXC_CTB_FEATURE_HASH = 1 << 4, 61 MXC_CTB_FEATURE_CIPHER = 1 << 5, 62 MXC_CTB_FEATURE_TRNG = 1 << 6 63 } mxc_ctb_features_t; 64 65 /* ************************************************************************* */ 66 /* DMA Definitions */ 67 /* ************************************************************************* */ 68 69 /** 70 * @brief Structure for using DMA with CTB 71 * 72 */ 73 struct _mxc_ctb_dma_req_t { 74 uint8_t *sourceBuffer; ///< pointer to source data 75 uint8_t *destBuffer; ///< pointer to destination buffer 76 uint32_t length; ///< length of source data 77 mxc_ctb_complete_cb_t callback; ///< Null callback indicates a blocking operation 78 } typedef mxc_ctb_dma_req_t; 79 80 /** 81 * @brief Enumeration type to select read source channel of DMA 82 * 83 */ 84 typedef enum { 85 MXC_CTB_DMA_READ_FIFO_DMA = MXC_V_CTB_CRYPTO_CTRL_RDSRC_DMAORAPB, 86 MXC_CTB_DMA_READ_FIFO_RNG = MXC_V_CTB_CRYPTO_CTRL_RDSRC_RNG 87 } mxc_ctb_dma_read_source_t; 88 89 /** 90 * @brief Enumeration type to select write source channel of DMA 91 * 92 */ 93 typedef enum { 94 MXC_CTB_DMA_WRITE_FIFO_CIPHER = MXC_V_CTB_CRYPTO_CTRL_WRSRC_CIPHEROUTPUT, 95 MXC_CTB_DMA_WRITE_FIFO_READ_FIFO = MXC_V_CTB_CRYPTO_CTRL_WRSRC_READFIFO, 96 MXC_CTB_DMA_WRITE_FIFO_NONE = MXC_V_CTB_CRYPTO_CTRL_WRSRC_NONE 97 } mxc_ctb_dma_write_source_t; 98 99 /* ************************************************************************* */ 100 /* ECC Definitions */ 101 /* ************************************************************************* */ 102 103 /** 104 * @brief Structure used to set up ECC request 105 * 106 */ 107 struct _mxc_ctb_ecc_req_t { 108 uint8_t *dataBuffer; 109 uint32_t dataLen; 110 uint32_t checksum; 111 mxc_ctb_complete_cb_t callback; 112 } typedef mxc_ctb_ecc_req_t; 113 114 /** 115 * @brief Structure used to set up CRC request 116 * 117 */ 118 struct _mxc_ctb_crc_req_t { 119 uint8_t *dataBuffer; 120 uint32_t dataLen; 121 uint32_t resultCRC; 122 mxc_ctb_complete_cb_t callback; 123 } typedef mxc_ctb_crc_req_t; 124 125 /** 126 * @brief CRC data bit order 127 * 128 */ 129 typedef enum { MXC_CTB_CRC_LSB_FIRST, MXC_CTB_CRC_MSB_FIRST } mxc_ctb_crc_bitorder_t; 130 131 /* ************************************************************************* */ 132 /* Hash Definitions */ 133 /* ************************************************************************* */ 134 135 /** 136 * @brief Structure used to set up Hash request 137 * 138 */ 139 struct _mxc_ctb_hash_req_t { 140 uint8_t *msg; 141 uint32_t len; 142 uint8_t *hash; 143 mxc_ctb_complete_cb_t callback; 144 } typedef mxc_ctb_hash_req_t; 145 146 /** 147 * @brief Enumeration type to select Hash function 148 * 149 */ 150 typedef enum { 151 MXC_CTB_HASH_DIS = MXC_V_CTB_HASH_CTRL_HASH_DIS, // Disable 152 MXC_CTB_HASH_SHA1 = MXC_V_CTB_HASH_CTRL_HASH_SHA1, // Select SHA1 153 MXC_CTB_HASH_SHA224 = MXC_V_CTB_HASH_CTRL_HASH_SHA224, // Select SHA224 154 MXC_CTB_HASH_SHA256 = MXC_V_CTB_HASH_CTRL_HASH_SHA256, // Select SHA256 155 MXC_CTB_HASH_SHA384 = MXC_V_CTB_HASH_CTRL_HASH_SHA384, // Select SHA384 156 MXC_CTB_HASH_SHA512 = MXC_V_CTB_HASH_CTRL_HASH_SHA512 // Select SHA384 157 } mxc_ctb_hash_func_t; 158 159 /** 160 * @brief Enumeration type to select FIFO source for Hash 161 * 162 */ 163 typedef enum { 164 MXC_CTB_HASH_SOURCE_INFIFO = 0, 165 MXC_CTB_HASH_SOURCE_OUTFIFO = 1 166 } mxc_ctb_hash_source_t; 167 168 /* ************************************************************************* */ 169 /* Cipher Definitions */ 170 /* ************************************************************************* */ 171 172 /** 173 * @brief Structure used to set up Cipher request 174 * 175 */ 176 struct _mxc_ctb_cipher_req_t { 177 uint8_t *plaintext; 178 uint32_t ptLen; 179 uint8_t *iv; 180 uint8_t *ciphertext; 181 mxc_ctb_complete_cb_t callback; 182 } typedef mxc_ctb_cipher_req_t; 183 184 /** 185 * @brief Enumeration type to select Cipher mode 186 * 187 */ 188 typedef enum { 189 MXC_CTB_MODE_ECB = MXC_V_CTB_CIPHER_CTRL_MODE_ECB, ///< Electronic Code Book 190 MXC_CTB_MODE_CBC = MXC_V_CTB_CIPHER_CTRL_MODE_CBC, ///< Cipher Block Chaining 191 MXC_CTB_MODE_CFB = MXC_V_CTB_CIPHER_CTRL_MODE_CFB, ///< Cipher Feedback 192 MXC_CTB_MODE_CTR = MXC_V_CTB_CIPHER_CTRL_MODE_CTR, ///< Counter 193 } mxc_ctb_cipher_mode_t; 194 195 /** 196 * @brief Enumeration type to select Cipher function 197 * 198 */ 199 typedef enum { 200 MXC_CTB_CIPHER_DIS = MXC_V_CTB_CIPHER_CTRL_CIPHER_DIS, ///< Disable 201 MXC_CTB_CIPHER_AES128 = MXC_V_CTB_CIPHER_CTRL_CIPHER_AES128, ///< Select AES-128 202 MXC_CTB_CIPHER_AES192 = MXC_V_CTB_CIPHER_CTRL_CIPHER_AES192, ///< Select AES-192 203 MXC_CTB_CIPHER_AES256 = MXC_V_CTB_CIPHER_CTRL_CIPHER_AES256, ///< Select AES-256 204 MXC_CTB_CIPHER_DES = MXC_V_CTB_CIPHER_CTRL_CIPHER_DES, ///< Select DES 205 MXC_CTB_CIPHER_TDES = MXC_V_CTB_CIPHER_CTRL_CIPHER_TDES ///< Select TDES 206 } mxc_ctb_cipher_t; 207 208 /** 209 * @brief Enumeration type to select Cipher key 210 * 211 */ 212 typedef enum { 213 MXC_CTB_CIPHER_KEY_SOFTWARE = 0, 214 MXC_CTB_CIPHER_KEY_AES_KEY2 = 2, 215 MXC_CTB_CIPHER_KEY_AES_KEY3 = 3 216 } mxc_ctb_cipher_key_t; 217 218 /** 219 * @brief Cipher operation 220 * 221 */ 222 typedef enum { MXC_CTB_CIPHER_ENCRYPTION, MXC_CTB_CIPHER_DECRYPTION } mxc_ctb_cipher_operation_t; 223 224 /***** Function Prototypes *****/ 225 226 /* ************************************************************************* */ 227 /* Global Control/Configuration functions */ 228 /* ************************************************************************* */ 229 230 /** 231 * @brief Enable portions of the CTB 232 * 233 * @param features bit banded value indicating features to enable 234 * see \ref mxc_ctb_features_t for a list of features 235 * 236 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 237 */ 238 int MXC_CTB_Init(uint32_t features); 239 240 /** 241 * @brief Detects what CTB features exist, see \ref mxc_ctb_features_t 242 * 243 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 244 */ 245 uint32_t MXC_CTB_CheckFeatures(void); 246 247 /** 248 * @brief Enable CTB Interrupts 249 * 250 */ 251 void MXC_CTB_EnableInt(void); 252 253 /** 254 * @brief Disable CTB Interrupts 255 * 256 */ 257 void MXC_CTB_DisableInt(void); 258 259 /** 260 * @brief Checks the global CTB Ready Status 261 * 262 * @return Nonzero if ready, zero if not ready or \ref MXC_Error_Codes. 263 */ 264 int MXC_CTB_Ready(void); 265 266 /** 267 * @brief Clears the selected feature's done bits, see \ref mxc_ctb_features_t 268 * 269 * @param features bit banded value indicating features to clear 270 */ 271 void MXC_CTB_DoneClear(uint32_t features); 272 273 /** 274 * @brief Returns CTB features showing operations complete, see \ref mxc_ctb_features_t 275 * 276 * @return CTB features showing operations complete, see \ref mxc_ctb_features_t. 277 */ 278 uint32_t MXC_CTB_Done(void); 279 280 /** 281 * @brief Resets the selected features, see \ref mxc_ctb_features_t 282 * 283 * @param features bit banded value indicating features to reset 284 */ 285 void MXC_CTB_Reset(uint32_t features); 286 287 /** 288 * @brief Invalidates the CTB's internal cache. 289 * @note For best security, should be done after every operation 290 */ 291 void MXC_CTB_CacheInvalidate(void); 292 293 /** 294 * @brief Disable and reset portions of the CTB 295 * 296 * @param features bit banded value indicating features to shutdown 297 * see \ref mxc_ctb_features_t for a list of features 298 * 299 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 300 */ 301 int MXC_CTB_Shutdown(uint32_t features); 302 303 /** 304 * @brief Check which CTB features are enabled 305 * 306 * @return CTB features showing features enabled, see \ref mxc_ctb_features_t. 307 */ 308 uint32_t MXC_CTB_GetEnabledFeatures(void); 309 310 /** 311 * @brief This function should be called from the CTB ISR Handler 312 * when using Async functions 313 */ 314 void MXC_CTB_Handler(void); 315 316 /************************************/ 317 /* CTB DMA - Used for all features */ 318 /************************************/ 319 320 /** 321 * @brief Set the source the DMA reads from 322 * @note The DMA is unable to read directly from Flash 323 * 324 * @param source The source of the data for DMA read operations 325 * see \ref mxc_ctb_dma_read_source_t for a list of sources 326 */ 327 void MXC_CTB_DMA_SetReadSource(mxc_ctb_dma_read_source_t source); 328 329 /** 330 * @brief Get the source the DMA reads from 331 * 332 * @return The source of the data for DMA read operations 333 * see \ref mxc_ctb_dma_read_source_t for a list of sources 334 */ 335 mxc_ctb_dma_read_source_t MXC_CTB_DMA_GetReadSource(void); 336 337 /** 338 * @brief Set the source the DMA write fifo reads from 339 * 340 * @param source The source of the data for DMA write operations 341 * see \ref mxc_ctb_dma_write_source_t for a list of sources 342 */ 343 void MXC_CTB_DMA_SetWriteSource(mxc_ctb_dma_write_source_t source); 344 345 /** 346 * @brief Set the source the DMA write fifo reads from 347 * 348 * @return The source of the data for DMA write operations 349 * see \ref mxc_ctb_dma_write_source_t for a list of sources 350 */ 351 mxc_ctb_dma_write_source_t MXC_CTB_DMA_GetWriteSource(void); 352 353 /** 354 * @brief Set the source address of the DMA 355 * @note This is only applicable when the read source is memory 356 * The DMA is unable to read directly from Flash 357 * 358 * @param source pointer to the source location 359 */ 360 void MXC_CTB_DMA_SetSource(uint8_t *source); 361 362 /** 363 * @brief Set the destination address of the DMA 364 * 365 * @param dest pointer to destination 366 */ 367 void MXC_CTB_DMA_SetDestination(uint8_t *dest); 368 369 /** 370 * @brief Set the source and destination addresses of the DMA 371 * 372 * @param req request structure that contains the source and destination 373 * information. A destination address of NULL will indicate 374 * that the Read Source has been set as something other than memory. 375 * 376 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 377 */ 378 int MXC_CTB_DMA_SetupOperation(mxc_ctb_dma_req_t *req); 379 380 /** 381 * @brief Start a DMA transfer defined by the request object 382 * Blocks until completion 383 * 384 * @param req request structure that contains the source and destination 385 * information. A destination address of NULL will indicate 386 * that the Read Source has been set as something other than memory. 387 * 388 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 389 */ 390 int MXC_CTB_DMA_DoOperation(mxc_ctb_dma_req_t *req); 391 392 /** 393 * @brief Start a DMA transfer of fixed size 394 * 395 * @param length Number of bytes to transfer 396 * 397 */ 398 void MXC_CTB_DMA_StartTransfer(uint32_t length); 399 400 /* ************************************************************************* */ 401 /* True Random Number Generator (TRNG) functions */ 402 /* ************************************************************************* */ 403 404 /** 405 * @brief Get a random number 406 * 407 * @return A random 32-bit number 408 */ 409 int MXC_CTB_TRNG_RandomInt(void); 410 411 /** 412 * @brief Get a random number of length len 413 * 414 * @param data Pointer to a location to store the number 415 * @param len Length of random number in bytes 416 * 417 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 418 */ 419 int MXC_CTB_TRNG_Random(uint8_t *data, uint32_t len); 420 421 /** 422 * @brief Get a random number of length len, do not block while generating data 423 * @note The user must call MXC_CTB_Handler() in the ISR 424 * 425 * @param data Pointer to a location to store the number 426 * @param len Length of random number in bytes 427 * @param callback Function that will be called when all data has been generated 428 * 429 */ 430 void MXC_CTB_TRNG_RandomAsync(uint8_t *data, uint32_t len, mxc_ctb_complete_cb_t callback); 431 432 /* ************************************************************************* */ 433 /* Error Correction Code (ECC) functions */ 434 /* ************************************************************************* */ 435 436 /*******************************/ 437 /* Low Level Functions */ 438 /*******************************/ 439 440 /** 441 * @brief Enable ECC Calculation 442 * @note ECC calculation is shared with CRC, when ECC is enabled, CRC 443 * computation is not possible 444 */ 445 void MXC_CTB_ECC_Enable(void); 446 447 /** 448 * @brief Disable ECC Calculation 449 * @note ECC calculation is shared with CRC, when ECC is enabled, CRC 450 * computation is not possible 451 */ 452 void MXC_CTB_ECC_Disable(void); 453 454 /** 455 * @brief Get the Result of an ECC Calculation 456 * 457 * @return The result of the ECC calculation 458 */ 459 uint32_t MXC_CTB_ECC_GetResult(void); 460 461 /*******************************/ 462 /* High Level Functions */ 463 /*******************************/ 464 465 /** 466 * @brief Compute the ECC value for a block of data up to 8kB in size 467 * @note This function places the computed ECC value in the appropriate 468 * place in the mxc_ctb_ecc_req_t structure 469 * 470 * @param req Structure containing data for the ECC request 471 * 472 * @return see \ref MXC_Error_Codes for a list of return codes. 473 */ 474 int MXC_CTB_ECC_Compute(mxc_ctb_ecc_req_t *req); 475 476 /** 477 * @brief Check for single or dual bit errors in a block of data 478 * @note This function will also correct single bit errors as needed 479 * 480 * @param req Structure containing data for the ECC request 481 * 482 * @return Positive values for 1 or 2 bit errors, respectively 483 * otherwise, see \ref MXC_Error_Codes for a list of return codes. 484 */ 485 int MXC_CTB_ECC_ErrorCheck(mxc_ctb_ecc_req_t *req); 486 487 /** 488 * @brief Compute the ECC value for a block of data up to 8kB in size 489 * @note This function places the computed ECC value in the appropriate 490 * place in the mxc_ctb_ecc_req_t structure. The user needs to call 491 * MXC_CTB_Handler() in the ISR 492 * 493 * @param req Structure containing data for the ECC request 494 */ 495 void MXC_CTB_ECC_ComputeAsync(mxc_ctb_ecc_req_t *req); 496 497 /** 498 * @brief Check for single or dual bit errors in a block of data 499 * @note This function will also correct single bit errors as needed 500 * The user must call MXC_CTB_Handler() in the ISR. 501 * 502 * @param req Structure containing data for the ECC request 503 */ 504 void MXC_CTB_ECC_ErrorCheckAsync(mxc_ctb_ecc_req_t *req); 505 506 /* ************************************************************************* */ 507 /* Cyclic Redundancy Check (CRC) functions */ 508 /* ************************************************************************* */ 509 510 /*******************************/ 511 /* Low Level Functions */ 512 /*******************************/ 513 514 /** 515 * @brief Set the bit-order of CRC calculation 516 * 517 * @param bitOrder The direction to perform CRC calculation in, \ref mxc_ctb_crc_bitorder_t 518 */ 519 void MXC_CTB_CRC_SetDirection(mxc_ctb_crc_bitorder_t bitOrder); 520 521 /** 522 * @brief Set the bit-order of CRC calculation 523 * 524 * @return The direction of calculation, 1 for MSB first, 0 for LSB first, \ref mxc_ctb_crc_bitorder_t 525 */ 526 mxc_ctb_crc_bitorder_t MXC_CTB_CRC_GetDirection(void); 527 528 /** 529 * @brief Set the Polynomial for CRC calculation 530 * 531 * @param poly The polynomial to use for CRC calculation 532 */ 533 void MXC_CTB_CRC_SetPoly(uint32_t poly); 534 535 /** 536 * @brief Get the polynomial for CRC calculation 537 * 538 * @return The polynomial used in calculation 539 */ 540 uint32_t MXC_CTB_CRC_GetPoly(void); 541 542 /** 543 * @brief Get the result of a CRC calculation 544 * 545 * @return The calculated CRC value 546 */ 547 uint32_t MXC_CTB_CRC_GetResult(void); 548 549 /** 550 * @brief Set the intial value used (the seed) when starting a CRC computation. 551 * 552 * @param seed The value to seed the CRC generator with 553 */ 554 void MXC_CTB_CRC_SetInitialValue(uint32_t seed); 555 556 /** 557 * @brief Set the value that will be bitwise XORed with the final output from the CRC computation. Use 0 to skip the XOR step. 558 * 559 * @param xor The value that will be XORed with the CRC 560 */ 561 void MXC_CTB_CRC_SetFinalXORValue(uint32_t xor); 562 563 /*******************************/ 564 /* High Level Functions */ 565 /*******************************/ 566 567 /** 568 * @brief Perform a CRC computation 569 * @note The result of the CRC calculation will be placed in the 570 * mxc_ctb_crc_req_t structure 571 * 572 * @param req Structure containing the data for calculation 573 * 574 * @return see \ref MXC_Error_Codes for a list of return codes. 575 */ 576 int MXC_CTB_CRC_Compute(mxc_ctb_crc_req_t *req); 577 578 /** 579 * @brief Perform a CRC computation asynchronously 580 * @note The result of the CRC calculation will be placed in the 581 * mxc_ctb_crc_req_t structure. The user must call 582 * MXC_CTB_Handler() in the ISR 583 * 584 * @param req Structure containing the data for calculation 585 */ 586 void MXC_CTB_CRC_ComputeAsync(mxc_ctb_crc_req_t *req); 587 588 /* ************************************************************************* */ 589 /* Hash functions */ 590 /* ************************************************************************* */ 591 592 /***********************/ 593 /* Low Level Functions */ 594 /***********************/ 595 596 /** 597 * @brief Get the block size for a given hash function 598 * 599 * @param function See \ref mxc_ctb_hash_func_t for options 600 * 601 * @return Block size in bytes 602 */ 603 unsigned int MXC_CTB_Hash_GetBlockSize(mxc_ctb_hash_func_t function); 604 605 /** 606 * @brief Get the digest size for a given hash function 607 * 608 * @param function See \ref mxc_ctb_hash_func_t for options 609 * 610 * @return Digest size in bytes 611 */ 612 unsigned int MXC_CTB_Hash_GetDigestSize(mxc_ctb_hash_func_t function); 613 614 /** 615 * @brief Set the algorithm to use for hash computation 616 * 617 * @param function See \ref mxc_ctb_hash_func_t for options 618 */ 619 void MXC_CTB_Hash_SetFunction(mxc_ctb_hash_func_t function); 620 621 /** 622 * @brief Get the algorithm to use for hash computation 623 * 624 * @return See \ref mxc_ctb_hash_func_t for options 625 */ 626 mxc_ctb_hash_func_t MXC_CTB_Hash_GetFunction(void); 627 628 /** 629 * @brief Set whether to use automatic padding of the input data 630 * @note The padding procedure used by hardware is described in the users guide 631 * 632 * @param pad Use hardware padding of the data 633 */ 634 void MXC_CTB_Hash_SetAutoPad(int pad); 635 636 /** 637 * @brief Get whether to use automatic padding of the input data 638 * 639 * @return Using hardware padding of the data 640 */ 641 int MXC_CTB_Hash_GetAutoPad(void); 642 643 /** 644 * @brief Get the result of a hash computation 645 * 646 * @param digest buffer to store the ouctbt of the hash algorithm 647 * @param len location to store the length of the digest 648 */ 649 void MXC_CTB_Hash_GetResult(uint8_t *digest, int *len); 650 651 /** 652 * @brief Set the size of the data input into the hash computation 653 * @note Hash data size is software limited to ~3GB 654 * 655 * @param size Size of the data in bytes 656 */ 657 void MXC_CTB_Hash_SetMessageSize(uint32_t size); 658 659 /** 660 * @brief Set the source of data for the hash computation 661 * 662 * @param source see \ref mxc_ctb_hash_source_t for options 663 */ 664 void MXC_CTB_Hash_SetSource(mxc_ctb_hash_source_t source); 665 666 /** 667 * @brief Get the source of data for the hash computation 668 * 669 * @return See \ref mxc_ctb_hash_source_t for options 670 */ 671 mxc_ctb_hash_source_t MXC_CTB_Hash_GetSource(void); 672 673 /** 674 * @brief Initialize the hash computation unit 675 * @note Call this after setting the hash function and message size 676 * This function blocks until load is complete 677 * 678 */ 679 void MXC_CTB_Hash_InitializeHash(void); 680 681 /************************/ 682 /* High Level Functions */ 683 /************************/ 684 685 /** 686 * @brief Compute a Hash Digest 687 * @note The computed digest will be stored in the req structure 688 * 689 * @param req Structure containing all data needed for a hash computation 690 * 691 * @return See \ref MXC_Error_Codes for a list of return codes 692 */ 693 int MXC_CTB_Hash_Compute(mxc_ctb_hash_req_t *req); 694 695 /** 696 * @brief Compute a Hash Digest 697 * @note The computed digest will be stored in the req structure. The user 698 * must call MXC_CTB_Handler() in the ISR. 699 * 700 * @param req Structure containing all data needed for a hash computation 701 */ 702 void MXC_CTB_Hash_ComputeAsync(mxc_ctb_hash_req_t *req); 703 704 /* ************************************************************************* */ 705 /* Cipher functions */ 706 /* ************************************************************************* */ 707 708 /************************/ 709 /* Low Level Functions */ 710 /************************/ 711 712 /** 713 * @brief Get the key size for a given cipher type 714 * 715 * @param cipher See \ref mxc_ctb_cipher_t for options 716 * 717 * @return Size of the key in bytes 718 */ 719 unsigned int MXC_CTB_Cipher_GetKeySize(mxc_ctb_cipher_t cipher); 720 721 /** 722 * @brief Get the block size for a given cipher type 723 * 724 * @param cipher See \ref mxc_ctb_cipher_t for options 725 * 726 * @return Size of the block in bytes 727 */ 728 unsigned int MXC_CTB_Cipher_GetBlockSize(mxc_ctb_cipher_t cipher); 729 730 /** 731 * @brief Set the block mode used for cipher operations 732 * 733 * @param mode See \ref mxc_ctb_cipher_mode_t for options 734 */ 735 void MXC_CTB_Cipher_SetMode(mxc_ctb_cipher_mode_t mode); 736 737 /** 738 * @brief Get the block mode used for cipher operations 739 * 740 * @return See \ref mxc_ctb_cipher_mode_t for options 741 */ 742 mxc_ctb_cipher_mode_t MXC_CTB_Cipher_GetMode(void); 743 744 /** 745 * @brief Set the cipher type used for cipher operations 746 * 747 * @param cipher See \ref mxc_ctb_cipher_t for options 748 */ 749 void MXC_CTB_Cipher_SetCipher(mxc_ctb_cipher_t cipher); 750 751 /** 752 * @brief Get the cipher type used for cipher operations 753 * 754 * @return See \ref mxc_ctb_cipher_t for options 755 */ 756 mxc_ctb_cipher_t MXC_CTB_Cipher_GetCipher(void); 757 758 /** 759 * @brief Set the source of the key used in cipher operations 760 * 761 * @param source See \ref mxc_ctb_cipher_key_t for options 762 */ 763 void MXC_CTB_Cipher_SetKeySource(mxc_ctb_cipher_key_t source); 764 765 /** 766 * @brief Get the cipher type used for cipher operations 767 * 768 * @return See \ref mxc_ctb_cipher_key_t for options 769 */ 770 mxc_ctb_cipher_key_t MXC_CTB_Cipher_GetKeySource(void); 771 772 /** 773 * @brief Load the cipher key from the selected source 774 * 775 */ 776 void MXC_CTB_Cipher_LoadKey(void); 777 778 /** 779 * @brief Configure for encryption or decryption 780 * 781 * @param operation Set to perform encryption/decryption \ref mxc_ctb_cipher_operation_t 782 */ 783 void MXC_CTB_Cipher_SetOperation(mxc_ctb_cipher_operation_t operation); 784 785 /** 786 * @brief Set the cipher key 787 * @note This only takes effect if software is the selected key source 788 * 789 * @param key buffer containing key 790 * @param len length of key (dependent on cipher used) 791 */ 792 void MXC_CTB_Cipher_SetKey(uint8_t *key, uint32_t len); 793 794 /** 795 * @brief Set the initial value used for cipher operations 796 * 797 * @param iv buffer containing iv 798 * @param len length of initial value 799 */ 800 void MXC_CTB_Cipher_SetIV(uint8_t *iv, uint32_t len); 801 802 /** 803 * @brief Get the initial value used for cipher operations 804 * 805 * @param ivOut buffer containing iv 806 * @param len length of buffer 807 */ 808 void MXC_CTB_Cipher_GetIV(uint8_t *ivOut, uint32_t len); 809 810 /************************/ 811 /* High Level Functions */ 812 /************************/ 813 814 /** 815 * @brief Perform an encryption using the cipher feature 816 * @note The result will be stored in the req structure 817 * 818 * @param req Structure containing data for the encryption 819 * 820 * @return See \ref MXC_Error_Codes for a list of return codes. 821 */ 822 int MXC_CTB_Cipher_Encrypt(mxc_ctb_cipher_req_t *req); 823 824 /** 825 * @brief Perform a decryption using the cipher feature 826 * @note The result will be stored in the req structure 827 * 828 * @param req Structure containing data for the decryption 829 * 830 * @return See \ref MXC_Error_Codes for a list of return codes. 831 */ 832 int MXC_CTB_Cipher_Decrypt(mxc_ctb_cipher_req_t *req); 833 834 /** 835 * @brief Perform an encryption using the cipher feature 836 * @note The result will be stored in the req structure. The user needs 837 * to call MXC_CTB_Handler() in the ISR 838 * 839 * @param req Structure containing data for the encryption 840 */ 841 void MXC_CTB_Cipher_EncryptAsync(mxc_ctb_cipher_req_t *req); 842 843 /** 844 * @brief Perform a decryption using the cipher feature 845 * @note The result will be stored in the req structure. The user needs 846 * to call MXC_CTB_Handler() in the ISR 847 * 848 * @param req Structure containing data for the decryption 849 */ 850 void MXC_CTB_Cipher_DecryptAsync(mxc_ctb_cipher_req_t *req); 851 852 #ifdef __cplusplus 853 } 854 #endif 855 /**@} end of group ctb */ 856 857 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32520_CTB_H_ 858