- Timestamp:
- Jun 25, 2009 12:46:00 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/1.0/pjlib-util/src/pjlib-util-test/encryption.c
r2394 r2809 65 65 static int sha1_test1(void) 66 66 { 67 enum { MILLION = 1000000 }; 67 68 int k; 68 69 pj_sha1_context context; 69 70 pj_uint8_t digest[20]; 70 71 char output[80]; 72 pj_pool_t *pool; 73 pj_uint8_t *block; 71 74 72 75 PJ_LOG(3, (THIS_FILE, " SHA1 test vector 1 from sha1.c..")); … … 87 90 /* million 'a' vector we feed separately */ 88 91 pj_sha1_init(&context); 89 for (k = 0; k < 1000000; k++)92 for (k = 0; k < MILLION; k++) 90 93 pj_sha1_update(&context, (pj_uint8_t*)"a", 1); 91 94 pj_sha1_final(&context, digest); … … 95 98 return -20; 96 99 } 100 101 /* million 'a' test, using block */ 102 pool = pj_pool_create(mem, "sha1test", 256, 512, NULL); 103 block = (pj_uint8_t*)pj_pool_alloc(pool, MILLION); 104 pj_memset(block, 'a', MILLION); 105 106 pj_sha1_init(&context); 107 pj_sha1_update(&context, block, MILLION); 108 pj_sha1_final(&context, digest); 109 digest_to_hex(digest, output); 110 if (strcmp(output, sha1_test_results[2])) { 111 pj_pool_release(pool); 112 PJ_LOG(3, (THIS_FILE, " incorrect hash result for block update!")); 113 return -21; 114 } 115 116 /* verify that original buffer was not modified */ 117 for (k=0; k<MILLION; ++k) { 118 if (block[k] != 'a') { 119 pj_pool_release(pool); 120 PJ_LOG(3, (THIS_FILE, " block was modified!")); 121 return -22; 122 } 123 } 124 125 pj_pool_release(pool); 97 126 98 127 /* success */
Note: See TracChangeset
for help on using the changeset viewer.