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

相关推荐
前端不太难15 小时前
鸿蒙 App 的“无状态 System”设计
华为·状态模式·harmonyos
UnicornDev17 小时前
【Flutter x HarmonyOS 6】魔方计时APP——计时逻辑实现
flutter·华为·harmonyos·鸿蒙·鸿蒙系统
AlbertZein1 天前
ImageKnifePro 源码解读:鸿蒙图片加载框架全貌
harmonyos
AlbertZein1 天前
鸿蒙工程化:build-profile.json5 逐字段解析
harmonyos
前端技术1 天前
鸿蒙ArkTS 自定义底部导航栏(Tabs+@Builder 极简实现)
harmonyos·鸿蒙
Swift社区1 天前
为什么“页面跳转”在鸿蒙 PC 上是错误设计?
华为·harmonyos
熬夜敲代码的小N2 天前
鸿蒙PC开发者必备!GitNext深度测评:一站式Git管理工具
git·华为·harmonyos
秋の本名2 天前
第一章 鸿蒙生态架构与开发理念
华为·wpf·harmonyos
Ww.xh2 天前
鸿蒙系统中HTML与Vue集成方案
vue.js·html·harmonyos
前端不太难2 天前
鸿蒙游戏 CI/CD:为什么你还在手动打包?
游戏·ci/cd·harmonyos