Commit a0d219c4 authored by cRTrn13's avatar cRTrn13
Browse files

mkb, aacs

parent abbb9c1a
#include <stdio.h>
#include "aacs.h"
#include "../util/macro.h"
AACS *aacs_open(const char *path)
{
AACS aacs = malloc(sizeof(AACS));
}
void aacs_close(AACS *aacs)
{
X_FREE(aacs);
}
/*
* libaacs by Doom9 ppl 2009
* The aim of libaacs is to achieve a complete open-source implementation of the AACS spec
* The spec isfreely available at http://www.aacsla.com/specifications/
*/
#ifndef AACS_H_
#define AACS_H_
#include <stdint.h>
#include <unistd.h>
#include "mkb.h"
typedef struct aacs AACS;
struct aacs {
*uks, // unit key array (size = 16 * num_uks, each key is at 16-byte offset)
iv[16]; // current decryption iv
uint16_t num_uks; // number of unit keys
};
AACS *aacs_open(const char *path);
void aacs_close(AACS *aacs);
#endif /* AACS_H_ */
#include "mkb.h"
#include "../util/macro.h"
uint8_t *_record(MKB *mkb, uint8_t type, size_t *rec_len); // returns ptr to requests MKB record
uint8_t *_record(MKB *mkb, uint8_t type, size_t *rec_len)
{
size_t pos = 0, len = 0;
while (pos + 4 <= len) {
len = MKINT_BE24(buf + pos + 1);
if (rec_len) {
*rec_len = len;
}
if (buf[pos] == type)
return (uint8_t *)buf + pos;
pos += len;
}
return NULL;
}
struct mkb *mkb_open(const char *path)
{
FILE *fp = NULL;
char f_name[100];
MKB *mkb = malloc(sizeof(MKB));
snprintf(f_name, 100, "%s/AACS/MKB_RO.inf", path);
fp = fopen(f_name, "rb");
fseek(fp, 0, SEEK_END);
mkb->size = ftell(fp);
rewind(fp);
buf = malloc(mkb->size);
fread(buf, 1, mkb->size, fp);
fclose(fp);
X_FREE(fp);
return mkb;
}
void mkb_close(MKB *mkb)
{
X_FREE(mkb->buf);
X_FREE(mkb);
}
uint8_t mkb_type(MKB *mkb)
{
uint8_t *rec = _mkb_record(mkb, 0x10, NULL);
return MKINT_BE32(rec + 4);
}
uint8_t mkb_version(MKB *mkb)
{
uint8_t *rec = _mkb_record(mkb, 0x10, NULL);
return MKINT_BE32(rec + 8);
}
uint8_t *mkb_subdiff_records(MKB *mkb, uint32_t *len)
{
uint8_t *rec = _mkb_record(mkb, 0x04, len) + 4;
*len -= 4;
return rec;
}
uint8_t *mkb_cvalues(MKB *mkb, uint32_t *len)
{
uint8_t *rec = _mkb_record(mkb, 0x05, len) + 4;
*len -= 4;
return rec;
}
uint8_t *mkb_mk_dv(MKB *mkb)
{
return _mkb_record(mkb, 0x81, NULL) + 4;
}
uint8_t *mkb_signature(MKB *mkb, uint32_t *len)
{
uint8_t *rec = _mkb_record(mkb, 0x02, len);
*len -= 4;
return rec + 4;
}
#ifndef MKB_H_
#define MKB_H_
#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
typedef struct mkb MKB;
struct mkb {
size_t size; // file size
uint8_t *buf; // file contents
};
MKB *mkb_open(const char *path); // init MKB
void mkb_close(MKB *mkb); // free MKB
uint8_t mkb_type(MKB *mkb); // returns type
uint32_t mkb_version(MKB *mkb); // returns version
uint8_t *mkb_host_revokation_entries(MKB *mkb, uint32_t *len); // returns list of revoked host entries
uint8_t *mkb_drive_revokation_entries(MKB *mkb, uint32_t *len); // returns list of revoked drive entries
uint8_t *mkb_subdiff_records(MKB *mkb, uint32_t *len); // returns subset-diff records
uint8_t *mkb_subdiff_offsets(MKB *mkb, uint32_t *len); // returns list of subset-diff offsets
uint8_t *mkb_cvalues(MKB *mkb, uint32_t *len); // returns list of cvalues
uint8_t *mkb_mk_dv(MKB *mkb); // media key verification data return in param (always 16 bytes)
uint8_t *mkb_signature(MKB *mkb, uint32_t *len); // returns MKB signature
/* The Media Key block is of variable size but must be a multiple of 4
* MKB Structure:
* Type and Version record (12 bytes)
* 0 | type = 0x10
* 1-3 | length = 0x00000c
* 4-7 | MKB type = 0x000?1003
* 8-11| MKB version
*
* Host Revokation List record (variable - multiple of 4 bytes)
* 0 | type = 0x21
* 1-3 | length
* 4-7 | total entries
* 8-11 | entires in signature block 1 (N1)
* 12-19 | host revokation list entry 0
* .
* .
* (12+(N1-1)*8)-(12+N1*8)-1| entry n
* (12+ N1*8)-(52+ N1*8)-1 | block 1 signature
* (52+ N1*8)-(length-1) | more signature blocks
*
* Host Rekovation List entry (8 bytes)
* 0-1| range
* 2-7| host id
*
* Drive Revokation List record (variable - multiple of 4 bytes)
* 0 | type = 0x20
* 1-3 | length
* 4-7 | total entries
* 8-11 | entires in signature block 1 (N1)
* 12-19 | drive revokation list entry 0
* .
* .
* (12+(N1-1)*8)-(12+N1*8)-1| entry n
* (12+ N1*8)-(52+ N1*8)-1 | block 1 signature
* (52+ N1*8)-(length-1) | more signature blocks
*
* Drive Rekovation List entry (8 bytes)
* 0-1| range
* 2-7| host id
*
* Verify Media Key record
* 0 | type = 0x81
* 1-3 | length = 0x14
* 4-19| verification data (Dv)
*
* Explicit Subset-Difference record (variable - multiple of 4 bytes)
* 0 | type = 0x04
* 1-3 | length
* 4 | uv mask 0
* 5-8 | uv number 0
* .
* .
* length-1| end of uv number n
*
* Subset-Difference Index record (variable, padded - multiple of 4 bytes)
* 0 | type = 0x07
* 1-3 | length
* 4-7 | span (number of devices)
* 8-10 | offset 0
* .
* .
* length-1| end of offset n
*
* Media Key Data / cvalue record (variable - muliple of 4 bytes)
* 0 | type = 0x05
* 1-3 | length
* 4-19 | media key data 0
* .
* .
* length-1| end of media key data n
*
* End of Media Key Block record (variable - multiple of 4 bytes)
* 0 | type = 0x02
* 1-3 | length
* 4-length-1| signature
*/
#endif /* MKB_H_ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment