阅读版本:2.0
sha1(tsk_sha1.h)接口:tsk_sha1_errcode_t tsk_sha1compute(const char* input, tsk_size_t size, tsk_sha1string_t *result);在此此接口实现中,使用string中hex值转为字符串的函数接口tsk_str_from_hex结合uuid来看此接口的应用time(tsk_time.h)接口:uint64_t tsk_time_now();返回当前时间的无符号整数UUID(tsk_uuid.h)接口:int tsk_uuidgenerate(tsk_uuidstring_t *result);在此接口实现中应用上述两个接口,看下源代码:1 /**@defgroup tsk_uuid_group niversally Unique Identifier (UUID version 5) implementation (RFC 4122). 2 */ 3 4 /**@ingroup tsk_uuid_group 5 */ 6 int tsk_uuidgenerate(tsk_uuidstring_t *result) 7 { 8 /* From wikipedia 9 * Version 5 UUIDs use a scheme with SHA-1 hashing, otherwise it is the same idea as in version 3.10 * RFC 4122 states that version 5 is preferred over version 3 name based UUIDs.11 * Note that the 160 bit SHA-1 hash is truncated to 128 bits to make the length work out.12 */13 tsk_sha1string_t sha1result;14 tsk_istr_t now;15 unsigned i, k;16 static char HEX[] = "0123456789abcdef";17 18 tsk_itoa(tsk_time_now(), &now);// tsk_itoa用法19 tsk_sha1compute(now, sizeof(now), &sha1result);// tsk_sha1compute用法20 21 /* XOR the SHA-1 result with random numbers. */22 for(i=0; i<(TSK_UUID_DIGEST_SIZE*2); i+=4){23 #if 024 *((uint32_t*)&sha1result[i]) ^= rand();25 #else26 k = rand();27 sha1result[i] ^= k, sha1result[i + 1] ^= k,28 sha1result[i + 2] ^= k, sha1result[i + 3] ^= k;29 #endif30 31 for(k=0; k
md5(tsk_md5.h)接口:int tsk_md5compute(const char* input, tsk_size_t size, tsk_md5string_t *result);eg,简单调用:tsk_md5compute(msgs_md5[i].msg, strlen(msgs_md5[i].msg), &md5result);base64(tsk_base64.h)接口:tsk_size_t tsk_base64_encode(const uint8_t* input, tsk_size_t input_size, char **output);tsk_size_t tsk_base64_decode(const uint8_t* input, tsk_size_t input_size, char **output);eg.size = tsk_base64_encode((const uint8_t*)b64_msgs[i].ascii, strlen(b64_msgs[i].ascii), &output_e);HMAC(tsk_hmac.h)HMAC是密钥相关的哈希运算消息认证码(Hash-based Message Authentication Code),HMAC运算利用哈希算法,以一个密钥和一个消息为输入,生成一个消息摘要作为输出。 接口:int hmac_md5_compute(const uint8_t* input, tsk_size_t input_size, const char* key, tsk_size_t key_size, tsk_md5string_t *result);int hmac_md5digest_compute(const uint8_t* input, tsk_size_t input_size, const char* key, tsk_size_t key_size, tsk_md5digest_t result);int hmac_sha1_compute(const uint8_t* input, tsk_size_t input_size, const char* key, tsk_size_t key_size, tsk_sha1string_t *result);int hmac_sha1digest_compute(const uint8_t* input, tsk_size_t input_size, const char* key, tsk_size_t key_size, tsk_sha1digest_t result);【备注】tinySAK部分的代码就阅读到此,其他源码后续应用中阅读比如,线程,timer,互斥锁等,可以在实际中应用,也可以依据平台使用该平台下提供的对象...努力学习...