首页
课程
问答
CTF
社区
招聘
峰会
发现
排行榜
知识库
工具下载
看雪20年
看雪商城
证书查询
登录
注册
首页
社区
课程
招聘
发现
问答
CTF
排行榜
知识库
工具下载
峰会
看雪商城
证书查询
社区
密码应用
发新帖
0
0
[原创自研]FlashSwirl 闪旋,一款高性能的对称加密算法库
发表于: 2026-4-25 20:25
2809
[原创自研]FlashSwirl 闪旋,一款高性能的对称加密算法库
风之暇想
2026-4-25 20:25
2809
 **<a href="elink@e7fK9s2c8@1M7s2y4Q4x3@1q4Q4x3V1k6Q4x3V1k6Y4K9i4c8Z5N6h3u0Q4x3X3g2U0L8$3#2Q4x3V1k6X3P5Y4S2^5i4K6u0r3c8X3I4S2M7$3S2e0N6$3W2J5L8l9`.`.">FlashSwirl 闪旋</a>,一款高性能的对称加密算法库,提供流加密、AEAD认证加密、HAS H、HMAC、HKDF、PBKDF2** --- ### 概述 由**风之暇想**研究的对称加密算法,基于ARX(Add-Rotate-XOR)结构设计,灵感来源于ChaCha20;加密库提供流加密、AEAD认证加密、HASH、HMAC、HKDF密钥派生、PBKDF2密钥派生的密码学功能。 ### ✨ 特性 - **多种加密模式**:支持流加密(Stream)和AEAD认证加密 - **高性能设计**:批量处理、并行计算、内存池优化 - **跨平台支持**:提供C++、Go、JavaScript三种语言代码 ### 算法规范 <a href="elink@0d0K9s2c8@1M7s2y4Q4x3@1q4Q4x3V1k6Q4x3V1k6Y4K9i4c8Z5N6h3u0Q4x3X3g2U0L8$3#2Q4x3V1k6X3P5Y4S2^5i4K6u0r3c8X3I4S2M7$3S2e0N6$3W2J5L8q4)9J5c8X3u0D9L8$3u0Q4x3V1k6E0j5h3W2F1i4K6u0r3f1#2m8q4b7@1W2r3d9f1y4m8g2p5W2a6e0W2)9J5k6h3#2V1">算法规范文档</a> --- ## 三种语言库调用说明 ### C++ 版本 **使用示例:** ```cpp #include "FlashSwirl.h" #include <iostream> #include <vector> int main() { // 准备密钥和Nonce uint8_t key[32] = { /* 32字节密钥 */ }; uint8_t nonce[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_t plaintext[] = "Secret message"; uint8_t ciphertext[256]; int outLen = sizeof(ciphertext); uint8_t ad[] = "additional-data"; FlashSwirl_EncryptAEADBuffer(key, 32, nonce, 24, plaintext, sizeof(plaintext)-1, ciphertext, &outLen, ad, sizeof(ad)-1, 20); uint8_t decrypted[256]; int plainLen = sizeof(decrypted); FlashSwirl_DecryptAEADBuffer(key, 32, nonce, 24, ciphertext, outLen, decrypted, &plainLen, ad, sizeof(ad)-1, 20); // ===== 3. HASH ===== const char* message = "Hello, FlashSwirl!"; uint8_t hash[32]; FlashSwirl_Hash((const uint8_t*)message, strlen(message), 20, hash); // ===== 4. HMAC ===== uint8_t hmacKey[] = "secret-key"; uint8_t hmacOut[32]; FlashSwirl_HMAC(hmacKey, sizeof(hmacKey)-1, (const uint8_t*)message, strlen(message), 20, hmacOut); // ===== 5. HKDF密钥派生 ===== uint8_t masterKey[32] = { /* 主密钥 */ }; uint8_t salt[32] = { /* 盐值 */ }; uint8_t info[] = "my-app"; uint8_t derivedKey[32]; FlashSwirl_HKDF(masterKey, 32, salt, 32, info, sizeof(info)-1, 32, 20, derivedKey); // ===== 6. PBKDF2密钥派生 ===== const char* password = "user-password"; uint8_t pbkdf2Salt[] = "random-salt"; uint8_t keyFromPassword[32]; FlashSwirl_PBKDF2((const uint8_t*)password, strlen(password), pbkdf2Salt, sizeof(pbkdf2Salt)-1, 10000, 32, 20, keyFromPassword); return 0; } ``` --- ### Go 版本 <a href="elink@4a4K9s2c8@1M7s2y4Q4x3@1q4Q4x3V1k6Q4x3V1k6H3K9$3N6Q4x3X3g2Y4L8#2)9J5k6h3c8W2N6W2)9J5c8X3N6A6N6r3S2#2j5W2)9J5k6h3y4G2L8g2)9J5c8X3k6*7P5s2S2Q4x3V1k6r3L8r3q4K6K9q4y4%4K9i4u0D9i4K6u0r3c8@1!0Q4x3V1k6r3L8r3q4K6K9q4y4%4K9i4u0D9"><mark class="encrypted">b30K9s2c8@1M7s2y4Q4x3@1q4Q4x3V1k6Q4x3V1k6H3K9$3N6Q4x3X3g2Y4L8#2)9J5k6h3c8W2N6W2)9J5c8X3N6A6N6r3S2#2j5W2)9J5k6h3y4G2L8g2)9J5c8X3k6*7P5s2S2Q4x3V1k6r3L8r3q4K6K9q4y4%4K9i4u0D9i4K6u0r3c8@1!0Q4x3V1k6r3L8r3q4K6K9q4y4%4K9i4u0D9</mark></a> **使用示例:** ```go package main import ( "bytes" "crypto/rand" "fmt" "FlashSwirl" ) func main() { // 准备密钥和Nonce key := make([]byte, 32) nonce := make([]byte, 24) rand.Read(key) rand.Read(nonce) // ===== 1. 流加密 ===== plaintext := []byte("Secret message") var encrypted bytes.Buffer FlashSwirl.Encrypt(key, nonce, bytes.NewReader(plaintext), &encrypted, 20) var decrypted bytes.Buffer FlashSwirl.Decrypt(key, nonce, &encrypted, &decrypted, 20) fmt.Printf("Decrypted: %s\n", decrypted.Bytes()) // ===== 2. AEAD认证加密 ===== var aeadEncrypted bytes.Buffer additionalData := []byte("context info") FlashSwirl.EncryptAEAD(key, nonce, bytes.NewReader(plaintext), &aeadEncrypted, additionalData, 20) var aeadDecrypted bytes.Buffer valid, _ := FlashSwirl.DecryptAEAD(key, nonce, &aeadEncrypted, &aeadDecrypted, additionalData, 20) if valid { 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 版本 <a href="elink@254K9s2c8@1M7s2y4Q4x3@1q4Q4x3V1k6Q4x3V1k6X3L8r3q4K6K9s2y4%4K9i4u0D9i4K6u0W2M7r3q4Y4k6i4y4Q4x3X3g2V1k6i4k6Q4x3V1j5`."><mark class="encrypted">739K9s2c8@1M7s2y4Q4x3@1q4Q4x3V1k6Q4x3V1k6X3L8r3q4K6K9s2y4%4K9i4u0D9i4K6u0W2M7r3q4Y4k6i4y4Q4x3X3g2V1k6i4k6Q4x3V1j5`.</mark></a> **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> ``` **使用示例:** ```javascript // 浏览器环境 // <script src="FlashSwirl.js"></script> // Node.js环境 // const FlashSwirl = require('./FlashSwirl.js'); // 准备密钥和Nonce const key = crypto.getRandomValues(new Uint8Array(32)); const nonce = crypto.getRandomValues(new Uint8Array(24)); // ===== 1. 流加密 ===== const plaintext = new TextEncoder().encode("Secret message"); const ciphertext = FlashSwirl.encrypt('stream', key, nonce, plaintext, new Uint8Array(0), 20); const decrypted = FlashSwirl.decrypt('stream', key, nonce, ciphertext, new Uint8Array(0), 20); console.log("Decrypted:", new TextDecoder().decode(decrypted)); // ===== 2. AEAD认证加密 ===== const additionalData = new TextEncoder().encode("context info"); const aeadCiphertext = FlashSwirl.encrypt('aead', key, nonce, plaintext, additionalData, 20); const aeadDecrypted = FlashSwirl.decrypt('aead', key, nonce, aeadCiphertext, additionalData, 20); console.log("AEAD Decrypted:", new TextDecoder().decode(aeadDecrypted)); // ===== 3. HASH ===== const message = new TextEncoder().encode("Hello, FlashSwirl!"); const hash = FlashSwirl.hash(message, 20); console.log("Hash:", Array.from(hash).map(b => b.toString(16).padStart(2, '0')).join('')); // ===== 4. HMAC ===== const hmacKey = new TextEncoder().encode("secret-key"); const hmacResult = FlashSwirl.hmac(hmacKey, message, 20); console.log("HMAC:", Array.from(hmacResult).map(b => b.toString(16).padStart(2, '0')).join('')); // ===== 5. HKDF密钥派生 ===== const salt = new TextEncoder().encode("random-salt"); const info = new TextEncoder().encode("my-app"); const derivedKey = 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密钥派生 ===== const password = new TextEncoder().encode("user-password"); const pbkdf2Salt = new TextEncoder().encode("random-salt"); const keyFromPassword = FlashSwirl.pbkdf2(password, pbkdf2Salt, 10000, 32, 20); console.log("Key from password:", Array.from(keyFromPassword).map(b => b.toString(16).padStart(2, '0')).join('')); ``` ## 开源地址 <a href="elink@292K9s2c8@1M7s2y4Q4x3@1q4Q4x3V1k6Q4x3V1k6Y4K9i4c8Z5N6h3u0Q4x3X3g2U0L8$3#2Q4x3V1k6X3P5Y4S2^5i4K6u0r3c8X3I4S2M7$3S2e0N6$3W2J5L8l9`.`."><mark class="encrypted">af5K9s2c8@1M7s2y4Q4x3@1q4Q4x3V1k6Q4x3V1k6Y4K9i4c8Z5N6h3u0Q4x3X3g2U0L8$3#2Q4x3V1k6X3P5Y4S2^5i4K6u0r3c8X3I4S2M7$3S2e0N6$3W2J5L8l9`.`.</mark></a> ## 最后 看看有没有人能破解出明文、密钥或者篡改认证标签 ### 8轮流密码 Nonce ``` ea1d81b7f34491c2098d22d84c5775d96d7d22cf24d1474c ``` 密文 ``` 7ab31ed650d880971841acf2ac575b1f3233e78ce37168f8167524e15fc4c21ab307120dd3c6f92b48e1c1b9e5724db6f7ba43c0cfe30cfc82bd37bc1b2a050b57406d953cf66c482d9dd63d0d370cbb3e321134b739c8b61a0d52deacc3264fdf04cb8eebd001c1e8b995f12814779127189cf10d1cd67fb84647d6af91df3f8efb18aabf1255fe1f5e5dd3c372231600daa53e2fe2da97e5de3161f80d154deb ``` ### 20轮AEAD Nonce ``` 27d481305a41e867520fe8f5ba433ec7cf5e0f6558e4febd ``` 密文 ``` 125c3f45a857e826769118f0ff983249003ae1bb908183355cd4876a38fe8d9687ddc15bf22828a2782e81560209f82dca1756ca9d01a4f81304272cf57fbe9eca8b117f56fbe6a43f3bce7385e112492c32db40a467dbbff541af64ca27fde182e0f5f6e8c7d9915f5047961d615066d4c48ade7de0257e42ea98d84017efc0ffb72b08f48f00f1d95922d4f2640777c7f67602ad407bc3328864c96078150fa58397882a79b79bf6d3cf07cbb27afab9 ```
