GNUnet 0.22.0
gnunet-elligator-tvg.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2020 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
26#include "gnunet_common.h"
27#include "gnunet_util_lib.h"
28#include <gcrypt.h>
29#include <stdio.h>
30#include <sodium.h>
31
32static uint8_t seed = 6; // only three least significant bits, rest will be ignored.
33
34static uint8_t skRmBytes[32] = {
35 0xf3, 0x38, 0x87, 0xa8, 0x56, 0x2d, 0xad, 0x51,
36 0x51, 0xe9, 0x28, 0x9a, 0x0a, 0xfa, 0x13, 0x01,
37 0xcc, 0xc6, 0x98, 0x91, 0x78, 0x50, 0xd5, 0x6e,
38 0xa4, 0x09, 0xa9, 0x94, 0x94, 0x97, 0xba, 0xa4
39};
40
41static uint8_t pkRmBytes[32] = {
42 0x3f, 0xeb, 0xad, 0xac, 0x12, 0x2d, 0x39, 0x77,
43 0x25, 0xff, 0x58, 0x0f, 0x6c, 0xe9, 0xa3, 0xe1,
44 0xc1, 0xc4, 0xa7, 0xde, 0x19, 0x80, 0x7f, 0x13,
45 0xd3, 0x83, 0xf2, 0xf9, 0xb6, 0x46, 0x71, 0x36
46};
47
48static uint8_t skEmBytes[32] = {
49 0x09, 0x39, 0x59, 0x66, 0xd6, 0xd1, 0xc4, 0x93,
50 0xb9, 0x91, 0x7d, 0xd1, 0x2c, 0x8d, 0xd2, 0x4e,
51 0x2c, 0x05, 0xc0, 0x81, 0xc9, 0x8a, 0x67, 0xeb,
52 0x2d, 0x6d, 0xff, 0x62, 0x2e, 0xc9, 0xc0, 0x69
53};
54
55static void
58{
60 key.type = htonl (GNUNET_PUBLIC_KEY_TYPE_EDDSA);
61 key.eddsa_key = *edpk;
63}
64
65
73int
74main (int argc,
75 char *const *argv)
76{
77 // hardcoded receiver key pair ("skRm","pkRm") and ephemeral secret key "skEm"
81 memcpy (skRm.d, skRmBytes, sizeof(skRm.d));
82 memcpy (pkRm.q_y, pkRmBytes, sizeof(pkRm.q_y));
83 memcpy (skEm.d, skEmBytes, sizeof(skEm.d));
84
85 // compute special elligator public key "pkEm" and representative "enc" deterministically
86 struct GNUNET_CRYPTO_EcdhePublicKey pkEm = {0};
87 struct GNUNET_CRYPTO_ElligatorRepresentative enc = {0}; // randomness through seed
89 &skEm,
90 &pkEm,
91 &enc);
92
93 // compute "key" deterministically
94 struct GNUNET_CRYPTO_EcdhePublicKey pkRmHpke = {0};
95 struct GNUNET_ShortHashCode key = {0};
96 eddsa_pub_to_hpke_key (&pkRm, &pkRmHpke);
98 &pkRmHpke,
99 (struct
101 *) &enc,
102 &skEm,
103 &key);
104
105 // print all
106 printf ("coin flip 1: %d\n", (seed) & 1); // high_y
107 printf ("coin flip 2: %d\n", (seed >> 1) & 1); // most significant bit (msb)
108 printf ("coin flip 3: %d\n", (seed >> 2) & 1); // second msb
109 printf ("pkEm: ");
110 GNUNET_print_bytes (pkEm.q_y, sizeof(pkEm.q_y), 0, 0);
111 printf ("skEm: ");
112 GNUNET_print_bytes (skEm.d, sizeof(skEm.d), 0, 0);
113 printf ("skRm: ");
114 GNUNET_print_bytes (skRm.d, sizeof(skRm.d), 0, 0);
115 printf ("pkRm: ");
116 GNUNET_print_bytes (pkRm.q_y, sizeof(pkRm.q_y), 0, 0);
117 printf ("enc: ");
118 GNUNET_print_bytes (enc.r, sizeof(enc.r), 0, 0);
119 printf ("key: ");
120 GNUNET_print_bytes (key.bits, sizeof(key.bits), 0, 0);
121}
struct GNUNET_HashCode key
The key used in the DHT.
static uint8_t pkRmBytes[32]
static uint8_t seed
static uint8_t skRmBytes[32]
static uint8_t skEmBytes[32]
int main(int argc, char *const *argv)
The main function of the test vector generation tool.
static void eddsa_pub_to_hpke_key(struct GNUNET_CRYPTO_EddsaPublicKey *edpk, struct GNUNET_CRYPTO_EcdhePublicKey *pk)
static OpusEncoder * enc
OPUS encoder.
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdhe_elligator_key_get_public_norand(uint8_t random_tweak, const struct GNUNET_CRYPTO_ElligatorEcdhePrivateKey *sk, struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_CRYPTO_ElligatorRepresentative *repr)
Generates a valid public key for elligator's inverse map by adding a lower order point to a prime ord...
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 ephem...
Definition: crypto_hpke.c:423
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)
Definition: crypto_hpke.c:989
uint32_t bits[512/8/sizeof(uint32_t)]
@ GNUNET_PUBLIC_KEY_TYPE_EDDSA
EDDSA identity.
void GNUNET_print_bytes(const void *buf, size_t buf_len, int fold, int in_be)
Print a byte string in hexadecimal ascii notation.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
unsigned char q_y[256/8]
Q consists of an x- and a y-value, each mod p (256 bits), given here in affine coordinates and Ed2551...
Private ECC key encoded for transmission.
unsigned char d[256/8]
d is a value mod n, where n has at most 256 bits.
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
unsigned char q_y[256/8]
Point Q consists of a y-value mod p (256 bits); the x-value is always positive.
Special private ECC key generated by GNUNET_CRYPTO_ecdhe_elligator_key_create.
unsigned char d[256/8]
d is a value mod n, where n has at most 256 bits.
Elligator representative (always for Curve25519)
HPKE DHKEM encapsulation (X25519) See RFC 9180.
An identity key as per LSD0001.
A 256-bit hashcode.