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