From 3d66114e15442b13f71c03374ef573bf8e37f0b0 Mon Sep 17 00:00:00 2001 From: bust3d Date: Fri, 22 Mar 2024 15:51:28 +0000 Subject: [PATCH] - reduced binary size with AES constants, there was twice included (thanks to lpm11) -> https://trac.streamboard.tv/oscam/ticket/4919 - fix dynamic linking compile errors on the system that install libdvbcsa at an unusual path (thanks to ohmza) - add supports to cwpk1 through cwpk7 (thanks to ohmza and feri33) git-svn-id: https://svn.streamboard.tv/oscam/trunk@11751 4b0bc96b-bc66-0410-9d44-ebda105a78c1 --- Makefile | 2 +- cscrypt/aes.c | 22 +++++++-------- cscrypt/fast_aes.c | 14 +++++++++ reader-nagracak7.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 104 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index c64a4b93..35d4ad71 100644 --- a/Makefile +++ b/Makefile @@ -52,7 +52,7 @@ endif ifeq "$(shell ./config.sh --enabled MODULE_STREAMRELAY)" "Y" override USE_LIBDVBCSA=1 - override CFLAGS += -DLIBDVBCSA_LIB=\"$(notdir ${LIBDVBCSA_LIB})\" + override CFLAGS += -DLIBDVBCSA_LIB=\"$(notdir $(subst $(empty) ,/,${LIBDVBCSA_LIB}))\" endif override STD_LIBS := -lm $(LIB_PTHREAD) $(LIB_DL) $(LIB_RT) diff --git a/cscrypt/aes.c b/cscrypt/aes.c index 3f07a667..9d7e24fe 100644 --- a/cscrypt/aes.c +++ b/cscrypt/aes.c @@ -7,7 +7,7 @@ #include #include "aes.h" -static const uint32_t Te0[256] = +const uint32_t Te0[256] = { 0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU, 0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U, @@ -74,7 +74,7 @@ static const uint32_t Te0[256] = 0x824141c3U, 0x299999b0U, 0x5a2d2d77U, 0x1e0f0f11U, 0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU, }; -static const uint32_t Te1[256] = +const uint32_t Te1[256] = { 0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU, 0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U, @@ -141,7 +141,7 @@ static const uint32_t Te1[256] = 0xc3824141U, 0xb0299999U, 0x775a2d2dU, 0x111e0f0fU, 0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U, }; -static const uint32_t Te2[256] = +const uint32_t Te2[256] = { 0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU, 0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U, @@ -208,7 +208,7 @@ static const uint32_t Te2[256] = 0x41c38241U, 0x99b02999U, 0x2d775a2dU, 0x0f111e0fU, 0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U, }; -static const uint32_t Te3[256] = +const uint32_t Te3[256] = { 0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U, 0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U, @@ -275,7 +275,7 @@ static const uint32_t Te3[256] = 0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU, 0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU, }; -static const uint32_t Te4[256] = +const uint32_t Te4[256] = { 0x63636363U, 0x7c7c7c7cU, 0x77777777U, 0x7b7b7b7bU, 0xf2f2f2f2U, 0x6b6b6b6bU, 0x6f6f6f6fU, 0xc5c5c5c5U, @@ -342,7 +342,7 @@ static const uint32_t Te4[256] = 0x41414141U, 0x99999999U, 0x2d2d2d2dU, 0x0f0f0f0fU, 0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U, }; -static const uint32_t Td0[256] = +const uint32_t Td0[256] = { 0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U, 0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U, @@ -409,7 +409,7 @@ static const uint32_t Td0[256] = 0x39a80171U, 0x080cb3deU, 0xd8b4e49cU, 0x6456c190U, 0x7bcb8461U, 0xd532b670U, 0x486c5c74U, 0xd0b85742U, }; -static const uint32_t Td1[256] = +const uint32_t Td1[256] = { 0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU, 0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U, @@ -476,7 +476,7 @@ static const uint32_t Td1[256] = 0x7139a801U, 0xde080cb3U, 0x9cd8b4e4U, 0x906456c1U, 0x617bcb84U, 0x70d532b6U, 0x74486c5cU, 0x42d0b857U, }; -static const uint32_t Td2[256] = +const uint32_t Td2[256] = { 0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U, 0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U, @@ -543,7 +543,7 @@ static const uint32_t Td2[256] = 0x017139a8U, 0xb3de080cU, 0xe49cd8b4U, 0xc1906456U, 0x84617bcbU, 0xb670d532U, 0x5c74486cU, 0x5742d0b8U, }; -static const uint32_t Td3[256] = +const uint32_t Td3[256] = { 0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU, 0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU, @@ -610,7 +610,7 @@ static const uint32_t Td3[256] = 0xa8017139U, 0x0cb3de08U, 0xb4e49cd8U, 0x56c19064U, 0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U, }; -static const uint32_t Td4[256] = +const uint32_t Td4[256] = { 0x52525252U, 0x09090909U, 0x6a6a6a6aU, 0xd5d5d5d5U, 0x30303030U, 0x36363636U, 0xa5a5a5a5U, 0x38383838U, @@ -677,7 +677,7 @@ static const uint32_t Td4[256] = 0xe1e1e1e1U, 0x69696969U, 0x14141414U, 0x63636363U, 0x55555555U, 0x21212121U, 0x0c0c0c0cU, 0x7d7d7d7dU, }; -static const uint32_t rcon[] = +const uint32_t rcon[] = { 0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000, 0x20000000, 0x40000000, 0x80000000, diff --git a/cscrypt/fast_aes.c b/cscrypt/fast_aes.c index 6987a813..e0e135db 100644 --- a/cscrypt/fast_aes.c +++ b/cscrypt/fast_aes.c @@ -1,6 +1,19 @@ #include "stdio.h" #include "fast_aes.h" +#ifndef WITH_LIBCRYPTO +extern const unsigned int Te0[256]; +extern const unsigned int Te1[256]; +extern const unsigned int Te2[256]; +extern const unsigned int Te3[256]; +extern const unsigned int Te4[256]; +extern const unsigned int Td0[256]; +extern const unsigned int Td1[256]; +extern const unsigned int Td2[256]; +extern const unsigned int Td3[256]; +extern const unsigned int Td4[256]; +extern const unsigned int rcon[]; +#else static const unsigned int Te0[256] = { 0xc66363a5UL, 0xf87c7c84UL, 0xee777799UL, 0xf67b7b8dUL, @@ -677,6 +690,7 @@ static const unsigned int rcon[] = 0x10000000UL, 0x20000000UL, 0x40000000UL, 0x80000000UL, 0x1B000000UL, 0x36000000UL, }; +#endif #define GETU32(pt) (((unsigned int)(pt)[0] << 24) ^ \ ((unsigned int)(pt)[1] << 16) ^ \ diff --git a/reader-nagracak7.c b/reader-nagracak7.c index e0368051..0a724238 100644 --- a/reader-nagracak7.c +++ b/reader-nagracak7.c @@ -1582,13 +1582,86 @@ static int32_t nagra3_do_ecm(struct s_reader *reader, const ECM_REQUEST *er, str } if(cta_res[27] == 0x5C) { - if(!reader->cwekey0_length) + if(cta_res[144] == 0x00) { - rdr_log(reader, "ERROR: CWPK is not set, can not decrypt CW"); - return ERROR; + if(!reader->cwekey0_length) + { + rdr_log(reader, "ERROR: CWPK0 is not set, can not decrypt CW"); + return ERROR; + } + des_ecb3_decrypt(_cwe0, reader->cwekey0); + des_ecb3_decrypt(_cwe1, reader->cwekey0); + } + else if(cta_res[144] == 0x01) + { + if(!reader->cwekey1_length) + { + rdr_log(reader, "ERROR: CWPK1 is not set, can not decrypt CW"); + return ERROR; + } + des_ecb3_decrypt(_cwe0, reader->cwekey1); + des_ecb3_decrypt(_cwe1, reader->cwekey1); + } + else if(cta_res[144] == 0x02) + { + if(!reader->cwekey2_length) + { + rdr_log(reader, "ERROR: CWPK2 is not set, can not decrypt CW"); + return ERROR; + } + des_ecb3_decrypt(_cwe0, reader->cwekey2); + des_ecb3_decrypt(_cwe1, reader->cwekey2); + } + else if(cta_res[144] == 0x03) + { + if(!reader->cwekey3_length) + { + rdr_log(reader, "ERROR: CWPK3 is not set, can not decrypt CW"); + return ERROR; + } + des_ecb3_decrypt(_cwe0, reader->cwekey3); + des_ecb3_decrypt(_cwe1, reader->cwekey3); + } + else if(cta_res[144] == 0x04) + { + if(!reader->cwekey4_length) + { + rdr_log(reader, "ERROR: CWPK4 is not set, can not decrypt CW"); + return ERROR; + } + des_ecb3_decrypt(_cwe0, reader->cwekey4); + des_ecb3_decrypt(_cwe1, reader->cwekey4); + } + else if(cta_res[144] == 0x05) + { + if(!reader->cwekey5_length) + { + rdr_log(reader, "ERROR: CWPK5 is not set, can not decrypt CW"); + return ERROR; + } + des_ecb3_decrypt(_cwe0, reader->cwekey5); + des_ecb3_decrypt(_cwe1, reader->cwekey5); + } + else if(cta_res[144] == 0x06) + { + if(!reader->cwekey6_length) + { + rdr_log(reader, "ERROR: CWPK6 is not set, can not decrypt CW"); + return ERROR; + } + des_ecb3_decrypt(_cwe0, reader->cwekey6); + des_ecb3_decrypt(_cwe1, reader->cwekey6); + } + else if(cta_res[144] == 0x07) + { + if(!reader->cwekey7_length) + { + rdr_log(reader, "ERROR: CWP7 is not set, can not decrypt CW"); + return ERROR; + } + des_ecb3_decrypt(_cwe0, reader->cwekey7); + des_ecb3_decrypt(_cwe1, reader->cwekey7); } - des_ecb3_decrypt(_cwe0, reader->cwekey0); - des_ecb3_decrypt(_cwe1, reader->cwekey0); } else if(cta_res[27] == 0x58) { -- 2.11.4.GIT