module CryptoFoleo
(
+ auth,
+
dhke,
chacha20,
poly1305,
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)
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
14 -> "e"
15 -> "f"
_ -> "0"
- ++
+ ++
case (mod b 16) of
0 -> "0"
1 -> "1"
14 -> "e"
15 -> "f"
_ -> "0"
-
+
byteStringToByteList :: ByteString -> [Word8]
byteStringToByteList b = BS.unpack b
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
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
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)
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
14 -> "e"
15 -> "f"
_ -> "0"
- ++
+ ++
case (mod b 16) of
0 -> "0"
1 -> "1"
14 -> "e"
15 -> "f"
_ -> "0"
-
+
byteStringToByteList :: ByteString -> [Word8]
byteStringToByteList b = BS.unpack b