GNUnet 0.28.0-dev.3-20-gf1136b0b8
 
Loading...
Searching...
No Matches
gnsrecord_crypto.c File Reference

API for GNS record-related crypto. More...

#include "platform.h"
#include "gnsrecord_crypto.h"
Include dependency graph for gnsrecord_crypto.c:

Go to the source code of this file.

Data Structures

struct  KeyCacheLine
 Line in cache mapping private keys to public keys. More...
 
struct  EncryptionContextData
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "gnsrecord", __VA_ARGS__)
 
#define CSIZE   64
 

Functions

void GNR_derive_block_aes_key (unsigned char *ctr, unsigned char *key, const char *label, uint64_t exp, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
 We disable deprecation warnings because we implement RFC9408/LSD0001 record types here.
 
void GNR_derive_block_xsalsa_key (struct GNUNET_CRYPTO_XSalsa20Nonce *nonce, struct GNUNET_CRYPTO_XSalsa20SecretKey *key, const char *label, uint64_t exp, const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
 Derive session key and iv from label and public key.
 
static enum GNUNET_GenericReturnValue block_sign_ecdsa (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey, const char *label, struct GNUNET_GNSRECORD_Block *block)
 
static enum GNUNET_GenericReturnValue block_sign_eddsa (const struct GNUNET_CRYPTO_EddsaPrivateKey *key, const struct GNUNET_CRYPTO_EddsaPublicKey *pkey, const char *label, struct GNUNET_GNSRECORD_Block *block)
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_sign (const struct GNUNET_CRYPTO_BlindablePrivateKey *key, const char *label, struct GNUNET_GNSRECORD_Block *block)
 Sign a block create with GNUNET_GNSRECORD_block_create_unsigned.
 
static enum GNUNET_GenericReturnValue block_create_ecdsa (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey, struct GNUNET_TIME_Absolute expire, const char *label, const unsigned char *rdata, size_t rdata_len, struct GNUNET_GNSRECORD_Block **block, int sign)
 Sign name and records.
 
static enum GNUNET_GenericReturnValue block_create_eddsa (const struct GNUNET_CRYPTO_EddsaPrivateKey *key, const struct GNUNET_CRYPTO_EddsaPublicKey *pkey, struct GNUNET_TIME_Absolute expire, const char *label, const unsigned char *rdata, size_t rdata_len, struct GNUNET_GNSRECORD_Block **block, int sign)
 Sign name and records (EDDSA version)
 
static enum GNUNET_GenericReturnValue block_create2 (const struct GNUNET_CRYPTO_BlindablePrivateKey *pkey, struct GNUNET_TIME_Absolute expire, const char *label, const unsigned char *rdata, size_t rdata_len, struct GNUNET_GNSRECORD_Block **result, int sign)
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block)
 Check if a signature is valid.
 
static enum GNUNET_GenericReturnValue block_decrypt_ecdsa (const struct GNUNET_GNSRECORD_Block *block, const struct GNUNET_CRYPTO_EcdsaPublicKey *zone_key, const char *label, GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls)
 
static enum GNUNET_GenericReturnValue block_decrypt_eddsa (const struct GNUNET_GNSRECORD_Block *block, const struct GNUNET_CRYPTO_EddsaPublicKey *zone_key, const char *label, GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls)
 
void GNUNET_GNSRECORD_query_from_private_key (const struct GNUNET_CRYPTO_BlindablePrivateKey *zone, const char *label, struct GNUNET_HashCode *query)
 Calculate the DHT query for a given label in a given zone.
 
void GNUNET_GNSRECORD_query_from_public_key (const struct GNUNET_CRYPTO_BlindablePublicKey *pub, const char *label, struct GNUNET_HashCode *query)
 Calculate the DHT query for a given label in a given zone.
 
static enum GNUNET_GenericReturnValue block_open_ecdsa (void *cls, const char *label, const struct GNUNET_GNSRECORD_Block *block, GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls)
 
static enum GNUNET_GenericReturnValue block_open_eddsa (void *cls, const char *label, const struct GNUNET_GNSRECORD_Block *block, GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls)
 
static enum GNUNET_GenericReturnValue block_seal_not_implemented (void *cls, const char *label, struct GNUNET_TIME_Absolute expire, unsigned char *rdata, size_t rdata_len, struct GNUNET_GNSRECORD_Block **result)
 
static enum GNUNET_GenericReturnValue block_seal (void *cls, const char *label, struct GNUNET_TIME_Absolute expire, unsigned char *rdata, size_t rdata_len, struct GNUNET_GNSRECORD_Block **result)
 
struct GNUNET_GNSRECORD_EncryptionContextGNUNET_GNSRECORD_encryption_context_setup_owner (const struct GNUNET_CRYPTO_BlindablePrivateKey *sk)
 Create a new encryption context for the zone owner.
 
struct GNUNET_GNSRECORD_EncryptionContextGNUNET_GNSRECORD_encryption_context_setup_resolver (const struct GNUNET_CRYPTO_BlindablePublicKey *zkey)
 Create a new encryption context for a resolver.
 
void GNUNET_GNSRECORD_encryption_context_destroy (struct GNUNET_GNSRECORD_EncryptionContext *ec)
 Cleanup and free the encryption context.
 
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block, const struct GNUNET_CRYPTO_BlindablePublicKey *zone_key, const char *label, GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls)
 Decrypt block.
 

Detailed Description

