Coder Social home page Coder Social logo

Comments (34)

NamsooCho avatar NamsooCho commented on May 24, 2024 1
running 542 tests
test toxcore::crypto_core::tests::crypto_init_test ... ok
alice_pk = PublicKey([127, 71, 215, 228, 18, 40, 100, 184, 186, 158, 178, 170, 102, 5, 177, 21, 105, 82, 207, 123, 8, 6, 230, 142, 123, 192, 140, 27, 108, 197, 150, 123]),
 alice_sk = [238, 115, 125, 75, 116, 121, 183, 189, 118, 66, 194, 5, 247, 157, 36, 177, 136, 141, 224, 72, 69, 103, 117, 36, 84, 108, 253, 58, 162, 135, 104, 162],
 bob_pk = PublicKey([137, 7, 228, 12, 185, 93, 189, 33, 161, 239, 221, 155, 122, 211, 161, 135, 7, 189, 188, 94, 101, 145, 66, 221, 174, 235, 183, 127, 82, 234, 248, 116]),
 bob_sk = [181, 105, 85, 80, 187, 92, 227, 190, 237, 114, 222, 133, 222, 192, 84, 207, 231, 91, 161, 187, 178, 130, 137, 241, 101, 230, 166, 6, 62, 208, 61, 251],
 nonce = Nonce([219, 2, 66, 226, 29, 162, 129, 210, 141, 14, 132, 203, 191, 114, 32, 190, 185, 97, 184, 82, 143, 24, 237, 45])
test toxcore::crypto_core::tests::increment_nonce_number_test_zero_plus_0xff00 ... ok
test toxcore::crypto_core::tests::increment_nonce_number_test_0xff0000_plus_0x011000 ... ok
thread 'toxcore::crypto_core::tests::encrypt_precompute_test' panicked at 'called `Result::unwrap()` on an `Err` value: ()', libcore/result.rs:1009:5

Opps! It succeeded. Refer below comment

from tox.

kurnevsky avatar kurnevsky commented on May 24, 2024

Is it reproducible? If so can you catch generated keys and nonce when this test fails?

from tox.

kpp avatar kpp commented on May 24, 2024

Nice catch!

from tox.

NamsooCho avatar NamsooCho commented on May 24, 2024
running 542 tests
encrypt_precompute_test
 alice_pk = PublicKey([130, 229, 192, 148, 62, 201, 246, 193, 93, 224, 30, 219, 87, 87, 2, 12, 62, 30, 48, 232, 117, 82, 8, 130, 163, 193, 49, 245, 218, 6, 96, 46]),
 alice_sk = [171, 208, 8, 222, 230, 181, 77, 126, 123, 252, 115, 199, 62, 25, 118, 30, 226, 141, 140, 96, 9, 44, 222, 35, 68, 140, 215, 130, 170, 114, 59, 150],
 bob_pk = PublicKey([42, 17, 171, 186, 151, 85, 130, 197, 12, 103, 66, 216, 205, 54, 68, 65, 135, 25, 87, 132, 39, 179, 211, 13, 181, 207, 212, 85, 14, 83, 122, 102]),
 bob_sk = [97, 30, 222, 95, 222, 225, 16, 217, 220, 125, 253, 76, 81, 148, 83, 82, 23, 123, 180, 120, 176, 48, 1, 6, 96, 5, 61, 147, 124, 11, 78, 209],
 nonce = Nonce([243, 128, 244, 180, 215, 104, 117, 98, 88, 250, 155, 217, 110, 165, 210, 188, 185, 18, 138, 238, 59, 80, 207, 211])

This is captured correctly.

from tox.

NamsooCho avatar NamsooCho commented on May 24, 2024

encrypt_precompute_test failure alternates with encrypt_data_symmetric_test failure

from tox.

kpp avatar kpp commented on May 24, 2024
    #[test]
    // test uses "bare" functions provided by `sodiumoxide`, with an exception
    // of the tested function
    fn encrypt_precompute_test() {
        let alice_pk = PublicKey([130, 229, 192, 148, 62, 201, 246, 193, 93, 224, 30, 219, 87, 87, 2, 12, 62, 30, 48, 232, 117, 82, 8, 130, 163, 193, 49, 245, 218, 6, 96, 46]);
        let alice_sk = SecretKey([171, 208, 8, 222, 230, 181, 77, 126, 123, 252, 115, 199, 62, 25, 118, 30, 226, 141, 140, 96, 9, 44, 222, 35, 68, 140, 215, 130, 170, 114, 59, 150]);

        let bob_pk = PublicKey([42, 17, 171, 186, 151, 85, 130, 197, 12, 103, 66, 216, 205, 54, 68, 65, 135, 25, 87, 132, 39, 179, 211, 13, 181, 207, 212, 85, 14, 83, 122, 102]);
        let bob_sk = SecretKey([97, 30, 222, 95, 222, 225, 16, 217, 220, 125, 253, 76, 81, 148, 83, 82, 23, 123, 180, 120, 176, 48, 1, 6, 96, 5, 61, 147, 124, 11, 78, 209]);

        let alice_plaintext = b"Hi, Bob.";
        let alice_precomputed_key = encrypt_precompute(&bob_pk, &alice_sk);

        let nonce = Nonce([243, 128, 244, 180, 215, 104, 117, 98, 88, 250, 155, 217, 110, 165, 210, 188, 185, 18, 138, 238, 59, 80, 207, 211]);

        let ciphertext = seal_precomputed(alice_plaintext, &nonce, &alice_precomputed_key);

        let bob_precomputed_key = encrypt_precompute(&alice_pk, &bob_sk);
        let bob_plaintext = open_precomputed(&ciphertext, &nonce, &bob_precomputed_key).unwrap();

        assert_eq!(alice_plaintext, &bob_plaintext[..]);
    }
