Add cyclic group abstraction, with test code. Separate off exponentation
[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))
34e4f738 14#define MP(x) { x, x + N(x), N(x), 0, MP_CONST, 0 }
432c4e18 15
16/*----- Curve data --------------------------------------------------------*/
17
18EOF
19
20names=""
21while 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
34EOF
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 47static mpw c_${n}_p[] = {
432c4e18 48EOF
49 ./mpdump $p
50 cat <<EOF
51};
52
34e4f738 53static mpw c_${n}_a[] = {
432c4e18 54EOF
55 ./mpdump $a
56 cat <<EOF
57};
58
34e4f738 59static mpw c_${n}_b[] = {
432c4e18 60EOF
61 ./mpdump $b
62 cat <<EOF
63};
64
65EOF
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 80static mpw c_${n}_r[] = {
432c4e18 81EOF
82 ./mpdump $r
83 cat <<EOF
84};
85
34e4f738 86static mpw c_${n}_h[] = {
432c4e18 87EOF
88 ./mpdump $h
89 cat <<EOF
90};
91
34e4f738 92static mpw c_${n}_gx[] = {
432c4e18 93EOF
94 ./mpdump $gx
95 cat <<EOF
96};
97
34e4f738 98static mpw c_${n}_gy[] = {
432c4e18 99EOF
100 ./mpdump $gy
101 cat <<EOF
102};
103
104EOF
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 112static 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
123EOF
124
125done
126
127cat <<EOF
128/*----- Main table --------------------------------------------------------*/
129
130const ecentry ectab[] = {
131EOF
132for 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 },
137EOF
138done
139cat <<EOF
140 { 0, 0 }
141};
142
143/*----- That's all, folks -------------------------------------------------*/
144EOF