吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 312|回复: 2
上一主题 下一主题
收起左侧

[C&C++ 原创] 给cppcryptfs增加Xchacha20-poly1305算法

[复制链接]
跳转到指定楼层
楼主
风之暇想 发表于 2026-9-2 13:31 回帖奖励
本帖最后由 风之暇想 于 2026-9-2 13:35 编辑


🤔Cppcryptfs是基于gocryptfs设计的,但是由于调用的库迟迟不添加Xchacha20-poly1305,所以没有加入Xchacha20-poly1305;我给手动添加上了。

截图

部分代码

#include "stdafx.h"

#include <cstring>
#include <cstdint>

#include "chacha20.h"

static void chacha20_quarter_round(uint32_t s[16], int a, int b, int c, int d)
{
        s[a] += s[b]; s[d] ^= s[a]; s[d] = (s[d] << 16) | (s[d] >> 16);
        s[c] += s[d]; s[b] ^= s[c]; s[b] = (s[b] << 12) | (s[b] >> 20);
        s[a] += s[b]; s[d] ^= s[a]; s[d] = (s[d] << 8)  | (s[d] >> 24);
        s[c] += s[d]; s[b] ^= s[c]; s[b] = (s[b] << 7)  | (s[b] >> 25);
}

static void wipe_words(uint32_t *p, int n)
{
        volatile uint32_t *v = p;
        while (n--)
                *v++ = 0;
}

void hchacha20(const unsigned char key[32], const unsigned char nonce[16], unsigned char out[32])
{
        static const uint32_t constant[4] = {
                0x61707865, 0x3320646e, 0x79622d32, 0x6b206574
        };

        uint32_t state[16];

        state[0] = constant[0];
        state[1] = constant[1];
        state[2] = constant[2];
        state[3] = constant[3];

        for (int i = 0; i < 8; i++)
                state[4 + i] = (uint32_t)key[4*i] | ((uint32_t)key[4*i+1] << 8) |
                        ((uint32_t)key[4*i+2] << 16) | ((uint32_t)key[4*i+3] << 24);

        for (int i = 0; i < 4; i++)
                state[12 + i] = (uint32_t)nonce[4*i] | ((uint32_t)nonce[4*i+1] << 8) |
                        ((uint32_t)nonce[4*i+2] << 16) | ((uint32_t)nonce[4*i+3] << 24);

        uint32_t working[16];
        memcpy(working, state, sizeof(working));

        for (int round = 0; round < 10; round++) {
                chacha20_quarter_round(working, 0, 4, 8, 12);
                chacha20_quarter_round(working, 1, 5, 9, 13);
                chacha20_quarter_round(working, 2, 6, 10, 14);
                chacha20_quarter_round(working, 3, 7, 11, 15);
                chacha20_quarter_round(working, 0, 5, 10, 15);
                chacha20_quarter_round(working, 1, 6, 11, 12);
                chacha20_quarter_round(working, 2, 7, 8, 13);
                chacha20_quarter_round(working, 3, 4, 9, 14);
        }

        uint32_t out_words[8];
        for (int i = 0; i < 4; i++)
                out_words[i] = working[i];
        for (int i = 0; i < 4; i++)
                out_words[4 + i] = working[12 + i];

        memcpy(out, out_words, 32);

        wipe_words(state, 16);
        wipe_words(working, 16);
        wipe_words(out_words, 8);
}

开源地址

https://github.com/fzxx/cppcryptfs

免费评分

参与人数 1威望 +1 吾爱币 +20 热心值 +1 收起 理由
苏紫方璇 + 1 + 20 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

沙发
自然疯 发表于 2026-9-2 13:47
软件下载有吗
3#
开创者 发表于 2026-9-2 14:06
这个怎么玩啊,和你之前弄的那个7zip的有区别吗
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - 52pojie.cn ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2026-9-10 05:02

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表