### skeinsum usage example Source: https://pythonhosted.org/pyskein/_sources/scripts.txt Command-line usage of the skeinsum script, which hashes files with Skein-512-256 and prints the hexdigest followed by the filename. ```shell $ skeinsum COPYING 63fb45390c188b7ba0e8eb2ed0e2fefa8416da515f0b28e670345ecd0de673dc COPYING ``` -------------------------------- ### Using skein.Random PRNG with different seeds and reading bytes/bits Source: https://pythonhosted.org/pyskein/_sources/random.txt Shows how to create a skein.Random instance with a bytes seed, a hashable seed, no seed, and how to read raw bytes or bits. The output values are examples and will vary with the seed and system randomness. ```python >>> import skein >>> r = skein.Random(b"some seed value") >>> r.random() 0.12674259115116804 ``` ```python >>> skein.Random(12345).random() 0.1976938882004089 ``` ```python >>> r = skein.Random() >>> r.random() 0.9696830103216001 ``` ```python >>> r = skein.Random(b"seed") >>> r.read(5) b'\xfe\xe6j\x8d\xb6' >>> r.getrandbits(4) 9 ``` -------------------------------- ### threefish encrypt and decrypt usage example Source: https://pythonhosted.org/pyskein/_sources/scripts.txt Command-line usage of the threefish script for file encryption and decryption. The script prompts for a password, derives a 256-bit key via Skein-512-256, and uses a tweak block chaining variant with a 32-byte block size. Decryption always succeeds even with a wrong key, producing garbage. ```shell $ threefish encrypt README Password: $ ls README* README README.3f $ mv README README.orig $ threefish decrypt README.3f Password: $ diff README README.orig $ ``` -------------------------------- ### hash.digest([start, stop]) Source: https://pythonhosted.org/pyskein/skein.html Returns the digest of all data processed so far. Optionally accepts start and stop indices to return a slice of the digest efficiently. ```APIDOC ## hash.digest([start, stop]) ### Description Returns the digest of all data processed so far. If start and stop are omitted, returns a bytes object of length digest_size. If specified, returns the same as digest()[start:stop] but computed more efficiently for small slices of large digests. ### Parameters - **start** (int) - Optional - Starting index of the digest slice. - **stop** (int) - Optional - Ending index of the digest slice. ### Returns - **bytes** - The digest (or slice thereof). ``` -------------------------------- ### Encrypt and decrypt with skein.StreamCipher Source: https://pythonhosted.org/pyskein/stream.html Create a StreamCipher with a secret key, encrypt a message, and decrypt it back. The example shows that the ciphertext is a bytes object and that decrypting with a new StreamCipher using the same key recovers the original plaintext. ```python >>> import skein >>> sc = skein.StreamCipher(b"secret") >>> x = sc.encrypt(b"squeamish ossifrage") >>> x b'\x94!\xc5\xbfM\xb5%{\x96qPw\x7f\x16]\xf3\x1cEc' >>> sc = skein.StreamCipher(b"secret") >>> sc.decrypt(x) b'squeamish ossifrage' ``` -------------------------------- ### Create a Skein-512 hash object Source: https://pythonhosted.org/pyskein/skein.html Demonstrates initializing a Skein-512 hash object, updating it with data, and retrieving the digest and metadata. ```python >>> from skein import skein256, skein512, skein1024 >>> h = skein512() >>> h.update(b'Nobody inspects') >>> h.update(b' the spammish repetition') >>> h.digest() b'\x1bN\x03+\xcb\x1d\xa4Rs\x01\x1c\xa9Ee\xef\x10|f+\x0b\xd3\r[5\xfbS5Ko\xced#\xa5\xeb\x10\xda\xe6\xf3v\xd6\xb2JNQ}\x85\xc7&\xfc\x01\xfb\x87J\x8f\xe2m\xe9Y\x1f\xa5\x9f\xa3\xc7\xd4' >>> h.digest_size, h.digest_bits (64, 512) >>> h.block_size, h.block_bits (64, 512) >>> h.hashed_bits 312 ``` -------------------------------- ### Initialize skein.Random with bytes seed Source: https://pythonhosted.org/pyskein/random.html Demonstrates initializing the PRNG with a bytes object seed. ```python >>> import skein >>> r = skein.Random(b"some seed value") >>> r.random() 0.12674259115116804 ``` -------------------------------- ### Initialize skein.Random with hashable object Source: https://pythonhosted.org/pyskein/random.html Demonstrates initializing the PRNG with a hashable object, which is internally converted to a bytes seed. ```python >>> skein.Random(12345).random() 0.1976938882004089 ``` -------------------------------- ### Perform tree hashing with skein256 Source: https://pythonhosted.org/pyskein/skein.html Demonstrates initializing a skein256 hash object with tree parameters (L, F, M) and updating it with data. ```python >>> h = skein256(tree=(5, 2, 255)) >>> for _ in range(1000): ... h.update(b'\0' * 10**6) ... >>> h.update(b'foobar') >>> h.hexdigest() '3d5bea7b8e2ffdaef60ce9d68b1db7cb4549a6bb52b3801eda640623cbeca5bd' ``` -------------------------------- ### Initialize skein.Random without seed Source: https://pythonhosted.org/pyskein/random.html Demonstrates initializing the PRNG without a seed, causing it to derive the initial state from a system source of randomness. ```python >>> r = skein.Random() >>> r.random() 0.9696830103216001 ``` -------------------------------- ### Encrypt and Decrypt a 32-byte Block Source: https://pythonhosted.org/pyskein/_sources/threefish.txt Demonstrates initializing a Threefish cipher object and performing basic encryption and decryption on a 32-byte block. ```python >>> from skein import threefish >>> t = threefish(b'key of 32,64 or 128 bytes length', b'tweak: 16 bytes ') >>> t.block_size, t.block_bits (32, 256) >>> c = t.encrypt_block(b'block of data,same length as key') >>> c b'\x1c\xbf\x83\xbeoW\xd8\xe0f\xba\xb2\xea\x0e\x91\x0b\n\x06,\xd5:\x97\x9a\x11IaEGM\xc0\xe8\x9e\x86' >>> t.decrypt_block(c) b'block of data,same length as key' ``` -------------------------------- ### Create a Skein-1024-384 hash object Source: https://pythonhosted.org/pyskein/skein.html Demonstrates initializing a Skein-1024 hash object with a specific digest bit length. ```python >>> h = skein1024(b'Nobody inspects the spammish repetition', digest_bits=384) >>> h.hexdigest() 'b602b02c5e02ecb37361b17dd4da33bb41c49ff685dca0408048a425fe3dee8bfbaf6c42575e9d71d89eb0dd2ec2a2a8' >>> h.digest_size, h.digest_bits (48, 384) >>> h.block_size, h.block_bits (128, 1024) >>> h.hashed_bits 312 ``` -------------------------------- ### Use Skein as a key derivation function (KDF) Source: https://pythonhosted.org/pyskein/skein.html Uses Skein-256 as a KDF by specifying a master key and a key identifier. ```python >>> skein256(key=b'mastersecret', key_id=b'email', digest_bits=128).hexdigest() 'c3ad501b1abfcf25bd1bdc4ef4053348' ``` -------------------------------- ### skein.skein256(init=b'', digest_bits=256, **params) Source: https://pythonhosted.org/pyskein/skein.html Creates a new Skein-256 hash object. Optionally accepts an initial data chunk, desired digest length in bits, and keyword-only parameters for key, personalization, public key, key ID, nonce, and tree hashing. ```APIDOC ## skein.skein256(init=b'', digest_bits=256, **params) ### Description Creates a new Skein-256 hash object with 256-bit internal state. Optionally takes an initial chunk of data and the desired digest length in bits. ### Parameters - **init** (bytes) - Optional - Initial chunk of data to hash. - **digest_bits** (int) - Optional - Desired digest length in bits, must be < 2**31. - **key** (bytes) - Optional - Private key. - **pers** (bytes) - Optional - Personalization string. - **public_key** (bytes) - Optional - Public key. - **key_id** (bytes) - Optional - Key identifier. - **nonce** (bytes) - Optional - Nonce value. - **tree** (tuple) - Optional - Tree hashing parameters: (leaf, fan_out, max_height). ### Returns A Skein-256 hash object. ``` -------------------------------- ### Use a personalization string Source: https://pythonhosted.org/pyskein/skein.html Specifies a personalization string for personalized hashing using Skein-256. ```python >>> skein256(b'message', pers=b'20100101 me@example.com').hexdigest() '00c4f6aa109902e8db81d4c9324d2980265adcda583090aa894447511ca5f773' ``` -------------------------------- ### Read bytes and bits from skein.Random Source: https://pythonhosted.org/pyskein/random.html Demonstrates reading raw bytes and bits directly from the random stream. ```python >>> r = skein.Random(b"seed") >>> r.read(5) b'\xfe\xe6j\x8d\xb6' >>> r.getrandbits(4) 9 ``` -------------------------------- ### Use a nonce for randomized hashing Source: https://pythonhosted.org/pyskein/skein.html Specifies a nonce for randomized hashing using Skein-256. ```python >>> skein256(b'message', nonce=b'foobar').hexdigest() 'e01f8f8d57521f28d08390be94da96390177eff11932eaa59e2976686ac4a280' ``` -------------------------------- ### hash.copy() Source: https://pythonhosted.org/pyskein/skein.html Returns a clone of the hash object, useful for efficiently computing hashes of data sharing a common prefix. ```APIDOC ## hash.copy() ### Description Returns a clone of the hash object, e.g., to efficiently compute hashes of data sharing a common prefix. ### Returns - **hash object** - A copy of the current hash object. ``` -------------------------------- ### Generate a message authentication code (MAC) Source: https://pythonhosted.org/pyskein/skein.html Uses the key parameter to generate a MAC with Skein-256. ```python >>> skein256(b'message', key=b'secret').hexdigest() 'aee7b931f0e5e134b7af4ac1a7958f5c5f5f7e20dd68cfeab474c0aae0290de7' ``` -------------------------------- ### skein.skein1024(init=b'', digest_bits=1024, **params) Source: https://pythonhosted.org/pyskein/skein.html Creates a new Skein-1024 hash object with 1024-bit internal state. Accepts the same optional parameters as skein256. ```APIDOC ## skein.skein1024(init=b'', digest_bits=1024, **params) ### Description Creates a new Skein-1024 hash object with 1024-bit internal state. Optionally takes an initial chunk of data and the desired digest length in bits. ### Parameters - **init** (bytes) - Optional - Initial chunk of data to hash. - **digest_bits** (int) - Optional - Desired digest length in bits, must be < 2**31. - **key** (bytes) - Optional - Private key. - **pers** (bytes) - Optional - Personalization string. - **public_key** (bytes) - Optional - Public key. - **key_id** (bytes) - Optional - Key identifier. - **nonce** (bytes) - Optional - Nonce value. - **tree** (tuple) - Optional - Tree hashing parameters: (leaf, fan_out, max_height). ### Returns A Skein-1024 hash object. ``` -------------------------------- ### skein.skein512(init=b'', digest_bits=512, **params) Source: https://pythonhosted.org/pyskein/skein.html Creates a new Skein-512 hash object with 512-bit internal state. Accepts the same optional parameters as skein256. ```APIDOC ## skein.skein512(init=b'', digest_bits=512, **params) ### Description Creates a new Skein-512 hash object with 512-bit internal state. Optionally takes an initial chunk of data and the desired digest length in bits. ### Parameters - **init** (bytes) - Optional - Initial chunk of data to hash. - **digest_bits** (int) - Optional - Desired digest length in bits, must be < 2**31. - **key** (bytes) - Optional - Private key. - **pers** (bytes) - Optional - Personalization string. - **public_key** (bytes) - Optional - Public key. - **key_id** (bytes) - Optional - Key identifier. - **nonce** (bytes) - Optional - Nonce value. - **tree** (tuple) - Optional - Tree hashing parameters: (leaf, fan_out, max_height). ### Returns A Skein-512 hash object. ``` -------------------------------- ### hash.name Source: https://pythonhosted.org/pyskein/_sources/skein.txt Attribute that returns the name of the algorithm, e.g., 'Skein-256', 'Skein-512', or 'Skein-1024'. ```APIDOC ## hash.name ### Description Attribute that returns the name of the algorithm, e.g., 'Skein-256', 'Skein-512', or 'Skein-1024'. ### Type str ### Example ```python print(h.name) ``` ``` -------------------------------- ### Threefish Block Cipher API Source: https://pythonhosted.org/pyskein/_sources/threefish.txt Documentation for the Threefish block cipher API, including the constructor function, encryption/decryption methods, and attributes. ```APIDOC ## skein.threefish(key, tweak) ### Description This constructor function returns a cipher object for encryption and decryption with the given key and tweak values. ### Parameters - **key** (bytes) - Required - The key must be a bytes object of length 32, 64, or 128. - **tweak** (bytes) - Required - The tweak must always consist of 16 bytes. ### Returns A Threefish cipher object. ## threefish.encrypt_block(data) ### Description Encrypt the given block of (bytes) data. The block has to have the same length as the key, i.e. 32, 64, or 128 bytes. ### Parameters - **data** (bytes) - Required - The block of data to encrypt. Must be the same length as the key. ### Returns The encrypted block as bytes. ## threefish.decrypt_block(data) ### Description Decrypt the given block of (bytes) data. The block has to have the same length as the key, i.e. 32, 64, or 128 bytes. ### Parameters - **data** (bytes) - Required - The block of data to decrypt. Must be the same length as the key. ### Returns The decrypted block as bytes. ## threefish.tweak ### Description This attribute is writable, allowing the tweak to be changed without creation of a new cipher object. ### Type bytes ## threefish.block_bits ### Description Threefish block size (as determined by the key length) in bits, i.e. 256, 512, or 1024. ### Type int ## threefish.block_size ### Description Threefish block size in bytes (same as the key length), i.e. 32, 64, or 128. ### Type int ``` -------------------------------- ### Hash a public key for digital signatures Source: https://pythonhosted.org/pyskein/skein.html Hashes a public key into the digest for digital signature applications using Skein-256. ```python >>> skein256(b'message', public_key=b'mypubkey').hexdigest() '81a3a49606da1acf1a1ab3324e7ca170f310d905f8fabcff096d4ddf12aeef10' ``` -------------------------------- ### hash.update(message, bits=None) Source: https://pythonhosted.org/pyskein/skein.html Hashes the given message into the internal state. Repeated calls are equivalent to a single call with concatenated arguments. Optionally specifies the number of bits to hash. ```APIDOC ## hash.update(message, bits=None) ### Description Hashes the given message (bytes) into the internal state. Repeated calls are equivalent to a single call with the concatenation of all arguments. If bits is given, it must be <= 8*len(message) and specifies how many bits of the message are hashed. ### Parameters - **message** (bytes) - Required - The message to hash. - **bits** (int) - Optional - Number of bits to hash. Defaults to 8*len(message). Must be <= 8*len(message). If the number of hashed bits so far is not a multiple of 8, bits must be at most 8 - hashed_bits % 8, otherwise a ValueError is raised. ### Raises - **ValueError** - If bits is invalid or causes improper byte alignment. ``` -------------------------------- ### hash.hexdigest() Source: https://pythonhosted.org/pyskein/skein.html Returns the digest as a string of hexadecimal digits. ```APIDOC ## hash.hexdigest() ### Description Returns the digest as a string of hexadecimal digits. ### Returns - **str** - Hexadecimal digest string. ``` -------------------------------- ### Modify Cipher Tweak Source: https://pythonhosted.org/pyskein/_sources/threefish.txt Shows how to update the tweak attribute of an existing Threefish object, which results in different ciphertext for the same input data. ```python >>> t.tweak = b'some other tweak' >>> c = t.encrypt_block(b'block of data,same length as key') >>> c b'3gE(9X|_\xab\x87\xe5\xc7\xcc\xa6m\xc4e\x06\xcb\xdbBg\xf2\xe6A\xb9\x86o\xecW\xe6\xfd' >>> t.decrypt_block(c) b'block of data,same length as key' ``` -------------------------------- ### Hash object attributes Source: https://pythonhosted.org/pyskein/skein.html Attributes available on each hash object: name, block_bits, block_size, digest_bits, digest_size, and hashed_bits. ```APIDOC ## Hash object attributes ### Description Each hash object has the following attributes: - **name** (str) - Name of the algorithm: 'Skein-256', 'Skein-512', or 'Skein-1024'. - **block_bits** (int) - Internal state size in bits: 256, 512, or 1024. - **block_size** (int) - Internal state size in bytes: 32, 64, or 128. - **digest_bits** (int) - Output digest length in bits (value given to constructor or default). - **digest_size** (int) - Digest size in bytes (rounded up). - **hashed_bits** (int) - Number of message bits hashed so far. ``` -------------------------------- ### hash.digest_bits Source: https://pythonhosted.org/pyskein/_sources/skein.txt Attribute that returns the output digest length in bits, as given to the constructor or default. ```APIDOC ## hash.digest_bits ### Description Attribute that returns the output digest length in bits, as given to the constructor or default. ### Type int ### Example ```python print(h.digest_bits) ``` ``` -------------------------------- ### hash.block_size Source: https://pythonhosted.org/pyskein/_sources/skein.txt Attribute that returns the internal state size in bytes (32, 64, or 128), conforming to hashlib. ```APIDOC ## hash.block_size ### Description Attribute that returns the internal state size in bytes (32, 64, or 128), conforming to hashlib. ### Type int ### Example ```python print(h.block_size) ``` ``` -------------------------------- ### hash.block_bits Source: https://pythonhosted.org/pyskein/_sources/skein.txt Attribute that returns the internal state size in bits (256, 512, or 1024). ```APIDOC ## hash.block_bits ### Description Attribute that returns the internal state size in bits (256, 512, or 1024). ### Type int ### Example ```python print(h.block_bits) ``` ``` -------------------------------- ### hash.digest_size Source: https://pythonhosted.org/pyskein/_sources/skein.txt Attribute that returns the digest size in bytes (rounded up). ```APIDOC ## hash.digest_size ### Description Attribute that returns the digest size in bytes (rounded up). ### Type int ### Example ```python print(h.digest_size) ``` ``` -------------------------------- ### hash.hashed_bits Source: https://pythonhosted.org/pyskein/_sources/skein.txt Attribute that returns the number of message bits hashed so far. ```APIDOC ## hash.hashed_bits ### Description Attribute that returns the number of message bits hashed so far. ### Type int ### Example ```python print(h.hashed_bits) ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.