API for GNS record-related crypto.

Author
Martin Schanzenbach
Matthias Wachs
Christian Grothoff

Definition in file gnsrecord_crypto.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "gnsrecord", __VA_ARGS__)

Definition at line 31 of file gnsrecord_crypto.c.

◆ CSIZE

#define CSIZE   64

Function Documentation

◆ GNR_derive_block_aes_key()

void GNR_derive_block_aes_key ( unsigned char *  ctr,
unsigned char *  key,
const char *  label,
uint64_t  exp,
const struct GNUNET_CRYPTO_EcdsaPublicKey pub 
)

We disable deprecation warnings because we implement RFC9408/LSD0001 record types here.

Derive session key and iv from label and public key.

We may eventually stop doing that, however!

4 byte nonce

Expiration time 64 bit.

Set counter part to 1

Definition at line 41 of file gnsrecord_crypto.c.

46{
47 static const char ctx_key[] = "gns-aes-ctx-key";
48 static const char ctx_iv[] = "gns-aes-ctx-iv";
49
51 ctx_key, strlen (ctx_key),
52 pub, sizeof(struct
55 memset (ctr, 0, GNUNET_CRYPTO_AES_KEY_LENGTH / 2);
58 ctx_iv, strlen (ctx_iv),
59 pub, sizeof(struct
63 memcpy (ctr + 4, &exp, sizeof (exp));
65 ctr[15] |= 0x01;
66}
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_CRYPTO_EddsaPublicKey pub
#define GNUNET_CRYPTO_hkdf_gnunet(result, out_len, xts, xts_len, skm, skm_len,...)
A peculiar HKDF instantiation that tried to mimic Truncated NMAC.
#define GNUNET_CRYPTO_kdf_arg_string(d)
#define GNUNET_CRYPTO_AES_KEY_LENGTH
length of the sessionkey in bytes
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...

References GNUNET_CRYPTO_AES_KEY_LENGTH, GNUNET_CRYPTO_hkdf_gnunet, GNUNET_CRYPTO_kdf_arg_string, key, and pub.

Referenced by block_create_ecdsa(), block_decrypt_ecdsa(), and run_pkey().

Here is the caller graph for this function:

◆ GNR_derive_block_xsalsa_key()

void GNR_derive_block_xsalsa_key ( struct GNUNET_CRYPTO_XSalsa20Nonce nonce,
struct GNUNET_CRYPTO_XSalsa20SecretKey key,
const char *  label,
uint64_t  exp,
const struct GNUNET_CRYPTO_EddsaPublicKey pub 
)

Derive session key and iv from label and public key.

Parameters
nonceinitialization vector to initialize
skeysession key to initialize
labellabel to use for KDF
pubpublic key to use for KDF

16 byte nonce

Expiration time 64 bit.

Definition at line 70 of file gnsrecord_crypto.c.

75{
76 static const char ctx_key[] = "gns-xsalsa-ctx-key";
77 static const char ctx_iv[] = "gns-xsalsa-ctx-iv";
78
80 key, crypto_secretbox_KEYBYTES,
81 ctx_key, strlen (ctx_key),
82 pub, sizeof(struct GNUNET_CRYPTO_EddsaPublicKey),
84 memset (nonce, 0, crypto_secretbox_NONCEBYTES);
87 nonce, (crypto_secretbox_NONCEBYTES - sizeof (exp)),
88 ctx_iv, strlen (ctx_iv),
89 pub, sizeof(struct GNUNET_CRYPTO_EddsaPublicKey),
92 memcpy (&nonce->nonce[crypto_secretbox_NONCEBYTES - sizeof (exp)],
93 &exp,
94 sizeof (exp));
95}
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
unsigned char nonce[24]
Initialization vector.

References GNUNET_CRYPTO_hkdf_gnunet, GNUNET_CRYPTO_kdf_arg_string, key, GNUNET_CRYPTO_XSalsa20Nonce::nonce, and pub.

Referenced by block_create_eddsa(), block_decrypt_eddsa(), and run_edkey().

Here is the caller graph for this function:

◆ block_sign_ecdsa()

static enum GNUNET_GenericReturnValue block_sign_ecdsa ( const struct GNUNET_CRYPTO_EcdsaPrivateKey key,
const struct GNUNET_CRYPTO_EcdsaPublicKey pkey,
const char *  label,
struct GNUNET_GNSRECORD_Block block 
)
static

Definition at line 99 of file gnsrecord_crypto.c.

105{
106 struct GNRBlockPS *gnr_block;
107 struct GNUNET_GNSRECORD_EcdsaBlock *ecblock;
108 size_t size = ntohl (block->size) - sizeof (*block) + sizeof (*gnr_block);
109
110 gnr_block = GNUNET_malloc (size);
111 ecblock = &(block)->ecdsa_block;
112 gnr_block->purpose.size = htonl (size);
113 gnr_block->purpose.purpose =
115 gnr_block->expiration_time = ecblock->expiration_time;
116 /* encrypt and sign */
117 GNUNET_memcpy (&gnr_block[1], &ecblock[1],
118 size - sizeof (*gnr_block));
120 label,
121 "gns",
122 &ecblock->derived_key);
123 if (GNUNET_OK !=
125 label,
126 "gns",
127 &gnr_block->purpose,
128 &ecblock->signature))
129 {
130 GNUNET_break (0);
131 GNUNET_free (gnr_block);
132 return GNUNET_SYSERR;
133 }
134 GNUNET_free (gnr_block);
135 return GNUNET_OK;
136}
static char * pkey
Public key of the zone to look in, in ASCII.
#define GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN
GNS record set signature (GNS)
void GNUNET_CRYPTO_ecdsa_public_key_derive(const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, const char *label, const char *context, struct GNUNET_CRYPTO_EcdsaPublicKey *result)
Derive a public key from a given public key and a label.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_sign_derived(const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, const char *label, const char *context, const struct GNUNET_CRYPTO_SignaturePurpose *purpose, struct GNUNET_CRYPTO_EcdsaSignature *sig)
This is a signature function for ECDSA which takes a private key, derives/blinds it and signs the mes...
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
static unsigned int size
Size of the "table".
Definition peer.c:68
Information we have in an encrypted block with record data (i.e.
struct GNUNET_TIME_AbsoluteNBO expiration_time
Expiration time of the block.
struct GNUNET_CRYPTO_SignaturePurpose purpose
Number of bytes signed; also specifies the number of bytes of encrypted data that follow.
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
uint32_t size
Size of the block.
Information we have in an encrypted block with record data (i.e.
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature of the block.
struct GNUNET_TIME_AbsoluteNBO expiration_time
Expiration time of the block.
struct GNUNET_CRYPTO_EcdsaPublicKey derived_key
Derived key used for signing; hash of this is the query.

References GNUNET_GNSRECORD_EcdsaBlock::derived_key, GNUNET_GNSRECORD_EcdsaBlock::expiration_time, GNRBlockPS::expiration_time, GNUNET_break, GNUNET_CRYPTO_ecdsa_public_key_derive(), GNUNET_CRYPTO_ecdsa_sign_derived(), GNUNET_free, GNUNET_malloc, GNUNET_memcpy, GNUNET_OK, GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN, GNUNET_SYSERR, key, pkey, GNUNET_CRYPTO_SignaturePurpose::purpose, GNRBlockPS::purpose, GNUNET_GNSRECORD_EcdsaBlock::signature, GNUNET_CRYPTO_SignaturePurpose::size, GNUNET_GNSRECORD_Block::size, and size.

Referenced by block_create_ecdsa(), and GNUNET_GNSRECORD_block_sign().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ block_sign_eddsa()

static enum GNUNET_GenericReturnValue block_sign_eddsa ( const struct GNUNET_CRYPTO_EddsaPrivateKey key,
const struct GNUNET_CRYPTO_EddsaPublicKey pkey,
const char *  label,
struct GNUNET_GNSRECORD_Block block 
)
static

Definition at line 140 of file gnsrecord_crypto.c.

146{
147 struct GNRBlockPS *gnr_block;
148 struct GNUNET_GNSRECORD_EddsaBlock *edblock;
149 size_t size = ntohl (block->size) - sizeof (*block) + sizeof (*gnr_block);
150 gnr_block = GNUNET_malloc (size);
151 edblock = &(block)->eddsa_block;
152 gnr_block->purpose.size = htonl (size);
153 gnr_block->purpose.purpose =
155 gnr_block->expiration_time = edblock->expiration_time;
156 GNUNET_memcpy (&gnr_block[1], &edblock[1],
157 size - sizeof (*gnr_block));
158 /* encrypt and sign */
160 label,
161 "gns",
162 &edblock->derived_key);
164 label,
165 "gns",
166 &gnr_block->purpose,
167 &edblock->signature);
168 GNUNET_free (gnr_block);
169 return GNUNET_OK;
170}
void GNUNET_CRYPTO_eddsa_public_key_derive(const struct GNUNET_CRYPTO_EddsaPublicKey *pub, const char *label, const char *context, struct GNUNET_CRYPTO_EddsaPublicKey *result)
Derive a public key from a given public key and a label.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_sign_derived(const struct GNUNET_CRYPTO_EddsaPrivateKey *pkey, const char *label, const char *context, const struct GNUNET_CRYPTO_SignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
This is a signature function for EdDSA which takes a private key and derives it using the label and c...
Information we have in an encrypted block with record data (i.e.
struct GNUNET_CRYPTO_EddsaPublicKey derived_key
Derived key used for signing; hash of this is the query.
struct GNUNET_TIME_AbsoluteNBO expiration_time
Expiration time of the block.
struct GNUNET_CRYPTO_EddsaSignature signature
Signature of the block.

References GNUNET_GNSRECORD_EddsaBlock::derived_key, GNUNET_GNSRECORD_EddsaBlock::expiration_time, GNRBlockPS::expiration_time, GNUNET_CRYPTO_eddsa_public_key_derive(), GNUNET_CRYPTO_eddsa_sign_derived(), GNUNET_free, GNUNET_malloc, GNUNET_memcpy, GNUNET_OK, GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN, key, pkey, GNUNET_CRYPTO_SignaturePurpose::purpose, GNRBlockPS::purpose, GNUNET_GNSRECORD_EddsaBlock::signature, GNUNET_CRYPTO_SignaturePurpose::size, GNUNET_GNSRECORD_Block::size, and size.

Referenced by block_create_eddsa(), and GNUNET_GNSRECORD_block_sign().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ block_create_ecdsa()

static enum GNUNET_GenericReturnValue block_create_ecdsa ( const struct GNUNET_CRYPTO_EcdsaPrivateKey key,
const struct GNUNET_CRYPTO_EcdsaPublicKey pkey,
struct GNUNET_TIME_Absolute  expire,
const char *  label,
const unsigned char *  rdata,
size_t  rdata_len,
struct GNUNET_GNSRECORD_Block **  block,
int  sign 
)
static

Sign name and records.

Parameters
keythe private key
pkeyassociated public key
expireblock expiration
labelthe name for the records
rdrecord data
rd_countnumber of records
blockthe block result. Must be allocated sufficiently.
signsign the block GNUNET_NO if block will be signed later.
Returns
GNUNET_SYSERR on error (otherwise GNUNET_OK)

Definition at line 223 of file gnsrecord_crypto.c.

231{
232 struct GNUNET_GNSRECORD_EcdsaBlock *ecblock;
233 unsigned char ctr[GNUNET_CRYPTO_AES_KEY_LENGTH / 2];
234 unsigned char skey[GNUNET_CRYPTO_AES_KEY_LENGTH];
235
236 if (rdata_len > GNUNET_GNSRECORD_MAX_BLOCK_SIZE)
237 {
238 GNUNET_break (0);
239 return GNUNET_SYSERR;
240 }
241 /* serialize */
242 *block = GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_Block) + rdata_len);
243 (*block)->size = htonl (sizeof (struct GNUNET_GNSRECORD_Block) + rdata_len);
244 {
245 ecblock = &(*block)->ecdsa_block;
246 (*block)->type = htonl (GNUNET_GNSRECORD_TYPE_PKEY);
249 skey,
250 label,
252 pkey);
254 rdata_len,
255 skey,
256 ctr,
257 &ecblock[1]);
258 }
259 if (GNUNET_YES != sign)
260 return GNUNET_OK;
261 if (GNUNET_OK !=
262 block_sign_ecdsa (key, pkey, label, *block))
263 {
264 GNUNET_break (0);
265 GNUNET_free (*block);
266 return GNUNET_SYSERR;
267 }
268 return GNUNET_OK;
269}
static enum GNUNET_GenericReturnValue block_sign_ecdsa(const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey, const char *label, struct GNUNET_GNSRECORD_Block *block)
void GNR_derive_block_aes_key(unsigned char *ctr, unsigned char *key, const char *label, uint64_t exp, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
We disable deprecation warnings because we implement RFC9408/LSD0001 record types here.
#define GNUNET_GNSRECORD_TYPE_PKEY
WARNING: This header is generated! In order to add GNS record types, you must register them in GANA,...
static char * expire
DID Document expiration Date Attribute String.
Definition gnunet-did.c:98
void GNUNET_CRYPTO_aes_ctr(const void *in_buf, size_t in_buf_len, const unsigned char key[(256/8)], const unsigned char iv[(128/8)], void *out_buf)
Decrypt or encrypt a given block using a symmetric key using AES in counter mode.
#define GNUNET_GNSRECORD_MAX_BLOCK_SIZE
Maximum size of a value that can be stored in a GNS block.
@ GNUNET_YES
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition time.c:636
uint64_t abs_value_us__
The actual value (in network byte order).

References GNUNET_TIME_AbsoluteNBO::abs_value_us__, block_sign_ecdsa(), GNUNET_GNSRECORD_EcdsaBlock::expiration_time, expire, GNR_derive_block_aes_key(), GNUNET_break, GNUNET_CRYPTO_aes_ctr(), GNUNET_CRYPTO_AES_KEY_LENGTH, GNUNET_free, GNUNET_GNSRECORD_MAX_BLOCK_SIZE, GNUNET_GNSRECORD_TYPE_PKEY, GNUNET_malloc, GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_absolute_hton(), GNUNET_YES, key, and pkey.

Referenced by block_create2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ block_create_eddsa()

static enum GNUNET_GenericReturnValue block_create_eddsa ( const struct GNUNET_CRYPTO_EddsaPrivateKey key,
const struct GNUNET_CRYPTO_EddsaPublicKey pkey,
struct GNUNET_TIME_Absolute  expire,
const char *  label,
const unsigned char *  rdata,
size_t  rdata_len,
struct GNUNET_GNSRECORD_Block **  block,
int  sign 
)
static

Sign name and records (EDDSA version)

Parameters
keythe private key
pkeyassociated public key
expireblock expiration
labelthe name for the records
rdrecord data
rd_countnumber of records
blockwhere to store the block. Must be allocated sufficiently.
signGNUNET_YES if block shall be signed as well
Returns
GNUNET_SYSERR on error (otherwise GNUNET_OK)

Definition at line 286 of file gnsrecord_crypto.c.

294{
295 struct GNUNET_GNSRECORD_EddsaBlock *edblock;
298
299 if (rdata_len > GNUNET_GNSRECORD_MAX_BLOCK_SIZE)
300 {
301 GNUNET_break (0);
302 return GNUNET_SYSERR;
303 }
304 /* serialize */
305 *block = GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_Block)
306 + rdata_len + crypto_secretbox_MACBYTES);
307 (*block)->size = htonl (sizeof (struct GNUNET_GNSRECORD_Block)
308 + rdata_len + crypto_secretbox_MACBYTES);
309 {
310 edblock = &(*block)->eddsa_block;
311 (*block)->type = htonl (GNUNET_GNSRECORD_TYPE_EDKEY);
314 &skey,
315 label,
317 pkey);
320 rdata_len,
321 (unsigned char*) rdata,
322 &skey,
323 &nonce,
324 &edblock[1]));
325 if (GNUNET_YES != sign)
326 return GNUNET_OK;
327 block_sign_eddsa (key, pkey, label, *block);
328 }
329 return GNUNET_OK;
330}
static enum GNUNET_GenericReturnValue block_sign_eddsa(const struct GNUNET_CRYPTO_EddsaPrivateKey *key, const struct GNUNET_CRYPTO_EddsaPublicKey *pkey, const char *label, struct GNUNET_GNSRECORD_Block *block)
void GNR_derive_block_xsalsa_key(struct GNUNET_CRYPTO_XSalsa20Nonce *nonce, struct GNUNET_CRYPTO_XSalsa20SecretKey *key, const char *label, uint64_t exp, const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Derive session key and iv from label and public key.
#define GNUNET_GNSRECORD_TYPE_EDKEY
GNS zone delegation (EDKEY)
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_xsalsa20poly1305_encrypt(size_t in_buf_len, const unsigned char in_buf[in_buf_len], const struct GNUNET_CRYPTO_XSalsa20SecretKey *key, const struct GNUNET_CRYPTO_XSalsa20Nonce *nonce, void *out_buf)
Encrypt the given data using XSalsa20-Poly1305.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.

References GNUNET_TIME_AbsoluteNBO::abs_value_us__, block_sign_eddsa(), GNUNET_GNSRECORD_EddsaBlock::expiration_time, expire, GNR_derive_block_xsalsa_key(), GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_xsalsa20poly1305_encrypt(), GNUNET_GNSRECORD_MAX_BLOCK_SIZE, GNUNET_GNSRECORD_TYPE_EDKEY, GNUNET_malloc, GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_absolute_hton(), GNUNET_YES, key, GNUNET_CRYPTO_XSalsa20Nonce::nonce, and pkey.

Referenced by block_create2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ block_create2()

static enum GNUNET_GenericReturnValue block_create2 ( const struct GNUNET_CRYPTO_BlindablePrivateKey pkey,
struct GNUNET_TIME_Absolute  expire,
const char *  label,
const unsigned char *  rdata,
size_t  rdata_len,
struct GNUNET_GNSRECORD_Block **  result,
int  sign 
)
static

Definition at line 350 of file gnsrecord_crypto.c.

357{
359 struct GNUNET_CRYPTO_EddsaPublicKey edpubkey;
361 char *norm_label;
362#define CSIZE 64
363 static struct KeyCacheLine cache[CSIZE];
364 struct KeyCacheLine *line;
365
366 norm_label = GNUNET_GNSRECORD_string_normalize (label);
367
368 if (GNUNET_PUBLIC_KEY_TYPE_ECDSA == ntohl (pkey->type))
369 {
370 key = &pkey->ecdsa_key;
371
372 line = &cache[(*(unsigned int *) key) % CSIZE];
373 if (0 != memcmp (&line->key,
374 key,
375 sizeof(*key)))
376 {
377 /* cache miss, recompute */
378 line->key = *key;
380 &line->pkey);
381 }
383 &line->pkey,
384 expire,
385 norm_label,
386 rdata,
387 rdata_len,
388 result,
389 sign);
390 }
391 else if (GNUNET_PUBLIC_KEY_TYPE_EDDSA == ntohl (pkey->type))
392 {
394 &edpubkey);
395 res = block_create_eddsa (&pkey->eddsa_key,
396 &edpubkey,
397 expire,
398 norm_label,
399 rdata,
400 rdata_len,
401 result,
402 sign);
403 }
404#undef CSIZE
405 GNUNET_free (norm_label);
406 return res;
407}
static enum GNUNET_GenericReturnValue block_create_ecdsa(const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey, struct GNUNET_TIME_Absolute expire, const char *label, const unsigned char *rdata, size_t rdata_len, struct GNUNET_GNSRECORD_Block **block, int sign)
Sign name and records.
#define CSIZE
static enum GNUNET_GenericReturnValue block_create_eddsa(const struct GNUNET_CRYPTO_EddsaPrivateKey *key, const struct GNUNET_CRYPTO_EddsaPublicKey *pkey, struct GNUNET_TIME_Absolute expire, const char *label, const unsigned char *rdata, size_t rdata_len, struct GNUNET_GNSRECORD_Block **block, int sign)
Sign name and records (EDDSA version)
static char * line
Desired phone line (string to be converted to a hash).
static char * res
Currently read line or NULL on EOF.
static int result
Global testing status.
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition crypto_ecc.c:201
void GNUNET_CRYPTO_ecdsa_key_get_public(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Derive key.
Definition crypto_ecc.c:190
char * GNUNET_GNSRECORD_string_normalize(const char *src)
Normalize a UTF-8 string to a GNS name.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_PUBLIC_KEY_TYPE_EDDSA
EDDSA identity.
@ GNUNET_PUBLIC_KEY_TYPE_ECDSA
The identity type.
Private ECC key encoded for transmission.
Line in cache mapping private keys to public keys.

References block_create_ecdsa(), block_create_eddsa(), CSIZE, expire, GNUNET_CRYPTO_ecdsa_key_get_public(), GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_free, GNUNET_GNSRECORD_string_normalize(), GNUNET_PUBLIC_KEY_TYPE_ECDSA, GNUNET_PUBLIC_KEY_TYPE_EDDSA, GNUNET_SYSERR, key, KeyCacheLine::key, line, pkey, res, and result.

Referenced by block_seal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ block_decrypt_ecdsa()

static enum GNUNET_GenericReturnValue block_decrypt_ecdsa ( const struct GNUNET_GNSRECORD_Block block,
const struct GNUNET_CRYPTO_EcdsaPublicKey zone_key,
const char *  label,
GNUNET_GNSRECORD_RecordCallback  proc,
void *  proc_cls 
)
static

Definition at line 465 of file gnsrecord_crypto.c.

471{
472 size_t payload_len = ntohl (block->size)
473 - sizeof (struct GNUNET_GNSRECORD_Block);
474 unsigned char ctr[GNUNET_CRYPTO_AES_KEY_LENGTH / 2];
475 unsigned char key[GNUNET_CRYPTO_AES_KEY_LENGTH];
476
477 if (ntohl (block->size) <
478 sizeof (struct GNUNET_GNSRECORD_Block))
479 {
480 GNUNET_break_op (0);
481 return GNUNET_SYSERR;
482 }
483 if (payload_len > UINT16_MAX)
484 {
485 GNUNET_break_op (0);
486 return GNUNET_SYSERR;
487 }
489 key,
490 label,
492 zone_key);
493 {
494 char payload[payload_len];
495 unsigned int rd_count;
496
497 GNUNET_CRYPTO_aes_ctr (&block[1],
498 payload_len,
499 key,
500 ctr,
501 payload);
503 payload);
504 if (rd_count > 2048)
505 {
506 /* limit to sane value */
507 GNUNET_break_op (0);
508 return GNUNET_SYSERR;
509 }
510 {
512 unsigned int j;
513 struct GNUNET_TIME_Absolute now;
514
515 if (GNUNET_OK !=
517 payload,
518 rd_count,
519 rd))
520 {
521 GNUNET_break_op (0);
522 return GNUNET_SYSERR;
523 }
524 /* hide expired records */
526 j = 0;
527 for (unsigned int i = 0; i < rd_count; i++)
528 {
529 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
530 {
531 /* encrypted blocks must never have relative expiration times, skip! */
532 GNUNET_break_op (0);
533 continue;
534 }
535
536 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW))
537 {
538 int include_record = GNUNET_YES;
539 /* Shadow record, figure out if we have a not expired active record */
540 for (unsigned int k = 0; k < rd_count; k++)
541 {
542 if (k == i)
543 continue;
544 if (rd[i].expiration_time < now.abs_value_us)
545 include_record = GNUNET_NO; /* Shadow record is expired */
546 if ((rd[k].record_type == rd[i].record_type) &&
547 (rd[k].expiration_time >= now.abs_value_us) &&
548 (0 == (rd[k].flags & GNUNET_GNSRECORD_RF_SHADOW)))
549 {
550 include_record = GNUNET_NO; /* We have a non-expired, non-shadow record of the same type */
552 "Ignoring shadow record\n");
553 break;
554 }
555 }
556 if (GNUNET_YES == include_record)
557 {
558 rd[i].flags ^= GNUNET_GNSRECORD_RF_SHADOW; /* Remove Flag */
559 if (j != i)
560 rd[j] = rd[i];
561 j++;
562 }
563 }
564 else if (rd[i].expiration_time >= now.abs_value_us)
565 {
566 /* Include this record */
567 if (j != i)
568 rd[j] = rd[i];
569 j++;
570 }
571 else
572 {
573 struct GNUNET_TIME_Absolute at;
574
577 "Excluding record that expired %s (%llu ago)\n",
579 (unsigned long long) rd[i].expiration_time
580 - now.abs_value_us);
581 }
582 }
583 rd_count = j;
584 if (NULL != proc)
585 proc (proc_cls,
586 rd_count,
587 (0 != rd_count) ? rd : NULL);
588 }
589 }
590 return GNUNET_OK;
591}
static unsigned int rd_count
Number of records for currently parsed set.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
static unsigned long long payload
How much data are we currently storing in the database?
int GNUNET_GNSRECORD_records_deserialize(size_t len, const char *src, unsigned int rd_count, struct GNUNET_GNSRECORD_Data *dest)
Deserialize the given records to the given destination.
unsigned int GNUNET_GNSRECORD_records_deserialize_get_size(size_t len, const char *src)
@ GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION
This expiration time of the record is a relative time (not an absolute time).
@ GNUNET_GNSRECORD_RF_SHADOW
This record should not be used unless all (other) records in the set with an absolute expiration time...
#define GNUNET_log(kind,...)
#define GNUNET_NZL(l)
Macro used to avoid using 0 for the length of a variable-size array (Non-Zero-Length).
@ GNUNET_NO
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
@ GNUNET_ERROR_TYPE_INFO
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition time.c:111
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition strings.c:671
struct GNUNET_GNSRECORD_EcdsaBlock ecdsa_block
enum GNUNET_GNSRECORD_Flags flags
Flags for the record.
uint64_t expiration_time
Expiration time for the DNS record.
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_TIME_AbsoluteNBO::abs_value_us__, GNUNET_GNSRECORD_Block::ecdsa_block, GNUNET_GNSRECORD_Data::expiration_time, GNUNET_GNSRECORD_EcdsaBlock::expiration_time, GNUNET_GNSRECORD_Data::flags, GNR_derive_block_aes_key(), GNUNET_break_op, GNUNET_CRYPTO_aes_ctr(), GNUNET_CRYPTO_AES_KEY_LENGTH, GNUNET_ERROR_TYPE_INFO, GNUNET_GNSRECORD_records_deserialize(), GNUNET_GNSRECORD_records_deserialize_get_size(), GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION, GNUNET_GNSRECORD_RF_SHADOW, GNUNET_log, GNUNET_NO, GNUNET_NZL, GNUNET_OK, GNUNET_STRINGS_absolute_time_to_string(), GNUNET_SYSERR, GNUNET_TIME_absolute_get(), GNUNET_YES, key, payload, rd, rd_count, and GNUNET_GNSRECORD_Block::size.

