Embedded SDK
Embedded SDK
cx_rng_rfc6979.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 
19 #ifndef CX_RNG_RFC6979_H
20 #define CX_RNG_RFC6979_H
21 
22 #ifdef HAVE_RNG_RFC6979
23 
24 #include "libcxng.h"
25 #include "cx_hash.h"
26 #include <stddef.h>
27 #include <stdint.h>
28 
29 #define CX_RFC6979_BUFFER_LENGTH 64
30 #define CX_RFC6979_MAX_RLEN 66
31 
32 typedef struct {
33  uint8_t v[CX_RFC6979_BUFFER_LENGTH + 1];
34  uint8_t k[CX_RFC6979_BUFFER_LENGTH];
35  uint8_t q[CX_RFC6979_MAX_RLEN];
36  uint32_t q_len;
37  uint32_t r_len;
38  uint8_t tmp[CX_RFC6979_MAX_RLEN];
39  cx_md_t hash_id;
40  size_t md_len;
41 
42  union {
43 #if (!defined(HAVE_SHA512) && !defined(HAVE_SHA384) && !defined(HAVE_SHA256) \
44  && !defined(HAVE_SHA224)) \
45  || !defined(HAVE_HMAC)
46 #error No hmac defined for rfc6979 support
47 #endif
48 
49  cx_hmac_t hmac;
50 
51 #if defined(HAVE_SHA512) || defined(HAVE_SHA384)
52  cx_hmac_sha512_t hmac_sha512;
53 #endif
54 
55 #if defined(HAVE_SHA256) || defined(HAVE_SHA224)
56  cx_hmac_sha256_t hmac_sha256;
57 #endif
58  };
59 } cx_rnd_rfc6979_ctx_t;
60 
61 WARN_UNUSED_RESULT cx_err_t cx_rng_rfc6979_init(
62  cx_rnd_rfc6979_ctx_t *rfc_ctx,
63  cx_md_t hash_id,
64  const uint8_t *x,
65  size_t x_len,
66  const uint8_t *h1,
67  size_t h1_len,
68  const uint8_t *q,
69  size_t q_len
70  /*const uint8_t *additional_input, size_t additional_input_len*/);
71 
72 WARN_UNUSED_RESULT cx_err_t cx_rng_rfc6979_next(cx_rnd_rfc6979_ctx_t *rfc_ctx,
73  uint8_t *out,
74  size_t out_len);
75 
76 #endif // HAVE_RNG_RFC6979
77 
78 #endif // CX_RNG_RFC6979_H
Include cryptography files.
unsigned char uint8_t
Definition: usbd_conf.h:53