Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/BLAKE2b.pyi +32 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/BLAKE2s.py +247 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/BLAKE2s.pyi +26 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/CMAC.py +306 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/HMAC.py +238 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/HMAC.pyi +25 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/KMAC128.py +179 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/KMAC128.pyi +33 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/KangarooTwelve.py +222 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/Poly1305.pyi +24 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/RIPEMD.py +26 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/RIPEMD.pyi +3 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/SHA224.pyi +19 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/SHA3_256.py +174 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/SHA3_256.pyi +19 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/SHA3_512.pyi +19 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/SHA512.pyi +22 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/SHAKE256.pyi +13 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/TupleHash256.py +70 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/TupleHash256.pyi +5 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/_RIPEMD160.abi3.so +0 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/_SHA384.abi3.so +0 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/_SHA512.abi3.so +0 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/__init__.py +69 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/_ghash_clmul.abi3.so +0 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/_keccak.abi3.so +0 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/_poly1305.abi3.so +0 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/cSHAKE128.py +187 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/cSHAKE256.py +56 -0
- minigpt2/lib/python3.10/site-packages/Crypto/Hash/keccak.py +181 -0
- minigpt2/lib/python3.10/site-packages/markdown_it/__pycache__/__init__.cpython-310.pyc +0 -0
- minigpt2/lib/python3.10/site-packages/markdown_it/__pycache__/_punycode.cpython-310.pyc +0 -0
- minigpt2/lib/python3.10/site-packages/markdown_it/__pycache__/main.cpython-310.pyc +0 -0
- minigpt2/lib/python3.10/site-packages/markdown_it/__pycache__/renderer.cpython-310.pyc +0 -0
- minigpt2/lib/python3.10/site-packages/markdown_it/__pycache__/utils.cpython-310.pyc +0 -0
- minigpt2/lib/python3.10/site-packages/markdown_it/helpers/__init__.py +6 -0
- minigpt2/lib/python3.10/site-packages/markdown_it/helpers/__pycache__/parse_link_label.cpython-310.pyc +0 -0
- minigpt2/lib/python3.10/site-packages/markdown_it/helpers/parse_link_destination.py +86 -0
- minigpt2/lib/python3.10/site-packages/markdown_it/helpers/parse_link_label.py +43 -0
- minigpt2/lib/python3.10/site-packages/markdown_it/helpers/parse_link_title.py +60 -0
- minigpt2/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/.hash/_cparser.pxd.hash +1 -0
- minigpt2/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/.hash/hdrs.py.hash +1 -0
- minigpt2/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/__pycache__/abc.cpython-310.pyc +0 -0
- minigpt2/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/__pycache__/client_ws.cpython-310.pyc +0 -0
- minigpt2/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/__pycache__/hdrs.cpython-310.pyc +0 -0
- minigpt2/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/__pycache__/http.cpython-310.pyc +0 -0
- minigpt2/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/__pycache__/pytest_plugin.cpython-310.pyc +0 -0
- minigpt2/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/__pycache__/resolver.cpython-310.pyc +0 -0
- minigpt2/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/__pycache__/web_log.cpython-310.pyc +0 -0
- minigpt2/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/__pycache__/web_ws.cpython-310.pyc +0 -0
minigpt2/lib/python3.10/site-packages/Crypto/Hash/BLAKE2b.pyi
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, Union
|
| 2 |
+
from types import ModuleType
|
| 3 |
+
|
| 4 |
+
Buffer = Union[bytes, bytearray, memoryview]
|
| 5 |
+
|
| 6 |
+
class BLAKE2b_Hash(object):
|
| 7 |
+
block_size: int
|
| 8 |
+
digest_size: int
|
| 9 |
+
oid: str
|
| 10 |
+
|
| 11 |
+
def __init__(self,
|
| 12 |
+
data: Buffer,
|
| 13 |
+
key: Buffer,
|
| 14 |
+
digest_bytes: bytes,
|
| 15 |
+
update_after_digest: bool) -> None: ...
|
| 16 |
+
def update(self, data: Buffer) -> BLAKE2b_Hash: ...
|
| 17 |
+
def digest(self) -> bytes: ...
|
| 18 |
+
def hexdigest(self) -> str: ...
|
| 19 |
+
def verify(self, mac_tag: Buffer) -> None: ...
|
| 20 |
+
def hexverify(self, hex_mac_tag: str) -> None: ...
|
| 21 |
+
def new(self,
|
| 22 |
+
data: Buffer = ...,
|
| 23 |
+
digest_bytes: int = ...,
|
| 24 |
+
digest_bits: int = ...,
|
| 25 |
+
key: Buffer = ...,
|
| 26 |
+
update_after_digest: bool = ...) -> BLAKE2b_Hash: ...
|
| 27 |
+
|
| 28 |
+
def new(data: Buffer = ...,
|
| 29 |
+
digest_bytes: int = ...,
|
| 30 |
+
digest_bits: int = ...,
|
| 31 |
+
key: Buffer = ...,
|
| 32 |
+
update_after_digest: bool = ...) -> BLAKE2b_Hash: ...
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/BLAKE2s.py
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ===================================================================
|
| 2 |
+
#
|
| 3 |
+
# Copyright (c) 2014, Legrandin <helderijs@gmail.com>
|
| 4 |
+
# All rights reserved.
|
| 5 |
+
#
|
| 6 |
+
# Redistribution and use in source and binary forms, with or without
|
| 7 |
+
# modification, are permitted provided that the following conditions
|
| 8 |
+
# are met:
|
| 9 |
+
#
|
| 10 |
+
# 1. Redistributions of source code must retain the above copyright
|
| 11 |
+
# notice, this list of conditions and the following disclaimer.
|
| 12 |
+
# 2. Redistributions in binary form must reproduce the above copyright
|
| 13 |
+
# notice, this list of conditions and the following disclaimer in
|
| 14 |
+
# the documentation and/or other materials provided with the
|
| 15 |
+
# distribution.
|
| 16 |
+
#
|
| 17 |
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 18 |
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 19 |
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
| 20 |
+
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
| 21 |
+
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
| 22 |
+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
| 23 |
+
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 24 |
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 25 |
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 26 |
+
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
| 27 |
+
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
| 28 |
+
# POSSIBILITY OF SUCH DAMAGE.
|
| 29 |
+
# ===================================================================
|
| 30 |
+
|
| 31 |
+
from binascii import unhexlify
|
| 32 |
+
|
| 33 |
+
from Crypto.Util.py3compat import bord, tobytes
|
| 34 |
+
|
| 35 |
+
from Crypto.Random import get_random_bytes
|
| 36 |
+
from Crypto.Util._raw_api import (load_pycryptodome_raw_lib,
|
| 37 |
+
VoidPointer, SmartPointer,
|
| 38 |
+
create_string_buffer,
|
| 39 |
+
get_raw_buffer, c_size_t,
|
| 40 |
+
c_uint8_ptr)
|
| 41 |
+
|
| 42 |
+
_raw_blake2s_lib = load_pycryptodome_raw_lib("Crypto.Hash._BLAKE2s",
|
| 43 |
+
"""
|
| 44 |
+
int blake2s_init(void **state,
|
| 45 |
+
const uint8_t *key,
|
| 46 |
+
size_t key_size,
|
| 47 |
+
size_t digest_size);
|
| 48 |
+
int blake2s_destroy(void *state);
|
| 49 |
+
int blake2s_update(void *state,
|
| 50 |
+
const uint8_t *buf,
|
| 51 |
+
size_t len);
|
| 52 |
+
int blake2s_digest(const void *state,
|
| 53 |
+
uint8_t digest[32]);
|
| 54 |
+
int blake2s_copy(const void *src, void *dst);
|
| 55 |
+
""")
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
class BLAKE2s_Hash(object):
|
| 59 |
+
"""A BLAKE2s hash object.
|
| 60 |
+
Do not instantiate directly. Use the :func:`new` function.
|
| 61 |
+
|
| 62 |
+
:ivar oid: ASN.1 Object ID
|
| 63 |
+
:vartype oid: string
|
| 64 |
+
|
| 65 |
+
:ivar block_size: the size in bytes of the internal message block,
|
| 66 |
+
input to the compression function
|
| 67 |
+
:vartype block_size: integer
|
| 68 |
+
|
| 69 |
+
:ivar digest_size: the size in bytes of the resulting hash
|
| 70 |
+
:vartype digest_size: integer
|
| 71 |
+
"""
|
| 72 |
+
|
| 73 |
+
# The internal block size of the hash algorithm in bytes.
|
| 74 |
+
block_size = 32
|
| 75 |
+
|
| 76 |
+
def __init__(self, data, key, digest_bytes, update_after_digest):
|
| 77 |
+
|
| 78 |
+
# The size of the resulting hash in bytes.
|
| 79 |
+
self.digest_size = digest_bytes
|
| 80 |
+
|
| 81 |
+
self._update_after_digest = update_after_digest
|
| 82 |
+
self._digest_done = False
|
| 83 |
+
|
| 84 |
+
# See https://tools.ietf.org/html/rfc7693
|
| 85 |
+
if digest_bytes in (16, 20, 28, 32) and not key:
|
| 86 |
+
self.oid = "1.3.6.1.4.1.1722.12.2.2." + str(digest_bytes)
|
| 87 |
+
|
| 88 |
+
state = VoidPointer()
|
| 89 |
+
result = _raw_blake2s_lib.blake2s_init(state.address_of(),
|
| 90 |
+
c_uint8_ptr(key),
|
| 91 |
+
c_size_t(len(key)),
|
| 92 |
+
c_size_t(digest_bytes)
|
| 93 |
+
)
|
| 94 |
+
if result:
|
| 95 |
+
raise ValueError("Error %d while instantiating BLAKE2s" % result)
|
| 96 |
+
self._state = SmartPointer(state.get(),
|
| 97 |
+
_raw_blake2s_lib.blake2s_destroy)
|
| 98 |
+
if data:
|
| 99 |
+
self.update(data)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def update(self, data):
|
| 103 |
+
"""Continue hashing of a message by consuming the next chunk of data.
|
| 104 |
+
|
| 105 |
+
Args:
|
| 106 |
+
data (byte string/byte array/memoryview): The next chunk of the message being hashed.
|
| 107 |
+
"""
|
| 108 |
+
|
| 109 |
+
if self._digest_done and not self._update_after_digest:
|
| 110 |
+
raise TypeError("You can only call 'digest' or 'hexdigest' on this object")
|
| 111 |
+
|
| 112 |
+
result = _raw_blake2s_lib.blake2s_update(self._state.get(),
|
| 113 |
+
c_uint8_ptr(data),
|
| 114 |
+
c_size_t(len(data)))
|
| 115 |
+
if result:
|
| 116 |
+
raise ValueError("Error %d while hashing BLAKE2s data" % result)
|
| 117 |
+
return self
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def digest(self):
|
| 121 |
+
"""Return the **binary** (non-printable) digest of the message that has been hashed so far.
|
| 122 |
+
|
| 123 |
+
:return: The hash digest, computed over the data processed so far.
|
| 124 |
+
Binary form.
|
| 125 |
+
:rtype: byte string
|
| 126 |
+
"""
|
| 127 |
+
|
| 128 |
+
bfr = create_string_buffer(32)
|
| 129 |
+
result = _raw_blake2s_lib.blake2s_digest(self._state.get(),
|
| 130 |
+
bfr)
|
| 131 |
+
if result:
|
| 132 |
+
raise ValueError("Error %d while creating BLAKE2s digest" % result)
|
| 133 |
+
|
| 134 |
+
self._digest_done = True
|
| 135 |
+
|
| 136 |
+
return get_raw_buffer(bfr)[:self.digest_size]
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def hexdigest(self):
|
| 140 |
+
"""Return the **printable** digest of the message that has been hashed so far.
|
| 141 |
+
|
| 142 |
+
:return: The hash digest, computed over the data processed so far.
|
| 143 |
+
Hexadecimal encoded.
|
| 144 |
+
:rtype: string
|
| 145 |
+
"""
|
| 146 |
+
|
| 147 |
+
return "".join(["%02x" % bord(x) for x in tuple(self.digest())])
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def verify(self, mac_tag):
|
| 151 |
+
"""Verify that a given **binary** MAC (computed by another party)
|
| 152 |
+
is valid.
|
| 153 |
+
|
| 154 |
+
Args:
|
| 155 |
+
mac_tag (byte string/byte array/memoryview): the expected MAC of the message.
|
| 156 |
+
|
| 157 |
+
Raises:
|
| 158 |
+
ValueError: if the MAC does not match. It means that the message
|
| 159 |
+
has been tampered with or that the MAC key is incorrect.
|
| 160 |
+
"""
|
| 161 |
+
|
| 162 |
+
secret = get_random_bytes(16)
|
| 163 |
+
|
| 164 |
+
mac1 = new(digest_bits=160, key=secret, data=mac_tag)
|
| 165 |
+
mac2 = new(digest_bits=160, key=secret, data=self.digest())
|
| 166 |
+
|
| 167 |
+
if mac1.digest() != mac2.digest():
|
| 168 |
+
raise ValueError("MAC check failed")
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
def hexverify(self, hex_mac_tag):
|
| 172 |
+
"""Verify that a given **printable** MAC (computed by another party)
|
| 173 |
+
is valid.
|
| 174 |
+
|
| 175 |
+
Args:
|
| 176 |
+
hex_mac_tag (string): the expected MAC of the message, as a hexadecimal string.
|
| 177 |
+
|
| 178 |
+
Raises:
|
| 179 |
+
ValueError: if the MAC does not match. It means that the message
|
| 180 |
+
has been tampered with or that the MAC key is incorrect.
|
| 181 |
+
"""
|
| 182 |
+
|
| 183 |
+
self.verify(unhexlify(tobytes(hex_mac_tag)))
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
def new(self, **kwargs):
|
| 187 |
+
"""Return a new instance of a BLAKE2s hash object.
|
| 188 |
+
See :func:`new`.
|
| 189 |
+
"""
|
| 190 |
+
|
| 191 |
+
if "digest_bytes" not in kwargs and "digest_bits" not in kwargs:
|
| 192 |
+
kwargs["digest_bytes"] = self.digest_size
|
| 193 |
+
|
| 194 |
+
return new(**kwargs)
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
def new(**kwargs):
|
| 198 |
+
"""Create a new hash object.
|
| 199 |
+
|
| 200 |
+
Args:
|
| 201 |
+
data (byte string/byte array/memoryview):
|
| 202 |
+
Optional. The very first chunk of the message to hash.
|
| 203 |
+
It is equivalent to an early call to :meth:`BLAKE2s_Hash.update`.
|
| 204 |
+
digest_bytes (integer):
|
| 205 |
+
Optional. The size of the digest, in bytes (1 to 32). Default is 32.
|
| 206 |
+
digest_bits (integer):
|
| 207 |
+
Optional and alternative to ``digest_bytes``.
|
| 208 |
+
The size of the digest, in bits (8 to 256, in steps of 8).
|
| 209 |
+
Default is 256.
|
| 210 |
+
key (byte string):
|
| 211 |
+
Optional. The key to use to compute the MAC (1 to 64 bytes).
|
| 212 |
+
If not specified, no key will be used.
|
| 213 |
+
update_after_digest (boolean):
|
| 214 |
+
Optional. By default, a hash object cannot be updated anymore after
|
| 215 |
+
the digest is computed. When this flag is ``True``, such check
|
| 216 |
+
is no longer enforced.
|
| 217 |
+
|
| 218 |
+
Returns:
|
| 219 |
+
A :class:`BLAKE2s_Hash` hash object
|
| 220 |
+
"""
|
| 221 |
+
|
| 222 |
+
data = kwargs.pop("data", None)
|
| 223 |
+
update_after_digest = kwargs.pop("update_after_digest", False)
|
| 224 |
+
|
| 225 |
+
digest_bytes = kwargs.pop("digest_bytes", None)
|
| 226 |
+
digest_bits = kwargs.pop("digest_bits", None)
|
| 227 |
+
if None not in (digest_bytes, digest_bits):
|
| 228 |
+
raise TypeError("Only one digest parameter must be provided")
|
| 229 |
+
if (None, None) == (digest_bytes, digest_bits):
|
| 230 |
+
digest_bytes = 32
|
| 231 |
+
if digest_bytes is not None:
|
| 232 |
+
if not (1 <= digest_bytes <= 32):
|
| 233 |
+
raise ValueError("'digest_bytes' not in range 1..32")
|
| 234 |
+
else:
|
| 235 |
+
if not (8 <= digest_bits <= 256) or (digest_bits % 8):
|
| 236 |
+
raise ValueError("'digest_bits' not in range 8..256, "
|
| 237 |
+
"with steps of 8")
|
| 238 |
+
digest_bytes = digest_bits // 8
|
| 239 |
+
|
| 240 |
+
key = kwargs.pop("key", b"")
|
| 241 |
+
if len(key) > 32:
|
| 242 |
+
raise ValueError("BLAKE2s key cannot exceed 32 bytes")
|
| 243 |
+
|
| 244 |
+
if kwargs:
|
| 245 |
+
raise TypeError("Unknown parameters: " + str(kwargs))
|
| 246 |
+
|
| 247 |
+
return BLAKE2s_Hash(data, key, digest_bytes, update_after_digest)
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/BLAKE2s.pyi
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, Union
|
| 2 |
+
|
| 3 |
+
Buffer = Union[bytes, bytearray, memoryview]
|
| 4 |
+
|
| 5 |
+
class BLAKE2s_Hash(object):
|
| 6 |
+
block_size: int
|
| 7 |
+
digest_size: int
|
| 8 |
+
oid: str
|
| 9 |
+
|
| 10 |
+
def __init__(self,
|
| 11 |
+
data: Buffer,
|
| 12 |
+
key: Buffer,
|
| 13 |
+
digest_bytes: bytes,
|
| 14 |
+
update_after_digest: bool) -> None: ...
|
| 15 |
+
def update(self, data: Buffer) -> BLAKE2s_Hash: ...
|
| 16 |
+
def digest(self) -> bytes: ...
|
| 17 |
+
def hexdigest(self) -> str: ...
|
| 18 |
+
def verify(self, mac_tag: Buffer) -> None: ...
|
| 19 |
+
def hexverify(self, hex_mac_tag: str) -> None: ...
|
| 20 |
+
def new(self, **kwargs: Any) -> BLAKE2s_Hash: ...
|
| 21 |
+
|
| 22 |
+
def new(data: Buffer = ...,
|
| 23 |
+
digest_bytes: int = ...,
|
| 24 |
+
digest_bits: int = ...,
|
| 25 |
+
key: Buffer = ...,
|
| 26 |
+
update_after_digest: bool = ...) -> BLAKE2s_Hash: ...
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/CMAC.py
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
#
|
| 3 |
+
# Hash/CMAC.py - Implements the CMAC algorithm
|
| 4 |
+
#
|
| 5 |
+
# ===================================================================
|
| 6 |
+
# The contents of this file are dedicated to the public domain. To
|
| 7 |
+
# the extent that dedication to the public domain is not available,
|
| 8 |
+
# everyone is granted a worldwide, perpetual, royalty-free,
|
| 9 |
+
# non-exclusive license to exercise all rights associated with the
|
| 10 |
+
# contents of this file for any purpose whatsoever.
|
| 11 |
+
# No rights are reserved.
|
| 12 |
+
#
|
| 13 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 14 |
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
| 15 |
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
| 16 |
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
| 17 |
+
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
| 18 |
+
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 19 |
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 20 |
+
# SOFTWARE.
|
| 21 |
+
# ===================================================================
|
| 22 |
+
|
| 23 |
+
from binascii import unhexlify
|
| 24 |
+
|
| 25 |
+
from Crypto.Hash import BLAKE2s
|
| 26 |
+
from Crypto.Util.strxor import strxor
|
| 27 |
+
from Crypto.Util.number import long_to_bytes, bytes_to_long
|
| 28 |
+
from Crypto.Util.py3compat import bord, tobytes, _copy_bytes
|
| 29 |
+
from Crypto.Random import get_random_bytes
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
# The size of the authentication tag produced by the MAC.
|
| 33 |
+
digest_size = None
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def _shift_bytes(bs, xor_lsb=0):
|
| 37 |
+
num = (bytes_to_long(bs) << 1) ^ xor_lsb
|
| 38 |
+
return long_to_bytes(num, len(bs))[-len(bs):]
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
class CMAC(object):
|
| 42 |
+
"""A CMAC hash object.
|
| 43 |
+
Do not instantiate directly. Use the :func:`new` function.
|
| 44 |
+
|
| 45 |
+
:ivar digest_size: the size in bytes of the resulting MAC tag
|
| 46 |
+
:vartype digest_size: integer
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
digest_size = None
|
| 50 |
+
|
| 51 |
+
def __init__(self, key, msg, ciphermod, cipher_params, mac_len,
|
| 52 |
+
update_after_digest):
|
| 53 |
+
|
| 54 |
+
self.digest_size = mac_len
|
| 55 |
+
|
| 56 |
+
self._key = _copy_bytes(None, None, key)
|
| 57 |
+
self._factory = ciphermod
|
| 58 |
+
self._cipher_params = cipher_params
|
| 59 |
+
self._block_size = bs = ciphermod.block_size
|
| 60 |
+
self._mac_tag = None
|
| 61 |
+
self._update_after_digest = update_after_digest
|
| 62 |
+
|
| 63 |
+
# Section 5.3 of NIST SP 800 38B and Appendix B
|
| 64 |
+
if bs == 8:
|
| 65 |
+
const_Rb = 0x1B
|
| 66 |
+
self._max_size = 8 * (2 ** 21)
|
| 67 |
+
elif bs == 16:
|
| 68 |
+
const_Rb = 0x87
|
| 69 |
+
self._max_size = 16 * (2 ** 48)
|
| 70 |
+
else:
|
| 71 |
+
raise TypeError("CMAC requires a cipher with a block size"
|
| 72 |
+
" of 8 or 16 bytes, not %d" % bs)
|
| 73 |
+
|
| 74 |
+
# Compute sub-keys
|
| 75 |
+
zero_block = b'\x00' * bs
|
| 76 |
+
self._ecb = ciphermod.new(key,
|
| 77 |
+
ciphermod.MODE_ECB,
|
| 78 |
+
**self._cipher_params)
|
| 79 |
+
L = self._ecb.encrypt(zero_block)
|
| 80 |
+
if bord(L[0]) & 0x80:
|
| 81 |
+
self._k1 = _shift_bytes(L, const_Rb)
|
| 82 |
+
else:
|
| 83 |
+
self._k1 = _shift_bytes(L)
|
| 84 |
+
if bord(self._k1[0]) & 0x80:
|
| 85 |
+
self._k2 = _shift_bytes(self._k1, const_Rb)
|
| 86 |
+
else:
|
| 87 |
+
self._k2 = _shift_bytes(self._k1)
|
| 88 |
+
|
| 89 |
+
# Initialize CBC cipher with zero IV
|
| 90 |
+
self._cbc = ciphermod.new(key,
|
| 91 |
+
ciphermod.MODE_CBC,
|
| 92 |
+
zero_block,
|
| 93 |
+
**self._cipher_params)
|
| 94 |
+
|
| 95 |
+
# Cache for outstanding data to authenticate
|
| 96 |
+
self._cache = bytearray(bs)
|
| 97 |
+
self._cache_n = 0
|
| 98 |
+
|
| 99 |
+
# Last piece of ciphertext produced
|
| 100 |
+
self._last_ct = zero_block
|
| 101 |
+
|
| 102 |
+
# Last block that was encrypted with AES
|
| 103 |
+
self._last_pt = None
|
| 104 |
+
|
| 105 |
+
# Counter for total message size
|
| 106 |
+
self._data_size = 0
|
| 107 |
+
|
| 108 |
+
if msg:
|
| 109 |
+
self.update(msg)
|
| 110 |
+
|
| 111 |
+
def update(self, msg):
|
| 112 |
+
"""Authenticate the next chunk of message.
|
| 113 |
+
|
| 114 |
+
Args:
|
| 115 |
+
data (byte string/byte array/memoryview): The next chunk of data
|
| 116 |
+
"""
|
| 117 |
+
|
| 118 |
+
if self._mac_tag is not None and not self._update_after_digest:
|
| 119 |
+
raise TypeError("update() cannot be called after digest() or verify()")
|
| 120 |
+
|
| 121 |
+
self._data_size += len(msg)
|
| 122 |
+
bs = self._block_size
|
| 123 |
+
|
| 124 |
+
if self._cache_n > 0:
|
| 125 |
+
filler = min(bs - self._cache_n, len(msg))
|
| 126 |
+
self._cache[self._cache_n:self._cache_n+filler] = msg[:filler]
|
| 127 |
+
self._cache_n += filler
|
| 128 |
+
|
| 129 |
+
if self._cache_n < bs:
|
| 130 |
+
return self
|
| 131 |
+
|
| 132 |
+
msg = memoryview(msg)[filler:]
|
| 133 |
+
self._update(self._cache)
|
| 134 |
+
self._cache_n = 0
|
| 135 |
+
|
| 136 |
+
remain = len(msg) % bs
|
| 137 |
+
if remain > 0:
|
| 138 |
+
self._update(msg[:-remain])
|
| 139 |
+
self._cache[:remain] = msg[-remain:]
|
| 140 |
+
else:
|
| 141 |
+
self._update(msg)
|
| 142 |
+
self._cache_n = remain
|
| 143 |
+
return self
|
| 144 |
+
|
| 145 |
+
def _update(self, data_block):
|
| 146 |
+
"""Update a block aligned to the block boundary"""
|
| 147 |
+
|
| 148 |
+
bs = self._block_size
|
| 149 |
+
assert len(data_block) % bs == 0
|
| 150 |
+
|
| 151 |
+
if len(data_block) == 0:
|
| 152 |
+
return
|
| 153 |
+
|
| 154 |
+
ct = self._cbc.encrypt(data_block)
|
| 155 |
+
if len(data_block) == bs:
|
| 156 |
+
second_last = self._last_ct
|
| 157 |
+
else:
|
| 158 |
+
second_last = ct[-bs*2:-bs]
|
| 159 |
+
self._last_ct = ct[-bs:]
|
| 160 |
+
self._last_pt = strxor(second_last, data_block[-bs:])
|
| 161 |
+
|
| 162 |
+
def copy(self):
|
| 163 |
+
"""Return a copy ("clone") of the CMAC object.
|
| 164 |
+
|
| 165 |
+
The copy will have the same internal state as the original CMAC
|
| 166 |
+
object.
|
| 167 |
+
This can be used to efficiently compute the MAC tag of byte
|
| 168 |
+
strings that share a common initial substring.
|
| 169 |
+
|
| 170 |
+
:return: An :class:`CMAC`
|
| 171 |
+
"""
|
| 172 |
+
|
| 173 |
+
obj = self.__new__(CMAC)
|
| 174 |
+
obj.__dict__ = self.__dict__.copy()
|
| 175 |
+
obj._cbc = self._factory.new(self._key,
|
| 176 |
+
self._factory.MODE_CBC,
|
| 177 |
+
self._last_ct,
|
| 178 |
+
**self._cipher_params)
|
| 179 |
+
obj._cache = self._cache[:]
|
| 180 |
+
obj._last_ct = self._last_ct[:]
|
| 181 |
+
return obj
|
| 182 |
+
|
| 183 |
+
def digest(self):
|
| 184 |
+
"""Return the **binary** (non-printable) MAC tag of the message
|
| 185 |
+
that has been authenticated so far.
|
| 186 |
+
|
| 187 |
+
:return: The MAC tag, computed over the data processed so far.
|
| 188 |
+
Binary form.
|
| 189 |
+
:rtype: byte string
|
| 190 |
+
"""
|
| 191 |
+
|
| 192 |
+
bs = self._block_size
|
| 193 |
+
|
| 194 |
+
if self._mac_tag is not None and not self._update_after_digest:
|
| 195 |
+
return self._mac_tag
|
| 196 |
+
|
| 197 |
+
if self._data_size > self._max_size:
|
| 198 |
+
raise ValueError("MAC is unsafe for this message")
|
| 199 |
+
|
| 200 |
+
if self._cache_n == 0 and self._data_size > 0:
|
| 201 |
+
# Last block was full
|
| 202 |
+
pt = strxor(self._last_pt, self._k1)
|
| 203 |
+
else:
|
| 204 |
+
# Last block is partial (or message length is zero)
|
| 205 |
+
partial = self._cache[:]
|
| 206 |
+
partial[self._cache_n:] = b'\x80' + b'\x00' * (bs - self._cache_n - 1)
|
| 207 |
+
pt = strxor(strxor(self._last_ct, partial), self._k2)
|
| 208 |
+
|
| 209 |
+
self._mac_tag = self._ecb.encrypt(pt)[:self.digest_size]
|
| 210 |
+
|
| 211 |
+
return self._mac_tag
|
| 212 |
+
|
| 213 |
+
def hexdigest(self):
|
| 214 |
+
"""Return the **printable** MAC tag of the message authenticated so far.
|
| 215 |
+
|
| 216 |
+
:return: The MAC tag, computed over the data processed so far.
|
| 217 |
+
Hexadecimal encoded.
|
| 218 |
+
:rtype: string
|
| 219 |
+
"""
|
| 220 |
+
|
| 221 |
+
return "".join(["%02x" % bord(x)
|
| 222 |
+
for x in tuple(self.digest())])
|
| 223 |
+
|
| 224 |
+
def verify(self, mac_tag):
|
| 225 |
+
"""Verify that a given **binary** MAC (computed by another party)
|
| 226 |
+
is valid.
|
| 227 |
+
|
| 228 |
+
Args:
|
| 229 |
+
mac_tag (byte string/byte array/memoryview): the expected MAC of the message.
|
| 230 |
+
|
| 231 |
+
Raises:
|
| 232 |
+
ValueError: if the MAC does not match. It means that the message
|
| 233 |
+
has been tampered with or that the MAC key is incorrect.
|
| 234 |
+
"""
|
| 235 |
+
|
| 236 |
+
secret = get_random_bytes(16)
|
| 237 |
+
|
| 238 |
+
mac1 = BLAKE2s.new(digest_bits=160, key=secret, data=mac_tag)
|
| 239 |
+
mac2 = BLAKE2s.new(digest_bits=160, key=secret, data=self.digest())
|
| 240 |
+
|
| 241 |
+
if mac1.digest() != mac2.digest():
|
| 242 |
+
raise ValueError("MAC check failed")
|
| 243 |
+
|
| 244 |
+
def hexverify(self, hex_mac_tag):
|
| 245 |
+
"""Verify that a given **printable** MAC (computed by another party)
|
| 246 |
+
is valid.
|
| 247 |
+
|
| 248 |
+
Args:
|
| 249 |
+
hex_mac_tag (string): the expected MAC of the message, as a hexadecimal string.
|
| 250 |
+
|
| 251 |
+
Raises:
|
| 252 |
+
ValueError: if the MAC does not match. It means that the message
|
| 253 |
+
has been tampered with or that the MAC key is incorrect.
|
| 254 |
+
"""
|
| 255 |
+
|
| 256 |
+
self.verify(unhexlify(tobytes(hex_mac_tag)))
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
def new(key, msg=None, ciphermod=None, cipher_params=None, mac_len=None,
|
| 260 |
+
update_after_digest=False):
|
| 261 |
+
"""Create a new MAC object.
|
| 262 |
+
|
| 263 |
+
Args:
|
| 264 |
+
key (byte string/byte array/memoryview):
|
| 265 |
+
key for the CMAC object.
|
| 266 |
+
The key must be valid for the underlying cipher algorithm.
|
| 267 |
+
For instance, it must be 16 bytes long for AES-128.
|
| 268 |
+
ciphermod (module):
|
| 269 |
+
A cipher module from :mod:`Crypto.Cipher`.
|
| 270 |
+
The cipher's block size has to be 128 bits,
|
| 271 |
+
like :mod:`Crypto.Cipher.AES`, to reduce the probability
|
| 272 |
+
of collisions.
|
| 273 |
+
msg (byte string/byte array/memoryview):
|
| 274 |
+
Optional. The very first chunk of the message to authenticate.
|
| 275 |
+
It is equivalent to an early call to `CMAC.update`. Optional.
|
| 276 |
+
cipher_params (dict):
|
| 277 |
+
Optional. A set of parameters to use when instantiating a cipher
|
| 278 |
+
object.
|
| 279 |
+
mac_len (integer):
|
| 280 |
+
Length of the MAC, in bytes.
|
| 281 |
+
It must be at least 4 bytes long.
|
| 282 |
+
The default (and recommended) length matches the size of a cipher block.
|
| 283 |
+
update_after_digest (boolean):
|
| 284 |
+
Optional. By default, a hash object cannot be updated anymore after
|
| 285 |
+
the digest is computed. When this flag is ``True``, such check
|
| 286 |
+
is no longer enforced.
|
| 287 |
+
Returns:
|
| 288 |
+
A :class:`CMAC` object
|
| 289 |
+
"""
|
| 290 |
+
|
| 291 |
+
if ciphermod is None:
|
| 292 |
+
raise TypeError("ciphermod must be specified (try AES)")
|
| 293 |
+
|
| 294 |
+
cipher_params = {} if cipher_params is None else dict(cipher_params)
|
| 295 |
+
|
| 296 |
+
if mac_len is None:
|
| 297 |
+
mac_len = ciphermod.block_size
|
| 298 |
+
|
| 299 |
+
if mac_len < 4:
|
| 300 |
+
raise ValueError("MAC tag length must be at least 4 bytes long")
|
| 301 |
+
|
| 302 |
+
if mac_len > ciphermod.block_size:
|
| 303 |
+
raise ValueError("MAC tag length cannot be larger than a cipher block (%d) bytes" % ciphermod.block_size)
|
| 304 |
+
|
| 305 |
+
return CMAC(key, msg, ciphermod, cipher_params, mac_len,
|
| 306 |
+
update_after_digest)
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/HMAC.py
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# HMAC.py - Implements the HMAC algorithm as described by RFC 2104.
|
| 3 |
+
#
|
| 4 |
+
# ===================================================================
|
| 5 |
+
#
|
| 6 |
+
# Copyright (c) 2014, Legrandin <helderijs@gmail.com>
|
| 7 |
+
# All rights reserved.
|
| 8 |
+
#
|
| 9 |
+
# Redistribution and use in source and binary forms, with or without
|
| 10 |
+
# modification, are permitted provided that the following conditions
|
| 11 |
+
# are met:
|
| 12 |
+
#
|
| 13 |
+
# 1. Redistributions of source code must retain the above copyright
|
| 14 |
+
# notice, this list of conditions and the following disclaimer.
|
| 15 |
+
# 2. Redistributions in binary form must reproduce the above copyright
|
| 16 |
+
# notice, this list of conditions and the following disclaimer in
|
| 17 |
+
# the documentation and/or other materials provided with the
|
| 18 |
+
# distribution.
|
| 19 |
+
#
|
| 20 |
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 21 |
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 22 |
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
| 23 |
+
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
| 24 |
+
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
| 25 |
+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
| 26 |
+
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 27 |
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 28 |
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 29 |
+
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
| 30 |
+
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
| 31 |
+
# POSSIBILITY OF SUCH DAMAGE.
|
| 32 |
+
# ===================================================================
|
| 33 |
+
|
| 34 |
+
from Crypto.Util.py3compat import bord, tobytes
|
| 35 |
+
|
| 36 |
+
from binascii import unhexlify
|
| 37 |
+
|
| 38 |
+
from Crypto.Hash import BLAKE2s
|
| 39 |
+
from Crypto.Util.strxor import strxor
|
| 40 |
+
from Crypto.Random import get_random_bytes
|
| 41 |
+
|
| 42 |
+
__all__ = ['new', 'HMAC']
|
| 43 |
+
|
| 44 |
+
_hash2hmac_oid = {
|
| 45 |
+
'1.3.14.3.2.26': '1.2.840.113549.2.7', # SHA-1
|
| 46 |
+
'2.16.840.1.101.3.4.2.4': '1.2.840.113549.2.8', # SHA-224
|
| 47 |
+
'2.16.840.1.101.3.4.2.1': '1.2.840.113549.2.9', # SHA-256
|
| 48 |
+
'2.16.840.1.101.3.4.2.2': '1.2.840.113549.2.10', # SHA-384
|
| 49 |
+
'2.16.840.1.101.3.4.2.3': '1.2.840.113549.2.11', # SHA-512
|
| 50 |
+
'2.16.840.1.101.3.4.2.5': '1.2.840.113549.2.12', # SHA-512_224
|
| 51 |
+
'2.16.840.1.101.3.4.2.6': '1.2.840.113549.2.13', # SHA-512_256
|
| 52 |
+
'2.16.840.1.101.3.4.2.7': '2.16.840.1.101.3.4.2.13', # SHA-3 224
|
| 53 |
+
'2.16.840.1.101.3.4.2.8': '2.16.840.1.101.3.4.2.14', # SHA-3 256
|
| 54 |
+
'2.16.840.1.101.3.4.2.9': '2.16.840.1.101.3.4.2.15', # SHA-3 384
|
| 55 |
+
'2.16.840.1.101.3.4.2.10': '2.16.840.1.101.3.4.2.16', # SHA-3 512
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
_hmac2hash_oid = {v: k for k, v in _hash2hmac_oid.items()}
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
class HMAC(object):
|
| 62 |
+
"""An HMAC hash object.
|
| 63 |
+
Do not instantiate directly. Use the :func:`new` function.
|
| 64 |
+
|
| 65 |
+
:ivar digest_size: the size in bytes of the resulting MAC tag
|
| 66 |
+
:vartype digest_size: integer
|
| 67 |
+
|
| 68 |
+
:ivar oid: the ASN.1 object ID of the HMAC algorithm.
|
| 69 |
+
Only present if the algorithm was officially assigned one.
|
| 70 |
+
"""
|
| 71 |
+
|
| 72 |
+
def __init__(self, key, msg=b"", digestmod=None):
|
| 73 |
+
|
| 74 |
+
if digestmod is None:
|
| 75 |
+
from Crypto.Hash import MD5
|
| 76 |
+
digestmod = MD5
|
| 77 |
+
|
| 78 |
+
if msg is None:
|
| 79 |
+
msg = b""
|
| 80 |
+
|
| 81 |
+
# Size of the MAC tag
|
| 82 |
+
self.digest_size = digestmod.digest_size
|
| 83 |
+
|
| 84 |
+
self._digestmod = digestmod
|
| 85 |
+
|
| 86 |
+
# Hash OID --> HMAC OID
|
| 87 |
+
try:
|
| 88 |
+
self.oid = _hash2hmac_oid[digestmod.oid]
|
| 89 |
+
except (KeyError, AttributeError):
|
| 90 |
+
pass
|
| 91 |
+
|
| 92 |
+
if isinstance(key, memoryview):
|
| 93 |
+
key = key.tobytes()
|
| 94 |
+
|
| 95 |
+
try:
|
| 96 |
+
if len(key) <= digestmod.block_size:
|
| 97 |
+
# Step 1 or 2
|
| 98 |
+
key_0 = key + b"\x00" * (digestmod.block_size - len(key))
|
| 99 |
+
else:
|
| 100 |
+
# Step 3
|
| 101 |
+
hash_k = digestmod.new(key).digest()
|
| 102 |
+
key_0 = hash_k + b"\x00" * (digestmod.block_size - len(hash_k))
|
| 103 |
+
except AttributeError:
|
| 104 |
+
# Not all hash types have "block_size"
|
| 105 |
+
raise ValueError("Hash type incompatible to HMAC")
|
| 106 |
+
|
| 107 |
+
# Step 4
|
| 108 |
+
key_0_ipad = strxor(key_0, b"\x36" * len(key_0))
|
| 109 |
+
|
| 110 |
+
# Start step 5 and 6
|
| 111 |
+
self._inner = digestmod.new(key_0_ipad)
|
| 112 |
+
self._inner.update(msg)
|
| 113 |
+
|
| 114 |
+
# Step 7
|
| 115 |
+
key_0_opad = strxor(key_0, b"\x5c" * len(key_0))
|
| 116 |
+
|
| 117 |
+
# Start step 8 and 9
|
| 118 |
+
self._outer = digestmod.new(key_0_opad)
|
| 119 |
+
|
| 120 |
+
def update(self, msg):
|
| 121 |
+
"""Authenticate the next chunk of message.
|
| 122 |
+
|
| 123 |
+
Args:
|
| 124 |
+
data (byte string/byte array/memoryview): The next chunk of data
|
| 125 |
+
"""
|
| 126 |
+
|
| 127 |
+
self._inner.update(msg)
|
| 128 |
+
return self
|
| 129 |
+
|
| 130 |
+
def _pbkdf2_hmac_assist(self, first_digest, iterations):
|
| 131 |
+
"""Carry out the expensive inner loop for PBKDF2-HMAC"""
|
| 132 |
+
|
| 133 |
+
result = self._digestmod._pbkdf2_hmac_assist(
|
| 134 |
+
self._inner,
|
| 135 |
+
self._outer,
|
| 136 |
+
first_digest,
|
| 137 |
+
iterations)
|
| 138 |
+
return result
|
| 139 |
+
|
| 140 |
+
def copy(self):
|
| 141 |
+
"""Return a copy ("clone") of the HMAC object.
|
| 142 |
+
|
| 143 |
+
The copy will have the same internal state as the original HMAC
|
| 144 |
+
object.
|
| 145 |
+
This can be used to efficiently compute the MAC tag of byte
|
| 146 |
+
strings that share a common initial substring.
|
| 147 |
+
|
| 148 |
+
:return: An :class:`HMAC`
|
| 149 |
+
"""
|
| 150 |
+
|
| 151 |
+
new_hmac = HMAC(b"fake key", digestmod=self._digestmod)
|
| 152 |
+
|
| 153 |
+
# Syncronize the state
|
| 154 |
+
new_hmac._inner = self._inner.copy()
|
| 155 |
+
new_hmac._outer = self._outer.copy()
|
| 156 |
+
|
| 157 |
+
return new_hmac
|
| 158 |
+
|
| 159 |
+
def digest(self):
|
| 160 |
+
"""Return the **binary** (non-printable) MAC tag of the message
|
| 161 |
+
authenticated so far.
|
| 162 |
+
|
| 163 |
+
:return: The MAC tag digest, computed over the data processed so far.
|
| 164 |
+
Binary form.
|
| 165 |
+
:rtype: byte string
|
| 166 |
+
"""
|
| 167 |
+
|
| 168 |
+
frozen_outer_hash = self._outer.copy()
|
| 169 |
+
frozen_outer_hash.update(self._inner.digest())
|
| 170 |
+
return frozen_outer_hash.digest()
|
| 171 |
+
|
| 172 |
+
def verify(self, mac_tag):
|
| 173 |
+
"""Verify that a given **binary** MAC (computed by another party)
|
| 174 |
+
is valid.
|
| 175 |
+
|
| 176 |
+
Args:
|
| 177 |
+
mac_tag (byte string/byte string/memoryview): the expected MAC of the message.
|
| 178 |
+
|
| 179 |
+
Raises:
|
| 180 |
+
ValueError: if the MAC does not match. It means that the message
|
| 181 |
+
has been tampered with or that the MAC key is incorrect.
|
| 182 |
+
"""
|
| 183 |
+
|
| 184 |
+
secret = get_random_bytes(16)
|
| 185 |
+
|
| 186 |
+
mac1 = BLAKE2s.new(digest_bits=160, key=secret, data=mac_tag)
|
| 187 |
+
mac2 = BLAKE2s.new(digest_bits=160, key=secret, data=self.digest())
|
| 188 |
+
|
| 189 |
+
if mac1.digest() != mac2.digest():
|
| 190 |
+
raise ValueError("MAC check failed")
|
| 191 |
+
|
| 192 |
+
def hexdigest(self):
|
| 193 |
+
"""Return the **printable** MAC tag of the message authenticated so far.
|
| 194 |
+
|
| 195 |
+
:return: The MAC tag, computed over the data processed so far.
|
| 196 |
+
Hexadecimal encoded.
|
| 197 |
+
:rtype: string
|
| 198 |
+
"""
|
| 199 |
+
|
| 200 |
+
return "".join(["%02x" % bord(x)
|
| 201 |
+
for x in tuple(self.digest())])
|
| 202 |
+
|
| 203 |
+
def hexverify(self, hex_mac_tag):
|
| 204 |
+
"""Verify that a given **printable** MAC (computed by another party)
|
| 205 |
+
is valid.
|
| 206 |
+
|
| 207 |
+
Args:
|
| 208 |
+
hex_mac_tag (string): the expected MAC of the message,
|
| 209 |
+
as a hexadecimal string.
|
| 210 |
+
|
| 211 |
+
Raises:
|
| 212 |
+
ValueError: if the MAC does not match. It means that the message
|
| 213 |
+
has been tampered with or that the MAC key is incorrect.
|
| 214 |
+
"""
|
| 215 |
+
|
| 216 |
+
self.verify(unhexlify(tobytes(hex_mac_tag)))
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
def new(key, msg=b"", digestmod=None):
|
| 220 |
+
"""Create a new MAC object.
|
| 221 |
+
|
| 222 |
+
Args:
|
| 223 |
+
key (bytes/bytearray/memoryview):
|
| 224 |
+
key for the MAC object.
|
| 225 |
+
It must be long enough to match the expected security level of the
|
| 226 |
+
MAC.
|
| 227 |
+
msg (bytes/bytearray/memoryview):
|
| 228 |
+
Optional. The very first chunk of the message to authenticate.
|
| 229 |
+
It is equivalent to an early call to :meth:`HMAC.update`.
|
| 230 |
+
digestmod (module):
|
| 231 |
+
The hash to use to implement the HMAC.
|
| 232 |
+
Default is :mod:`Crypto.Hash.MD5`.
|
| 233 |
+
|
| 234 |
+
Returns:
|
| 235 |
+
An :class:`HMAC` object
|
| 236 |
+
"""
|
| 237 |
+
|
| 238 |
+
return HMAC(key, msg, digestmod)
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/HMAC.pyi
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from types import ModuleType
|
| 2 |
+
from typing import Union, Dict
|
| 3 |
+
|
| 4 |
+
Buffer = Union[bytes, bytearray, memoryview]
|
| 5 |
+
|
| 6 |
+
digest_size: int
|
| 7 |
+
|
| 8 |
+
class HMAC(object):
|
| 9 |
+
digest_size: int
|
| 10 |
+
|
| 11 |
+
def __init__(self,
|
| 12 |
+
key: Buffer,
|
| 13 |
+
msg: Buffer,
|
| 14 |
+
digestmod: ModuleType) -> None: ...
|
| 15 |
+
def update(self, msg: Buffer) -> HMAC: ...
|
| 16 |
+
def copy(self) -> HMAC: ...
|
| 17 |
+
def digest(self) -> bytes: ...
|
| 18 |
+
def hexdigest(self) -> str: ...
|
| 19 |
+
def verify(self, mac_tag: Buffer) -> None: ...
|
| 20 |
+
def hexverify(self, hex_mac_tag: str) -> None: ...
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def new(key: Buffer,
|
| 24 |
+
msg: Buffer = ...,
|
| 25 |
+
digestmod: ModuleType = ...) -> HMAC: ...
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/KMAC128.py
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ===================================================================
|
| 2 |
+
#
|
| 3 |
+
# Copyright (c) 2021, Legrandin <helderijs@gmail.com>
|
| 4 |
+
# All rights reserved.
|
| 5 |
+
#
|
| 6 |
+
# Redistribution and use in source and binary forms, with or without
|
| 7 |
+
# modification, are permitted provided that the following conditions
|
| 8 |
+
# are met:
|
| 9 |
+
#
|
| 10 |
+
# 1. Redistributions of source code must retain the above copyright
|
| 11 |
+
# notice, this list of conditions and the following disclaimer.
|
| 12 |
+
# 2. Redistributions in binary form must reproduce the above copyright
|
| 13 |
+
# notice, this list of conditions and the following disclaimer in
|
| 14 |
+
# the documentation and/or other materials provided with the
|
| 15 |
+
# distribution.
|
| 16 |
+
#
|
| 17 |
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 18 |
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 19 |
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
| 20 |
+
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
| 21 |
+
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
| 22 |
+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
| 23 |
+
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 24 |
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 25 |
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 26 |
+
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
| 27 |
+
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
| 28 |
+
# POSSIBILITY OF SUCH DAMAGE.
|
| 29 |
+
# ===================================================================
|
| 30 |
+
|
| 31 |
+
from binascii import unhexlify
|
| 32 |
+
|
| 33 |
+
from Crypto.Util.py3compat import bord, tobytes, is_bytes
|
| 34 |
+
from Crypto.Random import get_random_bytes
|
| 35 |
+
|
| 36 |
+
from . import cSHAKE128, SHA3_256
|
| 37 |
+
from .cSHAKE128 import _bytepad, _encode_str, _right_encode
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class KMAC_Hash(object):
|
| 41 |
+
"""A KMAC hash object.
|
| 42 |
+
Do not instantiate directly.
|
| 43 |
+
Use the :func:`new` function.
|
| 44 |
+
"""
|
| 45 |
+
|
| 46 |
+
def __init__(self, data, key, mac_len, custom,
|
| 47 |
+
oid_variant, cshake, rate):
|
| 48 |
+
|
| 49 |
+
# See https://tools.ietf.org/html/rfc8702
|
| 50 |
+
self.oid = "2.16.840.1.101.3.4.2." + oid_variant
|
| 51 |
+
self.digest_size = mac_len
|
| 52 |
+
|
| 53 |
+
self._mac = None
|
| 54 |
+
|
| 55 |
+
partial_newX = _bytepad(_encode_str(tobytes(key)), rate)
|
| 56 |
+
self._cshake = cshake._new(partial_newX, custom, b"KMAC")
|
| 57 |
+
|
| 58 |
+
if data:
|
| 59 |
+
self._cshake.update(data)
|
| 60 |
+
|
| 61 |
+
def update(self, data):
|
| 62 |
+
"""Authenticate the next chunk of message.
|
| 63 |
+
|
| 64 |
+
Args:
|
| 65 |
+
data (bytes/bytearray/memoryview): The next chunk of the message to
|
| 66 |
+
authenticate.
|
| 67 |
+
"""
|
| 68 |
+
|
| 69 |
+
if self._mac:
|
| 70 |
+
raise TypeError("You can only call 'digest' or 'hexdigest' on this object")
|
| 71 |
+
|
| 72 |
+
self._cshake.update(data)
|
| 73 |
+
return self
|
| 74 |
+
|
| 75 |
+
def digest(self):
|
| 76 |
+
"""Return the **binary** (non-printable) MAC tag of the message.
|
| 77 |
+
|
| 78 |
+
:return: The MAC tag. Binary form.
|
| 79 |
+
:rtype: byte string
|
| 80 |
+
"""
|
| 81 |
+
|
| 82 |
+
if not self._mac:
|
| 83 |
+
self._cshake.update(_right_encode(self.digest_size * 8))
|
| 84 |
+
self._mac = self._cshake.read(self.digest_size)
|
| 85 |
+
|
| 86 |
+
return self._mac
|
| 87 |
+
|
| 88 |
+
def hexdigest(self):
|
| 89 |
+
"""Return the **printable** MAC tag of the message.
|
| 90 |
+
|
| 91 |
+
:return: The MAC tag. Hexadecimal encoded.
|
| 92 |
+
:rtype: string
|
| 93 |
+
"""
|
| 94 |
+
|
| 95 |
+
return "".join(["%02x" % bord(x) for x in tuple(self.digest())])
|
| 96 |
+
|
| 97 |
+
def verify(self, mac_tag):
|
| 98 |
+
"""Verify that a given **binary** MAC (computed by another party)
|
| 99 |
+
is valid.
|
| 100 |
+
|
| 101 |
+
Args:
|
| 102 |
+
mac_tag (bytes/bytearray/memoryview): the expected MAC of the message.
|
| 103 |
+
|
| 104 |
+
Raises:
|
| 105 |
+
ValueError: if the MAC does not match. It means that the message
|
| 106 |
+
has been tampered with or that the MAC key is incorrect.
|
| 107 |
+
"""
|
| 108 |
+
|
| 109 |
+
secret = get_random_bytes(16)
|
| 110 |
+
|
| 111 |
+
mac1 = SHA3_256.new(secret + mac_tag)
|
| 112 |
+
mac2 = SHA3_256.new(secret + self.digest())
|
| 113 |
+
|
| 114 |
+
if mac1.digest() != mac2.digest():
|
| 115 |
+
raise ValueError("MAC check failed")
|
| 116 |
+
|
| 117 |
+
def hexverify(self, hex_mac_tag):
|
| 118 |
+
"""Verify that a given **printable** MAC (computed by another party)
|
| 119 |
+
is valid.
|
| 120 |
+
|
| 121 |
+
Args:
|
| 122 |
+
hex_mac_tag (string): the expected MAC of the message, as a hexadecimal string.
|
| 123 |
+
|
| 124 |
+
Raises:
|
| 125 |
+
ValueError: if the MAC does not match. It means that the message
|
| 126 |
+
has been tampered with or that the MAC key is incorrect.
|
| 127 |
+
"""
|
| 128 |
+
|
| 129 |
+
self.verify(unhexlify(tobytes(hex_mac_tag)))
|
| 130 |
+
|
| 131 |
+
def new(self, **kwargs):
|
| 132 |
+
"""Return a new instance of a KMAC hash object.
|
| 133 |
+
See :func:`new`.
|
| 134 |
+
"""
|
| 135 |
+
|
| 136 |
+
if "mac_len" not in kwargs:
|
| 137 |
+
kwargs["mac_len"] = self.digest_size
|
| 138 |
+
|
| 139 |
+
return new(**kwargs)
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def new(**kwargs):
|
| 143 |
+
"""Create a new KMAC128 object.
|
| 144 |
+
|
| 145 |
+
Args:
|
| 146 |
+
key (bytes/bytearray/memoryview):
|
| 147 |
+
The key to use to compute the MAC.
|
| 148 |
+
It must be at least 128 bits long (16 bytes).
|
| 149 |
+
data (bytes/bytearray/memoryview):
|
| 150 |
+
Optional. The very first chunk of the message to authenticate.
|
| 151 |
+
It is equivalent to an early call to :meth:`KMAC_Hash.update`.
|
| 152 |
+
mac_len (integer):
|
| 153 |
+
Optional. The size of the authentication tag, in bytes.
|
| 154 |
+
Default is 64. Minimum is 8.
|
| 155 |
+
custom (bytes/bytearray/memoryview):
|
| 156 |
+
Optional. A customization byte string (``S`` in SP 800-185).
|
| 157 |
+
|
| 158 |
+
Returns:
|
| 159 |
+
A :class:`KMAC_Hash` hash object
|
| 160 |
+
"""
|
| 161 |
+
|
| 162 |
+
key = kwargs.pop("key", None)
|
| 163 |
+
if not is_bytes(key):
|
| 164 |
+
raise TypeError("You must pass a key to KMAC128")
|
| 165 |
+
if len(key) < 16:
|
| 166 |
+
raise ValueError("The key must be at least 128 bits long (16 bytes)")
|
| 167 |
+
|
| 168 |
+
data = kwargs.pop("data", None)
|
| 169 |
+
|
| 170 |
+
mac_len = kwargs.pop("mac_len", 64)
|
| 171 |
+
if mac_len < 8:
|
| 172 |
+
raise ValueError("'mac_len' must be 8 bytes or more")
|
| 173 |
+
|
| 174 |
+
custom = kwargs.pop("custom", b"")
|
| 175 |
+
|
| 176 |
+
if kwargs:
|
| 177 |
+
raise TypeError("Unknown parameters: " + str(kwargs))
|
| 178 |
+
|
| 179 |
+
return KMAC_Hash(data, key, mac_len, custom, "19", cSHAKE128, 168)
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/KMAC128.pyi
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Union
|
| 2 |
+
from types import ModuleType
|
| 3 |
+
|
| 4 |
+
Buffer = Union[bytes, bytearray, memoryview]
|
| 5 |
+
|
| 6 |
+
class KMAC_Hash(object):
|
| 7 |
+
|
| 8 |
+
def __init__(self,
|
| 9 |
+
data: Buffer,
|
| 10 |
+
key: Buffer,
|
| 11 |
+
mac_len: int,
|
| 12 |
+
custom: Buffer,
|
| 13 |
+
oid_variant: str,
|
| 14 |
+
cshake: ModuleType,
|
| 15 |
+
rate: int) -> None: ...
|
| 16 |
+
|
| 17 |
+
def update(self, data: Buffer) -> KMAC_Hash: ...
|
| 18 |
+
|
| 19 |
+
def digest(self) -> bytes: ...
|
| 20 |
+
def hexdigest(self) -> str: ...
|
| 21 |
+
def verify(self, mac_tag: Buffer) -> None: ...
|
| 22 |
+
def hexverify(self, hex_mac_tag: str) -> None: ...
|
| 23 |
+
def new(self,
|
| 24 |
+
data: Buffer = ...,
|
| 25 |
+
mac_len: int = ...,
|
| 26 |
+
key: Buffer = ...,
|
| 27 |
+
custom: Buffer = ...) -> KMAC_Hash: ...
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def new(key: Buffer,
|
| 31 |
+
data: Buffer = ...,
|
| 32 |
+
mac_len: int = ...,
|
| 33 |
+
custom: Buffer = ...) -> KMAC_Hash: ...
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/KangarooTwelve.py
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ===================================================================
|
| 2 |
+
#
|
| 3 |
+
# Copyright (c) 2021, Legrandin <helderijs@gmail.com>
|
| 4 |
+
# All rights reserved.
|
| 5 |
+
#
|
| 6 |
+
# Redistribution and use in source and binary forms, with or without
|
| 7 |
+
# modification, are permitted provided that the following conditions
|
| 8 |
+
# are met:
|
| 9 |
+
#
|
| 10 |
+
# 1. Redistributions of source code must retain the above copyright
|
| 11 |
+
# notice, this list of conditions and the following disclaimer.
|
| 12 |
+
# 2. Redistributions in binary form must reproduce the above copyright
|
| 13 |
+
# notice, this list of conditions and the following disclaimer in
|
| 14 |
+
# the documentation and/or other materials provided with the
|
| 15 |
+
# distribution.
|
| 16 |
+
#
|
| 17 |
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 18 |
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 19 |
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
| 20 |
+
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
| 21 |
+
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
| 22 |
+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
| 23 |
+
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 24 |
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 25 |
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 26 |
+
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
| 27 |
+
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
| 28 |
+
# POSSIBILITY OF SUCH DAMAGE.
|
| 29 |
+
# ===================================================================
|
| 30 |
+
|
| 31 |
+
from Crypto.Util.number import long_to_bytes
|
| 32 |
+
from Crypto.Util.py3compat import bchr
|
| 33 |
+
|
| 34 |
+
from . import TurboSHAKE128
|
| 35 |
+
|
| 36 |
+
def _length_encode(x):
|
| 37 |
+
if x == 0:
|
| 38 |
+
return b'\x00'
|
| 39 |
+
|
| 40 |
+
S = long_to_bytes(x)
|
| 41 |
+
return S + bchr(len(S))
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
# Possible states for a KangarooTwelve instance, which depend on the amount of data processed so far.
|
| 45 |
+
SHORT_MSG = 1 # Still within the first 8192 bytes, but it is not certain we will exceed them.
|
| 46 |
+
LONG_MSG_S0 = 2 # Still within the first 8192 bytes, and it is certain we will exceed them.
|
| 47 |
+
LONG_MSG_SX = 3 # Beyond the first 8192 bytes.
|
| 48 |
+
SQUEEZING = 4 # No more data to process.
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
class K12_XOF(object):
|
| 52 |
+
"""A KangarooTwelve hash object.
|
| 53 |
+
Do not instantiate directly.
|
| 54 |
+
Use the :func:`new` function.
|
| 55 |
+
"""
|
| 56 |
+
|
| 57 |
+
def __init__(self, data, custom):
|
| 58 |
+
|
| 59 |
+
if custom == None:
|
| 60 |
+
custom = b''
|
| 61 |
+
|
| 62 |
+
self._custom = custom + _length_encode(len(custom))
|
| 63 |
+
self._state = SHORT_MSG
|
| 64 |
+
self._padding = None # Final padding is only decided in read()
|
| 65 |
+
|
| 66 |
+
# Internal hash that consumes FinalNode
|
| 67 |
+
# The real domain separation byte will be known before squeezing
|
| 68 |
+
self._hash1 = TurboSHAKE128.new(domain=1)
|
| 69 |
+
self._length1 = 0
|
| 70 |
+
|
| 71 |
+
# Internal hash that produces CV_i (reset each time)
|
| 72 |
+
self._hash2 = None
|
| 73 |
+
self._length2 = 0
|
| 74 |
+
|
| 75 |
+
# Incremented by one for each 8192-byte block
|
| 76 |
+
self._ctr = 0
|
| 77 |
+
|
| 78 |
+
if data:
|
| 79 |
+
self.update(data)
|
| 80 |
+
|
| 81 |
+
def update(self, data):
|
| 82 |
+
"""Hash the next piece of data.
|
| 83 |
+
|
| 84 |
+
.. note::
|
| 85 |
+
For better performance, submit chunks with a length multiple of 8192 bytes.
|
| 86 |
+
|
| 87 |
+
Args:
|
| 88 |
+
data (byte string/byte array/memoryview): The next chunk of the
|
| 89 |
+
message to hash.
|
| 90 |
+
"""
|
| 91 |
+
|
| 92 |
+
if self._state == SQUEEZING:
|
| 93 |
+
raise TypeError("You cannot call 'update' after the first 'read'")
|
| 94 |
+
|
| 95 |
+
if self._state == SHORT_MSG:
|
| 96 |
+
next_length = self._length1 + len(data)
|
| 97 |
+
|
| 98 |
+
if next_length + len(self._custom) <= 8192:
|
| 99 |
+
self._length1 = next_length
|
| 100 |
+
self._hash1.update(data)
|
| 101 |
+
return self
|
| 102 |
+
|
| 103 |
+
# Switch to tree hashing
|
| 104 |
+
self._state = LONG_MSG_S0
|
| 105 |
+
|
| 106 |
+
if self._state == LONG_MSG_S0:
|
| 107 |
+
data_mem = memoryview(data)
|
| 108 |
+
assert(self._length1 < 8192)
|
| 109 |
+
dtc = min(len(data), 8192 - self._length1)
|
| 110 |
+
self._hash1.update(data_mem[:dtc])
|
| 111 |
+
self._length1 += dtc
|
| 112 |
+
|
| 113 |
+
if self._length1 < 8192:
|
| 114 |
+
return self
|
| 115 |
+
|
| 116 |
+
# Finish hashing S_0 and start S_1
|
| 117 |
+
assert(self._length1 == 8192)
|
| 118 |
+
|
| 119 |
+
divider = b'\x03' + b'\x00' * 7
|
| 120 |
+
self._hash1.update(divider)
|
| 121 |
+
self._length1 += 8
|
| 122 |
+
|
| 123 |
+
self._hash2 = TurboSHAKE128.new(domain=0x0B)
|
| 124 |
+
self._length2 = 0
|
| 125 |
+
self._ctr = 1
|
| 126 |
+
|
| 127 |
+
self._state = LONG_MSG_SX
|
| 128 |
+
return self.update(data_mem[dtc:])
|
| 129 |
+
|
| 130 |
+
# LONG_MSG_SX
|
| 131 |
+
assert(self._state == LONG_MSG_SX)
|
| 132 |
+
index = 0
|
| 133 |
+
len_data = len(data)
|
| 134 |
+
|
| 135 |
+
# All iteractions could actually run in parallel
|
| 136 |
+
data_mem = memoryview(data)
|
| 137 |
+
while index < len_data:
|
| 138 |
+
|
| 139 |
+
new_index = min(index + 8192 - self._length2, len_data)
|
| 140 |
+
self._hash2.update(data_mem[index:new_index])
|
| 141 |
+
self._length2 += new_index - index
|
| 142 |
+
index = new_index
|
| 143 |
+
|
| 144 |
+
if self._length2 == 8192:
|
| 145 |
+
cv_i = self._hash2.read(32)
|
| 146 |
+
self._hash1.update(cv_i)
|
| 147 |
+
self._length1 += 32
|
| 148 |
+
self._hash2._reset()
|
| 149 |
+
self._length2 = 0
|
| 150 |
+
self._ctr += 1
|
| 151 |
+
|
| 152 |
+
return self
|
| 153 |
+
|
| 154 |
+
def read(self, length):
|
| 155 |
+
"""
|
| 156 |
+
Produce more bytes of the digest.
|
| 157 |
+
|
| 158 |
+
.. note::
|
| 159 |
+
You cannot use :meth:`update` anymore after the first call to
|
| 160 |
+
:meth:`read`.
|
| 161 |
+
|
| 162 |
+
Args:
|
| 163 |
+
length (integer): the amount of bytes this method must return
|
| 164 |
+
|
| 165 |
+
:return: the next piece of XOF output (of the given length)
|
| 166 |
+
:rtype: byte string
|
| 167 |
+
"""
|
| 168 |
+
|
| 169 |
+
custom_was_consumed = False
|
| 170 |
+
|
| 171 |
+
if self._state == SHORT_MSG:
|
| 172 |
+
self._hash1.update(self._custom)
|
| 173 |
+
self._padding = 0x07
|
| 174 |
+
self._state = SQUEEZING
|
| 175 |
+
|
| 176 |
+
if self._state == LONG_MSG_S0:
|
| 177 |
+
self.update(self._custom)
|
| 178 |
+
custom_was_consumed = True
|
| 179 |
+
assert(self._state == LONG_MSG_SX)
|
| 180 |
+
|
| 181 |
+
if self._state == LONG_MSG_SX:
|
| 182 |
+
if not custom_was_consumed:
|
| 183 |
+
self.update(self._custom)
|
| 184 |
+
|
| 185 |
+
# Is there still some leftover data in hash2?
|
| 186 |
+
if self._length2 > 0:
|
| 187 |
+
cv_i = self._hash2.read(32)
|
| 188 |
+
self._hash1.update(cv_i)
|
| 189 |
+
self._length1 += 32
|
| 190 |
+
self._hash2._reset()
|
| 191 |
+
self._length2 = 0
|
| 192 |
+
self._ctr += 1
|
| 193 |
+
|
| 194 |
+
trailer = _length_encode(self._ctr - 1) + b'\xFF\xFF'
|
| 195 |
+
self._hash1.update(trailer)
|
| 196 |
+
|
| 197 |
+
self._padding = 0x06
|
| 198 |
+
self._state = SQUEEZING
|
| 199 |
+
|
| 200 |
+
self._hash1._domain = self._padding
|
| 201 |
+
return self._hash1.read(length)
|
| 202 |
+
|
| 203 |
+
def new(self, data=None, custom=b''):
|
| 204 |
+
return type(self)(data, custom)
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
def new(data=None, custom=None):
|
| 208 |
+
"""Return a fresh instance of a KangarooTwelve object.
|
| 209 |
+
|
| 210 |
+
Args:
|
| 211 |
+
data (bytes/bytearray/memoryview):
|
| 212 |
+
Optional.
|
| 213 |
+
The very first chunk of the message to hash.
|
| 214 |
+
It is equivalent to an early call to :meth:`update`.
|
| 215 |
+
custom (bytes):
|
| 216 |
+
Optional.
|
| 217 |
+
A customization byte string.
|
| 218 |
+
|
| 219 |
+
:Return: A :class:`K12_XOF` object
|
| 220 |
+
"""
|
| 221 |
+
|
| 222 |
+
return K12_XOF(data, custom)
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/Poly1305.pyi
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from types import ModuleType
|
| 2 |
+
from typing import Union
|
| 3 |
+
|
| 4 |
+
Buffer = Union[bytes, bytearray, memoryview]
|
| 5 |
+
|
| 6 |
+
class Poly1305_MAC(object):
|
| 7 |
+
block_size: int
|
| 8 |
+
digest_size: int
|
| 9 |
+
oid: str
|
| 10 |
+
|
| 11 |
+
def __init__(self,
|
| 12 |
+
r : int,
|
| 13 |
+
s : int,
|
| 14 |
+
data : Buffer) -> None: ...
|
| 15 |
+
def update(self, data: Buffer) -> Poly1305_MAC: ...
|
| 16 |
+
def digest(self) -> bytes: ...
|
| 17 |
+
def hexdigest(self) -> str: ...
|
| 18 |
+
def verify(self, mac_tag: Buffer) -> None: ...
|
| 19 |
+
def hexverify(self, hex_mac_tag: str) -> None: ...
|
| 20 |
+
|
| 21 |
+
def new(key: Buffer,
|
| 22 |
+
cipher: ModuleType,
|
| 23 |
+
nonce: Buffer = ...,
|
| 24 |
+
data: Buffer = ...) -> Poly1305_MAC: ...
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/RIPEMD.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
#
|
| 3 |
+
# ===================================================================
|
| 4 |
+
# The contents of this file are dedicated to the public domain. To
|
| 5 |
+
# the extent that dedication to the public domain is not available,
|
| 6 |
+
# everyone is granted a worldwide, perpetual, royalty-free,
|
| 7 |
+
# non-exclusive license to exercise all rights associated with the
|
| 8 |
+
# contents of this file for any purpose whatsoever.
|
| 9 |
+
# No rights are reserved.
|
| 10 |
+
#
|
| 11 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 12 |
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
| 13 |
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
| 14 |
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
| 15 |
+
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
| 16 |
+
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 17 |
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 18 |
+
# SOFTWARE.
|
| 19 |
+
# ===================================================================
|
| 20 |
+
|
| 21 |
+
# This file exists for backward compatibility with old code that refers to
|
| 22 |
+
# Crypto.Hash.RIPEMD
|
| 23 |
+
|
| 24 |
+
"""Deprecated alias for `Crypto.Hash.RIPEMD160`"""
|
| 25 |
+
|
| 26 |
+
from Crypto.Hash.RIPEMD160 import new, block_size, digest_size
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/RIPEMD.pyi
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file exists for backward compatibility with old code that refers to
|
| 2 |
+
# Crypto.Hash.SHA
|
| 3 |
+
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/SHA224.pyi
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Union, Optional
|
| 2 |
+
|
| 3 |
+
Buffer = Union[bytes, bytearray, memoryview]
|
| 4 |
+
|
| 5 |
+
class SHA224Hash(object):
|
| 6 |
+
digest_size: int
|
| 7 |
+
block_size: int
|
| 8 |
+
oid: str
|
| 9 |
+
|
| 10 |
+
def __init__(self, data: Optional[Buffer] = ...) -> None: ...
|
| 11 |
+
def update(self, data: Buffer) -> None: ...
|
| 12 |
+
def digest(self) -> bytes: ...
|
| 13 |
+
def hexdigest(self) -> str: ...
|
| 14 |
+
def copy(self) -> SHA224Hash: ...
|
| 15 |
+
def new(self, data: Optional[Buffer] = ...) -> SHA224Hash: ...
|
| 16 |
+
|
| 17 |
+
def new(data: Optional[Buffer] = ...) -> SHA224Hash: ...
|
| 18 |
+
digest_size: int
|
| 19 |
+
block_size: int
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/SHA3_256.py
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
#
|
| 3 |
+
# ===================================================================
|
| 4 |
+
# The contents of this file are dedicated to the public domain. To
|
| 5 |
+
# the extent that dedication to the public domain is not available,
|
| 6 |
+
# everyone is granted a worldwide, perpetual, royalty-free,
|
| 7 |
+
# non-exclusive license to exercise all rights associated with the
|
| 8 |
+
# contents of this file for any purpose whatsoever.
|
| 9 |
+
# No rights are reserved.
|
| 10 |
+
#
|
| 11 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 12 |
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
| 13 |
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
| 14 |
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
| 15 |
+
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
| 16 |
+
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 17 |
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 18 |
+
# SOFTWARE.
|
| 19 |
+
# ===================================================================
|
| 20 |
+
|
| 21 |
+
from Crypto.Util.py3compat import bord
|
| 22 |
+
|
| 23 |
+
from Crypto.Util._raw_api import (load_pycryptodome_raw_lib,
|
| 24 |
+
VoidPointer, SmartPointer,
|
| 25 |
+
create_string_buffer,
|
| 26 |
+
get_raw_buffer, c_size_t,
|
| 27 |
+
c_uint8_ptr, c_ubyte)
|
| 28 |
+
|
| 29 |
+
from Crypto.Hash.keccak import _raw_keccak_lib
|
| 30 |
+
|
| 31 |
+
class SHA3_256_Hash(object):
|
| 32 |
+
"""A SHA3-256 hash object.
|
| 33 |
+
Do not instantiate directly.
|
| 34 |
+
Use the :func:`new` function.
|
| 35 |
+
|
| 36 |
+
:ivar oid: ASN.1 Object ID
|
| 37 |
+
:vartype oid: string
|
| 38 |
+
|
| 39 |
+
:ivar digest_size: the size in bytes of the resulting hash
|
| 40 |
+
:vartype digest_size: integer
|
| 41 |
+
"""
|
| 42 |
+
|
| 43 |
+
# The size of the resulting hash in bytes.
|
| 44 |
+
digest_size = 32
|
| 45 |
+
|
| 46 |
+
# ASN.1 Object ID
|
| 47 |
+
oid = "2.16.840.1.101.3.4.2.8"
|
| 48 |
+
|
| 49 |
+
# Input block size for HMAC
|
| 50 |
+
block_size = 136
|
| 51 |
+
|
| 52 |
+
def __init__(self, data, update_after_digest):
|
| 53 |
+
self._update_after_digest = update_after_digest
|
| 54 |
+
self._digest_done = False
|
| 55 |
+
self._padding = 0x06
|
| 56 |
+
|
| 57 |
+
state = VoidPointer()
|
| 58 |
+
result = _raw_keccak_lib.keccak_init(state.address_of(),
|
| 59 |
+
c_size_t(self.digest_size * 2),
|
| 60 |
+
c_ubyte(24))
|
| 61 |
+
if result:
|
| 62 |
+
raise ValueError("Error %d while instantiating SHA-3/256"
|
| 63 |
+
% result)
|
| 64 |
+
self._state = SmartPointer(state.get(),
|
| 65 |
+
_raw_keccak_lib.keccak_destroy)
|
| 66 |
+
if data:
|
| 67 |
+
self.update(data)
|
| 68 |
+
|
| 69 |
+
def update(self, data):
|
| 70 |
+
"""Continue hashing of a message by consuming the next chunk of data.
|
| 71 |
+
|
| 72 |
+
Args:
|
| 73 |
+
data (byte string/byte array/memoryview): The next chunk of the message being hashed.
|
| 74 |
+
"""
|
| 75 |
+
|
| 76 |
+
if self._digest_done and not self._update_after_digest:
|
| 77 |
+
raise TypeError("You can only call 'digest' or 'hexdigest' on this object")
|
| 78 |
+
|
| 79 |
+
result = _raw_keccak_lib.keccak_absorb(self._state.get(),
|
| 80 |
+
c_uint8_ptr(data),
|
| 81 |
+
c_size_t(len(data))
|
| 82 |
+
)
|
| 83 |
+
if result:
|
| 84 |
+
raise ValueError("Error %d while updating SHA-3/256"
|
| 85 |
+
% result)
|
| 86 |
+
return self
|
| 87 |
+
|
| 88 |
+
def digest(self):
|
| 89 |
+
"""Return the **binary** (non-printable) digest of the message that has been hashed so far.
|
| 90 |
+
|
| 91 |
+
:return: The hash digest, computed over the data processed so far.
|
| 92 |
+
Binary form.
|
| 93 |
+
:rtype: byte string
|
| 94 |
+
"""
|
| 95 |
+
|
| 96 |
+
self._digest_done = True
|
| 97 |
+
|
| 98 |
+
bfr = create_string_buffer(self.digest_size)
|
| 99 |
+
result = _raw_keccak_lib.keccak_digest(self._state.get(),
|
| 100 |
+
bfr,
|
| 101 |
+
c_size_t(self.digest_size),
|
| 102 |
+
c_ubyte(self._padding))
|
| 103 |
+
if result:
|
| 104 |
+
raise ValueError("Error %d while instantiating SHA-3/256"
|
| 105 |
+
% result)
|
| 106 |
+
|
| 107 |
+
self._digest_value = get_raw_buffer(bfr)
|
| 108 |
+
return self._digest_value
|
| 109 |
+
|
| 110 |
+
def hexdigest(self):
|
| 111 |
+
"""Return the **printable** digest of the message that has been hashed so far.
|
| 112 |
+
|
| 113 |
+
:return: The hash digest, computed over the data processed so far.
|
| 114 |
+
Hexadecimal encoded.
|
| 115 |
+
:rtype: string
|
| 116 |
+
"""
|
| 117 |
+
|
| 118 |
+
return "".join(["%02x" % bord(x) for x in self.digest()])
|
| 119 |
+
|
| 120 |
+
def copy(self):
|
| 121 |
+
"""Return a copy ("clone") of the hash object.
|
| 122 |
+
|
| 123 |
+
The copy will have the same internal state as the original hash
|
| 124 |
+
object.
|
| 125 |
+
This can be used to efficiently compute the digests of strings that
|
| 126 |
+
share a common initial substring.
|
| 127 |
+
|
| 128 |
+
:return: A hash object of the same type
|
| 129 |
+
"""
|
| 130 |
+
|
| 131 |
+
clone = self.new()
|
| 132 |
+
result = _raw_keccak_lib.keccak_copy(self._state.get(),
|
| 133 |
+
clone._state.get())
|
| 134 |
+
if result:
|
| 135 |
+
raise ValueError("Error %d while copying SHA3-256" % result)
|
| 136 |
+
return clone
|
| 137 |
+
|
| 138 |
+
def new(self, data=None):
|
| 139 |
+
"""Create a fresh SHA3-256 hash object."""
|
| 140 |
+
|
| 141 |
+
return type(self)(data, self._update_after_digest)
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
def new(*args, **kwargs):
|
| 145 |
+
"""Create a new hash object.
|
| 146 |
+
|
| 147 |
+
Args:
|
| 148 |
+
data (byte string/byte array/memoryview):
|
| 149 |
+
The very first chunk of the message to hash.
|
| 150 |
+
It is equivalent to an early call to :meth:`update`.
|
| 151 |
+
update_after_digest (boolean):
|
| 152 |
+
Whether :meth:`digest` can be followed by another :meth:`update`
|
| 153 |
+
(default: ``False``).
|
| 154 |
+
|
| 155 |
+
:Return: A :class:`SHA3_256_Hash` hash object
|
| 156 |
+
"""
|
| 157 |
+
|
| 158 |
+
data = kwargs.pop("data", None)
|
| 159 |
+
update_after_digest = kwargs.pop("update_after_digest", False)
|
| 160 |
+
if len(args) == 1:
|
| 161 |
+
if data:
|
| 162 |
+
raise ValueError("Initial data for hash specified twice")
|
| 163 |
+
data = args[0]
|
| 164 |
+
|
| 165 |
+
if kwargs:
|
| 166 |
+
raise TypeError("Unknown parameters: " + str(kwargs))
|
| 167 |
+
|
| 168 |
+
return SHA3_256_Hash(data, update_after_digest)
|
| 169 |
+
|
| 170 |
+
# The size of the resulting hash in bytes.
|
| 171 |
+
digest_size = SHA3_256_Hash.digest_size
|
| 172 |
+
|
| 173 |
+
# Input block size for HMAC
|
| 174 |
+
block_size = 136
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/SHA3_256.pyi
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Union, Optional
|
| 2 |
+
|
| 3 |
+
Buffer = Union[bytes, bytearray, memoryview]
|
| 4 |
+
|
| 5 |
+
class SHA3_256_Hash(object):
|
| 6 |
+
digest_size: int
|
| 7 |
+
block_size: int
|
| 8 |
+
oid: str
|
| 9 |
+
def __init__(self, data: Optional[Buffer], update_after_digest: bool) -> None: ...
|
| 10 |
+
def update(self, data: Buffer) -> SHA3_256_Hash: ...
|
| 11 |
+
def digest(self) -> bytes: ...
|
| 12 |
+
def hexdigest(self) -> str: ...
|
| 13 |
+
def copy(self) -> SHA3_256_Hash: ...
|
| 14 |
+
def new(self, data: Optional[Buffer]) -> SHA3_256_Hash: ...
|
| 15 |
+
|
| 16 |
+
def new(__data: Buffer = ..., update_after_digest: bool = ...) -> SHA3_256_Hash: ...
|
| 17 |
+
|
| 18 |
+
digest_size: int
|
| 19 |
+
block_size: int
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/SHA3_512.pyi
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Union, Optional
|
| 2 |
+
|
| 3 |
+
Buffer = Union[bytes, bytearray, memoryview]
|
| 4 |
+
|
| 5 |
+
class SHA3_512_Hash(object):
|
| 6 |
+
digest_size: int
|
| 7 |
+
block_size: int
|
| 8 |
+
oid: str
|
| 9 |
+
def __init__(self, data: Optional[Buffer], update_after_digest: bool) -> None: ...
|
| 10 |
+
def update(self, data: Buffer) -> SHA3_512_Hash: ...
|
| 11 |
+
def digest(self) -> bytes: ...
|
| 12 |
+
def hexdigest(self) -> str: ...
|
| 13 |
+
def copy(self) -> SHA3_512_Hash: ...
|
| 14 |
+
def new(self, data: Optional[Buffer]) -> SHA3_512_Hash: ...
|
| 15 |
+
|
| 16 |
+
def new(__data: Buffer = ..., update_after_digest: bool = ...) -> SHA3_512_Hash: ...
|
| 17 |
+
|
| 18 |
+
digest_size: int
|
| 19 |
+
block_size: int
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/SHA512.pyi
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Union, Optional
|
| 2 |
+
|
| 3 |
+
Buffer = Union[bytes, bytearray, memoryview]
|
| 4 |
+
|
| 5 |
+
class SHA512Hash(object):
|
| 6 |
+
digest_size: int
|
| 7 |
+
block_size: int
|
| 8 |
+
oid: str
|
| 9 |
+
|
| 10 |
+
def __init__(self,
|
| 11 |
+
data: Optional[Buffer],
|
| 12 |
+
truncate: Optional[str]) -> None: ...
|
| 13 |
+
def update(self, data: Buffer) -> None: ...
|
| 14 |
+
def digest(self) -> bytes: ...
|
| 15 |
+
def hexdigest(self) -> str: ...
|
| 16 |
+
def copy(self) -> SHA512Hash: ...
|
| 17 |
+
def new(self, data: Optional[Buffer] = ...) -> SHA512Hash: ...
|
| 18 |
+
|
| 19 |
+
def new(data: Optional[Buffer] = ...,
|
| 20 |
+
truncate: Optional[str] = ...) -> SHA512Hash: ...
|
| 21 |
+
digest_size: int
|
| 22 |
+
block_size: int
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/SHAKE256.pyi
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Union, Optional
|
| 2 |
+
|
| 3 |
+
Buffer = Union[bytes, bytearray, memoryview]
|
| 4 |
+
|
| 5 |
+
class SHAKE256_XOF(object):
|
| 6 |
+
oid: str
|
| 7 |
+
def __init__(self,
|
| 8 |
+
data: Optional[Buffer] = ...) -> None: ...
|
| 9 |
+
def update(self, data: Buffer) -> SHAKE256_XOF: ...
|
| 10 |
+
def read(self, length: int) -> bytes: ...
|
| 11 |
+
def new(self, data: Optional[Buffer] = ...) -> SHAKE256_XOF: ...
|
| 12 |
+
|
| 13 |
+
def new(data: Optional[Buffer] = ...) -> SHAKE256_XOF: ...
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/TupleHash256.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ===================================================================
|
| 2 |
+
#
|
| 3 |
+
# Copyright (c) 2021, Legrandin <helderijs@gmail.com>
|
| 4 |
+
# All rights reserved.
|
| 5 |
+
#
|
| 6 |
+
# Redistribution and use in source and binary forms, with or without
|
| 7 |
+
# modification, are permitted provided that the following conditions
|
| 8 |
+
# are met:
|
| 9 |
+
#
|
| 10 |
+
# 1. Redistributions of source code must retain the above copyright
|
| 11 |
+
# notice, this list of conditions and the following disclaimer.
|
| 12 |
+
# 2. Redistributions in binary form must reproduce the above copyright
|
| 13 |
+
# notice, this list of conditions and the following disclaimer in
|
| 14 |
+
# the documentation and/or other materials provided with the
|
| 15 |
+
# distribution.
|
| 16 |
+
#
|
| 17 |
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 18 |
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 19 |
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
| 20 |
+
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
| 21 |
+
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
| 22 |
+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
| 23 |
+
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 24 |
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 25 |
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 26 |
+
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
| 27 |
+
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
| 28 |
+
# POSSIBILITY OF SUCH DAMAGE.
|
| 29 |
+
# ===================================================================
|
| 30 |
+
|
| 31 |
+
from . import cSHAKE256
|
| 32 |
+
from .TupleHash128 import TupleHash
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def new(**kwargs):
|
| 36 |
+
"""Create a new TupleHash256 object.
|
| 37 |
+
|
| 38 |
+
Args:
|
| 39 |
+
digest_bytes (integer):
|
| 40 |
+
Optional. The size of the digest, in bytes.
|
| 41 |
+
Default is 64. Minimum is 8.
|
| 42 |
+
digest_bits (integer):
|
| 43 |
+
Optional and alternative to ``digest_bytes``.
|
| 44 |
+
The size of the digest, in bits (and in steps of 8).
|
| 45 |
+
Default is 512. Minimum is 64.
|
| 46 |
+
custom (bytes):
|
| 47 |
+
Optional.
|
| 48 |
+
A customization bytestring (``S`` in SP 800-185).
|
| 49 |
+
|
| 50 |
+
:Return: A :class:`TupleHash` object
|
| 51 |
+
"""
|
| 52 |
+
|
| 53 |
+
digest_bytes = kwargs.pop("digest_bytes", None)
|
| 54 |
+
digest_bits = kwargs.pop("digest_bits", None)
|
| 55 |
+
if None not in (digest_bytes, digest_bits):
|
| 56 |
+
raise TypeError("Only one digest parameter must be provided")
|
| 57 |
+
if (None, None) == (digest_bytes, digest_bits):
|
| 58 |
+
digest_bytes = 64
|
| 59 |
+
if digest_bytes is not None:
|
| 60 |
+
if digest_bytes < 8:
|
| 61 |
+
raise ValueError("'digest_bytes' must be at least 8")
|
| 62 |
+
else:
|
| 63 |
+
if digest_bits < 64 or digest_bits % 8:
|
| 64 |
+
raise ValueError("'digest_bytes' must be at least 64 "
|
| 65 |
+
"in steps of 8")
|
| 66 |
+
digest_bytes = digest_bits // 8
|
| 67 |
+
|
| 68 |
+
custom = kwargs.pop("custom", b'')
|
| 69 |
+
|
| 70 |
+
return TupleHash(custom, cSHAKE256, digest_bytes)
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/TupleHash256.pyi
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .TupleHash128 import TupleHash
|
| 2 |
+
|
| 3 |
+
def new(digest_bytes: int = ...,
|
| 4 |
+
digest_bits: int = ...,
|
| 5 |
+
custom: int = ...) -> TupleHash: ...
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/_RIPEMD160.abi3.so
ADDED
|
Binary file (60.7 kB). View file
|
|
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/_SHA384.abi3.so
ADDED
|
Binary file (54.2 kB). View file
|
|
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/_SHA512.abi3.so
ADDED
|
Binary file (54.2 kB). View file
|
|
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/__init__.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
#
|
| 3 |
+
# ===================================================================
|
| 4 |
+
# The contents of this file are dedicated to the public domain. To
|
| 5 |
+
# the extent that dedication to the public domain is not available,
|
| 6 |
+
# everyone is granted a worldwide, perpetual, royalty-free,
|
| 7 |
+
# non-exclusive license to exercise all rights associated with the
|
| 8 |
+
# contents of this file for any purpose whatsoever.
|
| 9 |
+
# No rights are reserved.
|
| 10 |
+
#
|
| 11 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 12 |
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
| 13 |
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
| 14 |
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
| 15 |
+
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
| 16 |
+
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 17 |
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 18 |
+
# SOFTWARE.
|
| 19 |
+
# ===================================================================
|
| 20 |
+
|
| 21 |
+
__all__ = ['HMAC', 'MD2', 'MD4', 'MD5', 'RIPEMD160', 'SHA1',
|
| 22 |
+
'SHA224', 'SHA256', 'SHA384', 'SHA512',
|
| 23 |
+
'SHA3_224', 'SHA3_256', 'SHA3_384', 'SHA3_512',
|
| 24 |
+
'CMAC', 'Poly1305',
|
| 25 |
+
'cSHAKE128', 'cSHAKE256', 'KMAC128', 'KMAC256',
|
| 26 |
+
'TupleHash128', 'TupleHash256', 'KangarooTwelve',
|
| 27 |
+
'TurboSHAKE128', 'TurboSHAKE256']
|
| 28 |
+
|
| 29 |
+
def new(name):
|
| 30 |
+
"""Return a new hash instance, based on its name or
|
| 31 |
+
on its ASN.1 Object ID"""
|
| 32 |
+
|
| 33 |
+
name = name.upper()
|
| 34 |
+
if name in ("1.3.14.3.2.26", "SHA1", "SHA-1"):
|
| 35 |
+
from . import SHA1
|
| 36 |
+
return SHA1.new()
|
| 37 |
+
if name in ("2.16.840.1.101.3.4.2.4", "SHA224", "SHA-224"):
|
| 38 |
+
from . import SHA224
|
| 39 |
+
return SHA224.new()
|
| 40 |
+
if name in ("2.16.840.1.101.3.4.2.1", "SHA256", "SHA-256"):
|
| 41 |
+
from . import SHA256
|
| 42 |
+
return SHA256.new()
|
| 43 |
+
if name in ("2.16.840.1.101.3.4.2.2", "SHA384", "SHA-384"):
|
| 44 |
+
from . import SHA384
|
| 45 |
+
return SHA384.new()
|
| 46 |
+
if name in ("2.16.840.1.101.3.4.2.3", "SHA512", "SHA-512"):
|
| 47 |
+
from . import SHA512
|
| 48 |
+
return SHA512.new()
|
| 49 |
+
if name in ("2.16.840.1.101.3.4.2.5", "SHA512-224", "SHA-512-224"):
|
| 50 |
+
from . import SHA512
|
| 51 |
+
return SHA512.new(truncate='224')
|
| 52 |
+
if name in ("2.16.840.1.101.3.4.2.6", "SHA512-256", "SHA-512-256"):
|
| 53 |
+
from . import SHA512
|
| 54 |
+
return SHA512.new(truncate='256')
|
| 55 |
+
if name in ("2.16.840.1.101.3.4.2.7", "SHA3-224", "SHA-3-224"):
|
| 56 |
+
from . import SHA3_224
|
| 57 |
+
return SHA3_224.new()
|
| 58 |
+
if name in ("2.16.840.1.101.3.4.2.8", "SHA3-256", "SHA-3-256"):
|
| 59 |
+
from . import SHA3_256
|
| 60 |
+
return SHA3_256.new()
|
| 61 |
+
if name in ("2.16.840.1.101.3.4.2.9", "SHA3-384", "SHA-3-384"):
|
| 62 |
+
from . import SHA3_384
|
| 63 |
+
return SHA3_384.new()
|
| 64 |
+
if name in ("2.16.840.1.101.3.4.2.10", "SHA3-512", "SHA-3-512"):
|
| 65 |
+
from . import SHA3_512
|
| 66 |
+
return SHA3_512.new()
|
| 67 |
+
else:
|
| 68 |
+
raise ValueError("Unknown hash %s" % str(name))
|
| 69 |
+
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/_ghash_clmul.abi3.so
ADDED
|
Binary file (58.4 kB). View file
|
|
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/_keccak.abi3.so
ADDED
|
Binary file (41.6 kB). View file
|
|
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/_poly1305.abi3.so
ADDED
|
Binary file (33.4 kB). View file
|
|
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/cSHAKE128.py
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ===================================================================
|
| 2 |
+
#
|
| 3 |
+
# Copyright (c) 2021, Legrandin <helderijs@gmail.com>
|
| 4 |
+
# All rights reserved.
|
| 5 |
+
#
|
| 6 |
+
# Redistribution and use in source and binary forms, with or without
|
| 7 |
+
# modification, are permitted provided that the following conditions
|
| 8 |
+
# are met:
|
| 9 |
+
#
|
| 10 |
+
# 1. Redistributions of source code must retain the above copyright
|
| 11 |
+
# notice, this list of conditions and the following disclaimer.
|
| 12 |
+
# 2. Redistributions in binary form must reproduce the above copyright
|
| 13 |
+
# notice, this list of conditions and the following disclaimer in
|
| 14 |
+
# the documentation and/or other materials provided with the
|
| 15 |
+
# distribution.
|
| 16 |
+
#
|
| 17 |
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 18 |
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 19 |
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
| 20 |
+
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
| 21 |
+
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
| 22 |
+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
| 23 |
+
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 24 |
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 25 |
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 26 |
+
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
| 27 |
+
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
| 28 |
+
# POSSIBILITY OF SUCH DAMAGE.
|
| 29 |
+
# ===================================================================
|
| 30 |
+
|
| 31 |
+
from Crypto.Util.py3compat import bchr, concat_buffers
|
| 32 |
+
|
| 33 |
+
from Crypto.Util._raw_api import (VoidPointer, SmartPointer,
|
| 34 |
+
create_string_buffer,
|
| 35 |
+
get_raw_buffer, c_size_t,
|
| 36 |
+
c_uint8_ptr, c_ubyte)
|
| 37 |
+
|
| 38 |
+
from Crypto.Util.number import long_to_bytes
|
| 39 |
+
|
| 40 |
+
from Crypto.Hash.keccak import _raw_keccak_lib
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def _left_encode(x):
|
| 44 |
+
"""Left encode function as defined in NIST SP 800-185"""
|
| 45 |
+
|
| 46 |
+
assert (x < (1 << 2040) and x >= 0)
|
| 47 |
+
|
| 48 |
+
# Get number of bytes needed to represent this integer.
|
| 49 |
+
num = 1 if x == 0 else (x.bit_length() + 7) // 8
|
| 50 |
+
|
| 51 |
+
return bchr(num) + long_to_bytes(x)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def _right_encode(x):
|
| 55 |
+
"""Right encode function as defined in NIST SP 800-185"""
|
| 56 |
+
|
| 57 |
+
assert (x < (1 << 2040) and x >= 0)
|
| 58 |
+
|
| 59 |
+
# Get number of bytes needed to represent this integer.
|
| 60 |
+
num = 1 if x == 0 else (x.bit_length() + 7) // 8
|
| 61 |
+
|
| 62 |
+
return long_to_bytes(x) + bchr(num)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def _encode_str(x):
|
| 66 |
+
"""Encode string function as defined in NIST SP 800-185"""
|
| 67 |
+
|
| 68 |
+
bitlen = len(x) * 8
|
| 69 |
+
if bitlen >= (1 << 2040):
|
| 70 |
+
raise ValueError("String too large to encode in cSHAKE")
|
| 71 |
+
|
| 72 |
+
return concat_buffers(_left_encode(bitlen), x)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def _bytepad(x, length):
|
| 76 |
+
"""Zero pad byte string as defined in NIST SP 800-185"""
|
| 77 |
+
|
| 78 |
+
to_pad = concat_buffers(_left_encode(length), x)
|
| 79 |
+
|
| 80 |
+
# Note: this implementation works with byte aligned strings,
|
| 81 |
+
# hence no additional bit padding is needed at this point.
|
| 82 |
+
npad = (length - len(to_pad) % length) % length
|
| 83 |
+
|
| 84 |
+
return to_pad + b'\x00' * npad
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
class cSHAKE_XOF(object):
|
| 88 |
+
"""A cSHAKE hash object.
|
| 89 |
+
Do not instantiate directly.
|
| 90 |
+
Use the :func:`new` function.
|
| 91 |
+
"""
|
| 92 |
+
|
| 93 |
+
def __init__(self, data, custom, capacity, function):
|
| 94 |
+
state = VoidPointer()
|
| 95 |
+
|
| 96 |
+
if custom or function:
|
| 97 |
+
prefix_unpad = _encode_str(function) + _encode_str(custom)
|
| 98 |
+
prefix = _bytepad(prefix_unpad, (1600 - capacity)//8)
|
| 99 |
+
self._padding = 0x04
|
| 100 |
+
else:
|
| 101 |
+
prefix = None
|
| 102 |
+
self._padding = 0x1F # for SHAKE
|
| 103 |
+
|
| 104 |
+
result = _raw_keccak_lib.keccak_init(state.address_of(),
|
| 105 |
+
c_size_t(capacity//8),
|
| 106 |
+
c_ubyte(24))
|
| 107 |
+
if result:
|
| 108 |
+
raise ValueError("Error %d while instantiating cSHAKE"
|
| 109 |
+
% result)
|
| 110 |
+
self._state = SmartPointer(state.get(),
|
| 111 |
+
_raw_keccak_lib.keccak_destroy)
|
| 112 |
+
self._is_squeezing = False
|
| 113 |
+
|
| 114 |
+
if prefix:
|
| 115 |
+
self.update(prefix)
|
| 116 |
+
|
| 117 |
+
if data:
|
| 118 |
+
self.update(data)
|
| 119 |
+
|
| 120 |
+
def update(self, data):
|
| 121 |
+
"""Continue hashing of a message by consuming the next chunk of data.
|
| 122 |
+
|
| 123 |
+
Args:
|
| 124 |
+
data (byte string/byte array/memoryview): The next chunk of the message being hashed.
|
| 125 |
+
"""
|
| 126 |
+
|
| 127 |
+
if self._is_squeezing:
|
| 128 |
+
raise TypeError("You cannot call 'update' after the first 'read'")
|
| 129 |
+
|
| 130 |
+
result = _raw_keccak_lib.keccak_absorb(self._state.get(),
|
| 131 |
+
c_uint8_ptr(data),
|
| 132 |
+
c_size_t(len(data)))
|
| 133 |
+
if result:
|
| 134 |
+
raise ValueError("Error %d while updating %s state"
|
| 135 |
+
% (result, self.name))
|
| 136 |
+
return self
|
| 137 |
+
|
| 138 |
+
def read(self, length):
|
| 139 |
+
"""
|
| 140 |
+
Compute the next piece of XOF output.
|
| 141 |
+
|
| 142 |
+
.. note::
|
| 143 |
+
You cannot use :meth:`update` anymore after the first call to
|
| 144 |
+
:meth:`read`.
|
| 145 |
+
|
| 146 |
+
Args:
|
| 147 |
+
length (integer): the amount of bytes this method must return
|
| 148 |
+
|
| 149 |
+
:return: the next piece of XOF output (of the given length)
|
| 150 |
+
:rtype: byte string
|
| 151 |
+
"""
|
| 152 |
+
|
| 153 |
+
self._is_squeezing = True
|
| 154 |
+
bfr = create_string_buffer(length)
|
| 155 |
+
result = _raw_keccak_lib.keccak_squeeze(self._state.get(),
|
| 156 |
+
bfr,
|
| 157 |
+
c_size_t(length),
|
| 158 |
+
c_ubyte(self._padding))
|
| 159 |
+
if result:
|
| 160 |
+
raise ValueError("Error %d while extracting from %s"
|
| 161 |
+
% (result, self.name))
|
| 162 |
+
|
| 163 |
+
return get_raw_buffer(bfr)
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
def _new(data, custom, function):
|
| 167 |
+
# Use Keccak[256]
|
| 168 |
+
return cSHAKE_XOF(data, custom, 256, function)
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
def new(data=None, custom=None):
|
| 172 |
+
"""Return a fresh instance of a cSHAKE128 object.
|
| 173 |
+
|
| 174 |
+
Args:
|
| 175 |
+
data (bytes/bytearray/memoryview):
|
| 176 |
+
Optional.
|
| 177 |
+
The very first chunk of the message to hash.
|
| 178 |
+
It is equivalent to an early call to :meth:`update`.
|
| 179 |
+
custom (bytes):
|
| 180 |
+
Optional.
|
| 181 |
+
A customization bytestring (``S`` in SP 800-185).
|
| 182 |
+
|
| 183 |
+
:Return: A :class:`cSHAKE_XOF` object
|
| 184 |
+
"""
|
| 185 |
+
|
| 186 |
+
# Use Keccak[256]
|
| 187 |
+
return cSHAKE_XOF(data, custom, 256, b'')
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/cSHAKE256.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ===================================================================
|
| 2 |
+
#
|
| 3 |
+
# Copyright (c) 2021, Legrandin <helderijs@gmail.com>
|
| 4 |
+
# All rights reserved.
|
| 5 |
+
#
|
| 6 |
+
# Redistribution and use in source and binary forms, with or without
|
| 7 |
+
# modification, are permitted provided that the following conditions
|
| 8 |
+
# are met:
|
| 9 |
+
#
|
| 10 |
+
# 1. Redistributions of source code must retain the above copyright
|
| 11 |
+
# notice, this list of conditions and the following disclaimer.
|
| 12 |
+
# 2. Redistributions in binary form must reproduce the above copyright
|
| 13 |
+
# notice, this list of conditions and the following disclaimer in
|
| 14 |
+
# the documentation and/or other materials provided with the
|
| 15 |
+
# distribution.
|
| 16 |
+
#
|
| 17 |
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 18 |
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 19 |
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
| 20 |
+
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
| 21 |
+
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
| 22 |
+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
| 23 |
+
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 24 |
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 25 |
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 26 |
+
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
| 27 |
+
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
| 28 |
+
# POSSIBILITY OF SUCH DAMAGE.
|
| 29 |
+
# ===================================================================
|
| 30 |
+
|
| 31 |
+
from Crypto.Util._raw_api import c_size_t
|
| 32 |
+
from Crypto.Hash.cSHAKE128 import cSHAKE_XOF
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def _new(data, custom, function):
|
| 36 |
+
# Use Keccak[512]
|
| 37 |
+
return cSHAKE_XOF(data, custom, 512, function)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def new(data=None, custom=None):
|
| 41 |
+
"""Return a fresh instance of a cSHAKE256 object.
|
| 42 |
+
|
| 43 |
+
Args:
|
| 44 |
+
data (bytes/bytearray/memoryview):
|
| 45 |
+
The very first chunk of the message to hash.
|
| 46 |
+
It is equivalent to an early call to :meth:`update`.
|
| 47 |
+
Optional.
|
| 48 |
+
custom (bytes):
|
| 49 |
+
Optional.
|
| 50 |
+
A customization bytestring (``S`` in SP 800-185).
|
| 51 |
+
|
| 52 |
+
:Return: A :class:`cSHAKE_XOF` object
|
| 53 |
+
"""
|
| 54 |
+
|
| 55 |
+
# Use Keccak[512]
|
| 56 |
+
return cSHAKE_XOF(data, custom, 512, b'')
|
minigpt2/lib/python3.10/site-packages/Crypto/Hash/keccak.py
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ===================================================================
|
| 2 |
+
#
|
| 3 |
+
# Copyright (c) 2015, Legrandin <helderijs@gmail.com>
|
| 4 |
+
# All rights reserved.
|
| 5 |
+
#
|
| 6 |
+
# Redistribution and use in source and binary forms, with or without
|
| 7 |
+
# modification, are permitted provided that the following conditions
|
| 8 |
+
# are met:
|
| 9 |
+
#
|
| 10 |
+
# 1. Redistributions of source code must retain the above copyright
|
| 11 |
+
# notice, this list of conditions and the following disclaimer.
|
| 12 |
+
# 2. Redistributions in binary form must reproduce the above copyright
|
| 13 |
+
# notice, this list of conditions and the following disclaimer in
|
| 14 |
+
# the documentation and/or other materials provided with the
|
| 15 |
+
# distribution.
|
| 16 |
+
#
|
| 17 |
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 18 |
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 19 |
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
| 20 |
+
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
| 21 |
+
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
| 22 |
+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
| 23 |
+
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 24 |
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 25 |
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 26 |
+
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
| 27 |
+
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
| 28 |
+
# POSSIBILITY OF SUCH DAMAGE.
|
| 29 |
+
# ===================================================================
|
| 30 |
+
|
| 31 |
+
from Crypto.Util.py3compat import bord
|
| 32 |
+
|
| 33 |
+
from Crypto.Util._raw_api import (load_pycryptodome_raw_lib,
|
| 34 |
+
VoidPointer, SmartPointer,
|
| 35 |
+
create_string_buffer,
|
| 36 |
+
get_raw_buffer, c_size_t,
|
| 37 |
+
c_uint8_ptr, c_ubyte)
|
| 38 |
+
|
| 39 |
+
_raw_keccak_lib = load_pycryptodome_raw_lib("Crypto.Hash._keccak",
|
| 40 |
+
"""
|
| 41 |
+
int keccak_init(void **state,
|
| 42 |
+
size_t capacity_bytes,
|
| 43 |
+
uint8_t rounds);
|
| 44 |
+
int keccak_destroy(void *state);
|
| 45 |
+
int keccak_absorb(void *state,
|
| 46 |
+
const uint8_t *in,
|
| 47 |
+
size_t len);
|
| 48 |
+
int keccak_squeeze(const void *state,
|
| 49 |
+
uint8_t *out,
|
| 50 |
+
size_t len,
|
| 51 |
+
uint8_t padding);
|
| 52 |
+
int keccak_digest(void *state,
|
| 53 |
+
uint8_t *digest,
|
| 54 |
+
size_t len,
|
| 55 |
+
uint8_t padding);
|
| 56 |
+
int keccak_copy(const void *src, void *dst);
|
| 57 |
+
int keccak_reset(void *state);
|
| 58 |
+
""")
|
| 59 |
+
|
| 60 |
+
class Keccak_Hash(object):
|
| 61 |
+
"""A Keccak hash object.
|
| 62 |
+
Do not instantiate directly.
|
| 63 |
+
Use the :func:`new` function.
|
| 64 |
+
|
| 65 |
+
:ivar digest_size: the size in bytes of the resulting hash
|
| 66 |
+
:vartype digest_size: integer
|
| 67 |
+
"""
|
| 68 |
+
|
| 69 |
+
def __init__(self, data, digest_bytes, update_after_digest):
|
| 70 |
+
# The size of the resulting hash in bytes.
|
| 71 |
+
self.digest_size = digest_bytes
|
| 72 |
+
|
| 73 |
+
self._update_after_digest = update_after_digest
|
| 74 |
+
self._digest_done = False
|
| 75 |
+
self._padding = 0x01
|
| 76 |
+
|
| 77 |
+
state = VoidPointer()
|
| 78 |
+
result = _raw_keccak_lib.keccak_init(state.address_of(),
|
| 79 |
+
c_size_t(self.digest_size * 2),
|
| 80 |
+
c_ubyte(24))
|
| 81 |
+
if result:
|
| 82 |
+
raise ValueError("Error %d while instantiating keccak" % result)
|
| 83 |
+
self._state = SmartPointer(state.get(),
|
| 84 |
+
_raw_keccak_lib.keccak_destroy)
|
| 85 |
+
if data:
|
| 86 |
+
self.update(data)
|
| 87 |
+
|
| 88 |
+
def update(self, data):
|
| 89 |
+
"""Continue hashing of a message by consuming the next chunk of data.
|
| 90 |
+
|
| 91 |
+
Args:
|
| 92 |
+
data (byte string/byte array/memoryview): The next chunk of the message being hashed.
|
| 93 |
+
"""
|
| 94 |
+
|
| 95 |
+
if self._digest_done and not self._update_after_digest:
|
| 96 |
+
raise TypeError("You can only call 'digest' or 'hexdigest' on this object")
|
| 97 |
+
|
| 98 |
+
result = _raw_keccak_lib.keccak_absorb(self._state.get(),
|
| 99 |
+
c_uint8_ptr(data),
|
| 100 |
+
c_size_t(len(data)))
|
| 101 |
+
if result:
|
| 102 |
+
raise ValueError("Error %d while updating keccak" % result)
|
| 103 |
+
return self
|
| 104 |
+
|
| 105 |
+
def digest(self):
|
| 106 |
+
"""Return the **binary** (non-printable) digest of the message that has been hashed so far.
|
| 107 |
+
|
| 108 |
+
:return: The hash digest, computed over the data processed so far.
|
| 109 |
+
Binary form.
|
| 110 |
+
:rtype: byte string
|
| 111 |
+
"""
|
| 112 |
+
|
| 113 |
+
self._digest_done = True
|
| 114 |
+
bfr = create_string_buffer(self.digest_size)
|
| 115 |
+
result = _raw_keccak_lib.keccak_digest(self._state.get(),
|
| 116 |
+
bfr,
|
| 117 |
+
c_size_t(self.digest_size),
|
| 118 |
+
c_ubyte(self._padding))
|
| 119 |
+
if result:
|
| 120 |
+
raise ValueError("Error %d while squeezing keccak" % result)
|
| 121 |
+
|
| 122 |
+
return get_raw_buffer(bfr)
|
| 123 |
+
|
| 124 |
+
def hexdigest(self):
|
| 125 |
+
"""Return the **printable** digest of the message that has been hashed so far.
|
| 126 |
+
|
| 127 |
+
:return: The hash digest, computed over the data processed so far.
|
| 128 |
+
Hexadecimal encoded.
|
| 129 |
+
:rtype: string
|
| 130 |
+
"""
|
| 131 |
+
|
| 132 |
+
return "".join(["%02x" % bord(x) for x in self.digest()])
|
| 133 |
+
|
| 134 |
+
def new(self, **kwargs):
|
| 135 |
+
"""Create a fresh Keccak hash object."""
|
| 136 |
+
|
| 137 |
+
if "digest_bytes" not in kwargs and "digest_bits" not in kwargs:
|
| 138 |
+
kwargs["digest_bytes"] = self.digest_size
|
| 139 |
+
|
| 140 |
+
return new(**kwargs)
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
def new(**kwargs):
|
| 144 |
+
"""Create a new hash object.
|
| 145 |
+
|
| 146 |
+
Args:
|
| 147 |
+
data (bytes/bytearray/memoryview):
|
| 148 |
+
The very first chunk of the message to hash.
|
| 149 |
+
It is equivalent to an early call to :meth:`Keccak_Hash.update`.
|
| 150 |
+
digest_bytes (integer):
|
| 151 |
+
The size of the digest, in bytes (28, 32, 48, 64).
|
| 152 |
+
digest_bits (integer):
|
| 153 |
+
The size of the digest, in bits (224, 256, 384, 512).
|
| 154 |
+
update_after_digest (boolean):
|
| 155 |
+
Whether :meth:`Keccak.digest` can be followed by another
|
| 156 |
+
:meth:`Keccak.update` (default: ``False``).
|
| 157 |
+
|
| 158 |
+
:Return: A :class:`Keccak_Hash` hash object
|
| 159 |
+
"""
|
| 160 |
+
|
| 161 |
+
data = kwargs.pop("data", None)
|
| 162 |
+
update_after_digest = kwargs.pop("update_after_digest", False)
|
| 163 |
+
|
| 164 |
+
digest_bytes = kwargs.pop("digest_bytes", None)
|
| 165 |
+
digest_bits = kwargs.pop("digest_bits", None)
|
| 166 |
+
if None not in (digest_bytes, digest_bits):
|
| 167 |
+
raise TypeError("Only one digest parameter must be provided")
|
| 168 |
+
if (None, None) == (digest_bytes, digest_bits):
|
| 169 |
+
raise TypeError("Digest size (bits, bytes) not provided")
|
| 170 |
+
if digest_bytes is not None:
|
| 171 |
+
if digest_bytes not in (28, 32, 48, 64):
|
| 172 |
+
raise ValueError("'digest_bytes' must be: 28, 32, 48 or 64")
|
| 173 |
+
else:
|
| 174 |
+
if digest_bits not in (224, 256, 384, 512):
|
| 175 |
+
raise ValueError("'digest_bytes' must be: 224, 256, 384 or 512")
|
| 176 |
+
digest_bytes = digest_bits // 8
|
| 177 |
+
|
| 178 |
+
if kwargs:
|
| 179 |
+
raise TypeError("Unknown parameters: " + str(kwargs))
|
| 180 |
+
|
| 181 |
+
return Keccak_Hash(data, digest_bytes, update_after_digest)
|
minigpt2/lib/python3.10/site-packages/markdown_it/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (290 Bytes). View file
|
|
|
minigpt2/lib/python3.10/site-packages/markdown_it/__pycache__/_punycode.cpython-310.pyc
ADDED
|
Binary file (1.74 kB). View file
|
|
|
minigpt2/lib/python3.10/site-packages/markdown_it/__pycache__/main.cpython-310.pyc
ADDED
|
Binary file (12.8 kB). View file
|
|
|
minigpt2/lib/python3.10/site-packages/markdown_it/__pycache__/renderer.cpython-310.pyc
ADDED
|
Binary file (7.72 kB). View file
|
|
|
minigpt2/lib/python3.10/site-packages/markdown_it/__pycache__/utils.cpython-310.pyc
ADDED
|
Binary file (5.86 kB). View file
|
|
|
minigpt2/lib/python3.10/site-packages/markdown_it/helpers/__init__.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Functions for parsing Links
|
| 2 |
+
"""
|
| 3 |
+
__all__ = ("parseLinkLabel", "parseLinkDestination", "parseLinkTitle")
|
| 4 |
+
from .parse_link_destination import parseLinkDestination
|
| 5 |
+
from .parse_link_label import parseLinkLabel
|
| 6 |
+
from .parse_link_title import parseLinkTitle
|
minigpt2/lib/python3.10/site-packages/markdown_it/helpers/__pycache__/parse_link_label.cpython-310.pyc
ADDED
|
Binary file (899 Bytes). View file
|
|
|
minigpt2/lib/python3.10/site-packages/markdown_it/helpers/parse_link_destination.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Parse link destination
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from ..common.utils import charCodeAt, unescapeAll
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class _Result:
|
| 9 |
+
__slots__ = ("ok", "pos", "lines", "str")
|
| 10 |
+
|
| 11 |
+
def __init__(self) -> None:
|
| 12 |
+
self.ok = False
|
| 13 |
+
self.pos = 0
|
| 14 |
+
self.lines = 0
|
| 15 |
+
self.str = ""
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def parseLinkDestination(string: str, pos: int, maximum: int) -> _Result:
|
| 19 |
+
lines = 0
|
| 20 |
+
start = pos
|
| 21 |
+
result = _Result()
|
| 22 |
+
|
| 23 |
+
if charCodeAt(string, pos) == 0x3C: # /* < */
|
| 24 |
+
pos += 1
|
| 25 |
+
while pos < maximum:
|
| 26 |
+
code = charCodeAt(string, pos)
|
| 27 |
+
if code == 0x0A: # /* \n */)
|
| 28 |
+
return result
|
| 29 |
+
if code == 0x3C: # / * < * /
|
| 30 |
+
return result
|
| 31 |
+
if code == 0x3E: # /* > */) {
|
| 32 |
+
result.pos = pos + 1
|
| 33 |
+
result.str = unescapeAll(string[start + 1 : pos])
|
| 34 |
+
result.ok = True
|
| 35 |
+
return result
|
| 36 |
+
|
| 37 |
+
if code == 0x5C and pos + 1 < maximum: # \
|
| 38 |
+
pos += 2
|
| 39 |
+
continue
|
| 40 |
+
|
| 41 |
+
pos += 1
|
| 42 |
+
|
| 43 |
+
# no closing '>'
|
| 44 |
+
return result
|
| 45 |
+
|
| 46 |
+
# this should be ... } else { ... branch
|
| 47 |
+
|
| 48 |
+
level = 0
|
| 49 |
+
while pos < maximum:
|
| 50 |
+
code = charCodeAt(string, pos)
|
| 51 |
+
|
| 52 |
+
if code is None or code == 0x20:
|
| 53 |
+
break
|
| 54 |
+
|
| 55 |
+
# ascii control characters
|
| 56 |
+
if code < 0x20 or code == 0x7F:
|
| 57 |
+
break
|
| 58 |
+
|
| 59 |
+
if code == 0x5C and pos + 1 < maximum:
|
| 60 |
+
if charCodeAt(string, pos + 1) == 0x20:
|
| 61 |
+
break
|
| 62 |
+
pos += 2
|
| 63 |
+
continue
|
| 64 |
+
|
| 65 |
+
if code == 0x28: # /* ( */)
|
| 66 |
+
level += 1
|
| 67 |
+
if level > 32:
|
| 68 |
+
return result
|
| 69 |
+
|
| 70 |
+
if code == 0x29: # /* ) */)
|
| 71 |
+
if level == 0:
|
| 72 |
+
break
|
| 73 |
+
level -= 1
|
| 74 |
+
|
| 75 |
+
pos += 1
|
| 76 |
+
|
| 77 |
+
if start == pos:
|
| 78 |
+
return result
|
| 79 |
+
if level != 0:
|
| 80 |
+
return result
|
| 81 |
+
|
| 82 |
+
result.str = unescapeAll(string[start:pos])
|
| 83 |
+
result.lines = lines
|
| 84 |
+
result.pos = pos
|
| 85 |
+
result.ok = True
|
| 86 |
+
return result
|
minigpt2/lib/python3.10/site-packages/markdown_it/helpers/parse_link_label.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Parse link label
|
| 3 |
+
|
| 4 |
+
this function assumes that first character ("[") already matches
|
| 5 |
+
returns the end of the label
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
from markdown_it.rules_inline import StateInline
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def parseLinkLabel(state: StateInline, start: int, disableNested: bool = False) -> int:
|
| 12 |
+
labelEnd = -1
|
| 13 |
+
oldPos = state.pos
|
| 14 |
+
found = False
|
| 15 |
+
|
| 16 |
+
state.pos = start + 1
|
| 17 |
+
level = 1
|
| 18 |
+
|
| 19 |
+
while state.pos < state.posMax:
|
| 20 |
+
marker = state.src[state.pos]
|
| 21 |
+
if marker == "]":
|
| 22 |
+
level -= 1
|
| 23 |
+
if level == 0:
|
| 24 |
+
found = True
|
| 25 |
+
break
|
| 26 |
+
|
| 27 |
+
prevPos = state.pos
|
| 28 |
+
state.md.inline.skipToken(state)
|
| 29 |
+
if marker == "[":
|
| 30 |
+
if prevPos == state.pos - 1:
|
| 31 |
+
# increase level if we find text `[`,
|
| 32 |
+
# which is not a part of any token
|
| 33 |
+
level += 1
|
| 34 |
+
elif disableNested:
|
| 35 |
+
state.pos = oldPos
|
| 36 |
+
return -1
|
| 37 |
+
if found:
|
| 38 |
+
labelEnd = state.pos
|
| 39 |
+
|
| 40 |
+
# restore old state
|
| 41 |
+
state.pos = oldPos
|
| 42 |
+
|
| 43 |
+
return labelEnd
|
minigpt2/lib/python3.10/site-packages/markdown_it/helpers/parse_link_title.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Parse link title
|
| 2 |
+
"""
|
| 3 |
+
from ..common.utils import charCodeAt, unescapeAll
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class _Result:
|
| 7 |
+
__slots__ = ("ok", "pos", "lines", "str")
|
| 8 |
+
|
| 9 |
+
def __init__(self) -> None:
|
| 10 |
+
self.ok = False
|
| 11 |
+
self.pos = 0
|
| 12 |
+
self.lines = 0
|
| 13 |
+
self.str = ""
|
| 14 |
+
|
| 15 |
+
def __str__(self) -> str:
|
| 16 |
+
return self.str
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def parseLinkTitle(string: str, pos: int, maximum: int) -> _Result:
|
| 20 |
+
lines = 0
|
| 21 |
+
start = pos
|
| 22 |
+
result = _Result()
|
| 23 |
+
|
| 24 |
+
if pos >= maximum:
|
| 25 |
+
return result
|
| 26 |
+
|
| 27 |
+
marker = charCodeAt(string, pos)
|
| 28 |
+
|
| 29 |
+
# /* " */ /* ' */ /* ( */
|
| 30 |
+
if marker != 0x22 and marker != 0x27 and marker != 0x28:
|
| 31 |
+
return result
|
| 32 |
+
|
| 33 |
+
pos += 1
|
| 34 |
+
|
| 35 |
+
# if opening marker is "(", switch it to closing marker ")"
|
| 36 |
+
if marker == 0x28:
|
| 37 |
+
marker = 0x29
|
| 38 |
+
|
| 39 |
+
while pos < maximum:
|
| 40 |
+
code = charCodeAt(string, pos)
|
| 41 |
+
if code == marker:
|
| 42 |
+
title = string[start + 1 : pos]
|
| 43 |
+
title = unescapeAll(title)
|
| 44 |
+
result.pos = pos + 1
|
| 45 |
+
result.lines = lines
|
| 46 |
+
result.str = title
|
| 47 |
+
result.ok = True
|
| 48 |
+
return result
|
| 49 |
+
elif code == 0x28 and marker == 0x29: # /* ( */ /* ) */
|
| 50 |
+
return result
|
| 51 |
+
elif code == 0x0A:
|
| 52 |
+
lines += 1
|
| 53 |
+
elif code == 0x5C and pos + 1 < maximum: # /* \ */
|
| 54 |
+
pos += 1
|
| 55 |
+
if charCodeAt(string, pos) == 0x0A:
|
| 56 |
+
lines += 1
|
| 57 |
+
|
| 58 |
+
pos += 1
|
| 59 |
+
|
| 60 |
+
return result
|
minigpt2/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/.hash/_cparser.pxd.hash
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
f2318883e549f69de597009a914603b0f1b10381e265ef5d98af499ad973fb98 /home/runner/work/aiohttp/aiohttp/aiohttp/_cparser.pxd
|
minigpt2/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/.hash/hdrs.py.hash
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
dab8f933203eeb245d60f856e542a45b888d5a110094620e4811f90f816628d1 /home/runner/work/aiohttp/aiohttp/aiohttp/hdrs.py
|
minigpt2/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/__pycache__/abc.cpython-310.pyc
ADDED
|
Binary file (9.66 kB). View file
|
|
|
minigpt2/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/__pycache__/client_ws.cpython-310.pyc
ADDED
|
Binary file (12.5 kB). View file
|
|
|
minigpt2/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/__pycache__/hdrs.cpython-310.pyc
ADDED
|
Binary file (5.51 kB). View file
|
|
|
minigpt2/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/__pycache__/http.cpython-310.pyc
ADDED
|
Binary file (1.5 kB). View file
|
|
|
minigpt2/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/__pycache__/pytest_plugin.cpython-310.pyc
ADDED
|
Binary file (11.5 kB). View file
|
|
|
minigpt2/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/__pycache__/resolver.cpython-310.pyc
ADDED
|
Binary file (4.49 kB). View file
|
|
|
minigpt2/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/__pycache__/web_log.cpython-310.pyc
ADDED
|
Binary file (7.58 kB). View file
|
|
|
minigpt2/lib/python3.10/site-packages/ray/_private/runtime_env/agent/thirdparty_files/aiohttp/__pycache__/web_ws.cpython-310.pyc
ADDED
|
Binary file (17.4 kB). View file
|
|
|