@@ -36,22 +36,60 @@ The project includes:
3636
3737``` julia
3838using TinyCrypto
39+ import TinyCrypto: is_identity
3940
40- # Find a suitable Weierstrass curve over small field primes and coefficient ranges
41+ # Find a suitable Weierstrass curve over small field primes and coefficient ranges with iterative method
42+ # general syntax: curve-name(prime-field-range, parameter-range₁, ..., parameter-rangeₙ, max_cofactor=8)
4143curve = Weierstrass (97 : 103 , 10 : 15 , 2 : 7 ) # (prime range, a range, b range)
42- # Output: Weierstrass curve : y² = x³ + 10x + 3 |𝔽₉₇ with order: 101 and 𝔾(0,10)
44+ # Output: Weierstrass{𝔽₉₇} : y² = x³ + 10x + 3 | 𝔾(0,10), q = 101, h = 1, #E = 10
4345
44- # Get all curve points
45- E = curve_points (curve)
46+ E = curve_points (curve) # Get all curve points
4647# → 101-element Vector{ECPoint₁₂₈}: (0𝔽₉₇,10𝔽₉₇), (0𝔽₉₇,87𝔽₉₇), ..., (96𝔽₉₇,63𝔽₉₇), (∞,∞)
48+ S = subgroup_points (curve) # same as `curve_points` as #E(𝔽₉₇) ∈ primes
49+
50+ curve = Montgomery (30 : 40 , 8 : 40 , 3 : 40 )
51+ # Montgomery{𝔽₃₇}: 8y² = x³ + 3x² + x | 𝔾(15,2), q = 11, h = 4, #E = 44
52+ S = subgroup_points (curve) # when cofactor greater than one, there are multiple sub groups
53+ E = curve_points (curve)
54+
55+ curve = TwistedEdwards (50 : 100 , 1 : 20 , 1 : 20 )
56+ # TwistedEdwards{𝔽₉₇}: 3x² + y² = 1 + 10x²y² | 𝔾(48,93), q = 29, h = 4, #E = 116
57+
58+ curve = Edwards (50 : 100 , 1 : 20 , max_cofactor= 8 )
59+ # Edwards{𝔽₇₉}: 1x² + y² = 1 + 6x²y² | 𝔾(7,58), q = 23, h = 4, #E = 92
60+ is_singular (curve) # false
61+
62+ # # Point arithmetic on curve
63+ 𝔾 = curve. G # (7𝔽₇₉,58𝔽₇₉) ∈ Edwards{Fp{UInt128, 79}}
64+ 𝔾 + 𝔾 + 𝔾 + 𝔾 # (68𝔽₇₉,67𝔽₇₉) point addition on a cyclic group
65+ 2 𝔾 # (31𝔽₇₉,51𝔽₇₉)
66+ 2 𝔾 == 𝔾 + 𝔾 # true
67+
68+ 𝒪 = identity (curve) # identity point on Edwards curve variant: (0𝔽₇₉,1𝔽₇₉)
69+ 𝒪 + 𝔾 == 𝔾 # true
70+ 𝔾 + 𝒪 == 𝔾 # true
71+
72+ # direct construction from paramters:
73+ const 𝔽₃₁ = 𝔽ₚ{UInt8, 31 } # define field prime 𝔽ₚ for the abelian group, or use non-unicode `Fp{base_type, prime_number}`
74+ Weierstrass {𝔽₃₁} (6 , 9 , 37 , 1 , (0 ,3 )) # Weierstrass{𝔽₃₁}: y² = x³ + 6x + 9 | 𝔾(0,3), q = 37, h = 1, #E = 37
75+ # or pass the 𝔽ₚ field prime directly as in:
76+ curve = Weierstrass (31 , 6 , 9 , 37 , 1 , (0 ,3 )) # Weierstrass{𝔽₃₁}: y² = x³ + 6x + 9 | 𝔾(0,3), q = 37, h = 1, #E = 37
77+
78+ 𝒪 = identity (curve) # (∞,∞) Weierstrass curve identity is infinity
79+ is_identity (𝒪) # true
80+ ∞ = infinity (curve) # (∞,∞) as expected
81+ is_infinity (∞) # true
82+
83+ E = curve_points (curve) #
84+ is_point_on_curve (E[1 ], curve) # true
85+ is_point_on_curve (curve. G, curve) # true, G generator point defines the cyclic group, which in this case the entire abelien group
86+
4787
48- # ECDSA example
49- private_key = 42
50- msg = 33
5188
52- public_key = private_key2public (private_key, curve) # ECPoint on curve
53- r, s, v = ecdsa_sign (curve, private_key, msg)
54- ecdsa_verify (curve, public_key, r, s, v) # true
89+ # # Tiny Hash (not for cryptographic use, for obvious reasons)
90+ H (" byte size hash of a string" ) # hashes string to a byte, given the abelian group is byte size
91+ H₁₆ (" 16 bit hash" ) # in case you need more hash space
92+ H₈ (" is same" ) == H (" is same" ) # true, it is just a alias, smae as H8
5593```
5694
5795## Installation
0 commit comments