NVIDIA DRIVE OS Linux API Reference

5.1.3.0 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ote_crypto.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2017, NVIDIA CORPORATION. All rights reserved
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining
5  * a copy of this software and associated documentation files
6  * (the "Software"), to deal in the Software without restriction,
7  * including without limitation the rights to use, copy, modify, merge,
8  * publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 
41 #ifndef __OTE_CRYPTO_H
42 #define __OTE_CRYPTO_H
43 
44 #include <service/ote_attrs.h>
45 
46 /* Crypto object/operation forward definition. */
47 struct __te_crypto_object;
48 typedef struct __te_crypto_object *te_crypto_object_t;
51 
53 typedef struct {
54  uint32_t algorithm;
55  uint32_t operation_class;
56  uint32_t mode;
57  uint32_t digest_length;
58  uint32_t key_size;
60  uint32_t handle_state;
62 
66  void *key;
67  void *iv;
68  size_t iv_len;
69  void *imp_obj;
70  te_error_t (*init)(te_crypto_operation_t operation);
71  te_error_t (*update)(te_crypto_operation_t operation,
72  const void *src_data,
73  size_t src_size,
74  void *dst_dat,
75  size_t *dst_size);
76  te_error_t (*do_final)(te_crypto_operation_t operation,
77  const void *srd_data,
78  size_t src_size,
79  void *dst_data,
80  size_t *dst_size);
81  te_error_t (*handle_req)(te_crypto_operation_t operation,
82  const void *src_data,
83  size_t src_size,
84  void *dst_data,
85  size_t *dst_size);
86  void (*free)(te_crypto_operation_t operation);
87 };
88 
90 typedef struct {
92  uint8_t *public_mod;
96  uint8_t *public_expo;
100  uint8_t *private_expo;
104  uint8_t *prime1;
108  uint8_t *prime2;
112  uint8_t *expo1;
116  uint8_t *expo2;
120  uint8_t *coeff;
124 
134 
145  uint32_t attr_count);
146 
153 
155 typedef enum {
156  OTE_ALG_AES_ECB_NOPAD = 0x10000010,
157  OTE_ALG_AES_CBC_NOPAD = 0x10000110,
158  OTE_ALG_AES_CTR = 0x10000210,
159  OTE_ALG_AES_CTS = 0x10000310,
160  OTE_ALG_AES_ECB = 0x10000510,
161  OTE_ALG_AES_CBC = 0x10000610,
162  OTE_ALG_AES_CBC_256 = 0x10000710,
164  OTE_ALG_AES_CMAC_128 = 0x20000110, /* AES-CBC w/ 128 bit key */
165  OTE_ALG_AES_CMAC_192 = 0x20000120, /* AES-CBC w/ 192 bit key */
166  OTE_ALG_AES_CMAC_256 = 0x20000130, /* AES-CBC w/ 256 bit key */
167  OTE_ALG_SHA_HMAC_224 = 0x20000210, /* HMAC w/ SHA224 */
168  OTE_ALG_SHA_HMAC_256 = 0x20000220, /* HMAC w/ SHA256 */
169  OTE_ALG_SHA_HMAC_384 = 0x20000230, /* HMAC w/ SHA384 */
170  OTE_ALG_SHA_HMAC_512 = 0x20000240, /* HMAC w/ SHA512 */
171  OTE_ALG_SHA_HMAC_1 = 0x20000250, /* HMAC w/ SHA1 */
172  OTE_ALG_RSA_PKCS_OAEP = 0x30000100,
173  OTE_ALG_RSA_PSS = 0x30000200,
174  OTE_ALG_PKCS1_Block1 = 0x30000300,
175  OTE_ALG_DRNG = 0x50000000, /* Deterministic RNG */
177 
178 
179 #define AES_BLOCK_SIZE 16
180 #define AES_ENCRYPTION_PADDED_SIZE(clearlen) \
181  ((((clearlen) + AES_BLOCK_SIZE) / AES_BLOCK_SIZE) * AES_BLOCK_SIZE)
182 
183 #define OTE_AES_MODE_NEEDS_PADDING(algo) \
184  (((algo) == OTE_ALG_AES_ECB) || ((algo) == OTE_ALG_AES_CBC) || \
185  ((algo) == OTE_ALG_AES_CBC_256))
186 
188 typedef enum {
196 
207 te_error_t te_allocate_operation(te_crypto_operation_t *oper,
208  te_oper_crypto_algo_t algorithm,
210 
220 te_error_t te_set_operation_key(te_crypto_operation_t oper,
221  te_crypto_object_t obj);
222 
232 te_error_t te_cipher_init(te_crypto_operation_t oper, void *iv,
233  size_t iv_size);
234 
250 te_error_t te_cipher_update(te_crypto_operation_t oper, const void *src_data,
251  size_t src_size, void *dst_data, size_t *dst_size);
252 
268 te_error_t te_cipher_do_final(te_crypto_operation_t oper, const void *src_data,
269  size_t src_len, void *dst_data, size_t *dst_len);
270 
277 te_error_t te_rsa_init(te_crypto_operation_t oper);
278 
286 te_error_t te_rsa_get_modulus_size(te_crypto_operation_t oper, size_t *modulus_size_bytes);
287 
302 te_error_t te_rsa_handle_request(te_crypto_operation_t oper,
303  const void *src_data, size_t src_size,
304  void *dst_data, size_t *dst_size);
305 
307 void te_free_operation(te_crypto_operation_t oper);
308 
309 #define HWRNG_CACHE_SIZE_BYTES 1024
310 #define HWRNG_CACHE_ENTROPY_SIZE_BYTES 256
311 
312 /* The hwrng cache is structured as follows:
313  * [ Randomness available to TAs | Entropy for Crypto Libraries ]
314  * <-HWRNG_CACHE_ENTROPY_SIZE_BYTES->
315  * <-----------------HWRNG_CACHE_SIZE_BYTES------------------------->
316  */
317 
318 /*
319  * @brief Cache to store random numbers generated by the HW.
320  * @cache Buffer to hold random data
321  * @size Overall Size of the Buffer
322  * @entropy_size Reserved Size to seed Entropy in a s/w crypto library
323  * @bytes_available Number of Bytes available in the cache
324  */
325 struct hwrng_cache {
326  uint8_t *cache;
327  size_t size;
328  size_t entropy_size;
330 };
331 
337 void te_generate_random(void *buffer, size_t size);
338 
351 
370  te_oper_crypto_algo_t algo, unsigned char *key,
371  unsigned int keysize,
372  unsigned char *iv, unsigned int ivsize,
373  unsigned char *in, unsigned int insize,
374  unsigned char *out, unsigned int *outsize);
375 
378 #endif
void(* free)(te_crypto_operation_t operation)
Definition: ote_crypto.h:86
size_t size
Definition: ote_crypto.h:327
te_error_t(* init)(te_crypto_operation_t operation)
Definition: ote_crypto.h:70
int expo1_len
Holds expo1 length in bytes.
Definition: ote_crypto.h:114
int public_expo_len
Holds public exponent length in bytes.
Definition: ote_crypto.h:98
uint8_t * expo1
Holds d mod (p-1).
Definition: ote_crypto.h:112
uint8_t * prime1
Holds secret prime factor.
Definition: ote_crypto.h:104
te_error_t te_allocate_operation(te_crypto_operation_t *oper, te_oper_crypto_algo_t algorithm, te_oper_crypto_algo_mode_t mode)
Allocates memory for crypto operation.
void te_free_object(te_crypto_object_t obj)
Frees allocated memory within crypto object.
Holds a crypto operation info object.
Definition: ote_crypto.h:53
Internal data structure for te_crypto_operation_t.
Definition: ote_crypto.h:64
int expo2_len
Holds expo2 length in bytes.
Definition: ote_crypto.h:118
int prime2_len
Holds prime2 length in bytes.
Definition: ote_crypto.h:110
te_error_t te_set_operation_key(te_crypto_operation_t oper, te_crypto_object_t obj)
Allocates memory in the crypto operation and copies the key from the crypto object to the operation o...
te_oper_crypto_algo_t
Defines algorithm types.
Definition: ote_crypto.h:155
te_error_t(* do_final)(te_crypto_operation_t operation, const void *srd_data, size_t src_size, void *dst_data, size_t *dst_size)
Definition: ote_crypto.h:76
uint8_t * public_mod
Holds public modulus.
Definition: ote_crypto.h:92
te_error_t te_rsa_get_modulus_size(te_crypto_operation_t oper, size_t *modulus_size_bytes)
Returns the RSA modulus size in bytes.
te_attribute_id_t
Defines attribute ID types.
Definition: ote_attrs.h:50
te_error_t(* handle_req)(te_crypto_operation_t operation, const void *src_data, size_t src_size, void *dst_data, size_t *dst_size)
Definition: ote_crypto.h:81
uint8_t * coeff
Holds q^-1 mod p.
Definition: ote_crypto.h:120
te_error_t te_allocate_object(te_crypto_object_t *obj)
Allocates memory for a te_crypto_object_t.
int prime1_len
Holds prime1 length in bytes.
Definition: ote_crypto.h:106
size_t bytes_available
Definition: ote_crypto.h:329
uint8_t * public_expo
Holds public exponent.
Definition: ote_crypto.h:96
size_t entropy_size
Definition: ote_crypto.h:328
te_error_t te_get_attribute_by_id(te_crypto_object_t object, te_attribute_id_t id, te_attribute_t **ret)
Finds the first attribute in the crypto object that matches ID.
te_error_t te_rsa_init(te_crypto_operation_t oper)
Initializes the RSA operation.
int coeff_len
Holds the coefficient length in bytes.
Definition: ote_crypto.h:122
te_error_t te_cipher_do_final(te_crypto_operation_t oper, const void *src_data, size_t src_len, void *dst_data, size_t *dst_len)
Calls operation do_final with supplied parameters.
te_error_t te_populate_object(te_crypto_object_t obj, te_attribute_t *attrs, uint32_t attr_count)
Populates crypto object from a list of attributes.
te_crypto_operation_info_t info
Definition: ote_crypto.h:65
te_oper_crypto_algo_mode_t
Defines algrorithm modes.
Definition: ote_crypto.h:188
void te_generate_random(void *buffer, size_t size)
Generates random data.
uint8_t * private_expo
Holds private exponent.
Definition: ote_crypto.h:100
struct __te_crypto_operation_t * te_crypto_operation_t
Definition: ote_crypto.h:50
te_error_t te_cipher_update(te_crypto_operation_t oper, const void *src_data, size_t src_size, void *dst_data, size_t *dst_size)
Updates the cipher by calling the operation update function with the supplied parameters.
te_error_t(* update)(te_crypto_operation_t operation, const void *src_data, size_t src_size, void *dst_dat, size_t *dst_size)
Definition: ote_crypto.h:71
Defines attribute object internals.
Definition: ote_attrs.h:82
te_error_t te_cipher_init(te_crypto_operation_t oper, void *iv, size_t iv_size)
Initializes the operation cipher.
te_error_t te_crypt_data(te_oper_crypto_algo_mode_t mode, te_oper_crypto_algo_t algo, unsigned char *key, unsigned int keysize, unsigned char *iv, unsigned int ivsize, unsigned char *in, unsigned int insize, unsigned char *out, unsigned int *outsize)
Crypto wrapper around software crypto library.
uint8_t * cache
Definition: ote_crypto.h:326
te_error_t te_rsa_handle_request(te_crypto_operation_t oper, const void *src_data, size_t src_size, void *dst_data, size_t *dst_size)
Executes the specified RSA operations.
int private_expo_len
Holds private exponent length in bytes.
Definition: ote_crypto.h:102
int public_mod_len
Holds public modulus length in bytes.
Definition: ote_crypto.h:94
te_error_t
Defines Open Trusted Environment (OTE) error codes.
Definition: ote_error.h:45
Holds internal data for RSA keys.
Definition: ote_crypto.h:90
uint8_t * expo2
Holds d mod (q-1).
Definition: ote_crypto.h:116
struct __te_crypto_object * te_crypto_object_t
Definition: ote_crypto.h:48
void te_free_operation(te_crypto_operation_t oper)
Frees operation internal memory.
NVIDIA Trusted Little Kernel Interface: Service Attributes
uint8_t * prime2
Holds secret prime factor.
Definition: ote_crypto.h:108