From b6d2896c0832dd6bd75b2ec793a9df8137676d8c Mon Sep 17 00:00:00 2001 From: Florent Morselli Date: Mon, 14 Nov 2016 19:13:39 +0100 Subject: [PATCH] Tag Length and Appended Tag support --- README.md | 57 ++++++++++++++++++++++++++++++++++ src/AESGCM.php | 72 +++++++++++++++++++++++++++++++++++++------ tests/IEEE802Test.php | 7 +++++ tests/NistTest.php | 7 +++++ 4 files changed, 134 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index acfd01e..661f9a7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,12 @@ AES GCM (Galois Counter Mode) PHP Implementation ==================================================== +Help me out for a couple of :beers:! + +[![Beerpay](https://beerpay.io/Spomky-Labs/php-aes-gcm/badge.svg?style=beer-square)](https://beerpay.io/Spomky-Labs/php-aes-gcm) [![Beerpay](https://beerpay.io/Spomky-Labs/php-aes-gcm/make-wish.svg?style=flat-square)](https://beerpay.io/Spomky-Labs/php-aes-gcm?focus=wish) + +---- + [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Spomky-Labs/php-aes-gcm/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Spomky-Labs/php-aes-gcm/?branch=master) [![Coverage Status](https://coveralls.io/repos/github/Spomky-Labs/php-aes-gcm/badge.svg?branch=master)](https://coveralls.io/github/Spomky-Labs/php-aes-gcm?branch=master) @@ -37,6 +43,8 @@ composer require "spomky-labs/php-aes-gcm" # How to use ```php +assertEquals($P, $computed_P); + + foreach([128, 120, 112, 104, 96] as $tag_length) { + + $c = AESGCM::encryptAndAppendTag($K, $IV, $P, $A, $tag_length); + $p = AESGCM::decryptWithAppendedTag($K, $IV, $c, $A, $tag_length); + $this->assertEquals($P, $p); + } } public function dataVectors() diff --git a/tests/NistTest.php b/tests/NistTest.php index b0eab2c..55e28ce 100644 --- a/tests/NistTest.php +++ b/tests/NistTest.php @@ -30,6 +30,13 @@ public function testVectors($K, $P, $A, $IV, $expected_C, $expected_T) $computed_P = AESGCM::decrypt($K, $IV, $C, $A, $T); $this->assertEquals($P, $computed_P); + + foreach([128, 120, 112, 104, 96] as $tag_length) { + + $c = AESGCM::encryptAndAppendTag($K, $IV, $P, $A, $tag_length); + $p = AESGCM::decryptWithAppendedTag($K, $IV, $c, $A, $tag_length); + $this->assertEquals($P, $p); + } } public function dataVectors()