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

Go to the source code of this file.

Classes

struct  xor_state
 

Macros

#define MAX_xor_KEY_SIZE   32768
 

Functions

static bool xor_init_state (struct xor_state *const state, const ut8 *key, int keylen)
 
static void xor_crypt (struct xor_state *const state, const ut8 *inbuf, ut8 *outbuf, int buflen)
 
static bool xor_set_key (RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction)
 
static int xor_get_key_size (RzCrypto *cry)
 
static bool xor_use (const char *algo)
 
static bool update (RzCrypto *cry, const ut8 *buf, int len)
 
static bool final (RzCrypto *cry, const ut8 *buf, int len)
 
static bool xor_init (RzCrypto *cry)
 
static bool xor_fini (RzCrypto *cry)
 

Variables

RzCryptoPlugin rz_crypto_plugin_xor
 
RZ_API RzLibStruct rizin_plugin
 

Macro Definition Documentation

◆ MAX_xor_KEY_SIZE

#define MAX_xor_KEY_SIZE   32768

Definition at line 8 of file crypto_xor.c.

Function Documentation

◆ final()

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

Definition at line 68 of file crypto_xor.c.

68  {
69  return update(cry, buf, len);
70 }
size_t len
Definition: 6502dis.c:15
static bool update(RzCrypto *cry, const ut8 *buf, int len)
Definition: crypto_xor.c:54
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 54 of file crypto_xor.c.

54  {
55  rz_return_val_if_fail(cry->user, false);
56  struct xor_state *st = (struct xor_state *)cry->user;
57 
58  ut8 *obuf = calloc(1, len);
59  if (!obuf) {
60  return false;
61  }
62  xor_crypt(st, buf, obuf, len);
63  rz_crypto_append(cry, obuf, len);
64  free(obuf);
65  return true;
66 }
RZ_API int rz_crypto_append(RzCrypto *cry, const ut8 *buf, int len)
Definition: crypto.c:175
static void xor_crypt(struct xor_state *const state, const ut8 *inbuf, ut8 *outbuf, int buflen)
Definition: crypto_xor.c:29
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
uint8_t ut8
Definition: lh5801.h:11
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
void * user
Definition: rz_crypto.h:36
static unsigned char * obuf
Definition: z80asm.c:36

References calloc(), free(), len, obuf, rz_crypto_append(), rz_return_val_if_fail, rz_crypto_t::user, and xor_crypt().

Referenced by final().

◆ xor_crypt()

static void xor_crypt ( struct xor_state *const  state,
const ut8 inbuf,
ut8 outbuf,
int  buflen 
)
static

Definition at line 29 of file crypto_xor.c.

29  {
30  int i; // index for input
31  for (i = 0; i < buflen; i++) {
32  outbuf[i] = inbuf[i] ^ state->key[(i % state->key_size)];
33  }
34 }
lzma_index ** i
Definition: index.h:629
unsigned char outbuf[SIZE]
Definition: gun.c:162
unsigned char inbuf[SIZE]
Definition: gun.c:161
Definition: dis.h:43
ut64 buflen
Definition: core.c:76

References buflen, i, inbuf, and outbuf.

Referenced by update().

◆ xor_fini()

static bool xor_fini ( RzCrypto cry)
static

Definition at line 79 of file crypto_xor.c.

79  {
80  rz_return_val_if_fail(cry, false);
81  struct xor_state *state = (struct xor_state *)cry->user;
82 
83  if (state) {
84  free(state->key);
85  }
86  free(cry->user);
87  return true;
88 }
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4

References free(), if(), rz_return_val_if_fail, and rz_crypto_t::user.

◆ xor_get_key_size()

static int xor_get_key_size ( RzCrypto cry)
static

Definition at line 43 of file crypto_xor.c.

43  {
44  rz_return_val_if_fail(cry->user, 0);
45  struct xor_state *st = (struct xor_state *)cry->user;
46 
47  return st->key_size;
48 }
int key_size
Definition: crypto_xor.c:12

References xor_state::key_size, rz_return_val_if_fail, and rz_crypto_t::user.

◆ xor_init()

static bool xor_init ( RzCrypto cry)
static

Definition at line 72 of file crypto_xor.c.

72  {
73  rz_return_val_if_fail(cry, false);
74 
75  cry->user = RZ_NEW0(struct xor_state);
76  return cry->user != NULL;
77 }
#define NULL
Definition: cris-opc.c:27
#define RZ_NEW0(x)
Definition: rz_types.h:284

References NULL, RZ_NEW0, rz_return_val_if_fail, and rz_crypto_t::user.

◆ xor_init_state()

static bool xor_init_state ( struct xor_state *const  state,
const ut8 key,
int  keylen 
)
static

Definition at line 15 of file crypto_xor.c.

15  {
16  if (!state || !key || keylen < 1) { // || keylen > MAX_xor_KEY_SIZE) {
17  return false;
18  }
19  state->key_size = keylen;
20  state->key = malloc(keylen);
21  if (!state->key) {
22  return false;
23  }
24  memcpy(state->key, key, keylen);
25  return true;
26 }
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
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
void * malloc(size_t size)
Definition: malloc.c:123

References key, malloc(), and memcpy().

Referenced by xor_set_key().

◆ xor_set_key()

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

Definition at line 36 of file crypto_xor.c.

36  {
37  rz_return_val_if_fail(cry->user, 0);
38  struct xor_state *st = (struct xor_state *)cry->user;
39 
40  return xor_init_state(st, key, keylen);
41 }
static bool xor_init_state(struct xor_state *const state, const ut8 *key, int keylen)
Definition: crypto_xor.c:15

References key, rz_return_val_if_fail, rz_crypto_t::user, and xor_init_state().

◆ xor_use()

static bool xor_use ( const char *  algo)
static

Definition at line 50 of file crypto_xor.c.

50  {
51  return !strcmp(algo, "xor");
52 }

Variable Documentation

◆ rizin_plugin

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

Definition at line 104 of file crypto_xor.c.

◆ rz_crypto_plugin_xor

RzCryptoPlugin rz_crypto_plugin_xor
Initial value:
= {
.name = "xor",
.author = "pancake",
.license = "LGPL-3",
.set_key = xor_set_key,
.get_key_size = xor_get_key_size,
.use = xor_use,
.update = update,
.final = final,
.init = xor_init,
.fini = xor_fini,
}
static bool xor_set_key(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction)
Definition: crypto_xor.c:36
static int xor_get_key_size(RzCrypto *cry)
Definition: crypto_xor.c:43
static bool xor_fini(RzCrypto *cry)
Definition: crypto_xor.c:79
static bool xor_use(const char *algo)
Definition: crypto_xor.c:50
static bool xor_init(RzCrypto *cry)
Definition: crypto_xor.c:72

Definition at line 90 of file crypto_xor.c.