libaaruformat 1.0
Aaru Data Preservation Suite - Format Library
Loading...
Searching...
No Matches
ps3_crypto.c File Reference
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <aaruformat.h>
#include "../lib/aes128.h"
#include "ps3_crypto.h"
#include "ps3_encryption_map.h"

Go to the source code of this file.

Functions

void ps3_derive_disc_key (const uint8_t data1[16], uint8_t disc_key[16])
 Derive a PS3 disc key from a data1 key.
void ps3_derive_iv (uint64_t sector_num, uint8_t iv[16])
 Derive the per-sector AES IV from a sector number.
void ps3_encrypt_sector (const uint8_t disc_key[16], uint64_t sector_num, uint8_t *data, uint32_t length)
 Encrypt a sector using PS3 disc encryption (AES-128-CBC).
void ps3_decrypt_sector (const uint8_t disc_key[16], uint64_t sector_num, uint8_t *data, uint32_t length)
 Decrypt a sector using PS3 disc encryption (AES-128-CBC).
void ps3_lazy_init (aaruformat_context *ctx)
 Lazy-initialize PS3 encryption state from context media tags.

Variables

static const uint8_t PS3_ERK [16]
static const uint8_t PS3_ERK_IV [16]

Function Documentation

◆ ps3_decrypt_sector()

void ps3_decrypt_sector ( const uint8_t disc_key[16],
uint64_t sector_num,
uint8_t * data,
uint32_t length )

Decrypt a sector using PS3 disc encryption (AES-128-CBC).

Parameters
disc_key16-byte disc key.
sector_numSector number (for IV derivation).
dataBuffer to decrypt in-place.
lengthNumber of bytes (must be multiple of 16).

Definition at line 63 of file ps3_crypto.c.

References aes128_cbc_decrypt(), and ps3_derive_iv().

Referenced by aaruf_write_sector().

◆ ps3_derive_disc_key()

void ps3_derive_disc_key ( const uint8_t data1[16],
uint8_t disc_key[16] )

Derive a PS3 disc key from a data1 key.

disc_key = AES-128-CBC-Encrypt(PS3_ERK, PS3_ERK_IV, data1)

Parameters
data116-byte data1 key (from disc or IRD).
disc_keyOutput: 16-byte derived disc key.

Definition at line 39 of file ps3_crypto.c.

References aes128_cbc_encrypt(), PS3_ERK, and PS3_ERK_IV.

Referenced by ps3_lazy_init().

◆ ps3_derive_iv()

void ps3_derive_iv ( uint64_t sector_num,
uint8_t iv[16] )

Derive the per-sector AES IV from a sector number.

IV = sector number as 128-bit big-endian integer, zero-padded left.

Parameters
sector_numSector number.
ivOutput: 16-byte IV buffer.

Definition at line 45 of file ps3_crypto.c.

Referenced by ps3_decrypt_sector(), and ps3_encrypt_sector().

◆ ps3_encrypt_sector()

void ps3_encrypt_sector ( const uint8_t disc_key[16],
uint64_t sector_num,
uint8_t * data,
uint32_t length )

Encrypt a sector using PS3 disc encryption (AES-128-CBC).

Parameters
disc_key16-byte disc key.
sector_numSector number (for IV derivation).
dataBuffer to encrypt in-place.
lengthNumber of bytes (must be multiple of 16).

Definition at line 56 of file ps3_crypto.c.

References aes128_cbc_encrypt(), and ps3_derive_iv().

Referenced by aaruf_read_sector().

◆ ps3_lazy_init()

void ps3_lazy_init ( aaruformat_context * ctx)

Lazy-initialize PS3 encryption state from context media tags.

Reads kMediaTagPs3DiscKey and kMediaTagPs3EncryptionMap from the context's media tag hash table. Safe to call multiple times (no-op after first init). On failure, leaves fields NULL so callers degrade gracefully.

Parameters
ctxThe aaruformat context.

Definition at line 70 of file ps3_crypto.c.

References mediaTagEntry::data, kMediaTagPs3Data1, kMediaTagPs3DiscKey, kMediaTagPs3EncryptionMap, mediaTagEntry::length, aaruformat_context::mediaTags, ps3_derive_disc_key(), ps3_deserialize_encryption_map(), aaruformat_context::ps3_disc_key, aaruformat_context::ps3_plaintext_region_count, and aaruformat_context::ps3_plaintext_regions.

Referenced by aaruf_read_sector(), and aaruf_write_sector().

Variable Documentation

◆ PS3_ERK

const uint8_t PS3_ERK[16]
static
Initial value:
= {0x38, 0x0B, 0xCF, 0x0B, 0x53, 0x45, 0x5B, 0x3C,
0x78, 0x17, 0xAB, 0x4F, 0xA3, 0xBA, 0x90, 0xED}

Definition at line 32 of file ps3_crypto.c.

Referenced by ps3_derive_disc_key().

◆ PS3_ERK_IV

const uint8_t PS3_ERK_IV[16]
static
Initial value:
= {0x69, 0x47, 0x47, 0x72, 0xAF, 0x6F, 0xDA, 0xB3,
0x42, 0x74, 0x3A, 0xEF, 0xAA, 0x18, 0x62, 0x87}

Definition at line 36 of file ps3_crypto.c.

Referenced by ps3_derive_disc_key().