Rizin
unix-like reverse engineering framework and cli tools
crypto_ror.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  ror_state
 

Macros

#define NAME   "ror"
 

Enumerations

enum  { MAX_ror_KEY_SIZE = 32768 }
 

Functions

static bool ror_init_state (struct ror_state *const state, const ut8 *key, int keylen)
 
static void ror_crypt (struct ror_state *const state, const ut8 *inbuf, ut8 *outbuf, int buflen)
 
static bool ror_set_key (RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction)
 
static int ror_get_key_size (RzCrypto *cry)
 
static bool ror_use (const char *algo)
 
static bool update (RzCrypto *cry, const ut8 *buf, int len)
 
static bool ror_init (RzCrypto *cry)
 
static bool ror_fini (RzCrypto *cry)
 

Variables

RzCryptoPlugin rz_crypto_plugin_ror
 
RZ_API RzLibStruct rizin_plugin
 

Macro Definition Documentation

◆ NAME

#define NAME   "ror"

Definition at line 8 of file crypto_ror.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
MAX_ror_KEY_SIZE 

Definition at line 10 of file crypto_ror.c.

10 { MAX_ror_KEY_SIZE = 32768 };
@ MAX_ror_KEY_SIZE
Definition: crypto_ror.c:10

Function Documentation

◆ ror_crypt()

static void ror_crypt ( struct ror_state *const  state,
const ut8 inbuf,
ut8 outbuf,
int  buflen 
)
static

Definition at line 29 of file crypto_ror.c.

29  {
30  int i;
31  for (i = 0; i < buflen; i++) {
32  ut8 count = state->key[i % state->key_size] & 7;
33  ut8 inByte = inbuf[i];
34  outbuf[i] = (inByte >> count) | (inByte << ((8 - count) & 7));
35  }
36 }
lzma_index ** i
Definition: index.h:629
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 count
Definition: sflib.h:98
unsigned char outbuf[SIZE]
Definition: gun.c:162
unsigned char inbuf[SIZE]
Definition: gun.c:161
uint8_t ut8
Definition: lh5801.h:11
Definition: dis.h:43
ut64 buflen
Definition: core.c:76

References buflen, count, i, inbuf, and outbuf.

Referenced by update().

◆ ror_fini()

static bool ror_fini ( RzCrypto cry)
static

Definition at line 82 of file crypto_ror.c.

82  {
83  rz_return_val_if_fail(cry, false);
84 
85  free(cry->user);
86  return true;
87 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
void * user
Definition: rz_crypto.h:36

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

◆ ror_get_key_size()

static int ror_get_key_size ( RzCrypto cry)
static

Definition at line 46 of file crypto_ror.c.

46  {
47  rz_return_val_if_fail(cry->user, 0);
48  struct ror_state *st = (struct ror_state *)cry->user;
49 
50  return st->key_size;
51 }
int key_size
Definition: crypto_ror.c:14

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

◆ ror_init()

static bool ror_init ( RzCrypto cry)
static

Definition at line 75 of file crypto_ror.c.

75  {
76  rz_return_val_if_fail(cry, false);
77 
78  cry->user = RZ_NEW0(struct ror_state);
79  return cry->user != NULL;
80 }
#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.

◆ ror_init_state()

static bool ror_init_state ( struct ror_state *const  state,
const ut8 key,
int  keylen 
)
static

Definition at line 17 of file crypto_ror.c.

17  {
18  if (!state || !key || keylen < 1 || keylen > MAX_ror_KEY_SIZE) {
19  return false;
20  }
21  int i;
22  state->key_size = keylen;
23  for (i = 0; i < keylen; i++) {
24  state->key[i] = key[i];
25  }
26  return true;
27 }
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

References i, key, and MAX_ror_KEY_SIZE.

Referenced by ror_set_key().

◆ ror_set_key()

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

Definition at line 38 of file crypto_ror.c.

38  {
39  rz_return_val_if_fail(cry->user && key, false);
40  struct ror_state *st = (struct ror_state *)cry->user;
41 
42  cry->dir = direction;
43  return ror_init_state(st, key, keylen);
44 }
static bool ror_init_state(struct ror_state *const state, const ut8 *key, int keylen)
Definition: crypto_ror.c:17

References rz_crypto_t::dir, key, ror_init_state(), rz_return_val_if_fail, and rz_crypto_t::user.

◆ ror_use()

static bool ror_use ( const char *  algo)
static

Definition at line 53 of file crypto_ror.c.

53  {
54  return !strcmp(algo, NAME);
55 }
#define NAME
Definition: crypto_ror.c:8

References NAME.

◆ update()

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

Definition at line 57 of file crypto_ror.c.

57  {
58  rz_return_val_if_fail(cry->user, false);
59  struct ror_state *st = (struct ror_state *)cry->user;
60 
61  if (cry->dir) {
62  eprintf("Use ROL algorithm to decrypt\n");
63  return false;
64  }
65  ut8 *obuf = calloc(1, len);
66  if (!obuf) {
67  return false;
68  }
69  ror_crypt(st, buf, obuf, len);
70  rz_crypto_append(cry, obuf, len);
71  free(obuf);
72  return true;
73 }
size_t len
Definition: 6502dis.c:15
RZ_API int rz_crypto_append(RzCrypto *cry, const ut8 *buf, int len)
Definition: crypto.c:175
static void ror_crypt(struct ror_state *const state, const ut8 *inbuf, ut8 *outbuf, int buflen)
Definition: crypto_ror.c:29
voidpf void * buf
Definition: ioapi.h:138
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
#define eprintf(x, y...)
Definition: rlcc.c:7
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4
static unsigned char * obuf
Definition: z80asm.c:36

References calloc(), rz_crypto_t::dir, eprintf, free(), if(), len, obuf, ror_crypt(), rz_crypto_append(), rz_return_val_if_fail, and rz_crypto_t::user.

Variable Documentation

◆ rizin_plugin

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

Definition at line 103 of file crypto_ror.c.

◆ rz_crypto_plugin_ror

RzCryptoPlugin rz_crypto_plugin_ror
Initial value:
= {
.name = NAME,
.author = "pancake",
.license = "LGPL-3",
.set_key = ror_set_key,
.get_key_size = ror_get_key_size,
.use = ror_use,
.update = update,
.final = update,
.init = ror_init,
.fini = ror_fini,
}
static int ror_get_key_size(RzCrypto *cry)
Definition: crypto_ror.c:46
static bool ror_fini(RzCrypto *cry)
Definition: crypto_ror.c:82
static bool update(RzCrypto *cry, const ut8 *buf, int len)
Definition: crypto_ror.c:57
static bool ror_use(const char *algo)
Definition: crypto_ror.c:53
static bool ror_set_key(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction)
Definition: crypto_ror.c:38
static bool ror_init(RzCrypto *cry)
Definition: crypto_ror.c:75

Definition at line 89 of file crypto_ror.c.