1 /*
2  * Copyright (c) 2021-2023, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * *  Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * *  Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * *  Neither the name of Texas Instruments Incorporated nor the names of
17  *    its contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include <stdint.h>
34 
35 #include <ti/drivers/cryptoutils/ecc/ECCInitLPF3SW.h>
36 #include <ti/drivers/cryptoutils/ecc/ECCParams.h>
37 
38 #include <third_party/ecc/include/ECCSW.h>
39 
40 /*
41  *  ======== ECCInitLPF3SW_NISTP256 ========
42  */
ECCInitLPF3SW_NISTP256(ECC_State * state,uint8_t windowSize,uint32_t * workZone)43 void ECCInitLPF3SW_NISTP256(ECC_State *state, uint8_t windowSize, uint32_t *workZone)
44 {
45     state->data_Gx     = ECC_NISTP256_generatorX.word;
46     state->data_Gy     = ECC_NISTP256_generatorY.word;
47     state->data_p      = ECC_NISTP256_prime.word;
48     state->data_r      = ECC_NISTP256_order.word;
49     state->data_a      = ECC_NISTP256_a.word;
50     state->data_b      = ECC_NISTP256_b.word;
51     state->data_a_mont = ECC_NISTP256_a_mont.word;
52     state->data_b_mont = ECC_NISTP256_b_mont.word;
53     state->data_k_mont = ECC_NISTP256_k_mont.word;
54     state->win         = windowSize;
55 
56     state->workzone = workZone;
57 }
58 
59 /*
60  *  ======== ECCInitLPF3SW_NISTP224 ========
61  */
ECCInitLPF3SW_NISTP224(ECC_State * state,uint8_t windowSize,uint32_t * workZone)62 void ECCInitLPF3SW_NISTP224(ECC_State *state, uint8_t windowSize, uint32_t *workZone)
63 {
64     state->data_Gx     = ECC_NISTP224_generatorX.word;
65     state->data_Gy     = ECC_NISTP224_generatorY.word;
66     state->data_p      = ECC_NISTP224_prime.word;
67     state->data_r      = ECC_NISTP224_order.word;
68     state->data_a      = ECC_NISTP224_a.word;
69     state->data_b      = ECC_NISTP224_b.word;
70     state->data_a_mont = ECC_NISTP224_a_mont.word;
71     state->data_b_mont = ECC_NISTP224_b_mont.word;
72     state->data_k_mont = ECC_NISTP224_k_mont.word;
73     state->win         = windowSize;
74 
75     state->workzone = workZone;
76 }
77 
78 /*
79  *  ======== ECCInitLPF3SW_Curve25519 ========
80  */
ECCInitLPF3SW_Curve25519(ECC_State * state,uint8_t windowSize,uint32_t * workZone)81 void ECCInitLPF3SW_Curve25519(ECC_State *state, uint8_t windowSize, uint32_t *workZone)
82 {
83     state->data_Gx     = ECC_Curve25519_generatorX.word;
84     state->data_Gy     = ECC_Curve25519_generatorY.word;
85     state->data_p      = ECC_Curve25519_prime.word;
86     state->data_r      = ECC_Curve25519_order.word;
87     state->data_a      = ECC_Curve25519_a.word;
88     state->data_b      = ECC_Curve25519_b.word;
89     /* The following montgomery curve params are not used for any Curve25519 functions */
90     state->data_a_mont = NULL;
91     state->data_b_mont = NULL;
92     state->data_k_mont = NULL;
93     state->win         = windowSize;
94 
95     state->workzone = workZone;
96 }
97