Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 #include <string.h>
00025 #include <stdio.h>
00026 #include "ink_code.h"
00027 #include "INK_MD5.h"
00028 #include "ink_assert.h"
00029 #include "INK_MD5.h"
00030 
00031 ats::CryptoHash const ats::CRYPTO_HASH_ZERO; 
00032 
00033 MD5Context::MD5Context() {
00034   MD5_Init(&_ctx);
00035 }
00036 
00037 bool
00038 MD5Context::update(void const* data, int length) {
00039   return 0 != MD5_Update(&_ctx, data, length);
00040 }
00041 
00042 bool
00043 MD5Context::finalize(CryptoHash& hash) {
00044   return 0 != MD5_Final(hash.u8, &_ctx);
00045 }
00046 
00047 
00048 
00049 
00050 int
00051 ink_code_incr_md5_init(INK_DIGEST_CTX * context) {
00052   return MD5_Init(context);
00053 }
00054 
00055 
00056 
00057 
00058 int
00059 ink_code_incr_md5_update(INK_DIGEST_CTX * context, const char *input, int input_length) {
00060   return MD5_Update(context, input, input_length);
00061 }
00062 
00063 
00064 
00065 
00066 int
00067 ink_code_incr_md5_final(char *sixteen_byte_hash_pointer, INK_DIGEST_CTX * context) {
00068   return MD5_Final((unsigned char*)sixteen_byte_hash_pointer, context);
00069 }
00070 
00071 
00072 
00073 
00074 
00075 
00076 int
00077 ink_code_md5(unsigned char const* input, int input_length, unsigned char *sixteen_byte_hash_pointer)
00078 {
00079   MD5_CTX context;
00080 
00081   MD5_Init(&context);
00082   MD5_Update(&context, input, input_length);
00083   MD5_Final(sixteen_byte_hash_pointer, &context);
00084 
00085   return (0);
00086 }
00087 
00088 
00089 
00090 
00091 
00092 
00093 
00094 
00095 
00096 
00097 
00098 
00099 
00100 char *
00101 ink_code_md5_stringify(char *dest33, const size_t destSize, const char *md5)
00102 {
00103   ink_assert(destSize >= 33);
00104 
00105   int i;
00106   for (i = 0; i < 16; i++) {
00107     
00108     
00109     sprintf(&(dest33[i * 2]), "%02X", md5[i]);
00110   }
00111   ink_assert(dest33[32] == '\0');
00112   return (dest33);
00113 }                               
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00121 
00122 
00123 
00124 
00125 
00126 
00127 
00128 char *
00129 ink_code_to_hex_str(char *dest33, uint8_t const* hash)
00130 {
00131   int i;
00132   char *d;
00133 
00134   static char hex_digits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
00135 
00136   d = dest33;
00137   for (i = 0; i < 16; i += 4) {
00138     *(d + 0) = hex_digits[hash[i + 0] >> 4];
00139     *(d + 1) = hex_digits[hash[i + 0] & 15];
00140     *(d + 2) = hex_digits[hash[i + 1] >> 4];
00141     *(d + 3) = hex_digits[hash[i + 1] & 15];
00142     *(d + 4) = hex_digits[hash[i + 2] >> 4];
00143     *(d + 5) = hex_digits[hash[i + 2] & 15];
00144     *(d + 6) = hex_digits[hash[i + 3] >> 4];
00145     *(d + 7) = hex_digits[hash[i + 3] & 15];
00146     d += 8;
00147   }
00148   *d = '\0';
00149   return (dest33);
00150 }
00151