Referenced by block_open_ecdsa().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ block_decrypt_eddsa()

static enum GNUNET_GenericReturnValue block_decrypt_eddsa ( const struct GNUNET_GNSRECORD_Block block,
const struct GNUNET_CRYPTO_EddsaPublicKey zone_key,
const char *  label,
GNUNET_GNSRECORD_RecordCallback  proc,
void *  proc_cls 
)
static

Definition at line 595 of file gnsrecord_crypto.c.

601{
602 size_t payload_len = ntohl (block->size)
603 - sizeof (struct GNUNET_GNSRECORD_Block);
606
607
608 if (ntohl (block->size) <
609 sizeof(struct GNUNET_GNSRECORD_Block))
610 {
611 GNUNET_break_op (0);
612 return GNUNET_SYSERR;
613 }
614 if (payload_len > UINT16_MAX)
615 {
616 GNUNET_break_op (0);
617 return GNUNET_SYSERR;
618 }
620 &skey,
621 label,
623 ,
624 zone_key);
625 {
626 char payload[payload_len];
627 unsigned int rd_count;
628
629 if (GNUNET_OK !=
631 payload_len,
632 (unsigned char*) &block[1],
633 &skey,
634 &nonce,
635 payload))
636 {
637 GNUNET_break_op (0);
638 return GNUNET_SYSERR;
639 }
640 payload_len -= crypto_secretbox_MACBYTES;
642 payload);
643 if (rd_count > 2048)
644 {
645 /* limit to sane value */
646 GNUNET_break_op (0);
647 return GNUNET_SYSERR;
648 }
649 {
651 unsigned int j;
652 struct GNUNET_TIME_Absolute now;
653
654 if (GNUNET_OK !=
656 payload,
657 rd_count,
658 rd))
659 {
660 GNUNET_break_op (0);
661 return GNUNET_SYSERR;
662 }
663 /* hide expired records */
665 j = 0;
666 for (unsigned int i = 0; i < rd_count; i++)
667 {
668 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
669 {
670 /* encrypted blocks must never have relative expiration times, skip! */
671 GNUNET_break_op (0);
672 continue;
673 }
674
675 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW))
676 {
677 int include_record = GNUNET_YES;
678 /* Shadow record, figure out if we have a not expired active record */
679 for (unsigned int k = 0; k < rd_count; k++)
680 {
681 if (k == i)
682 continue;
683 if (rd[i].expiration_time < now.abs_value_us)
684 include_record = GNUNET_NO; /* Shadow record is expired */
685 if ((rd[k].record_type == rd[i].record_type) &&
686 (rd[k].expiration_time >= now.abs_value_us) &&
687 (0 == (rd[k].flags & GNUNET_GNSRECORD_RF_SHADOW)))
688 {
689 include_record = GNUNET_NO; /* We have a non-expired, non-shadow record of the same type */
691 "Ignoring shadow record\n");
692 break;
693 }
694 }
695 if (GNUNET_YES == include_record)
696 {
697 rd[i].flags ^= GNUNET_GNSRECORD_RF_SHADOW; /* Remove Flag */
698 if (j != i)
699 rd[j] = rd[i];
700 j++;
701 }
702 }
703 else if (rd[i].expiration_time >= now.abs_value_us)
704 {
705 /* Include this record */
706 if (j != i)
707 rd[j] = rd[i];
708 j++;
709 }
710 else
711 {
712 struct GNUNET_TIME_Absolute at;
713
716 "Excluding record that expired %s (%llu ago)\n",
718 (unsigned long long) rd[i].expiration_time
719 - now.abs_value_us);
720 }
721 }
722 rd_count = j;
723 if (NULL != proc)
724 proc (proc_cls,
725 rd_count,
726 (0 != rd_count) ? rd : NULL);
727 }
728 }
729 return GNUNET_OK;
730}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_xsalsa20poly1305_decrypt(size_t in_buf_len, const unsigned char in_buf[in_buf_len], const struct GNUNET_CRYPTO_XSalsa20SecretKey *key, const struct GNUNET_CRYPTO_XSalsa20Nonce *nonce, void *out_buf)
Encrypt the given data using XSalsa20-Poly1305.
struct GNUNET_GNSRECORD_EddsaBlock eddsa_block

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_TIME_AbsoluteNBO::abs_value_us__, GNUNET_GNSRECORD_Block::eddsa_block, GNUNET_GNSRECORD_Data::expiration_time, GNUNET_GNSRECORD_EddsaBlock::expiration_time, GNUNET_GNSRECORD_Data::flags, GNR_derive_block_xsalsa_key(), GNUNET_break_op, GNUNET_CRYPTO_xsalsa20poly1305_decrypt(), GNUNET_ERROR_TYPE_INFO, GNUNET_GNSRECORD_records_deserialize(), GNUNET_GNSRECORD_records_deserialize_get_size(), GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION, GNUNET_GNSRECORD_RF_SHADOW, GNUNET_log, GNUNET_NO, GNUNET_NZL, GNUNET_OK, GNUNET_STRINGS_absolute_time_to_string(), GNUNET_SYSERR, GNUNET_TIME_absolute_get(), GNUNET_YES, GNUNET_CRYPTO_XSalsa20Nonce::nonce, payload, rd, rd_count, and GNUNET_GNSRECORD_Block::size.

