]> foleosoft.com Git - CryptoFoleo.git/commitdiff
Fri Aug 11 07:09:09 PM EDT 2023
authormiha-q <>
Fri, 11 Aug 2023 23:09:09 +0000 (19:09 -0400)
committermiha-q <>
Fri, 11 Aug 2023 23:09:09 +0000 (19:09 -0400)
bin/CryptoFoleo.h
bin/CryptoFoleo.hi
bin/CryptoFoleo.hs
bin/CryptoFoleo.o
bin/Main.hi
bin/Main.hs
bin/Main.o
bin/libCryptoFoleo.so
bin/main
src/headers.hs

index da94f6d5faf7a03c0acf662a05831f929be7052e..f45039d7821c7f1a8cb6bc35be2e7b6e70088871 100644 (file)
@@ -1,17 +1,17 @@
 #include <stdint.h>
 #include <gmp.h>
 
-uint8_t* foleo_chacha20(uint8_t[32], uint8_t[12], uint32_t, uint64_t);
-uint8_t* foleo_chacha20_poly1305(uint8_t[32], uint8_t[12], uint8_t*, uint64_t);
+uint8_t* foleo_chacha20(uint8_t[32], uint8_t[12], uint32_t, size_t);
+uint8_t* foleo_chacha20_poly1305(uint8_t[32], uint8_t[12], uint8_t*, size_t);
 uint8_t* foleo_dhke(uint8_t*, uint8_t*);
-uint8_t* foleo_dhke_prf(uint32_t, uint8_t*, uint32_t, uint8_t*, uint32_t, uint8_t*, uint32_t);
-uint8_t* foleo_poly1305(uint8_t*, uint8_t*, uint8_t*, uint64_t);
-static uint8_t* foleo_prigen(uint16_t);
-#define FOLEO_RSA_NONE 99
-#define FOLEO_RSA_ENCRYPTION 1
-#define FOLEO_RSA_SIGNATURE 2
-#define FOLEO_RSA_OAEP 3
-#define FOLEO_RSA_PSS 4
+uint16_t foleo_dhke_modsize();
+
+uint8_t* foleo_poly1305(uint8_t[32], uint8_t*, size_t);
+#define FOLEO_RSA_PADDING_NONE 99
+#define FOLEO_RSA_PADDING_ENCRYPTION 1
+#define FOLEO_RSA_PADDING_SIGNATURE 2
+#define FOLEO_RSA_PADDING_OAEP 3
+#define FOLEO_RSA_PADDING_PSS 4
 typedef struct
 {
     mpz_t n, k;
@@ -22,9 +22,25 @@ void foleo_rsa_import(rsakey_t*, uint8_t*);
 uint8_t* foleo_rsa_export(rsakey_t*);
 void foleo_rsa_free(rsakey_t*);
 void foleo_rsa_keygen(uint16_t, rsakey_t*, rsakey_t*);
+
+//The maximum message block size that can be used
+//  for a particular padding scheme.
+uint16_t foleo_rsa_msgsize(rsakey_t*, uint8_t);
+
+//Size of the rsakey struct
 uint16_t foleo_rsa_keysize();
-uint16_t foleo_rsa_size(rsakey_t, uint8_t);
-uint8_t* foleo_rsa_encrypt(rsakey_t, uint8_t, uint8_t*, uint16_t);
-uint8_t* foleo_rsa_decrypt(rsakey_t, uint8_t, uint8_t*, uint16_t*);
+
+//Size in bytes of RSA modulus, same thing as the number
+//  of bytes the encrypt() function will return
+uint16_t foleo_rsa_modsize(rsakey_t*);
+
+uint8_t* foleo_rsa_encrypt(rsakey_t*, uint8_t, uint8_t*, uint16_t);
+uint8_t* foleo_rsa_decrypt(rsakey_t*, uint8_t, uint8_t*, uint16_t*);
 uint8_t* foleo_sha256(uint8_t*, uint32_t);
-#define FOLEO_SHA256 foleo_sha256, 32, 64
+
+#define FOLEO_SHA256 1
+uint8_t* foleo_hmac(uint8_t, uint8_t*, uint32_t, uint8_t*, uint32_t);
+uint8_t* foleo_hmac_hkdf(uint8_t, uint32_t, uint8_t*, uint32_t, uint8_t*, uint32_t, uint8_t*, uint32_t);
+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);
\ No newline at end of file
index 48ee2380dce22d750c7af704a61d90ac487ee488..fa2461427760193a1a79d8d3189f92fa10218e2d 100644 (file)
Binary files a/bin/CryptoFoleo.hi and b/bin/CryptoFoleo.hi differ
index 7a2746bb480ca65fc6ec87b61b57ad78b793fdb0..401baa05fddf0a83477fb2c759fd0c1fd58febe2 100644 (file)
@@ -88,7 +88,7 @@ foreign import ccall unsafe "foleo_chacha20"
     c_chacha20 :: Ptr (CUChar) -> Ptr (CUChar) -> Word32 -> CSize -> IO (Ptr (CUChar))
 
 foreign import ccall unsafe "foleo_poly1305"
-    c_poly1305 :: Ptr (CUChar) -> Ptr (CUChar) -> Ptr (CUChar) -> CSize -> IO (Ptr (CUChar))
+    c_poly1305 :: Ptr (CUChar) -> Ptr (CUChar) -> CSize -> IO (Ptr (CUChar))
 
 foreign import ccall unsafe "foleo_chacha20_poly1305"
     c_chacha20_poly1305 :: Ptr (CUChar) -> Ptr (CUChar) -> Ptr (CUChar) -> CSize -> IO (Ptr (CUChar))
