Commit baa36879 authored by npzacs's avatar npzacs
Browse files

Merge util changes from other libs

parent e032b1b0
......@@ -18,7 +18,7 @@
*/
#include "file/keydbcfg.h"
#include "util/logging.h"
#include "util/strutl.h"
#include <stdio.h>
#include <stdlib.h>
......@@ -66,7 +66,7 @@ static int print_title_entries(title_entry_list *list)
if (!cursor->entry.discid)
break;
printf("DISCID: %s\n", print_hex(tmp, cursor->entry.discid, 20));
printf("DISCID: %s\n", str_print_hex(tmp, cursor->entry.discid, 20));
printf(" Title: %s\n", cursor->entry.title);
printf(" Date: %u-%u-%u\n", cursor->entry.date.year,
cursor->entry.date.month, cursor->entry.date.day);
......@@ -112,8 +112,8 @@ static int print_cert_list(cert_list *list)
cert_list *cursor = list;
while (cursor)
{
printf(" Host private key: %s\n", print_hex(tmp, cursor->host_priv_key, 20));
printf(" Host certificate: %s\n", print_hex(tmp, cursor->host_cert, 92));
printf(" Host private key: %s\n", str_print_hex(tmp, cursor->host_priv_key, 20));
printf(" Host certificate: %s\n", str_print_hex(tmp, cursor->host_cert, 92));
printf("\n");
cursor = cursor->next;
......@@ -133,7 +133,7 @@ static int print_config_file(config_file *cfgfile)
dk_list *dkcursor = cfgfile->dkl;
while (dkcursor)
{
printf(" Device key: %s\n", print_hex(tmp, dkcursor->key, 16));
printf(" Device key: %s\n", str_print_hex(tmp, dkcursor->key, 16));
printf(" Device node: %lu\n", dkcursor->node);
dkcursor = dkcursor->next;
......@@ -146,7 +146,7 @@ static int print_config_file(config_file *cfgfile)
pk_list *cursor = cfgfile->pkl;
while (cursor)
{
printf(" %s\n", print_hex(tmp, cursor->key, 16));
printf(" %s\n", str_print_hex(tmp, cursor->key, 16));
cursor = cursor->next;
}
......
......@@ -23,17 +23,17 @@
#include "util/attributes.h"
#ifdef _WIN32
AACS_PRIVATE int win32_mkdir(const char *dir);
BD_PRIVATE int win32_mkdir(const char *dir);
#endif
/*
* Config, cache and data dirs
*/
AACS_PRIVATE const char *file_get_config_system(const char *dir);
BD_PRIVATE const char *file_get_config_system(const char *dir);
AACS_PRIVATE char *file_get_config_home(void) AACS_ATTR_MALLOC;
AACS_PRIVATE char *file_get_cache_home(void) AACS_ATTR_MALLOC;
AACS_PRIVATE char *file_get_data_home(void) AACS_ATTR_MALLOC;
BD_PRIVATE char *file_get_config_home(void) BD_ATTR_MALLOC;
BD_PRIVATE char *file_get_cache_home(void) BD_ATTR_MALLOC;
BD_PRIVATE char *file_get_data_home(void) BD_ATTR_MALLOC;
#endif
......@@ -28,8 +28,10 @@
#ifdef _WIN32
# define DIR_SEP "\\"
# define DIR_SEP_CHAR '\\'
#else
# define DIR_SEP "/"
# define DIR_SEP_CHAR '/'
#endif
/*
......@@ -42,7 +44,7 @@
#define file_read(X,Y,Z) X->read(X,Y,Z)
AACS_PRIVATE extern AACS_FILE_H *(*file_open)(const char* filename, const char *mode);
BD_PRIVATE extern AACS_FILE_H *(*file_open)(const char* filename, const char *mode);
#endif /* FILE_H_ */
......@@ -114,26 +114,26 @@ struct config_file_t
};
/* Functions used throughout the parser */
AACS_PRIVATE int keydbcfg_parse_config(config_file *cfgfile, const char *path);
AACS_PRIVATE config_file *keydbcfg_new_config_file(void);
AACS_PRIVATE int keydbcfg_config_file_close(config_file *cfgfile);
BD_PRIVATE int keydbcfg_parse_config(config_file *cfgfile, const char *path);
BD_PRIVATE config_file *keydbcfg_new_config_file(void);
BD_PRIVATE int keydbcfg_config_file_close(config_file *cfgfile);
/* */
AACS_PRIVATE config_file *keydbcfg_config_load(const char *configfile_path);
BD_PRIVATE config_file *keydbcfg_config_load(const char *configfile_path);
AACS_PRIVATE int keycache_save(const char *type, const uint8_t *disc_id,
BD_PRIVATE int keycache_save(const char *type, const uint8_t *disc_id,
const uint8_t *key, unsigned int len);
AACS_PRIVATE int keycache_find(const char *type, const uint8_t *disc_id,
BD_PRIVATE int keycache_find(const char *type, const uint8_t *disc_id,
uint8_t *key, unsigned int len);
AACS_PRIVATE int cache_get(const char *name, uint32_t *version, uint32_t *len, void *buf); /* use buf=NULL to get version and size */
AACS_PRIVATE int cache_save(const char *name, uint32_t version, const void *data, uint32_t len);
AACS_PRIVATE int cache_remove(const char *name);
BD_PRIVATE int cache_get(const char *name, uint32_t *version, uint32_t *len, void *buf); /* use buf=NULL to get version and size */
BD_PRIVATE int cache_save(const char *name, uint32_t version, const void *data, uint32_t len);
BD_PRIVATE int cache_remove(const char *name);
AACS_PRIVATE void *cache_get_or_update(const char *type, const void *data, uint32_t *len, uint32_t version);
BD_PRIVATE void *cache_get_or_update(const char *type, const void *data, uint32_t *len, uint32_t version);
AACS_PRIVATE int config_get(const char *name, uint32_t *len, void *buf); /* use buf=NULL to get size */
AACS_PRIVATE int config_save(const char *name, const void *data, uint32_t len);
BD_PRIVATE int config_get(const char *name, uint32_t *len, void *buf); /* use buf=NULL to get size */
BD_PRIVATE int config_save(const char *name, const void *data, uint32_t len);
#endif
......@@ -28,9 +28,9 @@
typedef struct mmcdev MMCDEV;
AACS_PRIVATE MMCDEV *device_open(const char *path);
AACS_PRIVATE void device_close(MMCDEV **mmc);
BD_PRIVATE MMCDEV *device_open(const char *path);
BD_PRIVATE void device_close(MMCDEV **mmc);
AACS_PRIVATE int device_send_cmd(MMCDEV *dev, const uint8_t *cmd, uint8_t *buf, size_t tx, size_t rx);
BD_PRIVATE int device_send_cmd(MMCDEV *dev, const uint8_t *cmd, uint8_t *buf, size_t tx, size_t rx);
#endif /* MMC_DEVICE_H_ */
......@@ -25,8 +25,9 @@
#include "mmc_device.h"
#include "util/macro.h"
#include "util/logging.h"
#include "util/macro.h"
#include "util/strutl.h"
#include <stdlib.h>
#include <string.h>
......@@ -138,11 +139,11 @@ int device_send_cmd(MMCDEV *mmc, const uint8_t *cmd, uint8_t *buf, size_t tx, si
rc = (*task)->ExecuteTaskSync (task, &sense, &status, &sent);
char str[512];
BD_DEBUG(DBG_MMC, "Send SCSI MMC cmd %s:\n", print_hex(str, cmd, 16));
BD_DEBUG(DBG_MMC, "Send SCSI MMC cmd %s:\n", str_print_hex(str, cmd, 16));
if (tx) {
BD_DEBUG(DBG_MMC, " Buffer: %s ->\n", print_hex(str, buf, tx>255?255:tx));
BD_DEBUG(DBG_MMC, " Buffer: %s ->\n", str_print_hex(str, buf, tx>255?255:tx));
} else {
BD_DEBUG(DBG_MMC, " Buffer: %s <-\n", print_hex(str, buf, rx>255?255:rx));
BD_DEBUG(DBG_MMC, " Buffer: %s <-\n", str_print_hex(str, buf, rx>255?255:rx));
}
if (kIOReturnSuccess != rc || status != 0) {
......
......@@ -27,8 +27,9 @@
#include "path.h"
#include "util/macro.h"
#include "util/logging.h"
#include "util/macro.h"
#include "util/strutl.h"
#include <stdlib.h>
#include <string.h>
......@@ -86,11 +87,11 @@ int device_send_cmd(MMCDEV *dev, const uint8_t *cmd, uint8_t *buf, size_t tx, si
result = ioctl(dev->fd, CDROM_SEND_PACKET, &cgc);
BD_DEBUG(DBG_MMC, "Send LINUX MMC cmd %s:\n", print_hex(str, cmd, 16));
BD_DEBUG(DBG_MMC, "Send LINUX MMC cmd %s:\n", str_print_hex(str, cmd, 16));
if (tx) {
BD_DEBUG(DBG_MMC, " Buffer: %s ->\n", print_hex(str, buf, tx>255?255:tx));
BD_DEBUG(DBG_MMC, " Buffer: %s ->\n", str_print_hex(str, buf, tx>255?255:tx));
} else {
BD_DEBUG(DBG_MMC, " Buffer: %s <-\n", print_hex(str, buf, rx>255?255:rx));
BD_DEBUG(DBG_MMC, " Buffer: %s <-\n", str_print_hex(str, buf, rx>255?255:rx));
}
if (result >= 0) {
......
......@@ -26,6 +26,6 @@
#define AACS_PATH_MAX 1024
#endif
AACS_PRIVATE char *aacs_resolve_path(const char *path, char *resolved_path);
BD_PRIVATE char *aacs_resolve_path(const char *path, char *resolved_path);
#endif /* AACS_PATH_H */
......@@ -100,11 +100,11 @@ static int _validate_pk(const uint8_t *pk,
uint8_t dec_vd[16];
char str[40];
BD_DEBUG(DBG_AACS, "Validate processing key %s...\n", print_hex(str, pk, 16));
BD_DEBUG(DBG_AACS, "Validate processing key %s...\n", str_print_hex(str, pk, 16));
BD_DEBUG(DBG_AACS, " Using:\n");
BD_DEBUG(DBG_AACS, " UV: %s\n", print_hex(str, uv, 4));
BD_DEBUG(DBG_AACS, " cvalue: %s\n", print_hex(str, cvalue, 16));
BD_DEBUG(DBG_AACS, " Verification data: %s\n", print_hex(str, vd, 16));
BD_DEBUG(DBG_AACS, " UV: %s\n", str_print_hex(str, uv, 4));
BD_DEBUG(DBG_AACS, " cvalue: %s\n", str_print_hex(str, cvalue, 16));
BD_DEBUG(DBG_AACS, " Verification data: %s\n", str_print_hex(str, vd, 16));
gcry_cipher_open(&gcry_h, GCRY_CIPHER_AES, GCRY_CIPHER_MODE_ECB, 0);
gcry_cipher_setkey(gcry_h, pk, 16);
......@@ -119,7 +119,7 @@ static int _validate_pk(const uint8_t *pk,
gcry_cipher_close(gcry_h);
if (!memcmp(dec_vd, "\x01\x23\x45\x67\x89\xAB\xCD\xEF", 8)) {
BD_DEBUG(DBG_AACS, "Processing key %s is valid!\n", print_hex(str, pk, 16));
BD_DEBUG(DBG_AACS, "Processing key %s is valid!\n", str_print_hex(str, pk, 16));
return AACS_SUCCESS;
}
......@@ -226,7 +226,7 @@ static void _calc_pk(const uint8_t *dk, uint8_t *pk, uint32_t uv, uint32_t v_mas
}
char str[40];
BD_DEBUG(DBG_AACS, "Processing key: %s\n", print_hex(str, pk, 16));
BD_DEBUG(DBG_AACS, "Processing key: %s\n", str_print_hex(str, pk, 16));
}
static dk_list *_find_dk(dk_list *dkl, uint32_t *p_dev_key_v_mask, uint32_t uv, uint32_t u_mask)
......@@ -258,7 +258,7 @@ static dk_list *_find_dk(dk_list *dkl, uint32_t *p_dev_key_v_mask, uint32_t uv,
BD_DEBUG(DBG_AACS | DBG_CRIT, "could not find applying device key (device 0x%x)\n", device_number);
} else {
char str[128];
BD_DEBUG(DBG_AACS, "Applying device key is #%d %s\n", key_idx, print_hex(str, dkl->key, 16));
BD_DEBUG(DBG_AACS, "Applying device key is #%d %s\n", key_idx, str_print_hex(str, dkl->key, 16));
BD_DEBUG(DBG_AACS, " UV: 0x%08x U mask: 0x%08x V mask: 0x%08x\n", dev_key_uv, dev_key_u_mask, dev_key_v_mask);
*p_dev_key_v_mask = dev_key_v_mask;
}
......@@ -362,11 +362,11 @@ static int _calc_pk_mk(MKB *mkb, dk_list *dkl, uint8_t *mk)
mk)
== AACS_SUCCESS) {
BD_DEBUG(DBG_AACS, "Media key: %s\n", print_hex(str, mk, 16));
BD_DEBUG(DBG_AACS, "Media key: %s\n", str_print_hex(str, mk, 16));
return AACS_SUCCESS;
}
BD_DEBUG(DBG_AACS | DBG_CRIT, "Processing key %s is invalid!\n", print_hex(str, pk, 16));
BD_DEBUG(DBG_AACS | DBG_CRIT, "Processing key %s is invalid!\n", str_print_hex(str, pk, 16));
/* try next device */
}
......@@ -455,7 +455,7 @@ static int _calc_mk(AACS *aacs, uint8_t *mk, pk_list *pkl, dk_list *dkl)
mkb_close(mkb);
char str[40];
BD_DEBUG(DBG_AACS, "Media key: %s\n", print_hex(str, mk, 16));
BD_DEBUG(DBG_AACS, "Media key: %s\n", str_print_hex(str, mk, 16));
memcpy(aacs->mk, mk, sizeof(aacs->mk));
return AACS_SUCCESS;
}
......@@ -488,18 +488,18 @@ static int _mmc_read_auth(AACS *aacs, cert_list *hcl, int type, uint8_t *p1, uin
if (!crypto_aacs_verify_host_cert(hcl->host_cert)) {
BD_DEBUG(DBG_AACS, "Not using invalid host certificate %s.\n",
print_hex(tmp_str, hcl->host_cert, 92));
str_print_hex(tmp_str, hcl->host_cert, 92));
continue;
}
if (drive_cert && (drive_cert[1] & 0x01) && !(hcl->host_cert[1] & 0x01)) {
BD_DEBUG(DBG_AACS, "Certificate (id 0x%s) does not support bus encryption\n",
print_hex(tmp_str, hcl->host_cert + 4, 6));
str_print_hex(tmp_str, hcl->host_cert + 4, 6));
//continue;
}
BD_DEBUG(DBG_AACS, "Trying host certificate (id 0x%s)...\n",
print_hex(tmp_str, hcl->host_cert + 4, 6));
str_print_hex(tmp_str, hcl->host_cert + 4, 6));
int mmc_result = mmc_read_auth(mmc, hcl->host_priv_key, hcl->host_cert, type, p1, p2);
switch (mmc_result) {
......@@ -598,7 +598,7 @@ static int _calc_vuk(AACS *aacs, uint8_t *mk, uint8_t *vuk, config_file *cf)
}
char str[40];
BD_DEBUG(DBG_AACS, "Volume unique key: %s\n", print_hex(str, vuk, 16));
BD_DEBUG(DBG_AACS, "Volume unique key: %s\n", str_print_hex(str, vuk, 16));
/* cache vuk */
keycache_save("vuk", aacs->disc_id, vuk, 16);
......@@ -667,7 +667,7 @@ static void _find_config_entry(AACS *aacs, title_entry_list *ce,
while (ce && ce->entry.discid) {
if (!memcmp(aacs->disc_id, ce->entry.discid, 20)) {
BD_DEBUG(DBG_AACS, "Found config entry for discid %s\n",
print_hex(str, ce->entry.discid, 20));
str_print_hex(str, ce->entry.discid, 20));
break;
}
......@@ -681,7 +681,7 @@ static void _find_config_entry(AACS *aacs, title_entry_list *ce,
hexstring_to_hex_array(mk, 16, ce->entry.mek);
BD_DEBUG(DBG_AACS, "Found media key for %s: %s\n",
ce->entry.discid, print_hex(str, mk, 16));
ce->entry.discid, str_print_hex(str, mk, 16));
}
if (ce->entry.vid) {
......@@ -689,14 +689,14 @@ static void _find_config_entry(AACS *aacs, title_entry_list *ce,
ce->entry.vid);
BD_DEBUG(DBG_AACS, "Found volume id for %s: %s\n",
ce->entry.discid, print_hex(str, aacs->vid, 16));
ce->entry.discid, str_print_hex(str, aacs->vid, 16));
}
if (ce->entry.vuk) {
hexstring_to_hex_array(vuk, 16, ce->entry.vuk);
BD_DEBUG(DBG_AACS, "Found volume unique key for %s: %s\n",
ce->entry.discid, print_hex(str, vuk, 16));
ce->entry.discid, str_print_hex(str, vuk, 16));
}
if (ce->entry.uk) {
......@@ -712,7 +712,7 @@ static void _find_config_entry(AACS *aacs, title_entry_list *ce,
BD_DEBUG(DBG_AACS, "Unit key %d from keydb entry: %s\n",
aacs->num_uks,
print_hex(str, aacs->uks + (16 * (aacs->num_uks - 1)), 16));
str_print_hex(str, aacs->uks + (16 * (aacs->num_uks - 1)), 16));
ukcursor = ukcursor->next;
}
......@@ -788,7 +788,7 @@ static int _calc_uks(AACS *aacs, config_file *cf)
char str[40];
BD_DEBUG(DBG_AACS, "Unit key %d: %s\n", i,
print_hex(str, aacs->uks + 16*i, 16));
str_print_hex(str, aacs->uks + 16*i, 16));
}
/* failing next is not fatal, it just slows down things */
......@@ -827,7 +827,7 @@ static int _calc_title_hash(AACS *aacs)
if ((file_read(fp, ukf_buf, f_size)) == f_size) {
crypto_aacs_title_hash(ukf_buf, f_size, aacs->disc_id);
BD_DEBUG(DBG_AACS, "Disc ID: %s\n", print_hex(str, aacs->disc_id, 20));
BD_DEBUG(DBG_AACS, "Disc ID: %s\n", str_print_hex(str, aacs->disc_id, 20));
} else {
result = AACS_ERROR_CORRUPTED_DISC;
......@@ -888,7 +888,7 @@ static int _verify_ts(uint8_t *buf)
{
int i;
for (i = 0; i < ALIGNED_UNIT_LEN; i += 192) {
if (AACS_UNLIKELY(buf[i + 4] != 0x47)) {
if (BD_UNLIKELY(buf[i + 4] != 0x47)) {
return 0;
}
......@@ -906,7 +906,7 @@ static int _decrypt_unit(AACS *aacs, uint8_t *out_buf, const uint8_t *in_buf, ui
int a;
uint8_t key[16];
if (AACS_UNLIKELY(in_buf != NULL)) {
if (BD_UNLIKELY(in_buf != NULL)) {
memcpy(out_buf, in_buf, 16); /* first 16 bytes are plain */
}
......@@ -922,7 +922,7 @@ static int _decrypt_unit(AACS *aacs, uint8_t *out_buf, const uint8_t *in_buf, ui
gcry_cipher_open(&gcry_h, GCRY_CIPHER_AES, GCRY_CIPHER_MODE_CBC, 0);
gcry_cipher_setkey(gcry_h, key, 16);
gcry_cipher_setiv(gcry_h, aacs_iv, 16);
if (AACS_UNLIKELY(in_buf != NULL)) {
if (BD_UNLIKELY(in_buf != NULL)) {
gcry_cipher_decrypt(gcry_h, out_buf + 16, ALIGNED_UNIT_LEN - 16, in_buf + 16, ALIGNED_UNIT_LEN - 16);
} else {
gcry_cipher_decrypt(gcry_h, out_buf + 16, ALIGNED_UNIT_LEN - 16, NULL, 0);
......@@ -1081,8 +1081,8 @@ int aacs_decrypt_unit(AACS *aacs, uint8_t *buf)
}
/* decrypt in-place if current unit key is known */
if (AACS_LIKELY(aacs->cps_unit_selected) || AACS_LIKELY(aacs->num_uks == 1)) {
if (AACS_LIKELY(_decrypt_unit(aacs, buf, NULL, aacs->current_cps_unit))) {
if (BD_LIKELY(aacs->cps_unit_selected) || BD_LIKELY(aacs->num_uks == 1)) {
if (BD_LIKELY(_decrypt_unit(aacs, buf, NULL, aacs->current_cps_unit))) {
return 1;
}
......
......@@ -25,25 +25,25 @@
#include <stdlib.h>
#include <stdint.h>
AACS_PRIVATE int crypto_init(void);
AACS_PRIVATE void crypto_aes128d(const uint8_t *key, const uint8_t *data, uint8_t *dst);
AACS_PRIVATE void crypto_aesg3(const uint8_t *D, uint8_t *lsubk, uint8_t* rsubk,
uint8_t *pk); // returns left, centre, right keys
AACS_PRIVATE void crypto_aes_cmac_16(const unsigned char *data, const unsigned char *aes_key, unsigned char *cmac);
AACS_PRIVATE void crypto_aacs_sign(const uint8_t *cert, const uint8_t *priv_key,
uint8_t *signature,
const uint8_t *nonce, const uint8_t *point);
AACS_PRIVATE void crypto_aacs_title_hash(const uint8_t *ukf, uint64_t len, uint8_t *hash);
AACS_PRIVATE int crypto_aacs_verify(const uint8_t *cert, const uint8_t *signature, const uint8_t *data, uint32_t len);
AACS_PRIVATE int crypto_aacs_verify_aacsla(const uint8_t *signature, const uint8_t *data, uint32_t len);
AACS_PRIVATE int crypto_aacs_verify_cert(const uint8_t *cert);
AACS_PRIVATE int crypto_aacs_verify_host_cert(const uint8_t *cert);
AACS_PRIVATE int crypto_aacs_verify_drive_cert(const uint8_t *cert);
AACS_PRIVATE void crypto_create_host_key_pair(uint8_t *key, uint8_t *key_point);
AACS_PRIVATE void crypto_create_nonce(uint8_t *buf, size_t len);
AACS_PRIVATE void crypto_create_bus_key(const uint8_t *priv_key, const uint8_t *drive_key_point, unsigned char *bus_key);
BD_PRIVATE int crypto_init(void);
BD_PRIVATE void crypto_aes128d(const uint8_t *key, const uint8_t *data, uint8_t *dst);
BD_PRIVATE void crypto_aesg3(const uint8_t *D, uint8_t *lsubk, uint8_t* rsubk,
uint8_t *pk); // returns left, centre, right keys
BD_PRIVATE void crypto_aes_cmac_16(const unsigned char *data, const unsigned char *aes_key, unsigned char *cmac);
BD_PRIVATE void crypto_aacs_sign(const uint8_t *cert, const uint8_t *priv_key,
uint8_t *signature,
const uint8_t *nonce, const uint8_t *point);
BD_PRIVATE void crypto_aacs_title_hash(const uint8_t *ukf, uint64_t len, uint8_t *hash);
BD_PRIVATE int crypto_aacs_verify(const uint8_t *cert, const uint8_t *signature, const uint8_t *data, uint32_t len);
BD_PRIVATE int crypto_aacs_verify_aacsla(const uint8_t *signature, const uint8_t *data, uint32_t len);
BD_PRIVATE int crypto_aacs_verify_cert(const uint8_t *cert);
BD_PRIVATE int crypto_aacs_verify_host_cert(const uint8_t *cert);
BD_PRIVATE int crypto_aacs_verify_drive_cert(const uint8_t *cert);
BD_PRIVATE void crypto_create_host_key_pair(uint8_t *key, uint8_t *key_point);
BD_PRIVATE void crypto_create_nonce(uint8_t *buf, size_t len);
BD_PRIVATE void crypto_create_bus_key(const uint8_t *priv_key, const uint8_t *drive_key_point, unsigned char *bus_key);
#endif /* CRYPTO_H_ */
......@@ -206,7 +206,7 @@ static int _cert_is_revoked(const uint8_t *rl, size_t rl_size, const uint8_t *ce
uint64_t id = MKINT_BE48(rl + 2);
if (cert_id >= id && cert_id <= id + len) {
char str[16];
print_hex(str, rl + 2, 6);
str_print_hex(str, rl + 2, 6);
BD_DEBUG(DBG_MKB, "Certificate %s has been revoked\n", str);
return 1;
}
......
......@@ -29,36 +29,36 @@ typedef struct mkb MKB;
struct aacs_file_s;
AACS_PRIVATE MKB *mkb_read(struct aacs_file_s *fp); // init MKB
AACS_PRIVATE MKB *mkb_init(uint8_t *data, int len); // init MKB from data
AACS_PRIVATE void mkb_close(MKB *mkb); // free MKB
BD_PRIVATE MKB *mkb_read(struct aacs_file_s *fp); // init MKB
BD_PRIVATE MKB *mkb_init(uint8_t *data, int len); // init MKB from data
BD_PRIVATE void mkb_close(MKB *mkb); // free MKB
AACS_PRIVATE const uint8_t *mkb_data(MKB *mkb);
AACS_PRIVATE size_t mkb_data_size(MKB *mkb);
BD_PRIVATE const uint8_t *mkb_data(MKB *mkb);
BD_PRIVATE size_t mkb_data_size(MKB *mkb);
// returns type
AACS_PRIVATE uint8_t mkb_type(MKB *mkb);
BD_PRIVATE uint8_t mkb_type(MKB *mkb);
// returns version
AACS_PRIVATE uint32_t mkb_version(MKB *mkb);
BD_PRIVATE uint32_t mkb_version(MKB *mkb);
// returns type and version record (required to verify signatures)
AACS_PRIVATE const uint8_t *mkb_type_and_version_record(MKB *mkb);
BD_PRIVATE const uint8_t *mkb_type_and_version_record(MKB *mkb);
// returns list of revoked host entries
AACS_PRIVATE const uint8_t *mkb_host_revokation_entries(MKB *mkb, size_t *len);
BD_PRIVATE const uint8_t *mkb_host_revokation_entries(MKB *mkb, size_t *len);
// returns list of revoked drive entries
AACS_PRIVATE const uint8_t *mkb_drive_revokation_entries(MKB *mkb, size_t *len);
BD_PRIVATE const uint8_t *mkb_drive_revokation_entries(MKB *mkb, size_t *len);
// returns subset-diff records
AACS_PRIVATE const uint8_t *mkb_subdiff_records(MKB *mkb, size_t *len);
BD_PRIVATE const uint8_t *mkb_subdiff_records(MKB *mkb, size_t *len);
// returns list of subset-diff offsets
AACS_PRIVATE const uint8_t *mkb_subdiff_offsets(MKB *mkb, size_t *len);
BD_PRIVATE const uint8_t *mkb_subdiff_offsets(MKB *mkb, size_t *len);
// returns list of cvalues
AACS_PRIVATE const uint8_t *mkb_cvalues(MKB *mkb, size_t *len);
BD_PRIVATE const uint8_t *mkb_cvalues(MKB *mkb, size_t *len);
// media key verification data return in param (always 16 bytes)
AACS_PRIVATE const uint8_t *mkb_mk_dv(MKB *mkb);
BD_PRIVATE const uint8_t *mkb_mk_dv(MKB *mkb);
// returns MKB signature
AACS_PRIVATE const uint8_t *mkb_signature(MKB *mkb, size_t *len);
BD_PRIVATE const uint8_t *mkb_signature(MKB *mkb, size_t *len);
AACS_PRIVATE int mkb_host_cert_is_revoked(MKB *mkb, const uint8_t *cert_id);
AACS_PRIVATE int mkb_drive_cert_is_revoked(MKB *mkb, const uint8_t *cert_id);
BD_PRIVATE int mkb_host_cert_is_revoked(MKB *mkb, const uint8_t *cert_id);
BD_PRIVATE int mkb_drive_cert_is_revoked(MKB *mkb, const uint8_t *cert_id);
/* The Media Key block is of variable size but must be a multiple of 4
* MKB Structure:
......
......@@ -27,8 +27,9 @@
#include "crypto.h"
#include "file/mmc_device.h"
#include "util/macro.h"
#include "util/logging.h"
#include "util/macro.h"
#include "util/strutl.h"
#include <stdlib.h>
#include <string.h>
......@@ -84,7 +85,7 @@ static int _mmc_send_key(MMC *mmc, uint8_t agid, uint8_t format, uint8_t *buf,
char str[512];
memset(cmd, 0, sizeof(cmd));
BD_DEBUG(DBG_MMC, "MMC send key [%d] %s...\n", len, print_hex(str, buf, len));
BD_DEBUG(DBG_MMC, "MMC send key [%d] %s...\n", len, str_print_hex(str, buf, len));
cmd[0] = 0xa3;
cmd[7] = 0x02;
......@@ -92,7 +93,7 @@ static int _mmc_send_key(MMC *mmc, uint8_t agid, uint8_t format, uint8_t *buf,
cmd[9] = len & 0xff;
cmd[10] = (agid << 6) | (format & 0x3f);
BD_DEBUG(DBG_MMC, "cmd: %s\n", print_hex(str, cmd, 16));
BD_DEBUG(DBG_MMC, "cmd: %s\n", str_print_hex(str, cmd, 16));
return device_send_cmd(mmc->dev, cmd, buf, len, 0);
}
......@@ -346,7 +347,7 @@ MMC *mmc_open(const char *path)
if (DEBUG_KEYS) {
char str[sizeof(mmc->host_nonce)*2 + 1];
BD_DEBUG(DBG_MMC, "Created host nonce (Hn): %s\n",
print_hex(str, mmc->host_nonce, sizeof(mmc->host_nonce)));
str_print_hex(str, mmc->host_nonce, sizeof(mmc->host_nonce)));
}
crypto_create_host_key_pair(mmc->host_key, mmc->host_key_point);
......@@ -354,9 +355,9 @@ MMC *mmc_open(const char *path)
if (DEBUG_KEYS) {
char str[sizeof(mmc->host_key_point)*2 + 1];
BD_DEBUG(DBG_MMC, "Created host key (Hk): %s\n",
print_hex(str, mmc->host_key, sizeof(mmc->host_key)));
str_print_hex(str, mmc->host_key, sizeof(mmc->host_key)));
BD_DEBUG(DBG_MMC, "Created host key point (Hv): %s\n",
print_hex(str, mmc->host_key_point, sizeof(mmc->host_key_point)));
str_print_hex(str, mmc->host_key_point, sizeof(mmc->host_key_point)));
}
mmc->dev = device_open(path);
......@@ -417,8 +418,8 @@ static int _mmc_aacs_auth(MMC *mmc, uint8_t agid, const uint8_t *host_priv_key,
memset(hks, 0, sizeof(hks));
if (DEBUG_KEYS) {
BD_DEBUG(DBG_MMC, "Host certificate : %s\n", print_hex(str, host_cert, 92));
BD_DEBUG(DBG_MMC, "Host nonce : %s\n", print_hex(str, mmc->host_nonce, 20));
BD_DEBUG(DBG_MMC, "Host certificate : %s\n", str_print_hex(str, host_cert, 92));
BD_DEBUG(DBG_MMC, "Host nonce : %s\n", str_print_hex(str, mmc->host_nonce, 20));
}
// send host cert + nonce
......@@ -426,7 +427,7 @@ static int _mmc_aacs_auth(MMC *mmc, uint8_t agid, const uint8_t *host_priv_key,
if ((mmc->drive_cert[1] & 0x01) && !(host_cert[1] & 0x01)) {
BD_DEBUG(DBG_MMC | DBG_CRIT, "Certificate (id 0x%s) can not be used with bus encryption capable drive\n",
print_hex(str, host_cert + 4, 6));
str_print_hex(str, host_cert + 4, 6));
} else {
BD_DEBUG(DBG_MMC | DBG_CRIT, "Host key / Certificate has been revoked by your drive ?\n");
}
......@@ -441,8 +442,8 @@ static int _mmc_aacs_auth(MMC *mmc, uint8_t agid, const uint8_t *host_priv_key,
}
if (DEBUG_KEYS) {
BD_DEBUG(DBG_MMC, "Drive certificate : %s\n", print_hex(str, mmc->drive_cert, 92));
BD_DEBUG(DBG_MMC, "Drive nonce : %s\n", print_hex(str, dn, 20));
BD_DEBUG(DBG_MMC, "Drive certificate : %s\n", str_print_hex(str, mmc->drive_cert, 92));
BD_DEBUG(DBG_MMC, "Drive nonce : %s\n", str_print_hex(str, dn, 20));
}
// verify drive certificate
......@@ -458,8 +459,8 @@ static int _mmc_aacs_auth(MMC *mmc, uint8_t agid, const uint8_t *host_priv_key,
}
if (DEBUG_KEYS) {
BD_DEBUG(DBG_MMC, "Drive key point : %s\n", print_hex(str, dkp, 40));