Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 28 additions & 0 deletions Ada/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
This is a collection of examples using the wolfSSL Ada wrapper

By default it is expecting the wolfssl directory to be located at wolfssl-examples/Ada/wolfssl
but that can be adjusted by changing the directory path in wolfssl_sha256.gpr
`with "../wolfssl/wrapper/Ada/config/wolfssl_config.gpr";` and the for Source_Dirs paths.

An example of building for use with SHA256 would be:

```
cd wolfssl-examples/Ada
git clone --depth=1 git@github.com:wolfssl/wolfssl
cd sha256
gprbuild sha256.gpr
```

And then running the example with:

```
bash-3.2$ ./obj/sha256_main
DFFD6021BB2BD5B0AF676290809EC3A53191DD81C7F70A4B28688A362182986F
```

Which matches the hash used from shasum:

```
bash-3.2$ printf 'Hello, World!' | shasum -a 256
dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f -
```
78 changes: 78 additions & 0 deletions Ada/sha256/sha256.gpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
with "wolfssl_sha256.gpr";

project SHA256 is

type OS_Kind is ("Windows", "Linux_Or_Mac");

OS : OS_Kind := external ("OS", "Linux_Or_Mac");

for Languages use ("Ada");

for Source_Dirs use (".");

for Object_Dir use "obj";

for Main use ("sha256_main.adb");

package Naming is
for Spec_Suffix ("C") use ".h";
end Naming;

package Compiler is
for Switches ("C") use
("-DWOLFSSL_USER_SETTINGS", -- Use the user_settings.h file.
"-Wno-pragmas",
"-Wall",
"-Wextra",
"-Wunknown-pragmas",
"--param=ssp-buffer-size=1",
"-Waddress",
"-Warray-bounds",
"-Wbad-function-cast",
"-Wchar-subscripts",
"-Wcomment",
"-Wfloat-equal",
"-Wformat-security",
"-Wformat=2",
"-Wmaybe-uninitialized",
"-Wmissing-field-initializers",
"-Wmissing-noreturn",
"-Wmissing-prototypes",
"-Wnested-externs",
"-Wnormalized=id",
"-Woverride-init",
"-Wpointer-arith",
"-Wpointer-sign",
"-Wshadow",
"-Wsign-compare",
"-Wstrict-overflow=1",
"-Wstrict-prototypes",
"-Wswitch-enum",
"-Wundef",
"-Wunused",
"-Wunused-result",
"-Wunused-variable",
"-Wwrite-strings",
"-fwrapv");

for Switches ("Ada") use ("-g");
end Compiler;

package Linker is
case OS is
when "Windows" =>
for Switches ("Ada") use
("-lm", -- To include the math library (used by WolfSSL).
"-lcrypt32"); -- Needed on Windows.

when "Linux_Or_Mac" =>
for Switches ("Ada") use
("-lm"); -- To include the math library (used by WolfSSL).
end case;
end Linker;

package Binder is
for Switches ("Ada") use ("-Es"); -- To include stack traces.
end Binder;

end SHA256;
47 changes: 47 additions & 0 deletions Ada/sha256/sha256_main.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
with Ada.Text_IO;
with WolfSSL;

procedure SHA256_Main is
procedure Put (Text : String) renames Ada.Text_IO.Put;

procedure New_Line is
begin
Ada.Text_IO.New_Line;
end New_Line;

use type WolfSSL.Subprogram_Result;

Hash : WolfSSL.SHA256_Hash;
B : WolfSSL.Byte_Array := (
1 => 'H', 2 => 'e', 3 => 'l', 4 => 'l', 5 => 'o',
6 => ',', 7 => ' ', 8 => 'W', 9 => 'o', 10 => 'r',
11 => 'l', 12 => 'd', 13 => '!');
SHA256 : WolfSSL.SHA256_Type;
R : Integer;
S : WolfSSL.SHA256_As_String;
begin
WolfSSL.Create_SHA256 (Index => 1, SHA256 => SHA256, Result => R);
if R /= 0 then
Put ("SHA256 instance creation failed");
New_Line;
return;
end if;
WolfSSL.Update_SHA256 (SHA256 => SHA256, Byte => B, Result => R);
if R /= 0 then
Put ("Update of SHA256 instance failed");
New_Line;
return;
end if;
WolfSSL.Finalize_SHA256 (SHA256 => SHA256,
Hash => Hash,
Text => S,
Result => R);
if R = 0 then
Put (S);
New_Line;
else
Put ("Finalization of SHA256 instance failed");
New_Line;
return;
end if;
end SHA256_Main;
98 changes: 98 additions & 0 deletions Ada/sha256/wolfssl_sha256.gpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
with "../wolfssl/wrapper/Ada/config/wolfssl_config.gpr";

library project WolfSSL_SHA256 is

for Library_Name use "wolfssl";

for Languages use ("C", "Ada");

for Source_Dirs use ("../wolfssl/wrapper/Ada",
"../wolfssl",
"../wolfssl/src",
"../wolfssl/wolfcrypt/src");

-- Don't build the tls client or server application.
-- They are not needed in order to build the library.
-- Also exclude wolfssl-full_runtime files from this example build
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",
"spark_sockets.ads",
"spark_sockets.adb",
"sha256_main.adb",
"rsa_verify_main.adb",
"wolfssl-full_runtime.adb",
"wolfssl-full_runtime.ads");

for Object_Dir use "./obj";
for Library_Dir use "./lib";
for Create_Missing_Dirs use "True";

type Library_Type_Type is ("relocatable", "static", "static-pic");
Library_Type : Library_Type_Type := external("LIBRARY_TYPE", "static");
for Library_Kind use Library_Type;

package Naming is
for Spec_Suffix ("C") use ".h";
end Naming;

C_Compiler_Config := ();

case Wolfssl_Config.STATIC_PSK is
when "True" =>
C_Compiler_Config :=
("-DWOLFSSL_STATIC_PSK" -- Enable the static PSK cipher support
);
when others =>
C_Compiler_Config := ();
end case;

package Compiler is
for Switches ("C") use C_Compiler_Config &
("-DWOLFSSL_USER_SETTINGS", -- Use the user_settings.h file.
"-Wno-pragmas",
"-Wall",
"-Wextra",
"-Wunknown-pragmas",
"--param=ssp-buffer-size=1",
"-Waddress",
"-Warray-bounds",
"-Wbad-function-cast",
"-Wchar-subscripts",
"-Wcomment",
"-Wfloat-equal",
"-Wformat-security",
"-Wformat=2",
"-Wmaybe-uninitialized",
"-Wmissing-field-initializers",
"-Wmissing-noreturn",
"-Wmissing-prototypes",
"-Wnested-externs",
"-Wnormalized=id",
"-Woverride-init",
"-Wpointer-arith",
"-Wpointer-sign",
"-Wshadow",
"-Wsign-compare",
"-Wstrict-overflow=1",
"-Wstrict-prototypes",
"-Wswitch-enum",
"-Wundef",
"-Wunused",
"-Wunused-result",
"-Wunused-variable",
"-Wwrite-strings",
"-fwrapv") & External_As_List ("CFLAGS", " ");

for Switches ("Ada") use ("-g") & External_As_List ("ADAFLAGS", " ");
end Compiler;

package Binder is
for Switches ("Ada") use ("-Es"); -- To include stack traces.
end Binder;

end WolfSSL_SHA256;