Skip to content
This repository was archived by the owner on Jan 24, 2023. It is now read-only.

Commit 26473dc

Browse files
committed
Add options to use blank external dependencies
This commit makes external dependencies unnecessary when `WITH_BLANK_EXTERNAL_DEPENDENCIES` is specified. It is useful in some restricted environments (e.g. webassembly) or in some specific applications (e.g. deterministic signature generation).
1 parent aa5cf60 commit 26473dc

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,8 @@ compiler is not gcc/clang compatible, the user can modify the CFLAGS as well as
693693
for 8-bit MCUs to 64-bit CPUs. If the toolchain does not have a [`stdint.h`](http://pubs.opengroup.org/onlinepubs/009695399/basedefs/stdint.h.html)
694694
header, it is still possible to compile libecc by exporting LIBECC_NOSTDLIB=1: in this case, the code will try to
695695
guess and fit to native C types or throw an error so that the user can adapt [src/words/types.h](src/words/types.h) to its specific case.
696-
* The library core is platform independent. However, when the platform is not recognized (i.e. everything aside UNIX/Windows/Mac OS),
696+
* The library core is platform independent. However, when the platform is not recognized (i.e. everything aside UNIX/Windows/Mac OS)
697+
and when not compiled with `WITH_BLANK_EXTERNAL_DEPENDENCIES` specified,
697698
an error is thrown at compilation time asking the user to provide implementations for **external dependencies**
698699
in [src/external_deps/](src/external_deps), namely:
699700
* The printing helper in [src/external_deps/print.c](src/external_deps/print.c). This helper serves output debugging purposes.
@@ -703,6 +704,10 @@ in [src/external_deps/](src/external_deps), namely:
703704
schemes. One should notice that a **good random source** is **crucial** for the security of Elliptic Curve based signature schemes,
704705
so great care must be taken when implementing this.
705706

707+
If `WITH_BLANK_EXTERNAL_DEPENDENCIES` is specified in compiling time, blank implementation for these helpers are provided.
708+
As the random helper does not really generate random bits, this may be dangerous. They are provided
709+
because it is useful in some restricted environments or in some specific applications (e.g. deterministic signature generation).
710+
706711
Some other external dependencies could arise depending on the compilation chain and/or the platform. Such an example is the
707712
implementation of the gcc and clang stack protection option, usually expecting the user to provide stack canaries generation
708713
(with random values) and failover behavior.
@@ -890,7 +895,8 @@ other compilers (`-c` flag to generate object files, `-o` flag to define output
890895
[partially implemented](http://sdcc.sourceforge.net/mediawiki/index.php/Standard_compliance).
891896
* The compiler has "exotic" targets such as the Zilog Z80 MCU.
892897

893-
We suppose that the user has also provided the **external dependencies** for print, random and time
898+
Unless compiling with `WITH_BLANK_EXTERNAL_DEPENDENCIES` specified (which can be dangerous),
899+
we suppose that the user has also provided the **external dependencies** for print, random and time
894900
functions (otherwise explicit errors will be thrown by #error directives).
895901

896902
We will show how overloading the Makefile flags can be of use in this case. Say that we want

src/external_deps/print.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ void ext_printf(const char *format, ...)
2626
vprintf(format, arglist);
2727
va_end(arglist);
2828
}
29+
30+
#elif defined(WITH_BLANK_EXTERNAL_DEPENDENCIES)
31+
void ext_printf(const char *_format, ...) {}
32+
2933
#else
3034
#error "print.c: you have to implement ext_printf"
3135
#endif

src/external_deps/rand.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ int get_random(unsigned char *buf, u16 len)
106106
return ret;
107107
}
108108

109+
#elif defined(WITH_BLANK_EXTERNAL_DEPENDENCIES)
110+
int get_random(unsigned char *buf, u16 len) {
111+
for (int i = 0; i < len; i++) {
112+
buf[i] = 0;
113+
}
114+
return 0;
115+
}
116+
109117
/* No platform detected, the user must provide an implementation! */
110118
#else
111119
/* WARNING: when providing/implementing the get_random function, one must:

src/external_deps/time.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ int get_ms_time(u64 *time)
6666
return ret;
6767
}
6868

69+
#elif defined(WITH_BLANK_EXTERNAL_DEPENDENCIES)
70+
int get_ms_time(u64 *time) {
71+
*time = 0;
72+
return 0;
73+
}
74+
6975
/* No platform detected, the used must provide an implementation! */
7076
#else
7177
#error "time.c: you have to implement get_ms_time()"

0 commit comments

Comments
 (0)