当前位置: 首页 > news >正文

基于ASCON的AEAD

1. 引言

前序博客:

  • ASCON:以“慢而稳”赢得NIST轻量级加密算法标准
  • 密码学中的AEAD(authenticated encryption with associated data)

对称密钥加密过去数年来已发生改变,具体为:

  • 当今主要使用stream ciphers,因其比block ciphers要快得多。
  • 经常会使用AEAD(Authenticated Encryption with Additional Data)。
  • 在加密过程中常使用sponge函数,进而支持使用sponge函数来创建对称密钥和哈希函数。
  • Rust现在正在成为一种事实上的软件语言,它在编码方面提高了健壮性。

ASCON代码示例见:

  • ASCON AEAD - Light-weight cipher
  • https://github.com/usnistgov/Lightweight-Cryptography-Benchmarking(C)
  • https://github.com/meichlseder/pyascon/blob/master/ascon.py(Python)
  • https://github.com/itzmeanjan/ascon(C++)
  • https://github.com/NomanNasirMinhas/ASCON_Benchmark(Rust)
  • https://github.com/sebastinas/isap-aead(Rust)
  • https://github.com/neoilir/Simple-ascon-hash-implementation-rust(Rust)
  • https://github.com/sebastinas/ascon-aead(Rust)
  • https://github.com/IAIK/ascon_hardware(VHDL,硬件实现)
  • https://github.com/ascon/ascon-c(C和汇编)
  • https://github.com/ascon/ascon-hardware(Python和VHDL,硬件实现)
  • https://github.com/RustCrypto/sponges/tree/master/ascon(Rust)
  • https://github.com/RustCrypto/AEADs/tree/master/ascon-aead(Rust)

2. AEAD(Authenticated Encryption with Additional Data)

所谓对称密钥加密,是指使用相同的密钥来加解密:
在这里插入图片描述
但是这样的对称密钥加密存在重放攻击问题,如:

  • Bob用对称密钥加密了一条消息给Alice,Alice收到密文用相同的对称密钥解密后,获得“你明天可休假一天”,于是Alice第二天休假了。
  • 但是,Eve窃听了上述消息,在第二天将相同的密文再次发送给Alice,Alice解密后,第三天又休假了一天。
  • Bob会很奇怪,为啥Alice连休了2天假。

原因就在于Eve对密文进行了重放攻击。因此,需要将加密过程与某网络连接或session绑定,使得Eve无法重构相同的场景。

通过增强的加密方法,使得既可认证加密,也可证明其完整性。这被称为关联数据的身份验证加密(AEAD)。为此,提供额外的数据来认证加密过程,并可识别密文已被修改因其无法被加密:
在这里插入图片描述
大多数传统的AEA方法为创建一个nonce值,并添加认证但不加密的额外数据(Additional Data, AD)。额外数据AD可为:

addresses, ports, sequence numbers, protocol version numbers, and other fields that indicate how the plaintext or ciphertext should be handled, forwarded, or processed

这样就可将网络包与加密数据绑定,提供了完整性,使得入侵者无法复制粘贴其它通道的密文来形成攻击。如,若绑定包序号和端口号,使用另一序号或端口号将认证失败。

可以用于AEAD的主要方法是AES GCM、AES SIV、AES CCM、ChaCha20/Poly1305和AES OCB3。每一个都是流密码,避免了CBC和ECB的块方法模式。

3. 基于ASCON的AEAD

如以https://github.com/RustCrypto/sponges/tree/master/ascon(Rust)实现的AEAD为例:

cargo new arc

相应的cargo.toml文件为:

[package]
name = "arc"
version = "0.1.0"
edition = "2021"# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html[dependencies]
ascon = "0.1.4"
rand="0.8.3"
hex="0.4.3"

相应的main.rs源代码为:

use ascon;
use rand::thread_rng;
use rand::Rng;
use hex::{self};
use std::env;fn get_random_key16() ->  [u8; 16]{let mut arr = [0u8; 16];thread_rng().try_fill(&mut arr[..]).expect("Ooops!");return arr;
}fn main() {let mut msg="hello";let mut aad1="test";let args: Vec<String> = env::args().collect();if args.len() >1 { msg = args[1].as_str();}if args.len() >2 { aad1 = args[2].as_str();}let randkey128=get_random_key16(); //为128字节let iv=get_random_key16(); //用作saltlet plaintext=msg.as_bytes();let aad=aad1.as_bytes();let (ciphertext,tag) = ascon::aead_encrypt(&randkey128, &iv, plaintext, aad); //tag也为128字节let pt=ascon::aead_decrypt(&randkey128, &iv,&ciphertext[..], &aad, &tag);let s = String::from_utf8(pt.unwrap()).expect("Found invalid UTF-8");println!("Message:\t{}\n",msg);println!("AAD:\t\t{}\n",aad1);println!("Key:\t\t{}\n",hex::encode(randkey128));println!("Cipher:\t\t{}\n",hex::encode(ciphertext));println!("Tag:\t\t{}\n",hex::encode(tag));println!("Decryped:\t{}", s);
}

运行结果为:

Message:        helloAAD:            testKey:            6680811197f36de07227b8f08ae31c33Cipher:         01e0d0d020Tag:            6e90b3a9790c28188172d5bd8041555dDecryped:       hello

参考资料

[1] Prof Bill Buchanan OBE 2023年9月博客 ASCON, Rust and AEAD: Is ASCON better than AES?

http://www.lryc.cn/news/172455.html

相关文章:

  • 汇编宏伪指令介绍
  • 优化系统报错提示信息,提高人机交互(一)
  • FPGA纯verilog实现8路视频拼接显示,提供工程源码和技术支持
  • spring boot项目一次性能测试的总结
  • 10分钟设置免费海外远程桌面
  • 基于复旦微的FMQL45T900全国产化ARM核心模块(100%国产化)
  • 2023.9.11 关于传输层协议 UDP和TCP 详解
  • thinkphp8路由
  • Python统计pdf中英文单词的个数
  • Kindle电子书下载功能关闭怎么办,借助calibre和cpolar搭建私有的网络书库公网访问
  • ubuntu、linux in window安装docker教程
  • clickhouse学习之路----clickhouse的特点及安装
  • STM32 驱动
  • JavaScript系列从入门到精通系列第五篇:JavaScript中的强制类型转换包含强制类型转换之Number,包含强制类型转换之String
  • 动力节点老杜JavaWeb笔记(全)
  • 【微信小程序开发】宠物预约医疗项目实战-注册实现
  • 聚观早报 | 飞书签约韵达速递;蔚来首颗自研芯片“杨戬”量产
  • zookeeper + kafka
  • wordpress添加评论过滤器
  • 工具篇 | Gradle入门与使用指南
  • Wireshark TS | MQ 传输缓慢问题
  • flink集群与资源@k8s源码分析-回顾
  • 学习心得09:C++新特性
  • 前端框架vBean admin
  • 云原生周刊:Grafana Beyla 发布 | 2023.9.18
  • C++ std::unique_lock 用法
  • Pytorch C++ 前端第二部分:输入、权重和偏差
  • 面试题:RocketMQ 如何保证消息不丢失,如何保证消息不被重复消费?
  • uniapp打包安卓后在安卓屏上实现开机自启动
  • 浅谈KNX总线智能照明控制系统在北京南站房中的应用