news 2026/10/7 2:20:17

FlashSwirl 闪旋,一款高性能的对称加密算法库,提供流加密、AEAD认证加密、HASH、HMAC、HKDF、PBKDF2

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
FlashSwirl 闪旋,一款高性能的对称加密算法库,提供流加密、AEAD认证加密、HASH、HMAC、HKDF、PBKDF2

FlashSwirl 闪旋,一款高性能的对称加密算法库,提供流加密、AEAD认证加密、HAS
H、HMAC、HKDF、PBKDF2


概述

由风之暇想研究的对称加密算法,基于ARX(Add-Rotate-XOR)结构设计,灵感来源于ChaCha20;加密库提供流加密、AEAD认证加密、HASH、HMAC、HKDF密钥派生、PBKDF2密钥派生的密码学功能。

✨ 特性

  • 多种加密模式:支持流加密(Stream)和AEAD认证加密
  • 高性能设计:批量处理、并行计算、内存池优化
  • 跨平台支持:提供C++、Go、JavaScript三种语言代码

📊 算法规范

算法规范文档


📚 三种语言库调用说明

C++ 版本

使用示例:

#include"FlashSwirl.h"#include<iostream>#include<vector>intmain(){// 准备密钥和Nonceuint8_tkey[32]={/* 32字节密钥 */};uint8_tnonce[24]={/* 24字节随机Nonce,必须使用安全随机数生成 */};// ===== 1. 流加密 =====std::vector<uint8_t>data={'H','e','l','l','o'};FlashSwirl_EncryptBuffer(key,32,nonce,24,data.data(),data.size(),20);// data现在包含密文FlashSwirl_DecryptBuffer(key,32,nonce,24,data.data(),data.size(),20);// data现在恢复为明文// ===== 2. AEAD认证加密 =====uint8_tplaintext[]="Secret message";uint8_tciphertext[256];intoutLen=sizeof(ciphertext);uint8_tad[]="additional-data";FlashSwirl_EncryptAEADBuffer(key,32,nonce,24,plaintext,sizeof(plaintext)-1,ciphertext,&outLen,ad,sizeof(ad)-1,20);uint8_tdecrypted[256];intplainLen=sizeof(decrypted);FlashSwirl_DecryptAEADBuffer(key,32,nonce,24,ciphertext,outLen,decrypted,&plainLen,ad,sizeof(ad)-1,20);// ===== 3. HASH =====constchar*message="Hello, FlashSwirl!";uint8_thash[32];FlashSwirl_Hash((constuint8_t*)message,strlen(message),20,hash);// ===== 4. HMAC =====uint8_thmacKey[]="secret-key";uint8_thmacOut[32];FlashSwirl_HMAC(hmacKey,sizeof(hmacKey)-1,(constuint8_t*)message,strlen(message),20,hmacOut);// ===== 5. HKDF密钥派生 =====uint8_tmasterKey[32]={/* 主密钥 */};uint8_tsalt[32]={/* 盐值 */};uint8_tinfo[]="my-app";uint8_tderivedKey[32];FlashSwirl_HKDF(masterKey,32,salt,32,info,sizeof(info)-1,32,20,derivedKey);// ===== 6. PBKDF2密钥派生 =====constchar*password="user-password";uint8_tpbkdf2Salt[]="random-salt";uint8_tkeyFromPassword[32];FlashSwirl_PBKDF2((constuint8_t*)password,strlen(password),pbkdf2Salt,sizeof(pbkdf2Salt)-1,10000,32,20,keyFromPassword);return0;}

Go 版本

https://pkg.go.dev/github.com/fzxx/FlashSwirl/GO/FlashSwirl

使用示例:

