ndn-lite
Functions
data.c File Reference
#include "data.h"
#include "../security/ndn-lite-hmac.h"
#include "../security/ndn-lite-sha.h"
#include "../security/ndn-lite-aes.h"
#include "../security/ndn-lite-ecc.h"
#include "encoder.h"
#include "../ndn-error-code.h"

Functions

static int _ndn_data_prepare_unsigned_block (ndn_encoder_t *encoder, const ndn_data_t *data)
 
static void _prepare_signature_info (ndn_data_t *data, uint8_t signature_type, const ndn_name_t *producer_identity, uint32_t key_id)
 
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...
 
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...
 

Function Documentation

◆ _ndn_data_prepare_unsigned_block()

static int _ndn_data_prepare_unsigned_block ( ndn_encoder_t encoder,
const ndn_data_t data 
)
static

◆ _prepare_signature_info()

static void _prepare_signature_info ( ndn_data_t data,
uint8_t  signature_type,
const ndn_name_t producer_identity,
uint32_t  key_id 
)
static

◆ 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_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.