|
22 | 22 |
|
23 | 23 |
|
24 | 24 | AES = lazy_import.lazy_module("Crypto.Cipher.AES") |
| 25 | +Salsa20 = lazy_import.lazy_module("Crypto.Cipher.Salsa20") |
25 | 26 | ARC4 = lazy_import.lazy_module("Crypto.Cipher.ARC4") |
26 | 27 | DES = lazy_import.lazy_module("Crypto.Cipher.DES") |
27 | 28 | ChaCha20 = lazy_import.lazy_module("Crypto.Cipher.ChaCha20") |
@@ -705,6 +706,58 @@ def des_decrypt( |
705 | 706 | self.state = cipher.decrypt(self._convert_to_bytes()) |
706 | 707 | return self |
707 | 708 |
|
| 709 | + @ChepyDecorators.call_stack |
| 710 | + def salsa20_encrypt( |
| 711 | + self, |
| 712 | + key: str, |
| 713 | + nonce: str = "0000000000000000", |
| 714 | + key_format: str = "hex", |
| 715 | + nonce_format: str = "hex", |
| 716 | + ) -> EncryptionEncodingT: |
| 717 | + """Encrypt raw state with Salsa 20 rounds |
| 718 | +
|
| 719 | + Args: |
| 720 | + key (str): Required. The secret key |
| 721 | + nonce (str, optional): Nonce. Defaults to '0000000000000000'. |
| 722 | + key_format (str, optional): Format of key. Defaults to 'hex'. |
| 723 | + nonce_format (str, optional): Format of nonce. Defaults to 'hex'. |
| 724 | +
|
| 725 | + Returns: |
| 726 | + Chepy: The Chepy object. |
| 727 | + """ |
| 728 | + |
| 729 | + key, nonce = self._convert_key(key, nonce, key_format, nonce_format) |
| 730 | + |
| 731 | + cipher = Salsa20.new(key=key, nonce=nonce) |
| 732 | + self.state = cipher.encrypt(self._convert_to_bytes()) |
| 733 | + return self |
| 734 | + |
| 735 | + @ChepyDecorators.call_stack |
| 736 | + def salsa20_decrypt( |
| 737 | + self, |
| 738 | + key: str, |
| 739 | + nonce: str = "0000000000000000", |
| 740 | + key_format: str = "hex", |
| 741 | + nonce_format: str = "hex", |
| 742 | + ) -> EncryptionEncodingT: |
| 743 | + """Decrypt raw state encrypted with ChaCha 20 rounds. |
| 744 | +
|
| 745 | + Args: |
| 746 | + key (str): Required. The secret key |
| 747 | + nonce (str, optional): nonce for certain modes only. Defaults to '0000000000000000'. |
| 748 | + key_format (str, optional): Format of key. Defaults to 'hex'. |
| 749 | + nonce_format (str, optional): Format of nonce. Defaults to 'hex'. |
| 750 | +
|
| 751 | + Returns: |
| 752 | + Chepy: The Chepy object. |
| 753 | + """ |
| 754 | + |
| 755 | + key, nonce = self._convert_key(key, nonce, key_format, nonce_format) |
| 756 | + |
| 757 | + cipher = Salsa20.new(key=key, nonce=nonce) |
| 758 | + self.state = cipher.decrypt(self._convert_to_bytes()) |
| 759 | + return self |
| 760 | + |
708 | 761 | @ChepyDecorators.call_stack |
709 | 762 | def chacha_encrypt( |
710 | 763 | self, |
|
0 commit comments