File: //var/opt/nydus/ops/oscrypto/_openssl/__pycache__/symmetric.cpython-39.pyc
a
�,�h�[ � @ s d dl mZmZmZmZ d dlZddlmZ ddlm Z m
Z
mZmZm
Z
mZ ddlmZmZmZmZ ddlmZ dd lmZmZ g d
�Zdd� Zd
d� Zdd� Zdd� Zdd� Zdd� Zdd� Z dd� Z!dd� Z"dd� Z#dd � Z$d!d"� Z%d#d$� Z&d%d&� Z'd'd(� Z(d)d*� Z)dS )+� )�unicode_literals�division�absolute_import�print_functionN� )�pretty_message)�new�null�is_null�buffer_from_bytes�bytes_from_buffer�deref� )� libcrypto�libcrypto_legacy_support�LibcryptoConst�handle_openssl_error)�
rand_bytes)� type_name�byte_cls)�aes_cbc_no_padding_decrypt�aes_cbc_no_padding_encrypt�aes_cbc_pkcs7_decrypt�aes_cbc_pkcs7_encrypt�des_cbc_pkcs5_decrypt�des_cbc_pkcs5_encrypt�rc2_cbc_pkcs5_decrypt�rc2_cbc_pkcs5_encrypt�rc4_decrypt�rc4_encrypt�tripledes_cbc_pkcs5_decrypt�tripledes_cbc_pkcs5_encryptc C sj t | �}|std�}nt|�dkr4ttdt|����t|�d dkrVttdt|����|t|| ||d�fS )a�
Encrypts plaintext using AES in CBC mode with a 128, 192 or 256 bit key and
no padding. This means the ciphertext must be an exact multiple of 16 bytes
long.
:param key:
The encryption key - a byte string either 16, 24 or 32 bytes long
:param data:
The plaintext - a byte string
:param iv:
The initialization vector - either a byte string 16-bytes long or None
to generate an IV
:raises:
ValueError - when any of the parameters contain an invalid value
TypeError - when any of the parameters are of the wrong type
OSError - when an error is returned by OpenSSL
:return:
A tuple of two byte strings (iv, ciphertext)
� �:
iv must be 16 bytes long - is %s
r zJ
data must be a multiple of 16 bytes long - is %s
F��_calculate_aes_cipherr �len�
ValueErrorr �_encrypt��key�data�iv�cipher� r. �L/opt/nydus/tmp/pip-target-wkfpz8uv/lib/python/oscrypto/_openssl/symmetric.pyr s
��r c C s6 t | �}t|�dkr&ttdt|����t|| ||d�S )aM
Decrypts AES ciphertext in CBC mode using a 128, 192 or 256 bit key and no
padding.
:param key:
The encryption key - a byte string either 16, 24 or 32 bytes long
:param data:
The ciphertext - a byte string
:param iv:
The initialization vector - a byte string 16-bytes long
:raises:
ValueError - when any of the parameters contain an invalid value
TypeError - when any of the parameters are of the wrong type
OSError - when an error is returned by OpenSSL
:return:
A byte string of the plaintext
r"