packagemainimport("bytes""crypto/rand""fmt""FlashSwirl")funcmain(){// 准备密钥和Noncekey:=make([]byte,32)nonce:=make([]byte,24)rand.Read(key)rand.Read(nonce)// ===== 1. 流加密 =====plaintext:=[]byte("Secret message")varencrypted bytes.Buffer FlashSwirl.Encrypt(key,nonce,bytes.NewReader(plaintext),&encrypted,20)vardecrypted bytes.Buffer FlashSwirl.Decrypt(key,nonce,&encrypted,&decrypted,20)fmt.Printf("Decrypted: %s\n",decrypted.Bytes())// ===== 2. AEAD认证加密 =====varaeadEncrypted bytes.Buffer additionalData:=[]byte("context info")FlashSwirl.EncryptAEAD(key,nonce,bytes.NewReader(plaintext),&aeadEncrypted,additionalData,20)varaeadDecrypted bytes.Buffer valid,_:=FlashSwirl.DecryptAEAD(key,nonce,&aeadEncrypted,&aeadDecrypted,additionalData,20)ifvalid{fmt.Printf("AEAD Decrypted: %s\n",aeadDecrypted.Bytes())}// ===== 3. HASH =====message:=[]byte("Hello, FlashSwirl!")hash,_:=FlashSwirl.Hash(bytes.NewReader(message),20)fmt.Printf("Hash: %x\n",hash)// ===== 4. HMAC =====hmacKey:=[]byte("secret-key")hmacResult,_:=FlashSwirl.HMAC(hmacKey,bytes.NewReader(message),20)fmt.Printf("HMAC: %x\n",hmacResult)// ===== 5. HKDF密钥派生 =====salt:=[]byte("random-salt")info:=[]byte("my-app")derivedKey,_:=FlashSwirl.HKDF(key,salt,info,32,20)fmt.Printf("Derived Key: %x\n",derivedKey)// ===== 6. PBKDF2密钥派生 =====password:=[]byte("user-password")pbkdf2Salt:=[]byte("random-salt")keyFromPassword,_:=FlashSwirl.PBKDF2(password,pbkdf2Salt,10000,32,20)fmt.Printf("Key from password: %x\n",keyFromPassword)}

JavaScript 版本

https://flashswirl.pages.dev/

CDN引用

<script src="https://cdn.jsdelivr.net/gh/fzxx/FlashSwirl/JS/FlashSwirl.js"></script>
<script src="https://cdn.statically.io/gh/fzxx/FlashSwirl@main/JS/FlashSwirl.js"></script>

使用示例:

// 浏览器环境// <script src="FlashSwirl.js"></script>// Node.js环境// const FlashSwirl = require('./FlashSwirl.js');// 准备密钥和Nonceconstkey=crypto.getRandomValues(newUint8Array(32));constnonce=crypto.getRandomValues(newUint8Array(24));// ===== 1. 流加密 =====constplaintext=newTextEncoder().encode("Secret message");constciphertext=FlashSwirl.encrypt('stream',key,nonce,plaintext,newUint8Array(0),20);constdecrypted=FlashSwirl.decrypt('stream',key,nonce,ciphertext,newUint8Array(0),20);console.log("Decrypted:",newTextDecoder().decode(decrypted));// ===== 2. AEAD认证加密 =====constadditionalData=newTextEncoder().encode("context info");constaeadCiphertext=FlashSwirl.encrypt('aead',key,nonce,plaintext,additionalData,20);constaeadDecrypted=FlashSwirl.decrypt('aead',key,nonce,aeadCiphertext,additionalData,20);console.log("AEAD Decrypted:",newTextDecoder().decode(aeadDecrypted));// ===== 3. HASH =====constmessage=newTextEncoder().encode("Hello, FlashSwirl!");consthash=FlashSwirl.hash(message,20);console.log("Hash:",Array.from(hash).map(b=>b.toString(16).padStart(2,'0')).join(''));// ===== 4. HMAC =====consthmacKey=newTextEncoder().encode("secret-key");consthmacResult=FlashSwirl.hmac(hmacKey,message,20);console.log("HMAC:",Array.from(hmacResult).map(b=>b.toString(16).padStart(2,'0')).join(''));// ===== 5. HKDF密钥派生 =====constsalt=newTextEncoder().encode("random-salt");constinfo=newTextEncoder().encode("my-app");constderivedKey=FlashSwirl.hkdf(key,salt,info,32,20);console.log("Derived Key:",Array.from(derivedKey).map(b=>b.toString(16).padStart(2,'0')).join(''));// ===== 6. PBKDF2密钥派生 =====constpassword=newTextEncoder().encode("user-password");constpbkdf2Salt=newTextEncoder().encode("random-salt");constkeyFromPassword=FlashSwirl.pbkdf2(password,pbkdf2Salt,10000,32,20);console.log("Key from password:",Array.from(keyFromPassword).map(b=>b.toString(16).padStart(2,'0')).join(''));

🧑‍💻开源地址

https://github.com/fzxx/FlashSwirl/

📖 更新日志

更新日志

📚许可证

GNU General Public License 3.0

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/10/7 2:15:15

DeepSeek本地部署全指南:显存计算、量化选型与推理框架调优

简介&#xff1a;一份DeepSeek大语言模型本地部署教程&#xff0c;面向具有一定计算机基础、希望实现数据本地化处理或模型二次开发的技术人员。教程完整覆盖安装前准备、部署方案选择、可视化界面配置、验证与测试、常见问题与解决方案、安全与性能优化建议等环节&#xff1a;…

作者头像 李华
网站建设 2026/10/7 2:13:25

排序全解析:算法、工程与应用的三个核心层面

如果只看标题“排序------3”&#xff0c;你可能会觉得这是一个随手记的草稿&#xff1a;不知道“3”是第几版&#xff0c;也不知道为什么要用三个横杠隔开。但恰恰是这种模糊的标题&#xff0c;反而把一个被大多数人当成“理所当然”的技术话题重新推到了台前。排序这件事&…

作者头像 李华
网站建设 2026/10/7 2:12:55

代理记账许可证编号怎么查?DLJZ 编号含义与查验方法

代理记账许可证编号怎么查&#xff1f;DLJZ 编号含义与查验方法 一分钟看答案 正规代理记账机构的《代理记账许可证书》编号以 DLJZ 开头&#xff08;DL代理&#xff0c;JZ记账&#xff09;&#xff0c;后面是地区行政区划码、核发年份和流水号。查验只要三步&#xff1a; 要编…

作者头像 李华
网站建设 2026/10/7 2:11:16

AI工作流实战:WorkBuddy技能封装与本地化搭建指南

如果你最近在关注 AI 工作流&#xff0c;可能会发现一个现象&#xff1a;Coze、Dify、n8n 这类工具已经把“搭建工作流”讲得很透了&#xff0c;教程遍地都是&#xff0c;但真正落到自己项目里的却不多。原因倒不难理解——很多演示停留在“拖几个节点、点一下运行、截图发朋友…

作者头像 李华
网站建设 2026/10/7 2:11:13

题解:洛谷 P3366 【模板】最小生成树

本文分享的必刷题目是从蓝桥云课、洛谷、AcWing等知名刷题平台精心挑选而来,并结合各平台提供的算法标签和难度等级进行了系统分类。题目涵盖了从基础到进阶的多种算法和数据结构,旨在为不同阶段的编程学习者提供一条清晰、平稳的学习提升路径。 欢迎大家订阅我的专栏:算法…

作者头像 李华