Skip to content

Commit

Permalink
Fix Build
Browse files Browse the repository at this point in the history
  • Loading branch information
ircmaxell committed Jun 28, 2011
1 parent fc93886 commit bc68c09
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 41 deletions.
4 changes: 2 additions & 2 deletions build/PHPCS/ruleset.xml
Expand Up @@ -23,8 +23,8 @@

<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="80" />
<property name="absoluteLineLimit" value="85" />
<property name="lineLimit" value="85" />
<property name="absoluteLineLimit" value="90" />
</properties>
</rule>

Expand Down
4 changes: 0 additions & 4 deletions build/build.xml
Expand Up @@ -49,12 +49,8 @@
<target name="cs" depends="prepare">
<exec
command="phpcs --report=summary --report-checkstyle=${logdir}/checkstyle.xml --standard=${builddir}/PHPCS/ruleset.xml ${libdir}/CryptLib"
os="Linux"
passthru="true"
checkreturn="true" />
<exec
command="phpcs.bat --report=summary --report-checkstyle=${logdir}/checkstyle.xml --standard=${builddir}/PHPCS/ruleset.xml ${libdir}/CryptLib"
os="WIN" checkreturn="true" />
</target>

<target name="cpd" depends="prepare">
Expand Down
4 changes: 2 additions & 2 deletions lib/CryptLib/Cipher/Block/Mode.php
Expand Up @@ -33,7 +33,7 @@ interface Mode {
* @param string $key The key to use for decrypting the data
* @param BlockCipher $cipher The cipher to use for decrypting the data
* @param string $initv The initialization vector to use
* @param string $adata Any additional authenticated data to encrypt/decrypt with
* @param string $adata Any additional authenticated data to decrypt with
*
* @return string The decrypted data
*/
Expand All @@ -52,7 +52,7 @@ public function decrypt(
* @param string $key The key to use for encrypting the data
* @param BlockCipher $cipher The cipher to use for encrypting the data
* @param string $initv The initialization vector to use
* @param string $adata Any additional authenticated data to encrypt/decrypt with
* @param string $adata Any additional authenticated data to encrypt with
*
* @return string The encrypted data
*/
Expand Down
78 changes: 45 additions & 33 deletions lib/CryptLib/Cipher/Block/Mode/CCM.php
Expand Up @@ -61,7 +61,7 @@ public function setAuthFieldSize($new) {
}

/**
* Set the size of the length field. This is a tradeoff between the maximum
* Set the size of the length field. This is a tradeoff between the maximum
* message size and the size of the initialization vector
*
* Valid values are 2, 3, 4, 5, 6, 7, 8
Expand Down Expand Up @@ -98,12 +98,18 @@ public function decrypt(
$initv,
$adata = ''
) {
$initv = $this->extractInitv($initv, $cipher->getBlockSize($key));
$message = substr($data, 0, -1 * $this->authFieldSize);
$uValue = substr($data, -1 * $this->authFieldSize);
$data = $this->encryptMessage($initv, $key, $message, $uValue, $cipher);
$computedT = substr($data, -1 * $this->authFieldSize);
$data = substr($data, 0, -1 * $this->authFieldSize);
$initv = $this->extractInitv($initv, $cipher->getBlockSize($key));
$message = substr($data, 0, -1 * $this->authFieldSize);
$uValue = substr($data, -1 * $this->authFieldSize);
$data = $this->encryptMessage(
$initv,
$key,
$message,
$uValue,
$cipher
);
$computedT = substr($data, -1 * $this->authFieldSize);
$data = substr($data, 0, -1 * $this->authFieldSize);
$authFieldT = $this->computeAuthField($initv, $key, $data, $adata, $cipher);
if ($authFieldT != $computedT) {
return false;
Expand All @@ -129,10 +135,16 @@ public function encrypt(
$initv,
$adata = ''
) {
$blockSize = $cipher->getBlockSize($key);
$initv = $this->extractInitv($initv, $blockSize);
$blockSize = $cipher->getBlockSize($key);
$initv = $this->extractInitv($initv, $blockSize);
$authFieldT = $this->computeAuthField($initv, $key, $data, $adata, $cipher);
$data = $this->encryptMessage($initv, $key, $data, $authFieldT, $cipher);
$data = $this->encryptMessage(
$initv,
$key,
$data,
$authFieldT,
$cipher
);
return $data;
}

Expand All @@ -157,35 +169,35 @@ public function getMode() {
* @return string The computed MAC Authentication Code
*/
protected function computeAuthField(
$initv,
$key,
$data,
$adata,
$initv,
$key,
$data,
$adata,
\CryptLib\Cipher\Block\BlockCipher $cipher
) {
$blockSize = $cipher->getBlockSize($key);
$flags = pack(
'C',
64 * (empty($adata) ? 0 : 1)
+ 8 * (($this->authFieldSize - 2) / 2)
$flags = pack(
'C',
64 * (empty($adata) ? 0 : 1)
+ 8 * (($this->authFieldSize - 2) / 2)
+ ($this->lSize - 1)
);
$blocks = array(
$blocks = array(
$flags . $initv . pack($this->getLPackString(), strlen($data))
);
if (strlen($data) % $blockSize != 0) {
$data .= str_repeat(chr(0), $blockSize - (strlen($data) % $blockSize));
}

$blocks = array_merge($blocks, $this->processAData($adata, $blockSize));
$blocks = array_merge($blocks, str_split($data, $blockSize));
$crypted = array(
$blocks = array_merge($blocks, $this->processAData($adata, $blockSize));
$blocks = array_merge($blocks, str_split($data, $blockSize));
$crypted = array(
1 => $cipher->encryptBlock($blocks[0], $key)
);
$blockLen = count($blocks);
for ($i = 1; $i < $blockLen; $i++) {
$crypted[$i + 1] = $cipher->encryptBlock(
$crypted[$i] ^ $blocks[$i],
$crypted[$i] ^ $blocks[$i],
$key
);
}
Expand All @@ -204,20 +216,20 @@ protected function computeAuthField(
* @return string The encrypted data with authfield payload
*/
protected function encryptMessage(
$initv,
$key,
$data,
$initv,
$key,
$data,
$authValue,
\CryptLib\Cipher\Block\BlockCipher $cipher
) {
$blockSize = $cipher->getBlockSize($key);
$flags = pack('C', ($this->lSize - 1));
$blocks = str_split($data, $blockSize);
$sblocks = array();
$blockLen = count($blocks);
$flags = pack('C', ($this->lSize - 1));
$blocks = str_split($data, $blockSize);
$sblocks = array();
$blockLen = count($blocks);
for ($i = 0; $i <= $blockLen; $i++) {
$sblocks[] = $cipher->encryptBlock(
$flags . $initv . pack($this->getLPackString(), $i),
$flags . $initv . pack($this->getLPackString(), $i),
$key
);
}
Expand Down Expand Up @@ -262,7 +274,7 @@ protected function extractInitv($initv, $blockSize) {
protected function getLPackString() {
if ($this->lSize <= 3) {
return str_repeat('x', $this->lSize - 2) . 'n';
}
}
return str_repeat('x', $this->lSize - 4) . 'N';
}

Expand All @@ -285,7 +297,7 @@ protected function processAData($adata, $blockSize) {
if (strlen($temp) % $blockSize != 0) {
//Pad the string to exactly mod16
$temp .= str_repeat(
chr(0),
chr(0),
$blockSize - (strlen($temp) % $blockSize)
);
}
Expand Down

0 comments on commit bc68c09

Please sign in to comment.