1 /* 2 * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @file wm_crypto_hard.h 18 * 19 * @brief hard crypto module 20 * 21 * @author dave 22 * 23 * Copyright (c) 2014 Winner Microelectronics Co., Ltd. 24 */ 25 26 #ifndef WM_CRYPTO_HARD_H 27 #define WM_CRYPTO_HARD_H 28 29 #include "wm_type_def.h" 30 #include "wm_osal.h" 31 32 #ifndef min 33 #define min(a, b) (((a) < (b)) ? (a) : (b)) 34 #endif /* min */ 35 36 /** The base address of the registers of encryption/decryption module. */ 37 #define HR_CRYPTO_BASE_ADDR 0x40000600 38 /** The address of the source text address register. */ 39 #define HR_CRYPTO_SRC_ADDR (HR_CRYPTO_BASE_ADDR + 0x00) 40 /** The address of the encrypted/decrypted text address register. */ 41 #define HR_CRYPTO_DEST_ADDR (HR_CRYPTO_BASE_ADDR + 0x04) 42 /** The address of the configuration register. */ 43 #define HR_CRYPTO_SEC_CFG (HR_CRYPTO_BASE_ADDR + 0x08) 44 /** The address of the control register. */ 45 #define HR_CRYPTO_SEC_CTRL (HR_CRYPTO_BASE_ADDR + 0x0C) 46 /** The address of the key0 register. */ 47 #define HR_CRYPTO_KEY0 (HR_CRYPTO_BASE_ADDR + 0x10) 48 /** The address of the key1 register. */ 49 #define HR_CRYPTO_KEY1 (HR_CRYPTO_BASE_ADDR + 0x14) 50 /** The address of the key2 register. */ 51 #define HR_CRYPTO_KEY2 (HR_CRYPTO_BASE_ADDR + 0x18) 52 /** The address of the key3 register. */ 53 #define HR_CRYPTO_KEY3 (HR_CRYPTO_BASE_ADDR + 0x1C) 54 /** The address of the key4 register. */ 55 #define HR_CRYPTO_KEY4 (HR_CRYPTO_BASE_ADDR + 0x20) 56 /** The address of the key5 register. */ 57 #define HR_CRYPTO_KEY5 (HR_CRYPTO_BASE_ADDR + 0x24) 58 /** The address of the key6 register. */ 59 #define HR_CRYPTO_KEY6 (HR_CRYPTO_BASE_ADDR + 0x4c) 60 /** The address of the key7 register. */ 61 #define HR_CRYPTO_KEY7 (HR_CRYPTO_BASE_ADDR + 0x50) 62 63 /** The address of the IV0 register. */ 64 #define HR_CRYPTO_IV0 (HR_CRYPTO_BASE_ADDR + 0x28) 65 /** The address of the IV1 register. */ 66 #define HR_CRYPTO_IV1 (HR_CRYPTO_BASE_ADDR + 0x20) 67 68 /** The address of the encrypted/decrypted status register. */ 69 #define HR_CRYPTO_SEC_STS (HR_CRYPTO_BASE_ADDR + 0x30) 70 71 /** The address of the SHA1/MD5 digest0 register. */ 72 #define HR_CRYPTO_SHA1_DIGEST0 (HR_CRYPTO_BASE_ADDR + 0x34) 73 /** The address of the SHA1/MD5 digest1 register. */ 74 #define HR_CRYPTO_SHA1_DIGEST1 (HR_CRYPTO_BASE_ADDR + 0x38) 75 /** The address of the SHA1/MD5 digest2 register. */ 76 #define HR_CRYPTO_SHA1_DIGEST2 (HR_CRYPTO_BASE_ADDR + 0x3C) 77 /** The address of the SHA1/MD5 digest3 register. */ 78 #define HR_CRYPTO_SHA1_DIGEST3 (HR_CRYPTO_BASE_ADDR + 0x40) 79 /** The address of the SHA1 digest4 and CRC in/output register. */ 80 #define HR_CRYPTO_SHA1_DIGEST4 (HR_CRYPTO_BASE_ADDR + 0x44) 81 /** The address of the RNG RESULT register. */ 82 #define HR_CRYPTO_RNG_RESULT (HR_CRYPTO_BASE_ADDR + 0x48) 83 /** The address of the TRNG CR register. */ 84 #define HR_CRYPTO_TRNG_CR (HR_CRYPTO_BASE_ADDR + 0x54) 85 86 /** The address of the CRC in register. */ 87 #define HR_CRYPTO_CRC_KEY HR_CRYPTO_SHA1_DIGEST4 88 /** The address of the CRC output register. */ 89 #define HR_CRYPTO_CRC_RESULT HR_CRYPTO_SHA1_DIGEST4 90 91 #define ERR_CRY_OK 0 // /< No error, everything OK. 92 #define ERR_FAILURE (-1) /* failure */ 93 #define ERR_ARG_FAIL (-6) /* Failure due to bad function param */ 94 95 # define PS_SUCCESS 0 96 # define PS_FAILURE (-1) 97 # define PS_FAIL PS_FAILURE /* Just another name */ 98 99 /* NOTE: Failure return codes MUST be < 0 */ 100 /* NOTE: The range for core error codes should be between -2 and -29 */ 101 # define PS_ARG_FAIL (-6) /* Failure due to bad function param */ 102 # define PS_PLATFORM_FAIL (-7) /* Failure as a result of system call error */ 103 # define PS_MEM_FAIL (-8) /* Failure to allocate requested memory */ 104 # define PS_LIMIT_FAIL (-9) /* Failure on sanity/limit tests */ 105 # define PS_UNSUPPORTED_FAIL (-10) /* Unimplemented feature error */ 106 # define PS_DISABLED_FEATURE_FAIL (-11) /* Incorrect #define toggle for feature */ 107 # define PS_PROTOCOL_FAIL (-12) /* A protocol error occurred */ 108 # define PS_TIMEOUT_FAIL (-13) /* A timeout occurred and MAY be an error */ 109 # define PS_INTERRUPT_FAIL (-14) /* An interrupt occurred and MAY be an error */ 110 # define PS_PENDING (-15) /* In process. Not necessarily an error */ 111 # define PS_EAGAIN (-16) /* Try again later. Not necessarily an error */ 112 # define PS_OUTPUT_LENGTH (-17) /* Output length negotiation: 113 output buffer is too small. */ 114 # define PS_HOSTNAME_RESOLUTION (-18) /* Cannot resolve host name. */ 115 # define PS_CONNECT (-19) /* Cannot connect to remote host. */ 116 # define PS_INSECURE_PROTOCOL (-20) /* The operation needs to use insecure protocol. 117 The caller needs to accept use of insecure 118 protocol. */ 119 # define PS_VERIFICATION_FAILED (-21) /* Signature verification failed. */ 120 121 // CRC 122 #define OUTPUT_REFLECT 1 123 #define INPUT_REFLECT 2 124 125 typedef enum __CRYPTO_METHOD { 126 CRYPTO_METHOD_RSV = 0, 127 CRYPTO_METHOD_RC4, 128 CRYPTO_METHOD_SHA1, 129 CRYPTO_METHOD_AES, 130 CRYPTO_METHOD_DES, 131 CRYPTO_METHOD_3DES, 132 CRYPTO_METHOD_CRC, // /< CRC 133 CRYPTO_METHOD_MD5 // /< MD5 134 }CRYPTO_METHOD; 135 136 /** 137 * The enum of the encryption/decryption way. 138 */ 139 typedef enum __CRYPTO_WAY { 140 CRYPTO_WAY_ENCRYPT = 0, // /< Encryption 141 CRYPTO_WAY_DECRYPT // /< Decryption 142 }CRYPTO_WAY; 143 144 typedef enum __CRYPTO_RNG_SWITCH { 145 CRYPTO_RNG_SWITCH_16 = 0, 146 CRYPTO_RNG_SWITCH_32 147 }CRYPTO_RNG_SWITCH; 148 149 /** 150 * The enum of the encryption/decryption mode, only for (aes des 3des). 151 */ 152 typedef enum __CRYPTO_MODE { 153 CRYPTO_MODE_ECB = 0, // /< ECB 154 CRYPTO_MODE_CBC, // /< CBC 155 CRYPTO_MODE_CTR, // /< CTR, only for AES 156 CRYPTO_MODE_CMAC // /< MAC, only for AES 157 }CRYPTO_MODE; 158 /** 159 * The enum of the CRC type. 160 */ 161 typedef enum __CRYPTO_CRC_TYPE { 162 CRYPTO_CRC_TYPE_8 = 0, // /< 8 bits CRC 163 CRYPTO_CRC_TYPE_16_MODBUS, // /< 16 bits Modbus CRC 164 CRYPTO_CRC_TYPE_16_CCITT, // /< 16 bits CCITT CRC 165 CRYPTO_CRC_TYPE_32 // /< 32 bits CRC 166 }CRYPTO_CRC_TYPE; 167 168 /** 169 * The struct of the CRC context. 170 */ 171 typedef struct { 172 u32 state; // /< The initial value input and result value output. 173 u8 type; // /< The type of CRC, refernec the CRYPTO_CRC_TYPE enum. 174 u8 mode; // /< The mode of CRC, bit0 means output reflection and bit1 means input reflection. 175 }psCrcContext_t; 176 177 #if 1 178 typedef u32 hstm_digit; 179 typedef struct { 180 int16 used, alloc, sign; 181 hstm_digit *dp; 182 } hstm_int; 183 184 typedef struct { 185 # ifdef HAVE_NATIVE_INT64 186 uint64 length; 187 # else 188 uint32 lengthHi; 189 uint32 lengthLo; 190 # endif /* HAVE_NATIVE_INT64 */ 191 uint32 state[5], curlen; 192 unsigned char buf[64]; 193 } psSha1_t; 194 typedef struct { 195 # ifdef HAVE_NATIVE_INT64 196 uint64 length; 197 # else 198 uint32 lengthHi; 199 uint32 lengthLo; 200 # endif /* HAVE_NATIVE_INT64 */ 201 uint32 state[4], curlen; 202 unsigned char buf[64]; 203 } psMd5_t; 204 205 typedef struct { 206 union { 207 psSha1_t sha1; 208 psMd5_t md5; 209 } u; 210 int32_t hashAlgId; 211 } psDigestContext_t; 212 213 # define AES_BLOCKLEN 16 214 # define AES_IVLEN AES_BLOCKLEN 215 # define AES128_KEYLEN 16 216 # define AES192_KEYLEN 24 217 # define AES256_KEYLEN 32 218 # define DES3_BLOCKLEN 8 219 # define DES3_IVLEN DES3_BLOCKLEN 220 # define DES3_KEYLEN 24 221 222 typedef struct { 223 uint32_t skey[64]; /**< Key schedule (either encrypt or decrypt) */ 224 uint16_t rounds; /**< Number of rounds */ 225 uint16_t type; /**< PS_AES_ENCRYPT or PS_AES_DECRYPT (inverse) key */ 226 } psAesKey_t; 227 typedef struct { 228 psAesKey_t key; 229 unsigned char IV[AES_BLOCKLEN]; 230 } psAesCbc_t; 231 232 typedef struct { 233 unsigned char state[256]; 234 uint32_t byteCount; 235 unsigned char x; 236 unsigned char y; 237 } psArc4_t; 238 239 typedef struct { 240 uint32_t ek[3][32]; 241 uint32_t dk[3][32]; 242 } psDes3Key_t; 243 244 typedef struct { 245 psDes3Key_t key; 246 unsigned char IV[DES3_BLOCKLEN]; 247 uint32_t blocklen; 248 } psDes3_t; 249 250 typedef union { 251 psAesCbc_t aes; 252 psArc4_t arc4; 253 psDes3_t des3; 254 } psCipherContext_t; 255 256 #endif 257 258 struct wm_crypto_ctx { 259 volatile u8 rsa_complete; 260 volatile u8 gpsec_complete; 261 #ifndef CONFIG_KERNEL_NONE 262 tls_os_sem_t *gpsec_lock; 263 #endif 264 }; 265 266 /** 267 * @defgroup System_APIs System APIs 268 * @brief System APIs 269 */ 270 271 /** 272 * @addtogroup System_APIs 273 * @{ 274 */ 275 276 /** 277 * @defgroup HARD_CRYPTO_APIs HARD CRYPTO APIs 278 * @brief hard crypto APIs 279 */ 280 281 /** 282 * @addtogroup HARD_CRYPTO_APIs 283 * @{ 284 */ 285 286 /** 287 * @brief This function is used to stop random produce. 288 * 289 * @param[in] None 290 * 291 * @retval 0 success 292 * @retval other failed 293 * 294 * @note None 295 */ 296 int tls_crypto_random_stop(void); 297 298 /** 299 * @brief This function initializes random digit seed and BIT number. 300 * 301 * @param[in] seed The random digit seed. 302 * @param[in] rng_switch The random digit bit number. (0: 16bit 1:32bit) 303 * 304 * @retval 0 success 305 * @retval other failed 306 * 307 * @note None 308 */ 309 int tls_crypto_random_init(u32 seed, CRYPTO_RNG_SWITCH rng_switch); 310 311 /** 312 * @brief This function is used to get random digit content. 313 * 314 * @param[in] out Pointer to the output of random digit. 315 * @param[in] len The random digit bit number will output. 316 * 317 * @retval 0 success 318 * @retval other failed 319 * 320 * @note None 321 */ 322 int tls_crypto_random_bytes(unsigned char *out, u32 len); 323 324 /** 325 * @brief This function is used to generate true random number. 326 * 327 * @param[in] out Pointer to the output of random number. 328 * @param[in] len The random number length. 329 * 330 * @retval 0 success 331 * @retval other failed 332 * 333 * @note None 334 */ 335 int tls_crypto_trng(unsigned char *out, u32 len); 336 337 /** 338 * @brief This function initializes a RC4 encryption algorithm, 339 * i.e. fills the psCipherContext_t structure pointed to by ctx with necessary data. 340 * 341 * @param[in] ctx Pointer to the Cipher Context. 342 * @param[in] key Pointer to the key. 343 * @param[in] keylen the length of key. 344 * 345 * @retval 0 success 346 * @retval other failed 347 348 * 349 * @note The first parameter ctx must be a structure which is allocated externally. 350 * And all of Context parameters in the initializing methods should be allocated externally too. 351 */ 352 int tls_crypto_rc4_init(psCipherContext_t *ctx, const unsigned char *key, u32 keylen); 353 354 /** 355 * @brief This function encrypts a variable length data stream according to RC4. 356 * The RC4 algorithm it generates a "keystream" 357 * which is simply XORed with the plaintext to produce the ciphertext stream. 358 * Decryption is exactly the same as encryption. 359 * This function also decrypts a variable length data stream according to RC4. 360 * 361 * @param[in] ctx Pointer to the Cipher Context. 362 * @param[in] in Pointer to the input plaintext data stream(or the encrypted text data stream) of variable length. 363 * @param[in] out Pointer to the resulting ciphertext data stream. 364 * @param[in] len Length of the plaintext data stream in octets. 365 * 366 * @retval 0 success 367 * @retval other failed 368 * 369 * @note None 370 */ 371 int tls_crypto_rc4(psCipherContext_t *ctx, unsigned char *in, unsigned char *out, u32 len); 372 373 /** 374 * @brief This function initializes a AES encryption algorithm, 375 * i.e. fills the psCipherContext_t structure pointed to by ctx with necessary data. 376 * 377 * @param[in] ctx Pointer to the Cipher Context. 378 * @param[in] IV Pointer to the Initialization Vector 379 * @param[in] key Pointer to the key. 380 * @param[in] keylen the length of key. 381 * @param[in] cbc the encryption mode, AES supports ECB/CBC/CTR modes. 382 * 383 * @retval 0 success 384 * @retval other failed 385 * 386 * @note None 387 */ 388 int tls_crypto_aes_init(psCipherContext_t *ctx, const unsigned char *IV, 389 const unsigned char *key, u32 keylen, CRYPTO_MODE cbc); 390 391 /** 392 * @brief This function encrypts or decrypts a variable length data stream according to AES. 393 * 394 * @param[in] ctx Pointer to the Cipher Context. 395 * @param[in] in Pointer to the input plaintext data stream(or the encrypted text data stream) of variable length. 396 * @param[in] out Pointer to the resulting ciphertext data stream. 397 * @param[in] len Length of the plaintext data stream in octets. 398 * @param[in] dec The cryption way which indicates encryption or decryption. 399 * 400 * @retval 0 success 401 * @retval other failed 402 * 403 * @note None 404 */ 405 int tls_crypto_aes_encrypt_decrypt(psCipherContext_t *ctx, unsigned char *in, 406 unsigned char *out, u32 len, CRYPTO_WAY dec); 407 408 /** 409 * @brief This function initializes a 3DES encryption algorithm, 410 * i.e. fills the psCipherContext_t structure pointed to by ctx with necessary data. 411 * 412 * @param[in] ctx Pointer to the Cipher Context. 413 * @param[in] IV Pointer to the Initialization Vector 414 * @param[in] key Pointer to the key. 415 * @param[in] keylen the length of key. 416 * @param[in] cbc the encryption mode, 3DES supports ECB/CBC modes. 417 * 418 * @retval 0 success 419 * @retval other failed 420 * 421 * @note None 422 */ 423 int tls_crypto_3des_init(psCipherContext_t *ctx, const unsigned char *IV, 424 const unsigned char *key, u32 keylen, CRYPTO_MODE cbc); 425 426 /** 427 * @brief This function encrypts or decrypts a variable length data stream according to 3DES. 428 * 429 * @param[in] ctx Pointer to the Cipher Context. 430 * @param[in] in Pointer to the input plaintext data stream(or the encrypted text data stream) of variable length. 431 * @param[in] out Pointer to the resulting ciphertext data stream. 432 * @param[in] len Length of the plaintext data stream in octets. 433 * @param[in] dec The cryption way which indicates encryption or decryption. 434 * 435 * @retval 0 success 436 * @retval other failed 437 * 438 * @note None 439 */ 440 int tls_crypto_3des_encrypt_decrypt(psCipherContext_t *ctx, unsigned char *in, 441 unsigned char *out, u32 len, CRYPTO_WAY dec); 442 443 /** 444 * @brief This function initializes a DES encryption algorithm, 445 * i.e. fills the psCipherContext_t structure pointed to by ctx with necessary data. 446 * 447 * @param[in] ctx Pointer to the Cipher Context. 448 * @param[in] IV Pointer to the Initialization Vector 449 * @param[in] key Pointer to the key. 450 * @param[in] keylen the length of key. 451 * @param[in] cbc the encryption mode, DES supports ECB/CBC modes. 452 * 453 * @retval 0 success 454 * @retval other failed 455 * 456 * @note None 457 */ 458 int tls_crypto_des_init(psCipherContext_t *ctx, const unsigned char *IV, 459 const unsigned char *key, u32 keylen, CRYPTO_MODE cbc); 460 461 /** 462 * @brief This function encrypts or decrypts a variable length data stream according to DES. 463 * 464 * @param[in] ctx Pointer to the Cipher Context. 465 * @param[in] in Pointer to the input plaintext data stream(or the encrypted text data stream) of variable length. 466 * @param[in] out Pointer to the resulting ciphertext data stream. 467 * @param[in] len Length of the plaintext data stream in octets. 468 * @param[in] dec The cryption way which indicates encryption or decryption. 469 * 470 * @retval 0 success 471 * @retval other failed 472 * 473 * @note None 474 */ 475 int tls_crypto_des_encrypt_decrypt(psCipherContext_t *ctx, unsigned char *in, 476 unsigned char *out, u32 len, CRYPTO_WAY dec); 477 478 /** 479 * @brief This function initializes a CRC algorithm, 480 * i.e. fills the psCrcContext_t structure pointed to by ctx with necessary data. 481 * 482 * @param[in] ctx Pointer to the CRC Context. 483 * @param[in] key The initialization key. 484 * @param[in] crc_type The CRC type, supports CRC8/CRC16 MODBUS/CRC16 CCITT/CRC32 485 * @param[in] mode Set input or outpu reflect. 486 * @param[in] dec The cryption way which indicates encryption or decryption. 487 * see OUTPUT_REFLECT 488 * see INPUT_REFLECT 489 * 490 * @retval 0 success 491 * @retval other failed 492 * 493 * @note None 494 */ 495 int tls_crypto_crc_init(psCrcContext_t *ctx, u32 key, CRYPTO_CRC_TYPE crc_type, u8 mode); 496 497 /** 498 * @brief This function updates the CRC value with a variable length bytes. 499 * This function may be called as many times as necessary, so the message may be processed in blocks. 500 * 501 * @param[in] ctx Pointer to the CRC Context. 502 * @param[in] in Pointer to a variable length bytes 503 * @param[in] len The bytes 's length 504 * 505 * @retval 0 success 506 * @retval other failed 507 * 508 * @note None 509 */ 510 int tls_crypto_crc_update(psCrcContext_t *ctx, unsigned char *in, u32 len); 511 512 /** 513 * @brief This function ends a CRC operation and produces a CRC value. 514 * 515 * @param[in] ctx Pointer to the CRC Context. 516 * @param[in] crc_val Pointer to the CRC value. 517 * 518 * @retval 0 success 519 * @retval other failed 520 * 521 * @note None 522 */ 523 int tls_crypto_crc_final(psCrcContext_t *ctx, u32 *crc_val); 524 525 /** 526 * @brief This function initializes Message-Diggest context for usage in SHA1 algorithm, 527 * starts a new SHA1 operation and writes a new Digest Context. 528 * 529 * @param[in] md Pointer to the SHA1 Digest Context. 530 * 531 * @retval 0 success 532 * @retval other failed 533 * 534 * @note None 535 */ 536 void tls_crypto_sha1_init(psDigestContext_t *md); 537 538 /** 539 * @brief Process a message block using SHA1 algorithm. 540 * This function performs a SHA1 block update operation. It continues an SHA1 message-digest operation, 541 * by processing InputLen-byte length message block pointed to by buf, 542 * and by updating the SHA1 context pointed to by md. 543 * This function may be called as many times as necessary, so the message may be processed in blocks. 544 * 545 * @param[in] md Pointer to the SHA1 Digest Context. 546 * @param[in] buf InputLen-byte length message block 547 * @param[in] len The buf 's length 548 * 549 * @returnl None 550 * 551 * @note None 552 */ 553 void tls_crypto_sha1_update(psDigestContext_t *md, const unsigned char *buf, u32 len); 554 555 /** 556 * @brief This function ends a SHA1 operation and produces a Message-Digest. 557 * This function finalizes SHA1 algorithm, i.e. ends an SHA1 Message-Digest operation, 558 * writing the Message-Digest in the 20-byte buffer pointed to by hash in according to 559 * the information stored in context. 560 * 561 * @param[in] md Pointer to the SHA1 Digest Context. 562 * @param[in] hash Pointer to the Message-Digest 563 * 564 * @retval 20 success, return the hash size. 565 * @retval <0 failed 566 567 * 568 * @note None 569 */ 570 int tls_crypto_sha1_final(psDigestContext_t *md, unsigned char *hash); 571 572 /** 573 * @brief This function initializes Message-Diggest context for usage in MD5 algorithm, 574 * starts a new MD5 operation and writes a new Digest Context. 575 * This function begins a MD5 Message-Diggest Algorithm, 576 * i.e. fills the psDigestContext_t structure pointed to by md with necessary data. 577 * MD5 is the algorithm which takes as input a message of arbitrary length 578 * and produces as output a 128-bit "fingerprint" or "message digest" of the input. 579 * It is conjectured that it is computationally infeasible to produce two messages having the same message digest, 580 * or to produce any message having a given prespecified target message digest. 581 * 582 * @param[in] md MD5 Digest Context. 583 * 584 * @return None 585 * 586 * @note None 587 */ 588 void tls_crypto_md5_init(psDigestContext_t *md); 589 590 /** 591 * @brief Process a message block using MD5 algorithm. 592 * This function performs a MD5 block update operation. It continues an MD5 message-digest operation, 593 * by processing InputLen-byte length message block pointed to by buf, 594 * and by updating the MD5 context pointed to by md. 595 * This function may be called as many times as necessary, so the message may be processed in blocks. 596 * 597 * @param[in] md MD5 Digest Context. 598 * @param[in] buf InputLen-byte length message block 599 * @param[in] len The buf 's length 600 * 601 * @return None 602 * 603 * @note None 604 */ 605 void tls_crypto_md5_update(psDigestContext_t *md, const unsigned char *buf, u32 len); 606 607 /** 608 * @brief This function ends a MD5 operation and produces a Message-Digest. 609 * This function finalizes MD5 algorithm, i.e. ends an MD5 Message-Digest operation, 610 * writing the Message-Digest in the 16-byte buffer pointed to by hash in according 611 * to the information stored in context. 612 * 613 * @param[in] md MD5 Digest Context. 614 * @param[in] hash the Message-Digest 615 * 616 * @retval 16 success, return the hash size. 617 * @retval <0 failed 618 * 619 * @note None 620 */ 621 int tls_crypto_md5_final(psDigestContext_t *md, unsigned char *hash); 622 623 /** 624 * @brief This function implements the large module power multiplication algorithm. 625 * res = a**e (mod n) 626 * 627 * @param[in] a Pointer to a bignumber. 628 * @param[in] e Pointer to a bignumber. 629 * @param[in] n Pointer to a bignumber. 630 * @param[out] res Pointer to the result bignumber. 631 * 632 * @retval 0 success 633 * @retval other failed 634 * 635 * @note None 636 */ 637 int tls_crypto_exptmod(hstm_int *a, hstm_int *e, hstm_int *n, hstm_int *res); 638 639 /** 640 * @brief This function initializes the encryption module. 641 * 642 * @param None 643 * 644 * @retval 0 success 645 * @retval other failed 646 * 647 * @note None 648 */ 649 int tls_crypto_init(void); 650 651 /** 652 * @} 653 */ 654 655 /** 656 * @} 657 */ 658 659 #endif 660 661