libmobi
C library for handling MOBI format ebook documents
Data Structures | Functions
encryption.h File Reference
#include "config.h"
#include "mobi.h"

Go to the source code of this file.

Data Structures

struct  MOBICookie
 Drm cookie data. More...
 
struct  MOBIDrm
 Drm data. More...
 

Functions

void mobi_free_drm (MOBIData *m)
 Free DRM structure. More...
 
MOBI_RET mobi_buffer_decrypt (unsigned char *out, const unsigned char *in, const size_t length, const MOBIData *m)
 Decrypt buffer with PK1 algorithm. More...
 
MOBI_RET mobi_drmkey_set (MOBIData *m, const char *pid)
 Store key for encryption in MOBIData stucture. More...
 
MOBI_RET mobi_drmkey_set_serial (MOBIData *m, const char *serial)
 Store key for encryption in MOBIData stucture. Pid will be calculated from device serial number. More...
 
MOBI_RET mobi_drmkey_delete (MOBIData *m)
 Remove key from MOBIData structure. More...
 
MOBI_RET mobi_voucher_add (MOBIData *m, const char *serial, const time_t valid_from, const time_t valid_to, const MOBIExthTag *tamperkeys, const size_t tamperkeys_count)
 Add DRM voucher. More...
 
MOBI_RET mobi_drm_serialize_v1 (MOBIBuffer *buf, const MOBIData *m)
 Serialize encryption scheme version 1. More...
 
MOBI_RET mobi_drm_serialize_v2 (MOBIBuffer *buf, const MOBIData *m)
 Serialize encryption scheme version 2. More...
 

Detailed Description

Copyright (c) 2014 Bartek Fabiszewski http://www.fabiszewski.net

This file is part of libmobi. Licensed under LGPL, either version 3, or any later. See http://www.gnu.org/licenses/

Function Documentation

◆ mobi_buffer_decrypt()

MOBI_RET mobi_buffer_decrypt ( unsigned char *  out,
const unsigned char *  in,
const size_t  length,
const MOBIData m 
)

Decrypt buffer with PK1 algorithm.

Parameters
[in,out]outDecrypted buffer
[in]inEncrypted buffer
[in]lengthBuffer length
[in]mMOBIData structure with loaded key
Returns
MOBI_RET status code (on success MOBI_SUCCESS)

◆ mobi_drm_serialize_v1()

MOBI_RET mobi_drm_serialize_v1 ( MOBIBuffer buf,
const MOBIData m 
)

Serialize encryption scheme version 1.

Parameters
[in,out]bufOutput buffer
[in]mMOBIData structure with raw data and metadata
Returns
MOBI_RET status code (on success MOBI_SUCCESS)

◆ mobi_drm_serialize_v2()

MOBI_RET mobi_drm_serialize_v2 ( MOBIBuffer buf,
const MOBIData m 
)

Serialize encryption scheme version 2.

Parameters
[in,out]bufOutput buffer
[in]mMOBIData structure with raw data and metadata
Returns
MOBI_RET status code (on success MOBI_SUCCESS)

◆ mobi_drmkey_delete()

MOBI_RET mobi_drmkey_delete ( MOBIData m)

Remove key from MOBIData structure.

Parameters
[in,out]mMOBIData structure with raw data and metadata
Returns
MOBI_RET status code (on success MOBI_SUCCESS)

◆ mobi_drmkey_set()

MOBI_RET mobi_drmkey_set ( MOBIData m,
const char *  pid 
)

Store key for encryption in MOBIData stucture.

In case of encrypted document key is extracted from document. PID may be needed.

Parameters
[in,out]mMOBIData structure with raw data and metadata
[in]pidPID, may be NULL in case of encryption type 1, which does not use PID
Returns
MOBI_RET status code (on success MOBI_SUCCESS)

◆ mobi_drmkey_set_serial()

MOBI_RET mobi_drmkey_set_serial ( MOBIData m,
const char *  serial 
)

Store key for encryption in MOBIData stucture. Pid will be calculated from device serial number.

Parameters
[in,out]mMOBIData structure with raw data and metadata
[in]serialSerial
Returns
MOBI_RET status code (on success MOBI_SUCCESS)

◆ mobi_free_drm()

void mobi_free_drm ( MOBIData m)

Free DRM structure.

Parameters
[in,out]mMOBIData structure with raw data and metadata

◆ mobi_voucher_add()

MOBI_RET mobi_voucher_add ( MOBIData m,
const char *  serial,
const time_t  valid_from,
const time_t  valid_to,
const MOBIExthTag tamperkeys,
const size_t  tamperkeys_count 
)

Add DRM voucher.

See also
mobi_drm_addvoucher
Parameters
[in,out]mMOBIData structure with raw data and metadata
[in]serialDevice serial number
[in]valid_fromVoucher validity start time, -1 if not set
[in]valid_toVoucher expire time, -1 if not set
[in]tamperkeysArray of EXTH tags to include in PID generation, NULL if none
[in]tamperkeys_countCount of EXTH tags
Returns
MOBI_RET status code (on success MOBI_SUCCESS)