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

Go to the source code of this file.

Functions

int mod (int a, int b)
 
static bool rot_init_state (ut8 *rotkey, const ut8 *key, int keylen)
 
static void rot_crypt (ut8 key, const ut8 *inbuf, ut8 *outbuf, int buflen)
 
static void rot_decrypt (ut8 key, const ut8 *inbuf, ut8 *outbuf, int buflen)
 
static bool rot_set_key (RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction)
 
static int rot_get_key_size (RzCrypto *cry)
 
static bool rot_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 rol_init (RzCrypto *cry)
 
static bool rol_fini (RzCrypto *cry)
 

Variables

RzCryptoPlugin rz_crypto_plugin_rot
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ final()

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

Definition at line 97 of file crypto_rot.c.

97  {
98  return update(cry, buf, len);
99 }
size_t len
Definition: 6502dis.c:15
static bool update(RzCrypto *cry, const ut8 *buf, int len)
Definition: crypto_rot.c:79
voidpf void * buf
Definition: ioapi.h:138

References len, and update().

◆ mod()

◆ rol_fini()

static bool rol_fini ( RzCrypto cry)
static

Definition at line 108 of file crypto_rot.c.

108  {
109  rz_return_val_if_fail(cry, false);
110 
111  free(cry->user);
112  return true;
113 }
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_init()

static bool rol_init ( RzCrypto cry)
static

Definition at line 101 of file crypto_rot.c.

101  {
102  rz_return_val_if_fail(cry, false);
103 
104  cry->user = RZ_NEW0(ut8);
105  return cry->user != NULL;
106 }
#define NULL
Definition: cris-opc.c:27
uint8_t ut8
Definition: lh5801.h:11
#define RZ_NEW0(x)
Definition: rz_types.h:284

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

◆ rot_crypt()

static void rot_crypt ( ut8  key,
const ut8 inbuf,
ut8 outbuf,
int  buflen 
)
static

Definition at line 28 of file crypto_rot.c.

28  {
29  int i;
30  for (i = 0; i < buflen; i++) {
31  outbuf[i] = inbuf[i];
32  if ((inbuf[i] < 'a' || inbuf[i] > 'z') && (inbuf[i] < 'A' || inbuf[i] > 'Z')) {
33  continue;
34  }
35  outbuf[i] += key;
36  outbuf[i] -= (inbuf[i] >= 'a' && inbuf[i] <= 'z') ? 'a' : 'A';
37  outbuf[i] = mod(outbuf[i], 26);
38  outbuf[i] += (inbuf[i] >= 'a' && inbuf[i] <= 'z') ? 'a' : 'A';
39  }
40 }
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 static offset struct stat static buf void long static basep static whence static length const void static len key
Definition: sflib.h:118
unsigned char outbuf[SIZE]
Definition: gun.c:162
unsigned char inbuf[SIZE]
Definition: gun.c:161
ut64 buflen
Definition: core.c:76

References buflen, i, inbuf, key, mod(), and outbuf.

Referenced by update().

◆ rot_decrypt()

static void rot_decrypt ( ut8  key,
const ut8 inbuf,
ut8 outbuf,
int  buflen 
)
static

Definition at line 42 of file crypto_rot.c.

42  {
43  int i;
44  for (i = 0; i < buflen; i++) {
45  outbuf[i] = inbuf[i];
46  if ((inbuf[i] < 'a' || inbuf[i] > 'z') && (inbuf[i] < 'A' || inbuf[i] > 'Z')) {
47  continue;
48  }
49  outbuf[i] += 26; // adding so that subtracting does not make it negative
50  outbuf[i] -= key;
51  outbuf[i] -= (inbuf[i] >= 'a' && inbuf[i] <= 'z') ? 'a' : 'A';
52  outbuf[i] = mod(outbuf[i], 26);
53  outbuf[i] += (inbuf[i] >= 'a' && inbuf[i] <= 'z') ? 'a' : 'A';
54  }
55 }

References buflen, i, inbuf, key, mod(), and outbuf.

