Contiki-NG
ecc-curve.c
1 /*
2  * Copyright (c) 2014, Institute for Pervasive Computing, ETH Zurich.
3  * All rights reserved.
4  *
5  * Author: Andreas Dröscher <contiki@anticat.ch>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * 2. 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  * 3. Neither the name of the Institute nor the names of its contributors
16  * may be used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  */
31 /**
32  * \addtogroup cc2538-ecc-curves
33  * @{
34  */
35 #include "contiki.h"
36 #include "dev/ecc-driver.h"
37 
38 /* [NIST P-256, X9.62 prime256v1] */
39 static const uint32_t nist_p_256_p[8] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
40  0x00000000, 0x00000000, 0x00000001, 0xFFFFFFFF };
41 static const uint32_t nist_p_256_n[8] = { 0xFC632551, 0xF3B9CAC2, 0xA7179E84, 0xBCE6FAAD,
42  0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF };
43 static const uint32_t nist_p_256_a[8] = { 0xFFFFFFFC, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
44  0x00000000, 0x00000000, 0x00000001, 0xFFFFFFFF };
45 static const uint32_t nist_p_256_b[8] = { 0x27D2604B, 0x3BCE3C3E, 0xCC53B0F6, 0x651D06B0,
46  0x769886BC, 0xB3EBBD55, 0xAA3A93E7, 0x5AC635D8 };
47 static const uint32_t nist_p_256_x[8] = { 0xD898C296, 0xF4A13945, 0x2DEB33A0, 0x77037D81,
48  0x63A440F2, 0xF8BCE6E5, 0xE12C4247, 0x6B17D1F2 };
49 static const uint32_t nist_p_256_y[8] = { 0x37BF51F5, 0xCBB64068, 0x6B315ECE, 0x2BCE3357,
50  0x7C0F9E16, 0x8EE7EB4A, 0xFE1A7F9B, 0x4FE342E2 };
51 
52 ecc_curve_info_t nist_p_256 = {
53  .name = "NIST P-256",
54  .size = 8,
55  .prime = nist_p_256_p,
56  .n = nist_p_256_n,
57  .a = nist_p_256_a,
58  .b = nist_p_256_b,
59  .x = nist_p_256_x,
60  .y = nist_p_256_y
61 };
62 
63 /* [NIST P-192, X9.62 prime192v1] */
64 static const uint32_t nist_p_192_p[6] = { 0xffffffff, 0xffffffff, 0xfffffffe, 0xffffffff,
65  0xffffffff, 0xffffffff };
66 static const uint32_t nist_p_192_a[6] = { 0xfffffffc, 0xffffffff, 0xfffffffe, 0xffffffff,
67  0xffffffff, 0xffffffff };
68 static const uint32_t nist_p_192_b[6] = { 0xc146b9b1, 0xfeb8deec, 0x72243049, 0x0fa7e9ab,
69  0xe59c80e7, 0x64210519 };
70 static const uint32_t nist_p_192_x[6] = { 0x82ff1012, 0xf4ff0afd, 0x43a18800, 0x7cbf20eb,
71  0xb03090f6, 0x188da80e };
72 static const uint32_t nist_p_192_y[6] = { 0x1e794811, 0x73f977a1, 0x6b24cdd5, 0x631011ed,
73  0xffc8da78, 0x07192b95 };
74 static const uint32_t nist_p_192_n[6] = { 0xb4d22831, 0x146bc9b1, 0x99def836, 0xffffffff,
75  0xffffffff, 0xffffffff };
76 
77 ecc_curve_info_t nist_p_192 = {
78  .name = "NIST P-192",
79  .size = 6,
80  .prime = nist_p_192_p,
81  .n = nist_p_192_n,
82  .a = nist_p_192_a,
83  .b = nist_p_192_b,
84  .x = nist_p_192_x,
85  .y = nist_p_192_y
86 };
87 
88 /**
89  * @}
90  * @}
91  */
Header file for the cc2538 ECC driver.