Rizin
unix-like reverse engineering framework and cli tools
crypto_punycode.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2009-2016 pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_util.h>
5 #include <rz_lib.h>
6 #include <rz_crypto.h>
7 
8 static bool punycode_set_key(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction) {
9  cry->dir = direction;
10  return true;
11 }
12 
13 static int punycode_get_key_size(RzCrypto *cry) {
14  return 0;
15 }
16 
17 static bool punycode_use(const char *algo) {
18  return !strcmp(algo, "punycode");
19 }
20 
21 static bool update(RzCrypto *cry, const ut8 *buf, int len) {
22  if (len < 1 || !buf) {
23  return false;
24  }
25 
26  char *obuf;
27  int olen;
28  if (cry->dir == RZ_CRYPTO_DIR_DECRYPT) {
29  obuf = rz_punycode_decode((const char *)buf, len, &olen);
30  } else {
31  obuf = rz_punycode_encode(buf, len, &olen);
32  }
33  rz_crypto_append(cry, (ut8 *)obuf, olen);
34  free(obuf);
35  return true;
36 }
37 
38 static bool final(RzCrypto *cry, const ut8 *buf, int len) {
39  return update(cry, buf, len);
40 }
41 
43  .name = "punycode",
44  .author = "pancake",
45  .license = "LGPL-3",
46  .set_key = punycode_set_key,
47  .get_key_size = punycode_get_key_size,
48  .use = punycode_use,
49  .update = update,
50  .final = final
51 };
52 
53 #ifndef RZ_PLUGIN_INCORE
57  .version = RZ_VERSION
58 };
59 #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
RzCryptoPlugin rz_crypto_plugin_punycode
static bool punycode_set_key(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction)
static bool punycode_use(const char *algo)
static bool update(RzCrypto *cry, const ut8 *buf, int len)
RZ_API RzLibStruct rizin_plugin
static int punycode_get_key_size(RzCrypto *cry)
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
@ RZ_CRYPTO_DIR_DECRYPT
Definition: rz_crypto.h:24
@ RZ_LIB_TYPE_CRYPTO
Definition: rz_lib.h:81
RZ_API char * rz_punycode_encode(const ut8 *src, int srclen, int *dstlen)
Definition: punycode.c:176
RZ_API char * rz_punycode_decode(const char *src, int srclen, int *dstlen)
Definition: punycode.c:255
#define RZ_VERSION
Definition: rz_version.h:8
const char * name
Definition: rz_crypto.h:41
static unsigned char * obuf
Definition: z80asm.c:36