1 /*
2  * Copyright (c) 2009 Chris K Cockrum <ckc@cockrum.net>
3  *
4  * Copyright (c) 2013 Jens Trillmann <jtrillma@tzi.de>
5  * Copyright (c) 2013 Marc Müller-Weinhardt <muewei@tzi.de>
6  * Copyright (c) 2013 Lars Schmertmann <lars@tzi.de>
7  * Copyright (c) 2013 Hauke Mehrtens <hauke@hauke-m.de>
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy
10  * of this software and associated documentation files (the "Software"), to deal
11  * in the Software without restriction, including without limitation the rights
12  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13  * copies of the Software, and to permit persons to whom the Software is
14  * furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included in
17  * all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25  * THE SOFTWARE.
26  *
27  *
28  * This implementation is based in part on the paper Implementation of an
29  * Elliptic Curve Cryptosystem on an 8-bit Microcontroller [0] by
30  * Chris K Cockrum <ckc@cockrum.net>.
31  *
32  * [0]: http://cockrum.net/Implementation_of_ECC_on_an_8-bit_microcontroller.pdf
33  *
34  * This is a efficient ECC implementation on the secp256r1 curve for 32 Bit CPU
35  * architectures. It provides basic operations on the secp256r1 curve and support
36  * for ECDH and ECDSA.
37  */
38 #include "test_helper.h"
39 #include "ecc.h"
40 #include <string.h>
41 #include <stdio.h>
42 #include <stdlib.h>
43 
ecc_printNumber(const uint32_t * x,int numberLength)44 void ecc_printNumber(const uint32_t *x, int numberLength){ //here the values are turned to MSB!
45 	int n;
46 
47 	for(n = numberLength - 1; n >= 0; n--){
48 		printf("%08x", x[n]);
49 	}
50 	printf("\n");
51 }
52 
ecc_setRandom(uint32_t * secret)53 void ecc_setRandom(uint32_t *secret){
54 	int i;
55 
56 	for (i = 0; i < arrayLength; ++i)
57 	{
58 		secret[i] = rand();
59 	}
60 }
61 const uint32_t ecc_prime_m[8] = {0xffffffff, 0xffffffff, 0xffffffff, 0x00000000,
62 				 0x00000000, 0x00000000, 0x00000001, 0xffffffff};
63 
64 
65 /* This is added after an static byte addition if the answer has a carry in MSB*/
66 const uint32_t ecc_prime_r[8] = {0x00000001, 0x00000000, 0x00000000, 0xffffffff,
67 				 0xffffffff, 0xffffffff, 0xfffffffe, 0x00000000};
68 
69 #ifdef CONTIKI
70 void
test_assert(const char * file,int lineno)71 test_assert(const char *file, int lineno)
72 {
73   printf("Assertion failed: file %s, line %d.\n", file, lineno);
74   /*
75    * loop for a while;
76    * call _reset_vector__();
77    */
78 }
79 #endif
80