Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
caa3d0a
Refactored Ada binding. Separated code that depends upon Interfaces.C…
joakim-strandberg Nov 20, 2025
053bfaa
Added Ada binding for the SHA256 implementation in the Wolfssl library.
joakim-strandberg Dec 2, 2025
e25db30
Saving work in progress on RSA signature verification.
joakim-strandberg Dec 7, 2025
714deb4
Removed errors resulting from violation of restriction No Secondary S…
joakim-strandberg Dec 9, 2025
a175045
Silenced many warnings related to no exception propagation for zero f…
joakim-strandberg Dec 11, 2025
7237743
Saving work in progress on RSA example.
joakim-strandberg Dec 17, 2025
f756214
Rsa example can now digitaly sign and verify digital signatures.
joakim-strandberg Dec 19, 2025
5bcb103
RSA example complete.
joakim-strandberg Dec 20, 2025
3ac9a5b
Started work on AES example.
joakim-strandberg Dec 21, 2025
367c359
Add AUnit SHA256 binding tests for Ada wrapper
julek-wolfssl Dec 22, 2025
1c39528
Add AUnit RSA sign/verify tests and clean up Ada tests warnings
julek-wolfssl Dec 22, 2025
b7ccc76
Add basic AUnit AES CBC tests
julek-wolfssl Dec 23, 2025
258a71b
Ada tests: statically allocate suites and runner
julek-wolfssl Dec 23, 2025
630ff05
Ada tests: add valgrind suppressions for AUnit leaks
julek-wolfssl Dec 23, 2025
bdc07a3
Ada tests: statically allocate AES suites
julek-wolfssl Dec 23, 2025
a98899f
Ada tests: drop Build_Once and register suites at elaboration
julek-wolfssl Dec 23, 2025
9c246e1
Ada tests: simplify harness and reduce boilerplate
julek-wolfssl Dec 23, 2025
b2b1bde
Ada: allocate SHA256 with malloc and add Free_SHA256
julek-wolfssl Dec 23, 2025
b303106
Ada: allocate RNG with wc_rng_new and add Free_RNG
julek-wolfssl Dec 23, 2025
ae1d743
Ada: allocate RSA with wc_NewRsaKey and add Free_RSA
julek-wolfssl Dec 23, 2025
cebc4e8
Ada: allocate AES with wc_AesNew and free with wc_AesDelete
julek-wolfssl Dec 23, 2025
52359de
Ada tests: fix warnings (redundant with, style spacing)
julek-wolfssl Dec 23, 2025
05e9549
Ada: document test running with valgrind and using gprbuild/gprclean …
julek-wolfssl Dec 23, 2025
0cd0210
CI: add Ada AUnit tests
julek-wolfssl Dec 23, 2025
bc77f7c
Ada: allow older aunit
julek-wolfssl Dec 29, 2025
2c60c96
Ada: add Post conditions for Free_*
julek-wolfssl Dec 29, 2025
f341065
Ada: document possible source of dependency error
julek-wolfssl Dec 30, 2025
44193d9
Ada: add GNATprove ownership annotations
julek-wolfssl Dec 29, 2025
04c495e
Ada: GNATprove is clean on examples.gpr
julek-wolfssl Dec 30, 2025
3794d70
Ada: move examples to sub-directory
julek-wolfssl Dec 31, 2025
5874be0
Ada: fix wrapper/Ada after moving examples
julek-wolfssl Dec 31, 2025
22a7ea9
Ada: fix examples after move
julek-wolfssl Dec 31, 2025
0213170
Ada: update include.am
julek-wolfssl Dec 31, 2025
9670234
Ada: update examples executables
julek-wolfssl Dec 31, 2025
597e633
Ada: update readme
julek-wolfssl Dec 31, 2025
972ee56
Ada: fix the client-server examples
julek-wolfssl Dec 31, 2025
039e08b
Ada: add examples to ada.yml
julek-wolfssl Dec 31, 2025
d8511f8
Ada: leverage gnatprove to track memory
julek-wolfssl Dec 31, 2025
56ac0a6
Ada: fix length proofs in gnatprove
julek-wolfssl Jan 5, 2026
b0fea88
Ada: add gnatprove to CI
julek-wolfssl Jan 6, 2026
6f11509
Ada: update editorconfig
julek-wolfssl Jan 6, 2026
9a07720
Ada: update gitignore to match others
julek-wolfssl Jan 6, 2026
ac2c7e5
Ada: fix default.gpr
julek-wolfssl Jan 6, 2026
515c8e6
Ada: build default.gpr in CI
julek-wolfssl Jan 6, 2026
7ac2700
Ada: fix tls_client call in CI
julek-wolfssl Jan 6, 2026
56d6d28
Ada: use XMALLOC and XFREE for dynamic allocation
julek-wolfssl Jan 8, 2026
b533ac8
Ada wrapper: update .gitignore tracking, clarify RNG comment, remove …
julek-wolfssl Jan 8, 2026
22b98bc
Ada: `RNG_Key_Type` => `RNG_Type`
julek-wolfssl Jan 20, 2026
23a937f
Ada: Use `nul` for clarity
julek-wolfssl Jan 20, 2026
c36e33b
Ada: Remove `Text` from `Finalize_SHA256`
julek-wolfssl Jan 20, 2026
af9086a
Ada: fix typo
julek-wolfssl Jan 22, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{ads,adb,gpr}]
indent_size = 3
65 changes: 52 additions & 13 deletions .github/workflows/ada.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,59 @@ jobs:
steps:
- uses: actions/checkout@master

