Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
32d8c2b
Refactored Ada binding. Separated code that depends upon Interfaces.C…
joakim-strandberg Nov 20, 2025
f268092
Added Ada binding for the SHA256 implementation in the Wolfssl library.
joakim-strandberg Dec 2, 2025
2b85d52
Saving work in progress on RSA signature verification.
joakim-strandberg Dec 7, 2025
aae7dcd
Removed errors resulting from violation of restriction No Secondary S…
joakim-strandberg Dec 9, 2025
7fd73a3
Silenced many warnings related to no exception propagation for zero f…
joakim-strandberg Dec 11, 2025
38c4805
Saving work in progress on RSA example.
joakim-strandberg Dec 17, 2025
77e9192
Rsa example can now digitaly sign and verify digital signatures.
joakim-strandberg Dec 19, 2025
37c99c2
RSA example complete.
joakim-strandberg Dec 20, 2025
4ea1c05
Started work on AES example.
joakim-strandberg Dec 21, 2025
0745977
Add AUnit SHA256 binding tests for Ada wrapper
julek-wolfssl Dec 22, 2025
0f98e3f
Add AUnit RSA sign/verify tests and clean up Ada tests warnings
julek-wolfssl Dec 22, 2025
8869620
Add basic AUnit AES CBC tests
julek-wolfssl Dec 23, 2025
0f1a352
Ada tests: statically allocate suites and runner
julek-wolfssl Dec 23, 2025
807ea5a
Ada tests: add valgrind suppressions for AUnit leaks
julek-wolfssl Dec 23, 2025
59cc059
Ada tests: statically allocate AES suites
julek-wolfssl Dec 23, 2025
4115fd7
Ada tests: drop Build_Once and register suites at elaboration
julek-wolfssl Dec 23, 2025
2421a66
Ada tests: simplify harness and reduce boilerplate
julek-wolfssl Dec 23, 2025
10c6294
Ada: allocate SHA256 with malloc and add Free_SHA256
julek-wolfssl Dec 23, 2025
b910e9b
Ada: allocate RNG with wc_rng_new and add Free_RNG
julek-wolfssl Dec 23, 2025
28ca392
Ada: allocate RSA with wc_NewRsaKey and add Free_RSA
julek-wolfssl Dec 23, 2025
47eceef
Ada: allocate AES with wc_AesNew and free with wc_AesDelete
julek-wolfssl Dec 23, 2025
7241806
Ada tests: fix warnings (redundant with, style spacing)
julek-wolfssl Dec 23, 2025
848e884
Ada: document test running with valgrind and using gprbuild/gprclean …
julek-wolfssl Dec 23, 2025
b83fc05
CI: add Ada AUnit tests
julek-wolfssl Dec 23, 2025
aa02bf2
Ada: allow older aunit
julek-wolfssl Dec 29, 2025
ce92a17
Ada: add Post conditions for Free_*
julek-wolfssl Dec 29, 2025
dc06618
Ada: document possible source of dependency error
julek-wolfssl Dec 30, 2025
f207165
Ada: add GNATprove ownership annotations
julek-wolfssl Dec 29, 2025
314ae1c
Ada: GNATprove is clean on examples.gpr
julek-wolfssl Dec 30, 2025
37741ba
Ada: move examples to sub-directory
julek-wolfssl Dec 31, 2025
7909ff7
Ada: fix wrapper/Ada after moving examples
julek-wolfssl Dec 31, 2025
35aa191
Ada: fix examples after move
julek-wolfssl Dec 31, 2025
4e54eb4
Ada: update include.am
julek-wolfssl Dec 31, 2025
a600471
Ada: update examples executables
julek-wolfssl Dec 31, 2025
25ffb78
Ada: update readme
julek-wolfssl Dec 31, 2025
b3ce6ec
Ada: fix the client-server examples
julek-wolfssl Dec 31, 2025
b3d092e
Ada: add examples to ada.yml
julek-wolfssl Dec 31, 2025
0054c55
Ada: leverage gnatprove to track memory
julek-wolfssl Dec 31, 2025
f5a54a5
Ada: fix length proofs in gnatprove
julek-wolfssl Jan 5, 2026
f73588c
Ada: add gnatprove to CI
julek-wolfssl Jan 6, 2026
c45c781
Ada: update editorconfig
julek-wolfssl Jan 6, 2026
53b6a47
Ada: update gitignore to match others
julek-wolfssl Jan 6, 2026
9807dc0
Ada: fix default.gpr
julek-wolfssl Jan 6, 2026
7fe01ba
Ada: build default.gpr in CI
julek-wolfssl Jan 6, 2026
cec63b5
Ada: fix tls_client call in CI
julek-wolfssl Jan 6, 2026
6685aa3
Ada: use XMALLOC and XFREE for dynamic allocation
julek-wolfssl Jan 8, 2026
5ee8987
Ada wrapper: update .gitignore tracking, clarify RNG comment, remove …
julek-wolfssl Jan 8, 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 @@ -1348,6 +1348,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