a56295b5f5c6 — Leonard Ritter a month ago
* added SHA256 support based on libcrypto
3 files changed, 43 insertions(+), 0 deletions(-)

A => testing/test_sha256.sc
A => tukan/SHA256.sc
A => tukan/crypto.sc
A => testing/test_sha256.sc +13 -0
@@ 0,0 1,13 @@ 
+
+using import ..tukan.SHA256
+
+fn main ()
+    let s = "Rosetta code"
+    for b in (sha256 s)
+        sc_write
+            hex b
+    sc_write "\n"
+    return 0
+
+main;
+

          
A => tukan/SHA256.sc +19 -0
@@ 0,0 1,19 @@ 
+
+using import .crypto
+
+let DigestType = (array u8 SHA256_DIGEST_LENGTH)
+
+inline... sha256
+case (data : rawstring, len : usize)
+    local ctx : SHA256_CTX
+    SHA256_Init &ctx
+    SHA256_Update &ctx (data as @u8) len
+    local result : DigestType
+    SHA256_Final &result &ctx
+    result
+case (data : string,)
+    this-function data ((countof data) as usize)
+
+do
+    let sha256
+    locals;
  No newline at end of file

          
A => tukan/crypto.sc +11 -0
@@ 0,0 1,11 @@ 
+
+static-library "libcrypto.so"
+# todo: add more stuff
+let crypto =
+    include "openssl/sha.h"
+
+do
+    using crypto.extern
+    using crypto.define
+    using crypto.typedef
+    locals;