Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Nguyen Van Nguyen <[email protected]>
  • Loading branch information
nguyennv committed Sep 25, 2024
1 parent fa8ee0a commit 9250990
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
10 changes: 5 additions & 5 deletions examples/cleartext-signing.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
=aLGb
-----END PGP PRIVATE KEY BLOCK-----
EOT;
$curve4489PrivateKey = OpenPGP::decryptPrivateKey(
$curve448PrivateKey = OpenPGP::decryptPrivateKey(
$keyData,
$passphase,
);
Expand All @@ -203,7 +203,7 @@
$rsaPrivateKey,
$eccPrivateKey,
$curve25519PrivateKey,
$curve4489PrivateKey,
$curve448PrivateKey,
],
);
echo $armored = $signedMessage->armor() . PHP_EOL;
Expand All @@ -213,7 +213,7 @@
$rsaPrivateKey->toPublic(),
$eccPrivateKey->toPublic(),
$curve25519PrivateKey->toPublic(),
$curve4489PrivateKey->toPublic(),
$curve448PrivateKey->toPublic(),
]);
foreach ($verifications as $verification) {
echo "Key ID: {$verification->getKeyID(true)}" . PHP_EOL;
Expand All @@ -228,7 +228,7 @@
$rsaPrivateKey,
$eccPrivateKey,
$curve25519PrivateKey,
$curve4489PrivateKey,
$curve448PrivateKey,
],
);
echo $armored = $signature->armor() . PHP_EOL;
Expand All @@ -241,7 +241,7 @@
$rsaPrivateKey->toPublic(),
$eccPrivateKey->toPublic(),
$curve25519PrivateKey->toPublic(),
$curve4489PrivateKey->toPublic(),
$curve448PrivateKey->toPublic(),
],
);
foreach ($verifications as $verification) {
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public static function generatePassword(int $length = 32): string
{
return preg_replace_callback(
'/\*/u',
static fn () => chr(random_int(33, 126)),
static fn () => chr(random_int(40, 126)),
str_repeat('*', $length),
);
}
Expand Down
9 changes: 5 additions & 4 deletions src/Packet/Key/MontgomerySessionKeyCryptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public static function encryptSessionKey(
MontgomeryCurve $curve = MontgomeryCurve::Curve25519,
): self
{
if ($sessionKey->getSymmetric() !== $curve->symmetricAlgorithm()) {
$pkeskV6 = $pkeskVersion === self::PKESK_VERSION_6;
if ($pkeskV6 && $sessionKey->getSymmetric() !== $curve->symmetricAlgorithm()) {
throw new \InvalidArgumentException(
'Symmetric algorithm of the session key mismatch!'
);
Expand Down Expand Up @@ -120,9 +121,9 @@ public static function encryptSessionKey(
$ephemeralKey,
$keyWrapper->wrap(
$kek,
$pkeskVersion === self::PKESK_VERSION_3 ?
$sessionKey->toBytes() :
$sessionKey->getEncryptionKey(),
$pkeskV6 ?
$sessionKey->getEncryptionKey() :
$sessionKey->toBytes(),
),
$pkeskVersion,
$curve,
Expand Down
1 change: 1 addition & 0 deletions src/Type/SessionKeyCryptorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
interface SessionKeyCryptorInterface
{
const PKESK_VERSION_3 = 3;
const PKESK_VERSION_6 = 6;

/**
* Decrypt session key by using secret key packet
Expand Down

0 comments on commit 9250990

Please sign in to comment.