Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f33fdaa
Implement LRP mode for SDM protocol
claude Nov 23, 2025
bc40620
Fix LRP test vectors and improve SDM LRP integration
claude Nov 23, 2025
c6656e4
Fix LRP mode SDM integration
claude Nov 23, 2025
1714322
Merge remote-tracking branch 'origin/main' into claude/implement-sdm-…
claude Nov 23, 2025
d5642b9
Enable LRP mode in example web application
claude Nov 23, 2025
5246599
Add LRPCipher to SDMCoverageTest coverage annotations
claude Nov 23, 2025
ba4688a
Fix encryption mode display to show name instead of integer
claude Nov 23, 2025
e15b1e1
ignore /example-app/.vite
kduma Nov 23, 2025
9295bf7
Fix counter overflow handling with byte-by-byte increment
claude Nov 23, 2025
c0b4cd6
Improve encryptECB documentation
claude Nov 23, 2025
1f99af8
Document MAC byte extraction security implications
claude Nov 23, 2025
038e17b
Fix padding removal timing attack vulnerability
claude Nov 23, 2025
54d6920
Optimize XOR implementation with native bitwise operator
claude Nov 23, 2025
a3a815c
Document LRP magic values as named constants
claude Nov 23, 2025
a5ffe17
Document ignored IV and key parameters in encrypt/decrypt
claude Nov 23, 2025
67f81b6
Document platform safety of counter operations
claude Nov 23, 2025
30a40db
Improve constant-time behavior of padding removal
claude Nov 23, 2025
4ff2c43
Fix PHPUnit deprecations and code style issues
claude Nov 23, 2025
f20c1ee
Merge branch 'claude/implement-sdm-lrp-mode-01TK3XNGFeN7tSPT7D4KhN9d'…
kduma Nov 23, 2025
da400bd
Improve code coverage for LRPCipher and other classes
claude Nov 23, 2025
6024687
Remove unused files
kduma Nov 23, 2025
21a4568
Ignore few parts for code coverage
kduma Nov 23, 2025
82c8999
Merge branch 'claude/implement-sdm-lrp-mode-01TK3XNGFeN7tSPT7D4KhN9d'…
kduma Nov 23, 2025
3f15654
Ignore few parts for code coverage
kduma Nov 23, 2025
7c767d7
Add counter length validation and support variable-length counters
claude Nov 23, 2025
729ecd3
Document test data format for LRP file_data assertions
claude Nov 23, 2025
f595e31
Add counter length validation without padding
claude Nov 23, 2025
2077d34
Document variable-length counter support in LRP implementation
claude Nov 23, 2025
57bc05c
Document ignored key parameter in cmac() method
claude Nov 23, 2025
0472472
Fix code style issues - add trailing commas
claude Nov 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ coverage/
*~
*.bak
.DS_Store
/example-app/.vite
18 changes: 4 additions & 14 deletions example-app/app/Http/Controllers/SDMController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function tagPlainText(Request $request)
);

return view('info', [
'encryptionMode' => $result['encryption_mode']->value,
'encryptionMode' => $result['encryption_mode']->name,
'uid' => $result['uid'],
'readCtr' => $result['read_ctr'],
'fileData' => null,
Expand Down Expand Up @@ -79,7 +79,7 @@ public function apiTagPlainText(Request $request): JsonResponse
);

return $this->jsonResponse([
'encryption_mode' => $result['encryption_mode']->value,
'encryption_mode' => $result['encryption_mode']->name,
'uid' => bin2hex($result['uid']),
'read_ctr' => $result['read_ctr'],
]);
Expand Down Expand Up @@ -135,11 +135,6 @@ private function processEncryptedTag(Request $request, bool $isTamperTag)
return $this->errorResponse('LRP mode is required', 400);
}

// Check if LRP mode is requested but not supported
if ($params['mode'] === 'LRP') {
return $this->errorResponse('LRP mode is not yet supported in the php-sdm library', 501);
}

$sdm = $this->getSDM();

$result = $sdm->decryptSunMessage(
Expand All @@ -153,7 +148,7 @@ private function processEncryptedTag(Request $request, bool $isTamperTag)

$viewData = [
'piccDataTag' => $result['picc_data_tag'],
'encryptionMode' => $result['encryption_mode']->value,
'encryptionMode' => $result['encryption_mode']->name,
'uid' => $result['uid'],
'readCtr' => $result['read_ctr'],
'fileData' => $result['file_data'],
Expand Down Expand Up @@ -194,11 +189,6 @@ private function processEncryptedTagApi(Request $request, bool $isTamperTag): Js
return $this->jsonErrorResponse('LRP mode is required', 400);
}

// Check if LRP mode is requested but not supported
if ($params['mode'] === 'LRP') {
return $this->jsonErrorResponse('LRP mode is not yet supported in the php-sdm library', 501);
}

$sdm = $this->getSDM();

$result = $sdm->decryptSunMessage(
Expand All @@ -212,7 +202,7 @@ private function processEncryptedTagApi(Request $request, bool $isTamperTag): Js

$responseData = [
'picc_data_tag' => bin2hex($result['picc_data_tag']),
'encryption_mode' => $result['encryption_mode']->value,
'encryption_mode' => $result['encryption_mode']->name,
'uid' => bin2hex($result['uid']),
'read_ctr' => $result['read_ctr'],
];
Expand Down
3 changes: 2 additions & 1 deletion example-app/config/sdm.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
|--------------------------------------------------------------------------
|
| When enabled, this will enforce LRP encryption mode and reject AES requests.
| Note: LRP mode is not yet implemented in the php-sdm library.
| LRP (Leakage Resilient Primitive) provides enhanced security against
| side-channel attacks compared to standard AES encryption.
|
*/

Expand Down
5 changes: 0 additions & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,3 @@ parameters:
message: '#expects string\|null, string\|false given#'
paths:
- tests/Unit/
# Unreachable statements after markTestSkipped() in LRP tests
# These tests are intentionally skipped but kept for documentation and future LRP support
-
message: '#Unreachable statement - code above always terminates#'
path: tests/Unit/SDMProtocolTest.php
6 changes: 6 additions & 0 deletions src/Cipher/AESCipher.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ public function cmac(string $data, string $key): string
$encrypted = openssl_encrypt($x, 'AES-128-ECB', $key, OPENSSL_RAW_DATA | OPENSSL_NO_PADDING);

if (false === $encrypted) {
// @codeCoverageIgnoreStart
throw new \RuntimeException('Failed to encrypt data during CMAC calculation');
// @codeCoverageIgnoreEnd
}

$x = $encrypted;
Expand All @@ -150,7 +152,9 @@ public function cmac(string $data, string $key): string
$mac = openssl_encrypt($x, 'AES-128-ECB', $key, OPENSSL_RAW_DATA | OPENSSL_NO_PADDING);

if (false === $mac) {
// @codeCoverageIgnoreStart
throw new \RuntimeException('Failed to generate CMAC');
// @codeCoverageIgnoreEnd
}

return $mac;
Expand All @@ -168,7 +172,9 @@ private function generateSubkeys(string $key, int $blockSize): array
$l = openssl_encrypt($zero, 'AES-128-ECB', $key, OPENSSL_RAW_DATA | OPENSSL_NO_PADDING);

if (false === $l) {
// @codeCoverageIgnoreStart
throw new \RuntimeException('Failed to encrypt data for CMAC subkey generation');
// @codeCoverageIgnoreEnd
}

// K1 = L << 1
Expand Down
Loading