Rizin
unix-like reverse engineering framework and cli tools
crypto_base64.c File Reference
#include <rz_lib.h>
#include <rz_crypto.h>
#include <rz_util.h>

Go to the source code of this file.

Functions

static bool base64_set_key (RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction)
 
static int base64_get_key_size (RzCrypto *cry)
 
static bool base64_use (const char *algo)
 
static bool update (RzCrypto *cry, const ut8 *buf, int len)
 
static bool final (RzCrypto *cry, const ut8 *buf, int len)
 

Variables

RzCryptoPlugin rz_crypto_plugin_base64
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ base64_get_key_size()

static int base64_get_key_size ( RzCrypto cry)
static

Definition at line 13 of file crypto_base64.c.

13  {
14  return 0;
15 }

◆ base64_set_key()

static bool base64_set_key ( RzCrypto cry,
const ut8 key,
int  keylen,
int  mode,
int  direction 
)
static

Definition at line 8 of file crypto_base64.c.

8  {
9  cry->dir = direction;
10  return true;
11 }

References rz_crypto_t::dir.

◆ base64_use()

static bool base64_use ( const char *  algo)
static

Definition at line 17 of file crypto_base64.c.

17  {
18  return !strcmp(algo, "base64");
19 }

◆ final()

static bool final ( RzCrypto cry,
const ut8 buf,
int  len 
)
static

Definition at line 53 of file crypto_base64.c.

53  {
54  if (!buf) {
55  return true;
56  }
57  return update(cry, buf, len);
58 }
size_t len
Definition: 6502dis.c:15
static bool update(RzCrypto *cry, const ut8 *buf, int len)
Definition: crypto_base64.c:21
voidpf void * buf
Definition: ioapi.h:138

References len, and update().

◆ update()

static bool update ( RzCrypto cry,
const ut8 buf,
int  len 
)
static

Definition at line 21 of file crypto_base64.c.

21  {
22  if (len < 1) {
23  return false;
24  }
25 
26  int olen = 0;
27  ut8 *obuf = NULL;
28  if (cry->dir == RZ_CRYPTO_DIR_ENCRYPT) {
29  olen = ((len + 2) / 3) * 4;
30  obuf = malloc(olen + 1);
31  if (!obuf) {
32  return false;
33  }
34  rz_base64_encode((char *)obuf, (const ut8 *)buf, len);
35  } else {
36  olen = 4 + ((len / 4) * 3);
37  if (len > 0) {
38  olen -= (buf[len - 1] == '=') ? ((buf[len - 2] == '=') ? 2 : 1) : 0;
39  }
40  obuf = malloc(olen + 4);
41  if (!obuf) {
42  return false;
43  }
44  olen = rz_base64_decode(obuf, (const char *)buf, len);
45  }
46  if (olen > 0) {
47  rz_crypto_append(cry, obuf, olen);
48  }
49  free(obuf);
50  return true;
51 }
#define NULL
Definition: cris-opc.c:27
RZ_API int rz_crypto_append(RzCrypto *cry, const ut8 *buf, int len)
Definition: crypto.c:175
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
uint8_t ut8
Definition: lh5801.h:11
void * malloc(size_t size)
Definition: malloc.c:123
RZ_API size_t rz_base64_encode(char *bout, const ut8 *bin, size_t sz)
Definition: ubase64.c:81
RZ_API int rz_base64_decode(ut8 *bout, const char *bin, int len)
Definition: ubase64.c:48
@ RZ_CRYPTO_DIR_ENCRYPT
Definition: rz_crypto.h:23
static unsigned char * obuf
Definition: z80asm.c:36

References rz_crypto_t::dir, free(), len, malloc(), NULL, obuf, rz_base64_decode(), rz_base64_encode(), rz_crypto_append(), and RZ_CRYPTO_DIR_ENCRYPT.

Referenced by final().

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.version = RZ_VERSION
}
RzCryptoPlugin rz_crypto_plugin_base64
Definition: crypto_base64.c:60
@ RZ_LIB_TYPE_CRYPTO
Definition: rz_lib.h:81
#define RZ_VERSION
Definition: rz_version.h:8

Definition at line 72 of file crypto_base64.c.

◆ rz_crypto_plugin_base64

RzCryptoPlugin rz_crypto_plugin_base64
Initial value:
= {
.name = "base64",
.author = "rakholiyajenish.07",
.license = "LGPL-3",
.set_key = base64_set_key,
.get_key_size = base64_get_key_size,
.use = base64_use,
.update = update,
.final = final
}
static int base64_get_key_size(RzCrypto *cry)
Definition: crypto_base64.c:13
static bool base64_use(const char *algo)
Definition: crypto_base64.c:17
static bool base64_set_key(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction)
Definition: crypto_base64.c:8

Definition at line 60 of file crypto_base64.c.