Skip to content

Commit 1015fe5

Browse files
committed
Merge pull request #44 from emargolis/master
Added support for new secp224r1 curve.
2 parents 8674d47 + ac89ddc commit 1015fe5

5 files changed

Lines changed: 400 additions & 31 deletions

File tree

asm_arm.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#define DEC_5 4
22
#define DEC_6 5
3+
#define DEC_7 6
34
#define DEC_8 7
45

56
#define DEC(N) uECC_CONCAT(DEC_, N)

asm_avr.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#define DEC_20 19
22
#define DEC_24 23
3+
#define DEC_28 27
34
#define DEC_32 31
45

56
#define DEC(N) uECC_CONCAT(DEC_, N)

test/test_compress.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/* Copyright 2014, Kenneth MacKay. Licensed under the BSD 2-clause license. */
2+
3+
#include "uECC.h"
4+
5+
#include <stdio.h>
6+
#include <string.h>
7+
8+
#ifndef uECC_TEST_NUMBER_OF_ITERATIONS
9+
#define uECC_TEST_NUMBER_OF_ITERATIONS 256
10+
#endif
11+
12+
#if LPC11XX
13+
14+
#include "/Projects/lpc11xx/peripherals/uart.h"
15+
#include "/Projects/lpc11xx/peripherals/time.h"
16+
17+
static uint64_t g_rand = 88172645463325252ull;
18+
int fake_rng(uint8_t *dest, unsigned size) {
19+
while(size) {
20+
g_rand ^= (g_rand << 13);
21+
g_rand ^= (g_rand >> 7);
22+
g_rand ^= (g_rand << 17);
23+
24+
unsigned amount = (size > 8 ? 8 : size);
25+
memcpy(dest, &g_rand, amount);
26+
dest += amount;
27+
size -= amount;
28+
}
29+
return 1;
30+
}
31+
32+
#endif
33+
34+
void vli_print(char *str, uint8_t *vli, unsigned int size) {
35+
printf("%s ", str);
36+
while (size) {
37+
printf("%02X ", (unsigned)vli[size - 1]);
38+
--size;
39+
}
40+
printf("\n");
41+
}
42+
43+
int main() {
44+
#if LPC11XX
45+
uartInit(BAUD_115200);
46+
initTime();
47+
48+
uECC_set_rng(&fake_rng);
49+
#endif
50+
51+
uint8_t public[uECC_BYTES * 2];
52+
uint8_t private[uECC_BYTES];
53+
uint8_t compressed_point[uECC_BYTES + 1];
54+
uint8_t decompressed_point[uECC_BYTES * 2];
55+
56+
int i;
57+
printf("Testing compression and decompression of %d random EC points\n", uECC_TEST_NUMBER_OF_ITERATIONS);
58+
59+
for (i = 0; i < uECC_TEST_NUMBER_OF_ITERATIONS; ++i) {
60+
printf(".");
61+
#if !LPC11XX
62+
fflush(stdout);
63+
#endif
64+
65+
/* Generate arbitrary EC point (public) on Curve */
66+
if (!uECC_make_key(public, private)) {
67+
printf("uECC_make_key() failed\n");
68+
continue;
69+
}
70+
71+
/* compress and decompress point */
72+
uECC_compress(public, compressed_point);
73+
uECC_decompress(compressed_point, decompressed_point);
74+
75+
if (memcmp(public, decompressed_point, 2 * uECC_BYTES) != 0) {
76+
printf("Original and decompressed points are not identical!\n");
77+
vli_print("Original point = ", public, 2 * uECC_BYTES);
78+
vli_print("Compressed point = ", compressed_point, uECC_BYTES + 1);
79+
vli_print("Decompressed point = ", decompressed_point, 2 * uECC_BYTES);
80+
}
81+
}
82+
printf("\n");
83+
84+
return 0;
85+
}

0 commit comments

Comments
 (0)