Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Jean-Baptiste Kempf
libaacs
Commits
baa36879
Commit
baa36879
authored
Jan 22, 2015
by
npzacs
Browse files
Merge util changes from other libs
parent
e032b1b0
Changes
20
Hide whitespace changes
Inline
Side-by-side
src/examples/parser_test.c
View file @
baa36879
...
...
@@ -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
;
}
...
...
src/file/dirs.h
View file @
baa36879
...
...
@@ -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
src/file/file.h
View file @
baa36879
...
...
@@ -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_ */
src/file/keydbcfg.h
View file @
baa36879
...
...
@@ -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
src/file/mmc_device.h
View file @
baa36879
...
...
@@ -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_ */
src/file/mmc_device_darwin.c
View file @
baa36879
...
...
@@ -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
)
{
...
...
src/file/mmc_device_linux.c
View file @
baa36879
...
...
@@ -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
)
{
...
...
src/file/path.h
View file @
baa36879
...
...
@@ -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 */
src/libaacs/aacs.c
View file @
baa36879
...
...
@@ -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
;
}
...
...
src/libaacs/crypto.h
View file @
baa36879
...
...
@@ -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_ */
src/libaacs/mkb.c
View file @
baa36879
...
...
@@ -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
;
}
...
...
src/libaacs/mkb.h
View file @
baa36879
...
...
@@ -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:
...
...
src/libaacs/mmc.c
View file @
baa36879
...
...
@@ -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
));
BD_DEBUG
(
DBG_MMC
,
"Drive key signature : %s
\n
"
,
print_hex
(
str
,
dks
,
40
));
BD_DEBUG
(
DBG_MMC
,
"Drive key point : %s
\n
"
,
str_
print_hex
(
str
,
dkp
,
40
));
BD_DEBUG
(
DBG_MMC
,
"Drive key signature : %s
\n
"
,
str_
print_hex
(
str
,
dks
,
40
));
}
// verify drive signature
...
...
@@ -481,7 +482,7 @@ static int _mmc_aacs_auth(MMC *mmc, uint8_t agid, const uint8_t *host_priv_key,
// send signed host key and point
if
(
!
_mmc_send_host_key
(
mmc
,
agid
,
mmc
->
host_key_point
,
hks
))
{