diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2022-08-31 17:04:24 +0200 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2022-08-31 17:04:24 +0200 |
commit | cc70504a2f2756107976924843fe6b39b9ac94cb (patch) | |
tree | 05b3fe4d969d157903c30e720adb7e8227b24f00 /src/util | |
parent | fcfa115e2a1416df949d88dbb25898d8492f513a (diff) | |
parent | 2a46a30bdbfbcf07a755bd83a876ef9a7e7643fb (diff) | |
download | gnunet-cc70504a2f2756107976924843fe6b39b9ac94cb.tar.gz gnunet-cc70504a2f2756107976924843fe6b39b9ac94cb.zip |
Merge branch 'dev/trizuz/siop'
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/.gitignore | 2 | ||||
-rw-r--r-- | src/util/Makefile.am | 6 | ||||
-rw-r--r-- | src/util/crypto_ecc.c | 64 | ||||
-rw-r--r-- | src/util/test_crypto_ecc.c | 57 |
4 files changed, 129 insertions, 0 deletions
diff --git a/src/util/.gitignore b/src/util/.gitignore index 0e3449fed..6151c4f7a 100644 --- a/src/util/.gitignore +++ b/src/util/.gitignore | |||
@@ -85,3 +85,5 @@ perf_malloc | |||
85 | perf_mq | 85 | perf_mq |
86 | perf_scheduler | 86 | perf_scheduler |
87 | gnunet-base32 | 87 | gnunet-base32 |
88 | test_crypto_cs | ||
89 | test_crypto_ecc | ||
diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 9cb7da15b..b86fa0f12 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am | |||
@@ -292,6 +292,7 @@ check_PROGRAMS = \ | |||
292 | test_container_heap \ | 292 | test_container_heap \ |
293 | test_crypto_symmetric \ | 293 | test_crypto_symmetric \ |
294 | test_crypto_crc \ | 294 | test_crypto_crc \ |
295 | test_crypto_ecc \ | ||
295 | test_crypto_cs \ | 296 | test_crypto_cs \ |
296 | test_crypto_ecdsa \ | 297 | test_crypto_ecdsa \ |
297 | test_crypto_eddsa \ | 298 | test_crypto_eddsa \ |
@@ -460,6 +461,11 @@ test_crypto_cs_LDADD = \ | |||
460 | libgnunetutil.la \ | 461 | libgnunetutil.la \ |
461 | -lsodium | 462 | -lsodium |
462 | 463 | ||
464 | test_crypto_ecc_SOURCES = \ | ||
465 | test_crypto_ecc.c | ||
466 | test_crypto_ecc_LDADD = \ | ||
467 | libgnunetutil.la | ||
468 | |||
463 | test_crypto_ecdsa_SOURCES = \ | 469 | test_crypto_ecdsa_SOURCES = \ |
464 | test_crypto_ecdsa.c | 470 | test_crypto_ecdsa.c |
465 | test_crypto_ecdsa_LDADD = \ | 471 | test_crypto_ecdsa_LDADD = \ |
diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c index 0e73078bd..8eba2f635 100644 --- a/src/util/crypto_ecc.c +++ b/src/util/crypto_ecc.c | |||
@@ -594,6 +594,70 @@ GNUNET_CRYPTO_ecdsa_sign_ ( | |||
594 | return GNUNET_OK; | 594 | return GNUNET_OK; |
595 | } | 595 | } |
596 | 596 | ||
597 | enum GNUNET_GenericReturnValue | ||
598 | GNUNET_CRYPTO_eddsa_sign_raw ( | ||
599 | const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, | ||
600 | void *data, | ||
601 | size_t size, | ||
602 | struct GNUNET_CRYPTO_EddsaSignature *sig) | ||
603 | { | ||
604 | unsigned char sk[crypto_sign_SECRETKEYBYTES]; | ||
605 | unsigned char pk[crypto_sign_PUBLICKEYBYTES]; | ||
606 | int res; | ||
607 | |||
608 | GNUNET_assert (0 == crypto_sign_seed_keypair (pk, sk, priv->d)); | ||
609 | res = crypto_sign_detached ((uint8_t *) sig, | ||
610 | NULL, | ||
611 | (uint8_t *) data, | ||
612 | size, | ||
613 | sk); | ||
614 | return (res == 0) ? GNUNET_OK : GNUNET_SYSERR; | ||
615 | } | ||
616 | |||
617 | size_t | ||
618 | GNUNET_CRYPTO_eddsa_signature_encode ( | ||
619 | const struct GNUNET_CRYPTO_EddsaSignature *sig, | ||
620 | char **sig_str) | ||
621 | { | ||
622 | return GNUNET_STRINGS_base64url_encode ( | ||
623 | (void*) sig, | ||
624 | 64, | ||
625 | sig_str); | ||
626 | } | ||
627 | |||
628 | size_t | ||
629 | GNUNET_CRYPTO_eddsa_signature_decode ( | ||
630 | const char *sig_str, | ||
631 | struct GNUNET_CRYPTO_EddsaSignature *sig) | ||
632 | { | ||
633 | return GNUNET_STRINGS_base64url_decode ( | ||
634 | sig_str, | ||
635 | strlen (sig_str), | ||
636 | (void **) &sig); | ||
637 | } | ||
638 | |||
639 | size_t | ||
640 | GNUNET_CRYPTO_ecdsa_signature_encode ( | ||
641 | const struct GNUNET_CRYPTO_EcdsaSignature *sig, | ||
642 | char **sig_str) | ||
643 | { | ||
644 | return GNUNET_STRINGS_base64url_encode ( | ||
645 | (void*) sig, | ||
646 | 64, | ||
647 | sig_str); | ||
648 | } | ||
649 | |||
650 | size_t | ||
651 | GNUNET_CRYPTO_ecdsa_signature_decode ( | ||
652 | const char *sig_str, | ||
653 | struct GNUNET_CRYPTO_EcdsaSignature *sig) | ||
654 | { | ||
655 | return GNUNET_STRINGS_base64url_decode ( | ||
656 | sig_str, | ||
657 | strlen (sig_str), | ||
658 | (void **) &sig); | ||
659 | } | ||
660 | |||
597 | 661 | ||
598 | enum GNUNET_GenericReturnValue | 662 | enum GNUNET_GenericReturnValue |
599 | GNUNET_CRYPTO_eddsa_sign_ ( | 663 | GNUNET_CRYPTO_eddsa_sign_ ( |
diff --git a/src/util/test_crypto_ecc.c b/src/util/test_crypto_ecc.c new file mode 100644 index 000000000..ebfa04c45 --- /dev/null +++ b/src/util/test_crypto_ecc.c | |||
@@ -0,0 +1,57 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2002-2015 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 | */ | ||
21 | /** | ||
22 | * @file util/test_crypto_ecc.c | ||
23 | * @brief test case for crypto_ecc.c GNUNET_CRYPTO_ecdsa_sign_raw() function | ||
24 | * @author Tristan Schwieren | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | |||
29 | static int | ||
30 | test_GNUNET_CRYPTO_ecdsa_sign_raw () | ||
31 | { | ||
32 | struct GNUNET_CRYPTO_EcdsaPrivateKey skey; | ||
33 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | ||
34 | struct GNUNET_CRYPTO_EcdsaSignature sig; | ||
35 | const char *test_data = "Hello World!"; | ||
36 | |||
37 | /* Generate keys */ | ||
38 | GNUNET_CRYPTO_ecdsa_key_create (&skey); | ||
39 | GNUNET_CRYPTO_ecdsa_key_get_public (&skey, &pkey); | ||
40 | |||
41 | GNUNET_assert (GNUNET_OK == | ||
42 | GNUNET_CRYPTO_ecdsa_sign_raw (&skey, | ||
43 | test_data, | ||
44 | strlen (test_data), | ||
45 | &sig)); | ||
46 | |||
47 | return 0; | ||
48 | } | ||
49 | |||
50 | int | ||
51 | main (int argc, char *argv[]) | ||
52 | { | ||
53 | return test_GNUNET_CRYPTO_ecdsa_sign_raw (); | ||
54 | } | ||
55 | |||
56 | |||
57 | /* end of test_crypto_ecc.c */ | ||