libidav/crypto.h

Sun, 24 Jun 2018 11:51:07 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 24 Jun 2018 11:51:07 +0200
changeset 428
b50ade8e7197
parent 404
5c08b8e14df8
child 470
6bf798ad3aec
child 481
ff477f1f7765
permissions
-rw-r--r--

adds documentation for tag config

40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
404
5c08b8e14df8 updates copyright notice
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 367
diff changeset
4 * Copyright 2018 Olaf Wintermann. All rights reserved.
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
a95ee94b9204 supports whitespace in paths
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
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #ifndef DAV_CRYPTO_H
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #define DAV_CRYPTO_H
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include "webdav.h"
349
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
33 #include <ucx/string.h>
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
34
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
35 #ifdef __APPLE__
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
36 /* macos */
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
37 #define DAV_AES_CTX CCCryptorRef
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
38 #define DAV_SHA_CTX CC_SHA256_CTX
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
39 #define DAV_SHA256_DIGEST_LENGTH 32
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
40
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
41 #include <CommonCrypto/CommonCrypto.h>
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
42 #include <CommonCrypto/CommonDigest.h>
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
43
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
44 #else
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
45 /* unix/linux and still windows */
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
46 #define DAV_AES_CTX EVP_CIPHER_CTX*
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
47 #define DAV_SHA_CTX SHA256_CTX
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
48 #define DAV_SHA256_DIGEST_LENGTH 32
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
49
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
50 #define DAV_USE_OPENSSL
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
51
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 #include <openssl/evp.h>
349
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
53 #include <openssl/rand.h>
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54
234
33f373b28c8c added support for compiling with gcc on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
55 #if defined(__sun) && defined(__SunOS_5_10)
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
56 #include <sha2.h>
183
c238e0017257 fixed Solaris build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
57 #define SHA256_Init SHA256Init
c238e0017257 fixed Solaris build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
58 #define SHA256_Update SHA256Update
c238e0017257 fixed Solaris build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 150
diff changeset
59 #define SHA256_Final SHA256Final
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
60 #else
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
61 #include <openssl/sha.h>
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
62 #endif
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
63
349
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
64 #endif
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
65
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 #ifdef __cplusplus
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 extern "C" {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 #endif
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 typedef struct {
349
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
71 DAV_AES_CTX ctx;
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
72 DAV_SHA_CTX sha256;
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 void *stream;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 dav_write_func write;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 DavKey *key;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 int init;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 unsigned char ivtmp[16];
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 size_t ivpos;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 } AESDecrypter;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 typedef struct {
349
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
82 DAV_AES_CTX ctx;
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
83 DAV_SHA_CTX sha256;
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 void *iv;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 size_t ivlen;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 void *stream;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 dav_read_func read;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 char *tmp;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 size_t tmplen;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 size_t tmpoff;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 int end;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 } AESEncrypter;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93
349
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
94 int dav_rand_bytes(unsigned char *buf, size_t len);
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
95
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 AESDecrypter* aes_decrypter_new(DavKey *key, void *stream, dav_write_func write_func);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 size_t aes_write(const void *buf, size_t s, size_t n, AESDecrypter *dec);
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
98 void aes_decrypter_shutdown(AESDecrypter *dec);
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 void aes_decrypter_close(AESDecrypter *dec);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 AESEncrypter* aes_encrypter_new(DavKey *key, void *stream, dav_read_func read_func);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 size_t aes_read(void *buf, size_t s, size_t n, AESEncrypter *enc);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 void aes_encrypter_close(AESEncrypter *enc);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
105 char* aes_encrypt(char *in, size_t len, DavKey *key);
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
106 char* aes_decrypt(char *in, size_t *len, DavKey *key);
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
107
349
0b4ecadaf3f9 ports openssl code to commoncrypto (macos)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 260
diff changeset
108 void dav_get_hash(DAV_SHA_CTX *sha256, unsigned char *buf);
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109
367
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
110 char* dav_create_hash(const char *data, size_t len);
4a6a59f89f9f adds dav-sync config for autodetecting tag changes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 349
diff changeset
111
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 #ifdef __cplusplus
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 }
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 #endif
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 #endif /* DAV_CRYPTO_H */
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117

mercurial