Skip to content
This repository has been archived by the owner on Dec 30, 2020. It is now read-only.

Commit

Permalink
EC Key Creator and new AES GCM dep (#155)
Browse files Browse the repository at this point in the history
* GCM algorithms improvements
  • Loading branch information
Spomky authored Dec 25, 2016
1 parent ce66425 commit 749695b
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 52 deletions.
23 changes: 0 additions & 23 deletions src/Algorithm/ContentEncryption/AESGCM.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Jose\Algorithm\ContentEncryption;

use AESGCM\AESGCM as GCM;
use Crypto\Cipher;
use Jose\Algorithm\ContentEncryptionAlgorithmInterface;

abstract class AESGCM implements ContentEncryptionAlgorithmInterface
Expand Down Expand Up @@ -42,31 +41,9 @@ public function decryptContent($data, $cek, $iv, $aad, $encoded_protected_header
$calculated_aad .= '.'.$aad;
}

if (version_compare(PHP_VERSION, '7.1.0') >= 0) {
return openssl_decrypt($data, $this->getMode($cek), $cek, OPENSSL_RAW_DATA, $iv, $tag, $calculated_aad);
} elseif (class_exists('\Crypto\Cipher')) {
$cipher = Cipher::aes(Cipher::MODE_GCM, $this->getKeySize());
$cipher->setTag($tag);
$cipher->setAAD($calculated_aad);

$plaintext = $cipher->decrypt($data, $cek, $iv);

return $plaintext;
}

return GCM::decrypt($cek, $iv, $data, $calculated_aad, $tag);
}

/**
* @param string $k
*
* @return string
*/
private function getMode($k)
{
return 'aes-'.(8 * mb_strlen($k, '8bit')).'-gcm';
}

/**
* @return int
*/
Expand Down
23 changes: 0 additions & 23 deletions src/Algorithm/KeyEncryption/AESGCMKW.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use AESGCM\AESGCM;
use Assert\Assertion;
use Base64Url\Base64Url;
use Crypto\Cipher;
use Jose\Object\JWKInterface;

/**
Expand Down Expand Up @@ -50,31 +49,9 @@ public function unwrapKey(JWKInterface $key, $encrypted_cek, array $header)
$tag = Base64Url::decode($header['tag']);
$iv = Base64Url::decode($header['iv']);

if (version_compare(PHP_VERSION, '7.1.0') >= 0) {
return openssl_decrypt($encrypted_cek, $this->getMode($kek), $kek, OPENSSL_RAW_DATA, $iv, $tag, null);
} elseif (class_exists('\Crypto\Cipher')) {
$cipher = Cipher::aes(Cipher::MODE_GCM, $this->getKeySize());
$cipher->setTag($tag);
$cipher->setAAD(null);

$cek = $cipher->decrypt($encrypted_cek, $kek, $iv);

return $cek;
}

return AESGCM::decrypt($kek, $iv, $encrypted_cek, null, $tag);
}

/**
* @param string $k
*
* @return string
*/
private function getMode($k)
{
return 'aes-'.(8 * mb_strlen($k, '8bit')).'-gcm';
}

/**
* {@inheritdoc}
*/
Expand Down
4 changes: 0 additions & 4 deletions src/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ private function fromFlattenedSerializationRecipientToSerialization($input)
}
}


return $recipients;
}

Expand All @@ -200,7 +199,6 @@ private function fromFlattenedSerializationSignatureToSerialization($input)
}
$temp['signatures'] = [$signature];


return $temp;
}

Expand Down Expand Up @@ -243,7 +241,6 @@ private function fromCompactSerializationRecipientToSerialization(array $parts)
}
}


return $recipients;
}

Expand All @@ -264,7 +261,6 @@ private function fromCompactSerializationSignatureToSerialization(array $parts)
'signature' => $parts[2],
]];


return $temp;
}
}
1 change: 0 additions & 1 deletion src/Signer.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ private function computeSignature(Object\JWSInterface $jws, Object\SignatureInte
$input
);


$signature = Object\Signature::createSignatureFromLoadedData(
$value,
$signature->getEncodedProtectedHeaders(),
Expand Down
1 change: 0 additions & 1 deletion tests/Unit/Objects/PublicJWKSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public function testWithMultipleKeySets()
$public_jwkset->removeKey(0);
$this->assertEquals(7, $public_jwkset->countKeys());


$this->assertEquals(7, count($public_jwkset->toPEM()));

foreach ($public_jwkset as $key) {
Expand Down

0 comments on commit 749695b

Please sign in to comment.