149:509e9e1cbdcc | 150:37fb12574acd |
---|---|
31 | 31 |
32 #include "webdav.h" | 32 #include "webdav.h" |
33 #include <openssl/evp.h> | 33 #include <openssl/evp.h> |
34 #include <ucx/string.h> | 34 #include <ucx/string.h> |
35 | 35 |
36 #ifdef __sun | |
37 #include <sha2.h> | |
38 #else | |
39 #include <openssl/sha.h> | |
40 #endif | |
41 | |
36 #ifdef __cplusplus | 42 #ifdef __cplusplus |
37 extern "C" { | 43 extern "C" { |
38 #endif | 44 #endif |
39 | 45 |
40 typedef struct { | 46 typedef struct { |
41 EVP_CIPHER_CTX ctx; | 47 EVP_CIPHER_CTX ctx; |
48 SHA256_CTX sha256; | |
42 void *stream; | 49 void *stream; |
43 dav_write_func write; | 50 dav_write_func write; |
44 DavKey *key; | 51 DavKey *key; |
45 int init; | 52 int init; |
46 unsigned char ivtmp[16]; | 53 unsigned char ivtmp[16]; |
47 size_t ivpos; | 54 size_t ivpos; |
48 } AESDecrypter; | 55 } AESDecrypter; |
49 | 56 |
50 typedef struct { | 57 typedef struct { |
51 EVP_CIPHER_CTX ctx; | 58 EVP_CIPHER_CTX ctx; |
59 SHA256_CTX sha256; | |
52 void *iv; | 60 void *iv; |
53 size_t ivlen; | 61 size_t ivlen; |
54 void *stream; | 62 void *stream; |
55 dav_read_func read; | 63 dav_read_func read; |
56 char *tmp; | 64 char *tmp; |
66 | 74 |
67 AESEncrypter* aes_encrypter_new(DavKey *key, void *stream, dav_read_func read_func); | 75 AESEncrypter* aes_encrypter_new(DavKey *key, void *stream, dav_read_func read_func); |
68 size_t aes_read(void *buf, size_t s, size_t n, AESEncrypter *enc); | 76 size_t aes_read(void *buf, size_t s, size_t n, AESEncrypter *enc); |
69 void aes_encrypter_close(AESEncrypter *enc); | 77 void aes_encrypter_close(AESEncrypter *enc); |
70 | 78 |
71 char* aes_encrypt(char *in, DavKey *key); | 79 char* aes_encrypt(char *in, size_t len, DavKey *key); |
72 char* aes_decrypt(char *in, DavKey *key); | 80 char* aes_decrypt(char *in, size_t *len, DavKey *key); |
81 | |
82 void dav_get_hash(SHA256_CTX *sha256, char *buf); | |
73 | 83 |
74 #ifdef __cplusplus | 84 #ifdef __cplusplus |
75 } | 85 } |
76 #endif | 86 #endif |
77 | 87 |