Rizin
unix-like reverse engineering framework and cli tools
zip_crypto_win.h File Reference

Go to the source code of this file.

Macros

#define HAVE_SECURE_RANDOM
 

Typedefs

typedef struct _zip_crypto_aes_s _zip_crypto_aes_t
 
typedef struct _zip_crypto_hmac_s _zip_crypto_hmac_t
 

Functions

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)
 
bool _zip_crypto_aes_encrypt_block (_zip_crypto_aes_t *aes, const zip_uint8_t *in, zip_uint8_t *out)
 
bool _zip_crypto_pbkdf2 (const zip_uint8_t *key, zip_uint64_t key_length, const zip_uint8_t *salt, zip_uint16_t salt_length, zip_uint16_t iterations, zip_uint8_t *output, zip_uint16_t output_length)
 
_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_hmac (_zip_crypto_hmac_t *hmac, zip_uint8_t *data, zip_uint64_t length)
 
bool _zip_crypto_hmac_output (_zip_crypto_hmac_t *hmac, zip_uint8_t *data)
 

Macro Definition Documentation

◆ HAVE_SECURE_RANDOM

#define HAVE_SECURE_RANDOM

Definition at line 37 of file zip_crypto_win.h.

Typedef Documentation

◆ _zip_crypto_aes_t

Definition at line 1 of file zip_crypto_win.h.

◆ _zip_crypto_hmac_t

Definition at line 1 of file zip_crypto_win.h.

Function Documentation

◆ _zip_crypto_aes_encrypt_block()

bool _zip_crypto_aes_encrypt_block ( _zip_crypto_aes_t aes,
const zip_uint8_t in,
zip_uint8_t out 
)

Definition at line 54 of file zip_crypto_commoncrypto.c.

54  {
55  size_t len;
57  return true;
58 }
size_t len
Definition: 6502dis.c:15
const lzma_allocator const uint8_t * in
Definition: block.h:527
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
#define ZIP_CRYPTO_AES_BLOCK_LENGTH
Definition: zip_crypto.h:38

References _zip_crypto_aes_t::ctx, _zip_crypto_aes_t::ctx_128, _zip_crypto_aes_t::ctx_192, _zip_crypto_aes_t::ctx_256, in, _zip_crypto_aes_t::key_size, len, nettle_aes128_encrypt(), nettle_aes192_encrypt(), nettle_aes256_encrypt(), NULL, out, status, ULONG, and ZIP_CRYPTO_AES_BLOCK_LENGTH.

◆ _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

References _zip_crypto_clear, free(), and NULL.

Referenced by _zip_crypto_aes_new(), _zip_winzip_aes_free(), and _zip_winzip_aes_new().

◆ _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

References _zip_crypto_aes_free(), calloc(), _zip_crypto_aes_t::ctx, _zip_crypto_aes_t::ctx_128, _zip_crypto_aes_t::ctx_192, _zip_crypto_aes_t::ctx_256, error(), free(), key, _zip_crypto_aes_t::key_size, malloc(), memset(), nettle_aes128_set_encrypt_key(), nettle_aes192_set_encrypt_key(), nettle_aes256_set_encrypt_key(), NULL, ULONG, ZIP_ER_INTERNAL, ZIP_ER_INVAL, ZIP_ER_MEMORY, and zip_error_set().

Referenced by _zip_winzip_aes_new().

◆ _zip_crypto_hmac()

bool _zip_crypto_hmac ( _zip_crypto_hmac_t hmac,
zip_uint8_t data,
zip_uint64_t  length 
)

Definition at line 475 of file zip_crypto_win.c.

475  {
476  if (hmac == NULL || length > ULONG_MAX) {
477  return false;
478  }
479 
480  return BCRYPT_SUCCESS(BCryptHashData(hmac->hHash, data, (ULONG)length, 0));
481 }
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
Definition: sflib.h:133
BCRYPT_HASH_HANDLE hHash
ULONG

References _zip_crypto_hmac_s::hHash, length, NULL, and ULONG.

◆ _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

References _zip_crypto_clear, free(), _zip_crypto_hmac_s::hAlgorithm, _zip_crypto_hmac_s::hHash, NULL, _zip_crypto_hmac_s::pbHash, _zip_crypto_hmac_s::pbHashObject, and ZIP_CRYPTO_SHA1_LENGTH.

Referenced by _zip_crypto_hmac_new(), and _zip_winzip_aes_free().

◆ _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

References _zip_crypto_hmac_free(), calloc(), _zip_crypto_hmac_s::cbHash, _zip_crypto_hmac_s::cbHashObject, error(), free(), _zip_crypto_hmac_s::hAlgorithm, _zip_crypto_hmac_s::hHash, INT_MAX, malloc(), NULL, _zip_crypto_hmac_s::pbHash, _zip_crypto_hmac_s::pbHashObject, status, ULONG, ZIP_ER_INTERNAL, ZIP_ER_INVAL, ZIP_ER_MEMORY, and zip_error_set().

Referenced by _zip_winzip_aes_new().

◆ _zip_crypto_hmac_output()

bool _zip_crypto_hmac_output ( _zip_crypto_hmac_t hmac,
zip_uint8_t data 
)

Definition at line 174 of file zip_crypto_openssl.c.

174  {
175  unsigned int length;
176 
177  return HMAC_Final(hmac, data, &length) == 1;
178 }

References _zip_crypto_hmac_s::cbHash, _zip_crypto_hmac_s::hHash, length, and NULL.

◆ _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,
zip_uint16_t  iterations,
zip_uint8_t output,
zip_uint16_t  output_length 
)

Definition at line 91 of file zip_crypto_win.c.

91  {
92  BCRYPT_ALG_HANDLE hAlgorithm = NULL;
93  bool result;
94 
95  if (!BCRYPT_SUCCESS(BCryptOpenAlgorithmProvider(&hAlgorithm, BCRYPT_SHA1_ALGORITHM, NULL, BCRYPT_ALG_HANDLE_HMAC_FLAG))) {
96  return false;
97  }
98 
99  result = BCRYPT_SUCCESS(BCryptDeriveKeyPBKDF2(hAlgorithm, (PUCHAR)key, (ULONG)key_length, (PUCHAR)salt, salt_length, iterations, output, output_length, 0));
100 
101  BCryptCloseAlgorithmProvider(hAlgorithm, 0);
102 
103  return result;
104 }
diff_output_t output
Definition: zipcmp.c:237

References key, NULL, output, and ULONG.