libidav/crypto.c

Fri, 09 Dec 2016 10:55:18 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 09 Dec 2016 10:55:18 +0100
changeset 258
571b62700df6
parent 237
fd9135bc7580
child 260
26f5f817429e
permissions
-rw-r--r--

adds auth prompt to dav get-property, set-property, lock, unlock and info

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 *
185
cd42cccee550 updated copyright notice
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 183
diff changeset
4 * Copyright 2016 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 #include <stdio.h>
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <string.h>
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include <openssl/rand.h>
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include <libidav/utils.h>
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "crypto.h"
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 AESDecrypter* aes_decrypter_new(DavKey *key, void *stream, dav_write_func write_func) {
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
38 AESDecrypter *dec = calloc(1, sizeof(AESDecrypter));
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
39 SHA256_Init(&dec->sha256);
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 dec->stream = stream;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 dec->write = write_func;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 dec->key = key;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 dec->init = 0;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 dec->ivpos = 0;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 return dec;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 }
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 void aes_decrypter_init(AESDecrypter *dec) {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 EVP_CIPHER_CTX_init(&dec->ctx);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 dec->init = 1;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 if(dec->key->type == DAV_KEY_AES128) {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 EVP_DecryptInit_ex(
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 &dec->ctx,
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 EVP_aes_128_cbc(),
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 NULL,
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 dec->key->data,
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 dec->ivtmp);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 } else if(dec->key->type == DAV_KEY_AES256) {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 EVP_DecryptInit_ex(
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 &dec->ctx,
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 EVP_aes_256_cbc(),
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 NULL,
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 dec->key->data,
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 dec->ivtmp);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 } else {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 fprintf(stderr, "unknown key type\n");
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 exit(-1);
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 }
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 size_t aes_write(const void *buf, size_t s, size_t n, AESDecrypter *dec) {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 int len = s*n;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 if(!dec->init) {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 size_t n = 16 - dec->ivpos;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 size_t cp = n > len ? len : n;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 memcpy(dec->ivtmp + dec->ivpos, buf, cp);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 dec->ivpos += cp;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 if(dec->ivpos >= 16) {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 aes_decrypter_init(dec);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 }
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 if(len == cp) {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 return len;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 } else {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 buf = (char*)buf + cp;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 len -= cp;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 }
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 }
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 int outlen = len + 16;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 unsigned char *out = malloc(outlen);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 EVP_DecryptUpdate(&dec->ctx, out, &len, buf, len);
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
93 ssize_t wlen = dec->write(out, 1, len, dec->stream);
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
94 SHA256_Update(&dec->sha256, out, wlen);
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 free(out);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 return (s*n) / s;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 }
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
99 void aes_decrypter_shutdown(AESDecrypter *dec) {
237
fd9135bc7580 fixed crash when encrypted streams are empty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
100 if(dec->init) {
fd9135bc7580 fixed crash when encrypted streams are empty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
101 void *out = malloc(128);
fd9135bc7580 fixed crash when encrypted streams are empty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
102 int len = 0;
fd9135bc7580 fixed crash when encrypted streams are empty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
103 EVP_DecryptFinal_ex(&dec->ctx, out, &len);
fd9135bc7580 fixed crash when encrypted streams are empty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
104 dec->write(out, 1, len, dec->stream);
fd9135bc7580 fixed crash when encrypted streams are empty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
105 SHA256_Update(&dec->sha256, out, len);
fd9135bc7580 fixed crash when encrypted streams are empty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
106 free(out);
fd9135bc7580 fixed crash when encrypted streams are empty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
107 EVP_CIPHER_CTX_cleanup(&dec->ctx);
fd9135bc7580 fixed crash when encrypted streams are empty
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 207
diff changeset
108 }
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
109 }
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
110
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
111 void aes_decrypter_close(AESDecrypter *dec) {
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 free(dec);
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
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 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
117 unsigned char *iv = malloc(16);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 if(!RAND_bytes(iv, 16)) {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 free(iv);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 return NULL;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 }
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 AESEncrypter *enc = malloc(sizeof(AESEncrypter));
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
124 SHA256_Init(&enc->sha256);
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 enc->stream = stream;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 enc->read = read_func;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 enc->tmp = NULL;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 enc->tmplen = 0;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 enc->tmpoff = 0;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 enc->end = 0;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 enc->iv = iv;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 enc->ivlen = 16;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 EVP_CIPHER_CTX_init(&enc->ctx);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 if(key->type == DAV_KEY_AES128) {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 EVP_EncryptInit_ex(&enc->ctx, EVP_aes_128_cbc(), NULL, key->data, enc->iv);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 } else if(key->type == DAV_KEY_AES256) {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 EVP_EncryptInit_ex(&enc->ctx, EVP_aes_256_cbc(), NULL, key->data, enc->iv);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 } else {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 fprintf(stderr, "unknown key type\n");
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 exit(-1);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 }
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 return enc;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 }
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 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
147 size_t len = s*n;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 if(enc->tmp) {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 size_t tmp_diff = enc->tmplen - enc->tmpoff;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 size_t cp_len = tmp_diff > len ? len : tmp_diff;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 memcpy(buf, enc->tmp + enc->tmpoff, cp_len);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 enc->tmpoff += cp_len;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 if(enc->tmpoff >= enc->tmplen) {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 free(enc->tmp);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 enc->tmp = NULL;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 enc->tmplen = 0;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 enc->tmpoff = 0;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 }
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 return cp_len / s;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 }
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 if(enc->end) {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 return 0;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 }
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 void *in = malloc(len);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 size_t in_len = enc->read(in, 1, len, enc->stream);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
169 SHA256_Update(&enc->sha256, in, in_len);
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
170
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 unsigned char *out = NULL;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 int outlen = 0;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 size_t ivl = enc->ivlen;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 if(in_len != 0) {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 outlen = len + 16;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 out = malloc(outlen + ivl);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 if(enc->iv) {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 memcpy(out, enc->iv, ivl);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 }
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 EVP_EncryptUpdate(&enc->ctx, out + ivl, &outlen, in, in_len);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 free(in);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 } else {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 out = malloc(16);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 EVP_EncryptFinal_ex(&enc->ctx, out, &outlen);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 enc->end = 1;
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
186 free(in);
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 }
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 enc->tmp = (char*)out;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 enc->tmplen = outlen + ivl;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 enc->tmpoff = 0;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 if(enc->iv) {
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
193 free(enc->iv);
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 enc->iv = NULL;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 enc->ivlen = 0;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 }
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 return aes_read(buf, s, n, enc);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 }
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201 void aes_encrypter_close(AESEncrypter *enc) {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 if(enc->tmp) {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 free(enc->tmp);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 }
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
205 if(enc->iv) {
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
206 free(enc->iv);
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
207 }
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 EVP_CIPHER_CTX_cleanup(&enc->ctx);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 free(enc);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 }
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
213 char* aes_encrypt(char *in, size_t len, DavKey *key) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
214 unsigned char iv[16];
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215 if(!RAND_bytes(iv, 16)) {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216 return NULL;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 }
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 EVP_CIPHER_CTX ctx;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 EVP_CIPHER_CTX_init(&ctx);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 if(key->type == DAV_KEY_AES128) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
222 EVP_EncryptInit_ex(
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
223 &ctx,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
224 EVP_aes_128_cbc(),
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
225 NULL,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
226 (unsigned char*)key->data,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
227 iv);
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228 } else if(key->type == DAV_KEY_AES256) {
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
229 EVP_EncryptInit_ex(
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
230 &ctx,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
231 EVP_aes_256_cbc(),
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
232 NULL,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
233 (unsigned char*)key->data,
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
234 iv);
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 } else {
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
236 EVP_CIPHER_CTX_cleanup(&ctx);
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237 return NULL;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238 }
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
240 //int len = strlen(in);
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 int buflen = len + 64;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
242 unsigned char *buf = calloc(1, buflen);
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243 memcpy(buf, iv, 16);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245 int l = buflen - 16;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
246 EVP_EncryptUpdate(&ctx, buf + 16, &l, (unsigned char*)in, len);
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248 int f = 0;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249 EVP_EncryptFinal_ex(&ctx, buf + 16 + l, &f);
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
250 char *out = util_base64encode((char*)buf, 16 + l + f);
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251 free(buf);
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
252 EVP_CIPHER_CTX_cleanup(&ctx);
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
253
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
254 return out;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255 }
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
257 char* aes_decrypt(char *in, size_t *length, DavKey *key) {
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 int len;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
259 unsigned char *buf = (unsigned char*)util_base64decode_len(in, &len);
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 EVP_CIPHER_CTX ctx;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262 EVP_CIPHER_CTX_init(&ctx);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263 if(key->type == DAV_KEY_AES128) {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264 EVP_DecryptInit_ex(
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265 &ctx,
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266 EVP_aes_128_cbc(),
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 NULL,
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 key->data,
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 buf);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 } else if(key->type == DAV_KEY_AES256) {
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271 EVP_DecryptInit_ex(
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
272 &ctx,
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
273 EVP_aes_256_cbc(),
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
274 NULL,
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275 key->data,
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
276 buf);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
277 } else {
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
278 EVP_CIPHER_CTX_cleanup(&ctx);
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
279 return NULL;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
280 }
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
281
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
282 unsigned char *out = malloc(len + 1);
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283 int outlen = len;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
284 unsigned char *in_buf = buf + 16;
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285 int inlen = len - 16;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
286 int f = 0;
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288 EVP_DecryptUpdate(&ctx, out, &outlen, in_buf, inlen);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
289 EVP_DecryptFinal_ex(&ctx, out + outlen, &f);
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
290 out[outlen + f] = '\0';
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291 free(buf);
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
292 EVP_CIPHER_CTX_cleanup(&ctx);
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
293
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
294 *length = outlen + f;
43
03076907b58a added file name encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
295 return (char*)out;
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296 }
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
297
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
298
207
de23f8881e9f fixed hash verification and head requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
299 void dav_get_hash(SHA256_CTX *sha256, unsigned char *buf) {
155
b85248a8aee2 fixed some cases of incompatible types in crypto functions
Mike Becker <universe@uap-core.de>
parents: 150
diff changeset
300 SHA256_Final((unsigned char*)buf, sha256);
150
37fb12574acd added checksums for encrypted resources
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 75
diff changeset
301 }

mercurial