メインページ | アルファベット順一覧 | 構成 | ファイル一覧 | 構成メンバ | ファイルメンバ | 関連ページ

# md5.h

http://sourceforge.net/projects/libmd5-rfc/ [詳細]

このグラフは、どのファイルから直接、間接的にインクルードされているかを示しています。

ソースコードを見る。

## 構成
struct | md5_state_s
## 型定義
typedef unsigned char | md5_byte_t
typedef unsigned int | md5_word_t
typedef md5_state_s | md5_state_t
## 関数
void | md5_init (md5_state_t *pms)
void | md5_append (md5_state_t *pms, const md5_byte_t *data, int nbytes)
void | md5_finish (md5_state_t *pms, md5_byte_t digest[16])
void | md5_finalize (md5_state_t *pms)
void | md5_get_digest (md5_state_t *pms, md5_byte_t digest[16])
void | md5_get_str_digest (md5_state_t *pms, char digest[32+1])

## 説明

http://sourceforge.net/projects/libmd5-rfc/

## Copyright

Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved.

This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution.

L. Peter Deutsch ghost@aladdin.com

Id
  md5.h,v 1.1 2004/07/11 09:46:28 studiokingyonet Exp

Independent implementation of MD5 (RFC 1321).

This code implements the MD5 Algorithm defined in RFC 1321, whose text is available at http://www.ietf.org/rfc/rfc1321.txt The code is derived from the text of the RFC, including the test suite (section A.5) but excluding the rest of Appendix A. It does not include any code or documentation that is identified in the RFC as being copyrighted.

The original and principal author of md5.h is L. Peter Deutsch <ghost@aladdin.com>. Other authors are noted in the change history that follows (in reverse chronological order):

2002-04-13 lpd Removed support for non-ANSI compilers; removed references to Ghostscript; clarified derivation from RFC 1321; now handles byte order either statically or dynamically. 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5); added conditionalization for C++ compilation from Martin Purschke <purschke@bnl.gov>. 1999-05-03 lpd Original version.

This package supports both compile-time and run-time determination of CPU byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is defined as non-zero, the code will be compiled to run only on big-endian CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to run on either big- or little-endian CPUs, but will run slightly less efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined.

覚え書き:
  reconstruct by d金魚

md5.h で定義されています。

## 型定義

typedef unsigned char md5_byte_t

| md5.h の 68 行で定義されています。

typedef struct md5_state_s md5_state_t

typedef unsigned int md5_word_t

| md5.h の 69 行で定義されています。

## 関数

void md5_append | ( | md5_state_t * | pms,
|  | const md5_byte_t * | data,
|  | int | nbytes
| ) |

| Append a string to the message. md5.c の 324 行で定義されています。 参照先 md5_state_s::buf, md5_state_s::count, と md5_process(). 参照元 dkcMD5AdapterLoadStandard(), と md5_finalize().
    00325 {
    00326   const md5_byte_t *p = data;
    00327   int left = nbytes;
    00328   int offset = (pms->count[0] >> 3) & 63;
    00329   md5_word_t nbits = (md5_word_t)(nbytes << 3);
    00330
    00331   if (nbytes <= 0)
    00332         return;
    00333   /* Update the message length. */
    00334   pms->count[1] += nbytes >> 29;
    00335   pms->count[0] += nbits;
    00336   if (pms->count[0] < nbits)
    00337   pms->count[1]++;
    00338   /* Process an initial partial block. */
    00339   if (offset) {
    00340     int copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
    00341     memcpy(pms->buf + offset, p, copy);
    00342     if (offset + copy < 64)
    00343     return;
    00344     p += copy;
    00345     left -= copy;
    00346     md5_process(pms, pms->buf);
    00347   }
    00348   /* Process full blocks. */
    00349   for (; left >= 64; p += 64, left -= 64)
    00350         md5_process(pms, p);
    00351   /* Process a final partial block. */
    00352   if (left)
    00353         memcpy(pms->buf, p, left);
    00354 }

void md5_finalize | ( | md5_state_t * | pms | ) |

| finalize process md5.c の 368 行で定義されています。 参照先 md5_state_s::count, と md5_append(). 参照元 dkcMD5AdapterFinal(), と md5_finish().
    00368                                    {
    00369     static const md5_byte_t pad[64] = {
    00370     0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    00371     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    00372     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    00373     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    00374   };
    00375   md5_byte_t data[8];
    00376   int i;
    00377   /* Save the length before padding. */
    00378   for (i = 0; i < 8; ++i){
    00379     data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
    00380   }
    00381   /* Pad to 56 bytes mod 64. */
    00382   md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
    00383   /* Append the length. */
    00384   md5_append(pms, data, 8);
    00385 }

void md5_finish | ( | md5_state_t * | pms,
|  | md5_byte_t | digest[16]
| ) |

| Finish the message and return the digest. ( md5_finalize() + md5_get_digest() ) md5.c の 358 行で定義されています。 参照先 md5_finalize(), と md5_get_digest().
    00359 {
    00360   md5_finalize(pms);
    00361     md5_get_digest(pms,digest);
    00362 }

void md5_get_digest | ( | md5_state_t * | pms,
|  | md5_byte_t | digest[16]
| ) |

| get digest binary value md5.c の 387 行で定義されています。 参照先 md5_state_s::abcd. 参照元 dkcMD5AdapterDigest(), md5_finish(), と md5_get_str_digest().
    00387                                                            {
    00388     int i;
    00389     for (i = 0; i < 16; ++i){
    00390     digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
    00391   }
    00392 }

void md5_get_str_digest | ( | md5_state_t * | pms,
|  | char | digest[32+1]
| ) |

| get digest strings md5.c の 394 行で定義されています。 参照先 md5_get_digest(). 参照元 dkcMD5AdapterDigestStr().
    00394                                                              {
    00395     md5_byte_t temp[16];
    00396     int i;
    00397
    00398     md5_get_digest(pms,temp);
    00399
    00400
    00401     for (i=0; i<16; i++){
    00402     //wsprintf(digest+i*2, "%02x", temp[i]);
    00403         sprintf(digest+i*2,"%02x", temp[i]);
    00404     }
    00405   digest[32]='\0';
    00406 }

void md5_init | ( | md5_state_t * | pms | ) |

| Initialize the algorithm. md5.c の 315 行で定義されています。 参照先 md5_state_s::abcd, md5_state_s::count, と T_MASK. 参照元 dkcMD5AdapterInit().
    00316 {
    00317   pms->count[0] = pms->count[1] = 0;
    00318   pms->abcd[0] = 0x67452301;
    00319   pms->abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476;
    00320   pms->abcd[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301;
    00321   pms->abcd[3] = 0x10325476;
    00322 }