このページを編集する際は,編集に関する方針に従ってください.[]
概要[]
- gcc-4.1.0/libiberty/md5.cにて定義
- 残りのバッファを処理し、restbufにハッシュ値を入れる
- ビッグエンディアンかリトルエンディアンかに注意
引数[]
- struct md5_ctx *ctx
- void *resbuf
実装[]
49: #ifdef WORDS_BIGENDIAN
50: # define SWAP(n) \
51: (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
52: #else
53: # define SWAP(n) (n)
54: #endif
55:
56:
57: /* This array contains the bytes used to pad the buffer to the next
58: 64-byte boundary. (RFC 1321, 3.1: Step 1) */
59: static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ };
~
~
92: /* Process the remaining bytes in the internal buffer and the usual
93: prolog according to the standard and write the result to RESBUF.
94:
95: IMPORTANT: On some systems it is required that RESBUF is correctly
96: aligned for a 32 bits value. */
97: void *
98: md5_finish_ctx (struct md5_ctx *ctx, void *resbuf)
99: {
100: /* Take yet unprocessed bytes into account. */
これまでに未処理のバイトを考慮に入れてください。
101: md5_uint32 bytes = ctx->buflen;
102: size_t pad;
103:
104: /* Now count remaining bytes. */
すぐに、残りのバイトを数えてください。
105: ctx->total[0] += bytes;
106: if (ctx->total[0] < bytes)
107: ++ctx->total[1];
108:
~
*バッファを埋める
109: pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes;
110: memcpy (&ctx->buffer[bytes], fillbuf, pad);
111:
112: /* Put the 64-bit file length in *bits* at the end of the buffer. */
113: *(md5_uint32 *) &ctx->buffer[bytes + pad] = SWAP (ctx->total[0] << 3);
114: *(md5_uint32 *) &ctx->buffer[bytes + pad + 4] = SWAP ((ctx->total[1] << 3) |
115: (ctx->total[0] >> 29));
116:
~
117: /* Process last bytes. */
最後のバイト列を処理する。
*bytes + pad + 8の8は113,114行目の分
**bytes + padを64で割った余りが56になるので、56+8で64で割り切れるようになる
118: md5_process_block (ctx->buffer, bytes + pad + 8, ctx);
119:
120: return md5_read_ctx (ctx, resbuf);
121: }