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

相关推荐
HarmonyOS_SDK2 小时前
HarmonyOS免密认证方案 助力应用登录安全升级
harmonyos
zhanshuo3 小时前
鸿蒙操作系统核心特性解析:从分布式架构到高效开发的全景技术图谱
harmonyos
塞尔维亚大汉3 小时前
鸿蒙内核源码分析(编译过程篇) | 简单案例窥视编译全过程
源码·harmonyos
别说我什么都不会4 小时前
【OpenHarmony】鸿蒙开发之ohos_beacon_library
harmonyos
不凡的凡10 小时前
鸿蒙图片相似性对比
华为·harmonyos
Georgewu12 小时前
【HarmonyOS】HAR和HSP循环依赖和依赖传递问题详解
harmonyos
Georgewu9 天前
【HarmonyOS 5】鸿蒙跨平台开发方案详解(一)
flutter·harmonyos
万少10 天前
重磅推出 🔥 HarmonyOS AI 助手 CodeGenie V6 的使用教程
前端·harmonyos
我睡醒再说10 天前
纯血HarmonyOS5 打造小游戏实践:绘画板(附源文件)
harmonyos
我睡醒再说10 天前
HarmonyOS 5 ArkTS Worker线程:构建高性能移动应用的并行计算引擎
harmonyos