承接 brainfoolong/php-ascon 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

brainfoolong/php-ascon

最新稳定版本:1.3.0

Composer 安装命令:

composer require brainfoolong/php-ascon

包简介

PHP 8+ Implementation of Ascon, a family of authenticated encryption (AEAD) and hashing algorithms designed to be lightweight.

README 文档

README

Tests

This is a PHP implementation of Ascon v1.3, an authenticated cipher and hash function. It allows to encrypt and decrypt any kind of message. Includes the authenticated encryption and hash function variants as specified in NIST SP 800-232 (initial public draft). Heavily inspired by the python implementation of Ascon by https://github.com/meichlseder/pyascon

Notice: This library does contain the version 1.3 of Ascon. v1.2 was a draft version and there are already newer versions of ascon. See https://github.com/ascon/ascon-c . Version 1.2 is not compatible with 1.3

About Ascon

Ascon is a family of authenticated encryption (AEAD) and hashing algorithms designed to be lightweight and easy to implement, even with added countermeasures against side-channel attacks. It was designed by a team of cryptographers from Graz University of Technology, Infineon Technologies, and Radboud University: Christoph Dobraunig, Maria Eichlseder, Florian Mendel, and Martin Schläffer.

Ascon has been selected as the standard for lightweight cryptography in the NIST Lightweight Cryptography competition (2019–2023) and as the primary choice for lightweight authenticated encryption in the final portfolio of the CAESAR competition (2014–2019).

Find more information, including the specification and more implementations here:

https://ascon.iaik.tugraz.at/

About me

I have made library for AES PHP/JS encryption already in the past. Bit juggling is somewhat cool, in a really nerdy way. I like the Ascon implementation and it at the time of writing, a PHP implementation was missing. So i made one. Would be cool if you leave a follow or spend some virtual coffee. s

Javascript/Typescript Implementation

Chances are high that you probably need a Javascript/Typescript (For your frontend) implementation too. I've made one here -> https://github.com/brainfoolong/js-ascon

Installation

# via composer
composer require brainfoolong/php-ascon

Performance

As PHP do not support unsigned integers, there is no chance to directly work with 64bit unsigned integers. This library use 2x 32bit integers for all bit operations, which have performance penalties (almost half as fast as the typescript implementation). Without requiring specials php extensions which can handle 64bit unsigned integers, there is no way to improve the performance for now.

Usage

For more demos see in folder demo.

use Nullix\Ascon\Ascon;
// convenient usage (generating random nonce and hashing keys for you)
$key = "mypassword";
$message = ["this can be any data type 😎 文 or encoding", 123];
$associatedData = "Some data 😋 文 This data is not contained in the encrypt output but must be passed to both encrypt and decrypt.";
$encrypted = Ascon::encryptToHex($key, $message, $associatedData);
$decrypted = Ascon::decryptFromHex($key, $encrypted, $associatedData);

// raw usage of basic methods
// key must be 16 bytes or 20 bytes, depending on variant
$key = [0x90, 0x80, 0x70, 0x60, 0x50, 0x40, 0x30, 0x20, 0x10, 0xAA, 0x90, 0x90, 0x90, 0x90, 0xCC, 0xEF];
// nonce must be 16 bytes and should always be random bytes, you must use same nonce for encrypt and decrypt the same message
$nonce = random_bytes(16);
// this is the text you want to encrypt
$plaintext = "Hi, i am a secret message!";
// associated data is not being encrypted, but is taken into account in the ciphertext
// this means, you can only decrypt when you pass the exact same associated data to the decrypt function as well
// so you can make sure that associated data and plaintext is not manipulated for given encrypted message
// this is optional and can be an empty string
$associatedData = "Some data to pass to encryption and decryption - This data is not contained in the ciphertext output.";
$ciphertextByteArray = Ascon::encrypt($key, $nonce, $associatedData, $plaintext);
$plaintextDecrypted = Ascon::decrypt($key, $nonce, $associatedData, $ciphertextByteArray);

var_dump(Ascon::hash('Testmessage'));
var_dump(Ascon::mac($key, 'Testmessage'));

Development

Change code in src/Ascon.php. Test changes with php tests/tests.php.

Algorithms

This is a simple reference implementation of Ascon as specified in NIST's draft standard, NIST SP 800-232, which includes

  • Authenticated encryption Ascon::encrypt and Ascon::decrypt

    • Ascon-AEAD128
  • Hashing algorithms Ascon::hash including 3 hash function variants with slightly different interfaces:

    • Ascon-Hash256 with fixed 256-bit output
    • Ascon-XOF128 with variable output lengths (specified with hashlength)
    • Ascon-CXOF128 with variable output lengths (hashlength) and supporting a customization string as an additional input (to be implemented)
  • Message Authentication Code Ascon::mac

    • Ascon-Mac (128-bit output, arbitrarily long input),
    • Ascon-Prf (arbitrarily long input and output),
    • Ascon-PrfShort (t-bit output for t<=128, m-bit input for m<=128)

Older Algorithm Variants

Older versions implement Ascon v1.2 as submitted to the NIST LWC competition and published in the Journal of Cryptology, as well as additional functionality for message authentication. These versions can be found in at https://github.com/brainfoolong/php-ascon/tree/412dd162b737c212829c95787e7a4801fec7629e, including

  • Authenticated encryption:

    • Ascon-128
    • Ascon-128a
    • Ascon-80pq
  • Hashing algorithms:

    • Ascon-Hash
    • Ascon-Hasha
    • Ascon-Xof
    • Ascon-Xofa
  • Message authentication codes ascon_mac(key, message, variant="Ascon-Mac", taglength=16) for 5 MAC variants (from https://eprint.iacr.org/2021/1574, not part of the LWC proposal) with fixed 128-bit (Mac) or variable (Prf) output lengths, including a variant for short messages of up to 128 bits (PrfShort).

    • Ascon-Mac
    • Ascon-Maca
    • Ascon-Prf
    • Ascon-Prfa
    • Ascon-PrfShortort`

brainfoolong/php-ascon 适用场景与选型建议

brainfoolong/php-ascon 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2023 年 11 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「hash」 「encryption」 「decryption」 「cipher」 「MAC」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 brainfoolong/php-ascon 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 brainfoolong/php-ascon 我们能提供哪些服务?
定制开发 / 二次开发

基于 brainfoolong/php-ascon 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 36
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-24