3 * Raw formatting of elliptic curve points
5 * (c) 2004 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Catacomb.
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.
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.
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,
28 #ifndef CATACOMB_EC_RAW_H
29 #define CATACOMB_EC_RAW_H
35 /*----- Header files ------------------------------------------------------*/
37 #ifndef CATACOMB_BUF_H
45 /*----- Data formatting ---------------------------------------------------*/
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' */
55 /* --- @ec_ec2osp@ --- *
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
62 * Returns: Zero on success, nonzero on failure.
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
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
78 * Returns failure (@-1@) if the flags are invalid, or if there
79 * isn't enough space in the output buffer.
82 extern int ec_ec2osp(ec_curve */*c*/, unsigned /*f*/,
83 buf */*b*/, const ec */*p*/);
85 /* --- @ec_os2ecp@ --- *
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
92 * Returns: Zero on success, nonzero on failure.
94 * Use: Reads an elliptic curve point from the given buffer using the
95 * standard uncompressed format described in P1363 and SEC1.
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.
110 extern int ec_os2ecp(ec_curve */*c*/, unsigned /*f*/, buf */*b*/, ec */*d*/);
112 /* --- @ec_putraw@ --- *
114 * Arguments: @ec_curve *c@ = elliptic curve
115 * @buf *b@ = pointer to a buffer
116 * @const ec *p@ = an elliptic curve point
118 * Returns: Zero on success, nonzero on failure.
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.
125 extern int ec_putraw(ec_curve */*c*/, buf */*b*/, const ec */*p*/);
127 /* --- @ec_getraw@ --- *
129 * Arguments: @ec_curve *c@ = elliptic curve
130 * @buf *b@ = pointer to a buffer
131 * @ec *d@ = an elliptic curve point
133 * Returns: Zero on success, nonzero on failure.
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.
140 extern int ec_getraw(ec_curve */*c*/, buf */*b*/, ec */*d*/);
142 /*----- That's all, folks -------------------------------------------------*/