ksjsb/core/kwsg.py
2026-07-30 20:25:56 +08:00

211 lines
5.8 KiB
Python

"""Compatibility aggregate for recovered KWSG-related algorithms.
Implementations live in focused modules:
- `core.sig`
- `core.tokensig`
- `core.sig3`
- `core.enc_data`
- `core.atlas_sign`
- `core.dfp_sign`
- `core.reward_sign`
- `core.xfalcon`
This module exists so old `from ks_sign import ...` call sites keep working.
Do not add new algorithm implementation here.
"""
from __future__ import annotations
from .captured_profile import API_ST, CLIENT_KEY, CLIENT_SALT, DID, EGID, ODID, RDID
from .atlas_sign import (
ATLAS_SIGN_HMAC_KEY,
atlas_sign,
atlas_sign_from_digest_hex,
atlas_sign_to_digest_hex,
)
from .dfp_sign import (
DFP_PAYLOAD_KEYS,
DFP_SDK_ID,
DFP_SIGN_KEYS,
DfpSignMaterial,
build_dfp_sign_material,
dfp_atlas_sign,
id_mapping_data_only,
legacy_product_ts_sv_payload,
parse_dfp_atlas_sign,
sign_dfp_form,
tree_values_sorted_non_empty_except_sign,
)
from .enc_data import (
KWSG_10400_DEFAULT_CFG9,
KWSG_10400_NONCE_XOR,
KWSG_10400_T1_LEN,
KWSG_10400_T2_LEN,
KWSG_266FC_PERM,
KWSG_STATIC_AES_IV,
KWSG_STATIC_AES_KEY,
ZT_OUTER_CONFIGS,
build_inner_zt_header,
derive_outer_xor_key,
kwsg_10400_ecb_encrypt,
kwsg_10400_nonce9,
kwsg_10400_raw,
kwsg_10400_raw_with_inner_fields,
kwsg_266fc_block,
load_kwsg_10400_tables,
parse_inner_zt_header,
zt_outer_unwrap,
zt_outer_wrap,
)
from .reward_sign import (
KWSG_10418_SIGN_HMAC_KEY,
kwsg_10418_reward_sign,
kwsg_10418_reward_sign_from_digest_hex,
kwsg_10418_reward_sign_to_digest_hex,
)
from .sig import SIG_SALT, body_md5, build_sig_plaintext, sig
from .sig3 import (
KWSG_10418_DEFAULT_STATE_SOURCE,
KWSG_10418_HMAC_KEY,
KWSG_10418_PREFIX8,
KWSG_10418_PREFIX_HEAD2,
KWSG_10418_SAMPLE_SESSION_SEED,
KWSG_10418_SIG3_HMAC_KEY,
KWSG_10418_SIG3_PREFIX8,
KWSG_10418_SIG3_PREFIX_CODE,
KWSG_10418_SIGN_PREFIX8,
KWSG_10418_SIGN_PREFIX_CODE,
Kwsg10418State,
kwsg_10418_binary48,
kwsg_10418_binary48_from_prehash32,
kwsg_10418_digest24,
kwsg_10418_digest24_from_binary48,
kwsg_10418_digest24_unmix,
kwsg_10418_prefix8,
kwsg_10418_prehash32,
kwsg_10418_sig3_hex,
kwsg_10418_state_low24_from_source,
load_kwsg_10418_sign_tables,
load_kwsg_10418_tables,
)
from .tokensig import tokensig
from .xfalcon import (
xfalcon_digest_hex_from_input_bytes,
xfalcon_digest_hex_from_input_hex,
xfalcon_digest_words_from_input_bytes,
xfalcon_digest_words_from_input_hex,
xfalcon_folded_block_from_input_bytes,
xfalcon_folded_block_from_raw_bytes,
xfalcon_message_words_from_folded_block,
xfalcon_message_words_from_input_hex,
xfalcon_packed_block_from_input_hex,
xfalcon_te_hex_from_input_bytes,
xfalcon_te_hex_from_input_hex,
xfalcon_value_from_input_bytes,
xfalcon_value_from_input_hex,
)
__all__ = [
"API_ST",
"ATLAS_SIGN_HMAC_KEY",
"CLIENT_KEY",
"CLIENT_SALT",
"DID",
"DFP_PAYLOAD_KEYS",
"DFP_SDK_ID",
"DFP_SIGN_KEYS",
"DfpSignMaterial",
"EGID",
"KWSG_10400_DEFAULT_CFG9",
"KWSG_10400_NONCE_XOR",
"KWSG_10400_T1_LEN",
"KWSG_10400_T2_LEN",
"KWSG_10418_DEFAULT_STATE_SOURCE",
"KWSG_10418_HMAC_KEY",
"KWSG_10418_PREFIX8",
"KWSG_10418_PREFIX_HEAD2",
"KWSG_10418_SAMPLE_SESSION_SEED",
"KWSG_10418_SIG3_HMAC_KEY",
"KWSG_10418_SIG3_PREFIX8",
"KWSG_10418_SIG3_PREFIX_CODE",
"KWSG_10418_SIGN_HMAC_KEY",
"KWSG_10418_SIGN_PREFIX8",
"KWSG_10418_SIGN_PREFIX_CODE",
"KWSG_266FC_PERM",
"KWSG_STATIC_AES_IV",
"KWSG_STATIC_AES_KEY",
"Kwsg10418State",
"ODID",
"RDID",
"SIG_SALT",
"ZT_OUTER_CONFIGS",
"atlas_sign",
"atlas_sign_from_digest_hex",
"atlas_sign_to_digest_hex",
"body_md5",
"build_inner_zt_header",
"build_dfp_sign_material",
"build_sig_plaintext",
"dfp_atlas_sign",
"derive_outer_xor_key",
"id_mapping_data_only",
"kwsg_10400_ecb_encrypt",
"kwsg_10400_nonce9",
"kwsg_10400_raw",
"kwsg_10400_raw_with_inner_fields",
"kwsg_10418_binary48",
"kwsg_10418_binary48_from_prehash32",
"kwsg_10418_digest24",
"kwsg_10418_digest24_from_binary48",
"kwsg_10418_digest24_unmix",
"kwsg_10418_prefix8",
"kwsg_10418_prehash32",
"kwsg_10418_reward_sign",
"kwsg_10418_reward_sign_from_digest_hex",
"kwsg_10418_reward_sign_to_digest_hex",
"kwsg_10418_sig3_hex",
"kwsg_10418_state_low24_from_source",
"kwsg_266fc_block",
"legacy_product_ts_sv_payload",
"load_kwsg_10400_tables",
"load_kwsg_10418_sign_tables",
"load_kwsg_10418_tables",
"parse_inner_zt_header",
"parse_dfp_atlas_sign",
"sig",
"sign_dfp_form",
"tokensig",
"tree_values_sorted_non_empty_except_sign",
"xfalcon_digest_hex_from_input_bytes",
"xfalcon_digest_hex_from_input_hex",
"xfalcon_digest_words_from_input_bytes",
"xfalcon_digest_words_from_input_hex",
"xfalcon_folded_block_from_input_bytes",
"xfalcon_folded_block_from_raw_bytes",
"xfalcon_message_words_from_folded_block",
"xfalcon_message_words_from_input_hex",
"xfalcon_packed_block_from_input_hex",
"xfalcon_te_hex_from_input_bytes",
"xfalcon_te_hex_from_input_hex",
"xfalcon_value_from_input_bytes",
"xfalcon_value_from_input_hex",
"zt_outer_unwrap",
"zt_outer_wrap",
]
def _self_test() -> None:
assert tokensig("6000aa38bfa87d4bacd329574529f9e2", CLIENT_SALT) == (
"13a8a7fc2860f9d6da3d878c22b54c010edbefc9aae4aa138ab9293aa342e41b"
)
assert xfalcon_digest_hex_from_input_hex(
"c29904a53f6a7138ab1d2d4584d24b32a9b8cdeb8ab04ece59e0e2e3f56979b286b5b591fcf0fee8"
) == "a8651e4eff5a688f80b628fd2d9a255ad7655c772cdc835728dccaf5ee5ef8ab"
print("[OK] core.kwsg compatibility exports verified")
if __name__ == "__main__":
_self_test()