- name: Install gnat
- name: Install alire
uses: alire-project/setup-alire@v5

- name: Install wolfssl Ada
working-directory: ./wrapper/Ada
run: alr install

- name: Build default.gpr
working-directory: ./wrapper/Ada
run: alr exec -- gprbuild default.gpr -j$(nproc)

- name: Run Ada wrapper tests
working-directory: ./wrapper/Ada/tests
run: alr run

- name: Run Ada examples
id: examples
working-directory: ./wrapper/Ada/examples
run: |
sudo apt-get update
sudo apt-get install -y gnat gprbuild
alr build

echo "Running sha256_main example..."
alr run sha256_main

- name: Checkout wolfssl
uses: actions/checkout@master
with:
repository: wolfssl/wolfssl
path: wolfssl
echo "Running aes_verify_main example..."
alr run aes_verify_main

- name: Build wolfssl Ada
working-directory: ./wolfssl/wrapper/Ada
echo "Running rsa_verify_main example..."
alr run rsa_verify_main

echo "Running TLS server/client example..."
alr run tls_server_main &> server.log &
SERVER_PID=$!
sleep 1
echo "test message" | alr run tls_client_main --args=127.0.0.1
kill $SERVER_PID || true

- name: show errors
if: ${{ failure() && steps.examples.outcome == 'failure' }}
run: cat ./wrapper/Ada/examples/server.log

- name: Run Ada wrapper tests (valgrind)
working-directory: ./wrapper/Ada/tests
run: |
mkdir obj
gprbuild default.gpr
gprbuild examples.gpr
sudo apt-get update
sudo apt-get install -y valgrind
valgrind --leak-check=full --error-exitcode=1 \
--suppressions=valgrind.supp ./bin/tests

- name: Run gnatprove on wolfssl
working-directory: ./wrapper/Ada
run: alr gnatprove --level=4 -P wolfssl.gpr -j 0 --warnings=error --checks-as-errors --proof-warnings -U

