Skip to content

Commit

Permalink
small cleanup in cscrypt
Browse files Browse the repository at this point in the history
+ adding libs

thnx to Nautilus7


git-svn-id: http://www.streamboard.tv/svn/oscam/trunk@11467 4b0bc96b-bc66-0410-9d44-ebda105a78c1
  • Loading branch information
gorgone.impertinence committed Jan 15, 2019
1 parent ea45b69 commit 0bba18b
Show file tree
Hide file tree
Showing 18 changed files with 2,703 additions and 12 deletions.
67 changes: 67 additions & 0 deletions cscrypt/aes.c
Expand Up @@ -1250,4 +1250,71 @@ void AES_decrypt(const unsigned char *in, unsigned char *out,
rk[3];
PUTU32(out + 12, s3);
}

void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
const unsigned long length, const AES_KEY *key,
unsigned char *ivec, const int enc)
{
unsigned long n;
unsigned long len = length;
unsigned char tmp[AES_BLOCK_SIZE];

assert(in && out && key && ivec);
assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc));

if(AES_ENCRYPT == enc)
{
while(len >= AES_BLOCK_SIZE)
{
for(n=0; n < AES_BLOCK_SIZE; ++n)
tmp[n] = in[n] ^ ivec[n];

AES_encrypt(tmp, out, key);
memcpy(ivec, out, AES_BLOCK_SIZE);
len -= AES_BLOCK_SIZE;
in += AES_BLOCK_SIZE;
out += AES_BLOCK_SIZE;
}

if(len)
{
for(n=0; n < len; ++n)
tmp[n] = in[n] ^ ivec[n];

for(n=len; n < AES_BLOCK_SIZE; ++n)
tmp[n] = ivec[n];

AES_encrypt(tmp, tmp, key);
memcpy(out, tmp, AES_BLOCK_SIZE);
memcpy(ivec, tmp, AES_BLOCK_SIZE);
}
}
else
{
while(len >= AES_BLOCK_SIZE)
{
memcpy(tmp, in, AES_BLOCK_SIZE);
AES_decrypt(in, out, key);

for(n=0; n < AES_BLOCK_SIZE; ++n)
out[n] ^= ivec[n];

memcpy(ivec, tmp, AES_BLOCK_SIZE);
len -= AES_BLOCK_SIZE;
in += AES_BLOCK_SIZE;
out += AES_BLOCK_SIZE;
}

if(len)
{
memcpy(tmp, in, AES_BLOCK_SIZE);
AES_decrypt(tmp, tmp, key);

for(n=0; n < len; ++n)
out[n] ^= ivec[n];

memcpy(ivec, tmp, AES_BLOCK_SIZE);
}
}
}
#endif
3 changes: 3 additions & 0 deletions cscrypt/aes.h
Expand Up @@ -42,6 +42,9 @@ void AES_encrypt(const unsigned char *in, unsigned char *out,
void AES_decrypt(const unsigned char *in, unsigned char *out,
const AES_KEY *key);

void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
const unsigned long length, const AES_KEY *key,
unsigned char *ivec, const int enc);
#endif /* !HEADER_AES_H */

#endif
12 changes: 12 additions & 0 deletions cscrypt/des.c
Expand Up @@ -919,3 +919,15 @@ void des_ecb3_encrypt(uint8_t* data, const uint8_t* key)
des(data, schedule2, 0);
des(data, schedule1, 1);
}

void _3DES(uint8_t *data, uint8_t *key)
{
uint32_t ks1[32], ks2[32];

des_set_key(key, ks1);
des_set_key(key+8, ks2);

des(data, ks1, 0);
des(data, ks2, 1);
des(data, ks1, 0);
}
2 changes: 2 additions & 0 deletions cscrypt/des.h
Expand Up @@ -37,4 +37,6 @@
void des_ecb3_encrypt(uint8_t* data, const uint8_t* key);
void des_ecb3_decrypt(uint8_t* data, const uint8_t* key);

void _3DES(uint8_t *data, uint8_t *key);

#endif
13 changes: 3 additions & 10 deletions cscrypt/md5.c
Expand Up @@ -25,13 +25,6 @@

#if !defined(WITH_SSL) && !defined(WITH_LIBCRYPTO)

typedef struct MD5Context
{
uint32_t buf[4];
uint32_t bits[2];
uint32_t in[16];
} MD5_CTX;

#ifdef __i386__
#define byteReverse(a, b)
#else
Expand Down Expand Up @@ -155,7 +148,7 @@ static void MD5_Transform(uint32_t buf[4], uint32_t in[16])
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
* initialization constants.
*/
static void MD5_Init(MD5_CTX *ctx)
void MD5_Init(MD5_CTX *ctx)
{
ctx->buf[0] = 0x67452301;
ctx->buf[1] = 0xefcdab89;
Expand All @@ -170,7 +163,7 @@ static void MD5_Init(MD5_CTX *ctx)
* Update context to reflect the concatenation of another buffer full
* of bytes.
*/
static void MD5_Update(MD5_CTX *ctx, const unsigned char *buf, unsigned int len)
void MD5_Update(MD5_CTX *ctx, const unsigned char *buf, unsigned int len)
{
uint32_t t;

Expand Down Expand Up @@ -219,7 +212,7 @@ static void MD5_Update(MD5_CTX *ctx, const unsigned char *buf, unsigned int len)
* Final wrapup - pad to 64-byte boundary with the bit pattern
* 1 0* (64-bit count of bits processed, MSB-first)
*/
static void MD5_Final(unsigned char digest[MD5_DIGEST_LENGTH], MD5_CTX *ctx)
void MD5_Final(unsigned char digest[MD5_DIGEST_LENGTH], MD5_CTX *ctx)
{
unsigned count;
unsigned char *p;
Expand Down
12 changes: 10 additions & 2 deletions cscrypt/md5.h
Expand Up @@ -7,8 +7,16 @@
#define MD5_DIGEST_LENGTH 16

unsigned char *MD5(const unsigned char *input, unsigned long len, unsigned char *output_hash);
#endif

char *__md5_crypt(const char *text_pass, const char *salt, char *crypted_passwd);
typedef struct MD5Context {
uint32_t buf[4];
uint32_t bits[2];
uint32_t in[16];
} MD5_CTX;

void MD5_Init(MD5_CTX *ctx);
void MD5_Update(MD5_CTX *ctx, const unsigned char *buf, unsigned int len);
void MD5_Final(unsigned char digest[MD5_DIGEST_LENGTH], MD5_CTX *ctx);
#endif
char *__md5_crypt(const char *text_pass, const char *salt, char *crypted_passwd);
#endif
8 changes: 8 additions & 0 deletions ffdecsa/CMakeLists.txt
@@ -0,0 +1,8 @@
project (ffdecsa)

file (GLOB ffdecsa_srcs "ffdecsa.c")
file (GLOB ffdecsa_hdrs "*.h")

set (lib_name "ffdecsa")

add_library (${lib_name} STATIC ${ffdecsa_srcs} ${ffdecsa_hdrs})

0 comments on commit 0bba18b

Please sign in to comment.