1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/srtp/src/crypto/test/sha1_driver.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,550 @@ 1.4 +/* 1.5 + * sha1_driver.c 1.6 + * 1.7 + * a test driver for SHA-1 1.8 + * 1.9 + * David A. McGrew 1.10 + * Cisco Systems, Inc. 1.11 + */ 1.12 + 1.13 +/* 1.14 + * 1.15 + * Copyright (c) 2001-2006, Cisco Systems, Inc. 1.16 + * All rights reserved. 1.17 + * 1.18 + * Redistribution and use in source and binary forms, with or without 1.19 + * modification, are permitted provided that the following conditions 1.20 + * are met: 1.21 + * 1.22 + * Redistributions of source code must retain the above copyright 1.23 + * notice, this list of conditions and the following disclaimer. 1.24 + * 1.25 + * Redistributions in binary form must reproduce the above 1.26 + * copyright notice, this list of conditions and the following 1.27 + * disclaimer in the documentation and/or other materials provided 1.28 + * with the distribution. 1.29 + * 1.30 + * Neither the name of the Cisco Systems, Inc. nor the names of its 1.31 + * contributors may be used to endorse or promote products derived 1.32 + * from this software without specific prior written permission. 1.33 + * 1.34 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.35 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.36 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 1.37 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 1.38 + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 1.39 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 1.40 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 1.41 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 1.42 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 1.43 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1.44 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 1.45 + * OF THE POSSIBILITY OF SUCH DAMAGE. 1.46 + * 1.47 + */ 1.48 + 1.49 +#include <stdio.h> 1.50 +#include "sha1.h" 1.51 + 1.52 +#define SHA_PASS 0 1.53 +#define SHA_FAIL 1 1.54 + 1.55 +#define MAX_HASH_DATA_LEN 1024 1.56 +#define MAX_HASH_OUT_LEN 20 1.57 + 1.58 +typedef struct hash_test_case_t { 1.59 + unsigned data_len; /* number of octets in data */ 1.60 + unsigned hash_len; /* number of octets output by hash */ 1.61 + uint8_t data[MAX_HASH_DATA_LEN]; /* message data */ 1.62 + uint8_t hash[MAX_HASH_OUT_LEN]; /* expected hash output */ 1.63 + struct hash_test_case_t *next_test_case; 1.64 +} hash_test_case_t; 1.65 + 1.66 +hash_test_case_t *sha1_test_case_list; 1.67 + 1.68 +err_status_t 1.69 +hash_test_case_add(hash_test_case_t **list_ptr, 1.70 + char *hex_data, 1.71 + unsigned data_len, 1.72 + char *hex_hash, 1.73 + unsigned hash_len) { 1.74 + hash_test_case_t *list_head = *list_ptr; 1.75 + hash_test_case_t *test_case; 1.76 + unsigned tmp_len; 1.77 + 1.78 + test_case = malloc(sizeof(hash_test_case_t)); 1.79 + if (test_case == NULL) 1.80 + return err_status_alloc_fail; 1.81 + 1.82 + tmp_len = hex_string_to_octet_string((char *)test_case->data, hex_data, data_len*2); 1.83 + if (tmp_len != data_len*2) 1.84 + return err_status_parse_err; 1.85 + 1.86 + tmp_len = hex_string_to_octet_string((char *)test_case->hash, hex_hash, hash_len*2); 1.87 + if (tmp_len != hash_len*2) 1.88 + return err_status_parse_err; 1.89 + 1.90 + test_case->data_len = data_len; 1.91 + test_case->hash_len = hash_len; 1.92 + 1.93 + /* add the new test case to the head of the list */ 1.94 + test_case->next_test_case = list_head; 1.95 + *list_ptr = test_case; 1.96 + 1.97 + return err_status_ok; 1.98 +} 1.99 + 1.100 +err_status_t 1.101 +sha1_test_case_validate(const hash_test_case_t *test_case) { 1.102 + sha1_ctx_t ctx; 1.103 + uint32_t hash_value[5]; 1.104 + 1.105 + if (test_case == NULL) 1.106 + return err_status_bad_param; 1.107 + 1.108 + if (test_case->hash_len != 20) 1.109 + return err_status_bad_param; 1.110 + if (test_case->data_len > MAX_HASH_DATA_LEN) 1.111 + return err_status_bad_param; 1.112 + 1.113 + sha1_init(&ctx); 1.114 + sha1_update(&ctx, test_case->data, test_case->data_len); 1.115 + sha1_final(&ctx, hash_value); 1.116 + if (0 == memcmp(test_case->hash, hash_value, 20)) { 1.117 +#if VERBOSE 1.118 + printf("PASSED: reference value: %s\n", 1.119 + octet_string_hex_string((const uint8_t *)test_case->hash, 20)); 1.120 + printf("PASSED: computed value: %s\n", 1.121 + octet_string_hex_string((const uint8_t *)hash_value, 20)); 1.122 +#endif 1.123 + return err_status_ok; 1.124 + } 1.125 + 1.126 + printf("reference value: %s\n", 1.127 + octet_string_hex_string((const uint8_t *)test_case->hash, 20)); 1.128 + printf("computed value: %s\n", 1.129 + octet_string_hex_string((const uint8_t *)hash_value, 20)); 1.130 + 1.131 + return err_status_algo_fail; 1.132 + 1.133 +} 1.134 + 1.135 +struct hex_sha1_test_case_t { 1.136 + unsigned bit_len; 1.137 + char hex_data[MAX_HASH_DATA_LEN*2]; 1.138 + char hex_hash[40]; 1.139 +}; 1.140 + 1.141 +err_status_t 1.142 +sha1_add_test_cases(void) { 1.143 + int i; 1.144 + err_status_t err; 1.145 + 1.146 + /* 1.147 + * these test cases are taken from the "SHA-1 Sample Vectors" 1.148 + * provided by NIST at http://csrc.nist.gov/cryptval/shs.html 1.149 + */ 1.150 + 1.151 + struct hex_sha1_test_case_t tc[] = { 1.152 + { 1.153 + 0, 1.154 + "", 1.155 + "da39a3ee5e6b4b0d3255bfef95601890afd80709" 1.156 + }, 1.157 + { 1.158 + 8, 1.159 + "a8", 1.160 + "99f2aa95e36f95c2acb0eaf23998f030638f3f15" 1.161 + }, 1.162 + { 1.163 + 16, 1.164 + "3000", 1.165 + "f944dcd635f9801f7ac90a407fbc479964dec024" 1.166 + }, 1.167 + { 1.168 + 24, 1.169 + "42749e", 1.170 + "a444319e9b6cc1e8464c511ec0969c37d6bb2619" 1.171 + }, 1.172 + { 1.173 + 32, 1.174 + "9fc3fe08", 1.175 + "16a0ff84fcc156fd5d3ca3a744f20a232d172253" 1.176 + }, 1.177 + { 1.178 + 40, 1.179 + "b5c1c6f1af", 1.180 + "fec9deebfcdedaf66dda525e1be43597a73a1f93" 1.181 + }, 1.182 + { 1.183 + 48, 1.184 + "e47571e5022e", 1.185 + "8ce051181f0ed5e9d0c498f6bc4caf448d20deb5" 1.186 + }, 1.187 + { 1.188 + 56, 1.189 + "3e1b28839fb758", 1.190 + "67da53837d89e03bf652ef09c369a3415937cfd3" 1.191 + }, 1.192 + { 1.193 + 64, 1.194 + "a81350cbb224cb90", 1.195 + "305e4ff9888ad855a78573cddf4c5640cce7e946" 1.196 + }, 1.197 + { 1.198 + 72, "c243d167923dec3ce1", 1.199 + "5902b77b3265f023f9bbc396ba1a93fa3509bde7" 1.200 + }, 1.201 + { 1.202 + 80, 1.203 + "50ac18c59d6a37a29bf4", 1.204 + "fcade5f5d156bf6f9af97bdfa9c19bccfb4ff6ab" 1.205 + }, 1.206 + { 1.207 + 88, 1.208 + "98e2b611ad3b1cccf634f6", 1.209 + "1d20fbe00533c10e3cbd6b27088a5de0c632c4b5" 1.210 + }, 1.211 + { 1.212 + 96, 1.213 + "73fe9afb68e1e8712e5d4eec", 1.214 + "7e1b7e0f7a8f3455a9c03e9580fd63ae205a2d93" 1.215 + }, 1.216 + { 1.217 + 104, 1.218 + "9e701ed7d412a9226a2a130e66", 1.219 + "706f0677146307b20bb0e8d6311e329966884d13" 1.220 + }, 1.221 + { 1.222 + 112, 1.223 + "6d3ee90413b0a7cbf69e5e6144ca", 1.224 + "a7241a703aaf0d53fe142f86bf2e849251fa8dff" 1.225 + }, 1.226 + { 1.227 + 120, 1.228 + "fae24d56514efcb530fd4802f5e71f", 1.229 + "400f53546916d33ad01a5e6df66822dfbdc4e9e6" 1.230 + }, 1.231 + { 1.232 + 128, 1.233 + "c5a22dd6eda3fe2bdc4ddb3ce6b35fd1", 1.234 + "fac8ab93c1ae6c16f0311872b984f729dc928ccd" 1.235 + }, 1.236 + { 1.237 + 136, 1.238 + "d98cded2adabf08fda356445c781802d95", 1.239 + "fba6d750c18da58f6e2aab10112b9a5ef3301b3b" 1.240 + }, 1.241 + { 1.242 + 144, 1.243 + "bcc6d7087a84f00103ccb32e5f5487a751a2", 1.244 + "29d27c2d44c205c8107f0351b05753ac708226b6" 1.245 + }, 1.246 + { 1.247 + 152, 1.248 + "36ecacb1055434190dbbc556c48bafcb0feb0d", 1.249 + "b971bfc1ebd6f359e8d74cb7ecfe7f898d0ba845" 1.250 + }, 1.251 + { 1.252 + 160, 1.253 + "5ff9edb69e8f6bbd498eb4537580b7fba7ad31d0", 1.254 + "96d08c430094b9fcc164ad2fb6f72d0a24268f68" 1.255 + }, 1.256 + { 1.257 + 168, "c95b441d8270822a46a798fae5defcf7b26abace36", 1.258 + "a287ea752a593d5209e287881a09c49fa3f0beb1" 1.259 + }, 1.260 + { 1.261 + 176, 1.262 + "83104c1d8a55b28f906f1b72cb53f68cbb097b44f860", 1.263 + "a06c713779cbd88519ed4a585ac0cb8a5e9d612b" 1.264 + }, 1.265 + { 1.266 + 184, 1.267 + "755175528d55c39c56493d697b790f099a5ce741f7754b", 1.268 + "bff7d52c13a3688132a1d407b1ab40f5b5ace298" 1.269 + }, 1.270 + { 1.271 + 192, 1.272 + "088fc38128bbdb9fd7d65228b3184b3faac6c8715f07272f", 1.273 + "c7566b91d7b6f56bdfcaa9781a7b6841aacb17e9" 1.274 + }, 1.275 + { 1.276 + 200, 1.277 + "a4a586eb9245a6c87e3adf1009ac8a49f46c07e14185016895", 1.278 + "ffa30c0b5c550ea4b1e34f8a60ec9295a1e06ac1" 1.279 + }, 1.280 + { 1.281 + 208, 1.282 + "8e7c555270c006092c2a3189e2a526b873e2e269f0fb28245256", 1.283 + "29e66ed23e914351e872aa761df6e4f1a07f4b81" 1.284 + }, 1.285 + { 1.286 + 216, 1.287 + "a5f3bfa6bb0ba3b59f6b9cbdef8a558ec565e8aa3121f405e7f2f0", 1.288 + "b28cf5e5b806a01491d41f69bd9248765c5dc292" 1.289 + }, 1.290 + { 1.291 + 224, 1.292 + "589054f0d2bd3c2c85b466bfd8ce18e6ec3e0b87d944cd093ba36469", 1.293 + "60224fb72c46069652cd78bcd08029ef64da62f3" 1.294 + }, 1.295 + { 1.296 + 232, 1.297 + "a0abb12083b5bbc78128601bf1cbdbc0fdf4b862b24d899953d8da0ff3", 1.298 + "b72c4a86f72608f24c05f3b9088ef92fba431df7" 1.299 + }, 1.300 + { 1.301 + 240, 1.302 + "82143f4cea6fadbf998e128a8811dc75301cf1db4f079501ea568da68eeb", 1.303 + "73779ad5d6b71b9b8328ef7220ff12eb167076ac" 1.304 + }, 1.305 + { 1.306 + 248, 1.307 + "9f1231dd6df1ff7bc0b0d4f989d048672683ce35d956d2f57913046267e6f3", 1.308 + "a09671d4452d7cf50015c914a1e31973d20cc1a0" 1.309 + }, 1.310 + { 1.311 + 256, 1.312 + "041c512b5eed791f80d3282f3a28df263bb1df95e1239a7650e5670fc2187919", 1.313 + "e88cdcd233d99184a6fd260b8fca1b7f7687aee0" 1.314 + }, 1.315 + { 1.316 + 264, 1.317 + "17e81f6ae8c2e5579d69dafa6e070e7111461552d314b691e7a3e7a4feb3fae418", 1.318 + "010def22850deb1168d525e8c84c28116cb8a269" 1.319 + }, 1.320 + { 1.321 + 272, 1.322 + "d15976b23a1d712ad28fad04d805f572026b54dd64961fda94d5355a0cc98620cf77", 1.323 + "aeaa40ba1717ed5439b1e6ea901b294ba500f9ad" 1.324 + }, 1.325 + { 1.326 + 280, 1.327 + "09fce4d434f6bd32a44e04b848ff50ec9f642a8a85b37a264dc73f130f22838443328f", 1.328 + "c6433791238795e34f080a5f1f1723f065463ca0" 1.329 + }, 1.330 + { 1.331 + 288, "f17af27d776ec82a257d8d46d2b46b639462c56984cc1be9c1222eadb8b26594a25c709d", 1.332 + "e21e22b89c1bb944a32932e6b2a2f20d491982c3" 1.333 + }, 1.334 + { 1.335 + 296, 1.336 + "b13ce635d6f8758143ffb114f2f601cb20b6276951416a2f94fbf4ad081779d79f4f195b22", 1.337 + "575323a9661f5d28387964d2ba6ab92c17d05a8a" 1.338 + }, 1.339 + { 1.340 + 304, 1.341 + "5498793f60916ff1c918dde572cdea76da8629ba4ead6d065de3dfb48de94d234cc1c5002910", 1.342 + "feb44494af72f245bfe68e86c4d7986d57c11db7" 1.343 + }, 1.344 + { 1.345 + 312, 1.346 + "498a1e0b39fa49582ae688cd715c86fbaf8a81b8b11b4d1594c49c902d197c8ba8a621fd6e3be5", 1.347 + "cff2290b3648ba2831b98dde436a72f9ebf51eee" 1.348 + }, 1.349 + { 1.350 + 320, 1.351 + "3a36ae71521f9af628b3e34dcb0d4513f84c78ee49f10416a98857150b8b15cb5c83afb4b570376e", 1.352 + "9b4efe9d27b965905b0c3dab67b8d7c9ebacd56c" 1.353 + }, 1.354 + { 1.355 + 328, 1.356 + "dcc76b40ae0ea3ba253e92ac50fcde791662c5b6c948538cffc2d95e9de99cac34dfca38910db2678f", 1.357 + "afedb0ff156205bcd831cbdbda43db8b0588c113" 1.358 + }, 1.359 + { 1.360 + 336, 1.361 + "5b5ec6ec4fd3ad9c4906f65c747fd4233c11a1736b6b228b92e90cddabb0c7c2fcf9716d3fad261dff33", 1.362 + "8deb1e858f88293a5e5e4d521a34b2a4efa70fc4" 1.363 + }, 1.364 + { 1.365 + 344, 1.366 + "df48a37b29b1d6de4e94717d60cdb4293fcf170bba388bddf7a9035a15d433f20fd697c3e4c8b8c5f590ab", 1.367 + "95cbdac0f74afa69cebd0e5c7defbc6faf0cbeaf" 1.368 + }, 1.369 + { 1.370 + 352, 1.371 + "1f179b3b82250a65e1b0aee949e218e2f45c7a8dbfd6ba08de05c55acfc226b48c68d7f7057e5675cd96fcfc", 1.372 + "f0307bcb92842e5ae0cd4f4f14f3df7f877fbef2" 1.373 + }, 1.374 + { 1.375 + 360, 1.376 + "ee3d72da3a44d971578972a8e6780ce64941267e0f7d0179b214fa97855e1790e888e09fbe3a70412176cb3b54", 1.377 + "7b13bb0dbf14964bd63b133ac85e22100542ef55" 1.378 + }, 1.379 + { 1.380 + 368, 1.381 + "d4d4c7843d312b30f610b3682254c8be96d5f6684503f8fbfbcd15774fc1b084d3741afb8d24aaa8ab9c104f7258", 1.382 + "c314d2b6cf439be678d2a74e890d96cfac1c02ed" 1.383 + }, 1.384 + { 1.385 + 376, 1.386 + "32c094944f5936a190a0877fb9178a7bf60ceae36fd530671c5b38c5dbd5e6a6c0d615c2ac8ad04b213cc589541cf6", 1.387 + "4d0be361e410b47a9d67d8ce0bb6a8e01c53c078" 1.388 + }, 1.389 + { 1.390 + 384, 1.391 + "e5d3180c14bf27a5409fa12b104a8fd7e9639609bfde6ee82bbf9648be2546d29688a65e2e3f3da47a45ac14343c9c02", 1.392 + "e5353431ffae097f675cbf498869f6fbb6e1c9f2" 1.393 + }, 1.394 + { 1.395 + 392, 1.396 + "e7b6e4b69f724327e41e1188a37f4fe38b1dba19cbf5a7311d6e32f1038e97ab506ee05aebebc1eed09fc0e357109818b9", 1.397 + "b8720a7068a085c018ab18961de2765aa6cd9ac4" 1.398 + }, 1.399 + { 1.400 + 400, 1.401 + "bc880cb83b8ac68ef2fedc2da95e7677ce2aa18b0e2d8b322701f67af7d5e7a0d96e9e33326ccb7747cfff0852b961bfd475", 1.402 + "b0732181568543ba85f2b6da602b4b065d9931aa" 1.403 + }, 1.404 + { 1.405 + 408, 1.406 + "235ea9c2ba7af25400f2e98a47a291b0bccdaad63faa2475721fda5510cc7dad814bce8dabb611790a6abe56030b798b75c944", 1.407 + "9c22674cf3222c3ba921672694aafee4ce67b96b" 1.408 + }, 1.409 + { 1.410 + 416, 1.411 + "07e3e29fed63104b8410f323b975fd9fba53f636af8c4e68a53fb202ca35dd9ee07cb169ec5186292e44c27e5696a967f5e67709", 1.412 + "d128335f4cecca9066cdae08958ce656ff0b4cfc" 1.413 + }, 1.414 + { 1.415 + 424, 1.416 + "65d2a1dd60a517eb27bfbf530cf6a5458f9d5f4730058bd9814379547f34241822bf67e6335a6d8b5ed06abf8841884c636a25733f", 1.417 + "0b67c57ac578de88a2ae055caeaec8bb9b0085a0" 1.418 + }, 1.419 + { 1.420 + 432, 1.421 + "dcc86b3bd461615bab739d8daafac231c0f462e819ad29f9f14058f3ab5b75941d4241ea2f17ebb8a458831b37a9b16dead4a76a9b0e", 1.422 + "c766f912a89d4ccda88e0cce6a713ef5f178b596" 1.423 + }, 1.424 + { 1.425 + 440, 1.426 + "4627d54f0568dc126b62a8c35fb46a9ac5024400f2995e51635636e1afc4373dbb848eb32df23914230560b82477e9c3572647a7f2bb92", 1.427 + "9aa3925a9dcb177b15ccff9b78e70cf344858779" 1.428 + }, 1.429 + { 1.430 + 448, 1.431 + "ba531affd4381168ef24d8b275a84d9254c7f5cc55fded53aa8024b2c5c5c8aa7146fe1d1b83d62b70467e9a2e2cb67b3361830adbab28d7", 1.432 + "4811fa30042fc076acf37c8e2274d025307e5943" 1.433 + }, 1.434 + { 1.435 + 456, 1.436 + "8764dcbcf89dcf4282eb644e3d568bdccb4b13508bfa7bfe0ffc05efd1390be22109969262992d377691eb4f77f3d59ea8466a74abf57b2ef4", 1.437 + "6743018450c9730761ee2b130df9b91c1e118150" 1.438 + }, 1.439 + { 1.440 + 464, 1.441 + "497d9df9ddb554f3d17870b1a31986c1be277bc44feff713544217a9f579623d18b5ffae306c25a45521d2759a72c0459b58957255ab592f3be4", 1.442 + "71ad4a19d37d92a5e6ef3694ddbeb5aa61ada645" 1.443 + }, 1.444 + { 1.445 + 472, 1.446 + "72c3c2e065aefa8d9f7a65229e818176eef05da83f835107ba90ec2e95472e73e538f783b416c04654ba8909f26a12db6e5c4e376b7615e4a25819", 1.447 + "a7d9dc68dacefb7d6116186048cb355cc548e11d" 1.448 + }, 1.449 + { 1.450 + 480, 1.451 + "7cc9894454d0055ab5069a33984e2f712bef7e3124960d33559f5f3b81906bb66fe64da13c153ca7f5cabc89667314c32c01036d12ecaf5f9a78de98", 1.452 + "142e429f0522ba5abf5131fa81df82d355b96909" 1.453 + }, 1.454 + { 1.455 + 488, 1.456 + "74e8404d5a453c5f4d306f2cfa338ca65501c840ddab3fb82117933483afd6913c56aaf8a0a0a6b2a342fc3d9dc7599f4a850dfa15d06c61966d74ea59", 1.457 + "ef72db70dcbcab991e9637976c6faf00d22caae9" 1.458 + }, 1.459 + { 1.460 + 496, 1.461 + "46fe5ed326c8fe376fcc92dc9e2714e2240d3253b105adfbb256ff7a19bc40975c604ad7c0071c4fd78a7cb64786e1bece548fa4833c04065fe593f6fb10", 1.462 + "f220a7457f4588d639dc21407c942e9843f8e26b" 1.463 + }, 1.464 + { 1.465 + 504, 1.466 + "836dfa2524d621cf07c3d2908835de859e549d35030433c796b81272fd8bc0348e8ddbc7705a5ad1fdf2155b6bc48884ac0cd376925f069a37849c089c8645", 1.467 + "ddd2117b6e309c233ede85f962a0c2fc215e5c69" 1.468 + }, 1.469 + { 1.470 + 512, 1.471 + "7e3a4c325cb9c52b88387f93d01ae86d42098f5efa7f9457388b5e74b6d28b2438d42d8b64703324d4aa25ab6aad153ae30cd2b2af4d5e5c00a8a2d0220c6116", 1.472 + "a3054427cdb13f164a610b348702724c808a0dcc" 1.473 + } 1.474 + }; 1.475 + 1.476 + 1.477 + for (i=0; i < 65; i++) { 1.478 + err = hash_test_case_add(&sha1_test_case_list, 1.479 + tc[i].hex_data, 1.480 + tc[i].bit_len/8, 1.481 + tc[i].hex_hash, 20); 1.482 + if (err) { 1.483 + printf("error adding hash test case (code %d)\n", err); 1.484 + return err; 1.485 + } 1.486 + } 1.487 + 1.488 + return err_status_ok; 1.489 +} 1.490 + 1.491 +err_status_t 1.492 +sha1_dealloc_test_cases(void) { 1.493 + hash_test_case_t *t, *next; 1.494 + 1.495 + for (t = sha1_test_case_list; t != NULL; t = next) { 1.496 + next = t->next_test_case; 1.497 + free(t); 1.498 + } 1.499 + 1.500 + sha1_test_case_list = NULL; 1.501 + 1.502 + return err_status_ok; 1.503 +} 1.504 + 1.505 + 1.506 + 1.507 +err_status_t 1.508 +sha1_validate(void) { 1.509 + hash_test_case_t *test_case; 1.510 + err_status_t err; 1.511 + 1.512 + err = sha1_add_test_cases(); 1.513 + if (err) { 1.514 + printf("error adding SHA1 test cases (error code %d)\n", err); 1.515 + return err; 1.516 + } 1.517 + 1.518 + if (sha1_test_case_list == NULL) 1.519 + return err_status_cant_check; 1.520 + 1.521 + test_case = sha1_test_case_list; 1.522 + while (test_case != NULL) { 1.523 + err = sha1_test_case_validate(test_case); 1.524 + if (err) { 1.525 + printf("error validating hash test case (error code %d)\n", err); 1.526 + return err; 1.527 + } 1.528 + test_case = test_case->next_test_case; 1.529 + } 1.530 + 1.531 + sha1_dealloc_test_cases(); 1.532 + 1.533 + return err_status_ok; 1.534 +} 1.535 + 1.536 + 1.537 + 1.538 +int 1.539 +main (void) { 1.540 + err_status_t err; 1.541 + 1.542 + printf("sha1 test driver\n"); 1.543 + 1.544 + err = sha1_validate(); 1.545 + if (err) { 1.546 + printf("SHA1 did not pass validation testing\n"); 1.547 + return 1; 1.548 + } 1.549 + printf("SHA1 passed validation tests\n"); 1.550 + 1.551 + return 0; 1.552 + 1.553 +}