Rizin
unix-like reverse engineering framework and cli tools
zip_crypto_mbedtls.h File Reference
#include <mbedtls/aes.h>
#include <mbedtls/md.h>

Go to the source code of this file.

Macros

#define HAVE_SECURE_RANDOM
 
#define _zip_crypto_aes_t   mbedtls_aes_context
 
#define _zip_crypto_hmac_t   mbedtls_md_context_t
 
#define _zip_crypto_aes_encrypt_block(aes, in, out)   (mbedtls_aes_crypt_ecb((aes), MBEDTLS_AES_ENCRYPT, (in), (out)) == 0)
 
#define _zip_crypto_hmac(hmac, data, length)   (mbedtls_md_hmac_update((hmac), (data), (length)) == 0)
 
#define _zip_crypto_hmac_output(hmac, data)   (mbedtls_md_hmac_finish((hmac), (data)) == 0)
 

Functions

_zip_crypto_aes_t_zip_crypto_aes_new (const zip_uint8_t *key, zip_uint16_t key_size, zip_error_t *error)
 
void _zip_crypto_aes_free (_zip_crypto_aes_t *aes)
 
_zip_crypto_hmac_t_zip_crypto_hmac_new (const zip_uint8_t *secret, zip_uint64_t secret_length, zip_error_t *error)
 
void _zip_crypto_hmac_free (_zip_crypto_hmac_t *hmac)
 
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)
 

Macro Definition Documentation

◆ _zip_crypto_aes_encrypt_block

#define _zip_crypto_aes_encrypt_block (   aes,
  in,
  out 
)    (mbedtls_aes_crypt_ecb((aes), MBEDTLS_AES_ENCRYPT, (in), (out)) == 0)

Definition at line 46 of file zip_crypto_mbedtls.h.

◆ _zip_crypto_aes_t

#define _zip_crypto_aes_t   mbedtls_aes_context

Definition at line 42 of file zip_crypto_mbedtls.h.

◆ _zip_crypto_hmac

#define _zip_crypto_hmac (   hmac,
  data,
  length 
)    (mbedtls_md_hmac_update((hmac), (data), (length)) == 0)

Definition at line 50 of file zip_crypto_mbedtls.h.

◆ _zip_crypto_hmac_output

#define _zip_crypto_hmac_output (   hmac,
  data 
)    (mbedtls_md_hmac_finish((hmac), (data)) == 0)

Definition at line 51 of file zip_crypto_mbedtls.h.

◆ _zip_crypto_hmac_t

#define _zip_crypto_hmac_t   mbedtls_md_context_t

Definition at line 43 of file zip_crypto_mbedtls.h.

◆ HAVE_SECURE_RANDOM

#define HAVE_SECURE_RANDOM

Definition at line 37 of file zip_crypto_mbedtls.h.

Function Documentation

◆ _zip_crypto_aes_free()

void _zip_crypto_aes_free ( _zip_crypto_aes_t aes)

Definition at line 44 of file zip_crypto_commoncrypto.c.

44  {
45  if (aes == NULL) {
46  return;
47  }
48 
49  CCCryptorRelease(aes);
50 }
#define NULL
Definition: cris-opc.c:27

◆ _zip_crypto_aes_new()

_zip_crypto_aes_t* _zip_crypto_aes_new ( const zip_uint8_t key,
zip_uint16_t  key_size,
zip_error_t error 
)

Definition at line 62 of file zip_crypto_commoncrypto.c.

62  {
63  _zip_crypto_aes_t *aes;
64  CCCryptorStatus ret;
65 
66  ret = CCCryptorCreate(kCCEncrypt, kCCAlgorithmAES, kCCOptionECBMode, key, key_size / 8, NULL, &aes);
67 
68  switch (ret) {
69  case kCCSuccess:
70  return aes;
71 
72  case kCCMemoryFailure:
74  return NULL;
75 
76  case kCCParamError:
78  return NULL;
79 
80  default:
82  return NULL;
83  }
84 }
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
Definition: sflib.h:118
#define ZIP_ER_INTERNAL
Definition: zip.h:125
ZIP_EXTERN void zip_error_set(zip_error_t *_Nullable, int, int)
Definition: zip_error.c:126
#define ZIP_ER_MEMORY
Definition: zip.h:119
#define ZIP_ER_INVAL
Definition: zip.h:123
void error(const char *msg)
Definition: untgz.c:593

◆ _zip_crypto_hmac_free()

void _zip_crypto_hmac_free ( _zip_crypto_hmac_t hmac)

Definition at line 88 of file zip_crypto_commoncrypto.c.

88  {
89  if (hmac == NULL) {
90  return;
91  }
92 
93  _zip_crypto_clear(hmac, sizeof(*hmac));
94  free(hmac);
95 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
#define _zip_crypto_clear(b, l)
Definition: zipint.h:489

◆ _zip_crypto_hmac_new()

_zip_crypto_hmac_t* _zip_crypto_hmac_new ( const zip_uint8_t secret,
zip_uint64_t  secret_length,
zip_error_t error 
)

Definition at line 99 of file zip_crypto_commoncrypto.c.

99  {
100  _zip_crypto_hmac_t *hmac;
101 
102  if ((hmac = (_zip_crypto_hmac_t *)malloc(sizeof(*hmac))) == NULL) {
104  return NULL;
105  }
106 
107  CCHmacInit(hmac, kCCHmacAlgSHA1, secret, secret_length);
108 
109  return hmac;
110 }
void * malloc(size_t size)
Definition: malloc.c:123

◆ _zip_crypto_pbkdf2()

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 
)

Definition at line 116 of file zip_crypto_mbedtls.c.

116  {
117  mbedtls_md_context_t sha1_ctx;
118  bool ok = true;
119 
120  mbedtls_md_init(&sha1_ctx);
121 
122  if (mbedtls_md_setup(&sha1_ctx, mbedtls_md_info_from_type(MBEDTLS_MD_SHA1), 1) != 0) {
123  ok = false;
124  }
125 
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) {
127  ok = false;
128  }
129 
130  mbedtls_md_free(&sha1_ctx);
131  return ok;
132 }
@ ok
Definition: lz4.c:1706
unsigned int uint32_t
Definition: sftypes.h:29
diff_output_t output
Definition: zipcmp.c:237

References key, ok, and output.