| 856 CC_SHA256_Update(ctx, data, len); |
856 CC_SHA256_Update(ctx, data, len); |
| 857 } |
857 } |
| 858 |
858 |
| 859 void dav_sha256_final(DAV_SHA_CTX *ctx, unsigned char *buf) { |
859 void dav_sha256_final(DAV_SHA_CTX *ctx, unsigned char *buf) { |
| 860 CC_SHA256_Final(buf, ctx); |
860 CC_SHA256_Final(buf, ctx); |
| 861 free(ctx); |
|
| 862 } |
861 } |
| 863 |
862 |
| 864 DavKey* dav_pw2key(const char *password, const unsigned char *salt, int saltlen, int pwfunc, int enc) { |
863 DavKey* dav_pw2key(const char *password, const unsigned char *salt, int saltlen, int pwfunc, int enc) { |
| 865 if(!password) { |
864 if(!password) { |
| 866 return NULL; |
865 return NULL; |
| 1424 char* dav_create_hash(const char *data, size_t len) { |
1423 char* dav_create_hash(const char *data, size_t len) { |
| 1425 unsigned char hash[DAV_SHA256_DIGEST_LENGTH]; |
1424 unsigned char hash[DAV_SHA256_DIGEST_LENGTH]; |
| 1426 DAV_SHA_CTX *ctx = dav_sha256_create(); |
1425 DAV_SHA_CTX *ctx = dav_sha256_create(); |
| 1427 if(ctx) { |
1426 if(ctx) { |
| 1428 dav_sha256_update(ctx, data, len); |
1427 dav_sha256_update(ctx, data, len); |
| 1429 dav_sha256_final(ctx, hash); |
1428 dav_sha256_final_free(ctx, hash); |
| 1430 } |
1429 } |
| 1431 return util_hexstr(hash, DAV_SHA256_DIGEST_LENGTH); |
1430 return util_hexstr(hash, DAV_SHA256_DIGEST_LENGTH); |
| 1432 } |
1431 } |
| 1433 |
1432 |
| 1434 DAV_SHA_CTX* dav_sha256_create(void) { |
1433 DAV_SHA_CTX* dav_sha256_create(void) { |
| 1450 void dav_sha256_final(DAV_SHA_CTX *ctx, unsigned char *buf) { |
1449 void dav_sha256_final(DAV_SHA_CTX *ctx, unsigned char *buf) { |
| 1451 BCryptFinishHash(ctx->hHash, (PUCHAR)buf, DAV_SHA256_DIGEST_LENGTH, 0); |
1450 BCryptFinishHash(ctx->hHash, (PUCHAR)buf, DAV_SHA256_DIGEST_LENGTH, 0); |
| 1452 |
1451 |
| 1453 // cleanup |
1452 // cleanup |
| 1454 cng_cleanup(ctx->hAlg, NULL, ctx->hHash, ctx->pbHashObject); |
1453 cng_cleanup(ctx->hAlg, NULL, ctx->hHash, ctx->pbHashObject); |
| 1455 free(ctx); |
|
| 1456 } |
1454 } |
| 1457 |
1455 |
| 1458 DavKey* dav_pw2key(const char *password, const unsigned char *salt, int saltlen, int pwfunc, int enc) { |
1456 DavKey* dav_pw2key(const char *password, const unsigned char *salt, int saltlen, int pwfunc, int enc) { |
| 1459 if(!password) { |
1457 if(!password) { |
| 1460 return NULL; |
1458 return NULL; |
| 1516 memcpy(key->data, keydata, keylen); |
1514 memcpy(key->data, keydata, keylen); |
| 1517 return key; |
1515 return key; |
| 1518 } |
1516 } |
| 1519 #endif |
1517 #endif |
| 1520 |
1518 |
| 1521 |
1519 void dav_sha256_final_free(DAV_SHA_CTX *ctx, unsigned char *buf) { |
| |
1520 dav_sha256_final(ctx, buf); |
| |
1521 free(ctx); |
| |
1522 } |
| 1522 |
1523 |
| 1523 CxBuffer* aes_encrypt_buffer(CxBuffer *in, DavKey *key) { |
1524 CxBuffer* aes_encrypt_buffer(CxBuffer *in, DavKey *key) { |
| 1524 CxBuffer *encbuf = cxBufferCreate(NULL, in->size, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); |
1525 CxBuffer *encbuf = cxBufferCreate(NULL, in->size, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); |
| 1525 if(!encbuf) { |
1526 if(!encbuf) { |
| 1526 return NULL; |
1527 return NULL; |