#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;
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
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))
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
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))
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