FFFTPのソースコードです。
Revision | ff0c7c150e630254fec6dd2bcd36d306f6f759bf (tree) |
---|---|
Time | 2014-01-11 14:23:58 |
Author | s_kawamoto <s_kawamoto@user...> |
Commiter | s_kawamoto |
Change the algorithm to encrypt all settings.
@@ -3189,55 +3189,33 @@ DWORD GetRandamDWRODValue(void) | ||
3189 | 3189 | void MaskSettingsData(const char* Salt, int SaltLength, void* Data, DWORD Size, int EscapeZero) |
3190 | 3190 | { |
3191 | 3191 | char Key[FMAX_PATH*2+1]; |
3192 | - ulong Hash[5]; | |
3192 | + BYTE* p; | |
3193 | 3193 | DWORD i; |
3194 | + DWORD j; | |
3195 | + ulong Hash[5]; | |
3194 | 3196 | BYTE Mask[20]; |
3195 | - BYTE* p; | |
3196 | 3197 | memcpy(&Key[0], SecretKey, SecretKeyLength); |
3197 | 3198 | memcpy(&Key[SecretKeyLength], Salt, SaltLength); |
3198 | - sha_memory(Key, SecretKeyLength + SaltLength, Hash); | |
3199 | - // sha.cはビッグエンディアンのため | |
3200 | - for(i = 0; i < 5; i++) | |
3201 | - Hash[i] = _byteswap_ulong(Hash[i]); | |
3202 | - memcpy(&Mask, &Hash, 20); | |
3203 | 3199 | p = (BYTE*)Data; |
3204 | 3200 | for(i = 0; i < Size; i++) |
3205 | 3201 | { |
3206 | - if(EscapeZero == YES) | |
3202 | + if(i % 20 == 0) | |
3207 | 3203 | { |
3208 | - if(p[i] != 0 && p[i] != Mask[i % sizeof(Mask)]) | |
3209 | - p[i] ^= Mask[i % sizeof(Mask)]; | |
3204 | + memcpy(&Key[SecretKeyLength + SaltLength], &i, 4); | |
3205 | + sha_memory(Key, SecretKeyLength + SaltLength + 4, Hash); | |
3206 | + // sha.cはビッグエンディアンのため | |
3207 | + for(j = 0; j < 5; j++) | |
3208 | + Hash[j] = _byteswap_ulong(Hash[j]); | |
3209 | + memcpy(&Mask, &Hash, 20); | |
3210 | 3210 | } |
3211 | - else | |
3212 | - p[i] ^= Mask[i % sizeof(Mask)]; | |
3211 | + if(EscapeZero == NO || (p[i] != 0 && p[i] != Mask[i % 20])) | |
3212 | + p[i] ^= Mask[i % 20]; | |
3213 | 3213 | } |
3214 | 3214 | } |
3215 | 3215 | |
3216 | 3216 | void UnmaskSettingsData(const char* Salt, int SaltLength, void* Data, DWORD Size, int EscapeZero) |
3217 | 3217 | { |
3218 | - char Key[FMAX_PATH*2+1]; | |
3219 | - ulong Hash[5]; | |
3220 | - DWORD i; | |
3221 | - BYTE Mask[20]; | |
3222 | - BYTE* p; | |
3223 | - memcpy(&Key[0], SecretKey, SecretKeyLength); | |
3224 | - memcpy(&Key[SecretKeyLength], Salt, SaltLength); | |
3225 | - sha_memory(Key, SecretKeyLength + SaltLength, Hash); | |
3226 | - // sha.cはビッグエンディアンのため | |
3227 | - for(i = 0; i < 5; i++) | |
3228 | - Hash[i] = _byteswap_ulong(Hash[i]); | |
3229 | - memcpy(&Mask, &Hash, 20); | |
3230 | - p = (BYTE*)Data; | |
3231 | - for(i = 0; i < Size; i++) | |
3232 | - { | |
3233 | - if(EscapeZero == YES) | |
3234 | - { | |
3235 | - if(p[i] != 0 && p[i] != Mask[i % sizeof(Mask)]) | |
3236 | - p[i] ^= Mask[i % sizeof(Mask)]; | |
3237 | - } | |
3238 | - else | |
3239 | - p[i] ^= Mask[i % sizeof(Mask)]; | |
3240 | - } | |
3218 | + MaskSettingsData(Salt, SaltLength, Data, Size, EscapeZero); | |
3241 | 3219 | } |
3242 | 3220 | |
3243 | 3221 | void CalculateSettingsDataChecksum(void* Data, DWORD Size) |