40 #include <mbedtls/ctr_drbg.h>
41 #include <mbedtls/entropy.h>
42 #include <mbedtls/pkcs5.h>
55 mbedtls_aes_init(aes);
56 mbedtls_aes_setkey_enc(aes, (
const unsigned char *)
key, (
unsigned int)key_size);
67 mbedtls_aes_free(aes);
86 mbedtls_md_init(hmac);
88 if (mbedtls_md_setup(hmac, mbedtls_md_info_from_type(MBEDTLS_MD_SHA1), 1) != 0) {
94 if (mbedtls_md_hmac_starts(hmac, (
const unsigned char *)secret, (
size_t)secret_length) != 0) {
110 mbedtls_md_free(hmac);
117 mbedtls_md_context_t sha1_ctx;
120 mbedtls_md_init(&sha1_ctx);
122 if (mbedtls_md_setup(&sha1_ctx, mbedtls_md_info_from_type(MBEDTLS_MD_SHA1), 1) != 0) {
126 if (
ok && mbedtls_pkcs5_pbkdf2_hmac(&sha1_ctx, (
const unsigned char *)
key, (
size_t)key_length, (
const unsigned char *)salt, (
size_t)salt_length, (
unsigned int)iterations, (
uint32_t)output_length, (
unsigned char *)
output) != 0) {
130 mbedtls_md_free(&sha1_ctx);
143 const unsigned char *pers =
"zip_crypto_mbedtls";
150 mbedtls_entropy_init(&
ctx->entropy);
151 mbedtls_ctr_drbg_init(&
ctx->ctr_drbg);
152 if (mbedtls_ctr_drbg_seed(&
ctx->ctr_drbg, mbedtls_entropy_func, &
ctx->entropy, pers, strlen(pers)) != 0) {
153 mbedtls_ctr_drbg_free(&
ctx->ctr_drbg);
154 mbedtls_entropy_free(&
ctx->entropy);
161 return mbedtls_ctr_drbg_random(&
ctx->ctr_drbg, (
unsigned char *)
buffer, (
size_t)
length) == 0;
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len key
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
RZ_API void Ht_() free(HtName_(Ht) *ht)
ZIP_EXTERN void zip_error_set(zip_error_t *_Nullable, int, int)
void * malloc(size_t size)
mbedtls_entropy_context entropy
mbedtls_ctr_drbg_context ctr_drbg
void error(const char *msg)
bool _zip_crypto_pbkdf2(const zip_uint8_t *key, zip_uint64_t key_length, const zip_uint8_t *salt, zip_uint16_t salt_length, int iterations, zip_uint8_t *output, zip_uint64_t output_length)
void _zip_crypto_hmac_free(_zip_crypto_hmac_t *hmac)
void _zip_crypto_aes_free(_zip_crypto_aes_t *aes)
_zip_crypto_aes_t * _zip_crypto_aes_new(const zip_uint8_t *key, zip_uint16_t key_size, zip_error_t *error)
ZIP_EXTERN bool zip_secure_random(zip_uint8_t *buffer, zip_uint16_t length)
_zip_crypto_hmac_t * _zip_crypto_hmac_new(const zip_uint8_t *secret, zip_uint64_t secret_length, zip_error_t *error)