libidav/crypto.h

changeset 349
0b4ecadaf3f9
parent 260
26f5f817429e
child 367
4a6a59f89f9f
--- a/libidav/crypto.h	Sun Dec 17 10:53:08 2017 +0100
+++ b/libidav/crypto.h	Sun Dec 17 13:20:01 2017 +0100
@@ -30,8 +30,27 @@
 #define	DAV_CRYPTO_H
 
 #include "webdav.h"
+#include <ucx/string.h>
+
+#ifdef __APPLE__
+/* macos */
+#define DAV_AES_CTX              CCCryptorRef
+#define DAV_SHA_CTX              CC_SHA256_CTX
+#define DAV_SHA256_DIGEST_LENGTH 32
+
+#include <CommonCrypto/CommonCrypto.h>
+#include <CommonCrypto/CommonDigest.h>
+
+#else
+/* unix/linux and still windows */
+#define DAV_AES_CTX              EVP_CIPHER_CTX*
+#define DAV_SHA_CTX              SHA256_CTX
+#define DAV_SHA256_DIGEST_LENGTH 32
+
+#define DAV_USE_OPENSSL
+
 #include <openssl/evp.h>
-#include <ucx/string.h>
+#include <openssl/rand.h>
 
 #if defined(__sun) && defined(__SunOS_5_10)
 #include <sha2.h>
@@ -42,13 +61,15 @@
 #include <openssl/sha.h>
 #endif
 
+#endif
+
 #ifdef	__cplusplus
 extern "C" {
 #endif
 
 typedef struct {
-    EVP_CIPHER_CTX *ctx;
-    SHA256_CTX     sha256;
+    DAV_AES_CTX    ctx;
+    DAV_SHA_CTX    sha256;
     void           *stream;
     dav_write_func write;
     DavKey         *key;
@@ -58,8 +79,8 @@
 } AESDecrypter;
 
 typedef struct {
-    EVP_CIPHER_CTX *ctx;
-    SHA256_CTX     sha256;
+    DAV_AES_CTX    ctx;
+    DAV_SHA_CTX    sha256;
     void           *iv;
     size_t         ivlen;
     void           *stream;
@@ -70,6 +91,8 @@
     int            end;
 } AESEncrypter;
 
+int dav_rand_bytes(unsigned char *buf, size_t len);
+
 AESDecrypter* aes_decrypter_new(DavKey *key, void *stream, dav_write_func write_func);
 size_t aes_write(const void *buf, size_t s, size_t n, AESDecrypter *dec);
 void aes_decrypter_shutdown(AESDecrypter *dec);
@@ -82,7 +105,7 @@
 char* aes_encrypt(char *in, size_t len, DavKey *key);
 char* aes_decrypt(char *in, size_t *len, DavKey *key);
 
-void dav_get_hash(SHA256_CTX *sha256, unsigned char *buf);
+void dav_get_hash(DAV_SHA_CTX *sha256, unsigned char *buf);
 
 #ifdef	__cplusplus
 }

mercurial