libidav/crypto.c

changeset 624
27985062cd2c
parent 520
da2b0cc44e4f
child 625
e1a85fbf68f9
equal deleted inserted replaced
623:7870656d302d 624:27985062cd2c
353 SHA256_Final((unsigned char*)buf, sha256); 353 SHA256_Final((unsigned char*)buf, sha256);
354 } 354 }
355 355
356 char* dav_create_hash(const char *data, size_t len) { 356 char* dav_create_hash(const char *data, size_t len) {
357 unsigned char hash[DAV_SHA256_DIGEST_LENGTH]; 357 unsigned char hash[DAV_SHA256_DIGEST_LENGTH];
358 SHA256((const unsigned char*)data, len, hash); 358 DAV_SHA_CTX ctx;
359 SHA256_Init(&ctx);
360 SHA256_Update(&ctx, data, len);
361 SHA256_Final(hash, &ctx);
359 return util_hexstr(hash, DAV_SHA256_DIGEST_LENGTH); 362 return util_hexstr(hash, DAV_SHA256_DIGEST_LENGTH);
360 } 363 }
361 364
362 DAV_SHA_CTX* dav_hash_init(void) { 365 DAV_SHA_CTX* dav_hash_init(void) {
363 DAV_SHA_CTX *ctx = malloc(sizeof(DAV_SHA_CTX)); 366 DAV_SHA_CTX *ctx = malloc(sizeof(DAV_SHA_CTX));
372 void dav_hash_final(DAV_SHA_CTX *ctx, unsigned char *buf) { 375 void dav_hash_final(DAV_SHA_CTX *ctx, unsigned char *buf) {
373 SHA256_Final(buf, ctx); 376 SHA256_Final(buf, ctx);
374 free(ctx); 377 free(ctx);
375 } 378 }
376 379
380 #if OPENSSL_VERSION_NUMBER < 0x10100000L
381 static int crypto_pw2key_error = 0;
382 DavKey* dav_pw2key(const char *password, const unsigned char *salt, int saltlen, int pwfunc, int enc) {
383 if(!crypto_pw2key_error) {
384 fprintf(stderr, "Error: password key derivation not supported on this platform: openssl to old\n");
385 crypto_pw2key_error = 1;
386 }
387 return 0;
388 }
389
390 #else
377 DavKey* dav_pw2key(const char *password, const unsigned char *salt, int saltlen, int pwfunc, int enc) { 391 DavKey* dav_pw2key(const char *password, const unsigned char *salt, int saltlen, int pwfunc, int enc) {
378 if(!password) { 392 if(!password) {
379 return NULL; 393 return NULL;
380 } 394 }
381 size_t len = strlen(password); 395 size_t len = strlen(password);
428 key->name = NULL; 442 key->name = NULL;
429 key->type = enc; 443 key->type = enc;
430 memcpy(key->data, keydata, keylen); 444 memcpy(key->data, keydata, keylen);
431 return key; 445 return key;
432 } 446 }
447 #endif
433 448
434 #endif 449 #endif
435 450
436 451
437 /* -------------------- Apple Crypto Functions -------------------- */ 452 /* -------------------- Apple Crypto Functions -------------------- */

mercurial