@@ -261,18 +261,17 @@ chacha20 key nonce block count = do
                 c_free rPtr
                 return r
 
-poly1305 :: ByteString -> ByteString -> ByteString -> IO (ByteString)
-poly1305 r s m = do
-    if (BS.length r /= 16) || (BS.length s /= 16) then
+poly1305 :: ByteString -> ByteString -> IO (ByteString)
+poly1305 k m = do
+    if BS.length k /= 32 then
         return BS.empty
     else
-        useAsCString r $ \rPtr -> do
-            useAsCString s $ \sPtr -> do
-                useAsCString m $ \mPtr -> do
-                    hPtr <- c_poly1305 (castPtr rPtr) (castPtr sPtr) (castPtr mPtr) (fromIntegral (BS.length m))
-                    h <- BI.create 16 (\ptr -> MU.copyBytes ptr (castPtr hPtr) 16)
-                    c_free hPtr
-                    return h
+        useAsCString k $ \kPtr -> do
+            useAsCString m $ \mPtr -> do
+                hPtr <- c_poly1305 (castPtr kPtr) (castPtr mPtr) (fromIntegral (BS.length m))
+                h <- BI.create 16 (\ptr -> MU.copyBytes ptr (castPtr hPtr) 16)
+                c_free hPtr
+                return h
 
 chacha20_poly1305 :: ByteString -> ByteString -> ByteString -> IO (ByteString)
 chacha20_poly1305 key nonce ctext = do
index 40f9b4db9bd03269c70b540dc2ec3ac5c1adb532..d62821ab6be14b4ac294c0839cd95b95e90f363a 100644 (file)
Binary files a/bin/CryptoFoleo.o and b/bin/CryptoFoleo.o differ
index d96de911a0d77b573a6a6561f83a308c87b4b83c..fe2978d109b5de4c400156563d364841766652ef 100644 (file)
Binary files a/bin/Main.hi and b/bin/Main.hi differ
index 62a1c6408bfc780dca7fa3628e8ed920b2cb41dc..9d4a3e5c7db3356de7b09fc80da7636f383be84b 100644 (file)
@@ -30,7 +30,7 @@ main = do
                 0x75, 0x70
             ]
 
-    p <- poly1305 r m
+    p <- poly1305 r m
     print $ byteStringToHexString p
 
 
index 39907d3bdc69c7739f44ace8a13dc19ab423d0cf..7a0ecde3fc9624afe8c70057f1a1637ef1e776b4 100644 (file)
Binary files a/bin/Main.o and b/bin/Main.o differ
index a40af30c168b0817911d8afc70515a2e11a04fa8..8b3724f0460aadbd9dc3269d812749d20875dadb 100755 (executable)
Binary files a/bin/libCryptoFoleo.so and b/bin/libCryptoFoleo.so differ
index e819b9b65606b41baa56f3e88564f834fe781af6..a5af5bdfd6159dca77b2bf7757030480e3a3c0d6 100755 (executable)
Binary files a/bin/main and b/bin/main differ
index 7a2746bb480ca65fc6ec87b61b57ad78b793fdb0..401baa05fddf0a83477fb2c759fd0c1fd58febe2 100644 (file)
@@ -88,7 +88,7 @@ foreign import ccall unsafe "foleo_chacha20"
     c_chacha20 :: Ptr (CUChar) -> Ptr (CUChar) -> Word32 -> CSize -> IO (Ptr (CUChar))
 
 foreign import ccall unsafe "foleo_poly1305"
-    c_poly1305 :: Ptr (CUChar) -> Ptr (CUChar) -> Ptr (CUChar) -> CSize -> IO (Ptr (CUChar))
+    c_poly1305 :: Ptr (CUChar) -> Ptr (CUChar) -> CSize -> IO (Ptr (CUChar))
 
 foreign import ccall unsafe "foleo_chacha20_poly1305"
     c_chacha20_poly1305 :: Ptr (CUChar) -> Ptr (CUChar) -> Ptr (CUChar) -> CSize -> IO (Ptr (CUChar))
@@ -261,18 +261,17 @@ chacha20 key nonce block count = do
                 c_free rPtr
                 return r
 
-poly1305 :: ByteString -> ByteString -> ByteString -> IO (ByteString)
-poly1305 r s m = do
-    if (BS.length r /= 16) || (BS.length s /= 16) then
+poly1305 :: ByteString -> ByteString -> IO (ByteString)
+poly1305 k m = do
+    if BS.length k /= 32 then
         return BS.empty
     else
-        useAsCString r $ \rPtr -> do
-            useAsCString s $ \sPtr -> do
-                useAsCString m $ \mPtr -> do
-                    hPtr <- c_poly1305 (castPtr rPtr) (castPtr sPtr) (castPtr mPtr) (fromIntegral (BS.length m))
-                    h <- BI.create 16 (\ptr -> MU.copyBytes ptr (castPtr hPtr) 16)
-                    c_free hPtr
-                    return h
+        useAsCString k $ \kPtr -> do
+            useAsCString m $ \mPtr -> do
+                hPtr <- c_poly1305 (castPtr kPtr) (castPtr mPtr) (fromIntegral (BS.length m))
+                h <- BI.create 16 (\ptr -> MU.copyBytes ptr (castPtr hPtr) 16)
+                c_free hPtr
+                return h
 
 chacha20_poly1305 :: ByteString -> ByteString -> ByteString -> IO (ByteString)
 chacha20_poly1305 key nonce ctext = do