GNUnet 0.21.1
crypto_pkey.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2013, 2016, 2021 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
27#include "platform.h"
28#include "gnunet_util_lib.h"
29
30
33{
34 switch (type)
35 {
38 return GNUNET_OK;
39 default:
40 return GNUNET_SYSERR;
41 }
42 return GNUNET_SYSERR;
43}
44
45
46ssize_t
49{
50 switch (ntohl (key->type))
51 {
53 return sizeof (key->type) + sizeof (key->ecdsa_key);
54 break;
56 return sizeof (key->type) + sizeof (key->eddsa_key);
57 break;
58 default:
60 "Got key type %u\n", ntohl (key->type));
61 GNUNET_break (0);
62 }
63 return -1;
64}
65
66
67ssize_t
70{
71 switch (ntohl (key->type))
72 {
74 return sizeof (key->type) + sizeof (key->ecdsa_key);
76 return sizeof (key->type) + sizeof (key->eddsa_key);
77 default:
78 GNUNET_break (0);
79 }
80 return -1;
81}
82
83
84ssize_t
86{
87 switch (kt)
88 {
90 return sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey);
91 break;
93 return sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey);
94 break;
95 default:
96 GNUNET_break (0);
97 }
98 return -1;
99}
100
101
104 size_t len,
106 key,
107 size_t *kb_read)
108{
109 if (len < sizeof (key->type))
110 return GNUNET_SYSERR;
111 GNUNET_memcpy (&key->type,
112 buffer,
113 sizeof (key->type));
114 ssize_t length = GNUNET_CRYPTO_public_key_get_length (key);
115 if (len < length)
116 return GNUNET_SYSERR;
117 if (length < 0)
118 return GNUNET_SYSERR;
119 GNUNET_memcpy (&key->ecdsa_key,
120 buffer + sizeof (key->type),
121 length - sizeof (key->type));
122 *kb_read = length;
123 return GNUNET_OK;
124}
125
126
127ssize_t
130 void*buffer,
131 size_t len)
132{
133 const ssize_t length = GNUNET_CRYPTO_public_key_get_length (key);
134 if (len < length)
135 return -1;
136 if (length < 0)
137 return -2;
138 GNUNET_memcpy (buffer, &(key->type), sizeof (key->type));
139 GNUNET_memcpy (buffer + sizeof (key->type), &(key->ecdsa_key), length
140 - sizeof (key->type));
141 return length;
142}
143
144
147 size_t len,
148 struct
150 size_t *kb_read)
151{
152 if (len < sizeof (key->type))
153 return GNUNET_SYSERR;
154 GNUNET_memcpy (&key->type,
155 buffer,
156 sizeof (key->type));
157 ssize_t length = GNUNET_CRYPTO_private_key_get_length (key);
158 if (len < length)
159 return GNUNET_SYSERR;
160 if (length < 0)
161 return GNUNET_SYSERR;
162 GNUNET_memcpy (&key->ecdsa_key,
163 buffer + sizeof (key->type),
164 length - sizeof (key->type));
165 *kb_read = length;
166 return GNUNET_OK;
167}
168
169
170ssize_t
173 void *buffer,
174 size_t len)
175{
176 const ssize_t length = GNUNET_CRYPTO_private_key_get_length (key);
177 if (len < length)
178 return -1;
179 if (length < 0)
180 return -2;
181 GNUNET_memcpy (buffer, &(key->type), sizeof (key->type));
182 GNUNET_memcpy (buffer + sizeof (key->type), &(key->ecdsa_key), length
183 - sizeof (key->type));
184 return length;
185}
186
187
188ssize_t
191{
192 switch (ntohl (sig->type))
193 {
195 return sizeof (sig->type) + sizeof (sig->ecdsa_signature);
196 break;
198 return sizeof (sig->type) + sizeof (sig->eddsa_signature);
199 break;
200 default:
201 GNUNET_break (0);
202 }
203 return -1;
204}
205
206
207ssize_t
209{
210 switch (ntohl (type))
211 {
213 return sizeof (struct GNUNET_CRYPTO_EcdsaSignature);
214 break;
216 return sizeof (struct GNUNET_CRYPTO_EddsaSignature);
217 break;
218 default:
219 GNUNET_break (0);
220 }
221 return -1;
222}
223
224
225ssize_t
228 const void*buffer,
229 size_t len)
230{
231 if (len < sizeof (sig->type))
232 return -1;
233 GNUNET_memcpy (&(sig->type), buffer, sizeof (sig->type));
234 const ssize_t length = GNUNET_CRYPTO_signature_get_length (sig);
235 if (len < length)
236 return -1;
237 if (length < 0)
238 return -2;
239 GNUNET_memcpy (&(sig->ecdsa_signature), buffer + sizeof (sig->type), length
240 - sizeof (sig->type));
241 return length;
242}
243
244
245ssize_t
248 void*buffer,
249 size_t len)
250{
251 const ssize_t length = GNUNET_CRYPTO_signature_get_length (sig);
252 if (len < length)
253 return -1;
254 if (length < 0)
255 return -2;
256 GNUNET_memcpy (buffer, &(sig->type), sizeof (sig->type));
257 GNUNET_memcpy (buffer + sizeof (sig->type), &(sig->ecdsa_signature), length
258 - sizeof (sig->type));
259 return length;
260}
261
262
266 const struct
268 unsigned char *sig)
269{
270 switch (ntohl (priv->type))
271 {
273 return GNUNET_CRYPTO_ecdsa_sign_ (&(priv->ecdsa_key), purpose,
274 (struct
276 break;
278 return GNUNET_CRYPTO_eddsa_sign_ (&(priv->eddsa_key), purpose,
279 (struct
281 break;
282 default:
283 GNUNET_break (0);
284 }
285
286 return GNUNET_SYSERR;
287}
288
289
293 const struct
295 struct GNUNET_CRYPTO_Signature *sig)
296{
297 sig->type = priv->type;
298 switch (ntohl (priv->type))
299 {
301 return GNUNET_CRYPTO_ecdsa_sign_ (&(priv->ecdsa_key), purpose,
302 &(sig->ecdsa_signature));
303 break;
305 return GNUNET_CRYPTO_eddsa_sign_ (&(priv->eddsa_key), purpose,
306 &(sig->eddsa_signature));
307 break;
308 default:
309 GNUNET_break (0);
310 }
311
312 return GNUNET_SYSERR;
313}
314
315
318 const struct
320 const struct GNUNET_CRYPTO_Signature *sig,
321 const struct GNUNET_CRYPTO_PublicKey *pub)
322{
323 /* check type matching of 'sig' and 'pub' */
324 GNUNET_assert (ntohl (pub->type) == ntohl (sig->type));
325 switch (ntohl (pub->type))
326 {
328 return GNUNET_CRYPTO_ecdsa_verify_ (purpose, validate,
329 &(sig->ecdsa_signature),
330 &(pub->ecdsa_key));
331 break;
333 return GNUNET_CRYPTO_eddsa_verify_ (purpose, validate,
334 &(sig->eddsa_signature),
335 &(pub->eddsa_key));
336 break;
337 default:
338 GNUNET_break (0);
339 }
340
341 return GNUNET_SYSERR;
342}
343
344
347 const struct
349 validate,
350 const unsigned char *sig,
351 const struct
353{
354 switch (ntohl (pub->type))
355 {
357 return GNUNET_CRYPTO_ecdsa_verify_ (purpose, validate,
358 (struct
360 &(pub->ecdsa_key));
361 break;
363 return GNUNET_CRYPTO_eddsa_verify_ (purpose, validate,
364 (struct
366 &(pub->eddsa_key));
367 break;
368 default:
369 GNUNET_break (0);
370 }
371
372 return GNUNET_SYSERR;
373}
374
375
376ssize_t
377GNUNET_CRYPTO_encrypt_old (const void *block,
378 size_t size,
379 const struct GNUNET_CRYPTO_PublicKey *pub,
381 void *result)
382{
385 struct GNUNET_HashCode hash;
386 switch (ntohl (pub->type))
387 {
389 if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdh_ecdsa (&pk, &(pub->ecdsa_key),
390 &hash))
391 return -1;
392 break;
394 if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdh_eddsa (&pk, &(pub->eddsa_key),
395 &hash))
396 return -1;
397 break;
398 default:
399 return -1;
400 }
405 GNUNET_CRYPTO_hash_to_aes_key (&hash, &key, &iv);
406 GNUNET_CRYPTO_zero_keys (&hash, sizeof(hash));
407 const ssize_t encrypted = GNUNET_CRYPTO_symmetric_encrypt (block, size, &key,
408 &iv, result);
409 GNUNET_CRYPTO_zero_keys (&key, sizeof(key));
410 GNUNET_CRYPTO_zero_keys (&iv, sizeof(iv));
411 return encrypted;
412}
413
414
416GNUNET_CRYPTO_encrypt (const void *pt,
417 size_t pt_size,
418 const struct GNUNET_CRYPTO_PublicKey *pub,
419 void *ct_buf,
420 size_t ct_size)
421{
422 struct GNUNET_HashCode k;
423 struct GNUNET_CRYPTO_FoKemC kemc;
424 struct GNUNET_CRYPTO_FoKemC *kemc_buf = (struct GNUNET_CRYPTO_FoKemC*) ct_buf;
425 unsigned char *encrypted_data = (unsigned char*) &kemc_buf[1];
426 unsigned char nonce[crypto_secretbox_NONCEBYTES];
427 unsigned char key[crypto_secretbox_KEYBYTES];
428
429 if (ct_size < pt_size + GNUNET_CRYPTO_ENCRYPT_OVERHEAD_BYTES)
430 {
432 "Output buffer size for ciphertext too small: Got %llu, want >= %llu\n",
433 (unsigned long long) ct_size,
434 (unsigned long long) (pt_size
436 return GNUNET_SYSERR;
437 }
438 switch (ntohl (pub->type))
439 {
442 &kemc,
443 &k))
444 return GNUNET_SYSERR;
445 break;
448 &kemc,
449 &k))
450 return GNUNET_SYSERR;
451 break;
452 default:
453 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unsupported key type\n");
454 return GNUNET_SYSERR;
455 }
456 memcpy (key, &k, crypto_secretbox_KEYBYTES);
457 memcpy (nonce, ((char* ) &k) + crypto_secretbox_KEYBYTES,
458 crypto_secretbox_NONCEBYTES);
459 if (crypto_secretbox_easy (encrypted_data, pt, pt_size, nonce, key))
460 return GNUNET_SYSERR;
461 memcpy (kemc_buf, &kemc, sizeof (kemc));
462 return GNUNET_OK;
463}
464
465
467GNUNET_CRYPTO_decrypt (const void *ct_buf,
468 size_t ct_size,
469 const struct GNUNET_CRYPTO_PrivateKey *priv,
470 void *pt,
471 size_t pt_size)
472{
473 struct GNUNET_HashCode k;
474 struct GNUNET_CRYPTO_FoKemC *kemc = (struct GNUNET_CRYPTO_FoKemC*) ct_buf;
475 unsigned char *encrypted_data = (unsigned char*) &kemc[1];
476 unsigned char nonce[crypto_secretbox_NONCEBYTES];
477 unsigned char key[crypto_secretbox_KEYBYTES];
478 size_t expected_pt_len = ct_size - GNUNET_CRYPTO_ENCRYPT_OVERHEAD_BYTES;
479
480 if (pt_size < expected_pt_len)
481 {
483 "Output buffer size for plaintext too small: Got %llu, want >= %llu\n",
484 (unsigned long long) pt_size,
485 (unsigned long long) expected_pt_len);
486 return GNUNET_SYSERR;
487 }
488 switch (ntohl (priv->type))
489 {
492 kemc,
493 &k))
494 return GNUNET_SYSERR;
495 break;
498 kemc,
499 &k))
500 return GNUNET_SYSERR;
501 break;
502 default:
503 return GNUNET_SYSERR;
504 }
505 memcpy (key, &k, crypto_secretbox_KEYBYTES);
506 memcpy (nonce, ((char* ) &k) + crypto_secretbox_KEYBYTES,
507 crypto_secretbox_NONCEBYTES);
508 if (crypto_secretbox_open_easy (pt, encrypted_data, ct_size - sizeof (*kemc),
509 nonce, key))
510 return GNUNET_SYSERR;
511 return GNUNET_OK;
512}
513
514
515ssize_t
516GNUNET_CRYPTO_decrypt_old (const void *block,
517 size_t size,
518 const struct GNUNET_CRYPTO_PrivateKey *priv,
519 const struct GNUNET_CRYPTO_EcdhePublicKey *ecc,
520 void *result)
521{
522 struct GNUNET_HashCode hash;
523 switch (ntohl (priv->type))
524 {
527 &hash))
528 return -1;
529 break;
532 &hash))
533 return -1;
534 break;
535 default:
536 return -1;
537 }
540 GNUNET_CRYPTO_hash_to_aes_key (&hash, &key, &iv);
541 GNUNET_CRYPTO_zero_keys (&hash, sizeof(hash));
542 const ssize_t decrypted = GNUNET_CRYPTO_symmetric_decrypt (block, size, &key,
543 &iv, result);
544 GNUNET_CRYPTO_zero_keys (&key, sizeof(key));
545 GNUNET_CRYPTO_zero_keys (&iv, sizeof(iv));
546 return decrypted;
547}
548
549
550char *
553{
556 size);
557}
558
559
560char *
563{
566 size);
567}
568
569
573{
576 strlen (str),
577 key,
578 sizeof (*key));
579 if (GNUNET_OK != ret)
580 return GNUNET_SYSERR;
581 return check_key_type (ntohl (key->type));
582
583}
584
585
589{
592 strlen (str),
593 key,
594 sizeof (*key));
595 if (GNUNET_OK != ret)
596 return GNUNET_SYSERR;
597 return check_key_type (ntohl (key->type));
598}
599
600
605{
606 key->type = privkey->type;
607 switch (ntohl (privkey->type))
608 {
611 &key->ecdsa_key);
612 break;
615 &key->eddsa_key);
616 break;
617 default:
618 GNUNET_break (0);
619 return GNUNET_SYSERR;
620 }
621 return GNUNET_OK;
622}
ssize_t GNUNET_CRYPTO_private_key_length_by_type(enum GNUNET_CRYPTO_KeyType kt)
Definition: crypto_pkey.c:85
static enum GNUNET_GenericReturnValue check_key_type(uint32_t type)
Definition: crypto_pkey.c:32
static int ret
Final status code.
Definition: gnunet-arm.c:94
struct GNUNET_HashCode key
The key used in the DHT.
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
static uint32_t type
Type string converted to DNS type value.
static int result
Global testing status.
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:47
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_fo_kem_decaps(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, struct GNUNET_CRYPTO_FoKemC *c, struct GNUNET_HashCode *key_material)
Decapsulate key material using a CCA-secure KEM.
Definition: crypto_ecc.c:924
void GNUNET_CRYPTO_ecdhe_key_create(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:436
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_fo_kem_encaps(const struct GNUNET_CRYPTO_EddsaPublicKey *pub, struct GNUNET_CRYPTO_FoKemC *c, struct GNUNET_HashCode *key_material)
Encapsulate key material using a CCA-secure KEM.
Definition: crypto_ecc.c:840
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:198
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_ecdh(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material)
Derive key material from a ECDH public key and a private ECDSA key.
Definition: crypto_ecc.c:759
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_sign_(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EcdsaSignature *sig)
ECDSA Sign a given block.
Definition: crypto_ecc.c:536
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_fo_kem_encaps(const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, struct GNUNET_CRYPTO_FoKemC *c, struct GNUNET_HashCode *key_material)
Encapsulate key material using a CCA-secure KEM.
Definition: crypto_ecc.c:807
ssize_t GNUNET_CRYPTO_symmetric_encrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
Encrypt a block using a symmetric sessionkey.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_ecdh(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material)
Derive key material from a ECDH public key and a private EdDSA key.
Definition: crypto_ecc.c:727
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdh_ecdsa(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, struct GNUNET_HashCode *key_material)
Derive key material from a EcDSA public key and a private ECDH key.
Definition: crypto_ecc.c:940
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdh_eddsa(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EddsaPublicKey *pub, struct GNUNET_HashCode *key_material)
Derive key material from a EdDSA public key and a private ECDH key.
Definition: crypto_ecc.c:777
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_sign_(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
EdDSA sign a given block.
Definition: crypto_ecc.c:607
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_verify_(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EcdsaSignature *sig, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Verify ECDSA signature.
Definition: crypto_ecc.c:631
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_fo_kem_decaps(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_FoKemC *c, struct GNUNET_HashCode *key_material)
Decapsulate key material using a CCA-secure KEM.
Definition: crypto_ecc.c:908
void GNUNET_CRYPTO_ecdsa_key_get_public(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:187
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_verify_(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EddsaSignature *sig, const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Verify EdDSA signature.
Definition: crypto_ecc.c:690
void GNUNET_CRYPTO_zero_keys(void *buffer, size_t length)
Zero out buffer, securely against compiler optimizations.
void GNUNET_CRYPTO_ecdhe_key_clear(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Clear memory that was used to store a private key.
Definition: crypto_ecc.c:415
void GNUNET_CRYPTO_ecdhe_key_get_public(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, struct GNUNET_CRYPTO_EcdhePublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:214
ssize_t GNUNET_CRYPTO_symmetric_decrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
Decrypt a given block using a symmetric sessionkey.
void GNUNET_CRYPTO_hash_to_aes_key(const struct GNUNET_HashCode *hc, struct GNUNET_CRYPTO_SymmetricSessionKey *skey, struct GNUNET_CRYPTO_SymmetricInitializationVector *iv)
Convert a hashcode into a key.
Definition: crypto_hash.c:152
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_sign_raw_(const struct GNUNET_CRYPTO_PrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, unsigned char *sig)
Sign a given block.
Definition: crypto_pkey.c:264
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_signature_verify_raw_(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const unsigned char *sig, const struct GNUNET_CRYPTO_PublicKey *pub)
Verify a given signature.
Definition: crypto_pkey.c:346
ssize_t GNUNET_CRYPTO_read_signature_from_buffer(struct GNUNET_CRYPTO_Signature *sig, const void *buffer, size_t len)
Reads a GNUNET_CRYPTO_Signature from a compact buffer.
Definition: crypto_pkey.c:226
ssize_t GNUNET_CRYPTO_public_key_get_length(const struct GNUNET_CRYPTO_PublicKey *key)
Get the compacted length of a GNUNET_CRYPTO_PublicKey.
Definition: crypto_pkey.c:68
#define GNUNET_log(kind,...)
GNUNET_CRYPTO_KeyType
Key type for the generic public key union.
#define GNUNET_CRYPTO_ENCRYPT_OVERHEAD_BYTES
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_signature_verify_(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_Signature *sig, const struct GNUNET_CRYPTO_PublicKey *pub)
Verify a given signature.
Definition: crypto_pkey.c:317
ssize_t GNUNET_CRYPTO_decrypt_old(const void *block, size_t size, const struct GNUNET_CRYPTO_PrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *ecc, void *result)
Decrypt a given block with GNUNET_CRYPTO_PrivateKey and a given GNUNET_CRYPTO_EcdhePublicKey using ec...
Definition: crypto_pkey.c:516
char * GNUNET_CRYPTO_public_key_to_string(const struct GNUNET_CRYPTO_PublicKey *key)
Creates a (Base32) string representation of the public key.
Definition: crypto_pkey.c:551
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_encrypt(const void *pt, size_t pt_size, const struct GNUNET_CRYPTO_PublicKey *pub, void *ct_buf, size_t ct_size)
Encrypt a block with GNUNET_CRYPTO_PublicKey and derives a GNUNET_CRYPTO_EcdhePublicKey which is requ...
Definition: crypto_pkey.c:416
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_private_key_from_string(const char *str, struct GNUNET_CRYPTO_PrivateKey *key)
Parses a (Base32) string representation of the private key.
Definition: crypto_pkey.c:587
ssize_t GNUNET_CRYPTO_write_public_key_to_buffer(const struct GNUNET_CRYPTO_PublicKey *key, void *buffer, size_t len)
Writes a GNUNET_CRYPTO_PublicKey to a compact buffer.
Definition: crypto_pkey.c:128
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_key_get_public(const struct GNUNET_CRYPTO_PrivateKey *privkey, struct GNUNET_CRYPTO_PublicKey *key)
Retrieves the public key representation of a private key.
Definition: crypto_pkey.c:602
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_sign_(const struct GNUNET_CRYPTO_PrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_Signature *sig)
Sign a given block.
Definition: crypto_pkey.c:291
char * GNUNET_CRYPTO_private_key_to_string(const struct GNUNET_CRYPTO_PrivateKey *key)
Creates a (Base32) string representation of the private key.
Definition: crypto_pkey.c:561
ssize_t GNUNET_CRYPTO_encrypt_old(const void *block, size_t size, const struct GNUNET_CRYPTO_PublicKey *pub, struct GNUNET_CRYPTO_EcdhePublicKey *ecc, void *result)
Encrypt a block with GNUNET_CRYPTO_PublicKey and derives a GNUNET_CRYPTO_EcdhePublicKey which is requ...
Definition: crypto_pkey.c:377
ssize_t GNUNET_CRYPTO_signature_get_raw_length_by_type(uint32_t type)
Get the compacted length of a signature by type.
Definition: crypto_pkey.c:208
ssize_t GNUNET_CRYPTO_write_signature_to_buffer(const struct GNUNET_CRYPTO_Signature *sig, void *buffer, size_t len)
Writes a GNUNET_CRYPTO_Signature to a compact buffer.
Definition: crypto_pkey.c:246
ssize_t GNUNET_CRYPTO_private_key_get_length(const struct GNUNET_CRYPTO_PrivateKey *key)
Get the compacted length of a GNUNET_CRYPTO_PrivateKey.
Definition: crypto_pkey.c:47
ssize_t GNUNET_CRYPTO_write_private_key_to_buffer(const struct GNUNET_CRYPTO_PrivateKey *key, void *buffer, size_t len)
Writes a GNUNET_CRYPTO_PrivateKey to a compact buffer.
Definition: crypto_pkey.c:171
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_decrypt(const void *ct_buf, size_t ct_size, const struct GNUNET_CRYPTO_PrivateKey *priv, void *pt, size_t pt_size)
Decrypt a given block with GNUNET_CRYPTO_PrivateKey and a given GNUNET_CRYPTO_EcdhePublicKey using ec...
Definition: crypto_pkey.c:467
ssize_t GNUNET_CRYPTO_signature_get_length(const struct GNUNET_CRYPTO_Signature *sig)
Get the compacted length of a GNUNET_CRYPTO_Signature.
Definition: crypto_pkey.c:189
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_read_public_key_from_buffer(const void *buffer, size_t len, struct GNUNET_CRYPTO_PublicKey *key, size_t *kb_read)
Reads a GNUNET_CRYPTO_PublicKey from a compact buffer.
Definition: crypto_pkey.c:103
GNUNET_GenericReturnValue
Named constants for return values.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_read_private_key_from_buffer(const void *buffer, size_t len, struct GNUNET_CRYPTO_PrivateKey *key, size_t *kb_read)
Reads a GNUNET_CRYPTO_PrivateKey from a compact buffer.
Definition: crypto_pkey.c:146
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_public_key_from_string(const char *str, struct GNUNET_CRYPTO_PublicKey *key)
Parses a (Base32) string representation of the public key.
Definition: crypto_pkey.c:571
@ GNUNET_PUBLIC_KEY_TYPE_EDDSA
EDDSA identity.
@ GNUNET_PUBLIC_KEY_TYPE_ECDSA
The identity type.
@ GNUNET_OK
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_ERROR
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:764
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:789
static unsigned int size
Size of the "table".
Definition: peer.c:68
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
Private ECC key encoded for transmission.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
Private ECC key encoded for transmission.
an ECC signature using ECDSA
an ECC signature using EdDSA.
This is the encapsulated key of our FO-KEM.
A private key for an identity as per LSD0001.
uint32_t type
Type of public key.
struct GNUNET_CRYPTO_EddsaPrivateKey eddsa_key
AN EdDSA identtiy key.
struct GNUNET_CRYPTO_EcdsaPrivateKey ecdsa_key
An ECDSA identity key.
An identity key as per LSD0001.
An identity signature as per LSD0001.
struct GNUNET_CRYPTO_EddsaSignature eddsa_signature
AN EdDSA signature.
struct GNUNET_CRYPTO_EcdsaSignature ecdsa_signature
An ECDSA signature.
uint32_t type
Type of signature.
A 512-bit hashcode.