]> git.codecow.com Git - Monocypher.git/commitdiff
Added overlapping tests for argon2i
authorLoup Vaillant <loup@loup-vaillant.fr>
Sun, 24 Sep 2017 10:03:45 +0000 (12:03 +0200)
committerLoup Vaillant <loup@loup-vaillant.fr>
Sun, 24 Sep 2017 10:03:45 +0000 (12:03 +0200)
Related to #32

tests/test.c

index 7faa094810d6193f7ceae7bb39f7bdf54fe2b119..f2f9b0631ab66cf27e35cdab7cf1cb0fa88f1cb6 100644 (file)
@@ -565,6 +565,36 @@ static int p_sha512_overlap()
     return status;
 }
 
+static int p_argon2i_overlap()
+{
+    int status = 0;
+    FOR (i, 0, 128) {
+        RANDOM_INPUT(work_area, 1024 * 8);
+        u32 hash_offset = rand64() % 128;
+        u32 pass_offset = rand64() % 128;
+        u32 salt_offset = rand64() % 128;
+        u32 key_offset  = rand64() % 128;
+        u32 ad_offset   = rand64() % 128;
+        u8 clean_work_area[1024 * 8];
+        u8 hash[32];
+        u8 pass[16];  FOR (i, 0, 16) { pass[i] = work_area[i + pass_offset]; }
+        u8 salt[16];  FOR (i, 0, 16) { salt[i] = work_area[i + salt_offset]; }
+        u8 key [32];  FOR (i, 0, 32) { key [i] = work_area[i +  key_offset]; }
+        u8 ad  [32];  FOR (i, 0, 32) { ad  [i] = work_area[i +   ad_offset]; }
+
+        crypto_argon2i(hash, 32, clean_work_area, 8, 1,
+                       pass, 16, salt, 16, key, 32, ad, 32);
+        crypto_argon2i(work_area + hash_offset, 32, work_area, 8, 1,
+                       work_area + pass_offset, 16,
+                       work_area + salt_offset, 16,
+                       work_area +  key_offset, 32,
+                       work_area +   ad_offset, 32);
+        status |= crypto_memcmp(hash, work_area + hash_offset, 32);
+    }
+    printf("%s: Argon2i (overlaping i/o)\n", status != 0 ? "FAILED" : "OK");
+    return status;
+}
+
 // Verifies that random signatures are all invalid.  Uses random
 // public keys to see what happens outside of the curve (it should
 // yield an invalid signature).
@@ -664,6 +694,7 @@ int main(void)
     status |= p_blake2b_overlap();
     status |= p_sha512();
     status |= p_sha512_overlap();
+    status |= p_argon2i_overlap();
     status |= p_eddsa();
     status |= p_eddsa_overlap();
     status |= p_aead();