]> git.cryptolib.org Git - avr-crypto-lib.git/blob - ecdsa/ecc.h
new and more compact aes
[avr-crypto-lib.git] / ecdsa / ecc.h
1 /* ecc.h */
2 /*
3     This file is part of the AVR-Crypto-Lib.
4     Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org)
5
6     This program is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef ECC_H_
21 #define ECC_H_
22
23 #include <stddef.h>
24
25 typedef struct {
26     bigint_t x;
27     bigint_t y;
28     bigint_t z1;
29     bigint_t z2;
30     bigint_t z3;
31 } ecc_chudnovsky_point_t;
32
33 typedef struct {
34     bigint_t x;
35     bigint_t y;
36 } ecc_affine_point_t;
37
38 typedef union __attribute__((packed)){
39     ecc_affine_point_t affine;
40     ecc_chudnovsky_point_t chudnovsky;
41 } ecc_combi_point_t;
42
43 typedef struct {
44     bigint_t *p;
45     bigint_t *n;
46     bigint_t *b;
47     int (*reduce_p)(bigint_t*);
48 } ecc_curve_sp_t;
49
50
51 uint8_t ecc_chudnovsky_point_alloc(ecc_chudnovsky_point_t *p, size_t length_B);
52
53 void ecc_chudnovsky_point_free(ecc_chudnovsky_point_t *p);
54
55 void ecc_chudnovsky_point_print(const ecc_chudnovsky_point_t *p);
56
57
58 uint8_t ecc_affine_to_chudnovsky_point(ecc_chudnovsky_point_t *dest,
59                                        const ecc_affine_point_t *src);
60 uint8_t ecc_chudnovsky_to_affine_point(ecc_affine_point_t *dest,
61                                        const ecc_chudnovsky_point_t *src,
62                                        const ecc_curve_sp_t *curve);
63 uint8_t ecc_chudnovsky_point_double_sp(ecc_chudnovsky_point_t *dest,
64                                        const ecc_chudnovsky_point_t *a,
65                                        const ecc_curve_sp_t *curve);
66 void ecc_chudnovsky_point_copy(ecc_chudnovsky_point_t *dest,
67                                const ecc_chudnovsky_point_t *src);
68 uint8_t ecc_chudnovsky_point_add_sp(ecc_chudnovsky_point_t *dest,
69                                     const ecc_chudnovsky_point_t *a,
70                                     const ecc_chudnovsky_point_t *b,
71                                     const ecc_curve_sp_t *curve);
72 uint8_t ecc_chudnovsky_double_and_add(ecc_chudnovsky_point_t *dest,
73                                       const bigint_t *k,
74                                       const ecc_chudnovsky_point_t *p,
75                                       const ecc_curve_sp_t *curve);
76 uint8_t bigint_to_naf(uint8_t *dest, uint16_t *length, const bigint_t *src);
77 uint8_t ecc_chudnovsky_naf_multiplication(ecc_chudnovsky_point_t *dest,
78                                           const bigint_t *k,
79                                           const ecc_chudnovsky_point_t *p,
80                                           const ecc_curve_sp_t *curve);
81 uint8_t ecc_chudnovsky_multiplication(ecc_chudnovsky_point_t *dest,
82                                       const bigint_t *k,
83                                       const ecc_chudnovsky_point_t *p,
84                                       const ecc_curve_sp_t *curve);
85
86 #endif /* ECC_H_ */