]> foleosoft.com Git - CryptoFoleo.git/commitdiff
Mon Aug 14 04:33:46 PM EDT 2023
authorserver <[email protected]>
Mon, 14 Aug 2023 20:33:46 +0000 (16:33 -0400)
committerserver <[email protected]>
Mon, 14 Aug 2023 20:33:46 +0000 (16:33 -0400)
bin/CryptoFoleo.h
bin/CryptoFoleo.hi
bin/CryptoFoleo.hs
bin/CryptoFoleo.o
bin/Main.hi
bin/Main.hs
bin/Main.o
bin/main
src/auth.c
src/headers.h
src/headers.hs

index c7a6885a8f728e2e21e4108c9c925ccec02b04a6..5829a6320c70dc6de8b71e581a8857cdcd17f3cf 100644 (file)
@@ -44,4 +44,4 @@ uint8_t* foleo_hmac_hkdf(uint8_t, uint32_t, uint8_t*, uint32_t, uint8_t*, uint32
 uint8_t* foleo_hmac_prf(uint8_t, uint32_t, uint8_t*, uint32_t, uint8_t*, uint32_t, uint8_t*, uint32_t);
 
 uint8_t foleo_hash_size(uint8_t);
-uint8_t foleo_auth(const char*, const char*);
+uint8_t foleo_auth(uint8_t*, uint8_t*);
index fa2461427760193a1a79d8d3189f92fa10218e2d..85910568c220edfad1945db2c5ab0a1360297cbd 100644 (file)
Binary files a/bin/CryptoFoleo.hi and b/bin/CryptoFoleo.hi differ
index f5c6bc1d21997ea90ab63cb0b5b9f7e45cf3f6d5..41753f36dbff4d4314f36ed1f8767471e82d3986 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(CUChar) -> Ptr(CUChar) -> 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 (C8.pack u) $ \uPtr -> do
+        useAsCString (C8.pack p) $ \pPtr -> do
+            r <- c_auth (castPtr uPtr) (castPtr pPtr)
+            if (fromIntegral r) == 1 then return True else return False
+
 dhke :: [ByteString] -> IO (ByteString)
 dhke v = do
     c_modSize <- c_dhke_modsize
@@ -311,7 +323,7 @@ byteToHexString b = do
         14 -> "e"
         15 -> "f"
         _ -> "0"
-    ++ 
+    ++
     case (mod b 16) of
         0 -> "0"
         1 -> "1"
@@ -330,7 +342,7 @@ byteToHexString b = do
         14 -> "e"
         15 -> "f"
         _ -> "0"
-    
+
 byteStringToByteList :: ByteString -> [Word8]
 byteStringToByteList b = BS.unpack b
 
@@ -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
index d62821ab6be14b4ac294c0839cd95b95e90f363a..f5f42efb17fd05107f8890695c70a59fa7960d90 100644 (file)
Binary files a/bin/CryptoFoleo.o and b/bin/CryptoFoleo.o differ
index fe2978d109b5de4c400156563d364841766652ef..6d0bb4c6d382d39e4b03ec5cfac172823f9444d8 100644 (file)
Binary files a/bin/Main.hi and b/bin/Main.hi differ
index 9d4a3e5c7db3356de7b09fc80da7636f383be84b..efebe6a60d40cb33091e34f11753a0d59104ee9b 100644 (file)
@@ -8,81 +8,5 @@ import qualified Numeric as N
 
 main :: IO()
 main = do
-    let s :: BS.ByteString
-        s = BS.pack
-            [
-                0x01, 0x03, 0x80, 0x8a, 0xfb, 0x0d, 0xb2, 0xfd,
-                0x4a, 0xbf, 0xf6, 0xaf, 0x41, 0x49, 0xf5, 0x1b
-            ]
-        r :: BS.ByteString
-        r = BS.pack
-            [
-                0x85, 0xd6, 0xbe, 0x78, 0x57, 0x55, 0x6d, 0x33,
-                0x7f, 0x44, 0x52, 0xfe, 0x42, 0xd5, 0x06, 0xa8
-            ]
-        m :: BS.ByteString
-        m = BS.pack
-            [
-                0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x67, 0x72,
-                0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x46, 0x6f,
-                0x72, 0x75, 0x6d, 0x20, 0x52, 0x65, 0x73, 0x65,
-                0x61, 0x72, 0x63, 0x68, 0x20, 0x47, 0x72, 0x6f,
-                0x75, 0x70
-            ]
-
-    p <- poly1305 r m
-    print $ byteStringToHexString p
-
-
---    --generate key files if the don't exist
---    existsPub <- doesFileExist "pub.key"
---    existsPrv <- doesFileExist "prv.key"
---    unless (existsPub && existsPrv) $ do
---        rsa_keygen 2048 $ \pub prv -> do
---            spub <- rsa_export pub
---            sprv <- rsa_export prv
---            writeFile "pub.key" spub
---            writeFile "prv.key" sprv
---
---    --load the key files if they do exist
---    spub <- readFile "pub.key"
---    sprv <- readFile "prv.key"
---    rsa_import spub $ \pubKey -> do
---        rsa_import sprv $ \prvKey -> do
---            let pt = C8.pack "one two three it's photosynthesis you see"
---            ct <- rsa_encrypt pubKey rsa_padding_oaep pt
---            dt <- rsa_decrypt prvKey rsa_padding_oaep ct
---            putStrLn $ "Plaintext:\n\t" ++ (show pt)
---            putStrLn $ "Ciphertext:\n\t" ++ (show ct)
---            putStrLn $ "Decrypted message:\n\t" ++ (show dt)
---
---    
---    g <- sha256 (C8.pack "abc")
---    print g
---
---    prv1 <- dhke (BS.empty, BS.empty)
---    putStrLn "prv1="
---    print prv1
---
---    prv2 <- dhke (BS.empty, BS.empty)
---    putStrLn "prv2="
---    print prv2
---
---    pub1 <- dhke (prv1, BS.empty)
---    putStrLn "pub1="
---    print pub1
---
---    pub2 <- dhke (prv2, BS.empty)
---    putStrLn "pub2="
---    print pub2
---
---    key1 <- dhke(prv1, pub2)
---    putStrLn "key1="
---    print key1
---
---    key2 <- dhke(prv2, pub1)
---    putStrLn "key2="
---    print key2
---
---
-
+    q <- auth "server" "-"
+    print q
index 7a0ecde3fc9624afe8c70057f1a1637ef1e776b4..f852d22da1d3e68479bd2dbf72fc051dab44e8f8 100644 (file)
Binary files a/bin/Main.o and b/bin/Main.o differ
index a5af5bdfd6159dca77b2bf7757030480e3a3c0d6..39ec996c12c9a95bf2b604f6e1a881057f9933ca 100755 (executable)
Binary files a/bin/main and b/bin/main differ
index ea0086bc039f2611e5df16939a2df22e2a848099..f2a28ef38ac078a0419f3098823ef32795eaff00 100644 (file)
@@ -9,7 +9,8 @@
 #include <stdint.h>
 #include <unistd.h>
 
-uint8_t foleo_auth(const char *username, const char* password) {
+uint8_t foleo_auth(uint8_t* username, uint8_t* password)
+{
         struct spwd spw, *result;
         char *buf;
         size_t bufsize;
index c7a6885a8f728e2e21e4108c9c925ccec02b04a6..5829a6320c70dc6de8b71e581a8857cdcd17f3cf 100644 (file)
@@ -44,4 +44,4 @@ uint8_t* foleo_hmac_hkdf(uint8_t, uint32_t, uint8_t*, uint32_t, uint8_t*, uint32
 uint8_t* foleo_hmac_prf(uint8_t, uint32_t, uint8_t*, uint32_t, uint8_t*, uint32_t, uint8_t*, uint32_t);
 
 uint8_t foleo_hash_size(uint8_t);
-uint8_t foleo_auth(const char*, const char*);
+uint8_t foleo_auth(uint8_t*, uint8_t*);
index 723422e931a4badb31c008ec9d3b466feb9b643a..41753f36dbff4d4314f36ed1f8767471e82d3986 100644 (file)
@@ -43,7 +43,7 @@ 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)
+    c_auth :: Ptr(CUChar) -> Ptr(CUChar) -> IO(CUChar)
 
 foreign import ccall unsafe "foleo_rsa_keysize"
     c_rsa_keysize :: IO (CUShort)
@@ -184,10 +184,10 @@ 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
+    useAsCString (C8.pack u) $ \uPtr -> do
+        useAsCString (C8.pack p) $ \pPtr -> do
+            r <- c_auth (castPtr uPtr) (castPtr pPtr)
+            if (fromIntegral r) == 1 then return True else return False
 
 dhke :: [ByteString] -> IO (ByteString)
 dhke v = do
@@ -323,7 +323,7 @@ byteToHexString b = do
         14 -> "e"
         15 -> "f"
         _ -> "0"
-    ++ 
+    ++
     case (mod b 16) of
         0 -> "0"
         1 -> "1"
@@ -342,7 +342,7 @@ byteToHexString b = do
         14 -> "e"
         15 -> "f"
         _ -> "0"
-    
+
 byteStringToByteList :: ByteString -> [Word8]
 byteStringToByteList b = BS.unpack b