ndn-lite
data.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) Zhiyi Zhang
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  * See AUTHORS.md for complete list of NDN IOT PKG authors and contributors.
9  */
10 
11 #ifndef NDN_ENCODING_DATA_H
12 #define NDN_ENCODING_DATA_H
13 
14 #include "signature.h"
15 #include "metainfo.h"
16 #include "../security/ndn-lite-hmac.h"
17 #include "../security/ndn-lite-ecc.h"
18 #include "../security/ndn-lite-sha.h"
19 #include "../security/ndn-lite-aes.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
30 typedef struct ndn_data {
46  uint32_t content_size;
53 } ndn_data_t;
54 
55 
62 static inline void
64 {
66 }
67 
76 int
78 
89 int
91  const ndn_name_t* producer_identity, const ndn_ecc_prv_t* prv_key);
92 
103 int
105  const ndn_name_t* producer_identity, const ndn_hmac_key_t* hmac_key);
106 
114 int
115 ndn_data_tlv_decode_no_verify(ndn_data_t* data, const uint8_t* block_value, uint32_t block_size);
116 
124 int
125 ndn_data_tlv_decode_digest_verify(ndn_data_t* data, const uint8_t* block_value, uint32_t block_size);
126 
135 int
136 ndn_data_tlv_decode_ecdsa_verify(ndn_data_t* data, const uint8_t* block_value, uint32_t block_size,
137  const ndn_ecc_pub_t* pub_key);
138 
147 int
148 ndn_data_tlv_decode_hmac_verify(ndn_data_t* data, const uint8_t* block_value, uint32_t block_size,
149  const ndn_hmac_key_t* hmac_key);
150 
158 static inline int
159 ndn_data_set_content(ndn_data_t* data, uint8_t* content_value, uint32_t content_size)
160 {
161  if (content_size <= NDN_CONTENT_BUFFER_SIZE) {
162  memcpy(data->content_value, content_value, content_size);
163  data->content_size = content_size;
164  return 0;
165  }else{
166  return NDN_OVERSIZE;
167  }
168 }
169 
181 int
183  const uint8_t* content_value, uint32_t content_size,
184  const ndn_name_t* key_id, const uint8_t* aes_iv,
185  const ndn_aes_key_t* key);
186 
199 int
201  uint8_t* content_value, uint32_t* content_used_size,
202  ndn_name_t* key_id, uint8_t* aes_iv, const ndn_aes_key_t* key);
203 
204 #ifdef __cplusplus
205 }
206 #endif
207 
208 #endif // NDN_ENCODING_DATA_H
ndn_signature_t signature
Data Signature.
Definition: data.h:52
int ndn_data_tlv_encode_ecdsa_sign(ndn_encoder_t *encoder, ndn_data_t *data, const ndn_name_t *producer_identity, const ndn_ecc_prv_t *prv_key)
Use ECDSA Algorithm to sign the Data and encode the Data into wire format.
Definition: data.c:128
The structure to keep a HMAC key.
Definition: ndn-lite-hmac.h:65
int ndn_data_parse_encrypted_content(const ndn_data_t *data, uint8_t *content_value, uint32_t *content_used_size, ndn_name_t *key_id, uint8_t *aes_iv, const ndn_aes_key_t *key)
Parse the Data encrypted content and get the decrypted content.
Definition: data.c:589
int ndn_data_tlv_encode_digest_sign(ndn_encoder_t *encoder, ndn_data_t *data)
Use Digest (SHA256) to sign the Data and encode the Data into wire format.
Definition: data.c:80
The structure to represent an NDN Data packet The best practice of using ndn_data_t is to first decla...
Definition: data.h:30
int ndn_data_tlv_decode_hmac_verify(ndn_data_t *data, const uint8_t *block_value, uint32_t block_size, const ndn_hmac_key_t *hmac_key)
Decode the encoded Data into a ndn_data_t and verify the HMAC signature.
Definition: data.c:463
int ndn_data_tlv_encode_hmac_sign(ndn_encoder_t *encoder, ndn_data_t *data, const ndn_name_t *producer_identity, const ndn_hmac_key_t *hmac_key)
Use HMAC Algorithm to sign the Data and encode the Data into wire format.
Definition: data.c:215
The structure to keep an ECC private key.
Definition: ndn-lite-ecc.h:86
int ndn_data_tlv_decode_ecdsa_verify(ndn_data_t *data, const uint8_t *block_value, uint32_t block_size, const ndn_ecc_pub_t *pub_key)
Decode the encoded Data into a ndn_data_t and verify the ECDSA signature.
Definition: data.c:393
int ndn_data_set_encrypted_content(ndn_data_t *data, const uint8_t *content_value, uint32_t content_size, const ndn_name_t *key_id, const uint8_t *aes_iv, const ndn_aes_key_t *key)
Set the Data content with the encrypted content.
Definition: data.c:533
#define NDN_CONTENT_BUFFER_SIZE
Definition: ndn-constants.h:33
uint8_t content_value[NDN_CONTENT_BUFFER_SIZE]
Data Content Value (not including T and L)
Definition: data.h:42
ndn_metainfo_t metainfo
Data MetaInfo Value (not including T and L)
Definition: data.h:38
The structure to represent the Name.
Definition: name.h:24
The structure to keep an AES-128 key.
Definition: ndn-lite-aes.h:56
static void ndn_data_init(ndn_data_t *data)
Init an Data packet.
Definition: data.h:63
The structure to represent the Signature.
Definition: signature.h:38
The structure to represent the Metainfo structure.
Definition: metainfo.h:21
static void ndn_metainfo_init(ndn_metainfo_t *meta)
Init a Metainfo structure.
Definition: metainfo.h:45
static int ndn_data_set_content(ndn_data_t *data, uint8_t *content_value, uint32_t content_size)
Set the Data content.
Definition: data.h:159
ndn_name_t name
Data Name Value (not including T and L)
Definition: data.h:34
uint32_t content_size
Data MetaInfo Content Value Size.
Definition: data.h:46
struct ndn_data ndn_data_t
The structure to represent an NDN Data packet The best practice of using ndn_data_t is to first decla...
#define NDN_OVERSIZE
The object given is larger than expected.
Definition: ndn-error-code.h:33
The structure to keep the state when doing NDN TLV encoding.
Definition: encoder.h:31
int ndn_data_tlv_decode_digest_verify(ndn_data_t *data, const uint8_t *block_value, uint32_t block_size)
Decode the encoded Data into a ndn_data_t and verify the Digest (SHA256) signature.
Definition: data.c:325
The structure to keep an ECC public key.
Definition: ndn-lite-ecc.h:71
int ndn_data_tlv_decode_no_verify(ndn_data_t *data, const uint8_t *block_value, uint32_t block_size)
Simply decode the encoded Data into a ndn_data_t without signature verification.
Definition: data.c:263