ndn-lite
ndn-lite-sha.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 - 2019 Zhiyi Zhang, Tianyuan Yu
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v3.0. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #ifndef NDN_SECURITY_SHA_H_
10 #define NDN_SECURITY_SHA_H_
11 
12 #include "ndn-lite-sec-config.h"
13 #include "../ndn-error-code.h"
14 #include "../ndn-constants.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
24 
29 typedef int (*ndn_sha256_update_impl)(abstract_sha256_state_t* state, const uint8_t* data, uint32_t datalen);
30 typedef int (*ndn_sha256_finish_impl)(abstract_sha256_state_t* state, uint8_t* hash_result);
31 
35 typedef struct ndn_sha_backend {
40 
41 
45 typedef struct ndn_sha256_state {
47 
49 
52 
53 
59 int
61 
62 /*
63  * SHA256 update procedure. Hashes datalen bytes addressed by data into state
64  * @note Assumes state has been initialized
65  * @param state. Input. SHA256 state struct.
66  * @param data. Input. message to hash.
67  * @param datalen. Input. length of message to hash.
68  * @return NDN_SUCCESS (0) if there is no error.
69  */
70 int
71 ndn_sha256_update(ndn_sha256_state_t* state, const uint8_t* data, uint32_t datalen);
72 
79 int
80 ndn_sha256_finish(ndn_sha256_state_t* state, uint8_t* hash_result);
81 
89 int
90 ndn_sha256(const uint8_t* data, uint32_t datalen, uint8_t* hash_result);
91 
102 int
103 ndn_sha256_sign(const uint8_t* input_value, uint32_t input_size,
104  uint8_t* output_value, uint32_t output_max_size,
105  uint32_t* output_used_size);
106 
115 int
116 ndn_sha256_verify(const uint8_t* input_value, uint32_t input_size,
117  const uint8_t* sig_value, uint32_t sig_size);
118 
119 #ifdef __cplusplus
120 }
121 #endif
122 
123 #endif // NDN_SECURITY_AES_H_
abstract_sha256_state_t abs_state
Definition: ndn-lite-sha.h:46
int(* ndn_sha256_init_impl)(abstract_sha256_state_t *state)
The APIs that are supposed to be implemented by the backend.
Definition: ndn-lite-sha.h:28
int ndn_sha256_update(ndn_sha256_state_t *state, const uint8_t *data, uint32_t datalen)
Definition: ndn-lite-sha.c:28
struct ndn_sha256_state ndn_sha256_state_t
The structure to represent the SHA256 hash state.
struct ndn_sha_backend ndn_sha_backend_t
The structure to represent the backend implementation.
int ndn_sha256(const uint8_t *data, uint32_t datalen, uint8_t *hash_result)
SHA256 a series of bytes into the result.
Definition: ndn-lite-sha.c:40
int(* ndn_sha256_update_impl)(abstract_sha256_state_t *state, const uint8_t *data, uint32_t datalen)
Definition: ndn-lite-sha.h:29
ndn_sha256_update_impl sha256_update
Definition: ndn-lite-sha.h:37
int ndn_sha256_verify(const uint8_t *input_value, uint32_t input_size, const uint8_t *sig_value, uint32_t sig_size)
Verify a SHA-256 signature.
Definition: ndn-lite-sha.c:67
int ndn_sha256_init(ndn_sha256_state_t *state)
SHA256 initialization procedure.
Definition: ndn-lite-sha.c:22
int ndn_sha256_finish(ndn_sha256_state_t *state, uint8_t *hash_result)
SHA256 final procedure.
Definition: ndn-lite-sha.c:34
ndn_sha_backend_t * ndn_sha_get_backend(void)
Definition: ndn-lite-sha.c:16
The structure to represent the backend implementation.
Definition: ndn-lite-sha.h:35
int ndn_sha256_sign(const uint8_t *input_value, uint32_t input_size, uint8_t *output_value, uint32_t output_max_size, uint32_t *output_used_size)
Sign a buffer using SHA-256 algorithm.
Definition: ndn-lite-sha.c:53
ndn_sha256_finish_impl sha256_finish
Definition: ndn-lite-sha.h:38
ndn_sha256_init_impl sha256_init
Definition: ndn-lite-sha.h:36
int(* ndn_sha256_finish_impl)(abstract_sha256_state_t *state, uint8_t *hash_result)
Definition: ndn-lite-sha.h:30
Definition: ndn-lite-default-sha-impl.h:16
The structure to represent the SHA256 hash state.
Definition: ndn-lite-sha.h:45