source: svn/newcon3bcm2_21bu/BSEAV/api/include/bsettop_crypto.h

Last change on this file was 76, checked in by megakiss, 10 years ago

1W 대기전력을 만족시키기 위하여 POWEROFF시 튜너를 Standby 상태로 함

  • Property svn:executable set to *
File size: 11.8 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2006-2007, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: bsettop_crypto.h $
11 * $brcm_Revision: 13 $
12 * $brcm_Date: 8/27/07 5:11p $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /BSEAV/api/include/bsettop_crypto.h $
19 *
20 * 13   8/27/07 5:11p vsilyaev
21 * PR 34353: Data structure change to allow the keyladder to be sourced
22 * correctly
23 *
24 * 12   8/22/07 5:26p jgarrett
25 * PR 31818: Adding external encryption algorithm support
26 *
27 * 11   7/19/07 12:23a vsilyaev
28 * PR 32275: Added 5-th level keys
29 *
30 * 10   6/28/07 2:19p vsilyaev
31 * PR 32275: Added hmac (keyed-hash message authentication code) operation
32 *
33 * 9   3/14/07 3:27p vsilyaev
34 * PR 26200: Changes in bcrypto configuration structures
35 *
36 * 8   11/28/06 1:23p mphillip
37 * PR26154: Enable hardware RSA for 7401
38 *
39 * 7   11/6/06 6:00p mphillip
40 * PR23943: Add counter mode
41 *
42 * 6   11/1/06 6:27p mphillip
43 * PR23943: First pass at adding CMAC support.  The current approach may
44 * change in the future if it doesn't work out correctly.
45 *
46 * 5   9/27/06 4:19p mphillip
47 * PR24607: Add extern statement
48 *
49 * 4   8/11/06 5:57p mphillip
50 * PR23573: Rename bcrypt_ to bcrypto_
51 *
52 * 3   8/3/06 11:09a mphillip
53 * PR19544: Correct the paramater for bcrypt_open
54 *
55 * 2   8/2/06 1:58p mphillip
56 * PR19544: Update bsettop_crypt.h to handle multiple calls to hashes, and
57 * fix a typo in bsettop_crypt.c
58 *
59 * 1   7/11/06 5:47p mphillip
60 * PR19544: Initial commit of bcrypt_ stubs
61 *
62 *
63 *
64 ***************************************************************************/
65
66#ifndef BSETTOP_CRYPTO_H__
67#define BSETTOP_CRYPTO_H__
68
69#ifdef __cplusplus
70extern "C"
71{
72#endif
73
74/*=*************************
75The crypto module provides access to cryptographic functionality.
76
77This is not the interface for controlling playback or record encryption or live conditional access.
78PVR encryption is handled through the bstream_mpeg.encryption structure passed in to
79bplayback_start.  Live conditional access (or playback of network-encrypted streams) is controlled
80through bstream_set_encryption.
81****************************/
82
83/*
84Summary:
85Cryptographic hardware selection
86Description:
87This controls how cryptography is performed.  When bcrypto_hardware_default is used, the bcrypto layer will choose
88whether to use a hardware or software implementation.  Other values will dictate a specific implementation.
89*/
90typedef enum bcrypto_hardware_ctrl {
91        bcrypto_hardware_default,       /* Use either a software or hardware implementation, bcrypto will choose */
92        bcrypto_hardware_none,          /* Use only a software implementation */
93        bcrypto_hardware_m2m,           /* Use only a mem-to-mem (M2M) implementation */
94        bcrypto_hardware_keyladder      /* Use the keyladder approach */
95} bcrypto_hardware_ctrl;
96
97/*
98Summary:
99Cryptographic operation selection
100Description:
101This controls what cryptographic operation should be performed.  Each algorithm supports only certain operations,
102so the bcrypto documentation should be consulted for specifics.
103*/
104typedef enum bcrypto_operation {
105        bcrypto_operation_encrypt,
106        bcrypto_operation_decrypt,
107        bcrypto_operation_sign,
108        bcrypto_operation_verify,
109        bcrypto_operation_hash,
110        bcrypto_operation_mac,
111        bcrypto_operation_hmac
112} bcrypto_operation;
113
114/*
115Summary:
116Description:
117*/
118typedef enum bcrypto_data_format {
119        bcrypto_data_format_raw,        /* Process all data */
120        bcrypto_data_format_ts,         /* Data will be processed in 188 byte packets, skipping the transport headers. */
121        bcrypto_data_format_dss         /* Data will be processed in 130 byte packets, skipping the transport headers. */
122} bcrypto_data_format;
123
124/*
125Summary:
126RSA 1024-bit key structure
127Description:
128A pointer to this structure should be used for long_key (see bencryption_params) to pass an RSA key.  In this case, bencryption_params.key_length will refer to the size of the struct (in bits, so sizeof(bcrypto_rsa_1024)*8), not the length of the key.  That will be in the first member variable of this struct.
129
130Not all values need to be filled in for all modes of operation.  For signing, n, and d are required.  For verifying, n and e are required.
131
132For software modes, dmp1, dmq1, and iqmp are also required.
133
134For 7401 hardware, p, q, dmp1, dmq1, and iqmp are not necessary.
135*/
136typedef struct bcrypto_rsa_1024 {
137        unsigned key_length;    /* Should be 1024 */
138        uint8_t n[128];         /* modulus */
139        uint8_t e[128];         /* public exponent */
140        uint8_t d[128];         /* private exponent */
141        uint8_t p[128];         /* first prime number */
142        uint8_t q[128];         /* second prime number */
143        uint8_t dmp1[128];      /* exponent corresponding to the first prime */
144        uint8_t dmq1[128];      /* exponent corresponding to the second prime */
145        uint8_t iqmp[128];      /* inverse of q mod p */
146} bcrypto_rsa_1024;
147
148/*
149Summary:
150RSA 2048-bit key structure
151Description:
152A pointer to this structure should be used for long_key (see bencryption_params) to pass an RSA key.  In this case, bencryption_params.key_length will refer to the size of the struct (in bits, so sizeof(bcrypto_rsa_2048)*8), not the length of the key.  That will be in the first member variable of this struct.
153
154Not all values need to be filled in for all modes of operation.  For signing, n, and d are required.  For verifying, n and e are required.
155
156For software modes, dmp1, dmq1, and iqmp are also required.
157
158For 7401 hardware, p, q, dmp1, dmq1, and iqmp are not necessary.
159*/
160typedef struct bcrypto_rsa_2048 {
161        unsigned key_length;    /* Should be 2048 */
162        uint8_t n[256];         /* modulus */
163        uint8_t e[256];         /* public exponent */
164        uint8_t d[256];         /* private exponent */
165        uint8_t p[256];         /* first prime number */
166        uint8_t q[256];         /* second prime number */
167        uint8_t dmp1[256];      /* exponent corresponding to the first prime */
168        uint8_t dmq1[256];      /* exponent corresponding to the second prime */
169        uint8_t iqmp[256];      /* inverse of q mod p */
170} bcrypto_rsa_2048;
171
172/*
173Summary:
174Keyladder input structure
175Description:
176This is part of bcrypto_keyladder_data.
177*/
178typedef enum bcrypto_swizzle {
179        bcrypto_swizzle_none,
180        bcrypto_swizzle_0,
181        bcrypto_swizzle_1
182} bcrypto_swizzle;
183 
184/*
185Summary:
186Keyladder input structure
187Description:
188This is part of bcrypto_keyladder_data.
189*/
190typedef enum bcrypto_keyladder_key {
191        bcrypto_keyladder_key_0,
192        bcrypto_keyladder_key_1,
193        bcrypto_keyladder_key_2,
194        bcrypto_keyladder_key_3,
195        bcrypto_keyladder_key_4,
196        bcrypto_keyladder_key_5
197} bcrypto_keyladder_key;
198 
199/*
200Summary:
201Keyladder input structure
202Description:
203This is part of bcrypto_keyladder_data.
204*/
205typedef enum bcrypto_keyladder_rootkey_src {
206        bcrypto_rootkey_cust_key,
207        bcrypto_rootkey_otp_a,
208        bcrypto_rootkey_otp_b,
209        bcrypto_rootkey_otp_c,
210        bcrypto_rootkey_reserved_0,
211        bcrypto_rootkey_reserved_1,
212        bcrypto_rootkey_reserved_2,
213        bcrypto_rootkey_invalid
214} bcrypto_keyladder_rootkey_src;
215
216/*
217Summary:
218Keyladder input structure
219Description:
220This is passed in as long_key when using keyladder.  Remember to set key_length to the size of this struct in bits (key_length = 8*sizeof(struct bcrypto_keyladder_data)).
221*/
222typedef struct bcrypto_keyladder_data {
223        bcrypto_swizzle swizzle;
224        bcrypto_keyladder_key keyladder_key;
225        uint8_t odd_in_3[24];
226        uint8_t even_in_3[24];
227        uint8_t odd_in_4[24];
228        uint8_t even_in_4[24];
229        uint8_t odd_in_5[24];
230        uint8_t even_in_5[24];
231        uint8_t key_cust_low;
232        uint8_t key_cust_high;
233        uint8_t key_var_low;
234        uint8_t key_var_high;
235        bcrypto_keyladder_rootkey_src rootkey_src;
236        bool use_cust_key_decrypt;
237        bool gen_key_decrypt; /* matches generateRouteKeyIO.bls3DESDecrypt, false unless instructed otherwise */
238} bcrypto_keyladder_data;
239
240/*
241Summary:
242External bcrypto algorithm input structure
243Description:
244This is passed in as long_key when using an external encryption algorithm.  Remember to set key_length to the size of this struct in bits (key_length = 8*sizeof(struct bcrypto_external_crypto_data)).
245
246When using an external algorithm with encrypted PVR, this is used to control the parameters.  All other encryption parameters are ignored, so it is up to the external algorithm to manage keys, state, and other data.
247*/
248typedef void (*bcrypto_external_callback)(void *context, void *buffer, long size);
249typedef struct bcrypto_external_crypto_data {
250        void *callback_context;
251        bcrypto_external_callback callback;
252} bcrypto_external_crypto_data;
253
254/*
255Summary:
256BCrypt settings structure
257Description:
258This structure controls the bcrypto settings.  It carries bencryption_params forward to control keys and algorithm choices.
259*/
260typedef struct bcrypto_settings {
261        bencryption_params      encryption;
262        bcrypto_operation       operation;      /* encrypt, decrypt, sign, verify, hash */
263                                                /* (formerly "bcypher_mode", changed to avoid confusion) */
264        bcrypto_data_format     data_format;    /* all, ts */
265        bcrypto_hardware_ctrl   hardware_ctrl;  /* any, software only, m2m only, keyladder only, etc. */
266        bool                            multiple_hashes;        /* allows hashing functions to occur one block at a time; requires an extra closing process call with in_buffer == NULL to close out the hash */
267} bcrypto_settings;
268
269/*
270Summary:
271BCrypt status structure
272Description:
273This returns information about the algorithm chosen.  It can be used to dynamically allocate output blocks, but it is
274strongly recommended that the bcrypto user know the algorithms already.
275
276If matching_output_size is set, then the output buffer for bcrypto_process needs to be the same size as the input buffer.
277
278If fixed_output_size is set, then the output buffer needs to be of a specific, fixed length, regardless of the size of the
279input buffer.
280*/
281typedef struct bcrypto_status_t {
282        bool    matching_output_size;   /* true for block ciphers, where the output block length should match the input block length */
283        bool    fixed_output_size;              /* true for hash, sign, and verify operations */
284        int             fixed_output_length;    /* if fixed_output_size is true, this holds the expected output size */
285} bcrypto_status_t;
286
287/*
288Summary:
289BCrypt structure
290Description:
291This is an opaque structure containing internal state for bcrypto operations.
292*/
293typedef struct bcrypto *bcrypto_t;
294
295/*
296Summary:
297BCrypt settings initialization
298Description:
299This function initializes settings to safe, default values.  The bcrypto user will still need to
300populate the structure with algorithm choices, keys, and any other necessary settings after this call.
301*/
302void bcrypto_settings_init(
303        bcrypto_settings        *settings
304);
305
306/*
307Summary:
308BCrypt open call
309Description:
310This creates a bcrypto object and populates it from the passed in bcrypto_settings.
311*/
312bcrypto_t bcrypto_open (
313        const bcrypto_settings  *settings
314);
315
316/*
317Summary:
318BCrypt status call
319Description:
320This retrieves status information about a current bcrypto session.  Its primary use is to find out
321algorithmic requirements.
322*/
323bresult bcrypto_status (
324        bcrypto_t       crypt,
325        bcrypto_status_t        *status
326);
327
328/*
329Summary:
330BCrypt process call
331Description:
332This processes a chunk of data and, where appropriate, returns the result.
333*/
334bresult bcrypto_process (
335        bcrypto_t       crypt,
336        uint8_t         *in_buffer,
337        unsigned long   in_buffer_length,
338        uint8_t         *out_buffer,
339        unsigned long   out_buffer_length
340);
341
342/*
343Summary:
344BCrypt close call
345Description:
346This closes out a bcrypto session.
347*/
348void bcrypto_close (
349        bcrypto_t       crypt
350);
351
352/*
353Summary:
354BCrypt m2m/dma memory allocation
355Description:
356This allocates a buffer suitable for use with m2m hardware encryption.
357
358This function is probably not suitable for here, and the m2m/dma support should probably be handled differently.
359*/
360uint8_t *bcrypto_alloc(
361        unsigned        buffer_length
362);
363
364/*
365Summary:
366BCrypt m2m/dma memory de-allocation
367Description:
368This frees a buffer suitable for use with m2m hardware encryption.
369
370This function is probably not suitable for here, and the m2m/dma support should probably be handled differently.
371*/
372void bcrypto_free(
373        uint8_t *buffer
374);
375
376#ifdef __cplusplus
377}
378#endif
379
380#endif /* BSETTOP_CRYPTO_H__ */
Note: See TracBrowser for help on using the repository browser.