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(CChar) -> Ptr(CChar) -> 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 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
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
+++ /dev/null
-#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()
-{
-}