mirror of
https://github.com/kmackay/micro-ecc.git
synced 2026-08-25 19:30:03 +00:00
Code to allow testing on lpc1114 board.
This commit is contained in:
+23
-3
@@ -1,6 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
c, link = emk.module("c", "link")
|
c, link, asm, utils = emk.module("c", "link", "asm", "utils")
|
||||||
|
|
||||||
default_compile_flags = ["-fvisibility=hidden", "-Wall", "-Wextra", "-Wshadow", "-Werror", "-Wno-missing-field-initializers", "-Wno-unused-parameter", \
|
default_compile_flags = ["-fvisibility=hidden", "-Wall", "-Wextra", "-Wshadow", "-Werror", "-Wno-missing-field-initializers", "-Wno-unused-parameter", \
|
||||||
"-Wno-comment", "-Wno-unused", "-Wno-unknown-pragmas"]
|
"-Wno-comment", "-Wno-unused", "-Wno-unknown-pragmas"]
|
||||||
@@ -63,13 +63,33 @@ def setup_avr():
|
|||||||
def setup_arm_thumb():
|
def setup_arm_thumb():
|
||||||
global c
|
global c
|
||||||
global link
|
global link
|
||||||
|
global asm
|
||||||
|
global utils
|
||||||
|
|
||||||
|
asm.assembler = asm.GccAssembler("/cross/arm_cortex/bin/arm-none-eabi-")
|
||||||
c.compiler = c.GccCompiler("/cross/arm_cortex/bin/arm-none-eabi-")
|
c.compiler = c.GccCompiler("/cross/arm_cortex/bin/arm-none-eabi-")
|
||||||
link.linker = link.GccLinker("/cross/arm_cortex/bin/arm-none-eabi-")
|
link.linker = link.GccLinker("/cross/arm_cortex/bin/arm-none-eabi-")
|
||||||
|
|
||||||
c.flags += ["-march=armv6-m", "-mthumb", "-ffunction-sections", "-fdata-sections"]
|
c.flags.extend(["-mcpu=cortex-m0", "-mthumb", "-ffunction-sections", "-fdata-sections", "-fno-builtin-fprintf", "-fno-builtin-printf"])
|
||||||
link.local_flags += ["-march=armv6-m", "-mthumb", "-Wl,--gc-sections"]
|
c.defines["LPC11XX"] = 1
|
||||||
|
|
||||||
|
link.local_flags.extend(["-mcpu=cortex-m0", "-mthumb", "-nostartfiles", "-nostdlib", "-Wl,--gc-sections"])
|
||||||
|
link.local_flags.extend(["-Tflash.lds", "-L/Projects/lpc11xx/core", "/Projects/lpc11xx/core/" + emk.build_dir + "/board_cstartup.o"])
|
||||||
|
link.local_syslibs += ["gcc"]
|
||||||
|
link.depdirs += ["/Projects/lpc11xx/stdlib"]
|
||||||
|
|
||||||
|
def do_objcopy(produces, requires):
|
||||||
|
utils.call("/cross/arm_cortex/bin/arm-none-eabi-objcopy", "-O", "binary", requires[0], produces[0])
|
||||||
|
|
||||||
|
def handle_exe(path):
|
||||||
|
emk.depend(path, "/Projects/lpc11xx/core/" + emk.build_dir + "/board_cstartup.o")
|
||||||
|
emk.rule(do_objcopy, path + ".bin", path, cwd_safe=True, ex_safe=True)
|
||||||
|
emk.autobuild(path + ".bin")
|
||||||
|
|
||||||
|
link.exe_funcs.append(handle_exe)
|
||||||
link.strip = True
|
link.strip = True
|
||||||
|
|
||||||
|
emk.recurse("/Projects/lpc11xx/core")
|
||||||
|
|
||||||
setup_build_dir()
|
setup_build_dir()
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,29 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#if LPC11XX
|
||||||
|
|
||||||
|
#include "/Projects/lpc11xx/peripherals/uart.h"
|
||||||
|
#include "/Projects/lpc11xx/peripherals/time.h"
|
||||||
|
|
||||||
|
static uint64_t g_rand = 88172645463325252ull;
|
||||||
|
int fake_rng(uint8_t *p_dest, unsigned p_size)
|
||||||
|
{
|
||||||
|
while(p_size)
|
||||||
|
{
|
||||||
|
g_rand ^= (g_rand << 13);
|
||||||
|
g_rand ^= (g_rand >> 7);
|
||||||
|
g_rand ^= (g_rand << 17);
|
||||||
|
|
||||||
|
unsigned l_amount = (p_size > 8 ? 8 : p_size);
|
||||||
|
memcpy(p_dest, &g_rand, l_amount);
|
||||||
|
p_size -= l_amount;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
void vli_print(uint8_t *p_vli, unsigned int p_size)
|
void vli_print(uint8_t *p_vli, unsigned int p_size)
|
||||||
{
|
{
|
||||||
while(p_size)
|
while(p_size)
|
||||||
@@ -16,6 +39,13 @@ void vli_print(uint8_t *p_vli, unsigned int p_size)
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
#if LPC11XX
|
||||||
|
uartInit(BAUD_115200);
|
||||||
|
initTime();
|
||||||
|
|
||||||
|
uECC_set_rng(&fake_rng);
|
||||||
|
#endif
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
uint8_t l_private1[uECC_BYTES];
|
uint8_t l_private1[uECC_BYTES];
|
||||||
@@ -32,7 +62,9 @@ int main()
|
|||||||
for(i=0; i<256; ++i)
|
for(i=0; i<256; ++i)
|
||||||
{
|
{
|
||||||
printf(".");
|
printf(".");
|
||||||
|
#if !LPC11XX
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
#endif
|
||||||
|
|
||||||
if(!uECC_make_key(l_public1, l_private1) || !uECC_make_key(l_public2, l_private2))
|
if(!uECC_make_key(l_public1, l_private1) || !uECC_make_key(l_public2, l_private2))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,8 +5,38 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#if LPC11XX
|
||||||
|
|
||||||
|
#include "/Projects/lpc11xx/peripherals/uart.h"
|
||||||
|
#include "/Projects/lpc11xx/peripherals/time.h"
|
||||||
|
|
||||||
|
static uint64_t g_rand = 88172645463325252ull;
|
||||||
|
int fake_rng(uint8_t *p_dest, unsigned p_size)
|
||||||
|
{
|
||||||
|
while(p_size)
|
||||||
|
{
|
||||||
|
g_rand ^= (g_rand << 13);
|
||||||
|
g_rand ^= (g_rand >> 7);
|
||||||
|
g_rand ^= (g_rand << 17);
|
||||||
|
|
||||||
|
unsigned l_amount = (p_size > 8 ? 8 : p_size);
|
||||||
|
memcpy(p_dest, &g_rand, l_amount);
|
||||||
|
p_size -= l_amount;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
#if LPC11XX
|
||||||
|
uartInit(BAUD_115200);
|
||||||
|
initTime();
|
||||||
|
|
||||||
|
uECC_set_rng(&fake_rng);
|
||||||
|
#endif
|
||||||
|
|
||||||
uint8_t l_public[uECC_BYTES*2];
|
uint8_t l_public[uECC_BYTES*2];
|
||||||
uint8_t l_private[uECC_BYTES];
|
uint8_t l_private[uECC_BYTES];
|
||||||
|
|
||||||
@@ -21,7 +51,9 @@ int main()
|
|||||||
for(i=0; i<256; ++i)
|
for(i=0; i<256; ++i)
|
||||||
{
|
{
|
||||||
printf(".");
|
printf(".");
|
||||||
|
#if !LPC11XX
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
#endif
|
||||||
|
|
||||||
if(!uECC_make_key(l_public, l_private))
|
if(!uECC_make_key(l_public, l_private))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user