2025-09-30 11:56:06 +08:00
<!DOCTYPE html> < html xmlns = "http://www.w3.org/1999/xhtml" xml:lang = "zh-cn" lang = "zh-cn" data-whc_version = "26.0" >
< head > < meta http-equiv = "Content-Type" content = "text/html; charset=UTF-8" / > < meta name = "viewport" content = "width=device-width, initial-scale=1.0" / > < meta http-equiv = "X-UA-Compatible" content = "IE=edge" / > < meta name = "description" content = "用户空间编程使用 CE 时,根据使用场景和需求的不同,有几层 API 可以选择: AF_ALG Socket API Libkcapi API OpenSSL API 图 1 . 用户空间 API 对接 AF_ALG API 相关 API 可参考头文件 linux/if_alg.h 要使用内核提供的算法和驱动,需要知道对应的算法名字。可通过下列命令获取: cat /proc/crypto 例如: ..." / > < meta name = "DC.rights.owner" content = "(C) 版权 2025" / > < meta name = "copyright" content = "(C) 版权 2025" / > < meta name = "generator" content = "DITA-OT" / > < meta name = "DC.type" content = "concept" / > < meta name = "DC.contributor" content = "yan.wang" / > < meta name = "DC.date.modified" content = "2024-12-04" / > < meta name = "DC.format" content = "HTML5" / > < meta name = "DC.identifier" content = "ce_demo" / > < meta name = "DC.language" content = "zh-CN" / > < title > 应用编程< / title > <!-- Build number 2023110923. --> < meta name = "wh-path2root" content = "../../../" / > < meta name = "wh-toc-id" content = "" / > < meta name = "wh-source-relpath" content = "topics/sdk/ce/ce-demo.dita" / > < meta name = "wh-out-relpath" content = "topics/sdk/ce/ce-demo.html" / >
< link rel = "stylesheet" type = "text/css" href = "../../../webhelp/app/commons.css?buildId=2023110923" / >
< link rel = "stylesheet" type = "text/css" href = "../../../webhelp/app/topic.css?buildId=2023110923" / >
< script src = "../../../webhelp/app/options/properties.js?buildId=20250121171154" > < / script >
< script src = "../../../webhelp/app/localization/strings.js?buildId=2023110923" > < / script >
< script src = "../../../webhelp/app/search/index/keywords.js?buildId=20250121171154" > < / script >
< script defer = "defer" src = "../../../webhelp/app/commons.js?buildId=2023110923" > < / script >
< script defer = "defer" src = "../../../webhelp/app/topic.js?buildId=2023110923" > < / script >
< link rel = "stylesheet" type = "text/css" href = "../../../webhelp/template/aic-styles-web.css?buildId=2023110923" / > < link rel = "stylesheet" type = "text/css" href = "../../../webhelp/template/notes.css?buildId=2023110923" / > < link rel = "stylesheet" type = "text/css" href = "../../../webhelp/template/aic-common.css?buildId=2023110923" / > < link rel = "stylesheet" type = "text/css" href = "../../../webhelp/template/aic-images.css?buildId=2023110923" / > < link rel = "stylesheet" type = "text/css" href = "../../../webhelp/template/footnote.css?buildId=2023110923" / > < link rel = "stylesheet" type = "text/css" href = "../../../webhelp/template/aic-web-watermark.css?buildId=2023110923" / > < link rel = "stylesheet" type = "text/css" href = "../../../webhelp/template/topic-body-list.css?buildId=2023110923" / > < / head >
< body id = "ce_demo" class = "wh_topic_page frmBody" >
< a href = "#wh_topic_body" class = "sr-only sr-only-focusable" >
跳转到主要内容
< / a >
< header class = "navbar navbar-default wh_header" >
< div class = "container-fluid" >
< div class = "wh_header_flex_container navbar-nav navbar-expand-md navbar-dark" >
< div class = "wh_logo_and_publication_title_container" >
< div class = "wh_logo_and_publication_title" >
< a href = "http://www.artinchip.com" class = " wh_logo d-none d-sm-block " > < img src = "../../../company-logo-white.png" alt = "RTOS SDK 使用指南SDK 指南文件" / > < / a >
< div class = " wh_publication_title " > < a href = "../../../index.html" > < span class = "booktitle" > < span class = "ph mainbooktitle" > RTOS SDK 使用指南< / span > < span class = "ph booktitlealt" > SDK 指南文件< / span > < / span > < / a > < / div >
< / div >
< / div >
< div class = "wh_top_menu_and_indexterms_link collapse navbar-collapse" id = "wh_top_menu_and_indexterms_link" >
< / div >
< / div >
< / div >
< / header >
< div class = " wh_search_input navbar-form wh_topic_page_search search " role = "form" >
< form id = "searchForm" method = "get" role = "search" action = "../../../search.html" > < div > < input type = "search" placeholder = "搜索 " class = "wh_search_textfield" id = "textToSearch" name = "searchQuery" aria-label = "搜索查询" required = "required" / > < button type = "submit" class = "wh_search_button" aria-label = "搜索" > < span class = "search_input_text" > 搜索< / span > < / button > < / div > < / form >
< / div >
< div class = "container-fluid" id = "wh_topic_container" >
< div class = "row" >
< nav class = "wh_tools d-print-none navbar-expand-md" aria-label = "Tools" >
< div data-tooltip-position = "bottom" class = " wh_breadcrumb " > < / div >
< div class = "wh_right_tools" >
< button class = "wh_hide_highlight" aria-label = "切换搜索突出显示" title = "切换搜索突出显示" > < / button >
< button class = "webhelp_expand_collapse_sections" data-next-state = "collapsed" aria-label = "折叠截面" title = "折叠截面" > < / button >
< div class = " wh_print_link print d-none d-md-inline-block " > < button onClick = "window.print()" title = "打印此页" aria-label = "打印此页" > < / button > < / div >
< / div >
< / nav >
< / div >
< div class = "wh_content_area" >
< div class = "row" >
< div class = "col-lg-10 col-md-10 col-sm-10 col-xs-12" id = "wh_topic_body" >
< button id = "wh_close_topic_toc_button" class = "close-toc-button d-none" aria-label = "Toggle topic table of content" aria-controls = "wh_topic_toc" aria-expanded = "true" >
< span class = "close-toc-icon-container" >
< span class = "close-toc-icon" > < / span >
< / span >
< / button >
< div class = " wh_topic_content body " > < main role = "main" > < article class = "- topic/topic concept/concept topic concept" role = "article" aria-labelledby = "ariaid-title1" > < span class = "edit-link" style = "font-size:12px; opacity:0.6; text-align:right; vertical-align:middle" > < a target = "_blank" href = "http://172.16.35.88/tasks/jdssno1uvvbf2mltu9kb9v3if05d5gopuakboe8hlud18rma/edit/F:/aicdita/aicdita-cn/topics/sdk/ce/ce-demo.dita" > Edit online< / a > < / span > < h1 class = "- topic/title title topictitle1" id = "ariaid-title1" > 应用编程< / h1 > < div class = "date inPage" > 4 Dec 2024< / div > < div style = "color: gray;" >
Read time: 3 minute(s)
< / div > < div class = "- topic/body concept/conbody body conbody" > < p class = "- topic/p p" data-ofbid = "d239016e22__20250121171656" > 用户空间编程使用 CE 时,根据使用场景和需求的不同,有几层 API 可以选择:< / p > < ul class = "- topic/ul ul" id = "ce_demo__ul_p45_vpy_21c" data-ofbid = "ce_demo__ul_p45_vpy_21c" > < li class = "- topic/li li" data-ofbid = "d239016e25__20250121171656" >
< p class = "- topic/p p" data-ofbid = "d239016e27__20250121171656" > < span class = "+ topic/keyword pr-d/apiname keyword apiname" > AF_ALG Socket API< / span > < / p >
< / li > < li class = "- topic/li li" data-ofbid = "d239016e31__20250121171656" >
< p class = "- topic/p p" data-ofbid = "d239016e33__20250121171656" > < span class = "+ topic/keyword pr-d/apiname keyword apiname" > Libkcapi API< / span > < / p >
< / li > < li class = "- topic/li li" data-ofbid = "d239016e37__20250121171656" >
< p class = "- topic/p p" data-ofbid = "d239016e39__20250121171656" > < span class = "+ topic/keyword pr-d/apiname keyword apiname" > OpenSSL API< / span > < / p >
< / li > < / ul > < figure class = "- topic/fig fig fignone" id = "ce_demo__fig_ndg_cqy_21c" data-ofbid = "ce_demo__fig_ndg_cqy_21c" > < br / > < div class = "imagecenter" > < img class = "- topic/image image imagecenter" id = "ce_demo__image_q45_vpy_21c" src = "../../../images/ce/ce_userpace_api.png" alt = "ce_userpace_api" / > < / div > < br / > < figcaption data-caption-side = "bottom" class = "- topic/title title figcapcenter" > < span class = "figtitleprefix fig--title-label" > 图< span class = "fig--title-label-number" > 1< / span > < span class = "fig--title-label-punctuation" > . < / span > < / span > < span class = "fig--title" > 用户空间 API 对接< / span > < / figcaption > < / figure > < section class = "- topic/section section" id = "ce_demo__section_r45_vpy_21c" data-ofbid = "ce_demo__section_r45_vpy_21c" > < h2 class = "- topic/title title sectiontitle" > AF_ALG API< / h2 >
< p class = "- topic/p p" data-ofbid = "d239016e54__20250121171656" > 相关 API 可参考头文件 < span class = "+ topic/ph sw-d/filepath ph filepath" > linux/if_alg.h< / span > < / p >
< div class = "- topic/p p" data-ofbid = "d239016e59__20250121171656" > 要使用内核提供的算法和驱动,需要知道对应的算法名字。可通过下列命令获取:< pre class = "+ topic/pre pr-d/codeblock pre codeblock language-c" id = "ce_demo__codeblock_ysz_kc3_p1c" data-ofbid = "ce_demo__codeblock_ysz_kc3_p1c" > cat /proc/crypto< / pre > < / div >
< div class = "- topic/p p" data-ofbid = "d239016e64__20250121171656" > 例如:< pre class = "+ topic/pre pr-d/codeblock pre codeblock language-c" id = "ce_demo__codeblock_aq2_bqy_21c" data-ofbid = "ce_demo__codeblock_aq2_bqy_21c" > name : ctr(aes)
driver : ctr-aes-aic
module : kernel
priority : < span class = "hl-number" > 400< / span >
refcnt : < span class = "hl-number" > 1< / span >
selftest : passed
internal : no
type : skcipher
async : yes
blocksize : < span class = "hl-number" > 16< / span >
min keysize : < span class = "hl-number" > 16< / span >
max keysize : < span class = "hl-number" > 32< / span >
ivsize : < span class = "hl-number" > 16< / span >
chunksize : < span class = "hl-number" > 16< / span >
walksize : < span class = "hl-number" > 16< / span >
name : cbc(aes)
driver : cbc-aes-aic
module : kernel
priority : < span class = "hl-number" > 400< / span >
refcnt : < span class = "hl-number" > 1< / span >
selftest : passed
internal : no
type : skcipher
async : yes
blocksize : < span class = "hl-number" > 16< / span >
min keysize : < span class = "hl-number" > 16< / span >
max keysize : < span class = "hl-number" > 32< / span >
ivsize : < span class = "hl-number" > 16< / span >
chunksize : < span class = "hl-number" > 16< / span >
walksize : < span class = "hl-number" > 16< / span >
......< / pre > < / div >
< p class = "- topic/p p" data-ofbid = "d239016e69__20250121171656" > 这里的 < span class = "+ topic/ph sw-d/filepath ph filepath" > /proc/crypto< / span > 是目标平台上的文件< / p >
< p class = "- topic/p p" data-ofbid = "d239016e76__20250121171656" > < span class = "+ topic/keyword pr-d/apiname keyword apiname" > AF_ALG API< / span > 的特点:< / p >
< ul class = "- topic/ul ul" id = "ce_demo__ul_x45_vpy_21c" data-ofbid = "ce_demo__ul_x45_vpy_21c" > < li class = "- topic/li li" data-ofbid = "d239016e82__20250121171656" >
< p class = "- topic/p p" data-ofbid = "d239016e84__20250121171656" > 效率高< / p >
< / li > < li class = "- topic/li li" data-ofbid = "d239016e87__20250121171656" >
< p class = "- topic/p p" data-ofbid = "d239016e89__20250121171656" > 接口灵活< / p >
< / li > < li class = "- topic/li li" data-ofbid = "d239016e92__20250121171656" >
< p class = "- topic/p p" data-ofbid = "d239016e94__20250121171656" > 较为复杂< / p >
< / li > < / ul >
< / section > < section class = "- topic/section section" id = "ce_demo__section_y45_vpy_21c" data-ofbid = "ce_demo__section_y45_vpy_21c" > < h2 class = "- topic/title title sectiontitle" > Libkcapi API< / h2 >
< p class = "- topic/p p" data-ofbid = "d239016e103__20250121171656" > SDK 已经提供对应的 < span class = "+ topic/keyword pr-d/apiname keyword apiname" > libkcapi< / span > 库,默认配置已经支持< / p >
< ul class = "- topic/ul ul" id = "ce_demo__ul_ap5_vpy_21c" data-ofbid = "ce_demo__ul_ap5_vpy_21c" > < li class = "- topic/li li" data-ofbid = "d239016e110__20250121171656" >
< p class = "- topic/p p" data-ofbid = "d239016e112__20250121171656" > 对称密钥算法< / p >
< / li > < li class = "- topic/li li" data-ofbid = "d239016e115__20250121171656" >
< p class = "- topic/p p" data-ofbid = "d239016e117__20250121171656" > 非对称密钥算法< / p >
< / li > < li class = "- topic/li li" data-ofbid = "d239016e120__20250121171656" >
< p class = "- topic/p p" data-ofbid = "d239016e122__20250121171656" > 消息摘要算法< / p >
< / li > < li class = "- topic/li li" data-ofbid = "d239016e125__20250121171656" >
< p class = "- topic/p p" data-ofbid = "d239016e127__20250121171656" > 随机数读取< / p >
< / li > < / ul >
< p class = "- topic/p p" data-ofbid = "d239016e131__20250121171656" > 如果需要修改对应包的编译配置,可在 Luban SDK 顶层目录执行 < span class = "+ topic/keyword sw-d/cmdname keyword cmdname" > make menuconfig< / span > 或 < span class = "+ topic/keyword sw-d/cmdname keyword cmdname" > make
m< / span > 。< / p >
< div class = "- topic/p p" data-ofbid = "d239016e140__20250121171656" > 配置界面的索引如下:< pre class = "+ topic/pre pr-d/codeblock pre codeblock language-c" id = "ce_demo__codeblock_t2f_pc3_p1c" data-ofbid = "ce_demo__codeblock_t2f_pc3_p1c" > Third-party packages --->
-*- libkcapi --->
[*] use prebuilt binary instead of building from source
[*] enable asym algorithm support
[*] build enc application
[*] build hasher application
[*] build rng read application
[*] build speed-test program
[*] build test program
< / pre > < / div >
< p class = "- topic/p p" data-ofbid = "d239016e146__20250121171656" > < span class = "+ topic/keyword pr-d/apiname keyword apiname" > Libkcapi< / span > 的特点:< / p >
< ul class = "- topic/ul ul" id = "ce_demo__ul_ep5_vpy_21c" data-ofbid = "ce_demo__ul_ep5_vpy_21c" > < li class = "- topic/li li" data-ofbid = "d239016e152__20250121171656" >
< p class = "- topic/p p" data-ofbid = "d239016e154__20250121171656" > 接口简单< / p >
< / li > < li class = "- topic/li li" data-ofbid = "d239016e157__20250121171656" >
< p class = "- topic/p p" data-ofbid = "d239016e159__20250121171656" > 效率高< / p >
< / li > < / ul >
< p class = "- topic/p p" data-ofbid = "d239016e163__20250121171656" > 基于 < span class = "+ topic/keyword pr-d/apiname keyword apiname" > Libkcapi API< / span > 的参考示例
< span class = "+ topic/ph sw-d/filepath ph filepath" > source/artinchip/test-ce/kcapi/< / span > 。< / p >
< / section > < section class = "- topic/section section" id = "ce_demo__section_gp5_vpy_21c" data-ofbid = "ce_demo__section_gp5_vpy_21c" > < h2 class = "- topic/title title sectiontitle" > OpenSSL API< / h2 >
< p class = "- topic/p p" data-ofbid = "d239016e177__20250121171656" > Luban SDK 通过 OpenSSL 的 Engine 机制,以实现 Engine 库的方式,已经完成了对 OpenSSL 的对接。 无论是通过 OpenSSL
的命令行,还是通过使用库编程,都可以使用到 CE。< / p >
< p class = "- topic/p p" data-ofbid = "d239016e180__20250121171656" > Engine 库有两个,根据不同的目的进行使用。< / p >
< div class = "table-container" > < table class = "- topic/table table frame-all" id = "ce_demo__table_hp5_vpy_21c" data-ofbid = "ce_demo__table_hp5_vpy_21c" data-cols = "3" > < caption > < / caption > < colgroup > < col style = "width:16.666666666666664%" / > < col style = "width:25.666666666666664%" / > < col style = "width:57.666666666666664%" / > < / colgroup > < thead class = "- topic/thead thead" > < tr class = "- topic/row" > < th class = "- topic/entry entry colsep-1 rowsep-1" id = "ce_demo__table_hp5_vpy_21c__entry__1" > Engine< / th > < th class = "- topic/entry entry colsep-1 rowsep-1" id = "ce_demo__table_hp5_vpy_21c__entry__2" > 库和路径< / th > < th class = "- topic/entry entry colsep-0 rowsep-1" id = "ce_demo__table_hp5_vpy_21c__entry__3" > 说明< / th > < / tr > < / thead > < tbody class = "- topic/tbody tbody" > < tr class = "- topic/row" > < td class = "- topic/entry entry colsep-1 rowsep-1" headers = "ce_demo__table_hp5_vpy_21c__entry__1" > aic engine< / td > < td class = "- topic/entry entry colsep-1 rowsep-1" headers = "ce_demo__table_hp5_vpy_21c__entry__2" > < span class = "+ topic/ph sw-d/filepath ph filepath" > usr/lib/libengine_aic.so< / span > < / td > < td class = "- topic/entry entry colsep-0 rowsep-1" headers = "ce_demo__table_hp5_vpy_21c__entry__3" > 实现 CE 所提供的对称密钥算法、RSA 算法和消息摘要算法该 Engine 实现的都是标准算法。< / td > < / tr > < tr class = "- topic/row" > < td class = "- topic/entry entry colsep-1 rowsep-0" headers = "ce_demo__table_hp5_vpy_21c__entry__1" > huk engine< / td > < td class = "- topic/entry entry colsep-1 rowsep-0" headers = "ce_demo__table_hp5_vpy_21c__entry__2" > < span class = "+ topic/ph sw-d/filepath ph filepath" > usr/lib/libengine_huk.so< / span > < / td > < td class = "- topic/entry entry colsep-0 rowsep-0" headers = "ce_demo__table_hp5_vpy_21c__entry__3" > 实现了 HUK 保护的 AES 算法,可用于本地数据保护。使用该 Engine 时,输入的密钥会被 HUK
进行一次解密,然后才用于 AES 加解密。HUK 每一颗芯片不同,因此使用该 Engine
加密后的数据,仅当前平台可解密。< / td > < / tr > < / tbody > < / table > < / div >
< p class = "- topic/p p" data-ofbid = "d239016e214__20250121171656" > 命令行中使用指定 Engine 的示例:< / p >
< pre class = "+ topic/pre pr-d/codeblock pre codeblock language-c" id = "ce_demo__codeblock_ip5_vpy_21c" data-ofbid = "ce_demo__codeblock_ip5_vpy_21c" > openssl enc -engine aic -p -nosalt -nopad -aes-< span class = "hl-number" > 128< / span > -ecb -e -K < span class = "hl-number" > 0123< / span > -in data.bin -out enc.bin< / pre >
< p class = "- topic/p p" data-ofbid = "d239016e221__20250121171656" > 上述示例中,通过 < span class = "+ topic/keyword pr-d/parmname keyword parmname" > -engine aic< / span > 指定了使用 < span class = "+ topic/keyword pr-d/parmname keyword parmname" > aic< / span > engine。< / p >
< p class = "- topic/p p" data-ofbid = "d239016e230__20250121171656" > 当在 < span class = "+ topic/ph sw-d/filepath ph filepath" > openssl.cnf< / span > 文件中配置了默认的 Engine 之后,命令行中可以忽略 < span class = "+ topic/keyword pr-d/parmname keyword parmname" > -engine< / span >
参数。 具体配置可参考 < span class = "+ topic/ph sw-d/filepath ph filepath" > /etc/ssl/openssl_aic.cnf< / span > 文件。< / p >
< pre class = "+ topic/pre pr-d/codeblock pre codeblock language-c" id = "ce_demo__codeblock_jp5_vpy_21c" data-ofbid = "ce_demo__codeblock_jp5_vpy_21c" > openssl_conf = openssl_def
[openssl_def]
engines = engine_section
[engine_section]
aic = aic_section
[aic_section]
engine_id = aic
dynamic_path = /usr/lib/libengine_aic.so
default_algorithms = CIPHERS,DIGESTS,RSA
< / pre >
< p class = "- topic/p p" data-ofbid = "d239016e245__20250121171656" > Libopenssl API 的特点:< / p >
< ul class = "- topic/ul ul" id = "ce_demo__ul_lp5_vpy_21c" data-ofbid = "ce_demo__ul_lp5_vpy_21c" > < li class = "- topic/li li" data-ofbid = "d239016e249__20250121171656" >
< p class = "- topic/p p" data-ofbid = "d239016e251__20250121171656" > 功能强大< / p >
< / li > < li class = "- topic/li li" data-ofbid = "d239016e254__20250121171656" >
< p class = "- topic/p p" data-ofbid = "d239016e256__20250121171656" > 调用效率稍差< / p >
< / li > < / ul >
< p class = "- topic/p p" data-ofbid = "d239016e261__20250121171656" > 基于 Libopenssl API 的参考示例: < span class = "+ topic/ph sw-d/filepath ph filepath" > source/artinchip/test-ce/openssl/< / span > < / p >
< / section > < / div > < / article > < / main > < / div >
< / div >
< nav role = "navigation" id = "wh_topic_toc" aria-label = "On this page" class = "col-lg-2 d-none d-lg-block navbar d-print-none" >
< div id = "wh_topic_toc_content" >
< div class = " wh_topic_toc " > < div class = "wh_topic_label" > 在本页上< / div > < ul > < li class = "section-item" > < div class = "section-title" > < a href = "#ce_demo__section_r45_vpy_21c" data-tocid = "ce_demo__section_r45_vpy_21c" > AF_ALG API< / a > < / div > < / li > < li class = "section-item" > < div class = "section-title" > < a href = "#ce_demo__section_y45_vpy_21c" data-tocid = "ce_demo__section_y45_vpy_21c" > Libkcapi API< / a > < / div > < / li > < li class = "section-item" > < div class = "section-title" > < a href = "#ce_demo__section_gp5_vpy_21c" data-tocid = "ce_demo__section_gp5_vpy_21c" > OpenSSL API< / a > < / div > < / li > < / ul > < / div >
< / div >
< / nav >
< / div >
< / div >
< / div >
< footer class = "navbar navbar-default wh_footer" >
< div class = " footer-container mx-auto " >
< title > footer def< / title >
< style > < ! - -
.p1 {
font-family: FangZhengShuSong, Times, serif;
}
.p2 {
font-family: Arial, Helvetica, sans-serif;
}
.p3 {
font-family: "Lucida Console", "Courier New", monospace;
}
-->< / style >
< div class = "webhelp.fragment.footer" >
< p class = "p1" > Copyright © 2019-2024 广东匠芯创科技有限公司. All rights reserved.< / p >
< / div > < div >
< div class = "generation_time" >
Update Time: 2025-01-21
< / div >
< / div >
< / div >
< / footer >
< div id = "go2top" class = "d-print-none" >
< span class = "oxy-icon oxy-icon-up" > < / span >
< / div >
< div id = "modal_img_large" class = "modal" >
< span class = "close oxy-icon oxy-icon-remove" > < / span >
< div id = "modal_img_container" > < / div >
< div id = "caption" > < / div >
< / div >
< script src = "${pd}/publishing/publishing-styles-AIC-template/js/custom.js" defer = "defer" > < / script >
< / body >
2025-01-23 16:37:00 +08:00
< / html >