adds test for dav_pw2key

Sat, 20 Oct 2018 13:33:46 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 20 Oct 2018 13:33:46 +0200
changeset 487
a2fc5b1cd476
parent 486
35d17c52d45c
child 488
29b979ca8750

adds test for dav_pw2key

test/crypto.c file | annotate | diff | comparison | revisions
test/crypto.h file | annotate | diff | comparison | revisions
test/main.c file | annotate | diff | comparison | revisions
--- a/test/crypto.c	Sat Oct 20 12:11:55 2018 +0200
+++ b/test/crypto.c	Sat Oct 20 13:33:46 2018 +0200
@@ -323,3 +323,138 @@
     
     UCX_TEST_END;
 }
+
+static char *pws[] = {
+    "1234",
+    "abdefgh",
+    "AAAAAAAAAAAAAAAAA",
+    "5478FFJD:Loire923!$$123sd;fhgfdee432ASDAfd432"
+};
+
+static uint8_t salt[][16] = {
+    { 1, 10, 100, 222},
+    { 123, 12, 92, 14, 11, 0, 255, 190 },
+    { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 },
+    { 100, 240, 1, 190, 17, 0, 189, 50, 31, 13, 37, 25, 01, 0, 0, 7}
+};
+static int saltlen[] = { 4, 8, 12, 16 };
+
+static uint8_t pwgenkeys[][32] = {
+    
+    { 94, 67, 10, 1, 46, 198, 81, 162, 236, 220, 211, 196, 141, 127, 122, 39  },
+    { 94, 67, 10, 1, 46, 198, 81, 162, 236, 220, 211, 196, 141, 127, 122, 39, 96, 93, 105, 0, 131, 184, 21, 87, 165, 76, 247, 96, 74, 130, 90, 81  },
+    { 23, 185, 87, 96, 109, 149, 18, 87, 24, 246, 70, 196, 142, 67, 187, 156  },
+    { 23, 185, 87, 96, 109, 149, 18, 87, 24, 246, 70, 196, 142, 67, 187, 156, 131, 104, 108, 119, 175, 221, 108, 220, 75, 83, 91, 205, 157, 142, 132, 175  },
+    { 224, 80, 236, 51, 156, 38, 77, 11, 198, 205, 190, 210, 193, 40, 188, 215  },
+    { 224, 80, 236, 51, 156, 38, 77, 11, 198, 205, 190, 210, 193, 40, 188, 215, 247, 201, 231, 19, 243, 61, 20, 166, 155, 147, 234, 3, 148, 240, 255, 190  },
+    { 29, 209, 169, 101, 7, 80, 162, 82, 196, 20, 110, 36, 66, 41, 189, 16  },
+    { 29, 209, 169, 101, 7, 80, 162, 82, 196, 20, 110, 36, 66, 41, 189, 16, 65, 37, 90, 2, 226, 228, 201, 21, 87, 230, 115, 201, 87, 157, 53, 251  },
+    { 107, 129, 5, 22, 175, 18, 160, 61, 29, 249, 96, 108, 136, 1, 238, 168  },
+    { 107, 129, 5, 22, 175, 18, 160, 61, 29, 249, 96, 108, 136, 1, 238, 168, 32, 208, 199, 177, 44, 251, 145, 195, 189, 18, 119, 161, 167, 101, 248, 83  },
+    { 14, 193, 58, 165, 156, 202, 237, 35, 113, 184, 24, 180, 221, 81, 213, 62  },
+    { 14, 193, 58, 165, 156, 202, 237, 35, 113, 184, 24, 180, 221, 81, 213, 62, 211, 25, 211, 30, 47, 253, 168, 169, 84, 31, 162, 185, 75, 136, 22, 244  },
+    { 83, 193, 218, 177, 173, 5, 134, 61, 45, 14, 141, 225, 194, 114, 91, 221  },
+    { 83, 193, 218, 177, 173, 5, 134, 61, 45, 14, 141, 225, 194, 114, 91, 221, 61, 56, 69, 123, 1, 149, 247, 141, 71, 48, 55, 182, 237, 32, 20, 20  },
+    { 223, 221, 209, 7, 249, 39, 34, 180, 121, 44, 144, 153, 47, 188, 104, 33  },
+    { 223, 221, 209, 7, 249, 39, 34, 180, 121, 44, 144, 153, 47, 188, 104, 33, 29, 159, 51, 8, 200, 85, 137, 129, 97, 255, 26, 23, 147, 133, 11, 240  },
+    { 142, 13, 212, 33, 112, 149, 245, 39, 20, 237, 141, 46, 35, 253, 228, 43  },
+    { 142, 13, 212, 33, 112, 149, 245, 39, 20, 237, 141, 46, 35, 253, 228, 43, 219, 69, 181, 28, 235, 85, 202, 135, 6, 215, 130, 67, 235, 114, 91, 79  },
+    { 53, 10, 18, 131, 28, 151, 84, 93, 2, 102, 69, 224, 174, 140, 2, 168  },
+    { 53, 10, 18, 131, 28, 151, 84, 93, 2, 102, 69, 224, 174, 140, 2, 168, 213, 236, 43, 135, 148, 195, 134, 160, 143, 216, 109, 167, 150, 72, 162, 22  },
+    { 26, 199, 244, 1, 219, 53, 16, 109, 121, 230, 129, 204, 69, 120, 246, 83  },
+    { 26, 199, 244, 1, 219, 53, 16, 109, 121, 230, 129, 204, 69, 120, 246, 83, 93, 9, 117, 21, 49, 67, 56, 255, 147, 16, 18, 39, 245, 93, 20, 201  },
+    { 195, 217, 248, 6, 86, 212, 115, 132, 32, 81, 238, 97, 116, 173, 176, 250  },
+    { 195, 217, 248, 6, 86, 212, 115, 132, 32, 81, 238, 97, 116, 173, 176, 250, 207, 152, 10, 150, 113, 90, 246, 88, 41, 9, 195, 244, 70, 190, 165, 251  },
+    { 60, 114, 156, 195, 119, 103, 167, 179, 70, 3, 11, 189, 25, 27, 175, 30  },
+    { 60, 114, 156, 195, 119, 103, 167, 179, 70, 3, 11, 189, 25, 27, 175, 30, 115, 175, 250, 36, 181, 250, 22, 148, 210, 198, 36, 182, 207, 10, 150, 104  },
+    { 204, 63, 177, 165, 41, 0, 40, 99, 117, 9, 245, 59, 176, 66, 3, 234  },
+    { 204, 63, 177, 165, 41, 0, 40, 99, 117, 9, 245, 59, 176, 66, 3, 234, 106, 50, 241, 16, 254, 158, 60, 115, 221, 22, 141, 140, 220, 241, 69, 59  },
+    { 253, 68, 7, 137, 52, 78, 146, 207, 4, 68, 42, 89, 166, 74, 108, 34  },
+    { 253, 68, 7, 137, 52, 78, 146, 207, 4, 68, 42, 89, 166, 74, 108, 34, 183, 51, 183, 187, 192, 254, 20, 197, 159, 173, 10, 2, 137, 81, 148, 147  },
+    { 242, 67, 91, 24, 61, 250, 13, 44, 131, 236, 224, 118, 37, 250, 67, 160  },
+    { 242, 67, 91, 24, 61, 250, 13, 44, 131, 236, 224, 118, 37, 250, 67, 160, 57, 53, 134, 248, 210, 25, 218, 240, 124, 195, 151, 234, 220, 136, 193, 14  },
+    { 226, 55, 98, 79, 192, 117, 212, 68, 109, 46, 58, 233, 95, 180, 2, 154  },
+    { 226, 55, 98, 79, 192, 117, 212, 68, 109, 46, 58, 233, 95, 180, 2, 154, 135, 111, 74, 105, 94, 113, 77, 37, 133, 53, 72, 43, 15, 131, 69, 209  },
+    { 36, 177, 96, 156, 175, 123, 208, 63, 203, 224, 204, 179, 152, 35, 5, 115  },
+    { 36, 177, 96, 156, 175, 123, 208, 63, 203, 224, 204, 179, 152, 35, 5, 115, 142, 221, 213, 107, 223, 91, 99, 91, 126, 121, 22, 199, 195, 202, 123, 181  },
+    { 223, 189, 161, 102, 183, 210, 183, 174, 247, 101, 81, 10, 73, 169, 246, 255  },
+    { 223, 189, 161, 102, 183, 210, 183, 174, 247, 101, 81, 10, 73, 169, 246, 255, 248, 174, 81, 251, 70, 4, 221, 232, 147, 106, 138, 118, 156, 196, 58, 244  },
+    { 175, 105, 140, 110, 225, 120, 1, 72, 76, 149, 8, 203, 116, 79, 187, 131  },
+    { 175, 105, 140, 110, 225, 120, 1, 72, 76, 149, 8, 203, 116, 79, 187, 131, 218, 82, 5, 84, 22, 185, 236, 252, 165, 72, 154, 6, 50, 0, 89, 33  },
+    { 90, 125, 87, 16, 162, 186, 98, 211, 44, 165, 26, 118, 138, 83, 6, 121  },
+    { 90, 125, 87, 16, 162, 186, 98, 211, 44, 165, 26, 118, 138, 83, 6, 121, 66, 33, 63, 5, 235, 119, 12, 150, 13, 118, 198, 35, 176, 99, 252, 232  },
+    { 97, 17, 86, 48, 46, 241, 84, 19, 149, 72, 120, 235, 239, 7, 165, 117  },
+    { 97, 17, 86, 48, 46, 241, 84, 19, 149, 72, 120, 235, 239, 7, 165, 117, 226, 124, 56, 147, 68, 13, 49, 222, 211, 30, 121, 158, 74, 98, 244, 10  },
+    { 20, 216, 59, 111, 87, 145, 3, 117, 255, 156, 25, 154, 190, 118, 78, 20  },
+    { 20, 216, 59, 111, 87, 145, 3, 117, 255, 156, 25, 154, 190, 118, 78, 20, 248, 214, 78, 139, 61, 192, 140, 235, 59, 160, 40, 78, 54, 47, 25, 109  },
+    { 32, 229, 86, 178, 39, 205, 7, 101, 40, 38, 134, 141, 19, 69, 80, 243  },
+    { 32, 229, 86, 178, 39, 205, 7, 101, 40, 38, 134, 141, 19, 69, 80, 243, 28, 53, 160, 113, 203, 108, 57, 9, 231, 117, 86, 17, 206, 148, 110, 224  },
+    { 210, 190, 211, 92, 237, 193, 7, 64, 87, 132, 86, 141, 30, 125, 82, 106  },
+    { 210, 190, 211, 92, 237, 193, 7, 64, 87, 132, 86, 141, 30, 125, 82, 106, 25, 187, 172, 61, 235, 190, 17, 208, 203, 92, 238, 153, 58, 16, 49, 223  },
+    { 244, 127, 138, 189, 35, 167, 166, 55, 4, 191, 212, 31, 233, 227, 153, 170  },
+    { 244, 127, 138, 189, 35, 167, 166, 55, 4, 191, 212, 31, 233, 227, 153, 170, 40, 148, 206, 207, 252, 157, 92, 212, 241, 88, 224, 141, 179, 209, 252, 43  },
+    { 144, 204, 246, 93, 75, 176, 77, 125, 131, 249, 85, 13, 133, 132, 179, 13  },
+    { 144, 204, 246, 93, 75, 176, 77, 125, 131, 249, 85, 13, 133, 132, 179, 13, 49, 133, 237, 34, 95, 96, 223, 131, 7, 116, 177, 234, 58, 175, 154, 61  },
+    { 168, 143, 20, 221, 217, 4, 182, 225, 236, 110, 92, 32, 110, 49, 20, 94  },
+    { 168, 143, 20, 221, 217, 4, 182, 225, 236, 110, 92, 32, 110, 49, 20, 94, 184, 23, 40, 57, 120, 148, 146, 245, 154, 136, 43, 183, 113, 171, 180, 149  },
+    { 187, 226, 167, 37, 42, 163, 119, 0, 115, 104, 56, 58, 207, 206, 35, 0  },
+    { 187, 226, 167, 37, 42, 163, 119, 0, 115, 104, 56, 58, 207, 206, 35, 0, 93, 176, 200, 184, 33, 23, 15, 179, 21, 58, 210, 183, 59, 173, 205, 98  },
+    { 46, 112, 16, 101, 211, 3, 163, 33, 2, 36, 37, 139, 46, 0, 29, 198  },
+    { 46, 112, 16, 101, 211, 3, 163, 33, 2, 36, 37, 139, 46, 0, 29, 198, 128, 252, 22, 247, 105, 129, 84, 50, 252, 218, 215, 235, 200, 254, 34, 109  },
+    { 115, 186, 123, 201, 63, 21, 207, 229, 86, 0, 7, 254, 45, 115, 84, 8  },
+    { 115, 186, 123, 201, 63, 21, 207, 229, 86, 0, 7, 254, 45, 115, 84, 8, 39, 27, 113, 37, 108, 123, 230, 153, 209, 218, 180, 77, 66, 207, 239, 26  },
+    { 252, 208, 199, 95, 179, 33, 229, 155, 159, 226, 234, 213, 21, 83, 30, 206  },
+    { 252, 208, 199, 95, 179, 33, 229, 155, 159, 226, 234, 213, 21, 83, 30, 206, 174, 151, 174, 207, 58, 169, 148, 244, 37, 88, 44, 46, 72, 172, 15, 214  }
+};
+
+
+UCX_TEST(test_dav_pw2key) {
+    
+    
+    UCX_TEST_BEGIN;
+    
+    for(int p=0;p<4;p++) {
+        for(int s=0;s<4;s++) {
+            DavKey *keys[4];
+            keys[0] =  dav_pw2key(
+                    pws[p],
+                    salt[s],
+                    saltlen[s],
+                    DAV_PWFUNC_PBKDF2_SHA256,
+                    DAV_KEY_AES128);
+            keys[1] = dav_pw2key(
+                    pws[p],
+                    salt[s],
+                    saltlen[s],
+                    DAV_PWFUNC_PBKDF2_SHA256,
+                    DAV_KEY_AES256);
+            keys[2] = dav_pw2key(
+                    pws[p],
+                    salt[s],
+                    saltlen[s],
+                    DAV_PWFUNC_PBKDF2_SHA512,
+                    DAV_KEY_AES128);
+            keys[3] = dav_pw2key(
+                    pws[p],
+                    salt[s],
+                    saltlen[s],
+                    DAV_PWFUNC_PBKDF2_SHA512,
+                    DAV_KEY_AES256);
+            
+            for(int i=0;i<4;i++) {
+                DavKey *key = keys[i];
+                
+                int index = 16*p + 4*s + i;
+                int keylen = index % 2 == 0 ? 16 : 32;
+                
+                char *s1 = pwgenkeys[index];
+                char *s2 = key->data;
+                
+                UCX_TEST_ASSERT(keylen == key->length, "wrong key length");
+                UCX_TEST_ASSERT(!memcmp(key->data, pwgenkeys[index], keylen), "wrong key data");
+            }
+        }
+    }
+    
+    UCX_TEST_END;
+}
--- a/test/crypto.h	Sat Oct 20 12:11:55 2018 +0200
+++ b/test/crypto.h	Sat Oct 20 13:33:46 2018 +0200
@@ -39,6 +39,7 @@
 UCX_TEST(test_util_encrypt_str_k);
 UCX_TEST(test_crypto_buffer);
 UCX_TEST(test_crypto_stream);
+UCX_TEST(test_dav_pw2key);
 
 
 #ifdef __cplusplus
--- a/test/main.c	Sat Oct 20 12:11:55 2018 +0200
+++ b/test/main.c	Sat Oct 20 13:33:46 2018 +0200
@@ -47,6 +47,7 @@
     ucx_test_register(suite, test_util_encrypt_str_k);
     ucx_test_register(suite, test_crypto_buffer);
     ucx_test_register(suite, test_crypto_stream);
+    ucx_test_register(suite, test_dav_pw2key);
     
     ucx_test_run(suite, stdout);
     fflush(stdout);

mercurial