283be0f39af0aac2e69cc5aaf5547453e62ac0c9
[BearSSL] / bearssl_ec.h
1 /*
2 * Copyright (c) 2016 Thomas Pornin <pornin@bolet.org>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25 #ifndef BR_BEARSSL_EC_H__
26 #define BR_BEARSSL_EC_H__
27
28 #include <stddef.h>
29 #include <stdint.h>
30
31 /** \file bearssl_ec.h
32 *
33 * # Elliptic Curves
34 *
35 * This file documents the EC implementations provided with BearSSL, and
36 * ECDSA.
37 *
38 * ## Elliptic Curve API
39 *
40 * Only "named curves" are supported. Each EC implementation supports
41 * one or several named curves, identified by symbolic identifiers.
42 * These identifiers are small integers, that correspond to the values
43 * registered by the
44 * [IANA](http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8).
45 *
46 * Since all currently defined elliptic curve identifiers are in the 0..31
47 * range, it is convenient to encode support of some curves in a 32-bit
48 * word, such that bit x corresponds to curve of identifier x.
49 *
50 * An EC implementation is incarnated by a `br_ec_impl` instance, that
51 * offers the following fields:
52 *
53 * - `supported_curves`
54 *
55 * A 32-bit word that documents the identifiers of the curves supported
56 * by this implementation.
57 *
58 * - `generator()`
59 *
60 * Callback method that returns a pointer to the conventional generator
61 * point for that curve.
62 *
63 * - `order()`
64 *
65 * Callback method that returns a pointer to the subgroup order for
66 * that curve. That value uses unsigned big-endian encoding.
67 *
68 * - `xoff()`
69 *
70 * Callback method that returns the offset and length of the X
71 * coordinate in an encoded point.
72 *
73 * - `mul()`
74 *
75 * Multiply a curve point with an integer.
76 *
77 * - `mulgen()`
78 *
79 * Multiply the curve generator with an integer. This may be faster
80 * than the generic `mul()`.
81 *
82 * - `muladd()`
83 *
84 * Multiply two curve points by two integers, and return the sum of
85 * the two products.
86 *
87 * All curve points are represented in uncompressed format. The `mul()`
88 * and `muladd()` methods take care to validate that the provided points
89 * are really part of the relevant curve subgroup.
90 *
91 * For all point multiplication functions, the following holds:
92 *
93 * - Functions validate that the provided points are valid members
94 * of the relevant curve subgroup. An error is reported if that is
95 * not the case.
96 *
97 * - Processing is constant-time, even if the point operands are not
98 * valid. This holds for both the source and resulting points, and
99 * the multipliers (integers). Only the byte length of the provided
100 * multiplier arrays (not their actual value length in bits) may
101 * leak through timing-based side channels.
102 *
103 * - The multipliers (integers) MUST be lower than the subgroup order.
104 * If this property is not met, then the result is indeterminate,
105 * but an error value is not ncessearily returned.
106 *
107 *
108 * ## ECDSA
109 *
110 * ECDSA signatures have two standard formats, called "raw" and "asn1".
111 * Internally, such a signature is a pair of modular integers `(r,s)`.
112 * The "raw" format is the concatenation of the unsigned big-endian
113 * encodings of these two integers, possibly left-padded with zeros so
114 * that they have the same encoded length. The "asn1" format is the
115 * DER encoding of an ASN.1 structure that contains the two integer
116 * values:
117 *
118 * ECDSASignature ::= SEQUENCE {
119 * r INTEGER,
120 * s INTEGER
121 * }
122 *
123 * In general, in all of X.509 and SSL/TLS, the "asn1" format is used.
124 * BearSSL offers ECDSA implementations for both formats; conversion
125 * functions between the two formats are also provided. Conversion of a
126 * "raw" format signature into "asn1" may enlarge a signature by no more
127 * than 9 bytes for all supported curves; conversely, conversion of an
128 * "asn1" signature to "raw" may expand the signature but the "raw"
129 * length will never be more than twice the length of the "asn1" length
130 * (and usually it will be shorter).
131 *
132 * Note that for a given signature, the "raw" format is not fully
133 * deterministic, in that it does not enforce a minimal common length.
134 */
135
136 /*
137 * Standard curve ID. These ID are equal to the assigned numerical
138 * identifiers assigned to these curves for TLS:
139 * http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8
140 */
141
142 /** \brief Identifier for named curve sect163k1. */
143 #define BR_EC_sect163k1 1
144
145 /** \brief Identifier for named curve sect163r1. */
146 #define BR_EC_sect163r1 2
147
148 /** \brief Identifier for named curve sect163r2. */
149 #define BR_EC_sect163r2 3
150
151 /** \brief Identifier for named curve sect193r1. */
152 #define BR_EC_sect193r1 4
153
154 /** \brief Identifier for named curve sect193r2. */
155 #define BR_EC_sect193r2 5
156
157 /** \brief Identifier for named curve sect233k1. */
158 #define BR_EC_sect233k1 6
159
160 /** \brief Identifier for named curve sect233r1. */
161 #define BR_EC_sect233r1 7
162
163 /** \brief Identifier for named curve sect239k1. */
164 #define BR_EC_sect239k1 8
165
166 /** \brief Identifier for named curve sect283k1. */
167 #define BR_EC_sect283k1 9
168
169 /** \brief Identifier for named curve sect283r1. */
170 #define BR_EC_sect283r1 10
171
172 /** \brief Identifier for named curve sect409k1. */
173 #define BR_EC_sect409k1 11
174
175 /** \brief Identifier for named curve sect409r1. */
176 #define BR_EC_sect409r1 12
177
178 /** \brief Identifier for named curve sect571k1. */
179 #define BR_EC_sect571k1 13
180
181 /** \brief Identifier for named curve sect571r1. */
182 #define BR_EC_sect571r1 14
183
184 /** \brief Identifier for named curve secp160k1. */
185 #define BR_EC_secp160k1 15
186
187 /** \brief Identifier for named curve secp160r1. */
188 #define BR_EC_secp160r1 16
189
190 /** \brief Identifier for named curve secp160r2. */
191 #define BR_EC_secp160r2 17
192
193 /** \brief Identifier for named curve secp192k1. */
194 #define BR_EC_secp192k1 18
195
196 /** \brief Identifier for named curve secp192r1. */
197 #define BR_EC_secp192r1 19
198
199 /** \brief Identifier for named curve secp224k1. */
200 #define BR_EC_secp224k1 20
201
202 /** \brief Identifier for named curve secp224r1. */
203 #define BR_EC_secp224r1 21
204
205 /** \brief Identifier for named curve secp256k1. */
206 #define BR_EC_secp256k1 22
207
208 /** \brief Identifier for named curve secp256r1. */
209 #define BR_EC_secp256r1 23
210
211 /** \brief Identifier for named curve secp384r1. */
212 #define BR_EC_secp384r1 24
213
214 /** \brief Identifier for named curve secp521r1. */
215 #define BR_EC_secp521r1 25
216
217 /** \brief Identifier for named curve brainpoolP256r1. */
218 #define BR_EC_brainpoolP256r1 26
219
220 /** \brief Identifier for named curve brainpoolP384r1. */
221 #define BR_EC_brainpoolP384r1 27
222
223 /** \brief Identifier for named curve brainpoolP512r1. */
224 #define BR_EC_brainpoolP512r1 28
225
226 /** \brief Identifier for named curve Curve25519. */
227 #define BR_EC_curve25519 29
228
229 /** \brief Identifier for named curve Curve448. */
230 #define BR_EC_curve448 30
231
232 /**
233 * \brief Structure for an EC public key.
234 */
235 typedef struct {
236 /** \brief Identifier for the curve used by this key. */
237 int curve;
238 /** \brief Public curve point (uncompressed format). */
239 unsigned char *q;
240 /** \brief Length of public curve point (in bytes). */
241 size_t qlen;
242 } br_ec_public_key;
243
244 /**
245 * \brief Structure for an EC private key.
246 *
247 * The private key is an integer modulo the curve subgroup order. The
248 * encoding below tolerates extra leading zeros. In general, it is
249 * recommended that the private key has the same length as the curve
250 * subgroup order.
251 */
252 typedef struct {
253 /** \brief Identifier for the curve used by this key. */
254 int curve;
255 /** \brief Private key (integer, unsigned big-endian encoding). */
256 unsigned char *x;
257 /** \brief Private key length (in bytes). */
258 size_t xlen;
259 } br_ec_private_key;
260
261 /**
262 * \brief Type for an EC implementation.
263 */
264 typedef struct {
265 /**
266 * \brief Supported curves.
267 *
268 * This word is a bitfield: bit `x` is set if the curve of ID `x`
269 * is supported. E.g. an implementation supporting both NIST P-256
270 * (secp256r1, ID 23) and NIST P-384 (secp384r1, ID 24) will have
271 * value `0x01800000` in this field.
272 */
273 uint32_t supported_curves;
274
275 /**
276 * \brief Get the conventional generator.
277 *
278 * This function returns the conventional generator (encoded
279 * curve point) for the specified curve. This function MUST NOT
280 * be called if the curve is not supported.
281 *
282 * \param curve curve identifier.
283 * \param len receiver for the encoded generator length (in bytes).
284 * \return the encoded generator.
285 */
286 const unsigned char *(*generator)(int curve, size_t *len);
287
288 /**
289 * \brief Get the subgroup order.
290 *
291 * This function returns the order of the subgroup generated by
292 * the conventional generator, for the specified curve. Unsigned
293 * big-endian encoding is used. This function MUST NOT be called
294 * if the curve is not supported.
295 *
296 * \param curve curve identifier.
297 * \param len receiver for the encoded order length (in bytes).
298 * \return the encoded order.
299 */
300 const unsigned char *(*order)(int curve, size_t *len);
301
302 /**
303 * \brief Get the offset and length for the X coordinate.
304 *
305 * This function returns the offset and length (in bytes) of
306 * the X coordinate in an encoded non-zero point.
307 *
308 * \param curve curve identifier.
309 * \param len receiver for the X coordinate length (in bytes).
310 * \return the offset for the X coordinate (in bytes).
311 */
312 size_t (*xoff)(int curve, size_t *len);
313
314 /**
315 * \brief Multiply a curve point by an integer.
316 *
317 * The source point is provided in array `G` (of size `Glen` bytes);
318 * the multiplication result is written over it. The multiplier
319 * `x` (of size `xlen` bytes) uses unsigned big-endian encoding.
320 *
321 * Rules:
322 *
323 * - The specified curve MUST be supported.
324 *
325 * - The source point must be a valid point on the relevant curve
326 * subgroup (and not the "point at infinity" either). If this is
327 * not the case, then this function returns an error (0).
328 *
329 * - The multiplier integer MUST be non-zero and less than the
330 * curve subgroup order. If this property does not hold, then
331 * the result is indeterminate and an error code is not
332 * guaranteed.
333 *
334 * Returned value is 1 on success, 0 on error. On error, the
335 * contents of `G` are indeterminate.
336 *
337 * \param G point to multiply.
338 * \param Glen length of the encoded point (in bytes).
339 * \param x multiplier (unsigned big-endian).
340 * \param xlen multiplier length (in bytes).
341 * \param curve curve identifier.
342 * \return 1 on success, 0 on error.
343 */
344 uint32_t (*mul)(unsigned char *G, size_t Glen,
345 const unsigned char *x, size_t xlen, int curve);
346
347 /**
348 * \brief Multiply the generator by an integer.
349 *
350 * The multiplier MUST be non-zero and less than the curve
351 * subgroup order. Results are indeterminate if this property
352 * does not hold.
353 *
354 * \param R output buffer for the point.
355 * \param x multiplier (unsigned big-endian).
356 * \param xlen multiplier length (in bytes).
357 * \param curve curve identifier.
358 * \return encoded result point length (in bytes).
359 */
360 size_t (*mulgen)(unsigned char *R,
361 const unsigned char *x, size_t xlen, int curve);
362
363 /**
364 * \brief Multiply two points by two integers and add the
365 * results.
366 *
367 * The point `x*A + y*B` is computed and written back in the `A`
368 * array.
369 *
370 * Rules:
371 *
372 * - The specified curve MUST be supported.
373 *
374 * - The source points (`A` and `B`) must be valid points on
375 * the relevant curve subgroup (and not the "point at
376 * infinity" either). If this is not the case, then this
377 * function returns an error (0).
378 *
379 * - If the `B` pointer is `NULL`, then the conventional
380 * subgroup generator is used. With some implementations,
381 * this may be faster than providing a pointer to the
382 * generator.
383 *
384 * - The multiplier integers (`x` and `y`) MUST be non-zero
385 * and less than the curve subgroup order. If either integer
386 * is zero, then an error is reported, but if one of them is
387 * not lower than the subgroup order, then the result is
388 * indeterminate and an error code is not guaranteed.
389 *
390 * - If the final result is the point at infinity, then an
391 * error is returned.
392 *
393 * Returned value is 1 on success, 0 on error. On error, the
394 * contents of `A` are indeterminate.
395 *
396 * \param A first point to multiply.
397 * \param B second point to multiply (`NULL` for the generator).
398 * \param len common length of the encoded points (in bytes).
399 * \param x multiplier for `A` (unsigned big-endian).
400 * \param xlen length of multiplier for `A` (in bytes).
401 * \param y multiplier for `A` (unsigned big-endian).
402 * \param ylen length of multiplier for `A` (in bytes).
403 * \param curve curve identifier.
404 * \return 1 on success, 0 on error.
405 */
406 uint32_t (*muladd)(unsigned char *A, const unsigned char *B, size_t len,
407 const unsigned char *x, size_t xlen,
408 const unsigned char *y, size_t ylen, int curve);
409 } br_ec_impl;
410
411 /**
412 * \brief EC implementation "i31".
413 *
414 * This implementation internally uses generic code for modular integers,
415 * with a representation as sequences of 31-bit words. It supports secp256r1,
416 * secp384r1 and secp521r1 (aka NIST curves P-256, P-384 and P-521).
417 */
418 extern const br_ec_impl br_ec_prime_i31;
419
420 /**
421 * \brief EC implementation "i15".
422 *
423 * This implementation internally uses generic code for modular integers,
424 * with a representation as sequences of 15-bit words. It supports secp256r1,
425 * secp384r1 and secp521r1 (aka NIST curves P-256, P-384 and P-521).
426 */
427 extern const br_ec_impl br_ec_prime_i15;
428
429 /**
430 * \brief EC implementation "m15" for P-256.
431 *
432 * This implementation uses specialised code for curve secp256r1 (also
433 * known as NIST P-256), with optional Karatsuba decomposition, and fast
434 * modular reduction thanks to the field modulus special format. Only
435 * 32-bit multiplications are used (with 32-bit results, not 64-bit).
436 */
437 extern const br_ec_impl br_ec_p256_m15;
438
439 /**
440 * \brief EC implementation "i15" (generic code) for Curve25519.
441 *
442 * This implementation uses the generic code for modular integers (with
443 * 15-bit words) to support Curve25519. Due to the specificities of the
444 * curve definition, the following applies:
445 *
446 * - `muladd()` is not implemented (the function returns 0 systematically).
447 * - `order()` returns 2^255-1, since the point multiplication algorithm
448 * accepts any 32-bit integer as input (it clears the top bit and low
449 * three bits systematically).
450 */
451 extern const br_ec_impl br_ec_c25519_i15;
452
453 /**
454 * \brief EC implementation "i31" (generic code) for Curve25519.
455 *
456 * This implementation uses the generic code for modular integers (with
457 * 31-bit words) to support Curve25519. Due to the specificities of the
458 * curve definition, the following applies:
459 *
460 * - `muladd()` is not implemented (the function returns 0 systematically).
461 * - `order()` returns 2^255-1, since the point multiplication algorithm
462 * accepts any 32-bit integer as input (it clears the top bit and low
463 * three bits systematically).
464 */
465 extern const br_ec_impl br_ec_c25519_i31;
466
467 /**
468 * \brief EC implementation "m15" (specialised code) for Curve25519.
469 *
470 * This implementation uses custom code relying on multiplication of
471 * integers up to 15 bits. Due to the specificities of the curve
472 * definition, the following applies:
473 *
474 * - `muladd()` is not implemented (the function returns 0 systematically).
475 * - `order()` returns 2^255-1, since the point multiplication algorithm
476 * accepts any 32-bit integer as input (it clears the top bit and low
477 * three bits systematically).
478 */
479 extern const br_ec_impl br_ec_c25519_m15;
480
481 /**
482 * \brief EC implementation "m31" (specialised code) for Curve25519.
483 *
484 * This implementation uses custom code relying on multiplication of
485 * integers up to 31 bits. Due to the specificities of the curve
486 * definition, the following applies:
487 *
488 * - `muladd()` is not implemented (the function returns 0 systematically).
489 * - `order()` returns 2^255-1, since the point multiplication algorithm
490 * accepts any 32-bit integer as input (it clears the top bit and low
491 * three bits systematically).
492 */
493 extern const br_ec_impl br_ec_c25519_m31;
494
495 /**
496 * \brief Aggregate EC implementation "m15".
497 *
498 * This implementation is a wrapper for:
499 *
500 * - `br_ec_c25519_m15` for Curve25519
501 * - `br_ec_p256_m15` for NIST P-256
502 * - `br_ec_prime_i15` for other curves (NIST P-384 and NIST-P512)
503 */
504 extern const br_ec_impl br_ec_all_m15;
505
506 /**
507 * \brief Convert a signature from "raw" to "asn1".
508 *
509 * Conversion is done "in place" and the new length is returned.
510 * Conversion may enlarge the signature, but by no more than 9 bytes at
511 * most. On error, 0 is returned (error conditions include an odd raw
512 * signature length, or an oversized integer).
513 *
514 * \param sig signature to convert.
515 * \param sig_len signature length (in bytes).
516 * \return the new signature length, or 0 on error.
517 */
518 size_t br_ecdsa_raw_to_asn1(void *sig, size_t sig_len);
519
520 /**
521 * \brief Convert a signature from "asn1" to "raw".
522 *
523 * Conversion is done "in place" and the new length is returned.
524 * Conversion may enlarge the signature, but the new signature length
525 * will be less than twice the source length at most. On error, 0 is
526 * returned (error conditions include an invalid ASN.1 structure or an
527 * oversized integer).
528 *
529 * \param sig signature to convert.
530 * \param sig_len signature length (in bytes).
531 * \return the new signature length, or 0 on error.
532 */
533 size_t br_ecdsa_asn1_to_raw(void *sig, size_t sig_len);
534
535 /**
536 * \brief Type for an ECDSA signer function.
537 *
538 * A pointer to the EC implementation is provided. The hash value is
539 * assumed to have the length inferred from the designated hash function
540 * class.
541 *
542 * Signature is written in the buffer pointed to by `sig`, and the length
543 * (in bytes) is returned. On error, nothing is written in the buffer,
544 * and 0 is returned. This function returns 0 if the specified curve is
545 * not supported by the provided EC implementation.
546 *
547 * The signature format is either "raw" or "asn1", depending on the
548 * implementation; maximum length is predictable from the implemented
549 * curve:
550 *
551 * | curve | raw | asn1 |
552 * | :--------- | --: | ---: |
553 * | NIST P-256 | 64 | 72 |
554 * | NIST P-384 | 96 | 104 |
555 * | NIST P-521 | 132 | 139 |
556 *
557 * \param impl EC implementation to use.
558 * \param hf hash function used to process the data.
559 * \param hash_value signed data (hashed).
560 * \param sk EC private key.
561 * \param sig destination buffer.
562 * \return the signature length (in bytes), or 0 on error.
563 */
564 typedef size_t (*br_ecdsa_sign)(const br_ec_impl *impl,
565 const br_hash_class *hf, const void *hash_value,
566 const br_ec_private_key *sk, void *sig);
567
568 /**
569 * \brief Type for an ECDSA signature verification function.
570 *
571 * A pointer to the EC implementation is provided. The hashed value,
572 * computed over the purportedly signed data, is also provided with
573 * its length.
574 *
575 * The signature format is either "raw" or "asn1", depending on the
576 * implementation.
577 *
578 * Returned value is 1 on success (valid signature), 0 on error. This
579 * function returns 0 if the specified curve is not supported by the
580 * provided EC implementation.
581 *
582 * \param impl EC implementation to use.
583 * \param hash signed data (hashed).
584 * \param hash_len hash value length (in bytes).
585 * \param pk EC public key.
586 * \param sig signature.
587 * \param sig_len signature length (in bytes).
588 * \return 1 on success, 0 on error.
589 */
590 typedef uint32_t (*br_ecdsa_vrfy)(const br_ec_impl *impl,
591 const void *hash, size_t hash_len,
592 const br_ec_public_key *pk, const void *sig, size_t sig_len);
593
594 /**
595 * \brief ECDSA signature generator, "i31" implementation, "asn1" format.
596 *
597 * \see br_ecdsa_sign()
598 *
599 * \param impl EC implementation to use.
600 * \param hf hash function used to process the data.
601 * \param hash_value signed data (hashed).
602 * \param sk EC private key.
603 * \param sig destination buffer.
604 * \return the signature length (in bytes), or 0 on error.
605 */
606 size_t br_ecdsa_i31_sign_asn1(const br_ec_impl *impl,
607 const br_hash_class *hf, const void *hash_value,
608 const br_ec_private_key *sk, void *sig);
609
610 /**
611 * \brief ECDSA signature generator, "i31" implementation, "raw" format.
612 *
613 * \see br_ecdsa_sign()
614 *
615 * \param impl EC implementation to use.
616 * \param hf hash function used to process the data.
617 * \param hash_value signed data (hashed).
618 * \param sk EC private key.
619 * \param sig destination buffer.
620 * \return the signature length (in bytes), or 0 on error.
621 */
622 size_t br_ecdsa_i31_sign_raw(const br_ec_impl *impl,
623 const br_hash_class *hf, const void *hash_value,
624 const br_ec_private_key *sk, void *sig);
625
626 /**
627 * \brief ECDSA signature verifier, "i31" implementation, "asn1" format.
628 *
629 * \see br_ecdsa_vrfy()
630 *
631 * \param impl EC implementation to use.
632 * \param hash signed data (hashed).
633 * \param hash_len hash value length (in bytes).
634 * \param pk EC public key.
635 * \param sig signature.
636 * \param sig_len signature length (in bytes).
637 * \return 1 on success, 0 on error.
638 */
639 uint32_t br_ecdsa_i31_vrfy_asn1(const br_ec_impl *impl,
640 const void *hash, size_t hash_len,
641 const br_ec_public_key *pk, const void *sig, size_t sig_len);
642
643 /**
644 * \brief ECDSA signature verifier, "i31" implementation, "raw" format.
645 *
646 * \see br_ecdsa_vrfy()
647 *
648 * \param impl EC implementation to use.
649 * \param hash signed data (hashed).
650 * \param hash_len hash value length (in bytes).
651 * \param pk EC public key.
652 * \param sig signature.
653 * \param sig_len signature length (in bytes).
654 * \return 1 on success, 0 on error.
655 */
656 uint32_t br_ecdsa_i31_vrfy_raw(const br_ec_impl *impl,
657 const void *hash, size_t hash_len,
658 const br_ec_public_key *pk, const void *sig, size_t sig_len);
659
660 /**
661 * \brief ECDSA signature generator, "i15" implementation, "asn1" format.
662 *
663 * \see br_ecdsa_sign()
664 *
665 * \param impl EC implementation to use.
666 * \param hf hash function used to process the data.
667 * \param hash_value signed data (hashed).
668 * \param sk EC private key.
669 * \param sig destination buffer.
670 * \return the signature length (in bytes), or 0 on error.
671 */
672 size_t br_ecdsa_i15_sign_asn1(const br_ec_impl *impl,
673 const br_hash_class *hf, const void *hash_value,
674 const br_ec_private_key *sk, void *sig);
675
676 /**
677 * \brief ECDSA signature generator, "i15" implementation, "raw" format.
678 *
679 * \see br_ecdsa_sign()
680 *
681 * \param impl EC implementation to use.
682 * \param hf hash function used to process the data.
683 * \param hash_value signed data (hashed).
684 * \param sk EC private key.
685 * \param sig destination buffer.
686 * \return the signature length (in bytes), or 0 on error.
687 */
688 size_t br_ecdsa_i15_sign_raw(const br_ec_impl *impl,
689 const br_hash_class *hf, const void *hash_value,
690 const br_ec_private_key *sk, void *sig);
691
692 /**
693 * \brief ECDSA signature verifier, "i15" implementation, "asn1" format.
694 *
695 * \see br_ecdsa_vrfy()
696 *
697 * \param impl EC implementation to use.
698 * \param hash signed data (hashed).
699 * \param hash_len hash value length (in bytes).
700 * \param pk EC public key.
701 * \param sig signature.
702 * \param sig_len signature length (in bytes).
703 * \return 1 on success, 0 on error.
704 */
705 uint32_t br_ecdsa_i15_vrfy_asn1(const br_ec_impl *impl,
706 const void *hash, size_t hash_len,
707 const br_ec_public_key *pk, const void *sig, size_t sig_len);
708
709 /**
710 * \brief ECDSA signature verifier, "i15" implementation, "raw" format.
711 *
712 * \see br_ecdsa_vrfy()
713 *
714 * \param impl EC implementation to use.
715 * \param hash signed data (hashed).
716 * \param hash_len hash value length (in bytes).
717 * \param pk EC public key.
718 * \param sig signature.
719 * \param sig_len signature length (in bytes).
720 * \return 1 on success, 0 on error.
721 */
722 uint32_t br_ecdsa_i15_vrfy_raw(const br_ec_impl *impl,
723 const void *hash, size_t hash_len,
724 const br_ec_public_key *pk, const void *sig, size_t sig_len);
725
726 #endif