冰与火的战歌:Windows内核攻防实战高级班!从零到实战,融合AI与Windows内核攻防全技术栈,打造具备自动化能力的内核开发高手。
收藏
・
0
点赞
・
0
打赏
分享
分享到微信
分享到QQ
分享到微博
赞赏记录
参与人
雪币
留言
时间
查看更多
赞赏
×
1 雪花
5 雪花
10 雪花
20 雪花
50 雪花
80 雪花
100 雪花
150 雪花
200 雪花
支付方式:
微信支付
赞赏留言:
快捷留言
感谢分享~
精品文章~
原创内容~
精彩转帖~
助人为乐~
感谢分享~
最新回复
(
1
)
风之暇想
雪 币:
226
活跃值:
(170)
能力值:
( LV2,RANK:10 )
在线值:
发帖
1
回帖
3
粉丝
0
关注
私信
风之暇想
2
楼
看来没有人破1.1版本,那么1.2版本自用了
6天前
0
游客
登录
|
注册
方可回帖
回帖
表情
雪币赚取及消费
高级回复
返回
风之暇想
1
发帖
3
回帖
10
RANK
关注
私信
他的文章
[原创自研]FlashSwirl 闪旋,一款高性能的对称加密算法库
2807
关于我们
联系我们
企业服务
看雪公众号
专注于PC、移动、智能设备安全研究及逆向工程的开发者社区
看原图
赞赏
×
雪币:
+
留言:
快捷留言
为你点赞!
返回
顶部