Referenced by block_open_eddsa().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ block_open_ecdsa()

static enum GNUNET_GenericReturnValue block_open_ecdsa ( void *  cls,
const char *  label,
const struct GNUNET_GNSRECORD_Block block,
GNUNET_GNSRECORD_RecordCallback  proc,
void *  proc_cls 
)
static

Definition at line 823 of file gnsrecord_crypto.c.

828{
829 struct EncryptionContextData *ecd = cls;
831 char *norm_label;
832
833 norm_label = GNUNET_GNSRECORD_string_normalize (label);
834 return block_decrypt_ecdsa (block,
835 &ecd->zkey.ecdsa_key,
836 norm_label, proc,
837 proc_cls);
838 GNUNET_free (norm_label);
839 return res;
840
841}
static enum GNUNET_GenericReturnValue block_decrypt_ecdsa(const struct GNUNET_GNSRECORD_Block *block, const struct GNUNET_CRYPTO_EcdsaPublicKey *zone_key, const char *label, GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls)
struct GNUNET_CRYPTO_BlindablePublicKey zkey
struct GNUNET_CRYPTO_EcdsaPublicKey ecdsa_key
An ECDSA identity key.

References block_decrypt_ecdsa(), GNUNET_CRYPTO_BlindablePublicKey::ecdsa_key, GNUNET_free, GNUNET_GNSRECORD_string_normalize(), GNUNET_SYSERR, res, and EncryptionContextData::zkey.