Referenced by update().

◆ rot_get_key_size()

static int rot_get_key_size ( RzCrypto cry)
static

Definition at line 70 of file crypto_rot.c.

70  {
71  // Returning number of bytes occupied by ut8
72  return 1;
73 }

◆ rot_init_state()

static bool rot_init_state ( ut8 rotkey,
const ut8 key,
int  keylen 
)
static

Definition at line 19 of file crypto_rot.c.

19  {
20  if (rotkey && key && keylen > 0) {
21  int i = atoi((const char *)key);
22  *rotkey = (ut8)mod(i, 26);
23  return true;
24  }
25  return false;
26 }
#define ut8
Definition: dcpu16.h:8

References i, key, mod(), and ut8.

Referenced by rot_set_key().

◆ rot_set_key()

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

Definition at line 57 of file crypto_rot.c.

57  {
58  rz_return_val_if_fail(cry->user && key, false);
59  ut8 *rot_key = (ut8 *)cry->user;
60 
61  if (keylen > (sizeof(ut8) * 8) || keylen < 0) {
62  return false;
63  }
64 
65  cry->dir = direction;
66 
67  return rot_init_state(rot_key, key, keylen);
68 }
static bool rot_init_state(ut8 *rotkey, const ut8 *key, int keylen)
Definition: crypto_rot.c:19
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4

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

◆ rot_use()

static bool rot_use ( const char *  algo)
static

Definition at line 75 of file crypto_rot.c.

75  {
76  return !strcmp(algo, "rot");
77 }

◆ update()

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

Definition at line 79 of file crypto_rot.c.

79  {
80  rz_return_val_if_fail(cry->user, false);
81  ut8 *rot_key = (ut8 *)cry->user;
82 
83  ut8 *obuf = calloc(1, len);
84  if (!obuf) {
85  return false;
86  }
87  if (cry->dir == RZ_CRYPTO_DIR_ENCRYPT) {
88  rot_crypt(*rot_key, buf, obuf, len);
89  } else {
90  rot_decrypt(*rot_key, buf, obuf, len);
91  }
92  rz_crypto_append(cry, obuf, len);
93  free(obuf);
94  return true;
95 }
RZ_API int rz_crypto_append(RzCrypto *cry, const ut8 *buf, int len)
Definition: crypto.c:175
static void rot_crypt(ut8 key, const ut8 *inbuf, ut8 *outbuf, int buflen)
Definition: crypto_rot.c:28
static void rot_decrypt(ut8 key, const ut8 *inbuf, ut8 *outbuf, int buflen)
Definition: crypto_rot.c:42
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
@ RZ_CRYPTO_DIR_ENCRYPT
Definition: rz_crypto.h:23
static unsigned char * obuf
Definition: z80asm.c:36

References calloc(), rz_crypto_t::dir, free(), len, obuf, rot_crypt(), rot_decrypt(), rz_crypto_append(), RZ_CRYPTO_DIR_ENCRYPT, rz_return_val_if_fail, and rz_crypto_t::user.

Referenced by final().

Variable Documentation

◆ rizin_plugin

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

Definition at line 129 of file crypto_rot.c.

◆ rz_crypto_plugin_rot

RzCryptoPlugin rz_crypto_plugin_rot
Initial value:
= {
.name = "rot",
.author = "pancake",
.license = "LGPL-3",
.set_key = rot_set_key,
.get_key_size = rot_get_key_size,
.use = rot_use,
.update = update,
.final = final,
.init = rol_init,
.fini = rol_fini,
}
static bool rol_init(RzCrypto *cry)
Definition: crypto_rot.c:101
static bool rol_fini(RzCrypto *cry)
Definition: crypto_rot.c:108
static bool rot_use(const char *algo)
Definition: crypto_rot.c:75
static bool rot_set_key(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction)
Definition: crypto_rot.c:57
static int rot_get_key_size(RzCrypto *cry)
Definition: crypto_rot.c:70

Definition at line 115 of file crypto_rot.c.