ndn-lite
Data Structures | Typedefs | Functions
data.h File Reference
#include "signature.h"
#include "metainfo.h"
#include "../security/ndn-lite-hmac.h"
#include "../security/ndn-lite-ecc.h"
#include "../security/ndn-lite-sha.h"
#include "../security/ndn-lite-aes.h"

Go to the source code of this file.

Data Structures

struct  ndn_data
 The structure to represent an NDN Data packet The best practice of using ndn_data_t is to first declare a ndn_data_t object and init each of its component to save memory. More...
 

Typedefs

typedef 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 declare a ndn_data_t object and init each of its component to save memory. More...
 

Functions

static void ndn_data_init (ndn_data_t *data)
 Init an Data packet. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
static int ndn_data_set_content (ndn_data_t *data, uint8_t *content_value, uint32_t content_size)
 Set the Data content. More...
 
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. More...
 
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. More...
 

Typedef Documentation

◆ ndn_data_t

typedef 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 declare a ndn_data_t object and init each of its component to save memory.

Function Documentation

◆ ndn_data_init()

static void ndn_data_init ( ndn_data_t data)
inlinestatic

Init an Data packet.

This function should be invoked whenever a new ndn_data_t is created.

Parameters
data.Output. The Data to be inited.

◆ ndn_data_parse_encrypted_content()

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.

The content payload will be decrypted with AES CBC without padding.

Parameters
data.Input. The data whose content will be set.
content_value.Output. The decrypted content buffer (Content Value only, no T(type) and L(length)).
content_used_size.Output. The size of the decrypted content buffer.
key_id.Output. The encryption key name.
aes_iv.Output. The IV used for AES decryption.
key.Input. The AES key used for AES decryption.
Returns
0 if there is no error.

◆ ndn_data_set_content()

static int ndn_data_set_content ( ndn_data_t data,
uint8_t *  content_value,
uint32_t  content_size 
)
inlinestatic

Set the Data content.

Parameters
data.Output. The data whose content will be set.
content_value.Input. The content buffer (Content Value only, no T(type) and L(length)).
content_size.Input. The size of the content buffer.
Returns
0 if there is no error.

◆ ndn_data_set_encrypted_content()

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.

The content payload will be encrypted with AES CBC without padding.

Parameters
data.Output. The data whose content will be set.
content_value.Input. The content buffer (Content Value only, no T(type) and L(length)).
content_size.Input. The size of the content buffer.
key_id.Input. The encryption key name.
aes_iv.Input. The IV used for AES encryption.
key.Input. The AES key used for AES encryption.
Returns
0 if there is no error.

◆ ndn_data_tlv_decode_digest_verify()

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.

Parameters
data.Output. The data to which the wired block will be decoded.
block_value.Input. The wire format Data buffer.
block_size.Input. The size of the wire format Data buffer.
Returns
0 if there is no error and the signature is valid.

◆ ndn_data_tlv_decode_ecdsa_verify()

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.

Parameters
data.Output. The data to which the wired block will be decoded.
block_value.Input. The wire format Data buffer.
block_size.Input. The size of the wire format Data buffer.
pub_key.Input. The ECC public key used to verify the Data signature.
Returns
0 if there is no error and the signature is valid.

◆ ndn_data_tlv_decode_hmac_verify()

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.

Parameters
data.Output. The data to which the wired block will be decoded.
block_value.Input. The wire format Data buffer.
block_size.Input. The size of the wire format Data buffer.
hmac_key.Input. The HMAC key used to verify the Data signature.
Returns
0 if there is no error and the signature is valid.

◆ ndn_data_tlv_decode_no_verify()

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.

Parameters
data.Output. The data to which the wired block will be decoded.
block_value.Input. The wire format Data buffer.
block_size.Input. The size of the wire format Data buffer.
Returns
0 if there is no error.

◆ ndn_data_tlv_encode_digest_sign()

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.

This function will automatically set signature info and signature value.

Parameters
encoderOutput. The encoder to keep the encoded Data. The encoder should be inited to proper output buffer.
dataInput. The data to be encoded.
Returns
0 if there is no error.

◆ ndn_data_tlv_encode_ecdsa_sign()

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.

This function will automatically set signature info and signature value.

Parameters
encoder.Output. The encoder to keep the encoded Data. The encoder should be inited to proper output buffer.
data.Input. The data to be encoded.
producer_identity.Input. The producer's identity name.
prv_key.Input. The private ECC key used to generate the signature.
Returns
0 if there is no error.

◆ ndn_data_tlv_encode_hmac_sign()

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.

This function will automatically set signature info and signature value.

Parameters
encoder.Output. The encoder to keep the encoded Data. The encoder should be inited to proper output buffer.
data.Input. The data to be encoded.
producer_identity.Input. The producer's identity name.
prv_key.Input. The HMAC key used to generate the signature.
Returns
0 if there is no error.