chiark / gitweb /
rand/rand-x86ish.S: Hoist argument register allocation outside.
[catacomb] / math / ec-raw.h
1 /* -*-c-*-
2  *
3  * Raw formatting of elliptic curve points
4  *
5  * (c) 2004 Straylight/Edgeware
6  */
7
8 /*----- Licensing notice --------------------------------------------------*
9  *
10  * This file is part of Catacomb.
11  *
12  * Catacomb is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU Library General Public License as
14  * published by the Free Software Foundation; either version 2 of the
15  * License, or (at your option) any later version.
16  *
17  * Catacomb is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU Library General Public License for more details.
21  *
22  * You should have received a copy of the GNU Library General Public
23  * License along with Catacomb; if not, write to the Free
24  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25  * MA 02111-1307, USA.
26  */
27
28 #ifndef CATACOMB_EC_RAW_H
29 #define CATACOMB_EC_RAW_H
30
31 #ifdef __cplusplus
32   extern "C" {
33 #endif
34
35 /*----- Header files ------------------------------------------------------*/
36
37 #ifndef CATACOMB_BUF_H
38 #  include "buf.h"
39 #endif
40
41 #ifndef CATACOMB_EC_H
42 #  include "ec.h"
43 #endif
44
45 /*----- Data formatting ---------------------------------------------------*/
46
47 /* EC2OSP/OS2ECP bit mask. */
48 #define EC_YBIT 1u                      /* The compressed @y@-coordinate */
49 #define EC_XONLY 1u                     /* The @y@-coordinate is absent */
50 #define EC_CMPR 2u                      /* Compressed @y@-coordinate */
51 #define EC_LSB 2u                       /* Use `lsb' compression */
52 #define EC_EXPLY 4u                     /* Explicit @y@-coordinate */
53 #define EC_SORT 8u                      /* Use `sort' rather than `lsb' */
54
55 /* --- @ec_ec2osp@ --- *
56  *
57  * Arguments:   @ec_curve *c@ = elliptic curve
58  *              @unsigned f@ = format flags for output
59  *              @buf *b@ = pointer to a buffer
60  *              @const ec *p@ = an elliptic curve point
61  *
62  * Returns:     Zero on success, nonzero on failure.
63  *
64  * Use:         Puts an elliptic curve point to the given buffer using the
65  *              standard uncompressed format described in P1363 and SEC1.
66  *              This requires at most @1 + 2 * c->f->noctets@ space in the
67  *              buffer.
68  *
69  *              Point compression features are determined by @f@ as follows.
70  *              If @EC_CMPR@ is set then point compression is performed and a
71  *              compressed form of the %$y$%-coordinate is contained in the
72  *              first output byte; if @EC_SORT@ is set then P1363a `SORT'
73  *              compression is used, otherwise LSB compression.  If
74  *              @EC_EXPLY@ is set, then an explicit %$y$%-coordinate is
75  *              output in full.  Otherwise the %$y$%-coordinate is
76  *              suppressed.
77  *
78  *              Returns failure (@-1@) if the flags are invalid, or if there
79  *              isn't enough space in the output buffer.
80  */
81
82 extern int ec_ec2osp(ec_curve */*c*/, unsigned /*f*/,
83                      buf */*b*/, const ec */*p*/);
84
85 /* --- @ec_os2ecp@ --- *
86  *
87  * Arguments:   @ec_curve *c = elliptic curve
88  *              @unsigned f@ = format flags for input
89  *              @buf *b@ = pointer to a buffer
90  *              @ec *d@ = an elliptic curve point
91  *
92  * Returns:     Zero on success, nonzero on failure.
93  *
94  * Use:         Reads an elliptic curve point from the given buffer using the
95  *              standard uncompressed format described in P1363 and SEC1.
96  *
97  *              Point compression features are determined by @f@ as follows.
98  *              If @EC_LSB@ is set, then accept an LSB-compressed %$y$%-
99  *              coordinate; if @EC_SORT@ is set, then accept a SORT-
100  *              compressed %$y$%-coordinate; if @EC_EXPLY@ is set, then
101  *              accept an explicit %$y$%-coordinate; if @EC_XONLY@ is set
102  *              then accept a bare %$x$%-coordinate (a correct
103  *              %$y$%-coordinate is chosen arbitrarily).  Hybrid forms are
104  *              acceptable, and the input is checked to verify that the
105  *              redundant representations are consistent.  If no flags are
106  *              set in @f@, then no input (other than the point at infinity)
107  *              will be acceptable.
108  */
109
110 extern int ec_os2ecp(ec_curve */*c*/, unsigned /*f*/, buf */*b*/, ec */*d*/);
111
112 /* --- @ec_putraw@ --- *
113  *
114  * Arguments:   @ec_curve *c@ = elliptic curve
115  *              @buf *b@ = pointer to a buffer
116  *              @const ec *p@ = an elliptic curve point
117  *
118  * Returns:     Zero on success, nonzero on failure.
119  *
120  * Use:         Puts an elliptic curve point to the given buffer using the
121  *              standard uncompressed format described in P1383 and SEC1.
122  *              We don't do point compression.
123  */
124
125 extern int ec_putraw(ec_curve */*c*/, buf */*b*/, const ec */*p*/);
126
127 /* --- @ec_getraw@ --- *
128  *
129  * Arguments:   @ec_curve *c@ = elliptic curve
130  *              @buf *b@ = pointer to a buffer
131  *              @ec *d@ = an elliptic curve point
132  *
133  * Returns:     Zero on success, nonzero on failure.
134  *
135  * Use:         Reads an elliptic curve point from the given buffer using the
136  *              standard uncompressed format described in P1383 and SEC1.
137  *              We don't do point compression.
138  */
139
140 extern int ec_getraw(ec_curve */*c*/, buf */*b*/, ec */*d*/);
141
142 /*----- That's all, folks -------------------------------------------------*/
143
144 #ifdef __cplusplus
145   }
146 #endif
147
148 #endif