|
82 | 82 | ECC_BRAINPOOLP384R1 = 26 |
83 | 83 | ECC_BRAINPOOLP512R1 = 27 |
84 | 84 |
|
85 | | -RSA_PKCSV15_PAD = 0 |
86 | | -RSA_OAEP_PAD = 1 |
87 | | -RSA_PSS_PAD = 2 |
88 | | -RSA_NO_PSA = 3 |
89 | | - |
90 | | -MGF1NONE = 0 |
91 | | -MGF1SHA1 = 26 |
92 | | -MGF1SHA224 = 4 |
93 | | -MGF1SHA256 = 1 |
94 | | -MGF1SHA384 = 2 |
95 | | -MGF1SHA512 = 3 |
96 | | - |
97 | | -BLOCK_TYPE_1 = 1 |
98 | | -BLOCK_TYPE_2 = 2 |
99 | | - |
100 | | -HASH_TYPE_NONE = 0 |
101 | | -HASH_TYPE_MD2 = 1 |
102 | | -HASH_TYPE_MD4 = 2 |
103 | | -HASH_TYPE_MD5 = 3 |
104 | | -HASH_TYPE_SHA = 4 |
105 | | -HASH_TYPE_SHA224 = 5 |
106 | | -HASH_TYPE_SHA256 = 6 |
107 | | -HASH_TYPE_SHA384 = 7 |
108 | | -HASH_TYPE_SHA512 = 8 |
109 | | -HASH_TYPE_MD5_SHA = 9 |
110 | | -HASH_TYPE_SHA3_224 = 10 |
111 | | -HASH_TYPE_SHA3_256 = 11 |
112 | | -HASH_TYPE_SHA3_384 = 12 |
113 | | -HASH_TYPE_SHA3_512 = 13 |
114 | | -HASH_TYPE_BLAKE2B = 14 |
115 | | -HASH_TYPE_BLAKE2S = 15 |
| 85 | +MGF1NONE = _lib.WC_MGF1NONE |
| 86 | +MGF1SHA1 = _lib.WC_MGF1SHA1 |
| 87 | +MGF1SHA224 = _lib.WC_MGF1SHA224 |
| 88 | +MGF1SHA256 = _lib.WC_MGF1SHA256 |
| 89 | +MGF1SHA384 = _lib.WC_MGF1SHA384 |
| 90 | +MGF1SHA512 = _lib.WC_MGF1SHA512 |
| 91 | + |
| 92 | +HASH_TYPE_NONE = _lib.WC_HASH_TYPE_NONE |
| 93 | +HASH_TYPE_MD2 = _lib.WC_HASH_TYPE_MD2 |
| 94 | +HASH_TYPE_MD4 = _lib.WC_HASH_TYPE_MD4 |
| 95 | +HASH_TYPE_MD5 = _lib.WC_HASH_TYPE_MD5 |
| 96 | +HASH_TYPE_SHA = _lib.WC_HASH_TYPE_SHA |
| 97 | +HASH_TYPE_SHA224 = _lib.WC_HASH_TYPE_SHA224 |
| 98 | +HASH_TYPE_SHA256 = _lib.WC_HASH_TYPE_SHA256 |
| 99 | +HASH_TYPE_SHA384 = _lib.WC_HASH_TYPE_SHA384 |
| 100 | +HASH_TYPE_SHA512 = _lib.WC_HASH_TYPE_SHA512 |
| 101 | +HASH_TYPE_MD5_SHA = _lib.WC_HASH_TYPE_MD5_SHA |
| 102 | +HASH_TYPE_SHA3_224 = _lib.WC_HASH_TYPE_SHA3_224 |
| 103 | +HASH_TYPE_SHA3_256 = _lib.WC_HASH_TYPE_SHA3_256 |
| 104 | +HASH_TYPE_SHA3_384 = _lib.WC_HASH_TYPE_SHA3_384 |
| 105 | +HASH_TYPE_SHA3_512 = _lib.WC_HASH_TYPE_SHA3_512 |
| 106 | +HASH_TYPE_BLAKE2B = _lib.WC_HASH_TYPE_BLAKE2B |
| 107 | +HASH_TYPE_BLAKE2S = _lib.WC_HASH_TYPE_BLAKE2S |
116 | 108 |
|
117 | 109 |
|
118 | 110 |
|
@@ -515,8 +507,8 @@ def encrypt_oaep(self, plaintext, hash_type, mgf, label): |
515 | 507 | ciphertext, self.output_size, |
516 | 508 | self.native_object, |
517 | 509 | self._random.native_object, |
518 | | - RSA_OAEP_PAD, hash_type, mgf, |
519 | | - label, len(label)) |
| 510 | + _lib.WC_RSA_OAEP_PAD, hash_type, |
| 511 | + mgf, label, len(label)) |
520 | 512 |
|
521 | 513 | if ret != self.output_size: # pragma: no cover |
522 | 514 | raise WolfCryptError("Encryption error (%d)" % ret) |
@@ -544,30 +536,31 @@ def verify(self, signature): |
544 | 536 |
|
545 | 537 | return _ffi.buffer(plaintext, ret)[:] |
546 | 538 |
|
547 | | - def verify_pss(self, plaintext, signature, hash_type, mgf): |
548 | | - """ |
549 | | - Verifies **signature**, using the public key data in the |
550 | | - object. The signature's length must be equal to: |
| 539 | + if _lib.RSA_PSS_ENABLED: |
| 540 | + def verify_pss(self, plaintext, signature, hash_type, mgf): |
| 541 | + """ |
| 542 | + Verifies **signature**, using the public key data in the |
| 543 | + object. The signature's length must be equal to: |
551 | 544 |
|
552 | | - **self.output_size** |
| 545 | + **self.output_size** |
553 | 546 |
|
554 | | - Returns a string containing the plaintext. |
555 | | - """ |
556 | | - plaintext = t2b(plaintext) |
557 | | - signature = t2b(signature) |
558 | | - verify = _ffi.new("byte[%d]" % self.output_size) |
| 547 | + Returns a string containing the plaintext. |
| 548 | + """ |
| 549 | + plaintext = t2b(plaintext) |
| 550 | + signature = t2b(signature) |
| 551 | + verify = _ffi.new("byte[%d]" % self.output_size) |
559 | 552 |
|
560 | | - ret = _lib.wc_RsaPSS_Verify(signature, len(signature), |
561 | | - verify, self.output_size, |
562 | | - hash_type, mgf, |
563 | | - self.native_object) |
| 553 | + ret = _lib.wc_RsaPSS_Verify(signature, len(signature), |
| 554 | + verify, self.output_size, |
| 555 | + hash_type, mgf, |
| 556 | + self.native_object) |
564 | 557 |
|
565 | | - if ret < 0: # pragma: no cover |
566 | | - raise WolfCryptError("Verify error (%d)" % ret) |
567 | | - ret = _lib.wc_RsaPSS_CheckPadding(plaintext, len(plaintext), |
568 | | - verify, ret, hash_type) |
| 558 | + if ret < 0: # pragma: no cover |
| 559 | + raise WolfCryptError("Verify error (%d)" % ret) |
| 560 | + ret = _lib.wc_RsaPSS_CheckPadding(plaintext, len(plaintext), |
| 561 | + verify, ret, hash_type) |
569 | 562 |
|
570 | | - return ret |
| 563 | + return ret |
571 | 564 |
|
572 | 565 |
|
573 | 566 |
|
@@ -687,8 +680,9 @@ def decrypt_oaep(self, ciphertext, hash_type, mgf, label): |
687 | 680 | plaintext = _ffi.new("byte[%d]" % self.output_size) |
688 | 681 | ret = _lib.wc_RsaPrivateDecrypt_ex(ciphertext, len(ciphertext), |
689 | 682 | plaintext, self.output_size, |
690 | | - self.native_object, RSA_OAEP_PAD, |
691 | | - hash_type, mgf, label, len(label)) |
| 683 | + self.native_object, |
| 684 | + _lib.WC_RSA_OAEP_PAD, hash_type, |
| 685 | + mgf, label, len(label)) |
692 | 686 |
|
693 | 687 | if ret < 0: # pragma: no cover |
694 | 688 | raise WolfCryptError("Decryption error (%d)" % ret) |
@@ -717,28 +711,29 @@ def sign(self, plaintext): |
717 | 711 |
|
718 | 712 | return _ffi.buffer(signature, self.output_size)[:] |
719 | 713 |
|
720 | | - def sign_pss(self, plaintext, hash_type, mgf): |
721 | | - """ |
722 | | - Signs **plaintext**, using the private key data in the object. |
723 | | - The plaintext's length must not be greater than: |
| 714 | + if _lib.RSA_PSS_ENABLED: |
| 715 | + def sign_pss(self, plaintext, hash_type, mgf): |
| 716 | + """ |
| 717 | + Signs **plaintext**, using the private key data in the object. |
| 718 | + The plaintext's length must not be greater than: |
724 | 719 |
|
725 | | - **self.output_size - self.RSA_MIN_PAD_SIZE** |
| 720 | + **self.output_size - self.RSA_MIN_PAD_SIZE** |
726 | 721 |
|
727 | | - Returns a string containing the signature. |
728 | | - """ |
729 | | - plaintext = t2b(plaintext) |
730 | | - signature = _ffi.new("byte[%d]" % self.output_size) |
| 722 | + Returns a string containing the signature. |
| 723 | + """ |
| 724 | + plaintext = t2b(plaintext) |
| 725 | + signature = _ffi.new("byte[%d]" % self.output_size) |
731 | 726 |
|
732 | | - ret = _lib.wc_RsaPSS_Sign(plaintext, len(plaintext), |
733 | | - signature, self.output_size, |
734 | | - hash_type, mgf, |
735 | | - self.native_object, |
736 | | - self._random.native_object) |
| 727 | + ret = _lib.wc_RsaPSS_Sign(plaintext, len(plaintext), |
| 728 | + signature, self.output_size, |
| 729 | + hash_type, mgf, |
| 730 | + self.native_object, |
| 731 | + self._random.native_object) |
737 | 732 |
|
738 | | - if ret != self.output_size: # pragma: no cover |
739 | | - raise WolfCryptError("Signature error (%d)" % ret) |
| 733 | + if ret != self.output_size: # pragma: no cover |
| 734 | + raise WolfCryptError("Signature error (%d)" % ret) |
740 | 735 |
|
741 | | - return _ffi.buffer(signature, self.output_size)[:] |
| 736 | + return _ffi.buffer(signature, self.output_size)[:] |
742 | 737 |
|
743 | 738 |
|
744 | 739 | if _lib.ECC_ENABLED: |
|
0 commit comments