U vf @ s d dl mZ d dlmZmZ d dl mZ eeedddZ ee eddd Zee edd dZeedd dZ eeedddZdS ) N)ffilib)ensure)inp1inp2returnc C s t t| ttjd t t|ttjd tt| t|}td|}td|}t || t| t ||t| t| t|k}t |||dk}|o|S )zA Compare contents of two memory regions in constant time Zraisingzchar []r )r isinstancebytesexc TypeErrormaxlenr newmemmover sodium_memcmp)r r lnZbuf1Zbuf2ZeqLZeqC r F/opt/alt/python38/lib64/python3.8/site-packages/nacl/bindings/utils.pyr s r )s blocksizer c C s t t| ttjd t t|ttjd |dkr6tjt| }|| }t d|}t dd}t || | t|||||}t |dkdtj d t||d dd S )z Pad the input bytearray ``s`` to a multiple of ``blocksize`` using the ISO/IEC 7816-4 algorithm :param s: input bytes string :type s: bytes :param blocksize: :type blocksize: int :return: padded string :rtype: bytes r r unsigned char [] size_t [] zPadding failureN)r r r r r int ValueErrorr r r r r sodium_padCryptoErrorbuffer)r r s_lenZm_lenbufZp_lenrcr r r r ) s r c C sn t t| ttjd t t|ttjd t| }tdd}t || ||}|dkr^td| d|d S )z Remove ISO/IEC 7816-4 padding from the input byte array ``s`` :param s: input bytes string :type s: bytes :param blocksize: :type blocksize: int :return: unpadded string :rtype: bytes r r r r zUnpadding failureN)r r r r r r r r r r sodium_unpadr )r r r Zu_lenr! r r r r" C s r" )inpr c C sV t t| ttjd t| }td|}t|| | t || t||dd S )ag Increment the value of a byte-sequence interpreted as the little-endian representation of a unsigned big integer. :param inp: input bytes buffer :type inp: bytes :return: a byte-sequence representing, as a little-endian unsigned big integer, the value ``to_int(inp)`` incremented by one. :rtype: bytes r r N)r r r r r r r r r r sodium_incrementr )r# r r r r r r$ X s r$ )abr c C s t t| ttjd t t|ttjd t| }t t||ktjd td|}td|}t|| | t||| t ||| t||dd S )a Given a couple of *same-sized* byte sequences, interpreted as the little-endian representation of two unsigned integers, compute the modular addition of the represented values, in constant time for a given common length of the byte sequences. :param a: input bytes buffer :type a: bytes :param b: input bytes buffer :type b: bytes :return: a byte-sequence representing, as a little-endian big integer, the integer value of ``(to_int(a) + to_int(b)) mod 2^(8*len(a))`` :rtype: bytes r r N)r r r r r r r r r r sodium_addr )r% r&