libidav/crypto.h

Sun, 10 Nov 2024 15:30:46 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 10 Nov 2024 15:30:46 +0100
changeset 76
641dcc79e0ef
parent 1
b5bb7b3cd597
permissions
-rw-r--r--

update toolkit

1
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2018 Olaf Wintermann. All rights reserved.
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #ifndef DAV_CRYPTO_H
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #define DAV_CRYPTO_H
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include "webdav.h"
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include <cx/string.h>
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #ifdef __APPLE__
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 /* macos */
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #define DAV_CRYPTO_COMMON_CRYPTO
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 #define DAV_AES_CTX CCCryptorRef
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 #define DAV_SHA_CTX CC_SHA256_CTX
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 #define DAV_SHA256_DIGEST_LENGTH 32
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 #include <CommonCrypto/CommonCrypto.h>
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 #include <CommonCrypto/CommonDigest.h>
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 #elif defined(_WIN32)
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 #define DAV_CRYPTO_CNG
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 #include <windows.h>
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 #include <bcrypt.h>
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 typedef struct WinBCryptCTX {
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 BCRYPT_ALG_HANDLE hAlg;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 BCRYPT_KEY_HANDLE hKey;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 void *pbKeyObject;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 unsigned char pbIV[16];
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 unsigned char buf[16];
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 ULONG buflen;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 } WinBCryptCTX;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 typedef struct WinBCryptSHACTX {
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 BCRYPT_ALG_HANDLE hAlg;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 BCRYPT_HASH_HANDLE hHash;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 void *pbHashObject;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 } WinBCryptSHACTX;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 #define DAV_AES_CTX WinBCryptCTX
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 #define DAV_SHA_CTX WinBCryptSHACTX
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 #define DAV_SHA256_DIGEST_LENGTH 32
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 #else
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 /* unix/linux */
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 #define DAV_USE_OPENSSL
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 #define DAV_AES_CTX EVP_CIPHER_CTX*
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 #define DAV_SHA_CTX SHA256_CTX
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 #define DAV_SHA256_DIGEST_LENGTH 32
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 #include <openssl/evp.h>
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 #include <openssl/rand.h>
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 #if defined(__sun) && defined(__SunOS_5_10)
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 #include <sha2.h>
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 #define SHA256_Init SHA256Init
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 #define SHA256_Update SHA256Update
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 #define SHA256_Final SHA256Final
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 #else
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 #include <openssl/sha.h>
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 #endif
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 #endif
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 #ifdef __cplusplus
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 extern "C" {
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 #endif
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 #define DAV_PWFUNC_PBKDF2_SHA256 0
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 #define DAV_PWFUNC_PBKDF2_SHA512 1
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 #define DAV_CRYPTO_ITERATION_COUNT 4000
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 typedef struct {
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 DAV_AES_CTX ctx;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 DAV_SHA_CTX sha256;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 void *stream;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 dav_write_func write;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 DavKey *key;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 int init;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 unsigned char ivtmp[16];
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 size_t ivpos;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 } AESDecrypter;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 typedef struct {
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 DAV_AES_CTX ctx;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 DAV_SHA_CTX sha256;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 void *iv;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 size_t ivlen;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 void *stream;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 dav_read_func read;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 dav_seek_func seek;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 char *tmp;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 size_t tmplen;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 size_t tmpoff;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 int end;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 } AESEncrypter;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 typedef struct DavHashContext DavHashContext;
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 int dav_rand_bytes(unsigned char *buf, size_t len);
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 AESDecrypter* aes_decrypter_new(DavKey *key, void *stream, dav_write_func write_func);
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 size_t aes_write(const void *buf, size_t s, size_t n, AESDecrypter *dec);
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 void aes_decrypter_shutdown(AESDecrypter *dec);
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 void aes_decrypter_close(AESDecrypter *dec);
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 AESEncrypter* aes_encrypter_new(DavKey *key, void *stream, dav_read_func read_func, dav_seek_func seek_func);
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 size_t aes_read(void *buf, size_t s, size_t n, AESEncrypter *enc);
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 void aes_encrypter_close(AESEncrypter *enc);
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 int aes_encrypter_reset(AESEncrypter *enc, curl_off_t offset, int origin);
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 char* aes_encrypt(const char *in, size_t len, DavKey *key);
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 char* aes_decrypt(const char *in, size_t *len, DavKey *key);
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 void dav_get_hash(DAV_SHA_CTX *sha256, unsigned char *buf);
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 char* dav_create_hash(const char *data, size_t len);
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 DAV_SHA_CTX* dav_hash_init(void);
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 void dav_hash_update(DAV_SHA_CTX *ctx, const char *data, size_t len);
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 void dav_hash_final(DAV_SHA_CTX *ctx, unsigned char *buf);
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 DavKey* dav_pw2key(const char *password, const unsigned char *salt, int saltlen, int pwfunc, int enc);
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 CxBuffer* aes_encrypt_buffer(CxBuffer *in, DavKey *key);
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 CxBuffer* aes_decrypt_buffer(CxBuffer *in, DavKey *key);
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 #ifdef __cplusplus
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 }
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 #endif
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 #endif /* DAV_CRYPTO_H */
b5bb7b3cd597 add libidav code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166

mercurial