mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-libstb-hal.git
synced 2025-08-26 15:02:43 +02:00
test c**
Origin commit data
------------------
Branch: master
Commit: 890f4e2ea3
Author: max_10 <max_10@gmx.de>
Date: 2015-11-10 (Tue, 10 Nov 2015)
------------------
No further description and justification available within origin commit message!
------------------
This commit was generated by Migit
This commit is contained in:
39
libdvbci/_dh_params.h
Normal file
39
libdvbci/_dh_params.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/* DH */
|
||||
|
||||
unsigned char dh_p[256] = { /* prime */
|
||||
0xd6, 0x27, 0x14, 0x7a, 0x7c, 0x0c, 0x26, 0x63, 0x9d, 0x82, 0xeb, 0x1f, 0x4a, 0x18, 0xff, 0x6c,
|
||||
0x34, 0xad, 0xea, 0xa6, 0xc0, 0x23, 0xe6, 0x65, 0xfc, 0x8e, 0x32, 0xc3, 0x33, 0xf4, 0x91, 0xa7,
|
||||
0xcc, 0x88, 0x58, 0xd7, 0xf3, 0xb3, 0x17, 0x5e, 0xb0, 0xa8, 0xeb, 0x5c, 0xd4, 0xd8, 0x3a, 0xae,
|
||||
0x8e, 0x75, 0xa1, 0x50, 0x5f, 0x5d, 0x67, 0xc5, 0x40, 0xf4, 0xb3, 0x68, 0x35, 0xd1, 0x3a, 0x4c,
|
||||
0x93, 0x7f, 0xca, 0xce, 0xdd, 0x83, 0x29, 0x01, 0xc8, 0x4b, 0x76, 0x81, 0x56, 0x34, 0x83, 0x31,
|
||||
0x92, 0x72, 0x65, 0x7b, 0xac, 0xd9, 0xda, 0xa9, 0xd1, 0xd3, 0xe5, 0x77, 0x58, 0x6f, 0x5b, 0x44,
|
||||
0x3e, 0xaf, 0x7f, 0x6d, 0xf5, 0xcf, 0x0a, 0x80, 0x0d, 0xa5, 0x56, 0x4f, 0x4b, 0x85, 0x41, 0x0f,
|
||||
0x13, 0x41, 0x06, 0x1f, 0xf3, 0xd9, 0x65, 0x36, 0xae, 0x47, 0x41, 0x1f, 0x1f, 0xe0, 0xde, 0x69,
|
||||
0xe5, 0x86, 0x2a, 0xa1, 0xf2, 0x48, 0x02, 0x92, 0x68, 0xa6, 0x37, 0x9f, 0x76, 0x4f, 0x7d, 0x94,
|
||||
0x5d, 0x10, 0xe5, 0xab, 0x5d, 0xb2, 0xf3, 0x12, 0x8c, 0x79, 0x03, 0x92, 0xa6, 0x7f, 0x8a, 0x78,
|
||||
0xb0, 0xba, 0xc5, 0xb5, 0x31, 0xc5, 0xc8, 0x22, 0x6e, 0x29, 0x02, 0x40, 0xab, 0xe7, 0x5c, 0x23,
|
||||
0x33, 0x7f, 0xcb, 0x86, 0xc7, 0xb4, 0xfd, 0xaa, 0x44, 0xcd, 0x9c, 0x9f, 0xba, 0xac, 0x3a, 0xcf,
|
||||
0x7e, 0x31, 0x5f, 0xa8, 0x47, 0xce, 0xca, 0x1c, 0xb4, 0x77, 0xa0, 0xec, 0x9a, 0x46, 0xd4, 0x79,
|
||||
0x7b, 0x64, 0xbb, 0x6c, 0x91, 0xb2, 0x38, 0x01, 0x65, 0x11, 0x45, 0x9f, 0x62, 0x08, 0x6f, 0x31,
|
||||
0xcf, 0xc4, 0xba, 0xdc, 0xd0, 0x03, 0x91, 0xf1, 0x18, 0x1f, 0xcb, 0x4d, 0xfc, 0x73, 0x5a, 0xa2,
|
||||
0x15, 0xb8, 0x3c, 0x8d, 0x80, 0x92, 0x1c, 0xa1, 0x03, 0xd0, 0x83, 0x2f, 0x5f, 0xe3, 0x07, 0x69
|
||||
};
|
||||
|
||||
unsigned char dh_g[256] = { /* generator */
|
||||
0x95, 0x7d, 0xd1, 0x49, 0x68, 0xc1, 0xa5, 0xf1, 0x48, 0xe6, 0x50, 0x4f, 0xa1, 0x10, 0x72, 0xc4,
|
||||
0xef, 0x12, 0xec, 0x2d, 0x94, 0xbe, 0xc7, 0x20, 0x2c, 0x94, 0xf9, 0x68, 0x67, 0x0e, 0x22, 0x17,
|
||||
0xb5, 0x5c, 0x0b, 0xca, 0xac, 0x9f, 0x25, 0x9c, 0xd2, 0xa6, 0x1a, 0x20, 0x10, 0x16, 0x6a, 0x42,
|
||||
0x27, 0x83, 0x47, 0x42, 0xa0, 0x07, 0x52, 0x09, 0x33, 0x97, 0x4e, 0x30, 0x57, 0xd8, 0xb7, 0x1e,
|
||||
0x46, 0xa6, 0xba, 0x4e, 0x40, 0x6a, 0xe9, 0x1a, 0x5a, 0xa0, 0x74, 0x56, 0x92, 0x55, 0xc2, 0xbd,
|
||||
0x44, 0xcd, 0xb3, 0x33, 0xf7, 0x35, 0x46, 0x25, 0xdf, 0x84, 0x19, 0xf3, 0xe2, 0x7a, 0xac, 0x4e,
|
||||
0xee, 0x1a, 0x86, 0x3b, 0xb3, 0x87, 0xa6, 0x66, 0xc1, 0x70, 0x21, 0x41, 0xd3, 0x58, 0x36, 0xb5,
|
||||
0x3b, 0x6e, 0xa1, 0x55, 0x60, 0x9a, 0x59, 0xd3, 0x85, 0xd8, 0xdc, 0x6a, 0xff, 0x41, 0xb6, 0xbf,
|
||||
0x42, 0xde, 0x64, 0x00, 0xd0, 0xee, 0x3a, 0xa1, 0x8a, 0xed, 0x12, 0xf9, 0xba, 0x54, 0x5c, 0xdb,
|
||||
0x06, 0x24, 0x49, 0xe8, 0x47, 0xcf, 0x5b, 0xe4, 0xbb, 0xc0, 0xaa, 0x8a, 0x8c, 0xbe, 0x73, 0xd9,
|
||||
0x02, 0xea, 0xee, 0x8d, 0x87, 0x5b, 0xbf, 0x78, 0x04, 0x41, 0x9e, 0xa8, 0x5c, 0x3c, 0x49, 0xde,
|
||||
0x88, 0x6d, 0x62, 0x21, 0x7f, 0xf0, 0x5e, 0x2d, 0x1d, 0xfc, 0x47, 0x0d, 0x1b, 0xaa, 0x4e, 0x0d,
|
||||
0x78, 0x20, 0xfe, 0x57, 0x0f, 0xca, 0xdf, 0xeb, 0x3c, 0x84, 0xa7, 0xe1, 0x61, 0xb2, 0x95, 0x98,
|
||||
0x07, 0x73, 0x8e, 0x51, 0xc6, 0x87, 0xe4, 0xcf, 0xf1, 0x5f, 0x86, 0x99, 0xec, 0x8d, 0x44, 0x92,
|
||||
0x2c, 0x99, 0xf6, 0xc0, 0xf4, 0x39, 0xe8, 0x05, 0xbf, 0xc1, 0x56, 0xde, 0xfe, 0x93, 0x75, 0x06,
|
||||
0x69, 0x87, 0x83, 0x06, 0x51, 0x80, 0xa5, 0x6e, 0xa6, 0x19, 0x7d, 0x3b, 0xef, 0xfb, 0xe0, 0x4a
|
||||
};
|
62
libdvbci/aes_xcbc_mac.cpp
Normal file
62
libdvbci/aes_xcbc_mac.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <openssl/aes.h>
|
||||
|
||||
#include "aes_xcbc_mac.h"
|
||||
|
||||
int aes_xcbc_mac_init(struct aes_xcbc_mac_ctx *ctx, const uint8_t *key)
|
||||
{
|
||||
AES_KEY aes_key;
|
||||
int y, x;
|
||||
|
||||
AES_set_encrypt_key(key, 128, &aes_key);
|
||||
|
||||
for (y = 0; y < 3; y++) {
|
||||
for (x = 0; x < 16; x++)
|
||||
ctx->K[y][x] = y + 1;
|
||||
AES_ecb_encrypt(ctx->K[y], ctx->K[y], &aes_key, 1);
|
||||
}
|
||||
|
||||
/* setup K1 */
|
||||
AES_set_encrypt_key(ctx->K[0], 128, &ctx->key);
|
||||
|
||||
memset(ctx->IV, 0, 16);
|
||||
ctx->buflen = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int aes_xcbc_mac_process(struct aes_xcbc_mac_ctx *ctx, const uint8_t *in, unsigned int len)
|
||||
{
|
||||
while (len) {
|
||||
if (ctx->buflen == 16) {
|
||||
AES_ecb_encrypt(ctx->IV, ctx->IV, &ctx->key, 1);
|
||||
ctx->buflen = 0;
|
||||
}
|
||||
ctx->IV[ctx->buflen++] ^= *in++;
|
||||
--len;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int aes_xcbc_mac_done(struct aes_xcbc_mac_ctx *ctx, uint8_t *out)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (ctx->buflen == 16) {
|
||||
/* K2 */
|
||||
for (i = 0; i < 16; i++)
|
||||
ctx->IV[i] ^= ctx->K[1][i];
|
||||
} else {
|
||||
ctx->IV[ctx->buflen] ^= 0x80;
|
||||
/* K3 */
|
||||
for (i = 0; i < 16; i++)
|
||||
ctx->IV[i] ^= ctx->K[2][i];
|
||||
}
|
||||
|
||||
AES_ecb_encrypt(ctx->IV, ctx->IV, &ctx->key, 1);
|
||||
memcpy(out, ctx->IV, 16);
|
||||
|
||||
return 0;
|
||||
}
|
15
libdvbci/aes_xcbc_mac.h
Normal file
15
libdvbci/aes_xcbc_mac.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef __AES_XCBC_H_
|
||||
#define __AES_XCBC_H_
|
||||
|
||||
struct aes_xcbc_mac_ctx {
|
||||
uint8_t K[3][16];
|
||||
uint8_t IV[16];
|
||||
AES_KEY key;
|
||||
int buflen;
|
||||
};
|
||||
|
||||
int aes_xcbc_mac_init(struct aes_xcbc_mac_ctx *ctx, const uint8_t *key);
|
||||
int aes_xcbc_mac_process(struct aes_xcbc_mac_ctx *ctx, const uint8_t *in, unsigned int len);
|
||||
int aes_xcbc_mac_done(struct aes_xcbc_mac_ctx *ctx, uint8_t *out);
|
||||
|
||||
#endif
|
105
libdvbci/descrambler.cpp
Normal file
105
libdvbci/descrambler.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <linux/dvb/ca.h>
|
||||
|
||||
#include "misc.h"
|
||||
#include "descrambler.h"
|
||||
|
||||
static const char * FILENAME = "[descrambler]";
|
||||
|
||||
/* alles im Kernel Header ca.h definiert da es der player2 auch braucht
|
||||
|
||||
enum ca_descr_data_type {
|
||||
CA_DATA_IV,
|
||||
CA_DATA_KEY,
|
||||
};
|
||||
|
||||
enum ca_descr_parity {
|
||||
CA_PARITY_EVEN,
|
||||
CA_PARITY_ODD,
|
||||
};
|
||||
|
||||
struct ca_descr_data {
|
||||
unsigned int index;
|
||||
enum ca_descr_parity parity;
|
||||
enum ca_descr_data_type data_type;
|
||||
unsigned int length;
|
||||
unsigned char *data;
|
||||
};
|
||||
#define CA_SET_DESCR_DATA _IOW('o', 137, struct ca_descr_data)
|
||||
|
||||
*/
|
||||
|
||||
static int desc_fd;
|
||||
|
||||
int descrambler_set_key(int index, int parity, unsigned char *data)
|
||||
{
|
||||
struct ca_descr_data d;
|
||||
|
||||
printf("%s -> %s\n", FILENAME, __FUNCTION__);
|
||||
d.index = index;
|
||||
d.parity = (ca_descr_parity)parity;
|
||||
d.data_type = CA_DATA_KEY;
|
||||
d.length = 16;
|
||||
d.data = data;
|
||||
|
||||
printf("Index: %d Parity: %d Type CA_DATA_KEY= %d\n", d.index, d.parity, d.data_type);
|
||||
hexdump(d.data, 16);
|
||||
|
||||
if (ioctl(desc_fd, CA_SET_DESCR_DATA, &d))
|
||||
printf("CA_SET_DESCR_DATA\n");
|
||||
|
||||
d.index = index;
|
||||
d.parity = (ca_descr_parity)parity;
|
||||
d.data_type = CA_DATA_IV;
|
||||
d.length = 16;
|
||||
d.data = data + 16;
|
||||
|
||||
printf("Index: %d Parity: %d Type CA_DATA_IV= %d\n", d.index, d.parity, d.data_type);
|
||||
hexdump(d.data, 16);
|
||||
|
||||
if (ioctl(desc_fd, CA_SET_DESCR_DATA, &d))
|
||||
printf("CA_SET_DESCR_DATA\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int descrambler_set_pid(int index, int enable, int pid)
|
||||
{
|
||||
struct ca_pid p;
|
||||
if (enable)
|
||||
p.index = index;
|
||||
else
|
||||
p.index = -1;
|
||||
|
||||
p.pid = pid;
|
||||
|
||||
if (ioctl(desc_fd, CA_SET_PID, &p))
|
||||
printf("CA_SET_PID\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int descrambler_init(void)
|
||||
{
|
||||
const char *filename = "/dev/dvb/adapter0/ca1";
|
||||
|
||||
printf("%s -> %s\n", FILENAME, __FUNCTION__);
|
||||
|
||||
desc_fd = open(filename, O_RDWR | O_NONBLOCK );
|
||||
if (desc_fd <= 0) {
|
||||
printf("cannot open %s\n", filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void descrambler_deinit(void)
|
||||
{
|
||||
close(desc_fd);
|
||||
}
|
9
libdvbci/descrambler.h
Normal file
9
libdvbci/descrambler.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef __DESCR_H_
|
||||
#define __DESCR_H_
|
||||
|
||||
int descrambler_init(void);
|
||||
void descrambler_deinit(void);
|
||||
int descrambler_set_key(int index, int parity, unsigned char *data);
|
||||
int descrambler_set_pid(int index, int enable, int pid);
|
||||
|
||||
#endif
|
244
libdvbci/dh_rsa_misc.cpp
Normal file
244
libdvbci/dh_rsa_misc.cpp
Normal file
@@ -0,0 +1,244 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/dh.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/sha.h>
|
||||
|
||||
#include "misc.h"
|
||||
|
||||
/* stolen from libtomcrypt */
|
||||
|
||||
static int pkcs_1_mgf1(const uint8_t *seed, unsigned long seedlen, uint8_t *mask, unsigned long masklen)
|
||||
{
|
||||
unsigned long hLen, x;
|
||||
uint32_t counter;
|
||||
uint8_t *buf;
|
||||
|
||||
/* get hash output size */
|
||||
hLen = 20; /* SHA1 */
|
||||
|
||||
/* allocate memory */
|
||||
buf = (uint8_t*)malloc(hLen);
|
||||
if (buf == NULL) {
|
||||
printf("error mem\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* start counter */
|
||||
counter = 0;
|
||||
|
||||
while (masklen > 0) {
|
||||
/* handle counter */
|
||||
BYTE32(buf, counter);
|
||||
++counter;
|
||||
|
||||
/* get hash of seed || counter */
|
||||
unsigned char buffer[0x18];
|
||||
memcpy(buffer, seed, seedlen);
|
||||
memcpy(buffer + 0x14, buf, 4);
|
||||
SHA1(buffer, 0x18, buf);
|
||||
|
||||
/* store it */
|
||||
for (x = 0; x < hLen && masklen > 0; x++, masklen--)
|
||||
*mask++ = buf[x];
|
||||
}
|
||||
|
||||
free(buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pkcs_1_pss_encode(const uint8_t *msghash, unsigned int msghashlen,
|
||||
unsigned long saltlen, unsigned long modulus_bitlen,
|
||||
uint8_t *out, unsigned int outlen)
|
||||
{
|
||||
unsigned char *DB, *mask, *salt, *hash;
|
||||
unsigned long x, y, hLen, modulus_len;
|
||||
int err = -1;
|
||||
unsigned char *hashbuf;
|
||||
unsigned int hashbuflen;
|
||||
|
||||
hLen = 20; /* SHA1 */
|
||||
modulus_len = (modulus_bitlen >> 3) + (modulus_bitlen & 7 ? 1 : 0);
|
||||
|
||||
/* allocate ram for DB/mask/salt/hash of size modulus_len */
|
||||
DB = (unsigned char*)malloc(modulus_len);
|
||||
mask = (unsigned char*)malloc(modulus_len);
|
||||
salt = (unsigned char*)malloc(modulus_len);
|
||||
hash = (unsigned char*)malloc(modulus_len);
|
||||
|
||||
hashbuflen = 8 + msghashlen + saltlen;
|
||||
hashbuf = (unsigned char*)malloc(hashbuflen);
|
||||
|
||||
if (!(DB && mask && salt && hash && hashbuf)) {
|
||||
printf("out of memory\n");
|
||||
goto LBL_ERR;
|
||||
}
|
||||
|
||||
/* generate random salt */
|
||||
if (saltlen > 0) {
|
||||
if (get_random(salt, saltlen) != (long)saltlen) {
|
||||
printf("rnd failed\n");
|
||||
goto LBL_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
/* M = (eight) 0x00 || msghash || salt, hash = H(M) */
|
||||
memset(hashbuf, 0, 8);
|
||||
memcpy(hashbuf + 8, msghash, msghashlen);
|
||||
memcpy(hashbuf + 8 + msghashlen, salt, saltlen);
|
||||
SHA1(hashbuf, hashbuflen, hash);
|
||||
|
||||
/* generate DB = PS || 0x01 || salt, PS == modulus_len - saltlen - hLen - 2 zero bytes */
|
||||
x = 0;
|
||||
memset(DB + x, 0, modulus_len - saltlen - hLen - 2);
|
||||
x += modulus_len - saltlen - hLen - 2;
|
||||
DB[x++] = 0x01;
|
||||
memcpy(DB + x, salt, saltlen);
|
||||
x += saltlen;
|
||||
|
||||
err = pkcs_1_mgf1(hash, hLen, mask, modulus_len - hLen - 1);
|
||||
if (err)
|
||||
goto LBL_ERR;
|
||||
|
||||
/* xor against DB */
|
||||
for (y = 0; y < (modulus_len - hLen - 1); y++)
|
||||
DB[y] ^= mask[y];
|
||||
|
||||
/* output is DB || hash || 0xBC */
|
||||
if (outlen < modulus_len) {
|
||||
err = -1;
|
||||
printf("error overflow\n");
|
||||
goto LBL_ERR;
|
||||
}
|
||||
|
||||
/* DB len = modulus_len - hLen - 1 */
|
||||
y = 0;
|
||||
memcpy(out + y, DB, modulus_len - hLen - 1);
|
||||
y += modulus_len - hLen - 1;
|
||||
|
||||
/* hash */
|
||||
memcpy(out + y, hash, hLen);
|
||||
y += hLen;
|
||||
|
||||
/* 0xBC */
|
||||
out[y] = 0xBC;
|
||||
|
||||
/* now clear the 8*modulus_len - modulus_bitlen most significant bits */
|
||||
out[0] &= 0xFF >> ((modulus_len << 3) - (modulus_bitlen - 1));
|
||||
|
||||
err = 0;
|
||||
LBL_ERR:
|
||||
free(hashbuf);
|
||||
free(hash);
|
||||
free(salt);
|
||||
free(mask);
|
||||
free(DB);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/* DH */
|
||||
|
||||
int dh_gen_exp(uint8_t *dest, int dest_len, uint8_t *dh_g, int dh_g_len, uint8_t *dh_p, int dh_p_len)
|
||||
{
|
||||
DH *dh;
|
||||
int len;
|
||||
unsigned int gap;
|
||||
|
||||
dh = DH_new();
|
||||
|
||||
dh->p = BN_bin2bn(dh_p, dh_p_len, 0);
|
||||
dh->g = BN_bin2bn(dh_g, dh_g_len, 0);
|
||||
dh->flags |= DH_FLAG_NO_EXP_CONSTTIME;
|
||||
|
||||
DH_generate_key(dh);
|
||||
|
||||
len = BN_num_bytes(dh->priv_key);
|
||||
if (len > dest_len) {
|
||||
printf("len > dest_len\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
gap = dest_len - len;
|
||||
memset(dest, 0, gap);
|
||||
BN_bn2bin(dh->priv_key, &dest[gap]);
|
||||
|
||||
DH_free(dh);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* dest = base ^ exp % mod */
|
||||
int dh_mod_exp(uint8_t *dest, int dest_len, uint8_t *base, int base_len, uint8_t *mod, int mod_len, uint8_t *exp, int exp_len)
|
||||
{
|
||||
BIGNUM *bn_dest, *bn_base, *bn_exp, *bn_mod;
|
||||
BN_CTX *ctx;
|
||||
int len;
|
||||
unsigned int gap;
|
||||
|
||||
bn_base = BN_bin2bn(base, base_len, NULL);
|
||||
bn_exp = BN_bin2bn(exp, exp_len, NULL);
|
||||
bn_mod = BN_bin2bn(mod, mod_len, NULL);
|
||||
ctx = BN_CTX_new();
|
||||
|
||||
bn_dest = BN_new();
|
||||
BN_mod_exp(bn_dest, bn_base, bn_exp, bn_mod, ctx);
|
||||
BN_CTX_free(ctx);
|
||||
|
||||
|
||||
len = BN_num_bytes(bn_dest);
|
||||
if (len > dest_len) {
|
||||
printf("len > dest_len\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
gap = dest_len - len;
|
||||
memset(dest, 0, gap);
|
||||
BN_bn2bin(bn_dest, &dest[gap]);
|
||||
|
||||
BN_free(bn_dest);
|
||||
BN_free(bn_mod);
|
||||
BN_free(bn_exp);
|
||||
BN_free(bn_base);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dh_dhph_signature(uint8_t *out, uint8_t *nonce, uint8_t *dhph, RSA *r)
|
||||
{
|
||||
unsigned char dest[302];
|
||||
uint8_t hash[20];
|
||||
unsigned char dbuf[256];
|
||||
|
||||
dest[0x00] = 0x00; /* version */
|
||||
dest[0x01] = 0x00;
|
||||
dest[0x02] = 0x08; /* len (bits) */
|
||||
dest[0x03] = 0x01; /* version data */
|
||||
|
||||
dest[0x04] = 0x01; /* msg_label */
|
||||
dest[0x05] = 0x00;
|
||||
dest[0x06] = 0x08; /* len (bits) */
|
||||
dest[0x07] = 0x02; /* message data */
|
||||
|
||||
dest[0x08] = 0x02; /* auth_nonce */
|
||||
dest[0x09] = 0x01;
|
||||
dest[0x0a] = 0x00; /* len (bits) */
|
||||
memcpy(&dest[0x0b], nonce, 32);
|
||||
|
||||
dest[0x2b] = 0x04; /* DHPH - DH public key host */
|
||||
dest[0x2c] = 0x08;
|
||||
dest[0x2d] = 0x00; /* len (bits) */
|
||||
memcpy(&dest[0x2e], dhph, 256);
|
||||
|
||||
SHA1(dest, 0x12e, hash);
|
||||
|
||||
if (pkcs_1_pss_encode(hash, 20, 20, 0x800, dbuf, sizeof(dbuf))) {
|
||||
printf("pss encode failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
RSA_private_encrypt(sizeof(dbuf), dbuf, out, r, RSA_NO_PADDING);
|
||||
|
||||
return 0;
|
||||
}
|
8
libdvbci/dh_rsa_misc.h
Normal file
8
libdvbci/dh_rsa_misc.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef __DH_RSA_MISC_H_
|
||||
#define __DH_RSA_MISC_H_
|
||||
|
||||
int dh_gen_exp(uint8_t *dest, int dest_len, uint8_t *dh_g, int dh_g_len, uint8_t *dh_p, int dh_p_len);
|
||||
int dh_mod_exp(uint8_t *dest, int dest_len, uint8_t *base, int base_len, uint8_t *mod, int mod_len, uint8_t *exp, int exp_len);
|
||||
int dh_dhph_signature(uint8_t *out, uint8_t *nonce, uint8_t *dhph, RSA *r);
|
||||
|
||||
#endif
|
1321
libdvbci/dvbci_ccmgr.cpp
Normal file
1321
libdvbci/dvbci_ccmgr.cpp
Normal file
File diff suppressed because it is too large
Load Diff
26
libdvbci/dvbci_ccmgr.h
Normal file
26
libdvbci/dvbci_ccmgr.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef __dvbci_dvbci_ccmgr_h
|
||||
#define __dvbci_dvbci_ccmgr_h
|
||||
|
||||
#include "dvbci_session.h"
|
||||
|
||||
class eDVBCIContentControlManagerSession: public eDVBCISession
|
||||
{
|
||||
bool data_initialize(tSlot *tslot);
|
||||
bool ci_ccmgr_cc_data_req(tSlot *tslot, const uint8_t *data, unsigned int len);
|
||||
bool ci_ccmgr_cc_sac_data_req(tSlot *tslot, const uint8_t *data, unsigned int len);
|
||||
bool ci_ccmgr_cc_sac_send(tSlot *tslot, const uint8_t *tag, uint8_t *data, unsigned int pos);
|
||||
void ci_ccmgr_cc_sac_sync_req(tSlot *tslot, const uint8_t *data, unsigned int len);
|
||||
void ci_ccmgr_cc_sync_req();
|
||||
void ci_ccmgr_cc_open_cnf(tSlot *slot);
|
||||
|
||||
enum {
|
||||
stateFinal=statePrivate
|
||||
};
|
||||
int receivedAPDU(const unsigned char *tag, const void *data, int len);
|
||||
int doAction();
|
||||
public:
|
||||
eDVBCIContentControlManagerSession(tSlot *tslot);
|
||||
~eDVBCIContentControlManagerSession();
|
||||
void ci_ccmgr_doClose(tSlot *tslot);
|
||||
};
|
||||
#endif
|
118
libdvbci/misc.cpp
Normal file
118
libdvbci/misc.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
void hexdump(const uint8_t *data, unsigned int len)
|
||||
{
|
||||
while (len--)
|
||||
printf("%02x ", *data++);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int get_random(unsigned char *dest, int len)
|
||||
{
|
||||
int fd;
|
||||
const char *urnd = "/dev/urandom";
|
||||
|
||||
fd = open(urnd, O_RDONLY);
|
||||
if (fd <= 0) {
|
||||
printf("cannot open %s\n", urnd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (read(fd, dest, len) != len) {
|
||||
printf("cannot read from %s\n", urnd);
|
||||
close(fd);
|
||||
return -2;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int parseLengthField(const unsigned char *pkt, int *len)
|
||||
{
|
||||
int i;
|
||||
|
||||
*len = 0;
|
||||
if (!(*pkt & 0x80)) {
|
||||
*len = *pkt;
|
||||
return 1;
|
||||
}
|
||||
for (i = 0; i < (pkt[0] & 0x7F); ++i) {
|
||||
*len <<= 8;
|
||||
*len |= pkt[i + 1];
|
||||
}
|
||||
return (pkt[0] & 0x7F) + 1;
|
||||
}
|
||||
|
||||
int add_padding(uint8_t *dest, unsigned int len, unsigned int blocklen)
|
||||
{
|
||||
uint8_t padding = 0x80;
|
||||
int count = 0;
|
||||
|
||||
while (len & (blocklen - 1)) {
|
||||
*dest++ = padding;
|
||||
++len;
|
||||
++count;
|
||||
padding = 0;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static int get_bin_from_nibble(int in)
|
||||
{
|
||||
if ((in >= '0') && (in <= '9'))
|
||||
return in - 0x30;
|
||||
|
||||
if ((in >= 'A') && (in <= 'Z'))
|
||||
return in - 0x41 + 10;
|
||||
|
||||
if ((in >= 'a') && (in <= 'z'))
|
||||
return in - 0x61 + 10;
|
||||
|
||||
printf("fixme: unsupported chars in hostid\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void str2bin(uint8_t *dst, char *data, int len)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < len; i += 2)
|
||||
*dst++ = (get_bin_from_nibble(data[i]) << 4) | get_bin_from_nibble(data[i + 1]);
|
||||
}
|
||||
|
||||
uint32_t UINT32(const unsigned char *in, unsigned int len)
|
||||
{
|
||||
uint32_t val = 0;
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
val <<= 8;
|
||||
val |= *in++;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
int BYTE32(unsigned char *dest, uint32_t val)
|
||||
{
|
||||
*dest++ = val >> 24;
|
||||
*dest++ = val >> 16;
|
||||
*dest++ = val >> 8;
|
||||
*dest++ = val;
|
||||
|
||||
return 4;
|
||||
}
|
||||
|
||||
int BYTE16(unsigned char *dest, uint16_t val)
|
||||
{
|
||||
*dest++ = val >> 8;
|
||||
*dest++ = val;
|
||||
return 2;
|
||||
}
|
19
libdvbci/misc.h
Normal file
19
libdvbci/misc.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef __MISC_H_
|
||||
#define __MISC_H_
|
||||
|
||||
void hexdump(const uint8_t *data, unsigned int len);
|
||||
|
||||
int parseLengthField(const unsigned char *pkt, int *len);
|
||||
|
||||
int get_random(unsigned char *dest, int len);
|
||||
|
||||
int add_padding(uint8_t *dest, unsigned int len, unsigned int blocklen);
|
||||
|
||||
void str2bin(uint8_t *dst, char *data, int len);
|
||||
|
||||
uint32_t UINT32(const uint8_t *in, unsigned int len);
|
||||
|
||||
int BYTE32(uint8_t *dest, uint32_t val);
|
||||
int BYTE16(uint8_t *dest, uint16_t val);
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user