Protocols
ecutils.protocols
Key exchange protocols built on top of the core elliptic curve primitives.
DiffieHellman dataclass
Elliptic Curve Diffie-Hellman key exchange.
Protocol
- Alice computes her public key: H_A = d_A · G
- Bob computes his public key: H_B = d_B · G
- Shared secret: S = d_A · H_B = d_B · H_A = d_A · d_B · G
Security relies on the Elliptic Curve Discrete Logarithm Problem (ECDLP): given G and Q = d·G, it is computationally infeasible to recover the private scalar d.
Attributes:
| Name | Type | Description |
|---|---|---|
private_key | int | The private scalar (integer). |
curve_name | str | Name of the curve (e.g. |
Source code in ecutils/protocols/diffie_hellman.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
public_key: Point property
Compute the public key: private_key * G.
compute_shared_secret(other_public_key)
Compute the shared secret from another party's public key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other_public_key | Point | The other party's public key point. | required |
Returns:
| Type | Description |
|---|---|
Point | The shared secret point |
Source code in ecutils/protocols/diffie_hellman.py
59 60 61 62 63 64 65 66 67 68 | |
MasseyOmura dataclass
Massey-Omura three-pass protocol.
Three-pass message exchange without shared keys:
C1 = e_A · M (Alice encrypts)
C2 = e_B · C1 (Bob encrypts)
C3 = e_A⁻¹ · C2 (Alice removes her encryption)
M = e_B⁻¹ · C3 (Bob recovers the message)
The protocol works because scalar multiplication on elliptic curves is commutative: e_A · (e_B · M) = e_B · (e_A · M).
Requirement: gcd(private_key, n) = 1 so that the modular inverse e⁻¹ mod n exists.
Attributes:
| Name | Type | Description |
|---|---|---|
private_key | int | The private scalar (integer), must be coprime with n. |
curve_name | str | Name of the curve (e.g. |
Source code in ecutils/protocols/massey_omura.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
decrypt(point)
Decrypt (multiply) a point with the inverse of the private key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point | Point | A curve point to decrypt. | required |
Returns:
| Type | Description |
|---|---|
Point |
|
Source code in ecutils/protocols/massey_omura.py
91 92 93 94 95 96 97 98 99 100 | |
encrypt(point)
Encrypt (multiply) a point with the private key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point | Point | A curve point (message or partially encrypted). | required |
Returns:
| Type | Description |
|---|---|
Point |
|
Source code in ecutils/protocols/massey_omura.py
80 81 82 83 84 85 86 87 88 89 | |