- Timestamp:
- Jun 22, 2021, 9:00:19 PM (3 years ago)
- Location:
- azure_iot_hub_f767zi/trunk/wolfssl-4.7.0
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
azure_iot_hub_f767zi/trunk/wolfssl-4.7.0/wolfcrypt/src/wc_encrypt.c
r457 r464 29 29 #include <wolfssl/wolfcrypt/des3.h> 30 30 #include <wolfssl/wolfcrypt/hash.h> 31 #include <wolfssl/wolfcrypt/rc2.h> 31 32 #include <wolfssl/wolfcrypt/arc4.h> 32 33 #include <wolfssl/wolfcrypt/wc_encrypt.h> … … 239 240 240 241 241 #if def WOLFSSL_ENCRYPTED_KEYS242 #if !defined(NO_ASN) && defined(WOLFSSL_ENCRYPTED_KEYS) 242 243 243 244 int wc_BufferKeyDecrypt(EncryptedInfo* info, byte* der, word32 derSz, … … 361 362 } 362 363 363 #endif /* WOLFSSL_ENCRYPTED_KEYS */364 #endif /* !NO_ASN && WOLFSSL_ENCRYPTED_KEYS */ 364 365 365 366 … … 375 376 int length, int version, byte* cbcIv, int enc, int shaOid) 376 377 { 377 int typeH ;378 int typeH = WC_HASH_TYPE_NONE; 378 379 int derivedLen = 0; 379 380 int ret = 0; … … 456 457 break; 457 458 #endif /* WOLFSSL_AES_128 && !NO_SHA */ 459 #ifdef WC_RC2 460 case PBE_SHA1_40RC2_CBC: 461 typeH = WC_SHA; 462 derivedLen = 5; 463 break; 464 #endif 458 465 default: 459 466 WOLFSSL_MSG("Unknown/Unsupported encrypt/decrypt id"); … … 612 619 case PBE_AES128_CBC: 613 620 { 614 Aes aes; 615 ret = wc_AesInit(&aes, NULL, INVALID_DEVID); 621 #ifdef WOLFSSL_SMALL_STACK 622 Aes *aes; 623 aes = (Aes *)XMALLOC(sizeof *aes, NULL, DYNAMIC_TYPE_AES); 624 if (aes == NULL) 625 return MEMORY_E; 626 #else 627 Aes aes[1]; 628 #endif 629 ret = wc_AesInit(aes, NULL, INVALID_DEVID); 616 630 if (ret == 0) { 617 631 if (enc) { 618 ret = wc_AesSetKey( &aes, key, derivedLen, cbcIv,632 ret = wc_AesSetKey(aes, key, derivedLen, cbcIv, 619 633 AES_ENCRYPTION); 620 634 } 621 635 else { 622 ret = wc_AesSetKey( &aes, key, derivedLen, cbcIv,636 ret = wc_AesSetKey(aes, key, derivedLen, cbcIv, 623 637 AES_DECRYPTION); 624 638 } … … 626 640 if (ret == 0) { 627 641 if (enc) 628 ret = wc_AesCbcEncrypt( &aes, input, input, length);642 ret = wc_AesCbcEncrypt(aes, input, input, length); 629 643 else 630 ret = wc_AesCbcDecrypt(&aes, input, input, length); 631 } 644 ret = wc_AesCbcDecrypt(aes, input, input, length); 645 } 646 ForceZero(aes, sizeof(Aes)); 647 #ifdef WOLFSSL_SMALL_STACK 648 XFREE(aes, NULL, DYNAMIC_TYPE_AES); 649 #endif 632 650 if (ret != 0) { 633 651 #ifdef WOLFSSL_SMALL_STACK … … 636 654 return ret; 637 655 } 638 ForceZero(&aes, sizeof(Aes));639 656 break; 640 657 } 641 658 #endif /* WOLFSSL_AES_256 */ 642 659 #endif /* !NO_AES && HAVE_AES_CBC */ 660 #ifdef WC_RC2 661 case PBE_SHA1_40RC2_CBC: 662 { 663 Rc2 rc2; 664 /* effective key size for RC2-40-CBC is 40 bits */ 665 ret = wc_Rc2SetKey(&rc2, key, derivedLen, cbcIv, 40); 666 if (ret == 0) { 667 if (enc) 668 ret = wc_Rc2CbcEncrypt(&rc2, input, input, length); 669 else 670 ret = wc_Rc2CbcDecrypt(&rc2, input, input, length); 671 } 672 if (ret != 0) { 673 #ifdef WOLFSSL_SMALL_STACK 674 XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER); 675 #endif 676 return ret; 677 } 678 ForceZero(&rc2, sizeof(Rc2)); 679 break; 680 } 681 #endif 643 682 644 683 default:
Note:
See TracChangeset
for help on using the changeset viewer.