• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

ギコナビ


Commit MetaInfo

Revision74f8cf9f7f4ed3dcc9cd38b7525191287a93ba6d (tree)
Time2009-06-21 00:37:28
Authorh677 <h677>
Commiterh677

Log Message

2ちゃんねるのトリップ仕様の拡張に対応

Change Summary

Incremental Difference

--- /dev/null
+++ b/SHA1Unit.pas
@@ -0,0 +1,194 @@
1+unit SHA1Unit;
2+
3+interface
4+
5+uses
6+ Windows, SysUtils;
7+
8+const
9+ SHA1_A = DWORD( $67452301 );
10+ SHA1_B = DWORD( $EFCDAB89 );
11+ SHA1_C = DWORD( $98BADCFE );
12+ SHA1_D = DWORD( $10325476 );
13+ SHA1_E = DWORD( $C3D2E1F0 );
14+ SHA1_K1 = DWORD( $5A827999 );
15+ SHA1_K2 = DWORD( $6ED9EBA1 );
16+ SHA1_K3 = DWORD( $8F1BBCDC );
17+ SHA1_K4 = DWORD( $CA62C1D6 );
18+ LBMASK_HI = DWORD( $FF0000 );
19+ LBMASK_LO = DWORD( $FF00 );
20+
21+type
22+ TSHA1Digest = array [0..19] of Byte;
23+ TSHA1Context = record
24+ sdHi : DWord;
25+ sdLo : DWord;
26+ sdIndex : DWord;
27+ sdHash : array [0..4] of DWord;
28+ sdBuf : array [0..63] of Byte;
29+ end;
30+
31+ function SHA1SwapByteOrder( n : DWORD ) : DWORD;
32+ procedure HashSHA1( var Digest : TSHA1Digest; const Buf; BufSize : Longint );
33+ procedure StringHashSHA1(var Digest : TSHA1Digest; const Str : string);
34+ procedure SHA1Hash( var Context : TSHA1Context );
35+
36+implementation
37+//! •¶Žš—ñ—pSHA1ƒnƒbƒVƒ…Žæ“¾
38+procedure StringHashSHA1(var Digest : TSHA1Digest; const Str : string);
39+begin
40+ HashSHA1(Digest, Str[1], Length(Str));
41+end;
42+//! SHA1ƒnƒbƒVƒ…Žæ“¾
43+procedure HashSHA1( var Digest : TSHA1Digest; const Buf; BufSize : Longint );
44+var
45+ Context : TSHA1Context;
46+ PBuf: ^Byte;
47+ procedure UpdateLen( var Context : TSHA1Context; Len : DWord );
48+ begin
49+ Inc( Context.sdLo,( Len shl 3 ));
50+ if Context.sdLo < ( Len shl 3 ) then
51+ Inc( Context.sdHi );
52+ Inc( Context.sdHi, Len shr 29 );
53+ end;
54+begin
55+ //0–„‚ß
56+ fillchar( Context, SizeOf( Context ), 0 );
57+ // ƒ}ƒWƒbƒNƒiƒ“ƒo[‚ŏ‰Šú‰»‚·‚é
58+ Context.sdHash[ 0 ] := SHA1_A;
59+ Context.sdHash[ 1 ] := SHA1_B;
60+ Context.sdHash[ 2 ] := SHA1_C;
61+ Context.sdHash[ 3 ] := SHA1_D;
62+ Context.sdHash[ 4 ] := SHA1_E;
63+
64+ UpdateLen( Context, BufSize );
65+ PBuf := @Buf;
66+ while BufSize > 0 do begin
67+ if ( Sizeof( Context.sdBuf ) - Context.sdIndex ) <= DWord( BufSize ) then begin
68+ Move( PBuf^, Context.sdBuf[ Context.sdIndex ], Sizeof( Context.sdBuf ) - Context.sdIndex );
69+ Dec( BufSize, Sizeof( Context.sdBuf ) - Context.sdIndex );
70+ Inc( PBuf, Sizeof( Context.sdBuf ) - Context.sdIndex );
71+ SHA1Hash( Context );
72+ end else begin
73+ Move( PBuf^, Context.sdBuf[ Context.sdIndex ], BufSize );
74+ Inc( Context.sdIndex, BufSize );
75+ BufSize := 0;
76+ end;
77+ end;
78+
79+ Context.sdBuf[ Context.sdIndex ] := $80;
80+
81+ if Context.sdIndex >= 56 then
82+ SHA1Hash( Context );
83+
84+ PDWord( @Context.sdBuf[ 56 ])^ := SHA1SwapByteOrder( Context.sdHi );
85+ PDWord( @Context.sdBuf[ 60 ])^ := SHA1SwapByteOrder( Context.sdLo );
86+
87+ SHA1Hash( Context );
88+
89+ Context.sdHash[ 0 ] := SHA1SwapByteOrder( Context.sdHash[ 0 ]);
90+ Context.sdHash[ 1 ] := SHA1SwapByteOrder( Context.sdHash[ 1 ]);
91+ Context.sdHash[ 2 ] := SHA1SwapByteOrder( Context.sdHash[ 2 ]);
92+ Context.sdHash[ 3 ] := SHA1SwapByteOrder( Context.sdHash[ 3 ]);
93+ Context.sdHash[ 4 ] := SHA1SwapByteOrder( Context.sdHash[ 4 ]);
94+
95+ Move( Context.sdHash, Digest, Sizeof( Digest ));
96+end;
97+//! ƒnƒbƒVƒ…ˆ—
98+procedure SHA1Hash( var Context : TSHA1Context );
99+var
100+ A : DWord;
101+ B : DWord;
102+ C : DWord;
103+ D : DWord;
104+ E : DWord;
105+
106+ temp : DWord;
107+ W : array[ 0..79 ] of DWord;
108+
109+ i : Longint;
110+ function SHA1CircularShift(I, C : DWord) : DWord; register;
111+ asm
112+ mov ecx, edx
113+ rol eax, cl
114+ end;
115+begin
116+ with Context do begin
117+ sdIndex:= 0;
118+ Move( sdBuf, W, Sizeof( W ));
119+
120+ // Initialize the first 16 words in the array W
121+ for i := 0 to 15 do begin
122+ W[ i ]:= SHA1SwapByteOrder( W[ i ] );
123+ end;
124+
125+ // Transform Message block from 16 32 bit words to 80 32 bit words
126+ // Wt, = ( Wt-3 xor Wt-8 xor Wt-13 xor Wt-16 ) rolL 1 : Wt is W sub t
127+ for i:= 16 to 79 do begin
128+ W[i]:= SHA1CircularShift( W[ i - 3 ] xor W[ i - 8 ] xor W[ i - 14 ] xor W[ i - 16 ], 1 );
129+ end;
130+
131+ A := sdHash[ 0 ];
132+ B := sdHash[ 1 ];
133+ C := sdHash[ 2 ];
134+ D := sdHash[ 3 ];
135+ E := sdHash[ 4 ];
136+
137+ // the four rounds
138+ for i:= 0 to 19 do begin
139+ temp := SHA1CircularShift( A, 5 ) + ( D xor ( B and ( C xor D ))) + E + W[ i ] + SHA1_K1;
140+ E := D;
141+ D := C;
142+ C := SHA1CircularShift( B, 30 );
143+ B := A;
144+ A := temp;
145+ end;
146+
147+ for i:= 20 to 39 do begin
148+ temp := SHA1CircularShift( A, 5 ) + ( B xor C xor D ) + E + W[ i ] + SHA1_K2;
149+ E := D;
150+ D := C;
151+ C := SHA1CircularShift( B, 30 );
152+ B := A;
153+ A := temp;
154+ end;
155+
156+ for i:= 40 to 59 do begin
157+ temp := SHA1CircularShift( A, 5 ) + (( B and C ) or ( D and ( B or C ))) + E + W[ i ] + SHA1_K3;
158+ E := D;
159+ D := C;
160+ C := SHA1CircularShift( B, 30 );
161+ B := A;
162+ A := temp;
163+ end;
164+
165+ for i:= 60 to 79 do
166+ begin
167+ temp := SHA1CircularShift( A, 5 ) + ( B xor C xor D ) + E + W[ i ] + SHA1_K4;
168+ E := D;
169+ D := C;
170+ C := SHA1CircularShift( B, 30 );
171+ B := A;
172+ A := temp;
173+ end;
174+
175+ sdHash[ 0 ]:= sdHash[ 0 ] + A;
176+ sdHash[ 1 ]:= sdHash[ 1 ] + B;
177+ sdHash[ 2 ]:= sdHash[ 2 ] + C;
178+ sdHash[ 3 ]:= sdHash[ 3 ] + D;
179+ sdHash[ 4 ]:= sdHash[ 4 ] + E;
180+
181+ FillChar( W, Sizeof( W ), 0 );
182+ FillChar( sdBuf, Sizeof( sdBuf ), 0 );
183+ end;
184+end;
185+
186+//! ãˆÊƒoƒCƒg‚ƉºˆÊƒoƒCƒg‚Ì“ü‚ê‘Ö‚¦
187+function SHA1SwapByteOrder( n : DWORD ) : DWORD;
188+begin
189+ n := ( n shr 24 ) or (( n shr 8 ) and LBMASK_LO )
190+ or (( n shl 8 ) and LBMASK_HI ) or ( n shl 24 );
191+ Result := n;
192+end;
193+
194+end.
--- a/Trip.pas
+++ b/Trip.pas
@@ -9,6 +9,9 @@ unit Trip;
99 }
1010 interface
1111
12+uses
13+ SHA1Unit, UBase64, SysUtils;
14+
1215 type
1316 CryptBlock = record
1417 b_data : array [0..63] of char;
@@ -417,25 +420,93 @@ begin
417420
418421 end;
419422
423+procedure get_pw_salt(
424+ const pw : PChar;
425+ var convpw : String;
426+ const salt : PChar
427+);
428+var
429+ i : integer;
430+begin
431+ // ^([0-9A-Fa-f]{16})([./0-9A-Za-z]{0,2})$
432+ if (Length(pw) >= 17) or (Length(pw) <= 19) then begin
433+ // ƒL[•”•ª
434+ for i := 0 to 7 do begin
435+ if (Pos(pw[2*i + 0 + 1], '0123456789abcdefABCDEF') > 0) and
436+ (Pos(pw[2*i + 1 + 1], '0123456789abcdefABCDEF') > 0) then begin
437+ convpw := convpw +
438+ Char(StrToInt( pw[2*i + 0 + 1] ) shl 4 + StrToInt( pw[2*i + 1 + 1] ));
439+ end else begin
440+ convpw := '';
441+ Break;
442+ end;
443+ end;
444+
445+ if (Length(convpw) = 8) then begin
446+ if (Length(pw) = 19) then begin
447+ if (Pos(pw[17], './0123456789abcdefABCDEF') > 0) and
448+ (Pos(pw[18], './0123456789abcdefABCDEF') > 0) then begin
449+ salt[ 0 ] := pw[17];
450+ salt[ 1 ] := pw[18];
451+ salt[ 2 ] := #0;
452+ end else begin
453+ convpw := '';
454+ end;
455+ end else if (Length(pw) = 18) then begin
456+ if (Pos(pw[17], './0123456789abcdefABCDEF') > 0) then begin
457+ salt[ 0 ] := pw[17];
458+ salt[ 1 ] := '.';
459+ salt[ 2 ] := #0;
460+ end else begin
461+ convpw := '';
462+ end;
463+ end else begin
464+ salt[ 0 ] := '.';
465+ salt[ 1 ] := '.';
466+ salt[ 2 ] := #0;
467+ end;
468+ end;
469+ end;
470+end;
471+
420472 function get_2ch_trip(
421473 const pw : PChar
422474 ) : string;
423475 var
424476 s : CryptData;
425477 salt : array [0..2] of char;
478+ digest : TSHA1Digest;
479+ convpw : String;
426480 begin
427-
481+ Result := '';
428482 if pw[ 0 ] = #0 then
429483 begin
430- Result := '';
431484 Exit;
432485 end;
433-
434- get_salt( pw, salt );
435-
436-
437- Result := Copy( crypt_r( pw, salt, s ), 4, 100 );
438-
486+ // 11Œ…‚Ü‚Å‚Í‹Œ•ûŽ®
487+ if (Length(pw) <= 11) then begin
488+ get_salt( pw, salt );
489+ Result := Copy( crypt_r( pw, salt, s ), 4, 100 );
490+ end else begin
491+ // V•ûŽ®ƒgƒŠƒbƒv
492+ if pw[ 0 ] = '$' then begin
493+ // «—ˆ‚ÌŠg’£—p
494+ Result := '???';
495+ end else begin
496+ convpw := '';
497+ // ¶ƒL[•ûŽ®
498+ if pw[ 0 ] = '#' then begin
499+ get_pw_salt(pw, convpw, salt);
500+ end;
501+ if Length(convpw) = 8 then begin
502+ Result := Copy( crypt_r( PChar(convpw), salt, s ), 4, 100 );
503+ end else begin
504+ // V•ûŽ®
505+ StringHashSHA1(digest, pw);
506+ Result := Copy(HogeBase64Encode(digest), 0, 12);
507+ end;
508+ end;
509+ end;
439510 end;
440511
441512 procedure get_salt(
--- a/gikoNavi.dpr
+++ b/gikoNavi.dpr
@@ -52,7 +52,6 @@ uses
5252 ExternalBoardPlugInMain in 'ExternalBoardPlugInMain.pas',
5353 ExternalFilePath in 'ExternalFilePath.pas',
5454 MojuUtils in 'MojuUtils.pas',
55- {crc in 'gzip_delphi2\crc.pas', //zlibXV‚É”º‚¢íœ}
5655 gzip in 'gzip_delphi2\gzip.pas',
5756 zlib in 'gzip_delphi2\zlib.pas',
5857 bmRegExp in 'bmRegExp\bmregexp.pas',
@@ -81,7 +80,8 @@ uses
8180 SkinFiles in 'SkinFiles.pas',
8281 NewBoardURL in 'NewBoardURL.pas' {NewBoardURLForm},
8382 ExtPreviewDatamodule in 'ExtPreviewDatamodule.pas' {ExtPreviewDM: TDataModule},
84- UpdateCheck in 'UpdateCheck.pas' {UpdateCheckForm};
83+ UpdateCheck in 'UpdateCheck.pas' {UpdateCheckForm},
84+ SHA1Unit in 'SHA1Unit.pas';
8585
8686 {$R *.RES}
8787 {$R gikoResource.res}