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

Macros

#define NAME   "rol"
 

Enumerations

enum  { MAX_rol_KEY_SIZE = 32768 }
 

Functions

static bool rol_init_state (struct rol_state *const state, const ut8 *key, int keylen)
 
static void rol_crypt (struct rol_state *const state, const ut8 *inbuf, ut8 *outbuf, int buflen)
 
static bool rol_set_key (RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction)
 
static int rol_get_key_size (RzCrypto *cry)
 
static bool rol_use (const char *algo)
 
static bool update (RzCrypto *cry, const ut8 *buf, int len)
 
static bool rol_init (RzCrypto *cry)
 
static bool rol_fini (RzCrypto *cry)
 

Variables

RzCryptoPlugin rz_crypto_plugin_rol
 
RZ_API RzLibStruct rizin_plugin
 

Macro Definition Documentation

◆ NAME

#define NAME   "rol"

Definition at line 8 of file crypto_rol.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
MAX_rol_KEY_SIZE 

Definition at line 10 of file crypto_rol.c.

10 { MAX_rol_KEY_SIZE = 32768 };
@ MAX_rol_KEY_SIZE
Definition: crypto_rol.c:10

Function Documentation

◆ rol_crypt()

static void rol_crypt ( struct rol_state *const  state,
const ut8 inbuf,
ut8 outbuf,
int  buflen 
)
static

Definition at line 29 of file crypto_rol.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().

◆ rol_fini()

static bool rol_fini ( RzCrypto cry)
static

Definition at line 82 of file crypto_rol.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.

◆ rol_get_key_size()

static int rol_get_key_size ( RzCrypto cry)
static

Definition at line 46 of file crypto_rol.c.

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

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

◆ rol_init()

static bool rol_init ( RzCrypto cry)
static

Definition at line 75 of file crypto_rol.c.

75  {
76  rz_return_val_if_fail(cry, false);
77 
78  cry->user = RZ_NEW0(struct rol_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.

◆ rol_init_state()

static bool rol_init_state ( struct rol_state *const  state,
const ut8 key,
int  keylen 
)
static

Definition at line 17 of file crypto_rol.c.

17  {
18  if (!state || !key || keylen < 1 || keylen > MAX_rol_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_rol_KEY_SIZE.

Referenced by rol_set_key().

◆ rol_set_key()

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

Definition at line 38 of file crypto_rol.c.

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

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

◆ rol_use()

static bool rol_use ( const char *  algo)
static

Definition at line 53 of file crypto_rol.c.

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

References NAME.

◆ update()

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

Definition at line 57 of file crypto_rol.c.

57  {
58  rz_return_val_if_fail(cry->user, false);
59  struct rol_state *st = (struct rol_state *)cry->user;
60 
61  if (cry->dir) {
62  eprintf("Use ROR algorithm to decrypt\n");
63  return false;
64  }
65  ut8 *obuf = calloc(1, len);
66  if (!obuf) {
67  return false;
68  }
69  rol_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 rol_crypt(struct rol_state *const state, const ut8 *inbuf, ut8 *outbuf, int buflen)
Definition: crypto_rol.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, rol_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_rol
Definition: crypto_rol.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_rol.c.

◆ rz_crypto_plugin_rol

RzCryptoPlugin rz_crypto_plugin_rol
Initial value:
= {
.name = NAME,
.author = "pancake",
.license = "LGPL-3",
.set_key = rol_set_key,
.get_key_size = rol_get_key_size,
.use = rol_use,
.update = update,
.final = update,
.init = rol_init,
.fini = rol_fini,
}
static bool rol_init(RzCrypto *cry)
Definition: crypto_rol.c:75
static bool update(RzCrypto *cry, const ut8 *buf, int len)
Definition: crypto_rol.c:57
static bool rol_use(const char *algo)
Definition: crypto_rol.c:53
static bool rol_set_key(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction)
Definition: crypto_rol.c:38
static bool rol_fini(RzCrypto *cry)
Definition: crypto_rol.c:82
static int rol_get_key_size(RzCrypto *cry)
Definition: crypto_rol.c:46

Definition at line 89 of file crypto_rol.c.