mini_cryptography package
Submodules
mini_cryptography.ecdsa module
ECDSA file info. The following script allows users to perform ECC (Elliptic Curve Cryptography) arithmetic operations, including ECDSA (Elliptic Curve Digital Signature Algorithm) signature formation and verification.
Pre-requisite : tiny.ec package to be installed within the Python runtime environment
- class mini_cryptography.ecdsa.Ecdsa(field: Field, name: str)[source]
Bases:
object
A class used to do ECC arithmetic operations and ECDSA (Elliptic Curve Digital Signature Algorithm) signature formation and verification
- G_multiplication(multiplyer: int)[source]
Multiplies G point from the given multiplier
- Args:
multiplyer (int): Given point multipliers
- Returns:
Point: A new point after multiplication
- calculate_public_key(private_key: int)[source]
Calculate the public key
- Args:
private_key (int): private key value
- Returns:
Point: A public key
- generate_random_number(lower: int, upper: int)[source]
Generates random number [lower, … upper range]
- Args:
lower (int): lower is the lower limit of the range upper (int): upper is the upper limit of the range
- Returns:
int: generated number
- multiply_points(point: Point, multiplyer: int)[source]
Point multiplication from a given multiplier
- Args:
point (Point): Curve point multiplyer (int): Given point multiplier
- Returns:
Point: A new point after multiplication
- sign_message(private_key: int, k: int, hash: str)[source]
Create a signature for the given message.
- Args:
private_key (int): private key value k (int): random number k hash (str): message hash value
- Returns:
int, int: e. signature component values r, s bool: 0 if wrong r or 1 if wrong s
mini_cryptography.merkle module
Merkle file info. The following script allows users to calculate the Merkle tree root using different hash algorithm functions.
- class mini_cryptography.merkle.Merkle(sha: SHA = SHA.SHA256, shake_length: int = 100)[source]
Bases:
object
A class that is used to calculate the Merkle tree root
- class SHA(value)[source]
Bases:
Enum
An enumerator that is used to represent possible hash algorithms
- Args:
Enum (constant): Hash algorithm
- SHA1 = 1
- SHA224 = 2
- SHA256 = 3
- SHA3_224 = 4
- SHA3_256 = 5
- SHA3_384 = 6
- SHA3_512 = 7
- SHA512 = 8
- SHAKE_128 = 9
- SHAKE_256 = 10
- calculate_hash(value: str)[source]
Calculates the hash value from the given text.
- Args:
value (str): text
- Returns:
str: hash value
- merkle_root(transactionList: list[str], hashTransaction: bool = 1)[source]
Calculates the Merkle root of transactions.
- Args:
transactionList (list[str]): transaction list. hashTransaction (bool, optional): is transactions hashed. Defaults to 1 (hashed).
- Returns:
str: Merkle root value in hexadecimal format