Referenced by GNUNET_GNSRECORD_encryption_context_setup_owner(), and GNUNET_GNSRECORD_encryption_context_setup_resolver().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ block_open_eddsa()

static enum GNUNET_GenericReturnValue block_open_eddsa ( void *  cls,
const char *  label,
const struct GNUNET_GNSRECORD_Block block,
GNUNET_GNSRECORD_RecordCallback  proc,
void *  proc_cls 
)
static

Definition at line 845 of file gnsrecord_crypto.c.

850{
851 struct EncryptionContextData *ecd = cls;
853 char *norm_label;
854
855 norm_label = GNUNET_GNSRECORD_string_normalize (label);
856 res = block_decrypt_eddsa (block,
857 &ecd->zkey.eddsa_key,
858 norm_label, proc,
859 proc_cls);
860 GNUNET_free (norm_label);
861 return res;
862}
static enum GNUNET_GenericReturnValue block_decrypt_eddsa(const struct GNUNET_GNSRECORD_Block *block, const struct GNUNET_CRYPTO_EddsaPublicKey *zone_key, const char *label, GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls)
struct GNUNET_CRYPTO_EddsaPublicKey eddsa_key
AN EdDSA identtiy key.

References block_decrypt_eddsa(), GNUNET_CRYPTO_BlindablePublicKey::eddsa_key, GNUNET_free, GNUNET_GNSRECORD_string_normalize(), res, and EncryptionContextData::zkey.

