432c4e18 |
1 | #! /bin/sh |
2 | |
3 | set -e |
4 | |
5 | cat <<EOF |
6 | /* -*-c-*- |
7 | * |
8 | * Table of standard elliptic curves [generated] |
9 | */ |
10 | |
11 | #include "ectab.h" |
12 | |
13 | #define N(x) (sizeof(x)/sizeof(*x)) |
34e4f738 |
14 | #define MP(x) { x, x + N(x), N(x), 0, MP_CONST, 0 } |
432c4e18 |
15 | |
16 | /*----- Curve data --------------------------------------------------------*/ |
17 | |
18 | EOF |
19 | |
20 | names="" |
21 | while read t n f; do |
22 | |
23 | case $t in |
24 | curve) ;; |
25 | alias) names="$names $n=$f" continue;; |
26 | \#* | "") continue;; |
27 | *) echo >&2 "$0: unknown keyword $t"; exit 1;; |
28 | esac |
29 | |
30 | names="$names $n=$n" |
31 | cat <<EOF |
32 | /* --- Curve $n --- */ |
33 | |
34 | EOF |
35 | |
36 | n=`echo $n | sed 's/[^a-zA-Z0-9_][^a-zA-Z0-9_]*/_/g'` |
37 | case $f in |
38 | prime | niceprime | binpoly) |
39 | read t p; |
40 | if [ $t != p ]; then echo >&2 "$0: wanted p; found $t"; exit 1; fi |
41 | read t a |
42 | if [ $t != a ]; then echo >&2 "$0: wanted a; found $t"; exit 1; fi |
43 | read t b |
44 | if [ $t != b ]; then echo >&2 "$0: wanted b; found $t"; exit 1; fi |
45 | |
46 | cat <<EOF |
34e4f738 |
47 | static mpw c_${n}_p[] = { |
432c4e18 |
48 | EOF |
49 | ./mpdump $p |
50 | cat <<EOF |
51 | }; |
52 | |
34e4f738 |
53 | static mpw c_${n}_a[] = { |
432c4e18 |
54 | EOF |
55 | ./mpdump $a |
56 | cat <<EOF |
57 | }; |
58 | |
34e4f738 |
59 | static mpw c_${n}_b[] = { |
432c4e18 |
60 | EOF |
61 | ./mpdump $b |
62 | cat <<EOF |
63 | }; |
64 | |
65 | EOF |
66 | ;; |
67 | *) echo >&2 "$0: unknown field type $f"; exit 1;; |
68 | esac |
69 | |
70 | read t r |
71 | if [ $t != r ]; then echo >&2 "$0: wanted r; found $t"; exit 1; fi |
72 | read t h |
73 | if [ $t != h ]; then echo >&2 "$0: wanted h; found $t"; exit 1; fi |
74 | read t gx |
75 | if [ $t != gx ]; then echo >&2 "$0: wanted gx; found $t"; exit 1; fi |
76 | read t gy |
77 | if [ $t != gy ]; then echo >&2 "$0: wanted gy; found $t"; exit 1; fi |
78 | |
79 | cat <<EOF |
34e4f738 |
80 | static mpw c_${n}_r[] = { |
432c4e18 |
81 | EOF |
82 | ./mpdump $r |
83 | cat <<EOF |
84 | }; |
85 | |
34e4f738 |
86 | static mpw c_${n}_h[] = { |
432c4e18 |
87 | EOF |
88 | ./mpdump $h |
89 | cat <<EOF |
90 | }; |
91 | |
34e4f738 |
92 | static mpw c_${n}_gx[] = { |
432c4e18 |
93 | EOF |
94 | ./mpdump $gx |
95 | cat <<EOF |
96 | }; |
97 | |
34e4f738 |
98 | static mpw c_${n}_gy[] = { |
432c4e18 |
99 | EOF |
100 | ./mpdump $gy |
101 | cat <<EOF |
102 | }; |
103 | |
104 | EOF |
105 | |
106 | case $f in |
107 | prime) ftag=FTAG_PRIME;; |
108 | niceprime) ftag=FTAG_NICEPRIME;; |
109 | binpoly) ftag=FTAG_BINPOLY;; |
110 | esac |
111 | cat <<EOF |
34e4f738 |
112 | static ecdata c_$n = { |
432c4e18 |
113 | $ftag, |
34e4f738 |
114 | MP(c_${n}_p), |
115 | MP(c_${n}_a), |
116 | MP(c_${n}_b), |
117 | MP(c_${n}_r), |
118 | MP(c_${n}_h), |
119 | MP(c_${n}_gx), |
120 | MP(c_${n}_gy) |
432c4e18 |
121 | }; |
122 | |
123 | EOF |
124 | |
125 | done |
126 | |
127 | cat <<EOF |
128 | /*----- Main table --------------------------------------------------------*/ |
129 | |
130 | const ecentry ectab[] = { |
131 | EOF |
132 | for i in $names; do |
133 | a=`echo $i | sed 's/=.*$//'` |
134 | n=`echo $i | sed 's/^.*=//; s/[^a-zA-Z0-9_][^a-zA-Z0-9_]*/_/g'` |
135 | cat <<EOF |
136 | { "$a", &c_$n }, |
137 | EOF |
138 | done |
139 | cat <<EOF |
140 | { 0, 0 } |
141 | }; |
142 | |
143 | /*----- That's all, folks -------------------------------------------------*/ |
144 | EOF |