$ cargo test encrypt_precompute_test
   Compiling tox v0.0.7 (/home/humbug/tox)
    Finished dev [unoptimized + debuginfo] target(s) in 8.56s
     Running target/debug/deps/tox-d08d73a27a9a5786

running 1 test
test toxcore::crypto_core::tests::encrypt_precompute_test ... ok

from tox.

kurnevsky avatar kurnevsky commented on May 24, 2024

Perhaps it's mac-specific? @NamsooCho can you try this test that @kpp posted? Does it fail?

from tox.

kpp avatar kpp commented on May 24, 2024

Do you use system libsodium(with SODIUM_LIB_DIR)?

from tox.

NamsooCho avatar NamsooCho commented on May 24, 2024

Do you use system libsodium(with SODIUM_LIB_DIR)?

Yes

from tox.

NamsooCho avatar NamsooCho commented on May 24, 2024

Perhaps it's mac-specific? @NamsooCho can you try this test that @kpp posted? Does it fail?

Yes. I will do it tomorrow.

from tox.

NamsooCho avatar NamsooCho commented on May 24, 2024

The test that @kpp posted always success on Mac.
But irregularly cargo test still fails.

failures:

---- toxcore::crypto_core::tests::encrypt_data_symmetric_test stdout ----
thread 'toxcore::crypto_core::tests::encrypt_data_symmetric_test' panicked at 'called `Result::unwrap()` on an `Err` value: ()', libcore/result.rs:1009:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.


failures:
    toxcore::crypto_core::tests::encrypt_data_symmetric_test

test result: FAILED. 541 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

from tox.

kpp avatar kpp commented on May 24, 2024

@NamsooCho try to put sodium::init() in the beginning of the test

from tox.

NamsooCho avatar NamsooCho commented on May 24, 2024

Putting crypto_init() solves this problem.

from tox.

NamsooCho avatar NamsooCho commented on May 24, 2024

When making it like this

pub fn crypto_init() -> bool {
//    ::sodiumoxide::init().is_ok()
    true
}

never fails on cargo test

from tox.

NamsooCho avatar NamsooCho commented on May 24, 2024

Maybe It is because, one thread do job of sodium, other thread call crypto_init().

from tox.

kpp avatar kpp commented on May 24, 2024

never fails on cargo test

Did you remove libsodium from brew and did you build tox with static && newest libsodium?

from tox.

NamsooCho avatar NamsooCho commented on May 24, 2024

Did you remove libsodium from brew and did you build tox with static && newest libsodium?

Yes

from tox.

kpp avatar kpp commented on May 24, 2024

Maybe that's the reason of the fix?

from tox.

NamsooCho avatar NamsooCho commented on May 24, 2024

No. even after removing libsodium from brew, it fails irregularly.

from tox.

kpp avatar kpp commented on May 24, 2024

But you said:

When making it like this .... never fails on cargo test

from tox.

NamsooCho avatar NamsooCho commented on May 24, 2024

Yes. after making crypto_init() to blank, it always success.

from tox.

kpp avatar kpp commented on May 24, 2024

Wow... does it fail with cargo test -- --test-threads=1 with non-blank crypto_init?

from tox.

NamsooCho avatar NamsooCho commented on May 24, 2024

Test with cargo test -- --test-threads=1 with non-blank crypto_init never fail.

from tox.

kpp avatar kpp commented on May 24, 2024

What is the frequency of failing with cargo test -- --test-threads=4 with non-blank crypto_init?

from tox.

NamsooCho avatar NamsooCho commented on May 24, 2024

Run 9 times, 1 fails.

from tox.

kpp avatar kpp commented on May 24, 2024

How many times did you run cargo test -- --test-threads=1?

from tox.

NamsooCho avatar NamsooCho commented on May 24, 2024

about 10 times.

from tox.

kpp avatar kpp commented on May 24, 2024

Run 30 times more =)

from tox.

NamsooCho avatar NamsooCho commented on May 24, 2024

40 times all success

from tox.

kpp avatar kpp commented on May 24, 2024

From https://libsodium.gitbook.io/doc/internals :

Thread safety

Initializing the random number generator is the only operation that requires an internal lock.

sodium_init() should be called before any other functions. It picks the best implementations for the current platform, initializes the random number generator and generates the canary for guarded heap allocations.

On POSIX systems, everything in libsodium is guaranteed to always be thread-safe.

from tox.

kpp avatar kpp commented on May 24, 2024

Maybe that's why tests fail?

from tox.

NamsooCho avatar NamsooCho commented on May 24, 2024

Yes. I guess.

from tox.

kpp avatar kpp commented on May 24, 2024

Good catch. I will try to discover how to fix it. One solution is to put crypto_init in every test fn =(

from tox.

kpp avatar kpp commented on May 24, 2024

Depends on rust-lang/rfcs#1664

from tox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.