웹마스터 팁
page_full_width" class="col-xs-12" |cond="$__Context->page_full_width">
md5() 알고리듬
2002.02.05 09:52
상단 소개등 내용 생략
아래 내용은 알고리듬 부분만 발췌
하단에 양창민 부연 설명
--------------------------------
3. MD5 Algorithm Description
We begin by supposing that we have a b-bit message as input, and that
we wish to find its message digest. Here b is an arbitrary
nonnegative integer; b may be zero, it need not be a multiple of
eight, and it may be arbitrarily large. We imagine the bits of the
message written down as follows:
m_0 m_1 ... m_{b-1}
The following five steps are performed to compute the message digest
of the message.
3.1 Step 1. Append Padding Bits
The message is "padded" (extended) so that its length (in bits) is
congruent to 448, modulo 512. That is, the message is extended so
that it is just 64 bits shy of being a multiple of 512 bits long.
Padding is always performed, even if the length of the message is
already congruent to 448, modulo 512.
Padding is performed as follows: a single "1" bit is appended to the
message, and then "0" bits are appended so that the length in bits of
the padded message becomes congruent to 448, modulo 512. In all, at
least one bit and at most 512 bits are appended.
3.2 Step 2. Append Length
A 64-bit representation of b (the length of the message before the
padding bits were added) is appended to the result of the previous
step. In the unlikely event that b is greater than 2^64, then only
the low-order 64 bits of b are used. (These bits are appended as two
32-bit words and appended low-order word first in accordance with the
previous conventions.)
At this point the resulting message (after padding with bits and with
b) has a length that is an exact multiple of 512 bits. Equivalently,
this message has a length that is an exact multiple of 16 (32-bit)
words. Let M[0 ... N-1] denote the words of the resulting message,
where N is a multiple of 16.
3.3 Step 3. Initialize MD Buffer
A four-word buffer (A,B,C,D) is used to compute the message digest.
Here each of A, B, C, D is a 32-bit register. These registers are
initialized to the following values in hexadecimal, low-order bytes
first):
word A: 01 23 45 67
word B: 89 ab cd ef
word C: fe dc ba 98
word D: 76 54 32 10
3.4 Step 4. Process Message in 16-Word Blocks
We first define four auxiliary functions that each take as input
three 32-bit words and produce as output one 32-bit word.
F(X,Y,Z) = XY v not(X) Z
G(X,Y,Z) = XZ v Y not(Z)
H(X,Y,Z) = X xor Y xor Z
I(X,Y,Z) = Y xor (X v not(Z))
In each bit position F acts as a conditional: if X then Y else Z.
The function F could have been defined using + instead of v since XY
and not(X)Z will never have 1's in the same bit position.) It is
interesting to note that if the bits of X, Y, and Z are independent
and unbiased, the each bit of F(X,Y,Z) will be independent and
unbiased.
The functions G, H, and I are similar to the function F, in that they
act in "bitwise parallel" to produce their output from the bits of X,
Y, and Z, in such a manner that if the corresponding bits of X, Y,
and Z are independent and unbiased, then each bit of G(X,Y,Z),
H(X,Y,Z), and I(X,Y,Z) will be independent and unbiased. Note that
the function H is the bit-wise "xor" or "parity" function of its
inputs.
This step uses a 64-element table T[1 ... 64] constructed from the
sine function. Let T[i] denote the i-th element of the table, which
is equal to the integer part of 4294967296 times abs(sin(i)), where i
is in radians. The elements of the table are given in the appendix.
Do the following:
/* Process each 16-word block. */
For i = 0 to N/16-1 do
/* Copy block i into X. */
For j = 0 to 15 do
Set X[j] to M[i*16+j].
end /* of loop on j */
/* Save A as AA, B as BB, C as CC, and D as DD. */
AA = A
BB = B
CC = C
DD = D
/* Round 1. */
/* Let [abcd k s i] denote the operation
a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */
/* Do the following 16 operations. */
[ABCD 0 7 1] [DABC 1 12 2] [CDAB 2 17 3] [BCDA 3 22 4]
[ABCD 4 7 5] [DABC 5 12 6] [CDAB 6 17 7] [BCDA 7 22 8]
[ABCD 8 7 9] [DABC 9 12 10] [CDAB 10 17 11] [BCDA 11 22 12]
[ABCD 12 7 13] [DABC 13 12 14] [CDAB 14 17 15] [BCDA 15 22 16]
/* Round 2. */
/* Let [abcd k s i] denote the operation
a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */
/* Do the following 16 operations. */
[ABCD 1 5 17] [DABC 6 9 18] [CDAB 11 14 19] [BCDA 0 20 20]
[ABCD 5 5 21] [DABC 10 9 22] [CDAB 15 14 23] [BCDA 4 20 24]
[ABCD 9 5 25] [DABC 14 9 26] [CDAB 3 14 27] [BCDA 8 20 28]
[ABCD 13 5 29] [DABC 2 9 30] [CDAB 7 14 31] [BCDA 12 20 32]
/* Round 3. */
/* Let [abcd k s t] denote the operation
a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */
/* Do the following 16 operations. */
[ABCD 5 4 33] [DABC 8 11 34] [CDAB 11 16 35] [BCDA 14 23 36]
[ABCD 1 4 37] [DABC 4 11 38] [CDAB 7 16 39] [BCDA 10 23 40]
[ABCD 13 4 41] [DABC 0 11 42] [CDAB 3 16 43] [BCDA 6 23 44]
[ABCD 9 4 45] [DABC 12 11 46] [CDAB 15 16 47] [BCDA 2 23 48]
/* Round 4. */
/* Let [abcd k s t] denote the operation
a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */
/* Do the following 16 operations. */
[ABCD 0 6 49] [DABC 7 10 50] [CDAB 14 15 51] [BCDA 5 21 52]
[ABCD 12 6 53] [DABC 3 10 54] [CDAB 10 15 55] [BCDA 1 21 56]
[ABCD 8 6 57] [DABC 15 10 58] [CDAB 6 15 59] [BCDA 13 21 60]
[ABCD 4 6 61] [DABC 11 10 62] [CDAB 2 15 63] [BCDA 9 21 64]
/* Then perform the following additions. (That is increment each
of the four registers by the value it had before this block
was started.) */
A = A + AA
B = B + BB
C = C + CC
D = D + DD
end /* of loop on i */
3.5 Step 5. Output
The message digest produced as output is A, B, C, D. That is, we
begin with the low-order byte of A, and end with the high-order byte
of D.
This completes the description of MD5. A reference implementation in
C is given in the appendix.
4. Summary
The MD5 message-digest algorithm is simple to implement, and provides
a "fingerprint" or message digest of a message of arbitrary length.
It is conjectured that the difficulty of coming up with two messages
having the same message digest is on the order of 2^64 operations,
and that the difficulty of coming up with any message having a given
message digest is on the order of 2^128 operations. The MD5 algorithm
has been carefully scrutinized for weaknesses. It is, however, a
relatively new algorithm and further security analysis is of course
justified, as is the case with any new proposal of this sort.
양창민 부연설명
md5()는 절대 암호화가 아니다.
md5() 에서 md 의 뜻은 Message Digest, 즉
메시지변환하는 함수라는 뜻이다.
MySQL password() 도 마찬가지의 메시지변환 함수일 뿐이다.
암호화라는 것은 3DES나 RAS처럼 Key값에 의하여 Value값을 코드변환하여
Encrypted Result를 얻는 과정을 말한다.
즉, Key가 없으면 암호화라고 할 수 없는 것이다.
왜냐하면 Key가 없는 코드변환의 결과는 입력값이 같으면 항상 그 결과값이
같으므로 공개된 코드변환 알고리듬을 역으로 돌리면 디코딩이 된다.
물로, 프로그래머가 알고리듬의 천재라면 md()에 외부적으로 Key
형태의 알고리듬을 추가하여 암호화를 구현할 수도 있다.
그러나, md5()나 password()의 단순 형 변환은 그냥 일정한 자릿수 논리계산 법칙에 의하여 코드변환한 결과일 뿐이다.
메시지변환을 해서 오데다 쓰는가?
직관적으로 알아볼 수 없는 바이너리코드형태로 텍스트를 변환시킨다는
것으로써 get/post 과정에서 노출되는 텍스트, MySQL 테이블에서 노출되어
드러나는 패스워드를 1차적으로 위장하기 위한 목적으로 사용된다.
MySQL 암호화 어쩌구 하는데, MySQL 암호화 필드 저장을 위해서는
PHP에 추가 설치하는 암호화 라이브러리 팩이 따로 있다.
해당 라이브러리 팩을 설치하면 3DES 등 현존하는 대부분의 암호화 알고리듬을 구현할 수 있다. (PHP에 디폴트로 포함되지않으며 추가 다운로드 후 설치하여야 함)
md5()가 3DES네 RAS네 하는 부류가 아니다.
2002-02-06 16:03:49 이해도 향상을 위하여 내용 보충
...............................................................................................................
Written date/time: 2002-02-05 09:42:03
...............................................................................................................
COMPUTER - hardware, software, programming, flash, graphic, java, php
GAME - diablo2, fortress2, starcraft
...............................................................................................................
http://myhome.hananet.net/~changminyang
...............................................................................................................
아래 내용은 알고리듬 부분만 발췌
하단에 양창민 부연 설명
--------------------------------
3. MD5 Algorithm Description
We begin by supposing that we have a b-bit message as input, and that
we wish to find its message digest. Here b is an arbitrary
nonnegative integer; b may be zero, it need not be a multiple of
eight, and it may be arbitrarily large. We imagine the bits of the
message written down as follows:
m_0 m_1 ... m_{b-1}
The following five steps are performed to compute the message digest
of the message.
3.1 Step 1. Append Padding Bits
The message is "padded" (extended) so that its length (in bits) is
congruent to 448, modulo 512. That is, the message is extended so
that it is just 64 bits shy of being a multiple of 512 bits long.
Padding is always performed, even if the length of the message is
already congruent to 448, modulo 512.
Padding is performed as follows: a single "1" bit is appended to the
message, and then "0" bits are appended so that the length in bits of
the padded message becomes congruent to 448, modulo 512. In all, at
least one bit and at most 512 bits are appended.
3.2 Step 2. Append Length
A 64-bit representation of b (the length of the message before the
padding bits were added) is appended to the result of the previous
step. In the unlikely event that b is greater than 2^64, then only
the low-order 64 bits of b are used. (These bits are appended as two
32-bit words and appended low-order word first in accordance with the
previous conventions.)
At this point the resulting message (after padding with bits and with
b) has a length that is an exact multiple of 512 bits. Equivalently,
this message has a length that is an exact multiple of 16 (32-bit)
words. Let M[0 ... N-1] denote the words of the resulting message,
where N is a multiple of 16.
3.3 Step 3. Initialize MD Buffer
A four-word buffer (A,B,C,D) is used to compute the message digest.
Here each of A, B, C, D is a 32-bit register. These registers are
initialized to the following values in hexadecimal, low-order bytes
first):
word A: 01 23 45 67
word B: 89 ab cd ef
word C: fe dc ba 98
word D: 76 54 32 10
3.4 Step 4. Process Message in 16-Word Blocks
We first define four auxiliary functions that each take as input
three 32-bit words and produce as output one 32-bit word.
F(X,Y,Z) = XY v not(X) Z
G(X,Y,Z) = XZ v Y not(Z)
H(X,Y,Z) = X xor Y xor Z
I(X,Y,Z) = Y xor (X v not(Z))
In each bit position F acts as a conditional: if X then Y else Z.
The function F could have been defined using + instead of v since XY
and not(X)Z will never have 1's in the same bit position.) It is
interesting to note that if the bits of X, Y, and Z are independent
and unbiased, the each bit of F(X,Y,Z) will be independent and
unbiased.
The functions G, H, and I are similar to the function F, in that they
act in "bitwise parallel" to produce their output from the bits of X,
Y, and Z, in such a manner that if the corresponding bits of X, Y,
and Z are independent and unbiased, then each bit of G(X,Y,Z),
H(X,Y,Z), and I(X,Y,Z) will be independent and unbiased. Note that
the function H is the bit-wise "xor" or "parity" function of its
inputs.
This step uses a 64-element table T[1 ... 64] constructed from the
sine function. Let T[i] denote the i-th element of the table, which
is equal to the integer part of 4294967296 times abs(sin(i)), where i
is in radians. The elements of the table are given in the appendix.
Do the following:
/* Process each 16-word block. */
For i = 0 to N/16-1 do
/* Copy block i into X. */
For j = 0 to 15 do
Set X[j] to M[i*16+j].
end /* of loop on j */
/* Save A as AA, B as BB, C as CC, and D as DD. */
AA = A
BB = B
CC = C
DD = D
/* Round 1. */
/* Let [abcd k s i] denote the operation
a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */
/* Do the following 16 operations. */
[ABCD 0 7 1] [DABC 1 12 2] [CDAB 2 17 3] [BCDA 3 22 4]
[ABCD 4 7 5] [DABC 5 12 6] [CDAB 6 17 7] [BCDA 7 22 8]
[ABCD 8 7 9] [DABC 9 12 10] [CDAB 10 17 11] [BCDA 11 22 12]
[ABCD 12 7 13] [DABC 13 12 14] [CDAB 14 17 15] [BCDA 15 22 16]
/* Round 2. */
/* Let [abcd k s i] denote the operation
a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */
/* Do the following 16 operations. */
[ABCD 1 5 17] [DABC 6 9 18] [CDAB 11 14 19] [BCDA 0 20 20]
[ABCD 5 5 21] [DABC 10 9 22] [CDAB 15 14 23] [BCDA 4 20 24]
[ABCD 9 5 25] [DABC 14 9 26] [CDAB 3 14 27] [BCDA 8 20 28]
[ABCD 13 5 29] [DABC 2 9 30] [CDAB 7 14 31] [BCDA 12 20 32]
/* Round 3. */
/* Let [abcd k s t] denote the operation
a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */
/* Do the following 16 operations. */
[ABCD 5 4 33] [DABC 8 11 34] [CDAB 11 16 35] [BCDA 14 23 36]
[ABCD 1 4 37] [DABC 4 11 38] [CDAB 7 16 39] [BCDA 10 23 40]
[ABCD 13 4 41] [DABC 0 11 42] [CDAB 3 16 43] [BCDA 6 23 44]
[ABCD 9 4 45] [DABC 12 11 46] [CDAB 15 16 47] [BCDA 2 23 48]
/* Round 4. */
/* Let [abcd k s t] denote the operation
a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */
/* Do the following 16 operations. */
[ABCD 0 6 49] [DABC 7 10 50] [CDAB 14 15 51] [BCDA 5 21 52]
[ABCD 12 6 53] [DABC 3 10 54] [CDAB 10 15 55] [BCDA 1 21 56]
[ABCD 8 6 57] [DABC 15 10 58] [CDAB 6 15 59] [BCDA 13 21 60]
[ABCD 4 6 61] [DABC 11 10 62] [CDAB 2 15 63] [BCDA 9 21 64]
/* Then perform the following additions. (That is increment each
of the four registers by the value it had before this block
was started.) */
A = A + AA
B = B + BB
C = C + CC
D = D + DD
end /* of loop on i */
3.5 Step 5. Output
The message digest produced as output is A, B, C, D. That is, we
begin with the low-order byte of A, and end with the high-order byte
of D.
This completes the description of MD5. A reference implementation in
C is given in the appendix.
4. Summary
The MD5 message-digest algorithm is simple to implement, and provides
a "fingerprint" or message digest of a message of arbitrary length.
It is conjectured that the difficulty of coming up with two messages
having the same message digest is on the order of 2^64 operations,
and that the difficulty of coming up with any message having a given
message digest is on the order of 2^128 operations. The MD5 algorithm
has been carefully scrutinized for weaknesses. It is, however, a
relatively new algorithm and further security analysis is of course
justified, as is the case with any new proposal of this sort.
양창민 부연설명
md5()는 절대 암호화가 아니다.
md5() 에서 md 의 뜻은 Message Digest, 즉
메시지변환하는 함수라는 뜻이다.
MySQL password() 도 마찬가지의 메시지변환 함수일 뿐이다.
암호화라는 것은 3DES나 RAS처럼 Key값에 의하여 Value값을 코드변환하여
Encrypted Result를 얻는 과정을 말한다.
즉, Key가 없으면 암호화라고 할 수 없는 것이다.
왜냐하면 Key가 없는 코드변환의 결과는 입력값이 같으면 항상 그 결과값이
같으므로 공개된 코드변환 알고리듬을 역으로 돌리면 디코딩이 된다.
물로, 프로그래머가 알고리듬의 천재라면 md()에 외부적으로 Key
형태의 알고리듬을 추가하여 암호화를 구현할 수도 있다.
그러나, md5()나 password()의 단순 형 변환은 그냥 일정한 자릿수 논리계산 법칙에 의하여 코드변환한 결과일 뿐이다.
메시지변환을 해서 오데다 쓰는가?
직관적으로 알아볼 수 없는 바이너리코드형태로 텍스트를 변환시킨다는
것으로써 get/post 과정에서 노출되는 텍스트, MySQL 테이블에서 노출되어
드러나는 패스워드를 1차적으로 위장하기 위한 목적으로 사용된다.
MySQL 암호화 어쩌구 하는데, MySQL 암호화 필드 저장을 위해서는
PHP에 추가 설치하는 암호화 라이브러리 팩이 따로 있다.
해당 라이브러리 팩을 설치하면 3DES 등 현존하는 대부분의 암호화 알고리듬을 구현할 수 있다. (PHP에 디폴트로 포함되지않으며 추가 다운로드 후 설치하여야 함)
md5()가 3DES네 RAS네 하는 부류가 아니다.
2002-02-06 16:03:49 이해도 향상을 위하여 내용 보충
...............................................................................................................
Written date/time: 2002-02-05 09:42:03
...............................................................................................................
COMPUTER - hardware, software, programming, flash, graphic, java, php
GAME - diablo2, fortress2, starcraft
...............................................................................................................
http://myhome.hananet.net/~changminyang
...............................................................................................................
댓글 8
-
Seungkal
2002.02.06 16:08
알고리즘 -
양창민
2002.02.07 01:26
원어 발음
^앨거리듬
캐럿은 액선트.
algorithm [ǽlgrìm]
...............................................................................................................
Written date/time: 2002-02-07 01:28:25
...............................................................................................................
COMPUTER - hardware, software, programming, flash, graphic, java, php
GAME - diablo2, fortress2, starcraft
...............................................................................................................
target=_blank>http://myhome.hananet.net/~changminyang
............................................................................................................... -
정재윤
2002.02.09 15:55
MD5가 decoding이 가능한가요? decoding 불가능한 one-way function으로 알고 있는데... -
inFove
2002.02.09 16:31
역연산은 안된다고 하네요.. -
nTruth
2002.02.18 07:47
디코딩.. 말은 쉽지요... -
김민종
2002.03.18 00:57
Message Digest 는 decoding이 불가능 합니다. 목적이 특정 데이터의 유니크한 흔적을 만들어내는거니까요.. 간단한 예로, 특정 문자열이 오면 그 문자열의 아스키 값의 합을 뽑아내는것을 들 수 있는데요.. "ABCDEF"를 넣으면 ??라는 어느 값이 나오겠죠?(아스키 값을 몰라서.. ^_^) 하지만 ??를 가지고 원래 문자열이 "ABCDEF"라는 것을 알아내는것은 꽤나 힘들겠죠.. ^_^. 뭐.. MD5같이 실전에 쓰이는 Message Digest 알고리즘은 이보다 백만배쯤 복잡한 알고리즘을 사용하니까 그냥 Decoding은 불가능하다고 이해하는게 정신건강에 좋을것 같네요.. 압축파일의 무결성을 검사하는(CRC 같은) 데에도 이같은 알고리즘이 쓰이는 것으로 알고 있습니다.. 자세한것은 암호관련 사이트나 서적을 찾아보시면 찾아보실수 있을겁니다.. ^_^ -
미노우
2002.03.19 04:31
저..ㅡㅡ;; 초본데여..
비밀번호 같은건..md5같은거로 암호화하라..등의 말이 많더라구요
근데여..변환해서 DB에 디비넣은다음에 나중에 로긴할때나 그럴때
비번확인할때..ㅡㅡ 그값 도로 원상복귀만들어서 비교해야하자나요
어케하는지요..ㅡㅡ;;;;; 다른함수 있나..ㅡㅡ음...
아..글구요..md5같은거...한 10번 돌려버리면..
엄청복잡해서 헷갈려지지 않을까염..ㅡㅡ? -
John Sync.
2002.03.29 21:17
미노우//아이디 등을 md5로 해서 일치되면 되는거죠~
제목 | 글쓴이 | 날짜 |
---|---|---|
좋은 난수값을 얻기위한 시드배정 방법 mt_srand(), srand() | 차카게살자 | 2002.02.21 |
필터링조금 다른거.. [7] | 두기두바 | 2002.02.10 |
한글 필터링 정확히 하기 [1] | mini | 2002.02.09 |
원고지 함수;; [3] | 디쓰 | 2002.02.07 |
md5() 알고리듬 [8] | 양창민 | 2002.02.05 |
이제 홈페이지 업데이트 안하는 수모를 겪지 말자! [7] | 담배를끊으면복이옴과 | 2002.02.02 |
이제 PHP에 ?id=가나다라 같은것을 넣자! [12] | 담배를끊으면복이옴과 | 2002.01.30 |
초보분들을 위한 연산자 총정리 [6] | TheMics | 2002.01.29 |
[PHP]모르는 분이 있는듯 해서...변수관련 [2] | TheMics | 2002.01.24 |
cron을 이용해 윈앰프 방송정보를 빠르게 분석. [9] | Romeo | 2002.01.15 |
파일시스템에서 비밀번호 생성/수정/인증 [7] | 두기두바 | 2002.01.10 |
파일시스템(배열)에서의 검색기능 [5] | 두기두바 | 2002.01.09 |
[추천 팁] 디망쉬식 스킨 시스템 [4] | 디망쉬 | 2001.12.11 |
[추천 소스] phpMyAdmin 다중사용자용... [5] | WOWpc | 2001.11.29 |
MySQL에서 한글 정렬 문제 [2] | 손정호 | 2001.11.21 |
phpMyAdmin에서 dump 안 되시는 분들 보세요 [5] | 똥가리 | 2001.11.18 |
컴에 phpMyAdmin 깔고 원격 Mysql 관리.(이것도 팁이 되려나?) [1] | 최형삼 | 2001.11.17 |
[추천 소스] 특정일로부터 몇일 지났나 또는 몇일 남았나 알아보는 소스 ㅡ.ㅡ; [1] | 타스케 | 2001.11.15 |
게시판 만들 때 스팸메일을 막을 수 있는 방법중 한개. [11] | WOWpc | 2001.11.09 |
[GD] 이미지 회전 함수 공개합니다. [7] | 노경민 | 2001.11.05 |