phxql / argon2-jvm

Argon2 Binding for the JVM
GNU Lesser General Public License v3.0
330 stars 32 forks source link

Verify fails randomly for the same plaintext and hash #62

Closed steffen-harbich-cognitum closed 5 years ago

steffen-harbich-cognitum commented 5 years ago

I am facing a similar problem as in: https://github.com/phxql/argon2-jvm/issues/46

@Test
    public void testArgon2FailedHash() throws InterruptedException {
        String failedSecret = "fourty two";
        String failedHash = "$argon2i$v=19$m=65536,t=12,p=1$uySzYkfINQ1sDU4WZJ+D4Q$DSYZB1XQAmPLyMJi+7aWjqEfpagRO5zAEIvOlJzKRPU";

        AtomicInteger counter = new AtomicInteger(0);
        AtomicInteger failedCounter = new AtomicInteger(0);
        ExecutorService executor = Executors.newFixedThreadPool(4);
        Runnable verificationTask = () -> {
            boolean same = passwordHasher.compare(failedSecret.toCharArray(), failedHash);
            if (!same) {
                failedCounter.incrementAndGet();
            }
            counter.incrementAndGet();
        };

        for (int i = 0; i < 10000; i++) {
            executor.execute(verificationTask);
        }
        executor.shutdown();
        executor.awaitTermination(2, TimeUnit.MINUTES);

        int counted = failedCounter.get();
        assertEquals("Hashing failed " + counted + " of " + counter.get() + " times", 0, counted);
    }

This test fails on my Ubuntu server regularly but not on my windows 10 machine. In average 1 of 300 times the hash is not verified correctly. I already tested the memory with memtester without any problem. Any idea what is going wrong on my server?

steffen-harbich-cognitum commented 5 years ago

I am sorry. Another run of memtester showed that - indeed - we have some memory faults.