xref: /freebsd/crypto/libecc/include/libecc/curves/prj_pt.h (revision f0865ec9906d5a18fa2a3b61381f22ce16e606ad)
1 /*
2  *  Copyright (C) 2017 - This file is part of libecc project
3  *
4  *  Authors:
5  *      Ryad BENADJILA <ryadbenadjila@gmail.com>
6  *      Arnaud EBALARD <arnaud.ebalard@ssi.gouv.fr>
7  *      Jean-Pierre FLORI <jean-pierre.flori@ssi.gouv.fr>
8  *
9  *  Contributors:
10  *      Nicolas VIVET <nicolas.vivet@ssi.gouv.fr>
11  *      Karim KHALFALLAH <karim.khalfallah@ssi.gouv.fr>
12  *
13  *  This software is licensed under a dual BSD and GPL v2 license.
14  *  See LICENSE file at the root folder of the project.
15  */
16 #ifndef __PRJ_PT_H__
17 #define __PRJ_PT_H__
18 
19 #include <libecc/nn/nn_mul_public.h>
20 #include <libecc/fp/fp.h>
21 #include <libecc/fp/fp_mul.h>
22 #include <libecc/fp/fp_mul_redc1.h>
23 #include <libecc/curves/ec_shortw.h>
24 #include <libecc/curves/aff_pt.h>
25 
26 typedef struct {
27 	fp X;
28 	fp Y;
29 	fp Z;
30 	ec_shortw_crv_src_t crv;
31 	word_t magic;
32 } prj_pt;
33 
34 typedef prj_pt *prj_pt_t;
35 typedef const prj_pt *prj_pt_src_t;
36 
37 typedef enum {
38 	PUBLIC_PT = 0,
39 	PRIVATE_PT = 1
40 } prj_pt_sensitivity;
41 
42 ATTRIBUTE_WARN_UNUSED_RET int prj_pt_check_initialized(prj_pt_src_t in);
43 ATTRIBUTE_WARN_UNUSED_RET int prj_pt_init(prj_pt_t in, ec_shortw_crv_src_t curve);
44 ATTRIBUTE_WARN_UNUSED_RET int prj_pt_init_from_coords(prj_pt_t in,
45 			    ec_shortw_crv_src_t curve,
46 			    fp_src_t xcoord,
47 			    fp_src_t ycoord, fp_src_t zcoord);
48 void prj_pt_uninit(prj_pt_t in);
49 ATTRIBUTE_WARN_UNUSED_RET int prj_pt_zero(prj_pt_t out);
50 ATTRIBUTE_WARN_UNUSED_RET int prj_pt_iszero(prj_pt_src_t in, int *iszero);
51 ATTRIBUTE_WARN_UNUSED_RET int prj_pt_is_on_curve(prj_pt_src_t in, int *on_curve);
52 ATTRIBUTE_WARN_UNUSED_RET int prj_pt_copy(prj_pt_t out, prj_pt_src_t in);
53 ATTRIBUTE_WARN_UNUSED_RET int prj_pt_to_aff(aff_pt_t out, prj_pt_src_t in);
54 ATTRIBUTE_WARN_UNUSED_RET int prj_pt_unique(prj_pt_t out, prj_pt_src_t in);
55 ATTRIBUTE_WARN_UNUSED_RET int ec_shortw_aff_to_prj(prj_pt_t out, aff_pt_src_t in);
56 ATTRIBUTE_WARN_UNUSED_RET int prj_pt_cmp(prj_pt_src_t in1, prj_pt_src_t in2, int *cmp);
57 ATTRIBUTE_WARN_UNUSED_RET int prj_pt_eq_or_opp(prj_pt_src_t in1, prj_pt_src_t in2, int *eq_or_opp);
58 ATTRIBUTE_WARN_UNUSED_RET int prj_pt_neg(prj_pt_t out, prj_pt_src_t in);
59 ATTRIBUTE_WARN_UNUSED_RET int prj_pt_add(prj_pt_t sum, prj_pt_src_t in1, prj_pt_src_t in2);
60 ATTRIBUTE_WARN_UNUSED_RET int prj_pt_dbl(prj_pt_t dbl, prj_pt_src_t in);
61 ATTRIBUTE_WARN_UNUSED_RET int prj_pt_mul(prj_pt_t out, nn_src_t m, prj_pt_src_t in);
62 ATTRIBUTE_WARN_UNUSED_RET int prj_pt_mul_blind(prj_pt_t out, nn_src_t m, prj_pt_src_t in);
63 /* XXX: WARNING: this function must only be used on public points! */
64 ATTRIBUTE_WARN_UNUSED_RET int _prj_pt_unprotected_mult(prj_pt_t out, nn_src_t cofactor, prj_pt_src_t public_in);
65 ATTRIBUTE_WARN_UNUSED_RET int check_prj_pt_order(prj_pt_src_t in_shortw, nn_src_t in_isorder, prj_pt_sensitivity s, int *check);
66 ATTRIBUTE_WARN_UNUSED_RET int prj_pt_import_from_buf(prj_pt_t pt,
67 			   const u8 *pt_buf,
68 			   u16 pt_buf_len, ec_shortw_crv_src_t crv);
69 ATTRIBUTE_WARN_UNUSED_RET int prj_pt_import_from_aff_buf(prj_pt_t pt,
70 			   const u8 *pt_buf,
71 			   u16 pt_buf_len, ec_shortw_crv_src_t crv);
72 ATTRIBUTE_WARN_UNUSED_RET int prj_pt_export_to_buf(prj_pt_src_t pt, u8 *pt_buf, u32 pt_buf_len);
73 ATTRIBUTE_WARN_UNUSED_RET int prj_pt_export_to_aff_buf(prj_pt_src_t pt, u8 *pt_buf, u32 pt_buf_len);
74 ATTRIBUTE_WARN_UNUSED_RET int aff_pt_edwards_to_prj_pt_shortw(aff_pt_edwards_src_t in_edwards,
75 				    ec_shortw_crv_src_t shortw_crv,
76 				    prj_pt_t out_shortw, fp_src_t alpha);
77 ATTRIBUTE_WARN_UNUSED_RET int aff_pt_montgomery_to_prj_pt_shortw(aff_pt_montgomery_src_t in_montgomery,
78 				       ec_shortw_crv_src_t shortw_crv,
79 				       prj_pt_t out_shortw);
80 ATTRIBUTE_WARN_UNUSED_RET int prj_pt_shortw_to_aff_pt_edwards(prj_pt_src_t in_shortw,
81 				    ec_edwards_crv_src_t edwards_crv,
82 				    aff_pt_edwards_t out_edwards,
83 				    fp_src_t alpha);
84 ATTRIBUTE_WARN_UNUSED_RET int prj_pt_shortw_to_aff_pt_montgomery(prj_pt_src_t in_shortw,
85 				       ec_montgomery_crv_src_t montgomery_crv,
86 				       aff_pt_montgomery_t out_montgomery);
87 
88 #endif /* __PRJ_PT_H__ */
89