diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-03-17 01:04:35 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-03-17 01:04:35 +0100 |
commit | cb50ebbc641ed40d24a0fed24797dded5bcc5745 (patch) | |
tree | 62be950837fdb7ebce737c8be4977676cd12f978 /src | |
parent | 39c6d488d4b8b8061ac33a902064cd5b2167b60c (diff) | |
download | gnunet-cb50ebbc641ed40d24a0fed24797dded5bcc5745.tar.gz gnunet-cb50ebbc641ed40d24a0fed24797dded5bcc5745.zip |
use void * instead of char * for RSA key material to make it more clear that these are not 0-terminated strings
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_crypto_lib.h | 18 | ||||
-rw-r--r-- | src/util/crypto_rsa.c | 57 |
2 files changed, 40 insertions, 35 deletions
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index 00fe3fbef..f22e87075 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h | |||
@@ -1908,7 +1908,7 @@ GNUNET_CRYPTO_rsa_private_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *key); | |||
1908 | size_t | 1908 | size_t |
1909 | GNUNET_CRYPTO_rsa_private_key_encode ( | 1909 | GNUNET_CRYPTO_rsa_private_key_encode ( |
1910 | const struct GNUNET_CRYPTO_RsaPrivateKey *key, | 1910 | const struct GNUNET_CRYPTO_RsaPrivateKey *key, |
1911 | char **buffer); | 1911 | void **buffer); |
1912 | 1912 | ||
1913 | 1913 | ||
1914 | /** | 1914 | /** |
@@ -1916,11 +1916,12 @@ GNUNET_CRYPTO_rsa_private_key_encode ( | |||
1916 | * to the "normal", internal format. | 1916 | * to the "normal", internal format. |
1917 | * | 1917 | * |
1918 | * @param buf the buffer where the private key data is stored | 1918 | * @param buf the buffer where the private key data is stored |
1919 | * @param len the length of the data in @a buf | 1919 | * @param buf_size the size of the data in @a buf |
1920 | * @return NULL on error | 1920 | * @return NULL on error |
1921 | */ | 1921 | */ |
1922 | struct GNUNET_CRYPTO_RsaPrivateKey * | 1922 | struct GNUNET_CRYPTO_RsaPrivateKey * |
1923 | GNUNET_CRYPTO_rsa_private_key_decode (const char *buf, size_t len); | 1923 | GNUNET_CRYPTO_rsa_private_key_decode (const void *buf, |
1924 | size_t buf_size); | ||
1924 | 1925 | ||
1925 | 1926 | ||
1926 | /** | 1927 | /** |
@@ -1986,7 +1987,7 @@ GNUNET_CRYPTO_rsa_public_key_free (struct GNUNET_CRYPTO_RsaPublicKey *key); | |||
1986 | size_t | 1987 | size_t |
1987 | GNUNET_CRYPTO_rsa_public_key_encode ( | 1988 | GNUNET_CRYPTO_rsa_public_key_encode ( |
1988 | const struct GNUNET_CRYPTO_RsaPublicKey *key, | 1989 | const struct GNUNET_CRYPTO_RsaPublicKey *key, |
1989 | char **buffer); | 1990 | void **buffer); |
1990 | 1991 | ||
1991 | 1992 | ||
1992 | /** | 1993 | /** |
@@ -2060,7 +2061,7 @@ int | |||
2060 | GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, | 2061 | GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, |
2061 | const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, | 2062 | const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, |
2062 | struct GNUNET_CRYPTO_RsaPublicKey *pkey, | 2063 | struct GNUNET_CRYPTO_RsaPublicKey *pkey, |
2063 | char **buf, | 2064 | void **buf, |
2064 | size_t *buf_size); | 2065 | size_t *buf_size); |
2065 | 2066 | ||
2066 | 2067 | ||
@@ -2109,7 +2110,7 @@ GNUNET_CRYPTO_rsa_signature_free (struct GNUNET_CRYPTO_RsaSignature *sig); | |||
2109 | size_t | 2110 | size_t |
2110 | GNUNET_CRYPTO_rsa_signature_encode ( | 2111 | GNUNET_CRYPTO_rsa_signature_encode ( |
2111 | const struct GNUNET_CRYPTO_RsaSignature *sig, | 2112 | const struct GNUNET_CRYPTO_RsaSignature *sig, |
2112 | char **buffer); | 2113 | void **buffer); |
2113 | 2114 | ||
2114 | 2115 | ||
2115 | /** | 2116 | /** |
@@ -2117,11 +2118,12 @@ GNUNET_CRYPTO_rsa_signature_encode ( | |||
2117 | * format. | 2118 | * format. |
2118 | * | 2119 | * |
2119 | * @param buf the buffer where the public key data is stored | 2120 | * @param buf the buffer where the public key data is stored |
2120 | * @param len the length of the data in @a buf | 2121 | * @param buf_size the number of bytes of the data in @a buf |
2121 | * @return NULL on error | 2122 | * @return NULL on error |
2122 | */ | 2123 | */ |
2123 | struct GNUNET_CRYPTO_RsaSignature * | 2124 | struct GNUNET_CRYPTO_RsaSignature * |
2124 | GNUNET_CRYPTO_rsa_signature_decode (const char *buf, size_t len); | 2125 | GNUNET_CRYPTO_rsa_signature_decode (const void *buf, |
2126 | size_t buf_size); | ||
2125 | 2127 | ||
2126 | 2128 | ||
2127 | /** | 2129 | /** |
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c index f0d564790..2957546a7 100644 --- a/src/util/crypto_rsa.c +++ b/src/util/crypto_rsa.c | |||
@@ -198,7 +198,7 @@ GNUNET_CRYPTO_rsa_private_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *key) | |||
198 | size_t | 198 | size_t |
199 | GNUNET_CRYPTO_rsa_private_key_encode (const struct | 199 | GNUNET_CRYPTO_rsa_private_key_encode (const struct |
200 | GNUNET_CRYPTO_RsaPrivateKey *key, | 200 | GNUNET_CRYPTO_RsaPrivateKey *key, |
201 | char **buffer) | 201 | void **buffer) |
202 | { | 202 | { |
203 | size_t n; | 203 | size_t n; |
204 | char *b; | 204 | char *b; |
@@ -223,12 +223,12 @@ GNUNET_CRYPTO_rsa_private_key_encode (const struct | |||
223 | * to the "normal", internal format. | 223 | * to the "normal", internal format. |
224 | * | 224 | * |
225 | * @param buf the buffer where the private key data is stored | 225 | * @param buf the buffer where the private key data is stored |
226 | * @param len the length of the data in @a buf | 226 | * @param buf_size the size of the data in @a buf |
227 | * @return NULL on error | 227 | * @return NULL on error |
228 | */ | 228 | */ |
229 | struct GNUNET_CRYPTO_RsaPrivateKey * | 229 | struct GNUNET_CRYPTO_RsaPrivateKey * |
230 | GNUNET_CRYPTO_rsa_private_key_decode (const char *buf, | 230 | GNUNET_CRYPTO_rsa_private_key_decode (const void *buf, |
231 | size_t len) | 231 | size_t buf_size) |
232 | { | 232 | { |
233 | struct GNUNET_CRYPTO_RsaPrivateKey *key; | 233 | struct GNUNET_CRYPTO_RsaPrivateKey *key; |
234 | 234 | ||
@@ -236,7 +236,7 @@ GNUNET_CRYPTO_rsa_private_key_decode (const char *buf, | |||
236 | if (0 != | 236 | if (0 != |
237 | gcry_sexp_new (&key->sexp, | 237 | gcry_sexp_new (&key->sexp, |
238 | buf, | 238 | buf, |
239 | len, | 239 | buf_size, |
240 | 0)) | 240 | 0)) |
241 | { | 241 | { |
242 | LOG (GNUNET_ERROR_TYPE_WARNING, | 242 | LOG (GNUNET_ERROR_TYPE_WARNING, |
@@ -343,9 +343,9 @@ GNUNET_NETWORK_STRUCT_END | |||
343 | * @return size of memory allocated in @a buffer | 343 | * @return size of memory allocated in @a buffer |
344 | */ | 344 | */ |
345 | size_t | 345 | size_t |
346 | GNUNET_CRYPTO_rsa_public_key_encode (const struct | 346 | GNUNET_CRYPTO_rsa_public_key_encode ( |
347 | GNUNET_CRYPTO_RsaPublicKey *key, | 347 | const struct GNUNET_CRYPTO_RsaPublicKey *key, |
348 | char **buffer) | 348 | void **buffer) |
349 | { | 349 | { |
350 | gcry_mpi_t ne[2]; | 350 | gcry_mpi_t ne[2]; |
351 | size_t n_size; | 351 | size_t n_size; |
@@ -419,7 +419,7 @@ void | |||
419 | GNUNET_CRYPTO_rsa_public_key_hash (const struct GNUNET_CRYPTO_RsaPublicKey *key, | 419 | GNUNET_CRYPTO_rsa_public_key_hash (const struct GNUNET_CRYPTO_RsaPublicKey *key, |
420 | struct GNUNET_HashCode *hc) | 420 | struct GNUNET_HashCode *hc) |
421 | { | 421 | { |
422 | char *buf; | 422 | void *buf; |
423 | size_t buf_size; | 423 | size_t buf_size; |
424 | 424 | ||
425 | buf_size = GNUNET_CRYPTO_rsa_public_key_encode (key, | 425 | buf_size = GNUNET_CRYPTO_rsa_public_key_encode (key, |
@@ -623,8 +623,8 @@ int | |||
623 | GNUNET_CRYPTO_rsa_signature_cmp (struct GNUNET_CRYPTO_RsaSignature *s1, | 623 | GNUNET_CRYPTO_rsa_signature_cmp (struct GNUNET_CRYPTO_RsaSignature *s1, |
624 | struct GNUNET_CRYPTO_RsaSignature *s2) | 624 | struct GNUNET_CRYPTO_RsaSignature *s2) |
625 | { | 625 | { |
626 | char *b1; | 626 | void *b1; |
627 | char *b2; | 627 | void *b2; |
628 | size_t z1; | 628 | size_t z1; |
629 | size_t z2; | 629 | size_t z2; |
630 | int ret; | 630 | int ret; |
@@ -656,8 +656,8 @@ int | |||
656 | GNUNET_CRYPTO_rsa_public_key_cmp (struct GNUNET_CRYPTO_RsaPublicKey *p1, | 656 | GNUNET_CRYPTO_rsa_public_key_cmp (struct GNUNET_CRYPTO_RsaPublicKey *p1, |
657 | struct GNUNET_CRYPTO_RsaPublicKey *p2) | 657 | struct GNUNET_CRYPTO_RsaPublicKey *p2) |
658 | { | 658 | { |
659 | char *b1; | 659 | void *b1; |
660 | char *b2; | 660 | void *b2; |
661 | size_t z1; | 661 | size_t z1; |
662 | size_t z2; | 662 | size_t z2; |
663 | int ret; | 663 | int ret; |
@@ -689,8 +689,8 @@ int | |||
689 | GNUNET_CRYPTO_rsa_private_key_cmp (struct GNUNET_CRYPTO_RsaPrivateKey *p1, | 689 | GNUNET_CRYPTO_rsa_private_key_cmp (struct GNUNET_CRYPTO_RsaPrivateKey *p1, |
690 | struct GNUNET_CRYPTO_RsaPrivateKey *p2) | 690 | struct GNUNET_CRYPTO_RsaPrivateKey *p2) |
691 | { | 691 | { |
692 | char *b1; | 692 | void *b1; |
693 | char *b2; | 693 | void *b2; |
694 | size_t z1; | 694 | size_t z1; |
695 | size_t z2; | 695 | size_t z2; |
696 | int ret; | 696 | int ret; |
@@ -796,7 +796,7 @@ rsa_full_domain_hash (const struct GNUNET_CRYPTO_RsaPublicKey *pkey, | |||
796 | const struct GNUNET_HashCode *hash) | 796 | const struct GNUNET_HashCode *hash) |
797 | { | 797 | { |
798 | gcry_mpi_t r, n; | 798 | gcry_mpi_t r, n; |
799 | char *xts; | 799 | void *xts; |
800 | size_t xts_len; | 800 | size_t xts_len; |
801 | int ok; | 801 | int ok; |
802 | 802 | ||
@@ -841,7 +841,8 @@ int | |||
841 | GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, | 841 | GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, |
842 | const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, | 842 | const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, |
843 | struct GNUNET_CRYPTO_RsaPublicKey *pkey, | 843 | struct GNUNET_CRYPTO_RsaPublicKey *pkey, |
844 | char **buf, size_t *buf_size) | 844 | void **buf, |
845 | size_t *buf_size) | ||
845 | { | 846 | { |
846 | struct RsaBlindingKey *bkey; | 847 | struct RsaBlindingKey *bkey; |
847 | gcry_mpi_t data; | 848 | gcry_mpi_t data; |
@@ -852,7 +853,8 @@ GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, | |||
852 | 853 | ||
853 | BENCHMARK_START (rsa_blind); | 854 | BENCHMARK_START (rsa_blind); |
854 | 855 | ||
855 | GNUNET_assert (buf != NULL && buf_size != NULL); | 856 | GNUNET_assert (buf != NULL); |
857 | GNUNET_assert (buf_size != NULL); | ||
856 | ret = key_from_sexp (ne, pkey->sexp, "public-key", "ne"); | 858 | ret = key_from_sexp (ne, pkey->sexp, "public-key", "ne"); |
857 | if (0 != ret) | 859 | if (0 != ret) |
858 | ret = key_from_sexp (ne, pkey->sexp, "rsa", "ne"); | 860 | ret = key_from_sexp (ne, pkey->sexp, "rsa", "ne"); |
@@ -891,7 +893,8 @@ GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, | |||
891 | gcry_mpi_release (r_e); | 893 | gcry_mpi_release (r_e); |
892 | rsa_blinding_key_free (bkey); | 894 | rsa_blinding_key_free (bkey); |
893 | 895 | ||
894 | *buf_size = numeric_mpi_alloc_n_print (data_r_e, buf); | 896 | *buf_size = numeric_mpi_alloc_n_print (data_r_e, |
897 | (char **) buf); | ||
895 | gcry_mpi_release (data_r_e); | 898 | gcry_mpi_release (data_r_e); |
896 | 899 | ||
897 | BENCHMARK_END (rsa_blind); | 900 | BENCHMARK_END (rsa_blind); |
@@ -1070,9 +1073,9 @@ GNUNET_CRYPTO_rsa_signature_free (struct GNUNET_CRYPTO_RsaSignature *sig) | |||
1070 | * @return size of memory allocated in @a buffer | 1073 | * @return size of memory allocated in @a buffer |
1071 | */ | 1074 | */ |
1072 | size_t | 1075 | size_t |
1073 | GNUNET_CRYPTO_rsa_signature_encode (const struct | 1076 | GNUNET_CRYPTO_rsa_signature_encode ( |
1074 | GNUNET_CRYPTO_RsaSignature *sig, | 1077 | const struct GNUNET_CRYPTO_RsaSignature *sig, |
1075 | char **buffer) | 1078 | void **buffer) |
1076 | { | 1079 | { |
1077 | gcry_mpi_t s; | 1080 | gcry_mpi_t s; |
1078 | size_t buf_size; | 1081 | size_t buf_size; |
@@ -1103,7 +1106,7 @@ GNUNET_CRYPTO_rsa_signature_encode (const struct | |||
1103 | &rsize, | 1106 | &rsize, |
1104 | s)); | 1107 | s)); |
1105 | GNUNET_assert (rsize == buf_size); | 1108 | GNUNET_assert (rsize == buf_size); |
1106 | *buffer = (char *) buf; | 1109 | *buffer = (void *) buf; |
1107 | gcry_mpi_release (s); | 1110 | gcry_mpi_release (s); |
1108 | return buf_size; | 1111 | return buf_size; |
1109 | } | 1112 | } |
@@ -1114,12 +1117,12 @@ GNUNET_CRYPTO_rsa_signature_encode (const struct | |||
1114 | * format. | 1117 | * format. |
1115 | * | 1118 | * |
1116 | * @param buf the buffer where the public key data is stored | 1119 | * @param buf the buffer where the public key data is stored |
1117 | * @param len the length of the data in @a buf | 1120 | * @param buf_size the size of the data in @a buf |
1118 | * @return NULL on error | 1121 | * @return NULL on error |
1119 | */ | 1122 | */ |
1120 | struct GNUNET_CRYPTO_RsaSignature * | 1123 | struct GNUNET_CRYPTO_RsaSignature * |
1121 | GNUNET_CRYPTO_rsa_signature_decode (const char *buf, | 1124 | GNUNET_CRYPTO_rsa_signature_decode (const void *buf, |
1122 | size_t len) | 1125 | size_t buf_size) |
1123 | { | 1126 | { |
1124 | struct GNUNET_CRYPTO_RsaSignature *sig; | 1127 | struct GNUNET_CRYPTO_RsaSignature *sig; |
1125 | gcry_mpi_t s; | 1128 | gcry_mpi_t s; |
@@ -1129,7 +1132,7 @@ GNUNET_CRYPTO_rsa_signature_decode (const char *buf, | |||
1129 | gcry_mpi_scan (&s, | 1132 | gcry_mpi_scan (&s, |
1130 | GCRYMPI_FMT_USG, | 1133 | GCRYMPI_FMT_USG, |
1131 | buf, | 1134 | buf, |
1132 | len, | 1135 | buf_size, |
1133 | NULL)) | 1136 | NULL)) |
1134 | { | 1137 | { |
1135 | GNUNET_break_op (0); | 1138 | GNUNET_break_op (0); |