jan2000/ffxradix

格式保持加密的FFX操作模式的Scheme FFX[radix]

v1.1.0 2016-07-17 21:46 UTC

This package is not auto-updated.

Last update: 2024-09-20 22:43:17 UTC


README

Build Status

这是 格式保持加密的FFX操作模式 [1,2] 中的FFX[radix]方案的PHP实现。也称为NIST特别出版物800-38G中的模式FF1: 推荐块加密操作模式:格式保持加密的方法 [3]

使用介于2到62之间的基数加密和解密消息,并保持其长度。在FFX[radix]下加密的消息被视为来自字母表 Chars = {0, 1, 2,...,radix − 1} 的字符串。方案FFX[radix]使用基于AES的平衡Feistel网络来完成其工作。如果消息长度为奇数,则使用交替的、最大平衡的Feistel方案。

示例用法

<?php
require __DIR__.'/vendor/autoload.php';

use Janv\FFXRadix\FFXRadix;

// Key must be a 16 byte long string if AES-128 (default) is used
$key = hex2bin('00000000000000000000000000000000');
// Tweak can be anything
$tweak = hex2bin('0123456789abcdef');

$ffx = new FFXRadix();

// Encrypt a 16 decimal number (radix = 10)
$enc = $ffx->encrypt(sprintf('%016d', 1), 10, $key, $tweak);
// Outputs 1299047952447293
echo "$enc\n";

// Decrypt
$dec = $ffx->decrypt($enc, 10, $key, $tweak);
// Outputs 0000000000000001
echo "$dec\n";

测试

此实现已通过以下提供的测试向量进行验证