package mec

  1. Overview
  2. Docs
Mec - Mini Elliptic Curve library

Install

Dune Dependency

Authors

Maintainers

Sources

ocaml-ec-0.1.0.tar.bz2
md5=7c68b531c8011b5d032f0a0d8523e8c5
sha512=f428751c5f2b7c7fc07548551bea0277c9c8c32c1052aecf22787188e7678939dbb091844e29178b2819d724cf843c65774d9211c0a0ede5bf71caff3f2dd1bc

doc/src/mec.curve/secp256k1.ml.html

Source file secp256k1.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
(**
  Base field: 2^256 - 2^32 - 2^9 - 2^8 - 2^7 - 2^6 - 2^4 - 1 = 115792089237316195423570985008687907853269984665640564039457584007908834671663 (255 bits - 32 bytes)
  Scalar field: 115792089237316195423570985008687907852837564279074904382605163141518161494337 (255 bits - 32 bytes)

  Base field multiplicative subgroup decomposition:
    2 * 3 * 7 * 13441 * 205115282021455665897114700593932402728804164701536103180137503955397371

  Prime field multiplication subgroup decomposition:
    2^6 * 3 * 149 * 631 * 6414488540731361226607730496888035255996436684289152125202372832747357
*)

let two_z = Z.succ Z.one

module Fq = Ff.MakeFp (struct
  let prime_order =
    Z.(
      (two_z ** 256) - (two_z ** 32) - (two_z ** 9) - (two_z ** 8)
      - (two_z ** 7) - (two_z ** 6) - (two_z ** 4) - one)
end)

module Fp = Ff.MakeFp (struct
  let prime_order =
    Z.of_string
      "115792089237316195423570985008687907852837564279074904382605163141518161494337"
end)

module Projective =
  Ec.MakeProjectiveWeierstrass (Fq) (Fp)
    (struct
      (* See https://en.bitcoin.it/wiki/Secp256k1 *)
      let a = Fq.zero

      let b = Fq.of_z (Z.of_int 7)

      let cofactor = Z.one

      (* x = 55066263022277343669578718895168534326250603453777594175500187360389116729240
         y = 32670510020758816978083085130507043184471273380659243275938904335757337482424
      *)
      let bytes_generator =
        Bytes.concat
          Bytes.empty
          [ Fq.(
              to_bytes
                (of_string
                   "55066263022277343669578718895168534326250603453777594175500187360389116729240"));
            Fq.(
              to_bytes
                (of_string
                   "32670510020758816978083085130507043184471273380659243275938904335757337482424"));
            Fq.(to_bytes one) ]
    end)

module Jacobian =
  Ec.MakeJacobianWeierstrass (Fq) (Fp)
    (struct
      (* See https://en.bitcoin.it/wiki/Secp256k1 *)
      let a = Fq.zero

      let b = Fq.of_z (Z.of_int 7)

      let cofactor = Z.one

      (* x = 55066263022277343669578718895168534326250603453777594175500187360389116729240
         y = 32670510020758816978083085130507043184471273380659243275938904335757337482424
      *)
      let bytes_generator =
        Bytes.concat
          Bytes.empty
          [ Fq.(
              to_bytes
                (of_string
                   "55066263022277343669578718895168534326250603453777594175500187360389116729240"));
            Fq.(
              to_bytes
                (of_string
                   "32670510020758816978083085130507043184471273380659243275938904335757337482424"));
            Fq.(to_bytes one) ]
    end)

module Affine =
  Ec.MakeAffineWeierstrass (Fq) (Fp)
    (struct
      (* See https://en.bitcoin.it/wiki/Secp256k1 *)
      let a = Fq.zero

      let b = Fq.of_z (Z.of_int 7)

      let cofactor = Z.one

      (* x = 55066263022277343669578718895168534326250603453777594175500187360389116729240
         y = 32670510020758816978083085130507043184471273380659243275938904335757337482424
      *)
      let bytes_generator =
        Bytes.concat
          Bytes.empty
          [ Fq.(
              to_bytes
                (of_string
                   "55066263022277343669578718895168534326250603453777594175500187360389116729240"));
            Fq.(
              to_bytes
                (of_string
                   "32670510020758816978083085130507043184471273380659243275938904335757337482424"))
          ]
    end)

let from_affine_weierstrass_to_jacobian_weierstrass p =
  Ec.from_affine_weierstrass_to_jacobian_weierstrass
    (module Affine)
    (module Jacobian)
    p

let from_affine_weierstrass_to_projective_weierstrass p =
  Ec.from_affine_weierstrass_to_projective_weierstrass
    (module Affine)
    (module Projective)
    p

let from_jacobian_weierstrass_to_affine_weierstrass p =
  Ec.from_jacobian_weierstrass_to_affine_weierstrass
    (module Jacobian)
    (module Affine)
    p

let from_projective_weierstrass_to_affine_weierstrass p =
  Ec.from_projective_weierstrass_to_affine_weierstrass
    (module Projective)
    (module Affine)
    p
OCaml

Innovation. Community. Security.