Embedded SDK
Embedded SDK
lcx_ripemd160.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 
27 #ifndef LCX_RIPEMD160_H
28 #define LCX_RIPEMD160_H
29 
30 #ifdef HAVE_RIPEMD160
31 
32 #include "lcx_wrappers.h"
33 #include "lcx_hash.h"
34 
36 #define CX_RIPEMD160_SIZE 20
37 
41 struct cx_ripemd160_s {
42  struct cx_hash_header_s header;
43  size_t blen;
44  uint8_t block[64];
45  // After finishing the digest,
46  // contains the digest if correct
47  // parameters are passed.
48  uint8_t acc[5 * 4];
49 };
51 typedef struct cx_ripemd160_s cx_ripemd160_t;
52 
62 WARN_UNUSED_RESULT cx_err_t cx_ripemd160_init_no_throw(cx_ripemd160_t *hash);
63 
72 static inline int cx_ripemd160_init(cx_ripemd160_t *hash)
73 {
74 #pragma GCC diagnostic push
75 #pragma GCC diagnostic ignored "-Wunused-result"
76  cx_ripemd160_init_no_throw(hash);
77 #pragma GCC diagnostic pop
78  return CX_RIPEMD160;
79 }
80 
93 cx_err_t cx_ripemd160_hash_iovec(const cx_iovec_t *iovec,
94  size_t iovec_len,
95  uint8_t digest[static CX_RIPEMD160_SIZE]);
96 
109 static inline cx_err_t cx_ripemd160_hash(const uint8_t *in,
110  size_t in_len,
111  uint8_t digest[static CX_RIPEMD160_SIZE])
112 {
113  const cx_iovec_t iovec = {.iov_base = in, .iov_len = in_len};
114 
115  return cx_ripemd160_hash_iovec(&iovec, 1, digest);
116 }
117 
131 size_t cx_hash_ripemd160(const uint8_t *in, size_t in_len, uint8_t *out, size_t out_len);
132 
133 #endif // HAVE_RIPEMD160
134 
135 #endif // LCX_RIPEMD160_H
Hash functions.
Similar to libc iovec type.
Definition: lcx_common.h:66
const uint8_t * iov_base
Definition: lcx_common.h:67
unsigned char uint8_t
Definition: usbd_conf.h:53