GNUnet 0.21.2
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
46void
48{
49 switch (ntohl (key->type))
50 {
53 break;
56 break;
57 default:
58 GNUNET_break (0);
59 }
60}
61
62
63ssize_t
66{
67 switch (ntohl (key->type))
68 {
70 return sizeof (key->type) + sizeof (key->ecdsa_key);
71 break;
73 return sizeof (key->type) + sizeof (key->eddsa_key);
74 break;
75 default:
77 "Got key type %u\n", ntohl (key->type));
78 GNUNET_break (0);
79 }
80 return -1;
81}
82
83
84ssize_t
87{
88 switch (ntohl (key->type))
89 {
91 return sizeof (key->type) + sizeof (key->ecdsa_key);
93 return sizeof (key->type) + sizeof (key->eddsa_key);
94 default:
95 GNUNET_break (0);
96 }
97 return -1;
98}
99
100
101ssize_t
103{
104 switch (kt)
105 {
107 return sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey);
108 break;
110 return sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey);
111 break;
112 default:
113 GNUNET_break (0);
114 }
115 return -1;
116}
117
118
121 size_t len,
123 key,
124 size_t *kb_read)
125{
126 if (len < sizeof (key->type))
127 return GNUNET_SYSERR;
128 GNUNET_memcpy (&key->type,
129 buffer,
130 sizeof (key->type));
131 ssize_t length = GNUNET_CRYPTO_public_key_get_length (key);
132 if (len < length)
133 return GNUNET_SYSERR;
134 if (length < 0)
135 return GNUNET_SYSERR;
136 GNUNET_memcpy (&key->ecdsa_key,
137 buffer + sizeof (key->type),
138 length - sizeof (key->type));
139 *kb_read = length;
140 return GNUNET_OK;
141}
142
143
144ssize_t
147 void*buffer,
148 size_t len)
149{
150 const ssize_t length = GNUNET_CRYPTO_public_key_get_length (key);
151 if (len < length)
152 return -1;
153 if (length < 0)
154 return -2;
155 GNUNET_memcpy (buffer, &(key->type), sizeof (key->type));
156 GNUNET_memcpy (buffer + sizeof (key->type), &(key->ecdsa_key), length
157 - sizeof (key->type));
158 return length;
159}
160
161
164 size_t len,
165 struct
167 size_t *kb_read)
168{
169 if (len < sizeof (key->type))
170 return GNUNET_SYSERR;
171 GNUNET_memcpy (&key->type,
172 buffer,
173 sizeof (key->type));
174 ssize_t length = GNUNET_CRYPTO_private_key_get_length (key);
175 if (len < length)
176 return GNUNET_SYSERR;
177 if (length < 0)
178 return GNUNET_SYSERR;
179 GNUNET_memcpy (&key->ecdsa_key,
180 buffer + sizeof (key->type),
181 length - sizeof (key->type));
182 *kb_read = length;
183 return GNUNET_OK;
184}
185
186
187ssize_t
190 void *buffer,
191 size_t len)
192{
193 const ssize_t length = GNUNET_CRYPTO_private_key_get_length (key);
194 if (len < length)
195 return -1;
196 if (length < 0)
197 return -2;
198 GNUNET_memcpy (buffer, &(key->type), sizeof (key->type));
199 GNUNET_memcpy (buffer + sizeof (key->type), &(key->ecdsa_key), length
200 - sizeof (key->type));
201 return length;
202}
203
204
205ssize_t
208{
209 switch (ntohl (sig->type))
210 {
212 return sizeof (sig->type) + sizeof (sig->ecdsa_signature);
213 break;
215 return sizeof (sig->type) + sizeof (sig->eddsa_signature);
216 break;
217 default:
218 GNUNET_break (0);
219 }
220 return -1;
221}
222
223
224ssize_t
226{
227 switch (ntohl (type))
228 {
230 return sizeof (struct GNUNET_CRYPTO_EcdsaSignature);
231 break;
233 return sizeof (struct GNUNET_CRYPTO_EddsaSignature);
234 break;
235 default:
236 GNUNET_break (0);
237 }
238 return -1;
239}
240
241
242ssize_t
245 const void*buffer,
246 size_t len)
247{
248 if (len < sizeof (sig->type))
249 return -1;
250 GNUNET_memcpy (&(sig->type), buffer, sizeof (sig->type));
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 (&(sig->ecdsa_signature), buffer + sizeof (sig->type), length
257 - sizeof (sig->type));
258 return length;
259}
260
261
262ssize_t
265 void*buffer,
266 size_t len)
267{
268 const ssize_t length = GNUNET_CRYPTO_signature_get_length (sig);
269 if (len < length)
270 return -1;
271 if (length < 0)
272 return -2;
273 GNUNET_memcpy (buffer, &(sig->type), sizeof (sig->type));
274 GNUNET_memcpy (buffer + sizeof (sig->type), &(sig->ecdsa_signature), length
275 - sizeof (sig->type));
276 return length;
277}
278
279
283 const struct
285 unsigned char *sig)
286{
287 switch (ntohl (priv->type))
288 {
290 return GNUNET_CRYPTO_ecdsa_sign_ (&(priv->ecdsa_key), purpose,
291 (struct
293 break;
295 return GNUNET_CRYPTO_eddsa_sign_ (&(priv->eddsa_key), purpose,
296 (struct
298 break;
299 default:
300 GNUNET_break (0);
301 }
302
303 return GNUNET_SYSERR;
304}
305
306
310 const struct
312 struct GNUNET_CRYPTO_Signature *sig)
313{
314 sig->type = priv->type;
315 switch (ntohl (priv->type))
316 {
318 return GNUNET_CRYPTO_ecdsa_sign_ (&(priv->ecdsa_key), purpose,
319 &(sig->ecdsa_signature));
320 break;
322 return GNUNET_CRYPTO_eddsa_sign_ (&(priv->eddsa_key), purpose,
323 &(sig->eddsa_signature));
324 break;
325 default:
326 GNUNET_break (0);
327 }
328
329 return GNUNET_SYSERR;
330}
331
332
335 const struct
337 const struct GNUNET_CRYPTO_Signature *sig,
338 const struct GNUNET_CRYPTO_PublicKey *pub)
339{
340 /* check type matching of 'sig' and 'pub' */
341 GNUNET_assert (ntohl (pub->type) == ntohl (sig->type));
342 switch (ntohl (pub->type))
343 {
345 return GNUNET_CRYPTO_ecdsa_verify_ (purpose, validate,
346 &(sig->ecdsa_signature),
347 &(pub->ecdsa_key));
348 break;
350 return GNUNET_CRYPTO_eddsa_verify_ (purpose, validate,
351 &(sig->eddsa_signature),
352 &(pub->eddsa_key));
353 break;
354 default:
355 GNUNET_break (0);
356 }
357
358 return GNUNET_SYSERR;
359}
360
361
364 const struct
366 validate,
367 const unsigned char *sig,
368 const struct
370{
371 switch (ntohl (pub->type))
372 {
374 return GNUNET_CRYPTO_ecdsa_verify_ (purpose, validate,
375 (struct
377 &(pub->ecdsa_key));
378 break;
380 return GNUNET_CRYPTO_eddsa_verify_ (purpose, validate,
381 (struct
383 &(pub->eddsa_key));
384 break;
385 default:
386 GNUNET_break (0);
387 }
388
389 return GNUNET_SYSERR;
390}
391
392
393ssize_t
394GNUNET_CRYPTO_encrypt_old (const void *block,
395 size_t size,
396 const struct GNUNET_CRYPTO_PublicKey *pub,
398 void *result)
399{
402 struct GNUNET_HashCode hash;
403 switch (ntohl (pub->type))
404 {
406 if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdh_ecdsa (&pk, &(pub->ecdsa_key),
407 &hash))
408 return -1;
409 break;
411 if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdh_eddsa (&pk, &(pub->eddsa_key),
412 &hash))
413 return -1;
414 break;
415 default:
416 return -1;
417 }
422 GNUNET_CRYPTO_hash_to_aes_key (&hash, &key, &iv);
423 GNUNET_CRYPTO_zero_keys (&hash, sizeof(hash));
424 const ssize_t encrypted = GNUNET_CRYPTO_symmetric_encrypt (block, size, &key,
425 &iv, result);
426 GNUNET_CRYPTO_zero_keys (&key, sizeof(key));
427 GNUNET_CRYPTO_zero_keys (&iv, sizeof(iv));
428 return encrypted;
429}
430
431
433GNUNET_CRYPTO_encrypt (const void *pt,
434 size_t pt_size,
435 const struct GNUNET_CRYPTO_PublicKey *pub,
436 void *ct_buf,
437 size_t ct_size)
438{
439 struct GNUNET_HashCode k;
440 struct GNUNET_CRYPTO_FoKemC kemc;
441 struct GNUNET_CRYPTO_FoKemC *kemc_buf = (struct GNUNET_CRYPTO_FoKemC*) ct_buf;
442 unsigned char *encrypted_data = (unsigned char*) &kemc_buf[1];
443 unsigned char nonce[crypto_secretbox_NONCEBYTES];
444 unsigned char key[crypto_secretbox_KEYBYTES];
445
446 if (ct_size < pt_size + GNUNET_CRYPTO_ENCRYPT_OVERHEAD_BYTES)
447 {
449 "Output buffer size for ciphertext too small: Got %llu, want >= %llu\n",
450 (unsigned long long) ct_size,
451 (unsigned long long) (pt_size
453 return GNUNET_SYSERR;
454 }
455 switch (ntohl (pub->type))
456 {
459 &kemc,
460 &k))
461 return GNUNET_SYSERR;
462 break;
465 &kemc,
466 &k))
467 return GNUNET_SYSERR;
468 break;
469 default:
470 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unsupported key type\n");
471 return GNUNET_SYSERR;
472 }
473 memcpy (key, &k, crypto_secretbox_KEYBYTES);
474 memcpy (nonce, ((char* ) &k) + crypto_secretbox_KEYBYTES,
475 crypto_secretbox_NONCEBYTES);
476 if (crypto_secretbox_easy (encrypted_data, pt, pt_size, nonce, key))
477 return GNUNET_SYSERR;
478 memcpy (kemc_buf, &kemc, sizeof (kemc));
479 return GNUNET_OK;
480}
481
482
484GNUNET_CRYPTO_decrypt (const void *ct_buf,
485 size_t ct_size,
486 const struct GNUNET_CRYPTO_PrivateKey *priv,
487 void *pt,
488 size_t pt_size)
489{
490 struct GNUNET_HashCode k;
491 struct GNUNET_CRYPTO_FoKemC *kemc = (struct GNUNET_CRYPTO_FoKemC*) ct_buf;
492 unsigned char *encrypted_data = (unsigned char*) &kemc[1];
493 unsigned char nonce[crypto_secretbox_NONCEBYTES];
494 unsigned char key[crypto_secretbox_KEYBYTES];
495 size_t expected_pt_len = ct_size - GNUNET_CRYPTO_ENCRYPT_OVERHEAD_BYTES;
496
497 if (pt_size < expected_pt_len)
498 {
500 "Output buffer size for plaintext too small: Got %llu, want >= %llu\n",
501 (unsigned long long) pt_size,
502 (unsigned long long) expected_pt_len);
503 return GNUNET_SYSERR;
504 }
505 switch (ntohl (priv->type))
506 {
509 kemc,
510 &k))
511 return GNUNET_SYSERR;
512 break;
515 kemc,
516 &k))
517 return GNUNET_SYSERR;
518 break;
519 default:
520 return GNUNET_SYSERR;
521 }
522 memcpy (key, &k, crypto_secretbox_KEYBYTES);
523 memcpy (nonce, ((char* ) &k) + crypto_secretbox_KEYBYTES,
524 crypto_secretbox_NONCEBYTES);
525 if (crypto_secretbox_open_easy (pt, encrypted_data, ct_size - sizeof (*kemc),
526 nonce, key))
527 return GNUNET_SYSERR;
528 return GNUNET_OK;
529}
530
531
532ssize_t
533GNUNET_CRYPTO_decrypt_old (const void *block,
534 size_t size,
535 const struct GNUNET_CRYPTO_PrivateKey *priv,
536 const struct GNUNET_CRYPTO_EcdhePublicKey *ecc,
537 void *result)
538{
539 struct GNUNET_HashCode hash;
540 switch (ntohl (priv->type))
541 {
544 &hash))
545 return -1;
546 break;
549 &hash))
550 return -1;
551 break;
552 default:
553 return -1;
554 }
557 GNUNET_CRYPTO_hash_to_aes_key (&hash, &key, &iv);
558 GNUNET_CRYPTO_zero_keys (&hash, sizeof(hash));
559 const ssize_t decrypted = GNUNET_CRYPTO_symmetric_decrypt (block, size, &key,
560 &iv, result);
561 GNUNET_CRYPTO_zero_keys (&key, sizeof(key));
562 GNUNET_CRYPTO_zero_keys (&iv, sizeof(iv));
563 return decrypted;
564}
565
566
567char *
570{
573 size);
574}
575
576
577char *
580{
583 size);
584}
585
586
590{
593 strlen (str),
594 key,
595 sizeof (*key));
596 if (GNUNET_OK != ret)
597 return GNUNET_SYSERR;
598 return check_key_type (ntohl (key->type));
599
600}
601
602
606{
609 strlen (str),
610 key,
611 sizeof (*key));
612 if (GNUNET_OK != ret)
613 return GNUNET_SYSERR;
614 return check_key_type (ntohl (key->type));
615}
616
617
622{
623 key->type = privkey->type;
624 switch (ntohl (privkey->type))
625 {
628 &key->ecdsa_key);
629 break;
632 &key->eddsa_key);
633 break;
634 default:
635 GNUNET_break (0);
636 return GNUNET_SYSERR;
637 }
638 return GNUNET_OK;
639}
ssize_t GNUNET_CRYPTO_private_key_length_by_type(enum GNUNET_CRYPTO_KeyType kt)
Definition: crypto_pkey.c:102
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:1010
void GNUNET_CRYPTO_ecdhe_key_create(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:454
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:926
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
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:845
void GNUNET_CRYPTO_eddsa_key_clear(struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
Clear memory that was used to store a private key.
Definition: crypto_ecc.c:447
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:554
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:893
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:745
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:1026
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:863
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:625
void GNUNET_CRYPTO_ecdsa_key_clear(struct GNUNET_CRYPTO_EcdsaPrivateKey *pk)
Clear memory that was used to store a private key.
Definition: crypto_ecc.c:440
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:649
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:994
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:190
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:708
void GNUNET_CRYPTO_private_key_clear(struct GNUNET_CRYPTO_PrivateKey *key)
Clear memory that was used to store a private key.
Definition: crypto_pkey.c:47
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:433
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:217
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:281
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:363
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:243
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:85
#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:334
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:533
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:568
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:433
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:604
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:145
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:619
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:308
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:578
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:394
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:225
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:263
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:64
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:188
#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:484
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:206
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:120
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:163
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:588
@ 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.