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
79 extern int ec_ec2osp(ec_curve */*c*/, unsigned /*f*/,
80 buf */*b*/, const ec */*p*/);
82 /* --- @ec_os2ecp@ --- *
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
89 * Returns: Zero on success, nonzero on failure.
91 * Use: Reads an elliptic curve point from the given buffer using the
92 * standard uncompressed format described in P1363 and SEC1.
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.
107 extern int ec_os2ecp(ec_curve */*c*/, unsigned /*f*/, buf */*b*/, ec */*d*/);
109 /* --- @ec_putraw@ --- *
111 * Arguments: @ec_curve *c@ = elliptic curve
112 * @buf *b@ = pointer to a buffer
113 * @const ec *p@ = an elliptic curve point
115 * Returns: Zero on success, nonzero on failure.
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.
122 extern int ec_putraw(ec_curve */*c*/, buf */*b*/, const ec */*p*/);
124 /* --- @ec_getraw@ --- *
126 * Arguments: @ec_curve *c@ = elliptic curve
127 * @buf *b@ = pointer to a buffer
128 * @ec *d@ = an elliptic curve point
130 * Returns: Zero on success, nonzero on failure.
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.
137 extern int ec_getraw(ec_curve */*c*/, buf */*b*/, ec */*d*/);
139 /*----- That's all, folks -------------------------------------------------*/