cryptal
latest
Cryptography Abstraction Layer
Main Page
Classes
Files
File List
NonEmptyZero.php
1
<?php
2
3
namespace
fpoirotte\Cryptal\Padding
;
4
5
use
fpoirotte\Cryptal\PaddingInterface
;
6
11
class
NonEmptyZero
implements
PaddingInterface
12
{
13
public
function
getPaddingData
($blockSize, $expectedSize)
14
{
15
return
str_repeat(
"\x00"
, $expectedSize);
16
}
17
18
public
function
getPaddingSize
($paddedData, $blockSize)
19
{
20
// We could use strspn(strrev($paddedData), "\x00") instead,
21
// but this would require additional memory allocations,
22
// which is undesirable as $paddedData gets larger.
23
$m = strlen($paddedData) - 1;
24
for
($i = 0; $i <= $blockSize && $i <= $m &&
"\x00"
=== $paddedData[$m - $i]; $i++) {
25
// Nothing to do
26
}
27
28
if
(0 === $i) {
29
// This should never happen.
30
throw
new \Exception(
'Invalid data'
);
31
}
32
33
return
$i;
34
}
35
}
fpoirotte\Cryptal\PaddingInterface
Definition:
PaddingInterface.php:8
fpoirotte\Cryptal\Padding
Definition:
AnsiX923.php:3
fpoirotte\Cryptal\Padding\NonEmptyZero
Definition:
NonEmptyZero.php:11
fpoirotte\Cryptal\Padding\NonEmptyZero\getPaddingData
getPaddingData($blockSize, $expectedSize)
Definition:
NonEmptyZero.php:13
fpoirotte\Cryptal\Padding\NonEmptyZero\getPaddingSize
getPaddingSize($paddedData, $blockSize)
Definition:
NonEmptyZero.php:18
PaddingInterface
src
Cryptal
Padding
NonEmptyZero.php
Generated on Sat Sep 29 2018 22:22:05 for cryptal by
1.8.11