Referenced by GNUNET_GNSRECORD_encryption_context_setup_owner(), and GNUNET_GNSRECORD_encryption_context_setup_resolver().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ block_seal_not_implemented()

static enum GNUNET_GenericReturnValue block_seal_not_implemented ( void *  cls,
const char *  label,
struct GNUNET_TIME_Absolute  expire,
unsigned char *  rdata,
size_t  rdata_len,
struct GNUNET_GNSRECORD_Block **  result 
)
static

Definition at line 866 of file gnsrecord_crypto.c.

872{
873 GNUNET_break (0);
874 return GNUNET_SYSERR;
875}

References GNUNET_break, and GNUNET_SYSERR.

Referenced by GNUNET_GNSRECORD_encryption_context_setup_resolver().

Here is the caller graph for this function:

◆ block_seal()

static enum GNUNET_GenericReturnValue block_seal ( void *  cls,
const char *  label,
struct GNUNET_TIME_Absolute  expire,
unsigned char *  rdata,
size_t  rdata_len,
struct GNUNET_GNSRECORD_Block **  result 
)
static

Definition at line 879 of file gnsrecord_crypto.c.

885{
886 struct EncryptionContextData *ecd = cls;
887
888 return block_create2 (ecd->sk,
889 expire,
890 label,
891 rdata,
892 rdata_len,
893 result,
894 GNUNET_YES);
895}
static enum GNUNET_GenericReturnValue block_create2(const struct GNUNET_CRYPTO_BlindablePrivateKey *pkey, struct GNUNET_TIME_Absolute expire, const char *label, const unsigned char *rdata, size_t rdata_len, struct GNUNET_GNSRECORD_Block **result, int sign)
struct GNUNET_CRYPTO_BlindablePrivateKey * sk

References block_create2(), expire, GNUNET_YES, result, and EncryptionContextData::sk.

Referenced by GNUNET_GNSRECORD_encryption_context_setup_owner().

Here is the call graph for this function:
Here is the caller graph for this function: