]> foleosoft.com Git - CryptoFoleo.git/commitdiff
Mon Aug 14 04:00:40 PM EDT 2023
authorserver <[email protected]>
Mon, 14 Aug 2023 20:00:40 +0000 (16:00 -0400)
committerserver <[email protected]>
Mon, 14 Aug 2023 20:00:40 +0000 (16:00 -0400)
src/headers.hs
src/test.c [deleted file]

index f5c6bc1d21997ea90ab63cb0b5b9f7e45cf3f6d5..723422e931a4badb31c008ec9d3b466feb9b643a 100644 (file)
@@ -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 (file)
index 86f30fa..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-#include <stdio.h>
-#include <shadow.h>
-#include <string.h>
-#include <crypt.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <pwd.h>
-
-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()
-{
-}