@@ -52,20 +52,6 @@ private function gpg_encrypt($key, $text) {
5252 $ rblock [$ i ] = GPG_Utility::c_random ();
5353 }
5454
55-
56- $ iblock = GPG_AES ::encrypt ($ iblock , $ ekey );
57- for ($ i = 0 ; $ i < $ this ->width ; $ i ++) {
58- $ ct [$ i ] = ($ iblock [$ i ] ^= $ rblock [$ i ]);
59- }
60-
61- $ iblock = GPG_AES ::encrypt ($ iblock , $ ekey );
62- $ ct [$ this ->width ] = ($ iblock [0 ] ^ $ rblock [$ this ->width - 2 ]);
63- $ ct [$ this ->width + 1 ] = ($ iblock [1 ] ^ $ rblock [$ this ->width - 1 ]);
64-
65- for ($ i = 0 ; $ i < $ this ->width + 2 ; $ i ++) $ cipher .= chr ($ ct [$ i ]);
66-
67- $ iblock = array_slice ($ ct , 2 , $ this ->width + 2 );
68-
6955 for ($ n = 0 ; $ n < strlen ($ text ); $ n += $ this ->width ) {
7056 $ iblock = GPG_AES ::encrypt ($ iblock , $ ekey );
7157 for ($ i = 0 ; $ i < $ this ->width ; $ i ++) {
@@ -74,7 +60,7 @@ private function gpg_encrypt($key, $text) {
7460 }
7561 }
7662
77- return substr ($ cipher , 0 , $ len + $ this -> width + 2 );
63+ return substr ($ cipher , 0 , $ len );
7864 }
7965
8066 private function gpg_header ($ tag , $ len )
@@ -158,15 +144,16 @@ private function gpg_literal($text)
158144 if (strpos ($ text , "\r\n" ) === false )
159145 $ text = str_replace ("\n" , "\r\n" , $ text );
160146
161- return
162- $ this ->gpg_header (0xac , strlen ($ text ) + 10 ) . "t " .
163- chr (4 ) . "file \0\0\0\0" . $ text ;
147+ return chr (11 | 0xC0 ) . chr (255 ) . $ this ->writeNumber (strlen ($ text ) + 10 , 4 ) . "t " . chr (4 ) . "file \0\0\0\0" . $ text ;
164148 }
165149
166150 private function gpg_data ($ key , $ text )
167151 {
168- $ enc = $ this ->gpg_encrypt ($ key , $ this ->gpg_literal ($ text ));
169- return $ this ->gpg_header (0xa4 , strlen ($ enc )) . $ enc ;
152+ $ prefix = GPG_Utility::s_random ($ this ->width , 0 );
153+ $ prefix .= substr ($ prefix , -2 );
154+ $ mdc ="\xD3\x14" .hash ('sha1 ' , $ prefix .$ this ->gpg_literal ($ text )."\xD3\x14" , true );
155+ $ enc = $ this ->gpg_encrypt ($ key , $ prefix .$ this ->gpg_literal ($ text ).$ mdc );
156+ return chr (0x12 | 0xC0 ) . chr (255 ) . $ this ->writeNumber (1 +strlen ($ enc ), 4 ) . chr (1 ) . $ enc ;
170157 }
171158
172159 /**
0 commit comments