chiark / gitweb /
0ceadd63ebb3bece9e54339b71b504d09c22bbad
[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
79 extern int ec_ec2osp(ec_curve */*c*/, unsigned /*f*/,
80                      buf */*b*/, const ec */*p*/);
81
82 /* --- @ec_os2ecp@ --- *
83  *
84  * Arguments:   @ec_curve *c = elliptic curve
85  *              @unsigned f@ = format flags for input
86  *              @buf *b@ = pointer to a buffer
87  *              @ec *d@ = an elliptic curve point
88  *
89  * Returns:     Zero on success, nonzero on failure.
90  *
91  * Use:         Reads an elliptic curve point from the given buffer using the
92  *              standard uncompressed format described in P1363 and SEC1.
93  *
94  *              Point compression features are determined by @f@ as follows.
95  *              If @EC_LSB@ is set, then accept an LSB-compressed %$y$%-
96  *              coordinate; if @EC_SORT@ is set, then accept a SORT-
97  *              compressed %$y$%-coordinate; if @EC_EXPLY@ is set, then
98  *              accept an explicit %$y$%-coordinate; if @EC_XONLY@ is set
99  *              then accept a bare %$x$%-coordinate (a correct
100  *              %$y$%-coordinate is chosen arbitrarily).  Hybrid forms are
101  *              acceptable, and the input is checked to verify that the
102  *              redundant representations are consistent.  If no flags are
103  *              set in @f@, then no input (other than the point at infinity)
104  *              will be acceptable.
105  */
106
107 extern int ec_os2ecp(ec_curve */*c*/, unsigned /*f*/, buf */*b*/, ec */*d*/);
108
109 /* --- @ec_putraw@ --- *
110  *
111  * Arguments:   @ec_curve *c@ = elliptic curve
112  *              @buf *b@ = pointer to a buffer
113  *              @const ec *p@ = an elliptic curve point
114  *
115  * Returns:     Zero on success, nonzero on failure.
116  *
117  * Use:         Puts an elliptic curve point to the given buffer using the
118  *              standard uncompressed format described in P1383 and SEC1.
119  *              We don't do point compression.
120  */
121
122 extern int ec_putraw(ec_curve */*c*/, buf */*b*/, const ec */*p*/);
123
124 /* --- @ec_getraw@ --- *
125  *
126  * Arguments:   @ec_curve *c@ = elliptic curve
127  *              @buf *b@ = pointer to a buffer
128  *              @ec *d@ = an elliptic curve point
129  *
130  * Returns:     Zero on success, nonzero on failure.
131  *
132  * Use:         Reads an elliptic curve point from the given buffer using the
133  *              standard uncompressed format described in P1383 and SEC1.
134  *              We don't do point compression.
135  */
136
137 extern int ec_getraw(ec_curve */*c*/, buf */*b*/, ec */*d*/);
138
139 /*----- That's all, folks -------------------------------------------------*/
140
141 #ifdef __cplusplus
142   }
143 #endif
144
145 #endif