luat_lib_crypto.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. /*
  2. @module crypto
  3. @summary 加解密和hash函数
  4. @version 1.0
  5. @date 2020.07.03
  6. @demo crypto
  7. */
  8. #include "luat_base.h"
  9. #include "luat_crypto.h"
  10. #include "luat_malloc.h"
  11. #include "luat_str.h"
  12. #include <time.h>
  13. #include "luat_zbuff.h"
  14. #define LUAT_LOG_TAG "crypto"
  15. #include "luat_log.h"
  16. static const unsigned char hexchars[] = "0123456789ABCDEF";
  17. static void fixhex(const char* source, char* dst, size_t len) {
  18. for (size_t i = 0; i < len; i++)
  19. {
  20. char ch = *(source+i);
  21. dst[i*2] = hexchars[(unsigned char)ch >> 4];
  22. dst[i*2+1] = hexchars[(unsigned char)ch & 0xF];
  23. }
  24. }
  25. /**
  26. 计算md5值
  27. @api crypto.md5(str)
  28. @string 需要计算的字符串
  29. @return string 计算得出的md5值的hex字符串
  30. @usage
  31. -- 计算字符串"abc"的md5
  32. log.info("md5", crypto.md5("abc"))
  33. */
  34. static int l_crypto_md5(lua_State *L) {
  35. size_t size = 0;
  36. const char* str = luaL_checklstring(L, 1, &size);
  37. char tmp[32] = {0};
  38. char dst[32] = {0};
  39. if (luat_crypto_md5_simple(str, size, tmp) == 0) {
  40. fixhex(tmp, dst, 16);
  41. lua_pushlstring(L, dst, 32);
  42. return 1;
  43. }
  44. return 0;
  45. }
  46. /**
  47. 计算hmac_md5值
  48. @api crypto.hmac_md5(str, key)
  49. @string 需要计算的字符串
  50. @string 密钥
  51. @return string 计算得出的hmac_md5值的hex字符串
  52. @usage
  53. -- 计算字符串"abc"的hmac_md5
  54. log.info("hmac_md5", crypto.hmac_md5("abc", "1234567890"))
  55. */
  56. static int l_crypto_hmac_md5(lua_State *L) {
  57. size_t str_size = 0;
  58. size_t key_size = 0;
  59. const char* str = luaL_checklstring(L, 1, &str_size);
  60. const char* key = luaL_checklstring(L, 2, &key_size);
  61. char tmp[32] = {0};
  62. char dst[32] = {0};
  63. if (luat_crypto_hmac_md5_simple(str, str_size, key, key_size, tmp) == 0) {
  64. fixhex(tmp, dst, 16);
  65. lua_pushlstring(L, dst, 32);
  66. return 1;
  67. }
  68. return 0;
  69. }
  70. /**
  71. 计算sha1值
  72. @api crypto.sha1(str)
  73. @string 需要计算的字符串
  74. @return string 计算得出的sha1值的hex字符串
  75. @usage
  76. -- 计算字符串"abc"的sha1
  77. log.info("sha1", crypto.sha1("abc"))
  78. */
  79. static int l_crypto_sha1(lua_State *L) {
  80. size_t size = 0;
  81. const char* str = luaL_checklstring(L, 1, &size);
  82. char tmp[40] = {0};
  83. char dst[40] = {0};
  84. if (luat_crypto_sha1_simple(str, size, tmp) == 0) {
  85. fixhex(tmp, dst, 20);
  86. lua_pushlstring(L, dst, 40);
  87. return 1;
  88. }
  89. return 0;
  90. }
  91. /**
  92. 计算hmac_sha1值
  93. @api crypto.hmac_sha1(str, key)
  94. @string 需要计算的字符串
  95. @string 密钥
  96. @return string 计算得出的hmac_sha1值的hex字符串
  97. @usage
  98. -- 计算字符串"abc"的hmac_sha1
  99. log.info("hmac_sha1", crypto.hmac_sha1("abc", "1234567890"))
  100. */
  101. static int l_crypto_hmac_sha1(lua_State *L) {
  102. size_t str_size = 0;
  103. size_t key_size = 0;
  104. const char* str = luaL_checklstring(L, 1, &str_size);
  105. const char* key = luaL_checklstring(L, 2, &key_size);
  106. char tmp[40] = {0};
  107. char dst[40] = {0};
  108. if (luat_crypto_hmac_sha1_simple(str, str_size, key, key_size, tmp) == 0) {
  109. fixhex(tmp, dst, 20);
  110. lua_pushlstring(L, dst, 40);
  111. return 1;
  112. }
  113. return 0;
  114. }
  115. /**
  116. 计算sha256值
  117. @api crypto.sha256(str)
  118. @string 需要计算的字符串
  119. @return string 计算得出的sha256值的hex字符串
  120. @usage
  121. -- 计算字符串"abc"的sha256
  122. log.info("sha256", crypto.sha256("abc"))
  123. */
  124. static int l_crypto_sha256(lua_State *L) {
  125. size_t size = 0;
  126. const char* str = luaL_checklstring(L, 1, &size);
  127. char tmp[64] = {0};
  128. char dst[64] = {0};
  129. if (luat_crypto_sha256_simple(str, size, tmp) == 0) {
  130. fixhex(tmp, dst, 32);
  131. lua_pushlstring(L, dst, 64);
  132. return 1;
  133. }
  134. return 0;
  135. }
  136. /**
  137. 计算hmac_sha256值
  138. @api crypto.hmac_sha256(str, key)
  139. @string 需要计算的字符串
  140. @string 密钥
  141. @return string 计算得出的hmac_sha256值的hex字符串
  142. @usage
  143. -- 计算字符串"abc"的hmac_sha256
  144. log.info("hmac_sha256", crypto.hmac_sha256("abc", "1234567890"))
  145. */
  146. static int l_crypto_hmac_sha256(lua_State *L) {
  147. size_t str_size = 0;
  148. size_t key_size = 0;
  149. const char* str = luaL_checklstring(L, 1, &str_size);
  150. const char* key = luaL_checklstring(L, 2, &key_size);
  151. char tmp[64] = {0};
  152. char dst[64] = {0};
  153. if (key_size > 64) {
  154. luat_crypto_sha256_simple(key, key_size, dst);
  155. key = (const char*)dst;
  156. key_size = 64;
  157. }
  158. if (luat_crypto_hmac_sha256_simple(str, str_size, key, key_size, tmp) == 0) {
  159. fixhex(tmp, dst, 32);
  160. lua_pushlstring(L, dst, 64);
  161. return 1;
  162. }
  163. return 0;
  164. }
  165. //---
  166. /**
  167. 计算sha512值
  168. @api crypto.sha512(str)
  169. @string 需要计算的字符串
  170. @return string 计算得出的sha512值的hex字符串
  171. @usage
  172. -- 计算字符串"abc"的sha512
  173. log.info("sha512", crypto.sha512("abc"))
  174. */
  175. static int l_crypto_sha512(lua_State *L) {
  176. size_t size = 0;
  177. const char* str = luaL_checklstring(L, 1, &size);
  178. char tmp[128] = {0};
  179. char dst[128] = {0};
  180. if (luat_crypto_sha512_simple(str, size, tmp) == 0) {
  181. fixhex(tmp, dst, 64);
  182. lua_pushlstring(L, dst, 128);
  183. return 1;
  184. }
  185. return 0;
  186. }
  187. /**
  188. 计算hmac_sha512值
  189. @api crypto.hmac_sha512(str, key)
  190. @string 需要计算的字符串
  191. @string 密钥
  192. @return string 计算得出的hmac_sha512值的hex字符串
  193. @usage
  194. -- 计算字符串"abc"的hmac_sha512
  195. log.info("hmac_sha512", crypto.hmac_sha512("abc", "1234567890"))
  196. */
  197. static int l_crypto_hmac_sha512(lua_State *L) {
  198. size_t str_size = 0;
  199. size_t key_size = 0;
  200. const char* str = luaL_checklstring(L, 1, &str_size);
  201. const char* key = luaL_checklstring(L, 2, &key_size);
  202. char tmp[128] = {0};
  203. char dst[128] = {0};
  204. if (key_size > 128) {
  205. luat_crypto_sha512_simple(key, key_size, dst);
  206. key = (const char*)dst;
  207. key_size = 128;
  208. }
  209. if (luat_crypto_hmac_sha512_simple(str, str_size, key, key_size, tmp) == 0) {
  210. fixhex(tmp, dst, 64);
  211. lua_pushlstring(L, dst, 128);
  212. return 1;
  213. }
  214. return 0;
  215. }
  216. int l_crypto_cipher_xxx(lua_State *L, uint8_t flags);
  217. /**
  218. 对称加密
  219. @api crypto.cipher_encrypt(type, padding, str, key, iv)
  220. @string 算法名称, 例如 AES-128-ECB/AES-128-CBC, 可查阅mbedtls的cipher_wrap.c
  221. @string 对齐方式, 当前仅支持PKCS7
  222. @string 需要加密的数据
  223. @string 密钥,需要对应算法的密钥长度
  224. @string IV值, 非ECB算法需要
  225. @return string 加密后的字符串
  226. @usage
  227. -- 计算AES
  228. local data = crypto.cipher_encrypt("AES-128-ECB", "PKCS7", "1234567890123456", "1234567890123456")
  229. local data2 = crypto.cipher_encrypt("AES-128-CBC", "PKCS7", "1234567890123456", "1234567890123456", "1234567890666666")
  230. */
  231. int l_crypto_cipher_encrypt(lua_State *L) {
  232. return l_crypto_cipher_xxx(L, 1);
  233. }
  234. /**
  235. 对称解密
  236. @api crypto.cipher_decrypt(type, padding, str, key, iv)
  237. @string 算法名称, 例如 AES-128-ECB/AES-128-CBC, 可查阅mbedtls的cipher_wrap.c
  238. @string 对齐方式, 当前仅支持PKCS7
  239. @string 需要解密的数据
  240. @string 密钥,需要对应算法的密钥长度
  241. @string IV值, 非ECB算法需要
  242. @return string 解密后的字符串
  243. @usage
  244. -- 用AES加密,然后用AES解密
  245. local data = crypto.cipher_encrypt("AES-128-ECB", "PKCS7", "1234567890123456", "1234567890123456")
  246. local data2 = crypto.cipher_decrypt("AES-128-ECB", "PKCS7", data, "1234567890123456")
  247. -- data的hex为 757CCD0CDC5C90EADBEEECF638DD0000
  248. -- data2的值为 1234567890123456
  249. */
  250. int l_crypto_cipher_decrypt(lua_State *L) {
  251. return l_crypto_cipher_xxx(L, 0);
  252. }
  253. #include "crc.h"
  254. /**
  255. 计算CRC16
  256. @api crypto.crc16(method, data, poly, initial, finally, inReversem outReverse)
  257. @string CRC16模式("IBM","MAXIM","USB","MODBUS","CCITT","CCITT-FALSE","X25","XMODEM","DNP","USER-DEFINED")
  258. @string 字符串
  259. @int poly值
  260. @int initial值
  261. @int finally值
  262. @int 输入反转,1反转,默认0不反转
  263. @int 输入反转,1反转,默认0不反转
  264. @return int 对应的CRC16值
  265. @usage
  266. -- 计算CRC16
  267. local crc = crypto.crc16("")
  268. */
  269. static int l_crypto_crc16(lua_State *L)
  270. {
  271. size_t inputlen;
  272. const unsigned char *inputData;
  273. const char *inputmethod = (const char*)luaL_checkstring(L, 1);
  274. if(lua_isuserdata(L, 2))
  275. {
  276. luat_zbuff_t *buff = ((luat_zbuff_t *)luaL_checkudata(L, 2, LUAT_ZBUFF_TYPE));
  277. inputlen = buff->len - buff->cursor;
  278. inputData = (const unsigned char *)(buff->addr + buff->cursor);
  279. }else{
  280. inputData = (const unsigned char*)lua_tolstring(L,2,&inputlen);
  281. }
  282. uint16_t poly = luaL_optnumber(L,3,0x0000);
  283. uint16_t initial = luaL_optnumber(L,4,0x0000);
  284. uint16_t finally = luaL_optnumber(L,5,0x0000);
  285. uint8_t inReverse = luaL_optnumber(L,6,0);
  286. uint8_t outReverse = luaL_optnumber(L,7,0);
  287. lua_pushinteger(L, calcCRC16(inputData, inputmethod,inputlen,poly,initial,finally,inReverse,outReverse));
  288. return 1;
  289. }
  290. /**
  291. 直接计算modbus的crc16值
  292. @api crypto.crc16_modbus(data)
  293. @string 数据
  294. @return int 对应的CRC16值
  295. @usage
  296. -- 计算CRC16 modbus
  297. local crc = crypto.crc16_modbus(data)
  298. */
  299. static int l_crypto_crc16_modbus(lua_State *L)
  300. {
  301. size_t len = 0;
  302. const unsigned char *inputData = (const unsigned char*)luaL_checklstring(L, 1, &len);
  303. lua_pushinteger(L, calcCRC16_modbus(inputData, len));
  304. return 1;
  305. }
  306. /**
  307. 计算crc32值
  308. @api crypto.crc32(data)
  309. @string 数据
  310. @return int 对应的CRC32值
  311. @usage
  312. -- 计算CRC32
  313. local crc = crypto.crc32(data)
  314. */
  315. static int l_crypto_crc32(lua_State *L)
  316. {
  317. size_t len = 0;
  318. const unsigned char *inputData = (const unsigned char*)luaL_checklstring(L, 1, &len);
  319. lua_pushinteger(L, calcCRC32(inputData, len));
  320. return 1;
  321. }
  322. /**
  323. 计算crc8值
  324. @api crypto.crc8(data)
  325. @string 数据
  326. @int crc多项式,可选,如果不写,将忽略除了数据外所有参数
  327. @int crc初始值,可选,默认0
  328. @boolean 是否需要逆序处理,默认否
  329. @return int 对应的CRC8值
  330. @usage
  331. -- 计算CRC8
  332. local crc = crypto.crc8(data)
  333. local crc = crypto.crc8(data, 0x31, 0xff, false)
  334. */
  335. static int l_crypto_crc8(lua_State *L)
  336. {
  337. size_t len = 0;
  338. const unsigned char *inputData = (const unsigned char*)luaL_checklstring(L, 1, &len);
  339. if (!lua_isinteger(L, 2)) {
  340. lua_pushinteger(L, calcCRC8(inputData, len));
  341. } else {
  342. uint8_t poly = lua_tointeger(L, 2);
  343. uint8_t start = luaL_optinteger(L, 3, 0);
  344. uint8_t is_rev = 0;
  345. if (lua_isboolean(L, 4)) {
  346. is_rev = lua_toboolean(L, 4);
  347. }
  348. uint8_t i;
  349. uint8_t CRC8 = start;
  350. uint8_t *Src = (uint8_t *)inputData;
  351. if (is_rev)
  352. {
  353. poly = 0;
  354. for (i = 0; i < 8; i++)
  355. {
  356. if (start & (1 << (7 - i)))
  357. {
  358. poly |= 1 << i;
  359. }
  360. }
  361. while (len--)
  362. {
  363. CRC8 ^= *Src++;
  364. for (i = 0; i < 8; i++)
  365. {
  366. if ((CRC8 & 0x01))
  367. {
  368. CRC8 >>= 1;
  369. CRC8 ^= poly;
  370. }
  371. else
  372. {
  373. CRC8 >>= 1;
  374. }
  375. }
  376. }
  377. }
  378. else
  379. {
  380. while (len--)
  381. {
  382. CRC8 ^= *Src++;
  383. for (i = 8; i > 0; --i)
  384. {
  385. if ((CRC8 & 0x80))
  386. {
  387. CRC8 <<= 1;
  388. CRC8 ^= poly;
  389. }
  390. else
  391. {
  392. CRC8 <<= 1;
  393. }
  394. }
  395. }
  396. }
  397. lua_pushinteger(L, CRC8);
  398. }
  399. return 1;
  400. }
  401. /**
  402. 生成真随机数
  403. @api crypto.trng(len)
  404. @int 数据长度
  405. @return string 指定随机数字符串
  406. @usage
  407. -- 生成32位随机数ir
  408. local r = crypto.trng(4)
  409. local _, ir = pack.unpack(r, "I")
  410. */
  411. static int l_crypto_trng(lua_State *L) {
  412. int ret = 0;
  413. size_t len = luaL_checkinteger(L, 1);
  414. if (len < 1) {
  415. return 0;
  416. }
  417. if (len > 128)
  418. len = 128;
  419. char buff[128];
  420. ret = luat_crypto_trng(buff, len);
  421. if(ret ==0){
  422. lua_pushlstring(L, buff, len);
  423. return 1;
  424. }
  425. return 0;
  426. }
  427. /**
  428. 计算TOTP动态密码的结果
  429. @api crypto.totp(secret,time)
  430. @string 网站提供的密钥(就是BASE32编码后的结果)
  431. @int 可选,时间戳,默认当前时间
  432. @return int 计算得出的六位数结果 计算失败返回nil
  433. @usage
  434. --使用当前系统时间计算
  435. local otp = crypto.totp("asdfassdfasdfass")
  436. */
  437. static int l_crypto_totp(lua_State *L) {
  438. size_t len = 0;
  439. const char* secret_base32 = luaL_checklstring(L,1,&len);
  440. char * secret = (char *)luat_heap_malloc(len+1);
  441. len = (size_t)luat_str_base32_decode((const uint8_t * )secret_base32,(uint8_t*)secret,len+1);
  442. uint64_t t = (uint64_t)(luaL_optinteger(L,2,(lua_Integer)time(NULL))/30);
  443. uint8_t data[sizeof(t)] = {0};
  444. for(int i=0;i<sizeof(t);i++)
  445. data[sizeof(t)-1-i] = *(((uint8_t*)&t)+i);
  446. uint8_t hmac[20] = {0};
  447. if(luat_crypto_hmac_sha1_simple((const char *)data, sizeof(data), (const char *)secret, len, hmac) == 0)
  448. {
  449. uint8_t offset = hmac[19] & 0x0f;
  450. uint32_t r = (
  451. ((uint32_t)((hmac[offset + 0] & 0x7f)) << 24) |
  452. ((uint32_t)((hmac[offset + 1] & 0xff)) << 16) |
  453. ((uint32_t)((hmac[offset + 2] & 0xff)) << 8) |
  454. ((uint32_t)(hmac[offset + 3] & 0xff))
  455. ) % 1000000;
  456. lua_pushinteger(L,r);
  457. return 1;
  458. }
  459. return 0;
  460. }
  461. /**
  462. 将数据进行base64编码
  463. @api crypto.base64_encode(data)
  464. @string 待编码的数据
  465. @return string 编码后的数据
  466. @usage
  467. -- 本函数与 string.toBase64 是同一个
  468. local data = "123"
  469. local bdata = crypto.base64_encode(data)
  470. log.info("base64", "encode", data, bdata)
  471. data = crypto.base64_decode(data)
  472. log.info("base64", "decode", data, bdata)
  473. */
  474. int l_str_toBase64(lua_State *L);
  475. /**
  476. 将数据进行base64解码
  477. @api crypto.base64_decode(data)
  478. @string 待解码的数据
  479. @return string 解码后的数据
  480. @usage
  481. -- 本函数与 string.fromBase64 是同一个
  482. local data = "123"
  483. local bdata = crypto.base64_encode(data)
  484. log.info("base64", "encode", data, bdata)
  485. data = crypto.base64_decode(data)
  486. log.info("base64", "decode", data, bdata)
  487. */
  488. int l_str_fromBase64(lua_State *L);
  489. /**
  490. 获取当前固件支持的cipher列表
  491. @api crypto.cipher_list()
  492. @return table 本固件支持的cipher列表,字符串数组
  493. @usage
  494. -- 本API于2022.07.27添加
  495. local ciphers = crypto.cipher_list()
  496. if ciphers then
  497. log.info("crypto", "ciphers list", json.encode(ciphers))
  498. end
  499. */
  500. int l_crypto_cipher_list(lua_State *L) {
  501. const char* list[32] = {0};
  502. size_t len = 0;
  503. lua_newtable(L);
  504. if (list == NULL) {
  505. LLOGD("out of memory when cipher_list");
  506. return 1;
  507. }
  508. int ret = luat_crypto_cipher_list(list, &len, 32);
  509. if (ret == 0) {
  510. for (size_t i = 0; i < len; i++)
  511. {
  512. lua_pushstring(L, list[i]);
  513. lua_seti(L, -2, i + 1);
  514. }
  515. return 1;
  516. }
  517. else {
  518. LLOGD("bsp not support cipher_list");
  519. }
  520. return 1;
  521. }
  522. #include "rotable2.h"
  523. static const rotable_Reg_t reg_crypto[] =
  524. {
  525. { "md5" , ROREG_FUNC(l_crypto_md5 )},
  526. { "sha1" , ROREG_FUNC(l_crypto_sha1 )},
  527. { "sha256" , ROREG_FUNC(l_crypto_sha256 )},
  528. { "sha512" , ROREG_FUNC(l_crypto_sha512 )},
  529. { "hmac_md5" , ROREG_FUNC(l_crypto_hmac_md5 )},
  530. { "hmac_sha1" , ROREG_FUNC(l_crypto_hmac_sha1 )},
  531. { "hmac_sha256" , ROREG_FUNC(l_crypto_hmac_sha256 )},
  532. { "hmac_sha512" , ROREG_FUNC(l_crypto_hmac_sha512 )},
  533. { "cipher" , ROREG_FUNC(l_crypto_cipher_encrypt )},
  534. { "cipher_encrypt" ,ROREG_FUNC(l_crypto_cipher_encrypt )},
  535. { "cipher_decrypt" ,ROREG_FUNC(l_crypto_cipher_decrypt )},
  536. { "cipher_list" , ROREG_FUNC(l_crypto_cipher_list )},
  537. { "crc16", ROREG_FUNC(l_crypto_crc16 )},
  538. { "crc16_modbus", ROREG_FUNC(l_crypto_crc16_modbus )},
  539. { "crc32", ROREG_FUNC(l_crypto_crc32 )},
  540. { "crc8", ROREG_FUNC(l_crypto_crc8 )},
  541. { "trng", ROREG_FUNC(l_crypto_trng )},
  542. { "totp", ROREG_FUNC(l_crypto_totp )},
  543. { "base64_encode", ROREG_FUNC(l_str_toBase64)},
  544. { "base64_decode", ROREG_FUNC(l_str_fromBase64)},
  545. { NULL, ROREG_INT(0) }
  546. };
  547. LUAMOD_API int luaopen_crypto( lua_State *L ) {
  548. luat_newlib2(L, reg_crypto);
  549. return 1;
  550. }
  551. // 添加几个默认实现
  552. #ifndef LUAT_COMPILER_NOWEAK
  553. LUAT_WEAK int luat_crypto_md5_simple(const char* str, size_t str_size, void* out_ptr) {return -1;}
  554. LUAT_WEAK int luat_crypto_hmac_md5_simple(const char* str, size_t str_size, const char* mac, size_t mac_size, void* out_ptr) {return -1;}
  555. LUAT_WEAK int luat_crypto_sha1_simple(const char* str, size_t str_size, void* out_ptr) {return -1;}
  556. LUAT_WEAK int luat_crypto_hmac_sha1_simple(const char* str, size_t str_size, const char* mac, size_t mac_size, void* out_ptr) {return -1;}
  557. LUAT_WEAK int luat_crypto_sha256_simple(const char* str, size_t str_size, void* out_ptr) {return -1;}
  558. LUAT_WEAK int luat_crypto_hmac_sha256_simple(const char* str, size_t str_size, const char* mac, size_t mac_size, void* out_ptr) {return -1;}
  559. LUAT_WEAK int luat_crypto_sha512_simple(const char* str, size_t str_size, void* out_ptr) {return -1;}
  560. LUAT_WEAK int luat_crypto_hmac_sha512_simple(const char* str, size_t str_size, const char* mac, size_t mac_size, void* out_ptr) {return -1;}
  561. LUAT_WEAK int l_crypto_cipher_xxx(lua_State *L, uint8_t flags) {return 0;}
  562. LUAT_WEAK int luat_crypto_trng(char* buff, size_t len) {
  563. memset(buff, 0, len);
  564. return 0;
  565. }
  566. #endif