File manager - Edit - /home/newsbmcs.com/public_html/static/img/logo/asymmetric.tar
Back
dh.py 0000644 00000014237 15030211711 0005507 0 ustar 00 # This file is dual licensed under the terms of the Apache License, Version # 2.0, and the BSD License. See the LICENSE file in the root of this repository # for complete details. import abc import typing from cryptography import utils from cryptography.hazmat.backends import _get_backend from cryptography.hazmat.primitives import serialization _MIN_MODULUS_SIZE = 512 def generate_parameters(generator, key_size, backend=None) -> "DHParameters": backend = _get_backend(backend) return backend.generate_dh_parameters(generator, key_size) class DHParameterNumbers(object): def __init__(self, p: int, g: int, q: typing.Optional[int] = None): if not isinstance(p, int) or not isinstance(g, int): raise TypeError("p and g must be integers") if q is not None and not isinstance(q, int): raise TypeError("q must be integer or None") if g < 2: raise ValueError("DH generator must be 2 or greater") if p.bit_length() < _MIN_MODULUS_SIZE: raise ValueError( "p (modulus) must be at least {}-bit".format(_MIN_MODULUS_SIZE) ) self._p = p self._g = g self._q = q def __eq__(self, other): if not isinstance(other, DHParameterNumbers): return NotImplemented return ( self._p == other._p and self._g == other._g and self._q == other._q ) def __ne__(self, other): return not self == other def parameters(self, backend=None): backend = _get_backend(backend) return backend.load_dh_parameter_numbers(self) p = utils.read_only_property("_p") g = utils.read_only_property("_g") q = utils.read_only_property("_q") class DHPublicNumbers(object): def __init__(self, y, parameter_numbers: DHParameterNumbers): if not isinstance(y, int): raise TypeError("y must be an integer.") if not isinstance(parameter_numbers, DHParameterNumbers): raise TypeError( "parameters must be an instance of DHParameterNumbers." ) self._y = y self._parameter_numbers = parameter_numbers def __eq__(self, other): if not isinstance(other, DHPublicNumbers): return NotImplemented return ( self._y == other._y and self._parameter_numbers == other._parameter_numbers ) def __ne__(self, other): return not self == other def public_key(self, backend=None) -> "DHPublicKey": backend = _get_backend(backend) return backend.load_dh_public_numbers(self) y = utils.read_only_property("_y") parameter_numbers = utils.read_only_property("_parameter_numbers") class DHPrivateNumbers(object): def __init__(self, x, public_numbers: DHPublicNumbers): if not isinstance(x, int): raise TypeError("x must be an integer.") if not isinstance(public_numbers, DHPublicNumbers): raise TypeError( "public_numbers must be an instance of " "DHPublicNumbers." ) self._x = x self._public_numbers = public_numbers def __eq__(self, other): if not isinstance(other, DHPrivateNumbers): return NotImplemented return ( self._x == other._x and self._public_numbers == other._public_numbers ) def __ne__(self, other): return not self == other def private_key(self, backend=None) -> "DHPrivateKey": backend = _get_backend(backend) return backend.load_dh_private_numbers(self) public_numbers = utils.read_only_property("_public_numbers") x = utils.read_only_property("_x") class DHParameters(metaclass=abc.ABCMeta): @abc.abstractmethod def generate_private_key(self) -> "DHPrivateKey": """ Generates and returns a DHPrivateKey. """ @abc.abstractmethod def parameter_bytes( self, encoding: "serialization.Encoding", format: "serialization.ParameterFormat", ) -> bytes: """ Returns the parameters serialized as bytes. """ @abc.abstractmethod def parameter_numbers(self) -> DHParameterNumbers: """ Returns a DHParameterNumbers. """ DHParametersWithSerialization = DHParameters class DHPublicKey(metaclass=abc.ABCMeta): @abc.abstractproperty def key_size(self) -> int: """ The bit length of the prime modulus. """ @abc.abstractmethod def parameters(self) -> DHParameters: """ The DHParameters object associated with this public key. """ @abc.abstractmethod def public_numbers(self) -> DHPublicNumbers: """ Returns a DHPublicNumbers. """ @abc.abstractmethod def public_bytes( self, encoding: "serialization.Encoding", format: "serialization.PublicFormat", ) -> bytes: """ Returns the key serialized as bytes. """ DHPublicKeyWithSerialization = DHPublicKey class DHPrivateKey(metaclass=abc.ABCMeta): @abc.abstractproperty def key_size(self) -> int: """ The bit length of the prime modulus. """ @abc.abstractmethod def public_key(self) -> DHPublicKey: """ The DHPublicKey associated with this private key. """ @abc.abstractmethod def parameters(self) -> DHParameters: """ The DHParameters object associated with this private key. """ @abc.abstractmethod def exchange(self, peer_public_key: DHPublicKey) -> bytes: """ Given peer's DHPublicKey, carry out the key exchange and return shared key as bytes. """ @abc.abstractmethod def private_numbers(self) -> DHPrivateNumbers: """ Returns a DHPrivateNumbers. """ @abc.abstractmethod def private_bytes( self, encoding: "serialization.Encoding", format: "serialization.PrivateFormat", encryption_algorithm: "serialization.KeySerializationEncryption", ) -> bytes: """ Returns the key serialized as bytes. """ DHPrivateKeyWithSerialization = DHPrivateKey ed25519.py 0000644 00000005237 15030211711 0006112 0 ustar 00 # This file is dual licensed under the terms of the Apache License, Version # 2.0, and the BSD License. See the LICENSE file in the root of this repository # for complete details. import abc from cryptography.exceptions import UnsupportedAlgorithm, _Reasons from cryptography.hazmat.primitives import _serialization _ED25519_KEY_SIZE = 32 _ED25519_SIG_SIZE = 64 class Ed25519PublicKey(metaclass=abc.ABCMeta): @classmethod def from_public_bytes(cls, data: bytes) -> "Ed25519PublicKey": from cryptography.hazmat.backends.openssl.backend import backend if not backend.ed25519_supported(): raise UnsupportedAlgorithm( "ed25519 is not supported by this version of OpenSSL.", _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM, ) return backend.ed25519_load_public_bytes(data) @abc.abstractmethod def public_bytes( self, encoding: _serialization.Encoding, format: _serialization.PublicFormat, ) -> bytes: """ The serialized bytes of the public key. """ @abc.abstractmethod def verify(self, signature: bytes, data: bytes) -> None: """ Verify the signature. """ class Ed25519PrivateKey(metaclass=abc.ABCMeta): @classmethod def generate(cls) -> "Ed25519PrivateKey": from cryptography.hazmat.backends.openssl.backend import backend if not backend.ed25519_supported(): raise UnsupportedAlgorithm( "ed25519 is not supported by this version of OpenSSL.", _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM, ) return backend.ed25519_generate_key() @classmethod def from_private_bytes(cls, data: bytes) -> "Ed25519PrivateKey": from cryptography.hazmat.backends.openssl.backend import backend if not backend.ed25519_supported(): raise UnsupportedAlgorithm( "ed25519 is not supported by this version of OpenSSL.", _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM, ) return backend.ed25519_load_private_bytes(data) @abc.abstractmethod def public_key(self) -> Ed25519PublicKey: """ The Ed25519PublicKey derived from the private key. """ @abc.abstractmethod def private_bytes( self, encoding: _serialization.Encoding, format: _serialization.PrivateFormat, encryption_algorithm: _serialization.KeySerializationEncryption, ): """ The serialized bytes of the private key. """ @abc.abstractmethod def sign(self, data: bytes) -> bytes: """ Signs the data. """ __pycache__/x25519.cpython-310.pyc 0000644 00000005167 15030211711 0012332 0 ustar 00 o -&%a � @ sP d dl Z d dlmZmZ d dlmZ G dd� de jd�ZG dd� de jd�ZdS ) � N)�UnsupportedAlgorithm�_Reasons)�_serializationc @ sB e Zd Zededd fdd��Zejdej dej defdd��Zd S ) �X25519PublicKey�data�returnc C �* ddl m} |�� stdtj��|�|�S �Nr )�backendz3X25519 is not supported by this version of OpenSSL.)�,cryptography.hazmat.backends.openssl.backendr �x25519_supportedr r �UNSUPPORTED_EXCHANGE_ALGORITHM�x25519_load_public_bytes��clsr r � r �R/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/asymmetric/x25519.py�from_public_bytes � � z!X25519PublicKey.from_public_bytes�encoding�formatc C � dS �z9 The serialized bytes of the public key. Nr )�selfr r r r r �public_bytes � zX25519PublicKey.public_bytesN)�__name__� __module__�__qualname__�classmethod�bytesr �abc�abstractmethodr �Encoding�PublicFormatr r r r r r s ���r )� metaclassc @ s� e Zd Zeddd��Zededd fdd��Zejde fdd��Z ejd ejd ej dejdefdd ��Zejde defdd��ZdS )�X25519PrivateKeyr c C s( ddl m} |�� stdtj��|�� S r )r r r r r r �x25519_generate_key)r r r r r �generate% s �zX25519PrivateKey.generater c C r r )r r r r r r �x25519_load_private_bytesr r r r �from_private_bytes0 r z#X25519PrivateKey.from_private_bytesc C r r r )r r r r � public_key<