OpenHarmony移植的加解密库—libsodium [GN编译]

简介

libsodium主要是易用,可移植的加解密库。

下载安装

直接在OpenHarmony-SIG仓中搜索libsodium并下载。

使用说明

以OpenHarmony 3.1Beta的rk3568版本为例

  1. 库代码存放路径:./third_party/libsodium

  2. 修改添加依赖的编译脚本,路径:/developtools/bytrace_standard/ohos.build

    {
    "subsystem": "developtools",
    "parts": {
    "bytrace_standard": {
    "module_list": [
    "//developtools/bytrace_standard/interfaces/innerkits/native:bytrace_core",
    "//developtools/bytrace_standard/bin:bytrace_target",
    "//developtools/bytrace_standard/bin:bytrace.cfg",
    "//developtools/bytrace_standard/interfaces/kits/js/napi:bytrace",
    "//third_party/libsodium:libsodium",
    "//third_party/libsodium:libsodium_test"
    ],
    "inner_kits": [
    {
    "type": "so",
    "name": "//developtools/bytrace_standard/interfaces/innerkits/native:bytrace_core",
    "header": {
    "header_files": [
    "bytrace.h"
    ],
    "header_base": "//developtools/bytrace_standard/interfaces/innerkits/native/include"
    }
    }
    ],
    "test_list": [
    "//developtools/bytrace_standard/bin/test:unittest"
    ]
    }
    }
    }

  3. 用命令 ./build.sh --product-name rk3568 --ccache 编译

  4. 生成库文件路径:out/rk3568/graphic/graphic_standard,该路径会生成库文件

接口说明

  1. 初始化库
    sodium_init(void)

  2. 等式的恒定时间检验
    sodium_memcmp(const void * const b1_, const void * const b2_, size_t len);

  3. 十六进制编码/解码
    sodium_bin2hex(char * const hex, const size_t hex_maxlen, const unsigned char * const bin, const size_t bin_len);

  4. Base64编码/解码
    sodium_bin2base64(char * const b64, const size_t b64_maxlen, const unsigned char * const bin, const size_t bin_len, const int variant)

  5. 调零记忆
    sodium_memzero(void * const pnt, const size_t len)

  6. 锁定内存
    int sodium_mlock(void * const addr, const size_t len)

  7. 密钥派生
    crypto_pwhash(unsigned char * const out, unsigned long long outlen, const char * const passwd, unsigned long long passwdlen, const unsigned char * const salt, unsigned long long opslimit, size_t memlimit, int alg)

  8. 密码存储
    crypto_pwhash_str(char out[crypto_pwhash_STRBYTES], const char * const passwd, unsigned long long passwdlen, unsigned long long opslimit, size_t memlimit)

  9. 创建一个新的密钥对
    int sodium_mlock(void * const addr, const size_t len)

  10. 计算共享密钥
    crypto_kx_client_session_keys(unsigned char rx[crypto_kx_SESSIONKEYBYTES], unsigned char tx[crypto_kx_SESSIONKEYBYTES], const unsigned char client_pk[crypto_kx_PUBLICKEYBYTES], const unsigned char client_sk[crypto_kx_SECRETKEYBYTES], const unsigned char server_pk[crypto_kx_PUBLICKEYBYTES])

兼容性

支持 OpenHarmony系统 3.0 及以上版本。

目录结构

|---- libsodium
|     |---- src
|           |---- crypto_aead   #aead结构
|           |---- crypto_auth   #密钥消息验证
|           |---- crypto_box   #密封盒
|           |---- crypto_core   #有限域算术
|           |---- crypto_generichash   #散列
|           |---- crypto_hash   #哈希
|           |---- crypto_kdf   #密钥派生
|           |---- crypto_kx   #密钥交换
|           |---- crypto_onetimeauth   #一次性认证
|           |---- crypto_pwhash   #密码哈希
|           |---- crypto_scalarmult   #加密标量乘法
|           |---- crypto_secretbox   #认证加密
|           |---- crypto_secretstream   #加密流和文件加密
|           |---- crypto_shorthash   #端输入散列
|           |---- crypto_sign   #公钥签名
|           |---- crypto_stream   #流密码
|           |---- crypto_verify   #公钥签名
|           |---- include   #头文件
|           |---- randombytes   #生成随机数据
|           |---- sodium   #基础代码
|     |---- tests   #单元测试用例
|     |---- README.md   #安装使用方法

为了能让大家更好的学习鸿蒙(HarmonyOS NEXT)开发技术,这边特意整理了《鸿蒙开发学习手册》(共计890页),希望对大家有所帮助:https://qr21.cn/FV7h05

《鸿蒙开发学习手册》:

如何快速入门:https://qr21.cn/FV7h05

  1. 基本概念
  2. 构建第一个ArkTS应用
  3. ......

开发基础知识:https://qr21.cn/FV7h05

  1. 应用基础知识
  2. 配置文件
  3. 应用数据管理
  4. 应用安全管理
  5. 应用隐私保护
  6. 三方应用调用管控机制
  7. 资源分类与访问
  8. 学习ArkTS语言
  9. ......

基于ArkTS 开发:https://qr21.cn/FV7h05

  1. Ability开发
  2. UI开发
  3. 公共事件与通知
  4. 窗口管理
  5. 媒体
  6. 安全
  7. 网络与链接
  8. 电话服务
  9. 数据管理
  10. 后台任务(Background Task)管理
  11. 设备管理
  12. 设备使用信息统计
  13. DFX
  14. 国际化开发
  15. 折叠屏系列
  16. ......

鸿蒙开发面试真题(含参考答案):https://qr18.cn/F781PH

鸿蒙开发面试大盘集篇(共计319页):https://qr18.cn/F781PH

1.项目开发必备面试题

2.性能优化方向

3.架构方向

4.鸿蒙开发系统底层方向

5.鸿蒙音视频开发方向

6.鸿蒙车载开发方向

7.鸿蒙南向开发方向

相关推荐
冯志浩4 小时前
Harmony NEXT:如何给数据库添加自定义分词
harmonyos·掘金·金石计划
爱桥代码的程序媛6 小时前
鸿蒙OpenHarmony【轻量系统芯片移植案例】标准系统方案之瑞芯微RK3568移植案例
嵌入式硬件·harmonyos·鸿蒙·鸿蒙系统·移植·openharmony·鸿蒙开发
AORO_BEIDOU6 小时前
防爆手机+鸿蒙系统,遨游通讯筑牢工业安全基石
5g·安全·智能手机·信息与通信·harmonyos
小强在此21 小时前
【基于开源鸿蒙(OpenHarmony)的智慧农业综合应用系统】
华为·开源·团队开发·智慧农业·harmonyos·开源鸿蒙
PlumCarefree1 天前
基于鸿蒙API10的RTSP播放器(四:沉浸式播放窗口)
华为·harmonyos
中关村科金1 天前
中关村科金推出得助音视频鸿蒙SDK,助力金融业务系统鸿蒙化提速
华为·音视频·harmonyos
小强在此1 天前
基于OpenHarmony(开源鸿蒙)的智慧医疗综合应用系统
华为·开源·团队开发·健康医疗·harmonyos·开源鸿蒙
奔跑的露西ly2 天前
【鸿蒙 HarmonyOS NEXT】popup弹窗
华为·harmonyos
OH五星上将2 天前
OpenHarmony(鸿蒙南向开发)——轻量和小型系统三方库移植指南(一)
嵌入式硬件·移动开发·harmonyos·openharmony·鸿蒙开发·鸿蒙移植