Hybrid Public Key Encryption (HPKE) and Key encapsulation mechanisms (KEMs) More...
#include "platform.h"
#include "gnunet_common.h"
#include <sodium.h>
#include <stdint.h>
#include "gnunet_util_lib.h"
#include "sodium/crypto_scalarmult.h"
#include "sodium/crypto_scalarmult_curve25519.h"
#include "sodium/utils.h"
Go to the source code of this file.
Functions | |
static enum GNUNET_GenericReturnValue | labeled_extract (const char *ctx_str, const void *salt, size_t salt_len, const void *label, size_t label_len, const void *ikm, size_t ikm_len, const uint8_t *suite_id, size_t suite_id_len, struct GNUNET_ShortHashCode *prk) |
A RFC9180 inspired labeled extract. More... | |
static enum GNUNET_GenericReturnValue | labeled_expand (const char *ctx_str, const struct GNUNET_ShortHashCode *prk, const char *label, size_t label_len, const void *info, size_t info_len, const uint8_t *suite_id, size_t suite_id_len, void *out_buf, uint16_t out_len) |
A RFC9180 inspired labeled extract. More... | |
static enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_hpke_labeled_extract_and_expand (const void *dh, size_t dh_len, const char *extract_ctx, const char *expand_ctx, const void *extract_lbl, size_t extract_lbl_len, const void *expand_lbl, size_t expand_lbl_len, const uint8_t *kem_context, size_t kem_context_len, const uint8_t *suite_id, size_t suite_id_len, struct GNUNET_ShortHashCode *shared_secret) |
static enum GNUNET_GenericReturnValue | authkem_encaps_norand (uint8_t *suite_id, size_t suite_id_len, const struct GNUNET_CRYPTO_EcdhePublicKey *pkR, const struct GNUNET_CRYPTO_EcdhePrivateKey *skS, struct GNUNET_CRYPTO_HpkeEncapsulation *c, const struct GNUNET_CRYPTO_EcdhePrivateKey *skE, struct GNUNET_ShortHashCode *shared_secret) |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_hpke_authkem_encaps_norand (const struct GNUNET_CRYPTO_EcdhePublicKey *pkR, const struct GNUNET_CRYPTO_EcdhePrivateKey *skS, struct GNUNET_CRYPTO_HpkeEncapsulation *c, const struct GNUNET_CRYPTO_EcdhePrivateKey *skE, struct GNUNET_ShortHashCode *shared_secret) |
Encapsulate authenticated key material for a X25519 public key. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_hpke_authkem_encaps (const struct GNUNET_CRYPTO_EcdhePublicKey *pkR, const struct GNUNET_CRYPTO_EcdhePrivateKey *skS, struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *shared_secret) |
Encapsulate authenticated key material for a X25519 public key. More... | |
static enum GNUNET_GenericReturnValue | kem_encaps_norand (uint8_t *suite_id, size_t suite_id_len, const struct GNUNET_CRYPTO_EcdhePublicKey *pkR, const struct GNUNET_CRYPTO_HpkeEncapsulation *c, const struct GNUNET_CRYPTO_EcdhePrivateKey *skE, struct GNUNET_ShortHashCode *shared_secret) |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_hpke_kem_encaps_norand (const struct GNUNET_CRYPTO_EcdhePublicKey *pkR, struct GNUNET_CRYPTO_HpkeEncapsulation *enc, const struct GNUNET_CRYPTO_EcdhePrivateKey *skE, struct GNUNET_ShortHashCode *shared_secret) |
Deterministic variant of GNUNET_CRYPTO_hpke_kem_encaps. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_hpke_kem_encaps (const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *shared_secret) |
Encapsulate key material for a X25519 public key. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_eddsa_kem_encaps (const struct GNUNET_CRYPTO_EddsaPublicKey *pub, struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *shared_secret) |
Encapsulate key material for a EdDSA public key. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_hpke_authkem_decaps (const struct GNUNET_CRYPTO_EcdhePrivateKey *skR, const struct GNUNET_CRYPTO_EcdhePublicKey *pkS, const struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *shared_secret) |
Decapsulate a key for a private X25519 key. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_hpke_kem_decaps (const struct GNUNET_CRYPTO_EcdhePrivateKey *skR, const struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *shared_secret) |
Decapsulate a key for a private X25519 key. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_eddsa_kem_decaps (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *shared_secret) |
Decapsulate a key for a private EdDSA key. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_hpke_elligator_kem_encaps_norand (uint8_t random_tweak, const struct GNUNET_CRYPTO_EcdhePublicKey *pkR, struct GNUNET_CRYPTO_HpkeEncapsulation *c, const struct GNUNET_CRYPTO_ElligatorEcdhePrivateKey *skE, struct GNUNET_ShortHashCode *shared_secret) |
Carries out ecdh encapsulation with given public key and the private key from a freshly created ephemeral key pair. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_hpke_elligator_kem_encaps (const struct GNUNET_CRYPTO_EcdhePublicKey *pkR, struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *shared_secret) |
Carries out ecdh encapsulation with given public key and the private key from a freshly created ephemeral key pair. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_hpke_elligator_kem_decaps (const struct GNUNET_CRYPTO_EcdhePrivateKey *skR, const struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *shared_secret) |
Carries out ecdh decapsulation with own private key and the representative of the received public key. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_hpke_elligator_authkem_encaps_norand (const struct GNUNET_CRYPTO_EcdhePublicKey *pkR, const struct GNUNET_CRYPTO_EcdhePrivateKey *skS, struct GNUNET_CRYPTO_HpkeEncapsulation *c, const struct GNUNET_CRYPTO_ElligatorEcdhePrivateKey *skE, struct GNUNET_ShortHashCode *shared_secret) |
Encapsulate authenticated key material for a X25519 public key. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_hpke_elligator_authkem_encaps (const struct GNUNET_CRYPTO_EcdhePublicKey *pkR, const struct GNUNET_CRYPTO_EcdhePrivateKey *skS, struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *shared_secret) |
Encapsulate authenticated key material for a X25519 public key. More... | |
static enum GNUNET_GenericReturnValue | verify_psk_inputs (enum GNUNET_CRYPTO_HpkeMode mode, const uint8_t *psk, size_t psk_len, const uint8_t *psk_id, size_t psk_id_len) |
static enum GNUNET_GenericReturnValue | key_schedule (enum GNUNET_CRYPTO_HpkeRole role, enum GNUNET_CRYPTO_HpkeMode mode, const struct GNUNET_ShortHashCode *shared_secret, const uint8_t *info, size_t info_len, const uint8_t *psk, size_t psk_len, const uint8_t *psk_id, size_t psk_id_len, struct GNUNET_CRYPTO_HpkeContext *ctx) |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_hpke_sender_setup2 (enum GNUNET_CRYPTO_HpkeKem kem, enum GNUNET_CRYPTO_HpkeMode mode, struct GNUNET_CRYPTO_EcdhePrivateKey *skE, struct GNUNET_CRYPTO_EcdhePrivateKey *skS, const struct GNUNET_CRYPTO_EcdhePublicKey *pkR, const uint8_t *info, size_t info_len, const uint8_t *psk, size_t psk_len, const uint8_t *psk_id, size_t psk_id_len, struct GNUNET_CRYPTO_HpkeEncapsulation *enc, struct GNUNET_CRYPTO_HpkeContext *ctx) |
RFC9180 HPKE encryption. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_hpke_sender_setup (const struct GNUNET_CRYPTO_EcdhePublicKey *pkR, const uint8_t *info, size_t info_len, struct GNUNET_CRYPTO_HpkeEncapsulation *enc, struct GNUNET_CRYPTO_HpkeContext *ctx) |
RFC9180 HPKE encryption. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_hpke_receiver_setup2 (enum GNUNET_CRYPTO_HpkeKem kem, enum GNUNET_CRYPTO_HpkeMode mode, const struct GNUNET_CRYPTO_HpkeEncapsulation *enc, const struct GNUNET_CRYPTO_EcdhePrivateKey *skR, const struct GNUNET_CRYPTO_EcdhePublicKey *pkS, const uint8_t *info, size_t info_len, const uint8_t *psk, size_t psk_len, const uint8_t *psk_id, size_t psk_id_len, struct GNUNET_CRYPTO_HpkeContext *ctx) |
RFC9180 HPKE encryption. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_hpke_receiver_setup (const struct GNUNET_CRYPTO_HpkeEncapsulation *enc, const struct GNUNET_CRYPTO_EcdhePrivateKey *skR, const uint8_t *info, size_t info_len, struct GNUNET_CRYPTO_HpkeContext *ctx) |
RFC9180 HPKE encryption. More... | |
static enum GNUNET_GenericReturnValue | increment_seq (struct GNUNET_CRYPTO_HpkeContext *ctx) |
static void | compute_nonce (struct GNUNET_CRYPTO_HpkeContext *ctx, uint8_t *nonce) |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_hpke_seal (struct GNUNET_CRYPTO_HpkeContext *ctx, const uint8_t *aad, size_t aad_len, const uint8_t *pt, size_t pt_len, uint8_t *ct, unsigned long long *ct_len_p) |
RFC9180 HPKE encryption. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_hpke_open (struct GNUNET_CRYPTO_HpkeContext *ctx, const uint8_t *aad, size_t aad_len, const uint8_t *ct, size_t ct_len, uint8_t *pt, unsigned long long *pt_len) |
RFC9180 HPKE encryption. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_hpke_seal_oneshot (const struct GNUNET_CRYPTO_EcdhePublicKey *pkR, const uint8_t *info, size_t info_len, const uint8_t *aad, size_t aad_len, const uint8_t *pt, size_t pt_len, uint8_t *ct, unsigned long long *ct_len_p) |
RFC9180 HPKE encryption. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_hpke_open_oneshot (const struct GNUNET_CRYPTO_EcdhePrivateKey *skR, const uint8_t *info, size_t info_len, const uint8_t *aad, size_t aad_len, const uint8_t *ct, size_t ct_len, uint8_t *pt, unsigned long long *pt_len_p) |
RFC9180 HPKE encryption. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_hpke_pk_to_x25519 (const struct GNUNET_CRYPTO_PublicKey *pk, struct GNUNET_CRYPTO_EcdhePublicKey *x25519) |
Convert a GNUnet identity key to a key sutiable for HPKE (X25519) More... | |
enum GNUNET_GenericReturnValue | GNUNET_CRYPTO_hpke_sk_to_x25519 (const struct GNUNET_CRYPTO_PrivateKey *sk, struct GNUNET_CRYPTO_EcdhePrivateKey *x25519) |
Convert a GNUnet identity key to a key sutiable for HPKE (X25519) More... | |
Variables | |
static uint8_t | GNUNET_CRYPTO_HPKE_KEM_SUITE_ID [] |
static uint8_t | GNUNET_CRYPTO_HPKE_KEM_ELLIGATOR_SUITE_ID [] |
Hybrid Public Key Encryption (HPKE) and Key encapsulation mechanisms (KEMs)
Definition in file crypto_hpke.c.
|
static |
A RFC9180 inspired labeled extract.
ctx_str | the context to label with (c string) |
salt | the extract salt |
salt_len | salt length in bytes |
label | the label to label with |
label_len | label length in bytes |
ikm | initial keying material |
ikm_len | ikm length in bytes |
suite_id | the suite ID |
suite_id_len | suite_id length in bytes |
prk | the resulting extracted PRK |
Definition at line 51 of file crypto_hpke.c.
References GNUNET_CRYPTO_hkdf_extract(), and salt.
Referenced by GNUNET_CRYPTO_hpke_labeled_extract_and_expand(), and key_schedule().
|
static |
A RFC9180 inspired labeled extract.
ctx_str | the context to label with (c string) |
prk | the extracted PRK |
label | the label to label with |
label_len | label length in bytes |
info | context info |
info_len | info in bytes |
suite_id | the suite ID |
suite_id_len | suite_id length in bytes |
out_buf | output buffer, must be allocated |
out_len | out_buf length in bytes |
Definition at line 94 of file crypto_hpke.c.
References GNUNET_CRYPTO_hkdf_expand(), and info.
Referenced by GNUNET_CRYPTO_hpke_labeled_extract_and_expand(), and key_schedule().
|
static |
Definition at line 124 of file crypto_hpke.c.
References labeled_expand(), and labeled_extract().
Referenced by authkem_encaps_norand(), GNUNET_CRYPTO_hpke_authkem_decaps(), GNUNET_CRYPTO_hpke_elligator_kem_decaps(), GNUNET_CRYPTO_hpke_kem_decaps(), and kem_encaps_norand().
|
static |
Definition at line 166 of file crypto_hpke.c.
References GNUNET_CRYPTO_ecdh_x25519(), GNUNET_CRYPTO_ecdhe_key_get_public(), GNUNET_CRYPTO_hpke_labeled_extract_and_expand(), GNUNET_OK, and GNUNET_SYSERR.
Referenced by GNUNET_CRYPTO_hpke_authkem_encaps_norand(), and GNUNET_CRYPTO_hpke_elligator_authkem_encaps_norand().
|
static |
Definition at line 246 of file crypto_hpke.c.
References GNUNET_CRYPTO_ecdh_x25519(), GNUNET_CRYPTO_hpke_labeled_extract_and_expand(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, and GNUNET_SYSERR.
Referenced by GNUNET_CRYPTO_hpke_elligator_kem_encaps_norand(), and GNUNET_CRYPTO_hpke_kem_encaps_norand().
|
static |
Definition at line 547 of file crypto_hpke.c.
References GNUNET_CRYPTO_HPKE_MODE_AUTH, GNUNET_CRYPTO_HPKE_MODE_AUTH_PSK, GNUNET_CRYPTO_HPKE_MODE_BASE, GNUNET_CRYPTO_HPKE_MODE_PSK, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, and mode.
Referenced by key_schedule().
|
static |
Definition at line 585 of file crypto_hpke.c.
References ctx, GNUNET_OK, GNUNET_SYSERR, info, labeled_expand(), labeled_extract(), mode, and verify_psk_inputs().
Referenced by GNUNET_CRYPTO_hpke_receiver_setup2(), and GNUNET_CRYPTO_hpke_sender_setup2().
|
static |
Definition at line 833 of file crypto_hpke.c.
References ctx, GNUNET_ERROR_TYPE_ERROR, GNUNET_htonll(), GNUNET_log, GNUNET_ntohll(), GNUNET_OK, and GNUNET_SYSERR.
Referenced by GNUNET_CRYPTO_hpke_open(), and GNUNET_CRYPTO_hpke_seal().
|
static |
Definition at line 846 of file crypto_hpke.c.
References ctx, and GNUNET_CRYPTO_HPKE_NONCE_LEN.
Referenced by GNUNET_CRYPTO_hpke_open(), and GNUNET_CRYPTO_hpke_seal().
|
static |
Definition at line 158 of file crypto_hpke.c.
Referenced by GNUNET_CRYPTO_hpke_authkem_decaps(), GNUNET_CRYPTO_hpke_authkem_encaps_norand(), GNUNET_CRYPTO_hpke_kem_decaps(), and GNUNET_CRYPTO_hpke_kem_encaps_norand().
|
static |
Definition at line 163 of file crypto_hpke.c.
Referenced by GNUNET_CRYPTO_hpke_elligator_authkem_encaps_norand(), GNUNET_CRYPTO_hpke_elligator_kem_decaps(), and GNUNET_CRYPTO_hpke_elligator_kem_encaps_norand().