Linux cpanel.rrshost.in 5.15.0-25-generic #25-Ubuntu SMP Wed Mar 30 15:54:22 UTC 2022 x86_64
Apache
: 109.123.238.221 | : 172.69.130.108
128 Domain
8.2.28
aev999
Terminal
AUTO ROOT
Adminer
Backdoor Destroyer
Linux Exploit
Lock Shell
Lock File
Create User
CREATE RDP
PHP Mailer
BACKCONNECT
HASH IDENTIFIER
README
+ Create Folder
+ Create File
/
usr /
lib /
python3 /
dist-packages /
nacl /
bindings /
[ HOME SHELL ]
Name
Size
Permission
Action
__pycache__
[ DIR ]
drwxr-xr-x
__init__.py
16.6
KB
-rw-r--r--
crypto_aead.py
15.23
KB
-rw-r--r--
crypto_box.py
9.9
KB
-rw-r--r--
crypto_core.py
13.41
KB
-rw-r--r--
crypto_generichash.py
8.64
KB
-rw-r--r--
crypto_hash.py
2.12
KB
-rw-r--r--
crypto_kx.py
6.57
KB
-rw-r--r--
crypto_pwhash.py
18.41
KB
-rw-r--r--
crypto_scalarmult.py
8.05
KB
-rw-r--r--
crypto_secretbox.py
2.85
KB
-rw-r--r--
crypto_secretstream.py
10.9
KB
-rw-r--r--
crypto_shorthash.py
2.54
KB
-rw-r--r--
crypto_sign.py
10.1
KB
-rw-r--r--
randombytes.py
1.53
KB
-rw-r--r--
sodium_core.py
1.01
KB
-rw-r--r--
utils.py
4.2
KB
-rw-r--r--
Delete
Unzip
Zip
${this.title}
Close
Code Editor : crypto_aead.py
# Copyright 2017 Donald Stufft and individual contributors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from typing import Optional from nacl import exceptions as exc from nacl._sodium import ffi, lib from nacl.exceptions import ensure """ Implementations of authenticated encription with associated data (*AEAD*) constructions building on the chacha20 stream cipher and the poly1305 authenticator """ crypto_aead_chacha20poly1305_ietf_KEYBYTES: int = ( lib.crypto_aead_chacha20poly1305_ietf_keybytes() ) crypto_aead_chacha20poly1305_ietf_NSECBYTES: int = ( lib.crypto_aead_chacha20poly1305_ietf_nsecbytes() ) crypto_aead_chacha20poly1305_ietf_NPUBBYTES: int = ( lib.crypto_aead_chacha20poly1305_ietf_npubbytes() ) crypto_aead_chacha20poly1305_ietf_ABYTES: int = ( lib.crypto_aead_chacha20poly1305_ietf_abytes() ) crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX: int = ( lib.crypto_aead_chacha20poly1305_ietf_messagebytes_max() ) _aead_chacha20poly1305_ietf_CRYPTBYTES_MAX = ( crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX + crypto_aead_chacha20poly1305_ietf_ABYTES ) crypto_aead_chacha20poly1305_KEYBYTES: int = ( lib.crypto_aead_chacha20poly1305_keybytes() ) crypto_aead_chacha20poly1305_NSECBYTES: int = ( lib.crypto_aead_chacha20poly1305_nsecbytes() ) crypto_aead_chacha20poly1305_NPUBBYTES: int = ( lib.crypto_aead_chacha20poly1305_npubbytes() ) crypto_aead_chacha20poly1305_ABYTES: int = ( lib.crypto_aead_chacha20poly1305_abytes() ) crypto_aead_chacha20poly1305_MESSAGEBYTES_MAX: int = ( lib.crypto_aead_chacha20poly1305_messagebytes_max() ) _aead_chacha20poly1305_CRYPTBYTES_MAX = ( crypto_aead_chacha20poly1305_MESSAGEBYTES_MAX + crypto_aead_chacha20poly1305_ABYTES ) crypto_aead_xchacha20poly1305_ietf_KEYBYTES: int = ( lib.crypto_aead_xchacha20poly1305_ietf_keybytes() ) crypto_aead_xchacha20poly1305_ietf_NSECBYTES: int = ( lib.crypto_aead_xchacha20poly1305_ietf_nsecbytes() ) crypto_aead_xchacha20poly1305_ietf_NPUBBYTES: int = ( lib.crypto_aead_xchacha20poly1305_ietf_npubbytes() ) crypto_aead_xchacha20poly1305_ietf_ABYTES: int = ( lib.crypto_aead_xchacha20poly1305_ietf_abytes() ) crypto_aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX: int = ( lib.crypto_aead_xchacha20poly1305_ietf_messagebytes_max() ) _aead_xchacha20poly1305_ietf_CRYPTBYTES_MAX = ( crypto_aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX + crypto_aead_xchacha20poly1305_ietf_ABYTES ) def crypto_aead_chacha20poly1305_ietf_encrypt( message: bytes, aad: Optional[bytes], nonce: bytes, key: bytes ) -> bytes: """ Encrypt the given ``message`` using the IETF ratified chacha20poly1305 construction described in RFC7539. :param message: :type message: bytes :param aad: :type aad: Optional[bytes] :param nonce: :type nonce: bytes :param key: :type key: bytes :return: authenticated ciphertext :rtype: bytes """ ensure( isinstance(message, bytes), "Input message type must be bytes", raising=exc.TypeError, ) mlen = len(message) ensure( mlen <= crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX, "Message must be at most {} bytes long".format( crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX ), raising=exc.ValueError, ) ensure( isinstance(aad, bytes) or (aad is None), "Additional data must be bytes or None", raising=exc.TypeError, ) ensure( isinstance(nonce, bytes) and len(nonce) == crypto_aead_chacha20poly1305_ietf_NPUBBYTES, "Nonce must be a {} bytes long bytes sequence".format( crypto_aead_chacha20poly1305_ietf_NPUBBYTES ), raising=exc.TypeError, ) ensure( isinstance(key, bytes) and len(key) == crypto_aead_chacha20poly1305_ietf_KEYBYTES, "Key must be a {} bytes long bytes sequence".format( crypto_aead_chacha20poly1305_ietf_KEYBYTES ), raising=exc.TypeError, ) if aad: _aad = aad aalen = len(aad) else: _aad = ffi.NULL aalen = 0 mxout = mlen + crypto_aead_chacha20poly1305_ietf_ABYTES clen = ffi.new("unsigned long long *") ciphertext = ffi.new("unsigned char[]", mxout) res = lib.crypto_aead_chacha20poly1305_ietf_encrypt( ciphertext, clen, message, mlen, _aad, aalen, ffi.NULL, nonce, key ) ensure(res == 0, "Encryption failed.", raising=exc.CryptoError) return ffi.buffer(ciphertext, clen[0])[:] def crypto_aead_chacha20poly1305_ietf_decrypt( ciphertext: bytes, aad: Optional[bytes], nonce: bytes, key: bytes ) -> bytes: """ Decrypt the given ``ciphertext`` using the IETF ratified chacha20poly1305 construction described in RFC7539. :param ciphertext: :type ciphertext: bytes :param aad: :type aad: Optional[bytes] :param nonce: :type nonce: bytes :param key: :type key: bytes :return: message :rtype: bytes """ ensure( isinstance(ciphertext, bytes), "Input ciphertext type must be bytes", raising=exc.TypeError, ) clen = len(ciphertext) ensure( clen <= _aead_chacha20poly1305_ietf_CRYPTBYTES_MAX, "Ciphertext must be at most {} bytes long".format( _aead_chacha20poly1305_ietf_CRYPTBYTES_MAX ), raising=exc.ValueError, ) ensure( isinstance(aad, bytes) or (aad is None), "Additional data must be bytes or None", raising=exc.TypeError, ) ensure( isinstance(nonce, bytes) and len(nonce) == crypto_aead_chacha20poly1305_ietf_NPUBBYTES, "Nonce must be a {} bytes long bytes sequence".format( crypto_aead_chacha20poly1305_ietf_NPUBBYTES ), raising=exc.TypeError, ) ensure( isinstance(key, bytes) and len(key) == crypto_aead_chacha20poly1305_ietf_KEYBYTES, "Key must be a {} bytes long bytes sequence".format( crypto_aead_chacha20poly1305_ietf_KEYBYTES ), raising=exc.TypeError, ) mxout = clen - crypto_aead_chacha20poly1305_ietf_ABYTES mlen = ffi.new("unsigned long long *") message = ffi.new("unsigned char[]", mxout) if aad: _aad = aad aalen = len(aad) else: _aad = ffi.NULL aalen = 0 res = lib.crypto_aead_chacha20poly1305_ietf_decrypt( message, mlen, ffi.NULL, ciphertext, clen, _aad, aalen, nonce, key ) ensure(res == 0, "Decryption failed.", raising=exc.CryptoError) return ffi.buffer(message, mlen[0])[:] def crypto_aead_chacha20poly1305_encrypt( message: bytes, aad: Optional[bytes], nonce: bytes, key: bytes ) -> bytes: """ Encrypt the given ``message`` using the "legacy" construction described in draft-agl-tls-chacha20poly1305. :param message: :type message: bytes :param aad: :type aad: Optional[bytes] :param nonce: :type nonce: bytes :param key: :type key: bytes :return: authenticated ciphertext :rtype: bytes """ ensure( isinstance(message, bytes), "Input message type must be bytes", raising=exc.TypeError, ) mlen = len(message) ensure( mlen <= crypto_aead_chacha20poly1305_MESSAGEBYTES_MAX, "Message must be at most {} bytes long".format( crypto_aead_chacha20poly1305_MESSAGEBYTES_MAX ), raising=exc.ValueError, ) ensure( isinstance(aad, bytes) or (aad is None), "Additional data must be bytes or None", raising=exc.TypeError, ) ensure( isinstance(nonce, bytes) and len(nonce) == crypto_aead_chacha20poly1305_NPUBBYTES, "Nonce must be a {} bytes long bytes sequence".format( crypto_aead_chacha20poly1305_NPUBBYTES ), raising=exc.TypeError, ) ensure( isinstance(key, bytes) and len(key) == crypto_aead_chacha20poly1305_KEYBYTES, "Key must be a {} bytes long bytes sequence".format( crypto_aead_chacha20poly1305_KEYBYTES ), raising=exc.TypeError, ) if aad: _aad = aad aalen = len(aad) else: _aad = ffi.NULL aalen = 0 mlen = len(message) mxout = mlen + crypto_aead_chacha20poly1305_ietf_ABYTES clen = ffi.new("unsigned long long *") ciphertext = ffi.new("unsigned char[]", mxout) res = lib.crypto_aead_chacha20poly1305_encrypt( ciphertext, clen, message, mlen, _aad, aalen, ffi.NULL, nonce, key ) ensure(res == 0, "Encryption failed.", raising=exc.CryptoError) return ffi.buffer(ciphertext, clen[0])[:] def crypto_aead_chacha20poly1305_decrypt( ciphertext: bytes, aad: Optional[bytes], nonce: bytes, key: bytes ) -> bytes: """ Decrypt the given ``ciphertext`` using the "legacy" construction described in draft-agl-tls-chacha20poly1305. :param ciphertext: authenticated ciphertext :type ciphertext: bytes :param aad: :type aad: Optional[bytes] :param nonce: :type nonce: bytes :param key: :type key: bytes :return: message :rtype: bytes """ ensure( isinstance(ciphertext, bytes), "Input ciphertext type must be bytes", raising=exc.TypeError, ) clen = len(ciphertext) ensure( clen <= _aead_chacha20poly1305_CRYPTBYTES_MAX, "Ciphertext must be at most {} bytes long".format( _aead_chacha20poly1305_CRYPTBYTES_MAX ), raising=exc.ValueError, ) ensure( isinstance(aad, bytes) or (aad is None), "Additional data must be bytes or None", raising=exc.TypeError, ) ensure( isinstance(nonce, bytes) and len(nonce) == crypto_aead_chacha20poly1305_NPUBBYTES, "Nonce must be a {} bytes long bytes sequence".format( crypto_aead_chacha20poly1305_NPUBBYTES ), raising=exc.TypeError, ) ensure( isinstance(key, bytes) and len(key) == crypto_aead_chacha20poly1305_KEYBYTES, "Key must be a {} bytes long bytes sequence".format( crypto_aead_chacha20poly1305_KEYBYTES ), raising=exc.TypeError, ) mxout = clen - crypto_aead_chacha20poly1305_ABYTES mlen = ffi.new("unsigned long long *") message = ffi.new("unsigned char[]", mxout) if aad: _aad = aad aalen = len(aad) else: _aad = ffi.NULL aalen = 0 res = lib.crypto_aead_chacha20poly1305_decrypt( message, mlen, ffi.NULL, ciphertext, clen, _aad, aalen, nonce, key ) ensure(res == 0, "Decryption failed.", raising=exc.CryptoError) return ffi.buffer(message, mlen[0])[:] def crypto_aead_xchacha20poly1305_ietf_encrypt( message: bytes, aad: Optional[bytes], nonce: bytes, key: bytes ) -> bytes: """ Encrypt the given ``message`` using the long-nonces xchacha20poly1305 construction. :param message: :type message: bytes :param aad: :type aad: Optional[bytes] :param nonce: :type nonce: bytes :param key: :type key: bytes :return: authenticated ciphertext :rtype: bytes """ ensure( isinstance(message, bytes), "Input message type must be bytes", raising=exc.TypeError, ) mlen = len(message) ensure( mlen <= crypto_aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX, "Message must be at most {} bytes long".format( crypto_aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX ), raising=exc.ValueError, ) ensure( isinstance(aad, bytes) or (aad is None), "Additional data must be bytes or None", raising=exc.TypeError, ) ensure( isinstance(nonce, bytes) and len(nonce) == crypto_aead_xchacha20poly1305_ietf_NPUBBYTES, "Nonce must be a {} bytes long bytes sequence".format( crypto_aead_xchacha20poly1305_ietf_NPUBBYTES ), raising=exc.TypeError, ) ensure( isinstance(key, bytes) and len(key) == crypto_aead_xchacha20poly1305_ietf_KEYBYTES, "Key must be a {} bytes long bytes sequence".format( crypto_aead_xchacha20poly1305_ietf_KEYBYTES ), raising=exc.TypeError, ) if aad: _aad = aad aalen = len(aad) else: _aad = ffi.NULL aalen = 0 mlen = len(message) mxout = mlen + crypto_aead_xchacha20poly1305_ietf_ABYTES clen = ffi.new("unsigned long long *") ciphertext = ffi.new("unsigned char[]", mxout) res = lib.crypto_aead_xchacha20poly1305_ietf_encrypt( ciphertext, clen, message, mlen, _aad, aalen, ffi.NULL, nonce, key ) ensure(res == 0, "Encryption failed.", raising=exc.CryptoError) return ffi.buffer(ciphertext, clen[0])[:] def crypto_aead_xchacha20poly1305_ietf_decrypt( ciphertext: bytes, aad: Optional[bytes], nonce: bytes, key: bytes ) -> bytes: """ Decrypt the given ``ciphertext`` using the long-nonces xchacha20poly1305 construction. :param ciphertext: authenticated ciphertext :type ciphertext: bytes :param aad: :type aad: Optional[bytes] :param nonce: :type nonce: bytes :param key: :type key: bytes :return: message :rtype: bytes """ ensure( isinstance(ciphertext, bytes), "Input ciphertext type must be bytes", raising=exc.TypeError, ) clen = len(ciphertext) ensure( clen <= _aead_xchacha20poly1305_ietf_CRYPTBYTES_MAX, "Ciphertext must be at most {} bytes long".format( _aead_xchacha20poly1305_ietf_CRYPTBYTES_MAX ), raising=exc.ValueError, ) ensure( isinstance(aad, bytes) or (aad is None), "Additional data must be bytes or None", raising=exc.TypeError, ) ensure( isinstance(nonce, bytes) and len(nonce) == crypto_aead_xchacha20poly1305_ietf_NPUBBYTES, "Nonce must be a {} bytes long bytes sequence".format( crypto_aead_xchacha20poly1305_ietf_NPUBBYTES ), raising=exc.TypeError, ) ensure( isinstance(key, bytes) and len(key) == crypto_aead_xchacha20poly1305_ietf_KEYBYTES, "Key must be a {} bytes long bytes sequence".format( crypto_aead_xchacha20poly1305_ietf_KEYBYTES ), raising=exc.TypeError, ) mxout = clen - crypto_aead_xchacha20poly1305_ietf_ABYTES mlen = ffi.new("unsigned long long *") message = ffi.new("unsigned char[]", mxout) if aad: _aad = aad aalen = len(aad) else: _aad = ffi.NULL aalen = 0 res = lib.crypto_aead_xchacha20poly1305_ietf_decrypt( message, mlen, ffi.NULL, ciphertext, clen, _aad, aalen, nonce, key ) ensure(res == 0, "Decryption failed.", raising=exc.CryptoError) return ffi.buffer(message, mlen[0])[:]
Close