Functions to handle encryption.
More...
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include "util.h"
#include "debug.h"
#include "randombytes.h"
#include "sha1.h"
#include "encryption.h"
|
#define | INTERNAL_READER_KEY ((unsigned char*) "\x72\x38\x33\xb0\xb4\xf2\xe3\xca\xdf\x09\x01\xd6\xe2\xe0\x3f\x96") |
|
#define | INTERNAL_PUBLISHER_KEY ((unsigned char*) "\x95\xda\x7b\xed\x90\x5e\x10\x2e\x44\x4c\xb5\xe5\xc0\x25\xdf\x2c") |
|
#define | INTERNAL_READER_KEY_V1 ((unsigned char*) "QDCVEPMU675RUBSZ") |
|
#define | PIDSIZE 10 |
|
#define | SERIALSIZE 16 |
|
#define | SERIALLONGSIZE 40 |
|
#define | KEYSIZE 16 |
|
#define | COOKIESIZE 32 |
|
#define | VOUCHERSIZE 48 |
|
#define | VOUCHERS_COUNT_MAX 1024 |
|
#define | VOUCHERS_SIZE_MIN 288 |
|
#define | pk1_swap(a, b) { uint16_t tmp = a; (a) = b; (b) = tmp; } |
|
|
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_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_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_drmkey_set (MOBIData *m, const char *pid) |
| Store key for encryption in MOBIData stucture. More...
|
|
MOBI_RET | mobi_drmkey_delete (MOBIData *m) |
| Remove key from MOBIData structure. More...
|
|
MOBI_RET | mobi_drm_decrypt (MOBIData *m) |
| Decrypt document. More...
|
|
MOBI_RET | mobi_drm_serialize_v2 (MOBIBuffer *buf, const MOBIData *m) |
| Serialize encryption scheme version 2. More...
|
|
MOBI_RET | mobi_drm_serialize_v1 (MOBIBuffer *buf, const MOBIData *m) |
| Serialize encryption scheme version 1. More...
|
|
MOBI_RET | mobi_drm_encrypt (MOBIData *m) |
| Encrypt document. More...
|
|
Functions to handle encryption.
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/
◆ 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] | out | Decrypted buffer |
[in] | in | Encrypted buffer |
[in] | length | Buffer length |
[in] | m | MOBIData structure with loaded key |
- Returns
- MOBI_RET status code (on success MOBI_SUCCESS)
◆ mobi_drm_serialize_v1()
Serialize encryption scheme version 1.
- Parameters
-
[in,out] | buf | Output buffer |
[in] | m | MOBIData structure with raw data and metadata |
- Returns
- MOBI_RET status code (on success MOBI_SUCCESS)
◆ mobi_drm_serialize_v2()
Serialize encryption scheme version 2.
- Parameters
-
[in,out] | buf | Output buffer |
[in] | m | MOBIData structure with raw data and metadata |
- Returns
- MOBI_RET status code (on success MOBI_SUCCESS)
◆ mobi_drmkey_delete()
Remove key from MOBIData structure.
- Parameters
-
[in,out] | m | MOBIData structure with raw data and metadata |
- Returns
- MOBI_RET status code (on success MOBI_SUCCESS)
◆ mobi_drmkey_set()
Store key for encryption in MOBIData stucture.
In case of encrypted document key is extracted from document. PID may be needed.
- Parameters
-
[in,out] | m | MOBIData structure with raw data and metadata |
[in] | pid | PID, 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()
Store key for encryption in MOBIData stucture. Pid will be calculated from device serial number.
- Parameters
-
[in,out] | m | MOBIData structure with raw data and metadata |
[in] | serial | Serial |
- Returns
- MOBI_RET status code (on success MOBI_SUCCESS)
◆ mobi_free_drm()
Free DRM structure.
- Parameters
-
[in,out] | m | MOBIData 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] | m | MOBIData structure with raw data and metadata |
[in] | serial | Device serial number |
[in] | valid_from | Voucher validity start time, -1 if not set |
[in] | valid_to | Voucher expire time, -1 if not set |
[in] | tamperkeys | Array of EXTH tags to include in PID generation, NULL if none |
[in] | tamperkeys_count | Count of EXTH tags |
- Returns
- MOBI_RET status code (on success MOBI_SUCCESS)