supercop.ts

cross-compiled javascript implementation of ed25519 based on supercop-ref10
git clone git://git.finwo.net/lib/supercop.ts
Log | Files | Refs | README | LICENSE

commit 86cbb50375aa5d382275f1130c9d429e28132d1d
parent 16f001200e862bc4c7a76ee686f7347ad98bb058
Author: finwo <finwo@pm.me>
Date:   Wed, 11 Sep 2019 16:31:23 +0200

More libc functions

Diffstat:
Mlib/c/malloc.c | 5+++++
Alib/c/memcmp.c | 16++++++++++++++++
Alib/c/memcpy.c | 13+++++++++++++
Mlib/c/memset.c | 5+++++
Alib/c/null.c | 3+++
5 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/lib/c/malloc.c b/lib/c/malloc.c @@ -1,6 +1,11 @@ + extern unsigned char __heap_base; unsigned int bump_pointer = &__heap_base; + +// TODO: realloc +// TODO: free + void* malloc(int n) { unsigned int r = bump_pointer; bump_pointer += n; diff --git a/lib/c/memcmp.c b/lib/c/memcmp.c @@ -0,0 +1,16 @@ +#ifndef __MEMCMP_C__ +#define __MEMCMP_C__ + +int memcmp (const void *str1, const void *str2, int count) { + const unsigned char *s1 = str1; + const unsigned char *s2 = str2; + + while (count-- > 0) + { + if (*s1++ != *s2++) + return s1[-1] < s2[-1] ? -1 : 1; + } + return 0; +} + +#endif // __MEMCMP_C__ diff --git a/lib/c/memcpy.c b/lib/c/memcpy.c @@ -0,0 +1,13 @@ +#ifndef __MEMCPY_C__ +#define __MEMCPY_C__ + +void * memcpy (void *dest, const void *src, int len) +{ + char *d = dest; + const char *s = src; + while (len--) + *d++ = *s++; + return dest; +} + +#endif // __MEMCPY_C__ diff --git a/lib/c/memset.c b/lib/c/memset.c @@ -1,6 +1,11 @@ +#ifndef __MEMSET_C__ +#define __MEMSET_C__ + void * memset (void *dest, int val, int len) { unsigned char *ptr = dest; while (len-- > 0) *ptr++ = val; return dest; } + +#endif // __MEMSET_C__ diff --git a/lib/c/null.c b/lib/c/null.c @@ -0,0 +1,3 @@ +#ifndef NULL +#define NULL ((void*)0) +#endif