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.鸿蒙南向开发方向

相关推荐
摘星编程7 分钟前
OpenHarmony + RN:Bluetooth连接蓝牙外设
react native·react.js·harmonyos
小风呼呼吹儿1 小时前
Flutter 框架跨平台鸿蒙开发 - 车辆保养记录器:智能管理车辆保养全流程
flutter·华为·harmonyos
不会写代码0001 小时前
Flutter 框架跨平台鸿蒙开发 - 在线小说阅读器开发教程
flutter·华为·harmonyos
weixin_541299943 小时前
鸿蒙应用开发:保存应用数据 - 关系型数据库的使用
数据库·oracle·harmonyos
Stara05117 小时前
微信小程序页面渲染核心—WXML模板语法与WXSS自适应样式开发实战V1.1
移动开发·网络请求·数据绑定·wxml·wxss·事件处理·微信小程序开发
夜雨声烦丿8 小时前
Flutter 框架跨平台鸿蒙开发 - 万年历应用开发教程
flutter·华为·harmonyos
Swift社区9 小时前
ArkUI 中 Flex 和 Grid 布局的选择与实践
harmonyos·arkui·flex
2501_944424129 小时前
Flutter for OpenHarmony游戏集合App实战之黑白棋落子翻转
android·开发语言·windows·flutter·游戏·harmonyos
猛扇赵四那边好嘴.10 小时前
Flutter 框架跨平台鸿蒙开发 - 全国公厕查询:智能定位附近公厕
flutter·华为·harmonyos
2501_9444241210 小时前
Flutter for OpenHarmony游戏集合App实战之消消乐下落填充
android·开发语言·flutter·游戏·harmonyos