Skip to main content

Elliptic Cryptography and ECDSA

Project description

foss_cryptography

foss_cryptography is a Python free open source library for Elliptic Curves Cryptography under the MIT License.

The library provides:

  1. the basic operations for the generic elliptic curve points: addition, doubling and scalar multiplication
  2. the ECDSA (Elliptic Curve Digital Signature Algorithm) for non-deterministic and deterministic message signing and signature verification
  3. a library of parameters of some standard elliptic curves (NIST, etc.)

The main functions of this library are self-contained, and the library doesn't require any external dependencies to perform its core operations.

Features

  • Elliptic Curve Operations: The library includes a module ellipticCurves.py that provides essential operations on elliptic curves, such as point doubling, point addition, and scalar multiplication.

  • ECDSA Implementation: The ecdsa.py module implements the ECDSA algorithm with non-deterministic and deterministic generation of k (RFC6979), allowing users to sign and verify messages using a provided library of standard elliptic curves.

Installation

From PyPI:

Install the library

pip install foss-cryptography

From GitHub:

Clone the library from GitHub

git clone https://github.com/stefanogaspari/foss_cryptography.git

Install the library dependencies

pip install -r requirements.txt

Build the library

python setup.py bdist_wheel

Install the library

pip install /path/to/wheelfile.whl

Usage

Elliptic Curves

from cryptography.ellipticCurves import EllipticCurve
from cyptography.secp256k1 import p, a, b

# Initialize an elliptic curve
curve = EllipticCurve(p, a, b)

# Point initialization
P = [x1, y1] # x1 and y1: type int
Q = [x2, y2] # x2 and y2: type int

# Point doubling R = 2 * P
R = curve.double(P)

# Point addition, R = P + Q
R = curve.add(P, Q)

# Scalar multiplication, R = n * P
R = curve.scalar_multiply(n, P)

non-deterministic ECDSA

from cryptography.ecdsa import ECDSA
from cyptography.curves.secp256k1 import p, a, b, origin_G, n

# Define the hash function
hash_function = 'sha256'

# Initialize ECDSA secp256k1 instance
ecdsa = ECDSA(m, a, b, origin_G, n, hash_function)

# Sign a message with a secure random k
# k: int
# message: bytes
# private_key: bytes
# signature: Tuple(bytes, bytes) -> r , s
signature = ecdsa.non_deterministic_sign(k, message, private_key)

# Verify a message
# signature: bytes -> r || s
# message: bytes
# public_key: bytes -> public_key_x || public_key_y
# is_verified: bool
is_verified = ecdsa.verify(signature, message, public_key)

deterministic ECDSA

from cryptography.ecdsa import ECDSA
from cyptography.curves.secp256k1 import p, a, b, origin_G, n

# Define the hash function
hash_function = 'sha256'

# Initialize ECDSA secp256k1 instance
ecdsa = ECDSA(m, a, b, origin_G, n)

# Sign a message with a deterministic k (as per RFC6979)
# message: bytes
# private_key: bytes
# signature: Tuple(bytes, bytes) -> r , s
signature = ecdsa.deterministic_sign(message, private_key)

# Verify a message
# signature: bytes -> r || s
# message: bytes
# public_key: bytes -> public_key_x || public_key_y
# is_verified: bool
is_verified = ecdsa.verify(signature, message, public_key)

License

This project is under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

foss_cryptography-2.0.3-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file foss_cryptography-2.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for foss_cryptography-2.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 db14721d9feffab724d73d42651d31efb6191c8f8f7c7c67882d22d1f57d20ae
MD5 d7ebfe058d4f55fcf3c75fc8fc3ca3be
BLAKE2b-256 771b0bc95be3cb2d0284455f35b8e0f16da0642609782d6f55673b26fdff635f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page