Rizin
unix-like reverse engineering framework and cli tools
crypto_base91.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2016-2017 rakholiyajenish.07 <rakholiyajenish.07@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_lib.h>
5 #include <rz_crypto.h>
6 #include <rz_util.h>
7 
8 #define INSIZE 32768
9 
10 static bool base91_set_key(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction) {
11  cry->dir = direction;
12  return true;
13 }
14 
15 static int base91_get_key_size(RzCrypto *cry) {
16  return 0;
17 }
18 
19 static bool base91_use(const char *algo) {
20  return algo && !strcmp(algo, "base91");
21 }
22 
23 static bool update(RzCrypto *cry, const ut8 *buf, int len) {
24  if (len < 1) {
25  return false;
26  }
27 
28  int olen = INSIZE;
29  if (!cry || !buf || len < 1) {
30  return false;
31  }
32  ut8 *obuf = malloc(olen);
33  if (!obuf) {
34  return false;
35  }
36  if (cry->dir == RZ_CRYPTO_DIR_ENCRYPT) {
37  olen = rz_base91_encode((char *)obuf, (const ut8 *)buf, len);
38  } else if (cry->dir == 1) {
39  olen = rz_base91_decode(obuf, (const char *)buf, len);
40  } else {
41  free(obuf);
42  return false;
43  }
44  rz_crypto_append(cry, obuf, olen);
45  free(obuf);
46  return true;
47 }
48 
49 static bool final(RzCrypto *cry, const ut8 *buf, int len) {
50  return update(cry, buf, len);
51 }
52 
54  .name = "base91",
55  .author = "rakholiyajenish.07",
56  .license = "LGPL-3",
57  .set_key = base91_set_key,
58  .get_key_size = base91_get_key_size,
59  .use = base91_use,
60  .update = update,
61  .final = final
62 };
63 
64 #ifndef RZ_PLUGIN_INCORE
67  .data = &rz_crypto_plugin_base91,
68  .version = RZ_VERSION
69 };
70 #endif
size_t len
Definition: 6502dis.c:15
#define RZ_API
RZ_API int rz_crypto_append(RzCrypto *cry, const ut8 *buf, int len)
Definition: crypto.c:175
static bool update(RzCrypto *cry, const ut8 *buf, int len)
Definition: crypto_base91.c:23
#define INSIZE
Definition: crypto_base91.c:8
RZ_API RzLibStruct rizin_plugin
Definition: crypto_base91.c:65
static int base91_get_key_size(RzCrypto *cry)
Definition: crypto_base91.c:15
static bool base91_set_key(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction)
Definition: crypto_base91.c:10
RzCryptoPlugin rz_crypto_plugin_base91
Definition: crypto_base91.c:53
static bool base91_use(const char *algo)
Definition: crypto_base91.c:19
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
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
const char int mode
Definition: ioapi.h:137
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
void * malloc(size_t size)
Definition: malloc.c:123
RZ_API int rz_base91_encode(char *bout, const ut8 *bin, int len)
Definition: base91.c:69
RZ_API int rz_base91_decode(ut8 *bout, const char *bin, int len)
Definition: base91.c:28
@ RZ_CRYPTO_DIR_ENCRYPT
Definition: rz_crypto.h:23
@ RZ_LIB_TYPE_CRYPTO
Definition: rz_lib.h:81
#define RZ_VERSION
Definition: rz_version.h:8
const char * name
Definition: rz_crypto.h:41
static unsigned char * obuf
Definition: z80asm.c:36