netwerk/srtp/src/crypto/test/sha1_driver.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * sha1_driver.c
michael@0 3 *
michael@0 4 * a test driver for SHA-1
michael@0 5 *
michael@0 6 * David A. McGrew
michael@0 7 * Cisco Systems, Inc.
michael@0 8 */
michael@0 9
michael@0 10 /*
michael@0 11 *
michael@0 12 * Copyright (c) 2001-2006, Cisco Systems, Inc.
michael@0 13 * All rights reserved.
michael@0 14 *
michael@0 15 * Redistribution and use in source and binary forms, with or without
michael@0 16 * modification, are permitted provided that the following conditions
michael@0 17 * are met:
michael@0 18 *
michael@0 19 * Redistributions of source code must retain the above copyright
michael@0 20 * notice, this list of conditions and the following disclaimer.
michael@0 21 *
michael@0 22 * Redistributions in binary form must reproduce the above
michael@0 23 * copyright notice, this list of conditions and the following
michael@0 24 * disclaimer in the documentation and/or other materials provided
michael@0 25 * with the distribution.
michael@0 26 *
michael@0 27 * Neither the name of the Cisco Systems, Inc. nor the names of its
michael@0 28 * contributors may be used to endorse or promote products derived
michael@0 29 * from this software without specific prior written permission.
michael@0 30 *
michael@0 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
michael@0 32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
michael@0 33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
michael@0 34 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
michael@0 35 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
michael@0 36 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
michael@0 37 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
michael@0 38 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
michael@0 39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
michael@0 40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
michael@0 41 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
michael@0 42 * OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 43 *
michael@0 44 */
michael@0 45
michael@0 46 #include <stdio.h>
michael@0 47 #include "sha1.h"
michael@0 48
michael@0 49 #define SHA_PASS 0
michael@0 50 #define SHA_FAIL 1
michael@0 51
michael@0 52 #define MAX_HASH_DATA_LEN 1024
michael@0 53 #define MAX_HASH_OUT_LEN 20
michael@0 54
michael@0 55 typedef struct hash_test_case_t {
michael@0 56 unsigned data_len; /* number of octets in data */
michael@0 57 unsigned hash_len; /* number of octets output by hash */
michael@0 58 uint8_t data[MAX_HASH_DATA_LEN]; /* message data */
michael@0 59 uint8_t hash[MAX_HASH_OUT_LEN]; /* expected hash output */
michael@0 60 struct hash_test_case_t *next_test_case;
michael@0 61 } hash_test_case_t;
michael@0 62
michael@0 63 hash_test_case_t *sha1_test_case_list;
michael@0 64
michael@0 65 err_status_t
michael@0 66 hash_test_case_add(hash_test_case_t **list_ptr,
michael@0 67 char *hex_data,
michael@0 68 unsigned data_len,
michael@0 69 char *hex_hash,
michael@0 70 unsigned hash_len) {
michael@0 71 hash_test_case_t *list_head = *list_ptr;
michael@0 72 hash_test_case_t *test_case;
michael@0 73 unsigned tmp_len;
michael@0 74
michael@0 75 test_case = malloc(sizeof(hash_test_case_t));
michael@0 76 if (test_case == NULL)
michael@0 77 return err_status_alloc_fail;
michael@0 78
michael@0 79 tmp_len = hex_string_to_octet_string((char *)test_case->data, hex_data, data_len*2);
michael@0 80 if (tmp_len != data_len*2)
michael@0 81 return err_status_parse_err;
michael@0 82
michael@0 83 tmp_len = hex_string_to_octet_string((char *)test_case->hash, hex_hash, hash_len*2);
michael@0 84 if (tmp_len != hash_len*2)
michael@0 85 return err_status_parse_err;
michael@0 86
michael@0 87 test_case->data_len = data_len;
michael@0 88 test_case->hash_len = hash_len;
michael@0 89
michael@0 90 /* add the new test case to the head of the list */
michael@0 91 test_case->next_test_case = list_head;
michael@0 92 *list_ptr = test_case;
michael@0 93
michael@0 94 return err_status_ok;
michael@0 95 }
michael@0 96
michael@0 97 err_status_t
michael@0 98 sha1_test_case_validate(const hash_test_case_t *test_case) {
michael@0 99 sha1_ctx_t ctx;
michael@0 100 uint32_t hash_value[5];
michael@0 101
michael@0 102 if (test_case == NULL)
michael@0 103 return err_status_bad_param;
michael@0 104
michael@0 105 if (test_case->hash_len != 20)
michael@0 106 return err_status_bad_param;
michael@0 107 if (test_case->data_len > MAX_HASH_DATA_LEN)
michael@0 108 return err_status_bad_param;
michael@0 109
michael@0 110 sha1_init(&ctx);
michael@0 111 sha1_update(&ctx, test_case->data, test_case->data_len);
michael@0 112 sha1_final(&ctx, hash_value);
michael@0 113 if (0 == memcmp(test_case->hash, hash_value, 20)) {
michael@0 114 #if VERBOSE
michael@0 115 printf("PASSED: reference value: %s\n",
michael@0 116 octet_string_hex_string((const uint8_t *)test_case->hash, 20));
michael@0 117 printf("PASSED: computed value: %s\n",
michael@0 118 octet_string_hex_string((const uint8_t *)hash_value, 20));
michael@0 119 #endif
michael@0 120 return err_status_ok;
michael@0 121 }
michael@0 122
michael@0 123 printf("reference value: %s\n",
michael@0 124 octet_string_hex_string((const uint8_t *)test_case->hash, 20));
michael@0 125 printf("computed value: %s\n",
michael@0 126 octet_string_hex_string((const uint8_t *)hash_value, 20));
michael@0 127
michael@0 128 return err_status_algo_fail;
michael@0 129
michael@0 130 }
michael@0 131
michael@0 132 struct hex_sha1_test_case_t {
michael@0 133 unsigned bit_len;
michael@0 134 char hex_data[MAX_HASH_DATA_LEN*2];
michael@0 135 char hex_hash[40];
michael@0 136 };
michael@0 137
michael@0 138 err_status_t
michael@0 139 sha1_add_test_cases(void) {
michael@0 140 int i;
michael@0 141 err_status_t err;
michael@0 142
michael@0 143 /*
michael@0 144 * these test cases are taken from the "SHA-1 Sample Vectors"
michael@0 145 * provided by NIST at http://csrc.nist.gov/cryptval/shs.html
michael@0 146 */
michael@0 147
michael@0 148 struct hex_sha1_test_case_t tc[] = {
michael@0 149 {
michael@0 150 0,
michael@0 151 "",
michael@0 152 "da39a3ee5e6b4b0d3255bfef95601890afd80709"
michael@0 153 },
michael@0 154 {
michael@0 155 8,
michael@0 156 "a8",
michael@0 157 "99f2aa95e36f95c2acb0eaf23998f030638f3f15"
michael@0 158 },
michael@0 159 {
michael@0 160 16,
michael@0 161 "3000",
michael@0 162 "f944dcd635f9801f7ac90a407fbc479964dec024"
michael@0 163 },
michael@0 164 {
michael@0 165 24,
michael@0 166 "42749e",
michael@0 167 "a444319e9b6cc1e8464c511ec0969c37d6bb2619"
michael@0 168 },
michael@0 169 {
michael@0 170 32,
michael@0 171 "9fc3fe08",
michael@0 172 "16a0ff84fcc156fd5d3ca3a744f20a232d172253"
michael@0 173 },
michael@0 174 {
michael@0 175 40,
michael@0 176 "b5c1c6f1af",
michael@0 177 "fec9deebfcdedaf66dda525e1be43597a73a1f93"
michael@0 178 },
michael@0 179 {
michael@0 180 48,
michael@0 181 "e47571e5022e",
michael@0 182 "8ce051181f0ed5e9d0c498f6bc4caf448d20deb5"
michael@0 183 },
michael@0 184 {
michael@0 185 56,
michael@0 186 "3e1b28839fb758",
michael@0 187 "67da53837d89e03bf652ef09c369a3415937cfd3"
michael@0 188 },
michael@0 189 {
michael@0 190 64,
michael@0 191 "a81350cbb224cb90",
michael@0 192 "305e4ff9888ad855a78573cddf4c5640cce7e946"
michael@0 193 },
michael@0 194 {
michael@0 195 72, "c243d167923dec3ce1",
michael@0 196 "5902b77b3265f023f9bbc396ba1a93fa3509bde7"
michael@0 197 },
michael@0 198 {
michael@0 199 80,
michael@0 200 "50ac18c59d6a37a29bf4",
michael@0 201 "fcade5f5d156bf6f9af97bdfa9c19bccfb4ff6ab"
michael@0 202 },
michael@0 203 {
michael@0 204 88,
michael@0 205 "98e2b611ad3b1cccf634f6",
michael@0 206 "1d20fbe00533c10e3cbd6b27088a5de0c632c4b5"
michael@0 207 },
michael@0 208 {
michael@0 209 96,
michael@0 210 "73fe9afb68e1e8712e5d4eec",
michael@0 211 "7e1b7e0f7a8f3455a9c03e9580fd63ae205a2d93"
michael@0 212 },
michael@0 213 {
michael@0 214 104,
michael@0 215 "9e701ed7d412a9226a2a130e66",
michael@0 216 "706f0677146307b20bb0e8d6311e329966884d13"
michael@0 217 },
michael@0 218 {
michael@0 219 112,
michael@0 220 "6d3ee90413b0a7cbf69e5e6144ca",
michael@0 221 "a7241a703aaf0d53fe142f86bf2e849251fa8dff"
michael@0 222 },
michael@0 223 {
michael@0 224 120,
michael@0 225 "fae24d56514efcb530fd4802f5e71f",
michael@0 226 "400f53546916d33ad01a5e6df66822dfbdc4e9e6"
michael@0 227 },
michael@0 228 {
michael@0 229 128,
michael@0 230 "c5a22dd6eda3fe2bdc4ddb3ce6b35fd1",
michael@0 231 "fac8ab93c1ae6c16f0311872b984f729dc928ccd"
michael@0 232 },
michael@0 233 {
michael@0 234 136,
michael@0 235 "d98cded2adabf08fda356445c781802d95",
michael@0 236 "fba6d750c18da58f6e2aab10112b9a5ef3301b3b"
michael@0 237 },
michael@0 238 {
michael@0 239 144,
michael@0 240 "bcc6d7087a84f00103ccb32e5f5487a751a2",
michael@0 241 "29d27c2d44c205c8107f0351b05753ac708226b6"
michael@0 242 },
michael@0 243 {
michael@0 244 152,
michael@0 245 "36ecacb1055434190dbbc556c48bafcb0feb0d",
michael@0 246 "b971bfc1ebd6f359e8d74cb7ecfe7f898d0ba845"
michael@0 247 },
michael@0 248 {
michael@0 249 160,
michael@0 250 "5ff9edb69e8f6bbd498eb4537580b7fba7ad31d0",
michael@0 251 "96d08c430094b9fcc164ad2fb6f72d0a24268f68"
michael@0 252 },
michael@0 253 {
michael@0 254 168, "c95b441d8270822a46a798fae5defcf7b26abace36",
michael@0 255 "a287ea752a593d5209e287881a09c49fa3f0beb1"
michael@0 256 },
michael@0 257 {
michael@0 258 176,
michael@0 259 "83104c1d8a55b28f906f1b72cb53f68cbb097b44f860",
michael@0 260 "a06c713779cbd88519ed4a585ac0cb8a5e9d612b"
michael@0 261 },
michael@0 262 {
michael@0 263 184,
michael@0 264 "755175528d55c39c56493d697b790f099a5ce741f7754b",
michael@0 265 "bff7d52c13a3688132a1d407b1ab40f5b5ace298"
michael@0 266 },
michael@0 267 {
michael@0 268 192,
michael@0 269 "088fc38128bbdb9fd7d65228b3184b3faac6c8715f07272f",
michael@0 270 "c7566b91d7b6f56bdfcaa9781a7b6841aacb17e9"
michael@0 271 },
michael@0 272 {
michael@0 273 200,
michael@0 274 "a4a586eb9245a6c87e3adf1009ac8a49f46c07e14185016895",
michael@0 275 "ffa30c0b5c550ea4b1e34f8a60ec9295a1e06ac1"
michael@0 276 },
michael@0 277 {
michael@0 278 208,
michael@0 279 "8e7c555270c006092c2a3189e2a526b873e2e269f0fb28245256",
michael@0 280 "29e66ed23e914351e872aa761df6e4f1a07f4b81"
michael@0 281 },
michael@0 282 {
michael@0 283 216,
michael@0 284 "a5f3bfa6bb0ba3b59f6b9cbdef8a558ec565e8aa3121f405e7f2f0",
michael@0 285 "b28cf5e5b806a01491d41f69bd9248765c5dc292"
michael@0 286 },
michael@0 287 {
michael@0 288 224,
michael@0 289 "589054f0d2bd3c2c85b466bfd8ce18e6ec3e0b87d944cd093ba36469",
michael@0 290 "60224fb72c46069652cd78bcd08029ef64da62f3"
michael@0 291 },
michael@0 292 {
michael@0 293 232,
michael@0 294 "a0abb12083b5bbc78128601bf1cbdbc0fdf4b862b24d899953d8da0ff3",
michael@0 295 "b72c4a86f72608f24c05f3b9088ef92fba431df7"
michael@0 296 },
michael@0 297 {
michael@0 298 240,
michael@0 299 "82143f4cea6fadbf998e128a8811dc75301cf1db4f079501ea568da68eeb",
michael@0 300 "73779ad5d6b71b9b8328ef7220ff12eb167076ac"
michael@0 301 },
michael@0 302 {
michael@0 303 248,
michael@0 304 "9f1231dd6df1ff7bc0b0d4f989d048672683ce35d956d2f57913046267e6f3",
michael@0 305 "a09671d4452d7cf50015c914a1e31973d20cc1a0"
michael@0 306 },
michael@0 307 {
michael@0 308 256,
michael@0 309 "041c512b5eed791f80d3282f3a28df263bb1df95e1239a7650e5670fc2187919",
michael@0 310 "e88cdcd233d99184a6fd260b8fca1b7f7687aee0"
michael@0 311 },
michael@0 312 {
michael@0 313 264,
michael@0 314 "17e81f6ae8c2e5579d69dafa6e070e7111461552d314b691e7a3e7a4feb3fae418",
michael@0 315 "010def22850deb1168d525e8c84c28116cb8a269"
michael@0 316 },
michael@0 317 {
michael@0 318 272,
michael@0 319 "d15976b23a1d712ad28fad04d805f572026b54dd64961fda94d5355a0cc98620cf77",
michael@0 320 "aeaa40ba1717ed5439b1e6ea901b294ba500f9ad"
michael@0 321 },
michael@0 322 {
michael@0 323 280,
michael@0 324 "09fce4d434f6bd32a44e04b848ff50ec9f642a8a85b37a264dc73f130f22838443328f",
michael@0 325 "c6433791238795e34f080a5f1f1723f065463ca0"
michael@0 326 },
michael@0 327 {
michael@0 328 288, "f17af27d776ec82a257d8d46d2b46b639462c56984cc1be9c1222eadb8b26594a25c709d",
michael@0 329 "e21e22b89c1bb944a32932e6b2a2f20d491982c3"
michael@0 330 },
michael@0 331 {
michael@0 332 296,
michael@0 333 "b13ce635d6f8758143ffb114f2f601cb20b6276951416a2f94fbf4ad081779d79f4f195b22",
michael@0 334 "575323a9661f5d28387964d2ba6ab92c17d05a8a"
michael@0 335 },
michael@0 336 {
michael@0 337 304,
michael@0 338 "5498793f60916ff1c918dde572cdea76da8629ba4ead6d065de3dfb48de94d234cc1c5002910",
michael@0 339 "feb44494af72f245bfe68e86c4d7986d57c11db7"
michael@0 340 },
michael@0 341 {
michael@0 342 312,
michael@0 343 "498a1e0b39fa49582ae688cd715c86fbaf8a81b8b11b4d1594c49c902d197c8ba8a621fd6e3be5",
michael@0 344 "cff2290b3648ba2831b98dde436a72f9ebf51eee"
michael@0 345 },
michael@0 346 {
michael@0 347 320,
michael@0 348 "3a36ae71521f9af628b3e34dcb0d4513f84c78ee49f10416a98857150b8b15cb5c83afb4b570376e",
michael@0 349 "9b4efe9d27b965905b0c3dab67b8d7c9ebacd56c"
michael@0 350 },
michael@0 351 {
michael@0 352 328,
michael@0 353 "dcc76b40ae0ea3ba253e92ac50fcde791662c5b6c948538cffc2d95e9de99cac34dfca38910db2678f",
michael@0 354 "afedb0ff156205bcd831cbdbda43db8b0588c113"
michael@0 355 },
michael@0 356 {
michael@0 357 336,
michael@0 358 "5b5ec6ec4fd3ad9c4906f65c747fd4233c11a1736b6b228b92e90cddabb0c7c2fcf9716d3fad261dff33",
michael@0 359 "8deb1e858f88293a5e5e4d521a34b2a4efa70fc4"
michael@0 360 },
michael@0 361 {
michael@0 362 344,
michael@0 363 "df48a37b29b1d6de4e94717d60cdb4293fcf170bba388bddf7a9035a15d433f20fd697c3e4c8b8c5f590ab",
michael@0 364 "95cbdac0f74afa69cebd0e5c7defbc6faf0cbeaf"
michael@0 365 },
michael@0 366 {
michael@0 367 352,
michael@0 368 "1f179b3b82250a65e1b0aee949e218e2f45c7a8dbfd6ba08de05c55acfc226b48c68d7f7057e5675cd96fcfc",
michael@0 369 "f0307bcb92842e5ae0cd4f4f14f3df7f877fbef2"
michael@0 370 },
michael@0 371 {
michael@0 372 360,
michael@0 373 "ee3d72da3a44d971578972a8e6780ce64941267e0f7d0179b214fa97855e1790e888e09fbe3a70412176cb3b54",
michael@0 374 "7b13bb0dbf14964bd63b133ac85e22100542ef55"
michael@0 375 },
michael@0 376 {
michael@0 377 368,
michael@0 378 "d4d4c7843d312b30f610b3682254c8be96d5f6684503f8fbfbcd15774fc1b084d3741afb8d24aaa8ab9c104f7258",
michael@0 379 "c314d2b6cf439be678d2a74e890d96cfac1c02ed"
michael@0 380 },
michael@0 381 {
michael@0 382 376,
michael@0 383 "32c094944f5936a190a0877fb9178a7bf60ceae36fd530671c5b38c5dbd5e6a6c0d615c2ac8ad04b213cc589541cf6",
michael@0 384 "4d0be361e410b47a9d67d8ce0bb6a8e01c53c078"
michael@0 385 },
michael@0 386 {
michael@0 387 384,
michael@0 388 "e5d3180c14bf27a5409fa12b104a8fd7e9639609bfde6ee82bbf9648be2546d29688a65e2e3f3da47a45ac14343c9c02",
michael@0 389 "e5353431ffae097f675cbf498869f6fbb6e1c9f2"
michael@0 390 },
michael@0 391 {
michael@0 392 392,
michael@0 393 "e7b6e4b69f724327e41e1188a37f4fe38b1dba19cbf5a7311d6e32f1038e97ab506ee05aebebc1eed09fc0e357109818b9",
michael@0 394 "b8720a7068a085c018ab18961de2765aa6cd9ac4"
michael@0 395 },
michael@0 396 {
michael@0 397 400,
michael@0 398 "bc880cb83b8ac68ef2fedc2da95e7677ce2aa18b0e2d8b322701f67af7d5e7a0d96e9e33326ccb7747cfff0852b961bfd475",
michael@0 399 "b0732181568543ba85f2b6da602b4b065d9931aa"
michael@0 400 },
michael@0 401 {
michael@0 402 408,
michael@0 403 "235ea9c2ba7af25400f2e98a47a291b0bccdaad63faa2475721fda5510cc7dad814bce8dabb611790a6abe56030b798b75c944",
michael@0 404 "9c22674cf3222c3ba921672694aafee4ce67b96b"
michael@0 405 },
michael@0 406 {
michael@0 407 416,
michael@0 408 "07e3e29fed63104b8410f323b975fd9fba53f636af8c4e68a53fb202ca35dd9ee07cb169ec5186292e44c27e5696a967f5e67709",
michael@0 409 "d128335f4cecca9066cdae08958ce656ff0b4cfc"
michael@0 410 },
michael@0 411 {
michael@0 412 424,
michael@0 413 "65d2a1dd60a517eb27bfbf530cf6a5458f9d5f4730058bd9814379547f34241822bf67e6335a6d8b5ed06abf8841884c636a25733f",
michael@0 414 "0b67c57ac578de88a2ae055caeaec8bb9b0085a0"
michael@0 415 },
michael@0 416 {
michael@0 417 432,
michael@0 418 "dcc86b3bd461615bab739d8daafac231c0f462e819ad29f9f14058f3ab5b75941d4241ea2f17ebb8a458831b37a9b16dead4a76a9b0e",
michael@0 419 "c766f912a89d4ccda88e0cce6a713ef5f178b596"
michael@0 420 },
michael@0 421 {
michael@0 422 440,
michael@0 423 "4627d54f0568dc126b62a8c35fb46a9ac5024400f2995e51635636e1afc4373dbb848eb32df23914230560b82477e9c3572647a7f2bb92",
michael@0 424 "9aa3925a9dcb177b15ccff9b78e70cf344858779"
michael@0 425 },
michael@0 426 {
michael@0 427 448,
michael@0 428 "ba531affd4381168ef24d8b275a84d9254c7f5cc55fded53aa8024b2c5c5c8aa7146fe1d1b83d62b70467e9a2e2cb67b3361830adbab28d7",
michael@0 429 "4811fa30042fc076acf37c8e2274d025307e5943"
michael@0 430 },
michael@0 431 {
michael@0 432 456,
michael@0 433 "8764dcbcf89dcf4282eb644e3d568bdccb4b13508bfa7bfe0ffc05efd1390be22109969262992d377691eb4f77f3d59ea8466a74abf57b2ef4",
michael@0 434 "6743018450c9730761ee2b130df9b91c1e118150"
michael@0 435 },
michael@0 436 {
michael@0 437 464,
michael@0 438 "497d9df9ddb554f3d17870b1a31986c1be277bc44feff713544217a9f579623d18b5ffae306c25a45521d2759a72c0459b58957255ab592f3be4",
michael@0 439 "71ad4a19d37d92a5e6ef3694ddbeb5aa61ada645"
michael@0 440 },
michael@0 441 {
michael@0 442 472,
michael@0 443 "72c3c2e065aefa8d9f7a65229e818176eef05da83f835107ba90ec2e95472e73e538f783b416c04654ba8909f26a12db6e5c4e376b7615e4a25819",
michael@0 444 "a7d9dc68dacefb7d6116186048cb355cc548e11d"
michael@0 445 },
michael@0 446 {
michael@0 447 480,
michael@0 448 "7cc9894454d0055ab5069a33984e2f712bef7e3124960d33559f5f3b81906bb66fe64da13c153ca7f5cabc89667314c32c01036d12ecaf5f9a78de98",
michael@0 449 "142e429f0522ba5abf5131fa81df82d355b96909"
michael@0 450 },
michael@0 451 {
michael@0 452 488,
michael@0 453 "74e8404d5a453c5f4d306f2cfa338ca65501c840ddab3fb82117933483afd6913c56aaf8a0a0a6b2a342fc3d9dc7599f4a850dfa15d06c61966d74ea59",
michael@0 454 "ef72db70dcbcab991e9637976c6faf00d22caae9"
michael@0 455 },
michael@0 456 {
michael@0 457 496,
michael@0 458 "46fe5ed326c8fe376fcc92dc9e2714e2240d3253b105adfbb256ff7a19bc40975c604ad7c0071c4fd78a7cb64786e1bece548fa4833c04065fe593f6fb10",
michael@0 459 "f220a7457f4588d639dc21407c942e9843f8e26b"
michael@0 460 },
michael@0 461 {
michael@0 462 504,
michael@0 463 "836dfa2524d621cf07c3d2908835de859e549d35030433c796b81272fd8bc0348e8ddbc7705a5ad1fdf2155b6bc48884ac0cd376925f069a37849c089c8645",
michael@0 464 "ddd2117b6e309c233ede85f962a0c2fc215e5c69"
michael@0 465 },
michael@0 466 {
michael@0 467 512,
michael@0 468 "7e3a4c325cb9c52b88387f93d01ae86d42098f5efa7f9457388b5e74b6d28b2438d42d8b64703324d4aa25ab6aad153ae30cd2b2af4d5e5c00a8a2d0220c6116",
michael@0 469 "a3054427cdb13f164a610b348702724c808a0dcc"
michael@0 470 }
michael@0 471 };
michael@0 472
michael@0 473
michael@0 474 for (i=0; i < 65; i++) {
michael@0 475 err = hash_test_case_add(&sha1_test_case_list,
michael@0 476 tc[i].hex_data,
michael@0 477 tc[i].bit_len/8,
michael@0 478 tc[i].hex_hash, 20);
michael@0 479 if (err) {
michael@0 480 printf("error adding hash test case (code %d)\n", err);
michael@0 481 return err;
michael@0 482 }
michael@0 483 }
michael@0 484
michael@0 485 return err_status_ok;
michael@0 486 }
michael@0 487
michael@0 488 err_status_t
michael@0 489 sha1_dealloc_test_cases(void) {
michael@0 490 hash_test_case_t *t, *next;
michael@0 491
michael@0 492 for (t = sha1_test_case_list; t != NULL; t = next) {
michael@0 493 next = t->next_test_case;
michael@0 494 free(t);
michael@0 495 }
michael@0 496
michael@0 497 sha1_test_case_list = NULL;
michael@0 498
michael@0 499 return err_status_ok;
michael@0 500 }
michael@0 501
michael@0 502
michael@0 503
michael@0 504 err_status_t
michael@0 505 sha1_validate(void) {
michael@0 506 hash_test_case_t *test_case;
michael@0 507 err_status_t err;
michael@0 508
michael@0 509 err = sha1_add_test_cases();
michael@0 510 if (err) {
michael@0 511 printf("error adding SHA1 test cases (error code %d)\n", err);
michael@0 512 return err;
michael@0 513 }
michael@0 514
michael@0 515 if (sha1_test_case_list == NULL)
michael@0 516 return err_status_cant_check;
michael@0 517
michael@0 518 test_case = sha1_test_case_list;
michael@0 519 while (test_case != NULL) {
michael@0 520 err = sha1_test_case_validate(test_case);
michael@0 521 if (err) {
michael@0 522 printf("error validating hash test case (error code %d)\n", err);
michael@0 523 return err;
michael@0 524 }
michael@0 525 test_case = test_case->next_test_case;
michael@0 526 }
michael@0 527
michael@0 528 sha1_dealloc_test_cases();
michael@0 529
michael@0 530 return err_status_ok;
michael@0 531 }
michael@0 532
michael@0 533
michael@0 534
michael@0 535 int
michael@0 536 main (void) {
michael@0 537 err_status_t err;
michael@0 538
michael@0 539 printf("sha1 test driver\n");
michael@0 540
michael@0 541 err = sha1_validate();
michael@0 542 if (err) {
michael@0 543 printf("SHA1 did not pass validation testing\n");
michael@0 544 return 1;
michael@0 545 }
michael@0 546 printf("SHA1 passed validation tests\n");
michael@0 547
michael@0 548 return 0;
michael@0 549
michael@0 550 }

mercurial