#include <stdint.h>#include <string.h>#include <byteswap.h>#include <gpxe/crypto.h>#include <gpxe/md5.h>Go to the source code of this file.
Data Structures | |
| struct | md5_step |
Functions | |
| FILE_LICENCE (GPL2_OR_LATER) | |
| static u32 | f1 (u32 b, u32 c, u32 d) |
| static u32 | f2 (u32 b, u32 c, u32 d) |
| static u32 | f3 (u32 b, u32 c, u32 d) |
| static u32 | f4 (u32 b, u32 c, u32 d) |
| static void | md5_transform (u32 *hash, const u32 *in) |
| static void | le32_to_cpu_array (u32 *buf, unsigned int words) |
| static void | cpu_to_le32_array (u32 *buf, unsigned int words) |
| static void | md5_transform_helper (struct md5_ctx *ctx) |
| static void | md5_init (void *context) |
| static void | md5_update (void *context, const void *data, size_t len) |
| static void | md5_final (void *context, void *out) |
Variables | |
| static struct md5_step | md5_steps [4] |
| static const u8 | r [64] |
| static const u32 | k [64] |
| struct digest_algorithm | md5_algorithm |
| FILE_LICENCE | ( | GPL2_OR_LATER | ) |
Definition at line 106 of file md5.c.
References md5_step::coefficient, md5_step::constant, md5_step::f, k, r, step(), and u32.
Referenced by md5_final(), and md5_transform_helper().
00107 { 00108 u32 a, b, c, d, f, g, temp; 00109 int i; 00110 struct md5_step *step; 00111 00112 a = hash[0]; 00113 b = hash[1]; 00114 c = hash[2]; 00115 d = hash[3]; 00116 00117 for ( i = 0 ; i < 64 ; i++ ) { 00118 step = &md5_steps[i >> 4]; 00119 f = step->f ( b, c, d ); 00120 g = ( ( i * step->coefficient + step->constant ) & 0xf ); 00121 temp = d; 00122 d = c; 00123 c = b; 00124 a += ( f + k[i] + in[g] ); 00125 a = ( ( a << r[i] ) | ( a >> ( 32-r[i] ) ) ); 00126 b += a; 00127 a = temp; 00128 } 00129 00130 hash[0] += a; 00131 hash[1] += b; 00132 hash[2] += c; 00133 hash[3] += d; 00134 }
| static void le32_to_cpu_array | ( | u32 * | buf, | |
| unsigned int | words | |||
| ) | [inline, static] |
Definition at line 137 of file md5.c.
References le32_to_cpus.
Referenced by md5_final(), and md5_transform_helper().
00138 { 00139 while (words--) { 00140 le32_to_cpus(buf); 00141 buf++; 00142 } 00143 }
| static void cpu_to_le32_array | ( | u32 * | buf, | |
| unsigned int | words | |||
| ) | [inline, static] |
Definition at line 145 of file md5.c.
References cpu_to_le32s.
Referenced by md5_final().
00146 { 00147 while (words--) { 00148 cpu_to_le32s(buf); 00149 buf++; 00150 } 00151 }
| static void md5_transform_helper | ( | struct md5_ctx * | ctx | ) | [inline, static] |
Definition at line 153 of file md5.c.
References md5_ctx::block, md5_ctx::hash, le32_to_cpu_array(), md5_transform(), and u32.
Referenced by md5_final(), and md5_update().
00154 { 00155 le32_to_cpu_array(ctx->block, sizeof(ctx->block) / sizeof(u32)); 00156 md5_transform(ctx->hash, ctx->block); 00157 }
| static void md5_init | ( | void * | context | ) | [static] |
Definition at line 159 of file md5.c.
References md5_ctx::byte_count, and md5_ctx::hash.
00160 { 00161 struct md5_ctx *mctx = context; 00162 00163 mctx->hash[0] = 0x67452301; 00164 mctx->hash[1] = 0xefcdab89; 00165 mctx->hash[2] = 0x98badcfe; 00166 mctx->hash[3] = 0x10325476; 00167 mctx->byte_count = 0; 00168 }
| static void md5_update | ( | void * | context, | |
| const void * | data, | |||
| size_t | len | |||
| ) | [static] |
Definition at line 170 of file md5.c.
References md5_ctx::block, md5_ctx::byte_count, md5_transform_helper(), memcpy, and u32.
00171 { 00172 struct md5_ctx *mctx = context; 00173 const u32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f); 00174 00175 mctx->byte_count += len; 00176 00177 if (avail > len) { 00178 memcpy((char *)mctx->block + (sizeof(mctx->block) - avail), 00179 data, len); 00180 return; 00181 } 00182 00183 memcpy((char *)mctx->block + (sizeof(mctx->block) - avail), 00184 data, avail); 00185 00186 md5_transform_helper(mctx); 00187 data += avail; 00188 len -= avail; 00189 00190 while (len >= sizeof(mctx->block)) { 00191 memcpy(mctx->block, data, sizeof(mctx->block)); 00192 md5_transform_helper(mctx); 00193 data += sizeof(mctx->block); 00194 len -= sizeof(mctx->block); 00195 } 00196 00197 memcpy(mctx->block, data, len); 00198 }
| static void md5_final | ( | void * | context, | |
| void * | out | |||
| ) | [static] |
Definition at line 200 of file md5.c.
References md5_ctx::block, md5_ctx::byte_count, cpu_to_le32_array(), md5_ctx::hash, le32_to_cpu_array(), md5_transform(), md5_transform_helper(), memcpy, memset(), offset, and u32.
00201 { 00202 struct md5_ctx *mctx = context; 00203 const unsigned int offset = mctx->byte_count & 0x3f; 00204 char *p = (char *)mctx->block + offset; 00205 int padding = 56 - (offset + 1); 00206 00207 *p++ = 0x80; 00208 if (padding < 0) { 00209 memset(p, 0x00, padding + sizeof (u64)); 00210 md5_transform_helper(mctx); 00211 p = (char *)mctx->block; 00212 padding = 56; 00213 } 00214 00215 memset(p, 0, padding); 00216 mctx->block[14] = mctx->byte_count << 3; 00217 mctx->block[15] = mctx->byte_count >> 29; 00218 le32_to_cpu_array(mctx->block, (sizeof(mctx->block) - 00219 sizeof(u64)) / sizeof(u32)); 00220 md5_transform(mctx->hash, mctx->block); 00221 cpu_to_le32_array(mctx->hash, sizeof(mctx->hash) / sizeof(u32)); 00222 memcpy(out, mctx->hash, sizeof(mctx->hash)); 00223 memset(mctx, 0, sizeof(*mctx)); 00224 }
Initial value:
{
7,12,17,22,7,12,17,22,7,12,17,22,7,12,17,22,
5,9,14,20,5,9,14,20,5,9,14,20,5,9,14,20,
4,11,16,23,4,11,16,23,4,11,16,23,4,11,16,23,
6,10,15,21,6,10,15,21,6,10,15,21,6,10,15,21
}
Definition at line 80 of file md5.c.
Referenced by __attribute__(), bcom_phy_init(), bi_compare(), bi_int_divide(), bi_int_multiply(), fls(), genesis_mac_init(), md5_transform(), and strcspn().
Initial value:
{
0xd76aa478UL, 0xe8c7b756UL, 0x242070dbUL, 0xc1bdceeeUL,
0xf57c0fafUL, 0x4787c62aUL, 0xa8304613UL, 0xfd469501UL,
0x698098d8UL, 0x8b44f7afUL, 0xffff5bb1UL, 0x895cd7beUL,
0x6b901122UL, 0xfd987193UL, 0xa679438eUL, 0x49b40821UL,
0xf61e2562UL, 0xc040b340UL, 0x265e5a51UL, 0xe9b6c7aaUL,
0xd62f105dUL, 0x02441453UL, 0xd8a1e681UL, 0xe7d3fbc8UL,
0x21e1cde6UL, 0xc33707d6UL, 0xf4d50d87UL, 0x455a14edUL,
0xa9e3e905UL, 0xfcefa3f8UL, 0x676f02d9UL, 0x8d2a4c8aUL,
0xfffa3942UL, 0x8771f681UL, 0x6d9d6122UL, 0xfde5380cUL,
0xa4beea44UL, 0x4bdecfa9UL, 0xf6bb4b60UL, 0xbebfbc70UL,
0x289b7ec6UL, 0xeaa127faUL, 0xd4ef3085UL, 0x04881d05UL,
0xd9d4d039UL, 0xe6db99e5UL, 0x1fa27cf8UL, 0xc4ac5665UL,
0xf4292244UL, 0x432aff97UL, 0xab9423a7UL, 0xfc93a039UL,
0x655b59c3UL, 0x8f0ccc92UL, 0xffeff47dUL, 0x85845dd1UL,
0x6fa87e4fUL, 0xfe2ce6e0UL, 0xa3014314UL, 0x4e0811a1UL,
0xf7537e82UL, 0xbd3af235UL, 0x2ad7d2bbUL, 0xeb86d391UL,
}
Definition at line 87 of file md5.c.
Referenced by AES_convert_key(), AES_decrypt(), AES_encrypt(), bi_export(), bi_set_mod(), md5_transform(), and vxgetlink().
| struct digest_algorithm md5_algorithm |
Initial value:
{
.name = "md5",
.ctxsize = MD5_CTX_SIZE,
.blocksize = ( MD5_BLOCK_WORDS * 4 ),
.digestsize = MD5_DIGEST_SIZE,
.init = md5_init,
.update = md5_update,
.final = md5_final,
}
Definition at line 226 of file md5.c.
Referenced by add_tls(), iscsi_handle_chap_i_value(), iscsi_handle_chap_r_value(), md5sum_exec(), tkip_kie_mic(), tls_add_handshake(), tls_prf(), and tls_verify_handshake().
1.5.7.1