diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-02-09 10:24:47 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-02-09 10:24:47 +0100 |
commit | ddef3efd4cb73934fc90ccafe6f7ab98645d9848 (patch) | |
tree | 9cff8362db1e117cfbb44d273014f5c8acfb51fe /src/util | |
parent | 5ace56b96850dafc157839e6fb3795103f1bfc71 (diff) | |
download | gnunet-ddef3efd4cb73934fc90ccafe6f7ab98645d9848.tar.gz gnunet-ddef3efd4cb73934fc90ccafe6f7ab98645d9848.zip |
-fix use of uninitialized memory in test
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/crypto_cs.c | 13 | ||||
-rw-r--r-- | src/util/test_crypto_cs.c | 49 |
2 files changed, 55 insertions, 7 deletions
diff --git a/src/util/crypto_cs.c b/src/util/crypto_cs.c index c89ba5d83..c4bc3380a 100644 --- a/src/util/crypto_cs.c +++ b/src/util/crypto_cs.c | |||
@@ -205,11 +205,16 @@ cs_full_domain_hash (const struct GNUNET_CRYPTO_CsRPublic *r_dash, | |||
205 | memcpy (r_m_concat, r_dash, sizeof(struct GNUNET_CRYPTO_CsRPublic)); | 205 | memcpy (r_m_concat, r_dash, sizeof(struct GNUNET_CRYPTO_CsRPublic)); |
206 | memcpy (r_m_concat + sizeof(struct GNUNET_CRYPTO_CsRPublic), msg, msg_len); | 206 | memcpy (r_m_concat + sizeof(struct GNUNET_CRYPTO_CsRPublic), msg, msg_len); |
207 | struct GNUNET_HashCode prehash; | 207 | struct GNUNET_HashCode prehash; |
208 | GNUNET_CRYPTO_hash (r_m_concat, r_m_concat_len, &prehash); | 208 | |
209 | GNUNET_CRYPTO_hash (r_m_concat, | ||
210 | r_m_concat_len, | ||
211 | &prehash); | ||
209 | 212 | ||
210 | // modulus converted to MPI representation | 213 | // modulus converted to MPI representation |
211 | gcry_mpi_t l_mpi; | 214 | gcry_mpi_t l_mpi; |
212 | GNUNET_CRYPTO_mpi_scan_unsigned (&l_mpi, L_BIG_ENDIAN, sizeof(L_BIG_ENDIAN)); | 215 | GNUNET_CRYPTO_mpi_scan_unsigned (&l_mpi, |
216 | L_BIG_ENDIAN, | ||
217 | sizeof(L_BIG_ENDIAN)); | ||
213 | 218 | ||
214 | // calculate full domain hash | 219 | // calculate full domain hash |
215 | gcry_mpi_t c_mpi; | 220 | gcry_mpi_t c_mpi; |
@@ -224,7 +229,9 @@ cs_full_domain_hash (const struct GNUNET_CRYPTO_CsRPublic *r_dash, | |||
224 | 229 | ||
225 | // convert c from mpi | 230 | // convert c from mpi |
226 | unsigned char c_big_endian[256 / 8]; | 231 | unsigned char c_big_endian[256 / 8]; |
227 | GNUNET_CRYPTO_mpi_print_unsigned (c_big_endian, sizeof(c_big_endian), c_mpi); | 232 | GNUNET_CRYPTO_mpi_print_unsigned (c_big_endian, |
233 | sizeof(c_big_endian), | ||
234 | c_mpi); | ||
228 | gcry_mpi_release (c_mpi); | 235 | gcry_mpi_release (c_mpi); |
229 | for (size_t i = 0; i<32; i++) | 236 | for (size_t i = 0; i<32; i++) |
230 | c->scalar.d[i] = c_big_endian[31 - i]; | 237 | c->scalar.d[i] = c_big_endian[31 - i]; |
diff --git a/src/util/test_crypto_cs.c b/src/util/test_crypto_cs.c index f7ac10982..347d2e214 100644 --- a/src/util/test_crypto_cs.c +++ b/src/util/test_crypto_cs.c | |||
@@ -486,10 +486,19 @@ main (int argc, | |||
486 | size_t message_len = strlen ("test message"); | 486 | size_t message_len = strlen ("test message"); |
487 | 487 | ||
488 | struct GNUNET_CRYPTO_CsPrivateKey priv; | 488 | struct GNUNET_CRYPTO_CsPrivateKey priv; |
489 | |||
490 | memset (&priv, | ||
491 | 42, | ||
492 | sizeof (priv)); | ||
489 | test_create_priv (&priv); | 493 | test_create_priv (&priv); |
490 | 494 | ||
491 | struct GNUNET_CRYPTO_CsPublicKey pub; | 495 | struct GNUNET_CRYPTO_CsPublicKey pub; |
492 | test_generate_pub (&priv, &pub); | 496 | |
497 | memset (&pub, | ||
498 | 42, | ||
499 | sizeof (pub)); | ||
500 | test_generate_pub (&priv, | ||
501 | &pub); | ||
493 | 502 | ||
494 | // derive nonce | 503 | // derive nonce |
495 | struct GNUNET_CRYPTO_CsNonce nonce; | 504 | struct GNUNET_CRYPTO_CsNonce nonce; |
@@ -505,22 +514,45 @@ main (int argc, | |||
505 | 514 | ||
506 | // generate r, R | 515 | // generate r, R |
507 | struct GNUNET_CRYPTO_CsRSecret r_secrets[2]; | 516 | struct GNUNET_CRYPTO_CsRSecret r_secrets[2]; |
508 | test_derive_rsecret (&nonce, &priv, r_secrets); | 517 | |
518 | memset (r_secrets, | ||
519 | 42, | ||
520 | sizeof (r_secrets)); | ||
521 | test_derive_rsecret (&nonce, | ||
522 | &priv, | ||
523 | r_secrets); | ||
509 | 524 | ||
510 | struct GNUNET_CRYPTO_CsRPublic r_publics[2]; | 525 | struct GNUNET_CRYPTO_CsRPublic r_publics[2]; |
511 | test_generate_rpublic (&r_secrets[0], &r_publics[0]); | 526 | |
512 | test_generate_rpublic (&r_secrets[1], &r_publics[1]); | 527 | memset (r_publics, |
528 | 42, | ||
529 | sizeof (r_publics)); | ||
530 | test_generate_rpublic (&r_secrets[0], | ||
531 | &r_publics[0]); | ||
532 | test_generate_rpublic (&r_secrets[1], | ||
533 | &r_publics[1]); | ||
513 | 534 | ||
514 | // ---------- actions performed by user | 535 | // ---------- actions performed by user |
515 | 536 | ||
516 | // generate blinding secrets | 537 | // generate blinding secrets |
517 | struct GNUNET_CRYPTO_CsBlindingSecret blindingsecrets[2]; | 538 | struct GNUNET_CRYPTO_CsBlindingSecret blindingsecrets[2]; |
539 | |||
540 | memset (blindingsecrets, | ||
541 | 42, | ||
542 | sizeof (blindingsecrets)); | ||
518 | test_derive_blindingsecrets (&nonce, | 543 | test_derive_blindingsecrets (&nonce, |
519 | blindingsecrets); | 544 | blindingsecrets); |
520 | 545 | ||
521 | // calculate blinded c's | 546 | // calculate blinded c's |
522 | struct GNUNET_CRYPTO_CsC blinded_cs[2]; | 547 | struct GNUNET_CRYPTO_CsC blinded_cs[2]; |
523 | struct GNUNET_CRYPTO_CsRPublic blinded_r_pubs[2]; | 548 | struct GNUNET_CRYPTO_CsRPublic blinded_r_pubs[2]; |
549 | |||
550 | memset (blinded_cs, | ||
551 | 42, | ||
552 | sizeof (blinded_cs)); | ||
553 | memset (blinded_r_pubs, | ||
554 | 42, | ||
555 | sizeof (blinded_r_pubs)); | ||
524 | test_calc_blindedc (blindingsecrets, | 556 | test_calc_blindedc (blindingsecrets, |
525 | r_publics, | 557 | r_publics, |
526 | &pub, | 558 | &pub, |
@@ -533,6 +565,10 @@ main (int argc, | |||
533 | // sign blinded c's and get b and s in return | 565 | // sign blinded c's and get b and s in return |
534 | unsigned int b; | 566 | unsigned int b; |
535 | struct GNUNET_CRYPTO_CsBlindS blinded_s; | 567 | struct GNUNET_CRYPTO_CsBlindS blinded_s; |
568 | |||
569 | memset (&blinded_s, | ||
570 | 42, | ||
571 | sizeof (blinded_s)); | ||
536 | test_blind_sign (&b, | 572 | test_blind_sign (&b, |
537 | &priv, | 573 | &priv, |
538 | r_secrets, | 574 | r_secrets, |
@@ -542,6 +578,7 @@ main (int argc, | |||
542 | 578 | ||
543 | // verify blinded signature | 579 | // verify blinded signature |
544 | struct GNUNET_CRYPTO_CsSignature blinded_signature; | 580 | struct GNUNET_CRYPTO_CsSignature blinded_signature; |
581 | |||
545 | blinded_signature.r_point = r_publics[b]; | 582 | blinded_signature.r_point = r_publics[b]; |
546 | blinded_signature.s_scalar.scalar = blinded_s.scalar; | 583 | blinded_signature.s_scalar.scalar = blinded_s.scalar; |
547 | test_blind_verify (&blinded_signature, | 584 | test_blind_verify (&blinded_signature, |
@@ -550,6 +587,10 @@ main (int argc, | |||
550 | 587 | ||
551 | // ---------- actions performed by user | 588 | // ---------- actions performed by user |
552 | struct GNUNET_CRYPTO_CsS sig_scalar; | 589 | struct GNUNET_CRYPTO_CsS sig_scalar; |
590 | |||
591 | memset (&sig_scalar, | ||
592 | 42, | ||
593 | sizeof (sig_scalar)); | ||
553 | test_unblinds (&blinded_s, | 594 | test_unblinds (&blinded_s, |
554 | &blindingsecrets[b], | 595 | &blindingsecrets[b], |
555 | &sig_scalar); | 596 | &sig_scalar); |