PHP Classes

File: tests/unit/HChaCha20Test.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   PHP Sodium Compat   tests/unit/HChaCha20Test.php   Download  
File: tests/unit/HChaCha20Test.php
Role: Class source
Content type: text/plain
Description: Class source
Class: PHP Sodium Compat
Cryptographic functions of libsodium in pure PHP
Author: By
Last change:
Date: 6 years ago
Size: 1,643 bytes
 

Contents

Class file image Download
<?php

class HChaCha20Test extends PHPUnit_Framework_TestCase
{
   
/**
     * @covers ParagonIE_Sodium_Core_HChaCha20::hChaCha20()
     */
   
public function testVector()
    {
       
$key = str_repeat("\x00", 32);
       
$iv = str_repeat("\x00", 16);

       
$this->assertSame(
           
'1140704c328d1d5d0e30086cdf209dbd6a43b8f41518a11cc387b669b2ee6586',
           
ParagonIE_Sodium_Core_Util::bin2hex(
               
PHP_INT_SIZE === 4
                   
? ParagonIE_Sodium_Core32_HChaCha20::hChaCha20($iv, $key)
                    :
ParagonIE_Sodium_Core_HChaCha20::hChaCha20($iv, $key)
            ),
           
'hChaCha20 with all 0s'
       
);

       
$iv = "\x80" . str_repeat("\x00", 15);

       
$this->assertSame(
           
'ff34edeb8f338fb707f5ef4695302d9fc8b567517f9fc0983970019823266d2c',
           
ParagonIE_Sodium_Core_Util::bin2hex(
               
PHP_INT_SIZE === 4
                   
? ParagonIE_Sodium_Core32_HChaCha20::hChaCha20($iv, $key)
                    :
ParagonIE_Sodium_Core_HChaCha20::hChaCha20($iv, $key)
            ),
           
'hChaCha20 with one nonce bitflip'
       
);

       
$key = "\x80" . str_repeat("\x00", 31);
       
$iv = str_repeat("\x00", 16);

       
$this->assertSame(
           
'7d266a7fd808cae4c02a0a70dcbfbcc250dae65ce3eae7fc210f54cc8f77df86',
           
ParagonIE_Sodium_Core_Util::bin2hex(
               
PHP_INT_SIZE === 4
                   
? ParagonIE_Sodium_Core32_HChaCha20::hChaCha20($iv, $key)
                    :
ParagonIE_Sodium_Core_HChaCha20::hChaCha20($iv, $key)
            ),
           
'hChaCha20 with one key bitflip'
       
);
    }
}