From 72094af40c065591d72dce1302f2f0a1981da1b1 Mon Sep 17 00:00:00 2001 From: server Date: Mon, 14 Aug 2023 16:00:40 -0400 Subject: [PATCH] Mon Aug 14 04:00:40 PM EDT 2023 --- src/headers.hs | 14 +++++++++++++- src/test.c | 24 ------------------------ 2 files changed, 13 insertions(+), 25 deletions(-) delete mode 100644 src/test.c diff --git a/src/headers.hs b/src/headers.hs index f5c6bc1..723422e 100644 --- a/src/headers.hs +++ b/src/headers.hs @@ -1,5 +1,7 @@ module CryptoFoleo ( + auth, + dhke, chacha20, poly1305, @@ -40,6 +42,9 @@ import qualified Data.ByteString.Internal as BI import qualified Foreign.Marshal.Utils as MU import qualified Data.ByteString.Char8 as C8 +foreign import ccall unsafe "foleo_auth" + c_auth :: Ptr(CChar) -> Ptr(CChar) -> IO(CUChar) + foreign import ccall unsafe "foleo_rsa_keysize" c_rsa_keysize :: IO (CUShort) @@ -177,6 +182,13 @@ rsa_export keyBS = do rsa_free :: ByteString -> IO() rsa_free blob = useAsCString blob $ \ptr -> c_rsa_free (castPtr ptr) +auth :: String -> String -> IO (Bool) +auth u p = do + useAsCString u $ \uPtr -> do + useAsCString p $ \pPtr -> do + r <- c_auth uPtr pPtr + if (fromIntegral c) == 1 then return True else return False + dhke :: [ByteString] -> IO (ByteString) dhke v = do c_modSize <- c_dhke_modsize @@ -349,4 +361,4 @@ fromNumberFixedSize n p = do pd :: [Word8] -> [Word8] pd x = if (Prelude.length x) < p then pd ([0] ++ x) else x rt = pd (fn n []) - BS.pack $ if (Prelude.length rt) > p then Prelude.drop ((Prelude.length rt) - p) rt else rt \ No newline at end of file + BS.pack $ if (Prelude.length rt) > p then Prelude.drop ((Prelude.length rt) - p) rt else rt diff --git a/src/test.c b/src/test.c deleted file mode 100644 index 86f30fa..0000000 --- a/src/test.c +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -uint8_t authenticate(const char *username, const char* password) -{ - struct spwd* pw; - pw = getspnam(username); - if (!pw) - { - fprintf(stderr, "authenticate(): Permission denied.\n"); - return 0; - } - const char* hashedPassword = crypt(password, pw->sp_pwdp); - return strcmp(hashedPassword, pw->sp_pwdp) == 0; -} - -void main() -{ -} -- 2.39.5