Rizin
unix-like reverse engineering framework and cli tools
zip_crypto_gnutls.c File Reference
#include <stdlib.h>
#include "zipint.h"
#include "zip_crypto.h"

Go to the source code of this file.

Functions

_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)
 
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)
 
ZIP_EXTERN bool zip_secure_random (zip_uint8_t *buffer, zip_uint16_t length)
 

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 71 of file zip_crypto_gnutls.c.

71  {
72  switch (aes->key_size) {
73  case 128:
75  break;
76  case 192:
78  break;
79  case 256:
81  break;
82  }
83 
84  return true;
85 }
void nettle_aes128_encrypt(const struct aes128_ctx *ctx, size_t length, uint8_t *dst, const uint8_t *src)
void nettle_aes192_encrypt(const struct aes192_ctx *ctx, size_t length, uint8_t *dst, const uint8_t *src)
void nettle_aes256_encrypt(const struct aes256_ctx *ctx, size_t length, uint8_t *dst, const uint8_t *src)
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
union _zip_crypto_aes_t::@409 ctx
struct aes256_ctx ctx_256
struct aes128_ctx ctx_128
zip_uint16_t key_size
struct aes192_ctx ctx_192
#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, nettle_aes128_encrypt(), nettle_aes192_encrypt(), nettle_aes256_encrypt(), out, and ZIP_CRYPTO_AES_BLOCK_LENGTH.

◆ _zip_crypto_aes_free()

void _zip_crypto_aes_free ( _zip_crypto_aes_t aes)

Definition at line 88 of file zip_crypto_gnutls.c.

88  {
89  if (aes == NULL) {
90  return;
91  }
92 
93  _zip_crypto_clear(aes, sizeof(*aes));
94  free(aes);
95 }
#define NULL
Definition: cris-opc.c:27
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(), and NULL.

◆ _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 41 of file zip_crypto_gnutls.c.

41  {
42  _zip_crypto_aes_t *aes;
43 
44  if ((aes = (_zip_crypto_aes_t *)malloc(sizeof(*aes))) == NULL) {
46  return NULL;
47  }
48 
49  aes->key_size = key_size;
50 
51  switch (aes->key_size) {
52  case 128:
54  break;
55  case 192:
57  break;
58  case 256:
60  break;
61  default:
63  free(aes);
64  return NULL;
65  }
66 
67  return aes;
68 }
void nettle_aes128_set_encrypt_key(struct aes128_ctx *ctx, const uint8_t *key)
void nettle_aes192_set_encrypt_key(struct aes192_ctx *ctx, const uint8_t *key)
void nettle_aes256_set_encrypt_key(struct aes256_ctx *ctx, const uint8_t *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 key
Definition: sflib.h:118
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 * malloc(size_t size)
Definition: malloc.c:123
void error(const char *msg)
Definition: untgz.c:593

References _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(), nettle_aes128_set_encrypt_key(), nettle_aes192_set_encrypt_key(), nettle_aes256_set_encrypt_key(), NULL, ZIP_ER_INVAL, ZIP_ER_MEMORY, and zip_error_set().

◆ _zip_crypto_hmac_free()

void _zip_crypto_hmac_free ( _zip_crypto_hmac_t hmac)

Definition at line 118 of file zip_crypto_gnutls.c.

118  {
120 
121  if (hmac == NULL) {
122  return;
123  }
124 
125  gnutls_hmac_deinit(*hmac, buf);
126  _zip_crypto_clear(hmac, sizeof(*hmac));
127  free(hmac);
128 }
voidpf void * buf
Definition: ioapi.h:138
#define ZIP_CRYPTO_SHA1_LENGTH
Definition: zip_crypto.h:37
uint8_t zip_uint8_t
Definition: zipconf.h:33

References _zip_crypto_clear, free(), NULL, and ZIP_CRYPTO_SHA1_LENGTH.

◆ _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_gnutls.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  if (gnutls_hmac_init(hmac, GNUTLS_MAC_SHA1, secret, secret_length) < 0) {
109  free(hmac);
110  return NULL;
111  }
112 
113  return hmac;
114 }
#define ZIP_ER_INTERNAL
Definition: zip.h:125

References error(), free(), malloc(), NULL, ZIP_ER_INTERNAL, ZIP_ER_MEMORY, and zip_error_set().

◆ zip_secure_random()

ZIP_EXTERN bool zip_secure_random ( zip_uint8_t buffer,
zip_uint16_t  length 
)

Definition at line 132 of file zip_crypto_gnutls.c.

132  {
133  return gnutls_rnd(GNUTLS_RND_KEY, buffer, length) == 0;
134 }
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
Definition: buffer.h:15

References length.

Referenced by encrypt_header(), and main().