Embedded SDK
Embedded SDK
lcx_rng.h
Go to the documentation of this file.
1 
2 /*******************************************************************************
3  * Ledger Nano S - Secure firmware
4  * (c) 2022 Ledger
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  ********************************************************************************/
18 
28 #ifndef LCX_RNG_H
29 #define LCX_RNG_H
30 
31 #ifdef HAVE_RNG
32 
33 #include "lcx_wrappers.h"
34 #include "lcx_hash.h"
35 
45 void cx_rng_no_throw(uint8_t *buffer, size_t len);
46 
58 static inline unsigned char *cx_rng(uint8_t *buffer, size_t len)
59 {
60  cx_rng_no_throw(buffer, len);
61  return buffer;
62 }
63 
69 static inline uint32_t cx_rng_u32(void)
70 {
71  uint32_t r;
72  cx_rng_no_throw((uint8_t *) &r, sizeof(uint32_t));
73  return r;
74 }
75 
81 static inline uint8_t cx_rng_u8(void)
82 {
83  uint8_t r;
84  cx_rng_no_throw((uint8_t *) &r, sizeof(uint8_t));
85  return r;
86 }
87 
88 typedef uint32_t (*cx_rng_u32_range_randfunc_t)(void);
89 
105 uint32_t cx_rng_u32_range_func(uint32_t a, uint32_t b, cx_rng_u32_range_randfunc_t randfunc);
106 
119 static inline uint32_t cx_rng_u32_range(uint32_t a, uint32_t b)
120 {
121  return cx_rng_u32_range_func(a, b, cx_rng_u32);
122 }
123 
150 WARN_UNUSED_RESULT cx_err_t cx_rng_rfc6979(cx_md_t hash_id,
151  const uint8_t *x,
152  size_t x_len,
153  const uint8_t *h1,
154  size_t h1_len,
155  const uint8_t *q,
156  size_t q_len,
157  uint8_t *out,
158  size_t out_len);
159 
160 #endif // HAVE_RNG
161 
162 #endif // LCX_RNG_H
Hash functions.
unsigned char uint8_t
Definition: usbd_conf.h:53