- name: Run gnatprove on examples
working-directory: ./wrapper/Ada/examples
run: alr gnatprove --level=4 -P examples.gpr -j 0 --warnings=error --checks-as-errors --proof-warnings -U
1 change: 1 addition & 0 deletions wolfssl/wolfcrypt/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,7 @@ enum {
DYNAMIC_TYPE_X509_ACERT = 103,
DYNAMIC_TYPE_OS_BUF = 104,
DYNAMIC_TYPE_ASCON = 105,
DYNAMIC_TYPE_SHA = 106,
DYNAMIC_TYPE_SNIFFER_SERVER = 1000,
DYNAMIC_TYPE_SNIFFER_SESSION = 1001,
DYNAMIC_TYPE_SNIFFER_PB = 1002,
Expand Down
5 changes: 4 additions & 1 deletion wrapper/Ada/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
obj
/obj/
/bin/
/alire/
/config/
40 changes: 31 additions & 9 deletions wrapper/Ada/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ been developed with maximum portability in mind.
Not only can the WolfSSL Ada binding be used in Ada applications but
also SPARK applications (a subset of the Ada language suitable for
formal verification). To formally verify the Ada code in this repository
open the examples.gpr with GNAT Studio and then select
open the examples/examples.gpr with GNAT Studio and then select
SPARK -> Prove All Sources and use Proof Level 2. Or when using the command
line, use `gnatprove -Pexamples.gpr --level=4 -j12` (`-j12` is there in
line, use `gnatprove -Pexamples/examples.gpr --level=4 -j12` (`-j12` is there in
order to instruct the prover to use 12 CPUs if available).

```
Expand Down Expand Up @@ -62,6 +62,8 @@ ecosystem. The latest version is available for Windows, OSX, Linux and FreeBSD
systems. It can install a complete Ada toolchain if needed, see `alr install`
for more information.

**Note:** If you encounter a missing dependency error, it may be caused by the installed dependency being too old. In this case, either install a newer toolchain or decrease the required dependency version in your project.

In order to use WolfSSL in a project, just add WolfSSL as a dependency by
running `alr with wolfssl` within your project's directory.

Expand All @@ -84,28 +86,48 @@ and use gprbuild to build the source code.
cd wrapper/Ada
gprclean
gprbuild default.gpr

cd examples
gprbuild examples.gpr

cd obj/
./tls_server_main &
./tls_client_main 127.0.0.1
```

If you are using Alire, you can build the library and examples with:

```sh
cd wrapper/Ada
alr install

cd examples
alr build
```

You can also run the examples directly with Alire:

```sh
cd wrapper/Ada/examples
alr run tls_server_main &
alr run tls_client_main --args=127.0.0.1
```

On Windows, build the executables with:
```sh
gprbuild -XOS=Windows default.gpr
cd wrapper/Ada/examples
gprbuild -XOS=Windows examples.gpr
```

## Files
The (D)TLS v1.3 client example in the Ada/SPARK programming language
using the WolfSSL library can be found in the files:
tls_client_main.adb
tls_client.ads
tls_client.adb
examples/src/tls_client_main.adb
examples/src/tls_client.ads
examples/src/tls_client.adb

The (D)TLS v1.3 server example in the Ada/SPARK programming language
using the WolfSSL library can be found in the files:
tls_server_main.adb
tls_server.ads
tls_server.adb
examples/src/tls_server_main.adb
examples/src/tls_server.ads
examples/src/tls_server.adb
141 changes: 141 additions & 0 deletions wrapper/Ada/ada_binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@
/* wolfSSL */
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/ssl.h>
#include <wolfssl/wolfcrypt/rsa.h>
#include <wolfssl/wolfcrypt/sha256.h>
#include <wolfssl/wolfcrypt/aes.h>

#include <stdlib.h>

/* RSA instances are now dynamically allocated (no fixed pool). */
/* SHA256 instances are now dynamically allocated (no fixed pool). */
/* AES instances are now dynamically allocated (no fixed pool). */
/* These functions give access to the integer values of the enumeration
constants used in WolfSSL. These functions make it possible
for the WolfSSL implementation to change the values of the constants
Expand All @@ -48,6 +56,31 @@ extern int get_wolfssl_filetype_asn1(void);
extern int get_wolfssl_filetype_pem(void);
extern int get_wolfssl_filetype_default(void);

extern void* ada_new_rsa (void);
extern void ada_free_rsa (void* key);

extern void *ada_new_sha256 (void);
extern void ada_free_sha256 (void* sha256);

extern void* ada_new_aes (int devId);
extern void ada_free_aes (void* aes);

extern void* ada_new_rng (void);
extern void ada_free_rng (void* rng);
extern int ada_RsaSetRNG (RsaKey* key, WC_RNG* rng);

extern int get_wolfssl_invalid_devid (void);

extern int ada_md5 (void);
extern int ada_sha (void);
extern int ada_sha256 (void);
extern int ada_sha384 (void);
extern int ada_sha512 (void);
extern int ada_sha3_224 (void);
extern int ada_sha3_256 (void);
extern int ada_sha3_384 (void);
extern int ada_sha3_512 (void);

extern int get_wolfssl_error_want_read(void) {
return WOLFSSL_ERROR_WANT_READ;
}
Expand Down Expand Up @@ -107,3 +140,111 @@ extern int get_wolfssl_filetype_pem(void) {
extern int get_wolfssl_filetype_default(void) {
return WOLFSSL_FILETYPE_DEFAULT;
}

extern void* ada_new_rsa (void)
{
/* Allocate and initialize an RSA key using wolfCrypt's constructor. */
return (void*)wc_NewRsaKey(NULL, INVALID_DEVID, NULL);
}

extern void ada_free_rsa (void* key)
{
/* Delete RSA key and release its memory. */
wc_DeleteRsaKey((RsaKey*)key, NULL);
}

extern void* ada_new_sha256 (void)
{
return XMALLOC(sizeof(wc_Sha256), NULL, DYNAMIC_TYPE_SHA);
}

extern void ada_free_sha256 (void* sha256)
{
XFREE(sha256, NULL, DYNAMIC_TYPE_SHA);
}



extern void* ada_new_aes (int devId)
{
/* Allocate and initialize an AES object using wolfCrypt's constructor. */
return (void*)wc_AesNew(NULL, devId, NULL);
}

extern void ada_free_aes (void* aes)
{
/* Delete AES object and release its memory. */
wc_AesDelete((Aes*)aes, NULL);
}

extern int get_wolfssl_invalid_devid (void)
{
return INVALID_DEVID;
}

extern void* ada_new_rng (void)
{
/* Allocate and initialize a WC_RNG using wolfCrypt's allocator.
* Per request: pass NULL and 0 to wc_rng_new (nonce, nonceSz).
*/
return (void*)wc_rng_new(NULL, 0, NULL);
}

extern void ada_free_rng (void* rng)
{
wc_rng_free((WC_RNG*)rng);
}

extern int ada_RsaSetRNG(RsaKey* key, WC_RNG* rng)
{
int r = 0;
#ifdef WC_RSA_BLINDING /* HIGHLY RECOMMENDED! */
r = wc_RsaSetRNG(key, rng);
#endif
return r;
}

extern int ada_md5 (void)
{
return WC_MD5;
}

extern int ada_sha (void)
{
return WC_SHA;
}

extern int ada_sha256 (void)
{
return WC_SHA256;
}

extern int ada_sha384 (void)
{
return WC_SHA384;
}

extern int ada_sha512 (void)
{
return WC_SHA512;
}

extern int ada_sha3_224 (void)
{
return WC_SHA3_224;
}

extern int ada_sha3_256 (void)
{
return WC_SHA3_256;
}

extern int ada_sha3_384 (void)
{
return WC_SHA3_384;
}

extern int ada_sha3_512 (void)
{
return WC_SHA3_512;
}
3 changes: 3 additions & 0 deletions wrapper/Ada/alire.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ tags = ["ssl", "tls", "embedded", "spark"]

[configuration.variables]
STATIC_PSK = {type = "Boolean", default = false}

[[depends-on]]
gnatprove = "^13.2.1"
11 changes: 0 additions & 11 deletions wrapper/Ada/default.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@ project Default is
"../../src",
"../../wolfcrypt/src");

-- Don't build the tls application examples because they make use
-- of the Secondary Stack due to usage of the Ada.Command_Line
-- package. All other Ada source code does not use the secondary stack.
for Excluded_Source_Files use
("tls_client_main.adb",
"tls_client.ads",
"tls_client.adb",
"tls_server_main.adb",
"tls_server.ads",
"tls_server.adb");

for Object_Dir use "obj";

package Naming is
Expand Down
Loading