Exploit databaseDownload repository ZIP
GH-d040af49f7627d91b0e314e6400f7010
creeeeger/cve-2024-56426
Sources for CVE-2024-56426
2 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars.
Repository files19
creeeeger/cve-2024-56426Revision 3d6d94a21066
- ↑..Parent directory
- NOTICE.md
- apply_lk_patches.py
- build_tampered_loader.py
- common.py
- el3_mon_crypto.py
- epbl_crypto.py
- extract_ldfw.py
- gen_key.py
- key_bundle.py
- model_data.py
- patch_epbl_header.py
- recrypt-el3_mon.py
- recrypt-epbl.py
- sign_sboot_images.py
- sign_tool.py
- signature_crypto.py
- stage2_common.py
- stage2_sign_tool.py
- stage2_verify_tool.py
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
external/tools/signature_crypto.py
Python · 3,730 bytes# SPDX-License-Identifier: GPL-2.0-only
# SPDX-FileCopyrightText: 2026 Umer Uddin <[email protected]>
# SPDX-FileCopyrightText: 2026 Creeeeger <[email protected]>
"""ECDSA key and signature encoding helpers for Exynos boot images."""
from __future__ import annotations
from pathlib import Path
try:
from .common import (
ECDSA_COORD_SIZE,
ECDSA_FIELD_SIZE,
PUBKEY_BLOB_SIZE,
SIGNATURE_BLOB_SIZE,
)
except ImportError:
from common import (
ECDSA_COORD_SIZE,
ECDSA_FIELD_SIZE,
PUBKEY_BLOB_SIZE,
SIGNATURE_BLOB_SIZE,
)
from cryptography.exceptions import InvalidSignature
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import ec, utils
from cryptography.hazmat.primitives.asymmetric.utils import (
decode_dss_signature,
encode_dss_signature,
)
def generate_padded_pub_key(public_key) -> bytes:
numbers = public_key.public_numbers()
x = numbers.x.to_bytes(ECDSA_COORD_SIZE, byteorder="big")
y = numbers.y.to_bytes(ECDSA_COORD_SIZE, byteorder="big")
blob = x.rjust(ECDSA_FIELD_SIZE, b"\x00") + y.rjust(ECDSA_FIELD_SIZE, b"\x00")
return blob.ljust(PUBKEY_BLOB_SIZE, b"\x00")
def generate_padded_signature(r: int, s: int) -> bytes:
r_bytes = r.to_bytes(ECDSA_COORD_SIZE, byteorder="big").rjust(ECDSA_FIELD_SIZE, b"\x00")
s_bytes = s.to_bytes(ECDSA_COORD_SIZE, byteorder="big").rjust(ECDSA_FIELD_SIZE, b"\x00")
return (r_bytes + s_bytes).ljust(SIGNATURE_BLOB_SIZE, b"\x00")
def load_private_key(path: str | Path):
return serialization.load_pem_private_key(Path(path).read_bytes(), password=None)
def load_pubkey_blob(path: str | Path) -> bytes:
blob = Path(path).read_bytes()
if len(blob) != PUBKEY_BLOB_SIZE:
raise ValueError(
f"Public key blob must be {PUBKEY_BLOB_SIZE} bytes, got {len(blob)}"
)
return blob
def public_key_from_blob(pubkey_blob: bytes):
if len(pubkey_blob) < ECDSA_FIELD_SIZE * 2:
raise ValueError("Public key blob is too short")
x = int.from_bytes(
pubkey_blob[ECDSA_FIELD_SIZE - ECDSA_COORD_SIZE:ECDSA_FIELD_SIZE], "big"
)
y_start = ECDSA_FIELD_SIZE
y = int.from_bytes(
pubkey_blob[
y_start + ECDSA_FIELD_SIZE - ECDSA_COORD_SIZE:y_start + ECDSA_FIELD_SIZE
],
"big",
)
return ec.EllipticCurvePublicNumbers(x, y, ec.SECP384R1()).public_key()
def padded_signature_to_der(signature_blob: bytes) -> bytes:
if len(signature_blob) != SIGNATURE_BLOB_SIZE:
raise ValueError(
f"Signature blob must be {SIGNATURE_BLOB_SIZE} bytes, got {len(signature_blob)}"
)
r = int.from_bytes(
signature_blob[ECDSA_FIELD_SIZE - ECDSA_COORD_SIZE:ECDSA_FIELD_SIZE], "big"
)
s_start = ECDSA_FIELD_SIZE
s = int.from_bytes(
signature_blob[
s_start + ECDSA_FIELD_SIZE - ECDSA_COORD_SIZE:s_start + ECDSA_FIELD_SIZE
],
"big",
)
return encode_dss_signature(r, s)
def sign_digest(private_key, digest: bytes) -> bytes:
signature = private_key.sign(digest, ec.ECDSA(utils.Prehashed(hashes.SHA512())))
r, s = decode_dss_signature(signature)
return generate_padded_signature(r, s)
def verify_digest(
public_key_blob: bytes,
signature_blob: bytes,
digest: bytes,
) -> bool:
public_key = public_key_from_blob(public_key_blob)
signature = padded_signature_to_der(signature_blob)
try:
public_key.verify(signature, digest, ec.ECDSA(utils.Prehashed(hashes.SHA512())))
return True
except InvalidSignature:
return False